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/if_arp.h>
88 #include <linux/wireless.h>
89 #include <net/iw_handler.h>
90 #include <net/ieee80211.h>
92 #include <linux/scatterlist.h>
93 #include <linux/crypto.h>
95 #include "hermes_rid.h"
96 #include "hermes_dld.h"
99 /********************************************************************/
100 /* Module information */
101 /********************************************************************/
103 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
104 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
105 MODULE_LICENSE("Dual MPL/GPL");
107 /* Level of debugging. Used in the macros in orinoco.h */
109 int orinoco_debug = ORINOCO_DEBUG;
110 module_param(orinoco_debug, int, 0644);
111 MODULE_PARM_DESC(orinoco_debug, "Debug level");
112 EXPORT_SYMBOL(orinoco_debug);
115 static int suppress_linkstatus; /* = 0 */
116 module_param(suppress_linkstatus, bool, 0644);
117 MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
118 static int ignore_disconnect; /* = 0 */
119 module_param(ignore_disconnect, int, 0644);
120 MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
122 static int force_monitor; /* = 0 */
123 module_param(force_monitor, int, 0644);
124 MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
126 /********************************************************************/
127 /* Compile time configuration and compatibility stuff */
128 /********************************************************************/
130 /* We do this this way to avoid ifdefs in the actual code */
132 #define SPY_NUMBER(priv) (priv->spy_data.spy_number)
134 #define SPY_NUMBER(priv) 0
135 #endif /* WIRELESS_SPY */
137 /********************************************************************/
138 /* Internal constants */
139 /********************************************************************/
141 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
142 static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
143 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
145 #define ORINOCO_MIN_MTU 256
146 #define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
148 #define SYMBOL_MAX_VER_LEN (14)
151 #define MAX_IRQLOOPS_PER_IRQ 10
152 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
153 * how many events the
155 * legitimately generate */
156 #define SMALL_KEY_SIZE 5
157 #define LARGE_KEY_SIZE 13
158 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
160 #define DUMMY_FID 0xFFFF
162 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
163 HERMES_MAX_MULTICAST : 0)*/
164 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
166 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
167 | HERMES_EV_TX | HERMES_EV_TXEXC \
168 | HERMES_EV_WTERR | HERMES_EV_INFO \
169 | HERMES_EV_INFDROP )
171 #define MAX_RID_LEN 1024
173 static const struct iw_handler_def orinoco_handler_def;
174 static const struct ethtool_ops orinoco_ethtool_ops;
176 /********************************************************************/
178 /********************************************************************/
180 /* The frequency of each channel in MHz */
181 static const long channel_frequency[] = {
182 2412, 2417, 2422, 2427, 2432, 2437, 2442,
183 2447, 2452, 2457, 2462, 2467, 2472, 2484
185 #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
187 /* This tables gives the actual meanings of the bitrate IDs returned
188 * by the firmware. */
190 int bitrate; /* in 100s of kilobits */
192 u16 agere_txratectrl;
193 u16 intersil_txratectrl;
194 } bitrate_table[] = {
195 {110, 1, 3, 15}, /* Entry 0 is the default */
204 #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
206 /********************************************************************/
208 /********************************************************************/
210 /* Beginning of the Tx descriptor, used in TxExc handling */
211 struct hermes_txexc_data {
212 struct hermes_tx_descriptor desc;
216 } __attribute__ ((packed));
218 /* Rx frame header except compatibility 802.3 header */
219 struct hermes_rx_descriptor {
240 } __attribute__ ((packed));
242 /********************************************************************/
243 /* Function prototypes */
244 /********************************************************************/
246 static int __orinoco_program_rids(struct net_device *dev);
247 static void __orinoco_set_multicast_list(struct net_device *dev);
249 /********************************************************************/
250 /* Michael MIC crypto setup */
251 /********************************************************************/
252 #define MICHAEL_MIC_LEN 8
253 static int orinoco_mic_init(struct orinoco_private *priv)
255 priv->tx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
256 if (IS_ERR(priv->tx_tfm_mic)) {
257 printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
258 "crypto API michael_mic\n");
259 priv->tx_tfm_mic = NULL;
263 priv->rx_tfm_mic = crypto_alloc_hash("michael_mic", 0, 0);
264 if (IS_ERR(priv->rx_tfm_mic)) {
265 printk(KERN_DEBUG "orinoco_mic_init: could not allocate "
266 "crypto API michael_mic\n");
267 priv->rx_tfm_mic = NULL;
274 static void orinoco_mic_free(struct orinoco_private *priv)
276 if (priv->tx_tfm_mic)
277 crypto_free_hash(priv->tx_tfm_mic);
278 if (priv->rx_tfm_mic)
279 crypto_free_hash(priv->rx_tfm_mic);
282 static int michael_mic(struct crypto_hash *tfm_michael, u8 *key,
283 u8 *da, u8 *sa, u8 priority,
284 u8 *data, size_t data_len, u8 *mic)
286 struct hash_desc desc;
287 struct scatterlist sg[2];
288 u8 hdr[ETH_HLEN + 2]; /* size of header + padding */
290 if (tfm_michael == NULL) {
291 printk(KERN_WARNING "michael_mic: tfm_michael == NULL\n");
295 /* Copy header into buffer. We need the padding on the end zeroed */
296 memcpy(&hdr[0], da, ETH_ALEN);
297 memcpy(&hdr[ETH_ALEN], sa, ETH_ALEN);
298 hdr[ETH_ALEN*2] = priority;
299 hdr[ETH_ALEN*2+1] = 0;
300 hdr[ETH_ALEN*2+2] = 0;
301 hdr[ETH_ALEN*2+3] = 0;
303 /* Use scatter gather to MIC header and data in one go */
304 sg_init_table(sg, 2);
305 sg_set_buf(&sg[0], hdr, sizeof(hdr));
306 sg_set_buf(&sg[1], data, data_len);
308 if (crypto_hash_setkey(tfm_michael, key, MIC_KEYLEN))
311 desc.tfm = tfm_michael;
313 return crypto_hash_digest(&desc, sg, data_len + sizeof(hdr),
317 /********************************************************************/
318 /* Internal helper functions */
319 /********************************************************************/
321 static inline void set_port_type(struct orinoco_private *priv)
323 switch (priv->iw_mode) {
326 priv->createibss = 0;
329 if (priv->prefer_port3) {
331 priv->createibss = 0;
333 priv->port_type = priv->ibss_port;
334 priv->createibss = 1;
337 case IW_MODE_MONITOR:
339 priv->createibss = 0;
342 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
347 #define ORINOCO_MAX_BSS_COUNT 64
348 static int orinoco_bss_data_allocate(struct orinoco_private *priv)
350 if (priv->bss_xbss_data)
353 if (priv->has_ext_scan)
354 priv->bss_xbss_data = kzalloc(ORINOCO_MAX_BSS_COUNT *
355 sizeof(struct xbss_element),
358 priv->bss_xbss_data = kzalloc(ORINOCO_MAX_BSS_COUNT *
359 sizeof(struct bss_element),
362 if (!priv->bss_xbss_data) {
363 printk(KERN_WARNING "Out of memory allocating beacons");
369 static void orinoco_bss_data_free(struct orinoco_private *priv)
371 kfree(priv->bss_xbss_data);
372 priv->bss_xbss_data = NULL;
375 #define PRIV_BSS ((struct bss_element *)priv->bss_xbss_data)
376 #define PRIV_XBSS ((struct xbss_element *)priv->bss_xbss_data)
377 static void orinoco_bss_data_init(struct orinoco_private *priv)
381 INIT_LIST_HEAD(&priv->bss_free_list);
382 INIT_LIST_HEAD(&priv->bss_list);
383 if (priv->has_ext_scan)
384 for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++)
385 list_add_tail(&(PRIV_XBSS[i].list),
386 &priv->bss_free_list);
388 for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++)
389 list_add_tail(&(PRIV_BSS[i].list),
390 &priv->bss_free_list);
394 static inline u8 *orinoco_get_ie(u8 *data, size_t len,
395 enum ieee80211_mfie eid)
398 while ((p + 2) < (data + len)) {
406 #define WPA_OUI_TYPE "\x00\x50\xF2\x01"
407 #define WPA_SELECTOR_LEN 4
408 static inline u8 *orinoco_get_wpa_ie(u8 *data, size_t len)
411 while ((p + 2 + WPA_SELECTOR_LEN) < (data + len)) {
412 if ((p[0] == MFIE_TYPE_GENERIC) &&
413 (memcmp(&p[2], WPA_OUI_TYPE, WPA_SELECTOR_LEN) == 0))
421 /********************************************************************/
422 /* Download functionality */
423 /********************************************************************/
433 const static struct fw_info orinoco_fw[] = {
434 { "", "agere_sta_fw.bin", "agere_ap_fw.bin", 0x00390000, 1000 },
435 { "", "prism_sta_fw.bin", "prism_ap_fw.bin", 0, 1024 },
436 { "symbol_sp24t_prim_fw", "symbol_sp24t_sec_fw", "", 0x00003100, 0x100 }
439 /* Structure used to access fields in FW
440 * Make sure LE decoding macros are used
442 struct orinoco_fw_header {
443 char hdr_vers[6]; /* ASCII string for header version */
444 __le16 headersize; /* Total length of header */
445 __le32 entry_point; /* NIC entry point */
446 __le32 blocks; /* Number of blocks to program */
447 __le32 block_offset; /* Offset of block data from eof header */
448 __le32 pdr_offset; /* Offset to PDR data from eof header */
449 __le32 pri_offset; /* Offset to primary plug data */
450 __le32 compat_offset; /* Offset to compatibility data*/
451 char signature[0]; /* FW signature length headersize-20 */
452 } __attribute__ ((packed));
454 /* Download either STA or AP firmware into the card. */
456 orinoco_dl_firmware(struct orinoco_private *priv,
457 const struct fw_info *fw,
460 /* Plug Data Area (PDA) */
461 __le16 pda[512] = { 0 };
463 hermes_t *hw = &priv->hw;
464 const struct firmware *fw_entry;
465 const struct orinoco_fw_header *hdr;
466 const unsigned char *first_block;
467 const unsigned char *end;
468 const char *firmware;
469 struct net_device *dev = priv->ndev;
473 firmware = fw->ap_fw;
475 firmware = fw->sta_fw;
477 printk(KERN_DEBUG "%s: Attempting to download firmware %s\n",
478 dev->name, firmware);
480 /* Read current plug data */
481 err = hermes_read_pda(hw, pda, fw->pda_addr,
482 min_t(u16, fw->pda_size, sizeof(pda)), 0);
483 printk(KERN_DEBUG "%s: Read PDA returned %d\n", dev->name, err);
487 err = request_firmware(&fw_entry, firmware, priv->dev);
489 printk(KERN_ERR "%s: Cannot find firmware %s\n",
490 dev->name, firmware);
494 hdr = (const struct orinoco_fw_header *) fw_entry->data;
496 /* Enable aux port to allow programming */
497 err = hermesi_program_init(hw, le32_to_cpu(hdr->entry_point));
498 printk(KERN_DEBUG "%s: Program init returned %d\n", dev->name, err);
503 first_block = (fw_entry->data +
504 le16_to_cpu(hdr->headersize) +
505 le32_to_cpu(hdr->block_offset));
506 end = fw_entry->data + fw_entry->size;
508 err = hermes_program(hw, first_block, end);
509 printk(KERN_DEBUG "%s: Program returned %d\n", dev->name, err);
513 /* Update production data */
514 first_block = (fw_entry->data +
515 le16_to_cpu(hdr->headersize) +
516 le32_to_cpu(hdr->pdr_offset));
518 err = hermes_apply_pda_with_defaults(hw, first_block, pda);
519 printk(KERN_DEBUG "%s: Apply PDA returned %d\n", dev->name, err);
523 /* Tell card we've finished */
524 err = hermesi_program_end(hw);
525 printk(KERN_DEBUG "%s: Program end returned %d\n", dev->name, err);
529 /* Check if we're running */
530 printk(KERN_DEBUG "%s: hermes_present returned %d\n",
531 dev->name, hermes_present(hw));
534 release_firmware(fw_entry);
539 #define TEXT_END 0x1A /* End of text header */
542 * Process a firmware image - stop the card, load the firmware, reset
543 * the card and make sure it responds. For the secondary firmware take
544 * care of the PDA - read it and then write it on top of the firmware.
547 symbol_dl_image(struct orinoco_private *priv, const struct fw_info *fw,
548 const unsigned char *image, const unsigned char *end,
551 hermes_t *hw = &priv->hw;
553 const unsigned char *ptr;
554 const unsigned char *first_block;
556 /* Plug Data Area (PDA) */
559 /* Binary block begins after the 0x1A marker */
561 while (*ptr++ != TEXT_END);
564 /* Read the PDA from EEPROM */
566 ret = hermes_read_pda(hw, pda, fw->pda_addr, sizeof(pda), 1);
571 /* Stop the firmware, so that it can be safely rewritten */
573 ret = priv->stop_fw(priv, 1);
578 /* Program the adapter with new firmware */
579 ret = hermes_program(hw, first_block, end);
583 /* Write the PDA to the adapter */
585 size_t len = hermes_blocks_length(first_block);
586 ptr = first_block + len;
587 ret = hermes_apply_pda(hw, ptr, pda);
592 /* Run the firmware */
594 ret = priv->stop_fw(priv, 0);
599 /* Reset hermes chip and make sure it responds */
600 ret = hermes_init(hw);
602 /* hermes_reset() should return 0 with the secondary firmware */
603 if (secondary && ret != 0)
606 /* And this should work with any firmware */
607 if (!hermes_present(hw))
615 * Download the firmware into the card, this also does a PCMCIA soft
616 * reset on the card, to make sure it's in a sane state.
619 symbol_dl_firmware(struct orinoco_private *priv,
620 const struct fw_info *fw)
622 struct net_device *dev = priv->ndev;
624 const struct firmware *fw_entry;
626 if (request_firmware(&fw_entry, fw->pri_fw,
628 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
629 dev->name, fw->pri_fw);
633 /* Load primary firmware */
634 ret = symbol_dl_image(priv, fw, fw_entry->data,
635 fw_entry->data + fw_entry->size, 0);
636 release_firmware(fw_entry);
638 printk(KERN_ERR "%s: Primary firmware download failed\n",
643 if (request_firmware(&fw_entry, fw->sta_fw,
645 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
646 dev->name, fw->sta_fw);
650 /* Load secondary firmware */
651 ret = symbol_dl_image(priv, fw, fw_entry->data,
652 fw_entry->data + fw_entry->size, 1);
653 release_firmware(fw_entry);
655 printk(KERN_ERR "%s: Secondary firmware download failed\n",
662 static int orinoco_download(struct orinoco_private *priv)
665 /* Reload firmware */
666 switch (priv->firmware_type) {
667 case FIRMWARE_TYPE_AGERE:
668 /* case FIRMWARE_TYPE_INTERSIL: */
669 err = orinoco_dl_firmware(priv,
670 &orinoco_fw[priv->firmware_type], 0);
673 case FIRMWARE_TYPE_SYMBOL:
674 err = symbol_dl_firmware(priv,
675 &orinoco_fw[priv->firmware_type]);
677 case FIRMWARE_TYPE_INTERSIL:
680 /* TODO: if we fail we probably need to reinitialise
686 /********************************************************************/
688 /********************************************************************/
690 static int orinoco_open(struct net_device *dev)
692 struct orinoco_private *priv = netdev_priv(dev);
696 if (orinoco_lock(priv, &flags) != 0)
699 err = __orinoco_up(dev);
704 orinoco_unlock(priv, &flags);
709 static int orinoco_stop(struct net_device *dev)
711 struct orinoco_private *priv = netdev_priv(dev);
714 /* We mustn't use orinoco_lock() here, because we need to be
715 able to close the interface even if hw_unavailable is set
716 (e.g. as we're released after a PC Card removal) */
717 spin_lock_irq(&priv->lock);
721 err = __orinoco_down(dev);
723 spin_unlock_irq(&priv->lock);
728 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
730 struct orinoco_private *priv = netdev_priv(dev);
735 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
737 struct orinoco_private *priv = netdev_priv(dev);
738 hermes_t *hw = &priv->hw;
739 struct iw_statistics *wstats = &priv->wstats;
743 if (! netif_device_present(dev)) {
744 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
746 return NULL; /* FIXME: Can we do better than this? */
749 /* If busy, return the old stats. Returning NULL may cause
750 * the interface to disappear from /proc/net/wireless */
751 if (orinoco_lock(priv, &flags) != 0)
754 /* We can't really wait for the tallies inquiry command to
755 * complete, so we just use the previous results and trigger
756 * a new tallies inquiry command for next time - Jean II */
757 /* FIXME: Really we should wait for the inquiry to come back -
758 * as it is the stats we give don't make a whole lot of sense.
759 * Unfortunately, it's not clear how to do that within the
760 * wireless extensions framework: I think we're in user
761 * context, but a lock seems to be held by the time we get in
762 * here so we're not safe to sleep here. */
763 hermes_inquire(hw, HERMES_INQ_TALLIES);
765 if (priv->iw_mode == IW_MODE_ADHOC) {
766 memset(&wstats->qual, 0, sizeof(wstats->qual));
767 /* If a spy address is defined, we report stats of the
768 * first spy address - Jean II */
769 if (SPY_NUMBER(priv)) {
770 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
771 wstats->qual.level = priv->spy_data.spy_stat[0].level;
772 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
773 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
777 __le16 qual, signal, noise, unused;
778 } __attribute__ ((packed)) cq;
780 err = HERMES_READ_RECORD(hw, USER_BAP,
781 HERMES_RID_COMMSQUALITY, &cq);
784 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
785 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
786 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
787 wstats->qual.updated = 7;
791 orinoco_unlock(priv, &flags);
795 static void orinoco_set_multicast_list(struct net_device *dev)
797 struct orinoco_private *priv = netdev_priv(dev);
800 if (orinoco_lock(priv, &flags) != 0) {
801 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
802 "called when hw_unavailable\n", dev->name);
806 __orinoco_set_multicast_list(dev);
807 orinoco_unlock(priv, &flags);
810 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
812 struct orinoco_private *priv = netdev_priv(dev);
814 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
817 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
818 (priv->nicbuf_size - ETH_HLEN) )
826 /********************************************************************/
828 /********************************************************************/
830 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
832 struct orinoco_private *priv = netdev_priv(dev);
833 struct net_device_stats *stats = &priv->stats;
834 hermes_t *hw = &priv->hw;
836 u16 txfid = priv->txfid;
841 if (! netif_running(dev)) {
842 printk(KERN_ERR "%s: Tx on stopped device!\n",
844 return NETDEV_TX_BUSY;
847 if (netif_queue_stopped(dev)) {
848 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
850 return NETDEV_TX_BUSY;
853 if (orinoco_lock(priv, &flags) != 0) {
854 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
856 return NETDEV_TX_BUSY;
859 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
860 /* Oops, the firmware hasn't established a connection,
861 silently drop the packet (this seems to be the
866 /* Check packet length */
867 if (skb->len < ETH_HLEN)
870 tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
872 if (priv->encode_alg == IW_ENCODE_ALG_TKIP)
873 tx_control |= (priv->tx_key << HERMES_MIC_KEY_ID_SHIFT) |
876 if (priv->has_alt_txcntl) {
877 /* WPA enabled firmwares have tx_cntl at the end of
878 * the 802.11 header. So write zeroed descriptor and
879 * 802.11 header at the same time
881 char desc[HERMES_802_3_OFFSET];
882 __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
884 memset(&desc, 0, sizeof(desc));
886 *txcntl = cpu_to_le16(tx_control);
887 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
891 printk(KERN_ERR "%s: Error %d writing Tx "
892 "descriptor to BAP\n", dev->name, err);
896 struct hermes_tx_descriptor desc;
898 memset(&desc, 0, sizeof(desc));
900 desc.tx_control = cpu_to_le16(tx_control);
901 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
905 printk(KERN_ERR "%s: Error %d writing Tx "
906 "descriptor to BAP\n", dev->name, err);
910 /* Clear the 802.11 header and data length fields - some
911 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
912 * if this isn't done. */
913 hermes_clear_words(hw, HERMES_DATA0,
914 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
917 eh = (struct ethhdr *)skb->data;
919 /* Encapsulate Ethernet-II frames */
920 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
921 struct header_struct {
922 struct ethhdr eth; /* 802.3 header */
923 u8 encap[6]; /* 802.2 header */
924 } __attribute__ ((packed)) hdr;
926 /* Strip destination and source from the data */
927 skb_pull(skb, 2 * ETH_ALEN);
929 /* And move them to a separate header */
930 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
931 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
932 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
934 /* Insert the SNAP header */
935 if (skb_headroom(skb) < sizeof(hdr)) {
937 "%s: Not enough headroom for 802.2 headers %d\n",
938 dev->name, skb_headroom(skb));
941 eh = (struct ethhdr *) skb_push(skb, sizeof(hdr));
942 memcpy(eh, &hdr, sizeof(hdr));
945 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
946 txfid, HERMES_802_3_OFFSET);
948 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
953 /* Calculate Michael MIC */
954 if (priv->encode_alg == IW_ENCODE_ALG_TKIP) {
955 u8 mic_buf[MICHAEL_MIC_LEN + 1];
961 /* MIC start is on an odd boundary */
962 mic_buf[0] = skb->data[skb->len - 1];
964 offset = skb->len - 1;
965 len = MICHAEL_MIC_LEN + 1;
969 len = MICHAEL_MIC_LEN;
972 michael_mic(priv->tx_tfm_mic,
973 priv->tkip_key[priv->tx_key].tx_mic,
974 eh->h_dest, eh->h_source, 0 /* priority */,
975 skb->data + ETH_HLEN, skb->len - ETH_HLEN, mic);
978 err = hermes_bap_pwrite(hw, USER_BAP, &mic_buf[0], len,
979 txfid, HERMES_802_3_OFFSET + offset);
981 printk(KERN_ERR "%s: Error %d writing MIC to BAP\n",
987 /* Finally, we actually initiate the send */
988 netif_stop_queue(dev);
990 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
993 netif_start_queue(dev);
995 printk(KERN_ERR "%s: Error %d transmitting packet\n",
1000 dev->trans_start = jiffies;
1001 stats->tx_bytes += HERMES_802_3_OFFSET + skb->len;
1006 stats->tx_dropped++;
1009 orinoco_unlock(priv, &flags);
1011 return NETDEV_TX_OK;
1015 schedule_work(&priv->reset_work);
1016 orinoco_unlock(priv, &flags);
1017 return NETDEV_TX_BUSY;
1020 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
1022 struct orinoco_private *priv = netdev_priv(dev);
1023 u16 fid = hermes_read_regn(hw, ALLOCFID);
1025 if (fid != priv->txfid) {
1026 if (fid != DUMMY_FID)
1027 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
1032 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
1035 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
1037 struct orinoco_private *priv = netdev_priv(dev);
1038 struct net_device_stats *stats = &priv->stats;
1040 stats->tx_packets++;
1042 netif_wake_queue(dev);
1044 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
1047 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
1049 struct orinoco_private *priv = netdev_priv(dev);
1050 struct net_device_stats *stats = &priv->stats;
1051 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
1053 struct hermes_txexc_data hdr;
1056 if (fid == DUMMY_FID)
1057 return; /* Nothing's really happened */
1059 /* Read part of the frame header - we need status and addr1 */
1060 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
1061 sizeof(struct hermes_txexc_data),
1064 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
1068 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
1069 "(FID=%04X error %d)\n",
1070 dev->name, fid, err);
1074 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
1077 /* We produce a TXDROP event only for retry or lifetime
1078 * exceeded, because that's the only status that really mean
1079 * that this particular node went away.
1080 * Other errors means that *we* screwed up. - Jean II */
1081 status = le16_to_cpu(hdr.desc.status);
1082 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
1083 union iwreq_data wrqu;
1085 /* Copy 802.11 dest address.
1086 * We use the 802.11 header because the frame may
1087 * not be 802.3 or may be mangled...
1088 * In Ad-Hoc mode, it will be the node address.
1089 * In managed mode, it will be most likely the AP addr
1090 * User space will figure out how to convert it to
1091 * whatever it needs (IP address or else).
1093 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
1094 wrqu.addr.sa_family = ARPHRD_ETHER;
1096 /* Send event to user space */
1097 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
1100 netif_wake_queue(dev);
1103 static void orinoco_tx_timeout(struct net_device *dev)
1105 struct orinoco_private *priv = netdev_priv(dev);
1106 struct net_device_stats *stats = &priv->stats;
1107 struct hermes *hw = &priv->hw;
1109 printk(KERN_WARNING "%s: Tx timeout! "
1110 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
1111 dev->name, hermes_read_regn(hw, ALLOCFID),
1112 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
1116 schedule_work(&priv->reset_work);
1119 /********************************************************************/
1120 /* Rx path (data frames) */
1121 /********************************************************************/
1123 /* Does the frame have a SNAP header indicating it should be
1124 * de-encapsulated to Ethernet-II? */
1125 static inline int is_ethersnap(void *_hdr)
1129 /* We de-encapsulate all packets which, a) have SNAP headers
1130 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
1131 * and where b) the OUI of the SNAP header is 00:00:00 or
1132 * 00:00:f8 - we need both because different APs appear to use
1133 * different OUIs for some reason */
1134 return (memcmp(hdr, &encaps_hdr, 5) == 0)
1135 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
1138 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
1139 int level, int noise)
1141 struct iw_quality wstats;
1142 wstats.level = level - 0x95;
1143 wstats.noise = noise - 0x95;
1144 wstats.qual = (level > noise) ? (level - noise) : 0;
1146 /* Update spy records */
1147 wireless_spy_update(dev, mac, &wstats);
1150 static void orinoco_stat_gather(struct net_device *dev,
1151 struct sk_buff *skb,
1152 struct hermes_rx_descriptor *desc)
1154 struct orinoco_private *priv = netdev_priv(dev);
1156 /* Using spy support with lots of Rx packets, like in an
1157 * infrastructure (AP), will really slow down everything, because
1158 * the MAC address must be compared to each entry of the spy list.
1159 * If the user really asks for it (set some address in the
1160 * spy list), we do it, but he will pay the price.
1161 * Note that to get here, you need both WIRELESS_SPY
1162 * compiled in AND some addresses in the list !!!
1164 /* Note : gcc will optimise the whole section away if
1165 * WIRELESS_SPY is not defined... - Jean II */
1166 if (SPY_NUMBER(priv)) {
1167 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
1168 desc->signal, desc->silence);
1173 * orinoco_rx_monitor - handle received monitor frames.
1176 * dev network device
1177 * rxfid received FID
1178 * desc rx descriptor of the frame
1180 * Call context: interrupt
1182 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
1183 struct hermes_rx_descriptor *desc)
1185 u32 hdrlen = 30; /* return full header by default */
1190 struct sk_buff *skb;
1191 struct orinoco_private *priv = netdev_priv(dev);
1192 struct net_device_stats *stats = &priv->stats;
1193 hermes_t *hw = &priv->hw;
1195 len = le16_to_cpu(desc->data_len);
1197 /* Determine the size of the header and the data */
1198 fc = le16_to_cpu(desc->frame_ctl);
1199 switch (fc & IEEE80211_FCTL_FTYPE) {
1200 case IEEE80211_FTYPE_DATA:
1201 if ((fc & IEEE80211_FCTL_TODS)
1202 && (fc & IEEE80211_FCTL_FROMDS))
1208 case IEEE80211_FTYPE_MGMT:
1212 case IEEE80211_FTYPE_CTL:
1213 switch (fc & IEEE80211_FCTL_STYPE) {
1214 case IEEE80211_STYPE_PSPOLL:
1215 case IEEE80211_STYPE_RTS:
1216 case IEEE80211_STYPE_CFEND:
1217 case IEEE80211_STYPE_CFENDACK:
1220 case IEEE80211_STYPE_CTS:
1221 case IEEE80211_STYPE_ACK:
1227 /* Unknown frame type */
1231 /* sanity check the length */
1232 if (datalen > IEEE80211_DATA_LEN + 12) {
1233 printk(KERN_DEBUG "%s: oversized monitor frame, "
1234 "data length = %d\n", dev->name, datalen);
1235 stats->rx_length_errors++;
1239 skb = dev_alloc_skb(hdrlen + datalen);
1241 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
1246 /* Copy the 802.11 header to the skb */
1247 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
1248 skb_reset_mac_header(skb);
1250 /* If any, copy the data from the card to the skb */
1252 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
1253 ALIGN(datalen, 2), rxfid,
1254 HERMES_802_2_OFFSET);
1256 printk(KERN_ERR "%s: error %d reading monitor frame\n",
1263 skb->ip_summed = CHECKSUM_NONE;
1264 skb->pkt_type = PACKET_OTHERHOST;
1265 skb->protocol = __constant_htons(ETH_P_802_2);
1267 dev->last_rx = jiffies;
1268 stats->rx_packets++;
1269 stats->rx_bytes += skb->len;
1275 dev_kfree_skb_irq(skb);
1278 stats->rx_dropped++;
1281 /* Get tsc from the firmware */
1282 static int orinoco_hw_get_tkip_iv(struct orinoco_private *priv, int key,
1285 hermes_t *hw = &priv->hw;
1287 u8 tsc_arr[4][IW_ENCODE_SEQ_MAX_SIZE];
1289 if ((key < 0) || (key > 4))
1292 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENT_TKIP_IV,
1293 sizeof(tsc_arr), NULL, &tsc_arr);
1295 memcpy(tsc, &tsc_arr[key][0], sizeof(tsc_arr[0]));
1300 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1302 struct orinoco_private *priv = netdev_priv(dev);
1303 struct net_device_stats *stats = &priv->stats;
1304 struct iw_statistics *wstats = &priv->wstats;
1305 struct sk_buff *skb = NULL;
1308 struct hermes_rx_descriptor *desc;
1309 struct orinoco_rx_data *rx_data;
1312 desc = kmalloc(sizeof(*desc), GFP_ATOMIC);
1315 "%s: Can't allocate space for RX descriptor\n",
1320 rxfid = hermes_read_regn(hw, RXFID);
1322 err = hermes_bap_pread(hw, IRQ_BAP, desc, sizeof(*desc),
1325 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
1326 "Frame dropped.\n", dev->name, err);
1330 status = le16_to_cpu(desc->status);
1332 if (status & HERMES_RXSTAT_BADCRC) {
1333 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
1335 stats->rx_crc_errors++;
1339 /* Handle frames in monitor mode */
1340 if (priv->iw_mode == IW_MODE_MONITOR) {
1341 orinoco_rx_monitor(dev, rxfid, desc);
1345 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
1346 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1348 wstats->discard.code++;
1352 length = le16_to_cpu(desc->data_len);
1355 if (length < 3) { /* No for even an 802.2 LLC header */
1356 /* At least on Symbol firmware with PCF we get quite a
1357 lot of these legitimately - Poll frames with no
1361 if (length > IEEE80211_DATA_LEN) {
1362 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1364 stats->rx_length_errors++;
1368 /* Payload size does not include Michael MIC. Increase payload
1369 * size to read it together with the data. */
1370 if (status & HERMES_RXSTAT_MIC)
1371 length += MICHAEL_MIC_LEN;
1373 /* We need space for the packet data itself, plus an ethernet
1374 header, plus 2 bytes so we can align the IP header on a
1375 32bit boundary, plus 1 byte so we can read in odd length
1376 packets from the card, which has an IO granularity of 16
1378 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
1380 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1385 /* We'll prepend the header, so reserve space for it. The worst
1386 case is no decapsulation, when 802.3 header is prepended and
1387 nothing is removed. 2 is for aligning the IP header. */
1388 skb_reserve(skb, ETH_HLEN + 2);
1390 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
1391 ALIGN(length, 2), rxfid,
1392 HERMES_802_2_OFFSET);
1394 printk(KERN_ERR "%s: error %d reading frame. "
1395 "Frame dropped.\n", dev->name, err);
1399 /* Add desc and skb to rx queue */
1400 rx_data = kzalloc(sizeof(*rx_data), GFP_ATOMIC);
1402 printk(KERN_WARNING "%s: Can't allocate RX packet\n",
1406 rx_data->desc = desc;
1408 list_add_tail(&rx_data->list, &priv->rx_list);
1409 tasklet_schedule(&priv->rx_tasklet);
1414 dev_kfree_skb_irq(skb);
1417 stats->rx_dropped++;
1422 static void orinoco_rx(struct net_device *dev,
1423 struct hermes_rx_descriptor *desc,
1424 struct sk_buff *skb)
1426 struct orinoco_private *priv = netdev_priv(dev);
1427 struct net_device_stats *stats = &priv->stats;
1432 status = le16_to_cpu(desc->status);
1433 length = le16_to_cpu(desc->data_len);
1434 fc = le16_to_cpu(desc->frame_ctl);
1436 /* Calculate and check MIC */
1437 if (status & HERMES_RXSTAT_MIC) {
1438 int key_id = ((status & HERMES_RXSTAT_MIC_KEY_ID) >>
1439 HERMES_MIC_KEY_ID_SHIFT);
1440 u8 mic[MICHAEL_MIC_LEN];
1442 u8 *src = (fc & IEEE80211_FCTL_FROMDS) ?
1443 desc->addr3 : desc->addr2;
1445 /* Extract Michael MIC from payload */
1446 rxmic = skb->data + skb->len - MICHAEL_MIC_LEN;
1448 skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
1449 length -= MICHAEL_MIC_LEN;
1451 michael_mic(priv->rx_tfm_mic,
1452 priv->tkip_key[key_id].rx_mic,
1455 0, /* priority or QoS? */
1460 if (memcmp(mic, rxmic,
1462 union iwreq_data wrqu;
1463 struct iw_michaelmicfailure wxmic;
1464 DECLARE_MAC_BUF(mac);
1466 printk(KERN_WARNING "%s: "
1467 "Invalid Michael MIC in data frame from %s, "
1469 dev->name, print_mac(mac, src), key_id);
1471 /* TODO: update stats */
1473 /* Notify userspace */
1474 memset(&wxmic, 0, sizeof(wxmic));
1475 wxmic.flags = key_id & IW_MICFAILURE_KEY_ID;
1476 wxmic.flags |= (desc->addr1[0] & 1) ?
1477 IW_MICFAILURE_GROUP : IW_MICFAILURE_PAIRWISE;
1478 wxmic.src_addr.sa_family = ARPHRD_ETHER;
1479 memcpy(wxmic.src_addr.sa_data, src, ETH_ALEN);
1481 (void) orinoco_hw_get_tkip_iv(priv, key_id,
1484 memset(&wrqu, 0, sizeof(wrqu));
1485 wrqu.data.length = sizeof(wxmic);
1486 wireless_send_event(dev, IWEVMICHAELMICFAILURE, &wrqu,
1493 /* Handle decapsulation
1494 * In most cases, the firmware tell us about SNAP frames.
1495 * For some reason, the SNAP frames sent by LinkSys APs
1496 * are not properly recognised by most firmwares.
1497 * So, check ourselves */
1498 if (length >= ENCAPS_OVERHEAD &&
1499 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1500 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
1501 is_ethersnap(skb->data))) {
1502 /* These indicate a SNAP within 802.2 LLC within
1503 802.11 frame which we'll need to de-encapsulate to
1504 the original EthernetII frame. */
1505 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
1507 /* 802.3 frame - prepend 802.3 header as is */
1508 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
1509 hdr->h_proto = htons(length);
1511 memcpy(hdr->h_dest, desc->addr1, ETH_ALEN);
1512 if (fc & IEEE80211_FCTL_FROMDS)
1513 memcpy(hdr->h_source, desc->addr3, ETH_ALEN);
1515 memcpy(hdr->h_source, desc->addr2, ETH_ALEN);
1517 dev->last_rx = jiffies;
1518 skb->protocol = eth_type_trans(skb, dev);
1519 skb->ip_summed = CHECKSUM_NONE;
1520 if (fc & IEEE80211_FCTL_TODS)
1521 skb->pkt_type = PACKET_OTHERHOST;
1523 /* Process the wireless stats if needed */
1524 orinoco_stat_gather(dev, skb, desc);
1526 /* Pass the packet to the networking stack */
1528 stats->rx_packets++;
1529 stats->rx_bytes += length;
1536 stats->rx_dropped++;
1539 static void orinoco_rx_isr_tasklet(unsigned long data)
1541 struct net_device *dev = (struct net_device *) data;
1542 struct orinoco_private *priv = netdev_priv(dev);
1543 struct orinoco_rx_data *rx_data, *temp;
1544 struct hermes_rx_descriptor *desc;
1545 struct sk_buff *skb;
1547 /* extract desc and skb from queue */
1548 list_for_each_entry_safe(rx_data, temp, &priv->rx_list, list) {
1549 desc = rx_data->desc;
1551 list_del(&rx_data->list);
1554 orinoco_rx(dev, desc, skb);
1560 /********************************************************************/
1561 /* Rx path (info frames) */
1562 /********************************************************************/
1564 static void print_linkstatus(struct net_device *dev, u16 status)
1568 if (suppress_linkstatus)
1572 case HERMES_LINKSTATUS_NOT_CONNECTED:
1573 s = "Not Connected";
1575 case HERMES_LINKSTATUS_CONNECTED:
1578 case HERMES_LINKSTATUS_DISCONNECTED:
1581 case HERMES_LINKSTATUS_AP_CHANGE:
1584 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1585 s = "AP Out of Range";
1587 case HERMES_LINKSTATUS_AP_IN_RANGE:
1590 case HERMES_LINKSTATUS_ASSOC_FAILED:
1591 s = "Association Failed";
1597 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1598 dev->name, s, status);
1601 /* Search scan results for requested BSSID, join it if found */
1602 static void orinoco_join_ap(struct work_struct *work)
1604 struct orinoco_private *priv =
1605 container_of(work, struct orinoco_private, join_work);
1606 struct net_device *dev = priv->ndev;
1607 struct hermes *hw = &priv->hw;
1609 unsigned long flags;
1613 } __attribute__ ((packed)) req;
1614 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1615 struct prism2_scan_apinfo *atom = NULL;
1621 /* Allocate buffer for scan results */
1622 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1626 if (orinoco_lock(priv, &flags) != 0)
1629 /* Sanity checks in case user changed something in the meantime */
1630 if (! priv->bssid_fixed)
1633 if (strlen(priv->desired_essid) == 0)
1636 /* Read scan results from the firmware */
1637 err = hermes_read_ltv(hw, USER_BAP,
1638 HERMES_RID_SCANRESULTSTABLE,
1639 MAX_SCAN_LEN, &len, buf);
1641 printk(KERN_ERR "%s: Cannot read scan results\n",
1646 len = HERMES_RECLEN_TO_BYTES(len);
1648 /* Go through the scan results looking for the channel of the AP
1649 * we were requested to join */
1650 for (; offset + atom_len <= len; offset += atom_len) {
1651 atom = (struct prism2_scan_apinfo *) (buf + offset);
1652 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1659 DEBUG(1, "%s: Requested AP not found in scan results\n",
1664 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1665 req.channel = atom->channel; /* both are little-endian */
1666 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1669 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1672 orinoco_unlock(priv, &flags);
1678 /* Send new BSSID to userspace */
1679 static void orinoco_send_bssid_wevent(struct orinoco_private *priv)
1681 struct net_device *dev = priv->ndev;
1682 struct hermes *hw = &priv->hw;
1683 union iwreq_data wrqu;
1686 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1687 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1691 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1693 /* Send event to user space */
1694 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1697 static void orinoco_send_assocreqie_wevent(struct orinoco_private *priv)
1699 struct net_device *dev = priv->ndev;
1700 struct hermes *hw = &priv->hw;
1701 union iwreq_data wrqu;
1709 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENT_ASSOC_REQ_INFO,
1710 sizeof(buf), NULL, &buf);
1714 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1716 int rem = sizeof(buf) - (ie - &buf[0]);
1717 wrqu.data.length = ie[1] + 2;
1718 if (wrqu.data.length > rem)
1719 wrqu.data.length = rem;
1721 if (wrqu.data.length)
1722 /* Send event to user space */
1723 wireless_send_event(dev, IWEVASSOCREQIE, &wrqu, ie);
1727 static void orinoco_send_assocrespie_wevent(struct orinoco_private *priv)
1729 struct net_device *dev = priv->ndev;
1730 struct hermes *hw = &priv->hw;
1731 union iwreq_data wrqu;
1733 u8 buf[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1739 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENT_ASSOC_RESP_INFO,
1740 sizeof(buf), NULL, &buf);
1744 ie = orinoco_get_wpa_ie(buf, sizeof(buf));
1746 int rem = sizeof(buf) - (ie - &buf[0]);
1747 wrqu.data.length = ie[1] + 2;
1748 if (wrqu.data.length > rem)
1749 wrqu.data.length = rem;
1751 if (wrqu.data.length)
1752 /* Send event to user space */
1753 wireless_send_event(dev, IWEVASSOCRESPIE, &wrqu, ie);
1757 static void orinoco_send_wevents(struct work_struct *work)
1759 struct orinoco_private *priv =
1760 container_of(work, struct orinoco_private, wevent_work);
1761 unsigned long flags;
1763 if (orinoco_lock(priv, &flags) != 0)
1766 orinoco_send_assocreqie_wevent(priv);
1767 orinoco_send_assocrespie_wevent(priv);
1768 orinoco_send_bssid_wevent(priv);
1770 orinoco_unlock(priv, &flags);
1773 static inline void orinoco_clear_scan_results(struct orinoco_private *priv,
1774 unsigned long scan_age)
1776 if (priv->has_ext_scan) {
1777 struct xbss_element *bss;
1778 struct xbss_element *tmp_bss;
1780 /* Blow away current list of scan results */
1781 list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
1783 time_after(jiffies, bss->last_scanned + scan_age)) {
1784 list_move_tail(&bss->list,
1785 &priv->bss_free_list);
1786 /* Don't blow away ->list, just BSS data */
1787 memset(&bss->bss, 0, sizeof(bss->bss));
1788 bss->last_scanned = 0;
1792 struct bss_element *bss;
1793 struct bss_element *tmp_bss;
1795 /* Blow away current list of scan results */
1796 list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
1798 time_after(jiffies, bss->last_scanned + scan_age)) {
1799 list_move_tail(&bss->list,
1800 &priv->bss_free_list);
1801 /* Don't blow away ->list, just BSS data */
1802 memset(&bss->bss, 0, sizeof(bss->bss));
1803 bss->last_scanned = 0;
1809 static void orinoco_add_ext_scan_result(struct orinoco_private *priv,
1810 struct agere_ext_scan_info *atom)
1812 struct xbss_element *bss = NULL;
1815 /* Try to update an existing bss first */
1816 list_for_each_entry(bss, &priv->bss_list, list) {
1817 if (compare_ether_addr(bss->bss.bssid, atom->bssid))
1820 if (bss->bss.data[1] != atom->data[1])
1822 if (memcmp(&bss->bss.data[2], &atom->data[2],
1829 /* Grab a bss off the free list */
1830 if (!found && !list_empty(&priv->bss_free_list)) {
1831 bss = list_entry(priv->bss_free_list.next,
1832 struct xbss_element, list);
1833 list_del(priv->bss_free_list.next);
1835 list_add_tail(&bss->list, &priv->bss_list);
1839 /* Always update the BSS to get latest beacon info */
1840 memcpy(&bss->bss, atom, sizeof(bss->bss));
1841 bss->last_scanned = jiffies;
1845 static int orinoco_process_scan_results(struct net_device *dev,
1849 struct orinoco_private *priv = netdev_priv(dev);
1850 int offset; /* In the scan data */
1851 union hermes_scan_info *atom;
1854 switch (priv->firmware_type) {
1855 case FIRMWARE_TYPE_AGERE:
1856 atom_len = sizeof(struct agere_scan_apinfo);
1859 case FIRMWARE_TYPE_SYMBOL:
1860 /* Lack of documentation necessitates this hack.
1861 * Different firmwares have 68 or 76 byte long atoms.
1862 * We try modulo first. If the length divides by both,
1863 * we check what would be the channel in the second
1864 * frame for a 68-byte atom. 76-byte atoms have 0 there.
1865 * Valid channel cannot be 0. */
1870 else if (len >= 1292 && buf[68] == 0)
1876 case FIRMWARE_TYPE_INTERSIL:
1878 if (priv->has_hostscan) {
1879 atom_len = le16_to_cpup((__le16 *)buf);
1880 /* Sanity check for atom_len */
1881 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
1882 printk(KERN_ERR "%s: Invalid atom_len in scan "
1883 "data: %d\n", dev->name, atom_len);
1887 atom_len = offsetof(struct prism2_scan_apinfo, atim);
1893 /* Check that we got an whole number of atoms */
1894 if ((len - offset) % atom_len) {
1895 printk(KERN_ERR "%s: Unexpected scan data length %d, "
1896 "atom_len %d, offset %d\n", dev->name, len,
1901 orinoco_clear_scan_results(priv, msecs_to_jiffies(15000));
1903 /* Read the entries one by one */
1904 for (; offset + atom_len <= len; offset += atom_len) {
1906 struct bss_element *bss = NULL;
1909 atom = (union hermes_scan_info *) (buf + offset);
1911 /* Try to update an existing bss first */
1912 list_for_each_entry(bss, &priv->bss_list, list) {
1913 if (compare_ether_addr(bss->bss.a.bssid, atom->a.bssid))
1915 if (le16_to_cpu(bss->bss.a.essid_len) !=
1916 le16_to_cpu(atom->a.essid_len))
1918 if (memcmp(bss->bss.a.essid, atom->a.essid,
1919 le16_to_cpu(atom->a.essid_len)))
1925 /* Grab a bss off the free list */
1926 if (!found && !list_empty(&priv->bss_free_list)) {
1927 bss = list_entry(priv->bss_free_list.next,
1928 struct bss_element, list);
1929 list_del(priv->bss_free_list.next);
1931 list_add_tail(&bss->list, &priv->bss_list);
1935 /* Always update the BSS to get latest beacon info */
1936 memcpy(&bss->bss, atom, sizeof(bss->bss));
1937 bss->last_scanned = jiffies;
1944 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1946 struct orinoco_private *priv = netdev_priv(dev);
1951 } __attribute__ ((packed)) info;
1955 /* This is an answer to an INQUIRE command that we did earlier,
1956 * or an information "event" generated by the card
1957 * The controller return to us a pseudo frame containing
1958 * the information in question - Jean II */
1959 infofid = hermes_read_regn(hw, INFOFID);
1961 /* Read the info frame header - don't try too hard */
1962 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1965 printk(KERN_ERR "%s: error %d reading info frame. "
1966 "Frame dropped.\n", dev->name, err);
1970 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1971 type = le16_to_cpu(info.type);
1974 case HERMES_INQ_TALLIES: {
1975 struct hermes_tallies_frame tallies;
1976 struct iw_statistics *wstats = &priv->wstats;
1978 if (len > sizeof(tallies)) {
1979 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1981 len = sizeof(tallies);
1984 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1985 infofid, sizeof(info));
1989 /* Increment our various counters */
1990 /* wstats->discard.nwid - no wrong BSSID stuff */
1991 wstats->discard.code +=
1992 le16_to_cpu(tallies.RxWEPUndecryptable);
1993 if (len == sizeof(tallies))
1994 wstats->discard.code +=
1995 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1996 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1997 wstats->discard.misc +=
1998 le16_to_cpu(tallies.TxDiscardsWrongSA);
1999 wstats->discard.fragment +=
2000 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
2001 wstats->discard.retries +=
2002 le16_to_cpu(tallies.TxRetryLimitExceeded);
2003 /* wstats->miss.beacon - no match */
2006 case HERMES_INQ_LINKSTATUS: {
2007 struct hermes_linkstatus linkstatus;
2011 if (priv->iw_mode == IW_MODE_MONITOR)
2014 if (len != sizeof(linkstatus)) {
2015 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
2020 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
2021 infofid, sizeof(info));
2024 newstatus = le16_to_cpu(linkstatus.linkstatus);
2026 /* Symbol firmware uses "out of range" to signal that
2027 * the hostscan frame can be requested. */
2028 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
2029 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
2030 priv->has_hostscan && priv->scan_inprogress) {
2031 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
2035 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
2036 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
2037 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
2040 netif_carrier_on(dev);
2041 else if (!ignore_disconnect)
2042 netif_carrier_off(dev);
2044 if (newstatus != priv->last_linkstatus) {
2045 priv->last_linkstatus = newstatus;
2046 print_linkstatus(dev, newstatus);
2047 /* The info frame contains only one word which is the
2048 * status (see hermes.h). The status is pretty boring
2049 * in itself, that's why we export the new BSSID...
2051 schedule_work(&priv->wevent_work);
2055 case HERMES_INQ_SCAN:
2056 if (!priv->scan_inprogress && priv->bssid_fixed &&
2057 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
2058 schedule_work(&priv->join_work);
2062 case HERMES_INQ_HOSTSCAN:
2063 case HERMES_INQ_HOSTSCAN_SYMBOL: {
2064 /* Result of a scanning. Contains information about
2065 * cells in the vicinity - Jean II */
2066 union iwreq_data wrqu;
2069 /* Scan is no longer in progress */
2070 priv->scan_inprogress = 0;
2074 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
2079 /* Allocate buffer for results */
2080 buf = kmalloc(len, GFP_ATOMIC);
2082 /* No memory, so can't printk()... */
2085 /* Read scan data */
2086 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
2087 infofid, sizeof(info));
2093 #ifdef ORINOCO_DEBUG
2096 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
2097 for(i = 1; i < (len * 2); i++)
2098 printk(":%02X", buf[i]);
2101 #endif /* ORINOCO_DEBUG */
2103 if (orinoco_process_scan_results(dev, buf, len) == 0) {
2104 /* Send an empty event to user space.
2105 * We don't send the received data on the event because
2106 * it would require us to do complex transcoding, and
2107 * we want to minimise the work done in the irq handler
2108 * Use a request to extract the data - Jean II */
2109 wrqu.data.length = 0;
2110 wrqu.data.flags = 0;
2111 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
2116 case HERMES_INQ_CHANNELINFO:
2118 struct agere_ext_scan_info *bss;
2120 if (!priv->scan_inprogress) {
2121 printk(KERN_DEBUG "%s: Got chaninfo without scan, "
2122 "len=%d\n", dev->name, len);
2126 /* An empty result indicates that the scan is complete */
2128 union iwreq_data wrqu;
2130 /* Scan is no longer in progress */
2131 priv->scan_inprogress = 0;
2133 wrqu.data.length = 0;
2134 wrqu.data.flags = 0;
2135 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
2140 else if (len > sizeof(*bss)) {
2142 "%s: Ext scan results too large (%d bytes). "
2143 "Truncating results to %zd bytes.\n",
2144 dev->name, len, sizeof(*bss));
2146 } else if (len < (offsetof(struct agere_ext_scan_info,
2148 /* Drop this result now so we don't have to
2149 * keep checking later */
2151 "%s: Ext scan results too short (%d bytes)\n",
2156 bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
2160 /* Read scan data */
2161 err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
2162 infofid, sizeof(info));
2168 orinoco_add_ext_scan_result(priv, bss);
2173 case HERMES_INQ_SEC_STAT_AGERE:
2174 /* Security status (Agere specific) */
2175 /* Ignore this frame for now */
2176 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
2180 printk(KERN_DEBUG "%s: Unknown information frame received: "
2181 "type 0x%04x, length %d\n", dev->name, type, len);
2182 /* We don't actually do anything about it */
2187 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
2189 if (net_ratelimit())
2190 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
2193 /********************************************************************/
2194 /* Internal hardware control routines */
2195 /********************************************************************/
2197 int __orinoco_up(struct net_device *dev)
2199 struct orinoco_private *priv = netdev_priv(dev);
2200 struct hermes *hw = &priv->hw;
2203 netif_carrier_off(dev); /* just to make sure */
2205 err = __orinoco_program_rids(dev);
2207 printk(KERN_ERR "%s: Error %d configuring card\n",
2212 /* Fire things up again */
2213 hermes_set_irqmask(hw, ORINOCO_INTEN);
2214 err = hermes_enable_port(hw, 0);
2216 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
2221 netif_start_queue(dev);
2226 int __orinoco_down(struct net_device *dev)
2228 struct orinoco_private *priv = netdev_priv(dev);
2229 struct hermes *hw = &priv->hw;
2232 netif_stop_queue(dev);
2234 if (! priv->hw_unavailable) {
2235 if (! priv->broken_disableport) {
2236 err = hermes_disable_port(hw, 0);
2238 /* Some firmwares (e.g. Intersil 1.3.x) seem
2239 * to have problems disabling the port, oh
2241 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
2243 priv->broken_disableport = 1;
2246 hermes_set_irqmask(hw, 0);
2247 hermes_write_regn(hw, EVACK, 0xffff);
2250 /* firmware will have to reassociate */
2251 netif_carrier_off(dev);
2252 priv->last_linkstatus = 0xffff;
2257 static int orinoco_allocate_fid(struct net_device *dev)
2259 struct orinoco_private *priv = netdev_priv(dev);
2260 struct hermes *hw = &priv->hw;
2263 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
2264 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
2265 /* Try workaround for old Symbol firmware bug */
2266 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
2267 "(old Symbol firmware?). Trying to work around... ",
2270 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
2271 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
2273 printk("failed!\n");
2281 int orinoco_reinit_firmware(struct net_device *dev)
2283 struct orinoco_private *priv = netdev_priv(dev);
2284 struct hermes *hw = &priv->hw;
2287 err = hermes_init(hw);
2289 err = orinoco_allocate_fid(dev);
2294 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
2296 hermes_t *hw = &priv->hw;
2299 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
2300 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
2301 priv->ndev->name, priv->bitratemode);
2305 switch (priv->firmware_type) {
2306 case FIRMWARE_TYPE_AGERE:
2307 err = hermes_write_wordrec(hw, USER_BAP,
2308 HERMES_RID_CNFTXRATECONTROL,
2309 bitrate_table[priv->bitratemode].agere_txratectrl);
2311 case FIRMWARE_TYPE_INTERSIL:
2312 case FIRMWARE_TYPE_SYMBOL:
2313 err = hermes_write_wordrec(hw, USER_BAP,
2314 HERMES_RID_CNFTXRATECONTROL,
2315 bitrate_table[priv->bitratemode].intersil_txratectrl);
2324 /* Set fixed AP address */
2325 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
2329 hermes_t *hw = &priv->hw;
2331 switch (priv->firmware_type) {
2332 case FIRMWARE_TYPE_AGERE:
2335 case FIRMWARE_TYPE_INTERSIL:
2336 if (priv->bssid_fixed)
2341 err = hermes_write_wordrec(hw, USER_BAP,
2342 HERMES_RID_CNFROAMINGMODE,
2345 case FIRMWARE_TYPE_SYMBOL:
2346 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2347 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
2348 &priv->desired_bssid);
2354 /* Change the WEP keys and/or the current keys. Can be called
2355 * either from __orinoco_hw_setup_enc() or directly from
2356 * orinoco_ioctl_setiwencode(). In the later case the association
2357 * with the AP is not broken (if the firmware can handle it),
2358 * which is needed for 802.1x implementations. */
2359 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
2361 hermes_t *hw = &priv->hw;
2364 switch (priv->firmware_type) {
2365 case FIRMWARE_TYPE_AGERE:
2366 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2367 HERMES_RID_CNFWEPKEYS_AGERE,
2371 err = hermes_write_wordrec(hw, USER_BAP,
2372 HERMES_RID_CNFTXKEY_AGERE,
2377 case FIRMWARE_TYPE_INTERSIL:
2378 case FIRMWARE_TYPE_SYMBOL:
2383 /* Force uniform key length to work around firmware bugs */
2384 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
2386 if (keylen > LARGE_KEY_SIZE) {
2387 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
2388 priv->ndev->name, priv->tx_key, keylen);
2392 /* Write all 4 keys */
2393 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
2394 err = hermes_write_ltv(hw, USER_BAP,
2395 HERMES_RID_CNFDEFAULTKEY0 + i,
2396 HERMES_BYTES_TO_RECLEN(keylen),
2397 priv->keys[i].data);
2402 /* Write the index of the key used in transmission */
2403 err = hermes_write_wordrec(hw, USER_BAP,
2404 HERMES_RID_CNFWEPDEFAULTKEYID,
2415 static int __orinoco_hw_setup_enc(struct orinoco_private *priv)
2417 hermes_t *hw = &priv->hw;
2419 int master_wep_flag;
2423 /* Setup WEP keys for WEP and WPA */
2424 if (priv->encode_alg)
2425 __orinoco_hw_setup_wepkeys(priv);
2427 if (priv->wep_restrict)
2428 auth_flag = HERMES_AUTH_SHARED_KEY;
2430 auth_flag = HERMES_AUTH_OPEN;
2432 if (priv->wpa_enabled)
2434 else if (priv->encode_alg == IW_ENCODE_ALG_WEP)
2439 switch (priv->firmware_type) {
2440 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
2441 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
2442 /* Enable the shared-key authentication. */
2443 err = hermes_write_wordrec(hw, USER_BAP,
2444 HERMES_RID_CNFAUTHENTICATION_AGERE,
2447 err = hermes_write_wordrec(hw, USER_BAP,
2448 HERMES_RID_CNFWEPENABLED_AGERE,
2453 if (priv->has_wpa) {
2454 /* Set WPA key management */
2455 err = hermes_write_wordrec(hw, USER_BAP,
2456 HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE,
2464 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
2465 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
2466 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
2467 if (priv->wep_restrict ||
2468 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
2469 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
2470 HERMES_WEP_EXCL_UNENCRYPTED;
2472 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
2474 err = hermes_write_wordrec(hw, USER_BAP,
2475 HERMES_RID_CNFAUTHENTICATION,
2480 master_wep_flag = 0;
2482 if (priv->iw_mode == IW_MODE_MONITOR)
2483 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
2485 /* Master WEP setting : on/off */
2486 err = hermes_write_wordrec(hw, USER_BAP,
2487 HERMES_RID_CNFWEPFLAGS_INTERSIL,
2498 /* key must be 32 bytes, including the tx and rx MIC keys.
2499 * rsc must be 8 bytes
2500 * tsc must be 8 bytes or NULL
2502 static int __orinoco_hw_set_tkip_key(hermes_t *hw, int key_idx, int set_tx,
2503 u8 *key, u8 *rsc, u8 *tsc)
2507 u8 rsc[IW_ENCODE_SEQ_MAX_SIZE];
2508 u8 key[TKIP_KEYLEN];
2509 u8 tx_mic[MIC_KEYLEN];
2510 u8 rx_mic[MIC_KEYLEN];
2511 u8 tsc[IW_ENCODE_SEQ_MAX_SIZE];
2512 } __attribute__ ((packed)) buf;
2523 buf.idx = cpu_to_le16(key_idx);
2524 memcpy(buf.key, key,
2525 sizeof(buf.key) + sizeof(buf.tx_mic) + sizeof(buf.rx_mic));
2528 memset(buf.rsc, 0, sizeof(buf.rsc));
2530 memcpy(buf.rsc, rsc, sizeof(buf.rsc));
2533 memset(buf.tsc, 0, sizeof(buf.tsc));
2536 memcpy(buf.tsc, tsc, sizeof(buf.tsc));
2539 /* Wait upto 100ms for tx queue to empty */
2544 ret = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_TXQUEUEEMPTY,
2548 } while ((k > 0) && xmitting);
2553 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2554 HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE,
2557 return ret ? ret : err;
2560 static int orinoco_clear_tkip_key(struct orinoco_private *priv,
2563 hermes_t *hw = &priv->hw;
2566 memset(&priv->tkip_key[key_idx], 0, sizeof(priv->tkip_key[key_idx]));
2567 err = hermes_write_wordrec(hw, USER_BAP,
2568 HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE,
2571 printk(KERN_WARNING "%s: Error %d clearing TKIP key %d\n",
2572 priv->ndev->name, err, key_idx);
2576 static int __orinoco_program_rids(struct net_device *dev)
2578 struct orinoco_private *priv = netdev_priv(dev);
2579 hermes_t *hw = &priv->hw;
2581 struct hermes_idstring idbuf;
2583 /* Set the MAC address */
2584 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2585 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
2587 printk(KERN_ERR "%s: Error %d setting MAC address\n",
2592 /* Set up the link mode */
2593 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
2596 printk(KERN_ERR "%s: Error %d setting port type\n",
2600 /* Set the channel/frequency */
2601 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
2602 err = hermes_write_wordrec(hw, USER_BAP,
2603 HERMES_RID_CNFOWNCHANNEL,
2606 printk(KERN_ERR "%s: Error %d setting channel %d\n",
2607 dev->name, err, priv->channel);
2612 if (priv->has_ibss) {
2615 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
2616 printk(KERN_WARNING "%s: This firmware requires an "
2617 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
2618 /* With wvlan_cs, in this case, we would crash.
2619 * hopefully, this driver will behave better...
2623 createibss = priv->createibss;
2626 err = hermes_write_wordrec(hw, USER_BAP,
2627 HERMES_RID_CNFCREATEIBSS,
2630 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
2636 /* Set the desired BSSID */
2637 err = __orinoco_hw_set_wap(priv);
2639 printk(KERN_ERR "%s: Error %d setting AP address\n",
2643 /* Set the desired ESSID */
2644 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
2645 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
2646 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
2647 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
2648 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2651 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
2655 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
2656 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2659 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
2664 /* Set the station name */
2665 idbuf.len = cpu_to_le16(strlen(priv->nick));
2666 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
2667 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2668 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
2671 printk(KERN_ERR "%s: Error %d setting nickname\n",
2676 /* Set AP density */
2677 if (priv->has_sensitivity) {
2678 err = hermes_write_wordrec(hw, USER_BAP,
2679 HERMES_RID_CNFSYSTEMSCALE,
2682 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
2683 "Disabling sensitivity control\n",
2686 priv->has_sensitivity = 0;
2690 /* Set RTS threshold */
2691 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2694 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
2699 /* Set fragmentation threshold or MWO robustness */
2701 err = hermes_write_wordrec(hw, USER_BAP,
2702 HERMES_RID_CNFMWOROBUST_AGERE,
2705 err = hermes_write_wordrec(hw, USER_BAP,
2706 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2709 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
2715 err = __orinoco_hw_set_bitrate(priv);
2717 printk(KERN_ERR "%s: Error %d setting bitrate\n",
2722 /* Set power management */
2724 err = hermes_write_wordrec(hw, USER_BAP,
2725 HERMES_RID_CNFPMENABLED,
2728 printk(KERN_ERR "%s: Error %d setting up PM\n",
2733 err = hermes_write_wordrec(hw, USER_BAP,
2734 HERMES_RID_CNFMULTICASTRECEIVE,
2737 printk(KERN_ERR "%s: Error %d setting up PM\n",
2741 err = hermes_write_wordrec(hw, USER_BAP,
2742 HERMES_RID_CNFMAXSLEEPDURATION,
2745 printk(KERN_ERR "%s: Error %d setting up PM\n",
2749 err = hermes_write_wordrec(hw, USER_BAP,
2750 HERMES_RID_CNFPMHOLDOVERDURATION,
2753 printk(KERN_ERR "%s: Error %d setting up PM\n",
2759 /* Set preamble - only for Symbol so far... */
2760 if (priv->has_preamble) {
2761 err = hermes_write_wordrec(hw, USER_BAP,
2762 HERMES_RID_CNFPREAMBLE_SYMBOL,
2765 printk(KERN_ERR "%s: Error %d setting preamble\n",
2771 /* Set up encryption */
2772 if (priv->has_wep || priv->has_wpa) {
2773 err = __orinoco_hw_setup_enc(priv);
2775 printk(KERN_ERR "%s: Error %d activating encryption\n",
2781 if (priv->iw_mode == IW_MODE_MONITOR) {
2782 /* Enable monitor mode */
2783 dev->type = ARPHRD_IEEE80211;
2784 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2785 HERMES_TEST_MONITOR, 0, NULL);
2787 /* Disable monitor mode */
2788 dev->type = ARPHRD_ETHER;
2789 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2790 HERMES_TEST_STOP, 0, NULL);
2795 /* Set promiscuity / multicast*/
2796 priv->promiscuous = 0;
2799 /* FIXME: what about netif_tx_lock */
2800 __orinoco_set_multicast_list(dev);
2805 /* FIXME: return int? */
2807 __orinoco_set_multicast_list(struct net_device *dev)
2809 struct orinoco_private *priv = netdev_priv(dev);
2810 hermes_t *hw = &priv->hw;
2812 int promisc, mc_count;
2814 /* The Hermes doesn't seem to have an allmulti mode, so we go
2815 * into promiscuous mode and let the upper levels deal. */
2816 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
2817 (dev->mc_count > MAX_MULTICAST(priv)) ) {
2822 mc_count = dev->mc_count;
2825 if (promisc != priv->promiscuous) {
2826 err = hermes_write_wordrec(hw, USER_BAP,
2827 HERMES_RID_CNFPROMISCUOUSMODE,
2830 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
2833 priv->promiscuous = promisc;
2836 if (! promisc && (mc_count || priv->mc_count) ) {
2837 struct dev_mc_list *p = dev->mc_list;
2838 struct hermes_multicast mclist;
2841 for (i = 0; i < mc_count; i++) {
2842 /* paranoia: is list shorter than mc_count? */
2844 /* paranoia: bad address size in list? */
2845 BUG_ON(p->dmi_addrlen != ETH_ALEN);
2847 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
2852 printk(KERN_WARNING "%s: Multicast list is "
2853 "longer than mc_count\n", dev->name);
2855 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
2856 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
2859 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
2862 priv->mc_count = mc_count;
2866 /* This must be called from user context, without locks held - use
2867 * schedule_work() */
2868 static void orinoco_reset(struct work_struct *work)
2870 struct orinoco_private *priv =
2871 container_of(work, struct orinoco_private, reset_work);
2872 struct net_device *dev = priv->ndev;
2873 struct hermes *hw = &priv->hw;
2875 unsigned long flags;
2877 if (orinoco_lock(priv, &flags) != 0)
2878 /* When the hardware becomes available again, whatever
2879 * detects that is responsible for re-initializing
2880 * it. So no need for anything further */
2883 netif_stop_queue(dev);
2885 /* Shut off interrupts. Depending on what state the hardware
2886 * is in, this might not work, but we'll try anyway */
2887 hermes_set_irqmask(hw, 0);
2888 hermes_write_regn(hw, EVACK, 0xffff);
2890 priv->hw_unavailable++;
2891 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
2892 netif_carrier_off(dev);
2894 orinoco_unlock(priv, &flags);
2896 /* Scanning support: Cleanup of driver struct */
2897 orinoco_clear_scan_results(priv, 0);
2898 priv->scan_inprogress = 0;
2900 if (priv->hard_reset) {
2901 err = (*priv->hard_reset)(priv);
2903 printk(KERN_ERR "%s: orinoco_reset: Error %d "
2904 "performing hard reset\n", dev->name, err);
2909 if (priv->do_fw_download) {
2910 err = orinoco_download(priv);
2912 priv->do_fw_download = 0;
2915 err = orinoco_reinit_firmware(dev);
2917 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
2922 spin_lock_irq(&priv->lock); /* This has to be called from user context */
2924 priv->hw_unavailable--;
2926 /* priv->open or priv->hw_unavailable might have changed while
2927 * we dropped the lock */
2928 if (priv->open && (! priv->hw_unavailable)) {
2929 err = __orinoco_up(dev);
2931 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
2934 dev->trans_start = jiffies;
2937 spin_unlock_irq(&priv->lock);
2941 hermes_set_irqmask(hw, 0);
2942 netif_device_detach(dev);
2943 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
2946 /********************************************************************/
2947 /* Interrupt handler */
2948 /********************************************************************/
2950 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
2952 printk(KERN_DEBUG "%s: TICK\n", dev->name);
2955 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
2957 /* This seems to happen a fair bit under load, but ignoring it
2958 seems to work fine...*/
2959 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
2963 irqreturn_t orinoco_interrupt(int irq, void *dev_id)
2965 struct net_device *dev = dev_id;
2966 struct orinoco_private *priv = netdev_priv(dev);
2967 hermes_t *hw = &priv->hw;
2968 int count = MAX_IRQLOOPS_PER_IRQ;
2970 /* These are used to detect a runaway interrupt situation */
2971 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2972 * we panic and shut down the hardware */
2973 static int last_irq_jiffy = 0; /* jiffies value the last time
2975 static int loops_this_jiffy = 0;
2976 unsigned long flags;
2978 if (orinoco_lock(priv, &flags) != 0) {
2979 /* If hw is unavailable - we don't know if the irq was
2984 evstat = hermes_read_regn(hw, EVSTAT);
2985 events = evstat & hw->inten;
2987 orinoco_unlock(priv, &flags);
2991 if (jiffies != last_irq_jiffy)
2992 loops_this_jiffy = 0;
2993 last_irq_jiffy = jiffies;
2995 while (events && count--) {
2996 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2997 printk(KERN_WARNING "%s: IRQ handler is looping too "
2998 "much! Resetting.\n", dev->name);
2999 /* Disable interrupts for now */
3000 hermes_set_irqmask(hw, 0);
3001 schedule_work(&priv->reset_work);
3005 /* Check the card hasn't been removed */
3006 if (! hermes_present(hw)) {
3007 DEBUG(0, "orinoco_interrupt(): card removed\n");
3011 if (events & HERMES_EV_TICK)
3012 __orinoco_ev_tick(dev, hw);
3013 if (events & HERMES_EV_WTERR)
3014 __orinoco_ev_wterr(dev, hw);
3015 if (events & HERMES_EV_INFDROP)
3016 __orinoco_ev_infdrop(dev, hw);
3017 if (events & HERMES_EV_INFO)
3018 __orinoco_ev_info(dev, hw);
3019 if (events & HERMES_EV_RX)
3020 __orinoco_ev_rx(dev, hw);
3021 if (events & HERMES_EV_TXEXC)
3022 __orinoco_ev_txexc(dev, hw);
3023 if (events & HERMES_EV_TX)
3024 __orinoco_ev_tx(dev, hw);
3025 if (events & HERMES_EV_ALLOC)
3026 __orinoco_ev_alloc(dev, hw);
3028 hermes_write_regn(hw, EVACK, evstat);
3030 evstat = hermes_read_regn(hw, EVSTAT);
3031 events = evstat & hw->inten;
3034 orinoco_unlock(priv, &flags);
3038 /********************************************************************/
3039 /* Initialization */
3040 /********************************************************************/
3043 u16 id, variant, major, minor;
3044 } __attribute__ ((packed));
3046 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
3048 if (nic_id->id < 0x8000)
3049 return FIRMWARE_TYPE_AGERE;
3050 else if (nic_id->id == 0x8000 && nic_id->major == 0)
3051 return FIRMWARE_TYPE_SYMBOL;
3053 return FIRMWARE_TYPE_INTERSIL;
3056 /* Set priv->firmware type, determine firmware properties */
3057 static int determine_firmware(struct net_device *dev)
3059 struct orinoco_private *priv = netdev_priv(dev);
3060 hermes_t *hw = &priv->hw;
3062 struct comp_id nic_id, sta_id;
3063 unsigned int firmver;
3064 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
3066 /* Get the hardware version */
3067 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
3069 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
3074 le16_to_cpus(&nic_id.id);
3075 le16_to_cpus(&nic_id.variant);
3076 le16_to_cpus(&nic_id.major);
3077 le16_to_cpus(&nic_id.minor);
3078 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
3079 dev->name, nic_id.id, nic_id.variant,
3080 nic_id.major, nic_id.minor);
3082 priv->firmware_type = determine_firmware_type(&nic_id);
3084 /* Get the firmware version */
3085 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
3087 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
3092 le16_to_cpus(&sta_id.id);
3093 le16_to_cpus(&sta_id.variant);
3094 le16_to_cpus(&sta_id.major);
3095 le16_to_cpus(&sta_id.minor);
3096 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
3097 dev->name, sta_id.id, sta_id.variant,
3098 sta_id.major, sta_id.minor);
3100 switch (sta_id.id) {
3102 printk(KERN_ERR "%s: Primary firmware is active\n",
3106 printk(KERN_ERR "%s: Tertiary firmware is active\n",
3109 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
3110 case 0x21: /* Symbol Spectrum24 Trilogy */
3113 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
3118 /* Default capabilities */
3119 priv->has_sensitivity = 1;
3121 priv->has_preamble = 0;
3122 priv->has_port3 = 1;
3125 priv->has_big_wep = 0;
3126 priv->has_alt_txcntl = 0;
3127 priv->has_ext_scan = 0;
3129 priv->do_fw_download = 0;
3131 /* Determine capabilities from the firmware version */
3132 switch (priv->firmware_type) {
3133 case FIRMWARE_TYPE_AGERE:
3134 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
3135 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
3136 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3137 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
3139 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
3141 priv->has_ibss = (firmver >= 0x60006);
3142 priv->has_wep = (firmver >= 0x40020);
3143 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
3144 Gold cards from the others? */
3145 priv->has_mwo = (firmver >= 0x60000);
3146 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
3147 priv->ibss_port = 1;
3148 priv->has_hostscan = (firmver >= 0x8000a);
3149 priv->do_fw_download = 1;
3150 priv->broken_monitor = (firmver >= 0x80000);
3151 priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
3152 priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
3153 priv->has_wpa = (firmver >= 0x9002a);
3154 /* Tested with Agere firmware :
3155 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
3156 * Tested CableTron firmware : 4.32 => Anton */
3158 case FIRMWARE_TYPE_SYMBOL:
3159 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
3160 /* Intel MAC : 00:02:B3:* */
3161 /* 3Com MAC : 00:50:DA:* */
3162 memset(tmp, 0, sizeof(tmp));
3163 /* Get the Symbol firmware version */
3164 err = hermes_read_ltv(hw, USER_BAP,
3165 HERMES_RID_SECONDARYVERSION_SYMBOL,
3166 SYMBOL_MAX_VER_LEN, NULL, &tmp);
3169 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
3174 /* The firmware revision is a string, the format is
3175 * something like : "V2.20-01".
3176 * Quick and dirty parsing... - Jean II
3178 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
3179 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
3182 tmp[SYMBOL_MAX_VER_LEN] = '\0';
3185 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3188 priv->has_ibss = (firmver >= 0x20000);
3189 priv->has_wep = (firmver >= 0x15012);
3190 priv->has_big_wep = (firmver >= 0x20000);
3191 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
3192 (firmver >= 0x29000 && firmver < 0x30000) ||
3194 priv->has_preamble = (firmver >= 0x20000);
3195 priv->ibss_port = 4;
3197 /* Symbol firmware is found on various cards, but
3198 * there has been no attempt to check firmware
3199 * download on non-spectrum_cs based cards.
3201 * Given that the Agere firmware download works
3202 * differently, we should avoid doing a firmware
3203 * download with the Symbol algorithm on non-spectrum
3206 * For now we can identify a spectrum_cs based card
3207 * because it has a firmware reset function.
3209 priv->do_fw_download = (priv->stop_fw != NULL);
3211 priv->broken_disableport = (firmver == 0x25013) ||
3212 (firmver >= 0x30000 && firmver <= 0x31000);
3213 priv->has_hostscan = (firmver >= 0x31001) ||
3214 (firmver >= 0x29057 && firmver < 0x30000);
3215 /* Tested with Intel firmware : 0x20015 => Jean II */
3216 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
3218 case FIRMWARE_TYPE_INTERSIL:
3219 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
3220 * Samsung, Compaq 100/200 and Proxim are slightly
3221 * different and less well tested */
3222 /* D-Link MAC : 00:40:05:* */
3223 /* Addtron MAC : 00:90:D1:* */
3224 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
3225 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
3228 firmver = ((unsigned long)sta_id.major << 16) |
3229 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
3231 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
3232 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
3233 priv->has_pm = (firmver >= 0x000700);
3234 priv->has_hostscan = (firmver >= 0x010301);
3236 if (firmver >= 0x000800)
3237 priv->ibss_port = 0;
3239 printk(KERN_NOTICE "%s: Intersil firmware earlier "
3240 "than v0.8.x - several features not supported\n",
3242 priv->ibss_port = 1;
3246 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
3252 static int orinoco_init(struct net_device *dev)
3254 struct orinoco_private *priv = netdev_priv(dev);
3255 hermes_t *hw = &priv->hw;
3257 struct hermes_idstring nickbuf;
3260 DECLARE_MAC_BUF(mac);
3262 /* No need to lock, the hw_unavailable flag is already set in
3263 * alloc_orinocodev() */
3264 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
3266 /* Initialize the firmware */
3267 err = hermes_init(hw);
3269 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
3274 err = determine_firmware(dev);
3276 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
3281 if (priv->do_fw_download) {
3282 err = orinoco_download(priv);
3284 priv->do_fw_download = 0;
3286 /* Check firmware version again */
3287 err = determine_firmware(dev);
3289 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
3295 if (priv->has_port3)
3296 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
3298 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
3300 if (priv->has_wep) {
3301 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
3302 if (priv->has_big_wep)
3303 printk("104-bit key\n");
3305 printk("40-bit key\n");
3307 if (priv->has_wpa) {
3308 printk(KERN_DEBUG "%s: WPA-PSK supported\n", dev->name);
3309 if (orinoco_mic_init(priv)) {
3310 printk(KERN_ERR "%s: Failed to setup MIC crypto "
3311 "algorithm. Disabling WPA support\n", dev->name);
3316 /* Now we have the firmware capabilities, allocate appropiate
3317 * sized scan buffers */
3318 if (orinoco_bss_data_allocate(priv))
3320 orinoco_bss_data_init(priv);
3322 /* Get the MAC address */
3323 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
3324 ETH_ALEN, NULL, dev->dev_addr);
3326 printk(KERN_WARNING "%s: failed to read MAC address!\n",
3331 printk(KERN_DEBUG "%s: MAC address %s\n",
3332 dev->name, print_mac(mac, dev->dev_addr));
3334 /* Get the station name */
3335 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
3336 sizeof(nickbuf), &reclen, &nickbuf);
3338 printk(KERN_ERR "%s: failed to read station name\n",
3343 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
3345 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
3346 memcpy(priv->nick, &nickbuf.val, len);
3347 priv->nick[len] = '\0';
3349 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
3351 err = orinoco_allocate_fid(dev);
3353 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
3358 /* Get allowed channels */
3359 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
3360 &priv->channel_mask);
3362 printk(KERN_ERR "%s: failed to read channel list!\n",
3367 /* Get initial AP density */
3368 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
3370 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
3371 priv->has_sensitivity = 0;
3374 /* Get initial RTS threshold */
3375 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
3378 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
3383 /* Get initial fragmentation settings */
3385 err = hermes_read_wordrec(hw, USER_BAP,
3386 HERMES_RID_CNFMWOROBUST_AGERE,
3389 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3390 &priv->frag_thresh);
3392 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
3397 /* Power management setup */
3401 err = hermes_read_wordrec(hw, USER_BAP,
3402 HERMES_RID_CNFMAXSLEEPDURATION,
3405 printk(KERN_ERR "%s: failed to read power management period!\n",
3409 err = hermes_read_wordrec(hw, USER_BAP,
3410 HERMES_RID_CNFPMHOLDOVERDURATION,
3413 printk(KERN_ERR "%s: failed to read power management timeout!\n",
3419 /* Preamble setup */
3420 if (priv->has_preamble) {
3421 err = hermes_read_wordrec(hw, USER_BAP,
3422 HERMES_RID_CNFPREAMBLE_SYMBOL,
3428 /* Set up the default configuration */
3429 priv->iw_mode = IW_MODE_INFRA;
3430 /* By default use IEEE/IBSS ad-hoc mode if we have it */
3431 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
3432 set_port_type(priv);
3433 priv->channel = 0; /* use firmware default */
3435 priv->promiscuous = 0;
3436 priv->encode_alg = IW_ENCODE_ALG_NONE;
3438 priv->wpa_enabled = 0;
3439 priv->tkip_cm_active = 0;
3441 priv->wpa_ie_len = 0;
3442 priv->wpa_ie = NULL;
3444 /* Make the hardware available, as long as it hasn't been
3445 * removed elsewhere (e.g. by PCMCIA hot unplug) */
3446 spin_lock_irq(&priv->lock);
3447 priv->hw_unavailable--;
3448 spin_unlock_irq(&priv->lock);
3450 printk(KERN_DEBUG "%s: ready\n", dev->name);
3457 *alloc_orinocodev(int sizeof_card,
3458 struct device *device,
3459 int (*hard_reset)(struct orinoco_private *),
3460 int (*stop_fw)(struct orinoco_private *, int))
3462 struct net_device *dev;
3463 struct orinoco_private *priv;
3465 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
3468 priv = netdev_priv(dev);
3471 priv->card = (void *)((unsigned long)priv
3472 + sizeof(struct orinoco_private));
3477 /* Setup / override net_device fields */
3478 dev->init = orinoco_init;
3479 dev->hard_start_xmit = orinoco_xmit;
3480 dev->tx_timeout = orinoco_tx_timeout;
3481 dev->watchdog_timeo = HZ; /* 1 second timeout */
3482 dev->get_stats = orinoco_get_stats;
3483 dev->ethtool_ops = &orinoco_ethtool_ops;
3484 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
3486 priv->wireless_data.spy_data = &priv->spy_data;
3487 dev->wireless_data = &priv->wireless_data;
3489 dev->change_mtu = orinoco_change_mtu;
3490 dev->set_multicast_list = orinoco_set_multicast_list;
3491 /* we use the default eth_mac_addr for setting the MAC addr */
3493 /* Reserve space in skb for the SNAP header */
3494 dev->hard_header_len += ENCAPS_OVERHEAD;
3496 /* Set up default callbacks */
3497 dev->open = orinoco_open;
3498 dev->stop = orinoco_stop;
3499 priv->hard_reset = hard_reset;
3500 priv->stop_fw = stop_fw;
3502 spin_lock_init(&priv->lock);
3504 priv->hw_unavailable = 1; /* orinoco_init() must clear this
3505 * before anything else touches the
3507 INIT_WORK(&priv->reset_work, orinoco_reset);
3508 INIT_WORK(&priv->join_work, orinoco_join_ap);
3509 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
3511 INIT_LIST_HEAD(&priv->rx_list);
3512 tasklet_init(&priv->rx_tasklet, orinoco_rx_isr_tasklet,
3513 (unsigned long) dev);
3515 netif_carrier_off(dev);
3516 priv->last_linkstatus = 0xffff;
3521 void free_orinocodev(struct net_device *dev)
3523 struct orinoco_private *priv = netdev_priv(dev);
3525 /* No need to empty priv->rx_list: if the tasklet is scheduled
3526 * when we call tasklet_kill it will run one final time,
3527 * emptying the list */
3528 tasklet_kill(&priv->rx_tasklet);
3529 priv->wpa_ie_len = 0;
3530 kfree(priv->wpa_ie);
3531 orinoco_mic_free(priv);
3532 orinoco_bss_data_free(priv);
3536 /********************************************************************/
3537 /* Wireless extensions */
3538 /********************************************************************/
3540 /* Return : < 0 -> error code ; >= 0 -> length */
3541 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
3542 char buf[IW_ESSID_MAX_SIZE+1])
3544 hermes_t *hw = &priv->hw;
3546 struct hermes_idstring essidbuf;
3547 char *p = (char *)(&essidbuf.val);
3549 unsigned long flags;
3551 if (orinoco_lock(priv, &flags) != 0)
3554 if (strlen(priv->desired_essid) > 0) {
3555 /* We read the desired SSID from the hardware rather
3556 than from priv->desired_essid, just in case the
3557 firmware is allowed to change it on us. I'm not
3559 /* My guess is that the OWNSSID should always be whatever
3560 * we set to the card, whereas CURRENT_SSID is the one that
3561 * may change... - Jean II */
3566 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
3567 HERMES_RID_CNFDESIREDSSID;
3569 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
3576 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
3577 sizeof(essidbuf), NULL, &essidbuf);
3582 len = le16_to_cpu(essidbuf.len);
3583 BUG_ON(len > IW_ESSID_MAX_SIZE);
3585 memset(buf, 0, IW_ESSID_MAX_SIZE);
3586 memcpy(buf, p, len);
3590 orinoco_unlock(priv, &flags);
3595 static long orinoco_hw_get_freq(struct orinoco_private *priv)
3598 hermes_t *hw = &priv->hw;
3602 unsigned long flags;
3604 if (orinoco_lock(priv, &flags) != 0)
3607 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
3611 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
3617 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
3618 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
3619 priv->ndev->name, channel);
3624 freq = channel_frequency[channel-1] * 100000;
3627 orinoco_unlock(priv, &flags);
3631 return err ? err : freq;
3634 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
3635 int *numrates, s32 *rates, int max)
3637 hermes_t *hw = &priv->hw;
3638 struct hermes_idstring list;
3639 unsigned char *p = (unsigned char *)&list.val;
3643 unsigned long flags;
3645 if (orinoco_lock(priv, &flags) != 0)
3648 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
3649 sizeof(list), NULL, &list);
3650 orinoco_unlock(priv, &flags);
3655 num = le16_to_cpu(list.len);
3657 num = min(num, max);
3659 for (i = 0; i < num; i++) {
3660 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
3666 static int orinoco_ioctl_getname(struct net_device *dev,
3667 struct iw_request_info *info,
3671 struct orinoco_private *priv = netdev_priv(dev);
3675 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
3677 if (!err && (numrates > 2))
3678 strcpy(name, "IEEE 802.11b");
3680 strcpy(name, "IEEE 802.11-DS");
3685 static int orinoco_ioctl_setwap(struct net_device *dev,
3686 struct iw_request_info *info,
3687 struct sockaddr *ap_addr,
3690 struct orinoco_private *priv = netdev_priv(dev);
3691 int err = -EINPROGRESS; /* Call commit handler */
3692 unsigned long flags;
3693 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3694 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3696 if (orinoco_lock(priv, &flags) != 0)
3699 /* Enable automatic roaming - no sanity checks are needed */
3700 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
3701 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
3702 priv->bssid_fixed = 0;
3703 memset(priv->desired_bssid, 0, ETH_ALEN);
3705 /* "off" means keep existing connection */
3706 if (ap_addr->sa_data[0] == 0) {
3707 __orinoco_hw_set_wap(priv);
3713 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
3714 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
3715 "support manual roaming\n",
3721 if (priv->iw_mode != IW_MODE_INFRA) {
3722 printk(KERN_WARNING "%s: Manual roaming supported only in "
3723 "managed mode\n", dev->name);
3728 /* Intersil firmware hangs without Desired ESSID */
3729 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
3730 strlen(priv->desired_essid) == 0) {
3731 printk(KERN_WARNING "%s: Desired ESSID must be set for "
3732 "manual roaming\n", dev->name);
3737 /* Finally, enable manual roaming */
3738 priv->bssid_fixed = 1;
3739 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
3742 orinoco_unlock(priv, &flags);
3746 static int orinoco_ioctl_getwap(struct net_device *dev,
3747 struct iw_request_info *info,
3748 struct sockaddr *ap_addr,
3751 struct orinoco_private *priv = netdev_priv(dev);
3753 hermes_t *hw = &priv->hw;
3755 unsigned long flags;
3757 if (orinoco_lock(priv, &flags) != 0)
3760 ap_addr->sa_family = ARPHRD_ETHER;
3761 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
3762 ETH_ALEN, NULL, ap_addr->sa_data);
3764 orinoco_unlock(priv, &flags);
3769 static int orinoco_ioctl_setmode(struct net_device *dev,
3770 struct iw_request_info *info,
3774 struct orinoco_private *priv = netdev_priv(dev);
3775 int err = -EINPROGRESS; /* Call commit handler */
3776 unsigned long flags;
3778 if (priv->iw_mode == *mode)
3781 if (orinoco_lock(priv, &flags) != 0)
3786 if (!priv->has_ibss && !priv->has_port3)
3793 case IW_MODE_MONITOR:
3794 if (priv->broken_monitor && !force_monitor) {
3795 printk(KERN_WARNING "%s: Monitor mode support is "
3796 "buggy in this firmware, not enabling\n",
3807 if (err == -EINPROGRESS) {
3808 priv->iw_mode = *mode;
3809 set_port_type(priv);
3812 orinoco_unlock(priv, &flags);
3817 static int orinoco_ioctl_getmode(struct net_device *dev,
3818 struct iw_request_info *info,
3822 struct orinoco_private *priv = netdev_priv(dev);
3824 *mode = priv->iw_mode;
3828 static int orinoco_ioctl_getiwrange(struct net_device *dev,
3829 struct iw_request_info *info,
3830 struct iw_point *rrq,
3833 struct orinoco_private *priv = netdev_priv(dev);
3835 struct iw_range *range = (struct iw_range *) extra;
3839 rrq->length = sizeof(struct iw_range);
3840 memset(range, 0, sizeof(struct iw_range));
3842 range->we_version_compiled = WIRELESS_EXT;
3843 range->we_version_source = 22;
3845 /* Set available channels/frequencies */
3846 range->num_channels = NUM_CHANNELS;
3848 for (i = 0; i < NUM_CHANNELS; i++) {
3849 if (priv->channel_mask & (1 << i)) {
3850 range->freq[k].i = i + 1;
3851 range->freq[k].m = channel_frequency[i] * 100000;
3852 range->freq[k].e = 1;
3856 if (k >= IW_MAX_FREQUENCIES)
3859 range->num_frequency = k;
3860 range->sensitivity = 3;
3862 if (priv->has_wep) {
3863 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
3864 range->encoding_size[0] = SMALL_KEY_SIZE;
3865 range->num_encoding_sizes = 1;
3867 if (priv->has_big_wep) {
3868 range->encoding_size[1] = LARGE_KEY_SIZE;
3869 range->num_encoding_sizes = 2;
3874 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_CIPHER_TKIP;
3876 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
3877 /* Quality stats meaningless in ad-hoc mode */
3879 range->max_qual.qual = 0x8b - 0x2f;
3880 range->max_qual.level = 0x2f - 0x95 - 1;
3881 range->max_qual.noise = 0x2f - 0x95 - 1;
3882 /* Need to get better values */
3883 range->avg_qual.qual = 0x24;
3884 range->avg_qual.level = 0xC2;
3885 range->avg_qual.noise = 0x9E;
3888 err = orinoco_hw_get_bitratelist(priv, &numrates,
3889 range->bitrate, IW_MAX_BITRATES);
3892 range->num_bitrates = numrates;
3894 /* Set an indication of the max TCP throughput in bit/s that we can
3895 * expect using this interface. May be use for QoS stuff...
3898 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
3900 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
3903 range->max_rts = 2347;
3904 range->min_frag = 256;
3905 range->max_frag = 2346;
3908 range->max_pmp = 65535000;
3910 range->max_pmt = 65535 * 1000; /* ??? */
3911 range->pmp_flags = IW_POWER_PERIOD;
3912 range->pmt_flags = IW_POWER_TIMEOUT;
3913 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
3915 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
3916 range->retry_flags = IW_RETRY_LIMIT;
3917 range->r_time_flags = IW_RETRY_LIFETIME;
3918 range->min_retry = 0;
3919 range->max_retry = 65535; /* ??? */
3920 range->min_r_time = 0;
3921 range->max_r_time = 65535 * 1000; /* ??? */
3923 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
3924 range->scan_capa = IW_SCAN_CAPA_ESSID;
3926 range->scan_capa = IW_SCAN_CAPA_NONE;
3928 /* Event capability (kernel) */
3929 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
3930 /* Event capability (driver) */
3931 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
3932 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
3933 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
3934 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
3939 static int orinoco_ioctl_setiwencode(struct net_device *dev,
3940 struct iw_request_info *info,
3941 struct iw_point *erq,
3944 struct orinoco_private *priv = netdev_priv(dev);
3945 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3946 int setindex = priv->tx_key;
3947 int encode_alg = priv->encode_alg;
3948 int restricted = priv->wep_restrict;
3950 int err = -EINPROGRESS; /* Call commit handler */
3951 unsigned long flags;
3953 if (! priv->has_wep)
3957 /* We actually have a key to set - check its length */
3958 if (erq->length > LARGE_KEY_SIZE)
3961 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
3965 if (orinoco_lock(priv, &flags) != 0)
3968 /* Clear any TKIP key we have */
3969 if ((priv->has_wpa) && (priv->encode_alg == IW_ENCODE_ALG_TKIP))
3970 (void) orinoco_clear_tkip_key(priv, setindex);
3972 if (erq->length > 0) {
3973 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3974 index = priv->tx_key;
3976 /* Adjust key length to a supported value */
3977 if (erq->length > SMALL_KEY_SIZE) {
3978 xlen = LARGE_KEY_SIZE;
3979 } else if (erq->length > 0) {
3980 xlen = SMALL_KEY_SIZE;
3984 /* Switch on WEP if off */
3985 if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
3987 encode_alg = IW_ENCODE_ALG_WEP;
3990 /* Important note : if the user do "iwconfig eth0 enc off",
3991 * we will arrive there with an index of -1. This is valid
3992 * but need to be taken care off... Jean II */
3993 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
3994 if((index != -1) || (erq->flags == 0)) {
3999 /* Set the index : Check that the key is valid */
4000 if(priv->keys[index].len == 0) {
4008 if (erq->flags & IW_ENCODE_DISABLED)
4009 encode_alg = IW_ENCODE_ALG_NONE;
4010 if (erq->flags & IW_ENCODE_OPEN)
4012 if (erq->flags & IW_ENCODE_RESTRICTED)
4015 if (erq->pointer && erq->length > 0) {
4016 priv->keys[index].len = cpu_to_le16(xlen);
4017 memset(priv->keys[index].data, 0,
4018 sizeof(priv->keys[index].data));
4019 memcpy(priv->keys[index].data, keybuf, erq->length);
4021 priv->tx_key = setindex;
4023 /* Try fast key change if connected and only keys are changed */
4024 if ((priv->encode_alg == encode_alg) &&
4025 (priv->wep_restrict == restricted) &&
4026 netif_carrier_ok(dev)) {
4027 err = __orinoco_hw_setup_wepkeys(priv);
4028 /* No need to commit if successful */
4032 priv->encode_alg = encode_alg;
4033 priv->wep_restrict = restricted;
4036 orinoco_unlock(priv, &flags);
4041 static int orinoco_ioctl_getiwencode(struct net_device *dev,
4042 struct iw_request_info *info,
4043 struct iw_point *erq,
4046 struct orinoco_private *priv = netdev_priv(dev);
4047 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
4049 unsigned long flags;
4051 if (! priv->has_wep)
4054 if (orinoco_lock(priv, &flags) != 0)
4057 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
4058 index = priv->tx_key;
4061 if (!priv->encode_alg)
4062 erq->flags |= IW_ENCODE_DISABLED;
4063 erq->flags |= index + 1;
4065 if (priv->wep_restrict)
4066 erq->flags |= IW_ENCODE_RESTRICTED;
4068 erq->flags |= IW_ENCODE_OPEN;
4070 xlen = le16_to_cpu(priv->keys[index].len);
4074 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
4076 orinoco_unlock(priv, &flags);
4080 static int orinoco_ioctl_setessid(struct net_device *dev,
4081 struct iw_request_info *info,
4082 struct iw_point *erq,
4085 struct orinoco_private *priv = netdev_priv(dev);
4086 unsigned long flags;
4088 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
4089 * anyway... - Jean II */
4091 /* Hum... Should not use Wireless Extension constant (may change),
4092 * should use our own... - Jean II */
4093 if (erq->length > IW_ESSID_MAX_SIZE)
4096 if (orinoco_lock(priv, &flags) != 0)
4099 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
4100 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
4102 /* If not ANY, get the new ESSID */
4104 memcpy(priv->desired_essid, essidbuf, erq->length);
4107 orinoco_unlock(priv, &flags);
4109 return -EINPROGRESS; /* Call commit handler */
4112 static int orinoco_ioctl_getessid(struct net_device *dev,
4113 struct iw_request_info *info,
4114 struct iw_point *erq,
4117 struct orinoco_private *priv = netdev_priv(dev);
4120 unsigned long flags;
4122 if (netif_running(dev)) {
4123 err = orinoco_hw_get_essid(priv, &active, essidbuf);
4128 if (orinoco_lock(priv, &flags) != 0)
4130 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
4131 erq->length = strlen(priv->desired_essid);
4132 orinoco_unlock(priv, &flags);
4140 static int orinoco_ioctl_setnick(struct net_device *dev,
4141 struct iw_request_info *info,
4142 struct iw_point *nrq,
4145 struct orinoco_private *priv = netdev_priv(dev);
4146 unsigned long flags;
4148 if (nrq->length > IW_ESSID_MAX_SIZE)
4151 if (orinoco_lock(priv, &flags) != 0)
4154 memset(priv->nick, 0, sizeof(priv->nick));
4155 memcpy(priv->nick, nickbuf, nrq->length);
4157 orinoco_unlock(priv, &flags);
4159 return -EINPROGRESS; /* Call commit handler */
4162 static int orinoco_ioctl_getnick(struct net_device *dev,
4163 struct iw_request_info *info,
4164 struct iw_point *nrq,
4167 struct orinoco_private *priv = netdev_priv(dev);
4168 unsigned long flags;
4170 if (orinoco_lock(priv, &flags) != 0)
4173 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
4174 orinoco_unlock(priv, &flags);
4176 nrq->length = strlen(priv->nick);
4181 static int orinoco_ioctl_setfreq(struct net_device *dev,
4182 struct iw_request_info *info,
4183 struct iw_freq *frq,
4186 struct orinoco_private *priv = netdev_priv(dev);
4188 unsigned long flags;
4189 int err = -EINPROGRESS; /* Call commit handler */
4191 /* In infrastructure mode the AP sets the channel */
4192 if (priv->iw_mode == IW_MODE_INFRA)
4195 if ( (frq->e == 0) && (frq->m <= 1000) ) {
4196 /* Setting by channel number */
4199 /* Setting by frequency - search the table */
4203 for (i = 0; i < (6 - frq->e); i++)
4206 for (i = 0; i < NUM_CHANNELS; i++)
4207 if (frq->m == (channel_frequency[i] * mult))
4211 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
4212 ! (priv->channel_mask & (1 << (chan-1)) ) )
4215 if (orinoco_lock(priv, &flags) != 0)
4218 priv->channel = chan;
4219 if (priv->iw_mode == IW_MODE_MONITOR) {
4220 /* Fast channel change - no commit if successful */
4221 hermes_t *hw = &priv->hw;
4222 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
4223 HERMES_TEST_SET_CHANNEL,
4226 orinoco_unlock(priv, &flags);
4231 static int orinoco_ioctl_getfreq(struct net_device *dev,
4232 struct iw_request_info *info,
4233 struct iw_freq *frq,
4236 struct orinoco_private *priv = netdev_priv(dev);
4239 /* Locking done in there */
4240 tmp = orinoco_hw_get_freq(priv);
4251 static int orinoco_ioctl_getsens(struct net_device *dev,
4252 struct iw_request_info *info,
4253 struct iw_param *srq,
4256 struct orinoco_private *priv = netdev_priv(dev);
4257 hermes_t *hw = &priv->hw;
4260 unsigned long flags;
4262 if (!priv->has_sensitivity)
4265 if (orinoco_lock(priv, &flags) != 0)
4267 err = hermes_read_wordrec(hw, USER_BAP,
4268 HERMES_RID_CNFSYSTEMSCALE, &val);
4269 orinoco_unlock(priv, &flags);
4275 srq->fixed = 0; /* auto */
4280 static int orinoco_ioctl_setsens(struct net_device *dev,
4281 struct iw_request_info *info,
4282 struct iw_param *srq,
4285 struct orinoco_private *priv = netdev_priv(dev);
4286 int val = srq->value;
4287 unsigned long flags;
4289 if (!priv->has_sensitivity)
4292 if ((val < 1) || (val > 3))
4295 if (orinoco_lock(priv, &flags) != 0)
4297 priv->ap_density = val;
4298 orinoco_unlock(priv, &flags);
4300 return -EINPROGRESS; /* Call commit handler */
4303 static int orinoco_ioctl_setrts(struct net_device *dev,
4304 struct iw_request_info *info,
4305 struct iw_param *rrq,
4308 struct orinoco_private *priv = netdev_priv(dev);
4309 int val = rrq->value;
4310 unsigned long flags;
4315 if ( (val < 0) || (val > 2347) )
4318 if (orinoco_lock(priv, &flags) != 0)
4321 priv->rts_thresh = val;
4322 orinoco_unlock(priv, &flags);
4324 return -EINPROGRESS; /* Call commit handler */
4327 static int orinoco_ioctl_getrts(struct net_device *dev,
4328 struct iw_request_info *info,
4329 struct iw_param *rrq,
4332 struct orinoco_private *priv = netdev_priv(dev);
4334 rrq->value = priv->rts_thresh;
4335 rrq->disabled = (rrq->value == 2347);
4341 static int orinoco_ioctl_setfrag(struct net_device *dev,
4342 struct iw_request_info *info,
4343 struct iw_param *frq,
4346 struct orinoco_private *priv = netdev_priv(dev);
4347 int err = -EINPROGRESS; /* Call commit handler */
4348 unsigned long flags;
4350 if (orinoco_lock(priv, &flags) != 0)
4353 if (priv->has_mwo) {
4355 priv->mwo_robust = 0;
4358 printk(KERN_WARNING "%s: Fixed fragmentation is "
4359 "not supported on this firmware. "
4360 "Using MWO robust instead.\n", dev->name);
4361 priv->mwo_robust = 1;
4365 priv->frag_thresh = 2346;
4367 if ( (frq->value < 256) || (frq->value > 2346) )
4370 priv->frag_thresh = frq->value & ~0x1; /* must be even */
4374 orinoco_unlock(priv, &flags);
4379 static int orinoco_ioctl_getfrag(struct net_device *dev,
4380 struct iw_request_info *info,
4381 struct iw_param *frq,
4384 struct orinoco_private *priv = netdev_priv(dev);
4385 hermes_t *hw = &priv->hw;
4388 unsigned long flags;
4390 if (orinoco_lock(priv, &flags) != 0)
4393 if (priv->has_mwo) {
4394 err = hermes_read_wordrec(hw, USER_BAP,
4395 HERMES_RID_CNFMWOROBUST_AGERE,
4400 frq->value = val ? 2347 : 0;
4401 frq->disabled = ! val;
4404 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
4410 frq->disabled = (val >= 2346);
4414 orinoco_unlock(priv, &flags);
4419 static int orinoco_ioctl_setrate(struct net_device *dev,
4420 struct iw_request_info *info,
4421 struct iw_param *rrq,
4424 struct orinoco_private *priv = netdev_priv(dev);
4426 int bitrate; /* 100s of kilobits */
4428 unsigned long flags;
4430 /* As the user space doesn't know our highest rate, it uses -1
4431 * to ask us to set the highest rate. Test it using "iwconfig
4432 * ethX rate auto" - Jean II */
4433 if (rrq->value == -1)
4436 if (rrq->value % 100000)
4438 bitrate = rrq->value / 100000;
4441 if ( (bitrate != 10) && (bitrate != 20) &&
4442 (bitrate != 55) && (bitrate != 110) )
4445 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
4446 if ( (bitrate_table[i].bitrate == bitrate) &&
4447 (bitrate_table[i].automatic == ! rrq->fixed) ) {
4455 if (orinoco_lock(priv, &flags) != 0)
4457 priv->bitratemode = ratemode;
4458 orinoco_unlock(priv, &flags);
4460 return -EINPROGRESS;
4463 static int orinoco_ioctl_getrate(struct net_device *dev,
4464 struct iw_request_info *info,
4465 struct iw_param *rrq,
4468 struct orinoco_private *priv = netdev_priv(dev);
4469 hermes_t *hw = &priv->hw;
4474 unsigned long flags;
4476 if (orinoco_lock(priv, &flags) != 0)
4479 ratemode = priv->bitratemode;
4481 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
4483 rrq->value = bitrate_table[ratemode].bitrate * 100000;
4484 rrq->fixed = ! bitrate_table[ratemode].automatic;
4487 /* If the interface is running we try to find more about the
4489 if (netif_running(dev)) {
4490 err = hermes_read_wordrec(hw, USER_BAP,
4491 HERMES_RID_CURRENTTXRATE, &val);
4495 switch (priv->firmware_type) {
4496 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
4497 /* Note : in Lucent firmware, the return value of
4498 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
4499 * and therefore is totally different from the
4500 * encoding of HERMES_RID_CNFTXRATECONTROL.
4501 * Don't forget that 6Mb/s is really 5.5Mb/s */
4503 rrq->value = 5500000;
4505 rrq->value = val * 1000000;
4507 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
4508 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
4509 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
4510 if (bitrate_table[i].intersil_txratectrl == val) {
4514 if (i >= BITRATE_TABLE_SIZE)
4515 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
4518 rrq->value = bitrate_table[ratemode].bitrate * 100000;
4526 orinoco_unlock(priv, &flags);
4531 static int orinoco_ioctl_setpower(struct net_device *dev,
4532 struct iw_request_info *info,
4533 struct iw_param *prq,
4536 struct orinoco_private *priv = netdev_priv(dev);
4537 int err = -EINPROGRESS; /* Call commit handler */
4538 unsigned long flags;
4540 if (orinoco_lock(priv, &flags) != 0)
4543 if (prq->disabled) {
4546 switch (prq->flags & IW_POWER_MODE) {
4547 case IW_POWER_UNICAST_R:
4551 case IW_POWER_ALL_R:
4556 /* No flags : but we may have a value - Jean II */
4563 if (prq->flags & IW_POWER_TIMEOUT) {
4565 priv->pm_timeout = prq->value / 1000;
4567 if (prq->flags & IW_POWER_PERIOD) {
4569 priv->pm_period = prq->value / 1000;
4571 /* It's valid to not have a value if we are just toggling
4572 * the flags... Jean II */
4580 orinoco_unlock(priv, &flags);
4585 static int orinoco_ioctl_getpower(struct net_device *dev,
4586 struct iw_request_info *info,
4587 struct iw_param *prq,
4590 struct orinoco_private *priv = netdev_priv(dev);
4591 hermes_t *hw = &priv->hw;
4593 u16 enable, period, timeout, mcast;
4594 unsigned long flags;
4596 if (orinoco_lock(priv, &flags) != 0)
4599 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
4603 err = hermes_read_wordrec(hw, USER_BAP,
4604 HERMES_RID_CNFMAXSLEEPDURATION, &period);
4608 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
4612 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
4616 prq->disabled = !enable;
4617 /* Note : by default, display the period */
4618 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
4619 prq->flags = IW_POWER_TIMEOUT;
4620 prq->value = timeout * 1000;
4622 prq->flags = IW_POWER_PERIOD;
4623 prq->value = period * 1000;
4626 prq->flags |= IW_POWER_ALL_R;
4628 prq->flags |= IW_POWER_UNICAST_R;
4631 orinoco_unlock(priv, &flags);
4636 static int orinoco_ioctl_set_encodeext(struct net_device *dev,
4637 struct iw_request_info *info,
4638 union iwreq_data *wrqu,
4641 struct orinoco_private *priv = netdev_priv(dev);
4642 struct iw_point *encoding = &wrqu->encoding;
4643 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
4644 int idx, alg = ext->alg, set_key = 1;
4645 unsigned long flags;
4649 if (orinoco_lock(priv, &flags) != 0)
4652 /* Determine and validate the key index */
4653 idx = encoding->flags & IW_ENCODE_INDEX;
4655 if ((idx < 1) || (idx > WEP_KEYS))
4661 if (encoding->flags & IW_ENCODE_DISABLED)
4662 alg = IW_ENCODE_ALG_NONE;
4664 if (priv->has_wpa && (alg != IW_ENCODE_ALG_TKIP)) {
4665 /* Clear any TKIP TX key we had */
4666 (void) orinoco_clear_tkip_key(priv, priv->tx_key);
4669 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
4671 set_key = ((alg == IW_ENCODE_ALG_TKIP) ||
4672 (ext->key_len > 0)) ? 1 : 0;
4676 /* Set the requested key first */
4678 case IW_ENCODE_ALG_NONE:
4679 priv->encode_alg = alg;
4680 priv->keys[idx].len = 0;
4683 case IW_ENCODE_ALG_WEP:
4684 if (ext->key_len > SMALL_KEY_SIZE)
4685 key_len = LARGE_KEY_SIZE;
4686 else if (ext->key_len > 0)
4687 key_len = SMALL_KEY_SIZE;
4691 priv->encode_alg = alg;
4692 priv->keys[idx].len = cpu_to_le16(key_len);
4694 key_len = min(ext->key_len, key_len);
4696 memset(priv->keys[idx].data, 0, ORINOCO_MAX_KEY_SIZE);
4697 memcpy(priv->keys[idx].data, ext->key, key_len);
4700 case IW_ENCODE_ALG_TKIP:
4702 hermes_t *hw = &priv->hw;
4705 if (!priv->has_wpa ||
4706 (ext->key_len > sizeof(priv->tkip_key[0])))
4709 priv->encode_alg = alg;
4710 memset(&priv->tkip_key[idx], 0,
4711 sizeof(priv->tkip_key[idx]));
4712 memcpy(&priv->tkip_key[idx], ext->key, ext->key_len);
4714 if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID)
4715 tkip_iv = &ext->rx_seq[0];
4717 err = __orinoco_hw_set_tkip_key(hw, idx,
4718 ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY,
4719 (u8 *) &priv->tkip_key[idx],
4722 printk(KERN_ERR "%s: Error %d setting TKIP key"
4723 "\n", dev->name, err);
4733 orinoco_unlock(priv, &flags);
4738 static int orinoco_ioctl_get_encodeext(struct net_device *dev,
4739 struct iw_request_info *info,
4740 union iwreq_data *wrqu,
4743 struct orinoco_private *priv = netdev_priv(dev);
4744 struct iw_point *encoding = &wrqu->encoding;
4745 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
4746 int idx, max_key_len;
4747 unsigned long flags;
4750 if (orinoco_lock(priv, &flags) != 0)
4754 max_key_len = encoding->length - sizeof(*ext);
4755 if (max_key_len < 0)
4758 idx = encoding->flags & IW_ENCODE_INDEX;
4760 if ((idx < 1) || (idx > WEP_KEYS))
4766 encoding->flags = idx + 1;
4767 memset(ext, 0, sizeof(*ext));
4769 ext->alg = priv->encode_alg;
4770 switch (priv->encode_alg) {
4771 case IW_ENCODE_ALG_NONE:
4773 encoding->flags |= IW_ENCODE_DISABLED;
4775 case IW_ENCODE_ALG_WEP:
4776 ext->key_len = min(le16_to_cpu(priv->keys[idx].len),
4778 memcpy(ext->key, priv->keys[idx].data, ext->key_len);
4779 encoding->flags |= IW_ENCODE_ENABLED;
4781 case IW_ENCODE_ALG_TKIP:
4782 ext->key_len = min((u16) sizeof(struct orinoco_tkip_key),
4784 memcpy(ext->key, &priv->tkip_key[idx], ext->key_len);
4785 encoding->flags |= IW_ENCODE_ENABLED;
4791 orinoco_unlock(priv, &flags);
4796 static int orinoco_ioctl_set_auth(struct net_device *dev,
4797 struct iw_request_info *info,
4798 union iwreq_data *wrqu, char *extra)
4800 struct orinoco_private *priv = netdev_priv(dev);
4801 hermes_t *hw = &priv->hw;
4802 struct iw_param *param = &wrqu->param;
4803 unsigned long flags;
4804 int ret = -EINPROGRESS;
4806 if (orinoco_lock(priv, &flags) != 0)
4809 switch (param->flags & IW_AUTH_INDEX) {
4810 case IW_AUTH_WPA_VERSION:
4811 case IW_AUTH_CIPHER_PAIRWISE:
4812 case IW_AUTH_CIPHER_GROUP:
4813 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
4814 case IW_AUTH_PRIVACY_INVOKED:
4815 case IW_AUTH_DROP_UNENCRYPTED:
4817 * orinoco does not use these parameters
4821 case IW_AUTH_KEY_MGMT:
4822 /* wl_lkm implies value 2 == PSK for Hermes I
4823 * which ties in with WEXT
4824 * no other hints tho :(
4826 priv->key_mgmt = param->value;
4829 case IW_AUTH_TKIP_COUNTERMEASURES:
4830 /* When countermeasures are enabled, shut down the
4831 * card; when disabled, re-enable the card. This must
4832 * take effect immediately.
4834 * TODO: Make sure that the EAPOL message is getting
4835 * out before card disabled
4838 priv->tkip_cm_active = 1;
4839 ret = hermes_enable_port(hw, 0);
4841 priv->tkip_cm_active = 0;
4842 ret = hermes_disable_port(hw, 0);
4846 case IW_AUTH_80211_AUTH_ALG:
4847 if (param->value & IW_AUTH_ALG_SHARED_KEY)
4848 priv->wep_restrict = 1;
4849 else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM)
4850 priv->wep_restrict = 0;
4855 case IW_AUTH_WPA_ENABLED:
4856 if (priv->has_wpa) {
4857 priv->wpa_enabled = param->value ? 1 : 0;
4861 /* else silently accept disable of WPA */
4862 priv->wpa_enabled = 0;
4870 orinoco_unlock(priv, &flags);
4874 static int orinoco_ioctl_get_auth(struct net_device *dev,
4875 struct iw_request_info *info,
4876 union iwreq_data *wrqu, char *extra)
4878 struct orinoco_private *priv = netdev_priv(dev);
4879 struct iw_param *param = &wrqu->param;
4880 unsigned long flags;
4883 if (orinoco_lock(priv, &flags) != 0)
4886 switch (param->flags & IW_AUTH_INDEX) {
4887 case IW_AUTH_KEY_MGMT:
4888 param->value = priv->key_mgmt;
4891 case IW_AUTH_TKIP_COUNTERMEASURES:
4892 param->value = priv->tkip_cm_active;
4895 case IW_AUTH_80211_AUTH_ALG:
4896 if (priv->wep_restrict)
4897 param->value = IW_AUTH_ALG_SHARED_KEY;
4899 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
4902 case IW_AUTH_WPA_ENABLED:
4903 param->value = priv->wpa_enabled;
4910 orinoco_unlock(priv, &flags);
4914 static int orinoco_ioctl_set_genie(struct net_device *dev,
4915 struct iw_request_info *info,
4916 union iwreq_data *wrqu, char *extra)
4918 struct orinoco_private *priv = netdev_priv(dev);
4920 unsigned long flags;
4923 if ((wrqu->data.length > MAX_WPA_IE_LEN) ||
4924 (wrqu->data.length && (extra == NULL)))
4927 if (orinoco_lock(priv, &flags) != 0)
4930 if (wrqu->data.length) {
4931 buf = kmalloc(wrqu->data.length, GFP_KERNEL);
4937 memcpy(buf, extra, wrqu->data.length);
4938 kfree(priv->wpa_ie);
4940 priv->wpa_ie_len = wrqu->data.length;
4942 kfree(priv->wpa_ie);
4943 priv->wpa_ie = NULL;
4944 priv->wpa_ie_len = 0;
4948 /* Looks like wl_lkm wants to check the auth alg, and
4949 * somehow pass it to the firmware.
4950 * Instead it just calls the key mgmt rid
4951 * - we do this in set auth.
4956 orinoco_unlock(priv, &flags);
4960 static int orinoco_ioctl_get_genie(struct net_device *dev,
4961 struct iw_request_info *info,
4962 union iwreq_data *wrqu, char *extra)
4964 struct orinoco_private *priv = netdev_priv(dev);
4965 unsigned long flags;
4968 if (orinoco_lock(priv, &flags) != 0)
4971 if ((priv->wpa_ie_len == 0) || (priv->wpa_ie == NULL)) {
4972 wrqu->data.length = 0;
4976 if (wrqu->data.length < priv->wpa_ie_len) {
4981 wrqu->data.length = priv->wpa_ie_len;
4982 memcpy(extra, priv->wpa_ie, priv->wpa_ie_len);
4985 orinoco_unlock(priv, &flags);
4989 static int orinoco_ioctl_set_mlme(struct net_device *dev,
4990 struct iw_request_info *info,
4991 union iwreq_data *wrqu, char *extra)
4993 struct orinoco_private *priv = netdev_priv(dev);
4994 hermes_t *hw = &priv->hw;
4995 struct iw_mlme *mlme = (struct iw_mlme *)extra;
4996 unsigned long flags;
4999 if (orinoco_lock(priv, &flags) != 0)
5002 switch (mlme->cmd) {
5003 case IW_MLME_DEAUTH:
5004 /* silently ignore */
5007 case IW_MLME_DISASSOC:
5012 } __attribute__ ((packed)) buf;
5014 memcpy(buf.addr, mlme->addr.sa_data, ETH_ALEN);
5015 buf.reason_code = cpu_to_le16(mlme->reason_code);
5016 ret = HERMES_WRITE_RECORD(hw, USER_BAP,
5017 HERMES_RID_CNFDISASSOCIATE,
5025 orinoco_unlock(priv, &flags);
5029 static int orinoco_ioctl_getretry(struct net_device *dev,
5030 struct iw_request_info *info,
5031 struct iw_param *rrq,
5034 struct orinoco_private *priv = netdev_priv(dev);
5035 hermes_t *hw = &priv->hw;
5037 u16 short_limit, long_limit, lifetime;
5038 unsigned long flags;
5040 if (orinoco_lock(priv, &flags) != 0)
5043 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
5048 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
5053 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
5058 rrq->disabled = 0; /* Can't be disabled */
5060 /* Note : by default, display the retry number */
5061 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
5062 rrq->flags = IW_RETRY_LIFETIME;
5063 rrq->value = lifetime * 1000; /* ??? */
5065 /* By default, display the min number */
5066 if ((rrq->flags & IW_RETRY_LONG)) {
5067 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
5068 rrq->value = long_limit;
5070 rrq->flags = IW_RETRY_LIMIT;
5071 rrq->value = short_limit;
5072 if(short_limit != long_limit)
5073 rrq->flags |= IW_RETRY_SHORT;
5078 orinoco_unlock(priv, &flags);
5083 static int orinoco_ioctl_reset(struct net_device *dev,
5084 struct iw_request_info *info,
5088 struct orinoco_private *priv = netdev_priv(dev);
5090 if (! capable(CAP_NET_ADMIN))
5093 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
5094 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
5096 /* Firmware reset */
5097 orinoco_reset(&priv->reset_work);
5099 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
5101 schedule_work(&priv->reset_work);
5107 static int orinoco_ioctl_setibssport(struct net_device *dev,
5108 struct iw_request_info *info,
5113 struct orinoco_private *priv = netdev_priv(dev);
5114 int val = *( (int *) extra );
5115 unsigned long flags;
5117 if (orinoco_lock(priv, &flags) != 0)
5120 priv->ibss_port = val ;
5122 /* Actually update the mode we are using */
5123 set_port_type(priv);
5125 orinoco_unlock(priv, &flags);
5126 return -EINPROGRESS; /* Call commit handler */
5129 static int orinoco_ioctl_getibssport(struct net_device *dev,
5130 struct iw_request_info *info,
5134 struct orinoco_private *priv = netdev_priv(dev);
5135 int *val = (int *) extra;
5137 *val = priv->ibss_port;
5141 static int orinoco_ioctl_setport3(struct net_device *dev,
5142 struct iw_request_info *info,
5146 struct orinoco_private *priv = netdev_priv(dev);
5147 int val = *( (int *) extra );
5149 unsigned long flags;
5151 if (orinoco_lock(priv, &flags) != 0)
5155 case 0: /* Try to do IEEE ad-hoc mode */
5156 if (! priv->has_ibss) {
5160 priv->prefer_port3 = 0;
5164 case 1: /* Try to do Lucent proprietary ad-hoc mode */
5165 if (! priv->has_port3) {
5169 priv->prefer_port3 = 1;
5177 /* Actually update the mode we are using */
5178 set_port_type(priv);
5182 orinoco_unlock(priv, &flags);
5187 static int orinoco_ioctl_getport3(struct net_device *dev,
5188 struct iw_request_info *info,
5192 struct orinoco_private *priv = netdev_priv(dev);
5193 int *val = (int *) extra;
5195 *val = priv->prefer_port3;
5199 static int orinoco_ioctl_setpreamble(struct net_device *dev,
5200 struct iw_request_info *info,
5204 struct orinoco_private *priv = netdev_priv(dev);
5205 unsigned long flags;
5208 if (! priv->has_preamble)
5211 /* 802.11b has recently defined some short preamble.
5212 * Basically, the Phy header has been reduced in size.
5213 * This increase performance, especially at high rates
5214 * (the preamble is transmitted at 1Mb/s), unfortunately
5215 * this give compatibility troubles... - Jean II */
5216 val = *( (int *) extra );
5218 if (orinoco_lock(priv, &flags) != 0)
5226 orinoco_unlock(priv, &flags);
5228 return -EINPROGRESS; /* Call commit handler */
5231 static int orinoco_ioctl_getpreamble(struct net_device *dev,
5232 struct iw_request_info *info,
5236 struct orinoco_private *priv = netdev_priv(dev);
5237 int *val = (int *) extra;
5239 if (! priv->has_preamble)
5242 *val = priv->preamble;
5246 /* ioctl interface to hermes_read_ltv()
5247 * To use with iwpriv, pass the RID as the token argument, e.g.
5248 * iwpriv get_rid [0xfc00]
5249 * At least Wireless Tools 25 is required to use iwpriv.
5250 * For Wireless Tools 25 and 26 append "dummy" are the end. */
5251 static int orinoco_ioctl_getrid(struct net_device *dev,
5252 struct iw_request_info *info,
5253 struct iw_point *data,
5256 struct orinoco_private *priv = netdev_priv(dev);
5257 hermes_t *hw = &priv->hw;
5258 int rid = data->flags;
5261 unsigned long flags;
5263 /* It's a "get" function, but we don't want users to access the
5264 * WEP key and other raw firmware data */
5265 if (! capable(CAP_NET_ADMIN))
5268 if (rid < 0xfc00 || rid > 0xffff)
5271 if (orinoco_lock(priv, &flags) != 0)
5274 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
5279 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
5283 orinoco_unlock(priv, &flags);
5287 /* Trigger a scan (look for other cells in the vicinity) */
5288 static int orinoco_ioctl_setscan(struct net_device *dev,
5289 struct iw_request_info *info,
5290 struct iw_param *srq,
5293 struct orinoco_private *priv = netdev_priv(dev);
5294 hermes_t *hw = &priv->hw;
5295 struct iw_scan_req *si = (struct iw_scan_req *) extra;
5297 unsigned long flags;
5299 /* Note : you may have realised that, as this is a SET operation,
5300 * this is privileged and therefore a normal user can't
5302 * This is not an error, while the device perform scanning,
5303 * traffic doesn't flow, so it's a perfect DoS...
5306 if (orinoco_lock(priv, &flags) != 0)
5309 /* Scanning with port 0 disabled would fail */
5310 if (!netif_running(dev)) {
5315 /* In monitor mode, the scan results are always empty.
5316 * Probe responses are passed to the driver as received
5317 * frames and could be processed in software. */
5318 if (priv->iw_mode == IW_MODE_MONITOR) {
5323 /* Note : because we don't lock out the irq handler, the way
5324 * we access scan variables in priv is critical.
5325 * o scan_inprogress : not touched by irq handler
5326 * o scan_mode : not touched by irq handler
5327 * Before modifying anything on those variables, please think hard !
5331 priv->scan_mode = srq->flags;
5333 /* Always trigger scanning, even if it's in progress.
5334 * This way, if the info frame get lost, we will recover somewhat
5335 * gracefully - Jean II */
5337 if (priv->has_hostscan) {
5338 switch (priv->firmware_type) {
5339 case FIRMWARE_TYPE_SYMBOL:
5340 err = hermes_write_wordrec(hw, USER_BAP,
5341 HERMES_RID_CNFHOSTSCAN_SYMBOL,
5342 HERMES_HOSTSCAN_SYMBOL_ONCE |
5343 HERMES_HOSTSCAN_SYMBOL_BCAST);
5345 case FIRMWARE_TYPE_INTERSIL: {
5348 req[0] = cpu_to_le16(0x3fff); /* All channels */
5349 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
5350 req[2] = 0; /* Any ESSID */
5351 err = HERMES_WRITE_RECORD(hw, USER_BAP,
5352 HERMES_RID_CNFHOSTSCAN, &req);
5355 case FIRMWARE_TYPE_AGERE:
5356 if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
5357 struct hermes_idstring idbuf;
5358 size_t len = min(sizeof(idbuf.val),
5359 (size_t) si->essid_len);
5360 idbuf.len = cpu_to_le16(len);
5361 memcpy(idbuf.val, si->essid, len);
5363 err = hermes_write_ltv(hw, USER_BAP,
5364 HERMES_RID_CNFSCANSSID_AGERE,
5365 HERMES_BYTES_TO_RECLEN(len + 2),
5368 err = hermes_write_wordrec(hw, USER_BAP,
5369 HERMES_RID_CNFSCANSSID_AGERE,
5374 if (priv->has_ext_scan) {
5375 /* Clear scan results at the start of
5376 * an extended scan */
5377 orinoco_clear_scan_results(priv,
5378 msecs_to_jiffies(15000));
5380 /* TODO: Is this available on older firmware?
5381 * Can we use it to scan specific channels
5382 * for IW_SCAN_THIS_FREQ? */
5383 err = hermes_write_wordrec(hw, USER_BAP,
5384 HERMES_RID_CNFSCANCHANNELS2GHZ,
5389 err = hermes_inquire(hw,
5390 HERMES_INQ_CHANNELINFO);
5392 err = hermes_inquire(hw, HERMES_INQ_SCAN);
5396 err = hermes_inquire(hw, HERMES_INQ_SCAN);
5398 /* One more client */
5400 priv->scan_inprogress = 1;
5403 orinoco_unlock(priv, &flags);
5407 #define MAX_CUSTOM_LEN 64
5409 /* Translate scan data returned from the card to a card independant
5410 * format that the Wireless Tools will understand - Jean II */
5411 static inline char *orinoco_translate_scan(struct net_device *dev,
5412 struct iw_request_info *info,
5415 union hermes_scan_info *bss,
5416 unsigned int last_scanned)
5418 struct orinoco_private *priv = netdev_priv(dev);
5421 struct iw_event iwe; /* Temporary buffer */
5422 char custom[MAX_CUSTOM_LEN];
5424 memset(&iwe, 0, sizeof(iwe));
5426 /* First entry *MUST* be the AP MAC address */
5427 iwe.cmd = SIOCGIWAP;
5428 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
5429 memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
5430 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5431 &iwe, IW_EV_ADDR_LEN);
5433 /* Other entries will be displayed in the order we give them */
5436 iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
5437 if (iwe.u.data.length > 32)
5438 iwe.u.data.length = 32;
5439 iwe.cmd = SIOCGIWESSID;
5440 iwe.u.data.flags = 1;
5441 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5442 &iwe, bss->a.essid);
5445 iwe.cmd = SIOCGIWMODE;
5446 capabilities = le16_to_cpu(bss->a.capabilities);
5447 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
5448 if (capabilities & WLAN_CAPABILITY_ESS)
5449 iwe.u.mode = IW_MODE_MASTER;
5451 iwe.u.mode = IW_MODE_ADHOC;
5452 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5453 &iwe, IW_EV_UINT_LEN);
5456 channel = bss->s.channel;
5457 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
5458 /* Add channel and frequency */
5459 iwe.cmd = SIOCGIWFREQ;
5460 iwe.u.freq.m = channel;
5462 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5463 &iwe, IW_EV_FREQ_LEN);
5465 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
5467 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5468 &iwe, IW_EV_FREQ_LEN);
5471 /* Add quality statistics. level and noise in dB. No link quality */
5473 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
5474 iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
5475 iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
5476 /* Wireless tools prior to 27.pre22 will show link quality
5477 * anyway, so we provide a reasonable value. */
5478 if (iwe.u.qual.level > iwe.u.qual.noise)
5479 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
5481 iwe.u.qual.qual = 0;
5482 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5483 &iwe, IW_EV_QUAL_LEN);
5485 /* Add encryption capability */
5486 iwe.cmd = SIOCGIWENCODE;
5487 if (capabilities & WLAN_CAPABILITY_PRIVACY)
5488 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
5490 iwe.u.data.flags = IW_ENCODE_DISABLED;
5491 iwe.u.data.length = 0;
5492 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5495 /* Bit rate is not available in Lucent/Agere firmwares */
5496 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
5497 char *current_val = current_ev + iwe_stream_lcp_len(info);
5501 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
5506 iwe.cmd = SIOCGIWRATE;
5507 /* Those two flags are ignored... */
5508 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
5510 for (i = 0; i < 10; i += step) {
5511 /* NULL terminated */
5512 if (bss->p.rates[i] == 0x0)
5514 /* Bit rate given in 500 kb/s units (+ 0x80) */
5515 iwe.u.bitrate.value =
5516 ((bss->p.rates[i] & 0x7f) * 500000);
5517 current_val = iwe_stream_add_value(info, current_ev,
5522 /* Check if we added any event */
5523 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
5524 current_ev = current_val;
5527 /* Beacon interval */
5528 iwe.cmd = IWEVCUSTOM;
5529 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5531 le16_to_cpu(bss->a.beacon_interv));
5532 if (iwe.u.data.length)
5533 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5537 iwe.cmd = IWEVCUSTOM;
5538 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5541 if (iwe.u.data.length)
5542 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5545 /* Add EXTRA: Age to display seconds since last beacon/probe response
5546 * for given network. */
5547 iwe.cmd = IWEVCUSTOM;
5548 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5549 " Last beacon: %dms ago",
5550 jiffies_to_msecs(jiffies - last_scanned));
5551 if (iwe.u.data.length)
5552 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5558 static inline char *orinoco_translate_ext_scan(struct net_device *dev,
5559 struct iw_request_info *info,
5562 struct agere_ext_scan_info *bss,
5563 unsigned int last_scanned)
5567 struct iw_event iwe; /* Temporary buffer */
5568 char custom[MAX_CUSTOM_LEN];
5571 memset(&iwe, 0, sizeof(iwe));
5573 /* First entry *MUST* be the AP MAC address */
5574 iwe.cmd = SIOCGIWAP;
5575 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
5576 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
5577 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5578 &iwe, IW_EV_ADDR_LEN);
5580 /* Other entries will be displayed in the order we give them */
5584 iwe.u.data.length = ie[1];
5585 if (iwe.u.data.length) {
5586 if (iwe.u.data.length > 32)
5587 iwe.u.data.length = 32;
5588 iwe.cmd = SIOCGIWESSID;
5589 iwe.u.data.flags = 1;
5590 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5595 capabilities = le16_to_cpu(bss->capabilities);
5596 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
5597 iwe.cmd = SIOCGIWMODE;
5598 if (capabilities & WLAN_CAPABILITY_ESS)
5599 iwe.u.mode = IW_MODE_MASTER;
5601 iwe.u.mode = IW_MODE_ADHOC;
5602 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5603 &iwe, IW_EV_UINT_LEN);
5606 ie = orinoco_get_ie(bss->data, sizeof(bss->data), MFIE_TYPE_DS_SET);
5607 channel = ie ? ie[2] : 0;
5608 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
5609 /* Add channel and frequency */
5610 iwe.cmd = SIOCGIWFREQ;
5611 iwe.u.freq.m = channel;
5613 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5614 &iwe, IW_EV_FREQ_LEN);
5616 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
5618 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5619 &iwe, IW_EV_FREQ_LEN);
5622 /* Add quality statistics. level and noise in dB. No link quality */
5624 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
5625 iwe.u.qual.level = bss->level - 0x95;
5626 iwe.u.qual.noise = bss->noise - 0x95;
5627 /* Wireless tools prior to 27.pre22 will show link quality
5628 * anyway, so we provide a reasonable value. */
5629 if (iwe.u.qual.level > iwe.u.qual.noise)
5630 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
5632 iwe.u.qual.qual = 0;
5633 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
5634 &iwe, IW_EV_QUAL_LEN);
5636 /* Add encryption capability */
5637 iwe.cmd = SIOCGIWENCODE;
5638 if (capabilities & WLAN_CAPABILITY_PRIVACY)
5639 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
5641 iwe.u.data.flags = IW_ENCODE_DISABLED;
5642 iwe.u.data.length = 0;
5643 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5647 ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data));
5649 iwe.cmd = IWEVGENIE;
5650 iwe.u.data.length = ie[1] + 2;
5651 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5656 ie = orinoco_get_ie(bss->data, sizeof(bss->data), MFIE_TYPE_RSN);
5658 iwe.cmd = IWEVGENIE;
5659 iwe.u.data.length = ie[1] + 2;
5660 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5664 ie = orinoco_get_ie(bss->data, sizeof(bss->data), MFIE_TYPE_RATES);
5666 char *p = current_ev + iwe_stream_lcp_len(info);
5669 iwe.cmd = SIOCGIWRATE;
5670 /* Those two flags are ignored... */
5671 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
5673 for (i = 2; i < (ie[1] + 2); i++) {
5674 iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000);
5675 p = iwe_stream_add_value(info, current_ev, p, end_buf,
5676 &iwe, IW_EV_PARAM_LEN);
5678 /* Check if we added any event */
5679 if (p > (current_ev + iwe_stream_lcp_len(info)))
5684 iwe.cmd = IWEVCUSTOM;
5685 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5687 le64_to_cpu(bss->timestamp));
5688 if (iwe.u.data.length)
5689 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5692 /* Beacon interval */
5693 iwe.cmd = IWEVCUSTOM;
5694 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5696 le16_to_cpu(bss->beacon_interval));
5697 if (iwe.u.data.length)
5698 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5702 iwe.cmd = IWEVCUSTOM;
5703 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5706 if (iwe.u.data.length)
5707 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5710 /* Add EXTRA: Age to display seconds since last beacon/probe response
5711 * for given network. */
5712 iwe.cmd = IWEVCUSTOM;
5713 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
5714 " Last beacon: %dms ago",
5715 jiffies_to_msecs(jiffies - last_scanned));
5716 if (iwe.u.data.length)
5717 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
5723 /* Return results of a scan */
5724 static int orinoco_ioctl_getscan(struct net_device *dev,
5725 struct iw_request_info *info,
5726 struct iw_point *srq,
5729 struct orinoco_private *priv = netdev_priv(dev);
5731 unsigned long flags;
5732 char *current_ev = extra;
5734 if (orinoco_lock(priv, &flags) != 0)
5737 if (priv->scan_inprogress) {
5738 /* Important note : we don't want to block the caller
5739 * until results are ready for various reasons.
5740 * First, managing wait queues is complex and racy.
5741 * Second, we grab some rtnetlink lock before comming
5742 * here (in dev_ioctl()).
5743 * Third, we generate an Wireless Event, so the
5744 * caller can wait itself on that - Jean II */
5749 if (priv->has_ext_scan) {
5750 struct xbss_element *bss;
5752 list_for_each_entry(bss, &priv->bss_list, list) {
5753 /* Translate this entry to WE format */
5755 orinoco_translate_ext_scan(dev, info,
5757 extra + srq->length,
5761 /* Check if there is space for one more entry */
5762 if ((extra + srq->length - current_ev)
5763 <= IW_EV_ADDR_LEN) {
5764 /* Ask user space to try again with a
5772 struct bss_element *bss;
5774 list_for_each_entry(bss, &priv->bss_list, list) {
5775 /* Translate this entry to WE format */
5776 current_ev = orinoco_translate_scan(dev, info,
5778 extra + srq->length,
5782 /* Check if there is space for one more entry */
5783 if ((extra + srq->length - current_ev)
5784 <= IW_EV_ADDR_LEN) {
5785 /* Ask user space to try again with a
5793 srq->length = (current_ev - extra);
5794 srq->flags = (__u16) priv->scan_mode;
5797 orinoco_unlock(priv, &flags);
5801 /* Commit handler, called after set operations */
5802 static int orinoco_ioctl_commit(struct net_device *dev,
5803 struct iw_request_info *info,
5807 struct orinoco_private *priv = netdev_priv(dev);
5808 struct hermes *hw = &priv->hw;
5809 unsigned long flags;
5815 if (priv->broken_disableport) {
5816 orinoco_reset(&priv->reset_work);
5820 if (orinoco_lock(priv, &flags) != 0)
5823 err = hermes_disable_port(hw, 0);
5825 printk(KERN_WARNING "%s: Unable to disable port "
5826 "while reconfiguring card\n", dev->name);
5827 priv->broken_disableport = 1;
5831 err = __orinoco_program_rids(dev);
5833 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
5838 err = hermes_enable_port(hw, 0);
5840 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
5847 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
5848 schedule_work(&priv->reset_work);
5852 orinoco_unlock(priv, &flags);
5856 static const struct iw_priv_args orinoco_privtab[] = {
5857 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
5858 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
5859 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5861 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5863 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5864 0, "set_preamble" },
5865 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5867 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5868 0, "set_ibssport" },
5869 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5871 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
5877 * Structures to export the Wireless Handlers
5880 #define STD_IW_HANDLER(id, func) \
5881 [IW_IOCTL_IDX(id)] = (iw_handler) func
5882 static const iw_handler orinoco_handler[] = {
5883 STD_IW_HANDLER(SIOCSIWCOMMIT, orinoco_ioctl_commit),
5884 STD_IW_HANDLER(SIOCGIWNAME, orinoco_ioctl_getname),
5885 STD_IW_HANDLER(SIOCSIWFREQ, orinoco_ioctl_setfreq),
5886 STD_IW_HANDLER(SIOCGIWFREQ, orinoco_ioctl_getfreq),
5887 STD_IW_HANDLER(SIOCSIWMODE, orinoco_ioctl_setmode),
5888 STD_IW_HANDLER(SIOCGIWMODE, orinoco_ioctl_getmode),
5889 STD_IW_HANDLER(SIOCSIWSENS, orinoco_ioctl_setsens),
5890 STD_IW_HANDLER(SIOCGIWSENS, orinoco_ioctl_getsens),
5891 STD_IW_HANDLER(SIOCGIWRANGE, orinoco_ioctl_getiwrange),
5892 STD_IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
5893 STD_IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
5894 STD_IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
5895 STD_IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
5896 STD_IW_HANDLER(SIOCSIWAP, orinoco_ioctl_setwap),
5897 STD_IW_HANDLER(SIOCGIWAP, orinoco_ioctl_getwap),
5898 STD_IW_HANDLER(SIOCSIWSCAN, orinoco_ioctl_setscan),
5899 STD_IW_HANDLER(SIOCGIWSCAN, orinoco_ioctl_getscan),
5900 STD_IW_HANDLER(SIOCSIWESSID, orinoco_ioctl_setessid),
5901 STD_IW_HANDLER(SIOCGIWESSID, orinoco_ioctl_getessid),
5902 STD_IW_HANDLER(SIOCSIWNICKN, orinoco_ioctl_setnick),
5903 STD_IW_HANDLER(SIOCGIWNICKN, orinoco_ioctl_getnick),
5904 STD_IW_HANDLER(SIOCSIWRATE, orinoco_ioctl_setrate),
5905 STD_IW_HANDLER(SIOCGIWRATE, orinoco_ioctl_getrate),
5906 STD_IW_HANDLER(SIOCSIWRTS, orinoco_ioctl_setrts),
5907 STD_IW_HANDLER(SIOCGIWRTS, orinoco_ioctl_getrts),
5908 STD_IW_HANDLER(SIOCSIWFRAG, orinoco_ioctl_setfrag),
5909 STD_IW_HANDLER(SIOCGIWFRAG, orinoco_ioctl_getfrag),
5910 STD_IW_HANDLER(SIOCGIWRETRY, orinoco_ioctl_getretry),
5911 STD_IW_HANDLER(SIOCSIWENCODE, orinoco_ioctl_setiwencode),
5912 STD_IW_HANDLER(SIOCGIWENCODE, orinoco_ioctl_getiwencode),
5913 STD_IW_HANDLER(SIOCSIWPOWER, orinoco_ioctl_setpower),
5914 STD_IW_HANDLER(SIOCGIWPOWER, orinoco_ioctl_getpower),
5915 STD_IW_HANDLER(SIOCSIWGENIE, orinoco_ioctl_set_genie),
5916 STD_IW_HANDLER(SIOCGIWGENIE, orinoco_ioctl_get_genie),
5917 STD_IW_HANDLER(SIOCSIWMLME, orinoco_ioctl_set_mlme),
5918 STD_IW_HANDLER(SIOCSIWAUTH, orinoco_ioctl_set_auth),
5919 STD_IW_HANDLER(SIOCGIWAUTH, orinoco_ioctl_get_auth),
5920 STD_IW_HANDLER(SIOCSIWENCODEEXT, orinoco_ioctl_set_encodeext),
5921 STD_IW_HANDLER(SIOCGIWENCODEEXT, orinoco_ioctl_get_encodeext),
5926 Added typecasting since we no longer use iwreq_data -- Moustafa
5928 static const iw_handler orinoco_private_handler[] = {
5929 [0] = (iw_handler) orinoco_ioctl_reset,
5930 [1] = (iw_handler) orinoco_ioctl_reset,
5931 [2] = (iw_handler) orinoco_ioctl_setport3,
5932 [3] = (iw_handler) orinoco_ioctl_getport3,
5933 [4] = (iw_handler) orinoco_ioctl_setpreamble,
5934 [5] = (iw_handler) orinoco_ioctl_getpreamble,
5935 [6] = (iw_handler) orinoco_ioctl_setibssport,
5936 [7] = (iw_handler) orinoco_ioctl_getibssport,
5937 [9] = (iw_handler) orinoco_ioctl_getrid,
5940 static const struct iw_handler_def orinoco_handler_def = {
5941 .num_standard = ARRAY_SIZE(orinoco_handler),
5942 .num_private = ARRAY_SIZE(orinoco_private_handler),
5943 .num_private_args = ARRAY_SIZE(orinoco_privtab),
5944 .standard = orinoco_handler,
5945 .private = orinoco_private_handler,
5946 .private_args = orinoco_privtab,
5947 .get_wireless_stats = orinoco_get_wireless_stats,
5950 static void orinoco_get_drvinfo(struct net_device *dev,
5951 struct ethtool_drvinfo *info)
5953 struct orinoco_private *priv = netdev_priv(dev);
5955 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
5956 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
5957 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
5958 if (dev->dev.parent)
5959 strncpy(info->bus_info, dev->dev.parent->bus_id,
5960 sizeof(info->bus_info) - 1);
5962 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
5963 "PCMCIA %p", priv->hw.iobase);
5966 static const struct ethtool_ops orinoco_ethtool_ops = {
5967 .get_drvinfo = orinoco_get_drvinfo,
5968 .get_link = ethtool_op_get_link,
5971 /********************************************************************/
5972 /* Module initialization */
5973 /********************************************************************/
5975 EXPORT_SYMBOL(alloc_orinocodev);
5976 EXPORT_SYMBOL(free_orinocodev);
5978 EXPORT_SYMBOL(__orinoco_up);
5979 EXPORT_SYMBOL(__orinoco_down);
5980 EXPORT_SYMBOL(orinoco_reinit_firmware);
5982 EXPORT_SYMBOL(orinoco_interrupt);
5984 /* Can't be declared "const" or the whole __initdata section will
5986 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
5987 " (David Gibson <hermes@gibson.dropbear.id.au>, "
5988 "Pavel Roskin <proski@gnu.org>, et al)";
5990 static int __init init_orinoco(void)
5992 printk(KERN_DEBUG "%s\n", version);
5996 static void __exit exit_orinoco(void)
6000 module_init(init_orinoco);
6001 module_exit(exit_orinoco);