blob: 8a0abb668ed42528d2d0d6e2af377afd94f70b09 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*======================================================================
2
3 Aironet driver for 4500 and 4800 series cards
4
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
7 the end of this file.
8
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>.
19
20======================================================================*/
21
22#include <linux/config.h>
23#include <linux/init.h>
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/proc_fs.h>
28#include <linux/smp_lock.h>
29
30#include <linux/sched.h>
31#include <linux/ptrace.h>
32#include <linux/slab.h>
33#include <linux/string.h>
34#include <linux/timer.h>
35#include <linux/interrupt.h>
36#include <linux/in.h>
37#include <linux/bitops.h>
David Hardeman378f0582005-09-17 17:55:31 +100038#include <linux/scatterlist.h>
Adrian Bunka39d3e72006-01-21 01:35:15 +010039#include <linux/crypto.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <asm/io.h>
41#include <asm/system.h>
42
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
Adrian Bunkd3808762005-11-05 17:42:27 +010051#include "airo.h"
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#ifdef CONFIG_PCI
54static struct pci_device_id card_ids[] = {
55 { 0x14b9, 1, PCI_ANY_ID, PCI_ANY_ID, },
56 { 0x14b9, 0x4500, PCI_ANY_ID, PCI_ANY_ID },
57 { 0x14b9, 0x4800, PCI_ANY_ID, PCI_ANY_ID, },
58 { 0x14b9, 0x0340, PCI_ANY_ID, PCI_ANY_ID, },
59 { 0x14b9, 0x0350, PCI_ANY_ID, PCI_ANY_ID, },
60 { 0x14b9, 0x5000, PCI_ANY_ID, PCI_ANY_ID, },
61 { 0x14b9, 0xa504, PCI_ANY_ID, PCI_ANY_ID, },
62 { 0, }
63};
64MODULE_DEVICE_TABLE(pci, card_ids);
65
66static int airo_pci_probe(struct pci_dev *, const struct pci_device_id *);
67static void airo_pci_remove(struct pci_dev *);
Pavel Machek05adc3b2005-04-16 15:25:25 -070068static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069static int airo_pci_resume(struct pci_dev *pdev);
70
71static struct pci_driver airo_driver = {
72 .name = "airo",
73 .id_table = card_ids,
74 .probe = airo_pci_probe,
75 .remove = __devexit_p(airo_pci_remove),
76 .suspend = airo_pci_suspend,
77 .resume = airo_pci_resume,
78};
79#endif /* CONFIG_PCI */
80
81/* Include Wireless Extension definition and check version - Jean II */
82#include <linux/wireless.h>
83#define WIRELESS_SPY // enable iwspy support
84#include <net/iw_handler.h> // New driver API
85
86#define CISCO_EXT // enable Cisco extensions
87#ifdef CISCO_EXT
88#include <linux/delay.h>
89#endif
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091/* Hack to do some power saving */
92#define POWER_ON_DOWN
93
94/* As you can see this list is HUGH!
95 I really don't know what a lot of these counts are about, but they
96 are all here for completeness. If the IGNLABEL macro is put in
97 infront of the label, that statistic will not be included in the list
98 of statistics in the /proc filesystem */
99
100#define IGNLABEL(comment) NULL
101static char *statsLabels[] = {
102 "RxOverrun",
103 IGNLABEL("RxPlcpCrcErr"),
104 IGNLABEL("RxPlcpFormatErr"),
105 IGNLABEL("RxPlcpLengthErr"),
106 "RxMacCrcErr",
107 "RxMacCrcOk",
108 "RxWepErr",
109 "RxWepOk",
110 "RetryLong",
111 "RetryShort",
112 "MaxRetries",
113 "NoAck",
114 "NoCts",
115 "RxAck",
116 "RxCts",
117 "TxAck",
118 "TxRts",
119 "TxCts",
120 "TxMc",
121 "TxBc",
122 "TxUcFrags",
123 "TxUcPackets",
124 "TxBeacon",
125 "RxBeacon",
126 "TxSinColl",
127 "TxMulColl",
128 "DefersNo",
129 "DefersProt",
130 "DefersEngy",
131 "DupFram",
132 "RxFragDisc",
133 "TxAged",
134 "RxAged",
135 "LostSync-MaxRetry",
136 "LostSync-MissedBeacons",
137 "LostSync-ArlExceeded",
138 "LostSync-Deauth",
139 "LostSync-Disassoced",
140 "LostSync-TsfTiming",
141 "HostTxMc",
142 "HostTxBc",
143 "HostTxUc",
144 "HostTxFail",
145 "HostRxMc",
146 "HostRxBc",
147 "HostRxUc",
148 "HostRxDiscard",
149 IGNLABEL("HmacTxMc"),
150 IGNLABEL("HmacTxBc"),
151 IGNLABEL("HmacTxUc"),
152 IGNLABEL("HmacTxFail"),
153 IGNLABEL("HmacRxMc"),
154 IGNLABEL("HmacRxBc"),
155 IGNLABEL("HmacRxUc"),
156 IGNLABEL("HmacRxDiscard"),
157 IGNLABEL("HmacRxAccepted"),
158 "SsidMismatch",
159 "ApMismatch",
160 "RatesMismatch",
161 "AuthReject",
162 "AuthTimeout",
163 "AssocReject",
164 "AssocTimeout",
165 IGNLABEL("ReasonOutsideTable"),
166 IGNLABEL("ReasonStatus1"),
167 IGNLABEL("ReasonStatus2"),
168 IGNLABEL("ReasonStatus3"),
169 IGNLABEL("ReasonStatus4"),
170 IGNLABEL("ReasonStatus5"),
171 IGNLABEL("ReasonStatus6"),
172 IGNLABEL("ReasonStatus7"),
173 IGNLABEL("ReasonStatus8"),
174 IGNLABEL("ReasonStatus9"),
175 IGNLABEL("ReasonStatus10"),
176 IGNLABEL("ReasonStatus11"),
177 IGNLABEL("ReasonStatus12"),
178 IGNLABEL("ReasonStatus13"),
179 IGNLABEL("ReasonStatus14"),
180 IGNLABEL("ReasonStatus15"),
181 IGNLABEL("ReasonStatus16"),
182 IGNLABEL("ReasonStatus17"),
183 IGNLABEL("ReasonStatus18"),
184 IGNLABEL("ReasonStatus19"),
185 "RxMan",
186 "TxMan",
187 "RxRefresh",
188 "TxRefresh",
189 "RxPoll",
190 "TxPoll",
191 "HostRetries",
192 "LostSync-HostReq",
193 "HostTxBytes",
194 "HostRxBytes",
195 "ElapsedUsec",
196 "ElapsedSec",
197 "LostSyncBetterAP",
198 "PrivacyMismatch",
199 "Jammed",
200 "DiscRxNotWepped",
201 "PhyEleMismatch",
202 (char*)-1 };
203#ifndef RUN_AT
204#define RUN_AT(x) (jiffies+(x))
205#endif
206
207
208/* These variables are for insmod, since it seems that the rates
209 can only be set in setup_card. Rates should be a comma separated
210 (no spaces) list of rates (up to 8). */
211
212static int rates[8];
213static int basic_rate;
214static char *ssids[3];
215
216static int io[4];
217static int irq[4];
218
219static
220int maxencrypt /* = 0 */; /* The highest rate that the card can encrypt at.
221 0 means no limit. For old cards this was 4 */
222
223static int auto_wep /* = 0 */; /* If set, it tries to figure out the wep mode */
224static int aux_bap /* = 0 */; /* Checks to see if the aux ports are needed to read
225 the bap, needed on some older cards and buses. */
226static int adhoc;
227
228static int probe = 1;
229
230static int proc_uid /* = 0 */;
231
232static int proc_gid /* = 0 */;
233
234static int airo_perm = 0555;
235
236static int proc_perm = 0644;
237
238MODULE_AUTHOR("Benjamin Reed");
239MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet \
240 cards. Direct support for ISA/PCI/MPI cards and support \
241 for PCMCIA when used with airo_cs.");
242MODULE_LICENSE("Dual BSD/GPL");
243MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340/350");
244module_param_array(io, int, NULL, 0);
245module_param_array(irq, int, NULL, 0);
246module_param(basic_rate, int, 0);
247module_param_array(rates, int, NULL, 0);
248module_param_array(ssids, charp, NULL, 0);
249module_param(auto_wep, int, 0);
250MODULE_PARM_DESC(auto_wep, "If non-zero, the driver will keep looping through \
251the authentication options until an association is made. The value of \
252auto_wep is number of the wep keys to check. A value of 2 will try using \
253the key at index 0 and index 1.");
254module_param(aux_bap, int, 0);
255MODULE_PARM_DESC(aux_bap, "If non-zero, the driver will switch into a mode \
256than seems to work better for older cards with some older buses. Before \
257switching it checks that the switch is needed.");
258module_param(maxencrypt, int, 0);
259MODULE_PARM_DESC(maxencrypt, "The maximum speed that the card can do \
260encryption. Units are in 512kbs. Zero (default) means there is no limit. \
261Older cards used to be limited to 2mbs (4).");
262module_param(adhoc, int, 0);
263MODULE_PARM_DESC(adhoc, "If non-zero, the card will start in adhoc mode.");
264module_param(probe, int, 0);
265MODULE_PARM_DESC(probe, "If zero, the driver won't start the card.");
266
267module_param(proc_uid, int, 0);
268MODULE_PARM_DESC(proc_uid, "The uid that the /proc files will belong to.");
269module_param(proc_gid, int, 0);
270MODULE_PARM_DESC(proc_gid, "The gid that the /proc files will belong to.");
271module_param(airo_perm, int, 0);
272MODULE_PARM_DESC(airo_perm, "The permission bits of /proc/[driver/]aironet.");
273module_param(proc_perm, int, 0);
274MODULE_PARM_DESC(proc_perm, "The permission bits of the files in /proc");
275
276/* This is a kind of sloppy hack to get this information to OUT4500 and
277 IN4500. I would be extremely interested in the situation where this
278 doesn't work though!!! */
279static int do8bitIO = 0;
280
281/* Return codes */
282#define SUCCESS 0
283#define ERROR -1
284#define NO_PACKET -2
285
286/* Commands */
287#define NOP2 0x0000
288#define MAC_ENABLE 0x0001
289#define MAC_DISABLE 0x0002
290#define CMD_LOSE_SYNC 0x0003 /* Not sure what this does... */
291#define CMD_SOFTRESET 0x0004
292#define HOSTSLEEP 0x0005
293#define CMD_MAGIC_PKT 0x0006
294#define CMD_SETWAKEMASK 0x0007
295#define CMD_READCFG 0x0008
296#define CMD_SETMODE 0x0009
297#define CMD_ALLOCATETX 0x000a
298#define CMD_TRANSMIT 0x000b
299#define CMD_DEALLOCATETX 0x000c
300#define NOP 0x0010
301#define CMD_WORKAROUND 0x0011
302#define CMD_ALLOCATEAUX 0x0020
303#define CMD_ACCESS 0x0021
304#define CMD_PCIBAP 0x0022
305#define CMD_PCIAUX 0x0023
306#define CMD_ALLOCBUF 0x0028
307#define CMD_GETTLV 0x0029
308#define CMD_PUTTLV 0x002a
309#define CMD_DELTLV 0x002b
310#define CMD_FINDNEXTTLV 0x002c
311#define CMD_PSPNODES 0x0030
312#define CMD_SETCW 0x0031
313#define CMD_SETPCF 0x0032
314#define CMD_SETPHYREG 0x003e
315#define CMD_TXTEST 0x003f
316#define MAC_ENABLETX 0x0101
317#define CMD_LISTBSS 0x0103
318#define CMD_SAVECFG 0x0108
319#define CMD_ENABLEAUX 0x0111
320#define CMD_WRITERID 0x0121
321#define CMD_USEPSPNODES 0x0130
322#define MAC_ENABLERX 0x0201
323
324/* Command errors */
325#define ERROR_QUALIF 0x00
326#define ERROR_ILLCMD 0x01
327#define ERROR_ILLFMT 0x02
328#define ERROR_INVFID 0x03
329#define ERROR_INVRID 0x04
330#define ERROR_LARGE 0x05
331#define ERROR_NDISABL 0x06
332#define ERROR_ALLOCBSY 0x07
333#define ERROR_NORD 0x0B
334#define ERROR_NOWR 0x0C
335#define ERROR_INVFIDTX 0x0D
336#define ERROR_TESTACT 0x0E
337#define ERROR_TAGNFND 0x12
338#define ERROR_DECODE 0x20
339#define ERROR_DESCUNAV 0x21
340#define ERROR_BADLEN 0x22
341#define ERROR_MODE 0x80
342#define ERROR_HOP 0x81
343#define ERROR_BINTER 0x82
344#define ERROR_RXMODE 0x83
345#define ERROR_MACADDR 0x84
346#define ERROR_RATES 0x85
347#define ERROR_ORDER 0x86
348#define ERROR_SCAN 0x87
349#define ERROR_AUTH 0x88
350#define ERROR_PSMODE 0x89
351#define ERROR_RTYPE 0x8A
352#define ERROR_DIVER 0x8B
353#define ERROR_SSID 0x8C
354#define ERROR_APLIST 0x8D
355#define ERROR_AUTOWAKE 0x8E
356#define ERROR_LEAP 0x8F
357
358/* Registers */
359#define COMMAND 0x00
360#define PARAM0 0x02
361#define PARAM1 0x04
362#define PARAM2 0x06
363#define STATUS 0x08
364#define RESP0 0x0a
365#define RESP1 0x0c
366#define RESP2 0x0e
367#define LINKSTAT 0x10
368#define SELECT0 0x18
369#define OFFSET0 0x1c
370#define RXFID 0x20
371#define TXALLOCFID 0x22
372#define TXCOMPLFID 0x24
373#define DATA0 0x36
374#define EVSTAT 0x30
375#define EVINTEN 0x32
376#define EVACK 0x34
377#define SWS0 0x28
378#define SWS1 0x2a
379#define SWS2 0x2c
380#define SWS3 0x2e
381#define AUXPAGE 0x3A
382#define AUXOFF 0x3C
383#define AUXDATA 0x3E
384
385#define FID_TX 1
386#define FID_RX 2
387/* Offset into aux memory for descriptors */
388#define AUX_OFFSET 0x800
389/* Size of allocated packets */
390#define PKTSIZE 1840
391#define RIDSIZE 2048
392/* Size of the transmit queue */
393#define MAXTXQ 64
394
395/* BAP selectors */
396#define BAP0 0 // Used for receiving packets
397#define BAP1 2 // Used for xmiting packets and working with RIDS
398
399/* Flags */
400#define COMMAND_BUSY 0x8000
401
402#define BAP_BUSY 0x8000
403#define BAP_ERR 0x4000
404#define BAP_DONE 0x2000
405
406#define PROMISC 0xffff
407#define NOPROMISC 0x0000
408
409#define EV_CMD 0x10
410#define EV_CLEARCOMMANDBUSY 0x4000
411#define EV_RX 0x01
412#define EV_TX 0x02
413#define EV_TXEXC 0x04
414#define EV_ALLOC 0x08
415#define EV_LINK 0x80
416#define EV_AWAKE 0x100
417#define EV_TXCPY 0x400
418#define EV_UNKNOWN 0x800
419#define EV_MIC 0x1000 /* Message Integrity Check Interrupt */
420#define EV_AWAKEN 0x2000
421#define STATUS_INTS (EV_AWAKE|EV_LINK|EV_TXEXC|EV_TX|EV_TXCPY|EV_RX|EV_MIC)
422
423#ifdef CHECK_UNKNOWN_INTS
424#define IGNORE_INTS ( EV_CMD | EV_UNKNOWN)
425#else
426#define IGNORE_INTS (~STATUS_INTS)
427#endif
428
429/* RID TYPES */
430#define RID_RW 0x20
431
432/* The RIDs */
433#define RID_CAPABILITIES 0xFF00
434#define RID_APINFO 0xFF01
435#define RID_RADIOINFO 0xFF02
436#define RID_UNKNOWN3 0xFF03
437#define RID_RSSI 0xFF04
438#define RID_CONFIG 0xFF10
439#define RID_SSID 0xFF11
440#define RID_APLIST 0xFF12
441#define RID_DRVNAME 0xFF13
442#define RID_ETHERENCAP 0xFF14
443#define RID_WEP_TEMP 0xFF15
444#define RID_WEP_PERM 0xFF16
445#define RID_MODULATION 0xFF17
446#define RID_OPTIONS 0xFF18
447#define RID_ACTUALCONFIG 0xFF20 /*readonly*/
448#define RID_FACTORYCONFIG 0xFF21
449#define RID_UNKNOWN22 0xFF22
450#define RID_LEAPUSERNAME 0xFF23
451#define RID_LEAPPASSWORD 0xFF24
452#define RID_STATUS 0xFF50
453#define RID_BEACON_HST 0xFF51
454#define RID_BUSY_HST 0xFF52
455#define RID_RETRIES_HST 0xFF53
456#define RID_UNKNOWN54 0xFF54
457#define RID_UNKNOWN55 0xFF55
458#define RID_UNKNOWN56 0xFF56
459#define RID_MIC 0xFF57
460#define RID_STATS16 0xFF60
461#define RID_STATS16DELTA 0xFF61
462#define RID_STATS16DELTACLEAR 0xFF62
463#define RID_STATS 0xFF68
464#define RID_STATSDELTA 0xFF69
465#define RID_STATSDELTACLEAR 0xFF6A
466#define RID_ECHOTEST_RID 0xFF70
467#define RID_ECHOTEST_RESULTS 0xFF71
468#define RID_BSSLISTFIRST 0xFF72
469#define RID_BSSLISTNEXT 0xFF73
470
471typedef struct {
472 u16 cmd;
473 u16 parm0;
474 u16 parm1;
475 u16 parm2;
476} Cmd;
477
478typedef struct {
479 u16 status;
480 u16 rsp0;
481 u16 rsp1;
482 u16 rsp2;
483} Resp;
484
485/*
486 * Rids and endian-ness: The Rids will always be in cpu endian, since
487 * this all the patches from the big-endian guys end up doing that.
488 * so all rid access should use the read/writeXXXRid routines.
489 */
490
491/* This is redundant for x86 archs, but it seems necessary for ARM */
492#pragma pack(1)
493
494/* This structure came from an email sent to me from an engineer at
495 aironet for inclusion into this driver */
496typedef struct {
497 u16 len;
498 u16 kindex;
499 u8 mac[ETH_ALEN];
500 u16 klen;
501 u8 key[16];
502} WepKeyRid;
503
504/* These structures are from the Aironet's PC4500 Developers Manual */
505typedef struct {
506 u16 len;
507 u8 ssid[32];
508} Ssid;
509
510typedef struct {
511 u16 len;
512 Ssid ssids[3];
513} SsidRid;
514
515typedef struct {
516 u16 len;
517 u16 modulation;
518#define MOD_DEFAULT 0
519#define MOD_CCK 1
520#define MOD_MOK 2
521} ModulationRid;
522
523typedef struct {
524 u16 len; /* sizeof(ConfigRid) */
525 u16 opmode; /* operating mode */
526#define MODE_STA_IBSS 0
527#define MODE_STA_ESS 1
528#define MODE_AP 2
529#define MODE_AP_RPTR 3
530#define MODE_ETHERNET_HOST (0<<8) /* rx payloads converted */
531#define MODE_LLC_HOST (1<<8) /* rx payloads left as is */
532#define MODE_AIRONET_EXTEND (1<<9) /* enable Aironet extenstions */
533#define MODE_AP_INTERFACE (1<<10) /* enable ap interface extensions */
534#define MODE_ANTENNA_ALIGN (1<<11) /* enable antenna alignment */
535#define MODE_ETHER_LLC (1<<12) /* enable ethernet LLC */
536#define MODE_LEAF_NODE (1<<13) /* enable leaf node bridge */
537#define MODE_CF_POLLABLE (1<<14) /* enable CF pollable */
538#define MODE_MIC (1<<15) /* enable MIC */
539 u16 rmode; /* receive mode */
540#define RXMODE_BC_MC_ADDR 0
541#define RXMODE_BC_ADDR 1 /* ignore multicasts */
542#define RXMODE_ADDR 2 /* ignore multicast and broadcast */
543#define RXMODE_RFMON 3 /* wireless monitor mode */
544#define RXMODE_RFMON_ANYBSS 4
545#define RXMODE_LANMON 5 /* lan style monitor -- data packets only */
546#define RXMODE_DISABLE_802_3_HEADER (1<<8) /* disables 802.3 header on rx */
547#define RXMODE_NORMALIZED_RSSI (1<<9) /* return normalized RSSI */
548 u16 fragThresh;
549 u16 rtsThres;
550 u8 macAddr[ETH_ALEN];
551 u8 rates[8];
552 u16 shortRetryLimit;
553 u16 longRetryLimit;
554 u16 txLifetime; /* in kusec */
555 u16 rxLifetime; /* in kusec */
556 u16 stationary;
557 u16 ordering;
558 u16 u16deviceType; /* for overriding device type */
559 u16 cfpRate;
560 u16 cfpDuration;
561 u16 _reserved1[3];
562 /*---------- Scanning/Associating ----------*/
563 u16 scanMode;
564#define SCANMODE_ACTIVE 0
565#define SCANMODE_PASSIVE 1
566#define SCANMODE_AIROSCAN 2
567 u16 probeDelay; /* in kusec */
568 u16 probeEnergyTimeout; /* in kusec */
569 u16 probeResponseTimeout;
570 u16 beaconListenTimeout;
571 u16 joinNetTimeout;
572 u16 authTimeout;
573 u16 authType;
574#define AUTH_OPEN 0x1
575#define AUTH_ENCRYPT 0x101
576#define AUTH_SHAREDKEY 0x102
577#define AUTH_ALLOW_UNENCRYPTED 0x200
578 u16 associationTimeout;
579 u16 specifiedApTimeout;
580 u16 offlineScanInterval;
581 u16 offlineScanDuration;
582 u16 linkLossDelay;
583 u16 maxBeaconLostTime;
584 u16 refreshInterval;
585#define DISABLE_REFRESH 0xFFFF
586 u16 _reserved1a[1];
587 /*---------- Power save operation ----------*/
588 u16 powerSaveMode;
589#define POWERSAVE_CAM 0
590#define POWERSAVE_PSP 1
591#define POWERSAVE_PSPCAM 2
592 u16 sleepForDtims;
593 u16 listenInterval;
594 u16 fastListenInterval;
595 u16 listenDecay;
596 u16 fastListenDelay;
597 u16 _reserved2[2];
598 /*---------- Ap/Ibss config items ----------*/
599 u16 beaconPeriod;
600 u16 atimDuration;
601 u16 hopPeriod;
602 u16 channelSet;
603 u16 channel;
604 u16 dtimPeriod;
605 u16 bridgeDistance;
606 u16 radioID;
607 /*---------- Radio configuration ----------*/
608 u16 radioType;
609#define RADIOTYPE_DEFAULT 0
610#define RADIOTYPE_802_11 1
611#define RADIOTYPE_LEGACY 2
612 u8 rxDiversity;
613 u8 txDiversity;
614 u16 txPower;
615#define TXPOWER_DEFAULT 0
616 u16 rssiThreshold;
617#define RSSI_DEFAULT 0
618 u16 modulation;
619#define PREAMBLE_AUTO 0
620#define PREAMBLE_LONG 1
621#define PREAMBLE_SHORT 2
622 u16 preamble;
623 u16 homeProduct;
624 u16 radioSpecific;
625 /*---------- Aironet Extensions ----------*/
626 u8 nodeName[16];
627 u16 arlThreshold;
628 u16 arlDecay;
629 u16 arlDelay;
630 u16 _reserved4[1];
631 /*---------- Aironet Extensions ----------*/
632 u8 magicAction;
633#define MAGIC_ACTION_STSCHG 1
634#define MAGIC_ACTION_RESUME 2
635#define MAGIC_IGNORE_MCAST (1<<8)
636#define MAGIC_IGNORE_BCAST (1<<9)
637#define MAGIC_SWITCH_TO_PSP (0<<10)
638#define MAGIC_STAY_IN_CAM (1<<10)
639 u8 magicControl;
640 u16 autoWake;
641} ConfigRid;
642
643typedef struct {
644 u16 len;
645 u8 mac[ETH_ALEN];
646 u16 mode;
647 u16 errorCode;
648 u16 sigQuality;
649 u16 SSIDlen;
650 char SSID[32];
651 char apName[16];
652 u8 bssid[4][ETH_ALEN];
653 u16 beaconPeriod;
654 u16 dimPeriod;
655 u16 atimDuration;
656 u16 hopPeriod;
657 u16 channelSet;
658 u16 channel;
659 u16 hopsToBackbone;
660 u16 apTotalLoad;
661 u16 generatedLoad;
662 u16 accumulatedArl;
663 u16 signalQuality;
664 u16 currentXmitRate;
665 u16 apDevExtensions;
666 u16 normalizedSignalStrength;
667 u16 shortPreamble;
668 u8 apIP[4];
669 u8 noisePercent; /* Noise percent in last second */
670 u8 noisedBm; /* Noise dBm in last second */
671 u8 noiseAvePercent; /* Noise percent in last minute */
672 u8 noiseAvedBm; /* Noise dBm in last minute */
673 u8 noiseMaxPercent; /* Highest noise percent in last minute */
674 u8 noiseMaxdBm; /* Highest noise dbm in last minute */
675 u16 load;
676 u8 carrier[4];
677 u16 assocStatus;
678#define STAT_NOPACKETS 0
679#define STAT_NOCARRIERSET 10
680#define STAT_GOTCARRIERSET 11
681#define STAT_WRONGSSID 20
682#define STAT_BADCHANNEL 25
683#define STAT_BADBITRATES 30
684#define STAT_BADPRIVACY 35
685#define STAT_APFOUND 40
686#define STAT_APREJECTED 50
687#define STAT_AUTHENTICATING 60
688#define STAT_DEAUTHENTICATED 61
689#define STAT_AUTHTIMEOUT 62
690#define STAT_ASSOCIATING 70
691#define STAT_DEASSOCIATED 71
692#define STAT_ASSOCTIMEOUT 72
693#define STAT_NOTAIROAP 73
694#define STAT_ASSOCIATED 80
695#define STAT_LEAPING 90
696#define STAT_LEAPFAILED 91
697#define STAT_LEAPTIMEDOUT 92
698#define STAT_LEAPCOMPLETE 93
699} StatusRid;
700
701typedef struct {
702 u16 len;
703 u16 spacer;
704 u32 vals[100];
705} StatsRid;
706
707
708typedef struct {
709 u16 len;
710 u8 ap[4][ETH_ALEN];
711} APListRid;
712
713typedef struct {
714 u16 len;
715 char oui[3];
716 char zero;
717 u16 prodNum;
718 char manName[32];
719 char prodName[16];
720 char prodVer[8];
721 char factoryAddr[ETH_ALEN];
722 char aironetAddr[ETH_ALEN];
723 u16 radioType;
724 u16 country;
725 char callid[ETH_ALEN];
726 char supportedRates[8];
727 char rxDiversity;
728 char txDiversity;
729 u16 txPowerLevels[8];
730 u16 hardVer;
731 u16 hardCap;
732 u16 tempRange;
733 u16 softVer;
734 u16 softSubVer;
735 u16 interfaceVer;
736 u16 softCap;
737 u16 bootBlockVer;
738 u16 requiredHard;
739 u16 extSoftCap;
740} CapabilityRid;
741
742typedef struct {
743 u16 len;
744 u16 index; /* First is 0 and 0xffff means end of list */
745#define RADIO_FH 1 /* Frequency hopping radio type */
746#define RADIO_DS 2 /* Direct sequence radio type */
747#define RADIO_TMA 4 /* Proprietary radio used in old cards (2500) */
748 u16 radioType;
749 u8 bssid[ETH_ALEN]; /* Mac address of the BSS */
750 u8 zero;
751 u8 ssidLen;
752 u8 ssid[32];
Dan Williams41480af2005-05-10 09:45:51 -0400753 u16 dBm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754#define CAP_ESS (1<<0)
755#define CAP_IBSS (1<<1)
756#define CAP_PRIVACY (1<<4)
757#define CAP_SHORTHDR (1<<5)
758 u16 cap;
759 u16 beaconInterval;
760 u8 rates[8]; /* Same as rates for config rid */
761 struct { /* For frequency hopping only */
762 u16 dwell;
763 u8 hopSet;
764 u8 hopPattern;
765 u8 hopIndex;
766 u8 fill;
767 } fh;
768 u16 dsChannel;
769 u16 atimWindow;
770} BSSListRid;
771
772typedef struct {
773 u8 rssipct;
774 u8 rssidBm;
775} tdsRssiEntry;
776
777typedef struct {
778 u16 len;
779 tdsRssiEntry x[256];
780} tdsRssiRid;
781
782typedef struct {
783 u16 len;
784 u16 state;
785 u16 multicastValid;
786 u8 multicast[16];
787 u16 unicastValid;
788 u8 unicast[16];
789} MICRid;
790
791typedef struct {
792 u16 typelen;
793
794 union {
795 u8 snap[8];
796 struct {
797 u8 dsap;
798 u8 ssap;
799 u8 control;
800 u8 orgcode[3];
801 u8 fieldtype[2];
802 } llc;
803 } u;
804 u32 mic;
805 u32 seq;
806} MICBuffer;
807
808typedef struct {
809 u8 da[ETH_ALEN];
810 u8 sa[ETH_ALEN];
811} etherHead;
812
813#pragma pack()
814
815#define TXCTL_TXOK (1<<1) /* report if tx is ok */
816#define TXCTL_TXEX (1<<2) /* report if tx fails */
817#define TXCTL_802_3 (0<<3) /* 802.3 packet */
818#define TXCTL_802_11 (1<<3) /* 802.11 mac packet */
819#define TXCTL_ETHERNET (0<<4) /* payload has ethertype */
820#define TXCTL_LLC (1<<4) /* payload is llc */
821#define TXCTL_RELEASE (0<<5) /* release after completion */
822#define TXCTL_NORELEASE (1<<5) /* on completion returns to host */
823
824#define BUSY_FID 0x10000
825
826#ifdef CISCO_EXT
827#define AIROMAGIC 0xa55a
828/* Warning : SIOCDEVPRIVATE may disapear during 2.5.X - Jean II */
829#ifdef SIOCIWFIRSTPRIV
830#ifdef SIOCDEVPRIVATE
831#define AIROOLDIOCTL SIOCDEVPRIVATE
832#define AIROOLDIDIFC AIROOLDIOCTL + 1
833#endif /* SIOCDEVPRIVATE */
834#else /* SIOCIWFIRSTPRIV */
835#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
836#endif /* SIOCIWFIRSTPRIV */
837/* This may be wrong. When using the new SIOCIWFIRSTPRIV range, we probably
838 * should use only "GET" ioctls (last bit set to 1). "SET" ioctls are root
839 * only and don't return the modified struct ifreq to the application which
840 * is usually a problem. - Jean II */
841#define AIROIOCTL SIOCIWFIRSTPRIV
842#define AIROIDIFC AIROIOCTL + 1
843
844/* Ioctl constants to be used in airo_ioctl.command */
845
846#define AIROGCAP 0 // Capability rid
847#define AIROGCFG 1 // USED A LOT
848#define AIROGSLIST 2 // System ID list
849#define AIROGVLIST 3 // List of specified AP's
850#define AIROGDRVNAM 4 // NOTUSED
851#define AIROGEHTENC 5 // NOTUSED
852#define AIROGWEPKTMP 6
853#define AIROGWEPKNV 7
854#define AIROGSTAT 8
855#define AIROGSTATSC32 9
856#define AIROGSTATSD32 10
857#define AIROGMICRID 11
858#define AIROGMICSTATS 12
859#define AIROGFLAGS 13
860#define AIROGID 14
861#define AIRORRID 15
862#define AIRORSWVERSION 17
863
864/* Leave gap of 40 commands after AIROGSTATSD32 for future */
865
866#define AIROPCAP AIROGSTATSD32 + 40
867#define AIROPVLIST AIROPCAP + 1
868#define AIROPSLIST AIROPVLIST + 1
869#define AIROPCFG AIROPSLIST + 1
870#define AIROPSIDS AIROPCFG + 1
871#define AIROPAPLIST AIROPSIDS + 1
872#define AIROPMACON AIROPAPLIST + 1 /* Enable mac */
873#define AIROPMACOFF AIROPMACON + 1 /* Disable mac */
874#define AIROPSTCLR AIROPMACOFF + 1
875#define AIROPWEPKEY AIROPSTCLR + 1
876#define AIROPWEPKEYNV AIROPWEPKEY + 1
877#define AIROPLEAPPWD AIROPWEPKEYNV + 1
878#define AIROPLEAPUSR AIROPLEAPPWD + 1
879
880/* Flash codes */
881
882#define AIROFLSHRST AIROPWEPKEYNV + 40
883#define AIROFLSHGCHR AIROFLSHRST + 1
884#define AIROFLSHSTFL AIROFLSHGCHR + 1
885#define AIROFLSHPCHR AIROFLSHSTFL + 1
886#define AIROFLPUTBUF AIROFLSHPCHR + 1
887#define AIRORESTART AIROFLPUTBUF + 1
888
889#define FLASHSIZE 32768
890#define AUXMEMSIZE (256 * 1024)
891
892typedef struct aironet_ioctl {
893 unsigned short command; // What to do
894 unsigned short len; // Len of data
895 unsigned short ridnum; // rid number
896 unsigned char __user *data; // d-data
897} aironet_ioctl;
898
Domen Puncer62595eb2005-06-20 23:54:37 +0200899static char swversion[] = "2.1";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900#endif /* CISCO_EXT */
901
902#define NUM_MODULES 2
903#define MIC_MSGLEN_MAX 2400
904#define EMMH32_MSGLEN_MAX MIC_MSGLEN_MAX
905
906typedef struct {
907 u32 size; // size
908 u8 enabled; // MIC enabled or not
909 u32 rxSuccess; // successful packets received
910 u32 rxIncorrectMIC; // pkts dropped due to incorrect MIC comparison
911 u32 rxNotMICed; // pkts dropped due to not being MIC'd
912 u32 rxMICPlummed; // pkts dropped due to not having a MIC plummed
913 u32 rxWrongSequence; // pkts dropped due to sequence number violation
914 u32 reserve[32];
915} mic_statistics;
916
917typedef struct {
918 u32 coeff[((EMMH32_MSGLEN_MAX)+3)>>2];
919 u64 accum; // accumulated mic, reduced to u32 in final()
920 int position; // current position (byte offset) in message
921 union {
922 u8 d8[4];
923 u32 d32;
924 } part; // saves partial message word across update() calls
925} emmh32_context;
926
927typedef struct {
928 emmh32_context seed; // Context - the seed
929 u32 rx; // Received sequence number
930 u32 tx; // Tx sequence number
931 u32 window; // Start of window
932 u8 valid; // Flag to say if context is valid or not
933 u8 key[16];
934} miccntx;
935
936typedef struct {
937 miccntx mCtx; // Multicast context
938 miccntx uCtx; // Unicast context
939} mic_module;
940
941typedef struct {
942 unsigned int rid: 16;
943 unsigned int len: 15;
944 unsigned int valid: 1;
945 dma_addr_t host_addr;
946} Rid;
947
948typedef struct {
949 unsigned int offset: 15;
950 unsigned int eoc: 1;
951 unsigned int len: 15;
952 unsigned int valid: 1;
953 dma_addr_t host_addr;
954} TxFid;
955
956typedef struct {
957 unsigned int ctl: 15;
958 unsigned int rdy: 1;
959 unsigned int len: 15;
960 unsigned int valid: 1;
961 dma_addr_t host_addr;
962} RxFid;
963
964/*
965 * Host receive descriptor
966 */
967typedef struct {
968 unsigned char __iomem *card_ram_off; /* offset into card memory of the
969 desc */
970 RxFid rx_desc; /* card receive descriptor */
971 char *virtual_host_addr; /* virtual address of host receive
972 buffer */
973 int pending;
974} HostRxDesc;
975
976/*
977 * Host transmit descriptor
978 */
979typedef struct {
980 unsigned char __iomem *card_ram_off; /* offset into card memory of the
981 desc */
982 TxFid tx_desc; /* card transmit descriptor */
983 char *virtual_host_addr; /* virtual address of host receive
984 buffer */
985 int pending;
986} HostTxDesc;
987
988/*
989 * Host RID descriptor
990 */
991typedef struct {
992 unsigned char __iomem *card_ram_off; /* offset into card memory of the
993 descriptor */
994 Rid rid_desc; /* card RID descriptor */
995 char *virtual_host_addr; /* virtual address of host receive
996 buffer */
997} HostRidDesc;
998
999typedef struct {
1000 u16 sw0;
1001 u16 sw1;
1002 u16 status;
1003 u16 len;
1004#define HOST_SET (1 << 0)
1005#define HOST_INT_TX (1 << 1) /* Interrupt on successful TX */
1006#define HOST_INT_TXERR (1 << 2) /* Interrupt on unseccessful TX */
1007#define HOST_LCC_PAYLOAD (1 << 4) /* LLC payload, 0 = Ethertype */
1008#define HOST_DONT_RLSE (1 << 5) /* Don't release buffer when done */
1009#define HOST_DONT_RETRY (1 << 6) /* Don't retry trasmit */
1010#define HOST_CLR_AID (1 << 7) /* clear AID failure */
1011#define HOST_RTS (1 << 9) /* Force RTS use */
1012#define HOST_SHORT (1 << 10) /* Do short preamble */
1013 u16 ctl;
1014 u16 aid;
1015 u16 retries;
1016 u16 fill;
1017} TxCtlHdr;
1018
1019typedef struct {
1020 u16 ctl;
1021 u16 duration;
1022 char addr1[6];
1023 char addr2[6];
1024 char addr3[6];
1025 u16 seq;
1026 char addr4[6];
1027} WifiHdr;
1028
1029
1030typedef struct {
1031 TxCtlHdr ctlhdr;
1032 u16 fill1;
1033 u16 fill2;
1034 WifiHdr wifihdr;
1035 u16 gaplen;
1036 u16 status;
1037} WifiCtlHdr;
1038
Jouni Malinenff1d2762005-05-12 22:54:16 -04001039static WifiCtlHdr wifictlhdr8023 = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 .ctlhdr = {
1041 .ctl = HOST_DONT_RLSE,
1042 }
1043};
1044
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045// Frequency list (map channels to frequencies)
1046static const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
1047 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
1048
1049// A few details needed for WEP (Wireless Equivalent Privacy)
1050#define MAX_KEY_SIZE 13 // 128 (?) bits
1051#define MIN_KEY_SIZE 5 // 40 bits RC4 - WEP
1052typedef struct wep_key_t {
1053 u16 len;
1054 u8 key[16]; /* 40-bit and 104-bit keys */
1055} wep_key_t;
1056
1057/* Backward compatibility */
1058#ifndef IW_ENCODE_NOKEY
1059#define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
1060#define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
1061#endif /* IW_ENCODE_NOKEY */
1062
1063/* List of Wireless Handlers (new API) */
1064static const struct iw_handler_def airo_handler_def;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
1066static const char version[] = "airo.c 0.6 (Ben Reed & Javier Achirica)";
1067
1068struct airo_info;
1069
1070static int get_dec_u16( char *buffer, int *start, int limit );
1071static void OUT4500( struct airo_info *, u16 register, u16 value );
1072static unsigned short IN4500( struct airo_info *, u16 register );
1073static u16 setup_card(struct airo_info*, u8 *mac, int lock);
1074static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock );
1075static void disable_MAC(struct airo_info *ai, int lock);
1076static void enable_interrupts(struct airo_info*);
1077static void disable_interrupts(struct airo_info*);
1078static u16 issuecommand(struct airo_info*, Cmd *pCmd, Resp *pRsp);
1079static int bap_setup(struct airo_info*, u16 rid, u16 offset, int whichbap);
1080static int aux_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen,
1081 int whichbap);
1082static int fast_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen,
1083 int whichbap);
1084static int bap_write(struct airo_info*, const u16 *pu16Src, int bytelen,
1085 int whichbap);
1086static int PC4500_accessrid(struct airo_info*, u16 rid, u16 accmd);
1087static int PC4500_readrid(struct airo_info*, u16 rid, void *pBuf, int len, int lock);
1088static int PC4500_writerid(struct airo_info*, u16 rid, const void
1089 *pBuf, int len, int lock);
1090static int do_writerid( struct airo_info*, u16 rid, const void *rid_data,
1091 int len, int dummy );
1092static u16 transmit_allocate(struct airo_info*, int lenPayload, int raw);
1093static int transmit_802_3_packet(struct airo_info*, int len, char *pPacket);
1094static int transmit_802_11_packet(struct airo_info*, int len, char *pPacket);
1095
1096static int mpi_send_packet (struct net_device *dev);
1097static void mpi_unmap_card(struct pci_dev *pci);
1098static void mpi_receive_802_3(struct airo_info *ai);
1099static void mpi_receive_802_11(struct airo_info *ai);
1100static int waitbusy (struct airo_info *ai);
1101
1102static irqreturn_t airo_interrupt( int irq, void* dev_id, struct pt_regs
1103 *regs);
1104static int airo_thread(void *data);
1105static void timer_func( struct net_device *dev );
1106static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001107static struct iw_statistics *airo_get_wireless_stats (struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108static void airo_read_wireless_stats (struct airo_info *local);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109#ifdef CISCO_EXT
1110static int readrids(struct net_device *dev, aironet_ioctl *comp);
1111static int writerids(struct net_device *dev, aironet_ioctl *comp);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001112static int flashcard(struct net_device *dev, aironet_ioctl *comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113#endif /* CISCO_EXT */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114static void micinit(struct airo_info *ai);
1115static int micsetup(struct airo_info *ai);
1116static int encapsulate(struct airo_info *ai, etherHead *pPacket, MICBuffer *buffer, int len);
1117static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *pPacket, u16 payLen);
1118
Dan Williams41480af2005-05-10 09:45:51 -04001119static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi);
1120static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm);
1121
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122struct airo_info {
1123 struct net_device_stats stats;
1124 struct net_device *dev;
1125 /* Note, we can have MAX_FIDS outstanding. FIDs are 16-bits, so we
1126 use the high bit to mark whether it is in use. */
1127#define MAX_FIDS 6
1128#define MPI_MAX_FIDS 1
1129 int fids[MAX_FIDS];
1130 ConfigRid config;
1131 char keyindex; // Used with auto wep
1132 char defindex; // Used with auto wep
1133 struct proc_dir_entry *proc_entry;
1134 spinlock_t aux_lock;
1135 unsigned long flags;
1136#define FLAG_PROMISC 8 /* IFF_PROMISC 0x100 - include/linux/if.h */
1137#define FLAG_RADIO_OFF 0 /* User disabling of MAC */
1138#define FLAG_RADIO_DOWN 1 /* ifup/ifdown disabling of MAC */
1139#define FLAG_RADIO_MASK 0x03
1140#define FLAG_ENABLED 2
1141#define FLAG_ADHOC 3 /* Needed by MIC */
1142#define FLAG_MIC_CAPABLE 4
1143#define FLAG_UPDATE_MULTI 5
1144#define FLAG_UPDATE_UNI 6
1145#define FLAG_802_11 7
1146#define FLAG_PENDING_XMIT 9
1147#define FLAG_PENDING_XMIT11 10
1148#define FLAG_MPI 11
1149#define FLAG_REGISTERED 12
1150#define FLAG_COMMIT 13
1151#define FLAG_RESET 14
1152#define FLAG_FLASHING 15
1153#define JOB_MASK 0x1ff0000
1154#define JOB_DIE 16
1155#define JOB_XMIT 17
1156#define JOB_XMIT11 18
1157#define JOB_STATS 19
1158#define JOB_PROMISC 20
1159#define JOB_MIC 21
1160#define JOB_EVENT 22
1161#define JOB_AUTOWEP 23
1162#define JOB_WSTATS 24
1163 int (*bap_read)(struct airo_info*, u16 *pu16Dst, int bytelen,
1164 int whichbap);
1165 unsigned short *flash;
1166 tdsRssiEntry *rssi;
1167 struct task_struct *task;
1168 struct semaphore sem;
1169 pid_t thr_pid;
1170 wait_queue_head_t thr_wait;
1171 struct completion thr_exited;
1172 unsigned long expires;
1173 struct {
1174 struct sk_buff *skb;
1175 int fid;
1176 } xmit, xmit11;
1177 struct net_device *wifidev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 struct iw_statistics wstats; // wireless stats
1179 unsigned long scan_timestamp; /* Time started to scan */
1180 struct iw_spy_data spy_data;
1181 struct iw_public_data wireless_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 /* MIC stuff */
1183 struct crypto_tfm *tfm;
1184 mic_module mod[2];
1185 mic_statistics micstats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 HostRxDesc rxfids[MPI_MAX_FIDS]; // rx/tx/config MPI350 descriptors
1187 HostTxDesc txfids[MPI_MAX_FIDS];
1188 HostRidDesc config_desc;
1189 unsigned long ridbus; // phys addr of config_desc
1190 struct sk_buff_head txq;// tx queue used by mpi350 code
1191 struct pci_dev *pci;
1192 unsigned char __iomem *pcimem;
1193 unsigned char __iomem *pciaux;
1194 unsigned char *shared;
1195 dma_addr_t shared_dma;
Pavel Machek1cc68ae2005-06-20 15:33:04 -07001196 pm_message_t power;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 SsidRid *SSID;
1198 APListRid *APList;
1199#define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE
1200 char proc_name[IFNAMSIZ];
1201};
1202
1203static inline int bap_read(struct airo_info *ai, u16 *pu16Dst, int bytelen,
1204 int whichbap) {
1205 return ai->bap_read(ai, pu16Dst, bytelen, whichbap);
1206}
1207
1208static int setup_proc_entry( struct net_device *dev,
1209 struct airo_info *apriv );
1210static int takedown_proc_entry( struct net_device *dev,
1211 struct airo_info *apriv );
1212
Jouni Malinenff1d2762005-05-12 22:54:16 -04001213static int cmdreset(struct airo_info *ai);
1214static int setflashmode (struct airo_info *ai);
1215static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime);
1216static int flashputbuf(struct airo_info *ai);
1217static int flashrestart(struct airo_info *ai,struct net_device *dev);
1218
Dan Williams934d8bf2006-03-16 13:46:23 -05001219#define airo_print(type, name, fmt, args...) \
1220 { printk(type "airo(%s): " fmt "\n", name, ##args); }
1221
1222#define airo_print_info(name, fmt, args...) \
1223 airo_print(KERN_INFO, name, fmt, ##args)
1224
1225#define airo_print_dbg(name, fmt, args...) \
1226 airo_print(KERN_DEBUG, name, fmt, ##args)
1227
1228#define airo_print_warn(name, fmt, args...) \
1229 airo_print(KERN_WARNING, name, fmt, ##args)
1230
1231#define airo_print_err(name, fmt, args...) \
1232 airo_print(KERN_ERR, name, fmt, ##args)
1233
1234
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235/***********************************************************************
1236 * MIC ROUTINES *
1237 ***********************************************************************
1238 */
1239
1240static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq);
1241static void MoveWindow(miccntx *context, u32 micSeq);
Jouni Malinenff1d2762005-05-12 22:54:16 -04001242static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *);
1243static void emmh32_init(emmh32_context *context);
1244static void emmh32_update(emmh32_context *context, u8 *pOctets, int len);
1245static void emmh32_final(emmh32_context *context, u8 digest[4]);
1246static int flashpchar(struct airo_info *ai,int byte,int dwelltime);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
1248/* micinit - Initialize mic seed */
1249
1250static void micinit(struct airo_info *ai)
1251{
1252 MICRid mic_rid;
1253
1254 clear_bit(JOB_MIC, &ai->flags);
1255 PC4500_readrid(ai, RID_MIC, &mic_rid, sizeof(mic_rid), 0);
1256 up(&ai->sem);
1257
1258 ai->micstats.enabled = (mic_rid.state & 0x00FF) ? 1 : 0;
1259
1260 if (ai->micstats.enabled) {
1261 /* Key must be valid and different */
1262 if (mic_rid.multicastValid && (!ai->mod[0].mCtx.valid ||
1263 (memcmp (ai->mod[0].mCtx.key, mic_rid.multicast,
1264 sizeof(ai->mod[0].mCtx.key)) != 0))) {
1265 /* Age current mic Context */
1266 memcpy(&ai->mod[1].mCtx,&ai->mod[0].mCtx,sizeof(miccntx));
1267 /* Initialize new context */
1268 memcpy(&ai->mod[0].mCtx.key,mic_rid.multicast,sizeof(mic_rid.multicast));
1269 ai->mod[0].mCtx.window = 33; //Window always points to the middle
1270 ai->mod[0].mCtx.rx = 0; //Rx Sequence numbers
1271 ai->mod[0].mCtx.tx = 0; //Tx sequence numbers
1272 ai->mod[0].mCtx.valid = 1; //Key is now valid
1273
1274 /* Give key to mic seed */
1275 emmh32_setseed(&ai->mod[0].mCtx.seed,mic_rid.multicast,sizeof(mic_rid.multicast), ai->tfm);
1276 }
1277
1278 /* Key must be valid and different */
1279 if (mic_rid.unicastValid && (!ai->mod[0].uCtx.valid ||
1280 (memcmp(ai->mod[0].uCtx.key, mic_rid.unicast,
1281 sizeof(ai->mod[0].uCtx.key)) != 0))) {
1282 /* Age current mic Context */
1283 memcpy(&ai->mod[1].uCtx,&ai->mod[0].uCtx,sizeof(miccntx));
1284 /* Initialize new context */
1285 memcpy(&ai->mod[0].uCtx.key,mic_rid.unicast,sizeof(mic_rid.unicast));
1286
1287 ai->mod[0].uCtx.window = 33; //Window always points to the middle
1288 ai->mod[0].uCtx.rx = 0; //Rx Sequence numbers
1289 ai->mod[0].uCtx.tx = 0; //Tx sequence numbers
1290 ai->mod[0].uCtx.valid = 1; //Key is now valid
1291
1292 //Give key to mic seed
1293 emmh32_setseed(&ai->mod[0].uCtx.seed, mic_rid.unicast, sizeof(mic_rid.unicast), ai->tfm);
1294 }
1295 } else {
1296 /* So next time we have a valid key and mic is enabled, we will update
1297 * the sequence number if the key is the same as before.
1298 */
1299 ai->mod[0].uCtx.valid = 0;
1300 ai->mod[0].mCtx.valid = 0;
1301 }
1302}
1303
1304/* micsetup - Get ready for business */
1305
1306static int micsetup(struct airo_info *ai) {
1307 int i;
1308
1309 if (ai->tfm == NULL)
Herbert Xueb6f1162005-09-01 17:43:25 -07001310 ai->tfm = crypto_alloc_tfm("aes", CRYPTO_TFM_REQ_MAY_SLEEP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
1312 if (ai->tfm == NULL) {
Dan Williams934d8bf2006-03-16 13:46:23 -05001313 airo_print_err(ai->dev->name, "failed to load transform for AES");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 return ERROR;
1315 }
1316
1317 for (i=0; i < NUM_MODULES; i++) {
1318 memset(&ai->mod[i].mCtx,0,sizeof(miccntx));
1319 memset(&ai->mod[i].uCtx,0,sizeof(miccntx));
1320 }
1321 return SUCCESS;
1322}
1323
Jouni Malinenff1d2762005-05-12 22:54:16 -04001324static char micsnap[] = {0xAA,0xAA,0x03,0x00,0x40,0x96,0x00,0x02};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
1326/*===========================================================================
1327 * Description: Mic a packet
1328 *
1329 * Inputs: etherHead * pointer to an 802.3 frame
1330 *
1331 * Returns: BOOLEAN if successful, otherwise false.
1332 * PacketTxLen will be updated with the mic'd packets size.
1333 *
1334 * Caveats: It is assumed that the frame buffer will already
1335 * be big enough to hold the largets mic message possible.
1336 * (No memory allocation is done here).
1337 *
1338 * Author: sbraneky (10/15/01)
1339 * Merciless hacks by rwilcher (1/14/02)
1340 */
1341
1342static int encapsulate(struct airo_info *ai ,etherHead *frame, MICBuffer *mic, int payLen)
1343{
1344 miccntx *context;
1345
1346 // Determine correct context
1347 // If not adhoc, always use unicast key
1348
1349 if (test_bit(FLAG_ADHOC, &ai->flags) && (frame->da[0] & 0x1))
1350 context = &ai->mod[0].mCtx;
1351 else
1352 context = &ai->mod[0].uCtx;
1353
1354 if (!context->valid)
1355 return ERROR;
1356
1357 mic->typelen = htons(payLen + 16); //Length of Mic'd packet
1358
1359 memcpy(&mic->u.snap, micsnap, sizeof(micsnap)); // Add Snap
1360
1361 // Add Tx sequence
1362 mic->seq = htonl(context->tx);
1363 context->tx += 2;
1364
1365 emmh32_init(&context->seed); // Mic the packet
1366 emmh32_update(&context->seed,frame->da,ETH_ALEN * 2); // DA,SA
1367 emmh32_update(&context->seed,(u8*)&mic->typelen,10); // Type/Length and Snap
1368 emmh32_update(&context->seed,(u8*)&mic->seq,sizeof(mic->seq)); //SEQ
1369 emmh32_update(&context->seed,frame->da + ETH_ALEN * 2,payLen); //payload
1370 emmh32_final(&context->seed, (u8*)&mic->mic);
1371
1372 /* New Type/length ?????????? */
1373 mic->typelen = 0; //Let NIC know it could be an oversized packet
1374 return SUCCESS;
1375}
1376
1377typedef enum {
1378 NONE,
1379 NOMIC,
1380 NOMICPLUMMED,
1381 SEQUENCE,
1382 INCORRECTMIC,
1383} mic_error;
1384
1385/*===========================================================================
1386 * Description: Decapsulates a MIC'd packet and returns the 802.3 packet
1387 * (removes the MIC stuff) if packet is a valid packet.
1388 *
1389 * Inputs: etherHead pointer to the 802.3 packet
1390 *
1391 * Returns: BOOLEAN - TRUE if packet should be dropped otherwise FALSE
1392 *
1393 * Author: sbraneky (10/15/01)
1394 * Merciless hacks by rwilcher (1/14/02)
1395 *---------------------------------------------------------------------------
1396 */
1397
1398static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *eth, u16 payLen)
1399{
1400 int i;
1401 u32 micSEQ;
1402 miccntx *context;
1403 u8 digest[4];
1404 mic_error micError = NONE;
1405
1406 // Check if the packet is a Mic'd packet
1407
1408 if (!ai->micstats.enabled) {
1409 //No Mic set or Mic OFF but we received a MIC'd packet.
1410 if (memcmp ((u8*)eth + 14, micsnap, sizeof(micsnap)) == 0) {
1411 ai->micstats.rxMICPlummed++;
1412 return ERROR;
1413 }
1414 return SUCCESS;
1415 }
1416
1417 if (ntohs(mic->typelen) == 0x888E)
1418 return SUCCESS;
1419
1420 if (memcmp (mic->u.snap, micsnap, sizeof(micsnap)) != 0) {
1421 // Mic enabled but packet isn't Mic'd
1422 ai->micstats.rxMICPlummed++;
1423 return ERROR;
1424 }
1425
1426 micSEQ = ntohl(mic->seq); //store SEQ as CPU order
1427
1428 //At this point we a have a mic'd packet and mic is enabled
1429 //Now do the mic error checking.
1430
1431 //Receive seq must be odd
1432 if ( (micSEQ & 1) == 0 ) {
1433 ai->micstats.rxWrongSequence++;
1434 return ERROR;
1435 }
1436
1437 for (i = 0; i < NUM_MODULES; i++) {
1438 int mcast = eth->da[0] & 1;
1439 //Determine proper context
1440 context = mcast ? &ai->mod[i].mCtx : &ai->mod[i].uCtx;
1441
1442 //Make sure context is valid
1443 if (!context->valid) {
1444 if (i == 0)
1445 micError = NOMICPLUMMED;
1446 continue;
1447 }
1448 //DeMic it
1449
1450 if (!mic->typelen)
1451 mic->typelen = htons(payLen + sizeof(MICBuffer) - 2);
1452
1453 emmh32_init(&context->seed);
1454 emmh32_update(&context->seed, eth->da, ETH_ALEN*2);
1455 emmh32_update(&context->seed, (u8 *)&mic->typelen, sizeof(mic->typelen)+sizeof(mic->u.snap));
1456 emmh32_update(&context->seed, (u8 *)&mic->seq,sizeof(mic->seq));
1457 emmh32_update(&context->seed, eth->da + ETH_ALEN*2,payLen);
1458 //Calculate MIC
1459 emmh32_final(&context->seed, digest);
1460
1461 if (memcmp(digest, &mic->mic, 4)) { //Make sure the mics match
1462 //Invalid Mic
1463 if (i == 0)
1464 micError = INCORRECTMIC;
1465 continue;
1466 }
1467
1468 //Check Sequence number if mics pass
1469 if (RxSeqValid(ai, context, mcast, micSEQ) == SUCCESS) {
1470 ai->micstats.rxSuccess++;
1471 return SUCCESS;
1472 }
1473 if (i == 0)
1474 micError = SEQUENCE;
1475 }
1476
1477 // Update statistics
1478 switch (micError) {
1479 case NOMICPLUMMED: ai->micstats.rxMICPlummed++; break;
1480 case SEQUENCE: ai->micstats.rxWrongSequence++; break;
1481 case INCORRECTMIC: ai->micstats.rxIncorrectMIC++; break;
1482 case NONE: break;
1483 case NOMIC: break;
1484 }
1485 return ERROR;
1486}
1487
1488/*===========================================================================
1489 * Description: Checks the Rx Seq number to make sure it is valid
1490 * and hasn't already been received
1491 *
1492 * Inputs: miccntx - mic context to check seq against
1493 * micSeq - the Mic seq number
1494 *
1495 * Returns: TRUE if valid otherwise FALSE.
1496 *
1497 * Author: sbraneky (10/15/01)
1498 * Merciless hacks by rwilcher (1/14/02)
1499 *---------------------------------------------------------------------------
1500 */
1501
1502static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq)
1503{
1504 u32 seq,index;
1505
1506 //Allow for the ap being rebooted - if it is then use the next
1507 //sequence number of the current sequence number - might go backwards
1508
1509 if (mcast) {
1510 if (test_bit(FLAG_UPDATE_MULTI, &ai->flags)) {
1511 clear_bit (FLAG_UPDATE_MULTI, &ai->flags);
1512 context->window = (micSeq > 33) ? micSeq : 33;
1513 context->rx = 0; // Reset rx
1514 }
1515 } else if (test_bit(FLAG_UPDATE_UNI, &ai->flags)) {
1516 clear_bit (FLAG_UPDATE_UNI, &ai->flags);
1517 context->window = (micSeq > 33) ? micSeq : 33; // Move window
1518 context->rx = 0; // Reset rx
1519 }
1520
1521 //Make sequence number relative to START of window
1522 seq = micSeq - (context->window - 33);
1523
1524 //Too old of a SEQ number to check.
1525 if ((s32)seq < 0)
1526 return ERROR;
1527
1528 if ( seq > 64 ) {
1529 //Window is infinite forward
1530 MoveWindow(context,micSeq);
1531 return SUCCESS;
1532 }
1533
1534 // We are in the window. Now check the context rx bit to see if it was already sent
1535 seq >>= 1; //divide by 2 because we only have odd numbers
1536 index = 1 << seq; //Get an index number
1537
1538 if (!(context->rx & index)) {
1539 //micSEQ falls inside the window.
1540 //Add seqence number to the list of received numbers.
1541 context->rx |= index;
1542
1543 MoveWindow(context,micSeq);
1544
1545 return SUCCESS;
1546 }
1547 return ERROR;
1548}
1549
1550static void MoveWindow(miccntx *context, u32 micSeq)
1551{
1552 u32 shift;
1553
1554 //Move window if seq greater than the middle of the window
1555 if (micSeq > context->window) {
1556 shift = (micSeq - context->window) >> 1;
1557
1558 //Shift out old
1559 if (shift < 32)
1560 context->rx >>= shift;
1561 else
1562 context->rx = 0;
1563
1564 context->window = micSeq; //Move window
1565 }
1566}
1567
1568/*==============================================*/
1569/*========== EMMH ROUTINES ====================*/
1570/*==============================================*/
1571
1572/* mic accumulate */
1573#define MIC_ACCUM(val) \
1574 context->accum += (u64)(val) * context->coeff[coeff_position++];
1575
1576static unsigned char aes_counter[16];
1577
1578/* expand the key to fill the MMH coefficient array */
Jouni Malinenff1d2762005-05-12 22:54:16 -04001579static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *tfm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580{
1581 /* take the keying material, expand if necessary, truncate at 16-bytes */
1582 /* run through AES counter mode to generate context->coeff[] */
1583
1584 int i,j;
1585 u32 counter;
1586 u8 *cipher, plain[16];
1587 struct scatterlist sg[1];
1588
1589 crypto_cipher_setkey(tfm, pkey, 16);
1590 counter = 0;
1591 for (i = 0; i < (sizeof(context->coeff)/sizeof(context->coeff[0])); ) {
1592 aes_counter[15] = (u8)(counter >> 0);
1593 aes_counter[14] = (u8)(counter >> 8);
1594 aes_counter[13] = (u8)(counter >> 16);
1595 aes_counter[12] = (u8)(counter >> 24);
1596 counter++;
1597 memcpy (plain, aes_counter, 16);
Herbert Xu6df5b9f2005-09-19 22:30:11 +10001598 sg_set_buf(sg, plain, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 crypto_cipher_encrypt(tfm, sg, sg, 16);
Herbert Xu6df5b9f2005-09-19 22:30:11 +10001600 cipher = kmap(sg->page) + sg->offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 for (j=0; (j<16) && (i< (sizeof(context->coeff)/sizeof(context->coeff[0]))); ) {
1602 context->coeff[i++] = ntohl(*(u32 *)&cipher[j]);
1603 j += 4;
1604 }
1605 }
1606}
1607
1608/* prepare for calculation of a new mic */
Jouni Malinenff1d2762005-05-12 22:54:16 -04001609static void emmh32_init(emmh32_context *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610{
1611 /* prepare for new mic calculation */
1612 context->accum = 0;
1613 context->position = 0;
1614}
1615
1616/* add some bytes to the mic calculation */
Jouni Malinenff1d2762005-05-12 22:54:16 -04001617static void emmh32_update(emmh32_context *context, u8 *pOctets, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618{
1619 int coeff_position, byte_position;
1620
1621 if (len == 0) return;
1622
1623 coeff_position = context->position >> 2;
1624
1625 /* deal with partial 32-bit word left over from last update */
1626 byte_position = context->position & 3;
1627 if (byte_position) {
1628 /* have a partial word in part to deal with */
1629 do {
1630 if (len == 0) return;
1631 context->part.d8[byte_position++] = *pOctets++;
1632 context->position++;
1633 len--;
1634 } while (byte_position < 4);
1635 MIC_ACCUM(htonl(context->part.d32));
1636 }
1637
1638 /* deal with full 32-bit words */
1639 while (len >= 4) {
1640 MIC_ACCUM(htonl(*(u32 *)pOctets));
1641 context->position += 4;
1642 pOctets += 4;
1643 len -= 4;
1644 }
1645
1646 /* deal with partial 32-bit word that will be left over from this update */
1647 byte_position = 0;
1648 while (len > 0) {
1649 context->part.d8[byte_position++] = *pOctets++;
1650 context->position++;
1651 len--;
1652 }
1653}
1654
1655/* mask used to zero empty bytes for final partial word */
1656static u32 mask32[4] = { 0x00000000L, 0xFF000000L, 0xFFFF0000L, 0xFFFFFF00L };
1657
1658/* calculate the mic */
Jouni Malinenff1d2762005-05-12 22:54:16 -04001659static void emmh32_final(emmh32_context *context, u8 digest[4])
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660{
1661 int coeff_position, byte_position;
1662 u32 val;
1663
1664 u64 sum, utmp;
1665 s64 stmp;
1666
1667 coeff_position = context->position >> 2;
1668
1669 /* deal with partial 32-bit word left over from last update */
1670 byte_position = context->position & 3;
1671 if (byte_position) {
1672 /* have a partial word in part to deal with */
1673 val = htonl(context->part.d32);
1674 MIC_ACCUM(val & mask32[byte_position]); /* zero empty bytes */
1675 }
1676
1677 /* reduce the accumulated u64 to a 32-bit MIC */
1678 sum = context->accum;
1679 stmp = (sum & 0xffffffffLL) - ((sum >> 32) * 15);
1680 utmp = (stmp & 0xffffffffLL) - ((stmp >> 32) * 15);
1681 sum = utmp & 0xffffffffLL;
1682 if (utmp > 0x10000000fLL)
1683 sum -= 15;
1684
1685 val = (u32)sum;
1686 digest[0] = (val>>24) & 0xFF;
1687 digest[1] = (val>>16) & 0xFF;
1688 digest[2] = (val>>8) & 0xFF;
1689 digest[3] = val & 0xFF;
1690}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691
1692static int readBSSListRid(struct airo_info *ai, int first,
1693 BSSListRid *list) {
1694 int rc;
1695 Cmd cmd;
1696 Resp rsp;
1697
1698 if (first == 1) {
1699 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
1700 memset(&cmd, 0, sizeof(cmd));
1701 cmd.cmd=CMD_LISTBSS;
1702 if (down_interruptible(&ai->sem))
1703 return -ERESTARTSYS;
1704 issuecommand(ai, &cmd, &rsp);
1705 up(&ai->sem);
1706 /* Let the command take effect */
1707 ai->task = current;
1708 ssleep(3);
1709 ai->task = NULL;
1710 }
1711 rc = PC4500_readrid(ai, first ? RID_BSSLISTFIRST : RID_BSSLISTNEXT,
1712 list, sizeof(*list), 1);
1713
1714 list->len = le16_to_cpu(list->len);
1715 list->index = le16_to_cpu(list->index);
1716 list->radioType = le16_to_cpu(list->radioType);
1717 list->cap = le16_to_cpu(list->cap);
1718 list->beaconInterval = le16_to_cpu(list->beaconInterval);
1719 list->fh.dwell = le16_to_cpu(list->fh.dwell);
1720 list->dsChannel = le16_to_cpu(list->dsChannel);
1721 list->atimWindow = le16_to_cpu(list->atimWindow);
Dan Williams41480af2005-05-10 09:45:51 -04001722 list->dBm = le16_to_cpu(list->dBm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 return rc;
1724}
1725
1726static int readWepKeyRid(struct airo_info*ai, WepKeyRid *wkr, int temp, int lock) {
1727 int rc = PC4500_readrid(ai, temp ? RID_WEP_TEMP : RID_WEP_PERM,
1728 wkr, sizeof(*wkr), lock);
1729
1730 wkr->len = le16_to_cpu(wkr->len);
1731 wkr->kindex = le16_to_cpu(wkr->kindex);
1732 wkr->klen = le16_to_cpu(wkr->klen);
1733 return rc;
1734}
1735/* In the writeXXXRid routines we copy the rids so that we don't screwup
1736 * the originals when we endian them... */
1737static int writeWepKeyRid(struct airo_info*ai, WepKeyRid *pwkr, int perm, int lock) {
1738 int rc;
1739 WepKeyRid wkr = *pwkr;
1740
1741 wkr.len = cpu_to_le16(wkr.len);
1742 wkr.kindex = cpu_to_le16(wkr.kindex);
1743 wkr.klen = cpu_to_le16(wkr.klen);
1744 rc = PC4500_writerid(ai, RID_WEP_TEMP, &wkr, sizeof(wkr), lock);
Dan Williams934d8bf2006-03-16 13:46:23 -05001745 if (rc!=SUCCESS) airo_print_err(ai->dev->name, "WEP_TEMP set %x", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 if (perm) {
1747 rc = PC4500_writerid(ai, RID_WEP_PERM, &wkr, sizeof(wkr), lock);
1748 if (rc!=SUCCESS) {
Dan Williams934d8bf2006-03-16 13:46:23 -05001749 airo_print_err(ai->dev->name, "WEP_PERM set %x", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 }
1751 }
1752 return rc;
1753}
1754
1755static int readSsidRid(struct airo_info*ai, SsidRid *ssidr) {
1756 int i;
1757 int rc = PC4500_readrid(ai, RID_SSID, ssidr, sizeof(*ssidr), 1);
1758
1759 ssidr->len = le16_to_cpu(ssidr->len);
1760 for(i = 0; i < 3; i++) {
1761 ssidr->ssids[i].len = le16_to_cpu(ssidr->ssids[i].len);
1762 }
1763 return rc;
1764}
1765static int writeSsidRid(struct airo_info*ai, SsidRid *pssidr, int lock) {
1766 int rc;
1767 int i;
1768 SsidRid ssidr = *pssidr;
1769
1770 ssidr.len = cpu_to_le16(ssidr.len);
1771 for(i = 0; i < 3; i++) {
1772 ssidr.ssids[i].len = cpu_to_le16(ssidr.ssids[i].len);
1773 }
1774 rc = PC4500_writerid(ai, RID_SSID, &ssidr, sizeof(ssidr), lock);
1775 return rc;
1776}
1777static int readConfigRid(struct airo_info*ai, int lock) {
1778 int rc;
1779 u16 *s;
1780 ConfigRid cfg;
1781
1782 if (ai->config.len)
1783 return SUCCESS;
1784
1785 rc = PC4500_readrid(ai, RID_ACTUALCONFIG, &cfg, sizeof(cfg), lock);
1786 if (rc != SUCCESS)
1787 return rc;
1788
1789 for(s = &cfg.len; s <= &cfg.rtsThres; s++) *s = le16_to_cpu(*s);
1790
1791 for(s = &cfg.shortRetryLimit; s <= &cfg.radioType; s++)
1792 *s = le16_to_cpu(*s);
1793
1794 for(s = &cfg.txPower; s <= &cfg.radioSpecific; s++)
1795 *s = le16_to_cpu(*s);
1796
1797 for(s = &cfg.arlThreshold; s <= &cfg._reserved4[0]; s++)
1798 *s = cpu_to_le16(*s);
1799
1800 for(s = &cfg.autoWake; s <= &cfg.autoWake; s++)
1801 *s = cpu_to_le16(*s);
1802
1803 ai->config = cfg;
1804 return SUCCESS;
1805}
1806static inline void checkThrottle(struct airo_info *ai) {
1807 int i;
1808/* Old hardware had a limit on encryption speed */
1809 if (ai->config.authType != AUTH_OPEN && maxencrypt) {
1810 for(i=0; i<8; i++) {
1811 if (ai->config.rates[i] > maxencrypt) {
1812 ai->config.rates[i] = 0;
1813 }
1814 }
1815 }
1816}
1817static int writeConfigRid(struct airo_info*ai, int lock) {
1818 u16 *s;
1819 ConfigRid cfgr;
1820
1821 if (!test_bit (FLAG_COMMIT, &ai->flags))
1822 return SUCCESS;
1823
1824 clear_bit (FLAG_COMMIT, &ai->flags);
1825 clear_bit (FLAG_RESET, &ai->flags);
1826 checkThrottle(ai);
1827 cfgr = ai->config;
1828
1829 if ((cfgr.opmode & 0xFF) == MODE_STA_IBSS)
1830 set_bit(FLAG_ADHOC, &ai->flags);
1831 else
1832 clear_bit(FLAG_ADHOC, &ai->flags);
1833
1834 for(s = &cfgr.len; s <= &cfgr.rtsThres; s++) *s = cpu_to_le16(*s);
1835
1836 for(s = &cfgr.shortRetryLimit; s <= &cfgr.radioType; s++)
1837 *s = cpu_to_le16(*s);
1838
1839 for(s = &cfgr.txPower; s <= &cfgr.radioSpecific; s++)
1840 *s = cpu_to_le16(*s);
1841
1842 for(s = &cfgr.arlThreshold; s <= &cfgr._reserved4[0]; s++)
1843 *s = cpu_to_le16(*s);
1844
1845 for(s = &cfgr.autoWake; s <= &cfgr.autoWake; s++)
1846 *s = cpu_to_le16(*s);
1847
1848 return PC4500_writerid( ai, RID_CONFIG, &cfgr, sizeof(cfgr), lock);
1849}
1850static int readStatusRid(struct airo_info*ai, StatusRid *statr, int lock) {
1851 int rc = PC4500_readrid(ai, RID_STATUS, statr, sizeof(*statr), lock);
1852 u16 *s;
1853
1854 statr->len = le16_to_cpu(statr->len);
1855 for(s = &statr->mode; s <= &statr->SSIDlen; s++) *s = le16_to_cpu(*s);
1856
1857 for(s = &statr->beaconPeriod; s <= &statr->shortPreamble; s++)
1858 *s = le16_to_cpu(*s);
1859 statr->load = le16_to_cpu(statr->load);
1860 statr->assocStatus = le16_to_cpu(statr->assocStatus);
1861 return rc;
1862}
1863static int readAPListRid(struct airo_info*ai, APListRid *aplr) {
1864 int rc = PC4500_readrid(ai, RID_APLIST, aplr, sizeof(*aplr), 1);
1865 aplr->len = le16_to_cpu(aplr->len);
1866 return rc;
1867}
1868static int writeAPListRid(struct airo_info*ai, APListRid *aplr, int lock) {
1869 int rc;
1870 aplr->len = cpu_to_le16(aplr->len);
1871 rc = PC4500_writerid(ai, RID_APLIST, aplr, sizeof(*aplr), lock);
1872 return rc;
1873}
1874static int readCapabilityRid(struct airo_info*ai, CapabilityRid *capr, int lock) {
1875 int rc = PC4500_readrid(ai, RID_CAPABILITIES, capr, sizeof(*capr), lock);
1876 u16 *s;
1877
1878 capr->len = le16_to_cpu(capr->len);
1879 capr->prodNum = le16_to_cpu(capr->prodNum);
1880 capr->radioType = le16_to_cpu(capr->radioType);
1881 capr->country = le16_to_cpu(capr->country);
1882 for(s = &capr->txPowerLevels[0]; s <= &capr->requiredHard; s++)
1883 *s = le16_to_cpu(*s);
1884 return rc;
1885}
1886static int readStatsRid(struct airo_info*ai, StatsRid *sr, int rid, int lock) {
1887 int rc = PC4500_readrid(ai, rid, sr, sizeof(*sr), lock);
1888 u32 *i;
1889
1890 sr->len = le16_to_cpu(sr->len);
1891 for(i = &sr->vals[0]; i <= &sr->vals[99]; i++) *i = le32_to_cpu(*i);
1892 return rc;
1893}
1894
1895static int airo_open(struct net_device *dev) {
1896 struct airo_info *info = dev->priv;
1897 Resp rsp;
1898
1899 if (test_bit(FLAG_FLASHING, &info->flags))
1900 return -EIO;
1901
1902 /* Make sure the card is configured.
1903 * Wireless Extensions may postpone config changes until the card
1904 * is open (to pipeline changes and speed-up card setup). If
1905 * those changes are not yet commited, do it now - Jean II */
1906 if (test_bit (FLAG_COMMIT, &info->flags)) {
1907 disable_MAC(info, 1);
1908 writeConfigRid(info, 1);
1909 }
1910
1911 if (info->wifidev != dev) {
1912 /* Power on the MAC controller (which may have been disabled) */
1913 clear_bit(FLAG_RADIO_DOWN, &info->flags);
1914 enable_interrupts(info);
1915 }
1916 enable_MAC(info, &rsp, 1);
1917
1918 netif_start_queue(dev);
1919 return 0;
1920}
1921
1922static int mpi_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1923 int npacks, pending;
1924 unsigned long flags;
1925 struct airo_info *ai = dev->priv;
1926
1927 if (!skb) {
Dan Williams934d8bf2006-03-16 13:46:23 -05001928 airo_print_err(dev->name, "%s: skb == NULL!",__FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 return 0;
1930 }
1931 npacks = skb_queue_len (&ai->txq);
1932
1933 if (npacks >= MAXTXQ - 1) {
1934 netif_stop_queue (dev);
1935 if (npacks > MAXTXQ) {
1936 ai->stats.tx_fifo_errors++;
1937 return 1;
1938 }
1939 skb_queue_tail (&ai->txq, skb);
1940 return 0;
1941 }
1942
1943 spin_lock_irqsave(&ai->aux_lock, flags);
1944 skb_queue_tail (&ai->txq, skb);
1945 pending = test_bit(FLAG_PENDING_XMIT, &ai->flags);
1946 spin_unlock_irqrestore(&ai->aux_lock,flags);
1947 netif_wake_queue (dev);
1948
1949 if (pending == 0) {
1950 set_bit(FLAG_PENDING_XMIT, &ai->flags);
1951 mpi_send_packet (dev);
1952 }
1953 return 0;
1954}
1955
1956/*
1957 * @mpi_send_packet
1958 *
1959 * Attempt to transmit a packet. Can be called from interrupt
1960 * or transmit . return number of packets we tried to send
1961 */
1962
1963static int mpi_send_packet (struct net_device *dev)
1964{
1965 struct sk_buff *skb;
1966 unsigned char *buffer;
1967 s16 len, *payloadLen;
1968 struct airo_info *ai = dev->priv;
1969 u8 *sendbuf;
1970
1971 /* get a packet to send */
1972
1973 if ((skb = skb_dequeue(&ai->txq)) == 0) {
Dan Williams934d8bf2006-03-16 13:46:23 -05001974 airo_print_err(dev->name,
1975 "%s: Dequeue'd zero in send_packet()",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 __FUNCTION__);
1977 return 0;
1978 }
1979
1980 /* check min length*/
1981 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1982 buffer = skb->data;
1983
1984 ai->txfids[0].tx_desc.offset = 0;
1985 ai->txfids[0].tx_desc.valid = 1;
1986 ai->txfids[0].tx_desc.eoc = 1;
1987 ai->txfids[0].tx_desc.len =len+sizeof(WifiHdr);
1988
1989/*
1990 * Magic, the cards firmware needs a length count (2 bytes) in the host buffer
1991 * right after TXFID_HDR.The TXFID_HDR contains the status short so payloadlen
1992 * is immediatly after it. ------------------------------------------------
1993 * |TXFIDHDR+STATUS|PAYLOADLEN|802.3HDR|PACKETDATA|
1994 * ------------------------------------------------
1995 */
1996
1997 memcpy((char *)ai->txfids[0].virtual_host_addr,
1998 (char *)&wifictlhdr8023, sizeof(wifictlhdr8023));
1999
2000 payloadLen = (s16 *)(ai->txfids[0].virtual_host_addr +
2001 sizeof(wifictlhdr8023));
2002 sendbuf = ai->txfids[0].virtual_host_addr +
2003 sizeof(wifictlhdr8023) + 2 ;
2004
2005 /*
2006 * Firmware automaticly puts 802 header on so
2007 * we don't need to account for it in the length
2008 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
2010 (ntohs(((u16 *)buffer)[6]) != 0x888E)) {
2011 MICBuffer pMic;
2012
2013 if (encapsulate(ai, (etherHead *)buffer, &pMic, len - sizeof(etherHead)) != SUCCESS)
2014 return ERROR;
2015
2016 *payloadLen = cpu_to_le16(len-sizeof(etherHead)+sizeof(pMic));
2017 ai->txfids[0].tx_desc.len += sizeof(pMic);
2018 /* copy data into airo dma buffer */
2019 memcpy (sendbuf, buffer, sizeof(etherHead));
2020 buffer += sizeof(etherHead);
2021 sendbuf += sizeof(etherHead);
2022 memcpy (sendbuf, &pMic, sizeof(pMic));
2023 sendbuf += sizeof(pMic);
2024 memcpy (sendbuf, buffer, len - sizeof(etherHead));
Adrian Bunka39d3e72006-01-21 01:35:15 +01002025 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 *payloadLen = cpu_to_le16(len - sizeof(etherHead));
2027
2028 dev->trans_start = jiffies;
2029
2030 /* copy data into airo dma buffer */
2031 memcpy(sendbuf, buffer, len);
2032 }
2033
2034 memcpy_toio(ai->txfids[0].card_ram_off,
2035 &ai->txfids[0].tx_desc, sizeof(TxFid));
2036
2037 OUT4500(ai, EVACK, 8);
2038
2039 dev_kfree_skb_any(skb);
2040 return 1;
2041}
2042
Gabriel A. Devenyi29b09fc2005-11-03 19:30:47 -05002043static void get_tx_error(struct airo_info *ai, s32 fid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044{
2045 u16 status;
2046
2047 if (fid < 0)
2048 status = ((WifiCtlHdr *)ai->txfids[0].virtual_host_addr)->ctlhdr.status;
2049 else {
2050 if (bap_setup(ai, ai->fids[fid] & 0xffff, 4, BAP0) != SUCCESS)
2051 return;
2052 bap_read(ai, &status, 2, BAP0);
2053 }
2054 if (le16_to_cpu(status) & 2) /* Too many retries */
2055 ai->stats.tx_aborted_errors++;
2056 if (le16_to_cpu(status) & 4) /* Transmit lifetime exceeded */
2057 ai->stats.tx_heartbeat_errors++;
2058 if (le16_to_cpu(status) & 8) /* Aid fail */
2059 { }
2060 if (le16_to_cpu(status) & 0x10) /* MAC disabled */
2061 ai->stats.tx_carrier_errors++;
2062 if (le16_to_cpu(status) & 0x20) /* Association lost */
2063 { }
2064 /* We produce a TXDROP event only for retry or lifetime
2065 * exceeded, because that's the only status that really mean
2066 * that this particular node went away.
2067 * Other errors means that *we* screwed up. - Jean II */
2068 if ((le16_to_cpu(status) & 2) ||
2069 (le16_to_cpu(status) & 4)) {
2070 union iwreq_data wrqu;
2071 char junk[0x18];
2072
2073 /* Faster to skip over useless data than to do
2074 * another bap_setup(). We are at offset 0x6 and
2075 * need to go to 0x18 and read 6 bytes - Jean II */
2076 bap_read(ai, (u16 *) junk, 0x18, BAP0);
2077
2078 /* Copy 802.11 dest address.
2079 * We use the 802.11 header because the frame may
2080 * not be 802.3 or may be mangled...
2081 * In Ad-Hoc mode, it will be the node address.
2082 * In managed mode, it will be most likely the AP addr
2083 * User space will figure out how to convert it to
2084 * whatever it needs (IP address or else).
2085 * - Jean II */
2086 memcpy(wrqu.addr.sa_data, junk + 0x12, ETH_ALEN);
2087 wrqu.addr.sa_family = ARPHRD_ETHER;
2088
2089 /* Send event to user space */
2090 wireless_send_event(ai->dev, IWEVTXDROP, &wrqu, NULL);
2091 }
2092}
2093
2094static void airo_end_xmit(struct net_device *dev) {
2095 u16 status;
2096 int i;
2097 struct airo_info *priv = dev->priv;
2098 struct sk_buff *skb = priv->xmit.skb;
2099 int fid = priv->xmit.fid;
2100 u32 *fids = priv->fids;
2101
2102 clear_bit(JOB_XMIT, &priv->flags);
2103 clear_bit(FLAG_PENDING_XMIT, &priv->flags);
2104 status = transmit_802_3_packet (priv, fids[fid], skb->data);
2105 up(&priv->sem);
2106
2107 i = 0;
2108 if ( status == SUCCESS ) {
2109 dev->trans_start = jiffies;
2110 for (; i < MAX_FIDS / 2 && (priv->fids[i] & 0xffff0000); i++);
2111 } else {
2112 priv->fids[fid] &= 0xffff;
2113 priv->stats.tx_window_errors++;
2114 }
2115 if (i < MAX_FIDS / 2)
2116 netif_wake_queue(dev);
2117 dev_kfree_skb(skb);
2118}
2119
2120static int airo_start_xmit(struct sk_buff *skb, struct net_device *dev) {
2121 s16 len;
2122 int i, j;
2123 struct airo_info *priv = dev->priv;
2124 u32 *fids = priv->fids;
2125
2126 if ( skb == NULL ) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002127 airo_print_err(dev->name, "%s: skb == NULL!", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 return 0;
2129 }
2130
2131 /* Find a vacant FID */
2132 for( i = 0; i < MAX_FIDS / 2 && (fids[i] & 0xffff0000); i++ );
2133 for( j = i + 1; j < MAX_FIDS / 2 && (fids[j] & 0xffff0000); j++ );
2134
2135 if ( j >= MAX_FIDS / 2 ) {
2136 netif_stop_queue(dev);
2137
2138 if (i == MAX_FIDS / 2) {
2139 priv->stats.tx_fifo_errors++;
2140 return 1;
2141 }
2142 }
2143 /* check min length*/
2144 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
2145 /* Mark fid as used & save length for later */
2146 fids[i] |= (len << 16);
2147 priv->xmit.skb = skb;
2148 priv->xmit.fid = i;
2149 if (down_trylock(&priv->sem) != 0) {
2150 set_bit(FLAG_PENDING_XMIT, &priv->flags);
2151 netif_stop_queue(dev);
2152 set_bit(JOB_XMIT, &priv->flags);
2153 wake_up_interruptible(&priv->thr_wait);
2154 } else
2155 airo_end_xmit(dev);
2156 return 0;
2157}
2158
2159static void airo_end_xmit11(struct net_device *dev) {
2160 u16 status;
2161 int i;
2162 struct airo_info *priv = dev->priv;
2163 struct sk_buff *skb = priv->xmit11.skb;
2164 int fid = priv->xmit11.fid;
2165 u32 *fids = priv->fids;
2166
2167 clear_bit(JOB_XMIT11, &priv->flags);
2168 clear_bit(FLAG_PENDING_XMIT11, &priv->flags);
2169 status = transmit_802_11_packet (priv, fids[fid], skb->data);
2170 up(&priv->sem);
2171
2172 i = MAX_FIDS / 2;
2173 if ( status == SUCCESS ) {
2174 dev->trans_start = jiffies;
2175 for (; i < MAX_FIDS && (priv->fids[i] & 0xffff0000); i++);
2176 } else {
2177 priv->fids[fid] &= 0xffff;
2178 priv->stats.tx_window_errors++;
2179 }
2180 if (i < MAX_FIDS)
2181 netif_wake_queue(dev);
2182 dev_kfree_skb(skb);
2183}
2184
2185static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) {
2186 s16 len;
2187 int i, j;
2188 struct airo_info *priv = dev->priv;
2189 u32 *fids = priv->fids;
2190
2191 if (test_bit(FLAG_MPI, &priv->flags)) {
2192 /* Not implemented yet for MPI350 */
2193 netif_stop_queue(dev);
2194 return -ENETDOWN;
2195 }
2196
2197 if ( skb == NULL ) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002198 airo_print_err(dev->name, "%s: skb == NULL!", __FUNCTION__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 return 0;
2200 }
2201
2202 /* Find a vacant FID */
2203 for( i = MAX_FIDS / 2; i < MAX_FIDS && (fids[i] & 0xffff0000); i++ );
2204 for( j = i + 1; j < MAX_FIDS && (fids[j] & 0xffff0000); j++ );
2205
2206 if ( j >= MAX_FIDS ) {
2207 netif_stop_queue(dev);
2208
2209 if (i == MAX_FIDS) {
2210 priv->stats.tx_fifo_errors++;
2211 return 1;
2212 }
2213 }
2214 /* check min length*/
2215 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
2216 /* Mark fid as used & save length for later */
2217 fids[i] |= (len << 16);
2218 priv->xmit11.skb = skb;
2219 priv->xmit11.fid = i;
2220 if (down_trylock(&priv->sem) != 0) {
2221 set_bit(FLAG_PENDING_XMIT11, &priv->flags);
2222 netif_stop_queue(dev);
2223 set_bit(JOB_XMIT11, &priv->flags);
2224 wake_up_interruptible(&priv->thr_wait);
2225 } else
2226 airo_end_xmit11(dev);
2227 return 0;
2228}
2229
2230static void airo_read_stats(struct airo_info *ai) {
2231 StatsRid stats_rid;
2232 u32 *vals = stats_rid.vals;
2233
2234 clear_bit(JOB_STATS, &ai->flags);
Pavel Machekca078ba2005-09-03 15:56:57 -07002235 if (ai->power.event) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 up(&ai->sem);
2237 return;
2238 }
2239 readStatsRid(ai, &stats_rid, RID_STATS, 0);
2240 up(&ai->sem);
2241
2242 ai->stats.rx_packets = vals[43] + vals[44] + vals[45];
2243 ai->stats.tx_packets = vals[39] + vals[40] + vals[41];
2244 ai->stats.rx_bytes = vals[92];
2245 ai->stats.tx_bytes = vals[91];
2246 ai->stats.rx_errors = vals[0] + vals[2] + vals[3] + vals[4];
2247 ai->stats.tx_errors = vals[42] + ai->stats.tx_fifo_errors;
2248 ai->stats.multicast = vals[43];
2249 ai->stats.collisions = vals[89];
2250
2251 /* detailed rx_errors: */
2252 ai->stats.rx_length_errors = vals[3];
2253 ai->stats.rx_crc_errors = vals[4];
2254 ai->stats.rx_frame_errors = vals[2];
2255 ai->stats.rx_fifo_errors = vals[0];
2256}
2257
Jouni Malinenff1d2762005-05-12 22:54:16 -04002258static struct net_device_stats *airo_get_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259{
2260 struct airo_info *local = dev->priv;
2261
2262 if (!test_bit(JOB_STATS, &local->flags)) {
2263 /* Get stats out of the card if available */
2264 if (down_trylock(&local->sem) != 0) {
2265 set_bit(JOB_STATS, &local->flags);
2266 wake_up_interruptible(&local->thr_wait);
2267 } else
2268 airo_read_stats(local);
2269 }
2270
2271 return &local->stats;
2272}
2273
2274static void airo_set_promisc(struct airo_info *ai) {
2275 Cmd cmd;
2276 Resp rsp;
2277
2278 memset(&cmd, 0, sizeof(cmd));
2279 cmd.cmd=CMD_SETMODE;
2280 clear_bit(JOB_PROMISC, &ai->flags);
2281 cmd.parm0=(ai->flags&IFF_PROMISC) ? PROMISC : NOPROMISC;
2282 issuecommand(ai, &cmd, &rsp);
2283 up(&ai->sem);
2284}
2285
2286static void airo_set_multicast_list(struct net_device *dev) {
2287 struct airo_info *ai = dev->priv;
2288
2289 if ((dev->flags ^ ai->flags) & IFF_PROMISC) {
2290 change_bit(FLAG_PROMISC, &ai->flags);
2291 if (down_trylock(&ai->sem) != 0) {
2292 set_bit(JOB_PROMISC, &ai->flags);
2293 wake_up_interruptible(&ai->thr_wait);
2294 } else
2295 airo_set_promisc(ai);
2296 }
2297
2298 if ((dev->flags&IFF_ALLMULTI)||dev->mc_count>0) {
2299 /* Turn on multicast. (Should be already setup...) */
2300 }
2301}
2302
2303static int airo_set_mac_address(struct net_device *dev, void *p)
2304{
2305 struct airo_info *ai = dev->priv;
2306 struct sockaddr *addr = p;
2307 Resp rsp;
2308
2309 readConfigRid(ai, 1);
2310 memcpy (ai->config.macAddr, addr->sa_data, dev->addr_len);
2311 set_bit (FLAG_COMMIT, &ai->flags);
2312 disable_MAC(ai, 1);
2313 writeConfigRid (ai, 1);
2314 enable_MAC(ai, &rsp, 1);
2315 memcpy (ai->dev->dev_addr, addr->sa_data, dev->addr_len);
2316 if (ai->wifidev)
2317 memcpy (ai->wifidev->dev_addr, addr->sa_data, dev->addr_len);
2318 return 0;
2319}
2320
2321static int airo_change_mtu(struct net_device *dev, int new_mtu)
2322{
2323 if ((new_mtu < 68) || (new_mtu > 2400))
2324 return -EINVAL;
2325 dev->mtu = new_mtu;
2326 return 0;
2327}
2328
2329
2330static int airo_close(struct net_device *dev) {
2331 struct airo_info *ai = dev->priv;
2332
2333 netif_stop_queue(dev);
2334
2335 if (ai->wifidev != dev) {
2336#ifdef POWER_ON_DOWN
2337 /* Shut power to the card. The idea is that the user can save
2338 * power when he doesn't need the card with "ifconfig down".
2339 * That's the method that is most friendly towards the network
2340 * stack (i.e. the network stack won't try to broadcast
2341 * anything on the interface and routes are gone. Jean II */
2342 set_bit(FLAG_RADIO_DOWN, &ai->flags);
2343 disable_MAC(ai, 1);
2344#endif
2345 disable_interrupts( ai );
2346 }
2347 return 0;
2348}
2349
2350static void del_airo_dev( struct net_device *dev );
2351
2352void stop_airo_card( struct net_device *dev, int freeres )
2353{
2354 struct airo_info *ai = dev->priv;
2355
2356 set_bit(FLAG_RADIO_DOWN, &ai->flags);
2357 disable_MAC(ai, 1);
2358 disable_interrupts(ai);
2359 free_irq( dev->irq, dev );
2360 takedown_proc_entry( dev, ai );
2361 if (test_bit(FLAG_REGISTERED, &ai->flags)) {
2362 unregister_netdev( dev );
2363 if (ai->wifidev) {
2364 unregister_netdev(ai->wifidev);
2365 free_netdev(ai->wifidev);
2366 ai->wifidev = NULL;
2367 }
2368 clear_bit(FLAG_REGISTERED, &ai->flags);
2369 }
2370 set_bit(JOB_DIE, &ai->flags);
2371 kill_proc(ai->thr_pid, SIGTERM, 1);
2372 wait_for_completion(&ai->thr_exited);
2373
2374 /*
2375 * Clean out tx queue
2376 */
David S. Millerb03efcf2005-07-08 14:57:23 -07002377 if (test_bit(FLAG_MPI, &ai->flags) && !skb_queue_empty(&ai->txq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 struct sk_buff *skb = NULL;
2379 for (;(skb = skb_dequeue(&ai->txq));)
2380 dev_kfree_skb(skb);
2381 }
2382
Jesper Juhlb4558ea2005-10-28 16:53:13 -04002383 kfree(ai->flash);
2384 kfree(ai->rssi);
2385 kfree(ai->APList);
2386 kfree(ai->SSID);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 if (freeres) {
2388 /* PCMCIA frees this stuff, so only for PCI and ISA */
2389 release_region( dev->base_addr, 64 );
2390 if (test_bit(FLAG_MPI, &ai->flags)) {
2391 if (ai->pci)
2392 mpi_unmap_card(ai->pci);
2393 if (ai->pcimem)
2394 iounmap(ai->pcimem);
2395 if (ai->pciaux)
2396 iounmap(ai->pciaux);
2397 pci_free_consistent(ai->pci, PCI_SHARED_LEN,
2398 ai->shared, ai->shared_dma);
2399 }
2400 }
Jesper Juhl573dbd92005-09-01 17:44:29 -07002401 crypto_free_tfm(ai->tfm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 del_airo_dev( dev );
2403 free_netdev( dev );
2404}
2405
2406EXPORT_SYMBOL(stop_airo_card);
2407
2408static int add_airo_dev( struct net_device *dev );
2409
Jouni Malinenff1d2762005-05-12 22:54:16 -04002410static int wll_header_parse(struct sk_buff *skb, unsigned char *haddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411{
2412 memcpy(haddr, skb->mac.raw + 10, ETH_ALEN);
2413 return ETH_ALEN;
2414}
2415
2416static void mpi_unmap_card(struct pci_dev *pci)
2417{
2418 unsigned long mem_start = pci_resource_start(pci, 1);
2419 unsigned long mem_len = pci_resource_len(pci, 1);
2420 unsigned long aux_start = pci_resource_start(pci, 2);
2421 unsigned long aux_len = AUXMEMSIZE;
2422
2423 release_mem_region(aux_start, aux_len);
2424 release_mem_region(mem_start, mem_len);
2425}
2426
2427/*************************************************************
2428 * This routine assumes that descriptors have been setup .
2429 * Run at insmod time or after reset when the decriptors
2430 * have been initialized . Returns 0 if all is well nz
2431 * otherwise . Does not allocate memory but sets up card
2432 * using previously allocated descriptors.
2433 */
2434static int mpi_init_descriptors (struct airo_info *ai)
2435{
2436 Cmd cmd;
2437 Resp rsp;
2438 int i;
2439 int rc = SUCCESS;
2440
2441 /* Alloc card RX descriptors */
2442 netif_stop_queue(ai->dev);
2443
2444 memset(&rsp,0,sizeof(rsp));
2445 memset(&cmd,0,sizeof(cmd));
2446
2447 cmd.cmd = CMD_ALLOCATEAUX;
2448 cmd.parm0 = FID_RX;
2449 cmd.parm1 = (ai->rxfids[0].card_ram_off - ai->pciaux);
2450 cmd.parm2 = MPI_MAX_FIDS;
2451 rc=issuecommand(ai, &cmd, &rsp);
2452 if (rc != SUCCESS) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002453 airo_print_err(ai->dev->name, "Couldn't allocate RX FID");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 return rc;
2455 }
2456
2457 for (i=0; i<MPI_MAX_FIDS; i++) {
2458 memcpy_toio(ai->rxfids[i].card_ram_off,
2459 &ai->rxfids[i].rx_desc, sizeof(RxFid));
2460 }
2461
2462 /* Alloc card TX descriptors */
2463
2464 memset(&rsp,0,sizeof(rsp));
2465 memset(&cmd,0,sizeof(cmd));
2466
2467 cmd.cmd = CMD_ALLOCATEAUX;
2468 cmd.parm0 = FID_TX;
2469 cmd.parm1 = (ai->txfids[0].card_ram_off - ai->pciaux);
2470 cmd.parm2 = MPI_MAX_FIDS;
2471
2472 for (i=0; i<MPI_MAX_FIDS; i++) {
2473 ai->txfids[i].tx_desc.valid = 1;
2474 memcpy_toio(ai->txfids[i].card_ram_off,
2475 &ai->txfids[i].tx_desc, sizeof(TxFid));
2476 }
2477 ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */
2478
2479 rc=issuecommand(ai, &cmd, &rsp);
2480 if (rc != SUCCESS) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002481 airo_print_err(ai->dev->name, "Couldn't allocate TX FID");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 return rc;
2483 }
2484
2485 /* Alloc card Rid descriptor */
2486 memset(&rsp,0,sizeof(rsp));
2487 memset(&cmd,0,sizeof(cmd));
2488
2489 cmd.cmd = CMD_ALLOCATEAUX;
2490 cmd.parm0 = RID_RW;
2491 cmd.parm1 = (ai->config_desc.card_ram_off - ai->pciaux);
2492 cmd.parm2 = 1; /* Magic number... */
2493 rc=issuecommand(ai, &cmd, &rsp);
2494 if (rc != SUCCESS) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002495 airo_print_err(ai->dev->name, "Couldn't allocate RID");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 return rc;
2497 }
2498
2499 memcpy_toio(ai->config_desc.card_ram_off,
2500 &ai->config_desc.rid_desc, sizeof(Rid));
2501
2502 return rc;
2503}
2504
2505/*
2506 * We are setting up three things here:
2507 * 1) Map AUX memory for descriptors: Rid, TxFid, or RxFid.
2508 * 2) Map PCI memory for issueing commands.
2509 * 3) Allocate memory (shared) to send and receive ethernet frames.
2510 */
2511static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci,
2512 const char *name)
2513{
2514 unsigned long mem_start, mem_len, aux_start, aux_len;
2515 int rc = -1;
2516 int i;
Jeff Garzik2759c8d2005-09-24 04:09:04 -04002517 dma_addr_t busaddroff;
2518 unsigned char *vpackoff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 unsigned char __iomem *pciaddroff;
2520
2521 mem_start = pci_resource_start(pci, 1);
2522 mem_len = pci_resource_len(pci, 1);
2523 aux_start = pci_resource_start(pci, 2);
2524 aux_len = AUXMEMSIZE;
2525
2526 if (!request_mem_region(mem_start, mem_len, name)) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002527 airo_print_err(ai->dev->name, "Couldn't get region %x[%x] for %s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 (int)mem_start, (int)mem_len, name);
2529 goto out;
2530 }
2531 if (!request_mem_region(aux_start, aux_len, name)) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002532 airo_print_err(ai->dev->name, "Couldn't get region %x[%x] for %s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 (int)aux_start, (int)aux_len, name);
2534 goto free_region1;
2535 }
2536
2537 ai->pcimem = ioremap(mem_start, mem_len);
2538 if (!ai->pcimem) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002539 airo_print_err(ai->dev->name, "Couldn't map region %x[%x] for %s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 (int)mem_start, (int)mem_len, name);
2541 goto free_region2;
2542 }
2543 ai->pciaux = ioremap(aux_start, aux_len);
2544 if (!ai->pciaux) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002545 airo_print_err(ai->dev->name, "Couldn't map region %x[%x] for %s",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 (int)aux_start, (int)aux_len, name);
2547 goto free_memmap;
2548 }
2549
2550 /* Reserve PKTSIZE for each fid and 2K for the Rids */
2551 ai->shared = pci_alloc_consistent(pci, PCI_SHARED_LEN, &ai->shared_dma);
2552 if (!ai->shared) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002553 airo_print_err(ai->dev->name, "Couldn't alloc_consistent %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 PCI_SHARED_LEN);
2555 goto free_auxmap;
2556 }
2557
2558 /*
2559 * Setup descriptor RX, TX, CONFIG
2560 */
Jeff Garzik2759c8d2005-09-24 04:09:04 -04002561 busaddroff = ai->shared_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 pciaddroff = ai->pciaux + AUX_OFFSET;
2563 vpackoff = ai->shared;
2564
2565 /* RX descriptor setup */
2566 for(i = 0; i < MPI_MAX_FIDS; i++) {
2567 ai->rxfids[i].pending = 0;
2568 ai->rxfids[i].card_ram_off = pciaddroff;
2569 ai->rxfids[i].virtual_host_addr = vpackoff;
Jeff Garzik2759c8d2005-09-24 04:09:04 -04002570 ai->rxfids[i].rx_desc.host_addr = busaddroff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 ai->rxfids[i].rx_desc.valid = 1;
2572 ai->rxfids[i].rx_desc.len = PKTSIZE;
2573 ai->rxfids[i].rx_desc.rdy = 0;
2574
2575 pciaddroff += sizeof(RxFid);
2576 busaddroff += PKTSIZE;
2577 vpackoff += PKTSIZE;
2578 }
2579
2580 /* TX descriptor setup */
2581 for(i = 0; i < MPI_MAX_FIDS; i++) {
2582 ai->txfids[i].card_ram_off = pciaddroff;
2583 ai->txfids[i].virtual_host_addr = vpackoff;
2584 ai->txfids[i].tx_desc.valid = 1;
Jeff Garzik2759c8d2005-09-24 04:09:04 -04002585 ai->txfids[i].tx_desc.host_addr = busaddroff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 memcpy(ai->txfids[i].virtual_host_addr,
2587 &wifictlhdr8023, sizeof(wifictlhdr8023));
2588
2589 pciaddroff += sizeof(TxFid);
2590 busaddroff += PKTSIZE;
2591 vpackoff += PKTSIZE;
2592 }
2593 ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */
2594
2595 /* Rid descriptor setup */
2596 ai->config_desc.card_ram_off = pciaddroff;
2597 ai->config_desc.virtual_host_addr = vpackoff;
Jeff Garzik2759c8d2005-09-24 04:09:04 -04002598 ai->config_desc.rid_desc.host_addr = busaddroff;
2599 ai->ridbus = busaddroff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 ai->config_desc.rid_desc.rid = 0;
2601 ai->config_desc.rid_desc.len = RIDSIZE;
2602 ai->config_desc.rid_desc.valid = 1;
2603 pciaddroff += sizeof(Rid);
2604 busaddroff += RIDSIZE;
2605 vpackoff += RIDSIZE;
2606
2607 /* Tell card about descriptors */
2608 if (mpi_init_descriptors (ai) != SUCCESS)
2609 goto free_shared;
2610
2611 return 0;
2612 free_shared:
2613 pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
2614 free_auxmap:
2615 iounmap(ai->pciaux);
2616 free_memmap:
2617 iounmap(ai->pcimem);
2618 free_region2:
2619 release_mem_region(aux_start, aux_len);
2620 free_region1:
2621 release_mem_region(mem_start, mem_len);
2622 out:
2623 return rc;
2624}
2625
2626static void wifi_setup(struct net_device *dev)
2627{
2628 dev->hard_header = NULL;
2629 dev->rebuild_header = NULL;
2630 dev->hard_header_cache = NULL;
2631 dev->header_cache_update= NULL;
2632
2633 dev->hard_header_parse = wll_header_parse;
2634 dev->hard_start_xmit = &airo_start_xmit11;
2635 dev->get_stats = &airo_get_stats;
2636 dev->set_mac_address = &airo_set_mac_address;
2637 dev->do_ioctl = &airo_ioctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 dev->wireless_handlers = &airo_handler_def;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 dev->change_mtu = &airo_change_mtu;
2640 dev->open = &airo_open;
2641 dev->stop = &airo_close;
2642
2643 dev->type = ARPHRD_IEEE80211;
2644 dev->hard_header_len = ETH_HLEN;
2645 dev->mtu = 2312;
2646 dev->addr_len = ETH_ALEN;
2647 dev->tx_queue_len = 100;
2648
2649 memset(dev->broadcast,0xFF, ETH_ALEN);
2650
2651 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2652}
2653
2654static struct net_device *init_wifidev(struct airo_info *ai,
2655 struct net_device *ethdev)
2656{
2657 int err;
2658 struct net_device *dev = alloc_netdev(0, "wifi%d", wifi_setup);
2659 if (!dev)
2660 return NULL;
2661 dev->priv = ethdev->priv;
2662 dev->irq = ethdev->irq;
2663 dev->base_addr = ethdev->base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 dev->wireless_data = ethdev->wireless_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 memcpy(dev->dev_addr, ethdev->dev_addr, dev->addr_len);
2666 err = register_netdev(dev);
2667 if (err<0) {
2668 free_netdev(dev);
2669 return NULL;
2670 }
2671 return dev;
2672}
2673
Jouni Malinenff1d2762005-05-12 22:54:16 -04002674static int reset_card( struct net_device *dev , int lock) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 struct airo_info *ai = dev->priv;
2676
2677 if (lock && down_interruptible(&ai->sem))
2678 return -1;
2679 waitbusy (ai);
2680 OUT4500(ai,COMMAND,CMD_SOFTRESET);
2681 msleep(200);
2682 waitbusy (ai);
2683 msleep(200);
2684 if (lock)
2685 up(&ai->sem);
2686 return 0;
2687}
2688
Jouni Malinenff1d2762005-05-12 22:54:16 -04002689static struct net_device *_init_airo_card( unsigned short irq, int port,
2690 int is_pcmcia, struct pci_dev *pci,
2691 struct device *dmdev )
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692{
2693 struct net_device *dev;
2694 struct airo_info *ai;
2695 int i, rc;
2696
2697 /* Create the network device object. */
2698 dev = alloc_etherdev(sizeof(*ai));
2699 if (!dev) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002700 airo_print_err("", "Couldn't alloc_etherdev");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 return NULL;
2702 }
2703 if (dev_alloc_name(dev, dev->name) < 0) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002704 airo_print_err("", "Couldn't get name!");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 goto err_out_free;
2706 }
2707
2708 ai = dev->priv;
2709 ai->wifidev = NULL;
2710 ai->flags = 0;
Dan Williams934d8bf2006-03-16 13:46:23 -05002711 ai->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 if (pci && (pci->device == 0x5000 || pci->device == 0xa504)) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002713 airo_print_dbg(dev->name, "Found an MPI350 card");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 set_bit(FLAG_MPI, &ai->flags);
2715 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 spin_lock_init(&ai->aux_lock);
2717 sema_init(&ai->sem, 1);
2718 ai->config.len = 0;
2719 ai->pci = pci;
2720 init_waitqueue_head (&ai->thr_wait);
2721 init_completion (&ai->thr_exited);
2722 ai->thr_pid = kernel_thread(airo_thread, dev, CLONE_FS | CLONE_FILES);
2723 if (ai->thr_pid < 0)
2724 goto err_out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 ai->tfm = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 rc = add_airo_dev( dev );
2727 if (rc)
2728 goto err_out_thr;
2729
2730 /* The Airo-specific entries in the device structure. */
2731 if (test_bit(FLAG_MPI,&ai->flags)) {
2732 skb_queue_head_init (&ai->txq);
2733 dev->hard_start_xmit = &mpi_start_xmit;
2734 } else
2735 dev->hard_start_xmit = &airo_start_xmit;
2736 dev->get_stats = &airo_get_stats;
2737 dev->set_multicast_list = &airo_set_multicast_list;
2738 dev->set_mac_address = &airo_set_mac_address;
2739 dev->do_ioctl = &airo_ioctl;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 dev->wireless_handlers = &airo_handler_def;
2741 ai->wireless_data.spy_data = &ai->spy_data;
2742 dev->wireless_data = &ai->wireless_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 dev->change_mtu = &airo_change_mtu;
2744 dev->open = &airo_open;
2745 dev->stop = &airo_close;
2746 dev->irq = irq;
2747 dev->base_addr = port;
2748
2749 SET_NETDEV_DEV(dev, dmdev);
2750
2751
Matthieu CASTET1d97f382005-12-01 02:35:26 -05002752 reset_card (dev, 1);
2753 msleep(400);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754
2755 rc = request_irq( dev->irq, airo_interrupt, SA_SHIRQ, dev->name, dev );
2756 if (rc) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002757 airo_print_err(dev->name, "register interrupt %d failed, rc %d",
2758 irq, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 goto err_out_unlink;
2760 }
2761 if (!is_pcmcia) {
2762 if (!request_region( dev->base_addr, 64, dev->name )) {
2763 rc = -EBUSY;
Dan Williams934d8bf2006-03-16 13:46:23 -05002764 airo_print_err(dev->name, "Couldn't request region");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 goto err_out_irq;
2766 }
2767 }
2768
2769 if (test_bit(FLAG_MPI,&ai->flags)) {
2770 if (mpi_map_card(ai, pci, dev->name)) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002771 airo_print_err(dev->name, "Could not map memory");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 goto err_out_res;
2773 }
2774 }
2775
2776 if (probe) {
2777 if ( setup_card( ai, dev->dev_addr, 1 ) != SUCCESS ) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002778 airo_print_err(dev->name, "MAC could not be enabled" );
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 rc = -EIO;
2780 goto err_out_map;
2781 }
2782 } else if (!test_bit(FLAG_MPI,&ai->flags)) {
2783 ai->bap_read = fast_bap_read;
2784 set_bit(FLAG_FLASHING, &ai->flags);
2785 }
2786
2787 rc = register_netdev(dev);
2788 if (rc) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002789 airo_print_err(dev->name, "Couldn't register_netdev");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 goto err_out_map;
2791 }
2792 ai->wifidev = init_wifidev(ai, dev);
2793
2794 set_bit(FLAG_REGISTERED,&ai->flags);
Dan Williams934d8bf2006-03-16 13:46:23 -05002795 airo_print_info(dev->name, "MAC enabled %x:%x:%x:%x:%x:%x",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
2797 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5] );
2798
2799 /* Allocate the transmit buffers */
2800 if (probe && !test_bit(FLAG_MPI,&ai->flags))
2801 for( i = 0; i < MAX_FIDS; i++ )
2802 ai->fids[i] = transmit_allocate(ai,2312,i>=MAX_FIDS/2);
2803
2804 setup_proc_entry( dev, dev->priv ); /* XXX check for failure */
2805 netif_start_queue(dev);
2806 SET_MODULE_OWNER(dev);
2807 return dev;
2808
2809err_out_map:
2810 if (test_bit(FLAG_MPI,&ai->flags) && pci) {
2811 pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
2812 iounmap(ai->pciaux);
2813 iounmap(ai->pcimem);
2814 mpi_unmap_card(ai->pci);
2815 }
2816err_out_res:
2817 if (!is_pcmcia)
2818 release_region( dev->base_addr, 64 );
2819err_out_irq:
2820 free_irq(dev->irq, dev);
2821err_out_unlink:
2822 del_airo_dev(dev);
2823err_out_thr:
2824 set_bit(JOB_DIE, &ai->flags);
2825 kill_proc(ai->thr_pid, SIGTERM, 1);
2826 wait_for_completion(&ai->thr_exited);
2827err_out_free:
2828 free_netdev(dev);
2829 return NULL;
2830}
2831
2832struct net_device *init_airo_card( unsigned short irq, int port, int is_pcmcia,
2833 struct device *dmdev)
2834{
2835 return _init_airo_card ( irq, port, is_pcmcia, NULL, dmdev);
2836}
2837
2838EXPORT_SYMBOL(init_airo_card);
2839
2840static int waitbusy (struct airo_info *ai) {
2841 int delay = 0;
2842 while ((IN4500 (ai, COMMAND) & COMMAND_BUSY) & (delay < 10000)) {
2843 udelay (10);
2844 if ((++delay % 20) == 0)
2845 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
2846 }
2847 return delay < 10000;
2848}
2849
2850int reset_airo_card( struct net_device *dev )
2851{
2852 int i;
2853 struct airo_info *ai = dev->priv;
2854
2855 if (reset_card (dev, 1))
2856 return -1;
2857
2858 if ( setup_card(ai, dev->dev_addr, 1 ) != SUCCESS ) {
Dan Williams934d8bf2006-03-16 13:46:23 -05002859 airo_print_err(dev->name, "MAC could not be enabled");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 return -1;
2861 }
Dan Williams934d8bf2006-03-16 13:46:23 -05002862 airo_print_info(dev->name, "MAC enabled %x:%x:%x:%x:%x:%x",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
2864 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
2865 /* Allocate the transmit buffers if needed */
2866 if (!test_bit(FLAG_MPI,&ai->flags))
2867 for( i = 0; i < MAX_FIDS; i++ )
2868 ai->fids[i] = transmit_allocate (ai,2312,i>=MAX_FIDS/2);
2869
2870 enable_interrupts( ai );
2871 netif_wake_queue(dev);
2872 return 0;
2873}
2874
2875EXPORT_SYMBOL(reset_airo_card);
2876
2877static void airo_send_event(struct net_device *dev) {
2878 struct airo_info *ai = dev->priv;
2879 union iwreq_data wrqu;
2880 StatusRid status_rid;
2881
2882 clear_bit(JOB_EVENT, &ai->flags);
2883 PC4500_readrid(ai, RID_STATUS, &status_rid, sizeof(status_rid), 0);
2884 up(&ai->sem);
2885 wrqu.data.length = 0;
2886 wrqu.data.flags = 0;
2887 memcpy(wrqu.ap_addr.sa_data, status_rid.bssid[0], ETH_ALEN);
2888 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
2889
2890 /* Send event to user space */
2891 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
2892}
2893
2894static int airo_thread(void *data) {
2895 struct net_device *dev = data;
2896 struct airo_info *ai = dev->priv;
2897 int locked;
2898
2899 daemonize("%s", dev->name);
2900 allow_signal(SIGTERM);
2901
2902 while(1) {
2903 if (signal_pending(current))
2904 flush_signals(current);
2905
2906 /* make swsusp happy with our thread */
Christoph Lameter3e1d1d22005-06-24 23:13:50 -07002907 try_to_freeze();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908
2909 if (test_bit(JOB_DIE, &ai->flags))
2910 break;
2911
2912 if (ai->flags & JOB_MASK) {
2913 locked = down_interruptible(&ai->sem);
2914 } else {
2915 wait_queue_t wait;
2916
2917 init_waitqueue_entry(&wait, current);
2918 add_wait_queue(&ai->thr_wait, &wait);
2919 for (;;) {
2920 set_current_state(TASK_INTERRUPTIBLE);
2921 if (ai->flags & JOB_MASK)
2922 break;
2923 if (ai->expires) {
2924 if (time_after_eq(jiffies,ai->expires)){
2925 set_bit(JOB_AUTOWEP,&ai->flags);
2926 break;
2927 }
2928 if (!signal_pending(current)) {
2929 schedule_timeout(ai->expires - jiffies);
2930 continue;
2931 }
2932 } else if (!signal_pending(current)) {
2933 schedule();
2934 continue;
2935 }
2936 break;
2937 }
2938 current->state = TASK_RUNNING;
2939 remove_wait_queue(&ai->thr_wait, &wait);
2940 locked = 1;
2941 }
2942
2943 if (locked)
2944 continue;
2945
2946 if (test_bit(JOB_DIE, &ai->flags)) {
2947 up(&ai->sem);
2948 break;
2949 }
2950
Pavel Machekca078ba2005-09-03 15:56:57 -07002951 if (ai->power.event || test_bit(FLAG_FLASHING, &ai->flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 up(&ai->sem);
2953 continue;
2954 }
2955
2956 if (test_bit(JOB_XMIT, &ai->flags))
2957 airo_end_xmit(dev);
2958 else if (test_bit(JOB_XMIT11, &ai->flags))
2959 airo_end_xmit11(dev);
2960 else if (test_bit(JOB_STATS, &ai->flags))
2961 airo_read_stats(ai);
2962 else if (test_bit(JOB_WSTATS, &ai->flags))
2963 airo_read_wireless_stats(ai);
2964 else if (test_bit(JOB_PROMISC, &ai->flags))
2965 airo_set_promisc(ai);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 else if (test_bit(JOB_MIC, &ai->flags))
2967 micinit(ai);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 else if (test_bit(JOB_EVENT, &ai->flags))
2969 airo_send_event(dev);
2970 else if (test_bit(JOB_AUTOWEP, &ai->flags))
2971 timer_func(dev);
2972 }
2973 complete_and_exit (&ai->thr_exited, 0);
2974}
2975
2976static irqreturn_t airo_interrupt ( int irq, void* dev_id, struct pt_regs *regs) {
2977 struct net_device *dev = (struct net_device *)dev_id;
2978 u16 status;
2979 u16 fid;
2980 struct airo_info *apriv = dev->priv;
2981 u16 savedInterrupts = 0;
2982 int handled = 0;
2983
2984 if (!netif_device_present(dev))
2985 return IRQ_NONE;
2986
2987 for (;;) {
2988 status = IN4500( apriv, EVSTAT );
2989 if ( !(status & STATUS_INTS) || status == 0xffff ) break;
2990
2991 handled = 1;
2992
2993 if ( status & EV_AWAKE ) {
2994 OUT4500( apriv, EVACK, EV_AWAKE );
2995 OUT4500( apriv, EVACK, EV_AWAKE );
2996 }
2997
2998 if (!savedInterrupts) {
2999 savedInterrupts = IN4500( apriv, EVINTEN );
3000 OUT4500( apriv, EVINTEN, 0 );
3001 }
3002
3003 if ( status & EV_MIC ) {
3004 OUT4500( apriv, EVACK, EV_MIC );
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 if (test_bit(FLAG_MIC_CAPABLE, &apriv->flags)) {
3006 set_bit(JOB_MIC, &apriv->flags);
3007 wake_up_interruptible(&apriv->thr_wait);
3008 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 }
3010 if ( status & EV_LINK ) {
3011 union iwreq_data wrqu;
3012 /* The link status has changed, if you want to put a
3013 monitor hook in, do it here. (Remember that
3014 interrupts are still disabled!)
3015 */
3016 u16 newStatus = IN4500(apriv, LINKSTAT);
3017 OUT4500( apriv, EVACK, EV_LINK);
3018 /* Here is what newStatus means: */
3019#define NOBEACON 0x8000 /* Loss of sync - missed beacons */
3020#define MAXRETRIES 0x8001 /* Loss of sync - max retries */
3021#define MAXARL 0x8002 /* Loss of sync - average retry level exceeded*/
3022#define FORCELOSS 0x8003 /* Loss of sync - host request */
3023#define TSFSYNC 0x8004 /* Loss of sync - TSF synchronization */
3024#define DEAUTH 0x8100 /* Deauthentication (low byte is reason code) */
3025#define DISASS 0x8200 /* Disassociation (low byte is reason code) */
3026#define ASSFAIL 0x8400 /* Association failure (low byte is reason
3027 code) */
3028#define AUTHFAIL 0x0300 /* Authentication failure (low byte is reason
3029 code) */
3030#define ASSOCIATED 0x0400 /* Assocatied */
3031#define RC_RESERVED 0 /* Reserved return code */
3032#define RC_NOREASON 1 /* Unspecified reason */
3033#define RC_AUTHINV 2 /* Previous authentication invalid */
3034#define RC_DEAUTH 3 /* Deauthenticated because sending station is
3035 leaving */
3036#define RC_NOACT 4 /* Disassociated due to inactivity */
3037#define RC_MAXLOAD 5 /* Disassociated because AP is unable to handle
3038 all currently associated stations */
3039#define RC_BADCLASS2 6 /* Class 2 frame received from
3040 non-Authenticated station */
3041#define RC_BADCLASS3 7 /* Class 3 frame received from
3042 non-Associated station */
3043#define RC_STATLEAVE 8 /* Disassociated because sending station is
3044 leaving BSS */
3045#define RC_NOAUTH 9 /* Station requesting (Re)Association is not
3046 Authenticated with the responding station */
3047 if (newStatus != ASSOCIATED) {
3048 if (auto_wep && !apriv->expires) {
3049 apriv->expires = RUN_AT(3*HZ);
3050 wake_up_interruptible(&apriv->thr_wait);
3051 }
3052 } else {
3053 struct task_struct *task = apriv->task;
3054 if (auto_wep)
3055 apriv->expires = 0;
3056 if (task)
3057 wake_up_process (task);
3058 set_bit(FLAG_UPDATE_UNI, &apriv->flags);
3059 set_bit(FLAG_UPDATE_MULTI, &apriv->flags);
3060 }
3061 /* Question : is ASSOCIATED the only status
3062 * that is valid ? We want to catch handover
3063 * and reassociations as valid status
3064 * Jean II */
3065 if(newStatus == ASSOCIATED) {
3066 if (apriv->scan_timestamp) {
3067 /* Send an empty event to user space.
3068 * We don't send the received data on
3069 * the event because it would require
3070 * us to do complex transcoding, and
3071 * we want to minimise the work done in
3072 * the irq handler. Use a request to
3073 * extract the data - Jean II */
3074 wrqu.data.length = 0;
3075 wrqu.data.flags = 0;
3076 wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
3077 apriv->scan_timestamp = 0;
3078 }
3079 if (down_trylock(&apriv->sem) != 0) {
3080 set_bit(JOB_EVENT, &apriv->flags);
3081 wake_up_interruptible(&apriv->thr_wait);
3082 } else
3083 airo_send_event(dev);
3084 } else {
3085 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
3086 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3087
3088 /* Send event to user space */
3089 wireless_send_event(dev, SIOCGIWAP, &wrqu,NULL);
3090 }
3091 }
3092
3093 /* Check to see if there is something to receive */
3094 if ( status & EV_RX ) {
3095 struct sk_buff *skb = NULL;
3096 u16 fc, len, hdrlen = 0;
3097#pragma pack(1)
3098 struct {
3099 u16 status, len;
3100 u8 rssi[2];
3101 u8 rate;
3102 u8 freq;
3103 u16 tmp[4];
3104 } hdr;
3105#pragma pack()
3106 u16 gap;
3107 u16 tmpbuf[4];
3108 u16 *buffer;
3109
3110 if (test_bit(FLAG_MPI,&apriv->flags)) {
3111 if (test_bit(FLAG_802_11, &apriv->flags))
3112 mpi_receive_802_11(apriv);
3113 else
3114 mpi_receive_802_3(apriv);
3115 OUT4500(apriv, EVACK, EV_RX);
3116 goto exitrx;
3117 }
3118
3119 fid = IN4500( apriv, RXFID );
3120
3121 /* Get the packet length */
3122 if (test_bit(FLAG_802_11, &apriv->flags)) {
3123 bap_setup (apriv, fid, 4, BAP0);
3124 bap_read (apriv, (u16*)&hdr, sizeof(hdr), BAP0);
3125 /* Bad CRC. Ignore packet */
3126 if (le16_to_cpu(hdr.status) & 2)
3127 hdr.len = 0;
3128 if (apriv->wifidev == NULL)
3129 hdr.len = 0;
3130 } else {
3131 bap_setup (apriv, fid, 0x36, BAP0);
3132 bap_read (apriv, (u16*)&hdr.len, 2, BAP0);
3133 }
3134 len = le16_to_cpu(hdr.len);
3135
3136 if (len > 2312) {
Dan Williams934d8bf2006-03-16 13:46:23 -05003137 airo_print_err(apriv->dev->name, "Bad size %d", len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138 goto badrx;
3139 }
3140 if (len == 0)
3141 goto badrx;
3142
3143 if (test_bit(FLAG_802_11, &apriv->flags)) {
3144 bap_read (apriv, (u16*)&fc, sizeof(fc), BAP0);
3145 fc = le16_to_cpu(fc);
3146 switch (fc & 0xc) {
3147 case 4:
3148 if ((fc & 0xe0) == 0xc0)
3149 hdrlen = 10;
3150 else
3151 hdrlen = 16;
3152 break;
3153 case 8:
3154 if ((fc&0x300)==0x300){
3155 hdrlen = 30;
3156 break;
3157 }
3158 default:
3159 hdrlen = 24;
3160 }
3161 } else
3162 hdrlen = ETH_ALEN * 2;
3163
3164 skb = dev_alloc_skb( len + hdrlen + 2 + 2 );
3165 if ( !skb ) {
3166 apriv->stats.rx_dropped++;
3167 goto badrx;
3168 }
3169 skb_reserve(skb, 2); /* This way the IP header is aligned */
3170 buffer = (u16*)skb_put (skb, len + hdrlen);
3171 if (test_bit(FLAG_802_11, &apriv->flags)) {
3172 buffer[0] = fc;
3173 bap_read (apriv, buffer + 1, hdrlen - 2, BAP0);
3174 if (hdrlen == 24)
3175 bap_read (apriv, tmpbuf, 6, BAP0);
3176
3177 bap_read (apriv, &gap, sizeof(gap), BAP0);
3178 gap = le16_to_cpu(gap);
3179 if (gap) {
Dan Williams934d8bf2006-03-16 13:46:23 -05003180 if (gap <= 8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 bap_read (apriv, tmpbuf, gap, BAP0);
Dan Williams934d8bf2006-03-16 13:46:23 -05003182 } else {
3183 airo_print_err(apriv->dev->name, "gaplen too "
3184 "big. Problems will follow...");
3185 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186 }
3187 bap_read (apriv, buffer + hdrlen/2, len, BAP0);
3188 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 MICBuffer micbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 bap_read (apriv, buffer, ETH_ALEN*2, BAP0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 if (apriv->micstats.enabled) {
3192 bap_read (apriv,(u16*)&micbuf,sizeof(micbuf),BAP0);
3193 if (ntohs(micbuf.typelen) > 0x05DC)
3194 bap_setup (apriv, fid, 0x44, BAP0);
3195 else {
3196 if (len <= sizeof(micbuf))
3197 goto badmic;
3198
3199 len -= sizeof(micbuf);
3200 skb_trim (skb, len + hdrlen);
3201 }
3202 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 bap_read(apriv,buffer+ETH_ALEN,len,BAP0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 if (decapsulate(apriv,&micbuf,(etherHead*)buffer,len)) {
3205badmic:
3206 dev_kfree_skb_irq (skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207badrx:
3208 OUT4500( apriv, EVACK, EV_RX);
3209 goto exitrx;
3210 }
3211 }
3212#ifdef WIRELESS_SPY
3213 if (apriv->spy_data.spy_number > 0) {
3214 char *sa;
3215 struct iw_quality wstats;
3216 /* Prepare spy data : addr + qual */
3217 if (!test_bit(FLAG_802_11, &apriv->flags)) {
3218 sa = (char*)buffer + 6;
3219 bap_setup (apriv, fid, 8, BAP0);
3220 bap_read (apriv, (u16*)hdr.rssi, 2, BAP0);
3221 } else
3222 sa = (char*)buffer + 10;
3223 wstats.qual = hdr.rssi[0];
3224 if (apriv->rssi)
3225 wstats.level = 0x100 - apriv->rssi[hdr.rssi[1]].rssidBm;
3226 else
3227 wstats.level = (hdr.rssi[1] + 321) / 2;
Dan Williams41480af2005-05-10 09:45:51 -04003228 wstats.noise = apriv->wstats.qual.noise;
3229 wstats.updated = IW_QUAL_LEVEL_UPDATED
3230 | IW_QUAL_QUAL_UPDATED
Jean Tourrilhesce6623c2005-09-02 11:45:10 -07003231 | IW_QUAL_DBM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 /* Update spy records */
3233 wireless_spy_update(dev, sa, &wstats);
3234 }
3235#endif /* WIRELESS_SPY */
3236 OUT4500( apriv, EVACK, EV_RX);
3237
3238 if (test_bit(FLAG_802_11, &apriv->flags)) {
3239 skb->mac.raw = skb->data;
3240 skb->pkt_type = PACKET_OTHERHOST;
3241 skb->dev = apriv->wifidev;
3242 skb->protocol = htons(ETH_P_802_2);
3243 } else {
3244 skb->dev = dev;
3245 skb->protocol = eth_type_trans(skb,dev);
3246 }
3247 skb->dev->last_rx = jiffies;
3248 skb->ip_summed = CHECKSUM_NONE;
3249
3250 netif_rx( skb );
3251 }
3252exitrx:
3253
3254 /* Check to see if a packet has been transmitted */
3255 if ( status & ( EV_TX|EV_TXCPY|EV_TXEXC ) ) {
3256 int i;
3257 int len = 0;
3258 int index = -1;
3259
3260 if (test_bit(FLAG_MPI,&apriv->flags)) {
3261 unsigned long flags;
3262
3263 if (status & EV_TXEXC)
3264 get_tx_error(apriv, -1);
3265 spin_lock_irqsave(&apriv->aux_lock, flags);
David S. Millerb03efcf2005-07-08 14:57:23 -07003266 if (!skb_queue_empty(&apriv->txq)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 spin_unlock_irqrestore(&apriv->aux_lock,flags);
3268 mpi_send_packet (dev);
3269 } else {
3270 clear_bit(FLAG_PENDING_XMIT, &apriv->flags);
3271 spin_unlock_irqrestore(&apriv->aux_lock,flags);
3272 netif_wake_queue (dev);
3273 }
3274 OUT4500( apriv, EVACK,
3275 status & (EV_TX|EV_TXCPY|EV_TXEXC));
3276 goto exittx;
3277 }
3278
3279 fid = IN4500(apriv, TXCOMPLFID);
3280
3281 for( i = 0; i < MAX_FIDS; i++ ) {
3282 if ( ( apriv->fids[i] & 0xffff ) == fid ) {
3283 len = apriv->fids[i] >> 16;
3284 index = i;
3285 }
3286 }
3287 if (index != -1) {
3288 if (status & EV_TXEXC)
3289 get_tx_error(apriv, index);
3290 OUT4500( apriv, EVACK, status & (EV_TX | EV_TXEXC));
3291 /* Set up to be used again */
3292 apriv->fids[index] &= 0xffff;
3293 if (index < MAX_FIDS / 2) {
3294 if (!test_bit(FLAG_PENDING_XMIT, &apriv->flags))
3295 netif_wake_queue(dev);
3296 } else {
3297 if (!test_bit(FLAG_PENDING_XMIT11, &apriv->flags))
3298 netif_wake_queue(apriv->wifidev);
3299 }
3300 } else {
3301 OUT4500( apriv, EVACK, status & (EV_TX | EV_TXCPY | EV_TXEXC));
Dan Williams934d8bf2006-03-16 13:46:23 -05003302 airo_print_err(apriv->dev->name, "Unallocated FID was "
3303 "used to xmit" );
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 }
3305 }
3306exittx:
3307 if ( status & ~STATUS_INTS & ~IGNORE_INTS )
Dan Williams934d8bf2006-03-16 13:46:23 -05003308 airo_print_warn(apriv->dev->name, "Got weird status %x",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 status & ~STATUS_INTS & ~IGNORE_INTS );
3310 }
3311
3312 if (savedInterrupts)
3313 OUT4500( apriv, EVINTEN, savedInterrupts );
3314
3315 /* done.. */
3316 return IRQ_RETVAL(handled);
3317}
3318
3319/*
3320 * Routines to talk to the card
3321 */
3322
3323/*
3324 * This was originally written for the 4500, hence the name
3325 * NOTE: If use with 8bit mode and SMP bad things will happen!
3326 * Why would some one do 8 bit IO in an SMP machine?!?
3327 */
3328static void OUT4500( struct airo_info *ai, u16 reg, u16 val ) {
3329 if (test_bit(FLAG_MPI,&ai->flags))
3330 reg <<= 1;
3331 if ( !do8bitIO )
3332 outw( val, ai->dev->base_addr + reg );
3333 else {
3334 outb( val & 0xff, ai->dev->base_addr + reg );
3335 outb( val >> 8, ai->dev->base_addr + reg + 1 );
3336 }
3337}
3338
3339static u16 IN4500( struct airo_info *ai, u16 reg ) {
3340 unsigned short rc;
3341
3342 if (test_bit(FLAG_MPI,&ai->flags))
3343 reg <<= 1;
3344 if ( !do8bitIO )
3345 rc = inw( ai->dev->base_addr + reg );
3346 else {
3347 rc = inb( ai->dev->base_addr + reg );
3348 rc += ((int)inb( ai->dev->base_addr + reg + 1 )) << 8;
3349 }
3350 return rc;
3351}
3352
3353static int enable_MAC( struct airo_info *ai, Resp *rsp, int lock ) {
3354 int rc;
3355 Cmd cmd;
3356
3357 /* FLAG_RADIO_OFF : Radio disabled via /proc or Wireless Extensions
3358 * FLAG_RADIO_DOWN : Radio disabled via "ifconfig ethX down"
3359 * Note : we could try to use !netif_running(dev) in enable_MAC()
3360 * instead of this flag, but I don't trust it *within* the
3361 * open/close functions, and testing both flags together is
3362 * "cheaper" - Jean II */
3363 if (ai->flags & FLAG_RADIO_MASK) return SUCCESS;
3364
3365 if (lock && down_interruptible(&ai->sem))
3366 return -ERESTARTSYS;
3367
3368 if (!test_bit(FLAG_ENABLED, &ai->flags)) {
3369 memset(&cmd, 0, sizeof(cmd));
3370 cmd.cmd = MAC_ENABLE;
3371 rc = issuecommand(ai, &cmd, rsp);
3372 if (rc == SUCCESS)
3373 set_bit(FLAG_ENABLED, &ai->flags);
3374 } else
3375 rc = SUCCESS;
3376
3377 if (lock)
3378 up(&ai->sem);
3379
3380 if (rc)
Dan Williams934d8bf2006-03-16 13:46:23 -05003381 airo_print_err(ai->dev->name, "%s: Cannot enable MAC, err=%d",
3382 __FUNCTION__, rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 return rc;
3384}
3385
3386static void disable_MAC( struct airo_info *ai, int lock ) {
3387 Cmd cmd;
3388 Resp rsp;
3389
3390 if (lock && down_interruptible(&ai->sem))
3391 return;
3392
3393 if (test_bit(FLAG_ENABLED, &ai->flags)) {
3394 memset(&cmd, 0, sizeof(cmd));
3395 cmd.cmd = MAC_DISABLE; // disable in case already enabled
3396 issuecommand(ai, &cmd, &rsp);
3397 clear_bit(FLAG_ENABLED, &ai->flags);
3398 }
3399 if (lock)
3400 up(&ai->sem);
3401}
3402
3403static void enable_interrupts( struct airo_info *ai ) {
3404 /* Enable the interrupts */
3405 OUT4500( ai, EVINTEN, STATUS_INTS );
3406}
3407
3408static void disable_interrupts( struct airo_info *ai ) {
3409 OUT4500( ai, EVINTEN, 0 );
3410}
3411
3412static void mpi_receive_802_3(struct airo_info *ai)
3413{
3414 RxFid rxd;
3415 int len = 0;
3416 struct sk_buff *skb;
3417 char *buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 int off = 0;
3419 MICBuffer micbuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420
3421 memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
3422 /* Make sure we got something */
3423 if (rxd.rdy && rxd.valid == 0) {
3424 len = rxd.len + 12;
3425 if (len < 12 || len > 2048)
3426 goto badrx;
3427
3428 skb = dev_alloc_skb(len);
3429 if (!skb) {
3430 ai->stats.rx_dropped++;
3431 goto badrx;
3432 }
3433 buffer = skb_put(skb,len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 memcpy(buffer, ai->rxfids[0].virtual_host_addr, ETH_ALEN * 2);
3435 if (ai->micstats.enabled) {
3436 memcpy(&micbuf,
3437 ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2,
3438 sizeof(micbuf));
3439 if (ntohs(micbuf.typelen) <= 0x05DC) {
3440 if (len <= sizeof(micbuf) + ETH_ALEN * 2)
3441 goto badmic;
3442
3443 off = sizeof(micbuf);
3444 skb_trim (skb, len - off);
3445 }
3446 }
3447 memcpy(buffer + ETH_ALEN * 2,
3448 ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2 + off,
3449 len - ETH_ALEN * 2 - off);
3450 if (decapsulate (ai, &micbuf, (etherHead*)buffer, len - off - ETH_ALEN * 2)) {
3451badmic:
3452 dev_kfree_skb_irq (skb);
3453 goto badrx;
3454 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455#ifdef WIRELESS_SPY
3456 if (ai->spy_data.spy_number > 0) {
3457 char *sa;
3458 struct iw_quality wstats;
3459 /* Prepare spy data : addr + qual */
3460 sa = buffer + ETH_ALEN;
3461 wstats.qual = 0; /* XXX Where do I get that info from ??? */
3462 wstats.level = 0;
3463 wstats.updated = 0;
3464 /* Update spy records */
3465 wireless_spy_update(ai->dev, sa, &wstats);
3466 }
3467#endif /* WIRELESS_SPY */
3468
3469 skb->dev = ai->dev;
3470 skb->ip_summed = CHECKSUM_NONE;
3471 skb->protocol = eth_type_trans(skb, ai->dev);
3472 skb->dev->last_rx = jiffies;
3473 netif_rx(skb);
3474 }
3475badrx:
3476 if (rxd.valid == 0) {
3477 rxd.valid = 1;
3478 rxd.rdy = 0;
3479 rxd.len = PKTSIZE;
3480 memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
3481 }
3482}
3483
3484void mpi_receive_802_11 (struct airo_info *ai)
3485{
3486 RxFid rxd;
3487 struct sk_buff *skb = NULL;
3488 u16 fc, len, hdrlen = 0;
3489#pragma pack(1)
3490 struct {
3491 u16 status, len;
3492 u8 rssi[2];
3493 u8 rate;
3494 u8 freq;
3495 u16 tmp[4];
3496 } hdr;
3497#pragma pack()
3498 u16 gap;
3499 u16 *buffer;
3500 char *ptr = ai->rxfids[0].virtual_host_addr+4;
3501
3502 memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
3503 memcpy ((char *)&hdr, ptr, sizeof(hdr));
3504 ptr += sizeof(hdr);
3505 /* Bad CRC. Ignore packet */
3506 if (le16_to_cpu(hdr.status) & 2)
3507 hdr.len = 0;
3508 if (ai->wifidev == NULL)
3509 hdr.len = 0;
3510 len = le16_to_cpu(hdr.len);
3511 if (len > 2312) {
Dan Williams934d8bf2006-03-16 13:46:23 -05003512 airo_print_err(ai->dev->name, "Bad size %d", len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513 goto badrx;
3514 }
3515 if (len == 0)
3516 goto badrx;
3517
3518 memcpy ((char *)&fc, ptr, sizeof(fc));
3519 fc = le16_to_cpu(fc);
3520 switch (fc & 0xc) {
3521 case 4:
3522 if ((fc & 0xe0) == 0xc0)
3523 hdrlen = 10;
3524 else
3525 hdrlen = 16;
3526 break;
3527 case 8:
3528 if ((fc&0x300)==0x300){
3529 hdrlen = 30;
3530 break;
3531 }
3532 default:
3533 hdrlen = 24;
3534 }
3535
3536 skb = dev_alloc_skb( len + hdrlen + 2 );
3537 if ( !skb ) {
3538 ai->stats.rx_dropped++;
3539 goto badrx;
3540 }
3541 buffer = (u16*)skb_put (skb, len + hdrlen);
3542 memcpy ((char *)buffer, ptr, hdrlen);
3543 ptr += hdrlen;
3544 if (hdrlen == 24)
3545 ptr += 6;
3546 memcpy ((char *)&gap, ptr, sizeof(gap));
3547 ptr += sizeof(gap);
3548 gap = le16_to_cpu(gap);
3549 if (gap) {
3550 if (gap <= 8)
3551 ptr += gap;
3552 else
Dan Williams934d8bf2006-03-16 13:46:23 -05003553 airo_print_err(ai->dev->name,
3554 "gaplen too big. Problems will follow...");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555 }
3556 memcpy ((char *)buffer + hdrlen, ptr, len);
3557 ptr += len;
3558#ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
3559 if (ai->spy_data.spy_number > 0) {
3560 char *sa;
3561 struct iw_quality wstats;
3562 /* Prepare spy data : addr + qual */
3563 sa = (char*)buffer + 10;
3564 wstats.qual = hdr.rssi[0];
3565 if (ai->rssi)
3566 wstats.level = 0x100 - ai->rssi[hdr.rssi[1]].rssidBm;
3567 else
3568 wstats.level = (hdr.rssi[1] + 321) / 2;
Dan Williams41480af2005-05-10 09:45:51 -04003569 wstats.noise = ai->wstats.qual.noise;
3570 wstats.updated = IW_QUAL_QUAL_UPDATED
3571 | IW_QUAL_LEVEL_UPDATED
Jean Tourrilhesce6623c2005-09-02 11:45:10 -07003572 | IW_QUAL_DBM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573 /* Update spy records */
3574 wireless_spy_update(ai->dev, sa, &wstats);
3575 }
3576#endif /* IW_WIRELESS_SPY */
3577 skb->mac.raw = skb->data;
3578 skb->pkt_type = PACKET_OTHERHOST;
3579 skb->dev = ai->wifidev;
3580 skb->protocol = htons(ETH_P_802_2);
3581 skb->dev->last_rx = jiffies;
3582 skb->ip_summed = CHECKSUM_NONE;
3583 netif_rx( skb );
3584badrx:
3585 if (rxd.valid == 0) {
3586 rxd.valid = 1;
3587 rxd.rdy = 0;
3588 rxd.len = PKTSIZE;
3589 memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
3590 }
3591}
3592
3593static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
3594{
3595 Cmd cmd;
3596 Resp rsp;
3597 int status;
3598 int i;
3599 SsidRid mySsid;
3600 u16 lastindex;
3601 WepKeyRid wkr;
3602 int rc;
3603
3604 memset( &mySsid, 0, sizeof( mySsid ) );
Jesper Juhlb4558ea2005-10-28 16:53:13 -04003605 kfree (ai->flash);
3606 ai->flash = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607
3608 /* The NOP is the first step in getting the card going */
3609 cmd.cmd = NOP;
3610 cmd.parm0 = cmd.parm1 = cmd.parm2 = 0;
3611 if (lock && down_interruptible(&ai->sem))
3612 return ERROR;
3613 if ( issuecommand( ai, &cmd, &rsp ) != SUCCESS ) {
3614 if (lock)
3615 up(&ai->sem);
3616 return ERROR;
3617 }
3618 disable_MAC( ai, 0);
3619
3620 // Let's figure out if we need to use the AUX port
3621 if (!test_bit(FLAG_MPI,&ai->flags)) {
3622 cmd.cmd = CMD_ENABLEAUX;
3623 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
3624 if (lock)
3625 up(&ai->sem);
Dan Williams934d8bf2006-03-16 13:46:23 -05003626 airo_print_err(ai->dev->name, "Error checking for AUX port");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003627 return ERROR;
3628 }
3629 if (!aux_bap || rsp.status & 0xff00) {
3630 ai->bap_read = fast_bap_read;
Dan Williams934d8bf2006-03-16 13:46:23 -05003631 airo_print_dbg(ai->dev->name, "Doing fast bap_reads");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 } else {
3633 ai->bap_read = aux_bap_read;
Dan Williams934d8bf2006-03-16 13:46:23 -05003634 airo_print_dbg(ai->dev->name, "Doing AUX bap_reads");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003635 }
3636 }
3637 if (lock)
3638 up(&ai->sem);
3639 if (ai->config.len == 0) {
3640 tdsRssiRid rssi_rid;
3641 CapabilityRid cap_rid;
3642
Jesper Juhlb4558ea2005-10-28 16:53:13 -04003643 kfree(ai->APList);
3644 ai->APList = NULL;
3645 kfree(ai->SSID);
3646 ai->SSID = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647 // general configuration (read/modify/write)
3648 status = readConfigRid(ai, lock);
3649 if ( status != SUCCESS ) return ERROR;
3650
3651 status = readCapabilityRid(ai, &cap_rid, lock);
3652 if ( status != SUCCESS ) return ERROR;
3653
3654 status = PC4500_readrid(ai,RID_RSSI,&rssi_rid,sizeof(rssi_rid),lock);
3655 if ( status == SUCCESS ) {
3656 if (ai->rssi || (ai->rssi = kmalloc(512, GFP_KERNEL)) != NULL)
Dan Williams41480af2005-05-10 09:45:51 -04003657 memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512); /* Skip RID length member */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658 }
3659 else {
Jesper Juhlb4558ea2005-10-28 16:53:13 -04003660 kfree(ai->rssi);
3661 ai->rssi = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662 if (cap_rid.softCap & 8)
3663 ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
3664 else
Dan Williams934d8bf2006-03-16 13:46:23 -05003665 airo_print_warn(ai->dev->name, "unknown received signal "
3666 "level scale");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667 }
3668 ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS;
3669 ai->config.authType = AUTH_OPEN;
3670 ai->config.modulation = MOD_CCK;
3671
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 if ((cap_rid.len>=sizeof(cap_rid)) && (cap_rid.extSoftCap&1) &&
3673 (micsetup(ai) == SUCCESS)) {
3674 ai->config.opmode |= MODE_MIC;
3675 set_bit(FLAG_MIC_CAPABLE, &ai->flags);
3676 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677
3678 /* Save off the MAC */
3679 for( i = 0; i < ETH_ALEN; i++ ) {
3680 mac[i] = ai->config.macAddr[i];
3681 }
3682
3683 /* Check to see if there are any insmod configured
3684 rates to add */
3685 if ( rates[0] ) {
3686 int i = 0;
3687 memset(ai->config.rates,0,sizeof(ai->config.rates));
3688 for( i = 0; i < 8 && rates[i]; i++ ) {
3689 ai->config.rates[i] = rates[i];
3690 }
3691 }
3692 if ( basic_rate > 0 ) {
3693 int i;
3694 for( i = 0; i < 8; i++ ) {
3695 if ( ai->config.rates[i] == basic_rate ||
3696 !ai->config.rates ) {
3697 ai->config.rates[i] = basic_rate | 0x80;
3698 break;
3699 }
3700 }
3701 }
3702 set_bit (FLAG_COMMIT, &ai->flags);
3703 }
3704
3705 /* Setup the SSIDs if present */
3706 if ( ssids[0] ) {
3707 int i;
3708 for( i = 0; i < 3 && ssids[i]; i++ ) {
3709 mySsid.ssids[i].len = strlen(ssids[i]);
3710 if ( mySsid.ssids[i].len > 32 )
3711 mySsid.ssids[i].len = 32;
3712 memcpy(mySsid.ssids[i].ssid, ssids[i],
3713 mySsid.ssids[i].len);
3714 }
3715 mySsid.len = sizeof(mySsid);
3716 }
3717
3718 status = writeConfigRid(ai, lock);
3719 if ( status != SUCCESS ) return ERROR;
3720
3721 /* Set up the SSID list */
3722 if ( ssids[0] ) {
3723 status = writeSsidRid(ai, &mySsid, lock);
3724 if ( status != SUCCESS ) return ERROR;
3725 }
3726
3727 status = enable_MAC(ai, &rsp, lock);
3728 if ( status != SUCCESS || (rsp.status & 0xFF00) != 0) {
Dan Williams934d8bf2006-03-16 13:46:23 -05003729 airo_print_err(ai->dev->name, "Bad MAC enable reason = %x, rid = %x,"
3730 " offset = %d", rsp.rsp0, rsp.rsp1, rsp.rsp2 );
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731 return ERROR;
3732 }
3733
3734 /* Grab the initial wep key, we gotta save it for auto_wep */
3735 rc = readWepKeyRid(ai, &wkr, 1, lock);
3736 if (rc == SUCCESS) do {
3737 lastindex = wkr.kindex;
3738 if (wkr.kindex == 0xffff) {
3739 ai->defindex = wkr.mac[0];
3740 }
3741 rc = readWepKeyRid(ai, &wkr, 0, lock);
3742 } while(lastindex != wkr.kindex);
3743
3744 if (auto_wep) {
3745 ai->expires = RUN_AT(3*HZ);
3746 wake_up_interruptible(&ai->thr_wait);
3747 }
3748
3749 return SUCCESS;
3750}
3751
3752static u16 issuecommand(struct airo_info *ai, Cmd *pCmd, Resp *pRsp) {
3753 // Im really paranoid about letting it run forever!
3754 int max_tries = 600000;
3755
3756 if (IN4500(ai, EVSTAT) & EV_CMD)
3757 OUT4500(ai, EVACK, EV_CMD);
3758
3759 OUT4500(ai, PARAM0, pCmd->parm0);
3760 OUT4500(ai, PARAM1, pCmd->parm1);
3761 OUT4500(ai, PARAM2, pCmd->parm2);
3762 OUT4500(ai, COMMAND, pCmd->cmd);
3763
3764 while (max_tries-- && (IN4500(ai, EVSTAT) & EV_CMD) == 0) {
3765 if ((IN4500(ai, COMMAND)) == pCmd->cmd)
3766 // PC4500 didn't notice command, try again
3767 OUT4500(ai, COMMAND, pCmd->cmd);
3768 if (!in_atomic() && (max_tries & 255) == 0)
3769 schedule();
3770 }
3771
3772 if ( max_tries == -1 ) {
Dan Williams934d8bf2006-03-16 13:46:23 -05003773 airo_print_err(ai->dev->name,
3774 "Max tries exceeded when issueing command");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 if (IN4500(ai, COMMAND) & COMMAND_BUSY)
3776 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
3777 return ERROR;
3778 }
3779
3780 // command completed
3781 pRsp->status = IN4500(ai, STATUS);
3782 pRsp->rsp0 = IN4500(ai, RESP0);
3783 pRsp->rsp1 = IN4500(ai, RESP1);
3784 pRsp->rsp2 = IN4500(ai, RESP2);
3785 if ((pRsp->status & 0xff00)!=0 && pCmd->cmd != CMD_SOFTRESET) {
Dan Williams934d8bf2006-03-16 13:46:23 -05003786 airo_print_err(ai->dev->name, "cmd= %x\n", pCmd->cmd);
3787 airo_print_err(ai->dev->name, "status= %x\n", pRsp->status);
3788 airo_print_err(ai->dev->name, "Rsp0= %x\n", pRsp->rsp0);
3789 airo_print_err(ai->dev->name, "Rsp1= %x\n", pRsp->rsp1);
3790 airo_print_err(ai->dev->name, "Rsp2= %x\n", pRsp->rsp2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791 }
3792
3793 // clear stuck command busy if necessary
3794 if (IN4500(ai, COMMAND) & COMMAND_BUSY) {
3795 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
3796 }
3797 // acknowledge processing the status/response
3798 OUT4500(ai, EVACK, EV_CMD);
3799
3800 return SUCCESS;
3801}
3802
3803/* Sets up the bap to start exchange data. whichbap should
3804 * be one of the BAP0 or BAP1 defines. Locks should be held before
3805 * calling! */
3806static int bap_setup(struct airo_info *ai, u16 rid, u16 offset, int whichbap )
3807{
3808 int timeout = 50;
3809 int max_tries = 3;
3810
3811 OUT4500(ai, SELECT0+whichbap, rid);
3812 OUT4500(ai, OFFSET0+whichbap, offset);
3813 while (1) {
3814 int status = IN4500(ai, OFFSET0+whichbap);
3815 if (status & BAP_BUSY) {
3816 /* This isn't really a timeout, but its kinda
3817 close */
3818 if (timeout--) {
3819 continue;
3820 }
3821 } else if ( status & BAP_ERR ) {
3822 /* invalid rid or offset */
Dan Williams934d8bf2006-03-16 13:46:23 -05003823 airo_print_err(ai->dev->name, "BAP error %x %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 status, whichbap );
3825 return ERROR;
3826 } else if (status & BAP_DONE) { // success
3827 return SUCCESS;
3828 }
3829 if ( !(max_tries--) ) {
Dan Williams934d8bf2006-03-16 13:46:23 -05003830 airo_print_err(ai->dev->name,
3831 "airo: BAP setup error too many retries\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 return ERROR;
3833 }
3834 // -- PC4500 missed it, try again
3835 OUT4500(ai, SELECT0+whichbap, rid);
3836 OUT4500(ai, OFFSET0+whichbap, offset);
3837 timeout = 50;
3838 }
3839}
3840
3841/* should only be called by aux_bap_read. This aux function and the
3842 following use concepts not documented in the developers guide. I
3843 got them from a patch given to my by Aironet */
3844static u16 aux_setup(struct airo_info *ai, u16 page,
3845 u16 offset, u16 *len)
3846{
3847 u16 next;
3848
3849 OUT4500(ai, AUXPAGE, page);
3850 OUT4500(ai, AUXOFF, 0);
3851 next = IN4500(ai, AUXDATA);
3852 *len = IN4500(ai, AUXDATA)&0xff;
3853 if (offset != 4) OUT4500(ai, AUXOFF, offset);
3854 return next;
3855}
3856
3857/* requires call to bap_setup() first */
3858static int aux_bap_read(struct airo_info *ai, u16 *pu16Dst,
3859 int bytelen, int whichbap)
3860{
3861 u16 len;
3862 u16 page;
3863 u16 offset;
3864 u16 next;
3865 int words;
3866 int i;
3867 unsigned long flags;
3868
3869 spin_lock_irqsave(&ai->aux_lock, flags);
3870 page = IN4500(ai, SWS0+whichbap);
3871 offset = IN4500(ai, SWS2+whichbap);
3872 next = aux_setup(ai, page, offset, &len);
3873 words = (bytelen+1)>>1;
3874
3875 for (i=0; i<words;) {
3876 int count;
3877 count = (len>>1) < (words-i) ? (len>>1) : (words-i);
3878 if ( !do8bitIO )
3879 insw( ai->dev->base_addr+DATA0+whichbap,
3880 pu16Dst+i,count );
3881 else
3882 insb( ai->dev->base_addr+DATA0+whichbap,
3883 pu16Dst+i, count << 1 );
3884 i += count;
3885 if (i<words) {
3886 next = aux_setup(ai, next, 4, &len);
3887 }
3888 }
3889 spin_unlock_irqrestore(&ai->aux_lock, flags);
3890 return SUCCESS;
3891}
3892
3893
3894/* requires call to bap_setup() first */
3895static int fast_bap_read(struct airo_info *ai, u16 *pu16Dst,
3896 int bytelen, int whichbap)
3897{
3898 bytelen = (bytelen + 1) & (~1); // round up to even value
3899 if ( !do8bitIO )
3900 insw( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen>>1 );
3901 else
3902 insb( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen );
3903 return SUCCESS;
3904}
3905
3906/* requires call to bap_setup() first */
3907static int bap_write(struct airo_info *ai, const u16 *pu16Src,
3908 int bytelen, int whichbap)
3909{
3910 bytelen = (bytelen + 1) & (~1); // round up to even value
3911 if ( !do8bitIO )
3912 outsw( ai->dev->base_addr+DATA0+whichbap,
3913 pu16Src, bytelen>>1 );
3914 else
3915 outsb( ai->dev->base_addr+DATA0+whichbap, pu16Src, bytelen );
3916 return SUCCESS;
3917}
3918
3919static int PC4500_accessrid(struct airo_info *ai, u16 rid, u16 accmd)
3920{
3921 Cmd cmd; /* for issuing commands */
3922 Resp rsp; /* response from commands */
3923 u16 status;
3924
3925 memset(&cmd, 0, sizeof(cmd));
3926 cmd.cmd = accmd;
3927 cmd.parm0 = rid;
3928 status = issuecommand(ai, &cmd, &rsp);
3929 if (status != 0) return status;
3930 if ( (rsp.status & 0x7F00) != 0) {
3931 return (accmd << 8) + (rsp.rsp0 & 0xFF);
3932 }
3933 return 0;
3934}
3935
3936/* Note, that we are using BAP1 which is also used by transmit, so
3937 * we must get a lock. */
3938static int PC4500_readrid(struct airo_info *ai, u16 rid, void *pBuf, int len, int lock)
3939{
3940 u16 status;
3941 int rc = SUCCESS;
3942
3943 if (lock) {
3944 if (down_interruptible(&ai->sem))
3945 return ERROR;
3946 }
3947 if (test_bit(FLAG_MPI,&ai->flags)) {
3948 Cmd cmd;
3949 Resp rsp;
3950
3951 memset(&cmd, 0, sizeof(cmd));
3952 memset(&rsp, 0, sizeof(rsp));
3953 ai->config_desc.rid_desc.valid = 1;
3954 ai->config_desc.rid_desc.len = RIDSIZE;
3955 ai->config_desc.rid_desc.rid = 0;
3956 ai->config_desc.rid_desc.host_addr = ai->ridbus;
3957
3958 cmd.cmd = CMD_ACCESS;
3959 cmd.parm0 = rid;
3960
3961 memcpy_toio(ai->config_desc.card_ram_off,
3962 &ai->config_desc.rid_desc, sizeof(Rid));
3963
3964 rc = issuecommand(ai, &cmd, &rsp);
3965
3966 if (rsp.status & 0x7f00)
3967 rc = rsp.rsp0;
3968 if (!rc)
3969 memcpy(pBuf, ai->config_desc.virtual_host_addr, len);
3970 goto done;
3971 } else {
3972 if ((status = PC4500_accessrid(ai, rid, CMD_ACCESS))!=SUCCESS) {
3973 rc = status;
3974 goto done;
3975 }
3976 if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
3977 rc = ERROR;
3978 goto done;
3979 }
3980 // read the rid length field
3981 bap_read(ai, pBuf, 2, BAP1);
3982 // length for remaining part of rid
3983 len = min(len, (int)le16_to_cpu(*(u16*)pBuf)) - 2;
3984
3985 if ( len <= 2 ) {
Dan Williams934d8bf2006-03-16 13:46:23 -05003986 airo_print_err(ai->dev->name,
3987 "Rid %x has a length of %d which is too short",
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988 (int)rid, (int)len );
3989 rc = ERROR;
3990 goto done;
3991 }
3992 // read remainder of the rid
3993 rc = bap_read(ai, ((u16*)pBuf)+1, len, BAP1);
3994 }
3995done:
3996 if (lock)
3997 up(&ai->sem);
3998 return rc;
3999}
4000
4001/* Note, that we are using BAP1 which is also used by transmit, so
4002 * make sure this isnt called when a transmit is happening */
4003static int PC4500_writerid(struct airo_info *ai, u16 rid,
4004 const void *pBuf, int len, int lock)
4005{
4006 u16 status;
4007 int rc = SUCCESS;
4008
4009 *(u16*)pBuf = cpu_to_le16((u16)len);
4010
4011 if (lock) {
4012 if (down_interruptible(&ai->sem))
4013 return ERROR;
4014 }
4015 if (test_bit(FLAG_MPI,&ai->flags)) {
4016 Cmd cmd;
4017 Resp rsp;
4018
Dan Streetmanf89b2322005-11-11 11:41:42 -05004019 if (test_bit(FLAG_ENABLED, &ai->flags) && (RID_WEP_TEMP != rid))
Dan Williams934d8bf2006-03-16 13:46:23 -05004020 airo_print_err(ai->dev->name,
4021 "%s: MAC should be disabled (rid=%04x)",
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 __FUNCTION__, rid);
4023 memset(&cmd, 0, sizeof(cmd));
4024 memset(&rsp, 0, sizeof(rsp));
4025
4026 ai->config_desc.rid_desc.valid = 1;
4027 ai->config_desc.rid_desc.len = *((u16 *)pBuf);
4028 ai->config_desc.rid_desc.rid = 0;
4029
4030 cmd.cmd = CMD_WRITERID;
4031 cmd.parm0 = rid;
4032
4033 memcpy_toio(ai->config_desc.card_ram_off,
4034 &ai->config_desc.rid_desc, sizeof(Rid));
4035
4036 if (len < 4 || len > 2047) {
Dan Williams934d8bf2006-03-16 13:46:23 -05004037 airo_print_err(ai->dev->name, "%s: len=%d", __FUNCTION__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 rc = -1;
4039 } else {
4040 memcpy((char *)ai->config_desc.virtual_host_addr,
4041 pBuf, len);
4042
4043 rc = issuecommand(ai, &cmd, &rsp);
4044 if ((rc & 0xff00) != 0) {
Dan Williams934d8bf2006-03-16 13:46:23 -05004045 airo_print_err(ai->dev->name, "%s: Write rid Error %d",
4046 __FUNCTION__, rc);
4047 airo_print_err(ai->dev->name, "%s: Cmd=%04x",
4048 __FUNCTION__, cmd.cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049 }
4050
4051 if ((rsp.status & 0x7f00))
4052 rc = rsp.rsp0;
4053 }
4054 } else {
4055 // --- first access so that we can write the rid data
4056 if ( (status = PC4500_accessrid(ai, rid, CMD_ACCESS)) != 0) {
4057 rc = status;
4058 goto done;
4059 }
4060 // --- now write the rid data
4061 if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
4062 rc = ERROR;
4063 goto done;
4064 }
4065 bap_write(ai, pBuf, len, BAP1);
4066 // ---now commit the rid data
4067 rc = PC4500_accessrid(ai, rid, 0x100|CMD_ACCESS);
4068 }
4069done:
4070 if (lock)
4071 up(&ai->sem);
4072 return rc;
4073}
4074
4075/* Allocates a FID to be used for transmitting packets. We only use
4076 one for now. */
4077static u16 transmit_allocate(struct airo_info *ai, int lenPayload, int raw)
4078{
4079 unsigned int loop = 3000;
4080 Cmd cmd;
4081 Resp rsp;
4082 u16 txFid;
4083 u16 txControl;
4084
4085 cmd.cmd = CMD_ALLOCATETX;
4086 cmd.parm0 = lenPayload;
4087 if (down_interruptible(&ai->sem))
4088 return ERROR;
4089 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
4090 txFid = ERROR;
4091 goto done;
4092 }
4093 if ( (rsp.status & 0xFF00) != 0) {
4094 txFid = ERROR;
4095 goto done;
4096 }
4097 /* wait for the allocate event/indication
4098 * It makes me kind of nervous that this can just sit here and spin,
4099 * but in practice it only loops like four times. */
4100 while (((IN4500(ai, EVSTAT) & EV_ALLOC) == 0) && --loop);
4101 if (!loop) {
4102 txFid = ERROR;
4103 goto done;
4104 }
4105
4106 // get the allocated fid and acknowledge
4107 txFid = IN4500(ai, TXALLOCFID);
4108 OUT4500(ai, EVACK, EV_ALLOC);
4109
4110 /* The CARD is pretty cool since it converts the ethernet packet
4111 * into 802.11. Also note that we don't release the FID since we
4112 * will be using the same one over and over again. */
4113 /* We only have to setup the control once since we are not
4114 * releasing the fid. */
4115 if (raw)
4116 txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_11
4117 | TXCTL_ETHERNET | TXCTL_NORELEASE);
4118 else
4119 txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_3
4120 | TXCTL_ETHERNET | TXCTL_NORELEASE);
4121 if (bap_setup(ai, txFid, 0x0008, BAP1) != SUCCESS)
4122 txFid = ERROR;
4123 else
4124 bap_write(ai, &txControl, sizeof(txControl), BAP1);
4125
4126done:
4127 up(&ai->sem);
4128
4129 return txFid;
4130}
4131
4132/* In general BAP1 is dedicated to transmiting packets. However,
4133 since we need a BAP when accessing RIDs, we also use BAP1 for that.
4134 Make sure the BAP1 spinlock is held when this is called. */
4135static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket)
4136{
4137 u16 payloadLen;
4138 Cmd cmd;
4139 Resp rsp;
4140 int miclen = 0;
4141 u16 txFid = len;
4142 MICBuffer pMic;
4143
4144 len >>= 16;
4145
4146 if (len <= ETH_ALEN * 2) {
Dan Williams934d8bf2006-03-16 13:46:23 -05004147 airo_print_warn(ai->dev->name, "Short packet %d", len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148 return ERROR;
4149 }
4150 len -= ETH_ALEN * 2;
4151
Linus Torvalds1da177e2005-04-16 15:20:36 -07004152 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
4153 (ntohs(((u16 *)pPacket)[6]) != 0x888E)) {
4154 if (encapsulate(ai,(etherHead *)pPacket,&pMic,len) != SUCCESS)
4155 return ERROR;
4156 miclen = sizeof(pMic);
4157 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158 // packet is destination[6], source[6], payload[len-12]
4159 // write the payload length and dst/src/payload
4160 if (bap_setup(ai, txFid, 0x0036, BAP1) != SUCCESS) return ERROR;
4161 /* The hardware addresses aren't counted as part of the payload, so
4162 * we have to subtract the 12 bytes for the addresses off */
4163 payloadLen = cpu_to_le16(len + miclen);
4164 bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
4165 bap_write(ai, (const u16*)pPacket, sizeof(etherHead), BAP1);
4166 if (miclen)
4167 bap_write(ai, (const u16*)&pMic, miclen, BAP1);
4168 bap_write(ai, (const u16*)(pPacket + sizeof(etherHead)), len, BAP1);
4169 // issue the transmit command
4170 memset( &cmd, 0, sizeof( cmd ) );
4171 cmd.cmd = CMD_TRANSMIT;
4172 cmd.parm0 = txFid;
4173 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
4174 if ( (rsp.status & 0xFF00) != 0) return ERROR;
4175 return SUCCESS;
4176}
4177
4178static int transmit_802_11_packet(struct airo_info *ai, int len, char *pPacket)
4179{
4180 u16 fc, payloadLen;
4181 Cmd cmd;
4182 Resp rsp;
4183 int hdrlen;
4184 struct {
4185 u8 addr4[ETH_ALEN];
4186 u16 gaplen;
4187 u8 gap[6];
4188 } gap;
4189 u16 txFid = len;
4190 len >>= 16;
4191 gap.gaplen = 6;
4192
4193 fc = le16_to_cpu(*(const u16*)pPacket);
4194 switch (fc & 0xc) {
4195 case 4:
4196 if ((fc & 0xe0) == 0xc0)
4197 hdrlen = 10;
4198 else
4199 hdrlen = 16;
4200 break;
4201 case 8:
4202 if ((fc&0x300)==0x300){
4203 hdrlen = 30;
4204 break;
4205 }
4206 default:
4207 hdrlen = 24;
4208 }
4209
4210 if (len < hdrlen) {
Dan Williams934d8bf2006-03-16 13:46:23 -05004211 airo_print_warn(ai->dev->name, "Short packet %d", len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 return ERROR;
4213 }
4214
4215 /* packet is 802.11 header + payload
4216 * write the payload length and dst/src/payload */
4217 if (bap_setup(ai, txFid, 6, BAP1) != SUCCESS) return ERROR;
4218 /* The 802.11 header aren't counted as part of the payload, so
4219 * we have to subtract the header bytes off */
4220 payloadLen = cpu_to_le16(len-hdrlen);
4221 bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
4222 if (bap_setup(ai, txFid, 0x0014, BAP1) != SUCCESS) return ERROR;
4223 bap_write(ai, (const u16*)pPacket, hdrlen, BAP1);
4224 bap_write(ai, hdrlen == 30 ?
4225 (const u16*)&gap.gaplen : (const u16*)&gap, 38 - hdrlen, BAP1);
4226
4227 bap_write(ai, (const u16*)(pPacket + hdrlen), len - hdrlen, BAP1);
4228 // issue the transmit command
4229 memset( &cmd, 0, sizeof( cmd ) );
4230 cmd.cmd = CMD_TRANSMIT;
4231 cmd.parm0 = txFid;
4232 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
4233 if ( (rsp.status & 0xFF00) != 0) return ERROR;
4234 return SUCCESS;
4235}
4236
4237/*
4238 * This is the proc_fs routines. It is a bit messier than I would
4239 * like! Feel free to clean it up!
4240 */
4241
4242static ssize_t proc_read( struct file *file,
4243 char __user *buffer,
4244 size_t len,
4245 loff_t *offset);
4246
4247static ssize_t proc_write( struct file *file,
4248 const char __user *buffer,
4249 size_t len,
4250 loff_t *offset );
4251static int proc_close( struct inode *inode, struct file *file );
4252
4253static int proc_stats_open( struct inode *inode, struct file *file );
4254static int proc_statsdelta_open( struct inode *inode, struct file *file );
4255static int proc_status_open( struct inode *inode, struct file *file );
4256static int proc_SSID_open( struct inode *inode, struct file *file );
4257static int proc_APList_open( struct inode *inode, struct file *file );
4258static int proc_BSSList_open( struct inode *inode, struct file *file );
4259static int proc_config_open( struct inode *inode, struct file *file );
4260static int proc_wepkey_open( struct inode *inode, struct file *file );
4261
4262static struct file_operations proc_statsdelta_ops = {
4263 .read = proc_read,
4264 .open = proc_statsdelta_open,
4265 .release = proc_close
4266};
4267
4268static struct file_operations proc_stats_ops = {
4269 .read = proc_read,
4270 .open = proc_stats_open,
4271 .release = proc_close
4272};
4273
4274static struct file_operations proc_status_ops = {
4275 .read = proc_read,
4276 .open = proc_status_open,
4277 .release = proc_close
4278};
4279
4280static struct file_operations proc_SSID_ops = {
4281 .read = proc_read,
4282 .write = proc_write,
4283 .open = proc_SSID_open,
4284 .release = proc_close
4285};
4286
4287static struct file_operations proc_BSSList_ops = {
4288 .read = proc_read,
4289 .write = proc_write,
4290 .open = proc_BSSList_open,
4291 .release = proc_close
4292};
4293
4294static struct file_operations proc_APList_ops = {
4295 .read = proc_read,
4296 .write = proc_write,
4297 .open = proc_APList_open,
4298 .release = proc_close
4299};
4300
4301static struct file_operations proc_config_ops = {
4302 .read = proc_read,
4303 .write = proc_write,
4304 .open = proc_config_open,
4305 .release = proc_close
4306};
4307
4308static struct file_operations proc_wepkey_ops = {
4309 .read = proc_read,
4310 .write = proc_write,
4311 .open = proc_wepkey_open,
4312 .release = proc_close
4313};
4314
4315static struct proc_dir_entry *airo_entry;
4316
4317struct proc_data {
4318 int release_buffer;
4319 int readlen;
4320 char *rbuffer;
4321 int writelen;
4322 int maxwritelen;
4323 char *wbuffer;
4324 void (*on_close) (struct inode *, struct file *);
4325};
4326
4327#ifndef SETPROC_OPS
4328#define SETPROC_OPS(entry, ops) (entry)->proc_fops = &(ops)
4329#endif
4330
4331static int setup_proc_entry( struct net_device *dev,
4332 struct airo_info *apriv ) {
4333 struct proc_dir_entry *entry;
4334 /* First setup the device directory */
4335 strcpy(apriv->proc_name,dev->name);
4336 apriv->proc_entry = create_proc_entry(apriv->proc_name,
4337 S_IFDIR|airo_perm,
4338 airo_entry);
4339 apriv->proc_entry->uid = proc_uid;
4340 apriv->proc_entry->gid = proc_gid;
4341 apriv->proc_entry->owner = THIS_MODULE;
4342
4343 /* Setup the StatsDelta */
4344 entry = create_proc_entry("StatsDelta",
4345 S_IFREG | (S_IRUGO&proc_perm),
4346 apriv->proc_entry);
4347 entry->uid = proc_uid;
4348 entry->gid = proc_gid;
4349 entry->data = dev;
4350 entry->owner = THIS_MODULE;
4351 SETPROC_OPS(entry, proc_statsdelta_ops);
4352
4353 /* Setup the Stats */
4354 entry = create_proc_entry("Stats",
4355 S_IFREG | (S_IRUGO&proc_perm),
4356 apriv->proc_entry);
4357 entry->uid = proc_uid;
4358 entry->gid = proc_gid;
4359 entry->data = dev;
4360 entry->owner = THIS_MODULE;
4361 SETPROC_OPS(entry, proc_stats_ops);
4362
4363 /* Setup the Status */
4364 entry = create_proc_entry("Status",
4365 S_IFREG | (S_IRUGO&proc_perm),
4366 apriv->proc_entry);
4367 entry->uid = proc_uid;
4368 entry->gid = proc_gid;
4369 entry->data = dev;
4370 entry->owner = THIS_MODULE;
4371 SETPROC_OPS(entry, proc_status_ops);
4372
4373 /* Setup the Config */
4374 entry = create_proc_entry("Config",
4375 S_IFREG | proc_perm,
4376 apriv->proc_entry);
4377 entry->uid = proc_uid;
4378 entry->gid = proc_gid;
4379 entry->data = dev;
4380 entry->owner = THIS_MODULE;
4381 SETPROC_OPS(entry, proc_config_ops);
4382
4383 /* Setup the SSID */
4384 entry = create_proc_entry("SSID",
4385 S_IFREG | proc_perm,
4386 apriv->proc_entry);
4387 entry->uid = proc_uid;
4388 entry->gid = proc_gid;
4389 entry->data = dev;
4390 entry->owner = THIS_MODULE;
4391 SETPROC_OPS(entry, proc_SSID_ops);
4392
4393 /* Setup the APList */
4394 entry = create_proc_entry("APList",
4395 S_IFREG | proc_perm,
4396 apriv->proc_entry);
4397 entry->uid = proc_uid;
4398 entry->gid = proc_gid;
4399 entry->data = dev;
4400 entry->owner = THIS_MODULE;
4401 SETPROC_OPS(entry, proc_APList_ops);
4402
4403 /* Setup the BSSList */
4404 entry = create_proc_entry("BSSList",
4405 S_IFREG | proc_perm,
4406 apriv->proc_entry);
4407 entry->uid = proc_uid;
4408 entry->gid = proc_gid;
4409 entry->data = dev;
4410 entry->owner = THIS_MODULE;
4411 SETPROC_OPS(entry, proc_BSSList_ops);
4412
4413 /* Setup the WepKey */
4414 entry = create_proc_entry("WepKey",
4415 S_IFREG | proc_perm,
4416 apriv->proc_entry);
4417 entry->uid = proc_uid;
4418 entry->gid = proc_gid;
4419 entry->data = dev;
4420 entry->owner = THIS_MODULE;
4421 SETPROC_OPS(entry, proc_wepkey_ops);
4422
4423 return 0;
4424}
4425
4426static int takedown_proc_entry( struct net_device *dev,
4427 struct airo_info *apriv ) {
4428 if ( !apriv->proc_entry->namelen ) return 0;
4429 remove_proc_entry("Stats",apriv->proc_entry);
4430 remove_proc_entry("StatsDelta",apriv->proc_entry);
4431 remove_proc_entry("Status",apriv->proc_entry);
4432 remove_proc_entry("Config",apriv->proc_entry);
4433 remove_proc_entry("SSID",apriv->proc_entry);
4434 remove_proc_entry("APList",apriv->proc_entry);
4435 remove_proc_entry("BSSList",apriv->proc_entry);
4436 remove_proc_entry("WepKey",apriv->proc_entry);
4437 remove_proc_entry(apriv->proc_name,airo_entry);
4438 return 0;
4439}
4440
4441/*
4442 * What we want from the proc_fs is to be able to efficiently read
4443 * and write the configuration. To do this, we want to read the
4444 * configuration when the file is opened and write it when the file is
4445 * closed. So basically we allocate a read buffer at open and fill it
4446 * with data, and allocate a write buffer and read it at close.
4447 */
4448
4449/*
4450 * The read routine is generic, it relies on the preallocated rbuffer
4451 * to supply the data.
4452 */
4453static ssize_t proc_read( struct file *file,
4454 char __user *buffer,
4455 size_t len,
4456 loff_t *offset )
4457{
4458 loff_t pos = *offset;
4459 struct proc_data *priv = (struct proc_data*)file->private_data;
4460
4461 if (!priv->rbuffer)
4462 return -EINVAL;
4463
4464 if (pos < 0)
4465 return -EINVAL;
4466 if (pos >= priv->readlen)
4467 return 0;
4468 if (len > priv->readlen - pos)
4469 len = priv->readlen - pos;
4470 if (copy_to_user(buffer, priv->rbuffer + pos, len))
4471 return -EFAULT;
4472 *offset = pos + len;
4473 return len;
4474}
4475
4476/*
4477 * The write routine is generic, it fills in a preallocated rbuffer
4478 * to supply the data.
4479 */
4480static ssize_t proc_write( struct file *file,
4481 const char __user *buffer,
4482 size_t len,
4483 loff_t *offset )
4484{
4485 loff_t pos = *offset;
4486 struct proc_data *priv = (struct proc_data*)file->private_data;
4487
4488 if (!priv->wbuffer)
4489 return -EINVAL;
4490
4491 if (pos < 0)
4492 return -EINVAL;
4493 if (pos >= priv->maxwritelen)
4494 return 0;
4495 if (len > priv->maxwritelen - pos)
4496 len = priv->maxwritelen - pos;
4497 if (copy_from_user(priv->wbuffer + pos, buffer, len))
4498 return -EFAULT;
4499 if ( pos + len > priv->writelen )
4500 priv->writelen = len + file->f_pos;
4501 *offset = pos + len;
4502 return len;
4503}
4504
4505static int proc_status_open( struct inode *inode, struct file *file ) {
4506 struct proc_data *data;
4507 struct proc_dir_entry *dp = PDE(inode);
4508 struct net_device *dev = dp->data;
4509 struct airo_info *apriv = dev->priv;
4510 CapabilityRid cap_rid;
4511 StatusRid status_rid;
4512 int i;
4513
Panagiotis Issarisb69a3aa2005-11-08 00:03:15 +01004514 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004515 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004516 data = (struct proc_data *)file->private_data;
4517 if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
4518 kfree (file->private_data);
4519 return -ENOMEM;
4520 }
4521
4522 readStatusRid(apriv, &status_rid, 1);
4523 readCapabilityRid(apriv, &cap_rid, 1);
4524
4525 i = sprintf(data->rbuffer, "Status: %s%s%s%s%s%s%s%s%s\n",
4526 status_rid.mode & 1 ? "CFG ": "",
4527 status_rid.mode & 2 ? "ACT ": "",
4528 status_rid.mode & 0x10 ? "SYN ": "",
4529 status_rid.mode & 0x20 ? "LNK ": "",
4530 status_rid.mode & 0x40 ? "LEAP ": "",
4531 status_rid.mode & 0x80 ? "PRIV ": "",
4532 status_rid.mode & 0x100 ? "KEY ": "",
4533 status_rid.mode & 0x200 ? "WEP ": "",
4534 status_rid.mode & 0x8000 ? "ERR ": "");
4535 sprintf( data->rbuffer+i, "Mode: %x\n"
4536 "Signal Strength: %d\n"
4537 "Signal Quality: %d\n"
4538 "SSID: %-.*s\n"
4539 "AP: %-.16s\n"
4540 "Freq: %d\n"
4541 "BitRate: %dmbs\n"
4542 "Driver Version: %s\n"
4543 "Device: %s\nManufacturer: %s\nFirmware Version: %s\n"
4544 "Radio type: %x\nCountry: %x\nHardware Version: %x\n"
4545 "Software Version: %x\nSoftware Subversion: %x\n"
4546 "Boot block version: %x\n",
4547 (int)status_rid.mode,
4548 (int)status_rid.normalizedSignalStrength,
4549 (int)status_rid.signalQuality,
4550 (int)status_rid.SSIDlen,
4551 status_rid.SSID,
4552 status_rid.apName,
4553 (int)status_rid.channel,
4554 (int)status_rid.currentXmitRate/2,
4555 version,
4556 cap_rid.prodName,
4557 cap_rid.manName,
4558 cap_rid.prodVer,
4559 cap_rid.radioType,
4560 cap_rid.country,
4561 cap_rid.hardVer,
4562 (int)cap_rid.softVer,
4563 (int)cap_rid.softSubVer,
4564 (int)cap_rid.bootBlockVer );
4565 data->readlen = strlen( data->rbuffer );
4566 return 0;
4567}
4568
4569static int proc_stats_rid_open(struct inode*, struct file*, u16);
4570static int proc_statsdelta_open( struct inode *inode,
4571 struct file *file ) {
4572 if (file->f_mode&FMODE_WRITE) {
4573 return proc_stats_rid_open(inode, file, RID_STATSDELTACLEAR);
4574 }
4575 return proc_stats_rid_open(inode, file, RID_STATSDELTA);
4576}
4577
4578static int proc_stats_open( struct inode *inode, struct file *file ) {
4579 return proc_stats_rid_open(inode, file, RID_STATS);
4580}
4581
4582static int proc_stats_rid_open( struct inode *inode,
4583 struct file *file,
4584 u16 rid ) {
4585 struct proc_data *data;
4586 struct proc_dir_entry *dp = PDE(inode);
4587 struct net_device *dev = dp->data;
4588 struct airo_info *apriv = dev->priv;
4589 StatsRid stats;
4590 int i, j;
4591 u32 *vals = stats.vals;
4592
Panagiotis Issarisb69a3aa2005-11-08 00:03:15 +01004593 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004594 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004595 data = (struct proc_data *)file->private_data;
4596 if ((data->rbuffer = kmalloc( 4096, GFP_KERNEL )) == NULL) {
4597 kfree (file->private_data);
4598 return -ENOMEM;
4599 }
4600
4601 readStatsRid(apriv, &stats, rid, 1);
4602
4603 j = 0;
4604 for(i=0; statsLabels[i]!=(char *)-1 &&
4605 i*4<stats.len; i++){
4606 if (!statsLabels[i]) continue;
4607 if (j+strlen(statsLabels[i])+16>4096) {
Dan Williams934d8bf2006-03-16 13:46:23 -05004608 airo_print_warn(apriv->dev->name,
4609 "Potentially disasterous buffer overflow averted!");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004610 break;
4611 }
4612 j+=sprintf(data->rbuffer+j, "%s: %u\n", statsLabels[i], vals[i]);
4613 }
4614 if (i*4>=stats.len){
Dan Williams934d8bf2006-03-16 13:46:23 -05004615 airo_print_warn(apriv->dev->name, "Got a short rid");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004616 }
4617 data->readlen = j;
4618 return 0;
4619}
4620
4621static int get_dec_u16( char *buffer, int *start, int limit ) {
4622 u16 value;
4623 int valid = 0;
4624 for( value = 0; buffer[*start] >= '0' &&
4625 buffer[*start] <= '9' &&
4626 *start < limit; (*start)++ ) {
4627 valid = 1;
4628 value *= 10;
4629 value += buffer[*start] - '0';
4630 }
4631 if ( !valid ) return -1;
4632 return value;
4633}
4634
4635static int airo_config_commit(struct net_device *dev,
4636 struct iw_request_info *info, void *zwrq,
4637 char *extra);
4638
4639static void proc_config_on_close( struct inode *inode, struct file *file ) {
4640 struct proc_data *data = file->private_data;
4641 struct proc_dir_entry *dp = PDE(inode);
4642 struct net_device *dev = dp->data;
4643 struct airo_info *ai = dev->priv;
4644 char *line;
4645
4646 if ( !data->writelen ) return;
4647
4648 readConfigRid(ai, 1);
4649 set_bit (FLAG_COMMIT, &ai->flags);
4650
4651 line = data->wbuffer;
4652 while( line[0] ) {
4653/*** Mode processing */
4654 if ( !strncmp( line, "Mode: ", 6 ) ) {
4655 line += 6;
4656 if ((ai->config.rmode & 0xff) >= RXMODE_RFMON)
4657 set_bit (FLAG_RESET, &ai->flags);
4658 ai->config.rmode &= 0xfe00;
4659 clear_bit (FLAG_802_11, &ai->flags);
4660 ai->config.opmode &= 0xFF00;
4661 ai->config.scanMode = SCANMODE_ACTIVE;
4662 if ( line[0] == 'a' ) {
4663 ai->config.opmode |= 0;
4664 } else {
4665 ai->config.opmode |= 1;
4666 if ( line[0] == 'r' ) {
4667 ai->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
4668 ai->config.scanMode = SCANMODE_PASSIVE;
4669 set_bit (FLAG_802_11, &ai->flags);
4670 } else if ( line[0] == 'y' ) {
4671 ai->config.rmode |= RXMODE_RFMON_ANYBSS | RXMODE_DISABLE_802_3_HEADER;
4672 ai->config.scanMode = SCANMODE_PASSIVE;
4673 set_bit (FLAG_802_11, &ai->flags);
4674 } else if ( line[0] == 'l' )
4675 ai->config.rmode |= RXMODE_LANMON;
4676 }
4677 set_bit (FLAG_COMMIT, &ai->flags);
4678 }
4679
4680/*** Radio status */
4681 else if (!strncmp(line,"Radio: ", 7)) {
4682 line += 7;
4683 if (!strncmp(line,"off",3)) {
4684 set_bit (FLAG_RADIO_OFF, &ai->flags);
4685 } else {
4686 clear_bit (FLAG_RADIO_OFF, &ai->flags);
4687 }
4688 }
4689/*** NodeName processing */
4690 else if ( !strncmp( line, "NodeName: ", 10 ) ) {
4691 int j;
4692
4693 line += 10;
4694 memset( ai->config.nodeName, 0, 16 );
4695/* Do the name, assume a space between the mode and node name */
4696 for( j = 0; j < 16 && line[j] != '\n'; j++ ) {
4697 ai->config.nodeName[j] = line[j];
4698 }
4699 set_bit (FLAG_COMMIT, &ai->flags);
4700 }
4701
4702/*** PowerMode processing */
4703 else if ( !strncmp( line, "PowerMode: ", 11 ) ) {
4704 line += 11;
4705 if ( !strncmp( line, "PSPCAM", 6 ) ) {
4706 ai->config.powerSaveMode = POWERSAVE_PSPCAM;
4707 set_bit (FLAG_COMMIT, &ai->flags);
4708 } else if ( !strncmp( line, "PSP", 3 ) ) {
4709 ai->config.powerSaveMode = POWERSAVE_PSP;
4710 set_bit (FLAG_COMMIT, &ai->flags);
4711 } else {
4712 ai->config.powerSaveMode = POWERSAVE_CAM;
4713 set_bit (FLAG_COMMIT, &ai->flags);
4714 }
4715 } else if ( !strncmp( line, "DataRates: ", 11 ) ) {
4716 int v, i = 0, k = 0; /* i is index into line,
4717 k is index to rates */
4718
4719 line += 11;
4720 while((v = get_dec_u16(line, &i, 3))!=-1) {
4721 ai->config.rates[k++] = (u8)v;
4722 line += i + 1;
4723 i = 0;
4724 }
4725 set_bit (FLAG_COMMIT, &ai->flags);
4726 } else if ( !strncmp( line, "Channel: ", 9 ) ) {
4727 int v, i = 0;
4728 line += 9;
4729 v = get_dec_u16(line, &i, i+3);
4730 if ( v != -1 ) {
4731 ai->config.channelSet = (u16)v;
4732 set_bit (FLAG_COMMIT, &ai->flags);
4733 }
4734 } else if ( !strncmp( line, "XmitPower: ", 11 ) ) {
4735 int v, i = 0;
4736 line += 11;
4737 v = get_dec_u16(line, &i, i+3);
4738 if ( v != -1 ) {
4739 ai->config.txPower = (u16)v;
4740 set_bit (FLAG_COMMIT, &ai->flags);
4741 }
4742 } else if ( !strncmp( line, "WEP: ", 5 ) ) {
4743 line += 5;
4744 switch( line[0] ) {
4745 case 's':
4746 ai->config.authType = (u16)AUTH_SHAREDKEY;
4747 break;
4748 case 'e':
4749 ai->config.authType = (u16)AUTH_ENCRYPT;
4750 break;
4751 default:
4752 ai->config.authType = (u16)AUTH_OPEN;
4753 break;
4754 }
4755 set_bit (FLAG_COMMIT, &ai->flags);
4756 } else if ( !strncmp( line, "LongRetryLimit: ", 16 ) ) {
4757 int v, i = 0;
4758
4759 line += 16;
4760 v = get_dec_u16(line, &i, 3);
4761 v = (v<0) ? 0 : ((v>255) ? 255 : v);
4762 ai->config.longRetryLimit = (u16)v;
4763 set_bit (FLAG_COMMIT, &ai->flags);
4764 } else if ( !strncmp( line, "ShortRetryLimit: ", 17 ) ) {
4765 int v, i = 0;
4766
4767 line += 17;
4768 v = get_dec_u16(line, &i, 3);
4769 v = (v<0) ? 0 : ((v>255) ? 255 : v);
4770 ai->config.shortRetryLimit = (u16)v;
4771 set_bit (FLAG_COMMIT, &ai->flags);
4772 } else if ( !strncmp( line, "RTSThreshold: ", 14 ) ) {
4773 int v, i = 0;
4774
4775 line += 14;
4776 v = get_dec_u16(line, &i, 4);
4777 v = (v<0) ? 0 : ((v>2312) ? 2312 : v);
4778 ai->config.rtsThres = (u16)v;
4779 set_bit (FLAG_COMMIT, &ai->flags);
4780 } else if ( !strncmp( line, "TXMSDULifetime: ", 16 ) ) {
4781 int v, i = 0;
4782
4783 line += 16;
4784 v = get_dec_u16(line, &i, 5);
4785 v = (v<0) ? 0 : v;
4786 ai->config.txLifetime = (u16)v;
4787 set_bit (FLAG_COMMIT, &ai->flags);
4788 } else if ( !strncmp( line, "RXMSDULifetime: ", 16 ) ) {
4789 int v, i = 0;
4790
4791 line += 16;
4792 v = get_dec_u16(line, &i, 5);
4793 v = (v<0) ? 0 : v;
4794 ai->config.rxLifetime = (u16)v;
4795 set_bit (FLAG_COMMIT, &ai->flags);
4796 } else if ( !strncmp( line, "TXDiversity: ", 13 ) ) {
4797 ai->config.txDiversity =
4798 (line[13]=='l') ? 1 :
4799 ((line[13]=='r')? 2: 3);
4800 set_bit (FLAG_COMMIT, &ai->flags);
4801 } else if ( !strncmp( line, "RXDiversity: ", 13 ) ) {
4802 ai->config.rxDiversity =
4803 (line[13]=='l') ? 1 :
4804 ((line[13]=='r')? 2: 3);
4805 set_bit (FLAG_COMMIT, &ai->flags);
4806 } else if ( !strncmp( line, "FragThreshold: ", 15 ) ) {
4807 int v, i = 0;
4808
4809 line += 15;
4810 v = get_dec_u16(line, &i, 4);
4811 v = (v<256) ? 256 : ((v>2312) ? 2312 : v);
4812 v = v & 0xfffe; /* Make sure its even */
4813 ai->config.fragThresh = (u16)v;
4814 set_bit (FLAG_COMMIT, &ai->flags);
4815 } else if (!strncmp(line, "Modulation: ", 12)) {
4816 line += 12;
4817 switch(*line) {
4818 case 'd': ai->config.modulation=MOD_DEFAULT; set_bit(FLAG_COMMIT, &ai->flags); break;
4819 case 'c': ai->config.modulation=MOD_CCK; set_bit(FLAG_COMMIT, &ai->flags); break;
4820 case 'm': ai->config.modulation=MOD_MOK; set_bit(FLAG_COMMIT, &ai->flags); break;
Dan Williams934d8bf2006-03-16 13:46:23 -05004821 default: airo_print_warn(ai->dev->name, "Unknown modulation");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004822 }
4823 } else if (!strncmp(line, "Preamble: ", 10)) {
4824 line += 10;
4825 switch(*line) {
4826 case 'a': ai->config.preamble=PREAMBLE_AUTO; set_bit(FLAG_COMMIT, &ai->flags); break;
4827 case 'l': ai->config.preamble=PREAMBLE_LONG; set_bit(FLAG_COMMIT, &ai->flags); break;
4828 case 's': ai->config.preamble=PREAMBLE_SHORT; set_bit(FLAG_COMMIT, &ai->flags); break;
Dan Williams934d8bf2006-03-16 13:46:23 -05004829 default: airo_print_warn(ai->dev->name, "Unknown preamble");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004830 }
4831 } else {
Dan Williams934d8bf2006-03-16 13:46:23 -05004832 airo_print_warn(ai->dev->name, "Couldn't figure out %s", line);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004833 }
4834 while( line[0] && line[0] != '\n' ) line++;
4835 if ( line[0] ) line++;
4836 }
4837 airo_config_commit(dev, NULL, NULL, NULL);
4838}
4839
4840static char *get_rmode(u16 mode) {
4841 switch(mode&0xff) {
4842 case RXMODE_RFMON: return "rfmon";
4843 case RXMODE_RFMON_ANYBSS: return "yna (any) bss rfmon";
4844 case RXMODE_LANMON: return "lanmon";
4845 }
4846 return "ESS";
4847}
4848
4849static int proc_config_open( struct inode *inode, struct file *file ) {
4850 struct proc_data *data;
4851 struct proc_dir_entry *dp = PDE(inode);
4852 struct net_device *dev = dp->data;
4853 struct airo_info *ai = dev->priv;
4854 int i;
4855
Panagiotis Issarisb69a3aa2005-11-08 00:03:15 +01004856 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004858 data = (struct proc_data *)file->private_data;
4859 if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
4860 kfree (file->private_data);
4861 return -ENOMEM;
4862 }
Panagiotis Issarisb69a3aa2005-11-08 00:03:15 +01004863 if ((data->wbuffer = kzalloc( 2048, GFP_KERNEL )) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004864 kfree (data->rbuffer);
4865 kfree (file->private_data);
4866 return -ENOMEM;
4867 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004868 data->maxwritelen = 2048;
4869 data->on_close = proc_config_on_close;
4870
4871 readConfigRid(ai, 1);
4872
4873 i = sprintf( data->rbuffer,
4874 "Mode: %s\n"
4875 "Radio: %s\n"
4876 "NodeName: %-16s\n"
4877 "PowerMode: %s\n"
4878 "DataRates: %d %d %d %d %d %d %d %d\n"
4879 "Channel: %d\n"
4880 "XmitPower: %d\n",
4881 (ai->config.opmode & 0xFF) == 0 ? "adhoc" :
4882 (ai->config.opmode & 0xFF) == 1 ? get_rmode(ai->config.rmode):
4883 (ai->config.opmode & 0xFF) == 2 ? "AP" :
4884 (ai->config.opmode & 0xFF) == 3 ? "AP RPTR" : "Error",
4885 test_bit(FLAG_RADIO_OFF, &ai->flags) ? "off" : "on",
4886 ai->config.nodeName,
4887 ai->config.powerSaveMode == 0 ? "CAM" :
4888 ai->config.powerSaveMode == 1 ? "PSP" :
4889 ai->config.powerSaveMode == 2 ? "PSPCAM" : "Error",
4890 (int)ai->config.rates[0],
4891 (int)ai->config.rates[1],
4892 (int)ai->config.rates[2],
4893 (int)ai->config.rates[3],
4894 (int)ai->config.rates[4],
4895 (int)ai->config.rates[5],
4896 (int)ai->config.rates[6],
4897 (int)ai->config.rates[7],
4898 (int)ai->config.channelSet,
4899 (int)ai->config.txPower
4900 );
4901 sprintf( data->rbuffer + i,
4902 "LongRetryLimit: %d\n"
4903 "ShortRetryLimit: %d\n"
4904 "RTSThreshold: %d\n"
4905 "TXMSDULifetime: %d\n"
4906 "RXMSDULifetime: %d\n"
4907 "TXDiversity: %s\n"
4908 "RXDiversity: %s\n"
4909 "FragThreshold: %d\n"
4910 "WEP: %s\n"
4911 "Modulation: %s\n"
4912 "Preamble: %s\n",
4913 (int)ai->config.longRetryLimit,
4914 (int)ai->config.shortRetryLimit,
4915 (int)ai->config.rtsThres,
4916 (int)ai->config.txLifetime,
4917 (int)ai->config.rxLifetime,
4918 ai->config.txDiversity == 1 ? "left" :
4919 ai->config.txDiversity == 2 ? "right" : "both",
4920 ai->config.rxDiversity == 1 ? "left" :
4921 ai->config.rxDiversity == 2 ? "right" : "both",
4922 (int)ai->config.fragThresh,
4923 ai->config.authType == AUTH_ENCRYPT ? "encrypt" :
4924 ai->config.authType == AUTH_SHAREDKEY ? "shared" : "open",
4925 ai->config.modulation == 0 ? "default" :
4926 ai->config.modulation == MOD_CCK ? "cck" :
4927 ai->config.modulation == MOD_MOK ? "mok" : "error",
4928 ai->config.preamble == PREAMBLE_AUTO ? "auto" :
4929 ai->config.preamble == PREAMBLE_LONG ? "long" :
4930 ai->config.preamble == PREAMBLE_SHORT ? "short" : "error"
4931 );
4932 data->readlen = strlen( data->rbuffer );
4933 return 0;
4934}
4935
4936static void proc_SSID_on_close( struct inode *inode, struct file *file ) {
4937 struct proc_data *data = (struct proc_data *)file->private_data;
4938 struct proc_dir_entry *dp = PDE(inode);
4939 struct net_device *dev = dp->data;
4940 struct airo_info *ai = dev->priv;
4941 SsidRid SSID_rid;
4942 Resp rsp;
4943 int i;
4944 int offset = 0;
4945
4946 if ( !data->writelen ) return;
4947
4948 memset( &SSID_rid, 0, sizeof( SSID_rid ) );
4949
4950 for( i = 0; i < 3; i++ ) {
4951 int j;
4952 for( j = 0; j+offset < data->writelen && j < 32 &&
4953 data->wbuffer[offset+j] != '\n'; j++ ) {
4954 SSID_rid.ssids[i].ssid[j] = data->wbuffer[offset+j];
4955 }
4956 if ( j == 0 ) break;
4957 SSID_rid.ssids[i].len = j;
4958 offset += j;
4959 while( data->wbuffer[offset] != '\n' &&
4960 offset < data->writelen ) offset++;
4961 offset++;
4962 }
4963 if (i)
4964 SSID_rid.len = sizeof(SSID_rid);
4965 disable_MAC(ai, 1);
4966 writeSsidRid(ai, &SSID_rid, 1);
4967 enable_MAC(ai, &rsp, 1);
4968}
4969
Jesper Juhl77933d72005-07-27 11:46:09 -07004970static inline u8 hexVal(char c) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004971 if (c>='0' && c<='9') return c -= '0';
4972 if (c>='a' && c<='f') return c -= 'a'-10;
4973 if (c>='A' && c<='F') return c -= 'A'-10;
4974 return 0;
4975}
4976
4977static void proc_APList_on_close( struct inode *inode, struct file *file ) {
4978 struct proc_data *data = (struct proc_data *)file->private_data;
4979 struct proc_dir_entry *dp = PDE(inode);
4980 struct net_device *dev = dp->data;
4981 struct airo_info *ai = dev->priv;
4982 APListRid APList_rid;
4983 Resp rsp;
4984 int i;
4985
4986 if ( !data->writelen ) return;
4987
4988 memset( &APList_rid, 0, sizeof(APList_rid) );
4989 APList_rid.len = sizeof(APList_rid);
4990
4991 for( i = 0; i < 4 && data->writelen >= (i+1)*6*3; i++ ) {
4992 int j;
4993 for( j = 0; j < 6*3 && data->wbuffer[j+i*6*3]; j++ ) {
4994 switch(j%3) {
4995 case 0:
4996 APList_rid.ap[i][j/3]=
4997 hexVal(data->wbuffer[j+i*6*3])<<4;
4998 break;
4999 case 1:
5000 APList_rid.ap[i][j/3]|=
5001 hexVal(data->wbuffer[j+i*6*3]);
5002 break;
5003 }
5004 }
5005 }
5006 disable_MAC(ai, 1);
5007 writeAPListRid(ai, &APList_rid, 1);
5008 enable_MAC(ai, &rsp, 1);
5009}
5010
5011/* This function wraps PC4500_writerid with a MAC disable */
5012static int do_writerid( struct airo_info *ai, u16 rid, const void *rid_data,
5013 int len, int dummy ) {
5014 int rc;
5015 Resp rsp;
5016
5017 disable_MAC(ai, 1);
5018 rc = PC4500_writerid(ai, rid, rid_data, len, 1);
5019 enable_MAC(ai, &rsp, 1);
5020 return rc;
5021}
5022
5023/* Returns the length of the key at the index. If index == 0xffff
5024 * the index of the transmit key is returned. If the key doesn't exist,
5025 * -1 will be returned.
5026 */
5027static int get_wep_key(struct airo_info *ai, u16 index) {
5028 WepKeyRid wkr;
5029 int rc;
5030 u16 lastindex;
5031
5032 rc = readWepKeyRid(ai, &wkr, 1, 1);
5033 if (rc == SUCCESS) do {
5034 lastindex = wkr.kindex;
5035 if (wkr.kindex == index) {
5036 if (index == 0xffff) {
5037 return wkr.mac[0];
5038 }
5039 return wkr.klen;
5040 }
5041 readWepKeyRid(ai, &wkr, 0, 1);
5042 } while(lastindex != wkr.kindex);
5043 return -1;
5044}
5045
5046static int set_wep_key(struct airo_info *ai, u16 index,
5047 const char *key, u16 keylen, int perm, int lock ) {
5048 static const unsigned char macaddr[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
5049 WepKeyRid wkr;
5050 Resp rsp;
5051
5052 memset(&wkr, 0, sizeof(wkr));
5053 if (keylen == 0) {
5054// We are selecting which key to use
5055 wkr.len = sizeof(wkr);
5056 wkr.kindex = 0xffff;
5057 wkr.mac[0] = (char)index;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005058 if (perm) ai->defindex = (char)index;
5059 } else {
5060// We are actually setting the key
5061 wkr.len = sizeof(wkr);
5062 wkr.kindex = index;
5063 wkr.klen = keylen;
5064 memcpy( wkr.key, key, keylen );
5065 memcpy( wkr.mac, macaddr, ETH_ALEN );
Linus Torvalds1da177e2005-04-16 15:20:36 -07005066 }
5067
Dan Streetmanf89b2322005-11-11 11:41:42 -05005068 if (perm) disable_MAC(ai, lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069 writeWepKeyRid(ai, &wkr, perm, lock);
Dan Streetmanf89b2322005-11-11 11:41:42 -05005070 if (perm) enable_MAC(ai, &rsp, lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005071 return 0;
5072}
5073
5074static void proc_wepkey_on_close( struct inode *inode, struct file *file ) {
5075 struct proc_data *data;
5076 struct proc_dir_entry *dp = PDE(inode);
5077 struct net_device *dev = dp->data;
5078 struct airo_info *ai = dev->priv;
5079 int i;
5080 char key[16];
5081 u16 index = 0;
5082 int j = 0;
5083
5084 memset(key, 0, sizeof(key));
5085
5086 data = (struct proc_data *)file->private_data;
5087 if ( !data->writelen ) return;
5088
5089 if (data->wbuffer[0] >= '0' && data->wbuffer[0] <= '3' &&
5090 (data->wbuffer[1] == ' ' || data->wbuffer[1] == '\n')) {
5091 index = data->wbuffer[0] - '0';
5092 if (data->wbuffer[1] == '\n') {
5093 set_wep_key(ai, index, NULL, 0, 1, 1);
5094 return;
5095 }
5096 j = 2;
5097 } else {
Dan Williams934d8bf2006-03-16 13:46:23 -05005098 airo_print_err(ai->dev->name, "WepKey passed invalid key index");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005099 return;
5100 }
5101
5102 for( i = 0; i < 16*3 && data->wbuffer[i+j]; i++ ) {
5103 switch(i%3) {
5104 case 0:
5105 key[i/3] = hexVal(data->wbuffer[i+j])<<4;
5106 break;
5107 case 1:
5108 key[i/3] |= hexVal(data->wbuffer[i+j]);
5109 break;
5110 }
5111 }
5112 set_wep_key(ai, index, key, i/3, 1, 1);
5113}
5114
5115static int proc_wepkey_open( struct inode *inode, struct file *file ) {
5116 struct proc_data *data;
5117 struct proc_dir_entry *dp = PDE(inode);
5118 struct net_device *dev = dp->data;
5119 struct airo_info *ai = dev->priv;
5120 char *ptr;
5121 WepKeyRid wkr;
5122 u16 lastindex;
5123 int j=0;
5124 int rc;
5125
Panagiotis Issarisb69a3aa2005-11-08 00:03:15 +01005126 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005127 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005128 memset(&wkr, 0, sizeof(wkr));
5129 data = (struct proc_data *)file->private_data;
Panagiotis Issarisb69a3aa2005-11-08 00:03:15 +01005130 if ((data->rbuffer = kzalloc( 180, GFP_KERNEL )) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005131 kfree (file->private_data);
5132 return -ENOMEM;
5133 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005134 data->writelen = 0;
5135 data->maxwritelen = 80;
Panagiotis Issarisb69a3aa2005-11-08 00:03:15 +01005136 if ((data->wbuffer = kzalloc( 80, GFP_KERNEL )) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005137 kfree (data->rbuffer);
5138 kfree (file->private_data);
5139 return -ENOMEM;
5140 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005141 data->on_close = proc_wepkey_on_close;
5142
5143 ptr = data->rbuffer;
5144 strcpy(ptr, "No wep keys\n");
5145 rc = readWepKeyRid(ai, &wkr, 1, 1);
5146 if (rc == SUCCESS) do {
5147 lastindex = wkr.kindex;
5148 if (wkr.kindex == 0xffff) {
5149 j += sprintf(ptr+j, "Tx key = %d\n",
5150 (int)wkr.mac[0]);
5151 } else {
5152 j += sprintf(ptr+j, "Key %d set with length = %d\n",
5153 (int)wkr.kindex, (int)wkr.klen);
5154 }
5155 readWepKeyRid(ai, &wkr, 0, 1);
5156 } while((lastindex != wkr.kindex) && (j < 180-30));
5157
5158 data->readlen = strlen( data->rbuffer );
5159 return 0;
5160}
5161
5162static int proc_SSID_open( struct inode *inode, struct file *file ) {
5163 struct proc_data *data;
5164 struct proc_dir_entry *dp = PDE(inode);
5165 struct net_device *dev = dp->data;
5166 struct airo_info *ai = dev->priv;
5167 int i;
5168 char *ptr;
5169 SsidRid SSID_rid;
5170
Panagiotis Issarisb69a3aa2005-11-08 00:03:15 +01005171 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005172 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005173 data = (struct proc_data *)file->private_data;
5174 if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
5175 kfree (file->private_data);
5176 return -ENOMEM;
5177 }
5178 data->writelen = 0;
5179 data->maxwritelen = 33*3;
Panagiotis Issarisb69a3aa2005-11-08 00:03:15 +01005180 if ((data->wbuffer = kzalloc( 33*3, GFP_KERNEL )) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005181 kfree (data->rbuffer);
5182 kfree (file->private_data);
5183 return -ENOMEM;
5184 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185 data->on_close = proc_SSID_on_close;
5186
5187 readSsidRid(ai, &SSID_rid);
5188 ptr = data->rbuffer;
5189 for( i = 0; i < 3; i++ ) {
5190 int j;
5191 if ( !SSID_rid.ssids[i].len ) break;
5192 for( j = 0; j < 32 &&
5193 j < SSID_rid.ssids[i].len &&
5194 SSID_rid.ssids[i].ssid[j]; j++ ) {
5195 *ptr++ = SSID_rid.ssids[i].ssid[j];
5196 }
5197 *ptr++ = '\n';
5198 }
5199 *ptr = '\0';
5200 data->readlen = strlen( data->rbuffer );
5201 return 0;
5202}
5203
5204static int proc_APList_open( struct inode *inode, struct file *file ) {
5205 struct proc_data *data;
5206 struct proc_dir_entry *dp = PDE(inode);
5207 struct net_device *dev = dp->data;
5208 struct airo_info *ai = dev->priv;
5209 int i;
5210 char *ptr;
5211 APListRid APList_rid;
5212
Panagiotis Issarisb69a3aa2005-11-08 00:03:15 +01005213 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005214 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005215 data = (struct proc_data *)file->private_data;
5216 if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
5217 kfree (file->private_data);
5218 return -ENOMEM;
5219 }
5220 data->writelen = 0;
5221 data->maxwritelen = 4*6*3;
Panagiotis Issarisb69a3aa2005-11-08 00:03:15 +01005222 if ((data->wbuffer = kzalloc( data->maxwritelen, GFP_KERNEL )) == NULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005223 kfree (data->rbuffer);
5224 kfree (file->private_data);
5225 return -ENOMEM;
5226 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227 data->on_close = proc_APList_on_close;
5228
5229 readAPListRid(ai, &APList_rid);
5230 ptr = data->rbuffer;
5231 for( i = 0; i < 4; i++ ) {
5232// We end when we find a zero MAC
5233 if ( !*(int*)APList_rid.ap[i] &&
5234 !*(int*)&APList_rid.ap[i][2]) break;
5235 ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02x\n",
5236 (int)APList_rid.ap[i][0],
5237 (int)APList_rid.ap[i][1],
5238 (int)APList_rid.ap[i][2],
5239 (int)APList_rid.ap[i][3],
5240 (int)APList_rid.ap[i][4],
5241 (int)APList_rid.ap[i][5]);
5242 }
5243 if (i==0) ptr += sprintf(ptr, "Not using specific APs\n");
5244
5245 *ptr = '\0';
5246 data->readlen = strlen( data->rbuffer );
5247 return 0;
5248}
5249
5250static int proc_BSSList_open( struct inode *inode, struct file *file ) {
5251 struct proc_data *data;
5252 struct proc_dir_entry *dp = PDE(inode);
5253 struct net_device *dev = dp->data;
5254 struct airo_info *ai = dev->priv;
5255 char *ptr;
5256 BSSListRid BSSList_rid;
5257 int rc;
5258 /* If doLoseSync is not 1, we won't do a Lose Sync */
5259 int doLoseSync = -1;
5260
Panagiotis Issarisb69a3aa2005-11-08 00:03:15 +01005261 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005262 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005263 data = (struct proc_data *)file->private_data;
5264 if ((data->rbuffer = kmalloc( 1024, GFP_KERNEL )) == NULL) {
5265 kfree (file->private_data);
5266 return -ENOMEM;
5267 }
5268 data->writelen = 0;
5269 data->maxwritelen = 0;
5270 data->wbuffer = NULL;
5271 data->on_close = NULL;
5272
5273 if (file->f_mode & FMODE_WRITE) {
5274 if (!(file->f_mode & FMODE_READ)) {
5275 Cmd cmd;
5276 Resp rsp;
5277
5278 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
5279 memset(&cmd, 0, sizeof(cmd));
5280 cmd.cmd=CMD_LISTBSS;
5281 if (down_interruptible(&ai->sem))
5282 return -ERESTARTSYS;
5283 issuecommand(ai, &cmd, &rsp);
5284 up(&ai->sem);
5285 data->readlen = 0;
5286 return 0;
5287 }
5288 doLoseSync = 1;
5289 }
5290 ptr = data->rbuffer;
5291 /* There is a race condition here if there are concurrent opens.
5292 Since it is a rare condition, we'll just live with it, otherwise
5293 we have to add a spin lock... */
5294 rc = readBSSListRid(ai, doLoseSync, &BSSList_rid);
5295 while(rc == 0 && BSSList_rid.index != 0xffff) {
5296 ptr += sprintf(ptr, "%02x:%02x:%02x:%02x:%02x:%02x %*s rssi = %d",
5297 (int)BSSList_rid.bssid[0],
5298 (int)BSSList_rid.bssid[1],
5299 (int)BSSList_rid.bssid[2],
5300 (int)BSSList_rid.bssid[3],
5301 (int)BSSList_rid.bssid[4],
5302 (int)BSSList_rid.bssid[5],
5303 (int)BSSList_rid.ssidLen,
5304 BSSList_rid.ssid,
Dan Williams41480af2005-05-10 09:45:51 -04005305 (int)BSSList_rid.dBm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005306 ptr += sprintf(ptr, " channel = %d %s %s %s %s\n",
5307 (int)BSSList_rid.dsChannel,
5308 BSSList_rid.cap & CAP_ESS ? "ESS" : "",
5309 BSSList_rid.cap & CAP_IBSS ? "adhoc" : "",
5310 BSSList_rid.cap & CAP_PRIVACY ? "wep" : "",
5311 BSSList_rid.cap & CAP_SHORTHDR ? "shorthdr" : "");
5312 rc = readBSSListRid(ai, 0, &BSSList_rid);
5313 }
5314 *ptr = '\0';
5315 data->readlen = strlen( data->rbuffer );
5316 return 0;
5317}
5318
5319static int proc_close( struct inode *inode, struct file *file )
5320{
Jesper Juhlb4558ea2005-10-28 16:53:13 -04005321 struct proc_data *data = file->private_data;
5322
5323 if (data->on_close != NULL)
5324 data->on_close(inode, file);
5325 kfree(data->rbuffer);
5326 kfree(data->wbuffer);
5327 kfree(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005328 return 0;
5329}
5330
5331static struct net_device_list {
5332 struct net_device *dev;
5333 struct net_device_list *next;
5334} *airo_devices;
5335
5336/* Since the card doesn't automatically switch to the right WEP mode,
5337 we will make it do it. If the card isn't associated, every secs we
5338 will switch WEP modes to see if that will help. If the card is
5339 associated we will check every minute to see if anything has
5340 changed. */
5341static void timer_func( struct net_device *dev ) {
5342 struct airo_info *apriv = dev->priv;
5343 Resp rsp;
5344
5345/* We don't have a link so try changing the authtype */
5346 readConfigRid(apriv, 0);
5347 disable_MAC(apriv, 0);
5348 switch(apriv->config.authType) {
5349 case AUTH_ENCRYPT:
5350/* So drop to OPEN */
5351 apriv->config.authType = AUTH_OPEN;
5352 break;
5353 case AUTH_SHAREDKEY:
5354 if (apriv->keyindex < auto_wep) {
5355 set_wep_key(apriv, apriv->keyindex, NULL, 0, 0, 0);
5356 apriv->config.authType = AUTH_SHAREDKEY;
5357 apriv->keyindex++;
5358 } else {
5359 /* Drop to ENCRYPT */
5360 apriv->keyindex = 0;
5361 set_wep_key(apriv, apriv->defindex, NULL, 0, 0, 0);
5362 apriv->config.authType = AUTH_ENCRYPT;
5363 }
5364 break;
5365 default: /* We'll escalate to SHAREDKEY */
5366 apriv->config.authType = AUTH_SHAREDKEY;
5367 }
5368 set_bit (FLAG_COMMIT, &apriv->flags);
5369 writeConfigRid(apriv, 0);
5370 enable_MAC(apriv, &rsp, 0);
5371 up(&apriv->sem);
5372
5373/* Schedule check to see if the change worked */
5374 clear_bit(JOB_AUTOWEP, &apriv->flags);
5375 apriv->expires = RUN_AT(HZ*3);
5376}
5377
5378static int add_airo_dev( struct net_device *dev ) {
5379 struct net_device_list *node = kmalloc( sizeof( *node ), GFP_KERNEL );
5380 if ( !node )
5381 return -ENOMEM;
5382
5383 node->dev = dev;
5384 node->next = airo_devices;
5385 airo_devices = node;
5386
5387 return 0;
5388}
5389
5390static void del_airo_dev( struct net_device *dev ) {
5391 struct net_device_list **p = &airo_devices;
5392 while( *p && ( (*p)->dev != dev ) )
5393 p = &(*p)->next;
5394 if ( *p && (*p)->dev == dev )
5395 *p = (*p)->next;
5396}
5397
5398#ifdef CONFIG_PCI
5399static int __devinit airo_pci_probe(struct pci_dev *pdev,
5400 const struct pci_device_id *pent)
5401{
5402 struct net_device *dev;
5403
5404 if (pci_enable_device(pdev))
5405 return -ENODEV;
5406 pci_set_master(pdev);
5407
5408 if (pdev->device == 0x5000 || pdev->device == 0xa504)
5409 dev = _init_airo_card(pdev->irq, pdev->resource[0].start, 0, pdev, &pdev->dev);
5410 else
5411 dev = _init_airo_card(pdev->irq, pdev->resource[2].start, 0, pdev, &pdev->dev);
5412 if (!dev)
5413 return -ENODEV;
5414
5415 pci_set_drvdata(pdev, dev);
5416 return 0;
5417}
5418
5419static void __devexit airo_pci_remove(struct pci_dev *pdev)
5420{
5421}
5422
Pavel Machek05adc3b2005-04-16 15:25:25 -07005423static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005424{
5425 struct net_device *dev = pci_get_drvdata(pdev);
5426 struct airo_info *ai = dev->priv;
5427 Cmd cmd;
5428 Resp rsp;
5429
5430 if ((ai->APList == NULL) &&
5431 (ai->APList = kmalloc(sizeof(APListRid), GFP_KERNEL)) == NULL)
5432 return -ENOMEM;
5433 if ((ai->SSID == NULL) &&
5434 (ai->SSID = kmalloc(sizeof(SsidRid), GFP_KERNEL)) == NULL)
5435 return -ENOMEM;
5436 readAPListRid(ai, ai->APList);
5437 readSsidRid(ai, ai->SSID);
5438 memset(&cmd, 0, sizeof(cmd));
5439 /* the lock will be released at the end of the resume callback */
5440 if (down_interruptible(&ai->sem))
5441 return -EAGAIN;
5442 disable_MAC(ai, 0);
5443 netif_device_detach(dev);
5444 ai->power = state;
5445 cmd.cmd=HOSTSLEEP;
5446 issuecommand(ai, &cmd, &rsp);
5447
Pavel Machek1cc68ae2005-06-20 15:33:04 -07005448 pci_enable_wake(pdev, pci_choose_state(pdev, state), 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005449 pci_save_state(pdev);
Pavel Machek1cc68ae2005-06-20 15:33:04 -07005450 return pci_set_power_state(pdev, pci_choose_state(pdev, state));
Linus Torvalds1da177e2005-04-16 15:20:36 -07005451}
5452
5453static int airo_pci_resume(struct pci_dev *pdev)
5454{
5455 struct net_device *dev = pci_get_drvdata(pdev);
5456 struct airo_info *ai = dev->priv;
5457 Resp rsp;
Michal Schmidt53232802005-10-04 07:46:21 -04005458 pci_power_t prev_state = pdev->current_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005459
Michal Schmidt53232802005-10-04 07:46:21 -04005460 pci_set_power_state(pdev, PCI_D0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005461 pci_restore_state(pdev);
Michal Schmidt53232802005-10-04 07:46:21 -04005462 pci_enable_wake(pdev, PCI_D0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005463
Michal Schmidt53232802005-10-04 07:46:21 -04005464 if (prev_state != PCI_D1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005465 reset_card(dev, 0);
5466 mpi_init_descriptors(ai);
5467 setup_card(ai, dev->dev_addr, 0);
5468 clear_bit(FLAG_RADIO_OFF, &ai->flags);
5469 clear_bit(FLAG_PENDING_XMIT, &ai->flags);
5470 } else {
5471 OUT4500(ai, EVACK, EV_AWAKEN);
5472 OUT4500(ai, EVACK, EV_AWAKEN);
5473 msleep(100);
5474 }
5475
5476 set_bit (FLAG_COMMIT, &ai->flags);
5477 disable_MAC(ai, 0);
5478 msleep(200);
5479 if (ai->SSID) {
5480 writeSsidRid(ai, ai->SSID, 0);
5481 kfree(ai->SSID);
5482 ai->SSID = NULL;
5483 }
5484 if (ai->APList) {
5485 writeAPListRid(ai, ai->APList, 0);
5486 kfree(ai->APList);
5487 ai->APList = NULL;
5488 }
5489 writeConfigRid(ai, 0);
5490 enable_MAC(ai, &rsp, 0);
Pavel Machek1cc68ae2005-06-20 15:33:04 -07005491 ai->power = PMSG_ON;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005492 netif_device_attach(dev);
5493 netif_wake_queue(dev);
5494 enable_interrupts(ai);
5495 up(&ai->sem);
5496 return 0;
5497}
5498#endif
5499
5500static int __init airo_init_module( void )
5501{
5502 int i, have_isa_dev = 0;
5503
5504 airo_entry = create_proc_entry("aironet",
5505 S_IFDIR | airo_perm,
5506 proc_root_driver);
5507 airo_entry->uid = proc_uid;
5508 airo_entry->gid = proc_gid;
5509
5510 for( i = 0; i < 4 && io[i] && irq[i]; i++ ) {
Dan Williams934d8bf2006-03-16 13:46:23 -05005511 airo_print_info("", "Trying to configure ISA adapter at irq=%d "
5512 "io=0x%x", irq[i], io[i] );
Linus Torvalds1da177e2005-04-16 15:20:36 -07005513 if (init_airo_card( irq[i], io[i], 0, NULL ))
5514 have_isa_dev = 1;
5515 }
5516
5517#ifdef CONFIG_PCI
Dan Williams934d8bf2006-03-16 13:46:23 -05005518 airo_print_info("", "Probing for PCI adapters");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005519 pci_register_driver(&airo_driver);
Dan Williams934d8bf2006-03-16 13:46:23 -05005520 airo_print_info("", "Finished probing for PCI adapters");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005521#endif
5522
5523 /* Always exit with success, as we are a library module
5524 * as well as a driver module
5525 */
5526 return 0;
5527}
5528
5529static void __exit airo_cleanup_module( void )
5530{
5531 while( airo_devices ) {
Dan Williams934d8bf2006-03-16 13:46:23 -05005532 airo_print_info(airo_devices->dev->name, "Unregistering...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005533 stop_airo_card( airo_devices->dev, 1 );
5534 }
5535#ifdef CONFIG_PCI
5536 pci_unregister_driver(&airo_driver);
5537#endif
5538 remove_proc_entry("aironet", proc_root_driver);
5539}
5540
Linus Torvalds1da177e2005-04-16 15:20:36 -07005541/*
5542 * Initial Wireless Extension code for Aironet driver by :
5543 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
5544 * Conversion to new driver API by :
5545 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
5546 * Javier also did a good amount of work here, adding some new extensions
5547 * and fixing my code. Let's just say that without him this code just
5548 * would not work at all... - Jean II
5549 */
5550
Dan Williams41480af2005-05-10 09:45:51 -04005551static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi)
5552{
5553 if( !rssi_rid )
5554 return 0;
5555
5556 return (0x100 - rssi_rid[rssi].rssidBm);
5557}
5558
5559static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm)
5560{
5561 int i;
5562
5563 if( !rssi_rid )
5564 return 0;
5565
5566 for( i = 0; i < 256; i++ )
5567 if (rssi_rid[i].rssidBm == dbm)
5568 return rssi_rid[i].rssipct;
5569
5570 return 0;
5571}
5572
5573
Linus Torvalds1da177e2005-04-16 15:20:36 -07005574static int airo_get_quality (StatusRid *status_rid, CapabilityRid *cap_rid)
5575{
5576 int quality = 0;
5577
5578 if ((status_rid->mode & 0x3f) == 0x3f && (cap_rid->hardCap & 8)) {
5579 if (memcmp(cap_rid->prodName, "350", 3))
5580 if (status_rid->signalQuality > 0x20)
5581 quality = 0;
5582 else
5583 quality = 0x20 - status_rid->signalQuality;
5584 else
5585 if (status_rid->signalQuality > 0xb0)
5586 quality = 0;
5587 else if (status_rid->signalQuality < 0x10)
5588 quality = 0xa0;
5589 else
5590 quality = 0xb0 - status_rid->signalQuality;
5591 }
5592 return quality;
5593}
5594
5595#define airo_get_max_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x20 : 0xa0)
5596#define airo_get_avg_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x10 : 0x50);
5597
5598/*------------------------------------------------------------------*/
5599/*
5600 * Wireless Handler : get protocol name
5601 */
5602static int airo_get_name(struct net_device *dev,
5603 struct iw_request_info *info,
5604 char *cwrq,
5605 char *extra)
5606{
5607 strcpy(cwrq, "IEEE 802.11-DS");
5608 return 0;
5609}
5610
5611/*------------------------------------------------------------------*/
5612/*
5613 * Wireless Handler : set frequency
5614 */
5615static int airo_set_freq(struct net_device *dev,
5616 struct iw_request_info *info,
5617 struct iw_freq *fwrq,
5618 char *extra)
5619{
5620 struct airo_info *local = dev->priv;
5621 int rc = -EINPROGRESS; /* Call commit handler */
5622
5623 /* If setting by frequency, convert to a channel */
5624 if((fwrq->e == 1) &&
5625 (fwrq->m >= (int) 2.412e8) &&
5626 (fwrq->m <= (int) 2.487e8)) {
5627 int f = fwrq->m / 100000;
5628 int c = 0;
5629 while((c < 14) && (f != frequency_list[c]))
5630 c++;
5631 /* Hack to fall through... */
5632 fwrq->e = 0;
5633 fwrq->m = c + 1;
5634 }
5635 /* Setting by channel number */
5636 if((fwrq->m > 1000) || (fwrq->e > 0))
5637 rc = -EOPNOTSUPP;
5638 else {
5639 int channel = fwrq->m;
5640 /* We should do a better check than that,
5641 * based on the card capability !!! */
Javier Achirica2610c732006-01-17 08:01:01 -05005642 if((channel < 1) || (channel > 14)) {
Dan Williams934d8bf2006-03-16 13:46:23 -05005643 airo_print_dbg(dev->name, "New channel value of %d is invalid!",
5644 fwrq->m);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005645 rc = -EINVAL;
5646 } else {
5647 readConfigRid(local, 1);
5648 /* Yes ! We can set it !!! */
Javier Achirica2610c732006-01-17 08:01:01 -05005649 local->config.channelSet = (u16) channel;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005650 set_bit (FLAG_COMMIT, &local->flags);
5651 }
5652 }
5653 return rc;
5654}
5655
5656/*------------------------------------------------------------------*/
5657/*
5658 * Wireless Handler : get frequency
5659 */
5660static int airo_get_freq(struct net_device *dev,
5661 struct iw_request_info *info,
5662 struct iw_freq *fwrq,
5663 char *extra)
5664{
5665 struct airo_info *local = dev->priv;
5666 StatusRid status_rid; /* Card status info */
Javier Achirica2610c732006-01-17 08:01:01 -05005667 int ch;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005668
5669 readConfigRid(local, 1);
5670 if ((local->config.opmode & 0xFF) == MODE_STA_ESS)
5671 status_rid.channel = local->config.channelSet;
5672 else
5673 readStatusRid(local, &status_rid, 1);
5674
Javier Achirica2610c732006-01-17 08:01:01 -05005675 ch = (int)status_rid.channel;
5676 if((ch > 0) && (ch < 15)) {
5677 fwrq->m = frequency_list[ch - 1] * 100000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005678 fwrq->e = 1;
Javier Achirica2610c732006-01-17 08:01:01 -05005679 } else {
5680 fwrq->m = ch;
5681 fwrq->e = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005682 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005683
5684 return 0;
5685}
5686
5687/*------------------------------------------------------------------*/
5688/*
5689 * Wireless Handler : set ESSID
5690 */
5691static int airo_set_essid(struct net_device *dev,
5692 struct iw_request_info *info,
5693 struct iw_point *dwrq,
5694 char *extra)
5695{
5696 struct airo_info *local = dev->priv;
5697 Resp rsp;
5698 SsidRid SSID_rid; /* SSIDs */
5699
5700 /* Reload the list of current SSID */
5701 readSsidRid(local, &SSID_rid);
5702
5703 /* Check if we asked for `any' */
5704 if(dwrq->flags == 0) {
5705 /* Just send an empty SSID list */
5706 memset(&SSID_rid, 0, sizeof(SSID_rid));
5707 } else {
5708 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
5709
5710 /* Check the size of the string */
5711 if(dwrq->length > IW_ESSID_MAX_SIZE+1) {
5712 return -E2BIG ;
5713 }
5714 /* Check if index is valid */
5715 if((index < 0) || (index >= 4)) {
5716 return -EINVAL;
5717 }
5718
5719 /* Set the SSID */
5720 memset(SSID_rid.ssids[index].ssid, 0,
5721 sizeof(SSID_rid.ssids[index].ssid));
5722 memcpy(SSID_rid.ssids[index].ssid, extra, dwrq->length);
5723 SSID_rid.ssids[index].len = dwrq->length - 1;
5724 }
5725 SSID_rid.len = sizeof(SSID_rid);
5726 /* Write it to the card */
5727 disable_MAC(local, 1);
5728 writeSsidRid(local, &SSID_rid, 1);
5729 enable_MAC(local, &rsp, 1);
5730
5731 return 0;
5732}
5733
5734/*------------------------------------------------------------------*/
5735/*
5736 * Wireless Handler : get ESSID
5737 */
5738static int airo_get_essid(struct net_device *dev,
5739 struct iw_request_info *info,
5740 struct iw_point *dwrq,
5741 char *extra)
5742{
5743 struct airo_info *local = dev->priv;
5744 StatusRid status_rid; /* Card status info */
5745
5746 readStatusRid(local, &status_rid, 1);
5747
5748 /* Note : if dwrq->flags != 0, we should
5749 * get the relevant SSID from the SSID list... */
5750
5751 /* Get the current SSID */
5752 memcpy(extra, status_rid.SSID, status_rid.SSIDlen);
5753 extra[status_rid.SSIDlen] = '\0';
5754 /* If none, we may want to get the one that was set */
5755
5756 /* Push it out ! */
Dan Williamsd6a13a22006-01-12 15:00:58 -05005757 dwrq->length = status_rid.SSIDlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758 dwrq->flags = 1; /* active */
5759
5760 return 0;
5761}
5762
5763/*------------------------------------------------------------------*/
5764/*
5765 * Wireless Handler : set AP address
5766 */
5767static int airo_set_wap(struct net_device *dev,
5768 struct iw_request_info *info,
5769 struct sockaddr *awrq,
5770 char *extra)
5771{
5772 struct airo_info *local = dev->priv;
5773 Cmd cmd;
5774 Resp rsp;
5775 APListRid APList_rid;
Dan Williams4be757d2006-01-30 11:58:00 -05005776 static const u8 any[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5777 static const u8 off[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07005778
5779 if (awrq->sa_family != ARPHRD_ETHER)
5780 return -EINVAL;
Dan Williams4be757d2006-01-30 11:58:00 -05005781 else if (!memcmp(any, awrq->sa_data, ETH_ALEN) ||
5782 !memcmp(off, awrq->sa_data, ETH_ALEN)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005783 memset(&cmd, 0, sizeof(cmd));
5784 cmd.cmd=CMD_LOSE_SYNC;
5785 if (down_interruptible(&local->sem))
5786 return -ERESTARTSYS;
5787 issuecommand(local, &cmd, &rsp);
5788 up(&local->sem);
5789 } else {
5790 memset(&APList_rid, 0, sizeof(APList_rid));
5791 APList_rid.len = sizeof(APList_rid);
5792 memcpy(APList_rid.ap[0], awrq->sa_data, ETH_ALEN);
5793 disable_MAC(local, 1);
5794 writeAPListRid(local, &APList_rid, 1);
5795 enable_MAC(local, &rsp, 1);
5796 }
5797 return 0;
5798}
5799
5800/*------------------------------------------------------------------*/
5801/*
5802 * Wireless Handler : get AP address
5803 */
5804static int airo_get_wap(struct net_device *dev,
5805 struct iw_request_info *info,
5806 struct sockaddr *awrq,
5807 char *extra)
5808{
5809 struct airo_info *local = dev->priv;
5810 StatusRid status_rid; /* Card status info */
5811
5812 readStatusRid(local, &status_rid, 1);
5813
5814 /* Tentative. This seems to work, wow, I'm lucky !!! */
5815 memcpy(awrq->sa_data, status_rid.bssid[0], ETH_ALEN);
5816 awrq->sa_family = ARPHRD_ETHER;
5817
5818 return 0;
5819}
5820
5821/*------------------------------------------------------------------*/
5822/*
5823 * Wireless Handler : set Nickname
5824 */
5825static int airo_set_nick(struct net_device *dev,
5826 struct iw_request_info *info,
5827 struct iw_point *dwrq,
5828 char *extra)
5829{
5830 struct airo_info *local = dev->priv;
5831
5832 /* Check the size of the string */
5833 if(dwrq->length > 16 + 1) {
5834 return -E2BIG;
5835 }
5836 readConfigRid(local, 1);
5837 memset(local->config.nodeName, 0, sizeof(local->config.nodeName));
5838 memcpy(local->config.nodeName, extra, dwrq->length);
5839 set_bit (FLAG_COMMIT, &local->flags);
5840
5841 return -EINPROGRESS; /* Call commit handler */
5842}
5843
5844/*------------------------------------------------------------------*/
5845/*
5846 * Wireless Handler : get Nickname
5847 */
5848static int airo_get_nick(struct net_device *dev,
5849 struct iw_request_info *info,
5850 struct iw_point *dwrq,
5851 char *extra)
5852{
5853 struct airo_info *local = dev->priv;
5854
5855 readConfigRid(local, 1);
5856 strncpy(extra, local->config.nodeName, 16);
5857 extra[16] = '\0';
5858 dwrq->length = strlen(extra) + 1;
5859
5860 return 0;
5861}
5862
5863/*------------------------------------------------------------------*/
5864/*
5865 * Wireless Handler : set Bit-Rate
5866 */
5867static int airo_set_rate(struct net_device *dev,
5868 struct iw_request_info *info,
5869 struct iw_param *vwrq,
5870 char *extra)
5871{
5872 struct airo_info *local = dev->priv;
5873 CapabilityRid cap_rid; /* Card capability info */
5874 u8 brate = 0;
5875 int i;
5876
5877 /* First : get a valid bit rate value */
5878 readCapabilityRid(local, &cap_rid, 1);
5879
5880 /* Which type of value ? */
5881 if((vwrq->value < 8) && (vwrq->value >= 0)) {
5882 /* Setting by rate index */
5883 /* Find value in the magic rate table */
5884 brate = cap_rid.supportedRates[vwrq->value];
5885 } else {
5886 /* Setting by frequency value */
5887 u8 normvalue = (u8) (vwrq->value/500000);
5888
5889 /* Check if rate is valid */
5890 for(i = 0 ; i < 8 ; i++) {
5891 if(normvalue == cap_rid.supportedRates[i]) {
5892 brate = normvalue;
5893 break;
5894 }
5895 }
5896 }
5897 /* -1 designed the max rate (mostly auto mode) */
5898 if(vwrq->value == -1) {
5899 /* Get the highest available rate */
5900 for(i = 0 ; i < 8 ; i++) {
5901 if(cap_rid.supportedRates[i] == 0)
5902 break;
5903 }
5904 if(i != 0)
5905 brate = cap_rid.supportedRates[i - 1];
5906 }
5907 /* Check that it is valid */
5908 if(brate == 0) {
5909 return -EINVAL;
5910 }
5911
5912 readConfigRid(local, 1);
5913 /* Now, check if we want a fixed or auto value */
5914 if(vwrq->fixed == 0) {
5915 /* Fill all the rates up to this max rate */
5916 memset(local->config.rates, 0, 8);
5917 for(i = 0 ; i < 8 ; i++) {
5918 local->config.rates[i] = cap_rid.supportedRates[i];
5919 if(local->config.rates[i] == brate)
5920 break;
5921 }
5922 } else {
5923 /* Fixed mode */
5924 /* One rate, fixed */
5925 memset(local->config.rates, 0, 8);
5926 local->config.rates[0] = brate;
5927 }
5928 set_bit (FLAG_COMMIT, &local->flags);
5929
5930 return -EINPROGRESS; /* Call commit handler */
5931}
5932
5933/*------------------------------------------------------------------*/
5934/*
5935 * Wireless Handler : get Bit-Rate
5936 */
5937static int airo_get_rate(struct net_device *dev,
5938 struct iw_request_info *info,
5939 struct iw_param *vwrq,
5940 char *extra)
5941{
5942 struct airo_info *local = dev->priv;
5943 StatusRid status_rid; /* Card status info */
5944
5945 readStatusRid(local, &status_rid, 1);
5946
5947 vwrq->value = status_rid.currentXmitRate * 500000;
5948 /* If more than one rate, set auto */
5949 readConfigRid(local, 1);
5950 vwrq->fixed = (local->config.rates[1] == 0);
5951
5952 return 0;
5953}
5954
5955/*------------------------------------------------------------------*/
5956/*
5957 * Wireless Handler : set RTS threshold
5958 */
5959static int airo_set_rts(struct net_device *dev,
5960 struct iw_request_info *info,
5961 struct iw_param *vwrq,
5962 char *extra)
5963{
5964 struct airo_info *local = dev->priv;
5965 int rthr = vwrq->value;
5966
5967 if(vwrq->disabled)
5968 rthr = 2312;
5969 if((rthr < 0) || (rthr > 2312)) {
5970 return -EINVAL;
5971 }
5972 readConfigRid(local, 1);
5973 local->config.rtsThres = rthr;
5974 set_bit (FLAG_COMMIT, &local->flags);
5975
5976 return -EINPROGRESS; /* Call commit handler */
5977}
5978
5979/*------------------------------------------------------------------*/
5980/*
5981 * Wireless Handler : get RTS threshold
5982 */
5983static int airo_get_rts(struct net_device *dev,
5984 struct iw_request_info *info,
5985 struct iw_param *vwrq,
5986 char *extra)
5987{
5988 struct airo_info *local = dev->priv;
5989
5990 readConfigRid(local, 1);
5991 vwrq->value = local->config.rtsThres;
5992 vwrq->disabled = (vwrq->value >= 2312);
5993 vwrq->fixed = 1;
5994
5995 return 0;
5996}
5997
5998/*------------------------------------------------------------------*/
5999/*
6000 * Wireless Handler : set Fragmentation threshold
6001 */
6002static int airo_set_frag(struct net_device *dev,
6003 struct iw_request_info *info,
6004 struct iw_param *vwrq,
6005 char *extra)
6006{
6007 struct airo_info *local = dev->priv;
6008 int fthr = vwrq->value;
6009
6010 if(vwrq->disabled)
6011 fthr = 2312;
6012 if((fthr < 256) || (fthr > 2312)) {
6013 return -EINVAL;
6014 }
6015 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
6016 readConfigRid(local, 1);
6017 local->config.fragThresh = (u16)fthr;
6018 set_bit (FLAG_COMMIT, &local->flags);
6019
6020 return -EINPROGRESS; /* Call commit handler */
6021}
6022
6023/*------------------------------------------------------------------*/
6024/*
6025 * Wireless Handler : get Fragmentation threshold
6026 */
6027static int airo_get_frag(struct net_device *dev,
6028 struct iw_request_info *info,
6029 struct iw_param *vwrq,
6030 char *extra)
6031{
6032 struct airo_info *local = dev->priv;
6033
6034 readConfigRid(local, 1);
6035 vwrq->value = local->config.fragThresh;
6036 vwrq->disabled = (vwrq->value >= 2312);
6037 vwrq->fixed = 1;
6038
6039 return 0;
6040}
6041
6042/*------------------------------------------------------------------*/
6043/*
6044 * Wireless Handler : set Mode of Operation
6045 */
6046static int airo_set_mode(struct net_device *dev,
6047 struct iw_request_info *info,
6048 __u32 *uwrq,
6049 char *extra)
6050{
6051 struct airo_info *local = dev->priv;
6052 int reset = 0;
6053
6054 readConfigRid(local, 1);
6055 if ((local->config.rmode & 0xff) >= RXMODE_RFMON)
6056 reset = 1;
6057
6058 switch(*uwrq) {
6059 case IW_MODE_ADHOC:
6060 local->config.opmode &= 0xFF00;
6061 local->config.opmode |= MODE_STA_IBSS;
6062 local->config.rmode &= 0xfe00;
6063 local->config.scanMode = SCANMODE_ACTIVE;
6064 clear_bit (FLAG_802_11, &local->flags);
6065 break;
6066 case IW_MODE_INFRA:
6067 local->config.opmode &= 0xFF00;
6068 local->config.opmode |= MODE_STA_ESS;
6069 local->config.rmode &= 0xfe00;
6070 local->config.scanMode = SCANMODE_ACTIVE;
6071 clear_bit (FLAG_802_11, &local->flags);
6072 break;
6073 case IW_MODE_MASTER:
6074 local->config.opmode &= 0xFF00;
6075 local->config.opmode |= MODE_AP;
6076 local->config.rmode &= 0xfe00;
6077 local->config.scanMode = SCANMODE_ACTIVE;
6078 clear_bit (FLAG_802_11, &local->flags);
6079 break;
6080 case IW_MODE_REPEAT:
6081 local->config.opmode &= 0xFF00;
6082 local->config.opmode |= MODE_AP_RPTR;
6083 local->config.rmode &= 0xfe00;
6084 local->config.scanMode = SCANMODE_ACTIVE;
6085 clear_bit (FLAG_802_11, &local->flags);
6086 break;
6087 case IW_MODE_MONITOR:
6088 local->config.opmode &= 0xFF00;
6089 local->config.opmode |= MODE_STA_ESS;
6090 local->config.rmode &= 0xfe00;
6091 local->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
6092 local->config.scanMode = SCANMODE_PASSIVE;
6093 set_bit (FLAG_802_11, &local->flags);
6094 break;
6095 default:
6096 return -EINVAL;
6097 }
6098 if (reset)
6099 set_bit (FLAG_RESET, &local->flags);
6100 set_bit (FLAG_COMMIT, &local->flags);
6101
6102 return -EINPROGRESS; /* Call commit handler */
6103}
6104
6105/*------------------------------------------------------------------*/
6106/*
6107 * Wireless Handler : get Mode of Operation
6108 */
6109static int airo_get_mode(struct net_device *dev,
6110 struct iw_request_info *info,
6111 __u32 *uwrq,
6112 char *extra)
6113{
6114 struct airo_info *local = dev->priv;
6115
6116 readConfigRid(local, 1);
6117 /* If not managed, assume it's ad-hoc */
6118 switch (local->config.opmode & 0xFF) {
6119 case MODE_STA_ESS:
6120 *uwrq = IW_MODE_INFRA;
6121 break;
6122 case MODE_AP:
6123 *uwrq = IW_MODE_MASTER;
6124 break;
6125 case MODE_AP_RPTR:
6126 *uwrq = IW_MODE_REPEAT;
6127 break;
6128 default:
6129 *uwrq = IW_MODE_ADHOC;
6130 }
6131
6132 return 0;
6133}
6134
6135/*------------------------------------------------------------------*/
6136/*
6137 * Wireless Handler : set Encryption Key
6138 */
6139static int airo_set_encode(struct net_device *dev,
6140 struct iw_request_info *info,
6141 struct iw_point *dwrq,
6142 char *extra)
6143{
6144 struct airo_info *local = dev->priv;
6145 CapabilityRid cap_rid; /* Card capability info */
Dan Streetmanf89b2322005-11-11 11:41:42 -05006146 int perm = ( dwrq->flags & IW_ENCODE_TEMP ? 0 : 1 );
6147 u16 currentAuthType = local->config.authType;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006148
6149 /* Is WEP supported ? */
6150 readCapabilityRid(local, &cap_rid, 1);
6151 /* Older firmware doesn't support this...
6152 if(!(cap_rid.softCap & 2)) {
6153 return -EOPNOTSUPP;
6154 } */
6155 readConfigRid(local, 1);
6156
6157 /* Basic checking: do we have a key to set ?
6158 * Note : with the new API, it's impossible to get a NULL pointer.
6159 * Therefore, we need to check a key size == 0 instead.
6160 * New version of iwconfig properly set the IW_ENCODE_NOKEY flag
6161 * when no key is present (only change flags), but older versions
6162 * don't do it. - Jean II */
6163 if (dwrq->length > 0) {
6164 wep_key_t key;
6165 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6166 int current_index = get_wep_key(local, 0xffff);
6167 /* Check the size of the key */
6168 if (dwrq->length > MAX_KEY_SIZE) {
6169 return -EINVAL;
6170 }
6171 /* Check the index (none -> use current) */
6172 if ((index < 0) || (index >= ((cap_rid.softCap & 0x80) ? 4:1)))
6173 index = current_index;
6174 /* Set the length */
6175 if (dwrq->length > MIN_KEY_SIZE)
6176 key.len = MAX_KEY_SIZE;
6177 else
6178 if (dwrq->length > 0)
6179 key.len = MIN_KEY_SIZE;
6180 else
6181 /* Disable the key */
6182 key.len = 0;
6183 /* Check if the key is not marked as invalid */
6184 if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
6185 /* Cleanup */
6186 memset(key.key, 0, MAX_KEY_SIZE);
6187 /* Copy the key in the driver */
6188 memcpy(key.key, extra, dwrq->length);
6189 /* Send the key to the card */
Dan Streetmanf89b2322005-11-11 11:41:42 -05006190 set_wep_key(local, index, key.key, key.len, perm, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191 }
6192 /* WE specify that if a valid key is set, encryption
6193 * should be enabled (user may turn it off later)
6194 * This is also how "iwconfig ethX key on" works */
6195 if((index == current_index) && (key.len > 0) &&
6196 (local->config.authType == AUTH_OPEN)) {
6197 local->config.authType = AUTH_ENCRYPT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006198 }
6199 } else {
6200 /* Do we want to just set the transmit key index ? */
6201 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6202 if ((index >= 0) && (index < ((cap_rid.softCap & 0x80)?4:1))) {
Dan Streetmanf89b2322005-11-11 11:41:42 -05006203 set_wep_key(local, index, NULL, 0, perm, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006204 } else
6205 /* Don't complain if only change the mode */
6206 if(!dwrq->flags & IW_ENCODE_MODE) {
6207 return -EINVAL;
6208 }
6209 }
6210 /* Read the flags */
6211 if(dwrq->flags & IW_ENCODE_DISABLED)
6212 local->config.authType = AUTH_OPEN; // disable encryption
6213 if(dwrq->flags & IW_ENCODE_RESTRICTED)
6214 local->config.authType = AUTH_SHAREDKEY; // Only Both
6215 if(dwrq->flags & IW_ENCODE_OPEN)
6216 local->config.authType = AUTH_ENCRYPT; // Only Wep
6217 /* Commit the changes to flags if needed */
Dan Streetmanf89b2322005-11-11 11:41:42 -05006218 if (local->config.authType != currentAuthType)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006219 set_bit (FLAG_COMMIT, &local->flags);
6220 return -EINPROGRESS; /* Call commit handler */
6221}
6222
6223/*------------------------------------------------------------------*/
6224/*
6225 * Wireless Handler : get Encryption Key
6226 */
6227static int airo_get_encode(struct net_device *dev,
6228 struct iw_request_info *info,
6229 struct iw_point *dwrq,
6230 char *extra)
6231{
6232 struct airo_info *local = dev->priv;
6233 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6234 CapabilityRid cap_rid; /* Card capability info */
6235
6236 /* Is it supported ? */
6237 readCapabilityRid(local, &cap_rid, 1);
6238 if(!(cap_rid.softCap & 2)) {
6239 return -EOPNOTSUPP;
6240 }
6241 readConfigRid(local, 1);
6242 /* Check encryption mode */
6243 switch(local->config.authType) {
6244 case AUTH_ENCRYPT:
6245 dwrq->flags = IW_ENCODE_OPEN;
6246 break;
6247 case AUTH_SHAREDKEY:
6248 dwrq->flags = IW_ENCODE_RESTRICTED;
6249 break;
6250 default:
6251 case AUTH_OPEN:
6252 dwrq->flags = IW_ENCODE_DISABLED;
6253 break;
6254 }
6255 /* We can't return the key, so set the proper flag and return zero */
6256 dwrq->flags |= IW_ENCODE_NOKEY;
6257 memset(extra, 0, 16);
6258
6259 /* Which key do we want ? -1 -> tx index */
6260 if ((index < 0) || (index >= ((cap_rid.softCap & 0x80) ? 4 : 1)))
6261 index = get_wep_key(local, 0xffff);
6262 dwrq->flags |= index + 1;
6263 /* Copy the key to the user buffer */
6264 dwrq->length = get_wep_key(local, index);
6265 if (dwrq->length > 16) {
6266 dwrq->length=0;
6267 }
6268 return 0;
6269}
6270
6271/*------------------------------------------------------------------*/
6272/*
Dan Williams4be757d2006-01-30 11:58:00 -05006273 * Wireless Handler : set extended Encryption parameters
6274 */
6275static int airo_set_encodeext(struct net_device *dev,
6276 struct iw_request_info *info,
6277 union iwreq_data *wrqu,
6278 char *extra)
6279{
6280 struct airo_info *local = dev->priv;
6281 struct iw_point *encoding = &wrqu->encoding;
6282 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6283 CapabilityRid cap_rid; /* Card capability info */
6284 int perm = ( encoding->flags & IW_ENCODE_TEMP ? 0 : 1 );
6285 u16 currentAuthType = local->config.authType;
Dan Williams22d88462006-02-05 18:00:30 -05006286 int idx, key_len, alg = ext->alg, set_key = 1;
Dan Williams4be757d2006-01-30 11:58:00 -05006287 wep_key_t key;
6288
6289 /* Is WEP supported ? */
6290 readCapabilityRid(local, &cap_rid, 1);
6291 /* Older firmware doesn't support this...
6292 if(!(cap_rid.softCap & 2)) {
6293 return -EOPNOTSUPP;
6294 } */
6295 readConfigRid(local, 1);
6296
6297 /* Determine and validate the key index */
6298 idx = encoding->flags & IW_ENCODE_INDEX;
6299 if (idx) {
6300 if (idx < 1 || idx > ((cap_rid.softCap & 0x80) ? 4:1))
6301 return -EINVAL;
6302 idx--;
6303 } else
6304 idx = get_wep_key(local, 0xffff);
6305
6306 if (encoding->flags & IW_ENCODE_DISABLED)
6307 alg = IW_ENCODE_ALG_NONE;
6308
Dan Williams4be757d2006-01-30 11:58:00 -05006309 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
Dan Williams22d88462006-02-05 18:00:30 -05006310 /* Only set transmit key index here, actual
6311 * key is set below if needed.
6312 */
Dan Williams4be757d2006-01-30 11:58:00 -05006313 set_wep_key(local, idx, NULL, 0, perm, 1);
Dan Williams22d88462006-02-05 18:00:30 -05006314 set_key = ext->key_len > 0 ? 1 : 0;
6315 }
6316
6317 if (set_key) {
Dan Williams4be757d2006-01-30 11:58:00 -05006318 /* Set the requested key first */
6319 memset(key.key, 0, MAX_KEY_SIZE);
6320 switch (alg) {
6321 case IW_ENCODE_ALG_NONE:
6322 key.len = 0;
6323 break;
6324 case IW_ENCODE_ALG_WEP:
6325 if (ext->key_len > MIN_KEY_SIZE) {
6326 key.len = MAX_KEY_SIZE;
6327 } else if (ext->key_len > 0) {
6328 key.len = MIN_KEY_SIZE;
6329 } else {
6330 return -EINVAL;
6331 }
6332 key_len = min (ext->key_len, key.len);
6333 memcpy(key.key, ext->key, key_len);
6334 break;
6335 default:
6336 return -EINVAL;
6337 }
6338 /* Send the key to the card */
6339 set_wep_key(local, idx, key.key, key.len, perm, 1);
6340 }
6341
6342 /* Read the flags */
6343 if(encoding->flags & IW_ENCODE_DISABLED)
6344 local->config.authType = AUTH_OPEN; // disable encryption
6345 if(encoding->flags & IW_ENCODE_RESTRICTED)
6346 local->config.authType = AUTH_SHAREDKEY; // Only Both
6347 if(encoding->flags & IW_ENCODE_OPEN)
6348 local->config.authType = AUTH_ENCRYPT; // Only Wep
6349 /* Commit the changes to flags if needed */
6350 if (local->config.authType != currentAuthType)
6351 set_bit (FLAG_COMMIT, &local->flags);
6352
6353 return -EINPROGRESS;
6354}
6355
6356
6357/*------------------------------------------------------------------*/
6358/*
6359 * Wireless Handler : get extended Encryption parameters
6360 */
6361static int airo_get_encodeext(struct net_device *dev,
6362 struct iw_request_info *info,
6363 union iwreq_data *wrqu,
6364 char *extra)
6365{
6366 struct airo_info *local = dev->priv;
6367 struct iw_point *encoding = &wrqu->encoding;
6368 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6369 CapabilityRid cap_rid; /* Card capability info */
6370 int idx, max_key_len;
6371
6372 /* Is it supported ? */
6373 readCapabilityRid(local, &cap_rid, 1);
6374 if(!(cap_rid.softCap & 2)) {
6375 return -EOPNOTSUPP;
6376 }
6377 readConfigRid(local, 1);
6378
6379 max_key_len = encoding->length - sizeof(*ext);
6380 if (max_key_len < 0)
6381 return -EINVAL;
6382
6383 idx = encoding->flags & IW_ENCODE_INDEX;
6384 if (idx) {
6385 if (idx < 1 || idx > ((cap_rid.softCap & 0x80) ? 4:1))
6386 return -EINVAL;
6387 idx--;
6388 } else
6389 idx = get_wep_key(local, 0xffff);
6390
6391 encoding->flags = idx + 1;
6392 memset(ext, 0, sizeof(*ext));
6393
6394 /* Check encryption mode */
6395 switch(local->config.authType) {
6396 case AUTH_ENCRYPT:
6397 encoding->flags = IW_ENCODE_ALG_WEP | IW_ENCODE_ENABLED;
6398 break;
6399 case AUTH_SHAREDKEY:
6400 encoding->flags = IW_ENCODE_ALG_WEP | IW_ENCODE_ENABLED;
6401 break;
6402 default:
6403 case AUTH_OPEN:
6404 encoding->flags = IW_ENCODE_ALG_NONE | IW_ENCODE_DISABLED;
6405 break;
6406 }
6407 /* We can't return the key, so set the proper flag and return zero */
6408 encoding->flags |= IW_ENCODE_NOKEY;
6409 memset(extra, 0, 16);
6410
6411 /* Copy the key to the user buffer */
6412 ext->key_len = get_wep_key(local, idx);
6413 if (ext->key_len > 16) {
6414 ext->key_len=0;
6415 }
6416
6417 return 0;
6418}
6419
6420
6421/*------------------------------------------------------------------*/
6422/*
6423 * Wireless Handler : set extended authentication parameters
6424 */
6425static int airo_set_auth(struct net_device *dev,
6426 struct iw_request_info *info,
6427 union iwreq_data *wrqu, char *extra)
6428{
6429 struct airo_info *local = dev->priv;
6430 struct iw_param *param = &wrqu->param;
6431 u16 currentAuthType = local->config.authType;
6432
6433 switch (param->flags & IW_AUTH_INDEX) {
6434 case IW_AUTH_WPA_VERSION:
6435 case IW_AUTH_CIPHER_PAIRWISE:
6436 case IW_AUTH_CIPHER_GROUP:
6437 case IW_AUTH_KEY_MGMT:
6438 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6439 case IW_AUTH_PRIVACY_INVOKED:
6440 /*
6441 * airo does not use these parameters
6442 */
6443 break;
6444
6445 case IW_AUTH_DROP_UNENCRYPTED:
6446 if (param->value) {
6447 /* Only change auth type if unencrypted */
6448 if (currentAuthType == AUTH_OPEN)
6449 local->config.authType = AUTH_ENCRYPT;
6450 } else {
6451 local->config.authType = AUTH_OPEN;
6452 }
6453
6454 /* Commit the changes to flags if needed */
6455 if (local->config.authType != currentAuthType)
6456 set_bit (FLAG_COMMIT, &local->flags);
6457 break;
6458
6459 case IW_AUTH_80211_AUTH_ALG: {
6460 /* FIXME: What about AUTH_OPEN? This API seems to
6461 * disallow setting our auth to AUTH_OPEN.
6462 */
6463 if (param->value & IW_AUTH_ALG_SHARED_KEY) {
6464 local->config.authType = AUTH_SHAREDKEY;
6465 } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) {
6466 local->config.authType = AUTH_ENCRYPT;
6467 } else
6468 return -EINVAL;
6469 break;
6470
6471 /* Commit the changes to flags if needed */
6472 if (local->config.authType != currentAuthType)
6473 set_bit (FLAG_COMMIT, &local->flags);
6474 }
6475
6476 case IW_AUTH_WPA_ENABLED:
6477 /* Silently accept disable of WPA */
6478 if (param->value > 0)
6479 return -EOPNOTSUPP;
6480 break;
6481
6482 default:
6483 return -EOPNOTSUPP;
6484 }
6485 return -EINPROGRESS;
6486}
6487
6488
6489/*------------------------------------------------------------------*/
6490/*
6491 * Wireless Handler : get extended authentication parameters
6492 */
6493static int airo_get_auth(struct net_device *dev,
6494 struct iw_request_info *info,
6495 union iwreq_data *wrqu, char *extra)
6496{
6497 struct airo_info *local = dev->priv;
6498 struct iw_param *param = &wrqu->param;
6499 u16 currentAuthType = local->config.authType;
6500
6501 switch (param->flags & IW_AUTH_INDEX) {
6502 case IW_AUTH_DROP_UNENCRYPTED:
6503 switch (currentAuthType) {
6504 case AUTH_SHAREDKEY:
6505 case AUTH_ENCRYPT:
6506 param->value = 1;
6507 break;
6508 default:
6509 param->value = 0;
6510 break;
6511 }
6512 break;
6513
6514 case IW_AUTH_80211_AUTH_ALG:
6515 switch (currentAuthType) {
6516 case AUTH_SHAREDKEY:
6517 param->value = IW_AUTH_ALG_SHARED_KEY;
6518 break;
6519 case AUTH_ENCRYPT:
6520 default:
6521 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
6522 break;
6523 }
6524 break;
6525
6526 case IW_AUTH_WPA_ENABLED:
6527 param->value = 0;
6528 break;
6529
6530 default:
6531 return -EOPNOTSUPP;
6532 }
6533 return 0;
6534}
6535
6536
6537/*------------------------------------------------------------------*/
6538/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006539 * Wireless Handler : set Tx-Power
6540 */
6541static int airo_set_txpow(struct net_device *dev,
6542 struct iw_request_info *info,
6543 struct iw_param *vwrq,
6544 char *extra)
6545{
6546 struct airo_info *local = dev->priv;
6547 CapabilityRid cap_rid; /* Card capability info */
6548 int i;
6549 int rc = -EINVAL;
6550
6551 readCapabilityRid(local, &cap_rid, 1);
6552
6553 if (vwrq->disabled) {
6554 set_bit (FLAG_RADIO_OFF, &local->flags);
6555 set_bit (FLAG_COMMIT, &local->flags);
6556 return -EINPROGRESS; /* Call commit handler */
6557 }
6558 if (vwrq->flags != IW_TXPOW_MWATT) {
6559 return -EINVAL;
6560 }
6561 clear_bit (FLAG_RADIO_OFF, &local->flags);
6562 for (i = 0; cap_rid.txPowerLevels[i] && (i < 8); i++)
6563 if ((vwrq->value==cap_rid.txPowerLevels[i])) {
6564 readConfigRid(local, 1);
6565 local->config.txPower = vwrq->value;
6566 set_bit (FLAG_COMMIT, &local->flags);
6567 rc = -EINPROGRESS; /* Call commit handler */
6568 break;
6569 }
6570 return rc;
6571}
6572
6573/*------------------------------------------------------------------*/
6574/*
6575 * Wireless Handler : get Tx-Power
6576 */
6577static int airo_get_txpow(struct net_device *dev,
6578 struct iw_request_info *info,
6579 struct iw_param *vwrq,
6580 char *extra)
6581{
6582 struct airo_info *local = dev->priv;
6583
6584 readConfigRid(local, 1);
6585 vwrq->value = local->config.txPower;
6586 vwrq->fixed = 1; /* No power control */
6587 vwrq->disabled = test_bit(FLAG_RADIO_OFF, &local->flags);
6588 vwrq->flags = IW_TXPOW_MWATT;
6589
6590 return 0;
6591}
6592
6593/*------------------------------------------------------------------*/
6594/*
6595 * Wireless Handler : set Retry limits
6596 */
6597static int airo_set_retry(struct net_device *dev,
6598 struct iw_request_info *info,
6599 struct iw_param *vwrq,
6600 char *extra)
6601{
6602 struct airo_info *local = dev->priv;
6603 int rc = -EINVAL;
6604
6605 if(vwrq->disabled) {
6606 return -EINVAL;
6607 }
6608 readConfigRid(local, 1);
6609 if(vwrq->flags & IW_RETRY_LIMIT) {
6610 if(vwrq->flags & IW_RETRY_MAX)
6611 local->config.longRetryLimit = vwrq->value;
6612 else if (vwrq->flags & IW_RETRY_MIN)
6613 local->config.shortRetryLimit = vwrq->value;
6614 else {
6615 /* No modifier : set both */
6616 local->config.longRetryLimit = vwrq->value;
6617 local->config.shortRetryLimit = vwrq->value;
6618 }
6619 set_bit (FLAG_COMMIT, &local->flags);
6620 rc = -EINPROGRESS; /* Call commit handler */
6621 }
6622 if(vwrq->flags & IW_RETRY_LIFETIME) {
6623 local->config.txLifetime = vwrq->value / 1024;
6624 set_bit (FLAG_COMMIT, &local->flags);
6625 rc = -EINPROGRESS; /* Call commit handler */
6626 }
6627 return rc;
6628}
6629
6630/*------------------------------------------------------------------*/
6631/*
6632 * Wireless Handler : get Retry limits
6633 */
6634static int airo_get_retry(struct net_device *dev,
6635 struct iw_request_info *info,
6636 struct iw_param *vwrq,
6637 char *extra)
6638{
6639 struct airo_info *local = dev->priv;
6640
6641 vwrq->disabled = 0; /* Can't be disabled */
6642
6643 readConfigRid(local, 1);
6644 /* Note : by default, display the min retry number */
6645 if((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
6646 vwrq->flags = IW_RETRY_LIFETIME;
6647 vwrq->value = (int)local->config.txLifetime * 1024;
6648 } else if((vwrq->flags & IW_RETRY_MAX)) {
6649 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
6650 vwrq->value = (int)local->config.longRetryLimit;
6651 } else {
6652 vwrq->flags = IW_RETRY_LIMIT;
6653 vwrq->value = (int)local->config.shortRetryLimit;
6654 if((int)local->config.shortRetryLimit != (int)local->config.longRetryLimit)
6655 vwrq->flags |= IW_RETRY_MIN;
6656 }
6657
6658 return 0;
6659}
6660
6661/*------------------------------------------------------------------*/
6662/*
6663 * Wireless Handler : get range info
6664 */
6665static int airo_get_range(struct net_device *dev,
6666 struct iw_request_info *info,
6667 struct iw_point *dwrq,
6668 char *extra)
6669{
6670 struct airo_info *local = dev->priv;
6671 struct iw_range *range = (struct iw_range *) extra;
6672 CapabilityRid cap_rid; /* Card capability info */
6673 int i;
6674 int k;
6675
6676 readCapabilityRid(local, &cap_rid, 1);
6677
6678 dwrq->length = sizeof(struct iw_range);
6679 memset(range, 0, sizeof(*range));
6680 range->min_nwid = 0x0000;
6681 range->max_nwid = 0x0000;
6682 range->num_channels = 14;
6683 /* Should be based on cap_rid.country to give only
6684 * what the current card support */
6685 k = 0;
6686 for(i = 0; i < 14; i++) {
6687 range->freq[k].i = i + 1; /* List index */
6688 range->freq[k].m = frequency_list[i] * 100000;
6689 range->freq[k++].e = 1; /* Values in table in MHz -> * 10^5 * 10 */
6690 }
6691 range->num_frequency = k;
6692
Linus Torvalds1da177e2005-04-16 15:20:36 -07006693 range->sensitivity = 65535;
6694
Dan Williams41480af2005-05-10 09:45:51 -04006695 /* Hum... Should put the right values there */
6696 if (local->rssi)
6697 range->max_qual.qual = 100; /* % */
6698 else
6699 range->max_qual.qual = airo_get_max_quality(&cap_rid);
Jean Tourrilhesce6623c2005-09-02 11:45:10 -07006700 range->max_qual.level = 0x100 - 120; /* -120 dBm */
6701 range->max_qual.noise = 0x100 - 120; /* -120 dBm */
Dan Williams41480af2005-05-10 09:45:51 -04006702
6703 /* Experimental measurements - boundary 11/5.5 Mb/s */
6704 /* Note : with or without the (local->rssi), results
6705 * are somewhat different. - Jean II */
6706 if (local->rssi) {
Jean Tourrilhesce6623c2005-09-02 11:45:10 -07006707 range->avg_qual.qual = 50; /* % */
6708 range->avg_qual.level = 0x100 - 70; /* -70 dBm */
Dan Williams41480af2005-05-10 09:45:51 -04006709 } else {
6710 range->avg_qual.qual = airo_get_avg_quality(&cap_rid);
Jean Tourrilhesce6623c2005-09-02 11:45:10 -07006711 range->avg_qual.level = 0x100 - 80; /* -80 dBm */
Dan Williams41480af2005-05-10 09:45:51 -04006712 }
Jean Tourrilhesce6623c2005-09-02 11:45:10 -07006713 range->avg_qual.noise = 0x100 - 85; /* -85 dBm */
Dan Williams41480af2005-05-10 09:45:51 -04006714
Linus Torvalds1da177e2005-04-16 15:20:36 -07006715 for(i = 0 ; i < 8 ; i++) {
6716 range->bitrate[i] = cap_rid.supportedRates[i] * 500000;
6717 if(range->bitrate[i] == 0)
6718 break;
6719 }
6720 range->num_bitrates = i;
6721
6722 /* Set an indication of the max TCP throughput
6723 * in bit/s that we can expect using this interface.
6724 * May be use for QoS stuff... Jean II */
6725 if(i > 2)
6726 range->throughput = 5000 * 1000;
6727 else
6728 range->throughput = 1500 * 1000;
6729
6730 range->min_rts = 0;
6731 range->max_rts = 2312;
6732 range->min_frag = 256;
6733 range->max_frag = 2312;
6734
6735 if(cap_rid.softCap & 2) {
6736 // WEP: RC4 40 bits
6737 range->encoding_size[0] = 5;
6738 // RC4 ~128 bits
6739 if (cap_rid.softCap & 0x100) {
6740 range->encoding_size[1] = 13;
6741 range->num_encoding_sizes = 2;
6742 } else
6743 range->num_encoding_sizes = 1;
6744 range->max_encoding_tokens = (cap_rid.softCap & 0x80) ? 4 : 1;
6745 } else {
6746 range->num_encoding_sizes = 0;
6747 range->max_encoding_tokens = 0;
6748 }
6749 range->min_pmp = 0;
6750 range->max_pmp = 5000000; /* 5 secs */
6751 range->min_pmt = 0;
6752 range->max_pmt = 65535 * 1024; /* ??? */
6753 range->pmp_flags = IW_POWER_PERIOD;
6754 range->pmt_flags = IW_POWER_TIMEOUT;
6755 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
6756
6757 /* Transmit Power - values are in mW */
6758 for(i = 0 ; i < 8 ; i++) {
6759 range->txpower[i] = cap_rid.txPowerLevels[i];
6760 if(range->txpower[i] == 0)
6761 break;
6762 }
6763 range->num_txpower = i;
6764 range->txpower_capa = IW_TXPOW_MWATT;
6765 range->we_version_source = 12;
6766 range->we_version_compiled = WIRELESS_EXT;
6767 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
6768 range->retry_flags = IW_RETRY_LIMIT;
6769 range->r_time_flags = IW_RETRY_LIFETIME;
6770 range->min_retry = 1;
6771 range->max_retry = 65535;
6772 range->min_r_time = 1024;
6773 range->max_r_time = 65535 * 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006774
6775 /* Event capability (kernel + driver) */
6776 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
6777 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
6778 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
6779 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
6780 range->event_capa[1] = IW_EVENT_CAPA_K_1;
6781 range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVTXDROP);
6782 return 0;
6783}
6784
6785/*------------------------------------------------------------------*/
6786/*
6787 * Wireless Handler : set Power Management
6788 */
6789static int airo_set_power(struct net_device *dev,
6790 struct iw_request_info *info,
6791 struct iw_param *vwrq,
6792 char *extra)
6793{
6794 struct airo_info *local = dev->priv;
6795
6796 readConfigRid(local, 1);
6797 if (vwrq->disabled) {
6798 if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
6799 return -EINVAL;
6800 }
6801 local->config.powerSaveMode = POWERSAVE_CAM;
6802 local->config.rmode &= 0xFF00;
6803 local->config.rmode |= RXMODE_BC_MC_ADDR;
6804 set_bit (FLAG_COMMIT, &local->flags);
6805 return -EINPROGRESS; /* Call commit handler */
6806 }
6807 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
6808 local->config.fastListenDelay = (vwrq->value + 500) / 1024;
6809 local->config.powerSaveMode = POWERSAVE_PSPCAM;
6810 set_bit (FLAG_COMMIT, &local->flags);
6811 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
6812 local->config.fastListenInterval = local->config.listenInterval = (vwrq->value + 500) / 1024;
6813 local->config.powerSaveMode = POWERSAVE_PSPCAM;
6814 set_bit (FLAG_COMMIT, &local->flags);
6815 }
6816 switch (vwrq->flags & IW_POWER_MODE) {
6817 case IW_POWER_UNICAST_R:
6818 if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
6819 return -EINVAL;
6820 }
6821 local->config.rmode &= 0xFF00;
6822 local->config.rmode |= RXMODE_ADDR;
6823 set_bit (FLAG_COMMIT, &local->flags);
6824 break;
6825 case IW_POWER_ALL_R:
6826 if ((local->config.rmode & 0xFF) >= RXMODE_RFMON) {
6827 return -EINVAL;
6828 }
6829 local->config.rmode &= 0xFF00;
6830 local->config.rmode |= RXMODE_BC_MC_ADDR;
6831 set_bit (FLAG_COMMIT, &local->flags);
6832 case IW_POWER_ON:
6833 break;
6834 default:
6835 return -EINVAL;
6836 }
6837 // Note : we may want to factor local->need_commit here
6838 // Note2 : may also want to factor RXMODE_RFMON test
6839 return -EINPROGRESS; /* Call commit handler */
6840}
6841
6842/*------------------------------------------------------------------*/
6843/*
6844 * Wireless Handler : get Power Management
6845 */
6846static int airo_get_power(struct net_device *dev,
6847 struct iw_request_info *info,
6848 struct iw_param *vwrq,
6849 char *extra)
6850{
6851 struct airo_info *local = dev->priv;
6852 int mode;
6853
6854 readConfigRid(local, 1);
6855 mode = local->config.powerSaveMode;
6856 if ((vwrq->disabled = (mode == POWERSAVE_CAM)))
6857 return 0;
6858 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
6859 vwrq->value = (int)local->config.fastListenDelay * 1024;
6860 vwrq->flags = IW_POWER_TIMEOUT;
6861 } else {
6862 vwrq->value = (int)local->config.fastListenInterval * 1024;
6863 vwrq->flags = IW_POWER_PERIOD;
6864 }
6865 if ((local->config.rmode & 0xFF) == RXMODE_ADDR)
6866 vwrq->flags |= IW_POWER_UNICAST_R;
6867 else
6868 vwrq->flags |= IW_POWER_ALL_R;
6869
6870 return 0;
6871}
6872
6873/*------------------------------------------------------------------*/
6874/*
6875 * Wireless Handler : set Sensitivity
6876 */
6877static int airo_set_sens(struct net_device *dev,
6878 struct iw_request_info *info,
6879 struct iw_param *vwrq,
6880 char *extra)
6881{
6882 struct airo_info *local = dev->priv;
6883
6884 readConfigRid(local, 1);
6885 local->config.rssiThreshold = vwrq->disabled ? RSSI_DEFAULT : vwrq->value;
6886 set_bit (FLAG_COMMIT, &local->flags);
6887
6888 return -EINPROGRESS; /* Call commit handler */
6889}
6890
6891/*------------------------------------------------------------------*/
6892/*
6893 * Wireless Handler : get Sensitivity
6894 */
6895static int airo_get_sens(struct net_device *dev,
6896 struct iw_request_info *info,
6897 struct iw_param *vwrq,
6898 char *extra)
6899{
6900 struct airo_info *local = dev->priv;
6901
6902 readConfigRid(local, 1);
6903 vwrq->value = local->config.rssiThreshold;
6904 vwrq->disabled = (vwrq->value == 0);
6905 vwrq->fixed = 1;
6906
6907 return 0;
6908}
6909
6910/*------------------------------------------------------------------*/
6911/*
6912 * Wireless Handler : get AP List
6913 * Note : this is deprecated in favor of IWSCAN
6914 */
6915static int airo_get_aplist(struct net_device *dev,
6916 struct iw_request_info *info,
6917 struct iw_point *dwrq,
6918 char *extra)
6919{
6920 struct airo_info *local = dev->priv;
6921 struct sockaddr *address = (struct sockaddr *) extra;
6922 struct iw_quality qual[IW_MAX_AP];
6923 BSSListRid BSSList;
6924 int i;
6925 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
6926
6927 for (i = 0; i < IW_MAX_AP; i++) {
6928 if (readBSSListRid(local, loseSync, &BSSList))
6929 break;
6930 loseSync = 0;
6931 memcpy(address[i].sa_data, BSSList.bssid, ETH_ALEN);
6932 address[i].sa_family = ARPHRD_ETHER;
Dan Williams41480af2005-05-10 09:45:51 -04006933 if (local->rssi) {
6934 qual[i].level = 0x100 - BSSList.dBm;
6935 qual[i].qual = airo_dbm_to_pct( local->rssi, BSSList.dBm );
Jean Tourrilhesce6623c2005-09-02 11:45:10 -07006936 qual[i].updated = IW_QUAL_QUAL_UPDATED
6937 | IW_QUAL_LEVEL_UPDATED
6938 | IW_QUAL_DBM;
Dan Williams41480af2005-05-10 09:45:51 -04006939 } else {
6940 qual[i].level = (BSSList.dBm + 321) / 2;
6941 qual[i].qual = 0;
Jean Tourrilhesce6623c2005-09-02 11:45:10 -07006942 qual[i].updated = IW_QUAL_QUAL_INVALID
6943 | IW_QUAL_LEVEL_UPDATED
6944 | IW_QUAL_DBM;
Dan Williams41480af2005-05-10 09:45:51 -04006945 }
6946 qual[i].noise = local->wstats.qual.noise;
Linus Torvalds1da177e2005-04-16 15:20:36 -07006947 if (BSSList.index == 0xffff)
6948 break;
6949 }
6950 if (!i) {
6951 StatusRid status_rid; /* Card status info */
6952 readStatusRid(local, &status_rid, 1);
6953 for (i = 0;
6954 i < min(IW_MAX_AP, 4) &&
6955 (status_rid.bssid[i][0]
6956 & status_rid.bssid[i][1]
6957 & status_rid.bssid[i][2]
6958 & status_rid.bssid[i][3]
6959 & status_rid.bssid[i][4]
6960 & status_rid.bssid[i][5])!=0xff &&
6961 (status_rid.bssid[i][0]
6962 | status_rid.bssid[i][1]
6963 | status_rid.bssid[i][2]
6964 | status_rid.bssid[i][3]
6965 | status_rid.bssid[i][4]
6966 | status_rid.bssid[i][5]);
6967 i++) {
6968 memcpy(address[i].sa_data,
6969 status_rid.bssid[i], ETH_ALEN);
6970 address[i].sa_family = ARPHRD_ETHER;
6971 }
6972 } else {
6973 dwrq->flags = 1; /* Should be define'd */
6974 memcpy(extra + sizeof(struct sockaddr)*i,
6975 &qual, sizeof(struct iw_quality)*i);
6976 }
6977 dwrq->length = i;
6978
6979 return 0;
6980}
6981
6982/*------------------------------------------------------------------*/
6983/*
6984 * Wireless Handler : Initiate Scan
6985 */
6986static int airo_set_scan(struct net_device *dev,
6987 struct iw_request_info *info,
6988 struct iw_param *vwrq,
6989 char *extra)
6990{
6991 struct airo_info *ai = dev->priv;
6992 Cmd cmd;
6993 Resp rsp;
6994
6995 /* Note : you may have realised that, as this is a SET operation,
6996 * this is privileged and therefore a normal user can't
6997 * perform scanning.
6998 * This is not an error, while the device perform scanning,
6999 * traffic doesn't flow, so it's a perfect DoS...
7000 * Jean II */
7001 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
7002
7003 /* Initiate a scan command */
7004 memset(&cmd, 0, sizeof(cmd));
7005 cmd.cmd=CMD_LISTBSS;
7006 if (down_interruptible(&ai->sem))
7007 return -ERESTARTSYS;
7008 issuecommand(ai, &cmd, &rsp);
7009 ai->scan_timestamp = jiffies;
7010 up(&ai->sem);
7011
7012 /* At this point, just return to the user. */
7013
7014 return 0;
7015}
7016
7017/*------------------------------------------------------------------*/
7018/*
7019 * Translate scan data returned from the card to a card independent
7020 * format that the Wireless Tools will understand - Jean II
7021 */
7022static inline char *airo_translate_scan(struct net_device *dev,
7023 char *current_ev,
7024 char *end_buf,
Dan Williams41480af2005-05-10 09:45:51 -04007025 BSSListRid *bss)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007026{
7027 struct airo_info *ai = dev->priv;
7028 struct iw_event iwe; /* Temporary buffer */
7029 u16 capabilities;
7030 char * current_val; /* For rates */
7031 int i;
7032
7033 /* First entry *MUST* be the AP MAC address */
7034 iwe.cmd = SIOCGIWAP;
7035 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
Dan Williams41480af2005-05-10 09:45:51 -04007036 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007037 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_ADDR_LEN);
7038
7039 /* Other entries will be displayed in the order we give them */
7040
7041 /* Add the ESSID */
Dan Williams41480af2005-05-10 09:45:51 -04007042 iwe.u.data.length = bss->ssidLen;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007043 if(iwe.u.data.length > 32)
7044 iwe.u.data.length = 32;
7045 iwe.cmd = SIOCGIWESSID;
7046 iwe.u.data.flags = 1;
Dan Williams41480af2005-05-10 09:45:51 -04007047 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, bss->ssid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007048
7049 /* Add mode */
7050 iwe.cmd = SIOCGIWMODE;
Dan Williams41480af2005-05-10 09:45:51 -04007051 capabilities = le16_to_cpu(bss->cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007052 if(capabilities & (CAP_ESS | CAP_IBSS)) {
7053 if(capabilities & CAP_ESS)
7054 iwe.u.mode = IW_MODE_MASTER;
7055 else
7056 iwe.u.mode = IW_MODE_ADHOC;
7057 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_UINT_LEN);
7058 }
7059
7060 /* Add frequency */
7061 iwe.cmd = SIOCGIWFREQ;
Dan Williams41480af2005-05-10 09:45:51 -04007062 iwe.u.freq.m = le16_to_cpu(bss->dsChannel);
matthieu castet11414552005-09-12 23:31:39 +02007063 /* iwe.u.freq.m containt the channel (starting 1), our
7064 * frequency_list array start at index 0...
7065 */
7066 iwe.u.freq.m = frequency_list[iwe.u.freq.m - 1] * 100000;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007067 iwe.u.freq.e = 1;
7068 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_FREQ_LEN);
7069
7070 /* Add quality statistics */
7071 iwe.cmd = IWEVQUAL;
Dan Williams41480af2005-05-10 09:45:51 -04007072 if (ai->rssi) {
7073 iwe.u.qual.level = 0x100 - bss->dBm;
7074 iwe.u.qual.qual = airo_dbm_to_pct( ai->rssi, bss->dBm );
Jean Tourrilhesce6623c2005-09-02 11:45:10 -07007075 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED
7076 | IW_QUAL_LEVEL_UPDATED
7077 | IW_QUAL_DBM;
Dan Williams41480af2005-05-10 09:45:51 -04007078 } else {
7079 iwe.u.qual.level = (bss->dBm + 321) / 2;
7080 iwe.u.qual.qual = 0;
Jeff Garzikbbeec902005-09-07 00:27:54 -04007081 iwe.u.qual.updated = IW_QUAL_QUAL_INVALID
Jean Tourrilhesce6623c2005-09-02 11:45:10 -07007082 | IW_QUAL_LEVEL_UPDATED
7083 | IW_QUAL_DBM;
Dan Williams41480af2005-05-10 09:45:51 -04007084 }
7085 iwe.u.qual.noise = ai->wstats.qual.noise;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007086 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe, IW_EV_QUAL_LEN);
7087
7088 /* Add encryption capability */
7089 iwe.cmd = SIOCGIWENCODE;
7090 if(capabilities & CAP_PRIVACY)
7091 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
7092 else
7093 iwe.u.data.flags = IW_ENCODE_DISABLED;
7094 iwe.u.data.length = 0;
Dan Williams41480af2005-05-10 09:45:51 -04007095 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, bss->ssid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007096
7097 /* Rate : stuffing multiple values in a single event require a bit
7098 * more of magic - Jean II */
7099 current_val = current_ev + IW_EV_LCP_LEN;
7100
7101 iwe.cmd = SIOCGIWRATE;
7102 /* Those two flags are ignored... */
7103 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
7104 /* Max 8 values */
7105 for(i = 0 ; i < 8 ; i++) {
7106 /* NULL terminated */
Dan Williams41480af2005-05-10 09:45:51 -04007107 if(bss->rates[i] == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007108 break;
7109 /* Bit rate given in 500 kb/s units (+ 0x80) */
Dan Williams41480af2005-05-10 09:45:51 -04007110 iwe.u.bitrate.value = ((bss->rates[i] & 0x7f) * 500000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07007111 /* Add new value to event */
7112 current_val = iwe_stream_add_value(current_ev, current_val, end_buf, &iwe, IW_EV_PARAM_LEN);
7113 }
7114 /* Check if we added any event */
7115 if((current_val - current_ev) > IW_EV_LCP_LEN)
7116 current_ev = current_val;
7117
7118 /* The other data in the scan result are not really
7119 * interesting, so for now drop it - Jean II */
7120 return current_ev;
7121}
7122
7123/*------------------------------------------------------------------*/
7124/*
7125 * Wireless Handler : Read Scan Results
7126 */
7127static int airo_get_scan(struct net_device *dev,
7128 struct iw_request_info *info,
7129 struct iw_point *dwrq,
7130 char *extra)
7131{
7132 struct airo_info *ai = dev->priv;
7133 BSSListRid BSSList;
7134 int rc;
7135 char *current_ev = extra;
7136
7137 /* When we are associated again, the scan has surely finished.
7138 * Just in case, let's make sure enough time has elapsed since
7139 * we started the scan. - Javier */
7140 if(ai->scan_timestamp && time_before(jiffies,ai->scan_timestamp+3*HZ)) {
7141 /* Important note : we don't want to block the caller
7142 * until results are ready for various reasons.
7143 * First, managing wait queues is complex and racy
7144 * (there may be multiple simultaneous callers).
7145 * Second, we grab some rtnetlink lock before comming
7146 * here (in dev_ioctl()).
7147 * Third, the caller can wait on the Wireless Event
7148 * - Jean II */
7149 return -EAGAIN;
7150 }
7151 ai->scan_timestamp = 0;
7152
7153 /* There's only a race with proc_BSSList_open(), but its
7154 * consequences are begnign. So I don't bother fixing it - Javier */
7155
7156 /* Try to read the first entry of the scan result */
7157 rc = PC4500_readrid(ai, RID_BSSLISTFIRST, &BSSList, sizeof(BSSList), 1);
7158 if((rc) || (BSSList.index == 0xffff)) {
7159 /* Client error, no scan results...
7160 * The caller need to restart the scan. */
7161 return -ENODATA;
7162 }
7163
7164 /* Read and parse all entries */
7165 while((!rc) && (BSSList.index != 0xffff)) {
7166 /* Translate to WE format this entry */
7167 current_ev = airo_translate_scan(dev, current_ev,
7168 extra + dwrq->length,
7169 &BSSList);
7170
7171 /* Check if there is space for one more entry */
7172 if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) {
7173 /* Ask user space to try again with a bigger buffer */
7174 return -E2BIG;
7175 }
7176
7177 /* Read next entry */
7178 rc = PC4500_readrid(ai, RID_BSSLISTNEXT,
7179 &BSSList, sizeof(BSSList), 1);
7180 }
7181 /* Length of data */
7182 dwrq->length = (current_ev - extra);
7183 dwrq->flags = 0; /* todo */
7184
7185 return 0;
7186}
7187
7188/*------------------------------------------------------------------*/
7189/*
7190 * Commit handler : called after a bunch of SET operations
7191 */
7192static int airo_config_commit(struct net_device *dev,
7193 struct iw_request_info *info, /* NULL */
7194 void *zwrq, /* NULL */
7195 char *extra) /* NULL */
7196{
7197 struct airo_info *local = dev->priv;
7198 Resp rsp;
7199
7200 if (!test_bit (FLAG_COMMIT, &local->flags))
7201 return 0;
7202
7203 /* Some of the "SET" function may have modified some of the
7204 * parameters. It's now time to commit them in the card */
7205 disable_MAC(local, 1);
7206 if (test_bit (FLAG_RESET, &local->flags)) {
7207 APListRid APList_rid;
7208 SsidRid SSID_rid;
7209
7210 readAPListRid(local, &APList_rid);
7211 readSsidRid(local, &SSID_rid);
7212 if (test_bit(FLAG_MPI,&local->flags))
7213 setup_card(local, dev->dev_addr, 1 );
7214 else
7215 reset_airo_card(dev);
7216 disable_MAC(local, 1);
7217 writeSsidRid(local, &SSID_rid, 1);
7218 writeAPListRid(local, &APList_rid, 1);
7219 }
7220 if (down_interruptible(&local->sem))
7221 return -ERESTARTSYS;
7222 writeConfigRid(local, 0);
7223 enable_MAC(local, &rsp, 0);
7224 if (test_bit (FLAG_RESET, &local->flags))
7225 airo_set_promisc(local);
7226 else
7227 up(&local->sem);
7228
7229 return 0;
7230}
7231
7232/*------------------------------------------------------------------*/
7233/*
7234 * Structures to export the Wireless Handlers
7235 */
7236
7237static const struct iw_priv_args airo_private_args[] = {
7238/*{ cmd, set_args, get_args, name } */
7239 { AIROIOCTL, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
7240 IW_PRIV_TYPE_BYTE | 2047, "airoioctl" },
7241 { AIROIDIFC, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
7242 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "airoidifc" },
7243};
7244
7245static const iw_handler airo_handler[] =
7246{
7247 (iw_handler) airo_config_commit, /* SIOCSIWCOMMIT */
7248 (iw_handler) airo_get_name, /* SIOCGIWNAME */
7249 (iw_handler) NULL, /* SIOCSIWNWID */
7250 (iw_handler) NULL, /* SIOCGIWNWID */
7251 (iw_handler) airo_set_freq, /* SIOCSIWFREQ */
7252 (iw_handler) airo_get_freq, /* SIOCGIWFREQ */
7253 (iw_handler) airo_set_mode, /* SIOCSIWMODE */
7254 (iw_handler) airo_get_mode, /* SIOCGIWMODE */
7255 (iw_handler) airo_set_sens, /* SIOCSIWSENS */
7256 (iw_handler) airo_get_sens, /* SIOCGIWSENS */
7257 (iw_handler) NULL, /* SIOCSIWRANGE */
7258 (iw_handler) airo_get_range, /* SIOCGIWRANGE */
7259 (iw_handler) NULL, /* SIOCSIWPRIV */
7260 (iw_handler) NULL, /* SIOCGIWPRIV */
7261 (iw_handler) NULL, /* SIOCSIWSTATS */
7262 (iw_handler) NULL, /* SIOCGIWSTATS */
7263 iw_handler_set_spy, /* SIOCSIWSPY */
7264 iw_handler_get_spy, /* SIOCGIWSPY */
7265 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
7266 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
7267 (iw_handler) airo_set_wap, /* SIOCSIWAP */
7268 (iw_handler) airo_get_wap, /* SIOCGIWAP */
7269 (iw_handler) NULL, /* -- hole -- */
7270 (iw_handler) airo_get_aplist, /* SIOCGIWAPLIST */
7271 (iw_handler) airo_set_scan, /* SIOCSIWSCAN */
7272 (iw_handler) airo_get_scan, /* SIOCGIWSCAN */
7273 (iw_handler) airo_set_essid, /* SIOCSIWESSID */
7274 (iw_handler) airo_get_essid, /* SIOCGIWESSID */
7275 (iw_handler) airo_set_nick, /* SIOCSIWNICKN */
7276 (iw_handler) airo_get_nick, /* SIOCGIWNICKN */
7277 (iw_handler) NULL, /* -- hole -- */
7278 (iw_handler) NULL, /* -- hole -- */
7279 (iw_handler) airo_set_rate, /* SIOCSIWRATE */
7280 (iw_handler) airo_get_rate, /* SIOCGIWRATE */
7281 (iw_handler) airo_set_rts, /* SIOCSIWRTS */
7282 (iw_handler) airo_get_rts, /* SIOCGIWRTS */
7283 (iw_handler) airo_set_frag, /* SIOCSIWFRAG */
7284 (iw_handler) airo_get_frag, /* SIOCGIWFRAG */
7285 (iw_handler) airo_set_txpow, /* SIOCSIWTXPOW */
7286 (iw_handler) airo_get_txpow, /* SIOCGIWTXPOW */
7287 (iw_handler) airo_set_retry, /* SIOCSIWRETRY */
7288 (iw_handler) airo_get_retry, /* SIOCGIWRETRY */
7289 (iw_handler) airo_set_encode, /* SIOCSIWENCODE */
7290 (iw_handler) airo_get_encode, /* SIOCGIWENCODE */
7291 (iw_handler) airo_set_power, /* SIOCSIWPOWER */
7292 (iw_handler) airo_get_power, /* SIOCGIWPOWER */
Dan Williams4be757d2006-01-30 11:58:00 -05007293 (iw_handler) NULL, /* -- hole -- */
7294 (iw_handler) NULL, /* -- hole -- */
7295 (iw_handler) NULL, /* SIOCSIWGENIE */
7296 (iw_handler) NULL, /* SIOCGIWGENIE */
7297 (iw_handler) airo_set_auth, /* SIOCSIWAUTH */
7298 (iw_handler) airo_get_auth, /* SIOCGIWAUTH */
7299 (iw_handler) airo_set_encodeext, /* SIOCSIWENCODEEXT */
7300 (iw_handler) airo_get_encodeext, /* SIOCGIWENCODEEXT */
7301 (iw_handler) NULL, /* SIOCSIWPMKSA */
Linus Torvalds1da177e2005-04-16 15:20:36 -07007302};
7303
7304/* Note : don't describe AIROIDIFC and AIROOLDIDIFC in here.
7305 * We want to force the use of the ioctl code, because those can't be
7306 * won't work the iw_handler code (because they simultaneously read
7307 * and write data and iw_handler can't do that).
7308 * Note that it's perfectly legal to read/write on a single ioctl command,
7309 * you just can't use iwpriv and need to force it via the ioctl handler.
7310 * Jean II */
7311static const iw_handler airo_private_handler[] =
7312{
7313 NULL, /* SIOCIWFIRSTPRIV */
7314};
7315
7316static const struct iw_handler_def airo_handler_def =
7317{
7318 .num_standard = sizeof(airo_handler)/sizeof(iw_handler),
7319 .num_private = sizeof(airo_private_handler)/sizeof(iw_handler),
7320 .num_private_args = sizeof(airo_private_args)/sizeof(struct iw_priv_args),
7321 .standard = airo_handler,
7322 .private = airo_private_handler,
7323 .private_args = airo_private_args,
7324 .get_wireless_stats = airo_get_wireless_stats,
7325};
7326
Linus Torvalds1da177e2005-04-16 15:20:36 -07007327/*
7328 * This defines the configuration part of the Wireless Extensions
7329 * Note : irq and spinlock protection will occur in the subroutines
7330 *
7331 * TODO :
7332 * o Check input value more carefully and fill correct values in range
7333 * o Test and shakeout the bugs (if any)
7334 *
7335 * Jean II
7336 *
7337 * Javier Achirica did a great job of merging code from the unnamed CISCO
7338 * developer that added support for flashing the card.
7339 */
7340static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
7341{
7342 int rc = 0;
7343 struct airo_info *ai = (struct airo_info *)dev->priv;
7344
Pavel Machekca078ba2005-09-03 15:56:57 -07007345 if (ai->power.event)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007346 return 0;
7347
7348 switch (cmd) {
7349#ifdef CISCO_EXT
7350 case AIROIDIFC:
7351#ifdef AIROOLDIDIFC
7352 case AIROOLDIDIFC:
7353#endif
7354 {
7355 int val = AIROMAGIC;
7356 aironet_ioctl com;
7357 if (copy_from_user(&com,rq->ifr_data,sizeof(com)))
7358 rc = -EFAULT;
7359 else if (copy_to_user(com.data,(char *)&val,sizeof(val)))
7360 rc = -EFAULT;
7361 }
7362 break;
7363
7364 case AIROIOCTL:
7365#ifdef AIROOLDIOCTL
7366 case AIROOLDIOCTL:
7367#endif
7368 /* Get the command struct and hand it off for evaluation by
7369 * the proper subfunction
7370 */
7371 {
7372 aironet_ioctl com;
7373 if (copy_from_user(&com,rq->ifr_data,sizeof(com))) {
7374 rc = -EFAULT;
7375 break;
7376 }
7377
7378 /* Separate R/W functions bracket legality here
7379 */
7380 if ( com.command == AIRORSWVERSION ) {
7381 if (copy_to_user(com.data, swversion, sizeof(swversion)))
7382 rc = -EFAULT;
7383 else
7384 rc = 0;
7385 }
7386 else if ( com.command <= AIRORRID)
7387 rc = readrids(dev,&com);
7388 else if ( com.command >= AIROPCAP && com.command <= (AIROPLEAPUSR+2) )
7389 rc = writerids(dev,&com);
7390 else if ( com.command >= AIROFLSHRST && com.command <= AIRORESTART )
7391 rc = flashcard(dev,&com);
7392 else
7393 rc = -EINVAL; /* Bad command in ioctl */
7394 }
7395 break;
7396#endif /* CISCO_EXT */
7397
7398 // All other calls are currently unsupported
7399 default:
7400 rc = -EOPNOTSUPP;
7401 }
7402 return rc;
7403}
7404
Linus Torvalds1da177e2005-04-16 15:20:36 -07007405/*
7406 * Get the Wireless stats out of the driver
7407 * Note : irq and spinlock protection will occur in the subroutines
7408 *
7409 * TODO :
7410 * o Check if work in Ad-Hoc mode (otherwise, use SPY, as in wvlan_cs)
7411 *
7412 * Jean
7413 */
7414static void airo_read_wireless_stats(struct airo_info *local)
7415{
7416 StatusRid status_rid;
7417 StatsRid stats_rid;
7418 CapabilityRid cap_rid;
7419 u32 *vals = stats_rid.vals;
7420
7421 /* Get stats out of the card */
7422 clear_bit(JOB_WSTATS, &local->flags);
Pavel Machekca078ba2005-09-03 15:56:57 -07007423 if (local->power.event) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007424 up(&local->sem);
7425 return;
7426 }
7427 readCapabilityRid(local, &cap_rid, 0);
7428 readStatusRid(local, &status_rid, 0);
7429 readStatsRid(local, &stats_rid, RID_STATS, 0);
7430 up(&local->sem);
7431
7432 /* The status */
7433 local->wstats.status = status_rid.mode;
7434
Dan Williams41480af2005-05-10 09:45:51 -04007435 /* Signal quality and co */
7436 if (local->rssi) {
7437 local->wstats.qual.level = airo_rssi_to_dbm( local->rssi, status_rid.sigQuality );
7438 /* normalizedSignalStrength appears to be a percentage */
7439 local->wstats.qual.qual = status_rid.normalizedSignalStrength;
7440 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007441 local->wstats.qual.level = (status_rid.normalizedSignalStrength + 321) / 2;
Dan Williams41480af2005-05-10 09:45:51 -04007442 local->wstats.qual.qual = airo_get_quality(&status_rid, &cap_rid);
7443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07007444 if (status_rid.len >= 124) {
Dan Williams41480af2005-05-10 09:45:51 -04007445 local->wstats.qual.noise = 0x100 - status_rid.noisedBm;
Jean Tourrilhesce6623c2005-09-02 11:45:10 -07007446 local->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007447 } else {
7448 local->wstats.qual.noise = 0;
Jean Tourrilhesce6623c2005-09-02 11:45:10 -07007449 local->wstats.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_INVALID | IW_QUAL_DBM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007450 }
7451
7452 /* Packets discarded in the wireless adapter due to wireless
7453 * specific problems */
7454 local->wstats.discard.nwid = vals[56] + vals[57] + vals[58];/* SSID Mismatch */
7455 local->wstats.discard.code = vals[6];/* RxWepErr */
7456 local->wstats.discard.fragment = vals[30];
7457 local->wstats.discard.retries = vals[10];
7458 local->wstats.discard.misc = vals[1] + vals[32];
7459 local->wstats.miss.beacon = vals[34];
7460}
7461
Jouni Malinenff1d2762005-05-12 22:54:16 -04007462static struct iw_statistics *airo_get_wireless_stats(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07007463{
7464 struct airo_info *local = dev->priv;
7465
7466 if (!test_bit(JOB_WSTATS, &local->flags)) {
7467 /* Get stats out of the card if available */
7468 if (down_trylock(&local->sem) != 0) {
7469 set_bit(JOB_WSTATS, &local->flags);
7470 wake_up_interruptible(&local->thr_wait);
7471 } else
7472 airo_read_wireless_stats(local);
7473 }
7474
7475 return &local->wstats;
7476}
Linus Torvalds1da177e2005-04-16 15:20:36 -07007477
7478#ifdef CISCO_EXT
7479/*
7480 * This just translates from driver IOCTL codes to the command codes to
7481 * feed to the radio's host interface. Things can be added/deleted
7482 * as needed. This represents the READ side of control I/O to
7483 * the card
7484 */
7485static int readrids(struct net_device *dev, aironet_ioctl *comp) {
7486 unsigned short ridcode;
7487 unsigned char *iobuf;
7488 int len;
7489 struct airo_info *ai = dev->priv;
7490 Resp rsp;
7491
7492 if (test_bit(FLAG_FLASHING, &ai->flags))
7493 return -EIO;
7494
7495 switch(comp->command)
7496 {
7497 case AIROGCAP: ridcode = RID_CAPABILITIES; break;
7498 case AIROGCFG: ridcode = RID_CONFIG;
7499 if (test_bit(FLAG_COMMIT, &ai->flags)) {
7500 disable_MAC (ai, 1);
7501 writeConfigRid (ai, 1);
7502 enable_MAC (ai, &rsp, 1);
7503 }
7504 break;
7505 case AIROGSLIST: ridcode = RID_SSID; break;
7506 case AIROGVLIST: ridcode = RID_APLIST; break;
7507 case AIROGDRVNAM: ridcode = RID_DRVNAME; break;
7508 case AIROGEHTENC: ridcode = RID_ETHERENCAP; break;
7509 case AIROGWEPKTMP: ridcode = RID_WEP_TEMP;
7510 /* Only super-user can read WEP keys */
7511 if (!capable(CAP_NET_ADMIN))
7512 return -EPERM;
7513 break;
7514 case AIROGWEPKNV: ridcode = RID_WEP_PERM;
7515 /* Only super-user can read WEP keys */
7516 if (!capable(CAP_NET_ADMIN))
7517 return -EPERM;
7518 break;
7519 case AIROGSTAT: ridcode = RID_STATUS; break;
7520 case AIROGSTATSD32: ridcode = RID_STATSDELTA; break;
7521 case AIROGSTATSC32: ridcode = RID_STATS; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007522 case AIROGMICSTATS:
7523 if (copy_to_user(comp->data, &ai->micstats,
7524 min((int)comp->len,(int)sizeof(ai->micstats))))
7525 return -EFAULT;
7526 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007527 case AIRORRID: ridcode = comp->ridnum; break;
7528 default:
7529 return -EINVAL;
7530 break;
7531 }
7532
7533 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7534 return -ENOMEM;
7535
7536 PC4500_readrid(ai,ridcode,iobuf,RIDSIZE, 1);
7537 /* get the count of bytes in the rid docs say 1st 2 bytes is it.
7538 * then return it to the user
7539 * 9/22/2000 Honor user given length
7540 */
7541 len = comp->len;
7542
7543 if (copy_to_user(comp->data, iobuf, min(len, (int)RIDSIZE))) {
7544 kfree (iobuf);
7545 return -EFAULT;
7546 }
7547 kfree (iobuf);
7548 return 0;
7549}
7550
7551/*
7552 * Danger Will Robinson write the rids here
7553 */
7554
7555static int writerids(struct net_device *dev, aironet_ioctl *comp) {
7556 struct airo_info *ai = dev->priv;
7557 int ridcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007558 int enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007559 Resp rsp;
7560 static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
7561 unsigned char *iobuf;
7562
7563 /* Only super-user can write RIDs */
7564 if (!capable(CAP_NET_ADMIN))
7565 return -EPERM;
7566
7567 if (test_bit(FLAG_FLASHING, &ai->flags))
7568 return -EIO;
7569
7570 ridcode = 0;
7571 writer = do_writerid;
7572
7573 switch(comp->command)
7574 {
7575 case AIROPSIDS: ridcode = RID_SSID; break;
7576 case AIROPCAP: ridcode = RID_CAPABILITIES; break;
7577 case AIROPAPLIST: ridcode = RID_APLIST; break;
7578 case AIROPCFG: ai->config.len = 0;
7579 clear_bit(FLAG_COMMIT, &ai->flags);
7580 ridcode = RID_CONFIG; break;
7581 case AIROPWEPKEYNV: ridcode = RID_WEP_PERM; break;
7582 case AIROPLEAPUSR: ridcode = RID_LEAPUSERNAME; break;
7583 case AIROPLEAPPWD: ridcode = RID_LEAPPASSWORD; break;
7584 case AIROPWEPKEY: ridcode = RID_WEP_TEMP; writer = PC4500_writerid;
7585 break;
7586 case AIROPLEAPUSR+1: ridcode = 0xFF2A; break;
7587 case AIROPLEAPUSR+2: ridcode = 0xFF2B; break;
7588
7589 /* this is not really a rid but a command given to the card
7590 * same with MAC off
7591 */
7592 case AIROPMACON:
7593 if (enable_MAC(ai, &rsp, 1) != 0)
7594 return -EIO;
7595 return 0;
7596
7597 /*
7598 * Evidently this code in the airo driver does not get a symbol
7599 * as disable_MAC. it's probably so short the compiler does not gen one.
7600 */
7601 case AIROPMACOFF:
7602 disable_MAC(ai, 1);
7603 return 0;
7604
7605 /* This command merely clears the counts does not actually store any data
7606 * only reads rid. But as it changes the cards state, I put it in the
7607 * writerid routines.
7608 */
7609 case AIROPSTCLR:
7610 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7611 return -ENOMEM;
7612
7613 PC4500_readrid(ai,RID_STATSDELTACLEAR,iobuf,RIDSIZE, 1);
7614
Linus Torvalds1da177e2005-04-16 15:20:36 -07007615 enabled = ai->micstats.enabled;
7616 memset(&ai->micstats,0,sizeof(ai->micstats));
7617 ai->micstats.enabled = enabled;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007618
7619 if (copy_to_user(comp->data, iobuf,
7620 min((int)comp->len, (int)RIDSIZE))) {
7621 kfree (iobuf);
7622 return -EFAULT;
7623 }
7624 kfree (iobuf);
7625 return 0;
7626
7627 default:
7628 return -EOPNOTSUPP; /* Blarg! */
7629 }
7630 if(comp->len > RIDSIZE)
7631 return -EINVAL;
7632
7633 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7634 return -ENOMEM;
7635
7636 if (copy_from_user(iobuf,comp->data,comp->len)) {
7637 kfree (iobuf);
7638 return -EFAULT;
7639 }
7640
7641 if (comp->command == AIROPCFG) {
7642 ConfigRid *cfg = (ConfigRid *)iobuf;
7643
7644 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags))
7645 cfg->opmode |= MODE_MIC;
7646
7647 if ((cfg->opmode & 0xFF) == MODE_STA_IBSS)
7648 set_bit (FLAG_ADHOC, &ai->flags);
7649 else
7650 clear_bit (FLAG_ADHOC, &ai->flags);
7651 }
7652
7653 if((*writer)(ai, ridcode, iobuf,comp->len,1)) {
7654 kfree (iobuf);
7655 return -EIO;
7656 }
7657 kfree (iobuf);
7658 return 0;
7659}
7660
7661/*****************************************************************************
7662 * Ancillary flash / mod functions much black magic lurkes here *
7663 *****************************************************************************
7664 */
7665
7666/*
7667 * Flash command switch table
7668 */
7669
Jouni Malinenff1d2762005-05-12 22:54:16 -04007670static int flashcard(struct net_device *dev, aironet_ioctl *comp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007671 int z;
Linus Torvalds1da177e2005-04-16 15:20:36 -07007672
7673 /* Only super-user can modify flash */
7674 if (!capable(CAP_NET_ADMIN))
7675 return -EPERM;
7676
7677 switch(comp->command)
7678 {
7679 case AIROFLSHRST:
7680 return cmdreset((struct airo_info *)dev->priv);
7681
7682 case AIROFLSHSTFL:
7683 if (!((struct airo_info *)dev->priv)->flash &&
7684 (((struct airo_info *)dev->priv)->flash = kmalloc (FLASHSIZE, GFP_KERNEL)) == NULL)
7685 return -ENOMEM;
7686 return setflashmode((struct airo_info *)dev->priv);
7687
7688 case AIROFLSHGCHR: /* Get char from aux */
7689 if(comp->len != sizeof(int))
7690 return -EINVAL;
7691 if (copy_from_user(&z,comp->data,comp->len))
7692 return -EFAULT;
7693 return flashgchar((struct airo_info *)dev->priv,z,8000);
7694
7695 case AIROFLSHPCHR: /* Send char to card. */
7696 if(comp->len != sizeof(int))
7697 return -EINVAL;
7698 if (copy_from_user(&z,comp->data,comp->len))
7699 return -EFAULT;
7700 return flashpchar((struct airo_info *)dev->priv,z,8000);
7701
7702 case AIROFLPUTBUF: /* Send 32k to card */
7703 if (!((struct airo_info *)dev->priv)->flash)
7704 return -ENOMEM;
7705 if(comp->len > FLASHSIZE)
7706 return -EINVAL;
7707 if(copy_from_user(((struct airo_info *)dev->priv)->flash,comp->data,comp->len))
7708 return -EFAULT;
7709
7710 flashputbuf((struct airo_info *)dev->priv);
7711 return 0;
7712
7713 case AIRORESTART:
7714 if(flashrestart((struct airo_info *)dev->priv,dev))
7715 return -EIO;
7716 return 0;
7717 }
7718 return -EINVAL;
7719}
7720
7721#define FLASH_COMMAND 0x7e7e
7722
7723/*
7724 * STEP 1)
7725 * Disable MAC and do soft reset on
7726 * card.
7727 */
7728
Jouni Malinenff1d2762005-05-12 22:54:16 -04007729static int cmdreset(struct airo_info *ai) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007730 disable_MAC(ai, 1);
7731
7732 if(!waitbusy (ai)){
Dan Williams934d8bf2006-03-16 13:46:23 -05007733 airo_print_info(ai->dev->name, "Waitbusy hang before RESET");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007734 return -EBUSY;
7735 }
7736
7737 OUT4500(ai,COMMAND,CMD_SOFTRESET);
7738
7739 ssleep(1); /* WAS 600 12/7/00 */
7740
7741 if(!waitbusy (ai)){
Dan Williams934d8bf2006-03-16 13:46:23 -05007742 airo_print_info(ai->dev->name, "Waitbusy hang AFTER RESET");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007743 return -EBUSY;
7744 }
7745 return 0;
7746}
7747
7748/* STEP 2)
7749 * Put the card in legendary flash
7750 * mode
7751 */
7752
Jouni Malinenff1d2762005-05-12 22:54:16 -04007753static int setflashmode (struct airo_info *ai) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007754 set_bit (FLAG_FLASHING, &ai->flags);
7755
7756 OUT4500(ai, SWS0, FLASH_COMMAND);
7757 OUT4500(ai, SWS1, FLASH_COMMAND);
7758 if (probe) {
7759 OUT4500(ai, SWS0, FLASH_COMMAND);
7760 OUT4500(ai, COMMAND,0x10);
7761 } else {
7762 OUT4500(ai, SWS2, FLASH_COMMAND);
7763 OUT4500(ai, SWS3, FLASH_COMMAND);
7764 OUT4500(ai, COMMAND,0);
7765 }
7766 msleep(500); /* 500ms delay */
7767
7768 if(!waitbusy(ai)) {
7769 clear_bit (FLAG_FLASHING, &ai->flags);
Dan Williams934d8bf2006-03-16 13:46:23 -05007770 airo_print_info(ai->dev->name, "Waitbusy hang after setflash mode");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007771 return -EIO;
7772 }
7773 return 0;
7774}
7775
7776/* Put character to SWS0 wait for dwelltime
7777 * x 50us for echo .
7778 */
7779
Jouni Malinenff1d2762005-05-12 22:54:16 -04007780static int flashpchar(struct airo_info *ai,int byte,int dwelltime) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07007781 int echo;
7782 int waittime;
7783
7784 byte |= 0x8000;
7785
7786 if(dwelltime == 0 )
7787 dwelltime = 200;
7788
7789 waittime=dwelltime;
7790
7791 /* Wait for busy bit d15 to go false indicating buffer empty */
7792 while ((IN4500 (ai, SWS0) & 0x8000) && waittime > 0) {
7793 udelay (50);
7794 waittime -= 50;
7795 }
7796
7797 /* timeout for busy clear wait */
7798 if(waittime <= 0 ){
Dan Williams934d8bf2006-03-16 13:46:23 -05007799 airo_print_info(ai->dev->name, "flash putchar busywait timeout!");
Linus Torvalds1da177e2005-04-16 15:20:36 -07007800 return -EBUSY;
7801 }
7802
7803 /* Port is clear now write byte and wait for it to echo back */
7804 do {
7805 OUT4500(ai,SWS0,byte);
7806 udelay(50);
7807 dwelltime -= 50;
7808 echo = IN4500(ai,SWS1);
7809 } while (dwelltime >= 0 && echo != byte);
7810
7811 OUT4500(ai,SWS1,0);
7812
7813 return (echo == byte) ? 0 : -EIO;
7814}
7815
7816/*
7817 * Get a character from the card matching matchbyte
7818 * Step 3)
7819 */
Jouni Malinenff1d2762005-05-12 22:54:16 -04007820static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime){
Linus Torvalds1da177e2005-04-16 15:20:36 -07007821 int rchar;
7822 unsigned char rbyte=0;
7823
7824 do {
7825 rchar = IN4500(ai,SWS1);
7826
7827 if(dwelltime && !(0x8000 & rchar)){
7828 dwelltime -= 10;
7829 mdelay(10);
7830 continue;
7831 }
7832 rbyte = 0xff & rchar;
7833
7834 if( (rbyte == matchbyte) && (0x8000 & rchar) ){
7835 OUT4500(ai,SWS1,0);
7836 return 0;
7837 }
7838 if( rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
7839 break;
7840 OUT4500(ai,SWS1,0);
7841
7842 }while(dwelltime > 0);
7843 return -EIO;
7844}
7845
7846/*
7847 * Transfer 32k of firmware data from user buffer to our buffer and
7848 * send to the card
7849 */
7850
Jouni Malinenff1d2762005-05-12 22:54:16 -04007851static int flashputbuf(struct airo_info *ai){
Linus Torvalds1da177e2005-04-16 15:20:36 -07007852 int nwords;
7853
7854 /* Write stuff */
7855 if (test_bit(FLAG_MPI,&ai->flags))
7856 memcpy_toio(ai->pciaux + 0x8000, ai->flash, FLASHSIZE);
7857 else {
7858 OUT4500(ai,AUXPAGE,0x100);
7859 OUT4500(ai,AUXOFF,0);
7860
7861 for(nwords=0;nwords != FLASHSIZE / 2;nwords++){
7862 OUT4500(ai,AUXDATA,ai->flash[nwords] & 0xffff);
7863 }
7864 }
7865 OUT4500(ai,SWS0,0x8000);
7866
7867 return 0;
7868}
7869
7870/*
7871 *
7872 */
Jouni Malinenff1d2762005-05-12 22:54:16 -04007873static int flashrestart(struct airo_info *ai,struct net_device *dev){
Linus Torvalds1da177e2005-04-16 15:20:36 -07007874 int i,status;
7875
7876 ssleep(1); /* Added 12/7/00 */
7877 clear_bit (FLAG_FLASHING, &ai->flags);
7878 if (test_bit(FLAG_MPI, &ai->flags)) {
7879 status = mpi_init_descriptors(ai);
7880 if (status != SUCCESS)
7881 return status;
7882 }
7883 status = setup_card(ai, dev->dev_addr, 1);
7884
7885 if (!test_bit(FLAG_MPI,&ai->flags))
7886 for( i = 0; i < MAX_FIDS; i++ ) {
7887 ai->fids[i] = transmit_allocate
7888 ( ai, 2312, i >= MAX_FIDS / 2 );
7889 }
7890
7891 ssleep(1); /* Added 12/7/00 */
7892 return status;
7893}
7894#endif /* CISCO_EXT */
7895
7896/*
7897 This program is free software; you can redistribute it and/or
7898 modify it under the terms of the GNU General Public License
7899 as published by the Free Software Foundation; either version 2
7900 of the License, or (at your option) any later version.
7901
7902 This program is distributed in the hope that it will be useful,
7903 but WITHOUT ANY WARRANTY; without even the implied warranty of
7904 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7905 GNU General Public License for more details.
7906
7907 In addition:
7908
7909 Redistribution and use in source and binary forms, with or without
7910 modification, are permitted provided that the following conditions
7911 are met:
7912
7913 1. Redistributions of source code must retain the above copyright
7914 notice, this list of conditions and the following disclaimer.
7915 2. Redistributions in binary form must reproduce the above copyright
7916 notice, this list of conditions and the following disclaimer in the
7917 documentation and/or other materials provided with the distribution.
7918 3. The name of the author may not be used to endorse or promote
7919 products derived from this software without specific prior written
7920 permission.
7921
7922 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
7923 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
7924 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
7925 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
7926 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
7927 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
7928 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
7929 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
7930 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
7931 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
7932 POSSIBILITY OF SUCH DAMAGE.
7933*/
7934
7935module_init(airo_init_module);
7936module_exit(airo_cleanup_module);