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/config.h>
23 #include <linux/init.h>
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/proc_fs.h>
28 #include <linux/smp_lock.h>
30 #include <linux/sched.h>
31 #include <linux/ptrace.h>
32 #include <linux/slab.h>
33 #include <linux/string.h>
34 #include <linux/timer.h>
35 #include <linux/interrupt.h>
37 #include <linux/bitops.h>
39 #include <asm/system.h>
41 #include <linux/netdevice.h>
42 #include <linux/etherdevice.h>
43 #include <linux/skbuff.h>
44 #include <linux/if_arp.h>
45 #include <linux/ioport.h>
46 #include <linux/pci.h>
47 #include <asm/uaccess.h>
50 static struct pci_device_id card_ids[] = {
51 { 0x14b9, 1, PCI_ANY_ID, PCI_ANY_ID, },
52 { 0x14b9, 0x4500, PCI_ANY_ID, PCI_ANY_ID },
53 { 0x14b9, 0x4800, PCI_ANY_ID, PCI_ANY_ID, },
54 { 0x14b9, 0x0340, PCI_ANY_ID, PCI_ANY_ID, },
55 { 0x14b9, 0x0350, PCI_ANY_ID, PCI_ANY_ID, },
56 { 0x14b9, 0x5000, PCI_ANY_ID, PCI_ANY_ID, },
57 { 0x14b9, 0xa504, PCI_ANY_ID, PCI_ANY_ID, },
60 MODULE_DEVICE_TABLE(pci, card_ids);
62 static int airo_pci_probe(struct pci_dev *, const struct pci_device_id *);
63 static void airo_pci_remove(struct pci_dev *);
64 static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state);
65 static int airo_pci_resume(struct pci_dev *pdev);
67 static struct pci_driver airo_driver = {
70 .probe = airo_pci_probe,
71 .remove = __devexit_p(airo_pci_remove),
72 .suspend = airo_pci_suspend,
73 .resume = airo_pci_resume,
75 #endif /* CONFIG_PCI */
77 /* Include Wireless Extension definition and check version - Jean II */
78 #include <linux/wireless.h>
79 #define WIRELESS_SPY // enable iwspy support
80 #include <net/iw_handler.h> // New driver API
82 #define CISCO_EXT // enable Cisco extensions
84 #include <linux/delay.h>
87 /* Support Cisco MIC feature */
90 #if defined(MICSUPPORT) && !defined(CONFIG_CRYPTO)
91 #warning MIC support requires Crypto API
95 /* Hack to do some power saving */
98 /* As you can see this list is HUGH!
99 I really don't know what a lot of these counts are about, but they
100 are all here for completeness. If the IGNLABEL macro is put in
101 infront of the label, that statistic will not be included in the list
102 of statistics in the /proc filesystem */
104 #define IGNLABEL(comment) NULL
105 static char *statsLabels[] = {
107 IGNLABEL("RxPlcpCrcErr"),
108 IGNLABEL("RxPlcpFormatErr"),
109 IGNLABEL("RxPlcpLengthErr"),
140 "LostSync-MissedBeacons",
141 "LostSync-ArlExceeded",
143 "LostSync-Disassoced",
144 "LostSync-TsfTiming",
153 IGNLABEL("HmacTxMc"),
154 IGNLABEL("HmacTxBc"),
155 IGNLABEL("HmacTxUc"),
156 IGNLABEL("HmacTxFail"),
157 IGNLABEL("HmacRxMc"),
158 IGNLABEL("HmacRxBc"),
159 IGNLABEL("HmacRxUc"),
160 IGNLABEL("HmacRxDiscard"),
161 IGNLABEL("HmacRxAccepted"),
169 IGNLABEL("ReasonOutsideTable"),
170 IGNLABEL("ReasonStatus1"),
171 IGNLABEL("ReasonStatus2"),
172 IGNLABEL("ReasonStatus3"),
173 IGNLABEL("ReasonStatus4"),
174 IGNLABEL("ReasonStatus5"),
175 IGNLABEL("ReasonStatus6"),
176 IGNLABEL("ReasonStatus7"),
177 IGNLABEL("ReasonStatus8"),
178 IGNLABEL("ReasonStatus9"),
179 IGNLABEL("ReasonStatus10"),
180 IGNLABEL("ReasonStatus11"),
181 IGNLABEL("ReasonStatus12"),
182 IGNLABEL("ReasonStatus13"),
183 IGNLABEL("ReasonStatus14"),
184 IGNLABEL("ReasonStatus15"),
185 IGNLABEL("ReasonStatus16"),
186 IGNLABEL("ReasonStatus17"),
187 IGNLABEL("ReasonStatus18"),
188 IGNLABEL("ReasonStatus19"),
208 #define RUN_AT(x) (jiffies+(x))
212 /* These variables are for insmod, since it seems that the rates
213 can only be set in setup_card. Rates should be a comma separated
214 (no spaces) list of rates (up to 8). */
217 static int basic_rate;
218 static char *ssids[3];
224 int maxencrypt /* = 0 */; /* The highest rate that the card can encrypt at.
225 0 means no limit. For old cards this was 4 */
227 static int auto_wep /* = 0 */; /* If set, it tries to figure out the wep mode */
228 static int aux_bap /* = 0 */; /* Checks to see if the aux ports are needed to read
229 the bap, needed on some older cards and buses. */
232 static int probe = 1;
234 static int proc_uid /* = 0 */;
236 static int proc_gid /* = 0 */;
238 static int airo_perm = 0555;
240 static int proc_perm = 0644;
242 MODULE_AUTHOR("Benjamin Reed");
243 MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet \
244 cards. Direct support for ISA/PCI/MPI cards and support \
245 for PCMCIA when used with airo_cs.");
246 MODULE_LICENSE("Dual BSD/GPL");
247 MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340/350");
248 module_param_array(io, int, NULL, 0);
249 module_param_array(irq, int, NULL, 0);
250 module_param(basic_rate, int, 0);
251 module_param_array(rates, int, NULL, 0);
252 module_param_array(ssids, charp, NULL, 0);
253 module_param(auto_wep, int, 0);
254 MODULE_PARM_DESC(auto_wep, "If non-zero, the driver will keep looping through \
255 the authentication options until an association is made. The value of \
256 auto_wep is number of the wep keys to check. A value of 2 will try using \
257 the key at index 0 and index 1.");
258 module_param(aux_bap, int, 0);
259 MODULE_PARM_DESC(aux_bap, "If non-zero, the driver will switch into a mode \
260 than seems to work better for older cards with some older buses. Before \
261 switching it checks that the switch is needed.");
262 module_param(maxencrypt, int, 0);
263 MODULE_PARM_DESC(maxencrypt, "The maximum speed that the card can do \
264 encryption. Units are in 512kbs. Zero (default) means there is no limit. \
265 Older cards used to be limited to 2mbs (4).");
266 module_param(adhoc, int, 0);
267 MODULE_PARM_DESC(adhoc, "If non-zero, the card will start in adhoc mode.");
268 module_param(probe, int, 0);
269 MODULE_PARM_DESC(probe, "If zero, the driver won't start the card.");
271 module_param(proc_uid, int, 0);
272 MODULE_PARM_DESC(proc_uid, "The uid that the /proc files will belong to.");
273 module_param(proc_gid, int, 0);
274 MODULE_PARM_DESC(proc_gid, "The gid that the /proc files will belong to.");
275 module_param(airo_perm, int, 0);
276 MODULE_PARM_DESC(airo_perm, "The permission bits of /proc/[driver/]aironet.");
277 module_param(proc_perm, int, 0);
278 MODULE_PARM_DESC(proc_perm, "The permission bits of the files in /proc");
280 /* This is a kind of sloppy hack to get this information to OUT4500 and
281 IN4500. I would be extremely interested in the situation where this
282 doesn't work though!!! */
283 static int do8bitIO = 0;
292 #define MAC_ENABLE 0x0001
293 #define MAC_DISABLE 0x0002
294 #define CMD_LOSE_SYNC 0x0003 /* Not sure what this does... */
295 #define CMD_SOFTRESET 0x0004
296 #define HOSTSLEEP 0x0005
297 #define CMD_MAGIC_PKT 0x0006
298 #define CMD_SETWAKEMASK 0x0007
299 #define CMD_READCFG 0x0008
300 #define CMD_SETMODE 0x0009
301 #define CMD_ALLOCATETX 0x000a
302 #define CMD_TRANSMIT 0x000b
303 #define CMD_DEALLOCATETX 0x000c
305 #define CMD_WORKAROUND 0x0011
306 #define CMD_ALLOCATEAUX 0x0020
307 #define CMD_ACCESS 0x0021
308 #define CMD_PCIBAP 0x0022
309 #define CMD_PCIAUX 0x0023
310 #define CMD_ALLOCBUF 0x0028
311 #define CMD_GETTLV 0x0029
312 #define CMD_PUTTLV 0x002a
313 #define CMD_DELTLV 0x002b
314 #define CMD_FINDNEXTTLV 0x002c
315 #define CMD_PSPNODES 0x0030
316 #define CMD_SETCW 0x0031
317 #define CMD_SETPCF 0x0032
318 #define CMD_SETPHYREG 0x003e
319 #define CMD_TXTEST 0x003f
320 #define MAC_ENABLETX 0x0101
321 #define CMD_LISTBSS 0x0103
322 #define CMD_SAVECFG 0x0108
323 #define CMD_ENABLEAUX 0x0111
324 #define CMD_WRITERID 0x0121
325 #define CMD_USEPSPNODES 0x0130
326 #define MAC_ENABLERX 0x0201
329 #define ERROR_QUALIF 0x00
330 #define ERROR_ILLCMD 0x01
331 #define ERROR_ILLFMT 0x02
332 #define ERROR_INVFID 0x03
333 #define ERROR_INVRID 0x04
334 #define ERROR_LARGE 0x05
335 #define ERROR_NDISABL 0x06
336 #define ERROR_ALLOCBSY 0x07
337 #define ERROR_NORD 0x0B
338 #define ERROR_NOWR 0x0C
339 #define ERROR_INVFIDTX 0x0D
340 #define ERROR_TESTACT 0x0E
341 #define ERROR_TAGNFND 0x12
342 #define ERROR_DECODE 0x20
343 #define ERROR_DESCUNAV 0x21
344 #define ERROR_BADLEN 0x22
345 #define ERROR_MODE 0x80
346 #define ERROR_HOP 0x81
347 #define ERROR_BINTER 0x82
348 #define ERROR_RXMODE 0x83
349 #define ERROR_MACADDR 0x84
350 #define ERROR_RATES 0x85
351 #define ERROR_ORDER 0x86
352 #define ERROR_SCAN 0x87
353 #define ERROR_AUTH 0x88
354 #define ERROR_PSMODE 0x89
355 #define ERROR_RTYPE 0x8A
356 #define ERROR_DIVER 0x8B
357 #define ERROR_SSID 0x8C
358 #define ERROR_APLIST 0x8D
359 #define ERROR_AUTOWAKE 0x8E
360 #define ERROR_LEAP 0x8F
371 #define LINKSTAT 0x10
375 #define TXALLOCFID 0x22
376 #define TXCOMPLFID 0x24
391 /* Offset into aux memory for descriptors */
392 #define AUX_OFFSET 0x800
393 /* Size of allocated packets */
396 /* Size of the transmit queue */
400 #define BAP0 0 // Used for receiving packets
401 #define BAP1 2 // Used for xmiting packets and working with RIDS
404 #define COMMAND_BUSY 0x8000
406 #define BAP_BUSY 0x8000
407 #define BAP_ERR 0x4000
408 #define BAP_DONE 0x2000
410 #define PROMISC 0xffff
411 #define NOPROMISC 0x0000
414 #define EV_CLEARCOMMANDBUSY 0x4000
417 #define EV_TXEXC 0x04
418 #define EV_ALLOC 0x08
420 #define EV_AWAKE 0x100
421 #define EV_TXCPY 0x400
422 #define EV_UNKNOWN 0x800
423 #define EV_MIC 0x1000 /* Message Integrity Check Interrupt */
424 #define EV_AWAKEN 0x2000
425 #define STATUS_INTS (EV_AWAKE|EV_LINK|EV_TXEXC|EV_TX|EV_TXCPY|EV_RX|EV_MIC)
427 #ifdef CHECK_UNKNOWN_INTS
428 #define IGNORE_INTS ( EV_CMD | EV_UNKNOWN)
430 #define IGNORE_INTS (~STATUS_INTS)
437 #define RID_CAPABILITIES 0xFF00
438 #define RID_APINFO 0xFF01
439 #define RID_RADIOINFO 0xFF02
440 #define RID_UNKNOWN3 0xFF03
441 #define RID_RSSI 0xFF04
442 #define RID_CONFIG 0xFF10
443 #define RID_SSID 0xFF11
444 #define RID_APLIST 0xFF12
445 #define RID_DRVNAME 0xFF13
446 #define RID_ETHERENCAP 0xFF14
447 #define RID_WEP_TEMP 0xFF15
448 #define RID_WEP_PERM 0xFF16
449 #define RID_MODULATION 0xFF17
450 #define RID_OPTIONS 0xFF18
451 #define RID_ACTUALCONFIG 0xFF20 /*readonly*/
452 #define RID_FACTORYCONFIG 0xFF21
453 #define RID_UNKNOWN22 0xFF22
454 #define RID_LEAPUSERNAME 0xFF23
455 #define RID_LEAPPASSWORD 0xFF24
456 #define RID_STATUS 0xFF50
457 #define RID_BEACON_HST 0xFF51
458 #define RID_BUSY_HST 0xFF52
459 #define RID_RETRIES_HST 0xFF53
460 #define RID_UNKNOWN54 0xFF54
461 #define RID_UNKNOWN55 0xFF55
462 #define RID_UNKNOWN56 0xFF56
463 #define RID_MIC 0xFF57
464 #define RID_STATS16 0xFF60
465 #define RID_STATS16DELTA 0xFF61
466 #define RID_STATS16DELTACLEAR 0xFF62
467 #define RID_STATS 0xFF68
468 #define RID_STATSDELTA 0xFF69
469 #define RID_STATSDELTACLEAR 0xFF6A
470 #define RID_ECHOTEST_RID 0xFF70
471 #define RID_ECHOTEST_RESULTS 0xFF71
472 #define RID_BSSLISTFIRST 0xFF72
473 #define RID_BSSLISTNEXT 0xFF73
490 * Rids and endian-ness: The Rids will always be in cpu endian, since
491 * this all the patches from the big-endian guys end up doing that.
492 * so all rid access should use the read/writeXXXRid routines.
495 /* This is redundant for x86 archs, but it seems necessary for ARM */
498 /* This structure came from an email sent to me from an engineer at
499 aironet for inclusion into this driver */
508 /* These structures are from the Aironet's PC4500 Developers Manual */
522 #define MOD_DEFAULT 0
528 u16 len; /* sizeof(ConfigRid) */
529 u16 opmode; /* operating mode */
530 #define MODE_STA_IBSS 0
531 #define MODE_STA_ESS 1
533 #define MODE_AP_RPTR 3
534 #define MODE_ETHERNET_HOST (0<<8) /* rx payloads converted */
535 #define MODE_LLC_HOST (1<<8) /* rx payloads left as is */
536 #define MODE_AIRONET_EXTEND (1<<9) /* enable Aironet extenstions */
537 #define MODE_AP_INTERFACE (1<<10) /* enable ap interface extensions */
538 #define MODE_ANTENNA_ALIGN (1<<11) /* enable antenna alignment */
539 #define MODE_ETHER_LLC (1<<12) /* enable ethernet LLC */
540 #define MODE_LEAF_NODE (1<<13) /* enable leaf node bridge */
541 #define MODE_CF_POLLABLE (1<<14) /* enable CF pollable */
542 #define MODE_MIC (1<<15) /* enable MIC */
543 u16 rmode; /* receive mode */
544 #define RXMODE_BC_MC_ADDR 0
545 #define RXMODE_BC_ADDR 1 /* ignore multicasts */
546 #define RXMODE_ADDR 2 /* ignore multicast and broadcast */
547 #define RXMODE_RFMON 3 /* wireless monitor mode */
548 #define RXMODE_RFMON_ANYBSS 4
549 #define RXMODE_LANMON 5 /* lan style monitor -- data packets only */
550 #define RXMODE_DISABLE_802_3_HEADER (1<<8) /* disables 802.3 header on rx */
551 #define RXMODE_NORMALIZED_RSSI (1<<9) /* return normalized RSSI */
554 u8 macAddr[ETH_ALEN];
558 u16 txLifetime; /* in kusec */
559 u16 rxLifetime; /* in kusec */
562 u16 u16deviceType; /* for overriding device type */
566 /*---------- Scanning/Associating ----------*/
568 #define SCANMODE_ACTIVE 0
569 #define SCANMODE_PASSIVE 1
570 #define SCANMODE_AIROSCAN 2
571 u16 probeDelay; /* in kusec */
572 u16 probeEnergyTimeout; /* in kusec */
573 u16 probeResponseTimeout;
574 u16 beaconListenTimeout;
578 #define AUTH_OPEN 0x1
579 #define AUTH_ENCRYPT 0x101
580 #define AUTH_SHAREDKEY 0x102
581 #define AUTH_ALLOW_UNENCRYPTED 0x200
582 u16 associationTimeout;
583 u16 specifiedApTimeout;
584 u16 offlineScanInterval;
585 u16 offlineScanDuration;
587 u16 maxBeaconLostTime;
589 #define DISABLE_REFRESH 0xFFFF
591 /*---------- Power save operation ----------*/
593 #define POWERSAVE_CAM 0
594 #define POWERSAVE_PSP 1
595 #define POWERSAVE_PSPCAM 2
598 u16 fastListenInterval;
602 /*---------- Ap/Ibss config items ----------*/
611 /*---------- Radio configuration ----------*/
613 #define RADIOTYPE_DEFAULT 0
614 #define RADIOTYPE_802_11 1
615 #define RADIOTYPE_LEGACY 2
619 #define TXPOWER_DEFAULT 0
621 #define RSSI_DEFAULT 0
623 #define PREAMBLE_AUTO 0
624 #define PREAMBLE_LONG 1
625 #define PREAMBLE_SHORT 2
629 /*---------- Aironet Extensions ----------*/
635 /*---------- Aironet Extensions ----------*/
637 #define MAGIC_ACTION_STSCHG 1
638 #define MAGIC_ACTION_RESUME 2
639 #define MAGIC_IGNORE_MCAST (1<<8)
640 #define MAGIC_IGNORE_BCAST (1<<9)
641 #define MAGIC_SWITCH_TO_PSP (0<<10)
642 #define MAGIC_STAY_IN_CAM (1<<10)
656 u8 bssid[4][ETH_ALEN];
670 u16 normalizedSignalStrength;
673 u8 noisePercent; /* Noise percent in last second */
674 u8 noisedBm; /* Noise dBm in last second */
675 u8 noiseAvePercent; /* Noise percent in last minute */
676 u8 noiseAvedBm; /* Noise dBm in last minute */
677 u8 noiseMaxPercent; /* Highest noise percent in last minute */
678 u8 noiseMaxdBm; /* Highest noise dbm in last minute */
682 #define STAT_NOPACKETS 0
683 #define STAT_NOCARRIERSET 10
684 #define STAT_GOTCARRIERSET 11
685 #define STAT_WRONGSSID 20
686 #define STAT_BADCHANNEL 25
687 #define STAT_BADBITRATES 30
688 #define STAT_BADPRIVACY 35
689 #define STAT_APFOUND 40
690 #define STAT_APREJECTED 50
691 #define STAT_AUTHENTICATING 60
692 #define STAT_DEAUTHENTICATED 61
693 #define STAT_AUTHTIMEOUT 62
694 #define STAT_ASSOCIATING 70
695 #define STAT_DEASSOCIATED 71
696 #define STAT_ASSOCTIMEOUT 72
697 #define STAT_NOTAIROAP 73
698 #define STAT_ASSOCIATED 80
699 #define STAT_LEAPING 90
700 #define STAT_LEAPFAILED 91
701 #define STAT_LEAPTIMEDOUT 92
702 #define STAT_LEAPCOMPLETE 93
725 char factoryAddr[ETH_ALEN];
726 char aironetAddr[ETH_ALEN];
729 char callid[ETH_ALEN];
730 char supportedRates[8];
733 u16 txPowerLevels[8];
748 u16 index; /* First is 0 and 0xffff means end of list */
749 #define RADIO_FH 1 /* Frequency hopping radio type */
750 #define RADIO_DS 2 /* Direct sequence radio type */
751 #define RADIO_TMA 4 /* Proprietary radio used in old cards (2500) */
753 u8 bssid[ETH_ALEN]; /* Mac address of the BSS */
758 #define CAP_ESS (1<<0)
759 #define CAP_IBSS (1<<1)
760 #define CAP_PRIVACY (1<<4)
761 #define CAP_SHORTHDR (1<<5)
764 u8 rates[8]; /* Same as rates for config rid */
765 struct { /* For frequency hopping only */
819 #define TXCTL_TXOK (1<<1) /* report if tx is ok */
820 #define TXCTL_TXEX (1<<2) /* report if tx fails */
821 #define TXCTL_802_3 (0<<3) /* 802.3 packet */
822 #define TXCTL_802_11 (1<<3) /* 802.11 mac packet */
823 #define TXCTL_ETHERNET (0<<4) /* payload has ethertype */
824 #define TXCTL_LLC (1<<4) /* payload is llc */
825 #define TXCTL_RELEASE (0<<5) /* release after completion */
826 #define TXCTL_NORELEASE (1<<5) /* on completion returns to host */
828 #define BUSY_FID 0x10000
831 #define AIROMAGIC 0xa55a
832 /* Warning : SIOCDEVPRIVATE may disapear during 2.5.X - Jean II */
833 #ifdef SIOCIWFIRSTPRIV
834 #ifdef SIOCDEVPRIVATE
835 #define AIROOLDIOCTL SIOCDEVPRIVATE
836 #define AIROOLDIDIFC AIROOLDIOCTL + 1
837 #endif /* SIOCDEVPRIVATE */
838 #else /* SIOCIWFIRSTPRIV */
839 #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
840 #endif /* SIOCIWFIRSTPRIV */
841 /* This may be wrong. When using the new SIOCIWFIRSTPRIV range, we probably
842 * should use only "GET" ioctls (last bit set to 1). "SET" ioctls are root
843 * only and don't return the modified struct ifreq to the application which
844 * is usually a problem. - Jean II */
845 #define AIROIOCTL SIOCIWFIRSTPRIV
846 #define AIROIDIFC AIROIOCTL + 1
848 /* Ioctl constants to be used in airo_ioctl.command */
850 #define AIROGCAP 0 // Capability rid
851 #define AIROGCFG 1 // USED A LOT
852 #define AIROGSLIST 2 // System ID list
853 #define AIROGVLIST 3 // List of specified AP's
854 #define AIROGDRVNAM 4 // NOTUSED
855 #define AIROGEHTENC 5 // NOTUSED
856 #define AIROGWEPKTMP 6
857 #define AIROGWEPKNV 7
859 #define AIROGSTATSC32 9
860 #define AIROGSTATSD32 10
861 #define AIROGMICRID 11
862 #define AIROGMICSTATS 12
863 #define AIROGFLAGS 13
866 #define AIRORSWVERSION 17
868 /* Leave gap of 40 commands after AIROGSTATSD32 for future */
870 #define AIROPCAP AIROGSTATSD32 + 40
871 #define AIROPVLIST AIROPCAP + 1
872 #define AIROPSLIST AIROPVLIST + 1
873 #define AIROPCFG AIROPSLIST + 1
874 #define AIROPSIDS AIROPCFG + 1
875 #define AIROPAPLIST AIROPSIDS + 1
876 #define AIROPMACON AIROPAPLIST + 1 /* Enable mac */
877 #define AIROPMACOFF AIROPMACON + 1 /* Disable mac */
878 #define AIROPSTCLR AIROPMACOFF + 1
879 #define AIROPWEPKEY AIROPSTCLR + 1
880 #define AIROPWEPKEYNV AIROPWEPKEY + 1
881 #define AIROPLEAPPWD AIROPWEPKEYNV + 1
882 #define AIROPLEAPUSR AIROPLEAPPWD + 1
886 #define AIROFLSHRST AIROPWEPKEYNV + 40
887 #define AIROFLSHGCHR AIROFLSHRST + 1
888 #define AIROFLSHSTFL AIROFLSHGCHR + 1
889 #define AIROFLSHPCHR AIROFLSHSTFL + 1
890 #define AIROFLPUTBUF AIROFLSHPCHR + 1
891 #define AIRORESTART AIROFLPUTBUF + 1
893 #define FLASHSIZE 32768
894 #define AUXMEMSIZE (256 * 1024)
896 typedef struct aironet_ioctl {
897 unsigned short command; // What to do
898 unsigned short len; // Len of data
899 unsigned short ridnum; // rid number
900 unsigned char __user *data; // d-data
903 static char swversion[] = "2.1";
904 #endif /* CISCO_EXT */
906 #define NUM_MODULES 2
907 #define MIC_MSGLEN_MAX 2400
908 #define EMMH32_MSGLEN_MAX MIC_MSGLEN_MAX
912 u8 enabled; // MIC enabled or not
913 u32 rxSuccess; // successful packets received
914 u32 rxIncorrectMIC; // pkts dropped due to incorrect MIC comparison
915 u32 rxNotMICed; // pkts dropped due to not being MIC'd
916 u32 rxMICPlummed; // pkts dropped due to not having a MIC plummed
917 u32 rxWrongSequence; // pkts dropped due to sequence number violation
922 u32 coeff[((EMMH32_MSGLEN_MAX)+3)>>2];
923 u64 accum; // accumulated mic, reduced to u32 in final()
924 int position; // current position (byte offset) in message
928 } part; // saves partial message word across update() calls
932 emmh32_context seed; // Context - the seed
933 u32 rx; // Received sequence number
934 u32 tx; // Tx sequence number
935 u32 window; // Start of window
936 u8 valid; // Flag to say if context is valid or not
941 miccntx mCtx; // Multicast context
942 miccntx uCtx; // Unicast context
946 unsigned int rid: 16;
947 unsigned int len: 15;
948 unsigned int valid: 1;
949 dma_addr_t host_addr;
953 unsigned int offset: 15;
955 unsigned int len: 15;
956 unsigned int valid: 1;
957 dma_addr_t host_addr;
961 unsigned int ctl: 15;
963 unsigned int len: 15;
964 unsigned int valid: 1;
965 dma_addr_t host_addr;
969 * Host receive descriptor
972 unsigned char __iomem *card_ram_off; /* offset into card memory of the
974 RxFid rx_desc; /* card receive descriptor */
975 char *virtual_host_addr; /* virtual address of host receive
981 * Host transmit descriptor
984 unsigned char __iomem *card_ram_off; /* offset into card memory of the
986 TxFid tx_desc; /* card transmit descriptor */
987 char *virtual_host_addr; /* virtual address of host receive
993 * Host RID descriptor
996 unsigned char __iomem *card_ram_off; /* offset into card memory of the
998 Rid rid_desc; /* card RID descriptor */
999 char *virtual_host_addr; /* virtual address of host receive
1008 #define HOST_SET (1 << 0)
1009 #define HOST_INT_TX (1 << 1) /* Interrupt on successful TX */
1010 #define HOST_INT_TXERR (1 << 2) /* Interrupt on unseccessful TX */
1011 #define HOST_LCC_PAYLOAD (1 << 4) /* LLC payload, 0 = Ethertype */
1012 #define HOST_DONT_RLSE (1 << 5) /* Don't release buffer when done */
1013 #define HOST_DONT_RETRY (1 << 6) /* Don't retry trasmit */
1014 #define HOST_CLR_AID (1 << 7) /* clear AID failure */
1015 #define HOST_RTS (1 << 9) /* Force RTS use */
1016 #define HOST_SHORT (1 << 10) /* Do short preamble */
1043 static WifiCtlHdr wifictlhdr8023 = {
1045 .ctl = HOST_DONT_RLSE,
1050 // Frequency list (map channels to frequencies)
1051 static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
1052 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
1054 // A few details needed for WEP (Wireless Equivalent Privacy)
1055 #define MAX_KEY_SIZE 13 // 128 (?) bits
1056 #define MIN_KEY_SIZE 5 // 40 bits RC4 - WEP
1057 typedef struct wep_key_t {
1059 u8 key[16]; /* 40-bit and 104-bit keys */
1062 /* Backward compatibility */
1063 #ifndef IW_ENCODE_NOKEY
1064 #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
1065 #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
1066 #endif /* IW_ENCODE_NOKEY */
1068 /* List of Wireless Handlers (new API) */
1069 static const struct iw_handler_def airo_handler_def;
1070 #endif /* WIRELESS_EXT */
1072 static const char version[] = "airo.c 0.6 (Ben Reed & Javier Achirica)";
1076 static int get_dec_u16( char *buffer, int *start, int limit );
1077 static void OUT4500( struct airo_info *, u16 register, u16 value );
1078 static unsigned short IN4500( struct airo_info *, u16 register );
1079 static u16 setup_card(struct airo_info*, u8 *mac, int lock);
1080 static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock );
1081 static void disable_MAC(struct airo_info *ai, int lock);
1082 static void enable_interrupts(struct airo_info*);
1083 static void disable_interrupts(struct airo_info*);
1084 static u16 issuecommand(struct airo_info*, Cmd *pCmd, Resp *pRsp);
1085 static int bap_setup(struct airo_info*, u16 rid, u16 offset, int whichbap);
1086 static int aux_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen,
1088 static int fast_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen,
1090 static int bap_write(struct airo_info*, const u16 *pu16Src, int bytelen,
1092 static int PC4500_accessrid(struct airo_info*, u16 rid, u16 accmd);
1093 static int PC4500_readrid(struct airo_info*, u16 rid, void *pBuf, int len, int lock);
1094 static int PC4500_writerid(struct airo_info*, u16 rid, const void
1095 *pBuf, int len, int lock);
1096 static int do_writerid( struct airo_info*, u16 rid, const void *rid_data,
1097 int len, int dummy );
1098 static u16 transmit_allocate(struct airo_info*, int lenPayload, int raw);
1099 static int transmit_802_3_packet(struct airo_info*, int len, char *pPacket);
1100 static int transmit_802_11_packet(struct airo_info*, int len, char *pPacket);
1102 static int mpi_send_packet (struct net_device *dev);
1103 static void mpi_unmap_card(struct pci_dev *pci);
1104 static void mpi_receive_802_3(struct airo_info *ai);
1105 static void mpi_receive_802_11(struct airo_info *ai);
1106 static int waitbusy (struct airo_info *ai);
1108 static irqreturn_t airo_interrupt( int irq, void* dev_id, struct pt_regs
1110 static int airo_thread(void *data);
1111 static void timer_func( struct net_device *dev );
1112 static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
1114 static struct iw_statistics *airo_get_wireless_stats (struct net_device *dev);
1115 static void airo_read_wireless_stats (struct airo_info *local);
1116 #endif /* WIRELESS_EXT */
1118 static int readrids(struct net_device *dev, aironet_ioctl *comp);
1119 static int writerids(struct net_device *dev, aironet_ioctl *comp);
1120 static int flashcard(struct net_device *dev, aironet_ioctl *comp);
1121 #endif /* CISCO_EXT */
1123 static void micinit(struct airo_info *ai);
1124 static int micsetup(struct airo_info *ai);
1125 static int encapsulate(struct airo_info *ai, etherHead *pPacket, MICBuffer *buffer, int len);
1126 static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *pPacket, u16 payLen);
1128 static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi);
1129 static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm);
1131 #include <linux/crypto.h>
1135 struct net_device_stats stats;
1136 struct net_device *dev;
1137 /* Note, we can have MAX_FIDS outstanding. FIDs are 16-bits, so we
1138 use the high bit to mark whether it is in use. */
1140 #define MPI_MAX_FIDS 1
1143 char keyindex; // Used with auto wep
1144 char defindex; // Used with auto wep
1145 struct proc_dir_entry *proc_entry;
1146 spinlock_t aux_lock;
1147 unsigned long flags;
1148 #define FLAG_PROMISC 8 /* IFF_PROMISC 0x100 - include/linux/if.h */
1149 #define FLAG_RADIO_OFF 0 /* User disabling of MAC */
1150 #define FLAG_RADIO_DOWN 1 /* ifup/ifdown disabling of MAC */
1151 #define FLAG_RADIO_MASK 0x03
1152 #define FLAG_ENABLED 2
1153 #define FLAG_ADHOC 3 /* Needed by MIC */
1154 #define FLAG_MIC_CAPABLE 4
1155 #define FLAG_UPDATE_MULTI 5
1156 #define FLAG_UPDATE_UNI 6
1157 #define FLAG_802_11 7
1158 #define FLAG_PENDING_XMIT 9
1159 #define FLAG_PENDING_XMIT11 10
1161 #define FLAG_REGISTERED 12
1162 #define FLAG_COMMIT 13
1163 #define FLAG_RESET 14
1164 #define FLAG_FLASHING 15
1165 #define JOB_MASK 0x1ff0000
1168 #define JOB_XMIT11 18
1169 #define JOB_STATS 19
1170 #define JOB_PROMISC 20
1172 #define JOB_EVENT 22
1173 #define JOB_AUTOWEP 23
1174 #define JOB_WSTATS 24
1175 int (*bap_read)(struct airo_info*, u16 *pu16Dst, int bytelen,
1177 unsigned short *flash;
1179 struct task_struct *task;
1180 struct semaphore sem;
1182 wait_queue_head_t thr_wait;
1183 struct completion thr_exited;
1184 unsigned long expires;
1186 struct sk_buff *skb;
1189 struct net_device *wifidev;
1191 struct iw_statistics wstats; // wireless stats
1192 unsigned long scan_timestamp; /* Time started to scan */
1193 struct iw_spy_data spy_data;
1194 struct iw_public_data wireless_data;
1195 #endif /* WIRELESS_EXT */
1198 struct crypto_tfm *tfm;
1200 mic_statistics micstats;
1202 HostRxDesc rxfids[MPI_MAX_FIDS]; // rx/tx/config MPI350 descriptors
1203 HostTxDesc txfids[MPI_MAX_FIDS];
1204 HostRidDesc config_desc;
1205 unsigned long ridbus; // phys addr of config_desc
1206 struct sk_buff_head txq;// tx queue used by mpi350 code
1207 struct pci_dev *pci;
1208 unsigned char __iomem *pcimem;
1209 unsigned char __iomem *pciaux;
1210 unsigned char *shared;
1211 dma_addr_t shared_dma;
1215 #define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE
1216 char proc_name[IFNAMSIZ];
1219 static inline int bap_read(struct airo_info *ai, u16 *pu16Dst, int bytelen,
1221 return ai->bap_read(ai, pu16Dst, bytelen, whichbap);
1224 static int setup_proc_entry( struct net_device *dev,
1225 struct airo_info *apriv );
1226 static int takedown_proc_entry( struct net_device *dev,
1227 struct airo_info *apriv );
1229 static int cmdreset(struct airo_info *ai);
1230 static int setflashmode (struct airo_info *ai);
1231 static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime);
1232 static int flashputbuf(struct airo_info *ai);
1233 static int flashrestart(struct airo_info *ai,struct net_device *dev);
1236 /***********************************************************************
1238 ***********************************************************************
1241 static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq);
1242 static void MoveWindow(miccntx *context, u32 micSeq);
1243 static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *);
1244 static void emmh32_init(emmh32_context *context);
1245 static void emmh32_update(emmh32_context *context, u8 *pOctets, int len);
1246 static void emmh32_final(emmh32_context *context, u8 digest[4]);
1247 static int flashpchar(struct airo_info *ai,int byte,int dwelltime);
1249 /* micinit - Initialize mic seed */
1251 static void micinit(struct airo_info *ai)
1255 clear_bit(JOB_MIC, &ai->flags);
1256 PC4500_readrid(ai, RID_MIC, &mic_rid, sizeof(mic_rid), 0);
1259 ai->micstats.enabled = (mic_rid.state & 0x00FF) ? 1 : 0;
1261 if (ai->micstats.enabled) {
1262 /* Key must be valid and different */
1263 if (mic_rid.multicastValid && (!ai->mod[0].mCtx.valid ||
1264 (memcmp (ai->mod[0].mCtx.key, mic_rid.multicast,
1265 sizeof(ai->mod[0].mCtx.key)) != 0))) {
1266 /* Age current mic Context */
1267 memcpy(&ai->mod[1].mCtx,&ai->mod[0].mCtx,sizeof(miccntx));
1268 /* Initialize new context */
1269 memcpy(&ai->mod[0].mCtx.key,mic_rid.multicast,sizeof(mic_rid.multicast));
1270 ai->mod[0].mCtx.window = 33; //Window always points to the middle
1271 ai->mod[0].mCtx.rx = 0; //Rx Sequence numbers
1272 ai->mod[0].mCtx.tx = 0; //Tx sequence numbers
1273 ai->mod[0].mCtx.valid = 1; //Key is now valid
1275 /* Give key to mic seed */
1276 emmh32_setseed(&ai->mod[0].mCtx.seed,mic_rid.multicast,sizeof(mic_rid.multicast), ai->tfm);
1279 /* Key must be valid and different */
1280 if (mic_rid.unicastValid && (!ai->mod[0].uCtx.valid ||
1281 (memcmp(ai->mod[0].uCtx.key, mic_rid.unicast,
1282 sizeof(ai->mod[0].uCtx.key)) != 0))) {
1283 /* Age current mic Context */
1284 memcpy(&ai->mod[1].uCtx,&ai->mod[0].uCtx,sizeof(miccntx));
1285 /* Initialize new context */
1286 memcpy(&ai->mod[0].uCtx.key,mic_rid.unicast,sizeof(mic_rid.unicast));
1288 ai->mod[0].uCtx.window = 33; //Window always points to the middle
1289 ai->mod[0].uCtx.rx = 0; //Rx Sequence numbers
1290 ai->mod[0].uCtx.tx = 0; //Tx sequence numbers
1291 ai->mod[0].uCtx.valid = 1; //Key is now valid
1293 //Give key to mic seed
1294 emmh32_setseed(&ai->mod[0].uCtx.seed, mic_rid.unicast, sizeof(mic_rid.unicast), ai->tfm);
1297 /* So next time we have a valid key and mic is enabled, we will update
1298 * the sequence number if the key is the same as before.
1300 ai->mod[0].uCtx.valid = 0;
1301 ai->mod[0].mCtx.valid = 0;
1305 /* micsetup - Get ready for business */
1307 static int micsetup(struct airo_info *ai) {
1310 if (ai->tfm == NULL)
1311 ai->tfm = crypto_alloc_tfm("aes", 0);
1313 if (ai->tfm == NULL) {
1314 printk(KERN_ERR "airo: failed to load transform for AES\n");
1318 for (i=0; i < NUM_MODULES; i++) {
1319 memset(&ai->mod[i].mCtx,0,sizeof(miccntx));
1320 memset(&ai->mod[i].uCtx,0,sizeof(miccntx));
1325 static char micsnap[] = {0xAA,0xAA,0x03,0x00,0x40,0x96,0x00,0x02};
1327 /*===========================================================================
1328 * Description: Mic a packet
1330 * Inputs: etherHead * pointer to an 802.3 frame
1332 * Returns: BOOLEAN if successful, otherwise false.
1333 * PacketTxLen will be updated with the mic'd packets size.
1335 * Caveats: It is assumed that the frame buffer will already
1336 * be big enough to hold the largets mic message possible.
1337 * (No memory allocation is done here).
1339 * Author: sbraneky (10/15/01)
1340 * Merciless hacks by rwilcher (1/14/02)
1343 static int encapsulate(struct airo_info *ai ,etherHead *frame, MICBuffer *mic, int payLen)
1347 // Determine correct context
1348 // If not adhoc, always use unicast key
1350 if (test_bit(FLAG_ADHOC, &ai->flags) && (frame->da[0] & 0x1))
1351 context = &ai->mod[0].mCtx;
1353 context = &ai->mod[0].uCtx;
1355 if (!context->valid)
1358 mic->typelen = htons(payLen + 16); //Length of Mic'd packet
1360 memcpy(&mic->u.snap, micsnap, sizeof(micsnap)); // Add Snap
1363 mic->seq = htonl(context->tx);
1366 emmh32_init(&context->seed); // Mic the packet
1367 emmh32_update(&context->seed,frame->da,ETH_ALEN * 2); // DA,SA
1368 emmh32_update(&context->seed,(u8*)&mic->typelen,10); // Type/Length and Snap
1369 emmh32_update(&context->seed,(u8*)&mic->seq,sizeof(mic->seq)); //SEQ
1370 emmh32_update(&context->seed,frame->da + ETH_ALEN * 2,payLen); //payload
1371 emmh32_final(&context->seed, (u8*)&mic->mic);
1373 /* New Type/length ?????????? */
1374 mic->typelen = 0; //Let NIC know it could be an oversized packet
1386 /*===========================================================================
1387 * Description: Decapsulates a MIC'd packet and returns the 802.3 packet
1388 * (removes the MIC stuff) if packet is a valid packet.
1390 * Inputs: etherHead pointer to the 802.3 packet
1392 * Returns: BOOLEAN - TRUE if packet should be dropped otherwise FALSE
1394 * Author: sbraneky (10/15/01)
1395 * Merciless hacks by rwilcher (1/14/02)
1396 *---------------------------------------------------------------------------
1399 static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *eth, u16 payLen)
1405 mic_error micError = NONE;
1407 // Check if the packet is a Mic'd packet
1409 if (!ai->micstats.enabled) {
1410 //No Mic set or Mic OFF but we received a MIC'd packet.
1411 if (memcmp ((u8*)eth + 14, micsnap, sizeof(micsnap)) == 0) {
1412 ai->micstats.rxMICPlummed++;
1418 if (ntohs(mic->typelen) == 0x888E)
1421 if (memcmp (mic->u.snap, micsnap, sizeof(micsnap)) != 0) {
1422 // Mic enabled but packet isn't Mic'd
1423 ai->micstats.rxMICPlummed++;
1427 micSEQ = ntohl(mic->seq); //store SEQ as CPU order
1429 //At this point we a have a mic'd packet and mic is enabled
1430 //Now do the mic error checking.
1432 //Receive seq must be odd
1433 if ( (micSEQ & 1) == 0 ) {
1434 ai->micstats.rxWrongSequence++;
1438 for (i = 0; i < NUM_MODULES; i++) {
1439 int mcast = eth->da[0] & 1;
1440 //Determine proper context
1441 context = mcast ? &ai->mod[i].mCtx : &ai->mod[i].uCtx;
1443 //Make sure context is valid
1444 if (!context->valid) {
1446 micError = NOMICPLUMMED;
1452 mic->typelen = htons(payLen + sizeof(MICBuffer) - 2);
1454 emmh32_init(&context->seed);
1455 emmh32_update(&context->seed, eth->da, ETH_ALEN*2);
1456 emmh32_update(&context->seed, (u8 *)&mic->typelen, sizeof(mic->typelen)+sizeof(mic->u.snap));
1457 emmh32_update(&context->seed, (u8 *)&mic->seq,sizeof(mic->seq));
1458 emmh32_update(&context->seed, eth->da + ETH_ALEN*2,payLen);
1460 emmh32_final(&context->seed, digest);
1462 if (memcmp(digest, &mic->mic, 4)) { //Make sure the mics match
1465 micError = INCORRECTMIC;
1469 //Check Sequence number if mics pass
1470 if (RxSeqValid(ai, context, mcast, micSEQ) == SUCCESS) {
1471 ai->micstats.rxSuccess++;
1475 micError = SEQUENCE;
1478 // Update statistics
1480 case NOMICPLUMMED: ai->micstats.rxMICPlummed++; break;
1481 case SEQUENCE: ai->micstats.rxWrongSequence++; break;
1482 case INCORRECTMIC: ai->micstats.rxIncorrectMIC++; break;
1489 /*===========================================================================
1490 * Description: Checks the Rx Seq number to make sure it is valid
1491 * and hasn't already been received
1493 * Inputs: miccntx - mic context to check seq against
1494 * micSeq - the Mic seq number
1496 * Returns: TRUE if valid otherwise FALSE.
1498 * Author: sbraneky (10/15/01)
1499 * Merciless hacks by rwilcher (1/14/02)
1500 *---------------------------------------------------------------------------
1503 static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq)
1507 //Allow for the ap being rebooted - if it is then use the next
1508 //sequence number of the current sequence number - might go backwards
1511 if (test_bit(FLAG_UPDATE_MULTI, &ai->flags)) {
1512 clear_bit (FLAG_UPDATE_MULTI, &ai->flags);
1513 context->window = (micSeq > 33) ? micSeq : 33;
1514 context->rx = 0; // Reset rx
1516 } else if (test_bit(FLAG_UPDATE_UNI, &ai->flags)) {
1517 clear_bit (FLAG_UPDATE_UNI, &ai->flags);
1518 context->window = (micSeq > 33) ? micSeq : 33; // Move window
1519 context->rx = 0; // Reset rx
1522 //Make sequence number relative to START of window
1523 seq = micSeq - (context->window - 33);
1525 //Too old of a SEQ number to check.
1530 //Window is infinite forward
1531 MoveWindow(context,micSeq);
1535 // We are in the window. Now check the context rx bit to see if it was already sent
1536 seq >>= 1; //divide by 2 because we only have odd numbers
1537 index = 1 << seq; //Get an index number
1539 if (!(context->rx & index)) {
1540 //micSEQ falls inside the window.
1541 //Add seqence number to the list of received numbers.
1542 context->rx |= index;
1544 MoveWindow(context,micSeq);
1551 static void MoveWindow(miccntx *context, u32 micSeq)
1555 //Move window if seq greater than the middle of the window
1556 if (micSeq > context->window) {
1557 shift = (micSeq - context->window) >> 1;
1561 context->rx >>= shift;
1565 context->window = micSeq; //Move window
1569 /*==============================================*/
1570 /*========== EMMH ROUTINES ====================*/
1571 /*==============================================*/
1573 /* mic accumulate */
1574 #define MIC_ACCUM(val) \
1575 context->accum += (u64)(val) * context->coeff[coeff_position++];
1577 static unsigned char aes_counter[16];
1579 /* expand the key to fill the MMH coefficient array */
1580 static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *tfm)
1582 /* take the keying material, expand if necessary, truncate at 16-bytes */
1583 /* run through AES counter mode to generate context->coeff[] */
1587 u8 *cipher, plain[16];
1588 struct scatterlist sg[1];
1590 crypto_cipher_setkey(tfm, pkey, 16);
1592 for (i = 0; i < (sizeof(context->coeff)/sizeof(context->coeff[0])); ) {
1593 aes_counter[15] = (u8)(counter >> 0);
1594 aes_counter[14] = (u8)(counter >> 8);
1595 aes_counter[13] = (u8)(counter >> 16);
1596 aes_counter[12] = (u8)(counter >> 24);
1598 memcpy (plain, aes_counter, 16);
1599 sg[0].page = virt_to_page(plain);
1600 sg[0].offset = ((long) plain & ~PAGE_MASK);
1602 crypto_cipher_encrypt(tfm, sg, sg, 16);
1603 cipher = kmap(sg[0].page) + sg[0].offset;
1604 for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) {
1605 context->coeff[i++] = ntohl(*(u32 *)&cipher[j]);
1611 /* prepare for calculation of a new mic */
1612 static void emmh32_init(emmh32_context *context)
1614 /* prepare for new mic calculation */
1616 context->position = 0;
1619 /* add some bytes to the mic calculation */
1620 static void emmh32_update(emmh32_context *context, u8 *pOctets, int len)
1622 int coeff_position, byte_position;
1624 if (len == 0) return;
1626 coeff_position = context->position >> 2;
1628 /* deal with partial 32-bit word left over from last update */
1629 byte_position = context->position & 3;
1630 if (byte_position) {
1631 /* have a partial word in part to deal with */
1633 if (len == 0) return;
1634 context->part.d8[byte_position++] = *pOctets++;
1635 context->position++;
1637 } while (byte_position < 4);
1638 MIC_ACCUM(htonl(context->part.d32));
1641 /* deal with full 32-bit words */
1643 MIC_ACCUM(htonl(*(u32 *)pOctets));
1644 context->position += 4;
1649 /* deal with partial 32-bit word that will be left over from this update */
1652 context->part.d8[byte_position++] = *pOctets++;
1653 context->position++;
1658 /* mask used to zero empty bytes for final partial word */
1659 static u32 mask32[4] = { 0x00000000L, 0xFF000000L, 0xFFFF0000L, 0xFFFFFF00L };
1661 /* calculate the mic */
1662 static void emmh32_final(emmh32_context *context, u8 digest[4])
1664 int coeff_position, byte_position;
1670 coeff_position = context->position >> 2;
1672 /* deal with partial 32-bit word left over from last update */
1673 byte_position = context->position & 3;
1674 if (byte_position) {
1675 /* have a partial word in part to deal with */
1676 val = htonl(context->part.d32);
1677 MIC_ACCUM(val & mask32[byte_position]); /* zero empty bytes */
1680 /* reduce the accumulated u64 to a 32-bit MIC */
1681 sum = context->accum;
1682 stmp = (sum & 0xffffffffLL) - ((sum >> 32) * 15);
1683 utmp = (stmp & 0xffffffffLL) - ((stmp >> 32) * 15);
1684 sum = utmp & 0xffffffffLL;
1685 if (utmp > 0x10000000fLL)
1689 digest[0] = (val>>24) & 0xFF;
1690 digest[1] = (val>>16) & 0xFF;
1691 digest[2] = (val>>8) & 0xFF;
1692 digest[3] = val & 0xFF;
1696 static int readBSSListRid(struct airo_info *ai, int first,
1703 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
1704 memset(&cmd, 0, sizeof(cmd));
1705 cmd.cmd=CMD_LISTBSS;
1706 if (down_interruptible(&ai->sem))
1707 return -ERESTARTSYS;
1708 issuecommand(ai, &cmd, &rsp);
1710 /* Let the command take effect */
1715 rc = PC4500_readrid(ai, first ? RID_BSSLISTFIRST : RID_BSSLISTNEXT,
1716 list, sizeof(*list), 1);
1718 list->len = le16_to_cpu(list->len);
1719 list->index = le16_to_cpu(list->index);
1720 list->radioType = le16_to_cpu(list->radioType);
1721 list->cap = le16_to_cpu(list->cap);
1722 list->beaconInterval = le16_to_cpu(list->beaconInterval);
1723 list->fh.dwell = le16_to_cpu(list->fh.dwell);
1724 list->dsChannel = le16_to_cpu(list->dsChannel);
1725 list->atimWindow = le16_to_cpu(list->atimWindow);
1726 list->dBm = le16_to_cpu(list->dBm);
1730 static int readWepKeyRid(struct airo_info*ai, WepKeyRid *wkr, int temp, int lock) {
1731 int rc = PC4500_readrid(ai, temp ? RID_WEP_TEMP : RID_WEP_PERM,
1732 wkr, sizeof(*wkr), lock);
1734 wkr->len = le16_to_cpu(wkr->len);
1735 wkr->kindex = le16_to_cpu(wkr->kindex);
1736 wkr->klen = le16_to_cpu(wkr->klen);
1739 /* In the writeXXXRid routines we copy the rids so that we don't screwup
1740 * the originals when we endian them... */
1741 static int writeWepKeyRid(struct airo_info*ai, WepKeyRid *pwkr, int perm, int lock) {
1743 WepKeyRid wkr = *pwkr;
1745 wkr.len = cpu_to_le16(wkr.len);
1746 wkr.kindex = cpu_to_le16(wkr.kindex);
1747 wkr.klen = cpu_to_le16(wkr.klen);
1748 rc = PC4500_writerid(ai, RID_WEP_TEMP, &wkr, sizeof(wkr), lock);
1749 if (rc!=SUCCESS) printk(KERN_ERR "airo: WEP_TEMP set %x\n", rc);
1751 rc = PC4500_writerid(ai, RID_WEP_PERM, &wkr, sizeof(wkr), lock);
1753 printk(KERN_ERR "airo: WEP_PERM set %x\n", rc);
1759 static int readSsidRid(struct airo_info*ai, SsidRid *ssidr) {
1761 int rc = PC4500_readrid(ai, RID_SSID, ssidr, sizeof(*ssidr), 1);
1763 ssidr->len = le16_to_cpu(ssidr->len);
1764 for(i = 0; i < 3; i++) {
1765 ssidr->ssids[i].len = le16_to_cpu(ssidr->ssids[i].len);
1769 static int writeSsidRid(struct airo_info*ai, SsidRid *pssidr, int lock) {
1772 SsidRid ssidr = *pssidr;
1774 ssidr.len = cpu_to_le16(ssidr.len);
1775 for(i = 0; i < 3; i++) {
1776 ssidr.ssids[i].len = cpu_to_le16(ssidr.ssids[i].len);
1778 rc = PC4500_writerid(ai, RID_SSID, &ssidr, sizeof(ssidr), lock);
1781 static int readConfigRid(struct airo_info*ai, int lock) {
1789 rc = PC4500_readrid(ai, RID_ACTUALCONFIG, &cfg, sizeof(cfg), lock);
1793 for(s = &cfg.len; s <= &cfg.rtsThres; s++) *s = le16_to_cpu(*s);
1795 for(s = &cfg.shortRetryLimit; s <= &cfg.radioType; s++)
1796 *s = le16_to_cpu(*s);
1798 for(s = &cfg.txPower; s <= &cfg.radioSpecific; s++)
1799 *s = le16_to_cpu(*s);
1801 for(s = &cfg.arlThreshold; s <= &cfg._reserved4[0]; s++)
1802 *s = cpu_to_le16(*s);
1804 for(s = &cfg.autoWake; s <= &cfg.autoWake; s++)
1805 *s = cpu_to_le16(*s);
1810 static inline void checkThrottle(struct airo_info *ai) {
1812 /* Old hardware had a limit on encryption speed */
1813 if (ai->config.authType != AUTH_OPEN && maxencrypt) {
1814 for(i=0; i<8; i++) {
1815 if (ai->config.rates[i] > maxencrypt) {
1816 ai->config.rates[i] = 0;
1821 static int writeConfigRid(struct airo_info*ai, int lock) {
1825 if (!test_bit (FLAG_COMMIT, &ai->flags))
1828 clear_bit (FLAG_COMMIT, &ai->flags);
1829 clear_bit (FLAG_RESET, &ai->flags);
1833 if ((cfgr.opmode & 0xFF) == MODE_STA_IBSS)
1834 set_bit(FLAG_ADHOC, &ai->flags);
1836 clear_bit(FLAG_ADHOC, &ai->flags);
1838 for(s = &cfgr.len; s <= &cfgr.rtsThres; s++) *s = cpu_to_le16(*s);
1840 for(s = &cfgr.shortRetryLimit; s <= &cfgr.radioType; s++)
1841 *s = cpu_to_le16(*s);
1843 for(s = &cfgr.txPower; s <= &cfgr.radioSpecific; s++)
1844 *s = cpu_to_le16(*s);
1846 for(s = &cfgr.arlThreshold; s <= &cfgr._reserved4[0]; s++)
1847 *s = cpu_to_le16(*s);
1849 for(s = &cfgr.autoWake; s <= &cfgr.autoWake; s++)
1850 *s = cpu_to_le16(*s);
1852 return PC4500_writerid( ai, RID_CONFIG, &cfgr, sizeof(cfgr), lock);
1854 static int readStatusRid(struct airo_info*ai, StatusRid *statr, int lock) {
1855 int rc = PC4500_readrid(ai, RID_STATUS, statr, sizeof(*statr), lock);
1858 statr->len = le16_to_cpu(statr->len);
1859 for(s = &statr->mode; s <= &statr->SSIDlen; s++) *s = le16_to_cpu(*s);
1861 for(s = &statr->beaconPeriod; s <= &statr->shortPreamble; s++)
1862 *s = le16_to_cpu(*s);
1863 statr->load = le16_to_cpu(statr->load);
1864 statr->assocStatus = le16_to_cpu(statr->assocStatus);
1867 static int readAPListRid(struct airo_info*ai, APListRid *aplr) {
1868 int rc = PC4500_readrid(ai, RID_APLIST, aplr, sizeof(*aplr), 1);
1869 aplr->len = le16_to_cpu(aplr->len);
1872 static int writeAPListRid(struct airo_info*ai, APListRid *aplr, int lock) {
1874 aplr->len = cpu_to_le16(aplr->len);
1875 rc = PC4500_writerid(ai, RID_APLIST, aplr, sizeof(*aplr), lock);
1878 static int readCapabilityRid(struct airo_info*ai, CapabilityRid *capr, int lock) {
1879 int rc = PC4500_readrid(ai, RID_CAPABILITIES, capr, sizeof(*capr), lock);
1882 capr->len = le16_to_cpu(capr->len);
1883 capr->prodNum = le16_to_cpu(capr->prodNum);
1884 capr->radioType = le16_to_cpu(capr->radioType);
1885 capr->country = le16_to_cpu(capr->country);
1886 for(s = &capr->txPowerLevels[0]; s <= &capr->requiredHard; s++)
1887 *s = le16_to_cpu(*s);
1890 static int readStatsRid(struct airo_info*ai, StatsRid *sr, int rid, int lock) {
1891 int rc = PC4500_readrid(ai, rid, sr, sizeof(*sr), lock);
1894 sr->len = le16_to_cpu(sr->len);
1895 for(i = &sr->vals[0]; i <= &sr->vals[99]; i++) *i = le32_to_cpu(*i);
1899 static int airo_open(struct net_device *dev) {
1900 struct airo_info *info = dev->priv;
1903 if (test_bit(FLAG_FLASHING, &info->flags))
1906 /* Make sure the card is configured.
1907 * Wireless Extensions may postpone config changes until the card
1908 * is open (to pipeline changes and speed-up card setup). If
1909 * those changes are not yet commited, do it now - Jean II */
1910 if (test_bit (FLAG_COMMIT, &info->flags)) {
1911 disable_MAC(info, 1);
1912 writeConfigRid(info, 1);
1915 if (info->wifidev != dev) {
1916 /* Power on the MAC controller (which may have been disabled) */
1917 clear_bit(FLAG_RADIO_DOWN, &info->flags);
1918 enable_interrupts(info);
1920 enable_MAC(info, &rsp, 1);
1922 netif_start_queue(dev);
1926 static int mpi_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1927 int npacks, pending;
1928 unsigned long flags;
1929 struct airo_info *ai = dev->priv;
1932 printk(KERN_ERR "airo: %s: skb==NULL\n",__FUNCTION__);
1935 npacks = skb_queue_len (&ai->txq);
1937 if (npacks >= MAXTXQ - 1) {
1938 netif_stop_queue (dev);
1939 if (npacks > MAXTXQ) {
1940 ai->stats.tx_fifo_errors++;
1943 skb_queue_tail (&ai->txq, skb);
1947 spin_lock_irqsave(&ai->aux_lock, flags);
1948 skb_queue_tail (&ai->txq, skb);
1949 pending = test_bit(FLAG_PENDING_XMIT, &ai->flags);
1950 spin_unlock_irqrestore(&ai->aux_lock,flags);
1951 netif_wake_queue (dev);
1954 set_bit(FLAG_PENDING_XMIT, &ai->flags);
1955 mpi_send_packet (dev);
1963 * Attempt to transmit a packet. Can be called from interrupt
1964 * or transmit . return number of packets we tried to send
1967 static int mpi_send_packet (struct net_device *dev)
1969 struct sk_buff *skb;
1970 unsigned char *buffer;
1971 s16 len, *payloadLen;
1972 struct airo_info *ai = dev->priv;
1975 /* get a packet to send */
1977 if ((skb = skb_dequeue(&ai->txq)) == 0) {
1979 "airo: %s: Dequeue'd zero in send_packet()\n",
1984 /* check min length*/
1985 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1988 ai->txfids[0].tx_desc.offset = 0;
1989 ai->txfids[0].tx_desc.valid = 1;
1990 ai->txfids[0].tx_desc.eoc = 1;
1991 ai->txfids[0].tx_desc.len =len+sizeof(WifiHdr);
1994 * Magic, the cards firmware needs a length count (2 bytes) in the host buffer
1995 * right after TXFID_HDR.The TXFID_HDR contains the status short so payloadlen
1996 * is immediatly after it. ------------------------------------------------
1997 * |TXFIDHDR+STATUS|PAYLOADLEN|802.3HDR|PACKETDATA|
1998 * ------------------------------------------------
2001 memcpy((char *)ai->txfids[0].virtual_host_addr,
2002 (char *)&wifictlhdr8023, sizeof(wifictlhdr8023));
2004 payloadLen = (s16 *)(ai->txfids[0].virtual_host_addr +
2005 sizeof(wifictlhdr8023));
2006 sendbuf = ai->txfids[0].virtual_host_addr +
2007 sizeof(wifictlhdr8023) + 2 ;
2010 * Firmware automaticly puts 802 header on so
2011 * we don't need to account for it in the length
2014 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
2015 (ntohs(((u16 *)buffer)[6]) != 0x888E)) {
2018 if (encapsulate(ai, (etherHead *)buffer, &pMic, len - sizeof(etherHead)) != SUCCESS)
2021 *payloadLen = cpu_to_le16(len-sizeof(etherHead)+sizeof(pMic));
2022 ai->txfids[0].tx_desc.len += sizeof(pMic);
2023 /* copy data into airo dma buffer */
2024 memcpy (sendbuf, buffer, sizeof(etherHead));
2025 buffer += sizeof(etherHead);
2026 sendbuf += sizeof(etherHead);
2027 memcpy (sendbuf, &pMic, sizeof(pMic));
2028 sendbuf += sizeof(pMic);
2029 memcpy (sendbuf, buffer, len - sizeof(etherHead));
2033 *payloadLen = cpu_to_le16(len - sizeof(etherHead));
2035 dev->trans_start = jiffies;
2037 /* copy data into airo dma buffer */
2038 memcpy(sendbuf, buffer, len);
2041 memcpy_toio(ai->txfids[0].card_ram_off,
2042 &ai->txfids[0].tx_desc, sizeof(TxFid));
2044 OUT4500(ai, EVACK, 8);
2046 dev_kfree_skb_any(skb);
2050 static void get_tx_error(struct airo_info *ai, u32 fid)
2055 status = ((WifiCtlHdr *)ai->txfids[0].virtual_host_addr)->ctlhdr.status;
2057 if (bap_setup(ai, ai->fids[fid] & 0xffff, 4, BAP0) != SUCCESS)
2059 bap_read(ai, &status, 2, BAP0);
2061 if (le16_to_cpu(status) & 2) /* Too many retries */
2062 ai->stats.tx_aborted_errors++;
2063 if (le16_to_cpu(status) & 4) /* Transmit lifetime exceeded */
2064 ai->stats.tx_heartbeat_errors++;
2065 if (le16_to_cpu(status) & 8) /* Aid fail */
2067 if (le16_to_cpu(status) & 0x10) /* MAC disabled */
2068 ai->stats.tx_carrier_errors++;
2069 if (le16_to_cpu(status) & 0x20) /* Association lost */
2071 /* We produce a TXDROP event only for retry or lifetime
2072 * exceeded, because that's the only status that really mean
2073 * that this particular node went away.
2074 * Other errors means that *we* screwed up. - Jean II */
2075 if ((le16_to_cpu(status) & 2) ||
2076 (le16_to_cpu(status) & 4)) {
2077 union iwreq_data wrqu;
2080 /* Faster to skip over useless data than to do
2081 * another bap_setup(). We are at offset 0x6 and
2082 * need to go to 0x18 and read 6 bytes - Jean II */
2083 bap_read(ai, (u16 *) junk, 0x18, BAP0);
2085 /* Copy 802.11 dest address.
2086 * We use the 802.11 header because the frame may
2087 * not be 802.3 or may be mangled...
2088 * In Ad-Hoc mode, it will be the node address.
2089 * In managed mode, it will be most likely the AP addr
2090 * User space will figure out how to convert it to
2091 * whatever it needs (IP address or else).
2093 memcpy(wrqu.addr.sa_data, junk + 0x12, ETH_ALEN);
2094 wrqu.addr.sa_family = ARPHRD_ETHER;
2096 /* Send event to user space */
2097 wireless_send_event(ai->dev, IWEVTXDROP, &wrqu, NULL);
2101 static void airo_end_xmit(struct net_device *dev) {
2104 struct airo_info *priv = dev->priv;
2105 struct sk_buff *skb = priv->xmit.skb;
2106 int fid = priv->xmit.fid;
2107 u32 *fids = priv->fids;
2109 clear_bit(JOB_XMIT, &priv->flags);
2110 clear_bit(FLAG_PENDING_XMIT, &priv->flags);
2111 status = transmit_802_3_packet (priv, fids[fid], skb->data);
2115 if ( status == SUCCESS ) {
2116 dev->trans_start = jiffies;
2117 for (; i < MAX_FIDS / 2 && (priv->fids[i] & 0xffff0000); i++);
2119 priv->fids[fid] &= 0xffff;
2120 priv->stats.tx_window_errors++;
2122 if (i < MAX_FIDS / 2)
2123 netif_wake_queue(dev);
2127 static int airo_start_xmit(struct sk_buff *skb, struct net_device *dev) {
2130 struct airo_info *priv = dev->priv;
2131 u32 *fids = priv->fids;
2133 if ( skb == NULL ) {
2134 printk( KERN_ERR "airo: skb == NULL!!!\n" );
2138 /* Find a vacant FID */
2139 for( i = 0; i < MAX_FIDS / 2 && (fids[i] & 0xffff0000); i++ );
2140 for( j = i + 1; j < MAX_FIDS / 2 && (fids[j] & 0xffff0000); j++ );
2142 if ( j >= MAX_FIDS / 2 ) {
2143 netif_stop_queue(dev);
2145 if (i == MAX_FIDS / 2) {
2146 priv->stats.tx_fifo_errors++;
2150 /* check min length*/
2151 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
2152 /* Mark fid as used & save length for later */
2153 fids[i] |= (len << 16);
2154 priv->xmit.skb = skb;
2156 if (down_trylock(&priv->sem) != 0) {
2157 set_bit(FLAG_PENDING_XMIT, &priv->flags);
2158 netif_stop_queue(dev);
2159 set_bit(JOB_XMIT, &priv->flags);
2160 wake_up_interruptible(&priv->thr_wait);
2166 static void airo_end_xmit11(struct net_device *dev) {
2169 struct airo_info *priv = dev->priv;
2170 struct sk_buff *skb = priv->xmit11.skb;
2171 int fid = priv->xmit11.fid;
2172 u32 *fids = priv->fids;
2174 clear_bit(JOB_XMIT11, &priv->flags);
2175 clear_bit(FLAG_PENDING_XMIT11, &priv->flags);
2176 status = transmit_802_11_packet (priv, fids[fid], skb->data);
2180 if ( status == SUCCESS ) {
2181 dev->trans_start = jiffies;
2182 for (; i < MAX_FIDS && (priv->fids[i] & 0xffff0000); i++);
2184 priv->fids[fid] &= 0xffff;
2185 priv->stats.tx_window_errors++;
2188 netif_wake_queue(dev);
2192 static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) {
2195 struct airo_info *priv = dev->priv;
2196 u32 *fids = priv->fids;
2198 if (test_bit(FLAG_MPI, &priv->flags)) {
2199 /* Not implemented yet for MPI350 */
2200 netif_stop_queue(dev);
2204 if ( skb == NULL ) {
2205 printk( KERN_ERR "airo: skb == NULL!!!\n" );
2209 /* Find a vacant FID */
2210 for( i = MAX_FIDS / 2; i < MAX_FIDS && (fids[i] & 0xffff0000); i++ );
2211 for( j = i + 1; j < MAX_FIDS && (fids[j] & 0xffff0000); j++ );
2213 if ( j >= MAX_FIDS ) {
2214 netif_stop_queue(dev);
2216 if (i == MAX_FIDS) {
2217 priv->stats.tx_fifo_errors++;
2221 /* check min length*/
2222 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
2223 /* Mark fid as used & save length for later */
2224 fids[i] |= (len << 16);
2225 priv->xmit11.skb = skb;
2226 priv->xmit11.fid = i;
2227 if (down_trylock(&priv->sem) != 0) {
2228 set_bit(FLAG_PENDING_XMIT11, &priv->flags);
2229 netif_stop_queue(dev);
2230 set_bit(JOB_XMIT11, &priv->flags);
2231 wake_up_interruptible(&priv->thr_wait);
2233 airo_end_xmit11(dev);
2237 static void airo_read_stats(struct airo_info *ai) {
2239 u32 *vals = stats_rid.vals;
2241 clear_bit(JOB_STATS, &ai->flags);
2246 readStatsRid(ai, &stats_rid, RID_STATS, 0);
2249 ai->stats.rx_packets = vals[43] + vals[44] + vals[45];
2250 ai->stats.tx_packets = vals[39] + vals[40] + vals[41];
2251 ai->stats.rx_bytes = vals[92];
2252 ai->stats.tx_bytes = vals[91];
2253 ai->stats.rx_errors = vals[0] + vals[2] + vals[3] + vals[4];
2254 ai->stats.tx_errors = vals[42] + ai->stats.tx_fifo_errors;
2255 ai->stats.multicast = vals[43];
2256 ai->stats.collisions = vals[89];
2258 /* detailed rx_errors: */
2259 ai->stats.rx_length_errors = vals[3];
2260 ai->stats.rx_crc_errors = vals[4];
2261 ai->stats.rx_frame_errors = vals[2];
2262 ai->stats.rx_fifo_errors = vals[0];
2265 static struct net_device_stats *airo_get_stats(struct net_device *dev)
2267 struct airo_info *local = dev->priv;
2269 if (!test_bit(JOB_STATS, &local->flags)) {
2270 /* Get stats out of the card if available */
2271 if (down_trylock(&local->sem) != 0) {
2272 set_bit(JOB_STATS, &local->flags);
2273 wake_up_interruptible(&local->thr_wait);
2275 airo_read_stats(local);
2278 return &local->stats;
2281 static void airo_set_promisc(struct airo_info *ai) {
2285 memset(&cmd, 0, sizeof(cmd));
2286 cmd.cmd=CMD_SETMODE;
2287 clear_bit(JOB_PROMISC, &ai->flags);
2288 cmd.parm0=(ai->flags&IFF_PROMISC) ? PROMISC : NOPROMISC;
2289 issuecommand(ai, &cmd, &rsp);
2293 static void airo_set_multicast_list(struct net_device *dev) {
2294 struct airo_info *ai = dev->priv;
2296 if ((dev->flags ^ ai->flags) & IFF_PROMISC) {
2297 change_bit(FLAG_PROMISC, &ai->flags);
2298 if (down_trylock(&ai->sem) != 0) {
2299 set_bit(JOB_PROMISC, &ai->flags);
2300 wake_up_interruptible(&ai->thr_wait);
2302 airo_set_promisc(ai);
2305 if ((dev->flags&IFF_ALLMULTI)||dev->mc_count>0) {
2306 /* Turn on multicast. (Should be already setup...) */
2310 static int airo_set_mac_address(struct net_device *dev, void *p)
2312 struct airo_info *ai = dev->priv;
2313 struct sockaddr *addr = p;
2316 readConfigRid(ai, 1);
2317 memcpy (ai->config.macAddr, addr->sa_data, dev->addr_len);
2318 set_bit (FLAG_COMMIT, &ai->flags);
2320 writeConfigRid (ai, 1);
2321 enable_MAC(ai, &rsp, 1);
2322 memcpy (ai->dev->dev_addr, addr->sa_data, dev->addr_len);
2324 memcpy (ai->wifidev->dev_addr, addr->sa_data, dev->addr_len);
2328 static int airo_change_mtu(struct net_device *dev, int new_mtu)
2330 if ((new_mtu < 68) || (new_mtu > 2400))
2337 static int airo_close(struct net_device *dev) {
2338 struct airo_info *ai = dev->priv;
2340 netif_stop_queue(dev);
2342 if (ai->wifidev != dev) {
2343 #ifdef POWER_ON_DOWN
2344 /* Shut power to the card. The idea is that the user can save
2345 * power when he doesn't need the card with "ifconfig down".
2346 * That's the method that is most friendly towards the network
2347 * stack (i.e. the network stack won't try to broadcast
2348 * anything on the interface and routes are gone. Jean II */
2349 set_bit(FLAG_RADIO_DOWN, &ai->flags);
2352 disable_interrupts( ai );
2357 static void del_airo_dev( struct net_device *dev );
2359 void stop_airo_card( struct net_device *dev, int freeres )
2361 struct airo_info *ai = dev->priv;
2363 set_bit(FLAG_RADIO_DOWN, &ai->flags);
2365 disable_interrupts(ai);
2366 free_irq( dev->irq, dev );
2367 takedown_proc_entry( dev, ai );
2368 if (test_bit(FLAG_REGISTERED, &ai->flags)) {
2369 unregister_netdev( dev );
2371 unregister_netdev(ai->wifidev);
2372 free_netdev(ai->wifidev);
2375 clear_bit(FLAG_REGISTERED, &ai->flags);
2377 set_bit(JOB_DIE, &ai->flags);
2378 kill_proc(ai->thr_pid, SIGTERM, 1);
2379 wait_for_completion(&ai->thr_exited);
2382 * Clean out tx queue
2384 if (test_bit(FLAG_MPI, &ai->flags) && !skb_queue_empty(&ai->txq)) {
2385 struct sk_buff *skb = NULL;
2386 for (;(skb = skb_dequeue(&ai->txq));)
2399 /* PCMCIA frees this stuff, so only for PCI and ISA */
2400 release_region( dev->base_addr, 64 );
2401 if (test_bit(FLAG_MPI, &ai->flags)) {
2403 mpi_unmap_card(ai->pci);
2405 iounmap(ai->pcimem);
2407 iounmap(ai->pciaux);
2408 pci_free_consistent(ai->pci, PCI_SHARED_LEN,
2409 ai->shared, ai->shared_dma);
2414 crypto_free_tfm(ai->tfm);
2416 del_airo_dev( dev );
2420 EXPORT_SYMBOL(stop_airo_card);
2422 static int add_airo_dev( struct net_device *dev );
2424 static int wll_header_parse(struct sk_buff *skb, unsigned char *haddr)
2426 memcpy(haddr, skb->mac.raw + 10, ETH_ALEN);
2430 static void mpi_unmap_card(struct pci_dev *pci)
2432 unsigned long mem_start = pci_resource_start(pci, 1);
2433 unsigned long mem_len = pci_resource_len(pci, 1);
2434 unsigned long aux_start = pci_resource_start(pci, 2);
2435 unsigned long aux_len = AUXMEMSIZE;
2437 release_mem_region(aux_start, aux_len);
2438 release_mem_region(mem_start, mem_len);
2441 /*************************************************************
2442 * This routine assumes that descriptors have been setup .
2443 * Run at insmod time or after reset when the decriptors
2444 * have been initialized . Returns 0 if all is well nz
2445 * otherwise . Does not allocate memory but sets up card
2446 * using previously allocated descriptors.
2448 static int mpi_init_descriptors (struct airo_info *ai)
2455 /* Alloc card RX descriptors */
2456 netif_stop_queue(ai->dev);
2458 memset(&rsp,0,sizeof(rsp));
2459 memset(&cmd,0,sizeof(cmd));
2461 cmd.cmd = CMD_ALLOCATEAUX;
2463 cmd.parm1 = (ai->rxfids[0].card_ram_off - ai->pciaux);
2464 cmd.parm2 = MPI_MAX_FIDS;
2465 rc=issuecommand(ai, &cmd, &rsp);
2466 if (rc != SUCCESS) {
2467 printk(KERN_ERR "airo: Couldn't allocate RX FID\n");
2471 for (i=0; i<MPI_MAX_FIDS; i++) {
2472 memcpy_toio(ai->rxfids[i].card_ram_off,
2473 &ai->rxfids[i].rx_desc, sizeof(RxFid));
2476 /* Alloc card TX descriptors */
2478 memset(&rsp,0,sizeof(rsp));
2479 memset(&cmd,0,sizeof(cmd));
2481 cmd.cmd = CMD_ALLOCATEAUX;
2483 cmd.parm1 = (ai->txfids[0].card_ram_off - ai->pciaux);
2484 cmd.parm2 = MPI_MAX_FIDS;
2486 for (i=0; i<MPI_MAX_FIDS; i++) {
2487 ai->txfids[i].tx_desc.valid = 1;
2488 memcpy_toio(ai->txfids[i].card_ram_off,
2489 &ai->txfids[i].tx_desc, sizeof(TxFid));
2491 ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */
2493 rc=issuecommand(ai, &cmd, &rsp);
2494 if (rc != SUCCESS) {
2495 printk(KERN_ERR "airo: Couldn't allocate TX FID\n");
2499 /* Alloc card Rid descriptor */
2500 memset(&rsp,0,sizeof(rsp));
2501 memset(&cmd,0,sizeof(cmd));
2503 cmd.cmd = CMD_ALLOCATEAUX;
2505 cmd.parm1 = (ai->config_desc.card_ram_off - ai->pciaux);
2506 cmd.parm2 = 1; /* Magic number... */
2507 rc=issuecommand(ai, &cmd, &rsp);
2508 if (rc != SUCCESS) {
2509 printk(KERN_ERR "airo: Couldn't allocate RID\n");
2513 memcpy_toio(ai->config_desc.card_ram_off,
2514 &ai->config_desc.rid_desc, sizeof(Rid));
2520 * We are setting up three things here:
2521 * 1) Map AUX memory for descriptors: Rid, TxFid, or RxFid.
2522 * 2) Map PCI memory for issueing commands.
2523 * 3) Allocate memory (shared) to send and receive ethernet frames.
2525 static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci,
2528 unsigned long mem_start, mem_len, aux_start, aux_len;
2531 unsigned char *busaddroff,*vpackoff;
2532 unsigned char __iomem *pciaddroff;
2534 mem_start = pci_resource_start(pci, 1);
2535 mem_len = pci_resource_len(pci, 1);
2536 aux_start = pci_resource_start(pci, 2);
2537 aux_len = AUXMEMSIZE;
2539 if (!request_mem_region(mem_start, mem_len, name)) {
2540 printk(KERN_ERR "airo: Couldn't get region %x[%x] for %s\n",
2541 (int)mem_start, (int)mem_len, name);
2544 if (!request_mem_region(aux_start, aux_len, name)) {
2545 printk(KERN_ERR "airo: Couldn't get region %x[%x] for %s\n",
2546 (int)aux_start, (int)aux_len, name);
2550 ai->pcimem = ioremap(mem_start, mem_len);
2552 printk(KERN_ERR "airo: Couldn't map region %x[%x] for %s\n",
2553 (int)mem_start, (int)mem_len, name);
2556 ai->pciaux = ioremap(aux_start, aux_len);
2558 printk(KERN_ERR "airo: Couldn't map region %x[%x] for %s\n",
2559 (int)aux_start, (int)aux_len, name);
2563 /* Reserve PKTSIZE for each fid and 2K for the Rids */
2564 ai->shared = pci_alloc_consistent(pci, PCI_SHARED_LEN, &ai->shared_dma);
2566 printk(KERN_ERR "airo: Couldn't alloc_consistent %d\n",
2572 * Setup descriptor RX, TX, CONFIG
2574 busaddroff = (unsigned char *)ai->shared_dma;
2575 pciaddroff = ai->pciaux + AUX_OFFSET;
2576 vpackoff = ai->shared;
2578 /* RX descriptor setup */
2579 for(i = 0; i < MPI_MAX_FIDS; i++) {
2580 ai->rxfids[i].pending = 0;
2581 ai->rxfids[i].card_ram_off = pciaddroff;
2582 ai->rxfids[i].virtual_host_addr = vpackoff;
2583 ai->rxfids[i].rx_desc.host_addr = (dma_addr_t) busaddroff;
2584 ai->rxfids[i].rx_desc.valid = 1;
2585 ai->rxfids[i].rx_desc.len = PKTSIZE;
2586 ai->rxfids[i].rx_desc.rdy = 0;
2588 pciaddroff += sizeof(RxFid);
2589 busaddroff += PKTSIZE;
2590 vpackoff += PKTSIZE;
2593 /* TX descriptor setup */
2594 for(i = 0; i < MPI_MAX_FIDS; i++) {
2595 ai->txfids[i].card_ram_off = pciaddroff;
2596 ai->txfids[i].virtual_host_addr = vpackoff;
2597 ai->txfids[i].tx_desc.valid = 1;
2598 ai->txfids[i].tx_desc.host_addr = (dma_addr_t) busaddroff;
2599 memcpy(ai->txfids[i].virtual_host_addr,
2600 &wifictlhdr8023, sizeof(wifictlhdr8023));
2602 pciaddroff += sizeof(TxFid);
2603 busaddroff += PKTSIZE;
2604 vpackoff += PKTSIZE;
2606 ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */
2608 /* Rid descriptor setup */
2609 ai->config_desc.card_ram_off = pciaddroff;
2610 ai->config_desc.virtual_host_addr = vpackoff;
2611 ai->config_desc.rid_desc.host_addr = (dma_addr_t) busaddroff;
2612 ai->ridbus = (dma_addr_t)busaddroff;
2613 ai->config_desc.rid_desc.rid = 0;
2614 ai->config_desc.rid_desc.len = RIDSIZE;
2615 ai->config_desc.rid_desc.valid = 1;
2616 pciaddroff += sizeof(Rid);
2617 busaddroff += RIDSIZE;
2618 vpackoff += RIDSIZE;
2620 /* Tell card about descriptors */
2621 if (mpi_init_descriptors (ai) != SUCCESS)
2626 pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
2628 iounmap(ai->pciaux);
2630 iounmap(ai->pcimem);
2632 release_mem_region(aux_start, aux_len);
2634 release_mem_region(mem_start, mem_len);
2639 static void wifi_setup(struct net_device *dev)
2641 dev->hard_header = NULL;
2642 dev->rebuild_header = NULL;
2643 dev->hard_header_cache = NULL;
2644 dev->header_cache_update= NULL;
2646 dev->hard_header_parse = wll_header_parse;
2647 dev->hard_start_xmit = &airo_start_xmit11;
2648 dev->get_stats = &airo_get_stats;
2649 dev->set_mac_address = &airo_set_mac_address;
2650 dev->do_ioctl = &airo_ioctl;
2652 dev->wireless_handlers = &airo_handler_def;
2653 #endif /* WIRELESS_EXT */
2654 dev->change_mtu = &airo_change_mtu;
2655 dev->open = &airo_open;
2656 dev->stop = &airo_close;
2658 dev->type = ARPHRD_IEEE80211;
2659 dev->hard_header_len = ETH_HLEN;
2661 dev->addr_len = ETH_ALEN;
2662 dev->tx_queue_len = 100;
2664 memset(dev->broadcast,0xFF, ETH_ALEN);
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", wifi_setup);
2676 dev->priv = ethdev->priv;
2677 dev->irq = ethdev->irq;
2678 dev->base_addr = ethdev->base_addr;
2680 dev->wireless_data = ethdev->wireless_data;
2681 #endif /* WIRELESS_EXT */
2682 memcpy(dev->dev_addr, ethdev->dev_addr, dev->addr_len);
2683 err = register_netdev(dev);
2691 static int reset_card( struct net_device *dev , int lock) {
2692 struct airo_info *ai = dev->priv;
2694 if (lock && down_interruptible(&ai->sem))
2697 OUT4500(ai,COMMAND,CMD_SOFTRESET);
2706 static struct net_device *_init_airo_card( unsigned short irq, int port,
2707 int is_pcmcia, struct pci_dev *pci,
2708 struct device *dmdev )
2710 struct net_device *dev;
2711 struct airo_info *ai;
2714 /* Create the network device object. */
2715 dev = alloc_etherdev(sizeof(*ai));
2717 printk(KERN_ERR "airo: Couldn't alloc_etherdev\n");
2720 if (dev_alloc_name(dev, dev->name) < 0) {
2721 printk(KERN_ERR "airo: Couldn't get name!\n");
2728 if (pci && (pci->device == 0x5000 || pci->device == 0xa504)) {
2729 printk(KERN_DEBUG "airo: Found an MPI350 card\n");
2730 set_bit(FLAG_MPI, &ai->flags);
2733 spin_lock_init(&ai->aux_lock);
2734 sema_init(&ai->sem, 1);
2737 init_waitqueue_head (&ai->thr_wait);
2738 init_completion (&ai->thr_exited);
2739 ai->thr_pid = kernel_thread(airo_thread, dev, CLONE_FS | CLONE_FILES);
2740 if (ai->thr_pid < 0)
2745 rc = add_airo_dev( dev );
2749 /* The Airo-specific entries in the device structure. */
2750 if (test_bit(FLAG_MPI,&ai->flags)) {
2751 skb_queue_head_init (&ai->txq);
2752 dev->hard_start_xmit = &mpi_start_xmit;
2754 dev->hard_start_xmit = &airo_start_xmit;
2755 dev->get_stats = &airo_get_stats;
2756 dev->set_multicast_list = &airo_set_multicast_list;
2757 dev->set_mac_address = &airo_set_mac_address;
2758 dev->do_ioctl = &airo_ioctl;
2760 dev->wireless_handlers = &airo_handler_def;
2761 ai->wireless_data.spy_data = &ai->spy_data;
2762 dev->wireless_data = &ai->wireless_data;
2763 #endif /* WIRELESS_EXT */
2764 dev->change_mtu = &airo_change_mtu;
2765 dev->open = &airo_open;
2766 dev->stop = &airo_close;
2768 dev->base_addr = port;
2770 SET_NETDEV_DEV(dev, dmdev);
2773 if (test_bit(FLAG_MPI,&ai->flags))
2774 reset_card (dev, 1);
2776 rc = request_irq( dev->irq, airo_interrupt, SA_SHIRQ, dev->name, dev );
2778 printk(KERN_ERR "airo: register interrupt %d failed, rc %d\n", irq, rc );
2779 goto err_out_unlink;
2782 if (!request_region( dev->base_addr, 64, dev->name )) {
2784 printk(KERN_ERR "airo: Couldn't request region\n");
2789 if (test_bit(FLAG_MPI,&ai->flags)) {
2790 if (mpi_map_card(ai, pci, dev->name)) {
2791 printk(KERN_ERR "airo: Could not map memory\n");
2797 if ( setup_card( ai, dev->dev_addr, 1 ) != SUCCESS ) {
2798 printk( KERN_ERR "airo: MAC could not be enabled\n" );
2802 } else if (!test_bit(FLAG_MPI,&ai->flags)) {
2803 ai->bap_read = fast_bap_read;
2804 set_bit(FLAG_FLASHING, &ai->flags);
2807 rc = register_netdev(dev);
2809 printk(KERN_ERR "airo: Couldn't register_netdev\n");
2812 ai->wifidev = init_wifidev(ai, dev);
2814 set_bit(FLAG_REGISTERED,&ai->flags);
2815 printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%x\n",
2817 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
2818 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5] );
2820 /* Allocate the transmit buffers */
2821 if (probe && !test_bit(FLAG_MPI,&ai->flags))
2822 for( i = 0; i < MAX_FIDS; i++ )
2823 ai->fids[i] = transmit_allocate(ai,2312,i>=MAX_FIDS/2);
2825 setup_proc_entry( dev, dev->priv ); /* XXX check for failure */
2826 netif_start_queue(dev);
2827 SET_MODULE_OWNER(dev);
2831 if (test_bit(FLAG_MPI,&ai->flags) && pci) {
2832 pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
2833 iounmap(ai->pciaux);
2834 iounmap(ai->pcimem);
2835 mpi_unmap_card(ai->pci);
2839 release_region( dev->base_addr, 64 );
2841 free_irq(dev->irq, dev);
2845 set_bit(JOB_DIE, &ai->flags);
2846 kill_proc(ai->thr_pid, SIGTERM, 1);
2847 wait_for_completion(&ai->thr_exited);
2853 struct net_device *init_airo_card( unsigned short irq, int port, int is_pcmcia,
2854 struct device *dmdev)
2856 return _init_airo_card ( irq, port, is_pcmcia, NULL, dmdev);
2859 EXPORT_SYMBOL(init_airo_card);
2861 static int waitbusy (struct airo_info *ai) {
2863 while ((IN4500 (ai, COMMAND) & COMMAND_BUSY) & (delay < 10000)) {
2865 if ((++delay % 20) == 0)
2866 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
2868 return delay < 10000;
2871 int reset_airo_card( struct net_device *dev )
2874 struct airo_info *ai = dev->priv;
2876 if (reset_card (dev, 1))
2879 if ( setup_card(ai, dev->dev_addr, 1 ) != SUCCESS ) {
2880 printk( KERN_ERR "airo: MAC could not be enabled\n" );
2883 printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%x\n", dev->name,
2884 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
2885 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
2886 /* Allocate the transmit buffers if needed */
2887 if (!test_bit(FLAG_MPI,&ai->flags))
2888 for( i = 0; i < MAX_FIDS; i++ )
2889 ai->fids[i] = transmit_allocate (ai,2312,i>=MAX_FIDS/2);
2891 enable_interrupts( ai );
2892 netif_wake_queue(dev);
2896 EXPORT_SYMBOL(reset_airo_card);
2898 static void airo_send_event(struct net_device *dev) {
2899 struct airo_info *ai = dev->priv;
2900 union iwreq_data wrqu;
2901 StatusRid status_rid;
2903 clear_bit(JOB_EVENT, &ai->flags);
2904 PC4500_readrid(ai, RID_STATUS, &status_rid, sizeof(status_rid), 0);
2906 wrqu.data.length = 0;
2907 wrqu.data.flags = 0;
2908 memcpy(wrqu.ap_addr.sa_data, status_rid.bssid[0], ETH_ALEN);
2909 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
2911 /* Send event to user space */
2912 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
2915 static int airo_thread(void *data) {
2916 struct net_device *dev = data;
2917 struct airo_info *ai = dev->priv;
2920 daemonize("%s", dev->name);
2921 allow_signal(SIGTERM);
2924 if (signal_pending(current))
2925 flush_signals(current);
2927 /* make swsusp happy with our thread */
2930 if (test_bit(JOB_DIE, &ai->flags))
2933 if (ai->flags & JOB_MASK) {
2934 locked = down_interruptible(&ai->sem);
2938 init_waitqueue_entry(&wait, current);
2939 add_wait_queue(&ai->thr_wait, &wait);
2941 set_current_state(TASK_INTERRUPTIBLE);
2942 if (ai->flags & JOB_MASK)
2945 if (time_after_eq(jiffies,ai->expires)){
2946 set_bit(JOB_AUTOWEP,&ai->flags);
2949 if (!signal_pending(current)) {
2950 schedule_timeout(ai->expires - jiffies);
2953 } else if (!signal_pending(current)) {
2959 current->state = TASK_RUNNING;
2960 remove_wait_queue(&ai->thr_wait, &wait);
2967 if (test_bit(JOB_DIE, &ai->flags)) {
2972 if (ai->power || test_bit(FLAG_FLASHING, &ai->flags)) {
2977 if (test_bit(JOB_XMIT, &ai->flags))
2979 else if (test_bit(JOB_XMIT11, &ai->flags))
2980 airo_end_xmit11(dev);
2981 else if (test_bit(JOB_STATS, &ai->flags))
2982 airo_read_stats(ai);
2983 else if (test_bit(JOB_WSTATS, &ai->flags))
2984 airo_read_wireless_stats(ai);
2985 else if (test_bit(JOB_PROMISC, &ai->flags))
2986 airo_set_promisc(ai);
2988 else if (test_bit(JOB_MIC, &ai->flags))
2991 else if (test_bit(JOB_EVENT, &ai->flags))
2992 airo_send_event(dev);
2993 else if (test_bit(JOB_AUTOWEP, &ai->flags))
2996 complete_and_exit (&ai->thr_exited, 0);
2999 static irqreturn_t airo_interrupt ( int irq, void* dev_id, struct pt_regs *regs) {
3000 struct net_device *dev = (struct net_device *)dev_id;
3003 struct airo_info *apriv = dev->priv;
3004 u16 savedInterrupts = 0;
3007 if (!netif_device_present(dev))
3011 status = IN4500( apriv, EVSTAT );
3012 if ( !(status & STATUS_INTS) || status == 0xffff ) break;
3016 if ( status & EV_AWAKE ) {
3017 OUT4500( apriv, EVACK, EV_AWAKE );
3018 OUT4500( apriv, EVACK, EV_AWAKE );
3021 if (!savedInterrupts) {
3022 savedInterrupts = IN4500( apriv, EVINTEN );
3023 OUT4500( apriv, EVINTEN, 0 );
3026 if ( status & EV_MIC ) {
3027 OUT4500( apriv, EVACK, EV_MIC );
3029 if (test_bit(FLAG_MIC_CAPABLE, &apriv->flags)) {
3030 set_bit(JOB_MIC, &apriv->flags);
3031 wake_up_interruptible(&apriv->thr_wait);
3035 if ( status & EV_LINK ) {
3036 union iwreq_data wrqu;
3037 /* The link status has changed, if you want to put a
3038 monitor hook in, do it here. (Remember that
3039 interrupts are still disabled!)
3041 u16 newStatus = IN4500(apriv, LINKSTAT);
3042 OUT4500( apriv, EVACK, EV_LINK);
3043 /* Here is what newStatus means: */
3044 #define NOBEACON 0x8000 /* Loss of sync - missed beacons */
3045 #define MAXRETRIES 0x8001 /* Loss of sync - max retries */
3046 #define MAXARL 0x8002 /* Loss of sync - average retry level exceeded*/
3047 #define FORCELOSS 0x8003 /* Loss of sync - host request */
3048 #define TSFSYNC 0x8004 /* Loss of sync - TSF synchronization */
3049 #define DEAUTH 0x8100 /* Deauthentication (low byte is reason code) */
3050 #define DISASS 0x8200 /* Disassociation (low byte is reason code) */
3051 #define ASSFAIL 0x8400 /* Association failure (low byte is reason
3053 #define AUTHFAIL 0x0300 /* Authentication failure (low byte is reason
3055 #define ASSOCIATED 0x0400 /* Assocatied */
3056 #define RC_RESERVED 0 /* Reserved return code */
3057 #define RC_NOREASON 1 /* Unspecified reason */
3058 #define RC_AUTHINV 2 /* Previous authentication invalid */
3059 #define RC_DEAUTH 3 /* Deauthenticated because sending station is
3061 #define RC_NOACT 4 /* Disassociated due to inactivity */
3062 #define RC_MAXLOAD 5 /* Disassociated because AP is unable to handle
3063 all currently associated stations */
3064 #define RC_BADCLASS2 6 /* Class 2 frame received from
3065 non-Authenticated station */
3066 #define RC_BADCLASS3 7 /* Class 3 frame received from
3067 non-Associated station */
3068 #define RC_STATLEAVE 8 /* Disassociated because sending station is
3070 #define RC_NOAUTH 9 /* Station requesting (Re)Association is not
3071 Authenticated with the responding station */
3072 if (newStatus != ASSOCIATED) {
3073 if (auto_wep && !apriv->expires) {
3074 apriv->expires = RUN_AT(3*HZ);
3075 wake_up_interruptible(&apriv->thr_wait);
3078 struct task_struct *task = apriv->task;
3082 wake_up_process (task);
3083 set_bit(FLAG_UPDATE_UNI, &apriv->flags);
3084 set_bit(FLAG_UPDATE_MULTI, &apriv->flags);
3086 /* Question : is ASSOCIATED the only status
3087 * that is valid ? We want to catch handover
3088 * and reassociations as valid status
3090 if(newStatus == ASSOCIATED) {
3091 if (apriv->scan_timestamp) {
3092 /* Send an empty event to user space.
3093 * We don't send the received data on
3094 * the event because it would require
3095 * us to do complex transcoding, and
3096 * we want to minimise the work done in
3097 * the irq handler. Use a request to
3098 * extract the data - Jean II */
3099 wrqu.data.length = 0;
3100 wrqu.data.flags = 0;
3101 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
3102 apriv->scan_timestamp = 0;
3104 if (down_trylock(&apriv->sem) != 0) {
3105 set_bit(JOB_EVENT, &apriv->flags);
3106 wake_up_interruptible(&apriv->thr_wait);
3108 airo_send_event(dev);
3110 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
3111 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3113 /* Send event to user space */
3114 wireless_send_event(dev, SIOCGIWAP, &wrqu,NULL);
3118 /* Check to see if there is something to receive */
3119 if ( status & EV_RX ) {
3120 struct sk_buff *skb = NULL;
3121 u16 fc, len, hdrlen = 0;
3135 if (test_bit(FLAG_MPI,&apriv->flags)) {
3136 if (test_bit(FLAG_802_11, &apriv->flags))
3137 mpi_receive_802_11(apriv);
3139 mpi_receive_802_3(apriv);
3140 OUT4500(apriv, EVACK, EV_RX);
3144 fid = IN4500( apriv, RXFID );
3146 /* Get the packet length */
3147 if (test_bit(FLAG_802_11, &apriv->flags)) {
3148 bap_setup (apriv, fid, 4, BAP0);
3149 bap_read (apriv, (u16*)&hdr, sizeof(hdr), BAP0);
3150 /* Bad CRC. Ignore packet */
3151 if (le16_to_cpu(hdr.status) & 2)
3153 if (apriv->wifidev == NULL)
3156 bap_setup (apriv, fid, 0x36, BAP0);
3157 bap_read (apriv, (u16*)&hdr.len, 2, BAP0);
3159 len = le16_to_cpu(hdr.len);
3162 printk( KERN_ERR "airo: Bad size %d\n", len );
3168 if (test_bit(FLAG_802_11, &apriv->flags)) {
3169 bap_read (apriv, (u16*)&fc, sizeof(fc), BAP0);
3170 fc = le16_to_cpu(fc);
3173 if ((fc & 0xe0) == 0xc0)
3179 if ((fc&0x300)==0x300){
3187 hdrlen = ETH_ALEN * 2;
3189 skb = dev_alloc_skb( len + hdrlen + 2 + 2 );
3191 apriv->stats.rx_dropped++;
3194 skb_reserve(skb, 2); /* This way the IP header is aligned */
3195 buffer = (u16*)skb_put (skb, len + hdrlen);
3196 if (test_bit(FLAG_802_11, &apriv->flags)) {
3198 bap_read (apriv, buffer + 1, hdrlen - 2, BAP0);
3200 bap_read (apriv, tmpbuf, 6, BAP0);
3202 bap_read (apriv, &gap, sizeof(gap), BAP0);
3203 gap = le16_to_cpu(gap);
3206 bap_read (apriv, tmpbuf, gap, BAP0);
3208 printk(KERN_ERR "airo: gaplen too big. Problems will follow...\n");
3210 bap_read (apriv, buffer + hdrlen/2, len, BAP0);
3215 bap_read (apriv, buffer, ETH_ALEN*2, BAP0);
3217 if (apriv->micstats.enabled) {
3218 bap_read (apriv,(u16*)&micbuf,sizeof(micbuf),BAP0);
3219 if (ntohs(micbuf.typelen) > 0x05DC)
3220 bap_setup (apriv, fid, 0x44, BAP0);
3222 if (len <= sizeof(micbuf))
3225 len -= sizeof(micbuf);
3226 skb_trim (skb, len + hdrlen);
3230 bap_read(apriv,buffer+ETH_ALEN,len,BAP0);
3232 if (decapsulate(apriv,&micbuf,(etherHead*)buffer,len)) {
3234 dev_kfree_skb_irq (skb);
3239 OUT4500( apriv, EVACK, EV_RX);
3244 if (apriv->spy_data.spy_number > 0) {
3246 struct iw_quality wstats;
3247 /* Prepare spy data : addr + qual */
3248 if (!test_bit(FLAG_802_11, &apriv->flags)) {
3249 sa = (char*)buffer + 6;
3250 bap_setup (apriv, fid, 8, BAP0);
3251 bap_read (apriv, (u16*)hdr.rssi, 2, BAP0);
3253 sa = (char*)buffer + 10;
3254 wstats.qual = hdr.rssi[0];
3256 wstats.level = 0x100 - apriv->rssi[hdr.rssi[1]].rssidBm;
3258 wstats.level = (hdr.rssi[1] + 321) / 2;
3259 wstats.noise = apriv->wstats.qual.noise;
3260 wstats.updated = IW_QUAL_LEVEL_UPDATED
3261 | IW_QUAL_QUAL_UPDATED
3262 | IW_QUAL_NOISE_UPDATED;
3263 /* Update spy records */
3264 wireless_spy_update(dev, sa, &wstats);
3266 #endif /* WIRELESS_SPY */
3267 OUT4500( apriv, EVACK, EV_RX);
3269 if (test_bit(FLAG_802_11, &apriv->flags)) {
3270 skb->mac.raw = skb->data;
3271 skb->pkt_type = PACKET_OTHERHOST;
3272 skb->dev = apriv->wifidev;
3273 skb->protocol = htons(ETH_P_802_2);
3276 skb->protocol = eth_type_trans(skb,dev);
3278 skb->dev->last_rx = jiffies;
3279 skb->ip_summed = CHECKSUM_NONE;
3285 /* Check to see if a packet has been transmitted */
3286 if ( status & ( EV_TX|EV_TXCPY|EV_TXEXC ) ) {
3291 if (test_bit(FLAG_MPI,&apriv->flags)) {
3292 unsigned long flags;
3294 if (status & EV_TXEXC)
3295 get_tx_error(apriv, -1);
3296 spin_lock_irqsave(&apriv->aux_lock, flags);
3297 if (!skb_queue_empty(&apriv->txq)) {
3298 spin_unlock_irqrestore(&apriv->aux_lock,flags);
3299 mpi_send_packet (dev);
3301 clear_bit(FLAG_PENDING_XMIT, &apriv->flags);
3302 spin_unlock_irqrestore(&apriv->aux_lock,flags);
3303 netif_wake_queue (dev);
3305 OUT4500( apriv, EVACK,
3306 status & (EV_TX|EV_TXCPY|EV_TXEXC));
3310 fid = IN4500(apriv, TXCOMPLFID);
3312 for( i = 0; i < MAX_FIDS; i++ ) {
3313 if ( ( apriv->fids[i] & 0xffff ) == fid ) {
3314 len = apriv->fids[i] >> 16;
3319 if (status & EV_TXEXC)
3320 get_tx_error(apriv, index);
3321 OUT4500( apriv, EVACK, status & (EV_TX | EV_TXEXC));
3322 /* Set up to be used again */
3323 apriv->fids[index] &= 0xffff;
3324 if (index < MAX_FIDS / 2) {
3325 if (!test_bit(FLAG_PENDING_XMIT, &apriv->flags))
3326 netif_wake_queue(dev);
3328 if (!test_bit(FLAG_PENDING_XMIT11, &apriv->flags))
3329 netif_wake_queue(apriv->wifidev);
3332 OUT4500( apriv, EVACK, status & (EV_TX | EV_TXCPY | EV_TXEXC));
3333 printk( KERN_ERR "airo: Unallocated FID was used to xmit\n" );
3337 if ( status & ~STATUS_INTS & ~IGNORE_INTS )
3338 printk( KERN_WARNING "airo: Got weird status %x\n",
3339 status & ~STATUS_INTS & ~IGNORE_INTS );
3342 if (savedInterrupts)
3343 OUT4500( apriv, EVINTEN, savedInterrupts );
3346 return IRQ_RETVAL(handled);
3350 * Routines to talk to the card
3354 * This was originally written for the 4500, hence the name
3355 * NOTE: If use with 8bit mode and SMP bad things will happen!
3356 * Why would some one do 8 bit IO in an SMP machine?!?
3358 static void OUT4500( struct airo_info *ai, u16 reg, u16 val ) {
3359 if (test_bit(FLAG_MPI,&ai->flags))
3362 outw( val, ai->dev->base_addr + reg );
3364 outb( val & 0xff, ai->dev->base_addr + reg );
3365 outb( val >> 8, ai->dev->base_addr + reg + 1 );
3369 static u16 IN4500( struct airo_info *ai, u16 reg ) {
3372 if (test_bit(FLAG_MPI,&ai->flags))
3375 rc = inw( ai->dev->base_addr + reg );
3377 rc = inb( ai->dev->base_addr + reg );
3378 rc += ((int)inb( ai->dev->base_addr + reg + 1 )) << 8;
3383 static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock ) {
3387 /* FLAG_RADIO_OFF : Radio disabled via /proc or Wireless Extensions
3388 * FLAG_RADIO_DOWN : Radio disabled via "ifconfig ethX down"
3389 * Note : we could try to use !netif_running(dev) in enable_MAC()
3390 * instead of this flag, but I don't trust it *within* the
3391 * open/close functions, and testing both flags together is
3392 * "cheaper" - Jean II */
3393 if (ai->flags & FLAG_RADIO_MASK) return SUCCESS;
3395 if (lock && down_interruptible(&ai->sem))
3396 return -ERESTARTSYS;
3398 if (!test_bit(FLAG_ENABLED, &ai->flags)) {
3399 memset(&cmd, 0, sizeof(cmd));
3400 cmd.cmd = MAC_ENABLE;
3401 rc = issuecommand(ai, &cmd, rsp);
3403 set_bit(FLAG_ENABLED, &ai->flags);
3411 printk(KERN_ERR "%s: Cannot enable MAC, err=%d\n",
3416 static void disable_MAC( struct airo_info *ai, int lock ) {
3420 if (lock && down_interruptible(&ai->sem))
3423 if (test_bit(FLAG_ENABLED, &ai->flags)) {
3424 memset(&cmd, 0, sizeof(cmd));
3425 cmd.cmd = MAC_DISABLE; // disable in case already enabled
3426 issuecommand(ai, &cmd, &rsp);
3427 clear_bit(FLAG_ENABLED, &ai->flags);
3433 static void enable_interrupts( struct airo_info *ai ) {
3434 /* Enable the interrupts */
3435 OUT4500( ai, EVINTEN, STATUS_INTS );
3438 static void disable_interrupts( struct airo_info *ai ) {
3439 OUT4500( ai, EVINTEN, 0 );
3442 static void mpi_receive_802_3(struct airo_info *ai)
3446 struct sk_buff *skb;
3453 memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
3454 /* Make sure we got something */
3455 if (rxd.rdy && rxd.valid == 0) {
3457 if (len < 12 || len > 2048)
3460 skb = dev_alloc_skb(len);
3462 ai->stats.rx_dropped++;
3465 buffer = skb_put(skb,len);
3467 memcpy(buffer, ai->rxfids[0].virtual_host_addr, ETH_ALEN * 2);
3468 if (ai->micstats.enabled) {
3470 ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2,
3472 if (ntohs(micbuf.typelen) <= 0x05DC) {
3473 if (len <= sizeof(micbuf) + ETH_ALEN * 2)
3476 off = sizeof(micbuf);
3477 skb_trim (skb, len - off);
3480 memcpy(buffer + ETH_ALEN * 2,
3481 ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2 + off,
3482 len - ETH_ALEN * 2 - off);
3483 if (decapsulate (ai, &micbuf, (etherHead*)buffer, len - off - ETH_ALEN * 2)) {
3485 dev_kfree_skb_irq (skb);
3489 memcpy(buffer, ai->rxfids[0].virtual_host_addr, len);
3492 if (ai->spy_data.spy_number > 0) {
3494 struct iw_quality wstats;
3495 /* Prepare spy data : addr + qual */
3496 sa = buffer + ETH_ALEN;
3497 wstats.qual = 0; /* XXX Where do I get that info from ??? */
3500 /* Update spy records */
3501 wireless_spy_update(ai->dev, sa, &wstats);
3503 #endif /* WIRELESS_SPY */
3506 skb->ip_summed = CHECKSUM_NONE;
3507 skb->protocol = eth_type_trans(skb, ai->dev);
3508 skb->dev->last_rx = jiffies;
3512 if (rxd.valid == 0) {
3516 memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
3520 void mpi_receive_802_11 (struct airo_info *ai)
3523 struct sk_buff *skb = NULL;
3524 u16 fc, len, hdrlen = 0;
3536 char *ptr = ai->rxfids[0].virtual_host_addr+4;
3538 memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
3539 memcpy ((char *)&hdr, ptr, sizeof(hdr));
3541 /* Bad CRC. Ignore packet */
3542 if (le16_to_cpu(hdr.status) & 2)
3544 if (ai->wifidev == NULL)
3546 len = le16_to_cpu(hdr.len);
3548 printk( KERN_ERR "airo: Bad size %d\n", len );
3554 memcpy ((char *)&fc, ptr, sizeof(fc));
3555 fc = le16_to_cpu(fc);
3558 if ((fc & 0xe0) == 0xc0)
3564 if ((fc&0x300)==0x300){
3572 skb = dev_alloc_skb( len + hdrlen + 2 );
3574 ai->stats.rx_dropped++;
3577 buffer = (u16*)skb_put (skb, len + hdrlen);
3578 memcpy ((char *)buffer, ptr, hdrlen);
3582 memcpy ((char *)&gap, ptr, sizeof(gap));
3584 gap = le16_to_cpu(gap);
3590 "airo: gaplen too big. Problems will follow...\n");
3592 memcpy ((char *)buffer + hdrlen, ptr, len);
3594 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
3595 if (ai->spy_data.spy_number > 0) {
3597 struct iw_quality wstats;
3598 /* Prepare spy data : addr + qual */
3599 sa = (char*)buffer + 10;
3600 wstats.qual = hdr.rssi[0];
3602 wstats.level = 0x100 - ai->rssi[hdr.rssi[1]].rssidBm;
3604 wstats.level = (hdr.rssi[1] + 321) / 2;
3605 wstats.noise = ai->wstats.qual.noise;
3606 wstats.updated = IW_QUAL_QUAL_UPDATED
3607 | IW_QUAL_LEVEL_UPDATED
3608 | IW_QUAL_NOISE_UPDATED;
3609 /* Update spy records */
3610 wireless_spy_update(ai->dev, sa, &wstats);
3612 #endif /* IW_WIRELESS_SPY */
3613 skb->mac.raw = skb->data;
3614 skb->pkt_type = PACKET_OTHERHOST;
3615 skb->dev = ai->wifidev;
3616 skb->protocol = htons(ETH_P_802_2);
3617 skb->dev->last_rx = jiffies;
3618 skb->ip_summed = CHECKSUM_NONE;
3621 if (rxd.valid == 0) {
3625 memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
3629 static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
3640 memset( &mySsid, 0, sizeof( mySsid ) );
3646 /* The NOP is the first step in getting the card going */
3648 cmd.parm0 = cmd.parm1 = cmd.parm2 = 0;
3649 if (lock && down_interruptible(&ai->sem))
3651 if ( issuecommand( ai, &cmd, &rsp ) != SUCCESS ) {
3656 disable_MAC( ai, 0);
3658 // Let's figure out if we need to use the AUX port
3659 if (!test_bit(FLAG_MPI,&ai->flags)) {
3660 cmd.cmd = CMD_ENABLEAUX;
3661 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
3664 printk(KERN_ERR "airo: Error checking for AUX port\n");
3667 if (!aux_bap || rsp.status & 0xff00) {
3668 ai->bap_read = fast_bap_read;
3669 printk(KERN_DEBUG "airo: Doing fast bap_reads\n");
3671 ai->bap_read = aux_bap_read;
3672 printk(KERN_DEBUG "airo: Doing AUX bap_reads\n");
3677 if (ai->config.len == 0) {
3678 tdsRssiRid rssi_rid;
3679 CapabilityRid cap_rid;
3689 // general configuration (read/modify/write)
3690 status = readConfigRid(ai, lock);
3691 if ( status != SUCCESS ) return ERROR;
3693 status = readCapabilityRid(ai, &cap_rid, lock);
3694 if ( status != SUCCESS ) return ERROR;
3696 status = PC4500_readrid(ai,RID_RSSI,&rssi_rid,sizeof(rssi_rid),lock);
3697 if ( status == SUCCESS ) {
3698 if (ai->rssi || (ai->rssi = kmalloc(512, GFP_KERNEL)) != NULL)
3699 memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512); /* Skip RID length member */
3706 if (cap_rid.softCap & 8)
3707 ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
3709 printk(KERN_WARNING "airo: unknown received signal level scale\n");
3711 ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS;
3712 ai->config.authType = AUTH_OPEN;
3713 ai->config.modulation = MOD_CCK;
3716 if ((cap_rid.len>=sizeof(cap_rid)) && (cap_rid.extSoftCap&1) &&
3717 (micsetup(ai) == SUCCESS)) {
3718 ai->config.opmode |= MODE_MIC;
3719 set_bit(FLAG_MIC_CAPABLE, &ai->flags);
3723 /* Save off the MAC */
3724 for( i = 0; i < ETH_ALEN; i++ ) {
3725 mac[i] = ai->config.macAddr[i];
3728 /* Check to see if there are any insmod configured
3732 memset(ai->config.rates,0,sizeof(ai->config.rates));
3733 for( i = 0; i < 8 && rates[i]; i++ ) {
3734 ai->config.rates[i] = rates[i];
3737 if ( basic_rate > 0 ) {
3739 for( i = 0; i < 8; i++ ) {
3740 if ( ai->config.rates[i] == basic_rate ||
3741 !ai->config.rates ) {
3742 ai->config.rates[i] = basic_rate | 0x80;
3747 set_bit (FLAG_COMMIT, &ai->flags);
3750 /* Setup the SSIDs if present */
3753 for( i = 0; i < 3 && ssids[i]; i++ ) {
3754 mySsid.ssids[i].len = strlen(ssids[i]);
3755 if ( mySsid.ssids[i].len > 32 )
3756 mySsid.ssids[i].len = 32;
3757 memcpy(mySsid.ssids[i].ssid, ssids[i],
3758 mySsid.ssids[i].len);
3760 mySsid.len = sizeof(mySsid);
3763 status = writeConfigRid(ai, lock);
3764 if ( status != SUCCESS ) return ERROR;
3766 /* Set up the SSID list */
3768 status = writeSsidRid(ai, &mySsid, lock);
3769 if ( status != SUCCESS ) return ERROR;
3772 status = enable_MAC(ai, &rsp, lock);
3773 if ( status != SUCCESS || (rsp.status & 0xFF00) != 0) {
3774 printk( KERN_ERR "airo: Bad MAC enable reason = %x, rid = %x, offset = %d\n", rsp.rsp0, rsp.rsp1, rsp.rsp2 );
3778 /* Grab the initial wep key, we gotta save it for auto_wep */
3779 rc = readWepKeyRid(ai, &wkr, 1, lock);
3780 if (rc == SUCCESS) do {
3781 lastindex = wkr.kindex;
3782 if (wkr.kindex == 0xffff) {
3783 ai->defindex = wkr.mac[0];
3785 rc = readWepKeyRid(ai, &wkr, 0, lock);
3786 } while(lastindex != wkr.kindex);
3789 ai->expires = RUN_AT(3*HZ);
3790 wake_up_interruptible(&ai->thr_wait);
3796 static u16 issuecommand(struct airo_info *ai, Cmd *pCmd, Resp *pRsp) {
3797 // Im really paranoid about letting it run forever!
3798 int max_tries = 600000;
3800 if (IN4500(ai, EVSTAT) & EV_CMD)
3801 OUT4500(ai, EVACK, EV_CMD);
3803 OUT4500(ai, PARAM0, pCmd->parm0);
3804 OUT4500(ai, PARAM1, pCmd->parm1);
3805 OUT4500(ai, PARAM2, pCmd->parm2);
3806 OUT4500(ai, COMMAND, pCmd->cmd);
3808 while (max_tries-- && (IN4500(ai, EVSTAT) & EV_CMD) == 0) {
3809 if ((IN4500(ai, COMMAND)) == pCmd->cmd)
3810 // PC4500 didn't notice command, try again
3811 OUT4500(ai, COMMAND, pCmd->cmd);
3812 if (!in_atomic() && (max_tries & 255) == 0)
3816 if ( max_tries == -1 ) {
3818 "airo: Max tries exceeded when issueing command\n" );
3819 if (IN4500(ai, COMMAND) & COMMAND_BUSY)
3820 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
3824 // command completed
3825 pRsp->status = IN4500(ai, STATUS);
3826 pRsp->rsp0 = IN4500(ai, RESP0);
3827 pRsp->rsp1 = IN4500(ai, RESP1);
3828 pRsp->rsp2 = IN4500(ai, RESP2);
3829 if ((pRsp->status & 0xff00)!=0 && pCmd->cmd != CMD_SOFTRESET) {
3830 printk (KERN_ERR "airo: cmd= %x\n", pCmd->cmd);
3831 printk (KERN_ERR "airo: status= %x\n", pRsp->status);
3832 printk (KERN_ERR "airo: Rsp0= %x\n", pRsp->rsp0);
3833 printk (KERN_ERR "airo: Rsp1= %x\n", pRsp->rsp1);
3834 printk (KERN_ERR "airo: Rsp2= %x\n", pRsp->rsp2);
3837 // clear stuck command busy if necessary
3838 if (IN4500(ai, COMMAND) & COMMAND_BUSY) {
3839 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
3841 // acknowledge processing the status/response
3842 OUT4500(ai, EVACK, EV_CMD);
3847 /* Sets up the bap to start exchange data. whichbap should
3848 * be one of the BAP0 or BAP1 defines. Locks should be held before
3850 static int bap_setup(struct airo_info *ai, u16 rid, u16 offset, int whichbap )
3855 OUT4500(ai, SELECT0+whichbap, rid);
3856 OUT4500(ai, OFFSET0+whichbap, offset);
3858 int status = IN4500(ai, OFFSET0+whichbap);
3859 if (status & BAP_BUSY) {
3860 /* This isn't really a timeout, but its kinda
3865 } else if ( status & BAP_ERR ) {
3866 /* invalid rid or offset */
3867 printk( KERN_ERR "airo: BAP error %x %d\n",
3870 } else if (status & BAP_DONE) { // success
3873 if ( !(max_tries--) ) {
3875 "airo: BAP setup error too many retries\n" );
3878 // -- PC4500 missed it, try again
3879 OUT4500(ai, SELECT0+whichbap, rid);
3880 OUT4500(ai, OFFSET0+whichbap, offset);
3885 /* should only be called by aux_bap_read. This aux function and the
3886 following use concepts not documented in the developers guide. I
3887 got them from a patch given to my by Aironet */
3888 static u16 aux_setup(struct airo_info *ai, u16 page,
3889 u16 offset, u16 *len)
3893 OUT4500(ai, AUXPAGE, page);
3894 OUT4500(ai, AUXOFF, 0);
3895 next = IN4500(ai, AUXDATA);
3896 *len = IN4500(ai, AUXDATA)&0xff;
3897 if (offset != 4) OUT4500(ai, AUXOFF, offset);
3901 /* requires call to bap_setup() first */
3902 static int aux_bap_read(struct airo_info *ai, u16 *pu16Dst,
3903 int bytelen, int whichbap)
3911 unsigned long flags;
3913 spin_lock_irqsave(&ai->aux_lock, flags);
3914 page = IN4500(ai, SWS0+whichbap);
3915 offset = IN4500(ai, SWS2+whichbap);
3916 next = aux_setup(ai, page, offset, &len);
3917 words = (bytelen+1)>>1;
3919 for (i=0; i<words;) {
3921 count = (len>>1) < (words-i) ? (len>>1) : (words-i);
3923 insw( ai->dev->base_addr+DATA0+whichbap,
3926 insb( ai->dev->base_addr+DATA0+whichbap,
3927 pu16Dst+i, count << 1 );
3930 next = aux_setup(ai, next, 4, &len);
3933 spin_unlock_irqrestore(&ai->aux_lock, flags);
3938 /* requires call to bap_setup() first */
3939 static int fast_bap_read(struct airo_info *ai, u16 *pu16Dst,
3940 int bytelen, int whichbap)
3942 bytelen = (bytelen + 1) & (~1); // round up to even value
3944 insw( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen>>1 );
3946 insb( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen );
3950 /* requires call to bap_setup() first */
3951 static int bap_write(struct airo_info *ai, const u16 *pu16Src,
3952 int bytelen, int whichbap)
3954 bytelen = (bytelen + 1) & (~1); // round up to even value
3956 outsw( ai->dev->base_addr+DATA0+whichbap,
3957 pu16Src, bytelen>>1 );
3959 outsb( ai->dev->base_addr+DATA0+whichbap, pu16Src, bytelen );
3963 static int PC4500_accessrid(struct airo_info *ai, u16 rid, u16 accmd)
3965 Cmd cmd; /* for issuing commands */
3966 Resp rsp; /* response from commands */
3969 memset(&cmd, 0, sizeof(cmd));
3972 status = issuecommand(ai, &cmd, &rsp);
3973 if (status != 0) return status;
3974 if ( (rsp.status & 0x7F00) != 0) {
3975 return (accmd << 8) + (rsp.rsp0 & 0xFF);
3980 /* Note, that we are using BAP1 which is also used by transmit, so
3981 * we must get a lock. */
3982 static int PC4500_readrid(struct airo_info *ai, u16 rid, void *pBuf, int len, int lock)
3988 if (down_interruptible(&ai->sem))
3991 if (test_bit(FLAG_MPI,&ai->flags)) {
3995 memset(&cmd, 0, sizeof(cmd));
3996 memset(&rsp, 0, sizeof(rsp));
3997 ai->config_desc.rid_desc.valid = 1;
3998 ai->config_desc.rid_desc.len = RIDSIZE;
3999 ai->config_desc.rid_desc.rid = 0;
4000 ai->config_desc.rid_desc.host_addr = ai->ridbus;
4002 cmd.cmd = CMD_ACCESS;
4005 memcpy_toio(ai->config_desc.card_ram_off,
4006 &ai->config_desc.rid_desc, sizeof(Rid));
4008 rc = issuecommand(ai, &cmd, &rsp);
4010 if (rsp.status & 0x7f00)
4013 memcpy(pBuf, ai->config_desc.virtual_host_addr, len);
4016 if ((status = PC4500_accessrid(ai, rid, CMD_ACCESS))!=SUCCESS) {
4020 if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
4024 // read the rid length field
4025 bap_read(ai, pBuf, 2, BAP1);
4026 // length for remaining part of rid
4027 len = min(len, (int)le16_to_cpu(*(u16*)pBuf)) - 2;
4031 "airo: Rid %x has a length of %d which is too short\n",
4032 (int)rid, (int)len );
4036 // read remainder of the rid
4037 rc = bap_read(ai, ((u16*)pBuf)+1, len, BAP1);
4045 /* Note, that we are using BAP1 which is also used by transmit, so
4046 * make sure this isnt called when a transmit is happening */
4047 static int PC4500_writerid(struct airo_info *ai, u16 rid,
4048 const void *pBuf, int len, int lock)
4053 *(u16*)pBuf = cpu_to_le16((u16)len);
4056 if (down_interruptible(&ai->sem))
4059 if (test_bit(FLAG_MPI,&ai->flags)) {
4063 if (test_bit(FLAG_ENABLED, &ai->flags))
4065 "%s: MAC should be disabled (rid=%04x)\n",
4067 memset(&cmd, 0, sizeof(cmd));
4068 memset(&rsp, 0, sizeof(rsp));
4070 ai->config_desc.rid_desc.valid = 1;
4071 ai->config_desc.rid_desc.len = *((u16 *)pBuf);
4072 ai->config_desc.rid_desc.rid = 0;
4074 cmd.cmd = CMD_WRITERID;
4077 memcpy_toio(ai->config_desc.card_ram_off,
4078 &ai->config_desc.rid_desc, sizeof(Rid));
4080 if (len < 4 || len > 2047) {
4081 printk(KERN_ERR "%s: len=%d\n",__FUNCTION__,len);
4084 memcpy((char *)ai->config_desc.virtual_host_addr,
4087 rc = issuecommand(ai, &cmd, &rsp);
4088 if ((rc & 0xff00) != 0) {
4089 printk(KERN_ERR "%s: Write rid Error %d\n",
4091 printk(KERN_ERR "%s: Cmd=%04x\n",
4092 __FUNCTION__,cmd.cmd);
4095 if ((rsp.status & 0x7f00))
4099 // --- first access so that we can write the rid data
4100 if ( (status = PC4500_accessrid(ai, rid, CMD_ACCESS)) != 0) {
4104 // --- now write the rid data
4105 if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
4109 bap_write(ai, pBuf, len, BAP1);
4110 // ---now commit the rid data
4111 rc = PC4500_accessrid(ai, rid, 0x100|CMD_ACCESS);
4119 /* Allocates a FID to be used for transmitting packets. We only use
4121 static u16 transmit_allocate(struct airo_info *ai, int lenPayload, int raw)
4123 unsigned int loop = 3000;
4129 cmd.cmd = CMD_ALLOCATETX;
4130 cmd.parm0 = lenPayload;
4131 if (down_interruptible(&ai->sem))
4133 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
4137 if ( (rsp.status & 0xFF00) != 0) {
4141 /* wait for the allocate event/indication
4142 * It makes me kind of nervous that this can just sit here and spin,
4143 * but in practice it only loops like four times. */
4144 while (((IN4500(ai, EVSTAT) & EV_ALLOC) == 0) && --loop);
4150 // get the allocated fid and acknowledge
4151 txFid = IN4500(ai, TXALLOCFID);
4152 OUT4500(ai, EVACK, EV_ALLOC);
4154 /* The CARD is pretty cool since it converts the ethernet packet
4155 * into 802.11. Also note that we don't release the FID since we
4156 * will be using the same one over and over again. */
4157 /* We only have to setup the control once since we are not
4158 * releasing the fid. */
4160 txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_11
4161 | TXCTL_ETHERNET | TXCTL_NORELEASE);
4163 txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_3
4164 | TXCTL_ETHERNET | TXCTL_NORELEASE);
4165 if (bap_setup(ai, txFid, 0x0008, BAP1) != SUCCESS)
4168 bap_write(ai, &txControl, sizeof(txControl), BAP1);
4176 /* In general BAP1 is dedicated to transmiting packets. However,
4177 since we need a BAP when accessing RIDs, we also use BAP1 for that.
4178 Make sure the BAP1 spinlock is held when this is called. */
4179 static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket)
4190 if (len <= ETH_ALEN * 2) {
4191 printk( KERN_WARNING "Short packet %d\n", len );
4194 len -= ETH_ALEN * 2;
4197 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
4198 (ntohs(((u16 *)pPacket)[6]) != 0x888E)) {
4199 if (encapsulate(ai,(etherHead *)pPacket,&pMic,len) != SUCCESS)
4201 miclen = sizeof(pMic);
4205 // packet is destination[6], source[6], payload[len-12]
4206 // write the payload length and dst/src/payload
4207 if (bap_setup(ai, txFid, 0x0036, BAP1) != SUCCESS) return ERROR;
4208 /* The hardware addresses aren't counted as part of the payload, so
4209 * we have to subtract the 12 bytes for the addresses off */
4210 payloadLen = cpu_to_le16(len + miclen);
4211 bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
4212 bap_write(ai, (const u16*)pPacket, sizeof(etherHead), BAP1);
4214 bap_write(ai, (const u16*)&pMic, miclen, BAP1);
4215 bap_write(ai, (const u16*)(pPacket + sizeof(etherHead)), len, BAP1);
4216 // issue the transmit command
4217 memset( &cmd, 0, sizeof( cmd ) );
4218 cmd.cmd = CMD_TRANSMIT;
4220 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
4221 if ( (rsp.status & 0xFF00) != 0) return ERROR;
4225 static int transmit_802_11_packet(struct airo_info *ai, int len, char *pPacket)
4240 fc = le16_to_cpu(*(const u16*)pPacket);
4243 if ((fc & 0xe0) == 0xc0)
4249 if ((fc&0x300)==0x300){
4258 printk( KERN_WARNING "Short packet %d\n", len );
4262 /* packet is 802.11 header + payload
4263 * write the payload length and dst/src/payload */
4264 if (bap_setup(ai, txFid, 6, BAP1) != SUCCESS) return ERROR;
4265 /* The 802.11 header aren't counted as part of the payload, so
4266 * we have to subtract the header bytes off */
4267 payloadLen = cpu_to_le16(len-hdrlen);
4268 bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
4269 if (bap_setup(ai, txFid, 0x0014, BAP1) != SUCCESS) return ERROR;
4270 bap_write(ai, (const u16*)pPacket, hdrlen, BAP1);
4271 bap_write(ai, hdrlen == 30 ?
4272 (const u16*)&gap.gaplen : (const u16*)&gap, 38 - hdrlen, BAP1);
4274 bap_write(ai, (const u16*)(pPacket + hdrlen), len - hdrlen, BAP1);
4275 // issue the transmit command
4276 memset( &cmd, 0, sizeof( cmd ) );
4277 cmd.cmd = CMD_TRANSMIT;
4279 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
4280 if ( (rsp.status & 0xFF00) != 0) return ERROR;
4285 * This is the proc_fs routines. It is a bit messier than I would
4286 * like! Feel free to clean it up!
4289 static ssize_t proc_read( struct file *file,
4290 char __user *buffer,
4294 static ssize_t proc_write( struct file *file,
4295 const char __user *buffer,
4298 static int proc_close( struct inode *inode, struct file *file );
4300 static int proc_stats_open( struct inode *inode, struct file *file );
4301 static int proc_statsdelta_open( struct inode *inode, struct file *file );
4302 static int proc_status_open( struct inode *inode, struct file *file );
4303 static int proc_SSID_open( struct inode *inode, struct file *file );
4304 static int proc_APList_open( struct inode *inode, struct file *file );
4305 static int proc_BSSList_open( struct inode *inode, struct file *file );
4306 static int proc_config_open( struct inode *inode, struct file *file );
4307 static int proc_wepkey_open( struct inode *inode, struct file *file );
4309 static struct file_operations proc_statsdelta_ops = {
4311 .open = proc_statsdelta_open,
4312 .release = proc_close
4315 static struct file_operations proc_stats_ops = {
4317 .open = proc_stats_open,
4318 .release = proc_close
4321 static struct file_operations proc_status_ops = {
4323 .open = proc_status_open,
4324 .release = proc_close
4327 static struct file_operations proc_SSID_ops = {
4329 .write = proc_write,
4330 .open = proc_SSID_open,
4331 .release = proc_close
4334 static struct file_operations proc_BSSList_ops = {
4336 .write = proc_write,
4337 .open = proc_BSSList_open,
4338 .release = proc_close
4341 static struct file_operations proc_APList_ops = {
4343 .write = proc_write,
4344 .open = proc_APList_open,
4345 .release = proc_close
4348 static struct file_operations proc_config_ops = {
4350 .write = proc_write,
4351 .open = proc_config_open,
4352 .release = proc_close
4355 static struct file_operations proc_wepkey_ops = {
4357 .write = proc_write,
4358 .open = proc_wepkey_open,
4359 .release = proc_close
4362 static struct proc_dir_entry *airo_entry;
4371 void (*on_close) (struct inode *, struct file *);
4375 #define SETPROC_OPS(entry, ops) (entry)->proc_fops = &(ops)
4378 static int setup_proc_entry( struct net_device *dev,
4379 struct airo_info *apriv ) {
4380 struct proc_dir_entry *entry;
4381 /* First setup the device directory */
4382 strcpy(apriv->proc_name,dev->name);
4383 apriv->proc_entry = create_proc_entry(apriv->proc_name,
4386 apriv->proc_entry->uid = proc_uid;
4387 apriv->proc_entry->gid = proc_gid;
4388 apriv->proc_entry->owner = THIS_MODULE;
4390 /* Setup the StatsDelta */
4391 entry = create_proc_entry("StatsDelta",
4392 S_IFREG | (S_IRUGO&proc_perm),
4394 entry->uid = proc_uid;
4395 entry->gid = proc_gid;
4397 entry->owner = THIS_MODULE;
4398 SETPROC_OPS(entry, proc_statsdelta_ops);
4400 /* Setup the Stats */
4401 entry = create_proc_entry("Stats",
4402 S_IFREG | (S_IRUGO&proc_perm),
4404 entry->uid = proc_uid;
4405 entry->gid = proc_gid;
4407 entry->owner = THIS_MODULE;
4408 SETPROC_OPS(entry, proc_stats_ops);
4410 /* Setup the Status */
4411 entry = create_proc_entry("Status",
4412 S_IFREG | (S_IRUGO&proc_perm),
4414 entry->uid = proc_uid;
4415 entry->gid = proc_gid;
4417 entry->owner = THIS_MODULE;
4418 SETPROC_OPS(entry, proc_status_ops);
4420 /* Setup the Config */
4421 entry = create_proc_entry("Config",
4422 S_IFREG | proc_perm,
4424 entry->uid = proc_uid;
4425 entry->gid = proc_gid;
4427 entry->owner = THIS_MODULE;
4428 SETPROC_OPS(entry, proc_config_ops);
4430 /* Setup the SSID */
4431 entry = create_proc_entry("SSID",
4432 S_IFREG | proc_perm,
4434 entry->uid = proc_uid;
4435 entry->gid = proc_gid;
4437 entry->owner = THIS_MODULE;
4438 SETPROC_OPS(entry, proc_SSID_ops);
4440 /* Setup the APList */
4441 entry = create_proc_entry("APList",
4442 S_IFREG | proc_perm,
4444 entry->uid = proc_uid;
4445 entry->gid = proc_gid;
4447 entry->owner = THIS_MODULE;
4448 SETPROC_OPS(entry, proc_APList_ops);
4450 /* Setup the BSSList */
4451 entry = create_proc_entry("BSSList",
4452 S_IFREG | proc_perm,
4454 entry->uid = proc_uid;
4455 entry->gid = proc_gid;
4457 entry->owner = THIS_MODULE;
4458 SETPROC_OPS(entry, proc_BSSList_ops);
4460 /* Setup the WepKey */
4461 entry = create_proc_entry("WepKey",
4462 S_IFREG | proc_perm,
4464 entry->uid = proc_uid;
4465 entry->gid = proc_gid;
4467 entry->owner = THIS_MODULE;
4468 SETPROC_OPS(entry, proc_wepkey_ops);
4473 static int takedown_proc_entry( struct net_device *dev,
4474 struct airo_info *apriv ) {
4475 if ( !apriv->proc_entry->namelen ) return 0;
4476 remove_proc_entry("Stats",apriv->proc_entry);
4477 remove_proc_entry("StatsDelta",apriv->proc_entry);
4478 remove_proc_entry("Status",apriv->proc_entry);
4479 remove_proc_entry("Config",apriv->proc_entry);
4480 remove_proc_entry("SSID",apriv->proc_entry);
4481 remove_proc_entry("APList",apriv->proc_entry);
4482 remove_proc_entry("BSSList",apriv->proc_entry);
4483 remove_proc_entry("WepKey",apriv->proc_entry);
4484 remove_proc_entry(apriv->proc_name,airo_entry);
4489 * What we want from the proc_fs is to be able to efficiently read
4490 * and write the configuration. To do this, we want to read the
4491 * configuration when the file is opened and write it when the file is
4492 * closed. So basically we allocate a read buffer at open and fill it
4493 * with data, and allocate a write buffer and read it at close.
4497 * The read routine is generic, it relies on the preallocated rbuffer
4498 * to supply the data.
4500 static ssize_t proc_read( struct file *file,
4501 char __user *buffer,
4505 loff_t pos = *offset;
4506 struct proc_data *priv = (struct proc_data*)file->private_data;
4513 if (pos >= priv->readlen)
4515 if (len > priv->readlen - pos)
4516 len = priv->readlen - pos;
4517 if (copy_to_user(buffer, priv->rbuffer + pos, len))
4519 *offset = pos + len;
4524 * The write routine is generic, it fills in a preallocated rbuffer
4525 * to supply the data.
4527 static ssize_t proc_write( struct file *file,
4528 const char __user *buffer,
4532 loff_t pos = *offset;
4533 struct proc_data *priv = (struct proc_data*)file->private_data;
4540 if (pos >= priv->maxwritelen)
4542 if (len > priv->maxwritelen - pos)
4543 len = priv->maxwritelen - pos;
4544 if (copy_from_user(priv->wbuffer + pos, buffer, len))
4546 if ( pos + len > priv->writelen )
4547 priv->writelen = len + file->f_pos;
4548 *offset = pos + len;
4552 static int proc_status_open( struct inode *inode, struct file *file ) {
4553 struct proc_data *data;
4554 struct proc_dir_entry *dp = PDE(inode);
4555 struct net_device *dev = dp->data;
4556 struct airo_info *apriv = dev->priv;
4557 CapabilityRid cap_rid;
4558 StatusRid status_rid;
4561 if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4563 memset(file->private_data, 0, sizeof(struct proc_data));
4564 data = (struct proc_data *)file->private_data;
4565 if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
4566 kfree (file->private_data);
4570 readStatusRid(apriv, &status_rid, 1);
4571 readCapabilityRid(apriv, &cap_rid, 1);
4573 i = sprintf(data->rbuffer, "Status: %s%s%s%s%s%s%s%s%s\n",
4574 status_rid.mode & 1 ? "CFG ": "",
4575 status_rid.mode & 2 ? "ACT ": "",
4576 status_rid.mode & 0x10 ? "SYN ": "",
4577 status_rid.mode & 0x20 ? "LNK ": "",
4578 status_rid.mode & 0x40 ? "LEAP ": "",
4579 status_rid.mode & 0x80 ? "PRIV ": "",
4580 status_rid.mode & 0x100 ? "KEY ": "",
4581 status_rid.mode & 0x200 ? "WEP ": "",
4582 status_rid.mode & 0x8000 ? "ERR ": "");
4583 sprintf( data->rbuffer+i, "Mode: %x\n"
4584 "Signal Strength: %d\n"
4585 "Signal Quality: %d\n"
4590 "Driver Version: %s\n"
4591 "Device: %s\nManufacturer: %s\nFirmware Version: %s\n"
4592 "Radio type: %x\nCountry: %x\nHardware Version: %x\n"
4593 "Software Version: %x\nSoftware Subversion: %x\n"
4594 "Boot block version: %x\n",
4595 (int)status_rid.mode,
4596 (int)status_rid.normalizedSignalStrength,
4597 (int)status_rid.signalQuality,
4598 (int)status_rid.SSIDlen,
4601 (int)status_rid.channel,
4602 (int)status_rid.currentXmitRate/2,
4610 (int)cap_rid.softVer,
4611 (int)cap_rid.softSubVer,
4612 (int)cap_rid.bootBlockVer );
4613 data->readlen = strlen( data->rbuffer );
4617 static int proc_stats_rid_open(struct inode*, struct file*, u16);
4618 static int proc_statsdelta_open( struct inode *inode,
4619 struct file *file ) {
4620 if (file->f_mode&FMODE_WRITE) {
4621 return proc_stats_rid_open(inode, file, RID_STATSDELTACLEAR);
4623 return proc_stats_rid_open(inode, file, RID_STATSDELTA);
4626 static int proc_stats_open( struct inode *inode, struct file *file ) {
4627 return proc_stats_rid_open(inode, file, RID_STATS);
4630 static int proc_stats_rid_open( struct inode *inode,
4633 struct proc_data *data;
4634 struct proc_dir_entry *dp = PDE(inode);
4635 struct net_device *dev = dp->data;
4636 struct airo_info *apriv = dev->priv;
4639 u32 *vals = stats.vals;
4641 if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4643 memset(file->private_data, 0, sizeof(struct proc_data));
4644 data = (struct proc_data *)file->private_data;
4645 if ((data->rbuffer = kmalloc( 4096, GFP_KERNEL )) == NULL) {
4646 kfree (file->private_data);
4650 readStatsRid(apriv, &stats, rid, 1);
4653 for(i=0; statsLabels[i]!=(char *)-1 &&
4654 i*4<stats.len; i++){
4655 if (!statsLabels[i]) continue;
4656 if (j+strlen(statsLabels[i])+16>4096) {
4658 "airo: Potentially disasterous buffer overflow averted!\n");
4661 j+=sprintf(data->rbuffer+j, "%s: %u\n", statsLabels[i], vals[i]);
4663 if (i*4>=stats.len){
4665 "airo: Got a short rid\n");
4671 static int get_dec_u16( char *buffer, int *start, int limit ) {
4674 for( value = 0; buffer[*start] >= '0' &&
4675 buffer[*start] <= '9' &&
4676 *start < limit; (*start)++ ) {
4679 value += buffer[*start] - '0';
4681 if ( !valid ) return -1;
4685 static int airo_config_commit(struct net_device *dev,
4686 struct iw_request_info *info, void *zwrq,
4689 static void proc_config_on_close( struct inode *inode, struct file *file ) {
4690 struct proc_data *data = file->private_data;
4691 struct proc_dir_entry *dp = PDE(inode);
4692 struct net_device *dev = dp->data;
4693 struct airo_info *ai = dev->priv;
4696 if ( !data->writelen ) return;
4698 readConfigRid(ai, 1);
4699 set_bit (FLAG_COMMIT, &ai->flags);
4701 line = data->wbuffer;
4703 /*** Mode processing */
4704 if ( !strncmp( line, "Mode: ", 6 ) ) {
4706 if ((ai->config.rmode & 0xff) >= RXMODE_RFMON)
4707 set_bit (FLAG_RESET, &ai->flags);
4708 ai->config.rmode &= 0xfe00;
4709 clear_bit (FLAG_802_11, &ai->flags);
4710 ai->config.opmode &= 0xFF00;
4711 ai->config.scanMode = SCANMODE_ACTIVE;
4712 if ( line[0] == 'a' ) {
4713 ai->config.opmode |= 0;
4715 ai->config.opmode |= 1;
4716 if ( line[0] == 'r' ) {
4717 ai->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
4718 ai->config.scanMode = SCANMODE_PASSIVE;
4719 set_bit (FLAG_802_11, &ai->flags);
4720 } else if ( line[0] == 'y' ) {
4721 ai->config.rmode |= RXMODE_RFMON_ANYBSS | RXMODE_DISABLE_802_3_HEADER;
4722 ai->config.scanMode = SCANMODE_PASSIVE;
4723 set_bit (FLAG_802_11, &ai->flags);
4724 } else if ( line[0] == 'l' )
4725 ai->config.rmode |= RXMODE_LANMON;
4727 set_bit (FLAG_COMMIT, &ai->flags);
4730 /*** Radio status */
4731 else if (!strncmp(line,"Radio: ", 7)) {
4733 if (!strncmp(line,"off",3)) {
4734 set_bit (FLAG_RADIO_OFF, &ai->flags);
4736 clear_bit (FLAG_RADIO_OFF, &ai->flags);
4739 /*** NodeName processing */
4740 else if ( !strncmp( line, "NodeName: ", 10 ) ) {
4744 memset( ai->config.nodeName, 0, 16 );
4745 /* Do the name, assume a space between the mode and node name */
4746 for( j = 0; j < 16 && line[j] != '\n'; j++ ) {
4747 ai->config.nodeName[j] = line[j];
4749 set_bit (FLAG_COMMIT, &ai->flags);
4752 /*** PowerMode processing */
4753 else if ( !strncmp( line, "PowerMode: ", 11 ) ) {
4755 if ( !strncmp( line, "PSPCAM", 6 ) ) {
4756 ai->config.powerSaveMode = POWERSAVE_PSPCAM;
4757 set_bit (FLAG_COMMIT, &ai->flags);
4758 } else if ( !strncmp( line, "PSP", 3 ) ) {
4759 ai->config.powerSaveMode = POWERSAVE_PSP;
4760 set_bit (FLAG_COMMIT, &ai->flags);
4762 ai->config.powerSaveMode = POWERSAVE_CAM;
4763 set_bit (FLAG_COMMIT, &ai->flags);
4765 } else if ( !strncmp( line, "DataRates: ", 11 ) ) {
4766 int v, i = 0, k = 0; /* i is index into line,
4767 k is index to rates */
4770 while((v = get_dec_u16(line, &i, 3))!=-1) {
4771 ai->config.rates[k++] = (u8)v;
4775 set_bit (FLAG_COMMIT, &ai->flags);
4776 } else if ( !strncmp( line, "Channel: ", 9 ) ) {
4779 v = get_dec_u16(line, &i, i+3);
4781 ai->config.channelSet = (u16)v;
4782 set_bit (FLAG_COMMIT, &ai->flags);
4784 } else if ( !strncmp( line, "XmitPower: ", 11 ) ) {
4787 v = get_dec_u16(line, &i, i+3);
4789 ai->config.txPower = (u16)v;
4790 set_bit (FLAG_COMMIT, &ai->flags);
4792 } else if ( !strncmp( line, "WEP: ", 5 ) ) {
4796 ai->config.authType = (u16)AUTH_SHAREDKEY;
4799 ai->config.authType = (u16)AUTH_ENCRYPT;
4802 ai->config.authType = (u16)AUTH_OPEN;
4805 set_bit (FLAG_COMMIT, &ai->flags);
4806 } else if ( !strncmp( line, "LongRetryLimit: ", 16 ) ) {
4810 v = get_dec_u16(line, &i, 3);
4811 v = (v<0) ? 0 : ((v>255) ? 255 : v);
4812 ai->config.longRetryLimit = (u16)v;
4813 set_bit (FLAG_COMMIT, &ai->flags);
4814 } else if ( !strncmp( line, "ShortRetryLimit: ", 17 ) ) {
4818 v = get_dec_u16(line, &i, 3);
4819 v = (v<0) ? 0 : ((v>255) ? 255 : v);
4820 ai->config.shortRetryLimit = (u16)v;
4821 set_bit (FLAG_COMMIT, &ai->flags);
4822 } else if ( !strncmp( line, "RTSThreshold: ", 14 ) ) {
4826 v = get_dec_u16(line, &i, 4);
4827 v = (v<0) ? 0 : ((v>2312) ? 2312 : v);
4828 ai->config.rtsThres = (u16)v;
4829 set_bit (FLAG_COMMIT, &ai->flags);
4830 } else if ( !strncmp( line, "TXMSDULifetime: ", 16 ) ) {
4834 v = get_dec_u16(line, &i, 5);
4836 ai->config.txLifetime = (u16)v;
4837 set_bit (FLAG_COMMIT, &ai->flags);
4838 } else if ( !strncmp( line, "RXMSDULifetime: ", 16 ) ) {
4842 v = get_dec_u16(line, &i, 5);
4844 ai->config.rxLifetime = (u16)v;
4845 set_bit (FLAG_COMMIT, &ai->flags);
4846 } else if ( !strncmp( line, "TXDiversity: ", 13 ) ) {
4847 ai->config.txDiversity =
4848 (line[13]=='l') ? 1 :
4849 ((line[13]=='r')? 2: 3);
4850 set_bit (FLAG_COMMIT, &ai->flags);
4851 } else if ( !strncmp( line, "RXDiversity: ", 13 ) ) {
4852 ai->config.rxDiversity =
4853 (line[13]=='l') ? 1 :
4854 ((line[13]=='r')? 2: 3);
4855 set_bit (FLAG_COMMIT, &ai->flags);
4856 } else if ( !strncmp( line, "FragThreshold: ", 15 ) ) {
4860 v = get_dec_u16(line, &i, 4);
4861 v = (v<256) ? 256 : ((v>2312) ? 2312 : v);
4862 v = v & 0xfffe; /* Make sure its even */
4863 ai->config.fragThresh = (u16)v;
4864 set_bit (FLAG_COMMIT, &ai->flags);
4865 } else if (!strncmp(line, "Modulation: ", 12)) {
4868 case 'd': ai->config.modulation=MOD_DEFAULT; set_bit(FLAG_COMMIT, &ai->flags); break;
4869 case 'c': ai->config.modulation=MOD_CCK; set_bit(FLAG_COMMIT, &ai->flags); break;
4870 case 'm': ai->config.modulation=MOD_MOK; set_bit(FLAG_COMMIT, &ai->flags); break;
4872 printk( KERN_WARNING "airo: Unknown modulation\n" );
4874 } else if (!strncmp(line, "Preamble: ", 10)) {
4877 case 'a': ai->config.preamble=PREAMBLE_AUTO; set_bit(FLAG_COMMIT, &ai->flags); break;
4878 case 'l': ai->config.preamble=PREAMBLE_LONG; set_bit(FLAG_COMMIT, &ai->flags); break;
4879 case 's': ai->config.preamble=PREAMBLE_SHORT; set_bit(FLAG_COMMIT, &ai->flags); break;
4880 default: printk(KERN_WARNING "airo: Unknown preamble\n");
4883 printk( KERN_WARNING "Couldn't figure out %s\n", line );
4885 while( line[0] && line[0] != '\n' ) line++;
4886 if ( line[0] ) line++;
4888 airo_config_commit(dev, NULL, NULL, NULL);
4891 static char *get_rmode(u16 mode) {
4893 case RXMODE_RFMON: return "rfmon";
4894 case RXMODE_RFMON_ANYBSS: return "yna (any) bss rfmon";
4895 case RXMODE_LANMON: return "lanmon";
4900 static int proc_config_open( struct inode *inode, struct file *file ) {
4901 struct proc_data *data;
4902 struct proc_dir_entry *dp = PDE(inode);
4903 struct net_device *dev = dp->data;
4904 struct airo_info *ai = dev->priv;
4907 if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4909 memset(file->private_data, 0, sizeof(struct proc_data));
4910 data = (struct proc_data *)file->private_data;
4911 if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
4912 kfree (file->private_data);
4915 if ((data->wbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
4916 kfree (data->rbuffer);
4917 kfree (file->private_data);
4920 memset( data->wbuffer, 0, 2048 );
4921 data->maxwritelen = 2048;
4922 data->on_close = proc_config_on_close;
4924 readConfigRid(ai, 1);
4926 i = sprintf( data->rbuffer,
4931 "DataRates: %d %d %d %d %d %d %d %d\n"
4934 (ai->config.opmode & 0xFF) == 0 ? "adhoc" :
4935 (ai->config.opmode & 0xFF) == 1 ? get_rmode(ai->config.rmode):
4936 (ai->config.opmode & 0xFF) == 2 ? "AP" :
4937 (ai->config.opmode & 0xFF) == 3 ? "AP RPTR" : "Error",
4938 test_bit(FLAG_RADIO_OFF, &ai->flags) ? "off" : "on",
4939 ai->config.nodeName,
4940 ai->config.powerSaveMode == 0 ? "CAM" :
4941 ai->config.powerSaveMode == 1 ? "PSP" :
4942 ai->config.powerSaveMode == 2 ? "PSPCAM" : "Error",
4943 (int)ai->config.rates[0],
4944 (int)ai->config.rates[1],
4945 (int)ai->config.rates[2],
4946 (int)ai->config.rates[3],
4947 (int)ai->config.rates[4],
4948 (int)ai->config.rates[5],
4949 (int)ai->config.rates[6],
4950 (int)ai->config.rates[7],
4951 (int)ai->config.channelSet,
4952 (int)ai->config.txPower
4954 sprintf( data->rbuffer + i,
4955 "LongRetryLimit: %d\n"
4956 "ShortRetryLimit: %d\n"
4957 "RTSThreshold: %d\n"
4958 "TXMSDULifetime: %d\n"
4959 "RXMSDULifetime: %d\n"
4962 "FragThreshold: %d\n"
4966 (int)ai->config.longRetryLimit,
4967 (int)ai->config.shortRetryLimit,
4968 (int)ai->config.rtsThres,
4969 (int)ai->config.txLifetime,
4970 (int)ai->config.rxLifetime,
4971 ai->config.txDiversity == 1 ? "left" :
4972 ai->config.txDiversity == 2 ? "right" : "both",
4973 ai->config.rxDiversity == 1 ? "left" :
4974 ai->config.rxDiversity == 2 ? "right" : "both",
4975 (int)ai->config.fragThresh,
4976 ai->config.authType == AUTH_ENCRYPT ? "encrypt" :
4977 ai->config.authType == AUTH_SHAREDKEY ? "shared" : "open",
4978 ai->config.modulation == 0 ? "default" :
4979 ai->config.modulation == MOD_CCK ? "cck" :
4980 ai->config.modulation == MOD_MOK ? "mok" : "error",
4981 ai->config.preamble == PREAMBLE_AUTO ? "auto" :
4982 ai->config.preamble == PREAMBLE_LONG ? "long" :
4983 ai->config.preamble == PREAMBLE_SHORT ? "short" : "error"
4985 data->readlen = strlen( data->rbuffer );
4989 static void proc_SSID_on_close( struct inode *inode, struct file *file ) {
4990 struct proc_data *data = (struct proc_data *)file->private_data;
4991 struct proc_dir_entry *dp = PDE(inode);
4992 struct net_device *dev = dp->data;
4993 struct airo_info *ai = dev->priv;
4999 if ( !data->writelen ) return;
5001 memset( &SSID_rid, 0, sizeof( SSID_rid ) );
5003 for( i = 0; i < 3; i++ ) {
5005 for( j = 0; j+offset < data->writelen && j < 32 &&
5006 data->wbuffer[offset+j] != '\n'; j++ ) {
5007 SSID_rid.ssids[i].ssid[j] = data->wbuffer[offset+j];
5009 if ( j == 0 ) break;
5010 SSID_rid.ssids[i].len = j;
5012 while( data->wbuffer[offset] != '\n' &&
5013 offset < data->writelen ) offset++;
5017 SSID_rid.len = sizeof(SSID_rid);
5019 writeSsidRid(ai, &SSID_rid, 1);
5020 enable_MAC(ai, &rsp, 1);
5023 static inline u8 hexVal(char c) {
5024 if (c>='0' && c<='9') return c -= '0';
5025 if (c>='a' && c<='f') return c -= 'a'-10;
5026 if (c>='A' && c<='F') return c -= 'A'-10;
5030 static void proc_APList_on_close( struct inode *inode, struct file *file ) {
5031 struct proc_data *data = (struct proc_data *)file->private_data;
5032 struct proc_dir_entry *dp = PDE(inode);
5033 struct net_device *dev = dp->data;
5034 struct airo_info *ai = dev->priv;
5035 APListRid APList_rid;
5039 if ( !data->writelen ) return;
5041 memset( &APList_rid, 0, sizeof(APList_rid) );
5042 APList_rid.len = sizeof(APList_rid);
5044 for( i = 0; i < 4 && data->writelen >= (i+1)*6*3; i++ ) {
5046 for( j = 0; j < 6*3 && data->wbuffer[j+i*6*3]; j++ ) {
5049 APList_rid.ap[i][j/3]=
5050 hexVal(data->wbuffer[j+i*6*3])<<4;
5053 APList_rid.ap[i][j/3]|=
5054 hexVal(data->wbuffer[j+i*6*3]);
5060 writeAPListRid(ai, &APList_rid, 1);
5061 enable_MAC(ai, &rsp, 1);
5064 /* This function wraps PC4500_writerid with a MAC disable */
5065 static int do_writerid( struct airo_info *ai, u16 rid, const void *rid_data,
5066 int len, int dummy ) {
5071 rc = PC4500_writerid(ai, rid, rid_data, len, 1);
5072 enable_MAC(ai, &rsp, 1);
5076 /* Returns the length of the key at the index. If index == 0xffff
5077 * the index of the transmit key is returned. If the key doesn't exist,
5078 * -1 will be returned.
5080 static int get_wep_key(struct airo_info *ai, u16 index) {
5085 rc = readWepKeyRid(ai, &wkr, 1, 1);
5086 if (rc == SUCCESS) do {
5087 lastindex = wkr.kindex;
5088 if (wkr.kindex == index) {
5089 if (index == 0xffff) {
5094 readWepKeyRid(ai, &wkr, 0, 1);
5095 } while(lastindex != wkr.kindex);
5099 static int set_wep_key(struct airo_info *ai, u16 index,
5100 const char *key, u16 keylen, int perm, int lock ) {
5101 static const unsigned char macaddr[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
5105 memset(&wkr, 0, sizeof(wkr));
5107 // We are selecting which key to use
5108 wkr.len = sizeof(wkr);
5109 wkr.kindex = 0xffff;
5110 wkr.mac[0] = (char)index;
5111 if (perm) printk(KERN_INFO "Setting transmit key to %d\n", index);
5112 if (perm) ai->defindex = (char)index;
5114 // We are actually setting the key
5115 wkr.len = sizeof(wkr);
5118 memcpy( wkr.key, key, keylen );
5119 memcpy( wkr.mac, macaddr, ETH_ALEN );
5120 printk(KERN_INFO "Setting key %d\n", index);
5123 disable_MAC(ai, lock);
5124 writeWepKeyRid(ai, &wkr, perm, lock);
5125 enable_MAC(ai, &rsp, lock);
5129 static void proc_wepkey_on_close( struct inode *inode, struct file *file ) {
5130 struct proc_data *data;
5131 struct proc_dir_entry *dp = PDE(inode);
5132 struct net_device *dev = dp->data;
5133 struct airo_info *ai = dev->priv;
5139 memset(key, 0, sizeof(key));
5141 data = (struct proc_data *)file->private_data;
5142 if ( !data->writelen ) return;
5144 if (data->wbuffer[0] >= '0' && data->wbuffer[0] <= '3' &&
5145 (data->wbuffer[1] == ' ' || data->wbuffer[1] == '\n')) {
5146 index = data->wbuffer[0] - '0';
5147 if (data->wbuffer[1] == '\n') {
5148 set_wep_key(ai, index, NULL, 0, 1, 1);
5153 printk(KERN_ERR "airo: WepKey passed invalid key index\n");
5157 for( i = 0; i < 16*3 && data->wbuffer[i+j]; i++ ) {
5160 key[i/3] = hexVal(data->wbuffer[i+j])<<4;
5163 key[i/3] |= hexVal(data->wbuffer[i+j]);
5167 set_wep_key(ai, index, key, i/3, 1, 1);
5170 static int proc_wepkey_open( struct inode *inode, struct file *file ) {
5171 struct proc_data *data;
5172 struct proc_dir_entry *dp = PDE(inode);
5173 struct net_device *dev = dp->data;
5174 struct airo_info *ai = dev->priv;
5181 if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5183 memset(file->private_data, 0, sizeof(struct proc_data));
5184 memset(&wkr, 0, sizeof(wkr));
5185 data = (struct proc_data *)file->private_data;
5186 if ((data->rbuffer = kmalloc( 180, GFP_KERNEL )) == NULL) {
5187 kfree (file->private_data);
5190 memset(data->rbuffer, 0, 180);
5192 data->maxwritelen = 80;
5193 if ((data->wbuffer = kmalloc( 80, GFP_KERNEL )) == NULL) {
5194 kfree (data->rbuffer);
5195 kfree (file->private_data);
5198 memset( data->wbuffer, 0, 80 );
5199 data->on_close = proc_wepkey_on_close;
5201 ptr = data->rbuffer;
5202 strcpy(ptr, "No wep keys\n");
5203 rc = readWepKeyRid(ai, &wkr, 1, 1);
5204 if (rc == SUCCESS) do {
5205 lastindex = wkr.kindex;
5206 if (wkr.kindex == 0xffff) {
5207 j += sprintf(ptr+j, "Tx key = %d\n",
5210 j += sprintf(ptr+j, "Key %d set with length = %d\n",
5211 (int)wkr.kindex, (int)wkr.klen);
5213 readWepKeyRid(ai, &wkr, 0, 1);
5214 } while((lastindex != wkr.kindex) && (j < 180-30));
5216 data->readlen = strlen( data->rbuffer );
5220 static int proc_SSID_open( struct inode *inode, struct file *file ) {
5221 struct proc_data *data;
5222 struct proc_dir_entry *dp = PDE(inode);
5223 struct net_device *dev = dp->data;
5224 struct airo_info *ai = dev->priv;
5229 if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5231 memset(file->private_data, 0, sizeof(struct proc_data));
5232 data = (struct proc_data *)file->private_data;
5233 if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
5234 kfree (file->private_data);
5238 data->maxwritelen = 33*3;
5239 if ((data->wbuffer = kmalloc( 33*3, GFP_KERNEL )) == NULL) {
5240 kfree (data->rbuffer);
5241 kfree (file->private_data);
5244 memset( data->wbuffer, 0, 33*3 );
5245 data->on_close = proc_SSID_on_close;
5247 readSsidRid(ai, &SSID_rid);
5248 ptr = data->rbuffer;
5249 for( i = 0; i < 3; i++ ) {
5251 if ( !SSID_rid.ssids[i].len ) break;
5252 for( j = 0; j < 32 &&
5253 j < SSID_rid.ssids[i].len &&
5254 SSID_rid.ssids[i].ssid[j]; j++ ) {
5255 *ptr++ = SSID_rid.ssids[i].ssid[j];
5260 data->readlen = strlen( data->rbuffer );
5264 static int proc_APList_open( struct inode *inode, struct file *file ) {
5265 struct proc_data *data;
5266 struct proc_dir_entry *dp = PDE(inode);
5267 struct net_device *dev = dp->data;
5268 struct airo_info *ai = dev->priv;
5271 APListRid APList_rid;
5273 if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5275 memset(file->private_data, 0, sizeof(struct proc_data));
5276 data = (struct proc_data *)file->private_data;
5277 if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
5278 kfree (file->private_data);
5282 data->maxwritelen = 4*6*3;
5283 if ((data->wbuffer = kmalloc( data->maxwritelen, GFP_KERNEL )) == NULL) {
5284 kfree (data->rbuffer);
5285 kfree (file->private_data);
5288 memset( data->wbuffer, 0, data->maxwritelen );
5289 data->on_close = proc_APList_on_close;
5291 readAPListRid(ai, &APList_rid);
5292 ptr = data->rbuffer;
5293 for( i = 0; i < 4; i++ ) {
5294 // We end when we find a zero MAC
5295 if ( !*(int*)APList_rid.ap[i] &&
5296 !*(int*)&APList_rid.ap[i][2]) break;
5297 ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02x\n",
5298 (int)APList_rid.ap[i][0],
5299 (int)APList_rid.ap[i][1],
5300 (int)APList_rid.ap[i][2],
5301 (int)APList_rid.ap[i][3],
5302 (int)APList_rid.ap[i][4],
5303 (int)APList_rid.ap[i][5]);
5305 if (i==0) ptr += sprintf(ptr, "Not using specific APs\n");
5308 data->readlen = strlen( data->rbuffer );
5312 static int proc_BSSList_open( struct inode *inode, struct file *file ) {
5313 struct proc_data *data;
5314 struct proc_dir_entry *dp = PDE(inode);
5315 struct net_device *dev = dp->data;
5316 struct airo_info *ai = dev->priv;
5318 BSSListRid BSSList_rid;
5320 /* If doLoseSync is not 1, we won't do a Lose Sync */
5321 int doLoseSync = -1;
5323 if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5325 memset(file->private_data, 0, sizeof(struct proc_data));
5326 data = (struct proc_data *)file->private_data;
5327 if ((data->rbuffer = kmalloc( 1024, GFP_KERNEL )) == NULL) {
5328 kfree (file->private_data);
5332 data->maxwritelen = 0;
5333 data->wbuffer = NULL;
5334 data->on_close = NULL;
5336 if (file->f_mode & FMODE_WRITE) {
5337 if (!(file->f_mode & FMODE_READ)) {
5341 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
5342 memset(&cmd, 0, sizeof(cmd));
5343 cmd.cmd=CMD_LISTBSS;
5344 if (down_interruptible(&ai->sem))
5345 return -ERESTARTSYS;
5346 issuecommand(ai, &cmd, &rsp);
5353 ptr = data->rbuffer;
5354 /* There is a race condition here if there are concurrent opens.
5355 Since it is a rare condition, we'll just live with it, otherwise
5356 we have to add a spin lock... */
5357 rc = readBSSListRid(ai, doLoseSync, &BSSList_rid);
5358 while(rc == 0 && BSSList_rid.index != 0xffff) {
5359 ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02x %*s rssi = %d",
5360 (int)BSSList_rid.bssid[0],
5361 (int)BSSList_rid.bssid[1],
5362 (int)BSSList_rid.bssid[2],
5363 (int)BSSList_rid.bssid[3],
5364 (int)BSSList_rid.bssid[4],
5365 (int)BSSList_rid.bssid[5],
5366 (int)BSSList_rid.ssidLen,
5368 (int)BSSList_rid.dBm);
5369 ptr += sprintf(ptr, " channel = %d %s %s %s %s\n",
5370 (int)BSSList_rid.dsChannel,
5371 BSSList_rid.cap & CAP_ESS ? "ESS" : "",
5372 BSSList_rid.cap & CAP_IBSS ? "adhoc" : "",
5373 BSSList_rid.cap & CAP_PRIVACY ? "wep" : "",
5374 BSSList_rid.cap & CAP_SHORTHDR ? "shorthdr" : "");
5375 rc = readBSSListRid(ai, 0, &BSSList_rid);
5378 data->readlen = strlen( data->rbuffer );
5382 static int proc_close( struct inode *inode, struct file *file )
5384 struct proc_data *data = (struct proc_data *)file->private_data;
5385 if ( data->on_close != NULL ) data->on_close( inode, file );
5386 if ( data->rbuffer ) kfree( data->rbuffer );
5387 if ( data->wbuffer ) kfree( data->wbuffer );
5392 static struct net_device_list {
5393 struct net_device *dev;
5394 struct net_device_list *next;
5397 /* Since the card doesn't automatically switch to the right WEP mode,
5398 we will make it do it. If the card isn't associated, every secs we
5399 will switch WEP modes to see if that will help. If the card is
5400 associated we will check every minute to see if anything has
5402 static void timer_func( struct net_device *dev ) {
5403 struct airo_info *apriv = dev->priv;
5406 /* We don't have a link so try changing the authtype */
5407 readConfigRid(apriv, 0);
5408 disable_MAC(apriv, 0);
5409 switch(apriv->config.authType) {
5411 /* So drop to OPEN */
5412 apriv->config.authType = AUTH_OPEN;
5414 case AUTH_SHAREDKEY:
5415 if (apriv->keyindex < auto_wep) {
5416 set_wep_key(apriv, apriv->keyindex, NULL, 0, 0, 0);
5417 apriv->config.authType = AUTH_SHAREDKEY;
5420 /* Drop to ENCRYPT */
5421 apriv->keyindex = 0;
5422 set_wep_key(apriv, apriv->defindex, NULL, 0, 0, 0);
5423 apriv->config.authType = AUTH_ENCRYPT;
5426 default: /* We'll escalate to SHAREDKEY */
5427 apriv->config.authType = AUTH_SHAREDKEY;
5429 set_bit (FLAG_COMMIT, &apriv->flags);
5430 writeConfigRid(apriv, 0);
5431 enable_MAC(apriv, &rsp, 0);
5434 /* Schedule check to see if the change worked */
5435 clear_bit(JOB_AUTOWEP, &apriv->flags);
5436 apriv->expires = RUN_AT(HZ*3);
5439 static int add_airo_dev( struct net_device *dev ) {
5440 struct net_device_list *node = kmalloc( sizeof( *node ), GFP_KERNEL );
5445 node->next = airo_devices;
5446 airo_devices = node;
5451 static void del_airo_dev( struct net_device *dev ) {
5452 struct net_device_list **p = &airo_devices;
5453 while( *p && ( (*p)->dev != dev ) )
5455 if ( *p && (*p)->dev == dev )
5460 static int __devinit airo_pci_probe(struct pci_dev *pdev,
5461 const struct pci_device_id *pent)
5463 struct net_device *dev;
5465 if (pci_enable_device(pdev))
5467 pci_set_master(pdev);
5469 if (pdev->device == 0x5000 || pdev->device == 0xa504)
5470 dev = _init_airo_card(pdev->irq, pdev->resource[0].start, 0, pdev, &pdev->dev);
5472 dev = _init_airo_card(pdev->irq, pdev->resource[2].start, 0, pdev, &pdev->dev);
5476 pci_set_drvdata(pdev, dev);
5480 static void __devexit airo_pci_remove(struct pci_dev *pdev)
5484 static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state)
5486 struct net_device *dev = pci_get_drvdata(pdev);
5487 struct airo_info *ai = dev->priv;
5491 if ((ai->APList == NULL) &&
5492 (ai->APList = kmalloc(sizeof(APListRid), GFP_KERNEL)) == NULL)
5494 if ((ai->SSID == NULL) &&
5495 (ai->SSID = kmalloc(sizeof(SsidRid), GFP_KERNEL)) == NULL)
5497 readAPListRid(ai, ai->APList);
5498 readSsidRid(ai, ai->SSID);
5499 memset(&cmd, 0, sizeof(cmd));
5500 /* the lock will be released at the end of the resume callback */
5501 if (down_interruptible(&ai->sem))
5504 netif_device_detach(dev);
5507 issuecommand(ai, &cmd, &rsp);
5509 pci_enable_wake(pdev, pci_choose_state(pdev, state), 1);
5510 pci_save_state(pdev);
5511 return pci_set_power_state(pdev, pci_choose_state(pdev, state));
5514 static int airo_pci_resume(struct pci_dev *pdev)
5516 struct net_device *dev = pci_get_drvdata(pdev);
5517 struct airo_info *ai = dev->priv;
5520 pci_set_power_state(pdev, 0);
5521 pci_restore_state(pdev);
5522 pci_enable_wake(pdev, pci_choose_state(pdev, ai->power), 0);
5524 if (ai->power > 1) {
5526 mpi_init_descriptors(ai);
5527 setup_card(ai, dev->dev_addr, 0);
5528 clear_bit(FLAG_RADIO_OFF, &ai->flags);
5529 clear_bit(FLAG_PENDING_XMIT, &ai->flags);
5531 OUT4500(ai, EVACK, EV_AWAKEN);
5532 OUT4500(ai, EVACK, EV_AWAKEN);
5536 set_bit (FLAG_COMMIT, &ai->flags);
5540 writeSsidRid(ai, ai->SSID, 0);
5545 writeAPListRid(ai, ai->APList, 0);
5549 writeConfigRid(ai, 0);
5550 enable_MAC(ai, &rsp, 0);
5551 ai->power = PMSG_ON;
5552 netif_device_attach(dev);
5553 netif_wake_queue(dev);
5554 enable_interrupts(ai);
5560 static int __init airo_init_module( void )
5562 int i, have_isa_dev = 0;
5564 airo_entry = create_proc_entry("aironet",
5565 S_IFDIR | airo_perm,
5567 airo_entry->uid = proc_uid;
5568 airo_entry->gid = proc_gid;
5570 for( i = 0; i < 4 && io[i] && irq[i]; i++ ) {
5572 "airo: Trying to configure ISA adapter at irq=%d io=0x%x\n",
5574 if (init_airo_card( irq[i], io[i], 0, NULL ))
5579 printk( KERN_INFO "airo: Probing for PCI adapters\n" );
5580 pci_register_driver(&airo_driver);
5581 printk( KERN_INFO "airo: Finished probing for PCI adapters\n" );
5584 /* Always exit with success, as we are a library module
5585 * as well as a driver module
5590 static void __exit airo_cleanup_module( void )
5592 while( airo_devices ) {
5593 printk( KERN_INFO "airo: Unregistering %s\n", airo_devices->dev->name );
5594 stop_airo_card( airo_devices->dev, 1 );
5597 pci_unregister_driver(&airo_driver);
5599 remove_proc_entry("aironet", proc_root_driver);
5604 * Initial Wireless Extension code for Aironet driver by :
5605 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
5606 * Conversion to new driver API by :
5607 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
5608 * Javier also did a good amount of work here, adding some new extensions
5609 * and fixing my code. Let's just say that without him this code just
5610 * would not work at all... - Jean II
5613 static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi)
5618 return (0x100 - rssi_rid[rssi].rssidBm);
5621 static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm)
5628 for( i = 0; i < 256; i++ )
5629 if (rssi_rid[i].rssidBm == dbm)
5630 return rssi_rid[i].rssipct;
5636 static int airo_get_quality (StatusRid *status_rid, CapabilityRid *cap_rid)
5640 if ((status_rid->mode & 0x3f) == 0x3f && (cap_rid->hardCap & 8)) {
5641 if (memcmp(cap_rid->prodName, "350", 3))
5642 if (status_rid->signalQuality > 0x20)
5645 quality = 0x20 - status_rid->signalQuality;
5647 if (status_rid->signalQuality > 0xb0)
5649 else if (status_rid->signalQuality < 0x10)
5652 quality = 0xb0 - status_rid->signalQuality;
5657 #define airo_get_max_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x20 : 0xa0)
5658 #define airo_get_avg_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x10 : 0x50);
5660 /*------------------------------------------------------------------*/
5662 * Wireless Handler : get protocol name
5664 static int airo_get_name(struct net_device *dev,
5665 struct iw_request_info *info,
5669 strcpy(cwrq, "IEEE 802.11-DS");
5673 /*------------------------------------------------------------------*/
5675 * Wireless Handler : set frequency
5677 static int airo_set_freq(struct net_device *dev,
5678 struct iw_request_info *info,
5679 struct iw_freq *fwrq,
5682 struct airo_info *local = dev->priv;
5683 int rc = -EINPROGRESS; /* Call commit handler */
5685 /* If setting by frequency, convert to a channel */
5686 if((fwrq->e == 1) &&
5687 (fwrq->m >= (int) 2.412e8) &&
5688 (fwrq->m <= (int) 2.487e8)) {
5689 int f = fwrq->m / 100000;
5691 while((c < 14) && (f != frequency_list[c]))
5693 /* Hack to fall through... */
5697 /* Setting by channel number */
5698 if((fwrq->m > 1000) || (fwrq->e > 0))
5701 int channel = fwrq->m;
5702 /* We should do a better check than that,
5703 * based on the card capability !!! */
5704 if((channel < 1) || (channel > 16)) {
5705 printk(KERN_DEBUG "%s: New channel value of %d is invalid!\n", dev->name, fwrq->m);
5708 readConfigRid(local, 1);
5709 /* Yes ! We can set it !!! */
5710 local->config.channelSet = (u16)(channel - 1);
5711 set_bit (FLAG_COMMIT, &local->flags);
5717 /*------------------------------------------------------------------*/
5719 * Wireless Handler : get frequency
5721 static int airo_get_freq(struct net_device *dev,
5722 struct iw_request_info *info,
5723 struct iw_freq *fwrq,
5726 struct airo_info *local = dev->priv;
5727 StatusRid status_rid; /* Card status info */
5729 readConfigRid(local, 1);
5730 if ((local->config.opmode & 0xFF) == MODE_STA_ESS)
5731 status_rid.channel = local->config.channelSet;
5733 readStatusRid(local, &status_rid, 1);
5735 #ifdef WEXT_USECHANNELS
5736 fwrq->m = ((int)status_rid.channel) + 1;
5740 int f = (int)status_rid.channel;
5741 fwrq->m = frequency_list[f] * 100000;
5749 /*------------------------------------------------------------------*/
5751 * Wireless Handler : set ESSID
5753 static int airo_set_essid(struct net_device *dev,
5754 struct iw_request_info *info,
5755 struct iw_point *dwrq,
5758 struct airo_info *local = dev->priv;
5760 SsidRid SSID_rid; /* SSIDs */
5762 /* Reload the list of current SSID */
5763 readSsidRid(local, &SSID_rid);
5765 /* Check if we asked for `any' */
5766 if(dwrq->flags == 0) {
5767 /* Just send an empty SSID list */
5768 memset(&SSID_rid, 0, sizeof(SSID_rid));
5770 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
5772 /* Check the size of the string */
5773 if(dwrq->length > IW_ESSID_MAX_SIZE+1) {
5776 /* Check if index is valid */
5777 if((index < 0) || (index >= 4)) {
5782 memset(SSID_rid.ssids[index].ssid, 0,
5783 sizeof(SSID_rid.ssids[index].ssid));
5784 memcpy(SSID_rid.ssids[index].ssid, extra, dwrq->length);
5785 SSID_rid.ssids[index].len = dwrq->length - 1;
5787 SSID_rid.len = sizeof(SSID_rid);
5788 /* Write it to the card */
5789 disable_MAC(local, 1);
5790 writeSsidRid(local, &SSID_rid, 1);
5791 enable_MAC(local, &rsp, 1);
5796 /*------------------------------------------------------------------*/
5798 * Wireless Handler : get ESSID
5800 static int airo_get_essid(struct net_device *dev,
5801 struct iw_request_info *info,
5802 struct iw_point *dwrq,
5805 struct airo_info *local = dev->priv;
5806 StatusRid status_rid; /* Card status info */
5808 readStatusRid(local, &status_rid, 1);
5810 /* Note : if dwrq->flags != 0, we should
5811 * get the relevant SSID from the SSID list... */
5813 /* Get the current SSID */
5814 memcpy(extra, status_rid.SSID, status_rid.SSIDlen);
5815 extra[status_rid.SSIDlen] = '\0';
5816 /* If none, we may want to get the one that was set */
5819 dwrq->length = status_rid.SSIDlen + 1;
5820 dwrq->flags = 1; /* active */
5825 /*------------------------------------------------------------------*/
5827 * Wireless Handler : set AP address
5829 static int airo_set_wap(struct net_device *dev,
5830 struct iw_request_info *info,
5831 struct sockaddr *awrq,
5834 struct airo_info *local = dev->priv;
5837 APListRid APList_rid;
5838 static const unsigned char bcast[ETH_ALEN] = { 255, 255, 255, 255, 255, 255 };
5840 if (awrq->sa_family != ARPHRD_ETHER)
5842 else if (!memcmp(bcast, awrq->sa_data, ETH_ALEN)) {
5843 memset(&cmd, 0, sizeof(cmd));
5844 cmd.cmd=CMD_LOSE_SYNC;
5845 if (down_interruptible(&local->sem))
5846 return -ERESTARTSYS;
5847 issuecommand(local, &cmd, &rsp);
5850 memset(&APList_rid, 0, sizeof(APList_rid));
5851 APList_rid.len = sizeof(APList_rid);
5852 memcpy(APList_rid.ap[0], awrq->sa_data, ETH_ALEN);
5853 disable_MAC(local, 1);
5854 writeAPListRid(local, &APList_rid, 1);
5855 enable_MAC(local, &rsp, 1);
5860 /*------------------------------------------------------------------*/
5862 * Wireless Handler : get AP address
5864 static int airo_get_wap(struct net_device *dev,
5865 struct iw_request_info *info,
5866 struct sockaddr *awrq,
5869 struct airo_info *local = dev->priv;
5870 StatusRid status_rid; /* Card status info */
5872 readStatusRid(local, &status_rid, 1);
5874 /* Tentative. This seems to work, wow, I'm lucky !!! */
5875 memcpy(awrq->sa_data, status_rid.bssid[0], ETH_ALEN);
5876 awrq->sa_family = ARPHRD_ETHER;
5881 /*------------------------------------------------------------------*/
5883 * Wireless Handler : set Nickname
5885 static int airo_set_nick(struct net_device *dev,
5886 struct iw_request_info *info,
5887 struct iw_point *dwrq,
5890 struct airo_info *local = dev->priv;
5892 /* Check the size of the string */
5893 if(dwrq->length > 16 + 1) {
5896 readConfigRid(local, 1);
5897 memset(local->config.nodeName, 0, sizeof(local->config.nodeName));
5898 memcpy(local->config.nodeName, extra, dwrq->length);
5899 set_bit (FLAG_COMMIT, &local->flags);
5901 return -EINPROGRESS; /* Call commit handler */
5904 /*------------------------------------------------------------------*/
5906 * Wireless Handler : get Nickname
5908 static int airo_get_nick(struct net_device *dev,
5909 struct iw_request_info *info,
5910 struct iw_point *dwrq,
5913 struct airo_info *local = dev->priv;
5915 readConfigRid(local, 1);
5916 strncpy(extra, local->config.nodeName, 16);
5918 dwrq->length = strlen(extra) + 1;
5923 /*------------------------------------------------------------------*/
5925 * Wireless Handler : set Bit-Rate
5927 static int airo_set_rate(struct net_device *dev,
5928 struct iw_request_info *info,
5929 struct iw_param *vwrq,
5932 struct airo_info *local = dev->priv;
5933 CapabilityRid cap_rid; /* Card capability info */
5937 /* First : get a valid bit rate value */
5938 readCapabilityRid(local, &cap_rid, 1);
5940 /* Which type of value ? */
5941 if((vwrq->value < 8) && (vwrq->value >= 0)) {
5942 /* Setting by rate index */
5943 /* Find value in the magic rate table */
5944 brate = cap_rid.supportedRates[vwrq->value];
5946 /* Setting by frequency value */
5947 u8 normvalue = (u8) (vwrq->value/500000);
5949 /* Check if rate is valid */
5950 for(i = 0 ; i < 8 ; i++) {
5951 if(normvalue == cap_rid.supportedRates[i]) {
5957 /* -1 designed the max rate (mostly auto mode) */
5958 if(vwrq->value == -1) {
5959 /* Get the highest available rate */
5960 for(i = 0 ; i < 8 ; i++) {
5961 if(cap_rid.supportedRates[i] == 0)
5965 brate = cap_rid.supportedRates[i - 1];
5967 /* Check that it is valid */
5972 readConfigRid(local, 1);
5973 /* Now, check if we want a fixed or auto value */
5974 if(vwrq->fixed == 0) {
5975 /* Fill all the rates up to this max rate */
5976 memset(local->config.rates, 0, 8);
5977 for(i = 0 ; i < 8 ; i++) {
5978 local->config.rates[i] = cap_rid.supportedRates[i];
5979 if(local->config.rates[i] == brate)
5984 /* One rate, fixed */
5985 memset(local->config.rates, 0, 8);
5986 local->config.rates[0] = brate;
5988 set_bit (FLAG_COMMIT, &local->flags);
5990 return -EINPROGRESS; /* Call commit handler */
5993 /*------------------------------------------------------------------*/
5995 * Wireless Handler : get Bit-Rate
5997 static int airo_get_rate(struct net_device *dev,
5998 struct iw_request_info *info,
5999 struct iw_param *vwrq,
6002 struct airo_info *local = dev->priv;
6003 StatusRid status_rid; /* Card status info */
6005 readStatusRid(local, &status_rid, 1);
6007 vwrq->value = status_rid.currentXmitRate * 500000;
6008 /* If more than one rate, set auto */
6009 readConfigRid(local, 1);
6010 vwrq->fixed = (local->config.rates[1] == 0);
6015 /*------------------------------------------------------------------*/
6017 * Wireless Handler : set RTS threshold
6019 static int airo_set_rts(struct net_device *dev,
6020 struct iw_request_info *info,
6021 struct iw_param *vwrq,
6024 struct airo_info *local = dev->priv;
6025 int rthr = vwrq->value;
6029 if((rthr < 0) || (rthr > 2312)) {
6032 readConfigRid(local, 1);
6033 local->config.rtsThres = rthr;
6034 set_bit (FLAG_COMMIT, &local->flags);
6036 return -EINPROGRESS; /* Call commit handler */
6039 /*------------------------------------------------------------------*/
6041 * Wireless Handler : get RTS threshold
6043 static int airo_get_rts(struct net_device *dev,
6044 struct iw_request_info *info,
6045 struct iw_param *vwrq,
6048 struct airo_info *local = dev->priv;
6050 readConfigRid(local, 1);
6051 vwrq->value = local->config.rtsThres;
6052 vwrq->disabled = (vwrq->value >= 2312);
6058 /*------------------------------------------------------------------*/
6060 * Wireless Handler : set Fragmentation threshold
6062 static int airo_set_frag(struct net_device *dev,
6063 struct iw_request_info *info,
6064 struct iw_param *vwrq,
6067 struct airo_info *local = dev->priv;
6068 int fthr = vwrq->value;
6072 if((fthr < 256) || (fthr > 2312)) {
6075 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
6076 readConfigRid(local, 1);
6077 local->config.fragThresh = (u16)fthr;
6078 set_bit (FLAG_COMMIT, &local->flags);
6080 return -EINPROGRESS; /* Call commit handler */
6083 /*------------------------------------------------------------------*/
6085 * Wireless Handler : get Fragmentation threshold
6087 static int airo_get_frag(struct net_device *dev,
6088 struct iw_request_info *info,
6089 struct iw_param *vwrq,
6092 struct airo_info *local = dev->priv;
6094 readConfigRid(local, 1);
6095 vwrq->value = local->config.fragThresh;
6096 vwrq->disabled = (vwrq->value >= 2312);
6102 /*------------------------------------------------------------------*/
6104 * Wireless Handler : set Mode of Operation
6106 static int airo_set_mode(struct net_device *dev,
6107 struct iw_request_info *info,
6111 struct airo_info *local = dev->priv;
6114 readConfigRid(local, 1);
6115 if ((local->config.rmode & 0xff) >= RXMODE_RFMON)
6120 local->config.opmode &= 0xFF00;
6121 local->config.opmode |= MODE_STA_IBSS;
6122 local->config.rmode &= 0xfe00;
6123 local->config.scanMode = SCANMODE_ACTIVE;
6124 clear_bit (FLAG_802_11, &local->flags);
6127 local->config.opmode &= 0xFF00;
6128 local->config.opmode |= MODE_STA_ESS;
6129 local->config.rmode &= 0xfe00;
6130 local->config.scanMode = SCANMODE_ACTIVE;
6131 clear_bit (FLAG_802_11, &local->flags);
6133 case IW_MODE_MASTER:
6134 local->config.opmode &= 0xFF00;
6135 local->config.opmode |= MODE_AP;
6136 local->config.rmode &= 0xfe00;
6137 local->config.scanMode = SCANMODE_ACTIVE;
6138 clear_bit (FLAG_802_11, &local->flags);
6140 case IW_MODE_REPEAT:
6141 local->config.opmode &= 0xFF00;
6142 local->config.opmode |= MODE_AP_RPTR;
6143 local->config.rmode &= 0xfe00;
6144 local->config.scanMode = SCANMODE_ACTIVE;
6145 clear_bit (FLAG_802_11, &local->flags);
6147 case IW_MODE_MONITOR:
6148 local->config.opmode &= 0xFF00;
6149 local->config.opmode |= MODE_STA_ESS;
6150 local->config.rmode &= 0xfe00;
6151 local->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
6152 local->config.scanMode = SCANMODE_PASSIVE;
6153 set_bit (FLAG_802_11, &local->flags);
6159 set_bit (FLAG_RESET, &local->flags);
6160 set_bit (FLAG_COMMIT, &local->flags);
6162 return -EINPROGRESS; /* Call commit handler */
6165 /*------------------------------------------------------------------*/
6167 * Wireless Handler : get Mode of Operation
6169 static int airo_get_mode(struct net_device *dev,
6170 struct iw_request_info *info,
6174 struct airo_info *local = dev->priv;
6176 readConfigRid(local, 1);
6177 /* If not managed, assume it's ad-hoc */
6178 switch (local->config.opmode & 0xFF) {
6180 *uwrq = IW_MODE_INFRA;
6183 *uwrq = IW_MODE_MASTER;
6186 *uwrq = IW_MODE_REPEAT;
6189 *uwrq = IW_MODE_ADHOC;
6195 /*------------------------------------------------------------------*/
6197 * Wireless Handler : set Encryption Key
6199 static int airo_set_encode(struct net_device *dev,
6200 struct iw_request_info *info,
6201 struct iw_point *dwrq,
6204 struct airo_info *local = dev->priv;
6205 CapabilityRid cap_rid; /* Card capability info */
6207 /* Is WEP supported ? */
6208 readCapabilityRid(local, &cap_rid, 1);
6209 /* Older firmware doesn't support this...
6210 if(!(cap_rid.softCap & 2)) {
6213 readConfigRid(local, 1);
6215 /* Basic checking: do we have a key to set ?
6216 * Note : with the new API, it's impossible to get a NULL pointer.
6217 * Therefore, we need to check a key size == 0 instead.
6218 * New version of iwconfig properly set the IW_ENCODE_NOKEY flag
6219 * when no key is present (only change flags), but older versions
6220 * don't do it. - Jean II */
6221 if (dwrq->length > 0) {
6223 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6224 int current_index = get_wep_key(local, 0xffff);
6225 /* Check the size of the key */
6226 if (dwrq->length > MAX_KEY_SIZE) {
6229 /* Check the index (none -> use current) */
6230 if ((index < 0) || (index >= ((cap_rid.softCap & 0x80) ? 4:1)))
6231 index = current_index;
6232 /* Set the length */
6233 if (dwrq->length > MIN_KEY_SIZE)
6234 key.len = MAX_KEY_SIZE;
6236 if (dwrq->length > 0)
6237 key.len = MIN_KEY_SIZE;
6239 /* Disable the key */
6241 /* Check if the key is not marked as invalid */
6242 if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
6244 memset(key.key, 0, MAX_KEY_SIZE);
6245 /* Copy the key in the driver */
6246 memcpy(key.key, extra, dwrq->length);
6247 /* Send the key to the card */
6248 set_wep_key(local, index, key.key, key.len, 1, 1);
6250 /* WE specify that if a valid key is set, encryption
6251 * should be enabled (user may turn it off later)
6252 * This is also how "iwconfig ethX key on" works */
6253 if((index == current_index) && (key.len > 0) &&
6254 (local->config.authType == AUTH_OPEN)) {
6255 local->config.authType = AUTH_ENCRYPT;
6256 set_bit (FLAG_COMMIT, &local->flags);
6259 /* Do we want to just set the transmit key index ? */
6260 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6261 if ((index >= 0) && (index < ((cap_rid.softCap & 0x80)?4:1))) {
6262 set_wep_key(local, index, NULL, 0, 1, 1);
6264 /* Don't complain if only change the mode */
6265 if(!dwrq->flags & IW_ENCODE_MODE) {
6269 /* Read the flags */
6270 if(dwrq->flags & IW_ENCODE_DISABLED)
6271 local->config.authType = AUTH_OPEN; // disable encryption
6272 if(dwrq->flags & IW_ENCODE_RESTRICTED)
6273 local->config.authType = AUTH_SHAREDKEY; // Only Both
6274 if(dwrq->flags & IW_ENCODE_OPEN)
6275 local->config.authType = AUTH_ENCRYPT; // Only Wep
6276 /* Commit the changes to flags if needed */
6277 if(dwrq->flags & IW_ENCODE_MODE)
6278 set_bit (FLAG_COMMIT, &local->flags);
6279 return -EINPROGRESS; /* Call commit handler */
6282 /*------------------------------------------------------------------*/
6284 * Wireless Handler : get Encryption Key
6286 static int airo_get_encode(struct net_device *dev,
6287 struct iw_request_info *info,
6288 struct iw_point *dwrq,
6291 struct airo_info *local = dev->priv;
6292 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6293 CapabilityRid cap_rid; /* Card capability info */
6295 /* Is it supported ? */
6296 readCapabilityRid(local, &cap_rid, 1);
6297 if(!(cap_rid.softCap & 2)) {
6300 readConfigRid(local, 1);
6301 /* Check encryption mode */
6302 switch(local->config.authType) {
6304 dwrq->flags = IW_ENCODE_OPEN;
6306 case AUTH_SHAREDKEY:
6307 dwrq->flags = IW_ENCODE_RESTRICTED;
6311 dwrq->flags = IW_ENCODE_DISABLED;
6314 /* We can't return the key, so set the proper flag and return zero */
6315 dwrq->flags |= IW_ENCODE_NOKEY;
6316 memset(extra, 0, 16);
6318 /* Which key do we want ? -1 -> tx index */
6319 if ((index < 0) || (index >= ((cap_rid.softCap & 0x80) ? 4 : 1)))
6320 index = get_wep_key(local, 0xffff);
6321 dwrq->flags |= index + 1;
6322 /* Copy the key to the user buffer */
6323 dwrq->length = get_wep_key(local, index);
6324 if (dwrq->length > 16) {
6330 /*------------------------------------------------------------------*/
6332 * Wireless Handler : set Tx-Power
6334 static int airo_set_txpow(struct net_device *dev,
6335 struct iw_request_info *info,
6336 struct iw_param *vwrq,
6339 struct airo_info *local = dev->priv;
6340 CapabilityRid cap_rid; /* Card capability info */
6344 readCapabilityRid(local, &cap_rid, 1);
6346 if (vwrq->disabled) {
6347 set_bit (FLAG_RADIO_OFF, &local->flags);
6348 set_bit (FLAG_COMMIT, &local->flags);
6349 return -EINPROGRESS; /* Call commit handler */
6351 if (vwrq->flags != IW_TXPOW_MWATT) {
6354 clear_bit (FLAG_RADIO_OFF, &local->flags);
6355 for (i = 0; cap_rid.txPowerLevels[i] && (i < 8); i++)
6356 if ((vwrq->value==cap_rid.txPowerLevels[i])) {
6357 readConfigRid(local, 1);
6358 local->config.txPower = vwrq->value;
6359 set_bit (FLAG_COMMIT, &local->flags);
6360 rc = -EINPROGRESS; /* Call commit handler */
6366 /*------------------------------------------------------------------*/
6368 * Wireless Handler : get Tx-Power
6370 static int airo_get_txpow(struct net_device *dev,
6371 struct iw_request_info *info,
6372 struct iw_param *vwrq,
6375 struct airo_info *local = dev->priv;
6377 readConfigRid(local, 1);
6378 vwrq->value = local->config.txPower;
6379 vwrq->fixed = 1; /* No power control */
6380 vwrq->disabled = test_bit(FLAG_RADIO_OFF, &local->flags);
6381 vwrq->flags = IW_TXPOW_MWATT;
6386 /*------------------------------------------------------------------*/
6388 * Wireless Handler : set Retry limits
6390 static int airo_set_retry(struct net_device *dev,
6391 struct iw_request_info *info,
6392 struct iw_param *vwrq,
6395 struct airo_info *local = dev->priv;
6398 if(vwrq->disabled) {
6401 readConfigRid(local, 1);
6402 if(vwrq->flags & IW_RETRY_LIMIT) {
6403 if(vwrq->flags & IW_RETRY_MAX)
6404 local->config.longRetryLimit = vwrq->value;
6405 else if (vwrq->flags & IW_RETRY_MIN)
6406 local->config.shortRetryLimit = vwrq->value;
6408 /* No modifier : set both */
6409 local->config.longRetryLimit = vwrq->value;
6410 local->config.shortRetryLimit = vwrq->value;
6412 set_bit (FLAG_COMMIT, &local->flags);
6413 rc = -EINPROGRESS; /* Call commit handler */
6415 if(vwrq->flags & IW_RETRY_LIFETIME) {
6416 local->config.txLifetime = vwrq->value / 1024;
6417 set_bit (FLAG_COMMIT, &local->flags);
6418 rc = -EINPROGRESS; /* Call commit handler */
6423 /*------------------------------------------------------------------*/
6425 * Wireless Handler : get Retry limits
6427 static int airo_get_retry(struct net_device *dev,
6428 struct iw_request_info *info,
6429 struct iw_param *vwrq,
6432 struct airo_info *local = dev->priv;
6434 vwrq->disabled = 0; /* Can't be disabled */
6436 readConfigRid(local, 1);
6437 /* Note : by default, display the min retry number */
6438 if((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
6439 vwrq->flags = IW_RETRY_LIFETIME;
6440 vwrq->value = (int)local->config.txLifetime * 1024;
6441 } else if((vwrq->flags & IW_RETRY_MAX)) {
6442 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
6443 vwrq->value = (int)local->config.longRetryLimit;
6445 vwrq->flags = IW_RETRY_LIMIT;
6446 vwrq->value = (int)local->config.shortRetryLimit;
6447 if((int)local->config.shortRetryLimit != (int)local->config.longRetryLimit)
6448 vwrq->flags |= IW_RETRY_MIN;
6454 /*------------------------------------------------------------------*/
6456 * Wireless Handler : get range info
6458 static int airo_get_range(struct net_device *dev,
6459 struct iw_request_info *info,
6460 struct iw_point *dwrq,
6463 struct airo_info *local = dev->priv;
6464 struct iw_range *range = (struct iw_range *) extra;
6465 CapabilityRid cap_rid; /* Card capability info */
6469 readCapabilityRid(local, &cap_rid, 1);
6471 dwrq->length = sizeof(struct iw_range);
6472 memset(range, 0, sizeof(*range));
6473 range->min_nwid = 0x0000;
6474 range->max_nwid = 0x0000;
6475 range->num_channels = 14;
6476 /* Should be based on cap_rid.country to give only
6477 * what the current card support */
6479 for(i = 0; i < 14; i++) {
6480 range->freq[k].i = i + 1; /* List index */
6481 range->freq[k].m = frequency_list[i] * 100000;
6482 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
6484 range->num_frequency = k;
6486 range->sensitivity = 65535;
6488 /* Hum... Should put the right values there */
6490 range->max_qual.qual = 100; /* % */
6492 range->max_qual.qual = airo_get_max_quality(&cap_rid);
6493 range->max_qual.level = 0; /* 0 means we use dBm */
6494 range->max_qual.noise = 0;
6495 range->max_qual.updated = 0;
6497 /* Experimental measurements - boundary 11/5.5 Mb/s */
6498 /* Note : with or without the (local->rssi), results
6499 * are somewhat different. - Jean II */
6501 range->avg_qual.qual = 50; /* % */
6502 range->avg_qual.level = 186; /* -70 dBm */
6504 range->avg_qual.qual = airo_get_avg_quality(&cap_rid);
6505 range->avg_qual.level = 176; /* -80 dBm */
6507 range->avg_qual.noise = 0;
6508 range->avg_qual.updated = 0;
6510 for(i = 0 ; i < 8 ; i++) {
6511 range->bitrate[i] = cap_rid.supportedRates[i] * 500000;
6512 if(range->bitrate[i] == 0)
6515 range->num_bitrates = i;
6517 /* Set an indication of the max TCP throughput
6518 * in bit/s that we can expect using this interface.
6519 * May be use for QoS stuff... Jean II */
6521 range->throughput = 5000 * 1000;
6523 range->throughput = 1500 * 1000;
6526 range->max_rts = 2312;
6527 range->min_frag = 256;
6528 range->max_frag = 2312;
6530 if(cap_rid.softCap & 2) {
6532 range->encoding_size[0] = 5;
6534 if (cap_rid.softCap & 0x100) {
6535 range->encoding_size[1] = 13;
6536 range->num_encoding_sizes = 2;
6538 range->num_encoding_sizes = 1;
6539 range->max_encoding_tokens = (cap_rid.softCap & 0x80) ? 4 : 1;
6541 range->num_encoding_sizes = 0;
6542 range->max_encoding_tokens = 0;
6545 range->max_pmp = 5000000; /* 5 secs */
6547 range->max_pmt = 65535 * 1024; /* ??? */
6548 range->pmp_flags = IW_POWER_PERIOD;
6549 range->pmt_flags = IW_POWER_TIMEOUT;
6550 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
6552 /* Transmit Power - values are in mW */
6553 for(i = 0 ; i < 8 ; i++) {
6554 range->txpower[i] = cap_rid.txPowerLevels[i];
6555 if(range->txpower[i] == 0)
6558 range->num_txpower = i;
6559 range->txpower_capa = IW_TXPOW_MWATT;
6560 range->we_version_source = 12;
6561 range->we_version_compiled = WIRELESS_EXT;
6562 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
6563 range->retry_flags = IW_RETRY_LIMIT;
6564 range->r_time_flags = IW_RETRY_LIFETIME;
6565 range->min_retry = 1;
6566 range->max_retry = 65535;
6567 range->min_r_time = 1024;
6568 range->max_r_time = 65535 * 1024;
6570 /* Event capability (kernel + driver) */
6571 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
6572 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
6573 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
6574 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
6575 range->event_capa[1] = IW_EVENT_CAPA_K_1;
6576 range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVTXDROP);
6580 /*------------------------------------------------------------------*/
6582 * Wireless Handler : set Power Management
6584 static int airo_set_power(struct net_device *dev,
6585 struct iw_request_info *info,
6586 struct iw_param *vwrq,
6589 struct airo_info *local = dev->priv;
6591 readConfigRid(local, 1);
6592 if (vwrq->disabled) {
6593 if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
6596 local->config.powerSaveMode = POWERSAVE_CAM;
6597 local->config.rmode &= 0xFF00;
6598 local->config.rmode |= RXMODE_BC_MC_ADDR;
6599 set_bit (FLAG_COMMIT, &local->flags);
6600 return -EINPROGRESS; /* Call commit handler */
6602 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
6603 local->config.fastListenDelay = (vwrq->value + 500) / 1024;
6604 local->config.powerSaveMode = POWERSAVE_PSPCAM;
6605 set_bit (FLAG_COMMIT, &local->flags);
6606 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
6607 local->config.fastListenInterval = local->config.listenInterval = (vwrq->value + 500) / 1024;
6608 local->config.powerSaveMode = POWERSAVE_PSPCAM;
6609 set_bit (FLAG_COMMIT, &local->flags);
6611 switch (vwrq->flags & IW_POWER_MODE) {
6612 case IW_POWER_UNICAST_R:
6613 if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
6616 local->config.rmode &= 0xFF00;
6617 local->config.rmode |= RXMODE_ADDR;
6618 set_bit (FLAG_COMMIT, &local->flags);
6620 case IW_POWER_ALL_R:
6621 if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
6624 local->config.rmode &= 0xFF00;
6625 local->config.rmode |= RXMODE_BC_MC_ADDR;
6626 set_bit (FLAG_COMMIT, &local->flags);
6632 // Note : we may want to factor local->need_commit here
6633 // Note2 : may also want to factor RXMODE_RFMON test
6634 return -EINPROGRESS; /* Call commit handler */
6637 /*------------------------------------------------------------------*/
6639 * Wireless Handler : get Power Management
6641 static int airo_get_power(struct net_device *dev,
6642 struct iw_request_info *info,
6643 struct iw_param *vwrq,
6646 struct airo_info *local = dev->priv;
6649 readConfigRid(local, 1);
6650 mode = local->config.powerSaveMode;
6651 if ((vwrq->disabled = (mode == POWERSAVE_CAM)))
6653 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
6654 vwrq->value = (int)local->config.fastListenDelay * 1024;
6655 vwrq->flags = IW_POWER_TIMEOUT;
6657 vwrq->value = (int)local->config.fastListenInterval * 1024;
6658 vwrq->flags = IW_POWER_PERIOD;
6660 if ((local->config.rmode & 0xFF) == RXMODE_ADDR)
6661 vwrq->flags |= IW_POWER_UNICAST_R;
6663 vwrq->flags |= IW_POWER_ALL_R;
6668 /*------------------------------------------------------------------*/
6670 * Wireless Handler : set Sensitivity
6672 static int airo_set_sens(struct net_device *dev,
6673 struct iw_request_info *info,
6674 struct iw_param *vwrq,
6677 struct airo_info *local = dev->priv;
6679 readConfigRid(local, 1);
6680 local->config.rssiThreshold = vwrq->disabled ? RSSI_DEFAULT : vwrq->value;
6681 set_bit (FLAG_COMMIT, &local->flags);
6683 return -EINPROGRESS; /* Call commit handler */
6686 /*------------------------------------------------------------------*/
6688 * Wireless Handler : get Sensitivity
6690 static int airo_get_sens(struct net_device *dev,
6691 struct iw_request_info *info,
6692 struct iw_param *vwrq,
6695 struct airo_info *local = dev->priv;
6697 readConfigRid(local, 1);
6698 vwrq->value = local->config.rssiThreshold;
6699 vwrq->disabled = (vwrq->value == 0);
6705 /*------------------------------------------------------------------*/
6707 * Wireless Handler : get AP List
6708 * Note : this is deprecated in favor of IWSCAN
6710 static int airo_get_aplist(struct net_device *dev,
6711 struct iw_request_info *info,
6712 struct iw_point *dwrq,
6715 struct airo_info *local = dev->priv;
6716 struct sockaddr *address = (struct sockaddr *) extra;
6717 struct iw_quality qual[IW_MAX_AP];
6720 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
6722 for (i = 0; i < IW_MAX_AP; i++) {
6723 if (readBSSListRid(local, loseSync, &BSSList))
6726 memcpy(address[i].sa_data, BSSList.bssid, ETH_ALEN);
6727 address[i].sa_family = ARPHRD_ETHER;
6729 qual[i].level = 0x100 - BSSList.dBm;
6730 qual[i].qual = airo_dbm_to_pct( local->rssi, BSSList.dBm );
6731 qual[i].updated = IW_QUAL_QUAL_UPDATED;
6733 qual[i].level = (BSSList.dBm + 321) / 2;
6735 qual[i].updated = IW_QUAL_QUAL_INVALID;
6737 qual[i].noise = local->wstats.qual.noise;
6738 qual[i].updated = IW_QUAL_LEVEL_UPDATED
6739 | IW_QUAL_NOISE_UPDATED;
6740 if (BSSList.index == 0xffff)
6744 StatusRid status_rid; /* Card status info */
6745 readStatusRid(local, &status_rid, 1);
6747 i < min(IW_MAX_AP, 4) &&
6748 (status_rid.bssid[i][0]
6749 & status_rid.bssid[i][1]
6750 & status_rid.bssid[i][2]
6751 & status_rid.bssid[i][3]
6752 & status_rid.bssid[i][4]
6753 & status_rid.bssid[i][5])!=0xff &&
6754 (status_rid.bssid[i][0]
6755 | status_rid.bssid[i][1]
6756 | status_rid.bssid[i][2]
6757 | status_rid.bssid[i][3]
6758 | status_rid.bssid[i][4]
6759 | status_rid.bssid[i][5]);
6761 memcpy(address[i].sa_data,
6762 status_rid.bssid[i], ETH_ALEN);
6763 address[i].sa_family = ARPHRD_ETHER;
6766 dwrq->flags = 1; /* Should be define'd */
6767 memcpy(extra + sizeof(struct sockaddr)*i,
6768 &qual, sizeof(struct iw_quality)*i);
6775 /*------------------------------------------------------------------*/
6777 * Wireless Handler : Initiate Scan
6779 static int airo_set_scan(struct net_device *dev,
6780 struct iw_request_info *info,
6781 struct iw_param *vwrq,
6784 struct airo_info *ai = dev->priv;
6788 /* Note : you may have realised that, as this is a SET operation,
6789 * this is privileged and therefore a normal user can't
6791 * This is not an error, while the device perform scanning,
6792 * traffic doesn't flow, so it's a perfect DoS...
6794 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
6796 /* Initiate a scan command */
6797 memset(&cmd, 0, sizeof(cmd));
6798 cmd.cmd=CMD_LISTBSS;
6799 if (down_interruptible(&ai->sem))
6800 return -ERESTARTSYS;
6801 issuecommand(ai, &cmd, &rsp);
6802 ai->scan_timestamp = jiffies;
6805 /* At this point, just return to the user. */
6810 /*------------------------------------------------------------------*/
6812 * Translate scan data returned from the card to a card independent
6813 * format that the Wireless Tools will understand - Jean II
6815 static inline char *airo_translate_scan(struct net_device *dev,
6820 struct airo_info *ai = dev->priv;
6821 struct iw_event iwe; /* Temporary buffer */
6823 char * current_val; /* For rates */
6826 /* First entry *MUST* be the AP MAC address */
6827 iwe.cmd = SIOCGIWAP;
6828 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
6829 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
6830 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
6832 /* Other entries will be displayed in the order we give them */
6835 iwe.u.data.length = bss->ssidLen;
6836 if(iwe.u.data.length > 32)
6837 iwe.u.data.length = 32;
6838 iwe.cmd = SIOCGIWESSID;
6839 iwe.u.data.flags = 1;
6840 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, bss->ssid);
6843 iwe.cmd = SIOCGIWMODE;
6844 capabilities = le16_to_cpu(bss->cap);
6845 if(capabilities & (CAP_ESS | CAP_IBSS)) {
6846 if(capabilities & CAP_ESS)
6847 iwe.u.mode = IW_MODE_MASTER;
6849 iwe.u.mode = IW_MODE_ADHOC;
6850 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
6854 iwe.cmd = SIOCGIWFREQ;
6855 iwe.u.freq.m = le16_to_cpu(bss->dsChannel);
6856 iwe.u.freq.m = frequency_list[iwe.u.freq.m] * 100000;
6858 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
6860 /* Add quality statistics */
6863 iwe.u.qual.level = 0x100 - bss->dBm;
6864 iwe.u.qual.qual = airo_dbm_to_pct( ai->rssi, bss->dBm );
6865 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED;
6867 iwe.u.qual.level = (bss->dBm + 321) / 2;
6868 iwe.u.qual.qual = 0;
6869 iwe.u.qual.updated = IW_QUAL_QUAL_INVALID;
6871 iwe.u.qual.noise = ai->wstats.qual.noise;
6872 iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED
6873 | IW_QUAL_NOISE_UPDATED;
6874 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
6876 /* Add encryption capability */
6877 iwe.cmd = SIOCGIWENCODE;
6878 if(capabilities & CAP_PRIVACY)
6879 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
6881 iwe.u.data.flags = IW_ENCODE_DISABLED;
6882 iwe.u.data.length = 0;
6883 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, bss->ssid);
6885 /* Rate : stuffing multiple values in a single event require a bit
6886 * more of magic - Jean II */
6887 current_val = current_ev + IW_EV_LCP_LEN;
6889 iwe.cmd = SIOCGIWRATE;
6890 /* Those two flags are ignored... */
6891 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
6893 for(i = 0 ; i < 8 ; i++) {
6894 /* NULL terminated */
6895 if(bss->rates[i] == 0)
6897 /* Bit rate given in 500 kb/s units (+ 0x80) */
6898 iwe.u.bitrate.value = ((bss->rates[i] & 0x7f) * 500000);
6899 /* Add new value to event */
6900 current_val = iwe_stream_add_value(current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
6902 /* Check if we added any event */
6903 if((current_val - current_ev) > IW_EV_LCP_LEN)
6904 current_ev = current_val;
6906 /* The other data in the scan result are not really
6907 * interesting, so for now drop it - Jean II */
6911 /*------------------------------------------------------------------*/
6913 * Wireless Handler : Read Scan Results
6915 static int airo_get_scan(struct net_device *dev,
6916 struct iw_request_info *info,
6917 struct iw_point *dwrq,
6920 struct airo_info *ai = dev->priv;
6923 char *current_ev = extra;
6925 /* When we are associated again, the scan has surely finished.
6926 * Just in case, let's make sure enough time has elapsed since
6927 * we started the scan. - Javier */
6928 if(ai->scan_timestamp && time_before(jiffies,ai->scan_timestamp+3*HZ)) {
6929 /* Important note : we don't want to block the caller
6930 * until results are ready for various reasons.
6931 * First, managing wait queues is complex and racy
6932 * (there may be multiple simultaneous callers).
6933 * Second, we grab some rtnetlink lock before comming
6934 * here (in dev_ioctl()).
6935 * Third, the caller can wait on the Wireless Event
6939 ai->scan_timestamp = 0;
6941 /* There's only a race with proc_BSSList_open(), but its
6942 * consequences are begnign. So I don't bother fixing it - Javier */
6944 /* Try to read the first entry of the scan result */
6945 rc = PC4500_readrid(ai, RID_BSSLISTFIRST, &BSSList, sizeof(BSSList), 1);
6946 if((rc) || (BSSList.index == 0xffff)) {
6947 /* Client error, no scan results...
6948 * The caller need to restart the scan. */
6952 /* Read and parse all entries */
6953 while((!rc) && (BSSList.index != 0xffff)) {
6954 /* Translate to WE format this entry */
6955 current_ev = airo_translate_scan(dev, current_ev,
6956 extra + dwrq->length,
6959 /* Check if there is space for one more entry */
6960 if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) {
6961 /* Ask user space to try again with a bigger buffer */
6965 /* Read next entry */
6966 rc = PC4500_readrid(ai, RID_BSSLISTNEXT,
6967 &BSSList, sizeof(BSSList), 1);
6969 /* Length of data */
6970 dwrq->length = (current_ev - extra);
6971 dwrq->flags = 0; /* todo */
6976 /*------------------------------------------------------------------*/
6978 * Commit handler : called after a bunch of SET operations
6980 static int airo_config_commit(struct net_device *dev,
6981 struct iw_request_info *info, /* NULL */
6982 void *zwrq, /* NULL */
6983 char *extra) /* NULL */
6985 struct airo_info *local = dev->priv;
6988 if (!test_bit (FLAG_COMMIT, &local->flags))
6991 /* Some of the "SET" function may have modified some of the
6992 * parameters. It's now time to commit them in the card */
6993 disable_MAC(local, 1);
6994 if (test_bit (FLAG_RESET, &local->flags)) {
6995 APListRid APList_rid;
6998 readAPListRid(local, &APList_rid);
6999 readSsidRid(local, &SSID_rid);
7000 if (test_bit(FLAG_MPI,&local->flags))
7001 setup_card(local, dev->dev_addr, 1 );
7003 reset_airo_card(dev);
7004 disable_MAC(local, 1);
7005 writeSsidRid(local, &SSID_rid, 1);
7006 writeAPListRid(local, &APList_rid, 1);
7008 if (down_interruptible(&local->sem))
7009 return -ERESTARTSYS;
7010 writeConfigRid(local, 0);
7011 enable_MAC(local, &rsp, 0);
7012 if (test_bit (FLAG_RESET, &local->flags))
7013 airo_set_promisc(local);
7020 /*------------------------------------------------------------------*/
7022 * Structures to export the Wireless Handlers
7025 static const struct iw_priv_args airo_private_args[] = {
7026 /*{ cmd, set_args, get_args, name } */
7027 { AIROIOCTL, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
7028 IW_PRIV_TYPE_BYTE | 2047, "airoioctl" },
7029 { AIROIDIFC, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
7030 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "airoidifc" },
7033 static const iw_handler airo_handler[] =
7035 (iw_handler) airo_config_commit, /* SIOCSIWCOMMIT */
7036 (iw_handler) airo_get_name, /* SIOCGIWNAME */
7037 (iw_handler) NULL, /* SIOCSIWNWID */
7038 (iw_handler) NULL, /* SIOCGIWNWID */
7039 (iw_handler) airo_set_freq, /* SIOCSIWFREQ */
7040 (iw_handler) airo_get_freq, /* SIOCGIWFREQ */
7041 (iw_handler) airo_set_mode, /* SIOCSIWMODE */
7042 (iw_handler) airo_get_mode, /* SIOCGIWMODE */
7043 (iw_handler) airo_set_sens, /* SIOCSIWSENS */
7044 (iw_handler) airo_get_sens, /* SIOCGIWSENS */
7045 (iw_handler) NULL, /* SIOCSIWRANGE */
7046 (iw_handler) airo_get_range, /* SIOCGIWRANGE */
7047 (iw_handler) NULL, /* SIOCSIWPRIV */
7048 (iw_handler) NULL, /* SIOCGIWPRIV */
7049 (iw_handler) NULL, /* SIOCSIWSTATS */
7050 (iw_handler) NULL, /* SIOCGIWSTATS */
7051 iw_handler_set_spy, /* SIOCSIWSPY */
7052 iw_handler_get_spy, /* SIOCGIWSPY */
7053 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
7054 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
7055 (iw_handler) airo_set_wap, /* SIOCSIWAP */
7056 (iw_handler) airo_get_wap, /* SIOCGIWAP */
7057 (iw_handler) NULL, /* -- hole -- */
7058 (iw_handler) airo_get_aplist, /* SIOCGIWAPLIST */
7059 (iw_handler) airo_set_scan, /* SIOCSIWSCAN */
7060 (iw_handler) airo_get_scan, /* SIOCGIWSCAN */
7061 (iw_handler) airo_set_essid, /* SIOCSIWESSID */
7062 (iw_handler) airo_get_essid, /* SIOCGIWESSID */
7063 (iw_handler) airo_set_nick, /* SIOCSIWNICKN */
7064 (iw_handler) airo_get_nick, /* SIOCGIWNICKN */
7065 (iw_handler) NULL, /* -- hole -- */
7066 (iw_handler) NULL, /* -- hole -- */
7067 (iw_handler) airo_set_rate, /* SIOCSIWRATE */
7068 (iw_handler) airo_get_rate, /* SIOCGIWRATE */
7069 (iw_handler) airo_set_rts, /* SIOCSIWRTS */
7070 (iw_handler) airo_get_rts, /* SIOCGIWRTS */
7071 (iw_handler) airo_set_frag, /* SIOCSIWFRAG */
7072 (iw_handler) airo_get_frag, /* SIOCGIWFRAG */
7073 (iw_handler) airo_set_txpow, /* SIOCSIWTXPOW */
7074 (iw_handler) airo_get_txpow, /* SIOCGIWTXPOW */
7075 (iw_handler) airo_set_retry, /* SIOCSIWRETRY */
7076 (iw_handler) airo_get_retry, /* SIOCGIWRETRY */
7077 (iw_handler) airo_set_encode, /* SIOCSIWENCODE */
7078 (iw_handler) airo_get_encode, /* SIOCGIWENCODE */
7079 (iw_handler) airo_set_power, /* SIOCSIWPOWER */
7080 (iw_handler) airo_get_power, /* SIOCGIWPOWER */
7083 /* Note : don't describe AIROIDIFC and AIROOLDIDIFC in here.
7084 * We want to force the use of the ioctl code, because those can't be
7085 * won't work the iw_handler code (because they simultaneously read
7086 * and write data and iw_handler can't do that).
7087 * Note that it's perfectly legal to read/write on a single ioctl command,
7088 * you just can't use iwpriv and need to force it via the ioctl handler.
7090 static const iw_handler airo_private_handler[] =
7092 NULL, /* SIOCIWFIRSTPRIV */
7095 static const struct iw_handler_def airo_handler_def =
7097 .num_standard = sizeof(airo_handler)/sizeof(iw_handler),
7098 .num_private = sizeof(airo_private_handler)/sizeof(iw_handler),
7099 .num_private_args = sizeof(airo_private_args)/sizeof(struct iw_priv_args),
7100 .standard = airo_handler,
7101 .private = airo_private_handler,
7102 .private_args = airo_private_args,
7103 .get_wireless_stats = airo_get_wireless_stats,
7106 #endif /* WIRELESS_EXT */
7109 * This defines the configuration part of the Wireless Extensions
7110 * Note : irq and spinlock protection will occur in the subroutines
7113 * o Check input value more carefully and fill correct values in range
7114 * o Test and shakeout the bugs (if any)
7118 * Javier Achirica did a great job of merging code from the unnamed CISCO
7119 * developer that added support for flashing the card.
7121 static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
7124 struct airo_info *ai = (struct airo_info *)dev->priv;
7136 int val = AIROMAGIC;
7138 if (copy_from_user(&com,rq->ifr_data,sizeof(com)))
7140 else if (copy_to_user(com.data,(char *)&val,sizeof(val)))
7149 /* Get the command struct and hand it off for evaluation by
7150 * the proper subfunction
7154 if (copy_from_user(&com,rq->ifr_data,sizeof(com))) {
7159 /* Separate R/W functions bracket legality here
7161 if ( com.command == AIRORSWVERSION ) {
7162 if (copy_to_user(com.data, swversion, sizeof(swversion)))
7167 else if ( com.command <= AIRORRID)
7168 rc = readrids(dev,&com);
7169 else if ( com.command >= AIROPCAP && com.command <= (AIROPLEAPUSR+2) )
7170 rc = writerids(dev,&com);
7171 else if ( com.command >= AIROFLSHRST && com.command <= AIRORESTART )
7172 rc = flashcard(dev,&com);
7174 rc = -EINVAL; /* Bad command in ioctl */
7177 #endif /* CISCO_EXT */
7179 // All other calls are currently unsupported
7188 * Get the Wireless stats out of the driver
7189 * Note : irq and spinlock protection will occur in the subroutines
7192 * o Check if work in Ad-Hoc mode (otherwise, use SPY, as in wvlan_cs)
7196 static void airo_read_wireless_stats(struct airo_info *local)
7198 StatusRid status_rid;
7200 CapabilityRid cap_rid;
7201 u32 *vals = stats_rid.vals;
7203 /* Get stats out of the card */
7204 clear_bit(JOB_WSTATS, &local->flags);
7209 readCapabilityRid(local, &cap_rid, 0);
7210 readStatusRid(local, &status_rid, 0);
7211 readStatsRid(local, &stats_rid, RID_STATS, 0);
7215 local->wstats.status = status_rid.mode;
7217 /* Signal quality and co */
7219 local->wstats.qual.level = airo_rssi_to_dbm( local->rssi, status_rid.sigQuality );
7220 /* normalizedSignalStrength appears to be a percentage */
7221 local->wstats.qual.qual = status_rid.normalizedSignalStrength;
7223 local->wstats.qual.level = (status_rid.normalizedSignalStrength + 321) / 2;
7224 local->wstats.qual.qual = airo_get_quality(&status_rid, &cap_rid);
7226 local->wstats.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED;
7227 if (status_rid.len >= 124) {
7228 local->wstats.qual.noise = 0x100 - status_rid.noisedBm;
7229 local->wstats.qual.updated |= IW_QUAL_NOISE_UPDATED;
7231 local->wstats.qual.noise = 0;
7232 local->wstats.qual.updated |= IW_QUAL_NOISE_INVALID;
7235 /* Packets discarded in the wireless adapter due to wireless
7236 * specific problems */
7237 local->wstats.discard.nwid = vals[56] + vals[57] + vals[58];/* SSID Mismatch */
7238 local->wstats.discard.code = vals[6];/* RxWepErr */
7239 local->wstats.discard.fragment = vals[30];
7240 local->wstats.discard.retries = vals[10];
7241 local->wstats.discard.misc = vals[1] + vals[32];
7242 local->wstats.miss.beacon = vals[34];
7245 static struct iw_statistics *airo_get_wireless_stats(struct net_device *dev)
7247 struct airo_info *local = dev->priv;
7249 if (!test_bit(JOB_WSTATS, &local->flags)) {
7250 /* Get stats out of the card if available */
7251 if (down_trylock(&local->sem) != 0) {
7252 set_bit(JOB_WSTATS, &local->flags);
7253 wake_up_interruptible(&local->thr_wait);
7255 airo_read_wireless_stats(local);
7258 return &local->wstats;
7260 #endif /* WIRELESS_EXT */
7264 * This just translates from driver IOCTL codes to the command codes to
7265 * feed to the radio's host interface. Things can be added/deleted
7266 * as needed. This represents the READ side of control I/O to
7269 static int readrids(struct net_device *dev, aironet_ioctl *comp) {
7270 unsigned short ridcode;
7271 unsigned char *iobuf;
7273 struct airo_info *ai = dev->priv;
7276 if (test_bit(FLAG_FLASHING, &ai->flags))
7279 switch(comp->command)
7281 case AIROGCAP: ridcode = RID_CAPABILITIES; break;
7282 case AIROGCFG: ridcode = RID_CONFIG;
7283 if (test_bit(FLAG_COMMIT, &ai->flags)) {
7284 disable_MAC (ai, 1);
7285 writeConfigRid (ai, 1);
7286 enable_MAC (ai, &rsp, 1);
7289 case AIROGSLIST: ridcode = RID_SSID; break;
7290 case AIROGVLIST: ridcode = RID_APLIST; break;
7291 case AIROGDRVNAM: ridcode = RID_DRVNAME; break;
7292 case AIROGEHTENC: ridcode = RID_ETHERENCAP; break;
7293 case AIROGWEPKTMP: ridcode = RID_WEP_TEMP;
7294 /* Only super-user can read WEP keys */
7295 if (!capable(CAP_NET_ADMIN))
7298 case AIROGWEPKNV: ridcode = RID_WEP_PERM;
7299 /* Only super-user can read WEP keys */
7300 if (!capable(CAP_NET_ADMIN))
7303 case AIROGSTAT: ridcode = RID_STATUS; break;
7304 case AIROGSTATSD32: ridcode = RID_STATSDELTA; break;
7305 case AIROGSTATSC32: ridcode = RID_STATS; break;
7308 if (copy_to_user(comp->data, &ai->micstats,
7309 min((int)comp->len,(int)sizeof(ai->micstats))))
7313 case AIRORRID: ridcode = comp->ridnum; break;
7319 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7322 PC4500_readrid(ai,ridcode,iobuf,RIDSIZE, 1);
7323 /* get the count of bytes in the rid docs say 1st 2 bytes is it.
7324 * then return it to the user
7325 * 9/22/2000 Honor user given length
7329 if (copy_to_user(comp->data, iobuf, min(len, (int)RIDSIZE))) {
7338 * Danger Will Robinson write the rids here
7341 static int writerids(struct net_device *dev, aironet_ioctl *comp) {
7342 struct airo_info *ai = dev->priv;
7348 static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
7349 unsigned char *iobuf;
7351 /* Only super-user can write RIDs */
7352 if (!capable(CAP_NET_ADMIN))
7355 if (test_bit(FLAG_FLASHING, &ai->flags))
7359 writer = do_writerid;
7361 switch(comp->command)
7363 case AIROPSIDS: ridcode = RID_SSID; break;
7364 case AIROPCAP: ridcode = RID_CAPABILITIES; break;
7365 case AIROPAPLIST: ridcode = RID_APLIST; break;
7366 case AIROPCFG: ai->config.len = 0;
7367 clear_bit(FLAG_COMMIT, &ai->flags);
7368 ridcode = RID_CONFIG; break;
7369 case AIROPWEPKEYNV: ridcode = RID_WEP_PERM; break;
7370 case AIROPLEAPUSR: ridcode = RID_LEAPUSERNAME; break;
7371 case AIROPLEAPPWD: ridcode = RID_LEAPPASSWORD; break;
7372 case AIROPWEPKEY: ridcode = RID_WEP_TEMP; writer = PC4500_writerid;
7374 case AIROPLEAPUSR+1: ridcode = 0xFF2A; break;
7375 case AIROPLEAPUSR+2: ridcode = 0xFF2B; break;
7377 /* this is not really a rid but a command given to the card
7381 if (enable_MAC(ai, &rsp, 1) != 0)
7386 * Evidently this code in the airo driver does not get a symbol
7387 * as disable_MAC. it's probably so short the compiler does not gen one.
7393 /* This command merely clears the counts does not actually store any data
7394 * only reads rid. But as it changes the cards state, I put it in the
7395 * writerid routines.
7398 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7401 PC4500_readrid(ai,RID_STATSDELTACLEAR,iobuf,RIDSIZE, 1);
7404 enabled = ai->micstats.enabled;
7405 memset(&ai->micstats,0,sizeof(ai->micstats));
7406 ai->micstats.enabled = enabled;
7409 if (copy_to_user(comp->data, iobuf,
7410 min((int)comp->len, (int)RIDSIZE))) {
7418 return -EOPNOTSUPP; /* Blarg! */
7420 if(comp->len > RIDSIZE)
7423 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7426 if (copy_from_user(iobuf,comp->data,comp->len)) {
7431 if (comp->command == AIROPCFG) {
7432 ConfigRid *cfg = (ConfigRid *)iobuf;
7434 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags))
7435 cfg->opmode |= MODE_MIC;
7437 if ((cfg->opmode & 0xFF) == MODE_STA_IBSS)
7438 set_bit (FLAG_ADHOC, &ai->flags);
7440 clear_bit (FLAG_ADHOC, &ai->flags);
7443 if((*writer)(ai, ridcode, iobuf,comp->len,1)) {
7451 /*****************************************************************************
7452 * Ancillary flash / mod functions much black magic lurkes here *
7453 *****************************************************************************
7457 * Flash command switch table
7460 static int flashcard(struct net_device *dev, aironet_ioctl *comp) {
7463 /* Only super-user can modify flash */
7464 if (!capable(CAP_NET_ADMIN))
7467 switch(comp->command)
7470 return cmdreset((struct airo_info *)dev->priv);
7473 if (!((struct airo_info *)dev->priv)->flash &&
7474 (((struct airo_info *)dev->priv)->flash = kmalloc (FLASHSIZE, GFP_KERNEL)) == NULL)
7476 return setflashmode((struct airo_info *)dev->priv);
7478 case AIROFLSHGCHR: /* Get char from aux */
7479 if(comp->len != sizeof(int))
7481 if (copy_from_user(&z,comp->data,comp->len))
7483 return flashgchar((struct airo_info *)dev->priv,z,8000);
7485 case AIROFLSHPCHR: /* Send char to card. */
7486 if(comp->len != sizeof(int))
7488 if (copy_from_user(&z,comp->data,comp->len))
7490 return flashpchar((struct airo_info *)dev->priv,z,8000);
7492 case AIROFLPUTBUF: /* Send 32k to card */
7493 if (!((struct airo_info *)dev->priv)->flash)
7495 if(comp->len > FLASHSIZE)
7497 if(copy_from_user(((struct airo_info *)dev->priv)->flash,comp->data,comp->len))
7500 flashputbuf((struct airo_info *)dev->priv);
7504 if(flashrestart((struct airo_info *)dev->priv,dev))
7511 #define FLASH_COMMAND 0x7e7e
7515 * Disable MAC and do soft reset on
7519 static int cmdreset(struct airo_info *ai) {
7523 printk(KERN_INFO "Waitbusy hang before RESET\n");
7527 OUT4500(ai,COMMAND,CMD_SOFTRESET);
7529 ssleep(1); /* WAS 600 12/7/00 */
7532 printk(KERN_INFO "Waitbusy hang AFTER RESET\n");
7539 * Put the card in legendary flash
7543 static int setflashmode (struct airo_info *ai) {
7544 set_bit (FLAG_FLASHING, &ai->flags);
7546 OUT4500(ai, SWS0, FLASH_COMMAND);
7547 OUT4500(ai, SWS1, FLASH_COMMAND);
7549 OUT4500(ai, SWS0, FLASH_COMMAND);
7550 OUT4500(ai, COMMAND,0x10);
7552 OUT4500(ai, SWS2, FLASH_COMMAND);
7553 OUT4500(ai, SWS3, FLASH_COMMAND);
7554 OUT4500(ai, COMMAND,0);
7556 msleep(500); /* 500ms delay */
7559 clear_bit (FLAG_FLASHING, &ai->flags);
7560 printk(KERN_INFO "Waitbusy hang after setflash mode\n");
7566 /* Put character to SWS0 wait for dwelltime
7570 static int flashpchar(struct airo_info *ai,int byte,int dwelltime) {
7581 /* Wait for busy bit d15 to go false indicating buffer empty */
7582 while ((IN4500 (ai, SWS0) & 0x8000) && waittime > 0) {
7587 /* timeout for busy clear wait */
7589 printk(KERN_INFO "flash putchar busywait timeout! \n");
7593 /* Port is clear now write byte and wait for it to echo back */
7595 OUT4500(ai,SWS0,byte);
7598 echo = IN4500(ai,SWS1);
7599 } while (dwelltime >= 0 && echo != byte);
7603 return (echo == byte) ? 0 : -EIO;
7607 * Get a character from the card matching matchbyte
7610 static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime){
7612 unsigned char rbyte=0;
7615 rchar = IN4500(ai,SWS1);
7617 if(dwelltime && !(0x8000 & rchar)){
7622 rbyte = 0xff & rchar;
7624 if( (rbyte == matchbyte) && (0x8000 & rchar) ){
7628 if( rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
7632 }while(dwelltime > 0);
7637 * Transfer 32k of firmware data from user buffer to our buffer and
7641 static int flashputbuf(struct airo_info *ai){
7645 if (test_bit(FLAG_MPI,&ai->flags))
7646 memcpy_toio(ai->pciaux + 0x8000, ai->flash, FLASHSIZE);
7648 OUT4500(ai,AUXPAGE,0x100);
7649 OUT4500(ai,AUXOFF,0);
7651 for(nwords=0;nwords != FLASHSIZE / 2;nwords++){
7652 OUT4500(ai,AUXDATA,ai->flash[nwords] & 0xffff);
7655 OUT4500(ai,SWS0,0x8000);
7663 static int flashrestart(struct airo_info *ai,struct net_device *dev){
7666 ssleep(1); /* Added 12/7/00 */
7667 clear_bit (FLAG_FLASHING, &ai->flags);
7668 if (test_bit(FLAG_MPI, &ai->flags)) {
7669 status = mpi_init_descriptors(ai);
7670 if (status != SUCCESS)
7673 status = setup_card(ai, dev->dev_addr, 1);
7675 if (!test_bit(FLAG_MPI,&ai->flags))
7676 for( i = 0; i < MAX_FIDS; i++ ) {
7677 ai->fids[i] = transmit_allocate
7678 ( ai, 2312, i >= MAX_FIDS / 2 );
7681 ssleep(1); /* Added 12/7/00 */
7684 #endif /* CISCO_EXT */
7687 This program is free software; you can redistribute it and/or
7688 modify it under the terms of the GNU General Public License
7689 as published by the Free Software Foundation; either version 2
7690 of the License, or (at your option) any later version.
7692 This program is distributed in the hope that it will be useful,
7693 but WITHOUT ANY WARRANTY; without even the implied warranty of
7694 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7695 GNU General Public License for more details.
7699 Redistribution and use in source and binary forms, with or without
7700 modification, are permitted provided that the following conditions
7703 1. Redistributions of source code must retain the above copyright
7704 notice, this list of conditions and the following disclaimer.
7705 2. Redistributions in binary form must reproduce the above copyright
7706 notice, this list of conditions and the following disclaimer in the
7707 documentation and/or other materials provided with the distribution.
7708 3. The name of the author may not be used to endorse or promote
7709 products derived from this software without specific prior written
7712 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
7713 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
7714 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7715 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
7716 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
7717 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
7718 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
7719 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
7720 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
7721 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
7722 POSSIBILITY OF SUCH DAMAGE.
7725 module_init(airo_init_module);
7726 module_exit(airo_cleanup_module);