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>
29 #include <linux/sched.h>
30 #include <linux/ptrace.h>
31 #include <linux/slab.h>
32 #include <linux/string.h>
33 #include <linux/timer.h>
34 #include <linux/interrupt.h>
35 #include <linux/suspend.h>
38 #include <asm/system.h>
39 #include <asm/bitops.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, u32 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) 0
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_PARM(io,"1-4i");
249 MODULE_PARM(irq,"1-4i");
250 MODULE_PARM(basic_rate,"i");
251 MODULE_PARM(rates,"1-8i");
252 MODULE_PARM(ssids,"1-3s");
253 MODULE_PARM(auto_wep,"i");
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_PARM(aux_bap,"i");
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_PARM(maxencrypt, "i");
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_PARM(adhoc, "i");
267 MODULE_PARM_DESC(adhoc, "If non-zero, the card will start in adhoc mode.");
268 MODULE_PARM(probe, "i");
269 MODULE_PARM_DESC(probe, "If zero, the driver won't start the card.");
271 MODULE_PARM(proc_uid, "i");
272 MODULE_PARM_DESC(proc_uid, "The uid that the /proc files will belong to.");
273 MODULE_PARM(proc_gid, "i");
274 MODULE_PARM_DESC(proc_gid, "The gid that the /proc files will belong to.");
275 MODULE_PARM(airo_perm, "i");
276 MODULE_PARM_DESC(airo_perm, "The permission bits of /proc/[driver/]aironet.");
277 MODULE_PARM(proc_perm, "i");
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 /* Leave gap of 40 commands after AIROGSTATSD32 for future */
868 #define AIROPCAP AIROGSTATSD32 + 40
869 #define AIROPVLIST AIROPCAP + 1
870 #define AIROPSLIST AIROPVLIST + 1
871 #define AIROPCFG AIROPSLIST + 1
872 #define AIROPSIDS AIROPCFG + 1
873 #define AIROPAPLIST AIROPSIDS + 1
874 #define AIROPMACON AIROPAPLIST + 1 /* Enable mac */
875 #define AIROPMACOFF AIROPMACON + 1 /* Disable mac */
876 #define AIROPSTCLR AIROPMACOFF + 1
877 #define AIROPWEPKEY AIROPSTCLR + 1
878 #define AIROPWEPKEYNV AIROPWEPKEY + 1
879 #define AIROPLEAPPWD AIROPWEPKEYNV + 1
880 #define AIROPLEAPUSR AIROPLEAPPWD + 1
884 #define AIROFLSHRST AIROPWEPKEYNV + 40
885 #define AIROFLSHGCHR AIROFLSHRST + 1
886 #define AIROFLSHSTFL AIROFLSHGCHR + 1
887 #define AIROFLSHPCHR AIROFLSHSTFL + 1
888 #define AIROFLPUTBUF AIROFLSHPCHR + 1
889 #define AIRORESTART AIROFLPUTBUF + 1
891 #define FLASHSIZE 32768
892 #define AUXMEMSIZE (256 * 1024)
894 typedef struct aironet_ioctl {
895 unsigned short command; // What to do
896 unsigned short len; // Len of data
897 unsigned char *data; // d-data
899 #endif /* CISCO_EXT */
901 #define NUM_MODULES 2
902 #define MIC_MSGLEN_MAX 2400
903 #define EMMH32_MSGLEN_MAX MIC_MSGLEN_MAX
907 u8 enabled; // MIC enabled or not
908 u32 rxSuccess; // successful packets received
909 u32 rxIncorrectMIC; // pkts dropped due to incorrect MIC comparison
910 u32 rxNotMICed; // pkts dropped due to not being MIC'd
911 u32 rxMICPlummed; // pkts dropped due to not having a MIC plummed
912 u32 rxWrongSequence; // pkts dropped due to sequence number violation
917 u32 coeff[((EMMH32_MSGLEN_MAX)+3)>>2];
918 u64 accum; // accumulated mic, reduced to u32 in final()
919 int position; // current position (byte offset) in message
923 } part; // saves partial message word across update() calls
927 emmh32_context seed; // Context - the seed
928 u32 rx; // Received sequence number
929 u32 tx; // Tx sequence number
930 u32 window; // Start of window
931 u8 valid; // Flag to say if context is valid or not
936 miccntx mCtx; // Multicast context
937 miccntx uCtx; // Unicast context
941 unsigned int rid: 16;
942 unsigned int len: 15;
943 unsigned int valid: 1;
944 dma_addr_t host_addr;
948 unsigned int offset: 15;
950 unsigned int len: 15;
951 unsigned int valid: 1;
952 dma_addr_t host_addr;
956 unsigned int ctl: 15;
958 unsigned int len: 15;
959 unsigned int valid: 1;
960 dma_addr_t host_addr;
964 * Host receive descriptor
967 unsigned char *card_ram_off; /* offset into card memory of the
969 RxFid rx_desc; /* card receive descriptor */
970 char *virtual_host_addr; /* virtual address of host receive
976 * Host transmit descriptor
979 unsigned char *card_ram_off; /* offset into card memory of the
981 TxFid tx_desc; /* card transmit descriptor */
982 char *virtual_host_addr; /* virtual address of host receive
988 * Host RID descriptor
991 unsigned char *card_ram_off; /* offset into card memory of the
993 Rid rid_desc; /* card RID descriptor */
994 char *virtual_host_addr; /* virtual address of host receive
1003 #define HOST_SET (1 << 0)
1004 #define HOST_INT_TX (1 << 1) /* Interrupt on successful TX */
1005 #define HOST_INT_TXERR (1 << 2) /* Interrupt on unseccessful TX */
1006 #define HOST_LCC_PAYLOAD (1 << 4) /* LLC payload, 0 = Ethertype */
1007 #define HOST_DONT_RLSE (1 << 5) /* Don't release buffer when done */
1008 #define HOST_DONT_RETRY (1 << 6) /* Don't retry trasmit */
1009 #define HOST_CLR_AID (1 << 7) /* clear AID failure */
1010 #define HOST_RTS (1 << 9) /* Force RTS use */
1011 #define HOST_SHORT (1 << 10) /* Do short preamble */
1038 WifiCtlHdr wifictlhdr8023 = {
1040 .ctl = HOST_DONT_RLSE,
1045 // Frequency list (map channels to frequencies)
1046 static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
1047 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
1049 // A few details needed for WEP (Wireless Equivalent Privacy)
1050 #define MAX_KEY_SIZE 13 // 128 (?) bits
1051 #define MIN_KEY_SIZE 5 // 40 bits RC4 - WEP
1052 typedef struct wep_key_t {
1054 u8 key[16]; /* 40-bit and 104-bit keys */
1057 /* Backward compatibility */
1058 #ifndef IW_ENCODE_NOKEY
1059 #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
1060 #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
1061 #endif /* IW_ENCODE_NOKEY */
1063 /* List of Wireless Handlers (new API) */
1064 static const struct iw_handler_def airo_handler_def;
1065 #endif /* WIRELESS_EXT */
1067 static const char version[] = "airo.c 0.6 (Ben Reed & Javier Achirica)";
1071 static int get_dec_u16( char *buffer, int *start, int limit );
1072 static void OUT4500( struct airo_info *, u16 register, u16 value );
1073 static unsigned short IN4500( struct airo_info *, u16 register );
1074 static u16 setup_card(struct airo_info*, u8 *mac, int lock);
1075 static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock );
1076 static void disable_MAC(struct airo_info *ai, int lock);
1077 static void enable_interrupts(struct airo_info*);
1078 static void disable_interrupts(struct airo_info*);
1079 static u16 issuecommand(struct airo_info*, Cmd *pCmd, Resp *pRsp);
1080 static int bap_setup(struct airo_info*, u16 rid, u16 offset, int whichbap);
1081 static int aux_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen,
1083 static int fast_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen,
1085 static int bap_write(struct airo_info*, const u16 *pu16Src, int bytelen,
1087 static int PC4500_accessrid(struct airo_info*, u16 rid, u16 accmd);
1088 static int PC4500_readrid(struct airo_info*, u16 rid, void *pBuf, int len, int lock);
1089 static int PC4500_writerid(struct airo_info*, u16 rid, const void
1090 *pBuf, int len, int lock);
1091 static int do_writerid( struct airo_info*, u16 rid, const void *rid_data,
1092 int len, int dummy );
1093 static u16 transmit_allocate(struct airo_info*, int lenPayload, int raw);
1094 static int transmit_802_3_packet(struct airo_info*, int len, char *pPacket);
1095 static int transmit_802_11_packet(struct airo_info*, int len, char *pPacket);
1097 static int mpi_send_packet (struct net_device *dev);
1098 static void mpi_unmap_card(struct pci_dev *pci);
1099 static void mpi_receive_802_3(struct airo_info *ai);
1100 static int waitbusy (struct airo_info *ai);
1102 static irqreturn_t airo_interrupt( int irq, void* dev_id, struct pt_regs
1104 static int airo_thread(void *data);
1105 static void timer_func( struct net_device *dev );
1106 static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
1108 struct iw_statistics *airo_get_wireless_stats (struct net_device *dev);
1109 static void airo_read_wireless_stats (struct airo_info *local);
1110 #endif /* WIRELESS_EXT */
1112 static int readrids(struct net_device *dev, aironet_ioctl *comp);
1113 static int writerids(struct net_device *dev, aironet_ioctl *comp);
1114 int flashcard(struct net_device *dev, aironet_ioctl *comp);
1115 #endif /* CISCO_EXT */
1117 static void micinit(struct airo_info *ai);
1118 static int micsetup(struct airo_info *ai);
1119 static int encapsulate(struct airo_info *ai, etherHead *pPacket, MICBuffer *buffer, int len);
1120 static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *pPacket, u16 payLen);
1122 #include <linux/crypto.h>
1126 struct net_device_stats stats;
1127 struct net_device *dev;
1128 /* Note, we can have MAX_FIDS outstanding. FIDs are 16-bits, so we
1129 use the high bit to mark whether it is in use. */
1131 #define MPI_MAX_FIDS 1
1134 char keyindex; // Used with auto wep
1135 char defindex; // Used with auto wep
1136 struct proc_dir_entry *proc_entry;
1137 spinlock_t aux_lock;
1138 unsigned long flags;
1139 #define FLAG_PROMISC 8 /* IFF_PROMISC 0x100 - include/linux/if.h */
1140 #define FLAG_RADIO_OFF 0 /* User disabling of MAC */
1141 #define FLAG_RADIO_DOWN 1 /* ifup/ifdown disabling of MAC */
1142 #define FLAG_RADIO_MASK 0x03
1143 #define FLAG_ENABLED 2
1144 #define FLAG_ADHOC 3 /* Needed by MIC */
1145 #define FLAG_MIC_CAPABLE 4
1146 #define FLAG_UPDATE_MULTI 5
1147 #define FLAG_UPDATE_UNI 6
1148 #define FLAG_802_11 7
1149 #define FLAG_PENDING_XMIT 9
1150 #define FLAG_PENDING_XMIT11 10
1152 #define FLAG_REGISTERED 12
1153 #define FLAG_COMMIT 13
1154 #define FLAG_RESET 14
1155 #define FLAG_FLASHING 15
1156 #define JOB_MASK 0x1ff0000
1159 #define JOB_XMIT11 18
1160 #define JOB_STATS 19
1161 #define JOB_PROMISC 20
1163 #define JOB_EVENT 22
1164 #define JOB_AUTOWEP 23
1165 #define JOB_WSTATS 24
1166 int (*bap_read)(struct airo_info*, u16 *pu16Dst, int bytelen,
1168 unsigned short *flash;
1170 struct task_struct *task;
1171 struct semaphore sem;
1173 wait_queue_head_t thr_wait;
1174 struct completion thr_exited;
1175 unsigned long expires;
1177 struct sk_buff *skb;
1180 struct net_device *wifidev;
1182 struct iw_statistics wstats; // wireless stats
1183 unsigned long scan_timestamp; /* Time started to scan */
1184 struct iw_spy_data spy_data;
1185 #endif /* WIRELESS_EXT */
1188 struct crypto_tfm *tfm;
1190 mic_statistics micstats;
1192 HostRxDesc rxfids[MPI_MAX_FIDS]; // rx/tx/config MPI350 descriptors
1193 HostTxDesc txfids[MPI_MAX_FIDS];
1194 HostRidDesc config_desc;
1195 unsigned long ridbus; // phys addr of config_desc
1196 struct sk_buff_head txq;// tx queue used by mpi350 code
1197 struct pci_dev *pci;
1198 unsigned char *pcimem;
1199 unsigned char *pciaux;
1200 unsigned char *shared;
1201 dma_addr_t shared_dma;
1205 #define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE
1208 static inline int bap_read(struct airo_info *ai, u16 *pu16Dst, int bytelen,
1210 return ai->bap_read(ai, pu16Dst, bytelen, whichbap);
1213 static int setup_proc_entry( struct net_device *dev,
1214 struct airo_info *apriv );
1215 static int takedown_proc_entry( struct net_device *dev,
1216 struct airo_info *apriv );
1219 /***********************************************************************
1221 ***********************************************************************
1224 static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq);
1225 static void MoveWindow(miccntx *context, u32 micSeq);
1226 void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *);
1227 void emmh32_init(emmh32_context *context);
1228 void emmh32_update(emmh32_context *context, u8 *pOctets, int len);
1229 void emmh32_final(emmh32_context *context, u8 digest[4]);
1231 /* micinit - Initialize mic seed */
1233 static void micinit(struct airo_info *ai)
1237 clear_bit(JOB_MIC, &ai->flags);
1238 PC4500_readrid(ai, RID_MIC, &mic_rid, sizeof(mic_rid), 0);
1241 ai->micstats.enabled = (mic_rid.state & 0x00FF) ? 1 : 0;
1243 if (ai->micstats.enabled) {
1244 /* Key must be valid and different */
1245 if (mic_rid.multicastValid && (!ai->mod[0].mCtx.valid ||
1246 (memcmp (ai->mod[0].mCtx.key, mic_rid.multicast,
1247 sizeof(ai->mod[0].mCtx.key)) != 0))) {
1248 /* Age current mic Context */
1249 memcpy(&ai->mod[1].mCtx,&ai->mod[0].mCtx,sizeof(miccntx));
1250 /* Initialize new context */
1251 memcpy(&ai->mod[0].mCtx.key,mic_rid.multicast,sizeof(mic_rid.multicast));
1252 ai->mod[0].mCtx.window = 33; //Window always points to the middle
1253 ai->mod[0].mCtx.rx = 0; //Rx Sequence numbers
1254 ai->mod[0].mCtx.tx = 0; //Tx sequence numbers
1255 ai->mod[0].mCtx.valid = 1; //Key is now valid
1257 /* Give key to mic seed */
1258 emmh32_setseed(&ai->mod[0].mCtx.seed,mic_rid.multicast,sizeof(mic_rid.multicast), ai->tfm);
1261 /* Key must be valid and different */
1262 if (mic_rid.unicastValid && (!ai->mod[0].uCtx.valid ||
1263 (memcmp(ai->mod[0].uCtx.key, mic_rid.unicast,
1264 sizeof(ai->mod[0].uCtx.key)) != 0))) {
1265 /* Age current mic Context */
1266 memcpy(&ai->mod[1].uCtx,&ai->mod[0].uCtx,sizeof(miccntx));
1267 /* Initialize new context */
1268 memcpy(&ai->mod[0].uCtx.key,mic_rid.unicast,sizeof(mic_rid.unicast));
1270 ai->mod[0].uCtx.window = 33; //Window always points to the middle
1271 ai->mod[0].uCtx.rx = 0; //Rx Sequence numbers
1272 ai->mod[0].uCtx.tx = 0; //Tx sequence numbers
1273 ai->mod[0].uCtx.valid = 1; //Key is now valid
1275 //Give key to mic seed
1276 emmh32_setseed(&ai->mod[0].uCtx.seed, mic_rid.unicast, sizeof(mic_rid.unicast), ai->tfm);
1279 /* So next time we have a valid key and mic is enabled, we will update
1280 * the sequence number if the key is the same as before.
1282 ai->mod[0].uCtx.valid = 0;
1283 ai->mod[0].mCtx.valid = 0;
1287 /* micsetup - Get ready for business */
1289 static int micsetup(struct airo_info *ai) {
1292 if (ai->tfm == NULL)
1293 ai->tfm = crypto_alloc_tfm("aes", 0);
1295 if (ai->tfm == NULL) {
1296 printk(KERN_ERR "airo: failed to load transform for AES\n");
1300 for (i=0; i < NUM_MODULES; i++) {
1301 memset(&ai->mod[i].mCtx,0,sizeof(miccntx));
1302 memset(&ai->mod[i].uCtx,0,sizeof(miccntx));
1307 char micsnap[]= {0xAA,0xAA,0x03,0x00,0x40,0x96,0x00,0x02};
1309 /*===========================================================================
1310 * Description: Mic a packet
1312 * Inputs: etherHead * pointer to an 802.3 frame
1314 * Returns: BOOLEAN if successful, otherwise false.
1315 * PacketTxLen will be updated with the mic'd packets size.
1317 * Caveats: It is assumed that the frame buffer will already
1318 * be big enough to hold the largets mic message possible.
1319 * (No memory allocation is done here).
1321 * Author: sbraneky (10/15/01)
1322 * Merciless hacks by rwilcher (1/14/02)
1325 static int encapsulate(struct airo_info *ai ,etherHead *frame, MICBuffer *mic, int payLen)
1329 // Determine correct context
1330 // If not adhoc, always use unicast key
1332 if (test_bit(FLAG_ADHOC, &ai->flags) && (frame->da[0] & 0x1))
1333 context = &ai->mod[0].mCtx;
1335 context = &ai->mod[0].uCtx;
1337 if (!context->valid)
1340 mic->typelen = htons(payLen + 16); //Length of Mic'd packet
1342 memcpy(&mic->u.snap, micsnap, sizeof(micsnap)); // Add Snap
1345 mic->seq = htonl(context->tx);
1348 emmh32_init(&context->seed); // Mic the packet
1349 emmh32_update(&context->seed,frame->da,ETH_ALEN * 2); // DA,SA
1350 emmh32_update(&context->seed,(u8*)&mic->typelen,10); // Type/Length and Snap
1351 emmh32_update(&context->seed,(u8*)&mic->seq,sizeof(mic->seq)); //SEQ
1352 emmh32_update(&context->seed,frame->da + ETH_ALEN * 2,payLen); //payload
1353 emmh32_final(&context->seed, (u8*)&mic->mic);
1355 /* New Type/length ?????????? */
1356 mic->typelen = 0; //Let NIC know it could be an oversized packet
1368 /*===========================================================================
1369 * Description: Decapsulates a MIC'd packet and returns the 802.3 packet
1370 * (removes the MIC stuff) if packet is a valid packet.
1372 * Inputs: etherHead pointer to the 802.3 packet
1374 * Returns: BOOLEAN - TRUE if packet should be dropped otherwise FALSE
1376 * Author: sbraneky (10/15/01)
1377 * Merciless hacks by rwilcher (1/14/02)
1378 *---------------------------------------------------------------------------
1381 static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *eth, u16 payLen)
1387 mic_error micError = NONE;
1389 // Check if the packet is a Mic'd packet
1391 if (!ai->micstats.enabled) {
1392 //No Mic set or Mic OFF but we received a MIC'd packet.
1393 if (memcmp ((u8*)eth + 14, micsnap, sizeof(micsnap)) == 0) {
1394 ai->micstats.rxMICPlummed++;
1400 if (ntohs(mic->typelen) == 0x888E)
1403 if (memcmp (mic->u.snap, micsnap, sizeof(micsnap)) != 0) {
1404 // Mic enabled but packet isn't Mic'd
1405 ai->micstats.rxMICPlummed++;
1409 micSEQ = ntohl(mic->seq); //store SEQ as CPU order
1411 //At this point we a have a mic'd packet and mic is enabled
1412 //Now do the mic error checking.
1414 //Receive seq must be odd
1415 if ( (micSEQ & 1) == 0 ) {
1416 ai->micstats.rxWrongSequence++;
1420 for (i = 0; i < NUM_MODULES; i++) {
1421 int mcast = eth->da[0] & 1;
1422 //Determine proper context
1423 context = mcast ? &ai->mod[i].mCtx : &ai->mod[i].uCtx;
1425 //Make sure context is valid
1426 if (!context->valid) {
1428 micError = NOMICPLUMMED;
1434 mic->typelen = htons(payLen + sizeof(MICBuffer) - 2);
1436 emmh32_init(&context->seed);
1437 emmh32_update(&context->seed, eth->da, ETH_ALEN*2);
1438 emmh32_update(&context->seed, (u8 *)&mic->typelen, sizeof(mic->typelen)+sizeof(mic->u.snap));
1439 emmh32_update(&context->seed, (u8 *)&mic->seq,sizeof(mic->seq));
1440 emmh32_update(&context->seed, eth->da + ETH_ALEN*2,payLen);
1442 emmh32_final(&context->seed, digest);
1444 if (memcmp(digest, &mic->mic, 4)) { //Make sure the mics match
1447 micError = INCORRECTMIC;
1451 //Check Sequence number if mics pass
1452 if (RxSeqValid(ai, context, mcast, micSEQ) == SUCCESS) {
1453 ai->micstats.rxSuccess++;
1457 micError = SEQUENCE;
1460 // Update statistics
1462 case NOMICPLUMMED: ai->micstats.rxMICPlummed++; break;
1463 case SEQUENCE: ai->micstats.rxWrongSequence++; break;
1464 case INCORRECTMIC: ai->micstats.rxIncorrectMIC++; break;
1471 /*===========================================================================
1472 * Description: Checks the Rx Seq number to make sure it is valid
1473 * and hasn't already been received
1475 * Inputs: miccntx - mic context to check seq against
1476 * micSeq - the Mic seq number
1478 * Returns: TRUE if valid otherwise FALSE.
1480 * Author: sbraneky (10/15/01)
1481 * Merciless hacks by rwilcher (1/14/02)
1482 *---------------------------------------------------------------------------
1485 static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq)
1489 //Allow for the ap being rebooted - if it is then use the next
1490 //sequence number of the current sequence number - might go backwards
1493 if (test_bit(FLAG_UPDATE_MULTI, &ai->flags)) {
1494 clear_bit (FLAG_UPDATE_MULTI, &ai->flags);
1495 context->window = (micSeq > 33) ? micSeq : 33;
1496 context->rx = 0; // Reset rx
1498 } else if (test_bit(FLAG_UPDATE_UNI, &ai->flags)) {
1499 clear_bit (FLAG_UPDATE_UNI, &ai->flags);
1500 context->window = (micSeq > 33) ? micSeq : 33; // Move window
1501 context->rx = 0; // Reset rx
1504 //Make sequence number relative to START of window
1505 seq = micSeq - (context->window - 33);
1507 //Too old of a SEQ number to check.
1512 //Window is infinite forward
1513 MoveWindow(context,micSeq);
1517 // We are in the window. Now check the context rx bit to see if it was already sent
1518 seq >>= 1; //divide by 2 because we only have odd numbers
1519 index = 1 << seq; //Get an index number
1521 if (!(context->rx & index)) {
1522 //micSEQ falls inside the window.
1523 //Add seqence number to the list of received numbers.
1524 context->rx |= index;
1526 MoveWindow(context,micSeq);
1533 static void MoveWindow(miccntx *context, u32 micSeq)
1537 //Move window if seq greater than the middle of the window
1538 if (micSeq > context->window) {
1539 shift = (micSeq - context->window) >> 1;
1543 context->rx >>= shift;
1547 context->window = micSeq; //Move window
1551 /*==============================================*/
1552 /*========== EMMH ROUTINES ====================*/
1553 /*==============================================*/
1555 /* mic accumulate */
1556 #define MIC_ACCUM(val) \
1557 context->accum += (u64)(val) * context->coeff[coeff_position++];
1559 static unsigned char aes_counter[16];
1561 /* expand the key to fill the MMH coefficient array */
1562 void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *tfm)
1564 /* take the keying material, expand if necessary, truncate at 16-bytes */
1565 /* run through AES counter mode to generate context->coeff[] */
1569 u8 *cipher, plain[16];
1570 struct scatterlist sg[1];
1572 crypto_cipher_setkey(tfm, pkey, 16);
1574 for (i = 0; i < (sizeof(context->coeff)/sizeof(context->coeff[0])); ) {
1575 aes_counter[15] = (u8)(counter >> 0);
1576 aes_counter[14] = (u8)(counter >> 8);
1577 aes_counter[13] = (u8)(counter >> 16);
1578 aes_counter[12] = (u8)(counter >> 24);
1580 memcpy (plain, aes_counter, 16);
1581 sg[0].page = virt_to_page(plain);
1582 sg[0].offset = ((long) plain & ~PAGE_MASK);
1584 crypto_cipher_encrypt(tfm, sg, sg, 16);
1585 cipher = kmap(sg[0].page) + sg[0].offset;
1586 for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) {
1587 context->coeff[i++] = ntohl(*(u32 *)&cipher[j]);
1593 /* prepare for calculation of a new mic */
1594 void emmh32_init(emmh32_context *context)
1596 /* prepare for new mic calculation */
1598 context->position = 0;
1601 /* add some bytes to the mic calculation */
1602 void emmh32_update(emmh32_context *context, u8 *pOctets, int len)
1604 int coeff_position, byte_position;
1606 if (len == 0) return;
1608 coeff_position = context->position >> 2;
1610 /* deal with partial 32-bit word left over from last update */
1611 byte_position = context->position & 3;
1612 if (byte_position) {
1613 /* have a partial word in part to deal with */
1615 if (len == 0) return;
1616 context->part.d8[byte_position++] = *pOctets++;
1617 context->position++;
1619 } while (byte_position < 4);
1620 MIC_ACCUM(htonl(context->part.d32));
1623 /* deal with full 32-bit words */
1625 MIC_ACCUM(htonl(*(u32 *)pOctets));
1626 context->position += 4;
1631 /* deal with partial 32-bit word that will be left over from this update */
1634 context->part.d8[byte_position++] = *pOctets++;
1635 context->position++;
1640 /* mask used to zero empty bytes for final partial word */
1641 static u32 mask32[4] = { 0x00000000L, 0xFF000000L, 0xFFFF0000L, 0xFFFFFF00L };
1643 /* calculate the mic */
1644 void emmh32_final(emmh32_context *context, u8 digest[4])
1646 int coeff_position, byte_position;
1652 coeff_position = context->position >> 2;
1654 /* deal with partial 32-bit word left over from last update */
1655 byte_position = context->position & 3;
1656 if (byte_position) {
1657 /* have a partial word in part to deal with */
1658 val = htonl(context->part.d32);
1659 MIC_ACCUM(val & mask32[byte_position]); /* zero empty bytes */
1662 /* reduce the accumulated u64 to a 32-bit MIC */
1663 sum = context->accum;
1664 stmp = (sum & 0xffffffffLL) - ((sum >> 32) * 15);
1665 utmp = (stmp & 0xffffffffLL) - ((stmp >> 32) * 15);
1666 sum = utmp & 0xffffffffLL;
1667 if (utmp > 0x10000000fLL)
1671 digest[0] = (val>>24) & 0xFF;
1672 digest[1] = (val>>16) & 0xFF;
1673 digest[2] = (val>>8) & 0xFF;
1674 digest[3] = val & 0xFF;
1678 static int readBSSListRid(struct airo_info *ai, int first,
1685 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
1686 memset(&cmd, 0, sizeof(cmd));
1687 cmd.cmd=CMD_LISTBSS;
1688 if (down_interruptible(&ai->sem))
1689 return -ERESTARTSYS;
1690 issuecommand(ai, &cmd, &rsp);
1692 /* Let the command take effect */
1693 set_current_state (TASK_INTERRUPTIBLE);
1695 schedule_timeout (3*HZ);
1698 rc = PC4500_readrid(ai, first ? RID_BSSLISTFIRST : RID_BSSLISTNEXT,
1699 list, sizeof(*list), 1);
1701 list->len = le16_to_cpu(list->len);
1702 list->index = le16_to_cpu(list->index);
1703 list->radioType = le16_to_cpu(list->radioType);
1704 list->cap = le16_to_cpu(list->cap);
1705 list->beaconInterval = le16_to_cpu(list->beaconInterval);
1706 list->fh.dwell = le16_to_cpu(list->fh.dwell);
1707 list->dsChannel = le16_to_cpu(list->dsChannel);
1708 list->atimWindow = le16_to_cpu(list->atimWindow);
1712 static int readWepKeyRid(struct airo_info*ai, WepKeyRid *wkr, int temp, int lock) {
1713 int rc = PC4500_readrid(ai, temp ? RID_WEP_TEMP : RID_WEP_PERM,
1714 wkr, sizeof(*wkr), lock);
1716 wkr->len = le16_to_cpu(wkr->len);
1717 wkr->kindex = le16_to_cpu(wkr->kindex);
1718 wkr->klen = le16_to_cpu(wkr->klen);
1721 /* In the writeXXXRid routines we copy the rids so that we don't screwup
1722 * the originals when we endian them... */
1723 static int writeWepKeyRid(struct airo_info*ai, WepKeyRid *pwkr, int perm, int lock) {
1725 WepKeyRid wkr = *pwkr;
1727 wkr.len = cpu_to_le16(wkr.len);
1728 wkr.kindex = cpu_to_le16(wkr.kindex);
1729 wkr.klen = cpu_to_le16(wkr.klen);
1730 rc = PC4500_writerid(ai, RID_WEP_TEMP, &wkr, sizeof(wkr), lock);
1731 if (rc!=SUCCESS) printk(KERN_ERR "airo: WEP_TEMP set %x\n", rc);
1733 rc = PC4500_writerid(ai, RID_WEP_PERM, &wkr, sizeof(wkr), lock);
1735 printk(KERN_ERR "airo: WEP_PERM set %x\n", rc);
1741 static int readSsidRid(struct airo_info*ai, SsidRid *ssidr) {
1743 int rc = PC4500_readrid(ai, RID_SSID, ssidr, sizeof(*ssidr), 1);
1745 ssidr->len = le16_to_cpu(ssidr->len);
1746 for(i = 0; i < 3; i++) {
1747 ssidr->ssids[i].len = le16_to_cpu(ssidr->ssids[i].len);
1751 static int writeSsidRid(struct airo_info*ai, SsidRid *pssidr, int lock) {
1754 SsidRid ssidr = *pssidr;
1756 ssidr.len = cpu_to_le16(ssidr.len);
1757 for(i = 0; i < 3; i++) {
1758 ssidr.ssids[i].len = cpu_to_le16(ssidr.ssids[i].len);
1760 rc = PC4500_writerid(ai, RID_SSID, &ssidr, sizeof(ssidr), lock);
1763 static int readConfigRid(struct airo_info*ai, int lock) {
1771 rc = PC4500_readrid(ai, RID_ACTUALCONFIG, &cfg, sizeof(cfg), lock);
1775 for(s = &cfg.len; s <= &cfg.rtsThres; s++) *s = le16_to_cpu(*s);
1777 for(s = &cfg.shortRetryLimit; s <= &cfg.radioType; s++)
1778 *s = le16_to_cpu(*s);
1780 for(s = &cfg.txPower; s <= &cfg.radioSpecific; s++)
1781 *s = le16_to_cpu(*s);
1783 for(s = &cfg.arlThreshold; s <= &cfg._reserved4[0]; s++)
1784 *s = cpu_to_le16(*s);
1786 for(s = &cfg.autoWake; s <= &cfg.autoWake; s++)
1787 *s = cpu_to_le16(*s);
1792 static inline void checkThrottle(struct airo_info *ai) {
1794 /* Old hardware had a limit on encryption speed */
1795 if (ai->config.authType != AUTH_OPEN && maxencrypt) {
1796 for(i=0; i<8; i++) {
1797 if (ai->config.rates[i] > maxencrypt) {
1798 ai->config.rates[i] = 0;
1803 static int writeConfigRid(struct airo_info*ai, int lock) {
1807 if (!test_bit (FLAG_COMMIT, &ai->flags))
1810 clear_bit (FLAG_COMMIT | FLAG_RESET, &ai->flags);
1814 if ((cfgr.opmode & 0xFF) == MODE_STA_IBSS)
1815 set_bit(FLAG_ADHOC, &ai->flags);
1817 clear_bit(FLAG_ADHOC, &ai->flags);
1819 for(s = &cfgr.len; s <= &cfgr.rtsThres; s++) *s = cpu_to_le16(*s);
1821 for(s = &cfgr.shortRetryLimit; s <= &cfgr.radioType; s++)
1822 *s = cpu_to_le16(*s);
1824 for(s = &cfgr.txPower; s <= &cfgr.radioSpecific; s++)
1825 *s = cpu_to_le16(*s);
1827 for(s = &cfgr.arlThreshold; s <= &cfgr._reserved4[0]; s++)
1828 *s = cpu_to_le16(*s);
1830 for(s = &cfgr.autoWake; s <= &cfgr.autoWake; s++)
1831 *s = cpu_to_le16(*s);
1833 return PC4500_writerid( ai, RID_CONFIG, &cfgr, sizeof(cfgr), lock);
1835 static int readStatusRid(struct airo_info*ai, StatusRid *statr, int lock) {
1836 int rc = PC4500_readrid(ai, RID_STATUS, statr, sizeof(*statr), lock);
1839 statr->len = le16_to_cpu(statr->len);
1840 for(s = &statr->mode; s <= &statr->SSIDlen; s++) *s = le16_to_cpu(*s);
1842 for(s = &statr->beaconPeriod; s <= &statr->shortPreamble; s++)
1843 *s = le16_to_cpu(*s);
1844 statr->load = le16_to_cpu(statr->load);
1845 statr->assocStatus = le16_to_cpu(statr->assocStatus);
1848 static int readAPListRid(struct airo_info*ai, APListRid *aplr) {
1849 int rc = PC4500_readrid(ai, RID_APLIST, aplr, sizeof(*aplr), 1);
1850 aplr->len = le16_to_cpu(aplr->len);
1853 static int writeAPListRid(struct airo_info*ai, APListRid *aplr, int lock) {
1855 aplr->len = cpu_to_le16(aplr->len);
1856 rc = PC4500_writerid(ai, RID_APLIST, aplr, sizeof(*aplr), lock);
1859 static int readCapabilityRid(struct airo_info*ai, CapabilityRid *capr, int lock) {
1860 int rc = PC4500_readrid(ai, RID_CAPABILITIES, capr, sizeof(*capr), lock);
1863 capr->len = le16_to_cpu(capr->len);
1864 capr->prodNum = le16_to_cpu(capr->prodNum);
1865 capr->radioType = le16_to_cpu(capr->radioType);
1866 capr->country = le16_to_cpu(capr->country);
1867 for(s = &capr->txPowerLevels[0]; s <= &capr->requiredHard; s++)
1868 *s = le16_to_cpu(*s);
1871 static int readStatsRid(struct airo_info*ai, StatsRid *sr, int rid, int lock) {
1872 int rc = PC4500_readrid(ai, rid, sr, sizeof(*sr), lock);
1875 sr->len = le16_to_cpu(sr->len);
1876 for(i = &sr->vals[0]; i <= &sr->vals[99]; i++) *i = le32_to_cpu(*i);
1880 static int airo_open(struct net_device *dev) {
1881 struct airo_info *info = dev->priv;
1884 if (test_bit(FLAG_FLASHING, &info->flags))
1887 /* Make sure the card is configured.
1888 * Wireless Extensions may postpone config changes until the card
1889 * is open (to pipeline changes and speed-up card setup). If
1890 * those changes are not yet commited, do it now - Jean II */
1891 if (test_bit (FLAG_COMMIT, &info->flags)) {
1892 disable_MAC(info, 1);
1893 writeConfigRid(info, 1);
1896 if (info->wifidev != dev) {
1897 /* Power on the MAC controller (which may have been disabled) */
1898 clear_bit(FLAG_RADIO_DOWN, &info->flags);
1899 enable_interrupts(info);
1901 enable_MAC(info, &rsp, 1);
1903 netif_start_queue(dev);
1907 static int mpi_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1908 int npacks, pending;
1909 unsigned long flags;
1910 struct airo_info *ai = dev->priv;
1913 printk(KERN_ERR "airo: %s: skb==NULL\n",__FUNCTION__);
1916 npacks = skb_queue_len (&ai->txq);
1918 if (npacks >= MAXTXQ - 1) {
1919 netif_stop_queue (dev);
1920 if (npacks > MAXTXQ) {
1921 ai->stats.tx_fifo_errors++;
1924 skb_queue_tail (&ai->txq, skb);
1928 spin_lock_irqsave(&ai->aux_lock, flags);
1929 skb_queue_tail (&ai->txq, skb);
1930 pending = test_bit(FLAG_PENDING_XMIT, &ai->flags);
1931 spin_unlock_irqrestore(&ai->aux_lock,flags);
1932 netif_wake_queue (dev);
1935 set_bit(FLAG_PENDING_XMIT, &ai->flags);
1936 mpi_send_packet (dev);
1944 * Attempt to transmit a packet. Can be called from interrupt
1945 * or transmit . return number of packets we tried to send
1948 static int mpi_send_packet (struct net_device *dev)
1950 struct sk_buff *skb;
1951 unsigned char *buffer;
1952 s16 len, *payloadLen;
1953 struct airo_info *ai = dev->priv;
1956 /* get a packet to send */
1958 if ((skb = skb_dequeue(&ai->txq)) == 0) {
1960 "airo_mpi: %s: Dequeue'd zero in send_packet()\n",
1965 /* check min length*/
1966 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1969 ai->txfids[0].tx_desc.offset = 0;
1970 ai->txfids[0].tx_desc.valid = 1;
1971 ai->txfids[0].tx_desc.eoc = 1;
1972 ai->txfids[0].tx_desc.len =len+sizeof(WifiHdr);
1974 memcpy((char *)ai->txfids[0].card_ram_off,
1975 (char *)&ai->txfids[0].tx_desc, sizeof(TxFid));
1978 * Magic, the cards firmware needs a length count (2 bytes) in the host buffer
1979 * right after TXFID_HDR.The TXFID_HDR contains the status short so payloadlen
1980 * is immediatly after it. ------------------------------------------------
1981 * |TXFIDHDR+STATUS|PAYLOADLEN|802.3HDR|PACKETDATA|
1982 * ------------------------------------------------
1985 memcpy((char *)ai->txfids[0].virtual_host_addr,
1986 (char *)&wifictlhdr8023, sizeof(wifictlhdr8023));
1988 payloadLen = (s16 *)(ai->txfids[0].virtual_host_addr +
1989 sizeof(wifictlhdr8023));
1990 sendbuf = ai->txfids[0].virtual_host_addr +
1991 sizeof(wifictlhdr8023) + 2 ;
1994 * Firmware automaticly puts 802 header on so
1995 * we don't need to account for it in the length
1998 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
1999 (ntohs(((u16 *)buffer)[6]) != 0x888E)) {
2002 if (encapsulate(ai, (etherHead *)buffer, &pMic, len - sizeof(etherHead)) != SUCCESS)
2005 *payloadLen = cpu_to_le16(len-sizeof(etherHead)+sizeof(pMic));
2006 /* copy data into airo dma buffer */
2007 memcpy (sendbuf, buffer, sizeof(etherHead));
2008 buffer += sizeof(etherHead);
2009 sendbuf += sizeof(etherHead);
2010 memcpy (sendbuf, &pMic, sizeof(pMic));
2011 sendbuf += sizeof(pMic);
2012 memcpy (sendbuf, buffer, len - sizeof(etherHead));
2016 *payloadLen = cpu_to_le16(len - sizeof(etherHead));
2018 dev->trans_start = jiffies;
2020 /* copy data into airo dma buffer */
2021 memcpy(sendbuf, buffer, len);
2024 OUT4500(ai, EVACK, 8);
2026 dev_kfree_skb_any(skb);
2030 static void get_tx_error(struct airo_info *ai, u32 fid)
2035 status = ((WifiCtlHdr *)ai->txfids[0].virtual_host_addr)->ctlhdr.status;
2037 if (bap_setup(ai, ai->fids[fid] & 0xffff, 4, BAP0) != SUCCESS)
2039 bap_read(ai, &status, 2, BAP0);
2041 if (le16_to_cpu(status) & 2) /* Too many retries */
2042 ai->stats.tx_aborted_errors++;
2043 if (le16_to_cpu(status) & 4) /* Transmit lifetime exceeded */
2044 ai->stats.tx_heartbeat_errors++;
2045 if (le16_to_cpu(status) & 8) /* Aid fail */
2047 if (le16_to_cpu(status) & 0x10) /* MAC disabled */
2048 ai->stats.tx_carrier_errors++;
2049 if (le16_to_cpu(status) & 0x20) /* Association lost */
2051 /* We produce a TXDROP event only for retry or lifetime
2052 * exceeded, because that's the only status that really mean
2053 * that this particular node went away.
2054 * Other errors means that *we* screwed up. - Jean II */
2055 if ((le16_to_cpu(status) & 2) ||
2056 (le16_to_cpu(status) & 4)) {
2057 union iwreq_data wrqu;
2060 /* Faster to skip over useless data than to do
2061 * another bap_setup(). We are at offset 0x6 and
2062 * need to go to 0x18 and read 6 bytes - Jean II */
2063 bap_read(ai, (u16 *) junk, 0x18, BAP0);
2065 /* Copy 802.11 dest address.
2066 * We use the 802.11 header because the frame may
2067 * not be 802.3 or may be mangled...
2068 * In Ad-Hoc mode, it will be the node address.
2069 * In managed mode, it will be most likely the AP addr
2070 * User space will figure out how to convert it to
2071 * whatever it needs (IP address or else).
2073 memcpy(wrqu.addr.sa_data, junk + 0x12, ETH_ALEN);
2074 wrqu.addr.sa_family = ARPHRD_ETHER;
2076 /* Send event to user space */
2077 wireless_send_event(ai->dev, IWEVTXDROP, &wrqu, NULL);
2081 static void airo_end_xmit(struct net_device *dev) {
2084 struct airo_info *priv = dev->priv;
2085 struct sk_buff *skb = priv->xmit.skb;
2086 int fid = priv->xmit.fid;
2087 u32 *fids = priv->fids;
2089 clear_bit(JOB_XMIT, &priv->flags);
2090 clear_bit(FLAG_PENDING_XMIT, &priv->flags);
2091 status = transmit_802_3_packet (priv, fids[fid], skb->data);
2095 if ( status == SUCCESS ) {
2096 dev->trans_start = jiffies;
2097 for (; i < MAX_FIDS / 2 && (priv->fids[i] & 0xffff0000); i++);
2099 priv->fids[fid] &= 0xffff;
2100 priv->stats.tx_window_errors++;
2102 if (i < MAX_FIDS / 2)
2103 netif_wake_queue(dev);
2107 static int airo_start_xmit(struct sk_buff *skb, struct net_device *dev) {
2110 struct airo_info *priv = dev->priv;
2111 u32 *fids = priv->fids;
2113 if ( skb == NULL ) {
2114 printk( KERN_ERR "airo: skb == NULL!!!\n" );
2118 /* Find a vacant FID */
2119 for( i = 0; i < MAX_FIDS / 2 && (fids[i] & 0xffff0000); i++ );
2120 for( j = i + 1; j < MAX_FIDS / 2 && (fids[j] & 0xffff0000); j++ );
2122 if ( j >= MAX_FIDS / 2 ) {
2123 netif_stop_queue(dev);
2125 if (i == MAX_FIDS / 2) {
2126 priv->stats.tx_fifo_errors++;
2130 /* check min length*/
2131 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
2132 /* Mark fid as used & save length for later */
2133 fids[i] |= (len << 16);
2134 priv->xmit.skb = skb;
2136 if (down_trylock(&priv->sem) != 0) {
2137 set_bit(FLAG_PENDING_XMIT, &priv->flags);
2138 netif_stop_queue(dev);
2139 set_bit(JOB_XMIT, &priv->flags);
2140 wake_up_interruptible(&priv->thr_wait);
2146 static void airo_end_xmit11(struct net_device *dev) {
2149 struct airo_info *priv = dev->priv;
2150 struct sk_buff *skb = priv->xmit11.skb;
2151 int fid = priv->xmit11.fid;
2152 u32 *fids = priv->fids;
2154 clear_bit(JOB_XMIT11, &priv->flags);
2155 clear_bit(FLAG_PENDING_XMIT11, &priv->flags);
2156 status = transmit_802_11_packet (priv, fids[fid], skb->data);
2160 if ( status == SUCCESS ) {
2161 dev->trans_start = jiffies;
2162 for (; i < MAX_FIDS && (priv->fids[i] & 0xffff0000); i++);
2164 priv->fids[fid] &= 0xffff;
2165 priv->stats.tx_window_errors++;
2168 netif_wake_queue(dev);
2172 static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) {
2175 struct airo_info *priv = dev->priv;
2176 u32 *fids = priv->fids;
2178 if ( skb == NULL ) {
2179 printk( KERN_ERR "airo: skb == NULL!!!\n" );
2183 /* Find a vacant FID */
2184 for( i = MAX_FIDS / 2; i < MAX_FIDS && (fids[i] & 0xffff0000); i++ );
2185 for( j = i + 1; j < MAX_FIDS && (fids[j] & 0xffff0000); j++ );
2187 if ( j >= MAX_FIDS ) {
2188 netif_stop_queue(dev);
2190 if (i == MAX_FIDS) {
2191 priv->stats.tx_fifo_errors++;
2195 /* check min length*/
2196 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
2197 /* Mark fid as used & save length for later */
2198 fids[i] |= (len << 16);
2199 priv->xmit11.skb = skb;
2200 priv->xmit11.fid = i;
2201 if (down_trylock(&priv->sem) != 0) {
2202 set_bit(FLAG_PENDING_XMIT11, &priv->flags);
2203 netif_stop_queue(dev);
2204 set_bit(JOB_XMIT11, &priv->flags);
2205 wake_up_interruptible(&priv->thr_wait);
2207 airo_end_xmit11(dev);
2211 static void airo_read_stats(struct airo_info *ai) {
2213 u32 *vals = stats_rid.vals;
2215 clear_bit(JOB_STATS, &ai->flags);
2220 readStatsRid(ai, &stats_rid, RID_STATS, 0);
2223 ai->stats.rx_packets = vals[43] + vals[44] + vals[45];
2224 ai->stats.tx_packets = vals[39] + vals[40] + vals[41];
2225 ai->stats.rx_bytes = vals[92];
2226 ai->stats.tx_bytes = vals[91];
2227 ai->stats.rx_errors = vals[0] + vals[2] + vals[3] + vals[4];
2228 ai->stats.tx_errors = vals[42] + ai->stats.tx_fifo_errors;
2229 ai->stats.multicast = vals[43];
2230 ai->stats.collisions = vals[89];
2232 /* detailed rx_errors: */
2233 ai->stats.rx_length_errors = vals[3];
2234 ai->stats.rx_crc_errors = vals[4];
2235 ai->stats.rx_frame_errors = vals[2];
2236 ai->stats.rx_fifo_errors = vals[0];
2239 struct net_device_stats *airo_get_stats(struct net_device *dev)
2241 struct airo_info *local = dev->priv;
2243 /* Get stats out of the card if available */
2244 if (down_trylock(&local->sem) != 0) {
2245 set_bit(JOB_STATS, &local->flags);
2246 wake_up_interruptible(&local->thr_wait);
2248 airo_read_stats(local);
2250 return &local->stats;
2253 static void airo_set_promisc(struct airo_info *ai) {
2257 memset(&cmd, 0, sizeof(cmd));
2258 cmd.cmd=CMD_SETMODE;
2259 clear_bit(JOB_PROMISC, &ai->flags);
2260 cmd.parm0=(ai->flags&IFF_PROMISC) ? PROMISC : NOPROMISC;
2261 issuecommand(ai, &cmd, &rsp);
2265 static void airo_set_multicast_list(struct net_device *dev) {
2266 struct airo_info *ai = dev->priv;
2268 if ((dev->flags ^ ai->flags) & IFF_PROMISC) {
2269 change_bit(FLAG_PROMISC, &ai->flags);
2270 if (down_trylock(&ai->sem) != 0) {
2271 set_bit(JOB_PROMISC, &ai->flags);
2272 wake_up_interruptible(&ai->thr_wait);
2274 airo_set_promisc(ai);
2277 if ((dev->flags&IFF_ALLMULTI)||dev->mc_count>0) {
2278 /* Turn on multicast. (Should be already setup...) */
2282 static int airo_set_mac_address(struct net_device *dev, void *p)
2284 struct airo_info *ai = dev->priv;
2285 struct sockaddr *addr = p;
2288 readConfigRid(ai, 1);
2289 memcpy (ai->config.macAddr, addr->sa_data, dev->addr_len);
2290 set_bit (FLAG_COMMIT, &ai->flags);
2292 writeConfigRid (ai, 1);
2293 enable_MAC(ai, &rsp, 1);
2294 memcpy (ai->dev->dev_addr, addr->sa_data, dev->addr_len);
2296 memcpy (ai->wifidev->dev_addr, addr->sa_data, dev->addr_len);
2300 static int airo_change_mtu(struct net_device *dev, int new_mtu)
2302 if ((new_mtu < 68) || (new_mtu > 2400))
2309 static int airo_close(struct net_device *dev) {
2310 struct airo_info *ai = dev->priv;
2312 netif_stop_queue(dev);
2314 if (ai->wifidev != dev) {
2315 #ifdef POWER_ON_DOWN
2316 /* Shut power to the card. The idea is that the user can save
2317 * power when he doesn't need the card with "ifconfig down".
2318 * That's the method that is most friendly towards the network
2319 * stack (i.e. the network stack won't try to broadcast
2320 * anything on the interface and routes are gone. Jean II */
2321 set_bit(FLAG_RADIO_DOWN, &ai->flags);
2324 disable_interrupts( ai );
2329 static void del_airo_dev( struct net_device *dev );
2331 void stop_airo_card( struct net_device *dev, int freeres )
2333 struct airo_info *ai = dev->priv;
2334 disable_interrupts(ai);
2335 free_irq( dev->irq, dev );
2336 takedown_proc_entry( dev, ai );
2337 if (test_bit(FLAG_REGISTERED, &ai->flags)) {
2338 unregister_netdev( dev );
2340 unregister_netdev(ai->wifidev);
2341 free_netdev(ai->wifidev);
2344 clear_bit(FLAG_REGISTERED, &ai->flags);
2346 set_bit(JOB_DIE, &ai->flags);
2347 kill_proc(ai->thr_pid, SIGTERM, 1);
2348 wait_for_completion(&ai->thr_exited);
2351 * Clean out tx queue
2353 if (test_bit(FLAG_MPI, &ai->flags) && skb_queue_len (&ai->txq) > 0) {
2354 struct sk_buff *skb = 0;
2355 for (;(skb = skb_dequeue(&ai->txq));)
2368 /* PCMCIA frees this stuff, so only for PCI and ISA */
2369 release_region( dev->base_addr, 64 );
2370 if (test_bit(FLAG_MPI, &ai->flags)) {
2372 mpi_unmap_card(ai->pci);
2374 iounmap(ai->pcimem);
2376 iounmap(ai->pciaux);
2377 pci_free_consistent(ai->pci, PCI_SHARED_LEN,
2378 ai->shared, ai->shared_dma);
2383 crypto_free_tfm(ai->tfm);
2385 del_airo_dev( dev );
2389 EXPORT_SYMBOL(stop_airo_card);
2391 static int add_airo_dev( struct net_device *dev );
2393 int wll_header_parse(struct sk_buff *skb, unsigned char *haddr)
2395 memcpy(haddr, skb->mac.raw + 10, ETH_ALEN);
2399 static void mpi_unmap_card(struct pci_dev *pci)
2401 unsigned long mem_start = pci_resource_start(pci, 1);
2402 unsigned long mem_len = pci_resource_len(pci, 1);
2403 unsigned long aux_start = pci_resource_start(pci, 2);
2404 unsigned long aux_len = AUXMEMSIZE;
2406 release_mem_region(aux_start, aux_len);
2407 release_mem_region(mem_start, mem_len);
2410 /*************************************************************
2411 * This routine assumes that descriptors have been setup .
2412 * Run at insmod time or after reset when the decriptors
2413 * have been initialized . Returns 0 if all is well nz
2414 * otherwise . Does not allocate memory but sets up card
2415 * using previously allocated descriptors.
2417 static int mpi_init_descriptors (struct airo_info *ai)
2424 /* Alloc card RX descriptors */
2425 netif_stop_queue(ai->dev);
2427 memset(&rsp,0,sizeof(rsp));
2428 memset(&cmd,0,sizeof(cmd));
2430 cmd.cmd = CMD_ALLOCATEAUX;
2432 cmd.parm1 = (ai->rxfids[0].card_ram_off - ai->pciaux);
2433 cmd.parm2 = MPI_MAX_FIDS;
2434 rc=issuecommand(ai, &cmd, &rsp);
2435 if (rc != SUCCESS) {
2436 printk(KERN_ERR "airo: Couldn't allocate RX FID\n");
2440 for (i=0; i<MPI_MAX_FIDS; i++) {
2441 memcpy(ai->rxfids[i].card_ram_off,
2442 &ai->rxfids[i].rx_desc, sizeof(RxFid));
2445 /* Alloc card TX descriptors */
2447 memset(&rsp,0,sizeof(rsp));
2448 memset(&cmd,0,sizeof(cmd));
2450 cmd.cmd = CMD_ALLOCATEAUX;
2452 cmd.parm1 = (ai->txfids[0].card_ram_off - ai->pciaux);
2453 cmd.parm2 = MPI_MAX_FIDS;
2454 rc=issuecommand(ai, &cmd, &rsp);
2455 if (rc != SUCCESS) {
2456 printk(KERN_ERR "airo: Couldn't allocate TX FID\n");
2460 for (i=0; i<MPI_MAX_FIDS; i++) {
2461 ai->txfids[i].tx_desc.valid = 1;
2462 memcpy((char *)ai->txfids[i].card_ram_off,
2463 &ai->txfids[i].tx_desc, sizeof(TxFid));
2466 /* Alloc card Rid descriptor */
2467 memset(&rsp,0,sizeof(rsp));
2468 memset(&cmd,0,sizeof(cmd));
2470 cmd.cmd = CMD_ALLOCATEAUX;
2472 cmd.parm1 = (ai->config_desc.card_ram_off - ai->pciaux);
2473 cmd.parm2 = 1; /* Magic number... */
2474 rc=issuecommand(ai, &cmd, &rsp);
2475 if (rc != SUCCESS) {
2476 printk(KERN_ERR "airo: Couldn't allocate RID\n");
2480 memcpy((char *)ai->config_desc.card_ram_off,
2481 (char *)&ai->config_desc.rid_desc, sizeof(Rid));
2487 * We are setting up three things here:
2488 * 1) Map AUX memory for descriptors: Rid, TxFid, or RxFid.
2489 * 2) Map PCI memory for issueing commands.
2490 * 3) Allocate memory (shared) to send and receive ethernet frames.
2492 static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci,
2495 unsigned long mem_start, mem_len, aux_start, aux_len;
2498 unsigned char *busaddroff,*vpackoff;
2499 unsigned char *pciaddroff;
2501 mem_start = pci_resource_start(pci, 1);
2502 mem_len = pci_resource_len(pci, 1);
2503 aux_start = pci_resource_start(pci, 2);
2504 aux_len = AUXMEMSIZE;
2506 if (!request_mem_region(mem_start, mem_len, name)) {
2507 printk(KERN_ERR "airo: Couldn't get region %x[%x] for %s\n",
2508 (int)mem_start, (int)mem_len, name);
2511 if (!request_mem_region(aux_start, aux_len, name)) {
2512 printk(KERN_ERR "airo: Couldn't get region %x[%x] for %s\n",
2513 (int)aux_start, (int)aux_len, name);
2517 ai->pcimem = ioremap(mem_start, mem_len);
2519 printk(KERN_ERR "airo: Couldn't map region %x[%x] for %s\n",
2520 (int)mem_start, (int)mem_len, name);
2523 ai->pciaux = ioremap(aux_start, aux_len);
2525 printk(KERN_ERR "airo: Couldn't map region %x[%x] for %s\n",
2526 (int)aux_start, (int)aux_len, name);
2530 /* Reserve PKTSIZE for each fid and 2K for the Rids */
2531 ai->shared = pci_alloc_consistent(pci, PCI_SHARED_LEN, &ai->shared_dma);
2533 printk(KERN_ERR "airo: Couldn't alloc_consistent %d\n",
2539 * Setup descriptor RX, TX, CONFIG
2541 busaddroff = (unsigned char *)ai->shared_dma;
2542 pciaddroff = ai->pciaux + AUX_OFFSET;
2543 vpackoff = ai->shared;
2545 /* RX descriptor setup */
2546 for(i = 0; i < MPI_MAX_FIDS; i++) {
2547 ai->rxfids[i].pending = 0;
2548 ai->rxfids[i].card_ram_off = pciaddroff;
2549 ai->rxfids[i].virtual_host_addr = vpackoff;
2550 ai->rxfids[i].rx_desc.host_addr = (dma_addr_t) busaddroff;
2551 ai->rxfids[i].rx_desc.valid = 1;
2552 ai->rxfids[i].rx_desc.len = PKTSIZE;
2553 ai->rxfids[i].rx_desc.rdy = 0;
2555 pciaddroff += sizeof(RxFid);
2556 busaddroff += PKTSIZE;
2557 vpackoff += PKTSIZE;
2560 /* TX descriptor setup */
2561 for(i = 0; i < MPI_MAX_FIDS; i++) {
2562 ai->txfids[i].card_ram_off = pciaddroff;
2563 ai->txfids[i].virtual_host_addr = vpackoff;
2564 ai->txfids[i].tx_desc.valid = 1;
2565 ai->txfids[i].tx_desc.host_addr = (dma_addr_t) busaddroff;
2566 memcpy(ai->txfids[i].virtual_host_addr,
2567 &wifictlhdr8023, sizeof(wifictlhdr8023));
2569 pciaddroff += sizeof(TxFid);
2570 busaddroff += PKTSIZE;
2571 vpackoff += PKTSIZE;
2573 ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */
2575 /* Rid descriptor setup */
2576 ai->config_desc.card_ram_off = pciaddroff;
2577 ai->config_desc.virtual_host_addr = vpackoff;
2578 ai->config_desc.rid_desc.host_addr = (dma_addr_t) busaddroff;
2579 ai->ridbus = (dma_addr_t)busaddroff;
2580 ai->config_desc.rid_desc.rid = 0;
2581 ai->config_desc.rid_desc.len = RIDSIZE;
2582 ai->config_desc.rid_desc.valid = 1;
2583 pciaddroff += sizeof(Rid);
2584 busaddroff += RIDSIZE;
2585 vpackoff += RIDSIZE;
2587 /* Tell card about descriptors */
2588 if (mpi_init_descriptors (ai) != SUCCESS)
2593 pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
2595 iounmap(ai->pciaux);
2597 iounmap(ai->pcimem);
2599 release_mem_region(aux_start, aux_len);
2601 release_mem_region(mem_start, mem_len);
2606 static void wifi_setup(struct net_device *dev)
2608 dev->hard_header = 0;
2609 dev->rebuild_header = 0;
2610 dev->hard_header_cache = 0;
2611 dev->header_cache_update= 0;
2613 dev->hard_header_parse = wll_header_parse;
2614 dev->hard_start_xmit = &airo_start_xmit11;
2615 dev->get_stats = &airo_get_stats;
2616 dev->set_mac_address = &airo_set_mac_address;
2617 dev->do_ioctl = &airo_ioctl;
2619 dev->get_wireless_stats = airo_get_wireless_stats;
2620 dev->wireless_handlers = (struct iw_handler_def *)&airo_handler_def;
2621 #endif /* WIRELESS_EXT */
2622 dev->change_mtu = &airo_change_mtu;
2623 dev->open = &airo_open;
2624 dev->stop = &airo_close;
2626 dev->type = ARPHRD_IEEE80211;
2627 dev->hard_header_len = ETH_HLEN;
2629 dev->addr_len = ETH_ALEN;
2630 dev->tx_queue_len = 100;
2632 memset(dev->broadcast,0xFF, ETH_ALEN);
2634 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2637 static struct net_device *init_wifidev(struct airo_info *ai,
2638 struct net_device *ethdev)
2641 struct net_device *dev = alloc_netdev(0, "wifi%d", wifi_setup);
2644 dev->priv = ethdev->priv;
2645 dev->irq = ethdev->irq;
2646 dev->base_addr = ethdev->base_addr;
2647 memcpy(dev->dev_addr, ethdev->dev_addr, dev->addr_len);
2648 err = register_netdev(dev);
2656 int reset_mpi_card( struct net_device *dev , int lock) {
2657 struct airo_info *ai = dev->priv;
2659 if (lock && down_interruptible(&ai->sem))
2662 OUT4500(ai,COMMAND,CMD_SOFTRESET);
2663 set_current_state (TASK_UNINTERRUPTIBLE);
2664 schedule_timeout (HZ/5);
2666 set_current_state (TASK_UNINTERRUPTIBLE);
2667 schedule_timeout (HZ/5);
2673 struct net_device *_init_airo_card( unsigned short irq, int port,
2674 int is_pcmcia, struct pci_dev *pci )
2676 struct net_device *dev;
2677 struct airo_info *ai;
2680 /* Create the network device object. */
2681 dev = alloc_etherdev(sizeof(*ai));
2683 printk(KERN_ERR "airo: Couldn't alloc_etherdev\n");
2686 if (dev_alloc_name(dev, dev->name) < 0) {
2687 printk(KERN_ERR "airo: Couldn't get name!\n");
2694 if (pci && (pci->device == 0x5000 || pci->device == 0xa504)) {
2695 printk(KERN_DEBUG "airo: Found an MPI350 card\n");
2696 set_bit(FLAG_MPI, &ai->flags);
2699 ai->aux_lock = SPIN_LOCK_UNLOCKED;
2700 sema_init(&ai->sem, 1);
2703 init_waitqueue_head (&ai->thr_wait);
2704 init_completion (&ai->thr_exited);
2705 ai->thr_pid = kernel_thread(airo_thread, dev, CLONE_FS | CLONE_FILES);
2706 if (ai->thr_pid < 0)
2711 rc = add_airo_dev( dev );
2715 /* The Airo-specific entries in the device structure. */
2716 if (test_bit(FLAG_MPI,&ai->flags)) {
2717 skb_queue_head_init (&ai->txq);
2718 dev->hard_start_xmit = &mpi_start_xmit;
2720 dev->hard_start_xmit = &airo_start_xmit;
2721 dev->get_stats = &airo_get_stats;
2722 dev->set_multicast_list = &airo_set_multicast_list;
2723 dev->set_mac_address = &airo_set_mac_address;
2724 dev->do_ioctl = &airo_ioctl;
2726 dev->get_wireless_stats = airo_get_wireless_stats;
2727 dev->wireless_handlers = (struct iw_handler_def *)&airo_handler_def;
2728 #endif /* WIRELESS_EXT */
2729 dev->change_mtu = &airo_change_mtu;
2730 dev->open = &airo_open;
2731 dev->stop = &airo_close;
2733 dev->base_addr = port;
2735 /* what is with PCMCIA ??? */
2737 SET_NETDEV_DEV(dev, &pci->dev);
2740 if (test_bit(FLAG_MPI,&ai->flags))
2741 reset_mpi_card (dev, 1);
2743 rc = request_irq( dev->irq, airo_interrupt, SA_SHIRQ, dev->name, dev );
2745 printk(KERN_ERR "airo: register interrupt %d failed, rc %d\n", irq, rc );
2746 goto err_out_unlink;
2749 if (!request_region( dev->base_addr, 64, dev->name )) {
2751 printk(KERN_ERR "airo: Couldn't request region\n");
2756 if (test_bit(FLAG_MPI,&ai->flags)) {
2757 if (mpi_map_card(ai, pci, dev->name)) {
2758 printk(KERN_ERR "airo: Could not map memory\n");
2764 if ( setup_card( ai, dev->dev_addr, 1 ) != SUCCESS ) {
2765 printk( KERN_ERR "airo: MAC could not be enabled\n" );
2769 } else if (!test_bit(FLAG_MPI,&ai->flags)) {
2770 ai->bap_read = fast_bap_read;
2771 set_bit(FLAG_FLASHING, &ai->flags);
2774 rc = register_netdev(dev);
2776 printk(KERN_ERR "airo: Couldn't register_netdev\n");
2779 if (!test_bit(FLAG_MPI,&ai->flags))
2780 ai->wifidev = init_wifidev(ai, dev);
2782 set_bit(FLAG_REGISTERED,&ai->flags);
2783 printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%x\n",
2785 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
2786 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5] );
2788 /* Allocate the transmit buffers */
2789 if (probe && !test_bit(FLAG_MPI,&ai->flags))
2790 for( i = 0; i < MAX_FIDS; i++ )
2791 ai->fids[i] = transmit_allocate(ai,2312,i>=MAX_FIDS/2);
2793 setup_proc_entry( dev, dev->priv ); /* XXX check for failure */
2794 netif_start_queue(dev);
2795 SET_MODULE_OWNER(dev);
2799 if (test_bit(FLAG_MPI,&ai->flags) && pci) {
2800 pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
2801 iounmap(ai->pciaux);
2802 iounmap(ai->pcimem);
2803 mpi_unmap_card(ai->pci);
2807 release_region( dev->base_addr, 64 );
2809 free_irq(dev->irq, dev);
2813 set_bit(JOB_DIE, &ai->flags);
2814 kill_proc(ai->thr_pid, SIGTERM, 1);
2815 wait_for_completion(&ai->thr_exited);
2821 struct net_device *init_airo_card( unsigned short irq, int port, int is_pcmcia )
2823 return _init_airo_card ( irq, port, is_pcmcia, 0);
2826 EXPORT_SYMBOL(init_airo_card);
2828 static int waitbusy (struct airo_info *ai) {
2830 while ((IN4500 (ai, COMMAND) & COMMAND_BUSY) & (delay < 10000)) {
2832 if ((++delay % 20) == 0)
2833 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
2835 return delay < 10000;
2838 int reset_airo_card( struct net_device *dev )
2841 struct airo_info *ai = dev->priv;
2843 if (reset_mpi_card (dev, 1))
2846 if ( setup_card(ai, dev->dev_addr, 1 ) != SUCCESS ) {
2847 printk( KERN_ERR "airo: MAC could not be enabled\n" );
2850 printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%x\n", dev->name,
2851 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
2852 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
2853 /* Allocate the transmit buffers if needed */
2854 if (!test_bit(FLAG_MPI,&ai->flags))
2855 for( i = 0; i < MAX_FIDS; i++ )
2856 ai->fids[i] = transmit_allocate (ai,2312,i>=MAX_FIDS/2);
2858 enable_interrupts( ai );
2859 netif_wake_queue(dev);
2863 EXPORT_SYMBOL(reset_airo_card);
2865 static void airo_send_event(struct net_device *dev) {
2866 struct airo_info *ai = dev->priv;
2867 union iwreq_data wrqu;
2868 StatusRid status_rid;
2870 clear_bit(JOB_EVENT, &ai->flags);
2871 PC4500_readrid(ai, RID_STATUS, &status_rid, sizeof(status_rid), 0);
2873 wrqu.data.length = 0;
2874 wrqu.data.flags = 0;
2875 memcpy(wrqu.ap_addr.sa_data, status_rid.bssid[0], ETH_ALEN);
2876 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
2878 /* Send event to user space */
2879 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
2882 static int airo_thread(void *data) {
2883 struct net_device *dev = data;
2884 struct airo_info *ai = dev->priv;
2887 daemonize("%s", dev->name);
2888 allow_signal(SIGTERM);
2891 if (signal_pending(current))
2892 flush_signals(current);
2894 /* make swsusp happy with our thread */
2895 if (current->flags & PF_FREEZE)
2896 refrigerator(PF_FREEZE);
2898 if (test_bit(JOB_DIE, &ai->flags))
2901 if (ai->flags & JOB_MASK) {
2902 locked = down_interruptible(&ai->sem);
2906 init_waitqueue_entry(&wait, current);
2907 add_wait_queue(&ai->thr_wait, &wait);
2909 set_current_state(TASK_INTERRUPTIBLE);
2910 if (ai->flags & JOB_MASK)
2913 if (time_after_eq(jiffies,ai->expires)){
2914 set_bit(JOB_AUTOWEP,&ai->flags);
2917 if (!signal_pending(current)) {
2918 schedule_timeout(ai->expires - jiffies);
2921 } else if (!signal_pending(current)) {
2927 current->state = TASK_RUNNING;
2928 remove_wait_queue(&ai->thr_wait, &wait);
2935 if (test_bit(JOB_DIE, &ai->flags)) {
2940 if (ai->power || test_bit(FLAG_FLASHING, &ai->flags)) {
2945 if (test_bit(JOB_XMIT, &ai->flags))
2947 else if (test_bit(JOB_XMIT11, &ai->flags))
2948 airo_end_xmit11(dev);
2949 else if (test_bit(JOB_STATS, &ai->flags))
2950 airo_read_stats(ai);
2951 else if (test_bit(JOB_WSTATS, &ai->flags))
2952 airo_read_wireless_stats(ai);
2953 else if (test_bit(JOB_PROMISC, &ai->flags))
2954 airo_set_promisc(ai);
2956 else if (test_bit(JOB_MIC, &ai->flags))
2959 else if (test_bit(JOB_EVENT, &ai->flags))
2960 airo_send_event(dev);
2961 else if (test_bit(JOB_AUTOWEP, &ai->flags))
2964 complete_and_exit (&ai->thr_exited, 0);
2967 static irqreturn_t airo_interrupt ( int irq, void* dev_id, struct pt_regs *regs) {
2968 struct net_device *dev = (struct net_device *)dev_id;
2971 struct airo_info *apriv = dev->priv;
2972 u16 savedInterrupts = 0;
2975 if (!netif_device_present(dev))
2979 status = IN4500( apriv, EVSTAT );
2980 if ( !(status & STATUS_INTS) || status == 0xffff ) break;
2984 if ( status & EV_AWAKE ) {
2985 OUT4500( apriv, EVACK, EV_AWAKE );
2986 OUT4500( apriv, EVACK, EV_AWAKE );
2989 if (!savedInterrupts) {
2990 savedInterrupts = IN4500( apriv, EVINTEN );
2991 OUT4500( apriv, EVINTEN, 0 );
2994 if ( status & EV_MIC ) {
2995 OUT4500( apriv, EVACK, EV_MIC );
2997 if (test_bit(FLAG_MIC_CAPABLE, &apriv->flags)) {
2998 set_bit(JOB_MIC, &apriv->flags);
2999 wake_up_interruptible(&apriv->thr_wait);
3003 if ( status & EV_LINK ) {
3004 union iwreq_data wrqu;
3005 /* The link status has changed, if you want to put a
3006 monitor hook in, do it here. (Remember that
3007 interrupts are still disabled!)
3009 u16 newStatus = IN4500(apriv, LINKSTAT);
3010 OUT4500( apriv, EVACK, EV_LINK);
3011 /* Here is what newStatus means: */
3012 #define NOBEACON 0x8000 /* Loss of sync - missed beacons */
3013 #define MAXRETRIES 0x8001 /* Loss of sync - max retries */
3014 #define MAXARL 0x8002 /* Loss of sync - average retry level exceeded*/
3015 #define FORCELOSS 0x8003 /* Loss of sync - host request */
3016 #define TSFSYNC 0x8004 /* Loss of sync - TSF synchronization */
3017 #define DEAUTH 0x8100 /* Deauthentication (low byte is reason code) */
3018 #define DISASS 0x8200 /* Disassociation (low byte is reason code) */
3019 #define ASSFAIL 0x8400 /* Association failure (low byte is reason
3021 #define AUTHFAIL 0x0300 /* Authentication failure (low byte is reason
3023 #define ASSOCIATED 0x0400 /* Assocatied */
3024 #define RC_RESERVED 0 /* Reserved return code */
3025 #define RC_NOREASON 1 /* Unspecified reason */
3026 #define RC_AUTHINV 2 /* Previous authentication invalid */
3027 #define RC_DEAUTH 3 /* Deauthenticated because sending station is
3029 #define RC_NOACT 4 /* Disassociated due to inactivity */
3030 #define RC_MAXLOAD 5 /* Disassociated because AP is unable to handle
3031 all currently associated stations */
3032 #define RC_BADCLASS2 6 /* Class 2 frame received from
3033 non-Authenticated station */
3034 #define RC_BADCLASS3 7 /* Class 3 frame received from
3035 non-Associated station */
3036 #define RC_STATLEAVE 8 /* Disassociated because sending station is
3038 #define RC_NOAUTH 9 /* Station requesting (Re)Association is not
3039 Authenticated with the responding station */
3040 if (newStatus != ASSOCIATED) {
3041 if (auto_wep && !apriv->expires) {
3042 apriv->expires = RUN_AT(3*HZ);
3043 wake_up_interruptible(&apriv->thr_wait);
3046 struct task_struct *task = apriv->task;
3050 wake_up_process (task);
3051 set_bit(FLAG_UPDATE_UNI, &apriv->flags);
3052 set_bit(FLAG_UPDATE_MULTI, &apriv->flags);
3054 /* Question : is ASSOCIATED the only status
3055 * that is valid ? We want to catch handover
3056 * and reassociations as valid status
3058 if(newStatus == ASSOCIATED) {
3059 if (apriv->scan_timestamp) {
3060 /* Send an empty event to user space.
3061 * We don't send the received data on
3062 * the event because it would require
3063 * us to do complex transcoding, and
3064 * we want to minimise the work done in
3065 * the irq handler. Use a request to
3066 * extract the data - Jean II */
3067 wrqu.data.length = 0;
3068 wrqu.data.flags = 0;
3069 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
3070 apriv->scan_timestamp = 0;
3072 if (down_trylock(&apriv->sem) != 0) {
3073 set_bit(JOB_EVENT, &apriv->flags);
3074 wake_up_interruptible(&apriv->thr_wait);
3076 airo_send_event(dev);
3078 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
3079 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3081 /* Send event to user space */
3082 wireless_send_event(dev, SIOCGIWAP, &wrqu,NULL);
3086 /* Check to see if there is something to receive */
3087 if ( status & EV_RX ) {
3088 struct sk_buff *skb = NULL;
3089 u16 fc, len, hdrlen = 0;
3103 if (test_bit(FLAG_MPI,&apriv->flags)) {
3104 mpi_receive_802_3(apriv);
3105 OUT4500(apriv, EVACK, EV_RX);
3109 fid = IN4500( apriv, RXFID );
3111 /* Get the packet length */
3112 if (test_bit(FLAG_802_11, &apriv->flags)) {
3113 bap_setup (apriv, fid, 4, BAP0);
3114 bap_read (apriv, (u16*)&hdr, sizeof(hdr), BAP0);
3115 /* Bad CRC. Ignore packet */
3116 if (le16_to_cpu(hdr.status) & 2)
3118 if (apriv->wifidev == NULL)
3121 bap_setup (apriv, fid, 0x36, BAP0);
3122 bap_read (apriv, (u16*)&hdr.len, 2, BAP0);
3124 len = le16_to_cpu(hdr.len);
3127 printk( KERN_ERR "airo: Bad size %d\n", len );
3133 if (test_bit(FLAG_802_11, &apriv->flags)) {
3134 bap_read (apriv, (u16*)&fc, sizeof(fc), BAP0);
3135 fc = le16_to_cpu(fc);
3138 if ((fc & 0xe0) == 0xc0)
3144 if ((fc&0x300)==0x300){
3152 hdrlen = ETH_ALEN * 2;
3154 skb = dev_alloc_skb( len + hdrlen + 2 );
3156 apriv->stats.rx_dropped++;
3159 buffer = (u16*)skb_put (skb, len + hdrlen);
3160 if (test_bit(FLAG_802_11, &apriv->flags)) {
3162 bap_read (apriv, buffer + 1, hdrlen - 2, BAP0);
3164 bap_read (apriv, tmpbuf, 6, BAP0);
3166 bap_read (apriv, &gap, sizeof(gap), BAP0);
3167 gap = le16_to_cpu(gap);
3170 bap_read (apriv, tmpbuf, gap, BAP0);
3172 printk(KERN_ERR "airo: gaplen too big. Problems will follow...\n");
3174 bap_read (apriv, buffer + hdrlen/2, len, BAP0);
3179 bap_read (apriv, buffer, ETH_ALEN*2, BAP0);
3181 if (apriv->micstats.enabled) {
3182 bap_read (apriv,(u16*)&micbuf,sizeof(micbuf),BAP0);
3183 if (ntohs(micbuf.typelen) > 0x05DC)
3184 bap_setup (apriv, fid, 0x44, BAP0);
3186 if (len <= sizeof(micbuf))
3189 len -= sizeof(micbuf);
3190 skb_trim (skb, len + hdrlen);
3194 bap_read(apriv,buffer+ETH_ALEN,len,BAP0);
3196 if (decapsulate(apriv,&micbuf,(etherHead*)buffer,len)) {
3198 dev_kfree_skb_irq (skb);
3203 OUT4500( apriv, EVACK, EV_RX);
3207 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
3208 if (apriv->spy_data.spy_number > 0) {
3210 struct iw_quality wstats;
3211 /* Prepare spy data : addr + qual */
3212 if (!test_bit(FLAG_802_11, &apriv->flags)) {
3213 sa = (char*)buffer + 6;
3214 bap_setup (apriv, fid, 8, BAP0);
3215 bap_read (apriv, (u16*)hdr.rssi, 2, BAP0);
3217 sa = (char*)buffer + 10;
3218 wstats.qual = hdr.rssi[0];
3220 wstats.level = 0x100 - apriv->rssi[hdr.rssi[1]].rssidBm;
3222 wstats.level = (hdr.rssi[1] + 321) / 2;
3224 /* Update spy records */
3225 wireless_spy_update(dev, sa, &wstats);
3227 #endif /* IW_WIRELESS_SPY */
3228 OUT4500( apriv, EVACK, EV_RX);
3230 if (test_bit(FLAG_802_11, &apriv->flags)) {
3231 skb->mac.raw = skb->data;
3232 skb->pkt_type = PACKET_OTHERHOST;
3233 skb->dev = apriv->wifidev;
3234 skb->protocol = htons(ETH_P_802_2);
3237 skb->protocol = eth_type_trans(skb,dev);
3239 skb->dev->last_rx = jiffies;
3240 skb->ip_summed = CHECKSUM_NONE;
3246 /* Check to see if a packet has been transmitted */
3247 if ( status & ( EV_TX|EV_TXCPY|EV_TXEXC ) ) {
3252 if (test_bit(FLAG_MPI,&apriv->flags)) {
3253 unsigned long flags;
3255 if (status & EV_TXEXC)
3256 get_tx_error(apriv, -1);
3257 spin_lock_irqsave(&apriv->aux_lock, flags);
3258 if (skb_queue_len (&apriv->txq)) {
3259 spin_unlock_irqrestore(&apriv->aux_lock,flags);
3260 mpi_send_packet (dev);
3262 clear_bit(FLAG_PENDING_XMIT, &apriv->flags);
3263 spin_unlock_irqrestore(&apriv->aux_lock,flags);
3264 netif_wake_queue (dev);
3266 OUT4500( apriv, EVACK,
3267 status & (EV_TX|EV_TXCPY|EV_TXEXC));
3271 fid = IN4500(apriv, TXCOMPLFID);
3273 for( i = 0; i < MAX_FIDS; i++ ) {
3274 if ( ( apriv->fids[i] & 0xffff ) == fid ) {
3275 len = apriv->fids[i] >> 16;
3280 if (status & EV_TXEXC)
3281 get_tx_error(apriv, index);
3282 OUT4500( apriv, EVACK, status & (EV_TX | EV_TXEXC));
3283 /* Set up to be used again */
3284 apriv->fids[index] &= 0xffff;
3285 if (index < MAX_FIDS / 2) {
3286 if (!test_bit(FLAG_PENDING_XMIT, &apriv->flags))
3287 netif_wake_queue(dev);
3289 if (!test_bit(FLAG_PENDING_XMIT11, &apriv->flags))
3290 netif_wake_queue(apriv->wifidev);
3293 OUT4500( apriv, EVACK, status & (EV_TX | EV_TXCPY | EV_TXEXC));
3294 printk( KERN_ERR "airo: Unallocated FID was used to xmit\n" );
3298 if ( status & ~STATUS_INTS & ~IGNORE_INTS )
3299 printk( KERN_WARNING "airo: Got weird status %x\n",
3300 status & ~STATUS_INTS & ~IGNORE_INTS );
3303 if (savedInterrupts)
3304 OUT4500( apriv, EVINTEN, savedInterrupts );
3307 return IRQ_RETVAL(handled);
3311 * Routines to talk to the card
3315 * This was originally written for the 4500, hence the name
3316 * NOTE: If use with 8bit mode and SMP bad things will happen!
3317 * Why would some one do 8 bit IO in an SMP machine?!?
3319 static void OUT4500( struct airo_info *ai, u16 reg, u16 val ) {
3320 if (test_bit(FLAG_MPI,&ai->flags))
3323 outw( val, ai->dev->base_addr + reg );
3325 outb( val & 0xff, ai->dev->base_addr + reg );
3326 outb( val >> 8, ai->dev->base_addr + reg + 1 );
3330 static u16 IN4500( struct airo_info *ai, u16 reg ) {
3333 if (test_bit(FLAG_MPI,&ai->flags))
3336 rc = inw( ai->dev->base_addr + reg );
3338 rc = inb( ai->dev->base_addr + reg );
3339 rc += ((int)inb( ai->dev->base_addr + reg + 1 )) << 8;
3344 static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock ) {
3348 /* FLAG_RADIO_OFF : Radio disabled via /proc or Wireless Extensions
3349 * FLAG_RADIO_DOWN : Radio disabled via "ifconfig ethX down"
3350 * Note : we could try to use !netif_running(dev) in enable_MAC()
3351 * instead of this flag, but I don't trust it *within* the
3352 * open/close functions, and testing both flags together is
3353 * "cheaper" - Jean II */
3354 if (ai->flags & FLAG_RADIO_MASK) return SUCCESS;
3356 if (lock && down_interruptible(&ai->sem))
3357 return -ERESTARTSYS;
3359 if (!test_bit(FLAG_ENABLED, &ai->flags)) {
3360 memset(&cmd, 0, sizeof(cmd));
3361 cmd.cmd = MAC_ENABLE;
3362 rc = issuecommand(ai, &cmd, rsp);
3364 set_bit(FLAG_ENABLED, &ai->flags);
3372 printk(KERN_ERR "%s: Cannot enable MAC, err=%d\n",
3377 static void disable_MAC( struct airo_info *ai, int lock ) {
3381 if (lock && down_interruptible(&ai->sem))
3384 if (test_bit(FLAG_ENABLED, &ai->flags)) {
3385 memset(&cmd, 0, sizeof(cmd));
3386 cmd.cmd = MAC_DISABLE; // disable in case already enabled
3387 issuecommand(ai, &cmd, &rsp);
3388 clear_bit(FLAG_ENABLED, &ai->flags);
3394 static void enable_interrupts( struct airo_info *ai ) {
3395 /* Reset the status register */
3396 u16 status = IN4500( ai, EVSTAT );
3397 OUT4500( ai, EVACK, status );
3398 /* Enable the interrupts */
3399 OUT4500( ai, EVINTEN, STATUS_INTS );
3400 /* Note there is a race condition between the last two lines that
3401 I don't know how to get rid of right now... */
3404 static void disable_interrupts( struct airo_info *ai ) {
3405 OUT4500( ai, EVINTEN, 0 );
3408 static void mpi_receive_802_3(struct airo_info *ai)
3412 struct sk_buff *skb;
3419 memcpy ((char *)&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
3420 /* Make sure we got something */
3421 if (rxd.rdy && rxd.valid == 0) {
3423 if (len < 12 && len > 2048)
3426 skb = dev_alloc_skb(len);
3428 ai->stats.rx_dropped++;
3431 buffer = skb_put(skb,len);
3433 memcpy(buffer, ai->rxfids[0].virtual_host_addr, ETH_ALEN * 2);
3434 if (ai->micstats.enabled) {
3436 ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2,
3438 if (ntohs(micbuf.typelen) <= 0x05DC) {
3439 if (len <= sizeof(micbuf) + ETH_ALEN * 2)
3442 off = sizeof(micbuf);
3443 skb_trim (skb, len - off);
3446 memcpy(buffer + ETH_ALEN * 2,
3447 ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2 + off,
3448 len - ETH_ALEN * 2 - off);
3449 if (decapsulate (ai, &micbuf, (etherHead*)buffer, len - off)) {
3451 dev_kfree_skb_irq (skb);
3455 memcpy(buffer, ai->rxfids[0].virtual_host_addr, len);
3457 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
3458 if (ai->spy_data.spy_number > 0) {
3460 struct iw_quality wstats;
3461 /* Prepare spy data : addr + qual */
3462 sa = buffer + ETH_ALEN;
3463 wstats.qual = 0; /* XXX Where do I get that info from ??? */
3466 /* Update spy records */
3467 wireless_spy_update(ai->dev, sa, &wstats);
3469 #endif /* IW_WIRELESS_SPY */
3472 skb->ip_summed = CHECKSUM_NONE;
3473 skb->protocol = eth_type_trans(skb, ai->dev);
3474 skb->dev->last_rx = jiffies;
3478 if (rxd.valid == 0) {
3482 memcpy (ai->rxfids[0].card_ram_off, (char *)&rxd, sizeof(rxd));
3486 static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
3497 memset( &mySsid, 0, sizeof( mySsid ) );
3503 /* The NOP is the first step in getting the card going */
3505 cmd.parm0 = cmd.parm1 = cmd.parm2 = 0;
3506 if (lock && down_interruptible(&ai->sem))
3508 if ( issuecommand( ai, &cmd, &rsp ) != SUCCESS ) {
3513 disable_MAC( ai, 0);
3515 // Let's figure out if we need to use the AUX port
3516 if (!test_bit(FLAG_MPI,&ai->flags)) {
3517 cmd.cmd = CMD_ENABLEAUX;
3518 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
3521 printk(KERN_ERR "airo: Error checking for AUX port\n");
3524 if (!aux_bap || rsp.status & 0xff00) {
3525 ai->bap_read = fast_bap_read;
3526 printk(KERN_DEBUG "airo: Doing fast bap_reads\n");
3528 ai->bap_read = aux_bap_read;
3529 printk(KERN_DEBUG "airo: Doing AUX bap_reads\n");
3534 if (ai->config.len == 0) {
3535 tdsRssiRid rssi_rid;
3536 CapabilityRid cap_rid;
3546 // general configuration (read/modify/write)
3547 status = readConfigRid(ai, lock);
3548 if ( status != SUCCESS ) return ERROR;
3550 status = readCapabilityRid(ai, &cap_rid, lock);
3551 if ( status != SUCCESS ) return ERROR;
3553 if (test_bit(FLAG_MPI, &ai->flags) &&
3554 strcmp (cap_rid.prodVer, "5.00.01") &&
3555 strcmp (cap_rid.prodVer, "5.00.03") &&
3556 strcmp (cap_rid.prodVer, "5b00.08"))
3557 printk(KERN_ERR "airo: Firmware version %s is not supported. Use it at your own risk!\n", cap_rid.prodVer);
3559 status = PC4500_readrid(ai,RID_RSSI,&rssi_rid,sizeof(rssi_rid),lock);
3560 if ( status == SUCCESS ) {
3561 if (ai->rssi || (ai->rssi = kmalloc(512, GFP_KERNEL)) != NULL)
3562 memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512);
3569 if (cap_rid.softCap & 8)
3570 ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
3572 printk(KERN_WARNING "airo: unknown received signal level scale\n");
3574 ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS;
3575 ai->config.authType = AUTH_OPEN;
3576 ai->config.modulation = MOD_CCK;
3579 if ((cap_rid.len>=sizeof(cap_rid)) && (cap_rid.extSoftCap&1) &&
3580 (micsetup(ai) == SUCCESS)) {
3581 ai->config.opmode |= MODE_MIC;
3582 set_bit(FLAG_MIC_CAPABLE, &ai->flags);
3586 /* Save off the MAC */
3587 for( i = 0; i < ETH_ALEN; i++ ) {
3588 mac[i] = ai->config.macAddr[i];
3591 /* Check to see if there are any insmod configured
3595 if ( rates[0] ) memset(ai->config.rates,0,sizeof(ai->config.rates));
3596 for( i = 0; i < 8 && rates[i]; i++ ) {
3597 ai->config.rates[i] = rates[i];
3600 if ( basic_rate > 0 ) {
3602 for( i = 0; i < 8; i++ ) {
3603 if ( ai->config.rates[i] == basic_rate ||
3604 !ai->config.rates ) {
3605 ai->config.rates[i] = basic_rate | 0x80;
3610 set_bit (FLAG_COMMIT, &ai->flags);
3613 /* Setup the SSIDs if present */
3616 for( i = 0; i < 3 && ssids[i]; i++ ) {
3617 mySsid.ssids[i].len = strlen(ssids[i]);
3618 if ( mySsid.ssids[i].len > 32 )
3619 mySsid.ssids[i].len = 32;
3620 memcpy(mySsid.ssids[i].ssid, ssids[i],
3621 mySsid.ssids[i].len);
3623 mySsid.len = sizeof(mySsid);
3626 status = writeConfigRid(ai, lock);
3627 if ( status != SUCCESS ) return ERROR;
3629 /* Set up the SSID list */
3631 status = writeSsidRid(ai, &mySsid, lock);
3632 if ( status != SUCCESS ) return ERROR;
3635 status = enable_MAC(ai, &rsp, lock);
3636 if ( status != SUCCESS || (rsp.status & 0xFF00) != 0) {
3637 printk( KERN_ERR "airo: Bad MAC enable reason = %x, rid = %x, offset = %d\n", rsp.rsp0, rsp.rsp1, rsp.rsp2 );
3641 /* Grab the initial wep key, we gotta save it for auto_wep */
3642 rc = readWepKeyRid(ai, &wkr, 1, lock);
3643 if (rc == SUCCESS) do {
3644 lastindex = wkr.kindex;
3645 if (wkr.kindex == 0xffff) {
3646 ai->defindex = wkr.mac[0];
3648 rc = readWepKeyRid(ai, &wkr, 0, lock);
3649 } while(lastindex != wkr.kindex);
3652 ai->expires = RUN_AT(3*HZ);
3653 wake_up_interruptible(&ai->thr_wait);
3659 static u16 issuecommand(struct airo_info *ai, Cmd *pCmd, Resp *pRsp) {
3660 // Im really paranoid about letting it run forever!
3661 int max_tries = 600000;
3664 if (IN4500(ai, EVSTAT) & EV_CMD)
3665 OUT4500(ai, EVACK, EV_CMD);
3667 OUT4500(ai, PARAM0, pCmd->parm0);
3668 OUT4500(ai, PARAM1, pCmd->parm1);
3669 OUT4500(ai, PARAM2, pCmd->parm2);
3670 OUT4500(ai, COMMAND, pCmd->cmd);
3671 while ( max_tries-- && (IN4500(ai, EVSTAT) & EV_CMD) == 0 &&
3672 (cmd = IN4500(ai, COMMAND)) != 0 )
3673 if (cmd == pCmd->cmd)
3674 // PC4500 didn't notice command, try again
3675 OUT4500(ai, COMMAND, pCmd->cmd);
3676 if ( max_tries == -1 ) {
3678 "airo: Max tries exceeded when issueing command\n" );
3682 while (max_tries-- && (IN4500(ai, EVSTAT) & EV_CMD) == 0) {
3683 if (!in_atomic() && (max_tries & 255) == 0)
3686 if ( max_tries == -1 ) {
3688 "airo: Max tries exceeded waiting for command\n" );
3691 // command completed
3692 pRsp->status = IN4500(ai, STATUS);
3693 pRsp->rsp0 = IN4500(ai, RESP0);
3694 pRsp->rsp1 = IN4500(ai, RESP1);
3695 pRsp->rsp2 = IN4500(ai, RESP2);
3696 if ((pRsp->status & 0xff00)!=0 && pCmd->cmd != CMD_SOFTRESET) {
3697 printk (KERN_ERR "airo: cmd= %x\n", pCmd->cmd);
3698 printk (KERN_ERR "airo: status= %x\n", pRsp->status);
3699 printk (KERN_ERR "airo: Rsp0= %x\n", pRsp->rsp0);
3700 printk (KERN_ERR "airo: Rsp1= %x\n", pRsp->rsp1);
3701 printk (KERN_ERR "airo: Rsp2= %x\n", pRsp->rsp2);
3704 // clear stuck command busy if necessary
3705 if (IN4500(ai, COMMAND) & COMMAND_BUSY) {
3706 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
3708 // acknowledge processing the status/response
3709 OUT4500(ai, EVACK, EV_CMD);
3714 /* Sets up the bap to start exchange data. whichbap should
3715 * be one of the BAP0 or BAP1 defines. Locks should be held before
3717 static int bap_setup(struct airo_info *ai, u16 rid, u16 offset, int whichbap )
3722 OUT4500(ai, SELECT0+whichbap, rid);
3723 OUT4500(ai, OFFSET0+whichbap, offset);
3725 int status = IN4500(ai, OFFSET0+whichbap);
3726 if (status & BAP_BUSY) {
3727 /* This isn't really a timeout, but its kinda
3732 } else if ( status & BAP_ERR ) {
3733 /* invalid rid or offset */
3734 printk( KERN_ERR "airo: BAP error %x %d\n",
3737 } else if (status & BAP_DONE) { // success
3740 if ( !(max_tries--) ) {
3742 "airo: BAP setup error too many retries\n" );
3745 // -- PC4500 missed it, try again
3746 OUT4500(ai, SELECT0+whichbap, rid);
3747 OUT4500(ai, OFFSET0+whichbap, offset);
3752 /* should only be called by aux_bap_read. This aux function and the
3753 following use concepts not documented in the developers guide. I
3754 got them from a patch given to my by Aironet */
3755 static u16 aux_setup(struct airo_info *ai, u16 page,
3756 u16 offset, u16 *len)
3760 OUT4500(ai, AUXPAGE, page);
3761 OUT4500(ai, AUXOFF, 0);
3762 next = IN4500(ai, AUXDATA);
3763 *len = IN4500(ai, AUXDATA)&0xff;
3764 if (offset != 4) OUT4500(ai, AUXOFF, offset);
3768 /* requires call to bap_setup() first */
3769 static int aux_bap_read(struct airo_info *ai, u16 *pu16Dst,
3770 int bytelen, int whichbap)
3778 unsigned long flags;
3780 spin_lock_irqsave(&ai->aux_lock, flags);
3781 page = IN4500(ai, SWS0+whichbap);
3782 offset = IN4500(ai, SWS2+whichbap);
3783 next = aux_setup(ai, page, offset, &len);
3784 words = (bytelen+1)>>1;
3786 for (i=0; i<words;) {
3788 count = (len>>1) < (words-i) ? (len>>1) : (words-i);
3790 insw( ai->dev->base_addr+DATA0+whichbap,
3793 insb( ai->dev->base_addr+DATA0+whichbap,
3794 pu16Dst+i, count << 1 );
3797 next = aux_setup(ai, next, 4, &len);
3800 spin_unlock_irqrestore(&ai->aux_lock, flags);
3805 /* requires call to bap_setup() first */
3806 static int fast_bap_read(struct airo_info *ai, u16 *pu16Dst,
3807 int bytelen, int whichbap)
3809 bytelen = (bytelen + 1) & (~1); // round up to even value
3811 insw( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen>>1 );
3813 insb( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen );
3817 /* requires call to bap_setup() first */
3818 static int bap_write(struct airo_info *ai, const u16 *pu16Src,
3819 int bytelen, int whichbap)
3821 bytelen = (bytelen + 1) & (~1); // round up to even value
3823 outsw( ai->dev->base_addr+DATA0+whichbap,
3824 pu16Src, bytelen>>1 );
3826 outsb( ai->dev->base_addr+DATA0+whichbap, pu16Src, bytelen );
3830 static int PC4500_accessrid(struct airo_info *ai, u16 rid, u16 accmd)
3832 Cmd cmd; /* for issuing commands */
3833 Resp rsp; /* response from commands */
3836 memset(&cmd, 0, sizeof(cmd));
3839 status = issuecommand(ai, &cmd, &rsp);
3840 if (status != 0) return status;
3841 if ( (rsp.status & 0x7F00) != 0) {
3842 return (accmd << 8) + (rsp.rsp0 & 0xFF);
3847 /* Note, that we are using BAP1 which is also used by transmit, so
3848 * we must get a lock. */
3849 static int PC4500_readrid(struct airo_info *ai, u16 rid, void *pBuf, int len, int lock)
3855 if (down_interruptible(&ai->sem))
3858 if (test_bit(FLAG_MPI,&ai->flags)) {
3862 memset(&cmd, 0, sizeof(cmd));
3863 memset(&rsp, 0, sizeof(rsp));
3864 ai->config_desc.rid_desc.valid = 1;
3865 ai->config_desc.rid_desc.len = RIDSIZE;
3866 ai->config_desc.rid_desc.rid = 0;
3867 ai->config_desc.rid_desc.host_addr = ai->ridbus;
3869 cmd.cmd = CMD_ACCESS;
3872 memcpy((char *)ai->config_desc.card_ram_off,
3873 (char *)&ai->config_desc.rid_desc, sizeof(Rid));
3875 rc = issuecommand(ai, &cmd, &rsp);
3877 if (rsp.status & 0x7f00)
3880 memcpy(pBuf, ai->config_desc.virtual_host_addr, len);
3883 if ((status = PC4500_accessrid(ai, rid, CMD_ACCESS))!=SUCCESS) {
3887 if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
3891 // read the rid length field
3892 bap_read(ai, pBuf, 2, BAP1);
3893 // length for remaining part of rid
3894 len = min(len, (int)le16_to_cpu(*(u16*)pBuf)) - 2;
3898 "airo: Rid %x has a length of %d which is too short\n",
3899 (int)rid, (int)len );
3903 // read remainder of the rid
3904 rc = bap_read(ai, ((u16*)pBuf)+1, len, BAP1);
3912 /* Note, that we are using BAP1 which is also used by transmit, so
3913 * make sure this isnt called when a transmit is happening */
3914 static int PC4500_writerid(struct airo_info *ai, u16 rid,
3915 const void *pBuf, int len, int lock)
3920 *(u16*)pBuf = cpu_to_le16((u16)len);
3923 if (down_interruptible(&ai->sem))
3926 if (test_bit(FLAG_MPI,&ai->flags)) {
3930 if (test_bit(FLAG_ENABLED, &ai->flags))
3931 printk(KERN_ERR "%s: MAC should be disabled (rid=%d)\n",
3933 memset(&cmd, 0, sizeof(cmd));
3934 memset(&rsp, 0, sizeof(rsp));
3936 ai->config_desc.rid_desc.valid = 1;
3937 ai->config_desc.rid_desc.len = RIDSIZE;
3938 ai->config_desc.rid_desc.rid = 0;
3940 cmd.cmd = CMD_WRITERID;
3943 memcpy((char *)ai->config_desc.card_ram_off,
3944 (char *)&ai->config_desc.rid_desc, sizeof(Rid));
3946 if (len < 4 || len > 2047) {
3947 printk(KERN_ERR "%s: len=%d\n",__FUNCTION__,len);
3950 memcpy((char *)ai->config_desc.virtual_host_addr,
3953 rc = issuecommand(ai, &cmd, &rsp);
3954 if ((rc & 0xff00) != 0) {
3955 printk(KERN_ERR "%s: Write rid Error %d\n",
3957 printk(KERN_ERR "%s: Cmd=%04x\n",
3958 __FUNCTION__,cmd.cmd);
3961 if ((rsp.status & 0x7f00))
3965 // --- first access so that we can write the rid data
3966 if ( (status = PC4500_accessrid(ai, rid, CMD_ACCESS)) != 0) {
3970 // --- now write the rid data
3971 if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
3975 bap_write(ai, pBuf, len, BAP1);
3976 // ---now commit the rid data
3977 rc = PC4500_accessrid(ai, rid, 0x100|CMD_ACCESS);
3985 /* Allocates a FID to be used for transmitting packets. We only use
3987 static u16 transmit_allocate(struct airo_info *ai, int lenPayload, int raw)
3989 unsigned int loop = 3000;
3995 cmd.cmd = CMD_ALLOCATETX;
3996 cmd.parm0 = lenPayload;
3997 if (down_interruptible(&ai->sem))
3999 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
4003 if ( (rsp.status & 0xFF00) != 0) {
4007 /* wait for the allocate event/indication
4008 * It makes me kind of nervous that this can just sit here and spin,
4009 * but in practice it only loops like four times. */
4010 while (((IN4500(ai, EVSTAT) & EV_ALLOC) == 0) && --loop);
4016 // get the allocated fid and acknowledge
4017 txFid = IN4500(ai, TXALLOCFID);
4018 OUT4500(ai, EVACK, EV_ALLOC);
4020 /* The CARD is pretty cool since it converts the ethernet packet
4021 * into 802.11. Also note that we don't release the FID since we
4022 * will be using the same one over and over again. */
4023 /* We only have to setup the control once since we are not
4024 * releasing the fid. */
4026 txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_11
4027 | TXCTL_ETHERNET | TXCTL_NORELEASE);
4029 txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_3
4030 | TXCTL_ETHERNET | TXCTL_NORELEASE);
4031 if (bap_setup(ai, txFid, 0x0008, BAP1) != SUCCESS)
4034 bap_write(ai, &txControl, sizeof(txControl), BAP1);
4042 /* In general BAP1 is dedicated to transmiting packets. However,
4043 since we need a BAP when accessing RIDs, we also use BAP1 for that.
4044 Make sure the BAP1 spinlock is held when this is called. */
4045 static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket)
4056 if (len <= ETH_ALEN * 2) {
4057 printk( KERN_WARNING "Short packet %d\n", len );
4060 len -= ETH_ALEN * 2;
4063 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
4064 (ntohs(((u16 *)pPacket)[6]) != 0x888E)) {
4065 if (encapsulate(ai,(etherHead *)pPacket,&pMic,len) != SUCCESS)
4067 miclen = sizeof(pMic);
4071 // packet is destination[6], source[6], payload[len-12]
4072 // write the payload length and dst/src/payload
4073 if (bap_setup(ai, txFid, 0x0036, BAP1) != SUCCESS) return ERROR;
4074 /* The hardware addresses aren't counted as part of the payload, so
4075 * we have to subtract the 12 bytes for the addresses off */
4076 payloadLen = cpu_to_le16(len + miclen);
4077 bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
4078 bap_write(ai, (const u16*)pPacket, sizeof(etherHead), BAP1);
4080 bap_write(ai, (const u16*)&pMic, miclen, BAP1);
4081 bap_write(ai, (const u16*)(pPacket + sizeof(etherHead)), len, BAP1);
4082 // issue the transmit command
4083 memset( &cmd, 0, sizeof( cmd ) );
4084 cmd.cmd = CMD_TRANSMIT;
4086 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
4087 if ( (rsp.status & 0xFF00) != 0) return ERROR;
4091 static int transmit_802_11_packet(struct airo_info *ai, int len, char *pPacket)
4106 fc = le16_to_cpu(*(const u16*)pPacket);
4109 if ((fc & 0xe0) == 0xc0)
4115 if ((fc&0x300)==0x300){
4124 printk( KERN_WARNING "Short packet %d\n", len );
4128 /* packet is 802.11 header + payload
4129 * write the payload length and dst/src/payload */
4130 if (bap_setup(ai, txFid, 6, BAP1) != SUCCESS) return ERROR;
4131 /* The 802.11 header aren't counted as part of the payload, so
4132 * we have to subtract the header bytes off */
4133 payloadLen = cpu_to_le16(len-hdrlen);
4134 bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
4135 if (bap_setup(ai, txFid, 0x0014, BAP1) != SUCCESS) return ERROR;
4136 bap_write(ai, (const u16*)pPacket, hdrlen, BAP1);
4137 bap_write(ai, hdrlen == 30 ?
4138 (const u16*)&gap.gaplen : (const u16*)&gap, 38 - hdrlen, BAP1);
4140 bap_write(ai, (const u16*)(pPacket + hdrlen), len - hdrlen, BAP1);
4141 // issue the transmit command
4142 memset( &cmd, 0, sizeof( cmd ) );
4143 cmd.cmd = CMD_TRANSMIT;
4145 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
4146 if ( (rsp.status & 0xFF00) != 0) return ERROR;
4151 * This is the proc_fs routines. It is a bit messier than I would
4152 * like! Feel free to clean it up!
4155 static ssize_t proc_read( struct file *file,
4160 static ssize_t proc_write( struct file *file,
4164 static int proc_close( struct inode *inode, struct file *file );
4166 static int proc_stats_open( struct inode *inode, struct file *file );
4167 static int proc_statsdelta_open( struct inode *inode, struct file *file );
4168 static int proc_status_open( struct inode *inode, struct file *file );
4169 static int proc_SSID_open( struct inode *inode, struct file *file );
4170 static int proc_APList_open( struct inode *inode, struct file *file );
4171 static int proc_BSSList_open( struct inode *inode, struct file *file );
4172 static int proc_config_open( struct inode *inode, struct file *file );
4173 static int proc_wepkey_open( struct inode *inode, struct file *file );
4175 static struct file_operations proc_statsdelta_ops = {
4177 .open = proc_statsdelta_open,
4178 .release = proc_close
4181 static struct file_operations proc_stats_ops = {
4183 .open = proc_stats_open,
4184 .release = proc_close
4187 static struct file_operations proc_status_ops = {
4189 .open = proc_status_open,
4190 .release = proc_close
4193 static struct file_operations proc_SSID_ops = {
4195 .write = proc_write,
4196 .open = proc_SSID_open,
4197 .release = proc_close
4200 static struct file_operations proc_BSSList_ops = {
4202 .write = proc_write,
4203 .open = proc_BSSList_open,
4204 .release = proc_close
4207 static struct file_operations proc_APList_ops = {
4209 .write = proc_write,
4210 .open = proc_APList_open,
4211 .release = proc_close
4214 static struct file_operations proc_config_ops = {
4216 .write = proc_write,
4217 .open = proc_config_open,
4218 .release = proc_close
4221 static struct file_operations proc_wepkey_ops = {
4223 .write = proc_write,
4224 .open = proc_wepkey_open,
4225 .release = proc_close
4228 static struct proc_dir_entry *airo_entry = 0;
4237 void (*on_close) (struct inode *, struct file *);
4241 #define SETPROC_OPS(entry, ops) (entry)->proc_fops = &(ops)
4244 static int setup_proc_entry( struct net_device *dev,
4245 struct airo_info *apriv ) {
4246 struct proc_dir_entry *entry;
4247 /* First setup the device directory */
4248 apriv->proc_entry = create_proc_entry(dev->name,
4251 apriv->proc_entry->uid = proc_uid;
4252 apriv->proc_entry->gid = proc_gid;
4253 apriv->proc_entry->owner = THIS_MODULE;
4255 /* Setup the StatsDelta */
4256 entry = create_proc_entry("StatsDelta",
4257 S_IFREG | (S_IRUGO&proc_perm),
4259 entry->uid = proc_uid;
4260 entry->gid = proc_gid;
4262 entry->owner = THIS_MODULE;
4263 SETPROC_OPS(entry, proc_statsdelta_ops);
4265 /* Setup the Stats */
4266 entry = create_proc_entry("Stats",
4267 S_IFREG | (S_IRUGO&proc_perm),
4269 entry->uid = proc_uid;
4270 entry->gid = proc_gid;
4272 entry->owner = THIS_MODULE;
4273 SETPROC_OPS(entry, proc_stats_ops);
4275 /* Setup the Status */
4276 entry = create_proc_entry("Status",
4277 S_IFREG | (S_IRUGO&proc_perm),
4279 entry->uid = proc_uid;
4280 entry->gid = proc_gid;
4282 entry->owner = THIS_MODULE;
4283 SETPROC_OPS(entry, proc_status_ops);
4285 /* Setup the Config */
4286 entry = create_proc_entry("Config",
4287 S_IFREG | proc_perm,
4289 entry->uid = proc_uid;
4290 entry->gid = proc_gid;
4292 entry->owner = THIS_MODULE;
4293 SETPROC_OPS(entry, proc_config_ops);
4295 /* Setup the SSID */
4296 entry = create_proc_entry("SSID",
4297 S_IFREG | proc_perm,
4299 entry->uid = proc_uid;
4300 entry->gid = proc_gid;
4302 entry->owner = THIS_MODULE;
4303 SETPROC_OPS(entry, proc_SSID_ops);
4305 /* Setup the APList */
4306 entry = create_proc_entry("APList",
4307 S_IFREG | proc_perm,
4309 entry->uid = proc_uid;
4310 entry->gid = proc_gid;
4312 entry->owner = THIS_MODULE;
4313 SETPROC_OPS(entry, proc_APList_ops);
4315 /* Setup the BSSList */
4316 entry = create_proc_entry("BSSList",
4317 S_IFREG | proc_perm,
4319 entry->uid = proc_uid;
4320 entry->gid = proc_gid;
4322 entry->owner = THIS_MODULE;
4323 SETPROC_OPS(entry, proc_BSSList_ops);
4325 /* Setup the WepKey */
4326 entry = create_proc_entry("WepKey",
4327 S_IFREG | proc_perm,
4329 entry->uid = proc_uid;
4330 entry->gid = proc_gid;
4332 entry->owner = THIS_MODULE;
4333 SETPROC_OPS(entry, proc_wepkey_ops);
4338 static int takedown_proc_entry( struct net_device *dev,
4339 struct airo_info *apriv ) {
4340 if ( !apriv->proc_entry->namelen ) return 0;
4341 remove_proc_entry("Stats",apriv->proc_entry);
4342 remove_proc_entry("StatsDelta",apriv->proc_entry);
4343 remove_proc_entry("Status",apriv->proc_entry);
4344 remove_proc_entry("Config",apriv->proc_entry);
4345 remove_proc_entry("SSID",apriv->proc_entry);
4346 remove_proc_entry("APList",apriv->proc_entry);
4347 remove_proc_entry("BSSList",apriv->proc_entry);
4348 remove_proc_entry("WepKey",apriv->proc_entry);
4349 remove_proc_entry(dev->name,airo_entry);
4354 * What we want from the proc_fs is to be able to efficiently read
4355 * and write the configuration. To do this, we want to read the
4356 * configuration when the file is opened and write it when the file is
4357 * closed. So basically we allocate a read buffer at open and fill it
4358 * with data, and allocate a write buffer and read it at close.
4362 * The read routine is generic, it relies on the preallocated rbuffer
4363 * to supply the data.
4365 static ssize_t proc_read( struct file *file,
4372 struct proc_data *priv = (struct proc_data*)file->private_data;
4374 if( !priv->rbuffer ) return -EINVAL;
4377 for( i = 0; i+pos < priv->readlen && i < len; i++ ) {
4378 if (put_user( priv->rbuffer[i+pos], buffer+i ))
4386 * The write routine is generic, it fills in a preallocated rbuffer
4387 * to supply the data.
4389 static ssize_t proc_write( struct file *file,
4396 struct proc_data *priv = (struct proc_data*)file->private_data;
4398 if ( !priv->wbuffer ) {
4404 for( i = 0; i + pos < priv->maxwritelen &&
4406 if (get_user( priv->wbuffer[i+pos], buffer + i ))
4409 if ( i+pos > priv->writelen ) priv->writelen = i+file->f_pos;
4414 static int proc_status_open( struct inode *inode, struct file *file ) {
4415 struct proc_data *data;
4416 struct proc_dir_entry *dp = PDE(inode);
4417 struct net_device *dev = dp->data;
4418 struct airo_info *apriv = dev->priv;
4419 CapabilityRid cap_rid;
4420 StatusRid status_rid;
4423 if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4425 memset(file->private_data, 0, sizeof(struct proc_data));
4426 data = (struct proc_data *)file->private_data;
4427 if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
4428 kfree (file->private_data);
4432 readStatusRid(apriv, &status_rid, 1);
4433 readCapabilityRid(apriv, &cap_rid, 1);
4435 i = sprintf(data->rbuffer, "Status: %s%s%s%s%s%s%s%s%s\n",
4436 status_rid.mode & 1 ? "CFG ": "",
4437 status_rid.mode & 2 ? "ACT ": "",
4438 status_rid.mode & 0x10 ? "SYN ": "",
4439 status_rid.mode & 0x20 ? "LNK ": "",
4440 status_rid.mode & 0x40 ? "LEAP ": "",
4441 status_rid.mode & 0x80 ? "PRIV ": "",
4442 status_rid.mode & 0x100 ? "KEY ": "",
4443 status_rid.mode & 0x200 ? "WEP ": "",
4444 status_rid.mode & 0x8000 ? "ERR ": "");
4445 sprintf( data->rbuffer+i, "Mode: %x\n"
4446 "Signal Strength: %d\n"
4447 "Signal Quality: %d\n"
4452 "Driver Version: %s\n"
4453 "Device: %s\nManufacturer: %s\nFirmware Version: %s\n"
4454 "Radio type: %x\nCountry: %x\nHardware Version: %x\n"
4455 "Software Version: %x\nSoftware Subversion: %x\n"
4456 "Boot block version: %x\n",
4457 (int)status_rid.mode,
4458 (int)status_rid.normalizedSignalStrength,
4459 (int)status_rid.signalQuality,
4460 (int)status_rid.SSIDlen,
4463 (int)status_rid.channel,
4464 (int)status_rid.currentXmitRate/2,
4472 (int)cap_rid.softVer,
4473 (int)cap_rid.softSubVer,
4474 (int)cap_rid.bootBlockVer );
4475 data->readlen = strlen( data->rbuffer );
4479 static int proc_stats_rid_open(struct inode*, struct file*, u16);
4480 static int proc_statsdelta_open( struct inode *inode,
4481 struct file *file ) {
4482 if (file->f_mode&FMODE_WRITE) {
4483 return proc_stats_rid_open(inode, file, RID_STATSDELTACLEAR);
4485 return proc_stats_rid_open(inode, file, RID_STATSDELTA);
4488 static int proc_stats_open( struct inode *inode, struct file *file ) {
4489 return proc_stats_rid_open(inode, file, RID_STATS);
4492 static int proc_stats_rid_open( struct inode *inode,
4495 struct proc_data *data;
4496 struct proc_dir_entry *dp = PDE(inode);
4497 struct net_device *dev = dp->data;
4498 struct airo_info *apriv = dev->priv;
4501 u32 *vals = stats.vals;
4503 if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4505 memset(file->private_data, 0, sizeof(struct proc_data));
4506 data = (struct proc_data *)file->private_data;
4507 if ((data->rbuffer = kmalloc( 4096, GFP_KERNEL )) == NULL) {
4508 kfree (file->private_data);
4512 readStatsRid(apriv, &stats, rid, 1);
4515 for(i=0; statsLabels[i]!=(char *)-1 &&
4516 i*4<stats.len; i++){
4517 if (!statsLabels[i]) continue;
4518 if (j+strlen(statsLabels[i])+16>4096) {
4520 "airo: Potentially disasterous buffer overflow averted!\n");
4523 j+=sprintf(data->rbuffer+j, "%s: %u\n", statsLabels[i], vals[i]);
4525 if (i*4>=stats.len){
4527 "airo: Got a short rid\n");
4533 static int get_dec_u16( char *buffer, int *start, int limit ) {
4536 for( value = 0; buffer[*start] >= '0' &&
4537 buffer[*start] <= '9' &&
4538 *start < limit; (*start)++ ) {
4541 value += buffer[*start] - '0';
4543 if ( !valid ) return -1;
4547 static int airo_config_commit(struct net_device *dev,
4548 struct iw_request_info *info, void *zwrq,
4551 static void proc_config_on_close( struct inode *inode, struct file *file ) {
4552 struct proc_data *data = file->private_data;
4553 struct proc_dir_entry *dp = PDE(inode);
4554 struct net_device *dev = dp->data;
4555 struct airo_info *ai = dev->priv;
4558 if ( !data->writelen ) return;
4560 readConfigRid(ai, 1);
4561 set_bit (FLAG_COMMIT, &ai->flags);
4563 line = data->wbuffer;
4565 /*** Mode processing */
4566 if ( !strncmp( line, "Mode: ", 6 ) ) {
4568 if ((ai->config.rmode & 0xff) >= RXMODE_RFMON)
4569 set_bit (FLAG_RESET, &ai->flags);
4570 ai->config.rmode &= 0xfe00;
4571 clear_bit (FLAG_802_11, &ai->flags);
4572 ai->config.opmode &= 0xFF00;
4573 ai->config.scanMode = SCANMODE_ACTIVE;
4574 if ( line[0] == 'a' ) {
4575 ai->config.opmode |= 0;
4577 ai->config.opmode |= 1;
4578 if ( line[0] == 'r' ) {
4579 ai->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
4580 ai->config.scanMode = SCANMODE_PASSIVE;
4581 set_bit (FLAG_802_11, &ai->flags);
4582 } else if ( line[0] == 'y' ) {
4583 ai->config.rmode |= RXMODE_RFMON_ANYBSS | RXMODE_DISABLE_802_3_HEADER;
4584 ai->config.scanMode = SCANMODE_PASSIVE;
4585 set_bit (FLAG_802_11, &ai->flags);
4586 } else if ( line[0] == 'l' )
4587 ai->config.rmode |= RXMODE_LANMON;
4589 set_bit (FLAG_COMMIT, &ai->flags);
4592 /*** Radio status */
4593 else if (!strncmp(line,"Radio: ", 7)) {
4595 if (!strncmp(line,"off",3)) {
4596 set_bit (FLAG_RADIO_OFF, &ai->flags);
4598 clear_bit (FLAG_RADIO_OFF, &ai->flags);
4601 /*** NodeName processing */
4602 else if ( !strncmp( line, "NodeName: ", 10 ) ) {
4606 memset( ai->config.nodeName, 0, 16 );
4607 /* Do the name, assume a space between the mode and node name */
4608 for( j = 0; j < 16 && line[j] != '\n'; j++ ) {
4609 ai->config.nodeName[j] = line[j];
4611 set_bit (FLAG_COMMIT, &ai->flags);
4614 /*** PowerMode processing */
4615 else if ( !strncmp( line, "PowerMode: ", 11 ) ) {
4617 if ( !strncmp( line, "PSPCAM", 6 ) ) {
4618 ai->config.powerSaveMode = POWERSAVE_PSPCAM;
4619 set_bit (FLAG_COMMIT, &ai->flags);
4620 } else if ( !strncmp( line, "PSP", 3 ) ) {
4621 ai->config.powerSaveMode = POWERSAVE_PSP;
4622 set_bit (FLAG_COMMIT, &ai->flags);
4624 ai->config.powerSaveMode = POWERSAVE_CAM;
4625 set_bit (FLAG_COMMIT, &ai->flags);
4627 } else if ( !strncmp( line, "DataRates: ", 11 ) ) {
4628 int v, i = 0, k = 0; /* i is index into line,
4629 k is index to rates */
4632 while((v = get_dec_u16(line, &i, 3))!=-1) {
4633 ai->config.rates[k++] = (u8)v;
4637 set_bit (FLAG_COMMIT, &ai->flags);
4638 } else if ( !strncmp( line, "Channel: ", 9 ) ) {
4641 v = get_dec_u16(line, &i, i+3);
4643 ai->config.channelSet = (u16)v;
4644 set_bit (FLAG_COMMIT, &ai->flags);
4646 } else if ( !strncmp( line, "XmitPower: ", 11 ) ) {
4649 v = get_dec_u16(line, &i, i+3);
4651 ai->config.txPower = (u16)v;
4652 set_bit (FLAG_COMMIT, &ai->flags);
4654 } else if ( !strncmp( line, "WEP: ", 5 ) ) {
4658 ai->config.authType = (u16)AUTH_SHAREDKEY;
4661 ai->config.authType = (u16)AUTH_ENCRYPT;
4664 ai->config.authType = (u16)AUTH_OPEN;
4667 set_bit (FLAG_COMMIT, &ai->flags);
4668 } else if ( !strncmp( line, "LongRetryLimit: ", 16 ) ) {
4672 v = get_dec_u16(line, &i, 3);
4673 v = (v<0) ? 0 : ((v>255) ? 255 : v);
4674 ai->config.longRetryLimit = (u16)v;
4675 set_bit (FLAG_COMMIT, &ai->flags);
4676 } else if ( !strncmp( line, "ShortRetryLimit: ", 17 ) ) {
4680 v = get_dec_u16(line, &i, 3);
4681 v = (v<0) ? 0 : ((v>255) ? 255 : v);
4682 ai->config.shortRetryLimit = (u16)v;
4683 set_bit (FLAG_COMMIT, &ai->flags);
4684 } else if ( !strncmp( line, "RTSThreshold: ", 14 ) ) {
4688 v = get_dec_u16(line, &i, 4);
4689 v = (v<0) ? 0 : ((v>2312) ? 2312 : v);
4690 ai->config.rtsThres = (u16)v;
4691 set_bit (FLAG_COMMIT, &ai->flags);
4692 } else if ( !strncmp( line, "TXMSDULifetime: ", 16 ) ) {
4696 v = get_dec_u16(line, &i, 5);
4698 ai->config.txLifetime = (u16)v;
4699 set_bit (FLAG_COMMIT, &ai->flags);
4700 } else if ( !strncmp( line, "RXMSDULifetime: ", 16 ) ) {
4704 v = get_dec_u16(line, &i, 5);
4706 ai->config.rxLifetime = (u16)v;
4707 set_bit (FLAG_COMMIT, &ai->flags);
4708 } else if ( !strncmp( line, "TXDiversity: ", 13 ) ) {
4709 ai->config.txDiversity =
4710 (line[13]=='l') ? 1 :
4711 ((line[13]=='r')? 2: 3);
4712 set_bit (FLAG_COMMIT, &ai->flags);
4713 } else if ( !strncmp( line, "RXDiversity: ", 13 ) ) {
4714 ai->config.rxDiversity =
4715 (line[13]=='l') ? 1 :
4716 ((line[13]=='r')? 2: 3);
4717 set_bit (FLAG_COMMIT, &ai->flags);
4718 } else if ( !strncmp( line, "FragThreshold: ", 15 ) ) {
4722 v = get_dec_u16(line, &i, 4);
4723 v = (v<256) ? 256 : ((v>2312) ? 2312 : v);
4724 v = v & 0xfffe; /* Make sure its even */
4725 ai->config.fragThresh = (u16)v;
4726 set_bit (FLAG_COMMIT, &ai->flags);
4727 } else if (!strncmp(line, "Modulation: ", 12)) {
4730 case 'd': ai->config.modulation=MOD_DEFAULT; set_bit(FLAG_COMMIT, &ai->flags); break;
4731 case 'c': ai->config.modulation=MOD_CCK; set_bit(FLAG_COMMIT, &ai->flags); break;
4732 case 'm': ai->config.modulation=MOD_MOK; set_bit(FLAG_COMMIT, &ai->flags); break;
4734 printk( KERN_WARNING "airo: Unknown modulation\n" );
4736 } else if (!strncmp(line, "Preamble: ", 10)) {
4739 case 'a': ai->config.preamble=PREAMBLE_AUTO; set_bit(FLAG_COMMIT, &ai->flags); break;
4740 case 'l': ai->config.preamble=PREAMBLE_LONG; set_bit(FLAG_COMMIT, &ai->flags); break;
4741 case 's': ai->config.preamble=PREAMBLE_SHORT; set_bit(FLAG_COMMIT, &ai->flags); break;
4742 default: printk(KERN_WARNING "airo: Unknown preamble\n");
4745 printk( KERN_WARNING "Couldn't figure out %s\n", line );
4747 while( line[0] && line[0] != '\n' ) line++;
4748 if ( line[0] ) line++;
4750 airo_config_commit(dev, NULL, NULL, NULL);
4753 static char *get_rmode(u16 mode) {
4755 case RXMODE_RFMON: return "rfmon";
4756 case RXMODE_RFMON_ANYBSS: return "yna (any) bss rfmon";
4757 case RXMODE_LANMON: return "lanmon";
4762 static int proc_config_open( struct inode *inode, struct file *file ) {
4763 struct proc_data *data;
4764 struct proc_dir_entry *dp = PDE(inode);
4765 struct net_device *dev = dp->data;
4766 struct airo_info *ai = dev->priv;
4769 if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4771 memset(file->private_data, 0, sizeof(struct proc_data));
4772 data = (struct proc_data *)file->private_data;
4773 if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
4774 kfree (file->private_data);
4777 if ((data->wbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
4778 kfree (data->rbuffer);
4779 kfree (file->private_data);
4782 memset( data->wbuffer, 0, 2048 );
4783 data->maxwritelen = 2048;
4784 data->on_close = proc_config_on_close;
4786 readConfigRid(ai, 1);
4788 i = sprintf( data->rbuffer,
4793 "DataRates: %d %d %d %d %d %d %d %d\n"
4796 (ai->config.opmode & 0xFF) == 0 ? "adhoc" :
4797 (ai->config.opmode & 0xFF) == 1 ? get_rmode(ai->config.rmode):
4798 (ai->config.opmode & 0xFF) == 2 ? "AP" :
4799 (ai->config.opmode & 0xFF) == 3 ? "AP RPTR" : "Error",
4800 test_bit(FLAG_RADIO_OFF, &ai->flags) ? "off" : "on",
4801 ai->config.nodeName,
4802 ai->config.powerSaveMode == 0 ? "CAM" :
4803 ai->config.powerSaveMode == 1 ? "PSP" :
4804 ai->config.powerSaveMode == 2 ? "PSPCAM" : "Error",
4805 (int)ai->config.rates[0],
4806 (int)ai->config.rates[1],
4807 (int)ai->config.rates[2],
4808 (int)ai->config.rates[3],
4809 (int)ai->config.rates[4],
4810 (int)ai->config.rates[5],
4811 (int)ai->config.rates[6],
4812 (int)ai->config.rates[7],
4813 (int)ai->config.channelSet,
4814 (int)ai->config.txPower
4816 sprintf( data->rbuffer + i,
4817 "LongRetryLimit: %d\n"
4818 "ShortRetryLimit: %d\n"
4819 "RTSThreshold: %d\n"
4820 "TXMSDULifetime: %d\n"
4821 "RXMSDULifetime: %d\n"
4824 "FragThreshold: %d\n"
4828 (int)ai->config.longRetryLimit,
4829 (int)ai->config.shortRetryLimit,
4830 (int)ai->config.rtsThres,
4831 (int)ai->config.txLifetime,
4832 (int)ai->config.rxLifetime,
4833 ai->config.txDiversity == 1 ? "left" :
4834 ai->config.txDiversity == 2 ? "right" : "both",
4835 ai->config.rxDiversity == 1 ? "left" :
4836 ai->config.rxDiversity == 2 ? "right" : "both",
4837 (int)ai->config.fragThresh,
4838 ai->config.authType == AUTH_ENCRYPT ? "encrypt" :
4839 ai->config.authType == AUTH_SHAREDKEY ? "shared" : "open",
4840 ai->config.modulation == 0 ? "default" :
4841 ai->config.modulation == MOD_CCK ? "cck" :
4842 ai->config.modulation == MOD_MOK ? "mok" : "error",
4843 ai->config.preamble == PREAMBLE_AUTO ? "auto" :
4844 ai->config.preamble == PREAMBLE_LONG ? "long" :
4845 ai->config.preamble == PREAMBLE_SHORT ? "short" : "error"
4847 data->readlen = strlen( data->rbuffer );
4851 static void proc_SSID_on_close( struct inode *inode, struct file *file ) {
4852 struct proc_data *data = (struct proc_data *)file->private_data;
4853 struct proc_dir_entry *dp = PDE(inode);
4854 struct net_device *dev = dp->data;
4855 struct airo_info *ai = dev->priv;
4861 if ( !data->writelen ) return;
4863 memset( &SSID_rid, 0, sizeof( SSID_rid ) );
4865 for( i = 0; i < 3; i++ ) {
4867 for( j = 0; j+offset < data->writelen && j < 32 &&
4868 data->wbuffer[offset+j] != '\n'; j++ ) {
4869 SSID_rid.ssids[i].ssid[j] = data->wbuffer[offset+j];
4871 if ( j == 0 ) break;
4872 SSID_rid.ssids[i].len = j;
4874 while( data->wbuffer[offset] != '\n' &&
4875 offset < data->writelen ) offset++;
4879 SSID_rid.len = sizeof(SSID_rid);
4881 writeSsidRid(ai, &SSID_rid, 1);
4882 enable_MAC(ai, &rsp, 1);
4885 inline static u8 hexVal(char c) {
4886 if (c>='0' && c<='9') return c -= '0';
4887 if (c>='a' && c<='f') return c -= 'a'-10;
4888 if (c>='A' && c<='F') return c -= 'A'-10;
4892 static void proc_APList_on_close( struct inode *inode, struct file *file ) {
4893 struct proc_data *data = (struct proc_data *)file->private_data;
4894 struct proc_dir_entry *dp = PDE(inode);
4895 struct net_device *dev = dp->data;
4896 struct airo_info *ai = dev->priv;
4897 APListRid APList_rid;
4901 if ( !data->writelen ) return;
4903 memset( &APList_rid, 0, sizeof(APList_rid) );
4904 APList_rid.len = sizeof(APList_rid);
4906 for( i = 0; i < 4 && data->writelen >= (i+1)*6*3; i++ ) {
4908 for( j = 0; j < 6*3 && data->wbuffer[j+i*6*3]; j++ ) {
4911 APList_rid.ap[i][j/3]=
4912 hexVal(data->wbuffer[j+i*6*3])<<4;
4915 APList_rid.ap[i][j/3]|=
4916 hexVal(data->wbuffer[j+i*6*3]);
4922 writeAPListRid(ai, &APList_rid, 1);
4923 enable_MAC(ai, &rsp, 1);
4926 /* This function wraps PC4500_writerid with a MAC disable */
4927 static int do_writerid( struct airo_info *ai, u16 rid, const void *rid_data,
4928 int len, int dummy ) {
4933 rc = PC4500_writerid(ai, rid, rid_data, len, 1);
4934 enable_MAC(ai, &rsp, 1);
4938 /* Returns the length of the key at the index. If index == 0xffff
4939 * the index of the transmit key is returned. If the key doesn't exist,
4940 * -1 will be returned.
4942 static int get_wep_key(struct airo_info *ai, u16 index) {
4947 rc = readWepKeyRid(ai, &wkr, 1, 1);
4948 if (rc == SUCCESS) do {
4949 lastindex = wkr.kindex;
4950 if (wkr.kindex == index) {
4951 if (index == 0xffff) {
4956 readWepKeyRid(ai, &wkr, 0, 1);
4957 } while(lastindex != wkr.kindex);
4961 static int set_wep_key(struct airo_info *ai, u16 index,
4962 const char *key, u16 keylen, int perm, int lock ) {
4963 static const unsigned char macaddr[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
4967 memset(&wkr, 0, sizeof(wkr));
4969 // We are selecting which key to use
4970 wkr.len = sizeof(wkr);
4971 wkr.kindex = 0xffff;
4972 wkr.mac[0] = (char)index;
4973 if (perm) printk(KERN_INFO "Setting transmit key to %d\n", index);
4974 if (perm) ai->defindex = (char)index;
4976 // We are actually setting the key
4977 wkr.len = sizeof(wkr);
4980 memcpy( wkr.key, key, keylen );
4981 memcpy( wkr.mac, macaddr, ETH_ALEN );
4982 printk(KERN_INFO "Setting key %d\n", index);
4985 disable_MAC(ai, lock);
4986 writeWepKeyRid(ai, &wkr, perm, lock);
4987 enable_MAC(ai, &rsp, lock);
4991 static void proc_wepkey_on_close( struct inode *inode, struct file *file ) {
4992 struct proc_data *data;
4993 struct proc_dir_entry *dp = PDE(inode);
4994 struct net_device *dev = dp->data;
4995 struct airo_info *ai = dev->priv;
5001 memset(key, 0, sizeof(key));
5003 data = (struct proc_data *)file->private_data;
5004 if ( !data->writelen ) return;
5006 if (data->wbuffer[0] >= '0' && data->wbuffer[0] <= '3' &&
5007 (data->wbuffer[1] == ' ' || data->wbuffer[1] == '\n')) {
5008 index = data->wbuffer[0] - '0';
5009 if (data->wbuffer[1] == '\n') {
5010 set_wep_key(ai, index, 0, 0, 1, 1);
5015 printk(KERN_ERR "airo: WepKey passed invalid key index\n");
5019 for( i = 0; i < 16*3 && data->wbuffer[i+j]; i++ ) {
5022 key[i/3] = hexVal(data->wbuffer[i+j])<<4;
5025 key[i/3] |= hexVal(data->wbuffer[i+j]);
5029 set_wep_key(ai, index, key, i/3, 1, 1);
5032 static int proc_wepkey_open( struct inode *inode, struct file *file ) {
5033 struct proc_data *data;
5034 struct proc_dir_entry *dp = PDE(inode);
5035 struct net_device *dev = dp->data;
5036 struct airo_info *ai = dev->priv;
5043 if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5045 memset(file->private_data, 0, sizeof(struct proc_data));
5046 memset(&wkr, 0, sizeof(wkr));
5047 data = (struct proc_data *)file->private_data;
5048 if ((data->rbuffer = kmalloc( 180, GFP_KERNEL )) == NULL) {
5049 kfree (file->private_data);
5052 memset(data->rbuffer, 0, 180);
5054 data->maxwritelen = 80;
5055 if ((data->wbuffer = kmalloc( 80, GFP_KERNEL )) == NULL) {
5056 kfree (data->rbuffer);
5057 kfree (file->private_data);
5060 memset( data->wbuffer, 0, 80 );
5061 data->on_close = proc_wepkey_on_close;
5063 ptr = data->rbuffer;
5064 strcpy(ptr, "No wep keys\n");
5065 rc = readWepKeyRid(ai, &wkr, 1, 1);
5066 if (rc == SUCCESS) do {
5067 lastindex = wkr.kindex;
5068 if (wkr.kindex == 0xffff) {
5069 j += sprintf(ptr+j, "Tx key = %d\n",
5072 j += sprintf(ptr+j, "Key %d set with length = %d\n",
5073 (int)wkr.kindex, (int)wkr.klen);
5075 readWepKeyRid(ai, &wkr, 0, 1);
5076 } while((lastindex != wkr.kindex) && (j < 180-30));
5078 data->readlen = strlen( data->rbuffer );
5082 static int proc_SSID_open( struct inode *inode, struct file *file ) {
5083 struct proc_data *data;
5084 struct proc_dir_entry *dp = PDE(inode);
5085 struct net_device *dev = dp->data;
5086 struct airo_info *ai = dev->priv;
5091 if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5093 memset(file->private_data, 0, sizeof(struct proc_data));
5094 data = (struct proc_data *)file->private_data;
5095 if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
5096 kfree (file->private_data);
5100 data->maxwritelen = 33*3;
5101 if ((data->wbuffer = kmalloc( 33*3, GFP_KERNEL )) == NULL) {
5102 kfree (data->rbuffer);
5103 kfree (file->private_data);
5106 memset( data->wbuffer, 0, 33*3 );
5107 data->on_close = proc_SSID_on_close;
5109 readSsidRid(ai, &SSID_rid);
5110 ptr = data->rbuffer;
5111 for( i = 0; i < 3; i++ ) {
5113 if ( !SSID_rid.ssids[i].len ) break;
5114 for( j = 0; j < 32 &&
5115 j < SSID_rid.ssids[i].len &&
5116 SSID_rid.ssids[i].ssid[j]; j++ ) {
5117 *ptr++ = SSID_rid.ssids[i].ssid[j];
5122 data->readlen = strlen( data->rbuffer );
5126 static int proc_APList_open( struct inode *inode, struct file *file ) {
5127 struct proc_data *data;
5128 struct proc_dir_entry *dp = PDE(inode);
5129 struct net_device *dev = dp->data;
5130 struct airo_info *ai = dev->priv;
5133 APListRid APList_rid;
5135 if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5137 memset(file->private_data, 0, sizeof(struct proc_data));
5138 data = (struct proc_data *)file->private_data;
5139 if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
5140 kfree (file->private_data);
5144 data->maxwritelen = 4*6*3;
5145 if ((data->wbuffer = kmalloc( data->maxwritelen, GFP_KERNEL )) == NULL) {
5146 kfree (data->rbuffer);
5147 kfree (file->private_data);
5150 memset( data->wbuffer, 0, data->maxwritelen );
5151 data->on_close = proc_APList_on_close;
5153 readAPListRid(ai, &APList_rid);
5154 ptr = data->rbuffer;
5155 for( i = 0; i < 4; i++ ) {
5156 // We end when we find a zero MAC
5157 if ( !*(int*)APList_rid.ap[i] &&
5158 !*(int*)&APList_rid.ap[i][2]) break;
5159 ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02x\n",
5160 (int)APList_rid.ap[i][0],
5161 (int)APList_rid.ap[i][1],
5162 (int)APList_rid.ap[i][2],
5163 (int)APList_rid.ap[i][3],
5164 (int)APList_rid.ap[i][4],
5165 (int)APList_rid.ap[i][5]);
5167 if (i==0) ptr += sprintf(ptr, "Not using specific APs\n");
5170 data->readlen = strlen( data->rbuffer );
5174 static int proc_BSSList_open( struct inode *inode, struct file *file ) {
5175 struct proc_data *data;
5176 struct proc_dir_entry *dp = PDE(inode);
5177 struct net_device *dev = dp->data;
5178 struct airo_info *ai = dev->priv;
5180 BSSListRid BSSList_rid;
5182 /* If doLoseSync is not 1, we won't do a Lose Sync */
5183 int doLoseSync = -1;
5185 if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5187 memset(file->private_data, 0, sizeof(struct proc_data));
5188 data = (struct proc_data *)file->private_data;
5189 if ((data->rbuffer = kmalloc( 1024, GFP_KERNEL )) == NULL) {
5190 kfree (file->private_data);
5194 data->maxwritelen = 0;
5198 if (file->f_mode & FMODE_WRITE) {
5199 if (!(file->f_mode & FMODE_READ)) {
5203 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
5204 memset(&cmd, 0, sizeof(cmd));
5205 cmd.cmd=CMD_LISTBSS;
5206 if (down_interruptible(&ai->sem))
5207 return -ERESTARTSYS;
5208 issuecommand(ai, &cmd, &rsp);
5215 ptr = data->rbuffer;
5216 /* There is a race condition here if there are concurrent opens.
5217 Since it is a rare condition, we'll just live with it, otherwise
5218 we have to add a spin lock... */
5219 rc = readBSSListRid(ai, doLoseSync, &BSSList_rid);
5220 while(rc == 0 && BSSList_rid.index != 0xffff) {
5221 ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02x %*s rssi = %d",
5222 (int)BSSList_rid.bssid[0],
5223 (int)BSSList_rid.bssid[1],
5224 (int)BSSList_rid.bssid[2],
5225 (int)BSSList_rid.bssid[3],
5226 (int)BSSList_rid.bssid[4],
5227 (int)BSSList_rid.bssid[5],
5228 (int)BSSList_rid.ssidLen,
5230 (int)BSSList_rid.rssi);
5231 ptr += sprintf(ptr, " channel = %d %s %s %s %s\n",
5232 (int)BSSList_rid.dsChannel,
5233 BSSList_rid.cap & CAP_ESS ? "ESS" : "",
5234 BSSList_rid.cap & CAP_IBSS ? "adhoc" : "",
5235 BSSList_rid.cap & CAP_PRIVACY ? "wep" : "",
5236 BSSList_rid.cap & CAP_SHORTHDR ? "shorthdr" : "");
5237 rc = readBSSListRid(ai, 0, &BSSList_rid);
5240 data->readlen = strlen( data->rbuffer );
5244 static int proc_close( struct inode *inode, struct file *file )
5246 struct proc_data *data = (struct proc_data *)file->private_data;
5247 if ( data->on_close != NULL ) data->on_close( inode, file );
5248 if ( data->rbuffer ) kfree( data->rbuffer );
5249 if ( data->wbuffer ) kfree( data->wbuffer );
5254 static struct net_device_list {
5255 struct net_device *dev;
5256 struct net_device_list *next;
5257 } *airo_devices = 0;
5259 /* Since the card doesn't automatically switch to the right WEP mode,
5260 we will make it do it. If the card isn't associated, every secs we
5261 will switch WEP modes to see if that will help. If the card is
5262 associated we will check every minute to see if anything has
5264 static void timer_func( struct net_device *dev ) {
5265 struct airo_info *apriv = dev->priv;
5268 /* We don't have a link so try changing the authtype */
5269 readConfigRid(apriv, 0);
5270 disable_MAC(apriv, 0);
5271 switch(apriv->config.authType) {
5273 /* So drop to OPEN */
5274 apriv->config.authType = AUTH_OPEN;
5276 case AUTH_SHAREDKEY:
5277 if (apriv->keyindex < auto_wep) {
5278 set_wep_key(apriv, apriv->keyindex, 0, 0, 0, 0);
5279 apriv->config.authType = AUTH_SHAREDKEY;
5282 /* Drop to ENCRYPT */
5283 apriv->keyindex = 0;
5284 set_wep_key(apriv, apriv->defindex, 0, 0, 0, 0);
5285 apriv->config.authType = AUTH_ENCRYPT;
5288 default: /* We'll escalate to SHAREDKEY */
5289 apriv->config.authType = AUTH_SHAREDKEY;
5291 set_bit (FLAG_COMMIT, &apriv->flags);
5292 writeConfigRid(apriv, 0);
5293 enable_MAC(apriv, &rsp, 0);
5296 /* Schedule check to see if the change worked */
5297 clear_bit(JOB_AUTOWEP, &apriv->flags);
5298 apriv->expires = RUN_AT(HZ*3);
5301 static int add_airo_dev( struct net_device *dev ) {
5302 struct net_device_list *node = kmalloc( sizeof( *node ), GFP_KERNEL );
5307 node->next = airo_devices;
5308 airo_devices = node;
5313 static void del_airo_dev( struct net_device *dev ) {
5314 struct net_device_list **p = &airo_devices;
5315 while( *p && ( (*p)->dev != dev ) )
5317 if ( *p && (*p)->dev == dev )
5322 static int __devinit airo_pci_probe(struct pci_dev *pdev,
5323 const struct pci_device_id *pent)
5325 struct net_device *dev;
5327 if (pci_enable_device(pdev))
5329 pci_set_master(pdev);
5331 if (pdev->device == 0x5000 || pdev->device == 0xa504)
5332 dev = _init_airo_card(pdev->irq, pdev->resource[0].start, 0, pdev);
5334 dev = _init_airo_card(pdev->irq, pdev->resource[2].start, 0, pdev);
5338 pci_set_drvdata(pdev, dev);
5342 static void __devexit airo_pci_remove(struct pci_dev *pdev)
5346 static int airo_pci_suspend(struct pci_dev *pdev, u32 state)
5348 struct net_device *dev = pci_get_drvdata(pdev);
5349 struct airo_info *ai = dev->priv;
5353 printk(KERN_DEBUG "%s: airo_mpi entering sleep mode (state=%d)\n",
5356 if ((ai->APList == NULL) &&
5357 (ai->APList = kmalloc(sizeof(APListRid), GFP_KERNEL)) == NULL)
5359 if ((ai->SSID == NULL) &&
5360 (ai->SSID = kmalloc(sizeof(SsidRid), GFP_KERNEL)) == NULL)
5362 readAPListRid(ai, ai->APList);
5363 readSsidRid(ai, ai->SSID);
5364 memset(&cmd, 0, sizeof(cmd));
5365 /* the lock will be released at the end of the resume callback */
5366 if (down_interruptible(&ai->sem))
5369 netif_device_detach(dev);
5372 issuecommand(ai, &cmd, &rsp);
5376 static int airo_pci_resume(struct pci_dev *pdev)
5378 struct net_device *dev = pci_get_drvdata(pdev);
5379 struct airo_info *ai = dev->priv;
5383 printk(KERN_DEBUG "%s: airo_mpi waking up\n", dev->name);
5388 if (ai->power > 1) {
5389 err = reset_mpi_card(dev, 0);
5391 printk(KERN_ERR "%s: Error %d resetting on %s()\n",
5392 dev->name, err, __FUNCTION__);
5395 schedule_timeout (HZ/2);
5396 mpi_init_descriptors(ai);
5397 setup_card(ai, dev->dev_addr, 0);
5398 clear_bit(FLAG_RADIO_OFF, &ai->flags);
5399 clear_bit(FLAG_RADIO_DOWN, &ai->flags);
5400 clear_bit(FLAG_PENDING_XMIT, &ai->flags);
5402 OUT4500(ai, EVACK, EV_AWAKEN);
5403 OUT4500(ai, EVACK, EV_AWAKEN);
5404 schedule_timeout(HZ/10);
5407 set_bit (FLAG_COMMIT, &ai->flags);
5409 schedule_timeout (HZ/5);
5411 writeSsidRid(ai, ai->SSID, 0);
5416 writeAPListRid(ai, ai->APList, 0);
5420 writeConfigRid(ai, 0);
5421 enable_MAC(ai, &rsp, 0);
5423 netif_device_attach(dev);
5424 netif_wake_queue(dev);
5425 enable_interrupts(ai);
5431 static int __init airo_init_module( void )
5433 int i, have_isa_dev = 0;
5435 airo_entry = create_proc_entry("aironet",
5436 S_IFDIR | airo_perm,
5438 airo_entry->uid = proc_uid;
5439 airo_entry->gid = proc_gid;
5441 for( i = 0; i < 4 && io[i] && irq[i]; i++ ) {
5443 "airo: Trying to configure ISA adapter at irq=%d io=0x%x\n",
5445 if (init_airo_card( irq[i], io[i], 0 ))
5450 printk( KERN_INFO "airo: Probing for PCI adapters\n" );
5451 pci_register_driver(&airo_driver);
5452 printk( KERN_INFO "airo: Finished probing for PCI adapters\n" );
5455 /* Always exit with success, as we are a library module
5456 * as well as a driver module
5461 static void __exit airo_cleanup_module( void )
5463 while( airo_devices ) {
5464 printk( KERN_INFO "airo: Unregistering %s\n", airo_devices->dev->name );
5465 stop_airo_card( airo_devices->dev, 1 );
5468 pci_unregister_driver(&airo_driver);
5470 remove_proc_entry("aironet", proc_root_driver);
5475 * Initial Wireless Extension code for Aironet driver by :
5476 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
5477 * Conversion to new driver API by :
5478 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
5479 * Javier also did a good amount of work here, adding some new extensions
5480 * and fixing my code. Let's just say that without him this code just
5481 * would not work at all... - Jean II
5484 /*------------------------------------------------------------------*/
5486 * Wireless Handler : get protocol name
5488 static int airo_get_name(struct net_device *dev,
5489 struct iw_request_info *info,
5493 strcpy(cwrq, "IEEE 802.11-DS");
5497 /*------------------------------------------------------------------*/
5499 * Wireless Handler : set frequency
5501 static int airo_set_freq(struct net_device *dev,
5502 struct iw_request_info *info,
5503 struct iw_freq *fwrq,
5506 struct airo_info *local = dev->priv;
5507 int rc = -EINPROGRESS; /* Call commit handler */
5509 /* If setting by frequency, convert to a channel */
5510 if((fwrq->e == 1) &&
5511 (fwrq->m >= (int) 2.412e8) &&
5512 (fwrq->m <= (int) 2.487e8)) {
5513 int f = fwrq->m / 100000;
5515 while((c < 14) && (f != frequency_list[c]))
5517 /* Hack to fall through... */
5521 /* Setting by channel number */
5522 if((fwrq->m > 1000) || (fwrq->e > 0))
5525 int channel = fwrq->m;
5526 /* We should do a better check than that,
5527 * based on the card capability !!! */
5528 if((channel < 1) || (channel > 16)) {
5529 printk(KERN_DEBUG "%s: New channel value of %d is invalid!\n", dev->name, fwrq->m);
5532 readConfigRid(local, 1);
5533 /* Yes ! We can set it !!! */
5534 local->config.channelSet = (u16)(channel - 1);
5535 set_bit (FLAG_COMMIT, &local->flags);
5541 /*------------------------------------------------------------------*/
5543 * Wireless Handler : get frequency
5545 static int airo_get_freq(struct net_device *dev,
5546 struct iw_request_info *info,
5547 struct iw_freq *fwrq,
5550 struct airo_info *local = dev->priv;
5551 StatusRid status_rid; /* Card status info */
5553 readConfigRid(local, 1);
5554 if ((local->config.opmode & 0xFF) == MODE_STA_ESS)
5555 status_rid.channel = local->config.channelSet;
5557 readStatusRid(local, &status_rid, 1);
5559 #ifdef WEXT_USECHANNELS
5560 fwrq->m = ((int)status_rid.channel) + 1;
5564 int f = (int)status_rid.channel;
5565 fwrq->m = frequency_list[f] * 100000;
5573 /*------------------------------------------------------------------*/
5575 * Wireless Handler : set ESSID
5577 static int airo_set_essid(struct net_device *dev,
5578 struct iw_request_info *info,
5579 struct iw_point *dwrq,
5582 struct airo_info *local = dev->priv;
5584 SsidRid SSID_rid; /* SSIDs */
5586 /* Reload the list of current SSID */
5587 readSsidRid(local, &SSID_rid);
5589 /* Check if we asked for `any' */
5590 if(dwrq->flags == 0) {
5591 /* Just send an empty SSID list */
5592 memset(&SSID_rid, 0, sizeof(SSID_rid));
5594 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
5596 /* Check the size of the string */
5597 if(dwrq->length > IW_ESSID_MAX_SIZE+1) {
5600 /* Check if index is valid */
5601 if((index < 0) || (index >= 4)) {
5606 memset(SSID_rid.ssids[index].ssid, 0,
5607 sizeof(SSID_rid.ssids[index].ssid));
5608 memcpy(SSID_rid.ssids[index].ssid, extra, dwrq->length);
5609 SSID_rid.ssids[index].len = dwrq->length - 1;
5611 SSID_rid.len = sizeof(SSID_rid);
5612 /* Write it to the card */
5613 disable_MAC(local, 1);
5614 writeSsidRid(local, &SSID_rid, 1);
5615 enable_MAC(local, &rsp, 1);
5620 /*------------------------------------------------------------------*/
5622 * Wireless Handler : get ESSID
5624 static int airo_get_essid(struct net_device *dev,
5625 struct iw_request_info *info,
5626 struct iw_point *dwrq,
5629 struct airo_info *local = dev->priv;
5630 StatusRid status_rid; /* Card status info */
5632 readStatusRid(local, &status_rid, 1);
5634 /* Note : if dwrq->flags != 0, we should
5635 * get the relevant SSID from the SSID list... */
5637 /* Get the current SSID */
5638 memcpy(extra, status_rid.SSID, status_rid.SSIDlen);
5639 extra[status_rid.SSIDlen] = '\0';
5640 /* If none, we may want to get the one that was set */
5643 dwrq->length = status_rid.SSIDlen + 1;
5644 dwrq->flags = 1; /* active */
5649 /*------------------------------------------------------------------*/
5651 * Wireless Handler : set AP address
5653 static int airo_set_wap(struct net_device *dev,
5654 struct iw_request_info *info,
5655 struct sockaddr *awrq,
5658 struct airo_info *local = dev->priv;
5661 APListRid APList_rid;
5662 static const unsigned char bcast[ETH_ALEN] = { 255, 255, 255, 255, 255, 255 };
5664 if (awrq->sa_family != ARPHRD_ETHER)
5666 else if (!memcmp(bcast, awrq->sa_data, ETH_ALEN)) {
5667 memset(&cmd, 0, sizeof(cmd));
5668 cmd.cmd=CMD_LOSE_SYNC;
5669 if (down_interruptible(&local->sem))
5670 return -ERESTARTSYS;
5671 issuecommand(local, &cmd, &rsp);
5674 memset(&APList_rid, 0, sizeof(APList_rid));
5675 APList_rid.len = sizeof(APList_rid);
5676 memcpy(APList_rid.ap[0], awrq->sa_data, ETH_ALEN);
5677 disable_MAC(local, 1);
5678 writeAPListRid(local, &APList_rid, 1);
5679 enable_MAC(local, &rsp, 1);
5684 /*------------------------------------------------------------------*/
5686 * Wireless Handler : get AP address
5688 static int airo_get_wap(struct net_device *dev,
5689 struct iw_request_info *info,
5690 struct sockaddr *awrq,
5693 struct airo_info *local = dev->priv;
5694 StatusRid status_rid; /* Card status info */
5696 readStatusRid(local, &status_rid, 1);
5698 /* Tentative. This seems to work, wow, I'm lucky !!! */
5699 memcpy(awrq->sa_data, status_rid.bssid[0], ETH_ALEN);
5700 awrq->sa_family = ARPHRD_ETHER;
5705 /*------------------------------------------------------------------*/
5707 * Wireless Handler : set Nickname
5709 static int airo_set_nick(struct net_device *dev,
5710 struct iw_request_info *info,
5711 struct iw_point *dwrq,
5714 struct airo_info *local = dev->priv;
5716 /* Check the size of the string */
5717 if(dwrq->length > 16 + 1) {
5720 readConfigRid(local, 1);
5721 memset(local->config.nodeName, 0, sizeof(local->config.nodeName));
5722 memcpy(local->config.nodeName, extra, dwrq->length);
5723 set_bit (FLAG_COMMIT, &local->flags);
5725 return -EINPROGRESS; /* Call commit handler */
5728 /*------------------------------------------------------------------*/
5730 * Wireless Handler : get Nickname
5732 static int airo_get_nick(struct net_device *dev,
5733 struct iw_request_info *info,
5734 struct iw_point *dwrq,
5737 struct airo_info *local = dev->priv;
5739 readConfigRid(local, 1);
5740 strncpy(extra, local->config.nodeName, 16);
5742 dwrq->length = strlen(extra) + 1;
5747 /*------------------------------------------------------------------*/
5749 * Wireless Handler : set Bit-Rate
5751 static int airo_set_rate(struct net_device *dev,
5752 struct iw_request_info *info,
5753 struct iw_param *vwrq,
5756 struct airo_info *local = dev->priv;
5757 CapabilityRid cap_rid; /* Card capability info */
5761 /* First : get a valid bit rate value */
5762 readCapabilityRid(local, &cap_rid, 1);
5764 /* Which type of value ? */
5765 if((vwrq->value < 8) && (vwrq->value >= 0)) {
5766 /* Setting by rate index */
5767 /* Find value in the magic rate table */
5768 brate = cap_rid.supportedRates[vwrq->value];
5770 /* Setting by frequency value */
5771 u8 normvalue = (u8) (vwrq->value/500000);
5773 /* Check if rate is valid */
5774 for(i = 0 ; i < 8 ; i++) {
5775 if(normvalue == cap_rid.supportedRates[i]) {
5781 /* -1 designed the max rate (mostly auto mode) */
5782 if(vwrq->value == -1) {
5783 /* Get the highest available rate */
5784 for(i = 0 ; i < 8 ; i++) {
5785 if(cap_rid.supportedRates[i] == 0)
5789 brate = cap_rid.supportedRates[i - 1];
5791 /* Check that it is valid */
5796 readConfigRid(local, 1);
5797 /* Now, check if we want a fixed or auto value */
5798 if(vwrq->fixed == 0) {
5799 /* Fill all the rates up to this max rate */
5800 memset(local->config.rates, 0, 8);
5801 for(i = 0 ; i < 8 ; i++) {
5802 local->config.rates[i] = cap_rid.supportedRates[i];
5803 if(local->config.rates[i] == brate)
5808 /* One rate, fixed */
5809 memset(local->config.rates, 0, 8);
5810 local->config.rates[0] = brate;
5812 set_bit (FLAG_COMMIT, &local->flags);
5814 return -EINPROGRESS; /* Call commit handler */
5817 /*------------------------------------------------------------------*/
5819 * Wireless Handler : get Bit-Rate
5821 static int airo_get_rate(struct net_device *dev,
5822 struct iw_request_info *info,
5823 struct iw_param *vwrq,
5826 struct airo_info *local = dev->priv;
5827 StatusRid status_rid; /* Card status info */
5829 readStatusRid(local, &status_rid, 1);
5831 vwrq->value = status_rid.currentXmitRate * 500000;
5832 /* If more than one rate, set auto */
5833 readConfigRid(local, 1);
5834 vwrq->fixed = (local->config.rates[1] == 0);
5839 /*------------------------------------------------------------------*/
5841 * Wireless Handler : set RTS threshold
5843 static int airo_set_rts(struct net_device *dev,
5844 struct iw_request_info *info,
5845 struct iw_param *vwrq,
5848 struct airo_info *local = dev->priv;
5849 int rthr = vwrq->value;
5853 if((rthr < 0) || (rthr > 2312)) {
5856 readConfigRid(local, 1);
5857 local->config.rtsThres = rthr;
5858 set_bit (FLAG_COMMIT, &local->flags);
5860 return -EINPROGRESS; /* Call commit handler */
5863 /*------------------------------------------------------------------*/
5865 * Wireless Handler : get RTS threshold
5867 static int airo_get_rts(struct net_device *dev,
5868 struct iw_request_info *info,
5869 struct iw_param *vwrq,
5872 struct airo_info *local = dev->priv;
5874 readConfigRid(local, 1);
5875 vwrq->value = local->config.rtsThres;
5876 vwrq->disabled = (vwrq->value >= 2312);
5882 /*------------------------------------------------------------------*/
5884 * Wireless Handler : set Fragmentation threshold
5886 static int airo_set_frag(struct net_device *dev,
5887 struct iw_request_info *info,
5888 struct iw_param *vwrq,
5891 struct airo_info *local = dev->priv;
5892 int fthr = vwrq->value;
5896 if((fthr < 256) || (fthr > 2312)) {
5899 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
5900 readConfigRid(local, 1);
5901 local->config.fragThresh = (u16)fthr;
5902 set_bit (FLAG_COMMIT, &local->flags);
5904 return -EINPROGRESS; /* Call commit handler */
5907 /*------------------------------------------------------------------*/
5909 * Wireless Handler : get Fragmentation threshold
5911 static int airo_get_frag(struct net_device *dev,
5912 struct iw_request_info *info,
5913 struct iw_param *vwrq,
5916 struct airo_info *local = dev->priv;
5918 readConfigRid(local, 1);
5919 vwrq->value = local->config.fragThresh;
5920 vwrq->disabled = (vwrq->value >= 2312);
5926 /*------------------------------------------------------------------*/
5928 * Wireless Handler : set Mode of Operation
5930 static int airo_set_mode(struct net_device *dev,
5931 struct iw_request_info *info,
5935 struct airo_info *local = dev->priv;
5938 readConfigRid(local, 1);
5939 if ((local->config.rmode & 0xff) >= RXMODE_RFMON)
5944 local->config.opmode &= 0xFF00;
5945 local->config.opmode |= MODE_STA_IBSS;
5946 local->config.rmode &= 0xfe00;
5947 local->config.scanMode = SCANMODE_ACTIVE;
5948 clear_bit (FLAG_802_11, &local->flags);
5951 local->config.opmode &= 0xFF00;
5952 local->config.opmode |= MODE_STA_ESS;
5953 local->config.rmode &= 0xfe00;
5954 local->config.scanMode = SCANMODE_ACTIVE;
5955 clear_bit (FLAG_802_11, &local->flags);
5957 case IW_MODE_MASTER:
5958 local->config.opmode &= 0xFF00;
5959 local->config.opmode |= MODE_AP;
5960 local->config.rmode &= 0xfe00;
5961 local->config.scanMode = SCANMODE_ACTIVE;
5962 clear_bit (FLAG_802_11, &local->flags);
5964 case IW_MODE_REPEAT:
5965 local->config.opmode &= 0xFF00;
5966 local->config.opmode |= MODE_AP_RPTR;
5967 local->config.rmode &= 0xfe00;
5968 local->config.scanMode = SCANMODE_ACTIVE;
5969 clear_bit (FLAG_802_11, &local->flags);
5971 case IW_MODE_MONITOR:
5972 local->config.opmode &= 0xFF00;
5973 local->config.opmode |= MODE_STA_ESS;
5974 local->config.rmode &= 0xfe00;
5975 local->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
5976 local->config.scanMode = SCANMODE_PASSIVE;
5977 set_bit (FLAG_802_11, &local->flags);
5983 set_bit (FLAG_RESET, &local->flags);
5984 set_bit (FLAG_COMMIT, &local->flags);
5986 return -EINPROGRESS; /* Call commit handler */
5989 /*------------------------------------------------------------------*/
5991 * Wireless Handler : get Mode of Operation
5993 static int airo_get_mode(struct net_device *dev,
5994 struct iw_request_info *info,
5998 struct airo_info *local = dev->priv;
6000 readConfigRid(local, 1);
6001 /* If not managed, assume it's ad-hoc */
6002 switch (local->config.opmode & 0xFF) {
6004 *uwrq = IW_MODE_INFRA;
6007 *uwrq = IW_MODE_MASTER;
6010 *uwrq = IW_MODE_REPEAT;
6013 *uwrq = IW_MODE_ADHOC;
6019 /*------------------------------------------------------------------*/
6021 * Wireless Handler : set Encryption Key
6023 static int airo_set_encode(struct net_device *dev,
6024 struct iw_request_info *info,
6025 struct iw_point *dwrq,
6028 struct airo_info *local = dev->priv;
6029 CapabilityRid cap_rid; /* Card capability info */
6031 /* Is WEP supported ? */
6032 readCapabilityRid(local, &cap_rid, 1);
6033 /* Older firmware doesn't support this...
6034 if(!(cap_rid.softCap & 2)) {
6037 readConfigRid(local, 1);
6039 /* Basic checking: do we have a key to set ?
6040 * Note : with the new API, it's impossible to get a NULL pointer.
6041 * Therefore, we need to check a key size == 0 instead.
6042 * New version of iwconfig properly set the IW_ENCODE_NOKEY flag
6043 * when no key is present (only change flags), but older versions
6044 * don't do it. - Jean II */
6045 if (dwrq->length > 0) {
6047 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6048 int current_index = get_wep_key(local, 0xffff);
6049 /* Check the size of the key */
6050 if (dwrq->length > MAX_KEY_SIZE) {
6053 /* Check the index (none -> use current) */
6054 if ((index < 0) || (index >= ((cap_rid.softCap & 0x80) ? 4:1)))
6055 index = current_index;
6056 /* Set the length */
6057 if (dwrq->length > MIN_KEY_SIZE)
6058 key.len = MAX_KEY_SIZE;
6060 if (dwrq->length > 0)
6061 key.len = MIN_KEY_SIZE;
6063 /* Disable the key */
6065 /* Check if the key is not marked as invalid */
6066 if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
6068 memset(key.key, 0, MAX_KEY_SIZE);
6069 /* Copy the key in the driver */
6070 memcpy(key.key, extra, dwrq->length);
6071 /* Send the key to the card */
6072 set_wep_key(local, index, key.key, key.len, 1, 1);
6074 /* WE specify that if a valid key is set, encryption
6075 * should be enabled (user may turn it off later)
6076 * This is also how "iwconfig ethX key on" works */
6077 if((index == current_index) && (key.len > 0) &&
6078 (local->config.authType == AUTH_OPEN)) {
6079 local->config.authType = AUTH_ENCRYPT;
6080 set_bit (FLAG_COMMIT, &local->flags);
6083 /* Do we want to just set the transmit key index ? */
6084 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6085 if ((index >= 0) && (index < ((cap_rid.softCap & 0x80)?4:1))) {
6086 set_wep_key(local, index, 0, 0, 1, 1);
6088 /* Don't complain if only change the mode */
6089 if(!dwrq->flags & IW_ENCODE_MODE) {
6093 /* Read the flags */
6094 if(dwrq->flags & IW_ENCODE_DISABLED)
6095 local->config.authType = AUTH_OPEN; // disable encryption
6096 if(dwrq->flags & IW_ENCODE_RESTRICTED)
6097 local->config.authType = AUTH_SHAREDKEY; // Only Both
6098 if(dwrq->flags & IW_ENCODE_OPEN)
6099 local->config.authType = AUTH_ENCRYPT; // Only Wep
6100 /* Commit the changes to flags if needed */
6101 if(dwrq->flags & IW_ENCODE_MODE)
6102 set_bit (FLAG_COMMIT, &local->flags);
6103 return -EINPROGRESS; /* Call commit handler */
6106 /*------------------------------------------------------------------*/
6108 * Wireless Handler : get Encryption Key
6110 static int airo_get_encode(struct net_device *dev,
6111 struct iw_request_info *info,
6112 struct iw_point *dwrq,
6115 struct airo_info *local = dev->priv;
6116 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6117 CapabilityRid cap_rid; /* Card capability info */
6119 /* Is it supported ? */
6120 readCapabilityRid(local, &cap_rid, 1);
6121 if(!(cap_rid.softCap & 2)) {
6124 readConfigRid(local, 1);
6125 /* Check encryption mode */
6126 switch(local->config.authType) {
6128 dwrq->flags = IW_ENCODE_OPEN;
6130 case AUTH_SHAREDKEY:
6131 dwrq->flags = IW_ENCODE_RESTRICTED;
6135 dwrq->flags = IW_ENCODE_DISABLED;
6138 /* We can't return the key, so set the proper flag and return zero */
6139 dwrq->flags |= IW_ENCODE_NOKEY;
6140 memset(extra, 0, 16);
6142 /* Which key do we want ? -1 -> tx index */
6143 if ((index < 0) || (index >= ((cap_rid.softCap & 0x80) ? 4 : 1)))
6144 index = get_wep_key(local, 0xffff);
6145 dwrq->flags |= index + 1;
6146 /* Copy the key to the user buffer */
6147 dwrq->length = get_wep_key(local, index);
6148 if (dwrq->length > 16) {
6154 /*------------------------------------------------------------------*/
6156 * Wireless Handler : set Tx-Power
6158 static int airo_set_txpow(struct net_device *dev,
6159 struct iw_request_info *info,
6160 struct iw_param *vwrq,
6163 struct airo_info *local = dev->priv;
6164 CapabilityRid cap_rid; /* Card capability info */
6168 readCapabilityRid(local, &cap_rid, 1);
6170 if (vwrq->disabled) {
6171 set_bit (FLAG_RADIO_OFF | FLAG_COMMIT, &local->flags);
6172 return -EINPROGRESS; /* Call commit handler */
6174 if (vwrq->flags != IW_TXPOW_MWATT) {
6177 clear_bit (FLAG_RADIO_OFF, &local->flags);
6178 for (i = 0; cap_rid.txPowerLevels[i] && (i < 8); i++)
6179 if ((vwrq->value==cap_rid.txPowerLevels[i])) {
6180 readConfigRid(local, 1);
6181 local->config.txPower = vwrq->value;
6182 set_bit (FLAG_COMMIT, &local->flags);
6183 rc = -EINPROGRESS; /* Call commit handler */
6189 /*------------------------------------------------------------------*/
6191 * Wireless Handler : get Tx-Power
6193 static int airo_get_txpow(struct net_device *dev,
6194 struct iw_request_info *info,
6195 struct iw_param *vwrq,
6198 struct airo_info *local = dev->priv;
6200 readConfigRid(local, 1);
6201 vwrq->value = local->config.txPower;
6202 vwrq->fixed = 1; /* No power control */
6203 vwrq->disabled = test_bit(FLAG_RADIO_OFF, &local->flags);
6204 vwrq->flags = IW_TXPOW_MWATT;
6209 /*------------------------------------------------------------------*/
6211 * Wireless Handler : set Retry limits
6213 static int airo_set_retry(struct net_device *dev,
6214 struct iw_request_info *info,
6215 struct iw_param *vwrq,
6218 struct airo_info *local = dev->priv;
6221 if(vwrq->disabled) {
6224 readConfigRid(local, 1);
6225 if(vwrq->flags & IW_RETRY_LIMIT) {
6226 if(vwrq->flags & IW_RETRY_MAX)
6227 local->config.longRetryLimit = vwrq->value;
6228 else if (vwrq->flags & IW_RETRY_MIN)
6229 local->config.shortRetryLimit = vwrq->value;
6231 /* No modifier : set both */
6232 local->config.longRetryLimit = vwrq->value;
6233 local->config.shortRetryLimit = vwrq->value;
6235 set_bit (FLAG_COMMIT, &local->flags);
6236 rc = -EINPROGRESS; /* Call commit handler */
6238 if(vwrq->flags & IW_RETRY_LIFETIME) {
6239 local->config.txLifetime = vwrq->value / 1024;
6240 set_bit (FLAG_COMMIT, &local->flags);
6241 rc = -EINPROGRESS; /* Call commit handler */
6246 /*------------------------------------------------------------------*/
6248 * Wireless Handler : get Retry limits
6250 static int airo_get_retry(struct net_device *dev,
6251 struct iw_request_info *info,
6252 struct iw_param *vwrq,
6255 struct airo_info *local = dev->priv;
6257 vwrq->disabled = 0; /* Can't be disabled */
6259 readConfigRid(local, 1);
6260 /* Note : by default, display the min retry number */
6261 if((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
6262 vwrq->flags = IW_RETRY_LIFETIME;
6263 vwrq->value = (int)local->config.txLifetime * 1024;
6264 } else if((vwrq->flags & IW_RETRY_MAX)) {
6265 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
6266 vwrq->value = (int)local->config.longRetryLimit;
6268 vwrq->flags = IW_RETRY_LIMIT;
6269 vwrq->value = (int)local->config.shortRetryLimit;
6270 if((int)local->config.shortRetryLimit != (int)local->config.longRetryLimit)
6271 vwrq->flags |= IW_RETRY_MIN;
6277 /*------------------------------------------------------------------*/
6279 * Wireless Handler : get range info
6281 static int airo_get_range(struct net_device *dev,
6282 struct iw_request_info *info,
6283 struct iw_point *dwrq,
6286 struct airo_info *local = dev->priv;
6287 struct iw_range *range = (struct iw_range *) extra;
6288 CapabilityRid cap_rid; /* Card capability info */
6292 readCapabilityRid(local, &cap_rid, 1);
6294 dwrq->length = sizeof(struct iw_range);
6295 memset(range, 0, sizeof(*range));
6296 range->min_nwid = 0x0000;
6297 range->max_nwid = 0x0000;
6298 range->num_channels = 14;
6299 /* Should be based on cap_rid.country to give only
6300 * what the current card support */
6302 for(i = 0; i < 14; i++) {
6303 range->freq[k].i = i + 1; /* List index */
6304 range->freq[k].m = frequency_list[i] * 100000;
6305 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
6307 range->num_frequency = k;
6309 /* Hum... Should put the right values there */
6310 range->max_qual.qual = 10;
6311 range->max_qual.level = 0x100 - 120; /* -120 dBm */
6312 range->max_qual.noise = 0;
6313 range->sensitivity = 65535;
6315 for(i = 0 ; i < 8 ; i++) {
6316 range->bitrate[i] = cap_rid.supportedRates[i] * 500000;
6317 if(range->bitrate[i] == 0)
6320 range->num_bitrates = i;
6322 /* Set an indication of the max TCP throughput
6323 * in bit/s that we can expect using this interface.
6324 * May be use for QoS stuff... Jean II */
6326 range->throughput = 5000 * 1000;
6328 range->throughput = 1500 * 1000;
6331 range->max_rts = 2312;
6332 range->min_frag = 256;
6333 range->max_frag = 2312;
6335 if(cap_rid.softCap & 2) {
6337 range->encoding_size[0] = 5;
6339 if (cap_rid.softCap & 0x100) {
6340 range->encoding_size[1] = 13;
6341 range->num_encoding_sizes = 2;
6343 range->num_encoding_sizes = 1;
6344 range->max_encoding_tokens = (cap_rid.softCap & 0x80) ? 4 : 1;
6346 range->num_encoding_sizes = 0;
6347 range->max_encoding_tokens = 0;
6350 range->max_pmp = 5000000; /* 5 secs */
6352 range->max_pmt = 65535 * 1024; /* ??? */
6353 range->pmp_flags = IW_POWER_PERIOD;
6354 range->pmt_flags = IW_POWER_TIMEOUT;
6355 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
6357 /* Transmit Power - values are in mW */
6358 for(i = 0 ; i < 8 ; i++) {
6359 range->txpower[i] = cap_rid.txPowerLevels[i];
6360 if(range->txpower[i] == 0)
6363 range->num_txpower = i;
6364 range->txpower_capa = IW_TXPOW_MWATT;
6365 range->we_version_source = 12;
6366 range->we_version_compiled = WIRELESS_EXT;
6367 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
6368 range->retry_flags = IW_RETRY_LIMIT;
6369 range->r_time_flags = IW_RETRY_LIFETIME;
6370 range->min_retry = 1;
6371 range->max_retry = 65535;
6372 range->min_r_time = 1024;
6373 range->max_r_time = 65535 * 1024;
6374 /* Experimental measurements - boundary 11/5.5 Mb/s */
6375 /* Note : with or without the (local->rssi), results
6376 * are somewhat different. - Jean II */
6377 range->avg_qual.qual = 6;
6379 range->avg_qual.level = 186; /* -70 dBm */
6381 range->avg_qual.level = 176; /* -80 dBm */
6382 range->avg_qual.noise = 0;
6387 /*------------------------------------------------------------------*/
6389 * Wireless Handler : set Power Management
6391 static int airo_set_power(struct net_device *dev,
6392 struct iw_request_info *info,
6393 struct iw_param *vwrq,
6396 struct airo_info *local = dev->priv;
6398 readConfigRid(local, 1);
6399 if (vwrq->disabled) {
6400 if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
6403 local->config.powerSaveMode = POWERSAVE_CAM;
6404 local->config.rmode &= 0xFF00;
6405 local->config.rmode |= RXMODE_BC_MC_ADDR;
6406 set_bit (FLAG_COMMIT, &local->flags);
6407 return -EINPROGRESS; /* Call commit handler */
6409 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
6410 local->config.fastListenDelay = (vwrq->value + 500) / 1024;
6411 local->config.powerSaveMode = POWERSAVE_PSPCAM;
6412 set_bit (FLAG_COMMIT, &local->flags);
6413 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
6414 local->config.fastListenInterval = local->config.listenInterval = (vwrq->value + 500) / 1024;
6415 local->config.powerSaveMode = POWERSAVE_PSPCAM;
6416 set_bit (FLAG_COMMIT, &local->flags);
6418 switch (vwrq->flags & IW_POWER_MODE) {
6419 case IW_POWER_UNICAST_R:
6420 if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
6423 local->config.rmode &= 0xFF00;
6424 local->config.rmode |= RXMODE_ADDR;
6425 set_bit (FLAG_COMMIT, &local->flags);
6427 case IW_POWER_ALL_R:
6428 if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
6431 local->config.rmode &= 0xFF00;
6432 local->config.rmode |= RXMODE_BC_MC_ADDR;
6433 set_bit (FLAG_COMMIT, &local->flags);
6439 // Note : we may want to factor local->need_commit here
6440 // Note2 : may also want to factor RXMODE_RFMON test
6441 return -EINPROGRESS; /* Call commit handler */
6444 /*------------------------------------------------------------------*/
6446 * Wireless Handler : get Power Management
6448 static int airo_get_power(struct net_device *dev,
6449 struct iw_request_info *info,
6450 struct iw_param *vwrq,
6453 struct airo_info *local = dev->priv;
6456 readConfigRid(local, 1);
6457 mode = local->config.powerSaveMode;
6458 if ((vwrq->disabled = (mode == POWERSAVE_CAM)))
6460 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
6461 vwrq->value = (int)local->config.fastListenDelay * 1024;
6462 vwrq->flags = IW_POWER_TIMEOUT;
6464 vwrq->value = (int)local->config.fastListenInterval * 1024;
6465 vwrq->flags = IW_POWER_PERIOD;
6467 if ((local->config.rmode & 0xFF) == RXMODE_ADDR)
6468 vwrq->flags |= IW_POWER_UNICAST_R;
6470 vwrq->flags |= IW_POWER_ALL_R;
6475 /*------------------------------------------------------------------*/
6477 * Wireless Handler : set Sensitivity
6479 static int airo_set_sens(struct net_device *dev,
6480 struct iw_request_info *info,
6481 struct iw_param *vwrq,
6484 struct airo_info *local = dev->priv;
6486 readConfigRid(local, 1);
6487 local->config.rssiThreshold = vwrq->disabled ? RSSI_DEFAULT : vwrq->value;
6488 set_bit (FLAG_COMMIT, &local->flags);
6490 return -EINPROGRESS; /* Call commit handler */
6493 /*------------------------------------------------------------------*/
6495 * Wireless Handler : get Sensitivity
6497 static int airo_get_sens(struct net_device *dev,
6498 struct iw_request_info *info,
6499 struct iw_param *vwrq,
6502 struct airo_info *local = dev->priv;
6504 readConfigRid(local, 1);
6505 vwrq->value = local->config.rssiThreshold;
6506 vwrq->disabled = (vwrq->value == 0);
6512 /*------------------------------------------------------------------*/
6514 * Wireless Handler : get AP List
6515 * Note : this is deprecated in favor of IWSCAN
6517 static int airo_get_aplist(struct net_device *dev,
6518 struct iw_request_info *info,
6519 struct iw_point *dwrq,
6522 struct airo_info *local = dev->priv;
6523 struct sockaddr *address = (struct sockaddr *) extra;
6524 struct iw_quality qual[IW_MAX_AP];
6527 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
6529 for (i = 0; i < IW_MAX_AP; i++) {
6530 if (readBSSListRid(local, loseSync, &BSSList))
6533 memcpy(address[i].sa_data, BSSList.bssid, ETH_ALEN);
6534 address[i].sa_family = ARPHRD_ETHER;
6536 qual[i].level = 0x100 - local->rssi[BSSList.rssi].rssidBm;
6538 qual[i].level = (BSSList.rssi + 321) / 2;
6539 qual[i].qual = qual[i].noise = 0;
6540 qual[i].updated = 2;
6541 if (BSSList.index == 0xffff)
6545 StatusRid status_rid; /* Card status info */
6546 readStatusRid(local, &status_rid, 1);
6548 i < min(IW_MAX_AP, 4) &&
6549 (status_rid.bssid[i][0]
6550 & status_rid.bssid[i][1]
6551 & status_rid.bssid[i][2]
6552 & status_rid.bssid[i][3]
6553 & status_rid.bssid[i][4]
6554 & status_rid.bssid[i][5])!=0xff &&
6555 (status_rid.bssid[i][0]
6556 | status_rid.bssid[i][1]
6557 | status_rid.bssid[i][2]
6558 | status_rid.bssid[i][3]
6559 | status_rid.bssid[i][4]
6560 | status_rid.bssid[i][5]);
6562 memcpy(address[i].sa_data,
6563 status_rid.bssid[i], ETH_ALEN);
6564 address[i].sa_family = ARPHRD_ETHER;
6567 dwrq->flags = 1; /* Should be define'd */
6568 memcpy(extra + sizeof(struct sockaddr)*i,
6569 &qual, sizeof(struct iw_quality)*i);
6576 /*------------------------------------------------------------------*/
6578 * Wireless Handler : Initiate Scan
6580 static int airo_set_scan(struct net_device *dev,
6581 struct iw_request_info *info,
6582 struct iw_param *vwrq,
6585 struct airo_info *ai = dev->priv;
6589 /* Note : you may have realised that, as this is a SET operation,
6590 * this is privileged and therefore a normal user can't
6592 * This is not an error, while the device perform scanning,
6593 * traffic doesn't flow, so it's a perfect DoS...
6595 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
6597 /* Initiate a scan command */
6598 memset(&cmd, 0, sizeof(cmd));
6599 cmd.cmd=CMD_LISTBSS;
6600 if (down_interruptible(&ai->sem))
6601 return -ERESTARTSYS;
6602 issuecommand(ai, &cmd, &rsp);
6603 ai->scan_timestamp = jiffies;
6606 /* At this point, just return to the user. */
6611 /*------------------------------------------------------------------*/
6613 * Translate scan data returned from the card to a card independent
6614 * format that the Wireless Tools will understand - Jean II
6616 static inline char *airo_translate_scan(struct net_device *dev,
6621 struct airo_info *ai = dev->priv;
6622 struct iw_event iwe; /* Temporary buffer */
6624 char * current_val; /* For rates */
6627 /* First entry *MUST* be the AP MAC address */
6628 iwe.cmd = SIOCGIWAP;
6629 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
6630 memcpy(iwe.u.ap_addr.sa_data, list->bssid, ETH_ALEN);
6631 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
6633 /* Other entries will be displayed in the order we give them */
6636 iwe.u.data.length = list->ssidLen;
6637 if(iwe.u.data.length > 32)
6638 iwe.u.data.length = 32;
6639 iwe.cmd = SIOCGIWESSID;
6640 iwe.u.data.flags = 1;
6641 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, list->ssid);
6644 iwe.cmd = SIOCGIWMODE;
6645 capabilities = le16_to_cpu(list->cap);
6646 if(capabilities & (CAP_ESS | CAP_IBSS)) {
6647 if(capabilities & CAP_ESS)
6648 iwe.u.mode = IW_MODE_MASTER;
6650 iwe.u.mode = IW_MODE_ADHOC;
6651 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
6655 iwe.cmd = SIOCGIWFREQ;
6656 iwe.u.freq.m = le16_to_cpu(list->dsChannel);
6657 iwe.u.freq.m = frequency_list[iwe.u.freq.m] * 100000;
6659 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
6661 /* Add quality statistics */
6664 iwe.u.qual.level = 0x100 - ai->rssi[list->rssi].rssidBm;
6666 iwe.u.qual.level = (list->rssi + 321) / 2;
6667 iwe.u.qual.noise = 0;
6668 iwe.u.qual.qual = 0;
6669 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
6671 /* Add encryption capability */
6672 iwe.cmd = SIOCGIWENCODE;
6673 if(capabilities & CAP_PRIVACY)
6674 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
6676 iwe.u.data.flags = IW_ENCODE_DISABLED;
6677 iwe.u.data.length = 0;
6678 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, list->ssid);
6680 /* Rate : stuffing multiple values in a single event require a bit
6681 * more of magic - Jean II */
6682 current_val = current_ev + IW_EV_LCP_LEN;
6684 iwe.cmd = SIOCGIWRATE;
6685 /* Those two flags are ignored... */
6686 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
6688 for(i = 0 ; i < 8 ; i++) {
6689 /* NULL terminated */
6690 if(list->rates[i] == 0)
6692 /* Bit rate given in 500 kb/s units (+ 0x80) */
6693 iwe.u.bitrate.value = ((list->rates[i] & 0x7f) * 500000);
6694 /* Add new value to event */
6695 current_val = iwe_stream_add_value(current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
6697 /* Check if we added any event */
6698 if((current_val - current_ev) > IW_EV_LCP_LEN)
6699 current_ev = current_val;
6701 /* The other data in the scan result are not really
6702 * interesting, so for now drop it - Jean II */
6706 /*------------------------------------------------------------------*/
6708 * Wireless Handler : Read Scan Results
6710 static int airo_get_scan(struct net_device *dev,
6711 struct iw_request_info *info,
6712 struct iw_point *dwrq,
6715 struct airo_info *ai = dev->priv;
6718 char *current_ev = extra;
6720 /* When we are associated again, the scan has surely finished.
6721 * Just in case, let's make sure enough time has elapsed since
6722 * we started the scan. - Javier */
6723 if(ai->scan_timestamp && time_before(jiffies,ai->scan_timestamp+3*HZ)) {
6724 /* Important note : we don't want to block the caller
6725 * until results are ready for various reasons.
6726 * First, managing wait queues is complex and racy
6727 * (there may be multiple simultaneous callers).
6728 * Second, we grab some rtnetlink lock before comming
6729 * here (in dev_ioctl()).
6730 * Third, the caller can wait on the Wireless Event
6734 ai->scan_timestamp = 0;
6736 /* There's only a race with proc_BSSList_open(), but its
6737 * consequences are begnign. So I don't bother fixing it - Javier */
6739 /* Try to read the first entry of the scan result */
6740 rc = PC4500_readrid(ai, RID_BSSLISTFIRST, &BSSList, sizeof(BSSList), 1);
6741 if((rc) || (BSSList.index == 0xffff)) {
6742 /* Client error, no scan results...
6743 * The caller need to restart the scan. */
6747 /* Read and parse all entries */
6748 while((!rc) && (BSSList.index != 0xffff)) {
6749 /* Translate to WE format this entry */
6750 current_ev = airo_translate_scan(dev, current_ev,
6751 extra + IW_SCAN_MAX_DATA,
6754 /* Read next entry */
6755 rc = PC4500_readrid(ai, RID_BSSLISTNEXT,
6756 &BSSList, sizeof(BSSList), 1);
6758 /* Length of data */
6759 dwrq->length = (current_ev - extra);
6760 dwrq->flags = 0; /* todo */
6765 /*------------------------------------------------------------------*/
6767 * Commit handler : called after a bunch of SET operations
6769 static int airo_config_commit(struct net_device *dev,
6770 struct iw_request_info *info, /* NULL */
6771 void *zwrq, /* NULL */
6772 char *extra) /* NULL */
6774 struct airo_info *local = dev->priv;
6777 if (!test_bit (FLAG_COMMIT, &local->flags))
6780 /* Some of the "SET" function may have modified some of the
6781 * parameters. It's now time to commit them in the card */
6782 disable_MAC(local, 1);
6783 if (test_bit (FLAG_RESET, &local->flags)) {
6784 APListRid APList_rid;
6787 readAPListRid(local, &APList_rid);
6788 readSsidRid(local, &SSID_rid);
6789 reset_airo_card(dev);
6790 disable_MAC(local, 1);
6791 writeSsidRid(local, &SSID_rid, 1);
6792 writeAPListRid(local, &APList_rid, 1);
6794 if (down_interruptible(&local->sem))
6795 return -ERESTARTSYS;
6796 writeConfigRid(local, 0);
6797 enable_MAC(local, &rsp, 0);
6798 if (test_bit (FLAG_RESET, &local->flags))
6799 airo_set_promisc(local);
6806 /*------------------------------------------------------------------*/
6808 * Structures to export the Wireless Handlers
6811 static const struct iw_priv_args airo_private_args[] = {
6812 /*{ cmd, set_args, get_args, name } */
6813 { AIROIOCTL, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
6814 IW_PRIV_TYPE_BYTE | 2047, "airoioctl" },
6815 { AIROIDIFC, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
6816 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "airoidifc" },
6819 static const iw_handler airo_handler[] =
6821 (iw_handler) airo_config_commit, /* SIOCSIWCOMMIT */
6822 (iw_handler) airo_get_name, /* SIOCGIWNAME */
6823 (iw_handler) NULL, /* SIOCSIWNWID */
6824 (iw_handler) NULL, /* SIOCGIWNWID */
6825 (iw_handler) airo_set_freq, /* SIOCSIWFREQ */
6826 (iw_handler) airo_get_freq, /* SIOCGIWFREQ */
6827 (iw_handler) airo_set_mode, /* SIOCSIWMODE */
6828 (iw_handler) airo_get_mode, /* SIOCGIWMODE */
6829 (iw_handler) airo_set_sens, /* SIOCSIWSENS */
6830 (iw_handler) airo_get_sens, /* SIOCGIWSENS */
6831 (iw_handler) NULL, /* SIOCSIWRANGE */
6832 (iw_handler) airo_get_range, /* SIOCGIWRANGE */
6833 (iw_handler) NULL, /* SIOCSIWPRIV */
6834 (iw_handler) NULL, /* SIOCGIWPRIV */
6835 (iw_handler) NULL, /* SIOCSIWSTATS */
6836 (iw_handler) NULL, /* SIOCGIWSTATS */
6837 iw_handler_set_spy, /* SIOCSIWSPY */
6838 iw_handler_get_spy, /* SIOCGIWSPY */
6839 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
6840 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
6841 (iw_handler) airo_set_wap, /* SIOCSIWAP */
6842 (iw_handler) airo_get_wap, /* SIOCGIWAP */
6843 (iw_handler) NULL, /* -- hole -- */
6844 (iw_handler) airo_get_aplist, /* SIOCGIWAPLIST */
6845 (iw_handler) airo_set_scan, /* SIOCSIWSCAN */
6846 (iw_handler) airo_get_scan, /* SIOCGIWSCAN */
6847 (iw_handler) airo_set_essid, /* SIOCSIWESSID */
6848 (iw_handler) airo_get_essid, /* SIOCGIWESSID */
6849 (iw_handler) airo_set_nick, /* SIOCSIWNICKN */
6850 (iw_handler) airo_get_nick, /* SIOCGIWNICKN */
6851 (iw_handler) NULL, /* -- hole -- */
6852 (iw_handler) NULL, /* -- hole -- */
6853 (iw_handler) airo_set_rate, /* SIOCSIWRATE */
6854 (iw_handler) airo_get_rate, /* SIOCGIWRATE */
6855 (iw_handler) airo_set_rts, /* SIOCSIWRTS */
6856 (iw_handler) airo_get_rts, /* SIOCGIWRTS */
6857 (iw_handler) airo_set_frag, /* SIOCSIWFRAG */
6858 (iw_handler) airo_get_frag, /* SIOCGIWFRAG */
6859 (iw_handler) airo_set_txpow, /* SIOCSIWTXPOW */
6860 (iw_handler) airo_get_txpow, /* SIOCGIWTXPOW */
6861 (iw_handler) airo_set_retry, /* SIOCSIWRETRY */
6862 (iw_handler) airo_get_retry, /* SIOCGIWRETRY */
6863 (iw_handler) airo_set_encode, /* SIOCSIWENCODE */
6864 (iw_handler) airo_get_encode, /* SIOCGIWENCODE */
6865 (iw_handler) airo_set_power, /* SIOCSIWPOWER */
6866 (iw_handler) airo_get_power, /* SIOCGIWPOWER */
6869 /* Note : don't describe AIROIDIFC and AIROOLDIDIFC in here.
6870 * We want to force the use of the ioctl code, because those can't be
6871 * won't work the iw_handler code (because they simultaneously read
6872 * and write data and iw_handler can't do that).
6873 * Note that it's perfectly legal to read/write on a single ioctl command,
6874 * you just can't use iwpriv and need to force it via the ioctl handler.
6876 static const iw_handler airo_private_handler[] =
6878 NULL, /* SIOCIWFIRSTPRIV */
6881 static const struct iw_handler_def airo_handler_def =
6883 .num_standard = sizeof(airo_handler)/sizeof(iw_handler),
6884 .num_private = sizeof(airo_private_handler)/sizeof(iw_handler),
6885 .num_private_args = sizeof(airo_private_args)/sizeof(struct iw_priv_args),
6886 .standard = (iw_handler *) airo_handler,
6887 .private = (iw_handler *) airo_private_handler,
6888 .private_args = (struct iw_priv_args *) airo_private_args,
6889 .spy_offset = ((void *) (&((struct airo_info *) NULL)->spy_data) -
6894 #endif /* WIRELESS_EXT */
6897 * This defines the configuration part of the Wireless Extensions
6898 * Note : irq and spinlock protection will occur in the subroutines
6901 * o Check input value more carefully and fill correct values in range
6902 * o Test and shakeout the bugs (if any)
6906 * Javier Achirica did a great job of merging code from the unnamed CISCO
6907 * developer that added support for flashing the card.
6909 static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
6912 struct airo_info *ai = (struct airo_info *)dev->priv;
6924 int val = AIROMAGIC;
6926 if (copy_from_user(&com,rq->ifr_data,sizeof(com)))
6928 else if (copy_to_user(com.data,(char *)&val,sizeof(val)))
6937 /* Get the command struct and hand it off for evaluation by
6938 * the proper subfunction
6942 if (copy_from_user(&com,rq->ifr_data,sizeof(com))) {
6947 /* Separate R/W functions bracket legality here
6949 if ( com.command <= AIRORRID )
6950 rc = readrids(dev,&com);
6951 else if ( com.command >= AIROPCAP && com.command <= AIROPLEAPUSR )
6952 rc = writerids(dev,&com);
6953 else if ( com.command >= AIROFLSHRST && com.command <= AIRORESTART )
6954 rc = flashcard(dev,&com);
6956 rc = -EINVAL; /* Bad command in ioctl */
6959 #endif /* CISCO_EXT */
6961 // All other calls are currently unsupported
6970 * Get the Wireless stats out of the driver
6971 * Note : irq and spinlock protection will occur in the subroutines
6974 * o Check if work in Ad-Hoc mode (otherwise, use SPY, as in wvlan_cs)
6978 static void airo_read_wireless_stats(struct airo_info *local)
6980 StatusRid status_rid;
6982 u32 *vals = stats_rid.vals;
6984 /* Get stats out of the card */
6985 clear_bit(JOB_WSTATS, &local->flags);
6990 readStatusRid(local, &status_rid, 0);
6991 readStatsRid(local, &stats_rid, RID_STATS, 0);
6995 local->wstats.status = status_rid.mode;
6997 /* Signal quality and co. But where is the noise level ??? */
6998 local->wstats.qual.qual = status_rid.signalQuality;
7000 local->wstats.qual.level = 0x100 - local->rssi[status_rid.sigQuality].rssidBm;
7002 local->wstats.qual.level = (status_rid.normalizedSignalStrength + 321) / 2;
7003 if (status_rid.len >= 124) {
7004 local->wstats.qual.noise = 256 - status_rid.noisedBm;
7005 local->wstats.qual.updated = 7;
7007 local->wstats.qual.noise = 0;
7008 local->wstats.qual.updated = 3;
7011 /* Packets discarded in the wireless adapter due to wireless
7012 * specific problems */
7013 local->wstats.discard.nwid = vals[56] + vals[57] + vals[58];/* SSID Mismatch */
7014 local->wstats.discard.code = vals[6];/* RxWepErr */
7015 local->wstats.discard.fragment = vals[30];
7016 local->wstats.discard.retries = vals[10];
7017 local->wstats.discard.misc = vals[1] + vals[32];
7018 local->wstats.miss.beacon = vals[34];
7021 struct iw_statistics *airo_get_wireless_stats(struct net_device *dev)
7023 struct airo_info *local = dev->priv;
7025 /* Get stats out of the card if available */
7026 if (down_trylock(&local->sem) != 0) {
7027 set_bit(JOB_WSTATS, &local->flags);
7028 wake_up_interruptible(&local->thr_wait);
7030 airo_read_wireless_stats(local);
7032 return &local->wstats;
7034 #endif /* WIRELESS_EXT */
7038 * This just translates from driver IOCTL codes to the command codes to
7039 * feed to the radio's host interface. Things can be added/deleted
7040 * as needed. This represents the READ side of control I/O to
7043 static int readrids(struct net_device *dev, aironet_ioctl *comp) {
7044 unsigned short ridcode;
7045 unsigned char *iobuf;
7047 struct airo_info *ai = dev->priv;
7049 if (test_bit(FLAG_FLASHING, &ai->flags))
7052 switch(comp->command)
7054 case AIROGCAP: ridcode = RID_CAPABILITIES; break;
7055 case AIROGCFG: writeConfigRid (ai, 1);
7056 ridcode = RID_CONFIG; break;
7057 case AIROGSLIST: ridcode = RID_SSID; break;
7058 case AIROGVLIST: ridcode = RID_APLIST; break;
7059 case AIROGDRVNAM: ridcode = RID_DRVNAME; break;
7060 case AIROGEHTENC: ridcode = RID_ETHERENCAP; break;
7061 case AIROGWEPKTMP: ridcode = RID_WEP_TEMP;
7062 /* Only super-user can read WEP keys */
7063 if (!capable(CAP_NET_ADMIN))
7066 case AIROGWEPKNV: ridcode = RID_WEP_PERM;
7067 /* Only super-user can read WEP keys */
7068 if (!capable(CAP_NET_ADMIN))
7071 case AIROGSTAT: ridcode = RID_STATUS; break;
7072 case AIROGSTATSD32: ridcode = RID_STATSDELTA; break;
7073 case AIROGSTATSC32: ridcode = RID_STATS; break;
7076 if (copy_to_user(comp->data, &ai->micstats,
7077 min((int)comp->len,(int)sizeof(ai->micstats))))
7081 case AIRORRID: ridcode = comp->len; break;
7087 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7090 PC4500_readrid(ai,ridcode,iobuf,RIDSIZE, 1);
7091 /* get the count of bytes in the rid docs say 1st 2 bytes is it.
7092 * then return it to the user
7093 * 9/22/2000 Honor user given length
7095 if (comp->command == AIRORRID)
7096 len = le16_to_cpu(*(unsigned short *)iobuf); /* Yuck! */
7100 if (copy_to_user(comp->data, iobuf, min(len, (int)RIDSIZE))) {
7109 * Danger Will Robinson write the rids here
7112 static int writerids(struct net_device *dev, aironet_ioctl *comp) {
7113 struct airo_info *ai = dev->priv;
7119 static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
7120 unsigned char *iobuf;
7122 /* Only super-user can write RIDs */
7123 if (!capable(CAP_NET_ADMIN))
7126 if (test_bit(FLAG_FLASHING, &ai->flags))
7130 writer = do_writerid;
7132 switch(comp->command)
7134 case AIROPSIDS: ridcode = RID_SSID; break;
7135 case AIROPCAP: ridcode = RID_CAPABILITIES; break;
7136 case AIROPAPLIST: ridcode = RID_APLIST; break;
7137 case AIROPCFG: ai->config.len = 0;
7138 ridcode = RID_CONFIG; break;
7139 case AIROPWEPKEYNV: ridcode = RID_WEP_PERM; break;
7140 case AIROPLEAPUSR: ridcode = RID_LEAPUSERNAME; break;
7141 case AIROPLEAPPWD: ridcode = RID_LEAPPASSWORD; break;
7142 case AIROPWEPKEY: ridcode = RID_WEP_TEMP; writer = PC4500_writerid;
7145 /* this is not really a rid but a command given to the card
7149 if (enable_MAC(ai, &rsp, 1) != 0)
7154 * Evidently this code in the airo driver does not get a symbol
7155 * as disable_MAC. it's probably so short the compiler does not gen one.
7161 /* This command merely clears the counts does not actually store any data
7162 * only reads rid. But as it changes the cards state, I put it in the
7163 * writerid routines.
7166 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7169 PC4500_readrid(ai,RID_STATSDELTACLEAR,iobuf,RIDSIZE, 1);
7172 enabled = ai->micstats.enabled;
7173 memset(&ai->micstats,0,sizeof(ai->micstats));
7174 ai->micstats.enabled = enabled;
7177 if (copy_to_user(comp->data, iobuf,
7178 min((int)comp->len, (int)RIDSIZE))) {
7186 return -EOPNOTSUPP; /* Blarg! */
7188 if(comp->len > RIDSIZE)
7191 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7194 if (copy_from_user(iobuf,comp->data,comp->len)) {
7199 if (comp->command == AIROPCFG) {
7200 ConfigRid *cfg = (ConfigRid *)iobuf;
7202 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags))
7203 cfg->opmode |= MODE_MIC;
7205 if ((cfg->opmode & 0xFF) == MODE_STA_IBSS)
7206 set_bit (FLAG_ADHOC, &ai->flags);
7208 clear_bit (FLAG_ADHOC, &ai->flags);
7211 if((*writer)(ai, ridcode, iobuf,comp->len,1)) {
7219 /*****************************************************************************
7220 * Ancillary flash / mod functions much black magic lurkes here *
7221 *****************************************************************************
7225 * Flash command switch table
7228 int flashcard(struct net_device *dev, aironet_ioctl *comp) {
7230 int cmdreset(struct airo_info *);
7231 int setflashmode(struct airo_info *);
7232 int flashgchar(struct airo_info *,int,int);
7233 int flashpchar(struct airo_info *,int,int);
7234 int flashputbuf(struct airo_info *);
7235 int flashrestart(struct airo_info *,struct net_device *);
7237 /* Only super-user can modify flash */
7238 if (!capable(CAP_NET_ADMIN))
7241 switch(comp->command)
7244 return cmdreset((struct airo_info *)dev->priv);
7247 if (!((struct airo_info *)dev->priv)->flash &&
7248 (((struct airo_info *)dev->priv)->flash = kmalloc (FLASHSIZE, GFP_KERNEL)) == NULL)
7250 return setflashmode((struct airo_info *)dev->priv);
7252 case AIROFLSHGCHR: /* Get char from aux */
7253 if(comp->len != sizeof(int))
7255 if (copy_from_user(&z,comp->data,comp->len))
7257 return flashgchar((struct airo_info *)dev->priv,z,8000);
7259 case AIROFLSHPCHR: /* Send char to card. */
7260 if(comp->len != sizeof(int))
7262 if (copy_from_user(&z,comp->data,comp->len))
7264 return flashpchar((struct airo_info *)dev->priv,z,8000);
7266 case AIROFLPUTBUF: /* Send 32k to card */
7267 if (!((struct airo_info *)dev->priv)->flash)
7269 if(comp->len > FLASHSIZE)
7271 if(copy_from_user(((struct airo_info *)dev->priv)->flash,comp->data,comp->len))
7274 flashputbuf((struct airo_info *)dev->priv);
7278 if(flashrestart((struct airo_info *)dev->priv,dev))
7285 #define FLASH_COMMAND 0x7e7e
7289 * Disable MAC and do soft reset on
7293 int cmdreset(struct airo_info *ai) {
7297 printk(KERN_INFO "Waitbusy hang before RESET\n");
7301 OUT4500(ai,COMMAND,CMD_SOFTRESET);
7303 set_current_state (TASK_UNINTERRUPTIBLE);
7304 schedule_timeout (HZ); /* WAS 600 12/7/00 */
7307 printk(KERN_INFO "Waitbusy hang AFTER RESET\n");
7314 * Put the card in legendary flash
7318 int setflashmode (struct airo_info *ai) {
7319 set_bit (FLAG_FLASHING, &ai->flags);
7321 OUT4500(ai, SWS0, FLASH_COMMAND);
7322 OUT4500(ai, SWS1, FLASH_COMMAND);
7324 OUT4500(ai, SWS0, FLASH_COMMAND);
7325 OUT4500(ai, COMMAND,0x10);
7327 OUT4500(ai, SWS2, FLASH_COMMAND);
7328 OUT4500(ai, SWS3, FLASH_COMMAND);
7329 OUT4500(ai, COMMAND,0);
7331 set_current_state (TASK_UNINTERRUPTIBLE);
7332 schedule_timeout (HZ/2); /* 500ms delay */
7335 clear_bit (FLAG_FLASHING, &ai->flags);
7336 printk(KERN_INFO "Waitbusy hang after setflash mode\n");
7342 /* Put character to SWS0 wait for dwelltime
7346 int flashpchar(struct airo_info *ai,int byte,int dwelltime) {
7357 /* Wait for busy bit d15 to go false indicating buffer empty */
7358 while ((IN4500 (ai, SWS0) & 0x8000) && waittime > 0) {
7363 /* timeout for busy clear wait */
7365 printk(KERN_INFO "flash putchar busywait timeout! \n");
7369 /* Port is clear now write byte and wait for it to echo back */
7371 OUT4500(ai,SWS0,byte);
7374 echo = IN4500(ai,SWS1);
7375 } while (dwelltime >= 0 && echo != byte);
7379 return (echo == byte) ? 0 : -EIO;
7383 * Get a character from the card matching matchbyte
7386 int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime){
7388 unsigned char rbyte=0;
7391 rchar = IN4500(ai,SWS1);
7393 if(dwelltime && !(0x8000 & rchar)){
7398 rbyte = 0xff & rchar;
7400 if( (rbyte == matchbyte) && (0x8000 & rchar) ){
7404 if( rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
7408 }while(dwelltime > 0);
7413 * Transfer 32k of firmware data from user buffer to our buffer and
7417 int flashputbuf(struct airo_info *ai){
7421 if (test_bit(FLAG_MPI,&ai->flags))
7422 memcpy(ai->pciaux + 0x8000, ai->flash, FLASHSIZE);
7424 OUT4500(ai,AUXPAGE,0x100);
7425 OUT4500(ai,AUXOFF,0);
7427 for(nwords=0;nwords != FLASHSIZE / 2;nwords++){
7428 OUT4500(ai,AUXDATA,ai->flash[nwords] & 0xffff);
7431 OUT4500(ai,SWS0,0x8000);
7439 int flashrestart(struct airo_info *ai,struct net_device *dev){
7442 set_current_state (TASK_UNINTERRUPTIBLE);
7443 schedule_timeout (HZ); /* Added 12/7/00 */
7444 clear_bit (FLAG_FLASHING, &ai->flags);
7445 status = setup_card(ai, dev->dev_addr, 1);
7447 if (!test_bit(FLAG_MPI,&ai->flags))
7448 for( i = 0; i < MAX_FIDS; i++ ) {
7449 ai->fids[i] = transmit_allocate
7450 ( ai, 2312, i >= MAX_FIDS / 2 );
7453 set_current_state (TASK_UNINTERRUPTIBLE);
7454 schedule_timeout (HZ); /* Added 12/7/00 */
7457 #endif /* CISCO_EXT */
7460 This program is free software; you can redistribute it and/or
7461 modify it under the terms of the GNU General Public License
7462 as published by the Free Software Foundation; either version 2
7463 of the License, or (at your option) any later version.
7465 This program is distributed in the hope that it will be useful,
7466 but WITHOUT ANY WARRANTY; without even the implied warranty of
7467 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7468 GNU General Public License for more details.
7472 Redistribution and use in source and binary forms, with or without
7473 modification, are permitted provided that the following conditions
7476 1. Redistributions of source code must retain the above copyright
7477 notice, this list of conditions and the following disclaimer.
7478 2. Redistributions in binary form must reproduce the above copyright
7479 notice, this list of conditions and the following disclaimer in the
7480 documentation and/or other materials provided with the distribution.
7481 3. The name of the author may not be used to endorse or promote
7482 products derived from this software without specific prior written
7485 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
7486 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
7487 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7488 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
7489 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
7490 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
7491 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
7492 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
7493 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
7494 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
7495 POSSIBILITY OF SUCH DAMAGE.
7498 module_init(airo_init_module);
7499 module_exit(airo_cleanup_module);