]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /*====================================================================== |
2 | ||
3 | Aironet driver for 4500 and 4800 series cards | |
4 | ||
5 | This code is released under both the GPL version 2 and BSD licenses. | |
6 | Either license may be used. The respective licenses are found at | |
7 | the end of this file. | |
8 | ||
9 | This code was developed by Benjamin Reed <[email protected]> | |
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 | <[email protected]> and Jean Tourrilhes <[email protected]>. | |
16 | Code was also integrated from the Cisco Aironet driver for Linux. | |
17 | Support for MPI350 cards was added by Fabrice Bellet | |
18 | <[email protected]>. | |
19 | ||
20 | ======================================================================*/ | |
21 | ||
f12cc209 | 22 | #include <linux/err.h> |
1da177e4 LT |
23 | #include <linux/init.h> |
24 | ||
25 | #include <linux/kernel.h> | |
26 | #include <linux/module.h> | |
27 | #include <linux/proc_fs.h> | |
1da177e4 LT |
28 | |
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> | |
378f058c | 37 | #include <linux/scatterlist.h> |
a39d3e79 | 38 | #include <linux/crypto.h> |
1da177e4 LT |
39 | #include <asm/io.h> |
40 | #include <asm/system.h> | |
593c2b9c | 41 | #include <asm/unaligned.h> |
1da177e4 LT |
42 | |
43 | #include <linux/netdevice.h> | |
44 | #include <linux/etherdevice.h> | |
45 | #include <linux/skbuff.h> | |
46 | #include <linux/if_arp.h> | |
47 | #include <linux/ioport.h> | |
48 | #include <linux/pci.h> | |
49 | #include <asm/uaccess.h> | |
3b4c7d64 | 50 | #include <linux/kthread.h> |
7dfb7103 | 51 | #include <linux/freezer.h> |
1da177e4 | 52 | |
2c706002 JB |
53 | #include <linux/ieee80211.h> |
54 | ||
d3808760 AB |
55 | #include "airo.h" |
56 | ||
1138c37b MS |
57 | #define DRV_NAME "airo" |
58 | ||
1da177e4 LT |
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, } | |
69 | }; | |
70 | MODULE_DEVICE_TABLE(pci, card_ids); | |
71 | ||
72 | static int airo_pci_probe(struct pci_dev *, const struct pci_device_id *); | |
73 | static void airo_pci_remove(struct pci_dev *); | |
05adc3b7 | 74 | static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state); |
1da177e4 LT |
75 | static int airo_pci_resume(struct pci_dev *pdev); |
76 | ||
77 | static struct pci_driver airo_driver = { | |
1138c37b | 78 | .name = DRV_NAME, |
1da177e4 LT |
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, | |
84 | }; | |
85 | #endif /* CONFIG_PCI */ | |
86 | ||
87 | /* Include Wireless Extension definition and check version - Jean II */ | |
88 | #include <linux/wireless.h> | |
e292c737 PM |
89 | #define WIRELESS_SPY /* enable iwspy support */ |
90 | #include <net/iw_handler.h> /* New driver API */ | |
1da177e4 | 91 | |
e292c737 | 92 | #define CISCO_EXT /* enable Cisco extensions */ |
1da177e4 LT |
93 | #ifdef CISCO_EXT |
94 | #include <linux/delay.h> | |
95 | #endif | |
96 | ||
1da177e4 LT |
97 | /* Hack to do some power saving */ |
98 | #define POWER_ON_DOWN | |
99 | ||
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 */ | |
105 | ||
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 | |
212 | ||
213 | ||
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). */ | |
217 | ||
218 | static int rates[8]; | |
219 | static int basic_rate; | |
220 | static char *ssids[3]; | |
221 | ||
222 | static int io[4]; | |
223 | static int irq[4]; | |
224 | ||
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 */ | |
228 | ||
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; | |
233 | ||
234 | static int probe = 1; | |
235 | ||
236 | static int proc_uid /* = 0 */; | |
237 | ||
238 | static int proc_gid /* = 0 */; | |
239 | ||
240 | static int airo_perm = 0555; | |
241 | ||
242 | static int proc_perm = 0644; | |
243 | ||
244 | MODULE_AUTHOR("Benjamin Reed"); | |
245 | MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet \ | |
d73ae55a BN |
246 | cards. Direct support for ISA/PCI/MPI cards and support \ |
247 | for PCMCIA when used with airo_cs."); | |
1da177e4 LT |
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."); | |
272 | ||
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"); | |
281 | ||
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!!! */ | |
e292c737 | 285 | static int do8bitIO /* = 0 */; |
1da177e4 LT |
286 | |
287 | /* Return codes */ | |
288 | #define SUCCESS 0 | |
289 | #define ERROR -1 | |
290 | #define NO_PACKET -2 | |
291 | ||
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 | |
329 | ||
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 | |
363 | ||
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 | |
390 | ||
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 | |
400 | ||
401 | /* BAP selectors */ | |
e292c737 PM |
402 | #define BAP0 0 /* Used for receiving packets */ |
403 | #define BAP1 2 /* Used for xmiting packets and working with RIDS */ | |
1da177e4 LT |
404 | |
405 | /* Flags */ | |
406 | #define COMMAND_BUSY 0x8000 | |
407 | ||
408 | #define BAP_BUSY 0x8000 | |
409 | #define BAP_ERR 0x4000 | |
410 | #define BAP_DONE 0x2000 | |
411 | ||
412 | #define PROMISC 0xffff | |
413 | #define NOPROMISC 0x0000 | |
414 | ||
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) | |
428 | ||
429 | #ifdef CHECK_UNKNOWN_INTS | |
430 | #define IGNORE_INTS ( EV_CMD | EV_UNKNOWN) | |
431 | #else | |
432 | #define IGNORE_INTS (~STATUS_INTS) | |
433 | #endif | |
434 | ||
435 | /* RID TYPES */ | |
436 | #define RID_RW 0x20 | |
437 | ||
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 | |
3c304956 DW |
476 | #define RID_WPA_BSSLISTFIRST 0xFF74 |
477 | #define RID_WPA_BSSLISTNEXT 0xFF75 | |
1da177e4 LT |
478 | |
479 | typedef struct { | |
480 | u16 cmd; | |
481 | u16 parm0; | |
482 | u16 parm1; | |
483 | u16 parm2; | |
484 | } Cmd; | |
485 | ||
486 | typedef struct { | |
487 | u16 status; | |
488 | u16 rsp0; | |
489 | u16 rsp1; | |
490 | u16 rsp2; | |
491 | } Resp; | |
492 | ||
493 | /* | |
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. | |
497 | */ | |
498 | ||
499 | /* This is redundant for x86 archs, but it seems necessary for ARM */ | |
500 | #pragma pack(1) | |
501 | ||
502 | /* This structure came from an email sent to me from an engineer at | |
503 | aironet for inclusion into this driver */ | |
504 | typedef struct { | |
4293ea33 AV |
505 | __le16 len; |
506 | __le16 kindex; | |
1da177e4 | 507 | u8 mac[ETH_ALEN]; |
4293ea33 | 508 | __le16 klen; |
1da177e4 LT |
509 | u8 key[16]; |
510 | } WepKeyRid; | |
511 | ||
512 | /* These structures are from the Aironet's PC4500 Developers Manual */ | |
513 | typedef struct { | |
0dd2212f | 514 | __le16 len; |
1da177e4 LT |
515 | u8 ssid[32]; |
516 | } Ssid; | |
517 | ||
518 | typedef struct { | |
0dd2212f | 519 | __le16 len; |
1da177e4 LT |
520 | Ssid ssids[3]; |
521 | } SsidRid; | |
522 | ||
523 | typedef struct { | |
3eb9b41f AV |
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) | |
1da177e4 LT |
529 | } ModulationRid; |
530 | ||
531 | typedef struct { | |
3eb9b41f AV |
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; | |
1da177e4 LT |
561 | u8 macAddr[ETH_ALEN]; |
562 | u8 rates[8]; | |
3eb9b41f AV |
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]; | |
1da177e4 | 573 | /*---------- Scanning/Associating ----------*/ |
3eb9b41f AV |
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]; | |
1da177e4 | 598 | /*---------- Power save operation ----------*/ |
3eb9b41f AV |
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]; | |
1da177e4 | 609 | /*---------- Ap/Ibss config items ----------*/ |
3eb9b41f AV |
610 | __le16 beaconPeriod; |
611 | __le16 atimDuration; | |
612 | __le16 hopPeriod; | |
613 | __le16 channelSet; | |
614 | __le16 channel; | |
615 | __le16 dtimPeriod; | |
616 | __le16 bridgeDistance; | |
617 | __le16 radioID; | |
1da177e4 | 618 | /*---------- Radio configuration ----------*/ |
3eb9b41f AV |
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) | |
1da177e4 LT |
623 | u8 rxDiversity; |
624 | u8 txDiversity; | |
3eb9b41f | 625 | __le16 txPower; |
1da177e4 | 626 | #define TXPOWER_DEFAULT 0 |
3eb9b41f | 627 | __le16 rssiThreshold; |
1da177e4 | 628 | #define RSSI_DEFAULT 0 |
3eb9b41f AV |
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; | |
1da177e4 LT |
636 | /*---------- Aironet Extensions ----------*/ |
637 | u8 nodeName[16]; | |
3eb9b41f AV |
638 | __le16 arlThreshold; |
639 | __le16 arlDecay; | |
640 | __le16 arlDelay; | |
641 | __le16 _reserved4[1]; | |
1da177e4 LT |
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; | |
3eb9b41f | 651 | __le16 autoWake; |
1da177e4 LT |
652 | } ConfigRid; |
653 | ||
654 | typedef struct { | |
329e2c00 | 655 | __le16 len; |
1da177e4 | 656 | u8 mac[ETH_ALEN]; |
329e2c00 AV |
657 | __le16 mode; |
658 | __le16 errorCode; | |
659 | __le16 sigQuality; | |
660 | __le16 SSIDlen; | |
1da177e4 LT |
661 | char SSID[32]; |
662 | char apName[16]; | |
663 | u8 bssid[4][ETH_ALEN]; | |
329e2c00 AV |
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; | |
1da177e4 LT |
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 */ | |
329e2c00 | 686 | __le16 load; |
1da177e4 | 687 | u8 carrier[4]; |
329e2c00 | 688 | __le16 assocStatus; |
1da177e4 LT |
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; | |
711 | ||
712 | typedef struct { | |
a23ace5f AV |
713 | __le16 len; |
714 | __le16 spacer; | |
715 | __le32 vals[100]; | |
1da177e4 LT |
716 | } StatsRid; |
717 | ||
718 | ||
719 | typedef struct { | |
a749716e | 720 | __le16 len; |
1da177e4 LT |
721 | u8 ap[4][ETH_ALEN]; |
722 | } APListRid; | |
723 | ||
724 | typedef struct { | |
56d81bd3 | 725 | __le16 len; |
1da177e4 LT |
726 | char oui[3]; |
727 | char zero; | |
56d81bd3 | 728 | __le16 prodNum; |
1da177e4 LT |
729 | char manName[32]; |
730 | char prodName[16]; | |
731 | char prodVer[8]; | |
732 | char factoryAddr[ETH_ALEN]; | |
733 | char aironetAddr[ETH_ALEN]; | |
56d81bd3 AV |
734 | __le16 radioType; |
735 | __le16 country; | |
1da177e4 LT |
736 | char callid[ETH_ALEN]; |
737 | char supportedRates[8]; | |
738 | char rxDiversity; | |
739 | char txDiversity; | |
56d81bd3 AV |
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; | |
1da177e4 LT |
751 | } CapabilityRid; |
752 | ||
3c304956 DW |
753 | |
754 | /* Only present on firmware >= 5.30.17 */ | |
755 | typedef struct { | |
17e70491 | 756 | __le16 unknown[4]; |
3c304956 DW |
757 | u8 fixed[12]; /* WLAN management frame */ |
758 | u8 iep[624]; | |
759 | } BSSListRidExtra; | |
760 | ||
1da177e4 | 761 | typedef struct { |
17e70491 AV |
762 | __le16 len; |
763 | __le16 index; /* First is 0 and 0xffff means end of list */ | |
1da177e4 LT |
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) */ | |
17e70491 | 767 | __le16 radioType; |
1da177e4 LT |
768 | u8 bssid[ETH_ALEN]; /* Mac address of the BSS */ |
769 | u8 zero; | |
770 | u8 ssidLen; | |
771 | u8 ssid[32]; | |
17e70491 AV |
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; | |
1da177e4 LT |
779 | u8 rates[8]; /* Same as rates for config rid */ |
780 | struct { /* For frequency hopping only */ | |
17e70491 | 781 | __le16 dwell; |
1da177e4 LT |
782 | u8 hopSet; |
783 | u8 hopPattern; | |
784 | u8 hopIndex; | |
785 | u8 fill; | |
786 | } fh; | |
17e70491 AV |
787 | __le16 dsChannel; |
788 | __le16 atimWindow; | |
3c304956 DW |
789 | |
790 | /* Only present on firmware >= 5.30.17 */ | |
791 | BSSListRidExtra extra; | |
1da177e4 LT |
792 | } BSSListRid; |
793 | ||
9e75af30 DW |
794 | typedef struct { |
795 | BSSListRid bss; | |
796 | struct list_head list; | |
797 | } BSSListElement; | |
798 | ||
1da177e4 LT |
799 | typedef struct { |
800 | u8 rssipct; | |
801 | u8 rssidBm; | |
802 | } tdsRssiEntry; | |
803 | ||
804 | typedef struct { | |
805 | u16 len; | |
806 | tdsRssiEntry x[256]; | |
807 | } tdsRssiRid; | |
808 | ||
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; | |
817 | ||
818 | typedef struct { | |
593c2b9c | 819 | __be16 typelen; |
1da177e4 LT |
820 | |
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; | |
593c2b9c AV |
831 | __be32 mic; |
832 | __be32 seq; | |
1da177e4 LT |
833 | } MICBuffer; |
834 | ||
835 | typedef struct { | |
836 | u8 da[ETH_ALEN]; | |
837 | u8 sa[ETH_ALEN]; | |
838 | } etherHead; | |
839 | ||
840 | #pragma pack() | |
841 | ||
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 */ | |
850 | ||
851 | #define BUSY_FID 0x10000 | |
852 | ||
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 | |
870 | ||
871 | /* Ioctl constants to be used in airo_ioctl.command */ | |
872 | ||
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 | |
890 | ||
891 | /* Leave gap of 40 commands after AIROGSTATSD32 for future */ | |
892 | ||
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 | |
906 | ||
907 | /* Flash codes */ | |
908 | ||
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 | |
915 | ||
916 | #define FLASHSIZE 32768 | |
917 | #define AUXMEMSIZE (256 * 1024) | |
918 | ||
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; | |
925 | ||
62595eb9 | 926 | static char swversion[] = "2.1"; |
1da177e4 LT |
927 | #endif /* CISCO_EXT */ |
928 | ||
929 | #define NUM_MODULES 2 | |
930 | #define MIC_MSGLEN_MAX 2400 | |
931 | #define EMMH32_MSGLEN_MAX MIC_MSGLEN_MAX | |
15db2763 | 932 | #define AIRO_DEF_MTU 2312 |
1da177e4 LT |
933 | |
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; | |
944 | ||
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]; | |
593c2b9c | 951 | __be32 d32; |
1da177e4 LT |
952 | } part; // saves partial message word across update() calls |
953 | } emmh32_context; | |
954 | ||
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; | |
963 | ||
964 | typedef struct { | |
965 | miccntx mCtx; // Multicast context | |
966 | miccntx uCtx; // Unicast context | |
967 | } mic_module; | |
968 | ||
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; | |
975 | ||
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; | |
983 | ||
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; | |
991 | ||
992 | /* | |
993 | * Host receive descriptor | |
994 | */ | |
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; | |
1003 | ||
1004 | /* | |
1005 | * Host transmit descriptor | |
1006 | */ | |
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; | |
1015 | ||
1016 | /* | |
1017 | * Host RID descriptor | |
1018 | */ | |
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; | |
1026 | ||
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; | |
1046 | ||
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; | |
1056 | ||
1057 | ||
1058 | typedef struct { | |
1059 | TxCtlHdr ctlhdr; | |
1060 | u16 fill1; | |
1061 | u16 fill2; | |
1062 | WifiHdr wifihdr; | |
1063 | u16 gaplen; | |
1064 | u16 status; | |
1065 | } WifiCtlHdr; | |
1066 | ||
ff1d2767 | 1067 | static WifiCtlHdr wifictlhdr8023 = { |
1da177e4 LT |
1068 | .ctlhdr = { |
1069 | .ctl = HOST_DONT_RLSE, | |
1070 | } | |
1071 | }; | |
1072 | ||
1da177e4 LT |
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; | |
1080 | ||
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 */ | |
1086 | ||
1087 | /* List of Wireless Handlers (new API) */ | |
1088 | static const struct iw_handler_def airo_handler_def; | |
1da177e4 LT |
1089 | |
1090 | static const char version[] = "airo.c 0.6 (Ben Reed & Javier Achirica)"; | |
1091 | ||
1092 | struct airo_info; | |
1093 | ||
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); | |
175ec1a1 | 1098 | static int enable_MAC(struct airo_info *ai, int lock); |
1da177e4 LT |
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); | |
b8c06bc1 | 1104 | static int aux_bap_read(struct airo_info*, __le16 *pu16Dst, int bytelen, |
1da177e4 | 1105 | int whichbap); |
b8c06bc1 | 1106 | static int fast_bap_read(struct airo_info*, __le16 *pu16Dst, int bytelen, |
1da177e4 | 1107 | int whichbap); |
b8c06bc1 | 1108 | static int bap_write(struct airo_info*, const __le16 *pu16Src, int bytelen, |
1da177e4 LT |
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); | |
1119 | ||
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); | |
1125 | ||
7d12e780 | 1126 | static irqreturn_t airo_interrupt( int irq, void* dev_id); |
1da177e4 LT |
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); | |
ff1d2767 | 1130 | static struct iw_statistics *airo_get_wireless_stats (struct net_device *dev); |
1da177e4 | 1131 | static void airo_read_wireless_stats (struct airo_info *local); |
1da177e4 LT |
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); | |
ff1d2767 | 1135 | static int flashcard(struct net_device *dev, aironet_ioctl *comp); |
1da177e4 | 1136 | #endif /* CISCO_EXT */ |
1da177e4 LT |
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); | |
1141 | ||
41480af2 DW |
1142 | static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi); |
1143 | static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm); | |
1144 | ||
9e75af30 DW |
1145 | static void airo_networks_free(struct airo_info *ai); |
1146 | ||
1da177e4 | 1147 | struct airo_info { |
1da177e4 | 1148 | struct net_device *dev; |
af5b5c9a | 1149 | struct list_head dev_list; |
1da177e4 LT |
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; | |
1da177e4 LT |
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 | |
3c304956 | 1169 | #define FLAG_PROMISC 8 /* IFF_PROMISC 0x100 - include/linux/if.h */ |
1da177e4 LT |
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 | |
3c304956 DW |
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; | |
b8c06bc1 | 1190 | int (*bap_read)(struct airo_info*, __le16 *pu16Dst, int bytelen, |
1da177e4 LT |
1191 | int whichbap); |
1192 | unsigned short *flash; | |
1193 | tdsRssiEntry *rssi; | |
3b4c7d64 SB |
1194 | struct task_struct *list_bss_task; |
1195 | struct task_struct *airo_thread_task; | |
1da177e4 | 1196 | struct semaphore sem; |
1da177e4 | 1197 | wait_queue_head_t thr_wait; |
1da177e4 LT |
1198 | unsigned long expires; |
1199 | struct { | |
1200 | struct sk_buff *skb; | |
1201 | int fid; | |
1202 | } xmit, xmit11; | |
1203 | struct net_device *wifidev; | |
1da177e4 | 1204 | struct iw_statistics wstats; // wireless stats |
9e75af30 | 1205 | unsigned long scan_timeout; /* Time scan should be read */ |
1da177e4 LT |
1206 | struct iw_spy_data spy_data; |
1207 | struct iw_public_data wireless_data; | |
1da177e4 | 1208 | /* MIC stuff */ |
f12cc209 | 1209 | struct crypto_cipher *tfm; |
1da177e4 LT |
1210 | mic_module mod[2]; |
1211 | mic_statistics micstats; | |
1da177e4 LT |
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; | |
1cc68ae0 | 1222 | pm_message_t power; |
1da177e4 LT |
1223 | SsidRid *SSID; |
1224 | APListRid *APList; | |
1225 | #define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE | |
1226 | char proc_name[IFNAMSIZ]; | |
9e75af30 | 1227 | |
3c304956 DW |
1228 | /* WPA-related stuff */ |
1229 | unsigned int bssListFirst; | |
1230 | unsigned int bssListNext; | |
1231 | unsigned int bssListRidLen; | |
1232 | ||
9e75af30 DW |
1233 | struct list_head network_list; |
1234 | struct list_head network_free_list; | |
1235 | BSSListElement *networks; | |
1da177e4 LT |
1236 | }; |
1237 | ||
b8c06bc1 AV |
1238 | static inline int bap_read(struct airo_info *ai, __le16 *pu16Dst, int bytelen, |
1239 | int whichbap) | |
1240 | { | |
1da177e4 LT |
1241 | return ai->bap_read(ai, pu16Dst, bytelen, whichbap); |
1242 | } | |
1243 | ||
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 ); | |
1248 | ||
ff1d2767 JM |
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); | |
1254 | ||
934d8bf1 | 1255 | #define airo_print(type, name, fmt, args...) \ |
1138c37b | 1256 | printk(type DRV_NAME "(%s): " fmt "\n", name, ##args) |
934d8bf1 DW |
1257 | |
1258 | #define airo_print_info(name, fmt, args...) \ | |
1259 | airo_print(KERN_INFO, name, fmt, ##args) | |
1260 | ||
1261 | #define airo_print_dbg(name, fmt, args...) \ | |
1262 | airo_print(KERN_DEBUG, name, fmt, ##args) | |
1263 | ||
1264 | #define airo_print_warn(name, fmt, args...) \ | |
1265 | airo_print(KERN_WARNING, name, fmt, ##args) | |
1266 | ||
1267 | #define airo_print_err(name, fmt, args...) \ | |
1268 | airo_print(KERN_ERR, name, fmt, ##args) | |
1269 | ||
faf3994a | 1270 | #define AIRO_FLASH(dev) (((struct airo_info *)dev->ml_priv)->flash) |
934d8bf1 | 1271 | |
1da177e4 LT |
1272 | /*********************************************************************** |
1273 | * MIC ROUTINES * | |
1274 | *********************************************************************** | |
1275 | */ | |
1276 | ||
1277 | static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq); | |
1278 | static void MoveWindow(miccntx *context, u32 micSeq); | |
f12cc209 HX |
1279 | static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, |
1280 | struct crypto_cipher *tfm); | |
ff1d2767 JM |
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); | |
1da177e4 LT |
1285 | |
1286 | /* micinit - Initialize mic seed */ | |
1287 | ||
1288 | static void micinit(struct airo_info *ai) | |
1289 | { | |
1290 | MICRid mic_rid; | |
1291 | ||
3c304956 | 1292 | clear_bit(JOB_MIC, &ai->jobs); |
1da177e4 LT |
1293 | PC4500_readrid(ai, RID_MIC, &mic_rid, sizeof(mic_rid), 0); |
1294 | up(&ai->sem); | |
1295 | ||
1296 | ai->micstats.enabled = (mic_rid.state & 0x00FF) ? 1 : 0; | |
1297 | ||
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 | |
1311 | ||
1312 | /* Give key to mic seed */ | |
1313 | emmh32_setseed(&ai->mod[0].mCtx.seed,mic_rid.multicast,sizeof(mic_rid.multicast), ai->tfm); | |
1314 | } | |
1315 | ||
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)); | |
1324 | ||
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 | |
1329 | ||
1330 | //Give key to mic seed | |
1331 | emmh32_setseed(&ai->mod[0].uCtx.seed, mic_rid.unicast, sizeof(mic_rid.unicast), ai->tfm); | |
1332 | } | |
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. | |
1336 | */ | |
1337 | ai->mod[0].uCtx.valid = 0; | |
1338 | ai->mod[0].mCtx.valid = 0; | |
1339 | } | |
1340 | } | |
1341 | ||
1342 | /* micsetup - Get ready for business */ | |
1343 | ||
1344 | static int micsetup(struct airo_info *ai) { | |
1345 | int i; | |
1346 | ||
1347 | if (ai->tfm == NULL) | |
f12cc209 | 1348 | ai->tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC); |
1da177e4 | 1349 | |
f12cc209 | 1350 | if (IS_ERR(ai->tfm)) { |
934d8bf1 | 1351 | airo_print_err(ai->dev->name, "failed to load transform for AES"); |
f12cc209 | 1352 | ai->tfm = NULL; |
1da177e4 LT |
1353 | return ERROR; |
1354 | } | |
1355 | ||
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)); | |
1359 | } | |
1360 | return SUCCESS; | |
1361 | } | |
1362 | ||
ff1d2767 | 1363 | static char micsnap[] = {0xAA,0xAA,0x03,0x00,0x40,0x96,0x00,0x02}; |
1da177e4 LT |
1364 | |
1365 | /*=========================================================================== | |
1366 | * Description: Mic a packet | |
1367 | * | |
1368 | * Inputs: etherHead * pointer to an 802.3 frame | |
1369 | * | |
1370 | * Returns: BOOLEAN if successful, otherwise false. | |
1371 | * PacketTxLen will be updated with the mic'd packets size. | |
1372 | * | |
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). | |
1376 | * | |
1377 | * Author: sbraneky (10/15/01) | |
1378 | * Merciless hacks by rwilcher (1/14/02) | |
1379 | */ | |
1380 | ||
1381 | static int encapsulate(struct airo_info *ai ,etherHead *frame, MICBuffer *mic, int payLen) | |
1382 | { | |
1383 | miccntx *context; | |
1384 | ||
1385 | // Determine correct context | |
1386 | // If not adhoc, always use unicast key | |
1387 | ||
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; | |
1392 | ||
1393 | if (!context->valid) | |
1394 | return ERROR; | |
1395 | ||
1396 | mic->typelen = htons(payLen + 16); //Length of Mic'd packet | |
1397 | ||
1398 | memcpy(&mic->u.snap, micsnap, sizeof(micsnap)); // Add Snap | |
1399 | ||
1400 | // Add Tx sequence | |
1401 | mic->seq = htonl(context->tx); | |
1402 | context->tx += 2; | |
1403 | ||
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); | |
1410 | ||
1411 | /* New Type/length ?????????? */ | |
1412 | mic->typelen = 0; //Let NIC know it could be an oversized packet | |
1413 | return SUCCESS; | |
1414 | } | |
1415 | ||
1416 | typedef enum { | |
1417 | NONE, | |
1418 | NOMIC, | |
1419 | NOMICPLUMMED, | |
1420 | SEQUENCE, | |
1421 | INCORRECTMIC, | |
1422 | } mic_error; | |
1423 | ||
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. | |
1427 | * | |
1428 | * Inputs: etherHead pointer to the 802.3 packet | |
1429 | * | |
1430 | * Returns: BOOLEAN - TRUE if packet should be dropped otherwise FALSE | |
1431 | * | |
1432 | * Author: sbraneky (10/15/01) | |
1433 | * Merciless hacks by rwilcher (1/14/02) | |
1434 | *--------------------------------------------------------------------------- | |
1435 | */ | |
1436 | ||
1437 | static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *eth, u16 payLen) | |
1438 | { | |
1439 | int i; | |
1440 | u32 micSEQ; | |
1441 | miccntx *context; | |
1442 | u8 digest[4]; | |
1443 | mic_error micError = NONE; | |
1444 | ||
1445 | // Check if the packet is a Mic'd packet | |
1446 | ||
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; | |
1452 | } | |
1453 | return SUCCESS; | |
1454 | } | |
1455 | ||
1456 | if (ntohs(mic->typelen) == 0x888E) | |
1457 | return SUCCESS; | |
1458 | ||
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; | |
1463 | } | |
1464 | ||
1465 | micSEQ = ntohl(mic->seq); //store SEQ as CPU order | |
1466 | ||
1467 | //At this point we a have a mic'd packet and mic is enabled | |
1468 | //Now do the mic error checking. | |
1469 | ||
1470 | //Receive seq must be odd | |
1471 | if ( (micSEQ & 1) == 0 ) { | |
1472 | ai->micstats.rxWrongSequence++; | |
1473 | return ERROR; | |
1474 | } | |
1475 | ||
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; | |
1480 | ||
1481 | //Make sure context is valid | |
1482 | if (!context->valid) { | |
1483 | if (i == 0) | |
1484 | micError = NOMICPLUMMED; | |
1485 | continue; | |
1486 | } | |
1487 | //DeMic it | |
1488 | ||
1489 | if (!mic->typelen) | |
1490 | mic->typelen = htons(payLen + sizeof(MICBuffer) - 2); | |
1491 | ||
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); | |
1499 | ||
1500 | if (memcmp(digest, &mic->mic, 4)) { //Make sure the mics match | |
1501 | //Invalid Mic | |
1502 | if (i == 0) | |
1503 | micError = INCORRECTMIC; | |
1504 | continue; | |
1505 | } | |
1506 | ||
1507 | //Check Sequence number if mics pass | |
1508 | if (RxSeqValid(ai, context, mcast, micSEQ) == SUCCESS) { | |
1509 | ai->micstats.rxSuccess++; | |
1510 | return SUCCESS; | |
1511 | } | |
1512 | if (i == 0) | |
1513 | micError = SEQUENCE; | |
1514 | } | |
1515 | ||
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; | |
1523 | } | |
1524 | return ERROR; | |
1525 | } | |
1526 | ||
1527 | /*=========================================================================== | |
1528 | * Description: Checks the Rx Seq number to make sure it is valid | |
1529 | * and hasn't already been received | |
1530 | * | |
1531 | * Inputs: miccntx - mic context to check seq against | |
1532 | * micSeq - the Mic seq number | |
1533 | * | |
1534 | * Returns: TRUE if valid otherwise FALSE. | |
1535 | * | |
1536 | * Author: sbraneky (10/15/01) | |
1537 | * Merciless hacks by rwilcher (1/14/02) | |
1538 | *--------------------------------------------------------------------------- | |
1539 | */ | |
1540 | ||
1541 | static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq) | |
1542 | { | |
1543 | u32 seq,index; | |
1544 | ||
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 | |
1547 | ||
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 | |
1553 | } | |
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 | |
1558 | } | |
1559 | ||
1560 | //Make sequence number relative to START of window | |
1561 | seq = micSeq - (context->window - 33); | |
1562 | ||
1563 | //Too old of a SEQ number to check. | |
1564 | if ((s32)seq < 0) | |
1565 | return ERROR; | |
1566 | ||
1567 | if ( seq > 64 ) { | |
1568 | //Window is infinite forward | |
1569 | MoveWindow(context,micSeq); | |
1570 | return SUCCESS; | |
1571 | } | |
1572 | ||
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 | |
1576 | ||
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; | |
1581 | ||
1582 | MoveWindow(context,micSeq); | |
1583 | ||
1584 | return SUCCESS; | |
1585 | } | |
1586 | return ERROR; | |
1587 | } | |
1588 | ||
1589 | static void MoveWindow(miccntx *context, u32 micSeq) | |
1590 | { | |
1591 | u32 shift; | |
1592 | ||
1593 | //Move window if seq greater than the middle of the window | |
1594 | if (micSeq > context->window) { | |
1595 | shift = (micSeq - context->window) >> 1; | |
1596 | ||
1597 | //Shift out old | |
1598 | if (shift < 32) | |
1599 | context->rx >>= shift; | |
1600 | else | |
1601 | context->rx = 0; | |
1602 | ||
1603 | context->window = micSeq; //Move window | |
1604 | } | |
1605 | } | |
1606 | ||
1607 | /*==============================================*/ | |
1608 | /*========== EMMH ROUTINES ====================*/ | |
1609 | /*==============================================*/ | |
1610 | ||
1611 | /* mic accumulate */ | |
1612 | #define MIC_ACCUM(val) \ | |
1613 | context->accum += (u64)(val) * context->coeff[coeff_position++]; | |
1614 | ||
1615 | static unsigned char aes_counter[16]; | |
1616 | ||
1617 | /* expand the key to fill the MMH coefficient array */ | |
f12cc209 HX |
1618 | static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, |
1619 | struct crypto_cipher *tfm) | |
1da177e4 LT |
1620 | { |
1621 | /* take the keying material, expand if necessary, truncate at 16-bytes */ | |
1622 | /* run through AES counter mode to generate context->coeff[] */ | |
1623 | ||
1624 | int i,j; | |
1625 | u32 counter; | |
1626 | u8 *cipher, plain[16]; | |
1da177e4 LT |
1627 | |
1628 | crypto_cipher_setkey(tfm, pkey, 16); | |
1629 | counter = 0; | |
e7c04fd3 | 1630 | for (i = 0; i < ARRAY_SIZE(context->coeff); ) { |
1da177e4 LT |
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); | |
f12cc209 HX |
1637 | crypto_cipher_encrypt_one(tfm, plain, plain); |
1638 | cipher = plain; | |
e7c04fd3 | 1639 | for (j = 0; (j < 16) && (i < ARRAY_SIZE(context->coeff)); ) { |
593c2b9c | 1640 | context->coeff[i++] = ntohl(*(__be32 *)&cipher[j]); |
1da177e4 LT |
1641 | j += 4; |
1642 | } | |
1643 | } | |
1644 | } | |
1645 | ||
1646 | /* prepare for calculation of a new mic */ | |
ff1d2767 | 1647 | static void emmh32_init(emmh32_context *context) |
1da177e4 LT |
1648 | { |
1649 | /* prepare for new mic calculation */ | |
1650 | context->accum = 0; | |
1651 | context->position = 0; | |
1652 | } | |
1653 | ||
1654 | /* add some bytes to the mic calculation */ | |
ff1d2767 | 1655 | static void emmh32_update(emmh32_context *context, u8 *pOctets, int len) |
1da177e4 LT |
1656 | { |
1657 | int coeff_position, byte_position; | |
1658 | ||
1659 | if (len == 0) return; | |
1660 | ||
1661 | coeff_position = context->position >> 2; | |
1662 | ||
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); | |
593c2b9c | 1673 | MIC_ACCUM(ntohl(context->part.d32)); |
1da177e4 LT |
1674 | } |
1675 | ||
1676 | /* deal with full 32-bit words */ | |
1677 | while (len >= 4) { | |
593c2b9c | 1678 | MIC_ACCUM(ntohl(*(__be32 *)pOctets)); |
1da177e4 LT |
1679 | context->position += 4; |
1680 | pOctets += 4; | |
1681 | len -= 4; | |
1682 | } | |
1683 | ||
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--; | |
1690 | } | |
1691 | } | |
1692 | ||
1693 | /* mask used to zero empty bytes for final partial word */ | |
1694 | static u32 mask32[4] = { 0x00000000L, 0xFF000000L, 0xFFFF0000L, 0xFFFFFF00L }; | |
1695 | ||
1696 | /* calculate the mic */ | |
ff1d2767 | 1697 | static void emmh32_final(emmh32_context *context, u8 digest[4]) |
1da177e4 LT |
1698 | { |
1699 | int coeff_position, byte_position; | |
1700 | u32 val; | |
1701 | ||
1702 | u64 sum, utmp; | |
1703 | s64 stmp; | |
1704 | ||
1705 | coeff_position = context->position >> 2; | |
1706 | ||
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 */ | |
593c2b9c | 1711 | val = ntohl(context->part.d32); |
1da177e4 LT |
1712 | MIC_ACCUM(val & mask32[byte_position]); /* zero empty bytes */ |
1713 | } | |
1714 | ||
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; | |
1722 | ||
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; | |
1728 | } | |
1da177e4 LT |
1729 | |
1730 | static int readBSSListRid(struct airo_info *ai, int first, | |
17e70491 AV |
1731 | BSSListRid *list) |
1732 | { | |
3c304956 DW |
1733 | Cmd cmd; |
1734 | Resp rsp; | |
1da177e4 LT |
1735 | |
1736 | if (first == 1) { | |
3c304956 DW |
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; | |
3b4c7d64 | 1742 | ai->list_bss_task = current; |
3c304956 DW |
1743 | issuecommand(ai, &cmd, &rsp); |
1744 | up(&ai->sem); | |
1745 | /* Let the command take effect */ | |
3b4c7d64 SB |
1746 | schedule_timeout_uninterruptible(3 * HZ); |
1747 | ai->list_bss_task = NULL; | |
3c304956 | 1748 | } |
17e70491 | 1749 | return PC4500_readrid(ai, first ? ai->bssListFirst : ai->bssListNext, |
3c304956 | 1750 | list, ai->bssListRidLen, 1); |
1da177e4 LT |
1751 | } |
1752 | ||
4293ea33 AV |
1753 | static int readWepKeyRid(struct airo_info *ai, WepKeyRid *wkr, int temp, int lock) |
1754 | { | |
1755 | return PC4500_readrid(ai, temp ? RID_WEP_TEMP : RID_WEP_PERM, | |
1da177e4 | 1756 | wkr, sizeof(*wkr), lock); |
1da177e4 | 1757 | } |
1da177e4 | 1758 | |
4293ea33 AV |
1759 | static int writeWepKeyRid(struct airo_info *ai, WepKeyRid *wkr, int perm, int lock) |
1760 | { | |
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); | |
1da177e4 | 1765 | if (perm) { |
4293ea33 AV |
1766 | rc = PC4500_writerid(ai, RID_WEP_PERM, wkr, sizeof(*wkr), lock); |
1767 | if (rc!=SUCCESS) | |
934d8bf1 | 1768 | airo_print_err(ai->dev->name, "WEP_PERM set %x", rc); |
1da177e4 LT |
1769 | } |
1770 | return rc; | |
1771 | } | |
1772 | ||
0dd2212f AV |
1773 | static int readSsidRid(struct airo_info*ai, SsidRid *ssidr) |
1774 | { | |
1775 | return PC4500_readrid(ai, RID_SSID, ssidr, sizeof(*ssidr), 1); | |
1da177e4 | 1776 | } |
1da177e4 | 1777 | |
0dd2212f AV |
1778 | static int writeSsidRid(struct airo_info*ai, SsidRid *pssidr, int lock) |
1779 | { | |
1780 | return PC4500_writerid(ai, RID_SSID, pssidr, sizeof(*pssidr), lock); | |
1da177e4 | 1781 | } |
0dd2212f | 1782 | |
3eb9b41f AV |
1783 | static int readConfigRid(struct airo_info *ai, int lock) |
1784 | { | |
1da177e4 | 1785 | int rc; |
1da177e4 LT |
1786 | ConfigRid cfg; |
1787 | ||
1788 | if (ai->config.len) | |
1789 | return SUCCESS; | |
1790 | ||
1791 | rc = PC4500_readrid(ai, RID_ACTUALCONFIG, &cfg, sizeof(cfg), lock); | |
1792 | if (rc != SUCCESS) | |
1793 | return rc; | |
1794 | ||
1da177e4 LT |
1795 | ai->config = cfg; |
1796 | return SUCCESS; | |
1797 | } | |
3eb9b41f AV |
1798 | |
1799 | static inline void checkThrottle(struct airo_info *ai) | |
1800 | { | |
1da177e4 LT |
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; | |
1807 | } | |
1808 | } | |
1809 | } | |
1810 | } | |
3eb9b41f AV |
1811 | |
1812 | static int writeConfigRid(struct airo_info *ai, int lock) | |
1813 | { | |
1da177e4 LT |
1814 | ConfigRid cfgr; |
1815 | ||
1816 | if (!test_bit (FLAG_COMMIT, &ai->flags)) | |
1817 | return SUCCESS; | |
1818 | ||
1819 | clear_bit (FLAG_COMMIT, &ai->flags); | |
1820 | clear_bit (FLAG_RESET, &ai->flags); | |
1821 | checkThrottle(ai); | |
1822 | cfgr = ai->config; | |
1823 | ||
3eb9b41f | 1824 | if ((cfgr.opmode & MODE_CFG_MASK) == MODE_STA_IBSS) |
1da177e4 LT |
1825 | set_bit(FLAG_ADHOC, &ai->flags); |
1826 | else | |
1827 | clear_bit(FLAG_ADHOC, &ai->flags); | |
1828 | ||
1da177e4 LT |
1829 | return PC4500_writerid( ai, RID_CONFIG, &cfgr, sizeof(cfgr), lock); |
1830 | } | |
1da177e4 | 1831 | |
329e2c00 AV |
1832 | static int readStatusRid(struct airo_info *ai, StatusRid *statr, int lock) |
1833 | { | |
1834 | return PC4500_readrid(ai, RID_STATUS, statr, sizeof(*statr), lock); | |
1da177e4 | 1835 | } |
a749716e AV |
1836 | |
1837 | static int readAPListRid(struct airo_info *ai, APListRid *aplr) | |
1838 | { | |
1839 | return PC4500_readrid(ai, RID_APLIST, aplr, sizeof(*aplr), 1); | |
1da177e4 | 1840 | } |
a749716e AV |
1841 | |
1842 | static int writeAPListRid(struct airo_info *ai, APListRid *aplr, int lock) | |
1843 | { | |
1844 | return PC4500_writerid(ai, RID_APLIST, aplr, sizeof(*aplr), lock); | |
1da177e4 | 1845 | } |
1da177e4 | 1846 | |
56d81bd3 AV |
1847 | static int readCapabilityRid(struct airo_info *ai, CapabilityRid *capr, int lock) |
1848 | { | |
1849 | return PC4500_readrid(ai, RID_CAPABILITIES, capr, sizeof(*capr), lock); | |
1da177e4 | 1850 | } |
1da177e4 | 1851 | |
a23ace5f AV |
1852 | static int readStatsRid(struct airo_info*ai, StatsRid *sr, int rid, int lock) |
1853 | { | |
1854 | return PC4500_readrid(ai, rid, sr, sizeof(*sr), lock); | |
1da177e4 LT |
1855 | } |
1856 | ||
1c2b7db8 MS |
1857 | static void try_auto_wep(struct airo_info *ai) |
1858 | { | |
1859 | if (auto_wep && !(ai->flags & FLAG_RADIO_DOWN)) { | |
1860 | ai->expires = RUN_AT(3*HZ); | |
1861 | wake_up_interruptible(&ai->thr_wait); | |
1862 | } | |
1863 | } | |
1864 | ||
1da177e4 | 1865 | static int airo_open(struct net_device *dev) { |
faf3994a | 1866 | struct airo_info *ai = dev->ml_priv; |
1c2b7db8 | 1867 | int rc = 0; |
1da177e4 | 1868 | |
1c2b7db8 | 1869 | if (test_bit(FLAG_FLASHING, &ai->flags)) |
1da177e4 LT |
1870 | return -EIO; |
1871 | ||
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 */ | |
1c2b7db8 MS |
1876 | if (test_bit(FLAG_COMMIT, &ai->flags)) { |
1877 | disable_MAC(ai, 1); | |
1878 | writeConfigRid(ai, 1); | |
1da177e4 LT |
1879 | } |
1880 | ||
1c2b7db8 MS |
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); | |
1886 | ||
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; | |
1896 | } | |
1897 | ||
1da177e4 | 1898 | /* Power on the MAC controller (which may have been disabled) */ |
1c2b7db8 MS |
1899 | clear_bit(FLAG_RADIO_DOWN, &ai->flags); |
1900 | enable_interrupts(ai); | |
1901 | ||
1902 | try_auto_wep(ai); | |
1da177e4 | 1903 | } |
175ec1a1 | 1904 | enable_MAC(ai, 1); |
1da177e4 LT |
1905 | |
1906 | netif_start_queue(dev); | |
1907 | return 0; | |
1908 | } | |
1909 | ||
1910 | static int mpi_start_xmit(struct sk_buff *skb, struct net_device *dev) { | |
1911 | int npacks, pending; | |
1912 | unsigned long flags; | |
faf3994a | 1913 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
1914 | |
1915 | if (!skb) { | |
c94c93da | 1916 | airo_print_err(dev->name, "%s: skb == NULL!",__func__); |
1da177e4 LT |
1917 | return 0; |
1918 | } | |
1919 | npacks = skb_queue_len (&ai->txq); | |
1920 | ||
1921 | if (npacks >= MAXTXQ - 1) { | |
1922 | netif_stop_queue (dev); | |
1923 | if (npacks > MAXTXQ) { | |
5d9276da | 1924 | dev->stats.tx_fifo_errors++; |
1da177e4 LT |
1925 | return 1; |
1926 | } | |
1927 | skb_queue_tail (&ai->txq, skb); | |
1928 | return 0; | |
1929 | } | |
1930 | ||
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); | |
1936 | ||
1937 | if (pending == 0) { | |
1938 | set_bit(FLAG_PENDING_XMIT, &ai->flags); | |
1939 | mpi_send_packet (dev); | |
1940 | } | |
1941 | return 0; | |
1942 | } | |
1943 | ||
1944 | /* | |
1945 | * @mpi_send_packet | |
1946 | * | |
1947 | * Attempt to transmit a packet. Can be called from interrupt | |
1948 | * or transmit . return number of packets we tried to send | |
1949 | */ | |
1950 | ||
1951 | static int mpi_send_packet (struct net_device *dev) | |
1952 | { | |
1953 | struct sk_buff *skb; | |
1954 | unsigned char *buffer; | |
593c2b9c AV |
1955 | s16 len; |
1956 | __le16 *payloadLen; | |
faf3994a | 1957 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
1958 | u8 *sendbuf; |
1959 | ||
1960 | /* get a packet to send */ | |
1961 | ||
79ea13ce | 1962 | if ((skb = skb_dequeue(&ai->txq)) == NULL) { |
934d8bf1 DW |
1963 | airo_print_err(dev->name, |
1964 | "%s: Dequeue'd zero in send_packet()", | |
c94c93da | 1965 | __func__); |
1da177e4 LT |
1966 | return 0; |
1967 | } | |
1968 | ||
1969 | /* check min length*/ | |
1970 | len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; | |
1971 | buffer = skb->data; | |
1972 | ||
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); | |
1977 | ||
1978 | /* | |
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 | * ------------------------------------------------ | |
1984 | */ | |
1985 | ||
1986 | memcpy((char *)ai->txfids[0].virtual_host_addr, | |
1987 | (char *)&wifictlhdr8023, sizeof(wifictlhdr8023)); | |
1988 | ||
593c2b9c | 1989 | payloadLen = (__le16 *)(ai->txfids[0].virtual_host_addr + |
1da177e4 LT |
1990 | sizeof(wifictlhdr8023)); |
1991 | sendbuf = ai->txfids[0].virtual_host_addr + | |
1992 | sizeof(wifictlhdr8023) + 2 ; | |
1993 | ||
1994 | /* | |
1995 | * Firmware automaticly puts 802 header on so | |
1996 | * we don't need to account for it in the length | |
1997 | */ | |
1da177e4 | 1998 | if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled && |
593c2b9c | 1999 | (ntohs(((__be16 *)buffer)[6]) != 0x888E)) { |
1da177e4 LT |
2000 | MICBuffer pMic; |
2001 | ||
2002 | if (encapsulate(ai, (etherHead *)buffer, &pMic, len - sizeof(etherHead)) != SUCCESS) | |
2003 | return ERROR; | |
2004 | ||
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)); | |
a39d3e79 | 2014 | } else { |
1da177e4 LT |
2015 | *payloadLen = cpu_to_le16(len - sizeof(etherHead)); |
2016 | ||
2017 | dev->trans_start = jiffies; | |
2018 | ||
2019 | /* copy data into airo dma buffer */ | |
2020 | memcpy(sendbuf, buffer, len); | |
2021 | } | |
2022 | ||
2023 | memcpy_toio(ai->txfids[0].card_ram_off, | |
2024 | &ai->txfids[0].tx_desc, sizeof(TxFid)); | |
2025 | ||
2026 | OUT4500(ai, EVACK, 8); | |
2027 | ||
2028 | dev_kfree_skb_any(skb); | |
2029 | return 1; | |
2030 | } | |
2031 | ||
29b09fcc | 2032 | static void get_tx_error(struct airo_info *ai, s32 fid) |
1da177e4 | 2033 | { |
593c2b9c | 2034 | __le16 status; |
1da177e4 LT |
2035 | |
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); | |
2042 | } | |
2043 | if (le16_to_cpu(status) & 2) /* Too many retries */ | |
5d9276da | 2044 | ai->dev->stats.tx_aborted_errors++; |
1da177e4 | 2045 | if (le16_to_cpu(status) & 4) /* Transmit lifetime exceeded */ |
5d9276da | 2046 | ai->dev->stats.tx_heartbeat_errors++; |
1da177e4 LT |
2047 | if (le16_to_cpu(status) & 8) /* Aid fail */ |
2048 | { } | |
2049 | if (le16_to_cpu(status) & 0x10) /* MAC disabled */ | |
5d9276da | 2050 | ai->dev->stats.tx_carrier_errors++; |
1da177e4 LT |
2051 | if (le16_to_cpu(status) & 0x20) /* Association lost */ |
2052 | { } | |
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]; | |
2061 | ||
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 */ | |
b8c06bc1 | 2065 | bap_read(ai, (__le16 *) junk, 0x18, BAP0); |
1da177e4 LT |
2066 | |
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; | |
2077 | ||
2078 | /* Send event to user space */ | |
2079 | wireless_send_event(ai->dev, IWEVTXDROP, &wrqu, NULL); | |
2080 | } | |
2081 | } | |
2082 | ||
2083 | static void airo_end_xmit(struct net_device *dev) { | |
2084 | u16 status; | |
2085 | int i; | |
faf3994a | 2086 | struct airo_info *priv = dev->ml_priv; |
1da177e4 LT |
2087 | struct sk_buff *skb = priv->xmit.skb; |
2088 | int fid = priv->xmit.fid; | |
2089 | u32 *fids = priv->fids; | |
2090 | ||
3c304956 | 2091 | clear_bit(JOB_XMIT, &priv->jobs); |
1da177e4 LT |
2092 | clear_bit(FLAG_PENDING_XMIT, &priv->flags); |
2093 | status = transmit_802_3_packet (priv, fids[fid], skb->data); | |
2094 | up(&priv->sem); | |
2095 | ||
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; | |
5d9276da | 2102 | dev->stats.tx_window_errors++; |
1da177e4 LT |
2103 | } |
2104 | if (i < MAX_FIDS / 2) | |
2105 | netif_wake_queue(dev); | |
2106 | dev_kfree_skb(skb); | |
2107 | } | |
2108 | ||
2109 | static int airo_start_xmit(struct sk_buff *skb, struct net_device *dev) { | |
2110 | s16 len; | |
2111 | int i, j; | |
faf3994a | 2112 | struct airo_info *priv = dev->ml_priv; |
1da177e4 LT |
2113 | u32 *fids = priv->fids; |
2114 | ||
2115 | if ( skb == NULL ) { | |
c94c93da | 2116 | airo_print_err(dev->name, "%s: skb == NULL!", __func__); |
1da177e4 LT |
2117 | return 0; |
2118 | } | |
2119 | ||
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++ ); | |
2123 | ||
2124 | if ( j >= MAX_FIDS / 2 ) { | |
2125 | netif_stop_queue(dev); | |
2126 | ||
2127 | if (i == MAX_FIDS / 2) { | |
5d9276da | 2128 | dev->stats.tx_fifo_errors++; |
1da177e4 LT |
2129 | return 1; |
2130 | } | |
2131 | } | |
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); | |
3c304956 | 2141 | set_bit(JOB_XMIT, &priv->jobs); |
1da177e4 LT |
2142 | wake_up_interruptible(&priv->thr_wait); |
2143 | } else | |
2144 | airo_end_xmit(dev); | |
2145 | return 0; | |
2146 | } | |
2147 | ||
2148 | static void airo_end_xmit11(struct net_device *dev) { | |
2149 | u16 status; | |
2150 | int i; | |
faf3994a | 2151 | struct airo_info *priv = dev->ml_priv; |
1da177e4 LT |
2152 | struct sk_buff *skb = priv->xmit11.skb; |
2153 | int fid = priv->xmit11.fid; | |
2154 | u32 *fids = priv->fids; | |
2155 | ||
3c304956 | 2156 | clear_bit(JOB_XMIT11, &priv->jobs); |
1da177e4 LT |
2157 | clear_bit(FLAG_PENDING_XMIT11, &priv->flags); |
2158 | status = transmit_802_11_packet (priv, fids[fid], skb->data); | |
2159 | up(&priv->sem); | |
2160 | ||
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; | |
5d9276da | 2167 | dev->stats.tx_window_errors++; |
1da177e4 LT |
2168 | } |
2169 | if (i < MAX_FIDS) | |
2170 | netif_wake_queue(dev); | |
2171 | dev_kfree_skb(skb); | |
2172 | } | |
2173 | ||
2174 | static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) { | |
2175 | s16 len; | |
2176 | int i, j; | |
faf3994a | 2177 | struct airo_info *priv = dev->ml_priv; |
1da177e4 LT |
2178 | u32 *fids = priv->fids; |
2179 | ||
2180 | if (test_bit(FLAG_MPI, &priv->flags)) { | |
2181 | /* Not implemented yet for MPI350 */ | |
2182 | netif_stop_queue(dev); | |
2183 | return -ENETDOWN; | |
2184 | } | |
2185 | ||
2186 | if ( skb == NULL ) { | |
c94c93da | 2187 | airo_print_err(dev->name, "%s: skb == NULL!", __func__); |
1da177e4 LT |
2188 | return 0; |
2189 | } | |
2190 | ||
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++ ); | |
2194 | ||
2195 | if ( j >= MAX_FIDS ) { | |
2196 | netif_stop_queue(dev); | |
2197 | ||
2198 | if (i == MAX_FIDS) { | |
5d9276da | 2199 | dev->stats.tx_fifo_errors++; |
1da177e4 LT |
2200 | return 1; |
2201 | } | |
2202 | } | |
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); | |
3c304956 | 2212 | set_bit(JOB_XMIT11, &priv->jobs); |
1da177e4 LT |
2213 | wake_up_interruptible(&priv->thr_wait); |
2214 | } else | |
2215 | airo_end_xmit11(dev); | |
2216 | return 0; | |
2217 | } | |
2218 | ||
5d9276da | 2219 | static void airo_read_stats(struct net_device *dev) |
a23ace5f | 2220 | { |
faf3994a | 2221 | struct airo_info *ai = dev->ml_priv; |
1da177e4 | 2222 | StatsRid stats_rid; |
a23ace5f | 2223 | __le32 *vals = stats_rid.vals; |
1da177e4 | 2224 | |
3c304956 | 2225 | clear_bit(JOB_STATS, &ai->jobs); |
ca078bae | 2226 | if (ai->power.event) { |
1da177e4 LT |
2227 | up(&ai->sem); |
2228 | return; | |
2229 | } | |
2230 | readStatsRid(ai, &stats_rid, RID_STATS, 0); | |
2231 | up(&ai->sem); | |
2232 | ||
5d9276da | 2233 | dev->stats.rx_packets = le32_to_cpu(vals[43]) + le32_to_cpu(vals[44]) + |
a23ace5f | 2234 | le32_to_cpu(vals[45]); |
5d9276da | 2235 | dev->stats.tx_packets = le32_to_cpu(vals[39]) + le32_to_cpu(vals[40]) + |
a23ace5f | 2236 | le32_to_cpu(vals[41]); |
5d9276da PZ |
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]) + | |
a23ace5f | 2240 | le32_to_cpu(vals[3]) + le32_to_cpu(vals[4]); |
5d9276da PZ |
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]); | |
1da177e4 LT |
2245 | |
2246 | /* detailed rx_errors: */ | |
5d9276da PZ |
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]); | |
1da177e4 LT |
2251 | } |
2252 | ||
ff1d2767 | 2253 | static struct net_device_stats *airo_get_stats(struct net_device *dev) |
1da177e4 | 2254 | { |
faf3994a | 2255 | struct airo_info *local = dev->ml_priv; |
1da177e4 | 2256 | |
3c304956 | 2257 | if (!test_bit(JOB_STATS, &local->jobs)) { |
1da177e4 LT |
2258 | /* Get stats out of the card if available */ |
2259 | if (down_trylock(&local->sem) != 0) { | |
3c304956 | 2260 | set_bit(JOB_STATS, &local->jobs); |
1da177e4 LT |
2261 | wake_up_interruptible(&local->thr_wait); |
2262 | } else | |
5d9276da | 2263 | airo_read_stats(dev); |
1da177e4 LT |
2264 | } |
2265 | ||
5d9276da | 2266 | return &dev->stats; |
1da177e4 LT |
2267 | } |
2268 | ||
2269 | static void airo_set_promisc(struct airo_info *ai) { | |
2270 | Cmd cmd; | |
2271 | Resp rsp; | |
2272 | ||
2273 | memset(&cmd, 0, sizeof(cmd)); | |
2274 | cmd.cmd=CMD_SETMODE; | |
3c304956 | 2275 | clear_bit(JOB_PROMISC, &ai->jobs); |
1da177e4 LT |
2276 | cmd.parm0=(ai->flags&IFF_PROMISC) ? PROMISC : NOPROMISC; |
2277 | issuecommand(ai, &cmd, &rsp); | |
2278 | up(&ai->sem); | |
2279 | } | |
2280 | ||
2281 | static void airo_set_multicast_list(struct net_device *dev) { | |
faf3994a | 2282 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
2283 | |
2284 | if ((dev->flags ^ ai->flags) & IFF_PROMISC) { | |
2285 | change_bit(FLAG_PROMISC, &ai->flags); | |
2286 | if (down_trylock(&ai->sem) != 0) { | |
3c304956 | 2287 | set_bit(JOB_PROMISC, &ai->jobs); |
1da177e4 LT |
2288 | wake_up_interruptible(&ai->thr_wait); |
2289 | } else | |
2290 | airo_set_promisc(ai); | |
2291 | } | |
2292 | ||
2293 | if ((dev->flags&IFF_ALLMULTI)||dev->mc_count>0) { | |
2294 | /* Turn on multicast. (Should be already setup...) */ | |
2295 | } | |
2296 | } | |
2297 | ||
2298 | static int airo_set_mac_address(struct net_device *dev, void *p) | |
2299 | { | |
faf3994a | 2300 | struct airo_info *ai = dev->ml_priv; |
1da177e4 | 2301 | struct sockaddr *addr = p; |
1da177e4 LT |
2302 | |
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); | |
175ec1a1 | 2308 | enable_MAC(ai, 1); |
1da177e4 LT |
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; | |
2313 | } | |
2314 | ||
2315 | static int airo_change_mtu(struct net_device *dev, int new_mtu) | |
2316 | { | |
2317 | if ((new_mtu < 68) || (new_mtu > 2400)) | |
2318 | return -EINVAL; | |
2319 | dev->mtu = new_mtu; | |
2320 | return 0; | |
2321 | } | |
2322 | ||
af5b5c9a MS |
2323 | static LIST_HEAD(airo_devices); |
2324 | ||
2325 | static void add_airo_dev(struct airo_info *ai) | |
2326 | { | |
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); | |
2331 | } | |
2332 | ||
2333 | static void del_airo_dev(struct airo_info *ai) | |
2334 | { | |
2335 | if (!ai->pci) | |
2336 | list_del(&ai->dev_list); | |
2337 | } | |
1da177e4 LT |
2338 | |
2339 | static int airo_close(struct net_device *dev) { | |
faf3994a | 2340 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
2341 | |
2342 | netif_stop_queue(dev); | |
2343 | ||
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 ); | |
1c2b7db8 MS |
2355 | |
2356 | free_irq(dev->irq, dev); | |
2357 | ||
2358 | set_bit(JOB_DIE, &ai->jobs); | |
2359 | kthread_stop(ai->airo_thread_task); | |
1da177e4 LT |
2360 | } |
2361 | return 0; | |
2362 | } | |
2363 | ||
1da177e4 LT |
2364 | void stop_airo_card( struct net_device *dev, int freeres ) |
2365 | { | |
faf3994a | 2366 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
2367 | |
2368 | set_bit(FLAG_RADIO_DOWN, &ai->flags); | |
2369 | disable_MAC(ai, 1); | |
2370 | disable_interrupts(ai); | |
1da177e4 LT |
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; | |
2378 | } | |
2379 | clear_bit(FLAG_REGISTERED, &ai->flags); | |
2380 | } | |
1da177e4 LT |
2381 | /* |
2382 | * Clean out tx queue | |
2383 | */ | |
b03efcfb | 2384 | if (test_bit(FLAG_MPI, &ai->flags) && !skb_queue_empty(&ai->txq)) { |
1da177e4 LT |
2385 | struct sk_buff *skb = NULL; |
2386 | for (;(skb = skb_dequeue(&ai->txq));) | |
2387 | dev_kfree_skb(skb); | |
2388 | } | |
2389 | ||
9e75af30 DW |
2390 | airo_networks_free (ai); |
2391 | ||
b4558ea9 JJ |
2392 | kfree(ai->flash); |
2393 | kfree(ai->rssi); | |
2394 | kfree(ai->APList); | |
2395 | kfree(ai->SSID); | |
1da177e4 LT |
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); | |
2408 | } | |
2409 | } | |
f12cc209 | 2410 | crypto_free_cipher(ai->tfm); |
af5b5c9a | 2411 | del_airo_dev(ai); |
1da177e4 LT |
2412 | free_netdev( dev ); |
2413 | } | |
2414 | ||
2415 | EXPORT_SYMBOL(stop_airo_card); | |
2416 | ||
b95cce35 | 2417 | static int wll_header_parse(const struct sk_buff *skb, unsigned char *haddr) |
1da177e4 | 2418 | { |
98e399f8 | 2419 | memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN); |
1da177e4 LT |
2420 | return ETH_ALEN; |
2421 | } | |
2422 | ||
2423 | static void mpi_unmap_card(struct pci_dev *pci) | |
2424 | { | |
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; | |
2429 | ||
2430 | release_mem_region(aux_start, aux_len); | |
2431 | release_mem_region(mem_start, mem_len); | |
2432 | } | |
2433 | ||
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. | |
2440 | */ | |
2441 | static int mpi_init_descriptors (struct airo_info *ai) | |
2442 | { | |
2443 | Cmd cmd; | |
2444 | Resp rsp; | |
2445 | int i; | |
2446 | int rc = SUCCESS; | |
2447 | ||
2448 | /* Alloc card RX descriptors */ | |
2449 | netif_stop_queue(ai->dev); | |
2450 | ||
2451 | memset(&rsp,0,sizeof(rsp)); | |
2452 | memset(&cmd,0,sizeof(cmd)); | |
2453 | ||
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) { | |
934d8bf1 | 2460 | airo_print_err(ai->dev->name, "Couldn't allocate RX FID"); |
1da177e4 LT |
2461 | return rc; |
2462 | } | |
2463 | ||
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)); | |
2467 | } | |
2468 | ||
2469 | /* Alloc card TX descriptors */ | |
2470 | ||
2471 | memset(&rsp,0,sizeof(rsp)); | |
2472 | memset(&cmd,0,sizeof(cmd)); | |
2473 | ||
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; | |
2478 | ||
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)); | |
2483 | } | |
2484 | ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */ | |
2485 | ||
2486 | rc=issuecommand(ai, &cmd, &rsp); | |
2487 | if (rc != SUCCESS) { | |
934d8bf1 | 2488 | airo_print_err(ai->dev->name, "Couldn't allocate TX FID"); |
1da177e4 LT |
2489 | return rc; |
2490 | } | |
2491 | ||
2492 | /* Alloc card Rid descriptor */ | |
2493 | memset(&rsp,0,sizeof(rsp)); | |
2494 | memset(&cmd,0,sizeof(cmd)); | |
2495 | ||
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) { | |
934d8bf1 | 2502 | airo_print_err(ai->dev->name, "Couldn't allocate RID"); |
1da177e4 LT |
2503 | return rc; |
2504 | } | |
2505 | ||
2506 | memcpy_toio(ai->config_desc.card_ram_off, | |
2507 | &ai->config_desc.rid_desc, sizeof(Rid)); | |
2508 | ||
2509 | return rc; | |
2510 | } | |
2511 | ||
2512 | /* | |
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. | |
2517 | */ | |
1138c37b | 2518 | static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci) |
1da177e4 LT |
2519 | { |
2520 | unsigned long mem_start, mem_len, aux_start, aux_len; | |
2521 | int rc = -1; | |
2522 | int i; | |
2759c8d5 JG |
2523 | dma_addr_t busaddroff; |
2524 | unsigned char *vpackoff; | |
1da177e4 LT |
2525 | unsigned char __iomem *pciaddroff; |
2526 | ||
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; | |
2531 | ||
1138c37b MS |
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); | |
1da177e4 LT |
2535 | goto out; |
2536 | } | |
1138c37b MS |
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); | |
1da177e4 LT |
2540 | goto free_region1; |
2541 | } | |
2542 | ||
2543 | ai->pcimem = ioremap(mem_start, mem_len); | |
2544 | if (!ai->pcimem) { | |
1138c37b MS |
2545 | airo_print_err("", "Couldn't map region %x[%x]", |
2546 | (int)mem_start, (int)mem_len); | |
1da177e4 LT |
2547 | goto free_region2; |
2548 | } | |
2549 | ai->pciaux = ioremap(aux_start, aux_len); | |
2550 | if (!ai->pciaux) { | |
1138c37b MS |
2551 | airo_print_err("", "Couldn't map region %x[%x]", |
2552 | (int)aux_start, (int)aux_len); | |
1da177e4 LT |
2553 | goto free_memmap; |
2554 | } | |
2555 | ||
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) { | |
1138c37b MS |
2559 | airo_print_err("", "Couldn't alloc_consistent %d", |
2560 | PCI_SHARED_LEN); | |
1da177e4 LT |
2561 | goto free_auxmap; |
2562 | } | |
2563 | ||
2564 | /* | |
2565 | * Setup descriptor RX, TX, CONFIG | |
2566 | */ | |
2759c8d5 | 2567 | busaddroff = ai->shared_dma; |
1da177e4 LT |
2568 | pciaddroff = ai->pciaux + AUX_OFFSET; |
2569 | vpackoff = ai->shared; | |
2570 | ||
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; | |
2759c8d5 | 2576 | ai->rxfids[i].rx_desc.host_addr = busaddroff; |
1da177e4 LT |
2577 | ai->rxfids[i].rx_desc.valid = 1; |
2578 | ai->rxfids[i].rx_desc.len = PKTSIZE; | |
2579 | ai->rxfids[i].rx_desc.rdy = 0; | |
2580 | ||
2581 | pciaddroff += sizeof(RxFid); | |
2582 | busaddroff += PKTSIZE; | |
2583 | vpackoff += PKTSIZE; | |
2584 | } | |
2585 | ||
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; | |
2759c8d5 | 2591 | ai->txfids[i].tx_desc.host_addr = busaddroff; |
1da177e4 LT |
2592 | memcpy(ai->txfids[i].virtual_host_addr, |
2593 | &wifictlhdr8023, sizeof(wifictlhdr8023)); | |
2594 | ||
2595 | pciaddroff += sizeof(TxFid); | |
2596 | busaddroff += PKTSIZE; | |
2597 | vpackoff += PKTSIZE; | |
2598 | } | |
2599 | ai->txfids[i-1].tx_desc.eoc = 1; /* Last descriptor has EOC set */ | |
2600 | ||
2601 | /* Rid descriptor setup */ | |
2602 | ai->config_desc.card_ram_off = pciaddroff; | |
2603 | ai->config_desc.virtual_host_addr = vpackoff; | |
2759c8d5 JG |
2604 | ai->config_desc.rid_desc.host_addr = busaddroff; |
2605 | ai->ridbus = busaddroff; | |
1da177e4 LT |
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; | |
2612 | ||
2613 | /* Tell card about descriptors */ | |
2614 | if (mpi_init_descriptors (ai) != SUCCESS) | |
2615 | goto free_shared; | |
2616 | ||
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; | |
2630 | } | |
2631 | ||
3b04ddde SH |
2632 | static const struct header_ops airo_header_ops = { |
2633 | .parse = wll_header_parse, | |
2634 | }; | |
2635 | ||
1da177e4 LT |
2636 | static void wifi_setup(struct net_device *dev) |
2637 | { | |
3b04ddde | 2638 | dev->header_ops = &airo_header_ops; |
1da177e4 LT |
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; | |
1da177e4 | 2643 | dev->wireless_handlers = &airo_handler_def; |
1da177e4 LT |
2644 | dev->change_mtu = &airo_change_mtu; |
2645 | dev->open = &airo_open; | |
2646 | dev->stop = &airo_close; | |
2647 | ||
2648 | dev->type = ARPHRD_IEEE80211; | |
2649 | dev->hard_header_len = ETH_HLEN; | |
15db2763 | 2650 | dev->mtu = AIRO_DEF_MTU; |
1da177e4 LT |
2651 | dev->addr_len = ETH_ALEN; |
2652 | dev->tx_queue_len = 100; | |
2653 | ||
2654 | memset(dev->broadcast,0xFF, ETH_ALEN); | |
2655 | ||
2656 | dev->flags = IFF_BROADCAST|IFF_MULTICAST; | |
2657 | } | |
2658 | ||
2659 | static struct net_device *init_wifidev(struct airo_info *ai, | |
2660 | struct net_device *ethdev) | |
2661 | { | |
2662 | int err; | |
2663 | struct net_device *dev = alloc_netdev(0, "wifi%d", wifi_setup); | |
2664 | if (!dev) | |
2665 | return NULL; | |
faf3994a | 2666 | dev->ml_priv = ethdev->ml_priv; |
1da177e4 LT |
2667 | dev->irq = ethdev->irq; |
2668 | dev->base_addr = ethdev->base_addr; | |
1da177e4 | 2669 | dev->wireless_data = ethdev->wireless_data; |
229ce3ab | 2670 | SET_NETDEV_DEV(dev, ethdev->dev.parent); |
1da177e4 LT |
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; | |
2676 | } | |
2677 | return dev; | |
2678 | } | |
2679 | ||
ff1d2767 | 2680 | static int reset_card( struct net_device *dev , int lock) { |
faf3994a | 2681 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
2682 | |
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; | |
2693 | } | |
2694 | ||
3c304956 | 2695 | #define AIRO_MAX_NETWORK_COUNT 64 |
9e75af30 DW |
2696 | static int airo_networks_allocate(struct airo_info *ai) |
2697 | { | |
2698 | if (ai->networks) | |
2699 | return 0; | |
2700 | ||
2701 | ai->networks = | |
3c304956 | 2702 | kzalloc(AIRO_MAX_NETWORK_COUNT * sizeof(BSSListElement), |
9e75af30 DW |
2703 | GFP_KERNEL); |
2704 | if (!ai->networks) { | |
1138c37b | 2705 | airo_print_warn("", "Out of memory allocating beacons"); |
9e75af30 DW |
2706 | return -ENOMEM; |
2707 | } | |
2708 | ||
2709 | return 0; | |
2710 | } | |
2711 | ||
2712 | static void airo_networks_free(struct airo_info *ai) | |
2713 | { | |
9e75af30 DW |
2714 | kfree(ai->networks); |
2715 | ai->networks = NULL; | |
2716 | } | |
2717 | ||
2718 | static void airo_networks_initialize(struct airo_info *ai) | |
2719 | { | |
2720 | int i; | |
2721 | ||
2722 | INIT_LIST_HEAD(&ai->network_free_list); | |
2723 | INIT_LIST_HEAD(&ai->network_list); | |
3c304956 | 2724 | for (i = 0; i < AIRO_MAX_NETWORK_COUNT; i++) |
9e75af30 DW |
2725 | list_add_tail(&ai->networks[i].list, |
2726 | &ai->network_free_list); | |
2727 | } | |
2728 | ||
3c304956 DW |
2729 | static int airo_test_wpa_capable(struct airo_info *ai) |
2730 | { | |
2731 | int status; | |
2732 | CapabilityRid cap_rid; | |
3c304956 DW |
2733 | |
2734 | status = readCapabilityRid(ai, &cap_rid, 1); | |
2735 | if (status != SUCCESS) return 0; | |
2736 | ||
2737 | /* Only firmware versions 5.30.17 or better can do WPA */ | |
56d81bd3 AV |
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)) { | |
1138c37b | 2741 | airo_print_info("", "WPA is supported."); |
3c304956 DW |
2742 | return 1; |
2743 | } | |
2744 | ||
2745 | /* No WPA support */ | |
1138c37b | 2746 | airo_print_info("", "WPA unsupported (only firmware versions 5.30.17" |
3c304956 DW |
2747 | " and greater support WPA. Detected %s)", cap_rid.prodVer); |
2748 | return 0; | |
2749 | } | |
2750 | ||
ff1d2767 JM |
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 ) | |
1da177e4 LT |
2754 | { |
2755 | struct net_device *dev; | |
2756 | struct airo_info *ai; | |
2757 | int i, rc; | |
2758 | ||
2759 | /* Create the network device object. */ | |
1138c37b MS |
2760 | dev = alloc_netdev(sizeof(*ai), "", ether_setup); |
2761 | if (!dev) { | |
934d8bf1 | 2762 | airo_print_err("", "Couldn't alloc_etherdev"); |
1da177e4 | 2763 | return NULL; |
1da177e4 LT |
2764 | } |
2765 | ||
faf3994a | 2766 | ai = dev->ml_priv = netdev_priv(dev); |
1da177e4 | 2767 | ai->wifidev = NULL; |
fb038c27 | 2768 | ai->flags = 1 << FLAG_RADIO_DOWN; |
3c304956 | 2769 | ai->jobs = 0; |
934d8bf1 | 2770 | ai->dev = dev; |
1da177e4 | 2771 | if (pci && (pci->device == 0x5000 || pci->device == 0xa504)) { |
1138c37b | 2772 | airo_print_dbg("", "Found an MPI350 card"); |
1da177e4 LT |
2773 | set_bit(FLAG_MPI, &ai->flags); |
2774 | } | |
1da177e4 LT |
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); | |
1da177e4 | 2780 | ai->tfm = NULL; |
af5b5c9a | 2781 | add_airo_dev(ai); |
1da177e4 | 2782 | |
9e75af30 | 2783 | if (airo_networks_allocate (ai)) |
1c2b7db8 | 2784 | goto err_out_free; |
9e75af30 DW |
2785 | airo_networks_initialize (ai); |
2786 | ||
1da177e4 LT |
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; | |
1da177e4 LT |
2797 | dev->wireless_handlers = &airo_handler_def; |
2798 | ai->wireless_data.spy_data = &ai->spy_data; | |
2799 | dev->wireless_data = &ai->wireless_data; | |
1da177e4 LT |
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; | |
2805 | ||
2806 | SET_NETDEV_DEV(dev, dmdev); | |
2807 | ||
1d97f384 MC |
2808 | reset_card (dev, 1); |
2809 | msleep(400); | |
1da177e4 | 2810 | |
1da177e4 | 2811 | if (!is_pcmcia) { |
1138c37b | 2812 | if (!request_region(dev->base_addr, 64, DRV_NAME)) { |
1da177e4 | 2813 | rc = -EBUSY; |
934d8bf1 | 2814 | airo_print_err(dev->name, "Couldn't request region"); |
1c2b7db8 | 2815 | goto err_out_nets; |
1da177e4 LT |
2816 | } |
2817 | } | |
2818 | ||
2819 | if (test_bit(FLAG_MPI,&ai->flags)) { | |
1138c37b MS |
2820 | if (mpi_map_card(ai, pci)) { |
2821 | airo_print_err("", "Could not map memory"); | |
1da177e4 LT |
2822 | goto err_out_res; |
2823 | } | |
2824 | } | |
2825 | ||
2826 | if (probe) { | |
2827 | if ( setup_card( ai, dev->dev_addr, 1 ) != SUCCESS ) { | |
934d8bf1 | 2828 | airo_print_err(dev->name, "MAC could not be enabled" ); |
1da177e4 LT |
2829 | rc = -EIO; |
2830 | goto err_out_map; | |
2831 | } | |
2832 | } else if (!test_bit(FLAG_MPI,&ai->flags)) { | |
2833 | ai->bap_read = fast_bap_read; | |
2834 | set_bit(FLAG_FLASHING, &ai->flags); | |
2835 | } | |
2836 | ||
3c304956 DW |
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); | |
2847 | } | |
2848 | ||
1138c37b | 2849 | strcpy(dev->name, "eth%d"); |
1da177e4 LT |
2850 | rc = register_netdev(dev); |
2851 | if (rc) { | |
934d8bf1 | 2852 | airo_print_err(dev->name, "Couldn't register_netdev"); |
1da177e4 LT |
2853 | goto err_out_map; |
2854 | } | |
2855 | ai->wifidev = init_wifidev(ai, dev); | |
431aca5a FM |
2856 | if (!ai->wifidev) |
2857 | goto err_out_reg; | |
1da177e4 LT |
2858 | |
2859 | set_bit(FLAG_REGISTERED,&ai->flags); | |
e174961c | 2860 | airo_print_info(dev->name, "MAC enabled %pM", dev->dev_addr); |
1da177e4 LT |
2861 | |
2862 | /* Allocate the transmit buffers */ | |
2863 | if (probe && !test_bit(FLAG_MPI,&ai->flags)) | |
2864 | for( i = 0; i < MAX_FIDS; i++ ) | |
15db2763 | 2865 | ai->fids[i] = transmit_allocate(ai,AIRO_DEF_MTU,i>=MAX_FIDS/2); |
1da177e4 | 2866 | |
faf3994a | 2867 | if (setup_proc_entry(dev, dev->ml_priv) < 0) |
431aca5a FM |
2868 | goto err_out_wifi; |
2869 | ||
1da177e4 LT |
2870 | return dev; |
2871 | ||
431aca5a FM |
2872 | err_out_wifi: |
2873 | unregister_netdev(ai->wifidev); | |
2874 | free_netdev(ai->wifidev); | |
2875 | err_out_reg: | |
2876 | unregister_netdev(dev); | |
1da177e4 LT |
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); | |
2883 | } | |
2884 | err_out_res: | |
2885 | if (!is_pcmcia) | |
2886 | release_region( dev->base_addr, 64 ); | |
4d881901 MS |
2887 | err_out_nets: |
2888 | airo_networks_free(ai); | |
af5b5c9a | 2889 | del_airo_dev(ai); |
1da177e4 LT |
2890 | err_out_free: |
2891 | free_netdev(dev); | |
2892 | return NULL; | |
2893 | } | |
2894 | ||
2895 | struct net_device *init_airo_card( unsigned short irq, int port, int is_pcmcia, | |
2896 | struct device *dmdev) | |
2897 | { | |
2898 | return _init_airo_card ( irq, port, is_pcmcia, NULL, dmdev); | |
2899 | } | |
2900 | ||
2901 | EXPORT_SYMBOL(init_airo_card); | |
2902 | ||
2903 | static int waitbusy (struct airo_info *ai) { | |
2904 | int delay = 0; | |
b212f337 | 2905 | while ((IN4500(ai, COMMAND) & COMMAND_BUSY) && (delay < 10000)) { |
1da177e4 LT |
2906 | udelay (10); |
2907 | if ((++delay % 20) == 0) | |
2908 | OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY); | |
2909 | } | |
2910 | return delay < 10000; | |
2911 | } | |
2912 | ||
2913 | int reset_airo_card( struct net_device *dev ) | |
2914 | { | |
2915 | int i; | |
faf3994a | 2916 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
2917 | |
2918 | if (reset_card (dev, 1)) | |
2919 | return -1; | |
2920 | ||
2921 | if ( setup_card(ai, dev->dev_addr, 1 ) != SUCCESS ) { | |
934d8bf1 | 2922 | airo_print_err(dev->name, "MAC could not be enabled"); |
1da177e4 LT |
2923 | return -1; |
2924 | } | |
e174961c | 2925 | airo_print_info(dev->name, "MAC enabled %pM", dev->dev_addr); |
1da177e4 LT |
2926 | /* Allocate the transmit buffers if needed */ |
2927 | if (!test_bit(FLAG_MPI,&ai->flags)) | |
2928 | for( i = 0; i < MAX_FIDS; i++ ) | |
15db2763 | 2929 | ai->fids[i] = transmit_allocate (ai,AIRO_DEF_MTU,i>=MAX_FIDS/2); |
1da177e4 LT |
2930 | |
2931 | enable_interrupts( ai ); | |
2932 | netif_wake_queue(dev); | |
2933 | return 0; | |
2934 | } | |
2935 | ||
2936 | EXPORT_SYMBOL(reset_airo_card); | |
2937 | ||
2938 | static void airo_send_event(struct net_device *dev) { | |
faf3994a | 2939 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
2940 | union iwreq_data wrqu; |
2941 | StatusRid status_rid; | |
2942 | ||
3c304956 | 2943 | clear_bit(JOB_EVENT, &ai->jobs); |
1da177e4 LT |
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; | |
2950 | ||
2951 | /* Send event to user space */ | |
2952 | wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL); | |
2953 | } | |
2954 | ||
9e75af30 DW |
2955 | static void airo_process_scan_results (struct airo_info *ai) { |
2956 | union iwreq_data wrqu; | |
3c304956 | 2957 | BSSListRid bss; |
9e75af30 DW |
2958 | int rc; |
2959 | BSSListElement * loop_net; | |
2960 | BSSListElement * tmp_net; | |
2961 | ||
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)); | |
2967 | } | |
2968 | ||
2969 | /* Try to read the first entry of the scan result */ | |
3c304956 | 2970 | rc = PC4500_readrid(ai, ai->bssListFirst, &bss, ai->bssListRidLen, 0); |
17e70491 | 2971 | if((rc) || (bss.index == cpu_to_le16(0xffff))) { |
9e75af30 DW |
2972 | /* No scan results */ |
2973 | goto out; | |
2974 | } | |
2975 | ||
2976 | /* Read and parse all entries */ | |
2977 | tmp_net = NULL; | |
17e70491 | 2978 | while((!rc) && (bss.index != cpu_to_le16(0xffff))) { |
9e75af30 DW |
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); | |
2984 | } | |
2985 | ||
2986 | if (tmp_net != NULL) { | |
3c304956 | 2987 | memcpy(tmp_net, &bss, sizeof(tmp_net->bss)); |
9e75af30 DW |
2988 | list_add_tail(&tmp_net->list, &ai->network_list); |
2989 | tmp_net = NULL; | |
2990 | } | |
2991 | ||
2992 | /* Read next entry */ | |
3c304956 DW |
2993 | rc = PC4500_readrid(ai, ai->bssListNext, |
2994 | &bss, ai->bssListRidLen, 0); | |
9e75af30 DW |
2995 | } |
2996 | ||
2997 | out: | |
2998 | ai->scan_timeout = 0; | |
3c304956 | 2999 | clear_bit(JOB_SCAN_RESULTS, &ai->jobs); |
9e75af30 DW |
3000 | up(&ai->sem); |
3001 | ||
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); | |
3012 | } | |
3013 | ||
1da177e4 LT |
3014 | static int airo_thread(void *data) { |
3015 | struct net_device *dev = data; | |
faf3994a | 3016 | struct airo_info *ai = dev->ml_priv; |
1da177e4 | 3017 | int locked; |
83144186 RW |
3018 | |
3019 | set_freezable(); | |
1da177e4 | 3020 | while(1) { |
1da177e4 | 3021 | /* make swsusp happy with our thread */ |
3e1d1d28 | 3022 | try_to_freeze(); |
1da177e4 | 3023 | |
3c304956 | 3024 | if (test_bit(JOB_DIE, &ai->jobs)) |
1da177e4 LT |
3025 | break; |
3026 | ||
3c304956 | 3027 | if (ai->jobs) { |
1da177e4 LT |
3028 | locked = down_interruptible(&ai->sem); |
3029 | } else { | |
3030 | wait_queue_t wait; | |
3031 | ||
3032 | init_waitqueue_entry(&wait, current); | |
3033 | add_wait_queue(&ai->thr_wait, &wait); | |
3034 | for (;;) { | |
3035 | set_current_state(TASK_INTERRUPTIBLE); | |
3c304956 | 3036 | if (ai->jobs) |
1da177e4 | 3037 | break; |
9e75af30 DW |
3038 | if (ai->expires || ai->scan_timeout) { |
3039 | if (ai->scan_timeout && | |
3040 | time_after_eq(jiffies,ai->scan_timeout)){ | |
3c304956 | 3041 | set_bit(JOB_SCAN_RESULTS, &ai->jobs); |
9e75af30 DW |
3042 | break; |
3043 | } else if (ai->expires && | |
3044 | time_after_eq(jiffies,ai->expires)){ | |
3c304956 | 3045 | set_bit(JOB_AUTOWEP, &ai->jobs); |
1da177e4 LT |
3046 | break; |
3047 | } | |
5bb85f18 DK |
3048 | if (!kthread_should_stop() && |
3049 | !freezing(current)) { | |
9e75af30 DW |
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); | |
3057 | } | |
3058 | schedule_timeout(wake_at - jiffies); | |
1da177e4 LT |
3059 | continue; |
3060 | } | |
5bb85f18 DK |
3061 | } else if (!kthread_should_stop() && |
3062 | !freezing(current)) { | |
1da177e4 LT |
3063 | schedule(); |
3064 | continue; | |
3065 | } | |
3066 | break; | |
3067 | } | |
3068 | current->state = TASK_RUNNING; | |
3069 | remove_wait_queue(&ai->thr_wait, &wait); | |
3070 | locked = 1; | |
3071 | } | |
3072 | ||
3073 | if (locked) | |
3074 | continue; | |
3075 | ||
3c304956 | 3076 | if (test_bit(JOB_DIE, &ai->jobs)) { |
1da177e4 LT |
3077 | up(&ai->sem); |
3078 | break; | |
3079 | } | |
3080 | ||
ca078bae | 3081 | if (ai->power.event || test_bit(FLAG_FLASHING, &ai->flags)) { |
1da177e4 LT |
3082 | up(&ai->sem); |
3083 | continue; | |
3084 | } | |
3085 | ||
3c304956 | 3086 | if (test_bit(JOB_XMIT, &ai->jobs)) |
1da177e4 | 3087 | airo_end_xmit(dev); |
3c304956 | 3088 | else if (test_bit(JOB_XMIT11, &ai->jobs)) |
1da177e4 | 3089 | airo_end_xmit11(dev); |
3c304956 | 3090 | else if (test_bit(JOB_STATS, &ai->jobs)) |
5d9276da | 3091 | airo_read_stats(dev); |
3c304956 | 3092 | else if (test_bit(JOB_WSTATS, &ai->jobs)) |
1da177e4 | 3093 | airo_read_wireless_stats(ai); |
3c304956 | 3094 | else if (test_bit(JOB_PROMISC, &ai->jobs)) |
1da177e4 | 3095 | airo_set_promisc(ai); |
3c304956 | 3096 | else if (test_bit(JOB_MIC, &ai->jobs)) |
1da177e4 | 3097 | micinit(ai); |
3c304956 | 3098 | else if (test_bit(JOB_EVENT, &ai->jobs)) |
1da177e4 | 3099 | airo_send_event(dev); |
3c304956 | 3100 | else if (test_bit(JOB_AUTOWEP, &ai->jobs)) |
1da177e4 | 3101 | timer_func(dev); |
3c304956 | 3102 | else if (test_bit(JOB_SCAN_RESULTS, &ai->jobs)) |
9e75af30 DW |
3103 | airo_process_scan_results(ai); |
3104 | else /* Shouldn't get here, but we make sure to unlock */ | |
3105 | up(&ai->sem); | |
1da177e4 | 3106 | } |
3b4c7d64 SB |
3107 | |
3108 | return 0; | |
1da177e4 LT |
3109 | } |
3110 | ||
0300b332 AV |
3111 | static int header_len(__le16 ctl) |
3112 | { | |
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 */ | |
3122 | } | |
3123 | return 24; | |
3124 | } | |
3125 | ||
28fc1f5a JG |
3126 | static irqreturn_t airo_interrupt(int irq, void *dev_id) |
3127 | { | |
3128 | struct net_device *dev = dev_id; | |
1da177e4 LT |
3129 | u16 status; |
3130 | u16 fid; | |
faf3994a | 3131 | struct airo_info *apriv = dev->ml_priv; |
1da177e4 LT |
3132 | u16 savedInterrupts = 0; |
3133 | int handled = 0; | |
3134 | ||
3135 | if (!netif_device_present(dev)) | |
3136 | return IRQ_NONE; | |
3137 | ||
3138 | for (;;) { | |
3139 | status = IN4500( apriv, EVSTAT ); | |
3140 | if ( !(status & STATUS_INTS) || status == 0xffff ) break; | |
3141 | ||
3142 | handled = 1; | |
3143 | ||
3144 | if ( status & EV_AWAKE ) { | |
3145 | OUT4500( apriv, EVACK, EV_AWAKE ); | |
3146 | OUT4500( apriv, EVACK, EV_AWAKE ); | |
3147 | } | |
3148 | ||
3149 | if (!savedInterrupts) { | |
3150 | savedInterrupts = IN4500( apriv, EVINTEN ); | |
3151 | OUT4500( apriv, EVINTEN, 0 ); | |
3152 | } | |
3153 | ||
3154 | if ( status & EV_MIC ) { | |
3155 | OUT4500( apriv, EVACK, EV_MIC ); | |
1da177e4 | 3156 | if (test_bit(FLAG_MIC_CAPABLE, &apriv->flags)) { |
3c304956 | 3157 | set_bit(JOB_MIC, &apriv->jobs); |
1da177e4 LT |
3158 | wake_up_interruptible(&apriv->thr_wait); |
3159 | } | |
1da177e4 LT |
3160 | } |
3161 | if ( status & EV_LINK ) { | |
3162 | union iwreq_data wrqu; | |
6fcdf565 | 3163 | int scan_forceloss = 0; |
1da177e4 LT |
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!) | |
3167 | */ | |
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) */ | |
6fcdf565 DW |
3182 | #define ASSOCIATED 0x0400 /* Associated */ |
3183 | #define REASSOCIATED 0x0600 /* Reassociated? Only on firmware >= 5.30.17 */ | |
1da177e4 LT |
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 */ | |
6fcdf565 DW |
3200 | if (newStatus == FORCELOSS && apriv->scan_timeout > 0) |
3201 | scan_forceloss = 1; | |
3202 | if(newStatus == ASSOCIATED || newStatus == REASSOCIATED) { | |
1da177e4 LT |
3203 | if (auto_wep) |
3204 | apriv->expires = 0; | |
3b4c7d64 SB |
3205 | if (apriv->list_bss_task) |
3206 | wake_up_process(apriv->list_bss_task); | |
1da177e4 LT |
3207 | set_bit(FLAG_UPDATE_UNI, &apriv->flags); |
3208 | set_bit(FLAG_UPDATE_MULTI, &apriv->flags); | |
6fcdf565 | 3209 | |
1da177e4 | 3210 | if (down_trylock(&apriv->sem) != 0) { |
3c304956 | 3211 | set_bit(JOB_EVENT, &apriv->jobs); |
1da177e4 LT |
3212 | wake_up_interruptible(&apriv->thr_wait); |
3213 | } else | |
3214 | airo_send_event(dev); | |
6fcdf565 DW |
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); | |
3219 | } | |
1da177e4 LT |
3220 | |
3221 | /* Send event to user space */ | |
6fcdf565 DW |
3222 | memset(wrqu.ap_addr.sa_data, '\0', ETH_ALEN); |
3223 | wrqu.ap_addr.sa_family = ARPHRD_ETHER; | |
1da177e4 LT |
3224 | wireless_send_event(dev, SIOCGIWAP, &wrqu,NULL); |
3225 | } | |
3226 | } | |
3227 | ||
3228 | /* Check to see if there is something to receive */ | |
3229 | if ( status & EV_RX ) { | |
3230 | struct sk_buff *skb = NULL; | |
b8c06bc1 AV |
3231 | __le16 fc, v; |
3232 | u16 len, hdrlen = 0; | |
1da177e4 LT |
3233 | #pragma pack(1) |
3234 | struct { | |
593c2b9c | 3235 | __le16 status, len; |
1da177e4 LT |
3236 | u8 rssi[2]; |
3237 | u8 rate; | |
3238 | u8 freq; | |
593c2b9c | 3239 | __le16 tmp[4]; |
1da177e4 LT |
3240 | } hdr; |
3241 | #pragma pack() | |
3242 | u16 gap; | |
b8c06bc1 AV |
3243 | __le16 tmpbuf[4]; |
3244 | __le16 *buffer; | |
1da177e4 LT |
3245 | |
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; | |
3253 | } | |
3254 | ||
3255 | fid = IN4500( apriv, RXFID ); | |
3256 | ||
3257 | /* Get the packet length */ | |
3258 | if (test_bit(FLAG_802_11, &apriv->flags)) { | |
3259 | bap_setup (apriv, fid, 4, BAP0); | |
b8c06bc1 | 3260 | bap_read (apriv, (__le16*)&hdr, sizeof(hdr), BAP0); |
1da177e4 LT |
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); | |
b8c06bc1 | 3268 | bap_read (apriv, &hdr.len, 2, BAP0); |
1da177e4 LT |
3269 | } |
3270 | len = le16_to_cpu(hdr.len); | |
3271 | ||
15db2763 | 3272 | if (len > AIRO_DEF_MTU) { |
934d8bf1 | 3273 | airo_print_err(apriv->dev->name, "Bad size %d", len); |
1da177e4 LT |
3274 | goto badrx; |
3275 | } | |
3276 | if (len == 0) | |
3277 | goto badrx; | |
3278 | ||
3279 | if (test_bit(FLAG_802_11, &apriv->flags)) { | |
0300b332 AV |
3280 | bap_read (apriv, &fc, sizeof(fc), BAP0); |
3281 | hdrlen = header_len(fc); | |
1da177e4 LT |
3282 | } else |
3283 | hdrlen = ETH_ALEN * 2; | |
3284 | ||
3285 | skb = dev_alloc_skb( len + hdrlen + 2 + 2 ); | |
3286 | if ( !skb ) { | |
5d9276da | 3287 | dev->stats.rx_dropped++; |
1da177e4 LT |
3288 | goto badrx; |
3289 | } | |
3290 | skb_reserve(skb, 2); /* This way the IP header is aligned */ | |
b8c06bc1 | 3291 | buffer = (__le16*)skb_put (skb, len + hdrlen); |
1da177e4 LT |
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); | |
3297 | ||
b8c06bc1 AV |
3298 | bap_read (apriv, &v, sizeof(v), BAP0); |
3299 | gap = le16_to_cpu(v); | |
1da177e4 | 3300 | if (gap) { |
934d8bf1 | 3301 | if (gap <= 8) { |
1da177e4 | 3302 | bap_read (apriv, tmpbuf, gap, BAP0); |
934d8bf1 DW |
3303 | } else { |
3304 | airo_print_err(apriv->dev->name, "gaplen too " | |
3305 | "big. Problems will follow..."); | |
3306 | } | |
1da177e4 LT |
3307 | } |
3308 | bap_read (apriv, buffer + hdrlen/2, len, BAP0); | |
3309 | } else { | |
1da177e4 | 3310 | MICBuffer micbuf; |
1da177e4 | 3311 | bap_read (apriv, buffer, ETH_ALEN*2, BAP0); |
1da177e4 | 3312 | if (apriv->micstats.enabled) { |
b8c06bc1 | 3313 | bap_read (apriv,(__le16*)&micbuf,sizeof(micbuf),BAP0); |
1da177e4 LT |
3314 | if (ntohs(micbuf.typelen) > 0x05DC) |
3315 | bap_setup (apriv, fid, 0x44, BAP0); | |
3316 | else { | |
3317 | if (len <= sizeof(micbuf)) | |
3318 | goto badmic; | |
3319 | ||
3320 | len -= sizeof(micbuf); | |
3321 | skb_trim (skb, len + hdrlen); | |
3322 | } | |
3323 | } | |
1da177e4 | 3324 | bap_read(apriv,buffer+ETH_ALEN,len,BAP0); |
1da177e4 LT |
3325 | if (decapsulate(apriv,&micbuf,(etherHead*)buffer,len)) { |
3326 | badmic: | |
3327 | dev_kfree_skb_irq (skb); | |
1da177e4 LT |
3328 | badrx: |
3329 | OUT4500( apriv, EVACK, EV_RX); | |
3330 | goto exitrx; | |
3331 | } | |
3332 | } | |
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); | |
b8c06bc1 | 3341 | bap_read (apriv, (__le16*)hdr.rssi, 2, BAP0); |
1da177e4 LT |
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; | |
41480af2 DW |
3349 | wstats.noise = apriv->wstats.qual.noise; |
3350 | wstats.updated = IW_QUAL_LEVEL_UPDATED | |
3351 | | IW_QUAL_QUAL_UPDATED | |
ce6623c3 | 3352 | | IW_QUAL_DBM; |
1da177e4 LT |
3353 | /* Update spy records */ |
3354 | wireless_spy_update(dev, sa, &wstats); | |
3355 | } | |
3356 | #endif /* WIRELESS_SPY */ | |
3357 | OUT4500( apriv, EVACK, EV_RX); | |
3358 | ||
3359 | if (test_bit(FLAG_802_11, &apriv->flags)) { | |
459a98ed | 3360 | skb_reset_mac_header(skb); |
1da177e4 LT |
3361 | skb->pkt_type = PACKET_OTHERHOST; |
3362 | skb->dev = apriv->wifidev; | |
3363 | skb->protocol = htons(ETH_P_802_2); | |
4c13eb66 | 3364 | } else |
1da177e4 | 3365 | skb->protocol = eth_type_trans(skb,dev); |
1da177e4 LT |
3366 | skb->ip_summed = CHECKSUM_NONE; |
3367 | ||
3368 | netif_rx( skb ); | |
3369 | } | |
3370 | exitrx: | |
3371 | ||
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; | |
3377 | ||
3378 | if (test_bit(FLAG_MPI,&apriv->flags)) { | |
3379 | unsigned long flags; | |
3380 | ||
3381 | if (status & EV_TXEXC) | |
3382 | get_tx_error(apriv, -1); | |
3383 | spin_lock_irqsave(&apriv->aux_lock, flags); | |
b03efcfb | 3384 | if (!skb_queue_empty(&apriv->txq)) { |
1da177e4 LT |
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); | |
3391 | } | |
3392 | OUT4500( apriv, EVACK, | |
3393 | status & (EV_TX|EV_TXCPY|EV_TXEXC)); | |
3394 | goto exittx; | |
3395 | } | |
3396 | ||
3397 | fid = IN4500(apriv, TXCOMPLFID); | |
3398 | ||
3399 | for( i = 0; i < MAX_FIDS; i++ ) { | |
3400 | if ( ( apriv->fids[i] & 0xffff ) == fid ) { | |
3401 | len = apriv->fids[i] >> 16; | |
3402 | index = i; | |
3403 | } | |
3404 | } | |
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); | |
3417 | } | |
3418 | } else { | |
3419 | OUT4500( apriv, EVACK, status & (EV_TX | EV_TXCPY | EV_TXEXC)); | |
934d8bf1 DW |
3420 | airo_print_err(apriv->dev->name, "Unallocated FID was " |
3421 | "used to xmit" ); | |
1da177e4 LT |
3422 | } |
3423 | } | |
3424 | exittx: | |
3425 | if ( status & ~STATUS_INTS & ~IGNORE_INTS ) | |
934d8bf1 | 3426 | airo_print_warn(apriv->dev->name, "Got weird status %x", |
1da177e4 LT |
3427 | status & ~STATUS_INTS & ~IGNORE_INTS ); |
3428 | } | |
3429 | ||
3430 | if (savedInterrupts) | |
3431 | OUT4500( apriv, EVINTEN, savedInterrupts ); | |
3432 | ||
3433 | /* done.. */ | |
3434 | return IRQ_RETVAL(handled); | |
3435 | } | |
3436 | ||
3437 | /* | |
3438 | * Routines to talk to the card | |
3439 | */ | |
3440 | ||
3441 | /* | |
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?!? | |
3445 | */ | |
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 ); | |
3454 | } | |
3455 | } | |
3456 | ||
3457 | static u16 IN4500( struct airo_info *ai, u16 reg ) { | |
3458 | unsigned short rc; | |
3459 | ||
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; | |
3467 | } | |
3468 | return rc; | |
3469 | } | |
3470 | ||
175ec1a1 MS |
3471 | static int enable_MAC(struct airo_info *ai, int lock) |
3472 | { | |
1da177e4 | 3473 | int rc; |
175ec1a1 MS |
3474 | Cmd cmd; |
3475 | Resp rsp; | |
1da177e4 LT |
3476 | |
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; | |
3484 | ||
3485 | if (lock && down_interruptible(&ai->sem)) | |
3486 | return -ERESTARTSYS; | |
3487 | ||
3488 | if (!test_bit(FLAG_ENABLED, &ai->flags)) { | |
3489 | memset(&cmd, 0, sizeof(cmd)); | |
3490 | cmd.cmd = MAC_ENABLE; | |
175ec1a1 | 3491 | rc = issuecommand(ai, &cmd, &rsp); |
1da177e4 LT |
3492 | if (rc == SUCCESS) |
3493 | set_bit(FLAG_ENABLED, &ai->flags); | |
3494 | } else | |
3495 | rc = SUCCESS; | |
3496 | ||
3497 | if (lock) | |
3498 | up(&ai->sem); | |
3499 | ||
3500 | if (rc) | |
175ec1a1 MS |
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; | |
3506 | } | |
1da177e4 LT |
3507 | return rc; |
3508 | } | |
3509 | ||
3510 | static void disable_MAC( struct airo_info *ai, int lock ) { | |
3511 | Cmd cmd; | |
3512 | Resp rsp; | |
3513 | ||
3514 | if (lock && down_interruptible(&ai->sem)) | |
3515 | return; | |
3516 | ||
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); | |
3522 | } | |
3523 | if (lock) | |
3524 | up(&ai->sem); | |
3525 | } | |
3526 | ||
3527 | static void enable_interrupts( struct airo_info *ai ) { | |
3528 | /* Enable the interrupts */ | |
3529 | OUT4500( ai, EVINTEN, STATUS_INTS ); | |
3530 | } | |
3531 | ||
3532 | static void disable_interrupts( struct airo_info *ai ) { | |
3533 | OUT4500( ai, EVINTEN, 0 ); | |
3534 | } | |
3535 | ||
3536 | static void mpi_receive_802_3(struct airo_info *ai) | |
3537 | { | |
3538 | RxFid rxd; | |
3539 | int len = 0; | |
3540 | struct sk_buff *skb; | |
3541 | char *buffer; | |
1da177e4 LT |
3542 | int off = 0; |
3543 | MICBuffer micbuf; | |
1da177e4 LT |
3544 | |
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; | |
3551 | ||
3552 | skb = dev_alloc_skb(len); | |
3553 | if (!skb) { | |
5d9276da | 3554 | ai->dev->stats.rx_dropped++; |
1da177e4 LT |
3555 | goto badrx; |
3556 | } | |
3557 | buffer = skb_put(skb,len); | |
1da177e4 LT |
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; | |
3566 | ||
3567 | off = sizeof(micbuf); | |
3568 | skb_trim (skb, len - off); | |
3569 | } | |
3570 | } | |
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; | |
3578 | } | |
1da177e4 LT |
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); | |
3590 | } | |
3591 | #endif /* WIRELESS_SPY */ | |
3592 | ||
1da177e4 LT |
3593 | skb->ip_summed = CHECKSUM_NONE; |
3594 | skb->protocol = eth_type_trans(skb, ai->dev); | |
1da177e4 LT |
3595 | netif_rx(skb); |
3596 | } | |
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)); | |
3603 | } | |
3604 | } | |
3605 | ||
2ed5ba89 | 3606 | static void mpi_receive_802_11(struct airo_info *ai) |
1da177e4 LT |
3607 | { |
3608 | RxFid rxd; | |
3609 | struct sk_buff *skb = NULL; | |
0300b332 AV |
3610 | u16 len, hdrlen = 0; |
3611 | __le16 fc; | |
1da177e4 LT |
3612 | #pragma pack(1) |
3613 | struct { | |
593c2b9c | 3614 | __le16 status, len; |
1da177e4 LT |
3615 | u8 rssi[2]; |
3616 | u8 rate; | |
3617 | u8 freq; | |
593c2b9c | 3618 | __le16 tmp[4]; |
1da177e4 LT |
3619 | } hdr; |
3620 | #pragma pack() | |
3621 | u16 gap; | |
3622 | u16 *buffer; | |
3623 | char *ptr = ai->rxfids[0].virtual_host_addr+4; | |
3624 | ||
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); | |
15db2763 | 3634 | if (len > AIRO_DEF_MTU) { |
934d8bf1 | 3635 | airo_print_err(ai->dev->name, "Bad size %d", len); |
1da177e4 LT |
3636 | goto badrx; |
3637 | } | |
3638 | if (len == 0) | |
3639 | goto badrx; | |
3640 | ||
0300b332 AV |
3641 | fc = get_unaligned((__le16 *)ptr); |
3642 | hdrlen = header_len(fc); | |
1da177e4 LT |
3643 | |
3644 | skb = dev_alloc_skb( len + hdrlen + 2 ); | |
3645 | if ( !skb ) { | |
5d9276da | 3646 | ai->dev->stats.rx_dropped++; |
1da177e4 LT |
3647 | goto badrx; |
3648 | } | |
3649 | buffer = (u16*)skb_put (skb, len + hdrlen); | |
3650 | memcpy ((char *)buffer, ptr, hdrlen); | |
3651 | ptr += hdrlen; | |
3652 | if (hdrlen == 24) | |
3653 | ptr += 6; | |
533dd1b0 | 3654 | gap = get_unaligned_le16(ptr); |
593c2b9c | 3655 | ptr += sizeof(__le16); |
1da177e4 LT |
3656 | if (gap) { |
3657 | if (gap <= 8) | |
3658 | ptr += gap; | |
3659 | else | |
934d8bf1 DW |
3660 | airo_print_err(ai->dev->name, |
3661 | "gaplen too big. Problems will follow..."); | |
1da177e4 LT |
3662 | } |
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; | |
41480af2 DW |
3676 | wstats.noise = ai->wstats.qual.noise; |
3677 | wstats.updated = IW_QUAL_QUAL_UPDATED | |
3678 | | IW_QUAL_LEVEL_UPDATED | |
ce6623c3 | 3679 | | IW_QUAL_DBM; |
1da177e4 LT |
3680 | /* Update spy records */ |
3681 | wireless_spy_update(ai->dev, sa, &wstats); | |
3682 | } | |
3683 | #endif /* IW_WIRELESS_SPY */ | |
459a98ed | 3684 | skb_reset_mac_header(skb); |
1da177e4 LT |
3685 | skb->pkt_type = PACKET_OTHERHOST; |
3686 | skb->dev = ai->wifidev; | |
3687 | skb->protocol = htons(ETH_P_802_2); | |
1da177e4 LT |
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)); | |
3696 | } | |
3697 | } | |
3698 | ||
3699 | static u16 setup_card(struct airo_info *ai, u8 *mac, int lock) | |
3700 | { | |
3701 | Cmd cmd; | |
3702 | Resp rsp; | |
3703 | int status; | |
3704 | int i; | |
3705 | SsidRid mySsid; | |
4293ea33 | 3706 | __le16 lastindex; |
1da177e4 LT |
3707 | WepKeyRid wkr; |
3708 | int rc; | |
3709 | ||
3710 | memset( &mySsid, 0, sizeof( mySsid ) ); | |
b4558ea9 JJ |
3711 | kfree (ai->flash); |
3712 | ai->flash = NULL; | |
1da177e4 LT |
3713 | |
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; | |
3723 | } | |
3724 | disable_MAC( ai, 0); | |
3725 | ||
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); | |
934d8bf1 | 3732 | airo_print_err(ai->dev->name, "Error checking for AUX port"); |
1da177e4 LT |
3733 | return ERROR; |
3734 | } | |
3735 | if (!aux_bap || rsp.status & 0xff00) { | |
3736 | ai->bap_read = fast_bap_read; | |
934d8bf1 | 3737 | airo_print_dbg(ai->dev->name, "Doing fast bap_reads"); |
1da177e4 LT |
3738 | } else { |
3739 | ai->bap_read = aux_bap_read; | |
934d8bf1 | 3740 | airo_print_dbg(ai->dev->name, "Doing AUX bap_reads"); |
1da177e4 LT |
3741 | } |
3742 | } | |
3743 | if (lock) | |
3744 | up(&ai->sem); | |
3745 | if (ai->config.len == 0) { | |
3746 | tdsRssiRid rssi_rid; | |
3747 | CapabilityRid cap_rid; | |
3748 | ||
b4558ea9 JJ |
3749 | kfree(ai->APList); |
3750 | ai->APList = NULL; | |
3751 | kfree(ai->SSID); | |
3752 | ai->SSID = NULL; | |
1da177e4 LT |
3753 | // general configuration (read/modify/write) |
3754 | status = readConfigRid(ai, lock); | |
3755 | if ( status != SUCCESS ) return ERROR; | |
3756 | ||
3757 | status = readCapabilityRid(ai, &cap_rid, lock); | |
3758 | if ( status != SUCCESS ) return ERROR; | |
3759 | ||
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) | |
41480af2 | 3763 | memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512); /* Skip RID length member */ |
1da177e4 LT |
3764 | } |
3765 | else { | |
b4558ea9 JJ |
3766 | kfree(ai->rssi); |
3767 | ai->rssi = NULL; | |
56d81bd3 | 3768 | if (cap_rid.softCap & cpu_to_le16(8)) |
1da177e4 LT |
3769 | ai->config.rmode |= RXMODE_NORMALIZED_RSSI; |
3770 | else | |
934d8bf1 DW |
3771 | airo_print_warn(ai->dev->name, "unknown received signal " |
3772 | "level scale"); | |
1da177e4 LT |
3773 | } |
3774 | ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS; | |
3775 | ai->config.authType = AUTH_OPEN; | |
3776 | ai->config.modulation = MOD_CCK; | |
3777 | ||
56d81bd3 | 3778 | if (le16_to_cpu(cap_rid.len) >= sizeof(cap_rid) && |
15617858 | 3779 | (cap_rid.extSoftCap & cpu_to_le16(1)) && |
56d81bd3 | 3780 | micsetup(ai) == SUCCESS) { |
1da177e4 LT |
3781 | ai->config.opmode |= MODE_MIC; |
3782 | set_bit(FLAG_MIC_CAPABLE, &ai->flags); | |
3783 | } | |
1da177e4 LT |
3784 | |
3785 | /* Save off the MAC */ | |
3786 | for( i = 0; i < ETH_ALEN; i++ ) { | |
3787 | mac[i] = ai->config.macAddr[i]; | |
3788 | } | |
3789 | ||
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]; | |
3797 | } | |
3798 | } | |
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; | |
3806 | } | |
3807 | } | |
3808 | } | |
3809 | set_bit (FLAG_COMMIT, &ai->flags); | |
3810 | } | |
3811 | ||
3812 | /* Setup the SSIDs if present */ | |
3813 | if ( ssids[0] ) { | |
3814 | int i; | |
3815 | for( i = 0; i < 3 && ssids[i]; i++ ) { | |
0dd2212f AV |
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); | |
1da177e4 | 3821 | } |
0dd2212f | 3822 | mySsid.len = cpu_to_le16(sizeof(mySsid)); |
1da177e4 LT |
3823 | } |
3824 | ||
3825 | status = writeConfigRid(ai, lock); | |
3826 | if ( status != SUCCESS ) return ERROR; | |
3827 | ||
3828 | /* Set up the SSID list */ | |
3829 | if ( ssids[0] ) { | |
3830 | status = writeSsidRid(ai, &mySsid, lock); | |
3831 | if ( status != SUCCESS ) return ERROR; | |
3832 | } | |
3833 | ||
175ec1a1 MS |
3834 | status = enable_MAC(ai, lock); |
3835 | if (status != SUCCESS) | |
1da177e4 | 3836 | return ERROR; |
1da177e4 LT |
3837 | |
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; | |
4293ea33 | 3842 | if (wkr.kindex == cpu_to_le16(0xffff)) { |
1da177e4 LT |
3843 | ai->defindex = wkr.mac[0]; |
3844 | } | |
3845 | rc = readWepKeyRid(ai, &wkr, 0, lock); | |
3846 | } while(lastindex != wkr.kindex); | |
3847 | ||
1c2b7db8 | 3848 | try_auto_wep(ai); |
1da177e4 LT |
3849 | |
3850 | return SUCCESS; | |
3851 | } | |
3852 | ||
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; | |
3856 | ||
3857 | if (IN4500(ai, EVSTAT) & EV_CMD) | |
3858 | OUT4500(ai, EVACK, EV_CMD); | |
3859 | ||
3860 | OUT4500(ai, PARAM0, pCmd->parm0); | |
3861 | OUT4500(ai, PARAM1, pCmd->parm1); | |
3862 | OUT4500(ai, PARAM2, pCmd->parm2); | |
3863 | OUT4500(ai, COMMAND, pCmd->cmd); | |
3864 | ||
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(); | |
3871 | } | |
3872 | ||
3873 | if ( max_tries == -1 ) { | |
934d8bf1 DW |
3874 | airo_print_err(ai->dev->name, |
3875 | "Max tries exceeded when issueing command"); | |
1da177e4 LT |
3876 | if (IN4500(ai, COMMAND) & COMMAND_BUSY) |
3877 | OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY); | |
3878 | return ERROR; | |
3879 | } | |
3880 | ||
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); | |
13dca9b8 RS |
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); | |
1da177e4 LT |
3891 | |
3892 | // clear stuck command busy if necessary | |
3893 | if (IN4500(ai, COMMAND) & COMMAND_BUSY) { | |
3894 | OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY); | |
3895 | } | |
3896 | // acknowledge processing the status/response | |
3897 | OUT4500(ai, EVACK, EV_CMD); | |
3898 | ||
3899 | return SUCCESS; | |
3900 | } | |
3901 | ||
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 ) | |
3906 | { | |
3907 | int timeout = 50; | |
3908 | int max_tries = 3; | |
3909 | ||
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; | |
3919 | } | |
3920 | } else if ( status & BAP_ERR ) { | |
3921 | /* invalid rid or offset */ | |
934d8bf1 | 3922 | airo_print_err(ai->dev->name, "BAP error %x %d", |
1da177e4 LT |
3923 | status, whichbap ); |
3924 | return ERROR; | |
3925 | } else if (status & BAP_DONE) { // success | |
3926 | return SUCCESS; | |
3927 | } | |
3928 | if ( !(max_tries--) ) { | |
934d8bf1 | 3929 | airo_print_err(ai->dev->name, |
1138c37b | 3930 | "BAP setup error too many retries\n"); |
1da177e4 LT |
3931 | return ERROR; |
3932 | } | |
3933 | // -- PC4500 missed it, try again | |
3934 | OUT4500(ai, SELECT0+whichbap, rid); | |
3935 | OUT4500(ai, OFFSET0+whichbap, offset); | |
3936 | timeout = 50; | |
3937 | } | |
3938 | } | |
3939 | ||
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) | |
3945 | { | |
3946 | u16 next; | |
3947 | ||
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; | |
3954 | } | |
3955 | ||
3956 | /* requires call to bap_setup() first */ | |
b8c06bc1 | 3957 | static int aux_bap_read(struct airo_info *ai, __le16 *pu16Dst, |
1da177e4 LT |
3958 | int bytelen, int whichbap) |
3959 | { | |
3960 | u16 len; | |
3961 | u16 page; | |
3962 | u16 offset; | |
3963 | u16 next; | |
3964 | int words; | |
3965 | int i; | |
3966 | unsigned long flags; | |
3967 | ||
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; | |
3973 | ||
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); | |
3986 | } | |
3987 | } | |
3988 | spin_unlock_irqrestore(&ai->aux_lock, flags); | |
3989 | return SUCCESS; | |
3990 | } | |
3991 | ||
3992 | ||
3993 | /* requires call to bap_setup() first */ | |
b8c06bc1 | 3994 | static int fast_bap_read(struct airo_info *ai, __le16 *pu16Dst, |
1da177e4 LT |
3995 | int bytelen, int whichbap) |
3996 | { | |
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; | |
4003 | } | |
4004 | ||
4005 | /* requires call to bap_setup() first */ | |
b8c06bc1 | 4006 | static int bap_write(struct airo_info *ai, const __le16 *pu16Src, |
1da177e4 LT |
4007 | int bytelen, int whichbap) |
4008 | { | |
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; | |
4016 | } | |
4017 | ||
4018 | static int PC4500_accessrid(struct airo_info *ai, u16 rid, u16 accmd) | |
4019 | { | |
4020 | Cmd cmd; /* for issuing commands */ | |
4021 | Resp rsp; /* response from commands */ | |
4022 | u16 status; | |
4023 | ||
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); | |
4031 | } | |
4032 | return 0; | |
4033 | } | |
4034 | ||
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) | |
4038 | { | |
4039 | u16 status; | |
4040 | int rc = SUCCESS; | |
4041 | ||
4042 | if (lock) { | |
4043 | if (down_interruptible(&ai->sem)) | |
4044 | return ERROR; | |
4045 | } | |
4046 | if (test_bit(FLAG_MPI,&ai->flags)) { | |
4047 | Cmd cmd; | |
4048 | Resp rsp; | |
4049 | ||
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; | |
4056 | ||
4057 | cmd.cmd = CMD_ACCESS; | |
4058 | cmd.parm0 = rid; | |
4059 | ||
4060 | memcpy_toio(ai->config_desc.card_ram_off, | |
4061 | &ai->config_desc.rid_desc, sizeof(Rid)); | |
4062 | ||
4063 | rc = issuecommand(ai, &cmd, &rsp); | |
4064 | ||
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; | |
4074 | } | |
4075 | if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) { | |
4076 | rc = ERROR; | |
4077 | goto done; | |
4078 | } | |
4079 | // read the rid length field | |
4080 | bap_read(ai, pBuf, 2, BAP1); | |
4081 | // length for remaining part of rid | |
593c2b9c | 4082 | len = min(len, (int)le16_to_cpu(*(__le16*)pBuf)) - 2; |
1da177e4 LT |
4083 | |
4084 | if ( len <= 2 ) { | |
934d8bf1 DW |
4085 | airo_print_err(ai->dev->name, |
4086 | "Rid %x has a length of %d which is too short", | |
1da177e4 LT |
4087 | (int)rid, (int)len ); |
4088 | rc = ERROR; | |
4089 | goto done; | |
4090 | } | |
4091 | // read remainder of the rid | |
b8c06bc1 | 4092 | rc = bap_read(ai, ((__le16*)pBuf)+1, len, BAP1); |
1da177e4 LT |
4093 | } |
4094 | done: | |
4095 | if (lock) | |
4096 | up(&ai->sem); | |
4097 | return rc; | |
4098 | } | |
4099 | ||
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) | |
4104 | { | |
4105 | u16 status; | |
4106 | int rc = SUCCESS; | |
4107 | ||
593c2b9c | 4108 | *(__le16*)pBuf = cpu_to_le16((u16)len); |
1da177e4 LT |
4109 | |
4110 | if (lock) { | |
4111 | if (down_interruptible(&ai->sem)) | |
4112 | return ERROR; | |
4113 | } | |
4114 | if (test_bit(FLAG_MPI,&ai->flags)) { | |
4115 | Cmd cmd; | |
4116 | Resp rsp; | |
4117 | ||
f89b2321 | 4118 | if (test_bit(FLAG_ENABLED, &ai->flags) && (RID_WEP_TEMP != rid)) |
934d8bf1 DW |
4119 | airo_print_err(ai->dev->name, |
4120 | "%s: MAC should be disabled (rid=%04x)", | |
c94c93da | 4121 | __func__, rid); |
1da177e4 LT |
4122 | memset(&cmd, 0, sizeof(cmd)); |
4123 | memset(&rsp, 0, sizeof(rsp)); | |
4124 | ||
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; | |
4128 | ||
4129 | cmd.cmd = CMD_WRITERID; | |
4130 | cmd.parm0 = rid; | |
4131 | ||
4132 | memcpy_toio(ai->config_desc.card_ram_off, | |
4133 | &ai->config_desc.rid_desc, sizeof(Rid)); | |
4134 | ||
4135 | if (len < 4 || len > 2047) { | |
c94c93da | 4136 | airo_print_err(ai->dev->name, "%s: len=%d", __func__, len); |
1da177e4 LT |
4137 | rc = -1; |
4138 | } else { | |
4139 | memcpy((char *)ai->config_desc.virtual_host_addr, | |
4140 | pBuf, len); | |
4141 | ||
4142 | rc = issuecommand(ai, &cmd, &rsp); | |
4143 | if ((rc & 0xff00) != 0) { | |
934d8bf1 | 4144 | airo_print_err(ai->dev->name, "%s: Write rid Error %d", |
c94c93da | 4145 | __func__, rc); |
934d8bf1 | 4146 | airo_print_err(ai->dev->name, "%s: Cmd=%04x", |
c94c93da | 4147 | __func__, cmd.cmd); |
1da177e4 LT |
4148 | } |
4149 | ||
4150 | if ((rsp.status & 0x7f00)) | |
4151 | rc = rsp.rsp0; | |
4152 | } | |
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; | |
4158 | } | |
4159 | // --- now write the rid data | |
4160 | if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) { | |
4161 | rc = ERROR; | |
4162 | goto done; | |
4163 | } | |
4164 | bap_write(ai, pBuf, len, BAP1); | |
4165 | // ---now commit the rid data | |
4166 | rc = PC4500_accessrid(ai, rid, 0x100|CMD_ACCESS); | |
4167 | } | |
4168 | done: | |
4169 | if (lock) | |
4170 | up(&ai->sem); | |
4171 | return rc; | |
4172 | } | |
4173 | ||
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) | |
4177 | { | |
4178 | unsigned int loop = 3000; | |
4179 | Cmd cmd; | |
4180 | Resp rsp; | |
4181 | u16 txFid; | |
593c2b9c | 4182 | __le16 txControl; |
1da177e4 LT |
4183 | |
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; | |
4191 | } | |
4192 | if ( (rsp.status & 0xFF00) != 0) { | |
4193 | txFid = ERROR; | |
4194 | goto done; | |
4195 | } | |
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; | |
4203 | } | |
4204 | ||
4205 | // get the allocated fid and acknowledge | |
4206 | txFid = IN4500(ai, TXALLOCFID); | |
4207 | OUT4500(ai, EVACK, EV_ALLOC); | |
4208 | ||
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); | |
4224 | ||
4225 | done: | |
4226 | up(&ai->sem); | |
4227 | ||
4228 | return txFid; | |
4229 | } | |
4230 | ||
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) | |
4235 | { | |
593c2b9c | 4236 | __le16 payloadLen; |
1da177e4 LT |
4237 | Cmd cmd; |
4238 | Resp rsp; | |
4239 | int miclen = 0; | |
4240 | u16 txFid = len; | |
4241 | MICBuffer pMic; | |
4242 | ||
4243 | len >>= 16; | |
4244 | ||
4245 | if (len <= ETH_ALEN * 2) { | |
934d8bf1 | 4246 | airo_print_warn(ai->dev->name, "Short packet %d", len); |
1da177e4 LT |
4247 | return ERROR; |
4248 | } | |
4249 | len -= ETH_ALEN * 2; | |
4250 | ||
1da177e4 | 4251 | if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled && |
593c2b9c | 4252 | (ntohs(((__be16 *)pPacket)[6]) != 0x888E)) { |
1da177e4 LT |
4253 | if (encapsulate(ai,(etherHead *)pPacket,&pMic,len) != SUCCESS) |
4254 | return ERROR; | |
4255 | miclen = sizeof(pMic); | |
4256 | } | |
1da177e4 LT |
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); | |
b8c06bc1 | 4264 | bap_write(ai, (__le16*)pPacket, sizeof(etherHead), BAP1); |
1da177e4 | 4265 | if (miclen) |
b8c06bc1 AV |
4266 | bap_write(ai, (__le16*)&pMic, miclen, BAP1); |
4267 | bap_write(ai, (__le16*)(pPacket + sizeof(etherHead)), len, BAP1); | |
1da177e4 LT |
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; | |
4275 | } | |
4276 | ||
4277 | static int transmit_802_11_packet(struct airo_info *ai, int len, char *pPacket) | |
4278 | { | |
593c2b9c | 4279 | __le16 fc, payloadLen; |
1da177e4 LT |
4280 | Cmd cmd; |
4281 | Resp rsp; | |
4282 | int hdrlen; | |
977b143c AV |
4283 | static u8 tail[(30-10) + 2 + 6] = {[30-10] = 6}; |
4284 | /* padding of header to full size + le16 gaplen (6) + gaplen bytes */ | |
1da177e4 LT |
4285 | u16 txFid = len; |
4286 | len >>= 16; | |
1da177e4 | 4287 | |
0300b332 AV |
4288 | fc = *(__le16*)pPacket; |
4289 | hdrlen = header_len(fc); | |
1da177e4 LT |
4290 | |
4291 | if (len < hdrlen) { | |
934d8bf1 | 4292 | airo_print_warn(ai->dev->name, "Short packet %d", len); |
1da177e4 LT |
4293 | return ERROR; |
4294 | } | |
4295 | ||
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; | |
b8c06bc1 AV |
4304 | bap_write(ai, (__le16 *)pPacket, hdrlen, BAP1); |
4305 | bap_write(ai, (__le16 *)(tail + (hdrlen - 10)), 38 - hdrlen, BAP1); | |
1da177e4 | 4306 | |
b8c06bc1 | 4307 | bap_write(ai, (__le16 *)(pPacket + hdrlen), len - hdrlen, BAP1); |
1da177e4 LT |
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; | |
4315 | } | |
4316 | ||
4317 | /* | |
4318 | * This is the proc_fs routines. It is a bit messier than I would | |
4319 | * like! Feel free to clean it up! | |
4320 | */ | |
4321 | ||
4322 | static ssize_t proc_read( struct file *file, | |
4323 | char __user *buffer, | |
4324 | size_t len, | |
4325 | loff_t *offset); | |
4326 | ||
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 ); | |
4332 | ||
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 ); | |
4341 | ||
d54b1fdb | 4342 | static const struct file_operations proc_statsdelta_ops = { |
a95609cb | 4343 | .owner = THIS_MODULE, |
1da177e4 LT |
4344 | .read = proc_read, |
4345 | .open = proc_statsdelta_open, | |
4346 | .release = proc_close | |
4347 | }; | |
4348 | ||
d54b1fdb | 4349 | static const struct file_operations proc_stats_ops = { |
a95609cb | 4350 | .owner = THIS_MODULE, |
1da177e4 LT |
4351 | .read = proc_read, |
4352 | .open = proc_stats_open, | |
4353 | .release = proc_close | |
4354 | }; | |
4355 | ||
d54b1fdb | 4356 | static const struct file_operations proc_status_ops = { |
a95609cb | 4357 | .owner = THIS_MODULE, |
1da177e4 LT |
4358 | .read = proc_read, |
4359 | .open = proc_status_open, | |
4360 | .release = proc_close | |
4361 | }; | |
4362 | ||
d54b1fdb | 4363 | static const struct file_operations proc_SSID_ops = { |
a95609cb | 4364 | .owner = THIS_MODULE, |
1da177e4 LT |
4365 | .read = proc_read, |
4366 | .write = proc_write, | |
4367 | .open = proc_SSID_open, | |
4368 | .release = proc_close | |
4369 | }; | |
4370 | ||
d54b1fdb | 4371 | static const struct file_operations proc_BSSList_ops = { |
a95609cb | 4372 | .owner = THIS_MODULE, |
1da177e4 LT |
4373 | .read = proc_read, |
4374 | .write = proc_write, | |
4375 | .open = proc_BSSList_open, | |
4376 | .release = proc_close | |
4377 | }; | |
4378 | ||
d54b1fdb | 4379 | static const struct file_operations proc_APList_ops = { |
a95609cb | 4380 | .owner = THIS_MODULE, |
1da177e4 LT |
4381 | .read = proc_read, |
4382 | .write = proc_write, | |
4383 | .open = proc_APList_open, | |
4384 | .release = proc_close | |
4385 | }; | |
4386 | ||
d54b1fdb | 4387 | static const struct file_operations proc_config_ops = { |
a95609cb | 4388 | .owner = THIS_MODULE, |
1da177e4 LT |
4389 | .read = proc_read, |
4390 | .write = proc_write, | |
4391 | .open = proc_config_open, | |
4392 | .release = proc_close | |
4393 | }; | |
4394 | ||
d54b1fdb | 4395 | static const struct file_operations proc_wepkey_ops = { |
a95609cb | 4396 | .owner = THIS_MODULE, |
1da177e4 LT |
4397 | .read = proc_read, |
4398 | .write = proc_write, | |
4399 | .open = proc_wepkey_open, | |
4400 | .release = proc_close | |
4401 | }; | |
4402 | ||
4403 | static struct proc_dir_entry *airo_entry; | |
4404 | ||
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 *); | |
4413 | }; | |
4414 | ||
1da177e4 LT |
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); | |
431aca5a FM |
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; | |
1da177e4 LT |
4428 | |
4429 | /* Setup the StatsDelta */ | |
a95609cb DL |
4430 | entry = proc_create_data("StatsDelta", |
4431 | S_IFREG | (S_IRUGO&proc_perm), | |
4432 | apriv->proc_entry, &proc_statsdelta_ops, dev); | |
431aca5a FM |
4433 | if (!entry) |
4434 | goto fail_stats_delta; | |
4435 | entry->uid = proc_uid; | |
4436 | entry->gid = proc_gid; | |
1da177e4 LT |
4437 | |
4438 | /* Setup the Stats */ | |
a95609cb DL |
4439 | entry = proc_create_data("Stats", |
4440 | S_IFREG | (S_IRUGO&proc_perm), | |
4441 | apriv->proc_entry, &proc_stats_ops, dev); | |
431aca5a FM |
4442 | if (!entry) |
4443 | goto fail_stats; | |
4444 | entry->uid = proc_uid; | |
4445 | entry->gid = proc_gid; | |
1da177e4 LT |
4446 | |
4447 | /* Setup the Status */ | |
a95609cb DL |
4448 | entry = proc_create_data("Status", |
4449 | S_IFREG | (S_IRUGO&proc_perm), | |
4450 | apriv->proc_entry, &proc_status_ops, dev); | |
431aca5a FM |
4451 | if (!entry) |
4452 | goto fail_status; | |
4453 | entry->uid = proc_uid; | |
4454 | entry->gid = proc_gid; | |
1da177e4 LT |
4455 | |
4456 | /* Setup the Config */ | |
a95609cb DL |
4457 | entry = proc_create_data("Config", |
4458 | S_IFREG | proc_perm, | |
4459 | apriv->proc_entry, &proc_config_ops, dev); | |
431aca5a FM |
4460 | if (!entry) |
4461 | goto fail_config; | |
4462 | entry->uid = proc_uid; | |
4463 | entry->gid = proc_gid; | |
1da177e4 LT |
4464 | |
4465 | /* Setup the SSID */ | |
a95609cb DL |
4466 | entry = proc_create_data("SSID", |
4467 | S_IFREG | proc_perm, | |
4468 | apriv->proc_entry, &proc_SSID_ops, dev); | |
431aca5a FM |
4469 | if (!entry) |
4470 | goto fail_ssid; | |
4471 | entry->uid = proc_uid; | |
4472 | entry->gid = proc_gid; | |
1da177e4 LT |
4473 | |
4474 | /* Setup the APList */ | |
a95609cb DL |
4475 | entry = proc_create_data("APList", |
4476 | S_IFREG | proc_perm, | |
4477 | apriv->proc_entry, &proc_APList_ops, dev); | |
431aca5a FM |
4478 | if (!entry) |
4479 | goto fail_aplist; | |
4480 | entry->uid = proc_uid; | |
4481 | entry->gid = proc_gid; | |
1da177e4 LT |
4482 | |
4483 | /* Setup the BSSList */ | |
a95609cb DL |
4484 | entry = proc_create_data("BSSList", |
4485 | S_IFREG | proc_perm, | |
4486 | apriv->proc_entry, &proc_BSSList_ops, dev); | |
431aca5a FM |
4487 | if (!entry) |
4488 | goto fail_bsslist; | |
1da177e4 LT |
4489 | entry->uid = proc_uid; |
4490 | entry->gid = proc_gid; | |
1da177e4 LT |
4491 | |
4492 | /* Setup the WepKey */ | |
a95609cb DL |
4493 | entry = proc_create_data("WepKey", |
4494 | S_IFREG | proc_perm, | |
4495 | apriv->proc_entry, &proc_wepkey_ops, dev); | |
431aca5a FM |
4496 | if (!entry) |
4497 | goto fail_wepkey; | |
4498 | entry->uid = proc_uid; | |
4499 | entry->gid = proc_gid; | |
1da177e4 LT |
4500 | |
4501 | return 0; | |
431aca5a FM |
4502 | |
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; | |
1da177e4 LT |
4521 | } |
4522 | ||
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; | |
4536 | } | |
4537 | ||
4538 | /* | |
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. | |
4544 | */ | |
4545 | ||
4546 | /* | |
4547 | * The read routine is generic, it relies on the preallocated rbuffer | |
4548 | * to supply the data. | |
4549 | */ | |
4550 | static ssize_t proc_read( struct file *file, | |
4551 | char __user *buffer, | |
4552 | size_t len, | |
4553 | loff_t *offset ) | |
4554 | { | |
cc0d9ff2 | 4555 | struct proc_data *priv = file->private_data; |
1da177e4 LT |
4556 | |
4557 | if (!priv->rbuffer) | |
4558 | return -EINVAL; | |
4559 | ||
cc0d9ff2 AM |
4560 | return simple_read_from_buffer(buffer, len, offset, priv->rbuffer, |
4561 | priv->readlen); | |
1da177e4 LT |
4562 | } |
4563 | ||
4564 | /* | |
4565 | * The write routine is generic, it fills in a preallocated rbuffer | |
4566 | * to supply the data. | |
4567 | */ | |
4568 | static ssize_t proc_write( struct file *file, | |
4569 | const char __user *buffer, | |
4570 | size_t len, | |
4571 | loff_t *offset ) | |
4572 | { | |
4573 | loff_t pos = *offset; | |
4574 | struct proc_data *priv = (struct proc_data*)file->private_data; | |
4575 | ||
4576 | if (!priv->wbuffer) | |
4577 | return -EINVAL; | |
4578 | ||
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; | |
4591 | } | |
4592 | ||
329e2c00 AV |
4593 | static int proc_status_open(struct inode *inode, struct file *file) |
4594 | { | |
1da177e4 LT |
4595 | struct proc_data *data; |
4596 | struct proc_dir_entry *dp = PDE(inode); | |
4597 | struct net_device *dev = dp->data; | |
faf3994a | 4598 | struct airo_info *apriv = dev->ml_priv; |
1da177e4 LT |
4599 | CapabilityRid cap_rid; |
4600 | StatusRid status_rid; | |
329e2c00 | 4601 | u16 mode; |
1da177e4 LT |
4602 | int i; |
4603 | ||
b69a3aa8 | 4604 | if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL) |
1da177e4 | 4605 | return -ENOMEM; |
1da177e4 LT |
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; | |
4610 | } | |
4611 | ||
4612 | readStatusRid(apriv, &status_rid, 1); | |
4613 | readCapabilityRid(apriv, &cap_rid, 1); | |
4614 | ||
329e2c00 AV |
4615 | mode = le16_to_cpu(status_rid.mode); |
4616 | ||
1da177e4 | 4617 | i = sprintf(data->rbuffer, "Status: %s%s%s%s%s%s%s%s%s\n", |
329e2c00 AV |
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 ": ""); | |
1da177e4 LT |
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", | |
329e2c00 AV |
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), | |
1da177e4 LT |
4643 | status_rid.SSID, |
4644 | status_rid.apName, | |
329e2c00 AV |
4645 | le16_to_cpu(status_rid.channel), |
4646 | le16_to_cpu(status_rid.currentXmitRate) / 2, | |
1da177e4 LT |
4647 | version, |
4648 | cap_rid.prodName, | |
4649 | cap_rid.manName, | |
4650 | cap_rid.prodVer, | |
56d81bd3 AV |
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)); | |
1da177e4 LT |
4657 | data->readlen = strlen( data->rbuffer ); |
4658 | return 0; | |
4659 | } | |
4660 | ||
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); | |
4666 | } | |
4667 | return proc_stats_rid_open(inode, file, RID_STATSDELTA); | |
4668 | } | |
4669 | ||
4670 | static int proc_stats_open( struct inode *inode, struct file *file ) { | |
4671 | return proc_stats_rid_open(inode, file, RID_STATS); | |
4672 | } | |
4673 | ||
4674 | static int proc_stats_rid_open( struct inode *inode, | |
4675 | struct file *file, | |
a23ace5f AV |
4676 | u16 rid ) |
4677 | { | |
1da177e4 LT |
4678 | struct proc_data *data; |
4679 | struct proc_dir_entry *dp = PDE(inode); | |
4680 | struct net_device *dev = dp->data; | |
faf3994a | 4681 | struct airo_info *apriv = dev->ml_priv; |
1da177e4 LT |
4682 | StatsRid stats; |
4683 | int i, j; | |
a23ace5f AV |
4684 | __le32 *vals = stats.vals; |
4685 | int len = le16_to_cpu(stats.len); | |
1da177e4 | 4686 | |
b69a3aa8 | 4687 | if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL) |
1da177e4 | 4688 | return -ENOMEM; |
1da177e4 LT |
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; | |
4693 | } | |
4694 | ||
4695 | readStatsRid(apriv, &stats, rid, 1); | |
4696 | ||
4697 | j = 0; | |
a23ace5f | 4698 | for(i=0; statsLabels[i]!=(char *)-1 && i*4<len; i++) { |
1da177e4 LT |
4699 | if (!statsLabels[i]) continue; |
4700 | if (j+strlen(statsLabels[i])+16>4096) { | |
934d8bf1 DW |
4701 | airo_print_warn(apriv->dev->name, |
4702 | "Potentially disasterous buffer overflow averted!"); | |
1da177e4 LT |
4703 | break; |
4704 | } | |
a23ace5f AV |
4705 | j+=sprintf(data->rbuffer+j, "%s: %u\n", statsLabels[i], |
4706 | le32_to_cpu(vals[i])); | |
1da177e4 | 4707 | } |
a23ace5f | 4708 | if (i*4 >= len) { |
934d8bf1 | 4709 | airo_print_warn(apriv->dev->name, "Got a short rid"); |
1da177e4 LT |
4710 | } |
4711 | data->readlen = j; | |
4712 | return 0; | |
4713 | } | |
4714 | ||
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'; | |
4724 | } | |
4725 | if ( !valid ) return -1; | |
4726 | return value; | |
4727 | } | |
4728 | ||
4729 | static int airo_config_commit(struct net_device *dev, | |
4730 | struct iw_request_info *info, void *zwrq, | |
4731 | char *extra); | |
4732 | ||
3eb9b41f AV |
4733 | static inline int sniffing_mode(struct airo_info *ai) |
4734 | { | |
4735 | return le16_to_cpu(ai->config.rmode & RXMODE_MASK) >= | |
4736 | le16_to_cpu(RXMODE_RFMON); | |
4737 | } | |
4738 | ||
4739 | static void proc_config_on_close(struct inode *inode, struct file *file) | |
4740 | { | |
1da177e4 LT |
4741 | struct proc_data *data = file->private_data; |
4742 | struct proc_dir_entry *dp = PDE(inode); | |
4743 | struct net_device *dev = dp->data; | |
faf3994a | 4744 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
4745 | char *line; |
4746 | ||
4747 | if ( !data->writelen ) return; | |
4748 | ||
4749 | readConfigRid(ai, 1); | |
4750 | set_bit (FLAG_COMMIT, &ai->flags); | |
4751 | ||
4752 | line = data->wbuffer; | |
4753 | while( line[0] ) { | |
4754 | /*** Mode processing */ | |
4755 | if ( !strncmp( line, "Mode: ", 6 ) ) { | |
4756 | line += 6; | |
3eb9b41f AV |
4757 | if (sniffing_mode(ai)) |
4758 | set_bit (FLAG_RESET, &ai->flags); | |
4759 | ai->config.rmode &= ~RXMODE_FULL_MASK; | |
1da177e4 | 4760 | clear_bit (FLAG_802_11, &ai->flags); |
3eb9b41f | 4761 | ai->config.opmode &= ~MODE_CFG_MASK; |
1da177e4 LT |
4762 | ai->config.scanMode = SCANMODE_ACTIVE; |
4763 | if ( line[0] == 'a' ) { | |
3eb9b41f | 4764 | ai->config.opmode |= MODE_STA_IBSS; |
1da177e4 | 4765 | } else { |
3eb9b41f | 4766 | ai->config.opmode |= MODE_STA_ESS; |
1da177e4 LT |
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; | |
4777 | } | |
4778 | set_bit (FLAG_COMMIT, &ai->flags); | |
4779 | } | |
4780 | ||
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); | |
4788 | } | |
4789 | } | |
4790 | /*** NodeName processing */ | |
4791 | else if ( !strncmp( line, "NodeName: ", 10 ) ) { | |
4792 | int j; | |
4793 | ||
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]; | |
4799 | } | |
4800 | set_bit (FLAG_COMMIT, &ai->flags); | |
4801 | } | |
4802 | ||
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); | |
4815 | } | |
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 */ | |
4819 | ||
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; | |
4825 | } | |
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 ) { | |
3eb9b41f | 4832 | ai->config.channelSet = cpu_to_le16(v); |
1da177e4 LT |
4833 | set_bit (FLAG_COMMIT, &ai->flags); |
4834 | } | |
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 ) { | |
3eb9b41f | 4840 | ai->config.txPower = cpu_to_le16(v); |
1da177e4 LT |
4841 | set_bit (FLAG_COMMIT, &ai->flags); |
4842 | } | |
4843 | } else if ( !strncmp( line, "WEP: ", 5 ) ) { | |
4844 | line += 5; | |
4845 | switch( line[0] ) { | |
4846 | case 's': | |
3eb9b41f | 4847 | ai->config.authType = AUTH_SHAREDKEY; |
1da177e4 LT |
4848 | break; |
4849 | case 'e': | |
3eb9b41f | 4850 | ai->config.authType = AUTH_ENCRYPT; |
1da177e4 LT |
4851 | break; |
4852 | default: | |
3eb9b41f | 4853 | ai->config.authType = AUTH_OPEN; |
1da177e4 LT |
4854 | break; |
4855 | } | |
4856 | set_bit (FLAG_COMMIT, &ai->flags); | |
4857 | } else if ( !strncmp( line, "LongRetryLimit: ", 16 ) ) { | |
4858 | int v, i = 0; | |
4859 | ||
4860 | line += 16; | |
4861 | v = get_dec_u16(line, &i, 3); | |
4862 | v = (v<0) ? 0 : ((v>255) ? 255 : v); | |
3eb9b41f | 4863 | ai->config.longRetryLimit = cpu_to_le16(v); |
1da177e4 LT |
4864 | set_bit (FLAG_COMMIT, &ai->flags); |
4865 | } else if ( !strncmp( line, "ShortRetryLimit: ", 17 ) ) { | |
4866 | int v, i = 0; | |
4867 | ||
4868 | line += 17; | |
4869 | v = get_dec_u16(line, &i, 3); | |
4870 | v = (v<0) ? 0 : ((v>255) ? 255 : v); | |
3eb9b41f | 4871 | ai->config.shortRetryLimit = cpu_to_le16(v); |
1da177e4 LT |
4872 | set_bit (FLAG_COMMIT, &ai->flags); |
4873 | } else if ( !strncmp( line, "RTSThreshold: ", 14 ) ) { | |
4874 | int v, i = 0; | |
4875 | ||
4876 | line += 14; | |
4877 | v = get_dec_u16(line, &i, 4); | |
15db2763 | 4878 | v = (v<0) ? 0 : ((v>AIRO_DEF_MTU) ? AIRO_DEF_MTU : v); |
3eb9b41f | 4879 | ai->config.rtsThres = cpu_to_le16(v); |
1da177e4 LT |
4880 | set_bit (FLAG_COMMIT, &ai->flags); |
4881 | } else if ( !strncmp( line, "TXMSDULifetime: ", 16 ) ) { | |
4882 | int v, i = 0; | |
4883 | ||
4884 | line += 16; | |
4885 | v = get_dec_u16(line, &i, 5); | |
4886 | v = (v<0) ? 0 : v; | |
3eb9b41f | 4887 | ai->config.txLifetime = cpu_to_le16(v); |
1da177e4 LT |
4888 | set_bit (FLAG_COMMIT, &ai->flags); |
4889 | } else if ( !strncmp( line, "RXMSDULifetime: ", 16 ) ) { | |
4890 | int v, i = 0; | |
4891 | ||
4892 | line += 16; | |
4893 | v = get_dec_u16(line, &i, 5); | |
4894 | v = (v<0) ? 0 : v; | |
3eb9b41f | 4895 | ai->config.rxLifetime = cpu_to_le16(v); |
1da177e4 LT |
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; | |
4909 | ||
4910 | line += 15; | |
4911 | v = get_dec_u16(line, &i, 4); | |
15db2763 | 4912 | v = (v<256) ? 256 : ((v>AIRO_DEF_MTU) ? AIRO_DEF_MTU : v); |
1da177e4 | 4913 | v = v & 0xfffe; /* Make sure its even */ |
3eb9b41f | 4914 | ai->config.fragThresh = cpu_to_le16(v); |
1da177e4 LT |
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; | |
934d8bf1 | 4922 | default: airo_print_warn(ai->dev->name, "Unknown modulation"); |
1da177e4 LT |
4923 | } |
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; | |
934d8bf1 | 4930 | default: airo_print_warn(ai->dev->name, "Unknown preamble"); |
1da177e4 LT |
4931 | } |
4932 | } else { | |
934d8bf1 | 4933 | airo_print_warn(ai->dev->name, "Couldn't figure out %s", line); |
1da177e4 LT |
4934 | } |
4935 | while( line[0] && line[0] != '\n' ) line++; | |
4936 | if ( line[0] ) line++; | |
4937 | } | |
4938 | airo_config_commit(dev, NULL, NULL, NULL); | |
4939 | } | |
4940 | ||
3eb9b41f AV |
4941 | static char *get_rmode(__le16 mode) |
4942 | { | |
4943 | switch(mode & RXMODE_MASK) { | |
1da177e4 LT |
4944 | case RXMODE_RFMON: return "rfmon"; |
4945 | case RXMODE_RFMON_ANYBSS: return "yna (any) bss rfmon"; | |
4946 | case RXMODE_LANMON: return "lanmon"; | |
4947 | } | |
4948 | return "ESS"; | |
4949 | } | |
4950 | ||
3eb9b41f AV |
4951 | static int proc_config_open(struct inode *inode, struct file *file) |
4952 | { | |
1da177e4 LT |
4953 | struct proc_data *data; |
4954 | struct proc_dir_entry *dp = PDE(inode); | |
4955 | struct net_device *dev = dp->data; | |
faf3994a | 4956 | struct airo_info *ai = dev->ml_priv; |
1da177e4 | 4957 | int i; |
3eb9b41f | 4958 | __le16 mode; |
1da177e4 | 4959 | |
b69a3aa8 | 4960 | if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL) |
1da177e4 | 4961 | return -ENOMEM; |
1da177e4 LT |
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; | |
4966 | } | |
b69a3aa8 | 4967 | if ((data->wbuffer = kzalloc( 2048, GFP_KERNEL )) == NULL) { |
1da177e4 LT |
4968 | kfree (data->rbuffer); |
4969 | kfree (file->private_data); | |
4970 | return -ENOMEM; | |
4971 | } | |
1da177e4 LT |
4972 | data->maxwritelen = 2048; |
4973 | data->on_close = proc_config_on_close; | |
4974 | ||
4975 | readConfigRid(ai, 1); | |
4976 | ||
3eb9b41f | 4977 | mode = ai->config.opmode & MODE_CFG_MASK; |
1da177e4 LT |
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", | |
3eb9b41f AV |
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", | |
1da177e4 LT |
4990 | test_bit(FLAG_RADIO_OFF, &ai->flags) ? "off" : "on", |
4991 | ai->config.nodeName, | |
3eb9b41f AV |
4992 | ai->config.powerSaveMode == POWERSAVE_CAM ? "CAM" : |
4993 | ai->config.powerSaveMode == POWERSAVE_PSP ? "PSP" : | |
4994 | ai->config.powerSaveMode == POWERSAVE_PSPCAM ? "PSPCAM" : | |
4995 | "Error", | |
1da177e4 LT |
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], | |
3eb9b41f AV |
5004 | le16_to_cpu(ai->config.channelSet), |
5005 | le16_to_cpu(ai->config.txPower) | |
1da177e4 LT |
5006 | ); |
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", | |
3eb9b41f AV |
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), | |
1da177e4 LT |
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", | |
3eb9b41f | 5028 | le16_to_cpu(ai->config.fragThresh), |
1da177e4 LT |
5029 | ai->config.authType == AUTH_ENCRYPT ? "encrypt" : |
5030 | ai->config.authType == AUTH_SHAREDKEY ? "shared" : "open", | |
3eb9b41f | 5031 | ai->config.modulation == MOD_DEFAULT ? "default" : |
1da177e4 LT |
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" | |
5037 | ); | |
5038 | data->readlen = strlen( data->rbuffer ); | |
5039 | return 0; | |
5040 | } | |
5041 | ||
0dd2212f AV |
5042 | static void proc_SSID_on_close(struct inode *inode, struct file *file) |
5043 | { | |
1da177e4 LT |
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; | |
faf3994a | 5047 | struct airo_info *ai = dev->ml_priv; |
1da177e4 | 5048 | SsidRid SSID_rid; |
1da177e4 | 5049 | int i; |
0dd2212f AV |
5050 | char *p = data->wbuffer; |
5051 | char *end = p + data->writelen; | |
1da177e4 | 5052 | |
0dd2212f AV |
5053 | if (!data->writelen) |
5054 | return; | |
1da177e4 | 5055 | |
0dd2212f | 5056 | *end = '\n'; /* sentinel; we have space for it */ |
1da177e4 | 5057 | |
0dd2212f AV |
5058 | memset(&SSID_rid, 0, sizeof(SSID_rid)); |
5059 | ||
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') | |
5070 | ; | |
1da177e4 LT |
5071 | } |
5072 | if (i) | |
0dd2212f | 5073 | SSID_rid.len = cpu_to_le16(sizeof(SSID_rid)); |
1da177e4 LT |
5074 | disable_MAC(ai, 1); |
5075 | writeSsidRid(ai, &SSID_rid, 1); | |
175ec1a1 | 5076 | enable_MAC(ai, 1); |
1da177e4 LT |
5077 | } |
5078 | ||
77933d72 | 5079 | static inline u8 hexVal(char c) { |
1da177e4 LT |
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; | |
5084 | } | |
5085 | ||
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; | |
faf3994a | 5090 | struct airo_info *ai = dev->ml_priv; |
1da177e4 | 5091 | APListRid APList_rid; |
1da177e4 LT |
5092 | int i; |
5093 | ||
5094 | if ( !data->writelen ) return; | |
5095 | ||
5096 | memset( &APList_rid, 0, sizeof(APList_rid) ); | |
a749716e | 5097 | APList_rid.len = cpu_to_le16(sizeof(APList_rid)); |
1da177e4 LT |
5098 | |
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; | |
5111 | } | |
5112 | } | |
5113 | } | |
5114 | disable_MAC(ai, 1); | |
5115 | writeAPListRid(ai, &APList_rid, 1); | |
175ec1a1 | 5116 | enable_MAC(ai, 1); |
1da177e4 LT |
5117 | } |
5118 | ||
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; | |
1da177e4 LT |
5123 | |
5124 | disable_MAC(ai, 1); | |
5125 | rc = PC4500_writerid(ai, rid, rid_data, len, 1); | |
175ec1a1 | 5126 | enable_MAC(ai, 1); |
1da177e4 LT |
5127 | return rc; |
5128 | } | |
5129 | ||
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. | |
5133 | */ | |
5134 | static int get_wep_key(struct airo_info *ai, u16 index) { | |
5135 | WepKeyRid wkr; | |
5136 | int rc; | |
4293ea33 | 5137 | __le16 lastindex; |
1da177e4 LT |
5138 | |
5139 | rc = readWepKeyRid(ai, &wkr, 1, 1); | |
5140 | if (rc == SUCCESS) do { | |
5141 | lastindex = wkr.kindex; | |
4293ea33 | 5142 | if (wkr.kindex == cpu_to_le16(index)) { |
1da177e4 LT |
5143 | if (index == 0xffff) { |
5144 | return wkr.mac[0]; | |
5145 | } | |
4293ea33 | 5146 | return le16_to_cpu(wkr.klen); |
1da177e4 LT |
5147 | } |
5148 | readWepKeyRid(ai, &wkr, 0, 1); | |
4293ea33 | 5149 | } while (lastindex != wkr.kindex); |
1da177e4 LT |
5150 | return -1; |
5151 | } | |
5152 | ||
5153 | static int set_wep_key(struct airo_info *ai, u16 index, | |
4293ea33 AV |
5154 | const char *key, u16 keylen, int perm, int lock ) |
5155 | { | |
1da177e4 LT |
5156 | static const unsigned char macaddr[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 }; |
5157 | WepKeyRid wkr; | |
1da177e4 LT |
5158 | |
5159 | memset(&wkr, 0, sizeof(wkr)); | |
5160 | if (keylen == 0) { | |
5161 | // We are selecting which key to use | |
4293ea33 AV |
5162 | wkr.len = cpu_to_le16(sizeof(wkr)); |
5163 | wkr.kindex = cpu_to_le16(0xffff); | |
1da177e4 | 5164 | wkr.mac[0] = (char)index; |
1da177e4 LT |
5165 | if (perm) ai->defindex = (char)index; |
5166 | } else { | |
5167 | // We are actually setting the key | |
4293ea33 AV |
5168 | wkr.len = cpu_to_le16(sizeof(wkr)); |
5169 | wkr.kindex = cpu_to_le16(index); | |
5170 | wkr.klen = cpu_to_le16(keylen); | |
1da177e4 LT |
5171 | memcpy( wkr.key, key, keylen ); |
5172 | memcpy( wkr.mac, macaddr, ETH_ALEN ); | |
1da177e4 LT |
5173 | } |
5174 | ||
f89b2321 | 5175 | if (perm) disable_MAC(ai, lock); |
1da177e4 | 5176 | writeWepKeyRid(ai, &wkr, perm, lock); |
175ec1a1 | 5177 | if (perm) enable_MAC(ai, lock); |
1da177e4 LT |
5178 | return 0; |
5179 | } | |
5180 | ||
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; | |
faf3994a | 5185 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
5186 | int i; |
5187 | char key[16]; | |
5188 | u16 index = 0; | |
5189 | int j = 0; | |
5190 | ||
5191 | memset(key, 0, sizeof(key)); | |
5192 | ||
5193 | data = (struct proc_data *)file->private_data; | |
5194 | if ( !data->writelen ) return; | |
5195 | ||
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; | |
5202 | } | |
5203 | j = 2; | |
5204 | } else { | |
934d8bf1 | 5205 | airo_print_err(ai->dev->name, "WepKey passed invalid key index"); |
1da177e4 LT |
5206 | return; |
5207 | } | |
5208 | ||
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; | |
5217 | } | |
5218 | } | |
5219 | set_wep_key(ai, index, key, i/3, 1, 1); | |
5220 | } | |
5221 | ||
4293ea33 AV |
5222 | static int proc_wepkey_open( struct inode *inode, struct file *file ) |
5223 | { | |
1da177e4 LT |
5224 | struct proc_data *data; |
5225 | struct proc_dir_entry *dp = PDE(inode); | |
5226 | struct net_device *dev = dp->data; | |
faf3994a | 5227 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
5228 | char *ptr; |
5229 | WepKeyRid wkr; | |
4293ea33 | 5230 | __le16 lastindex; |
1da177e4 LT |
5231 | int j=0; |
5232 | int rc; | |
5233 | ||
b69a3aa8 | 5234 | if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL) |
1da177e4 | 5235 | return -ENOMEM; |
1da177e4 LT |
5236 | memset(&wkr, 0, sizeof(wkr)); |
5237 | data = (struct proc_data *)file->private_data; | |
b69a3aa8 | 5238 | if ((data->rbuffer = kzalloc( 180, GFP_KERNEL )) == NULL) { |
1da177e4 LT |
5239 | kfree (file->private_data); |
5240 | return -ENOMEM; | |
5241 | } | |
1da177e4 LT |
5242 | data->writelen = 0; |
5243 | data->maxwritelen = 80; | |
b69a3aa8 | 5244 | if ((data->wbuffer = kzalloc( 80, GFP_KERNEL )) == NULL) { |
1da177e4 LT |
5245 | kfree (data->rbuffer); |
5246 | kfree (file->private_data); | |
5247 | return -ENOMEM; | |
5248 | } | |
1da177e4 LT |
5249 | data->on_close = proc_wepkey_on_close; |
5250 | ||
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; | |
4293ea33 | 5256 | if (wkr.kindex == cpu_to_le16(0xffff)) { |
1da177e4 LT |
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", | |
4293ea33 AV |
5261 | le16_to_cpu(wkr.kindex), |
5262 | le16_to_cpu(wkr.klen)); | |
1da177e4 LT |
5263 | } |
5264 | readWepKeyRid(ai, &wkr, 0, 1); | |
5265 | } while((lastindex != wkr.kindex) && (j < 180-30)); | |
5266 | ||
5267 | data->readlen = strlen( data->rbuffer ); | |
5268 | return 0; | |
5269 | } | |
5270 | ||
0dd2212f AV |
5271 | static int proc_SSID_open(struct inode *inode, struct file *file) |
5272 | { | |
1da177e4 LT |
5273 | struct proc_data *data; |
5274 | struct proc_dir_entry *dp = PDE(inode); | |
5275 | struct net_device *dev = dp->data; | |
faf3994a | 5276 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
5277 | int i; |
5278 | char *ptr; | |
5279 | SsidRid SSID_rid; | |
5280 | ||
b69a3aa8 | 5281 | if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL) |
1da177e4 | 5282 | return -ENOMEM; |
1da177e4 LT |
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; | |
5287 | } | |
5288 | data->writelen = 0; | |
5289 | data->maxwritelen = 33*3; | |
0dd2212f AV |
5290 | /* allocate maxwritelen + 1; we'll want a sentinel */ |
5291 | if ((data->wbuffer = kzalloc(33*3 + 1, GFP_KERNEL)) == NULL) { | |
1da177e4 LT |
5292 | kfree (data->rbuffer); |
5293 | kfree (file->private_data); | |
5294 | return -ENOMEM; | |
5295 | } | |
1da177e4 LT |
5296 | data->on_close = proc_SSID_on_close; |
5297 | ||
5298 | readSsidRid(ai, &SSID_rid); | |
5299 | ptr = data->rbuffer; | |
0dd2212f | 5300 | for (i = 0; i < 3; i++) { |
1da177e4 | 5301 | int j; |
0dd2212f AV |
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++) | |
1da177e4 | 5308 | *ptr++ = SSID_rid.ssids[i].ssid[j]; |
1da177e4 LT |
5309 | *ptr++ = '\n'; |
5310 | } | |
5311 | *ptr = '\0'; | |
5312 | data->readlen = strlen( data->rbuffer ); | |
5313 | return 0; | |
5314 | } | |
5315 | ||
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; | |
faf3994a | 5320 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
5321 | int i; |
5322 | char *ptr; | |
5323 | APListRid APList_rid; | |
5324 | ||
b69a3aa8 | 5325 | if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL) |
1da177e4 | 5326 | return -ENOMEM; |
1da177e4 LT |
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; | |
5331 | } | |
5332 | data->writelen = 0; | |
5333 | data->maxwritelen = 4*6*3; | |
b69a3aa8 | 5334 | if ((data->wbuffer = kzalloc( data->maxwritelen, GFP_KERNEL )) == NULL) { |
1da177e4 LT |
5335 | kfree (data->rbuffer); |
5336 | kfree (file->private_data); | |
5337 | return -ENOMEM; | |
5338 | } | |
1da177e4 LT |
5339 | data->on_close = proc_APList_on_close; |
5340 | ||
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; | |
e174961c | 5347 | ptr += sprintf(ptr, "%pM\n", APList_rid.ap[i]); |
1da177e4 LT |
5348 | } |
5349 | if (i==0) ptr += sprintf(ptr, "Not using specific APs\n"); | |
5350 | ||
5351 | *ptr = '\0'; | |
5352 | data->readlen = strlen( data->rbuffer ); | |
5353 | return 0; | |
5354 | } | |
5355 | ||
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; | |
faf3994a | 5360 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
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; | |
5366 | ||
b69a3aa8 | 5367 | if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL) |
1da177e4 | 5368 | return -ENOMEM; |
1da177e4 LT |
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; | |
5373 | } | |
5374 | data->writelen = 0; | |
5375 | data->maxwritelen = 0; | |
5376 | data->wbuffer = NULL; | |
5377 | data->on_close = NULL; | |
5378 | ||
5379 | if (file->f_mode & FMODE_WRITE) { | |
5380 | if (!(file->f_mode & FMODE_READ)) { | |
5381 | Cmd cmd; | |
5382 | Resp rsp; | |
5383 | ||
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; | |
5393 | } | |
5394 | doLoseSync = 1; | |
5395 | } | |
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); | |
17e70491 | 5401 | while(rc == 0 && BSSList_rid.index != cpu_to_le16(0xffff)) { |
e174961c JB |
5402 | ptr += sprintf(ptr, "%pM %*s rssi = %d", |
5403 | BSSList_rid.bssid, | |
1da177e4 LT |
5404 | (int)BSSList_rid.ssidLen, |
5405 | BSSList_rid.ssid, | |
17e70491 | 5406 | le16_to_cpu(BSSList_rid.dBm)); |
1da177e4 | 5407 | ptr += sprintf(ptr, " channel = %d %s %s %s %s\n", |
17e70491 | 5408 | le16_to_cpu(BSSList_rid.dsChannel), |
1da177e4 LT |
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); | |
5414 | } | |
5415 | *ptr = '\0'; | |
5416 | data->readlen = strlen( data->rbuffer ); | |
5417 | return 0; | |
5418 | } | |
5419 | ||
5420 | static int proc_close( struct inode *inode, struct file *file ) | |
5421 | { | |
b4558ea9 JJ |
5422 | struct proc_data *data = file->private_data; |
5423 | ||
5424 | if (data->on_close != NULL) | |
5425 | data->on_close(inode, file); | |
5426 | kfree(data->rbuffer); | |
5427 | kfree(data->wbuffer); | |
5428 | kfree(data); | |
1da177e4 LT |
5429 | return 0; |
5430 | } | |
5431 | ||
1da177e4 LT |
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 ) { | |
faf3994a | 5438 | struct airo_info *apriv = dev->ml_priv; |
1da177e4 LT |
5439 | |
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; | |
5458 | } | |
5459 | break; | |
5460 | default: /* We'll escalate to SHAREDKEY */ | |
5461 | apriv->config.authType = AUTH_SHAREDKEY; | |
5462 | } | |
5463 | set_bit (FLAG_COMMIT, &apriv->flags); | |
5464 | writeConfigRid(apriv, 0); | |
175ec1a1 | 5465 | enable_MAC(apriv, 0); |
1da177e4 LT |
5466 | up(&apriv->sem); |
5467 | ||
5468 | /* Schedule check to see if the change worked */ | |
3c304956 | 5469 | clear_bit(JOB_AUTOWEP, &apriv->jobs); |
1da177e4 LT |
5470 | apriv->expires = RUN_AT(HZ*3); |
5471 | } | |
5472 | ||
1da177e4 LT |
5473 | #ifdef CONFIG_PCI |
5474 | static int __devinit airo_pci_probe(struct pci_dev *pdev, | |
5475 | const struct pci_device_id *pent) | |
5476 | { | |
5477 | struct net_device *dev; | |
5478 | ||
5479 | if (pci_enable_device(pdev)) | |
5480 | return -ENODEV; | |
5481 | pci_set_master(pdev); | |
5482 | ||
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); | |
777ec5e9 MS |
5487 | if (!dev) { |
5488 | pci_disable_device(pdev); | |
1da177e4 | 5489 | return -ENODEV; |
777ec5e9 | 5490 | } |
1da177e4 LT |
5491 | |
5492 | pci_set_drvdata(pdev, dev); | |
5493 | return 0; | |
5494 | } | |
5495 | ||
5496 | static void __devexit airo_pci_remove(struct pci_dev *pdev) | |
5497 | { | |
af5b5c9a MS |
5498 | struct net_device *dev = pci_get_drvdata(pdev); |
5499 | ||
5500 | airo_print_info(dev->name, "Unregistering..."); | |
5501 | stop_airo_card(dev, 1); | |
777ec5e9 MS |
5502 | pci_disable_device(pdev); |
5503 | pci_set_drvdata(pdev, NULL); | |
1da177e4 LT |
5504 | } |
5505 | ||
05adc3b7 | 5506 | static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
1da177e4 LT |
5507 | { |
5508 | struct net_device *dev = pci_get_drvdata(pdev); | |
faf3994a | 5509 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
5510 | Cmd cmd; |
5511 | Resp rsp; | |
5512 | ||
e292c737 PM |
5513 | if (!ai->APList) |
5514 | ai->APList = kmalloc(sizeof(APListRid), GFP_KERNEL); | |
5515 | if (!ai->APList) | |
1da177e4 | 5516 | return -ENOMEM; |
e292c737 PM |
5517 | if (!ai->SSID) |
5518 | ai->SSID = kmalloc(sizeof(SsidRid), GFP_KERNEL); | |
5519 | if (!ai->SSID) | |
1da177e4 LT |
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; | |
e292c737 | 5530 | cmd.cmd = HOSTSLEEP; |
1da177e4 LT |
5531 | issuecommand(ai, &cmd, &rsp); |
5532 | ||
1cc68ae0 | 5533 | pci_enable_wake(pdev, pci_choose_state(pdev, state), 1); |
1da177e4 | 5534 | pci_save_state(pdev); |
1cc68ae0 | 5535 | return pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
1da177e4 LT |
5536 | } |
5537 | ||
5538 | static int airo_pci_resume(struct pci_dev *pdev) | |
5539 | { | |
5540 | struct net_device *dev = pci_get_drvdata(pdev); | |
faf3994a | 5541 | struct airo_info *ai = dev->ml_priv; |
53232803 | 5542 | pci_power_t prev_state = pdev->current_state; |
1da177e4 | 5543 | |
53232803 | 5544 | pci_set_power_state(pdev, PCI_D0); |
1da177e4 | 5545 | pci_restore_state(pdev); |
53232803 | 5546 | pci_enable_wake(pdev, PCI_D0, 0); |
1da177e4 | 5547 | |
53232803 | 5548 | if (prev_state != PCI_D1) { |
1da177e4 LT |
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); | |
5558 | } | |
5559 | ||
e292c737 | 5560 | set_bit(FLAG_COMMIT, &ai->flags); |
1da177e4 LT |
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; | |
5567 | } | |
5568 | if (ai->APList) { | |
5569 | writeAPListRid(ai, ai->APList, 0); | |
5570 | kfree(ai->APList); | |
5571 | ai->APList = NULL; | |
5572 | } | |
5573 | writeConfigRid(ai, 0); | |
175ec1a1 | 5574 | enable_MAC(ai, 0); |
1cc68ae0 | 5575 | ai->power = PMSG_ON; |
1da177e4 LT |
5576 | netif_device_attach(dev); |
5577 | netif_wake_queue(dev); | |
5578 | enable_interrupts(ai); | |
5579 | up(&ai->sem); | |
5580 | return 0; | |
5581 | } | |
5582 | #endif | |
5583 | ||
5584 | static int __init airo_init_module( void ) | |
5585 | { | |
de897881 | 5586 | int i; |
1da177e4 | 5587 | |
928b4d8c | 5588 | airo_entry = create_proc_entry("driver/aironet", |
1da177e4 | 5589 | S_IFDIR | airo_perm, |
928b4d8c | 5590 | NULL); |
de897881 JG |
5591 | |
5592 | if (airo_entry) { | |
5593 | airo_entry->uid = proc_uid; | |
5594 | airo_entry->gid = proc_gid; | |
5595 | } | |
1da177e4 | 5596 | |
e292c737 | 5597 | for (i = 0; i < 4 && io[i] && irq[i]; i++) { |
934d8bf1 DW |
5598 | airo_print_info("", "Trying to configure ISA adapter at irq=%d " |
5599 | "io=0x%x", irq[i], io[i] ); | |
1da177e4 | 5600 | if (init_airo_card( irq[i], io[i], 0, NULL )) |
de897881 | 5601 | /* do nothing */ ; |
1da177e4 LT |
5602 | } |
5603 | ||
5604 | #ifdef CONFIG_PCI | |
934d8bf1 | 5605 | airo_print_info("", "Probing for PCI adapters"); |
de897881 | 5606 | i = pci_register_driver(&airo_driver); |
934d8bf1 | 5607 | airo_print_info("", "Finished probing for PCI adapters"); |
de897881 JG |
5608 | |
5609 | if (i) { | |
928b4d8c | 5610 | remove_proc_entry("driver/aironet", NULL); |
de897881 JG |
5611 | return i; |
5612 | } | |
1da177e4 LT |
5613 | #endif |
5614 | ||
5615 | /* Always exit with success, as we are a library module | |
5616 | * as well as a driver module | |
5617 | */ | |
5618 | return 0; | |
5619 | } | |
5620 | ||
5621 | static void __exit airo_cleanup_module( void ) | |
5622 | { | |
af5b5c9a MS |
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); | |
1da177e4 LT |
5628 | } |
5629 | #ifdef CONFIG_PCI | |
5630 | pci_unregister_driver(&airo_driver); | |
5631 | #endif | |
928b4d8c | 5632 | remove_proc_entry("driver/aironet", NULL); |
1da177e4 LT |
5633 | } |
5634 | ||
1da177e4 LT |
5635 | /* |
5636 | * Initial Wireless Extension code for Aironet driver by : | |
5637 | * Jean Tourrilhes <[email protected]> - HPL - 17 November 00 | |
5638 | * Conversion to new driver API by : | |
5639 | * Jean Tourrilhes <[email protected]> - 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 | |
5643 | */ | |
5644 | ||
41480af2 DW |
5645 | static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi) |
5646 | { | |
e292c737 | 5647 | if (!rssi_rid) |
41480af2 DW |
5648 | return 0; |
5649 | ||
5650 | return (0x100 - rssi_rid[rssi].rssidBm); | |
5651 | } | |
5652 | ||
5653 | static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm) | |
5654 | { | |
5655 | int i; | |
5656 | ||
e292c737 | 5657 | if (!rssi_rid) |
41480af2 DW |
5658 | return 0; |
5659 | ||
e292c737 | 5660 | for (i = 0; i < 256; i++) |
41480af2 DW |
5661 | if (rssi_rid[i].rssidBm == dbm) |
5662 | return rssi_rid[i].rssipct; | |
5663 | ||
5664 | return 0; | |
5665 | } | |
5666 | ||
5667 | ||
1da177e4 LT |
5668 | static int airo_get_quality (StatusRid *status_rid, CapabilityRid *cap_rid) |
5669 | { | |
5670 | int quality = 0; | |
329e2c00 | 5671 | u16 sq; |
1da177e4 | 5672 | |
329e2c00 | 5673 | if ((status_rid->mode & cpu_to_le16(0x3f)) != cpu_to_le16(0x3f)) |
56d81bd3 AV |
5674 | return 0; |
5675 | ||
5676 | if (!(cap_rid->hardCap & cpu_to_le16(8))) | |
5677 | return 0; | |
5678 | ||
329e2c00 | 5679 | sq = le16_to_cpu(status_rid->signalQuality); |
56d81bd3 | 5680 | if (memcmp(cap_rid->prodName, "350", 3)) |
329e2c00 | 5681 | if (sq > 0x20) |
56d81bd3 | 5682 | quality = 0; |
1da177e4 | 5683 | else |
329e2c00 | 5684 | quality = 0x20 - sq; |
56d81bd3 | 5685 | else |
329e2c00 | 5686 | if (sq > 0xb0) |
56d81bd3 | 5687 | quality = 0; |
329e2c00 | 5688 | else if (sq < 0x10) |
56d81bd3 AV |
5689 | quality = 0xa0; |
5690 | else | |
329e2c00 | 5691 | quality = 0xb0 - sq; |
1da177e4 LT |
5692 | return quality; |
5693 | } | |
5694 | ||
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); | |
5697 | ||
5698 | /*------------------------------------------------------------------*/ | |
5699 | /* | |
5700 | * Wireless Handler : get protocol name | |
5701 | */ | |
5702 | static int airo_get_name(struct net_device *dev, | |
5703 | struct iw_request_info *info, | |
5704 | char *cwrq, | |
5705 | char *extra) | |
5706 | { | |
5707 | strcpy(cwrq, "IEEE 802.11-DS"); | |
5708 | return 0; | |
5709 | } | |
5710 | ||
5711 | /*------------------------------------------------------------------*/ | |
5712 | /* | |
5713 | * Wireless Handler : set frequency | |
5714 | */ | |
5715 | static int airo_set_freq(struct net_device *dev, | |
5716 | struct iw_request_info *info, | |
5717 | struct iw_freq *fwrq, | |
5718 | char *extra) | |
5719 | { | |
faf3994a | 5720 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
5721 | int rc = -EINPROGRESS; /* Call commit handler */ |
5722 | ||
5723 | /* If setting by frequency, convert to a channel */ | |
9ee677c2 | 5724 | if(fwrq->e == 1) { |
1da177e4 | 5725 | int f = fwrq->m / 100000; |
9ee677c2 | 5726 | |
1da177e4 LT |
5727 | /* Hack to fall through... */ |
5728 | fwrq->e = 0; | |
9ee677c2 | 5729 | fwrq->m = ieee80211_freq_to_dsss_chan(f); |
1da177e4 LT |
5730 | } |
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 !!! */ | |
2610c733 | 5738 | if((channel < 1) || (channel > 14)) { |
934d8bf1 DW |
5739 | airo_print_dbg(dev->name, "New channel value of %d is invalid!", |
5740 | fwrq->m); | |
1da177e4 LT |
5741 | rc = -EINVAL; |
5742 | } else { | |
5743 | readConfigRid(local, 1); | |
5744 | /* Yes ! We can set it !!! */ | |
3eb9b41f | 5745 | local->config.channelSet = cpu_to_le16(channel); |
1da177e4 LT |
5746 | set_bit (FLAG_COMMIT, &local->flags); |
5747 | } | |
5748 | } | |
5749 | return rc; | |
5750 | } | |
5751 | ||
5752 | /*------------------------------------------------------------------*/ | |
5753 | /* | |
5754 | * Wireless Handler : get frequency | |
5755 | */ | |
5756 | static int airo_get_freq(struct net_device *dev, | |
5757 | struct iw_request_info *info, | |
5758 | struct iw_freq *fwrq, | |
5759 | char *extra) | |
5760 | { | |
faf3994a | 5761 | struct airo_info *local = dev->ml_priv; |
1da177e4 | 5762 | StatusRid status_rid; /* Card status info */ |
2610c733 | 5763 | int ch; |
1da177e4 LT |
5764 | |
5765 | readConfigRid(local, 1); | |
3eb9b41f AV |
5766 | if ((local->config.opmode & MODE_CFG_MASK) == MODE_STA_ESS) |
5767 | status_rid.channel = local->config.channelSet; | |
1da177e4 LT |
5768 | else |
5769 | readStatusRid(local, &status_rid, 1); | |
5770 | ||
329e2c00 | 5771 | ch = le16_to_cpu(status_rid.channel); |
2610c733 | 5772 | if((ch > 0) && (ch < 15)) { |
9ee677c2 | 5773 | fwrq->m = ieee80211_dsss_chan_to_freq(ch) * 100000; |
1da177e4 | 5774 | fwrq->e = 1; |
2610c733 JA |
5775 | } else { |
5776 | fwrq->m = ch; | |
5777 | fwrq->e = 0; | |
1da177e4 | 5778 | } |
1da177e4 LT |
5779 | |
5780 | return 0; | |
5781 | } | |
5782 | ||
5783 | /*------------------------------------------------------------------*/ | |
5784 | /* | |
5785 | * Wireless Handler : set ESSID | |
5786 | */ | |
5787 | static int airo_set_essid(struct net_device *dev, | |
5788 | struct iw_request_info *info, | |
5789 | struct iw_point *dwrq, | |
5790 | char *extra) | |
5791 | { | |
faf3994a | 5792 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
5793 | SsidRid SSID_rid; /* SSIDs */ |
5794 | ||
5795 | /* Reload the list of current SSID */ | |
5796 | readSsidRid(local, &SSID_rid); | |
5797 | ||
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; | |
5804 | ||
5805 | /* Check the size of the string */ | |
7f8544cc | 5806 | if(dwrq->length > IW_ESSID_MAX_SIZE) { |
1da177e4 LT |
5807 | return -E2BIG ; |
5808 | } | |
5809 | /* Check if index is valid */ | |
5810 | if((index < 0) || (index >= 4)) { | |
5811 | return -EINVAL; | |
5812 | } | |
5813 | ||
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); | |
0dd2212f | 5818 | SSID_rid.ssids[index].len = cpu_to_le16(dwrq->length); |
1da177e4 | 5819 | } |
0dd2212f | 5820 | SSID_rid.len = cpu_to_le16(sizeof(SSID_rid)); |
1da177e4 LT |
5821 | /* Write it to the card */ |
5822 | disable_MAC(local, 1); | |
5823 | writeSsidRid(local, &SSID_rid, 1); | |
175ec1a1 | 5824 | enable_MAC(local, 1); |
1da177e4 LT |
5825 | |
5826 | return 0; | |
5827 | } | |
5828 | ||
5829 | /*------------------------------------------------------------------*/ | |
5830 | /* | |
5831 | * Wireless Handler : get ESSID | |
5832 | */ | |
5833 | static int airo_get_essid(struct net_device *dev, | |
5834 | struct iw_request_info *info, | |
5835 | struct iw_point *dwrq, | |
5836 | char *extra) | |
5837 | { | |
faf3994a | 5838 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
5839 | StatusRid status_rid; /* Card status info */ |
5840 | ||
5841 | readStatusRid(local, &status_rid, 1); | |
5842 | ||
5843 | /* Note : if dwrq->flags != 0, we should | |
5844 | * get the relevant SSID from the SSID list... */ | |
5845 | ||
5846 | /* Get the current SSID */ | |
329e2c00 | 5847 | memcpy(extra, status_rid.SSID, le16_to_cpu(status_rid.SSIDlen)); |
1da177e4 LT |
5848 | /* If none, we may want to get the one that was set */ |
5849 | ||
5850 | /* Push it out ! */ | |
329e2c00 | 5851 | dwrq->length = le16_to_cpu(status_rid.SSIDlen); |
1da177e4 LT |
5852 | dwrq->flags = 1; /* active */ |
5853 | ||
5854 | return 0; | |
5855 | } | |
5856 | ||
5857 | /*------------------------------------------------------------------*/ | |
5858 | /* | |
5859 | * Wireless Handler : set AP address | |
5860 | */ | |
5861 | static int airo_set_wap(struct net_device *dev, | |
5862 | struct iw_request_info *info, | |
5863 | struct sockaddr *awrq, | |
5864 | char *extra) | |
5865 | { | |
faf3994a | 5866 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
5867 | Cmd cmd; |
5868 | Resp rsp; | |
5869 | APListRid APList_rid; | |
4be757dd DW |
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 }; | |
1da177e4 LT |
5872 | |
5873 | if (awrq->sa_family != ARPHRD_ETHER) | |
5874 | return -EINVAL; | |
4be757dd DW |
5875 | else if (!memcmp(any, awrq->sa_data, ETH_ALEN) || |
5876 | !memcmp(off, awrq->sa_data, ETH_ALEN)) { | |
1da177e4 LT |
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)); | |
a749716e | 5885 | APList_rid.len = cpu_to_le16(sizeof(APList_rid)); |
1da177e4 LT |
5886 | memcpy(APList_rid.ap[0], awrq->sa_data, ETH_ALEN); |
5887 | disable_MAC(local, 1); | |
5888 | writeAPListRid(local, &APList_rid, 1); | |
175ec1a1 | 5889 | enable_MAC(local, 1); |
1da177e4 LT |
5890 | } |
5891 | return 0; | |
5892 | } | |
5893 | ||
5894 | /*------------------------------------------------------------------*/ | |
5895 | /* | |
5896 | * Wireless Handler : get AP address | |
5897 | */ | |
5898 | static int airo_get_wap(struct net_device *dev, | |
5899 | struct iw_request_info *info, | |
5900 | struct sockaddr *awrq, | |
5901 | char *extra) | |
5902 | { | |
faf3994a | 5903 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
5904 | StatusRid status_rid; /* Card status info */ |
5905 | ||
5906 | readStatusRid(local, &status_rid, 1); | |
5907 | ||
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; | |
5911 | ||
5912 | return 0; | |
5913 | } | |
5914 | ||
5915 | /*------------------------------------------------------------------*/ | |
5916 | /* | |
5917 | * Wireless Handler : set Nickname | |
5918 | */ | |
5919 | static int airo_set_nick(struct net_device *dev, | |
5920 | struct iw_request_info *info, | |
5921 | struct iw_point *dwrq, | |
5922 | char *extra) | |
5923 | { | |
faf3994a | 5924 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
5925 | |
5926 | /* Check the size of the string */ | |
7f8544cc | 5927 | if(dwrq->length > 16) { |
1da177e4 LT |
5928 | return -E2BIG; |
5929 | } | |
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); | |
5934 | ||
5935 | return -EINPROGRESS; /* Call commit handler */ | |
5936 | } | |
5937 | ||
5938 | /*------------------------------------------------------------------*/ | |
5939 | /* | |
5940 | * Wireless Handler : get Nickname | |
5941 | */ | |
5942 | static int airo_get_nick(struct net_device *dev, | |
5943 | struct iw_request_info *info, | |
5944 | struct iw_point *dwrq, | |
5945 | char *extra) | |
5946 | { | |
faf3994a | 5947 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
5948 | |
5949 | readConfigRid(local, 1); | |
5950 | strncpy(extra, local->config.nodeName, 16); | |
5951 | extra[16] = '\0'; | |
7f8544cc | 5952 | dwrq->length = strlen(extra); |
1da177e4 LT |
5953 | |
5954 | return 0; | |
5955 | } | |
5956 | ||
5957 | /*------------------------------------------------------------------*/ | |
5958 | /* | |
5959 | * Wireless Handler : set Bit-Rate | |
5960 | */ | |
5961 | static int airo_set_rate(struct net_device *dev, | |
5962 | struct iw_request_info *info, | |
5963 | struct iw_param *vwrq, | |
5964 | char *extra) | |
5965 | { | |
faf3994a | 5966 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
5967 | CapabilityRid cap_rid; /* Card capability info */ |
5968 | u8 brate = 0; | |
5969 | int i; | |
5970 | ||
5971 | /* First : get a valid bit rate value */ | |
5972 | readCapabilityRid(local, &cap_rid, 1); | |
5973 | ||
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); | |
5982 | ||
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; | |
5988 | } | |
5989 | } | |
5990 | } | |
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; | |
5997 | } | |
5998 | if(i != 0) | |
5999 | brate = cap_rid.supportedRates[i - 1]; | |
6000 | } | |
6001 | /* Check that it is valid */ | |
6002 | if(brate == 0) { | |
6003 | return -EINVAL; | |
6004 | } | |
6005 | ||
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; | |
6015 | } | |
6016 | } else { | |
6017 | /* Fixed mode */ | |
6018 | /* One rate, fixed */ | |
6019 | memset(local->config.rates, 0, 8); | |
6020 | local->config.rates[0] = brate; | |
6021 | } | |
6022 | set_bit (FLAG_COMMIT, &local->flags); | |
6023 | ||
6024 | return -EINPROGRESS; /* Call commit handler */ | |
6025 | } | |
6026 | ||
6027 | /*------------------------------------------------------------------*/ | |
6028 | /* | |
6029 | * Wireless Handler : get Bit-Rate | |
6030 | */ | |
6031 | static int airo_get_rate(struct net_device *dev, | |
6032 | struct iw_request_info *info, | |
6033 | struct iw_param *vwrq, | |
6034 | char *extra) | |
6035 | { | |
faf3994a | 6036 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
6037 | StatusRid status_rid; /* Card status info */ |
6038 | ||
6039 | readStatusRid(local, &status_rid, 1); | |
6040 | ||
329e2c00 | 6041 | vwrq->value = le16_to_cpu(status_rid.currentXmitRate) * 500000; |
1da177e4 LT |
6042 | /* If more than one rate, set auto */ |
6043 | readConfigRid(local, 1); | |
6044 | vwrq->fixed = (local->config.rates[1] == 0); | |
6045 | ||
6046 | return 0; | |
6047 | } | |
6048 | ||
6049 | /*------------------------------------------------------------------*/ | |
6050 | /* | |
6051 | * Wireless Handler : set RTS threshold | |
6052 | */ | |
6053 | static int airo_set_rts(struct net_device *dev, | |
6054 | struct iw_request_info *info, | |
6055 | struct iw_param *vwrq, | |
6056 | char *extra) | |
6057 | { | |
faf3994a | 6058 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
6059 | int rthr = vwrq->value; |
6060 | ||
6061 | if(vwrq->disabled) | |
15db2763 DW |
6062 | rthr = AIRO_DEF_MTU; |
6063 | if((rthr < 0) || (rthr > AIRO_DEF_MTU)) { | |
1da177e4 LT |
6064 | return -EINVAL; |
6065 | } | |
6066 | readConfigRid(local, 1); | |
3eb9b41f | 6067 | local->config.rtsThres = cpu_to_le16(rthr); |
1da177e4 LT |
6068 | set_bit (FLAG_COMMIT, &local->flags); |
6069 | ||
6070 | return -EINPROGRESS; /* Call commit handler */ | |
6071 | } | |
6072 | ||
6073 | /*------------------------------------------------------------------*/ | |
6074 | /* | |
6075 | * Wireless Handler : get RTS threshold | |
6076 | */ | |
6077 | static int airo_get_rts(struct net_device *dev, | |
6078 | struct iw_request_info *info, | |
6079 | struct iw_param *vwrq, | |
6080 | char *extra) | |
6081 | { | |
faf3994a | 6082 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
6083 | |
6084 | readConfigRid(local, 1); | |
3eb9b41f | 6085 | vwrq->value = le16_to_cpu(local->config.rtsThres); |
15db2763 | 6086 | vwrq->disabled = (vwrq->value >= AIRO_DEF_MTU); |
1da177e4 LT |
6087 | vwrq->fixed = 1; |
6088 | ||
6089 | return 0; | |
6090 | } | |
6091 | ||
6092 | /*------------------------------------------------------------------*/ | |
6093 | /* | |
6094 | * Wireless Handler : set Fragmentation threshold | |
6095 | */ | |
6096 | static int airo_set_frag(struct net_device *dev, | |
6097 | struct iw_request_info *info, | |
6098 | struct iw_param *vwrq, | |
6099 | char *extra) | |
6100 | { | |
faf3994a | 6101 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
6102 | int fthr = vwrq->value; |
6103 | ||
6104 | if(vwrq->disabled) | |
15db2763 DW |
6105 | fthr = AIRO_DEF_MTU; |
6106 | if((fthr < 256) || (fthr > AIRO_DEF_MTU)) { | |
1da177e4 LT |
6107 | return -EINVAL; |
6108 | } | |
6109 | fthr &= ~0x1; /* Get an even value - is it really needed ??? */ | |
6110 | readConfigRid(local, 1); | |
3eb9b41f | 6111 | local->config.fragThresh = cpu_to_le16(fthr); |
1da177e4 LT |
6112 | set_bit (FLAG_COMMIT, &local->flags); |
6113 | ||
6114 | return -EINPROGRESS; /* Call commit handler */ | |
6115 | } | |
6116 | ||
6117 | /*------------------------------------------------------------------*/ | |
6118 | /* | |
6119 | * Wireless Handler : get Fragmentation threshold | |
6120 | */ | |
6121 | static int airo_get_frag(struct net_device *dev, | |
6122 | struct iw_request_info *info, | |
6123 | struct iw_param *vwrq, | |
6124 | char *extra) | |
6125 | { | |
faf3994a | 6126 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
6127 | |
6128 | readConfigRid(local, 1); | |
3eb9b41f | 6129 | vwrq->value = le16_to_cpu(local->config.fragThresh); |
15db2763 | 6130 | vwrq->disabled = (vwrq->value >= AIRO_DEF_MTU); |
1da177e4 LT |
6131 | vwrq->fixed = 1; |
6132 | ||
6133 | return 0; | |
6134 | } | |
6135 | ||
6136 | /*------------------------------------------------------------------*/ | |
6137 | /* | |
6138 | * Wireless Handler : set Mode of Operation | |
6139 | */ | |
6140 | static int airo_set_mode(struct net_device *dev, | |
6141 | struct iw_request_info *info, | |
6142 | __u32 *uwrq, | |
6143 | char *extra) | |
6144 | { | |
faf3994a | 6145 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
6146 | int reset = 0; |
6147 | ||
6148 | readConfigRid(local, 1); | |
3eb9b41f | 6149 | if (sniffing_mode(local)) |
1da177e4 LT |
6150 | reset = 1; |
6151 | ||
6152 | switch(*uwrq) { | |
6153 | case IW_MODE_ADHOC: | |
3eb9b41f | 6154 | local->config.opmode &= ~MODE_CFG_MASK; |
1da177e4 | 6155 | local->config.opmode |= MODE_STA_IBSS; |
3eb9b41f | 6156 | local->config.rmode &= ~RXMODE_FULL_MASK; |
1da177e4 LT |
6157 | local->config.scanMode = SCANMODE_ACTIVE; |
6158 | clear_bit (FLAG_802_11, &local->flags); | |
6159 | break; | |
6160 | case IW_MODE_INFRA: | |
3eb9b41f | 6161 | local->config.opmode &= ~MODE_CFG_MASK; |
1da177e4 | 6162 | local->config.opmode |= MODE_STA_ESS; |
3eb9b41f | 6163 | local->config.rmode &= ~RXMODE_FULL_MASK; |
1da177e4 LT |
6164 | local->config.scanMode = SCANMODE_ACTIVE; |
6165 | clear_bit (FLAG_802_11, &local->flags); | |
6166 | break; | |
6167 | case IW_MODE_MASTER: | |
3eb9b41f | 6168 | local->config.opmode &= ~MODE_CFG_MASK; |
1da177e4 | 6169 | local->config.opmode |= MODE_AP; |
3eb9b41f | 6170 | local->config.rmode &= ~RXMODE_FULL_MASK; |
1da177e4 LT |
6171 | local->config.scanMode = SCANMODE_ACTIVE; |
6172 | clear_bit (FLAG_802_11, &local->flags); | |
6173 | break; | |
6174 | case IW_MODE_REPEAT: | |
3eb9b41f | 6175 | local->config.opmode &= ~MODE_CFG_MASK; |
1da177e4 | 6176 | local->config.opmode |= MODE_AP_RPTR; |
3eb9b41f | 6177 | local->config.rmode &= ~RXMODE_FULL_MASK; |
1da177e4 LT |
6178 | local->config.scanMode = SCANMODE_ACTIVE; |
6179 | clear_bit (FLAG_802_11, &local->flags); | |
6180 | break; | |
6181 | case IW_MODE_MONITOR: | |
3eb9b41f | 6182 | local->config.opmode &= ~MODE_CFG_MASK; |
1da177e4 | 6183 | local->config.opmode |= MODE_STA_ESS; |
3eb9b41f | 6184 | local->config.rmode &= ~RXMODE_FULL_MASK; |
1da177e4 LT |
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; | |
6191 | } | |
6192 | if (reset) | |
6193 | set_bit (FLAG_RESET, &local->flags); | |
6194 | set_bit (FLAG_COMMIT, &local->flags); | |
6195 | ||
6196 | return -EINPROGRESS; /* Call commit handler */ | |
6197 | } | |
6198 | ||
6199 | /*------------------------------------------------------------------*/ | |
6200 | /* | |
6201 | * Wireless Handler : get Mode of Operation | |
6202 | */ | |
6203 | static int airo_get_mode(struct net_device *dev, | |
6204 | struct iw_request_info *info, | |
6205 | __u32 *uwrq, | |
6206 | char *extra) | |
6207 | { | |
faf3994a | 6208 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
6209 | |
6210 | readConfigRid(local, 1); | |
6211 | /* If not managed, assume it's ad-hoc */ | |
3eb9b41f | 6212 | switch (local->config.opmode & MODE_CFG_MASK) { |
1da177e4 LT |
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; | |
6224 | } | |
6225 | ||
6226 | return 0; | |
6227 | } | |
6228 | ||
56d81bd3 AV |
6229 | static inline int valid_index(CapabilityRid *p, int index) |
6230 | { | |
6231 | if (index < 0) | |
6232 | return 0; | |
6233 | return index < (p->softCap & cpu_to_le16(0x80) ? 4 : 1); | |
6234 | } | |
6235 | ||
1da177e4 LT |
6236 | /*------------------------------------------------------------------*/ |
6237 | /* | |
6238 | * Wireless Handler : set Encryption Key | |
6239 | */ | |
6240 | static int airo_set_encode(struct net_device *dev, | |
6241 | struct iw_request_info *info, | |
6242 | struct iw_point *dwrq, | |
6243 | char *extra) | |
6244 | { | |
faf3994a | 6245 | struct airo_info *local = dev->ml_priv; |
1da177e4 | 6246 | CapabilityRid cap_rid; /* Card capability info */ |
f89b2321 | 6247 | int perm = ( dwrq->flags & IW_ENCODE_TEMP ? 0 : 1 ); |
3eb9b41f | 6248 | __le16 currentAuthType = local->config.authType; |
1da177e4 LT |
6249 | |
6250 | /* Is WEP supported ? */ | |
6251 | readCapabilityRid(local, &cap_rid, 1); | |
6252 | /* Older firmware doesn't support this... | |
56d81bd3 | 6253 | if(!(cap_rid.softCap & cpu_to_le16(2))) { |
1da177e4 LT |
6254 | return -EOPNOTSUPP; |
6255 | } */ | |
6256 | readConfigRid(local, 1); | |
6257 | ||
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; | |
6271 | } | |
6272 | /* Check the index (none -> use current) */ | |
56d81bd3 | 6273 | if (!valid_index(&cap_rid, index)) |
1da177e4 LT |
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 */ | |
f89b2321 | 6291 | set_wep_key(local, index, key.key, key.len, perm, 1); |
1da177e4 LT |
6292 | } |
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; | |
1da177e4 LT |
6299 | } |
6300 | } else { | |
6301 | /* Do we want to just set the transmit key index ? */ | |
6302 | int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; | |
56d81bd3 | 6303 | if (valid_index(&cap_rid, index)) { |
f89b2321 | 6304 | set_wep_key(local, index, NULL, 0, perm, 1); |
1da177e4 LT |
6305 | } else |
6306 | /* Don't complain if only change the mode */ | |
93a3b607 | 6307 | if (!(dwrq->flags & IW_ENCODE_MODE)) |
1da177e4 | 6308 | return -EINVAL; |
1da177e4 LT |
6309 | } |
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 */ | |
f89b2321 | 6318 | if (local->config.authType != currentAuthType) |
1da177e4 LT |
6319 | set_bit (FLAG_COMMIT, &local->flags); |
6320 | return -EINPROGRESS; /* Call commit handler */ | |
6321 | } | |
6322 | ||
6323 | /*------------------------------------------------------------------*/ | |
6324 | /* | |
6325 | * Wireless Handler : get Encryption Key | |
6326 | */ | |
6327 | static int airo_get_encode(struct net_device *dev, | |
6328 | struct iw_request_info *info, | |
6329 | struct iw_point *dwrq, | |
6330 | char *extra) | |
6331 | { | |
faf3994a | 6332 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
6333 | int index = (dwrq->flags & IW_ENCODE_INDEX) - 1; |
6334 | CapabilityRid cap_rid; /* Card capability info */ | |
6335 | ||
6336 | /* Is it supported ? */ | |
6337 | readCapabilityRid(local, &cap_rid, 1); | |
56d81bd3 | 6338 | if(!(cap_rid.softCap & cpu_to_le16(2))) { |
1da177e4 LT |
6339 | return -EOPNOTSUPP; |
6340 | } | |
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; | |
6354 | } | |
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); | |
6358 | ||
6359 | /* Which key do we want ? -1 -> tx index */ | |
56d81bd3 | 6360 | if (!valid_index(&cap_rid, index)) |
1da177e4 LT |
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; | |
6367 | } | |
6368 | return 0; | |
6369 | } | |
6370 | ||
4be757dd DW |
6371 | /*------------------------------------------------------------------*/ |
6372 | /* | |
6373 | * Wireless Handler : set extended Encryption parameters | |
6374 | */ | |
6375 | static int airo_set_encodeext(struct net_device *dev, | |
6376 | struct iw_request_info *info, | |
6377 | union iwreq_data *wrqu, | |
6378 | char *extra) | |
6379 | { | |
faf3994a | 6380 | struct airo_info *local = dev->ml_priv; |
4be757dd DW |
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 ); | |
3eb9b41f | 6385 | __le16 currentAuthType = local->config.authType; |
22d8846e | 6386 | int idx, key_len, alg = ext->alg, set_key = 1; |
4be757dd DW |
6387 | wep_key_t key; |
6388 | ||
6389 | /* Is WEP supported ? */ | |
6390 | readCapabilityRid(local, &cap_rid, 1); | |
6391 | /* Older firmware doesn't support this... | |
56d81bd3 | 6392 | if(!(cap_rid.softCap & cpu_to_le16(2))) { |
4be757dd DW |
6393 | return -EOPNOTSUPP; |
6394 | } */ | |
6395 | readConfigRid(local, 1); | |
6396 | ||
6397 | /* Determine and validate the key index */ | |
6398 | idx = encoding->flags & IW_ENCODE_INDEX; | |
6399 | if (idx) { | |
56d81bd3 | 6400 | if (!valid_index(&cap_rid, idx - 1)) |
4be757dd DW |
6401 | return -EINVAL; |
6402 | idx--; | |
6403 | } else | |
6404 | idx = get_wep_key(local, 0xffff); | |
6405 | ||
6406 | if (encoding->flags & IW_ENCODE_DISABLED) | |
6407 | alg = IW_ENCODE_ALG_NONE; | |
6408 | ||
4be757dd | 6409 | if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { |
22d8846e DW |
6410 | /* Only set transmit key index here, actual |
6411 | * key is set below if needed. | |
6412 | */ | |
4be757dd | 6413 | set_wep_key(local, idx, NULL, 0, perm, 1); |
22d8846e DW |
6414 | set_key = ext->key_len > 0 ? 1 : 0; |
6415 | } | |
6416 | ||
6417 | if (set_key) { | |
4be757dd DW |
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; | |
6431 | } | |
6432 | key_len = min (ext->key_len, key.len); | |
6433 | memcpy(key.key, ext->key, key_len); | |
6434 | break; | |
6435 | default: | |
6436 | return -EINVAL; | |
6437 | } | |
6438 | /* Send the key to the card */ | |
6439 | set_wep_key(local, idx, key.key, key.len, perm, 1); | |
6440 | } | |
6441 | ||
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); | |
6452 | ||
6453 | return -EINPROGRESS; | |
6454 | } | |
6455 | ||
6456 | ||
6457 | /*------------------------------------------------------------------*/ | |
6458 | /* | |
6459 | * Wireless Handler : get extended Encryption parameters | |
6460 | */ | |
6461 | static int airo_get_encodeext(struct net_device *dev, | |
6462 | struct iw_request_info *info, | |
6463 | union iwreq_data *wrqu, | |
6464 | char *extra) | |
6465 | { | |
faf3994a | 6466 | struct airo_info *local = dev->ml_priv; |
4be757dd DW |
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; | |
6471 | ||
6472 | /* Is it supported ? */ | |
6473 | readCapabilityRid(local, &cap_rid, 1); | |
56d81bd3 | 6474 | if(!(cap_rid.softCap & cpu_to_le16(2))) { |
4be757dd DW |
6475 | return -EOPNOTSUPP; |
6476 | } | |
6477 | readConfigRid(local, 1); | |
6478 | ||
6479 | max_key_len = encoding->length - sizeof(*ext); | |
6480 | if (max_key_len < 0) | |
6481 | return -EINVAL; | |
6482 | ||
6483 | idx = encoding->flags & IW_ENCODE_INDEX; | |
6484 | if (idx) { | |
56d81bd3 | 6485 | if (!valid_index(&cap_rid, idx - 1)) |
4be757dd DW |
6486 | return -EINVAL; |
6487 | idx--; | |
6488 | } else | |
6489 | idx = get_wep_key(local, 0xffff); | |
6490 | ||
6491 | encoding->flags = idx + 1; | |
6492 | memset(ext, 0, sizeof(*ext)); | |
6493 | ||
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; | |
6506 | } | |
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); | |
6510 | ||
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; | |
6515 | } | |
6516 | ||
6517 | return 0; | |
6518 | } | |
6519 | ||
6520 | ||
6521 | /*------------------------------------------------------------------*/ | |
6522 | /* | |
6523 | * Wireless Handler : set extended authentication parameters | |
6524 | */ | |
6525 | static int airo_set_auth(struct net_device *dev, | |
6526 | struct iw_request_info *info, | |
6527 | union iwreq_data *wrqu, char *extra) | |
6528 | { | |
faf3994a | 6529 | struct airo_info *local = dev->ml_priv; |
4be757dd | 6530 | struct iw_param *param = &wrqu->param; |
3eb9b41f | 6531 | __le16 currentAuthType = local->config.authType; |
4be757dd DW |
6532 | |
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: | |
6540 | /* | |
6541 | * airo does not use these parameters | |
6542 | */ | |
6543 | break; | |
6544 | ||
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; | |
6552 | } | |
6553 | ||
6554 | /* Commit the changes to flags if needed */ | |
6555 | if (local->config.authType != currentAuthType) | |
6556 | set_bit (FLAG_COMMIT, &local->flags); | |
6557 | break; | |
6558 | ||
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. | |
6562 | */ | |
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; | |
6570 | ||
6571 | /* Commit the changes to flags if needed */ | |
6572 | if (local->config.authType != currentAuthType) | |
6573 | set_bit (FLAG_COMMIT, &local->flags); | |
6574 | } | |
6575 | ||
6576 | case IW_AUTH_WPA_ENABLED: | |
6577 | /* Silently accept disable of WPA */ | |
6578 | if (param->value > 0) | |
6579 | return -EOPNOTSUPP; | |
6580 | break; | |
6581 | ||
6582 | default: | |
6583 | return -EOPNOTSUPP; | |
6584 | } | |
6585 | return -EINPROGRESS; | |
6586 | } | |
6587 | ||
6588 | ||
6589 | /*------------------------------------------------------------------*/ | |
6590 | /* | |
6591 | * Wireless Handler : get extended authentication parameters | |
6592 | */ | |
6593 | static int airo_get_auth(struct net_device *dev, | |
6594 | struct iw_request_info *info, | |
6595 | union iwreq_data *wrqu, char *extra) | |
6596 | { | |
faf3994a | 6597 | struct airo_info *local = dev->ml_priv; |
4be757dd | 6598 | struct iw_param *param = &wrqu->param; |
3eb9b41f | 6599 | __le16 currentAuthType = local->config.authType; |
4be757dd DW |
6600 | |
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; | |
6611 | } | |
6612 | break; | |
6613 | ||
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; | |
6623 | } | |
6624 | break; | |
6625 | ||
6626 | case IW_AUTH_WPA_ENABLED: | |
6627 | param->value = 0; | |
6628 | break; | |
6629 | ||
6630 | default: | |
6631 | return -EOPNOTSUPP; | |
6632 | } | |
6633 | return 0; | |
6634 | } | |
6635 | ||
6636 | ||
1da177e4 LT |
6637 | /*------------------------------------------------------------------*/ |
6638 | /* | |
6639 | * Wireless Handler : set Tx-Power | |
6640 | */ | |
6641 | static int airo_set_txpow(struct net_device *dev, | |
6642 | struct iw_request_info *info, | |
6643 | struct iw_param *vwrq, | |
6644 | char *extra) | |
6645 | { | |
faf3994a | 6646 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
6647 | CapabilityRid cap_rid; /* Card capability info */ |
6648 | int i; | |
6649 | int rc = -EINVAL; | |
3eb9b41f | 6650 | __le16 v = cpu_to_le16(vwrq->value); |
1da177e4 LT |
6651 | |
6652 | readCapabilityRid(local, &cap_rid, 1); | |
6653 | ||
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 */ | |
6658 | } | |
6659 | if (vwrq->flags != IW_TXPOW_MWATT) { | |
6660 | return -EINVAL; | |
6661 | } | |
6662 | clear_bit (FLAG_RADIO_OFF, &local->flags); | |
6663 | for (i = 0; cap_rid.txPowerLevels[i] && (i < 8); i++) | |
3eb9b41f | 6664 | if (v == cap_rid.txPowerLevels[i]) { |
1da177e4 | 6665 | readConfigRid(local, 1); |
3eb9b41f | 6666 | local->config.txPower = v; |
1da177e4 LT |
6667 | set_bit (FLAG_COMMIT, &local->flags); |
6668 | rc = -EINPROGRESS; /* Call commit handler */ | |
6669 | break; | |
6670 | } | |
6671 | return rc; | |
6672 | } | |
6673 | ||
6674 | /*------------------------------------------------------------------*/ | |
6675 | /* | |
6676 | * Wireless Handler : get Tx-Power | |
6677 | */ | |
6678 | static int airo_get_txpow(struct net_device *dev, | |
6679 | struct iw_request_info *info, | |
6680 | struct iw_param *vwrq, | |
6681 | char *extra) | |
6682 | { | |
faf3994a | 6683 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
6684 | |
6685 | readConfigRid(local, 1); | |
3eb9b41f | 6686 | vwrq->value = le16_to_cpu(local->config.txPower); |
1da177e4 LT |
6687 | vwrq->fixed = 1; /* No power control */ |
6688 | vwrq->disabled = test_bit(FLAG_RADIO_OFF, &local->flags); | |
6689 | vwrq->flags = IW_TXPOW_MWATT; | |
6690 | ||
6691 | return 0; | |
6692 | } | |
6693 | ||
6694 | /*------------------------------------------------------------------*/ | |
6695 | /* | |
6696 | * Wireless Handler : set Retry limits | |
6697 | */ | |
6698 | static int airo_set_retry(struct net_device *dev, | |
6699 | struct iw_request_info *info, | |
6700 | struct iw_param *vwrq, | |
6701 | char *extra) | |
6702 | { | |
faf3994a | 6703 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
6704 | int rc = -EINVAL; |
6705 | ||
6706 | if(vwrq->disabled) { | |
6707 | return -EINVAL; | |
6708 | } | |
6709 | readConfigRid(local, 1); | |
6710 | if(vwrq->flags & IW_RETRY_LIMIT) { | |
3eb9b41f | 6711 | __le16 v = cpu_to_le16(vwrq->value); |
7f8544cc | 6712 | if(vwrq->flags & IW_RETRY_LONG) |
3eb9b41f | 6713 | local->config.longRetryLimit = v; |
7f8544cc | 6714 | else if (vwrq->flags & IW_RETRY_SHORT) |
3eb9b41f | 6715 | local->config.shortRetryLimit = v; |
1da177e4 LT |
6716 | else { |
6717 | /* No modifier : set both */ | |
3eb9b41f AV |
6718 | local->config.longRetryLimit = v; |
6719 | local->config.shortRetryLimit = v; | |
1da177e4 LT |
6720 | } |
6721 | set_bit (FLAG_COMMIT, &local->flags); | |
6722 | rc = -EINPROGRESS; /* Call commit handler */ | |
6723 | } | |
6724 | if(vwrq->flags & IW_RETRY_LIFETIME) { | |
3eb9b41f | 6725 | local->config.txLifetime = cpu_to_le16(vwrq->value / 1024); |
1da177e4 LT |
6726 | set_bit (FLAG_COMMIT, &local->flags); |
6727 | rc = -EINPROGRESS; /* Call commit handler */ | |
6728 | } | |
6729 | return rc; | |
6730 | } | |
6731 | ||
6732 | /*------------------------------------------------------------------*/ | |
6733 | /* | |
6734 | * Wireless Handler : get Retry limits | |
6735 | */ | |
6736 | static int airo_get_retry(struct net_device *dev, | |
6737 | struct iw_request_info *info, | |
6738 | struct iw_param *vwrq, | |
6739 | char *extra) | |
6740 | { | |
faf3994a | 6741 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
6742 | |
6743 | vwrq->disabled = 0; /* Can't be disabled */ | |
6744 | ||
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; | |
3eb9b41f | 6749 | vwrq->value = le16_to_cpu(local->config.txLifetime) * 1024; |
7f8544cc JT |
6750 | } else if((vwrq->flags & IW_RETRY_LONG)) { |
6751 | vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG; | |
3eb9b41f | 6752 | vwrq->value = le16_to_cpu(local->config.longRetryLimit); |
1da177e4 LT |
6753 | } else { |
6754 | vwrq->flags = IW_RETRY_LIMIT; | |
3eb9b41f AV |
6755 | vwrq->value = le16_to_cpu(local->config.shortRetryLimit); |
6756 | if(local->config.shortRetryLimit != local->config.longRetryLimit) | |
7f8544cc | 6757 | vwrq->flags |= IW_RETRY_SHORT; |
1da177e4 LT |
6758 | } |
6759 | ||
6760 | return 0; | |
6761 | } | |
6762 | ||
6763 | /*------------------------------------------------------------------*/ | |
6764 | /* | |
6765 | * Wireless Handler : get range info | |
6766 | */ | |
6767 | static int airo_get_range(struct net_device *dev, | |
6768 | struct iw_request_info *info, | |
6769 | struct iw_point *dwrq, | |
6770 | char *extra) | |
6771 | { | |
faf3994a | 6772 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
6773 | struct iw_range *range = (struct iw_range *) extra; |
6774 | CapabilityRid cap_rid; /* Card capability info */ | |
6775 | int i; | |
6776 | int k; | |
6777 | ||
6778 | readCapabilityRid(local, &cap_rid, 1); | |
6779 | ||
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 */ | |
9ee677c2 DK |
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 */ | |
1da177e4 LT |
6792 | } |
6793 | range->num_frequency = k; | |
6794 | ||
41480af2 DW |
6795 | range->sensitivity = 65535; |
6796 | ||
1da177e4 | 6797 | /* Hum... Should put the right values there */ |
41480af2 DW |
6798 | if (local->rssi) |
6799 | range->max_qual.qual = 100; /* % */ | |
6800 | else | |
6801 | range->max_qual.qual = airo_get_max_quality(&cap_rid); | |
ce6623c3 JT |
6802 | range->max_qual.level = 0x100 - 120; /* -120 dBm */ |
6803 | range->max_qual.noise = 0x100 - 120; /* -120 dBm */ | |
41480af2 DW |
6804 | |
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) { | |
ce6623c3 JT |
6809 | range->avg_qual.qual = 50; /* % */ |
6810 | range->avg_qual.level = 0x100 - 70; /* -70 dBm */ | |
41480af2 DW |
6811 | } else { |
6812 | range->avg_qual.qual = airo_get_avg_quality(&cap_rid); | |
ce6623c3 | 6813 | range->avg_qual.level = 0x100 - 80; /* -80 dBm */ |
41480af2 | 6814 | } |
ce6623c3 | 6815 | range->avg_qual.noise = 0x100 - 85; /* -85 dBm */ |
1da177e4 LT |
6816 | |
6817 | for(i = 0 ; i < 8 ; i++) { | |
6818 | range->bitrate[i] = cap_rid.supportedRates[i] * 500000; | |
6819 | if(range->bitrate[i] == 0) | |
6820 | break; | |
6821 | } | |
6822 | range->num_bitrates = i; | |
6823 | ||
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; | |
6831 | ||
6832 | range->min_rts = 0; | |
15db2763 | 6833 | range->max_rts = AIRO_DEF_MTU; |
1da177e4 | 6834 | range->min_frag = 256; |
15db2763 | 6835 | range->max_frag = AIRO_DEF_MTU; |
1da177e4 | 6836 | |
56d81bd3 | 6837 | if(cap_rid.softCap & cpu_to_le16(2)) { |
1da177e4 LT |
6838 | // WEP: RC4 40 bits |
6839 | range->encoding_size[0] = 5; | |
6840 | // RC4 ~128 bits | |
56d81bd3 | 6841 | if (cap_rid.softCap & cpu_to_le16(0x100)) { |
1da177e4 LT |
6842 | range->encoding_size[1] = 13; |
6843 | range->num_encoding_sizes = 2; | |
6844 | } else | |
6845 | range->num_encoding_sizes = 1; | |
56d81bd3 AV |
6846 | range->max_encoding_tokens = |
6847 | cap_rid.softCap & cpu_to_le16(0x80) ? 4 : 1; | |
1da177e4 LT |
6848 | } else { |
6849 | range->num_encoding_sizes = 0; | |
6850 | range->max_encoding_tokens = 0; | |
6851 | } | |
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; | |
6859 | ||
6860 | /* Transmit Power - values are in mW */ | |
6861 | for(i = 0 ; i < 8 ; i++) { | |
56d81bd3 | 6862 | range->txpower[i] = le16_to_cpu(cap_rid.txPowerLevels[i]); |
1da177e4 LT |
6863 | if(range->txpower[i] == 0) |
6864 | break; | |
6865 | } | |
6866 | range->num_txpower = i; | |
6867 | range->txpower_capa = IW_TXPOW_MWATT; | |
3c304956 | 6868 | range->we_version_source = 19; |
1da177e4 LT |
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; | |
1da177e4 LT |
6877 | |
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; | |
6886 | } | |
6887 | ||
6888 | /*------------------------------------------------------------------*/ | |
6889 | /* | |
6890 | * Wireless Handler : set Power Management | |
6891 | */ | |
6892 | static int airo_set_power(struct net_device *dev, | |
6893 | struct iw_request_info *info, | |
6894 | struct iw_param *vwrq, | |
6895 | char *extra) | |
6896 | { | |
faf3994a | 6897 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
6898 | |
6899 | readConfigRid(local, 1); | |
6900 | if (vwrq->disabled) { | |
3eb9b41f | 6901 | if (sniffing_mode(local)) |
1da177e4 | 6902 | return -EINVAL; |
1da177e4 | 6903 | local->config.powerSaveMode = POWERSAVE_CAM; |
3eb9b41f | 6904 | local->config.rmode &= ~RXMODE_MASK; |
1da177e4 LT |
6905 | local->config.rmode |= RXMODE_BC_MC_ADDR; |
6906 | set_bit (FLAG_COMMIT, &local->flags); | |
6907 | return -EINPROGRESS; /* Call commit handler */ | |
6908 | } | |
6909 | if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) { | |
3eb9b41f | 6910 | local->config.fastListenDelay = cpu_to_le16((vwrq->value + 500) / 1024); |
1da177e4 LT |
6911 | local->config.powerSaveMode = POWERSAVE_PSPCAM; |
6912 | set_bit (FLAG_COMMIT, &local->flags); | |
6913 | } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) { | |
3eb9b41f AV |
6914 | local->config.fastListenInterval = |
6915 | local->config.listenInterval = | |
6916 | cpu_to_le16((vwrq->value + 500) / 1024); | |
1da177e4 LT |
6917 | local->config.powerSaveMode = POWERSAVE_PSPCAM; |
6918 | set_bit (FLAG_COMMIT, &local->flags); | |
6919 | } | |
6920 | switch (vwrq->flags & IW_POWER_MODE) { | |
6921 | case IW_POWER_UNICAST_R: | |
3eb9b41f | 6922 | if (sniffing_mode(local)) |
1da177e4 | 6923 | return -EINVAL; |
3eb9b41f | 6924 | local->config.rmode &= ~RXMODE_MASK; |
1da177e4 LT |
6925 | local->config.rmode |= RXMODE_ADDR; |
6926 | set_bit (FLAG_COMMIT, &local->flags); | |
6927 | break; | |
6928 | case IW_POWER_ALL_R: | |
3eb9b41f | 6929 | if (sniffing_mode(local)) |
1da177e4 | 6930 | return -EINVAL; |
3eb9b41f | 6931 | local->config.rmode &= ~RXMODE_MASK; |
1da177e4 LT |
6932 | local->config.rmode |= RXMODE_BC_MC_ADDR; |
6933 | set_bit (FLAG_COMMIT, &local->flags); | |
6934 | case IW_POWER_ON: | |
7f8544cc | 6935 | /* This is broken, fixme ;-) */ |
1da177e4 LT |
6936 | break; |
6937 | default: | |
6938 | return -EINVAL; | |
6939 | } | |
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 */ | |
6943 | } | |
6944 | ||
6945 | /*------------------------------------------------------------------*/ | |
6946 | /* | |
6947 | * Wireless Handler : get Power Management | |
6948 | */ | |
6949 | static int airo_get_power(struct net_device *dev, | |
6950 | struct iw_request_info *info, | |
6951 | struct iw_param *vwrq, | |
6952 | char *extra) | |
6953 | { | |
faf3994a | 6954 | struct airo_info *local = dev->ml_priv; |
3eb9b41f | 6955 | __le16 mode; |
1da177e4 LT |
6956 | |
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) { | |
3eb9b41f | 6962 | vwrq->value = le16_to_cpu(local->config.fastListenDelay) * 1024; |
1da177e4 LT |
6963 | vwrq->flags = IW_POWER_TIMEOUT; |
6964 | } else { | |
3eb9b41f | 6965 | vwrq->value = le16_to_cpu(local->config.fastListenInterval) * 1024; |
1da177e4 LT |
6966 | vwrq->flags = IW_POWER_PERIOD; |
6967 | } | |
3eb9b41f | 6968 | if ((local->config.rmode & RXMODE_MASK) == RXMODE_ADDR) |
1da177e4 LT |
6969 | vwrq->flags |= IW_POWER_UNICAST_R; |
6970 | else | |
6971 | vwrq->flags |= IW_POWER_ALL_R; | |
6972 | ||
6973 | return 0; | |
6974 | } | |
6975 | ||
6976 | /*------------------------------------------------------------------*/ | |
6977 | /* | |
6978 | * Wireless Handler : set Sensitivity | |
6979 | */ | |
6980 | static int airo_set_sens(struct net_device *dev, | |
6981 | struct iw_request_info *info, | |
6982 | struct iw_param *vwrq, | |
6983 | char *extra) | |
6984 | { | |
faf3994a | 6985 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
6986 | |
6987 | readConfigRid(local, 1); | |
3eb9b41f AV |
6988 | local->config.rssiThreshold = |
6989 | cpu_to_le16(vwrq->disabled ? RSSI_DEFAULT : vwrq->value); | |
1da177e4 LT |
6990 | set_bit (FLAG_COMMIT, &local->flags); |
6991 | ||
6992 | return -EINPROGRESS; /* Call commit handler */ | |
6993 | } | |
6994 | ||
6995 | /*------------------------------------------------------------------*/ | |
6996 | /* | |
6997 | * Wireless Handler : get Sensitivity | |
6998 | */ | |
6999 | static int airo_get_sens(struct net_device *dev, | |
7000 | struct iw_request_info *info, | |
7001 | struct iw_param *vwrq, | |
7002 | char *extra) | |
7003 | { | |
faf3994a | 7004 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
7005 | |
7006 | readConfigRid(local, 1); | |
3eb9b41f | 7007 | vwrq->value = le16_to_cpu(local->config.rssiThreshold); |
1da177e4 LT |
7008 | vwrq->disabled = (vwrq->value == 0); |
7009 | vwrq->fixed = 1; | |
7010 | ||
7011 | return 0; | |
7012 | } | |
7013 | ||
7014 | /*------------------------------------------------------------------*/ | |
7015 | /* | |
7016 | * Wireless Handler : get AP List | |
7017 | * Note : this is deprecated in favor of IWSCAN | |
7018 | */ | |
7019 | static int airo_get_aplist(struct net_device *dev, | |
7020 | struct iw_request_info *info, | |
7021 | struct iw_point *dwrq, | |
7022 | char *extra) | |
7023 | { | |
faf3994a | 7024 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
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; | |
7030 | ||
7031 | for (i = 0; i < IW_MAX_AP; i++) { | |
17e70491 | 7032 | u16 dBm; |
1da177e4 LT |
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; | |
17e70491 | 7038 | dBm = le16_to_cpu(BSSList.dBm); |
41480af2 | 7039 | if (local->rssi) { |
17e70491 AV |
7040 | qual[i].level = 0x100 - dBm; |
7041 | qual[i].qual = airo_dbm_to_pct(local->rssi, dBm); | |
ce6623c3 JT |
7042 | qual[i].updated = IW_QUAL_QUAL_UPDATED |
7043 | | IW_QUAL_LEVEL_UPDATED | |
7044 | | IW_QUAL_DBM; | |
41480af2 | 7045 | } else { |
17e70491 | 7046 | qual[i].level = (dBm + 321) / 2; |
41480af2 | 7047 | qual[i].qual = 0; |
ce6623c3 JT |
7048 | qual[i].updated = IW_QUAL_QUAL_INVALID |
7049 | | IW_QUAL_LEVEL_UPDATED | |
7050 | | IW_QUAL_DBM; | |
41480af2 DW |
7051 | } |
7052 | qual[i].noise = local->wstats.qual.noise; | |
17e70491 | 7053 | if (BSSList.index == cpu_to_le16(0xffff)) |
1da177e4 LT |
7054 | break; |
7055 | } | |
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; | |
7077 | } | |
7078 | } else { | |
7079 | dwrq->flags = 1; /* Should be define'd */ | |
7080 | memcpy(extra + sizeof(struct sockaddr)*i, | |
7081 | &qual, sizeof(struct iw_quality)*i); | |
7082 | } | |
7083 | dwrq->length = i; | |
7084 | ||
7085 | return 0; | |
7086 | } | |
7087 | ||
7088 | /*------------------------------------------------------------------*/ | |
7089 | /* | |
7090 | * Wireless Handler : Initiate Scan | |
7091 | */ | |
7092 | static int airo_set_scan(struct net_device *dev, | |
7093 | struct iw_request_info *info, | |
9930ccee | 7094 | struct iw_point *dwrq, |
1da177e4 LT |
7095 | char *extra) |
7096 | { | |
faf3994a | 7097 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
7098 | Cmd cmd; |
7099 | Resp rsp; | |
9e75af30 | 7100 | int wake = 0; |
1da177e4 LT |
7101 | |
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; | |
7109 | ||
9e75af30 DW |
7110 | if (down_interruptible(&ai->sem)) |
7111 | return -ERESTARTSYS; | |
7112 | ||
7113 | /* If there's already a scan in progress, don't | |
7114 | * trigger another one. */ | |
7115 | if (ai->scan_timeout > 0) | |
7116 | goto out; | |
7117 | ||
1da177e4 | 7118 | /* Initiate a scan command */ |
6fcdf565 | 7119 | ai->scan_timeout = RUN_AT(3*HZ); |
1da177e4 LT |
7120 | memset(&cmd, 0, sizeof(cmd)); |
7121 | cmd.cmd=CMD_LISTBSS; | |
1da177e4 | 7122 | issuecommand(ai, &cmd, &rsp); |
9e75af30 | 7123 | wake = 1; |
1da177e4 | 7124 | |
9e75af30 DW |
7125 | out: |
7126 | up(&ai->sem); | |
7127 | if (wake) | |
7128 | wake_up_interruptible(&ai->thr_wait); | |
1da177e4 LT |
7129 | return 0; |
7130 | } | |
7131 | ||
7132 | /*------------------------------------------------------------------*/ | |
7133 | /* | |
7134 | * Translate scan data returned from the card to a card independent | |
7135 | * format that the Wireless Tools will understand - Jean II | |
7136 | */ | |
7137 | static inline char *airo_translate_scan(struct net_device *dev, | |
ccc58057 | 7138 | struct iw_request_info *info, |
1da177e4 LT |
7139 | char *current_ev, |
7140 | char *end_buf, | |
41480af2 | 7141 | BSSListRid *bss) |
1da177e4 | 7142 | { |
faf3994a | 7143 | struct airo_info *ai = dev->ml_priv; |
1da177e4 | 7144 | struct iw_event iwe; /* Temporary buffer */ |
17e70491 | 7145 | __le16 capabilities; |
1da177e4 LT |
7146 | char * current_val; /* For rates */ |
7147 | int i; | |
3c304956 | 7148 | char * buf; |
851b3e5e | 7149 | u16 dBm; |
1da177e4 LT |
7150 | |
7151 | /* First entry *MUST* be the AP MAC address */ | |
7152 | iwe.cmd = SIOCGIWAP; | |
7153 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | |
41480af2 | 7154 | memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN); |
ccc58057 DM |
7155 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, |
7156 | &iwe, IW_EV_ADDR_LEN); | |
1da177e4 LT |
7157 | |
7158 | /* Other entries will be displayed in the order we give them */ | |
7159 | ||
7160 | /* Add the ESSID */ | |
41480af2 | 7161 | iwe.u.data.length = bss->ssidLen; |
1da177e4 LT |
7162 | if(iwe.u.data.length > 32) |
7163 | iwe.u.data.length = 32; | |
7164 | iwe.cmd = SIOCGIWESSID; | |
7165 | iwe.u.data.flags = 1; | |
ccc58057 DM |
7166 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
7167 | &iwe, bss->ssid); | |
1da177e4 LT |
7168 | |
7169 | /* Add mode */ | |
7170 | iwe.cmd = SIOCGIWMODE; | |
17e70491 | 7171 | capabilities = bss->cap; |
1da177e4 LT |
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; | |
ccc58057 DM |
7177 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, |
7178 | &iwe, IW_EV_UINT_LEN); | |
1da177e4 LT |
7179 | } |
7180 | ||
7181 | /* Add frequency */ | |
7182 | iwe.cmd = SIOCGIWFREQ; | |
41480af2 | 7183 | iwe.u.freq.m = le16_to_cpu(bss->dsChannel); |
9ee677c2 | 7184 | iwe.u.freq.m = ieee80211_dsss_chan_to_freq(iwe.u.freq.m) * 100000; |
1da177e4 | 7185 | iwe.u.freq.e = 1; |
ccc58057 DM |
7186 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, |
7187 | &iwe, IW_EV_FREQ_LEN); | |
1da177e4 | 7188 | |
851b3e5e AV |
7189 | dBm = le16_to_cpu(bss->dBm); |
7190 | ||
1da177e4 LT |
7191 | /* Add quality statistics */ |
7192 | iwe.cmd = IWEVQUAL; | |
41480af2 | 7193 | if (ai->rssi) { |
851b3e5e AV |
7194 | iwe.u.qual.level = 0x100 - dBm; |
7195 | iwe.u.qual.qual = airo_dbm_to_pct(ai->rssi, dBm); | |
ce6623c3 JT |
7196 | iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED |
7197 | | IW_QUAL_LEVEL_UPDATED | |
7198 | | IW_QUAL_DBM; | |
41480af2 | 7199 | } else { |
851b3e5e | 7200 | iwe.u.qual.level = (dBm + 321) / 2; |
41480af2 | 7201 | iwe.u.qual.qual = 0; |
bbeec90b | 7202 | iwe.u.qual.updated = IW_QUAL_QUAL_INVALID |
ce6623c3 JT |
7203 | | IW_QUAL_LEVEL_UPDATED |
7204 | | IW_QUAL_DBM; | |
41480af2 DW |
7205 | } |
7206 | iwe.u.qual.noise = ai->wstats.qual.noise; | |
ccc58057 DM |
7207 | current_ev = iwe_stream_add_event(info, current_ev, end_buf, |
7208 | &iwe, IW_EV_QUAL_LEN); | |
1da177e4 LT |
7209 | |
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; | |
ccc58057 DM |
7217 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
7218 | &iwe, bss->ssid); | |
1da177e4 LT |
7219 | |
7220 | /* Rate : stuffing multiple values in a single event require a bit | |
7221 | * more of magic - Jean II */ | |
ccc58057 | 7222 | current_val = current_ev + iwe_stream_lcp_len(info); |
1da177e4 LT |
7223 | |
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 */ | |
41480af2 | 7230 | if(bss->rates[i] == 0) |
1da177e4 LT |
7231 | break; |
7232 | /* Bit rate given in 500 kb/s units (+ 0x80) */ | |
41480af2 | 7233 | iwe.u.bitrate.value = ((bss->rates[i] & 0x7f) * 500000); |
1da177e4 | 7234 | /* Add new value to event */ |
ccc58057 DM |
7235 | current_val = iwe_stream_add_value(info, current_ev, |
7236 | current_val, end_buf, | |
7237 | &iwe, IW_EV_PARAM_LEN); | |
1da177e4 LT |
7238 | } |
7239 | /* Check if we added any event */ | |
ccc58057 | 7240 | if ((current_val - current_ev) > iwe_stream_lcp_len(info)) |
1da177e4 LT |
7241 | current_ev = current_val; |
7242 | ||
3c304956 DW |
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); | |
ccc58057 DM |
7249 | current_ev = iwe_stream_add_point(info, current_ev, end_buf, |
7250 | &iwe, buf); | |
3c304956 DW |
7251 | kfree(buf); |
7252 | } | |
7253 | ||
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); | |
2c706002 | 7258 | u8 *ie = (void *)&bss->extra.iep; |
3c304956 | 7259 | |
2c706002 JB |
7260 | while ((length >= 2) && (num_null_ies < 2)) { |
7261 | if (2 + ie[1] > length) { | |
3c304956 DW |
7262 | /* Invalid element, don't continue parsing IE */ |
7263 | break; | |
7264 | } | |
7265 | ||
2c706002 JB |
7266 | switch (ie[0]) { |
7267 | case WLAN_EID_SSID: | |
3c304956 DW |
7268 | /* Two zero-length SSID elements |
7269 | * mean we're done parsing elements */ | |
2c706002 | 7270 | if (!ie[1]) |
3c304956 DW |
7271 | num_null_ies++; |
7272 | break; | |
7273 | ||
2c706002 JB |
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) { | |
3c304956 | 7280 | iwe.cmd = IWEVGENIE; |
2c706002 JB |
7281 | /* 64 is an arbitrary cut-off */ |
7282 | iwe.u.data.length = min(ie[1] + 2, | |
7283 | 64); | |
ccc58057 DM |
7284 | current_ev = iwe_stream_add_point( |
7285 | info, current_ev, | |
2c706002 | 7286 | end_buf, &iwe, ie); |
3c304956 DW |
7287 | } |
7288 | break; | |
7289 | ||
2c706002 | 7290 | case WLAN_EID_RSN: |
3c304956 | 7291 | iwe.cmd = IWEVGENIE; |
2c706002 JB |
7292 | /* 64 is an arbitrary cut-off */ |
7293 | iwe.u.data.length = min(ie[1] + 2, 64); | |
ccc58057 DM |
7294 | current_ev = iwe_stream_add_point( |
7295 | info, current_ev, end_buf, | |
2c706002 | 7296 | &iwe, ie); |
3c304956 DW |
7297 | break; |
7298 | ||
7299 | default: | |
7300 | break; | |
7301 | } | |
7302 | ||
2c706002 JB |
7303 | length -= 2 + ie[1]; |
7304 | ie += 2 + ie[1]; | |
3c304956 DW |
7305 | } |
7306 | } | |
1da177e4 LT |
7307 | return current_ev; |
7308 | } | |
7309 | ||
7310 | /*------------------------------------------------------------------*/ | |
7311 | /* | |
7312 | * Wireless Handler : Read Scan Results | |
7313 | */ | |
7314 | static int airo_get_scan(struct net_device *dev, | |
7315 | struct iw_request_info *info, | |
7316 | struct iw_point *dwrq, | |
7317 | char *extra) | |
7318 | { | |
faf3994a | 7319 | struct airo_info *ai = dev->ml_priv; |
9e75af30 DW |
7320 | BSSListElement *net; |
7321 | int err = 0; | |
1da177e4 LT |
7322 | char *current_ev = extra; |
7323 | ||
9e75af30 DW |
7324 | /* If a scan is in-progress, return -EAGAIN */ |
7325 | if (ai->scan_timeout > 0) | |
1da177e4 | 7326 | return -EAGAIN; |
1da177e4 | 7327 | |
9e75af30 DW |
7328 | if (down_interruptible(&ai->sem)) |
7329 | return -EAGAIN; | |
1da177e4 | 7330 | |
9e75af30 | 7331 | list_for_each_entry (net, &ai->network_list, list) { |
1da177e4 | 7332 | /* Translate to WE format this entry */ |
ccc58057 | 7333 | current_ev = airo_translate_scan(dev, info, current_ev, |
1da177e4 | 7334 | extra + dwrq->length, |
9e75af30 | 7335 | &net->bss); |
1da177e4 LT |
7336 | |
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 */ | |
9e75af30 DW |
7340 | err = -E2BIG; |
7341 | goto out; | |
1da177e4 | 7342 | } |
1da177e4 | 7343 | } |
9e75af30 | 7344 | |
1da177e4 LT |
7345 | /* Length of data */ |
7346 | dwrq->length = (current_ev - extra); | |
7347 | dwrq->flags = 0; /* todo */ | |
7348 | ||
9e75af30 DW |
7349 | out: |
7350 | up(&ai->sem); | |
7351 | return err; | |
1da177e4 LT |
7352 | } |
7353 | ||
7354 | /*------------------------------------------------------------------*/ | |
7355 | /* | |
7356 | * Commit handler : called after a bunch of SET operations | |
7357 | */ | |
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 */ | |
7362 | { | |
faf3994a | 7363 | struct airo_info *local = dev->ml_priv; |
1da177e4 LT |
7364 | |
7365 | if (!test_bit (FLAG_COMMIT, &local->flags)) | |
7366 | return 0; | |
7367 | ||
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; | |
7374 | ||
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); | |
7384 | } | |
7385 | if (down_interruptible(&local->sem)) | |
7386 | return -ERESTARTSYS; | |
7387 | writeConfigRid(local, 0); | |
175ec1a1 | 7388 | enable_MAC(local, 0); |
1da177e4 LT |
7389 | if (test_bit (FLAG_RESET, &local->flags)) |
7390 | airo_set_promisc(local); | |
7391 | else | |
7392 | up(&local->sem); | |
7393 | ||
7394 | return 0; | |
7395 | } | |
7396 | ||
7397 | /*------------------------------------------------------------------*/ | |
7398 | /* | |
7399 | * Structures to export the Wireless Handlers | |
7400 | */ | |
7401 | ||
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" }, | |
7408 | }; | |
7409 | ||
7410 | static const iw_handler airo_handler[] = | |
7411 | { | |
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 */ | |
4be757dd DW |
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 */ | |
1da177e4 LT |
7467 | }; |
7468 | ||
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[] = | |
7477 | { | |
7478 | NULL, /* SIOCIWFIRSTPRIV */ | |
7479 | }; | |
7480 | ||
7481 | static const struct iw_handler_def airo_handler_def = | |
7482 | { | |
ff8ac609 DC |
7483 | .num_standard = ARRAY_SIZE(airo_handler), |
7484 | .num_private = ARRAY_SIZE(airo_private_handler), | |
7485 | .num_private_args = ARRAY_SIZE(airo_private_args), | |
1da177e4 LT |
7486 | .standard = airo_handler, |
7487 | .private = airo_private_handler, | |
7488 | .private_args = airo_private_args, | |
7489 | .get_wireless_stats = airo_get_wireless_stats, | |
7490 | }; | |
7491 | ||
1da177e4 LT |
7492 | /* |
7493 | * This defines the configuration part of the Wireless Extensions | |
7494 | * Note : irq and spinlock protection will occur in the subroutines | |
7495 | * | |
7496 | * TODO : | |
7497 | * o Check input value more carefully and fill correct values in range | |
7498 | * o Test and shakeout the bugs (if any) | |
7499 | * | |
7500 | * Jean II | |
7501 | * | |
7502 | * Javier Achirica did a great job of merging code from the unnamed CISCO | |
7503 | * developer that added support for flashing the card. | |
7504 | */ | |
7505 | static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) | |
7506 | { | |
7507 | int rc = 0; | |
faf3994a | 7508 | struct airo_info *ai = dev->ml_priv; |
1da177e4 | 7509 | |
ca078bae | 7510 | if (ai->power.event) |
1da177e4 LT |
7511 | return 0; |
7512 | ||
7513 | switch (cmd) { | |
7514 | #ifdef CISCO_EXT | |
7515 | case AIROIDIFC: | |
7516 | #ifdef AIROOLDIDIFC | |
7517 | case AIROOLDIDIFC: | |
7518 | #endif | |
7519 | { | |
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; | |
7526 | } | |
7527 | break; | |
7528 | ||
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 | |
7535 | */ | |
7536 | { | |
7537 | aironet_ioctl com; | |
7538 | if (copy_from_user(&com,rq->ifr_data,sizeof(com))) { | |
7539 | rc = -EFAULT; | |
7540 | break; | |
7541 | } | |
7542 | ||
7543 | /* Separate R/W functions bracket legality here | |
7544 | */ | |
7545 | if ( com.command == AIRORSWVERSION ) { | |
7546 | if (copy_to_user(com.data, swversion, sizeof(swversion))) | |
7547 | rc = -EFAULT; | |
7548 | else | |
7549 | rc = 0; | |
7550 | } | |
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 */ | |
7559 | } | |
7560 | break; | |
7561 | #endif /* CISCO_EXT */ | |
7562 | ||
7563 | // All other calls are currently unsupported | |
7564 | default: | |
7565 | rc = -EOPNOTSUPP; | |
7566 | } | |
7567 | return rc; | |
7568 | } | |
7569 | ||
1da177e4 LT |
7570 | /* |
7571 | * Get the Wireless stats out of the driver | |
7572 | * Note : irq and spinlock protection will occur in the subroutines | |
7573 | * | |
7574 | * TODO : | |
7575 | * o Check if work in Ad-Hoc mode (otherwise, use SPY, as in wvlan_cs) | |
7576 | * | |
7577 | * Jean | |
7578 | */ | |
7579 | static void airo_read_wireless_stats(struct airo_info *local) | |
7580 | { | |
7581 | StatusRid status_rid; | |
7582 | StatsRid stats_rid; | |
7583 | CapabilityRid cap_rid; | |
a23ace5f | 7584 | __le32 *vals = stats_rid.vals; |
1da177e4 LT |
7585 | |
7586 | /* Get stats out of the card */ | |
3c304956 | 7587 | clear_bit(JOB_WSTATS, &local->jobs); |
ca078bae | 7588 | if (local->power.event) { |
1da177e4 LT |
7589 | up(&local->sem); |
7590 | return; | |
7591 | } | |
7592 | readCapabilityRid(local, &cap_rid, 0); | |
7593 | readStatusRid(local, &status_rid, 0); | |
7594 | readStatsRid(local, &stats_rid, RID_STATS, 0); | |
7595 | up(&local->sem); | |
7596 | ||
7597 | /* The status */ | |
329e2c00 | 7598 | local->wstats.status = le16_to_cpu(status_rid.mode); |
1da177e4 | 7599 | |
41480af2 DW |
7600 | /* Signal quality and co */ |
7601 | if (local->rssi) { | |
329e2c00 AV |
7602 | local->wstats.qual.level = |
7603 | airo_rssi_to_dbm(local->rssi, | |
7604 | le16_to_cpu(status_rid.sigQuality)); | |
41480af2 | 7605 | /* normalizedSignalStrength appears to be a percentage */ |
329e2c00 AV |
7606 | local->wstats.qual.qual = |
7607 | le16_to_cpu(status_rid.normalizedSignalStrength); | |
41480af2 | 7608 | } else { |
329e2c00 AV |
7609 | local->wstats.qual.level = |
7610 | (le16_to_cpu(status_rid.normalizedSignalStrength) + 321) / 2; | |
41480af2 DW |
7611 | local->wstats.qual.qual = airo_get_quality(&status_rid, &cap_rid); |
7612 | } | |
329e2c00 | 7613 | if (le16_to_cpu(status_rid.len) >= 124) { |
41480af2 | 7614 | local->wstats.qual.noise = 0x100 - status_rid.noisedBm; |
ce6623c3 | 7615 | local->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; |
1da177e4 LT |
7616 | } else { |
7617 | local->wstats.qual.noise = 0; | |
ce6623c3 | 7618 | local->wstats.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_INVALID | IW_QUAL_DBM; |
1da177e4 LT |
7619 | } |
7620 | ||
7621 | /* Packets discarded in the wireless adapter due to wireless | |
7622 | * specific problems */ | |
a23ace5f AV |
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]); | |
1da177e4 LT |
7632 | } |
7633 | ||
ff1d2767 | 7634 | static struct iw_statistics *airo_get_wireless_stats(struct net_device *dev) |
1da177e4 | 7635 | { |
faf3994a | 7636 | struct airo_info *local = dev->ml_priv; |
1da177e4 | 7637 | |
3c304956 | 7638 | if (!test_bit(JOB_WSTATS, &local->jobs)) { |
1da177e4 LT |
7639 | /* Get stats out of the card if available */ |
7640 | if (down_trylock(&local->sem) != 0) { | |
3c304956 | 7641 | set_bit(JOB_WSTATS, &local->jobs); |
1da177e4 LT |
7642 | wake_up_interruptible(&local->thr_wait); |
7643 | } else | |
7644 | airo_read_wireless_stats(local); | |
7645 | } | |
7646 | ||
7647 | return &local->wstats; | |
7648 | } | |
1da177e4 LT |
7649 | |
7650 | #ifdef CISCO_EXT | |
7651 | /* | |
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 | |
7656 | */ | |
7657 | static int readrids(struct net_device *dev, aironet_ioctl *comp) { | |
7658 | unsigned short ridcode; | |
7659 | unsigned char *iobuf; | |
7660 | int len; | |
faf3994a | 7661 | struct airo_info *ai = dev->ml_priv; |
1da177e4 LT |
7662 | |
7663 | if (test_bit(FLAG_FLASHING, &ai->flags)) | |
7664 | return -EIO; | |
7665 | ||
7666 | switch(comp->command) | |
7667 | { | |
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); | |
175ec1a1 | 7673 | enable_MAC(ai, 1); |
1da177e4 LT |
7674 | } |
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; | |
1da177e4 LT |
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; | |
1da177e4 LT |
7698 | case AIRORRID: ridcode = comp->ridnum; break; |
7699 | default: | |
7700 | return -EINVAL; | |
7701 | break; | |
7702 | } | |
7703 | ||
7704 | if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL) | |
7705 | return -ENOMEM; | |
7706 | ||
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 | |
7711 | */ | |
7712 | len = comp->len; | |
7713 | ||
7714 | if (copy_to_user(comp->data, iobuf, min(len, (int)RIDSIZE))) { | |
7715 | kfree (iobuf); | |
7716 | return -EFAULT; | |
7717 | } | |
7718 | kfree (iobuf); | |
7719 | return 0; | |
7720 | } | |
7721 | ||
7722 | /* | |
7723 | * Danger Will Robinson write the rids here | |
7724 | */ | |
7725 | ||
7726 | static int writerids(struct net_device *dev, aironet_ioctl *comp) { | |
faf3994a | 7727 | struct airo_info *ai = dev->ml_priv; |
1da177e4 | 7728 | int ridcode; |
1da177e4 | 7729 | int enabled; |
1da177e4 LT |
7730 | static int (* writer)(struct airo_info *, u16 rid, const void *, int, int); |
7731 | unsigned char *iobuf; | |
7732 | ||
7733 | /* Only super-user can write RIDs */ | |
7734 | if (!capable(CAP_NET_ADMIN)) | |
7735 | return -EPERM; | |
7736 | ||
7737 | if (test_bit(FLAG_FLASHING, &ai->flags)) | |
7738 | return -EIO; | |
7739 | ||
7740 | ridcode = 0; | |
7741 | writer = do_writerid; | |
7742 | ||
7743 | switch(comp->command) | |
7744 | { | |
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; | |
7758 | ||
7759 | /* this is not really a rid but a command given to the card | |
7760 | * same with MAC off | |
7761 | */ | |
7762 | case AIROPMACON: | |
175ec1a1 | 7763 | if (enable_MAC(ai, 1) != 0) |
1da177e4 LT |
7764 | return -EIO; |
7765 | return 0; | |
7766 | ||
7767 | /* | |
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. | |
7770 | */ | |
7771 | case AIROPMACOFF: | |
7772 | disable_MAC(ai, 1); | |
7773 | return 0; | |
7774 | ||
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. | |
7778 | */ | |
7779 | case AIROPSTCLR: | |
7780 | if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL) | |
7781 | return -ENOMEM; | |
7782 | ||
7783 | PC4500_readrid(ai,RID_STATSDELTACLEAR,iobuf,RIDSIZE, 1); | |
7784 | ||
1da177e4 LT |
7785 | enabled = ai->micstats.enabled; |
7786 | memset(&ai->micstats,0,sizeof(ai->micstats)); | |
7787 | ai->micstats.enabled = enabled; | |
1da177e4 LT |
7788 | |
7789 | if (copy_to_user(comp->data, iobuf, | |
7790 | min((int)comp->len, (int)RIDSIZE))) { | |
7791 | kfree (iobuf); | |
7792 | return -EFAULT; | |
7793 | } | |
7794 | kfree (iobuf); | |
7795 | return 0; | |
7796 | ||
7797 | default: | |
7798 | return -EOPNOTSUPP; /* Blarg! */ | |
7799 | } | |
7800 | if(comp->len > RIDSIZE) | |
7801 | return -EINVAL; | |
7802 | ||
7803 | if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL) | |
7804 | return -ENOMEM; | |
7805 | ||
7806 | if (copy_from_user(iobuf,comp->data,comp->len)) { | |
7807 | kfree (iobuf); | |
7808 | return -EFAULT; | |
7809 | } | |
7810 | ||
7811 | if (comp->command == AIROPCFG) { | |
7812 | ConfigRid *cfg = (ConfigRid *)iobuf; | |
7813 | ||
7814 | if (test_bit(FLAG_MIC_CAPABLE, &ai->flags)) | |
3eb9b41f | 7815 | cfg->opmode |= MODE_MIC; |
1da177e4 | 7816 | |
3eb9b41f | 7817 | if ((cfg->opmode & MODE_CFG_MASK) == MODE_STA_IBSS) |
1da177e4 LT |
7818 | set_bit (FLAG_ADHOC, &ai->flags); |
7819 | else | |
7820 | clear_bit (FLAG_ADHOC, &ai->flags); | |
7821 | } | |
7822 | ||
7823 | if((*writer)(ai, ridcode, iobuf,comp->len,1)) { | |
7824 | kfree (iobuf); | |
7825 | return -EIO; | |
7826 | } | |
7827 | kfree (iobuf); | |
7828 | return 0; | |
7829 | } | |
7830 | ||
7831 | /***************************************************************************** | |
7832 | * Ancillary flash / mod functions much black magic lurkes here * | |
7833 | ***************************************************************************** | |
7834 | */ | |
7835 | ||
7836 | /* | |
7837 | * Flash command switch table | |
7838 | */ | |
7839 | ||
ff1d2767 | 7840 | static int flashcard(struct net_device *dev, aironet_ioctl *comp) { |
1da177e4 | 7841 | int z; |
1da177e4 LT |
7842 | |
7843 | /* Only super-user can modify flash */ | |
7844 | if (!capable(CAP_NET_ADMIN)) | |
7845 | return -EPERM; | |
7846 | ||
7847 | switch(comp->command) | |
7848 | { | |
7849 | case AIROFLSHRST: | |
faf3994a | 7850 | return cmdreset((struct airo_info *)dev->ml_priv); |
1da177e4 LT |
7851 | |
7852 | case AIROFLSHSTFL: | |
faf3994a WC |
7853 | if (!AIRO_FLASH(dev) && |
7854 | (AIRO_FLASH(dev) = kmalloc(FLASHSIZE, GFP_KERNEL)) == NULL) | |
1da177e4 | 7855 | return -ENOMEM; |
faf3994a | 7856 | return setflashmode((struct airo_info *)dev->ml_priv); |
1da177e4 LT |
7857 | |
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; | |
faf3994a | 7863 | return flashgchar((struct airo_info *)dev->ml_priv, z, 8000); |
1da177e4 LT |
7864 | |
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; | |
faf3994a | 7870 | return flashpchar((struct airo_info *)dev->ml_priv, z, 8000); |
1da177e4 LT |
7871 | |
7872 | case AIROFLPUTBUF: /* Send 32k to card */ | |
faf3994a | 7873 | if (!AIRO_FLASH(dev)) |
1da177e4 LT |
7874 | return -ENOMEM; |
7875 | if(comp->len > FLASHSIZE) | |
7876 | return -EINVAL; | |
faf3994a | 7877 | if (copy_from_user(AIRO_FLASH(dev), comp->data, comp->len)) |
1da177e4 LT |
7878 | return -EFAULT; |
7879 | ||
faf3994a | 7880 | flashputbuf((struct airo_info *)dev->ml_priv); |
1da177e4 LT |
7881 | return 0; |
7882 | ||
7883 | case AIRORESTART: | |
faf3994a | 7884 | if (flashrestart((struct airo_info *)dev->ml_priv, dev)) |
1da177e4 LT |
7885 | return -EIO; |
7886 | return 0; | |
7887 | } | |
7888 | return -EINVAL; | |
7889 | } | |
7890 | ||
7891 | #define FLASH_COMMAND 0x7e7e | |
7892 | ||
7893 | /* | |
7894 | * STEP 1) | |
7895 | * Disable MAC and do soft reset on | |
7896 | * card. | |
7897 | */ | |
7898 | ||
ff1d2767 | 7899 | static int cmdreset(struct airo_info *ai) { |
1da177e4 LT |
7900 | disable_MAC(ai, 1); |
7901 | ||
7902 | if(!waitbusy (ai)){ | |
934d8bf1 | 7903 | airo_print_info(ai->dev->name, "Waitbusy hang before RESET"); |
1da177e4 LT |
7904 | return -EBUSY; |
7905 | } | |
7906 | ||
7907 | OUT4500(ai,COMMAND,CMD_SOFTRESET); | |
7908 | ||
7909 | ssleep(1); /* WAS 600 12/7/00 */ | |
7910 | ||
7911 | if(!waitbusy (ai)){ | |
934d8bf1 | 7912 | airo_print_info(ai->dev->name, "Waitbusy hang AFTER RESET"); |
1da177e4 LT |
7913 | return -EBUSY; |
7914 | } | |
7915 | return 0; | |
7916 | } | |
7917 | ||
7918 | /* STEP 2) | |
7919 | * Put the card in legendary flash | |
7920 | * mode | |
7921 | */ | |
7922 | ||
ff1d2767 | 7923 | static int setflashmode (struct airo_info *ai) { |
1da177e4 LT |
7924 | set_bit (FLAG_FLASHING, &ai->flags); |
7925 | ||
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); | |
7935 | } | |
7936 | msleep(500); /* 500ms delay */ | |
7937 | ||
7938 | if(!waitbusy(ai)) { | |
7939 | clear_bit (FLAG_FLASHING, &ai->flags); | |
934d8bf1 | 7940 | airo_print_info(ai->dev->name, "Waitbusy hang after setflash mode"); |
1da177e4 LT |
7941 | return -EIO; |
7942 | } | |
7943 | return 0; | |
7944 | } | |
7945 | ||
7946 | /* Put character to SWS0 wait for dwelltime | |
7947 | * x 50us for echo . | |
7948 | */ | |
7949 | ||
ff1d2767 | 7950 | static int flashpchar(struct airo_info *ai,int byte,int dwelltime) { |
1da177e4 LT |
7951 | int echo; |
7952 | int waittime; | |
7953 | ||
7954 | byte |= 0x8000; | |
7955 | ||
7956 | if(dwelltime == 0 ) | |
7957 | dwelltime = 200; | |
7958 | ||
7959 | waittime=dwelltime; | |
7960 | ||
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; | |
7965 | } | |
7966 | ||
7967 | /* timeout for busy clear wait */ | |
7968 | if(waittime <= 0 ){ | |
934d8bf1 | 7969 | airo_print_info(ai->dev->name, "flash putchar busywait timeout!"); |
1da177e4 LT |
7970 | return -EBUSY; |
7971 | } | |
7972 | ||
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); | |
7980 | ||
7981 | OUT4500(ai,SWS1,0); | |
7982 | ||
7983 | return (echo == byte) ? 0 : -EIO; | |
7984 | } | |
7985 | ||
7986 | /* | |
7987 | * Get a character from the card matching matchbyte | |
7988 | * Step 3) | |
7989 | */ | |
ff1d2767 | 7990 | static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime){ |
1da177e4 LT |
7991 | int rchar; |
7992 | unsigned char rbyte=0; | |
7993 | ||
7994 | do { | |
7995 | rchar = IN4500(ai,SWS1); | |
7996 | ||
7997 | if(dwelltime && !(0x8000 & rchar)){ | |
7998 | dwelltime -= 10; | |
7999 | mdelay(10); | |
8000 | continue; | |
8001 | } | |
8002 | rbyte = 0xff & rchar; | |
8003 | ||
8004 | if( (rbyte == matchbyte) && (0x8000 & rchar) ){ | |
8005 | OUT4500(ai,SWS1,0); | |
8006 | return 0; | |
8007 | } | |
8008 | if( rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar) | |
8009 | break; | |
8010 | OUT4500(ai,SWS1,0); | |
8011 | ||
8012 | }while(dwelltime > 0); | |
8013 | return -EIO; | |
8014 | } | |
8015 | ||
8016 | /* | |
8017 | * Transfer 32k of firmware data from user buffer to our buffer and | |
8018 | * send to the card | |
8019 | */ | |
8020 | ||
ff1d2767 | 8021 | static int flashputbuf(struct airo_info *ai){ |
1da177e4 LT |
8022 | int nwords; |
8023 | ||
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); | |
8030 | ||
8031 | for(nwords=0;nwords != FLASHSIZE / 2;nwords++){ | |
8032 | OUT4500(ai,AUXDATA,ai->flash[nwords] & 0xffff); | |
8033 | } | |
8034 | } | |
8035 | OUT4500(ai,SWS0,0x8000); | |
8036 | ||
8037 | return 0; | |
8038 | } | |
8039 | ||
8040 | /* | |
8041 | * | |
8042 | */ | |
ff1d2767 | 8043 | static int flashrestart(struct airo_info *ai,struct net_device *dev){ |
1da177e4 LT |
8044 | int i,status; |
8045 | ||
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; | |
8052 | } | |
8053 | status = setup_card(ai, dev->dev_addr, 1); | |
8054 | ||
8055 | if (!test_bit(FLAG_MPI,&ai->flags)) | |
8056 | for( i = 0; i < MAX_FIDS; i++ ) { | |
8057 | ai->fids[i] = transmit_allocate | |
15db2763 | 8058 | ( ai, AIRO_DEF_MTU, i >= MAX_FIDS / 2 ); |
1da177e4 LT |
8059 | } |
8060 | ||
8061 | ssleep(1); /* Added 12/7/00 */ | |
8062 | return status; | |
8063 | } | |
8064 | #endif /* CISCO_EXT */ | |
8065 | ||
8066 | /* | |
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. | |
8071 | ||
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. | |
8076 | ||
8077 | In addition: | |
8078 | ||
8079 | Redistribution and use in source and binary forms, with or without | |
8080 | modification, are permitted provided that the following conditions | |
8081 | are met: | |
8082 | ||
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. | |
8091 | ||
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. | |
8103 | */ | |
8104 | ||
8105 | module_init(airo_init_module); | |
8106 | module_exit(airo_cleanup_module); |