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/wireless.h>
86 #include <net/iw_handler.h>
87 #include <net/ieee80211.h>
89 #include "hermes_rid.h"
92 /********************************************************************/
93 /* Module information */
94 /********************************************************************/
96 MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
97 MODULE_DESCRIPTION("Driver for Lucent Orinoco, Prism II based and similar wireless cards");
98 MODULE_LICENSE("Dual MPL/GPL");
100 /* Level of debugging. Used in the macros in orinoco.h */
102 int orinoco_debug
= ORINOCO_DEBUG
;
103 module_param(orinoco_debug
, int, 0644);
104 MODULE_PARM_DESC(orinoco_debug
, "Debug level");
105 EXPORT_SYMBOL(orinoco_debug
);
108 static int suppress_linkstatus
; /* = 0 */
109 module_param(suppress_linkstatus
, bool, 0644);
110 MODULE_PARM_DESC(suppress_linkstatus
, "Don't log link status changes");
111 static int ignore_disconnect
; /* = 0 */
112 module_param(ignore_disconnect
, int, 0644);
113 MODULE_PARM_DESC(ignore_disconnect
, "Don't report lost link to the network layer");
115 static int force_monitor
; /* = 0 */
116 module_param(force_monitor
, int, 0644);
117 MODULE_PARM_DESC(force_monitor
, "Allow monitor mode for all firmware versions");
119 /********************************************************************/
120 /* Compile time configuration and compatibility stuff */
121 /********************************************************************/
123 /* We do this this way to avoid ifdefs in the actual code */
125 #define SPY_NUMBER(priv) (priv->spy_data.spy_number)
127 #define SPY_NUMBER(priv) 0
128 #endif /* WIRELESS_SPY */
130 /********************************************************************/
131 /* Internal constants */
132 /********************************************************************/
134 /* 802.2 LLC/SNAP header used for Ethernet encapsulation over 802.11 */
135 static const u8 encaps_hdr
[] = {0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00};
136 #define ENCAPS_OVERHEAD (sizeof(encaps_hdr) + 2)
138 #define ORINOCO_MIN_MTU 256
139 #define ORINOCO_MAX_MTU (IEEE80211_DATA_LEN - ENCAPS_OVERHEAD)
141 #define SYMBOL_MAX_VER_LEN (14)
144 #define MAX_IRQLOOPS_PER_IRQ 10
145 #define MAX_IRQLOOPS_PER_JIFFY (20000/HZ) /* Based on a guestimate of
146 * how many events the
148 * legitimately generate */
149 #define SMALL_KEY_SIZE 5
150 #define LARGE_KEY_SIZE 13
151 #define TX_NICBUF_SIZE_BUG 1585 /* Bug in Symbol firmware */
153 #define DUMMY_FID 0xFFFF
155 /*#define MAX_MULTICAST(priv) (priv->firmware_type == FIRMWARE_TYPE_AGERE ? \
156 HERMES_MAX_MULTICAST : 0)*/
157 #define MAX_MULTICAST(priv) (HERMES_MAX_MULTICAST)
159 #define ORINOCO_INTEN (HERMES_EV_RX | HERMES_EV_ALLOC \
160 | HERMES_EV_TX | HERMES_EV_TXEXC \
161 | HERMES_EV_WTERR | HERMES_EV_INFO \
162 | HERMES_EV_INFDROP )
164 #define MAX_RID_LEN 1024
166 static const struct iw_handler_def orinoco_handler_def
;
167 static struct ethtool_ops orinoco_ethtool_ops
;
169 /********************************************************************/
171 /********************************************************************/
173 /* The frequency of each channel in MHz */
174 static const long channel_frequency
[] = {
175 2412, 2417, 2422, 2427, 2432, 2437, 2442,
176 2447, 2452, 2457, 2462, 2467, 2472, 2484
178 #define NUM_CHANNELS ARRAY_SIZE(channel_frequency)
180 /* This tables gives the actual meanings of the bitrate IDs returned
181 * by the firmware. */
183 int bitrate
; /* in 100s of kilobits */
185 u16 agere_txratectrl
;
186 u16 intersil_txratectrl
;
187 } bitrate_table
[] = {
188 {110, 1, 3, 15}, /* Entry 0 is the default */
197 #define BITRATE_TABLE_SIZE ARRAY_SIZE(bitrate_table)
199 /********************************************************************/
201 /********************************************************************/
203 /* Beginning of the Tx descriptor, used in TxExc handling */
204 struct hermes_txexc_data
{
205 struct hermes_tx_descriptor desc
;
209 } __attribute__ ((packed
));
211 /* Rx frame header except compatibility 802.3 header */
212 struct hermes_rx_descriptor
{
233 } __attribute__ ((packed
));
235 /********************************************************************/
236 /* Function prototypes */
237 /********************************************************************/
239 static int __orinoco_program_rids(struct net_device
*dev
);
240 static void __orinoco_set_multicast_list(struct net_device
*dev
);
242 /********************************************************************/
243 /* Internal helper functions */
244 /********************************************************************/
246 static inline void set_port_type(struct orinoco_private
*priv
)
248 switch (priv
->iw_mode
) {
251 priv
->createibss
= 0;
254 if (priv
->prefer_port3
) {
256 priv
->createibss
= 0;
258 priv
->port_type
= priv
->ibss_port
;
259 priv
->createibss
= 1;
262 case IW_MODE_MONITOR
:
264 priv
->createibss
= 0;
267 printk(KERN_ERR
"%s: Invalid priv->iw_mode in set_port_type()\n",
272 /********************************************************************/
274 /********************************************************************/
276 static int orinoco_open(struct net_device
*dev
)
278 struct orinoco_private
*priv
= netdev_priv(dev
);
282 if (orinoco_lock(priv
, &flags
) != 0)
285 err
= __orinoco_up(dev
);
290 orinoco_unlock(priv
, &flags
);
295 static int orinoco_stop(struct net_device
*dev
)
297 struct orinoco_private
*priv
= netdev_priv(dev
);
300 /* We mustn't use orinoco_lock() here, because we need to be
301 able to close the interface even if hw_unavailable is set
302 (e.g. as we're released after a PC Card removal) */
303 orinoco_spin_lock(priv
);
307 err
= __orinoco_down(dev
);
309 orinoco_spin_unlock(priv
);
314 static struct net_device_stats
*orinoco_get_stats(struct net_device
*dev
)
316 struct orinoco_private
*priv
= netdev_priv(dev
);
321 static struct iw_statistics
*orinoco_get_wireless_stats(struct net_device
*dev
)
323 struct orinoco_private
*priv
= netdev_priv(dev
);
324 hermes_t
*hw
= &priv
->hw
;
325 struct iw_statistics
*wstats
= &priv
->wstats
;
329 if (! netif_device_present(dev
)) {
330 printk(KERN_WARNING
"%s: get_wireless_stats() called while device not present\n",
332 return NULL
; /* FIXME: Can we do better than this? */
335 /* If busy, return the old stats. Returning NULL may cause
336 * the interface to disappear from /proc/net/wireless */
337 if (orinoco_lock(priv
, &flags
) != 0)
340 /* We can't really wait for the tallies inquiry command to
341 * complete, so we just use the previous results and trigger
342 * a new tallies inquiry command for next time - Jean II */
343 /* FIXME: Really we should wait for the inquiry to come back -
344 * as it is the stats we give don't make a whole lot of sense.
345 * Unfortunately, it's not clear how to do that within the
346 * wireless extensions framework: I think we're in user
347 * context, but a lock seems to be held by the time we get in
348 * here so we're not safe to sleep here. */
349 hermes_inquire(hw
, HERMES_INQ_TALLIES
);
351 if (priv
->iw_mode
== IW_MODE_ADHOC
) {
352 memset(&wstats
->qual
, 0, sizeof(wstats
->qual
));
353 /* If a spy address is defined, we report stats of the
354 * first spy address - Jean II */
355 if (SPY_NUMBER(priv
)) {
356 wstats
->qual
.qual
= priv
->spy_data
.spy_stat
[0].qual
;
357 wstats
->qual
.level
= priv
->spy_data
.spy_stat
[0].level
;
358 wstats
->qual
.noise
= priv
->spy_data
.spy_stat
[0].noise
;
359 wstats
->qual
.updated
= priv
->spy_data
.spy_stat
[0].updated
;
363 __le16 qual
, signal
, noise
, unused
;
364 } __attribute__ ((packed
)) cq
;
366 err
= HERMES_READ_RECORD(hw
, USER_BAP
,
367 HERMES_RID_COMMSQUALITY
, &cq
);
370 wstats
->qual
.qual
= (int)le16_to_cpu(cq
.qual
);
371 wstats
->qual
.level
= (int)le16_to_cpu(cq
.signal
) - 0x95;
372 wstats
->qual
.noise
= (int)le16_to_cpu(cq
.noise
) - 0x95;
373 wstats
->qual
.updated
= 7;
377 orinoco_unlock(priv
, &flags
);
381 static void orinoco_set_multicast_list(struct net_device
*dev
)
383 struct orinoco_private
*priv
= netdev_priv(dev
);
386 if (orinoco_lock(priv
, &flags
) != 0) {
387 printk(KERN_DEBUG
"%s: orinoco_set_multicast_list() "
388 "called when hw_unavailable\n", dev
->name
);
392 __orinoco_set_multicast_list(dev
);
393 orinoco_unlock(priv
, &flags
);
396 static int orinoco_change_mtu(struct net_device
*dev
, int new_mtu
)
398 struct orinoco_private
*priv
= netdev_priv(dev
);
400 if ( (new_mtu
< ORINOCO_MIN_MTU
) || (new_mtu
> ORINOCO_MAX_MTU
) )
403 if ( (new_mtu
+ ENCAPS_OVERHEAD
+ IEEE80211_HLEN
) >
404 (priv
->nicbuf_size
- ETH_HLEN
) )
412 /********************************************************************/
414 /********************************************************************/
416 static int orinoco_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
418 struct orinoco_private
*priv
= netdev_priv(dev
);
419 struct net_device_stats
*stats
= &priv
->stats
;
420 hermes_t
*hw
= &priv
->hw
;
422 u16 txfid
= priv
->txfid
;
425 struct hermes_tx_descriptor desc
;
428 if (! netif_running(dev
)) {
429 printk(KERN_ERR
"%s: Tx on stopped device!\n",
431 return NETDEV_TX_BUSY
;
434 if (netif_queue_stopped(dev
)) {
435 printk(KERN_DEBUG
"%s: Tx while transmitter busy!\n",
437 return NETDEV_TX_BUSY
;
440 if (orinoco_lock(priv
, &flags
) != 0) {
441 printk(KERN_ERR
"%s: orinoco_xmit() called while hw_unavailable\n",
443 return NETDEV_TX_BUSY
;
446 if (! netif_carrier_ok(dev
) || (priv
->iw_mode
== IW_MODE_MONITOR
)) {
447 /* Oops, the firmware hasn't established a connection,
448 silently drop the packet (this seems to be the
453 /* Check packet length */
454 if (skb
->len
< ETH_HLEN
)
457 eh
= (struct ethhdr
*)skb
->data
;
459 memset(&desc
, 0, sizeof(desc
));
460 desc
.tx_control
= cpu_to_le16(HERMES_TXCTRL_TX_OK
| HERMES_TXCTRL_TX_EX
);
461 err
= hermes_bap_pwrite(hw
, USER_BAP
, &desc
, sizeof(desc
), txfid
, 0);
464 printk(KERN_ERR
"%s: Error %d writing Tx descriptor "
465 "to BAP\n", dev
->name
, err
);
469 /* Clear the 802.11 header and data length fields - some
470 * firmwares (e.g. Lucent/Agere 8.xx) appear to get confused
471 * if this isn't done. */
472 hermes_clear_words(hw
, HERMES_DATA0
,
473 HERMES_802_3_OFFSET
- HERMES_802_11_OFFSET
);
475 /* Encapsulate Ethernet-II frames */
476 if (ntohs(eh
->h_proto
) > ETH_DATA_LEN
) { /* Ethernet-II frame */
477 struct header_struct
{
478 struct ethhdr eth
; /* 802.3 header */
479 u8 encap
[6]; /* 802.2 header */
480 } __attribute__ ((packed
)) hdr
;
482 /* Strip destination and source from the data */
483 skb_pull(skb
, 2 * ETH_ALEN
);
484 data_off
= HERMES_802_2_OFFSET
+ sizeof(encaps_hdr
);
486 /* And move them to a separate header */
487 memcpy(&hdr
.eth
, eh
, 2 * ETH_ALEN
);
488 hdr
.eth
.h_proto
= htons(sizeof(encaps_hdr
) + skb
->len
);
489 memcpy(hdr
.encap
, encaps_hdr
, sizeof(encaps_hdr
));
491 err
= hermes_bap_pwrite(hw
, USER_BAP
, &hdr
, sizeof(hdr
),
492 txfid
, HERMES_802_3_OFFSET
);
495 printk(KERN_ERR
"%s: Error %d writing packet "
496 "header to BAP\n", dev
->name
, err
);
499 } else { /* IEEE 802.3 frame */
500 data_off
= HERMES_802_3_OFFSET
;
503 err
= hermes_bap_pwrite(hw
, USER_BAP
, skb
->data
, skb
->len
,
506 printk(KERN_ERR
"%s: Error %d writing packet to BAP\n",
511 /* Finally, we actually initiate the send */
512 netif_stop_queue(dev
);
514 err
= hermes_docmd_wait(hw
, HERMES_CMD_TX
| HERMES_CMD_RECL
,
517 netif_start_queue(dev
);
519 printk(KERN_ERR
"%s: Error %d transmitting packet\n",
524 dev
->trans_start
= jiffies
;
525 stats
->tx_bytes
+= data_off
+ skb
->len
;
533 orinoco_unlock(priv
, &flags
);
538 orinoco_unlock(priv
, &flags
);
539 return NETDEV_TX_BUSY
;
542 static void __orinoco_ev_alloc(struct net_device
*dev
, hermes_t
*hw
)
544 struct orinoco_private
*priv
= netdev_priv(dev
);
545 u16 fid
= hermes_read_regn(hw
, ALLOCFID
);
547 if (fid
!= priv
->txfid
) {
548 if (fid
!= DUMMY_FID
)
549 printk(KERN_WARNING
"%s: Allocate event on unexpected fid (%04X)\n",
554 hermes_write_regn(hw
, ALLOCFID
, DUMMY_FID
);
557 static void __orinoco_ev_tx(struct net_device
*dev
, hermes_t
*hw
)
559 struct orinoco_private
*priv
= netdev_priv(dev
);
560 struct net_device_stats
*stats
= &priv
->stats
;
564 netif_wake_queue(dev
);
566 hermes_write_regn(hw
, TXCOMPLFID
, DUMMY_FID
);
569 static void __orinoco_ev_txexc(struct net_device
*dev
, hermes_t
*hw
)
571 struct orinoco_private
*priv
= netdev_priv(dev
);
572 struct net_device_stats
*stats
= &priv
->stats
;
573 u16 fid
= hermes_read_regn(hw
, TXCOMPLFID
);
575 struct hermes_txexc_data hdr
;
578 if (fid
== DUMMY_FID
)
579 return; /* Nothing's really happened */
581 /* Read part of the frame header - we need status and addr1 */
582 err
= hermes_bap_pread(hw
, IRQ_BAP
, &hdr
,
583 sizeof(struct hermes_txexc_data
),
586 hermes_write_regn(hw
, TXCOMPLFID
, DUMMY_FID
);
590 printk(KERN_WARNING
"%s: Unable to read descriptor on Tx error "
591 "(FID=%04X error %d)\n",
592 dev
->name
, fid
, err
);
596 DEBUG(1, "%s: Tx error, err %d (FID=%04X)\n", dev
->name
,
599 /* We produce a TXDROP event only for retry or lifetime
600 * exceeded, because that's the only status that really mean
601 * that this particular node went away.
602 * Other errors means that *we* screwed up. - Jean II */
603 status
= le16_to_cpu(hdr
.desc
.status
);
604 if (status
& (HERMES_TXSTAT_RETRYERR
| HERMES_TXSTAT_AGEDERR
)) {
605 union iwreq_data wrqu
;
607 /* Copy 802.11 dest address.
608 * We use the 802.11 header because the frame may
609 * not be 802.3 or may be mangled...
610 * In Ad-Hoc mode, it will be the node address.
611 * In managed mode, it will be most likely the AP addr
612 * User space will figure out how to convert it to
613 * whatever it needs (IP address or else).
615 memcpy(wrqu
.addr
.sa_data
, hdr
.addr1
, ETH_ALEN
);
616 wrqu
.addr
.sa_family
= ARPHRD_ETHER
;
618 /* Send event to user space */
619 wireless_send_event(dev
, IWEVTXDROP
, &wrqu
, NULL
);
622 netif_wake_queue(dev
);
625 static void orinoco_tx_timeout(struct net_device
*dev
)
627 struct orinoco_private
*priv
= netdev_priv(dev
);
628 struct net_device_stats
*stats
= &priv
->stats
;
629 struct hermes
*hw
= &priv
->hw
;
631 printk(KERN_WARNING
"%s: Tx timeout! "
632 "ALLOCFID=%04x, TXCOMPLFID=%04x, EVSTAT=%04x\n",
633 dev
->name
, hermes_read_regn(hw
, ALLOCFID
),
634 hermes_read_regn(hw
, TXCOMPLFID
), hermes_read_regn(hw
, EVSTAT
));
638 schedule_work(&priv
->reset_work
);
641 /********************************************************************/
642 /* Rx path (data frames) */
643 /********************************************************************/
645 /* Does the frame have a SNAP header indicating it should be
646 * de-encapsulated to Ethernet-II? */
647 static inline int is_ethersnap(void *_hdr
)
651 /* We de-encapsulate all packets which, a) have SNAP headers
652 * (i.e. SSAP=DSAP=0xaa and CTRL=0x3 in the 802.2 LLC header
653 * and where b) the OUI of the SNAP header is 00:00:00 or
654 * 00:00:f8 - we need both because different APs appear to use
655 * different OUIs for some reason */
656 return (memcmp(hdr
, &encaps_hdr
, 5) == 0)
657 && ( (hdr
[5] == 0x00) || (hdr
[5] == 0xf8) );
660 static inline void orinoco_spy_gather(struct net_device
*dev
, u_char
*mac
,
661 int level
, int noise
)
663 struct iw_quality wstats
;
664 wstats
.level
= level
- 0x95;
665 wstats
.noise
= noise
- 0x95;
666 wstats
.qual
= (level
> noise
) ? (level
- noise
) : 0;
668 /* Update spy records */
669 wireless_spy_update(dev
, mac
, &wstats
);
672 static void orinoco_stat_gather(struct net_device
*dev
,
674 struct hermes_rx_descriptor
*desc
)
676 struct orinoco_private
*priv
= netdev_priv(dev
);
678 /* Using spy support with lots of Rx packets, like in an
679 * infrastructure (AP), will really slow down everything, because
680 * the MAC address must be compared to each entry of the spy list.
681 * If the user really asks for it (set some address in the
682 * spy list), we do it, but he will pay the price.
683 * Note that to get here, you need both WIRELESS_SPY
684 * compiled in AND some addresses in the list !!!
686 /* Note : gcc will optimise the whole section away if
687 * WIRELESS_SPY is not defined... - Jean II */
688 if (SPY_NUMBER(priv
)) {
689 orinoco_spy_gather(dev
, skb_mac_header(skb
) + ETH_ALEN
,
690 desc
->signal
, desc
->silence
);
695 * orinoco_rx_monitor - handle received monitor frames.
700 * desc rx descriptor of the frame
702 * Call context: interrupt
704 static void orinoco_rx_monitor(struct net_device
*dev
, u16 rxfid
,
705 struct hermes_rx_descriptor
*desc
)
707 u32 hdrlen
= 30; /* return full header by default */
713 struct orinoco_private
*priv
= netdev_priv(dev
);
714 struct net_device_stats
*stats
= &priv
->stats
;
715 hermes_t
*hw
= &priv
->hw
;
717 len
= le16_to_cpu(desc
->data_len
);
719 /* Determine the size of the header and the data */
720 fc
= le16_to_cpu(desc
->frame_ctl
);
721 switch (fc
& IEEE80211_FCTL_FTYPE
) {
722 case IEEE80211_FTYPE_DATA
:
723 if ((fc
& IEEE80211_FCTL_TODS
)
724 && (fc
& IEEE80211_FCTL_FROMDS
))
730 case IEEE80211_FTYPE_MGMT
:
734 case IEEE80211_FTYPE_CTL
:
735 switch (fc
& IEEE80211_FCTL_STYPE
) {
736 case IEEE80211_STYPE_PSPOLL
:
737 case IEEE80211_STYPE_RTS
:
738 case IEEE80211_STYPE_CFEND
:
739 case IEEE80211_STYPE_CFENDACK
:
742 case IEEE80211_STYPE_CTS
:
743 case IEEE80211_STYPE_ACK
:
749 /* Unknown frame type */
753 /* sanity check the length */
754 if (datalen
> IEEE80211_DATA_LEN
+ 12) {
755 printk(KERN_DEBUG
"%s: oversized monitor frame, "
756 "data length = %d\n", dev
->name
, datalen
);
758 stats
->rx_length_errors
++;
762 skb
= dev_alloc_skb(hdrlen
+ datalen
);
764 printk(KERN_WARNING
"%s: Cannot allocate skb for monitor frame\n",
770 /* Copy the 802.11 header to the skb */
771 memcpy(skb_put(skb
, hdrlen
), &(desc
->frame_ctl
), hdrlen
);
772 skb_reset_mac_header(skb
);
774 /* If any, copy the data from the card to the skb */
776 err
= hermes_bap_pread(hw
, IRQ_BAP
, skb_put(skb
, datalen
),
777 ALIGN(datalen
, 2), rxfid
,
778 HERMES_802_2_OFFSET
);
780 printk(KERN_ERR
"%s: error %d reading monitor frame\n",
787 skb
->ip_summed
= CHECKSUM_NONE
;
788 skb
->pkt_type
= PACKET_OTHERHOST
;
789 skb
->protocol
= __constant_htons(ETH_P_802_2
);
791 dev
->last_rx
= jiffies
;
793 stats
->rx_bytes
+= skb
->len
;
799 dev_kfree_skb_irq(skb
);
805 void __orinoco_ev_rx(struct net_device
*dev
, hermes_t
*hw
)
807 struct orinoco_private
*priv
= netdev_priv(dev
);
808 struct net_device_stats
*stats
= &priv
->stats
;
809 struct iw_statistics
*wstats
= &priv
->wstats
;
810 struct sk_buff
*skb
= NULL
;
811 u16 rxfid
, status
, fc
;
813 struct hermes_rx_descriptor desc
;
817 rxfid
= hermes_read_regn(hw
, RXFID
);
819 err
= hermes_bap_pread(hw
, IRQ_BAP
, &desc
, sizeof(desc
),
822 printk(KERN_ERR
"%s: error %d reading Rx descriptor. "
823 "Frame dropped.\n", dev
->name
, err
);
827 status
= le16_to_cpu(desc
.status
);
829 if (status
& HERMES_RXSTAT_BADCRC
) {
830 DEBUG(1, "%s: Bad CRC on Rx. Frame dropped.\n",
832 stats
->rx_crc_errors
++;
836 /* Handle frames in monitor mode */
837 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
838 orinoco_rx_monitor(dev
, rxfid
, &desc
);
842 if (status
& HERMES_RXSTAT_UNDECRYPTABLE
) {
843 DEBUG(1, "%s: Undecryptable frame on Rx. Frame dropped.\n",
845 wstats
->discard
.code
++;
849 length
= le16_to_cpu(desc
.data_len
);
850 fc
= le16_to_cpu(desc
.frame_ctl
);
853 if (length
< 3) { /* No for even an 802.2 LLC header */
854 /* At least on Symbol firmware with PCF we get quite a
855 lot of these legitimately - Poll frames with no
859 if (length
> IEEE80211_DATA_LEN
) {
860 printk(KERN_WARNING
"%s: Oversized frame received (%d bytes)\n",
862 stats
->rx_length_errors
++;
866 /* We need space for the packet data itself, plus an ethernet
867 header, plus 2 bytes so we can align the IP header on a
868 32bit boundary, plus 1 byte so we can read in odd length
869 packets from the card, which has an IO granularity of 16
871 skb
= dev_alloc_skb(length
+ETH_HLEN
+2+1);
873 printk(KERN_WARNING
"%s: Can't allocate skb for Rx\n",
878 /* We'll prepend the header, so reserve space for it. The worst
879 case is no decapsulation, when 802.3 header is prepended and
880 nothing is removed. 2 is for aligning the IP header. */
881 skb_reserve(skb
, ETH_HLEN
+ 2);
883 err
= hermes_bap_pread(hw
, IRQ_BAP
, skb_put(skb
, length
),
884 ALIGN(length
, 2), rxfid
,
885 HERMES_802_2_OFFSET
);
887 printk(KERN_ERR
"%s: error %d reading frame. "
888 "Frame dropped.\n", dev
->name
, err
);
892 /* Handle decapsulation
893 * In most cases, the firmware tell us about SNAP frames.
894 * For some reason, the SNAP frames sent by LinkSys APs
895 * are not properly recognised by most firmwares.
896 * So, check ourselves */
897 if (length
>= ENCAPS_OVERHEAD
&&
898 (((status
& HERMES_RXSTAT_MSGTYPE
) == HERMES_RXSTAT_1042
) ||
899 ((status
& HERMES_RXSTAT_MSGTYPE
) == HERMES_RXSTAT_TUNNEL
) ||
900 is_ethersnap(skb
->data
))) {
901 /* These indicate a SNAP within 802.2 LLC within
902 802.11 frame which we'll need to de-encapsulate to
903 the original EthernetII frame. */
904 hdr
= (struct ethhdr
*)skb_push(skb
, ETH_HLEN
- ENCAPS_OVERHEAD
);
906 /* 802.3 frame - prepend 802.3 header as is */
907 hdr
= (struct ethhdr
*)skb_push(skb
, ETH_HLEN
);
908 hdr
->h_proto
= htons(length
);
910 memcpy(hdr
->h_dest
, desc
.addr1
, ETH_ALEN
);
911 if (fc
& IEEE80211_FCTL_FROMDS
)
912 memcpy(hdr
->h_source
, desc
.addr3
, ETH_ALEN
);
914 memcpy(hdr
->h_source
, desc
.addr2
, ETH_ALEN
);
916 dev
->last_rx
= jiffies
;
918 skb
->protocol
= eth_type_trans(skb
, dev
);
919 skb
->ip_summed
= CHECKSUM_NONE
;
920 if (fc
& IEEE80211_FCTL_TODS
)
921 skb
->pkt_type
= PACKET_OTHERHOST
;
923 /* Process the wireless stats if needed */
924 orinoco_stat_gather(dev
, skb
, &desc
);
926 /* Pass the packet to the networking stack */
929 stats
->rx_bytes
+= length
;
934 dev_kfree_skb_irq(skb
);
940 /********************************************************************/
941 /* Rx path (info frames) */
942 /********************************************************************/
944 static void print_linkstatus(struct net_device
*dev
, u16 status
)
948 if (suppress_linkstatus
)
952 case HERMES_LINKSTATUS_NOT_CONNECTED
:
955 case HERMES_LINKSTATUS_CONNECTED
:
958 case HERMES_LINKSTATUS_DISCONNECTED
:
961 case HERMES_LINKSTATUS_AP_CHANGE
:
964 case HERMES_LINKSTATUS_AP_OUT_OF_RANGE
:
965 s
= "AP Out of Range";
967 case HERMES_LINKSTATUS_AP_IN_RANGE
:
970 case HERMES_LINKSTATUS_ASSOC_FAILED
:
971 s
= "Association Failed";
977 printk(KERN_INFO
"%s: New link status: %s (%04x)\n",
978 dev
->name
, s
, status
);
981 /* Search scan results for requested BSSID, join it if found */
982 static void orinoco_join_ap(struct work_struct
*work
)
984 struct orinoco_private
*priv
=
985 container_of(work
, struct orinoco_private
, join_work
);
986 struct net_device
*dev
= priv
->ndev
;
987 struct hermes
*hw
= &priv
->hw
;
993 } __attribute__ ((packed
)) req
;
994 const int atom_len
= offsetof(struct prism2_scan_apinfo
, atim
);
995 struct prism2_scan_apinfo
*atom
= NULL
;
1001 /* Allocate buffer for scan results */
1002 buf
= kmalloc(MAX_SCAN_LEN
, GFP_KERNEL
);
1006 if (orinoco_lock(priv
, &flags
) != 0)
1009 /* Sanity checks in case user changed something in the meantime */
1010 if (! priv
->bssid_fixed
)
1013 if (strlen(priv
->desired_essid
) == 0)
1016 /* Read scan results from the firmware */
1017 err
= hermes_read_ltv(hw
, USER_BAP
,
1018 HERMES_RID_SCANRESULTSTABLE
,
1019 MAX_SCAN_LEN
, &len
, buf
);
1021 printk(KERN_ERR
"%s: Cannot read scan results\n",
1026 len
= HERMES_RECLEN_TO_BYTES(len
);
1028 /* Go through the scan results looking for the channel of the AP
1029 * we were requested to join */
1030 for (; offset
+ atom_len
<= len
; offset
+= atom_len
) {
1031 atom
= (struct prism2_scan_apinfo
*) (buf
+ offset
);
1032 if (memcmp(&atom
->bssid
, priv
->desired_bssid
, ETH_ALEN
) == 0) {
1039 DEBUG(1, "%s: Requested AP not found in scan results\n",
1044 memcpy(req
.bssid
, priv
->desired_bssid
, ETH_ALEN
);
1045 req
.channel
= atom
->channel
; /* both are little-endian */
1046 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
, HERMES_RID_CNFJOINREQUEST
,
1049 printk(KERN_ERR
"%s: Error issuing join request\n", dev
->name
);
1052 orinoco_unlock(priv
, &flags
);
1058 /* Send new BSSID to userspace */
1059 static void orinoco_send_wevents(struct work_struct
*work
)
1061 struct orinoco_private
*priv
=
1062 container_of(work
, struct orinoco_private
, wevent_work
);
1063 struct net_device
*dev
= priv
->ndev
;
1064 struct hermes
*hw
= &priv
->hw
;
1065 union iwreq_data wrqu
;
1067 unsigned long flags
;
1069 if (orinoco_lock(priv
, &flags
) != 0)
1072 err
= hermes_read_ltv(hw
, IRQ_BAP
, HERMES_RID_CURRENTBSSID
,
1073 ETH_ALEN
, NULL
, wrqu
.ap_addr
.sa_data
);
1077 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1079 /* Send event to user space */
1080 wireless_send_event(dev
, SIOCGIWAP
, &wrqu
, NULL
);
1083 orinoco_unlock(priv
, &flags
);
1086 void __orinoco_ev_info(struct net_device
*dev
, hermes_t
*hw
)
1088 struct orinoco_private
*priv
= netdev_priv(dev
);
1093 } __attribute__ ((packed
)) info
;
1097 /* This is an answer to an INQUIRE command that we did earlier,
1098 * or an information "event" generated by the card
1099 * The controller return to us a pseudo frame containing
1100 * the information in question - Jean II */
1101 infofid
= hermes_read_regn(hw
, INFOFID
);
1103 /* Read the info frame header - don't try too hard */
1104 err
= hermes_bap_pread(hw
, IRQ_BAP
, &info
, sizeof(info
),
1107 printk(KERN_ERR
"%s: error %d reading info frame. "
1108 "Frame dropped.\n", dev
->name
, err
);
1112 len
= HERMES_RECLEN_TO_BYTES(le16_to_cpu(info
.len
));
1113 type
= le16_to_cpu(info
.type
);
1116 case HERMES_INQ_TALLIES
: {
1117 struct hermes_tallies_frame tallies
;
1118 struct iw_statistics
*wstats
= &priv
->wstats
;
1120 if (len
> sizeof(tallies
)) {
1121 printk(KERN_WARNING
"%s: Tallies frame too long (%d bytes)\n",
1123 len
= sizeof(tallies
);
1126 err
= hermes_bap_pread(hw
, IRQ_BAP
, &tallies
, len
,
1127 infofid
, sizeof(info
));
1131 /* Increment our various counters */
1132 /* wstats->discard.nwid - no wrong BSSID stuff */
1133 wstats
->discard
.code
+=
1134 le16_to_cpu(tallies
.RxWEPUndecryptable
);
1135 if (len
== sizeof(tallies
))
1136 wstats
->discard
.code
+=
1137 le16_to_cpu(tallies
.RxDiscards_WEPICVError
) +
1138 le16_to_cpu(tallies
.RxDiscards_WEPExcluded
);
1139 wstats
->discard
.misc
+=
1140 le16_to_cpu(tallies
.TxDiscardsWrongSA
);
1141 wstats
->discard
.fragment
+=
1142 le16_to_cpu(tallies
.RxMsgInBadMsgFragments
);
1143 wstats
->discard
.retries
+=
1144 le16_to_cpu(tallies
.TxRetryLimitExceeded
);
1145 /* wstats->miss.beacon - no match */
1148 case HERMES_INQ_LINKSTATUS
: {
1149 struct hermes_linkstatus linkstatus
;
1153 if (priv
->iw_mode
== IW_MODE_MONITOR
)
1156 if (len
!= sizeof(linkstatus
)) {
1157 printk(KERN_WARNING
"%s: Unexpected size for linkstatus frame (%d bytes)\n",
1162 err
= hermes_bap_pread(hw
, IRQ_BAP
, &linkstatus
, len
,
1163 infofid
, sizeof(info
));
1166 newstatus
= le16_to_cpu(linkstatus
.linkstatus
);
1168 /* Symbol firmware uses "out of range" to signal that
1169 * the hostscan frame can be requested. */
1170 if (newstatus
== HERMES_LINKSTATUS_AP_OUT_OF_RANGE
&&
1171 priv
->firmware_type
== FIRMWARE_TYPE_SYMBOL
&&
1172 priv
->has_hostscan
&& priv
->scan_inprogress
) {
1173 hermes_inquire(hw
, HERMES_INQ_HOSTSCAN_SYMBOL
);
1177 connected
= (newstatus
== HERMES_LINKSTATUS_CONNECTED
)
1178 || (newstatus
== HERMES_LINKSTATUS_AP_CHANGE
)
1179 || (newstatus
== HERMES_LINKSTATUS_AP_IN_RANGE
);
1182 netif_carrier_on(dev
);
1183 else if (!ignore_disconnect
)
1184 netif_carrier_off(dev
);
1186 if (newstatus
!= priv
->last_linkstatus
) {
1187 priv
->last_linkstatus
= newstatus
;
1188 print_linkstatus(dev
, newstatus
);
1189 /* The info frame contains only one word which is the
1190 * status (see hermes.h). The status is pretty boring
1191 * in itself, that's why we export the new BSSID...
1193 schedule_work(&priv
->wevent_work
);
1197 case HERMES_INQ_SCAN
:
1198 if (!priv
->scan_inprogress
&& priv
->bssid_fixed
&&
1199 priv
->firmware_type
== FIRMWARE_TYPE_INTERSIL
) {
1200 schedule_work(&priv
->join_work
);
1204 case HERMES_INQ_HOSTSCAN
:
1205 case HERMES_INQ_HOSTSCAN_SYMBOL
: {
1206 /* Result of a scanning. Contains information about
1207 * cells in the vicinity - Jean II */
1208 union iwreq_data wrqu
;
1213 printk(KERN_WARNING
"%s: Scan results too large (%d bytes)\n",
1218 /* We are a strict producer. If the previous scan results
1219 * have not been consumed, we just have to drop this
1220 * frame. We can't remove the previous results ourselves,
1221 * that would be *very* racy... Jean II */
1222 if (priv
->scan_result
!= NULL
) {
1223 printk(KERN_WARNING
"%s: Previous scan results not consumed, dropping info frame.\n", dev
->name
);
1227 /* Allocate buffer for results */
1228 buf
= kmalloc(len
, GFP_ATOMIC
);
1230 /* No memory, so can't printk()... */
1233 /* Read scan data */
1234 err
= hermes_bap_pread(hw
, IRQ_BAP
, (void *) buf
, len
,
1235 infofid
, sizeof(info
));
1241 #ifdef ORINOCO_DEBUG
1244 printk(KERN_DEBUG
"Scan result [%02X", buf
[0]);
1245 for(i
= 1; i
< (len
* 2); i
++)
1246 printk(":%02X", buf
[i
]);
1249 #endif /* ORINOCO_DEBUG */
1251 /* Allow the clients to access the results */
1252 priv
->scan_len
= len
;
1253 priv
->scan_result
= buf
;
1255 /* Send an empty event to user space.
1256 * We don't send the received data on the event because
1257 * it would require us to do complex transcoding, and
1258 * we want to minimise the work done in the irq handler
1259 * Use a request to extract the data - Jean II */
1260 wrqu
.data
.length
= 0;
1261 wrqu
.data
.flags
= 0;
1262 wireless_send_event(dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
1265 case HERMES_INQ_SEC_STAT_AGERE
:
1266 /* Security status (Agere specific) */
1267 /* Ignore this frame for now */
1268 if (priv
->firmware_type
== FIRMWARE_TYPE_AGERE
)
1272 printk(KERN_DEBUG
"%s: Unknown information frame received: "
1273 "type 0x%04x, length %d\n", dev
->name
, type
, len
);
1274 /* We don't actually do anything about it */
1279 static void __orinoco_ev_infdrop(struct net_device
*dev
, hermes_t
*hw
)
1281 if (net_ratelimit())
1282 printk(KERN_DEBUG
"%s: Information frame lost.\n", dev
->name
);
1285 /********************************************************************/
1286 /* Internal hardware control routines */
1287 /********************************************************************/
1289 int __orinoco_up(struct net_device
*dev
)
1291 struct orinoco_private
*priv
= netdev_priv(dev
);
1292 struct hermes
*hw
= &priv
->hw
;
1295 netif_carrier_off(dev
); /* just to make sure */
1297 err
= __orinoco_program_rids(dev
);
1299 printk(KERN_ERR
"%s: Error %d configuring card\n",
1304 /* Fire things up again */
1305 hermes_set_irqmask(hw
, ORINOCO_INTEN
);
1306 err
= hermes_enable_port(hw
, 0);
1308 printk(KERN_ERR
"%s: Error %d enabling MAC port\n",
1313 netif_start_queue(dev
);
1318 int __orinoco_down(struct net_device
*dev
)
1320 struct orinoco_private
*priv
= netdev_priv(dev
);
1321 struct hermes
*hw
= &priv
->hw
;
1324 netif_stop_queue(dev
);
1326 if (! priv
->hw_unavailable
) {
1327 if (! priv
->broken_disableport
) {
1328 err
= hermes_disable_port(hw
, 0);
1330 /* Some firmwares (e.g. Intersil 1.3.x) seem
1331 * to have problems disabling the port, oh
1333 printk(KERN_WARNING
"%s: Error %d disabling MAC port\n",
1335 priv
->broken_disableport
= 1;
1338 hermes_set_irqmask(hw
, 0);
1339 hermes_write_regn(hw
, EVACK
, 0xffff);
1342 /* firmware will have to reassociate */
1343 netif_carrier_off(dev
);
1344 priv
->last_linkstatus
= 0xffff;
1349 static int orinoco_allocate_fid(struct net_device
*dev
)
1351 struct orinoco_private
*priv
= netdev_priv(dev
);
1352 struct hermes
*hw
= &priv
->hw
;
1355 err
= hermes_allocate(hw
, priv
->nicbuf_size
, &priv
->txfid
);
1356 if (err
== -EIO
&& priv
->nicbuf_size
> TX_NICBUF_SIZE_BUG
) {
1357 /* Try workaround for old Symbol firmware bug */
1358 printk(KERN_WARNING
"%s: firmware ALLOC bug detected "
1359 "(old Symbol firmware?). Trying to work around... ",
1362 priv
->nicbuf_size
= TX_NICBUF_SIZE_BUG
;
1363 err
= hermes_allocate(hw
, priv
->nicbuf_size
, &priv
->txfid
);
1365 printk("failed!\n");
1373 int orinoco_reinit_firmware(struct net_device
*dev
)
1375 struct orinoco_private
*priv
= netdev_priv(dev
);
1376 struct hermes
*hw
= &priv
->hw
;
1379 err
= hermes_init(hw
);
1381 err
= orinoco_allocate_fid(dev
);
1386 static int __orinoco_hw_set_bitrate(struct orinoco_private
*priv
)
1388 hermes_t
*hw
= &priv
->hw
;
1391 if (priv
->bitratemode
>= BITRATE_TABLE_SIZE
) {
1392 printk(KERN_ERR
"%s: BUG: Invalid bitrate mode %d\n",
1393 priv
->ndev
->name
, priv
->bitratemode
);
1397 switch (priv
->firmware_type
) {
1398 case FIRMWARE_TYPE_AGERE
:
1399 err
= hermes_write_wordrec(hw
, USER_BAP
,
1400 HERMES_RID_CNFTXRATECONTROL
,
1401 bitrate_table
[priv
->bitratemode
].agere_txratectrl
);
1403 case FIRMWARE_TYPE_INTERSIL
:
1404 case FIRMWARE_TYPE_SYMBOL
:
1405 err
= hermes_write_wordrec(hw
, USER_BAP
,
1406 HERMES_RID_CNFTXRATECONTROL
,
1407 bitrate_table
[priv
->bitratemode
].intersil_txratectrl
);
1416 /* Set fixed AP address */
1417 static int __orinoco_hw_set_wap(struct orinoco_private
*priv
)
1421 hermes_t
*hw
= &priv
->hw
;
1423 switch (priv
->firmware_type
) {
1424 case FIRMWARE_TYPE_AGERE
:
1427 case FIRMWARE_TYPE_INTERSIL
:
1428 if (priv
->bssid_fixed
)
1433 err
= hermes_write_wordrec(hw
, USER_BAP
,
1434 HERMES_RID_CNFROAMINGMODE
,
1437 case FIRMWARE_TYPE_SYMBOL
:
1438 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
1439 HERMES_RID_CNFMANDATORYBSSID_SYMBOL
,
1440 &priv
->desired_bssid
);
1446 /* Change the WEP keys and/or the current keys. Can be called
1447 * either from __orinoco_hw_setup_wep() or directly from
1448 * orinoco_ioctl_setiwencode(). In the later case the association
1449 * with the AP is not broken (if the firmware can handle it),
1450 * which is needed for 802.1x implementations. */
1451 static int __orinoco_hw_setup_wepkeys(struct orinoco_private
*priv
)
1453 hermes_t
*hw
= &priv
->hw
;
1456 switch (priv
->firmware_type
) {
1457 case FIRMWARE_TYPE_AGERE
:
1458 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
1459 HERMES_RID_CNFWEPKEYS_AGERE
,
1463 err
= hermes_write_wordrec(hw
, USER_BAP
,
1464 HERMES_RID_CNFTXKEY_AGERE
,
1469 case FIRMWARE_TYPE_INTERSIL
:
1470 case FIRMWARE_TYPE_SYMBOL
:
1475 /* Force uniform key length to work around firmware bugs */
1476 keylen
= le16_to_cpu(priv
->keys
[priv
->tx_key
].len
);
1478 if (keylen
> LARGE_KEY_SIZE
) {
1479 printk(KERN_ERR
"%s: BUG: Key %d has oversize length %d.\n",
1480 priv
->ndev
->name
, priv
->tx_key
, keylen
);
1484 /* Write all 4 keys */
1485 for(i
= 0; i
< ORINOCO_MAX_KEYS
; i
++) {
1486 err
= hermes_write_ltv(hw
, USER_BAP
,
1487 HERMES_RID_CNFDEFAULTKEY0
+ i
,
1488 HERMES_BYTES_TO_RECLEN(keylen
),
1489 priv
->keys
[i
].data
);
1494 /* Write the index of the key used in transmission */
1495 err
= hermes_write_wordrec(hw
, USER_BAP
,
1496 HERMES_RID_CNFWEPDEFAULTKEYID
,
1507 static int __orinoco_hw_setup_wep(struct orinoco_private
*priv
)
1509 hermes_t
*hw
= &priv
->hw
;
1511 int master_wep_flag
;
1515 __orinoco_hw_setup_wepkeys(priv
);
1517 if (priv
->wep_restrict
)
1518 auth_flag
= HERMES_AUTH_SHARED_KEY
;
1520 auth_flag
= HERMES_AUTH_OPEN
;
1522 switch (priv
->firmware_type
) {
1523 case FIRMWARE_TYPE_AGERE
: /* Agere style WEP */
1525 /* Enable the shared-key authentication. */
1526 err
= hermes_write_wordrec(hw
, USER_BAP
,
1527 HERMES_RID_CNFAUTHENTICATION_AGERE
,
1530 err
= hermes_write_wordrec(hw
, USER_BAP
,
1531 HERMES_RID_CNFWEPENABLED_AGERE
,
1537 case FIRMWARE_TYPE_INTERSIL
: /* Intersil style WEP */
1538 case FIRMWARE_TYPE_SYMBOL
: /* Symbol style WEP */
1540 if (priv
->wep_restrict
||
1541 (priv
->firmware_type
== FIRMWARE_TYPE_SYMBOL
))
1542 master_wep_flag
= HERMES_WEP_PRIVACY_INVOKED
|
1543 HERMES_WEP_EXCL_UNENCRYPTED
;
1545 master_wep_flag
= HERMES_WEP_PRIVACY_INVOKED
;
1547 err
= hermes_write_wordrec(hw
, USER_BAP
,
1548 HERMES_RID_CNFAUTHENTICATION
,
1553 master_wep_flag
= 0;
1555 if (priv
->iw_mode
== IW_MODE_MONITOR
)
1556 master_wep_flag
|= HERMES_WEP_HOST_DECRYPT
;
1558 /* Master WEP setting : on/off */
1559 err
= hermes_write_wordrec(hw
, USER_BAP
,
1560 HERMES_RID_CNFWEPFLAGS_INTERSIL
,
1571 static int __orinoco_program_rids(struct net_device
*dev
)
1573 struct orinoco_private
*priv
= netdev_priv(dev
);
1574 hermes_t
*hw
= &priv
->hw
;
1576 struct hermes_idstring idbuf
;
1578 /* Set the MAC address */
1579 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNMACADDR
,
1580 HERMES_BYTES_TO_RECLEN(ETH_ALEN
), dev
->dev_addr
);
1582 printk(KERN_ERR
"%s: Error %d setting MAC address\n",
1587 /* Set up the link mode */
1588 err
= hermes_write_wordrec(hw
, USER_BAP
, HERMES_RID_CNFPORTTYPE
,
1591 printk(KERN_ERR
"%s: Error %d setting port type\n",
1595 /* Set the channel/frequency */
1596 if (priv
->channel
!= 0 && priv
->iw_mode
!= IW_MODE_INFRA
) {
1597 err
= hermes_write_wordrec(hw
, USER_BAP
,
1598 HERMES_RID_CNFOWNCHANNEL
,
1601 printk(KERN_ERR
"%s: Error %d setting channel %d\n",
1602 dev
->name
, err
, priv
->channel
);
1607 if (priv
->has_ibss
) {
1610 if ((strlen(priv
->desired_essid
) == 0) && (priv
->createibss
)) {
1611 printk(KERN_WARNING
"%s: This firmware requires an "
1612 "ESSID in IBSS-Ad-Hoc mode.\n", dev
->name
);
1613 /* With wvlan_cs, in this case, we would crash.
1614 * hopefully, this driver will behave better...
1618 createibss
= priv
->createibss
;
1621 err
= hermes_write_wordrec(hw
, USER_BAP
,
1622 HERMES_RID_CNFCREATEIBSS
,
1625 printk(KERN_ERR
"%s: Error %d setting CREATEIBSS\n",
1631 /* Set the desired BSSID */
1632 err
= __orinoco_hw_set_wap(priv
);
1634 printk(KERN_ERR
"%s: Error %d setting AP address\n",
1638 /* Set the desired ESSID */
1639 idbuf
.len
= cpu_to_le16(strlen(priv
->desired_essid
));
1640 memcpy(&idbuf
.val
, priv
->desired_essid
, sizeof(idbuf
.val
));
1641 /* WinXP wants partner to configure OWNSSID even in IBSS mode. (jimc) */
1642 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNSSID
,
1643 HERMES_BYTES_TO_RECLEN(strlen(priv
->desired_essid
)+2),
1646 printk(KERN_ERR
"%s: Error %d setting OWNSSID\n",
1650 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFDESIREDSSID
,
1651 HERMES_BYTES_TO_RECLEN(strlen(priv
->desired_essid
)+2),
1654 printk(KERN_ERR
"%s: Error %d setting DESIREDSSID\n",
1659 /* Set the station name */
1660 idbuf
.len
= cpu_to_le16(strlen(priv
->nick
));
1661 memcpy(&idbuf
.val
, priv
->nick
, sizeof(idbuf
.val
));
1662 err
= hermes_write_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNNAME
,
1663 HERMES_BYTES_TO_RECLEN(strlen(priv
->nick
)+2),
1666 printk(KERN_ERR
"%s: Error %d setting nickname\n",
1671 /* Set AP density */
1672 if (priv
->has_sensitivity
) {
1673 err
= hermes_write_wordrec(hw
, USER_BAP
,
1674 HERMES_RID_CNFSYSTEMSCALE
,
1677 printk(KERN_WARNING
"%s: Error %d setting SYSTEMSCALE. "
1678 "Disabling sensitivity control\n",
1681 priv
->has_sensitivity
= 0;
1685 /* Set RTS threshold */
1686 err
= hermes_write_wordrec(hw
, USER_BAP
, HERMES_RID_CNFRTSTHRESHOLD
,
1689 printk(KERN_ERR
"%s: Error %d setting RTS threshold\n",
1694 /* Set fragmentation threshold or MWO robustness */
1696 err
= hermes_write_wordrec(hw
, USER_BAP
,
1697 HERMES_RID_CNFMWOROBUST_AGERE
,
1700 err
= hermes_write_wordrec(hw
, USER_BAP
,
1701 HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
1704 printk(KERN_ERR
"%s: Error %d setting fragmentation\n",
1710 err
= __orinoco_hw_set_bitrate(priv
);
1712 printk(KERN_ERR
"%s: Error %d setting bitrate\n",
1717 /* Set power management */
1719 err
= hermes_write_wordrec(hw
, USER_BAP
,
1720 HERMES_RID_CNFPMENABLED
,
1723 printk(KERN_ERR
"%s: Error %d setting up PM\n",
1728 err
= hermes_write_wordrec(hw
, USER_BAP
,
1729 HERMES_RID_CNFMULTICASTRECEIVE
,
1732 printk(KERN_ERR
"%s: Error %d setting up PM\n",
1736 err
= hermes_write_wordrec(hw
, USER_BAP
,
1737 HERMES_RID_CNFMAXSLEEPDURATION
,
1740 printk(KERN_ERR
"%s: Error %d setting up PM\n",
1744 err
= hermes_write_wordrec(hw
, USER_BAP
,
1745 HERMES_RID_CNFPMHOLDOVERDURATION
,
1748 printk(KERN_ERR
"%s: Error %d setting up PM\n",
1754 /* Set preamble - only for Symbol so far... */
1755 if (priv
->has_preamble
) {
1756 err
= hermes_write_wordrec(hw
, USER_BAP
,
1757 HERMES_RID_CNFPREAMBLE_SYMBOL
,
1760 printk(KERN_ERR
"%s: Error %d setting preamble\n",
1766 /* Set up encryption */
1767 if (priv
->has_wep
) {
1768 err
= __orinoco_hw_setup_wep(priv
);
1770 printk(KERN_ERR
"%s: Error %d activating WEP\n",
1776 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
1777 /* Enable monitor mode */
1778 dev
->type
= ARPHRD_IEEE80211
;
1779 err
= hermes_docmd_wait(hw
, HERMES_CMD_TEST
|
1780 HERMES_TEST_MONITOR
, 0, NULL
);
1782 /* Disable monitor mode */
1783 dev
->type
= ARPHRD_ETHER
;
1784 err
= hermes_docmd_wait(hw
, HERMES_CMD_TEST
|
1785 HERMES_TEST_STOP
, 0, NULL
);
1790 /* Set promiscuity / multicast*/
1791 priv
->promiscuous
= 0;
1793 __orinoco_set_multicast_list(dev
); /* FIXME: what about the xmit_lock */
1798 /* FIXME: return int? */
1800 __orinoco_set_multicast_list(struct net_device
*dev
)
1802 struct orinoco_private
*priv
= netdev_priv(dev
);
1803 hermes_t
*hw
= &priv
->hw
;
1805 int promisc
, mc_count
;
1807 /* The Hermes doesn't seem to have an allmulti mode, so we go
1808 * into promiscuous mode and let the upper levels deal. */
1809 if ( (dev
->flags
& IFF_PROMISC
) || (dev
->flags
& IFF_ALLMULTI
) ||
1810 (dev
->mc_count
> MAX_MULTICAST(priv
)) ) {
1815 mc_count
= dev
->mc_count
;
1818 if (promisc
!= priv
->promiscuous
) {
1819 err
= hermes_write_wordrec(hw
, USER_BAP
,
1820 HERMES_RID_CNFPROMISCUOUSMODE
,
1823 printk(KERN_ERR
"%s: Error %d setting PROMISCUOUSMODE to 1.\n",
1826 priv
->promiscuous
= promisc
;
1829 /* If we're not in promiscuous mode, then we need to set the
1830 * group address if either we want to multicast, or if we were
1831 * multicasting and want to stop */
1832 if (! promisc
&& (mc_count
|| priv
->mc_count
) ) {
1833 struct dev_mc_list
*p
= dev
->mc_list
;
1834 struct hermes_multicast mclist
;
1837 for (i
= 0; i
< mc_count
; i
++) {
1838 /* paranoia: is list shorter than mc_count? */
1840 /* paranoia: bad address size in list? */
1841 BUG_ON(p
->dmi_addrlen
!= ETH_ALEN
);
1843 memcpy(mclist
.addr
[i
], p
->dmi_addr
, ETH_ALEN
);
1848 printk(KERN_WARNING
"%s: Multicast list is "
1849 "longer than mc_count\n", dev
->name
);
1851 err
= hermes_write_ltv(hw
, USER_BAP
,
1852 HERMES_RID_CNFGROUPADDRESSES
,
1853 HERMES_BYTES_TO_RECLEN(mc_count
* ETH_ALEN
),
1856 printk(KERN_ERR
"%s: Error %d setting multicast list.\n",
1859 priv
->mc_count
= mc_count
;
1863 /* This must be called from user context, without locks held - use
1864 * schedule_work() */
1865 static void orinoco_reset(struct work_struct
*work
)
1867 struct orinoco_private
*priv
=
1868 container_of(work
, struct orinoco_private
, reset_work
);
1869 struct net_device
*dev
= priv
->ndev
;
1870 struct hermes
*hw
= &priv
->hw
;
1872 unsigned long flags
;
1874 if (orinoco_lock(priv
, &flags
) != 0)
1875 /* When the hardware becomes available again, whatever
1876 * detects that is responsible for re-initializing
1877 * it. So no need for anything further */
1880 netif_stop_queue(dev
);
1882 /* Shut off interrupts. Depending on what state the hardware
1883 * is in, this might not work, but we'll try anyway */
1884 hermes_set_irqmask(hw
, 0);
1885 hermes_write_regn(hw
, EVACK
, 0xffff);
1887 priv
->hw_unavailable
++;
1888 priv
->last_linkstatus
= 0xffff; /* firmware will have to reassociate */
1889 netif_carrier_off(dev
);
1891 orinoco_unlock(priv
, &flags
);
1893 /* Scanning support: Cleanup of driver struct */
1894 kfree(priv
->scan_result
);
1895 priv
->scan_result
= NULL
;
1896 priv
->scan_inprogress
= 0;
1898 if (priv
->hard_reset
) {
1899 err
= (*priv
->hard_reset
)(priv
);
1901 printk(KERN_ERR
"%s: orinoco_reset: Error %d "
1902 "performing hard reset\n", dev
->name
, err
);
1907 err
= orinoco_reinit_firmware(dev
);
1909 printk(KERN_ERR
"%s: orinoco_reset: Error %d re-initializing firmware\n",
1914 orinoco_spin_lock(priv
); /* This has to be called from user context */
1916 priv
->hw_unavailable
--;
1918 /* priv->open or priv->hw_unavailable might have changed while
1919 * we dropped the lock */
1920 if (priv
->open
&& (! priv
->hw_unavailable
)) {
1921 err
= __orinoco_up(dev
);
1923 printk(KERN_ERR
"%s: orinoco_reset: Error %d reenabling card\n",
1926 dev
->trans_start
= jiffies
;
1929 orinoco_spin_unlock(priv
);
1933 hermes_set_irqmask(hw
, 0);
1934 netif_device_detach(dev
);
1935 printk(KERN_ERR
"%s: Device has been disabled!\n", dev
->name
);
1938 /********************************************************************/
1939 /* Interrupt handler */
1940 /********************************************************************/
1942 static void __orinoco_ev_tick(struct net_device
*dev
, hermes_t
*hw
)
1944 printk(KERN_DEBUG
"%s: TICK\n", dev
->name
);
1947 static void __orinoco_ev_wterr(struct net_device
*dev
, hermes_t
*hw
)
1949 /* This seems to happen a fair bit under load, but ignoring it
1950 seems to work fine...*/
1951 printk(KERN_DEBUG
"%s: MAC controller error (WTERR). Ignoring.\n",
1955 irqreturn_t
orinoco_interrupt(int irq
, void *dev_id
)
1957 struct net_device
*dev
= dev_id
;
1958 struct orinoco_private
*priv
= netdev_priv(dev
);
1959 hermes_t
*hw
= &priv
->hw
;
1960 int count
= MAX_IRQLOOPS_PER_IRQ
;
1962 /* These are used to detect a runaway interrupt situation */
1963 /* If we get more than MAX_IRQLOOPS_PER_JIFFY iterations in a jiffy,
1964 * we panic and shut down the hardware */
1965 static int last_irq_jiffy
= 0; /* jiffies value the last time
1967 static int loops_this_jiffy
= 0;
1968 unsigned long flags
;
1970 if (orinoco_lock(priv
, &flags
) != 0) {
1971 /* If hw is unavailable - we don't know if the irq was
1976 evstat
= hermes_read_regn(hw
, EVSTAT
);
1977 events
= evstat
& hw
->inten
;
1979 orinoco_unlock(priv
, &flags
);
1983 if (jiffies
!= last_irq_jiffy
)
1984 loops_this_jiffy
= 0;
1985 last_irq_jiffy
= jiffies
;
1987 while (events
&& count
--) {
1988 if (++loops_this_jiffy
> MAX_IRQLOOPS_PER_JIFFY
) {
1989 printk(KERN_WARNING
"%s: IRQ handler is looping too "
1990 "much! Resetting.\n", dev
->name
);
1991 /* Disable interrupts for now */
1992 hermes_set_irqmask(hw
, 0);
1993 schedule_work(&priv
->reset_work
);
1997 /* Check the card hasn't been removed */
1998 if (! hermes_present(hw
)) {
1999 DEBUG(0, "orinoco_interrupt(): card removed\n");
2003 if (events
& HERMES_EV_TICK
)
2004 __orinoco_ev_tick(dev
, hw
);
2005 if (events
& HERMES_EV_WTERR
)
2006 __orinoco_ev_wterr(dev
, hw
);
2007 if (events
& HERMES_EV_INFDROP
)
2008 __orinoco_ev_infdrop(dev
, hw
);
2009 if (events
& HERMES_EV_INFO
)
2010 __orinoco_ev_info(dev
, hw
);
2011 if (events
& HERMES_EV_RX
)
2012 __orinoco_ev_rx(dev
, hw
);
2013 if (events
& HERMES_EV_TXEXC
)
2014 __orinoco_ev_txexc(dev
, hw
);
2015 if (events
& HERMES_EV_TX
)
2016 __orinoco_ev_tx(dev
, hw
);
2017 if (events
& HERMES_EV_ALLOC
)
2018 __orinoco_ev_alloc(dev
, hw
);
2020 hermes_write_regn(hw
, EVACK
, evstat
);
2022 evstat
= hermes_read_regn(hw
, EVSTAT
);
2023 events
= evstat
& hw
->inten
;
2026 orinoco_unlock(priv
, &flags
);
2030 /********************************************************************/
2031 /* Initialization */
2032 /********************************************************************/
2035 u16 id
, variant
, major
, minor
;
2036 } __attribute__ ((packed
));
2038 static inline fwtype_t
determine_firmware_type(struct comp_id
*nic_id
)
2040 if (nic_id
->id
< 0x8000)
2041 return FIRMWARE_TYPE_AGERE
;
2042 else if (nic_id
->id
== 0x8000 && nic_id
->major
== 0)
2043 return FIRMWARE_TYPE_SYMBOL
;
2045 return FIRMWARE_TYPE_INTERSIL
;
2048 /* Set priv->firmware type, determine firmware properties */
2049 static int determine_firmware(struct net_device
*dev
)
2051 struct orinoco_private
*priv
= netdev_priv(dev
);
2052 hermes_t
*hw
= &priv
->hw
;
2054 struct comp_id nic_id
, sta_id
;
2055 unsigned int firmver
;
2056 char tmp
[SYMBOL_MAX_VER_LEN
+1] __attribute__((aligned(2)));
2058 /* Get the hardware version */
2059 err
= HERMES_READ_RECORD(hw
, USER_BAP
, HERMES_RID_NICID
, &nic_id
);
2061 printk(KERN_ERR
"%s: Cannot read hardware identity: error %d\n",
2066 le16_to_cpus(&nic_id
.id
);
2067 le16_to_cpus(&nic_id
.variant
);
2068 le16_to_cpus(&nic_id
.major
);
2069 le16_to_cpus(&nic_id
.minor
);
2070 printk(KERN_DEBUG
"%s: Hardware identity %04x:%04x:%04x:%04x\n",
2071 dev
->name
, nic_id
.id
, nic_id
.variant
,
2072 nic_id
.major
, nic_id
.minor
);
2074 priv
->firmware_type
= determine_firmware_type(&nic_id
);
2076 /* Get the firmware version */
2077 err
= HERMES_READ_RECORD(hw
, USER_BAP
, HERMES_RID_STAID
, &sta_id
);
2079 printk(KERN_ERR
"%s: Cannot read station identity: error %d\n",
2084 le16_to_cpus(&sta_id
.id
);
2085 le16_to_cpus(&sta_id
.variant
);
2086 le16_to_cpus(&sta_id
.major
);
2087 le16_to_cpus(&sta_id
.minor
);
2088 printk(KERN_DEBUG
"%s: Station identity %04x:%04x:%04x:%04x\n",
2089 dev
->name
, sta_id
.id
, sta_id
.variant
,
2090 sta_id
.major
, sta_id
.minor
);
2092 switch (sta_id
.id
) {
2094 printk(KERN_ERR
"%s: Primary firmware is active\n",
2098 printk(KERN_ERR
"%s: Tertiary firmware is active\n",
2101 case 0x1f: /* Intersil, Agere, Symbol Spectrum24 */
2102 case 0x21: /* Symbol Spectrum24 Trilogy */
2105 printk(KERN_NOTICE
"%s: Unknown station ID, please report\n",
2110 /* Default capabilities */
2111 priv
->has_sensitivity
= 1;
2113 priv
->has_preamble
= 0;
2114 priv
->has_port3
= 1;
2117 priv
->has_big_wep
= 0;
2119 /* Determine capabilities from the firmware version */
2120 switch (priv
->firmware_type
) {
2121 case FIRMWARE_TYPE_AGERE
:
2122 /* Lucent Wavelan IEEE, Lucent Orinoco, Cabletron RoamAbout,
2123 ELSA, Melco, HP, IBM, Dell 1150, Compaq 110/210 */
2124 snprintf(priv
->fw_name
, sizeof(priv
->fw_name
) - 1,
2125 "Lucent/Agere %d.%02d", sta_id
.major
, sta_id
.minor
);
2127 firmver
= ((unsigned long)sta_id
.major
<< 16) | sta_id
.minor
;
2129 priv
->has_ibss
= (firmver
>= 0x60006);
2130 priv
->has_wep
= (firmver
>= 0x40020);
2131 priv
->has_big_wep
= 1; /* FIXME: this is wrong - how do we tell
2132 Gold cards from the others? */
2133 priv
->has_mwo
= (firmver
>= 0x60000);
2134 priv
->has_pm
= (firmver
>= 0x40020); /* Don't work in 7.52 ? */
2135 priv
->ibss_port
= 1;
2136 priv
->has_hostscan
= (firmver
>= 0x8000a);
2137 priv
->broken_monitor
= (firmver
>= 0x80000);
2139 /* Tested with Agere firmware :
2140 * 1.16 ; 4.08 ; 4.52 ; 6.04 ; 6.16 ; 7.28 => Jean II
2141 * Tested CableTron firmware : 4.32 => Anton */
2143 case FIRMWARE_TYPE_SYMBOL
:
2144 /* Symbol , 3Com AirConnect, Intel, Ericsson WLAN */
2145 /* Intel MAC : 00:02:B3:* */
2146 /* 3Com MAC : 00:50:DA:* */
2147 memset(tmp
, 0, sizeof(tmp
));
2148 /* Get the Symbol firmware version */
2149 err
= hermes_read_ltv(hw
, USER_BAP
,
2150 HERMES_RID_SECONDARYVERSION_SYMBOL
,
2151 SYMBOL_MAX_VER_LEN
, NULL
, &tmp
);
2154 "%s: Error %d reading Symbol firmware info. Wildly guessing capabilities...\n",
2159 /* The firmware revision is a string, the format is
2160 * something like : "V2.20-01".
2161 * Quick and dirty parsing... - Jean II
2163 firmver
= ((tmp
[1] - '0') << 16) | ((tmp
[3] - '0') << 12)
2164 | ((tmp
[4] - '0') << 8) | ((tmp
[6] - '0') << 4)
2167 tmp
[SYMBOL_MAX_VER_LEN
] = '\0';
2170 snprintf(priv
->fw_name
, sizeof(priv
->fw_name
) - 1,
2173 priv
->has_ibss
= (firmver
>= 0x20000);
2174 priv
->has_wep
= (firmver
>= 0x15012);
2175 priv
->has_big_wep
= (firmver
>= 0x20000);
2176 priv
->has_pm
= (firmver
>= 0x20000 && firmver
< 0x22000) ||
2177 (firmver
>= 0x29000 && firmver
< 0x30000) ||
2179 priv
->has_preamble
= (firmver
>= 0x20000);
2180 priv
->ibss_port
= 4;
2181 priv
->broken_disableport
= (firmver
== 0x25013) ||
2182 (firmver
>= 0x30000 && firmver
<= 0x31000);
2183 priv
->has_hostscan
= (firmver
>= 0x31001) ||
2184 (firmver
>= 0x29057 && firmver
< 0x30000);
2185 /* Tested with Intel firmware : 0x20015 => Jean II */
2186 /* Tested with 3Com firmware : 0x15012 & 0x22001 => Jean II */
2188 case FIRMWARE_TYPE_INTERSIL
:
2189 /* D-Link, Linksys, Adtron, ZoomAir, and many others...
2190 * Samsung, Compaq 100/200 and Proxim are slightly
2191 * different and less well tested */
2192 /* D-Link MAC : 00:40:05:* */
2193 /* Addtron MAC : 00:90:D1:* */
2194 snprintf(priv
->fw_name
, sizeof(priv
->fw_name
) - 1,
2195 "Intersil %d.%d.%d", sta_id
.major
, sta_id
.minor
,
2198 firmver
= ((unsigned long)sta_id
.major
<< 16) |
2199 ((unsigned long)sta_id
.minor
<< 8) | sta_id
.variant
;
2201 priv
->has_ibss
= (firmver
>= 0x000700); /* FIXME */
2202 priv
->has_big_wep
= priv
->has_wep
= (firmver
>= 0x000800);
2203 priv
->has_pm
= (firmver
>= 0x000700);
2204 priv
->has_hostscan
= (firmver
>= 0x010301);
2206 if (firmver
>= 0x000800)
2207 priv
->ibss_port
= 0;
2209 printk(KERN_NOTICE
"%s: Intersil firmware earlier "
2210 "than v0.8.x - several features not supported\n",
2212 priv
->ibss_port
= 1;
2216 printk(KERN_DEBUG
"%s: Firmware determined as %s\n", dev
->name
,
2222 static int orinoco_init(struct net_device
*dev
)
2224 struct orinoco_private
*priv
= netdev_priv(dev
);
2225 hermes_t
*hw
= &priv
->hw
;
2227 struct hermes_idstring nickbuf
;
2230 DECLARE_MAC_BUF(mac
);
2232 /* No need to lock, the hw_unavailable flag is already set in
2233 * alloc_orinocodev() */
2234 priv
->nicbuf_size
= IEEE80211_FRAME_LEN
+ ETH_HLEN
;
2236 /* Initialize the firmware */
2237 err
= hermes_init(hw
);
2239 printk(KERN_ERR
"%s: failed to initialize firmware (err = %d)\n",
2244 err
= determine_firmware(dev
);
2246 printk(KERN_ERR
"%s: Incompatible firmware, aborting\n",
2251 if (priv
->has_port3
)
2252 printk(KERN_DEBUG
"%s: Ad-hoc demo mode supported\n", dev
->name
);
2254 printk(KERN_DEBUG
"%s: IEEE standard IBSS ad-hoc mode supported\n",
2256 if (!priv
->has_big_wep
)
2257 printk(KERN_NOTICE
"%s: Only 40-bit WEP keys supported\n",
2260 /* Get the MAC address */
2261 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNMACADDR
,
2262 ETH_ALEN
, NULL
, dev
->dev_addr
);
2264 printk(KERN_WARNING
"%s: failed to read MAC address!\n",
2269 printk(KERN_DEBUG
"%s: MAC address %s\n",
2270 dev
->name
, print_mac(mac
, dev
->dev_addr
));
2272 /* Get the station name */
2273 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CNFOWNNAME
,
2274 sizeof(nickbuf
), &reclen
, &nickbuf
);
2276 printk(KERN_ERR
"%s: failed to read station name\n",
2281 len
= min(IW_ESSID_MAX_SIZE
, (int)le16_to_cpu(nickbuf
.len
));
2283 len
= min(IW_ESSID_MAX_SIZE
, 2 * reclen
);
2284 memcpy(priv
->nick
, &nickbuf
.val
, len
);
2285 priv
->nick
[len
] = '\0';
2287 printk(KERN_DEBUG
"%s: Station name \"%s\"\n", dev
->name
, priv
->nick
);
2289 err
= orinoco_allocate_fid(dev
);
2291 printk(KERN_ERR
"%s: failed to allocate NIC buffer!\n",
2296 /* Get allowed channels */
2297 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CHANNELLIST
,
2298 &priv
->channel_mask
);
2300 printk(KERN_ERR
"%s: failed to read channel list!\n",
2305 /* Get initial AP density */
2306 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFSYSTEMSCALE
,
2308 if (err
|| priv
->ap_density
< 1 || priv
->ap_density
> 3) {
2309 priv
->has_sensitivity
= 0;
2312 /* Get initial RTS threshold */
2313 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFRTSTHRESHOLD
,
2316 printk(KERN_ERR
"%s: failed to read RTS threshold!\n",
2321 /* Get initial fragmentation settings */
2323 err
= hermes_read_wordrec(hw
, USER_BAP
,
2324 HERMES_RID_CNFMWOROBUST_AGERE
,
2327 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
2328 &priv
->frag_thresh
);
2330 printk(KERN_ERR
"%s: failed to read fragmentation settings!\n",
2335 /* Power management setup */
2339 err
= hermes_read_wordrec(hw
, USER_BAP
,
2340 HERMES_RID_CNFMAXSLEEPDURATION
,
2343 printk(KERN_ERR
"%s: failed to read power management period!\n",
2347 err
= hermes_read_wordrec(hw
, USER_BAP
,
2348 HERMES_RID_CNFPMHOLDOVERDURATION
,
2351 printk(KERN_ERR
"%s: failed to read power management timeout!\n",
2357 /* Preamble setup */
2358 if (priv
->has_preamble
) {
2359 err
= hermes_read_wordrec(hw
, USER_BAP
,
2360 HERMES_RID_CNFPREAMBLE_SYMBOL
,
2366 /* Set up the default configuration */
2367 priv
->iw_mode
= IW_MODE_INFRA
;
2368 /* By default use IEEE/IBSS ad-hoc mode if we have it */
2369 priv
->prefer_port3
= priv
->has_port3
&& (! priv
->has_ibss
);
2370 set_port_type(priv
);
2371 priv
->channel
= 0; /* use firmware default */
2373 priv
->promiscuous
= 0;
2377 /* Make the hardware available, as long as it hasn't been
2378 * removed elsewhere (e.g. by PCMCIA hot unplug) */
2379 orinoco_spin_lock(priv
);
2380 priv
->hw_unavailable
--;
2381 orinoco_spin_unlock(priv
);
2383 printk(KERN_DEBUG
"%s: ready\n", dev
->name
);
2389 struct net_device
*alloc_orinocodev(int sizeof_card
,
2390 int (*hard_reset
)(struct orinoco_private
*))
2392 struct net_device
*dev
;
2393 struct orinoco_private
*priv
;
2395 dev
= alloc_etherdev(sizeof(struct orinoco_private
) + sizeof_card
);
2398 priv
= netdev_priv(dev
);
2401 priv
->card
= (void *)((unsigned long)priv
2402 + sizeof(struct orinoco_private
));
2406 /* Setup / override net_device fields */
2407 dev
->init
= orinoco_init
;
2408 dev
->hard_start_xmit
= orinoco_xmit
;
2409 dev
->tx_timeout
= orinoco_tx_timeout
;
2410 dev
->watchdog_timeo
= HZ
; /* 1 second timeout */
2411 dev
->get_stats
= orinoco_get_stats
;
2412 dev
->ethtool_ops
= &orinoco_ethtool_ops
;
2413 dev
->wireless_handlers
= (struct iw_handler_def
*)&orinoco_handler_def
;
2415 priv
->wireless_data
.spy_data
= &priv
->spy_data
;
2416 dev
->wireless_data
= &priv
->wireless_data
;
2418 dev
->change_mtu
= orinoco_change_mtu
;
2419 dev
->set_multicast_list
= orinoco_set_multicast_list
;
2420 /* we use the default eth_mac_addr for setting the MAC addr */
2422 /* Set up default callbacks */
2423 dev
->open
= orinoco_open
;
2424 dev
->stop
= orinoco_stop
;
2425 priv
->hard_reset
= hard_reset
;
2427 spin_lock_init(&priv
->lock
);
2429 priv
->hw_unavailable
= 1; /* orinoco_init() must clear this
2430 * before anything else touches the
2432 INIT_WORK(&priv
->reset_work
, orinoco_reset
);
2433 INIT_WORK(&priv
->join_work
, orinoco_join_ap
);
2434 INIT_WORK(&priv
->wevent_work
, orinoco_send_wevents
);
2436 netif_carrier_off(dev
);
2437 priv
->last_linkstatus
= 0xffff;
2442 void free_orinocodev(struct net_device
*dev
)
2444 struct orinoco_private
*priv
= netdev_priv(dev
);
2446 kfree(priv
->scan_result
);
2450 /********************************************************************/
2451 /* Wireless extensions */
2452 /********************************************************************/
2454 /* Return : < 0 -> error code ; >= 0 -> length */
2455 static int orinoco_hw_get_essid(struct orinoco_private
*priv
, int *active
,
2456 char buf
[IW_ESSID_MAX_SIZE
+1])
2458 hermes_t
*hw
= &priv
->hw
;
2460 struct hermes_idstring essidbuf
;
2461 char *p
= (char *)(&essidbuf
.val
);
2463 unsigned long flags
;
2465 if (orinoco_lock(priv
, &flags
) != 0)
2468 if (strlen(priv
->desired_essid
) > 0) {
2469 /* We read the desired SSID from the hardware rather
2470 than from priv->desired_essid, just in case the
2471 firmware is allowed to change it on us. I'm not
2473 /* My guess is that the OWNSSID should always be whatever
2474 * we set to the card, whereas CURRENT_SSID is the one that
2475 * may change... - Jean II */
2480 rid
= (priv
->port_type
== 3) ? HERMES_RID_CNFOWNSSID
:
2481 HERMES_RID_CNFDESIREDSSID
;
2483 err
= hermes_read_ltv(hw
, USER_BAP
, rid
, sizeof(essidbuf
),
2490 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENTSSID
,
2491 sizeof(essidbuf
), NULL
, &essidbuf
);
2496 len
= le16_to_cpu(essidbuf
.len
);
2497 BUG_ON(len
> IW_ESSID_MAX_SIZE
);
2499 memset(buf
, 0, IW_ESSID_MAX_SIZE
);
2500 memcpy(buf
, p
, len
);
2504 orinoco_unlock(priv
, &flags
);
2509 static long orinoco_hw_get_freq(struct orinoco_private
*priv
)
2512 hermes_t
*hw
= &priv
->hw
;
2516 unsigned long flags
;
2518 if (orinoco_lock(priv
, &flags
) != 0)
2521 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CURRENTCHANNEL
, &channel
);
2525 /* Intersil firmware 1.3.5 returns 0 when the interface is down */
2531 if ( (channel
< 1) || (channel
> NUM_CHANNELS
) ) {
2532 printk(KERN_WARNING
"%s: Channel out of range (%d)!\n",
2533 priv
->ndev
->name
, channel
);
2538 freq
= channel_frequency
[channel
-1] * 100000;
2541 orinoco_unlock(priv
, &flags
);
2545 return err
? err
: freq
;
2548 static int orinoco_hw_get_bitratelist(struct orinoco_private
*priv
,
2549 int *numrates
, s32
*rates
, int max
)
2551 hermes_t
*hw
= &priv
->hw
;
2552 struct hermes_idstring list
;
2553 unsigned char *p
= (unsigned char *)&list
.val
;
2557 unsigned long flags
;
2559 if (orinoco_lock(priv
, &flags
) != 0)
2562 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_SUPPORTEDDATARATES
,
2563 sizeof(list
), NULL
, &list
);
2564 orinoco_unlock(priv
, &flags
);
2569 num
= le16_to_cpu(list
.len
);
2571 num
= min(num
, max
);
2573 for (i
= 0; i
< num
; i
++) {
2574 rates
[i
] = (p
[i
] & 0x7f) * 500000; /* convert to bps */
2580 static int orinoco_ioctl_getname(struct net_device
*dev
,
2581 struct iw_request_info
*info
,
2585 struct orinoco_private
*priv
= netdev_priv(dev
);
2589 err
= orinoco_hw_get_bitratelist(priv
, &numrates
, NULL
, 0);
2591 if (!err
&& (numrates
> 2))
2592 strcpy(name
, "IEEE 802.11b");
2594 strcpy(name
, "IEEE 802.11-DS");
2599 static int orinoco_ioctl_setwap(struct net_device
*dev
,
2600 struct iw_request_info
*info
,
2601 struct sockaddr
*ap_addr
,
2604 struct orinoco_private
*priv
= netdev_priv(dev
);
2605 int err
= -EINPROGRESS
; /* Call commit handler */
2606 unsigned long flags
;
2607 static const u8 off_addr
[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
2608 static const u8 any_addr
[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
2610 if (orinoco_lock(priv
, &flags
) != 0)
2613 /* Enable automatic roaming - no sanity checks are needed */
2614 if (memcmp(&ap_addr
->sa_data
, off_addr
, ETH_ALEN
) == 0 ||
2615 memcmp(&ap_addr
->sa_data
, any_addr
, ETH_ALEN
) == 0) {
2616 priv
->bssid_fixed
= 0;
2617 memset(priv
->desired_bssid
, 0, ETH_ALEN
);
2619 /* "off" means keep existing connection */
2620 if (ap_addr
->sa_data
[0] == 0) {
2621 __orinoco_hw_set_wap(priv
);
2627 if (priv
->firmware_type
== FIRMWARE_TYPE_AGERE
) {
2628 printk(KERN_WARNING
"%s: Lucent/Agere firmware doesn't "
2629 "support manual roaming\n",
2635 if (priv
->iw_mode
!= IW_MODE_INFRA
) {
2636 printk(KERN_WARNING
"%s: Manual roaming supported only in "
2637 "managed mode\n", dev
->name
);
2642 /* Intersil firmware hangs without Desired ESSID */
2643 if (priv
->firmware_type
== FIRMWARE_TYPE_INTERSIL
&&
2644 strlen(priv
->desired_essid
) == 0) {
2645 printk(KERN_WARNING
"%s: Desired ESSID must be set for "
2646 "manual roaming\n", dev
->name
);
2651 /* Finally, enable manual roaming */
2652 priv
->bssid_fixed
= 1;
2653 memcpy(priv
->desired_bssid
, &ap_addr
->sa_data
, ETH_ALEN
);
2656 orinoco_unlock(priv
, &flags
);
2660 static int orinoco_ioctl_getwap(struct net_device
*dev
,
2661 struct iw_request_info
*info
,
2662 struct sockaddr
*ap_addr
,
2665 struct orinoco_private
*priv
= netdev_priv(dev
);
2667 hermes_t
*hw
= &priv
->hw
;
2669 unsigned long flags
;
2671 if (orinoco_lock(priv
, &flags
) != 0)
2674 ap_addr
->sa_family
= ARPHRD_ETHER
;
2675 err
= hermes_read_ltv(hw
, USER_BAP
, HERMES_RID_CURRENTBSSID
,
2676 ETH_ALEN
, NULL
, ap_addr
->sa_data
);
2678 orinoco_unlock(priv
, &flags
);
2683 static int orinoco_ioctl_setmode(struct net_device
*dev
,
2684 struct iw_request_info
*info
,
2688 struct orinoco_private
*priv
= netdev_priv(dev
);
2689 int err
= -EINPROGRESS
; /* Call commit handler */
2690 unsigned long flags
;
2692 if (priv
->iw_mode
== *mode
)
2695 if (orinoco_lock(priv
, &flags
) != 0)
2700 if (!priv
->has_ibss
&& !priv
->has_port3
)
2707 case IW_MODE_MONITOR
:
2708 if (priv
->broken_monitor
&& !force_monitor
) {
2709 printk(KERN_WARNING
"%s: Monitor mode support is "
2710 "buggy in this firmware, not enabling\n",
2721 if (err
== -EINPROGRESS
) {
2722 priv
->iw_mode
= *mode
;
2723 set_port_type(priv
);
2726 orinoco_unlock(priv
, &flags
);
2731 static int orinoco_ioctl_getmode(struct net_device
*dev
,
2732 struct iw_request_info
*info
,
2736 struct orinoco_private
*priv
= netdev_priv(dev
);
2738 *mode
= priv
->iw_mode
;
2742 static int orinoco_ioctl_getiwrange(struct net_device
*dev
,
2743 struct iw_request_info
*info
,
2744 struct iw_point
*rrq
,
2747 struct orinoco_private
*priv
= netdev_priv(dev
);
2749 struct iw_range
*range
= (struct iw_range
*) extra
;
2753 rrq
->length
= sizeof(struct iw_range
);
2754 memset(range
, 0, sizeof(struct iw_range
));
2756 range
->we_version_compiled
= WIRELESS_EXT
;
2757 range
->we_version_source
= 14;
2759 /* Set available channels/frequencies */
2760 range
->num_channels
= NUM_CHANNELS
;
2762 for (i
= 0; i
< NUM_CHANNELS
; i
++) {
2763 if (priv
->channel_mask
& (1 << i
)) {
2764 range
->freq
[k
].i
= i
+ 1;
2765 range
->freq
[k
].m
= channel_frequency
[i
] * 100000;
2766 range
->freq
[k
].e
= 1;
2770 if (k
>= IW_MAX_FREQUENCIES
)
2773 range
->num_frequency
= k
;
2774 range
->sensitivity
= 3;
2776 if (priv
->has_wep
) {
2777 range
->max_encoding_tokens
= ORINOCO_MAX_KEYS
;
2778 range
->encoding_size
[0] = SMALL_KEY_SIZE
;
2779 range
->num_encoding_sizes
= 1;
2781 if (priv
->has_big_wep
) {
2782 range
->encoding_size
[1] = LARGE_KEY_SIZE
;
2783 range
->num_encoding_sizes
= 2;
2787 if ((priv
->iw_mode
== IW_MODE_ADHOC
) && (!SPY_NUMBER(priv
))){
2788 /* Quality stats meaningless in ad-hoc mode */
2790 range
->max_qual
.qual
= 0x8b - 0x2f;
2791 range
->max_qual
.level
= 0x2f - 0x95 - 1;
2792 range
->max_qual
.noise
= 0x2f - 0x95 - 1;
2793 /* Need to get better values */
2794 range
->avg_qual
.qual
= 0x24;
2795 range
->avg_qual
.level
= 0xC2;
2796 range
->avg_qual
.noise
= 0x9E;
2799 err
= orinoco_hw_get_bitratelist(priv
, &numrates
,
2800 range
->bitrate
, IW_MAX_BITRATES
);
2803 range
->num_bitrates
= numrates
;
2805 /* Set an indication of the max TCP throughput in bit/s that we can
2806 * expect using this interface. May be use for QoS stuff...
2809 range
->throughput
= 5 * 1000 * 1000; /* ~5 Mb/s */
2811 range
->throughput
= 1.5 * 1000 * 1000; /* ~1.5 Mb/s */
2814 range
->max_rts
= 2347;
2815 range
->min_frag
= 256;
2816 range
->max_frag
= 2346;
2819 range
->max_pmp
= 65535000;
2821 range
->max_pmt
= 65535 * 1000; /* ??? */
2822 range
->pmp_flags
= IW_POWER_PERIOD
;
2823 range
->pmt_flags
= IW_POWER_TIMEOUT
;
2824 range
->pm_capa
= IW_POWER_PERIOD
| IW_POWER_TIMEOUT
| IW_POWER_UNICAST_R
;
2826 range
->retry_capa
= IW_RETRY_LIMIT
| IW_RETRY_LIFETIME
;
2827 range
->retry_flags
= IW_RETRY_LIMIT
;
2828 range
->r_time_flags
= IW_RETRY_LIFETIME
;
2829 range
->min_retry
= 0;
2830 range
->max_retry
= 65535; /* ??? */
2831 range
->min_r_time
= 0;
2832 range
->max_r_time
= 65535 * 1000; /* ??? */
2834 /* Event capability (kernel) */
2835 IW_EVENT_CAPA_SET_KERNEL(range
->event_capa
);
2836 /* Event capability (driver) */
2837 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWTHRSPY
);
2838 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWAP
);
2839 IW_EVENT_CAPA_SET(range
->event_capa
, SIOCGIWSCAN
);
2840 IW_EVENT_CAPA_SET(range
->event_capa
, IWEVTXDROP
);
2845 static int orinoco_ioctl_setiwencode(struct net_device
*dev
,
2846 struct iw_request_info
*info
,
2847 struct iw_point
*erq
,
2850 struct orinoco_private
*priv
= netdev_priv(dev
);
2851 int index
= (erq
->flags
& IW_ENCODE_INDEX
) - 1;
2852 int setindex
= priv
->tx_key
;
2853 int enable
= priv
->wep_on
;
2854 int restricted
= priv
->wep_restrict
;
2856 int err
= -EINPROGRESS
; /* Call commit handler */
2857 unsigned long flags
;
2859 if (! priv
->has_wep
)
2863 /* We actually have a key to set - check its length */
2864 if (erq
->length
> LARGE_KEY_SIZE
)
2867 if ( (erq
->length
> SMALL_KEY_SIZE
) && !priv
->has_big_wep
)
2871 if (orinoco_lock(priv
, &flags
) != 0)
2875 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
))
2876 index
= priv
->tx_key
;
2878 /* Adjust key length to a supported value */
2879 if (erq
->length
> SMALL_KEY_SIZE
) {
2880 xlen
= LARGE_KEY_SIZE
;
2881 } else if (erq
->length
> 0) {
2882 xlen
= SMALL_KEY_SIZE
;
2886 /* Switch on WEP if off */
2887 if ((!enable
) && (xlen
> 0)) {
2892 /* Important note : if the user do "iwconfig eth0 enc off",
2893 * we will arrive there with an index of -1. This is valid
2894 * but need to be taken care off... Jean II */
2895 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
)) {
2896 if((index
!= -1) || (erq
->flags
== 0)) {
2901 /* Set the index : Check that the key is valid */
2902 if(priv
->keys
[index
].len
== 0) {
2910 if (erq
->flags
& IW_ENCODE_DISABLED
)
2912 if (erq
->flags
& IW_ENCODE_OPEN
)
2914 if (erq
->flags
& IW_ENCODE_RESTRICTED
)
2918 priv
->keys
[index
].len
= cpu_to_le16(xlen
);
2919 memset(priv
->keys
[index
].data
, 0,
2920 sizeof(priv
->keys
[index
].data
));
2921 memcpy(priv
->keys
[index
].data
, keybuf
, erq
->length
);
2923 priv
->tx_key
= setindex
;
2925 /* Try fast key change if connected and only keys are changed */
2926 if (priv
->wep_on
&& enable
&& (priv
->wep_restrict
== restricted
) &&
2927 netif_carrier_ok(dev
)) {
2928 err
= __orinoco_hw_setup_wepkeys(priv
);
2929 /* No need to commit if successful */
2933 priv
->wep_on
= enable
;
2934 priv
->wep_restrict
= restricted
;
2937 orinoco_unlock(priv
, &flags
);
2942 static int orinoco_ioctl_getiwencode(struct net_device
*dev
,
2943 struct iw_request_info
*info
,
2944 struct iw_point
*erq
,
2947 struct orinoco_private
*priv
= netdev_priv(dev
);
2948 int index
= (erq
->flags
& IW_ENCODE_INDEX
) - 1;
2950 unsigned long flags
;
2952 if (! priv
->has_wep
)
2955 if (orinoco_lock(priv
, &flags
) != 0)
2958 if ((index
< 0) || (index
>= ORINOCO_MAX_KEYS
))
2959 index
= priv
->tx_key
;
2963 erq
->flags
|= IW_ENCODE_DISABLED
;
2964 erq
->flags
|= index
+ 1;
2966 if (priv
->wep_restrict
)
2967 erq
->flags
|= IW_ENCODE_RESTRICTED
;
2969 erq
->flags
|= IW_ENCODE_OPEN
;
2971 xlen
= le16_to_cpu(priv
->keys
[index
].len
);
2975 memcpy(keybuf
, priv
->keys
[index
].data
, ORINOCO_MAX_KEY_SIZE
);
2977 orinoco_unlock(priv
, &flags
);
2981 static int orinoco_ioctl_setessid(struct net_device
*dev
,
2982 struct iw_request_info
*info
,
2983 struct iw_point
*erq
,
2986 struct orinoco_private
*priv
= netdev_priv(dev
);
2987 unsigned long flags
;
2989 /* Note : ESSID is ignored in Ad-Hoc demo mode, but we can set it
2990 * anyway... - Jean II */
2992 /* Hum... Should not use Wireless Extension constant (may change),
2993 * should use our own... - Jean II */
2994 if (erq
->length
> IW_ESSID_MAX_SIZE
)
2997 if (orinoco_lock(priv
, &flags
) != 0)
3000 /* NULL the string (for NULL termination & ESSID = ANY) - Jean II */
3001 memset(priv
->desired_essid
, 0, sizeof(priv
->desired_essid
));
3003 /* If not ANY, get the new ESSID */
3005 memcpy(priv
->desired_essid
, essidbuf
, erq
->length
);
3008 orinoco_unlock(priv
, &flags
);
3010 return -EINPROGRESS
; /* Call commit handler */
3013 static int orinoco_ioctl_getessid(struct net_device
*dev
,
3014 struct iw_request_info
*info
,
3015 struct iw_point
*erq
,
3018 struct orinoco_private
*priv
= netdev_priv(dev
);
3021 unsigned long flags
;
3023 if (netif_running(dev
)) {
3024 err
= orinoco_hw_get_essid(priv
, &active
, essidbuf
);
3029 if (orinoco_lock(priv
, &flags
) != 0)
3031 memcpy(essidbuf
, priv
->desired_essid
, IW_ESSID_MAX_SIZE
);
3032 erq
->length
= strlen(priv
->desired_essid
);
3033 orinoco_unlock(priv
, &flags
);
3041 static int orinoco_ioctl_setnick(struct net_device
*dev
,
3042 struct iw_request_info
*info
,
3043 struct iw_point
*nrq
,
3046 struct orinoco_private
*priv
= netdev_priv(dev
);
3047 unsigned long flags
;
3049 if (nrq
->length
> IW_ESSID_MAX_SIZE
)
3052 if (orinoco_lock(priv
, &flags
) != 0)
3055 memset(priv
->nick
, 0, sizeof(priv
->nick
));
3056 memcpy(priv
->nick
, nickbuf
, nrq
->length
);
3058 orinoco_unlock(priv
, &flags
);
3060 return -EINPROGRESS
; /* Call commit handler */
3063 static int orinoco_ioctl_getnick(struct net_device
*dev
,
3064 struct iw_request_info
*info
,
3065 struct iw_point
*nrq
,
3068 struct orinoco_private
*priv
= netdev_priv(dev
);
3069 unsigned long flags
;
3071 if (orinoco_lock(priv
, &flags
) != 0)
3074 memcpy(nickbuf
, priv
->nick
, IW_ESSID_MAX_SIZE
);
3075 orinoco_unlock(priv
, &flags
);
3077 nrq
->length
= strlen(priv
->nick
);
3082 static int orinoco_ioctl_setfreq(struct net_device
*dev
,
3083 struct iw_request_info
*info
,
3084 struct iw_freq
*frq
,
3087 struct orinoco_private
*priv
= netdev_priv(dev
);
3089 unsigned long flags
;
3090 int err
= -EINPROGRESS
; /* Call commit handler */
3092 /* In infrastructure mode the AP sets the channel */
3093 if (priv
->iw_mode
== IW_MODE_INFRA
)
3096 if ( (frq
->e
== 0) && (frq
->m
<= 1000) ) {
3097 /* Setting by channel number */
3100 /* Setting by frequency - search the table */
3104 for (i
= 0; i
< (6 - frq
->e
); i
++)
3107 for (i
= 0; i
< NUM_CHANNELS
; i
++)
3108 if (frq
->m
== (channel_frequency
[i
] * mult
))
3112 if ( (chan
< 1) || (chan
> NUM_CHANNELS
) ||
3113 ! (priv
->channel_mask
& (1 << (chan
-1)) ) )
3116 if (orinoco_lock(priv
, &flags
) != 0)
3119 priv
->channel
= chan
;
3120 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
3121 /* Fast channel change - no commit if successful */
3122 hermes_t
*hw
= &priv
->hw
;
3123 err
= hermes_docmd_wait(hw
, HERMES_CMD_TEST
|
3124 HERMES_TEST_SET_CHANNEL
,
3127 orinoco_unlock(priv
, &flags
);
3132 static int orinoco_ioctl_getfreq(struct net_device
*dev
,
3133 struct iw_request_info
*info
,
3134 struct iw_freq
*frq
,
3137 struct orinoco_private
*priv
= netdev_priv(dev
);
3140 /* Locking done in there */
3141 tmp
= orinoco_hw_get_freq(priv
);
3152 static int orinoco_ioctl_getsens(struct net_device
*dev
,
3153 struct iw_request_info
*info
,
3154 struct iw_param
*srq
,
3157 struct orinoco_private
*priv
= netdev_priv(dev
);
3158 hermes_t
*hw
= &priv
->hw
;
3161 unsigned long flags
;
3163 if (!priv
->has_sensitivity
)
3166 if (orinoco_lock(priv
, &flags
) != 0)
3168 err
= hermes_read_wordrec(hw
, USER_BAP
,
3169 HERMES_RID_CNFSYSTEMSCALE
, &val
);
3170 orinoco_unlock(priv
, &flags
);
3176 srq
->fixed
= 0; /* auto */
3181 static int orinoco_ioctl_setsens(struct net_device
*dev
,
3182 struct iw_request_info
*info
,
3183 struct iw_param
*srq
,
3186 struct orinoco_private
*priv
= netdev_priv(dev
);
3187 int val
= srq
->value
;
3188 unsigned long flags
;
3190 if (!priv
->has_sensitivity
)
3193 if ((val
< 1) || (val
> 3))
3196 if (orinoco_lock(priv
, &flags
) != 0)
3198 priv
->ap_density
= val
;
3199 orinoco_unlock(priv
, &flags
);
3201 return -EINPROGRESS
; /* Call commit handler */
3204 static int orinoco_ioctl_setrts(struct net_device
*dev
,
3205 struct iw_request_info
*info
,
3206 struct iw_param
*rrq
,
3209 struct orinoco_private
*priv
= netdev_priv(dev
);
3210 int val
= rrq
->value
;
3211 unsigned long flags
;
3216 if ( (val
< 0) || (val
> 2347) )
3219 if (orinoco_lock(priv
, &flags
) != 0)
3222 priv
->rts_thresh
= val
;
3223 orinoco_unlock(priv
, &flags
);
3225 return -EINPROGRESS
; /* Call commit handler */
3228 static int orinoco_ioctl_getrts(struct net_device
*dev
,
3229 struct iw_request_info
*info
,
3230 struct iw_param
*rrq
,
3233 struct orinoco_private
*priv
= netdev_priv(dev
);
3235 rrq
->value
= priv
->rts_thresh
;
3236 rrq
->disabled
= (rrq
->value
== 2347);
3242 static int orinoco_ioctl_setfrag(struct net_device
*dev
,
3243 struct iw_request_info
*info
,
3244 struct iw_param
*frq
,
3247 struct orinoco_private
*priv
= netdev_priv(dev
);
3248 int err
= -EINPROGRESS
; /* Call commit handler */
3249 unsigned long flags
;
3251 if (orinoco_lock(priv
, &flags
) != 0)
3254 if (priv
->has_mwo
) {
3256 priv
->mwo_robust
= 0;
3259 printk(KERN_WARNING
"%s: Fixed fragmentation is "
3260 "not supported on this firmware. "
3261 "Using MWO robust instead.\n", dev
->name
);
3262 priv
->mwo_robust
= 1;
3266 priv
->frag_thresh
= 2346;
3268 if ( (frq
->value
< 256) || (frq
->value
> 2346) )
3271 priv
->frag_thresh
= frq
->value
& ~0x1; /* must be even */
3275 orinoco_unlock(priv
, &flags
);
3280 static int orinoco_ioctl_getfrag(struct net_device
*dev
,
3281 struct iw_request_info
*info
,
3282 struct iw_param
*frq
,
3285 struct orinoco_private
*priv
= netdev_priv(dev
);
3286 hermes_t
*hw
= &priv
->hw
;
3289 unsigned long flags
;
3291 if (orinoco_lock(priv
, &flags
) != 0)
3294 if (priv
->has_mwo
) {
3295 err
= hermes_read_wordrec(hw
, USER_BAP
,
3296 HERMES_RID_CNFMWOROBUST_AGERE
,
3301 frq
->value
= val
? 2347 : 0;
3302 frq
->disabled
= ! val
;
3305 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFFRAGMENTATIONTHRESHOLD
,
3311 frq
->disabled
= (val
>= 2346);
3315 orinoco_unlock(priv
, &flags
);
3320 static int orinoco_ioctl_setrate(struct net_device
*dev
,
3321 struct iw_request_info
*info
,
3322 struct iw_param
*rrq
,
3325 struct orinoco_private
*priv
= netdev_priv(dev
);
3327 int bitrate
; /* 100s of kilobits */
3329 unsigned long flags
;
3331 /* As the user space doesn't know our highest rate, it uses -1
3332 * to ask us to set the highest rate. Test it using "iwconfig
3333 * ethX rate auto" - Jean II */
3334 if (rrq
->value
== -1)
3337 if (rrq
->value
% 100000)
3339 bitrate
= rrq
->value
/ 100000;
3342 if ( (bitrate
!= 10) && (bitrate
!= 20) &&
3343 (bitrate
!= 55) && (bitrate
!= 110) )
3346 for (i
= 0; i
< BITRATE_TABLE_SIZE
; i
++)
3347 if ( (bitrate_table
[i
].bitrate
== bitrate
) &&
3348 (bitrate_table
[i
].automatic
== ! rrq
->fixed
) ) {
3356 if (orinoco_lock(priv
, &flags
) != 0)
3358 priv
->bitratemode
= ratemode
;
3359 orinoco_unlock(priv
, &flags
);
3361 return -EINPROGRESS
;
3364 static int orinoco_ioctl_getrate(struct net_device
*dev
,
3365 struct iw_request_info
*info
,
3366 struct iw_param
*rrq
,
3369 struct orinoco_private
*priv
= netdev_priv(dev
);
3370 hermes_t
*hw
= &priv
->hw
;
3375 unsigned long flags
;
3377 if (orinoco_lock(priv
, &flags
) != 0)
3380 ratemode
= priv
->bitratemode
;
3382 BUG_ON((ratemode
< 0) || (ratemode
>= BITRATE_TABLE_SIZE
));
3384 rrq
->value
= bitrate_table
[ratemode
].bitrate
* 100000;
3385 rrq
->fixed
= ! bitrate_table
[ratemode
].automatic
;
3388 /* If the interface is running we try to find more about the
3390 if (netif_running(dev
)) {
3391 err
= hermes_read_wordrec(hw
, USER_BAP
,
3392 HERMES_RID_CURRENTTXRATE
, &val
);
3396 switch (priv
->firmware_type
) {
3397 case FIRMWARE_TYPE_AGERE
: /* Lucent style rate */
3398 /* Note : in Lucent firmware, the return value of
3399 * HERMES_RID_CURRENTTXRATE is the bitrate in Mb/s,
3400 * and therefore is totally different from the
3401 * encoding of HERMES_RID_CNFTXRATECONTROL.
3402 * Don't forget that 6Mb/s is really 5.5Mb/s */
3404 rrq
->value
= 5500000;
3406 rrq
->value
= val
* 1000000;
3408 case FIRMWARE_TYPE_INTERSIL
: /* Intersil style rate */
3409 case FIRMWARE_TYPE_SYMBOL
: /* Symbol style rate */
3410 for (i
= 0; i
< BITRATE_TABLE_SIZE
; i
++)
3411 if (bitrate_table
[i
].intersil_txratectrl
== val
) {
3415 if (i
>= BITRATE_TABLE_SIZE
)
3416 printk(KERN_INFO
"%s: Unable to determine current bitrate (0x%04hx)\n",
3419 rrq
->value
= bitrate_table
[ratemode
].bitrate
* 100000;
3427 orinoco_unlock(priv
, &flags
);
3432 static int orinoco_ioctl_setpower(struct net_device
*dev
,
3433 struct iw_request_info
*info
,
3434 struct iw_param
*prq
,
3437 struct orinoco_private
*priv
= netdev_priv(dev
);
3438 int err
= -EINPROGRESS
; /* Call commit handler */
3439 unsigned long flags
;
3441 if (orinoco_lock(priv
, &flags
) != 0)
3444 if (prq
->disabled
) {
3447 switch (prq
->flags
& IW_POWER_MODE
) {
3448 case IW_POWER_UNICAST_R
:
3452 case IW_POWER_ALL_R
:
3457 /* No flags : but we may have a value - Jean II */
3464 if (prq
->flags
& IW_POWER_TIMEOUT
) {
3466 priv
->pm_timeout
= prq
->value
/ 1000;
3468 if (prq
->flags
& IW_POWER_PERIOD
) {
3470 priv
->pm_period
= prq
->value
/ 1000;
3472 /* It's valid to not have a value if we are just toggling
3473 * the flags... Jean II */
3481 orinoco_unlock(priv
, &flags
);
3486 static int orinoco_ioctl_getpower(struct net_device
*dev
,
3487 struct iw_request_info
*info
,
3488 struct iw_param
*prq
,
3491 struct orinoco_private
*priv
= netdev_priv(dev
);
3492 hermes_t
*hw
= &priv
->hw
;
3494 u16 enable
, period
, timeout
, mcast
;
3495 unsigned long flags
;
3497 if (orinoco_lock(priv
, &flags
) != 0)
3500 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFPMENABLED
, &enable
);
3504 err
= hermes_read_wordrec(hw
, USER_BAP
,
3505 HERMES_RID_CNFMAXSLEEPDURATION
, &period
);
3509 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFPMHOLDOVERDURATION
, &timeout
);
3513 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_CNFMULTICASTRECEIVE
, &mcast
);
3517 prq
->disabled
= !enable
;
3518 /* Note : by default, display the period */
3519 if ((prq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
3520 prq
->flags
= IW_POWER_TIMEOUT
;
3521 prq
->value
= timeout
* 1000;
3523 prq
->flags
= IW_POWER_PERIOD
;
3524 prq
->value
= period
* 1000;
3527 prq
->flags
|= IW_POWER_ALL_R
;
3529 prq
->flags
|= IW_POWER_UNICAST_R
;
3532 orinoco_unlock(priv
, &flags
);
3537 static int orinoco_ioctl_getretry(struct net_device
*dev
,
3538 struct iw_request_info
*info
,
3539 struct iw_param
*rrq
,
3542 struct orinoco_private
*priv
= netdev_priv(dev
);
3543 hermes_t
*hw
= &priv
->hw
;
3545 u16 short_limit
, long_limit
, lifetime
;
3546 unsigned long flags
;
3548 if (orinoco_lock(priv
, &flags
) != 0)
3551 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_SHORTRETRYLIMIT
,
3556 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_LONGRETRYLIMIT
,
3561 err
= hermes_read_wordrec(hw
, USER_BAP
, HERMES_RID_MAXTRANSMITLIFETIME
,
3566 rrq
->disabled
= 0; /* Can't be disabled */
3568 /* Note : by default, display the retry number */
3569 if ((rrq
->flags
& IW_RETRY_TYPE
) == IW_RETRY_LIFETIME
) {
3570 rrq
->flags
= IW_RETRY_LIFETIME
;
3571 rrq
->value
= lifetime
* 1000; /* ??? */
3573 /* By default, display the min number */
3574 if ((rrq
->flags
& IW_RETRY_LONG
)) {
3575 rrq
->flags
= IW_RETRY_LIMIT
| IW_RETRY_LONG
;
3576 rrq
->value
= long_limit
;
3578 rrq
->flags
= IW_RETRY_LIMIT
;
3579 rrq
->value
= short_limit
;
3580 if(short_limit
!= long_limit
)
3581 rrq
->flags
|= IW_RETRY_SHORT
;
3586 orinoco_unlock(priv
, &flags
);
3591 static int orinoco_ioctl_reset(struct net_device
*dev
,
3592 struct iw_request_info
*info
,
3596 struct orinoco_private
*priv
= netdev_priv(dev
);
3598 if (! capable(CAP_NET_ADMIN
))
3601 if (info
->cmd
== (SIOCIWFIRSTPRIV
+ 0x1)) {
3602 printk(KERN_DEBUG
"%s: Forcing reset!\n", dev
->name
);
3604 /* Firmware reset */
3605 orinoco_reset(&priv
->reset_work
);
3607 printk(KERN_DEBUG
"%s: Force scheduling reset!\n", dev
->name
);
3609 schedule_work(&priv
->reset_work
);
3615 static int orinoco_ioctl_setibssport(struct net_device
*dev
,
3616 struct iw_request_info
*info
,
3621 struct orinoco_private
*priv
= netdev_priv(dev
);
3622 int val
= *( (int *) extra
);
3623 unsigned long flags
;
3625 if (orinoco_lock(priv
, &flags
) != 0)
3628 priv
->ibss_port
= val
;
3630 /* Actually update the mode we are using */
3631 set_port_type(priv
);
3633 orinoco_unlock(priv
, &flags
);
3634 return -EINPROGRESS
; /* Call commit handler */
3637 static int orinoco_ioctl_getibssport(struct net_device
*dev
,
3638 struct iw_request_info
*info
,
3642 struct orinoco_private
*priv
= netdev_priv(dev
);
3643 int *val
= (int *) extra
;
3645 *val
= priv
->ibss_port
;
3649 static int orinoco_ioctl_setport3(struct net_device
*dev
,
3650 struct iw_request_info
*info
,
3654 struct orinoco_private
*priv
= netdev_priv(dev
);
3655 int val
= *( (int *) extra
);
3657 unsigned long flags
;
3659 if (orinoco_lock(priv
, &flags
) != 0)
3663 case 0: /* Try to do IEEE ad-hoc mode */
3664 if (! priv
->has_ibss
) {
3668 priv
->prefer_port3
= 0;
3672 case 1: /* Try to do Lucent proprietary ad-hoc mode */
3673 if (! priv
->has_port3
) {
3677 priv
->prefer_port3
= 1;
3685 /* Actually update the mode we are using */
3686 set_port_type(priv
);
3690 orinoco_unlock(priv
, &flags
);
3695 static int orinoco_ioctl_getport3(struct net_device
*dev
,
3696 struct iw_request_info
*info
,
3700 struct orinoco_private
*priv
= netdev_priv(dev
);
3701 int *val
= (int *) extra
;
3703 *val
= priv
->prefer_port3
;
3707 static int orinoco_ioctl_setpreamble(struct net_device
*dev
,
3708 struct iw_request_info
*info
,
3712 struct orinoco_private
*priv
= netdev_priv(dev
);
3713 unsigned long flags
;
3716 if (! priv
->has_preamble
)
3719 /* 802.11b has recently defined some short preamble.
3720 * Basically, the Phy header has been reduced in size.
3721 * This increase performance, especially at high rates
3722 * (the preamble is transmitted at 1Mb/s), unfortunately
3723 * this give compatibility troubles... - Jean II */
3724 val
= *( (int *) extra
);
3726 if (orinoco_lock(priv
, &flags
) != 0)
3734 orinoco_unlock(priv
, &flags
);
3736 return -EINPROGRESS
; /* Call commit handler */
3739 static int orinoco_ioctl_getpreamble(struct net_device
*dev
,
3740 struct iw_request_info
*info
,
3744 struct orinoco_private
*priv
= netdev_priv(dev
);
3745 int *val
= (int *) extra
;
3747 if (! priv
->has_preamble
)
3750 *val
= priv
->preamble
;
3754 /* ioctl interface to hermes_read_ltv()
3755 * To use with iwpriv, pass the RID as the token argument, e.g.
3756 * iwpriv get_rid [0xfc00]
3757 * At least Wireless Tools 25 is required to use iwpriv.
3758 * For Wireless Tools 25 and 26 append "dummy" are the end. */
3759 static int orinoco_ioctl_getrid(struct net_device
*dev
,
3760 struct iw_request_info
*info
,
3761 struct iw_point
*data
,
3764 struct orinoco_private
*priv
= netdev_priv(dev
);
3765 hermes_t
*hw
= &priv
->hw
;
3766 int rid
= data
->flags
;
3769 unsigned long flags
;
3771 /* It's a "get" function, but we don't want users to access the
3772 * WEP key and other raw firmware data */
3773 if (! capable(CAP_NET_ADMIN
))
3776 if (rid
< 0xfc00 || rid
> 0xffff)
3779 if (orinoco_lock(priv
, &flags
) != 0)
3782 err
= hermes_read_ltv(hw
, USER_BAP
, rid
, MAX_RID_LEN
, &length
,
3787 data
->length
= min_t(u16
, HERMES_RECLEN_TO_BYTES(length
),
3791 orinoco_unlock(priv
, &flags
);
3795 /* Trigger a scan (look for other cells in the vicinity) */
3796 static int orinoco_ioctl_setscan(struct net_device
*dev
,
3797 struct iw_request_info
*info
,
3798 struct iw_param
*srq
,
3801 struct orinoco_private
*priv
= netdev_priv(dev
);
3802 hermes_t
*hw
= &priv
->hw
;
3804 unsigned long flags
;
3806 /* Note : you may have realised that, as this is a SET operation,
3807 * this is privileged and therefore a normal user can't
3809 * This is not an error, while the device perform scanning,
3810 * traffic doesn't flow, so it's a perfect DoS...
3813 if (orinoco_lock(priv
, &flags
) != 0)
3816 /* Scanning with port 0 disabled would fail */
3817 if (!netif_running(dev
)) {
3822 /* In monitor mode, the scan results are always empty.
3823 * Probe responses are passed to the driver as received
3824 * frames and could be processed in software. */
3825 if (priv
->iw_mode
== IW_MODE_MONITOR
) {
3830 /* Note : because we don't lock out the irq handler, the way
3831 * we access scan variables in priv is critical.
3832 * o scan_inprogress : not touched by irq handler
3833 * o scan_mode : not touched by irq handler
3834 * o scan_result : irq is strict producer, non-irq is strict
3836 * o scan_len : synchronised with scan_result
3837 * Before modifying anything on those variables, please think hard !
3840 /* If there is still some left-over scan results, get rid of it */
3841 if (priv
->scan_result
!= NULL
) {
3842 /* What's likely is that a client did crash or was killed
3843 * between triggering the scan request and reading the
3844 * results, so we need to reset everything.
3845 * Some clients that are too slow may suffer from that...
3847 kfree(priv
->scan_result
);
3848 priv
->scan_result
= NULL
;
3852 priv
->scan_mode
= srq
->flags
;
3854 /* Always trigger scanning, even if it's in progress.
3855 * This way, if the info frame get lost, we will recover somewhat
3856 * gracefully - Jean II */
3858 if (priv
->has_hostscan
) {
3859 switch (priv
->firmware_type
) {
3860 case FIRMWARE_TYPE_SYMBOL
:
3861 err
= hermes_write_wordrec(hw
, USER_BAP
,
3862 HERMES_RID_CNFHOSTSCAN_SYMBOL
,
3863 HERMES_HOSTSCAN_SYMBOL_ONCE
|
3864 HERMES_HOSTSCAN_SYMBOL_BCAST
);
3866 case FIRMWARE_TYPE_INTERSIL
: {
3869 req
[0] = cpu_to_le16(0x3fff); /* All channels */
3870 req
[1] = cpu_to_le16(0x0001); /* rate 1 Mbps */
3871 req
[2] = 0; /* Any ESSID */
3872 err
= HERMES_WRITE_RECORD(hw
, USER_BAP
,
3873 HERMES_RID_CNFHOSTSCAN
, &req
);
3876 case FIRMWARE_TYPE_AGERE
:
3877 err
= hermes_write_wordrec(hw
, USER_BAP
,
3878 HERMES_RID_CNFSCANSSID_AGERE
,
3883 err
= hermes_inquire(hw
, HERMES_INQ_SCAN
);
3887 err
= hermes_inquire(hw
, HERMES_INQ_SCAN
);
3889 /* One more client */
3891 priv
->scan_inprogress
= 1;
3894 orinoco_unlock(priv
, &flags
);
3898 /* Translate scan data returned from the card to a card independant
3899 * format that the Wireless Tools will understand - Jean II
3900 * Return message length or -errno for fatal errors */
3901 static inline int orinoco_translate_scan(struct net_device
*dev
,
3902 struct iw_request_info
*info
,
3907 struct orinoco_private
*priv
= netdev_priv(dev
);
3908 int offset
; /* In the scan data */
3909 union hermes_scan_info
*atom
;
3913 struct iw_event iwe
; /* Temporary buffer */
3914 char * current_ev
= buffer
;
3915 char * end_buf
= buffer
+ IW_SCAN_MAX_DATA
;
3917 switch (priv
->firmware_type
) {
3918 case FIRMWARE_TYPE_AGERE
:
3919 atom_len
= sizeof(struct agere_scan_apinfo
);
3922 case FIRMWARE_TYPE_SYMBOL
:
3923 /* Lack of documentation necessitates this hack.
3924 * Different firmwares have 68 or 76 byte long atoms.
3925 * We try modulo first. If the length divides by both,
3926 * we check what would be the channel in the second
3927 * frame for a 68-byte atom. 76-byte atoms have 0 there.
3928 * Valid channel cannot be 0. */
3931 else if (scan_len
% 68)
3933 else if (scan_len
>= 1292 && scan
[68] == 0)
3939 case FIRMWARE_TYPE_INTERSIL
:
3941 if (priv
->has_hostscan
) {
3942 atom_len
= le16_to_cpup((__le16
*)scan
);
3943 /* Sanity check for atom_len */
3944 if (atom_len
< sizeof(struct prism2_scan_apinfo
)) {
3945 printk(KERN_ERR
"%s: Invalid atom_len in scan data: %d\n",
3946 dev
->name
, atom_len
);
3950 atom_len
= offsetof(struct prism2_scan_apinfo
, atim
);
3956 /* Check that we got an whole number of atoms */
3957 if ((scan_len
- offset
) % atom_len
) {
3958 printk(KERN_ERR
"%s: Unexpected scan data length %d, "
3959 "atom_len %d, offset %d\n", dev
->name
, scan_len
,
3964 /* Read the entries one by one */
3965 for (; offset
+ atom_len
<= scan_len
; offset
+= atom_len
) {
3967 atom
= (union hermes_scan_info
*) (scan
+ offset
);
3969 memset(&iwe
, 0, sizeof(iwe
));
3971 /* First entry *MUST* be the AP MAC address */
3972 iwe
.cmd
= SIOCGIWAP
;
3973 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
3974 memcpy(iwe
.u
.ap_addr
.sa_data
, atom
->a
.bssid
, ETH_ALEN
);
3975 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
3976 &iwe
, IW_EV_ADDR_LEN
);
3978 /* Other entries will be displayed in the order we give them */
3981 iwe
.u
.data
.length
= le16_to_cpu(atom
->a
.essid_len
);
3982 if (iwe
.u
.data
.length
> 32)
3983 iwe
.u
.data
.length
= 32;
3984 iwe
.cmd
= SIOCGIWESSID
;
3985 iwe
.u
.data
.flags
= 1;
3986 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
3987 &iwe
, atom
->a
.essid
);
3990 iwe
.cmd
= SIOCGIWMODE
;
3991 capabilities
= le16_to_cpu(atom
->a
.capabilities
);
3992 if (capabilities
& (WLAN_CAPABILITY_ESS
| WLAN_CAPABILITY_IBSS
)) {
3993 if (capabilities
& WLAN_CAPABILITY_ESS
)
3994 iwe
.u
.mode
= IW_MODE_MASTER
;
3996 iwe
.u
.mode
= IW_MODE_ADHOC
;
3997 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
3998 &iwe
, IW_EV_UINT_LEN
);
4001 channel
= atom
->s
.channel
;
4002 if ( (channel
>= 1) && (channel
<= NUM_CHANNELS
) ) {
4004 iwe
.cmd
= SIOCGIWFREQ
;
4005 iwe
.u
.freq
.m
= channel_frequency
[channel
-1] * 100000;
4007 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
4008 &iwe
, IW_EV_FREQ_LEN
);
4011 /* Add quality statistics. level and noise in dB. No link quality */
4013 iwe
.u
.qual
.updated
= IW_QUAL_DBM
| IW_QUAL_QUAL_INVALID
;
4014 iwe
.u
.qual
.level
= (__u8
) le16_to_cpu(atom
->a
.level
) - 0x95;
4015 iwe
.u
.qual
.noise
= (__u8
) le16_to_cpu(atom
->a
.noise
) - 0x95;
4016 /* Wireless tools prior to 27.pre22 will show link quality
4017 * anyway, so we provide a reasonable value. */
4018 if (iwe
.u
.qual
.level
> iwe
.u
.qual
.noise
)
4019 iwe
.u
.qual
.qual
= iwe
.u
.qual
.level
- iwe
.u
.qual
.noise
;
4021 iwe
.u
.qual
.qual
= 0;
4022 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
,
4023 &iwe
, IW_EV_QUAL_LEN
);
4025 /* Add encryption capability */
4026 iwe
.cmd
= SIOCGIWENCODE
;
4027 if (capabilities
& WLAN_CAPABILITY_PRIVACY
)
4028 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
4030 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
4031 iwe
.u
.data
.length
= 0;
4032 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
,
4033 &iwe
, atom
->a
.essid
);
4035 /* Bit rate is not available in Lucent/Agere firmwares */
4036 if (priv
->firmware_type
!= FIRMWARE_TYPE_AGERE
) {
4037 char * current_val
= current_ev
+ IW_EV_LCP_LEN
;
4041 if (priv
->firmware_type
== FIRMWARE_TYPE_SYMBOL
)
4046 iwe
.cmd
= SIOCGIWRATE
;
4047 /* Those two flags are ignored... */
4048 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
4050 for (i
= 0; i
< 10; i
+= step
) {
4051 /* NULL terminated */
4052 if (atom
->p
.rates
[i
] == 0x0)
4054 /* Bit rate given in 500 kb/s units (+ 0x80) */
4055 iwe
.u
.bitrate
.value
= ((atom
->p
.rates
[i
] & 0x7f) * 500000);
4056 current_val
= iwe_stream_add_value(info
, current_ev
,
4061 /* Check if we added any event */
4062 if ((current_val
- current_ev
) > iwe_stream_lcp_len(info
))
4063 current_ev
= current_val
;
4066 /* The other data in the scan result are not really
4067 * interesting, so for now drop it - Jean II */
4069 return current_ev
- buffer
;
4072 /* Return results of a scan */
4073 static int orinoco_ioctl_getscan(struct net_device
*dev
,
4074 struct iw_request_info
*info
,
4075 struct iw_point
*srq
,
4078 struct orinoco_private
*priv
= netdev_priv(dev
);
4080 unsigned long flags
;
4082 if (orinoco_lock(priv
, &flags
) != 0)
4085 /* If no results yet, ask to try again later */
4086 if (priv
->scan_result
== NULL
) {
4087 if (priv
->scan_inprogress
)
4088 /* Important note : we don't want to block the caller
4089 * until results are ready for various reasons.
4090 * First, managing wait queues is complex and racy.
4091 * Second, we grab some rtnetlink lock before comming
4092 * here (in dev_ioctl()).
4093 * Third, we generate an Wireless Event, so the
4094 * caller can wait itself on that - Jean II */
4097 /* Client error, no scan results...
4098 * The caller need to restart the scan. */
4101 /* We have some results to push back to user space */
4103 /* Translate to WE format */
4104 int ret
= orinoco_translate_scan(dev
, info
, extra
,
4110 kfree(priv
->scan_result
);
4111 priv
->scan_result
= NULL
;
4116 srq
->flags
= (__u16
) priv
->scan_mode
;
4118 /* In any case, Scan results will be cleaned up in the
4119 * reset function and when exiting the driver.
4120 * The person triggering the scanning may never come to
4121 * pick the results, so we need to do it in those places.
4124 #ifdef SCAN_SINGLE_READ
4125 /* If you enable this option, only one client (the first
4126 * one) will be able to read the result (and only one
4127 * time). If there is multiple concurent clients that
4128 * want to read scan results, this behavior is not
4129 * advisable - Jean II */
4130 kfree(priv
->scan_result
);
4131 priv
->scan_result
= NULL
;
4132 #endif /* SCAN_SINGLE_READ */
4133 /* Here, if too much time has elapsed since last scan,
4134 * we may want to clean up scan results... - Jean II */
4137 /* Scan is no longer in progress */
4138 priv
->scan_inprogress
= 0;
4141 orinoco_unlock(priv
, &flags
);
4145 /* Commit handler, called after set operations */
4146 static int orinoco_ioctl_commit(struct net_device
*dev
,
4147 struct iw_request_info
*info
,
4151 struct orinoco_private
*priv
= netdev_priv(dev
);
4152 struct hermes
*hw
= &priv
->hw
;
4153 unsigned long flags
;
4159 if (priv
->broken_disableport
) {
4160 orinoco_reset(&priv
->reset_work
);
4164 if (orinoco_lock(priv
, &flags
) != 0)
4167 err
= hermes_disable_port(hw
, 0);
4169 printk(KERN_WARNING
"%s: Unable to disable port "
4170 "while reconfiguring card\n", dev
->name
);
4171 priv
->broken_disableport
= 1;
4175 err
= __orinoco_program_rids(dev
);
4177 printk(KERN_WARNING
"%s: Unable to reconfigure card\n",
4182 err
= hermes_enable_port(hw
, 0);
4184 printk(KERN_WARNING
"%s: Unable to enable port while reconfiguring card\n",
4191 printk(KERN_WARNING
"%s: Resetting instead...\n", dev
->name
);
4192 schedule_work(&priv
->reset_work
);
4196 orinoco_unlock(priv
, &flags
);
4200 static const struct iw_priv_args orinoco_privtab
[] = {
4201 { SIOCIWFIRSTPRIV
+ 0x0, 0, 0, "force_reset" },
4202 { SIOCIWFIRSTPRIV
+ 0x1, 0, 0, "card_reset" },
4203 { SIOCIWFIRSTPRIV
+ 0x2, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
4205 { SIOCIWFIRSTPRIV
+ 0x3, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
4207 { SIOCIWFIRSTPRIV
+ 0x4, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
4208 0, "set_preamble" },
4209 { SIOCIWFIRSTPRIV
+ 0x5, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
4211 { SIOCIWFIRSTPRIV
+ 0x6, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
4212 0, "set_ibssport" },
4213 { SIOCIWFIRSTPRIV
+ 0x7, 0, IW_PRIV_TYPE_INT
| IW_PRIV_SIZE_FIXED
| 1,
4215 { SIOCIWFIRSTPRIV
+ 0x9, 0, IW_PRIV_TYPE_BYTE
| MAX_RID_LEN
,
4221 * Structures to export the Wireless Handlers
4224 static const iw_handler orinoco_handler
[] = {
4225 [SIOCSIWCOMMIT
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_commit
,
4226 [SIOCGIWNAME
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_getname
,
4227 [SIOCSIWFREQ
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_setfreq
,
4228 [SIOCGIWFREQ
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_getfreq
,
4229 [SIOCSIWMODE
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_setmode
,
4230 [SIOCGIWMODE
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_getmode
,
4231 [SIOCSIWSENS
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_setsens
,
4232 [SIOCGIWSENS
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_getsens
,
4233 [SIOCGIWRANGE
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_getiwrange
,
4234 [SIOCSIWSPY
-SIOCIWFIRST
] = (iw_handler
) iw_handler_set_spy
,
4235 [SIOCGIWSPY
-SIOCIWFIRST
] = (iw_handler
) iw_handler_get_spy
,
4236 [SIOCSIWTHRSPY
-SIOCIWFIRST
] = (iw_handler
) iw_handler_set_thrspy
,
4237 [SIOCGIWTHRSPY
-SIOCIWFIRST
] = (iw_handler
) iw_handler_get_thrspy
,
4238 [SIOCSIWAP
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_setwap
,
4239 [SIOCGIWAP
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_getwap
,
4240 [SIOCSIWSCAN
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_setscan
,
4241 [SIOCGIWSCAN
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_getscan
,
4242 [SIOCSIWESSID
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_setessid
,
4243 [SIOCGIWESSID
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_getessid
,
4244 [SIOCSIWNICKN
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_setnick
,
4245 [SIOCGIWNICKN
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_getnick
,
4246 [SIOCSIWRATE
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_setrate
,
4247 [SIOCGIWRATE
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_getrate
,
4248 [SIOCSIWRTS
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_setrts
,
4249 [SIOCGIWRTS
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_getrts
,
4250 [SIOCSIWFRAG
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_setfrag
,
4251 [SIOCGIWFRAG
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_getfrag
,
4252 [SIOCGIWRETRY
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_getretry
,
4253 [SIOCSIWENCODE
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_setiwencode
,
4254 [SIOCGIWENCODE
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_getiwencode
,
4255 [SIOCSIWPOWER
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_setpower
,
4256 [SIOCGIWPOWER
-SIOCIWFIRST
] = (iw_handler
) orinoco_ioctl_getpower
,
4261 Added typecasting since we no longer use iwreq_data -- Moustafa
4263 static const iw_handler orinoco_private_handler
[] = {
4264 [0] = (iw_handler
) orinoco_ioctl_reset
,
4265 [1] = (iw_handler
) orinoco_ioctl_reset
,
4266 [2] = (iw_handler
) orinoco_ioctl_setport3
,
4267 [3] = (iw_handler
) orinoco_ioctl_getport3
,
4268 [4] = (iw_handler
) orinoco_ioctl_setpreamble
,
4269 [5] = (iw_handler
) orinoco_ioctl_getpreamble
,
4270 [6] = (iw_handler
) orinoco_ioctl_setibssport
,
4271 [7] = (iw_handler
) orinoco_ioctl_getibssport
,
4272 [9] = (iw_handler
) orinoco_ioctl_getrid
,
4275 static const struct iw_handler_def orinoco_handler_def
= {
4276 .num_standard
= ARRAY_SIZE(orinoco_handler
),
4277 .num_private
= ARRAY_SIZE(orinoco_private_handler
),
4278 .num_private_args
= ARRAY_SIZE(orinoco_privtab
),
4279 .standard
= orinoco_handler
,
4280 .private = orinoco_private_handler
,
4281 .private_args
= orinoco_privtab
,
4282 .get_wireless_stats
= orinoco_get_wireless_stats
,
4285 static void orinoco_get_drvinfo(struct net_device
*dev
,
4286 struct ethtool_drvinfo
*info
)
4288 struct orinoco_private
*priv
= netdev_priv(dev
);
4290 strncpy(info
->driver
, DRIVER_NAME
, sizeof(info
->driver
) - 1);
4291 strncpy(info
->version
, DRIVER_VERSION
, sizeof(info
->version
) - 1);
4292 strncpy(info
->fw_version
, priv
->fw_name
, sizeof(info
->fw_version
) - 1);
4295 static struct ethtool_ops orinoco_ethtool_ops
= {
4296 .get_drvinfo
= orinoco_get_drvinfo
,
4297 .get_link
= ethtool_op_get_link
,
4300 /********************************************************************/
4301 /* Module initialization */
4302 /********************************************************************/
4304 EXPORT_SYMBOL(alloc_orinocodev
);
4305 EXPORT_SYMBOL(free_orinocodev
);
4307 EXPORT_SYMBOL(__orinoco_up
);
4308 EXPORT_SYMBOL(__orinoco_down
);
4309 EXPORT_SYMBOL(orinoco_reinit_firmware
);
4311 EXPORT_SYMBOL(orinoco_interrupt
);
4313 EXPORT_SYMBOL(__orinoco_ev_rx
);
4314 EXPORT_SYMBOL(__orinoco_ev_info
);
4316 /* Can't be declared "const" or the whole __initdata section will
4318 static char version
[] __initdata
= DRIVER_NAME
" " DRIVER_VERSION
4319 " (David Gibson <hermes@gibson.dropbear.id.au>, "
4320 "Pavel Roskin <proski@gnu.org>, et al)";
4322 static int __init
init_orinoco(void)
4324 printk(KERN_DEBUG
"%s\n", version
);
4328 static void __exit
exit_orinoco(void)
4332 module_init(init_orinoco
);
4333 module_exit(exit_orinoco
);