1 /*======================================================================
3 Aironet driver for 4500 and 4800 series cards
5 This code is released under both the GPL version 2 and BSD licenses.
6 Either license may be used. The respective licenses are found at
9 This code was developed by Benjamin Reed <breed@users.sourceforge.net>
10 including portions of which come from the Aironet PC4500
11 Developer's Reference Manual and used with permission. Copyright
12 (C) 1999 Benjamin Reed. All Rights Reserved. Permission to use
13 code in the Developer's manual was granted for this driver by
14 Aironet. Major code contributions were received from Javier Achirica
15 <achirica@users.sourceforge.net> and Jean Tourrilhes <jt@hpl.hp.com>.
16 Code was also integrated from the Cisco Aironet driver for Linux.
17 Support for MPI350 cards was added by Fabrice Bellet
18 <fabrice@bellet.info>.
20 ======================================================================*/
22 #include <linux/err.h>
23 #include <linux/init.h>
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/proc_fs.h>
29 #include <linux/sched.h>
30 #include <linux/ptrace.h>
31 #include <linux/slab.h>
32 #include <linux/string.h>
33 #include <linux/timer.h>
34 #include <linux/interrupt.h>
36 #include <linux/bitops.h>
37 #include <linux/scatterlist.h>
38 #include <linux/crypto.h>
40 #include <asm/system.h>
41 #include <asm/unaligned.h>
43 #include <linux/netdevice.h>
44 #include <linux/etherdevice.h>
45 #include <linux/skbuff.h>
46 #include <linux/if_arp.h>
47 #include <linux/ioport.h>
48 #include <linux/pci.h>
49 #include <asm/uaccess.h>
50 #include <linux/kthread.h>
51 #include <linux/freezer.h>
53 #include <linux/ieee80211.h>
57 #define DRV_NAME "airo"
60 static struct pci_device_id card_ids[] = {
61 { 0x14b9, 1, PCI_ANY_ID, PCI_ANY_ID, },
62 { 0x14b9, 0x4500, PCI_ANY_ID, PCI_ANY_ID },
63 { 0x14b9, 0x4800, PCI_ANY_ID, PCI_ANY_ID, },
64 { 0x14b9, 0x0340, PCI_ANY_ID, PCI_ANY_ID, },
65 { 0x14b9, 0x0350, PCI_ANY_ID, PCI_ANY_ID, },
66 { 0x14b9, 0x5000, PCI_ANY_ID, PCI_ANY_ID, },
67 { 0x14b9, 0xa504, PCI_ANY_ID, PCI_ANY_ID, },
70 MODULE_DEVICE_TABLE(pci, card_ids);
72 static int airo_pci_probe(struct pci_dev *, const struct pci_device_id *);
73 static void airo_pci_remove(struct pci_dev *);
74 static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state);
75 static int airo_pci_resume(struct pci_dev *pdev);
77 static struct pci_driver airo_driver = {
80 .probe = airo_pci_probe,
81 .remove = __devexit_p(airo_pci_remove),
82 .suspend = airo_pci_suspend,
83 .resume = airo_pci_resume,
85 #endif /* CONFIG_PCI */
87 /* Include Wireless Extension definition and check version - Jean II */
88 #include <linux/wireless.h>
89 #define WIRELESS_SPY /* enable iwspy support */
90 #include <net/iw_handler.h> /* New driver API */
92 #define CISCO_EXT /* enable Cisco extensions */
94 #include <linux/delay.h>
97 /* Hack to do some power saving */
100 /* As you can see this list is HUGH!
101 I really don't know what a lot of these counts are about, but they
102 are all here for completeness. If the IGNLABEL macro is put in
103 infront of the label, that statistic will not be included in the list
104 of statistics in the /proc filesystem */
106 #define IGNLABEL(comment) NULL
107 static char *statsLabels[] = {
109 IGNLABEL("RxPlcpCrcErr"),
110 IGNLABEL("RxPlcpFormatErr"),
111 IGNLABEL("RxPlcpLengthErr"),
142 "LostSync-MissedBeacons",
143 "LostSync-ArlExceeded",
145 "LostSync-Disassoced",
146 "LostSync-TsfTiming",
155 IGNLABEL("HmacTxMc"),
156 IGNLABEL("HmacTxBc"),
157 IGNLABEL("HmacTxUc"),
158 IGNLABEL("HmacTxFail"),
159 IGNLABEL("HmacRxMc"),
160 IGNLABEL("HmacRxBc"),
161 IGNLABEL("HmacRxUc"),
162 IGNLABEL("HmacRxDiscard"),
163 IGNLABEL("HmacRxAccepted"),
171 IGNLABEL("ReasonOutsideTable"),
172 IGNLABEL("ReasonStatus1"),
173 IGNLABEL("ReasonStatus2"),
174 IGNLABEL("ReasonStatus3"),
175 IGNLABEL("ReasonStatus4"),
176 IGNLABEL("ReasonStatus5"),
177 IGNLABEL("ReasonStatus6"),
178 IGNLABEL("ReasonStatus7"),
179 IGNLABEL("ReasonStatus8"),
180 IGNLABEL("ReasonStatus9"),
181 IGNLABEL("ReasonStatus10"),
182 IGNLABEL("ReasonStatus11"),
183 IGNLABEL("ReasonStatus12"),
184 IGNLABEL("ReasonStatus13"),
185 IGNLABEL("ReasonStatus14"),
186 IGNLABEL("ReasonStatus15"),
187 IGNLABEL("ReasonStatus16"),
188 IGNLABEL("ReasonStatus17"),
189 IGNLABEL("ReasonStatus18"),
190 IGNLABEL("ReasonStatus19"),
210 #define RUN_AT(x) (jiffies+(x))
214 /* These variables are for insmod, since it seems that the rates
215 can only be set in setup_card. Rates should be a comma separated
216 (no spaces) list of rates (up to 8). */
219 static int basic_rate;
220 static char *ssids[3];
226 int maxencrypt /* = 0 */; /* The highest rate that the card can encrypt at.
227 0 means no limit. For old cards this was 4 */
229 static int auto_wep /* = 0 */; /* If set, it tries to figure out the wep mode */
230 static int aux_bap /* = 0 */; /* Checks to see if the aux ports are needed to read
231 the bap, needed on some older cards and buses. */
234 static int probe = 1;
236 static int proc_uid /* = 0 */;
238 static int proc_gid /* = 0 */;
240 static int airo_perm = 0555;
242 static int proc_perm = 0644;
244 MODULE_AUTHOR("Benjamin Reed");
245 MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet \
246 cards. Direct support for ISA/PCI/MPI cards and support \
247 for PCMCIA when used with airo_cs.");
248 MODULE_LICENSE("Dual BSD/GPL");
249 MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340/350");
250 module_param_array(io, int, NULL, 0);
251 module_param_array(irq, int, NULL, 0);
252 module_param(basic_rate, int, 0);
253 module_param_array(rates, int, NULL, 0);
254 module_param_array(ssids, charp, NULL, 0);
255 module_param(auto_wep, int, 0);
256 MODULE_PARM_DESC(auto_wep, "If non-zero, the driver will keep looping through \
257 the authentication options until an association is made. The value of \
258 auto_wep is number of the wep keys to check. A value of 2 will try using \
259 the key at index 0 and index 1.");
260 module_param(aux_bap, int, 0);
261 MODULE_PARM_DESC(aux_bap, "If non-zero, the driver will switch into a mode \
262 than seems to work better for older cards with some older buses. Before \
263 switching it checks that the switch is needed.");
264 module_param(maxencrypt, int, 0);
265 MODULE_PARM_DESC(maxencrypt, "The maximum speed that the card can do \
266 encryption. Units are in 512kbs. Zero (default) means there is no limit. \
267 Older cards used to be limited to 2mbs (4).");
268 module_param(adhoc, int, 0);
269 MODULE_PARM_DESC(adhoc, "If non-zero, the card will start in adhoc mode.");
270 module_param(probe, int, 0);
271 MODULE_PARM_DESC(probe, "If zero, the driver won't start the card.");
273 module_param(proc_uid, int, 0);
274 MODULE_PARM_DESC(proc_uid, "The uid that the /proc files will belong to.");
275 module_param(proc_gid, int, 0);
276 MODULE_PARM_DESC(proc_gid, "The gid that the /proc files will belong to.");
277 module_param(airo_perm, int, 0);
278 MODULE_PARM_DESC(airo_perm, "The permission bits of /proc/[driver/]aironet.");
279 module_param(proc_perm, int, 0);
280 MODULE_PARM_DESC(proc_perm, "The permission bits of the files in /proc");
282 /* This is a kind of sloppy hack to get this information to OUT4500 and
283 IN4500. I would be extremely interested in the situation where this
284 doesn't work though!!! */
285 static int do8bitIO /* = 0 */;
294 #define MAC_ENABLE 0x0001
295 #define MAC_DISABLE 0x0002
296 #define CMD_LOSE_SYNC 0x0003 /* Not sure what this does... */
297 #define CMD_SOFTRESET 0x0004
298 #define HOSTSLEEP 0x0005
299 #define CMD_MAGIC_PKT 0x0006
300 #define CMD_SETWAKEMASK 0x0007
301 #define CMD_READCFG 0x0008
302 #define CMD_SETMODE 0x0009
303 #define CMD_ALLOCATETX 0x000a
304 #define CMD_TRANSMIT 0x000b
305 #define CMD_DEALLOCATETX 0x000c
307 #define CMD_WORKAROUND 0x0011
308 #define CMD_ALLOCATEAUX 0x0020
309 #define CMD_ACCESS 0x0021
310 #define CMD_PCIBAP 0x0022
311 #define CMD_PCIAUX 0x0023
312 #define CMD_ALLOCBUF 0x0028
313 #define CMD_GETTLV 0x0029
314 #define CMD_PUTTLV 0x002a
315 #define CMD_DELTLV 0x002b
316 #define CMD_FINDNEXTTLV 0x002c
317 #define CMD_PSPNODES 0x0030
318 #define CMD_SETCW 0x0031
319 #define CMD_SETPCF 0x0032
320 #define CMD_SETPHYREG 0x003e
321 #define CMD_TXTEST 0x003f
322 #define MAC_ENABLETX 0x0101
323 #define CMD_LISTBSS 0x0103
324 #define CMD_SAVECFG 0x0108
325 #define CMD_ENABLEAUX 0x0111
326 #define CMD_WRITERID 0x0121
327 #define CMD_USEPSPNODES 0x0130
328 #define MAC_ENABLERX 0x0201
331 #define ERROR_QUALIF 0x00
332 #define ERROR_ILLCMD 0x01
333 #define ERROR_ILLFMT 0x02
334 #define ERROR_INVFID 0x03
335 #define ERROR_INVRID 0x04
336 #define ERROR_LARGE 0x05
337 #define ERROR_NDISABL 0x06
338 #define ERROR_ALLOCBSY 0x07
339 #define ERROR_NORD 0x0B
340 #define ERROR_NOWR 0x0C
341 #define ERROR_INVFIDTX 0x0D
342 #define ERROR_TESTACT 0x0E
343 #define ERROR_TAGNFND 0x12
344 #define ERROR_DECODE 0x20
345 #define ERROR_DESCUNAV 0x21
346 #define ERROR_BADLEN 0x22
347 #define ERROR_MODE 0x80
348 #define ERROR_HOP 0x81
349 #define ERROR_BINTER 0x82
350 #define ERROR_RXMODE 0x83
351 #define ERROR_MACADDR 0x84
352 #define ERROR_RATES 0x85
353 #define ERROR_ORDER 0x86
354 #define ERROR_SCAN 0x87
355 #define ERROR_AUTH 0x88
356 #define ERROR_PSMODE 0x89
357 #define ERROR_RTYPE 0x8A
358 #define ERROR_DIVER 0x8B
359 #define ERROR_SSID 0x8C
360 #define ERROR_APLIST 0x8D
361 #define ERROR_AUTOWAKE 0x8E
362 #define ERROR_LEAP 0x8F
373 #define LINKSTAT 0x10
377 #define TXALLOCFID 0x22
378 #define TXCOMPLFID 0x24
393 /* Offset into aux memory for descriptors */
394 #define AUX_OFFSET 0x800
395 /* Size of allocated packets */
398 /* Size of the transmit queue */
402 #define BAP0 0 /* Used for receiving packets */
403 #define BAP1 2 /* Used for xmiting packets and working with RIDS */
406 #define COMMAND_BUSY 0x8000
408 #define BAP_BUSY 0x8000
409 #define BAP_ERR 0x4000
410 #define BAP_DONE 0x2000
412 #define PROMISC 0xffff
413 #define NOPROMISC 0x0000
416 #define EV_CLEARCOMMANDBUSY 0x4000
419 #define EV_TXEXC 0x04
420 #define EV_ALLOC 0x08
422 #define EV_AWAKE 0x100
423 #define EV_TXCPY 0x400
424 #define EV_UNKNOWN 0x800
425 #define EV_MIC 0x1000 /* Message Integrity Check Interrupt */
426 #define EV_AWAKEN 0x2000
427 #define STATUS_INTS (EV_AWAKE|EV_LINK|EV_TXEXC|EV_TX|EV_TXCPY|EV_RX|EV_MIC)
429 #ifdef CHECK_UNKNOWN_INTS
430 #define IGNORE_INTS ( EV_CMD | EV_UNKNOWN)
432 #define IGNORE_INTS (~STATUS_INTS)
439 #define RID_CAPABILITIES 0xFF00
440 #define RID_APINFO 0xFF01
441 #define RID_RADIOINFO 0xFF02
442 #define RID_UNKNOWN3 0xFF03
443 #define RID_RSSI 0xFF04
444 #define RID_CONFIG 0xFF10
445 #define RID_SSID 0xFF11
446 #define RID_APLIST 0xFF12
447 #define RID_DRVNAME 0xFF13
448 #define RID_ETHERENCAP 0xFF14
449 #define RID_WEP_TEMP 0xFF15
450 #define RID_WEP_PERM 0xFF16
451 #define RID_MODULATION 0xFF17
452 #define RID_OPTIONS 0xFF18
453 #define RID_ACTUALCONFIG 0xFF20 /*readonly*/
454 #define RID_FACTORYCONFIG 0xFF21
455 #define RID_UNKNOWN22 0xFF22
456 #define RID_LEAPUSERNAME 0xFF23
457 #define RID_LEAPPASSWORD 0xFF24
458 #define RID_STATUS 0xFF50
459 #define RID_BEACON_HST 0xFF51
460 #define RID_BUSY_HST 0xFF52
461 #define RID_RETRIES_HST 0xFF53
462 #define RID_UNKNOWN54 0xFF54
463 #define RID_UNKNOWN55 0xFF55
464 #define RID_UNKNOWN56 0xFF56
465 #define RID_MIC 0xFF57
466 #define RID_STATS16 0xFF60
467 #define RID_STATS16DELTA 0xFF61
468 #define RID_STATS16DELTACLEAR 0xFF62
469 #define RID_STATS 0xFF68
470 #define RID_STATSDELTA 0xFF69
471 #define RID_STATSDELTACLEAR 0xFF6A
472 #define RID_ECHOTEST_RID 0xFF70
473 #define RID_ECHOTEST_RESULTS 0xFF71
474 #define RID_BSSLISTFIRST 0xFF72
475 #define RID_BSSLISTNEXT 0xFF73
476 #define RID_WPA_BSSLISTFIRST 0xFF74
477 #define RID_WPA_BSSLISTNEXT 0xFF75
494 * Rids and endian-ness: The Rids will always be in cpu endian, since
495 * this all the patches from the big-endian guys end up doing that.
496 * so all rid access should use the read/writeXXXRid routines.
499 /* This is redundant for x86 archs, but it seems necessary for ARM */
502 /* This structure came from an email sent to me from an engineer at
503 aironet for inclusion into this driver */
512 /* These structures are from the Aironet's PC4500 Developers Manual */
526 #define MOD_DEFAULT cpu_to_le16(0)
527 #define MOD_CCK cpu_to_le16(1)
528 #define MOD_MOK cpu_to_le16(2)
532 __le16 len; /* sizeof(ConfigRid) */
533 __le16 opmode; /* operating mode */
534 #define MODE_STA_IBSS cpu_to_le16(0)
535 #define MODE_STA_ESS cpu_to_le16(1)
536 #define MODE_AP cpu_to_le16(2)
537 #define MODE_AP_RPTR cpu_to_le16(3)
538 #define MODE_CFG_MASK cpu_to_le16(0xff)
539 #define MODE_ETHERNET_HOST cpu_to_le16(0<<8) /* rx payloads converted */
540 #define MODE_LLC_HOST cpu_to_le16(1<<8) /* rx payloads left as is */
541 #define MODE_AIRONET_EXTEND cpu_to_le16(1<<9) /* enable Aironet extenstions */
542 #define MODE_AP_INTERFACE cpu_to_le16(1<<10) /* enable ap interface extensions */
543 #define MODE_ANTENNA_ALIGN cpu_to_le16(1<<11) /* enable antenna alignment */
544 #define MODE_ETHER_LLC cpu_to_le16(1<<12) /* enable ethernet LLC */
545 #define MODE_LEAF_NODE cpu_to_le16(1<<13) /* enable leaf node bridge */
546 #define MODE_CF_POLLABLE cpu_to_le16(1<<14) /* enable CF pollable */
547 #define MODE_MIC cpu_to_le16(1<<15) /* enable MIC */
548 __le16 rmode; /* receive mode */
549 #define RXMODE_BC_MC_ADDR cpu_to_le16(0)
550 #define RXMODE_BC_ADDR cpu_to_le16(1) /* ignore multicasts */
551 #define RXMODE_ADDR cpu_to_le16(2) /* ignore multicast and broadcast */
552 #define RXMODE_RFMON cpu_to_le16(3) /* wireless monitor mode */
553 #define RXMODE_RFMON_ANYBSS cpu_to_le16(4)
554 #define RXMODE_LANMON cpu_to_le16(5) /* lan style monitor -- data packets only */
555 #define RXMODE_MASK cpu_to_le16(255)
556 #define RXMODE_DISABLE_802_3_HEADER cpu_to_le16(1<<8) /* disables 802.3 header on rx */
557 #define RXMODE_FULL_MASK (RXMODE_MASK | RXMODE_DISABLE_802_3_HEADER)
558 #define RXMODE_NORMALIZED_RSSI cpu_to_le16(1<<9) /* return normalized RSSI */
561 u8 macAddr[ETH_ALEN];
563 __le16 shortRetryLimit;
564 __le16 longRetryLimit;
565 __le16 txLifetime; /* in kusec */
566 __le16 rxLifetime; /* in kusec */
569 __le16 u16deviceType; /* for overriding device type */
572 __le16 _reserved1[3];
573 /*---------- Scanning/Associating ----------*/
575 #define SCANMODE_ACTIVE cpu_to_le16(0)
576 #define SCANMODE_PASSIVE cpu_to_le16(1)
577 #define SCANMODE_AIROSCAN cpu_to_le16(2)
578 __le16 probeDelay; /* in kusec */
579 __le16 probeEnergyTimeout; /* in kusec */
580 __le16 probeResponseTimeout;
581 __le16 beaconListenTimeout;
582 __le16 joinNetTimeout;
585 #define AUTH_OPEN cpu_to_le16(0x1)
586 #define AUTH_ENCRYPT cpu_to_le16(0x101)
587 #define AUTH_SHAREDKEY cpu_to_le16(0x102)
588 #define AUTH_ALLOW_UNENCRYPTED cpu_to_le16(0x200)
589 __le16 associationTimeout;
590 __le16 specifiedApTimeout;
591 __le16 offlineScanInterval;
592 __le16 offlineScanDuration;
593 __le16 linkLossDelay;
594 __le16 maxBeaconLostTime;
595 __le16 refreshInterval;
596 #define DISABLE_REFRESH cpu_to_le16(0xFFFF)
597 __le16 _reserved1a[1];
598 /*---------- Power save operation ----------*/
599 __le16 powerSaveMode;
600 #define POWERSAVE_CAM cpu_to_le16(0)
601 #define POWERSAVE_PSP cpu_to_le16(1)
602 #define POWERSAVE_PSPCAM cpu_to_le16(2)
603 __le16 sleepForDtims;
604 __le16 listenInterval;
605 __le16 fastListenInterval;
607 __le16 fastListenDelay;
608 __le16 _reserved2[2];
609 /*---------- Ap/Ibss config items ----------*/
616 __le16 bridgeDistance;
618 /*---------- Radio configuration ----------*/
620 #define RADIOTYPE_DEFAULT cpu_to_le16(0)
621 #define RADIOTYPE_802_11 cpu_to_le16(1)
622 #define RADIOTYPE_LEGACY cpu_to_le16(2)
626 #define TXPOWER_DEFAULT 0
627 __le16 rssiThreshold;
628 #define RSSI_DEFAULT 0
630 #define PREAMBLE_AUTO cpu_to_le16(0)
631 #define PREAMBLE_LONG cpu_to_le16(1)
632 #define PREAMBLE_SHORT cpu_to_le16(2)
635 __le16 radioSpecific;
636 /*---------- Aironet Extensions ----------*/
641 __le16 _reserved4[1];
642 /*---------- Aironet Extensions ----------*/
644 #define MAGIC_ACTION_STSCHG 1
645 #define MAGIC_ACTION_RESUME 2
646 #define MAGIC_IGNORE_MCAST (1<<8)
647 #define MAGIC_IGNORE_BCAST (1<<9)
648 #define MAGIC_SWITCH_TO_PSP (0<<10)
649 #define MAGIC_STAY_IN_CAM (1<<10)
663 u8 bssid[4][ETH_ALEN];
670 __le16 hopsToBackbone;
672 __le16 generatedLoad;
673 __le16 accumulatedArl;
674 __le16 signalQuality;
675 __le16 currentXmitRate;
676 __le16 apDevExtensions;
677 __le16 normalizedSignalStrength;
678 __le16 shortPreamble;
680 u8 noisePercent; /* Noise percent in last second */
681 u8 noisedBm; /* Noise dBm in last second */
682 u8 noiseAvePercent; /* Noise percent in last minute */
683 u8 noiseAvedBm; /* Noise dBm in last minute */
684 u8 noiseMaxPercent; /* Highest noise percent in last minute */
685 u8 noiseMaxdBm; /* Highest noise dbm in last minute */
689 #define STAT_NOPACKETS 0
690 #define STAT_NOCARRIERSET 10
691 #define STAT_GOTCARRIERSET 11
692 #define STAT_WRONGSSID 20
693 #define STAT_BADCHANNEL 25
694 #define STAT_BADBITRATES 30
695 #define STAT_BADPRIVACY 35
696 #define STAT_APFOUND 40
697 #define STAT_APREJECTED 50
698 #define STAT_AUTHENTICATING 60
699 #define STAT_DEAUTHENTICATED 61
700 #define STAT_AUTHTIMEOUT 62
701 #define STAT_ASSOCIATING 70
702 #define STAT_DEASSOCIATED 71
703 #define STAT_ASSOCTIMEOUT 72
704 #define STAT_NOTAIROAP 73
705 #define STAT_ASSOCIATED 80
706 #define STAT_LEAPING 90
707 #define STAT_LEAPFAILED 91
708 #define STAT_LEAPTIMEDOUT 92
709 #define STAT_LEAPCOMPLETE 93
732 char factoryAddr[ETH_ALEN];
733 char aironetAddr[ETH_ALEN];
736 char callid[ETH_ALEN];
737 char supportedRates[8];
740 __le16 txPowerLevels[8];
754 /* Only present on firmware >= 5.30.17 */
757 u8 fixed[12]; /* WLAN management frame */
763 __le16 index; /* First is 0 and 0xffff means end of list */
764 #define RADIO_FH 1 /* Frequency hopping radio type */
765 #define RADIO_DS 2 /* Direct sequence radio type */
766 #define RADIO_TMA 4 /* Proprietary radio used in old cards (2500) */
768 u8 bssid[ETH_ALEN]; /* Mac address of the BSS */
773 #define CAP_ESS cpu_to_le16(1<<0)
774 #define CAP_IBSS cpu_to_le16(1<<1)
775 #define CAP_PRIVACY cpu_to_le16(1<<4)
776 #define CAP_SHORTHDR cpu_to_le16(1<<5)
778 __le16 beaconInterval;
779 u8 rates[8]; /* Same as rates for config rid */
780 struct { /* For frequency hopping only */
790 /* Only present on firmware >= 5.30.17 */
791 BSSListRidExtra extra;
796 struct list_head list;
842 #define TXCTL_TXOK (1<<1) /* report if tx is ok */
843 #define TXCTL_TXEX (1<<2) /* report if tx fails */
844 #define TXCTL_802_3 (0<<3) /* 802.3 packet */
845 #define TXCTL_802_11 (1<<3) /* 802.11 mac packet */
846 #define TXCTL_ETHERNET (0<<4) /* payload has ethertype */
847 #define TXCTL_LLC (1<<4) /* payload is llc */
848 #define TXCTL_RELEASE (0<<5) /* release after completion */
849 #define TXCTL_NORELEASE (1<<5) /* on completion returns to host */
851 #define BUSY_FID 0x10000
854 #define AIROMAGIC 0xa55a
855 /* Warning : SIOCDEVPRIVATE may disapear during 2.5.X - Jean II */
856 #ifdef SIOCIWFIRSTPRIV
857 #ifdef SIOCDEVPRIVATE
858 #define AIROOLDIOCTL SIOCDEVPRIVATE
859 #define AIROOLDIDIFC AIROOLDIOCTL + 1
860 #endif /* SIOCDEVPRIVATE */
861 #else /* SIOCIWFIRSTPRIV */
862 #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
863 #endif /* SIOCIWFIRSTPRIV */
864 /* This may be wrong. When using the new SIOCIWFIRSTPRIV range, we probably
865 * should use only "GET" ioctls (last bit set to 1). "SET" ioctls are root
866 * only and don't return the modified struct ifreq to the application which
867 * is usually a problem. - Jean II */
868 #define AIROIOCTL SIOCIWFIRSTPRIV
869 #define AIROIDIFC AIROIOCTL + 1
871 /* Ioctl constants to be used in airo_ioctl.command */
873 #define AIROGCAP 0 // Capability rid
874 #define AIROGCFG 1 // USED A LOT
875 #define AIROGSLIST 2 // System ID list
876 #define AIROGVLIST 3 // List of specified AP's
877 #define AIROGDRVNAM 4 // NOTUSED
878 #define AIROGEHTENC 5 // NOTUSED
879 #define AIROGWEPKTMP 6
880 #define AIROGWEPKNV 7
882 #define AIROGSTATSC32 9
883 #define AIROGSTATSD32 10
884 #define AIROGMICRID 11
885 #define AIROGMICSTATS 12
886 #define AIROGFLAGS 13
889 #define AIRORSWVERSION 17
891 /* Leave gap of 40 commands after AIROGSTATSD32 for future */
893 #define AIROPCAP AIROGSTATSD32 + 40
894 #define AIROPVLIST AIROPCAP + 1
895 #define AIROPSLIST AIROPVLIST + 1
896 #define AIROPCFG AIROPSLIST + 1
897 #define AIROPSIDS AIROPCFG + 1
898 #define AIROPAPLIST AIROPSIDS + 1
899 #define AIROPMACON AIROPAPLIST + 1 /* Enable mac */
900 #define AIROPMACOFF AIROPMACON + 1 /* Disable mac */
901 #define AIROPSTCLR AIROPMACOFF + 1
902 #define AIROPWEPKEY AIROPSTCLR + 1
903 #define AIROPWEPKEYNV AIROPWEPKEY + 1
904 #define AIROPLEAPPWD AIROPWEPKEYNV + 1
905 #define AIROPLEAPUSR AIROPLEAPPWD + 1
909 #define AIROFLSHRST AIROPWEPKEYNV + 40
910 #define AIROFLSHGCHR AIROFLSHRST + 1
911 #define AIROFLSHSTFL AIROFLSHGCHR + 1
912 #define AIROFLSHPCHR AIROFLSHSTFL + 1
913 #define AIROFLPUTBUF AIROFLSHPCHR + 1
914 #define AIRORESTART AIROFLPUTBUF + 1
916 #define FLASHSIZE 32768
917 #define AUXMEMSIZE (256 * 1024)
919 typedef struct aironet_ioctl {
920 unsigned short command; // What to do
921 unsigned short len; // Len of data
922 unsigned short ridnum; // rid number
923 unsigned char __user *data; // d-data
926 static char swversion[] = "2.1";
927 #endif /* CISCO_EXT */
929 #define NUM_MODULES 2
930 #define MIC_MSGLEN_MAX 2400
931 #define EMMH32_MSGLEN_MAX MIC_MSGLEN_MAX
932 #define AIRO_DEF_MTU 2312
936 u8 enabled; // MIC enabled or not
937 u32 rxSuccess; // successful packets received
938 u32 rxIncorrectMIC; // pkts dropped due to incorrect MIC comparison
939 u32 rxNotMICed; // pkts dropped due to not being MIC'd
940 u32 rxMICPlummed; // pkts dropped due to not having a MIC plummed
941 u32 rxWrongSequence; // pkts dropped due to sequence number violation
946 u32 coeff[((EMMH32_MSGLEN_MAX)+3)>>2];
947 u64 accum; // accumulated mic, reduced to u32 in final()
948 int position; // current position (byte offset) in message
952 } part; // saves partial message word across update() calls
956 emmh32_context seed; // Context - the seed
957 u32 rx; // Received sequence number
958 u32 tx; // Tx sequence number
959 u32 window; // Start of window
960 u8 valid; // Flag to say if context is valid or not
965 miccntx mCtx; // Multicast context
966 miccntx uCtx; // Unicast context
970 unsigned int rid: 16;
971 unsigned int len: 15;
972 unsigned int valid: 1;
973 dma_addr_t host_addr;
977 unsigned int offset: 15;
979 unsigned int len: 15;
980 unsigned int valid: 1;
981 dma_addr_t host_addr;
985 unsigned int ctl: 15;
987 unsigned int len: 15;
988 unsigned int valid: 1;
989 dma_addr_t host_addr;
993 * Host receive descriptor
996 unsigned char __iomem *card_ram_off; /* offset into card memory of the
998 RxFid rx_desc; /* card receive descriptor */
999 char *virtual_host_addr; /* virtual address of host receive
1005 * Host transmit descriptor
1008 unsigned char __iomem *card_ram_off; /* offset into card memory of the
1010 TxFid tx_desc; /* card transmit descriptor */
1011 char *virtual_host_addr; /* virtual address of host receive
1017 * Host RID descriptor
1020 unsigned char __iomem *card_ram_off; /* offset into card memory of the
1022 Rid rid_desc; /* card RID descriptor */
1023 char *virtual_host_addr; /* virtual address of host receive
1032 #define HOST_SET (1 << 0)
1033 #define HOST_INT_TX (1 << 1) /* Interrupt on successful TX */
1034 #define HOST_INT_TXERR (1 << 2) /* Interrupt on unseccessful TX */
1035 #define HOST_LCC_PAYLOAD (1 << 4) /* LLC payload, 0 = Ethertype */
1036 #define HOST_DONT_RLSE (1 << 5) /* Don't release buffer when done */
1037 #define HOST_DONT_RETRY (1 << 6) /* Don't retry trasmit */
1038 #define HOST_CLR_AID (1 << 7) /* clear AID failure */
1039 #define HOST_RTS (1 << 9) /* Force RTS use */
1040 #define HOST_SHORT (1 << 10) /* Do short preamble */
1067 static WifiCtlHdr wifictlhdr8023 = {
1069 .ctl = HOST_DONT_RLSE,
1073 // A few details needed for WEP (Wireless Equivalent Privacy)
1074 #define MAX_KEY_SIZE 13 // 128 (?) bits
1075 #define MIN_KEY_SIZE 5 // 40 bits RC4 - WEP
1076 typedef struct wep_key_t {
1078 u8 key[16]; /* 40-bit and 104-bit keys */
1081 /* Backward compatibility */
1082 #ifndef IW_ENCODE_NOKEY
1083 #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
1084 #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
1085 #endif /* IW_ENCODE_NOKEY */
1087 /* List of Wireless Handlers (new API) */
1088 static const struct iw_handler_def airo_handler_def;
1090 static const char version[] = "airo.c 0.6 (Ben Reed & Javier Achirica)";
1094 static int get_dec_u16( char *buffer, int *start, int limit );
1095 static void OUT4500( struct airo_info *, u16 register, u16 value );
1096 static unsigned short IN4500( struct airo_info *, u16 register );
1097 static u16 setup_card(struct airo_info*, u8 *mac, int lock);
1098 static int enable_MAC(struct airo_info *ai, int lock);
1099 static void disable_MAC(struct airo_info *ai, int lock);
1100 static void enable_interrupts(struct airo_info*);
1101 static void disable_interrupts(struct airo_info*);
1102 static u16 issuecommand(struct airo_info*, Cmd *pCmd, Resp *pRsp);
1103 static int bap_setup(struct airo_info*, u16 rid, u16 offset, int whichbap);
1104 static int aux_bap_read(struct airo_info*, __le16 *pu16Dst, int bytelen,
1106 static int fast_bap_read(struct airo_info*, __le16 *pu16Dst, int bytelen,
1108 static int bap_write(struct airo_info*, const __le16 *pu16Src, int bytelen,
1110 static int PC4500_accessrid(struct airo_info*, u16 rid, u16 accmd);
1111 static int PC4500_readrid(struct airo_info*, u16 rid, void *pBuf, int len, int lock);
1112 static int PC4500_writerid(struct airo_info*, u16 rid, const void
1113 *pBuf, int len, int lock);
1114 static int do_writerid( struct airo_info*, u16 rid, const void *rid_data,
1115 int len, int dummy );
1116 static u16 transmit_allocate(struct airo_info*, int lenPayload, int raw);
1117 static int transmit_802_3_packet(struct airo_info*, int len, char *pPacket);
1118 static int transmit_802_11_packet(struct airo_info*, int len, char *pPacket);
1120 static int mpi_send_packet (struct net_device *dev);
1121 static void mpi_unmap_card(struct pci_dev *pci);
1122 static void mpi_receive_802_3(struct airo_info *ai);
1123 static void mpi_receive_802_11(struct airo_info *ai);
1124 static int waitbusy (struct airo_info *ai);
1126 static irqreturn_t airo_interrupt( int irq, void* dev_id);
1127 static int airo_thread(void *data);
1128 static void timer_func( struct net_device *dev );
1129 static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
1130 static struct iw_statistics *airo_get_wireless_stats (struct net_device *dev);
1131 static void airo_read_wireless_stats (struct airo_info *local);
1133 static int readrids(struct net_device *dev, aironet_ioctl *comp);
1134 static int writerids(struct net_device *dev, aironet_ioctl *comp);
1135 static int flashcard(struct net_device *dev, aironet_ioctl *comp);
1136 #endif /* CISCO_EXT */
1137 static void micinit(struct airo_info *ai);
1138 static int micsetup(struct airo_info *ai);
1139 static int encapsulate(struct airo_info *ai, etherHead *pPacket, MICBuffer *buffer, int len);
1140 static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *pPacket, u16 payLen);
1142 static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi);
1143 static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm);
1145 static void airo_networks_free(struct airo_info *ai);
1148 struct net_device *dev;
1149 struct list_head dev_list;
1150 /* Note, we can have MAX_FIDS outstanding. FIDs are 16-bits, so we
1151 use the high bit to mark whether it is in use. */
1153 #define MPI_MAX_FIDS 1
1156 char keyindex; // Used with auto wep
1157 char defindex; // Used with auto wep
1158 struct proc_dir_entry *proc_entry;
1159 spinlock_t aux_lock;
1160 #define FLAG_RADIO_OFF 0 /* User disabling of MAC */
1161 #define FLAG_RADIO_DOWN 1 /* ifup/ifdown disabling of MAC */
1162 #define FLAG_RADIO_MASK 0x03
1163 #define FLAG_ENABLED 2
1164 #define FLAG_ADHOC 3 /* Needed by MIC */
1165 #define FLAG_MIC_CAPABLE 4
1166 #define FLAG_UPDATE_MULTI 5
1167 #define FLAG_UPDATE_UNI 6
1168 #define FLAG_802_11 7
1169 #define FLAG_PROMISC 8 /* IFF_PROMISC 0x100 - include/linux/if.h */
1170 #define FLAG_PENDING_XMIT 9
1171 #define FLAG_PENDING_XMIT11 10
1173 #define FLAG_REGISTERED 12
1174 #define FLAG_COMMIT 13
1175 #define FLAG_RESET 14
1176 #define FLAG_FLASHING 15
1177 #define FLAG_WPA_CAPABLE 16
1178 unsigned long flags;
1181 #define JOB_XMIT11 2
1183 #define JOB_PROMISC 4
1186 #define JOB_AUTOWEP 7
1187 #define JOB_WSTATS 8
1188 #define JOB_SCAN_RESULTS 9
1190 int (*bap_read)(struct airo_info*, __le16 *pu16Dst, int bytelen,
1192 unsigned short *flash;
1194 struct task_struct *list_bss_task;
1195 struct task_struct *airo_thread_task;
1196 struct semaphore sem;
1197 wait_queue_head_t thr_wait;
1198 unsigned long expires;
1200 struct sk_buff *skb;
1203 struct net_device *wifidev;
1204 struct iw_statistics wstats; // wireless stats
1205 unsigned long scan_timeout; /* Time scan should be read */
1206 struct iw_spy_data spy_data;
1207 struct iw_public_data wireless_data;
1209 struct crypto_cipher *tfm;
1211 mic_statistics micstats;
1212 HostRxDesc rxfids[MPI_MAX_FIDS]; // rx/tx/config MPI350 descriptors
1213 HostTxDesc txfids[MPI_MAX_FIDS];
1214 HostRidDesc config_desc;
1215 unsigned long ridbus; // phys addr of config_desc
1216 struct sk_buff_head txq;// tx queue used by mpi350 code
1217 struct pci_dev *pci;
1218 unsigned char __iomem *pcimem;
1219 unsigned char __iomem *pciaux;
1220 unsigned char *shared;
1221 dma_addr_t shared_dma;
1225 #define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE
1226 char proc_name[IFNAMSIZ];
1228 /* WPA-related stuff */
1229 unsigned int bssListFirst;
1230 unsigned int bssListNext;
1231 unsigned int bssListRidLen;
1233 struct list_head network_list;
1234 struct list_head network_free_list;
1235 BSSListElement *networks;
1238 static inline int bap_read(struct airo_info *ai, __le16 *pu16Dst, int bytelen,
1241 return ai->bap_read(ai, pu16Dst, bytelen, whichbap);
1244 static int setup_proc_entry( struct net_device *dev,
1245 struct airo_info *apriv );
1246 static int takedown_proc_entry( struct net_device *dev,
1247 struct airo_info *apriv );
1249 static int cmdreset(struct airo_info *ai);
1250 static int setflashmode (struct airo_info *ai);
1251 static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime);
1252 static int flashputbuf(struct airo_info *ai);
1253 static int flashrestart(struct airo_info *ai,struct net_device *dev);
1255 #define airo_print(type, name, fmt, args...) \
1256 printk(type DRV_NAME "(%s): " fmt "\n", name, ##args)
1258 #define airo_print_info(name, fmt, args...) \
1259 airo_print(KERN_INFO, name, fmt, ##args)
1261 #define airo_print_dbg(name, fmt, args...) \
1262 airo_print(KERN_DEBUG, name, fmt, ##args)
1264 #define airo_print_warn(name, fmt, args...) \
1265 airo_print(KERN_WARNING, name, fmt, ##args)
1267 #define airo_print_err(name, fmt, args...) \
1268 airo_print(KERN_ERR, name, fmt, ##args)
1270 #define AIRO_FLASH(dev) (((struct airo_info *)dev->ml_priv)->flash)
1272 /***********************************************************************
1274 ***********************************************************************
1277 static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq);
1278 static void MoveWindow(miccntx *context, u32 micSeq);
1279 static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
1280 struct crypto_cipher *tfm);
1281 static void emmh32_init(emmh32_context *context);
1282 static void emmh32_update(emmh32_context *context, u8 *pOctets, int len);
1283 static void emmh32_final(emmh32_context *context, u8 digest[4]);
1284 static int flashpchar(struct airo_info *ai,int byte,int dwelltime);
1286 /* micinit - Initialize mic seed */
1288 static void micinit(struct airo_info *ai)
1292 clear_bit(JOB_MIC, &ai->jobs);
1293 PC4500_readrid(ai, RID_MIC, &mic_rid, sizeof(mic_rid), 0);
1296 ai->micstats.enabled = (mic_rid.state & 0x00FF) ? 1 : 0;
1298 if (ai->micstats.enabled) {
1299 /* Key must be valid and different */
1300 if (mic_rid.multicastValid && (!ai->mod[0].mCtx.valid ||
1301 (memcmp (ai->mod[0].mCtx.key, mic_rid.multicast,
1302 sizeof(ai->mod[0].mCtx.key)) != 0))) {
1303 /* Age current mic Context */
1304 memcpy(&ai->mod[1].mCtx,&ai->mod[0].mCtx,sizeof(miccntx));
1305 /* Initialize new context */
1306 memcpy(&ai->mod[0].mCtx.key,mic_rid.multicast,sizeof(mic_rid.multicast));
1307 ai->mod[0].mCtx.window = 33; //Window always points to the middle
1308 ai->mod[0].mCtx.rx = 0; //Rx Sequence numbers
1309 ai->mod[0].mCtx.tx = 0; //Tx sequence numbers
1310 ai->mod[0].mCtx.valid = 1; //Key is now valid
1312 /* Give key to mic seed */
1313 emmh32_setseed(&ai->mod[0].mCtx.seed,mic_rid.multicast,sizeof(mic_rid.multicast), ai->tfm);
1316 /* Key must be valid and different */
1317 if (mic_rid.unicastValid && (!ai->mod[0].uCtx.valid ||
1318 (memcmp(ai->mod[0].uCtx.key, mic_rid.unicast,
1319 sizeof(ai->mod[0].uCtx.key)) != 0))) {
1320 /* Age current mic Context */
1321 memcpy(&ai->mod[1].uCtx,&ai->mod[0].uCtx,sizeof(miccntx));
1322 /* Initialize new context */
1323 memcpy(&ai->mod[0].uCtx.key,mic_rid.unicast,sizeof(mic_rid.unicast));
1325 ai->mod[0].uCtx.window = 33; //Window always points to the middle
1326 ai->mod[0].uCtx.rx = 0; //Rx Sequence numbers
1327 ai->mod[0].uCtx.tx = 0; //Tx sequence numbers
1328 ai->mod[0].uCtx.valid = 1; //Key is now valid
1330 //Give key to mic seed
1331 emmh32_setseed(&ai->mod[0].uCtx.seed, mic_rid.unicast, sizeof(mic_rid.unicast), ai->tfm);
1334 /* So next time we have a valid key and mic is enabled, we will update
1335 * the sequence number if the key is the same as before.
1337 ai->mod[0].uCtx.valid = 0;
1338 ai->mod[0].mCtx.valid = 0;
1342 /* micsetup - Get ready for business */
1344 static int micsetup(struct airo_info *ai) {
1347 if (ai->tfm == NULL)
1348 ai->tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
1350 if (IS_ERR(ai->tfm)) {
1351 airo_print_err(ai->dev->name, "failed to load transform for AES");
1356 for (i=0; i < NUM_MODULES; i++) {
1357 memset(&ai->mod[i].mCtx,0,sizeof(miccntx));
1358 memset(&ai->mod[i].uCtx,0,sizeof(miccntx));
1363 static char micsnap[] = {0xAA,0xAA,0x03,0x00,0x40,0x96,0x00,0x02};
1365 /*===========================================================================
1366 * Description: Mic a packet
1368 * Inputs: etherHead * pointer to an 802.3 frame
1370 * Returns: BOOLEAN if successful, otherwise false.
1371 * PacketTxLen will be updated with the mic'd packets size.
1373 * Caveats: It is assumed that the frame buffer will already
1374 * be big enough to hold the largets mic message possible.
1375 * (No memory allocation is done here).
1377 * Author: sbraneky (10/15/01)
1378 * Merciless hacks by rwilcher (1/14/02)
1381 static int encapsulate(struct airo_info *ai ,etherHead *frame, MICBuffer *mic, int payLen)
1385 // Determine correct context
1386 // If not adhoc, always use unicast key
1388 if (test_bit(FLAG_ADHOC, &ai->flags) && (frame->da[0] & 0x1))
1389 context = &ai->mod[0].mCtx;
1391 context = &ai->mod[0].uCtx;
1393 if (!context->valid)
1396 mic->typelen = htons(payLen + 16); //Length of Mic'd packet
1398 memcpy(&mic->u.snap, micsnap, sizeof(micsnap)); // Add Snap
1401 mic->seq = htonl(context->tx);
1404 emmh32_init(&context->seed); // Mic the packet
1405 emmh32_update(&context->seed,frame->da,ETH_ALEN * 2); // DA,SA
1406 emmh32_update(&context->seed,(u8*)&mic->typelen,10); // Type/Length and Snap
1407 emmh32_update(&context->seed,(u8*)&mic->seq,sizeof(mic->seq)); //SEQ
1408 emmh32_update(&context->seed,frame->da + ETH_ALEN * 2,payLen); //payload
1409 emmh32_final(&context->seed, (u8*)&mic->mic);
1411 /* New Type/length ?????????? */
1412 mic->typelen = 0; //Let NIC know it could be an oversized packet
1424 /*===========================================================================
1425 * Description: Decapsulates a MIC'd packet and returns the 802.3 packet
1426 * (removes the MIC stuff) if packet is a valid packet.
1428 * Inputs: etherHead pointer to the 802.3 packet
1430 * Returns: BOOLEAN - TRUE if packet should be dropped otherwise FALSE
1432 * Author: sbraneky (10/15/01)
1433 * Merciless hacks by rwilcher (1/14/02)
1434 *---------------------------------------------------------------------------
1437 static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *eth, u16 payLen)
1443 mic_error micError = NONE;
1445 // Check if the packet is a Mic'd packet
1447 if (!ai->micstats.enabled) {
1448 //No Mic set or Mic OFF but we received a MIC'd packet.
1449 if (memcmp ((u8*)eth + 14, micsnap, sizeof(micsnap)) == 0) {
1450 ai->micstats.rxMICPlummed++;
1456 if (ntohs(mic->typelen) == 0x888E)
1459 if (memcmp (mic->u.snap, micsnap, sizeof(micsnap)) != 0) {
1460 // Mic enabled but packet isn't Mic'd
1461 ai->micstats.rxMICPlummed++;
1465 micSEQ = ntohl(mic->seq); //store SEQ as CPU order
1467 //At this point we a have a mic'd packet and mic is enabled
1468 //Now do the mic error checking.
1470 //Receive seq must be odd
1471 if ( (micSEQ & 1) == 0 ) {
1472 ai->micstats.rxWrongSequence++;
1476 for (i = 0; i < NUM_MODULES; i++) {
1477 int mcast = eth->da[0] & 1;
1478 //Determine proper context
1479 context = mcast ? &ai->mod[i].mCtx : &ai->mod[i].uCtx;
1481 //Make sure context is valid
1482 if (!context->valid) {
1484 micError = NOMICPLUMMED;
1490 mic->typelen = htons(payLen + sizeof(MICBuffer) - 2);
1492 emmh32_init(&context->seed);
1493 emmh32_update(&context->seed, eth->da, ETH_ALEN*2);
1494 emmh32_update(&context->seed, (u8 *)&mic->typelen, sizeof(mic->typelen)+sizeof(mic->u.snap));
1495 emmh32_update(&context->seed, (u8 *)&mic->seq,sizeof(mic->seq));
1496 emmh32_update(&context->seed, eth->da + ETH_ALEN*2,payLen);
1498 emmh32_final(&context->seed, digest);
1500 if (memcmp(digest, &mic->mic, 4)) { //Make sure the mics match
1503 micError = INCORRECTMIC;
1507 //Check Sequence number if mics pass
1508 if (RxSeqValid(ai, context, mcast, micSEQ) == SUCCESS) {
1509 ai->micstats.rxSuccess++;
1513 micError = SEQUENCE;
1516 // Update statistics
1518 case NOMICPLUMMED: ai->micstats.rxMICPlummed++; break;
1519 case SEQUENCE: ai->micstats.rxWrongSequence++; break;
1520 case INCORRECTMIC: ai->micstats.rxIncorrectMIC++; break;
1527 /*===========================================================================
1528 * Description: Checks the Rx Seq number to make sure it is valid
1529 * and hasn't already been received
1531 * Inputs: miccntx - mic context to check seq against
1532 * micSeq - the Mic seq number
1534 * Returns: TRUE if valid otherwise FALSE.
1536 * Author: sbraneky (10/15/01)
1537 * Merciless hacks by rwilcher (1/14/02)
1538 *---------------------------------------------------------------------------
1541 static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq)
1545 //Allow for the ap being rebooted - if it is then use the next
1546 //sequence number of the current sequence number - might go backwards
1549 if (test_bit(FLAG_UPDATE_MULTI, &ai->flags)) {
1550 clear_bit (FLAG_UPDATE_MULTI, &ai->flags);
1551 context->window = (micSeq > 33) ? micSeq : 33;
1552 context->rx = 0; // Reset rx
1554 } else if (test_bit(FLAG_UPDATE_UNI, &ai->flags)) {
1555 clear_bit (FLAG_UPDATE_UNI, &ai->flags);
1556 context->window = (micSeq > 33) ? micSeq : 33; // Move window
1557 context->rx = 0; // Reset rx
1560 //Make sequence number relative to START of window
1561 seq = micSeq - (context->window - 33);
1563 //Too old of a SEQ number to check.
1568 //Window is infinite forward
1569 MoveWindow(context,micSeq);
1573 // We are in the window. Now check the context rx bit to see if it was already sent
1574 seq >>= 1; //divide by 2 because we only have odd numbers
1575 index = 1 << seq; //Get an index number
1577 if (!(context->rx & index)) {
1578 //micSEQ falls inside the window.
1579 //Add seqence number to the list of received numbers.
1580 context->rx |= index;
1582 MoveWindow(context,micSeq);
1589 static void MoveWindow(miccntx *context, u32 micSeq)
1593 //Move window if seq greater than the middle of the window
1594 if (micSeq > context->window) {
1595 shift = (micSeq - context->window) >> 1;
1599 context->rx >>= shift;
1603 context->window = micSeq; //Move window
1607 /*==============================================*/
1608 /*========== EMMH ROUTINES ====================*/
1609 /*==============================================*/
1611 /* mic accumulate */
1612 #define MIC_ACCUM(val) \
1613 context->accum += (u64)(val) * context->coeff[coeff_position++];
1615 static unsigned char aes_counter[16];
1617 /* expand the key to fill the MMH coefficient array */
1618 static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
1619 struct crypto_cipher *tfm)
1621 /* take the keying material, expand if necessary, truncate at 16-bytes */
1622 /* run through AES counter mode to generate context->coeff[] */
1626 u8 *cipher, plain[16];
1628 crypto_cipher_setkey(tfm, pkey, 16);
1630 for (i = 0; i < ARRAY_SIZE(context->coeff); ) {
1631 aes_counter[15] = (u8)(counter >> 0);
1632 aes_counter[14] = (u8)(counter >> 8);
1633 aes_counter[13] = (u8)(counter >> 16);
1634 aes_counter[12] = (u8)(counter >> 24);
1636 memcpy (plain, aes_counter, 16);
1637 crypto_cipher_encrypt_one(tfm, plain, plain);
1639 for (j = 0; (j < 16) && (i < ARRAY_SIZE(context->coeff)); ) {
1640 context->coeff[i++] = ntohl(*(__be32 *)&cipher[j]);
1646 /* prepare for calculation of a new mic */
1647 static void emmh32_init(emmh32_context *context)
1649 /* prepare for new mic calculation */
1651 context->position = 0;
1654 /* add some bytes to the mic calculation */
1655 static void emmh32_update(emmh32_context *context, u8 *pOctets, int len)
1657 int coeff_position, byte_position;
1659 if (len == 0) return;
1661 coeff_position = context->position >> 2;
1663 /* deal with partial 32-bit word left over from last update */
1664 byte_position = context->position & 3;
1665 if (byte_position) {
1666 /* have a partial word in part to deal with */
1668 if (len == 0) return;
1669 context->part.d8[byte_position++] = *pOctets++;
1670 context->position++;
1672 } while (byte_position < 4);
1673 MIC_ACCUM(ntohl(context->part.d32));
1676 /* deal with full 32-bit words */
1678 MIC_ACCUM(ntohl(*(__be32 *)pOctets));
1679 context->position += 4;
1684 /* deal with partial 32-bit word that will be left over from this update */
1687 context->part.d8[byte_position++] = *pOctets++;
1688 context->position++;
1693 /* mask used to zero empty bytes for final partial word */
1694 static u32 mask32[4] = { 0x00000000L, 0xFF000000L, 0xFFFF0000L, 0xFFFFFF00L };
1696 /* calculate the mic */
1697 static void emmh32_final(emmh32_context *context, u8 digest[4])
1699 int coeff_position, byte_position;
1705 coeff_position = context->position >> 2;
1707 /* deal with partial 32-bit word left over from last update */
1708 byte_position = context->position & 3;
1709 if (byte_position) {
1710 /* have a partial word in part to deal with */
1711 val = ntohl(context->part.d32);
1712 MIC_ACCUM(val & mask32[byte_position]); /* zero empty bytes */
1715 /* reduce the accumulated u64 to a 32-bit MIC */
1716 sum = context->accum;
1717 stmp = (sum & 0xffffffffLL) - ((sum >> 32) * 15);
1718 utmp = (stmp & 0xffffffffLL) - ((stmp >> 32) * 15);
1719 sum = utmp & 0xffffffffLL;
1720 if (utmp > 0x10000000fLL)
1724 digest[0] = (val>>24) & 0xFF;
1725 digest[1] = (val>>16) & 0xFF;
1726 digest[2] = (val>>8) & 0xFF;
1727 digest[3] = val & 0xFF;
1730 static int readBSSListRid(struct airo_info *ai, int first,
1737 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
1738 memset(&cmd, 0, sizeof(cmd));
1739 cmd.cmd=CMD_LISTBSS;
1740 if (down_interruptible(&ai->sem))
1741 return -ERESTARTSYS;
1742 ai->list_bss_task = current;
1743 issuecommand(ai, &cmd, &rsp);
1745 /* Let the command take effect */
1746 schedule_timeout_uninterruptible(3 * HZ);
1747 ai->list_bss_task = NULL;
1749 return PC4500_readrid(ai, first ? ai->bssListFirst : ai->bssListNext,
1750 list, ai->bssListRidLen, 1);
1753 static int readWepKeyRid(struct airo_info *ai, WepKeyRid *wkr, int temp, int lock)
1755 return PC4500_readrid(ai, temp ? RID_WEP_TEMP : RID_WEP_PERM,
1756 wkr, sizeof(*wkr), lock);
1759 static int writeWepKeyRid(struct airo_info *ai, WepKeyRid *wkr, int perm, int lock)
1762 rc = PC4500_writerid(ai, RID_WEP_TEMP, wkr, sizeof(*wkr), lock);
1764 airo_print_err(ai->dev->name, "WEP_TEMP set %x", rc);
1766 rc = PC4500_writerid(ai, RID_WEP_PERM, wkr, sizeof(*wkr), lock);
1768 airo_print_err(ai->dev->name, "WEP_PERM set %x", rc);
1773 static int readSsidRid(struct airo_info*ai, SsidRid *ssidr)
1775 return PC4500_readrid(ai, RID_SSID, ssidr, sizeof(*ssidr), 1);
1778 static int writeSsidRid(struct airo_info*ai, SsidRid *pssidr, int lock)
1780 return PC4500_writerid(ai, RID_SSID, pssidr, sizeof(*pssidr), lock);
1783 static int readConfigRid(struct airo_info *ai, int lock)
1791 rc = PC4500_readrid(ai, RID_ACTUALCONFIG, &cfg, sizeof(cfg), lock);
1799 static inline void checkThrottle(struct airo_info *ai)
1802 /* Old hardware had a limit on encryption speed */
1803 if (ai->config.authType != AUTH_OPEN && maxencrypt) {
1804 for(i=0; i<8; i++) {
1805 if (ai->config.rates[i] > maxencrypt) {
1806 ai->config.rates[i] = 0;
1812 static int writeConfigRid(struct airo_info *ai, int lock)
1816 if (!test_bit (FLAG_COMMIT, &ai->flags))
1819 clear_bit (FLAG_COMMIT, &ai->flags);
1820 clear_bit (FLAG_RESET, &ai->flags);
1824 if ((cfgr.opmode & MODE_CFG_MASK) == MODE_STA_IBSS)
1825 set_bit(FLAG_ADHOC, &ai->flags);
1827 clear_bit(FLAG_ADHOC, &ai->flags);
1829 return PC4500_writerid( ai, RID_CONFIG, &cfgr, sizeof(cfgr), lock);
1832 static int readStatusRid(struct airo_info *ai, StatusRid *statr, int lock)
1834 return PC4500_readrid(ai, RID_STATUS, statr, sizeof(*statr), lock);
1837 static int readAPListRid(struct airo_info *ai, APListRid *aplr)
1839 return PC4500_readrid(ai, RID_APLIST, aplr, sizeof(*aplr), 1);
1842 static int writeAPListRid(struct airo_info *ai, APListRid *aplr, int lock)
1844 return PC4500_writerid(ai, RID_APLIST, aplr, sizeof(*aplr), lock);
1847 static int readCapabilityRid(struct airo_info *ai, CapabilityRid *capr, int lock)
1849 return PC4500_readrid(ai, RID_CAPABILITIES, capr, sizeof(*capr), lock);
1852 static int readStatsRid(struct airo_info*ai, StatsRid *sr, int rid, int lock)
1854 return PC4500_readrid(ai, rid, sr, sizeof(*sr), lock);
1857 static void try_auto_wep(struct airo_info *ai)
1859 if (auto_wep && !(ai->flags & FLAG_RADIO_DOWN)) {
1860 ai->expires = RUN_AT(3*HZ);
1861 wake_up_interruptible(&ai->thr_wait);
1865 static int airo_open(struct net_device *dev) {
1866 struct airo_info *ai = dev->ml_priv;
1869 if (test_bit(FLAG_FLASHING, &ai->flags))
1872 /* Make sure the card is configured.
1873 * Wireless Extensions may postpone config changes until the card
1874 * is open (to pipeline changes and speed-up card setup). If
1875 * those changes are not yet commited, do it now - Jean II */
1876 if (test_bit(FLAG_COMMIT, &ai->flags)) {
1878 writeConfigRid(ai, 1);
1881 if (ai->wifidev != dev) {
1882 clear_bit(JOB_DIE, &ai->jobs);
1883 ai->airo_thread_task = kthread_run(airo_thread, dev, dev->name);
1884 if (IS_ERR(ai->airo_thread_task))
1885 return (int)PTR_ERR(ai->airo_thread_task);
1887 rc = request_irq(dev->irq, airo_interrupt, IRQF_SHARED,
1890 airo_print_err(dev->name,
1891 "register interrupt %d failed, rc %d",
1893 set_bit(JOB_DIE, &ai->jobs);
1894 kthread_stop(ai->airo_thread_task);
1898 /* Power on the MAC controller (which may have been disabled) */
1899 clear_bit(FLAG_RADIO_DOWN, &ai->flags);
1900 enable_interrupts(ai);
1906 netif_start_queue(dev);
1910 static int mpi_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1911 int npacks, pending;
1912 unsigned long flags;
1913 struct airo_info *ai = dev->ml_priv;
1916 airo_print_err(dev->name, "%s: skb == NULL!",__func__);
1919 npacks = skb_queue_len (&ai->txq);
1921 if (npacks >= MAXTXQ - 1) {
1922 netif_stop_queue (dev);
1923 if (npacks > MAXTXQ) {
1924 dev->stats.tx_fifo_errors++;
1927 skb_queue_tail (&ai->txq, skb);
1931 spin_lock_irqsave(&ai->aux_lock, flags);
1932 skb_queue_tail (&ai->txq, skb);
1933 pending = test_bit(FLAG_PENDING_XMIT, &ai->flags);
1934 spin_unlock_irqrestore(&ai->aux_lock,flags);
1935 netif_wake_queue (dev);
1938 set_bit(FLAG_PENDING_XMIT, &ai->flags);
1939 mpi_send_packet (dev);
1947 * Attempt to transmit a packet. Can be called from interrupt
1948 * or transmit . return number of packets we tried to send
1951 static int mpi_send_packet (struct net_device *dev)
1953 struct sk_buff *skb;
1954 unsigned char *buffer;
1957 struct airo_info *ai = dev->ml_priv;
1960 /* get a packet to send */
1962 if ((skb = skb_dequeue(&ai->txq)) == NULL) {
1963 airo_print_err(dev->name,
1964 "%s: Dequeue'd zero in send_packet()",
1969 /* check min length*/
1970 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1973 ai->txfids[0].tx_desc.offset = 0;
1974 ai->txfids[0].tx_desc.valid = 1;
1975 ai->txfids[0].tx_desc.eoc = 1;
1976 ai->txfids[0].tx_desc.len =len+sizeof(WifiHdr);
1979 * Magic, the cards firmware needs a length count (2 bytes) in the host buffer
1980 * right after TXFID_HDR.The TXFID_HDR contains the status short so payloadlen
1981 * is immediatly after it. ------------------------------------------------
1982 * |TXFIDHDR+STATUS|PAYLOADLEN|802.3HDR|PACKETDATA|
1983 * ------------------------------------------------
1986 memcpy((char *)ai->txfids[0].virtual_host_addr,
1987 (char *)&wifictlhdr8023, sizeof(wifictlhdr8023));
1989 payloadLen = (__le16 *)(ai->txfids[0].virtual_host_addr +
1990 sizeof(wifictlhdr8023));
1991 sendbuf = ai->txfids[0].virtual_host_addr +
1992 sizeof(wifictlhdr8023) + 2 ;
1995 * Firmware automaticly puts 802 header on so
1996 * 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(((__be16 *)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 ai->txfids[0].tx_desc.len += sizeof(pMic);
2007 /* copy data into airo dma buffer */
2008 memcpy (sendbuf, buffer, sizeof(etherHead));
2009 buffer += sizeof(etherHead);
2010 sendbuf += sizeof(etherHead);
2011 memcpy (sendbuf, &pMic, sizeof(pMic));
2012 sendbuf += sizeof(pMic);
2013 memcpy (sendbuf, buffer, len - sizeof(etherHead));
2015 *payloadLen = cpu_to_le16(len - sizeof(etherHead));
2017 dev->trans_start = jiffies;
2019 /* copy data into airo dma buffer */
2020 memcpy(sendbuf, buffer, len);
2023 memcpy_toio(ai->txfids[0].card_ram_off,
2024 &ai->txfids[0].tx_desc, sizeof(TxFid));
2026 OUT4500(ai, EVACK, 8);
2028 dev_kfree_skb_any(skb);
2032 static void get_tx_error(struct airo_info *ai, s32 fid)
2037 status = ((WifiCtlHdr *)ai->txfids[0].virtual_host_addr)->ctlhdr.status;
2039 if (bap_setup(ai, ai->fids[fid] & 0xffff, 4, BAP0) != SUCCESS)
2041 bap_read(ai, &status, 2, BAP0);
2043 if (le16_to_cpu(status) & 2) /* Too many retries */
2044 ai->dev->stats.tx_aborted_errors++;
2045 if (le16_to_cpu(status) & 4) /* Transmit lifetime exceeded */
2046 ai->dev->stats.tx_heartbeat_errors++;
2047 if (le16_to_cpu(status) & 8) /* Aid fail */
2049 if (le16_to_cpu(status) & 0x10) /* MAC disabled */
2050 ai->dev->stats.tx_carrier_errors++;
2051 if (le16_to_cpu(status) & 0x20) /* Association lost */
2053 /* We produce a TXDROP event only for retry or lifetime
2054 * exceeded, because that's the only status that really mean
2055 * that this particular node went away.
2056 * Other errors means that *we* screwed up. - Jean II */
2057 if ((le16_to_cpu(status) & 2) ||
2058 (le16_to_cpu(status) & 4)) {
2059 union iwreq_data wrqu;
2062 /* Faster to skip over useless data than to do
2063 * another bap_setup(). We are at offset 0x6 and
2064 * need to go to 0x18 and read 6 bytes - Jean II */
2065 bap_read(ai, (__le16 *) junk, 0x18, BAP0);
2067 /* Copy 802.11 dest address.
2068 * We use the 802.11 header because the frame may
2069 * not be 802.3 or may be mangled...
2070 * In Ad-Hoc mode, it will be the node address.
2071 * In managed mode, it will be most likely the AP addr
2072 * User space will figure out how to convert it to
2073 * whatever it needs (IP address or else).
2075 memcpy(wrqu.addr.sa_data, junk + 0x12, ETH_ALEN);
2076 wrqu.addr.sa_family = ARPHRD_ETHER;
2078 /* Send event to user space */
2079 wireless_send_event(ai->dev, IWEVTXDROP, &wrqu, NULL);
2083 static void airo_end_xmit(struct net_device *dev) {
2086 struct airo_info *priv = dev->ml_priv;
2087 struct sk_buff *skb = priv->xmit.skb;
2088 int fid = priv->xmit.fid;
2089 u32 *fids = priv->fids;
2091 clear_bit(JOB_XMIT, &priv->jobs);
2092 clear_bit(FLAG_PENDING_XMIT, &priv->flags);
2093 status = transmit_802_3_packet (priv, fids[fid], skb->data);
2097 if ( status == SUCCESS ) {
2098 dev->trans_start = jiffies;
2099 for (; i < MAX_FIDS / 2 && (priv->fids[i] & 0xffff0000); i++);
2101 priv->fids[fid] &= 0xffff;
2102 dev->stats.tx_window_errors++;
2104 if (i < MAX_FIDS / 2)
2105 netif_wake_queue(dev);
2109 static int airo_start_xmit(struct sk_buff *skb, struct net_device *dev) {
2112 struct airo_info *priv = dev->ml_priv;
2113 u32 *fids = priv->fids;
2115 if ( skb == NULL ) {
2116 airo_print_err(dev->name, "%s: skb == NULL!", __func__);
2120 /* Find a vacant FID */
2121 for( i = 0; i < MAX_FIDS / 2 && (fids[i] & 0xffff0000); i++ );
2122 for( j = i + 1; j < MAX_FIDS / 2 && (fids[j] & 0xffff0000); j++ );
2124 if ( j >= MAX_FIDS / 2 ) {
2125 netif_stop_queue(dev);
2127 if (i == MAX_FIDS / 2) {
2128 dev->stats.tx_fifo_errors++;
2132 /* check min length*/
2133 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
2134 /* Mark fid as used & save length for later */
2135 fids[i] |= (len << 16);
2136 priv->xmit.skb = skb;
2138 if (down_trylock(&priv->sem) != 0) {
2139 set_bit(FLAG_PENDING_XMIT, &priv->flags);
2140 netif_stop_queue(dev);
2141 set_bit(JOB_XMIT, &priv->jobs);
2142 wake_up_interruptible(&priv->thr_wait);
2148 static void airo_end_xmit11(struct net_device *dev) {
2151 struct airo_info *priv = dev->ml_priv;
2152 struct sk_buff *skb = priv->xmit11.skb;
2153 int fid = priv->xmit11.fid;
2154 u32 *fids = priv->fids;
2156 clear_bit(JOB_XMIT11, &priv->jobs);
2157 clear_bit(FLAG_PENDING_XMIT11, &priv->flags);
2158 status = transmit_802_11_packet (priv, fids[fid], skb->data);
2162 if ( status == SUCCESS ) {
2163 dev->trans_start = jiffies;
2164 for (; i < MAX_FIDS && (priv->fids[i] & 0xffff0000); i++);
2166 priv->fids[fid] &= 0xffff;
2167 dev->stats.tx_window_errors++;
2170 netif_wake_queue(dev);
2174 static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) {
2177 struct airo_info *priv = dev->ml_priv;
2178 u32 *fids = priv->fids;
2180 if (test_bit(FLAG_MPI, &priv->flags)) {
2181 /* Not implemented yet for MPI350 */
2182 netif_stop_queue(dev);
2186 if ( skb == NULL ) {
2187 airo_print_err(dev->name, "%s: skb == NULL!", __func__);
2191 /* Find a vacant FID */
2192 for( i = MAX_FIDS / 2; i < MAX_FIDS && (fids[i] & 0xffff0000); i++ );
2193 for( j = i + 1; j < MAX_FIDS && (fids[j] & 0xffff0000); j++ );
2195 if ( j >= MAX_FIDS ) {
2196 netif_stop_queue(dev);
2198 if (i == MAX_FIDS) {
2199 dev->stats.tx_fifo_errors++;
2203 /* check min length*/
2204 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
2205 /* Mark fid as used & save length for later */
2206 fids[i] |= (len << 16);
2207 priv->xmit11.skb = skb;
2208 priv->xmit11.fid = i;
2209 if (down_trylock(&priv->sem) != 0) {
2210 set_bit(FLAG_PENDING_XMIT11, &priv->flags);
2211 netif_stop_queue(dev);
2212 set_bit(JOB_XMIT11, &priv->jobs);
2213 wake_up_interruptible(&priv->thr_wait);
2215 airo_end_xmit11(dev);
2219 static void airo_read_stats(struct net_device *dev)
2221 struct airo_info *ai = dev->ml_priv;
2223 __le32 *vals = stats_rid.vals;
2225 clear_bit(JOB_STATS, &ai->jobs);
2226 if (ai->power.event) {
2230 readStatsRid(ai, &stats_rid, RID_STATS, 0);
2233 dev->stats.rx_packets = le32_to_cpu(vals[43]) + le32_to_cpu(vals[44]) +
2234 le32_to_cpu(vals[45]);
2235 dev->stats.tx_packets = le32_to_cpu(vals[39]) + le32_to_cpu(vals[40]) +
2236 le32_to_cpu(vals[41]);
2237 dev->stats.rx_bytes = le32_to_cpu(vals[92]);
2238 dev->stats.tx_bytes = le32_to_cpu(vals[91]);
2239 dev->stats.rx_errors = le32_to_cpu(vals[0]) + le32_to_cpu(vals[2]) +
2240 le32_to_cpu(vals[3]) + le32_to_cpu(vals[4]);
2241 dev->stats.tx_errors = le32_to_cpu(vals[42]) +
2242 dev->stats.tx_fifo_errors;
2243 dev->stats.multicast = le32_to_cpu(vals[43]);
2244 dev->stats.collisions = le32_to_cpu(vals[89]);
2246 /* detailed rx_errors: */
2247 dev->stats.rx_length_errors = le32_to_cpu(vals[3]);
2248 dev->stats.rx_crc_errors = le32_to_cpu(vals[4]);
2249 dev->stats.rx_frame_errors = le32_to_cpu(vals[2]);
2250 dev->stats.rx_fifo_errors = le32_to_cpu(vals[0]);
2253 static struct net_device_stats *airo_get_stats(struct net_device *dev)
2255 struct airo_info *local = dev->ml_priv;
2257 if (!test_bit(JOB_STATS, &local->jobs)) {
2258 /* Get stats out of the card if available */
2259 if (down_trylock(&local->sem) != 0) {
2260 set_bit(JOB_STATS, &local->jobs);
2261 wake_up_interruptible(&local->thr_wait);
2263 airo_read_stats(dev);
2269 static void airo_set_promisc(struct airo_info *ai) {
2273 memset(&cmd, 0, sizeof(cmd));
2274 cmd.cmd=CMD_SETMODE;
2275 clear_bit(JOB_PROMISC, &ai->jobs);
2276 cmd.parm0=(ai->flags&IFF_PROMISC) ? PROMISC : NOPROMISC;
2277 issuecommand(ai, &cmd, &rsp);
2281 static void airo_set_multicast_list(struct net_device *dev) {
2282 struct airo_info *ai = dev->ml_priv;
2284 if ((dev->flags ^ ai->flags) & IFF_PROMISC) {
2285 change_bit(FLAG_PROMISC, &ai->flags);
2286 if (down_trylock(&ai->sem) != 0) {
2287 set_bit(JOB_PROMISC, &ai->jobs);
2288 wake_up_interruptible(&ai->thr_wait);
2290 airo_set_promisc(ai);
2293 if ((dev->flags&IFF_ALLMULTI)||dev->mc_count>0) {
2294 /* Turn on multicast. (Should be already setup...) */
2298 static int airo_set_mac_address(struct net_device *dev, void *p)
2300 struct airo_info *ai = dev->ml_priv;
2301 struct sockaddr *addr = p;
2303 readConfigRid(ai, 1);
2304 memcpy (ai->config.macAddr, addr->sa_data, dev->addr_len);
2305 set_bit (FLAG_COMMIT, &ai->flags);
2307 writeConfigRid (ai, 1);
2309 memcpy (ai->dev->dev_addr, addr->sa_data, dev->addr_len);
2311 memcpy (ai->wifidev->dev_addr, addr->sa_data, dev->addr_len);
2315 static int airo_change_mtu(struct net_device *dev, int new_mtu)
2317 if ((new_mtu < 68) || (new_mtu > 2400))
2323 static LIST_HEAD(airo_devices);
2325 static void add_airo_dev(struct airo_info *ai)
2327 /* Upper layers already keep track of PCI devices,
2328 * so we only need to remember our non-PCI cards. */
2330 list_add_tail(&ai->dev_list, &airo_devices);
2333 static void del_airo_dev(struct airo_info *ai)
2336 list_del(&ai->dev_list);
2339 static int airo_close(struct net_device *dev) {
2340 struct airo_info *ai = dev->ml_priv;
2342 netif_stop_queue(dev);
2344 if (ai->wifidev != dev) {
2345 #ifdef POWER_ON_DOWN
2346 /* Shut power to the card. The idea is that the user can save
2347 * power when he doesn't need the card with "ifconfig down".
2348 * That's the method that is most friendly towards the network
2349 * stack (i.e. the network stack won't try to broadcast
2350 * anything on the interface and routes are gone. Jean II */
2351 set_bit(FLAG_RADIO_DOWN, &ai->flags);
2354 disable_interrupts( ai );
2356 free_irq(dev->irq, dev);
2358 set_bit(JOB_DIE, &ai->jobs);
2359 kthread_stop(ai->airo_thread_task);
2364 void stop_airo_card( struct net_device *dev, int freeres )
2366 struct airo_info *ai = dev->ml_priv;
2368 set_bit(FLAG_RADIO_DOWN, &ai->flags);
2370 disable_interrupts(ai);
2371 takedown_proc_entry( dev, ai );
2372 if (test_bit(FLAG_REGISTERED, &ai->flags)) {
2373 unregister_netdev( dev );
2375 unregister_netdev(ai->wifidev);
2376 free_netdev(ai->wifidev);
2379 clear_bit(FLAG_REGISTERED, &ai->flags);
2382 * Clean out tx queue
2384 if (test_bit(FLAG_MPI, &ai->flags) && !skb_queue_empty(&ai->txq)) {
2385 struct sk_buff *skb = NULL;
2386 for (;(skb = skb_dequeue(&ai->txq));)
2390 airo_networks_free (ai);
2397 /* PCMCIA frees this stuff, so only for PCI and ISA */
2398 release_region( dev->base_addr, 64 );
2399 if (test_bit(FLAG_MPI, &ai->flags)) {
2401 mpi_unmap_card(ai->pci);
2403 iounmap(ai->pcimem);
2405 iounmap(ai->pciaux);
2406 pci_free_consistent(ai->pci, PCI_SHARED_LEN,
2407 ai->shared, ai->shared_dma);
2410 crypto_free_cipher(ai->tfm);
2415 EXPORT_SYMBOL(stop_airo_card);
2417 static int wll_header_parse(const struct sk_buff *skb, unsigned char *haddr)
2419 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN);
2423 static void mpi_unmap_card(struct pci_dev *pci)
2425 unsigned long mem_start = pci_resource_start(pci, 1);
2426 unsigned long mem_len = pci_resource_len(pci, 1);
2427 unsigned long aux_start = pci_resource_start(pci, 2);
2428 unsigned long aux_len = AUXMEMSIZE;
2430 release_mem_region(aux_start, aux_len);
2431 release_mem_region(mem_start, mem_len);
2434 /*************************************************************
2435 * This routine assumes that descriptors have been setup .
2436 * Run at insmod time or after reset when the decriptors
2437 * have been initialized . Returns 0 if all is well nz
2438 * otherwise . Does not allocate memory but sets up card
2439 * using previously allocated descriptors.
2441 static int mpi_init_descriptors (struct airo_info *ai)
2448 /* Alloc card RX descriptors */
2449 netif_stop_queue(ai->dev);
2451 memset(&rsp,0,sizeof(rsp));
2452 memset(&cmd,0,sizeof(cmd));
2454 cmd.cmd = CMD_ALLOCATEAUX;
2456 cmd.parm1 = (ai->rxfids[0].card_ram_off - ai->pciaux);
2457 cmd.parm2 = MPI_MAX_FIDS;
2458 rc=issuecommand(ai, &cmd, &rsp);
2459 if (rc != SUCCESS) {
2460 airo_print_err(ai->dev->name, "Couldn't allocate RX FID");
2464 for (i=0; i<MPI_MAX_FIDS; i++) {
2465 memcpy_toio(ai->rxfids[i].card_ram_off,
2466 &ai->rxfids[i].rx_desc, sizeof(RxFid));
2469 /* Alloc card TX descriptors */
2471 memset(&rsp,0,sizeof(rsp));
2472 memset(&cmd,0,sizeof(cmd));
2474 cmd.cmd = CMD_ALLOCATEAUX;
2476 cmd.parm1 = (ai->txfids[0].card_ram_off - ai->pciaux);
2477 cmd.parm2 = MPI_MAX_FIDS;
2479 for (i=0; i<MPI_MAX_FIDS; i++) {
2480 ai->txfids[i].tx_desc.valid = 1;
2481 memcpy_toio(ai->txfids[i].card_ram_off,
2482 &ai->txfids[i].tx_desc, sizeof(TxFid));
2484 ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */
2486 rc=issuecommand(ai, &cmd, &rsp);
2487 if (rc != SUCCESS) {
2488 airo_print_err(ai->dev->name, "Couldn't allocate TX FID");
2492 /* Alloc card Rid descriptor */
2493 memset(&rsp,0,sizeof(rsp));
2494 memset(&cmd,0,sizeof(cmd));
2496 cmd.cmd = CMD_ALLOCATEAUX;
2498 cmd.parm1 = (ai->config_desc.card_ram_off - ai->pciaux);
2499 cmd.parm2 = 1; /* Magic number... */
2500 rc=issuecommand(ai, &cmd, &rsp);
2501 if (rc != SUCCESS) {
2502 airo_print_err(ai->dev->name, "Couldn't allocate RID");
2506 memcpy_toio(ai->config_desc.card_ram_off,
2507 &ai->config_desc.rid_desc, sizeof(Rid));
2513 * We are setting up three things here:
2514 * 1) Map AUX memory for descriptors: Rid, TxFid, or RxFid.
2515 * 2) Map PCI memory for issueing commands.
2516 * 3) Allocate memory (shared) to send and receive ethernet frames.
2518 static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci)
2520 unsigned long mem_start, mem_len, aux_start, aux_len;
2523 dma_addr_t busaddroff;
2524 unsigned char *vpackoff;
2525 unsigned char __iomem *pciaddroff;
2527 mem_start = pci_resource_start(pci, 1);
2528 mem_len = pci_resource_len(pci, 1);
2529 aux_start = pci_resource_start(pci, 2);
2530 aux_len = AUXMEMSIZE;
2532 if (!request_mem_region(mem_start, mem_len, DRV_NAME)) {
2533 airo_print_err("", "Couldn't get region %x[%x]",
2534 (int)mem_start, (int)mem_len);
2537 if (!request_mem_region(aux_start, aux_len, DRV_NAME)) {
2538 airo_print_err("", "Couldn't get region %x[%x]",
2539 (int)aux_start, (int)aux_len);
2543 ai->pcimem = ioremap(mem_start, mem_len);
2545 airo_print_err("", "Couldn't map region %x[%x]",
2546 (int)mem_start, (int)mem_len);
2549 ai->pciaux = ioremap(aux_start, aux_len);
2551 airo_print_err("", "Couldn't map region %x[%x]",
2552 (int)aux_start, (int)aux_len);
2556 /* Reserve PKTSIZE for each fid and 2K for the Rids */
2557 ai->shared = pci_alloc_consistent(pci, PCI_SHARED_LEN, &ai->shared_dma);
2559 airo_print_err("", "Couldn't alloc_consistent %d",
2565 * Setup descriptor RX, TX, CONFIG
2567 busaddroff = ai->shared_dma;
2568 pciaddroff = ai->pciaux + AUX_OFFSET;
2569 vpackoff = ai->shared;
2571 /* RX descriptor setup */
2572 for(i = 0; i < MPI_MAX_FIDS; i++) {
2573 ai->rxfids[i].pending = 0;
2574 ai->rxfids[i].card_ram_off = pciaddroff;
2575 ai->rxfids[i].virtual_host_addr = vpackoff;
2576 ai->rxfids[i].rx_desc.host_addr = busaddroff;
2577 ai->rxfids[i].rx_desc.valid = 1;
2578 ai->rxfids[i].rx_desc.len = PKTSIZE;
2579 ai->rxfids[i].rx_desc.rdy = 0;
2581 pciaddroff += sizeof(RxFid);
2582 busaddroff += PKTSIZE;
2583 vpackoff += PKTSIZE;
2586 /* TX descriptor setup */
2587 for(i = 0; i < MPI_MAX_FIDS; i++) {
2588 ai->txfids[i].card_ram_off = pciaddroff;
2589 ai->txfids[i].virtual_host_addr = vpackoff;
2590 ai->txfids[i].tx_desc.valid = 1;
2591 ai->txfids[i].tx_desc.host_addr = busaddroff;
2592 memcpy(ai->txfids[i].virtual_host_addr,
2593 &wifictlhdr8023, sizeof(wifictlhdr8023));
2595 pciaddroff += sizeof(TxFid);
2596 busaddroff += PKTSIZE;
2597 vpackoff += PKTSIZE;
2599 ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */
2601 /* Rid descriptor setup */
2602 ai->config_desc.card_ram_off = pciaddroff;
2603 ai->config_desc.virtual_host_addr = vpackoff;
2604 ai->config_desc.rid_desc.host_addr = busaddroff;
2605 ai->ridbus = busaddroff;
2606 ai->config_desc.rid_desc.rid = 0;
2607 ai->config_desc.rid_desc.len = RIDSIZE;
2608 ai->config_desc.rid_desc.valid = 1;
2609 pciaddroff += sizeof(Rid);
2610 busaddroff += RIDSIZE;
2611 vpackoff += RIDSIZE;
2613 /* Tell card about descriptors */
2614 if (mpi_init_descriptors (ai) != SUCCESS)
2619 pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
2621 iounmap(ai->pciaux);
2623 iounmap(ai->pcimem);
2625 release_mem_region(aux_start, aux_len);
2627 release_mem_region(mem_start, mem_len);
2632 static const struct header_ops airo_header_ops = {
2633 .parse = wll_header_parse,
2636 static void wifi_setup(struct net_device *dev)
2638 dev->header_ops = &airo_header_ops;
2639 dev->hard_start_xmit = &airo_start_xmit11;
2640 dev->get_stats = &airo_get_stats;
2641 dev->set_mac_address = &airo_set_mac_address;
2642 dev->do_ioctl = &airo_ioctl;
2643 dev->wireless_handlers = &airo_handler_def;
2644 dev->change_mtu = &airo_change_mtu;
2645 dev->open = &airo_open;
2646 dev->stop = &airo_close;
2648 dev->type = ARPHRD_IEEE80211;
2649 dev->hard_header_len = ETH_HLEN;
2650 dev->mtu = AIRO_DEF_MTU;
2651 dev->addr_len = ETH_ALEN;
2652 dev->tx_queue_len = 100;
2654 memset(dev->broadcast,0xFF, ETH_ALEN);
2656 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2659 static struct net_device *init_wifidev(struct airo_info *ai,
2660 struct net_device *ethdev)
2663 struct net_device *dev = alloc_netdev(0, "wifi%d", wifi_setup);
2666 dev->ml_priv = ethdev->ml_priv;
2667 dev->irq = ethdev->irq;
2668 dev->base_addr = ethdev->base_addr;
2669 dev->wireless_data = ethdev->wireless_data;
2670 SET_NETDEV_DEV(dev, ethdev->dev.parent);
2671 memcpy(dev->dev_addr, ethdev->dev_addr, dev->addr_len);
2672 err = register_netdev(dev);
2680 static int reset_card( struct net_device *dev , int lock) {
2681 struct airo_info *ai = dev->ml_priv;
2683 if (lock && down_interruptible(&ai->sem))
2686 OUT4500(ai,COMMAND,CMD_SOFTRESET);
2695 #define AIRO_MAX_NETWORK_COUNT 64
2696 static int airo_networks_allocate(struct airo_info *ai)
2702 kzalloc(AIRO_MAX_NETWORK_COUNT * sizeof(BSSListElement),
2704 if (!ai->networks) {
2705 airo_print_warn("", "Out of memory allocating beacons");
2712 static void airo_networks_free(struct airo_info *ai)
2714 kfree(ai->networks);
2715 ai->networks = NULL;
2718 static void airo_networks_initialize(struct airo_info *ai)
2722 INIT_LIST_HEAD(&ai->network_free_list);
2723 INIT_LIST_HEAD(&ai->network_list);
2724 for (i = 0; i < AIRO_MAX_NETWORK_COUNT; i++)
2725 list_add_tail(&ai->networks[i].list,
2726 &ai->network_free_list);
2729 static int airo_test_wpa_capable(struct airo_info *ai)
2732 CapabilityRid cap_rid;
2734 status = readCapabilityRid(ai, &cap_rid, 1);
2735 if (status != SUCCESS) return 0;
2737 /* Only firmware versions 5.30.17 or better can do WPA */
2738 if (le16_to_cpu(cap_rid.softVer) > 0x530
2739 || (le16_to_cpu(cap_rid.softVer) == 0x530
2740 && le16_to_cpu(cap_rid.softSubVer) >= 17)) {
2741 airo_print_info("", "WPA is supported.");
2745 /* No WPA support */
2746 airo_print_info("", "WPA unsupported (only firmware versions 5.30.17"
2747 " and greater support WPA. Detected %s)", cap_rid.prodVer);
2751 static struct net_device *_init_airo_card( unsigned short irq, int port,
2752 int is_pcmcia, struct pci_dev *pci,
2753 struct device *dmdev )
2755 struct net_device *dev;
2756 struct airo_info *ai;
2759 /* Create the network device object. */
2760 dev = alloc_netdev(sizeof(*ai), "", ether_setup);
2762 airo_print_err("", "Couldn't alloc_etherdev");
2766 ai = dev->ml_priv = netdev_priv(dev);
2768 ai->flags = 1 << FLAG_RADIO_DOWN;
2771 if (pci && (pci->device == 0x5000 || pci->device == 0xa504)) {
2772 airo_print_dbg("", "Found an MPI350 card");
2773 set_bit(FLAG_MPI, &ai->flags);
2775 spin_lock_init(&ai->aux_lock);
2776 sema_init(&ai->sem, 1);
2779 init_waitqueue_head (&ai->thr_wait);
2783 if (airo_networks_allocate (ai))
2785 airo_networks_initialize (ai);
2787 /* The Airo-specific entries in the device structure. */
2788 if (test_bit(FLAG_MPI,&ai->flags)) {
2789 skb_queue_head_init (&ai->txq);
2790 dev->hard_start_xmit = &mpi_start_xmit;
2792 dev->hard_start_xmit = &airo_start_xmit;
2793 dev->get_stats = &airo_get_stats;
2794 dev->set_multicast_list = &airo_set_multicast_list;
2795 dev->set_mac_address = &airo_set_mac_address;
2796 dev->do_ioctl = &airo_ioctl;
2797 dev->wireless_handlers = &airo_handler_def;
2798 ai->wireless_data.spy_data = &ai->spy_data;
2799 dev->wireless_data = &ai->wireless_data;
2800 dev->change_mtu = &airo_change_mtu;
2801 dev->open = &airo_open;
2802 dev->stop = &airo_close;
2804 dev->base_addr = port;
2806 SET_NETDEV_DEV(dev, dmdev);
2808 reset_card (dev, 1);
2812 if (!request_region(dev->base_addr, 64, DRV_NAME)) {
2814 airo_print_err(dev->name, "Couldn't request region");
2819 if (test_bit(FLAG_MPI,&ai->flags)) {
2820 if (mpi_map_card(ai, pci)) {
2821 airo_print_err("", "Could not map memory");
2827 if ( setup_card( ai, dev->dev_addr, 1 ) != SUCCESS ) {
2828 airo_print_err(dev->name, "MAC could not be enabled" );
2832 } else if (!test_bit(FLAG_MPI,&ai->flags)) {
2833 ai->bap_read = fast_bap_read;
2834 set_bit(FLAG_FLASHING, &ai->flags);
2837 /* Test for WPA support */
2838 if (airo_test_wpa_capable(ai)) {
2839 set_bit(FLAG_WPA_CAPABLE, &ai->flags);
2840 ai->bssListFirst = RID_WPA_BSSLISTFIRST;
2841 ai->bssListNext = RID_WPA_BSSLISTNEXT;
2842 ai->bssListRidLen = sizeof(BSSListRid);
2844 ai->bssListFirst = RID_BSSLISTFIRST;
2845 ai->bssListNext = RID_BSSLISTNEXT;
2846 ai->bssListRidLen = sizeof(BSSListRid) - sizeof(BSSListRidExtra);
2849 strcpy(dev->name, "eth%d");
2850 rc = register_netdev(dev);
2852 airo_print_err(dev->name, "Couldn't register_netdev");
2855 ai->wifidev = init_wifidev(ai, dev);
2859 set_bit(FLAG_REGISTERED,&ai->flags);
2860 airo_print_info(dev->name, "MAC enabled %pM", dev->dev_addr);
2862 /* Allocate the transmit buffers */
2863 if (probe && !test_bit(FLAG_MPI,&ai->flags))
2864 for( i = 0; i < MAX_FIDS; i++ )
2865 ai->fids[i] = transmit_allocate(ai,AIRO_DEF_MTU,i>=MAX_FIDS/2);
2867 if (setup_proc_entry(dev, dev->ml_priv) < 0)
2873 unregister_netdev(ai->wifidev);
2874 free_netdev(ai->wifidev);
2876 unregister_netdev(dev);
2878 if (test_bit(FLAG_MPI,&ai->flags) && pci) {
2879 pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
2880 iounmap(ai->pciaux);
2881 iounmap(ai->pcimem);
2882 mpi_unmap_card(ai->pci);
2886 release_region( dev->base_addr, 64 );
2888 airo_networks_free(ai);
2895 struct net_device *init_airo_card( unsigned short irq, int port, int is_pcmcia,
2896 struct device *dmdev)
2898 return _init_airo_card ( irq, port, is_pcmcia, NULL, dmdev);
2901 EXPORT_SYMBOL(init_airo_card);
2903 static int waitbusy (struct airo_info *ai) {
2905 while ((IN4500(ai, COMMAND) & COMMAND_BUSY) && (delay < 10000)) {
2907 if ((++delay % 20) == 0)
2908 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
2910 return delay < 10000;
2913 int reset_airo_card( struct net_device *dev )
2916 struct airo_info *ai = dev->ml_priv;
2918 if (reset_card (dev, 1))
2921 if ( setup_card(ai, dev->dev_addr, 1 ) != SUCCESS ) {
2922 airo_print_err(dev->name, "MAC could not be enabled");
2925 airo_print_info(dev->name, "MAC enabled %pM", dev->dev_addr);
2926 /* Allocate the transmit buffers if needed */
2927 if (!test_bit(FLAG_MPI,&ai->flags))
2928 for( i = 0; i < MAX_FIDS; i++ )
2929 ai->fids[i] = transmit_allocate (ai,AIRO_DEF_MTU,i>=MAX_FIDS/2);
2931 enable_interrupts( ai );
2932 netif_wake_queue(dev);
2936 EXPORT_SYMBOL(reset_airo_card);
2938 static void airo_send_event(struct net_device *dev) {
2939 struct airo_info *ai = dev->ml_priv;
2940 union iwreq_data wrqu;
2941 StatusRid status_rid;
2943 clear_bit(JOB_EVENT, &ai->jobs);
2944 PC4500_readrid(ai, RID_STATUS, &status_rid, sizeof(status_rid), 0);
2946 wrqu.data.length = 0;
2947 wrqu.data.flags = 0;
2948 memcpy(wrqu.ap_addr.sa_data, status_rid.bssid[0], ETH_ALEN);
2949 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
2951 /* Send event to user space */
2952 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
2955 static void airo_process_scan_results (struct airo_info *ai) {
2956 union iwreq_data wrqu;
2959 BSSListElement * loop_net;
2960 BSSListElement * tmp_net;
2962 /* Blow away current list of scan results */
2963 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
2964 list_move_tail (&loop_net->list, &ai->network_free_list);
2965 /* Don't blow away ->list, just BSS data */
2966 memset (loop_net, 0, sizeof (loop_net->bss));
2969 /* Try to read the first entry of the scan result */
2970 rc = PC4500_readrid(ai, ai->bssListFirst, &bss, ai->bssListRidLen, 0);
2971 if((rc) || (bss.index == cpu_to_le16(0xffff))) {
2972 /* No scan results */
2976 /* Read and parse all entries */
2978 while((!rc) && (bss.index != cpu_to_le16(0xffff))) {
2979 /* Grab a network off the free list */
2980 if (!list_empty(&ai->network_free_list)) {
2981 tmp_net = list_entry(ai->network_free_list.next,
2982 BSSListElement, list);
2983 list_del(ai->network_free_list.next);
2986 if (tmp_net != NULL) {
2987 memcpy(tmp_net, &bss, sizeof(tmp_net->bss));
2988 list_add_tail(&tmp_net->list, &ai->network_list);
2992 /* Read next entry */
2993 rc = PC4500_readrid(ai, ai->bssListNext,
2994 &bss, ai->bssListRidLen, 0);
2998 ai->scan_timeout = 0;
2999 clear_bit(JOB_SCAN_RESULTS, &ai->jobs);
3002 /* Send an empty event to user space.
3003 * We don't send the received data on
3004 * the event because it would require
3005 * us to do complex transcoding, and
3006 * we want to minimise the work done in
3007 * the irq handler. Use a request to
3008 * extract the data - Jean II */
3009 wrqu.data.length = 0;
3010 wrqu.data.flags = 0;
3011 wireless_send_event(ai->dev, SIOCGIWSCAN, &wrqu, NULL);
3014 static int airo_thread(void *data) {
3015 struct net_device *dev = data;
3016 struct airo_info *ai = dev->ml_priv;
3021 /* make swsusp happy with our thread */
3024 if (test_bit(JOB_DIE, &ai->jobs))
3028 locked = down_interruptible(&ai->sem);
3032 init_waitqueue_entry(&wait, current);
3033 add_wait_queue(&ai->thr_wait, &wait);
3035 set_current_state(TASK_INTERRUPTIBLE);
3038 if (ai->expires || ai->scan_timeout) {
3039 if (ai->scan_timeout &&
3040 time_after_eq(jiffies,ai->scan_timeout)){
3041 set_bit(JOB_SCAN_RESULTS, &ai->jobs);
3043 } else if (ai->expires &&
3044 time_after_eq(jiffies,ai->expires)){
3045 set_bit(JOB_AUTOWEP, &ai->jobs);
3048 if (!kthread_should_stop() &&
3049 !freezing(current)) {
3050 unsigned long wake_at;
3051 if (!ai->expires || !ai->scan_timeout) {
3052 wake_at = max(ai->expires,
3055 wake_at = min(ai->expires,
3058 schedule_timeout(wake_at - jiffies);
3061 } else if (!kthread_should_stop() &&
3062 !freezing(current)) {
3068 current->state = TASK_RUNNING;
3069 remove_wait_queue(&ai->thr_wait, &wait);
3076 if (test_bit(JOB_DIE, &ai->jobs)) {
3081 if (ai->power.event || test_bit(FLAG_FLASHING, &ai->flags)) {
3086 if (test_bit(JOB_XMIT, &ai->jobs))
3088 else if (test_bit(JOB_XMIT11, &ai->jobs))
3089 airo_end_xmit11(dev);
3090 else if (test_bit(JOB_STATS, &ai->jobs))
3091 airo_read_stats(dev);
3092 else if (test_bit(JOB_WSTATS, &ai->jobs))
3093 airo_read_wireless_stats(ai);
3094 else if (test_bit(JOB_PROMISC, &ai->jobs))
3095 airo_set_promisc(ai);
3096 else if (test_bit(JOB_MIC, &ai->jobs))
3098 else if (test_bit(JOB_EVENT, &ai->jobs))
3099 airo_send_event(dev);
3100 else if (test_bit(JOB_AUTOWEP, &ai->jobs))
3102 else if (test_bit(JOB_SCAN_RESULTS, &ai->jobs))
3103 airo_process_scan_results(ai);
3104 else /* Shouldn't get here, but we make sure to unlock */
3111 static int header_len(__le16 ctl)
3113 u16 fc = le16_to_cpu(ctl);
3116 if ((fc & 0xe0) == 0xc0)
3117 return 10; /* one-address control packet */
3118 return 16; /* two-address control packet */
3120 if ((fc & 0x300) == 0x300)
3121 return 30; /* WDS packet */
3126 static irqreturn_t airo_interrupt(int irq, void *dev_id)
3128 struct net_device *dev = dev_id;
3131 struct airo_info *apriv = dev->ml_priv;
3132 u16 savedInterrupts = 0;
3135 if (!netif_device_present(dev))
3139 status = IN4500( apriv, EVSTAT );
3140 if ( !(status & STATUS_INTS) || status == 0xffff ) break;
3144 if ( status & EV_AWAKE ) {
3145 OUT4500( apriv, EVACK, EV_AWAKE );
3146 OUT4500( apriv, EVACK, EV_AWAKE );
3149 if (!savedInterrupts) {
3150 savedInterrupts = IN4500( apriv, EVINTEN );
3151 OUT4500( apriv, EVINTEN, 0 );
3154 if ( status & EV_MIC ) {
3155 OUT4500( apriv, EVACK, EV_MIC );
3156 if (test_bit(FLAG_MIC_CAPABLE, &apriv->flags)) {
3157 set_bit(JOB_MIC, &apriv->jobs);
3158 wake_up_interruptible(&apriv->thr_wait);
3161 if ( status & EV_LINK ) {
3162 union iwreq_data wrqu;
3163 int scan_forceloss = 0;
3164 /* The link status has changed, if you want to put a
3165 monitor hook in, do it here. (Remember that
3166 interrupts are still disabled!)
3168 u16 newStatus = IN4500(apriv, LINKSTAT);
3169 OUT4500( apriv, EVACK, EV_LINK);
3170 /* Here is what newStatus means: */
3171 #define NOBEACON 0x8000 /* Loss of sync - missed beacons */
3172 #define MAXRETRIES 0x8001 /* Loss of sync - max retries */
3173 #define MAXARL 0x8002 /* Loss of sync - average retry level exceeded*/
3174 #define FORCELOSS 0x8003 /* Loss of sync - host request */
3175 #define TSFSYNC 0x8004 /* Loss of sync - TSF synchronization */
3176 #define DEAUTH 0x8100 /* Deauthentication (low byte is reason code) */
3177 #define DISASS 0x8200 /* Disassociation (low byte is reason code) */
3178 #define ASSFAIL 0x8400 /* Association failure (low byte is reason
3180 #define AUTHFAIL 0x0300 /* Authentication failure (low byte is reason
3182 #define ASSOCIATED 0x0400 /* Associated */
3183 #define REASSOCIATED 0x0600 /* Reassociated? Only on firmware >= 5.30.17 */
3184 #define RC_RESERVED 0 /* Reserved return code */
3185 #define RC_NOREASON 1 /* Unspecified reason */
3186 #define RC_AUTHINV 2 /* Previous authentication invalid */
3187 #define RC_DEAUTH 3 /* Deauthenticated because sending station is
3189 #define RC_NOACT 4 /* Disassociated due to inactivity */
3190 #define RC_MAXLOAD 5 /* Disassociated because AP is unable to handle
3191 all currently associated stations */
3192 #define RC_BADCLASS2 6 /* Class 2 frame received from
3193 non-Authenticated station */
3194 #define RC_BADCLASS3 7 /* Class 3 frame received from
3195 non-Associated station */
3196 #define RC_STATLEAVE 8 /* Disassociated because sending station is
3198 #define RC_NOAUTH 9 /* Station requesting (Re)Association is not
3199 Authenticated with the responding station */
3200 if (newStatus == FORCELOSS && apriv->scan_timeout > 0)
3202 if(newStatus == ASSOCIATED || newStatus == REASSOCIATED) {
3205 if (apriv->list_bss_task)
3206 wake_up_process(apriv->list_bss_task);
3207 set_bit(FLAG_UPDATE_UNI, &apriv->flags);
3208 set_bit(FLAG_UPDATE_MULTI, &apriv->flags);
3210 if (down_trylock(&apriv->sem) != 0) {
3211 set_bit(JOB_EVENT, &apriv->jobs);
3212 wake_up_interruptible(&apriv->thr_wait);
3214 airo_send_event(dev);
3215 } else if (!scan_forceloss) {
3216 if (auto_wep && !apriv->expires) {
3217 apriv->expires = RUN_AT(3*HZ);
3218 wake_up_interruptible(&apriv->thr_wait);
3221 /* Send event to user space */
3222 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
3223 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3224 wireless_send_event(dev, SIOCGIWAP, &wrqu,NULL);
3228 /* Check to see if there is something to receive */
3229 if ( status & EV_RX ) {
3230 struct sk_buff *skb = NULL;
3232 u16 len, hdrlen = 0;
3246 if (test_bit(FLAG_MPI,&apriv->flags)) {
3247 if (test_bit(FLAG_802_11, &apriv->flags))
3248 mpi_receive_802_11(apriv);
3250 mpi_receive_802_3(apriv);
3251 OUT4500(apriv, EVACK, EV_RX);
3255 fid = IN4500( apriv, RXFID );
3257 /* Get the packet length */
3258 if (test_bit(FLAG_802_11, &apriv->flags)) {
3259 bap_setup (apriv, fid, 4, BAP0);
3260 bap_read (apriv, (__le16*)&hdr, sizeof(hdr), BAP0);
3261 /* Bad CRC. Ignore packet */
3262 if (le16_to_cpu(hdr.status) & 2)
3264 if (apriv->wifidev == NULL)
3267 bap_setup (apriv, fid, 0x36, BAP0);
3268 bap_read (apriv, &hdr.len, 2, BAP0);
3270 len = le16_to_cpu(hdr.len);
3272 if (len > AIRO_DEF_MTU) {
3273 airo_print_err(apriv->dev->name, "Bad size %d", len);
3279 if (test_bit(FLAG_802_11, &apriv->flags)) {
3280 bap_read (apriv, &fc, sizeof(fc), BAP0);
3281 hdrlen = header_len(fc);
3283 hdrlen = ETH_ALEN * 2;
3285 skb = dev_alloc_skb( len + hdrlen + 2 + 2 );
3287 dev->stats.rx_dropped++;
3290 skb_reserve(skb, 2); /* This way the IP header is aligned */
3291 buffer = (__le16*)skb_put (skb, len + hdrlen);
3292 if (test_bit(FLAG_802_11, &apriv->flags)) {
3294 bap_read (apriv, buffer + 1, hdrlen - 2, BAP0);
3296 bap_read (apriv, tmpbuf, 6, BAP0);
3298 bap_read (apriv, &v, sizeof(v), BAP0);
3299 gap = le16_to_cpu(v);
3302 bap_read (apriv, tmpbuf, gap, BAP0);
3304 airo_print_err(apriv->dev->name, "gaplen too "
3305 "big. Problems will follow...");
3308 bap_read (apriv, buffer + hdrlen/2, len, BAP0);
3311 bap_read (apriv, buffer, ETH_ALEN*2, BAP0);
3312 if (apriv->micstats.enabled) {
3313 bap_read (apriv,(__le16*)&micbuf,sizeof(micbuf),BAP0);
3314 if (ntohs(micbuf.typelen) > 0x05DC)
3315 bap_setup (apriv, fid, 0x44, BAP0);
3317 if (len <= sizeof(micbuf))
3320 len -= sizeof(micbuf);
3321 skb_trim (skb, len + hdrlen);
3324 bap_read(apriv,buffer+ETH_ALEN,len,BAP0);
3325 if (decapsulate(apriv,&micbuf,(etherHead*)buffer,len)) {
3327 dev_kfree_skb_irq (skb);
3329 OUT4500( apriv, EVACK, EV_RX);
3334 if (apriv->spy_data.spy_number > 0) {
3336 struct iw_quality wstats;
3337 /* Prepare spy data : addr + qual */
3338 if (!test_bit(FLAG_802_11, &apriv->flags)) {
3339 sa = (char*)buffer + 6;
3340 bap_setup (apriv, fid, 8, BAP0);
3341 bap_read (apriv, (__le16*)hdr.rssi, 2, BAP0);
3343 sa = (char*)buffer + 10;
3344 wstats.qual = hdr.rssi[0];
3346 wstats.level = 0x100 - apriv->rssi[hdr.rssi[1]].rssidBm;
3348 wstats.level = (hdr.rssi[1] + 321) / 2;
3349 wstats.noise = apriv->wstats.qual.noise;
3350 wstats.updated = IW_QUAL_LEVEL_UPDATED
3351 | IW_QUAL_QUAL_UPDATED
3353 /* Update spy records */
3354 wireless_spy_update(dev, sa, &wstats);
3356 #endif /* WIRELESS_SPY */
3357 OUT4500( apriv, EVACK, EV_RX);
3359 if (test_bit(FLAG_802_11, &apriv->flags)) {
3360 skb_reset_mac_header(skb);
3361 skb->pkt_type = PACKET_OTHERHOST;
3362 skb->dev = apriv->wifidev;
3363 skb->protocol = htons(ETH_P_802_2);
3365 skb->protocol = eth_type_trans(skb,dev);
3366 skb->ip_summed = CHECKSUM_NONE;
3372 /* Check to see if a packet has been transmitted */
3373 if ( status & ( EV_TX|EV_TXCPY|EV_TXEXC ) ) {
3378 if (test_bit(FLAG_MPI,&apriv->flags)) {
3379 unsigned long flags;
3381 if (status & EV_TXEXC)
3382 get_tx_error(apriv, -1);
3383 spin_lock_irqsave(&apriv->aux_lock, flags);
3384 if (!skb_queue_empty(&apriv->txq)) {
3385 spin_unlock_irqrestore(&apriv->aux_lock,flags);
3386 mpi_send_packet (dev);
3388 clear_bit(FLAG_PENDING_XMIT, &apriv->flags);
3389 spin_unlock_irqrestore(&apriv->aux_lock,flags);
3390 netif_wake_queue (dev);
3392 OUT4500( apriv, EVACK,
3393 status & (EV_TX|EV_TXCPY|EV_TXEXC));
3397 fid = IN4500(apriv, TXCOMPLFID);
3399 for( i = 0; i < MAX_FIDS; i++ ) {
3400 if ( ( apriv->fids[i] & 0xffff ) == fid ) {
3401 len = apriv->fids[i] >> 16;
3406 if (status & EV_TXEXC)
3407 get_tx_error(apriv, index);
3408 OUT4500( apriv, EVACK, status & (EV_TX | EV_TXEXC));
3409 /* Set up to be used again */
3410 apriv->fids[index] &= 0xffff;
3411 if (index < MAX_FIDS / 2) {
3412 if (!test_bit(FLAG_PENDING_XMIT, &apriv->flags))
3413 netif_wake_queue(dev);
3415 if (!test_bit(FLAG_PENDING_XMIT11, &apriv->flags))
3416 netif_wake_queue(apriv->wifidev);
3419 OUT4500( apriv, EVACK, status & (EV_TX | EV_TXCPY | EV_TXEXC));
3420 airo_print_err(apriv->dev->name, "Unallocated FID was "
3425 if ( status & ~STATUS_INTS & ~IGNORE_INTS )
3426 airo_print_warn(apriv->dev->name, "Got weird status %x",
3427 status & ~STATUS_INTS & ~IGNORE_INTS );
3430 if (savedInterrupts)
3431 OUT4500( apriv, EVINTEN, savedInterrupts );
3434 return IRQ_RETVAL(handled);
3438 * Routines to talk to the card
3442 * This was originally written for the 4500, hence the name
3443 * NOTE: If use with 8bit mode and SMP bad things will happen!
3444 * Why would some one do 8 bit IO in an SMP machine?!?
3446 static void OUT4500( struct airo_info *ai, u16 reg, u16 val ) {
3447 if (test_bit(FLAG_MPI,&ai->flags))
3450 outw( val, ai->dev->base_addr + reg );
3452 outb( val & 0xff, ai->dev->base_addr + reg );
3453 outb( val >> 8, ai->dev->base_addr + reg + 1 );
3457 static u16 IN4500( struct airo_info *ai, u16 reg ) {
3460 if (test_bit(FLAG_MPI,&ai->flags))
3463 rc = inw( ai->dev->base_addr + reg );
3465 rc = inb( ai->dev->base_addr + reg );
3466 rc += ((int)inb( ai->dev->base_addr + reg + 1 )) << 8;
3471 static int enable_MAC(struct airo_info *ai, int lock)
3477 /* FLAG_RADIO_OFF : Radio disabled via /proc or Wireless Extensions
3478 * FLAG_RADIO_DOWN : Radio disabled via "ifconfig ethX down"
3479 * Note : we could try to use !netif_running(dev) in enable_MAC()
3480 * instead of this flag, but I don't trust it *within* the
3481 * open/close functions, and testing both flags together is
3482 * "cheaper" - Jean II */
3483 if (ai->flags & FLAG_RADIO_MASK) return SUCCESS;
3485 if (lock && down_interruptible(&ai->sem))
3486 return -ERESTARTSYS;
3488 if (!test_bit(FLAG_ENABLED, &ai->flags)) {
3489 memset(&cmd, 0, sizeof(cmd));
3490 cmd.cmd = MAC_ENABLE;
3491 rc = issuecommand(ai, &cmd, &rsp);
3493 set_bit(FLAG_ENABLED, &ai->flags);
3501 airo_print_err(ai->dev->name, "Cannot enable MAC");
3502 else if ((rsp.status & 0xFF00) != 0) {
3503 airo_print_err(ai->dev->name, "Bad MAC enable reason=%x, "
3504 "rid=%x, offset=%d", rsp.rsp0, rsp.rsp1, rsp.rsp2);
3510 static void disable_MAC( struct airo_info *ai, int lock ) {
3514 if (lock && down_interruptible(&ai->sem))
3517 if (test_bit(FLAG_ENABLED, &ai->flags)) {
3518 memset(&cmd, 0, sizeof(cmd));
3519 cmd.cmd = MAC_DISABLE; // disable in case already enabled
3520 issuecommand(ai, &cmd, &rsp);
3521 clear_bit(FLAG_ENABLED, &ai->flags);
3527 static void enable_interrupts( struct airo_info *ai ) {
3528 /* Enable the interrupts */
3529 OUT4500( ai, EVINTEN, STATUS_INTS );
3532 static void disable_interrupts( struct airo_info *ai ) {
3533 OUT4500( ai, EVINTEN, 0 );
3536 static void mpi_receive_802_3(struct airo_info *ai)
3540 struct sk_buff *skb;
3545 memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
3546 /* Make sure we got something */
3547 if (rxd.rdy && rxd.valid == 0) {
3549 if (len < 12 || len > 2048)
3552 skb = dev_alloc_skb(len);
3554 ai->dev->stats.rx_dropped++;
3557 buffer = skb_put(skb,len);
3558 memcpy(buffer, ai->rxfids[0].virtual_host_addr, ETH_ALEN * 2);
3559 if (ai->micstats.enabled) {
3561 ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2,
3563 if (ntohs(micbuf.typelen) <= 0x05DC) {
3564 if (len <= sizeof(micbuf) + ETH_ALEN * 2)
3567 off = sizeof(micbuf);
3568 skb_trim (skb, len - off);
3571 memcpy(buffer + ETH_ALEN * 2,
3572 ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2 + off,
3573 len - ETH_ALEN * 2 - off);
3574 if (decapsulate (ai, &micbuf, (etherHead*)buffer, len - off - ETH_ALEN * 2)) {
3576 dev_kfree_skb_irq (skb);
3580 if (ai->spy_data.spy_number > 0) {
3582 struct iw_quality wstats;
3583 /* Prepare spy data : addr + qual */
3584 sa = buffer + ETH_ALEN;
3585 wstats.qual = 0; /* XXX Where do I get that info from ??? */
3588 /* Update spy records */
3589 wireless_spy_update(ai->dev, sa, &wstats);
3591 #endif /* WIRELESS_SPY */
3593 skb->ip_summed = CHECKSUM_NONE;
3594 skb->protocol = eth_type_trans(skb, ai->dev);
3598 if (rxd.valid == 0) {
3602 memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
3606 static void mpi_receive_802_11(struct airo_info *ai)
3609 struct sk_buff *skb = NULL;
3610 u16 len, hdrlen = 0;
3623 char *ptr = ai->rxfids[0].virtual_host_addr+4;
3625 memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
3626 memcpy ((char *)&hdr, ptr, sizeof(hdr));
3628 /* Bad CRC. Ignore packet */
3629 if (le16_to_cpu(hdr.status) & 2)
3631 if (ai->wifidev == NULL)
3633 len = le16_to_cpu(hdr.len);
3634 if (len > AIRO_DEF_MTU) {
3635 airo_print_err(ai->dev->name, "Bad size %d", len);
3641 fc = get_unaligned((__le16 *)ptr);
3642 hdrlen = header_len(fc);
3644 skb = dev_alloc_skb( len + hdrlen + 2 );
3646 ai->dev->stats.rx_dropped++;
3649 buffer = (u16*)skb_put (skb, len + hdrlen);
3650 memcpy ((char *)buffer, ptr, hdrlen);
3654 gap = get_unaligned_le16(ptr);
3655 ptr += sizeof(__le16);
3660 airo_print_err(ai->dev->name,
3661 "gaplen too big. Problems will follow...");
3663 memcpy ((char *)buffer + hdrlen, ptr, len);
3665 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
3666 if (ai->spy_data.spy_number > 0) {
3668 struct iw_quality wstats;
3669 /* Prepare spy data : addr + qual */
3670 sa = (char*)buffer + 10;
3671 wstats.qual = hdr.rssi[0];
3673 wstats.level = 0x100 - ai->rssi[hdr.rssi[1]].rssidBm;
3675 wstats.level = (hdr.rssi[1] + 321) / 2;
3676 wstats.noise = ai->wstats.qual.noise;
3677 wstats.updated = IW_QUAL_QUAL_UPDATED
3678 | IW_QUAL_LEVEL_UPDATED
3680 /* Update spy records */
3681 wireless_spy_update(ai->dev, sa, &wstats);
3683 #endif /* IW_WIRELESS_SPY */
3684 skb_reset_mac_header(skb);
3685 skb->pkt_type = PACKET_OTHERHOST;
3686 skb->dev = ai->wifidev;
3687 skb->protocol = htons(ETH_P_802_2);
3688 skb->ip_summed = CHECKSUM_NONE;
3691 if (rxd.valid == 0) {
3695 memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
3699 static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
3710 memset( &mySsid, 0, sizeof( mySsid ) );
3714 /* The NOP is the first step in getting the card going */
3716 cmd.parm0 = cmd.parm1 = cmd.parm2 = 0;
3717 if (lock && down_interruptible(&ai->sem))
3719 if ( issuecommand( ai, &cmd, &rsp ) != SUCCESS ) {
3724 disable_MAC( ai, 0);
3726 // Let's figure out if we need to use the AUX port
3727 if (!test_bit(FLAG_MPI,&ai->flags)) {
3728 cmd.cmd = CMD_ENABLEAUX;
3729 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
3732 airo_print_err(ai->dev->name, "Error checking for AUX port");
3735 if (!aux_bap || rsp.status & 0xff00) {
3736 ai->bap_read = fast_bap_read;
3737 airo_print_dbg(ai->dev->name, "Doing fast bap_reads");
3739 ai->bap_read = aux_bap_read;
3740 airo_print_dbg(ai->dev->name, "Doing AUX bap_reads");
3745 if (ai->config.len == 0) {
3746 tdsRssiRid rssi_rid;
3747 CapabilityRid cap_rid;
3753 // general configuration (read/modify/write)
3754 status = readConfigRid(ai, lock);
3755 if ( status != SUCCESS ) return ERROR;
3757 status = readCapabilityRid(ai, &cap_rid, lock);
3758 if ( status != SUCCESS ) return ERROR;
3760 status = PC4500_readrid(ai,RID_RSSI,&rssi_rid,sizeof(rssi_rid),lock);
3761 if ( status == SUCCESS ) {
3762 if (ai->rssi || (ai->rssi = kmalloc(512, GFP_KERNEL)) != NULL)
3763 memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512); /* Skip RID length member */
3768 if (cap_rid.softCap & cpu_to_le16(8))
3769 ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
3771 airo_print_warn(ai->dev->name, "unknown received signal "
3774 ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS;
3775 ai->config.authType = AUTH_OPEN;
3776 ai->config.modulation = MOD_CCK;
3778 if (le16_to_cpu(cap_rid.len) >= sizeof(cap_rid) &&
3779 (cap_rid.extSoftCap & cpu_to_le16(1)) &&
3780 micsetup(ai) == SUCCESS) {
3781 ai->config.opmode |= MODE_MIC;
3782 set_bit(FLAG_MIC_CAPABLE, &ai->flags);
3785 /* Save off the MAC */
3786 for( i = 0; i < ETH_ALEN; i++ ) {
3787 mac[i] = ai->config.macAddr[i];
3790 /* Check to see if there are any insmod configured
3794 memset(ai->config.rates,0,sizeof(ai->config.rates));
3795 for( i = 0; i < 8 && rates[i]; i++ ) {
3796 ai->config.rates[i] = rates[i];
3799 if ( basic_rate > 0 ) {
3801 for( i = 0; i < 8; i++ ) {
3802 if ( ai->config.rates[i] == basic_rate ||
3803 !ai->config.rates ) {
3804 ai->config.rates[i] = basic_rate | 0x80;
3809 set_bit (FLAG_COMMIT, &ai->flags);
3812 /* Setup the SSIDs if present */
3815 for( i = 0; i < 3 && ssids[i]; i++ ) {
3816 size_t len = strlen(ssids[i]);
3819 mySsid.ssids[i].len = cpu_to_le16(len);
3820 memcpy(mySsid.ssids[i].ssid, ssids[i], len);
3822 mySsid.len = cpu_to_le16(sizeof(mySsid));
3825 status = writeConfigRid(ai, lock);
3826 if ( status != SUCCESS ) return ERROR;
3828 /* Set up the SSID list */
3830 status = writeSsidRid(ai, &mySsid, lock);
3831 if ( status != SUCCESS ) return ERROR;
3834 status = enable_MAC(ai, lock);
3835 if (status != SUCCESS)
3838 /* Grab the initial wep key, we gotta save it for auto_wep */
3839 rc = readWepKeyRid(ai, &wkr, 1, lock);
3840 if (rc == SUCCESS) do {
3841 lastindex = wkr.kindex;
3842 if (wkr.kindex == cpu_to_le16(0xffff)) {
3843 ai->defindex = wkr.mac[0];
3845 rc = readWepKeyRid(ai, &wkr, 0, lock);
3846 } while(lastindex != wkr.kindex);
3853 static u16 issuecommand(struct airo_info *ai, Cmd *pCmd, Resp *pRsp) {
3854 // Im really paranoid about letting it run forever!
3855 int max_tries = 600000;
3857 if (IN4500(ai, EVSTAT) & EV_CMD)
3858 OUT4500(ai, EVACK, EV_CMD);
3860 OUT4500(ai, PARAM0, pCmd->parm0);
3861 OUT4500(ai, PARAM1, pCmd->parm1);
3862 OUT4500(ai, PARAM2, pCmd->parm2);
3863 OUT4500(ai, COMMAND, pCmd->cmd);
3865 while (max_tries-- && (IN4500(ai, EVSTAT) & EV_CMD) == 0) {
3866 if ((IN4500(ai, COMMAND)) == pCmd->cmd)
3867 // PC4500 didn't notice command, try again
3868 OUT4500(ai, COMMAND, pCmd->cmd);
3869 if (!in_atomic() && (max_tries & 255) == 0)
3873 if ( max_tries == -1 ) {
3874 airo_print_err(ai->dev->name,
3875 "Max tries exceeded when issueing command");
3876 if (IN4500(ai, COMMAND) & COMMAND_BUSY)
3877 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
3881 // command completed
3882 pRsp->status = IN4500(ai, STATUS);
3883 pRsp->rsp0 = IN4500(ai, RESP0);
3884 pRsp->rsp1 = IN4500(ai, RESP1);
3885 pRsp->rsp2 = IN4500(ai, RESP2);
3886 if ((pRsp->status & 0xff00)!=0 && pCmd->cmd != CMD_SOFTRESET)
3887 airo_print_err(ai->dev->name,
3888 "cmd:%x status:%x rsp0:%x rsp1:%x rsp2:%x",
3889 pCmd->cmd, pRsp->status, pRsp->rsp0, pRsp->rsp1,
3892 // clear stuck command busy if necessary
3893 if (IN4500(ai, COMMAND) & COMMAND_BUSY) {
3894 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
3896 // acknowledge processing the status/response
3897 OUT4500(ai, EVACK, EV_CMD);
3902 /* Sets up the bap to start exchange data. whichbap should
3903 * be one of the BAP0 or BAP1 defines. Locks should be held before
3905 static int bap_setup(struct airo_info *ai, u16 rid, u16 offset, int whichbap )
3910 OUT4500(ai, SELECT0+whichbap, rid);
3911 OUT4500(ai, OFFSET0+whichbap, offset);
3913 int status = IN4500(ai, OFFSET0+whichbap);
3914 if (status & BAP_BUSY) {
3915 /* This isn't really a timeout, but its kinda
3920 } else if ( status & BAP_ERR ) {
3921 /* invalid rid or offset */
3922 airo_print_err(ai->dev->name, "BAP error %x %d",
3925 } else if (status & BAP_DONE) { // success
3928 if ( !(max_tries--) ) {
3929 airo_print_err(ai->dev->name,
3930 "BAP setup error too many retries\n");
3933 // -- PC4500 missed it, try again
3934 OUT4500(ai, SELECT0+whichbap, rid);
3935 OUT4500(ai, OFFSET0+whichbap, offset);
3940 /* should only be called by aux_bap_read. This aux function and the
3941 following use concepts not documented in the developers guide. I
3942 got them from a patch given to my by Aironet */
3943 static u16 aux_setup(struct airo_info *ai, u16 page,
3944 u16 offset, u16 *len)
3948 OUT4500(ai, AUXPAGE, page);
3949 OUT4500(ai, AUXOFF, 0);
3950 next = IN4500(ai, AUXDATA);
3951 *len = IN4500(ai, AUXDATA)&0xff;
3952 if (offset != 4) OUT4500(ai, AUXOFF, offset);
3956 /* requires call to bap_setup() first */
3957 static int aux_bap_read(struct airo_info *ai, __le16 *pu16Dst,
3958 int bytelen, int whichbap)
3966 unsigned long flags;
3968 spin_lock_irqsave(&ai->aux_lock, flags);
3969 page = IN4500(ai, SWS0+whichbap);
3970 offset = IN4500(ai, SWS2+whichbap);
3971 next = aux_setup(ai, page, offset, &len);
3972 words = (bytelen+1)>>1;
3974 for (i=0; i<words;) {
3976 count = (len>>1) < (words-i) ? (len>>1) : (words-i);
3978 insw( ai->dev->base_addr+DATA0+whichbap,
3981 insb( ai->dev->base_addr+DATA0+whichbap,
3982 pu16Dst+i, count << 1 );
3985 next = aux_setup(ai, next, 4, &len);
3988 spin_unlock_irqrestore(&ai->aux_lock, flags);
3993 /* requires call to bap_setup() first */
3994 static int fast_bap_read(struct airo_info *ai, __le16 *pu16Dst,
3995 int bytelen, int whichbap)
3997 bytelen = (bytelen + 1) & (~1); // round up to even value
3999 insw( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen>>1 );
4001 insb( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen );
4005 /* requires call to bap_setup() first */
4006 static int bap_write(struct airo_info *ai, const __le16 *pu16Src,
4007 int bytelen, int whichbap)
4009 bytelen = (bytelen + 1) & (~1); // round up to even value
4011 outsw( ai->dev->base_addr+DATA0+whichbap,
4012 pu16Src, bytelen>>1 );
4014 outsb( ai->dev->base_addr+DATA0+whichbap, pu16Src, bytelen );
4018 static int PC4500_accessrid(struct airo_info *ai, u16 rid, u16 accmd)
4020 Cmd cmd; /* for issuing commands */
4021 Resp rsp; /* response from commands */
4024 memset(&cmd, 0, sizeof(cmd));
4027 status = issuecommand(ai, &cmd, &rsp);
4028 if (status != 0) return status;
4029 if ( (rsp.status & 0x7F00) != 0) {
4030 return (accmd << 8) + (rsp.rsp0 & 0xFF);
4035 /* Note, that we are using BAP1 which is also used by transmit, so
4036 * we must get a lock. */
4037 static int PC4500_readrid(struct airo_info *ai, u16 rid, void *pBuf, int len, int lock)
4043 if (down_interruptible(&ai->sem))
4046 if (test_bit(FLAG_MPI,&ai->flags)) {
4050 memset(&cmd, 0, sizeof(cmd));
4051 memset(&rsp, 0, sizeof(rsp));
4052 ai->config_desc.rid_desc.valid = 1;
4053 ai->config_desc.rid_desc.len = RIDSIZE;
4054 ai->config_desc.rid_desc.rid = 0;
4055 ai->config_desc.rid_desc.host_addr = ai->ridbus;
4057 cmd.cmd = CMD_ACCESS;
4060 memcpy_toio(ai->config_desc.card_ram_off,
4061 &ai->config_desc.rid_desc, sizeof(Rid));
4063 rc = issuecommand(ai, &cmd, &rsp);
4065 if (rsp.status & 0x7f00)
4068 memcpy(pBuf, ai->config_desc.virtual_host_addr, len);
4071 if ((status = PC4500_accessrid(ai, rid, CMD_ACCESS))!=SUCCESS) {
4075 if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
4079 // read the rid length field
4080 bap_read(ai, pBuf, 2, BAP1);
4081 // length for remaining part of rid
4082 len = min(len, (int)le16_to_cpu(*(__le16*)pBuf)) - 2;
4085 airo_print_err(ai->dev->name,
4086 "Rid %x has a length of %d which is too short",
4087 (int)rid, (int)len );
4091 // read remainder of the rid
4092 rc = bap_read(ai, ((__le16*)pBuf)+1, len, BAP1);
4100 /* Note, that we are using BAP1 which is also used by transmit, so
4101 * make sure this isnt called when a transmit is happening */
4102 static int PC4500_writerid(struct airo_info *ai, u16 rid,
4103 const void *pBuf, int len, int lock)
4108 *(__le16*)pBuf = cpu_to_le16((u16)len);
4111 if (down_interruptible(&ai->sem))
4114 if (test_bit(FLAG_MPI,&ai->flags)) {
4118 if (test_bit(FLAG_ENABLED, &ai->flags) && (RID_WEP_TEMP != rid))
4119 airo_print_err(ai->dev->name,
4120 "%s: MAC should be disabled (rid=%04x)",
4122 memset(&cmd, 0, sizeof(cmd));
4123 memset(&rsp, 0, sizeof(rsp));
4125 ai->config_desc.rid_desc.valid = 1;
4126 ai->config_desc.rid_desc.len = *((u16 *)pBuf);
4127 ai->config_desc.rid_desc.rid = 0;
4129 cmd.cmd = CMD_WRITERID;
4132 memcpy_toio(ai->config_desc.card_ram_off,
4133 &ai->config_desc.rid_desc, sizeof(Rid));
4135 if (len < 4 || len > 2047) {
4136 airo_print_err(ai->dev->name, "%s: len=%d", __func__, len);
4139 memcpy((char *)ai->config_desc.virtual_host_addr,
4142 rc = issuecommand(ai, &cmd, &rsp);
4143 if ((rc & 0xff00) != 0) {
4144 airo_print_err(ai->dev->name, "%s: Write rid Error %d",
4146 airo_print_err(ai->dev->name, "%s: Cmd=%04x",
4150 if ((rsp.status & 0x7f00))
4154 // --- first access so that we can write the rid data
4155 if ( (status = PC4500_accessrid(ai, rid, CMD_ACCESS)) != 0) {
4159 // --- now write the rid data
4160 if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
4164 bap_write(ai, pBuf, len, BAP1);
4165 // ---now commit the rid data
4166 rc = PC4500_accessrid(ai, rid, 0x100|CMD_ACCESS);
4174 /* Allocates a FID to be used for transmitting packets. We only use
4176 static u16 transmit_allocate(struct airo_info *ai, int lenPayload, int raw)
4178 unsigned int loop = 3000;
4184 cmd.cmd = CMD_ALLOCATETX;
4185 cmd.parm0 = lenPayload;
4186 if (down_interruptible(&ai->sem))
4188 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
4192 if ( (rsp.status & 0xFF00) != 0) {
4196 /* wait for the allocate event/indication
4197 * It makes me kind of nervous that this can just sit here and spin,
4198 * but in practice it only loops like four times. */
4199 while (((IN4500(ai, EVSTAT) & EV_ALLOC) == 0) && --loop);
4205 // get the allocated fid and acknowledge
4206 txFid = IN4500(ai, TXALLOCFID);
4207 OUT4500(ai, EVACK, EV_ALLOC);
4209 /* The CARD is pretty cool since it converts the ethernet packet
4210 * into 802.11. Also note that we don't release the FID since we
4211 * will be using the same one over and over again. */
4212 /* We only have to setup the control once since we are not
4213 * releasing the fid. */
4215 txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_11
4216 | TXCTL_ETHERNET | TXCTL_NORELEASE);
4218 txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_3
4219 | TXCTL_ETHERNET | TXCTL_NORELEASE);
4220 if (bap_setup(ai, txFid, 0x0008, BAP1) != SUCCESS)
4223 bap_write(ai, &txControl, sizeof(txControl), BAP1);
4231 /* In general BAP1 is dedicated to transmiting packets. However,
4232 since we need a BAP when accessing RIDs, we also use BAP1 for that.
4233 Make sure the BAP1 spinlock is held when this is called. */
4234 static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket)
4245 if (len <= ETH_ALEN * 2) {
4246 airo_print_warn(ai->dev->name, "Short packet %d", len);
4249 len -= ETH_ALEN * 2;
4251 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
4252 (ntohs(((__be16 *)pPacket)[6]) != 0x888E)) {
4253 if (encapsulate(ai,(etherHead *)pPacket,&pMic,len) != SUCCESS)
4255 miclen = sizeof(pMic);
4257 // packet is destination[6], source[6], payload[len-12]
4258 // write the payload length and dst/src/payload
4259 if (bap_setup(ai, txFid, 0x0036, BAP1) != SUCCESS) return ERROR;
4260 /* The hardware addresses aren't counted as part of the payload, so
4261 * we have to subtract the 12 bytes for the addresses off */
4262 payloadLen = cpu_to_le16(len + miclen);
4263 bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
4264 bap_write(ai, (__le16*)pPacket, sizeof(etherHead), BAP1);
4266 bap_write(ai, (__le16*)&pMic, miclen, BAP1);
4267 bap_write(ai, (__le16*)(pPacket + sizeof(etherHead)), len, BAP1);
4268 // issue the transmit command
4269 memset( &cmd, 0, sizeof( cmd ) );
4270 cmd.cmd = CMD_TRANSMIT;
4272 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
4273 if ( (rsp.status & 0xFF00) != 0) return ERROR;
4277 static int transmit_802_11_packet(struct airo_info *ai, int len, char *pPacket)
4279 __le16 fc, payloadLen;
4283 static u8 tail[(30-10) + 2 + 6] = {[30-10] = 6};
4284 /* padding of header to full size + le16 gaplen (6) + gaplen bytes */
4288 fc = *(__le16*)pPacket;
4289 hdrlen = header_len(fc);
4292 airo_print_warn(ai->dev->name, "Short packet %d", len);
4296 /* packet is 802.11 header + payload
4297 * write the payload length and dst/src/payload */
4298 if (bap_setup(ai, txFid, 6, BAP1) != SUCCESS) return ERROR;
4299 /* The 802.11 header aren't counted as part of the payload, so
4300 * we have to subtract the header bytes off */
4301 payloadLen = cpu_to_le16(len-hdrlen);
4302 bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
4303 if (bap_setup(ai, txFid, 0x0014, BAP1) != SUCCESS) return ERROR;
4304 bap_write(ai, (__le16 *)pPacket, hdrlen, BAP1);
4305 bap_write(ai, (__le16 *)(tail + (hdrlen - 10)), 38 - hdrlen, BAP1);
4307 bap_write(ai, (__le16 *)(pPacket + hdrlen), len - hdrlen, BAP1);
4308 // issue the transmit command
4309 memset( &cmd, 0, sizeof( cmd ) );
4310 cmd.cmd = CMD_TRANSMIT;
4312 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
4313 if ( (rsp.status & 0xFF00) != 0) return ERROR;
4318 * This is the proc_fs routines. It is a bit messier than I would
4319 * like! Feel free to clean it up!
4322 static ssize_t proc_read( struct file *file,
4323 char __user *buffer,
4327 static ssize_t proc_write( struct file *file,
4328 const char __user *buffer,
4331 static int proc_close( struct inode *inode, struct file *file );
4333 static int proc_stats_open( struct inode *inode, struct file *file );
4334 static int proc_statsdelta_open( struct inode *inode, struct file *file );
4335 static int proc_status_open( struct inode *inode, struct file *file );
4336 static int proc_SSID_open( struct inode *inode, struct file *file );
4337 static int proc_APList_open( struct inode *inode, struct file *file );
4338 static int proc_BSSList_open( struct inode *inode, struct file *file );
4339 static int proc_config_open( struct inode *inode, struct file *file );
4340 static int proc_wepkey_open( struct inode *inode, struct file *file );
4342 static const struct file_operations proc_statsdelta_ops = {
4343 .owner = THIS_MODULE,
4345 .open = proc_statsdelta_open,
4346 .release = proc_close
4349 static const struct file_operations proc_stats_ops = {
4350 .owner = THIS_MODULE,
4352 .open = proc_stats_open,
4353 .release = proc_close
4356 static const struct file_operations proc_status_ops = {
4357 .owner = THIS_MODULE,
4359 .open = proc_status_open,
4360 .release = proc_close
4363 static const struct file_operations proc_SSID_ops = {
4364 .owner = THIS_MODULE,
4366 .write = proc_write,
4367 .open = proc_SSID_open,
4368 .release = proc_close
4371 static const struct file_operations proc_BSSList_ops = {
4372 .owner = THIS_MODULE,
4374 .write = proc_write,
4375 .open = proc_BSSList_open,
4376 .release = proc_close
4379 static const struct file_operations proc_APList_ops = {
4380 .owner = THIS_MODULE,
4382 .write = proc_write,
4383 .open = proc_APList_open,
4384 .release = proc_close
4387 static const struct file_operations proc_config_ops = {
4388 .owner = THIS_MODULE,
4390 .write = proc_write,
4391 .open = proc_config_open,
4392 .release = proc_close
4395 static const struct file_operations proc_wepkey_ops = {
4396 .owner = THIS_MODULE,
4398 .write = proc_write,
4399 .open = proc_wepkey_open,
4400 .release = proc_close
4403 static struct proc_dir_entry *airo_entry;
4412 void (*on_close) (struct inode *, struct file *);
4415 static int setup_proc_entry( struct net_device *dev,
4416 struct airo_info *apriv ) {
4417 struct proc_dir_entry *entry;
4418 /* First setup the device directory */
4419 strcpy(apriv->proc_name,dev->name);
4420 apriv->proc_entry = create_proc_entry(apriv->proc_name,
4423 if (!apriv->proc_entry)
4425 apriv->proc_entry->uid = proc_uid;
4426 apriv->proc_entry->gid = proc_gid;
4427 apriv->proc_entry->owner = THIS_MODULE;
4429 /* Setup the StatsDelta */
4430 entry = proc_create_data("StatsDelta",
4431 S_IFREG | (S_IRUGO&proc_perm),
4432 apriv->proc_entry, &proc_statsdelta_ops, dev);
4434 goto fail_stats_delta;
4435 entry->uid = proc_uid;
4436 entry->gid = proc_gid;
4438 /* Setup the Stats */
4439 entry = proc_create_data("Stats",
4440 S_IFREG | (S_IRUGO&proc_perm),
4441 apriv->proc_entry, &proc_stats_ops, dev);
4444 entry->uid = proc_uid;
4445 entry->gid = proc_gid;
4447 /* Setup the Status */
4448 entry = proc_create_data("Status",
4449 S_IFREG | (S_IRUGO&proc_perm),
4450 apriv->proc_entry, &proc_status_ops, dev);
4453 entry->uid = proc_uid;
4454 entry->gid = proc_gid;
4456 /* Setup the Config */
4457 entry = proc_create_data("Config",
4458 S_IFREG | proc_perm,
4459 apriv->proc_entry, &proc_config_ops, dev);
4462 entry->uid = proc_uid;
4463 entry->gid = proc_gid;
4465 /* Setup the SSID */
4466 entry = proc_create_data("SSID",
4467 S_IFREG | proc_perm,
4468 apriv->proc_entry, &proc_SSID_ops, dev);
4471 entry->uid = proc_uid;
4472 entry->gid = proc_gid;
4474 /* Setup the APList */
4475 entry = proc_create_data("APList",
4476 S_IFREG | proc_perm,
4477 apriv->proc_entry, &proc_APList_ops, dev);
4480 entry->uid = proc_uid;
4481 entry->gid = proc_gid;
4483 /* Setup the BSSList */
4484 entry = proc_create_data("BSSList",
4485 S_IFREG | proc_perm,
4486 apriv->proc_entry, &proc_BSSList_ops, dev);
4489 entry->uid = proc_uid;
4490 entry->gid = proc_gid;
4492 /* Setup the WepKey */
4493 entry = proc_create_data("WepKey",
4494 S_IFREG | proc_perm,
4495 apriv->proc_entry, &proc_wepkey_ops, dev);
4498 entry->uid = proc_uid;
4499 entry->gid = proc_gid;
4504 remove_proc_entry("BSSList", apriv->proc_entry);
4506 remove_proc_entry("APList", apriv->proc_entry);
4508 remove_proc_entry("SSID", apriv->proc_entry);
4510 remove_proc_entry("Config", apriv->proc_entry);
4512 remove_proc_entry("Status", apriv->proc_entry);
4514 remove_proc_entry("Stats", apriv->proc_entry);
4516 remove_proc_entry("StatsDelta", apriv->proc_entry);
4518 remove_proc_entry(apriv->proc_name, airo_entry);
4523 static int takedown_proc_entry( struct net_device *dev,
4524 struct airo_info *apriv ) {
4525 if ( !apriv->proc_entry->namelen ) return 0;
4526 remove_proc_entry("Stats",apriv->proc_entry);
4527 remove_proc_entry("StatsDelta",apriv->proc_entry);
4528 remove_proc_entry("Status",apriv->proc_entry);
4529 remove_proc_entry("Config",apriv->proc_entry);
4530 remove_proc_entry("SSID",apriv->proc_entry);
4531 remove_proc_entry("APList",apriv->proc_entry);
4532 remove_proc_entry("BSSList",apriv->proc_entry);
4533 remove_proc_entry("WepKey",apriv->proc_entry);
4534 remove_proc_entry(apriv->proc_name,airo_entry);
4539 * What we want from the proc_fs is to be able to efficiently read
4540 * and write the configuration. To do this, we want to read the
4541 * configuration when the file is opened and write it when the file is
4542 * closed. So basically we allocate a read buffer at open and fill it
4543 * with data, and allocate a write buffer and read it at close.
4547 * The read routine is generic, it relies on the preallocated rbuffer
4548 * to supply the data.
4550 static ssize_t proc_read( struct file *file,
4551 char __user *buffer,
4555 struct proc_data *priv = file->private_data;
4560 return simple_read_from_buffer(buffer, len, offset, priv->rbuffer,
4565 * The write routine is generic, it fills in a preallocated rbuffer
4566 * to supply the data.
4568 static ssize_t proc_write( struct file *file,
4569 const char __user *buffer,
4573 loff_t pos = *offset;
4574 struct proc_data *priv = (struct proc_data*)file->private_data;
4581 if (pos >= priv->maxwritelen)
4583 if (len > priv->maxwritelen - pos)
4584 len = priv->maxwritelen - pos;
4585 if (copy_from_user(priv->wbuffer + pos, buffer, len))
4587 if ( pos + len > priv->writelen )
4588 priv->writelen = len + file->f_pos;
4589 *offset = pos + len;
4593 static int proc_status_open(struct inode *inode, struct file *file)
4595 struct proc_data *data;
4596 struct proc_dir_entry *dp = PDE(inode);
4597 struct net_device *dev = dp->data;
4598 struct airo_info *apriv = dev->ml_priv;
4599 CapabilityRid cap_rid;
4600 StatusRid status_rid;
4604 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4606 data = (struct proc_data *)file->private_data;
4607 if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
4608 kfree (file->private_data);
4612 readStatusRid(apriv, &status_rid, 1);
4613 readCapabilityRid(apriv, &cap_rid, 1);
4615 mode = le16_to_cpu(status_rid.mode);
4617 i = sprintf(data->rbuffer, "Status: %s%s%s%s%s%s%s%s%s\n",
4618 mode & 1 ? "CFG ": "",
4619 mode & 2 ? "ACT ": "",
4620 mode & 0x10 ? "SYN ": "",
4621 mode & 0x20 ? "LNK ": "",
4622 mode & 0x40 ? "LEAP ": "",
4623 mode & 0x80 ? "PRIV ": "",
4624 mode & 0x100 ? "KEY ": "",
4625 mode & 0x200 ? "WEP ": "",
4626 mode & 0x8000 ? "ERR ": "");
4627 sprintf( data->rbuffer+i, "Mode: %x\n"
4628 "Signal Strength: %d\n"
4629 "Signal Quality: %d\n"
4634 "Driver Version: %s\n"
4635 "Device: %s\nManufacturer: %s\nFirmware Version: %s\n"
4636 "Radio type: %x\nCountry: %x\nHardware Version: %x\n"
4637 "Software Version: %x\nSoftware Subversion: %x\n"
4638 "Boot block version: %x\n",
4639 le16_to_cpu(status_rid.mode),
4640 le16_to_cpu(status_rid.normalizedSignalStrength),
4641 le16_to_cpu(status_rid.signalQuality),
4642 le16_to_cpu(status_rid.SSIDlen),
4645 le16_to_cpu(status_rid.channel),
4646 le16_to_cpu(status_rid.currentXmitRate) / 2,
4651 le16_to_cpu(cap_rid.radioType),
4652 le16_to_cpu(cap_rid.country),
4653 le16_to_cpu(cap_rid.hardVer),
4654 le16_to_cpu(cap_rid.softVer),
4655 le16_to_cpu(cap_rid.softSubVer),
4656 le16_to_cpu(cap_rid.bootBlockVer));
4657 data->readlen = strlen( data->rbuffer );
4661 static int proc_stats_rid_open(struct inode*, struct file*, u16);
4662 static int proc_statsdelta_open( struct inode *inode,
4663 struct file *file ) {
4664 if (file->f_mode&FMODE_WRITE) {
4665 return proc_stats_rid_open(inode, file, RID_STATSDELTACLEAR);
4667 return proc_stats_rid_open(inode, file, RID_STATSDELTA);
4670 static int proc_stats_open( struct inode *inode, struct file *file ) {
4671 return proc_stats_rid_open(inode, file, RID_STATS);
4674 static int proc_stats_rid_open( struct inode *inode,
4678 struct proc_data *data;
4679 struct proc_dir_entry *dp = PDE(inode);
4680 struct net_device *dev = dp->data;
4681 struct airo_info *apriv = dev->ml_priv;
4684 __le32 *vals = stats.vals;
4685 int len = le16_to_cpu(stats.len);
4687 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4689 data = (struct proc_data *)file->private_data;
4690 if ((data->rbuffer = kmalloc( 4096, GFP_KERNEL )) == NULL) {
4691 kfree (file->private_data);
4695 readStatsRid(apriv, &stats, rid, 1);
4698 for(i=0; statsLabels[i]!=(char *)-1 && i*4<len; i++) {
4699 if (!statsLabels[i]) continue;
4700 if (j+strlen(statsLabels[i])+16>4096) {
4701 airo_print_warn(apriv->dev->name,
4702 "Potentially disasterous buffer overflow averted!");
4705 j+=sprintf(data->rbuffer+j, "%s: %u\n", statsLabels[i],
4706 le32_to_cpu(vals[i]));
4709 airo_print_warn(apriv->dev->name, "Got a short rid");
4715 static int get_dec_u16( char *buffer, int *start, int limit ) {
4718 for( value = 0; buffer[*start] >= '0' &&
4719 buffer[*start] <= '9' &&
4720 *start < limit; (*start)++ ) {
4723 value += buffer[*start] - '0';
4725 if ( !valid ) return -1;
4729 static int airo_config_commit(struct net_device *dev,
4730 struct iw_request_info *info, void *zwrq,
4733 static inline int sniffing_mode(struct airo_info *ai)
4735 return le16_to_cpu(ai->config.rmode & RXMODE_MASK) >=
4736 le16_to_cpu(RXMODE_RFMON);
4739 static void proc_config_on_close(struct inode *inode, struct file *file)
4741 struct proc_data *data = file->private_data;
4742 struct proc_dir_entry *dp = PDE(inode);
4743 struct net_device *dev = dp->data;
4744 struct airo_info *ai = dev->ml_priv;
4747 if ( !data->writelen ) return;
4749 readConfigRid(ai, 1);
4750 set_bit (FLAG_COMMIT, &ai->flags);
4752 line = data->wbuffer;
4754 /*** Mode processing */
4755 if ( !strncmp( line, "Mode: ", 6 ) ) {
4757 if (sniffing_mode(ai))
4758 set_bit (FLAG_RESET, &ai->flags);
4759 ai->config.rmode &= ~RXMODE_FULL_MASK;
4760 clear_bit (FLAG_802_11, &ai->flags);
4761 ai->config.opmode &= ~MODE_CFG_MASK;
4762 ai->config.scanMode = SCANMODE_ACTIVE;
4763 if ( line[0] == 'a' ) {
4764 ai->config.opmode |= MODE_STA_IBSS;
4766 ai->config.opmode |= MODE_STA_ESS;
4767 if ( line[0] == 'r' ) {
4768 ai->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
4769 ai->config.scanMode = SCANMODE_PASSIVE;
4770 set_bit (FLAG_802_11, &ai->flags);
4771 } else if ( line[0] == 'y' ) {
4772 ai->config.rmode |= RXMODE_RFMON_ANYBSS | RXMODE_DISABLE_802_3_HEADER;
4773 ai->config.scanMode = SCANMODE_PASSIVE;
4774 set_bit (FLAG_802_11, &ai->flags);
4775 } else if ( line[0] == 'l' )
4776 ai->config.rmode |= RXMODE_LANMON;
4778 set_bit (FLAG_COMMIT, &ai->flags);
4781 /*** Radio status */
4782 else if (!strncmp(line,"Radio: ", 7)) {
4784 if (!strncmp(line,"off",3)) {
4785 set_bit (FLAG_RADIO_OFF, &ai->flags);
4787 clear_bit (FLAG_RADIO_OFF, &ai->flags);
4790 /*** NodeName processing */
4791 else if ( !strncmp( line, "NodeName: ", 10 ) ) {
4795 memset( ai->config.nodeName, 0, 16 );
4796 /* Do the name, assume a space between the mode and node name */
4797 for( j = 0; j < 16 && line[j] != '\n'; j++ ) {
4798 ai->config.nodeName[j] = line[j];
4800 set_bit (FLAG_COMMIT, &ai->flags);
4803 /*** PowerMode processing */
4804 else if ( !strncmp( line, "PowerMode: ", 11 ) ) {
4806 if ( !strncmp( line, "PSPCAM", 6 ) ) {
4807 ai->config.powerSaveMode = POWERSAVE_PSPCAM;
4808 set_bit (FLAG_COMMIT, &ai->flags);
4809 } else if ( !strncmp( line, "PSP", 3 ) ) {
4810 ai->config.powerSaveMode = POWERSAVE_PSP;
4811 set_bit (FLAG_COMMIT, &ai->flags);
4813 ai->config.powerSaveMode = POWERSAVE_CAM;
4814 set_bit (FLAG_COMMIT, &ai->flags);
4816 } else if ( !strncmp( line, "DataRates: ", 11 ) ) {
4817 int v, i = 0, k = 0; /* i is index into line,
4818 k is index to rates */
4821 while((v = get_dec_u16(line, &i, 3))!=-1) {
4822 ai->config.rates[k++] = (u8)v;
4826 set_bit (FLAG_COMMIT, &ai->flags);
4827 } else if ( !strncmp( line, "Channel: ", 9 ) ) {
4830 v = get_dec_u16(line, &i, i+3);
4832 ai->config.channelSet = cpu_to_le16(v);
4833 set_bit (FLAG_COMMIT, &ai->flags);
4835 } else if ( !strncmp( line, "XmitPower: ", 11 ) ) {
4838 v = get_dec_u16(line, &i, i+3);
4840 ai->config.txPower = cpu_to_le16(v);
4841 set_bit (FLAG_COMMIT, &ai->flags);
4843 } else if ( !strncmp( line, "WEP: ", 5 ) ) {
4847 ai->config.authType = AUTH_SHAREDKEY;
4850 ai->config.authType = AUTH_ENCRYPT;
4853 ai->config.authType = AUTH_OPEN;
4856 set_bit (FLAG_COMMIT, &ai->flags);
4857 } else if ( !strncmp( line, "LongRetryLimit: ", 16 ) ) {
4861 v = get_dec_u16(line, &i, 3);
4862 v = (v<0) ? 0 : ((v>255) ? 255 : v);
4863 ai->config.longRetryLimit = cpu_to_le16(v);
4864 set_bit (FLAG_COMMIT, &ai->flags);
4865 } else if ( !strncmp( line, "ShortRetryLimit: ", 17 ) ) {
4869 v = get_dec_u16(line, &i, 3);
4870 v = (v<0) ? 0 : ((v>255) ? 255 : v);
4871 ai->config.shortRetryLimit = cpu_to_le16(v);
4872 set_bit (FLAG_COMMIT, &ai->flags);
4873 } else if ( !strncmp( line, "RTSThreshold: ", 14 ) ) {
4877 v = get_dec_u16(line, &i, 4);
4878 v = (v<0) ? 0 : ((v>AIRO_DEF_MTU) ? AIRO_DEF_MTU : v);
4879 ai->config.rtsThres = cpu_to_le16(v);
4880 set_bit (FLAG_COMMIT, &ai->flags);
4881 } else if ( !strncmp( line, "TXMSDULifetime: ", 16 ) ) {
4885 v = get_dec_u16(line, &i, 5);
4887 ai->config.txLifetime = cpu_to_le16(v);
4888 set_bit (FLAG_COMMIT, &ai->flags);
4889 } else if ( !strncmp( line, "RXMSDULifetime: ", 16 ) ) {
4893 v = get_dec_u16(line, &i, 5);
4895 ai->config.rxLifetime = cpu_to_le16(v);
4896 set_bit (FLAG_COMMIT, &ai->flags);
4897 } else if ( !strncmp( line, "TXDiversity: ", 13 ) ) {
4898 ai->config.txDiversity =
4899 (line[13]=='l') ? 1 :
4900 ((line[13]=='r')? 2: 3);
4901 set_bit (FLAG_COMMIT, &ai->flags);
4902 } else if ( !strncmp( line, "RXDiversity: ", 13 ) ) {
4903 ai->config.rxDiversity =
4904 (line[13]=='l') ? 1 :
4905 ((line[13]=='r')? 2: 3);
4906 set_bit (FLAG_COMMIT, &ai->flags);
4907 } else if ( !strncmp( line, "FragThreshold: ", 15 ) ) {
4911 v = get_dec_u16(line, &i, 4);
4912 v = (v<256) ? 256 : ((v>AIRO_DEF_MTU) ? AIRO_DEF_MTU : v);
4913 v = v & 0xfffe; /* Make sure its even */
4914 ai->config.fragThresh = cpu_to_le16(v);
4915 set_bit (FLAG_COMMIT, &ai->flags);
4916 } else if (!strncmp(line, "Modulation: ", 12)) {
4919 case 'd': ai->config.modulation=MOD_DEFAULT; set_bit(FLAG_COMMIT, &ai->flags); break;
4920 case 'c': ai->config.modulation=MOD_CCK; set_bit(FLAG_COMMIT, &ai->flags); break;
4921 case 'm': ai->config.modulation=MOD_MOK; set_bit(FLAG_COMMIT, &ai->flags); break;
4922 default: airo_print_warn(ai->dev->name, "Unknown modulation");
4924 } else if (!strncmp(line, "Preamble: ", 10)) {
4927 case 'a': ai->config.preamble=PREAMBLE_AUTO; set_bit(FLAG_COMMIT, &ai->flags); break;
4928 case 'l': ai->config.preamble=PREAMBLE_LONG; set_bit(FLAG_COMMIT, &ai->flags); break;
4929 case 's': ai->config.preamble=PREAMBLE_SHORT; set_bit(FLAG_COMMIT, &ai->flags); break;
4930 default: airo_print_warn(ai->dev->name, "Unknown preamble");
4933 airo_print_warn(ai->dev->name, "Couldn't figure out %s", line);
4935 while( line[0] && line[0] != '\n' ) line++;
4936 if ( line[0] ) line++;
4938 airo_config_commit(dev, NULL, NULL, NULL);
4941 static char *get_rmode(__le16 mode)
4943 switch(mode & RXMODE_MASK) {
4944 case RXMODE_RFMON: return "rfmon";
4945 case RXMODE_RFMON_ANYBSS: return "yna (any) bss rfmon";
4946 case RXMODE_LANMON: return "lanmon";
4951 static int proc_config_open(struct inode *inode, struct file *file)
4953 struct proc_data *data;
4954 struct proc_dir_entry *dp = PDE(inode);
4955 struct net_device *dev = dp->data;
4956 struct airo_info *ai = dev->ml_priv;
4960 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4962 data = (struct proc_data *)file->private_data;
4963 if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
4964 kfree (file->private_data);
4967 if ((data->wbuffer = kzalloc( 2048, GFP_KERNEL )) == NULL) {
4968 kfree (data->rbuffer);
4969 kfree (file->private_data);
4972 data->maxwritelen = 2048;
4973 data->on_close = proc_config_on_close;
4975 readConfigRid(ai, 1);
4977 mode = ai->config.opmode & MODE_CFG_MASK;
4978 i = sprintf( data->rbuffer,
4983 "DataRates: %d %d %d %d %d %d %d %d\n"
4986 mode == MODE_STA_IBSS ? "adhoc" :
4987 mode == MODE_STA_ESS ? get_rmode(ai->config.rmode):
4988 mode == MODE_AP ? "AP" :
4989 mode == MODE_AP_RPTR ? "AP RPTR" : "Error",
4990 test_bit(FLAG_RADIO_OFF, &ai->flags) ? "off" : "on",
4991 ai->config.nodeName,
4992 ai->config.powerSaveMode == POWERSAVE_CAM ? "CAM" :
4993 ai->config.powerSaveMode == POWERSAVE_PSP ? "PSP" :
4994 ai->config.powerSaveMode == POWERSAVE_PSPCAM ? "PSPCAM" :
4996 (int)ai->config.rates[0],
4997 (int)ai->config.rates[1],
4998 (int)ai->config.rates[2],
4999 (int)ai->config.rates[3],
5000 (int)ai->config.rates[4],
5001 (int)ai->config.rates[5],
5002 (int)ai->config.rates[6],
5003 (int)ai->config.rates[7],
5004 le16_to_cpu(ai->config.channelSet),
5005 le16_to_cpu(ai->config.txPower)
5007 sprintf( data->rbuffer + i,
5008 "LongRetryLimit: %d\n"
5009 "ShortRetryLimit: %d\n"
5010 "RTSThreshold: %d\n"
5011 "TXMSDULifetime: %d\n"
5012 "RXMSDULifetime: %d\n"
5015 "FragThreshold: %d\n"
5019 le16_to_cpu(ai->config.longRetryLimit),
5020 le16_to_cpu(ai->config.shortRetryLimit),
5021 le16_to_cpu(ai->config.rtsThres),
5022 le16_to_cpu(ai->config.txLifetime),
5023 le16_to_cpu(ai->config.rxLifetime),
5024 ai->config.txDiversity == 1 ? "left" :
5025 ai->config.txDiversity == 2 ? "right" : "both",
5026 ai->config.rxDiversity == 1 ? "left" :
5027 ai->config.rxDiversity == 2 ? "right" : "both",
5028 le16_to_cpu(ai->config.fragThresh),
5029 ai->config.authType == AUTH_ENCRYPT ? "encrypt" :
5030 ai->config.authType == AUTH_SHAREDKEY ? "shared" : "open",
5031 ai->config.modulation == MOD_DEFAULT ? "default" :
5032 ai->config.modulation == MOD_CCK ? "cck" :
5033 ai->config.modulation == MOD_MOK ? "mok" : "error",
5034 ai->config.preamble == PREAMBLE_AUTO ? "auto" :
5035 ai->config.preamble == PREAMBLE_LONG ? "long" :
5036 ai->config.preamble == PREAMBLE_SHORT ? "short" : "error"
5038 data->readlen = strlen( data->rbuffer );
5042 static void proc_SSID_on_close(struct inode *inode, struct file *file)
5044 struct proc_data *data = (struct proc_data *)file->private_data;
5045 struct proc_dir_entry *dp = PDE(inode);
5046 struct net_device *dev = dp->data;
5047 struct airo_info *ai = dev->ml_priv;
5050 char *p = data->wbuffer;
5051 char *end = p + data->writelen;
5053 if (!data->writelen)
5056 *end = '\n'; /* sentinel; we have space for it */
5058 memset(&SSID_rid, 0, sizeof(SSID_rid));
5060 for (i = 0; i < 3 && p < end; i++) {
5062 /* copy up to 32 characters from this line */
5063 while (*p != '\n' && j < 32)
5064 SSID_rid.ssids[i].ssid[j++] = *p++;
5067 SSID_rid.ssids[i].len = cpu_to_le16(j);
5068 /* skip to the beginning of the next line */
5069 while (*p++ != '\n')
5073 SSID_rid.len = cpu_to_le16(sizeof(SSID_rid));
5075 writeSsidRid(ai, &SSID_rid, 1);
5079 static inline u8 hexVal(char c) {
5080 if (c>='0' && c<='9') return c -= '0';
5081 if (c>='a' && c<='f') return c -= 'a'-10;
5082 if (c>='A' && c<='F') return c -= 'A'-10;
5086 static void proc_APList_on_close( struct inode *inode, struct file *file ) {
5087 struct proc_data *data = (struct proc_data *)file->private_data;
5088 struct proc_dir_entry *dp = PDE(inode);
5089 struct net_device *dev = dp->data;
5090 struct airo_info *ai = dev->ml_priv;
5091 APListRid APList_rid;
5094 if ( !data->writelen ) return;
5096 memset( &APList_rid, 0, sizeof(APList_rid) );
5097 APList_rid.len = cpu_to_le16(sizeof(APList_rid));
5099 for( i = 0; i < 4 && data->writelen >= (i+1)*6*3; i++ ) {
5101 for( j = 0; j < 6*3 && data->wbuffer[j+i*6*3]; j++ ) {
5104 APList_rid.ap[i][j/3]=
5105 hexVal(data->wbuffer[j+i*6*3])<<4;
5108 APList_rid.ap[i][j/3]|=
5109 hexVal(data->wbuffer[j+i*6*3]);
5115 writeAPListRid(ai, &APList_rid, 1);
5119 /* This function wraps PC4500_writerid with a MAC disable */
5120 static int do_writerid( struct airo_info *ai, u16 rid, const void *rid_data,
5121 int len, int dummy ) {
5125 rc = PC4500_writerid(ai, rid, rid_data, len, 1);
5130 /* Returns the length of the key at the index. If index == 0xffff
5131 * the index of the transmit key is returned. If the key doesn't exist,
5132 * -1 will be returned.
5134 static int get_wep_key(struct airo_info *ai, u16 index) {
5139 rc = readWepKeyRid(ai, &wkr, 1, 1);
5140 if (rc == SUCCESS) do {
5141 lastindex = wkr.kindex;
5142 if (wkr.kindex == cpu_to_le16(index)) {
5143 if (index == 0xffff) {
5146 return le16_to_cpu(wkr.klen);
5148 readWepKeyRid(ai, &wkr, 0, 1);
5149 } while (lastindex != wkr.kindex);
5153 static int set_wep_key(struct airo_info *ai, u16 index,
5154 const char *key, u16 keylen, int perm, int lock )
5156 static const unsigned char macaddr[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
5159 memset(&wkr, 0, sizeof(wkr));
5161 // We are selecting which key to use
5162 wkr.len = cpu_to_le16(sizeof(wkr));
5163 wkr.kindex = cpu_to_le16(0xffff);
5164 wkr.mac[0] = (char)index;
5165 if (perm) ai->defindex = (char)index;
5167 // We are actually setting the key
5168 wkr.len = cpu_to_le16(sizeof(wkr));
5169 wkr.kindex = cpu_to_le16(index);
5170 wkr.klen = cpu_to_le16(keylen);
5171 memcpy( wkr.key, key, keylen );
5172 memcpy( wkr.mac, macaddr, ETH_ALEN );
5175 if (perm) disable_MAC(ai, lock);
5176 writeWepKeyRid(ai, &wkr, perm, lock);
5177 if (perm) enable_MAC(ai, lock);
5181 static void proc_wepkey_on_close( struct inode *inode, struct file *file ) {
5182 struct proc_data *data;
5183 struct proc_dir_entry *dp = PDE(inode);
5184 struct net_device *dev = dp->data;
5185 struct airo_info *ai = dev->ml_priv;
5191 memset(key, 0, sizeof(key));
5193 data = (struct proc_data *)file->private_data;
5194 if ( !data->writelen ) return;
5196 if (data->wbuffer[0] >= '0' && data->wbuffer[0] <= '3' &&
5197 (data->wbuffer[1] == ' ' || data->wbuffer[1] == '\n')) {
5198 index = data->wbuffer[0] - '0';
5199 if (data->wbuffer[1] == '\n') {
5200 set_wep_key(ai, index, NULL, 0, 1, 1);
5205 airo_print_err(ai->dev->name, "WepKey passed invalid key index");
5209 for( i = 0; i < 16*3 && data->wbuffer[i+j]; i++ ) {
5212 key[i/3] = hexVal(data->wbuffer[i+j])<<4;
5215 key[i/3] |= hexVal(data->wbuffer[i+j]);
5219 set_wep_key(ai, index, key, i/3, 1, 1);
5222 static int proc_wepkey_open( struct inode *inode, struct file *file )
5224 struct proc_data *data;
5225 struct proc_dir_entry *dp = PDE(inode);
5226 struct net_device *dev = dp->data;
5227 struct airo_info *ai = dev->ml_priv;
5234 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5236 memset(&wkr, 0, sizeof(wkr));
5237 data = (struct proc_data *)file->private_data;
5238 if ((data->rbuffer = kzalloc( 180, GFP_KERNEL )) == NULL) {
5239 kfree (file->private_data);
5243 data->maxwritelen = 80;
5244 if ((data->wbuffer = kzalloc( 80, GFP_KERNEL )) == NULL) {
5245 kfree (data->rbuffer);
5246 kfree (file->private_data);
5249 data->on_close = proc_wepkey_on_close;
5251 ptr = data->rbuffer;
5252 strcpy(ptr, "No wep keys\n");
5253 rc = readWepKeyRid(ai, &wkr, 1, 1);
5254 if (rc == SUCCESS) do {
5255 lastindex = wkr.kindex;
5256 if (wkr.kindex == cpu_to_le16(0xffff)) {
5257 j += sprintf(ptr+j, "Tx key = %d\n",
5260 j += sprintf(ptr+j, "Key %d set with length = %d\n",
5261 le16_to_cpu(wkr.kindex),
5262 le16_to_cpu(wkr.klen));
5264 readWepKeyRid(ai, &wkr, 0, 1);
5265 } while((lastindex != wkr.kindex) && (j < 180-30));
5267 data->readlen = strlen( data->rbuffer );
5271 static int proc_SSID_open(struct inode *inode, struct file *file)
5273 struct proc_data *data;
5274 struct proc_dir_entry *dp = PDE(inode);
5275 struct net_device *dev = dp->data;
5276 struct airo_info *ai = dev->ml_priv;
5281 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5283 data = (struct proc_data *)file->private_data;
5284 if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
5285 kfree (file->private_data);
5289 data->maxwritelen = 33*3;
5290 /* allocate maxwritelen + 1; we'll want a sentinel */
5291 if ((data->wbuffer = kzalloc(33*3 + 1, GFP_KERNEL)) == NULL) {
5292 kfree (data->rbuffer);
5293 kfree (file->private_data);
5296 data->on_close = proc_SSID_on_close;
5298 readSsidRid(ai, &SSID_rid);
5299 ptr = data->rbuffer;
5300 for (i = 0; i < 3; i++) {
5302 size_t len = le16_to_cpu(SSID_rid.ssids[i].len);
5307 for (j = 0; j < len && SSID_rid.ssids[i].ssid[j]; j++)
5308 *ptr++ = SSID_rid.ssids[i].ssid[j];
5312 data->readlen = strlen( data->rbuffer );
5316 static int proc_APList_open( struct inode *inode, struct file *file ) {
5317 struct proc_data *data;
5318 struct proc_dir_entry *dp = PDE(inode);
5319 struct net_device *dev = dp->data;
5320 struct airo_info *ai = dev->ml_priv;
5323 APListRid APList_rid;
5325 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5327 data = (struct proc_data *)file->private_data;
5328 if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
5329 kfree (file->private_data);
5333 data->maxwritelen = 4*6*3;
5334 if ((data->wbuffer = kzalloc( data->maxwritelen, GFP_KERNEL )) == NULL) {
5335 kfree (data->rbuffer);
5336 kfree (file->private_data);
5339 data->on_close = proc_APList_on_close;
5341 readAPListRid(ai, &APList_rid);
5342 ptr = data->rbuffer;
5343 for( i = 0; i < 4; i++ ) {
5344 // We end when we find a zero MAC
5345 if ( !*(int*)APList_rid.ap[i] &&
5346 !*(int*)&APList_rid.ap[i][2]) break;
5347 ptr += sprintf(ptr, "%pM\n", APList_rid.ap[i]);
5349 if (i==0) ptr += sprintf(ptr, "Not using specific APs\n");
5352 data->readlen = strlen( data->rbuffer );
5356 static int proc_BSSList_open( struct inode *inode, struct file *file ) {
5357 struct proc_data *data;
5358 struct proc_dir_entry *dp = PDE(inode);
5359 struct net_device *dev = dp->data;
5360 struct airo_info *ai = dev->ml_priv;
5362 BSSListRid BSSList_rid;
5364 /* If doLoseSync is not 1, we won't do a Lose Sync */
5365 int doLoseSync = -1;
5367 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5369 data = (struct proc_data *)file->private_data;
5370 if ((data->rbuffer = kmalloc( 1024, GFP_KERNEL )) == NULL) {
5371 kfree (file->private_data);
5375 data->maxwritelen = 0;
5376 data->wbuffer = NULL;
5377 data->on_close = NULL;
5379 if (file->f_mode & FMODE_WRITE) {
5380 if (!(file->f_mode & FMODE_READ)) {
5384 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
5385 memset(&cmd, 0, sizeof(cmd));
5386 cmd.cmd=CMD_LISTBSS;
5387 if (down_interruptible(&ai->sem))
5388 return -ERESTARTSYS;
5389 issuecommand(ai, &cmd, &rsp);
5396 ptr = data->rbuffer;
5397 /* There is a race condition here if there are concurrent opens.
5398 Since it is a rare condition, we'll just live with it, otherwise
5399 we have to add a spin lock... */
5400 rc = readBSSListRid(ai, doLoseSync, &BSSList_rid);
5401 while(rc == 0 && BSSList_rid.index != cpu_to_le16(0xffff)) {
5402 ptr += sprintf(ptr, "%pM %*s rssi = %d",
5404 (int)BSSList_rid.ssidLen,
5406 le16_to_cpu(BSSList_rid.dBm));
5407 ptr += sprintf(ptr, " channel = %d %s %s %s %s\n",
5408 le16_to_cpu(BSSList_rid.dsChannel),
5409 BSSList_rid.cap & CAP_ESS ? "ESS" : "",
5410 BSSList_rid.cap & CAP_IBSS ? "adhoc" : "",
5411 BSSList_rid.cap & CAP_PRIVACY ? "wep" : "",
5412 BSSList_rid.cap & CAP_SHORTHDR ? "shorthdr" : "");
5413 rc = readBSSListRid(ai, 0, &BSSList_rid);
5416 data->readlen = strlen( data->rbuffer );
5420 static int proc_close( struct inode *inode, struct file *file )
5422 struct proc_data *data = file->private_data;
5424 if (data->on_close != NULL)
5425 data->on_close(inode, file);
5426 kfree(data->rbuffer);
5427 kfree(data->wbuffer);
5432 /* Since the card doesn't automatically switch to the right WEP mode,
5433 we will make it do it. If the card isn't associated, every secs we
5434 will switch WEP modes to see if that will help. If the card is
5435 associated we will check every minute to see if anything has
5437 static void timer_func( struct net_device *dev ) {
5438 struct airo_info *apriv = dev->ml_priv;
5440 /* We don't have a link so try changing the authtype */
5441 readConfigRid(apriv, 0);
5442 disable_MAC(apriv, 0);
5443 switch(apriv->config.authType) {
5445 /* So drop to OPEN */
5446 apriv->config.authType = AUTH_OPEN;
5448 case AUTH_SHAREDKEY:
5449 if (apriv->keyindex < auto_wep) {
5450 set_wep_key(apriv, apriv->keyindex, NULL, 0, 0, 0);
5451 apriv->config.authType = AUTH_SHAREDKEY;
5454 /* Drop to ENCRYPT */
5455 apriv->keyindex = 0;
5456 set_wep_key(apriv, apriv->defindex, NULL, 0, 0, 0);
5457 apriv->config.authType = AUTH_ENCRYPT;
5460 default: /* We'll escalate to SHAREDKEY */
5461 apriv->config.authType = AUTH_SHAREDKEY;
5463 set_bit (FLAG_COMMIT, &apriv->flags);
5464 writeConfigRid(apriv, 0);
5465 enable_MAC(apriv, 0);
5468 /* Schedule check to see if the change worked */
5469 clear_bit(JOB_AUTOWEP, &apriv->jobs);
5470 apriv->expires = RUN_AT(HZ*3);
5474 static int __devinit airo_pci_probe(struct pci_dev *pdev,
5475 const struct pci_device_id *pent)
5477 struct net_device *dev;
5479 if (pci_enable_device(pdev))
5481 pci_set_master(pdev);
5483 if (pdev->device == 0x5000 || pdev->device == 0xa504)
5484 dev = _init_airo_card(pdev->irq, pdev->resource[0].start, 0, pdev, &pdev->dev);
5486 dev = _init_airo_card(pdev->irq, pdev->resource[2].start, 0, pdev, &pdev->dev);
5488 pci_disable_device(pdev);
5492 pci_set_drvdata(pdev, dev);
5496 static void __devexit airo_pci_remove(struct pci_dev *pdev)
5498 struct net_device *dev = pci_get_drvdata(pdev);
5500 airo_print_info(dev->name, "Unregistering...");
5501 stop_airo_card(dev, 1);
5502 pci_disable_device(pdev);
5503 pci_set_drvdata(pdev, NULL);
5506 static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state)
5508 struct net_device *dev = pci_get_drvdata(pdev);
5509 struct airo_info *ai = dev->ml_priv;
5514 ai->APList = kmalloc(sizeof(APListRid), GFP_KERNEL);
5518 ai->SSID = kmalloc(sizeof(SsidRid), GFP_KERNEL);
5521 readAPListRid(ai, ai->APList);
5522 readSsidRid(ai, ai->SSID);
5523 memset(&cmd, 0, sizeof(cmd));
5524 /* the lock will be released at the end of the resume callback */
5525 if (down_interruptible(&ai->sem))
5528 netif_device_detach(dev);
5530 cmd.cmd = HOSTSLEEP;
5531 issuecommand(ai, &cmd, &rsp);
5533 pci_enable_wake(pdev, pci_choose_state(pdev, state), 1);
5534 pci_save_state(pdev);
5535 return pci_set_power_state(pdev, pci_choose_state(pdev, state));
5538 static int airo_pci_resume(struct pci_dev *pdev)
5540 struct net_device *dev = pci_get_drvdata(pdev);
5541 struct airo_info *ai = dev->ml_priv;
5542 pci_power_t prev_state = pdev->current_state;
5544 pci_set_power_state(pdev, PCI_D0);
5545 pci_restore_state(pdev);
5546 pci_enable_wake(pdev, PCI_D0, 0);
5548 if (prev_state != PCI_D1) {
5550 mpi_init_descriptors(ai);
5551 setup_card(ai, dev->dev_addr, 0);
5552 clear_bit(FLAG_RADIO_OFF, &ai->flags);
5553 clear_bit(FLAG_PENDING_XMIT, &ai->flags);
5555 OUT4500(ai, EVACK, EV_AWAKEN);
5556 OUT4500(ai, EVACK, EV_AWAKEN);
5560 set_bit(FLAG_COMMIT, &ai->flags);
5564 writeSsidRid(ai, ai->SSID, 0);
5569 writeAPListRid(ai, ai->APList, 0);
5573 writeConfigRid(ai, 0);
5575 ai->power = PMSG_ON;
5576 netif_device_attach(dev);
5577 netif_wake_queue(dev);
5578 enable_interrupts(ai);
5584 static int __init airo_init_module( void )
5588 airo_entry = create_proc_entry("driver/aironet",
5589 S_IFDIR | airo_perm,
5593 airo_entry->uid = proc_uid;
5594 airo_entry->gid = proc_gid;
5597 for (i = 0; i < 4 && io[i] && irq[i]; i++) {
5598 airo_print_info("", "Trying to configure ISA adapter at irq=%d "
5599 "io=0x%x", irq[i], io[i] );
5600 if (init_airo_card( irq[i], io[i], 0, NULL ))
5605 airo_print_info("", "Probing for PCI adapters");
5606 i = pci_register_driver(&airo_driver);
5607 airo_print_info("", "Finished probing for PCI adapters");
5610 remove_proc_entry("driver/aironet", NULL);
5615 /* Always exit with success, as we are a library module
5616 * as well as a driver module
5621 static void __exit airo_cleanup_module( void )
5623 struct airo_info *ai;
5624 while(!list_empty(&airo_devices)) {
5625 ai = list_entry(airo_devices.next, struct airo_info, dev_list);
5626 airo_print_info(ai->dev->name, "Unregistering...");
5627 stop_airo_card(ai->dev, 1);
5630 pci_unregister_driver(&airo_driver);
5632 remove_proc_entry("driver/aironet", NULL);
5636 * Initial Wireless Extension code for Aironet driver by :
5637 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
5638 * Conversion to new driver API by :
5639 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
5640 * Javier also did a good amount of work here, adding some new extensions
5641 * and fixing my code. Let's just say that without him this code just
5642 * would not work at all... - Jean II
5645 static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi)
5650 return (0x100 - rssi_rid[rssi].rssidBm);
5653 static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm)
5660 for (i = 0; i < 256; i++)
5661 if (rssi_rid[i].rssidBm == dbm)
5662 return rssi_rid[i].rssipct;
5668 static int airo_get_quality (StatusRid *status_rid, CapabilityRid *cap_rid)
5673 if ((status_rid->mode & cpu_to_le16(0x3f)) != cpu_to_le16(0x3f))
5676 if (!(cap_rid->hardCap & cpu_to_le16(8)))
5679 sq = le16_to_cpu(status_rid->signalQuality);
5680 if (memcmp(cap_rid->prodName, "350", 3))
5684 quality = 0x20 - sq;
5691 quality = 0xb0 - sq;
5695 #define airo_get_max_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x20 : 0xa0)
5696 #define airo_get_avg_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x10 : 0x50);
5698 /*------------------------------------------------------------------*/
5700 * Wireless Handler : get protocol name
5702 static int airo_get_name(struct net_device *dev,
5703 struct iw_request_info *info,
5707 strcpy(cwrq, "IEEE 802.11-DS");
5711 /*------------------------------------------------------------------*/
5713 * Wireless Handler : set frequency
5715 static int airo_set_freq(struct net_device *dev,
5716 struct iw_request_info *info,
5717 struct iw_freq *fwrq,
5720 struct airo_info *local = dev->ml_priv;
5721 int rc = -EINPROGRESS; /* Call commit handler */
5723 /* If setting by frequency, convert to a channel */
5725 int f = fwrq->m / 100000;
5727 /* Hack to fall through... */
5729 fwrq->m = ieee80211_freq_to_dsss_chan(f);
5731 /* Setting by channel number */
5732 if((fwrq->m > 1000) || (fwrq->e > 0))
5735 int channel = fwrq->m;
5736 /* We should do a better check than that,
5737 * based on the card capability !!! */
5738 if((channel < 1) || (channel > 14)) {
5739 airo_print_dbg(dev->name, "New channel value of %d is invalid!",
5743 readConfigRid(local, 1);
5744 /* Yes ! We can set it !!! */
5745 local->config.channelSet = cpu_to_le16(channel);
5746 set_bit (FLAG_COMMIT, &local->flags);
5752 /*------------------------------------------------------------------*/
5754 * Wireless Handler : get frequency
5756 static int airo_get_freq(struct net_device *dev,
5757 struct iw_request_info *info,
5758 struct iw_freq *fwrq,
5761 struct airo_info *local = dev->ml_priv;
5762 StatusRid status_rid; /* Card status info */
5765 readConfigRid(local, 1);
5766 if ((local->config.opmode & MODE_CFG_MASK) == MODE_STA_ESS)
5767 status_rid.channel = local->config.channelSet;
5769 readStatusRid(local, &status_rid, 1);
5771 ch = le16_to_cpu(status_rid.channel);
5772 if((ch > 0) && (ch < 15)) {
5773 fwrq->m = ieee80211_dsss_chan_to_freq(ch) * 100000;
5783 /*------------------------------------------------------------------*/
5785 * Wireless Handler : set ESSID
5787 static int airo_set_essid(struct net_device *dev,
5788 struct iw_request_info *info,
5789 struct iw_point *dwrq,
5792 struct airo_info *local = dev->ml_priv;
5793 SsidRid SSID_rid; /* SSIDs */
5795 /* Reload the list of current SSID */
5796 readSsidRid(local, &SSID_rid);
5798 /* Check if we asked for `any' */
5799 if(dwrq->flags == 0) {
5800 /* Just send an empty SSID list */
5801 memset(&SSID_rid, 0, sizeof(SSID_rid));
5803 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
5805 /* Check the size of the string */
5806 if(dwrq->length > IW_ESSID_MAX_SIZE) {
5809 /* Check if index is valid */
5810 if((index < 0) || (index >= 4)) {
5815 memset(SSID_rid.ssids[index].ssid, 0,
5816 sizeof(SSID_rid.ssids[index].ssid));
5817 memcpy(SSID_rid.ssids[index].ssid, extra, dwrq->length);
5818 SSID_rid.ssids[index].len = cpu_to_le16(dwrq->length);
5820 SSID_rid.len = cpu_to_le16(sizeof(SSID_rid));
5821 /* Write it to the card */
5822 disable_MAC(local, 1);
5823 writeSsidRid(local, &SSID_rid, 1);
5824 enable_MAC(local, 1);
5829 /*------------------------------------------------------------------*/
5831 * Wireless Handler : get ESSID
5833 static int airo_get_essid(struct net_device *dev,
5834 struct iw_request_info *info,
5835 struct iw_point *dwrq,
5838 struct airo_info *local = dev->ml_priv;
5839 StatusRid status_rid; /* Card status info */
5841 readStatusRid(local, &status_rid, 1);
5843 /* Note : if dwrq->flags != 0, we should
5844 * get the relevant SSID from the SSID list... */
5846 /* Get the current SSID */
5847 memcpy(extra, status_rid.SSID, le16_to_cpu(status_rid.SSIDlen));
5848 /* If none, we may want to get the one that was set */
5851 dwrq->length = le16_to_cpu(status_rid.SSIDlen);
5852 dwrq->flags = 1; /* active */
5857 /*------------------------------------------------------------------*/
5859 * Wireless Handler : set AP address
5861 static int airo_set_wap(struct net_device *dev,
5862 struct iw_request_info *info,
5863 struct sockaddr *awrq,
5866 struct airo_info *local = dev->ml_priv;
5869 APListRid APList_rid;
5870 static const u8 any[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5871 static const u8 off[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5873 if (awrq->sa_family != ARPHRD_ETHER)
5875 else if (!memcmp(any, awrq->sa_data, ETH_ALEN) ||
5876 !memcmp(off, awrq->sa_data, ETH_ALEN)) {
5877 memset(&cmd, 0, sizeof(cmd));
5878 cmd.cmd=CMD_LOSE_SYNC;
5879 if (down_interruptible(&local->sem))
5880 return -ERESTARTSYS;
5881 issuecommand(local, &cmd, &rsp);
5884 memset(&APList_rid, 0, sizeof(APList_rid));
5885 APList_rid.len = cpu_to_le16(sizeof(APList_rid));
5886 memcpy(APList_rid.ap[0], awrq->sa_data, ETH_ALEN);
5887 disable_MAC(local, 1);
5888 writeAPListRid(local, &APList_rid, 1);
5889 enable_MAC(local, 1);
5894 /*------------------------------------------------------------------*/
5896 * Wireless Handler : get AP address
5898 static int airo_get_wap(struct net_device *dev,
5899 struct iw_request_info *info,
5900 struct sockaddr *awrq,
5903 struct airo_info *local = dev->ml_priv;
5904 StatusRid status_rid; /* Card status info */
5906 readStatusRid(local, &status_rid, 1);
5908 /* Tentative. This seems to work, wow, I'm lucky !!! */
5909 memcpy(awrq->sa_data, status_rid.bssid[0], ETH_ALEN);
5910 awrq->sa_family = ARPHRD_ETHER;
5915 /*------------------------------------------------------------------*/
5917 * Wireless Handler : set Nickname
5919 static int airo_set_nick(struct net_device *dev,
5920 struct iw_request_info *info,
5921 struct iw_point *dwrq,
5924 struct airo_info *local = dev->ml_priv;
5926 /* Check the size of the string */
5927 if(dwrq->length > 16) {
5930 readConfigRid(local, 1);
5931 memset(local->config.nodeName, 0, sizeof(local->config.nodeName));
5932 memcpy(local->config.nodeName, extra, dwrq->length);
5933 set_bit (FLAG_COMMIT, &local->flags);
5935 return -EINPROGRESS; /* Call commit handler */
5938 /*------------------------------------------------------------------*/
5940 * Wireless Handler : get Nickname
5942 static int airo_get_nick(struct net_device *dev,
5943 struct iw_request_info *info,
5944 struct iw_point *dwrq,
5947 struct airo_info *local = dev->ml_priv;
5949 readConfigRid(local, 1);
5950 strncpy(extra, local->config.nodeName, 16);
5952 dwrq->length = strlen(extra);
5957 /*------------------------------------------------------------------*/
5959 * Wireless Handler : set Bit-Rate
5961 static int airo_set_rate(struct net_device *dev,
5962 struct iw_request_info *info,
5963 struct iw_param *vwrq,
5966 struct airo_info *local = dev->ml_priv;
5967 CapabilityRid cap_rid; /* Card capability info */
5971 /* First : get a valid bit rate value */
5972 readCapabilityRid(local, &cap_rid, 1);
5974 /* Which type of value ? */
5975 if((vwrq->value < 8) && (vwrq->value >= 0)) {
5976 /* Setting by rate index */
5977 /* Find value in the magic rate table */
5978 brate = cap_rid.supportedRates[vwrq->value];
5980 /* Setting by frequency value */
5981 u8 normvalue = (u8) (vwrq->value/500000);
5983 /* Check if rate is valid */
5984 for(i = 0 ; i < 8 ; i++) {
5985 if(normvalue == cap_rid.supportedRates[i]) {
5991 /* -1 designed the max rate (mostly auto mode) */
5992 if(vwrq->value == -1) {
5993 /* Get the highest available rate */
5994 for(i = 0 ; i < 8 ; i++) {
5995 if(cap_rid.supportedRates[i] == 0)
5999 brate = cap_rid.supportedRates[i - 1];
6001 /* Check that it is valid */
6006 readConfigRid(local, 1);
6007 /* Now, check if we want a fixed or auto value */
6008 if(vwrq->fixed == 0) {
6009 /* Fill all the rates up to this max rate */
6010 memset(local->config.rates, 0, 8);
6011 for(i = 0 ; i < 8 ; i++) {
6012 local->config.rates[i] = cap_rid.supportedRates[i];
6013 if(local->config.rates[i] == brate)
6018 /* One rate, fixed */
6019 memset(local->config.rates, 0, 8);
6020 local->config.rates[0] = brate;
6022 set_bit (FLAG_COMMIT, &local->flags);
6024 return -EINPROGRESS; /* Call commit handler */
6027 /*------------------------------------------------------------------*/
6029 * Wireless Handler : get Bit-Rate
6031 static int airo_get_rate(struct net_device *dev,
6032 struct iw_request_info *info,
6033 struct iw_param *vwrq,
6036 struct airo_info *local = dev->ml_priv;
6037 StatusRid status_rid; /* Card status info */
6039 readStatusRid(local, &status_rid, 1);
6041 vwrq->value = le16_to_cpu(status_rid.currentXmitRate) * 500000;
6042 /* If more than one rate, set auto */
6043 readConfigRid(local, 1);
6044 vwrq->fixed = (local->config.rates[1] == 0);
6049 /*------------------------------------------------------------------*/
6051 * Wireless Handler : set RTS threshold
6053 static int airo_set_rts(struct net_device *dev,
6054 struct iw_request_info *info,
6055 struct iw_param *vwrq,
6058 struct airo_info *local = dev->ml_priv;
6059 int rthr = vwrq->value;
6062 rthr = AIRO_DEF_MTU;
6063 if((rthr < 0) || (rthr > AIRO_DEF_MTU)) {
6066 readConfigRid(local, 1);
6067 local->config.rtsThres = cpu_to_le16(rthr);
6068 set_bit (FLAG_COMMIT, &local->flags);
6070 return -EINPROGRESS; /* Call commit handler */
6073 /*------------------------------------------------------------------*/
6075 * Wireless Handler : get RTS threshold
6077 static int airo_get_rts(struct net_device *dev,
6078 struct iw_request_info *info,
6079 struct iw_param *vwrq,
6082 struct airo_info *local = dev->ml_priv;
6084 readConfigRid(local, 1);
6085 vwrq->value = le16_to_cpu(local->config.rtsThres);
6086 vwrq->disabled = (vwrq->value >= AIRO_DEF_MTU);
6092 /*------------------------------------------------------------------*/
6094 * Wireless Handler : set Fragmentation threshold
6096 static int airo_set_frag(struct net_device *dev,
6097 struct iw_request_info *info,
6098 struct iw_param *vwrq,
6101 struct airo_info *local = dev->ml_priv;
6102 int fthr = vwrq->value;
6105 fthr = AIRO_DEF_MTU;
6106 if((fthr < 256) || (fthr > AIRO_DEF_MTU)) {
6109 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
6110 readConfigRid(local, 1);
6111 local->config.fragThresh = cpu_to_le16(fthr);
6112 set_bit (FLAG_COMMIT, &local->flags);
6114 return -EINPROGRESS; /* Call commit handler */
6117 /*------------------------------------------------------------------*/
6119 * Wireless Handler : get Fragmentation threshold
6121 static int airo_get_frag(struct net_device *dev,
6122 struct iw_request_info *info,
6123 struct iw_param *vwrq,
6126 struct airo_info *local = dev->ml_priv;
6128 readConfigRid(local, 1);
6129 vwrq->value = le16_to_cpu(local->config.fragThresh);
6130 vwrq->disabled = (vwrq->value >= AIRO_DEF_MTU);
6136 /*------------------------------------------------------------------*/
6138 * Wireless Handler : set Mode of Operation
6140 static int airo_set_mode(struct net_device *dev,
6141 struct iw_request_info *info,
6145 struct airo_info *local = dev->ml_priv;
6148 readConfigRid(local, 1);
6149 if (sniffing_mode(local))
6154 local->config.opmode &= ~MODE_CFG_MASK;
6155 local->config.opmode |= MODE_STA_IBSS;
6156 local->config.rmode &= ~RXMODE_FULL_MASK;
6157 local->config.scanMode = SCANMODE_ACTIVE;
6158 clear_bit (FLAG_802_11, &local->flags);
6161 local->config.opmode &= ~MODE_CFG_MASK;
6162 local->config.opmode |= MODE_STA_ESS;
6163 local->config.rmode &= ~RXMODE_FULL_MASK;
6164 local->config.scanMode = SCANMODE_ACTIVE;
6165 clear_bit (FLAG_802_11, &local->flags);
6167 case IW_MODE_MASTER:
6168 local->config.opmode &= ~MODE_CFG_MASK;
6169 local->config.opmode |= MODE_AP;
6170 local->config.rmode &= ~RXMODE_FULL_MASK;
6171 local->config.scanMode = SCANMODE_ACTIVE;
6172 clear_bit (FLAG_802_11, &local->flags);
6174 case IW_MODE_REPEAT:
6175 local->config.opmode &= ~MODE_CFG_MASK;
6176 local->config.opmode |= MODE_AP_RPTR;
6177 local->config.rmode &= ~RXMODE_FULL_MASK;
6178 local->config.scanMode = SCANMODE_ACTIVE;
6179 clear_bit (FLAG_802_11, &local->flags);
6181 case IW_MODE_MONITOR:
6182 local->config.opmode &= ~MODE_CFG_MASK;
6183 local->config.opmode |= MODE_STA_ESS;
6184 local->config.rmode &= ~RXMODE_FULL_MASK;
6185 local->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
6186 local->config.scanMode = SCANMODE_PASSIVE;
6187 set_bit (FLAG_802_11, &local->flags);
6193 set_bit (FLAG_RESET, &local->flags);
6194 set_bit (FLAG_COMMIT, &local->flags);
6196 return -EINPROGRESS; /* Call commit handler */
6199 /*------------------------------------------------------------------*/
6201 * Wireless Handler : get Mode of Operation
6203 static int airo_get_mode(struct net_device *dev,
6204 struct iw_request_info *info,
6208 struct airo_info *local = dev->ml_priv;
6210 readConfigRid(local, 1);
6211 /* If not managed, assume it's ad-hoc */
6212 switch (local->config.opmode & MODE_CFG_MASK) {
6214 *uwrq = IW_MODE_INFRA;
6217 *uwrq = IW_MODE_MASTER;
6220 *uwrq = IW_MODE_REPEAT;
6223 *uwrq = IW_MODE_ADHOC;
6229 static inline int valid_index(CapabilityRid *p, int index)
6233 return index < (p->softCap & cpu_to_le16(0x80) ? 4 : 1);
6236 /*------------------------------------------------------------------*/
6238 * Wireless Handler : set Encryption Key
6240 static int airo_set_encode(struct net_device *dev,
6241 struct iw_request_info *info,
6242 struct iw_point *dwrq,
6245 struct airo_info *local = dev->ml_priv;
6246 CapabilityRid cap_rid; /* Card capability info */
6247 int perm = ( dwrq->flags & IW_ENCODE_TEMP ? 0 : 1 );
6248 __le16 currentAuthType = local->config.authType;
6250 /* Is WEP supported ? */
6251 readCapabilityRid(local, &cap_rid, 1);
6252 /* Older firmware doesn't support this...
6253 if(!(cap_rid.softCap & cpu_to_le16(2))) {
6256 readConfigRid(local, 1);
6258 /* Basic checking: do we have a key to set ?
6259 * Note : with the new API, it's impossible to get a NULL pointer.
6260 * Therefore, we need to check a key size == 0 instead.
6261 * New version of iwconfig properly set the IW_ENCODE_NOKEY flag
6262 * when no key is present (only change flags), but older versions
6263 * don't do it. - Jean II */
6264 if (dwrq->length > 0) {
6266 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6267 int current_index = get_wep_key(local, 0xffff);
6268 /* Check the size of the key */
6269 if (dwrq->length > MAX_KEY_SIZE) {
6272 /* Check the index (none -> use current) */
6273 if (!valid_index(&cap_rid, index))
6274 index = current_index;
6275 /* Set the length */
6276 if (dwrq->length > MIN_KEY_SIZE)
6277 key.len = MAX_KEY_SIZE;
6279 if (dwrq->length > 0)
6280 key.len = MIN_KEY_SIZE;
6282 /* Disable the key */
6284 /* Check if the key is not marked as invalid */
6285 if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
6287 memset(key.key, 0, MAX_KEY_SIZE);
6288 /* Copy the key in the driver */
6289 memcpy(key.key, extra, dwrq->length);
6290 /* Send the key to the card */
6291 set_wep_key(local, index, key.key, key.len, perm, 1);
6293 /* WE specify that if a valid key is set, encryption
6294 * should be enabled (user may turn it off later)
6295 * This is also how "iwconfig ethX key on" works */
6296 if((index == current_index) && (key.len > 0) &&
6297 (local->config.authType == AUTH_OPEN)) {
6298 local->config.authType = AUTH_ENCRYPT;
6301 /* Do we want to just set the transmit key index ? */
6302 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6303 if (valid_index(&cap_rid, index)) {
6304 set_wep_key(local, index, NULL, 0, perm, 1);
6306 /* Don't complain if only change the mode */
6307 if (!(dwrq->flags & IW_ENCODE_MODE))
6310 /* Read the flags */
6311 if(dwrq->flags & IW_ENCODE_DISABLED)
6312 local->config.authType = AUTH_OPEN; // disable encryption
6313 if(dwrq->flags & IW_ENCODE_RESTRICTED)
6314 local->config.authType = AUTH_SHAREDKEY; // Only Both
6315 if(dwrq->flags & IW_ENCODE_OPEN)
6316 local->config.authType = AUTH_ENCRYPT; // Only Wep
6317 /* Commit the changes to flags if needed */
6318 if (local->config.authType != currentAuthType)
6319 set_bit (FLAG_COMMIT, &local->flags);
6320 return -EINPROGRESS; /* Call commit handler */
6323 /*------------------------------------------------------------------*/
6325 * Wireless Handler : get Encryption Key
6327 static int airo_get_encode(struct net_device *dev,
6328 struct iw_request_info *info,
6329 struct iw_point *dwrq,
6332 struct airo_info *local = dev->ml_priv;
6333 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6334 CapabilityRid cap_rid; /* Card capability info */
6336 /* Is it supported ? */
6337 readCapabilityRid(local, &cap_rid, 1);
6338 if(!(cap_rid.softCap & cpu_to_le16(2))) {
6341 readConfigRid(local, 1);
6342 /* Check encryption mode */
6343 switch(local->config.authType) {
6345 dwrq->flags = IW_ENCODE_OPEN;
6347 case AUTH_SHAREDKEY:
6348 dwrq->flags = IW_ENCODE_RESTRICTED;
6352 dwrq->flags = IW_ENCODE_DISABLED;
6355 /* We can't return the key, so set the proper flag and return zero */
6356 dwrq->flags |= IW_ENCODE_NOKEY;
6357 memset(extra, 0, 16);
6359 /* Which key do we want ? -1 -> tx index */
6360 if (!valid_index(&cap_rid, index))
6361 index = get_wep_key(local, 0xffff);
6362 dwrq->flags |= index + 1;
6363 /* Copy the key to the user buffer */
6364 dwrq->length = get_wep_key(local, index);
6365 if (dwrq->length > 16) {
6371 /*------------------------------------------------------------------*/
6373 * Wireless Handler : set extended Encryption parameters
6375 static int airo_set_encodeext(struct net_device *dev,
6376 struct iw_request_info *info,
6377 union iwreq_data *wrqu,
6380 struct airo_info *local = dev->ml_priv;
6381 struct iw_point *encoding = &wrqu->encoding;
6382 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6383 CapabilityRid cap_rid; /* Card capability info */
6384 int perm = ( encoding->flags & IW_ENCODE_TEMP ? 0 : 1 );
6385 __le16 currentAuthType = local->config.authType;
6386 int idx, key_len, alg = ext->alg, set_key = 1;
6389 /* Is WEP supported ? */
6390 readCapabilityRid(local, &cap_rid, 1);
6391 /* Older firmware doesn't support this...
6392 if(!(cap_rid.softCap & cpu_to_le16(2))) {
6395 readConfigRid(local, 1);
6397 /* Determine and validate the key index */
6398 idx = encoding->flags & IW_ENCODE_INDEX;
6400 if (!valid_index(&cap_rid, idx - 1))
6404 idx = get_wep_key(local, 0xffff);
6406 if (encoding->flags & IW_ENCODE_DISABLED)
6407 alg = IW_ENCODE_ALG_NONE;
6409 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
6410 /* Only set transmit key index here, actual
6411 * key is set below if needed.
6413 set_wep_key(local, idx, NULL, 0, perm, 1);
6414 set_key = ext->key_len > 0 ? 1 : 0;
6418 /* Set the requested key first */
6419 memset(key.key, 0, MAX_KEY_SIZE);
6421 case IW_ENCODE_ALG_NONE:
6424 case IW_ENCODE_ALG_WEP:
6425 if (ext->key_len > MIN_KEY_SIZE) {
6426 key.len = MAX_KEY_SIZE;
6427 } else if (ext->key_len > 0) {
6428 key.len = MIN_KEY_SIZE;
6432 key_len = min (ext->key_len, key.len);
6433 memcpy(key.key, ext->key, key_len);
6438 /* Send the key to the card */
6439 set_wep_key(local, idx, key.key, key.len, perm, 1);
6442 /* Read the flags */
6443 if(encoding->flags & IW_ENCODE_DISABLED)
6444 local->config.authType = AUTH_OPEN; // disable encryption
6445 if(encoding->flags & IW_ENCODE_RESTRICTED)
6446 local->config.authType = AUTH_SHAREDKEY; // Only Both
6447 if(encoding->flags & IW_ENCODE_OPEN)
6448 local->config.authType = AUTH_ENCRYPT; // Only Wep
6449 /* Commit the changes to flags if needed */
6450 if (local->config.authType != currentAuthType)
6451 set_bit (FLAG_COMMIT, &local->flags);
6453 return -EINPROGRESS;
6457 /*------------------------------------------------------------------*/
6459 * Wireless Handler : get extended Encryption parameters
6461 static int airo_get_encodeext(struct net_device *dev,
6462 struct iw_request_info *info,
6463 union iwreq_data *wrqu,
6466 struct airo_info *local = dev->ml_priv;
6467 struct iw_point *encoding = &wrqu->encoding;
6468 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6469 CapabilityRid cap_rid; /* Card capability info */
6470 int idx, max_key_len;
6472 /* Is it supported ? */
6473 readCapabilityRid(local, &cap_rid, 1);
6474 if(!(cap_rid.softCap & cpu_to_le16(2))) {
6477 readConfigRid(local, 1);
6479 max_key_len = encoding->length - sizeof(*ext);
6480 if (max_key_len < 0)
6483 idx = encoding->flags & IW_ENCODE_INDEX;
6485 if (!valid_index(&cap_rid, idx - 1))
6489 idx = get_wep_key(local, 0xffff);
6491 encoding->flags = idx + 1;
6492 memset(ext, 0, sizeof(*ext));
6494 /* Check encryption mode */
6495 switch(local->config.authType) {
6497 encoding->flags = IW_ENCODE_ALG_WEP | IW_ENCODE_ENABLED;
6499 case AUTH_SHAREDKEY:
6500 encoding->flags = IW_ENCODE_ALG_WEP | IW_ENCODE_ENABLED;
6504 encoding->flags = IW_ENCODE_ALG_NONE | IW_ENCODE_DISABLED;
6507 /* We can't return the key, so set the proper flag and return zero */
6508 encoding->flags |= IW_ENCODE_NOKEY;
6509 memset(extra, 0, 16);
6511 /* Copy the key to the user buffer */
6512 ext->key_len = get_wep_key(local, idx);
6513 if (ext->key_len > 16) {
6521 /*------------------------------------------------------------------*/
6523 * Wireless Handler : set extended authentication parameters
6525 static int airo_set_auth(struct net_device *dev,
6526 struct iw_request_info *info,
6527 union iwreq_data *wrqu, char *extra)
6529 struct airo_info *local = dev->ml_priv;
6530 struct iw_param *param = &wrqu->param;
6531 __le16 currentAuthType = local->config.authType;
6533 switch (param->flags & IW_AUTH_INDEX) {
6534 case IW_AUTH_WPA_VERSION:
6535 case IW_AUTH_CIPHER_PAIRWISE:
6536 case IW_AUTH_CIPHER_GROUP:
6537 case IW_AUTH_KEY_MGMT:
6538 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6539 case IW_AUTH_PRIVACY_INVOKED:
6541 * airo does not use these parameters
6545 case IW_AUTH_DROP_UNENCRYPTED:
6547 /* Only change auth type if unencrypted */
6548 if (currentAuthType == AUTH_OPEN)
6549 local->config.authType = AUTH_ENCRYPT;
6551 local->config.authType = AUTH_OPEN;
6554 /* Commit the changes to flags if needed */
6555 if (local->config.authType != currentAuthType)
6556 set_bit (FLAG_COMMIT, &local->flags);
6559 case IW_AUTH_80211_AUTH_ALG: {
6560 /* FIXME: What about AUTH_OPEN? This API seems to
6561 * disallow setting our auth to AUTH_OPEN.
6563 if (param->value & IW_AUTH_ALG_SHARED_KEY) {
6564 local->config.authType = AUTH_SHAREDKEY;
6565 } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) {
6566 local->config.authType = AUTH_ENCRYPT;
6571 /* Commit the changes to flags if needed */
6572 if (local->config.authType != currentAuthType)
6573 set_bit (FLAG_COMMIT, &local->flags);
6576 case IW_AUTH_WPA_ENABLED:
6577 /* Silently accept disable of WPA */
6578 if (param->value > 0)
6585 return -EINPROGRESS;
6589 /*------------------------------------------------------------------*/
6591 * Wireless Handler : get extended authentication parameters
6593 static int airo_get_auth(struct net_device *dev,
6594 struct iw_request_info *info,
6595 union iwreq_data *wrqu, char *extra)
6597 struct airo_info *local = dev->ml_priv;
6598 struct iw_param *param = &wrqu->param;
6599 __le16 currentAuthType = local->config.authType;
6601 switch (param->flags & IW_AUTH_INDEX) {
6602 case IW_AUTH_DROP_UNENCRYPTED:
6603 switch (currentAuthType) {
6604 case AUTH_SHAREDKEY:
6614 case IW_AUTH_80211_AUTH_ALG:
6615 switch (currentAuthType) {
6616 case AUTH_SHAREDKEY:
6617 param->value = IW_AUTH_ALG_SHARED_KEY;
6621 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
6626 case IW_AUTH_WPA_ENABLED:
6637 /*------------------------------------------------------------------*/
6639 * Wireless Handler : set Tx-Power
6641 static int airo_set_txpow(struct net_device *dev,
6642 struct iw_request_info *info,
6643 struct iw_param *vwrq,
6646 struct airo_info *local = dev->ml_priv;
6647 CapabilityRid cap_rid; /* Card capability info */
6650 __le16 v = cpu_to_le16(vwrq->value);
6652 readCapabilityRid(local, &cap_rid, 1);
6654 if (vwrq->disabled) {
6655 set_bit (FLAG_RADIO_OFF, &local->flags);
6656 set_bit (FLAG_COMMIT, &local->flags);
6657 return -EINPROGRESS; /* Call commit handler */
6659 if (vwrq->flags != IW_TXPOW_MWATT) {
6662 clear_bit (FLAG_RADIO_OFF, &local->flags);
6663 for (i = 0; cap_rid.txPowerLevels[i] && (i < 8); i++)
6664 if (v == cap_rid.txPowerLevels[i]) {
6665 readConfigRid(local, 1);
6666 local->config.txPower = v;
6667 set_bit (FLAG_COMMIT, &local->flags);
6668 rc = -EINPROGRESS; /* Call commit handler */
6674 /*------------------------------------------------------------------*/
6676 * Wireless Handler : get Tx-Power
6678 static int airo_get_txpow(struct net_device *dev,
6679 struct iw_request_info *info,
6680 struct iw_param *vwrq,
6683 struct airo_info *local = dev->ml_priv;
6685 readConfigRid(local, 1);
6686 vwrq->value = le16_to_cpu(local->config.txPower);
6687 vwrq->fixed = 1; /* No power control */
6688 vwrq->disabled = test_bit(FLAG_RADIO_OFF, &local->flags);
6689 vwrq->flags = IW_TXPOW_MWATT;
6694 /*------------------------------------------------------------------*/
6696 * Wireless Handler : set Retry limits
6698 static int airo_set_retry(struct net_device *dev,
6699 struct iw_request_info *info,
6700 struct iw_param *vwrq,
6703 struct airo_info *local = dev->ml_priv;
6706 if(vwrq->disabled) {
6709 readConfigRid(local, 1);
6710 if(vwrq->flags & IW_RETRY_LIMIT) {
6711 __le16 v = cpu_to_le16(vwrq->value);
6712 if(vwrq->flags & IW_RETRY_LONG)
6713 local->config.longRetryLimit = v;
6714 else if (vwrq->flags & IW_RETRY_SHORT)
6715 local->config.shortRetryLimit = v;
6717 /* No modifier : set both */
6718 local->config.longRetryLimit = v;
6719 local->config.shortRetryLimit = v;
6721 set_bit (FLAG_COMMIT, &local->flags);
6722 rc = -EINPROGRESS; /* Call commit handler */
6724 if(vwrq->flags & IW_RETRY_LIFETIME) {
6725 local->config.txLifetime = cpu_to_le16(vwrq->value / 1024);
6726 set_bit (FLAG_COMMIT, &local->flags);
6727 rc = -EINPROGRESS; /* Call commit handler */
6732 /*------------------------------------------------------------------*/
6734 * Wireless Handler : get Retry limits
6736 static int airo_get_retry(struct net_device *dev,
6737 struct iw_request_info *info,
6738 struct iw_param *vwrq,
6741 struct airo_info *local = dev->ml_priv;
6743 vwrq->disabled = 0; /* Can't be disabled */
6745 readConfigRid(local, 1);
6746 /* Note : by default, display the min retry number */
6747 if((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
6748 vwrq->flags = IW_RETRY_LIFETIME;
6749 vwrq->value = le16_to_cpu(local->config.txLifetime) * 1024;
6750 } else if((vwrq->flags & IW_RETRY_LONG)) {
6751 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
6752 vwrq->value = le16_to_cpu(local->config.longRetryLimit);
6754 vwrq->flags = IW_RETRY_LIMIT;
6755 vwrq->value = le16_to_cpu(local->config.shortRetryLimit);
6756 if(local->config.shortRetryLimit != local->config.longRetryLimit)
6757 vwrq->flags |= IW_RETRY_SHORT;
6763 /*------------------------------------------------------------------*/
6765 * Wireless Handler : get range info
6767 static int airo_get_range(struct net_device *dev,
6768 struct iw_request_info *info,
6769 struct iw_point *dwrq,
6772 struct airo_info *local = dev->ml_priv;
6773 struct iw_range *range = (struct iw_range *) extra;
6774 CapabilityRid cap_rid; /* Card capability info */
6778 readCapabilityRid(local, &cap_rid, 1);
6780 dwrq->length = sizeof(struct iw_range);
6781 memset(range, 0, sizeof(*range));
6782 range->min_nwid = 0x0000;
6783 range->max_nwid = 0x0000;
6784 range->num_channels = 14;
6785 /* Should be based on cap_rid.country to give only
6786 * what the current card support */
6788 for(i = 0; i < 14; i++) {
6789 range->freq[k].i = i + 1; /* List index */
6790 range->freq[k].m = ieee80211_dsss_chan_to_freq(i + 1) * 100000;
6791 range->freq[k++].e = 1; /* Values in MHz -> * 10^5 * 10 */
6793 range->num_frequency = k;
6795 range->sensitivity = 65535;
6797 /* Hum... Should put the right values there */
6799 range->max_qual.qual = 100; /* % */
6801 range->max_qual.qual = airo_get_max_quality(&cap_rid);
6802 range->max_qual.level = 0x100 - 120; /* -120 dBm */
6803 range->max_qual.noise = 0x100 - 120; /* -120 dBm */
6805 /* Experimental measurements - boundary 11/5.5 Mb/s */
6806 /* Note : with or without the (local->rssi), results
6807 * are somewhat different. - Jean II */
6809 range->avg_qual.qual = 50; /* % */
6810 range->avg_qual.level = 0x100 - 70; /* -70 dBm */
6812 range->avg_qual.qual = airo_get_avg_quality(&cap_rid);
6813 range->avg_qual.level = 0x100 - 80; /* -80 dBm */
6815 range->avg_qual.noise = 0x100 - 85; /* -85 dBm */
6817 for(i = 0 ; i < 8 ; i++) {
6818 range->bitrate[i] = cap_rid.supportedRates[i] * 500000;
6819 if(range->bitrate[i] == 0)
6822 range->num_bitrates = i;
6824 /* Set an indication of the max TCP throughput
6825 * in bit/s that we can expect using this interface.
6826 * May be use for QoS stuff... Jean II */
6828 range->throughput = 5000 * 1000;
6830 range->throughput = 1500 * 1000;
6833 range->max_rts = AIRO_DEF_MTU;
6834 range->min_frag = 256;
6835 range->max_frag = AIRO_DEF_MTU;
6837 if(cap_rid.softCap & cpu_to_le16(2)) {
6839 range->encoding_size[0] = 5;
6841 if (cap_rid.softCap & cpu_to_le16(0x100)) {
6842 range->encoding_size[1] = 13;
6843 range->num_encoding_sizes = 2;
6845 range->num_encoding_sizes = 1;
6846 range->max_encoding_tokens =
6847 cap_rid.softCap & cpu_to_le16(0x80) ? 4 : 1;
6849 range->num_encoding_sizes = 0;
6850 range->max_encoding_tokens = 0;
6853 range->max_pmp = 5000000; /* 5 secs */
6855 range->max_pmt = 65535 * 1024; /* ??? */
6856 range->pmp_flags = IW_POWER_PERIOD;
6857 range->pmt_flags = IW_POWER_TIMEOUT;
6858 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
6860 /* Transmit Power - values are in mW */
6861 for(i = 0 ; i < 8 ; i++) {
6862 range->txpower[i] = le16_to_cpu(cap_rid.txPowerLevels[i]);
6863 if(range->txpower[i] == 0)
6866 range->num_txpower = i;
6867 range->txpower_capa = IW_TXPOW_MWATT;
6868 range->we_version_source = 19;
6869 range->we_version_compiled = WIRELESS_EXT;
6870 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
6871 range->retry_flags = IW_RETRY_LIMIT;
6872 range->r_time_flags = IW_RETRY_LIFETIME;
6873 range->min_retry = 1;
6874 range->max_retry = 65535;
6875 range->min_r_time = 1024;
6876 range->max_r_time = 65535 * 1024;
6878 /* Event capability (kernel + driver) */
6879 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
6880 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
6881 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
6882 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
6883 range->event_capa[1] = IW_EVENT_CAPA_K_1;
6884 range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVTXDROP);
6888 /*------------------------------------------------------------------*/
6890 * Wireless Handler : set Power Management
6892 static int airo_set_power(struct net_device *dev,
6893 struct iw_request_info *info,
6894 struct iw_param *vwrq,
6897 struct airo_info *local = dev->ml_priv;
6899 readConfigRid(local, 1);
6900 if (vwrq->disabled) {
6901 if (sniffing_mode(local))
6903 local->config.powerSaveMode = POWERSAVE_CAM;
6904 local->config.rmode &= ~RXMODE_MASK;
6905 local->config.rmode |= RXMODE_BC_MC_ADDR;
6906 set_bit (FLAG_COMMIT, &local->flags);
6907 return -EINPROGRESS; /* Call commit handler */
6909 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
6910 local->config.fastListenDelay = cpu_to_le16((vwrq->value + 500) / 1024);
6911 local->config.powerSaveMode = POWERSAVE_PSPCAM;
6912 set_bit (FLAG_COMMIT, &local->flags);
6913 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
6914 local->config.fastListenInterval =
6915 local->config.listenInterval =
6916 cpu_to_le16((vwrq->value + 500) / 1024);
6917 local->config.powerSaveMode = POWERSAVE_PSPCAM;
6918 set_bit (FLAG_COMMIT, &local->flags);
6920 switch (vwrq->flags & IW_POWER_MODE) {
6921 case IW_POWER_UNICAST_R:
6922 if (sniffing_mode(local))
6924 local->config.rmode &= ~RXMODE_MASK;
6925 local->config.rmode |= RXMODE_ADDR;
6926 set_bit (FLAG_COMMIT, &local->flags);
6928 case IW_POWER_ALL_R:
6929 if (sniffing_mode(local))
6931 local->config.rmode &= ~RXMODE_MASK;
6932 local->config.rmode |= RXMODE_BC_MC_ADDR;
6933 set_bit (FLAG_COMMIT, &local->flags);
6935 /* This is broken, fixme ;-) */
6940 // Note : we may want to factor local->need_commit here
6941 // Note2 : may also want to factor RXMODE_RFMON test
6942 return -EINPROGRESS; /* Call commit handler */
6945 /*------------------------------------------------------------------*/
6947 * Wireless Handler : get Power Management
6949 static int airo_get_power(struct net_device *dev,
6950 struct iw_request_info *info,
6951 struct iw_param *vwrq,
6954 struct airo_info *local = dev->ml_priv;
6957 readConfigRid(local, 1);
6958 mode = local->config.powerSaveMode;
6959 if ((vwrq->disabled = (mode == POWERSAVE_CAM)))
6961 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
6962 vwrq->value = le16_to_cpu(local->config.fastListenDelay) * 1024;
6963 vwrq->flags = IW_POWER_TIMEOUT;
6965 vwrq->value = le16_to_cpu(local->config.fastListenInterval) * 1024;
6966 vwrq->flags = IW_POWER_PERIOD;
6968 if ((local->config.rmode & RXMODE_MASK) == RXMODE_ADDR)
6969 vwrq->flags |= IW_POWER_UNICAST_R;
6971 vwrq->flags |= IW_POWER_ALL_R;
6976 /*------------------------------------------------------------------*/
6978 * Wireless Handler : set Sensitivity
6980 static int airo_set_sens(struct net_device *dev,
6981 struct iw_request_info *info,
6982 struct iw_param *vwrq,
6985 struct airo_info *local = dev->ml_priv;
6987 readConfigRid(local, 1);
6988 local->config.rssiThreshold =
6989 cpu_to_le16(vwrq->disabled ? RSSI_DEFAULT : vwrq->value);
6990 set_bit (FLAG_COMMIT, &local->flags);
6992 return -EINPROGRESS; /* Call commit handler */
6995 /*------------------------------------------------------------------*/
6997 * Wireless Handler : get Sensitivity
6999 static int airo_get_sens(struct net_device *dev,
7000 struct iw_request_info *info,
7001 struct iw_param *vwrq,
7004 struct airo_info *local = dev->ml_priv;
7006 readConfigRid(local, 1);
7007 vwrq->value = le16_to_cpu(local->config.rssiThreshold);
7008 vwrq->disabled = (vwrq->value == 0);
7014 /*------------------------------------------------------------------*/
7016 * Wireless Handler : get AP List
7017 * Note : this is deprecated in favor of IWSCAN
7019 static int airo_get_aplist(struct net_device *dev,
7020 struct iw_request_info *info,
7021 struct iw_point *dwrq,
7024 struct airo_info *local = dev->ml_priv;
7025 struct sockaddr *address = (struct sockaddr *) extra;
7026 struct iw_quality qual[IW_MAX_AP];
7029 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
7031 for (i = 0; i < IW_MAX_AP; i++) {
7033 if (readBSSListRid(local, loseSync, &BSSList))
7036 memcpy(address[i].sa_data, BSSList.bssid, ETH_ALEN);
7037 address[i].sa_family = ARPHRD_ETHER;
7038 dBm = le16_to_cpu(BSSList.dBm);
7040 qual[i].level = 0x100 - dBm;
7041 qual[i].qual = airo_dbm_to_pct(local->rssi, dBm);
7042 qual[i].updated = IW_QUAL_QUAL_UPDATED
7043 | IW_QUAL_LEVEL_UPDATED
7046 qual[i].level = (dBm + 321) / 2;
7048 qual[i].updated = IW_QUAL_QUAL_INVALID
7049 | IW_QUAL_LEVEL_UPDATED
7052 qual[i].noise = local->wstats.qual.noise;
7053 if (BSSList.index == cpu_to_le16(0xffff))
7057 StatusRid status_rid; /* Card status info */
7058 readStatusRid(local, &status_rid, 1);
7060 i < min(IW_MAX_AP, 4) &&
7061 (status_rid.bssid[i][0]
7062 & status_rid.bssid[i][1]
7063 & status_rid.bssid[i][2]
7064 & status_rid.bssid[i][3]
7065 & status_rid.bssid[i][4]
7066 & status_rid.bssid[i][5])!=0xff &&
7067 (status_rid.bssid[i][0]
7068 | status_rid.bssid[i][1]
7069 | status_rid.bssid[i][2]
7070 | status_rid.bssid[i][3]
7071 | status_rid.bssid[i][4]
7072 | status_rid.bssid[i][5]);
7074 memcpy(address[i].sa_data,
7075 status_rid.bssid[i], ETH_ALEN);
7076 address[i].sa_family = ARPHRD_ETHER;
7079 dwrq->flags = 1; /* Should be define'd */
7080 memcpy(extra + sizeof(struct sockaddr)*i,
7081 &qual, sizeof(struct iw_quality)*i);
7088 /*------------------------------------------------------------------*/
7090 * Wireless Handler : Initiate Scan
7092 static int airo_set_scan(struct net_device *dev,
7093 struct iw_request_info *info,
7094 struct iw_point *dwrq,
7097 struct airo_info *ai = dev->ml_priv;
7102 /* Note : you may have realised that, as this is a SET operation,
7103 * this is privileged and therefore a normal user can't
7105 * This is not an error, while the device perform scanning,
7106 * traffic doesn't flow, so it's a perfect DoS...
7108 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
7110 if (down_interruptible(&ai->sem))
7111 return -ERESTARTSYS;
7113 /* If there's already a scan in progress, don't
7114 * trigger another one. */
7115 if (ai->scan_timeout > 0)
7118 /* Initiate a scan command */
7119 ai->scan_timeout = RUN_AT(3*HZ);
7120 memset(&cmd, 0, sizeof(cmd));
7121 cmd.cmd=CMD_LISTBSS;
7122 issuecommand(ai, &cmd, &rsp);
7128 wake_up_interruptible(&ai->thr_wait);
7132 /*------------------------------------------------------------------*/
7134 * Translate scan data returned from the card to a card independent
7135 * format that the Wireless Tools will understand - Jean II
7137 static inline char *airo_translate_scan(struct net_device *dev,
7138 struct iw_request_info *info,
7143 struct airo_info *ai = dev->ml_priv;
7144 struct iw_event iwe; /* Temporary buffer */
7145 __le16 capabilities;
7146 char * current_val; /* For rates */
7151 /* First entry *MUST* be the AP MAC address */
7152 iwe.cmd = SIOCGIWAP;
7153 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
7154 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
7155 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7156 &iwe, IW_EV_ADDR_LEN);
7158 /* Other entries will be displayed in the order we give them */
7161 iwe.u.data.length = bss->ssidLen;
7162 if(iwe.u.data.length > 32)
7163 iwe.u.data.length = 32;
7164 iwe.cmd = SIOCGIWESSID;
7165 iwe.u.data.flags = 1;
7166 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
7170 iwe.cmd = SIOCGIWMODE;
7171 capabilities = bss->cap;
7172 if(capabilities & (CAP_ESS | CAP_IBSS)) {
7173 if(capabilities & CAP_ESS)
7174 iwe.u.mode = IW_MODE_MASTER;
7176 iwe.u.mode = IW_MODE_ADHOC;
7177 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7178 &iwe, IW_EV_UINT_LEN);
7182 iwe.cmd = SIOCGIWFREQ;
7183 iwe.u.freq.m = le16_to_cpu(bss->dsChannel);
7184 iwe.u.freq.m = ieee80211_dsss_chan_to_freq(iwe.u.freq.m) * 100000;
7186 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7187 &iwe, IW_EV_FREQ_LEN);
7189 dBm = le16_to_cpu(bss->dBm);
7191 /* Add quality statistics */
7194 iwe.u.qual.level = 0x100 - dBm;
7195 iwe.u.qual.qual = airo_dbm_to_pct(ai->rssi, dBm);
7196 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED
7197 | IW_QUAL_LEVEL_UPDATED
7200 iwe.u.qual.level = (dBm + 321) / 2;
7201 iwe.u.qual.qual = 0;
7202 iwe.u.qual.updated = IW_QUAL_QUAL_INVALID
7203 | IW_QUAL_LEVEL_UPDATED
7206 iwe.u.qual.noise = ai->wstats.qual.noise;
7207 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7208 &iwe, IW_EV_QUAL_LEN);
7210 /* Add encryption capability */
7211 iwe.cmd = SIOCGIWENCODE;
7212 if(capabilities & CAP_PRIVACY)
7213 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
7215 iwe.u.data.flags = IW_ENCODE_DISABLED;
7216 iwe.u.data.length = 0;
7217 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
7220 /* Rate : stuffing multiple values in a single event require a bit
7221 * more of magic - Jean II */
7222 current_val = current_ev + iwe_stream_lcp_len(info);
7224 iwe.cmd = SIOCGIWRATE;
7225 /* Those two flags are ignored... */
7226 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
7228 for(i = 0 ; i < 8 ; i++) {
7229 /* NULL terminated */
7230 if(bss->rates[i] == 0)
7232 /* Bit rate given in 500 kb/s units (+ 0x80) */
7233 iwe.u.bitrate.value = ((bss->rates[i] & 0x7f) * 500000);
7234 /* Add new value to event */
7235 current_val = iwe_stream_add_value(info, current_ev,
7236 current_val, end_buf,
7237 &iwe, IW_EV_PARAM_LEN);
7239 /* Check if we added any event */
7240 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
7241 current_ev = current_val;
7243 /* Beacon interval */
7244 buf = kmalloc(30, GFP_KERNEL);
7246 iwe.cmd = IWEVCUSTOM;
7247 sprintf(buf, "bcn_int=%d", bss->beaconInterval);
7248 iwe.u.data.length = strlen(buf);
7249 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
7254 /* Put WPA/RSN Information Elements into the event stream */
7255 if (test_bit(FLAG_WPA_CAPABLE, &ai->flags)) {
7256 unsigned int num_null_ies = 0;
7257 u16 length = sizeof (bss->extra.iep);
7258 u8 *ie = (void *)&bss->extra.iep;
7260 while ((length >= 2) && (num_null_ies < 2)) {
7261 if (2 + ie[1] > length) {
7262 /* Invalid element, don't continue parsing IE */
7268 /* Two zero-length SSID elements
7269 * mean we're done parsing elements */
7274 case WLAN_EID_GENERIC:
7280 iwe.cmd = IWEVGENIE;
7281 /* 64 is an arbitrary cut-off */
7282 iwe.u.data.length = min(ie[1] + 2,
7284 current_ev = iwe_stream_add_point(
7291 iwe.cmd = IWEVGENIE;
7292 /* 64 is an arbitrary cut-off */
7293 iwe.u.data.length = min(ie[1] + 2, 64);
7294 current_ev = iwe_stream_add_point(
7295 info, current_ev, end_buf,
7303 length -= 2 + ie[1];
7310 /*------------------------------------------------------------------*/
7312 * Wireless Handler : Read Scan Results
7314 static int airo_get_scan(struct net_device *dev,
7315 struct iw_request_info *info,
7316 struct iw_point *dwrq,
7319 struct airo_info *ai = dev->ml_priv;
7320 BSSListElement *net;
7322 char *current_ev = extra;
7324 /* If a scan is in-progress, return -EAGAIN */
7325 if (ai->scan_timeout > 0)
7328 if (down_interruptible(&ai->sem))
7331 list_for_each_entry (net, &ai->network_list, list) {
7332 /* Translate to WE format this entry */
7333 current_ev = airo_translate_scan(dev, info, current_ev,
7334 extra + dwrq->length,
7337 /* Check if there is space for one more entry */
7338 if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) {
7339 /* Ask user space to try again with a bigger buffer */
7345 /* Length of data */
7346 dwrq->length = (current_ev - extra);
7347 dwrq->flags = 0; /* todo */
7354 /*------------------------------------------------------------------*/
7356 * Commit handler : called after a bunch of SET operations
7358 static int airo_config_commit(struct net_device *dev,
7359 struct iw_request_info *info, /* NULL */
7360 void *zwrq, /* NULL */
7361 char *extra) /* NULL */
7363 struct airo_info *local = dev->ml_priv;
7365 if (!test_bit (FLAG_COMMIT, &local->flags))
7368 /* Some of the "SET" function may have modified some of the
7369 * parameters. It's now time to commit them in the card */
7370 disable_MAC(local, 1);
7371 if (test_bit (FLAG_RESET, &local->flags)) {
7372 APListRid APList_rid;
7375 readAPListRid(local, &APList_rid);
7376 readSsidRid(local, &SSID_rid);
7377 if (test_bit(FLAG_MPI,&local->flags))
7378 setup_card(local, dev->dev_addr, 1 );
7380 reset_airo_card(dev);
7381 disable_MAC(local, 1);
7382 writeSsidRid(local, &SSID_rid, 1);
7383 writeAPListRid(local, &APList_rid, 1);
7385 if (down_interruptible(&local->sem))
7386 return -ERESTARTSYS;
7387 writeConfigRid(local, 0);
7388 enable_MAC(local, 0);
7389 if (test_bit (FLAG_RESET, &local->flags))
7390 airo_set_promisc(local);
7397 /*------------------------------------------------------------------*/
7399 * Structures to export the Wireless Handlers
7402 static const struct iw_priv_args airo_private_args[] = {
7403 /*{ cmd, set_args, get_args, name } */
7404 { AIROIOCTL, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
7405 IW_PRIV_TYPE_BYTE | 2047, "airoioctl" },
7406 { AIROIDIFC, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
7407 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "airoidifc" },
7410 static const iw_handler airo_handler[] =
7412 (iw_handler) airo_config_commit, /* SIOCSIWCOMMIT */
7413 (iw_handler) airo_get_name, /* SIOCGIWNAME */
7414 (iw_handler) NULL, /* SIOCSIWNWID */
7415 (iw_handler) NULL, /* SIOCGIWNWID */
7416 (iw_handler) airo_set_freq, /* SIOCSIWFREQ */
7417 (iw_handler) airo_get_freq, /* SIOCGIWFREQ */
7418 (iw_handler) airo_set_mode, /* SIOCSIWMODE */
7419 (iw_handler) airo_get_mode, /* SIOCGIWMODE */
7420 (iw_handler) airo_set_sens, /* SIOCSIWSENS */
7421 (iw_handler) airo_get_sens, /* SIOCGIWSENS */
7422 (iw_handler) NULL, /* SIOCSIWRANGE */
7423 (iw_handler) airo_get_range, /* SIOCGIWRANGE */
7424 (iw_handler) NULL, /* SIOCSIWPRIV */
7425 (iw_handler) NULL, /* SIOCGIWPRIV */
7426 (iw_handler) NULL, /* SIOCSIWSTATS */
7427 (iw_handler) NULL, /* SIOCGIWSTATS */
7428 iw_handler_set_spy, /* SIOCSIWSPY */
7429 iw_handler_get_spy, /* SIOCGIWSPY */
7430 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
7431 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
7432 (iw_handler) airo_set_wap, /* SIOCSIWAP */
7433 (iw_handler) airo_get_wap, /* SIOCGIWAP */
7434 (iw_handler) NULL, /* -- hole -- */
7435 (iw_handler) airo_get_aplist, /* SIOCGIWAPLIST */
7436 (iw_handler) airo_set_scan, /* SIOCSIWSCAN */
7437 (iw_handler) airo_get_scan, /* SIOCGIWSCAN */
7438 (iw_handler) airo_set_essid, /* SIOCSIWESSID */
7439 (iw_handler) airo_get_essid, /* SIOCGIWESSID */
7440 (iw_handler) airo_set_nick, /* SIOCSIWNICKN */
7441 (iw_handler) airo_get_nick, /* SIOCGIWNICKN */
7442 (iw_handler) NULL, /* -- hole -- */
7443 (iw_handler) NULL, /* -- hole -- */
7444 (iw_handler) airo_set_rate, /* SIOCSIWRATE */
7445 (iw_handler) airo_get_rate, /* SIOCGIWRATE */
7446 (iw_handler) airo_set_rts, /* SIOCSIWRTS */
7447 (iw_handler) airo_get_rts, /* SIOCGIWRTS */
7448 (iw_handler) airo_set_frag, /* SIOCSIWFRAG */
7449 (iw_handler) airo_get_frag, /* SIOCGIWFRAG */
7450 (iw_handler) airo_set_txpow, /* SIOCSIWTXPOW */
7451 (iw_handler) airo_get_txpow, /* SIOCGIWTXPOW */
7452 (iw_handler) airo_set_retry, /* SIOCSIWRETRY */
7453 (iw_handler) airo_get_retry, /* SIOCGIWRETRY */
7454 (iw_handler) airo_set_encode, /* SIOCSIWENCODE */
7455 (iw_handler) airo_get_encode, /* SIOCGIWENCODE */
7456 (iw_handler) airo_set_power, /* SIOCSIWPOWER */
7457 (iw_handler) airo_get_power, /* SIOCGIWPOWER */
7458 (iw_handler) NULL, /* -- hole -- */
7459 (iw_handler) NULL, /* -- hole -- */
7460 (iw_handler) NULL, /* SIOCSIWGENIE */
7461 (iw_handler) NULL, /* SIOCGIWGENIE */
7462 (iw_handler) airo_set_auth, /* SIOCSIWAUTH */
7463 (iw_handler) airo_get_auth, /* SIOCGIWAUTH */
7464 (iw_handler) airo_set_encodeext, /* SIOCSIWENCODEEXT */
7465 (iw_handler) airo_get_encodeext, /* SIOCGIWENCODEEXT */
7466 (iw_handler) NULL, /* SIOCSIWPMKSA */
7469 /* Note : don't describe AIROIDIFC and AIROOLDIDIFC in here.
7470 * We want to force the use of the ioctl code, because those can't be
7471 * won't work the iw_handler code (because they simultaneously read
7472 * and write data and iw_handler can't do that).
7473 * Note that it's perfectly legal to read/write on a single ioctl command,
7474 * you just can't use iwpriv and need to force it via the ioctl handler.
7476 static const iw_handler airo_private_handler[] =
7478 NULL, /* SIOCIWFIRSTPRIV */
7481 static const struct iw_handler_def airo_handler_def =
7483 .num_standard = ARRAY_SIZE(airo_handler),
7484 .num_private = ARRAY_SIZE(airo_private_handler),
7485 .num_private_args = ARRAY_SIZE(airo_private_args),
7486 .standard = airo_handler,
7487 .private = airo_private_handler,
7488 .private_args = airo_private_args,
7489 .get_wireless_stats = airo_get_wireless_stats,
7493 * This defines the configuration part of the Wireless Extensions
7494 * Note : irq and spinlock protection will occur in the subroutines
7497 * o Check input value more carefully and fill correct values in range
7498 * o Test and shakeout the bugs (if any)
7502 * Javier Achirica did a great job of merging code from the unnamed CISCO
7503 * developer that added support for flashing the card.
7505 static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
7508 struct airo_info *ai = dev->ml_priv;
7510 if (ai->power.event)
7520 int val = AIROMAGIC;
7522 if (copy_from_user(&com,rq->ifr_data,sizeof(com)))
7524 else if (copy_to_user(com.data,(char *)&val,sizeof(val)))
7533 /* Get the command struct and hand it off for evaluation by
7534 * the proper subfunction
7538 if (copy_from_user(&com,rq->ifr_data,sizeof(com))) {
7543 /* Separate R/W functions bracket legality here
7545 if ( com.command == AIRORSWVERSION ) {
7546 if (copy_to_user(com.data, swversion, sizeof(swversion)))
7551 else if ( com.command <= AIRORRID)
7552 rc = readrids(dev,&com);
7553 else if ( com.command >= AIROPCAP && com.command <= (AIROPLEAPUSR+2) )
7554 rc = writerids(dev,&com);
7555 else if ( com.command >= AIROFLSHRST && com.command <= AIRORESTART )
7556 rc = flashcard(dev,&com);
7558 rc = -EINVAL; /* Bad command in ioctl */
7561 #endif /* CISCO_EXT */
7563 // All other calls are currently unsupported
7571 * Get the Wireless stats out of the driver
7572 * Note : irq and spinlock protection will occur in the subroutines
7575 * o Check if work in Ad-Hoc mode (otherwise, use SPY, as in wvlan_cs)
7579 static void airo_read_wireless_stats(struct airo_info *local)
7581 StatusRid status_rid;
7583 CapabilityRid cap_rid;
7584 __le32 *vals = stats_rid.vals;
7586 /* Get stats out of the card */
7587 clear_bit(JOB_WSTATS, &local->jobs);
7588 if (local->power.event) {
7592 readCapabilityRid(local, &cap_rid, 0);
7593 readStatusRid(local, &status_rid, 0);
7594 readStatsRid(local, &stats_rid, RID_STATS, 0);
7598 local->wstats.status = le16_to_cpu(status_rid.mode);
7600 /* Signal quality and co */
7602 local->wstats.qual.level =
7603 airo_rssi_to_dbm(local->rssi,
7604 le16_to_cpu(status_rid.sigQuality));
7605 /* normalizedSignalStrength appears to be a percentage */
7606 local->wstats.qual.qual =
7607 le16_to_cpu(status_rid.normalizedSignalStrength);
7609 local->wstats.qual.level =
7610 (le16_to_cpu(status_rid.normalizedSignalStrength) + 321) / 2;
7611 local->wstats.qual.qual = airo_get_quality(&status_rid, &cap_rid);
7613 if (le16_to_cpu(status_rid.len) >= 124) {
7614 local->wstats.qual.noise = 0x100 - status_rid.noisedBm;
7615 local->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
7617 local->wstats.qual.noise = 0;
7618 local->wstats.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_INVALID | IW_QUAL_DBM;
7621 /* Packets discarded in the wireless adapter due to wireless
7622 * specific problems */
7623 local->wstats.discard.nwid = le32_to_cpu(vals[56]) +
7624 le32_to_cpu(vals[57]) +
7625 le32_to_cpu(vals[58]); /* SSID Mismatch */
7626 local->wstats.discard.code = le32_to_cpu(vals[6]);/* RxWepErr */
7627 local->wstats.discard.fragment = le32_to_cpu(vals[30]);
7628 local->wstats.discard.retries = le32_to_cpu(vals[10]);
7629 local->wstats.discard.misc = le32_to_cpu(vals[1]) +
7630 le32_to_cpu(vals[32]);
7631 local->wstats.miss.beacon = le32_to_cpu(vals[34]);
7634 static struct iw_statistics *airo_get_wireless_stats(struct net_device *dev)
7636 struct airo_info *local = dev->ml_priv;
7638 if (!test_bit(JOB_WSTATS, &local->jobs)) {
7639 /* Get stats out of the card if available */
7640 if (down_trylock(&local->sem) != 0) {
7641 set_bit(JOB_WSTATS, &local->jobs);
7642 wake_up_interruptible(&local->thr_wait);
7644 airo_read_wireless_stats(local);
7647 return &local->wstats;
7652 * This just translates from driver IOCTL codes to the command codes to
7653 * feed to the radio's host interface. Things can be added/deleted
7654 * as needed. This represents the READ side of control I/O to
7657 static int readrids(struct net_device *dev, aironet_ioctl *comp) {
7658 unsigned short ridcode;
7659 unsigned char *iobuf;
7661 struct airo_info *ai = dev->ml_priv;
7663 if (test_bit(FLAG_FLASHING, &ai->flags))
7666 switch(comp->command)
7668 case AIROGCAP: ridcode = RID_CAPABILITIES; break;
7669 case AIROGCFG: ridcode = RID_CONFIG;
7670 if (test_bit(FLAG_COMMIT, &ai->flags)) {
7671 disable_MAC (ai, 1);
7672 writeConfigRid (ai, 1);
7676 case AIROGSLIST: ridcode = RID_SSID; break;
7677 case AIROGVLIST: ridcode = RID_APLIST; break;
7678 case AIROGDRVNAM: ridcode = RID_DRVNAME; break;
7679 case AIROGEHTENC: ridcode = RID_ETHERENCAP; break;
7680 case AIROGWEPKTMP: ridcode = RID_WEP_TEMP;
7681 /* Only super-user can read WEP keys */
7682 if (!capable(CAP_NET_ADMIN))
7685 case AIROGWEPKNV: ridcode = RID_WEP_PERM;
7686 /* Only super-user can read WEP keys */
7687 if (!capable(CAP_NET_ADMIN))
7690 case AIROGSTAT: ridcode = RID_STATUS; break;
7691 case AIROGSTATSD32: ridcode = RID_STATSDELTA; break;
7692 case AIROGSTATSC32: ridcode = RID_STATS; break;
7694 if (copy_to_user(comp->data, &ai->micstats,
7695 min((int)comp->len,(int)sizeof(ai->micstats))))
7698 case AIRORRID: ridcode = comp->ridnum; break;
7704 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7707 PC4500_readrid(ai,ridcode,iobuf,RIDSIZE, 1);
7708 /* get the count of bytes in the rid docs say 1st 2 bytes is it.
7709 * then return it to the user
7710 * 9/22/2000 Honor user given length
7714 if (copy_to_user(comp->data, iobuf, min(len, (int)RIDSIZE))) {
7723 * Danger Will Robinson write the rids here
7726 static int writerids(struct net_device *dev, aironet_ioctl *comp) {
7727 struct airo_info *ai = dev->ml_priv;
7730 static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
7731 unsigned char *iobuf;
7733 /* Only super-user can write RIDs */
7734 if (!capable(CAP_NET_ADMIN))
7737 if (test_bit(FLAG_FLASHING, &ai->flags))
7741 writer = do_writerid;
7743 switch(comp->command)
7745 case AIROPSIDS: ridcode = RID_SSID; break;
7746 case AIROPCAP: ridcode = RID_CAPABILITIES; break;
7747 case AIROPAPLIST: ridcode = RID_APLIST; break;
7748 case AIROPCFG: ai->config.len = 0;
7749 clear_bit(FLAG_COMMIT, &ai->flags);
7750 ridcode = RID_CONFIG; break;
7751 case AIROPWEPKEYNV: ridcode = RID_WEP_PERM; break;
7752 case AIROPLEAPUSR: ridcode = RID_LEAPUSERNAME; break;
7753 case AIROPLEAPPWD: ridcode = RID_LEAPPASSWORD; break;
7754 case AIROPWEPKEY: ridcode = RID_WEP_TEMP; writer = PC4500_writerid;
7756 case AIROPLEAPUSR+1: ridcode = 0xFF2A; break;
7757 case AIROPLEAPUSR+2: ridcode = 0xFF2B; break;
7759 /* this is not really a rid but a command given to the card
7763 if (enable_MAC(ai, 1) != 0)
7768 * Evidently this code in the airo driver does not get a symbol
7769 * as disable_MAC. it's probably so short the compiler does not gen one.
7775 /* This command merely clears the counts does not actually store any data
7776 * only reads rid. But as it changes the cards state, I put it in the
7777 * writerid routines.
7780 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7783 PC4500_readrid(ai,RID_STATSDELTACLEAR,iobuf,RIDSIZE, 1);
7785 enabled = ai->micstats.enabled;
7786 memset(&ai->micstats,0,sizeof(ai->micstats));
7787 ai->micstats.enabled = enabled;
7789 if (copy_to_user(comp->data, iobuf,
7790 min((int)comp->len, (int)RIDSIZE))) {
7798 return -EOPNOTSUPP; /* Blarg! */
7800 if(comp->len > RIDSIZE)
7803 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7806 if (copy_from_user(iobuf,comp->data,comp->len)) {
7811 if (comp->command == AIROPCFG) {
7812 ConfigRid *cfg = (ConfigRid *)iobuf;
7814 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags))
7815 cfg->opmode |= MODE_MIC;
7817 if ((cfg->opmode & MODE_CFG_MASK) == MODE_STA_IBSS)
7818 set_bit (FLAG_ADHOC, &ai->flags);
7820 clear_bit (FLAG_ADHOC, &ai->flags);
7823 if((*writer)(ai, ridcode, iobuf,comp->len,1)) {
7831 /*****************************************************************************
7832 * Ancillary flash / mod functions much black magic lurkes here *
7833 *****************************************************************************
7837 * Flash command switch table
7840 static int flashcard(struct net_device *dev, aironet_ioctl *comp) {
7843 /* Only super-user can modify flash */
7844 if (!capable(CAP_NET_ADMIN))
7847 switch(comp->command)
7850 return cmdreset((struct airo_info *)dev->ml_priv);
7853 if (!AIRO_FLASH(dev) &&
7854 (AIRO_FLASH(dev) = kmalloc(FLASHSIZE, GFP_KERNEL)) == NULL)
7856 return setflashmode((struct airo_info *)dev->ml_priv);
7858 case AIROFLSHGCHR: /* Get char from aux */
7859 if(comp->len != sizeof(int))
7861 if (copy_from_user(&z,comp->data,comp->len))
7863 return flashgchar((struct airo_info *)dev->ml_priv, z, 8000);
7865 case AIROFLSHPCHR: /* Send char to card. */
7866 if(comp->len != sizeof(int))
7868 if (copy_from_user(&z,comp->data,comp->len))
7870 return flashpchar((struct airo_info *)dev->ml_priv, z, 8000);
7872 case AIROFLPUTBUF: /* Send 32k to card */
7873 if (!AIRO_FLASH(dev))
7875 if(comp->len > FLASHSIZE)
7877 if (copy_from_user(AIRO_FLASH(dev), comp->data, comp->len))
7880 flashputbuf((struct airo_info *)dev->ml_priv);
7884 if (flashrestart((struct airo_info *)dev->ml_priv, dev))
7891 #define FLASH_COMMAND 0x7e7e
7895 * Disable MAC and do soft reset on
7899 static int cmdreset(struct airo_info *ai) {
7903 airo_print_info(ai->dev->name, "Waitbusy hang before RESET");
7907 OUT4500(ai,COMMAND,CMD_SOFTRESET);
7909 ssleep(1); /* WAS 600 12/7/00 */
7912 airo_print_info(ai->dev->name, "Waitbusy hang AFTER RESET");
7919 * Put the card in legendary flash
7923 static int setflashmode (struct airo_info *ai) {
7924 set_bit (FLAG_FLASHING, &ai->flags);
7926 OUT4500(ai, SWS0, FLASH_COMMAND);
7927 OUT4500(ai, SWS1, FLASH_COMMAND);
7929 OUT4500(ai, SWS0, FLASH_COMMAND);
7930 OUT4500(ai, COMMAND,0x10);
7932 OUT4500(ai, SWS2, FLASH_COMMAND);
7933 OUT4500(ai, SWS3, FLASH_COMMAND);
7934 OUT4500(ai, COMMAND,0);
7936 msleep(500); /* 500ms delay */
7939 clear_bit (FLAG_FLASHING, &ai->flags);
7940 airo_print_info(ai->dev->name, "Waitbusy hang after setflash mode");
7946 /* Put character to SWS0 wait for dwelltime
7950 static int flashpchar(struct airo_info *ai,int byte,int dwelltime) {
7961 /* Wait for busy bit d15 to go false indicating buffer empty */
7962 while ((IN4500 (ai, SWS0) & 0x8000) && waittime > 0) {
7967 /* timeout for busy clear wait */
7969 airo_print_info(ai->dev->name, "flash putchar busywait timeout!");
7973 /* Port is clear now write byte and wait for it to echo back */
7975 OUT4500(ai,SWS0,byte);
7978 echo = IN4500(ai,SWS1);
7979 } while (dwelltime >= 0 && echo != byte);
7983 return (echo == byte) ? 0 : -EIO;
7987 * Get a character from the card matching matchbyte
7990 static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime){
7992 unsigned char rbyte=0;
7995 rchar = IN4500(ai,SWS1);
7997 if(dwelltime && !(0x8000 & rchar)){
8002 rbyte = 0xff & rchar;
8004 if( (rbyte == matchbyte) && (0x8000 & rchar) ){
8008 if( rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
8012 }while(dwelltime > 0);
8017 * Transfer 32k of firmware data from user buffer to our buffer and
8021 static int flashputbuf(struct airo_info *ai){
8025 if (test_bit(FLAG_MPI,&ai->flags))
8026 memcpy_toio(ai->pciaux + 0x8000, ai->flash, FLASHSIZE);
8028 OUT4500(ai,AUXPAGE,0x100);
8029 OUT4500(ai,AUXOFF,0);
8031 for(nwords=0;nwords != FLASHSIZE / 2;nwords++){
8032 OUT4500(ai,AUXDATA,ai->flash[nwords] & 0xffff);
8035 OUT4500(ai,SWS0,0x8000);
8043 static int flashrestart(struct airo_info *ai,struct net_device *dev){
8046 ssleep(1); /* Added 12/7/00 */
8047 clear_bit (FLAG_FLASHING, &ai->flags);
8048 if (test_bit(FLAG_MPI, &ai->flags)) {
8049 status = mpi_init_descriptors(ai);
8050 if (status != SUCCESS)
8053 status = setup_card(ai, dev->dev_addr, 1);
8055 if (!test_bit(FLAG_MPI,&ai->flags))
8056 for( i = 0; i < MAX_FIDS; i++ ) {
8057 ai->fids[i] = transmit_allocate
8058 ( ai, AIRO_DEF_MTU, i >= MAX_FIDS / 2 );
8061 ssleep(1); /* Added 12/7/00 */
8064 #endif /* CISCO_EXT */
8067 This program is free software; you can redistribute it and/or
8068 modify it under the terms of the GNU General Public License
8069 as published by the Free Software Foundation; either version 2
8070 of the License, or (at your option) any later version.
8072 This program is distributed in the hope that it will be useful,
8073 but WITHOUT ANY WARRANTY; without even the implied warranty of
8074 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8075 GNU General Public License for more details.
8079 Redistribution and use in source and binary forms, with or without
8080 modification, are permitted provided that the following conditions
8083 1. Redistributions of source code must retain the above copyright
8084 notice, this list of conditions and the following disclaimer.
8085 2. Redistributions in binary form must reproduce the above copyright
8086 notice, this list of conditions and the following disclaimer in the
8087 documentation and/or other materials provided with the distribution.
8088 3. The name of the author may not be used to endorse or promote
8089 products derived from this software without specific prior written
8092 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
8093 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
8094 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
8095 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
8096 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
8097 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
8098 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
8099 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
8100 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
8101 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
8102 POSSIBILITY OF SUCH DAMAGE.
8105 module_init(airo_init_module);
8106 module_exit(airo_cleanup_module);