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, 512 }
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) */
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
;
472 pda
= kzalloc(fw
->pda_size
, GFP_KERNEL
);
477 firmware
= fw
->ap_fw
;
479 firmware
= fw
->sta_fw
;
481 printk(KERN_DEBUG
"%s: Attempting to download firmware %s\n",
482 dev
->name
, firmware
);
484 /* Read current plug data */
485 err
= hermes_read_pda(hw
, pda
, fw
->pda_addr
, fw
->pda_size
, 0);
486 printk(KERN_DEBUG
"%s: Read PDA returned %d\n", dev
->name
, err
);
490 err
= request_firmware(&fw_entry
, firmware
, priv
->dev
);
492 printk(KERN_ERR
"%s: Cannot find firmware %s\n",
493 dev
->name
, firmware
);
498 hdr
= (const struct orinoco_fw_header
*) fw_entry
->data
;
500 /* Enable aux port to allow programming */
501 err
= hermesi_program_init(hw
, le32_to_cpu(hdr
->entry_point
));
502 printk(KERN_DEBUG
"%s: Program init returned %d\n", dev
->name
, err
);
507 first_block
= (fw_entry
->data
+
508 le16_to_cpu(hdr
->headersize
) +
509 le32_to_cpu(hdr
->block_offset
));
510 end
= fw_entry
->data
+ fw_entry
->size
;
512 err
= hermes_program(hw
, first_block
, end
);
513 printk(KERN_DEBUG
"%s: Program returned %d\n", dev
->name
, err
);
517 /* Update production data */
518 first_block
= (fw_entry
->data
+
519 le16_to_cpu(hdr
->headersize
) +
520 le32_to_cpu(hdr
->pdr_offset
));
522 err
= hermes_apply_pda_with_defaults(hw
, first_block
, pda
);
523 printk(KERN_DEBUG
"%s: Apply PDA returned %d\n", dev
->name
, err
);
527 /* Tell card we've finished */
528 err
= hermesi_program_end(hw
);
529 printk(KERN_DEBUG
"%s: Program end returned %d\n", dev
->name
, err
);
533 /* Check if we're running */
534 printk(KERN_DEBUG
"%s: hermes_present returned %d\n",
535 dev
->name
, hermes_present(hw
));
538 release_firmware(fw_entry
);
546 #define TEXT_END 0x1A /* End of text header */
549 * Process a firmware image - stop the card, load the firmware, reset
550 * the card and make sure it responds. For the secondary firmware take
551 * care of the PDA - read it and then write it on top of the firmware.
554 symbol_dl_image(struct orinoco_private
*priv
, const struct fw_info
*fw
,
555 const unsigned char *image
, const unsigned char *end
,
558 hermes_t
*hw
= &priv
->hw
;
560 const unsigned char *ptr
;
561 const unsigned char *first_block
;
563 /* Plug Data Area (PDA) */
566 /* Binary block begins after the 0x1A marker */
568 while (*ptr
++ != TEXT_END
);
571 /* Read the PDA from EEPROM */
573 pda
= kzalloc(fw
->pda_size
, GFP_KERNEL
);
577 ret
= hermes_read_pda(hw
, pda
, fw
->pda_addr
, fw
->pda_size
, 1);
582 /* Stop the firmware, so that it can be safely rewritten */
584 ret
= priv
->stop_fw(priv
, 1);
589 /* Program the adapter with new firmware */
590 ret
= hermes_program(hw
, first_block
, end
);
594 /* Write the PDA to the adapter */
596 size_t len
= hermes_blocks_length(first_block
);
597 ptr
= first_block
+ len
;
598 ret
= hermes_apply_pda(hw
, ptr
, pda
);
604 /* Run the firmware */
606 ret
= priv
->stop_fw(priv
, 0);
611 /* Reset hermes chip and make sure it responds */
612 ret
= hermes_init(hw
);
614 /* hermes_reset() should return 0 with the secondary firmware */
615 if (secondary
&& ret
!= 0)
618 /* And this should work with any firmware */
619 if (!hermes_present(hw
))
631 * Download the firmware into the card, this also does a PCMCIA soft
632 * reset on the card, to make sure it's in a sane state.
635 symbol_dl_firmware(struct orinoco_private
*priv
,
636 const struct fw_info
*fw
)
638 struct net_device
*dev
= priv
->ndev
;
640 const struct firmware
*fw_entry
;
642 if (request_firmware(&fw_entry
, fw
->pri_fw
,
644 printk(KERN_ERR
"%s: Cannot find firmware: %s\n",
645 dev
->name
, fw
->pri_fw
);
649 /* Load primary firmware */
650 ret
= symbol_dl_image(priv
, fw
, fw_entry
->data
,
651 fw_entry
->data
+ fw_entry
->size
, 0);
652 release_firmware(fw_entry
);
654 printk(KERN_ERR
"%s: Primary firmware download failed\n",
659 if (request_firmware(&fw_entry
, fw
->sta_fw
,
661 printk(KERN_ERR
"%s: Cannot find firmware: %s\n",
662 dev
->name
, fw
->sta_fw
);
666 /* Load secondary firmware */
667 ret
= symbol_dl_image(priv
, fw
, fw_entry
->data
,
668 fw_entry
->data
+ fw_entry
->size
, 1);
669 release_firmware(fw_entry
);
671 printk(KERN_ERR
"%s: Secondary firmware download failed\n",
678 static int orinoco_download(struct orinoco_private
*priv
)
681 /* Reload firmware */
682 switch (priv
->firmware_type
) {
683 case FIRMWARE_TYPE_AGERE
:
684 /* case FIRMWARE_TYPE_INTERSIL: */
685 err
= orinoco_dl_firmware(priv
,
686 &orinoco_fw
[priv
->firmware_type
], 0);
689 case FIRMWARE_TYPE_SYMBOL
:
690 err
= symbol_dl_firmware(priv
,
691 &orinoco_fw
[priv
->firmware_type
]);
693 case FIRMWARE_TYPE_INTERSIL
:
696 /* TODO: if we fail we probably need to reinitialise
702 /********************************************************************/
704 /********************************************************************/
706 static int orinoco_open(struct net_device
*dev
)
708 struct orinoco_private
*priv
= netdev_priv(dev
);
712 if (orinoco_lock(priv
, &flags
) != 0)
715 err
= __orinoco_up(dev
);
720 orinoco_unlock(priv
, &flags
);
725 static int orinoco_stop(struct net_device
*dev
)
727 struct orinoco_private
*priv
= netdev_priv(dev
);
730 /* We mustn't use orinoco_lock() here, because we need to be
731 able to close the interface even if hw_unavailable is set
732 (e.g. as we're released after a PC Card removal) */
733 spin_lock_irq(&priv
->lock
);
737 err
= __orinoco_down(dev
);
739 spin_unlock_irq(&priv
->lock
);
744 static struct net_device_stats
*orinoco_get_stats(struct net_device
*dev
)
746 struct orinoco_private
*priv
= netdev_priv(dev
);
751 static struct iw_statistics
*orinoco_get_wireless_stats(struct net_device
*dev
)
753 struct orinoco_private
*priv
= netdev_priv(dev
);
754 hermes_t
*hw
= &priv
->hw
;
755 struct iw_statistics
*wstats
= &priv
->wstats
;
759 if (! netif_device_present(dev
)) {
760 printk(KERN_WARNING
"%s: get_wireless_stats() called while device not present\n",
762 return NULL
; /* FIXME: Can we do better than this? */
765 /* If busy, return the old stats. Returning NULL may cause
766 * the interface to disappear from /proc/net/wireless */
767 if (orinoco_lock(priv
, &flags
) != 0)
770 /* We can't really wait for the tallies inquiry command to
771 * complete, so we just use the previous results and trigger
772 * a new tallies inquiry command for next time - Jean II */
773 /* FIXME: Really we should wait for the inquiry to come back -
774 * as it is the stats we give don't make a whole lot of sense.
775 * Unfortunately, it's not clear how to do that within the
776 * wireless extensions framework: I think we're in user
777 * context, but a lock seems to be held by the time we get in
778 * here so we're not safe to sleep here. */
779 hermes_inquire(hw
, HERMES_INQ_TALLIES
);
781 if (priv
->iw_mode
== IW_MODE_ADHOC
) {
782 memset(&wstats
->qual
, 0, sizeof(wstats
->qual
));
783 /* If a spy address is defined, we report stats of the
784 * first spy address - Jean II */
785 if (SPY_NUMBER(priv
)) {
786 wstats
->qual
.qual
= priv
->spy_data
.spy_stat
[0].qual
;
787 wstats
->qual
.level
= priv
->spy_data
.spy_stat
[0].level
;
788 wstats
->qual
.noise
= priv
->spy_data
.spy_stat
[0].noise
;
789 wstats
->qual
.updated
= priv
->spy_data
.spy_stat
[0].updated
;
793 __le16 qual
, signal
, noise
, unused
;
794 } __attribute__ ((packed
)) cq
;
796 err
= HERMES_READ_RECORD(hw
, USER_BAP
,
797 HERMES_RID_COMMSQUALITY
, &cq
);
800 wstats
->qual
.qual
= (int)le16_to_cpu(cq
.qual
);
801 wstats
->qual
.level
= (int)le16_to_cpu(cq
.signal
) - 0x95;
802 wstats
->qual
.noise
= (int)le16_to_cpu(cq
.noise
) - 0x95;
803 wstats
->qual
.updated
= 7;
807 orinoco_unlock(priv
, &flags
);
811 static void orinoco_set_multicast_list(struct net_device
*dev
)
813 struct orinoco_private
*priv
= netdev_priv(dev
);
816 if (orinoco_lock(priv
, &flags
) != 0) {
817 printk(KERN_DEBUG
"%s: orinoco_set_multicast_list() "
818 "called when hw_unavailable\n", dev
->name
);
822 __orinoco_set_multicast_list(dev
);
823 orinoco_unlock(priv
, &flags
);
826 static int orinoco_change_mtu(struct net_device
*dev
, int new_mtu
)
828 struct orinoco_private
*priv
= netdev_priv(dev
);
830 if ( (new_mtu
< ORINOCO_MIN_MTU
) || (new_mtu
> ORINOCO_MAX_MTU
) )
833 if ( (new_mtu
+ ENCAPS_OVERHEAD
+ IEEE80211_HLEN
) >
834 (priv
->nicbuf_size
- ETH_HLEN
) )
842 /********************************************************************/
844 /********************************************************************/
846 static int orinoco_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
848 struct orinoco_private
*priv
= netdev_priv(dev
);
849 struct net_device_stats
*stats
= &priv
->stats
;
850 hermes_t
*hw
= &priv
->hw
;
852 u16 txfid
= priv
->txfid
;
857 if (! netif_running(dev
)) {
858 printk(KERN_ERR
"%s: Tx on stopped device!\n",
860 return NETDEV_TX_BUSY
;
863 if (netif_queue_stopped(dev
)) {
864 printk(KERN_DEBUG
"%s: Tx while transmitter busy!\n",
866 return NETDEV_TX_BUSY
;
869 if (orinoco_lock(priv
, &flags
) != 0) {
870 printk(KERN_ERR
"%s: orinoco_xmit() called while hw_unavailable\n",
872 return NETDEV_TX_BUSY
;
875 if (! netif_carrier_ok(dev
) || (priv
->iw_mode
== IW_MODE_MONITOR
)) {
876 /* Oops, the firmware hasn't established a connection,
877 silently drop the packet (this seems to be the
882 /* Check packet length */
883 if (skb
->len
< ETH_HLEN
)
886 tx_control
= HERMES_TXCTRL_TX_OK
| HERMES_TXCTRL_TX_EX
;
888 if (priv
->encode_alg
== IW_ENCODE_ALG_TKIP
)
889 tx_control
|= (priv
->tx_key
<< HERMES_MIC_KEY_ID_SHIFT
) |
892 if (priv
->has_alt_txcntl
) {
893 /* WPA enabled firmwares have tx_cntl at the end of
894 * the 802.11 header. So write zeroed descriptor and
895 * 802.11 header at the same time
897 char desc
[HERMES_802_3_OFFSET
];
898 __le16
*txcntl
= (__le16
*) &desc
[HERMES_TXCNTL2_OFFSET
];
900 memset(&desc
, 0, sizeof(desc
));
902 *txcntl
= cpu_to_le16(tx_control
);
903 err
= hermes_bap_pwrite(hw
, USER_BAP
, &desc
, sizeof(desc
),
907 printk(KERN_ERR
"%s: Error %d writing Tx "
908 "descriptor to BAP\n", dev
->name
, err
);
912 struct hermes_tx_descriptor desc
;
914 memset(&desc
, 0, sizeof(desc
));
916 desc
.tx_control
= cpu_to_le16(tx_control
);
917 err
= hermes_bap_pwrite(hw
, USER_BAP
, &desc
, sizeof(desc
),
921 printk(KERN_ERR
"%s: Error %d writing Tx "
922 "descriptor to BAP\n", dev
->name
, err
);
926 /* Clear the 802.11 header and data length fields - some
927 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
928 * if this isn't done. */
929 hermes_clear_words(hw
, HERMES_DATA0
,
930 HERMES_802_3_OFFSET
- HERMES_802_11_OFFSET
);
933 eh
= (struct ethhdr
*)skb
->data
;
935 /* Encapsulate Ethernet-II frames */
936 if (ntohs(eh
->h_proto
) > ETH_DATA_LEN
) { /* Ethernet-II frame */
937 struct header_struct
{
938 struct ethhdr eth
; /* 802.3 header */
939 u8 encap
[6]; /* 802.2 header */
940 } __attribute__ ((packed
)) hdr
;
942 /* Strip destination and source from the data */
943 skb_pull(skb
, 2 * ETH_ALEN
);
945 /* And move them to a separate header */
946 memcpy(&hdr
.eth
, eh
, 2 * ETH_ALEN
);
947 hdr
.eth
.h_proto
= htons(sizeof(encaps_hdr
) + skb
->len
);
948 memcpy(hdr
.encap
, encaps_hdr
, sizeof(encaps_hdr
));
950 /* Insert the SNAP header */
951 if (skb_headroom(skb
) < sizeof(hdr
)) {
953 "%s: Not enough headroom for 802.2 headers %d\n",
954 dev
->name
, skb_headroom(skb
));
957 eh
= (struct ethhdr
*) skb_push(skb
, sizeof(hdr
));
958 memcpy(eh
, &hdr
, sizeof(hdr
));
961 err
= hermes_bap_pwrite(hw
, USER_BAP
, skb
->data
, skb
->len
,
962 txfid
, HERMES_802_3_OFFSET
);
964 printk(KERN_ERR
"%s: Error %d writing packet to BAP\n",
969 /* Calculate Michael MIC */
970 if (priv
->encode_alg
== IW_ENCODE_ALG_TKIP
) {
971 u8 mic_buf
[MICHAEL_MIC_LEN
+ 1];
977 /* MIC start is on an odd boundary */
978 mic_buf
[0] = skb
->data
[skb
->len
- 1];
980 offset
= skb
->len
- 1;
981 len
= MICHAEL_MIC_LEN
+ 1;
985 len
= MICHAEL_MIC_LEN
;
988 michael_mic(priv
->tx_tfm_mic
,
989 priv
->tkip_key
[priv
->tx_key
].tx_mic
,
990 eh
->h_dest
, eh
->h_source
, 0 /* priority */,
991 skb
->data
+ ETH_HLEN
, skb
->len
- ETH_HLEN
, mic
);
994 err
= hermes_bap_pwrite(hw
, USER_BAP
, &mic_buf
[0], len
,
995 txfid
, HERMES_802_3_OFFSET
+ offset
);
997 printk(KERN_ERR
"%s: Error %d writing MIC to BAP\n",
1003 /* Finally, we actually initiate the send */
1004 netif_stop_queue(dev
);
1006 err
= hermes_docmd_wait(hw
, HERMES_CMD_TX
| HERMES_CMD_RECL
,
1009 netif_start_queue(dev
);
1010 if (net_ratelimit())
1011 printk(KERN_ERR
"%s: Error %d transmitting packet\n",
1016 dev
->trans_start
= jiffies
;
1017 stats
->tx_bytes
+= HERMES_802_3_OFFSET
+ skb
->len
;
1022 stats
->tx_dropped
++;
1025 orinoco_unlock(priv
, &flags
);
1027 return NETDEV_TX_OK
;
1031 schedule_work(&priv
->reset_work
);
1032 orinoco_unlock(priv
, &flags
);
1033 return NETDEV_TX_BUSY
;
1036 static void __orinoco_ev_alloc(struct net_device
*dev
, hermes_t
*hw
)
1038 struct orinoco_private
*priv
= netdev_priv(dev
);
1039 u16 fid
= hermes_read_regn(hw
, ALLOCFID
);
1041 if (fid
!= priv
->txfid
) {
1042 if (fid
!= DUMMY_FID
)
1043 printk(KERN_WARNING
"%s: Allocate event on unexpected fid (%04X)\n",
1048 hermes_write_regn(hw
, ALLOCFID
, DUMMY_FID
);
1051 static void __orinoco_ev_tx(struct net_device
*dev
, hermes_t
*hw
)
1053 struct orinoco_private
*priv
= netdev_priv(dev
);
1054 struct net_device_stats
*stats
= &priv
->stats
;
1056 stats
->tx_packets
++;
1058 netif_wake_queue(dev
);
1060 hermes_write_regn(hw
, TXCOMPLFID
, DUMMY_FID
);
1063 static void __orinoco_ev_txexc(struct net_device
*dev
, hermes_t
*hw
)
1065 struct orinoco_private
*priv
= netdev_priv(dev
);
1066 struct net_device_stats
*stats
= &priv
->stats
;
1067 u16 fid
= hermes_read_regn(hw
, TXCOMPLFID
);
1069 struct hermes_txexc_data hdr
;
1072 if (fid
== DUMMY_FID
)
1073 return; /* Nothing's really happened */
1075 /* Read part of the frame header - we need status and addr1 */
1076 err
= hermes_bap_pread(hw
, IRQ_BAP
, &hdr
,
1077 sizeof(struct hermes_txexc_data
),
1080 hermes_write_regn(hw
, TXCOMPLFID
, DUMMY_FID
);
1084 printk(KERN_WARNING
"%s: Unable to read descriptor on Tx error "
1085 "(FID=%04X error %d)\n",
1086 dev
->name
, fid
, err
);
1090 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev
->name
,
1093 /* We produce a TXDROP event only for retry or lifetime
1094 * exceeded, because that's the only status that really mean
1095 * that this particular node went away.
1096 * Other errors means that *we* screwed up. - Jean II */
1097 status
= le16_to_cpu(hdr
.desc
.status
);
1098 if (status
& (HERMES_TXSTAT_RETRYERR
| HERMES_TXSTAT_AGEDERR
)) {
1099 union iwreq_data wrqu
;
1101 /* Copy 802.11 dest address.
1102 * We use the 802.11 header because the frame may
1103 * not be 802.3 or may be mangled...
1104 * In Ad-Hoc mode, it will be the node address.
1105 * In managed mode, it will be most likely the AP addr
1106 * User space will figure out how to convert it to
1107 * whatever it needs (IP address or else).
1109 memcpy(wrqu
.addr
.sa_data
, hdr
.addr1
, ETH_ALEN
);
1110 wrqu
.addr
.sa_family
= ARPHRD_ETHER
;
1112 /* Send event to user space */
1113 wireless_send_event(dev
, IWEVTXDROP
, &wrqu
, NULL
);
1116 netif_wake_queue(dev
);
1119 static void orinoco_tx_timeout(struct net_device
*dev
)
1121 struct orinoco_private
*priv
= netdev_priv(dev
);
1122 struct net_device_stats
*stats
= &priv
->stats
;
1123 struct hermes
*hw
= &priv
->hw
;
1125 printk(KERN_WARNING
"%s: Tx timeout! "
1126 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
1127 dev
->name
, hermes_read_regn(hw
, ALLOCFID
),
1128 hermes_read_regn(hw
, TXCOMPLFID
), hermes_read_regn(hw
, EVSTAT
));
1132 schedule_work(&priv
->reset_work
);
1135 /********************************************************************/
1136 /* Rx path (data frames) */
1137 /********************************************************************/
1139 /* Does the frame have a SNAP header indicating it should be
1140 * de-encapsulated to Ethernet-II? */
1141 static inline int is_ethersnap(void *_hdr
)
1145 /* We de-encapsulate all packets which, a) have SNAP headers
1146 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
1147 * and where b) the OUI of the SNAP header is 00:00:00 or
1148 * 00:00:f8 - we need both because different APs appear to use
1149 * different OUIs for some reason */
1150 return (memcmp(hdr
, &encaps_hdr
, 5) == 0)
1151 && ( (hdr
[5] == 0x00) || (hdr
[5] == 0xf8) );
1154 static inline void orinoco_spy_gather(struct net_device
*dev
, u_char
*mac
,
1155 int level
, int noise
)
1157 struct iw_quality wstats
;
1158 wstats
.level
= level
- 0x95;
1159 wstats
.noise
= noise
- 0x95;
1160 wstats
.qual
= (level
> noise
) ? (level
- noise
) : 0;
1162 /* Update spy records */
1163 wireless_spy_update(dev
, mac
, &wstats
);
1166 static void orinoco_stat_gather(struct net_device
*dev
,
1167 struct sk_buff
*skb
,
1168 struct hermes_rx_descriptor
*desc
)
1170 struct orinoco_private
*priv
= netdev_priv(dev
);
1172 /* Using spy support with lots of Rx packets, like in an
1173 * infrastructure (AP), will really slow down everything, because
1174 * the MAC address must be compared to each entry of the spy list.
1175 * If the user really asks for it (set some address in the
1176 * spy list), we do it, but he will pay the price.
1177 * Note that to get here, you need both WIRELESS_SPY
1178 * compiled in AND some addresses in the list !!!
1180 /* Note : gcc will optimise the whole section away if
1181 * WIRELESS_SPY is not defined... - Jean II */
1182 if (SPY_NUMBER(priv
)) {
1183 orinoco_spy_gather(dev
, skb_mac_header(skb
) + ETH_ALEN
,
1184 desc
->signal
, desc
->silence
);
1189 * orinoco_rx_monitor - handle received monitor frames.
1192 * dev network device
1193 * rxfid received FID
1194 * desc rx descriptor of the frame
1196 * Call context: interrupt
1198 static void orinoco_rx_monitor(struct net_device
*dev
, u16 rxfid
,
1199 struct hermes_rx_descriptor
*desc
)
1201 u32 hdrlen
= 30; /* return full header by default */
1206 struct sk_buff
*skb
;
1207 struct orinoco_private
*priv
= netdev_priv(dev
);
1208 struct net_device_stats
*stats
= &priv
->stats
;
1209 hermes_t
*hw
= &priv
->hw
;
1211 len
= le16_to_cpu(desc
->data_len
);
1213 /* Determine the size of the header and the data */
1214 fc
= le16_to_cpu(desc
->frame_ctl
);
1215 switch (fc
& IEEE80211_FCTL_FTYPE
) {
1216 case IEEE80211_FTYPE_DATA
:
1217 if ((fc
& IEEE80211_FCTL_TODS
)
1218 && (fc
& IEEE80211_FCTL_FROMDS
))
1224 case IEEE80211_FTYPE_MGMT
:
1228 case IEEE80211_FTYPE_CTL
:
1229 switch (fc
& IEEE80211_FCTL_STYPE
) {
1230 case IEEE80211_STYPE_PSPOLL
:
1231 case IEEE80211_STYPE_RTS
:
1232 case IEEE80211_STYPE_CFEND
:
1233 case IEEE80211_STYPE_CFENDACK
:
1236 case IEEE80211_STYPE_CTS
:
1237 case IEEE80211_STYPE_ACK
:
1243 /* Unknown frame type */
1247 /* sanity check the length */
1248 if (datalen
> IEEE80211_DATA_LEN
+ 12) {
1249 printk(KERN_DEBUG
"%s: oversized monitor frame, "
1250 "data length = %d\n", dev
->name
, datalen
);
1251 stats
->rx_length_errors
++;
1255 skb
= dev_alloc_skb(hdrlen
+ datalen
);
1257 printk(KERN_WARNING
"%s: Cannot allocate skb for monitor frame\n",
1262 /* Copy the 802.11 header to the skb */
1263 memcpy(skb_put(skb
, hdrlen
), &(desc
->frame_ctl
), hdrlen
);
1264 skb_reset_mac_header(skb
);
1266 /* If any, copy the data from the card to the skb */
1268 err
= hermes_bap_pread(hw
, IRQ_BAP
, skb_put(skb
, datalen
),
1269 ALIGN(datalen
, 2), rxfid
,
1270 HERMES_802_2_OFFSET
);
1272 printk(KERN_ERR
"%s: error %d reading monitor frame\n",
1279 skb
->ip_summed
= CHECKSUM_NONE
;
1280 skb
->pkt_type
= PACKET_OTHERHOST
;
1281 skb
->protocol
= __constant_htons(ETH_P_802_2
);
1283 dev
->last_rx
= jiffies
;
1284 stats
->rx_packets
++;
1285 stats
->rx_bytes
+= skb
->len
;
1291 dev_kfree_skb_irq(skb
);
1294 stats
->rx_dropped
++;
1297 /* Get tsc from the firmware */
1298 static int orinoco_hw_get_tkip_iv(struct orinoco_private
*priv
, int key
,
1301 hermes_t
*hw
= &priv
->hw
;
1303 u8 tsc_arr
[4][IW_ENCODE_SEQ_MAX_SIZE
];
1305 if ((key
< 0) || (key
> 4))
1308 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENT_TKIP_IV
,
1309 sizeof(tsc_arr
), NULL
, &tsc_arr
);
1311 memcpy(tsc
, &tsc_arr
[key
][0], sizeof(tsc_arr
[0]));
1316 static void __orinoco_ev_rx(struct net_device
*dev
, hermes_t
*hw
)
1318 struct orinoco_private
*priv
= netdev_priv(dev
);
1319 struct net_device_stats
*stats
= &priv
->stats
;
1320 struct iw_statistics
*wstats
= &priv
->wstats
;
1321 struct sk_buff
*skb
= NULL
;
1324 struct hermes_rx_descriptor
*desc
;
1325 struct orinoco_rx_data
*rx_data
;
1328 desc
= kmalloc(sizeof(*desc
), GFP_ATOMIC
);
1331 "%s: Can't allocate space for RX descriptor\n",
1336 rxfid
= hermes_read_regn(hw
, RXFID
);
1338 err
= hermes_bap_pread(hw
, IRQ_BAP
, desc
, sizeof(*desc
),
1341 printk(KERN_ERR
"%s: error %d reading Rx descriptor. "
1342 "Frame dropped.\n", dev
->name
, err
);
1346 status
= le16_to_cpu(desc
->status
);
1348 if (status
& HERMES_RXSTAT_BADCRC
) {
1349 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
1351 stats
->rx_crc_errors
++;
1355 /* Handle frames in monitor mode */
1356 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
1357 orinoco_rx_monitor(dev
, rxfid
, desc
);
1361 if (status
& HERMES_RXSTAT_UNDECRYPTABLE
) {
1362 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1364 wstats
->discard
.code
++;
1368 length
= le16_to_cpu(desc
->data_len
);
1371 if (length
< 3) { /* No for even an 802.2 LLC header */
1372 /* At least on Symbol firmware with PCF we get quite a
1373 lot of these legitimately - Poll frames with no
1377 if (length
> IEEE80211_DATA_LEN
) {
1378 printk(KERN_WARNING
"%s: Oversized frame received (%d bytes)\n",
1380 stats
->rx_length_errors
++;
1384 /* Payload size does not include Michael MIC. Increase payload
1385 * size to read it together with the data. */
1386 if (status
& HERMES_RXSTAT_MIC
)
1387 length
+= MICHAEL_MIC_LEN
;
1389 /* We need space for the packet data itself, plus an ethernet
1390 header, plus 2 bytes so we can align the IP header on a
1391 32bit boundary, plus 1 byte so we can read in odd length
1392 packets from the card, which has an IO granularity of 16
1394 skb
= dev_alloc_skb(length
+ETH_HLEN
+2+1);
1396 printk(KERN_WARNING
"%s: Can't allocate skb for Rx\n",
1401 /* We'll prepend the header, so reserve space for it. The worst
1402 case is no decapsulation, when 802.3 header is prepended and
1403 nothing is removed. 2 is for aligning the IP header. */
1404 skb_reserve(skb
, ETH_HLEN
+ 2);
1406 err
= hermes_bap_pread(hw
, IRQ_BAP
, skb_put(skb
, length
),
1407 ALIGN(length
, 2), rxfid
,
1408 HERMES_802_2_OFFSET
);
1410 printk(KERN_ERR
"%s: error %d reading frame. "
1411 "Frame dropped.\n", dev
->name
, err
);
1415 /* Add desc and skb to rx queue */
1416 rx_data
= kzalloc(sizeof(*rx_data
), GFP_ATOMIC
);
1418 printk(KERN_WARNING
"%s: Can't allocate RX packet\n",
1422 rx_data
->desc
= desc
;
1424 list_add_tail(&rx_data
->list
, &priv
->rx_list
);
1425 tasklet_schedule(&priv
->rx_tasklet
);
1430 dev_kfree_skb_irq(skb
);
1433 stats
->rx_dropped
++;
1438 static void orinoco_rx(struct net_device
*dev
,
1439 struct hermes_rx_descriptor
*desc
,
1440 struct sk_buff
*skb
)
1442 struct orinoco_private
*priv
= netdev_priv(dev
);
1443 struct net_device_stats
*stats
= &priv
->stats
;
1448 status
= le16_to_cpu(desc
->status
);
1449 length
= le16_to_cpu(desc
->data_len
);
1450 fc
= le16_to_cpu(desc
->frame_ctl
);
1452 /* Calculate and check MIC */
1453 if (status
& HERMES_RXSTAT_MIC
) {
1454 int key_id
= ((status
& HERMES_RXSTAT_MIC_KEY_ID
) >>
1455 HERMES_MIC_KEY_ID_SHIFT
);
1456 u8 mic
[MICHAEL_MIC_LEN
];
1458 u8
*src
= (fc
& IEEE80211_FCTL_FROMDS
) ?
1459 desc
->addr3
: desc
->addr2
;
1461 /* Extract Michael MIC from payload */
1462 rxmic
= skb
->data
+ skb
->len
- MICHAEL_MIC_LEN
;
1464 skb_trim(skb
, skb
->len
- MICHAEL_MIC_LEN
);
1465 length
-= MICHAEL_MIC_LEN
;
1467 michael_mic(priv
->rx_tfm_mic
,
1468 priv
->tkip_key
[key_id
].rx_mic
,
1471 0, /* priority or QoS? */
1476 if (memcmp(mic
, rxmic
,
1478 union iwreq_data wrqu
;
1479 struct iw_michaelmicfailure wxmic
;
1480 DECLARE_MAC_BUF(mac
);
1482 printk(KERN_WARNING
"%s: "
1483 "Invalid Michael MIC in data frame from %s, "
1485 dev
->name
, print_mac(mac
, src
), key_id
);
1487 /* TODO: update stats */
1489 /* Notify userspace */
1490 memset(&wxmic
, 0, sizeof(wxmic
));
1491 wxmic
.flags
= key_id
& IW_MICFAILURE_KEY_ID
;
1492 wxmic
.flags
|= (desc
->addr1
[0] & 1) ?
1493 IW_MICFAILURE_GROUP
: IW_MICFAILURE_PAIRWISE
;
1494 wxmic
.src_addr
.sa_family
= ARPHRD_ETHER
;
1495 memcpy(wxmic
.src_addr
.sa_data
, src
, ETH_ALEN
);
1497 (void) orinoco_hw_get_tkip_iv(priv
, key_id
,
1500 memset(&wrqu
, 0, sizeof(wrqu
));
1501 wrqu
.data
.length
= sizeof(wxmic
);
1502 wireless_send_event(dev
, IWEVMICHAELMICFAILURE
, &wrqu
,
1509 /* Handle decapsulation
1510 * In most cases, the firmware tell us about SNAP frames.
1511 * For some reason, the SNAP frames sent by LinkSys APs
1512 * are not properly recognised by most firmwares.
1513 * So, check ourselves */
1514 if (length
>= ENCAPS_OVERHEAD
&&
1515 (((status
& HERMES_RXSTAT_MSGTYPE
) == HERMES_RXSTAT_1042
) ||
1516 ((status
& HERMES_RXSTAT_MSGTYPE
) == HERMES_RXSTAT_TUNNEL
) ||
1517 is_ethersnap(skb
->data
))) {
1518 /* These indicate a SNAP within 802.2 LLC within
1519 802.11 frame which we'll need to de-encapsulate to
1520 the original EthernetII frame. */
1521 hdr
= (struct ethhdr
*)skb_push(skb
, ETH_HLEN
- ENCAPS_OVERHEAD
);
1523 /* 802.3 frame - prepend 802.3 header as is */
1524 hdr
= (struct ethhdr
*)skb_push(skb
, ETH_HLEN
);
1525 hdr
->h_proto
= htons(length
);
1527 memcpy(hdr
->h_dest
, desc
->addr1
, ETH_ALEN
);
1528 if (fc
& IEEE80211_FCTL_FROMDS
)
1529 memcpy(hdr
->h_source
, desc
->addr3
, ETH_ALEN
);
1531 memcpy(hdr
->h_source
, desc
->addr2
, ETH_ALEN
);
1533 dev
->last_rx
= jiffies
;
1534 skb
->protocol
= eth_type_trans(skb
, dev
);
1535 skb
->ip_summed
= CHECKSUM_NONE
;
1536 if (fc
& IEEE80211_FCTL_TODS
)
1537 skb
->pkt_type
= PACKET_OTHERHOST
;
1539 /* Process the wireless stats if needed */
1540 orinoco_stat_gather(dev
, skb
, desc
);
1542 /* Pass the packet to the networking stack */
1544 stats
->rx_packets
++;
1545 stats
->rx_bytes
+= length
;
1552 stats
->rx_dropped
++;
1555 static void orinoco_rx_isr_tasklet(unsigned long data
)
1557 struct net_device
*dev
= (struct net_device
*) data
;
1558 struct orinoco_private
*priv
= netdev_priv(dev
);
1559 struct orinoco_rx_data
*rx_data
, *temp
;
1560 struct hermes_rx_descriptor
*desc
;
1561 struct sk_buff
*skb
;
1563 /* extract desc and skb from queue */
1564 list_for_each_entry_safe(rx_data
, temp
, &priv
->rx_list
, list
) {
1565 desc
= rx_data
->desc
;
1567 list_del(&rx_data
->list
);
1570 orinoco_rx(dev
, desc
, skb
);
1576 /********************************************************************/
1577 /* Rx path (info frames) */
1578 /********************************************************************/
1580 static void print_linkstatus(struct net_device
*dev
, u16 status
)
1584 if (suppress_linkstatus
)
1588 case HERMES_LINKSTATUS_NOT_CONNECTED
:
1589 s
= "Not Connected";
1591 case HERMES_LINKSTATUS_CONNECTED
:
1594 case HERMES_LINKSTATUS_DISCONNECTED
:
1597 case HERMES_LINKSTATUS_AP_CHANGE
:
1600 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE
:
1601 s
= "AP Out of Range";
1603 case HERMES_LINKSTATUS_AP_IN_RANGE
:
1606 case HERMES_LINKSTATUS_ASSOC_FAILED
:
1607 s
= "Association Failed";
1613 printk(KERN_INFO
"%s: New link status: %s (%04x)\n",
1614 dev
->name
, s
, status
);
1617 /* Search scan results for requested BSSID, join it if found */
1618 static void orinoco_join_ap(struct work_struct
*work
)
1620 struct orinoco_private
*priv
=
1621 container_of(work
, struct orinoco_private
, join_work
);
1622 struct net_device
*dev
= priv
->ndev
;
1623 struct hermes
*hw
= &priv
->hw
;
1625 unsigned long flags
;
1629 } __attribute__ ((packed
)) req
;
1630 const int atom_len
= offsetof(struct prism2_scan_apinfo
, atim
);
1631 struct prism2_scan_apinfo
*atom
= NULL
;
1637 /* Allocate buffer for scan results */
1638 buf
= kmalloc(MAX_SCAN_LEN
, GFP_KERNEL
);
1642 if (orinoco_lock(priv
, &flags
) != 0)
1645 /* Sanity checks in case user changed something in the meantime */
1646 if (! priv
->bssid_fixed
)
1649 if (strlen(priv
->desired_essid
) == 0)
1652 /* Read scan results from the firmware */
1653 err
= hermes_read_ltv(hw
, USER_BAP
,
1654 HERMES_RID_SCANRESULTSTABLE
,
1655 MAX_SCAN_LEN
, &len
, buf
);
1657 printk(KERN_ERR
"%s: Cannot read scan results\n",
1662 len
= HERMES_RECLEN_TO_BYTES(len
);
1664 /* Go through the scan results looking for the channel of the AP
1665 * we were requested to join */
1666 for (; offset
+ atom_len
<= len
; offset
+= atom_len
) {
1667 atom
= (struct prism2_scan_apinfo
*) (buf
+ offset
);
1668 if (memcmp(&atom
->bssid
, priv
->desired_bssid
, ETH_ALEN
) == 0) {
1675 DEBUG(1, "%s: Requested AP not found in scan results\n",
1680 memcpy(req
.bssid
, priv
->desired_bssid
, ETH_ALEN
);
1681 req
.channel
= atom
->channel
; /* both are little-endian */
1682 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
, HERMES_RID_CNFJOINREQUEST
,
1685 printk(KERN_ERR
"%s: Error issuing join request\n", dev
->name
);
1688 orinoco_unlock(priv
, &flags
);
1694 /* Send new BSSID to userspace */
1695 static void orinoco_send_bssid_wevent(struct orinoco_private
*priv
)
1697 struct net_device
*dev
= priv
->ndev
;
1698 struct hermes
*hw
= &priv
->hw
;
1699 union iwreq_data wrqu
;
1702 err
= hermes_read_ltv(hw
, IRQ_BAP
, HERMES_RID_CURRENTBSSID
,
1703 ETH_ALEN
, NULL
, wrqu
.ap_addr
.sa_data
);
1707 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1709 /* Send event to user space */
1710 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
1713 static void orinoco_send_assocreqie_wevent(struct orinoco_private
*priv
)
1715 struct net_device
*dev
= priv
->ndev
;
1716 struct hermes
*hw
= &priv
->hw
;
1717 union iwreq_data wrqu
;
1725 err
= hermes_read_ltv(hw
, IRQ_BAP
, HERMES_RID_CURRENT_ASSOC_REQ_INFO
,
1726 sizeof(buf
), NULL
, &buf
);
1730 ie
= orinoco_get_wpa_ie(buf
, sizeof(buf
));
1732 int rem
= sizeof(buf
) - (ie
- &buf
[0]);
1733 wrqu
.data
.length
= ie
[1] + 2;
1734 if (wrqu
.data
.length
> rem
)
1735 wrqu
.data
.length
= rem
;
1737 if (wrqu
.data
.length
)
1738 /* Send event to user space */
1739 wireless_send_event(dev
, IWEVASSOCREQIE
, &wrqu
, ie
);
1743 static void orinoco_send_assocrespie_wevent(struct orinoco_private
*priv
)
1745 struct net_device
*dev
= priv
->ndev
;
1746 struct hermes
*hw
= &priv
->hw
;
1747 union iwreq_data wrqu
;
1749 u8 buf
[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1755 err
= hermes_read_ltv(hw
, IRQ_BAP
, HERMES_RID_CURRENT_ASSOC_RESP_INFO
,
1756 sizeof(buf
), NULL
, &buf
);
1760 ie
= orinoco_get_wpa_ie(buf
, sizeof(buf
));
1762 int rem
= sizeof(buf
) - (ie
- &buf
[0]);
1763 wrqu
.data
.length
= ie
[1] + 2;
1764 if (wrqu
.data
.length
> rem
)
1765 wrqu
.data
.length
= rem
;
1767 if (wrqu
.data
.length
)
1768 /* Send event to user space */
1769 wireless_send_event(dev
, IWEVASSOCRESPIE
, &wrqu
, ie
);
1773 static void orinoco_send_wevents(struct work_struct
*work
)
1775 struct orinoco_private
*priv
=
1776 container_of(work
, struct orinoco_private
, wevent_work
);
1777 unsigned long flags
;
1779 if (orinoco_lock(priv
, &flags
) != 0)
1782 orinoco_send_assocreqie_wevent(priv
);
1783 orinoco_send_assocrespie_wevent(priv
);
1784 orinoco_send_bssid_wevent(priv
);
1786 orinoco_unlock(priv
, &flags
);
1789 static inline void orinoco_clear_scan_results(struct orinoco_private
*priv
,
1790 unsigned long scan_age
)
1792 if (priv
->has_ext_scan
) {
1793 struct xbss_element
*bss
;
1794 struct xbss_element
*tmp_bss
;
1796 /* Blow away current list of scan results */
1797 list_for_each_entry_safe(bss
, tmp_bss
, &priv
->bss_list
, list
) {
1799 time_after(jiffies
, bss
->last_scanned
+ scan_age
)) {
1800 list_move_tail(&bss
->list
,
1801 &priv
->bss_free_list
);
1802 /* Don't blow away ->list, just BSS data */
1803 memset(&bss
->bss
, 0, sizeof(bss
->bss
));
1804 bss
->last_scanned
= 0;
1808 struct bss_element
*bss
;
1809 struct bss_element
*tmp_bss
;
1811 /* Blow away current list of scan results */
1812 list_for_each_entry_safe(bss
, tmp_bss
, &priv
->bss_list
, list
) {
1814 time_after(jiffies
, bss
->last_scanned
+ scan_age
)) {
1815 list_move_tail(&bss
->list
,
1816 &priv
->bss_free_list
);
1817 /* Don't blow away ->list, just BSS data */
1818 memset(&bss
->bss
, 0, sizeof(bss
->bss
));
1819 bss
->last_scanned
= 0;
1825 static void orinoco_add_ext_scan_result(struct orinoco_private
*priv
,
1826 struct agere_ext_scan_info
*atom
)
1828 struct xbss_element
*bss
= NULL
;
1831 /* Try to update an existing bss first */
1832 list_for_each_entry(bss
, &priv
->bss_list
, list
) {
1833 if (compare_ether_addr(bss
->bss
.bssid
, atom
->bssid
))
1836 if (bss
->bss
.data
[1] != atom
->data
[1])
1838 if (memcmp(&bss
->bss
.data
[2], &atom
->data
[2],
1845 /* Grab a bss off the free list */
1846 if (!found
&& !list_empty(&priv
->bss_free_list
)) {
1847 bss
= list_entry(priv
->bss_free_list
.next
,
1848 struct xbss_element
, list
);
1849 list_del(priv
->bss_free_list
.next
);
1851 list_add_tail(&bss
->list
, &priv
->bss_list
);
1855 /* Always update the BSS to get latest beacon info */
1856 memcpy(&bss
->bss
, atom
, sizeof(bss
->bss
));
1857 bss
->last_scanned
= jiffies
;
1861 static int orinoco_process_scan_results(struct net_device
*dev
,
1865 struct orinoco_private
*priv
= netdev_priv(dev
);
1866 int offset
; /* In the scan data */
1867 union hermes_scan_info
*atom
;
1870 switch (priv
->firmware_type
) {
1871 case FIRMWARE_TYPE_AGERE
:
1872 atom_len
= sizeof(struct agere_scan_apinfo
);
1875 case FIRMWARE_TYPE_SYMBOL
:
1876 /* Lack of documentation necessitates this hack.
1877 * Different firmwares have 68 or 76 byte long atoms.
1878 * We try modulo first. If the length divides by both,
1879 * we check what would be the channel in the second
1880 * frame for a 68-byte atom. 76-byte atoms have 0 there.
1881 * Valid channel cannot be 0. */
1886 else if (len
>= 1292 && buf
[68] == 0)
1892 case FIRMWARE_TYPE_INTERSIL
:
1894 if (priv
->has_hostscan
) {
1895 atom_len
= le16_to_cpup((__le16
*)buf
);
1896 /* Sanity check for atom_len */
1897 if (atom_len
< sizeof(struct prism2_scan_apinfo
)) {
1898 printk(KERN_ERR
"%s: Invalid atom_len in scan "
1899 "data: %d\n", dev
->name
, atom_len
);
1903 atom_len
= offsetof(struct prism2_scan_apinfo
, atim
);
1909 /* Check that we got an whole number of atoms */
1910 if ((len
- offset
) % atom_len
) {
1911 printk(KERN_ERR
"%s: Unexpected scan data length %d, "
1912 "atom_len %d, offset %d\n", dev
->name
, len
,
1917 orinoco_clear_scan_results(priv
, msecs_to_jiffies(15000));
1919 /* Read the entries one by one */
1920 for (; offset
+ atom_len
<= len
; offset
+= atom_len
) {
1922 struct bss_element
*bss
= NULL
;
1925 atom
= (union hermes_scan_info
*) (buf
+ offset
);
1927 /* Try to update an existing bss first */
1928 list_for_each_entry(bss
, &priv
->bss_list
, list
) {
1929 if (compare_ether_addr(bss
->bss
.a
.bssid
, atom
->a
.bssid
))
1931 if (le16_to_cpu(bss
->bss
.a
.essid_len
) !=
1932 le16_to_cpu(atom
->a
.essid_len
))
1934 if (memcmp(bss
->bss
.a
.essid
, atom
->a
.essid
,
1935 le16_to_cpu(atom
->a
.essid_len
)))
1941 /* Grab a bss off the free list */
1942 if (!found
&& !list_empty(&priv
->bss_free_list
)) {
1943 bss
= list_entry(priv
->bss_free_list
.next
,
1944 struct bss_element
, list
);
1945 list_del(priv
->bss_free_list
.next
);
1947 list_add_tail(&bss
->list
, &priv
->bss_list
);
1951 /* Always update the BSS to get latest beacon info */
1952 memcpy(&bss
->bss
, atom
, sizeof(bss
->bss
));
1953 bss
->last_scanned
= jiffies
;
1960 static void __orinoco_ev_info(struct net_device
*dev
, hermes_t
*hw
)
1962 struct orinoco_private
*priv
= netdev_priv(dev
);
1967 } __attribute__ ((packed
)) info
;
1971 /* This is an answer to an INQUIRE command that we did earlier,
1972 * or an information "event" generated by the card
1973 * The controller return to us a pseudo frame containing
1974 * the information in question - Jean II */
1975 infofid
= hermes_read_regn(hw
, INFOFID
);
1977 /* Read the info frame header - don't try too hard */
1978 err
= hermes_bap_pread(hw
, IRQ_BAP
, &info
, sizeof(info
),
1981 printk(KERN_ERR
"%s: error %d reading info frame. "
1982 "Frame dropped.\n", dev
->name
, err
);
1986 len
= HERMES_RECLEN_TO_BYTES(le16_to_cpu(info
.len
));
1987 type
= le16_to_cpu(info
.type
);
1990 case HERMES_INQ_TALLIES
: {
1991 struct hermes_tallies_frame tallies
;
1992 struct iw_statistics
*wstats
= &priv
->wstats
;
1994 if (len
> sizeof(tallies
)) {
1995 printk(KERN_WARNING
"%s: Tallies frame too long (%d bytes)\n",
1997 len
= sizeof(tallies
);
2000 err
= hermes_bap_pread(hw
, IRQ_BAP
, &tallies
, len
,
2001 infofid
, sizeof(info
));
2005 /* Increment our various counters */
2006 /* wstats->discard.nwid - no wrong BSSID stuff */
2007 wstats
->discard
.code
+=
2008 le16_to_cpu(tallies
.RxWEPUndecryptable
);
2009 if (len
== sizeof(tallies
))
2010 wstats
->discard
.code
+=
2011 le16_to_cpu(tallies
.RxDiscards_WEPICVError
) +
2012 le16_to_cpu(tallies
.RxDiscards_WEPExcluded
);
2013 wstats
->discard
.misc
+=
2014 le16_to_cpu(tallies
.TxDiscardsWrongSA
);
2015 wstats
->discard
.fragment
+=
2016 le16_to_cpu(tallies
.RxMsgInBadMsgFragments
);
2017 wstats
->discard
.retries
+=
2018 le16_to_cpu(tallies
.TxRetryLimitExceeded
);
2019 /* wstats->miss.beacon - no match */
2022 case HERMES_INQ_LINKSTATUS
: {
2023 struct hermes_linkstatus linkstatus
;
2027 if (priv
->iw_mode
== IW_MODE_MONITOR
)
2030 if (len
!= sizeof(linkstatus
)) {
2031 printk(KERN_WARNING
"%s: Unexpected size for linkstatus frame (%d bytes)\n",
2036 err
= hermes_bap_pread(hw
, IRQ_BAP
, &linkstatus
, len
,
2037 infofid
, sizeof(info
));
2040 newstatus
= le16_to_cpu(linkstatus
.linkstatus
);
2042 /* Symbol firmware uses "out of range" to signal that
2043 * the hostscan frame can be requested. */
2044 if (newstatus
== HERMES_LINKSTATUS_AP_OUT_OF_RANGE
&&
2045 priv
->firmware_type
== FIRMWARE_TYPE_SYMBOL
&&
2046 priv
->has_hostscan
&& priv
->scan_inprogress
) {
2047 hermes_inquire(hw
, HERMES_INQ_HOSTSCAN_SYMBOL
);
2051 connected
= (newstatus
== HERMES_LINKSTATUS_CONNECTED
)
2052 || (newstatus
== HERMES_LINKSTATUS_AP_CHANGE
)
2053 || (newstatus
== HERMES_LINKSTATUS_AP_IN_RANGE
);
2056 netif_carrier_on(dev
);
2057 else if (!ignore_disconnect
)
2058 netif_carrier_off(dev
);
2060 if (newstatus
!= priv
->last_linkstatus
) {
2061 priv
->last_linkstatus
= newstatus
;
2062 print_linkstatus(dev
, newstatus
);
2063 /* The info frame contains only one word which is the
2064 * status (see hermes.h). The status is pretty boring
2065 * in itself, that's why we export the new BSSID...
2067 schedule_work(&priv
->wevent_work
);
2071 case HERMES_INQ_SCAN
:
2072 if (!priv
->scan_inprogress
&& priv
->bssid_fixed
&&
2073 priv
->firmware_type
== FIRMWARE_TYPE_INTERSIL
) {
2074 schedule_work(&priv
->join_work
);
2078 case HERMES_INQ_HOSTSCAN
:
2079 case HERMES_INQ_HOSTSCAN_SYMBOL
: {
2080 /* Result of a scanning. Contains information about
2081 * cells in the vicinity - Jean II */
2082 union iwreq_data wrqu
;
2085 /* Scan is no longer in progress */
2086 priv
->scan_inprogress
= 0;
2090 printk(KERN_WARNING
"%s: Scan results too large (%d bytes)\n",
2095 /* Allocate buffer for results */
2096 buf
= kmalloc(len
, GFP_ATOMIC
);
2098 /* No memory, so can't printk()... */
2101 /* Read scan data */
2102 err
= hermes_bap_pread(hw
, IRQ_BAP
, (void *) buf
, len
,
2103 infofid
, sizeof(info
));
2109 #ifdef ORINOCO_DEBUG
2112 printk(KERN_DEBUG
"Scan result [%02X", buf
[0]);
2113 for(i
= 1; i
< (len
* 2); i
++)
2114 printk(":%02X", buf
[i
]);
2117 #endif /* ORINOCO_DEBUG */
2119 if (orinoco_process_scan_results(dev
, buf
, len
) == 0) {
2120 /* Send an empty event to user space.
2121 * We don't send the received data on the event because
2122 * it would require us to do complex transcoding, and
2123 * we want to minimise the work done in the irq handler
2124 * Use a request to extract the data - Jean II */
2125 wrqu
.data
.length
= 0;
2126 wrqu
.data
.flags
= 0;
2127 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
2132 case HERMES_INQ_CHANNELINFO
:
2134 struct agere_ext_scan_info
*bss
;
2136 if (!priv
->scan_inprogress
) {
2137 printk(KERN_DEBUG
"%s: Got chaninfo without scan, "
2138 "len=%d\n", dev
->name
, len
);
2142 /* An empty result indicates that the scan is complete */
2144 union iwreq_data wrqu
;
2146 /* Scan is no longer in progress */
2147 priv
->scan_inprogress
= 0;
2149 wrqu
.data
.length
= 0;
2150 wrqu
.data
.flags
= 0;
2151 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
2156 else if (len
> sizeof(*bss
)) {
2158 "%s: Ext scan results too large (%d bytes). "
2159 "Truncating results to %zd bytes.\n",
2160 dev
->name
, len
, sizeof(*bss
));
2162 } else if (len
< (offsetof(struct agere_ext_scan_info
,
2164 /* Drop this result now so we don't have to
2165 * keep checking later */
2167 "%s: Ext scan results too short (%d bytes)\n",
2172 bss
= kmalloc(sizeof(*bss
), GFP_ATOMIC
);
2176 /* Read scan data */
2177 err
= hermes_bap_pread(hw
, IRQ_BAP
, (void *) bss
, len
,
2178 infofid
, sizeof(info
));
2184 orinoco_add_ext_scan_result(priv
, bss
);
2189 case HERMES_INQ_SEC_STAT_AGERE
:
2190 /* Security status (Agere specific) */
2191 /* Ignore this frame for now */
2192 if (priv
->firmware_type
== FIRMWARE_TYPE_AGERE
)
2196 printk(KERN_DEBUG
"%s: Unknown information frame received: "
2197 "type 0x%04x, length %d\n", dev
->name
, type
, len
);
2198 /* We don't actually do anything about it */
2203 static void __orinoco_ev_infdrop(struct net_device
*dev
, hermes_t
*hw
)
2205 if (net_ratelimit())
2206 printk(KERN_DEBUG
"%s: Information frame lost.\n", dev
->name
);
2209 /********************************************************************/
2210 /* Internal hardware control routines */
2211 /********************************************************************/
2213 int __orinoco_up(struct net_device
*dev
)
2215 struct orinoco_private
*priv
= netdev_priv(dev
);
2216 struct hermes
*hw
= &priv
->hw
;
2219 netif_carrier_off(dev
); /* just to make sure */
2221 err
= __orinoco_program_rids(dev
);
2223 printk(KERN_ERR
"%s: Error %d configuring card\n",
2228 /* Fire things up again */
2229 hermes_set_irqmask(hw
, ORINOCO_INTEN
);
2230 err
= hermes_enable_port(hw
, 0);
2232 printk(KERN_ERR
"%s: Error %d enabling MAC port\n",
2237 netif_start_queue(dev
);
2242 int __orinoco_down(struct net_device
*dev
)
2244 struct orinoco_private
*priv
= netdev_priv(dev
);
2245 struct hermes
*hw
= &priv
->hw
;
2248 netif_stop_queue(dev
);
2250 if (! priv
->hw_unavailable
) {
2251 if (! priv
->broken_disableport
) {
2252 err
= hermes_disable_port(hw
, 0);
2254 /* Some firmwares (e.g. Intersil 1.3.x) seem
2255 * to have problems disabling the port, oh
2257 printk(KERN_WARNING
"%s: Error %d disabling MAC port\n",
2259 priv
->broken_disableport
= 1;
2262 hermes_set_irqmask(hw
, 0);
2263 hermes_write_regn(hw
, EVACK
, 0xffff);
2266 /* firmware will have to reassociate */
2267 netif_carrier_off(dev
);
2268 priv
->last_linkstatus
= 0xffff;
2273 static int orinoco_allocate_fid(struct net_device
*dev
)
2275 struct orinoco_private
*priv
= netdev_priv(dev
);
2276 struct hermes
*hw
= &priv
->hw
;
2279 err
= hermes_allocate(hw
, priv
->nicbuf_size
, &priv
->txfid
);
2280 if (err
== -EIO
&& priv
->nicbuf_size
> TX_NICBUF_SIZE_BUG
) {
2281 /* Try workaround for old Symbol firmware bug */
2282 printk(KERN_WARNING
"%s: firmware ALLOC bug detected "
2283 "(old Symbol firmware?). Trying to work around... ",
2286 priv
->nicbuf_size
= TX_NICBUF_SIZE_BUG
;
2287 err
= hermes_allocate(hw
, priv
->nicbuf_size
, &priv
->txfid
);
2289 printk("failed!\n");
2297 int orinoco_reinit_firmware(struct net_device
*dev
)
2299 struct orinoco_private
*priv
= netdev_priv(dev
);
2300 struct hermes
*hw
= &priv
->hw
;
2303 err
= hermes_init(hw
);
2305 err
= orinoco_allocate_fid(dev
);
2310 static int __orinoco_hw_set_bitrate(struct orinoco_private
*priv
)
2312 hermes_t
*hw
= &priv
->hw
;
2315 if (priv
->bitratemode
>= BITRATE_TABLE_SIZE
) {
2316 printk(KERN_ERR
"%s: BUG: Invalid bitrate mode %d\n",
2317 priv
->ndev
->name
, priv
->bitratemode
);
2321 switch (priv
->firmware_type
) {
2322 case FIRMWARE_TYPE_AGERE
:
2323 err
= hermes_write_wordrec(hw
, USER_BAP
,
2324 HERMES_RID_CNFTXRATECONTROL
,
2325 bitrate_table
[priv
->bitratemode
].agere_txratectrl
);
2327 case FIRMWARE_TYPE_INTERSIL
:
2328 case FIRMWARE_TYPE_SYMBOL
:
2329 err
= hermes_write_wordrec(hw
, USER_BAP
,
2330 HERMES_RID_CNFTXRATECONTROL
,
2331 bitrate_table
[priv
->bitratemode
].intersil_txratectrl
);
2340 /* Set fixed AP address */
2341 static int __orinoco_hw_set_wap(struct orinoco_private
*priv
)
2345 hermes_t
*hw
= &priv
->hw
;
2347 switch (priv
->firmware_type
) {
2348 case FIRMWARE_TYPE_AGERE
:
2351 case FIRMWARE_TYPE_INTERSIL
:
2352 if (priv
->bssid_fixed
)
2357 err
= hermes_write_wordrec(hw
, USER_BAP
,
2358 HERMES_RID_CNFROAMINGMODE
,
2361 case FIRMWARE_TYPE_SYMBOL
:
2362 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
2363 HERMES_RID_CNFMANDATORYBSSID_SYMBOL
,
2364 &priv
->desired_bssid
);
2370 /* Change the WEP keys and/or the current keys. Can be called
2371 * either from __orinoco_hw_setup_enc() or directly from
2372 * orinoco_ioctl_setiwencode(). In the later case the association
2373 * with the AP is not broken (if the firmware can handle it),
2374 * which is needed for 802.1x implementations. */
2375 static int __orinoco_hw_setup_wepkeys(struct orinoco_private
*priv
)
2377 hermes_t
*hw
= &priv
->hw
;
2380 switch (priv
->firmware_type
) {
2381 case FIRMWARE_TYPE_AGERE
:
2382 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
2383 HERMES_RID_CNFWEPKEYS_AGERE
,
2387 err
= hermes_write_wordrec(hw
, USER_BAP
,
2388 HERMES_RID_CNFTXKEY_AGERE
,
2393 case FIRMWARE_TYPE_INTERSIL
:
2394 case FIRMWARE_TYPE_SYMBOL
:
2399 /* Force uniform key length to work around firmware bugs */
2400 keylen
= le16_to_cpu(priv
->keys
[priv
->tx_key
].len
);
2402 if (keylen
> LARGE_KEY_SIZE
) {
2403 printk(KERN_ERR
"%s: BUG: Key %d has oversize length %d.\n",
2404 priv
->ndev
->name
, priv
->tx_key
, keylen
);
2408 /* Write all 4 keys */
2409 for(i
= 0; i
< ORINOCO_MAX_KEYS
; i
++) {
2410 err
= hermes_write_ltv(hw
, USER_BAP
,
2411 HERMES_RID_CNFDEFAULTKEY0
+ i
,
2412 HERMES_BYTES_TO_RECLEN(keylen
),
2413 priv
->keys
[i
].data
);
2418 /* Write the index of the key used in transmission */
2419 err
= hermes_write_wordrec(hw
, USER_BAP
,
2420 HERMES_RID_CNFWEPDEFAULTKEYID
,
2431 static int __orinoco_hw_setup_enc(struct orinoco_private
*priv
)
2433 hermes_t
*hw
= &priv
->hw
;
2435 int master_wep_flag
;
2439 /* Setup WEP keys for WEP and WPA */
2440 if (priv
->encode_alg
)
2441 __orinoco_hw_setup_wepkeys(priv
);
2443 if (priv
->wep_restrict
)
2444 auth_flag
= HERMES_AUTH_SHARED_KEY
;
2446 auth_flag
= HERMES_AUTH_OPEN
;
2448 if (priv
->wpa_enabled
)
2450 else if (priv
->encode_alg
== IW_ENCODE_ALG_WEP
)
2455 switch (priv
->firmware_type
) {
2456 case FIRMWARE_TYPE_AGERE
: /* Agere style WEP */
2457 if (priv
->encode_alg
== IW_ENCODE_ALG_WEP
) {
2458 /* Enable the shared-key authentication. */
2459 err
= hermes_write_wordrec(hw
, USER_BAP
,
2460 HERMES_RID_CNFAUTHENTICATION_AGERE
,
2463 err
= hermes_write_wordrec(hw
, USER_BAP
,
2464 HERMES_RID_CNFWEPENABLED_AGERE
,
2469 if (priv
->has_wpa
) {
2470 /* Set WPA key management */
2471 err
= hermes_write_wordrec(hw
, USER_BAP
,
2472 HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE
,
2480 case FIRMWARE_TYPE_INTERSIL
: /* Intersil style WEP */
2481 case FIRMWARE_TYPE_SYMBOL
: /* Symbol style WEP */
2482 if (priv
->encode_alg
== IW_ENCODE_ALG_WEP
) {
2483 if (priv
->wep_restrict
||
2484 (priv
->firmware_type
== FIRMWARE_TYPE_SYMBOL
))
2485 master_wep_flag
= HERMES_WEP_PRIVACY_INVOKED
|
2486 HERMES_WEP_EXCL_UNENCRYPTED
;
2488 master_wep_flag
= HERMES_WEP_PRIVACY_INVOKED
;
2490 err
= hermes_write_wordrec(hw
, USER_BAP
,
2491 HERMES_RID_CNFAUTHENTICATION
,
2496 master_wep_flag
= 0;
2498 if (priv
->iw_mode
== IW_MODE_MONITOR
)
2499 master_wep_flag
|= HERMES_WEP_HOST_DECRYPT
;
2501 /* Master WEP setting : on/off */
2502 err
= hermes_write_wordrec(hw
, USER_BAP
,
2503 HERMES_RID_CNFWEPFLAGS_INTERSIL
,
2514 /* key must be 32 bytes, including the tx and rx MIC keys.
2515 * rsc must be 8 bytes
2516 * tsc must be 8 bytes or NULL
2518 static int __orinoco_hw_set_tkip_key(hermes_t
*hw
, int key_idx
, int set_tx
,
2519 u8
*key
, u8
*rsc
, u8
*tsc
)
2523 u8 rsc
[IW_ENCODE_SEQ_MAX_SIZE
];
2524 u8 key
[TKIP_KEYLEN
];
2525 u8 tx_mic
[MIC_KEYLEN
];
2526 u8 rx_mic
[MIC_KEYLEN
];
2527 u8 tsc
[IW_ENCODE_SEQ_MAX_SIZE
];
2528 } __attribute__ ((packed
)) buf
;
2539 buf
.idx
= cpu_to_le16(key_idx
);
2540 memcpy(buf
.key
, key
,
2541 sizeof(buf
.key
) + sizeof(buf
.tx_mic
) + sizeof(buf
.rx_mic
));
2544 memset(buf
.rsc
, 0, sizeof(buf
.rsc
));
2546 memcpy(buf
.rsc
, rsc
, sizeof(buf
.rsc
));
2549 memset(buf
.tsc
, 0, sizeof(buf
.tsc
));
2552 memcpy(buf
.tsc
, tsc
, sizeof(buf
.tsc
));
2555 /* Wait upto 100ms for tx queue to empty */
2560 ret
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_TXQUEUEEMPTY
,
2564 } while ((k
> 0) && xmitting
);
2569 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
2570 HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE
,
2573 return ret
? ret
: err
;
2576 static int orinoco_clear_tkip_key(struct orinoco_private
*priv
,
2579 hermes_t
*hw
= &priv
->hw
;
2582 memset(&priv
->tkip_key
[key_idx
], 0, sizeof(priv
->tkip_key
[key_idx
]));
2583 err
= hermes_write_wordrec(hw
, USER_BAP
,
2584 HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE
,
2587 printk(KERN_WARNING
"%s: Error %d clearing TKIP key %d\n",
2588 priv
->ndev
->name
, err
, key_idx
);
2592 static int __orinoco_program_rids(struct net_device
*dev
)
2594 struct orinoco_private
*priv
= netdev_priv(dev
);
2595 hermes_t
*hw
= &priv
->hw
;
2597 struct hermes_idstring idbuf
;
2599 /* Set the MAC address */
2600 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNMACADDR
,
2601 HERMES_BYTES_TO_RECLEN(ETH_ALEN
), dev
->dev_addr
);
2603 printk(KERN_ERR
"%s: Error %d setting MAC address\n",
2608 /* Set up the link mode */
2609 err
= hermes_write_wordrec(hw
, USER_BAP
, HERMES_RID_CNFPORTTYPE
,
2612 printk(KERN_ERR
"%s: Error %d setting port type\n",
2616 /* Set the channel/frequency */
2617 if (priv
->channel
!= 0 && priv
->iw_mode
!= IW_MODE_INFRA
) {
2618 err
= hermes_write_wordrec(hw
, USER_BAP
,
2619 HERMES_RID_CNFOWNCHANNEL
,
2622 printk(KERN_ERR
"%s: Error %d setting channel %d\n",
2623 dev
->name
, err
, priv
->channel
);
2628 if (priv
->has_ibss
) {
2631 if ((strlen(priv
->desired_essid
) == 0) && (priv
->createibss
)) {
2632 printk(KERN_WARNING
"%s: This firmware requires an "
2633 "ESSID in IBSS-Ad-Hoc mode.\n", dev
->name
);
2634 /* With wvlan_cs, in this case, we would crash.
2635 * hopefully, this driver will behave better...
2639 createibss
= priv
->createibss
;
2642 err
= hermes_write_wordrec(hw
, USER_BAP
,
2643 HERMES_RID_CNFCREATEIBSS
,
2646 printk(KERN_ERR
"%s: Error %d setting CREATEIBSS\n",
2652 /* Set the desired BSSID */
2653 err
= __orinoco_hw_set_wap(priv
);
2655 printk(KERN_ERR
"%s: Error %d setting AP address\n",
2659 /* Set the desired ESSID */
2660 idbuf
.len
= cpu_to_le16(strlen(priv
->desired_essid
));
2661 memcpy(&idbuf
.val
, priv
->desired_essid
, sizeof(idbuf
.val
));
2662 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
2663 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNSSID
,
2664 HERMES_BYTES_TO_RECLEN(strlen(priv
->desired_essid
)+2),
2667 printk(KERN_ERR
"%s: Error %d setting OWNSSID\n",
2671 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFDESIREDSSID
,
2672 HERMES_BYTES_TO_RECLEN(strlen(priv
->desired_essid
)+2),
2675 printk(KERN_ERR
"%s: Error %d setting DESIREDSSID\n",
2680 /* Set the station name */
2681 idbuf
.len
= cpu_to_le16(strlen(priv
->nick
));
2682 memcpy(&idbuf
.val
, priv
->nick
, sizeof(idbuf
.val
));
2683 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNNAME
,
2684 HERMES_BYTES_TO_RECLEN(strlen(priv
->nick
)+2),
2687 printk(KERN_ERR
"%s: Error %d setting nickname\n",
2692 /* Set AP density */
2693 if (priv
->has_sensitivity
) {
2694 err
= hermes_write_wordrec(hw
, USER_BAP
,
2695 HERMES_RID_CNFSYSTEMSCALE
,
2698 printk(KERN_WARNING
"%s: Error %d setting SYSTEMSCALE. "
2699 "Disabling sensitivity control\n",
2702 priv
->has_sensitivity
= 0;
2706 /* Set RTS threshold */
2707 err
= hermes_write_wordrec(hw
, USER_BAP
, HERMES_RID_CNFRTSTHRESHOLD
,
2710 printk(KERN_ERR
"%s: Error %d setting RTS threshold\n",
2715 /* Set fragmentation threshold or MWO robustness */
2717 err
= hermes_write_wordrec(hw
, USER_BAP
,
2718 HERMES_RID_CNFMWOROBUST_AGERE
,
2721 err
= hermes_write_wordrec(hw
, USER_BAP
,
2722 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
2725 printk(KERN_ERR
"%s: Error %d setting fragmentation\n",
2731 err
= __orinoco_hw_set_bitrate(priv
);
2733 printk(KERN_ERR
"%s: Error %d setting bitrate\n",
2738 /* Set power management */
2740 err
= hermes_write_wordrec(hw
, USER_BAP
,
2741 HERMES_RID_CNFPMENABLED
,
2744 printk(KERN_ERR
"%s: Error %d setting up PM\n",
2749 err
= hermes_write_wordrec(hw
, USER_BAP
,
2750 HERMES_RID_CNFMULTICASTRECEIVE
,
2753 printk(KERN_ERR
"%s: Error %d setting up PM\n",
2757 err
= hermes_write_wordrec(hw
, USER_BAP
,
2758 HERMES_RID_CNFMAXSLEEPDURATION
,
2761 printk(KERN_ERR
"%s: Error %d setting up PM\n",
2765 err
= hermes_write_wordrec(hw
, USER_BAP
,
2766 HERMES_RID_CNFPMHOLDOVERDURATION
,
2769 printk(KERN_ERR
"%s: Error %d setting up PM\n",
2775 /* Set preamble - only for Symbol so far... */
2776 if (priv
->has_preamble
) {
2777 err
= hermes_write_wordrec(hw
, USER_BAP
,
2778 HERMES_RID_CNFPREAMBLE_SYMBOL
,
2781 printk(KERN_ERR
"%s: Error %d setting preamble\n",
2787 /* Set up encryption */
2788 if (priv
->has_wep
|| priv
->has_wpa
) {
2789 err
= __orinoco_hw_setup_enc(priv
);
2791 printk(KERN_ERR
"%s: Error %d activating encryption\n",
2797 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
2798 /* Enable monitor mode */
2799 dev
->type
= ARPHRD_IEEE80211
;
2800 err
= hermes_docmd_wait(hw
, HERMES_CMD_TEST
|
2801 HERMES_TEST_MONITOR
, 0, NULL
);
2803 /* Disable monitor mode */
2804 dev
->type
= ARPHRD_ETHER
;
2805 err
= hermes_docmd_wait(hw
, HERMES_CMD_TEST
|
2806 HERMES_TEST_STOP
, 0, NULL
);
2811 /* Set promiscuity / multicast*/
2812 priv
->promiscuous
= 0;
2815 /* FIXME: what about netif_tx_lock */
2816 __orinoco_set_multicast_list(dev
);
2821 /* FIXME: return int? */
2823 __orinoco_set_multicast_list(struct net_device
*dev
)
2825 struct orinoco_private
*priv
= netdev_priv(dev
);
2826 hermes_t
*hw
= &priv
->hw
;
2828 int promisc
, mc_count
;
2830 /* The Hermes doesn't seem to have an allmulti mode, so we go
2831 * into promiscuous mode and let the upper levels deal. */
2832 if ( (dev
->flags
& IFF_PROMISC
) || (dev
->flags
& IFF_ALLMULTI
) ||
2833 (dev
->mc_count
> MAX_MULTICAST(priv
)) ) {
2838 mc_count
= dev
->mc_count
;
2841 if (promisc
!= priv
->promiscuous
) {
2842 err
= hermes_write_wordrec(hw
, USER_BAP
,
2843 HERMES_RID_CNFPROMISCUOUSMODE
,
2846 printk(KERN_ERR
"%s: Error %d setting PROMISCUOUSMODE to 1.\n",
2849 priv
->promiscuous
= promisc
;
2852 /* If we're not in promiscuous mode, then we need to set the
2853 * group address if either we want to multicast, or if we were
2854 * multicasting and want to stop */
2855 if (! promisc
&& (mc_count
|| priv
->mc_count
) ) {
2856 struct dev_mc_list
*p
= dev
->mc_list
;
2857 struct hermes_multicast mclist
;
2860 for (i
= 0; i
< mc_count
; i
++) {
2861 /* paranoia: is list shorter than mc_count? */
2863 /* paranoia: bad address size in list? */
2864 BUG_ON(p
->dmi_addrlen
!= ETH_ALEN
);
2866 memcpy(mclist
.addr
[i
], p
->dmi_addr
, ETH_ALEN
);
2871 printk(KERN_WARNING
"%s: Multicast list is "
2872 "longer than mc_count\n", dev
->name
);
2874 err
= hermes_write_ltv(hw
, USER_BAP
,
2875 HERMES_RID_CNFGROUPADDRESSES
,
2876 HERMES_BYTES_TO_RECLEN(mc_count
* ETH_ALEN
),
2879 printk(KERN_ERR
"%s: Error %d setting multicast list.\n",
2882 priv
->mc_count
= mc_count
;
2886 /* This must be called from user context, without locks held - use
2887 * schedule_work() */
2888 static void orinoco_reset(struct work_struct
*work
)
2890 struct orinoco_private
*priv
=
2891 container_of(work
, struct orinoco_private
, reset_work
);
2892 struct net_device
*dev
= priv
->ndev
;
2893 struct hermes
*hw
= &priv
->hw
;
2895 unsigned long flags
;
2897 if (orinoco_lock(priv
, &flags
) != 0)
2898 /* When the hardware becomes available again, whatever
2899 * detects that is responsible for re-initializing
2900 * it. So no need for anything further */
2903 netif_stop_queue(dev
);
2905 /* Shut off interrupts. Depending on what state the hardware
2906 * is in, this might not work, but we'll try anyway */
2907 hermes_set_irqmask(hw
, 0);
2908 hermes_write_regn(hw
, EVACK
, 0xffff);
2910 priv
->hw_unavailable
++;
2911 priv
->last_linkstatus
= 0xffff; /* firmware will have to reassociate */
2912 netif_carrier_off(dev
);
2914 orinoco_unlock(priv
, &flags
);
2916 /* Scanning support: Cleanup of driver struct */
2917 orinoco_clear_scan_results(priv
, 0);
2918 priv
->scan_inprogress
= 0;
2920 if (priv
->hard_reset
) {
2921 err
= (*priv
->hard_reset
)(priv
);
2923 printk(KERN_ERR
"%s: orinoco_reset: Error %d "
2924 "performing hard reset\n", dev
->name
, err
);
2929 if (priv
->do_fw_download
) {
2930 err
= orinoco_download(priv
);
2932 priv
->do_fw_download
= 0;
2935 err
= orinoco_reinit_firmware(dev
);
2937 printk(KERN_ERR
"%s: orinoco_reset: Error %d re-initializing firmware\n",
2942 spin_lock_irq(&priv
->lock
); /* This has to be called from user context */
2944 priv
->hw_unavailable
--;
2946 /* priv->open or priv->hw_unavailable might have changed while
2947 * we dropped the lock */
2948 if (priv
->open
&& (! priv
->hw_unavailable
)) {
2949 err
= __orinoco_up(dev
);
2951 printk(KERN_ERR
"%s: orinoco_reset: Error %d reenabling card\n",
2954 dev
->trans_start
= jiffies
;
2957 spin_unlock_irq(&priv
->lock
);
2961 hermes_set_irqmask(hw
, 0);
2962 netif_device_detach(dev
);
2963 printk(KERN_ERR
"%s: Device has been disabled!\n", dev
->name
);
2966 /********************************************************************/
2967 /* Interrupt handler */
2968 /********************************************************************/
2970 static void __orinoco_ev_tick(struct net_device
*dev
, hermes_t
*hw
)
2972 printk(KERN_DEBUG
"%s: TICK\n", dev
->name
);
2975 static void __orinoco_ev_wterr(struct net_device
*dev
, hermes_t
*hw
)
2977 /* This seems to happen a fair bit under load, but ignoring it
2978 seems to work fine...*/
2979 printk(KERN_DEBUG
"%s: MAC controller error (WTERR). Ignoring.\n",
2983 irqreturn_t
orinoco_interrupt(int irq
, void *dev_id
)
2985 struct net_device
*dev
= dev_id
;
2986 struct orinoco_private
*priv
= netdev_priv(dev
);
2987 hermes_t
*hw
= &priv
->hw
;
2988 int count
= MAX_IRQLOOPS_PER_IRQ
;
2990 /* These are used to detect a runaway interrupt situation */
2991 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2992 * we panic and shut down the hardware */
2993 static int last_irq_jiffy
= 0; /* jiffies value the last time
2995 static int loops_this_jiffy
= 0;
2996 unsigned long flags
;
2998 if (orinoco_lock(priv
, &flags
) != 0) {
2999 /* If hw is unavailable - we don't know if the irq was
3004 evstat
= hermes_read_regn(hw
, EVSTAT
);
3005 events
= evstat
& hw
->inten
;
3007 orinoco_unlock(priv
, &flags
);
3011 if (jiffies
!= last_irq_jiffy
)
3012 loops_this_jiffy
= 0;
3013 last_irq_jiffy
= jiffies
;
3015 while (events
&& count
--) {
3016 if (++loops_this_jiffy
> MAX_IRQLOOPS_PER_JIFFY
) {
3017 printk(KERN_WARNING
"%s: IRQ handler is looping too "
3018 "much! Resetting.\n", dev
->name
);
3019 /* Disable interrupts for now */
3020 hermes_set_irqmask(hw
, 0);
3021 schedule_work(&priv
->reset_work
);
3025 /* Check the card hasn't been removed */
3026 if (! hermes_present(hw
)) {
3027 DEBUG(0, "orinoco_interrupt(): card removed\n");
3031 if (events
& HERMES_EV_TICK
)
3032 __orinoco_ev_tick(dev
, hw
);
3033 if (events
& HERMES_EV_WTERR
)
3034 __orinoco_ev_wterr(dev
, hw
);
3035 if (events
& HERMES_EV_INFDROP
)
3036 __orinoco_ev_infdrop(dev
, hw
);
3037 if (events
& HERMES_EV_INFO
)
3038 __orinoco_ev_info(dev
, hw
);
3039 if (events
& HERMES_EV_RX
)
3040 __orinoco_ev_rx(dev
, hw
);
3041 if (events
& HERMES_EV_TXEXC
)
3042 __orinoco_ev_txexc(dev
, hw
);
3043 if (events
& HERMES_EV_TX
)
3044 __orinoco_ev_tx(dev
, hw
);
3045 if (events
& HERMES_EV_ALLOC
)
3046 __orinoco_ev_alloc(dev
, hw
);
3048 hermes_write_regn(hw
, EVACK
, evstat
);
3050 evstat
= hermes_read_regn(hw
, EVSTAT
);
3051 events
= evstat
& hw
->inten
;
3054 orinoco_unlock(priv
, &flags
);
3058 /********************************************************************/
3059 /* Initialization */
3060 /********************************************************************/
3063 u16 id
, variant
, major
, minor
;
3064 } __attribute__ ((packed
));
3066 static inline fwtype_t
determine_firmware_type(struct comp_id
*nic_id
)
3068 if (nic_id
->id
< 0x8000)
3069 return FIRMWARE_TYPE_AGERE
;
3070 else if (nic_id
->id
== 0x8000 && nic_id
->major
== 0)
3071 return FIRMWARE_TYPE_SYMBOL
;
3073 return FIRMWARE_TYPE_INTERSIL
;
3076 /* Set priv->firmware type, determine firmware properties */
3077 static int determine_firmware(struct net_device
*dev
)
3079 struct orinoco_private
*priv
= netdev_priv(dev
);
3080 hermes_t
*hw
= &priv
->hw
;
3082 struct comp_id nic_id
, sta_id
;
3083 unsigned int firmver
;
3084 char tmp
[SYMBOL_MAX_VER_LEN
+1] __attribute__((aligned(2)));
3086 /* Get the hardware version */
3087 err
= HERMES_READ_RECORD(hw
, USER_BAP
, HERMES_RID_NICID
, &nic_id
);
3089 printk(KERN_ERR
"%s: Cannot read hardware identity: error %d\n",
3094 le16_to_cpus(&nic_id
.id
);
3095 le16_to_cpus(&nic_id
.variant
);
3096 le16_to_cpus(&nic_id
.major
);
3097 le16_to_cpus(&nic_id
.minor
);
3098 printk(KERN_DEBUG
"%s: Hardware identity %04x:%04x:%04x:%04x\n",
3099 dev
->name
, nic_id
.id
, nic_id
.variant
,
3100 nic_id
.major
, nic_id
.minor
);
3102 priv
->firmware_type
= determine_firmware_type(&nic_id
);
3104 /* Get the firmware version */
3105 err
= HERMES_READ_RECORD(hw
, USER_BAP
, HERMES_RID_STAID
, &sta_id
);
3107 printk(KERN_ERR
"%s: Cannot read station identity: error %d\n",
3112 le16_to_cpus(&sta_id
.id
);
3113 le16_to_cpus(&sta_id
.variant
);
3114 le16_to_cpus(&sta_id
.major
);
3115 le16_to_cpus(&sta_id
.minor
);
3116 printk(KERN_DEBUG
"%s: Station identity %04x:%04x:%04x:%04x\n",
3117 dev
->name
, sta_id
.id
, sta_id
.variant
,
3118 sta_id
.major
, sta_id
.minor
);
3120 switch (sta_id
.id
) {
3122 printk(KERN_ERR
"%s: Primary firmware is active\n",
3126 printk(KERN_ERR
"%s: Tertiary firmware is active\n",
3129 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
3130 case 0x21: /* Symbol Spectrum24 Trilogy */
3133 printk(KERN_NOTICE
"%s: Unknown station ID, please report\n",
3138 /* Default capabilities */
3139 priv
->has_sensitivity
= 1;
3141 priv
->has_preamble
= 0;
3142 priv
->has_port3
= 1;
3145 priv
->has_big_wep
= 0;
3146 priv
->has_alt_txcntl
= 0;
3147 priv
->has_ext_scan
= 0;
3149 priv
->do_fw_download
= 0;
3151 /* Determine capabilities from the firmware version */
3152 switch (priv
->firmware_type
) {
3153 case FIRMWARE_TYPE_AGERE
:
3154 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
3155 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
3156 snprintf(priv
->fw_name
, sizeof(priv
->fw_name
) - 1,
3157 "Lucent/Agere %d.%02d", sta_id
.major
, sta_id
.minor
);
3159 firmver
= ((unsigned long)sta_id
.major
<< 16) | sta_id
.minor
;
3161 priv
->has_ibss
= (firmver
>= 0x60006);
3162 priv
->has_wep
= (firmver
>= 0x40020);
3163 priv
->has_big_wep
= 1; /* FIXME: this is wrong - how do we tell
3164 Gold cards from the others? */
3165 priv
->has_mwo
= (firmver
>= 0x60000);
3166 priv
->has_pm
= (firmver
>= 0x40020); /* Don't work in 7.52 ? */
3167 priv
->ibss_port
= 1;
3168 priv
->has_hostscan
= (firmver
>= 0x8000a);
3169 priv
->do_fw_download
= 1;
3170 priv
->broken_monitor
= (firmver
>= 0x80000);
3171 priv
->has_alt_txcntl
= (firmver
>= 0x90000); /* All 9.x ? */
3172 priv
->has_ext_scan
= (firmver
>= 0x90000); /* All 9.x ? */
3173 priv
->has_wpa
= (firmver
>= 0x9002a);
3174 /* Tested with Agere firmware :
3175 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
3176 * Tested CableTron firmware : 4.32 => Anton */
3178 case FIRMWARE_TYPE_SYMBOL
:
3179 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
3180 /* Intel MAC : 00:02:B3:* */
3181 /* 3Com MAC : 00:50:DA:* */
3182 memset(tmp
, 0, sizeof(tmp
));
3183 /* Get the Symbol firmware version */
3184 err
= hermes_read_ltv(hw
, USER_BAP
,
3185 HERMES_RID_SECONDARYVERSION_SYMBOL
,
3186 SYMBOL_MAX_VER_LEN
, NULL
, &tmp
);
3189 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
3194 /* The firmware revision is a string, the format is
3195 * something like : "V2.20-01".
3196 * Quick and dirty parsing... - Jean II
3198 firmver
= ((tmp
[1] - '0') << 16) | ((tmp
[3] - '0') << 12)
3199 | ((tmp
[4] - '0') << 8) | ((tmp
[6] - '0') << 4)
3202 tmp
[SYMBOL_MAX_VER_LEN
] = '\0';
3205 snprintf(priv
->fw_name
, sizeof(priv
->fw_name
) - 1,
3208 priv
->has_ibss
= (firmver
>= 0x20000);
3209 priv
->has_wep
= (firmver
>= 0x15012);
3210 priv
->has_big_wep
= (firmver
>= 0x20000);
3211 priv
->has_pm
= (firmver
>= 0x20000 && firmver
< 0x22000) ||
3212 (firmver
>= 0x29000 && firmver
< 0x30000) ||
3214 priv
->has_preamble
= (firmver
>= 0x20000);
3215 priv
->ibss_port
= 4;
3217 /* Symbol firmware is found on various cards, but
3218 * there has been no attempt to check firmware
3219 * download on non-spectrum_cs based cards.
3221 * Given that the Agere firmware download works
3222 * differently, we should avoid doing a firmware
3223 * download with the Symbol algorithm on non-spectrum
3226 * For now we can identify a spectrum_cs based card
3227 * because it has a firmware reset function.
3229 priv
->do_fw_download
= (priv
->stop_fw
!= NULL
);
3231 priv
->broken_disableport
= (firmver
== 0x25013) ||
3232 (firmver
>= 0x30000 && firmver
<= 0x31000);
3233 priv
->has_hostscan
= (firmver
>= 0x31001) ||
3234 (firmver
>= 0x29057 && firmver
< 0x30000);
3235 /* Tested with Intel firmware : 0x20015 => Jean II */
3236 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
3238 case FIRMWARE_TYPE_INTERSIL
:
3239 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
3240 * Samsung, Compaq 100/200 and Proxim are slightly
3241 * different and less well tested */
3242 /* D-Link MAC : 00:40:05:* */
3243 /* Addtron MAC : 00:90:D1:* */
3244 snprintf(priv
->fw_name
, sizeof(priv
->fw_name
) - 1,
3245 "Intersil %d.%d.%d", sta_id
.major
, sta_id
.minor
,
3248 firmver
= ((unsigned long)sta_id
.major
<< 16) |
3249 ((unsigned long)sta_id
.minor
<< 8) | sta_id
.variant
;
3251 priv
->has_ibss
= (firmver
>= 0x000700); /* FIXME */
3252 priv
->has_big_wep
= priv
->has_wep
= (firmver
>= 0x000800);
3253 priv
->has_pm
= (firmver
>= 0x000700);
3254 priv
->has_hostscan
= (firmver
>= 0x010301);
3256 if (firmver
>= 0x000800)
3257 priv
->ibss_port
= 0;
3259 printk(KERN_NOTICE
"%s: Intersil firmware earlier "
3260 "than v0.8.x - several features not supported\n",
3262 priv
->ibss_port
= 1;
3266 printk(KERN_DEBUG
"%s: Firmware determined as %s\n", dev
->name
,
3272 static int orinoco_init(struct net_device
*dev
)
3274 struct orinoco_private
*priv
= netdev_priv(dev
);
3275 hermes_t
*hw
= &priv
->hw
;
3277 struct hermes_idstring nickbuf
;
3280 DECLARE_MAC_BUF(mac
);
3282 /* No need to lock, the hw_unavailable flag is already set in
3283 * alloc_orinocodev() */
3284 priv
->nicbuf_size
= IEEE80211_FRAME_LEN
+ ETH_HLEN
;
3286 /* Initialize the firmware */
3287 err
= hermes_init(hw
);
3289 printk(KERN_ERR
"%s: failed to initialize firmware (err = %d)\n",
3294 err
= determine_firmware(dev
);
3296 printk(KERN_ERR
"%s: Incompatible firmware, aborting\n",
3301 if (priv
->do_fw_download
) {
3302 err
= orinoco_download(priv
);
3304 priv
->do_fw_download
= 0;
3306 /* Check firmware version again */
3307 err
= determine_firmware(dev
);
3309 printk(KERN_ERR
"%s: Incompatible firmware, aborting\n",
3315 if (priv
->has_port3
)
3316 printk(KERN_DEBUG
"%s: Ad-hoc demo mode supported\n", dev
->name
);
3318 printk(KERN_DEBUG
"%s: IEEE standard IBSS ad-hoc mode supported\n",
3320 if (priv
->has_wep
) {
3321 printk(KERN_DEBUG
"%s: WEP supported, ", dev
->name
);
3322 if (priv
->has_big_wep
)
3323 printk("104-bit key\n");
3325 printk("40-bit key\n");
3327 if (priv
->has_wpa
) {
3328 printk(KERN_DEBUG
"%s: WPA-PSK supported\n", dev
->name
);
3329 if (orinoco_mic_init(priv
)) {
3330 printk(KERN_ERR
"%s: Failed to setup MIC crypto "
3331 "algorithm. Disabling WPA support\n", dev
->name
);
3336 /* Now we have the firmware capabilities, allocate appropiate
3337 * sized scan buffers */
3338 if (orinoco_bss_data_allocate(priv
))
3340 orinoco_bss_data_init(priv
);
3342 /* Get the MAC address */
3343 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNMACADDR
,
3344 ETH_ALEN
, NULL
, dev
->dev_addr
);
3346 printk(KERN_WARNING
"%s: failed to read MAC address!\n",
3351 printk(KERN_DEBUG
"%s: MAC address %s\n",
3352 dev
->name
, print_mac(mac
, dev
->dev_addr
));
3354 /* Get the station name */
3355 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNNAME
,
3356 sizeof(nickbuf
), &reclen
, &nickbuf
);
3358 printk(KERN_ERR
"%s: failed to read station name\n",
3363 len
= min(IW_ESSID_MAX_SIZE
, (int)le16_to_cpu(nickbuf
.len
));
3365 len
= min(IW_ESSID_MAX_SIZE
, 2 * reclen
);
3366 memcpy(priv
->nick
, &nickbuf
.val
, len
);
3367 priv
->nick
[len
] = '\0';
3369 printk(KERN_DEBUG
"%s: Station name \"%s\"\n", dev
->name
, priv
->nick
);
3371 err
= orinoco_allocate_fid(dev
);
3373 printk(KERN_ERR
"%s: failed to allocate NIC buffer!\n",
3378 /* Get allowed channels */
3379 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CHANNELLIST
,
3380 &priv
->channel_mask
);
3382 printk(KERN_ERR
"%s: failed to read channel list!\n",
3387 /* Get initial AP density */
3388 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFSYSTEMSCALE
,
3390 if (err
|| priv
->ap_density
< 1 || priv
->ap_density
> 3) {
3391 priv
->has_sensitivity
= 0;
3394 /* Get initial RTS threshold */
3395 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFRTSTHRESHOLD
,
3398 printk(KERN_ERR
"%s: failed to read RTS threshold!\n",
3403 /* Get initial fragmentation settings */
3405 err
= hermes_read_wordrec(hw
, USER_BAP
,
3406 HERMES_RID_CNFMWOROBUST_AGERE
,
3409 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
3410 &priv
->frag_thresh
);
3412 printk(KERN_ERR
"%s: failed to read fragmentation settings!\n",
3417 /* Power management setup */
3421 err
= hermes_read_wordrec(hw
, USER_BAP
,
3422 HERMES_RID_CNFMAXSLEEPDURATION
,
3425 printk(KERN_ERR
"%s: failed to read power management period!\n",
3429 err
= hermes_read_wordrec(hw
, USER_BAP
,
3430 HERMES_RID_CNFPMHOLDOVERDURATION
,
3433 printk(KERN_ERR
"%s: failed to read power management timeout!\n",
3439 /* Preamble setup */
3440 if (priv
->has_preamble
) {
3441 err
= hermes_read_wordrec(hw
, USER_BAP
,
3442 HERMES_RID_CNFPREAMBLE_SYMBOL
,
3448 /* Set up the default configuration */
3449 priv
->iw_mode
= IW_MODE_INFRA
;
3450 /* By default use IEEE/IBSS ad-hoc mode if we have it */
3451 priv
->prefer_port3
= priv
->has_port3
&& (! priv
->has_ibss
);
3452 set_port_type(priv
);
3453 priv
->channel
= 0; /* use firmware default */
3455 priv
->promiscuous
= 0;
3456 priv
->encode_alg
= IW_ENCODE_ALG_NONE
;
3458 priv
->wpa_enabled
= 0;
3459 priv
->tkip_cm_active
= 0;
3461 priv
->wpa_ie_len
= 0;
3462 priv
->wpa_ie
= NULL
;
3464 /* Make the hardware available, as long as it hasn't been
3465 * removed elsewhere (e.g. by PCMCIA hot unplug) */
3466 spin_lock_irq(&priv
->lock
);
3467 priv
->hw_unavailable
--;
3468 spin_unlock_irq(&priv
->lock
);
3470 printk(KERN_DEBUG
"%s: ready\n", dev
->name
);
3477 *alloc_orinocodev(int sizeof_card
,
3478 struct device
*device
,
3479 int (*hard_reset
)(struct orinoco_private
*),
3480 int (*stop_fw
)(struct orinoco_private
*, int))
3482 struct net_device
*dev
;
3483 struct orinoco_private
*priv
;
3485 dev
= alloc_etherdev(sizeof(struct orinoco_private
) + sizeof_card
);
3488 priv
= netdev_priv(dev
);
3491 priv
->card
= (void *)((unsigned long)priv
3492 + sizeof(struct orinoco_private
));
3497 /* Setup / override net_device fields */
3498 dev
->init
= orinoco_init
;
3499 dev
->hard_start_xmit
= orinoco_xmit
;
3500 dev
->tx_timeout
= orinoco_tx_timeout
;
3501 dev
->watchdog_timeo
= HZ
; /* 1 second timeout */
3502 dev
->get_stats
= orinoco_get_stats
;
3503 dev
->ethtool_ops
= &orinoco_ethtool_ops
;
3504 dev
->wireless_handlers
= (struct iw_handler_def
*)&orinoco_handler_def
;
3506 priv
->wireless_data
.spy_data
= &priv
->spy_data
;
3507 dev
->wireless_data
= &priv
->wireless_data
;
3509 dev
->change_mtu
= orinoco_change_mtu
;
3510 dev
->set_multicast_list
= orinoco_set_multicast_list
;
3511 /* we use the default eth_mac_addr for setting the MAC addr */
3513 /* Reserve space in skb for the SNAP header */
3514 dev
->hard_header_len
+= ENCAPS_OVERHEAD
;
3516 /* Set up default callbacks */
3517 dev
->open
= orinoco_open
;
3518 dev
->stop
= orinoco_stop
;
3519 priv
->hard_reset
= hard_reset
;
3520 priv
->stop_fw
= stop_fw
;
3522 spin_lock_init(&priv
->lock
);
3524 priv
->hw_unavailable
= 1; /* orinoco_init() must clear this
3525 * before anything else touches the
3527 INIT_WORK(&priv
->reset_work
, orinoco_reset
);
3528 INIT_WORK(&priv
->join_work
, orinoco_join_ap
);
3529 INIT_WORK(&priv
->wevent_work
, orinoco_send_wevents
);
3531 INIT_LIST_HEAD(&priv
->rx_list
);
3532 tasklet_init(&priv
->rx_tasklet
, orinoco_rx_isr_tasklet
,
3533 (unsigned long) dev
);
3535 netif_carrier_off(dev
);
3536 priv
->last_linkstatus
= 0xffff;
3541 void free_orinocodev(struct net_device
*dev
)
3543 struct orinoco_private
*priv
= netdev_priv(dev
);
3545 /* No need to empty priv->rx_list: if the tasklet is scheduled
3546 * when we call tasklet_kill it will run one final time,
3547 * emptying the list */
3548 tasklet_kill(&priv
->rx_tasklet
);
3549 priv
->wpa_ie_len
= 0;
3550 kfree(priv
->wpa_ie
);
3551 orinoco_mic_free(priv
);
3552 orinoco_bss_data_free(priv
);
3556 /********************************************************************/
3557 /* Wireless extensions */
3558 /********************************************************************/
3560 /* Return : < 0 -> error code ; >= 0 -> length */
3561 static int orinoco_hw_get_essid(struct orinoco_private
*priv
, int *active
,
3562 char buf
[IW_ESSID_MAX_SIZE
+1])
3564 hermes_t
*hw
= &priv
->hw
;
3566 struct hermes_idstring essidbuf
;
3567 char *p
= (char *)(&essidbuf
.val
);
3569 unsigned long flags
;
3571 if (orinoco_lock(priv
, &flags
) != 0)
3574 if (strlen(priv
->desired_essid
) > 0) {
3575 /* We read the desired SSID from the hardware rather
3576 than from priv->desired_essid, just in case the
3577 firmware is allowed to change it on us. I'm not
3579 /* My guess is that the OWNSSID should always be whatever
3580 * we set to the card, whereas CURRENT_SSID is the one that
3581 * may change... - Jean II */
3586 rid
= (priv
->port_type
== 3) ? HERMES_RID_CNFOWNSSID
:
3587 HERMES_RID_CNFDESIREDSSID
;
3589 err
= hermes_read_ltv(hw
, USER_BAP
, rid
, sizeof(essidbuf
),
3596 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENTSSID
,
3597 sizeof(essidbuf
), NULL
, &essidbuf
);
3602 len
= le16_to_cpu(essidbuf
.len
);
3603 BUG_ON(len
> IW_ESSID_MAX_SIZE
);
3605 memset(buf
, 0, IW_ESSID_MAX_SIZE
);
3606 memcpy(buf
, p
, len
);
3610 orinoco_unlock(priv
, &flags
);
3615 static long orinoco_hw_get_freq(struct orinoco_private
*priv
)
3618 hermes_t
*hw
= &priv
->hw
;
3622 unsigned long flags
;
3624 if (orinoco_lock(priv
, &flags
) != 0)
3627 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CURRENTCHANNEL
, &channel
);
3631 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
3637 if ( (channel
< 1) || (channel
> NUM_CHANNELS
) ) {
3638 printk(KERN_WARNING
"%s: Channel out of range (%d)!\n",
3639 priv
->ndev
->name
, channel
);
3644 freq
= channel_frequency
[channel
-1] * 100000;
3647 orinoco_unlock(priv
, &flags
);
3651 return err
? err
: freq
;
3654 static int orinoco_hw_get_bitratelist(struct orinoco_private
*priv
,
3655 int *numrates
, s32
*rates
, int max
)
3657 hermes_t
*hw
= &priv
->hw
;
3658 struct hermes_idstring list
;
3659 unsigned char *p
= (unsigned char *)&list
.val
;
3663 unsigned long flags
;
3665 if (orinoco_lock(priv
, &flags
) != 0)
3668 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_SUPPORTEDDATARATES
,
3669 sizeof(list
), NULL
, &list
);
3670 orinoco_unlock(priv
, &flags
);
3675 num
= le16_to_cpu(list
.len
);
3677 num
= min(num
, max
);
3679 for (i
= 0; i
< num
; i
++) {
3680 rates
[i
] = (p
[i
] & 0x7f) * 500000; /* convert to bps */
3686 static int orinoco_ioctl_getname(struct net_device
*dev
,
3687 struct iw_request_info
*info
,
3691 struct orinoco_private
*priv
= netdev_priv(dev
);
3695 err
= orinoco_hw_get_bitratelist(priv
, &numrates
, NULL
, 0);
3697 if (!err
&& (numrates
> 2))
3698 strcpy(name
, "IEEE 802.11b");
3700 strcpy(name
, "IEEE 802.11-DS");
3705 static int orinoco_ioctl_setwap(struct net_device
*dev
,
3706 struct iw_request_info
*info
,
3707 struct sockaddr
*ap_addr
,
3710 struct orinoco_private
*priv
= netdev_priv(dev
);
3711 int err
= -EINPROGRESS
; /* Call commit handler */
3712 unsigned long flags
;
3713 static const u8 off_addr
[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3714 static const u8 any_addr
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3716 if (orinoco_lock(priv
, &flags
) != 0)
3719 /* Enable automatic roaming - no sanity checks are needed */
3720 if (memcmp(&ap_addr
->sa_data
, off_addr
, ETH_ALEN
) == 0 ||
3721 memcmp(&ap_addr
->sa_data
, any_addr
, ETH_ALEN
) == 0) {
3722 priv
->bssid_fixed
= 0;
3723 memset(priv
->desired_bssid
, 0, ETH_ALEN
);
3725 /* "off" means keep existing connection */
3726 if (ap_addr
->sa_data
[0] == 0) {
3727 __orinoco_hw_set_wap(priv
);
3733 if (priv
->firmware_type
== FIRMWARE_TYPE_AGERE
) {
3734 printk(KERN_WARNING
"%s: Lucent/Agere firmware doesn't "
3735 "support manual roaming\n",
3741 if (priv
->iw_mode
!= IW_MODE_INFRA
) {
3742 printk(KERN_WARNING
"%s: Manual roaming supported only in "
3743 "managed mode\n", dev
->name
);
3748 /* Intersil firmware hangs without Desired ESSID */
3749 if (priv
->firmware_type
== FIRMWARE_TYPE_INTERSIL
&&
3750 strlen(priv
->desired_essid
) == 0) {
3751 printk(KERN_WARNING
"%s: Desired ESSID must be set for "
3752 "manual roaming\n", dev
->name
);
3757 /* Finally, enable manual roaming */
3758 priv
->bssid_fixed
= 1;
3759 memcpy(priv
->desired_bssid
, &ap_addr
->sa_data
, ETH_ALEN
);
3762 orinoco_unlock(priv
, &flags
);
3766 static int orinoco_ioctl_getwap(struct net_device
*dev
,
3767 struct iw_request_info
*info
,
3768 struct sockaddr
*ap_addr
,
3771 struct orinoco_private
*priv
= netdev_priv(dev
);
3773 hermes_t
*hw
= &priv
->hw
;
3775 unsigned long flags
;
3777 if (orinoco_lock(priv
, &flags
) != 0)
3780 ap_addr
->sa_family
= ARPHRD_ETHER
;
3781 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENTBSSID
,
3782 ETH_ALEN
, NULL
, ap_addr
->sa_data
);
3784 orinoco_unlock(priv
, &flags
);
3789 static int orinoco_ioctl_setmode(struct net_device
*dev
,
3790 struct iw_request_info
*info
,
3794 struct orinoco_private
*priv
= netdev_priv(dev
);
3795 int err
= -EINPROGRESS
; /* Call commit handler */
3796 unsigned long flags
;
3798 if (priv
->iw_mode
== *mode
)
3801 if (orinoco_lock(priv
, &flags
) != 0)
3806 if (!priv
->has_ibss
&& !priv
->has_port3
)
3813 case IW_MODE_MONITOR
:
3814 if (priv
->broken_monitor
&& !force_monitor
) {
3815 printk(KERN_WARNING
"%s: Monitor mode support is "
3816 "buggy in this firmware, not enabling\n",
3827 if (err
== -EINPROGRESS
) {
3828 priv
->iw_mode
= *mode
;
3829 set_port_type(priv
);
3832 orinoco_unlock(priv
, &flags
);
3837 static int orinoco_ioctl_getmode(struct net_device
*dev
,
3838 struct iw_request_info
*info
,
3842 struct orinoco_private
*priv
= netdev_priv(dev
);
3844 *mode
= priv
->iw_mode
;
3848 static int orinoco_ioctl_getiwrange(struct net_device
*dev
,
3849 struct iw_request_info
*info
,
3850 struct iw_point
*rrq
,
3853 struct orinoco_private
*priv
= netdev_priv(dev
);
3855 struct iw_range
*range
= (struct iw_range
*) extra
;
3859 rrq
->length
= sizeof(struct iw_range
);
3860 memset(range
, 0, sizeof(struct iw_range
));
3862 range
->we_version_compiled
= WIRELESS_EXT
;
3863 range
->we_version_source
= 22;
3865 /* Set available channels/frequencies */
3866 range
->num_channels
= NUM_CHANNELS
;
3868 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
3869 if (priv
->channel_mask
& (1 << i
)) {
3870 range
->freq
[k
].i
= i
+ 1;
3871 range
->freq
[k
].m
= channel_frequency
[i
] * 100000;
3872 range
->freq
[k
].e
= 1;
3876 if (k
>= IW_MAX_FREQUENCIES
)
3879 range
->num_frequency
= k
;
3880 range
->sensitivity
= 3;
3882 if (priv
->has_wep
) {
3883 range
->max_encoding_tokens
= ORINOCO_MAX_KEYS
;
3884 range
->encoding_size
[0] = SMALL_KEY_SIZE
;
3885 range
->num_encoding_sizes
= 1;
3887 if (priv
->has_big_wep
) {
3888 range
->encoding_size
[1] = LARGE_KEY_SIZE
;
3889 range
->num_encoding_sizes
= 2;
3894 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_CIPHER_TKIP
;
3896 if ((priv
->iw_mode
== IW_MODE_ADHOC
) && (!SPY_NUMBER(priv
))){
3897 /* Quality stats meaningless in ad-hoc mode */
3899 range
->max_qual
.qual
= 0x8b - 0x2f;
3900 range
->max_qual
.level
= 0x2f - 0x95 - 1;
3901 range
->max_qual
.noise
= 0x2f - 0x95 - 1;
3902 /* Need to get better values */
3903 range
->avg_qual
.qual
= 0x24;
3904 range
->avg_qual
.level
= 0xC2;
3905 range
->avg_qual
.noise
= 0x9E;
3908 err
= orinoco_hw_get_bitratelist(priv
, &numrates
,
3909 range
->bitrate
, IW_MAX_BITRATES
);
3912 range
->num_bitrates
= numrates
;
3914 /* Set an indication of the max TCP throughput in bit/s that we can
3915 * expect using this interface. May be use for QoS stuff...
3918 range
->throughput
= 5 * 1000 * 1000; /* ~5 Mb/s */
3920 range
->throughput
= 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
3923 range
->max_rts
= 2347;
3924 range
->min_frag
= 256;
3925 range
->max_frag
= 2346;
3928 range
->max_pmp
= 65535000;
3930 range
->max_pmt
= 65535 * 1000; /* ??? */
3931 range
->pmp_flags
= IW_POWER_PERIOD
;
3932 range
->pmt_flags
= IW_POWER_TIMEOUT
;
3933 range
->pm_capa
= IW_POWER_PERIOD
| IW_POWER_TIMEOUT
| IW_POWER_UNICAST_R
;
3935 range
->retry_capa
= IW_RETRY_LIMIT
| IW_RETRY_LIFETIME
;
3936 range
->retry_flags
= IW_RETRY_LIMIT
;
3937 range
->r_time_flags
= IW_RETRY_LIFETIME
;
3938 range
->min_retry
= 0;
3939 range
->max_retry
= 65535; /* ??? */
3940 range
->min_r_time
= 0;
3941 range
->max_r_time
= 65535 * 1000; /* ??? */
3943 if (priv
->firmware_type
== FIRMWARE_TYPE_AGERE
)
3944 range
->scan_capa
= IW_SCAN_CAPA_ESSID
;
3946 range
->scan_capa
= IW_SCAN_CAPA_NONE
;
3948 /* Event capability (kernel) */
3949 IW_EVENT_CAPA_SET_KERNEL(range
->event_capa
);
3950 /* Event capability (driver) */
3951 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWTHRSPY
);
3952 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWAP
);
3953 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWSCAN
);
3954 IW_EVENT_CAPA_SET(range
->event_capa
, IWEVTXDROP
);
3959 static int orinoco_ioctl_setiwencode(struct net_device
*dev
,
3960 struct iw_request_info
*info
,
3961 struct iw_point
*erq
,
3964 struct orinoco_private
*priv
= netdev_priv(dev
);
3965 int index
= (erq
->flags
& IW_ENCODE_INDEX
) - 1;
3966 int setindex
= priv
->tx_key
;
3967 int encode_alg
= priv
->encode_alg
;
3968 int restricted
= priv
->wep_restrict
;
3970 int err
= -EINPROGRESS
; /* Call commit handler */
3971 unsigned long flags
;
3973 if (! priv
->has_wep
)
3977 /* We actually have a key to set - check its length */
3978 if (erq
->length
> LARGE_KEY_SIZE
)
3981 if ( (erq
->length
> SMALL_KEY_SIZE
) && !priv
->has_big_wep
)
3985 if (orinoco_lock(priv
, &flags
) != 0)
3988 /* Clear any TKIP key we have */
3989 if ((priv
->has_wpa
) && (priv
->encode_alg
== IW_ENCODE_ALG_TKIP
))
3990 (void) orinoco_clear_tkip_key(priv
, setindex
);
3992 if (erq
->length
> 0) {
3993 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
))
3994 index
= priv
->tx_key
;
3996 /* Adjust key length to a supported value */
3997 if (erq
->length
> SMALL_KEY_SIZE
) {
3998 xlen
= LARGE_KEY_SIZE
;
3999 } else if (erq
->length
> 0) {
4000 xlen
= SMALL_KEY_SIZE
;
4004 /* Switch on WEP if off */
4005 if ((encode_alg
!= IW_ENCODE_ALG_WEP
) && (xlen
> 0)) {
4007 encode_alg
= IW_ENCODE_ALG_WEP
;
4010 /* Important note : if the user do "iwconfig eth0 enc off",
4011 * we will arrive there with an index of -1. This is valid
4012 * but need to be taken care off... Jean II */
4013 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
)) {
4014 if((index
!= -1) || (erq
->flags
== 0)) {
4019 /* Set the index : Check that the key is valid */
4020 if(priv
->keys
[index
].len
== 0) {
4028 if (erq
->flags
& IW_ENCODE_DISABLED
)
4029 encode_alg
= IW_ENCODE_ALG_NONE
;
4030 if (erq
->flags
& IW_ENCODE_OPEN
)
4032 if (erq
->flags
& IW_ENCODE_RESTRICTED
)
4035 if (erq
->pointer
&& erq
->length
> 0) {
4036 priv
->keys
[index
].len
= cpu_to_le16(xlen
);
4037 memset(priv
->keys
[index
].data
, 0,
4038 sizeof(priv
->keys
[index
].data
));
4039 memcpy(priv
->keys
[index
].data
, keybuf
, erq
->length
);
4041 priv
->tx_key
= setindex
;
4043 /* Try fast key change if connected and only keys are changed */
4044 if ((priv
->encode_alg
== encode_alg
) &&
4045 (priv
->wep_restrict
== restricted
) &&
4046 netif_carrier_ok(dev
)) {
4047 err
= __orinoco_hw_setup_wepkeys(priv
);
4048 /* No need to commit if successful */
4052 priv
->encode_alg
= encode_alg
;
4053 priv
->wep_restrict
= restricted
;
4056 orinoco_unlock(priv
, &flags
);
4061 static int orinoco_ioctl_getiwencode(struct net_device
*dev
,
4062 struct iw_request_info
*info
,
4063 struct iw_point
*erq
,
4066 struct orinoco_private
*priv
= netdev_priv(dev
);
4067 int index
= (erq
->flags
& IW_ENCODE_INDEX
) - 1;
4069 unsigned long flags
;
4071 if (! priv
->has_wep
)
4074 if (orinoco_lock(priv
, &flags
) != 0)
4077 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
))
4078 index
= priv
->tx_key
;
4081 if (!priv
->encode_alg
)
4082 erq
->flags
|= IW_ENCODE_DISABLED
;
4083 erq
->flags
|= index
+ 1;
4085 if (priv
->wep_restrict
)
4086 erq
->flags
|= IW_ENCODE_RESTRICTED
;
4088 erq
->flags
|= IW_ENCODE_OPEN
;
4090 xlen
= le16_to_cpu(priv
->keys
[index
].len
);
4094 memcpy(keybuf
, priv
->keys
[index
].data
, ORINOCO_MAX_KEY_SIZE
);
4096 orinoco_unlock(priv
, &flags
);
4100 static int orinoco_ioctl_setessid(struct net_device
*dev
,
4101 struct iw_request_info
*info
,
4102 struct iw_point
*erq
,
4105 struct orinoco_private
*priv
= netdev_priv(dev
);
4106 unsigned long flags
;
4108 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
4109 * anyway... - Jean II */
4111 /* Hum... Should not use Wireless Extension constant (may change),
4112 * should use our own... - Jean II */
4113 if (erq
->length
> IW_ESSID_MAX_SIZE
)
4116 if (orinoco_lock(priv
, &flags
) != 0)
4119 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
4120 memset(priv
->desired_essid
, 0, sizeof(priv
->desired_essid
));
4122 /* If not ANY, get the new ESSID */
4124 memcpy(priv
->desired_essid
, essidbuf
, erq
->length
);
4127 orinoco_unlock(priv
, &flags
);
4129 return -EINPROGRESS
; /* Call commit handler */
4132 static int orinoco_ioctl_getessid(struct net_device
*dev
,
4133 struct iw_request_info
*info
,
4134 struct iw_point
*erq
,
4137 struct orinoco_private
*priv
= netdev_priv(dev
);
4140 unsigned long flags
;
4142 if (netif_running(dev
)) {
4143 err
= orinoco_hw_get_essid(priv
, &active
, essidbuf
);
4148 if (orinoco_lock(priv
, &flags
) != 0)
4150 memcpy(essidbuf
, priv
->desired_essid
, IW_ESSID_MAX_SIZE
);
4151 erq
->length
= strlen(priv
->desired_essid
);
4152 orinoco_unlock(priv
, &flags
);
4160 static int orinoco_ioctl_setnick(struct net_device
*dev
,
4161 struct iw_request_info
*info
,
4162 struct iw_point
*nrq
,
4165 struct orinoco_private
*priv
= netdev_priv(dev
);
4166 unsigned long flags
;
4168 if (nrq
->length
> IW_ESSID_MAX_SIZE
)
4171 if (orinoco_lock(priv
, &flags
) != 0)
4174 memset(priv
->nick
, 0, sizeof(priv
->nick
));
4175 memcpy(priv
->nick
, nickbuf
, nrq
->length
);
4177 orinoco_unlock(priv
, &flags
);
4179 return -EINPROGRESS
; /* Call commit handler */
4182 static int orinoco_ioctl_getnick(struct net_device
*dev
,
4183 struct iw_request_info
*info
,
4184 struct iw_point
*nrq
,
4187 struct orinoco_private
*priv
= netdev_priv(dev
);
4188 unsigned long flags
;
4190 if (orinoco_lock(priv
, &flags
) != 0)
4193 memcpy(nickbuf
, priv
->nick
, IW_ESSID_MAX_SIZE
);
4194 orinoco_unlock(priv
, &flags
);
4196 nrq
->length
= strlen(priv
->nick
);
4201 static int orinoco_ioctl_setfreq(struct net_device
*dev
,
4202 struct iw_request_info
*info
,
4203 struct iw_freq
*frq
,
4206 struct orinoco_private
*priv
= netdev_priv(dev
);
4208 unsigned long flags
;
4209 int err
= -EINPROGRESS
; /* Call commit handler */
4211 /* In infrastructure mode the AP sets the channel */
4212 if (priv
->iw_mode
== IW_MODE_INFRA
)
4215 if ( (frq
->e
== 0) && (frq
->m
<= 1000) ) {
4216 /* Setting by channel number */
4219 /* Setting by frequency - search the table */
4223 for (i
= 0; i
< (6 - frq
->e
); i
++)
4226 for (i
= 0; i
< NUM_CHANNELS
; i
++)
4227 if (frq
->m
== (channel_frequency
[i
] * mult
))
4231 if ( (chan
< 1) || (chan
> NUM_CHANNELS
) ||
4232 ! (priv
->channel_mask
& (1 << (chan
-1)) ) )
4235 if (orinoco_lock(priv
, &flags
) != 0)
4238 priv
->channel
= chan
;
4239 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
4240 /* Fast channel change - no commit if successful */
4241 hermes_t
*hw
= &priv
->hw
;
4242 err
= hermes_docmd_wait(hw
, HERMES_CMD_TEST
|
4243 HERMES_TEST_SET_CHANNEL
,
4246 orinoco_unlock(priv
, &flags
);
4251 static int orinoco_ioctl_getfreq(struct net_device
*dev
,
4252 struct iw_request_info
*info
,
4253 struct iw_freq
*frq
,
4256 struct orinoco_private
*priv
= netdev_priv(dev
);
4259 /* Locking done in there */
4260 tmp
= orinoco_hw_get_freq(priv
);
4271 static int orinoco_ioctl_getsens(struct net_device
*dev
,
4272 struct iw_request_info
*info
,
4273 struct iw_param
*srq
,
4276 struct orinoco_private
*priv
= netdev_priv(dev
);
4277 hermes_t
*hw
= &priv
->hw
;
4280 unsigned long flags
;
4282 if (!priv
->has_sensitivity
)
4285 if (orinoco_lock(priv
, &flags
) != 0)
4287 err
= hermes_read_wordrec(hw
, USER_BAP
,
4288 HERMES_RID_CNFSYSTEMSCALE
, &val
);
4289 orinoco_unlock(priv
, &flags
);
4295 srq
->fixed
= 0; /* auto */
4300 static int orinoco_ioctl_setsens(struct net_device
*dev
,
4301 struct iw_request_info
*info
,
4302 struct iw_param
*srq
,
4305 struct orinoco_private
*priv
= netdev_priv(dev
);
4306 int val
= srq
->value
;
4307 unsigned long flags
;
4309 if (!priv
->has_sensitivity
)
4312 if ((val
< 1) || (val
> 3))
4315 if (orinoco_lock(priv
, &flags
) != 0)
4317 priv
->ap_density
= val
;
4318 orinoco_unlock(priv
, &flags
);
4320 return -EINPROGRESS
; /* Call commit handler */
4323 static int orinoco_ioctl_setrts(struct net_device
*dev
,
4324 struct iw_request_info
*info
,
4325 struct iw_param
*rrq
,
4328 struct orinoco_private
*priv
= netdev_priv(dev
);
4329 int val
= rrq
->value
;
4330 unsigned long flags
;
4335 if ( (val
< 0) || (val
> 2347) )
4338 if (orinoco_lock(priv
, &flags
) != 0)
4341 priv
->rts_thresh
= val
;
4342 orinoco_unlock(priv
, &flags
);
4344 return -EINPROGRESS
; /* Call commit handler */
4347 static int orinoco_ioctl_getrts(struct net_device
*dev
,
4348 struct iw_request_info
*info
,
4349 struct iw_param
*rrq
,
4352 struct orinoco_private
*priv
= netdev_priv(dev
);
4354 rrq
->value
= priv
->rts_thresh
;
4355 rrq
->disabled
= (rrq
->value
== 2347);
4361 static int orinoco_ioctl_setfrag(struct net_device
*dev
,
4362 struct iw_request_info
*info
,
4363 struct iw_param
*frq
,
4366 struct orinoco_private
*priv
= netdev_priv(dev
);
4367 int err
= -EINPROGRESS
; /* Call commit handler */
4368 unsigned long flags
;
4370 if (orinoco_lock(priv
, &flags
) != 0)
4373 if (priv
->has_mwo
) {
4375 priv
->mwo_robust
= 0;
4378 printk(KERN_WARNING
"%s: Fixed fragmentation is "
4379 "not supported on this firmware. "
4380 "Using MWO robust instead.\n", dev
->name
);
4381 priv
->mwo_robust
= 1;
4385 priv
->frag_thresh
= 2346;
4387 if ( (frq
->value
< 256) || (frq
->value
> 2346) )
4390 priv
->frag_thresh
= frq
->value
& ~0x1; /* must be even */
4394 orinoco_unlock(priv
, &flags
);
4399 static int orinoco_ioctl_getfrag(struct net_device
*dev
,
4400 struct iw_request_info
*info
,
4401 struct iw_param
*frq
,
4404 struct orinoco_private
*priv
= netdev_priv(dev
);
4405 hermes_t
*hw
= &priv
->hw
;
4408 unsigned long flags
;
4410 if (orinoco_lock(priv
, &flags
) != 0)
4413 if (priv
->has_mwo
) {
4414 err
= hermes_read_wordrec(hw
, USER_BAP
,
4415 HERMES_RID_CNFMWOROBUST_AGERE
,
4420 frq
->value
= val
? 2347 : 0;
4421 frq
->disabled
= ! val
;
4424 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
4430 frq
->disabled
= (val
>= 2346);
4434 orinoco_unlock(priv
, &flags
);
4439 static int orinoco_ioctl_setrate(struct net_device
*dev
,
4440 struct iw_request_info
*info
,
4441 struct iw_param
*rrq
,
4444 struct orinoco_private
*priv
= netdev_priv(dev
);
4446 int bitrate
; /* 100s of kilobits */
4448 unsigned long flags
;
4450 /* As the user space doesn't know our highest rate, it uses -1
4451 * to ask us to set the highest rate. Test it using "iwconfig
4452 * ethX rate auto" - Jean II */
4453 if (rrq
->value
== -1)
4456 if (rrq
->value
% 100000)
4458 bitrate
= rrq
->value
/ 100000;
4461 if ( (bitrate
!= 10) && (bitrate
!= 20) &&
4462 (bitrate
!= 55) && (bitrate
!= 110) )
4465 for (i
= 0; i
< BITRATE_TABLE_SIZE
; i
++)
4466 if ( (bitrate_table
[i
].bitrate
== bitrate
) &&
4467 (bitrate_table
[i
].automatic
== ! rrq
->fixed
) ) {
4475 if (orinoco_lock(priv
, &flags
) != 0)
4477 priv
->bitratemode
= ratemode
;
4478 orinoco_unlock(priv
, &flags
);
4480 return -EINPROGRESS
;
4483 static int orinoco_ioctl_getrate(struct net_device
*dev
,
4484 struct iw_request_info
*info
,
4485 struct iw_param
*rrq
,
4488 struct orinoco_private
*priv
= netdev_priv(dev
);
4489 hermes_t
*hw
= &priv
->hw
;
4494 unsigned long flags
;
4496 if (orinoco_lock(priv
, &flags
) != 0)
4499 ratemode
= priv
->bitratemode
;
4501 BUG_ON((ratemode
< 0) || (ratemode
>= BITRATE_TABLE_SIZE
));
4503 rrq
->value
= bitrate_table
[ratemode
].bitrate
* 100000;
4504 rrq
->fixed
= ! bitrate_table
[ratemode
].automatic
;
4507 /* If the interface is running we try to find more about the
4509 if (netif_running(dev
)) {
4510 err
= hermes_read_wordrec(hw
, USER_BAP
,
4511 HERMES_RID_CURRENTTXRATE
, &val
);
4515 switch (priv
->firmware_type
) {
4516 case FIRMWARE_TYPE_AGERE
: /* Lucent style rate */
4517 /* Note : in Lucent firmware, the return value of
4518 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
4519 * and therefore is totally different from the
4520 * encoding of HERMES_RID_CNFTXRATECONTROL.
4521 * Don't forget that 6Mb/s is really 5.5Mb/s */
4523 rrq
->value
= 5500000;
4525 rrq
->value
= val
* 1000000;
4527 case FIRMWARE_TYPE_INTERSIL
: /* Intersil style rate */
4528 case FIRMWARE_TYPE_SYMBOL
: /* Symbol style rate */
4529 for (i
= 0; i
< BITRATE_TABLE_SIZE
; i
++)
4530 if (bitrate_table
[i
].intersil_txratectrl
== val
) {
4534 if (i
>= BITRATE_TABLE_SIZE
)
4535 printk(KERN_INFO
"%s: Unable to determine current bitrate (0x%04hx)\n",
4538 rrq
->value
= bitrate_table
[ratemode
].bitrate
* 100000;
4546 orinoco_unlock(priv
, &flags
);
4551 static int orinoco_ioctl_setpower(struct net_device
*dev
,
4552 struct iw_request_info
*info
,
4553 struct iw_param
*prq
,
4556 struct orinoco_private
*priv
= netdev_priv(dev
);
4557 int err
= -EINPROGRESS
; /* Call commit handler */
4558 unsigned long flags
;
4560 if (orinoco_lock(priv
, &flags
) != 0)
4563 if (prq
->disabled
) {
4566 switch (prq
->flags
& IW_POWER_MODE
) {
4567 case IW_POWER_UNICAST_R
:
4571 case IW_POWER_ALL_R
:
4576 /* No flags : but we may have a value - Jean II */
4583 if (prq
->flags
& IW_POWER_TIMEOUT
) {
4585 priv
->pm_timeout
= prq
->value
/ 1000;
4587 if (prq
->flags
& IW_POWER_PERIOD
) {
4589 priv
->pm_period
= prq
->value
/ 1000;
4591 /* It's valid to not have a value if we are just toggling
4592 * the flags... Jean II */
4600 orinoco_unlock(priv
, &flags
);
4605 static int orinoco_ioctl_getpower(struct net_device
*dev
,
4606 struct iw_request_info
*info
,
4607 struct iw_param
*prq
,
4610 struct orinoco_private
*priv
= netdev_priv(dev
);
4611 hermes_t
*hw
= &priv
->hw
;
4613 u16 enable
, period
, timeout
, mcast
;
4614 unsigned long flags
;
4616 if (orinoco_lock(priv
, &flags
) != 0)
4619 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFPMENABLED
, &enable
);
4623 err
= hermes_read_wordrec(hw
, USER_BAP
,
4624 HERMES_RID_CNFMAXSLEEPDURATION
, &period
);
4628 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFPMHOLDOVERDURATION
, &timeout
);
4632 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFMULTICASTRECEIVE
, &mcast
);
4636 prq
->disabled
= !enable
;
4637 /* Note : by default, display the period */
4638 if ((prq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
4639 prq
->flags
= IW_POWER_TIMEOUT
;
4640 prq
->value
= timeout
* 1000;
4642 prq
->flags
= IW_POWER_PERIOD
;
4643 prq
->value
= period
* 1000;
4646 prq
->flags
|= IW_POWER_ALL_R
;
4648 prq
->flags
|= IW_POWER_UNICAST_R
;
4651 orinoco_unlock(priv
, &flags
);
4656 static int orinoco_ioctl_set_encodeext(struct net_device
*dev
,
4657 struct iw_request_info
*info
,
4658 union iwreq_data
*wrqu
,
4661 struct orinoco_private
*priv
= netdev_priv(dev
);
4662 struct iw_point
*encoding
= &wrqu
->encoding
;
4663 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
4664 int idx
, alg
= ext
->alg
, set_key
= 1;
4665 unsigned long flags
;
4669 if (orinoco_lock(priv
, &flags
) != 0)
4672 /* Determine and validate the key index */
4673 idx
= encoding
->flags
& IW_ENCODE_INDEX
;
4675 if ((idx
< 1) || (idx
> WEP_KEYS
))
4681 if (encoding
->flags
& IW_ENCODE_DISABLED
)
4682 alg
= IW_ENCODE_ALG_NONE
;
4684 if (priv
->has_wpa
&& (alg
!= IW_ENCODE_ALG_TKIP
)) {
4685 /* Clear any TKIP TX key we had */
4686 (void) orinoco_clear_tkip_key(priv
, priv
->tx_key
);
4689 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
) {
4691 set_key
= ((alg
== IW_ENCODE_ALG_TKIP
) ||
4692 (ext
->key_len
> 0)) ? 1 : 0;
4696 /* Set the requested key first */
4698 case IW_ENCODE_ALG_NONE
:
4699 priv
->encode_alg
= alg
;
4700 priv
->keys
[idx
].len
= 0;
4703 case IW_ENCODE_ALG_WEP
:
4704 if (ext
->key_len
> SMALL_KEY_SIZE
)
4705 key_len
= LARGE_KEY_SIZE
;
4706 else if (ext
->key_len
> 0)
4707 key_len
= SMALL_KEY_SIZE
;
4711 priv
->encode_alg
= alg
;
4712 priv
->keys
[idx
].len
= cpu_to_le16(key_len
);
4714 key_len
= min(ext
->key_len
, key_len
);
4716 memset(priv
->keys
[idx
].data
, 0, ORINOCO_MAX_KEY_SIZE
);
4717 memcpy(priv
->keys
[idx
].data
, ext
->key
, key_len
);
4720 case IW_ENCODE_ALG_TKIP
:
4722 hermes_t
*hw
= &priv
->hw
;
4725 if (!priv
->has_wpa
||
4726 (ext
->key_len
> sizeof(priv
->tkip_key
[0])))
4729 priv
->encode_alg
= alg
;
4730 memset(&priv
->tkip_key
[idx
], 0,
4731 sizeof(priv
->tkip_key
[idx
]));
4732 memcpy(&priv
->tkip_key
[idx
], ext
->key
, ext
->key_len
);
4734 if (ext
->ext_flags
& IW_ENCODE_EXT_RX_SEQ_VALID
)
4735 tkip_iv
= &ext
->rx_seq
[0];
4737 err
= __orinoco_hw_set_tkip_key(hw
, idx
,
4738 ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
,
4739 (u8
*) &priv
->tkip_key
[idx
],
4742 printk(KERN_ERR
"%s: Error %d setting TKIP key"
4743 "\n", dev
->name
, err
);
4753 orinoco_unlock(priv
, &flags
);
4758 static int orinoco_ioctl_get_encodeext(struct net_device
*dev
,
4759 struct iw_request_info
*info
,
4760 union iwreq_data
*wrqu
,
4763 struct orinoco_private
*priv
= netdev_priv(dev
);
4764 struct iw_point
*encoding
= &wrqu
->encoding
;
4765 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
4766 int idx
, max_key_len
;
4767 unsigned long flags
;
4770 if (orinoco_lock(priv
, &flags
) != 0)
4774 max_key_len
= encoding
->length
- sizeof(*ext
);
4775 if (max_key_len
< 0)
4778 idx
= encoding
->flags
& IW_ENCODE_INDEX
;
4780 if ((idx
< 1) || (idx
> WEP_KEYS
))
4786 encoding
->flags
= idx
+ 1;
4787 memset(ext
, 0, sizeof(*ext
));
4789 ext
->alg
= priv
->encode_alg
;
4790 switch (priv
->encode_alg
) {
4791 case IW_ENCODE_ALG_NONE
:
4793 encoding
->flags
|= IW_ENCODE_DISABLED
;
4795 case IW_ENCODE_ALG_WEP
:
4796 ext
->key_len
= min_t(u16
, le16_to_cpu(priv
->keys
[idx
].len
),
4798 memcpy(ext
->key
, priv
->keys
[idx
].data
, ext
->key_len
);
4799 encoding
->flags
|= IW_ENCODE_ENABLED
;
4801 case IW_ENCODE_ALG_TKIP
:
4802 ext
->key_len
= min_t(u16
, sizeof(struct orinoco_tkip_key
),
4804 memcpy(ext
->key
, &priv
->tkip_key
[idx
], ext
->key_len
);
4805 encoding
->flags
|= IW_ENCODE_ENABLED
;
4811 orinoco_unlock(priv
, &flags
);
4816 static int orinoco_ioctl_set_auth(struct net_device
*dev
,
4817 struct iw_request_info
*info
,
4818 union iwreq_data
*wrqu
, char *extra
)
4820 struct orinoco_private
*priv
= netdev_priv(dev
);
4821 hermes_t
*hw
= &priv
->hw
;
4822 struct iw_param
*param
= &wrqu
->param
;
4823 unsigned long flags
;
4824 int ret
= -EINPROGRESS
;
4826 if (orinoco_lock(priv
, &flags
) != 0)
4829 switch (param
->flags
& IW_AUTH_INDEX
) {
4830 case IW_AUTH_WPA_VERSION
:
4831 case IW_AUTH_CIPHER_PAIRWISE
:
4832 case IW_AUTH_CIPHER_GROUP
:
4833 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
4834 case IW_AUTH_PRIVACY_INVOKED
:
4835 case IW_AUTH_DROP_UNENCRYPTED
:
4837 * orinoco does not use these parameters
4841 case IW_AUTH_KEY_MGMT
:
4842 /* wl_lkm implies value 2 == PSK for Hermes I
4843 * which ties in with WEXT
4844 * no other hints tho :(
4846 priv
->key_mgmt
= param
->value
;
4849 case IW_AUTH_TKIP_COUNTERMEASURES
:
4850 /* When countermeasures are enabled, shut down the
4851 * card; when disabled, re-enable the card. This must
4852 * take effect immediately.
4854 * TODO: Make sure that the EAPOL message is getting
4855 * out before card disabled
4858 priv
->tkip_cm_active
= 1;
4859 ret
= hermes_enable_port(hw
, 0);
4861 priv
->tkip_cm_active
= 0;
4862 ret
= hermes_disable_port(hw
, 0);
4866 case IW_AUTH_80211_AUTH_ALG
:
4867 if (param
->value
& IW_AUTH_ALG_SHARED_KEY
)
4868 priv
->wep_restrict
= 1;
4869 else if (param
->value
& IW_AUTH_ALG_OPEN_SYSTEM
)
4870 priv
->wep_restrict
= 0;
4875 case IW_AUTH_WPA_ENABLED
:
4876 if (priv
->has_wpa
) {
4877 priv
->wpa_enabled
= param
->value
? 1 : 0;
4881 /* else silently accept disable of WPA */
4882 priv
->wpa_enabled
= 0;
4890 orinoco_unlock(priv
, &flags
);
4894 static int orinoco_ioctl_get_auth(struct net_device
*dev
,
4895 struct iw_request_info
*info
,
4896 union iwreq_data
*wrqu
, char *extra
)
4898 struct orinoco_private
*priv
= netdev_priv(dev
);
4899 struct iw_param
*param
= &wrqu
->param
;
4900 unsigned long flags
;
4903 if (orinoco_lock(priv
, &flags
) != 0)
4906 switch (param
->flags
& IW_AUTH_INDEX
) {
4907 case IW_AUTH_KEY_MGMT
:
4908 param
->value
= priv
->key_mgmt
;
4911 case IW_AUTH_TKIP_COUNTERMEASURES
:
4912 param
->value
= priv
->tkip_cm_active
;
4915 case IW_AUTH_80211_AUTH_ALG
:
4916 if (priv
->wep_restrict
)
4917 param
->value
= IW_AUTH_ALG_SHARED_KEY
;
4919 param
->value
= IW_AUTH_ALG_OPEN_SYSTEM
;
4922 case IW_AUTH_WPA_ENABLED
:
4923 param
->value
= priv
->wpa_enabled
;
4930 orinoco_unlock(priv
, &flags
);
4934 static int orinoco_ioctl_set_genie(struct net_device
*dev
,
4935 struct iw_request_info
*info
,
4936 union iwreq_data
*wrqu
, char *extra
)
4938 struct orinoco_private
*priv
= netdev_priv(dev
);
4940 unsigned long flags
;
4943 if ((wrqu
->data
.length
> MAX_WPA_IE_LEN
) ||
4944 (wrqu
->data
.length
&& (extra
== NULL
)))
4947 if (orinoco_lock(priv
, &flags
) != 0)
4950 if (wrqu
->data
.length
) {
4951 buf
= kmalloc(wrqu
->data
.length
, GFP_KERNEL
);
4957 memcpy(buf
, extra
, wrqu
->data
.length
);
4958 kfree(priv
->wpa_ie
);
4960 priv
->wpa_ie_len
= wrqu
->data
.length
;
4962 kfree(priv
->wpa_ie
);
4963 priv
->wpa_ie
= NULL
;
4964 priv
->wpa_ie_len
= 0;
4968 /* Looks like wl_lkm wants to check the auth alg, and
4969 * somehow pass it to the firmware.
4970 * Instead it just calls the key mgmt rid
4971 * - we do this in set auth.
4976 orinoco_unlock(priv
, &flags
);
4980 static int orinoco_ioctl_get_genie(struct net_device
*dev
,
4981 struct iw_request_info
*info
,
4982 union iwreq_data
*wrqu
, char *extra
)
4984 struct orinoco_private
*priv
= netdev_priv(dev
);
4985 unsigned long flags
;
4988 if (orinoco_lock(priv
, &flags
) != 0)
4991 if ((priv
->wpa_ie_len
== 0) || (priv
->wpa_ie
== NULL
)) {
4992 wrqu
->data
.length
= 0;
4996 if (wrqu
->data
.length
< priv
->wpa_ie_len
) {
5001 wrqu
->data
.length
= priv
->wpa_ie_len
;
5002 memcpy(extra
, priv
->wpa_ie
, priv
->wpa_ie_len
);
5005 orinoco_unlock(priv
, &flags
);
5009 static int orinoco_ioctl_set_mlme(struct net_device
*dev
,
5010 struct iw_request_info
*info
,
5011 union iwreq_data
*wrqu
, char *extra
)
5013 struct orinoco_private
*priv
= netdev_priv(dev
);
5014 hermes_t
*hw
= &priv
->hw
;
5015 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
5016 unsigned long flags
;
5019 if (orinoco_lock(priv
, &flags
) != 0)
5022 switch (mlme
->cmd
) {
5023 case IW_MLME_DEAUTH
:
5024 /* silently ignore */
5027 case IW_MLME_DISASSOC
:
5032 } __attribute__ ((packed
)) buf
;
5034 memcpy(buf
.addr
, mlme
->addr
.sa_data
, ETH_ALEN
);
5035 buf
.reason_code
= cpu_to_le16(mlme
->reason_code
);
5036 ret
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
5037 HERMES_RID_CNFDISASSOCIATE
,
5045 orinoco_unlock(priv
, &flags
);
5049 static int orinoco_ioctl_getretry(struct net_device
*dev
,
5050 struct iw_request_info
*info
,
5051 struct iw_param
*rrq
,
5054 struct orinoco_private
*priv
= netdev_priv(dev
);
5055 hermes_t
*hw
= &priv
->hw
;
5057 u16 short_limit
, long_limit
, lifetime
;
5058 unsigned long flags
;
5060 if (orinoco_lock(priv
, &flags
) != 0)
5063 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_SHORTRETRYLIMIT
,
5068 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_LONGRETRYLIMIT
,
5073 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_MAXTRANSMITLIFETIME
,
5078 rrq
->disabled
= 0; /* Can't be disabled */
5080 /* Note : by default, display the retry number */
5081 if ((rrq
->flags
& IW_RETRY_TYPE
) == IW_RETRY_LIFETIME
) {
5082 rrq
->flags
= IW_RETRY_LIFETIME
;
5083 rrq
->value
= lifetime
* 1000; /* ??? */
5085 /* By default, display the min number */
5086 if ((rrq
->flags
& IW_RETRY_LONG
)) {
5087 rrq
->flags
= IW_RETRY_LIMIT
| IW_RETRY_LONG
;
5088 rrq
->value
= long_limit
;
5090 rrq
->flags
= IW_RETRY_LIMIT
;
5091 rrq
->value
= short_limit
;
5092 if(short_limit
!= long_limit
)
5093 rrq
->flags
|= IW_RETRY_SHORT
;
5098 orinoco_unlock(priv
, &flags
);
5103 static int orinoco_ioctl_reset(struct net_device
*dev
,
5104 struct iw_request_info
*info
,
5108 struct orinoco_private
*priv
= netdev_priv(dev
);
5110 if (! capable(CAP_NET_ADMIN
))
5113 if (info
->cmd
== (SIOCIWFIRSTPRIV
+ 0x1)) {
5114 printk(KERN_DEBUG
"%s: Forcing reset!\n", dev
->name
);
5116 /* Firmware reset */
5117 orinoco_reset(&priv
->reset_work
);
5119 printk(KERN_DEBUG
"%s: Force scheduling reset!\n", dev
->name
);
5121 schedule_work(&priv
->reset_work
);
5127 static int orinoco_ioctl_setibssport(struct net_device
*dev
,
5128 struct iw_request_info
*info
,
5133 struct orinoco_private
*priv
= netdev_priv(dev
);
5134 int val
= *( (int *) extra
);
5135 unsigned long flags
;
5137 if (orinoco_lock(priv
, &flags
) != 0)
5140 priv
->ibss_port
= val
;
5142 /* Actually update the mode we are using */
5143 set_port_type(priv
);
5145 orinoco_unlock(priv
, &flags
);
5146 return -EINPROGRESS
; /* Call commit handler */
5149 static int orinoco_ioctl_getibssport(struct net_device
*dev
,
5150 struct iw_request_info
*info
,
5154 struct orinoco_private
*priv
= netdev_priv(dev
);
5155 int *val
= (int *) extra
;
5157 *val
= priv
->ibss_port
;
5161 static int orinoco_ioctl_setport3(struct net_device
*dev
,
5162 struct iw_request_info
*info
,
5166 struct orinoco_private
*priv
= netdev_priv(dev
);
5167 int val
= *( (int *) extra
);
5169 unsigned long flags
;
5171 if (orinoco_lock(priv
, &flags
) != 0)
5175 case 0: /* Try to do IEEE ad-hoc mode */
5176 if (! priv
->has_ibss
) {
5180 priv
->prefer_port3
= 0;
5184 case 1: /* Try to do Lucent proprietary ad-hoc mode */
5185 if (! priv
->has_port3
) {
5189 priv
->prefer_port3
= 1;
5197 /* Actually update the mode we are using */
5198 set_port_type(priv
);
5202 orinoco_unlock(priv
, &flags
);
5207 static int orinoco_ioctl_getport3(struct net_device
*dev
,
5208 struct iw_request_info
*info
,
5212 struct orinoco_private
*priv
= netdev_priv(dev
);
5213 int *val
= (int *) extra
;
5215 *val
= priv
->prefer_port3
;
5219 static int orinoco_ioctl_setpreamble(struct net_device
*dev
,
5220 struct iw_request_info
*info
,
5224 struct orinoco_private
*priv
= netdev_priv(dev
);
5225 unsigned long flags
;
5228 if (! priv
->has_preamble
)
5231 /* 802.11b has recently defined some short preamble.
5232 * Basically, the Phy header has been reduced in size.
5233 * This increase performance, especially at high rates
5234 * (the preamble is transmitted at 1Mb/s), unfortunately
5235 * this give compatibility troubles... - Jean II */
5236 val
= *( (int *) extra
);
5238 if (orinoco_lock(priv
, &flags
) != 0)
5246 orinoco_unlock(priv
, &flags
);
5248 return -EINPROGRESS
; /* Call commit handler */
5251 static int orinoco_ioctl_getpreamble(struct net_device
*dev
,
5252 struct iw_request_info
*info
,
5256 struct orinoco_private
*priv
= netdev_priv(dev
);
5257 int *val
= (int *) extra
;
5259 if (! priv
->has_preamble
)
5262 *val
= priv
->preamble
;
5266 /* ioctl interface to hermes_read_ltv()
5267 * To use with iwpriv, pass the RID as the token argument, e.g.
5268 * iwpriv get_rid [0xfc00]
5269 * At least Wireless Tools 25 is required to use iwpriv.
5270 * For Wireless Tools 25 and 26 append "dummy" are the end. */
5271 static int orinoco_ioctl_getrid(struct net_device
*dev
,
5272 struct iw_request_info
*info
,
5273 struct iw_point
*data
,
5276 struct orinoco_private
*priv
= netdev_priv(dev
);
5277 hermes_t
*hw
= &priv
->hw
;
5278 int rid
= data
->flags
;
5281 unsigned long flags
;
5283 /* It's a "get" function, but we don't want users to access the
5284 * WEP key and other raw firmware data */
5285 if (! capable(CAP_NET_ADMIN
))
5288 if (rid
< 0xfc00 || rid
> 0xffff)
5291 if (orinoco_lock(priv
, &flags
) != 0)
5294 err
= hermes_read_ltv(hw
, USER_BAP
, rid
, MAX_RID_LEN
, &length
,
5299 data
->length
= min_t(u16
, HERMES_RECLEN_TO_BYTES(length
),
5303 orinoco_unlock(priv
, &flags
);
5307 /* Trigger a scan (look for other cells in the vicinity) */
5308 static int orinoco_ioctl_setscan(struct net_device
*dev
,
5309 struct iw_request_info
*info
,
5310 struct iw_point
*srq
,
5313 struct orinoco_private
*priv
= netdev_priv(dev
);
5314 hermes_t
*hw
= &priv
->hw
;
5315 struct iw_scan_req
*si
= (struct iw_scan_req
*) extra
;
5317 unsigned long flags
;
5319 /* Note : you may have realised that, as this is a SET operation,
5320 * this is privileged and therefore a normal user can't
5322 * This is not an error, while the device perform scanning,
5323 * traffic doesn't flow, so it's a perfect DoS...
5326 if (orinoco_lock(priv
, &flags
) != 0)
5329 /* Scanning with port 0 disabled would fail */
5330 if (!netif_running(dev
)) {
5335 /* In monitor mode, the scan results are always empty.
5336 * Probe responses are passed to the driver as received
5337 * frames and could be processed in software. */
5338 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
5343 /* Note : because we don't lock out the irq handler, the way
5344 * we access scan variables in priv is critical.
5345 * o scan_inprogress : not touched by irq handler
5346 * o scan_mode : not touched by irq handler
5347 * Before modifying anything on those variables, please think hard !
5351 priv
->scan_mode
= srq
->flags
;
5353 /* Always trigger scanning, even if it's in progress.
5354 * This way, if the info frame get lost, we will recover somewhat
5355 * gracefully - Jean II */
5357 if (priv
->has_hostscan
) {
5358 switch (priv
->firmware_type
) {
5359 case FIRMWARE_TYPE_SYMBOL
:
5360 err
= hermes_write_wordrec(hw
, USER_BAP
,
5361 HERMES_RID_CNFHOSTSCAN_SYMBOL
,
5362 HERMES_HOSTSCAN_SYMBOL_ONCE
|
5363 HERMES_HOSTSCAN_SYMBOL_BCAST
);
5365 case FIRMWARE_TYPE_INTERSIL
: {
5368 req
[0] = cpu_to_le16(0x3fff); /* All channels */
5369 req
[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
5370 req
[2] = 0; /* Any ESSID */
5371 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
5372 HERMES_RID_CNFHOSTSCAN
, &req
);
5375 case FIRMWARE_TYPE_AGERE
:
5376 if (priv
->scan_mode
& IW_SCAN_THIS_ESSID
) {
5377 struct hermes_idstring idbuf
;
5378 size_t len
= min(sizeof(idbuf
.val
),
5379 (size_t) si
->essid_len
);
5380 idbuf
.len
= cpu_to_le16(len
);
5381 memcpy(idbuf
.val
, si
->essid
, len
);
5383 err
= hermes_write_ltv(hw
, USER_BAP
,
5384 HERMES_RID_CNFSCANSSID_AGERE
,
5385 HERMES_BYTES_TO_RECLEN(len
+ 2),
5388 err
= hermes_write_wordrec(hw
, USER_BAP
,
5389 HERMES_RID_CNFSCANSSID_AGERE
,
5394 if (priv
->has_ext_scan
) {
5395 /* Clear scan results at the start of
5396 * an extended scan */
5397 orinoco_clear_scan_results(priv
,
5398 msecs_to_jiffies(15000));
5400 /* TODO: Is this available on older firmware?
5401 * Can we use it to scan specific channels
5402 * for IW_SCAN_THIS_FREQ? */
5403 err
= hermes_write_wordrec(hw
, USER_BAP
,
5404 HERMES_RID_CNFSCANCHANNELS2GHZ
,
5409 err
= hermes_inquire(hw
,
5410 HERMES_INQ_CHANNELINFO
);
5412 err
= hermes_inquire(hw
, HERMES_INQ_SCAN
);
5416 err
= hermes_inquire(hw
, HERMES_INQ_SCAN
);
5418 /* One more client */
5420 priv
->scan_inprogress
= 1;
5423 orinoco_unlock(priv
, &flags
);
5427 #define MAX_CUSTOM_LEN 64
5429 /* Translate scan data returned from the card to a card independant
5430 * format that the Wireless Tools will understand - Jean II */
5431 static inline char *orinoco_translate_scan(struct net_device
*dev
,
5432 struct iw_request_info
*info
,
5435 union hermes_scan_info
*bss
,
5436 unsigned int last_scanned
)
5438 struct orinoco_private
*priv
= netdev_priv(dev
);
5441 struct iw_event iwe
; /* Temporary buffer */
5442 char custom
[MAX_CUSTOM_LEN
];
5444 memset(&iwe
, 0, sizeof(iwe
));
5446 /* First entry *MUST* be the AP MAC address */
5447 iwe
.cmd
= SIOCGIWAP
;
5448 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
5449 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->a
.bssid
, ETH_ALEN
);
5450 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5451 &iwe
, IW_EV_ADDR_LEN
);
5453 /* Other entries will be displayed in the order we give them */
5456 iwe
.u
.data
.length
= le16_to_cpu(bss
->a
.essid_len
);
5457 if (iwe
.u
.data
.length
> 32)
5458 iwe
.u
.data
.length
= 32;
5459 iwe
.cmd
= SIOCGIWESSID
;
5460 iwe
.u
.data
.flags
= 1;
5461 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5462 &iwe
, bss
->a
.essid
);
5465 iwe
.cmd
= SIOCGIWMODE
;
5466 capabilities
= le16_to_cpu(bss
->a
.capabilities
);
5467 if (capabilities
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)) {
5468 if (capabilities
& WLAN_CAPABILITY_ESS
)
5469 iwe
.u
.mode
= IW_MODE_MASTER
;
5471 iwe
.u
.mode
= IW_MODE_ADHOC
;
5472 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5473 &iwe
, IW_EV_UINT_LEN
);
5476 channel
= bss
->s
.channel
;
5477 if ((channel
>= 1) && (channel
<= NUM_CHANNELS
)) {
5478 /* Add channel and frequency */
5479 iwe
.cmd
= SIOCGIWFREQ
;
5480 iwe
.u
.freq
.m
= channel
;
5482 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5483 &iwe
, IW_EV_FREQ_LEN
);
5485 iwe
.u
.freq
.m
= channel_frequency
[channel
-1] * 100000;
5487 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5488 &iwe
, IW_EV_FREQ_LEN
);
5491 /* Add quality statistics. level and noise in dB. No link quality */
5493 iwe
.u
.qual
.updated
= IW_QUAL_DBM
| IW_QUAL_QUAL_INVALID
;
5494 iwe
.u
.qual
.level
= (__u8
) le16_to_cpu(bss
->a
.level
) - 0x95;
5495 iwe
.u
.qual
.noise
= (__u8
) le16_to_cpu(bss
->a
.noise
) - 0x95;
5496 /* Wireless tools prior to 27.pre22 will show link quality
5497 * anyway, so we provide a reasonable value. */
5498 if (iwe
.u
.qual
.level
> iwe
.u
.qual
.noise
)
5499 iwe
.u
.qual
.qual
= iwe
.u
.qual
.level
- iwe
.u
.qual
.noise
;
5501 iwe
.u
.qual
.qual
= 0;
5502 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5503 &iwe
, IW_EV_QUAL_LEN
);
5505 /* Add encryption capability */
5506 iwe
.cmd
= SIOCGIWENCODE
;
5507 if (capabilities
& WLAN_CAPABILITY_PRIVACY
)
5508 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
5510 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
5511 iwe
.u
.data
.length
= 0;
5512 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5515 /* Bit rate is not available in Lucent/Agere firmwares */
5516 if (priv
->firmware_type
!= FIRMWARE_TYPE_AGERE
) {
5517 char *current_val
= current_ev
+ iwe_stream_lcp_len(info
);
5521 if (priv
->firmware_type
== FIRMWARE_TYPE_SYMBOL
)
5526 iwe
.cmd
= SIOCGIWRATE
;
5527 /* Those two flags are ignored... */
5528 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
5530 for (i
= 0; i
< 10; i
+= step
) {
5531 /* NULL terminated */
5532 if (bss
->p
.rates
[i
] == 0x0)
5534 /* Bit rate given in 500 kb/s units (+ 0x80) */
5535 iwe
.u
.bitrate
.value
=
5536 ((bss
->p
.rates
[i
] & 0x7f) * 500000);
5537 current_val
= iwe_stream_add_value(info
, current_ev
,
5542 /* Check if we added any event */
5543 if ((current_val
- current_ev
) > iwe_stream_lcp_len(info
))
5544 current_ev
= current_val
;
5547 /* Beacon interval */
5548 iwe
.cmd
= IWEVCUSTOM
;
5549 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5551 le16_to_cpu(bss
->a
.beacon_interv
));
5552 if (iwe
.u
.data
.length
)
5553 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5557 iwe
.cmd
= IWEVCUSTOM
;
5558 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5561 if (iwe
.u
.data
.length
)
5562 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5565 /* Add EXTRA: Age to display seconds since last beacon/probe response
5566 * for given network. */
5567 iwe
.cmd
= IWEVCUSTOM
;
5568 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5569 " Last beacon: %dms ago",
5570 jiffies_to_msecs(jiffies
- last_scanned
));
5571 if (iwe
.u
.data
.length
)
5572 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5578 static inline char *orinoco_translate_ext_scan(struct net_device
*dev
,
5579 struct iw_request_info
*info
,
5582 struct agere_ext_scan_info
*bss
,
5583 unsigned int last_scanned
)
5587 struct iw_event iwe
; /* Temporary buffer */
5588 char custom
[MAX_CUSTOM_LEN
];
5591 memset(&iwe
, 0, sizeof(iwe
));
5593 /* First entry *MUST* be the AP MAC address */
5594 iwe
.cmd
= SIOCGIWAP
;
5595 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
5596 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
5597 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5598 &iwe
, IW_EV_ADDR_LEN
);
5600 /* Other entries will be displayed in the order we give them */
5604 iwe
.u
.data
.length
= ie
[1];
5605 if (iwe
.u
.data
.length
) {
5606 if (iwe
.u
.data
.length
> 32)
5607 iwe
.u
.data
.length
= 32;
5608 iwe
.cmd
= SIOCGIWESSID
;
5609 iwe
.u
.data
.flags
= 1;
5610 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5615 capabilities
= le16_to_cpu(bss
->capabilities
);
5616 if (capabilities
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)) {
5617 iwe
.cmd
= SIOCGIWMODE
;
5618 if (capabilities
& WLAN_CAPABILITY_ESS
)
5619 iwe
.u
.mode
= IW_MODE_MASTER
;
5621 iwe
.u
.mode
= IW_MODE_ADHOC
;
5622 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5623 &iwe
, IW_EV_UINT_LEN
);
5626 ie
= orinoco_get_ie(bss
->data
, sizeof(bss
->data
), MFIE_TYPE_DS_SET
);
5627 channel
= ie
? ie
[2] : 0;
5628 if ((channel
>= 1) && (channel
<= NUM_CHANNELS
)) {
5629 /* Add channel and frequency */
5630 iwe
.cmd
= SIOCGIWFREQ
;
5631 iwe
.u
.freq
.m
= channel
;
5633 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5634 &iwe
, IW_EV_FREQ_LEN
);
5636 iwe
.u
.freq
.m
= channel_frequency
[channel
-1] * 100000;
5638 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5639 &iwe
, IW_EV_FREQ_LEN
);
5642 /* Add quality statistics. level and noise in dB. No link quality */
5644 iwe
.u
.qual
.updated
= IW_QUAL_DBM
| IW_QUAL_QUAL_INVALID
;
5645 iwe
.u
.qual
.level
= bss
->level
- 0x95;
5646 iwe
.u
.qual
.noise
= bss
->noise
- 0x95;
5647 /* Wireless tools prior to 27.pre22 will show link quality
5648 * anyway, so we provide a reasonable value. */
5649 if (iwe
.u
.qual
.level
> iwe
.u
.qual
.noise
)
5650 iwe
.u
.qual
.qual
= iwe
.u
.qual
.level
- iwe
.u
.qual
.noise
;
5652 iwe
.u
.qual
.qual
= 0;
5653 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5654 &iwe
, IW_EV_QUAL_LEN
);
5656 /* Add encryption capability */
5657 iwe
.cmd
= SIOCGIWENCODE
;
5658 if (capabilities
& WLAN_CAPABILITY_PRIVACY
)
5659 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
5661 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
5662 iwe
.u
.data
.length
= 0;
5663 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5667 ie
= orinoco_get_wpa_ie(bss
->data
, sizeof(bss
->data
));
5669 iwe
.cmd
= IWEVGENIE
;
5670 iwe
.u
.data
.length
= ie
[1] + 2;
5671 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5676 ie
= orinoco_get_ie(bss
->data
, sizeof(bss
->data
), MFIE_TYPE_RSN
);
5678 iwe
.cmd
= IWEVGENIE
;
5679 iwe
.u
.data
.length
= ie
[1] + 2;
5680 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5684 ie
= orinoco_get_ie(bss
->data
, sizeof(bss
->data
), MFIE_TYPE_RATES
);
5686 char *p
= current_ev
+ iwe_stream_lcp_len(info
);
5689 iwe
.cmd
= SIOCGIWRATE
;
5690 /* Those two flags are ignored... */
5691 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
5693 for (i
= 2; i
< (ie
[1] + 2); i
++) {
5694 iwe
.u
.bitrate
.value
= ((ie
[i
] & 0x7F) * 500000);
5695 p
= iwe_stream_add_value(info
, current_ev
, p
, end_buf
,
5696 &iwe
, IW_EV_PARAM_LEN
);
5698 /* Check if we added any event */
5699 if (p
> (current_ev
+ iwe_stream_lcp_len(info
)))
5704 iwe
.cmd
= IWEVCUSTOM
;
5706 snprintf(custom
, MAX_CUSTOM_LEN
, "tsf=%016llx",
5707 (unsigned long long) le64_to_cpu(bss
->timestamp
));
5708 if (iwe
.u
.data
.length
)
5709 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5712 /* Beacon interval */
5713 iwe
.cmd
= IWEVCUSTOM
;
5714 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5716 le16_to_cpu(bss
->beacon_interval
));
5717 if (iwe
.u
.data
.length
)
5718 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5722 iwe
.cmd
= IWEVCUSTOM
;
5723 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5726 if (iwe
.u
.data
.length
)
5727 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5730 /* Add EXTRA: Age to display seconds since last beacon/probe response
5731 * for given network. */
5732 iwe
.cmd
= IWEVCUSTOM
;
5733 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5734 " Last beacon: %dms ago",
5735 jiffies_to_msecs(jiffies
- last_scanned
));
5736 if (iwe
.u
.data
.length
)
5737 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5743 /* Return results of a scan */
5744 static int orinoco_ioctl_getscan(struct net_device
*dev
,
5745 struct iw_request_info
*info
,
5746 struct iw_point
*srq
,
5749 struct orinoco_private
*priv
= netdev_priv(dev
);
5751 unsigned long flags
;
5752 char *current_ev
= extra
;
5754 if (orinoco_lock(priv
, &flags
) != 0)
5757 if (priv
->scan_inprogress
) {
5758 /* Important note : we don't want to block the caller
5759 * until results are ready for various reasons.
5760 * First, managing wait queues is complex and racy.
5761 * Second, we grab some rtnetlink lock before comming
5762 * here (in dev_ioctl()).
5763 * Third, we generate an Wireless Event, so the
5764 * caller can wait itself on that - Jean II */
5769 if (priv
->has_ext_scan
) {
5770 struct xbss_element
*bss
;
5772 list_for_each_entry(bss
, &priv
->bss_list
, list
) {
5773 /* Translate this entry to WE format */
5775 orinoco_translate_ext_scan(dev
, info
,
5777 extra
+ srq
->length
,
5781 /* Check if there is space for one more entry */
5782 if ((extra
+ srq
->length
- current_ev
)
5783 <= IW_EV_ADDR_LEN
) {
5784 /* Ask user space to try again with a
5792 struct bss_element
*bss
;
5794 list_for_each_entry(bss
, &priv
->bss_list
, list
) {
5795 /* Translate this entry to WE format */
5796 current_ev
= orinoco_translate_scan(dev
, info
,
5798 extra
+ srq
->length
,
5802 /* Check if there is space for one more entry */
5803 if ((extra
+ srq
->length
- current_ev
)
5804 <= IW_EV_ADDR_LEN
) {
5805 /* Ask user space to try again with a
5813 srq
->length
= (current_ev
- extra
);
5814 srq
->flags
= (__u16
) priv
->scan_mode
;
5817 orinoco_unlock(priv
, &flags
);
5821 /* Commit handler, called after set operations */
5822 static int orinoco_ioctl_commit(struct net_device
*dev
,
5823 struct iw_request_info
*info
,
5827 struct orinoco_private
*priv
= netdev_priv(dev
);
5828 struct hermes
*hw
= &priv
->hw
;
5829 unsigned long flags
;
5835 if (priv
->broken_disableport
) {
5836 orinoco_reset(&priv
->reset_work
);
5840 if (orinoco_lock(priv
, &flags
) != 0)
5843 err
= hermes_disable_port(hw
, 0);
5845 printk(KERN_WARNING
"%s: Unable to disable port "
5846 "while reconfiguring card\n", dev
->name
);
5847 priv
->broken_disableport
= 1;
5851 err
= __orinoco_program_rids(dev
);
5853 printk(KERN_WARNING
"%s: Unable to reconfigure card\n",
5858 err
= hermes_enable_port(hw
, 0);
5860 printk(KERN_WARNING
"%s: Unable to enable port while reconfiguring card\n",
5867 printk(KERN_WARNING
"%s: Resetting instead...\n", dev
->name
);
5868 schedule_work(&priv
->reset_work
);
5872 orinoco_unlock(priv
, &flags
);
5876 static const struct iw_priv_args orinoco_privtab
[] = {
5877 { SIOCIWFIRSTPRIV
+ 0x0, 0, 0, "force_reset" },
5878 { SIOCIWFIRSTPRIV
+ 0x1, 0, 0, "card_reset" },
5879 { SIOCIWFIRSTPRIV
+ 0x2, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5881 { SIOCIWFIRSTPRIV
+ 0x3, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5883 { SIOCIWFIRSTPRIV
+ 0x4, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5884 0, "set_preamble" },
5885 { SIOCIWFIRSTPRIV
+ 0x5, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5887 { SIOCIWFIRSTPRIV
+ 0x6, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5888 0, "set_ibssport" },
5889 { SIOCIWFIRSTPRIV
+ 0x7, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5891 { SIOCIWFIRSTPRIV
+ 0x9, 0, IW_PRIV_TYPE_BYTE
| MAX_RID_LEN
,
5897 * Structures to export the Wireless Handlers
5900 #define STD_IW_HANDLER(id, func) \
5901 [IW_IOCTL_IDX(id)] = (iw_handler) func
5902 static const iw_handler orinoco_handler
[] = {
5903 STD_IW_HANDLER(SIOCSIWCOMMIT
, orinoco_ioctl_commit
),
5904 STD_IW_HANDLER(SIOCGIWNAME
, orinoco_ioctl_getname
),
5905 STD_IW_HANDLER(SIOCSIWFREQ
, orinoco_ioctl_setfreq
),
5906 STD_IW_HANDLER(SIOCGIWFREQ
, orinoco_ioctl_getfreq
),
5907 STD_IW_HANDLER(SIOCSIWMODE
, orinoco_ioctl_setmode
),
5908 STD_IW_HANDLER(SIOCGIWMODE
, orinoco_ioctl_getmode
),
5909 STD_IW_HANDLER(SIOCSIWSENS
, orinoco_ioctl_setsens
),
5910 STD_IW_HANDLER(SIOCGIWSENS
, orinoco_ioctl_getsens
),
5911 STD_IW_HANDLER(SIOCGIWRANGE
, orinoco_ioctl_getiwrange
),
5912 STD_IW_HANDLER(SIOCSIWSPY
, iw_handler_set_spy
),
5913 STD_IW_HANDLER(SIOCGIWSPY
, iw_handler_get_spy
),
5914 STD_IW_HANDLER(SIOCSIWTHRSPY
, iw_handler_set_thrspy
),
5915 STD_IW_HANDLER(SIOCGIWTHRSPY
, iw_handler_get_thrspy
),
5916 STD_IW_HANDLER(SIOCSIWAP
, orinoco_ioctl_setwap
),
5917 STD_IW_HANDLER(SIOCGIWAP
, orinoco_ioctl_getwap
),
5918 STD_IW_HANDLER(SIOCSIWSCAN
, orinoco_ioctl_setscan
),
5919 STD_IW_HANDLER(SIOCGIWSCAN
, orinoco_ioctl_getscan
),
5920 STD_IW_HANDLER(SIOCSIWESSID
, orinoco_ioctl_setessid
),
5921 STD_IW_HANDLER(SIOCGIWESSID
, orinoco_ioctl_getessid
),
5922 STD_IW_HANDLER(SIOCSIWNICKN
, orinoco_ioctl_setnick
),
5923 STD_IW_HANDLER(SIOCGIWNICKN
, orinoco_ioctl_getnick
),
5924 STD_IW_HANDLER(SIOCSIWRATE
, orinoco_ioctl_setrate
),
5925 STD_IW_HANDLER(SIOCGIWRATE
, orinoco_ioctl_getrate
),
5926 STD_IW_HANDLER(SIOCSIWRTS
, orinoco_ioctl_setrts
),
5927 STD_IW_HANDLER(SIOCGIWRTS
, orinoco_ioctl_getrts
),
5928 STD_IW_HANDLER(SIOCSIWFRAG
, orinoco_ioctl_setfrag
),
5929 STD_IW_HANDLER(SIOCGIWFRAG
, orinoco_ioctl_getfrag
),
5930 STD_IW_HANDLER(SIOCGIWRETRY
, orinoco_ioctl_getretry
),
5931 STD_IW_HANDLER(SIOCSIWENCODE
, orinoco_ioctl_setiwencode
),
5932 STD_IW_HANDLER(SIOCGIWENCODE
, orinoco_ioctl_getiwencode
),
5933 STD_IW_HANDLER(SIOCSIWPOWER
, orinoco_ioctl_setpower
),
5934 STD_IW_HANDLER(SIOCGIWPOWER
, orinoco_ioctl_getpower
),
5935 STD_IW_HANDLER(SIOCSIWGENIE
, orinoco_ioctl_set_genie
),
5936 STD_IW_HANDLER(SIOCGIWGENIE
, orinoco_ioctl_get_genie
),
5937 STD_IW_HANDLER(SIOCSIWMLME
, orinoco_ioctl_set_mlme
),
5938 STD_IW_HANDLER(SIOCSIWAUTH
, orinoco_ioctl_set_auth
),
5939 STD_IW_HANDLER(SIOCGIWAUTH
, orinoco_ioctl_get_auth
),
5940 STD_IW_HANDLER(SIOCSIWENCODEEXT
, orinoco_ioctl_set_encodeext
),
5941 STD_IW_HANDLER(SIOCGIWENCODEEXT
, orinoco_ioctl_get_encodeext
),
5946 Added typecasting since we no longer use iwreq_data -- Moustafa
5948 static const iw_handler orinoco_private_handler
[] = {
5949 [0] = (iw_handler
) orinoco_ioctl_reset
,
5950 [1] = (iw_handler
) orinoco_ioctl_reset
,
5951 [2] = (iw_handler
) orinoco_ioctl_setport3
,
5952 [3] = (iw_handler
) orinoco_ioctl_getport3
,
5953 [4] = (iw_handler
) orinoco_ioctl_setpreamble
,
5954 [5] = (iw_handler
) orinoco_ioctl_getpreamble
,
5955 [6] = (iw_handler
) orinoco_ioctl_setibssport
,
5956 [7] = (iw_handler
) orinoco_ioctl_getibssport
,
5957 [9] = (iw_handler
) orinoco_ioctl_getrid
,
5960 static const struct iw_handler_def orinoco_handler_def
= {
5961 .num_standard
= ARRAY_SIZE(orinoco_handler
),
5962 .num_private
= ARRAY_SIZE(orinoco_private_handler
),
5963 .num_private_args
= ARRAY_SIZE(orinoco_privtab
),
5964 .standard
= orinoco_handler
,
5965 .private = orinoco_private_handler
,
5966 .private_args
= orinoco_privtab
,
5967 .get_wireless_stats
= orinoco_get_wireless_stats
,
5970 static void orinoco_get_drvinfo(struct net_device
*dev
,
5971 struct ethtool_drvinfo
*info
)
5973 struct orinoco_private
*priv
= netdev_priv(dev
);
5975 strncpy(info
->driver
, DRIVER_NAME
, sizeof(info
->driver
) - 1);
5976 strncpy(info
->version
, DRIVER_VERSION
, sizeof(info
->version
) - 1);
5977 strncpy(info
->fw_version
, priv
->fw_name
, sizeof(info
->fw_version
) - 1);
5978 if (dev
->dev
.parent
)
5979 strncpy(info
->bus_info
, dev
->dev
.parent
->bus_id
,
5980 sizeof(info
->bus_info
) - 1);
5982 snprintf(info
->bus_info
, sizeof(info
->bus_info
) - 1,
5983 "PCMCIA %p", priv
->hw
.iobase
);
5986 static const struct ethtool_ops orinoco_ethtool_ops
= {
5987 .get_drvinfo
= orinoco_get_drvinfo
,
5988 .get_link
= ethtool_op_get_link
,
5991 /********************************************************************/
5992 /* Module initialization */
5993 /********************************************************************/
5995 EXPORT_SYMBOL(alloc_orinocodev
);
5996 EXPORT_SYMBOL(free_orinocodev
);
5998 EXPORT_SYMBOL(__orinoco_up
);
5999 EXPORT_SYMBOL(__orinoco_down
);
6000 EXPORT_SYMBOL(orinoco_reinit_firmware
);
6002 EXPORT_SYMBOL(orinoco_interrupt
);
6004 /* Can't be declared "const" or the whole __initdata section will
6006 static char version
[] __initdata
= DRIVER_NAME
" " DRIVER_VERSION
6007 " (David Gibson <hermes@gibson.dropbear.id.au>, "
6008 "Pavel Roskin <proski@gnu.org>, et al)";
6010 static int __init
init_orinoco(void)
6012 printk(KERN_DEBUG
"%s\n", version
);
6016 static void __exit
exit_orinoco(void)
6020 module_init(init_orinoco
);
6021 module_exit(exit_orinoco
);