1 /*======================================================================
3 Aironet driver for 4500 and 4800 series cards
5 This code is released under both the GPL version 2 and BSD licenses.
6 Either license may be used. The respective licenses are found at
9 This code was developed by Benjamin Reed <breed@users.sourceforge.net>
10 including portions of which come from the Aironet PC4500
11 Developer's Reference Manual and used with permission. Copyright
12 (C) 1999 Benjamin Reed. All Rights Reserved. Permission to use
13 code in the Developer's manual was granted for this driver by
14 Aironet. Major code contributions were received from Javier Achirica
15 <achirica@users.sourceforge.net> and Jean Tourrilhes <jt@hpl.hp.com>.
16 Code was also integrated from the Cisco Aironet driver for Linux.
17 Support for MPI350 cards was added by Fabrice Bellet
18 <fabrice@bellet.info>.
20 ======================================================================*/
22 #include <linux/err.h>
23 #include <linux/init.h>
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/proc_fs.h>
29 #include <linux/sched.h>
30 #include <linux/ptrace.h>
31 #include <linux/slab.h>
32 #include <linux/string.h>
33 #include <linux/timer.h>
34 #include <linux/interrupt.h>
36 #include <linux/bitops.h>
37 #include <linux/scatterlist.h>
38 #include <linux/crypto.h>
40 #include <asm/unaligned.h>
42 #include <linux/netdevice.h>
43 #include <linux/etherdevice.h>
44 #include <linux/skbuff.h>
45 #include <linux/if_arp.h>
46 #include <linux/ioport.h>
47 #include <linux/pci.h>
48 #include <linux/uaccess.h>
49 #include <linux/kthread.h>
50 #include <linux/freezer.h>
52 #include <crypto/aes.h>
53 #include <crypto/skcipher.h>
55 #include <net/cfg80211.h>
56 #include <net/iw_handler.h>
60 #define DRV_NAME "airo"
63 static const struct pci_device_id card_ids[] = {
64 { 0x14b9, 1, PCI_ANY_ID, PCI_ANY_ID, },
65 { 0x14b9, 0x4500, PCI_ANY_ID, PCI_ANY_ID },
66 { 0x14b9, 0x4800, PCI_ANY_ID, PCI_ANY_ID, },
67 { 0x14b9, 0x0340, PCI_ANY_ID, PCI_ANY_ID, },
68 { 0x14b9, 0x0350, PCI_ANY_ID, PCI_ANY_ID, },
69 { 0x14b9, 0x5000, PCI_ANY_ID, PCI_ANY_ID, },
70 { 0x14b9, 0xa504, PCI_ANY_ID, PCI_ANY_ID, },
73 MODULE_DEVICE_TABLE(pci, card_ids);
75 static int airo_pci_probe(struct pci_dev *, const struct pci_device_id *);
76 static void airo_pci_remove(struct pci_dev *);
77 static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state);
78 static int airo_pci_resume(struct pci_dev *pdev);
80 static struct pci_driver airo_driver = {
83 .probe = airo_pci_probe,
84 .remove = airo_pci_remove,
85 .suspend = airo_pci_suspend,
86 .resume = airo_pci_resume,
88 #endif /* CONFIG_PCI */
90 /* Include Wireless Extension definition and check version - Jean II */
91 #include <linux/wireless.h>
92 #define WIRELESS_SPY /* enable iwspy support */
94 #define CISCO_EXT /* enable Cisco extensions */
96 #include <linux/delay.h>
99 /* Hack to do some power saving */
100 #define POWER_ON_DOWN
102 /* As you can see this list is HUGH!
103 I really don't know what a lot of these counts are about, but they
104 are all here for completeness. If the IGNLABEL macro is put in
105 infront of the label, that statistic will not be included in the list
106 of statistics in the /proc filesystem */
108 #define IGNLABEL(comment) NULL
109 static const char *statsLabels[] = {
111 IGNLABEL("RxPlcpCrcErr"),
112 IGNLABEL("RxPlcpFormatErr"),
113 IGNLABEL("RxPlcpLengthErr"),
144 "LostSync-MissedBeacons",
145 "LostSync-ArlExceeded",
147 "LostSync-Disassoced",
148 "LostSync-TsfTiming",
157 IGNLABEL("HmacTxMc"),
158 IGNLABEL("HmacTxBc"),
159 IGNLABEL("HmacTxUc"),
160 IGNLABEL("HmacTxFail"),
161 IGNLABEL("HmacRxMc"),
162 IGNLABEL("HmacRxBc"),
163 IGNLABEL("HmacRxUc"),
164 IGNLABEL("HmacRxDiscard"),
165 IGNLABEL("HmacRxAccepted"),
173 IGNLABEL("ReasonOutsideTable"),
174 IGNLABEL("ReasonStatus1"),
175 IGNLABEL("ReasonStatus2"),
176 IGNLABEL("ReasonStatus3"),
177 IGNLABEL("ReasonStatus4"),
178 IGNLABEL("ReasonStatus5"),
179 IGNLABEL("ReasonStatus6"),
180 IGNLABEL("ReasonStatus7"),
181 IGNLABEL("ReasonStatus8"),
182 IGNLABEL("ReasonStatus9"),
183 IGNLABEL("ReasonStatus10"),
184 IGNLABEL("ReasonStatus11"),
185 IGNLABEL("ReasonStatus12"),
186 IGNLABEL("ReasonStatus13"),
187 IGNLABEL("ReasonStatus14"),
188 IGNLABEL("ReasonStatus15"),
189 IGNLABEL("ReasonStatus16"),
190 IGNLABEL("ReasonStatus17"),
191 IGNLABEL("ReasonStatus18"),
192 IGNLABEL("ReasonStatus19"),
212 #define RUN_AT(x) (jiffies+(x))
216 /* These variables are for insmod, since it seems that the rates
217 can only be set in setup_card. Rates should be a comma separated
218 (no spaces) list of rates (up to 8). */
221 static char *ssids[3];
227 int maxencrypt /* = 0 */; /* The highest rate that the card can encrypt at.
228 0 means no limit. For old cards this was 4 */
230 static int auto_wep /* = 0 */; /* If set, it tries to figure out the wep mode */
231 static int aux_bap /* = 0 */; /* Checks to see if the aux ports are needed to read
232 the bap, needed on some older cards and buses. */
235 static int probe = 1;
237 static kuid_t proc_kuid;
238 static int proc_uid /* = 0 */;
240 static kgid_t proc_kgid;
241 static int proc_gid /* = 0 */;
243 static int airo_perm = 0555;
245 static int proc_perm = 0644;
247 MODULE_AUTHOR("Benjamin Reed");
248 MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet cards. "
249 "Direct support for ISA/PCI/MPI cards and support for PCMCIA when used with airo_cs.");
250 MODULE_LICENSE("Dual BSD/GPL");
251 MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340/350");
252 module_param_hw_array(io, int, ioport, NULL, 0);
253 module_param_hw_array(irq, int, irq, NULL, 0);
254 module_param_array(rates, int, NULL, 0);
255 module_param_array(ssids, charp, NULL, 0);
256 module_param(auto_wep, int, 0);
257 MODULE_PARM_DESC(auto_wep,
258 "If non-zero, the driver will keep looping through the authentication options until an association is made. "
259 "The value of auto_wep is number of the wep keys to check. "
260 "A value of 2 will try using the key at index 0 and index 1.");
261 module_param(aux_bap, int, 0);
262 MODULE_PARM_DESC(aux_bap,
263 "If non-zero, the driver will switch into a mode that seems to work better for older cards with some older buses. "
264 "Before switching it checks that the switch is needed.");
265 module_param(maxencrypt, int, 0);
266 MODULE_PARM_DESC(maxencrypt,
267 "The maximum speed that the card can do encryption. "
268 "Units are in 512kbs. "
269 "Zero (default) means there is no limit. "
270 "Older cards used to be limited to 2mbs (4).");
271 module_param(adhoc, int, 0);
272 MODULE_PARM_DESC(adhoc, "If non-zero, the card will start in adhoc mode.");
273 module_param(probe, int, 0);
274 MODULE_PARM_DESC(probe, "If zero, the driver won't start the card.");
276 module_param(proc_uid, int, 0);
277 MODULE_PARM_DESC(proc_uid, "The uid that the /proc files will belong to.");
278 module_param(proc_gid, int, 0);
279 MODULE_PARM_DESC(proc_gid, "The gid that the /proc files will belong to.");
280 module_param(airo_perm, int, 0);
281 MODULE_PARM_DESC(airo_perm, "The permission bits of /proc/[driver/]aironet.");
282 module_param(proc_perm, int, 0);
283 MODULE_PARM_DESC(proc_perm, "The permission bits of the files in /proc");
285 /* This is a kind of sloppy hack to get this information to OUT4500 and
286 IN4500. I would be extremely interested in the situation where this
287 doesn't work though!!! */
288 static int do8bitIO /* = 0 */;
297 #define MAC_ENABLE 0x0001
298 #define MAC_DISABLE 0x0002
299 #define CMD_LOSE_SYNC 0x0003 /* Not sure what this does... */
300 #define CMD_SOFTRESET 0x0004
301 #define HOSTSLEEP 0x0005
302 #define CMD_MAGIC_PKT 0x0006
303 #define CMD_SETWAKEMASK 0x0007
304 #define CMD_READCFG 0x0008
305 #define CMD_SETMODE 0x0009
306 #define CMD_ALLOCATETX 0x000a
307 #define CMD_TRANSMIT 0x000b
308 #define CMD_DEALLOCATETX 0x000c
310 #define CMD_WORKAROUND 0x0011
311 #define CMD_ALLOCATEAUX 0x0020
312 #define CMD_ACCESS 0x0021
313 #define CMD_PCIBAP 0x0022
314 #define CMD_PCIAUX 0x0023
315 #define CMD_ALLOCBUF 0x0028
316 #define CMD_GETTLV 0x0029
317 #define CMD_PUTTLV 0x002a
318 #define CMD_DELTLV 0x002b
319 #define CMD_FINDNEXTTLV 0x002c
320 #define CMD_PSPNODES 0x0030
321 #define CMD_SETCW 0x0031
322 #define CMD_SETPCF 0x0032
323 #define CMD_SETPHYREG 0x003e
324 #define CMD_TXTEST 0x003f
325 #define MAC_ENABLETX 0x0101
326 #define CMD_LISTBSS 0x0103
327 #define CMD_SAVECFG 0x0108
328 #define CMD_ENABLEAUX 0x0111
329 #define CMD_WRITERID 0x0121
330 #define CMD_USEPSPNODES 0x0130
331 #define MAC_ENABLERX 0x0201
334 #define ERROR_QUALIF 0x00
335 #define ERROR_ILLCMD 0x01
336 #define ERROR_ILLFMT 0x02
337 #define ERROR_INVFID 0x03
338 #define ERROR_INVRID 0x04
339 #define ERROR_LARGE 0x05
340 #define ERROR_NDISABL 0x06
341 #define ERROR_ALLOCBSY 0x07
342 #define ERROR_NORD 0x0B
343 #define ERROR_NOWR 0x0C
344 #define ERROR_INVFIDTX 0x0D
345 #define ERROR_TESTACT 0x0E
346 #define ERROR_TAGNFND 0x12
347 #define ERROR_DECODE 0x20
348 #define ERROR_DESCUNAV 0x21
349 #define ERROR_BADLEN 0x22
350 #define ERROR_MODE 0x80
351 #define ERROR_HOP 0x81
352 #define ERROR_BINTER 0x82
353 #define ERROR_RXMODE 0x83
354 #define ERROR_MACADDR 0x84
355 #define ERROR_RATES 0x85
356 #define ERROR_ORDER 0x86
357 #define ERROR_SCAN 0x87
358 #define ERROR_AUTH 0x88
359 #define ERROR_PSMODE 0x89
360 #define ERROR_RTYPE 0x8A
361 #define ERROR_DIVER 0x8B
362 #define ERROR_SSID 0x8C
363 #define ERROR_APLIST 0x8D
364 #define ERROR_AUTOWAKE 0x8E
365 #define ERROR_LEAP 0x8F
376 #define LINKSTAT 0x10
380 #define TXALLOCFID 0x22
381 #define TXCOMPLFID 0x24
396 /* Offset into aux memory for descriptors */
397 #define AUX_OFFSET 0x800
398 /* Size of allocated packets */
401 /* Size of the transmit queue */
405 #define BAP0 0 /* Used for receiving packets */
406 #define BAP1 2 /* Used for xmiting packets and working with RIDS */
409 #define COMMAND_BUSY 0x8000
411 #define BAP_BUSY 0x8000
412 #define BAP_ERR 0x4000
413 #define BAP_DONE 0x2000
415 #define PROMISC 0xffff
416 #define NOPROMISC 0x0000
419 #define EV_CLEARCOMMANDBUSY 0x4000
422 #define EV_TXEXC 0x04
423 #define EV_ALLOC 0x08
425 #define EV_AWAKE 0x100
426 #define EV_TXCPY 0x400
427 #define EV_UNKNOWN 0x800
428 #define EV_MIC 0x1000 /* Message Integrity Check Interrupt */
429 #define EV_AWAKEN 0x2000
430 #define STATUS_INTS (EV_AWAKE|EV_LINK|EV_TXEXC|EV_TX|EV_TXCPY|EV_RX|EV_MIC)
432 #ifdef CHECK_UNKNOWN_INTS
433 #define IGNORE_INTS ( EV_CMD | EV_UNKNOWN)
435 #define IGNORE_INTS (~STATUS_INTS)
442 #define RID_CAPABILITIES 0xFF00
443 #define RID_APINFO 0xFF01
444 #define RID_RADIOINFO 0xFF02
445 #define RID_UNKNOWN3 0xFF03
446 #define RID_RSSI 0xFF04
447 #define RID_CONFIG 0xFF10
448 #define RID_SSID 0xFF11
449 #define RID_APLIST 0xFF12
450 #define RID_DRVNAME 0xFF13
451 #define RID_ETHERENCAP 0xFF14
452 #define RID_WEP_TEMP 0xFF15
453 #define RID_WEP_PERM 0xFF16
454 #define RID_MODULATION 0xFF17
455 #define RID_OPTIONS 0xFF18
456 #define RID_ACTUALCONFIG 0xFF20 /*readonly*/
457 #define RID_FACTORYCONFIG 0xFF21
458 #define RID_UNKNOWN22 0xFF22
459 #define RID_LEAPUSERNAME 0xFF23
460 #define RID_LEAPPASSWORD 0xFF24
461 #define RID_STATUS 0xFF50
462 #define RID_BEACON_HST 0xFF51
463 #define RID_BUSY_HST 0xFF52
464 #define RID_RETRIES_HST 0xFF53
465 #define RID_UNKNOWN54 0xFF54
466 #define RID_UNKNOWN55 0xFF55
467 #define RID_UNKNOWN56 0xFF56
468 #define RID_MIC 0xFF57
469 #define RID_STATS16 0xFF60
470 #define RID_STATS16DELTA 0xFF61
471 #define RID_STATS16DELTACLEAR 0xFF62
472 #define RID_STATS 0xFF68
473 #define RID_STATSDELTA 0xFF69
474 #define RID_STATSDELTACLEAR 0xFF6A
475 #define RID_ECHOTEST_RID 0xFF70
476 #define RID_ECHOTEST_RESULTS 0xFF71
477 #define RID_BSSLISTFIRST 0xFF72
478 #define RID_BSSLISTNEXT 0xFF73
479 #define RID_WPA_BSSLISTFIRST 0xFF74
480 #define RID_WPA_BSSLISTNEXT 0xFF75
497 * Rids and endian-ness: The Rids will always be in cpu endian, since
498 * this all the patches from the big-endian guys end up doing that.
499 * so all rid access should use the read/writeXXXRid routines.
502 /* This structure came from an email sent to me from an engineer at
503 aironet for inclusion into this driver */
504 typedef struct WepKeyRid WepKeyRid;
513 /* These structures are from the Aironet's PC4500 Developers Manual */
514 typedef struct Ssid Ssid;
520 typedef struct SsidRid SsidRid;
526 typedef struct ModulationRid ModulationRid;
527 struct ModulationRid {
530 #define MOD_DEFAULT cpu_to_le16(0)
531 #define MOD_CCK cpu_to_le16(1)
532 #define MOD_MOK cpu_to_le16(2)
535 typedef struct ConfigRid ConfigRid;
537 __le16 len; /* sizeof(ConfigRid) */
538 __le16 opmode; /* operating mode */
539 #define MODE_STA_IBSS cpu_to_le16(0)
540 #define MODE_STA_ESS cpu_to_le16(1)
541 #define MODE_AP cpu_to_le16(2)
542 #define MODE_AP_RPTR cpu_to_le16(3)
543 #define MODE_CFG_MASK cpu_to_le16(0xff)
544 #define MODE_ETHERNET_HOST cpu_to_le16(0<<8) /* rx payloads converted */
545 #define MODE_LLC_HOST cpu_to_le16(1<<8) /* rx payloads left as is */
546 #define MODE_AIRONET_EXTEND cpu_to_le16(1<<9) /* enable Aironet extenstions */
547 #define MODE_AP_INTERFACE cpu_to_le16(1<<10) /* enable ap interface extensions */
548 #define MODE_ANTENNA_ALIGN cpu_to_le16(1<<11) /* enable antenna alignment */
549 #define MODE_ETHER_LLC cpu_to_le16(1<<12) /* enable ethernet LLC */
550 #define MODE_LEAF_NODE cpu_to_le16(1<<13) /* enable leaf node bridge */
551 #define MODE_CF_POLLABLE cpu_to_le16(1<<14) /* enable CF pollable */
552 #define MODE_MIC cpu_to_le16(1<<15) /* enable MIC */
553 __le16 rmode; /* receive mode */
554 #define RXMODE_BC_MC_ADDR cpu_to_le16(0)
555 #define RXMODE_BC_ADDR cpu_to_le16(1) /* ignore multicasts */
556 #define RXMODE_ADDR cpu_to_le16(2) /* ignore multicast and broadcast */
557 #define RXMODE_RFMON cpu_to_le16(3) /* wireless monitor mode */
558 #define RXMODE_RFMON_ANYBSS cpu_to_le16(4)
559 #define RXMODE_LANMON cpu_to_le16(5) /* lan style monitor -- data packets only */
560 #define RXMODE_MASK cpu_to_le16(255)
561 #define RXMODE_DISABLE_802_3_HEADER cpu_to_le16(1<<8) /* disables 802.3 header on rx */
562 #define RXMODE_FULL_MASK (RXMODE_MASK | RXMODE_DISABLE_802_3_HEADER)
563 #define RXMODE_NORMALIZED_RSSI cpu_to_le16(1<<9) /* return normalized RSSI */
566 u8 macAddr[ETH_ALEN];
568 __le16 shortRetryLimit;
569 __le16 longRetryLimit;
570 __le16 txLifetime; /* in kusec */
571 __le16 rxLifetime; /* in kusec */
574 __le16 u16deviceType; /* for overriding device type */
577 __le16 _reserved1[3];
578 /*---------- Scanning/Associating ----------*/
580 #define SCANMODE_ACTIVE cpu_to_le16(0)
581 #define SCANMODE_PASSIVE cpu_to_le16(1)
582 #define SCANMODE_AIROSCAN cpu_to_le16(2)
583 __le16 probeDelay; /* in kusec */
584 __le16 probeEnergyTimeout; /* in kusec */
585 __le16 probeResponseTimeout;
586 __le16 beaconListenTimeout;
587 __le16 joinNetTimeout;
590 #define AUTH_OPEN cpu_to_le16(0x1)
591 #define AUTH_ENCRYPT cpu_to_le16(0x101)
592 #define AUTH_SHAREDKEY cpu_to_le16(0x102)
593 #define AUTH_ALLOW_UNENCRYPTED cpu_to_le16(0x200)
594 __le16 associationTimeout;
595 __le16 specifiedApTimeout;
596 __le16 offlineScanInterval;
597 __le16 offlineScanDuration;
598 __le16 linkLossDelay;
599 __le16 maxBeaconLostTime;
600 __le16 refreshInterval;
601 #define DISABLE_REFRESH cpu_to_le16(0xFFFF)
602 __le16 _reserved1a[1];
603 /*---------- Power save operation ----------*/
604 __le16 powerSaveMode;
605 #define POWERSAVE_CAM cpu_to_le16(0)
606 #define POWERSAVE_PSP cpu_to_le16(1)
607 #define POWERSAVE_PSPCAM cpu_to_le16(2)
608 __le16 sleepForDtims;
609 __le16 listenInterval;
610 __le16 fastListenInterval;
612 __le16 fastListenDelay;
613 __le16 _reserved2[2];
614 /*---------- Ap/Ibss config items ----------*/
621 __le16 bridgeDistance;
623 /*---------- Radio configuration ----------*/
625 #define RADIOTYPE_DEFAULT cpu_to_le16(0)
626 #define RADIOTYPE_802_11 cpu_to_le16(1)
627 #define RADIOTYPE_LEGACY cpu_to_le16(2)
631 #define TXPOWER_DEFAULT 0
632 __le16 rssiThreshold;
633 #define RSSI_DEFAULT 0
635 #define PREAMBLE_AUTO cpu_to_le16(0)
636 #define PREAMBLE_LONG cpu_to_le16(1)
637 #define PREAMBLE_SHORT cpu_to_le16(2)
640 __le16 radioSpecific;
641 /*---------- Aironet Extensions ----------*/
646 __le16 _reserved4[1];
647 /*---------- Aironet Extensions ----------*/
649 #define MAGIC_ACTION_STSCHG 1
650 #define MAGIC_ACTION_RESUME 2
651 #define MAGIC_IGNORE_MCAST (1<<8)
652 #define MAGIC_IGNORE_BCAST (1<<9)
653 #define MAGIC_SWITCH_TO_PSP (0<<10)
654 #define MAGIC_STAY_IN_CAM (1<<10)
659 typedef struct StatusRid StatusRid;
669 u8 bssid[4][ETH_ALEN];
676 __le16 hopsToBackbone;
678 __le16 generatedLoad;
679 __le16 accumulatedArl;
680 __le16 signalQuality;
681 __le16 currentXmitRate;
682 __le16 apDevExtensions;
683 __le16 normalizedSignalStrength;
684 __le16 shortPreamble;
686 u8 noisePercent; /* Noise percent in last second */
687 u8 noisedBm; /* Noise dBm in last second */
688 u8 noiseAvePercent; /* Noise percent in last minute */
689 u8 noiseAvedBm; /* Noise dBm in last minute */
690 u8 noiseMaxPercent; /* Highest noise percent in last minute */
691 u8 noiseMaxdBm; /* Highest noise dbm in last minute */
695 #define STAT_NOPACKETS 0
696 #define STAT_NOCARRIERSET 10
697 #define STAT_GOTCARRIERSET 11
698 #define STAT_WRONGSSID 20
699 #define STAT_BADCHANNEL 25
700 #define STAT_BADBITRATES 30
701 #define STAT_BADPRIVACY 35
702 #define STAT_APFOUND 40
703 #define STAT_APREJECTED 50
704 #define STAT_AUTHENTICATING 60
705 #define STAT_DEAUTHENTICATED 61
706 #define STAT_AUTHTIMEOUT 62
707 #define STAT_ASSOCIATING 70
708 #define STAT_DEASSOCIATED 71
709 #define STAT_ASSOCTIMEOUT 72
710 #define STAT_NOTAIROAP 73
711 #define STAT_ASSOCIATED 80
712 #define STAT_LEAPING 90
713 #define STAT_LEAPFAILED 91
714 #define STAT_LEAPTIMEDOUT 92
715 #define STAT_LEAPCOMPLETE 93
718 typedef struct StatsRid StatsRid;
725 typedef struct APListRid APListRid;
731 typedef struct CapabilityRid CapabilityRid;
732 struct CapabilityRid {
740 char factoryAddr[ETH_ALEN];
741 char aironetAddr[ETH_ALEN];
744 char callid[ETH_ALEN];
745 char supportedRates[8];
748 __le16 txPowerLevels[8];
761 /* Only present on firmware >= 5.30.17 */
762 typedef struct BSSListRidExtra BSSListRidExtra;
763 struct BSSListRidExtra {
765 u8 fixed[12]; /* WLAN management frame */
769 typedef struct BSSListRid BSSListRid;
772 __le16 index; /* First is 0 and 0xffff means end of list */
773 #define RADIO_FH 1 /* Frequency hopping radio type */
774 #define RADIO_DS 2 /* Direct sequence radio type */
775 #define RADIO_TMA 4 /* Proprietary radio used in old cards (2500) */
777 u8 bssid[ETH_ALEN]; /* Mac address of the BSS */
782 #define CAP_ESS cpu_to_le16(1<<0)
783 #define CAP_IBSS cpu_to_le16(1<<1)
784 #define CAP_PRIVACY cpu_to_le16(1<<4)
785 #define CAP_SHORTHDR cpu_to_le16(1<<5)
787 __le16 beaconInterval;
788 u8 rates[8]; /* Same as rates for config rid */
789 struct { /* For frequency hopping only */
799 /* Only present on firmware >= 5.30.17 */
800 BSSListRidExtra extra;
805 struct list_head list;
808 typedef struct tdsRssiEntry tdsRssiEntry;
809 struct tdsRssiEntry {
814 typedef struct tdsRssiRid tdsRssiRid;
820 typedef struct MICRid MICRid;
824 __le16 multicastValid;
830 typedef struct MICBuffer MICBuffer;
853 #define TXCTL_TXOK (1<<1) /* report if tx is ok */
854 #define TXCTL_TXEX (1<<2) /* report if tx fails */
855 #define TXCTL_802_3 (0<<3) /* 802.3 packet */
856 #define TXCTL_802_11 (1<<3) /* 802.11 mac packet */
857 #define TXCTL_ETHERNET (0<<4) /* payload has ethertype */
858 #define TXCTL_LLC (1<<4) /* payload is llc */
859 #define TXCTL_RELEASE (0<<5) /* release after completion */
860 #define TXCTL_NORELEASE (1<<5) /* on completion returns to host */
862 #define BUSY_FID 0x10000
865 #define AIROMAGIC 0xa55a
866 /* Warning : SIOCDEVPRIVATE may disapear during 2.5.X - Jean II */
867 #ifdef SIOCIWFIRSTPRIV
868 #ifdef SIOCDEVPRIVATE
869 #define AIROOLDIOCTL SIOCDEVPRIVATE
870 #define AIROOLDIDIFC AIROOLDIOCTL + 1
871 #endif /* SIOCDEVPRIVATE */
872 #else /* SIOCIWFIRSTPRIV */
873 #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
874 #endif /* SIOCIWFIRSTPRIV */
875 /* This may be wrong. When using the new SIOCIWFIRSTPRIV range, we probably
876 * should use only "GET" ioctls (last bit set to 1). "SET" ioctls are root
877 * only and don't return the modified struct ifreq to the application which
878 * is usually a problem. - Jean II */
879 #define AIROIOCTL SIOCIWFIRSTPRIV
880 #define AIROIDIFC AIROIOCTL + 1
882 /* Ioctl constants to be used in airo_ioctl.command */
884 #define AIROGCAP 0 // Capability rid
885 #define AIROGCFG 1 // USED A LOT
886 #define AIROGSLIST 2 // System ID list
887 #define AIROGVLIST 3 // List of specified AP's
888 #define AIROGDRVNAM 4 // NOTUSED
889 #define AIROGEHTENC 5 // NOTUSED
890 #define AIROGWEPKTMP 6
891 #define AIROGWEPKNV 7
893 #define AIROGSTATSC32 9
894 #define AIROGSTATSD32 10
895 #define AIROGMICRID 11
896 #define AIROGMICSTATS 12
897 #define AIROGFLAGS 13
900 #define AIRORSWVERSION 17
902 /* Leave gap of 40 commands after AIROGSTATSD32 for future */
904 #define AIROPCAP AIROGSTATSD32 + 40
905 #define AIROPVLIST AIROPCAP + 1
906 #define AIROPSLIST AIROPVLIST + 1
907 #define AIROPCFG AIROPSLIST + 1
908 #define AIROPSIDS AIROPCFG + 1
909 #define AIROPAPLIST AIROPSIDS + 1
910 #define AIROPMACON AIROPAPLIST + 1 /* Enable mac */
911 #define AIROPMACOFF AIROPMACON + 1 /* Disable mac */
912 #define AIROPSTCLR AIROPMACOFF + 1
913 #define AIROPWEPKEY AIROPSTCLR + 1
914 #define AIROPWEPKEYNV AIROPWEPKEY + 1
915 #define AIROPLEAPPWD AIROPWEPKEYNV + 1
916 #define AIROPLEAPUSR AIROPLEAPPWD + 1
920 #define AIROFLSHRST AIROPWEPKEYNV + 40
921 #define AIROFLSHGCHR AIROFLSHRST + 1
922 #define AIROFLSHSTFL AIROFLSHGCHR + 1
923 #define AIROFLSHPCHR AIROFLSHSTFL + 1
924 #define AIROFLPUTBUF AIROFLSHPCHR + 1
925 #define AIRORESTART AIROFLPUTBUF + 1
927 #define FLASHSIZE 32768
928 #define AUXMEMSIZE (256 * 1024)
930 typedef struct aironet_ioctl {
931 unsigned short command; // What to do
932 unsigned short len; // Len of data
933 unsigned short ridnum; // rid number
934 unsigned char __user *data; // d-data
937 static const char swversion[] = "2.1";
938 #endif /* CISCO_EXT */
940 #define NUM_MODULES 2
941 #define MIC_MSGLEN_MAX 2400
942 #define EMMH32_MSGLEN_MAX MIC_MSGLEN_MAX
943 #define AIRO_DEF_MTU 2312
947 u8 enabled; // MIC enabled or not
948 u32 rxSuccess; // successful packets received
949 u32 rxIncorrectMIC; // pkts dropped due to incorrect MIC comparison
950 u32 rxNotMICed; // pkts dropped due to not being MIC'd
951 u32 rxMICPlummed; // pkts dropped due to not having a MIC plummed
952 u32 rxWrongSequence; // pkts dropped due to sequence number violation
957 __be32 coeff[((EMMH32_MSGLEN_MAX)+3)>>2];
958 u64 accum; // accumulated mic, reduced to u32 in final()
959 int position; // current position (byte offset) in message
963 } part; // saves partial message word across update() calls
967 emmh32_context seed; // Context - the seed
968 u32 rx; // Received sequence number
969 u32 tx; // Tx sequence number
970 u32 window; // Start of window
971 u8 valid; // Flag to say if context is valid or not
976 miccntx mCtx; // Multicast context
977 miccntx uCtx; // Unicast context
981 unsigned int rid: 16;
982 unsigned int len: 15;
983 unsigned int valid: 1;
984 dma_addr_t host_addr;
988 unsigned int offset: 15;
990 unsigned int len: 15;
991 unsigned int valid: 1;
992 dma_addr_t host_addr;
1004 unsigned int ctl: 15;
1005 unsigned int rdy: 1;
1006 unsigned int len: 15;
1007 unsigned int valid: 1;
1008 dma_addr_t host_addr;
1012 * Host receive descriptor
1015 unsigned char __iomem *card_ram_off; /* offset into card memory of the
1017 RxFid rx_desc; /* card receive descriptor */
1018 char *virtual_host_addr; /* virtual address of host receive
1024 * Host transmit descriptor
1027 unsigned char __iomem *card_ram_off; /* offset into card memory of the
1029 TxFid tx_desc; /* card transmit descriptor */
1030 char *virtual_host_addr; /* virtual address of host receive
1036 * Host RID descriptor
1039 unsigned char __iomem *card_ram_off; /* offset into card memory of the
1041 Rid rid_desc; /* card RID descriptor */
1042 char *virtual_host_addr; /* virtual address of host receive
1051 #define HOST_SET (1 << 0)
1052 #define HOST_INT_TX (1 << 1) /* Interrupt on successful TX */
1053 #define HOST_INT_TXERR (1 << 2) /* Interrupt on unseccessful TX */
1054 #define HOST_LCC_PAYLOAD (1 << 4) /* LLC payload, 0 = Ethertype */
1055 #define HOST_DONT_RLSE (1 << 5) /* Don't release buffer when done */
1056 #define HOST_DONT_RETRY (1 << 6) /* Don't retry trasmit */
1057 #define HOST_CLR_AID (1 << 7) /* clear AID failure */
1058 #define HOST_RTS (1 << 9) /* Force RTS use */
1059 #define HOST_SHORT (1 << 10) /* Do short preamble */
1086 static WifiCtlHdr wifictlhdr8023 = {
1088 .ctl = HOST_DONT_RLSE,
1092 // A few details needed for WEP (Wireless Equivalent Privacy)
1093 #define MAX_KEY_SIZE 13 // 128 (?) bits
1094 #define MIN_KEY_SIZE 5 // 40 bits RC4 - WEP
1095 typedef struct wep_key_t {
1097 u8 key[16]; /* 40-bit and 104-bit keys */
1100 /* List of Wireless Handlers (new API) */
1101 static const struct iw_handler_def airo_handler_def;
1103 static const char version[] = "airo.c 0.6 (Ben Reed & Javier Achirica)";
1107 static int get_dec_u16( char *buffer, int *start, int limit );
1108 static void OUT4500( struct airo_info *, u16 reg, u16 value );
1109 static unsigned short IN4500( struct airo_info *, u16 reg );
1110 static u16 setup_card(struct airo_info*, u8 *mac, int lock);
1111 static int enable_MAC(struct airo_info *ai, int lock);
1112 static void disable_MAC(struct airo_info *ai, int lock);
1113 static void enable_interrupts(struct airo_info*);
1114 static void disable_interrupts(struct airo_info*);
1115 static u16 issuecommand(struct airo_info*, Cmd *pCmd, Resp *pRsp);
1116 static int bap_setup(struct airo_info*, u16 rid, u16 offset, int whichbap);
1117 static int aux_bap_read(struct airo_info*, __le16 *pu16Dst, int bytelen,
1119 static int fast_bap_read(struct airo_info*, __le16 *pu16Dst, int bytelen,
1121 static int bap_write(struct airo_info*, const __le16 *pu16Src, int bytelen,
1123 static int PC4500_accessrid(struct airo_info*, u16 rid, u16 accmd);
1124 static int PC4500_readrid(struct airo_info*, u16 rid, void *pBuf, int len, int lock);
1125 static int PC4500_writerid(struct airo_info*, u16 rid, const void
1126 *pBuf, int len, int lock);
1127 static int do_writerid( struct airo_info*, u16 rid, const void *rid_data,
1128 int len, int dummy );
1129 static u16 transmit_allocate(struct airo_info*, int lenPayload, int raw);
1130 static int transmit_802_3_packet(struct airo_info*, int len, char *pPacket);
1131 static int transmit_802_11_packet(struct airo_info*, int len, char *pPacket);
1133 static int mpi_send_packet (struct net_device *dev);
1134 static void mpi_unmap_card(struct pci_dev *pci);
1135 static void mpi_receive_802_3(struct airo_info *ai);
1136 static void mpi_receive_802_11(struct airo_info *ai);
1137 static int waitbusy (struct airo_info *ai);
1139 static irqreturn_t airo_interrupt( int irq, void* dev_id);
1140 static int airo_thread(void *data);
1141 static void timer_func( struct net_device *dev );
1142 static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
1143 static struct iw_statistics *airo_get_wireless_stats (struct net_device *dev);
1144 static void airo_read_wireless_stats (struct airo_info *local);
1146 static int readrids(struct net_device *dev, aironet_ioctl *comp);
1147 static int writerids(struct net_device *dev, aironet_ioctl *comp);
1148 static int flashcard(struct net_device *dev, aironet_ioctl *comp);
1149 #endif /* CISCO_EXT */
1150 static void micinit(struct airo_info *ai);
1151 static int micsetup(struct airo_info *ai);
1152 static int encapsulate(struct airo_info *ai, etherHead *pPacket, MICBuffer *buffer, int len);
1153 static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *pPacket, u16 payLen);
1155 static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi);
1156 static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm);
1158 static void airo_networks_free(struct airo_info *ai);
1161 struct net_device *dev;
1162 struct list_head dev_list;
1163 /* Note, we can have MAX_FIDS outstanding. FIDs are 16-bits, so we
1164 use the high bit to mark whether it is in use. */
1166 #define MPI_MAX_FIDS 1
1169 char keyindex; // Used with auto wep
1170 char defindex; // Used with auto wep
1171 struct proc_dir_entry *proc_entry;
1172 spinlock_t aux_lock;
1173 #define FLAG_RADIO_OFF 0 /* User disabling of MAC */
1174 #define FLAG_RADIO_DOWN 1 /* ifup/ifdown disabling of MAC */
1175 #define FLAG_RADIO_MASK 0x03
1176 #define FLAG_ENABLED 2
1177 #define FLAG_ADHOC 3 /* Needed by MIC */
1178 #define FLAG_MIC_CAPABLE 4
1179 #define FLAG_UPDATE_MULTI 5
1180 #define FLAG_UPDATE_UNI 6
1181 #define FLAG_802_11 7
1182 #define FLAG_PROMISC 8 /* IFF_PROMISC 0x100 - include/linux/if.h */
1183 #define FLAG_PENDING_XMIT 9
1184 #define FLAG_PENDING_XMIT11 10
1186 #define FLAG_REGISTERED 12
1187 #define FLAG_COMMIT 13
1188 #define FLAG_RESET 14
1189 #define FLAG_FLASHING 15
1190 #define FLAG_WPA_CAPABLE 16
1191 unsigned long flags;
1194 #define JOB_XMIT11 2
1196 #define JOB_PROMISC 4
1199 #define JOB_AUTOWEP 7
1200 #define JOB_WSTATS 8
1201 #define JOB_SCAN_RESULTS 9
1203 int (*bap_read)(struct airo_info*, __le16 *pu16Dst, int bytelen,
1205 unsigned short *flash;
1207 struct task_struct *list_bss_task;
1208 struct task_struct *airo_thread_task;
1209 struct semaphore sem;
1210 wait_queue_head_t thr_wait;
1211 unsigned long expires;
1213 struct sk_buff *skb;
1216 struct net_device *wifidev;
1217 struct iw_statistics wstats; // wireless stats
1218 unsigned long scan_timeout; /* Time scan should be read */
1219 struct iw_spy_data spy_data;
1220 struct iw_public_data wireless_data;
1222 struct crypto_sync_skcipher *tfm;
1224 mic_statistics micstats;
1225 HostRxDesc rxfids[MPI_MAX_FIDS]; // rx/tx/config MPI350 descriptors
1226 HostTxDesc txfids[MPI_MAX_FIDS];
1227 HostRidDesc config_desc;
1228 unsigned long ridbus; // phys addr of config_desc
1229 struct sk_buff_head txq;// tx queue used by mpi350 code
1230 struct pci_dev *pci;
1231 unsigned char __iomem *pcimem;
1232 unsigned char __iomem *pciaux;
1233 unsigned char *shared;
1234 dma_addr_t shared_dma;
1238 #define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE
1239 char proc_name[IFNAMSIZ];
1245 /* WPA-related stuff */
1246 unsigned int bssListFirst;
1247 unsigned int bssListNext;
1248 unsigned int bssListRidLen;
1250 struct list_head network_list;
1251 struct list_head network_free_list;
1252 BSSListElement *networks;
1255 static inline int bap_read(struct airo_info *ai, __le16 *pu16Dst, int bytelen,
1258 return ai->bap_read(ai, pu16Dst, bytelen, whichbap);
1261 static int setup_proc_entry( struct net_device *dev,
1262 struct airo_info *apriv );
1263 static int takedown_proc_entry( struct net_device *dev,
1264 struct airo_info *apriv );
1266 static int cmdreset(struct airo_info *ai);
1267 static int setflashmode (struct airo_info *ai);
1268 static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime);
1269 static int flashputbuf(struct airo_info *ai);
1270 static int flashrestart(struct airo_info *ai,struct net_device *dev);
1272 #define airo_print(type, name, fmt, args...) \
1273 printk(type DRV_NAME "(%s): " fmt "\n", name, ##args)
1275 #define airo_print_info(name, fmt, args...) \
1276 airo_print(KERN_INFO, name, fmt, ##args)
1278 #define airo_print_dbg(name, fmt, args...) \
1279 airo_print(KERN_DEBUG, name, fmt, ##args)
1281 #define airo_print_warn(name, fmt, args...) \
1282 airo_print(KERN_WARNING, name, fmt, ##args)
1284 #define airo_print_err(name, fmt, args...) \
1285 airo_print(KERN_ERR, name, fmt, ##args)
1287 #define AIRO_FLASH(dev) (((struct airo_info *)dev->ml_priv)->flash)
1289 /***********************************************************************
1291 ***********************************************************************
1294 static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq);
1295 static void MoveWindow(miccntx *context, u32 micSeq);
1296 static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
1297 struct crypto_sync_skcipher *tfm);
1298 static void emmh32_init(emmh32_context *context);
1299 static void emmh32_update(emmh32_context *context, u8 *pOctets, int len);
1300 static void emmh32_final(emmh32_context *context, u8 digest[4]);
1301 static int flashpchar(struct airo_info *ai,int byte,int dwelltime);
1303 static void age_mic_context(miccntx *cur, miccntx *old, u8 *key, int key_len,
1304 struct crypto_sync_skcipher *tfm)
1306 /* If the current MIC context is valid and its key is the same as
1307 * the MIC register, there's nothing to do.
1309 if (cur->valid && (memcmp(cur->key, key, key_len) == 0))
1312 /* Age current mic Context */
1313 memcpy(old, cur, sizeof(*cur));
1315 /* Initialize new context */
1316 memcpy(cur->key, key, key_len);
1317 cur->window = 33; /* Window always points to the middle */
1318 cur->rx = 0; /* Rx Sequence numbers */
1319 cur->tx = 0; /* Tx sequence numbers */
1320 cur->valid = 1; /* Key is now valid */
1322 /* Give key to mic seed */
1323 emmh32_setseed(&cur->seed, key, key_len, tfm);
1326 /* micinit - Initialize mic seed */
1328 static void micinit(struct airo_info *ai)
1332 clear_bit(JOB_MIC, &ai->jobs);
1333 PC4500_readrid(ai, RID_MIC, &mic_rid, sizeof(mic_rid), 0);
1336 ai->micstats.enabled = (le16_to_cpu(mic_rid.state) & 0x00FF) ? 1 : 0;
1337 if (!ai->micstats.enabled) {
1338 /* So next time we have a valid key and mic is enabled, we will
1339 * update the sequence number if the key is the same as before.
1341 ai->mod[0].uCtx.valid = 0;
1342 ai->mod[0].mCtx.valid = 0;
1346 if (mic_rid.multicastValid) {
1347 age_mic_context(&ai->mod[0].mCtx, &ai->mod[1].mCtx,
1348 mic_rid.multicast, sizeof(mic_rid.multicast),
1352 if (mic_rid.unicastValid) {
1353 age_mic_context(&ai->mod[0].uCtx, &ai->mod[1].uCtx,
1354 mic_rid.unicast, sizeof(mic_rid.unicast),
1359 /* micsetup - Get ready for business */
1361 static int micsetup(struct airo_info *ai) {
1364 if (ai->tfm == NULL)
1365 ai->tfm = crypto_alloc_sync_skcipher("ctr(aes)", 0, 0);
1367 if (IS_ERR(ai->tfm)) {
1368 airo_print_err(ai->dev->name, "failed to load transform for AES");
1373 for (i=0; i < NUM_MODULES; i++) {
1374 memset(&ai->mod[i].mCtx,0,sizeof(miccntx));
1375 memset(&ai->mod[i].uCtx,0,sizeof(miccntx));
1380 static const u8 micsnap[] = {0xAA,0xAA,0x03,0x00,0x40,0x96,0x00,0x02};
1382 /*===========================================================================
1383 * Description: Mic a packet
1385 * Inputs: etherHead * pointer to an 802.3 frame
1387 * Returns: BOOLEAN if successful, otherwise false.
1388 * PacketTxLen will be updated with the mic'd packets size.
1390 * Caveats: It is assumed that the frame buffer will already
1391 * be big enough to hold the largets mic message possible.
1392 * (No memory allocation is done here).
1394 * Author: sbraneky (10/15/01)
1395 * Merciless hacks by rwilcher (1/14/02)
1398 static int encapsulate(struct airo_info *ai ,etherHead *frame, MICBuffer *mic, int payLen)
1402 // Determine correct context
1403 // If not adhoc, always use unicast key
1405 if (test_bit(FLAG_ADHOC, &ai->flags) && (frame->da[0] & 0x1))
1406 context = &ai->mod[0].mCtx;
1408 context = &ai->mod[0].uCtx;
1410 if (!context->valid)
1413 mic->typelen = htons(payLen + 16); //Length of Mic'd packet
1415 memcpy(&mic->u.snap, micsnap, sizeof(micsnap)); // Add Snap
1418 mic->seq = htonl(context->tx);
1421 emmh32_init(&context->seed); // Mic the packet
1422 emmh32_update(&context->seed,frame->da,ETH_ALEN * 2); // DA,SA
1423 emmh32_update(&context->seed,(u8*)&mic->typelen,10); // Type/Length and Snap
1424 emmh32_update(&context->seed,(u8*)&mic->seq,sizeof(mic->seq)); //SEQ
1425 emmh32_update(&context->seed,(u8*)(frame + 1),payLen); //payload
1426 emmh32_final(&context->seed, (u8*)&mic->mic);
1428 /* New Type/length ?????????? */
1429 mic->typelen = 0; //Let NIC know it could be an oversized packet
1441 /*===========================================================================
1442 * Description: Decapsulates a MIC'd packet and returns the 802.3 packet
1443 * (removes the MIC stuff) if packet is a valid packet.
1445 * Inputs: etherHead pointer to the 802.3 packet
1447 * Returns: BOOLEAN - TRUE if packet should be dropped otherwise FALSE
1449 * Author: sbraneky (10/15/01)
1450 * Merciless hacks by rwilcher (1/14/02)
1451 *---------------------------------------------------------------------------
1454 static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *eth, u16 payLen)
1460 mic_error micError = NONE;
1462 // Check if the packet is a Mic'd packet
1464 if (!ai->micstats.enabled) {
1465 //No Mic set or Mic OFF but we received a MIC'd packet.
1466 if (memcmp ((u8*)eth + 14, micsnap, sizeof(micsnap)) == 0) {
1467 ai->micstats.rxMICPlummed++;
1473 if (ntohs(mic->typelen) == 0x888E)
1476 if (memcmp (mic->u.snap, micsnap, sizeof(micsnap)) != 0) {
1477 // Mic enabled but packet isn't Mic'd
1478 ai->micstats.rxMICPlummed++;
1482 micSEQ = ntohl(mic->seq); //store SEQ as CPU order
1484 //At this point we a have a mic'd packet and mic is enabled
1485 //Now do the mic error checking.
1487 //Receive seq must be odd
1488 if ( (micSEQ & 1) == 0 ) {
1489 ai->micstats.rxWrongSequence++;
1493 for (i = 0; i < NUM_MODULES; i++) {
1494 int mcast = eth->da[0] & 1;
1495 //Determine proper context
1496 context = mcast ? &ai->mod[i].mCtx : &ai->mod[i].uCtx;
1498 //Make sure context is valid
1499 if (!context->valid) {
1501 micError = NOMICPLUMMED;
1507 mic->typelen = htons(payLen + sizeof(MICBuffer) - 2);
1509 emmh32_init(&context->seed);
1510 emmh32_update(&context->seed, eth->da, ETH_ALEN*2);
1511 emmh32_update(&context->seed, (u8 *)&mic->typelen, sizeof(mic->typelen)+sizeof(mic->u.snap));
1512 emmh32_update(&context->seed, (u8 *)&mic->seq,sizeof(mic->seq));
1513 emmh32_update(&context->seed, (u8 *)(eth + 1),payLen);
1515 emmh32_final(&context->seed, digest);
1517 if (memcmp(digest, &mic->mic, 4)) { //Make sure the mics match
1520 micError = INCORRECTMIC;
1524 //Check Sequence number if mics pass
1525 if (RxSeqValid(ai, context, mcast, micSEQ) == SUCCESS) {
1526 ai->micstats.rxSuccess++;
1530 micError = SEQUENCE;
1533 // Update statistics
1535 case NOMICPLUMMED: ai->micstats.rxMICPlummed++; break;
1536 case SEQUENCE: ai->micstats.rxWrongSequence++; break;
1537 case INCORRECTMIC: ai->micstats.rxIncorrectMIC++; break;
1544 /*===========================================================================
1545 * Description: Checks the Rx Seq number to make sure it is valid
1546 * and hasn't already been received
1548 * Inputs: miccntx - mic context to check seq against
1549 * micSeq - the Mic seq number
1551 * Returns: TRUE if valid otherwise FALSE.
1553 * Author: sbraneky (10/15/01)
1554 * Merciless hacks by rwilcher (1/14/02)
1555 *---------------------------------------------------------------------------
1558 static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq)
1562 //Allow for the ap being rebooted - if it is then use the next
1563 //sequence number of the current sequence number - might go backwards
1566 if (test_bit(FLAG_UPDATE_MULTI, &ai->flags)) {
1567 clear_bit (FLAG_UPDATE_MULTI, &ai->flags);
1568 context->window = (micSeq > 33) ? micSeq : 33;
1569 context->rx = 0; // Reset rx
1571 } else if (test_bit(FLAG_UPDATE_UNI, &ai->flags)) {
1572 clear_bit (FLAG_UPDATE_UNI, &ai->flags);
1573 context->window = (micSeq > 33) ? micSeq : 33; // Move window
1574 context->rx = 0; // Reset rx
1577 //Make sequence number relative to START of window
1578 seq = micSeq - (context->window - 33);
1580 //Too old of a SEQ number to check.
1585 //Window is infinite forward
1586 MoveWindow(context,micSeq);
1590 // We are in the window. Now check the context rx bit to see if it was already sent
1591 seq >>= 1; //divide by 2 because we only have odd numbers
1592 index = 1 << seq; //Get an index number
1594 if (!(context->rx & index)) {
1595 //micSEQ falls inside the window.
1596 //Add seqence number to the list of received numbers.
1597 context->rx |= index;
1599 MoveWindow(context,micSeq);
1606 static void MoveWindow(miccntx *context, u32 micSeq)
1610 //Move window if seq greater than the middle of the window
1611 if (micSeq > context->window) {
1612 shift = (micSeq - context->window) >> 1;
1616 context->rx >>= shift;
1620 context->window = micSeq; //Move window
1624 /*==============================================*/
1625 /*========== EMMH ROUTINES ====================*/
1626 /*==============================================*/
1628 /* mic accumulate */
1629 #define MIC_ACCUM(val) \
1630 context->accum += (u64)(val) * be32_to_cpu(context->coeff[coeff_position++]);
1632 /* expand the key to fill the MMH coefficient array */
1633 static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
1634 struct crypto_sync_skcipher *tfm)
1636 /* take the keying material, expand if necessary, truncate at 16-bytes */
1637 /* run through AES counter mode to generate context->coeff[] */
1639 SYNC_SKCIPHER_REQUEST_ON_STACK(req, tfm);
1640 struct scatterlist sg;
1641 u8 iv[AES_BLOCK_SIZE] = {};
1644 crypto_sync_skcipher_setkey(tfm, pkey, 16);
1646 memset(context->coeff, 0, sizeof(context->coeff));
1647 sg_init_one(&sg, context->coeff, sizeof(context->coeff));
1649 skcipher_request_set_sync_tfm(req, tfm);
1650 skcipher_request_set_callback(req, 0, NULL, NULL);
1651 skcipher_request_set_crypt(req, &sg, &sg, sizeof(context->coeff), iv);
1653 ret = crypto_skcipher_encrypt(req);
1657 /* prepare for calculation of a new mic */
1658 static void emmh32_init(emmh32_context *context)
1660 /* prepare for new mic calculation */
1662 context->position = 0;
1665 /* add some bytes to the mic calculation */
1666 static void emmh32_update(emmh32_context *context, u8 *pOctets, int len)
1668 int coeff_position, byte_position;
1670 if (len == 0) return;
1672 coeff_position = context->position >> 2;
1674 /* deal with partial 32-bit word left over from last update */
1675 byte_position = context->position & 3;
1676 if (byte_position) {
1677 /* have a partial word in part to deal with */
1679 if (len == 0) return;
1680 context->part.d8[byte_position++] = *pOctets++;
1681 context->position++;
1683 } while (byte_position < 4);
1684 MIC_ACCUM(ntohl(context->part.d32));
1687 /* deal with full 32-bit words */
1689 MIC_ACCUM(ntohl(*(__be32 *)pOctets));
1690 context->position += 4;
1695 /* deal with partial 32-bit word that will be left over from this update */
1698 context->part.d8[byte_position++] = *pOctets++;
1699 context->position++;
1704 /* mask used to zero empty bytes for final partial word */
1705 static u32 mask32[4] = { 0x00000000L, 0xFF000000L, 0xFFFF0000L, 0xFFFFFF00L };
1707 /* calculate the mic */
1708 static void emmh32_final(emmh32_context *context, u8 digest[4])
1710 int coeff_position, byte_position;
1716 coeff_position = context->position >> 2;
1718 /* deal with partial 32-bit word left over from last update */
1719 byte_position = context->position & 3;
1720 if (byte_position) {
1721 /* have a partial word in part to deal with */
1722 val = ntohl(context->part.d32);
1723 MIC_ACCUM(val & mask32[byte_position]); /* zero empty bytes */
1726 /* reduce the accumulated u64 to a 32-bit MIC */
1727 sum = context->accum;
1728 stmp = (sum & 0xffffffffLL) - ((sum >> 32) * 15);
1729 utmp = (stmp & 0xffffffffLL) - ((stmp >> 32) * 15);
1730 sum = utmp & 0xffffffffLL;
1731 if (utmp > 0x10000000fLL)
1735 digest[0] = (val>>24) & 0xFF;
1736 digest[1] = (val>>16) & 0xFF;
1737 digest[2] = (val>>8) & 0xFF;
1738 digest[3] = val & 0xFF;
1741 static int readBSSListRid(struct airo_info *ai, int first,
1748 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
1749 memset(&cmd, 0, sizeof(cmd));
1750 cmd.cmd=CMD_LISTBSS;
1751 if (down_interruptible(&ai->sem))
1752 return -ERESTARTSYS;
1753 ai->list_bss_task = current;
1754 issuecommand(ai, &cmd, &rsp);
1756 /* Let the command take effect */
1757 schedule_timeout_uninterruptible(3 * HZ);
1758 ai->list_bss_task = NULL;
1760 return PC4500_readrid(ai, first ? ai->bssListFirst : ai->bssListNext,
1761 list, ai->bssListRidLen, 1);
1764 static int readWepKeyRid(struct airo_info *ai, WepKeyRid *wkr, int temp, int lock)
1766 return PC4500_readrid(ai, temp ? RID_WEP_TEMP : RID_WEP_PERM,
1767 wkr, sizeof(*wkr), lock);
1770 static int writeWepKeyRid(struct airo_info *ai, WepKeyRid *wkr, int perm, int lock)
1773 rc = PC4500_writerid(ai, RID_WEP_TEMP, wkr, sizeof(*wkr), lock);
1775 airo_print_err(ai->dev->name, "WEP_TEMP set %x", rc);
1777 rc = PC4500_writerid(ai, RID_WEP_PERM, wkr, sizeof(*wkr), lock);
1779 airo_print_err(ai->dev->name, "WEP_PERM set %x", rc);
1784 static int readSsidRid(struct airo_info*ai, SsidRid *ssidr)
1786 return PC4500_readrid(ai, RID_SSID, ssidr, sizeof(*ssidr), 1);
1789 static int writeSsidRid(struct airo_info*ai, SsidRid *pssidr, int lock)
1791 return PC4500_writerid(ai, RID_SSID, pssidr, sizeof(*pssidr), lock);
1794 static int readConfigRid(struct airo_info *ai, int lock)
1802 rc = PC4500_readrid(ai, RID_ACTUALCONFIG, &cfg, sizeof(cfg), lock);
1810 static inline void checkThrottle(struct airo_info *ai)
1813 /* Old hardware had a limit on encryption speed */
1814 if (ai->config.authType != AUTH_OPEN && maxencrypt) {
1815 for(i=0; i<8; i++) {
1816 if (ai->config.rates[i] > maxencrypt) {
1817 ai->config.rates[i] = 0;
1823 static int writeConfigRid(struct airo_info *ai, int lock)
1827 if (!test_bit (FLAG_COMMIT, &ai->flags))
1830 clear_bit (FLAG_COMMIT, &ai->flags);
1831 clear_bit (FLAG_RESET, &ai->flags);
1835 if ((cfgr.opmode & MODE_CFG_MASK) == MODE_STA_IBSS)
1836 set_bit(FLAG_ADHOC, &ai->flags);
1838 clear_bit(FLAG_ADHOC, &ai->flags);
1840 return PC4500_writerid( ai, RID_CONFIG, &cfgr, sizeof(cfgr), lock);
1843 static int readStatusRid(struct airo_info *ai, StatusRid *statr, int lock)
1845 return PC4500_readrid(ai, RID_STATUS, statr, sizeof(*statr), lock);
1848 static int writeAPListRid(struct airo_info *ai, APListRid *aplr, int lock)
1850 return PC4500_writerid(ai, RID_APLIST, aplr, sizeof(*aplr), lock);
1853 static int readCapabilityRid(struct airo_info *ai, CapabilityRid *capr, int lock)
1855 return PC4500_readrid(ai, RID_CAPABILITIES, capr, sizeof(*capr), lock);
1858 static int readStatsRid(struct airo_info*ai, StatsRid *sr, int rid, int lock)
1860 return PC4500_readrid(ai, rid, sr, sizeof(*sr), lock);
1863 static void try_auto_wep(struct airo_info *ai)
1865 if (auto_wep && !test_bit(FLAG_RADIO_DOWN, &ai->flags)) {
1866 ai->expires = RUN_AT(3*HZ);
1867 wake_up_interruptible(&ai->thr_wait);
1871 static int airo_open(struct net_device *dev) {
1872 struct airo_info *ai = dev->ml_priv;
1875 if (test_bit(FLAG_FLASHING, &ai->flags))
1878 /* Make sure the card is configured.
1879 * Wireless Extensions may postpone config changes until the card
1880 * is open (to pipeline changes and speed-up card setup). If
1881 * those changes are not yet committed, do it now - Jean II */
1882 if (test_bit(FLAG_COMMIT, &ai->flags)) {
1884 writeConfigRid(ai, 1);
1887 if (ai->wifidev != dev) {
1888 clear_bit(JOB_DIE, &ai->jobs);
1889 ai->airo_thread_task = kthread_run(airo_thread, dev, "%s",
1891 if (IS_ERR(ai->airo_thread_task))
1892 return (int)PTR_ERR(ai->airo_thread_task);
1894 rc = request_irq(dev->irq, airo_interrupt, IRQF_SHARED,
1897 airo_print_err(dev->name,
1898 "register interrupt %d failed, rc %d",
1900 set_bit(JOB_DIE, &ai->jobs);
1901 kthread_stop(ai->airo_thread_task);
1905 /* Power on the MAC controller (which may have been disabled) */
1906 clear_bit(FLAG_RADIO_DOWN, &ai->flags);
1907 enable_interrupts(ai);
1913 netif_start_queue(dev);
1917 static netdev_tx_t mpi_start_xmit(struct sk_buff *skb,
1918 struct net_device *dev)
1920 int npacks, pending;
1921 unsigned long flags;
1922 struct airo_info *ai = dev->ml_priv;
1925 airo_print_err(dev->name, "%s: skb == NULL!",__func__);
1926 return NETDEV_TX_OK;
1928 npacks = skb_queue_len (&ai->txq);
1930 if (npacks >= MAXTXQ - 1) {
1931 netif_stop_queue (dev);
1932 if (npacks > MAXTXQ) {
1933 dev->stats.tx_fifo_errors++;
1934 return NETDEV_TX_BUSY;
1936 skb_queue_tail (&ai->txq, skb);
1937 return NETDEV_TX_OK;
1940 spin_lock_irqsave(&ai->aux_lock, flags);
1941 skb_queue_tail (&ai->txq, skb);
1942 pending = test_bit(FLAG_PENDING_XMIT, &ai->flags);
1943 spin_unlock_irqrestore(&ai->aux_lock,flags);
1944 netif_wake_queue (dev);
1947 set_bit(FLAG_PENDING_XMIT, &ai->flags);
1948 mpi_send_packet (dev);
1950 return NETDEV_TX_OK;
1956 * Attempt to transmit a packet. Can be called from interrupt
1957 * or transmit . return number of packets we tried to send
1960 static int mpi_send_packet (struct net_device *dev)
1962 struct sk_buff *skb;
1963 unsigned char *buffer;
1966 struct airo_info *ai = dev->ml_priv;
1969 /* get a packet to send */
1971 if ((skb = skb_dequeue(&ai->txq)) == NULL) {
1972 airo_print_err(dev->name,
1973 "%s: Dequeue'd zero in send_packet()",
1978 /* check min length*/
1979 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1982 ai->txfids[0].tx_desc.offset = 0;
1983 ai->txfids[0].tx_desc.valid = 1;
1984 ai->txfids[0].tx_desc.eoc = 1;
1985 ai->txfids[0].tx_desc.len =len+sizeof(WifiHdr);
1988 * Magic, the cards firmware needs a length count (2 bytes) in the host buffer
1989 * right after TXFID_HDR.The TXFID_HDR contains the status short so payloadlen
1990 * is immediately after it. ------------------------------------------------
1991 * |TXFIDHDR+STATUS|PAYLOADLEN|802.3HDR|PACKETDATA|
1992 * ------------------------------------------------
1995 memcpy(ai->txfids[0].virtual_host_addr,
1996 (char *)&wifictlhdr8023, sizeof(wifictlhdr8023));
1998 payloadLen = (__le16 *)(ai->txfids[0].virtual_host_addr +
1999 sizeof(wifictlhdr8023));
2000 sendbuf = ai->txfids[0].virtual_host_addr +
2001 sizeof(wifictlhdr8023) + 2 ;
2004 * Firmware automatically puts 802 header on so
2005 * we don't need to account for it in the length
2007 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
2008 (ntohs(((__be16 *)buffer)[6]) != 0x888E)) {
2011 if (encapsulate(ai, (etherHead *)buffer, &pMic, len - sizeof(etherHead)) != SUCCESS)
2014 *payloadLen = cpu_to_le16(len-sizeof(etherHead)+sizeof(pMic));
2015 ai->txfids[0].tx_desc.len += sizeof(pMic);
2016 /* copy data into airo dma buffer */
2017 memcpy (sendbuf, buffer, sizeof(etherHead));
2018 buffer += sizeof(etherHead);
2019 sendbuf += sizeof(etherHead);
2020 memcpy (sendbuf, &pMic, sizeof(pMic));
2021 sendbuf += sizeof(pMic);
2022 memcpy (sendbuf, buffer, len - sizeof(etherHead));
2024 *payloadLen = cpu_to_le16(len - sizeof(etherHead));
2026 netif_trans_update(dev);
2028 /* copy data into airo dma buffer */
2029 memcpy(sendbuf, buffer, len);
2032 memcpy_toio(ai->txfids[0].card_ram_off,
2033 &ai->txfids[0].tx_desc, sizeof(TxFid));
2035 OUT4500(ai, EVACK, 8);
2037 dev_kfree_skb_any(skb);
2041 static void get_tx_error(struct airo_info *ai, s32 fid)
2046 status = ((WifiCtlHdr *)ai->txfids[0].virtual_host_addr)->ctlhdr.status;
2048 if (bap_setup(ai, ai->fids[fid] & 0xffff, 4, BAP0) != SUCCESS)
2050 bap_read(ai, &status, 2, BAP0);
2052 if (le16_to_cpu(status) & 2) /* Too many retries */
2053 ai->dev->stats.tx_aborted_errors++;
2054 if (le16_to_cpu(status) & 4) /* Transmit lifetime exceeded */
2055 ai->dev->stats.tx_heartbeat_errors++;
2056 if (le16_to_cpu(status) & 8) /* Aid fail */
2058 if (le16_to_cpu(status) & 0x10) /* MAC disabled */
2059 ai->dev->stats.tx_carrier_errors++;
2060 if (le16_to_cpu(status) & 0x20) /* Association lost */
2062 /* We produce a TXDROP event only for retry or lifetime
2063 * exceeded, because that's the only status that really mean
2064 * that this particular node went away.
2065 * Other errors means that *we* screwed up. - Jean II */
2066 if ((le16_to_cpu(status) & 2) ||
2067 (le16_to_cpu(status) & 4)) {
2068 union iwreq_data wrqu;
2071 /* Faster to skip over useless data than to do
2072 * another bap_setup(). We are at offset 0x6 and
2073 * need to go to 0x18 and read 6 bytes - Jean II */
2074 bap_read(ai, (__le16 *) junk, 0x18, BAP0);
2076 /* Copy 802.11 dest address.
2077 * We use the 802.11 header because the frame may
2078 * not be 802.3 or may be mangled...
2079 * In Ad-Hoc mode, it will be the node address.
2080 * In managed mode, it will be most likely the AP addr
2081 * User space will figure out how to convert it to
2082 * whatever it needs (IP address or else).
2084 memcpy(wrqu.addr.sa_data, junk + 0x12, ETH_ALEN);
2085 wrqu.addr.sa_family = ARPHRD_ETHER;
2087 /* Send event to user space */
2088 wireless_send_event(ai->dev, IWEVTXDROP, &wrqu, NULL);
2092 static void airo_end_xmit(struct net_device *dev) {
2095 struct airo_info *priv = dev->ml_priv;
2096 struct sk_buff *skb = priv->xmit.skb;
2097 int fid = priv->xmit.fid;
2098 u32 *fids = priv->fids;
2100 clear_bit(JOB_XMIT, &priv->jobs);
2101 clear_bit(FLAG_PENDING_XMIT, &priv->flags);
2102 status = transmit_802_3_packet (priv, fids[fid], skb->data);
2106 if ( status == SUCCESS ) {
2107 netif_trans_update(dev);
2108 for (; i < MAX_FIDS / 2 && (priv->fids[i] & 0xffff0000); i++);
2110 priv->fids[fid] &= 0xffff;
2111 dev->stats.tx_window_errors++;
2113 if (i < MAX_FIDS / 2)
2114 netif_wake_queue(dev);
2118 static netdev_tx_t airo_start_xmit(struct sk_buff *skb,
2119 struct net_device *dev)
2123 struct airo_info *priv = dev->ml_priv;
2124 u32 *fids = priv->fids;
2126 if ( skb == NULL ) {
2127 airo_print_err(dev->name, "%s: skb == NULL!", __func__);
2128 return NETDEV_TX_OK;
2131 /* Find a vacant FID */
2132 for( i = 0; i < MAX_FIDS / 2 && (fids[i] & 0xffff0000); i++ );
2133 for( j = i + 1; j < MAX_FIDS / 2 && (fids[j] & 0xffff0000); j++ );
2135 if ( j >= MAX_FIDS / 2 ) {
2136 netif_stop_queue(dev);
2138 if (i == MAX_FIDS / 2) {
2139 dev->stats.tx_fifo_errors++;
2140 return NETDEV_TX_BUSY;
2143 /* check min length*/
2144 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
2145 /* Mark fid as used & save length for later */
2146 fids[i] |= (len << 16);
2147 priv->xmit.skb = skb;
2149 if (down_trylock(&priv->sem) != 0) {
2150 set_bit(FLAG_PENDING_XMIT, &priv->flags);
2151 netif_stop_queue(dev);
2152 set_bit(JOB_XMIT, &priv->jobs);
2153 wake_up_interruptible(&priv->thr_wait);
2156 return NETDEV_TX_OK;
2159 static void airo_end_xmit11(struct net_device *dev) {
2162 struct airo_info *priv = dev->ml_priv;
2163 struct sk_buff *skb = priv->xmit11.skb;
2164 int fid = priv->xmit11.fid;
2165 u32 *fids = priv->fids;
2167 clear_bit(JOB_XMIT11, &priv->jobs);
2168 clear_bit(FLAG_PENDING_XMIT11, &priv->flags);
2169 status = transmit_802_11_packet (priv, fids[fid], skb->data);
2173 if ( status == SUCCESS ) {
2174 netif_trans_update(dev);
2175 for (; i < MAX_FIDS && (priv->fids[i] & 0xffff0000); i++);
2177 priv->fids[fid] &= 0xffff;
2178 dev->stats.tx_window_errors++;
2181 netif_wake_queue(dev);
2185 static netdev_tx_t airo_start_xmit11(struct sk_buff *skb,
2186 struct net_device *dev)
2190 struct airo_info *priv = dev->ml_priv;
2191 u32 *fids = priv->fids;
2193 if (test_bit(FLAG_MPI, &priv->flags)) {
2194 /* Not implemented yet for MPI350 */
2195 netif_stop_queue(dev);
2196 dev_kfree_skb_any(skb);
2197 return NETDEV_TX_OK;
2200 if ( skb == NULL ) {
2201 airo_print_err(dev->name, "%s: skb == NULL!", __func__);
2202 return NETDEV_TX_OK;
2205 /* Find a vacant FID */
2206 for( i = MAX_FIDS / 2; i < MAX_FIDS && (fids[i] & 0xffff0000); i++ );
2207 for( j = i + 1; j < MAX_FIDS && (fids[j] & 0xffff0000); j++ );
2209 if ( j >= MAX_FIDS ) {
2210 netif_stop_queue(dev);
2212 if (i == MAX_FIDS) {
2213 dev->stats.tx_fifo_errors++;
2214 return NETDEV_TX_BUSY;
2217 /* check min length*/
2218 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
2219 /* Mark fid as used & save length for later */
2220 fids[i] |= (len << 16);
2221 priv->xmit11.skb = skb;
2222 priv->xmit11.fid = i;
2223 if (down_trylock(&priv->sem) != 0) {
2224 set_bit(FLAG_PENDING_XMIT11, &priv->flags);
2225 netif_stop_queue(dev);
2226 set_bit(JOB_XMIT11, &priv->jobs);
2227 wake_up_interruptible(&priv->thr_wait);
2229 airo_end_xmit11(dev);
2230 return NETDEV_TX_OK;
2233 static void airo_read_stats(struct net_device *dev)
2235 struct airo_info *ai = dev->ml_priv;
2237 __le32 *vals = stats_rid.vals;
2239 clear_bit(JOB_STATS, &ai->jobs);
2240 if (ai->power.event) {
2244 readStatsRid(ai, &stats_rid, RID_STATS, 0);
2247 dev->stats.rx_packets = le32_to_cpu(vals[43]) + le32_to_cpu(vals[44]) +
2248 le32_to_cpu(vals[45]);
2249 dev->stats.tx_packets = le32_to_cpu(vals[39]) + le32_to_cpu(vals[40]) +
2250 le32_to_cpu(vals[41]);
2251 dev->stats.rx_bytes = le32_to_cpu(vals[92]);
2252 dev->stats.tx_bytes = le32_to_cpu(vals[91]);
2253 dev->stats.rx_errors = le32_to_cpu(vals[0]) + le32_to_cpu(vals[2]) +
2254 le32_to_cpu(vals[3]) + le32_to_cpu(vals[4]);
2255 dev->stats.tx_errors = le32_to_cpu(vals[42]) +
2256 dev->stats.tx_fifo_errors;
2257 dev->stats.multicast = le32_to_cpu(vals[43]);
2258 dev->stats.collisions = le32_to_cpu(vals[89]);
2260 /* detailed rx_errors: */
2261 dev->stats.rx_length_errors = le32_to_cpu(vals[3]);
2262 dev->stats.rx_crc_errors = le32_to_cpu(vals[4]);
2263 dev->stats.rx_frame_errors = le32_to_cpu(vals[2]);
2264 dev->stats.rx_fifo_errors = le32_to_cpu(vals[0]);
2267 static struct net_device_stats *airo_get_stats(struct net_device *dev)
2269 struct airo_info *local = dev->ml_priv;
2271 if (!test_bit(JOB_STATS, &local->jobs)) {
2272 /* Get stats out of the card if available */
2273 if (down_trylock(&local->sem) != 0) {
2274 set_bit(JOB_STATS, &local->jobs);
2275 wake_up_interruptible(&local->thr_wait);
2277 airo_read_stats(dev);
2283 static void airo_set_promisc(struct airo_info *ai) {
2287 memset(&cmd, 0, sizeof(cmd));
2288 cmd.cmd=CMD_SETMODE;
2289 clear_bit(JOB_PROMISC, &ai->jobs);
2290 cmd.parm0=(ai->flags&IFF_PROMISC) ? PROMISC : NOPROMISC;
2291 issuecommand(ai, &cmd, &rsp);
2295 static void airo_set_multicast_list(struct net_device *dev) {
2296 struct airo_info *ai = dev->ml_priv;
2298 if ((dev->flags ^ ai->flags) & IFF_PROMISC) {
2299 change_bit(FLAG_PROMISC, &ai->flags);
2300 if (down_trylock(&ai->sem) != 0) {
2301 set_bit(JOB_PROMISC, &ai->jobs);
2302 wake_up_interruptible(&ai->thr_wait);
2304 airo_set_promisc(ai);
2307 if ((dev->flags&IFF_ALLMULTI) || !netdev_mc_empty(dev)) {
2308 /* Turn on multicast. (Should be already setup...) */
2312 static int airo_set_mac_address(struct net_device *dev, void *p)
2314 struct airo_info *ai = dev->ml_priv;
2315 struct sockaddr *addr = p;
2317 readConfigRid(ai, 1);
2318 memcpy (ai->config.macAddr, addr->sa_data, dev->addr_len);
2319 set_bit (FLAG_COMMIT, &ai->flags);
2321 writeConfigRid (ai, 1);
2323 memcpy (ai->dev->dev_addr, addr->sa_data, dev->addr_len);
2325 memcpy (ai->wifidev->dev_addr, addr->sa_data, dev->addr_len);
2329 static LIST_HEAD(airo_devices);
2331 static void add_airo_dev(struct airo_info *ai)
2333 /* Upper layers already keep track of PCI devices,
2334 * so we only need to remember our non-PCI cards. */
2336 list_add_tail(&ai->dev_list, &airo_devices);
2339 static void del_airo_dev(struct airo_info *ai)
2342 list_del(&ai->dev_list);
2345 static int airo_close(struct net_device *dev) {
2346 struct airo_info *ai = dev->ml_priv;
2348 netif_stop_queue(dev);
2350 if (ai->wifidev != dev) {
2351 #ifdef POWER_ON_DOWN
2352 /* Shut power to the card. The idea is that the user can save
2353 * power when he doesn't need the card with "ifconfig down".
2354 * That's the method that is most friendly towards the network
2355 * stack (i.e. the network stack won't try to broadcast
2356 * anything on the interface and routes are gone. Jean II */
2357 set_bit(FLAG_RADIO_DOWN, &ai->flags);
2360 disable_interrupts( ai );
2362 free_irq(dev->irq, dev);
2364 set_bit(JOB_DIE, &ai->jobs);
2365 kthread_stop(ai->airo_thread_task);
2370 void stop_airo_card( struct net_device *dev, int freeres )
2372 struct airo_info *ai = dev->ml_priv;
2374 set_bit(FLAG_RADIO_DOWN, &ai->flags);
2376 disable_interrupts(ai);
2377 takedown_proc_entry( dev, ai );
2378 if (test_bit(FLAG_REGISTERED, &ai->flags)) {
2379 unregister_netdev( dev );
2381 unregister_netdev(ai->wifidev);
2382 free_netdev(ai->wifidev);
2385 clear_bit(FLAG_REGISTERED, &ai->flags);
2388 * Clean out tx queue
2390 if (test_bit(FLAG_MPI, &ai->flags) && !skb_queue_empty(&ai->txq)) {
2391 struct sk_buff *skb = NULL;
2392 for (;(skb = skb_dequeue(&ai->txq));)
2396 airo_networks_free (ai);
2402 /* PCMCIA frees this stuff, so only for PCI and ISA */
2403 release_region( dev->base_addr, 64 );
2404 if (test_bit(FLAG_MPI, &ai->flags)) {
2406 mpi_unmap_card(ai->pci);
2408 iounmap(ai->pcimem);
2410 iounmap(ai->pciaux);
2411 pci_free_consistent(ai->pci, PCI_SHARED_LEN,
2412 ai->shared, ai->shared_dma);
2415 crypto_free_sync_skcipher(ai->tfm);
2420 EXPORT_SYMBOL(stop_airo_card);
2422 static int wll_header_parse(const struct sk_buff *skb, unsigned char *haddr)
2424 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN);
2428 static void mpi_unmap_card(struct pci_dev *pci)
2430 unsigned long mem_start = pci_resource_start(pci, 1);
2431 unsigned long mem_len = pci_resource_len(pci, 1);
2432 unsigned long aux_start = pci_resource_start(pci, 2);
2433 unsigned long aux_len = AUXMEMSIZE;
2435 release_mem_region(aux_start, aux_len);
2436 release_mem_region(mem_start, mem_len);
2439 /*************************************************************
2440 * This routine assumes that descriptors have been setup .
2441 * Run at insmod time or after reset when the decriptors
2442 * have been initialized . Returns 0 if all is well nz
2443 * otherwise . Does not allocate memory but sets up card
2444 * using previously allocated descriptors.
2446 static int mpi_init_descriptors (struct airo_info *ai)
2453 /* Alloc card RX descriptors */
2454 netif_stop_queue(ai->dev);
2456 memset(&rsp,0,sizeof(rsp));
2457 memset(&cmd,0,sizeof(cmd));
2459 cmd.cmd = CMD_ALLOCATEAUX;
2461 cmd.parm1 = (ai->rxfids[0].card_ram_off - ai->pciaux);
2462 cmd.parm2 = MPI_MAX_FIDS;
2463 rc=issuecommand(ai, &cmd, &rsp);
2464 if (rc != SUCCESS) {
2465 airo_print_err(ai->dev->name, "Couldn't allocate RX FID");
2469 for (i=0; i<MPI_MAX_FIDS; i++) {
2470 memcpy_toio(ai->rxfids[i].card_ram_off,
2471 &ai->rxfids[i].rx_desc, sizeof(RxFid));
2474 /* Alloc card TX descriptors */
2476 memset(&rsp,0,sizeof(rsp));
2477 memset(&cmd,0,sizeof(cmd));
2479 cmd.cmd = CMD_ALLOCATEAUX;
2481 cmd.parm1 = (ai->txfids[0].card_ram_off - ai->pciaux);
2482 cmd.parm2 = MPI_MAX_FIDS;
2484 for (i=0; i<MPI_MAX_FIDS; i++) {
2485 ai->txfids[i].tx_desc.valid = 1;
2486 memcpy_toio(ai->txfids[i].card_ram_off,
2487 &ai->txfids[i].tx_desc, sizeof(TxFid));
2489 ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */
2491 rc=issuecommand(ai, &cmd, &rsp);
2492 if (rc != SUCCESS) {
2493 airo_print_err(ai->dev->name, "Couldn't allocate TX FID");
2497 /* Alloc card Rid descriptor */
2498 memset(&rsp,0,sizeof(rsp));
2499 memset(&cmd,0,sizeof(cmd));
2501 cmd.cmd = CMD_ALLOCATEAUX;
2503 cmd.parm1 = (ai->config_desc.card_ram_off - ai->pciaux);
2504 cmd.parm2 = 1; /* Magic number... */
2505 rc=issuecommand(ai, &cmd, &rsp);
2506 if (rc != SUCCESS) {
2507 airo_print_err(ai->dev->name, "Couldn't allocate RID");
2511 memcpy_toio(ai->config_desc.card_ram_off,
2512 &ai->config_desc.rid_desc, sizeof(Rid));
2518 * We are setting up three things here:
2519 * 1) Map AUX memory for descriptors: Rid, TxFid, or RxFid.
2520 * 2) Map PCI memory for issuing commands.
2521 * 3) Allocate memory (shared) to send and receive ethernet frames.
2523 static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci)
2525 unsigned long mem_start, mem_len, aux_start, aux_len;
2528 dma_addr_t busaddroff;
2529 unsigned char *vpackoff;
2530 unsigned char __iomem *pciaddroff;
2532 mem_start = pci_resource_start(pci, 1);
2533 mem_len = pci_resource_len(pci, 1);
2534 aux_start = pci_resource_start(pci, 2);
2535 aux_len = AUXMEMSIZE;
2537 if (!request_mem_region(mem_start, mem_len, DRV_NAME)) {
2538 airo_print_err("", "Couldn't get region %x[%x]",
2539 (int)mem_start, (int)mem_len);
2542 if (!request_mem_region(aux_start, aux_len, DRV_NAME)) {
2543 airo_print_err("", "Couldn't get region %x[%x]",
2544 (int)aux_start, (int)aux_len);
2548 ai->pcimem = ioremap(mem_start, mem_len);
2550 airo_print_err("", "Couldn't map region %x[%x]",
2551 (int)mem_start, (int)mem_len);
2554 ai->pciaux = ioremap(aux_start, aux_len);
2556 airo_print_err("", "Couldn't map region %x[%x]",
2557 (int)aux_start, (int)aux_len);
2561 /* Reserve PKTSIZE for each fid and 2K for the Rids */
2562 ai->shared = pci_alloc_consistent(pci, PCI_SHARED_LEN, &ai->shared_dma);
2564 airo_print_err("", "Couldn't alloc_consistent %d",
2570 * Setup descriptor RX, TX, CONFIG
2572 busaddroff = ai->shared_dma;
2573 pciaddroff = ai->pciaux + AUX_OFFSET;
2574 vpackoff = ai->shared;
2576 /* RX descriptor setup */
2577 for(i = 0; i < MPI_MAX_FIDS; i++) {
2578 ai->rxfids[i].pending = 0;
2579 ai->rxfids[i].card_ram_off = pciaddroff;
2580 ai->rxfids[i].virtual_host_addr = vpackoff;
2581 ai->rxfids[i].rx_desc.host_addr = busaddroff;
2582 ai->rxfids[i].rx_desc.valid = 1;
2583 ai->rxfids[i].rx_desc.len = PKTSIZE;
2584 ai->rxfids[i].rx_desc.rdy = 0;
2586 pciaddroff += sizeof(RxFid);
2587 busaddroff += PKTSIZE;
2588 vpackoff += PKTSIZE;
2591 /* TX descriptor setup */
2592 for(i = 0; i < MPI_MAX_FIDS; i++) {
2593 ai->txfids[i].card_ram_off = pciaddroff;
2594 ai->txfids[i].virtual_host_addr = vpackoff;
2595 ai->txfids[i].tx_desc.valid = 1;
2596 ai->txfids[i].tx_desc.host_addr = busaddroff;
2597 memcpy(ai->txfids[i].virtual_host_addr,
2598 &wifictlhdr8023, sizeof(wifictlhdr8023));
2600 pciaddroff += sizeof(TxFid);
2601 busaddroff += PKTSIZE;
2602 vpackoff += PKTSIZE;
2604 ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */
2606 /* Rid descriptor setup */
2607 ai->config_desc.card_ram_off = pciaddroff;
2608 ai->config_desc.virtual_host_addr = vpackoff;
2609 ai->config_desc.rid_desc.host_addr = busaddroff;
2610 ai->ridbus = busaddroff;
2611 ai->config_desc.rid_desc.rid = 0;
2612 ai->config_desc.rid_desc.len = RIDSIZE;
2613 ai->config_desc.rid_desc.valid = 1;
2614 pciaddroff += sizeof(Rid);
2615 busaddroff += RIDSIZE;
2616 vpackoff += RIDSIZE;
2618 /* Tell card about descriptors */
2619 if (mpi_init_descriptors (ai) != SUCCESS)
2624 pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
2626 iounmap(ai->pciaux);
2628 iounmap(ai->pcimem);
2630 release_mem_region(aux_start, aux_len);
2632 release_mem_region(mem_start, mem_len);
2637 static const struct header_ops airo_header_ops = {
2638 .parse = wll_header_parse,
2641 static const struct net_device_ops airo11_netdev_ops = {
2642 .ndo_open = airo_open,
2643 .ndo_stop = airo_close,
2644 .ndo_start_xmit = airo_start_xmit11,
2645 .ndo_get_stats = airo_get_stats,
2646 .ndo_set_mac_address = airo_set_mac_address,
2647 .ndo_do_ioctl = airo_ioctl,
2650 static void wifi_setup(struct net_device *dev)
2652 dev->netdev_ops = &airo11_netdev_ops;
2653 dev->header_ops = &airo_header_ops;
2654 dev->wireless_handlers = &airo_handler_def;
2656 dev->type = ARPHRD_IEEE80211;
2657 dev->hard_header_len = ETH_HLEN;
2658 dev->mtu = AIRO_DEF_MTU;
2660 dev->max_mtu = MIC_MSGLEN_MAX;
2661 dev->addr_len = ETH_ALEN;
2662 dev->tx_queue_len = 100;
2664 eth_broadcast_addr(dev->broadcast);
2666 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2669 static struct net_device *init_wifidev(struct airo_info *ai,
2670 struct net_device *ethdev)
2673 struct net_device *dev = alloc_netdev(0, "wifi%d", NET_NAME_UNKNOWN,
2677 dev->ml_priv = ethdev->ml_priv;
2678 dev->irq = ethdev->irq;
2679 dev->base_addr = ethdev->base_addr;
2680 dev->wireless_data = ethdev->wireless_data;
2681 SET_NETDEV_DEV(dev, ethdev->dev.parent);
2682 eth_hw_addr_inherit(dev, ethdev);
2683 err = register_netdev(dev);
2691 static int reset_card( struct net_device *dev , int lock) {
2692 struct airo_info *ai = dev->ml_priv;
2694 if (lock && down_interruptible(&ai->sem))
2697 OUT4500(ai,COMMAND,CMD_SOFTRESET);
2706 #define AIRO_MAX_NETWORK_COUNT 64
2707 static int airo_networks_allocate(struct airo_info *ai)
2712 ai->networks = kcalloc(AIRO_MAX_NETWORK_COUNT, sizeof(BSSListElement),
2714 if (!ai->networks) {
2715 airo_print_warn("", "Out of memory allocating beacons");
2722 static void airo_networks_free(struct airo_info *ai)
2724 kfree(ai->networks);
2725 ai->networks = NULL;
2728 static void airo_networks_initialize(struct airo_info *ai)
2732 INIT_LIST_HEAD(&ai->network_free_list);
2733 INIT_LIST_HEAD(&ai->network_list);
2734 for (i = 0; i < AIRO_MAX_NETWORK_COUNT; i++)
2735 list_add_tail(&ai->networks[i].list,
2736 &ai->network_free_list);
2739 static const struct net_device_ops airo_netdev_ops = {
2740 .ndo_open = airo_open,
2741 .ndo_stop = airo_close,
2742 .ndo_start_xmit = airo_start_xmit,
2743 .ndo_get_stats = airo_get_stats,
2744 .ndo_set_rx_mode = airo_set_multicast_list,
2745 .ndo_set_mac_address = airo_set_mac_address,
2746 .ndo_do_ioctl = airo_ioctl,
2747 .ndo_validate_addr = eth_validate_addr,
2750 static const struct net_device_ops mpi_netdev_ops = {
2751 .ndo_open = airo_open,
2752 .ndo_stop = airo_close,
2753 .ndo_start_xmit = mpi_start_xmit,
2754 .ndo_get_stats = airo_get_stats,
2755 .ndo_set_rx_mode = airo_set_multicast_list,
2756 .ndo_set_mac_address = airo_set_mac_address,
2757 .ndo_do_ioctl = airo_ioctl,
2758 .ndo_validate_addr = eth_validate_addr,
2762 static struct net_device *_init_airo_card( unsigned short irq, int port,
2763 int is_pcmcia, struct pci_dev *pci,
2764 struct device *dmdev )
2766 struct net_device *dev;
2767 struct airo_info *ai;
2769 CapabilityRid cap_rid;
2771 /* Create the network device object. */
2772 dev = alloc_netdev(sizeof(*ai), "", NET_NAME_UNKNOWN, ether_setup);
2774 airo_print_err("", "Couldn't alloc_etherdev");
2778 ai = dev->ml_priv = netdev_priv(dev);
2780 ai->flags = 1 << FLAG_RADIO_DOWN;
2783 if (pci && (pci->device == 0x5000 || pci->device == 0xa504)) {
2784 airo_print_dbg("", "Found an MPI350 card");
2785 set_bit(FLAG_MPI, &ai->flags);
2787 spin_lock_init(&ai->aux_lock);
2788 sema_init(&ai->sem, 1);
2791 init_waitqueue_head (&ai->thr_wait);
2794 ai->APList.len = cpu_to_le16(sizeof(struct APListRid));
2796 if (airo_networks_allocate (ai))
2798 airo_networks_initialize (ai);
2800 skb_queue_head_init (&ai->txq);
2802 /* The Airo-specific entries in the device structure. */
2803 if (test_bit(FLAG_MPI,&ai->flags))
2804 dev->netdev_ops = &mpi_netdev_ops;
2806 dev->netdev_ops = &airo_netdev_ops;
2807 dev->wireless_handlers = &airo_handler_def;
2808 ai->wireless_data.spy_data = &ai->spy_data;
2809 dev->wireless_data = &ai->wireless_data;
2811 dev->base_addr = port;
2812 dev->priv_flags &= ~IFF_TX_SKB_SHARING;
2813 dev->max_mtu = MIC_MSGLEN_MAX;
2815 SET_NETDEV_DEV(dev, dmdev);
2817 reset_card (dev, 1);
2821 if (!request_region(dev->base_addr, 64, DRV_NAME)) {
2823 airo_print_err(dev->name, "Couldn't request region");
2828 if (test_bit(FLAG_MPI,&ai->flags)) {
2829 if (mpi_map_card(ai, pci)) {
2830 airo_print_err("", "Could not map memory");
2836 if (setup_card(ai, dev->dev_addr, 1) != SUCCESS) {
2837 airo_print_err(dev->name, "MAC could not be enabled" );
2841 } else if (!test_bit(FLAG_MPI,&ai->flags)) {
2842 ai->bap_read = fast_bap_read;
2843 set_bit(FLAG_FLASHING, &ai->flags);
2846 strcpy(dev->name, "eth%d");
2847 rc = register_netdev(dev);
2849 airo_print_err(dev->name, "Couldn't register_netdev");
2852 ai->wifidev = init_wifidev(ai, dev);
2856 rc = readCapabilityRid(ai, &cap_rid, 1);
2857 if (rc != SUCCESS) {
2861 /* WEP capability discovery */
2862 ai->wep_capable = (cap_rid.softCap & cpu_to_le16(0x02)) ? 1 : 0;
2863 ai->max_wep_idx = (cap_rid.softCap & cpu_to_le16(0x80)) ? 3 : 0;
2865 airo_print_info(dev->name, "Firmware version %x.%x.%02d",
2866 ((le16_to_cpu(cap_rid.softVer) >> 8) & 0xF),
2867 (le16_to_cpu(cap_rid.softVer) & 0xFF),
2868 le16_to_cpu(cap_rid.softSubVer));
2870 /* Test for WPA support */
2871 /* Only firmware versions 5.30.17 or better can do WPA */
2872 if (le16_to_cpu(cap_rid.softVer) > 0x530
2873 || (le16_to_cpu(cap_rid.softVer) == 0x530
2874 && le16_to_cpu(cap_rid.softSubVer) >= 17)) {
2875 airo_print_info(ai->dev->name, "WPA supported.");
2877 set_bit(FLAG_WPA_CAPABLE, &ai->flags);
2878 ai->bssListFirst = RID_WPA_BSSLISTFIRST;
2879 ai->bssListNext = RID_WPA_BSSLISTNEXT;
2880 ai->bssListRidLen = sizeof(BSSListRid);
2882 airo_print_info(ai->dev->name, "WPA unsupported with firmware "
2883 "versions older than 5.30.17.");
2885 ai->bssListFirst = RID_BSSLISTFIRST;
2886 ai->bssListNext = RID_BSSLISTNEXT;
2887 ai->bssListRidLen = sizeof(BSSListRid) - sizeof(BSSListRidExtra);
2890 set_bit(FLAG_REGISTERED,&ai->flags);
2891 airo_print_info(dev->name, "MAC enabled %pM", dev->dev_addr);
2893 /* Allocate the transmit buffers */
2894 if (probe && !test_bit(FLAG_MPI,&ai->flags))
2895 for( i = 0; i < MAX_FIDS; i++ )
2896 ai->fids[i] = transmit_allocate(ai,AIRO_DEF_MTU,i>=MAX_FIDS/2);
2898 if (setup_proc_entry(dev, dev->ml_priv) < 0)
2904 unregister_netdev(ai->wifidev);
2905 free_netdev(ai->wifidev);
2907 unregister_netdev(dev);
2909 if (test_bit(FLAG_MPI,&ai->flags) && pci) {
2910 pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
2911 iounmap(ai->pciaux);
2912 iounmap(ai->pcimem);
2913 mpi_unmap_card(ai->pci);
2917 release_region( dev->base_addr, 64 );
2919 airo_networks_free(ai);
2926 struct net_device *init_airo_card( unsigned short irq, int port, int is_pcmcia,
2927 struct device *dmdev)
2929 return _init_airo_card ( irq, port, is_pcmcia, NULL, dmdev);
2932 EXPORT_SYMBOL(init_airo_card);
2934 static int waitbusy (struct airo_info *ai) {
2936 while ((IN4500(ai, COMMAND) & COMMAND_BUSY) && (delay < 10000)) {
2938 if ((++delay % 20) == 0)
2939 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
2941 return delay < 10000;
2944 int reset_airo_card( struct net_device *dev )
2947 struct airo_info *ai = dev->ml_priv;
2949 if (reset_card (dev, 1))
2952 if ( setup_card(ai, dev->dev_addr, 1 ) != SUCCESS ) {
2953 airo_print_err(dev->name, "MAC could not be enabled");
2956 airo_print_info(dev->name, "MAC enabled %pM", dev->dev_addr);
2957 /* Allocate the transmit buffers if needed */
2958 if (!test_bit(FLAG_MPI,&ai->flags))
2959 for( i = 0; i < MAX_FIDS; i++ )
2960 ai->fids[i] = transmit_allocate (ai,AIRO_DEF_MTU,i>=MAX_FIDS/2);
2962 enable_interrupts( ai );
2963 netif_wake_queue(dev);
2967 EXPORT_SYMBOL(reset_airo_card);
2969 static void airo_send_event(struct net_device *dev) {
2970 struct airo_info *ai = dev->ml_priv;
2971 union iwreq_data wrqu;
2972 StatusRid status_rid;
2974 clear_bit(JOB_EVENT, &ai->jobs);
2975 PC4500_readrid(ai, RID_STATUS, &status_rid, sizeof(status_rid), 0);
2977 wrqu.data.length = 0;
2978 wrqu.data.flags = 0;
2979 memcpy(wrqu.ap_addr.sa_data, status_rid.bssid[0], ETH_ALEN);
2980 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
2982 /* Send event to user space */
2983 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
2986 static void airo_process_scan_results (struct airo_info *ai) {
2987 union iwreq_data wrqu;
2990 BSSListElement * loop_net;
2991 BSSListElement * tmp_net;
2993 /* Blow away current list of scan results */
2994 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
2995 list_move_tail (&loop_net->list, &ai->network_free_list);
2996 /* Don't blow away ->list, just BSS data */
2997 memset (loop_net, 0, sizeof (loop_net->bss));
3000 /* Try to read the first entry of the scan result */
3001 rc = PC4500_readrid(ai, ai->bssListFirst, &bss, ai->bssListRidLen, 0);
3002 if((rc) || (bss.index == cpu_to_le16(0xffff))) {
3003 /* No scan results */
3007 /* Read and parse all entries */
3009 while((!rc) && (bss.index != cpu_to_le16(0xffff))) {
3010 /* Grab a network off the free list */
3011 if (!list_empty(&ai->network_free_list)) {
3012 tmp_net = list_entry(ai->network_free_list.next,
3013 BSSListElement, list);
3014 list_del(ai->network_free_list.next);
3017 if (tmp_net != NULL) {
3018 memcpy(tmp_net, &bss, sizeof(tmp_net->bss));
3019 list_add_tail(&tmp_net->list, &ai->network_list);
3023 /* Read next entry */
3024 rc = PC4500_readrid(ai, ai->bssListNext,
3025 &bss, ai->bssListRidLen, 0);
3029 /* write APList back (we cleared it in airo_set_scan) */
3031 writeAPListRid(ai, &ai->APList, 0);
3034 ai->scan_timeout = 0;
3035 clear_bit(JOB_SCAN_RESULTS, &ai->jobs);
3038 /* Send an empty event to user space.
3039 * We don't send the received data on
3040 * the event because it would require
3041 * us to do complex transcoding, and
3042 * we want to minimise the work done in
3043 * the irq handler. Use a request to
3044 * extract the data - Jean II */
3045 wrqu.data.length = 0;
3046 wrqu.data.flags = 0;
3047 wireless_send_event(ai->dev, SIOCGIWSCAN, &wrqu, NULL);
3050 static int airo_thread(void *data) {
3051 struct net_device *dev = data;
3052 struct airo_info *ai = dev->ml_priv;
3057 /* make swsusp happy with our thread */
3060 if (test_bit(JOB_DIE, &ai->jobs))
3064 locked = down_interruptible(&ai->sem);
3066 wait_queue_entry_t wait;
3068 init_waitqueue_entry(&wait, current);
3069 add_wait_queue(&ai->thr_wait, &wait);
3071 set_current_state(TASK_INTERRUPTIBLE);
3074 if (ai->expires || ai->scan_timeout) {
3075 if (ai->scan_timeout &&
3076 time_after_eq(jiffies,ai->scan_timeout)){
3077 set_bit(JOB_SCAN_RESULTS, &ai->jobs);
3079 } else if (ai->expires &&
3080 time_after_eq(jiffies,ai->expires)){
3081 set_bit(JOB_AUTOWEP, &ai->jobs);
3084 if (!kthread_should_stop() &&
3085 !freezing(current)) {
3086 unsigned long wake_at;
3087 if (!ai->expires || !ai->scan_timeout) {
3088 wake_at = max(ai->expires,
3091 wake_at = min(ai->expires,
3094 schedule_timeout(wake_at - jiffies);
3097 } else if (!kthread_should_stop() &&
3098 !freezing(current)) {
3104 current->state = TASK_RUNNING;
3105 remove_wait_queue(&ai->thr_wait, &wait);
3112 if (test_bit(JOB_DIE, &ai->jobs)) {
3117 if (ai->power.event || test_bit(FLAG_FLASHING, &ai->flags)) {
3122 if (test_bit(JOB_XMIT, &ai->jobs))
3124 else if (test_bit(JOB_XMIT11, &ai->jobs))
3125 airo_end_xmit11(dev);
3126 else if (test_bit(JOB_STATS, &ai->jobs))
3127 airo_read_stats(dev);
3128 else if (test_bit(JOB_WSTATS, &ai->jobs))
3129 airo_read_wireless_stats(ai);
3130 else if (test_bit(JOB_PROMISC, &ai->jobs))
3131 airo_set_promisc(ai);
3132 else if (test_bit(JOB_MIC, &ai->jobs))
3134 else if (test_bit(JOB_EVENT, &ai->jobs))
3135 airo_send_event(dev);
3136 else if (test_bit(JOB_AUTOWEP, &ai->jobs))
3138 else if (test_bit(JOB_SCAN_RESULTS, &ai->jobs))
3139 airo_process_scan_results(ai);
3140 else /* Shouldn't get here, but we make sure to unlock */
3147 static int header_len(__le16 ctl)
3149 u16 fc = le16_to_cpu(ctl);
3152 if ((fc & 0xe0) == 0xc0)
3153 return 10; /* one-address control packet */
3154 return 16; /* two-address control packet */
3156 if ((fc & 0x300) == 0x300)
3157 return 30; /* WDS packet */
3162 static void airo_handle_cisco_mic(struct airo_info *ai)
3164 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags)) {
3165 set_bit(JOB_MIC, &ai->jobs);
3166 wake_up_interruptible(&ai->thr_wait);
3170 /* Airo Status codes */
3171 #define STAT_NOBEACON 0x8000 /* Loss of sync - missed beacons */
3172 #define STAT_MAXRETRIES 0x8001 /* Loss of sync - max retries */
3173 #define STAT_MAXARL 0x8002 /* Loss of sync - average retry level exceeded*/
3174 #define STAT_FORCELOSS 0x8003 /* Loss of sync - host request */
3175 #define STAT_TSFSYNC 0x8004 /* Loss of sync - TSF synchronization */
3176 #define STAT_DEAUTH 0x8100 /* low byte is 802.11 reason code */
3177 #define STAT_DISASSOC 0x8200 /* low byte is 802.11 reason code */
3178 #define STAT_ASSOC_FAIL 0x8400 /* low byte is 802.11 reason code */
3179 #define STAT_AUTH_FAIL 0x0300 /* low byte is 802.11 reason code */
3180 #define STAT_ASSOC 0x0400 /* Associated */
3181 #define STAT_REASSOC 0x0600 /* Reassociated? Only on firmware >= 5.30.17 */
3183 static void airo_print_status(const char *devname, u16 status)
3185 u8 reason = status & 0xFF;
3187 switch (status & 0xFF00) {
3191 airo_print_dbg(devname, "link lost (missed beacons)");
3193 case STAT_MAXRETRIES:
3195 airo_print_dbg(devname, "link lost (max retries)");
3197 case STAT_FORCELOSS:
3198 airo_print_dbg(devname, "link lost (local choice)");
3201 airo_print_dbg(devname, "link lost (TSF sync lost)");
3204 airo_print_dbg(devname, "unknown status %x\n", status);
3209 airo_print_dbg(devname, "deauthenticated (reason: %d)", reason);
3212 airo_print_dbg(devname, "disassociated (reason: %d)", reason);
3214 case STAT_ASSOC_FAIL:
3215 airo_print_dbg(devname, "association failed (reason: %d)",
3218 case STAT_AUTH_FAIL:
3219 airo_print_dbg(devname, "authentication failed (reason: %d)",
3226 airo_print_dbg(devname, "unknown status %x\n", status);
3231 static void airo_handle_link(struct airo_info *ai)
3233 union iwreq_data wrqu;
3234 int scan_forceloss = 0;
3237 /* Get new status and acknowledge the link change */
3238 status = le16_to_cpu(IN4500(ai, LINKSTAT));
3239 OUT4500(ai, EVACK, EV_LINK);
3241 if ((status == STAT_FORCELOSS) && (ai->scan_timeout > 0))
3244 airo_print_status(ai->dev->name, status);
3246 if ((status == STAT_ASSOC) || (status == STAT_REASSOC)) {
3249 if (ai->list_bss_task)
3250 wake_up_process(ai->list_bss_task);
3251 set_bit(FLAG_UPDATE_UNI, &ai->flags);
3252 set_bit(FLAG_UPDATE_MULTI, &ai->flags);
3254 if (down_trylock(&ai->sem) != 0) {
3255 set_bit(JOB_EVENT, &ai->jobs);
3256 wake_up_interruptible(&ai->thr_wait);
3258 airo_send_event(ai->dev);
3259 netif_carrier_on(ai->dev);
3260 } else if (!scan_forceloss) {
3261 if (auto_wep && !ai->expires) {
3262 ai->expires = RUN_AT(3*HZ);
3263 wake_up_interruptible(&ai->thr_wait);
3266 /* Send event to user space */
3267 eth_zero_addr(wrqu.ap_addr.sa_data);
3268 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3269 wireless_send_event(ai->dev, SIOCGIWAP, &wrqu, NULL);
3270 netif_carrier_off(ai->dev);
3272 netif_carrier_off(ai->dev);
3276 static void airo_handle_rx(struct airo_info *ai)
3278 struct sk_buff *skb = NULL;
3279 __le16 fc, v, *buffer, tmpbuf[4];
3280 u16 len, hdrlen = 0, gap, fid;
3284 if (test_bit(FLAG_MPI, &ai->flags)) {
3285 if (test_bit(FLAG_802_11, &ai->flags))
3286 mpi_receive_802_11(ai);
3288 mpi_receive_802_3(ai);
3289 OUT4500(ai, EVACK, EV_RX);
3293 fid = IN4500(ai, RXFID);
3295 /* Get the packet length */
3296 if (test_bit(FLAG_802_11, &ai->flags)) {
3297 bap_setup (ai, fid, 4, BAP0);
3298 bap_read (ai, (__le16*)&hdr, sizeof(hdr), BAP0);
3299 /* Bad CRC. Ignore packet */
3300 if (le16_to_cpu(hdr.status) & 2)
3302 if (ai->wifidev == NULL)
3305 bap_setup(ai, fid, 0x36, BAP0);
3306 bap_read(ai, &hdr.len, 2, BAP0);
3308 len = le16_to_cpu(hdr.len);
3310 if (len > AIRO_DEF_MTU) {
3311 airo_print_err(ai->dev->name, "Bad size %d", len);
3317 if (test_bit(FLAG_802_11, &ai->flags)) {
3318 bap_read(ai, &fc, sizeof (fc), BAP0);
3319 hdrlen = header_len(fc);
3321 hdrlen = ETH_ALEN * 2;
3323 skb = dev_alloc_skb(len + hdrlen + 2 + 2);
3325 ai->dev->stats.rx_dropped++;
3329 skb_reserve(skb, 2); /* This way the IP header is aligned */
3330 buffer = skb_put(skb, len + hdrlen);
3331 if (test_bit(FLAG_802_11, &ai->flags)) {
3333 bap_read(ai, buffer + 1, hdrlen - 2, BAP0);
3335 bap_read(ai, tmpbuf, 6, BAP0);
3337 bap_read(ai, &v, sizeof(v), BAP0);
3338 gap = le16_to_cpu(v);
3341 bap_read(ai, tmpbuf, gap, BAP0);
3343 airo_print_err(ai->dev->name, "gaplen too "
3344 "big. Problems will follow...");
3347 bap_read(ai, buffer + hdrlen/2, len, BAP0);
3351 bap_read(ai, buffer, ETH_ALEN * 2, BAP0);
3352 if (ai->micstats.enabled) {
3353 bap_read(ai, (__le16 *) &micbuf, sizeof (micbuf), BAP0);
3354 if (ntohs(micbuf.typelen) > 0x05DC)
3355 bap_setup(ai, fid, 0x44, BAP0);
3357 if (len <= sizeof (micbuf)) {
3358 dev_kfree_skb_irq(skb);
3362 len -= sizeof(micbuf);
3363 skb_trim(skb, len + hdrlen);
3367 bap_read(ai, buffer + ETH_ALEN, len, BAP0);
3368 if (decapsulate(ai, &micbuf, (etherHead*) buffer, len))
3369 dev_kfree_skb_irq (skb);
3375 if (success && (ai->spy_data.spy_number > 0)) {
3377 struct iw_quality wstats;
3379 /* Prepare spy data : addr + qual */
3380 if (!test_bit(FLAG_802_11, &ai->flags)) {
3381 sa = (char *) buffer + 6;
3382 bap_setup(ai, fid, 8, BAP0);
3383 bap_read(ai, (__le16 *) hdr.rssi, 2, BAP0);
3385 sa = (char *) buffer + 10;
3386 wstats.qual = hdr.rssi[0];
3388 wstats.level = 0x100 - ai->rssi[hdr.rssi[1]].rssidBm;
3390 wstats.level = (hdr.rssi[1] + 321) / 2;
3391 wstats.noise = ai->wstats.qual.noise;
3392 wstats.updated = IW_QUAL_LEVEL_UPDATED
3393 | IW_QUAL_QUAL_UPDATED
3395 /* Update spy records */
3396 wireless_spy_update(ai->dev, sa, &wstats);
3398 #endif /* WIRELESS_SPY */
3401 OUT4500(ai, EVACK, EV_RX);
3404 if (test_bit(FLAG_802_11, &ai->flags)) {
3405 skb_reset_mac_header(skb);
3406 skb->pkt_type = PACKET_OTHERHOST;
3407 skb->dev = ai->wifidev;
3408 skb->protocol = htons(ETH_P_802_2);
3410 skb->protocol = eth_type_trans(skb, ai->dev);
3411 skb->ip_summed = CHECKSUM_NONE;
3417 static void airo_handle_tx(struct airo_info *ai, u16 status)
3422 if (test_bit(FLAG_MPI, &ai->flags)) {
3423 unsigned long flags;
3425 if (status & EV_TXEXC)
3426 get_tx_error(ai, -1);
3428 spin_lock_irqsave(&ai->aux_lock, flags);
3429 if (!skb_queue_empty(&ai->txq)) {
3430 spin_unlock_irqrestore(&ai->aux_lock,flags);
3431 mpi_send_packet(ai->dev);
3433 clear_bit(FLAG_PENDING_XMIT, &ai->flags);
3434 spin_unlock_irqrestore(&ai->aux_lock,flags);
3435 netif_wake_queue(ai->dev);
3437 OUT4500(ai, EVACK, status & (EV_TX | EV_TXCPY | EV_TXEXC));
3441 fid = IN4500(ai, TXCOMPLFID);
3443 for (i = 0; i < MAX_FIDS; i++) {
3444 if ((ai->fids[i] & 0xffff) == fid)
3449 if (status & EV_TXEXC)
3450 get_tx_error(ai, index);
3452 OUT4500(ai, EVACK, status & (EV_TX | EV_TXEXC));
3454 /* Set up to be used again */
3455 ai->fids[index] &= 0xffff;
3456 if (index < MAX_FIDS / 2) {
3457 if (!test_bit(FLAG_PENDING_XMIT, &ai->flags))
3458 netif_wake_queue(ai->dev);
3460 if (!test_bit(FLAG_PENDING_XMIT11, &ai->flags))
3461 netif_wake_queue(ai->wifidev);
3464 OUT4500(ai, EVACK, status & (EV_TX | EV_TXCPY | EV_TXEXC));
3465 airo_print_err(ai->dev->name, "Unallocated FID was used to xmit");
3469 static irqreturn_t airo_interrupt(int irq, void *dev_id)
3471 struct net_device *dev = dev_id;
3472 u16 status, savedInterrupts = 0;
3473 struct airo_info *ai = dev->ml_priv;
3476 if (!netif_device_present(dev))
3480 status = IN4500(ai, EVSTAT);
3481 if (!(status & STATUS_INTS) || (status == 0xffff))
3486 if (status & EV_AWAKE) {
3487 OUT4500(ai, EVACK, EV_AWAKE);
3488 OUT4500(ai, EVACK, EV_AWAKE);
3491 if (!savedInterrupts) {
3492 savedInterrupts = IN4500(ai, EVINTEN);
3493 OUT4500(ai, EVINTEN, 0);
3496 if (status & EV_MIC) {
3497 OUT4500(ai, EVACK, EV_MIC);
3498 airo_handle_cisco_mic(ai);
3501 if (status & EV_LINK) {
3502 /* Link status changed */
3503 airo_handle_link(ai);
3506 /* Check to see if there is something to receive */
3510 /* Check to see if a packet has been transmitted */
3511 if (status & (EV_TX | EV_TXCPY | EV_TXEXC))
3512 airo_handle_tx(ai, status);
3514 if ( status & ~STATUS_INTS & ~IGNORE_INTS ) {
3515 airo_print_warn(ai->dev->name, "Got weird status %x",
3516 status & ~STATUS_INTS & ~IGNORE_INTS );
3520 if (savedInterrupts)
3521 OUT4500(ai, EVINTEN, savedInterrupts);
3523 return IRQ_RETVAL(handled);
3527 * Routines to talk to the card
3531 * This was originally written for the 4500, hence the name
3532 * NOTE: If use with 8bit mode and SMP bad things will happen!
3533 * Why would some one do 8 bit IO in an SMP machine?!?
3535 static void OUT4500( struct airo_info *ai, u16 reg, u16 val ) {
3536 if (test_bit(FLAG_MPI,&ai->flags))
3539 outw( val, ai->dev->base_addr + reg );
3541 outb( val & 0xff, ai->dev->base_addr + reg );
3542 outb( val >> 8, ai->dev->base_addr + reg + 1 );
3546 static u16 IN4500( struct airo_info *ai, u16 reg ) {
3549 if (test_bit(FLAG_MPI,&ai->flags))
3552 rc = inw( ai->dev->base_addr + reg );
3554 rc = inb( ai->dev->base_addr + reg );
3555 rc += ((int)inb( ai->dev->base_addr + reg + 1 )) << 8;
3560 static int enable_MAC(struct airo_info *ai, int lock)
3566 /* FLAG_RADIO_OFF : Radio disabled via /proc or Wireless Extensions
3567 * FLAG_RADIO_DOWN : Radio disabled via "ifconfig ethX down"
3568 * Note : we could try to use !netif_running(dev) in enable_MAC()
3569 * instead of this flag, but I don't trust it *within* the
3570 * open/close functions, and testing both flags together is
3571 * "cheaper" - Jean II */
3572 if (ai->flags & FLAG_RADIO_MASK) return SUCCESS;
3574 if (lock && down_interruptible(&ai->sem))
3575 return -ERESTARTSYS;
3577 if (!test_bit(FLAG_ENABLED, &ai->flags)) {
3578 memset(&cmd, 0, sizeof(cmd));
3579 cmd.cmd = MAC_ENABLE;
3580 rc = issuecommand(ai, &cmd, &rsp);
3582 set_bit(FLAG_ENABLED, &ai->flags);
3590 airo_print_err(ai->dev->name, "Cannot enable MAC");
3591 else if ((rsp.status & 0xFF00) != 0) {
3592 airo_print_err(ai->dev->name, "Bad MAC enable reason=%x, "
3593 "rid=%x, offset=%d", rsp.rsp0, rsp.rsp1, rsp.rsp2);
3599 static void disable_MAC( struct airo_info *ai, int lock ) {
3603 if (lock == 1 && down_interruptible(&ai->sem))
3606 if (test_bit(FLAG_ENABLED, &ai->flags)) {
3607 if (lock != 2) /* lock == 2 means don't disable carrier */
3608 netif_carrier_off(ai->dev);
3609 memset(&cmd, 0, sizeof(cmd));
3610 cmd.cmd = MAC_DISABLE; // disable in case already enabled
3611 issuecommand(ai, &cmd, &rsp);
3612 clear_bit(FLAG_ENABLED, &ai->flags);
3618 static void enable_interrupts( struct airo_info *ai ) {
3619 /* Enable the interrupts */
3620 OUT4500( ai, EVINTEN, STATUS_INTS );
3623 static void disable_interrupts( struct airo_info *ai ) {
3624 OUT4500( ai, EVINTEN, 0 );
3627 static void mpi_receive_802_3(struct airo_info *ai)
3631 struct sk_buff *skb;
3636 memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
3637 /* Make sure we got something */
3638 if (rxd.rdy && rxd.valid == 0) {
3640 if (len < 12 || len > 2048)
3643 skb = dev_alloc_skb(len);
3645 ai->dev->stats.rx_dropped++;
3648 buffer = skb_put(skb,len);
3649 memcpy(buffer, ai->rxfids[0].virtual_host_addr, ETH_ALEN * 2);
3650 if (ai->micstats.enabled) {
3652 ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2,
3654 if (ntohs(micbuf.typelen) <= 0x05DC) {
3655 if (len <= sizeof(micbuf) + ETH_ALEN * 2)
3658 off = sizeof(micbuf);
3659 skb_trim (skb, len - off);
3662 memcpy(buffer + ETH_ALEN * 2,
3663 ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2 + off,
3664 len - ETH_ALEN * 2 - off);
3665 if (decapsulate (ai, &micbuf, (etherHead*)buffer, len - off - ETH_ALEN * 2)) {
3667 dev_kfree_skb_irq (skb);
3671 if (ai->spy_data.spy_number > 0) {
3673 struct iw_quality wstats;
3674 /* Prepare spy data : addr + qual */
3675 sa = buffer + ETH_ALEN;
3676 wstats.qual = 0; /* XXX Where do I get that info from ??? */
3679 /* Update spy records */
3680 wireless_spy_update(ai->dev, sa, &wstats);
3682 #endif /* WIRELESS_SPY */
3684 skb->ip_summed = CHECKSUM_NONE;
3685 skb->protocol = eth_type_trans(skb, ai->dev);
3689 if (rxd.valid == 0) {
3693 memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
3697 static void mpi_receive_802_11(struct airo_info *ai)
3700 struct sk_buff *skb = NULL;
3701 u16 len, hdrlen = 0;
3706 char *ptr = ai->rxfids[0].virtual_host_addr + 4;
3708 memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
3709 memcpy ((char *)&hdr, ptr, sizeof(hdr));
3711 /* Bad CRC. Ignore packet */
3712 if (le16_to_cpu(hdr.status) & 2)
3714 if (ai->wifidev == NULL)
3716 len = le16_to_cpu(hdr.len);
3717 if (len > AIRO_DEF_MTU) {
3718 airo_print_err(ai->dev->name, "Bad size %d", len);
3724 fc = get_unaligned((__le16 *)ptr);
3725 hdrlen = header_len(fc);
3727 skb = dev_alloc_skb( len + hdrlen + 2 );
3729 ai->dev->stats.rx_dropped++;
3732 buffer = skb_put(skb, len + hdrlen);
3733 memcpy ((char *)buffer, ptr, hdrlen);
3737 gap = get_unaligned_le16(ptr);
3738 ptr += sizeof(__le16);
3743 airo_print_err(ai->dev->name,
3744 "gaplen too big. Problems will follow...");
3746 memcpy ((char *)buffer + hdrlen, ptr, len);
3748 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
3749 if (ai->spy_data.spy_number > 0) {
3751 struct iw_quality wstats;
3752 /* Prepare spy data : addr + qual */
3753 sa = (char*)buffer + 10;
3754 wstats.qual = hdr.rssi[0];
3756 wstats.level = 0x100 - ai->rssi[hdr.rssi[1]].rssidBm;
3758 wstats.level = (hdr.rssi[1] + 321) / 2;
3759 wstats.noise = ai->wstats.qual.noise;
3760 wstats.updated = IW_QUAL_QUAL_UPDATED
3761 | IW_QUAL_LEVEL_UPDATED
3763 /* Update spy records */
3764 wireless_spy_update(ai->dev, sa, &wstats);
3766 #endif /* IW_WIRELESS_SPY */
3767 skb_reset_mac_header(skb);
3768 skb->pkt_type = PACKET_OTHERHOST;
3769 skb->dev = ai->wifidev;
3770 skb->protocol = htons(ETH_P_802_2);
3771 skb->ip_summed = CHECKSUM_NONE;
3775 if (rxd.valid == 0) {
3779 memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
3783 static inline void set_auth_type(struct airo_info *local, int auth_type)
3785 local->config.authType = auth_type;
3786 /* Cache the last auth type used (of AUTH_OPEN and AUTH_ENCRYPT).
3787 * Used by airo_set_auth()
3789 if (auth_type == AUTH_OPEN || auth_type == AUTH_ENCRYPT)
3790 local->last_auth = auth_type;
3793 static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
3803 memset( &mySsid, 0, sizeof( mySsid ) );
3807 /* The NOP is the first step in getting the card going */
3809 cmd.parm0 = cmd.parm1 = cmd.parm2 = 0;
3810 if (lock && down_interruptible(&ai->sem))
3812 if ( issuecommand( ai, &cmd, &rsp ) != SUCCESS ) {
3817 disable_MAC( ai, 0);
3819 // Let's figure out if we need to use the AUX port
3820 if (!test_bit(FLAG_MPI,&ai->flags)) {
3821 cmd.cmd = CMD_ENABLEAUX;
3822 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
3825 airo_print_err(ai->dev->name, "Error checking for AUX port");
3828 if (!aux_bap || rsp.status & 0xff00) {
3829 ai->bap_read = fast_bap_read;
3830 airo_print_dbg(ai->dev->name, "Doing fast bap_reads");
3832 ai->bap_read = aux_bap_read;
3833 airo_print_dbg(ai->dev->name, "Doing AUX bap_reads");
3838 if (ai->config.len == 0) {
3840 tdsRssiRid rssi_rid;
3841 CapabilityRid cap_rid;
3845 // general configuration (read/modify/write)
3846 status = readConfigRid(ai, lock);
3847 if ( status != SUCCESS ) return ERROR;
3849 status = readCapabilityRid(ai, &cap_rid, lock);
3850 if ( status != SUCCESS ) return ERROR;
3852 status = PC4500_readrid(ai,RID_RSSI,&rssi_rid,sizeof(rssi_rid),lock);
3853 if ( status == SUCCESS ) {
3854 if (ai->rssi || (ai->rssi = kmalloc(512, GFP_KERNEL)) != NULL)
3855 memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512); /* Skip RID length member */
3860 if (cap_rid.softCap & cpu_to_le16(8))
3861 ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
3863 airo_print_warn(ai->dev->name, "unknown received signal "
3866 ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS;
3867 set_auth_type(ai, AUTH_OPEN);
3868 ai->config.modulation = MOD_CCK;
3870 if (le16_to_cpu(cap_rid.len) >= sizeof(cap_rid) &&
3871 (cap_rid.extSoftCap & cpu_to_le16(1)) &&
3872 micsetup(ai) == SUCCESS) {
3873 ai->config.opmode |= MODE_MIC;
3874 set_bit(FLAG_MIC_CAPABLE, &ai->flags);
3877 /* Save off the MAC */
3878 for( i = 0; i < ETH_ALEN; i++ ) {
3879 mac[i] = ai->config.macAddr[i];
3882 /* Check to see if there are any insmod configured
3885 memset(ai->config.rates,0,sizeof(ai->config.rates));
3886 for( i = 0; i < 8 && rates[i]; i++ ) {
3887 ai->config.rates[i] = rates[i];
3890 set_bit (FLAG_COMMIT, &ai->flags);
3893 /* Setup the SSIDs if present */
3896 for( i = 0; i < 3 && ssids[i]; i++ ) {
3897 size_t len = strlen(ssids[i]);
3900 mySsid.ssids[i].len = cpu_to_le16(len);
3901 memcpy(mySsid.ssids[i].ssid, ssids[i], len);
3903 mySsid.len = cpu_to_le16(sizeof(mySsid));
3906 status = writeConfigRid(ai, lock);
3907 if ( status != SUCCESS ) return ERROR;
3909 /* Set up the SSID list */
3911 status = writeSsidRid(ai, &mySsid, lock);
3912 if ( status != SUCCESS ) return ERROR;
3915 status = enable_MAC(ai, lock);
3916 if (status != SUCCESS)
3919 /* Grab the initial wep key, we gotta save it for auto_wep */
3920 rc = readWepKeyRid(ai, &wkr, 1, lock);
3921 if (rc == SUCCESS) do {
3922 lastindex = wkr.kindex;
3923 if (wkr.kindex == cpu_to_le16(0xffff)) {
3924 ai->defindex = wkr.mac[0];
3926 rc = readWepKeyRid(ai, &wkr, 0, lock);
3927 } while(lastindex != wkr.kindex);
3934 static u16 issuecommand(struct airo_info *ai, Cmd *pCmd, Resp *pRsp) {
3935 // Im really paranoid about letting it run forever!
3936 int max_tries = 600000;
3938 if (IN4500(ai, EVSTAT) & EV_CMD)
3939 OUT4500(ai, EVACK, EV_CMD);
3941 OUT4500(ai, PARAM0, pCmd->parm0);
3942 OUT4500(ai, PARAM1, pCmd->parm1);
3943 OUT4500(ai, PARAM2, pCmd->parm2);
3944 OUT4500(ai, COMMAND, pCmd->cmd);
3946 while (max_tries-- && (IN4500(ai, EVSTAT) & EV_CMD) == 0) {
3947 if ((IN4500(ai, COMMAND)) == pCmd->cmd)
3948 // PC4500 didn't notice command, try again
3949 OUT4500(ai, COMMAND, pCmd->cmd);
3950 if (!in_atomic() && (max_tries & 255) == 0)
3954 if ( max_tries == -1 ) {
3955 airo_print_err(ai->dev->name,
3956 "Max tries exceeded when issuing command");
3957 if (IN4500(ai, COMMAND) & COMMAND_BUSY)
3958 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
3962 // command completed
3963 pRsp->status = IN4500(ai, STATUS);
3964 pRsp->rsp0 = IN4500(ai, RESP0);
3965 pRsp->rsp1 = IN4500(ai, RESP1);
3966 pRsp->rsp2 = IN4500(ai, RESP2);
3967 if ((pRsp->status & 0xff00)!=0 && pCmd->cmd != CMD_SOFTRESET)
3968 airo_print_err(ai->dev->name,
3969 "cmd:%x status:%x rsp0:%x rsp1:%x rsp2:%x",
3970 pCmd->cmd, pRsp->status, pRsp->rsp0, pRsp->rsp1,
3973 // clear stuck command busy if necessary
3974 if (IN4500(ai, COMMAND) & COMMAND_BUSY) {
3975 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
3977 // acknowledge processing the status/response
3978 OUT4500(ai, EVACK, EV_CMD);
3983 /* Sets up the bap to start exchange data. whichbap should
3984 * be one of the BAP0 or BAP1 defines. Locks should be held before
3986 static int bap_setup(struct airo_info *ai, u16 rid, u16 offset, int whichbap )
3991 OUT4500(ai, SELECT0+whichbap, rid);
3992 OUT4500(ai, OFFSET0+whichbap, offset);
3994 int status = IN4500(ai, OFFSET0+whichbap);
3995 if (status & BAP_BUSY) {
3996 /* This isn't really a timeout, but its kinda
4001 } else if ( status & BAP_ERR ) {
4002 /* invalid rid or offset */
4003 airo_print_err(ai->dev->name, "BAP error %x %d",
4006 } else if (status & BAP_DONE) { // success
4009 if ( !(max_tries--) ) {
4010 airo_print_err(ai->dev->name,
4011 "BAP setup error too many retries\n");
4014 // -- PC4500 missed it, try again
4015 OUT4500(ai, SELECT0+whichbap, rid);
4016 OUT4500(ai, OFFSET0+whichbap, offset);
4021 /* should only be called by aux_bap_read. This aux function and the
4022 following use concepts not documented in the developers guide. I
4023 got them from a patch given to my by Aironet */
4024 static u16 aux_setup(struct airo_info *ai, u16 page,
4025 u16 offset, u16 *len)
4029 OUT4500(ai, AUXPAGE, page);
4030 OUT4500(ai, AUXOFF, 0);
4031 next = IN4500(ai, AUXDATA);
4032 *len = IN4500(ai, AUXDATA)&0xff;
4033 if (offset != 4) OUT4500(ai, AUXOFF, offset);
4037 /* requires call to bap_setup() first */
4038 static int aux_bap_read(struct airo_info *ai, __le16 *pu16Dst,
4039 int bytelen, int whichbap)
4047 unsigned long flags;
4049 spin_lock_irqsave(&ai->aux_lock, flags);
4050 page = IN4500(ai, SWS0+whichbap);
4051 offset = IN4500(ai, SWS2+whichbap);
4052 next = aux_setup(ai, page, offset, &len);
4053 words = (bytelen+1)>>1;
4055 for (i=0; i<words;) {
4057 count = (len>>1) < (words-i) ? (len>>1) : (words-i);
4059 insw( ai->dev->base_addr+DATA0+whichbap,
4062 insb( ai->dev->base_addr+DATA0+whichbap,
4063 pu16Dst+i, count << 1 );
4066 next = aux_setup(ai, next, 4, &len);
4069 spin_unlock_irqrestore(&ai->aux_lock, flags);
4074 /* requires call to bap_setup() first */
4075 static int fast_bap_read(struct airo_info *ai, __le16 *pu16Dst,
4076 int bytelen, int whichbap)
4078 bytelen = (bytelen + 1) & (~1); // round up to even value
4080 insw( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen>>1 );
4082 insb( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen );
4086 /* requires call to bap_setup() first */
4087 static int bap_write(struct airo_info *ai, const __le16 *pu16Src,
4088 int bytelen, int whichbap)
4090 bytelen = (bytelen + 1) & (~1); // round up to even value
4092 outsw( ai->dev->base_addr+DATA0+whichbap,
4093 pu16Src, bytelen>>1 );
4095 outsb( ai->dev->base_addr+DATA0+whichbap, pu16Src, bytelen );
4099 static int PC4500_accessrid(struct airo_info *ai, u16 rid, u16 accmd)
4101 Cmd cmd; /* for issuing commands */
4102 Resp rsp; /* response from commands */
4105 memset(&cmd, 0, sizeof(cmd));
4108 status = issuecommand(ai, &cmd, &rsp);
4109 if (status != 0) return status;
4110 if ( (rsp.status & 0x7F00) != 0) {
4111 return (accmd << 8) + (rsp.rsp0 & 0xFF);
4116 /* Note, that we are using BAP1 which is also used by transmit, so
4117 * we must get a lock. */
4118 static int PC4500_readrid(struct airo_info *ai, u16 rid, void *pBuf, int len, int lock)
4124 if (down_interruptible(&ai->sem))
4127 if (test_bit(FLAG_MPI,&ai->flags)) {
4131 memset(&cmd, 0, sizeof(cmd));
4132 memset(&rsp, 0, sizeof(rsp));
4133 ai->config_desc.rid_desc.valid = 1;
4134 ai->config_desc.rid_desc.len = RIDSIZE;
4135 ai->config_desc.rid_desc.rid = 0;
4136 ai->config_desc.rid_desc.host_addr = ai->ridbus;
4138 cmd.cmd = CMD_ACCESS;
4141 memcpy_toio(ai->config_desc.card_ram_off,
4142 &ai->config_desc.rid_desc, sizeof(Rid));
4144 rc = issuecommand(ai, &cmd, &rsp);
4146 if (rsp.status & 0x7f00)
4149 memcpy(pBuf, ai->config_desc.virtual_host_addr, len);
4152 if ((status = PC4500_accessrid(ai, rid, CMD_ACCESS))!=SUCCESS) {
4156 if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
4160 // read the rid length field
4161 bap_read(ai, pBuf, 2, BAP1);
4162 // length for remaining part of rid
4163 len = min(len, (int)le16_to_cpu(*(__le16*)pBuf)) - 2;
4166 airo_print_err(ai->dev->name,
4167 "Rid %x has a length of %d which is too short",
4168 (int)rid, (int)len );
4172 // read remainder of the rid
4173 rc = bap_read(ai, ((__le16*)pBuf)+1, len, BAP1);
4181 /* Note, that we are using BAP1 which is also used by transmit, so
4182 * make sure this isn't called when a transmit is happening */
4183 static int PC4500_writerid(struct airo_info *ai, u16 rid,
4184 const void *pBuf, int len, int lock)
4189 *(__le16*)pBuf = cpu_to_le16((u16)len);
4192 if (down_interruptible(&ai->sem))
4195 if (test_bit(FLAG_MPI,&ai->flags)) {
4199 if (test_bit(FLAG_ENABLED, &ai->flags) && (RID_WEP_TEMP != rid))
4200 airo_print_err(ai->dev->name,
4201 "%s: MAC should be disabled (rid=%04x)",
4203 memset(&cmd, 0, sizeof(cmd));
4204 memset(&rsp, 0, sizeof(rsp));
4206 ai->config_desc.rid_desc.valid = 1;
4207 ai->config_desc.rid_desc.len = *((u16 *)pBuf);
4208 ai->config_desc.rid_desc.rid = 0;
4210 cmd.cmd = CMD_WRITERID;
4213 memcpy_toio(ai->config_desc.card_ram_off,
4214 &ai->config_desc.rid_desc, sizeof(Rid));
4216 if (len < 4 || len > 2047) {
4217 airo_print_err(ai->dev->name, "%s: len=%d", __func__, len);
4220 memcpy(ai->config_desc.virtual_host_addr,
4223 rc = issuecommand(ai, &cmd, &rsp);
4224 if ((rc & 0xff00) != 0) {
4225 airo_print_err(ai->dev->name, "%s: Write rid Error %d",
4227 airo_print_err(ai->dev->name, "%s: Cmd=%04x",
4231 if ((rsp.status & 0x7f00))
4235 // --- first access so that we can write the rid data
4236 if ( (status = PC4500_accessrid(ai, rid, CMD_ACCESS)) != 0) {
4240 // --- now write the rid data
4241 if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
4245 bap_write(ai, pBuf, len, BAP1);
4246 // ---now commit the rid data
4247 rc = PC4500_accessrid(ai, rid, 0x100|CMD_ACCESS);
4255 /* Allocates a FID to be used for transmitting packets. We only use
4257 static u16 transmit_allocate(struct airo_info *ai, int lenPayload, int raw)
4259 unsigned int loop = 3000;
4265 cmd.cmd = CMD_ALLOCATETX;
4266 cmd.parm0 = lenPayload;
4267 if (down_interruptible(&ai->sem))
4269 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
4273 if ( (rsp.status & 0xFF00) != 0) {
4277 /* wait for the allocate event/indication
4278 * It makes me kind of nervous that this can just sit here and spin,
4279 * but in practice it only loops like four times. */
4280 while (((IN4500(ai, EVSTAT) & EV_ALLOC) == 0) && --loop);
4286 // get the allocated fid and acknowledge
4287 txFid = IN4500(ai, TXALLOCFID);
4288 OUT4500(ai, EVACK, EV_ALLOC);
4290 /* The CARD is pretty cool since it converts the ethernet packet
4291 * into 802.11. Also note that we don't release the FID since we
4292 * will be using the same one over and over again. */
4293 /* We only have to setup the control once since we are not
4294 * releasing the fid. */
4296 txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_11
4297 | TXCTL_ETHERNET | TXCTL_NORELEASE);
4299 txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_3
4300 | TXCTL_ETHERNET | TXCTL_NORELEASE);
4301 if (bap_setup(ai, txFid, 0x0008, BAP1) != SUCCESS)
4304 bap_write(ai, &txControl, sizeof(txControl), BAP1);
4312 /* In general BAP1 is dedicated to transmiting packets. However,
4313 since we need a BAP when accessing RIDs, we also use BAP1 for that.
4314 Make sure the BAP1 spinlock is held when this is called. */
4315 static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket)
4326 if (len <= ETH_ALEN * 2) {
4327 airo_print_warn(ai->dev->name, "Short packet %d", len);
4330 len -= ETH_ALEN * 2;
4332 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
4333 (ntohs(((__be16 *)pPacket)[6]) != 0x888E)) {
4334 if (encapsulate(ai,(etherHead *)pPacket,&pMic,len) != SUCCESS)
4336 miclen = sizeof(pMic);
4338 // packet is destination[6], source[6], payload[len-12]
4339 // write the payload length and dst/src/payload
4340 if (bap_setup(ai, txFid, 0x0036, BAP1) != SUCCESS) return ERROR;
4341 /* The hardware addresses aren't counted as part of the payload, so
4342 * we have to subtract the 12 bytes for the addresses off */
4343 payloadLen = cpu_to_le16(len + miclen);
4344 bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
4345 bap_write(ai, (__le16*)pPacket, sizeof(etherHead), BAP1);
4347 bap_write(ai, (__le16*)&pMic, miclen, BAP1);
4348 bap_write(ai, (__le16*)(pPacket + sizeof(etherHead)), len, BAP1);
4349 // issue the transmit command
4350 memset( &cmd, 0, sizeof( cmd ) );
4351 cmd.cmd = CMD_TRANSMIT;
4353 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
4354 if ( (rsp.status & 0xFF00) != 0) return ERROR;
4358 static int transmit_802_11_packet(struct airo_info *ai, int len, char *pPacket)
4360 __le16 fc, payloadLen;
4364 static u8 tail[(30-10) + 2 + 6] = {[30-10] = 6};
4365 /* padding of header to full size + le16 gaplen (6) + gaplen bytes */
4369 fc = *(__le16*)pPacket;
4370 hdrlen = header_len(fc);
4373 airo_print_warn(ai->dev->name, "Short packet %d", len);
4377 /* packet is 802.11 header + payload
4378 * write the payload length and dst/src/payload */
4379 if (bap_setup(ai, txFid, 6, BAP1) != SUCCESS) return ERROR;
4380 /* The 802.11 header aren't counted as part of the payload, so
4381 * we have to subtract the header bytes off */
4382 payloadLen = cpu_to_le16(len-hdrlen);
4383 bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
4384 if (bap_setup(ai, txFid, 0x0014, BAP1) != SUCCESS) return ERROR;
4385 bap_write(ai, (__le16 *)pPacket, hdrlen, BAP1);
4386 bap_write(ai, (__le16 *)(tail + (hdrlen - 10)), 38 - hdrlen, BAP1);
4388 bap_write(ai, (__le16 *)(pPacket + hdrlen), len - hdrlen, BAP1);
4389 // issue the transmit command
4390 memset( &cmd, 0, sizeof( cmd ) );
4391 cmd.cmd = CMD_TRANSMIT;
4393 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
4394 if ( (rsp.status & 0xFF00) != 0) return ERROR;
4399 * This is the proc_fs routines. It is a bit messier than I would
4400 * like! Feel free to clean it up!
4403 static ssize_t proc_read( struct file *file,
4404 char __user *buffer,
4408 static ssize_t proc_write( struct file *file,
4409 const char __user *buffer,
4412 static int proc_close( struct inode *inode, struct file *file );
4414 static int proc_stats_open( struct inode *inode, struct file *file );
4415 static int proc_statsdelta_open( struct inode *inode, struct file *file );
4416 static int proc_status_open( struct inode *inode, struct file *file );
4417 static int proc_SSID_open( struct inode *inode, struct file *file );
4418 static int proc_APList_open( struct inode *inode, struct file *file );
4419 static int proc_BSSList_open( struct inode *inode, struct file *file );
4420 static int proc_config_open( struct inode *inode, struct file *file );
4421 static int proc_wepkey_open( struct inode *inode, struct file *file );
4423 static const struct file_operations proc_statsdelta_ops = {
4424 .owner = THIS_MODULE,
4426 .open = proc_statsdelta_open,
4427 .release = proc_close,
4428 .llseek = default_llseek,
4431 static const struct file_operations proc_stats_ops = {
4432 .owner = THIS_MODULE,
4434 .open = proc_stats_open,
4435 .release = proc_close,
4436 .llseek = default_llseek,
4439 static const struct file_operations proc_status_ops = {
4440 .owner = THIS_MODULE,
4442 .open = proc_status_open,
4443 .release = proc_close,
4444 .llseek = default_llseek,
4447 static const struct file_operations proc_SSID_ops = {
4448 .owner = THIS_MODULE,
4450 .write = proc_write,
4451 .open = proc_SSID_open,
4452 .release = proc_close,
4453 .llseek = default_llseek,
4456 static const struct file_operations proc_BSSList_ops = {
4457 .owner = THIS_MODULE,
4459 .write = proc_write,
4460 .open = proc_BSSList_open,
4461 .release = proc_close,
4462 .llseek = default_llseek,
4465 static const struct file_operations proc_APList_ops = {
4466 .owner = THIS_MODULE,
4468 .write = proc_write,
4469 .open = proc_APList_open,
4470 .release = proc_close,
4471 .llseek = default_llseek,
4474 static const struct file_operations proc_config_ops = {
4475 .owner = THIS_MODULE,
4477 .write = proc_write,
4478 .open = proc_config_open,
4479 .release = proc_close,
4480 .llseek = default_llseek,
4483 static const struct file_operations proc_wepkey_ops = {
4484 .owner = THIS_MODULE,
4486 .write = proc_write,
4487 .open = proc_wepkey_open,
4488 .release = proc_close,
4489 .llseek = default_llseek,
4492 static struct proc_dir_entry *airo_entry;
4501 void (*on_close) (struct inode *, struct file *);
4504 static int setup_proc_entry( struct net_device *dev,
4505 struct airo_info *apriv ) {
4506 struct proc_dir_entry *entry;
4508 /* First setup the device directory */
4509 strcpy(apriv->proc_name,dev->name);
4510 apriv->proc_entry = proc_mkdir_mode(apriv->proc_name, airo_perm,
4512 if (!apriv->proc_entry)
4514 proc_set_user(apriv->proc_entry, proc_kuid, proc_kgid);
4516 /* Setup the StatsDelta */
4517 entry = proc_create_data("StatsDelta", 0444 & proc_perm,
4518 apriv->proc_entry, &proc_statsdelta_ops, dev);
4521 proc_set_user(entry, proc_kuid, proc_kgid);
4523 /* Setup the Stats */
4524 entry = proc_create_data("Stats", 0444 & proc_perm,
4525 apriv->proc_entry, &proc_stats_ops, dev);
4528 proc_set_user(entry, proc_kuid, proc_kgid);
4530 /* Setup the Status */
4531 entry = proc_create_data("Status", 0444 & proc_perm,
4532 apriv->proc_entry, &proc_status_ops, dev);
4535 proc_set_user(entry, proc_kuid, proc_kgid);
4537 /* Setup the Config */
4538 entry = proc_create_data("Config", proc_perm,
4539 apriv->proc_entry, &proc_config_ops, dev);
4542 proc_set_user(entry, proc_kuid, proc_kgid);
4544 /* Setup the SSID */
4545 entry = proc_create_data("SSID", proc_perm,
4546 apriv->proc_entry, &proc_SSID_ops, dev);
4549 proc_set_user(entry, proc_kuid, proc_kgid);
4551 /* Setup the APList */
4552 entry = proc_create_data("APList", proc_perm,
4553 apriv->proc_entry, &proc_APList_ops, dev);
4556 proc_set_user(entry, proc_kuid, proc_kgid);
4558 /* Setup the BSSList */
4559 entry = proc_create_data("BSSList", proc_perm,
4560 apriv->proc_entry, &proc_BSSList_ops, dev);
4563 proc_set_user(entry, proc_kuid, proc_kgid);
4565 /* Setup the WepKey */
4566 entry = proc_create_data("WepKey", proc_perm,
4567 apriv->proc_entry, &proc_wepkey_ops, dev);
4570 proc_set_user(entry, proc_kuid, proc_kgid);
4574 remove_proc_subtree(apriv->proc_name, airo_entry);
4578 static int takedown_proc_entry( struct net_device *dev,
4579 struct airo_info *apriv )
4581 remove_proc_subtree(apriv->proc_name, airo_entry);
4586 * What we want from the proc_fs is to be able to efficiently read
4587 * and write the configuration. To do this, we want to read the
4588 * configuration when the file is opened and write it when the file is
4589 * closed. So basically we allocate a read buffer at open and fill it
4590 * with data, and allocate a write buffer and read it at close.
4594 * The read routine is generic, it relies on the preallocated rbuffer
4595 * to supply the data.
4597 static ssize_t proc_read( struct file *file,
4598 char __user *buffer,
4602 struct proc_data *priv = file->private_data;
4607 return simple_read_from_buffer(buffer, len, offset, priv->rbuffer,
4612 * The write routine is generic, it fills in a preallocated rbuffer
4613 * to supply the data.
4615 static ssize_t proc_write( struct file *file,
4616 const char __user *buffer,
4621 struct proc_data *priv = file->private_data;
4626 ret = simple_write_to_buffer(priv->wbuffer, priv->maxwritelen, offset,
4629 priv->writelen = max_t(int, priv->writelen, *offset);
4634 static int proc_status_open(struct inode *inode, struct file *file)
4636 struct proc_data *data;
4637 struct net_device *dev = PDE_DATA(inode);
4638 struct airo_info *apriv = dev->ml_priv;
4639 CapabilityRid cap_rid;
4640 StatusRid status_rid;
4644 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4646 data = file->private_data;
4647 if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
4648 kfree (file->private_data);
4652 readStatusRid(apriv, &status_rid, 1);
4653 readCapabilityRid(apriv, &cap_rid, 1);
4655 mode = le16_to_cpu(status_rid.mode);
4657 i = sprintf(data->rbuffer, "Status: %s%s%s%s%s%s%s%s%s\n",
4658 mode & 1 ? "CFG ": "",
4659 mode & 2 ? "ACT ": "",
4660 mode & 0x10 ? "SYN ": "",
4661 mode & 0x20 ? "LNK ": "",
4662 mode & 0x40 ? "LEAP ": "",
4663 mode & 0x80 ? "PRIV ": "",
4664 mode & 0x100 ? "KEY ": "",
4665 mode & 0x200 ? "WEP ": "",
4666 mode & 0x8000 ? "ERR ": "");
4667 sprintf( data->rbuffer+i, "Mode: %x\n"
4668 "Signal Strength: %d\n"
4669 "Signal Quality: %d\n"
4674 "Driver Version: %s\n"
4675 "Device: %s\nManufacturer: %s\nFirmware Version: %s\n"
4676 "Radio type: %x\nCountry: %x\nHardware Version: %x\n"
4677 "Software Version: %x\nSoftware Subversion: %x\n"
4678 "Boot block version: %x\n",
4679 le16_to_cpu(status_rid.mode),
4680 le16_to_cpu(status_rid.normalizedSignalStrength),
4681 le16_to_cpu(status_rid.signalQuality),
4682 le16_to_cpu(status_rid.SSIDlen),
4685 le16_to_cpu(status_rid.channel),
4686 le16_to_cpu(status_rid.currentXmitRate) / 2,
4691 le16_to_cpu(cap_rid.radioType),
4692 le16_to_cpu(cap_rid.country),
4693 le16_to_cpu(cap_rid.hardVer),
4694 le16_to_cpu(cap_rid.softVer),
4695 le16_to_cpu(cap_rid.softSubVer),
4696 le16_to_cpu(cap_rid.bootBlockVer));
4697 data->readlen = strlen( data->rbuffer );
4701 static int proc_stats_rid_open(struct inode*, struct file*, u16);
4702 static int proc_statsdelta_open( struct inode *inode,
4703 struct file *file ) {
4704 if (file->f_mode&FMODE_WRITE) {
4705 return proc_stats_rid_open(inode, file, RID_STATSDELTACLEAR);
4707 return proc_stats_rid_open(inode, file, RID_STATSDELTA);
4710 static int proc_stats_open( struct inode *inode, struct file *file ) {
4711 return proc_stats_rid_open(inode, file, RID_STATS);
4714 static int proc_stats_rid_open( struct inode *inode,
4718 struct proc_data *data;
4719 struct net_device *dev = PDE_DATA(inode);
4720 struct airo_info *apriv = dev->ml_priv;
4723 __le32 *vals = stats.vals;
4726 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4728 data = file->private_data;
4729 if ((data->rbuffer = kmalloc( 4096, GFP_KERNEL )) == NULL) {
4730 kfree (file->private_data);
4734 readStatsRid(apriv, &stats, rid, 1);
4735 len = le16_to_cpu(stats.len);
4738 for(i=0; statsLabels[i]!=(char *)-1 && i*4<len; i++) {
4739 if (!statsLabels[i]) continue;
4740 if (j+strlen(statsLabels[i])+16>4096) {
4741 airo_print_warn(apriv->dev->name,
4742 "Potentially disastrous buffer overflow averted!");
4745 j+=sprintf(data->rbuffer+j, "%s: %u\n", statsLabels[i],
4746 le32_to_cpu(vals[i]));
4749 airo_print_warn(apriv->dev->name, "Got a short rid");
4755 static int get_dec_u16( char *buffer, int *start, int limit ) {
4758 for (value = 0; *start < limit && buffer[*start] >= '0' &&
4759 buffer[*start] <= '9'; (*start)++) {
4762 value += buffer[*start] - '0';
4764 if ( !valid ) return -1;
4768 static int airo_config_commit(struct net_device *dev,
4769 struct iw_request_info *info, void *zwrq,
4772 static inline int sniffing_mode(struct airo_info *ai)
4774 return (le16_to_cpu(ai->config.rmode) & le16_to_cpu(RXMODE_MASK)) >=
4775 le16_to_cpu(RXMODE_RFMON);
4778 static void proc_config_on_close(struct inode *inode, struct file *file)
4780 struct proc_data *data = file->private_data;
4781 struct net_device *dev = PDE_DATA(inode);
4782 struct airo_info *ai = dev->ml_priv;
4785 if ( !data->writelen ) return;
4787 readConfigRid(ai, 1);
4788 set_bit (FLAG_COMMIT, &ai->flags);
4790 line = data->wbuffer;
4792 /*** Mode processing */
4793 if ( !strncmp( line, "Mode: ", 6 ) ) {
4795 if (sniffing_mode(ai))
4796 set_bit (FLAG_RESET, &ai->flags);
4797 ai->config.rmode &= ~RXMODE_FULL_MASK;
4798 clear_bit (FLAG_802_11, &ai->flags);
4799 ai->config.opmode &= ~MODE_CFG_MASK;
4800 ai->config.scanMode = SCANMODE_ACTIVE;
4801 if ( line[0] == 'a' ) {
4802 ai->config.opmode |= MODE_STA_IBSS;
4804 ai->config.opmode |= MODE_STA_ESS;
4805 if ( line[0] == 'r' ) {
4806 ai->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
4807 ai->config.scanMode = SCANMODE_PASSIVE;
4808 set_bit (FLAG_802_11, &ai->flags);
4809 } else if ( line[0] == 'y' ) {
4810 ai->config.rmode |= RXMODE_RFMON_ANYBSS | RXMODE_DISABLE_802_3_HEADER;
4811 ai->config.scanMode = SCANMODE_PASSIVE;
4812 set_bit (FLAG_802_11, &ai->flags);
4813 } else if ( line[0] == 'l' )
4814 ai->config.rmode |= RXMODE_LANMON;
4816 set_bit (FLAG_COMMIT, &ai->flags);
4819 /*** Radio status */
4820 else if (!strncmp(line,"Radio: ", 7)) {
4822 if (!strncmp(line,"off",3)) {
4823 set_bit (FLAG_RADIO_OFF, &ai->flags);
4825 clear_bit (FLAG_RADIO_OFF, &ai->flags);
4828 /*** NodeName processing */
4829 else if ( !strncmp( line, "NodeName: ", 10 ) ) {
4833 memset( ai->config.nodeName, 0, 16 );
4834 /* Do the name, assume a space between the mode and node name */
4835 for( j = 0; j < 16 && line[j] != '\n'; j++ ) {
4836 ai->config.nodeName[j] = line[j];
4838 set_bit (FLAG_COMMIT, &ai->flags);
4841 /*** PowerMode processing */
4842 else if ( !strncmp( line, "PowerMode: ", 11 ) ) {
4844 if ( !strncmp( line, "PSPCAM", 6 ) ) {
4845 ai->config.powerSaveMode = POWERSAVE_PSPCAM;
4846 set_bit (FLAG_COMMIT, &ai->flags);
4847 } else if ( !strncmp( line, "PSP", 3 ) ) {
4848 ai->config.powerSaveMode = POWERSAVE_PSP;
4849 set_bit (FLAG_COMMIT, &ai->flags);
4851 ai->config.powerSaveMode = POWERSAVE_CAM;
4852 set_bit (FLAG_COMMIT, &ai->flags);
4854 } else if ( !strncmp( line, "DataRates: ", 11 ) ) {
4855 int v, i = 0, k = 0; /* i is index into line,
4856 k is index to rates */
4859 while((v = get_dec_u16(line, &i, 3))!=-1) {
4860 ai->config.rates[k++] = (u8)v;
4864 set_bit (FLAG_COMMIT, &ai->flags);
4865 } else if ( !strncmp( line, "Channel: ", 9 ) ) {
4868 v = get_dec_u16(line, &i, i+3);
4870 ai->config.channelSet = cpu_to_le16(v);
4871 set_bit (FLAG_COMMIT, &ai->flags);
4873 } else if ( !strncmp( line, "XmitPower: ", 11 ) ) {
4876 v = get_dec_u16(line, &i, i+3);
4878 ai->config.txPower = cpu_to_le16(v);
4879 set_bit (FLAG_COMMIT, &ai->flags);
4881 } else if ( !strncmp( line, "WEP: ", 5 ) ) {
4885 set_auth_type(ai, AUTH_SHAREDKEY);
4888 set_auth_type(ai, AUTH_ENCRYPT);
4891 set_auth_type(ai, AUTH_OPEN);
4894 set_bit (FLAG_COMMIT, &ai->flags);
4895 } else if ( !strncmp( line, "LongRetryLimit: ", 16 ) ) {
4899 v = get_dec_u16(line, &i, 3);
4900 v = (v<0) ? 0 : ((v>255) ? 255 : v);
4901 ai->config.longRetryLimit = cpu_to_le16(v);
4902 set_bit (FLAG_COMMIT, &ai->flags);
4903 } else if ( !strncmp( line, "ShortRetryLimit: ", 17 ) ) {
4907 v = get_dec_u16(line, &i, 3);
4908 v = (v<0) ? 0 : ((v>255) ? 255 : v);
4909 ai->config.shortRetryLimit = cpu_to_le16(v);
4910 set_bit (FLAG_COMMIT, &ai->flags);
4911 } else if ( !strncmp( line, "RTSThreshold: ", 14 ) ) {
4915 v = get_dec_u16(line, &i, 4);
4916 v = (v<0) ? 0 : ((v>AIRO_DEF_MTU) ? AIRO_DEF_MTU : v);
4917 ai->config.rtsThres = cpu_to_le16(v);
4918 set_bit (FLAG_COMMIT, &ai->flags);
4919 } else if ( !strncmp( line, "TXMSDULifetime: ", 16 ) ) {
4923 v = get_dec_u16(line, &i, 5);
4925 ai->config.txLifetime = cpu_to_le16(v);
4926 set_bit (FLAG_COMMIT, &ai->flags);
4927 } else if ( !strncmp( line, "RXMSDULifetime: ", 16 ) ) {
4931 v = get_dec_u16(line, &i, 5);
4933 ai->config.rxLifetime = cpu_to_le16(v);
4934 set_bit (FLAG_COMMIT, &ai->flags);
4935 } else if ( !strncmp( line, "TXDiversity: ", 13 ) ) {
4936 ai->config.txDiversity =
4937 (line[13]=='l') ? 1 :
4938 ((line[13]=='r')? 2: 3);
4939 set_bit (FLAG_COMMIT, &ai->flags);
4940 } else if ( !strncmp( line, "RXDiversity: ", 13 ) ) {
4941 ai->config.rxDiversity =
4942 (line[13]=='l') ? 1 :
4943 ((line[13]=='r')? 2: 3);
4944 set_bit (FLAG_COMMIT, &ai->flags);
4945 } else if ( !strncmp( line, "FragThreshold: ", 15 ) ) {
4949 v = get_dec_u16(line, &i, 4);
4950 v = (v<256) ? 256 : ((v>AIRO_DEF_MTU) ? AIRO_DEF_MTU : v);
4951 v = v & 0xfffe; /* Make sure its even */
4952 ai->config.fragThresh = cpu_to_le16(v);
4953 set_bit (FLAG_COMMIT, &ai->flags);
4954 } else if (!strncmp(line, "Modulation: ", 12)) {
4957 case 'd': ai->config.modulation=MOD_DEFAULT; set_bit(FLAG_COMMIT, &ai->flags); break;
4958 case 'c': ai->config.modulation=MOD_CCK; set_bit(FLAG_COMMIT, &ai->flags); break;
4959 case 'm': ai->config.modulation=MOD_MOK; set_bit(FLAG_COMMIT, &ai->flags); break;
4960 default: airo_print_warn(ai->dev->name, "Unknown modulation");
4962 } else if (!strncmp(line, "Preamble: ", 10)) {
4965 case 'a': ai->config.preamble=PREAMBLE_AUTO; set_bit(FLAG_COMMIT, &ai->flags); break;
4966 case 'l': ai->config.preamble=PREAMBLE_LONG; set_bit(FLAG_COMMIT, &ai->flags); break;
4967 case 's': ai->config.preamble=PREAMBLE_SHORT; set_bit(FLAG_COMMIT, &ai->flags); break;
4968 default: airo_print_warn(ai->dev->name, "Unknown preamble");
4971 airo_print_warn(ai->dev->name, "Couldn't figure out %s", line);
4973 while( line[0] && line[0] != '\n' ) line++;
4974 if ( line[0] ) line++;
4976 airo_config_commit(dev, NULL, NULL, NULL);
4979 static const char *get_rmode(__le16 mode)
4981 switch(mode & RXMODE_MASK) {
4982 case RXMODE_RFMON: return "rfmon";
4983 case RXMODE_RFMON_ANYBSS: return "yna (any) bss rfmon";
4984 case RXMODE_LANMON: return "lanmon";
4989 static int proc_config_open(struct inode *inode, struct file *file)
4991 struct proc_data *data;
4992 struct net_device *dev = PDE_DATA(inode);
4993 struct airo_info *ai = dev->ml_priv;
4997 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4999 data = file->private_data;
5000 if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
5001 kfree (file->private_data);
5004 if ((data->wbuffer = kzalloc( 2048, GFP_KERNEL )) == NULL) {
5005 kfree (data->rbuffer);
5006 kfree (file->private_data);
5009 data->maxwritelen = 2048;
5010 data->on_close = proc_config_on_close;
5012 readConfigRid(ai, 1);
5014 mode = ai->config.opmode & MODE_CFG_MASK;
5015 i = sprintf( data->rbuffer,
5020 "DataRates: %d %d %d %d %d %d %d %d\n"
5023 mode == MODE_STA_IBSS ? "adhoc" :
5024 mode == MODE_STA_ESS ? get_rmode(ai->config.rmode):
5025 mode == MODE_AP ? "AP" :
5026 mode == MODE_AP_RPTR ? "AP RPTR" : "Error",
5027 test_bit(FLAG_RADIO_OFF, &ai->flags) ? "off" : "on",
5028 ai->config.nodeName,
5029 ai->config.powerSaveMode == POWERSAVE_CAM ? "CAM" :
5030 ai->config.powerSaveMode == POWERSAVE_PSP ? "PSP" :
5031 ai->config.powerSaveMode == POWERSAVE_PSPCAM ? "PSPCAM" :
5033 (int)ai->config.rates[0],
5034 (int)ai->config.rates[1],
5035 (int)ai->config.rates[2],
5036 (int)ai->config.rates[3],
5037 (int)ai->config.rates[4],
5038 (int)ai->config.rates[5],
5039 (int)ai->config.rates[6],
5040 (int)ai->config.rates[7],
5041 le16_to_cpu(ai->config.channelSet),
5042 le16_to_cpu(ai->config.txPower)
5044 sprintf( data->rbuffer + i,
5045 "LongRetryLimit: %d\n"
5046 "ShortRetryLimit: %d\n"
5047 "RTSThreshold: %d\n"
5048 "TXMSDULifetime: %d\n"
5049 "RXMSDULifetime: %d\n"
5052 "FragThreshold: %d\n"
5056 le16_to_cpu(ai->config.longRetryLimit),
5057 le16_to_cpu(ai->config.shortRetryLimit),
5058 le16_to_cpu(ai->config.rtsThres),
5059 le16_to_cpu(ai->config.txLifetime),
5060 le16_to_cpu(ai->config.rxLifetime),
5061 ai->config.txDiversity == 1 ? "left" :
5062 ai->config.txDiversity == 2 ? "right" : "both",
5063 ai->config.rxDiversity == 1 ? "left" :
5064 ai->config.rxDiversity == 2 ? "right" : "both",
5065 le16_to_cpu(ai->config.fragThresh),
5066 ai->config.authType == AUTH_ENCRYPT ? "encrypt" :
5067 ai->config.authType == AUTH_SHAREDKEY ? "shared" : "open",
5068 ai->config.modulation == MOD_DEFAULT ? "default" :
5069 ai->config.modulation == MOD_CCK ? "cck" :
5070 ai->config.modulation == MOD_MOK ? "mok" : "error",
5071 ai->config.preamble == PREAMBLE_AUTO ? "auto" :
5072 ai->config.preamble == PREAMBLE_LONG ? "long" :
5073 ai->config.preamble == PREAMBLE_SHORT ? "short" : "error"
5075 data->readlen = strlen( data->rbuffer );
5079 static void proc_SSID_on_close(struct inode *inode, struct file *file)
5081 struct proc_data *data = file->private_data;
5082 struct net_device *dev = PDE_DATA(inode);
5083 struct airo_info *ai = dev->ml_priv;
5086 char *p = data->wbuffer;
5087 char *end = p + data->writelen;
5089 if (!data->writelen)
5092 *end = '\n'; /* sentinel; we have space for it */
5094 memset(&SSID_rid, 0, sizeof(SSID_rid));
5096 for (i = 0; i < 3 && p < end; i++) {
5098 /* copy up to 32 characters from this line */
5099 while (*p != '\n' && j < 32)
5100 SSID_rid.ssids[i].ssid[j++] = *p++;
5103 SSID_rid.ssids[i].len = cpu_to_le16(j);
5104 /* skip to the beginning of the next line */
5105 while (*p++ != '\n')
5109 SSID_rid.len = cpu_to_le16(sizeof(SSID_rid));
5111 writeSsidRid(ai, &SSID_rid, 1);
5115 static void proc_APList_on_close( struct inode *inode, struct file *file ) {
5116 struct proc_data *data = file->private_data;
5117 struct net_device *dev = PDE_DATA(inode);
5118 struct airo_info *ai = dev->ml_priv;
5119 APListRid *APList_rid = &ai->APList;
5122 if ( !data->writelen ) return;
5124 memset(APList_rid, 0, sizeof(*APList_rid));
5125 APList_rid->len = cpu_to_le16(sizeof(*APList_rid));
5127 for (i = 0; i < 4 && data->writelen >= (i + 1) * 6 * 3; i++)
5128 mac_pton(data->wbuffer + i * 6 * 3, APList_rid->ap[i]);
5131 writeAPListRid(ai, APList_rid, 1);
5135 /* This function wraps PC4500_writerid with a MAC disable */
5136 static int do_writerid( struct airo_info *ai, u16 rid, const void *rid_data,
5137 int len, int dummy ) {
5141 rc = PC4500_writerid(ai, rid, rid_data, len, 1);
5146 /* Returns the WEP key at the specified index, or -1 if that key does
5147 * not exist. The buffer is assumed to be at least 16 bytes in length.
5149 static int get_wep_key(struct airo_info *ai, u16 index, char *buf, u16 buflen)
5155 rc = readWepKeyRid(ai, &wkr, 1, 1);
5159 lastindex = wkr.kindex;
5160 if (le16_to_cpu(wkr.kindex) == index) {
5161 int klen = min_t(int, buflen, le16_to_cpu(wkr.klen));
5162 memcpy(buf, wkr.key, klen);
5165 rc = readWepKeyRid(ai, &wkr, 0, 1);
5168 } while (lastindex != wkr.kindex);
5172 static int get_wep_tx_idx(struct airo_info *ai)
5178 rc = readWepKeyRid(ai, &wkr, 1, 1);
5182 lastindex = wkr.kindex;
5183 if (wkr.kindex == cpu_to_le16(0xffff))
5185 rc = readWepKeyRid(ai, &wkr, 0, 1);
5188 } while (lastindex != wkr.kindex);
5192 static int set_wep_key(struct airo_info *ai, u16 index, const char *key,
5193 u16 keylen, int perm, int lock)
5195 static const unsigned char macaddr[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
5199 if (WARN_ON(keylen == 0))
5202 memset(&wkr, 0, sizeof(wkr));
5203 wkr.len = cpu_to_le16(sizeof(wkr));
5204 wkr.kindex = cpu_to_le16(index);
5205 wkr.klen = cpu_to_le16(keylen);
5206 memcpy(wkr.key, key, keylen);
5207 memcpy(wkr.mac, macaddr, ETH_ALEN);
5209 if (perm) disable_MAC(ai, lock);
5210 rc = writeWepKeyRid(ai, &wkr, perm, lock);
5211 if (perm) enable_MAC(ai, lock);
5215 static int set_wep_tx_idx(struct airo_info *ai, u16 index, int perm, int lock)
5220 memset(&wkr, 0, sizeof(wkr));
5221 wkr.len = cpu_to_le16(sizeof(wkr));
5222 wkr.kindex = cpu_to_le16(0xffff);
5223 wkr.mac[0] = (char)index;
5226 ai->defindex = (char)index;
5227 disable_MAC(ai, lock);
5230 rc = writeWepKeyRid(ai, &wkr, perm, lock);
5233 enable_MAC(ai, lock);
5237 static void proc_wepkey_on_close( struct inode *inode, struct file *file ) {
5238 struct proc_data *data;
5239 struct net_device *dev = PDE_DATA(inode);
5240 struct airo_info *ai = dev->ml_priv;
5246 memset(key, 0, sizeof(key));
5248 data = file->private_data;
5249 if ( !data->writelen ) return;
5251 if (data->wbuffer[0] >= '0' && data->wbuffer[0] <= '3' &&
5252 (data->wbuffer[1] == ' ' || data->wbuffer[1] == '\n')) {
5253 index = data->wbuffer[0] - '0';
5254 if (data->wbuffer[1] == '\n') {
5255 rc = set_wep_tx_idx(ai, index, 1, 1);
5257 airo_print_err(ai->dev->name, "failed to set "
5258 "WEP transmit index to %d: %d.",
5265 airo_print_err(ai->dev->name, "WepKey passed invalid key index");
5269 for( i = 0; i < 16*3 && data->wbuffer[i+j]; i++ ) {
5272 key[i/3] = hex_to_bin(data->wbuffer[i+j])<<4;
5275 key[i/3] |= hex_to_bin(data->wbuffer[i+j]);
5280 rc = set_wep_key(ai, index, key, i/3, 1, 1);
5282 airo_print_err(ai->dev->name, "failed to set WEP key at index "
5283 "%d: %d.", index, rc);
5287 static int proc_wepkey_open( struct inode *inode, struct file *file )
5289 struct proc_data *data;
5290 struct net_device *dev = PDE_DATA(inode);
5291 struct airo_info *ai = dev->ml_priv;
5298 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5300 memset(&wkr, 0, sizeof(wkr));
5301 data = file->private_data;
5302 if ((data->rbuffer = kzalloc( 180, GFP_KERNEL )) == NULL) {
5303 kfree (file->private_data);
5307 data->maxwritelen = 80;
5308 if ((data->wbuffer = kzalloc( 80, GFP_KERNEL )) == NULL) {
5309 kfree (data->rbuffer);
5310 kfree (file->private_data);
5313 data->on_close = proc_wepkey_on_close;
5315 ptr = data->rbuffer;
5316 strcpy(ptr, "No wep keys\n");
5317 rc = readWepKeyRid(ai, &wkr, 1, 1);
5318 if (rc == SUCCESS) do {
5319 lastindex = wkr.kindex;
5320 if (wkr.kindex == cpu_to_le16(0xffff)) {
5321 j += sprintf(ptr+j, "Tx key = %d\n",
5324 j += sprintf(ptr+j, "Key %d set with length = %d\n",
5325 le16_to_cpu(wkr.kindex),
5326 le16_to_cpu(wkr.klen));
5328 readWepKeyRid(ai, &wkr, 0, 1);
5329 } while((lastindex != wkr.kindex) && (j < 180-30));
5331 data->readlen = strlen( data->rbuffer );
5335 static int proc_SSID_open(struct inode *inode, struct file *file)
5337 struct proc_data *data;
5338 struct net_device *dev = PDE_DATA(inode);
5339 struct airo_info *ai = dev->ml_priv;
5344 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5346 data = file->private_data;
5347 if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
5348 kfree (file->private_data);
5352 data->maxwritelen = 33*3;
5353 /* allocate maxwritelen + 1; we'll want a sentinel */
5354 if ((data->wbuffer = kzalloc(33*3 + 1, GFP_KERNEL)) == NULL) {
5355 kfree (data->rbuffer);
5356 kfree (file->private_data);
5359 data->on_close = proc_SSID_on_close;
5361 readSsidRid(ai, &SSID_rid);
5362 ptr = data->rbuffer;
5363 for (i = 0; i < 3; i++) {
5365 size_t len = le16_to_cpu(SSID_rid.ssids[i].len);
5370 for (j = 0; j < len && SSID_rid.ssids[i].ssid[j]; j++)
5371 *ptr++ = SSID_rid.ssids[i].ssid[j];
5375 data->readlen = strlen( data->rbuffer );
5379 static int proc_APList_open( struct inode *inode, struct file *file ) {
5380 struct proc_data *data;
5381 struct net_device *dev = PDE_DATA(inode);
5382 struct airo_info *ai = dev->ml_priv;
5385 APListRid *APList_rid = &ai->APList;
5387 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5389 data = file->private_data;
5390 if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
5391 kfree (file->private_data);
5395 data->maxwritelen = 4*6*3;
5396 if ((data->wbuffer = kzalloc( data->maxwritelen, GFP_KERNEL )) == NULL) {
5397 kfree (data->rbuffer);
5398 kfree (file->private_data);
5401 data->on_close = proc_APList_on_close;
5403 ptr = data->rbuffer;
5404 for( i = 0; i < 4; i++ ) {
5405 // We end when we find a zero MAC
5406 if ( !*(int*)APList_rid->ap[i] &&
5407 !*(int*)&APList_rid->ap[i][2]) break;
5408 ptr += sprintf(ptr, "%pM\n", APList_rid->ap[i]);
5410 if (i==0) ptr += sprintf(ptr, "Not using specific APs\n");
5413 data->readlen = strlen( data->rbuffer );
5417 static int proc_BSSList_open( struct inode *inode, struct file *file ) {
5418 struct proc_data *data;
5419 struct net_device *dev = PDE_DATA(inode);
5420 struct airo_info *ai = dev->ml_priv;
5422 BSSListRid BSSList_rid;
5424 /* If doLoseSync is not 1, we won't do a Lose Sync */
5425 int doLoseSync = -1;
5427 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5429 data = file->private_data;
5430 if ((data->rbuffer = kmalloc( 1024, GFP_KERNEL )) == NULL) {
5431 kfree (file->private_data);
5435 data->maxwritelen = 0;
5436 data->wbuffer = NULL;
5437 data->on_close = NULL;
5439 if (file->f_mode & FMODE_WRITE) {
5440 if (!(file->f_mode & FMODE_READ)) {
5444 if (ai->flags & FLAG_RADIO_MASK) {
5445 kfree(data->rbuffer);
5446 kfree(file->private_data);
5449 memset(&cmd, 0, sizeof(cmd));
5450 cmd.cmd=CMD_LISTBSS;
5451 if (down_interruptible(&ai->sem)) {
5452 kfree(data->rbuffer);
5453 kfree(file->private_data);
5454 return -ERESTARTSYS;
5456 issuecommand(ai, &cmd, &rsp);
5463 ptr = data->rbuffer;
5464 /* There is a race condition here if there are concurrent opens.
5465 Since it is a rare condition, we'll just live with it, otherwise
5466 we have to add a spin lock... */
5467 rc = readBSSListRid(ai, doLoseSync, &BSSList_rid);
5468 while(rc == 0 && BSSList_rid.index != cpu_to_le16(0xffff)) {
5469 ptr += sprintf(ptr, "%pM %.*s rssi = %d",
5471 (int)BSSList_rid.ssidLen,
5473 le16_to_cpu(BSSList_rid.dBm));
5474 ptr += sprintf(ptr, " channel = %d %s %s %s %s\n",
5475 le16_to_cpu(BSSList_rid.dsChannel),
5476 BSSList_rid.cap & CAP_ESS ? "ESS" : "",
5477 BSSList_rid.cap & CAP_IBSS ? "adhoc" : "",
5478 BSSList_rid.cap & CAP_PRIVACY ? "wep" : "",
5479 BSSList_rid.cap & CAP_SHORTHDR ? "shorthdr" : "");
5480 rc = readBSSListRid(ai, 0, &BSSList_rid);
5483 data->readlen = strlen( data->rbuffer );
5487 static int proc_close( struct inode *inode, struct file *file )
5489 struct proc_data *data = file->private_data;
5491 if (data->on_close != NULL)
5492 data->on_close(inode, file);
5493 kfree(data->rbuffer);
5494 kfree(data->wbuffer);
5499 /* Since the card doesn't automatically switch to the right WEP mode,
5500 we will make it do it. If the card isn't associated, every secs we
5501 will switch WEP modes to see if that will help. If the card is
5502 associated we will check every minute to see if anything has
5504 static void timer_func( struct net_device *dev ) {
5505 struct airo_info *apriv = dev->ml_priv;
5507 /* We don't have a link so try changing the authtype */
5508 readConfigRid(apriv, 0);
5509 disable_MAC(apriv, 0);
5510 switch(apriv->config.authType) {
5512 /* So drop to OPEN */
5513 apriv->config.authType = AUTH_OPEN;
5515 case AUTH_SHAREDKEY:
5516 if (apriv->keyindex < auto_wep) {
5517 set_wep_tx_idx(apriv, apriv->keyindex, 0, 0);
5518 apriv->config.authType = AUTH_SHAREDKEY;
5521 /* Drop to ENCRYPT */
5522 apriv->keyindex = 0;
5523 set_wep_tx_idx(apriv, apriv->defindex, 0, 0);
5524 apriv->config.authType = AUTH_ENCRYPT;
5527 default: /* We'll escalate to SHAREDKEY */
5528 apriv->config.authType = AUTH_SHAREDKEY;
5530 set_bit (FLAG_COMMIT, &apriv->flags);
5531 writeConfigRid(apriv, 0);
5532 enable_MAC(apriv, 0);
5535 /* Schedule check to see if the change worked */
5536 clear_bit(JOB_AUTOWEP, &apriv->jobs);
5537 apriv->expires = RUN_AT(HZ*3);
5541 static int airo_pci_probe(struct pci_dev *pdev,
5542 const struct pci_device_id *pent)
5544 struct net_device *dev;
5546 if (pci_enable_device(pdev))
5548 pci_set_master(pdev);
5550 if (pdev->device == 0x5000 || pdev->device == 0xa504)
5551 dev = _init_airo_card(pdev->irq, pdev->resource[0].start, 0, pdev, &pdev->dev);
5553 dev = _init_airo_card(pdev->irq, pdev->resource[2].start, 0, pdev, &pdev->dev);
5555 pci_disable_device(pdev);
5559 pci_set_drvdata(pdev, dev);
5563 static void airo_pci_remove(struct pci_dev *pdev)
5565 struct net_device *dev = pci_get_drvdata(pdev);
5567 airo_print_info(dev->name, "Unregistering...");
5568 stop_airo_card(dev, 1);
5569 pci_disable_device(pdev);
5572 static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state)
5574 struct net_device *dev = pci_get_drvdata(pdev);
5575 struct airo_info *ai = dev->ml_priv;
5580 ai->SSID = kmalloc(sizeof(SsidRid), GFP_KERNEL);
5583 readSsidRid(ai, ai->SSID);
5584 memset(&cmd, 0, sizeof(cmd));
5585 /* the lock will be released at the end of the resume callback */
5586 if (down_interruptible(&ai->sem))
5589 netif_device_detach(dev);
5591 cmd.cmd = HOSTSLEEP;
5592 issuecommand(ai, &cmd, &rsp);
5594 pci_enable_wake(pdev, pci_choose_state(pdev, state), 1);
5595 pci_save_state(pdev);
5596 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5600 static int airo_pci_resume(struct pci_dev *pdev)
5602 struct net_device *dev = pci_get_drvdata(pdev);
5603 struct airo_info *ai = dev->ml_priv;
5604 pci_power_t prev_state = pdev->current_state;
5606 pci_set_power_state(pdev, PCI_D0);
5607 pci_restore_state(pdev);
5608 pci_enable_wake(pdev, PCI_D0, 0);
5610 if (prev_state != PCI_D1) {
5612 mpi_init_descriptors(ai);
5613 setup_card(ai, dev->dev_addr, 0);
5614 clear_bit(FLAG_RADIO_OFF, &ai->flags);
5615 clear_bit(FLAG_PENDING_XMIT, &ai->flags);
5617 OUT4500(ai, EVACK, EV_AWAKEN);
5618 OUT4500(ai, EVACK, EV_AWAKEN);
5622 set_bit(FLAG_COMMIT, &ai->flags);
5626 writeSsidRid(ai, ai->SSID, 0);
5630 writeAPListRid(ai, &ai->APList, 0);
5631 writeConfigRid(ai, 0);
5633 ai->power = PMSG_ON;
5634 netif_device_attach(dev);
5635 netif_wake_queue(dev);
5636 enable_interrupts(ai);
5642 static int __init airo_init_module( void )
5646 proc_kuid = make_kuid(&init_user_ns, proc_uid);
5647 proc_kgid = make_kgid(&init_user_ns, proc_gid);
5648 if (!uid_valid(proc_kuid) || !gid_valid(proc_kgid))
5651 airo_entry = proc_mkdir_mode("driver/aironet", airo_perm, NULL);
5654 proc_set_user(airo_entry, proc_kuid, proc_kgid);
5656 for (i = 0; i < 4 && io[i] && irq[i]; i++) {
5657 airo_print_info("", "Trying to configure ISA adapter at irq=%d "
5658 "io=0x%x", irq[i], io[i] );
5659 if (init_airo_card( irq[i], io[i], 0, NULL ))
5664 airo_print_info("", "Probing for PCI adapters");
5665 i = pci_register_driver(&airo_driver);
5666 airo_print_info("", "Finished probing for PCI adapters");
5669 remove_proc_entry("driver/aironet", NULL);
5674 /* Always exit with success, as we are a library module
5675 * as well as a driver module
5680 static void __exit airo_cleanup_module( void )
5682 struct airo_info *ai;
5683 while(!list_empty(&airo_devices)) {
5684 ai = list_entry(airo_devices.next, struct airo_info, dev_list);
5685 airo_print_info(ai->dev->name, "Unregistering...");
5686 stop_airo_card(ai->dev, 1);
5689 pci_unregister_driver(&airo_driver);
5691 remove_proc_entry("driver/aironet", NULL);
5695 * Initial Wireless Extension code for Aironet driver by :
5696 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
5697 * Conversion to new driver API by :
5698 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
5699 * Javier also did a good amount of work here, adding some new extensions
5700 * and fixing my code. Let's just say that without him this code just
5701 * would not work at all... - Jean II
5704 static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi)
5709 return (0x100 - rssi_rid[rssi].rssidBm);
5712 static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm)
5719 for (i = 0; i < 256; i++)
5720 if (rssi_rid[i].rssidBm == dbm)
5721 return rssi_rid[i].rssipct;
5727 static int airo_get_quality (StatusRid *status_rid, CapabilityRid *cap_rid)
5732 if ((status_rid->mode & cpu_to_le16(0x3f)) != cpu_to_le16(0x3f))
5735 if (!(cap_rid->hardCap & cpu_to_le16(8)))
5738 sq = le16_to_cpu(status_rid->signalQuality);
5739 if (memcmp(cap_rid->prodName, "350", 3))
5743 quality = 0x20 - sq;
5750 quality = 0xb0 - sq;
5754 #define airo_get_max_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x20 : 0xa0)
5755 #define airo_get_avg_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x10 : 0x50);
5757 /*------------------------------------------------------------------*/
5759 * Wireless Handler : get protocol name
5761 static int airo_get_name(struct net_device *dev,
5762 struct iw_request_info *info,
5766 strcpy(cwrq, "IEEE 802.11-DS");
5770 /*------------------------------------------------------------------*/
5772 * Wireless Handler : set frequency
5774 static int airo_set_freq(struct net_device *dev,
5775 struct iw_request_info *info,
5776 struct iw_freq *fwrq,
5779 struct airo_info *local = dev->ml_priv;
5780 int rc = -EINPROGRESS; /* Call commit handler */
5782 /* If setting by frequency, convert to a channel */
5784 int f = fwrq->m / 100000;
5786 /* Hack to fall through... */
5788 fwrq->m = ieee80211_frequency_to_channel(f);
5790 /* Setting by channel number */
5791 if (fwrq->m < 0 || fwrq->m > 1000 || fwrq->e > 0)
5794 int channel = fwrq->m;
5795 /* We should do a better check than that,
5796 * based on the card capability !!! */
5797 if((channel < 1) || (channel > 14)) {
5798 airo_print_dbg(dev->name, "New channel value of %d is invalid!",
5802 readConfigRid(local, 1);
5803 /* Yes ! We can set it !!! */
5804 local->config.channelSet = cpu_to_le16(channel);
5805 set_bit (FLAG_COMMIT, &local->flags);
5811 /*------------------------------------------------------------------*/
5813 * Wireless Handler : get frequency
5815 static int airo_get_freq(struct net_device *dev,
5816 struct iw_request_info *info,
5817 struct iw_freq *fwrq,
5820 struct airo_info *local = dev->ml_priv;
5821 StatusRid status_rid; /* Card status info */
5824 readConfigRid(local, 1);
5825 if ((local->config.opmode & MODE_CFG_MASK) == MODE_STA_ESS)
5826 status_rid.channel = local->config.channelSet;
5828 readStatusRid(local, &status_rid, 1);
5830 ch = le16_to_cpu(status_rid.channel);
5831 if((ch > 0) && (ch < 15)) {
5833 ieee80211_channel_to_frequency(ch, NL80211_BAND_2GHZ);
5843 /*------------------------------------------------------------------*/
5845 * Wireless Handler : set ESSID
5847 static int airo_set_essid(struct net_device *dev,
5848 struct iw_request_info *info,
5849 struct iw_point *dwrq,
5852 struct airo_info *local = dev->ml_priv;
5853 SsidRid SSID_rid; /* SSIDs */
5855 /* Reload the list of current SSID */
5856 readSsidRid(local, &SSID_rid);
5858 /* Check if we asked for `any' */
5859 if (dwrq->flags == 0) {
5860 /* Just send an empty SSID list */
5861 memset(&SSID_rid, 0, sizeof(SSID_rid));
5863 unsigned index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
5865 /* Check the size of the string */
5866 if (dwrq->length > IW_ESSID_MAX_SIZE)
5869 /* Check if index is valid */
5870 if (index >= ARRAY_SIZE(SSID_rid.ssids))
5874 memset(SSID_rid.ssids[index].ssid, 0,
5875 sizeof(SSID_rid.ssids[index].ssid));
5876 memcpy(SSID_rid.ssids[index].ssid, extra, dwrq->length);
5877 SSID_rid.ssids[index].len = cpu_to_le16(dwrq->length);
5879 SSID_rid.len = cpu_to_le16(sizeof(SSID_rid));
5880 /* Write it to the card */
5881 disable_MAC(local, 1);
5882 writeSsidRid(local, &SSID_rid, 1);
5883 enable_MAC(local, 1);
5888 /*------------------------------------------------------------------*/
5890 * Wireless Handler : get ESSID
5892 static int airo_get_essid(struct net_device *dev,
5893 struct iw_request_info *info,
5894 struct iw_point *dwrq,
5897 struct airo_info *local = dev->ml_priv;
5898 StatusRid status_rid; /* Card status info */
5900 readStatusRid(local, &status_rid, 1);
5902 /* Note : if dwrq->flags != 0, we should
5903 * get the relevant SSID from the SSID list... */
5905 /* Get the current SSID */
5906 memcpy(extra, status_rid.SSID, le16_to_cpu(status_rid.SSIDlen));
5907 /* If none, we may want to get the one that was set */
5910 dwrq->length = le16_to_cpu(status_rid.SSIDlen);
5911 dwrq->flags = 1; /* active */
5916 /*------------------------------------------------------------------*/
5918 * Wireless Handler : set AP address
5920 static int airo_set_wap(struct net_device *dev,
5921 struct iw_request_info *info,
5922 struct sockaddr *awrq,
5925 struct airo_info *local = dev->ml_priv;
5928 APListRid *APList_rid = &local->APList;
5930 if (awrq->sa_family != ARPHRD_ETHER)
5932 else if (is_broadcast_ether_addr(awrq->sa_data) ||
5933 is_zero_ether_addr(awrq->sa_data)) {
5934 memset(&cmd, 0, sizeof(cmd));
5935 cmd.cmd=CMD_LOSE_SYNC;
5936 if (down_interruptible(&local->sem))
5937 return -ERESTARTSYS;
5938 issuecommand(local, &cmd, &rsp);
5941 memset(APList_rid, 0, sizeof(*APList_rid));
5942 APList_rid->len = cpu_to_le16(sizeof(*APList_rid));
5943 memcpy(APList_rid->ap[0], awrq->sa_data, ETH_ALEN);
5944 disable_MAC(local, 1);
5945 writeAPListRid(local, APList_rid, 1);
5946 enable_MAC(local, 1);
5951 /*------------------------------------------------------------------*/
5953 * Wireless Handler : get AP address
5955 static int airo_get_wap(struct net_device *dev,
5956 struct iw_request_info *info,
5957 struct sockaddr *awrq,
5960 struct airo_info *local = dev->ml_priv;
5961 StatusRid status_rid; /* Card status info */
5963 readStatusRid(local, &status_rid, 1);
5965 /* Tentative. This seems to work, wow, I'm lucky !!! */
5966 memcpy(awrq->sa_data, status_rid.bssid[0], ETH_ALEN);
5967 awrq->sa_family = ARPHRD_ETHER;
5972 /*------------------------------------------------------------------*/
5974 * Wireless Handler : set Nickname
5976 static int airo_set_nick(struct net_device *dev,
5977 struct iw_request_info *info,
5978 struct iw_point *dwrq,
5981 struct airo_info *local = dev->ml_priv;
5983 /* Check the size of the string */
5984 if(dwrq->length > 16) {
5987 readConfigRid(local, 1);
5988 memset(local->config.nodeName, 0, sizeof(local->config.nodeName));
5989 memcpy(local->config.nodeName, extra, dwrq->length);
5990 set_bit (FLAG_COMMIT, &local->flags);
5992 return -EINPROGRESS; /* Call commit handler */
5995 /*------------------------------------------------------------------*/
5997 * Wireless Handler : get Nickname
5999 static int airo_get_nick(struct net_device *dev,
6000 struct iw_request_info *info,
6001 struct iw_point *dwrq,
6004 struct airo_info *local = dev->ml_priv;
6006 readConfigRid(local, 1);
6007 strncpy(extra, local->config.nodeName, 16);
6009 dwrq->length = strlen(extra);
6014 /*------------------------------------------------------------------*/
6016 * Wireless Handler : set Bit-Rate
6018 static int airo_set_rate(struct net_device *dev,
6019 struct iw_request_info *info,
6020 struct iw_param *vwrq,
6023 struct airo_info *local = dev->ml_priv;
6024 CapabilityRid cap_rid; /* Card capability info */
6028 /* First : get a valid bit rate value */
6029 readCapabilityRid(local, &cap_rid, 1);
6031 /* Which type of value ? */
6032 if((vwrq->value < 8) && (vwrq->value >= 0)) {
6033 /* Setting by rate index */
6034 /* Find value in the magic rate table */
6035 brate = cap_rid.supportedRates[vwrq->value];
6037 /* Setting by frequency value */
6038 u8 normvalue = (u8) (vwrq->value/500000);
6040 /* Check if rate is valid */
6041 for(i = 0 ; i < 8 ; i++) {
6042 if(normvalue == cap_rid.supportedRates[i]) {
6048 /* -1 designed the max rate (mostly auto mode) */
6049 if(vwrq->value == -1) {
6050 /* Get the highest available rate */
6051 for(i = 0 ; i < 8 ; i++) {
6052 if(cap_rid.supportedRates[i] == 0)
6056 brate = cap_rid.supportedRates[i - 1];
6058 /* Check that it is valid */
6063 readConfigRid(local, 1);
6064 /* Now, check if we want a fixed or auto value */
6065 if(vwrq->fixed == 0) {
6066 /* Fill all the rates up to this max rate */
6067 memset(local->config.rates, 0, 8);
6068 for(i = 0 ; i < 8 ; i++) {
6069 local->config.rates[i] = cap_rid.supportedRates[i];
6070 if(local->config.rates[i] == brate)
6075 /* One rate, fixed */
6076 memset(local->config.rates, 0, 8);
6077 local->config.rates[0] = brate;
6079 set_bit (FLAG_COMMIT, &local->flags);
6081 return -EINPROGRESS; /* Call commit handler */
6084 /*------------------------------------------------------------------*/
6086 * Wireless Handler : get Bit-Rate
6088 static int airo_get_rate(struct net_device *dev,
6089 struct iw_request_info *info,
6090 struct iw_param *vwrq,
6093 struct airo_info *local = dev->ml_priv;
6094 StatusRid status_rid; /* Card status info */
6096 readStatusRid(local, &status_rid, 1);
6098 vwrq->value = le16_to_cpu(status_rid.currentXmitRate) * 500000;
6099 /* If more than one rate, set auto */
6100 readConfigRid(local, 1);
6101 vwrq->fixed = (local->config.rates[1] == 0);
6106 /*------------------------------------------------------------------*/
6108 * Wireless Handler : set RTS threshold
6110 static int airo_set_rts(struct net_device *dev,
6111 struct iw_request_info *info,
6112 struct iw_param *vwrq,
6115 struct airo_info *local = dev->ml_priv;
6116 int rthr = vwrq->value;
6119 rthr = AIRO_DEF_MTU;
6120 if((rthr < 0) || (rthr > AIRO_DEF_MTU)) {
6123 readConfigRid(local, 1);
6124 local->config.rtsThres = cpu_to_le16(rthr);
6125 set_bit (FLAG_COMMIT, &local->flags);
6127 return -EINPROGRESS; /* Call commit handler */
6130 /*------------------------------------------------------------------*/
6132 * Wireless Handler : get RTS threshold
6134 static int airo_get_rts(struct net_device *dev,
6135 struct iw_request_info *info,
6136 struct iw_param *vwrq,
6139 struct airo_info *local = dev->ml_priv;
6141 readConfigRid(local, 1);
6142 vwrq->value = le16_to_cpu(local->config.rtsThres);
6143 vwrq->disabled = (vwrq->value >= AIRO_DEF_MTU);
6149 /*------------------------------------------------------------------*/
6151 * Wireless Handler : set Fragmentation threshold
6153 static int airo_set_frag(struct net_device *dev,
6154 struct iw_request_info *info,
6155 struct iw_param *vwrq,
6158 struct airo_info *local = dev->ml_priv;
6159 int fthr = vwrq->value;
6162 fthr = AIRO_DEF_MTU;
6163 if((fthr < 256) || (fthr > AIRO_DEF_MTU)) {
6166 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
6167 readConfigRid(local, 1);
6168 local->config.fragThresh = cpu_to_le16(fthr);
6169 set_bit (FLAG_COMMIT, &local->flags);
6171 return -EINPROGRESS; /* Call commit handler */
6174 /*------------------------------------------------------------------*/
6176 * Wireless Handler : get Fragmentation threshold
6178 static int airo_get_frag(struct net_device *dev,
6179 struct iw_request_info *info,
6180 struct iw_param *vwrq,
6183 struct airo_info *local = dev->ml_priv;
6185 readConfigRid(local, 1);
6186 vwrq->value = le16_to_cpu(local->config.fragThresh);
6187 vwrq->disabled = (vwrq->value >= AIRO_DEF_MTU);
6193 /*------------------------------------------------------------------*/
6195 * Wireless Handler : set Mode of Operation
6197 static int airo_set_mode(struct net_device *dev,
6198 struct iw_request_info *info,
6202 struct airo_info *local = dev->ml_priv;
6205 readConfigRid(local, 1);
6206 if (sniffing_mode(local))
6211 local->config.opmode &= ~MODE_CFG_MASK;
6212 local->config.opmode |= MODE_STA_IBSS;
6213 local->config.rmode &= ~RXMODE_FULL_MASK;
6214 local->config.scanMode = SCANMODE_ACTIVE;
6215 clear_bit (FLAG_802_11, &local->flags);
6218 local->config.opmode &= ~MODE_CFG_MASK;
6219 local->config.opmode |= MODE_STA_ESS;
6220 local->config.rmode &= ~RXMODE_FULL_MASK;
6221 local->config.scanMode = SCANMODE_ACTIVE;
6222 clear_bit (FLAG_802_11, &local->flags);
6224 case IW_MODE_MASTER:
6225 local->config.opmode &= ~MODE_CFG_MASK;
6226 local->config.opmode |= MODE_AP;
6227 local->config.rmode &= ~RXMODE_FULL_MASK;
6228 local->config.scanMode = SCANMODE_ACTIVE;
6229 clear_bit (FLAG_802_11, &local->flags);
6231 case IW_MODE_REPEAT:
6232 local->config.opmode &= ~MODE_CFG_MASK;
6233 local->config.opmode |= MODE_AP_RPTR;
6234 local->config.rmode &= ~RXMODE_FULL_MASK;
6235 local->config.scanMode = SCANMODE_ACTIVE;
6236 clear_bit (FLAG_802_11, &local->flags);
6238 case IW_MODE_MONITOR:
6239 local->config.opmode &= ~MODE_CFG_MASK;
6240 local->config.opmode |= MODE_STA_ESS;
6241 local->config.rmode &= ~RXMODE_FULL_MASK;
6242 local->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
6243 local->config.scanMode = SCANMODE_PASSIVE;
6244 set_bit (FLAG_802_11, &local->flags);
6250 set_bit (FLAG_RESET, &local->flags);
6251 set_bit (FLAG_COMMIT, &local->flags);
6253 return -EINPROGRESS; /* Call commit handler */
6256 /*------------------------------------------------------------------*/
6258 * Wireless Handler : get Mode of Operation
6260 static int airo_get_mode(struct net_device *dev,
6261 struct iw_request_info *info,
6265 struct airo_info *local = dev->ml_priv;
6267 readConfigRid(local, 1);
6268 /* If not managed, assume it's ad-hoc */
6269 switch (local->config.opmode & MODE_CFG_MASK) {
6271 *uwrq = IW_MODE_INFRA;
6274 *uwrq = IW_MODE_MASTER;
6277 *uwrq = IW_MODE_REPEAT;
6280 *uwrq = IW_MODE_ADHOC;
6286 static inline int valid_index(struct airo_info *ai, int index)
6288 return (index >= 0) && (index <= ai->max_wep_idx);
6291 /*------------------------------------------------------------------*/
6293 * Wireless Handler : set Encryption Key
6295 static int airo_set_encode(struct net_device *dev,
6296 struct iw_request_info *info,
6297 struct iw_point *dwrq,
6300 struct airo_info *local = dev->ml_priv;
6301 int perm = (dwrq->flags & IW_ENCODE_TEMP ? 0 : 1);
6302 __le16 currentAuthType = local->config.authType;
6305 if (!local->wep_capable)
6308 readConfigRid(local, 1);
6310 /* Basic checking: do we have a key to set ?
6311 * Note : with the new API, it's impossible to get a NULL pointer.
6312 * Therefore, we need to check a key size == 0 instead.
6313 * New version of iwconfig properly set the IW_ENCODE_NOKEY flag
6314 * when no key is present (only change flags), but older versions
6315 * don't do it. - Jean II */
6316 if (dwrq->length > 0) {
6318 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6321 /* Check the size of the key */
6322 if (dwrq->length > MAX_KEY_SIZE) {
6326 current_index = get_wep_tx_idx(local);
6327 if (current_index < 0)
6330 /* Check the index (none -> use current) */
6331 if (!valid_index(local, index))
6332 index = current_index;
6334 /* Set the length */
6335 if (dwrq->length > MIN_KEY_SIZE)
6336 key.len = MAX_KEY_SIZE;
6338 key.len = MIN_KEY_SIZE;
6339 /* Check if the key is not marked as invalid */
6340 if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
6342 memset(key.key, 0, MAX_KEY_SIZE);
6343 /* Copy the key in the driver */
6344 memcpy(key.key, extra, dwrq->length);
6345 /* Send the key to the card */
6346 rc = set_wep_key(local, index, key.key, key.len, perm, 1);
6348 airo_print_err(local->dev->name, "failed to set"
6349 " WEP key at index %d: %d.",
6354 /* WE specify that if a valid key is set, encryption
6355 * should be enabled (user may turn it off later)
6356 * This is also how "iwconfig ethX key on" works */
6357 if((index == current_index) && (key.len > 0) &&
6358 (local->config.authType == AUTH_OPEN))
6359 set_auth_type(local, AUTH_ENCRYPT);
6361 /* Do we want to just set the transmit key index ? */
6362 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6363 if (valid_index(local, index)) {
6364 rc = set_wep_tx_idx(local, index, perm, 1);
6366 airo_print_err(local->dev->name, "failed to set"
6367 " WEP transmit index to %d: %d.",
6372 /* Don't complain if only change the mode */
6373 if (!(dwrq->flags & IW_ENCODE_MODE))
6377 /* Read the flags */
6378 if (dwrq->flags & IW_ENCODE_DISABLED)
6379 set_auth_type(local, AUTH_OPEN); /* disable encryption */
6380 if(dwrq->flags & IW_ENCODE_RESTRICTED)
6381 set_auth_type(local, AUTH_SHAREDKEY); /* Only Both */
6382 if (dwrq->flags & IW_ENCODE_OPEN)
6383 set_auth_type(local, AUTH_ENCRYPT); /* Only Wep */
6384 /* Commit the changes to flags if needed */
6385 if (local->config.authType != currentAuthType)
6386 set_bit (FLAG_COMMIT, &local->flags);
6387 return -EINPROGRESS; /* Call commit handler */
6390 /*------------------------------------------------------------------*/
6392 * Wireless Handler : get Encryption Key
6394 static int airo_get_encode(struct net_device *dev,
6395 struct iw_request_info *info,
6396 struct iw_point *dwrq,
6399 struct airo_info *local = dev->ml_priv;
6400 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6404 if (!local->wep_capable)
6407 readConfigRid(local, 1);
6409 /* Check encryption mode */
6410 switch(local->config.authType) {
6412 dwrq->flags = IW_ENCODE_OPEN;
6414 case AUTH_SHAREDKEY:
6415 dwrq->flags = IW_ENCODE_RESTRICTED;
6419 dwrq->flags = IW_ENCODE_DISABLED;
6422 /* We can't return the key, so set the proper flag and return zero */
6423 dwrq->flags |= IW_ENCODE_NOKEY;
6424 memset(extra, 0, 16);
6426 /* Which key do we want ? -1 -> tx index */
6427 if (!valid_index(local, index)) {
6428 index = get_wep_tx_idx(local);
6432 dwrq->flags |= index + 1;
6434 /* Copy the key to the user buffer */
6435 wep_key_len = get_wep_key(local, index, &buf[0], sizeof(buf));
6436 if (wep_key_len < 0) {
6439 dwrq->length = wep_key_len;
6440 memcpy(extra, buf, dwrq->length);
6446 /*------------------------------------------------------------------*/
6448 * Wireless Handler : set extended Encryption parameters
6450 static int airo_set_encodeext(struct net_device *dev,
6451 struct iw_request_info *info,
6452 union iwreq_data *wrqu,
6455 struct airo_info *local = dev->ml_priv;
6456 struct iw_point *encoding = &wrqu->encoding;
6457 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6458 int perm = ( encoding->flags & IW_ENCODE_TEMP ? 0 : 1 );
6459 __le16 currentAuthType = local->config.authType;
6460 int idx, key_len, alg = ext->alg, set_key = 1, rc;
6463 if (!local->wep_capable)
6466 readConfigRid(local, 1);
6468 /* Determine and validate the key index */
6469 idx = encoding->flags & IW_ENCODE_INDEX;
6471 if (!valid_index(local, idx - 1))
6475 idx = get_wep_tx_idx(local);
6480 if (encoding->flags & IW_ENCODE_DISABLED)
6481 alg = IW_ENCODE_ALG_NONE;
6483 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
6484 /* Only set transmit key index here, actual
6485 * key is set below if needed.
6487 rc = set_wep_tx_idx(local, idx, perm, 1);
6489 airo_print_err(local->dev->name, "failed to set "
6490 "WEP transmit index to %d: %d.",
6494 set_key = ext->key_len > 0 ? 1 : 0;
6498 /* Set the requested key first */
6499 memset(key.key, 0, MAX_KEY_SIZE);
6501 case IW_ENCODE_ALG_NONE:
6504 case IW_ENCODE_ALG_WEP:
6505 if (ext->key_len > MIN_KEY_SIZE) {
6506 key.len = MAX_KEY_SIZE;
6507 } else if (ext->key_len > 0) {
6508 key.len = MIN_KEY_SIZE;
6512 key_len = min (ext->key_len, key.len);
6513 memcpy(key.key, ext->key, key_len);
6519 rc = set_wep_tx_idx(local, idx, perm, 1);
6521 airo_print_err(local->dev->name,
6522 "failed to set WEP transmit index to %d: %d.",
6527 rc = set_wep_key(local, idx, key.key, key.len, perm, 1);
6529 airo_print_err(local->dev->name,
6530 "failed to set WEP key at index %d: %d.",
6537 /* Read the flags */
6538 if (encoding->flags & IW_ENCODE_DISABLED)
6539 set_auth_type(local, AUTH_OPEN); /* disable encryption */
6540 if(encoding->flags & IW_ENCODE_RESTRICTED)
6541 set_auth_type(local, AUTH_SHAREDKEY); /* Only Both */
6542 if (encoding->flags & IW_ENCODE_OPEN)
6543 set_auth_type(local, AUTH_ENCRYPT);
6544 /* Commit the changes to flags if needed */
6545 if (local->config.authType != currentAuthType)
6546 set_bit (FLAG_COMMIT, &local->flags);
6548 return -EINPROGRESS;
6552 /*------------------------------------------------------------------*/
6554 * Wireless Handler : get extended Encryption parameters
6556 static int airo_get_encodeext(struct net_device *dev,
6557 struct iw_request_info *info,
6558 union iwreq_data *wrqu,
6561 struct airo_info *local = dev->ml_priv;
6562 struct iw_point *encoding = &wrqu->encoding;
6563 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6564 int idx, max_key_len, wep_key_len;
6567 if (!local->wep_capable)
6570 readConfigRid(local, 1);
6572 max_key_len = encoding->length - sizeof(*ext);
6573 if (max_key_len < 0)
6576 idx = encoding->flags & IW_ENCODE_INDEX;
6578 if (!valid_index(local, idx - 1))
6582 idx = get_wep_tx_idx(local);
6587 encoding->flags = idx + 1;
6588 memset(ext, 0, sizeof(*ext));
6590 /* Check encryption mode */
6591 switch(local->config.authType) {
6593 encoding->flags = IW_ENCODE_ALG_WEP | IW_ENCODE_ENABLED;
6595 case AUTH_SHAREDKEY:
6596 encoding->flags = IW_ENCODE_ALG_WEP | IW_ENCODE_ENABLED;
6600 encoding->flags = IW_ENCODE_ALG_NONE | IW_ENCODE_DISABLED;
6603 /* We can't return the key, so set the proper flag and return zero */
6604 encoding->flags |= IW_ENCODE_NOKEY;
6605 memset(extra, 0, 16);
6607 /* Copy the key to the user buffer */
6608 wep_key_len = get_wep_key(local, idx, &buf[0], sizeof(buf));
6609 if (wep_key_len < 0) {
6612 ext->key_len = wep_key_len;
6613 memcpy(extra, buf, ext->key_len);
6620 /*------------------------------------------------------------------*/
6622 * Wireless Handler : set extended authentication parameters
6624 static int airo_set_auth(struct net_device *dev,
6625 struct iw_request_info *info,
6626 union iwreq_data *wrqu, char *extra)
6628 struct airo_info *local = dev->ml_priv;
6629 struct iw_param *param = &wrqu->param;
6630 __le16 currentAuthType = local->config.authType;
6632 switch (param->flags & IW_AUTH_INDEX) {
6633 case IW_AUTH_WPA_VERSION:
6634 case IW_AUTH_CIPHER_PAIRWISE:
6635 case IW_AUTH_CIPHER_GROUP:
6636 case IW_AUTH_KEY_MGMT:
6637 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6638 case IW_AUTH_PRIVACY_INVOKED:
6640 * airo does not use these parameters
6644 case IW_AUTH_DROP_UNENCRYPTED:
6646 /* Only change auth type if unencrypted */
6647 if (currentAuthType == AUTH_OPEN)
6648 set_auth_type(local, AUTH_ENCRYPT);
6650 set_auth_type(local, AUTH_OPEN);
6653 /* Commit the changes to flags if needed */
6654 if (local->config.authType != currentAuthType)
6655 set_bit (FLAG_COMMIT, &local->flags);
6658 case IW_AUTH_80211_AUTH_ALG: {
6659 if (param->value & IW_AUTH_ALG_SHARED_KEY) {
6660 set_auth_type(local, AUTH_SHAREDKEY);
6661 } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) {
6662 /* We don't know here if WEP open system or
6663 * unencrypted mode was requested - so use the
6664 * last mode (of these two) used last time
6666 set_auth_type(local, local->last_auth);
6670 /* Commit the changes to flags if needed */
6671 if (local->config.authType != currentAuthType)
6672 set_bit (FLAG_COMMIT, &local->flags);
6676 case IW_AUTH_WPA_ENABLED:
6677 /* Silently accept disable of WPA */
6678 if (param->value > 0)
6685 return -EINPROGRESS;
6689 /*------------------------------------------------------------------*/
6691 * Wireless Handler : get extended authentication parameters
6693 static int airo_get_auth(struct net_device *dev,
6694 struct iw_request_info *info,
6695 union iwreq_data *wrqu, char *extra)
6697 struct airo_info *local = dev->ml_priv;
6698 struct iw_param *param = &wrqu->param;
6699 __le16 currentAuthType = local->config.authType;
6701 switch (param->flags & IW_AUTH_INDEX) {
6702 case IW_AUTH_DROP_UNENCRYPTED:
6703 switch (currentAuthType) {
6704 case AUTH_SHAREDKEY:
6714 case IW_AUTH_80211_AUTH_ALG:
6715 switch (currentAuthType) {
6716 case AUTH_SHAREDKEY:
6717 param->value = IW_AUTH_ALG_SHARED_KEY;
6721 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
6726 case IW_AUTH_WPA_ENABLED:
6737 /*------------------------------------------------------------------*/
6739 * Wireless Handler : set Tx-Power
6741 static int airo_set_txpow(struct net_device *dev,
6742 struct iw_request_info *info,
6743 struct iw_param *vwrq,
6746 struct airo_info *local = dev->ml_priv;
6747 CapabilityRid cap_rid; /* Card capability info */
6750 __le16 v = cpu_to_le16(vwrq->value);
6752 readCapabilityRid(local, &cap_rid, 1);
6754 if (vwrq->disabled) {
6755 set_bit (FLAG_RADIO_OFF, &local->flags);
6756 set_bit (FLAG_COMMIT, &local->flags);
6757 return -EINPROGRESS; /* Call commit handler */
6759 if (vwrq->flags != IW_TXPOW_MWATT) {
6762 clear_bit (FLAG_RADIO_OFF, &local->flags);
6763 for (i = 0; i < 8 && cap_rid.txPowerLevels[i]; i++)
6764 if (v == cap_rid.txPowerLevels[i]) {
6765 readConfigRid(local, 1);
6766 local->config.txPower = v;
6767 set_bit (FLAG_COMMIT, &local->flags);
6768 rc = -EINPROGRESS; /* Call commit handler */
6774 /*------------------------------------------------------------------*/
6776 * Wireless Handler : get Tx-Power
6778 static int airo_get_txpow(struct net_device *dev,
6779 struct iw_request_info *info,
6780 struct iw_param *vwrq,
6783 struct airo_info *local = dev->ml_priv;
6785 readConfigRid(local, 1);
6786 vwrq->value = le16_to_cpu(local->config.txPower);
6787 vwrq->fixed = 1; /* No power control */
6788 vwrq->disabled = test_bit(FLAG_RADIO_OFF, &local->flags);
6789 vwrq->flags = IW_TXPOW_MWATT;
6794 /*------------------------------------------------------------------*/
6796 * Wireless Handler : set Retry limits
6798 static int airo_set_retry(struct net_device *dev,
6799 struct iw_request_info *info,
6800 struct iw_param *vwrq,
6803 struct airo_info *local = dev->ml_priv;
6806 if(vwrq->disabled) {
6809 readConfigRid(local, 1);
6810 if(vwrq->flags & IW_RETRY_LIMIT) {
6811 __le16 v = cpu_to_le16(vwrq->value);
6812 if(vwrq->flags & IW_RETRY_LONG)
6813 local->config.longRetryLimit = v;
6814 else if (vwrq->flags & IW_RETRY_SHORT)
6815 local->config.shortRetryLimit = v;
6817 /* No modifier : set both */
6818 local->config.longRetryLimit = v;
6819 local->config.shortRetryLimit = v;
6821 set_bit (FLAG_COMMIT, &local->flags);
6822 rc = -EINPROGRESS; /* Call commit handler */
6824 if(vwrq->flags & IW_RETRY_LIFETIME) {
6825 local->config.txLifetime = cpu_to_le16(vwrq->value / 1024);
6826 set_bit (FLAG_COMMIT, &local->flags);
6827 rc = -EINPROGRESS; /* Call commit handler */
6832 /*------------------------------------------------------------------*/
6834 * Wireless Handler : get Retry limits
6836 static int airo_get_retry(struct net_device *dev,
6837 struct iw_request_info *info,
6838 struct iw_param *vwrq,
6841 struct airo_info *local = dev->ml_priv;
6843 vwrq->disabled = 0; /* Can't be disabled */
6845 readConfigRid(local, 1);
6846 /* Note : by default, display the min retry number */
6847 if((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
6848 vwrq->flags = IW_RETRY_LIFETIME;
6849 vwrq->value = le16_to_cpu(local->config.txLifetime) * 1024;
6850 } else if((vwrq->flags & IW_RETRY_LONG)) {
6851 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
6852 vwrq->value = le16_to_cpu(local->config.longRetryLimit);
6854 vwrq->flags = IW_RETRY_LIMIT;
6855 vwrq->value = le16_to_cpu(local->config.shortRetryLimit);
6856 if(local->config.shortRetryLimit != local->config.longRetryLimit)
6857 vwrq->flags |= IW_RETRY_SHORT;
6863 /*------------------------------------------------------------------*/
6865 * Wireless Handler : get range info
6867 static int airo_get_range(struct net_device *dev,
6868 struct iw_request_info *info,
6869 struct iw_point *dwrq,
6872 struct airo_info *local = dev->ml_priv;
6873 struct iw_range *range = (struct iw_range *) extra;
6874 CapabilityRid cap_rid; /* Card capability info */
6878 readCapabilityRid(local, &cap_rid, 1);
6880 dwrq->length = sizeof(struct iw_range);
6881 memset(range, 0, sizeof(*range));
6882 range->min_nwid = 0x0000;
6883 range->max_nwid = 0x0000;
6884 range->num_channels = 14;
6885 /* Should be based on cap_rid.country to give only
6886 * what the current card support */
6888 for(i = 0; i < 14; i++) {
6889 range->freq[k].i = i + 1; /* List index */
6890 range->freq[k].m = 100000 *
6891 ieee80211_channel_to_frequency(i + 1, NL80211_BAND_2GHZ);
6892 range->freq[k++].e = 1; /* Values in MHz -> * 10^5 * 10 */
6894 range->num_frequency = k;
6896 range->sensitivity = 65535;
6898 /* Hum... Should put the right values there */
6900 range->max_qual.qual = 100; /* % */
6902 range->max_qual.qual = airo_get_max_quality(&cap_rid);
6903 range->max_qual.level = 0x100 - 120; /* -120 dBm */
6904 range->max_qual.noise = 0x100 - 120; /* -120 dBm */
6906 /* Experimental measurements - boundary 11/5.5 Mb/s */
6907 /* Note : with or without the (local->rssi), results
6908 * are somewhat different. - Jean II */
6910 range->avg_qual.qual = 50; /* % */
6911 range->avg_qual.level = 0x100 - 70; /* -70 dBm */
6913 range->avg_qual.qual = airo_get_avg_quality(&cap_rid);
6914 range->avg_qual.level = 0x100 - 80; /* -80 dBm */
6916 range->avg_qual.noise = 0x100 - 85; /* -85 dBm */
6918 for(i = 0 ; i < 8 ; i++) {
6919 range->bitrate[i] = cap_rid.supportedRates[i] * 500000;
6920 if(range->bitrate[i] == 0)
6923 range->num_bitrates = i;
6925 /* Set an indication of the max TCP throughput
6926 * in bit/s that we can expect using this interface.
6927 * May be use for QoS stuff... Jean II */
6929 range->throughput = 5000 * 1000;
6931 range->throughput = 1500 * 1000;
6934 range->max_rts = AIRO_DEF_MTU;
6935 range->min_frag = 256;
6936 range->max_frag = AIRO_DEF_MTU;
6938 if(cap_rid.softCap & cpu_to_le16(2)) {
6940 range->encoding_size[0] = 5;
6942 if (cap_rid.softCap & cpu_to_le16(0x100)) {
6943 range->encoding_size[1] = 13;
6944 range->num_encoding_sizes = 2;
6946 range->num_encoding_sizes = 1;
6947 range->max_encoding_tokens =
6948 cap_rid.softCap & cpu_to_le16(0x80) ? 4 : 1;
6950 range->num_encoding_sizes = 0;
6951 range->max_encoding_tokens = 0;
6954 range->max_pmp = 5000000; /* 5 secs */
6956 range->max_pmt = 65535 * 1024; /* ??? */
6957 range->pmp_flags = IW_POWER_PERIOD;
6958 range->pmt_flags = IW_POWER_TIMEOUT;
6959 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
6961 /* Transmit Power - values are in mW */
6962 for(i = 0 ; i < 8 ; i++) {
6963 range->txpower[i] = le16_to_cpu(cap_rid.txPowerLevels[i]);
6964 if(range->txpower[i] == 0)
6967 range->num_txpower = i;
6968 range->txpower_capa = IW_TXPOW_MWATT;
6969 range->we_version_source = 19;
6970 range->we_version_compiled = WIRELESS_EXT;
6971 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
6972 range->retry_flags = IW_RETRY_LIMIT;
6973 range->r_time_flags = IW_RETRY_LIFETIME;
6974 range->min_retry = 1;
6975 range->max_retry = 65535;
6976 range->min_r_time = 1024;
6977 range->max_r_time = 65535 * 1024;
6979 /* Event capability (kernel + driver) */
6980 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
6981 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
6982 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
6983 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
6984 range->event_capa[1] = IW_EVENT_CAPA_K_1;
6985 range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVTXDROP);
6989 /*------------------------------------------------------------------*/
6991 * Wireless Handler : set Power Management
6993 static int airo_set_power(struct net_device *dev,
6994 struct iw_request_info *info,
6995 struct iw_param *vwrq,
6998 struct airo_info *local = dev->ml_priv;
7000 readConfigRid(local, 1);
7001 if (vwrq->disabled) {
7002 if (sniffing_mode(local))
7004 local->config.powerSaveMode = POWERSAVE_CAM;
7005 local->config.rmode &= ~RXMODE_MASK;
7006 local->config.rmode |= RXMODE_BC_MC_ADDR;
7007 set_bit (FLAG_COMMIT, &local->flags);
7008 return -EINPROGRESS; /* Call commit handler */
7010 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
7011 local->config.fastListenDelay = cpu_to_le16((vwrq->value + 500) / 1024);
7012 local->config.powerSaveMode = POWERSAVE_PSPCAM;
7013 set_bit (FLAG_COMMIT, &local->flags);
7014 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
7015 local->config.fastListenInterval =
7016 local->config.listenInterval =
7017 cpu_to_le16((vwrq->value + 500) / 1024);
7018 local->config.powerSaveMode = POWERSAVE_PSPCAM;
7019 set_bit (FLAG_COMMIT, &local->flags);
7021 switch (vwrq->flags & IW_POWER_MODE) {
7022 case IW_POWER_UNICAST_R:
7023 if (sniffing_mode(local))
7025 local->config.rmode &= ~RXMODE_MASK;
7026 local->config.rmode |= RXMODE_ADDR;
7027 set_bit (FLAG_COMMIT, &local->flags);
7029 case IW_POWER_ALL_R:
7030 if (sniffing_mode(local))
7032 local->config.rmode &= ~RXMODE_MASK;
7033 local->config.rmode |= RXMODE_BC_MC_ADDR;
7034 set_bit (FLAG_COMMIT, &local->flags);
7036 /* This is broken, fixme ;-) */
7041 // Note : we may want to factor local->need_commit here
7042 // Note2 : may also want to factor RXMODE_RFMON test
7043 return -EINPROGRESS; /* Call commit handler */
7046 /*------------------------------------------------------------------*/
7048 * Wireless Handler : get Power Management
7050 static int airo_get_power(struct net_device *dev,
7051 struct iw_request_info *info,
7052 struct iw_param *vwrq,
7055 struct airo_info *local = dev->ml_priv;
7058 readConfigRid(local, 1);
7059 mode = local->config.powerSaveMode;
7060 if ((vwrq->disabled = (mode == POWERSAVE_CAM)))
7062 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
7063 vwrq->value = le16_to_cpu(local->config.fastListenDelay) * 1024;
7064 vwrq->flags = IW_POWER_TIMEOUT;
7066 vwrq->value = le16_to_cpu(local->config.fastListenInterval) * 1024;
7067 vwrq->flags = IW_POWER_PERIOD;
7069 if ((local->config.rmode & RXMODE_MASK) == RXMODE_ADDR)
7070 vwrq->flags |= IW_POWER_UNICAST_R;
7072 vwrq->flags |= IW_POWER_ALL_R;
7077 /*------------------------------------------------------------------*/
7079 * Wireless Handler : set Sensitivity
7081 static int airo_set_sens(struct net_device *dev,
7082 struct iw_request_info *info,
7083 struct iw_param *vwrq,
7086 struct airo_info *local = dev->ml_priv;
7088 readConfigRid(local, 1);
7089 local->config.rssiThreshold =
7090 cpu_to_le16(vwrq->disabled ? RSSI_DEFAULT : vwrq->value);
7091 set_bit (FLAG_COMMIT, &local->flags);
7093 return -EINPROGRESS; /* Call commit handler */
7096 /*------------------------------------------------------------------*/
7098 * Wireless Handler : get Sensitivity
7100 static int airo_get_sens(struct net_device *dev,
7101 struct iw_request_info *info,
7102 struct iw_param *vwrq,
7105 struct airo_info *local = dev->ml_priv;
7107 readConfigRid(local, 1);
7108 vwrq->value = le16_to_cpu(local->config.rssiThreshold);
7109 vwrq->disabled = (vwrq->value == 0);
7115 /*------------------------------------------------------------------*/
7117 * Wireless Handler : get AP List
7118 * Note : this is deprecated in favor of IWSCAN
7120 static int airo_get_aplist(struct net_device *dev,
7121 struct iw_request_info *info,
7122 struct iw_point *dwrq,
7125 struct airo_info *local = dev->ml_priv;
7126 struct sockaddr *address = (struct sockaddr *) extra;
7127 struct iw_quality *qual;
7130 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
7132 qual = kmalloc_array(IW_MAX_AP, sizeof(*qual), GFP_KERNEL);
7136 for (i = 0; i < IW_MAX_AP; i++) {
7138 if (readBSSListRid(local, loseSync, &BSSList))
7141 memcpy(address[i].sa_data, BSSList.bssid, ETH_ALEN);
7142 address[i].sa_family = ARPHRD_ETHER;
7143 dBm = le16_to_cpu(BSSList.dBm);
7145 qual[i].level = 0x100 - dBm;
7146 qual[i].qual = airo_dbm_to_pct(local->rssi, dBm);
7147 qual[i].updated = IW_QUAL_QUAL_UPDATED
7148 | IW_QUAL_LEVEL_UPDATED
7151 qual[i].level = (dBm + 321) / 2;
7153 qual[i].updated = IW_QUAL_QUAL_INVALID
7154 | IW_QUAL_LEVEL_UPDATED
7157 qual[i].noise = local->wstats.qual.noise;
7158 if (BSSList.index == cpu_to_le16(0xffff))
7162 StatusRid status_rid; /* Card status info */
7163 readStatusRid(local, &status_rid, 1);
7165 i < min(IW_MAX_AP, 4) &&
7166 (status_rid.bssid[i][0]
7167 & status_rid.bssid[i][1]
7168 & status_rid.bssid[i][2]
7169 & status_rid.bssid[i][3]
7170 & status_rid.bssid[i][4]
7171 & status_rid.bssid[i][5])!=0xff &&
7172 (status_rid.bssid[i][0]
7173 | status_rid.bssid[i][1]
7174 | status_rid.bssid[i][2]
7175 | status_rid.bssid[i][3]
7176 | status_rid.bssid[i][4]
7177 | status_rid.bssid[i][5]);
7179 memcpy(address[i].sa_data,
7180 status_rid.bssid[i], ETH_ALEN);
7181 address[i].sa_family = ARPHRD_ETHER;
7184 dwrq->flags = 1; /* Should be define'd */
7185 memcpy(extra + sizeof(struct sockaddr) * i, qual,
7186 sizeof(struct iw_quality) * i);
7194 /*------------------------------------------------------------------*/
7196 * Wireless Handler : Initiate Scan
7198 static int airo_set_scan(struct net_device *dev,
7199 struct iw_request_info *info,
7200 struct iw_point *dwrq,
7203 struct airo_info *ai = dev->ml_priv;
7207 APListRid APList_rid_empty;
7209 /* Note : you may have realised that, as this is a SET operation,
7210 * this is privileged and therefore a normal user can't
7212 * This is not an error, while the device perform scanning,
7213 * traffic doesn't flow, so it's a perfect DoS...
7215 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
7217 if (down_interruptible(&ai->sem))
7218 return -ERESTARTSYS;
7220 /* If there's already a scan in progress, don't
7221 * trigger another one. */
7222 if (ai->scan_timeout > 0)
7225 /* Clear APList as it affects scan results */
7226 memset(&APList_rid_empty, 0, sizeof(APList_rid_empty));
7227 APList_rid_empty.len = cpu_to_le16(sizeof(APList_rid_empty));
7229 writeAPListRid(ai, &APList_rid_empty, 0);
7232 /* Initiate a scan command */
7233 ai->scan_timeout = RUN_AT(3*HZ);
7234 memset(&cmd, 0, sizeof(cmd));
7235 cmd.cmd=CMD_LISTBSS;
7236 issuecommand(ai, &cmd, &rsp);
7242 wake_up_interruptible(&ai->thr_wait);
7246 /*------------------------------------------------------------------*/
7248 * Translate scan data returned from the card to a card independent
7249 * format that the Wireless Tools will understand - Jean II
7251 static inline char *airo_translate_scan(struct net_device *dev,
7252 struct iw_request_info *info,
7257 struct airo_info *ai = dev->ml_priv;
7258 struct iw_event iwe; /* Temporary buffer */
7259 __le16 capabilities;
7260 char * current_val; /* For rates */
7265 /* First entry *MUST* be the AP MAC address */
7266 iwe.cmd = SIOCGIWAP;
7267 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
7268 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
7269 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7270 &iwe, IW_EV_ADDR_LEN);
7272 /* Other entries will be displayed in the order we give them */
7275 iwe.u.data.length = bss->ssidLen;
7276 if(iwe.u.data.length > 32)
7277 iwe.u.data.length = 32;
7278 iwe.cmd = SIOCGIWESSID;
7279 iwe.u.data.flags = 1;
7280 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
7284 iwe.cmd = SIOCGIWMODE;
7285 capabilities = bss->cap;
7286 if(capabilities & (CAP_ESS | CAP_IBSS)) {
7287 if(capabilities & CAP_ESS)
7288 iwe.u.mode = IW_MODE_MASTER;
7290 iwe.u.mode = IW_MODE_ADHOC;
7291 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7292 &iwe, IW_EV_UINT_LEN);
7296 iwe.cmd = SIOCGIWFREQ;
7297 iwe.u.freq.m = le16_to_cpu(bss->dsChannel);
7298 iwe.u.freq.m = 100000 *
7299 ieee80211_channel_to_frequency(iwe.u.freq.m, NL80211_BAND_2GHZ);
7301 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7302 &iwe, IW_EV_FREQ_LEN);
7304 dBm = le16_to_cpu(bss->dBm);
7306 /* Add quality statistics */
7309 iwe.u.qual.level = 0x100 - dBm;
7310 iwe.u.qual.qual = airo_dbm_to_pct(ai->rssi, dBm);
7311 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED
7312 | IW_QUAL_LEVEL_UPDATED
7315 iwe.u.qual.level = (dBm + 321) / 2;
7316 iwe.u.qual.qual = 0;
7317 iwe.u.qual.updated = IW_QUAL_QUAL_INVALID
7318 | IW_QUAL_LEVEL_UPDATED
7321 iwe.u.qual.noise = ai->wstats.qual.noise;
7322 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7323 &iwe, IW_EV_QUAL_LEN);
7325 /* Add encryption capability */
7326 iwe.cmd = SIOCGIWENCODE;
7327 if(capabilities & CAP_PRIVACY)
7328 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
7330 iwe.u.data.flags = IW_ENCODE_DISABLED;
7331 iwe.u.data.length = 0;
7332 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
7335 /* Rate : stuffing multiple values in a single event require a bit
7336 * more of magic - Jean II */
7337 current_val = current_ev + iwe_stream_lcp_len(info);
7339 iwe.cmd = SIOCGIWRATE;
7340 /* Those two flags are ignored... */
7341 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
7343 for(i = 0 ; i < 8 ; i++) {
7344 /* NULL terminated */
7345 if(bss->rates[i] == 0)
7347 /* Bit rate given in 500 kb/s units (+ 0x80) */
7348 iwe.u.bitrate.value = ((bss->rates[i] & 0x7f) * 500000);
7349 /* Add new value to event */
7350 current_val = iwe_stream_add_value(info, current_ev,
7351 current_val, end_buf,
7352 &iwe, IW_EV_PARAM_LEN);
7354 /* Check if we added any event */
7355 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
7356 current_ev = current_val;
7358 /* Beacon interval */
7359 buf = kmalloc(30, GFP_KERNEL);
7361 iwe.cmd = IWEVCUSTOM;
7362 sprintf(buf, "bcn_int=%d", bss->beaconInterval);
7363 iwe.u.data.length = strlen(buf);
7364 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
7369 /* Put WPA/RSN Information Elements into the event stream */
7370 if (test_bit(FLAG_WPA_CAPABLE, &ai->flags)) {
7371 unsigned int num_null_ies = 0;
7372 u16 length = sizeof (bss->extra.iep);
7373 u8 *ie = (void *)&bss->extra.iep;
7375 while ((length >= 2) && (num_null_ies < 2)) {
7376 if (2 + ie[1] > length) {
7377 /* Invalid element, don't continue parsing IE */
7383 /* Two zero-length SSID elements
7384 * mean we're done parsing elements */
7389 case WLAN_EID_VENDOR_SPECIFIC:
7395 iwe.cmd = IWEVGENIE;
7396 /* 64 is an arbitrary cut-off */
7397 iwe.u.data.length = min(ie[1] + 2,
7399 current_ev = iwe_stream_add_point(
7406 iwe.cmd = IWEVGENIE;
7407 /* 64 is an arbitrary cut-off */
7408 iwe.u.data.length = min(ie[1] + 2, 64);
7409 current_ev = iwe_stream_add_point(
7410 info, current_ev, end_buf,
7418 length -= 2 + ie[1];
7425 /*------------------------------------------------------------------*/
7427 * Wireless Handler : Read Scan Results
7429 static int airo_get_scan(struct net_device *dev,
7430 struct iw_request_info *info,
7431 struct iw_point *dwrq,
7434 struct airo_info *ai = dev->ml_priv;
7435 BSSListElement *net;
7437 char *current_ev = extra;
7439 /* If a scan is in-progress, return -EAGAIN */
7440 if (ai->scan_timeout > 0)
7443 if (down_interruptible(&ai->sem))
7446 list_for_each_entry (net, &ai->network_list, list) {
7447 /* Translate to WE format this entry */
7448 current_ev = airo_translate_scan(dev, info, current_ev,
7449 extra + dwrq->length,
7452 /* Check if there is space for one more entry */
7453 if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) {
7454 /* Ask user space to try again with a bigger buffer */
7460 /* Length of data */
7461 dwrq->length = (current_ev - extra);
7462 dwrq->flags = 0; /* todo */
7469 /*------------------------------------------------------------------*/
7471 * Commit handler : called after a bunch of SET operations
7473 static int airo_config_commit(struct net_device *dev,
7474 struct iw_request_info *info, /* NULL */
7475 void *zwrq, /* NULL */
7476 char *extra) /* NULL */
7478 struct airo_info *local = dev->ml_priv;
7480 if (!test_bit (FLAG_COMMIT, &local->flags))
7483 /* Some of the "SET" function may have modified some of the
7484 * parameters. It's now time to commit them in the card */
7485 disable_MAC(local, 1);
7486 if (test_bit (FLAG_RESET, &local->flags)) {
7489 readSsidRid(local, &SSID_rid);
7490 if (test_bit(FLAG_MPI,&local->flags))
7491 setup_card(local, dev->dev_addr, 1 );
7493 reset_airo_card(dev);
7494 disable_MAC(local, 1);
7495 writeSsidRid(local, &SSID_rid, 1);
7496 writeAPListRid(local, &local->APList, 1);
7498 if (down_interruptible(&local->sem))
7499 return -ERESTARTSYS;
7500 writeConfigRid(local, 0);
7501 enable_MAC(local, 0);
7502 if (test_bit (FLAG_RESET, &local->flags))
7503 airo_set_promisc(local);
7510 /*------------------------------------------------------------------*/
7512 * Structures to export the Wireless Handlers
7515 static const struct iw_priv_args airo_private_args[] = {
7516 /*{ cmd, set_args, get_args, name } */
7517 { AIROIOCTL, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
7518 IW_PRIV_TYPE_BYTE | 2047, "airoioctl" },
7519 { AIROIDIFC, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
7520 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "airoidifc" },
7523 static const iw_handler airo_handler[] =
7525 (iw_handler) airo_config_commit, /* SIOCSIWCOMMIT */
7526 (iw_handler) airo_get_name, /* SIOCGIWNAME */
7527 (iw_handler) NULL, /* SIOCSIWNWID */
7528 (iw_handler) NULL, /* SIOCGIWNWID */
7529 (iw_handler) airo_set_freq, /* SIOCSIWFREQ */
7530 (iw_handler) airo_get_freq, /* SIOCGIWFREQ */
7531 (iw_handler) airo_set_mode, /* SIOCSIWMODE */
7532 (iw_handler) airo_get_mode, /* SIOCGIWMODE */
7533 (iw_handler) airo_set_sens, /* SIOCSIWSENS */
7534 (iw_handler) airo_get_sens, /* SIOCGIWSENS */
7535 (iw_handler) NULL, /* SIOCSIWRANGE */
7536 (iw_handler) airo_get_range, /* SIOCGIWRANGE */
7537 (iw_handler) NULL, /* SIOCSIWPRIV */
7538 (iw_handler) NULL, /* SIOCGIWPRIV */
7539 (iw_handler) NULL, /* SIOCSIWSTATS */
7540 (iw_handler) NULL, /* SIOCGIWSTATS */
7541 iw_handler_set_spy, /* SIOCSIWSPY */
7542 iw_handler_get_spy, /* SIOCGIWSPY */
7543 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
7544 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
7545 (iw_handler) airo_set_wap, /* SIOCSIWAP */
7546 (iw_handler) airo_get_wap, /* SIOCGIWAP */
7547 (iw_handler) NULL, /* -- hole -- */
7548 (iw_handler) airo_get_aplist, /* SIOCGIWAPLIST */
7549 (iw_handler) airo_set_scan, /* SIOCSIWSCAN */
7550 (iw_handler) airo_get_scan, /* SIOCGIWSCAN */
7551 (iw_handler) airo_set_essid, /* SIOCSIWESSID */
7552 (iw_handler) airo_get_essid, /* SIOCGIWESSID */
7553 (iw_handler) airo_set_nick, /* SIOCSIWNICKN */
7554 (iw_handler) airo_get_nick, /* SIOCGIWNICKN */
7555 (iw_handler) NULL, /* -- hole -- */
7556 (iw_handler) NULL, /* -- hole -- */
7557 (iw_handler) airo_set_rate, /* SIOCSIWRATE */
7558 (iw_handler) airo_get_rate, /* SIOCGIWRATE */
7559 (iw_handler) airo_set_rts, /* SIOCSIWRTS */
7560 (iw_handler) airo_get_rts, /* SIOCGIWRTS */
7561 (iw_handler) airo_set_frag, /* SIOCSIWFRAG */
7562 (iw_handler) airo_get_frag, /* SIOCGIWFRAG */
7563 (iw_handler) airo_set_txpow, /* SIOCSIWTXPOW */
7564 (iw_handler) airo_get_txpow, /* SIOCGIWTXPOW */
7565 (iw_handler) airo_set_retry, /* SIOCSIWRETRY */
7566 (iw_handler) airo_get_retry, /* SIOCGIWRETRY */
7567 (iw_handler) airo_set_encode, /* SIOCSIWENCODE */
7568 (iw_handler) airo_get_encode, /* SIOCGIWENCODE */
7569 (iw_handler) airo_set_power, /* SIOCSIWPOWER */
7570 (iw_handler) airo_get_power, /* SIOCGIWPOWER */
7571 (iw_handler) NULL, /* -- hole -- */
7572 (iw_handler) NULL, /* -- hole -- */
7573 (iw_handler) NULL, /* SIOCSIWGENIE */
7574 (iw_handler) NULL, /* SIOCGIWGENIE */
7575 (iw_handler) airo_set_auth, /* SIOCSIWAUTH */
7576 (iw_handler) airo_get_auth, /* SIOCGIWAUTH */
7577 (iw_handler) airo_set_encodeext, /* SIOCSIWENCODEEXT */
7578 (iw_handler) airo_get_encodeext, /* SIOCGIWENCODEEXT */
7579 (iw_handler) NULL, /* SIOCSIWPMKSA */
7582 /* Note : don't describe AIROIDIFC and AIROOLDIDIFC in here.
7583 * We want to force the use of the ioctl code, because those can't be
7584 * won't work the iw_handler code (because they simultaneously read
7585 * and write data and iw_handler can't do that).
7586 * Note that it's perfectly legal to read/write on a single ioctl command,
7587 * you just can't use iwpriv and need to force it via the ioctl handler.
7589 static const iw_handler airo_private_handler[] =
7591 NULL, /* SIOCIWFIRSTPRIV */
7594 static const struct iw_handler_def airo_handler_def =
7596 .num_standard = ARRAY_SIZE(airo_handler),
7597 .num_private = ARRAY_SIZE(airo_private_handler),
7598 .num_private_args = ARRAY_SIZE(airo_private_args),
7599 .standard = airo_handler,
7600 .private = airo_private_handler,
7601 .private_args = airo_private_args,
7602 .get_wireless_stats = airo_get_wireless_stats,
7606 * This defines the configuration part of the Wireless Extensions
7607 * Note : irq and spinlock protection will occur in the subroutines
7610 * o Check input value more carefully and fill correct values in range
7611 * o Test and shakeout the bugs (if any)
7615 * Javier Achirica did a great job of merging code from the unnamed CISCO
7616 * developer that added support for flashing the card.
7618 static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
7621 struct airo_info *ai = dev->ml_priv;
7623 if (ai->power.event)
7633 int val = AIROMAGIC;
7635 if (copy_from_user(&com,rq->ifr_data,sizeof(com)))
7637 else if (copy_to_user(com.data,(char *)&val,sizeof(val)))
7646 /* Get the command struct and hand it off for evaluation by
7647 * the proper subfunction
7651 if (copy_from_user(&com,rq->ifr_data,sizeof(com))) {
7656 /* Separate R/W functions bracket legality here
7658 if ( com.command == AIRORSWVERSION ) {
7659 if (copy_to_user(com.data, swversion, sizeof(swversion)))
7664 else if ( com.command <= AIRORRID)
7665 rc = readrids(dev,&com);
7666 else if ( com.command >= AIROPCAP && com.command <= (AIROPLEAPUSR+2) )
7667 rc = writerids(dev,&com);
7668 else if ( com.command >= AIROFLSHRST && com.command <= AIRORESTART )
7669 rc = flashcard(dev,&com);
7671 rc = -EINVAL; /* Bad command in ioctl */
7674 #endif /* CISCO_EXT */
7676 // All other calls are currently unsupported
7684 * Get the Wireless stats out of the driver
7685 * Note : irq and spinlock protection will occur in the subroutines
7688 * o Check if work in Ad-Hoc mode (otherwise, use SPY, as in wvlan_cs)
7692 static void airo_read_wireless_stats(struct airo_info *local)
7694 StatusRid status_rid;
7696 CapabilityRid cap_rid;
7697 __le32 *vals = stats_rid.vals;
7699 /* Get stats out of the card */
7700 clear_bit(JOB_WSTATS, &local->jobs);
7701 if (local->power.event) {
7705 readCapabilityRid(local, &cap_rid, 0);
7706 readStatusRid(local, &status_rid, 0);
7707 readStatsRid(local, &stats_rid, RID_STATS, 0);
7711 local->wstats.status = le16_to_cpu(status_rid.mode);
7713 /* Signal quality and co */
7715 local->wstats.qual.level =
7716 airo_rssi_to_dbm(local->rssi,
7717 le16_to_cpu(status_rid.sigQuality));
7718 /* normalizedSignalStrength appears to be a percentage */
7719 local->wstats.qual.qual =
7720 le16_to_cpu(status_rid.normalizedSignalStrength);
7722 local->wstats.qual.level =
7723 (le16_to_cpu(status_rid.normalizedSignalStrength) + 321) / 2;
7724 local->wstats.qual.qual = airo_get_quality(&status_rid, &cap_rid);
7726 if (le16_to_cpu(status_rid.len) >= 124) {
7727 local->wstats.qual.noise = 0x100 - status_rid.noisedBm;
7728 local->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
7730 local->wstats.qual.noise = 0;
7731 local->wstats.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_INVALID | IW_QUAL_DBM;
7734 /* Packets discarded in the wireless adapter due to wireless
7735 * specific problems */
7736 local->wstats.discard.nwid = le32_to_cpu(vals[56]) +
7737 le32_to_cpu(vals[57]) +
7738 le32_to_cpu(vals[58]); /* SSID Mismatch */
7739 local->wstats.discard.code = le32_to_cpu(vals[6]);/* RxWepErr */
7740 local->wstats.discard.fragment = le32_to_cpu(vals[30]);
7741 local->wstats.discard.retries = le32_to_cpu(vals[10]);
7742 local->wstats.discard.misc = le32_to_cpu(vals[1]) +
7743 le32_to_cpu(vals[32]);
7744 local->wstats.miss.beacon = le32_to_cpu(vals[34]);
7747 static struct iw_statistics *airo_get_wireless_stats(struct net_device *dev)
7749 struct airo_info *local = dev->ml_priv;
7751 if (!test_bit(JOB_WSTATS, &local->jobs)) {
7752 /* Get stats out of the card if available */
7753 if (down_trylock(&local->sem) != 0) {
7754 set_bit(JOB_WSTATS, &local->jobs);
7755 wake_up_interruptible(&local->thr_wait);
7757 airo_read_wireless_stats(local);
7760 return &local->wstats;
7765 * This just translates from driver IOCTL codes to the command codes to
7766 * feed to the radio's host interface. Things can be added/deleted
7767 * as needed. This represents the READ side of control I/O to
7770 static int readrids(struct net_device *dev, aironet_ioctl *comp) {
7771 unsigned short ridcode;
7772 unsigned char *iobuf;
7774 struct airo_info *ai = dev->ml_priv;
7776 if (test_bit(FLAG_FLASHING, &ai->flags))
7779 switch(comp->command)
7781 case AIROGCAP: ridcode = RID_CAPABILITIES; break;
7782 case AIROGCFG: ridcode = RID_CONFIG;
7783 if (test_bit(FLAG_COMMIT, &ai->flags)) {
7784 disable_MAC (ai, 1);
7785 writeConfigRid (ai, 1);
7789 case AIROGSLIST: ridcode = RID_SSID; break;
7790 case AIROGVLIST: ridcode = RID_APLIST; break;
7791 case AIROGDRVNAM: ridcode = RID_DRVNAME; break;
7792 case AIROGEHTENC: ridcode = RID_ETHERENCAP; break;
7793 case AIROGWEPKTMP: ridcode = RID_WEP_TEMP;
7794 /* Only super-user can read WEP keys */
7795 if (!capable(CAP_NET_ADMIN))
7798 case AIROGWEPKNV: ridcode = RID_WEP_PERM;
7799 /* Only super-user can read WEP keys */
7800 if (!capable(CAP_NET_ADMIN))
7803 case AIROGSTAT: ridcode = RID_STATUS; break;
7804 case AIROGSTATSD32: ridcode = RID_STATSDELTA; break;
7805 case AIROGSTATSC32: ridcode = RID_STATS; break;
7807 if (copy_to_user(comp->data, &ai->micstats,
7808 min((int)comp->len,(int)sizeof(ai->micstats))))
7811 case AIRORRID: ridcode = comp->ridnum; break;
7816 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7819 PC4500_readrid(ai,ridcode,iobuf,RIDSIZE, 1);
7820 /* get the count of bytes in the rid docs say 1st 2 bytes is it.
7821 * then return it to the user
7822 * 9/22/2000 Honor user given length
7826 if (copy_to_user(comp->data, iobuf, min(len, (int)RIDSIZE))) {
7835 * Danger Will Robinson write the rids here
7838 static int writerids(struct net_device *dev, aironet_ioctl *comp) {
7839 struct airo_info *ai = dev->ml_priv;
7842 int (*writer)(struct airo_info *, u16 rid, const void *, int, int);
7843 unsigned char *iobuf;
7845 /* Only super-user can write RIDs */
7846 if (!capable(CAP_NET_ADMIN))
7849 if (test_bit(FLAG_FLASHING, &ai->flags))
7853 writer = do_writerid;
7855 switch(comp->command)
7857 case AIROPSIDS: ridcode = RID_SSID; break;
7858 case AIROPCAP: ridcode = RID_CAPABILITIES; break;
7859 case AIROPAPLIST: ridcode = RID_APLIST; break;
7860 case AIROPCFG: ai->config.len = 0;
7861 clear_bit(FLAG_COMMIT, &ai->flags);
7862 ridcode = RID_CONFIG; break;
7863 case AIROPWEPKEYNV: ridcode = RID_WEP_PERM; break;
7864 case AIROPLEAPUSR: ridcode = RID_LEAPUSERNAME; break;
7865 case AIROPLEAPPWD: ridcode = RID_LEAPPASSWORD; break;
7866 case AIROPWEPKEY: ridcode = RID_WEP_TEMP; writer = PC4500_writerid;
7868 case AIROPLEAPUSR+1: ridcode = 0xFF2A; break;
7869 case AIROPLEAPUSR+2: ridcode = 0xFF2B; break;
7871 /* this is not really a rid but a command given to the card
7875 if (enable_MAC(ai, 1) != 0)
7880 * Evidently this code in the airo driver does not get a symbol
7881 * as disable_MAC. it's probably so short the compiler does not gen one.
7887 /* This command merely clears the counts does not actually store any data
7888 * only reads rid. But as it changes the cards state, I put it in the
7889 * writerid routines.
7892 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7895 PC4500_readrid(ai,RID_STATSDELTACLEAR,iobuf,RIDSIZE, 1);
7897 enabled = ai->micstats.enabled;
7898 memset(&ai->micstats,0,sizeof(ai->micstats));
7899 ai->micstats.enabled = enabled;
7901 if (copy_to_user(comp->data, iobuf,
7902 min((int)comp->len, (int)RIDSIZE))) {
7910 return -EOPNOTSUPP; /* Blarg! */
7912 if(comp->len > RIDSIZE)
7915 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7918 if (copy_from_user(iobuf,comp->data,comp->len)) {
7923 if (comp->command == AIROPCFG) {
7924 ConfigRid *cfg = (ConfigRid *)iobuf;
7926 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags))
7927 cfg->opmode |= MODE_MIC;
7929 if ((cfg->opmode & MODE_CFG_MASK) == MODE_STA_IBSS)
7930 set_bit (FLAG_ADHOC, &ai->flags);
7932 clear_bit (FLAG_ADHOC, &ai->flags);
7935 if((*writer)(ai, ridcode, iobuf,comp->len,1)) {
7943 /*****************************************************************************
7944 * Ancillary flash / mod functions much black magic lurkes here *
7945 *****************************************************************************
7949 * Flash command switch table
7952 static int flashcard(struct net_device *dev, aironet_ioctl *comp) {
7955 /* Only super-user can modify flash */
7956 if (!capable(CAP_NET_ADMIN))
7959 switch(comp->command)
7962 return cmdreset((struct airo_info *)dev->ml_priv);
7965 if (!AIRO_FLASH(dev) &&
7966 (AIRO_FLASH(dev) = kmalloc(FLASHSIZE, GFP_KERNEL)) == NULL)
7968 return setflashmode((struct airo_info *)dev->ml_priv);
7970 case AIROFLSHGCHR: /* Get char from aux */
7971 if(comp->len != sizeof(int))
7973 if (copy_from_user(&z,comp->data,comp->len))
7975 return flashgchar((struct airo_info *)dev->ml_priv, z, 8000);
7977 case AIROFLSHPCHR: /* Send char to card. */
7978 if(comp->len != sizeof(int))
7980 if (copy_from_user(&z,comp->data,comp->len))
7982 return flashpchar((struct airo_info *)dev->ml_priv, z, 8000);
7984 case AIROFLPUTBUF: /* Send 32k to card */
7985 if (!AIRO_FLASH(dev))
7987 if(comp->len > FLASHSIZE)
7989 if (copy_from_user(AIRO_FLASH(dev), comp->data, comp->len))
7992 flashputbuf((struct airo_info *)dev->ml_priv);
7996 if (flashrestart((struct airo_info *)dev->ml_priv, dev))
8003 #define FLASH_COMMAND 0x7e7e
8007 * Disable MAC and do soft reset on
8011 static int cmdreset(struct airo_info *ai) {
8015 airo_print_info(ai->dev->name, "Waitbusy hang before RESET");
8019 OUT4500(ai,COMMAND,CMD_SOFTRESET);
8021 ssleep(1); /* WAS 600 12/7/00 */
8024 airo_print_info(ai->dev->name, "Waitbusy hang AFTER RESET");
8031 * Put the card in legendary flash
8035 static int setflashmode (struct airo_info *ai) {
8036 set_bit (FLAG_FLASHING, &ai->flags);
8038 OUT4500(ai, SWS0, FLASH_COMMAND);
8039 OUT4500(ai, SWS1, FLASH_COMMAND);
8041 OUT4500(ai, SWS0, FLASH_COMMAND);
8042 OUT4500(ai, COMMAND,0x10);
8044 OUT4500(ai, SWS2, FLASH_COMMAND);
8045 OUT4500(ai, SWS3, FLASH_COMMAND);
8046 OUT4500(ai, COMMAND,0);
8048 msleep(500); /* 500ms delay */
8051 clear_bit (FLAG_FLASHING, &ai->flags);
8052 airo_print_info(ai->dev->name, "Waitbusy hang after setflash mode");
8058 /* Put character to SWS0 wait for dwelltime
8062 static int flashpchar(struct airo_info *ai,int byte,int dwelltime) {
8073 /* Wait for busy bit d15 to go false indicating buffer empty */
8074 while ((IN4500 (ai, SWS0) & 0x8000) && waittime > 0) {
8079 /* timeout for busy clear wait */
8081 airo_print_info(ai->dev->name, "flash putchar busywait timeout!");
8085 /* Port is clear now write byte and wait for it to echo back */
8087 OUT4500(ai,SWS0,byte);
8090 echo = IN4500(ai,SWS1);
8091 } while (dwelltime >= 0 && echo != byte);
8095 return (echo == byte) ? 0 : -EIO;
8099 * Get a character from the card matching matchbyte
8102 static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime){
8104 unsigned char rbyte=0;
8107 rchar = IN4500(ai,SWS1);
8109 if(dwelltime && !(0x8000 & rchar)){
8114 rbyte = 0xff & rchar;
8116 if( (rbyte == matchbyte) && (0x8000 & rchar) ){
8120 if( rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
8124 }while(dwelltime > 0);
8129 * Transfer 32k of firmware data from user buffer to our buffer and
8133 static int flashputbuf(struct airo_info *ai){
8137 if (test_bit(FLAG_MPI,&ai->flags))
8138 memcpy_toio(ai->pciaux + 0x8000, ai->flash, FLASHSIZE);
8140 OUT4500(ai,AUXPAGE,0x100);
8141 OUT4500(ai,AUXOFF,0);
8143 for(nwords=0;nwords != FLASHSIZE / 2;nwords++){
8144 OUT4500(ai,AUXDATA,ai->flash[nwords] & 0xffff);
8147 OUT4500(ai,SWS0,0x8000);
8155 static int flashrestart(struct airo_info *ai,struct net_device *dev){
8158 ssleep(1); /* Added 12/7/00 */
8159 clear_bit (FLAG_FLASHING, &ai->flags);
8160 if (test_bit(FLAG_MPI, &ai->flags)) {
8161 status = mpi_init_descriptors(ai);
8162 if (status != SUCCESS)
8165 status = setup_card(ai, dev->dev_addr, 1);
8167 if (!test_bit(FLAG_MPI,&ai->flags))
8168 for( i = 0; i < MAX_FIDS; i++ ) {
8169 ai->fids[i] = transmit_allocate
8170 ( ai, AIRO_DEF_MTU, i >= MAX_FIDS / 2 );
8173 ssleep(1); /* Added 12/7/00 */
8176 #endif /* CISCO_EXT */
8179 This program is free software; you can redistribute it and/or
8180 modify it under the terms of the GNU General Public License
8181 as published by the Free Software Foundation; either version 2
8182 of the License, or (at your option) any later version.
8184 This program is distributed in the hope that it will be useful,
8185 but WITHOUT ANY WARRANTY; without even the implied warranty of
8186 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8187 GNU General Public License for more details.
8191 Redistribution and use in source and binary forms, with or without
8192 modification, are permitted provided that the following conditions
8195 1. Redistributions of source code must retain the above copyright
8196 notice, this list of conditions and the following disclaimer.
8197 2. Redistributions in binary form must reproduce the above copyright
8198 notice, this list of conditions and the following disclaimer in the
8199 documentation and/or other materials provided with the distribution.
8200 3. The name of the author may not be used to endorse or promote
8201 products derived from this software without specific prior written
8204 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
8205 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
8206 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
8207 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
8208 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
8209 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
8210 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
8211 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
8212 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
8213 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
8214 POSSIBILITY OF SUCH DAMAGE.
8217 module_init(airo_init_module);
8218 module_exit(airo_cleanup_module);