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)
282 kzalloc(ORINOCO_MAX_BSS_COUNT * sizeof(struct bss_element),
284 if (!priv->bss_data) {
285 printk(KERN_WARNING "Out of memory allocating beacons");
291 static void orinoco_bss_data_free(struct orinoco_private *priv)
293 kfree(priv->bss_data);
294 priv->bss_data = NULL;
297 static void orinoco_bss_data_init(struct orinoco_private *priv)
301 INIT_LIST_HEAD(&priv->bss_free_list);
302 INIT_LIST_HEAD(&priv->bss_list);
303 for (i = 0; i < ORINOCO_MAX_BSS_COUNT; i++)
304 list_add_tail(&priv->bss_data[i].list, &priv->bss_free_list);
308 /********************************************************************/
309 /* Download functionality */
310 /********************************************************************/
320 const static struct fw_info orinoco_fw[] = {
321 { "", "agere_sta_fw.bin", "agere_ap_fw.bin", 0x00390000, 1000 },
322 { "", "prism_sta_fw.bin", "prism_ap_fw.bin", 0, 1024 },
323 { "symbol_sp24t_prim_fw", "symbol_sp24t_sec_fw", "", 0x00003100, 0x100 }
326 /* Structure used to access fields in FW
327 * Make sure LE decoding macros are used
329 struct orinoco_fw_header {
330 char hdr_vers[6]; /* ASCII string for header version */
331 __le16 headersize; /* Total length of header */
332 __le32 entry_point; /* NIC entry point */
333 __le32 blocks; /* Number of blocks to program */
334 __le32 block_offset; /* Offset of block data from eof header */
335 __le32 pdr_offset; /* Offset to PDR data from eof header */
336 __le32 pri_offset; /* Offset to primary plug data */
337 __le32 compat_offset; /* Offset to compatibility data*/
338 char signature[0]; /* FW signature length headersize-20 */
339 } __attribute__ ((packed));
341 /* Download either STA or AP firmware into the card. */
343 orinoco_dl_firmware(struct orinoco_private *priv,
344 const struct fw_info *fw,
347 /* Plug Data Area (PDA) */
348 __le16 pda[512] = { 0 };
350 hermes_t *hw = &priv->hw;
351 const struct firmware *fw_entry;
352 const struct orinoco_fw_header *hdr;
353 const unsigned char *first_block;
354 const unsigned char *end;
355 const char *firmware;
356 struct net_device *dev = priv->ndev;
360 firmware = fw->ap_fw;
362 firmware = fw->sta_fw;
364 printk(KERN_DEBUG "%s: Attempting to download firmware %s\n",
365 dev->name, firmware);
367 /* Read current plug data */
368 err = hermes_read_pda(hw, pda, fw->pda_addr,
369 min_t(u16, fw->pda_size, sizeof(pda)), 0);
370 printk(KERN_DEBUG "%s: Read PDA returned %d\n", dev->name, err);
374 err = request_firmware(&fw_entry, firmware, priv->dev);
376 printk(KERN_ERR "%s: Cannot find firmware %s\n",
377 dev->name, firmware);
381 hdr = (const struct orinoco_fw_header *) fw_entry->data;
383 /* Enable aux port to allow programming */
384 err = hermesi_program_init(hw, le32_to_cpu(hdr->entry_point));
385 printk(KERN_DEBUG "%s: Program init returned %d\n", dev->name, err);
390 first_block = (fw_entry->data +
391 le16_to_cpu(hdr->headersize) +
392 le32_to_cpu(hdr->block_offset));
393 end = fw_entry->data + fw_entry->size;
395 err = hermes_program(hw, first_block, end);
396 printk(KERN_DEBUG "%s: Program returned %d\n", dev->name, err);
400 /* Update production data */
401 first_block = (fw_entry->data +
402 le16_to_cpu(hdr->headersize) +
403 le32_to_cpu(hdr->pdr_offset));
405 err = hermes_apply_pda_with_defaults(hw, first_block, pda);
406 printk(KERN_DEBUG "%s: Apply PDA returned %d\n", dev->name, err);
410 /* Tell card we've finished */
411 err = hermesi_program_end(hw);
412 printk(KERN_DEBUG "%s: Program end returned %d\n", dev->name, err);
416 /* Check if we're running */
417 printk(KERN_DEBUG "%s: hermes_present returned %d\n",
418 dev->name, hermes_present(hw));
421 release_firmware(fw_entry);
426 #define TEXT_END 0x1A /* End of text header */
429 * Process a firmware image - stop the card, load the firmware, reset
430 * the card and make sure it responds. For the secondary firmware take
431 * care of the PDA - read it and then write it on top of the firmware.
434 symbol_dl_image(struct orinoco_private *priv, const struct fw_info *fw,
435 const unsigned char *image, const unsigned char *end,
438 hermes_t *hw = &priv->hw;
440 const unsigned char *ptr;
441 const unsigned char *first_block;
443 /* Plug Data Area (PDA) */
446 /* Binary block begins after the 0x1A marker */
448 while (*ptr++ != TEXT_END);
451 /* Read the PDA from EEPROM */
453 ret = hermes_read_pda(hw, pda, fw->pda_addr, sizeof(pda), 1);
458 /* Stop the firmware, so that it can be safely rewritten */
460 ret = priv->stop_fw(priv, 1);
465 /* Program the adapter with new firmware */
466 ret = hermes_program(hw, first_block, end);
470 /* Write the PDA to the adapter */
472 size_t len = hermes_blocks_length(first_block);
473 ptr = first_block + len;
474 ret = hermes_apply_pda(hw, ptr, pda);
479 /* Run the firmware */
481 ret = priv->stop_fw(priv, 0);
486 /* Reset hermes chip and make sure it responds */
487 ret = hermes_init(hw);
489 /* hermes_reset() should return 0 with the secondary firmware */
490 if (secondary && ret != 0)
493 /* And this should work with any firmware */
494 if (!hermes_present(hw))
502 * Download the firmware into the card, this also does a PCMCIA soft
503 * reset on the card, to make sure it's in a sane state.
506 symbol_dl_firmware(struct orinoco_private *priv,
507 const struct fw_info *fw)
509 struct net_device *dev = priv->ndev;
511 const struct firmware *fw_entry;
513 if (request_firmware(&fw_entry, fw->pri_fw,
515 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
516 dev->name, fw->pri_fw);
520 /* Load primary firmware */
521 ret = symbol_dl_image(priv, fw, fw_entry->data,
522 fw_entry->data + fw_entry->size, 0);
523 release_firmware(fw_entry);
525 printk(KERN_ERR "%s: Primary firmware download failed\n",
530 if (request_firmware(&fw_entry, fw->sta_fw,
532 printk(KERN_ERR "%s: Cannot find firmware: %s\n",
533 dev->name, fw->sta_fw);
537 /* Load secondary firmware */
538 ret = symbol_dl_image(priv, fw, fw_entry->data,
539 fw_entry->data + fw_entry->size, 1);
540 release_firmware(fw_entry);
542 printk(KERN_ERR "%s: Secondary firmware download failed\n",
549 static int orinoco_download(struct orinoco_private *priv)
552 /* Reload firmware */
553 switch (priv->firmware_type) {
554 case FIRMWARE_TYPE_AGERE:
555 /* case FIRMWARE_TYPE_INTERSIL: */
556 err = orinoco_dl_firmware(priv,
557 &orinoco_fw[priv->firmware_type], 0);
560 case FIRMWARE_TYPE_SYMBOL:
561 err = symbol_dl_firmware(priv,
562 &orinoco_fw[priv->firmware_type]);
564 case FIRMWARE_TYPE_INTERSIL:
567 /* TODO: if we fail we probably need to reinitialise
573 /********************************************************************/
575 /********************************************************************/
577 static int orinoco_open(struct net_device *dev)
579 struct orinoco_private *priv = netdev_priv(dev);
583 if (orinoco_lock(priv, &flags) != 0)
586 err = __orinoco_up(dev);
591 orinoco_unlock(priv, &flags);
596 static int orinoco_stop(struct net_device *dev)
598 struct orinoco_private *priv = netdev_priv(dev);
601 /* We mustn't use orinoco_lock() here, because we need to be
602 able to close the interface even if hw_unavailable is set
603 (e.g. as we're released after a PC Card removal) */
604 spin_lock_irq(&priv->lock);
608 err = __orinoco_down(dev);
610 spin_unlock_irq(&priv->lock);
615 static struct net_device_stats *orinoco_get_stats(struct net_device *dev)
617 struct orinoco_private *priv = netdev_priv(dev);
622 static struct iw_statistics *orinoco_get_wireless_stats(struct net_device *dev)
624 struct orinoco_private *priv = netdev_priv(dev);
625 hermes_t *hw = &priv->hw;
626 struct iw_statistics *wstats = &priv->wstats;
630 if (! netif_device_present(dev)) {
631 printk(KERN_WARNING "%s: get_wireless_stats() called while device not present\n",
633 return NULL; /* FIXME: Can we do better than this? */
636 /* If busy, return the old stats. Returning NULL may cause
637 * the interface to disappear from /proc/net/wireless */
638 if (orinoco_lock(priv, &flags) != 0)
641 /* We can't really wait for the tallies inquiry command to
642 * complete, so we just use the previous results and trigger
643 * a new tallies inquiry command for next time - Jean II */
644 /* FIXME: Really we should wait for the inquiry to come back -
645 * as it is the stats we give don't make a whole lot of sense.
646 * Unfortunately, it's not clear how to do that within the
647 * wireless extensions framework: I think we're in user
648 * context, but a lock seems to be held by the time we get in
649 * here so we're not safe to sleep here. */
650 hermes_inquire(hw, HERMES_INQ_TALLIES);
652 if (priv->iw_mode == IW_MODE_ADHOC) {
653 memset(&wstats->qual, 0, sizeof(wstats->qual));
654 /* If a spy address is defined, we report stats of the
655 * first spy address - Jean II */
656 if (SPY_NUMBER(priv)) {
657 wstats->qual.qual = priv->spy_data.spy_stat[0].qual;
658 wstats->qual.level = priv->spy_data.spy_stat[0].level;
659 wstats->qual.noise = priv->spy_data.spy_stat[0].noise;
660 wstats->qual.updated = priv->spy_data.spy_stat[0].updated;
664 __le16 qual, signal, noise, unused;
665 } __attribute__ ((packed)) cq;
667 err = HERMES_READ_RECORD(hw, USER_BAP,
668 HERMES_RID_COMMSQUALITY, &cq);
671 wstats->qual.qual = (int)le16_to_cpu(cq.qual);
672 wstats->qual.level = (int)le16_to_cpu(cq.signal) - 0x95;
673 wstats->qual.noise = (int)le16_to_cpu(cq.noise) - 0x95;
674 wstats->qual.updated = 7;
678 orinoco_unlock(priv, &flags);
682 static void orinoco_set_multicast_list(struct net_device *dev)
684 struct orinoco_private *priv = netdev_priv(dev);
687 if (orinoco_lock(priv, &flags) != 0) {
688 printk(KERN_DEBUG "%s: orinoco_set_multicast_list() "
689 "called when hw_unavailable\n", dev->name);
693 __orinoco_set_multicast_list(dev);
694 orinoco_unlock(priv, &flags);
697 static int orinoco_change_mtu(struct net_device *dev, int new_mtu)
699 struct orinoco_private *priv = netdev_priv(dev);
701 if ( (new_mtu < ORINOCO_MIN_MTU) || (new_mtu > ORINOCO_MAX_MTU) )
704 if ( (new_mtu + ENCAPS_OVERHEAD + IEEE80211_HLEN) >
705 (priv->nicbuf_size - ETH_HLEN) )
713 /********************************************************************/
715 /********************************************************************/
717 static int orinoco_xmit(struct sk_buff *skb, struct net_device *dev)
719 struct orinoco_private *priv = netdev_priv(dev);
720 struct net_device_stats *stats = &priv->stats;
721 hermes_t *hw = &priv->hw;
723 u16 txfid = priv->txfid;
729 if (! netif_running(dev)) {
730 printk(KERN_ERR "%s: Tx on stopped device!\n",
732 return NETDEV_TX_BUSY;
735 if (netif_queue_stopped(dev)) {
736 printk(KERN_DEBUG "%s: Tx while transmitter busy!\n",
738 return NETDEV_TX_BUSY;
741 if (orinoco_lock(priv, &flags) != 0) {
742 printk(KERN_ERR "%s: orinoco_xmit() called while hw_unavailable\n",
744 return NETDEV_TX_BUSY;
747 if (! netif_carrier_ok(dev) || (priv->iw_mode == IW_MODE_MONITOR)) {
748 /* Oops, the firmware hasn't established a connection,
749 silently drop the packet (this seems to be the
754 /* Check packet length */
755 if (skb->len < ETH_HLEN)
758 eh = (struct ethhdr *)skb->data;
760 tx_control = HERMES_TXCTRL_TX_OK | HERMES_TXCTRL_TX_EX;
762 if (priv->has_alt_txcntl) {
763 /* WPA enabled firmwares have tx_cntl at the end of
764 * the 802.11 header. So write zeroed descriptor and
765 * 802.11 header at the same time
767 char desc[HERMES_802_3_OFFSET];
768 __le16 *txcntl = (__le16 *) &desc[HERMES_TXCNTL2_OFFSET];
770 memset(&desc, 0, sizeof(desc));
772 *txcntl = cpu_to_le16(tx_control);
773 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
777 printk(KERN_ERR "%s: Error %d writing Tx "
778 "descriptor to BAP\n", dev->name, err);
782 struct hermes_tx_descriptor desc;
784 memset(&desc, 0, sizeof(desc));
786 desc.tx_control = cpu_to_le16(tx_control);
787 err = hermes_bap_pwrite(hw, USER_BAP, &desc, sizeof(desc),
791 printk(KERN_ERR "%s: Error %d writing Tx "
792 "descriptor to BAP\n", dev->name, err);
796 /* Clear the 802.11 header and data length fields - some
797 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
798 * if this isn't done. */
799 hermes_clear_words(hw, HERMES_DATA0,
800 HERMES_802_3_OFFSET - HERMES_802_11_OFFSET);
803 /* Encapsulate Ethernet-II frames */
804 if (ntohs(eh->h_proto) > ETH_DATA_LEN) { /* Ethernet-II frame */
805 struct header_struct {
806 struct ethhdr eth; /* 802.3 header */
807 u8 encap[6]; /* 802.2 header */
808 } __attribute__ ((packed)) hdr;
810 /* Strip destination and source from the data */
811 skb_pull(skb, 2 * ETH_ALEN);
812 data_off = HERMES_802_2_OFFSET + sizeof(encaps_hdr);
814 /* And move them to a separate header */
815 memcpy(&hdr.eth, eh, 2 * ETH_ALEN);
816 hdr.eth.h_proto = htons(sizeof(encaps_hdr) + skb->len);
817 memcpy(hdr.encap, encaps_hdr, sizeof(encaps_hdr));
819 err = hermes_bap_pwrite(hw, USER_BAP, &hdr, sizeof(hdr),
820 txfid, HERMES_802_3_OFFSET);
823 printk(KERN_ERR "%s: Error %d writing packet "
824 "header to BAP\n", dev->name, err);
827 } else { /* IEEE 802.3 frame */
828 data_off = HERMES_802_3_OFFSET;
831 err = hermes_bap_pwrite(hw, USER_BAP, skb->data, skb->len,
834 printk(KERN_ERR "%s: Error %d writing packet to BAP\n",
839 /* Finally, we actually initiate the send */
840 netif_stop_queue(dev);
842 err = hermes_docmd_wait(hw, HERMES_CMD_TX | HERMES_CMD_RECL,
845 netif_start_queue(dev);
847 printk(KERN_ERR "%s: Error %d transmitting packet\n",
852 dev->trans_start = jiffies;
853 stats->tx_bytes += data_off + skb->len;
861 orinoco_unlock(priv, &flags);
867 schedule_work(&priv->reset_work);
868 orinoco_unlock(priv, &flags);
869 return NETDEV_TX_BUSY;
872 static void __orinoco_ev_alloc(struct net_device *dev, hermes_t *hw)
874 struct orinoco_private *priv = netdev_priv(dev);
875 u16 fid = hermes_read_regn(hw, ALLOCFID);
877 if (fid != priv->txfid) {
878 if (fid != DUMMY_FID)
879 printk(KERN_WARNING "%s: Allocate event on unexpected fid (%04X)\n",
884 hermes_write_regn(hw, ALLOCFID, DUMMY_FID);
887 static void __orinoco_ev_tx(struct net_device *dev, hermes_t *hw)
889 struct orinoco_private *priv = netdev_priv(dev);
890 struct net_device_stats *stats = &priv->stats;
894 netif_wake_queue(dev);
896 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
899 static void __orinoco_ev_txexc(struct net_device *dev, hermes_t *hw)
901 struct orinoco_private *priv = netdev_priv(dev);
902 struct net_device_stats *stats = &priv->stats;
903 u16 fid = hermes_read_regn(hw, TXCOMPLFID);
905 struct hermes_txexc_data hdr;
908 if (fid == DUMMY_FID)
909 return; /* Nothing's really happened */
911 /* Read part of the frame header - we need status and addr1 */
912 err = hermes_bap_pread(hw, IRQ_BAP, &hdr,
913 sizeof(struct hermes_txexc_data),
916 hermes_write_regn(hw, TXCOMPLFID, DUMMY_FID);
920 printk(KERN_WARNING "%s: Unable to read descriptor on Tx error "
921 "(FID=%04X error %d)\n",
922 dev->name, fid, err);
926 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev->name,
929 /* We produce a TXDROP event only for retry or lifetime
930 * exceeded, because that's the only status that really mean
931 * that this particular node went away.
932 * Other errors means that *we* screwed up. - Jean II */
933 status = le16_to_cpu(hdr.desc.status);
934 if (status & (HERMES_TXSTAT_RETRYERR | HERMES_TXSTAT_AGEDERR)) {
935 union iwreq_data wrqu;
937 /* Copy 802.11 dest address.
938 * We use the 802.11 header because the frame may
939 * not be 802.3 or may be mangled...
940 * In Ad-Hoc mode, it will be the node address.
941 * In managed mode, it will be most likely the AP addr
942 * User space will figure out how to convert it to
943 * whatever it needs (IP address or else).
945 memcpy(wrqu.addr.sa_data, hdr.addr1, ETH_ALEN);
946 wrqu.addr.sa_family = ARPHRD_ETHER;
948 /* Send event to user space */
949 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
952 netif_wake_queue(dev);
955 static void orinoco_tx_timeout(struct net_device *dev)
957 struct orinoco_private *priv = netdev_priv(dev);
958 struct net_device_stats *stats = &priv->stats;
959 struct hermes *hw = &priv->hw;
961 printk(KERN_WARNING "%s: Tx timeout! "
962 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
963 dev->name, hermes_read_regn(hw, ALLOCFID),
964 hermes_read_regn(hw, TXCOMPLFID), hermes_read_regn(hw, EVSTAT));
968 schedule_work(&priv->reset_work);
971 /********************************************************************/
972 /* Rx path (data frames) */
973 /********************************************************************/
975 /* Does the frame have a SNAP header indicating it should be
976 * de-encapsulated to Ethernet-II? */
977 static inline int is_ethersnap(void *_hdr)
981 /* We de-encapsulate all packets which, a) have SNAP headers
982 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
983 * and where b) the OUI of the SNAP header is 00:00:00 or
984 * 00:00:f8 - we need both because different APs appear to use
985 * different OUIs for some reason */
986 return (memcmp(hdr, &encaps_hdr, 5) == 0)
987 && ( (hdr[5] == 0x00) || (hdr[5] == 0xf8) );
990 static inline void orinoco_spy_gather(struct net_device *dev, u_char *mac,
991 int level, int noise)
993 struct iw_quality wstats;
994 wstats.level = level - 0x95;
995 wstats.noise = noise - 0x95;
996 wstats.qual = (level > noise) ? (level - noise) : 0;
998 /* Update spy records */
999 wireless_spy_update(dev, mac, &wstats);
1002 static void orinoco_stat_gather(struct net_device *dev,
1003 struct sk_buff *skb,
1004 struct hermes_rx_descriptor *desc)
1006 struct orinoco_private *priv = netdev_priv(dev);
1008 /* Using spy support with lots of Rx packets, like in an
1009 * infrastructure (AP), will really slow down everything, because
1010 * the MAC address must be compared to each entry of the spy list.
1011 * If the user really asks for it (set some address in the
1012 * spy list), we do it, but he will pay the price.
1013 * Note that to get here, you need both WIRELESS_SPY
1014 * compiled in AND some addresses in the list !!!
1016 /* Note : gcc will optimise the whole section away if
1017 * WIRELESS_SPY is not defined... - Jean II */
1018 if (SPY_NUMBER(priv)) {
1019 orinoco_spy_gather(dev, skb_mac_header(skb) + ETH_ALEN,
1020 desc->signal, desc->silence);
1025 * orinoco_rx_monitor - handle received monitor frames.
1028 * dev network device
1029 * rxfid received FID
1030 * desc rx descriptor of the frame
1032 * Call context: interrupt
1034 static void orinoco_rx_monitor(struct net_device *dev, u16 rxfid,
1035 struct hermes_rx_descriptor *desc)
1037 u32 hdrlen = 30; /* return full header by default */
1042 struct sk_buff *skb;
1043 struct orinoco_private *priv = netdev_priv(dev);
1044 struct net_device_stats *stats = &priv->stats;
1045 hermes_t *hw = &priv->hw;
1047 len = le16_to_cpu(desc->data_len);
1049 /* Determine the size of the header and the data */
1050 fc = le16_to_cpu(desc->frame_ctl);
1051 switch (fc & IEEE80211_FCTL_FTYPE) {
1052 case IEEE80211_FTYPE_DATA:
1053 if ((fc & IEEE80211_FCTL_TODS)
1054 && (fc & IEEE80211_FCTL_FROMDS))
1060 case IEEE80211_FTYPE_MGMT:
1064 case IEEE80211_FTYPE_CTL:
1065 switch (fc & IEEE80211_FCTL_STYPE) {
1066 case IEEE80211_STYPE_PSPOLL:
1067 case IEEE80211_STYPE_RTS:
1068 case IEEE80211_STYPE_CFEND:
1069 case IEEE80211_STYPE_CFENDACK:
1072 case IEEE80211_STYPE_CTS:
1073 case IEEE80211_STYPE_ACK:
1079 /* Unknown frame type */
1083 /* sanity check the length */
1084 if (datalen > IEEE80211_DATA_LEN + 12) {
1085 printk(KERN_DEBUG "%s: oversized monitor frame, "
1086 "data length = %d\n", dev->name, datalen);
1087 stats->rx_length_errors++;
1091 skb = dev_alloc_skb(hdrlen + datalen);
1093 printk(KERN_WARNING "%s: Cannot allocate skb for monitor frame\n",
1098 /* Copy the 802.11 header to the skb */
1099 memcpy(skb_put(skb, hdrlen), &(desc->frame_ctl), hdrlen);
1100 skb_reset_mac_header(skb);
1102 /* If any, copy the data from the card to the skb */
1104 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, datalen),
1105 ALIGN(datalen, 2), rxfid,
1106 HERMES_802_2_OFFSET);
1108 printk(KERN_ERR "%s: error %d reading monitor frame\n",
1115 skb->ip_summed = CHECKSUM_NONE;
1116 skb->pkt_type = PACKET_OTHERHOST;
1117 skb->protocol = __constant_htons(ETH_P_802_2);
1119 dev->last_rx = jiffies;
1120 stats->rx_packets++;
1121 stats->rx_bytes += skb->len;
1127 dev_kfree_skb_irq(skb);
1130 stats->rx_dropped++;
1133 static void __orinoco_ev_rx(struct net_device *dev, hermes_t *hw)
1135 struct orinoco_private *priv = netdev_priv(dev);
1136 struct net_device_stats *stats = &priv->stats;
1137 struct iw_statistics *wstats = &priv->wstats;
1138 struct sk_buff *skb = NULL;
1139 u16 rxfid, status, fc;
1141 struct hermes_rx_descriptor desc;
1145 rxfid = hermes_read_regn(hw, RXFID);
1147 err = hermes_bap_pread(hw, IRQ_BAP, &desc, sizeof(desc),
1150 printk(KERN_ERR "%s: error %d reading Rx descriptor. "
1151 "Frame dropped.\n", dev->name, err);
1155 status = le16_to_cpu(desc.status);
1157 if (status & HERMES_RXSTAT_BADCRC) {
1158 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
1160 stats->rx_crc_errors++;
1164 /* Handle frames in monitor mode */
1165 if (priv->iw_mode == IW_MODE_MONITOR) {
1166 orinoco_rx_monitor(dev, rxfid, &desc);
1170 if (status & HERMES_RXSTAT_UNDECRYPTABLE) {
1171 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
1173 wstats->discard.code++;
1177 length = le16_to_cpu(desc.data_len);
1178 fc = le16_to_cpu(desc.frame_ctl);
1181 if (length < 3) { /* No for even an 802.2 LLC header */
1182 /* At least on Symbol firmware with PCF we get quite a
1183 lot of these legitimately - Poll frames with no
1187 if (length > IEEE80211_DATA_LEN) {
1188 printk(KERN_WARNING "%s: Oversized frame received (%d bytes)\n",
1190 stats->rx_length_errors++;
1194 /* We need space for the packet data itself, plus an ethernet
1195 header, plus 2 bytes so we can align the IP header on a
1196 32bit boundary, plus 1 byte so we can read in odd length
1197 packets from the card, which has an IO granularity of 16
1199 skb = dev_alloc_skb(length+ETH_HLEN+2+1);
1201 printk(KERN_WARNING "%s: Can't allocate skb for Rx\n",
1206 /* We'll prepend the header, so reserve space for it. The worst
1207 case is no decapsulation, when 802.3 header is prepended and
1208 nothing is removed. 2 is for aligning the IP header. */
1209 skb_reserve(skb, ETH_HLEN + 2);
1211 err = hermes_bap_pread(hw, IRQ_BAP, skb_put(skb, length),
1212 ALIGN(length, 2), rxfid,
1213 HERMES_802_2_OFFSET);
1215 printk(KERN_ERR "%s: error %d reading frame. "
1216 "Frame dropped.\n", dev->name, err);
1220 /* Handle decapsulation
1221 * In most cases, the firmware tell us about SNAP frames.
1222 * For some reason, the SNAP frames sent by LinkSys APs
1223 * are not properly recognised by most firmwares.
1224 * So, check ourselves */
1225 if (length >= ENCAPS_OVERHEAD &&
1226 (((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_1042) ||
1227 ((status & HERMES_RXSTAT_MSGTYPE) == HERMES_RXSTAT_TUNNEL) ||
1228 is_ethersnap(skb->data))) {
1229 /* These indicate a SNAP within 802.2 LLC within
1230 802.11 frame which we'll need to de-encapsulate to
1231 the original EthernetII frame. */
1232 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN - ENCAPS_OVERHEAD);
1234 /* 802.3 frame - prepend 802.3 header as is */
1235 hdr = (struct ethhdr *)skb_push(skb, ETH_HLEN);
1236 hdr->h_proto = htons(length);
1238 memcpy(hdr->h_dest, desc.addr1, ETH_ALEN);
1239 if (fc & IEEE80211_FCTL_FROMDS)
1240 memcpy(hdr->h_source, desc.addr3, ETH_ALEN);
1242 memcpy(hdr->h_source, desc.addr2, ETH_ALEN);
1244 dev->last_rx = jiffies;
1245 skb->protocol = eth_type_trans(skb, dev);
1246 skb->ip_summed = CHECKSUM_NONE;
1247 if (fc & IEEE80211_FCTL_TODS)
1248 skb->pkt_type = PACKET_OTHERHOST;
1250 /* Process the wireless stats if needed */
1251 orinoco_stat_gather(dev, skb, &desc);
1253 /* Pass the packet to the networking stack */
1255 stats->rx_packets++;
1256 stats->rx_bytes += length;
1261 dev_kfree_skb_irq(skb);
1264 stats->rx_dropped++;
1267 /********************************************************************/
1268 /* Rx path (info frames) */
1269 /********************************************************************/
1271 static void print_linkstatus(struct net_device *dev, u16 status)
1275 if (suppress_linkstatus)
1279 case HERMES_LINKSTATUS_NOT_CONNECTED:
1280 s = "Not Connected";
1282 case HERMES_LINKSTATUS_CONNECTED:
1285 case HERMES_LINKSTATUS_DISCONNECTED:
1288 case HERMES_LINKSTATUS_AP_CHANGE:
1291 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE:
1292 s = "AP Out of Range";
1294 case HERMES_LINKSTATUS_AP_IN_RANGE:
1297 case HERMES_LINKSTATUS_ASSOC_FAILED:
1298 s = "Association Failed";
1304 printk(KERN_INFO "%s: New link status: %s (%04x)\n",
1305 dev->name, s, status);
1308 /* Search scan results for requested BSSID, join it if found */
1309 static void orinoco_join_ap(struct work_struct *work)
1311 struct orinoco_private *priv =
1312 container_of(work, struct orinoco_private, join_work);
1313 struct net_device *dev = priv->ndev;
1314 struct hermes *hw = &priv->hw;
1316 unsigned long flags;
1320 } __attribute__ ((packed)) req;
1321 const int atom_len = offsetof(struct prism2_scan_apinfo, atim);
1322 struct prism2_scan_apinfo *atom = NULL;
1328 /* Allocate buffer for scan results */
1329 buf = kmalloc(MAX_SCAN_LEN, GFP_KERNEL);
1333 if (orinoco_lock(priv, &flags) != 0)
1336 /* Sanity checks in case user changed something in the meantime */
1337 if (! priv->bssid_fixed)
1340 if (strlen(priv->desired_essid) == 0)
1343 /* Read scan results from the firmware */
1344 err = hermes_read_ltv(hw, USER_BAP,
1345 HERMES_RID_SCANRESULTSTABLE,
1346 MAX_SCAN_LEN, &len, buf);
1348 printk(KERN_ERR "%s: Cannot read scan results\n",
1353 len = HERMES_RECLEN_TO_BYTES(len);
1355 /* Go through the scan results looking for the channel of the AP
1356 * we were requested to join */
1357 for (; offset + atom_len <= len; offset += atom_len) {
1358 atom = (struct prism2_scan_apinfo *) (buf + offset);
1359 if (memcmp(&atom->bssid, priv->desired_bssid, ETH_ALEN) == 0) {
1366 DEBUG(1, "%s: Requested AP not found in scan results\n",
1371 memcpy(req.bssid, priv->desired_bssid, ETH_ALEN);
1372 req.channel = atom->channel; /* both are little-endian */
1373 err = HERMES_WRITE_RECORD(hw, USER_BAP, HERMES_RID_CNFJOINREQUEST,
1376 printk(KERN_ERR "%s: Error issuing join request\n", dev->name);
1379 orinoco_unlock(priv, &flags);
1385 /* Send new BSSID to userspace */
1386 static void orinoco_send_wevents(struct work_struct *work)
1388 struct orinoco_private *priv =
1389 container_of(work, struct orinoco_private, wevent_work);
1390 struct net_device *dev = priv->ndev;
1391 struct hermes *hw = &priv->hw;
1392 union iwreq_data wrqu;
1394 unsigned long flags;
1396 if (orinoco_lock(priv, &flags) != 0)
1399 err = hermes_read_ltv(hw, IRQ_BAP, HERMES_RID_CURRENTBSSID,
1400 ETH_ALEN, NULL, wrqu.ap_addr.sa_data);
1404 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1406 /* Send event to user space */
1407 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
1410 orinoco_unlock(priv, &flags);
1414 static inline void orinoco_clear_scan_results(struct orinoco_private *priv,
1415 unsigned long scan_age)
1417 struct bss_element *bss;
1418 struct bss_element *tmp_bss;
1420 /* Blow away current list of scan results */
1421 list_for_each_entry_safe(bss, tmp_bss, &priv->bss_list, list) {
1423 time_after(jiffies, bss->last_scanned + scan_age)) {
1424 list_move_tail(&bss->list, &priv->bss_free_list);
1425 /* Don't blow away ->list, just BSS data */
1426 memset(bss, 0, sizeof(bss->bss));
1427 bss->last_scanned = 0;
1432 static int orinoco_process_scan_results(struct net_device *dev,
1436 struct orinoco_private *priv = netdev_priv(dev);
1437 int offset; /* In the scan data */
1438 union hermes_scan_info *atom;
1441 switch (priv->firmware_type) {
1442 case FIRMWARE_TYPE_AGERE:
1443 atom_len = sizeof(struct agere_scan_apinfo);
1446 case FIRMWARE_TYPE_SYMBOL:
1447 /* Lack of documentation necessitates this hack.
1448 * Different firmwares have 68 or 76 byte long atoms.
1449 * We try modulo first. If the length divides by both,
1450 * we check what would be the channel in the second
1451 * frame for a 68-byte atom. 76-byte atoms have 0 there.
1452 * Valid channel cannot be 0. */
1457 else if (len >= 1292 && buf[68] == 0)
1463 case FIRMWARE_TYPE_INTERSIL:
1465 if (priv->has_hostscan) {
1466 atom_len = le16_to_cpup((__le16 *)buf);
1467 /* Sanity check for atom_len */
1468 if (atom_len < sizeof(struct prism2_scan_apinfo)) {
1469 printk(KERN_ERR "%s: Invalid atom_len in scan "
1470 "data: %d\n", dev->name, atom_len);
1474 atom_len = offsetof(struct prism2_scan_apinfo, atim);
1480 /* Check that we got an whole number of atoms */
1481 if ((len - offset) % atom_len) {
1482 printk(KERN_ERR "%s: Unexpected scan data length %d, "
1483 "atom_len %d, offset %d\n", dev->name, len,
1488 orinoco_clear_scan_results(priv, msecs_to_jiffies(15000));
1490 /* Read the entries one by one */
1491 for (; offset + atom_len <= len; offset += atom_len) {
1493 struct bss_element *bss = NULL;
1496 atom = (union hermes_scan_info *) (buf + offset);
1498 /* Try to update an existing bss first */
1499 list_for_each_entry(bss, &priv->bss_list, list) {
1500 if (compare_ether_addr(bss->bss.a.bssid, atom->a.bssid))
1502 if (le16_to_cpu(bss->bss.a.essid_len) !=
1503 le16_to_cpu(atom->a.essid_len))
1505 if (memcmp(bss->bss.a.essid, atom->a.essid,
1506 le16_to_cpu(atom->a.essid_len)))
1512 /* Grab a bss off the free list */
1513 if (!found && !list_empty(&priv->bss_free_list)) {
1514 bss = list_entry(priv->bss_free_list.next,
1515 struct bss_element, list);
1516 list_del(priv->bss_free_list.next);
1518 list_add_tail(&bss->list, &priv->bss_list);
1522 /* Always update the BSS to get latest beacon info */
1523 memcpy(&bss->bss, atom, sizeof(bss->bss));
1524 bss->last_scanned = jiffies;
1531 static void __orinoco_ev_info(struct net_device *dev, hermes_t *hw)
1533 struct orinoco_private *priv = netdev_priv(dev);
1538 } __attribute__ ((packed)) info;
1542 /* This is an answer to an INQUIRE command that we did earlier,
1543 * or an information "event" generated by the card
1544 * The controller return to us a pseudo frame containing
1545 * the information in question - Jean II */
1546 infofid = hermes_read_regn(hw, INFOFID);
1548 /* Read the info frame header - don't try too hard */
1549 err = hermes_bap_pread(hw, IRQ_BAP, &info, sizeof(info),
1552 printk(KERN_ERR "%s: error %d reading info frame. "
1553 "Frame dropped.\n", dev->name, err);
1557 len = HERMES_RECLEN_TO_BYTES(le16_to_cpu(info.len));
1558 type = le16_to_cpu(info.type);
1561 case HERMES_INQ_TALLIES: {
1562 struct hermes_tallies_frame tallies;
1563 struct iw_statistics *wstats = &priv->wstats;
1565 if (len > sizeof(tallies)) {
1566 printk(KERN_WARNING "%s: Tallies frame too long (%d bytes)\n",
1568 len = sizeof(tallies);
1571 err = hermes_bap_pread(hw, IRQ_BAP, &tallies, len,
1572 infofid, sizeof(info));
1576 /* Increment our various counters */
1577 /* wstats->discard.nwid - no wrong BSSID stuff */
1578 wstats->discard.code +=
1579 le16_to_cpu(tallies.RxWEPUndecryptable);
1580 if (len == sizeof(tallies))
1581 wstats->discard.code +=
1582 le16_to_cpu(tallies.RxDiscards_WEPICVError) +
1583 le16_to_cpu(tallies.RxDiscards_WEPExcluded);
1584 wstats->discard.misc +=
1585 le16_to_cpu(tallies.TxDiscardsWrongSA);
1586 wstats->discard.fragment +=
1587 le16_to_cpu(tallies.RxMsgInBadMsgFragments);
1588 wstats->discard.retries +=
1589 le16_to_cpu(tallies.TxRetryLimitExceeded);
1590 /* wstats->miss.beacon - no match */
1593 case HERMES_INQ_LINKSTATUS: {
1594 struct hermes_linkstatus linkstatus;
1598 if (priv->iw_mode == IW_MODE_MONITOR)
1601 if (len != sizeof(linkstatus)) {
1602 printk(KERN_WARNING "%s: Unexpected size for linkstatus frame (%d bytes)\n",
1607 err = hermes_bap_pread(hw, IRQ_BAP, &linkstatus, len,
1608 infofid, sizeof(info));
1611 newstatus = le16_to_cpu(linkstatus.linkstatus);
1613 /* Symbol firmware uses "out of range" to signal that
1614 * the hostscan frame can be requested. */
1615 if (newstatus == HERMES_LINKSTATUS_AP_OUT_OF_RANGE &&
1616 priv->firmware_type == FIRMWARE_TYPE_SYMBOL &&
1617 priv->has_hostscan && priv->scan_inprogress) {
1618 hermes_inquire(hw, HERMES_INQ_HOSTSCAN_SYMBOL);
1622 connected = (newstatus == HERMES_LINKSTATUS_CONNECTED)
1623 || (newstatus == HERMES_LINKSTATUS_AP_CHANGE)
1624 || (newstatus == HERMES_LINKSTATUS_AP_IN_RANGE);
1627 netif_carrier_on(dev);
1628 else if (!ignore_disconnect)
1629 netif_carrier_off(dev);
1631 if (newstatus != priv->last_linkstatus) {
1632 priv->last_linkstatus = newstatus;
1633 print_linkstatus(dev, newstatus);
1634 /* The info frame contains only one word which is the
1635 * status (see hermes.h). The status is pretty boring
1636 * in itself, that's why we export the new BSSID...
1638 schedule_work(&priv->wevent_work);
1642 case HERMES_INQ_SCAN:
1643 if (!priv->scan_inprogress && priv->bssid_fixed &&
1644 priv->firmware_type == FIRMWARE_TYPE_INTERSIL) {
1645 schedule_work(&priv->join_work);
1649 case HERMES_INQ_HOSTSCAN:
1650 case HERMES_INQ_HOSTSCAN_SYMBOL: {
1651 /* Result of a scanning. Contains information about
1652 * cells in the vicinity - Jean II */
1653 union iwreq_data wrqu;
1656 /* Scan is no longer in progress */
1657 priv->scan_inprogress = 0;
1661 printk(KERN_WARNING "%s: Scan results too large (%d bytes)\n",
1666 /* Allocate buffer for results */
1667 buf = kmalloc(len, GFP_ATOMIC);
1669 /* No memory, so can't printk()... */
1672 /* Read scan data */
1673 err = hermes_bap_pread(hw, IRQ_BAP, (void *) buf, len,
1674 infofid, sizeof(info));
1680 #ifdef ORINOCO_DEBUG
1683 printk(KERN_DEBUG "Scan result [%02X", buf[0]);
1684 for(i = 1; i < (len * 2); i++)
1685 printk(":%02X", buf[i]);
1688 #endif /* ORINOCO_DEBUG */
1690 if (orinoco_process_scan_results(dev, buf, len) == 0) {
1691 /* Send an empty event to user space.
1692 * We don't send the received data on the event because
1693 * it would require us to do complex transcoding, and
1694 * we want to minimise the work done in the irq handler
1695 * Use a request to extract the data - Jean II */
1696 wrqu.data.length = 0;
1697 wrqu.data.flags = 0;
1698 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
1703 case HERMES_INQ_SEC_STAT_AGERE:
1704 /* Security status (Agere specific) */
1705 /* Ignore this frame for now */
1706 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
1710 printk(KERN_DEBUG "%s: Unknown information frame received: "
1711 "type 0x%04x, length %d\n", dev->name, type, len);
1712 /* We don't actually do anything about it */
1717 static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
1719 if (net_ratelimit())
1720 printk(KERN_DEBUG "%s: Information frame lost.\n", dev->name);
1723 /********************************************************************/
1724 /* Internal hardware control routines */
1725 /********************************************************************/
1727 int __orinoco_up(struct net_device *dev)
1729 struct orinoco_private *priv = netdev_priv(dev);
1730 struct hermes *hw = &priv->hw;
1733 netif_carrier_off(dev); /* just to make sure */
1735 err = __orinoco_program_rids(dev);
1737 printk(KERN_ERR "%s: Error %d configuring card\n",
1742 /* Fire things up again */
1743 hermes_set_irqmask(hw, ORINOCO_INTEN);
1744 err = hermes_enable_port(hw, 0);
1746 printk(KERN_ERR "%s: Error %d enabling MAC port\n",
1751 netif_start_queue(dev);
1756 int __orinoco_down(struct net_device *dev)
1758 struct orinoco_private *priv = netdev_priv(dev);
1759 struct hermes *hw = &priv->hw;
1762 netif_stop_queue(dev);
1764 if (! priv->hw_unavailable) {
1765 if (! priv->broken_disableport) {
1766 err = hermes_disable_port(hw, 0);
1768 /* Some firmwares (e.g. Intersil 1.3.x) seem
1769 * to have problems disabling the port, oh
1771 printk(KERN_WARNING "%s: Error %d disabling MAC port\n",
1773 priv->broken_disableport = 1;
1776 hermes_set_irqmask(hw, 0);
1777 hermes_write_regn(hw, EVACK, 0xffff);
1780 /* firmware will have to reassociate */
1781 netif_carrier_off(dev);
1782 priv->last_linkstatus = 0xffff;
1787 static int orinoco_allocate_fid(struct net_device *dev)
1789 struct orinoco_private *priv = netdev_priv(dev);
1790 struct hermes *hw = &priv->hw;
1793 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1794 if (err == -EIO && priv->nicbuf_size > TX_NICBUF_SIZE_BUG) {
1795 /* Try workaround for old Symbol firmware bug */
1796 printk(KERN_WARNING "%s: firmware ALLOC bug detected "
1797 "(old Symbol firmware?). Trying to work around... ",
1800 priv->nicbuf_size = TX_NICBUF_SIZE_BUG;
1801 err = hermes_allocate(hw, priv->nicbuf_size, &priv->txfid);
1803 printk("failed!\n");
1811 int orinoco_reinit_firmware(struct net_device *dev)
1813 struct orinoco_private *priv = netdev_priv(dev);
1814 struct hermes *hw = &priv->hw;
1817 err = hermes_init(hw);
1819 err = orinoco_allocate_fid(dev);
1824 static int __orinoco_hw_set_bitrate(struct orinoco_private *priv)
1826 hermes_t *hw = &priv->hw;
1829 if (priv->bitratemode >= BITRATE_TABLE_SIZE) {
1830 printk(KERN_ERR "%s: BUG: Invalid bitrate mode %d\n",
1831 priv->ndev->name, priv->bitratemode);
1835 switch (priv->firmware_type) {
1836 case FIRMWARE_TYPE_AGERE:
1837 err = hermes_write_wordrec(hw, USER_BAP,
1838 HERMES_RID_CNFTXRATECONTROL,
1839 bitrate_table[priv->bitratemode].agere_txratectrl);
1841 case FIRMWARE_TYPE_INTERSIL:
1842 case FIRMWARE_TYPE_SYMBOL:
1843 err = hermes_write_wordrec(hw, USER_BAP,
1844 HERMES_RID_CNFTXRATECONTROL,
1845 bitrate_table[priv->bitratemode].intersil_txratectrl);
1854 /* Set fixed AP address */
1855 static int __orinoco_hw_set_wap(struct orinoco_private *priv)
1859 hermes_t *hw = &priv->hw;
1861 switch (priv->firmware_type) {
1862 case FIRMWARE_TYPE_AGERE:
1865 case FIRMWARE_TYPE_INTERSIL:
1866 if (priv->bssid_fixed)
1871 err = hermes_write_wordrec(hw, USER_BAP,
1872 HERMES_RID_CNFROAMINGMODE,
1875 case FIRMWARE_TYPE_SYMBOL:
1876 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1877 HERMES_RID_CNFMANDATORYBSSID_SYMBOL,
1878 &priv->desired_bssid);
1884 /* Change the WEP keys and/or the current keys. Can be called
1885 * either from __orinoco_hw_setup_wep() or directly from
1886 * orinoco_ioctl_setiwencode(). In the later case the association
1887 * with the AP is not broken (if the firmware can handle it),
1888 * which is needed for 802.1x implementations. */
1889 static int __orinoco_hw_setup_wepkeys(struct orinoco_private *priv)
1891 hermes_t *hw = &priv->hw;
1894 switch (priv->firmware_type) {
1895 case FIRMWARE_TYPE_AGERE:
1896 err = HERMES_WRITE_RECORD(hw, USER_BAP,
1897 HERMES_RID_CNFWEPKEYS_AGERE,
1901 err = hermes_write_wordrec(hw, USER_BAP,
1902 HERMES_RID_CNFTXKEY_AGERE,
1907 case FIRMWARE_TYPE_INTERSIL:
1908 case FIRMWARE_TYPE_SYMBOL:
1913 /* Force uniform key length to work around firmware bugs */
1914 keylen = le16_to_cpu(priv->keys[priv->tx_key].len);
1916 if (keylen > LARGE_KEY_SIZE) {
1917 printk(KERN_ERR "%s: BUG: Key %d has oversize length %d.\n",
1918 priv->ndev->name, priv->tx_key, keylen);
1922 /* Write all 4 keys */
1923 for(i = 0; i < ORINOCO_MAX_KEYS; i++) {
1924 err = hermes_write_ltv(hw, USER_BAP,
1925 HERMES_RID_CNFDEFAULTKEY0 + i,
1926 HERMES_BYTES_TO_RECLEN(keylen),
1927 priv->keys[i].data);
1932 /* Write the index of the key used in transmission */
1933 err = hermes_write_wordrec(hw, USER_BAP,
1934 HERMES_RID_CNFWEPDEFAULTKEYID,
1945 static int __orinoco_hw_setup_wep(struct orinoco_private *priv)
1947 hermes_t *hw = &priv->hw;
1949 int master_wep_flag;
1953 __orinoco_hw_setup_wepkeys(priv);
1955 if (priv->wep_restrict)
1956 auth_flag = HERMES_AUTH_SHARED_KEY;
1958 auth_flag = HERMES_AUTH_OPEN;
1960 switch (priv->firmware_type) {
1961 case FIRMWARE_TYPE_AGERE: /* Agere style WEP */
1963 /* Enable the shared-key authentication. */
1964 err = hermes_write_wordrec(hw, USER_BAP,
1965 HERMES_RID_CNFAUTHENTICATION_AGERE,
1968 err = hermes_write_wordrec(hw, USER_BAP,
1969 HERMES_RID_CNFWEPENABLED_AGERE,
1975 case FIRMWARE_TYPE_INTERSIL: /* Intersil style WEP */
1976 case FIRMWARE_TYPE_SYMBOL: /* Symbol style WEP */
1978 if (priv->wep_restrict ||
1979 (priv->firmware_type == FIRMWARE_TYPE_SYMBOL))
1980 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED |
1981 HERMES_WEP_EXCL_UNENCRYPTED;
1983 master_wep_flag = HERMES_WEP_PRIVACY_INVOKED;
1985 err = hermes_write_wordrec(hw, USER_BAP,
1986 HERMES_RID_CNFAUTHENTICATION,
1991 master_wep_flag = 0;
1993 if (priv->iw_mode == IW_MODE_MONITOR)
1994 master_wep_flag |= HERMES_WEP_HOST_DECRYPT;
1996 /* Master WEP setting : on/off */
1997 err = hermes_write_wordrec(hw, USER_BAP,
1998 HERMES_RID_CNFWEPFLAGS_INTERSIL,
2009 static int __orinoco_program_rids(struct net_device *dev)
2011 struct orinoco_private *priv = netdev_priv(dev);
2012 hermes_t *hw = &priv->hw;
2014 struct hermes_idstring idbuf;
2016 /* Set the MAC address */
2017 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2018 HERMES_BYTES_TO_RECLEN(ETH_ALEN), dev->dev_addr);
2020 printk(KERN_ERR "%s: Error %d setting MAC address\n",
2025 /* Set up the link mode */
2026 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFPORTTYPE,
2029 printk(KERN_ERR "%s: Error %d setting port type\n",
2033 /* Set the channel/frequency */
2034 if (priv->channel != 0 && priv->iw_mode != IW_MODE_INFRA) {
2035 err = hermes_write_wordrec(hw, USER_BAP,
2036 HERMES_RID_CNFOWNCHANNEL,
2039 printk(KERN_ERR "%s: Error %d setting channel %d\n",
2040 dev->name, err, priv->channel);
2045 if (priv->has_ibss) {
2048 if ((strlen(priv->desired_essid) == 0) && (priv->createibss)) {
2049 printk(KERN_WARNING "%s: This firmware requires an "
2050 "ESSID in IBSS-Ad-Hoc mode.\n", dev->name);
2051 /* With wvlan_cs, in this case, we would crash.
2052 * hopefully, this driver will behave better...
2056 createibss = priv->createibss;
2059 err = hermes_write_wordrec(hw, USER_BAP,
2060 HERMES_RID_CNFCREATEIBSS,
2063 printk(KERN_ERR "%s: Error %d setting CREATEIBSS\n",
2069 /* Set the desired BSSID */
2070 err = __orinoco_hw_set_wap(priv);
2072 printk(KERN_ERR "%s: Error %d setting AP address\n",
2076 /* Set the desired ESSID */
2077 idbuf.len = cpu_to_le16(strlen(priv->desired_essid));
2078 memcpy(&idbuf.val, priv->desired_essid, sizeof(idbuf.val));
2079 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
2080 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNSSID,
2081 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2084 printk(KERN_ERR "%s: Error %d setting OWNSSID\n",
2088 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFDESIREDSSID,
2089 HERMES_BYTES_TO_RECLEN(strlen(priv->desired_essid)+2),
2092 printk(KERN_ERR "%s: Error %d setting DESIREDSSID\n",
2097 /* Set the station name */
2098 idbuf.len = cpu_to_le16(strlen(priv->nick));
2099 memcpy(&idbuf.val, priv->nick, sizeof(idbuf.val));
2100 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2101 HERMES_BYTES_TO_RECLEN(strlen(priv->nick)+2),
2104 printk(KERN_ERR "%s: Error %d setting nickname\n",
2109 /* Set AP density */
2110 if (priv->has_sensitivity) {
2111 err = hermes_write_wordrec(hw, USER_BAP,
2112 HERMES_RID_CNFSYSTEMSCALE,
2115 printk(KERN_WARNING "%s: Error %d setting SYSTEMSCALE. "
2116 "Disabling sensitivity control\n",
2119 priv->has_sensitivity = 0;
2123 /* Set RTS threshold */
2124 err = hermes_write_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2127 printk(KERN_ERR "%s: Error %d setting RTS threshold\n",
2132 /* Set fragmentation threshold or MWO robustness */
2134 err = hermes_write_wordrec(hw, USER_BAP,
2135 HERMES_RID_CNFMWOROBUST_AGERE,
2138 err = hermes_write_wordrec(hw, USER_BAP,
2139 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2142 printk(KERN_ERR "%s: Error %d setting fragmentation\n",
2148 err = __orinoco_hw_set_bitrate(priv);
2150 printk(KERN_ERR "%s: Error %d setting bitrate\n",
2155 /* Set power management */
2157 err = hermes_write_wordrec(hw, USER_BAP,
2158 HERMES_RID_CNFPMENABLED,
2161 printk(KERN_ERR "%s: Error %d setting up PM\n",
2166 err = hermes_write_wordrec(hw, USER_BAP,
2167 HERMES_RID_CNFMULTICASTRECEIVE,
2170 printk(KERN_ERR "%s: Error %d setting up PM\n",
2174 err = hermes_write_wordrec(hw, USER_BAP,
2175 HERMES_RID_CNFMAXSLEEPDURATION,
2178 printk(KERN_ERR "%s: Error %d setting up PM\n",
2182 err = hermes_write_wordrec(hw, USER_BAP,
2183 HERMES_RID_CNFPMHOLDOVERDURATION,
2186 printk(KERN_ERR "%s: Error %d setting up PM\n",
2192 /* Set preamble - only for Symbol so far... */
2193 if (priv->has_preamble) {
2194 err = hermes_write_wordrec(hw, USER_BAP,
2195 HERMES_RID_CNFPREAMBLE_SYMBOL,
2198 printk(KERN_ERR "%s: Error %d setting preamble\n",
2204 /* Set up encryption */
2205 if (priv->has_wep) {
2206 err = __orinoco_hw_setup_wep(priv);
2208 printk(KERN_ERR "%s: Error %d activating WEP\n",
2214 if (priv->iw_mode == IW_MODE_MONITOR) {
2215 /* Enable monitor mode */
2216 dev->type = ARPHRD_IEEE80211;
2217 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2218 HERMES_TEST_MONITOR, 0, NULL);
2220 /* Disable monitor mode */
2221 dev->type = ARPHRD_ETHER;
2222 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
2223 HERMES_TEST_STOP, 0, NULL);
2228 /* Set promiscuity / multicast*/
2229 priv->promiscuous = 0;
2232 /* FIXME: what about netif_tx_lock */
2233 __orinoco_set_multicast_list(dev);
2238 /* FIXME: return int? */
2240 __orinoco_set_multicast_list(struct net_device *dev)
2242 struct orinoco_private *priv = netdev_priv(dev);
2243 hermes_t *hw = &priv->hw;
2245 int promisc, mc_count;
2247 /* The Hermes doesn't seem to have an allmulti mode, so we go
2248 * into promiscuous mode and let the upper levels deal. */
2249 if ( (dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI) ||
2250 (dev->mc_count > MAX_MULTICAST(priv)) ) {
2255 mc_count = dev->mc_count;
2258 if (promisc != priv->promiscuous) {
2259 err = hermes_write_wordrec(hw, USER_BAP,
2260 HERMES_RID_CNFPROMISCUOUSMODE,
2263 printk(KERN_ERR "%s: Error %d setting PROMISCUOUSMODE to 1.\n",
2266 priv->promiscuous = promisc;
2269 if (! promisc && (mc_count || priv->mc_count) ) {
2270 struct dev_mc_list *p = dev->mc_list;
2271 struct hermes_multicast mclist;
2274 for (i = 0; i < mc_count; i++) {
2275 /* paranoia: is list shorter than mc_count? */
2277 /* paranoia: bad address size in list? */
2278 BUG_ON(p->dmi_addrlen != ETH_ALEN);
2280 memcpy(mclist.addr[i], p->dmi_addr, ETH_ALEN);
2285 printk(KERN_WARNING "%s: Multicast list is "
2286 "longer than mc_count\n", dev->name);
2288 err = hermes_write_ltv(hw, USER_BAP, HERMES_RID_CNFGROUPADDRESSES,
2289 HERMES_BYTES_TO_RECLEN(priv->mc_count * ETH_ALEN),
2292 printk(KERN_ERR "%s: Error %d setting multicast list.\n",
2295 priv->mc_count = mc_count;
2299 /* This must be called from user context, without locks held - use
2300 * schedule_work() */
2301 static void orinoco_reset(struct work_struct *work)
2303 struct orinoco_private *priv =
2304 container_of(work, struct orinoco_private, reset_work);
2305 struct net_device *dev = priv->ndev;
2306 struct hermes *hw = &priv->hw;
2308 unsigned long flags;
2310 if (orinoco_lock(priv, &flags) != 0)
2311 /* When the hardware becomes available again, whatever
2312 * detects that is responsible for re-initializing
2313 * it. So no need for anything further */
2316 netif_stop_queue(dev);
2318 /* Shut off interrupts. Depending on what state the hardware
2319 * is in, this might not work, but we'll try anyway */
2320 hermes_set_irqmask(hw, 0);
2321 hermes_write_regn(hw, EVACK, 0xffff);
2323 priv->hw_unavailable++;
2324 priv->last_linkstatus = 0xffff; /* firmware will have to reassociate */
2325 netif_carrier_off(dev);
2327 orinoco_unlock(priv, &flags);
2329 /* Scanning support: Cleanup of driver struct */
2330 orinoco_clear_scan_results(priv, 0);
2331 priv->scan_inprogress = 0;
2333 if (priv->hard_reset) {
2334 err = (*priv->hard_reset)(priv);
2336 printk(KERN_ERR "%s: orinoco_reset: Error %d "
2337 "performing hard reset\n", dev->name, err);
2342 if (priv->do_fw_download) {
2343 err = orinoco_download(priv);
2345 priv->do_fw_download = 0;
2348 err = orinoco_reinit_firmware(dev);
2350 printk(KERN_ERR "%s: orinoco_reset: Error %d re-initializing firmware\n",
2355 spin_lock_irq(&priv->lock); /* This has to be called from user context */
2357 priv->hw_unavailable--;
2359 /* priv->open or priv->hw_unavailable might have changed while
2360 * we dropped the lock */
2361 if (priv->open && (! priv->hw_unavailable)) {
2362 err = __orinoco_up(dev);
2364 printk(KERN_ERR "%s: orinoco_reset: Error %d reenabling card\n",
2367 dev->trans_start = jiffies;
2370 spin_unlock_irq(&priv->lock);
2374 hermes_set_irqmask(hw, 0);
2375 netif_device_detach(dev);
2376 printk(KERN_ERR "%s: Device has been disabled!\n", dev->name);
2379 /********************************************************************/
2380 /* Interrupt handler */
2381 /********************************************************************/
2383 static void __orinoco_ev_tick(struct net_device *dev, hermes_t *hw)
2385 printk(KERN_DEBUG "%s: TICK\n", dev->name);
2388 static void __orinoco_ev_wterr(struct net_device *dev, hermes_t *hw)
2390 /* This seems to happen a fair bit under load, but ignoring it
2391 seems to work fine...*/
2392 printk(KERN_DEBUG "%s: MAC controller error (WTERR). Ignoring.\n",
2396 irqreturn_t orinoco_interrupt(int irq, void *dev_id)
2398 struct net_device *dev = dev_id;
2399 struct orinoco_private *priv = netdev_priv(dev);
2400 hermes_t *hw = &priv->hw;
2401 int count = MAX_IRQLOOPS_PER_IRQ;
2403 /* These are used to detect a runaway interrupt situation */
2404 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
2405 * we panic and shut down the hardware */
2406 static int last_irq_jiffy = 0; /* jiffies value the last time
2408 static int loops_this_jiffy = 0;
2409 unsigned long flags;
2411 if (orinoco_lock(priv, &flags) != 0) {
2412 /* If hw is unavailable - we don't know if the irq was
2417 evstat = hermes_read_regn(hw, EVSTAT);
2418 events = evstat & hw->inten;
2420 orinoco_unlock(priv, &flags);
2424 if (jiffies != last_irq_jiffy)
2425 loops_this_jiffy = 0;
2426 last_irq_jiffy = jiffies;
2428 while (events && count--) {
2429 if (++loops_this_jiffy > MAX_IRQLOOPS_PER_JIFFY) {
2430 printk(KERN_WARNING "%s: IRQ handler is looping too "
2431 "much! Resetting.\n", dev->name);
2432 /* Disable interrupts for now */
2433 hermes_set_irqmask(hw, 0);
2434 schedule_work(&priv->reset_work);
2438 /* Check the card hasn't been removed */
2439 if (! hermes_present(hw)) {
2440 DEBUG(0, "orinoco_interrupt(): card removed\n");
2444 if (events & HERMES_EV_TICK)
2445 __orinoco_ev_tick(dev, hw);
2446 if (events & HERMES_EV_WTERR)
2447 __orinoco_ev_wterr(dev, hw);
2448 if (events & HERMES_EV_INFDROP)
2449 __orinoco_ev_infdrop(dev, hw);
2450 if (events & HERMES_EV_INFO)
2451 __orinoco_ev_info(dev, hw);
2452 if (events & HERMES_EV_RX)
2453 __orinoco_ev_rx(dev, hw);
2454 if (events & HERMES_EV_TXEXC)
2455 __orinoco_ev_txexc(dev, hw);
2456 if (events & HERMES_EV_TX)
2457 __orinoco_ev_tx(dev, hw);
2458 if (events & HERMES_EV_ALLOC)
2459 __orinoco_ev_alloc(dev, hw);
2461 hermes_write_regn(hw, EVACK, evstat);
2463 evstat = hermes_read_regn(hw, EVSTAT);
2464 events = evstat & hw->inten;
2467 orinoco_unlock(priv, &flags);
2471 /********************************************************************/
2472 /* Initialization */
2473 /********************************************************************/
2476 u16 id, variant, major, minor;
2477 } __attribute__ ((packed));
2479 static inline fwtype_t determine_firmware_type(struct comp_id *nic_id)
2481 if (nic_id->id < 0x8000)
2482 return FIRMWARE_TYPE_AGERE;
2483 else if (nic_id->id == 0x8000 && nic_id->major == 0)
2484 return FIRMWARE_TYPE_SYMBOL;
2486 return FIRMWARE_TYPE_INTERSIL;
2489 /* Set priv->firmware type, determine firmware properties */
2490 static int determine_firmware(struct net_device *dev)
2492 struct orinoco_private *priv = netdev_priv(dev);
2493 hermes_t *hw = &priv->hw;
2495 struct comp_id nic_id, sta_id;
2496 unsigned int firmver;
2497 char tmp[SYMBOL_MAX_VER_LEN+1] __attribute__((aligned(2)));
2499 /* Get the hardware version */
2500 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_NICID, &nic_id);
2502 printk(KERN_ERR "%s: Cannot read hardware identity: error %d\n",
2507 le16_to_cpus(&nic_id.id);
2508 le16_to_cpus(&nic_id.variant);
2509 le16_to_cpus(&nic_id.major);
2510 le16_to_cpus(&nic_id.minor);
2511 printk(KERN_DEBUG "%s: Hardware identity %04x:%04x:%04x:%04x\n",
2512 dev->name, nic_id.id, nic_id.variant,
2513 nic_id.major, nic_id.minor);
2515 priv->firmware_type = determine_firmware_type(&nic_id);
2517 /* Get the firmware version */
2518 err = HERMES_READ_RECORD(hw, USER_BAP, HERMES_RID_STAID, &sta_id);
2520 printk(KERN_ERR "%s: Cannot read station identity: error %d\n",
2525 le16_to_cpus(&sta_id.id);
2526 le16_to_cpus(&sta_id.variant);
2527 le16_to_cpus(&sta_id.major);
2528 le16_to_cpus(&sta_id.minor);
2529 printk(KERN_DEBUG "%s: Station identity %04x:%04x:%04x:%04x\n",
2530 dev->name, sta_id.id, sta_id.variant,
2531 sta_id.major, sta_id.minor);
2533 switch (sta_id.id) {
2535 printk(KERN_ERR "%s: Primary firmware is active\n",
2539 printk(KERN_ERR "%s: Tertiary firmware is active\n",
2542 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2543 case 0x21: /* Symbol Spectrum24 Trilogy */
2546 printk(KERN_NOTICE "%s: Unknown station ID, please report\n",
2551 /* Default capabilities */
2552 priv->has_sensitivity = 1;
2554 priv->has_preamble = 0;
2555 priv->has_port3 = 1;
2558 priv->has_big_wep = 0;
2559 priv->has_alt_txcntl = 0;
2560 priv->do_fw_download = 0;
2562 /* Determine capabilities from the firmware version */
2563 switch (priv->firmware_type) {
2564 case FIRMWARE_TYPE_AGERE:
2565 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2566 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2567 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2568 "Lucent/Agere %d.%02d", sta_id.major, sta_id.minor);
2570 firmver = ((unsigned long)sta_id.major << 16) | sta_id.minor;
2572 priv->has_ibss = (firmver >= 0x60006);
2573 priv->has_wep = (firmver >= 0x40020);
2574 priv->has_big_wep = 1; /* FIXME: this is wrong - how do we tell
2575 Gold cards from the others? */
2576 priv->has_mwo = (firmver >= 0x60000);
2577 priv->has_pm = (firmver >= 0x40020); /* Don't work in 7.52 ? */
2578 priv->ibss_port = 1;
2579 priv->has_hostscan = (firmver >= 0x8000a);
2580 priv->do_fw_download = 1;
2581 priv->broken_monitor = (firmver >= 0x80000);
2582 priv->has_alt_txcntl = (firmver >= 0x90000); /* All 9.x ? */
2584 /* Tested with Agere firmware :
2585 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2586 * Tested CableTron firmware : 4.32 => Anton */
2588 case FIRMWARE_TYPE_SYMBOL:
2589 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2590 /* Intel MAC : 00:02:B3:* */
2591 /* 3Com MAC : 00:50:DA:* */
2592 memset(tmp, 0, sizeof(tmp));
2593 /* Get the Symbol firmware version */
2594 err = hermes_read_ltv(hw, USER_BAP,
2595 HERMES_RID_SECONDARYVERSION_SYMBOL,
2596 SYMBOL_MAX_VER_LEN, NULL, &tmp);
2599 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2604 /* The firmware revision is a string, the format is
2605 * something like : "V2.20-01".
2606 * Quick and dirty parsing... - Jean II
2608 firmver = ((tmp[1] - '0') << 16) | ((tmp[3] - '0') << 12)
2609 | ((tmp[4] - '0') << 8) | ((tmp[6] - '0') << 4)
2612 tmp[SYMBOL_MAX_VER_LEN] = '\0';
2615 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2618 priv->has_ibss = (firmver >= 0x20000);
2619 priv->has_wep = (firmver >= 0x15012);
2620 priv->has_big_wep = (firmver >= 0x20000);
2621 priv->has_pm = (firmver >= 0x20000 && firmver < 0x22000) ||
2622 (firmver >= 0x29000 && firmver < 0x30000) ||
2624 priv->has_preamble = (firmver >= 0x20000);
2625 priv->ibss_port = 4;
2627 /* Symbol firmware is found on various cards, but
2628 * there has been no attempt to check firmware
2629 * download on non-spectrum_cs based cards.
2631 * Given that the Agere firmware download works
2632 * differently, we should avoid doing a firmware
2633 * download with the Symbol algorithm on non-spectrum
2636 * For now we can identify a spectrum_cs based card
2637 * because it has a firmware reset function.
2639 priv->do_fw_download = (priv->stop_fw != NULL);
2641 priv->broken_disableport = (firmver == 0x25013) ||
2642 (firmver >= 0x30000 && firmver <= 0x31000);
2643 priv->has_hostscan = (firmver >= 0x31001) ||
2644 (firmver >= 0x29057 && firmver < 0x30000);
2645 /* Tested with Intel firmware : 0x20015 => Jean II */
2646 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2648 case FIRMWARE_TYPE_INTERSIL:
2649 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2650 * Samsung, Compaq 100/200 and Proxim are slightly
2651 * different and less well tested */
2652 /* D-Link MAC : 00:40:05:* */
2653 /* Addtron MAC : 00:90:D1:* */
2654 snprintf(priv->fw_name, sizeof(priv->fw_name) - 1,
2655 "Intersil %d.%d.%d", sta_id.major, sta_id.minor,
2658 firmver = ((unsigned long)sta_id.major << 16) |
2659 ((unsigned long)sta_id.minor << 8) | sta_id.variant;
2661 priv->has_ibss = (firmver >= 0x000700); /* FIXME */
2662 priv->has_big_wep = priv->has_wep = (firmver >= 0x000800);
2663 priv->has_pm = (firmver >= 0x000700);
2664 priv->has_hostscan = (firmver >= 0x010301);
2666 if (firmver >= 0x000800)
2667 priv->ibss_port = 0;
2669 printk(KERN_NOTICE "%s: Intersil firmware earlier "
2670 "than v0.8.x - several features not supported\n",
2672 priv->ibss_port = 1;
2676 printk(KERN_DEBUG "%s: Firmware determined as %s\n", dev->name,
2682 static int orinoco_init(struct net_device *dev)
2684 struct orinoco_private *priv = netdev_priv(dev);
2685 hermes_t *hw = &priv->hw;
2687 struct hermes_idstring nickbuf;
2690 DECLARE_MAC_BUF(mac);
2692 /* No need to lock, the hw_unavailable flag is already set in
2693 * alloc_orinocodev() */
2694 priv->nicbuf_size = IEEE80211_FRAME_LEN + ETH_HLEN;
2696 /* Initialize the firmware */
2697 err = hermes_init(hw);
2699 printk(KERN_ERR "%s: failed to initialize firmware (err = %d)\n",
2704 err = determine_firmware(dev);
2706 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2711 if (priv->do_fw_download) {
2712 err = orinoco_download(priv);
2714 priv->do_fw_download = 0;
2716 /* Check firmware version again */
2717 err = determine_firmware(dev);
2719 printk(KERN_ERR "%s: Incompatible firmware, aborting\n",
2725 if (priv->has_port3)
2726 printk(KERN_DEBUG "%s: Ad-hoc demo mode supported\n", dev->name);
2728 printk(KERN_DEBUG "%s: IEEE standard IBSS ad-hoc mode supported\n",
2730 if (priv->has_wep) {
2731 printk(KERN_DEBUG "%s: WEP supported, ", dev->name);
2732 if (priv->has_big_wep)
2733 printk("104-bit key\n");
2735 printk("40-bit key\n");
2738 /* Get the MAC address */
2739 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNMACADDR,
2740 ETH_ALEN, NULL, dev->dev_addr);
2742 printk(KERN_WARNING "%s: failed to read MAC address!\n",
2747 printk(KERN_DEBUG "%s: MAC address %s\n",
2748 dev->name, print_mac(mac, dev->dev_addr));
2750 /* Get the station name */
2751 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CNFOWNNAME,
2752 sizeof(nickbuf), &reclen, &nickbuf);
2754 printk(KERN_ERR "%s: failed to read station name\n",
2759 len = min(IW_ESSID_MAX_SIZE, (int)le16_to_cpu(nickbuf.len));
2761 len = min(IW_ESSID_MAX_SIZE, 2 * reclen);
2762 memcpy(priv->nick, &nickbuf.val, len);
2763 priv->nick[len] = '\0';
2765 printk(KERN_DEBUG "%s: Station name \"%s\"\n", dev->name, priv->nick);
2767 err = orinoco_allocate_fid(dev);
2769 printk(KERN_ERR "%s: failed to allocate NIC buffer!\n",
2774 /* Get allowed channels */
2775 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CHANNELLIST,
2776 &priv->channel_mask);
2778 printk(KERN_ERR "%s: failed to read channel list!\n",
2783 /* Get initial AP density */
2784 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFSYSTEMSCALE,
2786 if (err || priv->ap_density < 1 || priv->ap_density > 3) {
2787 priv->has_sensitivity = 0;
2790 /* Get initial RTS threshold */
2791 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFRTSTHRESHOLD,
2794 printk(KERN_ERR "%s: failed to read RTS threshold!\n",
2799 /* Get initial fragmentation settings */
2801 err = hermes_read_wordrec(hw, USER_BAP,
2802 HERMES_RID_CNFMWOROBUST_AGERE,
2805 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
2806 &priv->frag_thresh);
2808 printk(KERN_ERR "%s: failed to read fragmentation settings!\n",
2813 /* Power management setup */
2817 err = hermes_read_wordrec(hw, USER_BAP,
2818 HERMES_RID_CNFMAXSLEEPDURATION,
2821 printk(KERN_ERR "%s: failed to read power management period!\n",
2825 err = hermes_read_wordrec(hw, USER_BAP,
2826 HERMES_RID_CNFPMHOLDOVERDURATION,
2829 printk(KERN_ERR "%s: failed to read power management timeout!\n",
2835 /* Preamble setup */
2836 if (priv->has_preamble) {
2837 err = hermes_read_wordrec(hw, USER_BAP,
2838 HERMES_RID_CNFPREAMBLE_SYMBOL,
2844 /* Set up the default configuration */
2845 priv->iw_mode = IW_MODE_INFRA;
2846 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2847 priv->prefer_port3 = priv->has_port3 && (! priv->has_ibss);
2848 set_port_type(priv);
2849 priv->channel = 0; /* use firmware default */
2851 priv->promiscuous = 0;
2855 /* Make the hardware available, as long as it hasn't been
2856 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2857 spin_lock_irq(&priv->lock);
2858 priv->hw_unavailable--;
2859 spin_unlock_irq(&priv->lock);
2861 printk(KERN_DEBUG "%s: ready\n", dev->name);
2868 *alloc_orinocodev(int sizeof_card,
2869 struct device *device,
2870 int (*hard_reset)(struct orinoco_private *),
2871 int (*stop_fw)(struct orinoco_private *, int))
2873 struct net_device *dev;
2874 struct orinoco_private *priv;
2876 dev = alloc_etherdev(sizeof(struct orinoco_private) + sizeof_card);
2879 priv = netdev_priv(dev);
2882 priv->card = (void *)((unsigned long)priv
2883 + sizeof(struct orinoco_private));
2888 if (orinoco_bss_data_allocate(priv))
2890 orinoco_bss_data_init(priv);
2892 /* Setup / override net_device fields */
2893 dev->init = orinoco_init;
2894 dev->hard_start_xmit = orinoco_xmit;
2895 dev->tx_timeout = orinoco_tx_timeout;
2896 dev->watchdog_timeo = HZ; /* 1 second timeout */
2897 dev->get_stats = orinoco_get_stats;
2898 dev->ethtool_ops = &orinoco_ethtool_ops;
2899 dev->wireless_handlers = (struct iw_handler_def *)&orinoco_handler_def;
2901 priv->wireless_data.spy_data = &priv->spy_data;
2902 dev->wireless_data = &priv->wireless_data;
2904 dev->change_mtu = orinoco_change_mtu;
2905 dev->set_multicast_list = orinoco_set_multicast_list;
2906 /* we use the default eth_mac_addr for setting the MAC addr */
2908 /* Set up default callbacks */
2909 dev->open = orinoco_open;
2910 dev->stop = orinoco_stop;
2911 priv->hard_reset = hard_reset;
2912 priv->stop_fw = stop_fw;
2914 spin_lock_init(&priv->lock);
2916 priv->hw_unavailable = 1; /* orinoco_init() must clear this
2917 * before anything else touches the
2919 INIT_WORK(&priv->reset_work, orinoco_reset);
2920 INIT_WORK(&priv->join_work, orinoco_join_ap);
2921 INIT_WORK(&priv->wevent_work, orinoco_send_wevents);
2923 netif_carrier_off(dev);
2924 priv->last_linkstatus = 0xffff;
2933 void free_orinocodev(struct net_device *dev)
2935 struct orinoco_private *priv = netdev_priv(dev);
2937 orinoco_bss_data_free(priv);
2941 /********************************************************************/
2942 /* Wireless extensions */
2943 /********************************************************************/
2945 /* Return : < 0 -> error code ; >= 0 -> length */
2946 static int orinoco_hw_get_essid(struct orinoco_private *priv, int *active,
2947 char buf[IW_ESSID_MAX_SIZE+1])
2949 hermes_t *hw = &priv->hw;
2951 struct hermes_idstring essidbuf;
2952 char *p = (char *)(&essidbuf.val);
2954 unsigned long flags;
2956 if (orinoco_lock(priv, &flags) != 0)
2959 if (strlen(priv->desired_essid) > 0) {
2960 /* We read the desired SSID from the hardware rather
2961 than from priv->desired_essid, just in case the
2962 firmware is allowed to change it on us. I'm not
2964 /* My guess is that the OWNSSID should always be whatever
2965 * we set to the card, whereas CURRENT_SSID is the one that
2966 * may change... - Jean II */
2971 rid = (priv->port_type == 3) ? HERMES_RID_CNFOWNSSID :
2972 HERMES_RID_CNFDESIREDSSID;
2974 err = hermes_read_ltv(hw, USER_BAP, rid, sizeof(essidbuf),
2981 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTSSID,
2982 sizeof(essidbuf), NULL, &essidbuf);
2987 len = le16_to_cpu(essidbuf.len);
2988 BUG_ON(len > IW_ESSID_MAX_SIZE);
2990 memset(buf, 0, IW_ESSID_MAX_SIZE);
2991 memcpy(buf, p, len);
2995 orinoco_unlock(priv, &flags);
3000 static long orinoco_hw_get_freq(struct orinoco_private *priv)
3003 hermes_t *hw = &priv->hw;
3007 unsigned long flags;
3009 if (orinoco_lock(priv, &flags) != 0)
3012 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CURRENTCHANNEL, &channel);
3016 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
3022 if ( (channel < 1) || (channel > NUM_CHANNELS) ) {
3023 printk(KERN_WARNING "%s: Channel out of range (%d)!\n",
3024 priv->ndev->name, channel);
3029 freq = channel_frequency[channel-1] * 100000;
3032 orinoco_unlock(priv, &flags);
3036 return err ? err : freq;
3039 static int orinoco_hw_get_bitratelist(struct orinoco_private *priv,
3040 int *numrates, s32 *rates, int max)
3042 hermes_t *hw = &priv->hw;
3043 struct hermes_idstring list;
3044 unsigned char *p = (unsigned char *)&list.val;
3048 unsigned long flags;
3050 if (orinoco_lock(priv, &flags) != 0)
3053 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_SUPPORTEDDATARATES,
3054 sizeof(list), NULL, &list);
3055 orinoco_unlock(priv, &flags);
3060 num = le16_to_cpu(list.len);
3062 num = min(num, max);
3064 for (i = 0; i < num; i++) {
3065 rates[i] = (p[i] & 0x7f) * 500000; /* convert to bps */
3071 static int orinoco_ioctl_getname(struct net_device *dev,
3072 struct iw_request_info *info,
3076 struct orinoco_private *priv = netdev_priv(dev);
3080 err = orinoco_hw_get_bitratelist(priv, &numrates, NULL, 0);
3082 if (!err && (numrates > 2))
3083 strcpy(name, "IEEE 802.11b");
3085 strcpy(name, "IEEE 802.11-DS");
3090 static int orinoco_ioctl_setwap(struct net_device *dev,
3091 struct iw_request_info *info,
3092 struct sockaddr *ap_addr,
3095 struct orinoco_private *priv = netdev_priv(dev);
3096 int err = -EINPROGRESS; /* Call commit handler */
3097 unsigned long flags;
3098 static const u8 off_addr[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
3099 static const u8 any_addr[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
3101 if (orinoco_lock(priv, &flags) != 0)
3104 /* Enable automatic roaming - no sanity checks are needed */
3105 if (memcmp(&ap_addr->sa_data, off_addr, ETH_ALEN) == 0 ||
3106 memcmp(&ap_addr->sa_data, any_addr, ETH_ALEN) == 0) {
3107 priv->bssid_fixed = 0;
3108 memset(priv->desired_bssid, 0, ETH_ALEN);
3110 /* "off" means keep existing connection */
3111 if (ap_addr->sa_data[0] == 0) {
3112 __orinoco_hw_set_wap(priv);
3118 if (priv->firmware_type == FIRMWARE_TYPE_AGERE) {
3119 printk(KERN_WARNING "%s: Lucent/Agere firmware doesn't "
3120 "support manual roaming\n",
3126 if (priv->iw_mode != IW_MODE_INFRA) {
3127 printk(KERN_WARNING "%s: Manual roaming supported only in "
3128 "managed mode\n", dev->name);
3133 /* Intersil firmware hangs without Desired ESSID */
3134 if (priv->firmware_type == FIRMWARE_TYPE_INTERSIL &&
3135 strlen(priv->desired_essid) == 0) {
3136 printk(KERN_WARNING "%s: Desired ESSID must be set for "
3137 "manual roaming\n", dev->name);
3142 /* Finally, enable manual roaming */
3143 priv->bssid_fixed = 1;
3144 memcpy(priv->desired_bssid, &ap_addr->sa_data, ETH_ALEN);
3147 orinoco_unlock(priv, &flags);
3151 static int orinoco_ioctl_getwap(struct net_device *dev,
3152 struct iw_request_info *info,
3153 struct sockaddr *ap_addr,
3156 struct orinoco_private *priv = netdev_priv(dev);
3158 hermes_t *hw = &priv->hw;
3160 unsigned long flags;
3162 if (orinoco_lock(priv, &flags) != 0)
3165 ap_addr->sa_family = ARPHRD_ETHER;
3166 err = hermes_read_ltv(hw, USER_BAP, HERMES_RID_CURRENTBSSID,
3167 ETH_ALEN, NULL, ap_addr->sa_data);
3169 orinoco_unlock(priv, &flags);
3174 static int orinoco_ioctl_setmode(struct net_device *dev,
3175 struct iw_request_info *info,
3179 struct orinoco_private *priv = netdev_priv(dev);
3180 int err = -EINPROGRESS; /* Call commit handler */
3181 unsigned long flags;
3183 if (priv->iw_mode == *mode)
3186 if (orinoco_lock(priv, &flags) != 0)
3191 if (!priv->has_ibss && !priv->has_port3)
3198 case IW_MODE_MONITOR:
3199 if (priv->broken_monitor && !force_monitor) {
3200 printk(KERN_WARNING "%s: Monitor mode support is "
3201 "buggy in this firmware, not enabling\n",
3212 if (err == -EINPROGRESS) {
3213 priv->iw_mode = *mode;
3214 set_port_type(priv);
3217 orinoco_unlock(priv, &flags);
3222 static int orinoco_ioctl_getmode(struct net_device *dev,
3223 struct iw_request_info *info,
3227 struct orinoco_private *priv = netdev_priv(dev);
3229 *mode = priv->iw_mode;
3233 static int orinoco_ioctl_getiwrange(struct net_device *dev,
3234 struct iw_request_info *info,
3235 struct iw_point *rrq,
3238 struct orinoco_private *priv = netdev_priv(dev);
3240 struct iw_range *range = (struct iw_range *) extra;
3244 rrq->length = sizeof(struct iw_range);
3245 memset(range, 0, sizeof(struct iw_range));
3247 range->we_version_compiled = WIRELESS_EXT;
3248 range->we_version_source = 14;
3250 /* Set available channels/frequencies */
3251 range->num_channels = NUM_CHANNELS;
3253 for (i = 0; i < NUM_CHANNELS; i++) {
3254 if (priv->channel_mask & (1 << i)) {
3255 range->freq[k].i = i + 1;
3256 range->freq[k].m = channel_frequency[i] * 100000;
3257 range->freq[k].e = 1;
3261 if (k >= IW_MAX_FREQUENCIES)
3264 range->num_frequency = k;
3265 range->sensitivity = 3;
3267 if (priv->has_wep) {
3268 range->max_encoding_tokens = ORINOCO_MAX_KEYS;
3269 range->encoding_size[0] = SMALL_KEY_SIZE;
3270 range->num_encoding_sizes = 1;
3272 if (priv->has_big_wep) {
3273 range->encoding_size[1] = LARGE_KEY_SIZE;
3274 range->num_encoding_sizes = 2;
3278 if ((priv->iw_mode == IW_MODE_ADHOC) && (!SPY_NUMBER(priv))){
3279 /* Quality stats meaningless in ad-hoc mode */
3281 range->max_qual.qual = 0x8b - 0x2f;
3282 range->max_qual.level = 0x2f - 0x95 - 1;
3283 range->max_qual.noise = 0x2f - 0x95 - 1;
3284 /* Need to get better values */
3285 range->avg_qual.qual = 0x24;
3286 range->avg_qual.level = 0xC2;
3287 range->avg_qual.noise = 0x9E;
3290 err = orinoco_hw_get_bitratelist(priv, &numrates,
3291 range->bitrate, IW_MAX_BITRATES);
3294 range->num_bitrates = numrates;
3296 /* Set an indication of the max TCP throughput in bit/s that we can
3297 * expect using this interface. May be use for QoS stuff...
3300 range->throughput = 5 * 1000 * 1000; /* ~5 Mb/s */
3302 range->throughput = 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
3305 range->max_rts = 2347;
3306 range->min_frag = 256;
3307 range->max_frag = 2346;
3310 range->max_pmp = 65535000;
3312 range->max_pmt = 65535 * 1000; /* ??? */
3313 range->pmp_flags = IW_POWER_PERIOD;
3314 range->pmt_flags = IW_POWER_TIMEOUT;
3315 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_UNICAST_R;
3317 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
3318 range->retry_flags = IW_RETRY_LIMIT;
3319 range->r_time_flags = IW_RETRY_LIFETIME;
3320 range->min_retry = 0;
3321 range->max_retry = 65535; /* ??? */
3322 range->min_r_time = 0;
3323 range->max_r_time = 65535 * 1000; /* ??? */
3325 if (priv->firmware_type == FIRMWARE_TYPE_AGERE)
3326 range->scan_capa = IW_SCAN_CAPA_ESSID;
3328 range->scan_capa = IW_SCAN_CAPA_NONE;
3330 /* Event capability (kernel) */
3331 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
3332 /* Event capability (driver) */
3333 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
3334 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
3335 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
3336 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
3341 static int orinoco_ioctl_setiwencode(struct net_device *dev,
3342 struct iw_request_info *info,
3343 struct iw_point *erq,
3346 struct orinoco_private *priv = netdev_priv(dev);
3347 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3348 int setindex = priv->tx_key;
3349 int enable = priv->wep_on;
3350 int restricted = priv->wep_restrict;
3352 int err = -EINPROGRESS; /* Call commit handler */
3353 unsigned long flags;
3355 if (! priv->has_wep)
3359 /* We actually have a key to set - check its length */
3360 if (erq->length > LARGE_KEY_SIZE)
3363 if ( (erq->length > SMALL_KEY_SIZE) && !priv->has_big_wep )
3367 if (orinoco_lock(priv, &flags) != 0)
3370 if (erq->length > 0) {
3371 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3372 index = priv->tx_key;
3374 /* Adjust key length to a supported value */
3375 if (erq->length > SMALL_KEY_SIZE) {
3376 xlen = LARGE_KEY_SIZE;
3377 } else if (erq->length > 0) {
3378 xlen = SMALL_KEY_SIZE;
3382 /* Switch on WEP if off */
3383 if ((!enable) && (xlen > 0)) {
3388 /* Important note : if the user do "iwconfig eth0 enc off",
3389 * we will arrive there with an index of -1. This is valid
3390 * but need to be taken care off... Jean II */
3391 if ((index < 0) || (index >= ORINOCO_MAX_KEYS)) {
3392 if((index != -1) || (erq->flags == 0)) {
3397 /* Set the index : Check that the key is valid */
3398 if(priv->keys[index].len == 0) {
3406 if (erq->flags & IW_ENCODE_DISABLED)
3408 if (erq->flags & IW_ENCODE_OPEN)
3410 if (erq->flags & IW_ENCODE_RESTRICTED)
3413 if (erq->pointer && erq->length > 0) {
3414 priv->keys[index].len = cpu_to_le16(xlen);
3415 memset(priv->keys[index].data, 0,
3416 sizeof(priv->keys[index].data));
3417 memcpy(priv->keys[index].data, keybuf, erq->length);
3419 priv->tx_key = setindex;
3421 /* Try fast key change if connected and only keys are changed */
3422 if (priv->wep_on && enable && (priv->wep_restrict == restricted) &&
3423 netif_carrier_ok(dev)) {
3424 err = __orinoco_hw_setup_wepkeys(priv);
3425 /* No need to commit if successful */
3429 priv->wep_on = enable;
3430 priv->wep_restrict = restricted;
3433 orinoco_unlock(priv, &flags);
3438 static int orinoco_ioctl_getiwencode(struct net_device *dev,
3439 struct iw_request_info *info,
3440 struct iw_point *erq,
3443 struct orinoco_private *priv = netdev_priv(dev);
3444 int index = (erq->flags & IW_ENCODE_INDEX) - 1;
3446 unsigned long flags;
3448 if (! priv->has_wep)
3451 if (orinoco_lock(priv, &flags) != 0)
3454 if ((index < 0) || (index >= ORINOCO_MAX_KEYS))
3455 index = priv->tx_key;
3459 erq->flags |= IW_ENCODE_DISABLED;
3460 erq->flags |= index + 1;
3462 if (priv->wep_restrict)
3463 erq->flags |= IW_ENCODE_RESTRICTED;
3465 erq->flags |= IW_ENCODE_OPEN;
3467 xlen = le16_to_cpu(priv->keys[index].len);
3471 memcpy(keybuf, priv->keys[index].data, ORINOCO_MAX_KEY_SIZE);
3473 orinoco_unlock(priv, &flags);
3477 static int orinoco_ioctl_setessid(struct net_device *dev,
3478 struct iw_request_info *info,
3479 struct iw_point *erq,
3482 struct orinoco_private *priv = netdev_priv(dev);
3483 unsigned long flags;
3485 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
3486 * anyway... - Jean II */
3488 /* Hum... Should not use Wireless Extension constant (may change),
3489 * should use our own... - Jean II */
3490 if (erq->length > IW_ESSID_MAX_SIZE)
3493 if (orinoco_lock(priv, &flags) != 0)
3496 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3497 memset(priv->desired_essid, 0, sizeof(priv->desired_essid));
3499 /* If not ANY, get the new ESSID */
3501 memcpy(priv->desired_essid, essidbuf, erq->length);
3504 orinoco_unlock(priv, &flags);
3506 return -EINPROGRESS; /* Call commit handler */
3509 static int orinoco_ioctl_getessid(struct net_device *dev,
3510 struct iw_request_info *info,
3511 struct iw_point *erq,
3514 struct orinoco_private *priv = netdev_priv(dev);
3517 unsigned long flags;
3519 if (netif_running(dev)) {
3520 err = orinoco_hw_get_essid(priv, &active, essidbuf);
3525 if (orinoco_lock(priv, &flags) != 0)
3527 memcpy(essidbuf, priv->desired_essid, IW_ESSID_MAX_SIZE);
3528 erq->length = strlen(priv->desired_essid);
3529 orinoco_unlock(priv, &flags);
3537 static int orinoco_ioctl_setnick(struct net_device *dev,
3538 struct iw_request_info *info,
3539 struct iw_point *nrq,
3542 struct orinoco_private *priv = netdev_priv(dev);
3543 unsigned long flags;
3545 if (nrq->length > IW_ESSID_MAX_SIZE)
3548 if (orinoco_lock(priv, &flags) != 0)
3551 memset(priv->nick, 0, sizeof(priv->nick));
3552 memcpy(priv->nick, nickbuf, nrq->length);
3554 orinoco_unlock(priv, &flags);
3556 return -EINPROGRESS; /* Call commit handler */
3559 static int orinoco_ioctl_getnick(struct net_device *dev,
3560 struct iw_request_info *info,
3561 struct iw_point *nrq,
3564 struct orinoco_private *priv = netdev_priv(dev);
3565 unsigned long flags;
3567 if (orinoco_lock(priv, &flags) != 0)
3570 memcpy(nickbuf, priv->nick, IW_ESSID_MAX_SIZE);
3571 orinoco_unlock(priv, &flags);
3573 nrq->length = strlen(priv->nick);
3578 static int orinoco_ioctl_setfreq(struct net_device *dev,
3579 struct iw_request_info *info,
3580 struct iw_freq *frq,
3583 struct orinoco_private *priv = netdev_priv(dev);
3585 unsigned long flags;
3586 int err = -EINPROGRESS; /* Call commit handler */
3588 /* In infrastructure mode the AP sets the channel */
3589 if (priv->iw_mode == IW_MODE_INFRA)
3592 if ( (frq->e == 0) && (frq->m <= 1000) ) {
3593 /* Setting by channel number */
3596 /* Setting by frequency - search the table */
3600 for (i = 0; i < (6 - frq->e); i++)
3603 for (i = 0; i < NUM_CHANNELS; i++)
3604 if (frq->m == (channel_frequency[i] * mult))
3608 if ( (chan < 1) || (chan > NUM_CHANNELS) ||
3609 ! (priv->channel_mask & (1 << (chan-1)) ) )
3612 if (orinoco_lock(priv, &flags) != 0)
3615 priv->channel = chan;
3616 if (priv->iw_mode == IW_MODE_MONITOR) {
3617 /* Fast channel change - no commit if successful */
3618 hermes_t *hw = &priv->hw;
3619 err = hermes_docmd_wait(hw, HERMES_CMD_TEST |
3620 HERMES_TEST_SET_CHANNEL,
3623 orinoco_unlock(priv, &flags);
3628 static int orinoco_ioctl_getfreq(struct net_device *dev,
3629 struct iw_request_info *info,
3630 struct iw_freq *frq,
3633 struct orinoco_private *priv = netdev_priv(dev);
3636 /* Locking done in there */
3637 tmp = orinoco_hw_get_freq(priv);
3648 static int orinoco_ioctl_getsens(struct net_device *dev,
3649 struct iw_request_info *info,
3650 struct iw_param *srq,
3653 struct orinoco_private *priv = netdev_priv(dev);
3654 hermes_t *hw = &priv->hw;
3657 unsigned long flags;
3659 if (!priv->has_sensitivity)
3662 if (orinoco_lock(priv, &flags) != 0)
3664 err = hermes_read_wordrec(hw, USER_BAP,
3665 HERMES_RID_CNFSYSTEMSCALE, &val);
3666 orinoco_unlock(priv, &flags);
3672 srq->fixed = 0; /* auto */
3677 static int orinoco_ioctl_setsens(struct net_device *dev,
3678 struct iw_request_info *info,
3679 struct iw_param *srq,
3682 struct orinoco_private *priv = netdev_priv(dev);
3683 int val = srq->value;
3684 unsigned long flags;
3686 if (!priv->has_sensitivity)
3689 if ((val < 1) || (val > 3))
3692 if (orinoco_lock(priv, &flags) != 0)
3694 priv->ap_density = val;
3695 orinoco_unlock(priv, &flags);
3697 return -EINPROGRESS; /* Call commit handler */
3700 static int orinoco_ioctl_setrts(struct net_device *dev,
3701 struct iw_request_info *info,
3702 struct iw_param *rrq,
3705 struct orinoco_private *priv = netdev_priv(dev);
3706 int val = rrq->value;
3707 unsigned long flags;
3712 if ( (val < 0) || (val > 2347) )
3715 if (orinoco_lock(priv, &flags) != 0)
3718 priv->rts_thresh = val;
3719 orinoco_unlock(priv, &flags);
3721 return -EINPROGRESS; /* Call commit handler */
3724 static int orinoco_ioctl_getrts(struct net_device *dev,
3725 struct iw_request_info *info,
3726 struct iw_param *rrq,
3729 struct orinoco_private *priv = netdev_priv(dev);
3731 rrq->value = priv->rts_thresh;
3732 rrq->disabled = (rrq->value == 2347);
3738 static int orinoco_ioctl_setfrag(struct net_device *dev,
3739 struct iw_request_info *info,
3740 struct iw_param *frq,
3743 struct orinoco_private *priv = netdev_priv(dev);
3744 int err = -EINPROGRESS; /* Call commit handler */
3745 unsigned long flags;
3747 if (orinoco_lock(priv, &flags) != 0)
3750 if (priv->has_mwo) {
3752 priv->mwo_robust = 0;
3755 printk(KERN_WARNING "%s: Fixed fragmentation is "
3756 "not supported on this firmware. "
3757 "Using MWO robust instead.\n", dev->name);
3758 priv->mwo_robust = 1;
3762 priv->frag_thresh = 2346;
3764 if ( (frq->value < 256) || (frq->value > 2346) )
3767 priv->frag_thresh = frq->value & ~0x1; /* must be even */
3771 orinoco_unlock(priv, &flags);
3776 static int orinoco_ioctl_getfrag(struct net_device *dev,
3777 struct iw_request_info *info,
3778 struct iw_param *frq,
3781 struct orinoco_private *priv = netdev_priv(dev);
3782 hermes_t *hw = &priv->hw;
3785 unsigned long flags;
3787 if (orinoco_lock(priv, &flags) != 0)
3790 if (priv->has_mwo) {
3791 err = hermes_read_wordrec(hw, USER_BAP,
3792 HERMES_RID_CNFMWOROBUST_AGERE,
3797 frq->value = val ? 2347 : 0;
3798 frq->disabled = ! val;
3801 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD,
3807 frq->disabled = (val >= 2346);
3811 orinoco_unlock(priv, &flags);
3816 static int orinoco_ioctl_setrate(struct net_device *dev,
3817 struct iw_request_info *info,
3818 struct iw_param *rrq,
3821 struct orinoco_private *priv = netdev_priv(dev);
3823 int bitrate; /* 100s of kilobits */
3825 unsigned long flags;
3827 /* As the user space doesn't know our highest rate, it uses -1
3828 * to ask us to set the highest rate. Test it using "iwconfig
3829 * ethX rate auto" - Jean II */
3830 if (rrq->value == -1)
3833 if (rrq->value % 100000)
3835 bitrate = rrq->value / 100000;
3838 if ( (bitrate != 10) && (bitrate != 20) &&
3839 (bitrate != 55) && (bitrate != 110) )
3842 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3843 if ( (bitrate_table[i].bitrate == bitrate) &&
3844 (bitrate_table[i].automatic == ! rrq->fixed) ) {
3852 if (orinoco_lock(priv, &flags) != 0)
3854 priv->bitratemode = ratemode;
3855 orinoco_unlock(priv, &flags);
3857 return -EINPROGRESS;
3860 static int orinoco_ioctl_getrate(struct net_device *dev,
3861 struct iw_request_info *info,
3862 struct iw_param *rrq,
3865 struct orinoco_private *priv = netdev_priv(dev);
3866 hermes_t *hw = &priv->hw;
3871 unsigned long flags;
3873 if (orinoco_lock(priv, &flags) != 0)
3876 ratemode = priv->bitratemode;
3878 BUG_ON((ratemode < 0) || (ratemode >= BITRATE_TABLE_SIZE));
3880 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3881 rrq->fixed = ! bitrate_table[ratemode].automatic;
3884 /* If the interface is running we try to find more about the
3886 if (netif_running(dev)) {
3887 err = hermes_read_wordrec(hw, USER_BAP,
3888 HERMES_RID_CURRENTTXRATE, &val);
3892 switch (priv->firmware_type) {
3893 case FIRMWARE_TYPE_AGERE: /* Lucent style rate */
3894 /* Note : in Lucent firmware, the return value of
3895 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3896 * and therefore is totally different from the
3897 * encoding of HERMES_RID_CNFTXRATECONTROL.
3898 * Don't forget that 6Mb/s is really 5.5Mb/s */
3900 rrq->value = 5500000;
3902 rrq->value = val * 1000000;
3904 case FIRMWARE_TYPE_INTERSIL: /* Intersil style rate */
3905 case FIRMWARE_TYPE_SYMBOL: /* Symbol style rate */
3906 for (i = 0; i < BITRATE_TABLE_SIZE; i++)
3907 if (bitrate_table[i].intersil_txratectrl == val) {
3911 if (i >= BITRATE_TABLE_SIZE)
3912 printk(KERN_INFO "%s: Unable to determine current bitrate (0x%04hx)\n",
3915 rrq->value = bitrate_table[ratemode].bitrate * 100000;
3923 orinoco_unlock(priv, &flags);
3928 static int orinoco_ioctl_setpower(struct net_device *dev,
3929 struct iw_request_info *info,
3930 struct iw_param *prq,
3933 struct orinoco_private *priv = netdev_priv(dev);
3934 int err = -EINPROGRESS; /* Call commit handler */
3935 unsigned long flags;
3937 if (orinoco_lock(priv, &flags) != 0)
3940 if (prq->disabled) {
3943 switch (prq->flags & IW_POWER_MODE) {
3944 case IW_POWER_UNICAST_R:
3948 case IW_POWER_ALL_R:
3953 /* No flags : but we may have a value - Jean II */
3960 if (prq->flags & IW_POWER_TIMEOUT) {
3962 priv->pm_timeout = prq->value / 1000;
3964 if (prq->flags & IW_POWER_PERIOD) {
3966 priv->pm_period = prq->value / 1000;
3968 /* It's valid to not have a value if we are just toggling
3969 * the flags... Jean II */
3977 orinoco_unlock(priv, &flags);
3982 static int orinoco_ioctl_getpower(struct net_device *dev,
3983 struct iw_request_info *info,
3984 struct iw_param *prq,
3987 struct orinoco_private *priv = netdev_priv(dev);
3988 hermes_t *hw = &priv->hw;
3990 u16 enable, period, timeout, mcast;
3991 unsigned long flags;
3993 if (orinoco_lock(priv, &flags) != 0)
3996 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMENABLED, &enable);
4000 err = hermes_read_wordrec(hw, USER_BAP,
4001 HERMES_RID_CNFMAXSLEEPDURATION, &period);
4005 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFPMHOLDOVERDURATION, &timeout);
4009 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_CNFMULTICASTRECEIVE, &mcast);
4013 prq->disabled = !enable;
4014 /* Note : by default, display the period */
4015 if ((prq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
4016 prq->flags = IW_POWER_TIMEOUT;
4017 prq->value = timeout * 1000;
4019 prq->flags = IW_POWER_PERIOD;
4020 prq->value = period * 1000;
4023 prq->flags |= IW_POWER_ALL_R;
4025 prq->flags |= IW_POWER_UNICAST_R;
4028 orinoco_unlock(priv, &flags);
4033 static int orinoco_ioctl_getretry(struct net_device *dev,
4034 struct iw_request_info *info,
4035 struct iw_param *rrq,
4038 struct orinoco_private *priv = netdev_priv(dev);
4039 hermes_t *hw = &priv->hw;
4041 u16 short_limit, long_limit, lifetime;
4042 unsigned long flags;
4044 if (orinoco_lock(priv, &flags) != 0)
4047 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_SHORTRETRYLIMIT,
4052 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_LONGRETRYLIMIT,
4057 err = hermes_read_wordrec(hw, USER_BAP, HERMES_RID_MAXTRANSMITLIFETIME,
4062 rrq->disabled = 0; /* Can't be disabled */
4064 /* Note : by default, display the retry number */
4065 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
4066 rrq->flags = IW_RETRY_LIFETIME;
4067 rrq->value = lifetime * 1000; /* ??? */
4069 /* By default, display the min number */
4070 if ((rrq->flags & IW_RETRY_LONG)) {
4071 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
4072 rrq->value = long_limit;
4074 rrq->flags = IW_RETRY_LIMIT;
4075 rrq->value = short_limit;
4076 if(short_limit != long_limit)
4077 rrq->flags |= IW_RETRY_SHORT;
4082 orinoco_unlock(priv, &flags);
4087 static int orinoco_ioctl_reset(struct net_device *dev,
4088 struct iw_request_info *info,
4092 struct orinoco_private *priv = netdev_priv(dev);
4094 if (! capable(CAP_NET_ADMIN))
4097 if (info->cmd == (SIOCIWFIRSTPRIV + 0x1)) {
4098 printk(KERN_DEBUG "%s: Forcing reset!\n", dev->name);
4100 /* Firmware reset */
4101 orinoco_reset(&priv->reset_work);
4103 printk(KERN_DEBUG "%s: Force scheduling reset!\n", dev->name);
4105 schedule_work(&priv->reset_work);
4111 static int orinoco_ioctl_setibssport(struct net_device *dev,
4112 struct iw_request_info *info,
4117 struct orinoco_private *priv = netdev_priv(dev);
4118 int val = *( (int *) extra );
4119 unsigned long flags;
4121 if (orinoco_lock(priv, &flags) != 0)
4124 priv->ibss_port = val ;
4126 /* Actually update the mode we are using */
4127 set_port_type(priv);
4129 orinoco_unlock(priv, &flags);
4130 return -EINPROGRESS; /* Call commit handler */
4133 static int orinoco_ioctl_getibssport(struct net_device *dev,
4134 struct iw_request_info *info,
4138 struct orinoco_private *priv = netdev_priv(dev);
4139 int *val = (int *) extra;
4141 *val = priv->ibss_port;
4145 static int orinoco_ioctl_setport3(struct net_device *dev,
4146 struct iw_request_info *info,
4150 struct orinoco_private *priv = netdev_priv(dev);
4151 int val = *( (int *) extra );
4153 unsigned long flags;
4155 if (orinoco_lock(priv, &flags) != 0)
4159 case 0: /* Try to do IEEE ad-hoc mode */
4160 if (! priv->has_ibss) {
4164 priv->prefer_port3 = 0;
4168 case 1: /* Try to do Lucent proprietary ad-hoc mode */
4169 if (! priv->has_port3) {
4173 priv->prefer_port3 = 1;
4181 /* Actually update the mode we are using */
4182 set_port_type(priv);
4186 orinoco_unlock(priv, &flags);
4191 static int orinoco_ioctl_getport3(struct net_device *dev,
4192 struct iw_request_info *info,
4196 struct orinoco_private *priv = netdev_priv(dev);
4197 int *val = (int *) extra;
4199 *val = priv->prefer_port3;
4203 static int orinoco_ioctl_setpreamble(struct net_device *dev,
4204 struct iw_request_info *info,
4208 struct orinoco_private *priv = netdev_priv(dev);
4209 unsigned long flags;
4212 if (! priv->has_preamble)
4215 /* 802.11b has recently defined some short preamble.
4216 * Basically, the Phy header has been reduced in size.
4217 * This increase performance, especially at high rates
4218 * (the preamble is transmitted at 1Mb/s), unfortunately
4219 * this give compatibility troubles... - Jean II */
4220 val = *( (int *) extra );
4222 if (orinoco_lock(priv, &flags) != 0)
4230 orinoco_unlock(priv, &flags);
4232 return -EINPROGRESS; /* Call commit handler */
4235 static int orinoco_ioctl_getpreamble(struct net_device *dev,
4236 struct iw_request_info *info,
4240 struct orinoco_private *priv = netdev_priv(dev);
4241 int *val = (int *) extra;
4243 if (! priv->has_preamble)
4246 *val = priv->preamble;
4250 /* ioctl interface to hermes_read_ltv()
4251 * To use with iwpriv, pass the RID as the token argument, e.g.
4252 * iwpriv get_rid [0xfc00]
4253 * At least Wireless Tools 25 is required to use iwpriv.
4254 * For Wireless Tools 25 and 26 append "dummy" are the end. */
4255 static int orinoco_ioctl_getrid(struct net_device *dev,
4256 struct iw_request_info *info,
4257 struct iw_point *data,
4260 struct orinoco_private *priv = netdev_priv(dev);
4261 hermes_t *hw = &priv->hw;
4262 int rid = data->flags;
4265 unsigned long flags;
4267 /* It's a "get" function, but we don't want users to access the
4268 * WEP key and other raw firmware data */
4269 if (! capable(CAP_NET_ADMIN))
4272 if (rid < 0xfc00 || rid > 0xffff)
4275 if (orinoco_lock(priv, &flags) != 0)
4278 err = hermes_read_ltv(hw, USER_BAP, rid, MAX_RID_LEN, &length,
4283 data->length = min_t(u16, HERMES_RECLEN_TO_BYTES(length),
4287 orinoco_unlock(priv, &flags);
4291 /* Trigger a scan (look for other cells in the vicinity) */
4292 static int orinoco_ioctl_setscan(struct net_device *dev,
4293 struct iw_request_info *info,
4294 struct iw_param *srq,
4297 struct orinoco_private *priv = netdev_priv(dev);
4298 hermes_t *hw = &priv->hw;
4299 struct iw_scan_req *si = (struct iw_scan_req *) extra;
4301 unsigned long flags;
4303 /* Note : you may have realised that, as this is a SET operation,
4304 * this is privileged and therefore a normal user can't
4306 * This is not an error, while the device perform scanning,
4307 * traffic doesn't flow, so it's a perfect DoS...
4310 if (orinoco_lock(priv, &flags) != 0)
4313 /* Scanning with port 0 disabled would fail */
4314 if (!netif_running(dev)) {
4319 /* In monitor mode, the scan results are always empty.
4320 * Probe responses are passed to the driver as received
4321 * frames and could be processed in software. */
4322 if (priv->iw_mode == IW_MODE_MONITOR) {
4327 /* Note : because we don't lock out the irq handler, the way
4328 * we access scan variables in priv is critical.
4329 * o scan_inprogress : not touched by irq handler
4330 * o scan_mode : not touched by irq handler
4331 * Before modifying anything on those variables, please think hard !
4335 priv->scan_mode = srq->flags;
4337 /* Always trigger scanning, even if it's in progress.
4338 * This way, if the info frame get lost, we will recover somewhat
4339 * gracefully - Jean II */
4341 if (priv->has_hostscan) {
4342 switch (priv->firmware_type) {
4343 case FIRMWARE_TYPE_SYMBOL:
4344 err = hermes_write_wordrec(hw, USER_BAP,
4345 HERMES_RID_CNFHOSTSCAN_SYMBOL,
4346 HERMES_HOSTSCAN_SYMBOL_ONCE |
4347 HERMES_HOSTSCAN_SYMBOL_BCAST);
4349 case FIRMWARE_TYPE_INTERSIL: {
4352 req[0] = cpu_to_le16(0x3fff); /* All channels */
4353 req[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
4354 req[2] = 0; /* Any ESSID */
4355 err = HERMES_WRITE_RECORD(hw, USER_BAP,
4356 HERMES_RID_CNFHOSTSCAN, &req);
4359 case FIRMWARE_TYPE_AGERE:
4360 if (priv->scan_mode & IW_SCAN_THIS_ESSID) {
4361 struct hermes_idstring idbuf;
4362 size_t len = min(sizeof(idbuf.val),
4363 (size_t) si->essid_len);
4364 idbuf.len = cpu_to_le16(len);
4365 memcpy(idbuf.val, si->essid, len);
4367 err = hermes_write_ltv(hw, USER_BAP,
4368 HERMES_RID_CNFSCANSSID_AGERE,
4369 HERMES_BYTES_TO_RECLEN(len + 2),
4372 err = hermes_write_wordrec(hw, USER_BAP,
4373 HERMES_RID_CNFSCANSSID_AGERE,
4378 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4382 err = hermes_inquire(hw, HERMES_INQ_SCAN);
4384 /* One more client */
4386 priv->scan_inprogress = 1;
4389 orinoco_unlock(priv, &flags);
4393 #define MAX_CUSTOM_LEN 64
4395 /* Translate scan data returned from the card to a card independant
4396 * format that the Wireless Tools will understand - Jean II */
4397 static inline char *orinoco_translate_scan(struct net_device *dev,
4398 struct iw_request_info *info,
4401 union hermes_scan_info *bss,
4402 unsigned int last_scanned)
4404 struct orinoco_private *priv = netdev_priv(dev);
4407 struct iw_event iwe; /* Temporary buffer */
4408 char custom[MAX_CUSTOM_LEN];
4410 memset(&iwe, 0, sizeof(iwe));
4412 /* First entry *MUST* be the AP MAC address */
4413 iwe.cmd = SIOCGIWAP;
4414 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
4415 memcpy(iwe.u.ap_addr.sa_data, bss->a.bssid, ETH_ALEN);
4416 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4417 &iwe, IW_EV_ADDR_LEN);
4419 /* Other entries will be displayed in the order we give them */
4422 iwe.u.data.length = le16_to_cpu(bss->a.essid_len);
4423 if (iwe.u.data.length > 32)
4424 iwe.u.data.length = 32;
4425 iwe.cmd = SIOCGIWESSID;
4426 iwe.u.data.flags = 1;
4427 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4428 &iwe, bss->a.essid);
4431 iwe.cmd = SIOCGIWMODE;
4432 capabilities = le16_to_cpu(bss->a.capabilities);
4433 if (capabilities & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
4434 if (capabilities & WLAN_CAPABILITY_ESS)
4435 iwe.u.mode = IW_MODE_MASTER;
4437 iwe.u.mode = IW_MODE_ADHOC;
4438 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4439 &iwe, IW_EV_UINT_LEN);
4442 channel = bss->s.channel;
4443 if ((channel >= 1) && (channel <= NUM_CHANNELS)) {
4444 /* Add channel and frequency */
4445 iwe.cmd = SIOCGIWFREQ;
4446 iwe.u.freq.m = channel;
4448 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4449 &iwe, IW_EV_FREQ_LEN);
4451 iwe.u.freq.m = channel_frequency[channel-1] * 100000;
4453 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4454 &iwe, IW_EV_FREQ_LEN);
4457 /* Add quality statistics. level and noise in dB. No link quality */
4459 iwe.u.qual.updated = IW_QUAL_DBM | IW_QUAL_QUAL_INVALID;
4460 iwe.u.qual.level = (__u8) le16_to_cpu(bss->a.level) - 0x95;
4461 iwe.u.qual.noise = (__u8) le16_to_cpu(bss->a.noise) - 0x95;
4462 /* Wireless tools prior to 27.pre22 will show link quality
4463 * anyway, so we provide a reasonable value. */
4464 if (iwe.u.qual.level > iwe.u.qual.noise)
4465 iwe.u.qual.qual = iwe.u.qual.level - iwe.u.qual.noise;
4467 iwe.u.qual.qual = 0;
4468 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
4469 &iwe, IW_EV_QUAL_LEN);
4471 /* Add encryption capability */
4472 iwe.cmd = SIOCGIWENCODE;
4473 if (capabilities & WLAN_CAPABILITY_PRIVACY)
4474 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
4476 iwe.u.data.flags = IW_ENCODE_DISABLED;
4477 iwe.u.data.length = 0;
4478 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4481 /* Bit rate is not available in Lucent/Agere firmwares */
4482 if (priv->firmware_type != FIRMWARE_TYPE_AGERE) {
4483 char *current_val = current_ev + iwe_stream_lcp_len(info);
4487 if (priv->firmware_type == FIRMWARE_TYPE_SYMBOL)
4492 iwe.cmd = SIOCGIWRATE;
4493 /* Those two flags are ignored... */
4494 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
4496 for (i = 0; i < 10; i += step) {
4497 /* NULL terminated */
4498 if (bss->p.rates[i] == 0x0)
4500 /* Bit rate given in 500 kb/s units (+ 0x80) */
4501 iwe.u.bitrate.value =
4502 ((bss->p.rates[i] & 0x7f) * 500000);
4503 current_val = iwe_stream_add_value(info, current_ev,
4508 /* Check if we added any event */
4509 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
4510 current_ev = current_val;
4513 /* Beacon interval */
4514 iwe.cmd = IWEVCUSTOM;
4515 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4517 le16_to_cpu(bss->a.beacon_interv));
4518 if (iwe.u.data.length)
4519 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4523 iwe.cmd = IWEVCUSTOM;
4524 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4527 if (iwe.u.data.length)
4528 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4531 /* Add EXTRA: Age to display seconds since last beacon/probe response
4532 * for given network. */
4533 iwe.cmd = IWEVCUSTOM;
4534 iwe.u.data.length = snprintf(custom, MAX_CUSTOM_LEN,
4535 " Last beacon: %dms ago",
4536 jiffies_to_msecs(jiffies - last_scanned));
4537 if (iwe.u.data.length)
4538 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
4544 /* Return results of a scan */
4545 static int orinoco_ioctl_getscan(struct net_device *dev,
4546 struct iw_request_info *info,
4547 struct iw_point *srq,
4550 struct orinoco_private *priv = netdev_priv(dev);
4551 struct bss_element *bss;
4553 unsigned long flags;
4554 char *current_ev = extra;
4556 if (orinoco_lock(priv, &flags) != 0)
4559 if (priv->scan_inprogress) {
4560 /* Important note : we don't want to block the caller
4561 * until results are ready for various reasons.
4562 * First, managing wait queues is complex and racy.
4563 * Second, we grab some rtnetlink lock before comming
4564 * here (in dev_ioctl()).
4565 * Third, we generate an Wireless Event, so the
4566 * caller can wait itself on that - Jean II */
4571 list_for_each_entry(bss, &priv->bss_list, list) {
4572 /* Translate to WE format this entry */
4573 current_ev = orinoco_translate_scan(dev, info, current_ev,
4574 extra + srq->length,
4578 /* Check if there is space for one more entry */
4579 if ((extra + srq->length - current_ev) <= IW_EV_ADDR_LEN) {
4580 /* Ask user space to try again with a bigger buffer */
4586 srq->length = (current_ev - extra);
4587 srq->flags = (__u16) priv->scan_mode;
4590 orinoco_unlock(priv, &flags);
4594 /* Commit handler, called after set operations */
4595 static int orinoco_ioctl_commit(struct net_device *dev,
4596 struct iw_request_info *info,
4600 struct orinoco_private *priv = netdev_priv(dev);
4601 struct hermes *hw = &priv->hw;
4602 unsigned long flags;
4608 if (priv->broken_disableport) {
4609 orinoco_reset(&priv->reset_work);
4613 if (orinoco_lock(priv, &flags) != 0)
4616 err = hermes_disable_port(hw, 0);
4618 printk(KERN_WARNING "%s: Unable to disable port "
4619 "while reconfiguring card\n", dev->name);
4620 priv->broken_disableport = 1;
4624 err = __orinoco_program_rids(dev);
4626 printk(KERN_WARNING "%s: Unable to reconfigure card\n",
4631 err = hermes_enable_port(hw, 0);
4633 printk(KERN_WARNING "%s: Unable to enable port while reconfiguring card\n",
4640 printk(KERN_WARNING "%s: Resetting instead...\n", dev->name);
4641 schedule_work(&priv->reset_work);
4645 orinoco_unlock(priv, &flags);
4649 static const struct iw_priv_args orinoco_privtab[] = {
4650 { SIOCIWFIRSTPRIV + 0x0, 0, 0, "force_reset" },
4651 { SIOCIWFIRSTPRIV + 0x1, 0, 0, "card_reset" },
4652 { SIOCIWFIRSTPRIV + 0x2, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4654 { SIOCIWFIRSTPRIV + 0x3, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4656 { SIOCIWFIRSTPRIV + 0x4, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4657 0, "set_preamble" },
4658 { SIOCIWFIRSTPRIV + 0x5, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4660 { SIOCIWFIRSTPRIV + 0x6, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4661 0, "set_ibssport" },
4662 { SIOCIWFIRSTPRIV + 0x7, 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
4664 { SIOCIWFIRSTPRIV + 0x9, 0, IW_PRIV_TYPE_BYTE | MAX_RID_LEN,
4670 * Structures to export the Wireless Handlers
4673 static const iw_handler orinoco_handler[] = {
4674 [SIOCSIWCOMMIT-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_commit,
4675 [SIOCGIWNAME -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getname,
4676 [SIOCSIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfreq,
4677 [SIOCGIWFREQ -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfreq,
4678 [SIOCSIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setmode,
4679 [SIOCGIWMODE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getmode,
4680 [SIOCSIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setsens,
4681 [SIOCGIWSENS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getsens,
4682 [SIOCGIWRANGE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwrange,
4683 [SIOCSIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_set_spy,
4684 [SIOCGIWSPY -SIOCIWFIRST] = (iw_handler) iw_handler_get_spy,
4685 [SIOCSIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_set_thrspy,
4686 [SIOCGIWTHRSPY-SIOCIWFIRST] = (iw_handler) iw_handler_get_thrspy,
4687 [SIOCSIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setwap,
4688 [SIOCGIWAP -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getwap,
4689 [SIOCSIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setscan,
4690 [SIOCGIWSCAN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getscan,
4691 [SIOCSIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setessid,
4692 [SIOCGIWESSID -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getessid,
4693 [SIOCSIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setnick,
4694 [SIOCGIWNICKN -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getnick,
4695 [SIOCSIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrate,
4696 [SIOCGIWRATE -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrate,
4697 [SIOCSIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setrts,
4698 [SIOCGIWRTS -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getrts,
4699 [SIOCSIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setfrag,
4700 [SIOCGIWFRAG -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getfrag,
4701 [SIOCGIWRETRY -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getretry,
4702 [SIOCSIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setiwencode,
4703 [SIOCGIWENCODE-SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getiwencode,
4704 [SIOCSIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_setpower,
4705 [SIOCGIWPOWER -SIOCIWFIRST] = (iw_handler) orinoco_ioctl_getpower,
4710 Added typecasting since we no longer use iwreq_data -- Moustafa
4712 static const iw_handler orinoco_private_handler[] = {
4713 [0] = (iw_handler) orinoco_ioctl_reset,
4714 [1] = (iw_handler) orinoco_ioctl_reset,
4715 [2] = (iw_handler) orinoco_ioctl_setport3,
4716 [3] = (iw_handler) orinoco_ioctl_getport3,
4717 [4] = (iw_handler) orinoco_ioctl_setpreamble,
4718 [5] = (iw_handler) orinoco_ioctl_getpreamble,
4719 [6] = (iw_handler) orinoco_ioctl_setibssport,
4720 [7] = (iw_handler) orinoco_ioctl_getibssport,
4721 [9] = (iw_handler) orinoco_ioctl_getrid,
4724 static const struct iw_handler_def orinoco_handler_def = {
4725 .num_standard = ARRAY_SIZE(orinoco_handler),
4726 .num_private = ARRAY_SIZE(orinoco_private_handler),
4727 .num_private_args = ARRAY_SIZE(orinoco_privtab),
4728 .standard = orinoco_handler,
4729 .private = orinoco_private_handler,
4730 .private_args = orinoco_privtab,
4731 .get_wireless_stats = orinoco_get_wireless_stats,
4734 static void orinoco_get_drvinfo(struct net_device *dev,
4735 struct ethtool_drvinfo *info)
4737 struct orinoco_private *priv = netdev_priv(dev);
4739 strncpy(info->driver, DRIVER_NAME, sizeof(info->driver) - 1);
4740 strncpy(info->version, DRIVER_VERSION, sizeof(info->version) - 1);
4741 strncpy(info->fw_version, priv->fw_name, sizeof(info->fw_version) - 1);
4742 if (dev->dev.parent)
4743 strncpy(info->bus_info, dev->dev.parent->bus_id,
4744 sizeof(info->bus_info) - 1);
4746 snprintf(info->bus_info, sizeof(info->bus_info) - 1,
4747 "PCMCIA %p", priv->hw.iobase);
4750 static const struct ethtool_ops orinoco_ethtool_ops = {
4751 .get_drvinfo = orinoco_get_drvinfo,
4752 .get_link = ethtool_op_get_link,
4755 /********************************************************************/
4756 /* Module initialization */
4757 /********************************************************************/
4759 EXPORT_SYMBOL(alloc_orinocodev);
4760 EXPORT_SYMBOL(free_orinocodev);
4762 EXPORT_SYMBOL(__orinoco_up);
4763 EXPORT_SYMBOL(__orinoco_down);
4764 EXPORT_SYMBOL(orinoco_reinit_firmware);
4766 EXPORT_SYMBOL(orinoco_interrupt);
4768 /* Can't be declared "const" or the whole __initdata section will
4770 static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
4771 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4772 "Pavel Roskin <proski@gnu.org>, et al)";
4774 static int __init init_orinoco(void)
4776 printk(KERN_DEBUG "%s\n", version);
4780 static void __exit exit_orinoco(void)
4784 module_init(init_orinoco);
4785 module_exit(exit_orinoco);