1 /* orinoco.c - (formerly known as dldwd_cs.c and orinoco_cs.c)
3 * A driver for Hermes or Prism 2 chipset based PCMCIA wireless
4 * adaptors, with Lucent/Agere, Intersil or Symbol firmware.
6 * Current maintainers (as of 29 September 2003) are:
7 * Pavel Roskin <proski AT gnu.org>
8 * and David Gibson <hermes AT gibson.dropbear.id.au>
10 * (C) Copyright David Gibson, IBM Corporation 2001-2003.
11 * Copyright (C) 2000 David Gibson, Linuxcare Australia.
12 * With some help from :
13 * Copyright (C) 2001 Jean Tourrilhes, HP Labs
14 * Copyright (C) 2001 Benjamin Herrenschmidt
16 * Based on dummy_cs.c 1.27 2000/06/12 21:27:25
18 * Portions based on wvlan_cs.c 1.0.6, Copyright Andreas Neuhaus <andy
19 * AT fasta.fh-dortmund.de>
20 * http://www.stud.fh-dortmund.de/~andy/wvlan/
22 * The contents of this file are subject to the Mozilla Public License
23 * Version 1.1 (the "License"); you may not use this file except in
24 * compliance with the License. You may obtain a copy of the License
25 * at http://www.mozilla.org/MPL/
27 * Software distributed under the License is distributed on an "AS IS"
28 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
29 * the License for the specific language governing rights and
30 * limitations under the License.
32 * The initial developer of the original code is David A. Hinds
33 * <dahinds AT users.sourceforge.net>. Portions created by David
34 * A. Hinds are Copyright (C) 1999 David A. Hinds. All Rights
37 * Alternatively, the contents of this file may be used under the
38 * terms of the GNU General Public License version 2 (the "GPL"), in
39 * which case the provisions of the GPL are applicable instead of the
40 * above. If you wish to allow the use of your version of this file
41 * only under the terms of the GPL and not to allow others to use your
42 * version of this file under the MPL, indicate your decision by
43 * deleting the provisions above and replace them with the notice and
44 * other provisions required by the GPL. If you do not delete the
45 * provisions above, a recipient may use your version of this file
46 * under either the MPL or the GPL. */
50 * o Handle de-encapsulation within network layer, provide 802.11
51 * headers (patch from Thomas 'Dent' Mirlacher)
52 * o Fix possible races in SPY handling.
53 * o Disconnect wireless extensions from fundamental configuration.
54 * o (maybe) Software WEP support (patch from Stano Meduna).
55 * o (maybe) Use multiple Tx buffers - driver handling queue
56 * rather than firmware.
59 /* Locking and synchronization:
61 * The basic principle is that everything is serialized through a
62 * single spinlock, priv->lock. The lock is used in user, bh and irq
63 * context, so when taken outside hardirq context it should always be
64 * taken with interrupts disabled. The lock protects both the
65 * hardware and the struct orinoco_private.
67 * Another flag, priv->hw_unavailable indicates that the hardware is
68 * unavailable for an extended period of time (e.g. suspended, or in
69 * the middle of a hard reset). This flag is protected by the
70 * spinlock. All code which touches the hardware should check the
71 * flag after taking the lock, and if it is set, give up on whatever
72 * they are doing and drop the lock again. The orinoco_lock()
73 * function handles this (it unlocks and returns -EBUSY if
74 * hw_unavailable is non-zero).
77 #define DRIVER_NAME "orinoco"
79 #include <linux/module.h>
80 #include <linux/kernel.h>
81 #include <linux/init.h>
82 #include <linux/delay.h>
83 #include <linux/netdevice.h>
84 #include <linux/etherdevice.h>
85 #include <linux/ethtool.h>
86 #include <linux/firmware.h>
87 #include <linux/if_arp.h>
88 #include <linux/wireless.h>
89 #include <net/iw_handler.h>
90 #include <net/ieee80211.h>
92 #include <linux/scatterlist.h>
93 #include <linux/crypto.h>
95 #include "hermes_rid.h"
96 #include "hermes_dld.h"
99 /********************************************************************/
100 /* Module information */
101 /********************************************************************/
103 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
104 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
105 MODULE_LICENSE("Dual MPL/GPL");
107 /* Level of debugging. Used in the macros in orinoco.h */
109 int orinoco_debug
= ORINOCO_DEBUG
;
110 module_param(orinoco_debug
, int, 0644);
111 MODULE_PARM_DESC(orinoco_debug
, "Debug level");
112 EXPORT_SYMBOL(orinoco_debug
);
115 static int suppress_linkstatus
; /* = 0 */
116 module_param(suppress_linkstatus
, bool, 0644);
117 MODULE_PARM_DESC(suppress_linkstatus
, "Don't log link status changes");
118 static int ignore_disconnect
; /* = 0 */
119 module_param(ignore_disconnect
, int, 0644);
120 MODULE_PARM_DESC(ignore_disconnect
, "Don't report lost link to the network layer");
122 static int force_monitor
; /* = 0 */
123 module_param(force_monitor
, int, 0644);
124 MODULE_PARM_DESC(force_monitor
, "Allow monitor mode for all firmware versions");
126 /********************************************************************/
127 /* Compile time configuration and compatibility stuff */
128 /********************************************************************/
130 /* We do this this way to avoid ifdefs in the actual code */
132 #define SPY_NUMBER(priv) (priv->spy_data.spy_number)
134 #define SPY_NUMBER(priv) 0
135 #endif /* WIRELESS_SPY */
137 /********************************************************************/
138 /* Internal constants */
139 /********************************************************************/
141 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
142 static const u8 encaps_hdr
[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
143 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
145 #define ORINOCO_MIN_MTU 256
146 #define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
148 #define SYMBOL_MAX_VER_LEN (14)
151 #define MAX_IRQLOOPS_PER_IRQ 10
152 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
153 * how many events the
155 * legitimately generate */
156 #define SMALL_KEY_SIZE 5
157 #define LARGE_KEY_SIZE 13
158 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
160 #define DUMMY_FID 0xFFFF
162 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
163 HERMES_MAX_MULTICAST : 0)*/
164 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
166 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
167 | HERMES_EV_TX | HERMES_EV_TXEXC \
168 | HERMES_EV_WTERR | HERMES_EV_INFO \
169 | HERMES_EV_INFDROP )
171 #define MAX_RID_LEN 1024
173 static const struct iw_handler_def orinoco_handler_def
;
174 static const struct ethtool_ops orinoco_ethtool_ops
;
176 /********************************************************************/
178 /********************************************************************/
180 /* The frequency of each channel in MHz */
181 static const long channel_frequency
[] = {
182 2412, 2417, 2422, 2427, 2432, 2437, 2442,
183 2447, 2452, 2457, 2462, 2467, 2472, 2484
185 #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
187 /* This tables gives the actual meanings of the bitrate IDs returned
188 * by the firmware. */
190 int bitrate
; /* in 100s of kilobits */
192 u16 agere_txratectrl
;
193 u16 intersil_txratectrl
;
194 } bitrate_table
[] = {
195 {110, 1, 3, 15}, /* Entry 0 is the default */
204 #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
206 /********************************************************************/
208 /********************************************************************/
210 /* Beginning of the Tx descriptor, used in TxExc handling */
211 struct hermes_txexc_data
{
212 struct hermes_tx_descriptor desc
;
216 } __attribute__ ((packed
));
218 /* Rx frame header except compatibility 802.3 header */
219 struct hermes_rx_descriptor
{
240 } __attribute__ ((packed
));
242 /********************************************************************/
243 /* Function prototypes */
244 /********************************************************************/
246 static int __orinoco_program_rids(struct net_device
*dev
);
247 static void __orinoco_set_multicast_list(struct net_device
*dev
);
249 /********************************************************************/
250 /* Michael MIC crypto setup */
251 /********************************************************************/
252 #define MICHAEL_MIC_LEN 8
253 static int orinoco_mic_init(struct orinoco_private
*priv
)
255 priv
->tx_tfm_mic
= crypto_alloc_hash("michael_mic", 0, 0);
256 if (IS_ERR(priv
->tx_tfm_mic
)) {
257 printk(KERN_DEBUG
"orinoco_mic_init: could not allocate "
258 "crypto API michael_mic\n");
259 priv
->tx_tfm_mic
= NULL
;
263 priv
->rx_tfm_mic
= crypto_alloc_hash("michael_mic", 0, 0);
264 if (IS_ERR(priv
->rx_tfm_mic
)) {
265 printk(KERN_DEBUG
"orinoco_mic_init: could not allocate "
266 "crypto API michael_mic\n");
267 priv
->rx_tfm_mic
= NULL
;
274 static void orinoco_mic_free(struct orinoco_private
*priv
)
276 if (priv
->tx_tfm_mic
)
277 crypto_free_hash(priv
->tx_tfm_mic
);
278 if (priv
->rx_tfm_mic
)
279 crypto_free_hash(priv
->rx_tfm_mic
);
282 static int michael_mic(struct crypto_hash
*tfm_michael
, u8
*key
,
283 u8
*da
, u8
*sa
, u8 priority
,
284 u8
*data
, size_t data_len
, u8
*mic
)
286 struct hash_desc desc
;
287 struct scatterlist sg
[2];
288 u8 hdr
[ETH_HLEN
+ 2]; /* size of header + padding */
290 if (tfm_michael
== NULL
) {
291 printk(KERN_WARNING
"michael_mic: tfm_michael == NULL\n");
295 /* Copy header into buffer. We need the padding on the end zeroed */
296 memcpy(&hdr
[0], da
, ETH_ALEN
);
297 memcpy(&hdr
[ETH_ALEN
], sa
, ETH_ALEN
);
298 hdr
[ETH_ALEN
*2] = priority
;
299 hdr
[ETH_ALEN
*2+1] = 0;
300 hdr
[ETH_ALEN
*2+2] = 0;
301 hdr
[ETH_ALEN
*2+3] = 0;
303 /* Use scatter gather to MIC header and data in one go */
304 sg_init_table(sg
, 2);
305 sg_set_buf(&sg
[0], hdr
, sizeof(hdr
));
306 sg_set_buf(&sg
[1], data
, data_len
);
308 if (crypto_hash_setkey(tfm_michael
, key
, MIC_KEYLEN
))
311 desc
.tfm
= tfm_michael
;
313 return crypto_hash_digest(&desc
, sg
, data_len
+ sizeof(hdr
),
317 /********************************************************************/
318 /* Internal helper functions */
319 /********************************************************************/
321 static inline void set_port_type(struct orinoco_private
*priv
)
323 switch (priv
->iw_mode
) {
326 priv
->createibss
= 0;
329 if (priv
->prefer_port3
) {
331 priv
->createibss
= 0;
333 priv
->port_type
= priv
->ibss_port
;
334 priv
->createibss
= 1;
337 case IW_MODE_MONITOR
:
339 priv
->createibss
= 0;
342 printk(KERN_ERR
"%s: Invalid priv->iw_mode in set_port_type()\n",
347 #define ORINOCO_MAX_BSS_COUNT 64
348 static int orinoco_bss_data_allocate(struct orinoco_private
*priv
)
350 if (priv
->bss_xbss_data
)
353 if (priv
->has_ext_scan
)
354 priv
->bss_xbss_data
= kzalloc(ORINOCO_MAX_BSS_COUNT
*
355 sizeof(struct xbss_element
),
358 priv
->bss_xbss_data
= kzalloc(ORINOCO_MAX_BSS_COUNT
*
359 sizeof(struct bss_element
),
362 if (!priv
->bss_xbss_data
) {
363 printk(KERN_WARNING
"Out of memory allocating beacons");
369 static void orinoco_bss_data_free(struct orinoco_private
*priv
)
371 kfree(priv
->bss_xbss_data
);
372 priv
->bss_xbss_data
= NULL
;
375 #define PRIV_BSS ((struct bss_element *)priv->bss_xbss_data)
376 #define PRIV_XBSS ((struct xbss_element *)priv->bss_xbss_data)
377 static void orinoco_bss_data_init(struct orinoco_private
*priv
)
381 INIT_LIST_HEAD(&priv
->bss_free_list
);
382 INIT_LIST_HEAD(&priv
->bss_list
);
383 if (priv
->has_ext_scan
)
384 for (i
= 0; i
< ORINOCO_MAX_BSS_COUNT
; i
++)
385 list_add_tail(&(PRIV_XBSS
[i
].list
),
386 &priv
->bss_free_list
);
388 for (i
= 0; i
< ORINOCO_MAX_BSS_COUNT
; i
++)
389 list_add_tail(&(PRIV_BSS
[i
].list
),
390 &priv
->bss_free_list
);
394 static inline u8
*orinoco_get_ie(u8
*data
, size_t len
,
395 enum ieee80211_mfie eid
)
398 while ((p
+ 2) < (data
+ len
)) {
406 #define WPA_OUI_TYPE "\x00\x50\xF2\x01"
407 #define WPA_SELECTOR_LEN 4
408 static inline u8
*orinoco_get_wpa_ie(u8
*data
, size_t len
)
411 while ((p
+ 2 + WPA_SELECTOR_LEN
) < (data
+ len
)) {
412 if ((p
[0] == MFIE_TYPE_GENERIC
) &&
413 (memcmp(&p
[2], WPA_OUI_TYPE
, WPA_SELECTOR_LEN
) == 0))
421 /********************************************************************/
422 /* Download functionality */
423 /********************************************************************/
433 const static struct fw_info orinoco_fw
[] = {
434 { "", "agere_sta_fw.bin", "agere_ap_fw.bin", 0x00390000, 1000 },
435 { "", "prism_sta_fw.bin", "prism_ap_fw.bin", 0, 1024 },
436 { "symbol_sp24t_prim_fw", "symbol_sp24t_sec_fw", "", 0x00003100, 512 }
439 /* Structure used to access fields in FW
440 * Make sure LE decoding macros are used
442 struct orinoco_fw_header
{
443 char hdr_vers
[6]; /* ASCII string for header version */
444 __le16 headersize
; /* Total length of header */
445 __le32 entry_point
; /* NIC entry point */
446 __le32 blocks
; /* Number of blocks to program */
447 __le32 block_offset
; /* Offset of block data from eof header */
448 __le32 pdr_offset
; /* Offset to PDR data from eof header */
449 __le32 pri_offset
; /* Offset to primary plug data */
450 __le32 compat_offset
; /* Offset to compatibility data*/
451 char signature
[0]; /* FW signature length headersize-20 */
452 } __attribute__ ((packed
));
454 /* Download either STA or AP firmware into the card. */
456 orinoco_dl_firmware(struct orinoco_private
*priv
,
457 const struct fw_info
*fw
,
460 /* Plug Data Area (PDA) */
463 hermes_t
*hw
= &priv
->hw
;
464 const struct firmware
*fw_entry
;
465 const struct orinoco_fw_header
*hdr
;
466 const unsigned char *first_block
;
467 const unsigned char *end
;
468 const char *firmware
;
469 struct net_device
*dev
= priv
->ndev
;
472 pda
= kzalloc(fw
->pda_size
, GFP_KERNEL
);
477 firmware
= fw
->ap_fw
;
479 firmware
= fw
->sta_fw
;
481 printk(KERN_DEBUG
"%s: Attempting to download firmware %s\n",
482 dev
->name
, firmware
);
484 /* Read current plug data */
485 err
= hermes_read_pda(hw
, pda
, fw
->pda_addr
, fw
->pda_size
, 0);
486 printk(KERN_DEBUG
"%s: Read PDA returned %d\n", dev
->name
, err
);
490 err
= request_firmware(&fw_entry
, firmware
, priv
->dev
);
492 printk(KERN_ERR
"%s: Cannot find firmware %s\n",
493 dev
->name
, firmware
);
498 hdr
= (const struct orinoco_fw_header
*) fw_entry
->data
;
500 /* Enable aux port to allow programming */
501 err
= hermesi_program_init(hw
, le32_to_cpu(hdr
->entry_point
));
502 printk(KERN_DEBUG
"%s: Program init returned %d\n", dev
->name
, err
);
507 first_block
= (fw_entry
->data
+
508 le16_to_cpu(hdr
->headersize
) +
509 le32_to_cpu(hdr
->block_offset
));
510 end
= fw_entry
->data
+ fw_entry
->size
;
512 err
= hermes_program(hw
, first_block
, end
);
513 printk(KERN_DEBUG
"%s: Program returned %d\n", dev
->name
, err
);
517 /* Update production data */
518 first_block
= (fw_entry
->data
+
519 le16_to_cpu(hdr
->headersize
) +
520 le32_to_cpu(hdr
->pdr_offset
));
522 err
= hermes_apply_pda_with_defaults(hw
, first_block
, pda
);
523 printk(KERN_DEBUG
"%s: Apply PDA returned %d\n", dev
->name
, err
);
527 /* Tell card we've finished */
528 err
= hermesi_program_end(hw
);
529 printk(KERN_DEBUG
"%s: Program end returned %d\n", dev
->name
, err
);
533 /* Check if we're running */
534 printk(KERN_DEBUG
"%s: hermes_present returned %d\n",
535 dev
->name
, hermes_present(hw
));
538 release_firmware(fw_entry
);
546 #define TEXT_END 0x1A /* End of text header */
549 * Process a firmware image - stop the card, load the firmware, reset
550 * the card and make sure it responds. For the secondary firmware take
551 * care of the PDA - read it and then write it on top of the firmware.
554 symbol_dl_image(struct orinoco_private
*priv
, const struct fw_info
*fw
,
555 const unsigned char *image
, const unsigned char *end
,
558 hermes_t
*hw
= &priv
->hw
;
560 const unsigned char *ptr
;
561 const unsigned char *first_block
;
563 /* Plug Data Area (PDA) */
566 /* Binary block begins after the 0x1A marker */
568 while (*ptr
++ != TEXT_END
);
571 /* Read the PDA from EEPROM */
573 pda
= kzalloc(fw
->pda_size
, GFP_KERNEL
);
577 ret
= hermes_read_pda(hw
, pda
, fw
->pda_addr
, fw
->pda_size
, 1);
582 /* Stop the firmware, so that it can be safely rewritten */
584 ret
= priv
->stop_fw(priv
, 1);
589 /* Program the adapter with new firmware */
590 ret
= hermes_program(hw
, first_block
, end
);
594 /* Write the PDA to the adapter */
596 size_t len
= hermes_blocks_length(first_block
);
597 ptr
= first_block
+ len
;
598 ret
= hermes_apply_pda(hw
, ptr
, pda
);
604 /* Run the firmware */
606 ret
= priv
->stop_fw(priv
, 0);
611 /* Reset hermes chip and make sure it responds */
612 ret
= hermes_init(hw
);
614 /* hermes_reset() should return 0 with the secondary firmware */
615 if (secondary
&& ret
!= 0)
618 /* And this should work with any firmware */
619 if (!hermes_present(hw
))
631 * Download the firmware into the card, this also does a PCMCIA soft
632 * reset on the card, to make sure it's in a sane state.
635 symbol_dl_firmware(struct orinoco_private
*priv
,
636 const struct fw_info
*fw
)
638 struct net_device
*dev
= priv
->ndev
;
640 const struct firmware
*fw_entry
;
642 if (request_firmware(&fw_entry
, fw
->pri_fw
,
644 printk(KERN_ERR
"%s: Cannot find firmware: %s\n",
645 dev
->name
, fw
->pri_fw
);
649 /* Load primary firmware */
650 ret
= symbol_dl_image(priv
, fw
, fw_entry
->data
,
651 fw_entry
->data
+ fw_entry
->size
, 0);
652 release_firmware(fw_entry
);
654 printk(KERN_ERR
"%s: Primary firmware download failed\n",
659 if (request_firmware(&fw_entry
, fw
->sta_fw
,
661 printk(KERN_ERR
"%s: Cannot find firmware: %s\n",
662 dev
->name
, fw
->sta_fw
);
666 /* Load secondary firmware */
667 ret
= symbol_dl_image(priv
, fw
, fw_entry
->data
,
668 fw_entry
->data
+ fw_entry
->size
, 1);
669 release_firmware(fw_entry
);
671 printk(KERN_ERR
"%s: Secondary firmware download failed\n",
678 static int orinoco_download(struct orinoco_private
*priv
)
681 /* Reload firmware */
682 switch (priv
->firmware_type
) {
683 case FIRMWARE_TYPE_AGERE
:
684 /* case FIRMWARE_TYPE_INTERSIL: */
685 err
= orinoco_dl_firmware(priv
,
686 &orinoco_fw
[priv
->firmware_type
], 0);
689 case FIRMWARE_TYPE_SYMBOL
:
690 err
= symbol_dl_firmware(priv
,
691 &orinoco_fw
[priv
->firmware_type
]);
693 case FIRMWARE_TYPE_INTERSIL
:
696 /* TODO: if we fail we probably need to reinitialise
702 /********************************************************************/
704 /********************************************************************/
706 static int orinoco_open(struct net_device
*dev
)
708 struct orinoco_private
*priv
= netdev_priv(dev
);
712 if (orinoco_lock(priv
, &flags
) != 0)
715 err
= __orinoco_up(dev
);
720 orinoco_unlock(priv
, &flags
);
725 static int orinoco_stop(struct net_device
*dev
)
727 struct orinoco_private
*priv
= netdev_priv(dev
);
730 /* We mustn't use orinoco_lock() here, because we need to be
731 able to close the interface even if hw_unavailable is set
732 (e.g. as we're released after a PC Card removal) */
733 spin_lock_irq(&priv
->lock
);
737 err
= __orinoco_down(dev
);
739 spin_unlock_irq(&priv
->lock
);
744 static struct net_device_stats
*orinoco_get_stats(struct net_device
*dev
)
746 struct orinoco_private
*priv
= netdev_priv(dev
);
751 static struct iw_statistics
*orinoco_get_wireless_stats(struct net_device
*dev
)
753 struct orinoco_private
*priv
= netdev_priv(dev
);
754 hermes_t
*hw
= &priv
->hw
;
755 struct iw_statistics
*wstats
= &priv
->wstats
;
759 if (! netif_device_present(dev
)) {
760 printk(KERN_WARNING
"%s: get_wireless_stats() called while device not present\n",
762 return NULL
; /* FIXME: Can we do better than this? */
765 /* If busy, return the old stats. Returning NULL may cause
766 * the interface to disappear from /proc/net/wireless */
767 if (orinoco_lock(priv
, &flags
) != 0)
770 /* We can't really wait for the tallies inquiry command to
771 * complete, so we just use the previous results and trigger
772 * a new tallies inquiry command for next time - Jean II */
773 /* FIXME: Really we should wait for the inquiry to come back -
774 * as it is the stats we give don't make a whole lot of sense.
775 * Unfortunately, it's not clear how to do that within the
776 * wireless extensions framework: I think we're in user
777 * context, but a lock seems to be held by the time we get in
778 * here so we're not safe to sleep here. */
779 hermes_inquire(hw
, HERMES_INQ_TALLIES
);
781 if (priv
->iw_mode
== IW_MODE_ADHOC
) {
782 memset(&wstats
->qual
, 0, sizeof(wstats
->qual
));
783 /* If a spy address is defined, we report stats of the
784 * first spy address - Jean II */
785 if (SPY_NUMBER(priv
)) {
786 wstats
->qual
.qual
= priv
->spy_data
.spy_stat
[0].qual
;
787 wstats
->qual
.level
= priv
->spy_data
.spy_stat
[0].level
;
788 wstats
->qual
.noise
= priv
->spy_data
.spy_stat
[0].noise
;
789 wstats
->qual
.updated
= priv
->spy_data
.spy_stat
[0].updated
;
793 __le16 qual
, signal
, noise
, unused
;
794 } __attribute__ ((packed
)) cq
;
796 err
= HERMES_READ_RECORD(hw
, USER_BAP
,
797 HERMES_RID_COMMSQUALITY
, &cq
);
800 wstats
->qual
.qual
= (int)le16_to_cpu(cq
.qual
);
801 wstats
->qual
.level
= (int)le16_to_cpu(cq
.signal
) - 0x95;
802 wstats
->qual
.noise
= (int)le16_to_cpu(cq
.noise
) - 0x95;
803 wstats
->qual
.updated
= 7;
807 orinoco_unlock(priv
, &flags
);
811 static void orinoco_set_multicast_list(struct net_device
*dev
)
813 struct orinoco_private
*priv
= netdev_priv(dev
);
816 if (orinoco_lock(priv
, &flags
) != 0) {
817 printk(KERN_DEBUG
"%s: orinoco_set_multicast_list() "
818 "called when hw_unavailable\n", dev
->name
);
822 __orinoco_set_multicast_list(dev
);
823 orinoco_unlock(priv
, &flags
);
826 static int orinoco_change_mtu(struct net_device
*dev
, int new_mtu
)
828 struct orinoco_private
*priv
= netdev_priv(dev
);
830 if ( (new_mtu
< ORINOCO_MIN_MTU
) || (new_mtu
> ORINOCO_MAX_MTU
) )
833 if ( (new_mtu
+ ENCAPS_OVERHEAD
+ IEEE80211_HLEN
) >
834 (priv
->nicbuf_size
- ETH_HLEN
) )
842 /********************************************************************/
844 /********************************************************************/
846 static int orinoco_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
848 struct orinoco_private
*priv
= netdev_priv(dev
);
849 struct net_device_stats
*stats
= &priv
->stats
;
850 hermes_t
*hw
= &priv
->hw
;
852 u16 txfid
= priv
->txfid
;
857 if (! netif_running(dev
)) {
858 printk(KERN_ERR
"%s: Tx on stopped device!\n",
860 return NETDEV_TX_BUSY
;
863 if (netif_queue_stopped(dev
)) {
864 printk(KERN_DEBUG
"%s: Tx while transmitter busy!\n",
866 return NETDEV_TX_BUSY
;
869 if (orinoco_lock(priv
, &flags
) != 0) {
870 printk(KERN_ERR
"%s: orinoco_xmit() called while hw_unavailable\n",
872 return NETDEV_TX_BUSY
;
875 if (! netif_carrier_ok(dev
) || (priv
->iw_mode
== IW_MODE_MONITOR
)) {
876 /* Oops, the firmware hasn't established a connection,
877 silently drop the packet (this seems to be the
882 /* Check packet length */
883 if (skb
->len
< ETH_HLEN
)
886 tx_control
= HERMES_TXCTRL_TX_OK
| HERMES_TXCTRL_TX_EX
;
888 if (priv
->encode_alg
== IW_ENCODE_ALG_TKIP
)
889 tx_control
|= (priv
->tx_key
<< HERMES_MIC_KEY_ID_SHIFT
) |
892 if (priv
->has_alt_txcntl
) {
893 /* WPA enabled firmwares have tx_cntl at the end of
894 * the 802.11 header. So write zeroed descriptor and
895 * 802.11 header at the same time
897 char desc
[HERMES_802_3_OFFSET
];
898 __le16
*txcntl
= (__le16
*) &desc
[HERMES_TXCNTL2_OFFSET
];
900 memset(&desc
, 0, sizeof(desc
));
902 *txcntl
= cpu_to_le16(tx_control
);
903 err
= hermes_bap_pwrite(hw
, USER_BAP
, &desc
, sizeof(desc
),
907 printk(KERN_ERR
"%s: Error %d writing Tx "
908 "descriptor to BAP\n", dev
->name
, err
);
912 struct hermes_tx_descriptor desc
;
914 memset(&desc
, 0, sizeof(desc
));
916 desc
.tx_control
= cpu_to_le16(tx_control
);
917 err
= hermes_bap_pwrite(hw
, USER_BAP
, &desc
, sizeof(desc
),
921 printk(KERN_ERR
"%s: Error %d writing Tx "
922 "descriptor to BAP\n", dev
->name
, err
);
926 /* Clear the 802.11 header and data length fields - some
927 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
928 * if this isn't done. */
929 hermes_clear_words(hw
, HERMES_DATA0
,
930 HERMES_802_3_OFFSET
- HERMES_802_11_OFFSET
);
933 eh
= (struct ethhdr
*)skb
->data
;
935 /* Encapsulate Ethernet-II frames */
936 if (ntohs(eh
->h_proto
) > ETH_DATA_LEN
) { /* Ethernet-II frame */
937 struct header_struct
{
938 struct ethhdr eth
; /* 802.3 header */
939 u8 encap
[6]; /* 802.2 header */
940 } __attribute__ ((packed
)) hdr
;
942 /* Strip destination and source from the data */
943 skb_pull(skb
, 2 * ETH_ALEN
);
945 /* And move them to a separate header */
946 memcpy(&hdr
.eth
, eh
, 2 * ETH_ALEN
);
947 hdr
.eth
.h_proto
= htons(sizeof(encaps_hdr
) + skb
->len
);
948 memcpy(hdr
.encap
, encaps_hdr
, sizeof(encaps_hdr
));
950 /* Insert the SNAP header */
951 if (skb_headroom(skb
) < sizeof(hdr
)) {
953 "%s: Not enough headroom for 802.2 headers %d\n",
954 dev
->name
, skb_headroom(skb
));
957 eh
= (struct ethhdr
*) skb_push(skb
, sizeof(hdr
));
958 memcpy(eh
, &hdr
, sizeof(hdr
));
961 err
= hermes_bap_pwrite(hw
, USER_BAP
, skb
->data
, skb
->len
,
962 txfid
, HERMES_802_3_OFFSET
);
964 printk(KERN_ERR
"%s: Error %d writing packet to BAP\n",
969 /* Calculate Michael MIC */
970 if (priv
->encode_alg
== IW_ENCODE_ALG_TKIP
) {
971 u8 mic_buf
[MICHAEL_MIC_LEN
+ 1];
977 /* MIC start is on an odd boundary */
978 mic_buf
[0] = skb
->data
[skb
->len
- 1];
980 offset
= skb
->len
- 1;
981 len
= MICHAEL_MIC_LEN
+ 1;
985 len
= MICHAEL_MIC_LEN
;
988 michael_mic(priv
->tx_tfm_mic
,
989 priv
->tkip_key
[priv
->tx_key
].tx_mic
,
990 eh
->h_dest
, eh
->h_source
, 0 /* priority */,
991 skb
->data
+ ETH_HLEN
, skb
->len
- ETH_HLEN
, mic
);
994 err
= hermes_bap_pwrite(hw
, USER_BAP
, &mic_buf
[0], len
,
995 txfid
, HERMES_802_3_OFFSET
+ offset
);
997 printk(KERN_ERR
"%s: Error %d writing MIC to BAP\n",
1003 /* Finally, we actually initiate the send */
1004 netif_stop_queue(dev
);
1006 err
= hermes_docmd_wait(hw
, HERMES_CMD_TX
| HERMES_CMD_RECL
,
1009 netif_start_queue(dev
);
1010 if (net_ratelimit())
1011 printk(KERN_ERR
"%s: Error %d transmitting packet\n",
1016 dev
->trans_start
= jiffies
;
1017 stats
->tx_bytes
+= HERMES_802_3_OFFSET
+ skb
->len
;
1022 stats
->tx_dropped
++;
1025 orinoco_unlock(priv
, &flags
);
1027 return NETDEV_TX_OK
;
1031 schedule_work(&priv
->reset_work
);
1032 orinoco_unlock(priv
, &flags
);
1033 return NETDEV_TX_BUSY
;
1036 static void __orinoco_ev_alloc(struct net_device
*dev
, hermes_t
*hw
)
1038 struct orinoco_private
*priv
= netdev_priv(dev
);
1039 u16 fid
= hermes_read_regn(hw
, ALLOCFID
);
1041 if (fid
!= priv
->txfid
) {
1042 if (fid
!= DUMMY_FID
)
1043 printk(KERN_WARNING
"%s: Allocate event on unexpected fid (%04X)\n",
1048 hermes_write_regn(hw
, ALLOCFID
, DUMMY_FID
);
1051 static void __orinoco_ev_tx(struct net_device
*dev
, hermes_t
*hw
)
1053 struct orinoco_private
*priv
= netdev_priv(dev
);
1054 struct net_device_stats
*stats
= &priv
->stats
;
1056 stats
->tx_packets
++;
1058 netif_wake_queue(dev
);
1060 hermes_write_regn(hw
, TXCOMPLFID
, DUMMY_FID
);
1063 static void __orinoco_ev_txexc(struct net_device
*dev
, hermes_t
*hw
)
1065 struct orinoco_private
*priv
= netdev_priv(dev
);
1066 struct net_device_stats
*stats
= &priv
->stats
;
1067 u16 fid
= hermes_read_regn(hw
, TXCOMPLFID
);
1069 struct hermes_txexc_data hdr
;
1072 if (fid
== DUMMY_FID
)
1073 return; /* Nothing's really happened */
1075 /* Read part of the frame header - we need status and addr1 */
1076 err
= hermes_bap_pread(hw
, IRQ_BAP
, &hdr
,
1077 sizeof(struct hermes_txexc_data
),
1080 hermes_write_regn(hw
, TXCOMPLFID
, DUMMY_FID
);
1084 printk(KERN_WARNING
"%s: Unable to read descriptor on Tx error "
1085 "(FID=%04X error %d)\n",
1086 dev
->name
, fid
, err
);
1090 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev
->name
,
1093 /* We produce a TXDROP event only for retry or lifetime
1094 * exceeded, because that's the only status that really mean
1095 * that this particular node went away.
1096 * Other errors means that *we* screwed up. - Jean II */
1097 status
= le16_to_cpu(hdr
.desc
.status
);
1098 if (status
& (HERMES_TXSTAT_RETRYERR
| HERMES_TXSTAT_AGEDERR
)) {
1099 union iwreq_data wrqu
;
1101 /* Copy 802.11 dest address.
1102 * We use the 802.11 header because the frame may
1103 * not be 802.3 or may be mangled...
1104 * In Ad-Hoc mode, it will be the node address.
1105 * In managed mode, it will be most likely the AP addr
1106 * User space will figure out how to convert it to
1107 * whatever it needs (IP address or else).
1109 memcpy(wrqu
.addr
.sa_data
, hdr
.addr1
, ETH_ALEN
);
1110 wrqu
.addr
.sa_family
= ARPHRD_ETHER
;
1112 /* Send event to user space */
1113 wireless_send_event(dev
, IWEVTXDROP
, &wrqu
, NULL
);
1116 netif_wake_queue(dev
);
1119 static void orinoco_tx_timeout(struct net_device
*dev
)
1121 struct orinoco_private
*priv
= netdev_priv(dev
);
1122 struct net_device_stats
*stats
= &priv
->stats
;
1123 struct hermes
*hw
= &priv
->hw
;
1125 printk(KERN_WARNING
"%s: Tx timeout! "
1126 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
1127 dev
->name
, hermes_read_regn(hw
, ALLOCFID
),
1128 hermes_read_regn(hw
, TXCOMPLFID
), hermes_read_regn(hw
, EVSTAT
));
1132 schedule_work(&priv
->reset_work
);
1135 /********************************************************************/
1136 /* Rx path (data frames) */
1137 /********************************************************************/
1139 /* Does the frame have a SNAP header indicating it should be
1140 * de-encapsulated to Ethernet-II? */
1141 static inline int is_ethersnap(void *_hdr
)
1145 /* We de-encapsulate all packets which, a) have SNAP headers
1146 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
1147 * and where b) the OUI of the SNAP header is 00:00:00 or
1148 * 00:00:f8 - we need both because different APs appear to use
1149 * different OUIs for some reason */
1150 return (memcmp(hdr
, &encaps_hdr
, 5) == 0)
1151 && ( (hdr
[5] == 0x00) || (hdr
[5] == 0xf8) );
1154 static inline void orinoco_spy_gather(struct net_device
*dev
, u_char
*mac
,
1155 int level
, int noise
)
1157 struct iw_quality wstats
;
1158 wstats
.level
= level
- 0x95;
1159 wstats
.noise
= noise
- 0x95;
1160 wstats
.qual
= (level
> noise
) ? (level
- noise
) : 0;
1162 /* Update spy records */
1163 wireless_spy_update(dev
, mac
, &wstats
);
1166 static void orinoco_stat_gather(struct net_device
*dev
,
1167 struct sk_buff
*skb
,
1168 struct hermes_rx_descriptor
*desc
)
1170 struct orinoco_private
*priv
= netdev_priv(dev
);
1172 /* Using spy support with lots of Rx packets, like in an
1173 * infrastructure (AP), will really slow down everything, because
1174 * the MAC address must be compared to each entry of the spy list.
1175 * If the user really asks for it (set some address in the
1176 * spy list), we do it, but he will pay the price.
1177 * Note that to get here, you need both WIRELESS_SPY
1178 * compiled in AND some addresses in the list !!!
1180 /* Note : gcc will optimise the whole section away if
1181 * WIRELESS_SPY is not defined... - Jean II */
1182 if (SPY_NUMBER(priv
)) {
1183 orinoco_spy_gather(dev
, skb_mac_header(skb
) + ETH_ALEN
,
1184 desc
->signal
, desc
->silence
);
1189 * orinoco_rx_monitor - handle received monitor frames.
1192 * dev network device
1193 * rxfid received FID
1194 * desc rx descriptor of the frame
1196 * Call context: interrupt
1198 static void orinoco_rx_monitor(struct net_device
*dev
, u16 rxfid
,
1199 struct hermes_rx_descriptor
*desc
)
1201 u32 hdrlen
= 30; /* return full header by default */
1206 struct sk_buff
*skb
;
1207 struct orinoco_private
*priv
= netdev_priv(dev
);
1208 struct net_device_stats
*stats
= &priv
->stats
;
1209 hermes_t
*hw
= &priv
->hw
;
1211 len
= le16_to_cpu(desc
->data_len
);
1213 /* Determine the size of the header and the data */
1214 fc
= le16_to_cpu(desc
->frame_ctl
);
1215 switch (fc
& IEEE80211_FCTL_FTYPE
) {
1216 case IEEE80211_FTYPE_DATA
:
1217 if ((fc
& IEEE80211_FCTL_TODS
)
1218 && (fc
& IEEE80211_FCTL_FROMDS
))
1224 case IEEE80211_FTYPE_MGMT
:
1228 case IEEE80211_FTYPE_CTL
:
1229 switch (fc
& IEEE80211_FCTL_STYPE
) {
1230 case IEEE80211_STYPE_PSPOLL
:
1231 case IEEE80211_STYPE_RTS
:
1232 case IEEE80211_STYPE_CFEND
:
1233 case IEEE80211_STYPE_CFENDACK
:
1236 case IEEE80211_STYPE_CTS
:
1237 case IEEE80211_STYPE_ACK
:
1243 /* Unknown frame type */
1247 /* sanity check the length */
1248 if (datalen
> IEEE80211_DATA_LEN
+ 12) {
1249 printk(KERN_DEBUG
"%s: oversized monitor frame, "
1250 "data length = %d\n", dev
->name
, datalen
);
1251 stats
->rx_length_errors
++;
1255 skb
= dev_alloc_skb(hdrlen
+ datalen
);
1257 printk(KERN_WARNING
"%s: Cannot allocate skb for monitor frame\n",
1262 /* Copy the 802.11 header to the skb */
1263 memcpy(skb_put(skb
, hdrlen
), &(desc
->frame_ctl
), hdrlen
);
1264 skb_reset_mac_header(skb
);
1266 /* If any, copy the data from the card to the skb */
1268 err
= hermes_bap_pread(hw
, IRQ_BAP
, skb_put(skb
, datalen
),
1269 ALIGN(datalen
, 2), rxfid
,
1270 HERMES_802_2_OFFSET
);
1272 printk(KERN_ERR
"%s: error %d reading monitor frame\n",
1279 skb
->ip_summed
= CHECKSUM_NONE
;
1280 skb
->pkt_type
= PACKET_OTHERHOST
;
1281 skb
->protocol
= __constant_htons(ETH_P_802_2
);
1283 dev
->last_rx
= jiffies
;
1284 stats
->rx_packets
++;
1285 stats
->rx_bytes
+= skb
->len
;
1291 dev_kfree_skb_irq(skb
);
1294 stats
->rx_dropped
++;
1297 /* Get tsc from the firmware */
1298 static int orinoco_hw_get_tkip_iv(struct orinoco_private
*priv
, int key
,
1301 hermes_t
*hw
= &priv
->hw
;
1303 u8 tsc_arr
[4][IW_ENCODE_SEQ_MAX_SIZE
];
1305 if ((key
< 0) || (key
> 4))
1308 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENT_TKIP_IV
,
1309 sizeof(tsc_arr
), NULL
, &tsc_arr
);
1311 memcpy(tsc
, &tsc_arr
[key
][0], sizeof(tsc_arr
[0]));
1316 static void __orinoco_ev_rx(struct net_device
*dev
, hermes_t
*hw
)
1318 struct orinoco_private
*priv
= netdev_priv(dev
);
1319 struct net_device_stats
*stats
= &priv
->stats
;
1320 struct iw_statistics
*wstats
= &priv
->wstats
;
1321 struct sk_buff
*skb
= NULL
;
1324 struct hermes_rx_descriptor
*desc
;
1325 struct orinoco_rx_data
*rx_data
;
1328 desc
= kmalloc(sizeof(*desc
), GFP_ATOMIC
);
1331 "%s: Can't allocate space for RX descriptor\n",
1336 rxfid
= hermes_read_regn(hw
, RXFID
);
1338 err
= hermes_bap_pread(hw
, IRQ_BAP
, desc
, sizeof(*desc
),
1341 printk(KERN_ERR
"%s: error %d reading Rx descriptor. "
1342 "Frame dropped.\n", dev
->name
, err
);
1346 status
= le16_to_cpu(desc
->status
);
1348 if (status
& HERMES_RXSTAT_BADCRC
) {
1349 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
1351 stats
->rx_crc_errors
++;
1355 /* Handle frames in monitor mode */
1356 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
1357 orinoco_rx_monitor(dev
, rxfid
, desc
);
1361 if (status
& HERMES_RXSTAT_UNDECRYPTABLE
) {
1362 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1364 wstats
->discard
.code
++;
1368 length
= le16_to_cpu(desc
->data_len
);
1371 if (length
< 3) { /* No for even an 802.2 LLC header */
1372 /* At least on Symbol firmware with PCF we get quite a
1373 lot of these legitimately - Poll frames with no
1377 if (length
> IEEE80211_DATA_LEN
) {
1378 printk(KERN_WARNING
"%s: Oversized frame received (%d bytes)\n",
1380 stats
->rx_length_errors
++;
1384 /* Payload size does not include Michael MIC. Increase payload
1385 * size to read it together with the data. */
1386 if (status
& HERMES_RXSTAT_MIC
)
1387 length
+= MICHAEL_MIC_LEN
;
1389 /* We need space for the packet data itself, plus an ethernet
1390 header, plus 2 bytes so we can align the IP header on a
1391 32bit boundary, plus 1 byte so we can read in odd length
1392 packets from the card, which has an IO granularity of 16
1394 skb
= dev_alloc_skb(length
+ETH_HLEN
+2+1);
1396 printk(KERN_WARNING
"%s: Can't allocate skb for Rx\n",
1401 /* We'll prepend the header, so reserve space for it. The worst
1402 case is no decapsulation, when 802.3 header is prepended and
1403 nothing is removed. 2 is for aligning the IP header. */
1404 skb_reserve(skb
, ETH_HLEN
+ 2);
1406 err
= hermes_bap_pread(hw
, IRQ_BAP
, skb_put(skb
, length
),
1407 ALIGN(length
, 2), rxfid
,
1408 HERMES_802_2_OFFSET
);
1410 printk(KERN_ERR
"%s: error %d reading frame. "
1411 "Frame dropped.\n", dev
->name
, err
);
1415 /* Add desc and skb to rx queue */
1416 rx_data
= kzalloc(sizeof(*rx_data
), GFP_ATOMIC
);
1418 printk(KERN_WARNING
"%s: Can't allocate RX packet\n",
1422 rx_data
->desc
= desc
;
1424 list_add_tail(&rx_data
->list
, &priv
->rx_list
);
1425 tasklet_schedule(&priv
->rx_tasklet
);
1430 dev_kfree_skb_irq(skb
);
1433 stats
->rx_dropped
++;
1438 static void orinoco_rx(struct net_device
*dev
,
1439 struct hermes_rx_descriptor
*desc
,
1440 struct sk_buff
*skb
)
1442 struct orinoco_private
*priv
= netdev_priv(dev
);
1443 struct net_device_stats
*stats
= &priv
->stats
;
1448 status
= le16_to_cpu(desc
->status
);
1449 length
= le16_to_cpu(desc
->data_len
);
1450 fc
= le16_to_cpu(desc
->frame_ctl
);
1452 /* Calculate and check MIC */
1453 if (status
& HERMES_RXSTAT_MIC
) {
1454 int key_id
= ((status
& HERMES_RXSTAT_MIC_KEY_ID
) >>
1455 HERMES_MIC_KEY_ID_SHIFT
);
1456 u8 mic
[MICHAEL_MIC_LEN
];
1458 u8
*src
= (fc
& IEEE80211_FCTL_FROMDS
) ?
1459 desc
->addr3
: desc
->addr2
;
1461 /* Extract Michael MIC from payload */
1462 rxmic
= skb
->data
+ skb
->len
- MICHAEL_MIC_LEN
;
1464 skb_trim(skb
, skb
->len
- MICHAEL_MIC_LEN
);
1465 length
-= MICHAEL_MIC_LEN
;
1467 michael_mic(priv
->rx_tfm_mic
,
1468 priv
->tkip_key
[key_id
].rx_mic
,
1471 0, /* priority or QoS? */
1476 if (memcmp(mic
, rxmic
,
1478 union iwreq_data wrqu
;
1479 struct iw_michaelmicfailure wxmic
;
1481 printk(KERN_WARNING
"%s: "
1482 "Invalid Michael MIC in data frame from %pM, "
1484 dev
->name
, src
, key_id
);
1486 /* TODO: update stats */
1488 /* Notify userspace */
1489 memset(&wxmic
, 0, sizeof(wxmic
));
1490 wxmic
.flags
= key_id
& IW_MICFAILURE_KEY_ID
;
1491 wxmic
.flags
|= (desc
->addr1
[0] & 1) ?
1492 IW_MICFAILURE_GROUP
: IW_MICFAILURE_PAIRWISE
;
1493 wxmic
.src_addr
.sa_family
= ARPHRD_ETHER
;
1494 memcpy(wxmic
.src_addr
.sa_data
, src
, ETH_ALEN
);
1496 (void) orinoco_hw_get_tkip_iv(priv
, key_id
,
1499 memset(&wrqu
, 0, sizeof(wrqu
));
1500 wrqu
.data
.length
= sizeof(wxmic
);
1501 wireless_send_event(dev
, IWEVMICHAELMICFAILURE
, &wrqu
,
1508 /* Handle decapsulation
1509 * In most cases, the firmware tell us about SNAP frames.
1510 * For some reason, the SNAP frames sent by LinkSys APs
1511 * are not properly recognised by most firmwares.
1512 * So, check ourselves */
1513 if (length
>= ENCAPS_OVERHEAD
&&
1514 (((status
& HERMES_RXSTAT_MSGTYPE
) == HERMES_RXSTAT_1042
) ||
1515 ((status
& HERMES_RXSTAT_MSGTYPE
) == HERMES_RXSTAT_TUNNEL
) ||
1516 is_ethersnap(skb
->data
))) {
1517 /* These indicate a SNAP within 802.2 LLC within
1518 802.11 frame which we'll need to de-encapsulate to
1519 the original EthernetII frame. */
1520 hdr
= (struct ethhdr
*)skb_push(skb
, ETH_HLEN
- ENCAPS_OVERHEAD
);
1522 /* 802.3 frame - prepend 802.3 header as is */
1523 hdr
= (struct ethhdr
*)skb_push(skb
, ETH_HLEN
);
1524 hdr
->h_proto
= htons(length
);
1526 memcpy(hdr
->h_dest
, desc
->addr1
, ETH_ALEN
);
1527 if (fc
& IEEE80211_FCTL_FROMDS
)
1528 memcpy(hdr
->h_source
, desc
->addr3
, ETH_ALEN
);
1530 memcpy(hdr
->h_source
, desc
->addr2
, ETH_ALEN
);
1532 dev
->last_rx
= jiffies
;
1533 skb
->protocol
= eth_type_trans(skb
, dev
);
1534 skb
->ip_summed
= CHECKSUM_NONE
;
1535 if (fc
& IEEE80211_FCTL_TODS
)
1536 skb
->pkt_type
= PACKET_OTHERHOST
;
1538 /* Process the wireless stats if needed */
1539 orinoco_stat_gather(dev
, skb
, desc
);
1541 /* Pass the packet to the networking stack */
1543 stats
->rx_packets
++;
1544 stats
->rx_bytes
+= length
;
1551 stats
->rx_dropped
++;
1554 static void orinoco_rx_isr_tasklet(unsigned long data
)
1556 struct net_device
*dev
= (struct net_device
*) data
;
1557 struct orinoco_private
*priv
= netdev_priv(dev
);
1558 struct orinoco_rx_data
*rx_data
, *temp
;
1559 struct hermes_rx_descriptor
*desc
;
1560 struct sk_buff
*skb
;
1562 /* extract desc and skb from queue */
1563 list_for_each_entry_safe(rx_data
, temp
, &priv
->rx_list
, list
) {
1564 desc
= rx_data
->desc
;
1566 list_del(&rx_data
->list
);
1569 orinoco_rx(dev
, desc
, skb
);
1575 /********************************************************************/
1576 /* Rx path (info frames) */
1577 /********************************************************************/
1579 static void print_linkstatus(struct net_device
*dev
, u16 status
)
1583 if (suppress_linkstatus
)
1587 case HERMES_LINKSTATUS_NOT_CONNECTED
:
1588 s
= "Not Connected";
1590 case HERMES_LINKSTATUS_CONNECTED
:
1593 case HERMES_LINKSTATUS_DISCONNECTED
:
1596 case HERMES_LINKSTATUS_AP_CHANGE
:
1599 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE
:
1600 s
= "AP Out of Range";
1602 case HERMES_LINKSTATUS_AP_IN_RANGE
:
1605 case HERMES_LINKSTATUS_ASSOC_FAILED
:
1606 s
= "Association Failed";
1612 printk(KERN_INFO
"%s: New link status: %s (%04x)\n",
1613 dev
->name
, s
, status
);
1616 /* Search scan results for requested BSSID, join it if found */
1617 static void orinoco_join_ap(struct work_struct
*work
)
1619 struct orinoco_private
*priv
=
1620 container_of(work
, struct orinoco_private
, join_work
);
1621 struct net_device
*dev
= priv
->ndev
;
1622 struct hermes
*hw
= &priv
->hw
;
1624 unsigned long flags
;
1628 } __attribute__ ((packed
)) req
;
1629 const int atom_len
= offsetof(struct prism2_scan_apinfo
, atim
);
1630 struct prism2_scan_apinfo
*atom
= NULL
;
1636 /* Allocate buffer for scan results */
1637 buf
= kmalloc(MAX_SCAN_LEN
, GFP_KERNEL
);
1641 if (orinoco_lock(priv
, &flags
) != 0)
1644 /* Sanity checks in case user changed something in the meantime */
1645 if (! priv
->bssid_fixed
)
1648 if (strlen(priv
->desired_essid
) == 0)
1651 /* Read scan results from the firmware */
1652 err
= hermes_read_ltv(hw
, USER_BAP
,
1653 HERMES_RID_SCANRESULTSTABLE
,
1654 MAX_SCAN_LEN
, &len
, buf
);
1656 printk(KERN_ERR
"%s: Cannot read scan results\n",
1661 len
= HERMES_RECLEN_TO_BYTES(len
);
1663 /* Go through the scan results looking for the channel of the AP
1664 * we were requested to join */
1665 for (; offset
+ atom_len
<= len
; offset
+= atom_len
) {
1666 atom
= (struct prism2_scan_apinfo
*) (buf
+ offset
);
1667 if (memcmp(&atom
->bssid
, priv
->desired_bssid
, ETH_ALEN
) == 0) {
1674 DEBUG(1, "%s: Requested AP not found in scan results\n",
1679 memcpy(req
.bssid
, priv
->desired_bssid
, ETH_ALEN
);
1680 req
.channel
= atom
->channel
; /* both are little-endian */
1681 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
, HERMES_RID_CNFJOINREQUEST
,
1684 printk(KERN_ERR
"%s: Error issuing join request\n", dev
->name
);
1687 orinoco_unlock(priv
, &flags
);
1693 /* Send new BSSID to userspace */
1694 static void orinoco_send_bssid_wevent(struct orinoco_private
*priv
)
1696 struct net_device
*dev
= priv
->ndev
;
1697 struct hermes
*hw
= &priv
->hw
;
1698 union iwreq_data wrqu
;
1701 err
= hermes_read_ltv(hw
, IRQ_BAP
, HERMES_RID_CURRENTBSSID
,
1702 ETH_ALEN
, NULL
, wrqu
.ap_addr
.sa_data
);
1706 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1708 /* Send event to user space */
1709 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
1712 static void orinoco_send_assocreqie_wevent(struct orinoco_private
*priv
)
1714 struct net_device
*dev
= priv
->ndev
;
1715 struct hermes
*hw
= &priv
->hw
;
1716 union iwreq_data wrqu
;
1724 err
= hermes_read_ltv(hw
, IRQ_BAP
, HERMES_RID_CURRENT_ASSOC_REQ_INFO
,
1725 sizeof(buf
), NULL
, &buf
);
1729 ie
= orinoco_get_wpa_ie(buf
, sizeof(buf
));
1731 int rem
= sizeof(buf
) - (ie
- &buf
[0]);
1732 wrqu
.data
.length
= ie
[1] + 2;
1733 if (wrqu
.data
.length
> rem
)
1734 wrqu
.data
.length
= rem
;
1736 if (wrqu
.data
.length
)
1737 /* Send event to user space */
1738 wireless_send_event(dev
, IWEVASSOCREQIE
, &wrqu
, ie
);
1742 static void orinoco_send_assocrespie_wevent(struct orinoco_private
*priv
)
1744 struct net_device
*dev
= priv
->ndev
;
1745 struct hermes
*hw
= &priv
->hw
;
1746 union iwreq_data wrqu
;
1748 u8 buf
[88]; /* TODO: verify max size or IW_GENERIC_IE_MAX */
1754 err
= hermes_read_ltv(hw
, IRQ_BAP
, HERMES_RID_CURRENT_ASSOC_RESP_INFO
,
1755 sizeof(buf
), NULL
, &buf
);
1759 ie
= orinoco_get_wpa_ie(buf
, sizeof(buf
));
1761 int rem
= sizeof(buf
) - (ie
- &buf
[0]);
1762 wrqu
.data
.length
= ie
[1] + 2;
1763 if (wrqu
.data
.length
> rem
)
1764 wrqu
.data
.length
= rem
;
1766 if (wrqu
.data
.length
)
1767 /* Send event to user space */
1768 wireless_send_event(dev
, IWEVASSOCRESPIE
, &wrqu
, ie
);
1772 static void orinoco_send_wevents(struct work_struct
*work
)
1774 struct orinoco_private
*priv
=
1775 container_of(work
, struct orinoco_private
, wevent_work
);
1776 unsigned long flags
;
1778 if (orinoco_lock(priv
, &flags
) != 0)
1781 orinoco_send_assocreqie_wevent(priv
);
1782 orinoco_send_assocrespie_wevent(priv
);
1783 orinoco_send_bssid_wevent(priv
);
1785 orinoco_unlock(priv
, &flags
);
1788 static inline void orinoco_clear_scan_results(struct orinoco_private
*priv
,
1789 unsigned long scan_age
)
1791 if (priv
->has_ext_scan
) {
1792 struct xbss_element
*bss
;
1793 struct xbss_element
*tmp_bss
;
1795 /* Blow away current list of scan results */
1796 list_for_each_entry_safe(bss
, tmp_bss
, &priv
->bss_list
, list
) {
1798 time_after(jiffies
, bss
->last_scanned
+ scan_age
)) {
1799 list_move_tail(&bss
->list
,
1800 &priv
->bss_free_list
);
1801 /* Don't blow away ->list, just BSS data */
1802 memset(&bss
->bss
, 0, sizeof(bss
->bss
));
1803 bss
->last_scanned
= 0;
1807 struct bss_element
*bss
;
1808 struct bss_element
*tmp_bss
;
1810 /* Blow away current list of scan results */
1811 list_for_each_entry_safe(bss
, tmp_bss
, &priv
->bss_list
, list
) {
1813 time_after(jiffies
, bss
->last_scanned
+ scan_age
)) {
1814 list_move_tail(&bss
->list
,
1815 &priv
->bss_free_list
);
1816 /* Don't blow away ->list, just BSS data */
1817 memset(&bss
->bss
, 0, sizeof(bss
->bss
));
1818 bss
->last_scanned
= 0;
1824 static void orinoco_add_ext_scan_result(struct orinoco_private
*priv
,
1825 struct agere_ext_scan_info
*atom
)
1827 struct xbss_element
*bss
= NULL
;
1830 /* Try to update an existing bss first */
1831 list_for_each_entry(bss
, &priv
->bss_list
, list
) {
1832 if (compare_ether_addr(bss
->bss
.bssid
, atom
->bssid
))
1835 if (bss
->bss
.data
[1] != atom
->data
[1])
1837 if (memcmp(&bss
->bss
.data
[2], &atom
->data
[2],
1844 /* Grab a bss off the free list */
1845 if (!found
&& !list_empty(&priv
->bss_free_list
)) {
1846 bss
= list_entry(priv
->bss_free_list
.next
,
1847 struct xbss_element
, list
);
1848 list_del(priv
->bss_free_list
.next
);
1850 list_add_tail(&bss
->list
, &priv
->bss_list
);
1854 /* Always update the BSS to get latest beacon info */
1855 memcpy(&bss
->bss
, atom
, sizeof(bss
->bss
));
1856 bss
->last_scanned
= jiffies
;
1860 static int orinoco_process_scan_results(struct net_device
*dev
,
1864 struct orinoco_private
*priv
= netdev_priv(dev
);
1865 int offset
; /* In the scan data */
1866 union hermes_scan_info
*atom
;
1869 switch (priv
->firmware_type
) {
1870 case FIRMWARE_TYPE_AGERE
:
1871 atom_len
= sizeof(struct agere_scan_apinfo
);
1874 case FIRMWARE_TYPE_SYMBOL
:
1875 /* Lack of documentation necessitates this hack.
1876 * Different firmwares have 68 or 76 byte long atoms.
1877 * We try modulo first. If the length divides by both,
1878 * we check what would be the channel in the second
1879 * frame for a 68-byte atom. 76-byte atoms have 0 there.
1880 * Valid channel cannot be 0. */
1885 else if (len
>= 1292 && buf
[68] == 0)
1891 case FIRMWARE_TYPE_INTERSIL
:
1893 if (priv
->has_hostscan
) {
1894 atom_len
= le16_to_cpup((__le16
*)buf
);
1895 /* Sanity check for atom_len */
1896 if (atom_len
< sizeof(struct prism2_scan_apinfo
)) {
1897 printk(KERN_ERR
"%s: Invalid atom_len in scan "
1898 "data: %d\n", dev
->name
, atom_len
);
1902 atom_len
= offsetof(struct prism2_scan_apinfo
, atim
);
1908 /* Check that we got an whole number of atoms */
1909 if ((len
- offset
) % atom_len
) {
1910 printk(KERN_ERR
"%s: Unexpected scan data length %d, "
1911 "atom_len %d, offset %d\n", dev
->name
, len
,
1916 orinoco_clear_scan_results(priv
, msecs_to_jiffies(15000));
1918 /* Read the entries one by one */
1919 for (; offset
+ atom_len
<= len
; offset
+= atom_len
) {
1921 struct bss_element
*bss
= NULL
;
1924 atom
= (union hermes_scan_info
*) (buf
+ offset
);
1926 /* Try to update an existing bss first */
1927 list_for_each_entry(bss
, &priv
->bss_list
, list
) {
1928 if (compare_ether_addr(bss
->bss
.a
.bssid
, atom
->a
.bssid
))
1930 if (le16_to_cpu(bss
->bss
.a
.essid_len
) !=
1931 le16_to_cpu(atom
->a
.essid_len
))
1933 if (memcmp(bss
->bss
.a
.essid
, atom
->a
.essid
,
1934 le16_to_cpu(atom
->a
.essid_len
)))
1940 /* Grab a bss off the free list */
1941 if (!found
&& !list_empty(&priv
->bss_free_list
)) {
1942 bss
= list_entry(priv
->bss_free_list
.next
,
1943 struct bss_element
, list
);
1944 list_del(priv
->bss_free_list
.next
);
1946 list_add_tail(&bss
->list
, &priv
->bss_list
);
1950 /* Always update the BSS to get latest beacon info */
1951 memcpy(&bss
->bss
, atom
, sizeof(bss
->bss
));
1952 bss
->last_scanned
= jiffies
;
1959 static void __orinoco_ev_info(struct net_device
*dev
, hermes_t
*hw
)
1961 struct orinoco_private
*priv
= netdev_priv(dev
);
1966 } __attribute__ ((packed
)) info
;
1970 /* This is an answer to an INQUIRE command that we did earlier,
1971 * or an information "event" generated by the card
1972 * The controller return to us a pseudo frame containing
1973 * the information in question - Jean II */
1974 infofid
= hermes_read_regn(hw
, INFOFID
);
1976 /* Read the info frame header - don't try too hard */
1977 err
= hermes_bap_pread(hw
, IRQ_BAP
, &info
, sizeof(info
),
1980 printk(KERN_ERR
"%s: error %d reading info frame. "
1981 "Frame dropped.\n", dev
->name
, err
);
1985 len
= HERMES_RECLEN_TO_BYTES(le16_to_cpu(info
.len
));
1986 type
= le16_to_cpu(info
.type
);
1989 case HERMES_INQ_TALLIES
: {
1990 struct hermes_tallies_frame tallies
;
1991 struct iw_statistics
*wstats
= &priv
->wstats
;
1993 if (len
> sizeof(tallies
)) {
1994 printk(KERN_WARNING
"%s: Tallies frame too long (%d bytes)\n",
1996 len
= sizeof(tallies
);
1999 err
= hermes_bap_pread(hw
, IRQ_BAP
, &tallies
, len
,
2000 infofid
, sizeof(info
));
2004 /* Increment our various counters */
2005 /* wstats->discard.nwid - no wrong BSSID stuff */
2006 wstats
->discard
.code
+=
2007 le16_to_cpu(tallies
.RxWEPUndecryptable
);
2008 if (len
== sizeof(tallies
))
2009 wstats
->discard
.code
+=
2010 le16_to_cpu(tallies
.RxDiscards_WEPICVError
) +
2011 le16_to_cpu(tallies
.RxDiscards_WEPExcluded
);
2012 wstats
->discard
.misc
+=
2013 le16_to_cpu(tallies
.TxDiscardsWrongSA
);
2014 wstats
->discard
.fragment
+=
2015 le16_to_cpu(tallies
.RxMsgInBadMsgFragments
);
2016 wstats
->discard
.retries
+=
2017 le16_to_cpu(tallies
.TxRetryLimitExceeded
);
2018 /* wstats->miss.beacon - no match */
2021 case HERMES_INQ_LINKSTATUS
: {
2022 struct hermes_linkstatus linkstatus
;
2026 if (priv
->iw_mode
== IW_MODE_MONITOR
)
2029 if (len
!= sizeof(linkstatus
)) {
2030 printk(KERN_WARNING
"%s: Unexpected size for linkstatus frame (%d bytes)\n",
2035 err
= hermes_bap_pread(hw
, IRQ_BAP
, &linkstatus
, len
,
2036 infofid
, sizeof(info
));
2039 newstatus
= le16_to_cpu(linkstatus
.linkstatus
);
2041 /* Symbol firmware uses "out of range" to signal that
2042 * the hostscan frame can be requested. */
2043 if (newstatus
== HERMES_LINKSTATUS_AP_OUT_OF_RANGE
&&
2044 priv
->firmware_type
== FIRMWARE_TYPE_SYMBOL
&&
2045 priv
->has_hostscan
&& priv
->scan_inprogress
) {
2046 hermes_inquire(hw
, HERMES_INQ_HOSTSCAN_SYMBOL
);
2050 connected
= (newstatus
== HERMES_LINKSTATUS_CONNECTED
)
2051 || (newstatus
== HERMES_LINKSTATUS_AP_CHANGE
)
2052 || (newstatus
== HERMES_LINKSTATUS_AP_IN_RANGE
);
2055 netif_carrier_on(dev
);
2056 else if (!ignore_disconnect
)
2057 netif_carrier_off(dev
);
2059 if (newstatus
!= priv
->last_linkstatus
) {
2060 priv
->last_linkstatus
= newstatus
;
2061 print_linkstatus(dev
, newstatus
);
2062 /* The info frame contains only one word which is the
2063 * status (see hermes.h). The status is pretty boring
2064 * in itself, that's why we export the new BSSID...
2066 schedule_work(&priv
->wevent_work
);
2070 case HERMES_INQ_SCAN
:
2071 if (!priv
->scan_inprogress
&& priv
->bssid_fixed
&&
2072 priv
->firmware_type
== FIRMWARE_TYPE_INTERSIL
) {
2073 schedule_work(&priv
->join_work
);
2077 case HERMES_INQ_HOSTSCAN
:
2078 case HERMES_INQ_HOSTSCAN_SYMBOL
: {
2079 /* Result of a scanning. Contains information about
2080 * cells in the vicinity - Jean II */
2081 union iwreq_data wrqu
;
2084 /* Scan is no longer in progress */
2085 priv
->scan_inprogress
= 0;
2089 printk(KERN_WARNING
"%s: Scan results too large (%d bytes)\n",
2094 /* Allocate buffer for results */
2095 buf
= kmalloc(len
, GFP_ATOMIC
);
2097 /* No memory, so can't printk()... */
2100 /* Read scan data */
2101 err
= hermes_bap_pread(hw
, IRQ_BAP
, (void *) buf
, len
,
2102 infofid
, sizeof(info
));
2108 #ifdef ORINOCO_DEBUG
2111 printk(KERN_DEBUG
"Scan result [%02X", buf
[0]);
2112 for(i
= 1; i
< (len
* 2); i
++)
2113 printk(":%02X", buf
[i
]);
2116 #endif /* ORINOCO_DEBUG */
2118 if (orinoco_process_scan_results(dev
, buf
, len
) == 0) {
2119 /* Send an empty event to user space.
2120 * We don't send the received data on the event because
2121 * it would require us to do complex transcoding, and
2122 * we want to minimise the work done in the irq handler
2123 * Use a request to extract the data - Jean II */
2124 wrqu
.data
.length
= 0;
2125 wrqu
.data
.flags
= 0;
2126 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
2131 case HERMES_INQ_CHANNELINFO
:
2133 struct agere_ext_scan_info
*bss
;
2135 if (!priv
->scan_inprogress
) {
2136 printk(KERN_DEBUG
"%s: Got chaninfo without scan, "
2137 "len=%d\n", dev
->name
, len
);
2141 /* An empty result indicates that the scan is complete */
2143 union iwreq_data wrqu
;
2145 /* Scan is no longer in progress */
2146 priv
->scan_inprogress
= 0;
2148 wrqu
.data
.length
= 0;
2149 wrqu
.data
.flags
= 0;
2150 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
2155 else if (len
> sizeof(*bss
)) {
2157 "%s: Ext scan results too large (%d bytes). "
2158 "Truncating results to %zd bytes.\n",
2159 dev
->name
, len
, sizeof(*bss
));
2161 } else if (len
< (offsetof(struct agere_ext_scan_info
,
2163 /* Drop this result now so we don't have to
2164 * keep checking later */
2166 "%s: Ext scan results too short (%d bytes)\n",
2171 bss
= kmalloc(sizeof(*bss
), GFP_ATOMIC
);
2175 /* Read scan data */
2176 err
= hermes_bap_pread(hw
, IRQ_BAP
, (void *) bss
, len
,
2177 infofid
, sizeof(info
));
2183 orinoco_add_ext_scan_result(priv
, bss
);
2188 case HERMES_INQ_SEC_STAT_AGERE
:
2189 /* Security status (Agere specific) */
2190 /* Ignore this frame for now */
2191 if (priv
->firmware_type
== FIRMWARE_TYPE_AGERE
)
2195 printk(KERN_DEBUG
"%s: Unknown information frame received: "
2196 "type 0x%04x, length %d\n", dev
->name
, type
, len
);
2197 /* We don't actually do anything about it */
2202 static void __orinoco_ev_infdrop(struct net_device
*dev
, hermes_t
*hw
)
2204 if (net_ratelimit())
2205 printk(KERN_DEBUG
"%s: Information frame lost.\n", dev
->name
);
2208 /********************************************************************/
2209 /* Internal hardware control routines */
2210 /********************************************************************/
2212 int __orinoco_up(struct net_device
*dev
)
2214 struct orinoco_private
*priv
= netdev_priv(dev
);
2215 struct hermes
*hw
= &priv
->hw
;
2218 netif_carrier_off(dev
); /* just to make sure */
2220 err
= __orinoco_program_rids(dev
);
2222 printk(KERN_ERR
"%s: Error %d configuring card\n",
2227 /* Fire things up again */
2228 hermes_set_irqmask(hw
, ORINOCO_INTEN
);
2229 err
= hermes_enable_port(hw
, 0);
2231 printk(KERN_ERR
"%s: Error %d enabling MAC port\n",
2236 netif_start_queue(dev
);
2241 int __orinoco_down(struct net_device
*dev
)
2243 struct orinoco_private
*priv
= netdev_priv(dev
);
2244 struct hermes
*hw
= &priv
->hw
;
2247 netif_stop_queue(dev
);
2249 if (! priv
->hw_unavailable
) {
2250 if (! priv
->broken_disableport
) {
2251 err
= hermes_disable_port(hw
, 0);
2253 /* Some firmwares (e.g. Intersil 1.3.x) seem
2254 * to have problems disabling the port, oh
2256 printk(KERN_WARNING
"%s: Error %d disabling MAC port\n",
2258 priv
->broken_disableport
= 1;
2261 hermes_set_irqmask(hw
, 0);
2262 hermes_write_regn(hw
, EVACK
, 0xffff);
2265 /* firmware will have to reassociate */
2266 netif_carrier_off(dev
);
2267 priv
->last_linkstatus
= 0xffff;
2272 static int orinoco_allocate_fid(struct net_device
*dev
)
2274 struct orinoco_private
*priv
= netdev_priv(dev
);
2275 struct hermes
*hw
= &priv
->hw
;
2278 err
= hermes_allocate(hw
, priv
->nicbuf_size
, &priv
->txfid
);
2279 if (err
== -EIO
&& priv
->nicbuf_size
> TX_NICBUF_SIZE_BUG
) {
2280 /* Try workaround for old Symbol firmware bug */
2281 printk(KERN_WARNING
"%s: firmware ALLOC bug detected "
2282 "(old Symbol firmware?). Trying to work around... ",
2285 priv
->nicbuf_size
= TX_NICBUF_SIZE_BUG
;
2286 err
= hermes_allocate(hw
, priv
->nicbuf_size
, &priv
->txfid
);
2288 printk("failed!\n");
2296 int orinoco_reinit_firmware(struct net_device
*dev
)
2298 struct orinoco_private
*priv
= netdev_priv(dev
);
2299 struct hermes
*hw
= &priv
->hw
;
2302 err
= hermes_init(hw
);
2304 err
= orinoco_allocate_fid(dev
);
2309 static int __orinoco_hw_set_bitrate(struct orinoco_private
*priv
)
2311 hermes_t
*hw
= &priv
->hw
;
2314 if (priv
->bitratemode
>= BITRATE_TABLE_SIZE
) {
2315 printk(KERN_ERR
"%s: BUG: Invalid bitrate mode %d\n",
2316 priv
->ndev
->name
, priv
->bitratemode
);
2320 switch (priv
->firmware_type
) {
2321 case FIRMWARE_TYPE_AGERE
:
2322 err
= hermes_write_wordrec(hw
, USER_BAP
,
2323 HERMES_RID_CNFTXRATECONTROL
,
2324 bitrate_table
[priv
->bitratemode
].agere_txratectrl
);
2326 case FIRMWARE_TYPE_INTERSIL
:
2327 case FIRMWARE_TYPE_SYMBOL
:
2328 err
= hermes_write_wordrec(hw
, USER_BAP
,
2329 HERMES_RID_CNFTXRATECONTROL
,
2330 bitrate_table
[priv
->bitratemode
].intersil_txratectrl
);
2339 /* Set fixed AP address */
2340 static int __orinoco_hw_set_wap(struct orinoco_private
*priv
)
2344 hermes_t
*hw
= &priv
->hw
;
2346 switch (priv
->firmware_type
) {
2347 case FIRMWARE_TYPE_AGERE
:
2350 case FIRMWARE_TYPE_INTERSIL
:
2351 if (priv
->bssid_fixed
)
2356 err
= hermes_write_wordrec(hw
, USER_BAP
,
2357 HERMES_RID_CNFROAMINGMODE
,
2360 case FIRMWARE_TYPE_SYMBOL
:
2361 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
2362 HERMES_RID_CNFMANDATORYBSSID_SYMBOL
,
2363 &priv
->desired_bssid
);
2369 /* Change the WEP keys and/or the current keys. Can be called
2370 * either from __orinoco_hw_setup_enc() or directly from
2371 * orinoco_ioctl_setiwencode(). In the later case the association
2372 * with the AP is not broken (if the firmware can handle it),
2373 * which is needed for 802.1x implementations. */
2374 static int __orinoco_hw_setup_wepkeys(struct orinoco_private
*priv
)
2376 hermes_t
*hw
= &priv
->hw
;
2379 switch (priv
->firmware_type
) {
2380 case FIRMWARE_TYPE_AGERE
:
2381 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
2382 HERMES_RID_CNFWEPKEYS_AGERE
,
2386 err
= hermes_write_wordrec(hw
, USER_BAP
,
2387 HERMES_RID_CNFTXKEY_AGERE
,
2392 case FIRMWARE_TYPE_INTERSIL
:
2393 case FIRMWARE_TYPE_SYMBOL
:
2398 /* Force uniform key length to work around firmware bugs */
2399 keylen
= le16_to_cpu(priv
->keys
[priv
->tx_key
].len
);
2401 if (keylen
> LARGE_KEY_SIZE
) {
2402 printk(KERN_ERR
"%s: BUG: Key %d has oversize length %d.\n",
2403 priv
->ndev
->name
, priv
->tx_key
, keylen
);
2407 /* Write all 4 keys */
2408 for(i
= 0; i
< ORINOCO_MAX_KEYS
; i
++) {
2409 err
= hermes_write_ltv(hw
, USER_BAP
,
2410 HERMES_RID_CNFDEFAULTKEY0
+ i
,
2411 HERMES_BYTES_TO_RECLEN(keylen
),
2412 priv
->keys
[i
].data
);
2417 /* Write the index of the key used in transmission */
2418 err
= hermes_write_wordrec(hw
, USER_BAP
,
2419 HERMES_RID_CNFWEPDEFAULTKEYID
,
2430 static int __orinoco_hw_setup_enc(struct orinoco_private
*priv
)
2432 hermes_t
*hw
= &priv
->hw
;
2434 int master_wep_flag
;
2438 /* Setup WEP keys for WEP and WPA */
2439 if (priv
->encode_alg
)
2440 __orinoco_hw_setup_wepkeys(priv
);
2442 if (priv
->wep_restrict
)
2443 auth_flag
= HERMES_AUTH_SHARED_KEY
;
2445 auth_flag
= HERMES_AUTH_OPEN
;
2447 if (priv
->wpa_enabled
)
2449 else if (priv
->encode_alg
== IW_ENCODE_ALG_WEP
)
2454 switch (priv
->firmware_type
) {
2455 case FIRMWARE_TYPE_AGERE
: /* Agere style WEP */
2456 if (priv
->encode_alg
== IW_ENCODE_ALG_WEP
) {
2457 /* Enable the shared-key authentication. */
2458 err
= hermes_write_wordrec(hw
, USER_BAP
,
2459 HERMES_RID_CNFAUTHENTICATION_AGERE
,
2462 err
= hermes_write_wordrec(hw
, USER_BAP
,
2463 HERMES_RID_CNFWEPENABLED_AGERE
,
2468 if (priv
->has_wpa
) {
2469 /* Set WPA key management */
2470 err
= hermes_write_wordrec(hw
, USER_BAP
,
2471 HERMES_RID_CNFSETWPAAUTHMGMTSUITE_AGERE
,
2479 case FIRMWARE_TYPE_INTERSIL
: /* Intersil style WEP */
2480 case FIRMWARE_TYPE_SYMBOL
: /* Symbol style WEP */
2481 if (priv
->encode_alg
== IW_ENCODE_ALG_WEP
) {
2482 if (priv
->wep_restrict
||
2483 (priv
->firmware_type
== FIRMWARE_TYPE_SYMBOL
))
2484 master_wep_flag
= HERMES_WEP_PRIVACY_INVOKED
|
2485 HERMES_WEP_EXCL_UNENCRYPTED
;
2487 master_wep_flag
= HERMES_WEP_PRIVACY_INVOKED
;
2489 err
= hermes_write_wordrec(hw
, USER_BAP
,
2490 HERMES_RID_CNFAUTHENTICATION
,
2495 master_wep_flag
= 0;
2497 if (priv
->iw_mode
== IW_MODE_MONITOR
)
2498 master_wep_flag
|= HERMES_WEP_HOST_DECRYPT
;
2500 /* Master WEP setting : on/off */
2501 err
= hermes_write_wordrec(hw
, USER_BAP
,
2502 HERMES_RID_CNFWEPFLAGS_INTERSIL
,
2513 /* key must be 32 bytes, including the tx and rx MIC keys.
2514 * rsc must be 8 bytes
2515 * tsc must be 8 bytes or NULL
2517 static int __orinoco_hw_set_tkip_key(hermes_t
*hw
, int key_idx
, int set_tx
,
2518 u8
*key
, u8
*rsc
, u8
*tsc
)
2522 u8 rsc
[IW_ENCODE_SEQ_MAX_SIZE
];
2523 u8 key
[TKIP_KEYLEN
];
2524 u8 tx_mic
[MIC_KEYLEN
];
2525 u8 rx_mic
[MIC_KEYLEN
];
2526 u8 tsc
[IW_ENCODE_SEQ_MAX_SIZE
];
2527 } __attribute__ ((packed
)) buf
;
2538 buf
.idx
= cpu_to_le16(key_idx
);
2539 memcpy(buf
.key
, key
,
2540 sizeof(buf
.key
) + sizeof(buf
.tx_mic
) + sizeof(buf
.rx_mic
));
2543 memset(buf
.rsc
, 0, sizeof(buf
.rsc
));
2545 memcpy(buf
.rsc
, rsc
, sizeof(buf
.rsc
));
2548 memset(buf
.tsc
, 0, sizeof(buf
.tsc
));
2551 memcpy(buf
.tsc
, tsc
, sizeof(buf
.tsc
));
2554 /* Wait upto 100ms for tx queue to empty */
2559 ret
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_TXQUEUEEMPTY
,
2563 } while ((k
> 0) && xmitting
);
2568 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
2569 HERMES_RID_CNFADDDEFAULTTKIPKEY_AGERE
,
2572 return ret
? ret
: err
;
2575 static int orinoco_clear_tkip_key(struct orinoco_private
*priv
,
2578 hermes_t
*hw
= &priv
->hw
;
2581 memset(&priv
->tkip_key
[key_idx
], 0, sizeof(priv
->tkip_key
[key_idx
]));
2582 err
= hermes_write_wordrec(hw
, USER_BAP
,
2583 HERMES_RID_CNFREMDEFAULTTKIPKEY_AGERE
,
2586 printk(KERN_WARNING
"%s: Error %d clearing TKIP key %d\n",
2587 priv
->ndev
->name
, err
, key_idx
);
2591 static int __orinoco_program_rids(struct net_device
*dev
)
2593 struct orinoco_private
*priv
= netdev_priv(dev
);
2594 hermes_t
*hw
= &priv
->hw
;
2596 struct hermes_idstring idbuf
;
2598 /* Set the MAC address */
2599 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNMACADDR
,
2600 HERMES_BYTES_TO_RECLEN(ETH_ALEN
), dev
->dev_addr
);
2602 printk(KERN_ERR
"%s: Error %d setting MAC address\n",
2607 /* Set up the link mode */
2608 err
= hermes_write_wordrec(hw
, USER_BAP
, HERMES_RID_CNFPORTTYPE
,
2611 printk(KERN_ERR
"%s: Error %d setting port type\n",
2615 /* Set the channel/frequency */
2616 if (priv
->channel
!= 0 && priv
->iw_mode
!= IW_MODE_INFRA
) {
2617 err
= hermes_write_wordrec(hw
, USER_BAP
,
2618 HERMES_RID_CNFOWNCHANNEL
,
2621 printk(KERN_ERR
"%s: Error %d setting channel %d\n",
2622 dev
->name
, err
, priv
->channel
);
2627 if (priv
->has_ibss
) {
2630 if ((strlen(priv
->desired_essid
) == 0) && (priv
->createibss
)) {
2631 printk(KERN_WARNING
"%s: This firmware requires an "
2632 "ESSID in IBSS-Ad-Hoc mode.\n", dev
->name
);
2633 /* With wvlan_cs, in this case, we would crash.
2634 * hopefully, this driver will behave better...
2638 createibss
= priv
->createibss
;
2641 err
= hermes_write_wordrec(hw
, USER_BAP
,
2642 HERMES_RID_CNFCREATEIBSS
,
2645 printk(KERN_ERR
"%s: Error %d setting CREATEIBSS\n",
2651 /* Set the desired BSSID */
2652 err
= __orinoco_hw_set_wap(priv
);
2654 printk(KERN_ERR
"%s: Error %d setting AP address\n",
2658 /* Set the desired ESSID */
2659 idbuf
.len
= cpu_to_le16(strlen(priv
->desired_essid
));
2660 memcpy(&idbuf
.val
, priv
->desired_essid
, sizeof(idbuf
.val
));
2661 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
2662 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNSSID
,
2663 HERMES_BYTES_TO_RECLEN(strlen(priv
->desired_essid
)+2),
2666 printk(KERN_ERR
"%s: Error %d setting OWNSSID\n",
2670 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFDESIREDSSID
,
2671 HERMES_BYTES_TO_RECLEN(strlen(priv
->desired_essid
)+2),
2674 printk(KERN_ERR
"%s: Error %d setting DESIREDSSID\n",
2679 /* Set the station name */
2680 idbuf
.len
= cpu_to_le16(strlen(priv
->nick
));
2681 memcpy(&idbuf
.val
, priv
->nick
, sizeof(idbuf
.val
));
2682 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNNAME
,
2683 HERMES_BYTES_TO_RECLEN(strlen(priv
->nick
)+2),
2686 printk(KERN_ERR
"%s: Error %d setting nickname\n",
2691 /* Set AP density */
2692 if (priv
->has_sensitivity
) {
2693 err
= hermes_write_wordrec(hw
, USER_BAP
,
2694 HERMES_RID_CNFSYSTEMSCALE
,
2697 printk(KERN_WARNING
"%s: Error %d setting SYSTEMSCALE. "
2698 "Disabling sensitivity control\n",
2701 priv
->has_sensitivity
= 0;
2705 /* Set RTS threshold */
2706 err
= hermes_write_wordrec(hw
, USER_BAP
, HERMES_RID_CNFRTSTHRESHOLD
,
2709 printk(KERN_ERR
"%s: Error %d setting RTS threshold\n",
2714 /* Set fragmentation threshold or MWO robustness */
2716 err
= hermes_write_wordrec(hw
, USER_BAP
,
2717 HERMES_RID_CNFMWOROBUST_AGERE
,
2720 err
= hermes_write_wordrec(hw
, USER_BAP
,
2721 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
2724 printk(KERN_ERR
"%s: Error %d setting fragmentation\n",
2730 err
= __orinoco_hw_set_bitrate(priv
);
2732 printk(KERN_ERR
"%s: Error %d setting bitrate\n",
2737 /* Set power management */
2739 err
= hermes_write_wordrec(hw
, USER_BAP
,
2740 HERMES_RID_CNFPMENABLED
,
2743 printk(KERN_ERR
"%s: Error %d setting up PM\n",
2748 err
= hermes_write_wordrec(hw
, USER_BAP
,
2749 HERMES_RID_CNFMULTICASTRECEIVE
,
2752 printk(KERN_ERR
"%s: Error %d setting up PM\n",
2756 err
= hermes_write_wordrec(hw
, USER_BAP
,
2757 HERMES_RID_CNFMAXSLEEPDURATION
,
2760 printk(KERN_ERR
"%s: Error %d setting up PM\n",
2764 err
= hermes_write_wordrec(hw
, USER_BAP
,
2765 HERMES_RID_CNFPMHOLDOVERDURATION
,
2768 printk(KERN_ERR
"%s: Error %d setting up PM\n",
2774 /* Set preamble - only for Symbol so far... */
2775 if (priv
->has_preamble
) {
2776 err
= hermes_write_wordrec(hw
, USER_BAP
,
2777 HERMES_RID_CNFPREAMBLE_SYMBOL
,
2780 printk(KERN_ERR
"%s: Error %d setting preamble\n",
2786 /* Set up encryption */
2787 if (priv
->has_wep
|| priv
->has_wpa
) {
2788 err
= __orinoco_hw_setup_enc(priv
);
2790 printk(KERN_ERR
"%s: Error %d activating encryption\n",
2796 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
2797 /* Enable monitor mode */
2798 dev
->type
= ARPHRD_IEEE80211
;
2799 err
= hermes_docmd_wait(hw
, HERMES_CMD_TEST
|
2800 HERMES_TEST_MONITOR
, 0, NULL
);
2802 /* Disable monitor mode */
2803 dev
->type
= ARPHRD_ETHER
;
2804 err
= hermes_docmd_wait(hw
, HERMES_CMD_TEST
|
2805 HERMES_TEST_STOP
, 0, NULL
);
2810 /* Set promiscuity / multicast*/
2811 priv
->promiscuous
= 0;
2814 /* FIXME: what about netif_tx_lock */
2815 __orinoco_set_multicast_list(dev
);
2820 /* FIXME: return int? */
2822 __orinoco_set_multicast_list(struct net_device
*dev
)
2824 struct orinoco_private
*priv
= netdev_priv(dev
);
2825 hermes_t
*hw
= &priv
->hw
;
2827 int promisc
, mc_count
;
2829 /* The Hermes doesn't seem to have an allmulti mode, so we go
2830 * into promiscuous mode and let the upper levels deal. */
2831 if ( (dev
->flags
& IFF_PROMISC
) || (dev
->flags
& IFF_ALLMULTI
) ||
2832 (dev
->mc_count
> MAX_MULTICAST(priv
)) ) {
2837 mc_count
= dev
->mc_count
;
2840 if (promisc
!= priv
->promiscuous
) {
2841 err
= hermes_write_wordrec(hw
, USER_BAP
,
2842 HERMES_RID_CNFPROMISCUOUSMODE
,
2845 printk(KERN_ERR
"%s: Error %d setting PROMISCUOUSMODE to 1.\n",
2848 priv
->promiscuous
= promisc
;
2851 /* If we're not in promiscuous mode, then we need to set the
2852 * group address if either we want to multicast, or if we were
2853 * multicasting and want to stop */
2854 if (! promisc
&& (mc_count
|| priv
->mc_count
) ) {
2855 struct dev_mc_list
*p
= dev
->mc_list
;
2856 struct hermes_multicast mclist
;
2859 for (i
= 0; i
< mc_count
; i
++) {
2860 /* paranoia: is list shorter than mc_count? */
2862 /* paranoia: bad address size in list? */
2863 BUG_ON(p
->dmi_addrlen
!= ETH_ALEN
);
2865 memcpy(mclist
.addr
[i
], p
->dmi_addr
, ETH_ALEN
);
2870 printk(KERN_WARNING
"%s: Multicast list is "
2871 "longer than mc_count\n", dev
->name
);
2873 err
= hermes_write_ltv(hw
, USER_BAP
,
2874 HERMES_RID_CNFGROUPADDRESSES
,
2875 HERMES_BYTES_TO_RECLEN(mc_count
* ETH_ALEN
),
2878 printk(KERN_ERR
"%s: Error %d setting multicast list.\n",
2881 priv
->mc_count
= mc_count
;
2885 /* This must be called from user context, without locks held - use
2886 * schedule_work() */
2887 static void orinoco_reset(struct work_struct
*work
)
2889 struct orinoco_private
*priv
=
2890 container_of(work
, struct orinoco_private
, reset_work
);
2891 struct net_device
*dev
= priv
->ndev
;
2892 struct hermes
*hw
= &priv
->hw
;
2894 unsigned long flags
;
2896 if (orinoco_lock(priv
, &flags
) != 0)
2897 /* When the hardware becomes available again, whatever
2898 * detects that is responsible for re-initializing
2899 * it. So no need for anything further */
2902 netif_stop_queue(dev
);
2904 /* Shut off interrupts. Depending on what state the hardware
2905 * is in, this might not work, but we'll try anyway */
2906 hermes_set_irqmask(hw
, 0);
2907 hermes_write_regn(hw
, EVACK
, 0xffff);
2909 priv
->hw_unavailable
++;
2910 priv
->last_linkstatus
= 0xffff; /* firmware will have to reassociate */
2911 netif_carrier_off(dev
);
2913 orinoco_unlock(priv
, &flags
);
2915 /* Scanning support: Cleanup of driver struct */
2916 orinoco_clear_scan_results(priv
, 0);
2917 priv
->scan_inprogress
= 0;
2919 if (priv
->hard_reset
) {
2920 err
= (*priv
->hard_reset
)(priv
);
2922 printk(KERN_ERR
"%s: orinoco_reset: Error %d "
2923 "performing hard reset\n", dev
->name
, err
);
2928 if (priv
->do_fw_download
) {
2929 err
= orinoco_download(priv
);
2931 priv
->do_fw_download
= 0;
2934 err
= orinoco_reinit_firmware(dev
);
2936 printk(KERN_ERR
"%s: orinoco_reset: Error %d re-initializing firmware\n",
2941 spin_lock_irq(&priv
->lock
); /* This has to be called from user context */
2943 priv
->hw_unavailable
--;
2945 /* priv->open or priv->hw_unavailable might have changed while
2946 * we dropped the lock */
2947 if (priv
->open
&& (! priv
->hw_unavailable
)) {
2948 err
= __orinoco_up(dev
);
2950 printk(KERN_ERR
"%s: orinoco_reset: Error %d reenabling card\n",
2953 dev
->trans_start
= jiffies
;
2956 spin_unlock_irq(&priv
->lock
);
2960 hermes_set_irqmask(hw
, 0);
2961 netif_device_detach(dev
);
2962 printk(KERN_ERR
"%s: Device has been disabled!\n", dev
->name
);
2965 /********************************************************************/
2966 /* Interrupt handler */
2967 /********************************************************************/
2969 static void __orinoco_ev_tick(struct net_device
*dev
, hermes_t
*hw
)
2971 printk(KERN_DEBUG
"%s: TICK\n", dev
->name
);
2974 static void __orinoco_ev_wterr(struct net_device
*dev
, hermes_t
*hw
)
2976 /* This seems to happen a fair bit under load, but ignoring it
2977 seems to work fine...*/
2978 printk(KERN_DEBUG
"%s: MAC controller error (WTERR). Ignoring.\n",
2982 irqreturn_t
orinoco_interrupt(int irq
, void *dev_id
)
2984 struct net_device
*dev
= dev_id
;
2985 struct orinoco_private
*priv
= netdev_priv(dev
);
2986 hermes_t
*hw
= &priv
->hw
;
2987 int count
= MAX_IRQLOOPS_PER_IRQ
;
2989 /* These are used to detect a runaway interrupt situation */
2990 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2991 * we panic and shut down the hardware */
2992 static int last_irq_jiffy
= 0; /* jiffies value the last time
2994 static int loops_this_jiffy
= 0;
2995 unsigned long flags
;
2997 if (orinoco_lock(priv
, &flags
) != 0) {
2998 /* If hw is unavailable - we don't know if the irq was
3003 evstat
= hermes_read_regn(hw
, EVSTAT
);
3004 events
= evstat
& hw
->inten
;
3006 orinoco_unlock(priv
, &flags
);
3010 if (jiffies
!= last_irq_jiffy
)
3011 loops_this_jiffy
= 0;
3012 last_irq_jiffy
= jiffies
;
3014 while (events
&& count
--) {
3015 if (++loops_this_jiffy
> MAX_IRQLOOPS_PER_JIFFY
) {
3016 printk(KERN_WARNING
"%s: IRQ handler is looping too "
3017 "much! Resetting.\n", dev
->name
);
3018 /* Disable interrupts for now */
3019 hermes_set_irqmask(hw
, 0);
3020 schedule_work(&priv
->reset_work
);
3024 /* Check the card hasn't been removed */
3025 if (! hermes_present(hw
)) {
3026 DEBUG(0, "orinoco_interrupt(): card removed\n");
3030 if (events
& HERMES_EV_TICK
)
3031 __orinoco_ev_tick(dev
, hw
);
3032 if (events
& HERMES_EV_WTERR
)
3033 __orinoco_ev_wterr(dev
, hw
);
3034 if (events
& HERMES_EV_INFDROP
)
3035 __orinoco_ev_infdrop(dev
, hw
);
3036 if (events
& HERMES_EV_INFO
)
3037 __orinoco_ev_info(dev
, hw
);
3038 if (events
& HERMES_EV_RX
)
3039 __orinoco_ev_rx(dev
, hw
);
3040 if (events
& HERMES_EV_TXEXC
)
3041 __orinoco_ev_txexc(dev
, hw
);
3042 if (events
& HERMES_EV_TX
)
3043 __orinoco_ev_tx(dev
, hw
);
3044 if (events
& HERMES_EV_ALLOC
)
3045 __orinoco_ev_alloc(dev
, hw
);
3047 hermes_write_regn(hw
, EVACK
, evstat
);
3049 evstat
= hermes_read_regn(hw
, EVSTAT
);
3050 events
= evstat
& hw
->inten
;
3053 orinoco_unlock(priv
, &flags
);
3057 /********************************************************************/
3058 /* Initialization */
3059 /********************************************************************/
3062 u16 id
, variant
, major
, minor
;
3063 } __attribute__ ((packed
));
3065 static inline fwtype_t
determine_firmware_type(struct comp_id
*nic_id
)
3067 if (nic_id
->id
< 0x8000)
3068 return FIRMWARE_TYPE_AGERE
;
3069 else if (nic_id
->id
== 0x8000 && nic_id
->major
== 0)
3070 return FIRMWARE_TYPE_SYMBOL
;
3072 return FIRMWARE_TYPE_INTERSIL
;
3075 /* Set priv->firmware type, determine firmware properties */
3076 static int determine_firmware(struct net_device
*dev
)
3078 struct orinoco_private
*priv
= netdev_priv(dev
);
3079 hermes_t
*hw
= &priv
->hw
;
3081 struct comp_id nic_id
, sta_id
;
3082 unsigned int firmver
;
3083 char tmp
[SYMBOL_MAX_VER_LEN
+1] __attribute__((aligned(2)));
3085 /* Get the hardware version */
3086 err
= HERMES_READ_RECORD(hw
, USER_BAP
, HERMES_RID_NICID
, &nic_id
);
3088 printk(KERN_ERR
"%s: Cannot read hardware identity: error %d\n",
3093 le16_to_cpus(&nic_id
.id
);
3094 le16_to_cpus(&nic_id
.variant
);
3095 le16_to_cpus(&nic_id
.major
);
3096 le16_to_cpus(&nic_id
.minor
);
3097 printk(KERN_DEBUG
"%s: Hardware identity %04x:%04x:%04x:%04x\n",
3098 dev
->name
, nic_id
.id
, nic_id
.variant
,
3099 nic_id
.major
, nic_id
.minor
);
3101 priv
->firmware_type
= determine_firmware_type(&nic_id
);
3103 /* Get the firmware version */
3104 err
= HERMES_READ_RECORD(hw
, USER_BAP
, HERMES_RID_STAID
, &sta_id
);
3106 printk(KERN_ERR
"%s: Cannot read station identity: error %d\n",
3111 le16_to_cpus(&sta_id
.id
);
3112 le16_to_cpus(&sta_id
.variant
);
3113 le16_to_cpus(&sta_id
.major
);
3114 le16_to_cpus(&sta_id
.minor
);
3115 printk(KERN_DEBUG
"%s: Station identity %04x:%04x:%04x:%04x\n",
3116 dev
->name
, sta_id
.id
, sta_id
.variant
,
3117 sta_id
.major
, sta_id
.minor
);
3119 switch (sta_id
.id
) {
3121 printk(KERN_ERR
"%s: Primary firmware is active\n",
3125 printk(KERN_ERR
"%s: Tertiary firmware is active\n",
3128 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
3129 case 0x21: /* Symbol Spectrum24 Trilogy */
3132 printk(KERN_NOTICE
"%s: Unknown station ID, please report\n",
3137 /* Default capabilities */
3138 priv
->has_sensitivity
= 1;
3140 priv
->has_preamble
= 0;
3141 priv
->has_port3
= 1;
3144 priv
->has_big_wep
= 0;
3145 priv
->has_alt_txcntl
= 0;
3146 priv
->has_ext_scan
= 0;
3148 priv
->do_fw_download
= 0;
3150 /* Determine capabilities from the firmware version */
3151 switch (priv
->firmware_type
) {
3152 case FIRMWARE_TYPE_AGERE
:
3153 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
3154 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
3155 snprintf(priv
->fw_name
, sizeof(priv
->fw_name
) - 1,
3156 "Lucent/Agere %d.%02d", sta_id
.major
, sta_id
.minor
);
3158 firmver
= ((unsigned long)sta_id
.major
<< 16) | sta_id
.minor
;
3160 priv
->has_ibss
= (firmver
>= 0x60006);
3161 priv
->has_wep
= (firmver
>= 0x40020);
3162 priv
->has_big_wep
= 1; /* FIXME: this is wrong - how do we tell
3163 Gold cards from the others? */
3164 priv
->has_mwo
= (firmver
>= 0x60000);
3165 priv
->has_pm
= (firmver
>= 0x40020); /* Don't work in 7.52 ? */
3166 priv
->ibss_port
= 1;
3167 priv
->has_hostscan
= (firmver
>= 0x8000a);
3168 priv
->do_fw_download
= 1;
3169 priv
->broken_monitor
= (firmver
>= 0x80000);
3170 priv
->has_alt_txcntl
= (firmver
>= 0x90000); /* All 9.x ? */
3171 priv
->has_ext_scan
= (firmver
>= 0x90000); /* All 9.x ? */
3172 priv
->has_wpa
= (firmver
>= 0x9002a);
3173 /* Tested with Agere firmware :
3174 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
3175 * Tested CableTron firmware : 4.32 => Anton */
3177 case FIRMWARE_TYPE_SYMBOL
:
3178 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
3179 /* Intel MAC : 00:02:B3:* */
3180 /* 3Com MAC : 00:50:DA:* */
3181 memset(tmp
, 0, sizeof(tmp
));
3182 /* Get the Symbol firmware version */
3183 err
= hermes_read_ltv(hw
, USER_BAP
,
3184 HERMES_RID_SECONDARYVERSION_SYMBOL
,
3185 SYMBOL_MAX_VER_LEN
, NULL
, &tmp
);
3188 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
3193 /* The firmware revision is a string, the format is
3194 * something like : "V2.20-01".
3195 * Quick and dirty parsing... - Jean II
3197 firmver
= ((tmp
[1] - '0') << 16) | ((tmp
[3] - '0') << 12)
3198 | ((tmp
[4] - '0') << 8) | ((tmp
[6] - '0') << 4)
3201 tmp
[SYMBOL_MAX_VER_LEN
] = '\0';
3204 snprintf(priv
->fw_name
, sizeof(priv
->fw_name
) - 1,
3207 priv
->has_ibss
= (firmver
>= 0x20000);
3208 priv
->has_wep
= (firmver
>= 0x15012);
3209 priv
->has_big_wep
= (firmver
>= 0x20000);
3210 priv
->has_pm
= (firmver
>= 0x20000 && firmver
< 0x22000) ||
3211 (firmver
>= 0x29000 && firmver
< 0x30000) ||
3213 priv
->has_preamble
= (firmver
>= 0x20000);
3214 priv
->ibss_port
= 4;
3216 /* Symbol firmware is found on various cards, but
3217 * there has been no attempt to check firmware
3218 * download on non-spectrum_cs based cards.
3220 * Given that the Agere firmware download works
3221 * differently, we should avoid doing a firmware
3222 * download with the Symbol algorithm on non-spectrum
3225 * For now we can identify a spectrum_cs based card
3226 * because it has a firmware reset function.
3228 priv
->do_fw_download
= (priv
->stop_fw
!= NULL
);
3230 priv
->broken_disableport
= (firmver
== 0x25013) ||
3231 (firmver
>= 0x30000 && firmver
<= 0x31000);
3232 priv
->has_hostscan
= (firmver
>= 0x31001) ||
3233 (firmver
>= 0x29057 && firmver
< 0x30000);
3234 /* Tested with Intel firmware : 0x20015 => Jean II */
3235 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
3237 case FIRMWARE_TYPE_INTERSIL
:
3238 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
3239 * Samsung, Compaq 100/200 and Proxim are slightly
3240 * different and less well tested */
3241 /* D-Link MAC : 00:40:05:* */
3242 /* Addtron MAC : 00:90:D1:* */
3243 snprintf(priv
->fw_name
, sizeof(priv
->fw_name
) - 1,
3244 "Intersil %d.%d.%d", sta_id
.major
, sta_id
.minor
,
3247 firmver
= ((unsigned long)sta_id
.major
<< 16) |
3248 ((unsigned long)sta_id
.minor
<< 8) | sta_id
.variant
;
3250 priv
->has_ibss
= (firmver
>= 0x000700); /* FIXME */
3251 priv
->has_big_wep
= priv
->has_wep
= (firmver
>= 0x000800);
3252 priv
->has_pm
= (firmver
>= 0x000700);
3253 priv
->has_hostscan
= (firmver
>= 0x010301);
3255 if (firmver
>= 0x000800)
3256 priv
->ibss_port
= 0;
3258 printk(KERN_NOTICE
"%s: Intersil firmware earlier "
3259 "than v0.8.x - several features not supported\n",
3261 priv
->ibss_port
= 1;
3265 printk(KERN_DEBUG
"%s: Firmware determined as %s\n", dev
->name
,
3271 static int orinoco_init(struct net_device
*dev
)
3273 struct orinoco_private
*priv
= netdev_priv(dev
);
3274 hermes_t
*hw
= &priv
->hw
;
3276 struct hermes_idstring nickbuf
;
3280 /* No need to lock, the hw_unavailable flag is already set in
3281 * alloc_orinocodev() */
3282 priv
->nicbuf_size
= IEEE80211_FRAME_LEN
+ ETH_HLEN
;
3284 /* Initialize the firmware */
3285 err
= hermes_init(hw
);
3287 printk(KERN_ERR
"%s: failed to initialize firmware (err = %d)\n",
3292 err
= determine_firmware(dev
);
3294 printk(KERN_ERR
"%s: Incompatible firmware, aborting\n",
3299 if (priv
->do_fw_download
) {
3300 err
= orinoco_download(priv
);
3302 priv
->do_fw_download
= 0;
3304 /* Check firmware version again */
3305 err
= determine_firmware(dev
);
3307 printk(KERN_ERR
"%s: Incompatible firmware, aborting\n",
3313 if (priv
->has_port3
)
3314 printk(KERN_DEBUG
"%s: Ad-hoc demo mode supported\n", dev
->name
);
3316 printk(KERN_DEBUG
"%s: IEEE standard IBSS ad-hoc mode supported\n",
3318 if (priv
->has_wep
) {
3319 printk(KERN_DEBUG
"%s: WEP supported, ", dev
->name
);
3320 if (priv
->has_big_wep
)
3321 printk("104-bit key\n");
3323 printk("40-bit key\n");
3325 if (priv
->has_wpa
) {
3326 printk(KERN_DEBUG
"%s: WPA-PSK supported\n", dev
->name
);
3327 if (orinoco_mic_init(priv
)) {
3328 printk(KERN_ERR
"%s: Failed to setup MIC crypto "
3329 "algorithm. Disabling WPA support\n", dev
->name
);
3334 /* Now we have the firmware capabilities, allocate appropiate
3335 * sized scan buffers */
3336 if (orinoco_bss_data_allocate(priv
))
3338 orinoco_bss_data_init(priv
);
3340 /* Get the MAC address */
3341 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNMACADDR
,
3342 ETH_ALEN
, NULL
, dev
->dev_addr
);
3344 printk(KERN_WARNING
"%s: failed to read MAC address!\n",
3349 printk(KERN_DEBUG
"%s: MAC address %pM\n",
3350 dev
->name
, dev
->dev_addr
);
3352 /* Get the station name */
3353 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNNAME
,
3354 sizeof(nickbuf
), &reclen
, &nickbuf
);
3356 printk(KERN_ERR
"%s: failed to read station name\n",
3361 len
= min(IW_ESSID_MAX_SIZE
, (int)le16_to_cpu(nickbuf
.len
));
3363 len
= min(IW_ESSID_MAX_SIZE
, 2 * reclen
);
3364 memcpy(priv
->nick
, &nickbuf
.val
, len
);
3365 priv
->nick
[len
] = '\0';
3367 printk(KERN_DEBUG
"%s: Station name \"%s\"\n", dev
->name
, priv
->nick
);
3369 err
= orinoco_allocate_fid(dev
);
3371 printk(KERN_ERR
"%s: failed to allocate NIC buffer!\n",
3376 /* Get allowed channels */
3377 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CHANNELLIST
,
3378 &priv
->channel_mask
);
3380 printk(KERN_ERR
"%s: failed to read channel list!\n",
3385 /* Get initial AP density */
3386 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFSYSTEMSCALE
,
3388 if (err
|| priv
->ap_density
< 1 || priv
->ap_density
> 3) {
3389 priv
->has_sensitivity
= 0;
3392 /* Get initial RTS threshold */
3393 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFRTSTHRESHOLD
,
3396 printk(KERN_ERR
"%s: failed to read RTS threshold!\n",
3401 /* Get initial fragmentation settings */
3403 err
= hermes_read_wordrec(hw
, USER_BAP
,
3404 HERMES_RID_CNFMWOROBUST_AGERE
,
3407 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
3408 &priv
->frag_thresh
);
3410 printk(KERN_ERR
"%s: failed to read fragmentation settings!\n",
3415 /* Power management setup */
3419 err
= hermes_read_wordrec(hw
, USER_BAP
,
3420 HERMES_RID_CNFMAXSLEEPDURATION
,
3423 printk(KERN_ERR
"%s: failed to read power management period!\n",
3427 err
= hermes_read_wordrec(hw
, USER_BAP
,
3428 HERMES_RID_CNFPMHOLDOVERDURATION
,
3431 printk(KERN_ERR
"%s: failed to read power management timeout!\n",
3437 /* Preamble setup */
3438 if (priv
->has_preamble
) {
3439 err
= hermes_read_wordrec(hw
, USER_BAP
,
3440 HERMES_RID_CNFPREAMBLE_SYMBOL
,
3446 /* Set up the default configuration */
3447 priv
->iw_mode
= IW_MODE_INFRA
;
3448 /* By default use IEEE/IBSS ad-hoc mode if we have it */
3449 priv
->prefer_port3
= priv
->has_port3
&& (! priv
->has_ibss
);
3450 set_port_type(priv
);
3451 priv
->channel
= 0; /* use firmware default */
3453 priv
->promiscuous
= 0;
3454 priv
->encode_alg
= IW_ENCODE_ALG_NONE
;
3456 priv
->wpa_enabled
= 0;
3457 priv
->tkip_cm_active
= 0;
3459 priv
->wpa_ie_len
= 0;
3460 priv
->wpa_ie
= NULL
;
3462 /* Make the hardware available, as long as it hasn't been
3463 * removed elsewhere (e.g. by PCMCIA hot unplug) */
3464 spin_lock_irq(&priv
->lock
);
3465 priv
->hw_unavailable
--;
3466 spin_unlock_irq(&priv
->lock
);
3468 printk(KERN_DEBUG
"%s: ready\n", dev
->name
);
3475 *alloc_orinocodev(int sizeof_card
,
3476 struct device
*device
,
3477 int (*hard_reset
)(struct orinoco_private
*),
3478 int (*stop_fw
)(struct orinoco_private
*, int))
3480 struct net_device
*dev
;
3481 struct orinoco_private
*priv
;
3483 dev
= alloc_etherdev(sizeof(struct orinoco_private
) + sizeof_card
);
3486 priv
= netdev_priv(dev
);
3489 priv
->card
= (void *)((unsigned long)priv
3490 + sizeof(struct orinoco_private
));
3495 /* Setup / override net_device fields */
3496 dev
->init
= orinoco_init
;
3497 dev
->hard_start_xmit
= orinoco_xmit
;
3498 dev
->tx_timeout
= orinoco_tx_timeout
;
3499 dev
->watchdog_timeo
= HZ
; /* 1 second timeout */
3500 dev
->get_stats
= orinoco_get_stats
;
3501 dev
->ethtool_ops
= &orinoco_ethtool_ops
;
3502 dev
->wireless_handlers
= (struct iw_handler_def
*)&orinoco_handler_def
;
3504 priv
->wireless_data
.spy_data
= &priv
->spy_data
;
3505 dev
->wireless_data
= &priv
->wireless_data
;
3507 dev
->change_mtu
= orinoco_change_mtu
;
3508 dev
->set_multicast_list
= orinoco_set_multicast_list
;
3509 /* we use the default eth_mac_addr for setting the MAC addr */
3511 /* Reserve space in skb for the SNAP header */
3512 dev
->hard_header_len
+= ENCAPS_OVERHEAD
;
3514 /* Set up default callbacks */
3515 dev
->open
= orinoco_open
;
3516 dev
->stop
= orinoco_stop
;
3517 priv
->hard_reset
= hard_reset
;
3518 priv
->stop_fw
= stop_fw
;
3520 spin_lock_init(&priv
->lock
);
3522 priv
->hw_unavailable
= 1; /* orinoco_init() must clear this
3523 * before anything else touches the
3525 INIT_WORK(&priv
->reset_work
, orinoco_reset
);
3526 INIT_WORK(&priv
->join_work
, orinoco_join_ap
);
3527 INIT_WORK(&priv
->wevent_work
, orinoco_send_wevents
);
3529 INIT_LIST_HEAD(&priv
->rx_list
);
3530 tasklet_init(&priv
->rx_tasklet
, orinoco_rx_isr_tasklet
,
3531 (unsigned long) dev
);
3533 netif_carrier_off(dev
);
3534 priv
->last_linkstatus
= 0xffff;
3539 void free_orinocodev(struct net_device
*dev
)
3541 struct orinoco_private
*priv
= netdev_priv(dev
);
3543 /* No need to empty priv->rx_list: if the tasklet is scheduled
3544 * when we call tasklet_kill it will run one final time,
3545 * emptying the list */
3546 tasklet_kill(&priv
->rx_tasklet
);
3547 priv
->wpa_ie_len
= 0;
3548 kfree(priv
->wpa_ie
);
3549 orinoco_mic_free(priv
);
3550 orinoco_bss_data_free(priv
);
3554 /********************************************************************/
3555 /* Wireless extensions */
3556 /********************************************************************/
3558 /* Return : < 0 -> error code ; >= 0 -> length */
3559 static int orinoco_hw_get_essid(struct orinoco_private
*priv
, int *active
,
3560 char buf
[IW_ESSID_MAX_SIZE
+1])
3562 hermes_t
*hw
= &priv
->hw
;
3564 struct hermes_idstring essidbuf
;
3565 char *p
= (char *)(&essidbuf
.val
);
3567 unsigned long flags
;
3569 if (orinoco_lock(priv
, &flags
) != 0)
3572 if (strlen(priv
->desired_essid
) > 0) {
3573 /* We read the desired SSID from the hardware rather
3574 than from priv->desired_essid, just in case the
3575 firmware is allowed to change it on us. I'm not
3577 /* My guess is that the OWNSSID should always be whatever
3578 * we set to the card, whereas CURRENT_SSID is the one that
3579 * may change... - Jean II */
3584 rid
= (priv
->port_type
== 3) ? HERMES_RID_CNFOWNSSID
:
3585 HERMES_RID_CNFDESIREDSSID
;
3587 err
= hermes_read_ltv(hw
, USER_BAP
, rid
, sizeof(essidbuf
),
3594 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENTSSID
,
3595 sizeof(essidbuf
), NULL
, &essidbuf
);
3600 len
= le16_to_cpu(essidbuf
.len
);
3601 BUG_ON(len
> IW_ESSID_MAX_SIZE
);
3603 memset(buf
, 0, IW_ESSID_MAX_SIZE
);
3604 memcpy(buf
, p
, len
);
3608 orinoco_unlock(priv
, &flags
);
3613 static long orinoco_hw_get_freq(struct orinoco_private
*priv
)
3616 hermes_t
*hw
= &priv
->hw
;
3620 unsigned long flags
;
3622 if (orinoco_lock(priv
, &flags
) != 0)
3625 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CURRENTCHANNEL
, &channel
);
3629 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
3635 if ( (channel
< 1) || (channel
> NUM_CHANNELS
) ) {
3636 printk(KERN_WARNING
"%s: Channel out of range (%d)!\n",
3637 priv
->ndev
->name
, channel
);
3642 freq
= channel_frequency
[channel
-1] * 100000;
3645 orinoco_unlock(priv
, &flags
);
3649 return err
? err
: freq
;
3652 static int orinoco_hw_get_bitratelist(struct orinoco_private
*priv
,
3653 int *numrates
, s32
*rates
, int max
)
3655 hermes_t
*hw
= &priv
->hw
;
3656 struct hermes_idstring list
;
3657 unsigned char *p
= (unsigned char *)&list
.val
;
3661 unsigned long flags
;
3663 if (orinoco_lock(priv
, &flags
) != 0)
3666 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_SUPPORTEDDATARATES
,
3667 sizeof(list
), NULL
, &list
);
3668 orinoco_unlock(priv
, &flags
);
3673 num
= le16_to_cpu(list
.len
);
3675 num
= min(num
, max
);
3677 for (i
= 0; i
< num
; i
++) {
3678 rates
[i
] = (p
[i
] & 0x7f) * 500000; /* convert to bps */
3684 static int orinoco_ioctl_getname(struct net_device
*dev
,
3685 struct iw_request_info
*info
,
3689 struct orinoco_private
*priv
= netdev_priv(dev
);
3693 err
= orinoco_hw_get_bitratelist(priv
, &numrates
, NULL
, 0);
3695 if (!err
&& (numrates
> 2))
3696 strcpy(name
, "IEEE 802.11b");
3698 strcpy(name
, "IEEE 802.11-DS");
3703 static int orinoco_ioctl_setwap(struct net_device
*dev
,
3704 struct iw_request_info
*info
,
3705 struct sockaddr
*ap_addr
,
3708 struct orinoco_private
*priv
= netdev_priv(dev
);
3709 int err
= -EINPROGRESS
; /* Call commit handler */
3710 unsigned long flags
;
3711 static const u8 off_addr
[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3712 static const u8 any_addr
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3714 if (orinoco_lock(priv
, &flags
) != 0)
3717 /* Enable automatic roaming - no sanity checks are needed */
3718 if (memcmp(&ap_addr
->sa_data
, off_addr
, ETH_ALEN
) == 0 ||
3719 memcmp(&ap_addr
->sa_data
, any_addr
, ETH_ALEN
) == 0) {
3720 priv
->bssid_fixed
= 0;
3721 memset(priv
->desired_bssid
, 0, ETH_ALEN
);
3723 /* "off" means keep existing connection */
3724 if (ap_addr
->sa_data
[0] == 0) {
3725 __orinoco_hw_set_wap(priv
);
3731 if (priv
->firmware_type
== FIRMWARE_TYPE_AGERE
) {
3732 printk(KERN_WARNING
"%s: Lucent/Agere firmware doesn't "
3733 "support manual roaming\n",
3739 if (priv
->iw_mode
!= IW_MODE_INFRA
) {
3740 printk(KERN_WARNING
"%s: Manual roaming supported only in "
3741 "managed mode\n", dev
->name
);
3746 /* Intersil firmware hangs without Desired ESSID */
3747 if (priv
->firmware_type
== FIRMWARE_TYPE_INTERSIL
&&
3748 strlen(priv
->desired_essid
) == 0) {
3749 printk(KERN_WARNING
"%s: Desired ESSID must be set for "
3750 "manual roaming\n", dev
->name
);
3755 /* Finally, enable manual roaming */
3756 priv
->bssid_fixed
= 1;
3757 memcpy(priv
->desired_bssid
, &ap_addr
->sa_data
, ETH_ALEN
);
3760 orinoco_unlock(priv
, &flags
);
3764 static int orinoco_ioctl_getwap(struct net_device
*dev
,
3765 struct iw_request_info
*info
,
3766 struct sockaddr
*ap_addr
,
3769 struct orinoco_private
*priv
= netdev_priv(dev
);
3771 hermes_t
*hw
= &priv
->hw
;
3773 unsigned long flags
;
3775 if (orinoco_lock(priv
, &flags
) != 0)
3778 ap_addr
->sa_family
= ARPHRD_ETHER
;
3779 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENTBSSID
,
3780 ETH_ALEN
, NULL
, ap_addr
->sa_data
);
3782 orinoco_unlock(priv
, &flags
);
3787 static int orinoco_ioctl_setmode(struct net_device
*dev
,
3788 struct iw_request_info
*info
,
3792 struct orinoco_private
*priv
= netdev_priv(dev
);
3793 int err
= -EINPROGRESS
; /* Call commit handler */
3794 unsigned long flags
;
3796 if (priv
->iw_mode
== *mode
)
3799 if (orinoco_lock(priv
, &flags
) != 0)
3804 if (!priv
->has_ibss
&& !priv
->has_port3
)
3811 case IW_MODE_MONITOR
:
3812 if (priv
->broken_monitor
&& !force_monitor
) {
3813 printk(KERN_WARNING
"%s: Monitor mode support is "
3814 "buggy in this firmware, not enabling\n",
3825 if (err
== -EINPROGRESS
) {
3826 priv
->iw_mode
= *mode
;
3827 set_port_type(priv
);
3830 orinoco_unlock(priv
, &flags
);
3835 static int orinoco_ioctl_getmode(struct net_device
*dev
,
3836 struct iw_request_info
*info
,
3840 struct orinoco_private
*priv
= netdev_priv(dev
);
3842 *mode
= priv
->iw_mode
;
3846 static int orinoco_ioctl_getiwrange(struct net_device
*dev
,
3847 struct iw_request_info
*info
,
3848 struct iw_point
*rrq
,
3851 struct orinoco_private
*priv
= netdev_priv(dev
);
3853 struct iw_range
*range
= (struct iw_range
*) extra
;
3857 rrq
->length
= sizeof(struct iw_range
);
3858 memset(range
, 0, sizeof(struct iw_range
));
3860 range
->we_version_compiled
= WIRELESS_EXT
;
3861 range
->we_version_source
= 22;
3863 /* Set available channels/frequencies */
3864 range
->num_channels
= NUM_CHANNELS
;
3866 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
3867 if (priv
->channel_mask
& (1 << i
)) {
3868 range
->freq
[k
].i
= i
+ 1;
3869 range
->freq
[k
].m
= channel_frequency
[i
] * 100000;
3870 range
->freq
[k
].e
= 1;
3874 if (k
>= IW_MAX_FREQUENCIES
)
3877 range
->num_frequency
= k
;
3878 range
->sensitivity
= 3;
3880 if (priv
->has_wep
) {
3881 range
->max_encoding_tokens
= ORINOCO_MAX_KEYS
;
3882 range
->encoding_size
[0] = SMALL_KEY_SIZE
;
3883 range
->num_encoding_sizes
= 1;
3885 if (priv
->has_big_wep
) {
3886 range
->encoding_size
[1] = LARGE_KEY_SIZE
;
3887 range
->num_encoding_sizes
= 2;
3892 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_CIPHER_TKIP
;
3894 if ((priv
->iw_mode
== IW_MODE_ADHOC
) && (!SPY_NUMBER(priv
))){
3895 /* Quality stats meaningless in ad-hoc mode */
3897 range
->max_qual
.qual
= 0x8b - 0x2f;
3898 range
->max_qual
.level
= 0x2f - 0x95 - 1;
3899 range
->max_qual
.noise
= 0x2f - 0x95 - 1;
3900 /* Need to get better values */
3901 range
->avg_qual
.qual
= 0x24;
3902 range
->avg_qual
.level
= 0xC2;
3903 range
->avg_qual
.noise
= 0x9E;
3906 err
= orinoco_hw_get_bitratelist(priv
, &numrates
,
3907 range
->bitrate
, IW_MAX_BITRATES
);
3910 range
->num_bitrates
= numrates
;
3912 /* Set an indication of the max TCP throughput in bit/s that we can
3913 * expect using this interface. May be use for QoS stuff...
3916 range
->throughput
= 5 * 1000 * 1000; /* ~5 Mb/s */
3918 range
->throughput
= 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
3921 range
->max_rts
= 2347;
3922 range
->min_frag
= 256;
3923 range
->max_frag
= 2346;
3926 range
->max_pmp
= 65535000;
3928 range
->max_pmt
= 65535 * 1000; /* ??? */
3929 range
->pmp_flags
= IW_POWER_PERIOD
;
3930 range
->pmt_flags
= IW_POWER_TIMEOUT
;
3931 range
->pm_capa
= IW_POWER_PERIOD
| IW_POWER_TIMEOUT
| IW_POWER_UNICAST_R
;
3933 range
->retry_capa
= IW_RETRY_LIMIT
| IW_RETRY_LIFETIME
;
3934 range
->retry_flags
= IW_RETRY_LIMIT
;
3935 range
->r_time_flags
= IW_RETRY_LIFETIME
;
3936 range
->min_retry
= 0;
3937 range
->max_retry
= 65535; /* ??? */
3938 range
->min_r_time
= 0;
3939 range
->max_r_time
= 65535 * 1000; /* ??? */
3941 if (priv
->firmware_type
== FIRMWARE_TYPE_AGERE
)
3942 range
->scan_capa
= IW_SCAN_CAPA_ESSID
;
3944 range
->scan_capa
= IW_SCAN_CAPA_NONE
;
3946 /* Event capability (kernel) */
3947 IW_EVENT_CAPA_SET_KERNEL(range
->event_capa
);
3948 /* Event capability (driver) */
3949 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWTHRSPY
);
3950 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWAP
);
3951 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWSCAN
);
3952 IW_EVENT_CAPA_SET(range
->event_capa
, IWEVTXDROP
);
3957 static int orinoco_ioctl_setiwencode(struct net_device
*dev
,
3958 struct iw_request_info
*info
,
3959 struct iw_point
*erq
,
3962 struct orinoco_private
*priv
= netdev_priv(dev
);
3963 int index
= (erq
->flags
& IW_ENCODE_INDEX
) - 1;
3964 int setindex
= priv
->tx_key
;
3965 int encode_alg
= priv
->encode_alg
;
3966 int restricted
= priv
->wep_restrict
;
3968 int err
= -EINPROGRESS
; /* Call commit handler */
3969 unsigned long flags
;
3971 if (! priv
->has_wep
)
3975 /* We actually have a key to set - check its length */
3976 if (erq
->length
> LARGE_KEY_SIZE
)
3979 if ( (erq
->length
> SMALL_KEY_SIZE
) && !priv
->has_big_wep
)
3983 if (orinoco_lock(priv
, &flags
) != 0)
3986 /* Clear any TKIP key we have */
3987 if ((priv
->has_wpa
) && (priv
->encode_alg
== IW_ENCODE_ALG_TKIP
))
3988 (void) orinoco_clear_tkip_key(priv
, setindex
);
3990 if (erq
->length
> 0) {
3991 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
))
3992 index
= priv
->tx_key
;
3994 /* Adjust key length to a supported value */
3995 if (erq
->length
> SMALL_KEY_SIZE
) {
3996 xlen
= LARGE_KEY_SIZE
;
3997 } else if (erq
->length
> 0) {
3998 xlen
= SMALL_KEY_SIZE
;
4002 /* Switch on WEP if off */
4003 if ((encode_alg
!= IW_ENCODE_ALG_WEP
) && (xlen
> 0)) {
4005 encode_alg
= IW_ENCODE_ALG_WEP
;
4008 /* Important note : if the user do "iwconfig eth0 enc off",
4009 * we will arrive there with an index of -1. This is valid
4010 * but need to be taken care off... Jean II */
4011 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
)) {
4012 if((index
!= -1) || (erq
->flags
== 0)) {
4017 /* Set the index : Check that the key is valid */
4018 if(priv
->keys
[index
].len
== 0) {
4026 if (erq
->flags
& IW_ENCODE_DISABLED
)
4027 encode_alg
= IW_ENCODE_ALG_NONE
;
4028 if (erq
->flags
& IW_ENCODE_OPEN
)
4030 if (erq
->flags
& IW_ENCODE_RESTRICTED
)
4033 if (erq
->pointer
&& erq
->length
> 0) {
4034 priv
->keys
[index
].len
= cpu_to_le16(xlen
);
4035 memset(priv
->keys
[index
].data
, 0,
4036 sizeof(priv
->keys
[index
].data
));
4037 memcpy(priv
->keys
[index
].data
, keybuf
, erq
->length
);
4039 priv
->tx_key
= setindex
;
4041 /* Try fast key change if connected and only keys are changed */
4042 if ((priv
->encode_alg
== encode_alg
) &&
4043 (priv
->wep_restrict
== restricted
) &&
4044 netif_carrier_ok(dev
)) {
4045 err
= __orinoco_hw_setup_wepkeys(priv
);
4046 /* No need to commit if successful */
4050 priv
->encode_alg
= encode_alg
;
4051 priv
->wep_restrict
= restricted
;
4054 orinoco_unlock(priv
, &flags
);
4059 static int orinoco_ioctl_getiwencode(struct net_device
*dev
,
4060 struct iw_request_info
*info
,
4061 struct iw_point
*erq
,
4064 struct orinoco_private
*priv
= netdev_priv(dev
);
4065 int index
= (erq
->flags
& IW_ENCODE_INDEX
) - 1;
4067 unsigned long flags
;
4069 if (! priv
->has_wep
)
4072 if (orinoco_lock(priv
, &flags
) != 0)
4075 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
))
4076 index
= priv
->tx_key
;
4079 if (!priv
->encode_alg
)
4080 erq
->flags
|= IW_ENCODE_DISABLED
;
4081 erq
->flags
|= index
+ 1;
4083 if (priv
->wep_restrict
)
4084 erq
->flags
|= IW_ENCODE_RESTRICTED
;
4086 erq
->flags
|= IW_ENCODE_OPEN
;
4088 xlen
= le16_to_cpu(priv
->keys
[index
].len
);
4092 memcpy(keybuf
, priv
->keys
[index
].data
, ORINOCO_MAX_KEY_SIZE
);
4094 orinoco_unlock(priv
, &flags
);
4098 static int orinoco_ioctl_setessid(struct net_device
*dev
,
4099 struct iw_request_info
*info
,
4100 struct iw_point
*erq
,
4103 struct orinoco_private
*priv
= netdev_priv(dev
);
4104 unsigned long flags
;
4106 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
4107 * anyway... - Jean II */
4109 /* Hum... Should not use Wireless Extension constant (may change),
4110 * should use our own... - Jean II */
4111 if (erq
->length
> IW_ESSID_MAX_SIZE
)
4114 if (orinoco_lock(priv
, &flags
) != 0)
4117 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
4118 memset(priv
->desired_essid
, 0, sizeof(priv
->desired_essid
));
4120 /* If not ANY, get the new ESSID */
4122 memcpy(priv
->desired_essid
, essidbuf
, erq
->length
);
4125 orinoco_unlock(priv
, &flags
);
4127 return -EINPROGRESS
; /* Call commit handler */
4130 static int orinoco_ioctl_getessid(struct net_device
*dev
,
4131 struct iw_request_info
*info
,
4132 struct iw_point
*erq
,
4135 struct orinoco_private
*priv
= netdev_priv(dev
);
4138 unsigned long flags
;
4140 if (netif_running(dev
)) {
4141 err
= orinoco_hw_get_essid(priv
, &active
, essidbuf
);
4146 if (orinoco_lock(priv
, &flags
) != 0)
4148 memcpy(essidbuf
, priv
->desired_essid
, IW_ESSID_MAX_SIZE
);
4149 erq
->length
= strlen(priv
->desired_essid
);
4150 orinoco_unlock(priv
, &flags
);
4158 static int orinoco_ioctl_setnick(struct net_device
*dev
,
4159 struct iw_request_info
*info
,
4160 struct iw_point
*nrq
,
4163 struct orinoco_private
*priv
= netdev_priv(dev
);
4164 unsigned long flags
;
4166 if (nrq
->length
> IW_ESSID_MAX_SIZE
)
4169 if (orinoco_lock(priv
, &flags
) != 0)
4172 memset(priv
->nick
, 0, sizeof(priv
->nick
));
4173 memcpy(priv
->nick
, nickbuf
, nrq
->length
);
4175 orinoco_unlock(priv
, &flags
);
4177 return -EINPROGRESS
; /* Call commit handler */
4180 static int orinoco_ioctl_getnick(struct net_device
*dev
,
4181 struct iw_request_info
*info
,
4182 struct iw_point
*nrq
,
4185 struct orinoco_private
*priv
= netdev_priv(dev
);
4186 unsigned long flags
;
4188 if (orinoco_lock(priv
, &flags
) != 0)
4191 memcpy(nickbuf
, priv
->nick
, IW_ESSID_MAX_SIZE
);
4192 orinoco_unlock(priv
, &flags
);
4194 nrq
->length
= strlen(priv
->nick
);
4199 static int orinoco_ioctl_setfreq(struct net_device
*dev
,
4200 struct iw_request_info
*info
,
4201 struct iw_freq
*frq
,
4204 struct orinoco_private
*priv
= netdev_priv(dev
);
4206 unsigned long flags
;
4207 int err
= -EINPROGRESS
; /* Call commit handler */
4209 /* In infrastructure mode the AP sets the channel */
4210 if (priv
->iw_mode
== IW_MODE_INFRA
)
4213 if ( (frq
->e
== 0) && (frq
->m
<= 1000) ) {
4214 /* Setting by channel number */
4217 /* Setting by frequency - search the table */
4221 for (i
= 0; i
< (6 - frq
->e
); i
++)
4224 for (i
= 0; i
< NUM_CHANNELS
; i
++)
4225 if (frq
->m
== (channel_frequency
[i
] * mult
))
4229 if ( (chan
< 1) || (chan
> NUM_CHANNELS
) ||
4230 ! (priv
->channel_mask
& (1 << (chan
-1)) ) )
4233 if (orinoco_lock(priv
, &flags
) != 0)
4236 priv
->channel
= chan
;
4237 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
4238 /* Fast channel change - no commit if successful */
4239 hermes_t
*hw
= &priv
->hw
;
4240 err
= hermes_docmd_wait(hw
, HERMES_CMD_TEST
|
4241 HERMES_TEST_SET_CHANNEL
,
4244 orinoco_unlock(priv
, &flags
);
4249 static int orinoco_ioctl_getfreq(struct net_device
*dev
,
4250 struct iw_request_info
*info
,
4251 struct iw_freq
*frq
,
4254 struct orinoco_private
*priv
= netdev_priv(dev
);
4257 /* Locking done in there */
4258 tmp
= orinoco_hw_get_freq(priv
);
4269 static int orinoco_ioctl_getsens(struct net_device
*dev
,
4270 struct iw_request_info
*info
,
4271 struct iw_param
*srq
,
4274 struct orinoco_private
*priv
= netdev_priv(dev
);
4275 hermes_t
*hw
= &priv
->hw
;
4278 unsigned long flags
;
4280 if (!priv
->has_sensitivity
)
4283 if (orinoco_lock(priv
, &flags
) != 0)
4285 err
= hermes_read_wordrec(hw
, USER_BAP
,
4286 HERMES_RID_CNFSYSTEMSCALE
, &val
);
4287 orinoco_unlock(priv
, &flags
);
4293 srq
->fixed
= 0; /* auto */
4298 static int orinoco_ioctl_setsens(struct net_device
*dev
,
4299 struct iw_request_info
*info
,
4300 struct iw_param
*srq
,
4303 struct orinoco_private
*priv
= netdev_priv(dev
);
4304 int val
= srq
->value
;
4305 unsigned long flags
;
4307 if (!priv
->has_sensitivity
)
4310 if ((val
< 1) || (val
> 3))
4313 if (orinoco_lock(priv
, &flags
) != 0)
4315 priv
->ap_density
= val
;
4316 orinoco_unlock(priv
, &flags
);
4318 return -EINPROGRESS
; /* Call commit handler */
4321 static int orinoco_ioctl_setrts(struct net_device
*dev
,
4322 struct iw_request_info
*info
,
4323 struct iw_param
*rrq
,
4326 struct orinoco_private
*priv
= netdev_priv(dev
);
4327 int val
= rrq
->value
;
4328 unsigned long flags
;
4333 if ( (val
< 0) || (val
> 2347) )
4336 if (orinoco_lock(priv
, &flags
) != 0)
4339 priv
->rts_thresh
= val
;
4340 orinoco_unlock(priv
, &flags
);
4342 return -EINPROGRESS
; /* Call commit handler */
4345 static int orinoco_ioctl_getrts(struct net_device
*dev
,
4346 struct iw_request_info
*info
,
4347 struct iw_param
*rrq
,
4350 struct orinoco_private
*priv
= netdev_priv(dev
);
4352 rrq
->value
= priv
->rts_thresh
;
4353 rrq
->disabled
= (rrq
->value
== 2347);
4359 static int orinoco_ioctl_setfrag(struct net_device
*dev
,
4360 struct iw_request_info
*info
,
4361 struct iw_param
*frq
,
4364 struct orinoco_private
*priv
= netdev_priv(dev
);
4365 int err
= -EINPROGRESS
; /* Call commit handler */
4366 unsigned long flags
;
4368 if (orinoco_lock(priv
, &flags
) != 0)
4371 if (priv
->has_mwo
) {
4373 priv
->mwo_robust
= 0;
4376 printk(KERN_WARNING
"%s: Fixed fragmentation is "
4377 "not supported on this firmware. "
4378 "Using MWO robust instead.\n", dev
->name
);
4379 priv
->mwo_robust
= 1;
4383 priv
->frag_thresh
= 2346;
4385 if ( (frq
->value
< 256) || (frq
->value
> 2346) )
4388 priv
->frag_thresh
= frq
->value
& ~0x1; /* must be even */
4392 orinoco_unlock(priv
, &flags
);
4397 static int orinoco_ioctl_getfrag(struct net_device
*dev
,
4398 struct iw_request_info
*info
,
4399 struct iw_param
*frq
,
4402 struct orinoco_private
*priv
= netdev_priv(dev
);
4403 hermes_t
*hw
= &priv
->hw
;
4406 unsigned long flags
;
4408 if (orinoco_lock(priv
, &flags
) != 0)
4411 if (priv
->has_mwo
) {
4412 err
= hermes_read_wordrec(hw
, USER_BAP
,
4413 HERMES_RID_CNFMWOROBUST_AGERE
,
4418 frq
->value
= val
? 2347 : 0;
4419 frq
->disabled
= ! val
;
4422 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
4428 frq
->disabled
= (val
>= 2346);
4432 orinoco_unlock(priv
, &flags
);
4437 static int orinoco_ioctl_setrate(struct net_device
*dev
,
4438 struct iw_request_info
*info
,
4439 struct iw_param
*rrq
,
4442 struct orinoco_private
*priv
= netdev_priv(dev
);
4444 int bitrate
; /* 100s of kilobits */
4446 unsigned long flags
;
4448 /* As the user space doesn't know our highest rate, it uses -1
4449 * to ask us to set the highest rate. Test it using "iwconfig
4450 * ethX rate auto" - Jean II */
4451 if (rrq
->value
== -1)
4454 if (rrq
->value
% 100000)
4456 bitrate
= rrq
->value
/ 100000;
4459 if ( (bitrate
!= 10) && (bitrate
!= 20) &&
4460 (bitrate
!= 55) && (bitrate
!= 110) )
4463 for (i
= 0; i
< BITRATE_TABLE_SIZE
; i
++)
4464 if ( (bitrate_table
[i
].bitrate
== bitrate
) &&
4465 (bitrate_table
[i
].automatic
== ! rrq
->fixed
) ) {
4473 if (orinoco_lock(priv
, &flags
) != 0)
4475 priv
->bitratemode
= ratemode
;
4476 orinoco_unlock(priv
, &flags
);
4478 return -EINPROGRESS
;
4481 static int orinoco_ioctl_getrate(struct net_device
*dev
,
4482 struct iw_request_info
*info
,
4483 struct iw_param
*rrq
,
4486 struct orinoco_private
*priv
= netdev_priv(dev
);
4487 hermes_t
*hw
= &priv
->hw
;
4492 unsigned long flags
;
4494 if (orinoco_lock(priv
, &flags
) != 0)
4497 ratemode
= priv
->bitratemode
;
4499 BUG_ON((ratemode
< 0) || (ratemode
>= BITRATE_TABLE_SIZE
));
4501 rrq
->value
= bitrate_table
[ratemode
].bitrate
* 100000;
4502 rrq
->fixed
= ! bitrate_table
[ratemode
].automatic
;
4505 /* If the interface is running we try to find more about the
4507 if (netif_running(dev
)) {
4508 err
= hermes_read_wordrec(hw
, USER_BAP
,
4509 HERMES_RID_CURRENTTXRATE
, &val
);
4513 switch (priv
->firmware_type
) {
4514 case FIRMWARE_TYPE_AGERE
: /* Lucent style rate */
4515 /* Note : in Lucent firmware, the return value of
4516 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
4517 * and therefore is totally different from the
4518 * encoding of HERMES_RID_CNFTXRATECONTROL.
4519 * Don't forget that 6Mb/s is really 5.5Mb/s */
4521 rrq
->value
= 5500000;
4523 rrq
->value
= val
* 1000000;
4525 case FIRMWARE_TYPE_INTERSIL
: /* Intersil style rate */
4526 case FIRMWARE_TYPE_SYMBOL
: /* Symbol style rate */
4527 for (i
= 0; i
< BITRATE_TABLE_SIZE
; i
++)
4528 if (bitrate_table
[i
].intersil_txratectrl
== val
) {
4532 if (i
>= BITRATE_TABLE_SIZE
)
4533 printk(KERN_INFO
"%s: Unable to determine current bitrate (0x%04hx)\n",
4536 rrq
->value
= bitrate_table
[ratemode
].bitrate
* 100000;
4544 orinoco_unlock(priv
, &flags
);
4549 static int orinoco_ioctl_setpower(struct net_device
*dev
,
4550 struct iw_request_info
*info
,
4551 struct iw_param
*prq
,
4554 struct orinoco_private
*priv
= netdev_priv(dev
);
4555 int err
= -EINPROGRESS
; /* Call commit handler */
4556 unsigned long flags
;
4558 if (orinoco_lock(priv
, &flags
) != 0)
4561 if (prq
->disabled
) {
4564 switch (prq
->flags
& IW_POWER_MODE
) {
4565 case IW_POWER_UNICAST_R
:
4569 case IW_POWER_ALL_R
:
4574 /* No flags : but we may have a value - Jean II */
4581 if (prq
->flags
& IW_POWER_TIMEOUT
) {
4583 priv
->pm_timeout
= prq
->value
/ 1000;
4585 if (prq
->flags
& IW_POWER_PERIOD
) {
4587 priv
->pm_period
= prq
->value
/ 1000;
4589 /* It's valid to not have a value if we are just toggling
4590 * the flags... Jean II */
4598 orinoco_unlock(priv
, &flags
);
4603 static int orinoco_ioctl_getpower(struct net_device
*dev
,
4604 struct iw_request_info
*info
,
4605 struct iw_param
*prq
,
4608 struct orinoco_private
*priv
= netdev_priv(dev
);
4609 hermes_t
*hw
= &priv
->hw
;
4611 u16 enable
, period
, timeout
, mcast
;
4612 unsigned long flags
;
4614 if (orinoco_lock(priv
, &flags
) != 0)
4617 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFPMENABLED
, &enable
);
4621 err
= hermes_read_wordrec(hw
, USER_BAP
,
4622 HERMES_RID_CNFMAXSLEEPDURATION
, &period
);
4626 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFPMHOLDOVERDURATION
, &timeout
);
4630 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFMULTICASTRECEIVE
, &mcast
);
4634 prq
->disabled
= !enable
;
4635 /* Note : by default, display the period */
4636 if ((prq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
4637 prq
->flags
= IW_POWER_TIMEOUT
;
4638 prq
->value
= timeout
* 1000;
4640 prq
->flags
= IW_POWER_PERIOD
;
4641 prq
->value
= period
* 1000;
4644 prq
->flags
|= IW_POWER_ALL_R
;
4646 prq
->flags
|= IW_POWER_UNICAST_R
;
4649 orinoco_unlock(priv
, &flags
);
4654 static int orinoco_ioctl_set_encodeext(struct net_device
*dev
,
4655 struct iw_request_info
*info
,
4656 union iwreq_data
*wrqu
,
4659 struct orinoco_private
*priv
= netdev_priv(dev
);
4660 struct iw_point
*encoding
= &wrqu
->encoding
;
4661 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
4662 int idx
, alg
= ext
->alg
, set_key
= 1;
4663 unsigned long flags
;
4667 if (orinoco_lock(priv
, &flags
) != 0)
4670 /* Determine and validate the key index */
4671 idx
= encoding
->flags
& IW_ENCODE_INDEX
;
4673 if ((idx
< 1) || (idx
> WEP_KEYS
))
4679 if (encoding
->flags
& IW_ENCODE_DISABLED
)
4680 alg
= IW_ENCODE_ALG_NONE
;
4682 if (priv
->has_wpa
&& (alg
!= IW_ENCODE_ALG_TKIP
)) {
4683 /* Clear any TKIP TX key we had */
4684 (void) orinoco_clear_tkip_key(priv
, priv
->tx_key
);
4687 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
) {
4689 set_key
= ((alg
== IW_ENCODE_ALG_TKIP
) ||
4690 (ext
->key_len
> 0)) ? 1 : 0;
4694 /* Set the requested key first */
4696 case IW_ENCODE_ALG_NONE
:
4697 priv
->encode_alg
= alg
;
4698 priv
->keys
[idx
].len
= 0;
4701 case IW_ENCODE_ALG_WEP
:
4702 if (ext
->key_len
> SMALL_KEY_SIZE
)
4703 key_len
= LARGE_KEY_SIZE
;
4704 else if (ext
->key_len
> 0)
4705 key_len
= SMALL_KEY_SIZE
;
4709 priv
->encode_alg
= alg
;
4710 priv
->keys
[idx
].len
= cpu_to_le16(key_len
);
4712 key_len
= min(ext
->key_len
, key_len
);
4714 memset(priv
->keys
[idx
].data
, 0, ORINOCO_MAX_KEY_SIZE
);
4715 memcpy(priv
->keys
[idx
].data
, ext
->key
, key_len
);
4718 case IW_ENCODE_ALG_TKIP
:
4720 hermes_t
*hw
= &priv
->hw
;
4723 if (!priv
->has_wpa
||
4724 (ext
->key_len
> sizeof(priv
->tkip_key
[0])))
4727 priv
->encode_alg
= alg
;
4728 memset(&priv
->tkip_key
[idx
], 0,
4729 sizeof(priv
->tkip_key
[idx
]));
4730 memcpy(&priv
->tkip_key
[idx
], ext
->key
, ext
->key_len
);
4732 if (ext
->ext_flags
& IW_ENCODE_EXT_RX_SEQ_VALID
)
4733 tkip_iv
= &ext
->rx_seq
[0];
4735 err
= __orinoco_hw_set_tkip_key(hw
, idx
,
4736 ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
,
4737 (u8
*) &priv
->tkip_key
[idx
],
4740 printk(KERN_ERR
"%s: Error %d setting TKIP key"
4741 "\n", dev
->name
, err
);
4751 orinoco_unlock(priv
, &flags
);
4756 static int orinoco_ioctl_get_encodeext(struct net_device
*dev
,
4757 struct iw_request_info
*info
,
4758 union iwreq_data
*wrqu
,
4761 struct orinoco_private
*priv
= netdev_priv(dev
);
4762 struct iw_point
*encoding
= &wrqu
->encoding
;
4763 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
4764 int idx
, max_key_len
;
4765 unsigned long flags
;
4768 if (orinoco_lock(priv
, &flags
) != 0)
4772 max_key_len
= encoding
->length
- sizeof(*ext
);
4773 if (max_key_len
< 0)
4776 idx
= encoding
->flags
& IW_ENCODE_INDEX
;
4778 if ((idx
< 1) || (idx
> WEP_KEYS
))
4784 encoding
->flags
= idx
+ 1;
4785 memset(ext
, 0, sizeof(*ext
));
4787 ext
->alg
= priv
->encode_alg
;
4788 switch (priv
->encode_alg
) {
4789 case IW_ENCODE_ALG_NONE
:
4791 encoding
->flags
|= IW_ENCODE_DISABLED
;
4793 case IW_ENCODE_ALG_WEP
:
4794 ext
->key_len
= min_t(u16
, le16_to_cpu(priv
->keys
[idx
].len
),
4796 memcpy(ext
->key
, priv
->keys
[idx
].data
, ext
->key_len
);
4797 encoding
->flags
|= IW_ENCODE_ENABLED
;
4799 case IW_ENCODE_ALG_TKIP
:
4800 ext
->key_len
= min_t(u16
, sizeof(struct orinoco_tkip_key
),
4802 memcpy(ext
->key
, &priv
->tkip_key
[idx
], ext
->key_len
);
4803 encoding
->flags
|= IW_ENCODE_ENABLED
;
4809 orinoco_unlock(priv
, &flags
);
4814 static int orinoco_ioctl_set_auth(struct net_device
*dev
,
4815 struct iw_request_info
*info
,
4816 union iwreq_data
*wrqu
, char *extra
)
4818 struct orinoco_private
*priv
= netdev_priv(dev
);
4819 hermes_t
*hw
= &priv
->hw
;
4820 struct iw_param
*param
= &wrqu
->param
;
4821 unsigned long flags
;
4822 int ret
= -EINPROGRESS
;
4824 if (orinoco_lock(priv
, &flags
) != 0)
4827 switch (param
->flags
& IW_AUTH_INDEX
) {
4828 case IW_AUTH_WPA_VERSION
:
4829 case IW_AUTH_CIPHER_PAIRWISE
:
4830 case IW_AUTH_CIPHER_GROUP
:
4831 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
4832 case IW_AUTH_PRIVACY_INVOKED
:
4833 case IW_AUTH_DROP_UNENCRYPTED
:
4835 * orinoco does not use these parameters
4839 case IW_AUTH_KEY_MGMT
:
4840 /* wl_lkm implies value 2 == PSK for Hermes I
4841 * which ties in with WEXT
4842 * no other hints tho :(
4844 priv
->key_mgmt
= param
->value
;
4847 case IW_AUTH_TKIP_COUNTERMEASURES
:
4848 /* When countermeasures are enabled, shut down the
4849 * card; when disabled, re-enable the card. This must
4850 * take effect immediately.
4852 * TODO: Make sure that the EAPOL message is getting
4853 * out before card disabled
4856 priv
->tkip_cm_active
= 1;
4857 ret
= hermes_enable_port(hw
, 0);
4859 priv
->tkip_cm_active
= 0;
4860 ret
= hermes_disable_port(hw
, 0);
4864 case IW_AUTH_80211_AUTH_ALG
:
4865 if (param
->value
& IW_AUTH_ALG_SHARED_KEY
)
4866 priv
->wep_restrict
= 1;
4867 else if (param
->value
& IW_AUTH_ALG_OPEN_SYSTEM
)
4868 priv
->wep_restrict
= 0;
4873 case IW_AUTH_WPA_ENABLED
:
4874 if (priv
->has_wpa
) {
4875 priv
->wpa_enabled
= param
->value
? 1 : 0;
4879 /* else silently accept disable of WPA */
4880 priv
->wpa_enabled
= 0;
4888 orinoco_unlock(priv
, &flags
);
4892 static int orinoco_ioctl_get_auth(struct net_device
*dev
,
4893 struct iw_request_info
*info
,
4894 union iwreq_data
*wrqu
, char *extra
)
4896 struct orinoco_private
*priv
= netdev_priv(dev
);
4897 struct iw_param
*param
= &wrqu
->param
;
4898 unsigned long flags
;
4901 if (orinoco_lock(priv
, &flags
) != 0)
4904 switch (param
->flags
& IW_AUTH_INDEX
) {
4905 case IW_AUTH_KEY_MGMT
:
4906 param
->value
= priv
->key_mgmt
;
4909 case IW_AUTH_TKIP_COUNTERMEASURES
:
4910 param
->value
= priv
->tkip_cm_active
;
4913 case IW_AUTH_80211_AUTH_ALG
:
4914 if (priv
->wep_restrict
)
4915 param
->value
= IW_AUTH_ALG_SHARED_KEY
;
4917 param
->value
= IW_AUTH_ALG_OPEN_SYSTEM
;
4920 case IW_AUTH_WPA_ENABLED
:
4921 param
->value
= priv
->wpa_enabled
;
4928 orinoco_unlock(priv
, &flags
);
4932 static int orinoco_ioctl_set_genie(struct net_device
*dev
,
4933 struct iw_request_info
*info
,
4934 union iwreq_data
*wrqu
, char *extra
)
4936 struct orinoco_private
*priv
= netdev_priv(dev
);
4938 unsigned long flags
;
4941 if ((wrqu
->data
.length
> MAX_WPA_IE_LEN
) ||
4942 (wrqu
->data
.length
&& (extra
== NULL
)))
4945 if (orinoco_lock(priv
, &flags
) != 0)
4948 if (wrqu
->data
.length
) {
4949 buf
= kmalloc(wrqu
->data
.length
, GFP_KERNEL
);
4955 memcpy(buf
, extra
, wrqu
->data
.length
);
4956 kfree(priv
->wpa_ie
);
4958 priv
->wpa_ie_len
= wrqu
->data
.length
;
4960 kfree(priv
->wpa_ie
);
4961 priv
->wpa_ie
= NULL
;
4962 priv
->wpa_ie_len
= 0;
4966 /* Looks like wl_lkm wants to check the auth alg, and
4967 * somehow pass it to the firmware.
4968 * Instead it just calls the key mgmt rid
4969 * - we do this in set auth.
4974 orinoco_unlock(priv
, &flags
);
4978 static int orinoco_ioctl_get_genie(struct net_device
*dev
,
4979 struct iw_request_info
*info
,
4980 union iwreq_data
*wrqu
, char *extra
)
4982 struct orinoco_private
*priv
= netdev_priv(dev
);
4983 unsigned long flags
;
4986 if (orinoco_lock(priv
, &flags
) != 0)
4989 if ((priv
->wpa_ie_len
== 0) || (priv
->wpa_ie
== NULL
)) {
4990 wrqu
->data
.length
= 0;
4994 if (wrqu
->data
.length
< priv
->wpa_ie_len
) {
4999 wrqu
->data
.length
= priv
->wpa_ie_len
;
5000 memcpy(extra
, priv
->wpa_ie
, priv
->wpa_ie_len
);
5003 orinoco_unlock(priv
, &flags
);
5007 static int orinoco_ioctl_set_mlme(struct net_device
*dev
,
5008 struct iw_request_info
*info
,
5009 union iwreq_data
*wrqu
, char *extra
)
5011 struct orinoco_private
*priv
= netdev_priv(dev
);
5012 hermes_t
*hw
= &priv
->hw
;
5013 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
5014 unsigned long flags
;
5017 if (orinoco_lock(priv
, &flags
) != 0)
5020 switch (mlme
->cmd
) {
5021 case IW_MLME_DEAUTH
:
5022 /* silently ignore */
5025 case IW_MLME_DISASSOC
:
5030 } __attribute__ ((packed
)) buf
;
5032 memcpy(buf
.addr
, mlme
->addr
.sa_data
, ETH_ALEN
);
5033 buf
.reason_code
= cpu_to_le16(mlme
->reason_code
);
5034 ret
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
5035 HERMES_RID_CNFDISASSOCIATE
,
5043 orinoco_unlock(priv
, &flags
);
5047 static int orinoco_ioctl_getretry(struct net_device
*dev
,
5048 struct iw_request_info
*info
,
5049 struct iw_param
*rrq
,
5052 struct orinoco_private
*priv
= netdev_priv(dev
);
5053 hermes_t
*hw
= &priv
->hw
;
5055 u16 short_limit
, long_limit
, lifetime
;
5056 unsigned long flags
;
5058 if (orinoco_lock(priv
, &flags
) != 0)
5061 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_SHORTRETRYLIMIT
,
5066 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_LONGRETRYLIMIT
,
5071 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_MAXTRANSMITLIFETIME
,
5076 rrq
->disabled
= 0; /* Can't be disabled */
5078 /* Note : by default, display the retry number */
5079 if ((rrq
->flags
& IW_RETRY_TYPE
) == IW_RETRY_LIFETIME
) {
5080 rrq
->flags
= IW_RETRY_LIFETIME
;
5081 rrq
->value
= lifetime
* 1000; /* ??? */
5083 /* By default, display the min number */
5084 if ((rrq
->flags
& IW_RETRY_LONG
)) {
5085 rrq
->flags
= IW_RETRY_LIMIT
| IW_RETRY_LONG
;
5086 rrq
->value
= long_limit
;
5088 rrq
->flags
= IW_RETRY_LIMIT
;
5089 rrq
->value
= short_limit
;
5090 if(short_limit
!= long_limit
)
5091 rrq
->flags
|= IW_RETRY_SHORT
;
5096 orinoco_unlock(priv
, &flags
);
5101 static int orinoco_ioctl_reset(struct net_device
*dev
,
5102 struct iw_request_info
*info
,
5106 struct orinoco_private
*priv
= netdev_priv(dev
);
5108 if (! capable(CAP_NET_ADMIN
))
5111 if (info
->cmd
== (SIOCIWFIRSTPRIV
+ 0x1)) {
5112 printk(KERN_DEBUG
"%s: Forcing reset!\n", dev
->name
);
5114 /* Firmware reset */
5115 orinoco_reset(&priv
->reset_work
);
5117 printk(KERN_DEBUG
"%s: Force scheduling reset!\n", dev
->name
);
5119 schedule_work(&priv
->reset_work
);
5125 static int orinoco_ioctl_setibssport(struct net_device
*dev
,
5126 struct iw_request_info
*info
,
5131 struct orinoco_private
*priv
= netdev_priv(dev
);
5132 int val
= *( (int *) extra
);
5133 unsigned long flags
;
5135 if (orinoco_lock(priv
, &flags
) != 0)
5138 priv
->ibss_port
= val
;
5140 /* Actually update the mode we are using */
5141 set_port_type(priv
);
5143 orinoco_unlock(priv
, &flags
);
5144 return -EINPROGRESS
; /* Call commit handler */
5147 static int orinoco_ioctl_getibssport(struct net_device
*dev
,
5148 struct iw_request_info
*info
,
5152 struct orinoco_private
*priv
= netdev_priv(dev
);
5153 int *val
= (int *) extra
;
5155 *val
= priv
->ibss_port
;
5159 static int orinoco_ioctl_setport3(struct net_device
*dev
,
5160 struct iw_request_info
*info
,
5164 struct orinoco_private
*priv
= netdev_priv(dev
);
5165 int val
= *( (int *) extra
);
5167 unsigned long flags
;
5169 if (orinoco_lock(priv
, &flags
) != 0)
5173 case 0: /* Try to do IEEE ad-hoc mode */
5174 if (! priv
->has_ibss
) {
5178 priv
->prefer_port3
= 0;
5182 case 1: /* Try to do Lucent proprietary ad-hoc mode */
5183 if (! priv
->has_port3
) {
5187 priv
->prefer_port3
= 1;
5195 /* Actually update the mode we are using */
5196 set_port_type(priv
);
5200 orinoco_unlock(priv
, &flags
);
5205 static int orinoco_ioctl_getport3(struct net_device
*dev
,
5206 struct iw_request_info
*info
,
5210 struct orinoco_private
*priv
= netdev_priv(dev
);
5211 int *val
= (int *) extra
;
5213 *val
= priv
->prefer_port3
;
5217 static int orinoco_ioctl_setpreamble(struct net_device
*dev
,
5218 struct iw_request_info
*info
,
5222 struct orinoco_private
*priv
= netdev_priv(dev
);
5223 unsigned long flags
;
5226 if (! priv
->has_preamble
)
5229 /* 802.11b has recently defined some short preamble.
5230 * Basically, the Phy header has been reduced in size.
5231 * This increase performance, especially at high rates
5232 * (the preamble is transmitted at 1Mb/s), unfortunately
5233 * this give compatibility troubles... - Jean II */
5234 val
= *( (int *) extra
);
5236 if (orinoco_lock(priv
, &flags
) != 0)
5244 orinoco_unlock(priv
, &flags
);
5246 return -EINPROGRESS
; /* Call commit handler */
5249 static int orinoco_ioctl_getpreamble(struct net_device
*dev
,
5250 struct iw_request_info
*info
,
5254 struct orinoco_private
*priv
= netdev_priv(dev
);
5255 int *val
= (int *) extra
;
5257 if (! priv
->has_preamble
)
5260 *val
= priv
->preamble
;
5264 /* ioctl interface to hermes_read_ltv()
5265 * To use with iwpriv, pass the RID as the token argument, e.g.
5266 * iwpriv get_rid [0xfc00]
5267 * At least Wireless Tools 25 is required to use iwpriv.
5268 * For Wireless Tools 25 and 26 append "dummy" are the end. */
5269 static int orinoco_ioctl_getrid(struct net_device
*dev
,
5270 struct iw_request_info
*info
,
5271 struct iw_point
*data
,
5274 struct orinoco_private
*priv
= netdev_priv(dev
);
5275 hermes_t
*hw
= &priv
->hw
;
5276 int rid
= data
->flags
;
5279 unsigned long flags
;
5281 /* It's a "get" function, but we don't want users to access the
5282 * WEP key and other raw firmware data */
5283 if (! capable(CAP_NET_ADMIN
))
5286 if (rid
< 0xfc00 || rid
> 0xffff)
5289 if (orinoco_lock(priv
, &flags
) != 0)
5292 err
= hermes_read_ltv(hw
, USER_BAP
, rid
, MAX_RID_LEN
, &length
,
5297 data
->length
= min_t(u16
, HERMES_RECLEN_TO_BYTES(length
),
5301 orinoco_unlock(priv
, &flags
);
5305 /* Trigger a scan (look for other cells in the vicinity) */
5306 static int orinoco_ioctl_setscan(struct net_device
*dev
,
5307 struct iw_request_info
*info
,
5308 struct iw_point
*srq
,
5311 struct orinoco_private
*priv
= netdev_priv(dev
);
5312 hermes_t
*hw
= &priv
->hw
;
5313 struct iw_scan_req
*si
= (struct iw_scan_req
*) extra
;
5315 unsigned long flags
;
5317 /* Note : you may have realised that, as this is a SET operation,
5318 * this is privileged and therefore a normal user can't
5320 * This is not an error, while the device perform scanning,
5321 * traffic doesn't flow, so it's a perfect DoS...
5324 if (orinoco_lock(priv
, &flags
) != 0)
5327 /* Scanning with port 0 disabled would fail */
5328 if (!netif_running(dev
)) {
5333 /* In monitor mode, the scan results are always empty.
5334 * Probe responses are passed to the driver as received
5335 * frames and could be processed in software. */
5336 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
5341 /* Note : because we don't lock out the irq handler, the way
5342 * we access scan variables in priv is critical.
5343 * o scan_inprogress : not touched by irq handler
5344 * o scan_mode : not touched by irq handler
5345 * Before modifying anything on those variables, please think hard !
5349 priv
->scan_mode
= srq
->flags
;
5351 /* Always trigger scanning, even if it's in progress.
5352 * This way, if the info frame get lost, we will recover somewhat
5353 * gracefully - Jean II */
5355 if (priv
->has_hostscan
) {
5356 switch (priv
->firmware_type
) {
5357 case FIRMWARE_TYPE_SYMBOL
:
5358 err
= hermes_write_wordrec(hw
, USER_BAP
,
5359 HERMES_RID_CNFHOSTSCAN_SYMBOL
,
5360 HERMES_HOSTSCAN_SYMBOL_ONCE
|
5361 HERMES_HOSTSCAN_SYMBOL_BCAST
);
5363 case FIRMWARE_TYPE_INTERSIL
: {
5366 req
[0] = cpu_to_le16(0x3fff); /* All channels */
5367 req
[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
5368 req
[2] = 0; /* Any ESSID */
5369 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
5370 HERMES_RID_CNFHOSTSCAN
, &req
);
5373 case FIRMWARE_TYPE_AGERE
:
5374 if (priv
->scan_mode
& IW_SCAN_THIS_ESSID
) {
5375 struct hermes_idstring idbuf
;
5376 size_t len
= min(sizeof(idbuf
.val
),
5377 (size_t) si
->essid_len
);
5378 idbuf
.len
= cpu_to_le16(len
);
5379 memcpy(idbuf
.val
, si
->essid
, len
);
5381 err
= hermes_write_ltv(hw
, USER_BAP
,
5382 HERMES_RID_CNFSCANSSID_AGERE
,
5383 HERMES_BYTES_TO_RECLEN(len
+ 2),
5386 err
= hermes_write_wordrec(hw
, USER_BAP
,
5387 HERMES_RID_CNFSCANSSID_AGERE
,
5392 if (priv
->has_ext_scan
) {
5393 /* Clear scan results at the start of
5394 * an extended scan */
5395 orinoco_clear_scan_results(priv
,
5396 msecs_to_jiffies(15000));
5398 /* TODO: Is this available on older firmware?
5399 * Can we use it to scan specific channels
5400 * for IW_SCAN_THIS_FREQ? */
5401 err
= hermes_write_wordrec(hw
, USER_BAP
,
5402 HERMES_RID_CNFSCANCHANNELS2GHZ
,
5407 err
= hermes_inquire(hw
,
5408 HERMES_INQ_CHANNELINFO
);
5410 err
= hermes_inquire(hw
, HERMES_INQ_SCAN
);
5414 err
= hermes_inquire(hw
, HERMES_INQ_SCAN
);
5416 /* One more client */
5418 priv
->scan_inprogress
= 1;
5421 orinoco_unlock(priv
, &flags
);
5425 #define MAX_CUSTOM_LEN 64
5427 /* Translate scan data returned from the card to a card independant
5428 * format that the Wireless Tools will understand - Jean II */
5429 static inline char *orinoco_translate_scan(struct net_device
*dev
,
5430 struct iw_request_info
*info
,
5433 union hermes_scan_info
*bss
,
5434 unsigned int last_scanned
)
5436 struct orinoco_private
*priv
= netdev_priv(dev
);
5439 struct iw_event iwe
; /* Temporary buffer */
5440 char custom
[MAX_CUSTOM_LEN
];
5442 memset(&iwe
, 0, sizeof(iwe
));
5444 /* First entry *MUST* be the AP MAC address */
5445 iwe
.cmd
= SIOCGIWAP
;
5446 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
5447 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->a
.bssid
, ETH_ALEN
);
5448 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5449 &iwe
, IW_EV_ADDR_LEN
);
5451 /* Other entries will be displayed in the order we give them */
5454 iwe
.u
.data
.length
= le16_to_cpu(bss
->a
.essid_len
);
5455 if (iwe
.u
.data
.length
> 32)
5456 iwe
.u
.data
.length
= 32;
5457 iwe
.cmd
= SIOCGIWESSID
;
5458 iwe
.u
.data
.flags
= 1;
5459 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5460 &iwe
, bss
->a
.essid
);
5463 iwe
.cmd
= SIOCGIWMODE
;
5464 capabilities
= le16_to_cpu(bss
->a
.capabilities
);
5465 if (capabilities
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)) {
5466 if (capabilities
& WLAN_CAPABILITY_ESS
)
5467 iwe
.u
.mode
= IW_MODE_MASTER
;
5469 iwe
.u
.mode
= IW_MODE_ADHOC
;
5470 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5471 &iwe
, IW_EV_UINT_LEN
);
5474 channel
= bss
->s
.channel
;
5475 if ((channel
>= 1) && (channel
<= NUM_CHANNELS
)) {
5476 /* Add channel and frequency */
5477 iwe
.cmd
= SIOCGIWFREQ
;
5478 iwe
.u
.freq
.m
= channel
;
5480 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5481 &iwe
, IW_EV_FREQ_LEN
);
5483 iwe
.u
.freq
.m
= channel_frequency
[channel
-1] * 100000;
5485 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5486 &iwe
, IW_EV_FREQ_LEN
);
5489 /* Add quality statistics. level and noise in dB. No link quality */
5491 iwe
.u
.qual
.updated
= IW_QUAL_DBM
| IW_QUAL_QUAL_INVALID
;
5492 iwe
.u
.qual
.level
= (__u8
) le16_to_cpu(bss
->a
.level
) - 0x95;
5493 iwe
.u
.qual
.noise
= (__u8
) le16_to_cpu(bss
->a
.noise
) - 0x95;
5494 /* Wireless tools prior to 27.pre22 will show link quality
5495 * anyway, so we provide a reasonable value. */
5496 if (iwe
.u
.qual
.level
> iwe
.u
.qual
.noise
)
5497 iwe
.u
.qual
.qual
= iwe
.u
.qual
.level
- iwe
.u
.qual
.noise
;
5499 iwe
.u
.qual
.qual
= 0;
5500 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5501 &iwe
, IW_EV_QUAL_LEN
);
5503 /* Add encryption capability */
5504 iwe
.cmd
= SIOCGIWENCODE
;
5505 if (capabilities
& WLAN_CAPABILITY_PRIVACY
)
5506 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
5508 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
5509 iwe
.u
.data
.length
= 0;
5510 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5513 /* Bit rate is not available in Lucent/Agere firmwares */
5514 if (priv
->firmware_type
!= FIRMWARE_TYPE_AGERE
) {
5515 char *current_val
= current_ev
+ iwe_stream_lcp_len(info
);
5519 if (priv
->firmware_type
== FIRMWARE_TYPE_SYMBOL
)
5524 iwe
.cmd
= SIOCGIWRATE
;
5525 /* Those two flags are ignored... */
5526 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
5528 for (i
= 0; i
< 10; i
+= step
) {
5529 /* NULL terminated */
5530 if (bss
->p
.rates
[i
] == 0x0)
5532 /* Bit rate given in 500 kb/s units (+ 0x80) */
5533 iwe
.u
.bitrate
.value
=
5534 ((bss
->p
.rates
[i
] & 0x7f) * 500000);
5535 current_val
= iwe_stream_add_value(info
, current_ev
,
5540 /* Check if we added any event */
5541 if ((current_val
- current_ev
) > iwe_stream_lcp_len(info
))
5542 current_ev
= current_val
;
5545 /* Beacon interval */
5546 iwe
.cmd
= IWEVCUSTOM
;
5547 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5549 le16_to_cpu(bss
->a
.beacon_interv
));
5550 if (iwe
.u
.data
.length
)
5551 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5555 iwe
.cmd
= IWEVCUSTOM
;
5556 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5559 if (iwe
.u
.data
.length
)
5560 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5563 /* Add EXTRA: Age to display seconds since last beacon/probe response
5564 * for given network. */
5565 iwe
.cmd
= IWEVCUSTOM
;
5566 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5567 " Last beacon: %dms ago",
5568 jiffies_to_msecs(jiffies
- last_scanned
));
5569 if (iwe
.u
.data
.length
)
5570 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5576 static inline char *orinoco_translate_ext_scan(struct net_device
*dev
,
5577 struct iw_request_info
*info
,
5580 struct agere_ext_scan_info
*bss
,
5581 unsigned int last_scanned
)
5585 struct iw_event iwe
; /* Temporary buffer */
5586 char custom
[MAX_CUSTOM_LEN
];
5589 memset(&iwe
, 0, sizeof(iwe
));
5591 /* First entry *MUST* be the AP MAC address */
5592 iwe
.cmd
= SIOCGIWAP
;
5593 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
5594 memcpy(iwe
.u
.ap_addr
.sa_data
, bss
->bssid
, ETH_ALEN
);
5595 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5596 &iwe
, IW_EV_ADDR_LEN
);
5598 /* Other entries will be displayed in the order we give them */
5602 iwe
.u
.data
.length
= ie
[1];
5603 if (iwe
.u
.data
.length
) {
5604 if (iwe
.u
.data
.length
> 32)
5605 iwe
.u
.data
.length
= 32;
5606 iwe
.cmd
= SIOCGIWESSID
;
5607 iwe
.u
.data
.flags
= 1;
5608 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5613 capabilities
= le16_to_cpu(bss
->capabilities
);
5614 if (capabilities
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)) {
5615 iwe
.cmd
= SIOCGIWMODE
;
5616 if (capabilities
& WLAN_CAPABILITY_ESS
)
5617 iwe
.u
.mode
= IW_MODE_MASTER
;
5619 iwe
.u
.mode
= IW_MODE_ADHOC
;
5620 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5621 &iwe
, IW_EV_UINT_LEN
);
5624 ie
= orinoco_get_ie(bss
->data
, sizeof(bss
->data
), MFIE_TYPE_DS_SET
);
5625 channel
= ie
? ie
[2] : 0;
5626 if ((channel
>= 1) && (channel
<= NUM_CHANNELS
)) {
5627 /* Add channel and frequency */
5628 iwe
.cmd
= SIOCGIWFREQ
;
5629 iwe
.u
.freq
.m
= channel
;
5631 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5632 &iwe
, IW_EV_FREQ_LEN
);
5634 iwe
.u
.freq
.m
= channel_frequency
[channel
-1] * 100000;
5636 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5637 &iwe
, IW_EV_FREQ_LEN
);
5640 /* Add quality statistics. level and noise in dB. No link quality */
5642 iwe
.u
.qual
.updated
= IW_QUAL_DBM
| IW_QUAL_QUAL_INVALID
;
5643 iwe
.u
.qual
.level
= bss
->level
- 0x95;
5644 iwe
.u
.qual
.noise
= bss
->noise
- 0x95;
5645 /* Wireless tools prior to 27.pre22 will show link quality
5646 * anyway, so we provide a reasonable value. */
5647 if (iwe
.u
.qual
.level
> iwe
.u
.qual
.noise
)
5648 iwe
.u
.qual
.qual
= iwe
.u
.qual
.level
- iwe
.u
.qual
.noise
;
5650 iwe
.u
.qual
.qual
= 0;
5651 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
5652 &iwe
, IW_EV_QUAL_LEN
);
5654 /* Add encryption capability */
5655 iwe
.cmd
= SIOCGIWENCODE
;
5656 if (capabilities
& WLAN_CAPABILITY_PRIVACY
)
5657 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
5659 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
5660 iwe
.u
.data
.length
= 0;
5661 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5665 ie
= orinoco_get_wpa_ie(bss
->data
, sizeof(bss
->data
));
5667 iwe
.cmd
= IWEVGENIE
;
5668 iwe
.u
.data
.length
= ie
[1] + 2;
5669 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5674 ie
= orinoco_get_ie(bss
->data
, sizeof(bss
->data
), MFIE_TYPE_RSN
);
5676 iwe
.cmd
= IWEVGENIE
;
5677 iwe
.u
.data
.length
= ie
[1] + 2;
5678 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5682 ie
= orinoco_get_ie(bss
->data
, sizeof(bss
->data
), MFIE_TYPE_RATES
);
5684 char *p
= current_ev
+ iwe_stream_lcp_len(info
);
5687 iwe
.cmd
= SIOCGIWRATE
;
5688 /* Those two flags are ignored... */
5689 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
5691 for (i
= 2; i
< (ie
[1] + 2); i
++) {
5692 iwe
.u
.bitrate
.value
= ((ie
[i
] & 0x7F) * 500000);
5693 p
= iwe_stream_add_value(info
, current_ev
, p
, end_buf
,
5694 &iwe
, IW_EV_PARAM_LEN
);
5696 /* Check if we added any event */
5697 if (p
> (current_ev
+ iwe_stream_lcp_len(info
)))
5702 iwe
.cmd
= IWEVCUSTOM
;
5704 snprintf(custom
, MAX_CUSTOM_LEN
, "tsf=%016llx",
5705 (unsigned long long) le64_to_cpu(bss
->timestamp
));
5706 if (iwe
.u
.data
.length
)
5707 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5710 /* Beacon interval */
5711 iwe
.cmd
= IWEVCUSTOM
;
5712 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5714 le16_to_cpu(bss
->beacon_interval
));
5715 if (iwe
.u
.data
.length
)
5716 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5720 iwe
.cmd
= IWEVCUSTOM
;
5721 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5724 if (iwe
.u
.data
.length
)
5725 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5728 /* Add EXTRA: Age to display seconds since last beacon/probe response
5729 * for given network. */
5730 iwe
.cmd
= IWEVCUSTOM
;
5731 iwe
.u
.data
.length
= snprintf(custom
, MAX_CUSTOM_LEN
,
5732 " Last beacon: %dms ago",
5733 jiffies_to_msecs(jiffies
- last_scanned
));
5734 if (iwe
.u
.data
.length
)
5735 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
5741 /* Return results of a scan */
5742 static int orinoco_ioctl_getscan(struct net_device
*dev
,
5743 struct iw_request_info
*info
,
5744 struct iw_point
*srq
,
5747 struct orinoco_private
*priv
= netdev_priv(dev
);
5749 unsigned long flags
;
5750 char *current_ev
= extra
;
5752 if (orinoco_lock(priv
, &flags
) != 0)
5755 if (priv
->scan_inprogress
) {
5756 /* Important note : we don't want to block the caller
5757 * until results are ready for various reasons.
5758 * First, managing wait queues is complex and racy.
5759 * Second, we grab some rtnetlink lock before comming
5760 * here (in dev_ioctl()).
5761 * Third, we generate an Wireless Event, so the
5762 * caller can wait itself on that - Jean II */
5767 if (priv
->has_ext_scan
) {
5768 struct xbss_element
*bss
;
5770 list_for_each_entry(bss
, &priv
->bss_list
, list
) {
5771 /* Translate this entry to WE format */
5773 orinoco_translate_ext_scan(dev
, info
,
5775 extra
+ srq
->length
,
5779 /* Check if there is space for one more entry */
5780 if ((extra
+ srq
->length
- current_ev
)
5781 <= IW_EV_ADDR_LEN
) {
5782 /* Ask user space to try again with a
5790 struct bss_element
*bss
;
5792 list_for_each_entry(bss
, &priv
->bss_list
, list
) {
5793 /* Translate this entry to WE format */
5794 current_ev
= orinoco_translate_scan(dev
, info
,
5796 extra
+ srq
->length
,
5800 /* Check if there is space for one more entry */
5801 if ((extra
+ srq
->length
- current_ev
)
5802 <= IW_EV_ADDR_LEN
) {
5803 /* Ask user space to try again with a
5811 srq
->length
= (current_ev
- extra
);
5812 srq
->flags
= (__u16
) priv
->scan_mode
;
5815 orinoco_unlock(priv
, &flags
);
5819 /* Commit handler, called after set operations */
5820 static int orinoco_ioctl_commit(struct net_device
*dev
,
5821 struct iw_request_info
*info
,
5825 struct orinoco_private
*priv
= netdev_priv(dev
);
5826 struct hermes
*hw
= &priv
->hw
;
5827 unsigned long flags
;
5833 if (priv
->broken_disableport
) {
5834 orinoco_reset(&priv
->reset_work
);
5838 if (orinoco_lock(priv
, &flags
) != 0)
5841 err
= hermes_disable_port(hw
, 0);
5843 printk(KERN_WARNING
"%s: Unable to disable port "
5844 "while reconfiguring card\n", dev
->name
);
5845 priv
->broken_disableport
= 1;
5849 err
= __orinoco_program_rids(dev
);
5851 printk(KERN_WARNING
"%s: Unable to reconfigure card\n",
5856 err
= hermes_enable_port(hw
, 0);
5858 printk(KERN_WARNING
"%s: Unable to enable port while reconfiguring card\n",
5865 printk(KERN_WARNING
"%s: Resetting instead...\n", dev
->name
);
5866 schedule_work(&priv
->reset_work
);
5870 orinoco_unlock(priv
, &flags
);
5874 static const struct iw_priv_args orinoco_privtab
[] = {
5875 { SIOCIWFIRSTPRIV
+ 0x0, 0, 0, "force_reset" },
5876 { SIOCIWFIRSTPRIV
+ 0x1, 0, 0, "card_reset" },
5877 { SIOCIWFIRSTPRIV
+ 0x2, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5879 { SIOCIWFIRSTPRIV
+ 0x3, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5881 { SIOCIWFIRSTPRIV
+ 0x4, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5882 0, "set_preamble" },
5883 { SIOCIWFIRSTPRIV
+ 0x5, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5885 { SIOCIWFIRSTPRIV
+ 0x6, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5886 0, "set_ibssport" },
5887 { SIOCIWFIRSTPRIV
+ 0x7, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
5889 { SIOCIWFIRSTPRIV
+ 0x9, 0, IW_PRIV_TYPE_BYTE
| MAX_RID_LEN
,
5895 * Structures to export the Wireless Handlers
5898 #define STD_IW_HANDLER(id, func) \
5899 [IW_IOCTL_IDX(id)] = (iw_handler) func
5900 static const iw_handler orinoco_handler
[] = {
5901 STD_IW_HANDLER(SIOCSIWCOMMIT
, orinoco_ioctl_commit
),
5902 STD_IW_HANDLER(SIOCGIWNAME
, orinoco_ioctl_getname
),
5903 STD_IW_HANDLER(SIOCSIWFREQ
, orinoco_ioctl_setfreq
),
5904 STD_IW_HANDLER(SIOCGIWFREQ
, orinoco_ioctl_getfreq
),
5905 STD_IW_HANDLER(SIOCSIWMODE
, orinoco_ioctl_setmode
),
5906 STD_IW_HANDLER(SIOCGIWMODE
, orinoco_ioctl_getmode
),
5907 STD_IW_HANDLER(SIOCSIWSENS
, orinoco_ioctl_setsens
),
5908 STD_IW_HANDLER(SIOCGIWSENS
, orinoco_ioctl_getsens
),
5909 STD_IW_HANDLER(SIOCGIWRANGE
, orinoco_ioctl_getiwrange
),
5910 STD_IW_HANDLER(SIOCSIWSPY
, iw_handler_set_spy
),
5911 STD_IW_HANDLER(SIOCGIWSPY
, iw_handler_get_spy
),
5912 STD_IW_HANDLER(SIOCSIWTHRSPY
, iw_handler_set_thrspy
),
5913 STD_IW_HANDLER(SIOCGIWTHRSPY
, iw_handler_get_thrspy
),
5914 STD_IW_HANDLER(SIOCSIWAP
, orinoco_ioctl_setwap
),
5915 STD_IW_HANDLER(SIOCGIWAP
, orinoco_ioctl_getwap
),
5916 STD_IW_HANDLER(SIOCSIWSCAN
, orinoco_ioctl_setscan
),
5917 STD_IW_HANDLER(SIOCGIWSCAN
, orinoco_ioctl_getscan
),
5918 STD_IW_HANDLER(SIOCSIWESSID
, orinoco_ioctl_setessid
),
5919 STD_IW_HANDLER(SIOCGIWESSID
, orinoco_ioctl_getessid
),
5920 STD_IW_HANDLER(SIOCSIWNICKN
, orinoco_ioctl_setnick
),
5921 STD_IW_HANDLER(SIOCGIWNICKN
, orinoco_ioctl_getnick
),
5922 STD_IW_HANDLER(SIOCSIWRATE
, orinoco_ioctl_setrate
),
5923 STD_IW_HANDLER(SIOCGIWRATE
, orinoco_ioctl_getrate
),
5924 STD_IW_HANDLER(SIOCSIWRTS
, orinoco_ioctl_setrts
),
5925 STD_IW_HANDLER(SIOCGIWRTS
, orinoco_ioctl_getrts
),
5926 STD_IW_HANDLER(SIOCSIWFRAG
, orinoco_ioctl_setfrag
),
5927 STD_IW_HANDLER(SIOCGIWFRAG
, orinoco_ioctl_getfrag
),
5928 STD_IW_HANDLER(SIOCGIWRETRY
, orinoco_ioctl_getretry
),
5929 STD_IW_HANDLER(SIOCSIWENCODE
, orinoco_ioctl_setiwencode
),
5930 STD_IW_HANDLER(SIOCGIWENCODE
, orinoco_ioctl_getiwencode
),
5931 STD_IW_HANDLER(SIOCSIWPOWER
, orinoco_ioctl_setpower
),
5932 STD_IW_HANDLER(SIOCGIWPOWER
, orinoco_ioctl_getpower
),
5933 STD_IW_HANDLER(SIOCSIWGENIE
, orinoco_ioctl_set_genie
),
5934 STD_IW_HANDLER(SIOCGIWGENIE
, orinoco_ioctl_get_genie
),
5935 STD_IW_HANDLER(SIOCSIWMLME
, orinoco_ioctl_set_mlme
),
5936 STD_IW_HANDLER(SIOCSIWAUTH
, orinoco_ioctl_set_auth
),
5937 STD_IW_HANDLER(SIOCGIWAUTH
, orinoco_ioctl_get_auth
),
5938 STD_IW_HANDLER(SIOCSIWENCODEEXT
, orinoco_ioctl_set_encodeext
),
5939 STD_IW_HANDLER(SIOCGIWENCODEEXT
, orinoco_ioctl_get_encodeext
),
5944 Added typecasting since we no longer use iwreq_data -- Moustafa
5946 static const iw_handler orinoco_private_handler
[] = {
5947 [0] = (iw_handler
) orinoco_ioctl_reset
,
5948 [1] = (iw_handler
) orinoco_ioctl_reset
,
5949 [2] = (iw_handler
) orinoco_ioctl_setport3
,
5950 [3] = (iw_handler
) orinoco_ioctl_getport3
,
5951 [4] = (iw_handler
) orinoco_ioctl_setpreamble
,
5952 [5] = (iw_handler
) orinoco_ioctl_getpreamble
,
5953 [6] = (iw_handler
) orinoco_ioctl_setibssport
,
5954 [7] = (iw_handler
) orinoco_ioctl_getibssport
,
5955 [9] = (iw_handler
) orinoco_ioctl_getrid
,
5958 static const struct iw_handler_def orinoco_handler_def
= {
5959 .num_standard
= ARRAY_SIZE(orinoco_handler
),
5960 .num_private
= ARRAY_SIZE(orinoco_private_handler
),
5961 .num_private_args
= ARRAY_SIZE(orinoco_privtab
),
5962 .standard
= orinoco_handler
,
5963 .private = orinoco_private_handler
,
5964 .private_args
= orinoco_privtab
,
5965 .get_wireless_stats
= orinoco_get_wireless_stats
,
5968 static void orinoco_get_drvinfo(struct net_device
*dev
,
5969 struct ethtool_drvinfo
*info
)
5971 struct orinoco_private
*priv
= netdev_priv(dev
);
5973 strncpy(info
->driver
, DRIVER_NAME
, sizeof(info
->driver
) - 1);
5974 strncpy(info
->version
, DRIVER_VERSION
, sizeof(info
->version
) - 1);
5975 strncpy(info
->fw_version
, priv
->fw_name
, sizeof(info
->fw_version
) - 1);
5976 if (dev
->dev
.parent
)
5977 strncpy(info
->bus_info
, dev
->dev
.parent
->bus_id
,
5978 sizeof(info
->bus_info
) - 1);
5980 snprintf(info
->bus_info
, sizeof(info
->bus_info
) - 1,
5981 "PCMCIA %p", priv
->hw
.iobase
);
5984 static const struct ethtool_ops orinoco_ethtool_ops
= {
5985 .get_drvinfo
= orinoco_get_drvinfo
,
5986 .get_link
= ethtool_op_get_link
,
5989 /********************************************************************/
5990 /* Module initialization */
5991 /********************************************************************/
5993 EXPORT_SYMBOL(alloc_orinocodev
);
5994 EXPORT_SYMBOL(free_orinocodev
);
5996 EXPORT_SYMBOL(__orinoco_up
);
5997 EXPORT_SYMBOL(__orinoco_down
);
5998 EXPORT_SYMBOL(orinoco_reinit_firmware
);
6000 EXPORT_SYMBOL(orinoco_interrupt
);
6002 /* Can't be declared "const" or the whole __initdata section will
6004 static char version
[] __initdata
= DRIVER_NAME
" " DRIVER_VERSION
6005 " (David Gibson <hermes@gibson.dropbear.id.au>, "
6006 "Pavel Roskin <proski@gnu.org>, et al)";
6008 static int __init
init_orinoco(void)
6010 printk(KERN_DEBUG
"%s\n", version
);
6014 static void __exit
exit_orinoco(void)
6018 module_init(init_orinoco
);
6019 module_exit(exit_orinoco
);