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
= hw
->ops
->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
= hw
->ops
->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
= hw
->ops
->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
= hw
->ops
->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
= hw
->ops
->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
= hw
->ops
->cmd_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
= hw
->ops
->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
);
1252 stats
->rx_length_errors
++;
1256 skb
= dev_alloc_skb(hdrlen
+ datalen
);
1258 printk(KERN_WARNING
"%s: Cannot allocate skb for monitor frame\n",
1264 /* Copy the 802.11 header to the skb */
1265 memcpy(skb_put(skb
, hdrlen
), &(desc
->frame_ctl
), hdrlen
);
1266 skb_reset_mac_header(skb
);
1268 /* If any, copy the data from the card to the skb */
1270 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, skb_put(skb
, datalen
),
1271 ALIGN(datalen
, 2), rxfid
,
1272 HERMES_802_2_OFFSET
);
1274 printk(KERN_ERR
"%s: error %d reading monitor frame\n",
1281 skb
->ip_summed
= CHECKSUM_NONE
;
1282 skb
->pkt_type
= PACKET_OTHERHOST
;
1283 skb
->protocol
= __constant_htons(ETH_P_802_2
);
1285 dev
->last_rx
= jiffies
;
1286 stats
->rx_packets
++;
1287 stats
->rx_bytes
+= skb
->len
;
1293 dev_kfree_skb_irq(skb
);
1296 stats
->rx_dropped
++;
1299 /* Get tsc from the firmware */
1300 static int orinoco_hw_get_tkip_iv(struct orinoco_private
*priv
, int key
,
1303 hermes_t
*hw
= &priv
->hw
;
1305 u8 tsc_arr
[4][IW_ENCODE_SEQ_MAX_SIZE
];
1307 if ((key
< 0) || (key
> 4))
1310 err
= hw
->ops
->read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENT_TKIP_IV
,
1311 sizeof(tsc_arr
), NULL
, &tsc_arr
);
1313 memcpy(tsc
, &tsc_arr
[key
][0], sizeof(tsc_arr
[0]));
1318 static void __orinoco_ev_rx(struct net_device
*dev
, hermes_t
*hw
)
1320 struct orinoco_private
*priv
= netdev_priv(dev
);
1321 struct net_device_stats
*stats
= &priv
->stats
;
1322 struct iw_statistics
*wstats
= &priv
->wstats
;
1323 struct sk_buff
*skb
= NULL
;
1326 struct hermes_rx_descriptor
*desc
;
1327 struct orinoco_rx_data
*rx_data
;
1330 desc
= kmalloc(sizeof(*desc
), GFP_ATOMIC
);
1333 "%s: Can't allocate space for RX descriptor\n",
1338 rxfid
= hermes_read_regn(hw
, RXFID
);
1340 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, desc
, sizeof(*desc
),
1343 printk(KERN_ERR
"%s: error %d reading Rx descriptor. "
1344 "Frame dropped.\n", dev
->name
, err
);
1348 status
= le16_to_cpu(desc
->status
);
1350 if (status
& HERMES_RXSTAT_BADCRC
) {
1351 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
1353 stats
->rx_crc_errors
++;
1357 /* Handle frames in monitor mode */
1358 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
1359 orinoco_rx_monitor(dev
, rxfid
, desc
);
1363 if (status
& HERMES_RXSTAT_UNDECRYPTABLE
) {
1364 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1366 wstats
->discard
.code
++;
1370 length
= le16_to_cpu(desc
->data_len
);
1373 if (length
< 3) { /* No for even an 802.2 LLC header */
1374 /* At least on Symbol firmware with PCF we get quite a
1375 lot of these legitimately - Poll frames with no
1379 if (length
> IEEE80211_DATA_LEN
) {
1380 printk(KERN_WARNING
"%s: Oversized frame received (%d bytes)\n",
1382 stats
->rx_length_errors
++;
1386 /* Payload size does not include Michael MIC. Increase payload
1387 * size to read it together with the data. */
1388 if (status
& HERMES_RXSTAT_MIC
)
1389 length
+= MICHAEL_MIC_LEN
;
1391 /* We need space for the packet data itself, plus an ethernet
1392 header, plus 2 bytes so we can align the IP header on a
1393 32bit boundary, plus 1 byte so we can read in odd length
1394 packets from the card, which has an IO granularity of 16
1396 skb
= dev_alloc_skb(length
+ETH_HLEN
+2+1);
1398 printk(KERN_WARNING
"%s: Can't allocate skb for Rx\n",
1403 /* We'll prepend the header, so reserve space for it. The worst
1404 case is no decapsulation, when 802.3 header is prepended and
1405 nothing is removed. 2 is for aligning the IP header. */
1406 skb_reserve(skb
, ETH_HLEN
+ 2);
1408 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, skb_put(skb
, length
),
1409 ALIGN(length
, 2), rxfid
,
1410 HERMES_802_2_OFFSET
);
1412 printk(KERN_ERR
"%s: error %d reading frame. "
1413 "Frame dropped.\n", dev
->name
, err
);
1417 /* Add desc and skb to rx queue */
1418 rx_data
= kzalloc(sizeof(*rx_data
), GFP_ATOMIC
);
1420 printk(KERN_WARNING
"%s: Can't allocate RX packet\n",
1424 rx_data
->desc
= desc
;
1426 list_add_tail(&rx_data
->list
, &priv
->rx_list
);
1427 tasklet_schedule(&priv
->rx_tasklet
);
1432 dev_kfree_skb_irq(skb
);
1435 stats
->rx_dropped
++;
1440 static void orinoco_rx(struct net_device
*dev
,
1441 struct hermes_rx_descriptor
*desc
,
1442 struct sk_buff
*skb
)
1444 struct orinoco_private
*priv
= netdev_priv(dev
);
1445 struct net_device_stats
*stats
= &priv
->stats
;
1450 status
= le16_to_cpu(desc
->status
);
1451 length
= le16_to_cpu(desc
->data_len
);
1452 fc
= le16_to_cpu(desc
->frame_ctl
);
1454 /* Calculate and check MIC */
1455 if (status
& HERMES_RXSTAT_MIC
) {
1456 int key_id
= ((status
& HERMES_RXSTAT_MIC_KEY_ID
) >>
1457 HERMES_MIC_KEY_ID_SHIFT
);
1458 u8 mic
[MICHAEL_MIC_LEN
];
1460 u8
*src
= (fc
& IEEE80211_FCTL_FROMDS
) ?
1461 desc
->addr3
: desc
->addr2
;
1463 /* Extract Michael MIC from payload */
1464 rxmic
= skb
->data
+ skb
->len
- MICHAEL_MIC_LEN
;
1466 skb_trim(skb
, skb
->len
- MICHAEL_MIC_LEN
);
1467 length
-= MICHAEL_MIC_LEN
;
1469 michael_mic(priv
->rx_tfm_mic
,
1470 priv
->tkip_key
[key_id
].rx_mic
,
1473 0, /* priority or QoS? */
1478 if (memcmp(mic
, rxmic
,
1480 union iwreq_data wrqu
;
1481 struct iw_michaelmicfailure wxmic
;
1482 DECLARE_MAC_BUF(mac
);
1484 printk(KERN_WARNING
"%s: "
1485 "Invalid Michael MIC in data frame from %s, "
1487 dev
->name
, print_mac(mac
, src
), key_id
);
1489 /* TODO: update stats */
1491 /* Notify userspace */
1492 memset(&wxmic
, 0, sizeof(wxmic
));
1493 wxmic
.flags
= key_id
& IW_MICFAILURE_KEY_ID
;
1494 wxmic
.flags
|= (desc
->addr1
[0] & 1) ?
1495 IW_MICFAILURE_GROUP
: IW_MICFAILURE_PAIRWISE
;
1496 wxmic
.src_addr
.sa_family
= ARPHRD_ETHER
;
1497 memcpy(wxmic
.src_addr
.sa_data
, src
, ETH_ALEN
);
1499 (void) orinoco_hw_get_tkip_iv(priv
, key_id
,
1502 memset(&wrqu
, 0, sizeof(wrqu
));
1503 wrqu
.data
.length
= sizeof(wxmic
);
1504 wireless_send_event(dev
, IWEVMICHAELMICFAILURE
, &wrqu
,
1511 /* Handle decapsulation
1512 * In most cases, the firmware tell us about SNAP frames.
1513 * For some reason, the SNAP frames sent by LinkSys APs
1514 * are not properly recognised by most firmwares.
1515 * So, check ourselves */
1516 if (length
>= ENCAPS_OVERHEAD
&&
1517 (((status
& HERMES_RXSTAT_MSGTYPE
) == HERMES_RXSTAT_1042
) ||
1518 ((status
& HERMES_RXSTAT_MSGTYPE
) == HERMES_RXSTAT_TUNNEL
) ||
1519 is_ethersnap(skb
->data
))) {
1520 /* These indicate a SNAP within 802.2 LLC within
1521 802.11 frame which we'll need to de-encapsulate to
1522 the original EthernetII frame. */
1523 hdr
= (struct ethhdr
*)skb_push(skb
, ETH_HLEN
- ENCAPS_OVERHEAD
);
1525 /* 802.3 frame - prepend 802.3 header as is */
1526 hdr
= (struct ethhdr
*)skb_push(skb
, ETH_HLEN
);
1527 hdr
->h_proto
= htons(length
);
1529 memcpy(hdr
->h_dest
, desc
->addr1
, ETH_ALEN
);
1530 if (fc
& IEEE80211_FCTL_FROMDS
)
1531 memcpy(hdr
->h_source
, desc
->addr3
, ETH_ALEN
);
1533 memcpy(hdr
->h_source
, desc
->addr2
, ETH_ALEN
);
1535 dev
->last_rx
= jiffies
;
1536 skb
->protocol
= eth_type_trans(skb
, dev
);
1537 skb
->ip_summed
= CHECKSUM_NONE
;
1538 if (fc
& IEEE80211_FCTL_TODS
)
1539 skb
->pkt_type
= PACKET_OTHERHOST
;
1541 /* Process the wireless stats if needed */
1542 orinoco_stat_gather(dev
, skb
, desc
);
1544 /* Pass the packet to the networking stack */
1546 stats
->rx_packets
++;
1547 stats
->rx_bytes
+= length
;
1554 stats
->rx_dropped
++;
1557 static void orinoco_rx_isr_tasklet(unsigned long data
)
1559 struct net_device
*dev
= (struct net_device
*) data
;
1560 struct orinoco_private
*priv
= netdev_priv(dev
);
1561 struct orinoco_rx_data
*rx_data
, *temp
;
1562 struct hermes_rx_descriptor
*desc
;
1563 struct sk_buff
*skb
;
1565 /* extract desc and skb from queue */
1566 list_for_each_entry_safe(rx_data
, temp
, &priv
->rx_list
, list
) {
1567 desc
= rx_data
->desc
;
1569 list_del(&rx_data
->list
);
1572 orinoco_rx(dev
, desc
, skb
);
1578 /********************************************************************/
1579 /* Rx path (info frames) */
1580 /********************************************************************/
1582 static void print_linkstatus(struct net_device
*dev
, u16 status
)
1586 if (suppress_linkstatus
)
1590 case HERMES_LINKSTATUS_NOT_CONNECTED
:
1591 s
= "Not Connected";
1593 case HERMES_LINKSTATUS_CONNECTED
:
1596 case HERMES_LINKSTATUS_DISCONNECTED
:
1599 case HERMES_LINKSTATUS_AP_CHANGE
:
1602 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE
:
1603 s
= "AP Out of Range";
1605 case HERMES_LINKSTATUS_AP_IN_RANGE
:
1608 case HERMES_LINKSTATUS_ASSOC_FAILED
:
1609 s
= "Association Failed";
1615 printk(KERN_INFO
"%s: New link status: %s (%04x)\n",
1616 dev
->name
, s
, status
);
1619 /* Search scan results for requested BSSID, join it if found */
1620 static void orinoco_join_ap(struct work_struct
*work
)
1622 struct orinoco_private
*priv
=
1623 container_of(work
, struct orinoco_private
, join_work
);
1624 struct net_device
*dev
= priv
->ndev
;
1625 struct hermes
*hw
= &priv
->hw
;
1627 unsigned long flags
;
1631 } __attribute__ ((packed
)) req
;
1632 const int atom_len
= offsetof(struct prism2_scan_apinfo
, atim
);
1633 struct prism2_scan_apinfo
*atom
= NULL
;
1639 /* Allocate buffer for scan results */
1640 buf
= kmalloc(MAX_SCAN_LEN
, GFP_KERNEL
);
1644 if (orinoco_lock(priv
, &flags
) != 0)
1647 /* Sanity checks in case user changed something in the meantime */
1648 if (! priv
->bssid_fixed
)
1651 if (strlen(priv
->desired_essid
) == 0)
1654 /* Read scan results from the firmware */
1655 err
= hw
->ops
->read_ltv(hw
, USER_BAP
,
1656 HERMES_RID_SCANRESULTSTABLE
,
1657 MAX_SCAN_LEN
, &len
, buf
);
1659 printk(KERN_ERR
"%s: Cannot read scan results\n",
1664 len
= HERMES_RECLEN_TO_BYTES(len
);
1666 /* Go through the scan results looking for the channel of the AP
1667 * we were requested to join */
1668 for (; offset
+ atom_len
<= len
; offset
+= atom_len
) {
1669 atom
= (struct prism2_scan_apinfo
*) (buf
+ offset
);
1670 if (memcmp(&atom
->bssid
, priv
->desired_bssid
, ETH_ALEN
) == 0) {
1677 DEBUG(1, "%s: Requested AP not found in scan results\n",
1682 memcpy(req
.bssid
, priv
->desired_bssid
, ETH_ALEN
);
1683 req
.channel
= atom
->channel
; /* both are little-endian */
1684 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
, HERMES_RID_CNFJOINREQUEST
,
1687 printk(KERN_ERR
"%s: Error issuing join request\n", dev
->name
);
1690 orinoco_unlock(priv
, &flags
);
1696 /* Send new BSSID to userspace */
1697 static void orinoco_send_bssid_wevent(struct orinoco_private
*priv
)
1699 struct net_device
*dev
= priv
->ndev
;
1700 struct hermes
*hw
= &priv
->hw
;
1701 union iwreq_data wrqu
;
1704 err
= hw
->ops
->read_ltv(hw
, IRQ_BAP
, HERMES_RID_CURRENTBSSID
,
1705 ETH_ALEN
, NULL
, wrqu
.ap_addr
.sa_data
);
1709 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1711 /* Send event to user space */
1712 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
1715 static void orinoco_send_assocreqie_wevent(struct orinoco_private
*priv
)
1717 struct net_device
*dev
= priv
->ndev
;
1718 struct hermes
*hw
= &priv
->hw
;
1719 union iwreq_data wrqu
;
1727 err
= hw
->ops
->read_ltv(hw
, IRQ_BAP
, HERMES_RID_CURRENT_ASSOC_REQ_INFO
,
1728 sizeof(buf
), NULL
, &buf
);
1732 ie
= orinoco_get_wpa_ie(buf
, sizeof(buf
));
1734 int rem
= sizeof(buf
) - (ie
- &buf
[0]);
1735 wrqu
.data
.length
= ie
[1] + 2;
1736 if (wrqu
.data
.length
> rem
)
1737 wrqu
.data
.length
= rem
;
1739 if (wrqu
.data
.length
)
1740 /* Send event to user space */
1741 wireless_send_event(dev
, IWEVASSOCREQIE
, &wrqu
, ie
);
1745 static void orinoco_send_assocrespie_wevent(struct orinoco_private
*priv
)
1747 struct net_device
*dev
= priv
->ndev
;
1748 struct hermes
*hw
= &priv
->hw
;
1749 union iwreq_data wrqu
;
1751 u8 buf
[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1757 err
= hw
->ops
->read_ltv(hw
, IRQ_BAP
, HERMES_RID_CURRENT_ASSOC_RESP_INFO
,
1758 sizeof(buf
), NULL
, &buf
);
1762 ie
= orinoco_get_wpa_ie(buf
, sizeof(buf
));
1764 int rem
= sizeof(buf
) - (ie
- &buf
[0]);
1765 wrqu
.data
.length
= ie
[1] + 2;
1766 if (wrqu
.data
.length
> rem
)
1767 wrqu
.data
.length
= rem
;
1769 if (wrqu
.data
.length
)
1770 /* Send event to user space */
1771 wireless_send_event(dev
, IWEVASSOCRESPIE
, &wrqu
, ie
);
1775 static void orinoco_send_wevents(struct work_struct
*work
)
1777 struct orinoco_private
*priv
=
1778 container_of(work
, struct orinoco_private
, wevent_work
);
1779 unsigned long flags
;
1781 if (orinoco_lock(priv
, &flags
) != 0)
1784 orinoco_send_assocreqie_wevent(priv
);
1785 orinoco_send_assocrespie_wevent(priv
);
1786 orinoco_send_bssid_wevent(priv
);
1788 orinoco_unlock(priv
, &flags
);
1791 static inline void orinoco_clear_scan_results(struct orinoco_private
*priv
,
1792 unsigned long scan_age
)
1794 if (priv
->has_ext_scan
) {
1795 struct xbss_element
*bss
;
1796 struct xbss_element
*tmp_bss
;
1798 /* Blow away current list of scan results */
1799 list_for_each_entry_safe(bss
, tmp_bss
, &priv
->bss_list
, list
) {
1801 time_after(jiffies
, bss
->last_scanned
+ scan_age
)) {
1802 list_move_tail(&bss
->list
,
1803 &priv
->bss_free_list
);
1804 /* Don't blow away ->list, just BSS data */
1805 memset(&bss
->bss
, 0, sizeof(bss
->bss
));
1806 bss
->last_scanned
= 0;
1810 struct bss_element
*bss
;
1811 struct bss_element
*tmp_bss
;
1813 /* Blow away current list of scan results */
1814 list_for_each_entry_safe(bss
, tmp_bss
, &priv
->bss_list
, list
) {
1816 time_after(jiffies
, bss
->last_scanned
+ scan_age
)) {
1817 list_move_tail(&bss
->list
,
1818 &priv
->bss_free_list
);
1819 /* Don't blow away ->list, just BSS data */
1820 memset(&bss
->bss
, 0, sizeof(bss
->bss
));
1821 bss
->last_scanned
= 0;
1827 static void orinoco_add_ext_scan_result(struct orinoco_private
*priv
,
1828 struct agere_ext_scan_info
*atom
)
1830 struct xbss_element
*bss
= NULL
;
1833 /* Try to update an existing bss first */
1834 list_for_each_entry(bss
, &priv
->bss_list
, list
) {
1835 if (compare_ether_addr(bss
->bss
.bssid
, atom
->bssid
))
1838 if (bss
->bss
.data
[1] != atom
->data
[1])
1840 if (memcmp(&bss
->bss
.data
[2], &atom
->data
[2],
1847 /* Grab a bss off the free list */
1848 if (!found
&& !list_empty(&priv
->bss_free_list
)) {
1849 bss
= list_entry(priv
->bss_free_list
.next
,
1850 struct xbss_element
, list
);
1851 list_del(priv
->bss_free_list
.next
);
1853 list_add_tail(&bss
->list
, &priv
->bss_list
);
1857 /* Always update the BSS to get latest beacon info */
1858 memcpy(&bss
->bss
, atom
, sizeof(bss
->bss
));
1859 bss
->last_scanned
= jiffies
;
1863 static int orinoco_process_scan_results(struct net_device
*dev
,
1867 struct orinoco_private
*priv
= netdev_priv(dev
);
1868 int offset
; /* In the scan data */
1869 union hermes_scan_info
*atom
;
1872 switch (priv
->firmware_type
) {
1873 case FIRMWARE_TYPE_AGERE
:
1874 atom_len
= sizeof(struct agere_scan_apinfo
);
1877 case FIRMWARE_TYPE_SYMBOL
:
1878 /* Lack of documentation necessitates this hack.
1879 * Different firmwares have 68 or 76 byte long atoms.
1880 * We try modulo first. If the length divides by both,
1881 * we check what would be the channel in the second
1882 * frame for a 68-byte atom. 76-byte atoms have 0 there.
1883 * Valid channel cannot be 0. */
1888 else if (len
>= 1292 && buf
[68] == 0)
1894 case FIRMWARE_TYPE_INTERSIL
:
1896 if (priv
->has_hostscan
) {
1897 atom_len
= le16_to_cpup((__le16
*)buf
);
1898 /* Sanity check for atom_len */
1899 if (atom_len
< sizeof(struct prism2_scan_apinfo
)) {
1900 printk(KERN_ERR
"%s: Invalid atom_len in scan "
1901 "data: %d\n", dev
->name
, atom_len
);
1905 atom_len
= offsetof(struct prism2_scan_apinfo
, atim
);
1911 /* Check that we got an whole number of atoms */
1912 if ((len
- offset
) % atom_len
) {
1913 printk(KERN_ERR
"%s: Unexpected scan data length %d, "
1914 "atom_len %d, offset %d\n", dev
->name
, len
,
1919 orinoco_clear_scan_results(priv
, msecs_to_jiffies(15000));
1921 /* Read the entries one by one */
1922 for (; offset
+ atom_len
<= len
; offset
+= atom_len
) {
1924 struct bss_element
*bss
= NULL
;
1927 atom
= (union hermes_scan_info
*) (buf
+ offset
);
1929 /* Try to update an existing bss first */
1930 list_for_each_entry(bss
, &priv
->bss_list
, list
) {
1931 if (compare_ether_addr(bss
->bss
.a
.bssid
, atom
->a
.bssid
))
1933 if (le16_to_cpu(bss
->bss
.a
.essid_len
) !=
1934 le16_to_cpu(atom
->a
.essid_len
))
1936 if (memcmp(bss
->bss
.a
.essid
, atom
->a
.essid
,
1937 le16_to_cpu(atom
->a
.essid_len
)))
1943 /* Grab a bss off the free list */
1944 if (!found
&& !list_empty(&priv
->bss_free_list
)) {
1945 bss
= list_entry(priv
->bss_free_list
.next
,
1946 struct bss_element
, list
);
1947 list_del(priv
->bss_free_list
.next
);
1949 list_add_tail(&bss
->list
, &priv
->bss_list
);
1953 /* Always update the BSS to get latest beacon info */
1954 memcpy(&bss
->bss
, atom
, sizeof(bss
->bss
));
1955 bss
->last_scanned
= jiffies
;
1962 static void __orinoco_ev_info(struct net_device
*dev
, hermes_t
*hw
)
1964 struct orinoco_private
*priv
= netdev_priv(dev
);
1969 } __attribute__ ((packed
)) info
;
1973 /* This is an answer to an INQUIRE command that we did earlier,
1974 * or an information "event" generated by the card
1975 * The controller return to us a pseudo frame containing
1976 * the information in question - Jean II */
1977 infofid
= hermes_read_regn(hw
, INFOFID
);
1979 /* Read the info frame header - don't try too hard */
1980 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, &info
, sizeof(info
),
1983 printk(KERN_ERR
"%s: error %d reading info frame. "
1984 "Frame dropped.\n", dev
->name
, err
);
1988 len
= HERMES_RECLEN_TO_BYTES(le16_to_cpu(info
.len
));
1989 type
= le16_to_cpu(info
.type
);
1992 case HERMES_INQ_TALLIES
: {
1993 struct hermes_tallies_frame tallies
;
1994 struct iw_statistics
*wstats
= &priv
->wstats
;
1996 if (len
> sizeof(tallies
)) {
1997 printk(KERN_WARNING
"%s: Tallies frame too long (%d bytes)\n",
1999 len
= sizeof(tallies
);
2002 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, &tallies
, len
,
2003 infofid
, sizeof(info
));
2007 /* Increment our various counters */
2008 /* wstats->discard.nwid - no wrong BSSID stuff */
2009 wstats
->discard
.code
+=
2010 le16_to_cpu(tallies
.RxWEPUndecryptable
);
2011 if (len
== sizeof(tallies
))
2012 wstats
->discard
.code
+=
2013 le16_to_cpu(tallies
.RxDiscards_WEPICVError
) +
2014 le16_to_cpu(tallies
.RxDiscards_WEPExcluded
);
2015 wstats
->discard
.misc
+=
2016 le16_to_cpu(tallies
.TxDiscardsWrongSA
);
2017 wstats
->discard
.fragment
+=
2018 le16_to_cpu(tallies
.RxMsgInBadMsgFragments
);
2019 wstats
->discard
.retries
+=
2020 le16_to_cpu(tallies
.TxRetryLimitExceeded
);
2021 /* wstats->miss.beacon - no match */
2024 case HERMES_INQ_LINKSTATUS
: {
2025 struct hermes_linkstatus linkstatus
;
2029 if (priv
->iw_mode
== IW_MODE_MONITOR
)
2032 if (len
!= sizeof(linkstatus
)) {
2033 printk(KERN_WARNING
"%s: Unexpected size for linkstatus frame (%d bytes)\n",
2038 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, &linkstatus
, len
,
2039 infofid
, sizeof(info
));
2042 newstatus
= le16_to_cpu(linkstatus
.linkstatus
);
2044 /* Symbol firmware uses "out of range" to signal that
2045 * the hostscan frame can be requested. */
2046 if (newstatus
== HERMES_LINKSTATUS_AP_OUT_OF_RANGE
&&
2047 priv
->firmware_type
== FIRMWARE_TYPE_SYMBOL
&&
2048 priv
->has_hostscan
&& priv
->scan_inprogress
) {
2049 hermes_inquire(hw
, HERMES_INQ_HOSTSCAN_SYMBOL
);
2053 connected
= (newstatus
== HERMES_LINKSTATUS_CONNECTED
)
2054 || (newstatus
== HERMES_LINKSTATUS_AP_CHANGE
)
2055 || (newstatus
== HERMES_LINKSTATUS_AP_IN_RANGE
);
2058 netif_carrier_on(dev
);
2059 else if (!ignore_disconnect
)
2060 netif_carrier_off(dev
);
2062 if (newstatus
!= priv
->last_linkstatus
) {
2063 priv
->last_linkstatus
= newstatus
;
2064 print_linkstatus(dev
, newstatus
);
2065 /* The info frame contains only one word which is the
2066 * status (see hermes.h). The status is pretty boring
2067 * in itself, that's why we export the new BSSID...
2069 schedule_work(&priv
->wevent_work
);
2073 case HERMES_INQ_SCAN
:
2074 if (!priv
->scan_inprogress
&& priv
->bssid_fixed
&&
2075 priv
->firmware_type
== FIRMWARE_TYPE_INTERSIL
) {
2076 schedule_work(&priv
->join_work
);
2080 case HERMES_INQ_HOSTSCAN
:
2081 case HERMES_INQ_HOSTSCAN_SYMBOL
: {
2082 /* Result of a scanning. Contains information about
2083 * cells in the vicinity - Jean II */
2084 union iwreq_data wrqu
;
2087 /* Scan is no longer in progress */
2088 priv
->scan_inprogress
= 0;
2092 printk(KERN_WARNING
"%s: Scan results too large (%d bytes)\n",
2097 /* Allocate buffer for results */
2098 buf
= kmalloc(len
, GFP_ATOMIC
);
2100 /* No memory, so can't printk()... */
2103 /* Read scan data */
2104 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, (void *) buf
, len
,
2105 infofid
, sizeof(info
));
2111 #ifdef ORINOCO_DEBUG
2114 printk(KERN_DEBUG
"Scan result [%02X", buf
[0]);
2115 for(i
= 1; i
< (len
* 2); i
++)
2116 printk(":%02X", buf
[i
]);
2119 #endif /* ORINOCO_DEBUG */
2121 if (orinoco_process_scan_results(dev
, buf
, len
) == 0) {
2122 /* Send an empty event to user space.
2123 * We don't send the received data on the event because
2124 * it would require us to do complex transcoding, and
2125 * we want to minimise the work done in the irq handler
2126 * Use a request to extract the data - Jean II */
2127 wrqu
.data
.length
= 0;
2128 wrqu
.data
.flags
= 0;
2129 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
2134 case HERMES_INQ_CHANNELINFO
:
2136 struct agere_ext_scan_info
*bss
;
2138 if (!priv
->scan_inprogress
) {
2139 printk(KERN_DEBUG
"%s: Got chaninfo without scan, "
2140 "len=%d\n", dev
->name
, len
);
2144 /* An empty result indicates that the scan is complete */
2146 union iwreq_data wrqu
;
2148 /* Scan is no longer in progress */
2149 priv
->scan_inprogress
= 0;
2151 wrqu
.data
.length
= 0;
2152 wrqu
.data
.flags
= 0;
2153 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
2158 else if (len
> sizeof(*bss
)) {
2160 "%s: Ext scan results too large (%d bytes). "
2161 "Truncating results to %zd bytes.\n",
2162 dev
->name
, len
, sizeof(*bss
));
2164 } else if (len
< (offsetof(struct agere_ext_scan_info
,
2166 /* Drop this result now so we don't have to
2167 * keep checking later */
2169 "%s: Ext scan results too short (%d bytes)\n",
2174 bss
= kmalloc(sizeof(*bss
), GFP_ATOMIC
);
2178 /* Read scan data */
2179 err
= hw
->ops
->bap_pread(hw
, IRQ_BAP
, (void *) bss
, len
,
2180 infofid
, sizeof(info
));
2186 orinoco_add_ext_scan_result(priv
, bss
);
2191 case HERMES_INQ_SEC_STAT_AGERE
:
2192 /* Security status (Agere specific) */
2193 /* Ignore this frame for now */
2194 if (priv
->firmware_type
== FIRMWARE_TYPE_AGERE
)
2198 printk(KERN_DEBUG
"%s: Unknown information frame received: "
2199 "type 0x%04x, length %d\n", dev
->name
, type
, len
);
2200 /* We don't actually do anything about it */
2205 static void __orinoco_ev_infdrop(struct net_device
*dev
, hermes_t
*hw
)
2207 if (net_ratelimit())
2208 printk(KERN_DEBUG
"%s: Information frame lost.\n", dev
->name
);
2211 /********************************************************************/
2212 /* Internal hardware control routines */
2213 /********************************************************************/
2215 int __orinoco_up(struct net_device
*dev
)
2217 struct orinoco_private
*priv
= netdev_priv(dev
);
2218 struct hermes
*hw
= &priv
->hw
;
2221 netif_carrier_off(dev
); /* just to make sure */
2223 err
= __orinoco_program_rids(dev
);
2225 printk(KERN_ERR
"%s: Error %d configuring card\n",
2230 /* Fire things up again */
2231 hermes_set_irqmask(hw
, ORINOCO_INTEN
);
2232 err
= hermes_enable_port(hw
, 0);
2234 printk(KERN_ERR
"%s: Error %d enabling MAC port\n",
2239 netif_start_queue(dev
);
2244 int __orinoco_down(struct net_device
*dev
)
2246 struct orinoco_private
*priv
= netdev_priv(dev
);
2247 struct hermes
*hw
= &priv
->hw
;
2250 netif_stop_queue(dev
);
2252 if (! priv
->hw_unavailable
) {
2253 if (! priv
->broken_disableport
) {
2254 err
= hermes_disable_port(hw
, 0);
2256 /* Some firmwares (e.g. Intersil 1.3.x) seem
2257 * to have problems disabling the port, oh
2259 printk(KERN_WARNING
"%s: Error %d disabling MAC port\n",
2261 priv
->broken_disableport
= 1;
2264 hermes_set_irqmask(hw
, 0);
2265 hermes_write_regn(hw
, EVACK
, 0xffff);
2268 /* firmware will have to reassociate */
2269 netif_carrier_off(dev
);
2270 priv
->last_linkstatus
= 0xffff;
2275 static int orinoco_allocate_fid(struct net_device
*dev
)
2277 struct orinoco_private
*priv
= netdev_priv(dev
);
2278 struct hermes
*hw
= &priv
->hw
;
2281 err
= hw
->ops
->allocate(hw
, priv
->nicbuf_size
, &priv
->txfid
);
2282 if (err
== -EIO
&& priv
->nicbuf_size
> TX_NICBUF_SIZE_BUG
) {
2283 /* Try workaround for old Symbol firmware bug */
2284 printk(KERN_WARNING
"%s: firmware ALLOC bug detected "
2285 "(old Symbol firmware?). Trying to work around... ",
2288 priv
->nicbuf_size
= TX_NICBUF_SIZE_BUG
;
2289 err
= hw
->ops
->allocate(hw
, priv
->nicbuf_size
, &priv
->txfid
);
2291 printk("failed!\n");
2299 int orinoco_reinit_firmware(struct net_device
*dev
)
2301 struct orinoco_private
*priv
= netdev_priv(dev
);
2302 struct hermes
*hw
= &priv
->hw
;
2305 err
= hw
->ops
->init(hw
);
2307 err
= orinoco_allocate_fid(dev
);
2312 static int __orinoco_hw_set_bitrate(struct orinoco_private
*priv
)
2314 hermes_t
*hw
= &priv
->hw
;
2317 if (priv
->bitratemode
>= BITRATE_TABLE_SIZE
) {
2318 printk(KERN_ERR
"%s: BUG: Invalid bitrate mode %d\n",
2319 priv
->ndev
->name
, priv
->bitratemode
);
2323 switch (priv
->firmware_type
) {
2324 case FIRMWARE_TYPE_AGERE
:
2325 err
= hermes_write_wordrec(hw
, USER_BAP
,
2326 HERMES_RID_CNFTXRATECONTROL
,
2327 bitrate_table
[priv
->bitratemode
].agere_txratectrl
);
2329 case FIRMWARE_TYPE_INTERSIL
:
2330 case FIRMWARE_TYPE_SYMBOL
:
2331 err
= hermes_write_wordrec(hw
, USER_BAP
,
2332 HERMES_RID_CNFTXRATECONTROL
,
2333 bitrate_table
[priv
->bitratemode
].intersil_txratectrl
);
2342 /* Set fixed AP address */
2343 static int __orinoco_hw_set_wap(struct orinoco_private
*priv
)
2347 hermes_t
*hw
= &priv
->hw
;
2349 switch (priv
->firmware_type
) {
2350 case FIRMWARE_TYPE_AGERE
:
2353 case FIRMWARE_TYPE_INTERSIL
:
2354 if (priv
->bssid_fixed
)
2359 err
= hermes_write_wordrec(hw
, USER_BAP
,
2360 HERMES_RID_CNFROAMINGMODE
,
2363 case FIRMWARE_TYPE_SYMBOL
:
2364 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
2365 HERMES_RID_CNFMANDATORYBSSID_SYMBOL
,
2366 &priv
->desired_bssid
);
2372 /* Change the WEP keys and/or the current keys. Can be called
2373 * either from __orinoco_hw_setup_enc() or directly from
2374 * orinoco_ioctl_setiwencode(). In the later case the association
2375 * with the AP is not broken (if the firmware can handle it),
2376 * which is needed for 802.1x implementations. */
2377 static int __orinoco_hw_setup_wepkeys(struct orinoco_private
*priv
)
2379 hermes_t
*hw
= &priv
->hw
;
2382 switch (priv
->firmware_type
) {
2383 case FIRMWARE_TYPE_AGERE
:
2384 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
2385 HERMES_RID_CNFWEPKEYS_AGERE
,
2389 err
= hermes_write_wordrec(hw
, USER_BAP
,
2390 HERMES_RID_CNFTXKEY_AGERE
,
2395 case FIRMWARE_TYPE_INTERSIL
:
2396 case FIRMWARE_TYPE_SYMBOL
:
2401 /* Force uniform key length to work around firmware bugs */
2402 keylen
= le16_to_cpu(priv
->keys
[priv
->tx_key
].len
);
2404 if (keylen
> LARGE_KEY_SIZE
) {
2405 printk(KERN_ERR
"%s: BUG: Key %d has oversize length %d.\n",
2406 priv
->ndev
->name
, priv
->tx_key
, keylen
);
2410 /* Write all 4 keys */
2411 for(i
= 0; i
< ORINOCO_MAX_KEYS
; i
++) {
2412 err
= hw
->ops
->write_ltv(hw
, USER_BAP
,
2413 HERMES_RID_CNFDEFAULTKEY0
+ i
,
2414 HERMES_BYTES_TO_RECLEN(keylen
),
2415 priv
->keys
[i
].data
);
2420 /* Write the index of the key used in transmission */
2421 err
= hermes_write_wordrec(hw
, USER_BAP
,
2422 HERMES_RID_CNFWEPDEFAULTKEYID
,
2433 static int __orinoco_hw_setup_enc(struct orinoco_private
*priv
)
2435 hermes_t
*hw
= &priv
->hw
;
2437 int master_wep_flag
;
2441 /* Setup WEP keys for WEP and WPA */
2442 if (priv
->encode_alg
)
2443 __orinoco_hw_setup_wepkeys(priv
);
2445 if (priv
->wep_restrict
)
2446 auth_flag
= HERMES_AUTH_SHARED_KEY
;
2448 auth_flag
= HERMES_AUTH_OPEN
;
2450 if (priv
->wpa_enabled
)
2452 else if (priv
->encode_alg
== IW_ENCODE_ALG_WEP
)
2457 switch (priv
->firmware_type
) {
2458 case FIRMWARE_TYPE_AGERE
: /* Agere style WEP */
2459 if (priv
->encode_alg
== IW_ENCODE_ALG_WEP
) {
2460 /* Enable the shared-key authentication. */
2461 err
= hermes_write_wordrec(hw
, USER_BAP
,
2462 HERMES_RID_CNFAUTHENTICATION_AGERE
,
2465 err
= hermes_write_wordrec(hw
, USER_BAP
,
2466 HERMES_RID_CNFWEPENABLED_AGERE
,
2471 if (priv
->has_wpa
) {
2472 /* Set WPA key management */
2473 err
= hermes_write_wordrec(hw
, USER_BAP
,
2474 HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE
,
2482 case FIRMWARE_TYPE_INTERSIL
: /* Intersil style WEP */
2483 case FIRMWARE_TYPE_SYMBOL
: /* Symbol style WEP */
2484 if (priv
->encode_alg
== IW_ENCODE_ALG_WEP
) {
2485 if (priv
->wep_restrict
||
2486 (priv
->firmware_type
== FIRMWARE_TYPE_SYMBOL
))
2487 master_wep_flag
= HERMES_WEP_PRIVACY_INVOKED
|
2488 HERMES_WEP_EXCL_UNENCRYPTED
;
2490 master_wep_flag
= HERMES_WEP_PRIVACY_INVOKED
;
2492 err
= hermes_write_wordrec(hw
, USER_BAP
,
2493 HERMES_RID_CNFAUTHENTICATION
,
2498 master_wep_flag
= 0;
2500 if (priv
->iw_mode
== IW_MODE_MONITOR
)
2501 master_wep_flag
|= HERMES_WEP_HOST_DECRYPT
;
2503 /* Master WEP setting : on/off */
2504 err
= hermes_write_wordrec(hw
, USER_BAP
,
2505 HERMES_RID_CNFWEPFLAGS_INTERSIL
,
2516 /* key must be 32 bytes, including the tx and rx MIC keys.
2517 * rsc must be 8 bytes
2518 * tsc must be 8 bytes or NULL
2520 static int __orinoco_hw_set_tkip_key(hermes_t
*hw
, int key_idx
, int set_tx
,
2521 u8
*key
, u8
*rsc
, u8
*tsc
)
2525 u8 rsc
[IW_ENCODE_SEQ_MAX_SIZE
];
2526 u8 key
[TKIP_KEYLEN
];
2527 u8 tx_mic
[MIC_KEYLEN
];
2528 u8 rx_mic
[MIC_KEYLEN
];
2529 u8 tsc
[IW_ENCODE_SEQ_MAX_SIZE
];
2530 } __attribute__ ((packed
)) buf
;
2541 buf
.idx
= cpu_to_le16(key_idx
);
2542 memcpy(buf
.key
, key
,
2543 sizeof(buf
.key
) + sizeof(buf
.tx_mic
) + sizeof(buf
.rx_mic
));
2546 memset(buf
.rsc
, 0, sizeof(buf
.rsc
));
2548 memcpy(buf
.rsc
, rsc
, sizeof(buf
.rsc
));
2551 memset(buf
.tsc
, 0, sizeof(buf
.tsc
));
2554 memcpy(buf
.tsc
, tsc
, sizeof(buf
.tsc
));
2557 /* Wait upto 100ms for tx queue to empty */
2562 ret
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_TXQUEUEEMPTY
,
2566 } while ((k
> 0) && xmitting
);
2571 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
2572 HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE
,
2575 return ret
? ret
: err
;
2578 static int orinoco_clear_tkip_key(struct orinoco_private
*priv
,
2581 hermes_t
*hw
= &priv
->hw
;
2584 memset(&priv
->tkip_key
[key_idx
], 0, sizeof(priv
->tkip_key
[key_idx
]));
2585 err
= hermes_write_wordrec(hw
, USER_BAP
,
2586 HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE
,
2589 printk(KERN_WARNING
"%s: Error %d clearing TKIP key %d\n",
2590 priv
->ndev
->name
, err
, key_idx
);
2594 static int __orinoco_program_rids(struct net_device
*dev
)
2596 struct orinoco_private
*priv
= netdev_priv(dev
);
2597 hermes_t
*hw
= &priv
->hw
;
2599 struct hermes_idstring idbuf
;
2601 /* Set the MAC address */
2602 err
= hw
->ops
->write_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNMACADDR
,
2603 HERMES_BYTES_TO_RECLEN(ETH_ALEN
), dev
->dev_addr
);
2605 printk(KERN_ERR
"%s: Error %d setting MAC address\n",
2610 /* Set up the link mode */
2611 err
= hermes_write_wordrec(hw
, USER_BAP
, HERMES_RID_CNFPORTTYPE
,
2614 printk(KERN_ERR
"%s: Error %d setting port type\n",
2618 /* Set the channel/frequency */
2619 if (priv
->channel
!= 0 && priv
->iw_mode
!= IW_MODE_INFRA
) {
2620 err
= hermes_write_wordrec(hw
, USER_BAP
,
2621 HERMES_RID_CNFOWNCHANNEL
,
2624 printk(KERN_ERR
"%s: Error %d setting channel %d\n",
2625 dev
->name
, err
, priv
->channel
);
2630 if (priv
->has_ibss
) {
2633 if ((strlen(priv
->desired_essid
) == 0) && (priv
->createibss
)) {
2634 printk(KERN_WARNING
"%s: This firmware requires an "
2635 "ESSID in IBSS-Ad-Hoc mode.\n", dev
->name
);
2636 /* With wvlan_cs, in this case, we would crash.
2637 * hopefully, this driver will behave better...
2641 createibss
= priv
->createibss
;
2644 err
= hermes_write_wordrec(hw
, USER_BAP
,
2645 HERMES_RID_CNFCREATEIBSS
,
2648 printk(KERN_ERR
"%s: Error %d setting CREATEIBSS\n",
2654 /* Set the desired BSSID */
2655 err
= __orinoco_hw_set_wap(priv
);
2657 printk(KERN_ERR
"%s: Error %d setting AP address\n",
2661 /* Set the desired ESSID */
2662 idbuf
.len
= cpu_to_le16(strlen(priv
->desired_essid
));
2663 memcpy(&idbuf
.val
, priv
->desired_essid
, sizeof(idbuf
.val
));
2664 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
2665 err
= hw
->ops
->write_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNSSID
,
2666 HERMES_BYTES_TO_RECLEN(strlen(priv
->desired_essid
)+2),
2669 printk(KERN_ERR
"%s: Error %d setting OWNSSID\n",
2673 err
= hw
->ops
->write_ltv(hw
, USER_BAP
, HERMES_RID_CNFDESIREDSSID
,
2674 HERMES_BYTES_TO_RECLEN(strlen(priv
->desired_essid
)+2),
2677 printk(KERN_ERR
"%s: Error %d setting DESIREDSSID\n",
2682 /* Set the station name */
2683 idbuf
.len
= cpu_to_le16(strlen(priv
->nick
));
2684 memcpy(&idbuf
.val
, priv
->nick
, sizeof(idbuf
.val
));
2685 err
= hw
->ops
->write_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNNAME
,
2686 HERMES_BYTES_TO_RECLEN(strlen(priv
->nick
)+2),
2689 printk(KERN_ERR
"%s: Error %d setting nickname\n",
2694 /* Set AP density */
2695 if (priv
->has_sensitivity
) {
2696 err
= hermes_write_wordrec(hw
, USER_BAP
,
2697 HERMES_RID_CNFSYSTEMSCALE
,
2700 printk(KERN_WARNING
"%s: Error %d setting SYSTEMSCALE. "
2701 "Disabling sensitivity control\n",
2704 priv
->has_sensitivity
= 0;
2708 /* Set RTS threshold */
2709 err
= hermes_write_wordrec(hw
, USER_BAP
, HERMES_RID_CNFRTSTHRESHOLD
,
2712 printk(KERN_ERR
"%s: Error %d setting RTS threshold\n",
2717 /* Set fragmentation threshold or MWO robustness */
2719 err
= hermes_write_wordrec(hw
, USER_BAP
,
2720 HERMES_RID_CNFMWOROBUST_AGERE
,
2723 err
= hermes_write_wordrec(hw
, USER_BAP
,
2724 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
2727 printk(KERN_ERR
"%s: Error %d setting fragmentation\n",
2733 err
= __orinoco_hw_set_bitrate(priv
);
2735 printk(KERN_ERR
"%s: Error %d setting bitrate\n",
2740 /* Set power management */
2742 err
= hermes_write_wordrec(hw
, USER_BAP
,
2743 HERMES_RID_CNFPMENABLED
,
2746 printk(KERN_ERR
"%s: Error %d setting up PM\n",
2751 err
= hermes_write_wordrec(hw
, USER_BAP
,
2752 HERMES_RID_CNFMULTICASTRECEIVE
,
2755 printk(KERN_ERR
"%s: Error %d setting up PM\n",
2759 err
= hermes_write_wordrec(hw
, USER_BAP
,
2760 HERMES_RID_CNFMAXSLEEPDURATION
,
2763 printk(KERN_ERR
"%s: Error %d setting up PM\n",
2767 err
= hermes_write_wordrec(hw
, USER_BAP
,
2768 HERMES_RID_CNFPMHOLDOVERDURATION
,
2771 printk(KERN_ERR
"%s: Error %d setting up PM\n",
2777 /* Set preamble - only for Symbol so far... */
2778 if (priv
->has_preamble
) {
2779 err
= hermes_write_wordrec(hw
, USER_BAP
,
2780 HERMES_RID_CNFPREAMBLE_SYMBOL
,
2783 printk(KERN_ERR
"%s: Error %d setting preamble\n",
2789 /* Set up encryption */
2790 if (priv
->has_wep
|| priv
->has_wpa
) {
2791 err
= __orinoco_hw_setup_enc(priv
);
2793 printk(KERN_ERR
"%s: Error %d activating encryption\n",
2799 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
2800 /* Enable monitor mode */
2801 dev
->type
= ARPHRD_IEEE80211
;
2802 err
= hw
->ops
->cmd_wait(hw
, HERMES_CMD_TEST
|
2803 HERMES_TEST_MONITOR
, 0, NULL
);
2805 /* Disable monitor mode */
2806 dev
->type
= ARPHRD_ETHER
;
2807 err
= hw
->ops
->cmd_wait(hw
, HERMES_CMD_TEST
|
2808 HERMES_TEST_STOP
, 0, NULL
);
2813 /* Set promiscuity / multicast*/
2814 priv
->promiscuous
= 0;
2817 /* FIXME: what about netif_tx_lock */
2818 __orinoco_set_multicast_list(dev
);
2823 /* FIXME: return int? */
2825 __orinoco_set_multicast_list(struct net_device
*dev
)
2827 struct orinoco_private
*priv
= netdev_priv(dev
);
2828 hermes_t
*hw
= &priv
->hw
;
2830 int promisc
, mc_count
;
2832 /* The Hermes doesn't seem to have an allmulti mode, so we go
2833 * into promiscuous mode and let the upper levels deal. */
2834 if ( (dev
->flags
& IFF_PROMISC
) || (dev
->flags
& IFF_ALLMULTI
) ||
2835 (dev
->mc_count
> MAX_MULTICAST(priv
)) ) {
2840 mc_count
= dev
->mc_count
;
2843 if (promisc
!= priv
->promiscuous
) {
2844 err
= hermes_write_wordrec(hw
, USER_BAP
,
2845 HERMES_RID_CNFPROMISCUOUSMODE
,
2848 printk(KERN_ERR
"%s: Error %d setting PROMISCUOUSMODE to 1.\n",
2851 priv
->promiscuous
= promisc
;
2854 /* If we're not in promiscuous mode, then we need to set the
2855 * group address if either we want to multicast, or if we were
2856 * multicasting and want to stop */
2857 if (! promisc
&& (mc_count
|| priv
->mc_count
) ) {
2858 struct dev_mc_list
*p
= dev
->mc_list
;
2859 struct hermes_multicast mclist
;
2862 for (i
= 0; i
< mc_count
; i
++) {
2863 /* paranoia: is list shorter than mc_count? */
2865 /* paranoia: bad address size in list? */
2866 BUG_ON(p
->dmi_addrlen
!= ETH_ALEN
);
2868 memcpy(mclist
.addr
[i
], p
->dmi_addr
, ETH_ALEN
);
2873 printk(KERN_WARNING
"%s: Multicast list is "
2874 "longer than mc_count\n", dev
->name
);
2876 err
= hw
->ops
->write_ltv(hw
, USER_BAP
,
2877 HERMES_RID_CNFGROUPADDRESSES
,
2878 HERMES_BYTES_TO_RECLEN(mc_count
* ETH_ALEN
),
2881 printk(KERN_ERR
"%s: Error %d setting multicast list.\n",
2884 priv
->mc_count
= mc_count
;
2888 /* This must be called from user context, without locks held - use
2889 * schedule_work() */
2890 static void orinoco_reset(struct work_struct
*work
)
2892 struct orinoco_private
*priv
=
2893 container_of(work
, struct orinoco_private
, reset_work
);
2894 struct net_device
*dev
= priv
->ndev
;
2895 struct hermes
*hw
= &priv
->hw
;
2897 unsigned long flags
;
2899 if (orinoco_lock(priv
, &flags
) != 0)
2900 /* When the hardware becomes available again, whatever
2901 * detects that is responsible for re-initializing
2902 * it. So no need for anything further */
2905 netif_stop_queue(dev
);
2907 /* Shut off interrupts. Depending on what state the hardware
2908 * is in, this might not work, but we'll try anyway */
2909 hermes_set_irqmask(hw
, 0);
2910 hermes_write_regn(hw
, EVACK
, 0xffff);
2912 priv
->hw_unavailable
++;
2913 priv
->last_linkstatus
= 0xffff; /* firmware will have to reassociate */
2914 netif_carrier_off(dev
);
2916 orinoco_unlock(priv
, &flags
);
2918 /* Scanning support: Cleanup of driver struct */
2919 orinoco_clear_scan_results(priv
, 0);
2920 priv
->scan_inprogress
= 0;
2922 if (priv
->hard_reset
) {
2923 err
= (*priv
->hard_reset
)(priv
);
2925 printk(KERN_ERR
"%s: orinoco_reset: Error %d "
2926 "performing hard reset\n", dev
->name
, err
);
2931 if (priv
->do_fw_download
) {
2932 err
= orinoco_download(priv
);
2934 priv
->do_fw_download
= 0;
2937 err
= orinoco_reinit_firmware(dev
);
2939 printk(KERN_ERR
"%s: orinoco_reset: Error %d re-initializing firmware\n",
2944 spin_lock_irq(&priv
->lock
); /* This has to be called from user context */
2946 priv
->hw_unavailable
--;
2948 /* priv->open or priv->hw_unavailable might have changed while
2949 * we dropped the lock */
2950 if (priv
->open
&& (! priv
->hw_unavailable
)) {
2951 err
= __orinoco_up(dev
);
2953 printk(KERN_ERR
"%s: orinoco_reset: Error %d reenabling card\n",
2956 dev
->trans_start
= jiffies
;
2959 spin_unlock_irq(&priv
->lock
);
2963 hermes_set_irqmask(hw
, 0);
2964 netif_device_detach(dev
);
2965 printk(KERN_ERR
"%s: Device has been disabled!\n", dev
->name
);
2968 /********************************************************************/
2969 /* Interrupt handler */
2970 /********************************************************************/
2972 static void __orinoco_ev_tick(struct net_device
*dev
, hermes_t
*hw
)
2974 printk(KERN_DEBUG
"%s: TICK\n", dev
->name
);
2977 static void __orinoco_ev_wterr(struct net_device
*dev
, hermes_t
*hw
)
2979 /* This seems to happen a fair bit under load, but ignoring it
2980 seems to work fine...*/
2981 printk(KERN_DEBUG
"%s: MAC controller error (WTERR). Ignoring.\n",
2985 irqreturn_t
orinoco_interrupt(int irq
, void *dev_id
)
2987 struct net_device
*dev
= dev_id
;
2988 struct orinoco_private
*priv
= netdev_priv(dev
);
2989 hermes_t
*hw
= &priv
->hw
;
2990 int count
= MAX_IRQLOOPS_PER_IRQ
;
2992 /* These are used to detect a runaway interrupt situation */
2993 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2994 * we panic and shut down the hardware */
2995 static int last_irq_jiffy
= 0; /* jiffies value the last time
2997 static int loops_this_jiffy
= 0;
2998 unsigned long flags
;
3000 if (orinoco_lock(priv
, &flags
) != 0) {
3001 /* If hw is unavailable - we don't know if the irq was
3006 evstat
= hermes_read_regn(hw
, EVSTAT
);
3007 events
= evstat
& hw
->inten
;
3009 orinoco_unlock(priv
, &flags
);
3013 if (jiffies
!= last_irq_jiffy
)
3014 loops_this_jiffy
= 0;
3015 last_irq_jiffy
= jiffies
;
3017 while (events
&& count
--) {
3018 if (++loops_this_jiffy
> MAX_IRQLOOPS_PER_JIFFY
) {
3019 printk(KERN_WARNING
"%s: IRQ handler is looping too "
3020 "much! Resetting.\n", dev
->name
);
3021 /* Disable interrupts for now */
3022 hermes_set_irqmask(hw
, 0);
3023 schedule_work(&priv
->reset_work
);
3027 /* Check the card hasn't been removed */
3028 if (! hermes_present(hw
)) {
3029 DEBUG(0, "orinoco_interrupt(): card removed\n");
3033 if (events
& HERMES_EV_TICK
)
3034 __orinoco_ev_tick(dev
, hw
);
3035 if (events
& HERMES_EV_WTERR
)
3036 __orinoco_ev_wterr(dev
, hw
);
3037 if (events
& HERMES_EV_INFDROP
)
3038 __orinoco_ev_infdrop(dev
, hw
);
3039 if (events
& HERMES_EV_INFO
)
3040 __orinoco_ev_info(dev
, hw
);
3041 if (events
& HERMES_EV_RX
)
3042 __orinoco_ev_rx(dev
, hw
);
3043 if (events
& HERMES_EV_TXEXC
)
3044 __orinoco_ev_txexc(dev
, hw
);
3045 if (events
& HERMES_EV_TX
)
3046 __orinoco_ev_tx(dev
, hw
);
3047 if (events
& HERMES_EV_ALLOC
)
3048 __orinoco_ev_alloc(dev
, hw
);
3050 hermes_write_regn(hw
, EVACK
, evstat
);
3052 evstat
= hermes_read_regn(hw
, EVSTAT
);
3053 events
= evstat
& hw
->inten
;
3056 orinoco_unlock(priv
, &flags
);
3060 /********************************************************************/
3061 /* Initialization */
3062 /********************************************************************/
3065 u16 id
, variant
, major
, minor
;
3066 } __attribute__ ((packed
));
3068 static inline fwtype_t
determine_firmware_type(struct comp_id
*nic_id
)
3070 if (nic_id
->id
< 0x8000)
3071 return FIRMWARE_TYPE_AGERE
;
3072 else if (nic_id
->id
== 0x8000 && nic_id
->major
== 0)
3073 return FIRMWARE_TYPE_SYMBOL
;
3075 return FIRMWARE_TYPE_INTERSIL
;
3078 /* Set priv->firmware type, determine firmware properties */
3079 static int determine_firmware(struct net_device
*dev
)
3081 struct orinoco_private
*priv
= netdev_priv(dev
);
3082 hermes_t
*hw
= &priv
->hw
;
3084 struct comp_id nic_id
, sta_id
;
3085 unsigned int firmver
;
3086 char tmp
[SYMBOL_MAX_VER_LEN
+1] __attribute__((aligned(2)));
3088 /* Get the hardware version */
3089 err
= HERMES_READ_RECORD(hw
, USER_BAP
, HERMES_RID_NICID
, &nic_id
);
3091 printk(KERN_ERR
"%s: Cannot read hardware identity: error %d\n",
3096 le16_to_cpus(&nic_id
.id
);
3097 le16_to_cpus(&nic_id
.variant
);
3098 le16_to_cpus(&nic_id
.major
);
3099 le16_to_cpus(&nic_id
.minor
);
3100 printk(KERN_DEBUG
"%s: Hardware identity %04x:%04x:%04x:%04x\n",
3101 dev
->name
, nic_id
.id
, nic_id
.variant
,
3102 nic_id
.major
, nic_id
.minor
);
3104 priv
->firmware_type
= determine_firmware_type(&nic_id
);
3106 /* Get the firmware version */
3107 err
= HERMES_READ_RECORD(hw
, USER_BAP
, HERMES_RID_STAID
, &sta_id
);
3109 printk(KERN_ERR
"%s: Cannot read station identity: error %d\n",
3114 le16_to_cpus(&sta_id
.id
);
3115 le16_to_cpus(&sta_id
.variant
);
3116 le16_to_cpus(&sta_id
.major
);
3117 le16_to_cpus(&sta_id
.minor
);
3118 printk(KERN_DEBUG
"%s: Station identity %04x:%04x:%04x:%04x\n",
3119 dev
->name
, sta_id
.id
, sta_id
.variant
,
3120 sta_id
.major
, sta_id
.minor
);
3122 switch (sta_id
.id
) {
3124 printk(KERN_ERR
"%s: Primary firmware is active\n",
3128 printk(KERN_ERR
"%s: Tertiary firmware is active\n",
3131 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
3132 case 0x21: /* Symbol Spectrum24 Trilogy */
3135 printk(KERN_NOTICE
"%s: Unknown station ID, please report\n",
3140 /* Default capabilities */
3141 priv
->has_sensitivity
= 1;
3143 priv
->has_preamble
= 0;
3144 priv
->has_port3
= 1;
3147 priv
->has_big_wep
= 0;
3148 priv
->has_alt_txcntl
= 0;
3149 priv
->has_ext_scan
= 0;
3151 priv
->do_fw_download
= 0;
3153 /* Determine capabilities from the firmware version */
3154 switch (priv
->firmware_type
) {
3155 case FIRMWARE_TYPE_AGERE
:
3156 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
3157 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
3158 snprintf(priv
->fw_name
, sizeof(priv
->fw_name
) - 1,
3159 "Lucent/Agere %d.%02d", sta_id
.major
, sta_id
.minor
);
3161 firmver
= ((unsigned long)sta_id
.major
<< 16) | sta_id
.minor
;
3163 priv
->has_ibss
= (firmver
>= 0x60006);
3164 priv
->has_wep
= (firmver
>= 0x40020);
3165 priv
->has_big_wep
= 1; /* FIXME: this is wrong - how do we tell
3166 Gold cards from the others? */
3167 priv
->has_mwo
= (firmver
>= 0x60000);
3168 priv
->has_pm
= (firmver
>= 0x40020); /* Don't work in 7.52 ? */
3169 priv
->ibss_port
= 1;
3170 priv
->has_hostscan
= (firmver
>= 0x8000a);
3171 priv
->do_fw_download
= 1;
3172 priv
->broken_monitor
= (firmver
>= 0x80000);
3173 priv
->has_alt_txcntl
= (firmver
>= 0x90000); /* All 9.x ? */
3174 priv
->has_ext_scan
= (firmver
>= 0x90000); /* All 9.x ? */
3175 priv
->has_wpa
= (firmver
>= 0x9002a);
3176 /* Tested with Agere firmware :
3177 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
3178 * Tested CableTron firmware : 4.32 => Anton */
3180 case FIRMWARE_TYPE_SYMBOL
:
3181 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
3182 /* Intel MAC : 00:02:B3:* */
3183 /* 3Com MAC : 00:50:DA:* */
3184 memset(tmp
, 0, sizeof(tmp
));
3185 /* Get the Symbol firmware version */
3186 err
= hw
->ops
->read_ltv(hw
, USER_BAP
,
3187 HERMES_RID_SECONDARYVERSION_SYMBOL
,
3188 SYMBOL_MAX_VER_LEN
, NULL
, &tmp
);
3191 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
3196 /* The firmware revision is a string, the format is
3197 * something like : "V2.20-01".
3198 * Quick and dirty parsing... - Jean II
3200 firmver
= ((tmp
[1] - '0') << 16) | ((tmp
[3] - '0') << 12)
3201 | ((tmp
[4] - '0') << 8) | ((tmp
[6] - '0') << 4)
3204 tmp
[SYMBOL_MAX_VER_LEN
] = '\0';
3207 snprintf(priv
->fw_name
, sizeof(priv
->fw_name
) - 1,
3210 priv
->has_ibss
= (firmver
>= 0x20000);
3211 priv
->has_wep
= (firmver
>= 0x15012);
3212 priv
->has_big_wep
= (firmver
>= 0x20000);
3213 priv
->has_pm
= (firmver
>= 0x20000 && firmver
< 0x22000) ||
3214 (firmver
>= 0x29000 && firmver
< 0x30000) ||
3216 priv
->has_preamble
= (firmver
>= 0x20000);
3217 priv
->ibss_port
= 4;
3219 /* Symbol firmware is found on various cards, but
3220 * there has been no attempt to check firmware
3221 * download on non-spectrum_cs based cards.
3223 * Given that the Agere firmware download works
3224 * differently, we should avoid doing a firmware
3225 * download with the Symbol algorithm on non-spectrum
3228 * For now we can identify a spectrum_cs based card
3229 * because it has a firmware reset function.
3231 priv
->do_fw_download
= (priv
->stop_fw
!= NULL
);
3233 priv
->broken_disableport
= (firmver
== 0x25013) ||
3234 (firmver
>= 0x30000 && firmver
<= 0x31000);
3235 priv
->has_hostscan
= (firmver
>= 0x31001) ||
3236 (firmver
>= 0x29057 && firmver
< 0x30000);
3237 /* Tested with Intel firmware : 0x20015 => Jean II */
3238 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
3240 case FIRMWARE_TYPE_INTERSIL
:
3241 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
3242 * Samsung, Compaq 100/200 and Proxim are slightly
3243 * different and less well tested */
3244 /* D-Link MAC : 00:40:05:* */
3245 /* Addtron MAC : 00:90:D1:* */
3246 snprintf(priv
->fw_name
, sizeof(priv
->fw_name
) - 1,
3247 "Intersil %d.%d.%d", sta_id
.major
, sta_id
.minor
,
3250 firmver
= ((unsigned long)sta_id
.major
<< 16) |
3251 ((unsigned long)sta_id
.minor
<< 8) | sta_id
.variant
;
3253 priv
->has_ibss
= (firmver
>= 0x000700); /* FIXME */
3254 priv
->has_big_wep
= priv
->has_wep
= (firmver
>= 0x000800);
3255 priv
->has_pm
= (firmver
>= 0x000700);
3256 priv
->has_hostscan
= (firmver
>= 0x010301);
3258 if (firmver
>= 0x000800)
3259 priv
->ibss_port
= 0;
3261 printk(KERN_NOTICE
"%s: Intersil firmware earlier "
3262 "than v0.8.x - several features not supported\n",
3264 priv
->ibss_port
= 1;
3268 printk(KERN_DEBUG
"%s: Firmware determined as %s\n", dev
->name
,
3274 static int orinoco_init(struct net_device
*dev
)
3276 struct orinoco_private
*priv
= netdev_priv(dev
);
3277 hermes_t
*hw
= &priv
->hw
;
3279 struct hermes_idstring nickbuf
;
3282 DECLARE_MAC_BUF(mac
);
3284 /* No need to lock, the hw_unavailable flag is already set in
3285 * alloc_orinocodev() */
3286 priv
->nicbuf_size
= IEEE80211_FRAME_LEN
+ ETH_HLEN
;
3288 /* Initialize the firmware */
3289 err
= hw
->ops
->init(hw
);
3291 printk(KERN_ERR
"%s: failed to initialize firmware (err = %d)\n",
3296 err
= determine_firmware(dev
);
3298 printk(KERN_ERR
"%s: Incompatible firmware, aborting\n",
3303 if (priv
->do_fw_download
) {
3304 err
= orinoco_download(priv
);
3306 priv
->do_fw_download
= 0;
3308 /* Check firmware version again */
3309 err
= determine_firmware(dev
);
3311 printk(KERN_ERR
"%s: Incompatible firmware, aborting\n",
3317 if (priv
->has_port3
)
3318 printk(KERN_DEBUG
"%s: Ad-hoc demo mode supported\n", dev
->name
);
3320 printk(KERN_DEBUG
"%s: IEEE standard IBSS ad-hoc mode supported\n",
3322 if (priv
->has_wep
) {
3323 printk(KERN_DEBUG
"%s: WEP supported, ", dev
->name
);
3324 if (priv
->has_big_wep
)
3325 printk("104-bit key\n");
3327 printk("40-bit key\n");
3329 if (priv
->has_wpa
) {
3330 printk(KERN_DEBUG
"%s: WPA-PSK supported\n", dev
->name
);
3331 if (orinoco_mic_init(priv
)) {
3332 printk(KERN_ERR
"%s: Failed to setup MIC crypto "
3333 "algorithm. Disabling WPA support\n", dev
->name
);
3338 /* Now we have the firmware capabilities, allocate appropiate
3339 * sized scan buffers */
3340 if (orinoco_bss_data_allocate(priv
))
3342 orinoco_bss_data_init(priv
);
3344 /* Get the MAC address */
3345 err
= hw
->ops
->read_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNMACADDR
,
3346 ETH_ALEN
, NULL
, dev
->dev_addr
);
3348 printk(KERN_WARNING
"%s: failed to read MAC address!\n",
3353 printk(KERN_DEBUG
"%s: MAC address %s\n",
3354 dev
->name
, print_mac(mac
, dev
->dev_addr
));
3356 /* Get the station name */
3357 err
= hw
->ops
->read_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNNAME
,
3358 sizeof(nickbuf
), &reclen
, &nickbuf
);
3360 printk(KERN_ERR
"%s: failed to read station name\n",
3365 len
= min(IW_ESSID_MAX_SIZE
, (int)le16_to_cpu(nickbuf
.len
));
3367 len
= min(IW_ESSID_MAX_SIZE
, 2 * reclen
);
3368 memcpy(priv
->nick
, &nickbuf
.val
, len
);
3369 priv
->nick
[len
] = '\0';
3371 printk(KERN_DEBUG
"%s: Station name \"%s\"\n", dev
->name
, priv
->nick
);
3373 err
= orinoco_allocate_fid(dev
);
3375 printk(KERN_ERR
"%s: failed to allocate NIC buffer!\n",
3380 /* Get allowed channels */
3381 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CHANNELLIST
,
3382 &priv
->channel_mask
);
3384 printk(KERN_ERR
"%s: failed to read channel list!\n",
3389 /* Get initial AP density */
3390 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFSYSTEMSCALE
,
3392 if (err
|| priv
->ap_density
< 1 || priv
->ap_density
> 3) {
3393 priv
->has_sensitivity
= 0;
3396 /* Get initial RTS threshold */
3397 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFRTSTHRESHOLD
,
3400 printk(KERN_ERR
"%s: failed to read RTS threshold!\n",
3405 /* Get initial fragmentation settings */
3407 err
= hermes_read_wordrec(hw
, USER_BAP
,
3408 HERMES_RID_CNFMWOROBUST_AGERE
,
3411 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
3412 &priv
->frag_thresh
);
3414 printk(KERN_ERR
"%s: failed to read fragmentation settings!\n",
3419 /* Power management setup */
3423 err
= hermes_read_wordrec(hw
, USER_BAP
,
3424 HERMES_RID_CNFMAXSLEEPDURATION
,
3427 printk(KERN_ERR
"%s: failed to read power management period!\n",
3431 err
= hermes_read_wordrec(hw
, USER_BAP
,
3432 HERMES_RID_CNFPMHOLDOVERDURATION
,
3435 printk(KERN_ERR
"%s: failed to read power management timeout!\n",
3441 /* Preamble setup */
3442 if (priv
->has_preamble
) {
3443 err
= hermes_read_wordrec(hw
, USER_BAP
,
3444 HERMES_RID_CNFPREAMBLE_SYMBOL
,
3450 /* Set up the default configuration */
3451 priv
->iw_mode
= IW_MODE_INFRA
;
3452 /* By default use IEEE/IBSS ad-hoc mode if we have it */
3453 priv
->prefer_port3
= priv
->has_port3
&& (! priv
->has_ibss
);
3454 set_port_type(priv
);
3455 priv
->channel
= 0; /* use firmware default */
3457 priv
->promiscuous
= 0;
3458 priv
->encode_alg
= IW_ENCODE_ALG_NONE
;
3460 priv
->wpa_enabled
= 0;
3461 priv
->tkip_cm_active
= 0;
3463 priv
->wpa_ie_len
= 0;
3464 priv
->wpa_ie
= NULL
;
3466 /* Make the hardware available, as long as it hasn't been
3467 * removed elsewhere (e.g. by PCMCIA hot unplug) */
3468 spin_lock_irq(&priv
->lock
);
3469 priv
->hw_unavailable
--;
3470 spin_unlock_irq(&priv
->lock
);
3472 printk(KERN_DEBUG
"%s: ready\n", dev
->name
);
3479 *alloc_orinocodev(int sizeof_card
,
3480 struct device
*device
,
3481 int (*hard_reset
)(struct orinoco_private
*),
3482 int (*stop_fw
)(struct orinoco_private
*, int))
3484 struct net_device
*dev
;
3485 struct orinoco_private
*priv
;
3487 dev
= alloc_etherdev(sizeof(struct orinoco_private
) + sizeof_card
);
3490 priv
= netdev_priv(dev
);
3493 priv
->card
= (void *)((unsigned long)priv
3494 + sizeof(struct orinoco_private
));
3499 /* Setup / override net_device fields */
3500 dev
->init
= orinoco_init
;
3501 dev
->hard_start_xmit
= orinoco_xmit
;
3502 dev
->tx_timeout
= orinoco_tx_timeout
;
3503 dev
->watchdog_timeo
= HZ
; /* 1 second timeout */
3504 dev
->get_stats
= orinoco_get_stats
;
3505 dev
->ethtool_ops
= &orinoco_ethtool_ops
;
3506 dev
->wireless_handlers
= (struct iw_handler_def
*)&orinoco_handler_def
;
3508 priv
->wireless_data
.spy_data
= &priv
->spy_data
;
3509 dev
->wireless_data
= &priv
->wireless_data
;
3511 dev
->change_mtu
= orinoco_change_mtu
;
3512 dev
->set_multicast_list
= orinoco_set_multicast_list
;
3513 /* we use the default eth_mac_addr for setting the MAC addr */
3515 /* Reserve space in skb for the SNAP header */
3516 dev
->hard_header_len
+= ENCAPS_OVERHEAD
;
3518 /* Set up default callbacks */
3519 dev
->open
= orinoco_open
;
3520 dev
->stop
= orinoco_stop
;
3521 priv
->hard_reset
= hard_reset
;
3522 priv
->stop_fw
= stop_fw
;
3524 spin_lock_init(&priv
->lock
);
3526 priv
->hw_unavailable
= 1; /* orinoco_init() must clear this
3527 * before anything else touches the
3529 INIT_WORK(&priv
->reset_work
, orinoco_reset
);
3530 INIT_WORK(&priv
->join_work
, orinoco_join_ap
);
3531 INIT_WORK(&priv
->wevent_work
, orinoco_send_wevents
);
3533 INIT_LIST_HEAD(&priv
->rx_list
);
3534 tasklet_init(&priv
->rx_tasklet
, orinoco_rx_isr_tasklet
,
3535 (unsigned long) dev
);
3537 netif_carrier_off(dev
);
3538 priv
->last_linkstatus
= 0xffff;
3543 void free_orinocodev(struct net_device
*dev
)
3545 struct orinoco_private
*priv
= netdev_priv(dev
);
3547 /* No need to empty priv->rx_list: if the tasklet is scheduled
3548 * when we call tasklet_kill it will run one final time,
3549 * emptying the list */
3550 tasklet_kill(&priv
->rx_tasklet
);
3551 priv
->wpa_ie_len
= 0;
3552 kfree(priv
->wpa_ie
);
3553 orinoco_mic_free(priv
);
3554 orinoco_bss_data_free(priv
);
3558 /********************************************************************/
3559 /* Wireless extensions */
3560 /********************************************************************/
3562 /* Return : < 0 -> error code ; >= 0 -> length */
3563 static int orinoco_hw_get_essid(struct orinoco_private
*priv
, int *active
,
3564 char buf
[IW_ESSID_MAX_SIZE
+1])
3566 hermes_t
*hw
= &priv
->hw
;
3568 struct hermes_idstring essidbuf
;
3569 char *p
= (char *)(&essidbuf
.val
);
3571 unsigned long flags
;
3573 if (orinoco_lock(priv
, &flags
) != 0)
3576 if (strlen(priv
->desired_essid
) > 0) {
3577 /* We read the desired SSID from the hardware rather
3578 than from priv->desired_essid, just in case the
3579 firmware is allowed to change it on us. I'm not
3581 /* My guess is that the OWNSSID should always be whatever
3582 * we set to the card, whereas CURRENT_SSID is the one that
3583 * may change... - Jean II */
3588 rid
= (priv
->port_type
== 3) ? HERMES_RID_CNFOWNSSID
:
3589 HERMES_RID_CNFDESIREDSSID
;
3591 err
= hw
->ops
->read_ltv(hw
, USER_BAP
, rid
, sizeof(essidbuf
),
3598 err
= hw
->ops
->read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENTSSID
,
3599 sizeof(essidbuf
), NULL
, &essidbuf
);
3604 len
= le16_to_cpu(essidbuf
.len
);
3605 BUG_ON(len
> IW_ESSID_MAX_SIZE
);
3607 memset(buf
, 0, IW_ESSID_MAX_SIZE
);
3608 memcpy(buf
, p
, len
);
3612 orinoco_unlock(priv
, &flags
);
3617 static long orinoco_hw_get_freq(struct orinoco_private
*priv
)
3620 hermes_t
*hw
= &priv
->hw
;
3624 unsigned long flags
;
3626 if (orinoco_lock(priv
, &flags
) != 0)
3629 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CURRENTCHANNEL
, &channel
);
3633 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
3639 if ( (channel
< 1) || (channel
> NUM_CHANNELS
) ) {
3640 printk(KERN_WARNING
"%s: Channel out of range (%d)!\n",
3641 priv
->ndev
->name
, channel
);
3646 freq
= channel_frequency
[channel
-1] * 100000;
3649 orinoco_unlock(priv
, &flags
);
3653 return err
? err
: freq
;
3656 static int orinoco_hw_get_bitratelist(struct orinoco_private
*priv
,
3657 int *numrates
, s32
*rates
, int max
)
3659 hermes_t
*hw
= &priv
->hw
;
3660 struct hermes_idstring list
;
3661 unsigned char *p
= (unsigned char *)&list
.val
;
3665 unsigned long flags
;
3667 if (orinoco_lock(priv
, &flags
) != 0)
3670 err
= hw
->ops
->read_ltv(hw
, USER_BAP
, HERMES_RID_SUPPORTEDDATARATES
,
3671 sizeof(list
), NULL
, &list
);
3672 orinoco_unlock(priv
, &flags
);
3677 num
= le16_to_cpu(list
.len
);
3679 num
= min(num
, max
);
3681 for (i
= 0; i
< num
; i
++) {
3682 rates
[i
] = (p
[i
] & 0x7f) * 500000; /* convert to bps */
3688 static int orinoco_ioctl_getname(struct net_device
*dev
,
3689 struct iw_request_info
*info
,
3693 struct orinoco_private
*priv
= netdev_priv(dev
);
3697 err
= orinoco_hw_get_bitratelist(priv
, &numrates
, NULL
, 0);
3699 if (!err
&& (numrates
> 2))
3700 strcpy(name
, "IEEE 802.11b");
3702 strcpy(name
, "IEEE 802.11-DS");
3707 static int orinoco_ioctl_setwap(struct net_device
*dev
,
3708 struct iw_request_info
*info
,
3709 struct sockaddr
*ap_addr
,
3712 struct orinoco_private
*priv
= netdev_priv(dev
);
3713 int err
= -EINPROGRESS
; /* Call commit handler */
3714 unsigned long flags
;
3715 static const u8 off_addr
[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3716 static const u8 any_addr
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3718 if (orinoco_lock(priv
, &flags
) != 0)
3721 /* Enable automatic roaming - no sanity checks are needed */
3722 if (memcmp(&ap_addr
->sa_data
, off_addr
, ETH_ALEN
) == 0 ||
3723 memcmp(&ap_addr
->sa_data
, any_addr
, ETH_ALEN
) == 0) {
3724 priv
->bssid_fixed
= 0;
3725 memset(priv
->desired_bssid
, 0, ETH_ALEN
);
3727 /* "off" means keep existing connection */
3728 if (ap_addr
->sa_data
[0] == 0) {
3729 __orinoco_hw_set_wap(priv
);
3735 if (priv
->firmware_type
== FIRMWARE_TYPE_AGERE
) {
3736 printk(KERN_WARNING
"%s: Lucent/Agere firmware doesn't "
3737 "support manual roaming\n",
3743 if (priv
->iw_mode
!= IW_MODE_INFRA
) {
3744 printk(KERN_WARNING
"%s: Manual roaming supported only in "
3745 "managed mode\n", dev
->name
);
3750 /* Intersil firmware hangs without Desired ESSID */
3751 if (priv
->firmware_type
== FIRMWARE_TYPE_INTERSIL
&&
3752 strlen(priv
->desired_essid
) == 0) {
3753 printk(KERN_WARNING
"%s: Desired ESSID must be set for "
3754 "manual roaming\n", dev
->name
);
3759 /* Finally, enable manual roaming */
3760 priv
->bssid_fixed
= 1;
3761 memcpy(priv
->desired_bssid
, &ap_addr
->sa_data
, ETH_ALEN
);
3764 orinoco_unlock(priv
, &flags
);
3768 static int orinoco_ioctl_getwap(struct net_device
*dev
,
3769 struct iw_request_info
*info
,
3770 struct sockaddr
*ap_addr
,
3773 struct orinoco_private
*priv
= netdev_priv(dev
);
3775 hermes_t
*hw
= &priv
->hw
;
3777 unsigned long flags
;
3779 if (orinoco_lock(priv
, &flags
) != 0)
3782 ap_addr
->sa_family
= ARPHRD_ETHER
;
3783 err
= hw
->ops
->read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENTBSSID
,
3784 ETH_ALEN
, NULL
, ap_addr
->sa_data
);
3786 orinoco_unlock(priv
, &flags
);
3791 static int orinoco_ioctl_setmode(struct net_device
*dev
,
3792 struct iw_request_info
*info
,
3796 struct orinoco_private
*priv
= netdev_priv(dev
);
3797 int err
= -EINPROGRESS
; /* Call commit handler */
3798 unsigned long flags
;
3800 if (priv
->iw_mode
== *mode
)
3803 if (orinoco_lock(priv
, &flags
) != 0)
3808 if (!priv
->has_ibss
&& !priv
->has_port3
)
3815 case IW_MODE_MONITOR
:
3816 if (priv
->broken_monitor
&& !force_monitor
) {
3817 printk(KERN_WARNING
"%s: Monitor mode support is "
3818 "buggy in this firmware, not enabling\n",
3829 if (err
== -EINPROGRESS
) {
3830 priv
->iw_mode
= *mode
;
3831 set_port_type(priv
);
3834 orinoco_unlock(priv
, &flags
);
3839 static int orinoco_ioctl_getmode(struct net_device
*dev
,
3840 struct iw_request_info
*info
,
3844 struct orinoco_private
*priv
= netdev_priv(dev
);
3846 *mode
= priv
->iw_mode
;
3850 static int orinoco_ioctl_getiwrange(struct net_device
*dev
,
3851 struct iw_request_info
*info
,
3852 struct iw_point
*rrq
,
3855 struct orinoco_private
*priv
= netdev_priv(dev
);
3857 struct iw_range
*range
= (struct iw_range
*) extra
;
3861 rrq
->length
= sizeof(struct iw_range
);
3862 memset(range
, 0, sizeof(struct iw_range
));
3864 range
->we_version_compiled
= WIRELESS_EXT
;
3865 range
->we_version_source
= 22;
3867 /* Set available channels/frequencies */
3868 range
->num_channels
= NUM_CHANNELS
;
3870 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
3871 if (priv
->channel_mask
& (1 << i
)) {
3872 range
->freq
[k
].i
= i
+ 1;
3873 range
->freq
[k
].m
= channel_frequency
[i
] * 100000;
3874 range
->freq
[k
].e
= 1;
3878 if (k
>= IW_MAX_FREQUENCIES
)
3881 range
->num_frequency
= k
;
3882 range
->sensitivity
= 3;
3884 if (priv
->has_wep
) {
3885 range
->max_encoding_tokens
= ORINOCO_MAX_KEYS
;
3886 range
->encoding_size
[0] = SMALL_KEY_SIZE
;
3887 range
->num_encoding_sizes
= 1;
3889 if (priv
->has_big_wep
) {
3890 range
->encoding_size
[1] = LARGE_KEY_SIZE
;
3891 range
->num_encoding_sizes
= 2;
3896 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_CIPHER_TKIP
;
3898 if ((priv
->iw_mode
== IW_MODE_ADHOC
) && (!SPY_NUMBER(priv
))){
3899 /* Quality stats meaningless in ad-hoc mode */
3901 range
->max_qual
.qual
= 0x8b - 0x2f;
3902 range
->max_qual
.level
= 0x2f - 0x95 - 1;
3903 range
->max_qual
.noise
= 0x2f - 0x95 - 1;
3904 /* Need to get better values */
3905 range
->avg_qual
.qual
= 0x24;
3906 range
->avg_qual
.level
= 0xC2;
3907 range
->avg_qual
.noise
= 0x9E;
3910 err
= orinoco_hw_get_bitratelist(priv
, &numrates
,
3911 range
->bitrate
, IW_MAX_BITRATES
);
3914 range
->num_bitrates
= numrates
;
3916 /* Set an indication of the max TCP throughput in bit/s that we can
3917 * expect using this interface. May be use for QoS stuff...
3920 range
->throughput
= 5 * 1000 * 1000; /* ~5 Mb/s */
3922 range
->throughput
= 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
3925 range
->max_rts
= 2347;
3926 range
->min_frag
= 256;
3927 range
->max_frag
= 2346;
3930 range
->max_pmp
= 65535000;
3932 range
->max_pmt
= 65535 * 1000; /* ??? */
3933 range
->pmp_flags
= IW_POWER_PERIOD
;
3934 range
->pmt_flags
= IW_POWER_TIMEOUT
;
3935 range
->pm_capa
= IW_POWER_PERIOD
| IW_POWER_TIMEOUT
| IW_POWER_UNICAST_R
;
3937 range
->retry_capa
= IW_RETRY_LIMIT
| IW_RETRY_LIFETIME
;
3938 range
->retry_flags
= IW_RETRY_LIMIT
;
3939 range
->r_time_flags
= IW_RETRY_LIFETIME
;
3940 range
->min_retry
= 0;
3941 range
->max_retry
= 65535; /* ??? */
3942 range
->min_r_time
= 0;
3943 range
->max_r_time
= 65535 * 1000; /* ??? */
3945 if (priv
->firmware_type
== FIRMWARE_TYPE_AGERE
)
3946 range
->scan_capa
= IW_SCAN_CAPA_ESSID
;
3948 range
->scan_capa
= IW_SCAN_CAPA_NONE
;
3950 /* Event capability (kernel) */
3951 IW_EVENT_CAPA_SET_KERNEL(range
->event_capa
);
3952 /* Event capability (driver) */
3953 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWTHRSPY
);
3954 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWAP
);
3955 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWSCAN
);
3956 IW_EVENT_CAPA_SET(range
->event_capa
, IWEVTXDROP
);
3961 static int orinoco_ioctl_setiwencode(struct net_device
*dev
,
3962 struct iw_request_info
*info
,
3963 struct iw_point
*erq
,
3966 struct orinoco_private
*priv
= netdev_priv(dev
);
3967 int index
= (erq
->flags
& IW_ENCODE_INDEX
) - 1;
3968 int setindex
= priv
->tx_key
;
3969 int encode_alg
= priv
->encode_alg
;
3970 int restricted
= priv
->wep_restrict
;
3972 int err
= -EINPROGRESS
; /* Call commit handler */
3973 unsigned long flags
;
3975 if (! priv
->has_wep
)
3979 /* We actually have a key to set - check its length */
3980 if (erq
->length
> LARGE_KEY_SIZE
)
3983 if ( (erq
->length
> SMALL_KEY_SIZE
) && !priv
->has_big_wep
)
3987 if (orinoco_lock(priv
, &flags
) != 0)
3990 /* Clear any TKIP key we have */
3991 if ((priv
->has_wpa
) && (priv
->encode_alg
== IW_ENCODE_ALG_TKIP
))
3992 (void) orinoco_clear_tkip_key(priv
, setindex
);
3994 if (erq
->length
> 0) {
3995 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
))
3996 index
= priv
->tx_key
;
3998 /* Adjust key length to a supported value */
3999 if (erq
->length
> SMALL_KEY_SIZE
) {
4000 xlen
= LARGE_KEY_SIZE
;
4001 } else if (erq
->length
> 0) {
4002 xlen
= SMALL_KEY_SIZE
;
4006 /* Switch on WEP if off */
4007 if ((encode_alg
!= IW_ENCODE_ALG_WEP
) && (xlen
> 0)) {
4009 encode_alg
= IW_ENCODE_ALG_WEP
;
4012 /* Important note : if the user do "iwconfig eth0 enc off",
4013 * we will arrive there with an index of -1. This is valid
4014 * but need to be taken care off... Jean II */
4015 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
)) {
4016 if((index
!= -1) || (erq
->flags
== 0)) {
4021 /* Set the index : Check that the key is valid */
4022 if(priv
->keys
[index
].len
== 0) {
4030 if (erq
->flags
& IW_ENCODE_DISABLED
)
4031 encode_alg
= IW_ENCODE_ALG_NONE
;
4032 if (erq
->flags
& IW_ENCODE_OPEN
)
4034 if (erq
->flags
& IW_ENCODE_RESTRICTED
)
4037 if (erq
->pointer
&& erq
->length
> 0) {
4038 priv
->keys
[index
].len
= cpu_to_le16(xlen
);
4039 memset(priv
->keys
[index
].data
, 0,
4040 sizeof(priv
->keys
[index
].data
));
4041 memcpy(priv
->keys
[index
].data
, keybuf
, erq
->length
);
4043 priv
->tx_key
= setindex
;
4045 /* Try fast key change if connected and only keys are changed */
4046 if ((priv
->encode_alg
== encode_alg
) &&
4047 (priv
->wep_restrict
== restricted
) &&
4048 netif_carrier_ok(dev
)) {
4049 err
= __orinoco_hw_setup_wepkeys(priv
);
4050 /* No need to commit if successful */
4054 priv
->encode_alg
= encode_alg
;
4055 priv
->wep_restrict
= restricted
;
4058 orinoco_unlock(priv
, &flags
);
4063 static int orinoco_ioctl_getiwencode(struct net_device
*dev
,
4064 struct iw_request_info
*info
,
4065 struct iw_point
*erq
,
4068 struct orinoco_private
*priv
= netdev_priv(dev
);
4069 int index
= (erq
->flags
& IW_ENCODE_INDEX
) - 1;
4071 unsigned long flags
;
4073 if (! priv
->has_wep
)
4076 if (orinoco_lock(priv
, &flags
) != 0)
4079 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
))
4080 index
= priv
->tx_key
;
4083 if (!priv
->encode_alg
)
4084 erq
->flags
|= IW_ENCODE_DISABLED
;
4085 erq
->flags
|= index
+ 1;
4087 if (priv
->wep_restrict
)
4088 erq
->flags
|= IW_ENCODE_RESTRICTED
;
4090 erq
->flags
|= IW_ENCODE_OPEN
;
4092 xlen
= le16_to_cpu(priv
->keys
[index
].len
);
4096 memcpy(keybuf
, priv
->keys
[index
].data
, ORINOCO_MAX_KEY_SIZE
);
4098 orinoco_unlock(priv
, &flags
);
4102 static int orinoco_ioctl_setessid(struct net_device
*dev
,
4103 struct iw_request_info
*info
,
4104 struct iw_point
*erq
,
4107 struct orinoco_private
*priv
= netdev_priv(dev
);
4108 unsigned long flags
;
4110 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
4111 * anyway... - Jean II */
4113 /* Hum... Should not use Wireless Extension constant (may change),
4114 * should use our own... - Jean II */
4115 if (erq
->length
> IW_ESSID_MAX_SIZE
)
4118 if (orinoco_lock(priv
, &flags
) != 0)
4121 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
4122 memset(priv
->desired_essid
, 0, sizeof(priv
->desired_essid
));
4124 /* If not ANY, get the new ESSID */
4126 memcpy(priv
->desired_essid
, essidbuf
, erq
->length
);
4129 orinoco_unlock(priv
, &flags
);
4131 return -EINPROGRESS
; /* Call commit handler */
4134 static int orinoco_ioctl_getessid(struct net_device
*dev
,
4135 struct iw_request_info
*info
,
4136 struct iw_point
*erq
,
4139 struct orinoco_private
*priv
= netdev_priv(dev
);
4142 unsigned long flags
;
4144 if (netif_running(dev
)) {
4145 err
= orinoco_hw_get_essid(priv
, &active
, essidbuf
);
4150 if (orinoco_lock(priv
, &flags
) != 0)
4152 memcpy(essidbuf
, priv
->desired_essid
, IW_ESSID_MAX_SIZE
);
4153 erq
->length
= strlen(priv
->desired_essid
);
4154 orinoco_unlock(priv
, &flags
);
4162 static int orinoco_ioctl_setnick(struct net_device
*dev
,
4163 struct iw_request_info
*info
,
4164 struct iw_point
*nrq
,
4167 struct orinoco_private
*priv
= netdev_priv(dev
);
4168 unsigned long flags
;
4170 if (nrq
->length
> IW_ESSID_MAX_SIZE
)
4173 if (orinoco_lock(priv
, &flags
) != 0)
4176 memset(priv
->nick
, 0, sizeof(priv
->nick
));
4177 memcpy(priv
->nick
, nickbuf
, nrq
->length
);
4179 orinoco_unlock(priv
, &flags
);
4181 return -EINPROGRESS
; /* Call commit handler */
4184 static int orinoco_ioctl_getnick(struct net_device
*dev
,
4185 struct iw_request_info
*info
,
4186 struct iw_point
*nrq
,
4189 struct orinoco_private
*priv
= netdev_priv(dev
);
4190 unsigned long flags
;
4192 if (orinoco_lock(priv
, &flags
) != 0)
4195 memcpy(nickbuf
, priv
->nick
, IW_ESSID_MAX_SIZE
);
4196 orinoco_unlock(priv
, &flags
);
4198 nrq
->length
= strlen(priv
->nick
);
4203 static int orinoco_ioctl_setfreq(struct net_device
*dev
,
4204 struct iw_request_info
*info
,
4205 struct iw_freq
*frq
,
4208 struct orinoco_private
*priv
= netdev_priv(dev
);
4210 unsigned long flags
;
4211 int err
= -EINPROGRESS
; /* Call commit handler */
4213 /* In infrastructure mode the AP sets the channel */
4214 if (priv
->iw_mode
== IW_MODE_INFRA
)
4217 if ( (frq
->e
== 0) && (frq
->m
<= 1000) ) {
4218 /* Setting by channel number */
4221 /* Setting by frequency - search the table */
4225 for (i
= 0; i
< (6 - frq
->e
); i
++)
4228 for (i
= 0; i
< NUM_CHANNELS
; i
++)
4229 if (frq
->m
== (channel_frequency
[i
] * mult
))
4233 if ( (chan
< 1) || (chan
> NUM_CHANNELS
) ||
4234 ! (priv
->channel_mask
& (1 << (chan
-1)) ) )
4237 if (orinoco_lock(priv
, &flags
) != 0)
4240 priv
->channel
= chan
;
4241 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
4242 /* Fast channel change - no commit if successful */
4243 hermes_t
*hw
= &priv
->hw
;
4244 err
= hw
->ops
->cmd_wait(hw
, HERMES_CMD_TEST
|
4245 HERMES_TEST_SET_CHANNEL
,
4248 orinoco_unlock(priv
, &flags
);
4253 static int orinoco_ioctl_getfreq(struct net_device
*dev
,
4254 struct iw_request_info
*info
,
4255 struct iw_freq
*frq
,
4258 struct orinoco_private
*priv
= netdev_priv(dev
);
4261 /* Locking done in there */
4262 tmp
= orinoco_hw_get_freq(priv
);
4273 static int orinoco_ioctl_getsens(struct net_device
*dev
,
4274 struct iw_request_info
*info
,
4275 struct iw_param
*srq
,
4278 struct orinoco_private
*priv
= netdev_priv(dev
);
4279 hermes_t
*hw
= &priv
->hw
;
4282 unsigned long flags
;
4284 if (!priv
->has_sensitivity
)
4287 if (orinoco_lock(priv
, &flags
) != 0)
4289 err
= hermes_read_wordrec(hw
, USER_BAP
,
4290 HERMES_RID_CNFSYSTEMSCALE
, &val
);
4291 orinoco_unlock(priv
, &flags
);
4297 srq
->fixed
= 0; /* auto */
4302 static int orinoco_ioctl_setsens(struct net_device
*dev
,
4303 struct iw_request_info
*info
,
4304 struct iw_param
*srq
,
4307 struct orinoco_private
*priv
= netdev_priv(dev
);
4308 int val
= srq
->value
;
4309 unsigned long flags
;
4311 if (!priv
->has_sensitivity
)
4314 if ((val
< 1) || (val
> 3))
4317 if (orinoco_lock(priv
, &flags
) != 0)
4319 priv
->ap_density
= val
;
4320 orinoco_unlock(priv
, &flags
);
4322 return -EINPROGRESS
; /* Call commit handler */
4325 static int orinoco_ioctl_setrts(struct net_device
*dev
,
4326 struct iw_request_info
*info
,
4327 struct iw_param
*rrq
,
4330 struct orinoco_private
*priv
= netdev_priv(dev
);
4331 int val
= rrq
->value
;
4332 unsigned long flags
;
4337 if ( (val
< 0) || (val
> 2347) )
4340 if (orinoco_lock(priv
, &flags
) != 0)
4343 priv
->rts_thresh
= val
;
4344 orinoco_unlock(priv
, &flags
);
4346 return -EINPROGRESS
; /* Call commit handler */
4349 static int orinoco_ioctl_getrts(struct net_device
*dev
,
4350 struct iw_request_info
*info
,
4351 struct iw_param
*rrq
,
4354 struct orinoco_private
*priv
= netdev_priv(dev
);
4356 rrq
->value
= priv
->rts_thresh
;
4357 rrq
->disabled
= (rrq
->value
== 2347);
4363 static int orinoco_ioctl_setfrag(struct net_device
*dev
,
4364 struct iw_request_info
*info
,
4365 struct iw_param
*frq
,
4368 struct orinoco_private
*priv
= netdev_priv(dev
);
4369 int err
= -EINPROGRESS
; /* Call commit handler */
4370 unsigned long flags
;
4372 if (orinoco_lock(priv
, &flags
) != 0)
4375 if (priv
->has_mwo
) {
4377 priv
->mwo_robust
= 0;
4380 printk(KERN_WARNING
"%s: Fixed fragmentation is "
4381 "not supported on this firmware. "
4382 "Using MWO robust instead.\n", dev
->name
);
4383 priv
->mwo_robust
= 1;
4387 priv
->frag_thresh
= 2346;
4389 if ( (frq
->value
< 256) || (frq
->value
> 2346) )
4392 priv
->frag_thresh
= frq
->value
& ~0x1; /* must be even */
4396 orinoco_unlock(priv
, &flags
);
4401 static int orinoco_ioctl_getfrag(struct net_device
*dev
,
4402 struct iw_request_info
*info
,
4403 struct iw_param
*frq
,
4406 struct orinoco_private
*priv
= netdev_priv(dev
);
4407 hermes_t
*hw
= &priv
->hw
;
4410 unsigned long flags
;
4412 if (orinoco_lock(priv
, &flags
) != 0)
4415 if (priv
->has_mwo
) {
4416 err
= hermes_read_wordrec(hw
, USER_BAP
,
4417 HERMES_RID_CNFMWOROBUST_AGERE
,
4422 frq
->value
= val
? 2347 : 0;
4423 frq
->disabled
= ! val
;
4426 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
4432 frq
->disabled
= (val
>= 2346);
4436 orinoco_unlock(priv
, &flags
);
4441 static int orinoco_ioctl_setrate(struct net_device
*dev
,
4442 struct iw_request_info
*info
,
4443 struct iw_param
*rrq
,
4446 struct orinoco_private
*priv
= netdev_priv(dev
);
4448 int bitrate
; /* 100s of kilobits */
4450 unsigned long flags
;
4452 /* As the user space doesn't know our highest rate, it uses -1
4453 * to ask us to set the highest rate. Test it using "iwconfig
4454 * ethX rate auto" - Jean II */
4455 if (rrq
->value
== -1)
4458 if (rrq
->value
% 100000)
4460 bitrate
= rrq
->value
/ 100000;
4463 if ( (bitrate
!= 10) && (bitrate
!= 20) &&
4464 (bitrate
!= 55) && (bitrate
!= 110) )
4467 for (i
= 0; i
< BITRATE_TABLE_SIZE
; i
++)
4468 if ( (bitrate_table
[i
].bitrate
== bitrate
) &&
4469 (bitrate_table
[i
].automatic
== ! rrq
->fixed
) ) {
4477 if (orinoco_lock(priv
, &flags
) != 0)
4479 priv
->bitratemode
= ratemode
;
4480 orinoco_unlock(priv
, &flags
);
4482 return -EINPROGRESS
;
4485 static int orinoco_ioctl_getrate(struct net_device
*dev
,
4486 struct iw_request_info
*info
,
4487 struct iw_param
*rrq
,
4490 struct orinoco_private
*priv
= netdev_priv(dev
);
4491 hermes_t
*hw
= &priv
->hw
;
4496 unsigned long flags
;
4498 if (orinoco_lock(priv
, &flags
) != 0)
4501 ratemode
= priv
->bitratemode
;
4503 BUG_ON((ratemode
< 0) || (ratemode
>= BITRATE_TABLE_SIZE
));
4505 rrq
->value
= bitrate_table
[ratemode
].bitrate
* 100000;
4506 rrq
->fixed
= ! bitrate_table
[ratemode
].automatic
;
4509 /* If the interface is running we try to find more about the
4511 if (netif_running(dev
)) {
4512 err
= hermes_read_wordrec(hw
, USER_BAP
,
4513 HERMES_RID_CURRENTTXRATE
, &val
);
4517 switch (priv
->firmware_type
) {
4518 case FIRMWARE_TYPE_AGERE
: /* Lucent style rate */
4519 /* Note : in Lucent firmware, the return value of
4520 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
4521 * and therefore is totally different from the
4522 * encoding of HERMES_RID_CNFTXRATECONTROL.
4523 * Don't forget that 6Mb/s is really 5.5Mb/s */
4525 rrq
->value
= 5500000;
4527 rrq
->value
= val
* 1000000;
4529 case FIRMWARE_TYPE_INTERSIL
: /* Intersil style rate */
4530 case FIRMWARE_TYPE_SYMBOL
: /* Symbol style rate */
4531 for (i
= 0; i
< BITRATE_TABLE_SIZE
; i
++)
4532 if (bitrate_table
[i
].intersil_txratectrl
== val
) {
4536 if (i
>= BITRATE_TABLE_SIZE
)
4537 printk(KERN_INFO
"%s: Unable to determine current bitrate (0x%04hx)\n",
4540 rrq
->value
= bitrate_table
[ratemode
].bitrate
* 100000;
4548 orinoco_unlock(priv
, &flags
);
4553 static int orinoco_ioctl_setpower(struct net_device
*dev
,
4554 struct iw_request_info
*info
,
4555 struct iw_param
*prq
,
4558 struct orinoco_private
*priv
= netdev_priv(dev
);
4559 int err
= -EINPROGRESS
; /* Call commit handler */
4560 unsigned long flags
;
4562 if (orinoco_lock(priv
, &flags
) != 0)
4565 if (prq
->disabled
) {
4568 switch (prq
->flags
& IW_POWER_MODE
) {
4569 case IW_POWER_UNICAST_R
:
4573 case IW_POWER_ALL_R
:
4578 /* No flags : but we may have a value - Jean II */
4585 if (prq
->flags
& IW_POWER_TIMEOUT
) {
4587 priv
->pm_timeout
= prq
->value
/ 1000;
4589 if (prq
->flags
& IW_POWER_PERIOD
) {
4591 priv
->pm_period
= prq
->value
/ 1000;
4593 /* It's valid to not have a value if we are just toggling
4594 * the flags... Jean II */
4602 orinoco_unlock(priv
, &flags
);
4607 static int orinoco_ioctl_getpower(struct net_device
*dev
,
4608 struct iw_request_info
*info
,
4609 struct iw_param
*prq
,
4612 struct orinoco_private
*priv
= netdev_priv(dev
);
4613 hermes_t
*hw
= &priv
->hw
;
4615 u16 enable
, period
, timeout
, mcast
;
4616 unsigned long flags
;
4618 if (orinoco_lock(priv
, &flags
) != 0)
4621 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFPMENABLED
, &enable
);
4625 err
= hermes_read_wordrec(hw
, USER_BAP
,
4626 HERMES_RID_CNFMAXSLEEPDURATION
, &period
);
4630 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFPMHOLDOVERDURATION
, &timeout
);
4634 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFMULTICASTRECEIVE
, &mcast
);
4638 prq
->disabled
= !enable
;
4639 /* Note : by default, display the period */
4640 if ((prq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
4641 prq
->flags
= IW_POWER_TIMEOUT
;
4642 prq
->value
= timeout
* 1000;
4644 prq
->flags
= IW_POWER_PERIOD
;
4645 prq
->value
= period
* 1000;
4648 prq
->flags
|= IW_POWER_ALL_R
;
4650 prq
->flags
|= IW_POWER_UNICAST_R
;
4653 orinoco_unlock(priv
, &flags
);
4658 static int orinoco_ioctl_set_encodeext(struct net_device
*dev
,
4659 struct iw_request_info
*info
,
4660 union iwreq_data
*wrqu
,
4663 struct orinoco_private
*priv
= netdev_priv(dev
);
4664 struct iw_point
*encoding
= &wrqu
->encoding
;
4665 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
4666 int idx
, alg
= ext
->alg
, set_key
= 1;
4667 unsigned long flags
;
4671 if (orinoco_lock(priv
, &flags
) != 0)
4674 /* Determine and validate the key index */
4675 idx
= encoding
->flags
& IW_ENCODE_INDEX
;
4677 if ((idx
< 1) || (idx
> WEP_KEYS
))
4683 if (encoding
->flags
& IW_ENCODE_DISABLED
)
4684 alg
= IW_ENCODE_ALG_NONE
;
4686 if (priv
->has_wpa
&& (alg
!= IW_ENCODE_ALG_TKIP
)) {
4687 /* Clear any TKIP TX key we had */
4688 (void) orinoco_clear_tkip_key(priv
, priv
->tx_key
);
4691 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
) {
4693 set_key
= ((alg
== IW_ENCODE_ALG_TKIP
) ||
4694 (ext
->key_len
> 0)) ? 1 : 0;
4698 /* Set the requested key first */
4700 case IW_ENCODE_ALG_NONE
:
4701 priv
->encode_alg
= alg
;
4702 priv
->keys
[idx
].len
= 0;
4705 case IW_ENCODE_ALG_WEP
:
4706 if (ext
->key_len
> SMALL_KEY_SIZE
)
4707 key_len
= LARGE_KEY_SIZE
;
4708 else if (ext
->key_len
> 0)
4709 key_len
= SMALL_KEY_SIZE
;
4713 priv
->encode_alg
= alg
;
4714 priv
->keys
[idx
].len
= cpu_to_le16(key_len
);
4716 key_len
= min(ext
->key_len
, key_len
);
4718 memset(priv
->keys
[idx
].data
, 0, ORINOCO_MAX_KEY_SIZE
);
4719 memcpy(priv
->keys
[idx
].data
, ext
->key
, key_len
);
4722 case IW_ENCODE_ALG_TKIP
:
4724 hermes_t
*hw
= &priv
->hw
;
4727 if (!priv
->has_wpa
||
4728 (ext
->key_len
> sizeof(priv
->tkip_key
[0])))
4731 priv
->encode_alg
= alg
;
4732 memset(&priv
->tkip_key
[idx
], 0,
4733 sizeof(priv
->tkip_key
[idx
]));
4734 memcpy(&priv
->tkip_key
[idx
], ext
->key
, ext
->key_len
);
4736 if (ext
->ext_flags
& IW_ENCODE_EXT_RX_SEQ_VALID
)
4737 tkip_iv
= &ext
->rx_seq
[0];
4739 err
= __orinoco_hw_set_tkip_key(hw
, idx
,
4740 ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
,
4741 (u8
*) &priv
->tkip_key
[idx
],
4744 printk(KERN_ERR
"%s: Error %d setting TKIP key"
4745 "\n", dev
->name
, err
);
4755 orinoco_unlock(priv
, &flags
);
4760 static int orinoco_ioctl_get_encodeext(struct net_device
*dev
,
4761 struct iw_request_info
*info
,
4762 union iwreq_data
*wrqu
,
4765 struct orinoco_private
*priv
= netdev_priv(dev
);
4766 struct iw_point
*encoding
= &wrqu
->encoding
;
4767 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
4768 int idx
, max_key_len
;
4769 unsigned long flags
;
4772 if (orinoco_lock(priv
, &flags
) != 0)
4776 max_key_len
= encoding
->length
- sizeof(*ext
);
4777 if (max_key_len
< 0)
4780 idx
= encoding
->flags
& IW_ENCODE_INDEX
;
4782 if ((idx
< 1) || (idx
> WEP_KEYS
))
4788 encoding
->flags
= idx
+ 1;
4789 memset(ext
, 0, sizeof(*ext
));
4791 ext
->alg
= priv
->encode_alg
;
4792 switch (priv
->encode_alg
) {
4793 case IW_ENCODE_ALG_NONE
:
4795 encoding
->flags
|= IW_ENCODE_DISABLED
;
4797 case IW_ENCODE_ALG_WEP
:
4798 ext
->key_len
= min_t(u16
, le16_to_cpu(priv
->keys
[idx
].len
),
4800 memcpy(ext
->key
, priv
->keys
[idx
].data
, ext
->key_len
);
4801 encoding
->flags
|= IW_ENCODE_ENABLED
;
4803 case IW_ENCODE_ALG_TKIP
:
4804 ext
->key_len
= min_t(u16
, sizeof(struct orinoco_tkip_key
),
4806 memcpy(ext
->key
, &priv
->tkip_key
[idx
], ext
->key_len
);
4807 encoding
->flags
|= IW_ENCODE_ENABLED
;
4813 orinoco_unlock(priv
, &flags
);
4818 static int orinoco_ioctl_set_auth(struct net_device
*dev
,
4819 struct iw_request_info
*info
,
4820 union iwreq_data
*wrqu
, char *extra
)
4822 struct orinoco_private
*priv
= netdev_priv(dev
);
4823 hermes_t
*hw
= &priv
->hw
;
4824 struct iw_param
*param
= &wrqu
->param
;
4825 unsigned long flags
;
4826 int ret
= -EINPROGRESS
;
4828 if (orinoco_lock(priv
, &flags
) != 0)
4831 switch (param
->flags
& IW_AUTH_INDEX
) {
4832 case IW_AUTH_WPA_VERSION
:
4833 case IW_AUTH_CIPHER_PAIRWISE
:
4834 case IW_AUTH_CIPHER_GROUP
:
4835 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
4836 case IW_AUTH_PRIVACY_INVOKED
:
4837 case IW_AUTH_DROP_UNENCRYPTED
:
4839 * orinoco does not use these parameters
4843 case IW_AUTH_KEY_MGMT
:
4844 /* wl_lkm implies value 2 == PSK for Hermes I
4845 * which ties in with WEXT
4846 * no other hints tho :(
4848 priv
->key_mgmt
= param
->value
;
4851 case IW_AUTH_TKIP_COUNTERMEASURES
:
4852 /* When countermeasures are enabled, shut down the
4853 * card; when disabled, re-enable the card. This must
4854 * take effect immediately.
4856 * TODO: Make sure that the EAPOL message is getting
4857 * out before card disabled
4860 priv
->tkip_cm_active
= 1;
4861 ret
= hermes_enable_port(hw
, 0);
4863 priv
->tkip_cm_active
= 0;
4864 ret
= hermes_disable_port(hw
, 0);
4868 case IW_AUTH_80211_AUTH_ALG
:
4869 if (param
->value
& IW_AUTH_ALG_SHARED_KEY
)
4870 priv
->wep_restrict
= 1;
4871 else if (param
->value
& IW_AUTH_ALG_OPEN_SYSTEM
)
4872 priv
->wep_restrict
= 0;
4877 case IW_AUTH_WPA_ENABLED
:
4878 if (priv
->has_wpa
) {
4879 priv
->wpa_enabled
= param
->value
? 1 : 0;
4883 /* else silently accept disable of WPA */
4884 priv
->wpa_enabled
= 0;
4892 orinoco_unlock(priv
, &flags
);
4896 static int orinoco_ioctl_get_auth(struct net_device
*dev
,
4897 struct iw_request_info
*info
,
4898 union iwreq_data
*wrqu
, char *extra
)
4900 struct orinoco_private
*priv
= netdev_priv(dev
);
4901 struct iw_param
*param
= &wrqu
->param
;
4902 unsigned long flags
;
4905 if (orinoco_lock(priv
, &flags
) != 0)
4908 switch (param
->flags
& IW_AUTH_INDEX
) {
4909 case IW_AUTH_KEY_MGMT
:
4910 param
->value
= priv
->key_mgmt
;
4913 case IW_AUTH_TKIP_COUNTERMEASURES
:
4914 param
->value
= priv
->tkip_cm_active
;
4917 case IW_AUTH_80211_AUTH_ALG
:
4918 if (priv
->wep_restrict
)
4919 param
->value
= IW_AUTH_ALG_SHARED_KEY
;
4921 param
->value
= IW_AUTH_ALG_OPEN_SYSTEM
;
4924 case IW_AUTH_WPA_ENABLED
:
4925 param
->value
= priv
->wpa_enabled
;
4932 orinoco_unlock(priv
, &flags
);
4936 static int orinoco_ioctl_set_genie(struct net_device
*dev
,
4937 struct iw_request_info
*info
,
4938 union iwreq_data
*wrqu
, char *extra
)
4940 struct orinoco_private
*priv
= netdev_priv(dev
);
4942 unsigned long flags
;
4945 if ((wrqu
->data
.length
> MAX_WPA_IE_LEN
) ||
4946 (wrqu
->data
.length
&& (extra
== NULL
)))
4949 if (orinoco_lock(priv
, &flags
) != 0)
4952 if (wrqu
->data
.length
) {
4953 buf
= kmalloc(wrqu
->data
.length
, GFP_KERNEL
);
4959 memcpy(buf
, extra
, wrqu
->data
.length
);
4960 kfree(priv
->wpa_ie
);
4962 priv
->wpa_ie_len
= wrqu
->data
.length
;
4964 kfree(priv
->wpa_ie
);
4965 priv
->wpa_ie
= NULL
;
4966 priv
->wpa_ie_len
= 0;
4970 /* Looks like wl_lkm wants to check the auth alg, and
4971 * somehow pass it to the firmware.
4972 * Instead it just calls the key mgmt rid
4973 * - we do this in set auth.
4978 orinoco_unlock(priv
, &flags
);
4982 static int orinoco_ioctl_get_genie(struct net_device
*dev
,
4983 struct iw_request_info
*info
,
4984 union iwreq_data
*wrqu
, char *extra
)
4986 struct orinoco_private
*priv
= netdev_priv(dev
);
4987 unsigned long flags
;
4990 if (orinoco_lock(priv
, &flags
) != 0)
4993 if ((priv
->wpa_ie_len
== 0) || (priv
->wpa_ie
== NULL
)) {
4994 wrqu
->data
.length
= 0;
4998 if (wrqu
->data
.length
< priv
->wpa_ie_len
) {
5003 wrqu
->data
.length
= priv
->wpa_ie_len
;
5004 memcpy(extra
, priv
->wpa_ie
, priv
->wpa_ie_len
);
5007 orinoco_unlock(priv
, &flags
);
5011 static int orinoco_ioctl_set_mlme(struct net_device
*dev
,
5012 struct iw_request_info
*info
,
5013 union iwreq_data
*wrqu
, char *extra
)
5015 struct orinoco_private
*priv
= netdev_priv(dev
);
5016 hermes_t
*hw
= &priv
->hw
;
5017 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
5018 unsigned long flags
;
5021 if (orinoco_lock(priv
, &flags
) != 0)
5024 switch (mlme
->cmd
) {
5025 case IW_MLME_DEAUTH
:
5026 /* silently ignore */
5029 case IW_MLME_DISASSOC
:
5034 } __attribute__ ((packed
)) buf
;
5036 memcpy(buf
.addr
, mlme
->addr
.sa_data
, ETH_ALEN
);
5037 buf
.reason_code
= cpu_to_le16(mlme
->reason_code
);
5038 ret
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
5039 HERMES_RID_CNFDISASSOCIATE
,
5047 orinoco_unlock(priv
, &flags
);
5051 static int orinoco_ioctl_getretry(struct net_device
*dev
,
5052 struct iw_request_info
*info
,
5053 struct iw_param
*rrq
,
5056 struct orinoco_private
*priv
= netdev_priv(dev
);
5057 hermes_t
*hw
= &priv
->hw
;
5059 u16 short_limit
, long_limit
, lifetime
;
5060 unsigned long flags
;
5062 if (orinoco_lock(priv
, &flags
) != 0)
5065 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_SHORTRETRYLIMIT
,
5070 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_LONGRETRYLIMIT
,
5075 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_MAXTRANSMITLIFETIME
,
5080 rrq
->disabled
= 0; /* Can't be disabled */
5082 /* Note : by default, display the retry number */
5083 if ((rrq
->flags
& IW_RETRY_TYPE
) == IW_RETRY_LIFETIME
) {
5084 rrq
->flags
= IW_RETRY_LIFETIME
;
5085 rrq
->value
= lifetime
* 1000; /* ??? */
5087 /* By default, display the min number */
5088 if ((rrq
->flags
& IW_RETRY_LONG
)) {
5089 rrq
->flags
= IW_RETRY_LIMIT
| IW_RETRY_LONG
;
5090 rrq
->value
= long_limit
;
5092 rrq
->flags
= IW_RETRY_LIMIT
;
5093 rrq
->value
= short_limit
;
5094 if(short_limit
!= long_limit
)
5095 rrq
->flags
|= IW_RETRY_SHORT
;
5100 orinoco_unlock(priv
, &flags
);
5105 static int orinoco_ioctl_reset(struct net_device
*dev
,
5106 struct iw_request_info
*info
,
5110 struct orinoco_private
*priv
= netdev_priv(dev
);
5112 if (! capable(CAP_NET_ADMIN
))
5115 if (info
->cmd
== (SIOCIWFIRSTPRIV
+ 0x1)) {
5116 printk(KERN_DEBUG
"%s: Forcing reset!\n", dev
->name
);
5118 /* Firmware reset */
5119 orinoco_reset(&priv
->reset_work
);
5121 printk(KERN_DEBUG
"%s: Force scheduling reset!\n", dev
->name
);
5123 schedule_work(&priv
->reset_work
);
5129 static int orinoco_ioctl_setibssport(struct net_device
*dev
,
5130 struct iw_request_info
*info
,
5135 struct orinoco_private
*priv
= netdev_priv(dev
);
5136 int val
= *( (int *) extra
);
5137 unsigned long flags
;
5139 if (orinoco_lock(priv
, &flags
) != 0)
5142 priv
->ibss_port
= val
;
5144 /* Actually update the mode we are using */
5145 set_port_type(priv
);
5147 orinoco_unlock(priv
, &flags
);
5148 return -EINPROGRESS
; /* Call commit handler */
5151 static int orinoco_ioctl_getibssport(struct net_device
*dev
,
5152 struct iw_request_info
*info
,
5156 struct orinoco_private
*priv
= netdev_priv(dev
);
5157 int *val
= (int *) extra
;
5159 *val
= priv
->ibss_port
;
5163 static int orinoco_ioctl_setport3(struct net_device
*dev
,
5164 struct iw_request_info
*info
,
5168 struct orinoco_private
*priv
= netdev_priv(dev
);
5169 int val
= *( (int *) extra
);
5171 unsigned long flags
;
5173 if (orinoco_lock(priv
, &flags
) != 0)
5177 case 0: /* Try to do IEEE ad-hoc mode */
5178 if (! priv
->has_ibss
) {
5182 priv
->prefer_port3
= 0;
5186 case 1: /* Try to do Lucent proprietary ad-hoc mode */
5187 if (! priv
->has_port3
) {
5191 priv
->prefer_port3
= 1;
5199 /* Actually update the mode we are using */
5200 set_port_type(priv
);
5204 orinoco_unlock(priv
, &flags
);
5209 static int orinoco_ioctl_getport3(struct net_device
*dev
,
5210 struct iw_request_info
*info
,
5214 struct orinoco_private
*priv
= netdev_priv(dev
);
5215 int *val
= (int *) extra
;
5217 *val
= priv
->prefer_port3
;
5221 static int orinoco_ioctl_setpreamble(struct net_device
*dev
,
5222 struct iw_request_info
*info
,
5226 struct orinoco_private
*priv
= netdev_priv(dev
);
5227 unsigned long flags
;
5230 if (! priv
->has_preamble
)
5233 /* 802.11b has recently defined some short preamble.
5234 * Basically, the Phy header has been reduced in size.
5235 * This increase performance, especially at high rates
5236 * (the preamble is transmitted at 1Mb/s), unfortunately
5237 * this give compatibility troubles... - Jean II */
5238 val
= *( (int *) extra
);
5240 if (orinoco_lock(priv
, &flags
) != 0)
5248 orinoco_unlock(priv
, &flags
);
5250 return -EINPROGRESS
; /* Call commit handler */
5253 static int orinoco_ioctl_getpreamble(struct net_device
*dev
,
5254 struct iw_request_info
*info
,
5258 struct orinoco_private
*priv
= netdev_priv(dev
);
5259 int *val
= (int *) extra
;
5261 if (! priv
->has_preamble
)
5264 *val
= priv
->preamble
;
5268 /* ioctl interface to hermes_read_ltv()
5269 * To use with iwpriv, pass the RID as the token argument, e.g.
5270 * iwpriv get_rid [0xfc00]
5271 * At least Wireless Tools 25 is required to use iwpriv.
5272 * For Wireless Tools 25 and 26 append "dummy" are the end. */
5273 static int orinoco_ioctl_getrid(struct net_device
*dev
,
5274 struct iw_request_info
*info
,
5275 struct iw_point
*data
,
5278 struct orinoco_private
*priv
= netdev_priv(dev
);
5279 hermes_t
*hw
= &priv
->hw
;
5280 int rid
= data
->flags
;
5283 unsigned long flags
;
5285 /* It's a "get" function, but we don't want users to access the
5286 * WEP key and other raw firmware data */
5287 if (! capable(CAP_NET_ADMIN
))
5290 if (rid
< 0xfc00 || rid
> 0xffff)
5293 if (orinoco_lock(priv
, &flags
) != 0)
5296 err
= hw
->ops
->read_ltv(hw
, USER_BAP
, rid
, MAX_RID_LEN
, &length
,
5301 data
->length
= min_t(u16
, HERMES_RECLEN_TO_BYTES(length
),
5305 orinoco_unlock(priv
, &flags
);
5309 /* Trigger a scan (look for other cells in the vicinity) */
5310 static int orinoco_ioctl_setscan(struct net_device
*dev
,
5311 struct iw_request_info
*info
,
5312 struct iw_point
*srq
,
5315 struct orinoco_private
*priv
= netdev_priv(dev
);
5316 hermes_t
*hw
= &priv
->hw
;
5317 struct iw_scan_req
*si
= (struct iw_scan_req
*) extra
;
5319 unsigned long flags
;
5321 /* Note : you may have realised that, as this is a SET operation,
5322 * this is privileged and therefore a normal user can't
5324 * This is not an error, while the device perform scanning,
5325 * traffic doesn't flow, so it's a perfect DoS...
5328 if (orinoco_lock(priv
, &flags
) != 0)
5331 /* Scanning with port 0 disabled would fail */
5332 if (!netif_running(dev
)) {
5337 /* In monitor mode, the scan results are always empty.
5338 * Probe responses are passed to the driver as received
5339 * frames and could be processed in software. */
5340 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
5345 /* Note : because we don't lock out the irq handler, the way
5346 * we access scan variables in priv is critical.
5347 * o scan_inprogress : not touched by irq handler
5348 * o scan_mode : not touched by irq handler
5349 * Before modifying anything on those variables, please think hard !
5353 priv
->scan_mode
= srq
->flags
;
5355 /* Always trigger scanning, even if it's in progress.
5356 * This way, if the info frame get lost, we will recover somewhat
5357 * gracefully - Jean II */
5359 if (priv
->has_hostscan
) {
5360 switch (priv
->firmware_type
) {
5361 case FIRMWARE_TYPE_SYMBOL
:
5362 err
= hermes_write_wordrec(hw
, USER_BAP
,
5363 HERMES_RID_CNFHOSTSCAN_SYMBOL
,
5364 HERMES_HOSTSCAN_SYMBOL_ONCE
|
5365 HERMES_HOSTSCAN_SYMBOL_BCAST
);
5367 case FIRMWARE_TYPE_INTERSIL
: {
5370 req
[0] = cpu_to_le16(0x3fff); /* All channels */
5371 req
[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
5372 req
[2] = 0; /* Any ESSID */
5373 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
5374 HERMES_RID_CNFHOSTSCAN
, &req
);
5377 case FIRMWARE_TYPE_AGERE
:
5378 if (priv
->scan_mode
& IW_SCAN_THIS_ESSID
) {
5379 struct hermes_idstring idbuf
;
5380 size_t len
= min(sizeof(idbuf
.val
),
5381 (size_t) si
->essid_len
);
5382 idbuf
.len
= cpu_to_le16(len
);
5383 memcpy(idbuf
.val
, si
->essid
, len
);
5385 err
= hw
->ops
->write_ltv(hw
, USER_BAP
,
5386 HERMES_RID_CNFSCANSSID_AGERE
,
5387 HERMES_BYTES_TO_RECLEN(len
+ 2),
5390 err
= hermes_write_wordrec(hw
, USER_BAP
,
5391 HERMES_RID_CNFSCANSSID_AGERE
,
5396 if (priv
->has_ext_scan
) {
5397 /* Clear scan results at the start of
5398 * an extended scan */
5399 orinoco_clear_scan_results(priv
,
5400 msecs_to_jiffies(15000));
5402 /* TODO: Is this available on older firmware?
5403 * Can we use it to scan specific channels
5404 * for IW_SCAN_THIS_FREQ? */
5405 err
= hermes_write_wordrec(hw
, USER_BAP
,
5406 HERMES_RID_CNFSCANCHANNELS2GHZ
,
5411 err
= hermes_inquire(hw
,
5412 HERMES_INQ_CHANNELINFO
);
5414 err
= hermes_inquire(hw
, HERMES_INQ_SCAN
);
5418 err
= hermes_inquire(hw
, HERMES_INQ_SCAN
);
5420 /* One more client */
5422 priv
->scan_inprogress
= 1;
5425 orinoco_unlock(priv
, &flags
);
5429 #define MAX_CUSTOM_LEN 64
5431 /* Translate scan data returned from the card to a card independant
5432 * format that the Wireless Tools will understand - Jean II */
5433 static inline char *orinoco_translate_scan(struct net_device
*dev
,
5434 struct iw_request_info
*info
,
5437 union hermes_scan_info
*bss
,
5438 unsigned int last_scanned
)
5440 struct orinoco_private
*priv
= netdev_priv(dev
);
5443 struct iw_event iwe
; /* Temporary buffer */
5444 char custom
[MAX_CUSTOM_LEN
];
5446 memset(&iwe
, 0, sizeof(iwe
));
5448 /* First entry *MUST* be the AP MAC address */
5449 iwe
.cmd
= SIOCGIWAP
;
5450 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
5451 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->a
.bssid
, ETH_ALEN
);
5452 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5453 &iwe
, IW_EV_ADDR_LEN
);
5455 /* Other entries will be displayed in the order we give them */
5458 iwe
.u
.data
.length
= le16_to_cpu(bss
->a
.essid_len
);
5459 if (iwe
.u
.data
.length
> 32)
5460 iwe
.u
.data
.length
= 32;
5461 iwe
.cmd
= SIOCGIWESSID
;
5462 iwe
.u
.data
.flags
= 1;
5463 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5464 &iwe
, bss
->a
.essid
);
5467 iwe
.cmd
= SIOCGIWMODE
;
5468 capabilities
= le16_to_cpu(bss
->a
.capabilities
);
5469 if (capabilities
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)) {
5470 if (capabilities
& WLAN_CAPABILITY_ESS
)
5471 iwe
.u
.mode
= IW_MODE_MASTER
;
5473 iwe
.u
.mode
= IW_MODE_ADHOC
;
5474 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5475 &iwe
, IW_EV_UINT_LEN
);
5478 channel
= bss
->s
.channel
;
5479 if ((channel
>= 1) && (channel
<= NUM_CHANNELS
)) {
5480 /* Add channel and frequency */
5481 iwe
.cmd
= SIOCGIWFREQ
;
5482 iwe
.u
.freq
.m
= channel
;
5484 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5485 &iwe
, IW_EV_FREQ_LEN
);
5487 iwe
.u
.freq
.m
= channel_frequency
[channel
-1] * 100000;
5489 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5490 &iwe
, IW_EV_FREQ_LEN
);
5493 /* Add quality statistics. level and noise in dB. No link quality */
5495 iwe
.u
.qual
.updated
= IW_QUAL_DBM
| IW_QUAL_QUAL_INVALID
;
5496 iwe
.u
.qual
.level
= (__u8
) le16_to_cpu(bss
->a
.level
) - 0x95;
5497 iwe
.u
.qual
.noise
= (__u8
) le16_to_cpu(bss
->a
.noise
) - 0x95;
5498 /* Wireless tools prior to 27.pre22 will show link quality
5499 * anyway, so we provide a reasonable value. */
5500 if (iwe
.u
.qual
.level
> iwe
.u
.qual
.noise
)
5501 iwe
.u
.qual
.qual
= iwe
.u
.qual
.level
- iwe
.u
.qual
.noise
;
5503 iwe
.u
.qual
.qual
= 0;
5504 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5505 &iwe
, IW_EV_QUAL_LEN
);
5507 /* Add encryption capability */
5508 iwe
.cmd
= SIOCGIWENCODE
;
5509 if (capabilities
& WLAN_CAPABILITY_PRIVACY
)
5510 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
5512 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
5513 iwe
.u
.data
.length
= 0;
5514 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5517 /* Bit rate is not available in Lucent/Agere firmwares */
5518 if (priv
->firmware_type
!= FIRMWARE_TYPE_AGERE
) {
5519 char *current_val
= current_ev
+ iwe_stream_lcp_len(info
);
5523 if (priv
->firmware_type
== FIRMWARE_TYPE_SYMBOL
)
5528 iwe
.cmd
= SIOCGIWRATE
;
5529 /* Those two flags are ignored... */
5530 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
5532 for (i
= 0; i
< 10; i
+= step
) {
5533 /* NULL terminated */
5534 if (bss
->p
.rates
[i
] == 0x0)
5536 /* Bit rate given in 500 kb/s units (+ 0x80) */
5537 iwe
.u
.bitrate
.value
=
5538 ((bss
->p
.rates
[i
] & 0x7f) * 500000);
5539 current_val
= iwe_stream_add_value(info
, current_ev
,
5544 /* Check if we added any event */
5545 if ((current_val
- current_ev
) > iwe_stream_lcp_len(info
))
5546 current_ev
= current_val
;
5549 /* Beacon interval */
5550 iwe
.cmd
= IWEVCUSTOM
;
5551 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5553 le16_to_cpu(bss
->a
.beacon_interv
));
5554 if (iwe
.u
.data
.length
)
5555 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5559 iwe
.cmd
= IWEVCUSTOM
;
5560 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5563 if (iwe
.u
.data
.length
)
5564 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5567 /* Add EXTRA: Age to display seconds since last beacon/probe response
5568 * for given network. */
5569 iwe
.cmd
= IWEVCUSTOM
;
5570 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5571 " Last beacon: %dms ago",
5572 jiffies_to_msecs(jiffies
- last_scanned
));
5573 if (iwe
.u
.data
.length
)
5574 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5580 static inline char *orinoco_translate_ext_scan(struct net_device
*dev
,
5581 struct iw_request_info
*info
,
5584 struct agere_ext_scan_info
*bss
,
5585 unsigned int last_scanned
)
5589 struct iw_event iwe
; /* Temporary buffer */
5590 char custom
[MAX_CUSTOM_LEN
];
5593 memset(&iwe
, 0, sizeof(iwe
));
5595 /* First entry *MUST* be the AP MAC address */
5596 iwe
.cmd
= SIOCGIWAP
;
5597 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
5598 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
5599 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5600 &iwe
, IW_EV_ADDR_LEN
);
5602 /* Other entries will be displayed in the order we give them */
5606 iwe
.u
.data
.length
= ie
[1];
5607 if (iwe
.u
.data
.length
) {
5608 if (iwe
.u
.data
.length
> 32)
5609 iwe
.u
.data
.length
= 32;
5610 iwe
.cmd
= SIOCGIWESSID
;
5611 iwe
.u
.data
.flags
= 1;
5612 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5617 capabilities
= le16_to_cpu(bss
->capabilities
);
5618 if (capabilities
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)) {
5619 iwe
.cmd
= SIOCGIWMODE
;
5620 if (capabilities
& WLAN_CAPABILITY_ESS
)
5621 iwe
.u
.mode
= IW_MODE_MASTER
;
5623 iwe
.u
.mode
= IW_MODE_ADHOC
;
5624 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5625 &iwe
, IW_EV_UINT_LEN
);
5628 ie
= orinoco_get_ie(bss
->data
, sizeof(bss
->data
), MFIE_TYPE_DS_SET
);
5629 channel
= ie
? ie
[2] : 0;
5630 if ((channel
>= 1) && (channel
<= NUM_CHANNELS
)) {
5631 /* Add channel and frequency */
5632 iwe
.cmd
= SIOCGIWFREQ
;
5633 iwe
.u
.freq
.m
= channel
;
5635 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5636 &iwe
, IW_EV_FREQ_LEN
);
5638 iwe
.u
.freq
.m
= channel_frequency
[channel
-1] * 100000;
5640 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5641 &iwe
, IW_EV_FREQ_LEN
);
5644 /* Add quality statistics. level and noise in dB. No link quality */
5646 iwe
.u
.qual
.updated
= IW_QUAL_DBM
| IW_QUAL_QUAL_INVALID
;
5647 iwe
.u
.qual
.level
= bss
->level
- 0x95;
5648 iwe
.u
.qual
.noise
= bss
->noise
- 0x95;
5649 /* Wireless tools prior to 27.pre22 will show link quality
5650 * anyway, so we provide a reasonable value. */
5651 if (iwe
.u
.qual
.level
> iwe
.u
.qual
.noise
)
5652 iwe
.u
.qual
.qual
= iwe
.u
.qual
.level
- iwe
.u
.qual
.noise
;
5654 iwe
.u
.qual
.qual
= 0;
5655 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5656 &iwe
, IW_EV_QUAL_LEN
);
5658 /* Add encryption capability */
5659 iwe
.cmd
= SIOCGIWENCODE
;
5660 if (capabilities
& WLAN_CAPABILITY_PRIVACY
)
5661 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
5663 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
5664 iwe
.u
.data
.length
= 0;
5665 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5669 ie
= orinoco_get_wpa_ie(bss
->data
, sizeof(bss
->data
));
5671 iwe
.cmd
= IWEVGENIE
;
5672 iwe
.u
.data
.length
= ie
[1] + 2;
5673 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5678 ie
= orinoco_get_ie(bss
->data
, sizeof(bss
->data
), MFIE_TYPE_RSN
);
5680 iwe
.cmd
= IWEVGENIE
;
5681 iwe
.u
.data
.length
= ie
[1] + 2;
5682 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5686 ie
= orinoco_get_ie(bss
->data
, sizeof(bss
->data
), MFIE_TYPE_RATES
);
5688 char *p
= current_ev
+ iwe_stream_lcp_len(info
);
5691 iwe
.cmd
= SIOCGIWRATE
;
5692 /* Those two flags are ignored... */
5693 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
5695 for (i
= 2; i
< (ie
[1] + 2); i
++) {
5696 iwe
.u
.bitrate
.value
= ((ie
[i
] & 0x7F) * 500000);
5697 p
= iwe_stream_add_value(info
, current_ev
, p
, end_buf
,
5698 &iwe
, IW_EV_PARAM_LEN
);
5700 /* Check if we added any event */
5701 if (p
> (current_ev
+ iwe_stream_lcp_len(info
)))
5706 iwe
.cmd
= IWEVCUSTOM
;
5708 snprintf(custom
, MAX_CUSTOM_LEN
, "tsf=%016llx",
5709 (unsigned long long) le64_to_cpu(bss
->timestamp
));
5710 if (iwe
.u
.data
.length
)
5711 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5714 /* Beacon interval */
5715 iwe
.cmd
= IWEVCUSTOM
;
5716 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5718 le16_to_cpu(bss
->beacon_interval
));
5719 if (iwe
.u
.data
.length
)
5720 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5724 iwe
.cmd
= IWEVCUSTOM
;
5725 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5728 if (iwe
.u
.data
.length
)
5729 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5732 /* Add EXTRA: Age to display seconds since last beacon/probe response
5733 * for given network. */
5734 iwe
.cmd
= IWEVCUSTOM
;
5735 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5736 " Last beacon: %dms ago",
5737 jiffies_to_msecs(jiffies
- last_scanned
));
5738 if (iwe
.u
.data
.length
)
5739 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5745 /* Return results of a scan */
5746 static int orinoco_ioctl_getscan(struct net_device
*dev
,
5747 struct iw_request_info
*info
,
5748 struct iw_point
*srq
,
5751 struct orinoco_private
*priv
= netdev_priv(dev
);
5753 unsigned long flags
;
5754 char *current_ev
= extra
;
5756 if (orinoco_lock(priv
, &flags
) != 0)
5759 if (priv
->scan_inprogress
) {
5760 /* Important note : we don't want to block the caller
5761 * until results are ready for various reasons.
5762 * First, managing wait queues is complex and racy.
5763 * Second, we grab some rtnetlink lock before comming
5764 * here (in dev_ioctl()).
5765 * Third, we generate an Wireless Event, so the
5766 * caller can wait itself on that - Jean II */
5771 if (priv
->has_ext_scan
) {
5772 struct xbss_element
*bss
;
5774 list_for_each_entry(bss
, &priv
->bss_list
, list
) {
5775 /* Translate this entry to WE format */
5777 orinoco_translate_ext_scan(dev
, info
,
5779 extra
+ srq
->length
,
5783 /* Check if there is space for one more entry */
5784 if ((extra
+ srq
->length
- current_ev
)
5785 <= IW_EV_ADDR_LEN
) {
5786 /* Ask user space to try again with a
5794 struct bss_element
*bss
;
5796 list_for_each_entry(bss
, &priv
->bss_list
, list
) {
5797 /* Translate this entry to WE format */
5798 current_ev
= orinoco_translate_scan(dev
, info
,
5800 extra
+ srq
->length
,
5804 /* Check if there is space for one more entry */
5805 if ((extra
+ srq
->length
- current_ev
)
5806 <= IW_EV_ADDR_LEN
) {
5807 /* Ask user space to try again with a
5815 srq
->length
= (current_ev
- extra
);
5816 srq
->flags
= (__u16
) priv
->scan_mode
;
5819 orinoco_unlock(priv
, &flags
);
5823 /* Commit handler, called after set operations */
5824 static int orinoco_ioctl_commit(struct net_device
*dev
,
5825 struct iw_request_info
*info
,
5829 struct orinoco_private
*priv
= netdev_priv(dev
);
5830 struct hermes
*hw
= &priv
->hw
;
5831 unsigned long flags
;
5837 if (priv
->broken_disableport
) {
5838 orinoco_reset(&priv
->reset_work
);
5842 if (orinoco_lock(priv
, &flags
) != 0)
5845 err
= hermes_disable_port(hw
, 0);
5847 printk(KERN_WARNING
"%s: Unable to disable port "
5848 "while reconfiguring card\n", dev
->name
);
5849 priv
->broken_disableport
= 1;
5853 err
= __orinoco_program_rids(dev
);
5855 printk(KERN_WARNING
"%s: Unable to reconfigure card\n",
5860 err
= hermes_enable_port(hw
, 0);
5862 printk(KERN_WARNING
"%s: Unable to enable port while reconfiguring card\n",
5869 printk(KERN_WARNING
"%s: Resetting instead...\n", dev
->name
);
5870 schedule_work(&priv
->reset_work
);
5874 orinoco_unlock(priv
, &flags
);
5878 static const struct iw_priv_args orinoco_privtab
[] = {
5879 { SIOCIWFIRSTPRIV
+ 0x0, 0, 0, "force_reset" },
5880 { SIOCIWFIRSTPRIV
+ 0x1, 0, 0, "card_reset" },
5881 { SIOCIWFIRSTPRIV
+ 0x2, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5883 { SIOCIWFIRSTPRIV
+ 0x3, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5885 { SIOCIWFIRSTPRIV
+ 0x4, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5886 0, "set_preamble" },
5887 { SIOCIWFIRSTPRIV
+ 0x5, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5889 { SIOCIWFIRSTPRIV
+ 0x6, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5890 0, "set_ibssport" },
5891 { SIOCIWFIRSTPRIV
+ 0x7, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5893 { SIOCIWFIRSTPRIV
+ 0x9, 0, IW_PRIV_TYPE_BYTE
| MAX_RID_LEN
,
5899 * Structures to export the Wireless Handlers
5902 #define STD_IW_HANDLER(id, func) \
5903 [IW_IOCTL_IDX(id)] = (iw_handler) func
5904 static const iw_handler orinoco_handler
[] = {
5905 STD_IW_HANDLER(SIOCSIWCOMMIT
, orinoco_ioctl_commit
),
5906 STD_IW_HANDLER(SIOCGIWNAME
, orinoco_ioctl_getname
),
5907 STD_IW_HANDLER(SIOCSIWFREQ
, orinoco_ioctl_setfreq
),
5908 STD_IW_HANDLER(SIOCGIWFREQ
, orinoco_ioctl_getfreq
),
5909 STD_IW_HANDLER(SIOCSIWMODE
, orinoco_ioctl_setmode
),
5910 STD_IW_HANDLER(SIOCGIWMODE
, orinoco_ioctl_getmode
),
5911 STD_IW_HANDLER(SIOCSIWSENS
, orinoco_ioctl_setsens
),
5912 STD_IW_HANDLER(SIOCGIWSENS
, orinoco_ioctl_getsens
),
5913 STD_IW_HANDLER(SIOCGIWRANGE
, orinoco_ioctl_getiwrange
),
5914 STD_IW_HANDLER(SIOCSIWSPY
, iw_handler_set_spy
),
5915 STD_IW_HANDLER(SIOCGIWSPY
, iw_handler_get_spy
),
5916 STD_IW_HANDLER(SIOCSIWTHRSPY
, iw_handler_set_thrspy
),
5917 STD_IW_HANDLER(SIOCGIWTHRSPY
, iw_handler_get_thrspy
),
5918 STD_IW_HANDLER(SIOCSIWAP
, orinoco_ioctl_setwap
),
5919 STD_IW_HANDLER(SIOCGIWAP
, orinoco_ioctl_getwap
),
5920 STD_IW_HANDLER(SIOCSIWSCAN
, orinoco_ioctl_setscan
),
5921 STD_IW_HANDLER(SIOCGIWSCAN
, orinoco_ioctl_getscan
),
5922 STD_IW_HANDLER(SIOCSIWESSID
, orinoco_ioctl_setessid
),
5923 STD_IW_HANDLER(SIOCGIWESSID
, orinoco_ioctl_getessid
),
5924 STD_IW_HANDLER(SIOCSIWNICKN
, orinoco_ioctl_setnick
),
5925 STD_IW_HANDLER(SIOCGIWNICKN
, orinoco_ioctl_getnick
),
5926 STD_IW_HANDLER(SIOCSIWRATE
, orinoco_ioctl_setrate
),
5927 STD_IW_HANDLER(SIOCGIWRATE
, orinoco_ioctl_getrate
),
5928 STD_IW_HANDLER(SIOCSIWRTS
, orinoco_ioctl_setrts
),
5929 STD_IW_HANDLER(SIOCGIWRTS
, orinoco_ioctl_getrts
),
5930 STD_IW_HANDLER(SIOCSIWFRAG
, orinoco_ioctl_setfrag
),
5931 STD_IW_HANDLER(SIOCGIWFRAG
, orinoco_ioctl_getfrag
),
5932 STD_IW_HANDLER(SIOCGIWRETRY
, orinoco_ioctl_getretry
),
5933 STD_IW_HANDLER(SIOCSIWENCODE
, orinoco_ioctl_setiwencode
),
5934 STD_IW_HANDLER(SIOCGIWENCODE
, orinoco_ioctl_getiwencode
),
5935 STD_IW_HANDLER(SIOCSIWPOWER
, orinoco_ioctl_setpower
),
5936 STD_IW_HANDLER(SIOCGIWPOWER
, orinoco_ioctl_getpower
),
5937 STD_IW_HANDLER(SIOCSIWGENIE
, orinoco_ioctl_set_genie
),
5938 STD_IW_HANDLER(SIOCGIWGENIE
, orinoco_ioctl_get_genie
),
5939 STD_IW_HANDLER(SIOCSIWMLME
, orinoco_ioctl_set_mlme
),
5940 STD_IW_HANDLER(SIOCSIWAUTH
, orinoco_ioctl_set_auth
),
5941 STD_IW_HANDLER(SIOCGIWAUTH
, orinoco_ioctl_get_auth
),
5942 STD_IW_HANDLER(SIOCSIWENCODEEXT
, orinoco_ioctl_set_encodeext
),
5943 STD_IW_HANDLER(SIOCGIWENCODEEXT
, orinoco_ioctl_get_encodeext
),
5948 Added typecasting since we no longer use iwreq_data -- Moustafa
5950 static const iw_handler orinoco_private_handler
[] = {
5951 [0] = (iw_handler
) orinoco_ioctl_reset
,
5952 [1] = (iw_handler
) orinoco_ioctl_reset
,
5953 [2] = (iw_handler
) orinoco_ioctl_setport3
,
5954 [3] = (iw_handler
) orinoco_ioctl_getport3
,
5955 [4] = (iw_handler
) orinoco_ioctl_setpreamble
,
5956 [5] = (iw_handler
) orinoco_ioctl_getpreamble
,
5957 [6] = (iw_handler
) orinoco_ioctl_setibssport
,
5958 [7] = (iw_handler
) orinoco_ioctl_getibssport
,
5959 [9] = (iw_handler
) orinoco_ioctl_getrid
,
5962 static const struct iw_handler_def orinoco_handler_def
= {
5963 .num_standard
= ARRAY_SIZE(orinoco_handler
),
5964 .num_private
= ARRAY_SIZE(orinoco_private_handler
),
5965 .num_private_args
= ARRAY_SIZE(orinoco_privtab
),
5966 .standard
= orinoco_handler
,
5967 .private = orinoco_private_handler
,
5968 .private_args
= orinoco_privtab
,
5969 .get_wireless_stats
= orinoco_get_wireless_stats
,
5972 static void orinoco_get_drvinfo(struct net_device
*dev
,
5973 struct ethtool_drvinfo
*info
)
5975 struct orinoco_private
*priv
= netdev_priv(dev
);
5977 strncpy(info
->driver
, DRIVER_NAME
, sizeof(info
->driver
) - 1);
5978 strncpy(info
->version
, DRIVER_VERSION
, sizeof(info
->version
) - 1);
5979 strncpy(info
->fw_version
, priv
->fw_name
, sizeof(info
->fw_version
) - 1);
5980 if (dev
->dev
.parent
)
5981 strncpy(info
->bus_info
, dev
->dev
.parent
->bus_id
,
5982 sizeof(info
->bus_info
) - 1);
5984 snprintf(info
->bus_info
, sizeof(info
->bus_info
) - 1,
5985 "PCMCIA %p", priv
->hw
.iobase
);
5988 static const struct ethtool_ops orinoco_ethtool_ops
= {
5989 .get_drvinfo
= orinoco_get_drvinfo
,
5990 .get_link
= ethtool_op_get_link
,
5993 /********************************************************************/
5994 /* Module initialization */
5995 /********************************************************************/
5997 EXPORT_SYMBOL(alloc_orinocodev
);
5998 EXPORT_SYMBOL(free_orinocodev
);
6000 EXPORT_SYMBOL(__orinoco_up
);
6001 EXPORT_SYMBOL(__orinoco_down
);
6002 EXPORT_SYMBOL(orinoco_reinit_firmware
);
6004 EXPORT_SYMBOL(orinoco_interrupt
);
6006 /* Can't be declared "const" or the whole __initdata section will
6008 static char version
[] __initdata
= DRIVER_NAME
" " DRIVER_VERSION
6009 " (David Gibson <hermes@gibson.dropbear.id.au>, "
6010 "Pavel Roskin <proski@gnu.org>, et al)";
6012 static int __init
init_orinoco(void)
6014 printk(KERN_DEBUG
"%s\n", version
);
6018 static void __exit
exit_orinoco(void)
6022 module_init(init_orinoco
);
6023 module_exit(exit_orinoco
);