iwl3945: use iwl3945_tx_cmd instead of iwl_tx_cmd
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / net / wireless / airo.c
blob2ff588bb0a7c837fcdbb678962688af27ff2b0b3
1 /*======================================================================
3 Aironet driver for 4500 and 4800 series cards
5 This code is released under both the GPL version 2 and BSD licenses.
6 Either license may be used. The respective licenses are found at
7 the end of this file.
9 This code was developed by Benjamin Reed <breed@users.sourceforge.net>
10 including portions of which come from the Aironet PC4500
11 Developer's Reference Manual and used with permission. Copyright
12 (C) 1999 Benjamin Reed. All Rights Reserved. Permission to use
13 code in the Developer's manual was granted for this driver by
14 Aironet. Major code contributions were received from Javier Achirica
15 <achirica@users.sourceforge.net> and Jean Tourrilhes <jt@hpl.hp.com>.
16 Code was also integrated from the Cisco Aironet driver for Linux.
17 Support for MPI350 cards was added by Fabrice Bellet
18 <fabrice@bellet.info>.
20 ======================================================================*/
22 #include <linux/err.h>
23 #include <linux/init.h>
25 #include <linux/kernel.h>
26 #include <linux/module.h>
27 #include <linux/proc_fs.h>
29 #include <linux/sched.h>
30 #include <linux/ptrace.h>
31 #include <linux/slab.h>
32 #include <linux/string.h>
33 #include <linux/timer.h>
34 #include <linux/interrupt.h>
35 #include <linux/in.h>
36 #include <linux/bitops.h>
37 #include <linux/scatterlist.h>
38 #include <linux/crypto.h>
39 #include <asm/io.h>
40 #include <asm/system.h>
41 #include <asm/unaligned.h>
43 #include <linux/netdevice.h>
44 #include <linux/etherdevice.h>
45 #include <linux/skbuff.h>
46 #include <linux/if_arp.h>
47 #include <linux/ioport.h>
48 #include <linux/pci.h>
49 #include <asm/uaccess.h>
50 #include <linux/kthread.h>
51 #include <linux/freezer.h>
53 #include <linux/ieee80211.h>
55 #include "airo.h"
57 #define DRV_NAME "airo"
59 #ifdef CONFIG_PCI
60 static struct pci_device_id card_ids[] = {
61 { 0x14b9, 1, PCI_ANY_ID, PCI_ANY_ID, },
62 { 0x14b9, 0x4500, PCI_ANY_ID, PCI_ANY_ID },
63 { 0x14b9, 0x4800, PCI_ANY_ID, PCI_ANY_ID, },
64 { 0x14b9, 0x0340, PCI_ANY_ID, PCI_ANY_ID, },
65 { 0x14b9, 0x0350, PCI_ANY_ID, PCI_ANY_ID, },
66 { 0x14b9, 0x5000, PCI_ANY_ID, PCI_ANY_ID, },
67 { 0x14b9, 0xa504, PCI_ANY_ID, PCI_ANY_ID, },
68 { 0, }
70 MODULE_DEVICE_TABLE(pci, card_ids);
72 static int airo_pci_probe(struct pci_dev *, const struct pci_device_id *);
73 static void airo_pci_remove(struct pci_dev *);
74 static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state);
75 static int airo_pci_resume(struct pci_dev *pdev);
77 static struct pci_driver airo_driver = {
78 .name = DRV_NAME,
79 .id_table = card_ids,
80 .probe = airo_pci_probe,
81 .remove = __devexit_p(airo_pci_remove),
82 .suspend = airo_pci_suspend,
83 .resume = airo_pci_resume,
85 #endif /* CONFIG_PCI */
87 /* Include Wireless Extension definition and check version - Jean II */
88 #include <linux/wireless.h>
89 #define WIRELESS_SPY /* enable iwspy support */
90 #include <net/iw_handler.h> /* New driver API */
92 #define CISCO_EXT /* enable Cisco extensions */
93 #ifdef CISCO_EXT
94 #include <linux/delay.h>
95 #endif
97 /* Hack to do some power saving */
98 #define POWER_ON_DOWN
100 /* As you can see this list is HUGH!
101 I really don't know what a lot of these counts are about, but they
102 are all here for completeness. If the IGNLABEL macro is put in
103 infront of the label, that statistic will not be included in the list
104 of statistics in the /proc filesystem */
106 #define IGNLABEL(comment) NULL
107 static char *statsLabels[] = {
108 "RxOverrun",
109 IGNLABEL("RxPlcpCrcErr"),
110 IGNLABEL("RxPlcpFormatErr"),
111 IGNLABEL("RxPlcpLengthErr"),
112 "RxMacCrcErr",
113 "RxMacCrcOk",
114 "RxWepErr",
115 "RxWepOk",
116 "RetryLong",
117 "RetryShort",
118 "MaxRetries",
119 "NoAck",
120 "NoCts",
121 "RxAck",
122 "RxCts",
123 "TxAck",
124 "TxRts",
125 "TxCts",
126 "TxMc",
127 "TxBc",
128 "TxUcFrags",
129 "TxUcPackets",
130 "TxBeacon",
131 "RxBeacon",
132 "TxSinColl",
133 "TxMulColl",
134 "DefersNo",
135 "DefersProt",
136 "DefersEngy",
137 "DupFram",
138 "RxFragDisc",
139 "TxAged",
140 "RxAged",
141 "LostSync-MaxRetry",
142 "LostSync-MissedBeacons",
143 "LostSync-ArlExceeded",
144 "LostSync-Deauth",
145 "LostSync-Disassoced",
146 "LostSync-TsfTiming",
147 "HostTxMc",
148 "HostTxBc",
149 "HostTxUc",
150 "HostTxFail",
151 "HostRxMc",
152 "HostRxBc",
153 "HostRxUc",
154 "HostRxDiscard",
155 IGNLABEL("HmacTxMc"),
156 IGNLABEL("HmacTxBc"),
157 IGNLABEL("HmacTxUc"),
158 IGNLABEL("HmacTxFail"),
159 IGNLABEL("HmacRxMc"),
160 IGNLABEL("HmacRxBc"),
161 IGNLABEL("HmacRxUc"),
162 IGNLABEL("HmacRxDiscard"),
163 IGNLABEL("HmacRxAccepted"),
164 "SsidMismatch",
165 "ApMismatch",
166 "RatesMismatch",
167 "AuthReject",
168 "AuthTimeout",
169 "AssocReject",
170 "AssocTimeout",
171 IGNLABEL("ReasonOutsideTable"),
172 IGNLABEL("ReasonStatus1"),
173 IGNLABEL("ReasonStatus2"),
174 IGNLABEL("ReasonStatus3"),
175 IGNLABEL("ReasonStatus4"),
176 IGNLABEL("ReasonStatus5"),
177 IGNLABEL("ReasonStatus6"),
178 IGNLABEL("ReasonStatus7"),
179 IGNLABEL("ReasonStatus8"),
180 IGNLABEL("ReasonStatus9"),
181 IGNLABEL("ReasonStatus10"),
182 IGNLABEL("ReasonStatus11"),
183 IGNLABEL("ReasonStatus12"),
184 IGNLABEL("ReasonStatus13"),
185 IGNLABEL("ReasonStatus14"),
186 IGNLABEL("ReasonStatus15"),
187 IGNLABEL("ReasonStatus16"),
188 IGNLABEL("ReasonStatus17"),
189 IGNLABEL("ReasonStatus18"),
190 IGNLABEL("ReasonStatus19"),
191 "RxMan",
192 "TxMan",
193 "RxRefresh",
194 "TxRefresh",
195 "RxPoll",
196 "TxPoll",
197 "HostRetries",
198 "LostSync-HostReq",
199 "HostTxBytes",
200 "HostRxBytes",
201 "ElapsedUsec",
202 "ElapsedSec",
203 "LostSyncBetterAP",
204 "PrivacyMismatch",
205 "Jammed",
206 "DiscRxNotWepped",
207 "PhyEleMismatch",
208 (char*)-1 };
209 #ifndef RUN_AT
210 #define RUN_AT(x) (jiffies+(x))
211 #endif
214 /* These variables are for insmod, since it seems that the rates
215 can only be set in setup_card. Rates should be a comma separated
216 (no spaces) list of rates (up to 8). */
218 static int rates[8];
219 static int basic_rate;
220 static char *ssids[3];
222 static int io[4];
223 static int irq[4];
225 static
226 int maxencrypt /* = 0 */; /* The highest rate that the card can encrypt at.
227 0 means no limit. For old cards this was 4 */
229 static int auto_wep /* = 0 */; /* If set, it tries to figure out the wep mode */
230 static int aux_bap /* = 0 */; /* Checks to see if the aux ports are needed to read
231 the bap, needed on some older cards and buses. */
232 static int adhoc;
234 static int probe = 1;
236 static int proc_uid /* = 0 */;
238 static int proc_gid /* = 0 */;
240 static int airo_perm = 0555;
242 static int proc_perm = 0644;
244 MODULE_AUTHOR("Benjamin Reed");
245 MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet \
246 cards. Direct support for ISA/PCI/MPI cards and support \
247 for PCMCIA when used with airo_cs.");
248 MODULE_LICENSE("Dual BSD/GPL");
249 MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340/350");
250 module_param_array(io, int, NULL, 0);
251 module_param_array(irq, int, NULL, 0);
252 module_param(basic_rate, int, 0);
253 module_param_array(rates, int, NULL, 0);
254 module_param_array(ssids, charp, NULL, 0);
255 module_param(auto_wep, int, 0);
256 MODULE_PARM_DESC(auto_wep, "If non-zero, the driver will keep looping through \
257 the authentication options until an association is made. The value of \
258 auto_wep is number of the wep keys to check. A value of 2 will try using \
259 the key at index 0 and index 1.");
260 module_param(aux_bap, int, 0);
261 MODULE_PARM_DESC(aux_bap, "If non-zero, the driver will switch into a mode \
262 than seems to work better for older cards with some older buses. Before \
263 switching it checks that the switch is needed.");
264 module_param(maxencrypt, int, 0);
265 MODULE_PARM_DESC(maxencrypt, "The maximum speed that the card can do \
266 encryption. Units are in 512kbs. Zero (default) means there is no limit. \
267 Older cards used to be limited to 2mbs (4).");
268 module_param(adhoc, int, 0);
269 MODULE_PARM_DESC(adhoc, "If non-zero, the card will start in adhoc mode.");
270 module_param(probe, int, 0);
271 MODULE_PARM_DESC(probe, "If zero, the driver won't start the card.");
273 module_param(proc_uid, int, 0);
274 MODULE_PARM_DESC(proc_uid, "The uid that the /proc files will belong to.");
275 module_param(proc_gid, int, 0);
276 MODULE_PARM_DESC(proc_gid, "The gid that the /proc files will belong to.");
277 module_param(airo_perm, int, 0);
278 MODULE_PARM_DESC(airo_perm, "The permission bits of /proc/[driver/]aironet.");
279 module_param(proc_perm, int, 0);
280 MODULE_PARM_DESC(proc_perm, "The permission bits of the files in /proc");
282 /* This is a kind of sloppy hack to get this information to OUT4500 and
283 IN4500. I would be extremely interested in the situation where this
284 doesn't work though!!! */
285 static int do8bitIO /* = 0 */;
287 /* Return codes */
288 #define SUCCESS 0
289 #define ERROR -1
290 #define NO_PACKET -2
292 /* Commands */
293 #define NOP2 0x0000
294 #define MAC_ENABLE 0x0001
295 #define MAC_DISABLE 0x0002
296 #define CMD_LOSE_SYNC 0x0003 /* Not sure what this does... */
297 #define CMD_SOFTRESET 0x0004
298 #define HOSTSLEEP 0x0005
299 #define CMD_MAGIC_PKT 0x0006
300 #define CMD_SETWAKEMASK 0x0007
301 #define CMD_READCFG 0x0008
302 #define CMD_SETMODE 0x0009
303 #define CMD_ALLOCATETX 0x000a
304 #define CMD_TRANSMIT 0x000b
305 #define CMD_DEALLOCATETX 0x000c
306 #define NOP 0x0010
307 #define CMD_WORKAROUND 0x0011
308 #define CMD_ALLOCATEAUX 0x0020
309 #define CMD_ACCESS 0x0021
310 #define CMD_PCIBAP 0x0022
311 #define CMD_PCIAUX 0x0023
312 #define CMD_ALLOCBUF 0x0028
313 #define CMD_GETTLV 0x0029
314 #define CMD_PUTTLV 0x002a
315 #define CMD_DELTLV 0x002b
316 #define CMD_FINDNEXTTLV 0x002c
317 #define CMD_PSPNODES 0x0030
318 #define CMD_SETCW 0x0031
319 #define CMD_SETPCF 0x0032
320 #define CMD_SETPHYREG 0x003e
321 #define CMD_TXTEST 0x003f
322 #define MAC_ENABLETX 0x0101
323 #define CMD_LISTBSS 0x0103
324 #define CMD_SAVECFG 0x0108
325 #define CMD_ENABLEAUX 0x0111
326 #define CMD_WRITERID 0x0121
327 #define CMD_USEPSPNODES 0x0130
328 #define MAC_ENABLERX 0x0201
330 /* Command errors */
331 #define ERROR_QUALIF 0x00
332 #define ERROR_ILLCMD 0x01
333 #define ERROR_ILLFMT 0x02
334 #define ERROR_INVFID 0x03
335 #define ERROR_INVRID 0x04
336 #define ERROR_LARGE 0x05
337 #define ERROR_NDISABL 0x06
338 #define ERROR_ALLOCBSY 0x07
339 #define ERROR_NORD 0x0B
340 #define ERROR_NOWR 0x0C
341 #define ERROR_INVFIDTX 0x0D
342 #define ERROR_TESTACT 0x0E
343 #define ERROR_TAGNFND 0x12
344 #define ERROR_DECODE 0x20
345 #define ERROR_DESCUNAV 0x21
346 #define ERROR_BADLEN 0x22
347 #define ERROR_MODE 0x80
348 #define ERROR_HOP 0x81
349 #define ERROR_BINTER 0x82
350 #define ERROR_RXMODE 0x83
351 #define ERROR_MACADDR 0x84
352 #define ERROR_RATES 0x85
353 #define ERROR_ORDER 0x86
354 #define ERROR_SCAN 0x87
355 #define ERROR_AUTH 0x88
356 #define ERROR_PSMODE 0x89
357 #define ERROR_RTYPE 0x8A
358 #define ERROR_DIVER 0x8B
359 #define ERROR_SSID 0x8C
360 #define ERROR_APLIST 0x8D
361 #define ERROR_AUTOWAKE 0x8E
362 #define ERROR_LEAP 0x8F
364 /* Registers */
365 #define COMMAND 0x00
366 #define PARAM0 0x02
367 #define PARAM1 0x04
368 #define PARAM2 0x06
369 #define STATUS 0x08
370 #define RESP0 0x0a
371 #define RESP1 0x0c
372 #define RESP2 0x0e
373 #define LINKSTAT 0x10
374 #define SELECT0 0x18
375 #define OFFSET0 0x1c
376 #define RXFID 0x20
377 #define TXALLOCFID 0x22
378 #define TXCOMPLFID 0x24
379 #define DATA0 0x36
380 #define EVSTAT 0x30
381 #define EVINTEN 0x32
382 #define EVACK 0x34
383 #define SWS0 0x28
384 #define SWS1 0x2a
385 #define SWS2 0x2c
386 #define SWS3 0x2e
387 #define AUXPAGE 0x3A
388 #define AUXOFF 0x3C
389 #define AUXDATA 0x3E
391 #define FID_TX 1
392 #define FID_RX 2
393 /* Offset into aux memory for descriptors */
394 #define AUX_OFFSET 0x800
395 /* Size of allocated packets */
396 #define PKTSIZE 1840
397 #define RIDSIZE 2048
398 /* Size of the transmit queue */
399 #define MAXTXQ 64
401 /* BAP selectors */
402 #define BAP0 0 /* Used for receiving packets */
403 #define BAP1 2 /* Used for xmiting packets and working with RIDS */
405 /* Flags */
406 #define COMMAND_BUSY 0x8000
408 #define BAP_BUSY 0x8000
409 #define BAP_ERR 0x4000
410 #define BAP_DONE 0x2000
412 #define PROMISC 0xffff
413 #define NOPROMISC 0x0000
415 #define EV_CMD 0x10
416 #define EV_CLEARCOMMANDBUSY 0x4000
417 #define EV_RX 0x01
418 #define EV_TX 0x02
419 #define EV_TXEXC 0x04
420 #define EV_ALLOC 0x08
421 #define EV_LINK 0x80
422 #define EV_AWAKE 0x100
423 #define EV_TXCPY 0x400
424 #define EV_UNKNOWN 0x800
425 #define EV_MIC 0x1000 /* Message Integrity Check Interrupt */
426 #define EV_AWAKEN 0x2000
427 #define STATUS_INTS (EV_AWAKE|EV_LINK|EV_TXEXC|EV_TX|EV_TXCPY|EV_RX|EV_MIC)
429 #ifdef CHECK_UNKNOWN_INTS
430 #define IGNORE_INTS ( EV_CMD | EV_UNKNOWN)
431 #else
432 #define IGNORE_INTS (~STATUS_INTS)
433 #endif
435 /* RID TYPES */
436 #define RID_RW 0x20
438 /* The RIDs */
439 #define RID_CAPABILITIES 0xFF00
440 #define RID_APINFO 0xFF01
441 #define RID_RADIOINFO 0xFF02
442 #define RID_UNKNOWN3 0xFF03
443 #define RID_RSSI 0xFF04
444 #define RID_CONFIG 0xFF10
445 #define RID_SSID 0xFF11
446 #define RID_APLIST 0xFF12
447 #define RID_DRVNAME 0xFF13
448 #define RID_ETHERENCAP 0xFF14
449 #define RID_WEP_TEMP 0xFF15
450 #define RID_WEP_PERM 0xFF16
451 #define RID_MODULATION 0xFF17
452 #define RID_OPTIONS 0xFF18
453 #define RID_ACTUALCONFIG 0xFF20 /*readonly*/
454 #define RID_FACTORYCONFIG 0xFF21
455 #define RID_UNKNOWN22 0xFF22
456 #define RID_LEAPUSERNAME 0xFF23
457 #define RID_LEAPPASSWORD 0xFF24
458 #define RID_STATUS 0xFF50
459 #define RID_BEACON_HST 0xFF51
460 #define RID_BUSY_HST 0xFF52
461 #define RID_RETRIES_HST 0xFF53
462 #define RID_UNKNOWN54 0xFF54
463 #define RID_UNKNOWN55 0xFF55
464 #define RID_UNKNOWN56 0xFF56
465 #define RID_MIC 0xFF57
466 #define RID_STATS16 0xFF60
467 #define RID_STATS16DELTA 0xFF61
468 #define RID_STATS16DELTACLEAR 0xFF62
469 #define RID_STATS 0xFF68
470 #define RID_STATSDELTA 0xFF69
471 #define RID_STATSDELTACLEAR 0xFF6A
472 #define RID_ECHOTEST_RID 0xFF70
473 #define RID_ECHOTEST_RESULTS 0xFF71
474 #define RID_BSSLISTFIRST 0xFF72
475 #define RID_BSSLISTNEXT 0xFF73
476 #define RID_WPA_BSSLISTFIRST 0xFF74
477 #define RID_WPA_BSSLISTNEXT 0xFF75
479 typedef struct {
480 u16 cmd;
481 u16 parm0;
482 u16 parm1;
483 u16 parm2;
484 } Cmd;
486 typedef struct {
487 u16 status;
488 u16 rsp0;
489 u16 rsp1;
490 u16 rsp2;
491 } Resp;
494 * Rids and endian-ness: The Rids will always be in cpu endian, since
495 * this all the patches from the big-endian guys end up doing that.
496 * so all rid access should use the read/writeXXXRid routines.
499 /* This is redundant for x86 archs, but it seems necessary for ARM */
500 #pragma pack(1)
502 /* This structure came from an email sent to me from an engineer at
503 aironet for inclusion into this driver */
504 typedef struct {
505 __le16 len;
506 __le16 kindex;
507 u8 mac[ETH_ALEN];
508 __le16 klen;
509 u8 key[16];
510 } WepKeyRid;
512 /* These structures are from the Aironet's PC4500 Developers Manual */
513 typedef struct {
514 __le16 len;
515 u8 ssid[32];
516 } Ssid;
518 typedef struct {
519 __le16 len;
520 Ssid ssids[3];
521 } SsidRid;
523 typedef struct {
524 __le16 len;
525 __le16 modulation;
526 #define MOD_DEFAULT cpu_to_le16(0)
527 #define MOD_CCK cpu_to_le16(1)
528 #define MOD_MOK cpu_to_le16(2)
529 } ModulationRid;
531 typedef struct {
532 __le16 len; /* sizeof(ConfigRid) */
533 __le16 opmode; /* operating mode */
534 #define MODE_STA_IBSS cpu_to_le16(0)
535 #define MODE_STA_ESS cpu_to_le16(1)
536 #define MODE_AP cpu_to_le16(2)
537 #define MODE_AP_RPTR cpu_to_le16(3)
538 #define MODE_CFG_MASK cpu_to_le16(0xff)
539 #define MODE_ETHERNET_HOST cpu_to_le16(0<<8) /* rx payloads converted */
540 #define MODE_LLC_HOST cpu_to_le16(1<<8) /* rx payloads left as is */
541 #define MODE_AIRONET_EXTEND cpu_to_le16(1<<9) /* enable Aironet extenstions */
542 #define MODE_AP_INTERFACE cpu_to_le16(1<<10) /* enable ap interface extensions */
543 #define MODE_ANTENNA_ALIGN cpu_to_le16(1<<11) /* enable antenna alignment */
544 #define MODE_ETHER_LLC cpu_to_le16(1<<12) /* enable ethernet LLC */
545 #define MODE_LEAF_NODE cpu_to_le16(1<<13) /* enable leaf node bridge */
546 #define MODE_CF_POLLABLE cpu_to_le16(1<<14) /* enable CF pollable */
547 #define MODE_MIC cpu_to_le16(1<<15) /* enable MIC */
548 __le16 rmode; /* receive mode */
549 #define RXMODE_BC_MC_ADDR cpu_to_le16(0)
550 #define RXMODE_BC_ADDR cpu_to_le16(1) /* ignore multicasts */
551 #define RXMODE_ADDR cpu_to_le16(2) /* ignore multicast and broadcast */
552 #define RXMODE_RFMON cpu_to_le16(3) /* wireless monitor mode */
553 #define RXMODE_RFMON_ANYBSS cpu_to_le16(4)
554 #define RXMODE_LANMON cpu_to_le16(5) /* lan style monitor -- data packets only */
555 #define RXMODE_MASK cpu_to_le16(255)
556 #define RXMODE_DISABLE_802_3_HEADER cpu_to_le16(1<<8) /* disables 802.3 header on rx */
557 #define RXMODE_FULL_MASK (RXMODE_MASK | RXMODE_DISABLE_802_3_HEADER)
558 #define RXMODE_NORMALIZED_RSSI cpu_to_le16(1<<9) /* return normalized RSSI */
559 __le16 fragThresh;
560 __le16 rtsThres;
561 u8 macAddr[ETH_ALEN];
562 u8 rates[8];
563 __le16 shortRetryLimit;
564 __le16 longRetryLimit;
565 __le16 txLifetime; /* in kusec */
566 __le16 rxLifetime; /* in kusec */
567 __le16 stationary;
568 __le16 ordering;
569 __le16 u16deviceType; /* for overriding device type */
570 __le16 cfpRate;
571 __le16 cfpDuration;
572 __le16 _reserved1[3];
573 /*---------- Scanning/Associating ----------*/
574 __le16 scanMode;
575 #define SCANMODE_ACTIVE cpu_to_le16(0)
576 #define SCANMODE_PASSIVE cpu_to_le16(1)
577 #define SCANMODE_AIROSCAN cpu_to_le16(2)
578 __le16 probeDelay; /* in kusec */
579 __le16 probeEnergyTimeout; /* in kusec */
580 __le16 probeResponseTimeout;
581 __le16 beaconListenTimeout;
582 __le16 joinNetTimeout;
583 __le16 authTimeout;
584 __le16 authType;
585 #define AUTH_OPEN cpu_to_le16(0x1)
586 #define AUTH_ENCRYPT cpu_to_le16(0x101)
587 #define AUTH_SHAREDKEY cpu_to_le16(0x102)
588 #define AUTH_ALLOW_UNENCRYPTED cpu_to_le16(0x200)
589 __le16 associationTimeout;
590 __le16 specifiedApTimeout;
591 __le16 offlineScanInterval;
592 __le16 offlineScanDuration;
593 __le16 linkLossDelay;
594 __le16 maxBeaconLostTime;
595 __le16 refreshInterval;
596 #define DISABLE_REFRESH cpu_to_le16(0xFFFF)
597 __le16 _reserved1a[1];
598 /*---------- Power save operation ----------*/
599 __le16 powerSaveMode;
600 #define POWERSAVE_CAM cpu_to_le16(0)
601 #define POWERSAVE_PSP cpu_to_le16(1)
602 #define POWERSAVE_PSPCAM cpu_to_le16(2)
603 __le16 sleepForDtims;
604 __le16 listenInterval;
605 __le16 fastListenInterval;
606 __le16 listenDecay;
607 __le16 fastListenDelay;
608 __le16 _reserved2[2];
609 /*---------- Ap/Ibss config items ----------*/
610 __le16 beaconPeriod;
611 __le16 atimDuration;
612 __le16 hopPeriod;
613 __le16 channelSet;
614 __le16 channel;
615 __le16 dtimPeriod;
616 __le16 bridgeDistance;
617 __le16 radioID;
618 /*---------- Radio configuration ----------*/
619 __le16 radioType;
620 #define RADIOTYPE_DEFAULT cpu_to_le16(0)
621 #define RADIOTYPE_802_11 cpu_to_le16(1)
622 #define RADIOTYPE_LEGACY cpu_to_le16(2)
623 u8 rxDiversity;
624 u8 txDiversity;
625 __le16 txPower;
626 #define TXPOWER_DEFAULT 0
627 __le16 rssiThreshold;
628 #define RSSI_DEFAULT 0
629 __le16 modulation;
630 #define PREAMBLE_AUTO cpu_to_le16(0)
631 #define PREAMBLE_LONG cpu_to_le16(1)
632 #define PREAMBLE_SHORT cpu_to_le16(2)
633 __le16 preamble;
634 __le16 homeProduct;
635 __le16 radioSpecific;
636 /*---------- Aironet Extensions ----------*/
637 u8 nodeName[16];
638 __le16 arlThreshold;
639 __le16 arlDecay;
640 __le16 arlDelay;
641 __le16 _reserved4[1];
642 /*---------- Aironet Extensions ----------*/
643 u8 magicAction;
644 #define MAGIC_ACTION_STSCHG 1
645 #define MAGIC_ACTION_RESUME 2
646 #define MAGIC_IGNORE_MCAST (1<<8)
647 #define MAGIC_IGNORE_BCAST (1<<9)
648 #define MAGIC_SWITCH_TO_PSP (0<<10)
649 #define MAGIC_STAY_IN_CAM (1<<10)
650 u8 magicControl;
651 __le16 autoWake;
652 } ConfigRid;
654 typedef struct {
655 __le16 len;
656 u8 mac[ETH_ALEN];
657 __le16 mode;
658 __le16 errorCode;
659 __le16 sigQuality;
660 __le16 SSIDlen;
661 char SSID[32];
662 char apName[16];
663 u8 bssid[4][ETH_ALEN];
664 __le16 beaconPeriod;
665 __le16 dimPeriod;
666 __le16 atimDuration;
667 __le16 hopPeriod;
668 __le16 channelSet;
669 __le16 channel;
670 __le16 hopsToBackbone;
671 __le16 apTotalLoad;
672 __le16 generatedLoad;
673 __le16 accumulatedArl;
674 __le16 signalQuality;
675 __le16 currentXmitRate;
676 __le16 apDevExtensions;
677 __le16 normalizedSignalStrength;
678 __le16 shortPreamble;
679 u8 apIP[4];
680 u8 noisePercent; /* Noise percent in last second */
681 u8 noisedBm; /* Noise dBm in last second */
682 u8 noiseAvePercent; /* Noise percent in last minute */
683 u8 noiseAvedBm; /* Noise dBm in last minute */
684 u8 noiseMaxPercent; /* Highest noise percent in last minute */
685 u8 noiseMaxdBm; /* Highest noise dbm in last minute */
686 __le16 load;
687 u8 carrier[4];
688 __le16 assocStatus;
689 #define STAT_NOPACKETS 0
690 #define STAT_NOCARRIERSET 10
691 #define STAT_GOTCARRIERSET 11
692 #define STAT_WRONGSSID 20
693 #define STAT_BADCHANNEL 25
694 #define STAT_BADBITRATES 30
695 #define STAT_BADPRIVACY 35
696 #define STAT_APFOUND 40
697 #define STAT_APREJECTED 50
698 #define STAT_AUTHENTICATING 60
699 #define STAT_DEAUTHENTICATED 61
700 #define STAT_AUTHTIMEOUT 62
701 #define STAT_ASSOCIATING 70
702 #define STAT_DEASSOCIATED 71
703 #define STAT_ASSOCTIMEOUT 72
704 #define STAT_NOTAIROAP 73
705 #define STAT_ASSOCIATED 80
706 #define STAT_LEAPING 90
707 #define STAT_LEAPFAILED 91
708 #define STAT_LEAPTIMEDOUT 92
709 #define STAT_LEAPCOMPLETE 93
710 } StatusRid;
712 typedef struct {
713 __le16 len;
714 __le16 spacer;
715 __le32 vals[100];
716 } StatsRid;
719 typedef struct {
720 __le16 len;
721 u8 ap[4][ETH_ALEN];
722 } APListRid;
724 typedef struct {
725 __le16 len;
726 char oui[3];
727 char zero;
728 __le16 prodNum;
729 char manName[32];
730 char prodName[16];
731 char prodVer[8];
732 char factoryAddr[ETH_ALEN];
733 char aironetAddr[ETH_ALEN];
734 __le16 radioType;
735 __le16 country;
736 char callid[ETH_ALEN];
737 char supportedRates[8];
738 char rxDiversity;
739 char txDiversity;
740 __le16 txPowerLevels[8];
741 __le16 hardVer;
742 __le16 hardCap;
743 __le16 tempRange;
744 __le16 softVer;
745 __le16 softSubVer;
746 __le16 interfaceVer;
747 __le16 softCap;
748 __le16 bootBlockVer;
749 __le16 requiredHard;
750 __le16 extSoftCap;
751 } CapabilityRid;
754 /* Only present on firmware >= 5.30.17 */
755 typedef struct {
756 __le16 unknown[4];
757 u8 fixed[12]; /* WLAN management frame */
758 u8 iep[624];
759 } BSSListRidExtra;
761 typedef struct {
762 __le16 len;
763 __le16 index; /* First is 0 and 0xffff means end of list */
764 #define RADIO_FH 1 /* Frequency hopping radio type */
765 #define RADIO_DS 2 /* Direct sequence radio type */
766 #define RADIO_TMA 4 /* Proprietary radio used in old cards (2500) */
767 __le16 radioType;
768 u8 bssid[ETH_ALEN]; /* Mac address of the BSS */
769 u8 zero;
770 u8 ssidLen;
771 u8 ssid[32];
772 __le16 dBm;
773 #define CAP_ESS cpu_to_le16(1<<0)
774 #define CAP_IBSS cpu_to_le16(1<<1)
775 #define CAP_PRIVACY cpu_to_le16(1<<4)
776 #define CAP_SHORTHDR cpu_to_le16(1<<5)
777 __le16 cap;
778 __le16 beaconInterval;
779 u8 rates[8]; /* Same as rates for config rid */
780 struct { /* For frequency hopping only */
781 __le16 dwell;
782 u8 hopSet;
783 u8 hopPattern;
784 u8 hopIndex;
785 u8 fill;
786 } fh;
787 __le16 dsChannel;
788 __le16 atimWindow;
790 /* Only present on firmware >= 5.30.17 */
791 BSSListRidExtra extra;
792 } BSSListRid;
794 typedef struct {
795 BSSListRid bss;
796 struct list_head list;
797 } BSSListElement;
799 typedef struct {
800 u8 rssipct;
801 u8 rssidBm;
802 } tdsRssiEntry;
804 typedef struct {
805 u16 len;
806 tdsRssiEntry x[256];
807 } tdsRssiRid;
809 typedef struct {
810 u16 len;
811 u16 state;
812 u16 multicastValid;
813 u8 multicast[16];
814 u16 unicastValid;
815 u8 unicast[16];
816 } MICRid;
818 typedef struct {
819 __be16 typelen;
821 union {
822 u8 snap[8];
823 struct {
824 u8 dsap;
825 u8 ssap;
826 u8 control;
827 u8 orgcode[3];
828 u8 fieldtype[2];
829 } llc;
830 } u;
831 __be32 mic;
832 __be32 seq;
833 } MICBuffer;
835 typedef struct {
836 u8 da[ETH_ALEN];
837 u8 sa[ETH_ALEN];
838 } etherHead;
840 #pragma pack()
842 #define TXCTL_TXOK (1<<1) /* report if tx is ok */
843 #define TXCTL_TXEX (1<<2) /* report if tx fails */
844 #define TXCTL_802_3 (0<<3) /* 802.3 packet */
845 #define TXCTL_802_11 (1<<3) /* 802.11 mac packet */
846 #define TXCTL_ETHERNET (0<<4) /* payload has ethertype */
847 #define TXCTL_LLC (1<<4) /* payload is llc */
848 #define TXCTL_RELEASE (0<<5) /* release after completion */
849 #define TXCTL_NORELEASE (1<<5) /* on completion returns to host */
851 #define BUSY_FID 0x10000
853 #ifdef CISCO_EXT
854 #define AIROMAGIC 0xa55a
855 /* Warning : SIOCDEVPRIVATE may disapear during 2.5.X - Jean II */
856 #ifdef SIOCIWFIRSTPRIV
857 #ifdef SIOCDEVPRIVATE
858 #define AIROOLDIOCTL SIOCDEVPRIVATE
859 #define AIROOLDIDIFC AIROOLDIOCTL + 1
860 #endif /* SIOCDEVPRIVATE */
861 #else /* SIOCIWFIRSTPRIV */
862 #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
863 #endif /* SIOCIWFIRSTPRIV */
864 /* This may be wrong. When using the new SIOCIWFIRSTPRIV range, we probably
865 * should use only "GET" ioctls (last bit set to 1). "SET" ioctls are root
866 * only and don't return the modified struct ifreq to the application which
867 * is usually a problem. - Jean II */
868 #define AIROIOCTL SIOCIWFIRSTPRIV
869 #define AIROIDIFC AIROIOCTL + 1
871 /* Ioctl constants to be used in airo_ioctl.command */
873 #define AIROGCAP 0 // Capability rid
874 #define AIROGCFG 1 // USED A LOT
875 #define AIROGSLIST 2 // System ID list
876 #define AIROGVLIST 3 // List of specified AP's
877 #define AIROGDRVNAM 4 // NOTUSED
878 #define AIROGEHTENC 5 // NOTUSED
879 #define AIROGWEPKTMP 6
880 #define AIROGWEPKNV 7
881 #define AIROGSTAT 8
882 #define AIROGSTATSC32 9
883 #define AIROGSTATSD32 10
884 #define AIROGMICRID 11
885 #define AIROGMICSTATS 12
886 #define AIROGFLAGS 13
887 #define AIROGID 14
888 #define AIRORRID 15
889 #define AIRORSWVERSION 17
891 /* Leave gap of 40 commands after AIROGSTATSD32 for future */
893 #define AIROPCAP AIROGSTATSD32 + 40
894 #define AIROPVLIST AIROPCAP + 1
895 #define AIROPSLIST AIROPVLIST + 1
896 #define AIROPCFG AIROPSLIST + 1
897 #define AIROPSIDS AIROPCFG + 1
898 #define AIROPAPLIST AIROPSIDS + 1
899 #define AIROPMACON AIROPAPLIST + 1 /* Enable mac */
900 #define AIROPMACOFF AIROPMACON + 1 /* Disable mac */
901 #define AIROPSTCLR AIROPMACOFF + 1
902 #define AIROPWEPKEY AIROPSTCLR + 1
903 #define AIROPWEPKEYNV AIROPWEPKEY + 1
904 #define AIROPLEAPPWD AIROPWEPKEYNV + 1
905 #define AIROPLEAPUSR AIROPLEAPPWD + 1
907 /* Flash codes */
909 #define AIROFLSHRST AIROPWEPKEYNV + 40
910 #define AIROFLSHGCHR AIROFLSHRST + 1
911 #define AIROFLSHSTFL AIROFLSHGCHR + 1
912 #define AIROFLSHPCHR AIROFLSHSTFL + 1
913 #define AIROFLPUTBUF AIROFLSHPCHR + 1
914 #define AIRORESTART AIROFLPUTBUF + 1
916 #define FLASHSIZE 32768
917 #define AUXMEMSIZE (256 * 1024)
919 typedef struct aironet_ioctl {
920 unsigned short command; // What to do
921 unsigned short len; // Len of data
922 unsigned short ridnum; // rid number
923 unsigned char __user *data; // d-data
924 } aironet_ioctl;
926 static char swversion[] = "2.1";
927 #endif /* CISCO_EXT */
929 #define NUM_MODULES 2
930 #define MIC_MSGLEN_MAX 2400
931 #define EMMH32_MSGLEN_MAX MIC_MSGLEN_MAX
932 #define AIRO_DEF_MTU 2312
934 typedef struct {
935 u32 size; // size
936 u8 enabled; // MIC enabled or not
937 u32 rxSuccess; // successful packets received
938 u32 rxIncorrectMIC; // pkts dropped due to incorrect MIC comparison
939 u32 rxNotMICed; // pkts dropped due to not being MIC'd
940 u32 rxMICPlummed; // pkts dropped due to not having a MIC plummed
941 u32 rxWrongSequence; // pkts dropped due to sequence number violation
942 u32 reserve[32];
943 } mic_statistics;
945 typedef struct {
946 u32 coeff[((EMMH32_MSGLEN_MAX)+3)>>2];
947 u64 accum; // accumulated mic, reduced to u32 in final()
948 int position; // current position (byte offset) in message
949 union {
950 u8 d8[4];
951 __be32 d32;
952 } part; // saves partial message word across update() calls
953 } emmh32_context;
955 typedef struct {
956 emmh32_context seed; // Context - the seed
957 u32 rx; // Received sequence number
958 u32 tx; // Tx sequence number
959 u32 window; // Start of window
960 u8 valid; // Flag to say if context is valid or not
961 u8 key[16];
962 } miccntx;
964 typedef struct {
965 miccntx mCtx; // Multicast context
966 miccntx uCtx; // Unicast context
967 } mic_module;
969 typedef struct {
970 unsigned int rid: 16;
971 unsigned int len: 15;
972 unsigned int valid: 1;
973 dma_addr_t host_addr;
974 } Rid;
976 typedef struct {
977 unsigned int offset: 15;
978 unsigned int eoc: 1;
979 unsigned int len: 15;
980 unsigned int valid: 1;
981 dma_addr_t host_addr;
982 } TxFid;
984 typedef struct {
985 unsigned int ctl: 15;
986 unsigned int rdy: 1;
987 unsigned int len: 15;
988 unsigned int valid: 1;
989 dma_addr_t host_addr;
990 } RxFid;
993 * Host receive descriptor
995 typedef struct {
996 unsigned char __iomem *card_ram_off; /* offset into card memory of the
997 desc */
998 RxFid rx_desc; /* card receive descriptor */
999 char *virtual_host_addr; /* virtual address of host receive
1000 buffer */
1001 int pending;
1002 } HostRxDesc;
1005 * Host transmit descriptor
1007 typedef struct {
1008 unsigned char __iomem *card_ram_off; /* offset into card memory of the
1009 desc */
1010 TxFid tx_desc; /* card transmit descriptor */
1011 char *virtual_host_addr; /* virtual address of host receive
1012 buffer */
1013 int pending;
1014 } HostTxDesc;
1017 * Host RID descriptor
1019 typedef struct {
1020 unsigned char __iomem *card_ram_off; /* offset into card memory of the
1021 descriptor */
1022 Rid rid_desc; /* card RID descriptor */
1023 char *virtual_host_addr; /* virtual address of host receive
1024 buffer */
1025 } HostRidDesc;
1027 typedef struct {
1028 u16 sw0;
1029 u16 sw1;
1030 u16 status;
1031 u16 len;
1032 #define HOST_SET (1 << 0)
1033 #define HOST_INT_TX (1 << 1) /* Interrupt on successful TX */
1034 #define HOST_INT_TXERR (1 << 2) /* Interrupt on unseccessful TX */
1035 #define HOST_LCC_PAYLOAD (1 << 4) /* LLC payload, 0 = Ethertype */
1036 #define HOST_DONT_RLSE (1 << 5) /* Don't release buffer when done */
1037 #define HOST_DONT_RETRY (1 << 6) /* Don't retry trasmit */
1038 #define HOST_CLR_AID (1 << 7) /* clear AID failure */
1039 #define HOST_RTS (1 << 9) /* Force RTS use */
1040 #define HOST_SHORT (1 << 10) /* Do short preamble */
1041 u16 ctl;
1042 u16 aid;
1043 u16 retries;
1044 u16 fill;
1045 } TxCtlHdr;
1047 typedef struct {
1048 u16 ctl;
1049 u16 duration;
1050 char addr1[6];
1051 char addr2[6];
1052 char addr3[6];
1053 u16 seq;
1054 char addr4[6];
1055 } WifiHdr;
1058 typedef struct {
1059 TxCtlHdr ctlhdr;
1060 u16 fill1;
1061 u16 fill2;
1062 WifiHdr wifihdr;
1063 u16 gaplen;
1064 u16 status;
1065 } WifiCtlHdr;
1067 static WifiCtlHdr wifictlhdr8023 = {
1068 .ctlhdr = {
1069 .ctl = HOST_DONT_RLSE,
1073 // A few details needed for WEP (Wireless Equivalent Privacy)
1074 #define MAX_KEY_SIZE 13 // 128 (?) bits
1075 #define MIN_KEY_SIZE 5 // 40 bits RC4 - WEP
1076 typedef struct wep_key_t {
1077 u16 len;
1078 u8 key[16]; /* 40-bit and 104-bit keys */
1079 } wep_key_t;
1081 /* Backward compatibility */
1082 #ifndef IW_ENCODE_NOKEY
1083 #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
1084 #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
1085 #endif /* IW_ENCODE_NOKEY */
1087 /* List of Wireless Handlers (new API) */
1088 static const struct iw_handler_def airo_handler_def;
1090 static const char version[] = "airo.c 0.6 (Ben Reed & Javier Achirica)";
1092 struct airo_info;
1094 static int get_dec_u16( char *buffer, int *start, int limit );
1095 static void OUT4500( struct airo_info *, u16 register, u16 value );
1096 static unsigned short IN4500( struct airo_info *, u16 register );
1097 static u16 setup_card(struct airo_info*, u8 *mac, int lock);
1098 static int enable_MAC(struct airo_info *ai, int lock);
1099 static void disable_MAC(struct airo_info *ai, int lock);
1100 static void enable_interrupts(struct airo_info*);
1101 static void disable_interrupts(struct airo_info*);
1102 static u16 issuecommand(struct airo_info*, Cmd *pCmd, Resp *pRsp);
1103 static int bap_setup(struct airo_info*, u16 rid, u16 offset, int whichbap);
1104 static int aux_bap_read(struct airo_info*, __le16 *pu16Dst, int bytelen,
1105 int whichbap);
1106 static int fast_bap_read(struct airo_info*, __le16 *pu16Dst, int bytelen,
1107 int whichbap);
1108 static int bap_write(struct airo_info*, const __le16 *pu16Src, int bytelen,
1109 int whichbap);
1110 static int PC4500_accessrid(struct airo_info*, u16 rid, u16 accmd);
1111 static int PC4500_readrid(struct airo_info*, u16 rid, void *pBuf, int len, int lock);
1112 static int PC4500_writerid(struct airo_info*, u16 rid, const void
1113 *pBuf, int len, int lock);
1114 static int do_writerid( struct airo_info*, u16 rid, const void *rid_data,
1115 int len, int dummy );
1116 static u16 transmit_allocate(struct airo_info*, int lenPayload, int raw);
1117 static int transmit_802_3_packet(struct airo_info*, int len, char *pPacket);
1118 static int transmit_802_11_packet(struct airo_info*, int len, char *pPacket);
1120 static int mpi_send_packet (struct net_device *dev);
1121 static void mpi_unmap_card(struct pci_dev *pci);
1122 static void mpi_receive_802_3(struct airo_info *ai);
1123 static void mpi_receive_802_11(struct airo_info *ai);
1124 static int waitbusy (struct airo_info *ai);
1126 static irqreturn_t airo_interrupt( int irq, void* dev_id);
1127 static int airo_thread(void *data);
1128 static void timer_func( struct net_device *dev );
1129 static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
1130 static struct iw_statistics *airo_get_wireless_stats (struct net_device *dev);
1131 static void airo_read_wireless_stats (struct airo_info *local);
1132 #ifdef CISCO_EXT
1133 static int readrids(struct net_device *dev, aironet_ioctl *comp);
1134 static int writerids(struct net_device *dev, aironet_ioctl *comp);
1135 static int flashcard(struct net_device *dev, aironet_ioctl *comp);
1136 #endif /* CISCO_EXT */
1137 static void micinit(struct airo_info *ai);
1138 static int micsetup(struct airo_info *ai);
1139 static int encapsulate(struct airo_info *ai, etherHead *pPacket, MICBuffer *buffer, int len);
1140 static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *pPacket, u16 payLen);
1142 static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi);
1143 static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm);
1145 static void airo_networks_free(struct airo_info *ai);
1147 struct airo_info {
1148 struct net_device *dev;
1149 struct list_head dev_list;
1150 /* Note, we can have MAX_FIDS outstanding. FIDs are 16-bits, so we
1151 use the high bit to mark whether it is in use. */
1152 #define MAX_FIDS 6
1153 #define MPI_MAX_FIDS 1
1154 int fids[MAX_FIDS];
1155 ConfigRid config;
1156 char keyindex; // Used with auto wep
1157 char defindex; // Used with auto wep
1158 struct proc_dir_entry *proc_entry;
1159 spinlock_t aux_lock;
1160 #define FLAG_RADIO_OFF 0 /* User disabling of MAC */
1161 #define FLAG_RADIO_DOWN 1 /* ifup/ifdown disabling of MAC */
1162 #define FLAG_RADIO_MASK 0x03
1163 #define FLAG_ENABLED 2
1164 #define FLAG_ADHOC 3 /* Needed by MIC */
1165 #define FLAG_MIC_CAPABLE 4
1166 #define FLAG_UPDATE_MULTI 5
1167 #define FLAG_UPDATE_UNI 6
1168 #define FLAG_802_11 7
1169 #define FLAG_PROMISC 8 /* IFF_PROMISC 0x100 - include/linux/if.h */
1170 #define FLAG_PENDING_XMIT 9
1171 #define FLAG_PENDING_XMIT11 10
1172 #define FLAG_MPI 11
1173 #define FLAG_REGISTERED 12
1174 #define FLAG_COMMIT 13
1175 #define FLAG_RESET 14
1176 #define FLAG_FLASHING 15
1177 #define FLAG_WPA_CAPABLE 16
1178 unsigned long flags;
1179 #define JOB_DIE 0
1180 #define JOB_XMIT 1
1181 #define JOB_XMIT11 2
1182 #define JOB_STATS 3
1183 #define JOB_PROMISC 4
1184 #define JOB_MIC 5
1185 #define JOB_EVENT 6
1186 #define JOB_AUTOWEP 7
1187 #define JOB_WSTATS 8
1188 #define JOB_SCAN_RESULTS 9
1189 unsigned long jobs;
1190 int (*bap_read)(struct airo_info*, __le16 *pu16Dst, int bytelen,
1191 int whichbap);
1192 unsigned short *flash;
1193 tdsRssiEntry *rssi;
1194 struct task_struct *list_bss_task;
1195 struct task_struct *airo_thread_task;
1196 struct semaphore sem;
1197 wait_queue_head_t thr_wait;
1198 unsigned long expires;
1199 struct {
1200 struct sk_buff *skb;
1201 int fid;
1202 } xmit, xmit11;
1203 struct net_device *wifidev;
1204 struct iw_statistics wstats; // wireless stats
1205 unsigned long scan_timeout; /* Time scan should be read */
1206 struct iw_spy_data spy_data;
1207 struct iw_public_data wireless_data;
1208 /* MIC stuff */
1209 struct crypto_cipher *tfm;
1210 mic_module mod[2];
1211 mic_statistics micstats;
1212 HostRxDesc rxfids[MPI_MAX_FIDS]; // rx/tx/config MPI350 descriptors
1213 HostTxDesc txfids[MPI_MAX_FIDS];
1214 HostRidDesc config_desc;
1215 unsigned long ridbus; // phys addr of config_desc
1216 struct sk_buff_head txq;// tx queue used by mpi350 code
1217 struct pci_dev *pci;
1218 unsigned char __iomem *pcimem;
1219 unsigned char __iomem *pciaux;
1220 unsigned char *shared;
1221 dma_addr_t shared_dma;
1222 pm_message_t power;
1223 SsidRid *SSID;
1224 APListRid *APList;
1225 #define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE
1226 char proc_name[IFNAMSIZ];
1228 /* WPA-related stuff */
1229 unsigned int bssListFirst;
1230 unsigned int bssListNext;
1231 unsigned int bssListRidLen;
1233 struct list_head network_list;
1234 struct list_head network_free_list;
1235 BSSListElement *networks;
1238 static inline int bap_read(struct airo_info *ai, __le16 *pu16Dst, int bytelen,
1239 int whichbap)
1241 return ai->bap_read(ai, pu16Dst, bytelen, whichbap);
1244 static int setup_proc_entry( struct net_device *dev,
1245 struct airo_info *apriv );
1246 static int takedown_proc_entry( struct net_device *dev,
1247 struct airo_info *apriv );
1249 static int cmdreset(struct airo_info *ai);
1250 static int setflashmode (struct airo_info *ai);
1251 static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime);
1252 static int flashputbuf(struct airo_info *ai);
1253 static int flashrestart(struct airo_info *ai,struct net_device *dev);
1255 #define airo_print(type, name, fmt, args...) \
1256 printk(type DRV_NAME "(%s): " fmt "\n", name, ##args)
1258 #define airo_print_info(name, fmt, args...) \
1259 airo_print(KERN_INFO, name, fmt, ##args)
1261 #define airo_print_dbg(name, fmt, args...) \
1262 airo_print(KERN_DEBUG, name, fmt, ##args)
1264 #define airo_print_warn(name, fmt, args...) \
1265 airo_print(KERN_WARNING, name, fmt, ##args)
1267 #define airo_print_err(name, fmt, args...) \
1268 airo_print(KERN_ERR, name, fmt, ##args)
1270 #define AIRO_FLASH(dev) (((struct airo_info *)dev->ml_priv)->flash)
1272 /***********************************************************************
1273 * MIC ROUTINES *
1274 ***********************************************************************
1277 static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq);
1278 static void MoveWindow(miccntx *context, u32 micSeq);
1279 static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
1280 struct crypto_cipher *tfm);
1281 static void emmh32_init(emmh32_context *context);
1282 static void emmh32_update(emmh32_context *context, u8 *pOctets, int len);
1283 static void emmh32_final(emmh32_context *context, u8 digest[4]);
1284 static int flashpchar(struct airo_info *ai,int byte,int dwelltime);
1286 /* micinit - Initialize mic seed */
1288 static void micinit(struct airo_info *ai)
1290 MICRid mic_rid;
1292 clear_bit(JOB_MIC, &ai->jobs);
1293 PC4500_readrid(ai, RID_MIC, &mic_rid, sizeof(mic_rid), 0);
1294 up(&ai->sem);
1296 ai->micstats.enabled = (mic_rid.state & 0x00FF) ? 1 : 0;
1298 if (ai->micstats.enabled) {
1299 /* Key must be valid and different */
1300 if (mic_rid.multicastValid && (!ai->mod[0].mCtx.valid ||
1301 (memcmp (ai->mod[0].mCtx.key, mic_rid.multicast,
1302 sizeof(ai->mod[0].mCtx.key)) != 0))) {
1303 /* Age current mic Context */
1304 memcpy(&ai->mod[1].mCtx,&ai->mod[0].mCtx,sizeof(miccntx));
1305 /* Initialize new context */
1306 memcpy(&ai->mod[0].mCtx.key,mic_rid.multicast,sizeof(mic_rid.multicast));
1307 ai->mod[0].mCtx.window = 33; //Window always points to the middle
1308 ai->mod[0].mCtx.rx = 0; //Rx Sequence numbers
1309 ai->mod[0].mCtx.tx = 0; //Tx sequence numbers
1310 ai->mod[0].mCtx.valid = 1; //Key is now valid
1312 /* Give key to mic seed */
1313 emmh32_setseed(&ai->mod[0].mCtx.seed,mic_rid.multicast,sizeof(mic_rid.multicast), ai->tfm);
1316 /* Key must be valid and different */
1317 if (mic_rid.unicastValid && (!ai->mod[0].uCtx.valid ||
1318 (memcmp(ai->mod[0].uCtx.key, mic_rid.unicast,
1319 sizeof(ai->mod[0].uCtx.key)) != 0))) {
1320 /* Age current mic Context */
1321 memcpy(&ai->mod[1].uCtx,&ai->mod[0].uCtx,sizeof(miccntx));
1322 /* Initialize new context */
1323 memcpy(&ai->mod[0].uCtx.key,mic_rid.unicast,sizeof(mic_rid.unicast));
1325 ai->mod[0].uCtx.window = 33; //Window always points to the middle
1326 ai->mod[0].uCtx.rx = 0; //Rx Sequence numbers
1327 ai->mod[0].uCtx.tx = 0; //Tx sequence numbers
1328 ai->mod[0].uCtx.valid = 1; //Key is now valid
1330 //Give key to mic seed
1331 emmh32_setseed(&ai->mod[0].uCtx.seed, mic_rid.unicast, sizeof(mic_rid.unicast), ai->tfm);
1333 } else {
1334 /* So next time we have a valid key and mic is enabled, we will update
1335 * the sequence number if the key is the same as before.
1337 ai->mod[0].uCtx.valid = 0;
1338 ai->mod[0].mCtx.valid = 0;
1342 /* micsetup - Get ready for business */
1344 static int micsetup(struct airo_info *ai) {
1345 int i;
1347 if (ai->tfm == NULL)
1348 ai->tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
1350 if (IS_ERR(ai->tfm)) {
1351 airo_print_err(ai->dev->name, "failed to load transform for AES");
1352 ai->tfm = NULL;
1353 return ERROR;
1356 for (i=0; i < NUM_MODULES; i++) {
1357 memset(&ai->mod[i].mCtx,0,sizeof(miccntx));
1358 memset(&ai->mod[i].uCtx,0,sizeof(miccntx));
1360 return SUCCESS;
1363 static char micsnap[] = {0xAA,0xAA,0x03,0x00,0x40,0x96,0x00,0x02};
1365 /*===========================================================================
1366 * Description: Mic a packet
1368 * Inputs: etherHead * pointer to an 802.3 frame
1370 * Returns: BOOLEAN if successful, otherwise false.
1371 * PacketTxLen will be updated with the mic'd packets size.
1373 * Caveats: It is assumed that the frame buffer will already
1374 * be big enough to hold the largets mic message possible.
1375 * (No memory allocation is done here).
1377 * Author: sbraneky (10/15/01)
1378 * Merciless hacks by rwilcher (1/14/02)
1381 static int encapsulate(struct airo_info *ai ,etherHead *frame, MICBuffer *mic, int payLen)
1383 miccntx *context;
1385 // Determine correct context
1386 // If not adhoc, always use unicast key
1388 if (test_bit(FLAG_ADHOC, &ai->flags) && (frame->da[0] & 0x1))
1389 context = &ai->mod[0].mCtx;
1390 else
1391 context = &ai->mod[0].uCtx;
1393 if (!context->valid)
1394 return ERROR;
1396 mic->typelen = htons(payLen + 16); //Length of Mic'd packet
1398 memcpy(&mic->u.snap, micsnap, sizeof(micsnap)); // Add Snap
1400 // Add Tx sequence
1401 mic->seq = htonl(context->tx);
1402 context->tx += 2;
1404 emmh32_init(&context->seed); // Mic the packet
1405 emmh32_update(&context->seed,frame->da,ETH_ALEN * 2); // DA,SA
1406 emmh32_update(&context->seed,(u8*)&mic->typelen,10); // Type/Length and Snap
1407 emmh32_update(&context->seed,(u8*)&mic->seq,sizeof(mic->seq)); //SEQ
1408 emmh32_update(&context->seed,frame->da + ETH_ALEN * 2,payLen); //payload
1409 emmh32_final(&context->seed, (u8*)&mic->mic);
1411 /* New Type/length ?????????? */
1412 mic->typelen = 0; //Let NIC know it could be an oversized packet
1413 return SUCCESS;
1416 typedef enum {
1417 NONE,
1418 NOMIC,
1419 NOMICPLUMMED,
1420 SEQUENCE,
1421 INCORRECTMIC,
1422 } mic_error;
1424 /*===========================================================================
1425 * Description: Decapsulates a MIC'd packet and returns the 802.3 packet
1426 * (removes the MIC stuff) if packet is a valid packet.
1428 * Inputs: etherHead pointer to the 802.3 packet
1430 * Returns: BOOLEAN - TRUE if packet should be dropped otherwise FALSE
1432 * Author: sbraneky (10/15/01)
1433 * Merciless hacks by rwilcher (1/14/02)
1434 *---------------------------------------------------------------------------
1437 static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *eth, u16 payLen)
1439 int i;
1440 u32 micSEQ;
1441 miccntx *context;
1442 u8 digest[4];
1443 mic_error micError = NONE;
1445 // Check if the packet is a Mic'd packet
1447 if (!ai->micstats.enabled) {
1448 //No Mic set or Mic OFF but we received a MIC'd packet.
1449 if (memcmp ((u8*)eth + 14, micsnap, sizeof(micsnap)) == 0) {
1450 ai->micstats.rxMICPlummed++;
1451 return ERROR;
1453 return SUCCESS;
1456 if (ntohs(mic->typelen) == 0x888E)
1457 return SUCCESS;
1459 if (memcmp (mic->u.snap, micsnap, sizeof(micsnap)) != 0) {
1460 // Mic enabled but packet isn't Mic'd
1461 ai->micstats.rxMICPlummed++;
1462 return ERROR;
1465 micSEQ = ntohl(mic->seq); //store SEQ as CPU order
1467 //At this point we a have a mic'd packet and mic is enabled
1468 //Now do the mic error checking.
1470 //Receive seq must be odd
1471 if ( (micSEQ & 1) == 0 ) {
1472 ai->micstats.rxWrongSequence++;
1473 return ERROR;
1476 for (i = 0; i < NUM_MODULES; i++) {
1477 int mcast = eth->da[0] & 1;
1478 //Determine proper context
1479 context = mcast ? &ai->mod[i].mCtx : &ai->mod[i].uCtx;
1481 //Make sure context is valid
1482 if (!context->valid) {
1483 if (i == 0)
1484 micError = NOMICPLUMMED;
1485 continue;
1487 //DeMic it
1489 if (!mic->typelen)
1490 mic->typelen = htons(payLen + sizeof(MICBuffer) - 2);
1492 emmh32_init(&context->seed);
1493 emmh32_update(&context->seed, eth->da, ETH_ALEN*2);
1494 emmh32_update(&context->seed, (u8 *)&mic->typelen, sizeof(mic->typelen)+sizeof(mic->u.snap));
1495 emmh32_update(&context->seed, (u8 *)&mic->seq,sizeof(mic->seq));
1496 emmh32_update(&context->seed, eth->da + ETH_ALEN*2,payLen);
1497 //Calculate MIC
1498 emmh32_final(&context->seed, digest);
1500 if (memcmp(digest, &mic->mic, 4)) { //Make sure the mics match
1501 //Invalid Mic
1502 if (i == 0)
1503 micError = INCORRECTMIC;
1504 continue;
1507 //Check Sequence number if mics pass
1508 if (RxSeqValid(ai, context, mcast, micSEQ) == SUCCESS) {
1509 ai->micstats.rxSuccess++;
1510 return SUCCESS;
1512 if (i == 0)
1513 micError = SEQUENCE;
1516 // Update statistics
1517 switch (micError) {
1518 case NOMICPLUMMED: ai->micstats.rxMICPlummed++; break;
1519 case SEQUENCE: ai->micstats.rxWrongSequence++; break;
1520 case INCORRECTMIC: ai->micstats.rxIncorrectMIC++; break;
1521 case NONE: break;
1522 case NOMIC: break;
1524 return ERROR;
1527 /*===========================================================================
1528 * Description: Checks the Rx Seq number to make sure it is valid
1529 * and hasn't already been received
1531 * Inputs: miccntx - mic context to check seq against
1532 * micSeq - the Mic seq number
1534 * Returns: TRUE if valid otherwise FALSE.
1536 * Author: sbraneky (10/15/01)
1537 * Merciless hacks by rwilcher (1/14/02)
1538 *---------------------------------------------------------------------------
1541 static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq)
1543 u32 seq,index;
1545 //Allow for the ap being rebooted - if it is then use the next
1546 //sequence number of the current sequence number - might go backwards
1548 if (mcast) {
1549 if (test_bit(FLAG_UPDATE_MULTI, &ai->flags)) {
1550 clear_bit (FLAG_UPDATE_MULTI, &ai->flags);
1551 context->window = (micSeq > 33) ? micSeq : 33;
1552 context->rx = 0; // Reset rx
1554 } else if (test_bit(FLAG_UPDATE_UNI, &ai->flags)) {
1555 clear_bit (FLAG_UPDATE_UNI, &ai->flags);
1556 context->window = (micSeq > 33) ? micSeq : 33; // Move window
1557 context->rx = 0; // Reset rx
1560 //Make sequence number relative to START of window
1561 seq = micSeq - (context->window - 33);
1563 //Too old of a SEQ number to check.
1564 if ((s32)seq < 0)
1565 return ERROR;
1567 if ( seq > 64 ) {
1568 //Window is infinite forward
1569 MoveWindow(context,micSeq);
1570 return SUCCESS;
1573 // We are in the window. Now check the context rx bit to see if it was already sent
1574 seq >>= 1; //divide by 2 because we only have odd numbers
1575 index = 1 << seq; //Get an index number
1577 if (!(context->rx & index)) {
1578 //micSEQ falls inside the window.
1579 //Add seqence number to the list of received numbers.
1580 context->rx |= index;
1582 MoveWindow(context,micSeq);
1584 return SUCCESS;
1586 return ERROR;
1589 static void MoveWindow(miccntx *context, u32 micSeq)
1591 u32 shift;
1593 //Move window if seq greater than the middle of the window
1594 if (micSeq > context->window) {
1595 shift = (micSeq - context->window) >> 1;
1597 //Shift out old
1598 if (shift < 32)
1599 context->rx >>= shift;
1600 else
1601 context->rx = 0;
1603 context->window = micSeq; //Move window
1607 /*==============================================*/
1608 /*========== EMMH ROUTINES ====================*/
1609 /*==============================================*/
1611 /* mic accumulate */
1612 #define MIC_ACCUM(val) \
1613 context->accum += (u64)(val) * context->coeff[coeff_position++];
1615 static unsigned char aes_counter[16];
1617 /* expand the key to fill the MMH coefficient array */
1618 static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
1619 struct crypto_cipher *tfm)
1621 /* take the keying material, expand if necessary, truncate at 16-bytes */
1622 /* run through AES counter mode to generate context->coeff[] */
1624 int i,j;
1625 u32 counter;
1626 u8 *cipher, plain[16];
1628 crypto_cipher_setkey(tfm, pkey, 16);
1629 counter = 0;
1630 for (i = 0; i < ARRAY_SIZE(context->coeff); ) {
1631 aes_counter[15] = (u8)(counter >> 0);
1632 aes_counter[14] = (u8)(counter >> 8);
1633 aes_counter[13] = (u8)(counter >> 16);
1634 aes_counter[12] = (u8)(counter >> 24);
1635 counter++;
1636 memcpy (plain, aes_counter, 16);
1637 crypto_cipher_encrypt_one(tfm, plain, plain);
1638 cipher = plain;
1639 for (j = 0; (j < 16) && (i < ARRAY_SIZE(context->coeff)); ) {
1640 context->coeff[i++] = ntohl(*(__be32 *)&cipher[j]);
1641 j += 4;
1646 /* prepare for calculation of a new mic */
1647 static void emmh32_init(emmh32_context *context)
1649 /* prepare for new mic calculation */
1650 context->accum = 0;
1651 context->position = 0;
1654 /* add some bytes to the mic calculation */
1655 static void emmh32_update(emmh32_context *context, u8 *pOctets, int len)
1657 int coeff_position, byte_position;
1659 if (len == 0) return;
1661 coeff_position = context->position >> 2;
1663 /* deal with partial 32-bit word left over from last update */
1664 byte_position = context->position & 3;
1665 if (byte_position) {
1666 /* have a partial word in part to deal with */
1667 do {
1668 if (len == 0) return;
1669 context->part.d8[byte_position++] = *pOctets++;
1670 context->position++;
1671 len--;
1672 } while (byte_position < 4);
1673 MIC_ACCUM(ntohl(context->part.d32));
1676 /* deal with full 32-bit words */
1677 while (len >= 4) {
1678 MIC_ACCUM(ntohl(*(__be32 *)pOctets));
1679 context->position += 4;
1680 pOctets += 4;
1681 len -= 4;
1684 /* deal with partial 32-bit word that will be left over from this update */
1685 byte_position = 0;
1686 while (len > 0) {
1687 context->part.d8[byte_position++] = *pOctets++;
1688 context->position++;
1689 len--;
1693 /* mask used to zero empty bytes for final partial word */
1694 static u32 mask32[4] = { 0x00000000L, 0xFF000000L, 0xFFFF0000L, 0xFFFFFF00L };
1696 /* calculate the mic */
1697 static void emmh32_final(emmh32_context *context, u8 digest[4])
1699 int coeff_position, byte_position;
1700 u32 val;
1702 u64 sum, utmp;
1703 s64 stmp;
1705 coeff_position = context->position >> 2;
1707 /* deal with partial 32-bit word left over from last update */
1708 byte_position = context->position & 3;
1709 if (byte_position) {
1710 /* have a partial word in part to deal with */
1711 val = ntohl(context->part.d32);
1712 MIC_ACCUM(val & mask32[byte_position]); /* zero empty bytes */
1715 /* reduce the accumulated u64 to a 32-bit MIC */
1716 sum = context->accum;
1717 stmp = (sum & 0xffffffffLL) - ((sum >> 32) * 15);
1718 utmp = (stmp & 0xffffffffLL) - ((stmp >> 32) * 15);
1719 sum = utmp & 0xffffffffLL;
1720 if (utmp > 0x10000000fLL)
1721 sum -= 15;
1723 val = (u32)sum;
1724 digest[0] = (val>>24) & 0xFF;
1725 digest[1] = (val>>16) & 0xFF;
1726 digest[2] = (val>>8) & 0xFF;
1727 digest[3] = val & 0xFF;
1730 static int readBSSListRid(struct airo_info *ai, int first,
1731 BSSListRid *list)
1733 Cmd cmd;
1734 Resp rsp;
1736 if (first == 1) {
1737 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
1738 memset(&cmd, 0, sizeof(cmd));
1739 cmd.cmd=CMD_LISTBSS;
1740 if (down_interruptible(&ai->sem))
1741 return -ERESTARTSYS;
1742 ai->list_bss_task = current;
1743 issuecommand(ai, &cmd, &rsp);
1744 up(&ai->sem);
1745 /* Let the command take effect */
1746 schedule_timeout_uninterruptible(3 * HZ);
1747 ai->list_bss_task = NULL;
1749 return PC4500_readrid(ai, first ? ai->bssListFirst : ai->bssListNext,
1750 list, ai->bssListRidLen, 1);
1753 static int readWepKeyRid(struct airo_info *ai, WepKeyRid *wkr, int temp, int lock)
1755 return PC4500_readrid(ai, temp ? RID_WEP_TEMP : RID_WEP_PERM,
1756 wkr, sizeof(*wkr), lock);
1759 static int writeWepKeyRid(struct airo_info *ai, WepKeyRid *wkr, int perm, int lock)
1761 int rc;
1762 rc = PC4500_writerid(ai, RID_WEP_TEMP, wkr, sizeof(*wkr), lock);
1763 if (rc!=SUCCESS)
1764 airo_print_err(ai->dev->name, "WEP_TEMP set %x", rc);
1765 if (perm) {
1766 rc = PC4500_writerid(ai, RID_WEP_PERM, wkr, sizeof(*wkr), lock);
1767 if (rc!=SUCCESS)
1768 airo_print_err(ai->dev->name, "WEP_PERM set %x", rc);
1770 return rc;
1773 static int readSsidRid(struct airo_info*ai, SsidRid *ssidr)
1775 return PC4500_readrid(ai, RID_SSID, ssidr, sizeof(*ssidr), 1);
1778 static int writeSsidRid(struct airo_info*ai, SsidRid *pssidr, int lock)
1780 return PC4500_writerid(ai, RID_SSID, pssidr, sizeof(*pssidr), lock);
1783 static int readConfigRid(struct airo_info *ai, int lock)
1785 int rc;
1786 ConfigRid cfg;
1788 if (ai->config.len)
1789 return SUCCESS;
1791 rc = PC4500_readrid(ai, RID_ACTUALCONFIG, &cfg, sizeof(cfg), lock);
1792 if (rc != SUCCESS)
1793 return rc;
1795 ai->config = cfg;
1796 return SUCCESS;
1799 static inline void checkThrottle(struct airo_info *ai)
1801 int i;
1802 /* Old hardware had a limit on encryption speed */
1803 if (ai->config.authType != AUTH_OPEN && maxencrypt) {
1804 for(i=0; i<8; i++) {
1805 if (ai->config.rates[i] > maxencrypt) {
1806 ai->config.rates[i] = 0;
1812 static int writeConfigRid(struct airo_info *ai, int lock)
1814 ConfigRid cfgr;
1816 if (!test_bit (FLAG_COMMIT, &ai->flags))
1817 return SUCCESS;
1819 clear_bit (FLAG_COMMIT, &ai->flags);
1820 clear_bit (FLAG_RESET, &ai->flags);
1821 checkThrottle(ai);
1822 cfgr = ai->config;
1824 if ((cfgr.opmode & MODE_CFG_MASK) == MODE_STA_IBSS)
1825 set_bit(FLAG_ADHOC, &ai->flags);
1826 else
1827 clear_bit(FLAG_ADHOC, &ai->flags);
1829 return PC4500_writerid( ai, RID_CONFIG, &cfgr, sizeof(cfgr), lock);
1832 static int readStatusRid(struct airo_info *ai, StatusRid *statr, int lock)
1834 return PC4500_readrid(ai, RID_STATUS, statr, sizeof(*statr), lock);
1837 static int readAPListRid(struct airo_info *ai, APListRid *aplr)
1839 return PC4500_readrid(ai, RID_APLIST, aplr, sizeof(*aplr), 1);
1842 static int writeAPListRid(struct airo_info *ai, APListRid *aplr, int lock)
1844 return PC4500_writerid(ai, RID_APLIST, aplr, sizeof(*aplr), lock);
1847 static int readCapabilityRid(struct airo_info *ai, CapabilityRid *capr, int lock)
1849 return PC4500_readrid(ai, RID_CAPABILITIES, capr, sizeof(*capr), lock);
1852 static int readStatsRid(struct airo_info*ai, StatsRid *sr, int rid, int lock)
1854 return PC4500_readrid(ai, rid, sr, sizeof(*sr), lock);
1857 static void try_auto_wep(struct airo_info *ai)
1859 if (auto_wep && !(ai->flags & FLAG_RADIO_DOWN)) {
1860 ai->expires = RUN_AT(3*HZ);
1861 wake_up_interruptible(&ai->thr_wait);
1865 static int airo_open(struct net_device *dev) {
1866 struct airo_info *ai = dev->ml_priv;
1867 int rc = 0;
1869 if (test_bit(FLAG_FLASHING, &ai->flags))
1870 return -EIO;
1872 /* Make sure the card is configured.
1873 * Wireless Extensions may postpone config changes until the card
1874 * is open (to pipeline changes and speed-up card setup). If
1875 * those changes are not yet commited, do it now - Jean II */
1876 if (test_bit(FLAG_COMMIT, &ai->flags)) {
1877 disable_MAC(ai, 1);
1878 writeConfigRid(ai, 1);
1881 if (ai->wifidev != dev) {
1882 clear_bit(JOB_DIE, &ai->jobs);
1883 ai->airo_thread_task = kthread_run(airo_thread, dev, dev->name);
1884 if (IS_ERR(ai->airo_thread_task))
1885 return (int)PTR_ERR(ai->airo_thread_task);
1887 rc = request_irq(dev->irq, airo_interrupt, IRQF_SHARED,
1888 dev->name, dev);
1889 if (rc) {
1890 airo_print_err(dev->name,
1891 "register interrupt %d failed, rc %d",
1892 dev->irq, rc);
1893 set_bit(JOB_DIE, &ai->jobs);
1894 kthread_stop(ai->airo_thread_task);
1895 return rc;
1898 /* Power on the MAC controller (which may have been disabled) */
1899 clear_bit(FLAG_RADIO_DOWN, &ai->flags);
1900 enable_interrupts(ai);
1902 try_auto_wep(ai);
1904 enable_MAC(ai, 1);
1906 netif_start_queue(dev);
1907 return 0;
1910 static int mpi_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1911 int npacks, pending;
1912 unsigned long flags;
1913 struct airo_info *ai = dev->ml_priv;
1915 if (!skb) {
1916 airo_print_err(dev->name, "%s: skb == NULL!",__func__);
1917 return 0;
1919 npacks = skb_queue_len (&ai->txq);
1921 if (npacks >= MAXTXQ - 1) {
1922 netif_stop_queue (dev);
1923 if (npacks > MAXTXQ) {
1924 dev->stats.tx_fifo_errors++;
1925 return 1;
1927 skb_queue_tail (&ai->txq, skb);
1928 return 0;
1931 spin_lock_irqsave(&ai->aux_lock, flags);
1932 skb_queue_tail (&ai->txq, skb);
1933 pending = test_bit(FLAG_PENDING_XMIT, &ai->flags);
1934 spin_unlock_irqrestore(&ai->aux_lock,flags);
1935 netif_wake_queue (dev);
1937 if (pending == 0) {
1938 set_bit(FLAG_PENDING_XMIT, &ai->flags);
1939 mpi_send_packet (dev);
1941 return 0;
1945 * @mpi_send_packet
1947 * Attempt to transmit a packet. Can be called from interrupt
1948 * or transmit . return number of packets we tried to send
1951 static int mpi_send_packet (struct net_device *dev)
1953 struct sk_buff *skb;
1954 unsigned char *buffer;
1955 s16 len;
1956 __le16 *payloadLen;
1957 struct airo_info *ai = dev->ml_priv;
1958 u8 *sendbuf;
1960 /* get a packet to send */
1962 if ((skb = skb_dequeue(&ai->txq)) == NULL) {
1963 airo_print_err(dev->name,
1964 "%s: Dequeue'd zero in send_packet()",
1965 __func__);
1966 return 0;
1969 /* check min length*/
1970 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1971 buffer = skb->data;
1973 ai->txfids[0].tx_desc.offset = 0;
1974 ai->txfids[0].tx_desc.valid = 1;
1975 ai->txfids[0].tx_desc.eoc = 1;
1976 ai->txfids[0].tx_desc.len =len+sizeof(WifiHdr);
1979 * Magic, the cards firmware needs a length count (2 bytes) in the host buffer
1980 * right after TXFID_HDR.The TXFID_HDR contains the status short so payloadlen
1981 * is immediatly after it. ------------------------------------------------
1982 * |TXFIDHDR+STATUS|PAYLOADLEN|802.3HDR|PACKETDATA|
1983 * ------------------------------------------------
1986 memcpy((char *)ai->txfids[0].virtual_host_addr,
1987 (char *)&wifictlhdr8023, sizeof(wifictlhdr8023));
1989 payloadLen = (__le16 *)(ai->txfids[0].virtual_host_addr +
1990 sizeof(wifictlhdr8023));
1991 sendbuf = ai->txfids[0].virtual_host_addr +
1992 sizeof(wifictlhdr8023) + 2 ;
1995 * Firmware automaticly puts 802 header on so
1996 * we don't need to account for it in the length
1998 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
1999 (ntohs(((__be16 *)buffer)[6]) != 0x888E)) {
2000 MICBuffer pMic;
2002 if (encapsulate(ai, (etherHead *)buffer, &pMic, len - sizeof(etherHead)) != SUCCESS)
2003 return ERROR;
2005 *payloadLen = cpu_to_le16(len-sizeof(etherHead)+sizeof(pMic));
2006 ai->txfids[0].tx_desc.len += sizeof(pMic);
2007 /* copy data into airo dma buffer */
2008 memcpy (sendbuf, buffer, sizeof(etherHead));
2009 buffer += sizeof(etherHead);
2010 sendbuf += sizeof(etherHead);
2011 memcpy (sendbuf, &pMic, sizeof(pMic));
2012 sendbuf += sizeof(pMic);
2013 memcpy (sendbuf, buffer, len - sizeof(etherHead));
2014 } else {
2015 *payloadLen = cpu_to_le16(len - sizeof(etherHead));
2017 dev->trans_start = jiffies;
2019 /* copy data into airo dma buffer */
2020 memcpy(sendbuf, buffer, len);
2023 memcpy_toio(ai->txfids[0].card_ram_off,
2024 &ai->txfids[0].tx_desc, sizeof(TxFid));
2026 OUT4500(ai, EVACK, 8);
2028 dev_kfree_skb_any(skb);
2029 return 1;
2032 static void get_tx_error(struct airo_info *ai, s32 fid)
2034 __le16 status;
2036 if (fid < 0)
2037 status = ((WifiCtlHdr *)ai->txfids[0].virtual_host_addr)->ctlhdr.status;
2038 else {
2039 if (bap_setup(ai, ai->fids[fid] & 0xffff, 4, BAP0) != SUCCESS)
2040 return;
2041 bap_read(ai, &status, 2, BAP0);
2043 if (le16_to_cpu(status) & 2) /* Too many retries */
2044 ai->dev->stats.tx_aborted_errors++;
2045 if (le16_to_cpu(status) & 4) /* Transmit lifetime exceeded */
2046 ai->dev->stats.tx_heartbeat_errors++;
2047 if (le16_to_cpu(status) & 8) /* Aid fail */
2049 if (le16_to_cpu(status) & 0x10) /* MAC disabled */
2050 ai->dev->stats.tx_carrier_errors++;
2051 if (le16_to_cpu(status) & 0x20) /* Association lost */
2053 /* We produce a TXDROP event only for retry or lifetime
2054 * exceeded, because that's the only status that really mean
2055 * that this particular node went away.
2056 * Other errors means that *we* screwed up. - Jean II */
2057 if ((le16_to_cpu(status) & 2) ||
2058 (le16_to_cpu(status) & 4)) {
2059 union iwreq_data wrqu;
2060 char junk[0x18];
2062 /* Faster to skip over useless data than to do
2063 * another bap_setup(). We are at offset 0x6 and
2064 * need to go to 0x18 and read 6 bytes - Jean II */
2065 bap_read(ai, (__le16 *) junk, 0x18, BAP0);
2067 /* Copy 802.11 dest address.
2068 * We use the 802.11 header because the frame may
2069 * not be 802.3 or may be mangled...
2070 * In Ad-Hoc mode, it will be the node address.
2071 * In managed mode, it will be most likely the AP addr
2072 * User space will figure out how to convert it to
2073 * whatever it needs (IP address or else).
2074 * - Jean II */
2075 memcpy(wrqu.addr.sa_data, junk + 0x12, ETH_ALEN);
2076 wrqu.addr.sa_family = ARPHRD_ETHER;
2078 /* Send event to user space */
2079 wireless_send_event(ai->dev, IWEVTXDROP, &wrqu, NULL);
2083 static void airo_end_xmit(struct net_device *dev) {
2084 u16 status;
2085 int i;
2086 struct airo_info *priv = dev->ml_priv;
2087 struct sk_buff *skb = priv->xmit.skb;
2088 int fid = priv->xmit.fid;
2089 u32 *fids = priv->fids;
2091 clear_bit(JOB_XMIT, &priv->jobs);
2092 clear_bit(FLAG_PENDING_XMIT, &priv->flags);
2093 status = transmit_802_3_packet (priv, fids[fid], skb->data);
2094 up(&priv->sem);
2096 i = 0;
2097 if ( status == SUCCESS ) {
2098 dev->trans_start = jiffies;
2099 for (; i < MAX_FIDS / 2 && (priv->fids[i] & 0xffff0000); i++);
2100 } else {
2101 priv->fids[fid] &= 0xffff;
2102 dev->stats.tx_window_errors++;
2104 if (i < MAX_FIDS / 2)
2105 netif_wake_queue(dev);
2106 dev_kfree_skb(skb);
2109 static int airo_start_xmit(struct sk_buff *skb, struct net_device *dev) {
2110 s16 len;
2111 int i, j;
2112 struct airo_info *priv = dev->ml_priv;
2113 u32 *fids = priv->fids;
2115 if ( skb == NULL ) {
2116 airo_print_err(dev->name, "%s: skb == NULL!", __func__);
2117 return 0;
2120 /* Find a vacant FID */
2121 for( i = 0; i < MAX_FIDS / 2 && (fids[i] & 0xffff0000); i++ );
2122 for( j = i + 1; j < MAX_FIDS / 2 && (fids[j] & 0xffff0000); j++ );
2124 if ( j >= MAX_FIDS / 2 ) {
2125 netif_stop_queue(dev);
2127 if (i == MAX_FIDS / 2) {
2128 dev->stats.tx_fifo_errors++;
2129 return 1;
2132 /* check min length*/
2133 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
2134 /* Mark fid as used & save length for later */
2135 fids[i] |= (len << 16);
2136 priv->xmit.skb = skb;
2137 priv->xmit.fid = i;
2138 if (down_trylock(&priv->sem) != 0) {
2139 set_bit(FLAG_PENDING_XMIT, &priv->flags);
2140 netif_stop_queue(dev);
2141 set_bit(JOB_XMIT, &priv->jobs);
2142 wake_up_interruptible(&priv->thr_wait);
2143 } else
2144 airo_end_xmit(dev);
2145 return 0;
2148 static void airo_end_xmit11(struct net_device *dev) {
2149 u16 status;
2150 int i;
2151 struct airo_info *priv = dev->ml_priv;
2152 struct sk_buff *skb = priv->xmit11.skb;
2153 int fid = priv->xmit11.fid;
2154 u32 *fids = priv->fids;
2156 clear_bit(JOB_XMIT11, &priv->jobs);
2157 clear_bit(FLAG_PENDING_XMIT11, &priv->flags);
2158 status = transmit_802_11_packet (priv, fids[fid], skb->data);
2159 up(&priv->sem);
2161 i = MAX_FIDS / 2;
2162 if ( status == SUCCESS ) {
2163 dev->trans_start = jiffies;
2164 for (; i < MAX_FIDS && (priv->fids[i] & 0xffff0000); i++);
2165 } else {
2166 priv->fids[fid] &= 0xffff;
2167 dev->stats.tx_window_errors++;
2169 if (i < MAX_FIDS)
2170 netif_wake_queue(dev);
2171 dev_kfree_skb(skb);
2174 static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) {
2175 s16 len;
2176 int i, j;
2177 struct airo_info *priv = dev->ml_priv;
2178 u32 *fids = priv->fids;
2180 if (test_bit(FLAG_MPI, &priv->flags)) {
2181 /* Not implemented yet for MPI350 */
2182 netif_stop_queue(dev);
2183 return -ENETDOWN;
2186 if ( skb == NULL ) {
2187 airo_print_err(dev->name, "%s: skb == NULL!", __func__);
2188 return 0;
2191 /* Find a vacant FID */
2192 for( i = MAX_FIDS / 2; i < MAX_FIDS && (fids[i] & 0xffff0000); i++ );
2193 for( j = i + 1; j < MAX_FIDS && (fids[j] & 0xffff0000); j++ );
2195 if ( j >= MAX_FIDS ) {
2196 netif_stop_queue(dev);
2198 if (i == MAX_FIDS) {
2199 dev->stats.tx_fifo_errors++;
2200 return 1;
2203 /* check min length*/
2204 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
2205 /* Mark fid as used & save length for later */
2206 fids[i] |= (len << 16);
2207 priv->xmit11.skb = skb;
2208 priv->xmit11.fid = i;
2209 if (down_trylock(&priv->sem) != 0) {
2210 set_bit(FLAG_PENDING_XMIT11, &priv->flags);
2211 netif_stop_queue(dev);
2212 set_bit(JOB_XMIT11, &priv->jobs);
2213 wake_up_interruptible(&priv->thr_wait);
2214 } else
2215 airo_end_xmit11(dev);
2216 return 0;
2219 static void airo_read_stats(struct net_device *dev)
2221 struct airo_info *ai = dev->ml_priv;
2222 StatsRid stats_rid;
2223 __le32 *vals = stats_rid.vals;
2225 clear_bit(JOB_STATS, &ai->jobs);
2226 if (ai->power.event) {
2227 up(&ai->sem);
2228 return;
2230 readStatsRid(ai, &stats_rid, RID_STATS, 0);
2231 up(&ai->sem);
2233 dev->stats.rx_packets = le32_to_cpu(vals[43]) + le32_to_cpu(vals[44]) +
2234 le32_to_cpu(vals[45]);
2235 dev->stats.tx_packets = le32_to_cpu(vals[39]) + le32_to_cpu(vals[40]) +
2236 le32_to_cpu(vals[41]);
2237 dev->stats.rx_bytes = le32_to_cpu(vals[92]);
2238 dev->stats.tx_bytes = le32_to_cpu(vals[91]);
2239 dev->stats.rx_errors = le32_to_cpu(vals[0]) + le32_to_cpu(vals[2]) +
2240 le32_to_cpu(vals[3]) + le32_to_cpu(vals[4]);
2241 dev->stats.tx_errors = le32_to_cpu(vals[42]) +
2242 dev->stats.tx_fifo_errors;
2243 dev->stats.multicast = le32_to_cpu(vals[43]);
2244 dev->stats.collisions = le32_to_cpu(vals[89]);
2246 /* detailed rx_errors: */
2247 dev->stats.rx_length_errors = le32_to_cpu(vals[3]);
2248 dev->stats.rx_crc_errors = le32_to_cpu(vals[4]);
2249 dev->stats.rx_frame_errors = le32_to_cpu(vals[2]);
2250 dev->stats.rx_fifo_errors = le32_to_cpu(vals[0]);
2253 static struct net_device_stats *airo_get_stats(struct net_device *dev)
2255 struct airo_info *local = dev->ml_priv;
2257 if (!test_bit(JOB_STATS, &local->jobs)) {
2258 /* Get stats out of the card if available */
2259 if (down_trylock(&local->sem) != 0) {
2260 set_bit(JOB_STATS, &local->jobs);
2261 wake_up_interruptible(&local->thr_wait);
2262 } else
2263 airo_read_stats(dev);
2266 return &dev->stats;
2269 static void airo_set_promisc(struct airo_info *ai) {
2270 Cmd cmd;
2271 Resp rsp;
2273 memset(&cmd, 0, sizeof(cmd));
2274 cmd.cmd=CMD_SETMODE;
2275 clear_bit(JOB_PROMISC, &ai->jobs);
2276 cmd.parm0=(ai->flags&IFF_PROMISC) ? PROMISC : NOPROMISC;
2277 issuecommand(ai, &cmd, &rsp);
2278 up(&ai->sem);
2281 static void airo_set_multicast_list(struct net_device *dev) {
2282 struct airo_info *ai = dev->ml_priv;
2284 if ((dev->flags ^ ai->flags) & IFF_PROMISC) {
2285 change_bit(FLAG_PROMISC, &ai->flags);
2286 if (down_trylock(&ai->sem) != 0) {
2287 set_bit(JOB_PROMISC, &ai->jobs);
2288 wake_up_interruptible(&ai->thr_wait);
2289 } else
2290 airo_set_promisc(ai);
2293 if ((dev->flags&IFF_ALLMULTI)||dev->mc_count>0) {
2294 /* Turn on multicast. (Should be already setup...) */
2298 static int airo_set_mac_address(struct net_device *dev, void *p)
2300 struct airo_info *ai = dev->ml_priv;
2301 struct sockaddr *addr = p;
2303 readConfigRid(ai, 1);
2304 memcpy (ai->config.macAddr, addr->sa_data, dev->addr_len);
2305 set_bit (FLAG_COMMIT, &ai->flags);
2306 disable_MAC(ai, 1);
2307 writeConfigRid (ai, 1);
2308 enable_MAC(ai, 1);
2309 memcpy (ai->dev->dev_addr, addr->sa_data, dev->addr_len);
2310 if (ai->wifidev)
2311 memcpy (ai->wifidev->dev_addr, addr->sa_data, dev->addr_len);
2312 return 0;
2315 static int airo_change_mtu(struct net_device *dev, int new_mtu)
2317 if ((new_mtu < 68) || (new_mtu > 2400))
2318 return -EINVAL;
2319 dev->mtu = new_mtu;
2320 return 0;
2323 static LIST_HEAD(airo_devices);
2325 static void add_airo_dev(struct airo_info *ai)
2327 /* Upper layers already keep track of PCI devices,
2328 * so we only need to remember our non-PCI cards. */
2329 if (!ai->pci)
2330 list_add_tail(&ai->dev_list, &airo_devices);
2333 static void del_airo_dev(struct airo_info *ai)
2335 if (!ai->pci)
2336 list_del(&ai->dev_list);
2339 static int airo_close(struct net_device *dev) {
2340 struct airo_info *ai = dev->ml_priv;
2342 netif_stop_queue(dev);
2344 if (ai->wifidev != dev) {
2345 #ifdef POWER_ON_DOWN
2346 /* Shut power to the card. The idea is that the user can save
2347 * power when he doesn't need the card with "ifconfig down".
2348 * That's the method that is most friendly towards the network
2349 * stack (i.e. the network stack won't try to broadcast
2350 * anything on the interface and routes are gone. Jean II */
2351 set_bit(FLAG_RADIO_DOWN, &ai->flags);
2352 disable_MAC(ai, 1);
2353 #endif
2354 disable_interrupts( ai );
2356 free_irq(dev->irq, dev);
2358 set_bit(JOB_DIE, &ai->jobs);
2359 kthread_stop(ai->airo_thread_task);
2361 return 0;
2364 void stop_airo_card( struct net_device *dev, int freeres )
2366 struct airo_info *ai = dev->ml_priv;
2368 set_bit(FLAG_RADIO_DOWN, &ai->flags);
2369 disable_MAC(ai, 1);
2370 disable_interrupts(ai);
2371 takedown_proc_entry( dev, ai );
2372 if (test_bit(FLAG_REGISTERED, &ai->flags)) {
2373 unregister_netdev( dev );
2374 if (ai->wifidev) {
2375 unregister_netdev(ai->wifidev);
2376 free_netdev(ai->wifidev);
2377 ai->wifidev = NULL;
2379 clear_bit(FLAG_REGISTERED, &ai->flags);
2382 * Clean out tx queue
2384 if (test_bit(FLAG_MPI, &ai->flags) && !skb_queue_empty(&ai->txq)) {
2385 struct sk_buff *skb = NULL;
2386 for (;(skb = skb_dequeue(&ai->txq));)
2387 dev_kfree_skb(skb);
2390 airo_networks_free (ai);
2392 kfree(ai->flash);
2393 kfree(ai->rssi);
2394 kfree(ai->APList);
2395 kfree(ai->SSID);
2396 if (freeres) {
2397 /* PCMCIA frees this stuff, so only for PCI and ISA */
2398 release_region( dev->base_addr, 64 );
2399 if (test_bit(FLAG_MPI, &ai->flags)) {
2400 if (ai->pci)
2401 mpi_unmap_card(ai->pci);
2402 if (ai->pcimem)
2403 iounmap(ai->pcimem);
2404 if (ai->pciaux)
2405 iounmap(ai->pciaux);
2406 pci_free_consistent(ai->pci, PCI_SHARED_LEN,
2407 ai->shared, ai->shared_dma);
2410 crypto_free_cipher(ai->tfm);
2411 del_airo_dev(ai);
2412 free_netdev( dev );
2415 EXPORT_SYMBOL(stop_airo_card);
2417 static int wll_header_parse(const struct sk_buff *skb, unsigned char *haddr)
2419 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN);
2420 return ETH_ALEN;
2423 static void mpi_unmap_card(struct pci_dev *pci)
2425 unsigned long mem_start = pci_resource_start(pci, 1);
2426 unsigned long mem_len = pci_resource_len(pci, 1);
2427 unsigned long aux_start = pci_resource_start(pci, 2);
2428 unsigned long aux_len = AUXMEMSIZE;
2430 release_mem_region(aux_start, aux_len);
2431 release_mem_region(mem_start, mem_len);
2434 /*************************************************************
2435 * This routine assumes that descriptors have been setup .
2436 * Run at insmod time or after reset when the decriptors
2437 * have been initialized . Returns 0 if all is well nz
2438 * otherwise . Does not allocate memory but sets up card
2439 * using previously allocated descriptors.
2441 static int mpi_init_descriptors (struct airo_info *ai)
2443 Cmd cmd;
2444 Resp rsp;
2445 int i;
2446 int rc = SUCCESS;
2448 /* Alloc card RX descriptors */
2449 netif_stop_queue(ai->dev);
2451 memset(&rsp,0,sizeof(rsp));
2452 memset(&cmd,0,sizeof(cmd));
2454 cmd.cmd = CMD_ALLOCATEAUX;
2455 cmd.parm0 = FID_RX;
2456 cmd.parm1 = (ai->rxfids[0].card_ram_off - ai->pciaux);
2457 cmd.parm2 = MPI_MAX_FIDS;
2458 rc=issuecommand(ai, &cmd, &rsp);
2459 if (rc != SUCCESS) {
2460 airo_print_err(ai->dev->name, "Couldn't allocate RX FID");
2461 return rc;
2464 for (i=0; i<MPI_MAX_FIDS; i++) {
2465 memcpy_toio(ai->rxfids[i].card_ram_off,
2466 &ai->rxfids[i].rx_desc, sizeof(RxFid));
2469 /* Alloc card TX descriptors */
2471 memset(&rsp,0,sizeof(rsp));
2472 memset(&cmd,0,sizeof(cmd));
2474 cmd.cmd = CMD_ALLOCATEAUX;
2475 cmd.parm0 = FID_TX;
2476 cmd.parm1 = (ai->txfids[0].card_ram_off - ai->pciaux);
2477 cmd.parm2 = MPI_MAX_FIDS;
2479 for (i=0; i<MPI_MAX_FIDS; i++) {
2480 ai->txfids[i].tx_desc.valid = 1;
2481 memcpy_toio(ai->txfids[i].card_ram_off,
2482 &ai->txfids[i].tx_desc, sizeof(TxFid));
2484 ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */
2486 rc=issuecommand(ai, &cmd, &rsp);
2487 if (rc != SUCCESS) {
2488 airo_print_err(ai->dev->name, "Couldn't allocate TX FID");
2489 return rc;
2492 /* Alloc card Rid descriptor */
2493 memset(&rsp,0,sizeof(rsp));
2494 memset(&cmd,0,sizeof(cmd));
2496 cmd.cmd = CMD_ALLOCATEAUX;
2497 cmd.parm0 = RID_RW;
2498 cmd.parm1 = (ai->config_desc.card_ram_off - ai->pciaux);
2499 cmd.parm2 = 1; /* Magic number... */
2500 rc=issuecommand(ai, &cmd, &rsp);
2501 if (rc != SUCCESS) {
2502 airo_print_err(ai->dev->name, "Couldn't allocate RID");
2503 return rc;
2506 memcpy_toio(ai->config_desc.card_ram_off,
2507 &ai->config_desc.rid_desc, sizeof(Rid));
2509 return rc;
2513 * We are setting up three things here:
2514 * 1) Map AUX memory for descriptors: Rid, TxFid, or RxFid.
2515 * 2) Map PCI memory for issueing commands.
2516 * 3) Allocate memory (shared) to send and receive ethernet frames.
2518 static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci)
2520 unsigned long mem_start, mem_len, aux_start, aux_len;
2521 int rc = -1;
2522 int i;
2523 dma_addr_t busaddroff;
2524 unsigned char *vpackoff;
2525 unsigned char __iomem *pciaddroff;
2527 mem_start = pci_resource_start(pci, 1);
2528 mem_len = pci_resource_len(pci, 1);
2529 aux_start = pci_resource_start(pci, 2);
2530 aux_len = AUXMEMSIZE;
2532 if (!request_mem_region(mem_start, mem_len, DRV_NAME)) {
2533 airo_print_err("", "Couldn't get region %x[%x]",
2534 (int)mem_start, (int)mem_len);
2535 goto out;
2537 if (!request_mem_region(aux_start, aux_len, DRV_NAME)) {
2538 airo_print_err("", "Couldn't get region %x[%x]",
2539 (int)aux_start, (int)aux_len);
2540 goto free_region1;
2543 ai->pcimem = ioremap(mem_start, mem_len);
2544 if (!ai->pcimem) {
2545 airo_print_err("", "Couldn't map region %x[%x]",
2546 (int)mem_start, (int)mem_len);
2547 goto free_region2;
2549 ai->pciaux = ioremap(aux_start, aux_len);
2550 if (!ai->pciaux) {
2551 airo_print_err("", "Couldn't map region %x[%x]",
2552 (int)aux_start, (int)aux_len);
2553 goto free_memmap;
2556 /* Reserve PKTSIZE for each fid and 2K for the Rids */
2557 ai->shared = pci_alloc_consistent(pci, PCI_SHARED_LEN, &ai->shared_dma);
2558 if (!ai->shared) {
2559 airo_print_err("", "Couldn't alloc_consistent %d",
2560 PCI_SHARED_LEN);
2561 goto free_auxmap;
2565 * Setup descriptor RX, TX, CONFIG
2567 busaddroff = ai->shared_dma;
2568 pciaddroff = ai->pciaux + AUX_OFFSET;
2569 vpackoff = ai->shared;
2571 /* RX descriptor setup */
2572 for(i = 0; i < MPI_MAX_FIDS; i++) {
2573 ai->rxfids[i].pending = 0;
2574 ai->rxfids[i].card_ram_off = pciaddroff;
2575 ai->rxfids[i].virtual_host_addr = vpackoff;
2576 ai->rxfids[i].rx_desc.host_addr = busaddroff;
2577 ai->rxfids[i].rx_desc.valid = 1;
2578 ai->rxfids[i].rx_desc.len = PKTSIZE;
2579 ai->rxfids[i].rx_desc.rdy = 0;
2581 pciaddroff += sizeof(RxFid);
2582 busaddroff += PKTSIZE;
2583 vpackoff += PKTSIZE;
2586 /* TX descriptor setup */
2587 for(i = 0; i < MPI_MAX_FIDS; i++) {
2588 ai->txfids[i].card_ram_off = pciaddroff;
2589 ai->txfids[i].virtual_host_addr = vpackoff;
2590 ai->txfids[i].tx_desc.valid = 1;
2591 ai->txfids[i].tx_desc.host_addr = busaddroff;
2592 memcpy(ai->txfids[i].virtual_host_addr,
2593 &wifictlhdr8023, sizeof(wifictlhdr8023));
2595 pciaddroff += sizeof(TxFid);
2596 busaddroff += PKTSIZE;
2597 vpackoff += PKTSIZE;
2599 ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */
2601 /* Rid descriptor setup */
2602 ai->config_desc.card_ram_off = pciaddroff;
2603 ai->config_desc.virtual_host_addr = vpackoff;
2604 ai->config_desc.rid_desc.host_addr = busaddroff;
2605 ai->ridbus = busaddroff;
2606 ai->config_desc.rid_desc.rid = 0;
2607 ai->config_desc.rid_desc.len = RIDSIZE;
2608 ai->config_desc.rid_desc.valid = 1;
2609 pciaddroff += sizeof(Rid);
2610 busaddroff += RIDSIZE;
2611 vpackoff += RIDSIZE;
2613 /* Tell card about descriptors */
2614 if (mpi_init_descriptors (ai) != SUCCESS)
2615 goto free_shared;
2617 return 0;
2618 free_shared:
2619 pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
2620 free_auxmap:
2621 iounmap(ai->pciaux);
2622 free_memmap:
2623 iounmap(ai->pcimem);
2624 free_region2:
2625 release_mem_region(aux_start, aux_len);
2626 free_region1:
2627 release_mem_region(mem_start, mem_len);
2628 out:
2629 return rc;
2632 static const struct header_ops airo_header_ops = {
2633 .parse = wll_header_parse,
2636 static void wifi_setup(struct net_device *dev)
2638 dev->header_ops = &airo_header_ops;
2639 dev->hard_start_xmit = &airo_start_xmit11;
2640 dev->get_stats = &airo_get_stats;
2641 dev->set_mac_address = &airo_set_mac_address;
2642 dev->do_ioctl = &airo_ioctl;
2643 dev->wireless_handlers = &airo_handler_def;
2644 dev->change_mtu = &airo_change_mtu;
2645 dev->open = &airo_open;
2646 dev->stop = &airo_close;
2648 dev->type = ARPHRD_IEEE80211;
2649 dev->hard_header_len = ETH_HLEN;
2650 dev->mtu = AIRO_DEF_MTU;
2651 dev->addr_len = ETH_ALEN;
2652 dev->tx_queue_len = 100;
2654 memset(dev->broadcast,0xFF, ETH_ALEN);
2656 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2659 static struct net_device *init_wifidev(struct airo_info *ai,
2660 struct net_device *ethdev)
2662 int err;
2663 struct net_device *dev = alloc_netdev(0, "wifi%d", wifi_setup);
2664 if (!dev)
2665 return NULL;
2666 dev->ml_priv = ethdev->ml_priv;
2667 dev->irq = ethdev->irq;
2668 dev->base_addr = ethdev->base_addr;
2669 dev->wireless_data = ethdev->wireless_data;
2670 SET_NETDEV_DEV(dev, ethdev->dev.parent);
2671 memcpy(dev->dev_addr, ethdev->dev_addr, dev->addr_len);
2672 err = register_netdev(dev);
2673 if (err<0) {
2674 free_netdev(dev);
2675 return NULL;
2677 return dev;
2680 static int reset_card( struct net_device *dev , int lock) {
2681 struct airo_info *ai = dev->ml_priv;
2683 if (lock && down_interruptible(&ai->sem))
2684 return -1;
2685 waitbusy (ai);
2686 OUT4500(ai,COMMAND,CMD_SOFTRESET);
2687 msleep(200);
2688 waitbusy (ai);
2689 msleep(200);
2690 if (lock)
2691 up(&ai->sem);
2692 return 0;
2695 #define AIRO_MAX_NETWORK_COUNT 64
2696 static int airo_networks_allocate(struct airo_info *ai)
2698 if (ai->networks)
2699 return 0;
2701 ai->networks =
2702 kzalloc(AIRO_MAX_NETWORK_COUNT * sizeof(BSSListElement),
2703 GFP_KERNEL);
2704 if (!ai->networks) {
2705 airo_print_warn("", "Out of memory allocating beacons");
2706 return -ENOMEM;
2709 return 0;
2712 static void airo_networks_free(struct airo_info *ai)
2714 kfree(ai->networks);
2715 ai->networks = NULL;
2718 static void airo_networks_initialize(struct airo_info *ai)
2720 int i;
2722 INIT_LIST_HEAD(&ai->network_free_list);
2723 INIT_LIST_HEAD(&ai->network_list);
2724 for (i = 0; i < AIRO_MAX_NETWORK_COUNT; i++)
2725 list_add_tail(&ai->networks[i].list,
2726 &ai->network_free_list);
2729 static int airo_test_wpa_capable(struct airo_info *ai)
2731 int status;
2732 CapabilityRid cap_rid;
2734 status = readCapabilityRid(ai, &cap_rid, 1);
2735 if (status != SUCCESS) return 0;
2737 /* Only firmware versions 5.30.17 or better can do WPA */
2738 if (le16_to_cpu(cap_rid.softVer) > 0x530
2739 || (le16_to_cpu(cap_rid.softVer) == 0x530
2740 && le16_to_cpu(cap_rid.softSubVer) >= 17)) {
2741 airo_print_info("", "WPA is supported.");
2742 return 1;
2745 /* No WPA support */
2746 airo_print_info("", "WPA unsupported (only firmware versions 5.30.17"
2747 " and greater support WPA. Detected %s)", cap_rid.prodVer);
2748 return 0;
2751 static struct net_device *_init_airo_card( unsigned short irq, int port,
2752 int is_pcmcia, struct pci_dev *pci,
2753 struct device *dmdev )
2755 struct net_device *dev;
2756 struct airo_info *ai;
2757 int i, rc;
2759 /* Create the network device object. */
2760 dev = alloc_netdev(sizeof(*ai), "", ether_setup);
2761 if (!dev) {
2762 airo_print_err("", "Couldn't alloc_etherdev");
2763 return NULL;
2766 ai = dev->ml_priv = netdev_priv(dev);
2767 ai->wifidev = NULL;
2768 ai->flags = 1 << FLAG_RADIO_DOWN;
2769 ai->jobs = 0;
2770 ai->dev = dev;
2771 if (pci && (pci->device == 0x5000 || pci->device == 0xa504)) {
2772 airo_print_dbg("", "Found an MPI350 card");
2773 set_bit(FLAG_MPI, &ai->flags);
2775 spin_lock_init(&ai->aux_lock);
2776 sema_init(&ai->sem, 1);
2777 ai->config.len = 0;
2778 ai->pci = pci;
2779 init_waitqueue_head (&ai->thr_wait);
2780 ai->tfm = NULL;
2781 add_airo_dev(ai);
2783 if (airo_networks_allocate (ai))
2784 goto err_out_free;
2785 airo_networks_initialize (ai);
2787 /* The Airo-specific entries in the device structure. */
2788 if (test_bit(FLAG_MPI,&ai->flags)) {
2789 skb_queue_head_init (&ai->txq);
2790 dev->hard_start_xmit = &mpi_start_xmit;
2791 } else
2792 dev->hard_start_xmit = &airo_start_xmit;
2793 dev->get_stats = &airo_get_stats;
2794 dev->set_multicast_list = &airo_set_multicast_list;
2795 dev->set_mac_address = &airo_set_mac_address;
2796 dev->do_ioctl = &airo_ioctl;
2797 dev->wireless_handlers = &airo_handler_def;
2798 ai->wireless_data.spy_data = &ai->spy_data;
2799 dev->wireless_data = &ai->wireless_data;
2800 dev->change_mtu = &airo_change_mtu;
2801 dev->open = &airo_open;
2802 dev->stop = &airo_close;
2803 dev->irq = irq;
2804 dev->base_addr = port;
2806 SET_NETDEV_DEV(dev, dmdev);
2808 reset_card (dev, 1);
2809 msleep(400);
2811 if (!is_pcmcia) {
2812 if (!request_region(dev->base_addr, 64, DRV_NAME)) {
2813 rc = -EBUSY;
2814 airo_print_err(dev->name, "Couldn't request region");
2815 goto err_out_nets;
2819 if (test_bit(FLAG_MPI,&ai->flags)) {
2820 if (mpi_map_card(ai, pci)) {
2821 airo_print_err("", "Could not map memory");
2822 goto err_out_res;
2826 if (probe) {
2827 if ( setup_card( ai, dev->dev_addr, 1 ) != SUCCESS ) {
2828 airo_print_err(dev->name, "MAC could not be enabled" );
2829 rc = -EIO;
2830 goto err_out_map;
2832 } else if (!test_bit(FLAG_MPI,&ai->flags)) {
2833 ai->bap_read = fast_bap_read;
2834 set_bit(FLAG_FLASHING, &ai->flags);
2837 /* Test for WPA support */
2838 if (airo_test_wpa_capable(ai)) {
2839 set_bit(FLAG_WPA_CAPABLE, &ai->flags);
2840 ai->bssListFirst = RID_WPA_BSSLISTFIRST;
2841 ai->bssListNext = RID_WPA_BSSLISTNEXT;
2842 ai->bssListRidLen = sizeof(BSSListRid);
2843 } else {
2844 ai->bssListFirst = RID_BSSLISTFIRST;
2845 ai->bssListNext = RID_BSSLISTNEXT;
2846 ai->bssListRidLen = sizeof(BSSListRid) - sizeof(BSSListRidExtra);
2849 strcpy(dev->name, "eth%d");
2850 rc = register_netdev(dev);
2851 if (rc) {
2852 airo_print_err(dev->name, "Couldn't register_netdev");
2853 goto err_out_map;
2855 ai->wifidev = init_wifidev(ai, dev);
2856 if (!ai->wifidev)
2857 goto err_out_reg;
2859 set_bit(FLAG_REGISTERED,&ai->flags);
2860 airo_print_info(dev->name, "MAC enabled %pM", dev->dev_addr);
2862 /* Allocate the transmit buffers */
2863 if (probe && !test_bit(FLAG_MPI,&ai->flags))
2864 for( i = 0; i < MAX_FIDS; i++ )
2865 ai->fids[i] = transmit_allocate(ai,AIRO_DEF_MTU,i>=MAX_FIDS/2);
2867 if (setup_proc_entry(dev, dev->ml_priv) < 0)
2868 goto err_out_wifi;
2870 return dev;
2872 err_out_wifi:
2873 unregister_netdev(ai->wifidev);
2874 free_netdev(ai->wifidev);
2875 err_out_reg:
2876 unregister_netdev(dev);
2877 err_out_map:
2878 if (test_bit(FLAG_MPI,&ai->flags) && pci) {
2879 pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
2880 iounmap(ai->pciaux);
2881 iounmap(ai->pcimem);
2882 mpi_unmap_card(ai->pci);
2884 err_out_res:
2885 if (!is_pcmcia)
2886 release_region( dev->base_addr, 64 );
2887 err_out_nets:
2888 airo_networks_free(ai);
2889 del_airo_dev(ai);
2890 err_out_free:
2891 free_netdev(dev);
2892 return NULL;
2895 struct net_device *init_airo_card( unsigned short irq, int port, int is_pcmcia,
2896 struct device *dmdev)
2898 return _init_airo_card ( irq, port, is_pcmcia, NULL, dmdev);
2901 EXPORT_SYMBOL(init_airo_card);
2903 static int waitbusy (struct airo_info *ai) {
2904 int delay = 0;
2905 while ((IN4500(ai, COMMAND) & COMMAND_BUSY) && (delay < 10000)) {
2906 udelay (10);
2907 if ((++delay % 20) == 0)
2908 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
2910 return delay < 10000;
2913 int reset_airo_card( struct net_device *dev )
2915 int i;
2916 struct airo_info *ai = dev->ml_priv;
2918 if (reset_card (dev, 1))
2919 return -1;
2921 if ( setup_card(ai, dev->dev_addr, 1 ) != SUCCESS ) {
2922 airo_print_err(dev->name, "MAC could not be enabled");
2923 return -1;
2925 airo_print_info(dev->name, "MAC enabled %pM", dev->dev_addr);
2926 /* Allocate the transmit buffers if needed */
2927 if (!test_bit(FLAG_MPI,&ai->flags))
2928 for( i = 0; i < MAX_FIDS; i++ )
2929 ai->fids[i] = transmit_allocate (ai,AIRO_DEF_MTU,i>=MAX_FIDS/2);
2931 enable_interrupts( ai );
2932 netif_wake_queue(dev);
2933 return 0;
2936 EXPORT_SYMBOL(reset_airo_card);
2938 static void airo_send_event(struct net_device *dev) {
2939 struct airo_info *ai = dev->ml_priv;
2940 union iwreq_data wrqu;
2941 StatusRid status_rid;
2943 clear_bit(JOB_EVENT, &ai->jobs);
2944 PC4500_readrid(ai, RID_STATUS, &status_rid, sizeof(status_rid), 0);
2945 up(&ai->sem);
2946 wrqu.data.length = 0;
2947 wrqu.data.flags = 0;
2948 memcpy(wrqu.ap_addr.sa_data, status_rid.bssid[0], ETH_ALEN);
2949 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
2951 /* Send event to user space */
2952 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
2955 static void airo_process_scan_results (struct airo_info *ai) {
2956 union iwreq_data wrqu;
2957 BSSListRid bss;
2958 int rc;
2959 BSSListElement * loop_net;
2960 BSSListElement * tmp_net;
2962 /* Blow away current list of scan results */
2963 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
2964 list_move_tail (&loop_net->list, &ai->network_free_list);
2965 /* Don't blow away ->list, just BSS data */
2966 memset (loop_net, 0, sizeof (loop_net->bss));
2969 /* Try to read the first entry of the scan result */
2970 rc = PC4500_readrid(ai, ai->bssListFirst, &bss, ai->bssListRidLen, 0);
2971 if((rc) || (bss.index == cpu_to_le16(0xffff))) {
2972 /* No scan results */
2973 goto out;
2976 /* Read and parse all entries */
2977 tmp_net = NULL;
2978 while((!rc) && (bss.index != cpu_to_le16(0xffff))) {
2979 /* Grab a network off the free list */
2980 if (!list_empty(&ai->network_free_list)) {
2981 tmp_net = list_entry(ai->network_free_list.next,
2982 BSSListElement, list);
2983 list_del(ai->network_free_list.next);
2986 if (tmp_net != NULL) {
2987 memcpy(tmp_net, &bss, sizeof(tmp_net->bss));
2988 list_add_tail(&tmp_net->list, &ai->network_list);
2989 tmp_net = NULL;
2992 /* Read next entry */
2993 rc = PC4500_readrid(ai, ai->bssListNext,
2994 &bss, ai->bssListRidLen, 0);
2997 out:
2998 ai->scan_timeout = 0;
2999 clear_bit(JOB_SCAN_RESULTS, &ai->jobs);
3000 up(&ai->sem);
3002 /* Send an empty event to user space.
3003 * We don't send the received data on
3004 * the event because it would require
3005 * us to do complex transcoding, and
3006 * we want to minimise the work done in
3007 * the irq handler. Use a request to
3008 * extract the data - Jean II */
3009 wrqu.data.length = 0;
3010 wrqu.data.flags = 0;
3011 wireless_send_event(ai->dev, SIOCGIWSCAN, &wrqu, NULL);
3014 static int airo_thread(void *data) {
3015 struct net_device *dev = data;
3016 struct airo_info *ai = dev->ml_priv;
3017 int locked;
3019 set_freezable();
3020 while(1) {
3021 /* make swsusp happy with our thread */
3022 try_to_freeze();
3024 if (test_bit(JOB_DIE, &ai->jobs))
3025 break;
3027 if (ai->jobs) {
3028 locked = down_interruptible(&ai->sem);
3029 } else {
3030 wait_queue_t wait;
3032 init_waitqueue_entry(&wait, current);
3033 add_wait_queue(&ai->thr_wait, &wait);
3034 for (;;) {
3035 set_current_state(TASK_INTERRUPTIBLE);
3036 if (ai->jobs)
3037 break;
3038 if (ai->expires || ai->scan_timeout) {
3039 if (ai->scan_timeout &&
3040 time_after_eq(jiffies,ai->scan_timeout)){
3041 set_bit(JOB_SCAN_RESULTS, &ai->jobs);
3042 break;
3043 } else if (ai->expires &&
3044 time_after_eq(jiffies,ai->expires)){
3045 set_bit(JOB_AUTOWEP, &ai->jobs);
3046 break;
3048 if (!kthread_should_stop() &&
3049 !freezing(current)) {
3050 unsigned long wake_at;
3051 if (!ai->expires || !ai->scan_timeout) {
3052 wake_at = max(ai->expires,
3053 ai->scan_timeout);
3054 } else {
3055 wake_at = min(ai->expires,
3056 ai->scan_timeout);
3058 schedule_timeout(wake_at - jiffies);
3059 continue;
3061 } else if (!kthread_should_stop() &&
3062 !freezing(current)) {
3063 schedule();
3064 continue;
3066 break;
3068 current->state = TASK_RUNNING;
3069 remove_wait_queue(&ai->thr_wait, &wait);
3070 locked = 1;
3073 if (locked)
3074 continue;
3076 if (test_bit(JOB_DIE, &ai->jobs)) {
3077 up(&ai->sem);
3078 break;
3081 if (ai->power.event || test_bit(FLAG_FLASHING, &ai->flags)) {
3082 up(&ai->sem);
3083 continue;
3086 if (test_bit(JOB_XMIT, &ai->jobs))
3087 airo_end_xmit(dev);
3088 else if (test_bit(JOB_XMIT11, &ai->jobs))
3089 airo_end_xmit11(dev);
3090 else if (test_bit(JOB_STATS, &ai->jobs))
3091 airo_read_stats(dev);
3092 else if (test_bit(JOB_WSTATS, &ai->jobs))
3093 airo_read_wireless_stats(ai);
3094 else if (test_bit(JOB_PROMISC, &ai->jobs))
3095 airo_set_promisc(ai);
3096 else if (test_bit(JOB_MIC, &ai->jobs))
3097 micinit(ai);
3098 else if (test_bit(JOB_EVENT, &ai->jobs))
3099 airo_send_event(dev);
3100 else if (test_bit(JOB_AUTOWEP, &ai->jobs))
3101 timer_func(dev);
3102 else if (test_bit(JOB_SCAN_RESULTS, &ai->jobs))
3103 airo_process_scan_results(ai);
3104 else /* Shouldn't get here, but we make sure to unlock */
3105 up(&ai->sem);
3108 return 0;
3111 static int header_len(__le16 ctl)
3113 u16 fc = le16_to_cpu(ctl);
3114 switch (fc & 0xc) {
3115 case 4:
3116 if ((fc & 0xe0) == 0xc0)
3117 return 10; /* one-address control packet */
3118 return 16; /* two-address control packet */
3119 case 8:
3120 if ((fc & 0x300) == 0x300)
3121 return 30; /* WDS packet */
3123 return 24;
3126 static irqreturn_t airo_interrupt(int irq, void *dev_id)
3128 struct net_device *dev = dev_id;
3129 u16 status;
3130 u16 fid;
3131 struct airo_info *apriv = dev->ml_priv;
3132 u16 savedInterrupts = 0;
3133 int handled = 0;
3135 if (!netif_device_present(dev))
3136 return IRQ_NONE;
3138 for (;;) {
3139 status = IN4500( apriv, EVSTAT );
3140 if ( !(status & STATUS_INTS) || status == 0xffff ) break;
3142 handled = 1;
3144 if ( status & EV_AWAKE ) {
3145 OUT4500( apriv, EVACK, EV_AWAKE );
3146 OUT4500( apriv, EVACK, EV_AWAKE );
3149 if (!savedInterrupts) {
3150 savedInterrupts = IN4500( apriv, EVINTEN );
3151 OUT4500( apriv, EVINTEN, 0 );
3154 if ( status & EV_MIC ) {
3155 OUT4500( apriv, EVACK, EV_MIC );
3156 if (test_bit(FLAG_MIC_CAPABLE, &apriv->flags)) {
3157 set_bit(JOB_MIC, &apriv->jobs);
3158 wake_up_interruptible(&apriv->thr_wait);
3161 if ( status & EV_LINK ) {
3162 union iwreq_data wrqu;
3163 int scan_forceloss = 0;
3164 /* The link status has changed, if you want to put a
3165 monitor hook in, do it here. (Remember that
3166 interrupts are still disabled!)
3168 u16 newStatus = IN4500(apriv, LINKSTAT);
3169 OUT4500( apriv, EVACK, EV_LINK);
3170 /* Here is what newStatus means: */
3171 #define NOBEACON 0x8000 /* Loss of sync - missed beacons */
3172 #define MAXRETRIES 0x8001 /* Loss of sync - max retries */
3173 #define MAXARL 0x8002 /* Loss of sync - average retry level exceeded*/
3174 #define FORCELOSS 0x8003 /* Loss of sync - host request */
3175 #define TSFSYNC 0x8004 /* Loss of sync - TSF synchronization */
3176 #define DEAUTH 0x8100 /* Deauthentication (low byte is reason code) */
3177 #define DISASS 0x8200 /* Disassociation (low byte is reason code) */
3178 #define ASSFAIL 0x8400 /* Association failure (low byte is reason
3179 code) */
3180 #define AUTHFAIL 0x0300 /* Authentication failure (low byte is reason
3181 code) */
3182 #define ASSOCIATED 0x0400 /* Associated */
3183 #define REASSOCIATED 0x0600 /* Reassociated? Only on firmware >= 5.30.17 */
3184 #define RC_RESERVED 0 /* Reserved return code */
3185 #define RC_NOREASON 1 /* Unspecified reason */
3186 #define RC_AUTHINV 2 /* Previous authentication invalid */
3187 #define RC_DEAUTH 3 /* Deauthenticated because sending station is
3188 leaving */
3189 #define RC_NOACT 4 /* Disassociated due to inactivity */
3190 #define RC_MAXLOAD 5 /* Disassociated because AP is unable to handle
3191 all currently associated stations */
3192 #define RC_BADCLASS2 6 /* Class 2 frame received from
3193 non-Authenticated station */
3194 #define RC_BADCLASS3 7 /* Class 3 frame received from
3195 non-Associated station */
3196 #define RC_STATLEAVE 8 /* Disassociated because sending station is
3197 leaving BSS */
3198 #define RC_NOAUTH 9 /* Station requesting (Re)Association is not
3199 Authenticated with the responding station */
3200 if (newStatus == FORCELOSS && apriv->scan_timeout > 0)
3201 scan_forceloss = 1;
3202 if(newStatus == ASSOCIATED || newStatus == REASSOCIATED) {
3203 if (auto_wep)
3204 apriv->expires = 0;
3205 if (apriv->list_bss_task)
3206 wake_up_process(apriv->list_bss_task);
3207 set_bit(FLAG_UPDATE_UNI, &apriv->flags);
3208 set_bit(FLAG_UPDATE_MULTI, &apriv->flags);
3210 if (down_trylock(&apriv->sem) != 0) {
3211 set_bit(JOB_EVENT, &apriv->jobs);
3212 wake_up_interruptible(&apriv->thr_wait);
3213 } else
3214 airo_send_event(dev);
3215 } else if (!scan_forceloss) {
3216 if (auto_wep && !apriv->expires) {
3217 apriv->expires = RUN_AT(3*HZ);
3218 wake_up_interruptible(&apriv->thr_wait);
3221 /* Send event to user space */
3222 memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN);
3223 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3224 wireless_send_event(dev, SIOCGIWAP, &wrqu,NULL);
3228 /* Check to see if there is something to receive */
3229 if ( status & EV_RX ) {
3230 struct sk_buff *skb = NULL;
3231 __le16 fc, v;
3232 u16 len, hdrlen = 0;
3233 #pragma pack(1)
3234 struct {
3235 __le16 status, len;
3236 u8 rssi[2];
3237 u8 rate;
3238 u8 freq;
3239 __le16 tmp[4];
3240 } hdr;
3241 #pragma pack()
3242 u16 gap;
3243 __le16 tmpbuf[4];
3244 __le16 *buffer;
3246 if (test_bit(FLAG_MPI,&apriv->flags)) {
3247 if (test_bit(FLAG_802_11, &apriv->flags))
3248 mpi_receive_802_11(apriv);
3249 else
3250 mpi_receive_802_3(apriv);
3251 OUT4500(apriv, EVACK, EV_RX);
3252 goto exitrx;
3255 fid = IN4500( apriv, RXFID );
3257 /* Get the packet length */
3258 if (test_bit(FLAG_802_11, &apriv->flags)) {
3259 bap_setup (apriv, fid, 4, BAP0);
3260 bap_read (apriv, (__le16*)&hdr, sizeof(hdr), BAP0);
3261 /* Bad CRC. Ignore packet */
3262 if (le16_to_cpu(hdr.status) & 2)
3263 hdr.len = 0;
3264 if (apriv->wifidev == NULL)
3265 hdr.len = 0;
3266 } else {
3267 bap_setup (apriv, fid, 0x36, BAP0);
3268 bap_read (apriv, &hdr.len, 2, BAP0);
3270 len = le16_to_cpu(hdr.len);
3272 if (len > AIRO_DEF_MTU) {
3273 airo_print_err(apriv->dev->name, "Bad size %d", len);
3274 goto badrx;
3276 if (len == 0)
3277 goto badrx;
3279 if (test_bit(FLAG_802_11, &apriv->flags)) {
3280 bap_read (apriv, &fc, sizeof(fc), BAP0);
3281 hdrlen = header_len(fc);
3282 } else
3283 hdrlen = ETH_ALEN * 2;
3285 skb = dev_alloc_skb( len + hdrlen + 2 + 2 );
3286 if ( !skb ) {
3287 dev->stats.rx_dropped++;
3288 goto badrx;
3290 skb_reserve(skb, 2); /* This way the IP header is aligned */
3291 buffer = (__le16*)skb_put (skb, len + hdrlen);
3292 if (test_bit(FLAG_802_11, &apriv->flags)) {
3293 buffer[0] = fc;
3294 bap_read (apriv, buffer + 1, hdrlen - 2, BAP0);
3295 if (hdrlen == 24)
3296 bap_read (apriv, tmpbuf, 6, BAP0);
3298 bap_read (apriv, &v, sizeof(v), BAP0);
3299 gap = le16_to_cpu(v);
3300 if (gap) {
3301 if (gap <= 8) {
3302 bap_read (apriv, tmpbuf, gap, BAP0);
3303 } else {
3304 airo_print_err(apriv->dev->name, "gaplen too "
3305 "big. Problems will follow...");
3308 bap_read (apriv, buffer + hdrlen/2, len, BAP0);
3309 } else {
3310 MICBuffer micbuf;
3311 bap_read (apriv, buffer, ETH_ALEN*2, BAP0);
3312 if (apriv->micstats.enabled) {
3313 bap_read (apriv,(__le16*)&micbuf,sizeof(micbuf),BAP0);
3314 if (ntohs(micbuf.typelen) > 0x05DC)
3315 bap_setup (apriv, fid, 0x44, BAP0);
3316 else {
3317 if (len <= sizeof(micbuf))
3318 goto badmic;
3320 len -= sizeof(micbuf);
3321 skb_trim (skb, len + hdrlen);
3324 bap_read(apriv,buffer+ETH_ALEN,len,BAP0);
3325 if (decapsulate(apriv,&micbuf,(etherHead*)buffer,len)) {
3326 badmic:
3327 dev_kfree_skb_irq (skb);
3328 badrx:
3329 OUT4500( apriv, EVACK, EV_RX);
3330 goto exitrx;
3333 #ifdef WIRELESS_SPY
3334 if (apriv->spy_data.spy_number > 0) {
3335 char *sa;
3336 struct iw_quality wstats;
3337 /* Prepare spy data : addr + qual */
3338 if (!test_bit(FLAG_802_11, &apriv->flags)) {
3339 sa = (char*)buffer + 6;
3340 bap_setup (apriv, fid, 8, BAP0);
3341 bap_read (apriv, (__le16*)hdr.rssi, 2, BAP0);
3342 } else
3343 sa = (char*)buffer + 10;
3344 wstats.qual = hdr.rssi[0];
3345 if (apriv->rssi)
3346 wstats.level = 0x100 - apriv->rssi[hdr.rssi[1]].rssidBm;
3347 else
3348 wstats.level = (hdr.rssi[1] + 321) / 2;
3349 wstats.noise = apriv->wstats.qual.noise;
3350 wstats.updated = IW_QUAL_LEVEL_UPDATED
3351 | IW_QUAL_QUAL_UPDATED
3352 | IW_QUAL_DBM;
3353 /* Update spy records */
3354 wireless_spy_update(dev, sa, &wstats);
3356 #endif /* WIRELESS_SPY */
3357 OUT4500( apriv, EVACK, EV_RX);
3359 if (test_bit(FLAG_802_11, &apriv->flags)) {
3360 skb_reset_mac_header(skb);
3361 skb->pkt_type = PACKET_OTHERHOST;
3362 skb->dev = apriv->wifidev;
3363 skb->protocol = htons(ETH_P_802_2);
3364 } else
3365 skb->protocol = eth_type_trans(skb,dev);
3366 skb->ip_summed = CHECKSUM_NONE;
3368 netif_rx( skb );
3370 exitrx:
3372 /* Check to see if a packet has been transmitted */
3373 if ( status & ( EV_TX|EV_TXCPY|EV_TXEXC ) ) {
3374 int i;
3375 int len = 0;
3376 int index = -1;
3378 if (test_bit(FLAG_MPI,&apriv->flags)) {
3379 unsigned long flags;
3381 if (status & EV_TXEXC)
3382 get_tx_error(apriv, -1);
3383 spin_lock_irqsave(&apriv->aux_lock, flags);
3384 if (!skb_queue_empty(&apriv->txq)) {
3385 spin_unlock_irqrestore(&apriv->aux_lock,flags);
3386 mpi_send_packet (dev);
3387 } else {
3388 clear_bit(FLAG_PENDING_XMIT, &apriv->flags);
3389 spin_unlock_irqrestore(&apriv->aux_lock,flags);
3390 netif_wake_queue (dev);
3392 OUT4500( apriv, EVACK,
3393 status & (EV_TX|EV_TXCPY|EV_TXEXC));
3394 goto exittx;
3397 fid = IN4500(apriv, TXCOMPLFID);
3399 for( i = 0; i < MAX_FIDS; i++ ) {
3400 if ( ( apriv->fids[i] & 0xffff ) == fid ) {
3401 len = apriv->fids[i] >> 16;
3402 index = i;
3405 if (index != -1) {
3406 if (status & EV_TXEXC)
3407 get_tx_error(apriv, index);
3408 OUT4500( apriv, EVACK, status & (EV_TX | EV_TXEXC));
3409 /* Set up to be used again */
3410 apriv->fids[index] &= 0xffff;
3411 if (index < MAX_FIDS / 2) {
3412 if (!test_bit(FLAG_PENDING_XMIT, &apriv->flags))
3413 netif_wake_queue(dev);
3414 } else {
3415 if (!test_bit(FLAG_PENDING_XMIT11, &apriv->flags))
3416 netif_wake_queue(apriv->wifidev);
3418 } else {
3419 OUT4500( apriv, EVACK, status & (EV_TX | EV_TXCPY | EV_TXEXC));
3420 airo_print_err(apriv->dev->name, "Unallocated FID was "
3421 "used to xmit" );
3424 exittx:
3425 if ( status & ~STATUS_INTS & ~IGNORE_INTS )
3426 airo_print_warn(apriv->dev->name, "Got weird status %x",
3427 status & ~STATUS_INTS & ~IGNORE_INTS );
3430 if (savedInterrupts)
3431 OUT4500( apriv, EVINTEN, savedInterrupts );
3433 /* done.. */
3434 return IRQ_RETVAL(handled);
3438 * Routines to talk to the card
3442 * This was originally written for the 4500, hence the name
3443 * NOTE: If use with 8bit mode and SMP bad things will happen!
3444 * Why would some one do 8 bit IO in an SMP machine?!?
3446 static void OUT4500( struct airo_info *ai, u16 reg, u16 val ) {
3447 if (test_bit(FLAG_MPI,&ai->flags))
3448 reg <<= 1;
3449 if ( !do8bitIO )
3450 outw( val, ai->dev->base_addr + reg );
3451 else {
3452 outb( val & 0xff, ai->dev->base_addr + reg );
3453 outb( val >> 8, ai->dev->base_addr + reg + 1 );
3457 static u16 IN4500( struct airo_info *ai, u16 reg ) {
3458 unsigned short rc;
3460 if (test_bit(FLAG_MPI,&ai->flags))
3461 reg <<= 1;
3462 if ( !do8bitIO )
3463 rc = inw( ai->dev->base_addr + reg );
3464 else {
3465 rc = inb( ai->dev->base_addr + reg );
3466 rc += ((int)inb( ai->dev->base_addr + reg + 1 )) << 8;
3468 return rc;
3471 static int enable_MAC(struct airo_info *ai, int lock)
3473 int rc;
3474 Cmd cmd;
3475 Resp rsp;
3477 /* FLAG_RADIO_OFF : Radio disabled via /proc or Wireless Extensions
3478 * FLAG_RADIO_DOWN : Radio disabled via "ifconfig ethX down"
3479 * Note : we could try to use !netif_running(dev) in enable_MAC()
3480 * instead of this flag, but I don't trust it *within* the
3481 * open/close functions, and testing both flags together is
3482 * "cheaper" - Jean II */
3483 if (ai->flags & FLAG_RADIO_MASK) return SUCCESS;
3485 if (lock && down_interruptible(&ai->sem))
3486 return -ERESTARTSYS;
3488 if (!test_bit(FLAG_ENABLED, &ai->flags)) {
3489 memset(&cmd, 0, sizeof(cmd));
3490 cmd.cmd = MAC_ENABLE;
3491 rc = issuecommand(ai, &cmd, &rsp);
3492 if (rc == SUCCESS)
3493 set_bit(FLAG_ENABLED, &ai->flags);
3494 } else
3495 rc = SUCCESS;
3497 if (lock)
3498 up(&ai->sem);
3500 if (rc)
3501 airo_print_err(ai->dev->name, "Cannot enable MAC");
3502 else if ((rsp.status & 0xFF00) != 0) {
3503 airo_print_err(ai->dev->name, "Bad MAC enable reason=%x, "
3504 "rid=%x, offset=%d", rsp.rsp0, rsp.rsp1, rsp.rsp2);
3505 rc = ERROR;
3507 return rc;
3510 static void disable_MAC( struct airo_info *ai, int lock ) {
3511 Cmd cmd;
3512 Resp rsp;
3514 if (lock && down_interruptible(&ai->sem))
3515 return;
3517 if (test_bit(FLAG_ENABLED, &ai->flags)) {
3518 memset(&cmd, 0, sizeof(cmd));
3519 cmd.cmd = MAC_DISABLE; // disable in case already enabled
3520 issuecommand(ai, &cmd, &rsp);
3521 clear_bit(FLAG_ENABLED, &ai->flags);
3523 if (lock)
3524 up(&ai->sem);
3527 static void enable_interrupts( struct airo_info *ai ) {
3528 /* Enable the interrupts */
3529 OUT4500( ai, EVINTEN, STATUS_INTS );
3532 static void disable_interrupts( struct airo_info *ai ) {
3533 OUT4500( ai, EVINTEN, 0 );
3536 static void mpi_receive_802_3(struct airo_info *ai)
3538 RxFid rxd;
3539 int len = 0;
3540 struct sk_buff *skb;
3541 char *buffer;
3542 int off = 0;
3543 MICBuffer micbuf;
3545 memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
3546 /* Make sure we got something */
3547 if (rxd.rdy && rxd.valid == 0) {
3548 len = rxd.len + 12;
3549 if (len < 12 || len > 2048)
3550 goto badrx;
3552 skb = dev_alloc_skb(len);
3553 if (!skb) {
3554 ai->dev->stats.rx_dropped++;
3555 goto badrx;
3557 buffer = skb_put(skb,len);
3558 memcpy(buffer, ai->rxfids[0].virtual_host_addr, ETH_ALEN * 2);
3559 if (ai->micstats.enabled) {
3560 memcpy(&micbuf,
3561 ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2,
3562 sizeof(micbuf));
3563 if (ntohs(micbuf.typelen) <= 0x05DC) {
3564 if (len <= sizeof(micbuf) + ETH_ALEN * 2)
3565 goto badmic;
3567 off = sizeof(micbuf);
3568 skb_trim (skb, len - off);
3571 memcpy(buffer + ETH_ALEN * 2,
3572 ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2 + off,
3573 len - ETH_ALEN * 2 - off);
3574 if (decapsulate (ai, &micbuf, (etherHead*)buffer, len - off - ETH_ALEN * 2)) {
3575 badmic:
3576 dev_kfree_skb_irq (skb);
3577 goto badrx;
3579 #ifdef WIRELESS_SPY
3580 if (ai->spy_data.spy_number > 0) {
3581 char *sa;
3582 struct iw_quality wstats;
3583 /* Prepare spy data : addr + qual */
3584 sa = buffer + ETH_ALEN;
3585 wstats.qual = 0; /* XXX Where do I get that info from ??? */
3586 wstats.level = 0;
3587 wstats.updated = 0;
3588 /* Update spy records */
3589 wireless_spy_update(ai->dev, sa, &wstats);
3591 #endif /* WIRELESS_SPY */
3593 skb->ip_summed = CHECKSUM_NONE;
3594 skb->protocol = eth_type_trans(skb, ai->dev);
3595 netif_rx(skb);
3597 badrx:
3598 if (rxd.valid == 0) {
3599 rxd.valid = 1;
3600 rxd.rdy = 0;
3601 rxd.len = PKTSIZE;
3602 memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
3606 static void mpi_receive_802_11(struct airo_info *ai)
3608 RxFid rxd;
3609 struct sk_buff *skb = NULL;
3610 u16 len, hdrlen = 0;
3611 __le16 fc;
3612 #pragma pack(1)
3613 struct {
3614 __le16 status, len;
3615 u8 rssi[2];
3616 u8 rate;
3617 u8 freq;
3618 __le16 tmp[4];
3619 } hdr;
3620 #pragma pack()
3621 u16 gap;
3622 u16 *buffer;
3623 char *ptr = ai->rxfids[0].virtual_host_addr+4;
3625 memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
3626 memcpy ((char *)&hdr, ptr, sizeof(hdr));
3627 ptr += sizeof(hdr);
3628 /* Bad CRC. Ignore packet */
3629 if (le16_to_cpu(hdr.status) & 2)
3630 hdr.len = 0;
3631 if (ai->wifidev == NULL)
3632 hdr.len = 0;
3633 len = le16_to_cpu(hdr.len);
3634 if (len > AIRO_DEF_MTU) {
3635 airo_print_err(ai->dev->name, "Bad size %d", len);
3636 goto badrx;
3638 if (len == 0)
3639 goto badrx;
3641 fc = get_unaligned((__le16 *)ptr);
3642 hdrlen = header_len(fc);
3644 skb = dev_alloc_skb( len + hdrlen + 2 );
3645 if ( !skb ) {
3646 ai->dev->stats.rx_dropped++;
3647 goto badrx;
3649 buffer = (u16*)skb_put (skb, len + hdrlen);
3650 memcpy ((char *)buffer, ptr, hdrlen);
3651 ptr += hdrlen;
3652 if (hdrlen == 24)
3653 ptr += 6;
3654 gap = get_unaligned_le16(ptr);
3655 ptr += sizeof(__le16);
3656 if (gap) {
3657 if (gap <= 8)
3658 ptr += gap;
3659 else
3660 airo_print_err(ai->dev->name,
3661 "gaplen too big. Problems will follow...");
3663 memcpy ((char *)buffer + hdrlen, ptr, len);
3664 ptr += len;
3665 #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
3666 if (ai->spy_data.spy_number > 0) {
3667 char *sa;
3668 struct iw_quality wstats;
3669 /* Prepare spy data : addr + qual */
3670 sa = (char*)buffer + 10;
3671 wstats.qual = hdr.rssi[0];
3672 if (ai->rssi)
3673 wstats.level = 0x100 - ai->rssi[hdr.rssi[1]].rssidBm;
3674 else
3675 wstats.level = (hdr.rssi[1] + 321) / 2;
3676 wstats.noise = ai->wstats.qual.noise;
3677 wstats.updated = IW_QUAL_QUAL_UPDATED
3678 | IW_QUAL_LEVEL_UPDATED
3679 | IW_QUAL_DBM;
3680 /* Update spy records */
3681 wireless_spy_update(ai->dev, sa, &wstats);
3683 #endif /* IW_WIRELESS_SPY */
3684 skb_reset_mac_header(skb);
3685 skb->pkt_type = PACKET_OTHERHOST;
3686 skb->dev = ai->wifidev;
3687 skb->protocol = htons(ETH_P_802_2);
3688 skb->ip_summed = CHECKSUM_NONE;
3689 netif_rx( skb );
3690 badrx:
3691 if (rxd.valid == 0) {
3692 rxd.valid = 1;
3693 rxd.rdy = 0;
3694 rxd.len = PKTSIZE;
3695 memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
3699 static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
3701 Cmd cmd;
3702 Resp rsp;
3703 int status;
3704 int i;
3705 SsidRid mySsid;
3706 __le16 lastindex;
3707 WepKeyRid wkr;
3708 int rc;
3710 memset( &mySsid, 0, sizeof( mySsid ) );
3711 kfree (ai->flash);
3712 ai->flash = NULL;
3714 /* The NOP is the first step in getting the card going */
3715 cmd.cmd = NOP;
3716 cmd.parm0 = cmd.parm1 = cmd.parm2 = 0;
3717 if (lock && down_interruptible(&ai->sem))
3718 return ERROR;
3719 if ( issuecommand( ai, &cmd, &rsp ) != SUCCESS ) {
3720 if (lock)
3721 up(&ai->sem);
3722 return ERROR;
3724 disable_MAC( ai, 0);
3726 // Let's figure out if we need to use the AUX port
3727 if (!test_bit(FLAG_MPI,&ai->flags)) {
3728 cmd.cmd = CMD_ENABLEAUX;
3729 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
3730 if (lock)
3731 up(&ai->sem);
3732 airo_print_err(ai->dev->name, "Error checking for AUX port");
3733 return ERROR;
3735 if (!aux_bap || rsp.status & 0xff00) {
3736 ai->bap_read = fast_bap_read;
3737 airo_print_dbg(ai->dev->name, "Doing fast bap_reads");
3738 } else {
3739 ai->bap_read = aux_bap_read;
3740 airo_print_dbg(ai->dev->name, "Doing AUX bap_reads");
3743 if (lock)
3744 up(&ai->sem);
3745 if (ai->config.len == 0) {
3746 tdsRssiRid rssi_rid;
3747 CapabilityRid cap_rid;
3749 kfree(ai->APList);
3750 ai->APList = NULL;
3751 kfree(ai->SSID);
3752 ai->SSID = NULL;
3753 // general configuration (read/modify/write)
3754 status = readConfigRid(ai, lock);
3755 if ( status != SUCCESS ) return ERROR;
3757 status = readCapabilityRid(ai, &cap_rid, lock);
3758 if ( status != SUCCESS ) return ERROR;
3760 status = PC4500_readrid(ai,RID_RSSI,&rssi_rid,sizeof(rssi_rid),lock);
3761 if ( status == SUCCESS ) {
3762 if (ai->rssi || (ai->rssi = kmalloc(512, GFP_KERNEL)) != NULL)
3763 memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512); /* Skip RID length member */
3765 else {
3766 kfree(ai->rssi);
3767 ai->rssi = NULL;
3768 if (cap_rid.softCap & cpu_to_le16(8))
3769 ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
3770 else
3771 airo_print_warn(ai->dev->name, "unknown received signal "
3772 "level scale");
3774 ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS;
3775 ai->config.authType = AUTH_OPEN;
3776 ai->config.modulation = MOD_CCK;
3778 if (le16_to_cpu(cap_rid.len) >= sizeof(cap_rid) &&
3779 (cap_rid.extSoftCap & cpu_to_le16(1)) &&
3780 micsetup(ai) == SUCCESS) {
3781 ai->config.opmode |= MODE_MIC;
3782 set_bit(FLAG_MIC_CAPABLE, &ai->flags);
3785 /* Save off the MAC */
3786 for( i = 0; i < ETH_ALEN; i++ ) {
3787 mac[i] = ai->config.macAddr[i];
3790 /* Check to see if there are any insmod configured
3791 rates to add */
3792 if ( rates[0] ) {
3793 int i = 0;
3794 memset(ai->config.rates,0,sizeof(ai->config.rates));
3795 for( i = 0; i < 8 && rates[i]; i++ ) {
3796 ai->config.rates[i] = rates[i];
3799 if ( basic_rate > 0 ) {
3800 int i;
3801 for( i = 0; i < 8; i++ ) {
3802 if ( ai->config.rates[i] == basic_rate ||
3803 !ai->config.rates ) {
3804 ai->config.rates[i] = basic_rate | 0x80;
3805 break;
3809 set_bit (FLAG_COMMIT, &ai->flags);
3812 /* Setup the SSIDs if present */
3813 if ( ssids[0] ) {
3814 int i;
3815 for( i = 0; i < 3 && ssids[i]; i++ ) {
3816 size_t len = strlen(ssids[i]);
3817 if (len > 32)
3818 len = 32;
3819 mySsid.ssids[i].len = cpu_to_le16(len);
3820 memcpy(mySsid.ssids[i].ssid, ssids[i], len);
3822 mySsid.len = cpu_to_le16(sizeof(mySsid));
3825 status = writeConfigRid(ai, lock);
3826 if ( status != SUCCESS ) return ERROR;
3828 /* Set up the SSID list */
3829 if ( ssids[0] ) {
3830 status = writeSsidRid(ai, &mySsid, lock);
3831 if ( status != SUCCESS ) return ERROR;
3834 status = enable_MAC(ai, lock);
3835 if (status != SUCCESS)
3836 return ERROR;
3838 /* Grab the initial wep key, we gotta save it for auto_wep */
3839 rc = readWepKeyRid(ai, &wkr, 1, lock);
3840 if (rc == SUCCESS) do {
3841 lastindex = wkr.kindex;
3842 if (wkr.kindex == cpu_to_le16(0xffff)) {
3843 ai->defindex = wkr.mac[0];
3845 rc = readWepKeyRid(ai, &wkr, 0, lock);
3846 } while(lastindex != wkr.kindex);
3848 try_auto_wep(ai);
3850 return SUCCESS;
3853 static u16 issuecommand(struct airo_info *ai, Cmd *pCmd, Resp *pRsp) {
3854 // Im really paranoid about letting it run forever!
3855 int max_tries = 600000;
3857 if (IN4500(ai, EVSTAT) & EV_CMD)
3858 OUT4500(ai, EVACK, EV_CMD);
3860 OUT4500(ai, PARAM0, pCmd->parm0);
3861 OUT4500(ai, PARAM1, pCmd->parm1);
3862 OUT4500(ai, PARAM2, pCmd->parm2);
3863 OUT4500(ai, COMMAND, pCmd->cmd);
3865 while (max_tries-- && (IN4500(ai, EVSTAT) & EV_CMD) == 0) {
3866 if ((IN4500(ai, COMMAND)) == pCmd->cmd)
3867 // PC4500 didn't notice command, try again
3868 OUT4500(ai, COMMAND, pCmd->cmd);
3869 if (!in_atomic() && (max_tries & 255) == 0)
3870 schedule();
3873 if ( max_tries == -1 ) {
3874 airo_print_err(ai->dev->name,
3875 "Max tries exceeded when issueing command");
3876 if (IN4500(ai, COMMAND) & COMMAND_BUSY)
3877 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
3878 return ERROR;
3881 // command completed
3882 pRsp->status = IN4500(ai, STATUS);
3883 pRsp->rsp0 = IN4500(ai, RESP0);
3884 pRsp->rsp1 = IN4500(ai, RESP1);
3885 pRsp->rsp2 = IN4500(ai, RESP2);
3886 if ((pRsp->status & 0xff00)!=0 && pCmd->cmd != CMD_SOFTRESET)
3887 airo_print_err(ai->dev->name,
3888 "cmd:%x status:%x rsp0:%x rsp1:%x rsp2:%x",
3889 pCmd->cmd, pRsp->status, pRsp->rsp0, pRsp->rsp1,
3890 pRsp->rsp2);
3892 // clear stuck command busy if necessary
3893 if (IN4500(ai, COMMAND) & COMMAND_BUSY) {
3894 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
3896 // acknowledge processing the status/response
3897 OUT4500(ai, EVACK, EV_CMD);
3899 return SUCCESS;
3902 /* Sets up the bap to start exchange data. whichbap should
3903 * be one of the BAP0 or BAP1 defines. Locks should be held before
3904 * calling! */
3905 static int bap_setup(struct airo_info *ai, u16 rid, u16 offset, int whichbap )
3907 int timeout = 50;
3908 int max_tries = 3;
3910 OUT4500(ai, SELECT0+whichbap, rid);
3911 OUT4500(ai, OFFSET0+whichbap, offset);
3912 while (1) {
3913 int status = IN4500(ai, OFFSET0+whichbap);
3914 if (status & BAP_BUSY) {
3915 /* This isn't really a timeout, but its kinda
3916 close */
3917 if (timeout--) {
3918 continue;
3920 } else if ( status & BAP_ERR ) {
3921 /* invalid rid or offset */
3922 airo_print_err(ai->dev->name, "BAP error %x %d",
3923 status, whichbap );
3924 return ERROR;
3925 } else if (status & BAP_DONE) { // success
3926 return SUCCESS;
3928 if ( !(max_tries--) ) {
3929 airo_print_err(ai->dev->name,
3930 "BAP setup error too many retries\n");
3931 return ERROR;
3933 // -- PC4500 missed it, try again
3934 OUT4500(ai, SELECT0+whichbap, rid);
3935 OUT4500(ai, OFFSET0+whichbap, offset);
3936 timeout = 50;
3940 /* should only be called by aux_bap_read. This aux function and the
3941 following use concepts not documented in the developers guide. I
3942 got them from a patch given to my by Aironet */
3943 static u16 aux_setup(struct airo_info *ai, u16 page,
3944 u16 offset, u16 *len)
3946 u16 next;
3948 OUT4500(ai, AUXPAGE, page);
3949 OUT4500(ai, AUXOFF, 0);
3950 next = IN4500(ai, AUXDATA);
3951 *len = IN4500(ai, AUXDATA)&0xff;
3952 if (offset != 4) OUT4500(ai, AUXOFF, offset);
3953 return next;
3956 /* requires call to bap_setup() first */
3957 static int aux_bap_read(struct airo_info *ai, __le16 *pu16Dst,
3958 int bytelen, int whichbap)
3960 u16 len;
3961 u16 page;
3962 u16 offset;
3963 u16 next;
3964 int words;
3965 int i;
3966 unsigned long flags;
3968 spin_lock_irqsave(&ai->aux_lock, flags);
3969 page = IN4500(ai, SWS0+whichbap);
3970 offset = IN4500(ai, SWS2+whichbap);
3971 next = aux_setup(ai, page, offset, &len);
3972 words = (bytelen+1)>>1;
3974 for (i=0; i<words;) {
3975 int count;
3976 count = (len>>1) < (words-i) ? (len>>1) : (words-i);
3977 if ( !do8bitIO )
3978 insw( ai->dev->base_addr+DATA0+whichbap,
3979 pu16Dst+i,count );
3980 else
3981 insb( ai->dev->base_addr+DATA0+whichbap,
3982 pu16Dst+i, count << 1 );
3983 i += count;
3984 if (i<words) {
3985 next = aux_setup(ai, next, 4, &len);
3988 spin_unlock_irqrestore(&ai->aux_lock, flags);
3989 return SUCCESS;
3993 /* requires call to bap_setup() first */
3994 static int fast_bap_read(struct airo_info *ai, __le16 *pu16Dst,
3995 int bytelen, int whichbap)
3997 bytelen = (bytelen + 1) & (~1); // round up to even value
3998 if ( !do8bitIO )
3999 insw( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen>>1 );
4000 else
4001 insb( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen );
4002 return SUCCESS;
4005 /* requires call to bap_setup() first */
4006 static int bap_write(struct airo_info *ai, const __le16 *pu16Src,
4007 int bytelen, int whichbap)
4009 bytelen = (bytelen + 1) & (~1); // round up to even value
4010 if ( !do8bitIO )
4011 outsw( ai->dev->base_addr+DATA0+whichbap,
4012 pu16Src, bytelen>>1 );
4013 else
4014 outsb( ai->dev->base_addr+DATA0+whichbap, pu16Src, bytelen );
4015 return SUCCESS;
4018 static int PC4500_accessrid(struct airo_info *ai, u16 rid, u16 accmd)
4020 Cmd cmd; /* for issuing commands */
4021 Resp rsp; /* response from commands */
4022 u16 status;
4024 memset(&cmd, 0, sizeof(cmd));
4025 cmd.cmd = accmd;
4026 cmd.parm0 = rid;
4027 status = issuecommand(ai, &cmd, &rsp);
4028 if (status != 0) return status;
4029 if ( (rsp.status & 0x7F00) != 0) {
4030 return (accmd << 8) + (rsp.rsp0 & 0xFF);
4032 return 0;
4035 /* Note, that we are using BAP1 which is also used by transmit, so
4036 * we must get a lock. */
4037 static int PC4500_readrid(struct airo_info *ai, u16 rid, void *pBuf, int len, int lock)
4039 u16 status;
4040 int rc = SUCCESS;
4042 if (lock) {
4043 if (down_interruptible(&ai->sem))
4044 return ERROR;
4046 if (test_bit(FLAG_MPI,&ai->flags)) {
4047 Cmd cmd;
4048 Resp rsp;
4050 memset(&cmd, 0, sizeof(cmd));
4051 memset(&rsp, 0, sizeof(rsp));
4052 ai->config_desc.rid_desc.valid = 1;
4053 ai->config_desc.rid_desc.len = RIDSIZE;
4054 ai->config_desc.rid_desc.rid = 0;
4055 ai->config_desc.rid_desc.host_addr = ai->ridbus;
4057 cmd.cmd = CMD_ACCESS;
4058 cmd.parm0 = rid;
4060 memcpy_toio(ai->config_desc.card_ram_off,
4061 &ai->config_desc.rid_desc, sizeof(Rid));
4063 rc = issuecommand(ai, &cmd, &rsp);
4065 if (rsp.status & 0x7f00)
4066 rc = rsp.rsp0;
4067 if (!rc)
4068 memcpy(pBuf, ai->config_desc.virtual_host_addr, len);
4069 goto done;
4070 } else {
4071 if ((status = PC4500_accessrid(ai, rid, CMD_ACCESS))!=SUCCESS) {
4072 rc = status;
4073 goto done;
4075 if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
4076 rc = ERROR;
4077 goto done;
4079 // read the rid length field
4080 bap_read(ai, pBuf, 2, BAP1);
4081 // length for remaining part of rid
4082 len = min(len, (int)le16_to_cpu(*(__le16*)pBuf)) - 2;
4084 if ( len <= 2 ) {
4085 airo_print_err(ai->dev->name,
4086 "Rid %x has a length of %d which is too short",
4087 (int)rid, (int)len );
4088 rc = ERROR;
4089 goto done;
4091 // read remainder of the rid
4092 rc = bap_read(ai, ((__le16*)pBuf)+1, len, BAP1);
4094 done:
4095 if (lock)
4096 up(&ai->sem);
4097 return rc;
4100 /* Note, that we are using BAP1 which is also used by transmit, so
4101 * make sure this isnt called when a transmit is happening */
4102 static int PC4500_writerid(struct airo_info *ai, u16 rid,
4103 const void *pBuf, int len, int lock)
4105 u16 status;
4106 int rc = SUCCESS;
4108 *(__le16*)pBuf = cpu_to_le16((u16)len);
4110 if (lock) {
4111 if (down_interruptible(&ai->sem))
4112 return ERROR;
4114 if (test_bit(FLAG_MPI,&ai->flags)) {
4115 Cmd cmd;
4116 Resp rsp;
4118 if (test_bit(FLAG_ENABLED, &ai->flags) && (RID_WEP_TEMP != rid))
4119 airo_print_err(ai->dev->name,
4120 "%s: MAC should be disabled (rid=%04x)",
4121 __func__, rid);
4122 memset(&cmd, 0, sizeof(cmd));
4123 memset(&rsp, 0, sizeof(rsp));
4125 ai->config_desc.rid_desc.valid = 1;
4126 ai->config_desc.rid_desc.len = *((u16 *)pBuf);
4127 ai->config_desc.rid_desc.rid = 0;
4129 cmd.cmd = CMD_WRITERID;
4130 cmd.parm0 = rid;
4132 memcpy_toio(ai->config_desc.card_ram_off,
4133 &ai->config_desc.rid_desc, sizeof(Rid));
4135 if (len < 4 || len > 2047) {
4136 airo_print_err(ai->dev->name, "%s: len=%d", __func__, len);
4137 rc = -1;
4138 } else {
4139 memcpy((char *)ai->config_desc.virtual_host_addr,
4140 pBuf, len);
4142 rc = issuecommand(ai, &cmd, &rsp);
4143 if ((rc & 0xff00) != 0) {
4144 airo_print_err(ai->dev->name, "%s: Write rid Error %d",
4145 __func__, rc);
4146 airo_print_err(ai->dev->name, "%s: Cmd=%04x",
4147 __func__, cmd.cmd);
4150 if ((rsp.status & 0x7f00))
4151 rc = rsp.rsp0;
4153 } else {
4154 // --- first access so that we can write the rid data
4155 if ( (status = PC4500_accessrid(ai, rid, CMD_ACCESS)) != 0) {
4156 rc = status;
4157 goto done;
4159 // --- now write the rid data
4160 if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
4161 rc = ERROR;
4162 goto done;
4164 bap_write(ai, pBuf, len, BAP1);
4165 // ---now commit the rid data
4166 rc = PC4500_accessrid(ai, rid, 0x100|CMD_ACCESS);
4168 done:
4169 if (lock)
4170 up(&ai->sem);
4171 return rc;
4174 /* Allocates a FID to be used for transmitting packets. We only use
4175 one for now. */
4176 static u16 transmit_allocate(struct airo_info *ai, int lenPayload, int raw)
4178 unsigned int loop = 3000;
4179 Cmd cmd;
4180 Resp rsp;
4181 u16 txFid;
4182 __le16 txControl;
4184 cmd.cmd = CMD_ALLOCATETX;
4185 cmd.parm0 = lenPayload;
4186 if (down_interruptible(&ai->sem))
4187 return ERROR;
4188 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
4189 txFid = ERROR;
4190 goto done;
4192 if ( (rsp.status & 0xFF00) != 0) {
4193 txFid = ERROR;
4194 goto done;
4196 /* wait for the allocate event/indication
4197 * It makes me kind of nervous that this can just sit here and spin,
4198 * but in practice it only loops like four times. */
4199 while (((IN4500(ai, EVSTAT) & EV_ALLOC) == 0) && --loop);
4200 if (!loop) {
4201 txFid = ERROR;
4202 goto done;
4205 // get the allocated fid and acknowledge
4206 txFid = IN4500(ai, TXALLOCFID);
4207 OUT4500(ai, EVACK, EV_ALLOC);
4209 /* The CARD is pretty cool since it converts the ethernet packet
4210 * into 802.11. Also note that we don't release the FID since we
4211 * will be using the same one over and over again. */
4212 /* We only have to setup the control once since we are not
4213 * releasing the fid. */
4214 if (raw)
4215 txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_11
4216 | TXCTL_ETHERNET | TXCTL_NORELEASE);
4217 else
4218 txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_3
4219 | TXCTL_ETHERNET | TXCTL_NORELEASE);
4220 if (bap_setup(ai, txFid, 0x0008, BAP1) != SUCCESS)
4221 txFid = ERROR;
4222 else
4223 bap_write(ai, &txControl, sizeof(txControl), BAP1);
4225 done:
4226 up(&ai->sem);
4228 return txFid;
4231 /* In general BAP1 is dedicated to transmiting packets. However,
4232 since we need a BAP when accessing RIDs, we also use BAP1 for that.
4233 Make sure the BAP1 spinlock is held when this is called. */
4234 static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket)
4236 __le16 payloadLen;
4237 Cmd cmd;
4238 Resp rsp;
4239 int miclen = 0;
4240 u16 txFid = len;
4241 MICBuffer pMic;
4243 len >>= 16;
4245 if (len <= ETH_ALEN * 2) {
4246 airo_print_warn(ai->dev->name, "Short packet %d", len);
4247 return ERROR;
4249 len -= ETH_ALEN * 2;
4251 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
4252 (ntohs(((__be16 *)pPacket)[6]) != 0x888E)) {
4253 if (encapsulate(ai,(etherHead *)pPacket,&pMic,len) != SUCCESS)
4254 return ERROR;
4255 miclen = sizeof(pMic);
4257 // packet is destination[6], source[6], payload[len-12]
4258 // write the payload length and dst/src/payload
4259 if (bap_setup(ai, txFid, 0x0036, BAP1) != SUCCESS) return ERROR;
4260 /* The hardware addresses aren't counted as part of the payload, so
4261 * we have to subtract the 12 bytes for the addresses off */
4262 payloadLen = cpu_to_le16(len + miclen);
4263 bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
4264 bap_write(ai, (__le16*)pPacket, sizeof(etherHead), BAP1);
4265 if (miclen)
4266 bap_write(ai, (__le16*)&pMic, miclen, BAP1);
4267 bap_write(ai, (__le16*)(pPacket + sizeof(etherHead)), len, BAP1);
4268 // issue the transmit command
4269 memset( &cmd, 0, sizeof( cmd ) );
4270 cmd.cmd = CMD_TRANSMIT;
4271 cmd.parm0 = txFid;
4272 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
4273 if ( (rsp.status & 0xFF00) != 0) return ERROR;
4274 return SUCCESS;
4277 static int transmit_802_11_packet(struct airo_info *ai, int len, char *pPacket)
4279 __le16 fc, payloadLen;
4280 Cmd cmd;
4281 Resp rsp;
4282 int hdrlen;
4283 static u8 tail[(30-10) + 2 + 6] = {[30-10] = 6};
4284 /* padding of header to full size + le16 gaplen (6) + gaplen bytes */
4285 u16 txFid = len;
4286 len >>= 16;
4288 fc = *(__le16*)pPacket;
4289 hdrlen = header_len(fc);
4291 if (len < hdrlen) {
4292 airo_print_warn(ai->dev->name, "Short packet %d", len);
4293 return ERROR;
4296 /* packet is 802.11 header + payload
4297 * write the payload length and dst/src/payload */
4298 if (bap_setup(ai, txFid, 6, BAP1) != SUCCESS) return ERROR;
4299 /* The 802.11 header aren't counted as part of the payload, so
4300 * we have to subtract the header bytes off */
4301 payloadLen = cpu_to_le16(len-hdrlen);
4302 bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
4303 if (bap_setup(ai, txFid, 0x0014, BAP1) != SUCCESS) return ERROR;
4304 bap_write(ai, (__le16 *)pPacket, hdrlen, BAP1);
4305 bap_write(ai, (__le16 *)(tail + (hdrlen - 10)), 38 - hdrlen, BAP1);
4307 bap_write(ai, (__le16 *)(pPacket + hdrlen), len - hdrlen, BAP1);
4308 // issue the transmit command
4309 memset( &cmd, 0, sizeof( cmd ) );
4310 cmd.cmd = CMD_TRANSMIT;
4311 cmd.parm0 = txFid;
4312 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
4313 if ( (rsp.status & 0xFF00) != 0) return ERROR;
4314 return SUCCESS;
4318 * This is the proc_fs routines. It is a bit messier than I would
4319 * like! Feel free to clean it up!
4322 static ssize_t proc_read( struct file *file,
4323 char __user *buffer,
4324 size_t len,
4325 loff_t *offset);
4327 static ssize_t proc_write( struct file *file,
4328 const char __user *buffer,
4329 size_t len,
4330 loff_t *offset );
4331 static int proc_close( struct inode *inode, struct file *file );
4333 static int proc_stats_open( struct inode *inode, struct file *file );
4334 static int proc_statsdelta_open( struct inode *inode, struct file *file );
4335 static int proc_status_open( struct inode *inode, struct file *file );
4336 static int proc_SSID_open( struct inode *inode, struct file *file );
4337 static int proc_APList_open( struct inode *inode, struct file *file );
4338 static int proc_BSSList_open( struct inode *inode, struct file *file );
4339 static int proc_config_open( struct inode *inode, struct file *file );
4340 static int proc_wepkey_open( struct inode *inode, struct file *file );
4342 static const struct file_operations proc_statsdelta_ops = {
4343 .owner = THIS_MODULE,
4344 .read = proc_read,
4345 .open = proc_statsdelta_open,
4346 .release = proc_close
4349 static const struct file_operations proc_stats_ops = {
4350 .owner = THIS_MODULE,
4351 .read = proc_read,
4352 .open = proc_stats_open,
4353 .release = proc_close
4356 static const struct file_operations proc_status_ops = {
4357 .owner = THIS_MODULE,
4358 .read = proc_read,
4359 .open = proc_status_open,
4360 .release = proc_close
4363 static const struct file_operations proc_SSID_ops = {
4364 .owner = THIS_MODULE,
4365 .read = proc_read,
4366 .write = proc_write,
4367 .open = proc_SSID_open,
4368 .release = proc_close
4371 static const struct file_operations proc_BSSList_ops = {
4372 .owner = THIS_MODULE,
4373 .read = proc_read,
4374 .write = proc_write,
4375 .open = proc_BSSList_open,
4376 .release = proc_close
4379 static const struct file_operations proc_APList_ops = {
4380 .owner = THIS_MODULE,
4381 .read = proc_read,
4382 .write = proc_write,
4383 .open = proc_APList_open,
4384 .release = proc_close
4387 static const struct file_operations proc_config_ops = {
4388 .owner = THIS_MODULE,
4389 .read = proc_read,
4390 .write = proc_write,
4391 .open = proc_config_open,
4392 .release = proc_close
4395 static const struct file_operations proc_wepkey_ops = {
4396 .owner = THIS_MODULE,
4397 .read = proc_read,
4398 .write = proc_write,
4399 .open = proc_wepkey_open,
4400 .release = proc_close
4403 static struct proc_dir_entry *airo_entry;
4405 struct proc_data {
4406 int release_buffer;
4407 int readlen;
4408 char *rbuffer;
4409 int writelen;
4410 int maxwritelen;
4411 char *wbuffer;
4412 void (*on_close) (struct inode *, struct file *);
4415 static int setup_proc_entry( struct net_device *dev,
4416 struct airo_info *apriv ) {
4417 struct proc_dir_entry *entry;
4418 /* First setup the device directory */
4419 strcpy(apriv->proc_name,dev->name);
4420 apriv->proc_entry = create_proc_entry(apriv->proc_name,
4421 S_IFDIR|airo_perm,
4422 airo_entry);
4423 if (!apriv->proc_entry)
4424 goto fail;
4425 apriv->proc_entry->uid = proc_uid;
4426 apriv->proc_entry->gid = proc_gid;
4427 apriv->proc_entry->owner = THIS_MODULE;
4429 /* Setup the StatsDelta */
4430 entry = proc_create_data("StatsDelta",
4431 S_IFREG | (S_IRUGO&proc_perm),
4432 apriv->proc_entry, &proc_statsdelta_ops, dev);
4433 if (!entry)
4434 goto fail_stats_delta;
4435 entry->uid = proc_uid;
4436 entry->gid = proc_gid;
4438 /* Setup the Stats */
4439 entry = proc_create_data("Stats",
4440 S_IFREG | (S_IRUGO&proc_perm),
4441 apriv->proc_entry, &proc_stats_ops, dev);
4442 if (!entry)
4443 goto fail_stats;
4444 entry->uid = proc_uid;
4445 entry->gid = proc_gid;
4447 /* Setup the Status */
4448 entry = proc_create_data("Status",
4449 S_IFREG | (S_IRUGO&proc_perm),
4450 apriv->proc_entry, &proc_status_ops, dev);
4451 if (!entry)
4452 goto fail_status;
4453 entry->uid = proc_uid;
4454 entry->gid = proc_gid;
4456 /* Setup the Config */
4457 entry = proc_create_data("Config",
4458 S_IFREG | proc_perm,
4459 apriv->proc_entry, &proc_config_ops, dev);
4460 if (!entry)
4461 goto fail_config;
4462 entry->uid = proc_uid;
4463 entry->gid = proc_gid;
4465 /* Setup the SSID */
4466 entry = proc_create_data("SSID",
4467 S_IFREG | proc_perm,
4468 apriv->proc_entry, &proc_SSID_ops, dev);
4469 if (!entry)
4470 goto fail_ssid;
4471 entry->uid = proc_uid;
4472 entry->gid = proc_gid;
4474 /* Setup the APList */
4475 entry = proc_create_data("APList",
4476 S_IFREG | proc_perm,
4477 apriv->proc_entry, &proc_APList_ops, dev);
4478 if (!entry)
4479 goto fail_aplist;
4480 entry->uid = proc_uid;
4481 entry->gid = proc_gid;
4483 /* Setup the BSSList */
4484 entry = proc_create_data("BSSList",
4485 S_IFREG | proc_perm,
4486 apriv->proc_entry, &proc_BSSList_ops, dev);
4487 if (!entry)
4488 goto fail_bsslist;
4489 entry->uid = proc_uid;
4490 entry->gid = proc_gid;
4492 /* Setup the WepKey */
4493 entry = proc_create_data("WepKey",
4494 S_IFREG | proc_perm,
4495 apriv->proc_entry, &proc_wepkey_ops, dev);
4496 if (!entry)
4497 goto fail_wepkey;
4498 entry->uid = proc_uid;
4499 entry->gid = proc_gid;
4501 return 0;
4503 fail_wepkey:
4504 remove_proc_entry("BSSList", apriv->proc_entry);
4505 fail_bsslist:
4506 remove_proc_entry("APList", apriv->proc_entry);
4507 fail_aplist:
4508 remove_proc_entry("SSID", apriv->proc_entry);
4509 fail_ssid:
4510 remove_proc_entry("Config", apriv->proc_entry);
4511 fail_config:
4512 remove_proc_entry("Status", apriv->proc_entry);
4513 fail_status:
4514 remove_proc_entry("Stats", apriv->proc_entry);
4515 fail_stats:
4516 remove_proc_entry("StatsDelta", apriv->proc_entry);
4517 fail_stats_delta:
4518 remove_proc_entry(apriv->proc_name, airo_entry);
4519 fail:
4520 return -ENOMEM;
4523 static int takedown_proc_entry( struct net_device *dev,
4524 struct airo_info *apriv ) {
4525 if ( !apriv->proc_entry->namelen ) return 0;
4526 remove_proc_entry("Stats",apriv->proc_entry);
4527 remove_proc_entry("StatsDelta",apriv->proc_entry);
4528 remove_proc_entry("Status",apriv->proc_entry);
4529 remove_proc_entry("Config",apriv->proc_entry);
4530 remove_proc_entry("SSID",apriv->proc_entry);
4531 remove_proc_entry("APList",apriv->proc_entry);
4532 remove_proc_entry("BSSList",apriv->proc_entry);
4533 remove_proc_entry("WepKey",apriv->proc_entry);
4534 remove_proc_entry(apriv->proc_name,airo_entry);
4535 return 0;
4539 * What we want from the proc_fs is to be able to efficiently read
4540 * and write the configuration. To do this, we want to read the
4541 * configuration when the file is opened and write it when the file is
4542 * closed. So basically we allocate a read buffer at open and fill it
4543 * with data, and allocate a write buffer and read it at close.
4547 * The read routine is generic, it relies on the preallocated rbuffer
4548 * to supply the data.
4550 static ssize_t proc_read( struct file *file,
4551 char __user *buffer,
4552 size_t len,
4553 loff_t *offset )
4555 struct proc_data *priv = file->private_data;
4557 if (!priv->rbuffer)
4558 return -EINVAL;
4560 return simple_read_from_buffer(buffer, len, offset, priv->rbuffer,
4561 priv->readlen);
4565 * The write routine is generic, it fills in a preallocated rbuffer
4566 * to supply the data.
4568 static ssize_t proc_write( struct file *file,
4569 const char __user *buffer,
4570 size_t len,
4571 loff_t *offset )
4573 loff_t pos = *offset;
4574 struct proc_data *priv = (struct proc_data*)file->private_data;
4576 if (!priv->wbuffer)
4577 return -EINVAL;
4579 if (pos < 0)
4580 return -EINVAL;
4581 if (pos >= priv->maxwritelen)
4582 return 0;
4583 if (len > priv->maxwritelen - pos)
4584 len = priv->maxwritelen - pos;
4585 if (copy_from_user(priv->wbuffer + pos, buffer, len))
4586 return -EFAULT;
4587 if ( pos + len > priv->writelen )
4588 priv->writelen = len + file->f_pos;
4589 *offset = pos + len;
4590 return len;
4593 static int proc_status_open(struct inode *inode, struct file *file)
4595 struct proc_data *data;
4596 struct proc_dir_entry *dp = PDE(inode);
4597 struct net_device *dev = dp->data;
4598 struct airo_info *apriv = dev->ml_priv;
4599 CapabilityRid cap_rid;
4600 StatusRid status_rid;
4601 u16 mode;
4602 int i;
4604 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4605 return -ENOMEM;
4606 data = (struct proc_data *)file->private_data;
4607 if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
4608 kfree (file->private_data);
4609 return -ENOMEM;
4612 readStatusRid(apriv, &status_rid, 1);
4613 readCapabilityRid(apriv, &cap_rid, 1);
4615 mode = le16_to_cpu(status_rid.mode);
4617 i = sprintf(data->rbuffer, "Status: %s%s%s%s%s%s%s%s%s\n",
4618 mode & 1 ? "CFG ": "",
4619 mode & 2 ? "ACT ": "",
4620 mode & 0x10 ? "SYN ": "",
4621 mode & 0x20 ? "LNK ": "",
4622 mode & 0x40 ? "LEAP ": "",
4623 mode & 0x80 ? "PRIV ": "",
4624 mode & 0x100 ? "KEY ": "",
4625 mode & 0x200 ? "WEP ": "",
4626 mode & 0x8000 ? "ERR ": "");
4627 sprintf( data->rbuffer+i, "Mode: %x\n"
4628 "Signal Strength: %d\n"
4629 "Signal Quality: %d\n"
4630 "SSID: %-.*s\n"
4631 "AP: %-.16s\n"
4632 "Freq: %d\n"
4633 "BitRate: %dmbs\n"
4634 "Driver Version: %s\n"
4635 "Device: %s\nManufacturer: %s\nFirmware Version: %s\n"
4636 "Radio type: %x\nCountry: %x\nHardware Version: %x\n"
4637 "Software Version: %x\nSoftware Subversion: %x\n"
4638 "Boot block version: %x\n",
4639 le16_to_cpu(status_rid.mode),
4640 le16_to_cpu(status_rid.normalizedSignalStrength),
4641 le16_to_cpu(status_rid.signalQuality),
4642 le16_to_cpu(status_rid.SSIDlen),
4643 status_rid.SSID,
4644 status_rid.apName,
4645 le16_to_cpu(status_rid.channel),
4646 le16_to_cpu(status_rid.currentXmitRate) / 2,
4647 version,
4648 cap_rid.prodName,
4649 cap_rid.manName,
4650 cap_rid.prodVer,
4651 le16_to_cpu(cap_rid.radioType),
4652 le16_to_cpu(cap_rid.country),
4653 le16_to_cpu(cap_rid.hardVer),
4654 le16_to_cpu(cap_rid.softVer),
4655 le16_to_cpu(cap_rid.softSubVer),
4656 le16_to_cpu(cap_rid.bootBlockVer));
4657 data->readlen = strlen( data->rbuffer );
4658 return 0;
4661 static int proc_stats_rid_open(struct inode*, struct file*, u16);
4662 static int proc_statsdelta_open( struct inode *inode,
4663 struct file *file ) {
4664 if (file->f_mode&FMODE_WRITE) {
4665 return proc_stats_rid_open(inode, file, RID_STATSDELTACLEAR);
4667 return proc_stats_rid_open(inode, file, RID_STATSDELTA);
4670 static int proc_stats_open( struct inode *inode, struct file *file ) {
4671 return proc_stats_rid_open(inode, file, RID_STATS);
4674 static int proc_stats_rid_open( struct inode *inode,
4675 struct file *file,
4676 u16 rid )
4678 struct proc_data *data;
4679 struct proc_dir_entry *dp = PDE(inode);
4680 struct net_device *dev = dp->data;
4681 struct airo_info *apriv = dev->ml_priv;
4682 StatsRid stats;
4683 int i, j;
4684 __le32 *vals = stats.vals;
4685 int len = le16_to_cpu(stats.len);
4687 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4688 return -ENOMEM;
4689 data = (struct proc_data *)file->private_data;
4690 if ((data->rbuffer = kmalloc( 4096, GFP_KERNEL )) == NULL) {
4691 kfree (file->private_data);
4692 return -ENOMEM;
4695 readStatsRid(apriv, &stats, rid, 1);
4697 j = 0;
4698 for(i=0; statsLabels[i]!=(char *)-1 && i*4<len; i++) {
4699 if (!statsLabels[i]) continue;
4700 if (j+strlen(statsLabels[i])+16>4096) {
4701 airo_print_warn(apriv->dev->name,
4702 "Potentially disasterous buffer overflow averted!");
4703 break;
4705 j+=sprintf(data->rbuffer+j, "%s: %u\n", statsLabels[i],
4706 le32_to_cpu(vals[i]));
4708 if (i*4 >= len) {
4709 airo_print_warn(apriv->dev->name, "Got a short rid");
4711 data->readlen = j;
4712 return 0;
4715 static int get_dec_u16( char *buffer, int *start, int limit ) {
4716 u16 value;
4717 int valid = 0;
4718 for( value = 0; buffer[*start] >= '0' &&
4719 buffer[*start] <= '9' &&
4720 *start < limit; (*start)++ ) {
4721 valid = 1;
4722 value *= 10;
4723 value += buffer[*start] - '0';
4725 if ( !valid ) return -1;
4726 return value;
4729 static int airo_config_commit(struct net_device *dev,
4730 struct iw_request_info *info, void *zwrq,
4731 char *extra);
4733 static inline int sniffing_mode(struct airo_info *ai)
4735 return le16_to_cpu(ai->config.rmode & RXMODE_MASK) >=
4736 le16_to_cpu(RXMODE_RFMON);
4739 static void proc_config_on_close(struct inode *inode, struct file *file)
4741 struct proc_data *data = file->private_data;
4742 struct proc_dir_entry *dp = PDE(inode);
4743 struct net_device *dev = dp->data;
4744 struct airo_info *ai = dev->ml_priv;
4745 char *line;
4747 if ( !data->writelen ) return;
4749 readConfigRid(ai, 1);
4750 set_bit (FLAG_COMMIT, &ai->flags);
4752 line = data->wbuffer;
4753 while( line[0] ) {
4754 /*** Mode processing */
4755 if ( !strncmp( line, "Mode: ", 6 ) ) {
4756 line += 6;
4757 if (sniffing_mode(ai))
4758 set_bit (FLAG_RESET, &ai->flags);
4759 ai->config.rmode &= ~RXMODE_FULL_MASK;
4760 clear_bit (FLAG_802_11, &ai->flags);
4761 ai->config.opmode &= ~MODE_CFG_MASK;
4762 ai->config.scanMode = SCANMODE_ACTIVE;
4763 if ( line[0] == 'a' ) {
4764 ai->config.opmode |= MODE_STA_IBSS;
4765 } else {
4766 ai->config.opmode |= MODE_STA_ESS;
4767 if ( line[0] == 'r' ) {
4768 ai->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
4769 ai->config.scanMode = SCANMODE_PASSIVE;
4770 set_bit (FLAG_802_11, &ai->flags);
4771 } else if ( line[0] == 'y' ) {
4772 ai->config.rmode |= RXMODE_RFMON_ANYBSS | RXMODE_DISABLE_802_3_HEADER;
4773 ai->config.scanMode = SCANMODE_PASSIVE;
4774 set_bit (FLAG_802_11, &ai->flags);
4775 } else if ( line[0] == 'l' )
4776 ai->config.rmode |= RXMODE_LANMON;
4778 set_bit (FLAG_COMMIT, &ai->flags);
4781 /*** Radio status */
4782 else if (!strncmp(line,"Radio: ", 7)) {
4783 line += 7;
4784 if (!strncmp(line,"off",3)) {
4785 set_bit (FLAG_RADIO_OFF, &ai->flags);
4786 } else {
4787 clear_bit (FLAG_RADIO_OFF, &ai->flags);
4790 /*** NodeName processing */
4791 else if ( !strncmp( line, "NodeName: ", 10 ) ) {
4792 int j;
4794 line += 10;
4795 memset( ai->config.nodeName, 0, 16 );
4796 /* Do the name, assume a space between the mode and node name */
4797 for( j = 0; j < 16 && line[j] != '\n'; j++ ) {
4798 ai->config.nodeName[j] = line[j];
4800 set_bit (FLAG_COMMIT, &ai->flags);
4803 /*** PowerMode processing */
4804 else if ( !strncmp( line, "PowerMode: ", 11 ) ) {
4805 line += 11;
4806 if ( !strncmp( line, "PSPCAM", 6 ) ) {
4807 ai->config.powerSaveMode = POWERSAVE_PSPCAM;
4808 set_bit (FLAG_COMMIT, &ai->flags);
4809 } else if ( !strncmp( line, "PSP", 3 ) ) {
4810 ai->config.powerSaveMode = POWERSAVE_PSP;
4811 set_bit (FLAG_COMMIT, &ai->flags);
4812 } else {
4813 ai->config.powerSaveMode = POWERSAVE_CAM;
4814 set_bit (FLAG_COMMIT, &ai->flags);
4816 } else if ( !strncmp( line, "DataRates: ", 11 ) ) {
4817 int v, i = 0, k = 0; /* i is index into line,
4818 k is index to rates */
4820 line += 11;
4821 while((v = get_dec_u16(line, &i, 3))!=-1) {
4822 ai->config.rates[k++] = (u8)v;
4823 line += i + 1;
4824 i = 0;
4826 set_bit (FLAG_COMMIT, &ai->flags);
4827 } else if ( !strncmp( line, "Channel: ", 9 ) ) {
4828 int v, i = 0;
4829 line += 9;
4830 v = get_dec_u16(line, &i, i+3);
4831 if ( v != -1 ) {
4832 ai->config.channelSet = cpu_to_le16(v);
4833 set_bit (FLAG_COMMIT, &ai->flags);
4835 } else if ( !strncmp( line, "XmitPower: ", 11 ) ) {
4836 int v, i = 0;
4837 line += 11;
4838 v = get_dec_u16(line, &i, i+3);
4839 if ( v != -1 ) {
4840 ai->config.txPower = cpu_to_le16(v);
4841 set_bit (FLAG_COMMIT, &ai->flags);
4843 } else if ( !strncmp( line, "WEP: ", 5 ) ) {
4844 line += 5;
4845 switch( line[0] ) {
4846 case 's':
4847 ai->config.authType = AUTH_SHAREDKEY;
4848 break;
4849 case 'e':
4850 ai->config.authType = AUTH_ENCRYPT;
4851 break;
4852 default:
4853 ai->config.authType = AUTH_OPEN;
4854 break;
4856 set_bit (FLAG_COMMIT, &ai->flags);
4857 } else if ( !strncmp( line, "LongRetryLimit: ", 16 ) ) {
4858 int v, i = 0;
4860 line += 16;
4861 v = get_dec_u16(line, &i, 3);
4862 v = (v<0) ? 0 : ((v>255) ? 255 : v);
4863 ai->config.longRetryLimit = cpu_to_le16(v);
4864 set_bit (FLAG_COMMIT, &ai->flags);
4865 } else if ( !strncmp( line, "ShortRetryLimit: ", 17 ) ) {
4866 int v, i = 0;
4868 line += 17;
4869 v = get_dec_u16(line, &i, 3);
4870 v = (v<0) ? 0 : ((v>255) ? 255 : v);
4871 ai->config.shortRetryLimit = cpu_to_le16(v);
4872 set_bit (FLAG_COMMIT, &ai->flags);
4873 } else if ( !strncmp( line, "RTSThreshold: ", 14 ) ) {
4874 int v, i = 0;
4876 line += 14;
4877 v = get_dec_u16(line, &i, 4);
4878 v = (v<0) ? 0 : ((v>AIRO_DEF_MTU) ? AIRO_DEF_MTU : v);
4879 ai->config.rtsThres = cpu_to_le16(v);
4880 set_bit (FLAG_COMMIT, &ai->flags);
4881 } else if ( !strncmp( line, "TXMSDULifetime: ", 16 ) ) {
4882 int v, i = 0;
4884 line += 16;
4885 v = get_dec_u16(line, &i, 5);
4886 v = (v<0) ? 0 : v;
4887 ai->config.txLifetime = cpu_to_le16(v);
4888 set_bit (FLAG_COMMIT, &ai->flags);
4889 } else if ( !strncmp( line, "RXMSDULifetime: ", 16 ) ) {
4890 int v, i = 0;
4892 line += 16;
4893 v = get_dec_u16(line, &i, 5);
4894 v = (v<0) ? 0 : v;
4895 ai->config.rxLifetime = cpu_to_le16(v);
4896 set_bit (FLAG_COMMIT, &ai->flags);
4897 } else if ( !strncmp( line, "TXDiversity: ", 13 ) ) {
4898 ai->config.txDiversity =
4899 (line[13]=='l') ? 1 :
4900 ((line[13]=='r')? 2: 3);
4901 set_bit (FLAG_COMMIT, &ai->flags);
4902 } else if ( !strncmp( line, "RXDiversity: ", 13 ) ) {
4903 ai->config.rxDiversity =
4904 (line[13]=='l') ? 1 :
4905 ((line[13]=='r')? 2: 3);
4906 set_bit (FLAG_COMMIT, &ai->flags);
4907 } else if ( !strncmp( line, "FragThreshold: ", 15 ) ) {
4908 int v, i = 0;
4910 line += 15;
4911 v = get_dec_u16(line, &i, 4);
4912 v = (v<256) ? 256 : ((v>AIRO_DEF_MTU) ? AIRO_DEF_MTU : v);
4913 v = v & 0xfffe; /* Make sure its even */
4914 ai->config.fragThresh = cpu_to_le16(v);
4915 set_bit (FLAG_COMMIT, &ai->flags);
4916 } else if (!strncmp(line, "Modulation: ", 12)) {
4917 line += 12;
4918 switch(*line) {
4919 case 'd': ai->config.modulation=MOD_DEFAULT; set_bit(FLAG_COMMIT, &ai->flags); break;
4920 case 'c': ai->config.modulation=MOD_CCK; set_bit(FLAG_COMMIT, &ai->flags); break;
4921 case 'm': ai->config.modulation=MOD_MOK; set_bit(FLAG_COMMIT, &ai->flags); break;
4922 default: airo_print_warn(ai->dev->name, "Unknown modulation");
4924 } else if (!strncmp(line, "Preamble: ", 10)) {
4925 line += 10;
4926 switch(*line) {
4927 case 'a': ai->config.preamble=PREAMBLE_AUTO; set_bit(FLAG_COMMIT, &ai->flags); break;
4928 case 'l': ai->config.preamble=PREAMBLE_LONG; set_bit(FLAG_COMMIT, &ai->flags); break;
4929 case 's': ai->config.preamble=PREAMBLE_SHORT; set_bit(FLAG_COMMIT, &ai->flags); break;
4930 default: airo_print_warn(ai->dev->name, "Unknown preamble");
4932 } else {
4933 airo_print_warn(ai->dev->name, "Couldn't figure out %s", line);
4935 while( line[0] && line[0] != '\n' ) line++;
4936 if ( line[0] ) line++;
4938 airo_config_commit(dev, NULL, NULL, NULL);
4941 static char *get_rmode(__le16 mode)
4943 switch(mode & RXMODE_MASK) {
4944 case RXMODE_RFMON: return "rfmon";
4945 case RXMODE_RFMON_ANYBSS: return "yna (any) bss rfmon";
4946 case RXMODE_LANMON: return "lanmon";
4948 return "ESS";
4951 static int proc_config_open(struct inode *inode, struct file *file)
4953 struct proc_data *data;
4954 struct proc_dir_entry *dp = PDE(inode);
4955 struct net_device *dev = dp->data;
4956 struct airo_info *ai = dev->ml_priv;
4957 int i;
4958 __le16 mode;
4960 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4961 return -ENOMEM;
4962 data = (struct proc_data *)file->private_data;
4963 if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
4964 kfree (file->private_data);
4965 return -ENOMEM;
4967 if ((data->wbuffer = kzalloc( 2048, GFP_KERNEL )) == NULL) {
4968 kfree (data->rbuffer);
4969 kfree (file->private_data);
4970 return -ENOMEM;
4972 data->maxwritelen = 2048;
4973 data->on_close = proc_config_on_close;
4975 readConfigRid(ai, 1);
4977 mode = ai->config.opmode & MODE_CFG_MASK;
4978 i = sprintf( data->rbuffer,
4979 "Mode: %s\n"
4980 "Radio: %s\n"
4981 "NodeName: %-16s\n"
4982 "PowerMode: %s\n"
4983 "DataRates: %d %d %d %d %d %d %d %d\n"
4984 "Channel: %d\n"
4985 "XmitPower: %d\n",
4986 mode == MODE_STA_IBSS ? "adhoc" :
4987 mode == MODE_STA_ESS ? get_rmode(ai->config.rmode):
4988 mode == MODE_AP ? "AP" :
4989 mode == MODE_AP_RPTR ? "AP RPTR" : "Error",
4990 test_bit(FLAG_RADIO_OFF, &ai->flags) ? "off" : "on",
4991 ai->config.nodeName,
4992 ai->config.powerSaveMode == POWERSAVE_CAM ? "CAM" :
4993 ai->config.powerSaveMode == POWERSAVE_PSP ? "PSP" :
4994 ai->config.powerSaveMode == POWERSAVE_PSPCAM ? "PSPCAM" :
4995 "Error",
4996 (int)ai->config.rates[0],
4997 (int)ai->config.rates[1],
4998 (int)ai->config.rates[2],
4999 (int)ai->config.rates[3],
5000 (int)ai->config.rates[4],
5001 (int)ai->config.rates[5],
5002 (int)ai->config.rates[6],
5003 (int)ai->config.rates[7],
5004 le16_to_cpu(ai->config.channelSet),
5005 le16_to_cpu(ai->config.txPower)
5007 sprintf( data->rbuffer + i,
5008 "LongRetryLimit: %d\n"
5009 "ShortRetryLimit: %d\n"
5010 "RTSThreshold: %d\n"
5011 "TXMSDULifetime: %d\n"
5012 "RXMSDULifetime: %d\n"
5013 "TXDiversity: %s\n"
5014 "RXDiversity: %s\n"
5015 "FragThreshold: %d\n"
5016 "WEP: %s\n"
5017 "Modulation: %s\n"
5018 "Preamble: %s\n",
5019 le16_to_cpu(ai->config.longRetryLimit),
5020 le16_to_cpu(ai->config.shortRetryLimit),
5021 le16_to_cpu(ai->config.rtsThres),
5022 le16_to_cpu(ai->config.txLifetime),
5023 le16_to_cpu(ai->config.rxLifetime),
5024 ai->config.txDiversity == 1 ? "left" :
5025 ai->config.txDiversity == 2 ? "right" : "both",
5026 ai->config.rxDiversity == 1 ? "left" :
5027 ai->config.rxDiversity == 2 ? "right" : "both",
5028 le16_to_cpu(ai->config.fragThresh),
5029 ai->config.authType == AUTH_ENCRYPT ? "encrypt" :
5030 ai->config.authType == AUTH_SHAREDKEY ? "shared" : "open",
5031 ai->config.modulation == MOD_DEFAULT ? "default" :
5032 ai->config.modulation == MOD_CCK ? "cck" :
5033 ai->config.modulation == MOD_MOK ? "mok" : "error",
5034 ai->config.preamble == PREAMBLE_AUTO ? "auto" :
5035 ai->config.preamble == PREAMBLE_LONG ? "long" :
5036 ai->config.preamble == PREAMBLE_SHORT ? "short" : "error"
5038 data->readlen = strlen( data->rbuffer );
5039 return 0;
5042 static void proc_SSID_on_close(struct inode *inode, struct file *file)
5044 struct proc_data *data = (struct proc_data *)file->private_data;
5045 struct proc_dir_entry *dp = PDE(inode);
5046 struct net_device *dev = dp->data;
5047 struct airo_info *ai = dev->ml_priv;
5048 SsidRid SSID_rid;
5049 int i;
5050 char *p = data->wbuffer;
5051 char *end = p + data->writelen;
5053 if (!data->writelen)
5054 return;
5056 *end = '\n'; /* sentinel; we have space for it */
5058 memset(&SSID_rid, 0, sizeof(SSID_rid));
5060 for (i = 0; i < 3 && p < end; i++) {
5061 int j = 0;
5062 /* copy up to 32 characters from this line */
5063 while (*p != '\n' && j < 32)
5064 SSID_rid.ssids[i].ssid[j++] = *p++;
5065 if (j == 0)
5066 break;
5067 SSID_rid.ssids[i].len = cpu_to_le16(j);
5068 /* skip to the beginning of the next line */
5069 while (*p++ != '\n')
5072 if (i)
5073 SSID_rid.len = cpu_to_le16(sizeof(SSID_rid));
5074 disable_MAC(ai, 1);
5075 writeSsidRid(ai, &SSID_rid, 1);
5076 enable_MAC(ai, 1);
5079 static inline u8 hexVal(char c) {
5080 if (c>='0' && c<='9') return c -= '0';
5081 if (c>='a' && c<='f') return c -= 'a'-10;
5082 if (c>='A' && c<='F') return c -= 'A'-10;
5083 return 0;
5086 static void proc_APList_on_close( struct inode *inode, struct file *file ) {
5087 struct proc_data *data = (struct proc_data *)file->private_data;
5088 struct proc_dir_entry *dp = PDE(inode);
5089 struct net_device *dev = dp->data;
5090 struct airo_info *ai = dev->ml_priv;
5091 APListRid APList_rid;
5092 int i;
5094 if ( !data->writelen ) return;
5096 memset( &APList_rid, 0, sizeof(APList_rid) );
5097 APList_rid.len = cpu_to_le16(sizeof(APList_rid));
5099 for( i = 0; i < 4 && data->writelen >= (i+1)*6*3; i++ ) {
5100 int j;
5101 for( j = 0; j < 6*3 && data->wbuffer[j+i*6*3]; j++ ) {
5102 switch(j%3) {
5103 case 0:
5104 APList_rid.ap[i][j/3]=
5105 hexVal(data->wbuffer[j+i*6*3])<<4;
5106 break;
5107 case 1:
5108 APList_rid.ap[i][j/3]|=
5109 hexVal(data->wbuffer[j+i*6*3]);
5110 break;
5114 disable_MAC(ai, 1);
5115 writeAPListRid(ai, &APList_rid, 1);
5116 enable_MAC(ai, 1);
5119 /* This function wraps PC4500_writerid with a MAC disable */
5120 static int do_writerid( struct airo_info *ai, u16 rid, const void *rid_data,
5121 int len, int dummy ) {
5122 int rc;
5124 disable_MAC(ai, 1);
5125 rc = PC4500_writerid(ai, rid, rid_data, len, 1);
5126 enable_MAC(ai, 1);
5127 return rc;
5130 /* Returns the length of the key at the index. If index == 0xffff
5131 * the index of the transmit key is returned. If the key doesn't exist,
5132 * -1 will be returned.
5134 static int get_wep_key(struct airo_info *ai, u16 index) {
5135 WepKeyRid wkr;
5136 int rc;
5137 __le16 lastindex;
5139 rc = readWepKeyRid(ai, &wkr, 1, 1);
5140 if (rc == SUCCESS) do {
5141 lastindex = wkr.kindex;
5142 if (wkr.kindex == cpu_to_le16(index)) {
5143 if (index == 0xffff) {
5144 return wkr.mac[0];
5146 return le16_to_cpu(wkr.klen);
5148 readWepKeyRid(ai, &wkr, 0, 1);
5149 } while (lastindex != wkr.kindex);
5150 return -1;
5153 static int set_wep_key(struct airo_info *ai, u16 index,
5154 const char *key, u16 keylen, int perm, int lock )
5156 static const unsigned char macaddr[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
5157 WepKeyRid wkr;
5159 memset(&wkr, 0, sizeof(wkr));
5160 if (keylen == 0) {
5161 // We are selecting which key to use
5162 wkr.len = cpu_to_le16(sizeof(wkr));
5163 wkr.kindex = cpu_to_le16(0xffff);
5164 wkr.mac[0] = (char)index;
5165 if (perm) ai->defindex = (char)index;
5166 } else {
5167 // We are actually setting the key
5168 wkr.len = cpu_to_le16(sizeof(wkr));
5169 wkr.kindex = cpu_to_le16(index);
5170 wkr.klen = cpu_to_le16(keylen);
5171 memcpy( wkr.key, key, keylen );
5172 memcpy( wkr.mac, macaddr, ETH_ALEN );
5175 if (perm) disable_MAC(ai, lock);
5176 writeWepKeyRid(ai, &wkr, perm, lock);
5177 if (perm) enable_MAC(ai, lock);
5178 return 0;
5181 static void proc_wepkey_on_close( struct inode *inode, struct file *file ) {
5182 struct proc_data *data;
5183 struct proc_dir_entry *dp = PDE(inode);
5184 struct net_device *dev = dp->data;
5185 struct airo_info *ai = dev->ml_priv;
5186 int i;
5187 char key[16];
5188 u16 index = 0;
5189 int j = 0;
5191 memset(key, 0, sizeof(key));
5193 data = (struct proc_data *)file->private_data;
5194 if ( !data->writelen ) return;
5196 if (data->wbuffer[0] >= '0' && data->wbuffer[0] <= '3' &&
5197 (data->wbuffer[1] == ' ' || data->wbuffer[1] == '\n')) {
5198 index = data->wbuffer[0] - '0';
5199 if (data->wbuffer[1] == '\n') {
5200 set_wep_key(ai, index, NULL, 0, 1, 1);
5201 return;
5203 j = 2;
5204 } else {
5205 airo_print_err(ai->dev->name, "WepKey passed invalid key index");
5206 return;
5209 for( i = 0; i < 16*3 && data->wbuffer[i+j]; i++ ) {
5210 switch(i%3) {
5211 case 0:
5212 key[i/3] = hexVal(data->wbuffer[i+j])<<4;
5213 break;
5214 case 1:
5215 key[i/3] |= hexVal(data->wbuffer[i+j]);
5216 break;
5219 set_wep_key(ai, index, key, i/3, 1, 1);
5222 static int proc_wepkey_open( struct inode *inode, struct file *file )
5224 struct proc_data *data;
5225 struct proc_dir_entry *dp = PDE(inode);
5226 struct net_device *dev = dp->data;
5227 struct airo_info *ai = dev->ml_priv;
5228 char *ptr;
5229 WepKeyRid wkr;
5230 __le16 lastindex;
5231 int j=0;
5232 int rc;
5234 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5235 return -ENOMEM;
5236 memset(&wkr, 0, sizeof(wkr));
5237 data = (struct proc_data *)file->private_data;
5238 if ((data->rbuffer = kzalloc( 180, GFP_KERNEL )) == NULL) {
5239 kfree (file->private_data);
5240 return -ENOMEM;
5242 data->writelen = 0;
5243 data->maxwritelen = 80;
5244 if ((data->wbuffer = kzalloc( 80, GFP_KERNEL )) == NULL) {
5245 kfree (data->rbuffer);
5246 kfree (file->private_data);
5247 return -ENOMEM;
5249 data->on_close = proc_wepkey_on_close;
5251 ptr = data->rbuffer;
5252 strcpy(ptr, "No wep keys\n");
5253 rc = readWepKeyRid(ai, &wkr, 1, 1);
5254 if (rc == SUCCESS) do {
5255 lastindex = wkr.kindex;
5256 if (wkr.kindex == cpu_to_le16(0xffff)) {
5257 j += sprintf(ptr+j, "Tx key = %d\n",
5258 (int)wkr.mac[0]);
5259 } else {
5260 j += sprintf(ptr+j, "Key %d set with length = %d\n",
5261 le16_to_cpu(wkr.kindex),
5262 le16_to_cpu(wkr.klen));
5264 readWepKeyRid(ai, &wkr, 0, 1);
5265 } while((lastindex != wkr.kindex) && (j < 180-30));
5267 data->readlen = strlen( data->rbuffer );
5268 return 0;
5271 static int proc_SSID_open(struct inode *inode, struct file *file)
5273 struct proc_data *data;
5274 struct proc_dir_entry *dp = PDE(inode);
5275 struct net_device *dev = dp->data;
5276 struct airo_info *ai = dev->ml_priv;
5277 int i;
5278 char *ptr;
5279 SsidRid SSID_rid;
5281 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5282 return -ENOMEM;
5283 data = (struct proc_data *)file->private_data;
5284 if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
5285 kfree (file->private_data);
5286 return -ENOMEM;
5288 data->writelen = 0;
5289 data->maxwritelen = 33*3;
5290 /* allocate maxwritelen + 1; we'll want a sentinel */
5291 if ((data->wbuffer = kzalloc(33*3 + 1, GFP_KERNEL)) == NULL) {
5292 kfree (data->rbuffer);
5293 kfree (file->private_data);
5294 return -ENOMEM;
5296 data->on_close = proc_SSID_on_close;
5298 readSsidRid(ai, &SSID_rid);
5299 ptr = data->rbuffer;
5300 for (i = 0; i < 3; i++) {
5301 int j;
5302 size_t len = le16_to_cpu(SSID_rid.ssids[i].len);
5303 if (!len)
5304 break;
5305 if (len > 32)
5306 len = 32;
5307 for (j = 0; j < len && SSID_rid.ssids[i].ssid[j]; j++)
5308 *ptr++ = SSID_rid.ssids[i].ssid[j];
5309 *ptr++ = '\n';
5311 *ptr = '\0';
5312 data->readlen = strlen( data->rbuffer );
5313 return 0;
5316 static int proc_APList_open( struct inode *inode, struct file *file ) {
5317 struct proc_data *data;
5318 struct proc_dir_entry *dp = PDE(inode);
5319 struct net_device *dev = dp->data;
5320 struct airo_info *ai = dev->ml_priv;
5321 int i;
5322 char *ptr;
5323 APListRid APList_rid;
5325 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5326 return -ENOMEM;
5327 data = (struct proc_data *)file->private_data;
5328 if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
5329 kfree (file->private_data);
5330 return -ENOMEM;
5332 data->writelen = 0;
5333 data->maxwritelen = 4*6*3;
5334 if ((data->wbuffer = kzalloc( data->maxwritelen, GFP_KERNEL )) == NULL) {
5335 kfree (data->rbuffer);
5336 kfree (file->private_data);
5337 return -ENOMEM;
5339 data->on_close = proc_APList_on_close;
5341 readAPListRid(ai, &APList_rid);
5342 ptr = data->rbuffer;
5343 for( i = 0; i < 4; i++ ) {
5344 // We end when we find a zero MAC
5345 if ( !*(int*)APList_rid.ap[i] &&
5346 !*(int*)&APList_rid.ap[i][2]) break;
5347 ptr += sprintf(ptr, "%pM\n", APList_rid.ap[i]);
5349 if (i==0) ptr += sprintf(ptr, "Not using specific APs\n");
5351 *ptr = '\0';
5352 data->readlen = strlen( data->rbuffer );
5353 return 0;
5356 static int proc_BSSList_open( struct inode *inode, struct file *file ) {
5357 struct proc_data *data;
5358 struct proc_dir_entry *dp = PDE(inode);
5359 struct net_device *dev = dp->data;
5360 struct airo_info *ai = dev->ml_priv;
5361 char *ptr;
5362 BSSListRid BSSList_rid;
5363 int rc;
5364 /* If doLoseSync is not 1, we won't do a Lose Sync */
5365 int doLoseSync = -1;
5367 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5368 return -ENOMEM;
5369 data = (struct proc_data *)file->private_data;
5370 if ((data->rbuffer = kmalloc( 1024, GFP_KERNEL )) == NULL) {
5371 kfree (file->private_data);
5372 return -ENOMEM;
5374 data->writelen = 0;
5375 data->maxwritelen = 0;
5376 data->wbuffer = NULL;
5377 data->on_close = NULL;
5379 if (file->f_mode & FMODE_WRITE) {
5380 if (!(file->f_mode & FMODE_READ)) {
5381 Cmd cmd;
5382 Resp rsp;
5384 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
5385 memset(&cmd, 0, sizeof(cmd));
5386 cmd.cmd=CMD_LISTBSS;
5387 if (down_interruptible(&ai->sem))
5388 return -ERESTARTSYS;
5389 issuecommand(ai, &cmd, &rsp);
5390 up(&ai->sem);
5391 data->readlen = 0;
5392 return 0;
5394 doLoseSync = 1;
5396 ptr = data->rbuffer;
5397 /* There is a race condition here if there are concurrent opens.
5398 Since it is a rare condition, we'll just live with it, otherwise
5399 we have to add a spin lock... */
5400 rc = readBSSListRid(ai, doLoseSync, &BSSList_rid);
5401 while(rc == 0 && BSSList_rid.index != cpu_to_le16(0xffff)) {
5402 ptr += sprintf(ptr, "%pM %*s rssi = %d",
5403 BSSList_rid.bssid,
5404 (int)BSSList_rid.ssidLen,
5405 BSSList_rid.ssid,
5406 le16_to_cpu(BSSList_rid.dBm));
5407 ptr += sprintf(ptr, " channel = %d %s %s %s %s\n",
5408 le16_to_cpu(BSSList_rid.dsChannel),
5409 BSSList_rid.cap & CAP_ESS ? "ESS" : "",
5410 BSSList_rid.cap & CAP_IBSS ? "adhoc" : "",
5411 BSSList_rid.cap & CAP_PRIVACY ? "wep" : "",
5412 BSSList_rid.cap & CAP_SHORTHDR ? "shorthdr" : "");
5413 rc = readBSSListRid(ai, 0, &BSSList_rid);
5415 *ptr = '\0';
5416 data->readlen = strlen( data->rbuffer );
5417 return 0;
5420 static int proc_close( struct inode *inode, struct file *file )
5422 struct proc_data *data = file->private_data;
5424 if (data->on_close != NULL)
5425 data->on_close(inode, file);
5426 kfree(data->rbuffer);
5427 kfree(data->wbuffer);
5428 kfree(data);
5429 return 0;
5432 /* Since the card doesn't automatically switch to the right WEP mode,
5433 we will make it do it. If the card isn't associated, every secs we
5434 will switch WEP modes to see if that will help. If the card is
5435 associated we will check every minute to see if anything has
5436 changed. */
5437 static void timer_func( struct net_device *dev ) {
5438 struct airo_info *apriv = dev->ml_priv;
5440 /* We don't have a link so try changing the authtype */
5441 readConfigRid(apriv, 0);
5442 disable_MAC(apriv, 0);
5443 switch(apriv->config.authType) {
5444 case AUTH_ENCRYPT:
5445 /* So drop to OPEN */
5446 apriv->config.authType = AUTH_OPEN;
5447 break;
5448 case AUTH_SHAREDKEY:
5449 if (apriv->keyindex < auto_wep) {
5450 set_wep_key(apriv, apriv->keyindex, NULL, 0, 0, 0);
5451 apriv->config.authType = AUTH_SHAREDKEY;
5452 apriv->keyindex++;
5453 } else {
5454 /* Drop to ENCRYPT */
5455 apriv->keyindex = 0;
5456 set_wep_key(apriv, apriv->defindex, NULL, 0, 0, 0);
5457 apriv->config.authType = AUTH_ENCRYPT;
5459 break;
5460 default: /* We'll escalate to SHAREDKEY */
5461 apriv->config.authType = AUTH_SHAREDKEY;
5463 set_bit (FLAG_COMMIT, &apriv->flags);
5464 writeConfigRid(apriv, 0);
5465 enable_MAC(apriv, 0);
5466 up(&apriv->sem);
5468 /* Schedule check to see if the change worked */
5469 clear_bit(JOB_AUTOWEP, &apriv->jobs);
5470 apriv->expires = RUN_AT(HZ*3);
5473 #ifdef CONFIG_PCI
5474 static int __devinit airo_pci_probe(struct pci_dev *pdev,
5475 const struct pci_device_id *pent)
5477 struct net_device *dev;
5479 if (pci_enable_device(pdev))
5480 return -ENODEV;
5481 pci_set_master(pdev);
5483 if (pdev->device == 0x5000 || pdev->device == 0xa504)
5484 dev = _init_airo_card(pdev->irq, pdev->resource[0].start, 0, pdev, &pdev->dev);
5485 else
5486 dev = _init_airo_card(pdev->irq, pdev->resource[2].start, 0, pdev, &pdev->dev);
5487 if (!dev) {
5488 pci_disable_device(pdev);
5489 return -ENODEV;
5492 pci_set_drvdata(pdev, dev);
5493 return 0;
5496 static void __devexit airo_pci_remove(struct pci_dev *pdev)
5498 struct net_device *dev = pci_get_drvdata(pdev);
5500 airo_print_info(dev->name, "Unregistering...");
5501 stop_airo_card(dev, 1);
5502 pci_disable_device(pdev);
5503 pci_set_drvdata(pdev, NULL);
5506 static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state)
5508 struct net_device *dev = pci_get_drvdata(pdev);
5509 struct airo_info *ai = dev->ml_priv;
5510 Cmd cmd;
5511 Resp rsp;
5513 if (!ai->APList)
5514 ai->APList = kmalloc(sizeof(APListRid), GFP_KERNEL);
5515 if (!ai->APList)
5516 return -ENOMEM;
5517 if (!ai->SSID)
5518 ai->SSID = kmalloc(sizeof(SsidRid), GFP_KERNEL);
5519 if (!ai->SSID)
5520 return -ENOMEM;
5521 readAPListRid(ai, ai->APList);
5522 readSsidRid(ai, ai->SSID);
5523 memset(&cmd, 0, sizeof(cmd));
5524 /* the lock will be released at the end of the resume callback */
5525 if (down_interruptible(&ai->sem))
5526 return -EAGAIN;
5527 disable_MAC(ai, 0);
5528 netif_device_detach(dev);
5529 ai->power = state;
5530 cmd.cmd = HOSTSLEEP;
5531 issuecommand(ai, &cmd, &rsp);
5533 pci_enable_wake(pdev, pci_choose_state(pdev, state), 1);
5534 pci_save_state(pdev);
5535 return pci_set_power_state(pdev, pci_choose_state(pdev, state));
5538 static int airo_pci_resume(struct pci_dev *pdev)
5540 struct net_device *dev = pci_get_drvdata(pdev);
5541 struct airo_info *ai = dev->ml_priv;
5542 pci_power_t prev_state = pdev->current_state;
5544 pci_set_power_state(pdev, PCI_D0);
5545 pci_restore_state(pdev);
5546 pci_enable_wake(pdev, PCI_D0, 0);
5548 if (prev_state != PCI_D1) {
5549 reset_card(dev, 0);
5550 mpi_init_descriptors(ai);
5551 setup_card(ai, dev->dev_addr, 0);
5552 clear_bit(FLAG_RADIO_OFF, &ai->flags);
5553 clear_bit(FLAG_PENDING_XMIT, &ai->flags);
5554 } else {
5555 OUT4500(ai, EVACK, EV_AWAKEN);
5556 OUT4500(ai, EVACK, EV_AWAKEN);
5557 msleep(100);
5560 set_bit(FLAG_COMMIT, &ai->flags);
5561 disable_MAC(ai, 0);
5562 msleep(200);
5563 if (ai->SSID) {
5564 writeSsidRid(ai, ai->SSID, 0);
5565 kfree(ai->SSID);
5566 ai->SSID = NULL;
5568 if (ai->APList) {
5569 writeAPListRid(ai, ai->APList, 0);
5570 kfree(ai->APList);
5571 ai->APList = NULL;
5573 writeConfigRid(ai, 0);
5574 enable_MAC(ai, 0);
5575 ai->power = PMSG_ON;
5576 netif_device_attach(dev);
5577 netif_wake_queue(dev);
5578 enable_interrupts(ai);
5579 up(&ai->sem);
5580 return 0;
5582 #endif
5584 static int __init airo_init_module( void )
5586 int i;
5588 airo_entry = create_proc_entry("driver/aironet",
5589 S_IFDIR | airo_perm,
5590 NULL);
5592 if (airo_entry) {
5593 airo_entry->uid = proc_uid;
5594 airo_entry->gid = proc_gid;
5597 for (i = 0; i < 4 && io[i] && irq[i]; i++) {
5598 airo_print_info("", "Trying to configure ISA adapter at irq=%d "
5599 "io=0x%x", irq[i], io[i] );
5600 if (init_airo_card( irq[i], io[i], 0, NULL ))
5601 /* do nothing */ ;
5604 #ifdef CONFIG_PCI
5605 airo_print_info("", "Probing for PCI adapters");
5606 i = pci_register_driver(&airo_driver);
5607 airo_print_info("", "Finished probing for PCI adapters");
5609 if (i) {
5610 remove_proc_entry("driver/aironet", NULL);
5611 return i;
5613 #endif
5615 /* Always exit with success, as we are a library module
5616 * as well as a driver module
5618 return 0;
5621 static void __exit airo_cleanup_module( void )
5623 struct airo_info *ai;
5624 while(!list_empty(&airo_devices)) {
5625 ai = list_entry(airo_devices.next, struct airo_info, dev_list);
5626 airo_print_info(ai->dev->name, "Unregistering...");
5627 stop_airo_card(ai->dev, 1);
5629 #ifdef CONFIG_PCI
5630 pci_unregister_driver(&airo_driver);
5631 #endif
5632 remove_proc_entry("driver/aironet", NULL);
5636 * Initial Wireless Extension code for Aironet driver by :
5637 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 17 November 00
5638 * Conversion to new driver API by :
5639 * Jean Tourrilhes <jt@hpl.hp.com> - HPL - 26 March 02
5640 * Javier also did a good amount of work here, adding some new extensions
5641 * and fixing my code. Let's just say that without him this code just
5642 * would not work at all... - Jean II
5645 static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi)
5647 if (!rssi_rid)
5648 return 0;
5650 return (0x100 - rssi_rid[rssi].rssidBm);
5653 static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm)
5655 int i;
5657 if (!rssi_rid)
5658 return 0;
5660 for (i = 0; i < 256; i++)
5661 if (rssi_rid[i].rssidBm == dbm)
5662 return rssi_rid[i].rssipct;
5664 return 0;
5668 static int airo_get_quality (StatusRid *status_rid, CapabilityRid *cap_rid)
5670 int quality = 0;
5671 u16 sq;
5673 if ((status_rid->mode & cpu_to_le16(0x3f)) != cpu_to_le16(0x3f))
5674 return 0;
5676 if (!(cap_rid->hardCap & cpu_to_le16(8)))
5677 return 0;
5679 sq = le16_to_cpu(status_rid->signalQuality);
5680 if (memcmp(cap_rid->prodName, "350", 3))
5681 if (sq > 0x20)
5682 quality = 0;
5683 else
5684 quality = 0x20 - sq;
5685 else
5686 if (sq > 0xb0)
5687 quality = 0;
5688 else if (sq < 0x10)
5689 quality = 0xa0;
5690 else
5691 quality = 0xb0 - sq;
5692 return quality;
5695 #define airo_get_max_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x20 : 0xa0)
5696 #define airo_get_avg_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x10 : 0x50);
5698 /*------------------------------------------------------------------*/
5700 * Wireless Handler : get protocol name
5702 static int airo_get_name(struct net_device *dev,
5703 struct iw_request_info *info,
5704 char *cwrq,
5705 char *extra)
5707 strcpy(cwrq, "IEEE 802.11-DS");
5708 return 0;
5711 /*------------------------------------------------------------------*/
5713 * Wireless Handler : set frequency
5715 static int airo_set_freq(struct net_device *dev,
5716 struct iw_request_info *info,
5717 struct iw_freq *fwrq,
5718 char *extra)
5720 struct airo_info *local = dev->ml_priv;
5721 int rc = -EINPROGRESS; /* Call commit handler */
5723 /* If setting by frequency, convert to a channel */
5724 if(fwrq->e == 1) {
5725 int f = fwrq->m / 100000;
5727 /* Hack to fall through... */
5728 fwrq->e = 0;
5729 fwrq->m = ieee80211_freq_to_dsss_chan(f);
5731 /* Setting by channel number */
5732 if((fwrq->m > 1000) || (fwrq->e > 0))
5733 rc = -EOPNOTSUPP;
5734 else {
5735 int channel = fwrq->m;
5736 /* We should do a better check than that,
5737 * based on the card capability !!! */
5738 if((channel < 1) || (channel > 14)) {
5739 airo_print_dbg(dev->name, "New channel value of %d is invalid!",
5740 fwrq->m);
5741 rc = -EINVAL;
5742 } else {
5743 readConfigRid(local, 1);
5744 /* Yes ! We can set it !!! */
5745 local->config.channelSet = cpu_to_le16(channel);
5746 set_bit (FLAG_COMMIT, &local->flags);
5749 return rc;
5752 /*------------------------------------------------------------------*/
5754 * Wireless Handler : get frequency
5756 static int airo_get_freq(struct net_device *dev,
5757 struct iw_request_info *info,
5758 struct iw_freq *fwrq,
5759 char *extra)
5761 struct airo_info *local = dev->ml_priv;
5762 StatusRid status_rid; /* Card status info */
5763 int ch;
5765 readConfigRid(local, 1);
5766 if ((local->config.opmode & MODE_CFG_MASK) == MODE_STA_ESS)
5767 status_rid.channel = local->config.channelSet;
5768 else
5769 readStatusRid(local, &status_rid, 1);
5771 ch = le16_to_cpu(status_rid.channel);
5772 if((ch > 0) && (ch < 15)) {
5773 fwrq->m = ieee80211_dsss_chan_to_freq(ch) * 100000;
5774 fwrq->e = 1;
5775 } else {
5776 fwrq->m = ch;
5777 fwrq->e = 0;
5780 return 0;
5783 /*------------------------------------------------------------------*/
5785 * Wireless Handler : set ESSID
5787 static int airo_set_essid(struct net_device *dev,
5788 struct iw_request_info *info,
5789 struct iw_point *dwrq,
5790 char *extra)
5792 struct airo_info *local = dev->ml_priv;
5793 SsidRid SSID_rid; /* SSIDs */
5795 /* Reload the list of current SSID */
5796 readSsidRid(local, &SSID_rid);
5798 /* Check if we asked for `any' */
5799 if(dwrq->flags == 0) {
5800 /* Just send an empty SSID list */
5801 memset(&SSID_rid, 0, sizeof(SSID_rid));
5802 } else {
5803 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
5805 /* Check the size of the string */
5806 if(dwrq->length > IW_ESSID_MAX_SIZE) {
5807 return -E2BIG ;
5809 /* Check if index is valid */
5810 if((index < 0) || (index >= 4)) {
5811 return -EINVAL;
5814 /* Set the SSID */
5815 memset(SSID_rid.ssids[index].ssid, 0,
5816 sizeof(SSID_rid.ssids[index].ssid));
5817 memcpy(SSID_rid.ssids[index].ssid, extra, dwrq->length);
5818 SSID_rid.ssids[index].len = cpu_to_le16(dwrq->length);
5820 SSID_rid.len = cpu_to_le16(sizeof(SSID_rid));
5821 /* Write it to the card */
5822 disable_MAC(local, 1);
5823 writeSsidRid(local, &SSID_rid, 1);
5824 enable_MAC(local, 1);
5826 return 0;
5829 /*------------------------------------------------------------------*/
5831 * Wireless Handler : get ESSID
5833 static int airo_get_essid(struct net_device *dev,
5834 struct iw_request_info *info,
5835 struct iw_point *dwrq,
5836 char *extra)
5838 struct airo_info *local = dev->ml_priv;
5839 StatusRid status_rid; /* Card status info */
5841 readStatusRid(local, &status_rid, 1);
5843 /* Note : if dwrq->flags != 0, we should
5844 * get the relevant SSID from the SSID list... */
5846 /* Get the current SSID */
5847 memcpy(extra, status_rid.SSID, le16_to_cpu(status_rid.SSIDlen));
5848 /* If none, we may want to get the one that was set */
5850 /* Push it out ! */
5851 dwrq->length = le16_to_cpu(status_rid.SSIDlen);
5852 dwrq->flags = 1; /* active */
5854 return 0;
5857 /*------------------------------------------------------------------*/
5859 * Wireless Handler : set AP address
5861 static int airo_set_wap(struct net_device *dev,
5862 struct iw_request_info *info,
5863 struct sockaddr *awrq,
5864 char *extra)
5866 struct airo_info *local = dev->ml_priv;
5867 Cmd cmd;
5868 Resp rsp;
5869 APListRid APList_rid;
5870 static const u8 any[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
5871 static const u8 off[ETH_ALEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
5873 if (awrq->sa_family != ARPHRD_ETHER)
5874 return -EINVAL;
5875 else if (!memcmp(any, awrq->sa_data, ETH_ALEN) ||
5876 !memcmp(off, awrq->sa_data, ETH_ALEN)) {
5877 memset(&cmd, 0, sizeof(cmd));
5878 cmd.cmd=CMD_LOSE_SYNC;
5879 if (down_interruptible(&local->sem))
5880 return -ERESTARTSYS;
5881 issuecommand(local, &cmd, &rsp);
5882 up(&local->sem);
5883 } else {
5884 memset(&APList_rid, 0, sizeof(APList_rid));
5885 APList_rid.len = cpu_to_le16(sizeof(APList_rid));
5886 memcpy(APList_rid.ap[0], awrq->sa_data, ETH_ALEN);
5887 disable_MAC(local, 1);
5888 writeAPListRid(local, &APList_rid, 1);
5889 enable_MAC(local, 1);
5891 return 0;
5894 /*------------------------------------------------------------------*/
5896 * Wireless Handler : get AP address
5898 static int airo_get_wap(struct net_device *dev,
5899 struct iw_request_info *info,
5900 struct sockaddr *awrq,
5901 char *extra)
5903 struct airo_info *local = dev->ml_priv;
5904 StatusRid status_rid; /* Card status info */
5906 readStatusRid(local, &status_rid, 1);
5908 /* Tentative. This seems to work, wow, I'm lucky !!! */
5909 memcpy(awrq->sa_data, status_rid.bssid[0], ETH_ALEN);
5910 awrq->sa_family = ARPHRD_ETHER;
5912 return 0;
5915 /*------------------------------------------------------------------*/
5917 * Wireless Handler : set Nickname
5919 static int airo_set_nick(struct net_device *dev,
5920 struct iw_request_info *info,
5921 struct iw_point *dwrq,
5922 char *extra)
5924 struct airo_info *local = dev->ml_priv;
5926 /* Check the size of the string */
5927 if(dwrq->length > 16) {
5928 return -E2BIG;
5930 readConfigRid(local, 1);
5931 memset(local->config.nodeName, 0, sizeof(local->config.nodeName));
5932 memcpy(local->config.nodeName, extra, dwrq->length);
5933 set_bit (FLAG_COMMIT, &local->flags);
5935 return -EINPROGRESS; /* Call commit handler */
5938 /*------------------------------------------------------------------*/
5940 * Wireless Handler : get Nickname
5942 static int airo_get_nick(struct net_device *dev,
5943 struct iw_request_info *info,
5944 struct iw_point *dwrq,
5945 char *extra)
5947 struct airo_info *local = dev->ml_priv;
5949 readConfigRid(local, 1);
5950 strncpy(extra, local->config.nodeName, 16);
5951 extra[16] = '\0';
5952 dwrq->length = strlen(extra);
5954 return 0;
5957 /*------------------------------------------------------------------*/
5959 * Wireless Handler : set Bit-Rate
5961 static int airo_set_rate(struct net_device *dev,
5962 struct iw_request_info *info,
5963 struct iw_param *vwrq,
5964 char *extra)
5966 struct airo_info *local = dev->ml_priv;
5967 CapabilityRid cap_rid; /* Card capability info */
5968 u8 brate = 0;
5969 int i;
5971 /* First : get a valid bit rate value */
5972 readCapabilityRid(local, &cap_rid, 1);
5974 /* Which type of value ? */
5975 if((vwrq->value < 8) && (vwrq->value >= 0)) {
5976 /* Setting by rate index */
5977 /* Find value in the magic rate table */
5978 brate = cap_rid.supportedRates[vwrq->value];
5979 } else {
5980 /* Setting by frequency value */
5981 u8 normvalue = (u8) (vwrq->value/500000);
5983 /* Check if rate is valid */
5984 for(i = 0 ; i < 8 ; i++) {
5985 if(normvalue == cap_rid.supportedRates[i]) {
5986 brate = normvalue;
5987 break;
5991 /* -1 designed the max rate (mostly auto mode) */
5992 if(vwrq->value == -1) {
5993 /* Get the highest available rate */
5994 for(i = 0 ; i < 8 ; i++) {
5995 if(cap_rid.supportedRates[i] == 0)
5996 break;
5998 if(i != 0)
5999 brate = cap_rid.supportedRates[i - 1];
6001 /* Check that it is valid */
6002 if(brate == 0) {
6003 return -EINVAL;
6006 readConfigRid(local, 1);
6007 /* Now, check if we want a fixed or auto value */
6008 if(vwrq->fixed == 0) {
6009 /* Fill all the rates up to this max rate */
6010 memset(local->config.rates, 0, 8);
6011 for(i = 0 ; i < 8 ; i++) {
6012 local->config.rates[i] = cap_rid.supportedRates[i];
6013 if(local->config.rates[i] == brate)
6014 break;
6016 } else {
6017 /* Fixed mode */
6018 /* One rate, fixed */
6019 memset(local->config.rates, 0, 8);
6020 local->config.rates[0] = brate;
6022 set_bit (FLAG_COMMIT, &local->flags);
6024 return -EINPROGRESS; /* Call commit handler */
6027 /*------------------------------------------------------------------*/
6029 * Wireless Handler : get Bit-Rate
6031 static int airo_get_rate(struct net_device *dev,
6032 struct iw_request_info *info,
6033 struct iw_param *vwrq,
6034 char *extra)
6036 struct airo_info *local = dev->ml_priv;
6037 StatusRid status_rid; /* Card status info */
6039 readStatusRid(local, &status_rid, 1);
6041 vwrq->value = le16_to_cpu(status_rid.currentXmitRate) * 500000;
6042 /* If more than one rate, set auto */
6043 readConfigRid(local, 1);
6044 vwrq->fixed = (local->config.rates[1] == 0);
6046 return 0;
6049 /*------------------------------------------------------------------*/
6051 * Wireless Handler : set RTS threshold
6053 static int airo_set_rts(struct net_device *dev,
6054 struct iw_request_info *info,
6055 struct iw_param *vwrq,
6056 char *extra)
6058 struct airo_info *local = dev->ml_priv;
6059 int rthr = vwrq->value;
6061 if(vwrq->disabled)
6062 rthr = AIRO_DEF_MTU;
6063 if((rthr < 0) || (rthr > AIRO_DEF_MTU)) {
6064 return -EINVAL;
6066 readConfigRid(local, 1);
6067 local->config.rtsThres = cpu_to_le16(rthr);
6068 set_bit (FLAG_COMMIT, &local->flags);
6070 return -EINPROGRESS; /* Call commit handler */
6073 /*------------------------------------------------------------------*/
6075 * Wireless Handler : get RTS threshold
6077 static int airo_get_rts(struct net_device *dev,
6078 struct iw_request_info *info,
6079 struct iw_param *vwrq,
6080 char *extra)
6082 struct airo_info *local = dev->ml_priv;
6084 readConfigRid(local, 1);
6085 vwrq->value = le16_to_cpu(local->config.rtsThres);
6086 vwrq->disabled = (vwrq->value >= AIRO_DEF_MTU);
6087 vwrq->fixed = 1;
6089 return 0;
6092 /*------------------------------------------------------------------*/
6094 * Wireless Handler : set Fragmentation threshold
6096 static int airo_set_frag(struct net_device *dev,
6097 struct iw_request_info *info,
6098 struct iw_param *vwrq,
6099 char *extra)
6101 struct airo_info *local = dev->ml_priv;
6102 int fthr = vwrq->value;
6104 if(vwrq->disabled)
6105 fthr = AIRO_DEF_MTU;
6106 if((fthr < 256) || (fthr > AIRO_DEF_MTU)) {
6107 return -EINVAL;
6109 fthr &= ~0x1; /* Get an even value - is it really needed ??? */
6110 readConfigRid(local, 1);
6111 local->config.fragThresh = cpu_to_le16(fthr);
6112 set_bit (FLAG_COMMIT, &local->flags);
6114 return -EINPROGRESS; /* Call commit handler */
6117 /*------------------------------------------------------------------*/
6119 * Wireless Handler : get Fragmentation threshold
6121 static int airo_get_frag(struct net_device *dev,
6122 struct iw_request_info *info,
6123 struct iw_param *vwrq,
6124 char *extra)
6126 struct airo_info *local = dev->ml_priv;
6128 readConfigRid(local, 1);
6129 vwrq->value = le16_to_cpu(local->config.fragThresh);
6130 vwrq->disabled = (vwrq->value >= AIRO_DEF_MTU);
6131 vwrq->fixed = 1;
6133 return 0;
6136 /*------------------------------------------------------------------*/
6138 * Wireless Handler : set Mode of Operation
6140 static int airo_set_mode(struct net_device *dev,
6141 struct iw_request_info *info,
6142 __u32 *uwrq,
6143 char *extra)
6145 struct airo_info *local = dev->ml_priv;
6146 int reset = 0;
6148 readConfigRid(local, 1);
6149 if (sniffing_mode(local))
6150 reset = 1;
6152 switch(*uwrq) {
6153 case IW_MODE_ADHOC:
6154 local->config.opmode &= ~MODE_CFG_MASK;
6155 local->config.opmode |= MODE_STA_IBSS;
6156 local->config.rmode &= ~RXMODE_FULL_MASK;
6157 local->config.scanMode = SCANMODE_ACTIVE;
6158 clear_bit (FLAG_802_11, &local->flags);
6159 break;
6160 case IW_MODE_INFRA:
6161 local->config.opmode &= ~MODE_CFG_MASK;
6162 local->config.opmode |= MODE_STA_ESS;
6163 local->config.rmode &= ~RXMODE_FULL_MASK;
6164 local->config.scanMode = SCANMODE_ACTIVE;
6165 clear_bit (FLAG_802_11, &local->flags);
6166 break;
6167 case IW_MODE_MASTER:
6168 local->config.opmode &= ~MODE_CFG_MASK;
6169 local->config.opmode |= MODE_AP;
6170 local->config.rmode &= ~RXMODE_FULL_MASK;
6171 local->config.scanMode = SCANMODE_ACTIVE;
6172 clear_bit (FLAG_802_11, &local->flags);
6173 break;
6174 case IW_MODE_REPEAT:
6175 local->config.opmode &= ~MODE_CFG_MASK;
6176 local->config.opmode |= MODE_AP_RPTR;
6177 local->config.rmode &= ~RXMODE_FULL_MASK;
6178 local->config.scanMode = SCANMODE_ACTIVE;
6179 clear_bit (FLAG_802_11, &local->flags);
6180 break;
6181 case IW_MODE_MONITOR:
6182 local->config.opmode &= ~MODE_CFG_MASK;
6183 local->config.opmode |= MODE_STA_ESS;
6184 local->config.rmode &= ~RXMODE_FULL_MASK;
6185 local->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
6186 local->config.scanMode = SCANMODE_PASSIVE;
6187 set_bit (FLAG_802_11, &local->flags);
6188 break;
6189 default:
6190 return -EINVAL;
6192 if (reset)
6193 set_bit (FLAG_RESET, &local->flags);
6194 set_bit (FLAG_COMMIT, &local->flags);
6196 return -EINPROGRESS; /* Call commit handler */
6199 /*------------------------------------------------------------------*/
6201 * Wireless Handler : get Mode of Operation
6203 static int airo_get_mode(struct net_device *dev,
6204 struct iw_request_info *info,
6205 __u32 *uwrq,
6206 char *extra)
6208 struct airo_info *local = dev->ml_priv;
6210 readConfigRid(local, 1);
6211 /* If not managed, assume it's ad-hoc */
6212 switch (local->config.opmode & MODE_CFG_MASK) {
6213 case MODE_STA_ESS:
6214 *uwrq = IW_MODE_INFRA;
6215 break;
6216 case MODE_AP:
6217 *uwrq = IW_MODE_MASTER;
6218 break;
6219 case MODE_AP_RPTR:
6220 *uwrq = IW_MODE_REPEAT;
6221 break;
6222 default:
6223 *uwrq = IW_MODE_ADHOC;
6226 return 0;
6229 static inline int valid_index(CapabilityRid *p, int index)
6231 if (index < 0)
6232 return 0;
6233 return index < (p->softCap & cpu_to_le16(0x80) ? 4 : 1);
6236 /*------------------------------------------------------------------*/
6238 * Wireless Handler : set Encryption Key
6240 static int airo_set_encode(struct net_device *dev,
6241 struct iw_request_info *info,
6242 struct iw_point *dwrq,
6243 char *extra)
6245 struct airo_info *local = dev->ml_priv;
6246 CapabilityRid cap_rid; /* Card capability info */
6247 int perm = ( dwrq->flags & IW_ENCODE_TEMP ? 0 : 1 );
6248 __le16 currentAuthType = local->config.authType;
6250 /* Is WEP supported ? */
6251 readCapabilityRid(local, &cap_rid, 1);
6252 /* Older firmware doesn't support this...
6253 if(!(cap_rid.softCap & cpu_to_le16(2))) {
6254 return -EOPNOTSUPP;
6255 } */
6256 readConfigRid(local, 1);
6258 /* Basic checking: do we have a key to set ?
6259 * Note : with the new API, it's impossible to get a NULL pointer.
6260 * Therefore, we need to check a key size == 0 instead.
6261 * New version of iwconfig properly set the IW_ENCODE_NOKEY flag
6262 * when no key is present (only change flags), but older versions
6263 * don't do it. - Jean II */
6264 if (dwrq->length > 0) {
6265 wep_key_t key;
6266 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6267 int current_index = get_wep_key(local, 0xffff);
6268 /* Check the size of the key */
6269 if (dwrq->length > MAX_KEY_SIZE) {
6270 return -EINVAL;
6272 /* Check the index (none -> use current) */
6273 if (!valid_index(&cap_rid, index))
6274 index = current_index;
6275 /* Set the length */
6276 if (dwrq->length > MIN_KEY_SIZE)
6277 key.len = MAX_KEY_SIZE;
6278 else
6279 if (dwrq->length > 0)
6280 key.len = MIN_KEY_SIZE;
6281 else
6282 /* Disable the key */
6283 key.len = 0;
6284 /* Check if the key is not marked as invalid */
6285 if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
6286 /* Cleanup */
6287 memset(key.key, 0, MAX_KEY_SIZE);
6288 /* Copy the key in the driver */
6289 memcpy(key.key, extra, dwrq->length);
6290 /* Send the key to the card */
6291 set_wep_key(local, index, key.key, key.len, perm, 1);
6293 /* WE specify that if a valid key is set, encryption
6294 * should be enabled (user may turn it off later)
6295 * This is also how "iwconfig ethX key on" works */
6296 if((index == current_index) && (key.len > 0) &&
6297 (local->config.authType == AUTH_OPEN)) {
6298 local->config.authType = AUTH_ENCRYPT;
6300 } else {
6301 /* Do we want to just set the transmit key index ? */
6302 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6303 if (valid_index(&cap_rid, index)) {
6304 set_wep_key(local, index, NULL, 0, perm, 1);
6305 } else
6306 /* Don't complain if only change the mode */
6307 if (!(dwrq->flags & IW_ENCODE_MODE))
6308 return -EINVAL;
6310 /* Read the flags */
6311 if(dwrq->flags & IW_ENCODE_DISABLED)
6312 local->config.authType = AUTH_OPEN; // disable encryption
6313 if(dwrq->flags & IW_ENCODE_RESTRICTED)
6314 local->config.authType = AUTH_SHAREDKEY; // Only Both
6315 if(dwrq->flags & IW_ENCODE_OPEN)
6316 local->config.authType = AUTH_ENCRYPT; // Only Wep
6317 /* Commit the changes to flags if needed */
6318 if (local->config.authType != currentAuthType)
6319 set_bit (FLAG_COMMIT, &local->flags);
6320 return -EINPROGRESS; /* Call commit handler */
6323 /*------------------------------------------------------------------*/
6325 * Wireless Handler : get Encryption Key
6327 static int airo_get_encode(struct net_device *dev,
6328 struct iw_request_info *info,
6329 struct iw_point *dwrq,
6330 char *extra)
6332 struct airo_info *local = dev->ml_priv;
6333 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6334 CapabilityRid cap_rid; /* Card capability info */
6336 /* Is it supported ? */
6337 readCapabilityRid(local, &cap_rid, 1);
6338 if(!(cap_rid.softCap & cpu_to_le16(2))) {
6339 return -EOPNOTSUPP;
6341 readConfigRid(local, 1);
6342 /* Check encryption mode */
6343 switch(local->config.authType) {
6344 case AUTH_ENCRYPT:
6345 dwrq->flags = IW_ENCODE_OPEN;
6346 break;
6347 case AUTH_SHAREDKEY:
6348 dwrq->flags = IW_ENCODE_RESTRICTED;
6349 break;
6350 default:
6351 case AUTH_OPEN:
6352 dwrq->flags = IW_ENCODE_DISABLED;
6353 break;
6355 /* We can't return the key, so set the proper flag and return zero */
6356 dwrq->flags |= IW_ENCODE_NOKEY;
6357 memset(extra, 0, 16);
6359 /* Which key do we want ? -1 -> tx index */
6360 if (!valid_index(&cap_rid, index))
6361 index = get_wep_key(local, 0xffff);
6362 dwrq->flags |= index + 1;
6363 /* Copy the key to the user buffer */
6364 dwrq->length = get_wep_key(local, index);
6365 if (dwrq->length > 16) {
6366 dwrq->length=0;
6368 return 0;
6371 /*------------------------------------------------------------------*/
6373 * Wireless Handler : set extended Encryption parameters
6375 static int airo_set_encodeext(struct net_device *dev,
6376 struct iw_request_info *info,
6377 union iwreq_data *wrqu,
6378 char *extra)
6380 struct airo_info *local = dev->ml_priv;
6381 struct iw_point *encoding = &wrqu->encoding;
6382 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6383 CapabilityRid cap_rid; /* Card capability info */
6384 int perm = ( encoding->flags & IW_ENCODE_TEMP ? 0 : 1 );
6385 __le16 currentAuthType = local->config.authType;
6386 int idx, key_len, alg = ext->alg, set_key = 1;
6387 wep_key_t key;
6389 /* Is WEP supported ? */
6390 readCapabilityRid(local, &cap_rid, 1);
6391 /* Older firmware doesn't support this...
6392 if(!(cap_rid.softCap & cpu_to_le16(2))) {
6393 return -EOPNOTSUPP;
6394 } */
6395 readConfigRid(local, 1);
6397 /* Determine and validate the key index */
6398 idx = encoding->flags & IW_ENCODE_INDEX;
6399 if (idx) {
6400 if (!valid_index(&cap_rid, idx - 1))
6401 return -EINVAL;
6402 idx--;
6403 } else
6404 idx = get_wep_key(local, 0xffff);
6406 if (encoding->flags & IW_ENCODE_DISABLED)
6407 alg = IW_ENCODE_ALG_NONE;
6409 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
6410 /* Only set transmit key index here, actual
6411 * key is set below if needed.
6413 set_wep_key(local, idx, NULL, 0, perm, 1);
6414 set_key = ext->key_len > 0 ? 1 : 0;
6417 if (set_key) {
6418 /* Set the requested key first */
6419 memset(key.key, 0, MAX_KEY_SIZE);
6420 switch (alg) {
6421 case IW_ENCODE_ALG_NONE:
6422 key.len = 0;
6423 break;
6424 case IW_ENCODE_ALG_WEP:
6425 if (ext->key_len > MIN_KEY_SIZE) {
6426 key.len = MAX_KEY_SIZE;
6427 } else if (ext->key_len > 0) {
6428 key.len = MIN_KEY_SIZE;
6429 } else {
6430 return -EINVAL;
6432 key_len = min (ext->key_len, key.len);
6433 memcpy(key.key, ext->key, key_len);
6434 break;
6435 default:
6436 return -EINVAL;
6438 /* Send the key to the card */
6439 set_wep_key(local, idx, key.key, key.len, perm, 1);
6442 /* Read the flags */
6443 if(encoding->flags & IW_ENCODE_DISABLED)
6444 local->config.authType = AUTH_OPEN; // disable encryption
6445 if(encoding->flags & IW_ENCODE_RESTRICTED)
6446 local->config.authType = AUTH_SHAREDKEY; // Only Both
6447 if(encoding->flags & IW_ENCODE_OPEN)
6448 local->config.authType = AUTH_ENCRYPT; // Only Wep
6449 /* Commit the changes to flags if needed */
6450 if (local->config.authType != currentAuthType)
6451 set_bit (FLAG_COMMIT, &local->flags);
6453 return -EINPROGRESS;
6457 /*------------------------------------------------------------------*/
6459 * Wireless Handler : get extended Encryption parameters
6461 static int airo_get_encodeext(struct net_device *dev,
6462 struct iw_request_info *info,
6463 union iwreq_data *wrqu,
6464 char *extra)
6466 struct airo_info *local = dev->ml_priv;
6467 struct iw_point *encoding = &wrqu->encoding;
6468 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6469 CapabilityRid cap_rid; /* Card capability info */
6470 int idx, max_key_len;
6472 /* Is it supported ? */
6473 readCapabilityRid(local, &cap_rid, 1);
6474 if(!(cap_rid.softCap & cpu_to_le16(2))) {
6475 return -EOPNOTSUPP;
6477 readConfigRid(local, 1);
6479 max_key_len = encoding->length - sizeof(*ext);
6480 if (max_key_len < 0)
6481 return -EINVAL;
6483 idx = encoding->flags & IW_ENCODE_INDEX;
6484 if (idx) {
6485 if (!valid_index(&cap_rid, idx - 1))
6486 return -EINVAL;
6487 idx--;
6488 } else
6489 idx = get_wep_key(local, 0xffff);
6491 encoding->flags = idx + 1;
6492 memset(ext, 0, sizeof(*ext));
6494 /* Check encryption mode */
6495 switch(local->config.authType) {
6496 case AUTH_ENCRYPT:
6497 encoding->flags = IW_ENCODE_ALG_WEP | IW_ENCODE_ENABLED;
6498 break;
6499 case AUTH_SHAREDKEY:
6500 encoding->flags = IW_ENCODE_ALG_WEP | IW_ENCODE_ENABLED;
6501 break;
6502 default:
6503 case AUTH_OPEN:
6504 encoding->flags = IW_ENCODE_ALG_NONE | IW_ENCODE_DISABLED;
6505 break;
6507 /* We can't return the key, so set the proper flag and return zero */
6508 encoding->flags |= IW_ENCODE_NOKEY;
6509 memset(extra, 0, 16);
6511 /* Copy the key to the user buffer */
6512 ext->key_len = get_wep_key(local, idx);
6513 if (ext->key_len > 16) {
6514 ext->key_len=0;
6517 return 0;
6521 /*------------------------------------------------------------------*/
6523 * Wireless Handler : set extended authentication parameters
6525 static int airo_set_auth(struct net_device *dev,
6526 struct iw_request_info *info,
6527 union iwreq_data *wrqu, char *extra)
6529 struct airo_info *local = dev->ml_priv;
6530 struct iw_param *param = &wrqu->param;
6531 __le16 currentAuthType = local->config.authType;
6533 switch (param->flags & IW_AUTH_INDEX) {
6534 case IW_AUTH_WPA_VERSION:
6535 case IW_AUTH_CIPHER_PAIRWISE:
6536 case IW_AUTH_CIPHER_GROUP:
6537 case IW_AUTH_KEY_MGMT:
6538 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6539 case IW_AUTH_PRIVACY_INVOKED:
6541 * airo does not use these parameters
6543 break;
6545 case IW_AUTH_DROP_UNENCRYPTED:
6546 if (param->value) {
6547 /* Only change auth type if unencrypted */
6548 if (currentAuthType == AUTH_OPEN)
6549 local->config.authType = AUTH_ENCRYPT;
6550 } else {
6551 local->config.authType = AUTH_OPEN;
6554 /* Commit the changes to flags if needed */
6555 if (local->config.authType != currentAuthType)
6556 set_bit (FLAG_COMMIT, &local->flags);
6557 break;
6559 case IW_AUTH_80211_AUTH_ALG: {
6560 /* FIXME: What about AUTH_OPEN? This API seems to
6561 * disallow setting our auth to AUTH_OPEN.
6563 if (param->value & IW_AUTH_ALG_SHARED_KEY) {
6564 local->config.authType = AUTH_SHAREDKEY;
6565 } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) {
6566 local->config.authType = AUTH_ENCRYPT;
6567 } else
6568 return -EINVAL;
6569 break;
6571 /* Commit the changes to flags if needed */
6572 if (local->config.authType != currentAuthType)
6573 set_bit (FLAG_COMMIT, &local->flags);
6576 case IW_AUTH_WPA_ENABLED:
6577 /* Silently accept disable of WPA */
6578 if (param->value > 0)
6579 return -EOPNOTSUPP;
6580 break;
6582 default:
6583 return -EOPNOTSUPP;
6585 return -EINPROGRESS;
6589 /*------------------------------------------------------------------*/
6591 * Wireless Handler : get extended authentication parameters
6593 static int airo_get_auth(struct net_device *dev,
6594 struct iw_request_info *info,
6595 union iwreq_data *wrqu, char *extra)
6597 struct airo_info *local = dev->ml_priv;
6598 struct iw_param *param = &wrqu->param;
6599 __le16 currentAuthType = local->config.authType;
6601 switch (param->flags & IW_AUTH_INDEX) {
6602 case IW_AUTH_DROP_UNENCRYPTED:
6603 switch (currentAuthType) {
6604 case AUTH_SHAREDKEY:
6605 case AUTH_ENCRYPT:
6606 param->value = 1;
6607 break;
6608 default:
6609 param->value = 0;
6610 break;
6612 break;
6614 case IW_AUTH_80211_AUTH_ALG:
6615 switch (currentAuthType) {
6616 case AUTH_SHAREDKEY:
6617 param->value = IW_AUTH_ALG_SHARED_KEY;
6618 break;
6619 case AUTH_ENCRYPT:
6620 default:
6621 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
6622 break;
6624 break;
6626 case IW_AUTH_WPA_ENABLED:
6627 param->value = 0;
6628 break;
6630 default:
6631 return -EOPNOTSUPP;
6633 return 0;
6637 /*------------------------------------------------------------------*/
6639 * Wireless Handler : set Tx-Power
6641 static int airo_set_txpow(struct net_device *dev,
6642 struct iw_request_info *info,
6643 struct iw_param *vwrq,
6644 char *extra)
6646 struct airo_info *local = dev->ml_priv;
6647 CapabilityRid cap_rid; /* Card capability info */
6648 int i;
6649 int rc = -EINVAL;
6650 __le16 v = cpu_to_le16(vwrq->value);
6652 readCapabilityRid(local, &cap_rid, 1);
6654 if (vwrq->disabled) {
6655 set_bit (FLAG_RADIO_OFF, &local->flags);
6656 set_bit (FLAG_COMMIT, &local->flags);
6657 return -EINPROGRESS; /* Call commit handler */
6659 if (vwrq->flags != IW_TXPOW_MWATT) {
6660 return -EINVAL;
6662 clear_bit (FLAG_RADIO_OFF, &local->flags);
6663 for (i = 0; cap_rid.txPowerLevels[i] && (i < 8); i++)
6664 if (v == cap_rid.txPowerLevels[i]) {
6665 readConfigRid(local, 1);
6666 local->config.txPower = v;
6667 set_bit (FLAG_COMMIT, &local->flags);
6668 rc = -EINPROGRESS; /* Call commit handler */
6669 break;
6671 return rc;
6674 /*------------------------------------------------------------------*/
6676 * Wireless Handler : get Tx-Power
6678 static int airo_get_txpow(struct net_device *dev,
6679 struct iw_request_info *info,
6680 struct iw_param *vwrq,
6681 char *extra)
6683 struct airo_info *local = dev->ml_priv;
6685 readConfigRid(local, 1);
6686 vwrq->value = le16_to_cpu(local->config.txPower);
6687 vwrq->fixed = 1; /* No power control */
6688 vwrq->disabled = test_bit(FLAG_RADIO_OFF, &local->flags);
6689 vwrq->flags = IW_TXPOW_MWATT;
6691 return 0;
6694 /*------------------------------------------------------------------*/
6696 * Wireless Handler : set Retry limits
6698 static int airo_set_retry(struct net_device *dev,
6699 struct iw_request_info *info,
6700 struct iw_param *vwrq,
6701 char *extra)
6703 struct airo_info *local = dev->ml_priv;
6704 int rc = -EINVAL;
6706 if(vwrq->disabled) {
6707 return -EINVAL;
6709 readConfigRid(local, 1);
6710 if(vwrq->flags & IW_RETRY_LIMIT) {
6711 __le16 v = cpu_to_le16(vwrq->value);
6712 if(vwrq->flags & IW_RETRY_LONG)
6713 local->config.longRetryLimit = v;
6714 else if (vwrq->flags & IW_RETRY_SHORT)
6715 local->config.shortRetryLimit = v;
6716 else {
6717 /* No modifier : set both */
6718 local->config.longRetryLimit = v;
6719 local->config.shortRetryLimit = v;
6721 set_bit (FLAG_COMMIT, &local->flags);
6722 rc = -EINPROGRESS; /* Call commit handler */
6724 if(vwrq->flags & IW_RETRY_LIFETIME) {
6725 local->config.txLifetime = cpu_to_le16(vwrq->value / 1024);
6726 set_bit (FLAG_COMMIT, &local->flags);
6727 rc = -EINPROGRESS; /* Call commit handler */
6729 return rc;
6732 /*------------------------------------------------------------------*/
6734 * Wireless Handler : get Retry limits
6736 static int airo_get_retry(struct net_device *dev,
6737 struct iw_request_info *info,
6738 struct iw_param *vwrq,
6739 char *extra)
6741 struct airo_info *local = dev->ml_priv;
6743 vwrq->disabled = 0; /* Can't be disabled */
6745 readConfigRid(local, 1);
6746 /* Note : by default, display the min retry number */
6747 if((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
6748 vwrq->flags = IW_RETRY_LIFETIME;
6749 vwrq->value = le16_to_cpu(local->config.txLifetime) * 1024;
6750 } else if((vwrq->flags & IW_RETRY_LONG)) {
6751 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
6752 vwrq->value = le16_to_cpu(local->config.longRetryLimit);
6753 } else {
6754 vwrq->flags = IW_RETRY_LIMIT;
6755 vwrq->value = le16_to_cpu(local->config.shortRetryLimit);
6756 if(local->config.shortRetryLimit != local->config.longRetryLimit)
6757 vwrq->flags |= IW_RETRY_SHORT;
6760 return 0;
6763 /*------------------------------------------------------------------*/
6765 * Wireless Handler : get range info
6767 static int airo_get_range(struct net_device *dev,
6768 struct iw_request_info *info,
6769 struct iw_point *dwrq,
6770 char *extra)
6772 struct airo_info *local = dev->ml_priv;
6773 struct iw_range *range = (struct iw_range *) extra;
6774 CapabilityRid cap_rid; /* Card capability info */
6775 int i;
6776 int k;
6778 readCapabilityRid(local, &cap_rid, 1);
6780 dwrq->length = sizeof(struct iw_range);
6781 memset(range, 0, sizeof(*range));
6782 range->min_nwid = 0x0000;
6783 range->max_nwid = 0x0000;
6784 range->num_channels = 14;
6785 /* Should be based on cap_rid.country to give only
6786 * what the current card support */
6787 k = 0;
6788 for(i = 0; i < 14; i++) {
6789 range->freq[k].i = i + 1; /* List index */
6790 range->freq[k].m = ieee80211_dsss_chan_to_freq(i + 1) * 100000;
6791 range->freq[k++].e = 1; /* Values in MHz -> * 10^5 * 10 */
6793 range->num_frequency = k;
6795 range->sensitivity = 65535;
6797 /* Hum... Should put the right values there */
6798 if (local->rssi)
6799 range->max_qual.qual = 100; /* % */
6800 else
6801 range->max_qual.qual = airo_get_max_quality(&cap_rid);
6802 range->max_qual.level = 0x100 - 120; /* -120 dBm */
6803 range->max_qual.noise = 0x100 - 120; /* -120 dBm */
6805 /* Experimental measurements - boundary 11/5.5 Mb/s */
6806 /* Note : with or without the (local->rssi), results
6807 * are somewhat different. - Jean II */
6808 if (local->rssi) {
6809 range->avg_qual.qual = 50; /* % */
6810 range->avg_qual.level = 0x100 - 70; /* -70 dBm */
6811 } else {
6812 range->avg_qual.qual = airo_get_avg_quality(&cap_rid);
6813 range->avg_qual.level = 0x100 - 80; /* -80 dBm */
6815 range->avg_qual.noise = 0x100 - 85; /* -85 dBm */
6817 for(i = 0 ; i < 8 ; i++) {
6818 range->bitrate[i] = cap_rid.supportedRates[i] * 500000;
6819 if(range->bitrate[i] == 0)
6820 break;
6822 range->num_bitrates = i;
6824 /* Set an indication of the max TCP throughput
6825 * in bit/s that we can expect using this interface.
6826 * May be use for QoS stuff... Jean II */
6827 if(i > 2)
6828 range->throughput = 5000 * 1000;
6829 else
6830 range->throughput = 1500 * 1000;
6832 range->min_rts = 0;
6833 range->max_rts = AIRO_DEF_MTU;
6834 range->min_frag = 256;
6835 range->max_frag = AIRO_DEF_MTU;
6837 if(cap_rid.softCap & cpu_to_le16(2)) {
6838 // WEP: RC4 40 bits
6839 range->encoding_size[0] = 5;
6840 // RC4 ~128 bits
6841 if (cap_rid.softCap & cpu_to_le16(0x100)) {
6842 range->encoding_size[1] = 13;
6843 range->num_encoding_sizes = 2;
6844 } else
6845 range->num_encoding_sizes = 1;
6846 range->max_encoding_tokens =
6847 cap_rid.softCap & cpu_to_le16(0x80) ? 4 : 1;
6848 } else {
6849 range->num_encoding_sizes = 0;
6850 range->max_encoding_tokens = 0;
6852 range->min_pmp = 0;
6853 range->max_pmp = 5000000; /* 5 secs */
6854 range->min_pmt = 0;
6855 range->max_pmt = 65535 * 1024; /* ??? */
6856 range->pmp_flags = IW_POWER_PERIOD;
6857 range->pmt_flags = IW_POWER_TIMEOUT;
6858 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
6860 /* Transmit Power - values are in mW */
6861 for(i = 0 ; i < 8 ; i++) {
6862 range->txpower[i] = le16_to_cpu(cap_rid.txPowerLevels[i]);
6863 if(range->txpower[i] == 0)
6864 break;
6866 range->num_txpower = i;
6867 range->txpower_capa = IW_TXPOW_MWATT;
6868 range->we_version_source = 19;
6869 range->we_version_compiled = WIRELESS_EXT;
6870 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
6871 range->retry_flags = IW_RETRY_LIMIT;
6872 range->r_time_flags = IW_RETRY_LIFETIME;
6873 range->min_retry = 1;
6874 range->max_retry = 65535;
6875 range->min_r_time = 1024;
6876 range->max_r_time = 65535 * 1024;
6878 /* Event capability (kernel + driver) */
6879 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
6880 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
6881 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
6882 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
6883 range->event_capa[1] = IW_EVENT_CAPA_K_1;
6884 range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVTXDROP);
6885 return 0;
6888 /*------------------------------------------------------------------*/
6890 * Wireless Handler : set Power Management
6892 static int airo_set_power(struct net_device *dev,
6893 struct iw_request_info *info,
6894 struct iw_param *vwrq,
6895 char *extra)
6897 struct airo_info *local = dev->ml_priv;
6899 readConfigRid(local, 1);
6900 if (vwrq->disabled) {
6901 if (sniffing_mode(local))
6902 return -EINVAL;
6903 local->config.powerSaveMode = POWERSAVE_CAM;
6904 local->config.rmode &= ~RXMODE_MASK;
6905 local->config.rmode |= RXMODE_BC_MC_ADDR;
6906 set_bit (FLAG_COMMIT, &local->flags);
6907 return -EINPROGRESS; /* Call commit handler */
6909 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
6910 local->config.fastListenDelay = cpu_to_le16((vwrq->value + 500) / 1024);
6911 local->config.powerSaveMode = POWERSAVE_PSPCAM;
6912 set_bit (FLAG_COMMIT, &local->flags);
6913 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
6914 local->config.fastListenInterval =
6915 local->config.listenInterval =
6916 cpu_to_le16((vwrq->value + 500) / 1024);
6917 local->config.powerSaveMode = POWERSAVE_PSPCAM;
6918 set_bit (FLAG_COMMIT, &local->flags);
6920 switch (vwrq->flags & IW_POWER_MODE) {
6921 case IW_POWER_UNICAST_R:
6922 if (sniffing_mode(local))
6923 return -EINVAL;
6924 local->config.rmode &= ~RXMODE_MASK;
6925 local->config.rmode |= RXMODE_ADDR;
6926 set_bit (FLAG_COMMIT, &local->flags);
6927 break;
6928 case IW_POWER_ALL_R:
6929 if (sniffing_mode(local))
6930 return -EINVAL;
6931 local->config.rmode &= ~RXMODE_MASK;
6932 local->config.rmode |= RXMODE_BC_MC_ADDR;
6933 set_bit (FLAG_COMMIT, &local->flags);
6934 case IW_POWER_ON:
6935 /* This is broken, fixme ;-) */
6936 break;
6937 default:
6938 return -EINVAL;
6940 // Note : we may want to factor local->need_commit here
6941 // Note2 : may also want to factor RXMODE_RFMON test
6942 return -EINPROGRESS; /* Call commit handler */
6945 /*------------------------------------------------------------------*/
6947 * Wireless Handler : get Power Management
6949 static int airo_get_power(struct net_device *dev,
6950 struct iw_request_info *info,
6951 struct iw_param *vwrq,
6952 char *extra)
6954 struct airo_info *local = dev->ml_priv;
6955 __le16 mode;
6957 readConfigRid(local, 1);
6958 mode = local->config.powerSaveMode;
6959 if ((vwrq->disabled = (mode == POWERSAVE_CAM)))
6960 return 0;
6961 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
6962 vwrq->value = le16_to_cpu(local->config.fastListenDelay) * 1024;
6963 vwrq->flags = IW_POWER_TIMEOUT;
6964 } else {
6965 vwrq->value = le16_to_cpu(local->config.fastListenInterval) * 1024;
6966 vwrq->flags = IW_POWER_PERIOD;
6968 if ((local->config.rmode & RXMODE_MASK) == RXMODE_ADDR)
6969 vwrq->flags |= IW_POWER_UNICAST_R;
6970 else
6971 vwrq->flags |= IW_POWER_ALL_R;
6973 return 0;
6976 /*------------------------------------------------------------------*/
6978 * Wireless Handler : set Sensitivity
6980 static int airo_set_sens(struct net_device *dev,
6981 struct iw_request_info *info,
6982 struct iw_param *vwrq,
6983 char *extra)
6985 struct airo_info *local = dev->ml_priv;
6987 readConfigRid(local, 1);
6988 local->config.rssiThreshold =
6989 cpu_to_le16(vwrq->disabled ? RSSI_DEFAULT : vwrq->value);
6990 set_bit (FLAG_COMMIT, &local->flags);
6992 return -EINPROGRESS; /* Call commit handler */
6995 /*------------------------------------------------------------------*/
6997 * Wireless Handler : get Sensitivity
6999 static int airo_get_sens(struct net_device *dev,
7000 struct iw_request_info *info,
7001 struct iw_param *vwrq,
7002 char *extra)
7004 struct airo_info *local = dev->ml_priv;
7006 readConfigRid(local, 1);
7007 vwrq->value = le16_to_cpu(local->config.rssiThreshold);
7008 vwrq->disabled = (vwrq->value == 0);
7009 vwrq->fixed = 1;
7011 return 0;
7014 /*------------------------------------------------------------------*/
7016 * Wireless Handler : get AP List
7017 * Note : this is deprecated in favor of IWSCAN
7019 static int airo_get_aplist(struct net_device *dev,
7020 struct iw_request_info *info,
7021 struct iw_point *dwrq,
7022 char *extra)
7024 struct airo_info *local = dev->ml_priv;
7025 struct sockaddr *address = (struct sockaddr *) extra;
7026 struct iw_quality qual[IW_MAX_AP];
7027 BSSListRid BSSList;
7028 int i;
7029 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
7031 for (i = 0; i < IW_MAX_AP; i++) {
7032 u16 dBm;
7033 if (readBSSListRid(local, loseSync, &BSSList))
7034 break;
7035 loseSync = 0;
7036 memcpy(address[i].sa_data, BSSList.bssid, ETH_ALEN);
7037 address[i].sa_family = ARPHRD_ETHER;
7038 dBm = le16_to_cpu(BSSList.dBm);
7039 if (local->rssi) {
7040 qual[i].level = 0x100 - dBm;
7041 qual[i].qual = airo_dbm_to_pct(local->rssi, dBm);
7042 qual[i].updated = IW_QUAL_QUAL_UPDATED
7043 | IW_QUAL_LEVEL_UPDATED
7044 | IW_QUAL_DBM;
7045 } else {
7046 qual[i].level = (dBm + 321) / 2;
7047 qual[i].qual = 0;
7048 qual[i].updated = IW_QUAL_QUAL_INVALID
7049 | IW_QUAL_LEVEL_UPDATED
7050 | IW_QUAL_DBM;
7052 qual[i].noise = local->wstats.qual.noise;
7053 if (BSSList.index == cpu_to_le16(0xffff))
7054 break;
7056 if (!i) {
7057 StatusRid status_rid; /* Card status info */
7058 readStatusRid(local, &status_rid, 1);
7059 for (i = 0;
7060 i < min(IW_MAX_AP, 4) &&
7061 (status_rid.bssid[i][0]
7062 & status_rid.bssid[i][1]
7063 & status_rid.bssid[i][2]
7064 & status_rid.bssid[i][3]
7065 & status_rid.bssid[i][4]
7066 & status_rid.bssid[i][5])!=0xff &&
7067 (status_rid.bssid[i][0]
7068 | status_rid.bssid[i][1]
7069 | status_rid.bssid[i][2]
7070 | status_rid.bssid[i][3]
7071 | status_rid.bssid[i][4]
7072 | status_rid.bssid[i][5]);
7073 i++) {
7074 memcpy(address[i].sa_data,
7075 status_rid.bssid[i], ETH_ALEN);
7076 address[i].sa_family = ARPHRD_ETHER;
7078 } else {
7079 dwrq->flags = 1; /* Should be define'd */
7080 memcpy(extra + sizeof(struct sockaddr)*i,
7081 &qual, sizeof(struct iw_quality)*i);
7083 dwrq->length = i;
7085 return 0;
7088 /*------------------------------------------------------------------*/
7090 * Wireless Handler : Initiate Scan
7092 static int airo_set_scan(struct net_device *dev,
7093 struct iw_request_info *info,
7094 struct iw_point *dwrq,
7095 char *extra)
7097 struct airo_info *ai = dev->ml_priv;
7098 Cmd cmd;
7099 Resp rsp;
7100 int wake = 0;
7102 /* Note : you may have realised that, as this is a SET operation,
7103 * this is privileged and therefore a normal user can't
7104 * perform scanning.
7105 * This is not an error, while the device perform scanning,
7106 * traffic doesn't flow, so it's a perfect DoS...
7107 * Jean II */
7108 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
7110 if (down_interruptible(&ai->sem))
7111 return -ERESTARTSYS;
7113 /* If there's already a scan in progress, don't
7114 * trigger another one. */
7115 if (ai->scan_timeout > 0)
7116 goto out;
7118 /* Initiate a scan command */
7119 ai->scan_timeout = RUN_AT(3*HZ);
7120 memset(&cmd, 0, sizeof(cmd));
7121 cmd.cmd=CMD_LISTBSS;
7122 issuecommand(ai, &cmd, &rsp);
7123 wake = 1;
7125 out:
7126 up(&ai->sem);
7127 if (wake)
7128 wake_up_interruptible(&ai->thr_wait);
7129 return 0;
7132 /*------------------------------------------------------------------*/
7134 * Translate scan data returned from the card to a card independent
7135 * format that the Wireless Tools will understand - Jean II
7137 static inline char *airo_translate_scan(struct net_device *dev,
7138 struct iw_request_info *info,
7139 char *current_ev,
7140 char *end_buf,
7141 BSSListRid *bss)
7143 struct airo_info *ai = dev->ml_priv;
7144 struct iw_event iwe; /* Temporary buffer */
7145 __le16 capabilities;
7146 char * current_val; /* For rates */
7147 int i;
7148 char * buf;
7149 u16 dBm;
7151 /* First entry *MUST* be the AP MAC address */
7152 iwe.cmd = SIOCGIWAP;
7153 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
7154 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
7155 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7156 &iwe, IW_EV_ADDR_LEN);
7158 /* Other entries will be displayed in the order we give them */
7160 /* Add the ESSID */
7161 iwe.u.data.length = bss->ssidLen;
7162 if(iwe.u.data.length > 32)
7163 iwe.u.data.length = 32;
7164 iwe.cmd = SIOCGIWESSID;
7165 iwe.u.data.flags = 1;
7166 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
7167 &iwe, bss->ssid);
7169 /* Add mode */
7170 iwe.cmd = SIOCGIWMODE;
7171 capabilities = bss->cap;
7172 if(capabilities & (CAP_ESS | CAP_IBSS)) {
7173 if(capabilities & CAP_ESS)
7174 iwe.u.mode = IW_MODE_MASTER;
7175 else
7176 iwe.u.mode = IW_MODE_ADHOC;
7177 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7178 &iwe, IW_EV_UINT_LEN);
7181 /* Add frequency */
7182 iwe.cmd = SIOCGIWFREQ;
7183 iwe.u.freq.m = le16_to_cpu(bss->dsChannel);
7184 iwe.u.freq.m = ieee80211_dsss_chan_to_freq(iwe.u.freq.m) * 100000;
7185 iwe.u.freq.e = 1;
7186 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7187 &iwe, IW_EV_FREQ_LEN);
7189 dBm = le16_to_cpu(bss->dBm);
7191 /* Add quality statistics */
7192 iwe.cmd = IWEVQUAL;
7193 if (ai->rssi) {
7194 iwe.u.qual.level = 0x100 - dBm;
7195 iwe.u.qual.qual = airo_dbm_to_pct(ai->rssi, dBm);
7196 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED
7197 | IW_QUAL_LEVEL_UPDATED
7198 | IW_QUAL_DBM;
7199 } else {
7200 iwe.u.qual.level = (dBm + 321) / 2;
7201 iwe.u.qual.qual = 0;
7202 iwe.u.qual.updated = IW_QUAL_QUAL_INVALID
7203 | IW_QUAL_LEVEL_UPDATED
7204 | IW_QUAL_DBM;
7206 iwe.u.qual.noise = ai->wstats.qual.noise;
7207 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7208 &iwe, IW_EV_QUAL_LEN);
7210 /* Add encryption capability */
7211 iwe.cmd = SIOCGIWENCODE;
7212 if(capabilities & CAP_PRIVACY)
7213 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
7214 else
7215 iwe.u.data.flags = IW_ENCODE_DISABLED;
7216 iwe.u.data.length = 0;
7217 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
7218 &iwe, bss->ssid);
7220 /* Rate : stuffing multiple values in a single event require a bit
7221 * more of magic - Jean II */
7222 current_val = current_ev + iwe_stream_lcp_len(info);
7224 iwe.cmd = SIOCGIWRATE;
7225 /* Those two flags are ignored... */
7226 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
7227 /* Max 8 values */
7228 for(i = 0 ; i < 8 ; i++) {
7229 /* NULL terminated */
7230 if(bss->rates[i] == 0)
7231 break;
7232 /* Bit rate given in 500 kb/s units (+ 0x80) */
7233 iwe.u.bitrate.value = ((bss->rates[i] & 0x7f) * 500000);
7234 /* Add new value to event */
7235 current_val = iwe_stream_add_value(info, current_ev,
7236 current_val, end_buf,
7237 &iwe, IW_EV_PARAM_LEN);
7239 /* Check if we added any event */
7240 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
7241 current_ev = current_val;
7243 /* Beacon interval */
7244 buf = kmalloc(30, GFP_KERNEL);
7245 if (buf) {
7246 iwe.cmd = IWEVCUSTOM;
7247 sprintf(buf, "bcn_int=%d", bss->beaconInterval);
7248 iwe.u.data.length = strlen(buf);
7249 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
7250 &iwe, buf);
7251 kfree(buf);
7254 /* Put WPA/RSN Information Elements into the event stream */
7255 if (test_bit(FLAG_WPA_CAPABLE, &ai->flags)) {
7256 unsigned int num_null_ies = 0;
7257 u16 length = sizeof (bss->extra.iep);
7258 u8 *ie = (void *)&bss->extra.iep;
7260 while ((length >= 2) && (num_null_ies < 2)) {
7261 if (2 + ie[1] > length) {
7262 /* Invalid element, don't continue parsing IE */
7263 break;
7266 switch (ie[0]) {
7267 case WLAN_EID_SSID:
7268 /* Two zero-length SSID elements
7269 * mean we're done parsing elements */
7270 if (!ie[1])
7271 num_null_ies++;
7272 break;
7274 case WLAN_EID_GENERIC:
7275 if (ie[1] >= 4 &&
7276 ie[2] == 0x00 &&
7277 ie[3] == 0x50 &&
7278 ie[4] == 0xf2 &&
7279 ie[5] == 0x01) {
7280 iwe.cmd = IWEVGENIE;
7281 /* 64 is an arbitrary cut-off */
7282 iwe.u.data.length = min(ie[1] + 2,
7283 64);
7284 current_ev = iwe_stream_add_point(
7285 info, current_ev,
7286 end_buf, &iwe, ie);
7288 break;
7290 case WLAN_EID_RSN:
7291 iwe.cmd = IWEVGENIE;
7292 /* 64 is an arbitrary cut-off */
7293 iwe.u.data.length = min(ie[1] + 2, 64);
7294 current_ev = iwe_stream_add_point(
7295 info, current_ev, end_buf,
7296 &iwe, ie);
7297 break;
7299 default:
7300 break;
7303 length -= 2 + ie[1];
7304 ie += 2 + ie[1];
7307 return current_ev;
7310 /*------------------------------------------------------------------*/
7312 * Wireless Handler : Read Scan Results
7314 static int airo_get_scan(struct net_device *dev,
7315 struct iw_request_info *info,
7316 struct iw_point *dwrq,
7317 char *extra)
7319 struct airo_info *ai = dev->ml_priv;
7320 BSSListElement *net;
7321 int err = 0;
7322 char *current_ev = extra;
7324 /* If a scan is in-progress, return -EAGAIN */
7325 if (ai->scan_timeout > 0)
7326 return -EAGAIN;
7328 if (down_interruptible(&ai->sem))
7329 return -EAGAIN;
7331 list_for_each_entry (net, &ai->network_list, list) {
7332 /* Translate to WE format this entry */
7333 current_ev = airo_translate_scan(dev, info, current_ev,
7334 extra + dwrq->length,
7335 &net->bss);
7337 /* Check if there is space for one more entry */
7338 if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) {
7339 /* Ask user space to try again with a bigger buffer */
7340 err = -E2BIG;
7341 goto out;
7345 /* Length of data */
7346 dwrq->length = (current_ev - extra);
7347 dwrq->flags = 0; /* todo */
7349 out:
7350 up(&ai->sem);
7351 return err;
7354 /*------------------------------------------------------------------*/
7356 * Commit handler : called after a bunch of SET operations
7358 static int airo_config_commit(struct net_device *dev,
7359 struct iw_request_info *info, /* NULL */
7360 void *zwrq, /* NULL */
7361 char *extra) /* NULL */
7363 struct airo_info *local = dev->ml_priv;
7365 if (!test_bit (FLAG_COMMIT, &local->flags))
7366 return 0;
7368 /* Some of the "SET" function may have modified some of the
7369 * parameters. It's now time to commit them in the card */
7370 disable_MAC(local, 1);
7371 if (test_bit (FLAG_RESET, &local->flags)) {
7372 APListRid APList_rid;
7373 SsidRid SSID_rid;
7375 readAPListRid(local, &APList_rid);
7376 readSsidRid(local, &SSID_rid);
7377 if (test_bit(FLAG_MPI,&local->flags))
7378 setup_card(local, dev->dev_addr, 1 );
7379 else
7380 reset_airo_card(dev);
7381 disable_MAC(local, 1);
7382 writeSsidRid(local, &SSID_rid, 1);
7383 writeAPListRid(local, &APList_rid, 1);
7385 if (down_interruptible(&local->sem))
7386 return -ERESTARTSYS;
7387 writeConfigRid(local, 0);
7388 enable_MAC(local, 0);
7389 if (test_bit (FLAG_RESET, &local->flags))
7390 airo_set_promisc(local);
7391 else
7392 up(&local->sem);
7394 return 0;
7397 /*------------------------------------------------------------------*/
7399 * Structures to export the Wireless Handlers
7402 static const struct iw_priv_args airo_private_args[] = {
7403 /*{ cmd, set_args, get_args, name } */
7404 { AIROIOCTL, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
7405 IW_PRIV_TYPE_BYTE | 2047, "airoioctl" },
7406 { AIROIDIFC, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
7407 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "airoidifc" },
7410 static const iw_handler airo_handler[] =
7412 (iw_handler) airo_config_commit, /* SIOCSIWCOMMIT */
7413 (iw_handler) airo_get_name, /* SIOCGIWNAME */
7414 (iw_handler) NULL, /* SIOCSIWNWID */
7415 (iw_handler) NULL, /* SIOCGIWNWID */
7416 (iw_handler) airo_set_freq, /* SIOCSIWFREQ */
7417 (iw_handler) airo_get_freq, /* SIOCGIWFREQ */
7418 (iw_handler) airo_set_mode, /* SIOCSIWMODE */
7419 (iw_handler) airo_get_mode, /* SIOCGIWMODE */
7420 (iw_handler) airo_set_sens, /* SIOCSIWSENS */
7421 (iw_handler) airo_get_sens, /* SIOCGIWSENS */
7422 (iw_handler) NULL, /* SIOCSIWRANGE */
7423 (iw_handler) airo_get_range, /* SIOCGIWRANGE */
7424 (iw_handler) NULL, /* SIOCSIWPRIV */
7425 (iw_handler) NULL, /* SIOCGIWPRIV */
7426 (iw_handler) NULL, /* SIOCSIWSTATS */
7427 (iw_handler) NULL, /* SIOCGIWSTATS */
7428 iw_handler_set_spy, /* SIOCSIWSPY */
7429 iw_handler_get_spy, /* SIOCGIWSPY */
7430 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
7431 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
7432 (iw_handler) airo_set_wap, /* SIOCSIWAP */
7433 (iw_handler) airo_get_wap, /* SIOCGIWAP */
7434 (iw_handler) NULL, /* -- hole -- */
7435 (iw_handler) airo_get_aplist, /* SIOCGIWAPLIST */
7436 (iw_handler) airo_set_scan, /* SIOCSIWSCAN */
7437 (iw_handler) airo_get_scan, /* SIOCGIWSCAN */
7438 (iw_handler) airo_set_essid, /* SIOCSIWESSID */
7439 (iw_handler) airo_get_essid, /* SIOCGIWESSID */
7440 (iw_handler) airo_set_nick, /* SIOCSIWNICKN */
7441 (iw_handler) airo_get_nick, /* SIOCGIWNICKN */
7442 (iw_handler) NULL, /* -- hole -- */
7443 (iw_handler) NULL, /* -- hole -- */
7444 (iw_handler) airo_set_rate, /* SIOCSIWRATE */
7445 (iw_handler) airo_get_rate, /* SIOCGIWRATE */
7446 (iw_handler) airo_set_rts, /* SIOCSIWRTS */
7447 (iw_handler) airo_get_rts, /* SIOCGIWRTS */
7448 (iw_handler) airo_set_frag, /* SIOCSIWFRAG */
7449 (iw_handler) airo_get_frag, /* SIOCGIWFRAG */
7450 (iw_handler) airo_set_txpow, /* SIOCSIWTXPOW */
7451 (iw_handler) airo_get_txpow, /* SIOCGIWTXPOW */
7452 (iw_handler) airo_set_retry, /* SIOCSIWRETRY */
7453 (iw_handler) airo_get_retry, /* SIOCGIWRETRY */
7454 (iw_handler) airo_set_encode, /* SIOCSIWENCODE */
7455 (iw_handler) airo_get_encode, /* SIOCGIWENCODE */
7456 (iw_handler) airo_set_power, /* SIOCSIWPOWER */
7457 (iw_handler) airo_get_power, /* SIOCGIWPOWER */
7458 (iw_handler) NULL, /* -- hole -- */
7459 (iw_handler) NULL, /* -- hole -- */
7460 (iw_handler) NULL, /* SIOCSIWGENIE */
7461 (iw_handler) NULL, /* SIOCGIWGENIE */
7462 (iw_handler) airo_set_auth, /* SIOCSIWAUTH */
7463 (iw_handler) airo_get_auth, /* SIOCGIWAUTH */
7464 (iw_handler) airo_set_encodeext, /* SIOCSIWENCODEEXT */
7465 (iw_handler) airo_get_encodeext, /* SIOCGIWENCODEEXT */
7466 (iw_handler) NULL, /* SIOCSIWPMKSA */
7469 /* Note : don't describe AIROIDIFC and AIROOLDIDIFC in here.
7470 * We want to force the use of the ioctl code, because those can't be
7471 * won't work the iw_handler code (because they simultaneously read
7472 * and write data and iw_handler can't do that).
7473 * Note that it's perfectly legal to read/write on a single ioctl command,
7474 * you just can't use iwpriv and need to force it via the ioctl handler.
7475 * Jean II */
7476 static const iw_handler airo_private_handler[] =
7478 NULL, /* SIOCIWFIRSTPRIV */
7481 static const struct iw_handler_def airo_handler_def =
7483 .num_standard = ARRAY_SIZE(airo_handler),
7484 .num_private = ARRAY_SIZE(airo_private_handler),
7485 .num_private_args = ARRAY_SIZE(airo_private_args),
7486 .standard = airo_handler,
7487 .private = airo_private_handler,
7488 .private_args = airo_private_args,
7489 .get_wireless_stats = airo_get_wireless_stats,
7493 * This defines the configuration part of the Wireless Extensions
7494 * Note : irq and spinlock protection will occur in the subroutines
7496 * TODO :
7497 * o Check input value more carefully and fill correct values in range
7498 * o Test and shakeout the bugs (if any)
7500 * Jean II
7502 * Javier Achirica did a great job of merging code from the unnamed CISCO
7503 * developer that added support for flashing the card.
7505 static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
7507 int rc = 0;
7508 struct airo_info *ai = dev->ml_priv;
7510 if (ai->power.event)
7511 return 0;
7513 switch (cmd) {
7514 #ifdef CISCO_EXT
7515 case AIROIDIFC:
7516 #ifdef AIROOLDIDIFC
7517 case AIROOLDIDIFC:
7518 #endif
7520 int val = AIROMAGIC;
7521 aironet_ioctl com;
7522 if (copy_from_user(&com,rq->ifr_data,sizeof(com)))
7523 rc = -EFAULT;
7524 else if (copy_to_user(com.data,(char *)&val,sizeof(val)))
7525 rc = -EFAULT;
7527 break;
7529 case AIROIOCTL:
7530 #ifdef AIROOLDIOCTL
7531 case AIROOLDIOCTL:
7532 #endif
7533 /* Get the command struct and hand it off for evaluation by
7534 * the proper subfunction
7537 aironet_ioctl com;
7538 if (copy_from_user(&com,rq->ifr_data,sizeof(com))) {
7539 rc = -EFAULT;
7540 break;
7543 /* Separate R/W functions bracket legality here
7545 if ( com.command == AIRORSWVERSION ) {
7546 if (copy_to_user(com.data, swversion, sizeof(swversion)))
7547 rc = -EFAULT;
7548 else
7549 rc = 0;
7551 else if ( com.command <= AIRORRID)
7552 rc = readrids(dev,&com);
7553 else if ( com.command >= AIROPCAP && com.command <= (AIROPLEAPUSR+2) )
7554 rc = writerids(dev,&com);
7555 else if ( com.command >= AIROFLSHRST && com.command <= AIRORESTART )
7556 rc = flashcard(dev,&com);
7557 else
7558 rc = -EINVAL; /* Bad command in ioctl */
7560 break;
7561 #endif /* CISCO_EXT */
7563 // All other calls are currently unsupported
7564 default:
7565 rc = -EOPNOTSUPP;
7567 return rc;
7571 * Get the Wireless stats out of the driver
7572 * Note : irq and spinlock protection will occur in the subroutines
7574 * TODO :
7575 * o Check if work in Ad-Hoc mode (otherwise, use SPY, as in wvlan_cs)
7577 * Jean
7579 static void airo_read_wireless_stats(struct airo_info *local)
7581 StatusRid status_rid;
7582 StatsRid stats_rid;
7583 CapabilityRid cap_rid;
7584 __le32 *vals = stats_rid.vals;
7586 /* Get stats out of the card */
7587 clear_bit(JOB_WSTATS, &local->jobs);
7588 if (local->power.event) {
7589 up(&local->sem);
7590 return;
7592 readCapabilityRid(local, &cap_rid, 0);
7593 readStatusRid(local, &status_rid, 0);
7594 readStatsRid(local, &stats_rid, RID_STATS, 0);
7595 up(&local->sem);
7597 /* The status */
7598 local->wstats.status = le16_to_cpu(status_rid.mode);
7600 /* Signal quality and co */
7601 if (local->rssi) {
7602 local->wstats.qual.level =
7603 airo_rssi_to_dbm(local->rssi,
7604 le16_to_cpu(status_rid.sigQuality));
7605 /* normalizedSignalStrength appears to be a percentage */
7606 local->wstats.qual.qual =
7607 le16_to_cpu(status_rid.normalizedSignalStrength);
7608 } else {
7609 local->wstats.qual.level =
7610 (le16_to_cpu(status_rid.normalizedSignalStrength) + 321) / 2;
7611 local->wstats.qual.qual = airo_get_quality(&status_rid, &cap_rid);
7613 if (le16_to_cpu(status_rid.len) >= 124) {
7614 local->wstats.qual.noise = 0x100 - status_rid.noisedBm;
7615 local->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
7616 } else {
7617 local->wstats.qual.noise = 0;
7618 local->wstats.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_INVALID | IW_QUAL_DBM;
7621 /* Packets discarded in the wireless adapter due to wireless
7622 * specific problems */
7623 local->wstats.discard.nwid = le32_to_cpu(vals[56]) +
7624 le32_to_cpu(vals[57]) +
7625 le32_to_cpu(vals[58]); /* SSID Mismatch */
7626 local->wstats.discard.code = le32_to_cpu(vals[6]);/* RxWepErr */
7627 local->wstats.discard.fragment = le32_to_cpu(vals[30]);
7628 local->wstats.discard.retries = le32_to_cpu(vals[10]);
7629 local->wstats.discard.misc = le32_to_cpu(vals[1]) +
7630 le32_to_cpu(vals[32]);
7631 local->wstats.miss.beacon = le32_to_cpu(vals[34]);
7634 static struct iw_statistics *airo_get_wireless_stats(struct net_device *dev)
7636 struct airo_info *local = dev->ml_priv;
7638 if (!test_bit(JOB_WSTATS, &local->jobs)) {
7639 /* Get stats out of the card if available */
7640 if (down_trylock(&local->sem) != 0) {
7641 set_bit(JOB_WSTATS, &local->jobs);
7642 wake_up_interruptible(&local->thr_wait);
7643 } else
7644 airo_read_wireless_stats(local);
7647 return &local->wstats;
7650 #ifdef CISCO_EXT
7652 * This just translates from driver IOCTL codes to the command codes to
7653 * feed to the radio's host interface. Things can be added/deleted
7654 * as needed. This represents the READ side of control I/O to
7655 * the card
7657 static int readrids(struct net_device *dev, aironet_ioctl *comp) {
7658 unsigned short ridcode;
7659 unsigned char *iobuf;
7660 int len;
7661 struct airo_info *ai = dev->ml_priv;
7663 if (test_bit(FLAG_FLASHING, &ai->flags))
7664 return -EIO;
7666 switch(comp->command)
7668 case AIROGCAP: ridcode = RID_CAPABILITIES; break;
7669 case AIROGCFG: ridcode = RID_CONFIG;
7670 if (test_bit(FLAG_COMMIT, &ai->flags)) {
7671 disable_MAC (ai, 1);
7672 writeConfigRid (ai, 1);
7673 enable_MAC(ai, 1);
7675 break;
7676 case AIROGSLIST: ridcode = RID_SSID; break;
7677 case AIROGVLIST: ridcode = RID_APLIST; break;
7678 case AIROGDRVNAM: ridcode = RID_DRVNAME; break;
7679 case AIROGEHTENC: ridcode = RID_ETHERENCAP; break;
7680 case AIROGWEPKTMP: ridcode = RID_WEP_TEMP;
7681 /* Only super-user can read WEP keys */
7682 if (!capable(CAP_NET_ADMIN))
7683 return -EPERM;
7684 break;
7685 case AIROGWEPKNV: ridcode = RID_WEP_PERM;
7686 /* Only super-user can read WEP keys */
7687 if (!capable(CAP_NET_ADMIN))
7688 return -EPERM;
7689 break;
7690 case AIROGSTAT: ridcode = RID_STATUS; break;
7691 case AIROGSTATSD32: ridcode = RID_STATSDELTA; break;
7692 case AIROGSTATSC32: ridcode = RID_STATS; break;
7693 case AIROGMICSTATS:
7694 if (copy_to_user(comp->data, &ai->micstats,
7695 min((int)comp->len,(int)sizeof(ai->micstats))))
7696 return -EFAULT;
7697 return 0;
7698 case AIRORRID: ridcode = comp->ridnum; break;
7699 default:
7700 return -EINVAL;
7701 break;
7704 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7705 return -ENOMEM;
7707 PC4500_readrid(ai,ridcode,iobuf,RIDSIZE, 1);
7708 /* get the count of bytes in the rid docs say 1st 2 bytes is it.
7709 * then return it to the user
7710 * 9/22/2000 Honor user given length
7712 len = comp->len;
7714 if (copy_to_user(comp->data, iobuf, min(len, (int)RIDSIZE))) {
7715 kfree (iobuf);
7716 return -EFAULT;
7718 kfree (iobuf);
7719 return 0;
7723 * Danger Will Robinson write the rids here
7726 static int writerids(struct net_device *dev, aironet_ioctl *comp) {
7727 struct airo_info *ai = dev->ml_priv;
7728 int ridcode;
7729 int enabled;
7730 static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
7731 unsigned char *iobuf;
7733 /* Only super-user can write RIDs */
7734 if (!capable(CAP_NET_ADMIN))
7735 return -EPERM;
7737 if (test_bit(FLAG_FLASHING, &ai->flags))
7738 return -EIO;
7740 ridcode = 0;
7741 writer = do_writerid;
7743 switch(comp->command)
7745 case AIROPSIDS: ridcode = RID_SSID; break;
7746 case AIROPCAP: ridcode = RID_CAPABILITIES; break;
7747 case AIROPAPLIST: ridcode = RID_APLIST; break;
7748 case AIROPCFG: ai->config.len = 0;
7749 clear_bit(FLAG_COMMIT, &ai->flags);
7750 ridcode = RID_CONFIG; break;
7751 case AIROPWEPKEYNV: ridcode = RID_WEP_PERM; break;
7752 case AIROPLEAPUSR: ridcode = RID_LEAPUSERNAME; break;
7753 case AIROPLEAPPWD: ridcode = RID_LEAPPASSWORD; break;
7754 case AIROPWEPKEY: ridcode = RID_WEP_TEMP; writer = PC4500_writerid;
7755 break;
7756 case AIROPLEAPUSR+1: ridcode = 0xFF2A; break;
7757 case AIROPLEAPUSR+2: ridcode = 0xFF2B; break;
7759 /* this is not really a rid but a command given to the card
7760 * same with MAC off
7762 case AIROPMACON:
7763 if (enable_MAC(ai, 1) != 0)
7764 return -EIO;
7765 return 0;
7768 * Evidently this code in the airo driver does not get a symbol
7769 * as disable_MAC. it's probably so short the compiler does not gen one.
7771 case AIROPMACOFF:
7772 disable_MAC(ai, 1);
7773 return 0;
7775 /* This command merely clears the counts does not actually store any data
7776 * only reads rid. But as it changes the cards state, I put it in the
7777 * writerid routines.
7779 case AIROPSTCLR:
7780 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7781 return -ENOMEM;
7783 PC4500_readrid(ai,RID_STATSDELTACLEAR,iobuf,RIDSIZE, 1);
7785 enabled = ai->micstats.enabled;
7786 memset(&ai->micstats,0,sizeof(ai->micstats));
7787 ai->micstats.enabled = enabled;
7789 if (copy_to_user(comp->data, iobuf,
7790 min((int)comp->len, (int)RIDSIZE))) {
7791 kfree (iobuf);
7792 return -EFAULT;
7794 kfree (iobuf);
7795 return 0;
7797 default:
7798 return -EOPNOTSUPP; /* Blarg! */
7800 if(comp->len > RIDSIZE)
7801 return -EINVAL;
7803 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7804 return -ENOMEM;
7806 if (copy_from_user(iobuf,comp->data,comp->len)) {
7807 kfree (iobuf);
7808 return -EFAULT;
7811 if (comp->command == AIROPCFG) {
7812 ConfigRid *cfg = (ConfigRid *)iobuf;
7814 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags))
7815 cfg->opmode |= MODE_MIC;
7817 if ((cfg->opmode & MODE_CFG_MASK) == MODE_STA_IBSS)
7818 set_bit (FLAG_ADHOC, &ai->flags);
7819 else
7820 clear_bit (FLAG_ADHOC, &ai->flags);
7823 if((*writer)(ai, ridcode, iobuf,comp->len,1)) {
7824 kfree (iobuf);
7825 return -EIO;
7827 kfree (iobuf);
7828 return 0;
7831 /*****************************************************************************
7832 * Ancillary flash / mod functions much black magic lurkes here *
7833 *****************************************************************************
7837 * Flash command switch table
7840 static int flashcard(struct net_device *dev, aironet_ioctl *comp) {
7841 int z;
7843 /* Only super-user can modify flash */
7844 if (!capable(CAP_NET_ADMIN))
7845 return -EPERM;
7847 switch(comp->command)
7849 case AIROFLSHRST:
7850 return cmdreset((struct airo_info *)dev->ml_priv);
7852 case AIROFLSHSTFL:
7853 if (!AIRO_FLASH(dev) &&
7854 (AIRO_FLASH(dev) = kmalloc(FLASHSIZE, GFP_KERNEL)) == NULL)
7855 return -ENOMEM;
7856 return setflashmode((struct airo_info *)dev->ml_priv);
7858 case AIROFLSHGCHR: /* Get char from aux */
7859 if(comp->len != sizeof(int))
7860 return -EINVAL;
7861 if (copy_from_user(&z,comp->data,comp->len))
7862 return -EFAULT;
7863 return flashgchar((struct airo_info *)dev->ml_priv, z, 8000);
7865 case AIROFLSHPCHR: /* Send char to card. */
7866 if(comp->len != sizeof(int))
7867 return -EINVAL;
7868 if (copy_from_user(&z,comp->data,comp->len))
7869 return -EFAULT;
7870 return flashpchar((struct airo_info *)dev->ml_priv, z, 8000);
7872 case AIROFLPUTBUF: /* Send 32k to card */
7873 if (!AIRO_FLASH(dev))
7874 return -ENOMEM;
7875 if(comp->len > FLASHSIZE)
7876 return -EINVAL;
7877 if (copy_from_user(AIRO_FLASH(dev), comp->data, comp->len))
7878 return -EFAULT;
7880 flashputbuf((struct airo_info *)dev->ml_priv);
7881 return 0;
7883 case AIRORESTART:
7884 if (flashrestart((struct airo_info *)dev->ml_priv, dev))
7885 return -EIO;
7886 return 0;
7888 return -EINVAL;
7891 #define FLASH_COMMAND 0x7e7e
7894 * STEP 1)
7895 * Disable MAC and do soft reset on
7896 * card.
7899 static int cmdreset(struct airo_info *ai) {
7900 disable_MAC(ai, 1);
7902 if(!waitbusy (ai)){
7903 airo_print_info(ai->dev->name, "Waitbusy hang before RESET");
7904 return -EBUSY;
7907 OUT4500(ai,COMMAND,CMD_SOFTRESET);
7909 ssleep(1); /* WAS 600 12/7/00 */
7911 if(!waitbusy (ai)){
7912 airo_print_info(ai->dev->name, "Waitbusy hang AFTER RESET");
7913 return -EBUSY;
7915 return 0;
7918 /* STEP 2)
7919 * Put the card in legendary flash
7920 * mode
7923 static int setflashmode (struct airo_info *ai) {
7924 set_bit (FLAG_FLASHING, &ai->flags);
7926 OUT4500(ai, SWS0, FLASH_COMMAND);
7927 OUT4500(ai, SWS1, FLASH_COMMAND);
7928 if (probe) {
7929 OUT4500(ai, SWS0, FLASH_COMMAND);
7930 OUT4500(ai, COMMAND,0x10);
7931 } else {
7932 OUT4500(ai, SWS2, FLASH_COMMAND);
7933 OUT4500(ai, SWS3, FLASH_COMMAND);
7934 OUT4500(ai, COMMAND,0);
7936 msleep(500); /* 500ms delay */
7938 if(!waitbusy(ai)) {
7939 clear_bit (FLAG_FLASHING, &ai->flags);
7940 airo_print_info(ai->dev->name, "Waitbusy hang after setflash mode");
7941 return -EIO;
7943 return 0;
7946 /* Put character to SWS0 wait for dwelltime
7947 * x 50us for echo .
7950 static int flashpchar(struct airo_info *ai,int byte,int dwelltime) {
7951 int echo;
7952 int waittime;
7954 byte |= 0x8000;
7956 if(dwelltime == 0 )
7957 dwelltime = 200;
7959 waittime=dwelltime;
7961 /* Wait for busy bit d15 to go false indicating buffer empty */
7962 while ((IN4500 (ai, SWS0) & 0x8000) && waittime > 0) {
7963 udelay (50);
7964 waittime -= 50;
7967 /* timeout for busy clear wait */
7968 if(waittime <= 0 ){
7969 airo_print_info(ai->dev->name, "flash putchar busywait timeout!");
7970 return -EBUSY;
7973 /* Port is clear now write byte and wait for it to echo back */
7974 do {
7975 OUT4500(ai,SWS0,byte);
7976 udelay(50);
7977 dwelltime -= 50;
7978 echo = IN4500(ai,SWS1);
7979 } while (dwelltime >= 0 && echo != byte);
7981 OUT4500(ai,SWS1,0);
7983 return (echo == byte) ? 0 : -EIO;
7987 * Get a character from the card matching matchbyte
7988 * Step 3)
7990 static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime){
7991 int rchar;
7992 unsigned char rbyte=0;
7994 do {
7995 rchar = IN4500(ai,SWS1);
7997 if(dwelltime && !(0x8000 & rchar)){
7998 dwelltime -= 10;
7999 mdelay(10);
8000 continue;
8002 rbyte = 0xff & rchar;
8004 if( (rbyte == matchbyte) && (0x8000 & rchar) ){
8005 OUT4500(ai,SWS1,0);
8006 return 0;
8008 if( rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
8009 break;
8010 OUT4500(ai,SWS1,0);
8012 }while(dwelltime > 0);
8013 return -EIO;
8017 * Transfer 32k of firmware data from user buffer to our buffer and
8018 * send to the card
8021 static int flashputbuf(struct airo_info *ai){
8022 int nwords;
8024 /* Write stuff */
8025 if (test_bit(FLAG_MPI,&ai->flags))
8026 memcpy_toio(ai->pciaux + 0x8000, ai->flash, FLASHSIZE);
8027 else {
8028 OUT4500(ai,AUXPAGE,0x100);
8029 OUT4500(ai,AUXOFF,0);
8031 for(nwords=0;nwords != FLASHSIZE / 2;nwords++){
8032 OUT4500(ai,AUXDATA,ai->flash[nwords] & 0xffff);
8035 OUT4500(ai,SWS0,0x8000);
8037 return 0;
8043 static int flashrestart(struct airo_info *ai,struct net_device *dev){
8044 int i,status;
8046 ssleep(1); /* Added 12/7/00 */
8047 clear_bit (FLAG_FLASHING, &ai->flags);
8048 if (test_bit(FLAG_MPI, &ai->flags)) {
8049 status = mpi_init_descriptors(ai);
8050 if (status != SUCCESS)
8051 return status;
8053 status = setup_card(ai, dev->dev_addr, 1);
8055 if (!test_bit(FLAG_MPI,&ai->flags))
8056 for( i = 0; i < MAX_FIDS; i++ ) {
8057 ai->fids[i] = transmit_allocate
8058 ( ai, AIRO_DEF_MTU, i >= MAX_FIDS / 2 );
8061 ssleep(1); /* Added 12/7/00 */
8062 return status;
8064 #endif /* CISCO_EXT */
8067 This program is free software; you can redistribute it and/or
8068 modify it under the terms of the GNU General Public License
8069 as published by the Free Software Foundation; either version 2
8070 of the License, or (at your option) any later version.
8072 This program is distributed in the hope that it will be useful,
8073 but WITHOUT ANY WARRANTY; without even the implied warranty of
8074 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8075 GNU General Public License for more details.
8077 In addition:
8079 Redistribution and use in source and binary forms, with or without
8080 modification, are permitted provided that the following conditions
8081 are met:
8083 1. Redistributions of source code must retain the above copyright
8084 notice, this list of conditions and the following disclaimer.
8085 2. Redistributions in binary form must reproduce the above copyright
8086 notice, this list of conditions and the following disclaimer in the
8087 documentation and/or other materials provided with the distribution.
8088 3. The name of the author may not be used to endorse or promote
8089 products derived from this software without specific prior written
8090 permission.
8092 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
8093 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
8094 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
8095 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
8096 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
8097 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
8098 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
8099 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
8100 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
8101 IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
8102 POSSIBILITY OF SUCH DAMAGE.
8105 module_init(airo_init_module);
8106 module_exit(airo_cleanup_module);