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/netdevice.h>
83 #include <linux/etherdevice.h>
84 #include <linux/ethtool.h>
85 #include <linux/firmware.h>
86 #include <linux/if_arp.h>
87 #include <linux/wireless.h>
88 #include <net/iw_handler.h>
89 #include <net/ieee80211.h>
91 #include "hermes_rid.h"
92 #include "hermes_dld.h"
95 /********************************************************************/
96 /* Module information */
97 /********************************************************************/
99 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
100 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
101 MODULE_LICENSE("Dual MPL/GPL");
103 /* Level of debugging. Used in the macros in orinoco.h */
105 int orinoco_debug = ORINOCO_DEBUG;
106 module_param(orinoco_debug, int, 0644);
107 MODULE_PARM_DESC(orinoco_debug, "Debug level");
108 EXPORT_SYMBOL(orinoco_debug);
111 static int suppress_linkstatus; /* = 0 */
112 module_param(suppress_linkstatus, bool, 0644);
113 MODULE_PARM_DESC(suppress_linkstatus, "Don't log link status changes");
114 static int ignore_disconnect; /* = 0 */
115 module_param(ignore_disconnect, int, 0644);
116 MODULE_PARM_DESC(ignore_disconnect, "Don't report lost link to the network layer");
118 static int force_monitor; /* = 0 */
119 module_param(force_monitor, int, 0644);
120 MODULE_PARM_DESC(force_monitor, "Allow monitor mode for all firmware versions");
122 /********************************************************************/
123 /* Compile time configuration and compatibility stuff */
124 /********************************************************************/
126 /* We do this this way to avoid ifdefs in the actual code */
128 #define SPY_NUMBER(priv) (priv->spy_data.spy_number)
130 #define SPY_NUMBER(priv) 0
131 #endif /* WIRELESS_SPY */
133 /********************************************************************/
134 /* Internal constants */
135 /********************************************************************/
137 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
138 static const u8 encaps_hdr[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
139 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
141 #define ORINOCO_MIN_MTU 256
142 #define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
144 #define SYMBOL_MAX_VER_LEN (14)
147 #define MAX_IRQLOOPS_PER_IRQ 10
148 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
149 * how many events the
151 * legitimately generate */
152 #define SMALL_KEY_SIZE 5
153 #define LARGE_KEY_SIZE 13
154 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
156 #define DUMMY_FID 0xFFFF
158 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
159 HERMES_MAX_MULTICAST : 0)*/
160 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
162 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
163 | HERMES_EV_TX | HERMES_EV_TXEXC \
164 | HERMES_EV_WTERR | HERMES_EV_INFO \
165 | HERMES_EV_INFDROP )
167 #define MAX_RID_LEN 1024
169 static const struct iw_handler_def orinoco_handler_def;
170 static const struct ethtool_ops orinoco_ethtool_ops;
172 /********************************************************************/
174 /********************************************************************/
176 /* The frequency of each channel in MHz */
177 static const long channel_frequency[] = {
178 2412, 2417, 2422, 2427, 2432, 2437, 2442,
179 2447, 2452, 2457, 2462, 2467, 2472, 2484
181 #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
183 /* This tables gives the actual meanings of the bitrate IDs returned
184 * by the firmware. */
186 int bitrate; /* in 100s of kilobits */
188 u16 agere_txratectrl;
189 u16 intersil_txratectrl;
190 } bitrate_table[] = {
191 {110, 1, 3, 15}, /* Entry 0 is the default */
200 #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
202 /********************************************************************/
204 /********************************************************************/
206 /* Beginning of the Tx descriptor, used in TxExc handling */
207 struct hermes_txexc_data {
208 struct hermes_tx_descriptor desc;
212 } __attribute__ ((packed));
214 /* Rx frame header except compatibility 802.3 header */
215 struct hermes_rx_descriptor {
236 } __attribute__ ((packed));
238 /********************************************************************/
239 /* Function prototypes */
240 /********************************************************************/
242 static int __orinoco_program_rids(struct net_device *dev);
243 static void __orinoco_set_multicast_list(struct net_device *dev);
245 /********************************************************************/
246 /* Internal helper functions */
247 /********************************************************************/
249 static inline void set_port_type(struct orinoco_private *priv)
251 switch (priv->iw_mode) {
254 priv->createibss = 0;
257 if (priv->prefer_port3) {
259 priv->createibss = 0;
261 priv->port_type = priv->ibss_port;
262 priv->createibss = 1;
265 case IW_MODE_MONITOR:
267 priv->createibss = 0;
270 printk(KERN_ERR "%s: Invalid priv->iw_mode in set_port_type()\n",
275 #define ORINOCO_MAX_BSS_COUNT 64
276 static int orinoco_bss_data_allocate(struct orinoco_private *priv)
278 if (priv->bss_xbss_data)
281 if (priv->has_ext_scan)
282 priv->bss_xbss_data = kzalloc(ORINOCO_MAX_BSS_COUNT *
283 sizeof(struct xbss_element),
286 priv->bss_xbss_data = kzalloc(ORINOCO_MAX_BSS_COUNT *
287 sizeof(struct bss_element),
290 if (!priv->bss_xbss_data) {
291 printk(KERN_WARNING "Out of memory allocating beacons");
297 static void orinoco_bss_data_free(struct orinoco_private *priv)
299 kfree(priv->bss_xbss_data);
300 priv->bss_xbss_data = NULL;
303 #define PRIV_BSS ((struct bss_element *)priv->bss_xbss_data)
304 #define PRIV_XBSS ((struct xbss_element *)priv->bss_xbss_data)
305 static void orinoco_bss_data_init(struct orinoco_private *priv)
309 INIT_LIST_HEAD(&priv->bss_free_list);
310 INIT_LIST_HEAD(&priv->bss_list);
311 if (priv->has_ext_scan)
312 for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++)
313 list_add_tail(&(PRIV_XBSS[i].list),
314 &priv->bss_free_list);
316 for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++)
317 list_add_tail(&(PRIV_BSS[i].list),
318 &priv->bss_free_list);
322 static inline u8 *orinoco_get_ie(u8 *data, size_t len,
323 enum ieee80211_mfie eid)
326 while ((p + 2) < (data + len)) {
334 #define WPA_OUI_TYPE "\x00\x50\xF2\x01"
335 #define WPA_SELECTOR_LEN 4
336 static inline u8 *orinoco_get_wpa_ie(u8 *data, size_t len)
339 while ((p + 2 + WPA_SELECTOR_LEN) < (data + len)) {
340 if ((p[0] == MFIE_TYPE_GENERIC) &&
341 (memcmp(&p[2], WPA_OUI_TYPE, WPA_SELECTOR_LEN) == 0))
349 /********************************************************************/
350 /* Download functionality */
351 /********************************************************************/
361 const static struct fw_info orinoco_fw[] = {
362 { "", "agere_sta_fw.bin", "agere_ap_fw.bin", 0x00390000, 1000 },
363 { "", "prism_sta_fw.bin", "prism_ap_fw.bin", 0, 1024 },
364 { "symbol_sp24t_prim_fw", "symbol_sp24t_sec_fw", "", 0x00003100, 0x100 }
367 /* Structure used to access fields in FW
368 * Make sure LE decoding macros are used
370 struct orinoco_fw_header {
371 char hdr_vers[6]; /* ASCII string for header version */
372 __le16 headersize; /* Total length of header */
373 __le32 entry_point; /* NIC entry point */
374 __le32 blocks; /* Number of blocks to program */
375 __le32 block_offset; /* Offset of block data from eof header */
376 __le32 pdr_offset; /* Offset to PDR data from eof header */
377 __le32 pri_offset; /* Offset to primary plug data */
378 __le32 compat_offset; /* Offset to compatibility data*/
379 char signature[0]; /* FW signature length headersize-20 */
380 } __attribute__ ((packed));
382 /* Download either STA or AP firmware into the card. */
384 orinoco_dl_firmware(struct orinoco_private *priv,
385 const struct fw_info *fw,
388 /* Plug Data Area (PDA) */
389 __le16 pda[512] = { 0 };
391 hermes_t *hw = &priv->hw;
392 const struct firmware *fw_entry;
393 const struct orinoco_fw_header *hdr;
394 const unsigned char *first_block;
395 const unsigned char *end;
396 const char *firmware;
397 struct net_device *dev = priv->ndev;
401 firmware = fw->ap_fw;
403 firmware = fw->sta_fw;
405 printk(KERN_DEBUG "%s: Attempting to download firmware %s\n",
406 dev->name, firmware);
408 /* Read current plug data */
409 err = hermes_read_pda(hw, pda, fw->pda_addr,
410 min_t(u16, fw->pda_size, sizeof(pda)), 0);
411 printk(KERN_DEBUG "%s: Read PDA returned %d\n", dev->name, err);
415 err = request_firmware(&fw_entry, firmware, priv->dev);
417 printk(KERN_ERR "%s: Cannot find firmware %s\n",
418 dev->name, firmware);
422 hdr = (const struct orinoco_fw_header *) fw_entry->data;
424 /* Enable aux port to allow programming */
425 err = hermesi_program_init(hw, le32_to_cpu(hdr->entry_point));
426 printk(KERN_DEBUG "%s: Program init returned %d\n", dev->name, err);
431 first_block = (fw_entry->data +
432 le16_to_cpu(hdr->headersize) +
433 le32_to_cpu(hdr->block_offset));
434 end = fw_entry->data + fw_entry->size;
436 err = hermes_program(hw, first_block, end);
437 printk(KERN_DEBUG "%s: Program returned %d\n", dev->name, err);
441 /* Update production data */
442 first_block = (fw_entry->data +
443 le16_to_cpu(hdr->headersize) +
444 le32_to_cpu(hdr->pdr_offset));
446 err = hermes_apply_pda_with_defaults(hw, first_block, pda);
447 printk(KERN_DEBUG "%s: Apply PDA returned %d\n", dev->name, err);
451 /* Tell card we've finished */
452 err = hermesi_program_end(hw);
453 printk(KERN_DEBUG "%s: Program end returned %d\n", dev->name, err);
457 /* Check if we're running */
458 printk(KERN_DEBUG "%s: hermes_present returned %d\n",
459 dev->name, hermes_present(hw));
462 release_firmware(fw_entry);
467 #define TEXT_END 0x1A /* End of text header */
470 * Process a firmware image - stop the card, load the firmware, reset
471 * the card and make sure it responds. For the secondary firmware take
472 * care of the PDA - read it and then write it on top of the firmware.
475 symbol_dl_image(struct orinoco_private *priv, const struct fw_info *fw,
476 const unsigned char *image, const unsigned char *end,
479 hermes_t *hw = &priv->hw;
481 const unsigned char *ptr;
482 const unsigned char *first_block;
484 /* Plug Data Area (PDA) */
487 /* Binary block begins after the 0x1A marker */
489 while (*ptr++ != TEXT_END);
492 /* Read the PDA from EEPROM */
494 ret = hermes_read_pda(hw, pda, fw->pda_addr, sizeof(pda), 1);
499 /* Stop the firmware, so that it can be safely rewritten */
501 ret = priv->stop_fw(priv, 1);
506 /* Program the adapter with new firmware */
507 ret = hermes_program(hw, first_block, end);
511 /* Write the PDA to the adapter */
513 size_t len = hermes_blocks_length(first_block);
514 ptr = first_block + len;
515 ret = hermes_apply_pda(hw, ptr, pda);
520 /* Run the firmware */
522 ret = priv->stop_fw(priv, 0);
527 /* Reset hermes chip and make sure it responds */
528 ret = hermes_init(hw);
530 /* hermes_reset() should return 0 with the secondary firmware */
531 if (secondary && ret != 0)
534 /* And this should work with any firmware */
535 if (!hermes_present(hw))
543 * Download the firmware into the card, this also does a PCMCIA soft
544 * reset on the card, to make sure it's in a sane state.
547 symbol_dl_firmware(struct orinoco_private *priv,
548 const struct fw_info *fw)
550 struct net_device *dev = priv->ndev;
552 const struct firmware *fw_entry;
554 if (request_firmware(&fw_entry, fw->pri_fw,
556 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
557 dev->name, fw->pri_fw);
561 /* Load primary firmware */
562 ret = symbol_dl_image(priv, fw, fw_entry->data,
563 fw_entry->data + fw_entry->size, 0);
564 release_firmware(fw_entry);
566 printk(KERN_ERR "%s: Primary firmware download failed\n",
571 if (request_firmware(&fw_entry, fw->sta_fw,
573 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
574 dev->name, fw->sta_fw);
578 /* Load secondary firmware */
579 ret = symbol_dl_image(priv, fw, fw_entry->data,
580 fw_entry->data + fw_entry->size, 1);
581 release_firmware(fw_entry);
583 printk(KERN_ERR "%s: Secondary firmware download failed\n",
590 static int orinoco_download(struct orinoco_private *priv)
593 /* Reload firmware */
594 switch (priv->firmware_type) {
595 case FIRMWARE_TYPE_AGERE:
596 /* case FIRMWARE_TYPE_INTERSIL: */
597 err = orinoco_dl_firmware(priv,
598 &orinoco_fw[priv->firmware_type], 0);
601 case FIRMWARE_TYPE_SYMBOL:
602 err = symbol_dl_firmware(priv,
603 &orinoco_fw[priv->firmware_type]);
605 case FIRMWARE_TYPE_INTERSIL:
608 /* TODO: if we fail we probably need to reinitialise
614 /********************************************************************/
616 /********************************************************************/
618 static int orinoco_open(struct net_device *dev)
620 struct orinoco_private *priv = netdev_priv(dev);
624 if (orinoco_lock(priv, &flags) != 0)
627 err = __orinoco_up(dev);
632 orinoco_unlock(priv, &flags);
637 static int orinoco_stop(struct net_device *dev)
639 struct orinoco_private *priv = netdev_priv(dev);
642 /* We mustn't use orinoco_lock() here, because we need to be
643 able to close the interface even if hw_unavailable is set
644 (e.g. as we're released after a PC Card removal) */
645 spin_lock_irq(&priv->lock);
649 err = __orinoco_down(dev);
651 spin_unlock_irq(&priv->lock);
656 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
658 struct orinoco_private *priv = netdev_priv(dev);
663 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
665 struct orinoco_private *priv = netdev_priv(dev);
666 hermes_t *hw = &priv->hw;
667 struct iw_statistics *wstats = &priv->wstats;
671 if (! netif_device_present(dev)) {
672 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
674 return NULL; /* FIXME: Can we do better than this? */
677 /* If busy, return the old stats. Returning NULL may cause
678 * the interface to disappear from /proc/net/wireless */
679 if (orinoco_lock(priv, &flags) != 0)
682 /* We can't really wait for the tallies inquiry command to
683 * complete, so we just use the previous results and trigger
684 * a new tallies inquiry command for next time - Jean II */
685 /* FIXME: Really we should wait for the inquiry to come back -
686 * as it is the stats we give don't make a whole lot of sense.
687 * Unfortunately, it's not clear how to do that within the
688 * wireless extensions framework: I think we're in user
689 * context, but a lock seems to be held by the time we get in
690 * here so we're not safe to sleep here. */
691 hermes_inquire(hw, HERMES_INQ_TALLIES);
693 if (priv->iw_mode == IW_MODE_ADHOC) {
694 memset(&wstats->qual, 0, sizeof(wstats->qual));
695 /* If a spy address is defined, we report stats of the
696 * first spy address - Jean II */
697 if (SPY_NUMBER(priv)) {
698 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
699 wstats->qual.level = priv->spy_data.spy_stat[0].level;
700 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
701 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
705 __le16 qual, signal, noise, unused;
706 } __attribute__ ((packed)) cq;
708 err = HERMES_READ_RECORD(hw, USER_BAP,
709 HERMES_RID_COMMSQUALITY, &cq);
712 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
713 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
714 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
715 wstats->qual.updated = 7;
719 orinoco_unlock(priv, &flags);
723 static void orinoco_set_multicast_list(struct net_device *dev)
725 struct orinoco_private *priv = netdev_priv(dev);
728 if (orinoco_lock(priv, &flags) != 0) {
729 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
730 "called when hw_unavailable\n", dev->name);
734 __orinoco_set_multicast_list(dev);
735 orinoco_unlock(priv, &flags);
738 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
740 struct orinoco_private *priv = netdev_priv(dev);
742 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
745 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
746 (priv->nicbuf_size - ETH_HLEN) )
754 /********************************************************************/
756 /********************************************************************/
758 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
760 struct orinoco_private *priv = netdev_priv(dev);
761 struct net_device_stats *stats = &priv->stats;
762 hermes_t *hw = &priv->hw;
764 u16 txfid = priv->txfid;
770 if (! netif_running(dev)) {
771 printk(KERN_ERR "%s: Tx on stopped device!\n",
773 return NETDEV_TX_BUSY;
776 if (netif_queue_stopped(dev)) {
777 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
779 return NETDEV_TX_BUSY;
782 if (orinoco_lock(priv, &flags) != 0) {
783 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
785 return NETDEV_TX_BUSY;
788 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
789 /* Oops, the firmware hasn't established a connection,
790 silently drop the packet (this seems to be the
795 /* Check packet length */
796 if (skb->len < ETH_HLEN)
799 eh = (struct ethhdr *)skb->data;
801 tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
803 if (priv->has_alt_txcntl) {
804 /* WPA enabled firmwares have tx_cntl at the end of
805 * the 802.11 header. So write zeroed descriptor and
806 * 802.11 header at the same time
808 char desc[HERMES_802_3_OFFSET];
809 __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
811 memset(&desc, 0, sizeof(desc));
813 *txcntl = cpu_to_le16(tx_control);
814 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
818 printk(KERN_ERR "%s: Error %d writing Tx "
819 "descriptor to BAP\n", dev->name, err);
823 struct hermes_tx_descriptor desc;
825 memset(&desc, 0, sizeof(desc));
827 desc.tx_control = cpu_to_le16(tx_control);
828 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
832 printk(KERN_ERR "%s: Error %d writing Tx "
833 "descriptor to BAP\n", dev->name, err);
837 /* Clear the 802.11 header and data length fields - some
838 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
839 * if this isn't done. */
840 hermes_clear_words(hw, HERMES_DATA0,
841 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
844 /* Encapsulate Ethernet-II frames */
845 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
846 struct header_struct {
847 struct ethhdr eth; /* 802.3 header */
848 u8 encap[6]; /* 802.2 header */
849 } __attribute__ ((packed)) hdr;
851 /* Strip destination and source from the data */
852 skb_pull(skb, 2 * ETH_ALEN);
853 data_off = HERMES_802_2_OFFSET + sizeof(encaps_hdr);
855 /* And move them to a separate header */
856 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
857 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
858 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
860 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
861 txfid, HERMES_802_3_OFFSET);
864 printk(KERN_ERR "%s: Error %d writing packet "
865 "header to BAP\n", dev->name, err);
868 } else { /* IEEE 802.3 frame */
869 data_off = HERMES_802_3_OFFSET;
872 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
875 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
880 /* Finally, we actually initiate the send */
881 netif_stop_queue(dev);
883 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
886 netif_start_queue(dev);
888 printk(KERN_ERR "%s: Error %d transmitting packet\n",
893 dev->trans_start = jiffies;
894 stats->tx_bytes += data_off + skb->len;
902 orinoco_unlock(priv, &flags);
908 schedule_work(&priv->reset_work);
909 orinoco_unlock(priv, &flags);
910 return NETDEV_TX_BUSY;
913 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
915 struct orinoco_private *priv = netdev_priv(dev);
916 u16 fid = hermes_read_regn(hw, ALLOCFID);
918 if (fid != priv->txfid) {
919 if (fid != DUMMY_FID)
920 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
925 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
928 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
930 struct orinoco_private *priv = netdev_priv(dev);
931 struct net_device_stats *stats = &priv->stats;
935 netif_wake_queue(dev);
937 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
940 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
942 struct orinoco_private *priv = netdev_priv(dev);
943 struct net_device_stats *stats = &priv->stats;
944 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
946 struct hermes_txexc_data hdr;
949 if (fid == DUMMY_FID)
950 return; /* Nothing's really happened */
952 /* Read part of the frame header - we need status and addr1 */
953 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
954 sizeof(struct hermes_txexc_data),
957 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
961 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
962 "(FID=%04X error %d)\n",
963 dev->name, fid, err);
967 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
970 /* We produce a TXDROP event only for retry or lifetime
971 * exceeded, because that's the only status that really mean
972 * that this particular node went away.
973 * Other errors means that *we* screwed up. - Jean II */
974 status = le16_to_cpu(hdr.desc.status);
975 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
976 union iwreq_data wrqu;
978 /* Copy 802.11 dest address.
979 * We use the 802.11 header because the frame may
980 * not be 802.3 or may be mangled...
981 * In Ad-Hoc mode, it will be the node address.
982 * In managed mode, it will be most likely the AP addr
983 * User space will figure out how to convert it to
984 * whatever it needs (IP address or else).
986 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
987 wrqu.addr.sa_family = ARPHRD_ETHER;
989 /* Send event to user space */
990 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
993 netif_wake_queue(dev);
996 static void orinoco_tx_timeout(struct net_device *dev)
998 struct orinoco_private *priv = netdev_priv(dev);
999 struct net_device_stats *stats = &priv->stats;
1000 struct hermes *hw = &priv->hw;
1002 printk(KERN_WARNING "%s: Tx timeout! "
1003 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
1004 dev->name, hermes_read_regn(hw, ALLOCFID),
1005 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
1009 schedule_work(&priv->reset_work);
1012 /********************************************************************/
1013 /* Rx path (data frames) */
1014 /********************************************************************/
1016 /* Does the frame have a SNAP header indicating it should be
1017 * de-encapsulated to Ethernet-II? */
1018 static inline int is_ethersnap(void *_hdr)
1022 /* We de-encapsulate all packets which, a) have SNAP headers
1023 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
1024 * and where b) the OUI of the SNAP header is 00:00:00 or
1025 * 00:00:f8 - we need both because different APs appear to use
1026 * different OUIs for some reason */
1027 return (memcmp(hdr, &encaps_hdr, 5) == 0)
1028 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
1031 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
1032 int level, int noise)
1034 struct iw_quality wstats;
1035 wstats.level = level - 0x95;
1036 wstats.noise = noise - 0x95;
1037 wstats.qual = (level > noise) ? (level - noise) : 0;
1039 /* Update spy records */
1040 wireless_spy_update(dev, mac, &wstats);
1043 static void orinoco_stat_gather(struct net_device *dev,
1044 struct sk_buff *skb,
1045 struct hermes_rx_descriptor *desc)
1047 struct orinoco_private *priv = netdev_priv(dev);
1049 /* Using spy support with lots of Rx packets, like in an
1050 * infrastructure (AP), will really slow down everything, because
1051 * the MAC address must be compared to each entry of the spy list.
1052 * If the user really asks for it (set some address in the
1053 * spy list), we do it, but he will pay the price.
1054 * Note that to get here, you need both WIRELESS_SPY
1055 * compiled in AND some addresses in the list !!!
1057 /* Note : gcc will optimise the whole section away if
1058 * WIRELESS_SPY is not defined... - Jean II */
1059 if (SPY_NUMBER(priv)) {
1060 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
1061 desc->signal, desc->silence);
1066 * orinoco_rx_monitor - handle received monitor frames.
1069 * dev network device
1070 * rxfid received FID
1071 * desc rx descriptor of the frame
1073 * Call context: interrupt
1075 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
1076 struct hermes_rx_descriptor *desc)
1078 u32 hdrlen = 30; /* return full header by default */
1083 struct sk_buff *skb;
1084 struct orinoco_private *priv = netdev_priv(dev);
1085 struct net_device_stats *stats = &priv->stats;
1086 hermes_t *hw = &priv->hw;
1088 len = le16_to_cpu(desc->data_len);
1090 /* Determine the size of the header and the data */
1091 fc = le16_to_cpu(desc->frame_ctl);
1092 switch (fc & IEEE80211_FCTL_FTYPE) {
1093 case IEEE80211_FTYPE_DATA:
1094 if ((fc & IEEE80211_FCTL_TODS)
1095 && (fc & IEEE80211_FCTL_FROMDS))
1101 case IEEE80211_FTYPE_MGMT:
1105 case IEEE80211_FTYPE_CTL:
1106 switch (fc & IEEE80211_FCTL_STYPE) {
1107 case IEEE80211_STYPE_PSPOLL:
1108 case IEEE80211_STYPE_RTS:
1109 case IEEE80211_STYPE_CFEND:
1110 case IEEE80211_STYPE_CFENDACK:
1113 case IEEE80211_STYPE_CTS:
1114 case IEEE80211_STYPE_ACK:
1120 /* Unknown frame type */
1124 /* sanity check the length */
1125 if (datalen > IEEE80211_DATA_LEN + 12) {
1126 printk(KERN_DEBUG "%s: oversized monitor frame, "
1127 "data length = %d\n", dev->name, datalen);
1128 stats->rx_length_errors++;
1132 skb = dev_alloc_skb(hdrlen + datalen);
1134 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
1139 /* Copy the 802.11 header to the skb */
1140 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
1141 skb_reset_mac_header(skb);
1143 /* If any, copy the data from the card to the skb */
1145 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
1146 ALIGN(datalen, 2), rxfid,
1147 HERMES_802_2_OFFSET);
1149 printk(KERN_ERR "%s: error %d reading monitor frame\n",
1156 skb->ip_summed = CHECKSUM_NONE;
1157 skb->pkt_type = PACKET_OTHERHOST;
1158 skb->protocol = __constant_htons(ETH_P_802_2);
1160 dev->last_rx = jiffies;
1161 stats->rx_packets++;
1162 stats->rx_bytes += skb->len;
1168 dev_kfree_skb_irq(skb);
1171 stats->rx_dropped++;
1174 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1176 struct orinoco_private *priv = netdev_priv(dev);
1177 struct net_device_stats *stats = &priv->stats;
1178 struct iw_statistics *wstats = &priv->wstats;
1179 struct sk_buff *skb = NULL;
1180 u16 rxfid, status, fc;
1182 struct hermes_rx_descriptor desc;
1186 rxfid = hermes_read_regn(hw, RXFID);
1188 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
1191 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
1192 "Frame dropped.\n", dev->name, err);
1196 status = le16_to_cpu(desc.status);
1198 if (status & HERMES_RXSTAT_BADCRC) {
1199 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
1201 stats->rx_crc_errors++;
1205 /* Handle frames in monitor mode */
1206 if (priv->iw_mode == IW_MODE_MONITOR) {
1207 orinoco_rx_monitor(dev, rxfid, &desc);
1211 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
1212 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1214 wstats->discard.code++;
1218 length = le16_to_cpu(desc.data_len);
1219 fc = le16_to_cpu(desc.frame_ctl);
1222 if (length < 3) { /* No for even an 802.2 LLC header */
1223 /* At least on Symbol firmware with PCF we get quite a
1224 lot of these legitimately - Poll frames with no
1228 if (length > IEEE80211_DATA_LEN) {
1229 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1231 stats->rx_length_errors++;
1235 /* We need space for the packet data itself, plus an ethernet
1236 header, plus 2 bytes so we can align the IP header on a
1237 32bit boundary, plus 1 byte so we can read in odd length
1238 packets from the card, which has an IO granularity of 16
1240 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
1242 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1247 /* We'll prepend the header, so reserve space for it. The worst
1248 case is no decapsulation, when 802.3 header is prepended and
1249 nothing is removed. 2 is for aligning the IP header. */
1250 skb_reserve(skb, ETH_HLEN + 2);
1252 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
1253 ALIGN(length, 2), rxfid,
1254 HERMES_802_2_OFFSET);
1256 printk(KERN_ERR "%s: error %d reading frame. "
1257 "Frame dropped.\n", dev->name, err);
1261 /* Handle decapsulation
1262 * In most cases, the firmware tell us about SNAP frames.
1263 * For some reason, the SNAP frames sent by LinkSys APs
1264 * are not properly recognised by most firmwares.
1265 * So, check ourselves */
1266 if (length >= ENCAPS_OVERHEAD &&
1267 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1268 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
1269 is_ethersnap(skb->data))) {
1270 /* These indicate a SNAP within 802.2 LLC within
1271 802.11 frame which we'll need to de-encapsulate to
1272 the original EthernetII frame. */
1273 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
1275 /* 802.3 frame - prepend 802.3 header as is */
1276 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
1277 hdr->h_proto = htons(length);
1279 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
1280 if (fc & IEEE80211_FCTL_FROMDS)
1281 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
1283 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
1285 dev->last_rx = jiffies;
1286 skb->protocol = eth_type_trans(skb, dev);
1287 skb->ip_summed = CHECKSUM_NONE;
1288 if (fc & IEEE80211_FCTL_TODS)
1289 skb->pkt_type = PACKET_OTHERHOST;
1291 /* Process the wireless stats if needed */
1292 orinoco_stat_gather(dev, skb, &desc);
1294 /* Pass the packet to the networking stack */
1296 stats->rx_packets++;
1297 stats->rx_bytes += length;
1302 dev_kfree_skb_irq(skb);
1305 stats->rx_dropped++;
1308 /********************************************************************/
1309 /* Rx path (info frames) */
1310 /********************************************************************/
1312 static void print_linkstatus(struct net_device *dev, u16 status)
1316 if (suppress_linkstatus)
1320 case HERMES_LINKSTATUS_NOT_CONNECTED:
1321 s = "Not Connected";
1323 case HERMES_LINKSTATUS_CONNECTED:
1326 case HERMES_LINKSTATUS_DISCONNECTED:
1329 case HERMES_LINKSTATUS_AP_CHANGE:
1332 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1333 s = "AP Out of Range";
1335 case HERMES_LINKSTATUS_AP_IN_RANGE:
1338 case HERMES_LINKSTATUS_ASSOC_FAILED:
1339 s = "Association Failed";
1345 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1346 dev->name, s, status);
1349 /* Search scan results for requested BSSID, join it if found */
1350 static void orinoco_join_ap(struct work_struct *work)
1352 struct orinoco_private *priv =
1353 container_of(work, struct orinoco_private, join_work);
1354 struct net_device *dev = priv->ndev;
1355 struct hermes *hw = &priv->hw;
1357 unsigned long flags;
1361 } __attribute__ ((packed)) req;
1362 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1363 struct prism2_scan_apinfo *atom = NULL;
1369 /* Allocate buffer for scan results */
1370 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1374 if (orinoco_lock(priv, &flags) != 0)
1377 /* Sanity checks in case user changed something in the meantime */
1378 if (! priv->bssid_fixed)
1381 if (strlen(priv->desired_essid) == 0)
1384 /* Read scan results from the firmware */
1385 err = hermes_read_ltv(hw, USER_BAP,
1386 HERMES_RID_SCANRESULTSTABLE,
1387 MAX_SCAN_LEN, &len, buf);
1389 printk(KERN_ERR "%s: Cannot read scan results\n",
1394 len = HERMES_RECLEN_TO_BYTES(len);
1396 /* Go through the scan results looking for the channel of the AP
1397 * we were requested to join */
1398 for (; offset + atom_len <= len; offset += atom_len) {
1399 atom = (struct prism2_scan_apinfo *) (buf + offset);
1400 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1407 DEBUG(1, "%s: Requested AP not found in scan results\n",
1412 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1413 req.channel = atom->channel; /* both are little-endian */
1414 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1417 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1420 orinoco_unlock(priv, &flags);
1426 /* Send new BSSID to userspace */
1427 static void orinoco_send_wevents(struct work_struct *work)
1429 struct orinoco_private *priv =
1430 container_of(work, struct orinoco_private, wevent_work);
1431 struct net_device *dev = priv->ndev;
1432 struct hermes *hw = &priv->hw;
1433 union iwreq_data wrqu;
1435 unsigned long flags;
1437 if (orinoco_lock(priv, &flags) != 0)
1440 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1441 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1445 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1447 /* Send event to user space */
1448 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1451 orinoco_unlock(priv, &flags);
1455 static inline void orinoco_clear_scan_results(struct orinoco_private *priv,
1456 unsigned long scan_age)
1458 if (priv->has_ext_scan) {
1459 struct xbss_element *bss;
1460 struct xbss_element *tmp_bss;
1462 /* Blow away current list of scan results */
1463 list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
1465 time_after(jiffies, bss->last_scanned + scan_age)) {
1466 list_move_tail(&bss->list,
1467 &priv->bss_free_list);
1468 /* Don't blow away ->list, just BSS data */
1469 memset(&bss->bss, 0, sizeof(bss->bss));
1470 bss->last_scanned = 0;
1474 struct bss_element *bss;
1475 struct bss_element *tmp_bss;
1477 /* Blow away current list of scan results */
1478 list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
1480 time_after(jiffies, bss->last_scanned + scan_age)) {
1481 list_move_tail(&bss->list,
1482 &priv->bss_free_list);
1483 /* Don't blow away ->list, just BSS data */
1484 memset(&bss->bss, 0, sizeof(bss->bss));
1485 bss->last_scanned = 0;
1491 static void orinoco_add_ext_scan_result(struct orinoco_private *priv,
1492 struct agere_ext_scan_info *atom)
1494 struct xbss_element *bss = NULL;
1497 /* Try to update an existing bss first */
1498 list_for_each_entry(bss, &priv->bss_list, list) {
1499 if (compare_ether_addr(bss->bss.bssid, atom->bssid))
1502 if (bss->bss.data[1] != atom->data[1])
1504 if (memcmp(&bss->bss.data[2], &atom->data[2],
1511 /* Grab a bss off the free list */
1512 if (!found && !list_empty(&priv->bss_free_list)) {
1513 bss = list_entry(priv->bss_free_list.next,
1514 struct xbss_element, list);
1515 list_del(priv->bss_free_list.next);
1517 list_add_tail(&bss->list, &priv->bss_list);
1521 /* Always update the BSS to get latest beacon info */
1522 memcpy(&bss->bss, atom, sizeof(bss->bss));
1523 bss->last_scanned = jiffies;
1527 static int orinoco_process_scan_results(struct net_device *dev,
1531 struct orinoco_private *priv = netdev_priv(dev);
1532 int offset; /* In the scan data */
1533 union hermes_scan_info *atom;
1536 switch (priv->firmware_type) {
1537 case FIRMWARE_TYPE_AGERE:
1538 atom_len = sizeof(struct agere_scan_apinfo);
1541 case FIRMWARE_TYPE_SYMBOL:
1542 /* Lack of documentation necessitates this hack.
1543 * Different firmwares have 68 or 76 byte long atoms.
1544 * We try modulo first. If the length divides by both,
1545 * we check what would be the channel in the second
1546 * frame for a 68-byte atom. 76-byte atoms have 0 there.
1547 * Valid channel cannot be 0. */
1552 else if (len >= 1292 && buf[68] == 0)
1558 case FIRMWARE_TYPE_INTERSIL:
1560 if (priv->has_hostscan) {
1561 atom_len = le16_to_cpup((__le16 *)buf);
1562 /* Sanity check for atom_len */
1563 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
1564 printk(KERN_ERR "%s: Invalid atom_len in scan "
1565 "data: %d\n", dev->name, atom_len);
1569 atom_len = offsetof(struct prism2_scan_apinfo, atim);
1575 /* Check that we got an whole number of atoms */
1576 if ((len - offset) % atom_len) {
1577 printk(KERN_ERR "%s: Unexpected scan data length %d, "
1578 "atom_len %d, offset %d\n", dev->name, len,
1583 orinoco_clear_scan_results(priv, msecs_to_jiffies(15000));
1585 /* Read the entries one by one */
1586 for (; offset + atom_len <= len; offset += atom_len) {
1588 struct bss_element *bss = NULL;
1591 atom = (union hermes_scan_info *) (buf + offset);
1593 /* Try to update an existing bss first */
1594 list_for_each_entry(bss, &priv->bss_list, list) {
1595 if (compare_ether_addr(bss->bss.a.bssid, atom->a.bssid))
1597 if (le16_to_cpu(bss->bss.a.essid_len) !=
1598 le16_to_cpu(atom->a.essid_len))
1600 if (memcmp(bss->bss.a.essid, atom->a.essid,
1601 le16_to_cpu(atom->a.essid_len)))
1607 /* Grab a bss off the free list */
1608 if (!found && !list_empty(&priv->bss_free_list)) {
1609 bss = list_entry(priv->bss_free_list.next,
1610 struct bss_element, list);
1611 list_del(priv->bss_free_list.next);
1613 list_add_tail(&bss->list, &priv->bss_list);
1617 /* Always update the BSS to get latest beacon info */
1618 memcpy(&bss->bss, atom, sizeof(bss->bss));
1619 bss->last_scanned = jiffies;
1626 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1628 struct orinoco_private *priv = netdev_priv(dev);
1633 } __attribute__ ((packed)) info;
1637 /* This is an answer to an INQUIRE command that we did earlier,
1638 * or an information "event" generated by the card
1639 * The controller return to us a pseudo frame containing
1640 * the information in question - Jean II */
1641 infofid = hermes_read_regn(hw, INFOFID);
1643 /* Read the info frame header - don't try too hard */
1644 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1647 printk(KERN_ERR "%s: error %d reading info frame. "
1648 "Frame dropped.\n", dev->name, err);
1652 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1653 type = le16_to_cpu(info.type);
1656 case HERMES_INQ_TALLIES: {
1657 struct hermes_tallies_frame tallies;
1658 struct iw_statistics *wstats = &priv->wstats;
1660 if (len > sizeof(tallies)) {
1661 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1663 len = sizeof(tallies);
1666 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1667 infofid, sizeof(info));
1671 /* Increment our various counters */
1672 /* wstats->discard.nwid - no wrong BSSID stuff */
1673 wstats->discard.code +=
1674 le16_to_cpu(tallies.RxWEPUndecryptable);
1675 if (len == sizeof(tallies))
1676 wstats->discard.code +=
1677 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1678 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1679 wstats->discard.misc +=
1680 le16_to_cpu(tallies.TxDiscardsWrongSA);
1681 wstats->discard.fragment +=
1682 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1683 wstats->discard.retries +=
1684 le16_to_cpu(tallies.TxRetryLimitExceeded);
1685 /* wstats->miss.beacon - no match */
1688 case HERMES_INQ_LINKSTATUS: {
1689 struct hermes_linkstatus linkstatus;
1693 if (priv->iw_mode == IW_MODE_MONITOR)
1696 if (len != sizeof(linkstatus)) {
1697 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1702 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1703 infofid, sizeof(info));
1706 newstatus = le16_to_cpu(linkstatus.linkstatus);
1708 /* Symbol firmware uses "out of range" to signal that
1709 * the hostscan frame can be requested. */
1710 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1711 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1712 priv->has_hostscan && priv->scan_inprogress) {
1713 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1717 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1718 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1719 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1722 netif_carrier_on(dev);
1723 else if (!ignore_disconnect)
1724 netif_carrier_off(dev);
1726 if (newstatus != priv->last_linkstatus) {
1727 priv->last_linkstatus = newstatus;
1728 print_linkstatus(dev, newstatus);
1729 /* The info frame contains only one word which is the
1730 * status (see hermes.h). The status is pretty boring
1731 * in itself, that's why we export the new BSSID...
1733 schedule_work(&priv->wevent_work);
1737 case HERMES_INQ_SCAN:
1738 if (!priv->scan_inprogress && priv->bssid_fixed &&
1739 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1740 schedule_work(&priv->join_work);
1744 case HERMES_INQ_HOSTSCAN:
1745 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1746 /* Result of a scanning. Contains information about
1747 * cells in the vicinity - Jean II */
1748 union iwreq_data wrqu;
1751 /* Scan is no longer in progress */
1752 priv->scan_inprogress = 0;
1756 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1761 /* Allocate buffer for results */
1762 buf = kmalloc(len, GFP_ATOMIC);
1764 /* No memory, so can't printk()... */
1767 /* Read scan data */
1768 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1769 infofid, sizeof(info));
1775 #ifdef ORINOCO_DEBUG
1778 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1779 for(i = 1; i < (len * 2); i++)
1780 printk(":%02X", buf[i]);
1783 #endif /* ORINOCO_DEBUG */
1785 if (orinoco_process_scan_results(dev, buf, len) == 0) {
1786 /* Send an empty event to user space.
1787 * We don't send the received data on the event because
1788 * it would require us to do complex transcoding, and
1789 * we want to minimise the work done in the irq handler
1790 * Use a request to extract the data - Jean II */
1791 wrqu.data.length = 0;
1792 wrqu.data.flags = 0;
1793 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1798 case HERMES_INQ_CHANNELINFO:
1800 struct agere_ext_scan_info *bss;
1802 if (!priv->scan_inprogress) {
1803 printk(KERN_DEBUG "%s: Got chaninfo without scan, "
1804 "len=%d\n", dev->name, len);
1808 /* An empty result indicates that the scan is complete */
1810 union iwreq_data wrqu;
1812 /* Scan is no longer in progress */
1813 priv->scan_inprogress = 0;
1815 wrqu.data.length = 0;
1816 wrqu.data.flags = 0;
1817 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1822 else if (len > sizeof(*bss)) {
1824 "%s: Ext scan results too large (%d bytes). "
1825 "Truncating results to %zd bytes.\n",
1826 dev->name, len, sizeof(*bss));
1828 } else if (len < (offsetof(struct agere_ext_scan_info,
1830 /* Drop this result now so we don't have to
1831 * keep checking later */
1833 "%s: Ext scan results too short (%d bytes)\n",
1838 bss = kmalloc(sizeof(*bss), GFP_ATOMIC);
1842 /* Read scan data */
1843 err = hermes_bap_pread(hw, IRQ_BAP, (void *) bss, len,
1844 infofid, sizeof(info));
1850 orinoco_add_ext_scan_result(priv, bss);
1855 case HERMES_INQ_SEC_STAT_AGERE:
1856 /* Security status (Agere specific) */
1857 /* Ignore this frame for now */
1858 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1862 printk(KERN_DEBUG "%s: Unknown information frame received: "
1863 "type 0x%04x, length %d\n", dev->name, type, len);
1864 /* We don't actually do anything about it */
1869 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1871 if (net_ratelimit())
1872 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1875 /********************************************************************/
1876 /* Internal hardware control routines */
1877 /********************************************************************/
1879 int __orinoco_up(struct net_device *dev)
1881 struct orinoco_private *priv = netdev_priv(dev);
1882 struct hermes *hw = &priv->hw;
1885 netif_carrier_off(dev); /* just to make sure */
1887 err = __orinoco_program_rids(dev);
1889 printk(KERN_ERR "%s: Error %d configuring card\n",
1894 /* Fire things up again */
1895 hermes_set_irqmask(hw, ORINOCO_INTEN);
1896 err = hermes_enable_port(hw, 0);
1898 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1903 netif_start_queue(dev);
1908 int __orinoco_down(struct net_device *dev)
1910 struct orinoco_private *priv = netdev_priv(dev);
1911 struct hermes *hw = &priv->hw;
1914 netif_stop_queue(dev);
1916 if (! priv->hw_unavailable) {
1917 if (! priv->broken_disableport) {
1918 err = hermes_disable_port(hw, 0);
1920 /* Some firmwares (e.g. Intersil 1.3.x) seem
1921 * to have problems disabling the port, oh
1923 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1925 priv->broken_disableport = 1;
1928 hermes_set_irqmask(hw, 0);
1929 hermes_write_regn(hw, EVACK, 0xffff);
1932 /* firmware will have to reassociate */
1933 netif_carrier_off(dev);
1934 priv->last_linkstatus = 0xffff;
1939 static int orinoco_allocate_fid(struct net_device *dev)
1941 struct orinoco_private *priv = netdev_priv(dev);
1942 struct hermes *hw = &priv->hw;
1945 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1946 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1947 /* Try workaround for old Symbol firmware bug */
1948 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1949 "(old Symbol firmware?). Trying to work around... ",
1952 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1953 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1955 printk("failed!\n");
1963 int orinoco_reinit_firmware(struct net_device *dev)
1965 struct orinoco_private *priv = netdev_priv(dev);
1966 struct hermes *hw = &priv->hw;
1969 err = hermes_init(hw);
1971 err = orinoco_allocate_fid(dev);
1976 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1978 hermes_t *hw = &priv->hw;
1981 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1982 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1983 priv->ndev->name, priv->bitratemode);
1987 switch (priv->firmware_type) {
1988 case FIRMWARE_TYPE_AGERE:
1989 err = hermes_write_wordrec(hw, USER_BAP,
1990 HERMES_RID_CNFTXRATECONTROL,
1991 bitrate_table[priv->bitratemode].agere_txratectrl);
1993 case FIRMWARE_TYPE_INTERSIL:
1994 case FIRMWARE_TYPE_SYMBOL:
1995 err = hermes_write_wordrec(hw, USER_BAP,
1996 HERMES_RID_CNFTXRATECONTROL,
1997 bitrate_table[priv->bitratemode].intersil_txratectrl);
2006 /* Set fixed AP address */
2007 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
2011 hermes_t *hw = &priv->hw;
2013 switch (priv->firmware_type) {
2014 case FIRMWARE_TYPE_AGERE:
2017 case FIRMWARE_TYPE_INTERSIL:
2018 if (priv->bssid_fixed)
2023 err = hermes_write_wordrec(hw, USER_BAP,
2024 HERMES_RID_CNFROAMINGMODE,
2027 case FIRMWARE_TYPE_SYMBOL:
2028 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2029 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
2030 &priv->desired_bssid);
2036 /* Change the WEP keys and/or the current keys. Can be called
2037 * either from __orinoco_hw_setup_wep() or directly from
2038 * orinoco_ioctl_setiwencode(). In the later case the association
2039 * with the AP is not broken (if the firmware can handle it),
2040 * which is needed for 802.1x implementations. */
2041 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
2043 hermes_t *hw = &priv->hw;
2046 switch (priv->firmware_type) {
2047 case FIRMWARE_TYPE_AGERE:
2048 err = HERMES_WRITE_RECORD(hw, USER_BAP,
2049 HERMES_RID_CNFWEPKEYS_AGERE,
2053 err = hermes_write_wordrec(hw, USER_BAP,
2054 HERMES_RID_CNFTXKEY_AGERE,
2059 case FIRMWARE_TYPE_INTERSIL:
2060 case FIRMWARE_TYPE_SYMBOL:
2065 /* Force uniform key length to work around firmware bugs */
2066 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
2068 if (keylen > LARGE_KEY_SIZE) {
2069 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
2070 priv->ndev->name, priv->tx_key, keylen);
2074 /* Write all 4 keys */
2075 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
2076 err = hermes_write_ltv(hw, USER_BAP,
2077 HERMES_RID_CNFDEFAULTKEY0 + i,
2078 HERMES_BYTES_TO_RECLEN(keylen),
2079 priv->keys[i].data);
2084 /* Write the index of the key used in transmission */
2085 err = hermes_write_wordrec(hw, USER_BAP,
2086 HERMES_RID_CNFWEPDEFAULTKEYID,
2097 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
2099 hermes_t *hw = &priv->hw;
2101 int master_wep_flag;
2105 if (priv->encode_alg == IW_ENCODE_ALG_WEP)
2106 __orinoco_hw_setup_wepkeys(priv);
2108 if (priv->wep_restrict)
2109 auth_flag = HERMES_AUTH_SHARED_KEY;
2111 auth_flag = HERMES_AUTH_OPEN;
2113 if (priv->encode_alg == IW_ENCODE_ALG_WEP)
2118 switch (priv->firmware_type) {
2119 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
2120 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
2121 /* Enable the shared-key authentication. */
2122 err = hermes_write_wordrec(hw, USER_BAP,
2123 HERMES_RID_CNFAUTHENTICATION_AGERE,
2126 err = hermes_write_wordrec(hw, USER_BAP,
2127 HERMES_RID_CNFWEPENABLED_AGERE,
2133 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
2134 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
2135 if (priv->encode_alg == IW_ENCODE_ALG_WEP) {
2136 if (priv->wep_restrict ||
2137 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
2138 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
2139 HERMES_WEP_EXCL_UNENCRYPTED;
2141 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
2143 err = hermes_write_wordrec(hw, USER_BAP,
2144 HERMES_RID_CNFAUTHENTICATION,
2149 master_wep_flag = 0;
2151 if (priv->iw_mode == IW_MODE_MONITOR)
2152 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
2154 /* Master WEP setting : on/off */
2155 err = hermes_write_wordrec(hw, USER_BAP,
2156 HERMES_RID_CNFWEPFLAGS_INTERSIL,
2167 static int __orinoco_program_rids(struct net_device *dev)
2169 struct orinoco_private *priv = netdev_priv(dev);
2170 hermes_t *hw = &priv->hw;
2172 struct hermes_idstring idbuf;
2174 /* Set the MAC address */
2175 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2176 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
2178 printk(KERN_ERR "%s: Error %d setting MAC address\n",
2183 /* Set up the link mode */
2184 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
2187 printk(KERN_ERR "%s: Error %d setting port type\n",
2191 /* Set the channel/frequency */
2192 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
2193 err = hermes_write_wordrec(hw, USER_BAP,
2194 HERMES_RID_CNFOWNCHANNEL,
2197 printk(KERN_ERR "%s: Error %d setting channel %d\n",
2198 dev->name, err, priv->channel);
2203 if (priv->has_ibss) {
2206 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
2207 printk(KERN_WARNING "%s: This firmware requires an "
2208 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
2209 /* With wvlan_cs, in this case, we would crash.
2210 * hopefully, this driver will behave better...
2214 createibss = priv->createibss;
2217 err = hermes_write_wordrec(hw, USER_BAP,
2218 HERMES_RID_CNFCREATEIBSS,
2221 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
2227 /* Set the desired BSSID */
2228 err = __orinoco_hw_set_wap(priv);
2230 printk(KERN_ERR "%s: Error %d setting AP address\n",
2234 /* Set the desired ESSID */
2235 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
2236 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
2237 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
2238 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
2239 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2242 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
2246 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
2247 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2250 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
2255 /* Set the station name */
2256 idbuf.len = cpu_to_le16(strlen(priv->nick));
2257 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
2258 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2259 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
2262 printk(KERN_ERR "%s: Error %d setting nickname\n",
2267 /* Set AP density */
2268 if (priv->has_sensitivity) {
2269 err = hermes_write_wordrec(hw, USER_BAP,
2270 HERMES_RID_CNFSYSTEMSCALE,
2273 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
2274 "Disabling sensitivity control\n",
2277 priv->has_sensitivity = 0;
2281 /* Set RTS threshold */
2282 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2285 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
2290 /* Set fragmentation threshold or MWO robustness */
2292 err = hermes_write_wordrec(hw, USER_BAP,
2293 HERMES_RID_CNFMWOROBUST_AGERE,
2296 err = hermes_write_wordrec(hw, USER_BAP,
2297 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2300 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
2306 err = __orinoco_hw_set_bitrate(priv);
2308 printk(KERN_ERR "%s: Error %d setting bitrate\n",
2313 /* Set power management */
2315 err = hermes_write_wordrec(hw, USER_BAP,
2316 HERMES_RID_CNFPMENABLED,
2319 printk(KERN_ERR "%s: Error %d setting up PM\n",
2324 err = hermes_write_wordrec(hw, USER_BAP,
2325 HERMES_RID_CNFMULTICASTRECEIVE,
2328 printk(KERN_ERR "%s: Error %d setting up PM\n",
2332 err = hermes_write_wordrec(hw, USER_BAP,
2333 HERMES_RID_CNFMAXSLEEPDURATION,
2336 printk(KERN_ERR "%s: Error %d setting up PM\n",
2340 err = hermes_write_wordrec(hw, USER_BAP,
2341 HERMES_RID_CNFPMHOLDOVERDURATION,
2344 printk(KERN_ERR "%s: Error %d setting up PM\n",
2350 /* Set preamble - only for Symbol so far... */
2351 if (priv->has_preamble) {
2352 err = hermes_write_wordrec(hw, USER_BAP,
2353 HERMES_RID_CNFPREAMBLE_SYMBOL,
2356 printk(KERN_ERR "%s: Error %d setting preamble\n",
2362 /* Set up encryption */
2363 if (priv->has_wep) {
2364 err = __orinoco_hw_setup_wep(priv);
2366 printk(KERN_ERR "%s: Error %d activating WEP\n",
2372 if (priv->iw_mode == IW_MODE_MONITOR) {
2373 /* Enable monitor mode */
2374 dev->type = ARPHRD_IEEE80211;
2375 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2376 HERMES_TEST_MONITOR, 0, NULL);
2378 /* Disable monitor mode */
2379 dev->type = ARPHRD_ETHER;
2380 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2381 HERMES_TEST_STOP, 0, NULL);
2386 /* Set promiscuity / multicast*/
2387 priv->promiscuous = 0;
2390 /* FIXME: what about netif_tx_lock */
2391 __orinoco_set_multicast_list(dev);
2396 /* FIXME: return int? */
2398 __orinoco_set_multicast_list(struct net_device *dev)
2400 struct orinoco_private *priv = netdev_priv(dev);
2401 hermes_t *hw = &priv->hw;
2403 int promisc, mc_count;
2405 /* The Hermes doesn't seem to have an allmulti mode, so we go
2406 * into promiscuous mode and let the upper levels deal. */
2407 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
2408 (dev->mc_count > MAX_MULTICAST(priv)) ) {
2413 mc_count = dev->mc_count;
2416 if (promisc != priv->promiscuous) {
2417 err = hermes_write_wordrec(hw, USER_BAP,
2418 HERMES_RID_CNFPROMISCUOUSMODE,
2421 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
2424 priv->promiscuous = promisc;
2427 if (! promisc && (mc_count || priv->mc_count) ) {
2428 struct dev_mc_list *p = dev->mc_list;
2429 struct hermes_multicast mclist;
2432 for (i = 0; i < mc_count; i++) {
2433 /* paranoia: is list shorter than mc_count? */
2435 /* paranoia: bad address size in list? */
2436 BUG_ON(p->dmi_addrlen != ETH_ALEN);
2438 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
2443 printk(KERN_WARNING "%s: Multicast list is "
2444 "longer than mc_count\n", dev->name);
2446 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
2447 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
2450 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
2453 priv->mc_count = mc_count;
2457 /* This must be called from user context, without locks held - use
2458 * schedule_work() */
2459 static void orinoco_reset(struct work_struct *work)
2461 struct orinoco_private *priv =
2462 container_of(work, struct orinoco_private, reset_work);
2463 struct net_device *dev = priv->ndev;
2464 struct hermes *hw = &priv->hw;
2466 unsigned long flags;
2468 if (orinoco_lock(priv, &flags) != 0)
2469 /* When the hardware becomes available again, whatever
2470 * detects that is responsible for re-initializing
2471 * it. So no need for anything further */
2474 netif_stop_queue(dev);
2476 /* Shut off interrupts. Depending on what state the hardware
2477 * is in, this might not work, but we'll try anyway */
2478 hermes_set_irqmask(hw, 0);
2479 hermes_write_regn(hw, EVACK, 0xffff);
2481 priv->hw_unavailable++;
2482 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
2483 netif_carrier_off(dev);
2485 orinoco_unlock(priv, &flags);
2487 /* Scanning support: Cleanup of driver struct */
2488 orinoco_clear_scan_results(priv, 0);
2489 priv->scan_inprogress = 0;
2491 if (priv->hard_reset) {
2492 err = (*priv->hard_reset)(priv);
2494 printk(KERN_ERR "%s: orinoco_reset: Error %d "
2495 "performing hard reset\n", dev->name, err);
2500 if (priv->do_fw_download) {
2501 err = orinoco_download(priv);
2503 priv->do_fw_download = 0;
2506 err = orinoco_reinit_firmware(dev);
2508 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
2513 spin_lock_irq(&priv->lock); /* This has to be called from user context */
2515 priv->hw_unavailable--;
2517 /* priv->open or priv->hw_unavailable might have changed while
2518 * we dropped the lock */
2519 if (priv->open && (! priv->hw_unavailable)) {
2520 err = __orinoco_up(dev);
2522 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
2525 dev->trans_start = jiffies;
2528 spin_unlock_irq(&priv->lock);
2532 hermes_set_irqmask(hw, 0);
2533 netif_device_detach(dev);
2534 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
2537 /********************************************************************/
2538 /* Interrupt handler */
2539 /********************************************************************/
2541 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
2543 printk(KERN_DEBUG "%s: TICK\n", dev->name);
2546 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
2548 /* This seems to happen a fair bit under load, but ignoring it
2549 seems to work fine...*/
2550 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
2554 irqreturn_t orinoco_interrupt(int irq, void *dev_id)
2556 struct net_device *dev = dev_id;
2557 struct orinoco_private *priv = netdev_priv(dev);
2558 hermes_t *hw = &priv->hw;
2559 int count = MAX_IRQLOOPS_PER_IRQ;
2561 /* These are used to detect a runaway interrupt situation */
2562 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2563 * we panic and shut down the hardware */
2564 static int last_irq_jiffy = 0; /* jiffies value the last time
2566 static int loops_this_jiffy = 0;
2567 unsigned long flags;
2569 if (orinoco_lock(priv, &flags) != 0) {
2570 /* If hw is unavailable - we don't know if the irq was
2575 evstat = hermes_read_regn(hw, EVSTAT);
2576 events = evstat & hw->inten;
2578 orinoco_unlock(priv, &flags);
2582 if (jiffies != last_irq_jiffy)
2583 loops_this_jiffy = 0;
2584 last_irq_jiffy = jiffies;
2586 while (events && count--) {
2587 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2588 printk(KERN_WARNING "%s: IRQ handler is looping too "
2589 "much! Resetting.\n", dev->name);
2590 /* Disable interrupts for now */
2591 hermes_set_irqmask(hw, 0);
2592 schedule_work(&priv->reset_work);
2596 /* Check the card hasn't been removed */
2597 if (! hermes_present(hw)) {
2598 DEBUG(0, "orinoco_interrupt(): card removed\n");
2602 if (events & HERMES_EV_TICK)
2603 __orinoco_ev_tick(dev, hw);
2604 if (events & HERMES_EV_WTERR)
2605 __orinoco_ev_wterr(dev, hw);
2606 if (events & HERMES_EV_INFDROP)
2607 __orinoco_ev_infdrop(dev, hw);
2608 if (events & HERMES_EV_INFO)
2609 __orinoco_ev_info(dev, hw);
2610 if (events & HERMES_EV_RX)
2611 __orinoco_ev_rx(dev, hw);
2612 if (events & HERMES_EV_TXEXC)
2613 __orinoco_ev_txexc(dev, hw);
2614 if (events & HERMES_EV_TX)
2615 __orinoco_ev_tx(dev, hw);
2616 if (events & HERMES_EV_ALLOC)
2617 __orinoco_ev_alloc(dev, hw);
2619 hermes_write_regn(hw, EVACK, evstat);
2621 evstat = hermes_read_regn(hw, EVSTAT);
2622 events = evstat & hw->inten;
2625 orinoco_unlock(priv, &flags);
2629 /********************************************************************/
2630 /* Initialization */
2631 /********************************************************************/
2634 u16 id, variant, major, minor;
2635 } __attribute__ ((packed));
2637 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2639 if (nic_id->id < 0x8000)
2640 return FIRMWARE_TYPE_AGERE;
2641 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2642 return FIRMWARE_TYPE_SYMBOL;
2644 return FIRMWARE_TYPE_INTERSIL;
2647 /* Set priv->firmware type, determine firmware properties */
2648 static int determine_firmware(struct net_device *dev)
2650 struct orinoco_private *priv = netdev_priv(dev);
2651 hermes_t *hw = &priv->hw;
2653 struct comp_id nic_id, sta_id;
2654 unsigned int firmver;
2655 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
2657 /* Get the hardware version */
2658 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2660 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2665 le16_to_cpus(&nic_id.id);
2666 le16_to_cpus(&nic_id.variant);
2667 le16_to_cpus(&nic_id.major);
2668 le16_to_cpus(&nic_id.minor);
2669 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2670 dev->name, nic_id.id, nic_id.variant,
2671 nic_id.major, nic_id.minor);
2673 priv->firmware_type = determine_firmware_type(&nic_id);
2675 /* Get the firmware version */
2676 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2678 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2683 le16_to_cpus(&sta_id.id);
2684 le16_to_cpus(&sta_id.variant);
2685 le16_to_cpus(&sta_id.major);
2686 le16_to_cpus(&sta_id.minor);
2687 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2688 dev->name, sta_id.id, sta_id.variant,
2689 sta_id.major, sta_id.minor);
2691 switch (sta_id.id) {
2693 printk(KERN_ERR "%s: Primary firmware is active\n",
2697 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2700 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2701 case 0x21: /* Symbol Spectrum24 Trilogy */
2704 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2709 /* Default capabilities */
2710 priv->has_sensitivity = 1;
2712 priv->has_preamble = 0;
2713 priv->has_port3 = 1;
2716 priv->has_big_wep = 0;
2717 priv->has_alt_txcntl = 0;
2718 priv->has_ext_scan = 0;
2719 priv->do_fw_download = 0;
2721 /* Determine capabilities from the firmware version */
2722 switch (priv->firmware_type) {
2723 case FIRMWARE_TYPE_AGERE:
2724 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2725 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2726 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2727 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2729 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2731 priv->has_ibss = (firmver >= 0x60006);
2732 priv->has_wep = (firmver >= 0x40020);
2733 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2734 Gold cards from the others? */
2735 priv->has_mwo = (firmver >= 0x60000);
2736 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2737 priv->ibss_port = 1;
2738 priv->has_hostscan = (firmver >= 0x8000a);
2739 priv->do_fw_download = 1;
2740 priv->broken_monitor = (firmver >= 0x80000);
2741 priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
2742 priv->has_ext_scan = (firmver >= 0x90000); /* All 9.x ? */
2743 /* Tested with Agere firmware :
2744 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2745 * Tested CableTron firmware : 4.32 => Anton */
2747 case FIRMWARE_TYPE_SYMBOL:
2748 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2749 /* Intel MAC : 00:02:B3:* */
2750 /* 3Com MAC : 00:50:DA:* */
2751 memset(tmp, 0, sizeof(tmp));
2752 /* Get the Symbol firmware version */
2753 err = hermes_read_ltv(hw, USER_BAP,
2754 HERMES_RID_SECONDARYVERSION_SYMBOL,
2755 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2758 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2763 /* The firmware revision is a string, the format is
2764 * something like : "V2.20-01".
2765 * Quick and dirty parsing... - Jean II
2767 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2768 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2771 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2774 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2777 priv->has_ibss = (firmver >= 0x20000);
2778 priv->has_wep = (firmver >= 0x15012);
2779 priv->has_big_wep = (firmver >= 0x20000);
2780 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2781 (firmver >= 0x29000 && firmver < 0x30000) ||
2783 priv->has_preamble = (firmver >= 0x20000);
2784 priv->ibss_port = 4;
2786 /* Symbol firmware is found on various cards, but
2787 * there has been no attempt to check firmware
2788 * download on non-spectrum_cs based cards.
2790 * Given that the Agere firmware download works
2791 * differently, we should avoid doing a firmware
2792 * download with the Symbol algorithm on non-spectrum
2795 * For now we can identify a spectrum_cs based card
2796 * because it has a firmware reset function.
2798 priv->do_fw_download = (priv->stop_fw != NULL);
2800 priv->broken_disableport = (firmver == 0x25013) ||
2801 (firmver >= 0x30000 && firmver <= 0x31000);
2802 priv->has_hostscan = (firmver >= 0x31001) ||
2803 (firmver >= 0x29057 && firmver < 0x30000);
2804 /* Tested with Intel firmware : 0x20015 => Jean II */
2805 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2807 case FIRMWARE_TYPE_INTERSIL:
2808 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2809 * Samsung, Compaq 100/200 and Proxim are slightly
2810 * different and less well tested */
2811 /* D-Link MAC : 00:40:05:* */
2812 /* Addtron MAC : 00:90:D1:* */
2813 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2814 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2817 firmver = ((unsigned long)sta_id.major << 16) |
2818 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2820 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2821 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2822 priv->has_pm = (firmver >= 0x000700);
2823 priv->has_hostscan = (firmver >= 0x010301);
2825 if (firmver >= 0x000800)
2826 priv->ibss_port = 0;
2828 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2829 "than v0.8.x - several features not supported\n",
2831 priv->ibss_port = 1;
2835 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2841 static int orinoco_init(struct net_device *dev)
2843 struct orinoco_private *priv = netdev_priv(dev);
2844 hermes_t *hw = &priv->hw;
2846 struct hermes_idstring nickbuf;
2849 DECLARE_MAC_BUF(mac);
2851 /* No need to lock, the hw_unavailable flag is already set in
2852 * alloc_orinocodev() */
2853 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
2855 /* Initialize the firmware */
2856 err = hermes_init(hw);
2858 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2863 err = determine_firmware(dev);
2865 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2870 if (priv->do_fw_download) {
2871 err = orinoco_download(priv);
2873 priv->do_fw_download = 0;
2875 /* Check firmware version again */
2876 err = determine_firmware(dev);
2878 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2884 if (priv->has_port3)
2885 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2887 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2889 if (priv->has_wep) {
2890 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2891 if (priv->has_big_wep)
2892 printk("104-bit key\n");
2894 printk("40-bit key\n");
2897 /* Now we have the firmware capabilities, allocate appropiate
2898 * sized scan buffers */
2899 if (orinoco_bss_data_allocate(priv))
2901 orinoco_bss_data_init(priv);
2903 /* Get the MAC address */
2904 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2905 ETH_ALEN, NULL, dev->dev_addr);
2907 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2912 printk(KERN_DEBUG "%s: MAC address %s\n",
2913 dev->name, print_mac(mac, dev->dev_addr));
2915 /* Get the station name */
2916 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2917 sizeof(nickbuf), &reclen, &nickbuf);
2919 printk(KERN_ERR "%s: failed to read station name\n",
2924 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2926 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2927 memcpy(priv->nick, &nickbuf.val, len);
2928 priv->nick[len] = '\0';
2930 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2932 err = orinoco_allocate_fid(dev);
2934 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
2939 /* Get allowed channels */
2940 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2941 &priv->channel_mask);
2943 printk(KERN_ERR "%s: failed to read channel list!\n",
2948 /* Get initial AP density */
2949 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2951 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2952 priv->has_sensitivity = 0;
2955 /* Get initial RTS threshold */
2956 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2959 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2964 /* Get initial fragmentation settings */
2966 err = hermes_read_wordrec(hw, USER_BAP,
2967 HERMES_RID_CNFMWOROBUST_AGERE,
2970 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2971 &priv->frag_thresh);
2973 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2978 /* Power management setup */
2982 err = hermes_read_wordrec(hw, USER_BAP,
2983 HERMES_RID_CNFMAXSLEEPDURATION,
2986 printk(KERN_ERR "%s: failed to read power management period!\n",
2990 err = hermes_read_wordrec(hw, USER_BAP,
2991 HERMES_RID_CNFPMHOLDOVERDURATION,
2994 printk(KERN_ERR "%s: failed to read power management timeout!\n",
3000 /* Preamble setup */
3001 if (priv->has_preamble) {
3002 err = hermes_read_wordrec(hw, USER_BAP,
3003 HERMES_RID_CNFPREAMBLE_SYMBOL,
3009 /* Set up the default configuration */
3010 priv->iw_mode = IW_MODE_INFRA;
3011 /* By default use IEEE/IBSS ad-hoc mode if we have it */
3012 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
3013 set_port_type(priv);
3014 priv->channel = 0; /* use firmware default */
3016 priv->promiscuous = 0;
3017 priv->encode_alg = IW_ENCODE_ALG_NONE;
3020 /* Make the hardware available, as long as it hasn't been
3021 * removed elsewhere (e.g. by PCMCIA hot unplug) */
3022 spin_lock_irq(&priv->lock);
3023 priv->hw_unavailable--;
3024 spin_unlock_irq(&priv->lock);
3026 printk(KERN_DEBUG "%s: ready\n", dev->name);
3033 *alloc_orinocodev(int sizeof_card,
3034 struct device *device,
3035 int (*hard_reset)(struct orinoco_private *),
3036 int (*stop_fw)(struct orinoco_private *, int))
3038 struct net_device *dev;
3039 struct orinoco_private *priv;
3041 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
3044 priv = netdev_priv(dev);
3047 priv->card = (void *)((unsigned long)priv
3048 + sizeof(struct orinoco_private));
3053 /* Setup / override net_device fields */
3054 dev->init = orinoco_init;
3055 dev->hard_start_xmit = orinoco_xmit;
3056 dev->tx_timeout = orinoco_tx_timeout;
3057 dev->watchdog_timeo = HZ; /* 1 second timeout */
3058 dev->get_stats = orinoco_get_stats;
3059 dev->ethtool_ops = &orinoco_ethtool_ops;
3060 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
3062 priv->wireless_data.spy_data = &priv->spy_data;
3063 dev->wireless_data = &priv->wireless_data;
3065 dev->change_mtu = orinoco_change_mtu;
3066 dev->set_multicast_list = orinoco_set_multicast_list;
3067 /* we use the default eth_mac_addr for setting the MAC addr */
3069 /* Set up default callbacks */
3070 dev->open = orinoco_open;
3071 dev->stop = orinoco_stop;
3072 priv->hard_reset = hard_reset;
3073 priv->stop_fw = stop_fw;
3075 spin_lock_init(&priv->lock);
3077 priv->hw_unavailable = 1; /* orinoco_init() must clear this
3078 * before anything else touches the
3080 INIT_WORK(&priv->reset_work, orinoco_reset);
3081 INIT_WORK(&priv->join_work, orinoco_join_ap);
3082 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
3084 netif_carrier_off(dev);
3085 priv->last_linkstatus = 0xffff;
3090 void free_orinocodev(struct net_device *dev)
3092 struct orinoco_private *priv = netdev_priv(dev);
3094 orinoco_bss_data_free(priv);
3098 /********************************************************************/
3099 /* Wireless extensions */
3100 /********************************************************************/
3102 /* Return : < 0 -> error code ; >= 0 -> length */
3103 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
3104 char buf[IW_ESSID_MAX_SIZE+1])
3106 hermes_t *hw = &priv->hw;
3108 struct hermes_idstring essidbuf;
3109 char *p = (char *)(&essidbuf.val);
3111 unsigned long flags;
3113 if (orinoco_lock(priv, &flags) != 0)
3116 if (strlen(priv->desired_essid) > 0) {
3117 /* We read the desired SSID from the hardware rather
3118 than from priv->desired_essid, just in case the
3119 firmware is allowed to change it on us. I'm not
3121 /* My guess is that the OWNSSID should always be whatever
3122 * we set to the card, whereas CURRENT_SSID is the one that
3123 * may change... - Jean II */
3128 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
3129 HERMES_RID_CNFDESIREDSSID;
3131 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
3138 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
3139 sizeof(essidbuf), NULL, &essidbuf);
3144 len = le16_to_cpu(essidbuf.len);
3145 BUG_ON(len > IW_ESSID_MAX_SIZE);
3147 memset(buf, 0, IW_ESSID_MAX_SIZE);
3148 memcpy(buf, p, len);
3152 orinoco_unlock(priv, &flags);
3157 static long orinoco_hw_get_freq(struct orinoco_private *priv)
3160 hermes_t *hw = &priv->hw;
3164 unsigned long flags;
3166 if (orinoco_lock(priv, &flags) != 0)
3169 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
3173 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
3179 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
3180 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
3181 priv->ndev->name, channel);
3186 freq = channel_frequency[channel-1] * 100000;
3189 orinoco_unlock(priv, &flags);
3193 return err ? err : freq;
3196 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
3197 int *numrates, s32 *rates, int max)
3199 hermes_t *hw = &priv->hw;
3200 struct hermes_idstring list;
3201 unsigned char *p = (unsigned char *)&list.val;
3205 unsigned long flags;
3207 if (orinoco_lock(priv, &flags) != 0)
3210 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
3211 sizeof(list), NULL, &list);
3212 orinoco_unlock(priv, &flags);
3217 num = le16_to_cpu(list.len);
3219 num = min(num, max);
3221 for (i = 0; i < num; i++) {
3222 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
3228 static int orinoco_ioctl_getname(struct net_device *dev,
3229 struct iw_request_info *info,
3233 struct orinoco_private *priv = netdev_priv(dev);
3237 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
3239 if (!err && (numrates > 2))
3240 strcpy(name, "IEEE 802.11b");
3242 strcpy(name, "IEEE 802.11-DS");
3247 static int orinoco_ioctl_setwap(struct net_device *dev,
3248 struct iw_request_info *info,
3249 struct sockaddr *ap_addr,
3252 struct orinoco_private *priv = netdev_priv(dev);
3253 int err = -EINPROGRESS; /* Call commit handler */
3254 unsigned long flags;
3255 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3256 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3258 if (orinoco_lock(priv, &flags) != 0)
3261 /* Enable automatic roaming - no sanity checks are needed */
3262 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
3263 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
3264 priv->bssid_fixed = 0;
3265 memset(priv->desired_bssid, 0, ETH_ALEN);
3267 /* "off" means keep existing connection */
3268 if (ap_addr->sa_data[0] == 0) {
3269 __orinoco_hw_set_wap(priv);
3275 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
3276 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
3277 "support manual roaming\n",
3283 if (priv->iw_mode != IW_MODE_INFRA) {
3284 printk(KERN_WARNING "%s: Manual roaming supported only in "
3285 "managed mode\n", dev->name);
3290 /* Intersil firmware hangs without Desired ESSID */
3291 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
3292 strlen(priv->desired_essid) == 0) {
3293 printk(KERN_WARNING "%s: Desired ESSID must be set for "
3294 "manual roaming\n", dev->name);
3299 /* Finally, enable manual roaming */
3300 priv->bssid_fixed = 1;
3301 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
3304 orinoco_unlock(priv, &flags);
3308 static int orinoco_ioctl_getwap(struct net_device *dev,
3309 struct iw_request_info *info,
3310 struct sockaddr *ap_addr,
3313 struct orinoco_private *priv = netdev_priv(dev);
3315 hermes_t *hw = &priv->hw;
3317 unsigned long flags;
3319 if (orinoco_lock(priv, &flags) != 0)
3322 ap_addr->sa_family = ARPHRD_ETHER;
3323 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
3324 ETH_ALEN, NULL, ap_addr->sa_data);
3326 orinoco_unlock(priv, &flags);
3331 static int orinoco_ioctl_setmode(struct net_device *dev,
3332 struct iw_request_info *info,
3336 struct orinoco_private *priv = netdev_priv(dev);
3337 int err = -EINPROGRESS; /* Call commit handler */
3338 unsigned long flags;
3340 if (priv->iw_mode == *mode)
3343 if (orinoco_lock(priv, &flags) != 0)
3348 if (!priv->has_ibss && !priv->has_port3)
3355 case IW_MODE_MONITOR:
3356 if (priv->broken_monitor && !force_monitor) {
3357 printk(KERN_WARNING "%s: Monitor mode support is "
3358 "buggy in this firmware, not enabling\n",
3369 if (err == -EINPROGRESS) {
3370 priv->iw_mode = *mode;
3371 set_port_type(priv);
3374 orinoco_unlock(priv, &flags);
3379 static int orinoco_ioctl_getmode(struct net_device *dev,
3380 struct iw_request_info *info,
3384 struct orinoco_private *priv = netdev_priv(dev);
3386 *mode = priv->iw_mode;
3390 static int orinoco_ioctl_getiwrange(struct net_device *dev,
3391 struct iw_request_info *info,
3392 struct iw_point *rrq,
3395 struct orinoco_private *priv = netdev_priv(dev);
3397 struct iw_range *range = (struct iw_range *) extra;
3401 rrq->length = sizeof(struct iw_range);
3402 memset(range, 0, sizeof(struct iw_range));
3404 range->we_version_compiled = WIRELESS_EXT;
3405 range->we_version_source = 14;
3407 /* Set available channels/frequencies */
3408 range->num_channels = NUM_CHANNELS;
3410 for (i = 0; i < NUM_CHANNELS; i++) {
3411 if (priv->channel_mask & (1 << i)) {
3412 range->freq[k].i = i + 1;
3413 range->freq[k].m = channel_frequency[i] * 100000;
3414 range->freq[k].e = 1;
3418 if (k >= IW_MAX_FREQUENCIES)
3421 range->num_frequency = k;
3422 range->sensitivity = 3;
3424 if (priv->has_wep) {
3425 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
3426 range->encoding_size[0] = SMALL_KEY_SIZE;
3427 range->num_encoding_sizes = 1;
3429 if (priv->has_big_wep) {
3430 range->encoding_size[1] = LARGE_KEY_SIZE;
3431 range->num_encoding_sizes = 2;
3435 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
3436 /* Quality stats meaningless in ad-hoc mode */
3438 range->max_qual.qual = 0x8b - 0x2f;
3439 range->max_qual.level = 0x2f - 0x95 - 1;
3440 range->max_qual.noise = 0x2f - 0x95 - 1;
3441 /* Need to get better values */
3442 range->avg_qual.qual = 0x24;
3443 range->avg_qual.level = 0xC2;
3444 range->avg_qual.noise = 0x9E;
3447 err = orinoco_hw_get_bitratelist(priv, &numrates,
3448 range->bitrate, IW_MAX_BITRATES);
3451 range->num_bitrates = numrates;
3453 /* Set an indication of the max TCP throughput in bit/s that we can
3454 * expect using this interface. May be use for QoS stuff...
3457 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
3459 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
3462 range->max_rts = 2347;
3463 range->min_frag = 256;
3464 range->max_frag = 2346;
3467 range->max_pmp = 65535000;
3469 range->max_pmt = 65535 * 1000; /* ??? */
3470 range->pmp_flags = IW_POWER_PERIOD;
3471 range->pmt_flags = IW_POWER_TIMEOUT;
3472 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
3474 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
3475 range->retry_flags = IW_RETRY_LIMIT;
3476 range->r_time_flags = IW_RETRY_LIFETIME;
3477 range->min_retry = 0;
3478 range->max_retry = 65535; /* ??? */
3479 range->min_r_time = 0;
3480 range->max_r_time = 65535 * 1000; /* ??? */
3482 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
3483 range->scan_capa = IW_SCAN_CAPA_ESSID;
3485 range->scan_capa = IW_SCAN_CAPA_NONE;
3487 /* Event capability (kernel) */
3488 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
3489 /* Event capability (driver) */
3490 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
3491 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
3492 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
3493 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
3498 static int orinoco_ioctl_setiwencode(struct net_device *dev,
3499 struct iw_request_info *info,
3500 struct iw_point *erq,
3503 struct orinoco_private *priv = netdev_priv(dev);
3504 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3505 int setindex = priv->tx_key;
3506 int encode_alg = priv->encode_alg;
3507 int restricted = priv->wep_restrict;
3509 int err = -EINPROGRESS; /* Call commit handler */
3510 unsigned long flags;
3512 if (! priv->has_wep)
3516 /* We actually have a key to set - check its length */
3517 if (erq->length > LARGE_KEY_SIZE)
3520 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
3524 if (orinoco_lock(priv, &flags) != 0)
3527 if (erq->length > 0) {
3528 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3529 index = priv->tx_key;
3531 /* Adjust key length to a supported value */
3532 if (erq->length > SMALL_KEY_SIZE) {
3533 xlen = LARGE_KEY_SIZE;
3534 } else if (erq->length > 0) {
3535 xlen = SMALL_KEY_SIZE;
3539 /* Switch on WEP if off */
3540 if ((encode_alg != IW_ENCODE_ALG_WEP) && (xlen > 0)) {
3542 encode_alg = IW_ENCODE_ALG_WEP;
3545 /* Important note : if the user do "iwconfig eth0 enc off",
3546 * we will arrive there with an index of -1. This is valid
3547 * but need to be taken care off... Jean II */
3548 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
3549 if((index != -1) || (erq->flags == 0)) {
3554 /* Set the index : Check that the key is valid */
3555 if(priv->keys[index].len == 0) {
3563 if (erq->flags & IW_ENCODE_DISABLED)
3564 encode_alg = IW_ENCODE_ALG_NONE;
3565 if (erq->flags & IW_ENCODE_OPEN)
3567 if (erq->flags & IW_ENCODE_RESTRICTED)
3570 if (erq->pointer && erq->length > 0) {
3571 priv->keys[index].len = cpu_to_le16(xlen);
3572 memset(priv->keys[index].data, 0,
3573 sizeof(priv->keys[index].data));
3574 memcpy(priv->keys[index].data, keybuf, erq->length);
3576 priv->tx_key = setindex;
3578 /* Try fast key change if connected and only keys are changed */
3579 if ((priv->encode_alg == encode_alg) &&
3580 (priv->wep_restrict == restricted) &&
3581 netif_carrier_ok(dev)) {
3582 err = __orinoco_hw_setup_wepkeys(priv);
3583 /* No need to commit if successful */
3587 priv->encode_alg = encode_alg;
3588 priv->wep_restrict = restricted;
3591 orinoco_unlock(priv, &flags);
3596 static int orinoco_ioctl_getiwencode(struct net_device *dev,
3597 struct iw_request_info *info,
3598 struct iw_point *erq,
3601 struct orinoco_private *priv = netdev_priv(dev);
3602 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3604 unsigned long flags;
3606 if (! priv->has_wep)
3609 if (orinoco_lock(priv, &flags) != 0)
3612 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3613 index = priv->tx_key;
3616 if (!priv->encode_alg)
3617 erq->flags |= IW_ENCODE_DISABLED;
3618 erq->flags |= index + 1;
3620 if (priv->wep_restrict)
3621 erq->flags |= IW_ENCODE_RESTRICTED;
3623 erq->flags |= IW_ENCODE_OPEN;
3625 xlen = le16_to_cpu(priv->keys[index].len);
3629 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3631 orinoco_unlock(priv, &flags);
3635 static int orinoco_ioctl_setessid(struct net_device *dev,
3636 struct iw_request_info *info,
3637 struct iw_point *erq,
3640 struct orinoco_private *priv = netdev_priv(dev);
3641 unsigned long flags;
3643 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3644 * anyway... - Jean II */
3646 /* Hum... Should not use Wireless Extension constant (may change),
3647 * should use our own... - Jean II */
3648 if (erq->length > IW_ESSID_MAX_SIZE)
3651 if (orinoco_lock(priv, &flags) != 0)
3654 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3655 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3657 /* If not ANY, get the new ESSID */
3659 memcpy(priv->desired_essid, essidbuf, erq->length);
3662 orinoco_unlock(priv, &flags);
3664 return -EINPROGRESS; /* Call commit handler */
3667 static int orinoco_ioctl_getessid(struct net_device *dev,
3668 struct iw_request_info *info,
3669 struct iw_point *erq,
3672 struct orinoco_private *priv = netdev_priv(dev);
3675 unsigned long flags;
3677 if (netif_running(dev)) {
3678 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3683 if (orinoco_lock(priv, &flags) != 0)
3685 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
3686 erq->length = strlen(priv->desired_essid);
3687 orinoco_unlock(priv, &flags);
3695 static int orinoco_ioctl_setnick(struct net_device *dev,
3696 struct iw_request_info *info,
3697 struct iw_point *nrq,
3700 struct orinoco_private *priv = netdev_priv(dev);
3701 unsigned long flags;
3703 if (nrq->length > IW_ESSID_MAX_SIZE)
3706 if (orinoco_lock(priv, &flags) != 0)
3709 memset(priv->nick, 0, sizeof(priv->nick));
3710 memcpy(priv->nick, nickbuf, nrq->length);
3712 orinoco_unlock(priv, &flags);
3714 return -EINPROGRESS; /* Call commit handler */
3717 static int orinoco_ioctl_getnick(struct net_device *dev,
3718 struct iw_request_info *info,
3719 struct iw_point *nrq,
3722 struct orinoco_private *priv = netdev_priv(dev);
3723 unsigned long flags;
3725 if (orinoco_lock(priv, &flags) != 0)
3728 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
3729 orinoco_unlock(priv, &flags);
3731 nrq->length = strlen(priv->nick);
3736 static int orinoco_ioctl_setfreq(struct net_device *dev,
3737 struct iw_request_info *info,
3738 struct iw_freq *frq,
3741 struct orinoco_private *priv = netdev_priv(dev);
3743 unsigned long flags;
3744 int err = -EINPROGRESS; /* Call commit handler */
3746 /* In infrastructure mode the AP sets the channel */
3747 if (priv->iw_mode == IW_MODE_INFRA)
3750 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3751 /* Setting by channel number */
3754 /* Setting by frequency - search the table */
3758 for (i = 0; i < (6 - frq->e); i++)
3761 for (i = 0; i < NUM_CHANNELS; i++)
3762 if (frq->m == (channel_frequency[i] * mult))
3766 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3767 ! (priv->channel_mask & (1 << (chan-1)) ) )
3770 if (orinoco_lock(priv, &flags) != 0)
3773 priv->channel = chan;
3774 if (priv->iw_mode == IW_MODE_MONITOR) {
3775 /* Fast channel change - no commit if successful */
3776 hermes_t *hw = &priv->hw;
3777 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3778 HERMES_TEST_SET_CHANNEL,
3781 orinoco_unlock(priv, &flags);
3786 static int orinoco_ioctl_getfreq(struct net_device *dev,
3787 struct iw_request_info *info,
3788 struct iw_freq *frq,
3791 struct orinoco_private *priv = netdev_priv(dev);
3794 /* Locking done in there */
3795 tmp = orinoco_hw_get_freq(priv);
3806 static int orinoco_ioctl_getsens(struct net_device *dev,
3807 struct iw_request_info *info,
3808 struct iw_param *srq,
3811 struct orinoco_private *priv = netdev_priv(dev);
3812 hermes_t *hw = &priv->hw;
3815 unsigned long flags;
3817 if (!priv->has_sensitivity)
3820 if (orinoco_lock(priv, &flags) != 0)
3822 err = hermes_read_wordrec(hw, USER_BAP,
3823 HERMES_RID_CNFSYSTEMSCALE, &val);
3824 orinoco_unlock(priv, &flags);
3830 srq->fixed = 0; /* auto */
3835 static int orinoco_ioctl_setsens(struct net_device *dev,
3836 struct iw_request_info *info,
3837 struct iw_param *srq,
3840 struct orinoco_private *priv = netdev_priv(dev);
3841 int val = srq->value;
3842 unsigned long flags;
3844 if (!priv->has_sensitivity)
3847 if ((val < 1) || (val > 3))
3850 if (orinoco_lock(priv, &flags) != 0)
3852 priv->ap_density = val;
3853 orinoco_unlock(priv, &flags);
3855 return -EINPROGRESS; /* Call commit handler */
3858 static int orinoco_ioctl_setrts(struct net_device *dev,
3859 struct iw_request_info *info,
3860 struct iw_param *rrq,
3863 struct orinoco_private *priv = netdev_priv(dev);
3864 int val = rrq->value;
3865 unsigned long flags;
3870 if ( (val < 0) || (val > 2347) )
3873 if (orinoco_lock(priv, &flags) != 0)
3876 priv->rts_thresh = val;
3877 orinoco_unlock(priv, &flags);
3879 return -EINPROGRESS; /* Call commit handler */
3882 static int orinoco_ioctl_getrts(struct net_device *dev,
3883 struct iw_request_info *info,
3884 struct iw_param *rrq,
3887 struct orinoco_private *priv = netdev_priv(dev);
3889 rrq->value = priv->rts_thresh;
3890 rrq->disabled = (rrq->value == 2347);
3896 static int orinoco_ioctl_setfrag(struct net_device *dev,
3897 struct iw_request_info *info,
3898 struct iw_param *frq,
3901 struct orinoco_private *priv = netdev_priv(dev);
3902 int err = -EINPROGRESS; /* Call commit handler */
3903 unsigned long flags;
3905 if (orinoco_lock(priv, &flags) != 0)
3908 if (priv->has_mwo) {
3910 priv->mwo_robust = 0;
3913 printk(KERN_WARNING "%s: Fixed fragmentation is "
3914 "not supported on this firmware. "
3915 "Using MWO robust instead.\n", dev->name);
3916 priv->mwo_robust = 1;
3920 priv->frag_thresh = 2346;
3922 if ( (frq->value < 256) || (frq->value > 2346) )
3925 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3929 orinoco_unlock(priv, &flags);
3934 static int orinoco_ioctl_getfrag(struct net_device *dev,
3935 struct iw_request_info *info,
3936 struct iw_param *frq,
3939 struct orinoco_private *priv = netdev_priv(dev);
3940 hermes_t *hw = &priv->hw;
3943 unsigned long flags;
3945 if (orinoco_lock(priv, &flags) != 0)
3948 if (priv->has_mwo) {
3949 err = hermes_read_wordrec(hw, USER_BAP,
3950 HERMES_RID_CNFMWOROBUST_AGERE,
3955 frq->value = val ? 2347 : 0;
3956 frq->disabled = ! val;
3959 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3965 frq->disabled = (val >= 2346);
3969 orinoco_unlock(priv, &flags);
3974 static int orinoco_ioctl_setrate(struct net_device *dev,
3975 struct iw_request_info *info,
3976 struct iw_param *rrq,
3979 struct orinoco_private *priv = netdev_priv(dev);
3981 int bitrate; /* 100s of kilobits */
3983 unsigned long flags;
3985 /* As the user space doesn't know our highest rate, it uses -1
3986 * to ask us to set the highest rate. Test it using "iwconfig
3987 * ethX rate auto" - Jean II */
3988 if (rrq->value == -1)
3991 if (rrq->value % 100000)
3993 bitrate = rrq->value / 100000;
3996 if ( (bitrate != 10) && (bitrate != 20) &&
3997 (bitrate != 55) && (bitrate != 110) )
4000 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
4001 if ( (bitrate_table[i].bitrate == bitrate) &&
4002 (bitrate_table[i].automatic == ! rrq->fixed) ) {
4010 if (orinoco_lock(priv, &flags) != 0)
4012 priv->bitratemode = ratemode;
4013 orinoco_unlock(priv, &flags);
4015 return -EINPROGRESS;
4018 static int orinoco_ioctl_getrate(struct net_device *dev,
4019 struct iw_request_info *info,
4020 struct iw_param *rrq,
4023 struct orinoco_private *priv = netdev_priv(dev);
4024 hermes_t *hw = &priv->hw;
4029 unsigned long flags;
4031 if (orinoco_lock(priv, &flags) != 0)
4034 ratemode = priv->bitratemode;
4036 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
4038 rrq->value = bitrate_table[ratemode].bitrate * 100000;
4039 rrq->fixed = ! bitrate_table[ratemode].automatic;
4042 /* If the interface is running we try to find more about the
4044 if (netif_running(dev)) {
4045 err = hermes_read_wordrec(hw, USER_BAP,
4046 HERMES_RID_CURRENTTXRATE, &val);
4050 switch (priv->firmware_type) {
4051 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
4052 /* Note : in Lucent firmware, the return value of
4053 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
4054 * and therefore is totally different from the
4055 * encoding of HERMES_RID_CNFTXRATECONTROL.
4056 * Don't forget that 6Mb/s is really 5.5Mb/s */
4058 rrq->value = 5500000;
4060 rrq->value = val * 1000000;
4062 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
4063 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
4064 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
4065 if (bitrate_table[i].intersil_txratectrl == val) {
4069 if (i >= BITRATE_TABLE_SIZE)
4070 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
4073 rrq->value = bitrate_table[ratemode].bitrate * 100000;
4081 orinoco_unlock(priv, &flags);
4086 static int orinoco_ioctl_setpower(struct net_device *dev,
4087 struct iw_request_info *info,
4088 struct iw_param *prq,
4091 struct orinoco_private *priv = netdev_priv(dev);
4092 int err = -EINPROGRESS; /* Call commit handler */
4093 unsigned long flags;
4095 if (orinoco_lock(priv, &flags) != 0)
4098 if (prq->disabled) {
4101 switch (prq->flags & IW_POWER_MODE) {
4102 case IW_POWER_UNICAST_R:
4106 case IW_POWER_ALL_R:
4111 /* No flags : but we may have a value - Jean II */
4118 if (prq->flags & IW_POWER_TIMEOUT) {
4120 priv->pm_timeout = prq->value / 1000;
4122 if (prq->flags & IW_POWER_PERIOD) {
4124 priv->pm_period = prq->value / 1000;
4126 /* It's valid to not have a value if we are just toggling
4127 * the flags... Jean II */
4135 orinoco_unlock(priv, &flags);
4140 static int orinoco_ioctl_getpower(struct net_device *dev,
4141 struct iw_request_info *info,
4142 struct iw_param *prq,
4145 struct orinoco_private *priv = netdev_priv(dev);
4146 hermes_t *hw = &priv->hw;
4148 u16 enable, period, timeout, mcast;
4149 unsigned long flags;
4151 if (orinoco_lock(priv, &flags) != 0)
4154 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
4158 err = hermes_read_wordrec(hw, USER_BAP,
4159 HERMES_RID_CNFMAXSLEEPDURATION, &period);
4163 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
4167 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
4171 prq->disabled = !enable;
4172 /* Note : by default, display the period */
4173 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
4174 prq->flags = IW_POWER_TIMEOUT;
4175 prq->value = timeout * 1000;
4177 prq->flags = IW_POWER_PERIOD;
4178 prq->value = period * 1000;
4181 prq->flags |= IW_POWER_ALL_R;
4183 prq->flags |= IW_POWER_UNICAST_R;
4186 orinoco_unlock(priv, &flags);
4191 static int orinoco_ioctl_getretry(struct net_device *dev,
4192 struct iw_request_info *info,
4193 struct iw_param *rrq,
4196 struct orinoco_private *priv = netdev_priv(dev);
4197 hermes_t *hw = &priv->hw;
4199 u16 short_limit, long_limit, lifetime;
4200 unsigned long flags;
4202 if (orinoco_lock(priv, &flags) != 0)
4205 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
4210 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
4215 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
4220 rrq->disabled = 0; /* Can't be disabled */
4222 /* Note : by default, display the retry number */
4223 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
4224 rrq->flags = IW_RETRY_LIFETIME;
4225 rrq->value = lifetime * 1000; /* ??? */
4227 /* By default, display the min number */
4228 if ((rrq->flags & IW_RETRY_LONG)) {
4229 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
4230 rrq->value = long_limit;
4232 rrq->flags = IW_RETRY_LIMIT;
4233 rrq->value = short_limit;
4234 if(short_limit != long_limit)
4235 rrq->flags |= IW_RETRY_SHORT;
4240 orinoco_unlock(priv, &flags);
4245 static int orinoco_ioctl_reset(struct net_device *dev,
4246 struct iw_request_info *info,
4250 struct orinoco_private *priv = netdev_priv(dev);
4252 if (! capable(CAP_NET_ADMIN))
4255 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
4256 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
4258 /* Firmware reset */
4259 orinoco_reset(&priv->reset_work);
4261 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
4263 schedule_work(&priv->reset_work);
4269 static int orinoco_ioctl_setibssport(struct net_device *dev,
4270 struct iw_request_info *info,
4275 struct orinoco_private *priv = netdev_priv(dev);
4276 int val = *( (int *) extra );
4277 unsigned long flags;
4279 if (orinoco_lock(priv, &flags) != 0)
4282 priv->ibss_port = val ;
4284 /* Actually update the mode we are using */
4285 set_port_type(priv);
4287 orinoco_unlock(priv, &flags);
4288 return -EINPROGRESS; /* Call commit handler */
4291 static int orinoco_ioctl_getibssport(struct net_device *dev,
4292 struct iw_request_info *info,
4296 struct orinoco_private *priv = netdev_priv(dev);
4297 int *val = (int *) extra;
4299 *val = priv->ibss_port;
4303 static int orinoco_ioctl_setport3(struct net_device *dev,
4304 struct iw_request_info *info,
4308 struct orinoco_private *priv = netdev_priv(dev);
4309 int val = *( (int *) extra );
4311 unsigned long flags;
4313 if (orinoco_lock(priv, &flags) != 0)
4317 case 0: /* Try to do IEEE ad-hoc mode */
4318 if (! priv->has_ibss) {
4322 priv->prefer_port3 = 0;
4326 case 1: /* Try to do Lucent proprietary ad-hoc mode */
4327 if (! priv->has_port3) {
4331 priv->prefer_port3 = 1;
4339 /* Actually update the mode we are using */
4340 set_port_type(priv);
4344 orinoco_unlock(priv, &flags);
4349 static int orinoco_ioctl_getport3(struct net_device *dev,
4350 struct iw_request_info *info,
4354 struct orinoco_private *priv = netdev_priv(dev);
4355 int *val = (int *) extra;
4357 *val = priv->prefer_port3;
4361 static int orinoco_ioctl_setpreamble(struct net_device *dev,
4362 struct iw_request_info *info,
4366 struct orinoco_private *priv = netdev_priv(dev);
4367 unsigned long flags;
4370 if (! priv->has_preamble)
4373 /* 802.11b has recently defined some short preamble.
4374 * Basically, the Phy header has been reduced in size.
4375 * This increase performance, especially at high rates
4376 * (the preamble is transmitted at 1Mb/s), unfortunately
4377 * this give compatibility troubles... - Jean II */
4378 val = *( (int *) extra );
4380 if (orinoco_lock(priv, &flags) != 0)
4388 orinoco_unlock(priv, &flags);
4390 return -EINPROGRESS; /* Call commit handler */
4393 static int orinoco_ioctl_getpreamble(struct net_device *dev,
4394 struct iw_request_info *info,
4398 struct orinoco_private *priv = netdev_priv(dev);
4399 int *val = (int *) extra;
4401 if (! priv->has_preamble)
4404 *val = priv->preamble;
4408 /* ioctl interface to hermes_read_ltv()
4409 * To use with iwpriv, pass the RID as the token argument, e.g.
4410 * iwpriv get_rid [0xfc00]
4411 * At least Wireless Tools 25 is required to use iwpriv.
4412 * For Wireless Tools 25 and 26 append "dummy" are the end. */
4413 static int orinoco_ioctl_getrid(struct net_device *dev,
4414 struct iw_request_info *info,
4415 struct iw_point *data,
4418 struct orinoco_private *priv = netdev_priv(dev);
4419 hermes_t *hw = &priv->hw;
4420 int rid = data->flags;
4423 unsigned long flags;
4425 /* It's a "get" function, but we don't want users to access the
4426 * WEP key and other raw firmware data */
4427 if (! capable(CAP_NET_ADMIN))
4430 if (rid < 0xfc00 || rid > 0xffff)
4433 if (orinoco_lock(priv, &flags) != 0)
4436 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
4441 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
4445 orinoco_unlock(priv, &flags);
4449 /* Trigger a scan (look for other cells in the vicinity) */
4450 static int orinoco_ioctl_setscan(struct net_device *dev,
4451 struct iw_request_info *info,
4452 struct iw_param *srq,
4455 struct orinoco_private *priv = netdev_priv(dev);
4456 hermes_t *hw = &priv->hw;
4457 struct iw_scan_req *si = (struct iw_scan_req *) extra;
4459 unsigned long flags;
4461 /* Note : you may have realised that, as this is a SET operation,
4462 * this is privileged and therefore a normal user can't
4464 * This is not an error, while the device perform scanning,
4465 * traffic doesn't flow, so it's a perfect DoS...
4468 if (orinoco_lock(priv, &flags) != 0)
4471 /* Scanning with port 0 disabled would fail */
4472 if (!netif_running(dev)) {
4477 /* In monitor mode, the scan results are always empty.
4478 * Probe responses are passed to the driver as received
4479 * frames and could be processed in software. */
4480 if (priv->iw_mode == IW_MODE_MONITOR) {
4485 /* Note : because we don't lock out the irq handler, the way
4486 * we access scan variables in priv is critical.
4487 * o scan_inprogress : not touched by irq handler
4488 * o scan_mode : not touched by irq handler
4489 * Before modifying anything on those variables, please think hard !
4493 priv->scan_mode = srq->flags;
4495 /* Always trigger scanning, even if it's in progress.
4496 * This way, if the info frame get lost, we will recover somewhat
4497 * gracefully - Jean II */
4499 if (priv->has_hostscan) {
4500 switch (priv->firmware_type) {
4501 case FIRMWARE_TYPE_SYMBOL:
4502 err = hermes_write_wordrec(hw, USER_BAP,
4503 HERMES_RID_CNFHOSTSCAN_SYMBOL,
4504 HERMES_HOSTSCAN_SYMBOL_ONCE |
4505 HERMES_HOSTSCAN_SYMBOL_BCAST);
4507 case FIRMWARE_TYPE_INTERSIL: {
4510 req[0] = cpu_to_le16(0x3fff); /* All channels */
4511 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
4512 req[2] = 0; /* Any ESSID */
4513 err = HERMES_WRITE_RECORD(hw, USER_BAP,
4514 HERMES_RID_CNFHOSTSCAN, &req);
4517 case FIRMWARE_TYPE_AGERE:
4518 if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
4519 struct hermes_idstring idbuf;
4520 size_t len = min(sizeof(idbuf.val),
4521 (size_t) si->essid_len);
4522 idbuf.len = cpu_to_le16(len);
4523 memcpy(idbuf.val, si->essid, len);
4525 err = hermes_write_ltv(hw, USER_BAP,
4526 HERMES_RID_CNFSCANSSID_AGERE,
4527 HERMES_BYTES_TO_RECLEN(len + 2),
4530 err = hermes_write_wordrec(hw, USER_BAP,
4531 HERMES_RID_CNFSCANSSID_AGERE,
4536 if (priv->has_ext_scan) {
4537 /* Clear scan results at the start of
4538 * an extended scan */
4539 orinoco_clear_scan_results(priv,
4540 msecs_to_jiffies(15000));
4542 /* TODO: Is this available on older firmware?
4543 * Can we use it to scan specific channels
4544 * for IW_SCAN_THIS_FREQ? */
4545 err = hermes_write_wordrec(hw, USER_BAP,
4546 HERMES_RID_CNFSCANCHANNELS2GHZ,
4551 err = hermes_inquire(hw,
4552 HERMES_INQ_CHANNELINFO);
4554 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4558 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4560 /* One more client */
4562 priv->scan_inprogress = 1;
4565 orinoco_unlock(priv, &flags);
4569 #define MAX_CUSTOM_LEN 64
4571 /* Translate scan data returned from the card to a card independant
4572 * format that the Wireless Tools will understand - Jean II */
4573 static inline char *orinoco_translate_scan(struct net_device *dev,
4574 struct iw_request_info *info,
4577 union hermes_scan_info *bss,
4578 unsigned int last_scanned)
4580 struct orinoco_private *priv = netdev_priv(dev);
4583 struct iw_event iwe; /* Temporary buffer */
4584 char custom[MAX_CUSTOM_LEN];
4586 memset(&iwe, 0, sizeof(iwe));
4588 /* First entry *MUST* be the AP MAC address */
4589 iwe.cmd = SIOCGIWAP;
4590 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4591 memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
4592 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4593 &iwe, IW_EV_ADDR_LEN);
4595 /* Other entries will be displayed in the order we give them */
4598 iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
4599 if (iwe.u.data.length > 32)
4600 iwe.u.data.length = 32;
4601 iwe.cmd = SIOCGIWESSID;
4602 iwe.u.data.flags = 1;
4603 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4604 &iwe, bss->a.essid);
4607 iwe.cmd = SIOCGIWMODE;
4608 capabilities = le16_to_cpu(bss->a.capabilities);
4609 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
4610 if (capabilities & WLAN_CAPABILITY_ESS)
4611 iwe.u.mode = IW_MODE_MASTER;
4613 iwe.u.mode = IW_MODE_ADHOC;
4614 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4615 &iwe, IW_EV_UINT_LEN);
4618 channel = bss->s.channel;
4619 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
4620 /* Add channel and frequency */
4621 iwe.cmd = SIOCGIWFREQ;
4622 iwe.u.freq.m = channel;
4624 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4625 &iwe, IW_EV_FREQ_LEN);
4627 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4629 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4630 &iwe, IW_EV_FREQ_LEN);
4633 /* Add quality statistics. level and noise in dB. No link quality */
4635 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
4636 iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
4637 iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
4638 /* Wireless tools prior to 27.pre22 will show link quality
4639 * anyway, so we provide a reasonable value. */
4640 if (iwe.u.qual.level > iwe.u.qual.noise)
4641 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4643 iwe.u.qual.qual = 0;
4644 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4645 &iwe, IW_EV_QUAL_LEN);
4647 /* Add encryption capability */
4648 iwe.cmd = SIOCGIWENCODE;
4649 if (capabilities & WLAN_CAPABILITY_PRIVACY)
4650 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4652 iwe.u.data.flags = IW_ENCODE_DISABLED;
4653 iwe.u.data.length = 0;
4654 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4657 /* Bit rate is not available in Lucent/Agere firmwares */
4658 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4659 char *current_val = current_ev + iwe_stream_lcp_len(info);
4663 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4668 iwe.cmd = SIOCGIWRATE;
4669 /* Those two flags are ignored... */
4670 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4672 for (i = 0; i < 10; i += step) {
4673 /* NULL terminated */
4674 if (bss->p.rates[i] == 0x0)
4676 /* Bit rate given in 500 kb/s units (+ 0x80) */
4677 iwe.u.bitrate.value =
4678 ((bss->p.rates[i] & 0x7f) * 500000);
4679 current_val = iwe_stream_add_value(info, current_ev,
4684 /* Check if we added any event */
4685 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
4686 current_ev = current_val;
4689 /* Beacon interval */
4690 iwe.cmd = IWEVCUSTOM;
4691 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4693 le16_to_cpu(bss->a.beacon_interv));
4694 if (iwe.u.data.length)
4695 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4699 iwe.cmd = IWEVCUSTOM;
4700 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4703 if (iwe.u.data.length)
4704 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4707 /* Add EXTRA: Age to display seconds since last beacon/probe response
4708 * for given network. */
4709 iwe.cmd = IWEVCUSTOM;
4710 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4711 " Last beacon: %dms ago",
4712 jiffies_to_msecs(jiffies - last_scanned));
4713 if (iwe.u.data.length)
4714 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4720 static inline char *orinoco_translate_ext_scan(struct net_device *dev,
4721 struct iw_request_info *info,
4724 struct agere_ext_scan_info *bss,
4725 unsigned int last_scanned)
4729 struct iw_event iwe; /* Temporary buffer */
4730 char custom[MAX_CUSTOM_LEN];
4733 memset(&iwe, 0, sizeof(iwe));
4735 /* First entry *MUST* be the AP MAC address */
4736 iwe.cmd = SIOCGIWAP;
4737 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4738 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
4739 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4740 &iwe, IW_EV_ADDR_LEN);
4742 /* Other entries will be displayed in the order we give them */
4746 iwe.u.data.length = ie[1];
4747 if (iwe.u.data.length) {
4748 if (iwe.u.data.length > 32)
4749 iwe.u.data.length = 32;
4750 iwe.cmd = SIOCGIWESSID;
4751 iwe.u.data.flags = 1;
4752 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4757 capabilities = le16_to_cpu(bss->capabilities);
4758 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
4759 iwe.cmd = SIOCGIWMODE;
4760 if (capabilities & WLAN_CAPABILITY_ESS)
4761 iwe.u.mode = IW_MODE_MASTER;
4763 iwe.u.mode = IW_MODE_ADHOC;
4764 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4765 &iwe, IW_EV_UINT_LEN);
4768 ie = orinoco_get_ie(bss->data, sizeof(bss->data), MFIE_TYPE_DS_SET);
4769 channel = ie ? ie[2] : 0;
4770 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
4771 /* Add channel and frequency */
4772 iwe.cmd = SIOCGIWFREQ;
4773 iwe.u.freq.m = channel;
4775 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4776 &iwe, IW_EV_FREQ_LEN);
4778 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4780 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4781 &iwe, IW_EV_FREQ_LEN);
4784 /* Add quality statistics. level and noise in dB. No link quality */
4786 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
4787 iwe.u.qual.level = bss->level - 0x95;
4788 iwe.u.qual.noise = bss->noise - 0x95;
4789 /* Wireless tools prior to 27.pre22 will show link quality
4790 * anyway, so we provide a reasonable value. */
4791 if (iwe.u.qual.level > iwe.u.qual.noise)
4792 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4794 iwe.u.qual.qual = 0;
4795 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4796 &iwe, IW_EV_QUAL_LEN);
4798 /* Add encryption capability */
4799 iwe.cmd = SIOCGIWENCODE;
4800 if (capabilities & WLAN_CAPABILITY_PRIVACY)
4801 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4803 iwe.u.data.flags = IW_ENCODE_DISABLED;
4804 iwe.u.data.length = 0;
4805 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4809 ie = orinoco_get_wpa_ie(bss->data, sizeof(bss->data));
4811 iwe.cmd = IWEVGENIE;
4812 iwe.u.data.length = ie[1] + 2;
4813 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4818 ie = orinoco_get_ie(bss->data, sizeof(bss->data), MFIE_TYPE_RSN);
4820 iwe.cmd = IWEVGENIE;
4821 iwe.u.data.length = ie[1] + 2;
4822 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4826 ie = orinoco_get_ie(bss->data, sizeof(bss->data), MFIE_TYPE_RATES);
4828 char *p = current_ev + iwe_stream_lcp_len(info);
4831 iwe.cmd = SIOCGIWRATE;
4832 /* Those two flags are ignored... */
4833 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4835 for (i = 2; i < (ie[1] + 2); i++) {
4836 iwe.u.bitrate.value = ((ie[i] & 0x7F) * 500000);
4837 p = iwe_stream_add_value(info, current_ev, p, end_buf,
4838 &iwe, IW_EV_PARAM_LEN);
4840 /* Check if we added any event */
4841 if (p > (current_ev + iwe_stream_lcp_len(info)))
4846 iwe.cmd = IWEVCUSTOM;
4847 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4849 le64_to_cpu(bss->timestamp));
4850 if (iwe.u.data.length)
4851 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4854 /* Beacon interval */
4855 iwe.cmd = IWEVCUSTOM;
4856 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4858 le16_to_cpu(bss->beacon_interval));
4859 if (iwe.u.data.length)
4860 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4864 iwe.cmd = IWEVCUSTOM;
4865 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4868 if (iwe.u.data.length)
4869 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4872 /* Add EXTRA: Age to display seconds since last beacon/probe response
4873 * for given network. */
4874 iwe.cmd = IWEVCUSTOM;
4875 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4876 " Last beacon: %dms ago",
4877 jiffies_to_msecs(jiffies - last_scanned));
4878 if (iwe.u.data.length)
4879 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4885 /* Return results of a scan */
4886 static int orinoco_ioctl_getscan(struct net_device *dev,
4887 struct iw_request_info *info,
4888 struct iw_point *srq,
4891 struct orinoco_private *priv = netdev_priv(dev);
4893 unsigned long flags;
4894 char *current_ev = extra;
4896 if (orinoco_lock(priv, &flags) != 0)
4899 if (priv->scan_inprogress) {
4900 /* Important note : we don't want to block the caller
4901 * until results are ready for various reasons.
4902 * First, managing wait queues is complex and racy.
4903 * Second, we grab some rtnetlink lock before comming
4904 * here (in dev_ioctl()).
4905 * Third, we generate an Wireless Event, so the
4906 * caller can wait itself on that - Jean II */
4911 if (priv->has_ext_scan) {
4912 struct xbss_element *bss;
4914 list_for_each_entry(bss, &priv->bss_list, list) {
4915 /* Translate this entry to WE format */
4917 orinoco_translate_ext_scan(dev, info,
4919 extra + srq->length,
4923 /* Check if there is space for one more entry */
4924 if ((extra + srq->length - current_ev)
4925 <= IW_EV_ADDR_LEN) {
4926 /* Ask user space to try again with a
4934 struct bss_element *bss;
4936 list_for_each_entry(bss, &priv->bss_list, list) {
4937 /* Translate this entry to WE format */
4938 current_ev = orinoco_translate_scan(dev, info,
4940 extra + srq->length,
4944 /* Check if there is space for one more entry */
4945 if ((extra + srq->length - current_ev)
4946 <= IW_EV_ADDR_LEN) {
4947 /* Ask user space to try again with a
4955 srq->length = (current_ev - extra);
4956 srq->flags = (__u16) priv->scan_mode;
4959 orinoco_unlock(priv, &flags);
4963 /* Commit handler, called after set operations */
4964 static int orinoco_ioctl_commit(struct net_device *dev,
4965 struct iw_request_info *info,
4969 struct orinoco_private *priv = netdev_priv(dev);
4970 struct hermes *hw = &priv->hw;
4971 unsigned long flags;
4977 if (priv->broken_disableport) {
4978 orinoco_reset(&priv->reset_work);
4982 if (orinoco_lock(priv, &flags) != 0)
4985 err = hermes_disable_port(hw, 0);
4987 printk(KERN_WARNING "%s: Unable to disable port "
4988 "while reconfiguring card\n", dev->name);
4989 priv->broken_disableport = 1;
4993 err = __orinoco_program_rids(dev);
4995 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
5000 err = hermes_enable_port(hw, 0);
5002 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
5009 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
5010 schedule_work(&priv->reset_work);
5014 orinoco_unlock(priv, &flags);
5018 static const struct iw_priv_args orinoco_privtab[] = {
5019 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
5020 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
5021 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5023 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5025 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5026 0, "set_preamble" },
5027 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5029 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5030 0, "set_ibssport" },
5031 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
5033 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
5039 * Structures to export the Wireless Handlers
5042 static const iw_handler orinoco_handler[] = {
5043 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
5044 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
5045 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
5046 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
5047 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
5048 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
5049 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
5050 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
5051 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
5052 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
5053 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
5054 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
5055 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
5056 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
5057 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
5058 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
5059 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
5060 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
5061 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
5062 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
5063 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
5064 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
5065 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
5066 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
5067 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
5068 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
5069 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
5070 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
5071 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
5072 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
5073 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
5074 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
5079 Added typecasting since we no longer use iwreq_data -- Moustafa
5081 static const iw_handler orinoco_private_handler[] = {
5082 [0] = (iw_handler) orinoco_ioctl_reset,
5083 [1] = (iw_handler) orinoco_ioctl_reset,
5084 [2] = (iw_handler) orinoco_ioctl_setport3,
5085 [3] = (iw_handler) orinoco_ioctl_getport3,
5086 [4] = (iw_handler) orinoco_ioctl_setpreamble,
5087 [5] = (iw_handler) orinoco_ioctl_getpreamble,
5088 [6] = (iw_handler) orinoco_ioctl_setibssport,
5089 [7] = (iw_handler) orinoco_ioctl_getibssport,
5090 [9] = (iw_handler) orinoco_ioctl_getrid,
5093 static const struct iw_handler_def orinoco_handler_def = {
5094 .num_standard = ARRAY_SIZE(orinoco_handler),
5095 .num_private = ARRAY_SIZE(orinoco_private_handler),
5096 .num_private_args = ARRAY_SIZE(orinoco_privtab),
5097 .standard = orinoco_handler,
5098 .private = orinoco_private_handler,
5099 .private_args = orinoco_privtab,
5100 .get_wireless_stats = orinoco_get_wireless_stats,
5103 static void orinoco_get_drvinfo(struct net_device *dev,
5104 struct ethtool_drvinfo *info)
5106 struct orinoco_private *priv = netdev_priv(dev);
5108 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
5109 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
5110 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
5111 if (dev->dev.parent)
5112 strncpy(info->bus_info, dev->dev.parent->bus_id,
5113 sizeof(info->bus_info) - 1);
5115 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
5116 "PCMCIA %p", priv->hw.iobase);
5119 static const struct ethtool_ops orinoco_ethtool_ops = {
5120 .get_drvinfo = orinoco_get_drvinfo,
5121 .get_link = ethtool_op_get_link,
5124 /********************************************************************/
5125 /* Module initialization */
5126 /********************************************************************/
5128 EXPORT_SYMBOL(alloc_orinocodev);
5129 EXPORT_SYMBOL(free_orinocodev);
5131 EXPORT_SYMBOL(__orinoco_up);
5132 EXPORT_SYMBOL(__orinoco_down);
5133 EXPORT_SYMBOL(orinoco_reinit_firmware);
5135 EXPORT_SYMBOL(orinoco_interrupt);
5137 /* Can't be declared "const" or the whole __initdata section will
5139 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
5140 " (David Gibson <hermes@gibson.dropbear.id.au>, "
5141 "Pavel Roskin <proski@gnu.org>, et al)";
5143 static int __init init_orinoco(void)
5145 printk(KERN_DEBUG "%s\n", version);
5149 static void __exit exit_orinoco(void)
5153 module_init(init_orinoco);
5154 module_exit(exit_orinoco);