1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#include <linux/err.h>
23#include <linux/init.h>
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/proc_fs.h>
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>
37#include <linux/scatterlist.h>
38#include <linux/crypto.h>
39#include <linux/io.h>
40#include <asm/unaligned.h>
41
42#include <linux/netdevice.h>
43#include <linux/etherdevice.h>
44#include <linux/skbuff.h>
45#include <linux/if_arp.h>
46#include <linux/ioport.h>
47#include <linux/pci.h>
48#include <linux/uaccess.h>
49#include <linux/kthread.h>
50#include <linux/freezer.h>
51
52#include <crypto/aes.h>
53#include <crypto/skcipher.h>
54
55#include <net/cfg80211.h>
56#include <net/iw_handler.h>
57
58#include "airo.h"
59
60#define DRV_NAME "airo"
61
62#ifdef CONFIG_PCI
63static const struct pci_device_id card_ids[] = {
64 { 0x14b9, 1, PCI_ANY_ID, PCI_ANY_ID, },
65 { 0x14b9, 0x4500, PCI_ANY_ID, PCI_ANY_ID },
66 { 0x14b9, 0x4800, PCI_ANY_ID, PCI_ANY_ID, },
67 { 0x14b9, 0x0340, PCI_ANY_ID, PCI_ANY_ID, },
68 { 0x14b9, 0x0350, PCI_ANY_ID, PCI_ANY_ID, },
69 { 0x14b9, 0x5000, PCI_ANY_ID, PCI_ANY_ID, },
70 { 0x14b9, 0xa504, PCI_ANY_ID, PCI_ANY_ID, },
71 { 0, }
72};
73MODULE_DEVICE_TABLE(pci, card_ids);
74
75static int airo_pci_probe(struct pci_dev *, const struct pci_device_id *);
76static void airo_pci_remove(struct pci_dev *);
77static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state);
78static int airo_pci_resume(struct pci_dev *pdev);
79
80static struct pci_driver airo_driver = {
81 .name = DRV_NAME,
82 .id_table = card_ids,
83 .probe = airo_pci_probe,
84 .remove = airo_pci_remove,
85 .suspend = airo_pci_suspend,
86 .resume = airo_pci_resume,
87};
88#endif
89
90
91#include <linux/wireless.h>
92#define WIRELESS_SPY
93
94#define CISCO_EXT
95#ifdef CISCO_EXT
96#include <linux/delay.h>
97#endif
98
99
100#define POWER_ON_DOWN
101
102
103
104
105
106
107
108#define IGNLABEL(comment) NULL
109static const char *statsLabels[] = {
110 "RxOverrun",
111 IGNLABEL("RxPlcpCrcErr"),
112 IGNLABEL("RxPlcpFormatErr"),
113 IGNLABEL("RxPlcpLengthErr"),
114 "RxMacCrcErr",
115 "RxMacCrcOk",
116 "RxWepErr",
117 "RxWepOk",
118 "RetryLong",
119 "RetryShort",
120 "MaxRetries",
121 "NoAck",
122 "NoCts",
123 "RxAck",
124 "RxCts",
125 "TxAck",
126 "TxRts",
127 "TxCts",
128 "TxMc",
129 "TxBc",
130 "TxUcFrags",
131 "TxUcPackets",
132 "TxBeacon",
133 "RxBeacon",
134 "TxSinColl",
135 "TxMulColl",
136 "DefersNo",
137 "DefersProt",
138 "DefersEngy",
139 "DupFram",
140 "RxFragDisc",
141 "TxAged",
142 "RxAged",
143 "LostSync-MaxRetry",
144 "LostSync-MissedBeacons",
145 "LostSync-ArlExceeded",
146 "LostSync-Deauth",
147 "LostSync-Disassoced",
148 "LostSync-TsfTiming",
149 "HostTxMc",
150 "HostTxBc",
151 "HostTxUc",
152 "HostTxFail",
153 "HostRxMc",
154 "HostRxBc",
155 "HostRxUc",
156 "HostRxDiscard",
157 IGNLABEL("HmacTxMc"),
158 IGNLABEL("HmacTxBc"),
159 IGNLABEL("HmacTxUc"),
160 IGNLABEL("HmacTxFail"),
161 IGNLABEL("HmacRxMc"),
162 IGNLABEL("HmacRxBc"),
163 IGNLABEL("HmacRxUc"),
164 IGNLABEL("HmacRxDiscard"),
165 IGNLABEL("HmacRxAccepted"),
166 "SsidMismatch",
167 "ApMismatch",
168 "RatesMismatch",
169 "AuthReject",
170 "AuthTimeout",
171 "AssocReject",
172 "AssocTimeout",
173 IGNLABEL("ReasonOutsideTable"),
174 IGNLABEL("ReasonStatus1"),
175 IGNLABEL("ReasonStatus2"),
176 IGNLABEL("ReasonStatus3"),
177 IGNLABEL("ReasonStatus4"),
178 IGNLABEL("ReasonStatus5"),
179 IGNLABEL("ReasonStatus6"),
180 IGNLABEL("ReasonStatus7"),
181 IGNLABEL("ReasonStatus8"),
182 IGNLABEL("ReasonStatus9"),
183 IGNLABEL("ReasonStatus10"),
184 IGNLABEL("ReasonStatus11"),
185 IGNLABEL("ReasonStatus12"),
186 IGNLABEL("ReasonStatus13"),
187 IGNLABEL("ReasonStatus14"),
188 IGNLABEL("ReasonStatus15"),
189 IGNLABEL("ReasonStatus16"),
190 IGNLABEL("ReasonStatus17"),
191 IGNLABEL("ReasonStatus18"),
192 IGNLABEL("ReasonStatus19"),
193 "RxMan",
194 "TxMan",
195 "RxRefresh",
196 "TxRefresh",
197 "RxPoll",
198 "TxPoll",
199 "HostRetries",
200 "LostSync-HostReq",
201 "HostTxBytes",
202 "HostRxBytes",
203 "ElapsedUsec",
204 "ElapsedSec",
205 "LostSyncBetterAP",
206 "PrivacyMismatch",
207 "Jammed",
208 "DiscRxNotWepped",
209 "PhyEleMismatch",
210 (char*)-1 };
211#ifndef RUN_AT
212#define RUN_AT(x) (jiffies+(x))
213#endif
214
215
216
217
218
219
220static int rates[8];
221static char *ssids[3];
222
223static int io[4];
224static int irq[4];
225
226static
227int maxencrypt ;
228
229
230static int auto_wep ;
231static int aux_bap ;
232
233static int adhoc;
234
235static int probe = 1;
236
237static kuid_t proc_kuid;
238static int proc_uid ;
239
240static kgid_t proc_kgid;
241static int proc_gid ;
242
243static int airo_perm = 0555;
244
245static int proc_perm = 0644;
246
247MODULE_AUTHOR("Benjamin Reed");
248MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet cards. "
249 "Direct support for ISA/PCI/MPI cards and support for PCMCIA when used with airo_cs.");
250MODULE_LICENSE("Dual BSD/GPL");
251MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340/350");
252module_param_hw_array(io, int, ioport, NULL, 0);
253module_param_hw_array(irq, int, irq, NULL, 0);
254module_param_array(rates, int, NULL, 0);
255module_param_array(ssids, charp, NULL, 0);
256module_param(auto_wep, int, 0);
257MODULE_PARM_DESC(auto_wep,
258 "If non-zero, the driver will keep looping through the authentication options until an association is made. "
259 "The value of auto_wep is number of the wep keys to check. "
260 "A value of 2 will try using the key at index 0 and index 1.");
261module_param(aux_bap, int, 0);
262MODULE_PARM_DESC(aux_bap,
263 "If non-zero, the driver will switch into a mode that seems to work better for older cards with some older buses. "
264 "Before switching it checks that the switch is needed.");
265module_param(maxencrypt, int, 0);
266MODULE_PARM_DESC(maxencrypt,
267 "The maximum speed that the card can do encryption. "
268 "Units are in 512kbs. "
269 "Zero (default) means there is no limit. "
270 "Older cards used to be limited to 2mbs (4).");
271module_param(adhoc, int, 0);
272MODULE_PARM_DESC(adhoc, "If non-zero, the card will start in adhoc mode.");
273module_param(probe, int, 0);
274MODULE_PARM_DESC(probe, "If zero, the driver won't start the card.");
275
276module_param(proc_uid, int, 0);
277MODULE_PARM_DESC(proc_uid, "The uid that the /proc files will belong to.");
278module_param(proc_gid, int, 0);
279MODULE_PARM_DESC(proc_gid, "The gid that the /proc files will belong to.");
280module_param(airo_perm, int, 0);
281MODULE_PARM_DESC(airo_perm, "The permission bits of /proc/[driver/]aironet.");
282module_param(proc_perm, int, 0);
283MODULE_PARM_DESC(proc_perm, "The permission bits of the files in /proc");
284
285
286
287
288static int do8bitIO ;
289
290
291#define SUCCESS 0
292#define ERROR -1
293#define NO_PACKET -2
294
295
296#define NOP2 0x0000
297#define MAC_ENABLE 0x0001
298#define MAC_DISABLE 0x0002
299#define CMD_LOSE_SYNC 0x0003
300#define CMD_SOFTRESET 0x0004
301#define HOSTSLEEP 0x0005
302#define CMD_MAGIC_PKT 0x0006
303#define CMD_SETWAKEMASK 0x0007
304#define CMD_READCFG 0x0008
305#define CMD_SETMODE 0x0009
306#define CMD_ALLOCATETX 0x000a
307#define CMD_TRANSMIT 0x000b
308#define CMD_DEALLOCATETX 0x000c
309#define NOP 0x0010
310#define CMD_WORKAROUND 0x0011
311#define CMD_ALLOCATEAUX 0x0020
312#define CMD_ACCESS 0x0021
313#define CMD_PCIBAP 0x0022
314#define CMD_PCIAUX 0x0023
315#define CMD_ALLOCBUF 0x0028
316#define CMD_GETTLV 0x0029
317#define CMD_PUTTLV 0x002a
318#define CMD_DELTLV 0x002b
319#define CMD_FINDNEXTTLV 0x002c
320#define CMD_PSPNODES 0x0030
321#define CMD_SETCW 0x0031
322#define CMD_SETPCF 0x0032
323#define CMD_SETPHYREG 0x003e
324#define CMD_TXTEST 0x003f
325#define MAC_ENABLETX 0x0101
326#define CMD_LISTBSS 0x0103
327#define CMD_SAVECFG 0x0108
328#define CMD_ENABLEAUX 0x0111
329#define CMD_WRITERID 0x0121
330#define CMD_USEPSPNODES 0x0130
331#define MAC_ENABLERX 0x0201
332
333
334#define ERROR_QUALIF 0x00
335#define ERROR_ILLCMD 0x01
336#define ERROR_ILLFMT 0x02
337#define ERROR_INVFID 0x03
338#define ERROR_INVRID 0x04
339#define ERROR_LARGE 0x05
340#define ERROR_NDISABL 0x06
341#define ERROR_ALLOCBSY 0x07
342#define ERROR_NORD 0x0B
343#define ERROR_NOWR 0x0C
344#define ERROR_INVFIDTX 0x0D
345#define ERROR_TESTACT 0x0E
346#define ERROR_TAGNFND 0x12
347#define ERROR_DECODE 0x20
348#define ERROR_DESCUNAV 0x21
349#define ERROR_BADLEN 0x22
350#define ERROR_MODE 0x80
351#define ERROR_HOP 0x81
352#define ERROR_BINTER 0x82
353#define ERROR_RXMODE 0x83
354#define ERROR_MACADDR 0x84
355#define ERROR_RATES 0x85
356#define ERROR_ORDER 0x86
357#define ERROR_SCAN 0x87
358#define ERROR_AUTH 0x88
359#define ERROR_PSMODE 0x89
360#define ERROR_RTYPE 0x8A
361#define ERROR_DIVER 0x8B
362#define ERROR_SSID 0x8C
363#define ERROR_APLIST 0x8D
364#define ERROR_AUTOWAKE 0x8E
365#define ERROR_LEAP 0x8F
366
367
368#define COMMAND 0x00
369#define PARAM0 0x02
370#define PARAM1 0x04
371#define PARAM2 0x06
372#define STATUS 0x08
373#define RESP0 0x0a
374#define RESP1 0x0c
375#define RESP2 0x0e
376#define LINKSTAT 0x10
377#define SELECT0 0x18
378#define OFFSET0 0x1c
379#define RXFID 0x20
380#define TXALLOCFID 0x22
381#define TXCOMPLFID 0x24
382#define DATA0 0x36
383#define EVSTAT 0x30
384#define EVINTEN 0x32
385#define EVACK 0x34
386#define SWS0 0x28
387#define SWS1 0x2a
388#define SWS2 0x2c
389#define SWS3 0x2e
390#define AUXPAGE 0x3A
391#define AUXOFF 0x3C
392#define AUXDATA 0x3E
393
394#define FID_TX 1
395#define FID_RX 2
396
397#define AUX_OFFSET 0x800
398
399#define PKTSIZE 1840
400#define RIDSIZE 2048
401
402#define MAXTXQ 64
403
404
405#define BAP0 0
406#define BAP1 2
407
408
409#define COMMAND_BUSY 0x8000
410
411#define BAP_BUSY 0x8000
412#define BAP_ERR 0x4000
413#define BAP_DONE 0x2000
414
415#define PROMISC 0xffff
416#define NOPROMISC 0x0000
417
418#define EV_CMD 0x10
419#define EV_CLEARCOMMANDBUSY 0x4000
420#define EV_RX 0x01
421#define EV_TX 0x02
422#define EV_TXEXC 0x04
423#define EV_ALLOC 0x08
424#define EV_LINK 0x80
425#define EV_AWAKE 0x100
426#define EV_TXCPY 0x400
427#define EV_UNKNOWN 0x800
428#define EV_MIC 0x1000
429#define EV_AWAKEN 0x2000
430#define STATUS_INTS (EV_AWAKE|EV_LINK|EV_TXEXC|EV_TX|EV_TXCPY|EV_RX|EV_MIC)
431
432#ifdef CHECK_UNKNOWN_INTS
433#define IGNORE_INTS ( EV_CMD | EV_UNKNOWN)
434#else
435#define IGNORE_INTS (~STATUS_INTS)
436#endif
437
438
439#define RID_RW 0x20
440
441
442#define RID_CAPABILITIES 0xFF00
443#define RID_APINFO 0xFF01
444#define RID_RADIOINFO 0xFF02
445#define RID_UNKNOWN3 0xFF03
446#define RID_RSSI 0xFF04
447#define RID_CONFIG 0xFF10
448#define RID_SSID 0xFF11
449#define RID_APLIST 0xFF12
450#define RID_DRVNAME 0xFF13
451#define RID_ETHERENCAP 0xFF14
452#define RID_WEP_TEMP 0xFF15
453#define RID_WEP_PERM 0xFF16
454#define RID_MODULATION 0xFF17
455#define RID_OPTIONS 0xFF18
456#define RID_ACTUALCONFIG 0xFF20
457#define RID_FACTORYCONFIG 0xFF21
458#define RID_UNKNOWN22 0xFF22
459#define RID_LEAPUSERNAME 0xFF23
460#define RID_LEAPPASSWORD 0xFF24
461#define RID_STATUS 0xFF50
462#define RID_BEACON_HST 0xFF51
463#define RID_BUSY_HST 0xFF52
464#define RID_RETRIES_HST 0xFF53
465#define RID_UNKNOWN54 0xFF54
466#define RID_UNKNOWN55 0xFF55
467#define RID_UNKNOWN56 0xFF56
468#define RID_MIC 0xFF57
469#define RID_STATS16 0xFF60
470#define RID_STATS16DELTA 0xFF61
471#define RID_STATS16DELTACLEAR 0xFF62
472#define RID_STATS 0xFF68
473#define RID_STATSDELTA 0xFF69
474#define RID_STATSDELTACLEAR 0xFF6A
475#define RID_ECHOTEST_RID 0xFF70
476#define RID_ECHOTEST_RESULTS 0xFF71
477#define RID_BSSLISTFIRST 0xFF72
478#define RID_BSSLISTNEXT 0xFF73
479#define RID_WPA_BSSLISTFIRST 0xFF74
480#define RID_WPA_BSSLISTNEXT 0xFF75
481
482typedef struct {
483 u16 cmd;
484 u16 parm0;
485 u16 parm1;
486 u16 parm2;
487} Cmd;
488
489typedef struct {
490 u16 status;
491 u16 rsp0;
492 u16 rsp1;
493 u16 rsp2;
494} Resp;
495
496
497
498
499
500
501
502
503
504typedef struct WepKeyRid WepKeyRid;
505struct WepKeyRid {
506 __le16 len;
507 __le16 kindex;
508 u8 mac[ETH_ALEN];
509 __le16 klen;
510 u8 key[16];
511} __packed;
512
513
514typedef struct Ssid Ssid;
515struct Ssid {
516 __le16 len;
517 u8 ssid[32];
518} __packed;
519
520typedef struct SsidRid SsidRid;
521struct SsidRid {
522 __le16 len;
523 Ssid ssids[3];
524} __packed;
525
526typedef struct ModulationRid ModulationRid;
527struct ModulationRid {
528 __le16 len;
529 __le16 modulation;
530#define MOD_DEFAULT cpu_to_le16(0)
531#define MOD_CCK cpu_to_le16(1)
532#define MOD_MOK cpu_to_le16(2)
533} __packed;
534
535typedef struct ConfigRid ConfigRid;
536struct ConfigRid {
537 __le16 len;
538 __le16 opmode;
539#define MODE_STA_IBSS cpu_to_le16(0)
540#define MODE_STA_ESS cpu_to_le16(1)
541#define MODE_AP cpu_to_le16(2)
542#define MODE_AP_RPTR cpu_to_le16(3)
543#define MODE_CFG_MASK cpu_to_le16(0xff)
544#define MODE_ETHERNET_HOST cpu_to_le16(0<<8)
545#define MODE_LLC_HOST cpu_to_le16(1<<8)
546#define MODE_AIRONET_EXTEND cpu_to_le16(1<<9)
547#define MODE_AP_INTERFACE cpu_to_le16(1<<10)
548#define MODE_ANTENNA_ALIGN cpu_to_le16(1<<11)
549#define MODE_ETHER_LLC cpu_to_le16(1<<12)
550#define MODE_LEAF_NODE cpu_to_le16(1<<13)
551#define MODE_CF_POLLABLE cpu_to_le16(1<<14)
552#define MODE_MIC cpu_to_le16(1<<15)
553 __le16 rmode;
554#define RXMODE_BC_MC_ADDR cpu_to_le16(0)
555#define RXMODE_BC_ADDR cpu_to_le16(1)
556#define RXMODE_ADDR cpu_to_le16(2)
557#define RXMODE_RFMON cpu_to_le16(3)
558#define RXMODE_RFMON_ANYBSS cpu_to_le16(4)
559#define RXMODE_LANMON cpu_to_le16(5)
560#define RXMODE_MASK cpu_to_le16(255)
561#define RXMODE_DISABLE_802_3_HEADER cpu_to_le16(1<<8)
562#define RXMODE_FULL_MASK (RXMODE_MASK | RXMODE_DISABLE_802_3_HEADER)
563#define RXMODE_NORMALIZED_RSSI cpu_to_le16(1<<9)
564 __le16 fragThresh;
565 __le16 rtsThres;
566 u8 macAddr[ETH_ALEN];
567 u8 rates[8];
568 __le16 shortRetryLimit;
569 __le16 longRetryLimit;
570 __le16 txLifetime;
571 __le16 rxLifetime;
572 __le16 stationary;
573 __le16 ordering;
574 __le16 u16deviceType;
575 __le16 cfpRate;
576 __le16 cfpDuration;
577 __le16 _reserved1[3];
578
579 __le16 scanMode;
580#define SCANMODE_ACTIVE cpu_to_le16(0)
581#define SCANMODE_PASSIVE cpu_to_le16(1)
582#define SCANMODE_AIROSCAN cpu_to_le16(2)
583 __le16 probeDelay;
584 __le16 probeEnergyTimeout;
585 __le16 probeResponseTimeout;
586 __le16 beaconListenTimeout;
587 __le16 joinNetTimeout;
588 __le16 authTimeout;
589 __le16 authType;
590#define AUTH_OPEN cpu_to_le16(0x1)
591#define AUTH_ENCRYPT cpu_to_le16(0x101)
592#define AUTH_SHAREDKEY cpu_to_le16(0x102)
593#define AUTH_ALLOW_UNENCRYPTED cpu_to_le16(0x200)
594 __le16 associationTimeout;
595 __le16 specifiedApTimeout;
596 __le16 offlineScanInterval;
597 __le16 offlineScanDuration;
598 __le16 linkLossDelay;
599 __le16 maxBeaconLostTime;
600 __le16 refreshInterval;
601#define DISABLE_REFRESH cpu_to_le16(0xFFFF)
602 __le16 _reserved1a[1];
603
604 __le16 powerSaveMode;
605#define POWERSAVE_CAM cpu_to_le16(0)
606#define POWERSAVE_PSP cpu_to_le16(1)
607#define POWERSAVE_PSPCAM cpu_to_le16(2)
608 __le16 sleepForDtims;
609 __le16 listenInterval;
610 __le16 fastListenInterval;
611 __le16 listenDecay;
612 __le16 fastListenDelay;
613 __le16 _reserved2[2];
614
615 __le16 beaconPeriod;
616 __le16 atimDuration;
617 __le16 hopPeriod;
618 __le16 channelSet;
619 __le16 channel;
620 __le16 dtimPeriod;
621 __le16 bridgeDistance;
622 __le16 radioID;
623
624 __le16 radioType;
625#define RADIOTYPE_DEFAULT cpu_to_le16(0)
626#define RADIOTYPE_802_11 cpu_to_le16(1)
627#define RADIOTYPE_LEGACY cpu_to_le16(2)
628 u8 rxDiversity;
629 u8 txDiversity;
630 __le16 txPower;
631#define TXPOWER_DEFAULT 0
632 __le16 rssiThreshold;
633#define RSSI_DEFAULT 0
634 __le16 modulation;
635#define PREAMBLE_AUTO cpu_to_le16(0)
636#define PREAMBLE_LONG cpu_to_le16(1)
637#define PREAMBLE_SHORT cpu_to_le16(2)
638 __le16 preamble;
639 __le16 homeProduct;
640 __le16 radioSpecific;
641
642 u8 nodeName[16];
643 __le16 arlThreshold;
644 __le16 arlDecay;
645 __le16 arlDelay;
646 __le16 _reserved4[1];
647
648 u8 magicAction;
649#define MAGIC_ACTION_STSCHG 1
650#define MAGIC_ACTION_RESUME 2
651#define MAGIC_IGNORE_MCAST (1<<8)
652#define MAGIC_IGNORE_BCAST (1<<9)
653#define MAGIC_SWITCH_TO_PSP (0<<10)
654#define MAGIC_STAY_IN_CAM (1<<10)
655 u8 magicControl;
656 __le16 autoWake;
657} __packed;
658
659typedef struct StatusRid StatusRid;
660struct StatusRid {
661 __le16 len;
662 u8 mac[ETH_ALEN];
663 __le16 mode;
664 __le16 errorCode;
665 __le16 sigQuality;
666 __le16 SSIDlen;
667 char SSID[32];
668 char apName[16];
669 u8 bssid[4][ETH_ALEN];
670 __le16 beaconPeriod;
671 __le16 dimPeriod;
672 __le16 atimDuration;
673 __le16 hopPeriod;
674 __le16 channelSet;
675 __le16 channel;
676 __le16 hopsToBackbone;
677 __le16 apTotalLoad;
678 __le16 generatedLoad;
679 __le16 accumulatedArl;
680 __le16 signalQuality;
681 __le16 currentXmitRate;
682 __le16 apDevExtensions;
683 __le16 normalizedSignalStrength;
684 __le16 shortPreamble;
685 u8 apIP[4];
686 u8 noisePercent;
687 u8 noisedBm;
688 u8 noiseAvePercent;
689 u8 noiseAvedBm;
690 u8 noiseMaxPercent;
691 u8 noiseMaxdBm;
692 __le16 load;
693 u8 carrier[4];
694 __le16 assocStatus;
695#define STAT_NOPACKETS 0
696#define STAT_NOCARRIERSET 10
697#define STAT_GOTCARRIERSET 11
698#define STAT_WRONGSSID 20
699#define STAT_BADCHANNEL 25
700#define STAT_BADBITRATES 30
701#define STAT_BADPRIVACY 35
702#define STAT_APFOUND 40
703#define STAT_APREJECTED 50
704#define STAT_AUTHENTICATING 60
705#define STAT_DEAUTHENTICATED 61
706#define STAT_AUTHTIMEOUT 62
707#define STAT_ASSOCIATING 70
708#define STAT_DEASSOCIATED 71
709#define STAT_ASSOCTIMEOUT 72
710#define STAT_NOTAIROAP 73
711#define STAT_ASSOCIATED 80
712#define STAT_LEAPING 90
713#define STAT_LEAPFAILED 91
714#define STAT_LEAPTIMEDOUT 92
715#define STAT_LEAPCOMPLETE 93
716} __packed;
717
718typedef struct StatsRid StatsRid;
719struct StatsRid {
720 __le16 len;
721 __le16 spacer;
722 __le32 vals[100];
723} __packed;
724
725typedef struct APListRid APListRid;
726struct APListRid {
727 __le16 len;
728 u8 ap[4][ETH_ALEN];
729} __packed;
730
731typedef struct CapabilityRid CapabilityRid;
732struct CapabilityRid {
733 __le16 len;
734 char oui[3];
735 char zero;
736 __le16 prodNum;
737 char manName[32];
738 char prodName[16];
739 char prodVer[8];
740 char factoryAddr[ETH_ALEN];
741 char aironetAddr[ETH_ALEN];
742 __le16 radioType;
743 __le16 country;
744 char callid[ETH_ALEN];
745 char supportedRates[8];
746 char rxDiversity;
747 char txDiversity;
748 __le16 txPowerLevels[8];
749 __le16 hardVer;
750 __le16 hardCap;
751 __le16 tempRange;
752 __le16 softVer;
753 __le16 softSubVer;
754 __le16 interfaceVer;
755 __le16 softCap;
756 __le16 bootBlockVer;
757 __le16 requiredHard;
758 __le16 extSoftCap;
759} __packed;
760
761
762typedef struct BSSListRidExtra BSSListRidExtra;
763struct BSSListRidExtra {
764 __le16 unknown[4];
765 u8 fixed[12];
766 u8 iep[624];
767} __packed;
768
769typedef struct BSSListRid BSSListRid;
770struct BSSListRid {
771 __le16 len;
772 __le16 index;
773#define RADIO_FH 1
774#define RADIO_DS 2
775#define RADIO_TMA 4
776 __le16 radioType;
777 u8 bssid[ETH_ALEN];
778 u8 zero;
779 u8 ssidLen;
780 u8 ssid[32];
781 __le16 dBm;
782#define CAP_ESS cpu_to_le16(1<<0)
783#define CAP_IBSS cpu_to_le16(1<<1)
784#define CAP_PRIVACY cpu_to_le16(1<<4)
785#define CAP_SHORTHDR cpu_to_le16(1<<5)
786 __le16 cap;
787 __le16 beaconInterval;
788 u8 rates[8];
789 struct {
790 __le16 dwell;
791 u8 hopSet;
792 u8 hopPattern;
793 u8 hopIndex;
794 u8 fill;
795 } fh;
796 __le16 dsChannel;
797 __le16 atimWindow;
798
799
800 BSSListRidExtra extra;
801} __packed;
802
803typedef struct {
804 BSSListRid bss;
805 struct list_head list;
806} BSSListElement;
807
808typedef struct tdsRssiEntry tdsRssiEntry;
809struct tdsRssiEntry {
810 u8 rssipct;
811 u8 rssidBm;
812} __packed;
813
814typedef struct tdsRssiRid tdsRssiRid;
815struct tdsRssiRid {
816 u16 len;
817 tdsRssiEntry x[256];
818} __packed;
819
820typedef struct MICRid MICRid;
821struct MICRid {
822 __le16 len;
823 __le16 state;
824 __le16 multicastValid;
825 u8 multicast[16];
826 __le16 unicastValid;
827 u8 unicast[16];
828} __packed;
829
830typedef struct MICBuffer MICBuffer;
831struct MICBuffer {
832 __be16 typelen;
833
834 union {
835 u8 snap[8];
836 struct {
837 u8 dsap;
838 u8 ssap;
839 u8 control;
840 u8 orgcode[3];
841 u8 fieldtype[2];
842 } llc;
843 } u;
844 __be32 mic;
845 __be32 seq;
846} __packed;
847
848typedef struct {
849 u8 da[ETH_ALEN];
850 u8 sa[ETH_ALEN];
851} etherHead;
852
853#define TXCTL_TXOK (1<<1)
854#define TXCTL_TXEX (1<<2)
855#define TXCTL_802_3 (0<<3)
856#define TXCTL_802_11 (1<<3)
857#define TXCTL_ETHERNET (0<<4)
858#define TXCTL_LLC (1<<4)
859#define TXCTL_RELEASE (0<<5)
860#define TXCTL_NORELEASE (1<<5)
861
862#define BUSY_FID 0x10000
863
864#ifdef CISCO_EXT
865#define AIROMAGIC 0xa55a
866
867#ifdef SIOCIWFIRSTPRIV
868#ifdef SIOCDEVPRIVATE
869#define AIROOLDIOCTL SIOCDEVPRIVATE
870#define AIROOLDIDIFC AIROOLDIOCTL + 1
871#endif
872#else
873#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
874#endif
875
876
877
878
879#define AIROIOCTL SIOCIWFIRSTPRIV
880#define AIROIDIFC AIROIOCTL + 1
881
882
883
884#define AIROGCAP 0
885#define AIROGCFG 1
886#define AIROGSLIST 2
887#define AIROGVLIST 3
888#define AIROGDRVNAM 4
889#define AIROGEHTENC 5
890#define AIROGWEPKTMP 6
891#define AIROGWEPKNV 7
892#define AIROGSTAT 8
893#define AIROGSTATSC32 9
894#define AIROGSTATSD32 10
895#define AIROGMICRID 11
896#define AIROGMICSTATS 12
897#define AIROGFLAGS 13
898#define AIROGID 14
899#define AIRORRID 15
900#define AIRORSWVERSION 17
901
902
903
904#define AIROPCAP AIROGSTATSD32 + 40
905#define AIROPVLIST AIROPCAP + 1
906#define AIROPSLIST AIROPVLIST + 1
907#define AIROPCFG AIROPSLIST + 1
908#define AIROPSIDS AIROPCFG + 1
909#define AIROPAPLIST AIROPSIDS + 1
910#define AIROPMACON AIROPAPLIST + 1
911#define AIROPMACOFF AIROPMACON + 1
912#define AIROPSTCLR AIROPMACOFF + 1
913#define AIROPWEPKEY AIROPSTCLR + 1
914#define AIROPWEPKEYNV AIROPWEPKEY + 1
915#define AIROPLEAPPWD AIROPWEPKEYNV + 1
916#define AIROPLEAPUSR AIROPLEAPPWD + 1
917
918
919
920#define AIROFLSHRST AIROPWEPKEYNV + 40
921#define AIROFLSHGCHR AIROFLSHRST + 1
922#define AIROFLSHSTFL AIROFLSHGCHR + 1
923#define AIROFLSHPCHR AIROFLSHSTFL + 1
924#define AIROFLPUTBUF AIROFLSHPCHR + 1
925#define AIRORESTART AIROFLPUTBUF + 1
926
927#define FLASHSIZE 32768
928#define AUXMEMSIZE (256 * 1024)
929
930typedef struct aironet_ioctl {
931 unsigned short command;
932 unsigned short len;
933 unsigned short ridnum;
934 unsigned char __user *data;
935} aironet_ioctl;
936
937static const char swversion[] = "2.1";
938#endif
939
940#define NUM_MODULES 2
941#define MIC_MSGLEN_MAX 2400
942#define EMMH32_MSGLEN_MAX MIC_MSGLEN_MAX
943#define AIRO_DEF_MTU 2312
944
945typedef struct {
946 u32 size;
947 u8 enabled;
948 u32 rxSuccess;
949 u32 rxIncorrectMIC;
950 u32 rxNotMICed;
951 u32 rxMICPlummed;
952 u32 rxWrongSequence;
953 u32 reserve[32];
954} mic_statistics;
955
956typedef struct {
957 __be32 coeff[((EMMH32_MSGLEN_MAX)+3)>>2];
958 u64 accum;
959 int position;
960 union {
961 u8 d8[4];
962 __be32 d32;
963 } part;
964} emmh32_context;
965
966typedef struct {
967 emmh32_context seed;
968 u32 rx;
969 u32 tx;
970 u32 window;
971 u8 valid;
972 u8 key[16];
973} miccntx;
974
975typedef struct {
976 miccntx mCtx;
977 miccntx uCtx;
978} mic_module;
979
980typedef struct {
981 unsigned int rid: 16;
982 unsigned int len: 15;
983 unsigned int valid: 1;
984 dma_addr_t host_addr;
985} Rid;
986
987typedef struct {
988 unsigned int offset: 15;
989 unsigned int eoc: 1;
990 unsigned int len: 15;
991 unsigned int valid: 1;
992 dma_addr_t host_addr;
993} TxFid;
994
995struct rx_hdr {
996 __le16 status, len;
997 u8 rssi[2];
998 u8 rate;
999 u8 freq;
1000 __le16 tmp[4];
1001} __packed;
1002
1003typedef struct {
1004 unsigned int ctl: 15;
1005 unsigned int rdy: 1;
1006 unsigned int len: 15;
1007 unsigned int valid: 1;
1008 dma_addr_t host_addr;
1009} RxFid;
1010
1011
1012
1013
1014typedef struct {
1015 unsigned char __iomem *card_ram_off;
1016
1017 RxFid rx_desc;
1018 char *virtual_host_addr;
1019
1020 int pending;
1021} HostRxDesc;
1022
1023
1024
1025
1026typedef struct {
1027 unsigned char __iomem *card_ram_off;
1028
1029 TxFid tx_desc;
1030 char *virtual_host_addr;
1031
1032 int pending;
1033} HostTxDesc;
1034
1035
1036
1037
1038typedef struct {
1039 unsigned char __iomem *card_ram_off;
1040
1041 Rid rid_desc;
1042 char *virtual_host_addr;
1043
1044} HostRidDesc;
1045
1046typedef struct {
1047 u16 sw0;
1048 u16 sw1;
1049 u16 status;
1050 u16 len;
1051#define HOST_SET (1 << 0)
1052#define HOST_INT_TX (1 << 1)
1053#define HOST_INT_TXERR (1 << 2)
1054#define HOST_LCC_PAYLOAD (1 << 4)
1055#define HOST_DONT_RLSE (1 << 5)
1056#define HOST_DONT_RETRY (1 << 6)
1057#define HOST_CLR_AID (1 << 7)
1058#define HOST_RTS (1 << 9)
1059#define HOST_SHORT (1 << 10)
1060 u16 ctl;
1061 u16 aid;
1062 u16 retries;
1063 u16 fill;
1064} TxCtlHdr;
1065
1066typedef struct {
1067 u16 ctl;
1068 u16 duration;
1069 char addr1[6];
1070 char addr2[6];
1071 char addr3[6];
1072 u16 seq;
1073 char addr4[6];
1074} WifiHdr;
1075
1076
1077typedef struct {
1078 TxCtlHdr ctlhdr;
1079 u16 fill1;
1080 u16 fill2;
1081 WifiHdr wifihdr;
1082 u16 gaplen;
1083 u16 status;
1084} WifiCtlHdr;
1085
1086static WifiCtlHdr wifictlhdr8023 = {
1087 .ctlhdr = {
1088 .ctl = HOST_DONT_RLSE,
1089 }
1090};
1091
1092
1093#define MAX_KEY_SIZE 13
1094#define MIN_KEY_SIZE 5
1095typedef struct wep_key_t {
1096 u16 len;
1097 u8 key[16];
1098} wep_key_t;
1099
1100
1101static const struct iw_handler_def airo_handler_def;
1102
1103static const char version[] = "airo.c 0.6 (Ben Reed & Javier Achirica)";
1104
1105struct airo_info;
1106
1107static int get_dec_u16( char *buffer, int *start, int limit );
1108static void OUT4500( struct airo_info *, u16 reg, u16 value );
1109static unsigned short IN4500( struct airo_info *, u16 reg );
1110static u16 setup_card(struct airo_info*, u8 *mac, int lock);
1111static int enable_MAC(struct airo_info *ai, int lock);
1112static void disable_MAC(struct airo_info *ai, int lock);
1113static void enable_interrupts(struct airo_info*);
1114static void disable_interrupts(struct airo_info*);
1115static u16 issuecommand(struct airo_info*, Cmd *pCmd, Resp *pRsp);
1116static int bap_setup(struct airo_info*, u16 rid, u16 offset, int whichbap);
1117static int aux_bap_read(struct airo_info*, __le16 *pu16Dst, int bytelen,
1118 int whichbap);
1119static int fast_bap_read(struct airo_info*, __le16 *pu16Dst, int bytelen,
1120 int whichbap);
1121static int bap_write(struct airo_info*, const __le16 *pu16Src, int bytelen,
1122 int whichbap);
1123static int PC4500_accessrid(struct airo_info*, u16 rid, u16 accmd);
1124static int PC4500_readrid(struct airo_info*, u16 rid, void *pBuf, int len, int lock);
1125static int PC4500_writerid(struct airo_info*, u16 rid, const void
1126 *pBuf, int len, int lock);
1127static int do_writerid( struct airo_info*, u16 rid, const void *rid_data,
1128 int len, int dummy );
1129static u16 transmit_allocate(struct airo_info*, int lenPayload, int raw);
1130static int transmit_802_3_packet(struct airo_info*, int len, char *pPacket);
1131static int transmit_802_11_packet(struct airo_info*, int len, char *pPacket);
1132
1133static int mpi_send_packet (struct net_device *dev);
1134static void mpi_unmap_card(struct pci_dev *pci);
1135static void mpi_receive_802_3(struct airo_info *ai);
1136static void mpi_receive_802_11(struct airo_info *ai);
1137static int waitbusy (struct airo_info *ai);
1138
1139static irqreturn_t airo_interrupt( int irq, void* dev_id);
1140static int airo_thread(void *data);
1141static void timer_func( struct net_device *dev );
1142static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
1143static struct iw_statistics *airo_get_wireless_stats (struct net_device *dev);
1144static void airo_read_wireless_stats (struct airo_info *local);
1145#ifdef CISCO_EXT
1146static int readrids(struct net_device *dev, aironet_ioctl *comp);
1147static int writerids(struct net_device *dev, aironet_ioctl *comp);
1148static int flashcard(struct net_device *dev, aironet_ioctl *comp);
1149#endif
1150static void micinit(struct airo_info *ai);
1151static int micsetup(struct airo_info *ai);
1152static int encapsulate(struct airo_info *ai, etherHead *pPacket, MICBuffer *buffer, int len);
1153static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *pPacket, u16 payLen);
1154
1155static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi);
1156static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm);
1157
1158static void airo_networks_free(struct airo_info *ai);
1159
1160struct airo_info {
1161 struct net_device *dev;
1162 struct list_head dev_list;
1163
1164
1165#define MAX_FIDS 6
1166#define MPI_MAX_FIDS 1
1167 u32 fids[MAX_FIDS];
1168 ConfigRid config;
1169 char keyindex;
1170 char defindex;
1171 struct proc_dir_entry *proc_entry;
1172 spinlock_t aux_lock;
1173#define FLAG_RADIO_OFF 0
1174#define FLAG_RADIO_DOWN 1
1175#define FLAG_RADIO_MASK 0x03
1176#define FLAG_ENABLED 2
1177#define FLAG_ADHOC 3
1178#define FLAG_MIC_CAPABLE 4
1179#define FLAG_UPDATE_MULTI 5
1180#define FLAG_UPDATE_UNI 6
1181#define FLAG_802_11 7
1182#define FLAG_PROMISC 8
1183#define FLAG_PENDING_XMIT 9
1184#define FLAG_PENDING_XMIT11 10
1185#define FLAG_MPI 11
1186#define FLAG_REGISTERED 12
1187#define FLAG_COMMIT 13
1188#define FLAG_RESET 14
1189#define FLAG_FLASHING 15
1190#define FLAG_WPA_CAPABLE 16
1191 unsigned long flags;
1192#define JOB_DIE 0
1193#define JOB_XMIT 1
1194#define JOB_XMIT11 2
1195#define JOB_STATS 3
1196#define JOB_PROMISC 4
1197#define JOB_MIC 5
1198#define JOB_EVENT 6
1199#define JOB_AUTOWEP 7
1200#define JOB_WSTATS 8
1201#define JOB_SCAN_RESULTS 9
1202 unsigned long jobs;
1203 int (*bap_read)(struct airo_info*, __le16 *pu16Dst, int bytelen,
1204 int whichbap);
1205 unsigned short *flash;
1206 tdsRssiEntry *rssi;
1207 struct task_struct *list_bss_task;
1208 struct task_struct *airo_thread_task;
1209 struct semaphore sem;
1210 wait_queue_head_t thr_wait;
1211 unsigned long expires;
1212 struct {
1213 struct sk_buff *skb;
1214 int fid;
1215 } xmit, xmit11;
1216 struct net_device *wifidev;
1217 struct iw_statistics wstats;
1218 unsigned long scan_timeout;
1219 struct iw_spy_data spy_data;
1220 struct iw_public_data wireless_data;
1221
1222 struct crypto_sync_skcipher *tfm;
1223 mic_module mod[2];
1224 mic_statistics micstats;
1225 HostRxDesc rxfids[MPI_MAX_FIDS];
1226 HostTxDesc txfids[MPI_MAX_FIDS];
1227 HostRidDesc config_desc;
1228 unsigned long ridbus;
1229 struct sk_buff_head txq;
1230 struct pci_dev *pci;
1231 unsigned char __iomem *pcimem;
1232 unsigned char __iomem *pciaux;
1233 unsigned char *shared;
1234 dma_addr_t shared_dma;
1235 pm_message_t power;
1236 SsidRid *SSID;
1237 APListRid APList;
1238#define PCI_SHARED_LEN 2*MPI_MAX_FIDS*PKTSIZE+RIDSIZE
1239 char proc_name[IFNAMSIZ];
1240
1241 int wep_capable;
1242 int max_wep_idx;
1243 int last_auth;
1244
1245
1246 unsigned int bssListFirst;
1247 unsigned int bssListNext;
1248 unsigned int bssListRidLen;
1249
1250 struct list_head network_list;
1251 struct list_head network_free_list;
1252 BSSListElement *networks;
1253};
1254
1255static inline int bap_read(struct airo_info *ai, __le16 *pu16Dst, int bytelen,
1256 int whichbap)
1257{
1258 return ai->bap_read(ai, pu16Dst, bytelen, whichbap);
1259}
1260
1261static int setup_proc_entry( struct net_device *dev,
1262 struct airo_info *apriv );
1263static int takedown_proc_entry( struct net_device *dev,
1264 struct airo_info *apriv );
1265
1266static int cmdreset(struct airo_info *ai);
1267static int setflashmode (struct airo_info *ai);
1268static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime);
1269static int flashputbuf(struct airo_info *ai);
1270static int flashrestart(struct airo_info *ai,struct net_device *dev);
1271
1272#define airo_print(type, name, fmt, args...) \
1273 printk(type DRV_NAME "(%s): " fmt "\n", name, ##args)
1274
1275#define airo_print_info(name, fmt, args...) \
1276 airo_print(KERN_INFO, name, fmt, ##args)
1277
1278#define airo_print_dbg(name, fmt, args...) \
1279 airo_print(KERN_DEBUG, name, fmt, ##args)
1280
1281#define airo_print_warn(name, fmt, args...) \
1282 airo_print(KERN_WARNING, name, fmt, ##args)
1283
1284#define airo_print_err(name, fmt, args...) \
1285 airo_print(KERN_ERR, name, fmt, ##args)
1286
1287#define AIRO_FLASH(dev) (((struct airo_info *)dev->ml_priv)->flash)
1288
1289
1290
1291
1292
1293
1294static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq);
1295static void MoveWindow(miccntx *context, u32 micSeq);
1296static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
1297 struct crypto_sync_skcipher *tfm);
1298static void emmh32_init(emmh32_context *context);
1299static void emmh32_update(emmh32_context *context, u8 *pOctets, int len);
1300static void emmh32_final(emmh32_context *context, u8 digest[4]);
1301static int flashpchar(struct airo_info *ai,int byte,int dwelltime);
1302
1303static void age_mic_context(miccntx *cur, miccntx *old, u8 *key, int key_len,
1304 struct crypto_sync_skcipher *tfm)
1305{
1306
1307
1308
1309 if (cur->valid && (memcmp(cur->key, key, key_len) == 0))
1310 return;
1311
1312
1313 memcpy(old, cur, sizeof(*cur));
1314
1315
1316 memcpy(cur->key, key, key_len);
1317 cur->window = 33;
1318 cur->rx = 0;
1319 cur->tx = 0;
1320 cur->valid = 1;
1321
1322
1323 emmh32_setseed(&cur->seed, key, key_len, tfm);
1324}
1325
1326
1327
1328static void micinit(struct airo_info *ai)
1329{
1330 MICRid mic_rid;
1331
1332 clear_bit(JOB_MIC, &ai->jobs);
1333 PC4500_readrid(ai, RID_MIC, &mic_rid, sizeof(mic_rid), 0);
1334 up(&ai->sem);
1335
1336 ai->micstats.enabled = (le16_to_cpu(mic_rid.state) & 0x00FF) ? 1 : 0;
1337 if (!ai->micstats.enabled) {
1338
1339
1340
1341 ai->mod[0].uCtx.valid = 0;
1342 ai->mod[0].mCtx.valid = 0;
1343 return;
1344 }
1345
1346 if (mic_rid.multicastValid) {
1347 age_mic_context(&ai->mod[0].mCtx, &ai->mod[1].mCtx,
1348 mic_rid.multicast, sizeof(mic_rid.multicast),
1349 ai->tfm);
1350 }
1351
1352 if (mic_rid.unicastValid) {
1353 age_mic_context(&ai->mod[0].uCtx, &ai->mod[1].uCtx,
1354 mic_rid.unicast, sizeof(mic_rid.unicast),
1355 ai->tfm);
1356 }
1357}
1358
1359
1360
1361static int micsetup(struct airo_info *ai) {
1362 int i;
1363
1364 if (ai->tfm == NULL)
1365 ai->tfm = crypto_alloc_sync_skcipher("ctr(aes)", 0, 0);
1366
1367 if (IS_ERR(ai->tfm)) {
1368 airo_print_err(ai->dev->name, "failed to load transform for AES");
1369 ai->tfm = NULL;
1370 return ERROR;
1371 }
1372
1373 for (i=0; i < NUM_MODULES; i++) {
1374 memset(&ai->mod[i].mCtx,0,sizeof(miccntx));
1375 memset(&ai->mod[i].uCtx,0,sizeof(miccntx));
1376 }
1377 return SUCCESS;
1378}
1379
1380static const u8 micsnap[] = {0xAA,0xAA,0x03,0x00,0x40,0x96,0x00,0x02};
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398static int encapsulate(struct airo_info *ai ,etherHead *frame, MICBuffer *mic, int payLen)
1399{
1400 miccntx *context;
1401
1402
1403
1404
1405 if (test_bit(FLAG_ADHOC, &ai->flags) && (frame->da[0] & 0x1))
1406 context = &ai->mod[0].mCtx;
1407 else
1408 context = &ai->mod[0].uCtx;
1409
1410 if (!context->valid)
1411 return ERROR;
1412
1413 mic->typelen = htons(payLen + 16);
1414
1415 memcpy(&mic->u.snap, micsnap, sizeof(micsnap));
1416
1417
1418 mic->seq = htonl(context->tx);
1419 context->tx += 2;
1420
1421 emmh32_init(&context->seed);
1422 emmh32_update(&context->seed,frame->da,ETH_ALEN * 2);
1423 emmh32_update(&context->seed,(u8*)&mic->typelen,10);
1424 emmh32_update(&context->seed,(u8*)&mic->seq,sizeof(mic->seq));
1425 emmh32_update(&context->seed,(u8*)(frame + 1),payLen);
1426 emmh32_final(&context->seed, (u8*)&mic->mic);
1427
1428
1429 mic->typelen = 0;
1430 return SUCCESS;
1431}
1432
1433typedef enum {
1434 NONE,
1435 NOMIC,
1436 NOMICPLUMMED,
1437 SEQUENCE,
1438 INCORRECTMIC,
1439} mic_error;
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *eth, u16 payLen)
1455{
1456 int i;
1457 u32 micSEQ;
1458 miccntx *context;
1459 u8 digest[4];
1460 mic_error micError = NONE;
1461
1462
1463
1464 if (!ai->micstats.enabled) {
1465
1466 if (memcmp ((u8*)eth + 14, micsnap, sizeof(micsnap)) == 0) {
1467 ai->micstats.rxMICPlummed++;
1468 return ERROR;
1469 }
1470 return SUCCESS;
1471 }
1472
1473 if (ntohs(mic->typelen) == 0x888E)
1474 return SUCCESS;
1475
1476 if (memcmp (mic->u.snap, micsnap, sizeof(micsnap)) != 0) {
1477
1478 ai->micstats.rxMICPlummed++;
1479 return ERROR;
1480 }
1481
1482 micSEQ = ntohl(mic->seq);
1483
1484
1485
1486
1487
1488 if ( (micSEQ & 1) == 0 ) {
1489 ai->micstats.rxWrongSequence++;
1490 return ERROR;
1491 }
1492
1493 for (i = 0; i < NUM_MODULES; i++) {
1494 int mcast = eth->da[0] & 1;
1495
1496 context = mcast ? &ai->mod[i].mCtx : &ai->mod[i].uCtx;
1497
1498
1499 if (!context->valid) {
1500 if (i == 0)
1501 micError = NOMICPLUMMED;
1502 continue;
1503 }
1504
1505
1506 if (!mic->typelen)
1507 mic->typelen = htons(payLen + sizeof(MICBuffer) - 2);
1508
1509 emmh32_init(&context->seed);
1510 emmh32_update(&context->seed, eth->da, ETH_ALEN*2);
1511 emmh32_update(&context->seed, (u8 *)&mic->typelen, sizeof(mic->typelen)+sizeof(mic->u.snap));
1512 emmh32_update(&context->seed, (u8 *)&mic->seq,sizeof(mic->seq));
1513 emmh32_update(&context->seed, (u8 *)(eth + 1),payLen);
1514
1515 emmh32_final(&context->seed, digest);
1516
1517 if (memcmp(digest, &mic->mic, 4)) {
1518
1519 if (i == 0)
1520 micError = INCORRECTMIC;
1521 continue;
1522 }
1523
1524
1525 if (RxSeqValid(ai, context, mcast, micSEQ) == SUCCESS) {
1526 ai->micstats.rxSuccess++;
1527 return SUCCESS;
1528 }
1529 if (i == 0)
1530 micError = SEQUENCE;
1531 }
1532
1533
1534 switch (micError) {
1535 case NOMICPLUMMED: ai->micstats.rxMICPlummed++; break;
1536 case SEQUENCE: ai->micstats.rxWrongSequence++; break;
1537 case INCORRECTMIC: ai->micstats.rxIncorrectMIC++; break;
1538 case NONE: break;
1539 case NOMIC: break;
1540 }
1541 return ERROR;
1542}
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq)
1559{
1560 u32 seq,index;
1561
1562
1563
1564
1565 if (mcast) {
1566 if (test_bit(FLAG_UPDATE_MULTI, &ai->flags)) {
1567 clear_bit (FLAG_UPDATE_MULTI, &ai->flags);
1568 context->window = (micSeq > 33) ? micSeq : 33;
1569 context->rx = 0;
1570 }
1571 } else if (test_bit(FLAG_UPDATE_UNI, &ai->flags)) {
1572 clear_bit (FLAG_UPDATE_UNI, &ai->flags);
1573 context->window = (micSeq > 33) ? micSeq : 33;
1574 context->rx = 0;
1575 }
1576
1577
1578 seq = micSeq - (context->window - 33);
1579
1580
1581 if ((s32)seq < 0)
1582 return ERROR;
1583
1584 if ( seq > 64 ) {
1585
1586 MoveWindow(context,micSeq);
1587 return SUCCESS;
1588 }
1589
1590
1591 seq >>= 1;
1592 index = 1 << seq;
1593
1594 if (!(context->rx & index)) {
1595
1596
1597 context->rx |= index;
1598
1599 MoveWindow(context,micSeq);
1600
1601 return SUCCESS;
1602 }
1603 return ERROR;
1604}
1605
1606static void MoveWindow(miccntx *context, u32 micSeq)
1607{
1608 u32 shift;
1609
1610
1611 if (micSeq > context->window) {
1612 shift = (micSeq - context->window) >> 1;
1613
1614
1615 if (shift < 32)
1616 context->rx >>= shift;
1617 else
1618 context->rx = 0;
1619
1620 context->window = micSeq;
1621 }
1622}
1623
1624
1625
1626
1627
1628
1629#define MIC_ACCUM(val) \
1630 context->accum += (u64)(val) * be32_to_cpu(context->coeff[coeff_position++]);
1631
1632
1633static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen,
1634 struct crypto_sync_skcipher *tfm)
1635{
1636
1637
1638
1639 SYNC_SKCIPHER_REQUEST_ON_STACK(req, tfm);
1640 struct scatterlist sg;
1641 u8 iv[AES_BLOCK_SIZE] = {};
1642 int ret;
1643
1644 crypto_sync_skcipher_setkey(tfm, pkey, 16);
1645
1646 memset(context->coeff, 0, sizeof(context->coeff));
1647 sg_init_one(&sg, context->coeff, sizeof(context->coeff));
1648
1649 skcipher_request_set_sync_tfm(req, tfm);
1650 skcipher_request_set_callback(req, 0, NULL, NULL);
1651 skcipher_request_set_crypt(req, &sg, &sg, sizeof(context->coeff), iv);
1652
1653 ret = crypto_skcipher_encrypt(req);
1654 WARN_ON_ONCE(ret);
1655}
1656
1657
1658static void emmh32_init(emmh32_context *context)
1659{
1660
1661 context->accum = 0;
1662 context->position = 0;
1663}
1664
1665
1666static void emmh32_update(emmh32_context *context, u8 *pOctets, int len)
1667{
1668 int coeff_position, byte_position;
1669
1670 if (len == 0) return;
1671
1672 coeff_position = context->position >> 2;
1673
1674
1675 byte_position = context->position & 3;
1676 if (byte_position) {
1677
1678 do {
1679 if (len == 0) return;
1680 context->part.d8[byte_position++] = *pOctets++;
1681 context->position++;
1682 len--;
1683 } while (byte_position < 4);
1684 MIC_ACCUM(ntohl(context->part.d32));
1685 }
1686
1687
1688 while (len >= 4) {
1689 MIC_ACCUM(ntohl(*(__be32 *)pOctets));
1690 context->position += 4;
1691 pOctets += 4;
1692 len -= 4;
1693 }
1694
1695
1696 byte_position = 0;
1697 while (len > 0) {
1698 context->part.d8[byte_position++] = *pOctets++;
1699 context->position++;
1700 len--;
1701 }
1702}
1703
1704
1705static u32 mask32[4] = { 0x00000000L, 0xFF000000L, 0xFFFF0000L, 0xFFFFFF00L };
1706
1707
1708static void emmh32_final(emmh32_context *context, u8 digest[4])
1709{
1710 int coeff_position, byte_position;
1711 u32 val;
1712
1713 u64 sum, utmp;
1714 s64 stmp;
1715
1716 coeff_position = context->position >> 2;
1717
1718
1719 byte_position = context->position & 3;
1720 if (byte_position) {
1721
1722 val = ntohl(context->part.d32);
1723 MIC_ACCUM(val & mask32[byte_position]);
1724 }
1725
1726
1727 sum = context->accum;
1728 stmp = (sum & 0xffffffffLL) - ((sum >> 32) * 15);
1729 utmp = (stmp & 0xffffffffLL) - ((stmp >> 32) * 15);
1730 sum = utmp & 0xffffffffLL;
1731 if (utmp > 0x10000000fLL)
1732 sum -= 15;
1733
1734 val = (u32)sum;
1735 digest[0] = (val>>24) & 0xFF;
1736 digest[1] = (val>>16) & 0xFF;
1737 digest[2] = (val>>8) & 0xFF;
1738 digest[3] = val & 0xFF;
1739}
1740
1741static int readBSSListRid(struct airo_info *ai, int first,
1742 BSSListRid *list)
1743{
1744 Cmd cmd;
1745 Resp rsp;
1746
1747 if (first == 1) {
1748 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
1749 memset(&cmd, 0, sizeof(cmd));
1750 cmd.cmd=CMD_LISTBSS;
1751 if (down_interruptible(&ai->sem))
1752 return -ERESTARTSYS;
1753 ai->list_bss_task = current;
1754 issuecommand(ai, &cmd, &rsp);
1755 up(&ai->sem);
1756
1757 schedule_timeout_uninterruptible(3 * HZ);
1758 ai->list_bss_task = NULL;
1759 }
1760 return PC4500_readrid(ai, first ? ai->bssListFirst : ai->bssListNext,
1761 list, ai->bssListRidLen, 1);
1762}
1763
1764static int readWepKeyRid(struct airo_info *ai, WepKeyRid *wkr, int temp, int lock)
1765{
1766 return PC4500_readrid(ai, temp ? RID_WEP_TEMP : RID_WEP_PERM,
1767 wkr, sizeof(*wkr), lock);
1768}
1769
1770static int writeWepKeyRid(struct airo_info *ai, WepKeyRid *wkr, int perm, int lock)
1771{
1772 int rc;
1773 rc = PC4500_writerid(ai, RID_WEP_TEMP, wkr, sizeof(*wkr), lock);
1774 if (rc!=SUCCESS)
1775 airo_print_err(ai->dev->name, "WEP_TEMP set %x", rc);
1776 if (perm) {
1777 rc = PC4500_writerid(ai, RID_WEP_PERM, wkr, sizeof(*wkr), lock);
1778 if (rc!=SUCCESS)
1779 airo_print_err(ai->dev->name, "WEP_PERM set %x", rc);
1780 }
1781 return rc;
1782}
1783
1784static int readSsidRid(struct airo_info*ai, SsidRid *ssidr)
1785{
1786 return PC4500_readrid(ai, RID_SSID, ssidr, sizeof(*ssidr), 1);
1787}
1788
1789static int writeSsidRid(struct airo_info*ai, SsidRid *pssidr, int lock)
1790{
1791 return PC4500_writerid(ai, RID_SSID, pssidr, sizeof(*pssidr), lock);
1792}
1793
1794static int readConfigRid(struct airo_info *ai, int lock)
1795{
1796 int rc;
1797 ConfigRid cfg;
1798
1799 if (ai->config.len)
1800 return SUCCESS;
1801
1802 rc = PC4500_readrid(ai, RID_ACTUALCONFIG, &cfg, sizeof(cfg), lock);
1803 if (rc != SUCCESS)
1804 return rc;
1805
1806 ai->config = cfg;
1807 return SUCCESS;
1808}
1809
1810static inline void checkThrottle(struct airo_info *ai)
1811{
1812 int i;
1813
1814 if (ai->config.authType != AUTH_OPEN && maxencrypt) {
1815 for(i=0; i<8; i++) {
1816 if (ai->config.rates[i] > maxencrypt) {
1817 ai->config.rates[i] = 0;
1818 }
1819 }
1820 }
1821}
1822
1823static int writeConfigRid(struct airo_info *ai, int lock)
1824{
1825 ConfigRid cfgr;
1826
1827 if (!test_bit (FLAG_COMMIT, &ai->flags))
1828 return SUCCESS;
1829
1830 clear_bit (FLAG_COMMIT, &ai->flags);
1831 clear_bit (FLAG_RESET, &ai->flags);
1832 checkThrottle(ai);
1833 cfgr = ai->config;
1834
1835 if ((cfgr.opmode & MODE_CFG_MASK) == MODE_STA_IBSS)
1836 set_bit(FLAG_ADHOC, &ai->flags);
1837 else
1838 clear_bit(FLAG_ADHOC, &ai->flags);
1839
1840 return PC4500_writerid( ai, RID_CONFIG, &cfgr, sizeof(cfgr), lock);
1841}
1842
1843static int readStatusRid(struct airo_info *ai, StatusRid *statr, int lock)
1844{
1845 return PC4500_readrid(ai, RID_STATUS, statr, sizeof(*statr), lock);
1846}
1847
1848static int writeAPListRid(struct airo_info *ai, APListRid *aplr, int lock)
1849{
1850 return PC4500_writerid(ai, RID_APLIST, aplr, sizeof(*aplr), lock);
1851}
1852
1853static int readCapabilityRid(struct airo_info *ai, CapabilityRid *capr, int lock)
1854{
1855 return PC4500_readrid(ai, RID_CAPABILITIES, capr, sizeof(*capr), lock);
1856}
1857
1858static int readStatsRid(struct airo_info*ai, StatsRid *sr, int rid, int lock)
1859{
1860 return PC4500_readrid(ai, rid, sr, sizeof(*sr), lock);
1861}
1862
1863static void try_auto_wep(struct airo_info *ai)
1864{
1865 if (auto_wep && !test_bit(FLAG_RADIO_DOWN, &ai->flags)) {
1866 ai->expires = RUN_AT(3*HZ);
1867 wake_up_interruptible(&ai->thr_wait);
1868 }
1869}
1870
1871static int airo_open(struct net_device *dev) {
1872 struct airo_info *ai = dev->ml_priv;
1873 int rc = 0;
1874
1875 if (test_bit(FLAG_FLASHING, &ai->flags))
1876 return -EIO;
1877
1878
1879
1880
1881
1882 if (test_bit(FLAG_COMMIT, &ai->flags)) {
1883 disable_MAC(ai, 1);
1884 writeConfigRid(ai, 1);
1885 }
1886
1887 if (ai->wifidev != dev) {
1888 clear_bit(JOB_DIE, &ai->jobs);
1889 ai->airo_thread_task = kthread_run(airo_thread, dev, "%s",
1890 dev->name);
1891 if (IS_ERR(ai->airo_thread_task))
1892 return (int)PTR_ERR(ai->airo_thread_task);
1893
1894 rc = request_irq(dev->irq, airo_interrupt, IRQF_SHARED,
1895 dev->name, dev);
1896 if (rc) {
1897 airo_print_err(dev->name,
1898 "register interrupt %d failed, rc %d",
1899 dev->irq, rc);
1900 set_bit(JOB_DIE, &ai->jobs);
1901 kthread_stop(ai->airo_thread_task);
1902 return rc;
1903 }
1904
1905
1906 clear_bit(FLAG_RADIO_DOWN, &ai->flags);
1907 enable_interrupts(ai);
1908
1909 try_auto_wep(ai);
1910 }
1911 enable_MAC(ai, 1);
1912
1913 netif_start_queue(dev);
1914 return 0;
1915}
1916
1917static netdev_tx_t mpi_start_xmit(struct sk_buff *skb,
1918 struct net_device *dev)
1919{
1920 int npacks, pending;
1921 unsigned long flags;
1922 struct airo_info *ai = dev->ml_priv;
1923
1924 if (!skb) {
1925 airo_print_err(dev->name, "%s: skb == NULL!",__func__);
1926 return NETDEV_TX_OK;
1927 }
1928 npacks = skb_queue_len (&ai->txq);
1929
1930 if (npacks >= MAXTXQ - 1) {
1931 netif_stop_queue (dev);
1932 if (npacks > MAXTXQ) {
1933 dev->stats.tx_fifo_errors++;
1934 return NETDEV_TX_BUSY;
1935 }
1936 skb_queue_tail (&ai->txq, skb);
1937 return NETDEV_TX_OK;
1938 }
1939
1940 spin_lock_irqsave(&ai->aux_lock, flags);
1941 skb_queue_tail (&ai->txq, skb);
1942 pending = test_bit(FLAG_PENDING_XMIT, &ai->flags);
1943 spin_unlock_irqrestore(&ai->aux_lock,flags);
1944 netif_wake_queue (dev);
1945
1946 if (pending == 0) {
1947 set_bit(FLAG_PENDING_XMIT, &ai->flags);
1948 mpi_send_packet (dev);
1949 }
1950 return NETDEV_TX_OK;
1951}
1952
1953
1954
1955
1956
1957
1958
1959
1960static int mpi_send_packet (struct net_device *dev)
1961{
1962 struct sk_buff *skb;
1963 unsigned char *buffer;
1964 s16 len;
1965 __le16 *payloadLen;
1966 struct airo_info *ai = dev->ml_priv;
1967 u8 *sendbuf;
1968
1969
1970
1971 if ((skb = skb_dequeue(&ai->txq)) == NULL) {
1972 airo_print_err(dev->name,
1973 "%s: Dequeue'd zero in send_packet()",
1974 __func__);
1975 return 0;
1976 }
1977
1978
1979 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1980 buffer = skb->data;
1981
1982 ai->txfids[0].tx_desc.offset = 0;
1983 ai->txfids[0].tx_desc.valid = 1;
1984 ai->txfids[0].tx_desc.eoc = 1;
1985 ai->txfids[0].tx_desc.len =len+sizeof(WifiHdr);
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995 memcpy(ai->txfids[0].virtual_host_addr,
1996 (char *)&wifictlhdr8023, sizeof(wifictlhdr8023));
1997
1998 payloadLen = (__le16 *)(ai->txfids[0].virtual_host_addr +
1999 sizeof(wifictlhdr8023));
2000 sendbuf = ai->txfids[0].virtual_host_addr +
2001 sizeof(wifictlhdr8023) + 2 ;
2002
2003
2004
2005
2006
2007 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
2008 (ntohs(((__be16 *)buffer)[6]) != 0x888E)) {
2009 MICBuffer pMic;
2010
2011 if (encapsulate(ai, (etherHead *)buffer, &pMic, len - sizeof(etherHead)) != SUCCESS)
2012 return ERROR;
2013
2014 *payloadLen = cpu_to_le16(len-sizeof(etherHead)+sizeof(pMic));
2015 ai->txfids[0].tx_desc.len += sizeof(pMic);
2016
2017 memcpy (sendbuf, buffer, sizeof(etherHead));
2018 buffer += sizeof(etherHead);
2019 sendbuf += sizeof(etherHead);
2020 memcpy (sendbuf, &pMic, sizeof(pMic));
2021 sendbuf += sizeof(pMic);
2022 memcpy (sendbuf, buffer, len - sizeof(etherHead));
2023 } else {
2024 *payloadLen = cpu_to_le16(len - sizeof(etherHead));
2025
2026 netif_trans_update(dev);
2027
2028
2029 memcpy(sendbuf, buffer, len);
2030 }
2031
2032 memcpy_toio(ai->txfids[0].card_ram_off,
2033 &ai->txfids[0].tx_desc, sizeof(TxFid));
2034
2035 OUT4500(ai, EVACK, 8);
2036
2037 dev_kfree_skb_any(skb);
2038 return 1;
2039}
2040
2041static void get_tx_error(struct airo_info *ai, s32 fid)
2042{
2043 __le16 status;
2044
2045 if (fid < 0)
2046 status = ((WifiCtlHdr *)ai->txfids[0].virtual_host_addr)->ctlhdr.status;
2047 else {
2048 if (bap_setup(ai, ai->fids[fid] & 0xffff, 4, BAP0) != SUCCESS)
2049 return;
2050 bap_read(ai, &status, 2, BAP0);
2051 }
2052 if (le16_to_cpu(status) & 2)
2053 ai->dev->stats.tx_aborted_errors++;
2054 if (le16_to_cpu(status) & 4)
2055 ai->dev->stats.tx_heartbeat_errors++;
2056 if (le16_to_cpu(status) & 8)
2057 { }
2058 if (le16_to_cpu(status) & 0x10)
2059 ai->dev->stats.tx_carrier_errors++;
2060 if (le16_to_cpu(status) & 0x20)
2061 { }
2062
2063
2064
2065
2066 if ((le16_to_cpu(status) & 2) ||
2067 (le16_to_cpu(status) & 4)) {
2068 union iwreq_data wrqu;
2069 char junk[0x18];
2070
2071
2072
2073
2074 bap_read(ai, (__le16 *) junk, 0x18, BAP0);
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084 memcpy(wrqu.addr.sa_data, junk + 0x12, ETH_ALEN);
2085 wrqu.addr.sa_family = ARPHRD_ETHER;
2086
2087
2088 wireless_send_event(ai->dev, IWEVTXDROP, &wrqu, NULL);
2089 }
2090}
2091
2092static void airo_end_xmit(struct net_device *dev) {
2093 u16 status;
2094 int i;
2095 struct airo_info *priv = dev->ml_priv;
2096 struct sk_buff *skb = priv->xmit.skb;
2097 int fid = priv->xmit.fid;
2098 u32 *fids = priv->fids;
2099
2100 clear_bit(JOB_XMIT, &priv->jobs);
2101 clear_bit(FLAG_PENDING_XMIT, &priv->flags);
2102 status = transmit_802_3_packet (priv, fids[fid], skb->data);
2103 up(&priv->sem);
2104
2105 i = 0;
2106 if ( status == SUCCESS ) {
2107 netif_trans_update(dev);
2108 for (; i < MAX_FIDS / 2 && (priv->fids[i] & 0xffff0000); i++);
2109 } else {
2110 priv->fids[fid] &= 0xffff;
2111 dev->stats.tx_window_errors++;
2112 }
2113 if (i < MAX_FIDS / 2)
2114 netif_wake_queue(dev);
2115 dev_kfree_skb(skb);
2116}
2117
2118static netdev_tx_t airo_start_xmit(struct sk_buff *skb,
2119 struct net_device *dev)
2120{
2121 s16 len;
2122 int i, j;
2123 struct airo_info *priv = dev->ml_priv;
2124 u32 *fids = priv->fids;
2125
2126 if ( skb == NULL ) {
2127 airo_print_err(dev->name, "%s: skb == NULL!", __func__);
2128 return NETDEV_TX_OK;
2129 }
2130
2131
2132 for( i = 0; i < MAX_FIDS / 2 && (fids[i] & 0xffff0000); i++ );
2133 for( j = i + 1; j < MAX_FIDS / 2 && (fids[j] & 0xffff0000); j++ );
2134
2135 if ( j >= MAX_FIDS / 2 ) {
2136 netif_stop_queue(dev);
2137
2138 if (i == MAX_FIDS / 2) {
2139 dev->stats.tx_fifo_errors++;
2140 return NETDEV_TX_BUSY;
2141 }
2142 }
2143
2144 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
2145
2146 fids[i] |= (len << 16);
2147 priv->xmit.skb = skb;
2148 priv->xmit.fid = i;
2149 if (down_trylock(&priv->sem) != 0) {
2150 set_bit(FLAG_PENDING_XMIT, &priv->flags);
2151 netif_stop_queue(dev);
2152 set_bit(JOB_XMIT, &priv->jobs);
2153 wake_up_interruptible(&priv->thr_wait);
2154 } else
2155 airo_end_xmit(dev);
2156 return NETDEV_TX_OK;
2157}
2158
2159static void airo_end_xmit11(struct net_device *dev) {
2160 u16 status;
2161 int i;
2162 struct airo_info *priv = dev->ml_priv;
2163 struct sk_buff *skb = priv->xmit11.skb;
2164 int fid = priv->xmit11.fid;
2165 u32 *fids = priv->fids;
2166
2167 clear_bit(JOB_XMIT11, &priv->jobs);
2168 clear_bit(FLAG_PENDING_XMIT11, &priv->flags);
2169 status = transmit_802_11_packet (priv, fids[fid], skb->data);
2170 up(&priv->sem);
2171
2172 i = MAX_FIDS / 2;
2173 if ( status == SUCCESS ) {
2174 netif_trans_update(dev);
2175 for (; i < MAX_FIDS && (priv->fids[i] & 0xffff0000); i++);
2176 } else {
2177 priv->fids[fid] &= 0xffff;
2178 dev->stats.tx_window_errors++;
2179 }
2180 if (i < MAX_FIDS)
2181 netif_wake_queue(dev);
2182 dev_kfree_skb(skb);
2183}
2184
2185static netdev_tx_t airo_start_xmit11(struct sk_buff *skb,
2186 struct net_device *dev)
2187{
2188 s16 len;
2189 int i, j;
2190 struct airo_info *priv = dev->ml_priv;
2191 u32 *fids = priv->fids;
2192
2193 if (test_bit(FLAG_MPI, &priv->flags)) {
2194
2195 netif_stop_queue(dev);
2196 dev_kfree_skb_any(skb);
2197 return NETDEV_TX_OK;
2198 }
2199
2200 if ( skb == NULL ) {
2201 airo_print_err(dev->name, "%s: skb == NULL!", __func__);
2202 return NETDEV_TX_OK;
2203 }
2204
2205
2206 for( i = MAX_FIDS / 2; i < MAX_FIDS && (fids[i] & 0xffff0000); i++ );
2207 for( j = i + 1; j < MAX_FIDS && (fids[j] & 0xffff0000); j++ );
2208
2209 if ( j >= MAX_FIDS ) {
2210 netif_stop_queue(dev);
2211
2212 if (i == MAX_FIDS) {
2213 dev->stats.tx_fifo_errors++;
2214 return NETDEV_TX_BUSY;
2215 }
2216 }
2217
2218 len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
2219
2220 fids[i] |= (len << 16);
2221 priv->xmit11.skb = skb;
2222 priv->xmit11.fid = i;
2223 if (down_trylock(&priv->sem) != 0) {
2224 set_bit(FLAG_PENDING_XMIT11, &priv->flags);
2225 netif_stop_queue(dev);
2226 set_bit(JOB_XMIT11, &priv->jobs);
2227 wake_up_interruptible(&priv->thr_wait);
2228 } else
2229 airo_end_xmit11(dev);
2230 return NETDEV_TX_OK;
2231}
2232
2233static void airo_read_stats(struct net_device *dev)
2234{
2235 struct airo_info *ai = dev->ml_priv;
2236 StatsRid stats_rid;
2237 __le32 *vals = stats_rid.vals;
2238
2239 clear_bit(JOB_STATS, &ai->jobs);
2240 if (ai->power.event) {
2241 up(&ai->sem);
2242 return;
2243 }
2244 readStatsRid(ai, &stats_rid, RID_STATS, 0);
2245 up(&ai->sem);
2246
2247 dev->stats.rx_packets = le32_to_cpu(vals[43]) + le32_to_cpu(vals[44]) +
2248 le32_to_cpu(vals[45]);
2249 dev->stats.tx_packets = le32_to_cpu(vals[39]) + le32_to_cpu(vals[40]) +
2250 le32_to_cpu(vals[41]);
2251 dev->stats.rx_bytes = le32_to_cpu(vals[92]);
2252 dev->stats.tx_bytes = le32_to_cpu(vals[91]);
2253 dev->stats.rx_errors = le32_to_cpu(vals[0]) + le32_to_cpu(vals[2]) +
2254 le32_to_cpu(vals[3]) + le32_to_cpu(vals[4]);
2255 dev->stats.tx_errors = le32_to_cpu(vals[42]) +
2256 dev->stats.tx_fifo_errors;
2257 dev->stats.multicast = le32_to_cpu(vals[43]);
2258 dev->stats.collisions = le32_to_cpu(vals[89]);
2259
2260
2261 dev->stats.rx_length_errors = le32_to_cpu(vals[3]);
2262 dev->stats.rx_crc_errors = le32_to_cpu(vals[4]);
2263 dev->stats.rx_frame_errors = le32_to_cpu(vals[2]);
2264 dev->stats.rx_fifo_errors = le32_to_cpu(vals[0]);
2265}
2266
2267static struct net_device_stats *airo_get_stats(struct net_device *dev)
2268{
2269 struct airo_info *local = dev->ml_priv;
2270
2271 if (!test_bit(JOB_STATS, &local->jobs)) {
2272
2273 if (down_trylock(&local->sem) != 0) {
2274 set_bit(JOB_STATS, &local->jobs);
2275 wake_up_interruptible(&local->thr_wait);
2276 } else
2277 airo_read_stats(dev);
2278 }
2279
2280 return &dev->stats;
2281}
2282
2283static void airo_set_promisc(struct airo_info *ai) {
2284 Cmd cmd;
2285 Resp rsp;
2286
2287 memset(&cmd, 0, sizeof(cmd));
2288 cmd.cmd=CMD_SETMODE;
2289 clear_bit(JOB_PROMISC, &ai->jobs);
2290 cmd.parm0=(ai->flags&IFF_PROMISC) ? PROMISC : NOPROMISC;
2291 issuecommand(ai, &cmd, &rsp);
2292 up(&ai->sem);
2293}
2294
2295static void airo_set_multicast_list(struct net_device *dev) {
2296 struct airo_info *ai = dev->ml_priv;
2297
2298 if ((dev->flags ^ ai->flags) & IFF_PROMISC) {
2299 change_bit(FLAG_PROMISC, &ai->flags);
2300 if (down_trylock(&ai->sem) != 0) {
2301 set_bit(JOB_PROMISC, &ai->jobs);
2302 wake_up_interruptible(&ai->thr_wait);
2303 } else
2304 airo_set_promisc(ai);
2305 }
2306
2307 if ((dev->flags&IFF_ALLMULTI) || !netdev_mc_empty(dev)) {
2308
2309 }
2310}
2311
2312static int airo_set_mac_address(struct net_device *dev, void *p)
2313{
2314 struct airo_info *ai = dev->ml_priv;
2315 struct sockaddr *addr = p;
2316
2317 readConfigRid(ai, 1);
2318 memcpy (ai->config.macAddr, addr->sa_data, dev->addr_len);
2319 set_bit (FLAG_COMMIT, &ai->flags);
2320 disable_MAC(ai, 1);
2321 writeConfigRid (ai, 1);
2322 enable_MAC(ai, 1);
2323 memcpy (ai->dev->dev_addr, addr->sa_data, dev->addr_len);
2324 if (ai->wifidev)
2325 memcpy (ai->wifidev->dev_addr, addr->sa_data, dev->addr_len);
2326 return 0;
2327}
2328
2329static LIST_HEAD(airo_devices);
2330
2331static void add_airo_dev(struct airo_info *ai)
2332{
2333
2334
2335 if (!ai->pci)
2336 list_add_tail(&ai->dev_list, &airo_devices);
2337}
2338
2339static void del_airo_dev(struct airo_info *ai)
2340{
2341 if (!ai->pci)
2342 list_del(&ai->dev_list);
2343}
2344
2345static int airo_close(struct net_device *dev) {
2346 struct airo_info *ai = dev->ml_priv;
2347
2348 netif_stop_queue(dev);
2349
2350 if (ai->wifidev != dev) {
2351#ifdef POWER_ON_DOWN
2352
2353
2354
2355
2356
2357 set_bit(FLAG_RADIO_DOWN, &ai->flags);
2358 disable_MAC(ai, 1);
2359#endif
2360 disable_interrupts( ai );
2361
2362 free_irq(dev->irq, dev);
2363
2364 set_bit(JOB_DIE, &ai->jobs);
2365 kthread_stop(ai->airo_thread_task);
2366 }
2367 return 0;
2368}
2369
2370void stop_airo_card( struct net_device *dev, int freeres )
2371{
2372 struct airo_info *ai = dev->ml_priv;
2373
2374 set_bit(FLAG_RADIO_DOWN, &ai->flags);
2375 disable_MAC(ai, 1);
2376 disable_interrupts(ai);
2377 takedown_proc_entry( dev, ai );
2378 if (test_bit(FLAG_REGISTERED, &ai->flags)) {
2379 unregister_netdev( dev );
2380 if (ai->wifidev) {
2381 unregister_netdev(ai->wifidev);
2382 free_netdev(ai->wifidev);
2383 ai->wifidev = NULL;
2384 }
2385 clear_bit(FLAG_REGISTERED, &ai->flags);
2386 }
2387
2388
2389
2390 if (test_bit(FLAG_MPI, &ai->flags) && !skb_queue_empty(&ai->txq)) {
2391 struct sk_buff *skb = NULL;
2392 for (;(skb = skb_dequeue(&ai->txq));)
2393 dev_kfree_skb(skb);
2394 }
2395
2396 airo_networks_free (ai);
2397
2398 kfree(ai->flash);
2399 kfree(ai->rssi);
2400 kfree(ai->SSID);
2401 if (freeres) {
2402
2403 release_region( dev->base_addr, 64 );
2404 if (test_bit(FLAG_MPI, &ai->flags)) {
2405 if (ai->pci)
2406 mpi_unmap_card(ai->pci);
2407 if (ai->pcimem)
2408 iounmap(ai->pcimem);
2409 if (ai->pciaux)
2410 iounmap(ai->pciaux);
2411 pci_free_consistent(ai->pci, PCI_SHARED_LEN,
2412 ai->shared, ai->shared_dma);
2413 }
2414 }
2415 crypto_free_sync_skcipher(ai->tfm);
2416 del_airo_dev(ai);
2417 free_netdev( dev );
2418}
2419
2420EXPORT_SYMBOL(stop_airo_card);
2421
2422static int wll_header_parse(const struct sk_buff *skb, unsigned char *haddr)
2423{
2424 memcpy(haddr, skb_mac_header(skb) + 10, ETH_ALEN);
2425 return ETH_ALEN;
2426}
2427
2428static void mpi_unmap_card(struct pci_dev *pci)
2429{
2430 unsigned long mem_start = pci_resource_start(pci, 1);
2431 unsigned long mem_len = pci_resource_len(pci, 1);
2432 unsigned long aux_start = pci_resource_start(pci, 2);
2433 unsigned long aux_len = AUXMEMSIZE;
2434
2435 release_mem_region(aux_start, aux_len);
2436 release_mem_region(mem_start, mem_len);
2437}
2438
2439
2440
2441
2442
2443
2444
2445
2446static int mpi_init_descriptors (struct airo_info *ai)
2447{
2448 Cmd cmd;
2449 Resp rsp;
2450 int i;
2451 int rc = SUCCESS;
2452
2453
2454 netif_stop_queue(ai->dev);
2455
2456 memset(&rsp,0,sizeof(rsp));
2457 memset(&cmd,0,sizeof(cmd));
2458
2459 cmd.cmd = CMD_ALLOCATEAUX;
2460 cmd.parm0 = FID_RX;
2461 cmd.parm1 = (ai->rxfids[0].card_ram_off - ai->pciaux);
2462 cmd.parm2 = MPI_MAX_FIDS;
2463 rc=issuecommand(ai, &cmd, &rsp);
2464 if (rc != SUCCESS) {
2465 airo_print_err(ai->dev->name, "Couldn't allocate RX FID");
2466 return rc;
2467 }
2468
2469 for (i=0; i<MPI_MAX_FIDS; i++) {
2470 memcpy_toio(ai->rxfids[i].card_ram_off,
2471 &ai->rxfids[i].rx_desc, sizeof(RxFid));
2472 }
2473
2474
2475
2476 memset(&rsp,0,sizeof(rsp));
2477 memset(&cmd,0,sizeof(cmd));
2478
2479 cmd.cmd = CMD_ALLOCATEAUX;
2480 cmd.parm0 = FID_TX;
2481 cmd.parm1 = (ai->txfids[0].card_ram_off - ai->pciaux);
2482 cmd.parm2 = MPI_MAX_FIDS;
2483
2484 for (i=0; i<MPI_MAX_FIDS; i++) {
2485 ai->txfids[i].tx_desc.valid = 1;
2486 memcpy_toio(ai->txfids[i].card_ram_off,
2487 &ai->txfids[i].tx_desc, sizeof(TxFid));
2488 }
2489 ai->txfids[i-1].tx_desc.eoc = 1;
2490
2491 rc=issuecommand(ai, &cmd, &rsp);
2492 if (rc != SUCCESS) {
2493 airo_print_err(ai->dev->name, "Couldn't allocate TX FID");
2494 return rc;
2495 }
2496
2497
2498 memset(&rsp,0,sizeof(rsp));
2499 memset(&cmd,0,sizeof(cmd));
2500
2501 cmd.cmd = CMD_ALLOCATEAUX;
2502 cmd.parm0 = RID_RW;
2503 cmd.parm1 = (ai->config_desc.card_ram_off - ai->pciaux);
2504 cmd.parm2 = 1;
2505 rc=issuecommand(ai, &cmd, &rsp);
2506 if (rc != SUCCESS) {
2507 airo_print_err(ai->dev->name, "Couldn't allocate RID");
2508 return rc;
2509 }
2510
2511 memcpy_toio(ai->config_desc.card_ram_off,
2512 &ai->config_desc.rid_desc, sizeof(Rid));
2513
2514 return rc;
2515}
2516
2517
2518
2519
2520
2521
2522
2523static int mpi_map_card(struct airo_info *ai, struct pci_dev *pci)
2524{
2525 unsigned long mem_start, mem_len, aux_start, aux_len;
2526 int rc = -1;
2527 int i;
2528 dma_addr_t busaddroff;
2529 unsigned char *vpackoff;
2530 unsigned char __iomem *pciaddroff;
2531
2532 mem_start = pci_resource_start(pci, 1);
2533 mem_len = pci_resource_len(pci, 1);
2534 aux_start = pci_resource_start(pci, 2);
2535 aux_len = AUXMEMSIZE;
2536
2537 if (!request_mem_region(mem_start, mem_len, DRV_NAME)) {
2538 airo_print_err("", "Couldn't get region %x[%x]",
2539 (int)mem_start, (int)mem_len);
2540 goto out;
2541 }
2542 if (!request_mem_region(aux_start, aux_len, DRV_NAME)) {
2543 airo_print_err("", "Couldn't get region %x[%x]",
2544 (int)aux_start, (int)aux_len);
2545 goto free_region1;
2546 }
2547
2548 ai->pcimem = ioremap(mem_start, mem_len);
2549 if (!ai->pcimem) {
2550 airo_print_err("", "Couldn't map region %x[%x]",
2551 (int)mem_start, (int)mem_len);
2552 goto free_region2;
2553 }
2554 ai->pciaux = ioremap(aux_start, aux_len);
2555 if (!ai->pciaux) {
2556 airo_print_err("", "Couldn't map region %x[%x]",
2557 (int)aux_start, (int)aux_len);
2558 goto free_memmap;
2559 }
2560
2561
2562 ai->shared = pci_alloc_consistent(pci, PCI_SHARED_LEN, &ai->shared_dma);
2563 if (!ai->shared) {
2564 airo_print_err("", "Couldn't alloc_consistent %d",
2565 PCI_SHARED_LEN);
2566 goto free_auxmap;
2567 }
2568
2569
2570
2571
2572 busaddroff = ai->shared_dma;
2573 pciaddroff = ai->pciaux + AUX_OFFSET;
2574 vpackoff = ai->shared;
2575
2576
2577 for(i = 0; i < MPI_MAX_FIDS; i++) {
2578 ai->rxfids[i].pending = 0;
2579 ai->rxfids[i].card_ram_off = pciaddroff;
2580 ai->rxfids[i].virtual_host_addr = vpackoff;
2581 ai->rxfids[i].rx_desc.host_addr = busaddroff;
2582 ai->rxfids[i].rx_desc.valid = 1;
2583 ai->rxfids[i].rx_desc.len = PKTSIZE;
2584 ai->rxfids[i].rx_desc.rdy = 0;
2585
2586 pciaddroff += sizeof(RxFid);
2587 busaddroff += PKTSIZE;
2588 vpackoff += PKTSIZE;
2589 }
2590
2591
2592 for(i = 0; i < MPI_MAX_FIDS; i++) {
2593 ai->txfids[i].card_ram_off = pciaddroff;
2594 ai->txfids[i].virtual_host_addr = vpackoff;
2595 ai->txfids[i].tx_desc.valid = 1;
2596 ai->txfids[i].tx_desc.host_addr = busaddroff;
2597 memcpy(ai->txfids[i].virtual_host_addr,
2598 &wifictlhdr8023, sizeof(wifictlhdr8023));
2599
2600 pciaddroff += sizeof(TxFid);
2601 busaddroff += PKTSIZE;
2602 vpackoff += PKTSIZE;
2603 }
2604 ai->txfids[i-1].tx_desc.eoc = 1;
2605
2606
2607 ai->config_desc.card_ram_off = pciaddroff;
2608 ai->config_desc.virtual_host_addr = vpackoff;
2609 ai->config_desc.rid_desc.host_addr = busaddroff;
2610 ai->ridbus = busaddroff;
2611 ai->config_desc.rid_desc.rid = 0;
2612 ai->config_desc.rid_desc.len = RIDSIZE;
2613 ai->config_desc.rid_desc.valid = 1;
2614 pciaddroff += sizeof(Rid);
2615 busaddroff += RIDSIZE;
2616 vpackoff += RIDSIZE;
2617
2618
2619 if (mpi_init_descriptors (ai) != SUCCESS)
2620 goto free_shared;
2621
2622 return 0;
2623 free_shared:
2624 pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
2625 free_auxmap:
2626 iounmap(ai->pciaux);
2627 free_memmap:
2628 iounmap(ai->pcimem);
2629 free_region2:
2630 release_mem_region(aux_start, aux_len);
2631 free_region1:
2632 release_mem_region(mem_start, mem_len);
2633 out:
2634 return rc;
2635}
2636
2637static const struct header_ops airo_header_ops = {
2638 .parse = wll_header_parse,
2639};
2640
2641static const struct net_device_ops airo11_netdev_ops = {
2642 .ndo_open = airo_open,
2643 .ndo_stop = airo_close,
2644 .ndo_start_xmit = airo_start_xmit11,
2645 .ndo_get_stats = airo_get_stats,
2646 .ndo_set_mac_address = airo_set_mac_address,
2647 .ndo_do_ioctl = airo_ioctl,
2648};
2649
2650static void wifi_setup(struct net_device *dev)
2651{
2652 dev->netdev_ops = &airo11_netdev_ops;
2653 dev->header_ops = &airo_header_ops;
2654 dev->wireless_handlers = &airo_handler_def;
2655
2656 dev->type = ARPHRD_IEEE80211;
2657 dev->hard_header_len = ETH_HLEN;
2658 dev->mtu = AIRO_DEF_MTU;
2659 dev->min_mtu = 68;
2660 dev->max_mtu = MIC_MSGLEN_MAX;
2661 dev->addr_len = ETH_ALEN;
2662 dev->tx_queue_len = 100;
2663
2664 eth_broadcast_addr(dev->broadcast);
2665
2666 dev->flags = IFF_BROADCAST|IFF_MULTICAST;
2667}
2668
2669static struct net_device *init_wifidev(struct airo_info *ai,
2670 struct net_device *ethdev)
2671{
2672 int err;
2673 struct net_device *dev = alloc_netdev(0, "wifi%d", NET_NAME_UNKNOWN,
2674 wifi_setup);
2675 if (!dev)
2676 return NULL;
2677 dev->ml_priv = ethdev->ml_priv;
2678 dev->irq = ethdev->irq;
2679 dev->base_addr = ethdev->base_addr;
2680 dev->wireless_data = ethdev->wireless_data;
2681 SET_NETDEV_DEV(dev, ethdev->dev.parent);
2682 eth_hw_addr_inherit(dev, ethdev);
2683 err = register_netdev(dev);
2684 if (err<0) {
2685 free_netdev(dev);
2686 return NULL;
2687 }
2688 return dev;
2689}
2690
2691static int reset_card( struct net_device *dev , int lock) {
2692 struct airo_info *ai = dev->ml_priv;
2693
2694 if (lock && down_interruptible(&ai->sem))
2695 return -1;
2696 waitbusy (ai);
2697 OUT4500(ai,COMMAND,CMD_SOFTRESET);
2698 msleep(200);
2699 waitbusy (ai);
2700 msleep(200);
2701 if (lock)
2702 up(&ai->sem);
2703 return 0;
2704}
2705
2706#define AIRO_MAX_NETWORK_COUNT 64
2707static int airo_networks_allocate(struct airo_info *ai)
2708{
2709 if (ai->networks)
2710 return 0;
2711
2712 ai->networks = kcalloc(AIRO_MAX_NETWORK_COUNT, sizeof(BSSListElement),
2713 GFP_KERNEL);
2714 if (!ai->networks) {
2715 airo_print_warn("", "Out of memory allocating beacons");
2716 return -ENOMEM;
2717 }
2718
2719 return 0;
2720}
2721
2722static void airo_networks_free(struct airo_info *ai)
2723{
2724 kfree(ai->networks);
2725 ai->networks = NULL;
2726}
2727
2728static void airo_networks_initialize(struct airo_info *ai)
2729{
2730 int i;
2731
2732 INIT_LIST_HEAD(&ai->network_free_list);
2733 INIT_LIST_HEAD(&ai->network_list);
2734 for (i = 0; i < AIRO_MAX_NETWORK_COUNT; i++)
2735 list_add_tail(&ai->networks[i].list,
2736 &ai->network_free_list);
2737}
2738
2739static const struct net_device_ops airo_netdev_ops = {
2740 .ndo_open = airo_open,
2741 .ndo_stop = airo_close,
2742 .ndo_start_xmit = airo_start_xmit,
2743 .ndo_get_stats = airo_get_stats,
2744 .ndo_set_rx_mode = airo_set_multicast_list,
2745 .ndo_set_mac_address = airo_set_mac_address,
2746 .ndo_do_ioctl = airo_ioctl,
2747 .ndo_validate_addr = eth_validate_addr,
2748};
2749
2750static const struct net_device_ops mpi_netdev_ops = {
2751 .ndo_open = airo_open,
2752 .ndo_stop = airo_close,
2753 .ndo_start_xmit = mpi_start_xmit,
2754 .ndo_get_stats = airo_get_stats,
2755 .ndo_set_rx_mode = airo_set_multicast_list,
2756 .ndo_set_mac_address = airo_set_mac_address,
2757 .ndo_do_ioctl = airo_ioctl,
2758 .ndo_validate_addr = eth_validate_addr,
2759};
2760
2761
2762static struct net_device *_init_airo_card( unsigned short irq, int port,
2763 int is_pcmcia, struct pci_dev *pci,
2764 struct device *dmdev )
2765{
2766 struct net_device *dev;
2767 struct airo_info *ai;
2768 int i, rc;
2769 CapabilityRid cap_rid;
2770
2771
2772 dev = alloc_netdev(sizeof(*ai), "", NET_NAME_UNKNOWN, ether_setup);
2773 if (!dev) {
2774 airo_print_err("", "Couldn't alloc_etherdev");
2775 return NULL;
2776 }
2777
2778 ai = dev->ml_priv = netdev_priv(dev);
2779 ai->wifidev = NULL;
2780 ai->flags = 1 << FLAG_RADIO_DOWN;
2781 ai->jobs = 0;
2782 ai->dev = dev;
2783 if (pci && (pci->device == 0x5000 || pci->device == 0xa504)) {
2784 airo_print_dbg("", "Found an MPI350 card");
2785 set_bit(FLAG_MPI, &ai->flags);
2786 }
2787 spin_lock_init(&ai->aux_lock);
2788 sema_init(&ai->sem, 1);
2789 ai->config.len = 0;
2790 ai->pci = pci;
2791 init_waitqueue_head (&ai->thr_wait);
2792 ai->tfm = NULL;
2793 add_airo_dev(ai);
2794 ai->APList.len = cpu_to_le16(sizeof(struct APListRid));
2795
2796 if (airo_networks_allocate (ai))
2797 goto err_out_free;
2798 airo_networks_initialize (ai);
2799
2800 skb_queue_head_init (&ai->txq);
2801
2802
2803 if (test_bit(FLAG_MPI,&ai->flags))
2804 dev->netdev_ops = &mpi_netdev_ops;
2805 else
2806 dev->netdev_ops = &airo_netdev_ops;
2807 dev->wireless_handlers = &airo_handler_def;
2808 ai->wireless_data.spy_data = &ai->spy_data;
2809 dev->wireless_data = &ai->wireless_data;
2810 dev->irq = irq;
2811 dev->base_addr = port;
2812 dev->priv_flags &= ~IFF_TX_SKB_SHARING;
2813 dev->max_mtu = MIC_MSGLEN_MAX;
2814
2815 SET_NETDEV_DEV(dev, dmdev);
2816
2817 reset_card (dev, 1);
2818 msleep(400);
2819
2820 if (!is_pcmcia) {
2821 if (!request_region(dev->base_addr, 64, DRV_NAME)) {
2822 rc = -EBUSY;
2823 airo_print_err(dev->name, "Couldn't request region");
2824 goto err_out_nets;
2825 }
2826 }
2827
2828 if (test_bit(FLAG_MPI,&ai->flags)) {
2829 if (mpi_map_card(ai, pci)) {
2830 airo_print_err("", "Could not map memory");
2831 goto err_out_res;
2832 }
2833 }
2834
2835 if (probe) {
2836 if (setup_card(ai, dev->dev_addr, 1) != SUCCESS) {
2837 airo_print_err(dev->name, "MAC could not be enabled" );
2838 rc = -EIO;
2839 goto err_out_map;
2840 }
2841 } else if (!test_bit(FLAG_MPI,&ai->flags)) {
2842 ai->bap_read = fast_bap_read;
2843 set_bit(FLAG_FLASHING, &ai->flags);
2844 }
2845
2846 strcpy(dev->name, "eth%d");
2847 rc = register_netdev(dev);
2848 if (rc) {
2849 airo_print_err(dev->name, "Couldn't register_netdev");
2850 goto err_out_map;
2851 }
2852 ai->wifidev = init_wifidev(ai, dev);
2853 if (!ai->wifidev)
2854 goto err_out_reg;
2855
2856 rc = readCapabilityRid(ai, &cap_rid, 1);
2857 if (rc != SUCCESS) {
2858 rc = -EIO;
2859 goto err_out_wifi;
2860 }
2861
2862 ai->wep_capable = (cap_rid.softCap & cpu_to_le16(0x02)) ? 1 : 0;
2863 ai->max_wep_idx = (cap_rid.softCap & cpu_to_le16(0x80)) ? 3 : 0;
2864
2865 airo_print_info(dev->name, "Firmware version %x.%x.%02d",
2866 ((le16_to_cpu(cap_rid.softVer) >> 8) & 0xF),
2867 (le16_to_cpu(cap_rid.softVer) & 0xFF),
2868 le16_to_cpu(cap_rid.softSubVer));
2869
2870
2871
2872 if (le16_to_cpu(cap_rid.softVer) > 0x530
2873 || (le16_to_cpu(cap_rid.softVer) == 0x530
2874 && le16_to_cpu(cap_rid.softSubVer) >= 17)) {
2875 airo_print_info(ai->dev->name, "WPA supported.");
2876
2877 set_bit(FLAG_WPA_CAPABLE, &ai->flags);
2878 ai->bssListFirst = RID_WPA_BSSLISTFIRST;
2879 ai->bssListNext = RID_WPA_BSSLISTNEXT;
2880 ai->bssListRidLen = sizeof(BSSListRid);
2881 } else {
2882 airo_print_info(ai->dev->name, "WPA unsupported with firmware "
2883 "versions older than 5.30.17.");
2884
2885 ai->bssListFirst = RID_BSSLISTFIRST;
2886 ai->bssListNext = RID_BSSLISTNEXT;
2887 ai->bssListRidLen = sizeof(BSSListRid) - sizeof(BSSListRidExtra);
2888 }
2889
2890 set_bit(FLAG_REGISTERED,&ai->flags);
2891 airo_print_info(dev->name, "MAC enabled %pM", dev->dev_addr);
2892
2893
2894 if (probe && !test_bit(FLAG_MPI,&ai->flags))
2895 for( i = 0; i < MAX_FIDS; i++ )
2896 ai->fids[i] = transmit_allocate(ai,AIRO_DEF_MTU,i>=MAX_FIDS/2);
2897
2898 if (setup_proc_entry(dev, dev->ml_priv) < 0)
2899 goto err_out_wifi;
2900
2901 return dev;
2902
2903err_out_wifi:
2904 unregister_netdev(ai->wifidev);
2905 free_netdev(ai->wifidev);
2906err_out_reg:
2907 unregister_netdev(dev);
2908err_out_map:
2909 if (test_bit(FLAG_MPI,&ai->flags) && pci) {
2910 pci_free_consistent(pci, PCI_SHARED_LEN, ai->shared, ai->shared_dma);
2911 iounmap(ai->pciaux);
2912 iounmap(ai->pcimem);
2913 mpi_unmap_card(ai->pci);
2914 }
2915err_out_res:
2916 if (!is_pcmcia)
2917 release_region( dev->base_addr, 64 );
2918err_out_nets:
2919 airo_networks_free(ai);
2920err_out_free:
2921 del_airo_dev(ai);
2922 free_netdev(dev);
2923 return NULL;
2924}
2925
2926struct net_device *init_airo_card( unsigned short irq, int port, int is_pcmcia,
2927 struct device *dmdev)
2928{
2929 return _init_airo_card ( irq, port, is_pcmcia, NULL, dmdev);
2930}
2931
2932EXPORT_SYMBOL(init_airo_card);
2933
2934static int waitbusy (struct airo_info *ai) {
2935 int delay = 0;
2936 while ((IN4500(ai, COMMAND) & COMMAND_BUSY) && (delay < 10000)) {
2937 udelay (10);
2938 if ((++delay % 20) == 0)
2939 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
2940 }
2941 return delay < 10000;
2942}
2943
2944int reset_airo_card( struct net_device *dev )
2945{
2946 int i;
2947 struct airo_info *ai = dev->ml_priv;
2948
2949 if (reset_card (dev, 1))
2950 return -1;
2951
2952 if ( setup_card(ai, dev->dev_addr, 1 ) != SUCCESS ) {
2953 airo_print_err(dev->name, "MAC could not be enabled");
2954 return -1;
2955 }
2956 airo_print_info(dev->name, "MAC enabled %pM", dev->dev_addr);
2957
2958 if (!test_bit(FLAG_MPI,&ai->flags))
2959 for( i = 0; i < MAX_FIDS; i++ )
2960 ai->fids[i] = transmit_allocate (ai,AIRO_DEF_MTU,i>=MAX_FIDS/2);
2961
2962 enable_interrupts( ai );
2963 netif_wake_queue(dev);
2964 return 0;
2965}
2966
2967EXPORT_SYMBOL(reset_airo_card);
2968
2969static void airo_send_event(struct net_device *dev) {
2970 struct airo_info *ai = dev->ml_priv;
2971 union iwreq_data wrqu;
2972 StatusRid status_rid;
2973
2974 clear_bit(JOB_EVENT, &ai->jobs);
2975 PC4500_readrid(ai, RID_STATUS, &status_rid, sizeof(status_rid), 0);
2976 up(&ai->sem);
2977 wrqu.data.length = 0;
2978 wrqu.data.flags = 0;
2979 memcpy(wrqu.ap_addr.sa_data, status_rid.bssid[0], ETH_ALEN);
2980 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
2981
2982
2983 wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
2984}
2985
2986static void airo_process_scan_results (struct airo_info *ai) {
2987 union iwreq_data wrqu;
2988 BSSListRid bss;
2989 int rc;
2990 BSSListElement * loop_net;
2991 BSSListElement * tmp_net;
2992
2993
2994 list_for_each_entry_safe (loop_net, tmp_net, &ai->network_list, list) {
2995 list_move_tail (&loop_net->list, &ai->network_free_list);
2996
2997 memset (loop_net, 0, sizeof (loop_net->bss));
2998 }
2999
3000
3001 rc = PC4500_readrid(ai, ai->bssListFirst, &bss, ai->bssListRidLen, 0);
3002 if((rc) || (bss.index == cpu_to_le16(0xffff))) {
3003
3004 goto out;
3005 }
3006
3007
3008 tmp_net = NULL;
3009 while((!rc) && (bss.index != cpu_to_le16(0xffff))) {
3010
3011 if (!list_empty(&ai->network_free_list)) {
3012 tmp_net = list_entry(ai->network_free_list.next,
3013 BSSListElement, list);
3014 list_del(ai->network_free_list.next);
3015 }
3016
3017 if (tmp_net != NULL) {
3018 memcpy(tmp_net, &bss, sizeof(tmp_net->bss));
3019 list_add_tail(&tmp_net->list, &ai->network_list);
3020 tmp_net = NULL;
3021 }
3022
3023
3024 rc = PC4500_readrid(ai, ai->bssListNext,
3025 &bss, ai->bssListRidLen, 0);
3026 }
3027
3028out:
3029
3030 disable_MAC(ai, 2);
3031 writeAPListRid(ai, &ai->APList, 0);
3032 enable_MAC(ai, 0);
3033
3034 ai->scan_timeout = 0;
3035 clear_bit(JOB_SCAN_RESULTS, &ai->jobs);
3036 up(&ai->sem);
3037
3038
3039
3040
3041
3042
3043
3044
3045 wrqu.data.length = 0;
3046 wrqu.data.flags = 0;
3047 wireless_send_event(ai->dev, SIOCGIWSCAN, &wrqu, NULL);
3048}
3049
3050static int airo_thread(void *data) {
3051 struct net_device *dev = data;
3052 struct airo_info *ai = dev->ml_priv;
3053 int locked;
3054
3055 set_freezable();
3056 while(1) {
3057
3058 try_to_freeze();
3059
3060 if (test_bit(JOB_DIE, &ai->jobs))
3061 break;
3062
3063 if (ai->jobs) {
3064 locked = down_interruptible(&ai->sem);
3065 } else {
3066 wait_queue_entry_t wait;
3067
3068 init_waitqueue_entry(&wait, current);
3069 add_wait_queue(&ai->thr_wait, &wait);
3070 for (;;) {
3071 set_current_state(TASK_INTERRUPTIBLE);
3072 if (ai->jobs)
3073 break;
3074 if (ai->expires || ai->scan_timeout) {
3075 if (ai->scan_timeout &&
3076 time_after_eq(jiffies,ai->scan_timeout)){
3077 set_bit(JOB_SCAN_RESULTS, &ai->jobs);
3078 break;
3079 } else if (ai->expires &&
3080 time_after_eq(jiffies,ai->expires)){
3081 set_bit(JOB_AUTOWEP, &ai->jobs);
3082 break;
3083 }
3084 if (!kthread_should_stop() &&
3085 !freezing(current)) {
3086 unsigned long wake_at;
3087 if (!ai->expires || !ai->scan_timeout) {
3088 wake_at = max(ai->expires,
3089 ai->scan_timeout);
3090 } else {
3091 wake_at = min(ai->expires,
3092 ai->scan_timeout);
3093 }
3094 schedule_timeout(wake_at - jiffies);
3095 continue;
3096 }
3097 } else if (!kthread_should_stop() &&
3098 !freezing(current)) {
3099 schedule();
3100 continue;
3101 }
3102 break;
3103 }
3104 current->state = TASK_RUNNING;
3105 remove_wait_queue(&ai->thr_wait, &wait);
3106 locked = 1;
3107 }
3108
3109 if (locked)
3110 continue;
3111
3112 if (test_bit(JOB_DIE, &ai->jobs)) {
3113 up(&ai->sem);
3114 break;
3115 }
3116
3117 if (ai->power.event || test_bit(FLAG_FLASHING, &ai->flags)) {
3118 up(&ai->sem);
3119 continue;
3120 }
3121
3122 if (test_bit(JOB_XMIT, &ai->jobs))
3123 airo_end_xmit(dev);
3124 else if (test_bit(JOB_XMIT11, &ai->jobs))
3125 airo_end_xmit11(dev);
3126 else if (test_bit(JOB_STATS, &ai->jobs))
3127 airo_read_stats(dev);
3128 else if (test_bit(JOB_WSTATS, &ai->jobs))
3129 airo_read_wireless_stats(ai);
3130 else if (test_bit(JOB_PROMISC, &ai->jobs))
3131 airo_set_promisc(ai);
3132 else if (test_bit(JOB_MIC, &ai->jobs))
3133 micinit(ai);
3134 else if (test_bit(JOB_EVENT, &ai->jobs))
3135 airo_send_event(dev);
3136 else if (test_bit(JOB_AUTOWEP, &ai->jobs))
3137 timer_func(dev);
3138 else if (test_bit(JOB_SCAN_RESULTS, &ai->jobs))
3139 airo_process_scan_results(ai);
3140 else
3141 up(&ai->sem);
3142 }
3143
3144 return 0;
3145}
3146
3147static int header_len(__le16 ctl)
3148{
3149 u16 fc = le16_to_cpu(ctl);
3150 switch (fc & 0xc) {
3151 case 4:
3152 if ((fc & 0xe0) == 0xc0)
3153 return 10;
3154 return 16;
3155 case 8:
3156 if ((fc & 0x300) == 0x300)
3157 return 30;
3158 }
3159 return 24;
3160}
3161
3162static void airo_handle_cisco_mic(struct airo_info *ai)
3163{
3164 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags)) {
3165 set_bit(JOB_MIC, &ai->jobs);
3166 wake_up_interruptible(&ai->thr_wait);
3167 }
3168}
3169
3170
3171#define STAT_NOBEACON 0x8000
3172#define STAT_MAXRETRIES 0x8001
3173#define STAT_MAXARL 0x8002
3174#define STAT_FORCELOSS 0x8003
3175#define STAT_TSFSYNC 0x8004
3176#define STAT_DEAUTH 0x8100
3177#define STAT_DISASSOC 0x8200
3178#define STAT_ASSOC_FAIL 0x8400
3179#define STAT_AUTH_FAIL 0x0300
3180#define STAT_ASSOC 0x0400
3181#define STAT_REASSOC 0x0600
3182
3183static void airo_print_status(const char *devname, u16 status)
3184{
3185 u8 reason = status & 0xFF;
3186
3187 switch (status & 0xFF00) {
3188 case STAT_NOBEACON:
3189 switch (status) {
3190 case STAT_NOBEACON:
3191 airo_print_dbg(devname, "link lost (missed beacons)");
3192 break;
3193 case STAT_MAXRETRIES:
3194 case STAT_MAXARL:
3195 airo_print_dbg(devname, "link lost (max retries)");
3196 break;
3197 case STAT_FORCELOSS:
3198 airo_print_dbg(devname, "link lost (local choice)");
3199 break;
3200 case STAT_TSFSYNC:
3201 airo_print_dbg(devname, "link lost (TSF sync lost)");
3202 break;
3203 default:
3204 airo_print_dbg(devname, "unknown status %x\n", status);
3205 break;
3206 }
3207 break;
3208 case STAT_DEAUTH:
3209 airo_print_dbg(devname, "deauthenticated (reason: %d)", reason);
3210 break;
3211 case STAT_DISASSOC:
3212 airo_print_dbg(devname, "disassociated (reason: %d)", reason);
3213 break;
3214 case STAT_ASSOC_FAIL:
3215 airo_print_dbg(devname, "association failed (reason: %d)",
3216 reason);
3217 break;
3218 case STAT_AUTH_FAIL:
3219 airo_print_dbg(devname, "authentication failed (reason: %d)",
3220 reason);
3221 break;
3222 case STAT_ASSOC:
3223 case STAT_REASSOC:
3224 break;
3225 default:
3226 airo_print_dbg(devname, "unknown status %x\n", status);
3227 break;
3228 }
3229}
3230
3231static void airo_handle_link(struct airo_info *ai)
3232{
3233 union iwreq_data wrqu;
3234 int scan_forceloss = 0;
3235 u16 status;
3236
3237
3238 status = le16_to_cpu(IN4500(ai, LINKSTAT));
3239 OUT4500(ai, EVACK, EV_LINK);
3240
3241 if ((status == STAT_FORCELOSS) && (ai->scan_timeout > 0))
3242 scan_forceloss = 1;
3243
3244 airo_print_status(ai->dev->name, status);
3245
3246 if ((status == STAT_ASSOC) || (status == STAT_REASSOC)) {
3247 if (auto_wep)
3248 ai->expires = 0;
3249 if (ai->list_bss_task)
3250 wake_up_process(ai->list_bss_task);
3251 set_bit(FLAG_UPDATE_UNI, &ai->flags);
3252 set_bit(FLAG_UPDATE_MULTI, &ai->flags);
3253
3254 if (down_trylock(&ai->sem) != 0) {
3255 set_bit(JOB_EVENT, &ai->jobs);
3256 wake_up_interruptible(&ai->thr_wait);
3257 } else
3258 airo_send_event(ai->dev);
3259 netif_carrier_on(ai->dev);
3260 } else if (!scan_forceloss) {
3261 if (auto_wep && !ai->expires) {
3262 ai->expires = RUN_AT(3*HZ);
3263 wake_up_interruptible(&ai->thr_wait);
3264 }
3265
3266
3267 eth_zero_addr(wrqu.ap_addr.sa_data);
3268 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3269 wireless_send_event(ai->dev, SIOCGIWAP, &wrqu, NULL);
3270 netif_carrier_off(ai->dev);
3271 } else {
3272 netif_carrier_off(ai->dev);
3273 }
3274}
3275
3276static void airo_handle_rx(struct airo_info *ai)
3277{
3278 struct sk_buff *skb = NULL;
3279 __le16 fc, v, *buffer, tmpbuf[4];
3280 u16 len, hdrlen = 0, gap, fid;
3281 struct rx_hdr hdr;
3282 int success = 0;
3283
3284 if (test_bit(FLAG_MPI, &ai->flags)) {
3285 if (test_bit(FLAG_802_11, &ai->flags))
3286 mpi_receive_802_11(ai);
3287 else
3288 mpi_receive_802_3(ai);
3289 OUT4500(ai, EVACK, EV_RX);
3290 return;
3291 }
3292
3293 fid = IN4500(ai, RXFID);
3294
3295
3296 if (test_bit(FLAG_802_11, &ai->flags)) {
3297 bap_setup (ai, fid, 4, BAP0);
3298 bap_read (ai, (__le16*)&hdr, sizeof(hdr), BAP0);
3299
3300 if (le16_to_cpu(hdr.status) & 2)
3301 hdr.len = 0;
3302 if (ai->wifidev == NULL)
3303 hdr.len = 0;
3304 } else {
3305 bap_setup(ai, fid, 0x36, BAP0);
3306 bap_read(ai, &hdr.len, 2, BAP0);
3307 }
3308 len = le16_to_cpu(hdr.len);
3309
3310 if (len > AIRO_DEF_MTU) {
3311 airo_print_err(ai->dev->name, "Bad size %d", len);
3312 goto done;
3313 }
3314 if (len == 0)
3315 goto done;
3316
3317 if (test_bit(FLAG_802_11, &ai->flags)) {
3318 bap_read(ai, &fc, sizeof (fc), BAP0);
3319 hdrlen = header_len(fc);
3320 } else
3321 hdrlen = ETH_ALEN * 2;
3322
3323 skb = dev_alloc_skb(len + hdrlen + 2 + 2);
3324 if (!skb) {
3325 ai->dev->stats.rx_dropped++;
3326 goto done;
3327 }
3328
3329 skb_reserve(skb, 2);
3330 buffer = skb_put(skb, len + hdrlen);
3331 if (test_bit(FLAG_802_11, &ai->flags)) {
3332 buffer[0] = fc;
3333 bap_read(ai, buffer + 1, hdrlen - 2, BAP0);
3334 if (hdrlen == 24)
3335 bap_read(ai, tmpbuf, 6, BAP0);
3336
3337 bap_read(ai, &v, sizeof(v), BAP0);
3338 gap = le16_to_cpu(v);
3339 if (gap) {
3340 if (gap <= 8) {
3341 bap_read(ai, tmpbuf, gap, BAP0);
3342 } else {
3343 airo_print_err(ai->dev->name, "gaplen too "
3344 "big. Problems will follow...");
3345 }
3346 }
3347 bap_read(ai, buffer + hdrlen/2, len, BAP0);
3348 } else {
3349 MICBuffer micbuf;
3350
3351 bap_read(ai, buffer, ETH_ALEN * 2, BAP0);
3352 if (ai->micstats.enabled) {
3353 bap_read(ai, (__le16 *) &micbuf, sizeof (micbuf), BAP0);
3354 if (ntohs(micbuf.typelen) > 0x05DC)
3355 bap_setup(ai, fid, 0x44, BAP0);
3356 else {
3357 if (len <= sizeof (micbuf)) {
3358 dev_kfree_skb_irq(skb);
3359 goto done;
3360 }
3361
3362 len -= sizeof(micbuf);
3363 skb_trim(skb, len + hdrlen);
3364 }
3365 }
3366
3367 bap_read(ai, buffer + ETH_ALEN, len, BAP0);
3368 if (decapsulate(ai, &micbuf, (etherHead*) buffer, len))
3369 dev_kfree_skb_irq (skb);
3370 else
3371 success = 1;
3372 }
3373
3374#ifdef WIRELESS_SPY
3375 if (success && (ai->spy_data.spy_number > 0)) {
3376 char *sa;
3377 struct iw_quality wstats;
3378
3379
3380 if (!test_bit(FLAG_802_11, &ai->flags)) {
3381 sa = (char *) buffer + 6;
3382 bap_setup(ai, fid, 8, BAP0);
3383 bap_read(ai, (__le16 *) hdr.rssi, 2, BAP0);
3384 } else
3385 sa = (char *) buffer + 10;
3386 wstats.qual = hdr.rssi[0];
3387 if (ai->rssi)
3388 wstats.level = 0x100 - ai->rssi[hdr.rssi[1]].rssidBm;
3389 else
3390 wstats.level = (hdr.rssi[1] + 321) / 2;
3391 wstats.noise = ai->wstats.qual.noise;
3392 wstats.updated = IW_QUAL_LEVEL_UPDATED
3393 | IW_QUAL_QUAL_UPDATED
3394 | IW_QUAL_DBM;
3395
3396 wireless_spy_update(ai->dev, sa, &wstats);
3397 }
3398#endif
3399
3400done:
3401 OUT4500(ai, EVACK, EV_RX);
3402
3403 if (success) {
3404 if (test_bit(FLAG_802_11, &ai->flags)) {
3405 skb_reset_mac_header(skb);
3406 skb->pkt_type = PACKET_OTHERHOST;
3407 skb->dev = ai->wifidev;
3408 skb->protocol = htons(ETH_P_802_2);
3409 } else
3410 skb->protocol = eth_type_trans(skb, ai->dev);
3411 skb->ip_summed = CHECKSUM_NONE;
3412
3413 netif_rx(skb);
3414 }
3415}
3416
3417static void airo_handle_tx(struct airo_info *ai, u16 status)
3418{
3419 int i, index = -1;
3420 u16 fid;
3421
3422 if (test_bit(FLAG_MPI, &ai->flags)) {
3423 unsigned long flags;
3424
3425 if (status & EV_TXEXC)
3426 get_tx_error(ai, -1);
3427
3428 spin_lock_irqsave(&ai->aux_lock, flags);
3429 if (!skb_queue_empty(&ai->txq)) {
3430 spin_unlock_irqrestore(&ai->aux_lock,flags);
3431 mpi_send_packet(ai->dev);
3432 } else {
3433 clear_bit(FLAG_PENDING_XMIT, &ai->flags);
3434 spin_unlock_irqrestore(&ai->aux_lock,flags);
3435 netif_wake_queue(ai->dev);
3436 }
3437 OUT4500(ai, EVACK, status & (EV_TX | EV_TXCPY | EV_TXEXC));
3438 return;
3439 }
3440
3441 fid = IN4500(ai, TXCOMPLFID);
3442
3443 for (i = 0; i < MAX_FIDS; i++) {
3444 if ((ai->fids[i] & 0xffff) == fid)
3445 index = i;
3446 }
3447
3448 if (index != -1) {
3449 if (status & EV_TXEXC)
3450 get_tx_error(ai, index);
3451
3452 OUT4500(ai, EVACK, status & (EV_TX | EV_TXEXC));
3453
3454
3455 ai->fids[index] &= 0xffff;
3456 if (index < MAX_FIDS / 2) {
3457 if (!test_bit(FLAG_PENDING_XMIT, &ai->flags))
3458 netif_wake_queue(ai->dev);
3459 } else {
3460 if (!test_bit(FLAG_PENDING_XMIT11, &ai->flags))
3461 netif_wake_queue(ai->wifidev);
3462 }
3463 } else {
3464 OUT4500(ai, EVACK, status & (EV_TX | EV_TXCPY | EV_TXEXC));
3465 airo_print_err(ai->dev->name, "Unallocated FID was used to xmit");
3466 }
3467}
3468
3469static irqreturn_t airo_interrupt(int irq, void *dev_id)
3470{
3471 struct net_device *dev = dev_id;
3472 u16 status, savedInterrupts = 0;
3473 struct airo_info *ai = dev->ml_priv;
3474 int handled = 0;
3475
3476 if (!netif_device_present(dev))
3477 return IRQ_NONE;
3478
3479 for (;;) {
3480 status = IN4500(ai, EVSTAT);
3481 if (!(status & STATUS_INTS) || (status == 0xffff))
3482 break;
3483
3484 handled = 1;
3485
3486 if (status & EV_AWAKE) {
3487 OUT4500(ai, EVACK, EV_AWAKE);
3488 OUT4500(ai, EVACK, EV_AWAKE);
3489 }
3490
3491 if (!savedInterrupts) {
3492 savedInterrupts = IN4500(ai, EVINTEN);
3493 OUT4500(ai, EVINTEN, 0);
3494 }
3495
3496 if (status & EV_MIC) {
3497 OUT4500(ai, EVACK, EV_MIC);
3498 airo_handle_cisco_mic(ai);
3499 }
3500
3501 if (status & EV_LINK) {
3502
3503 airo_handle_link(ai);
3504 }
3505
3506
3507 if (status & EV_RX)
3508 airo_handle_rx(ai);
3509
3510
3511 if (status & (EV_TX | EV_TXCPY | EV_TXEXC))
3512 airo_handle_tx(ai, status);
3513
3514 if ( status & ~STATUS_INTS & ~IGNORE_INTS ) {
3515 airo_print_warn(ai->dev->name, "Got weird status %x",
3516 status & ~STATUS_INTS & ~IGNORE_INTS );
3517 }
3518 }
3519
3520 if (savedInterrupts)
3521 OUT4500(ai, EVINTEN, savedInterrupts);
3522
3523 return IRQ_RETVAL(handled);
3524}
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535static void OUT4500( struct airo_info *ai, u16 reg, u16 val ) {
3536 if (test_bit(FLAG_MPI,&ai->flags))
3537 reg <<= 1;
3538 if ( !do8bitIO )
3539 outw( val, ai->dev->base_addr + reg );
3540 else {
3541 outb( val & 0xff, ai->dev->base_addr + reg );
3542 outb( val >> 8, ai->dev->base_addr + reg + 1 );
3543 }
3544}
3545
3546static u16 IN4500( struct airo_info *ai, u16 reg ) {
3547 unsigned short rc;
3548
3549 if (test_bit(FLAG_MPI,&ai->flags))
3550 reg <<= 1;
3551 if ( !do8bitIO )
3552 rc = inw( ai->dev->base_addr + reg );
3553 else {
3554 rc = inb( ai->dev->base_addr + reg );
3555 rc += ((int)inb( ai->dev->base_addr + reg + 1 )) << 8;
3556 }
3557 return rc;
3558}
3559
3560static int enable_MAC(struct airo_info *ai, int lock)
3561{
3562 int rc;
3563 Cmd cmd;
3564 Resp rsp;
3565
3566
3567
3568
3569
3570
3571
3572 if (ai->flags & FLAG_RADIO_MASK) return SUCCESS;
3573
3574 if (lock && down_interruptible(&ai->sem))
3575 return -ERESTARTSYS;
3576
3577 if (!test_bit(FLAG_ENABLED, &ai->flags)) {
3578 memset(&cmd, 0, sizeof(cmd));
3579 cmd.cmd = MAC_ENABLE;
3580 rc = issuecommand(ai, &cmd, &rsp);
3581 if (rc == SUCCESS)
3582 set_bit(FLAG_ENABLED, &ai->flags);
3583 } else
3584 rc = SUCCESS;
3585
3586 if (lock)
3587 up(&ai->sem);
3588
3589 if (rc)
3590 airo_print_err(ai->dev->name, "Cannot enable MAC");
3591 else if ((rsp.status & 0xFF00) != 0) {
3592 airo_print_err(ai->dev->name, "Bad MAC enable reason=%x, "
3593 "rid=%x, offset=%d", rsp.rsp0, rsp.rsp1, rsp.rsp2);
3594 rc = ERROR;
3595 }
3596 return rc;
3597}
3598
3599static void disable_MAC( struct airo_info *ai, int lock ) {
3600 Cmd cmd;
3601 Resp rsp;
3602
3603 if (lock == 1 && down_interruptible(&ai->sem))
3604 return;
3605
3606 if (test_bit(FLAG_ENABLED, &ai->flags)) {
3607 if (lock != 2)
3608 netif_carrier_off(ai->dev);
3609 memset(&cmd, 0, sizeof(cmd));
3610 cmd.cmd = MAC_DISABLE;
3611 issuecommand(ai, &cmd, &rsp);
3612 clear_bit(FLAG_ENABLED, &ai->flags);
3613 }
3614 if (lock == 1)
3615 up(&ai->sem);
3616}
3617
3618static void enable_interrupts( struct airo_info *ai ) {
3619
3620 OUT4500( ai, EVINTEN, STATUS_INTS );
3621}
3622
3623static void disable_interrupts( struct airo_info *ai ) {
3624 OUT4500( ai, EVINTEN, 0 );
3625}
3626
3627static void mpi_receive_802_3(struct airo_info *ai)
3628{
3629 RxFid rxd;
3630 int len = 0;
3631 struct sk_buff *skb;
3632 char *buffer;
3633 int off = 0;
3634 MICBuffer micbuf;
3635
3636 memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
3637
3638 if (rxd.rdy && rxd.valid == 0) {
3639 len = rxd.len + 12;
3640 if (len < 12 || len > 2048)
3641 goto badrx;
3642
3643 skb = dev_alloc_skb(len);
3644 if (!skb) {
3645 ai->dev->stats.rx_dropped++;
3646 goto badrx;
3647 }
3648 buffer = skb_put(skb,len);
3649 memcpy(buffer, ai->rxfids[0].virtual_host_addr, ETH_ALEN * 2);
3650 if (ai->micstats.enabled) {
3651 memcpy(&micbuf,
3652 ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2,
3653 sizeof(micbuf));
3654 if (ntohs(micbuf.typelen) <= 0x05DC) {
3655 if (len <= sizeof(micbuf) + ETH_ALEN * 2)
3656 goto badmic;
3657
3658 off = sizeof(micbuf);
3659 skb_trim (skb, len - off);
3660 }
3661 }
3662 memcpy(buffer + ETH_ALEN * 2,
3663 ai->rxfids[0].virtual_host_addr + ETH_ALEN * 2 + off,
3664 len - ETH_ALEN * 2 - off);
3665 if (decapsulate (ai, &micbuf, (etherHead*)buffer, len - off - ETH_ALEN * 2)) {
3666badmic:
3667 dev_kfree_skb_irq (skb);
3668 goto badrx;
3669 }
3670#ifdef WIRELESS_SPY
3671 if (ai->spy_data.spy_number > 0) {
3672 char *sa;
3673 struct iw_quality wstats;
3674
3675 sa = buffer + ETH_ALEN;
3676 wstats.qual = 0;
3677 wstats.level = 0;
3678 wstats.updated = 0;
3679
3680 wireless_spy_update(ai->dev, sa, &wstats);
3681 }
3682#endif
3683
3684 skb->ip_summed = CHECKSUM_NONE;
3685 skb->protocol = eth_type_trans(skb, ai->dev);
3686 netif_rx(skb);
3687 }
3688badrx:
3689 if (rxd.valid == 0) {
3690 rxd.valid = 1;
3691 rxd.rdy = 0;
3692 rxd.len = PKTSIZE;
3693 memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
3694 }
3695}
3696
3697static void mpi_receive_802_11(struct airo_info *ai)
3698{
3699 RxFid rxd;
3700 struct sk_buff *skb = NULL;
3701 u16 len, hdrlen = 0;
3702 __le16 fc;
3703 struct rx_hdr hdr;
3704 u16 gap;
3705 u16 *buffer;
3706 char *ptr = ai->rxfids[0].virtual_host_addr + 4;
3707
3708 memcpy_fromio(&rxd, ai->rxfids[0].card_ram_off, sizeof(rxd));
3709 memcpy ((char *)&hdr, ptr, sizeof(hdr));
3710 ptr += sizeof(hdr);
3711
3712 if (le16_to_cpu(hdr.status) & 2)
3713 hdr.len = 0;
3714 if (ai->wifidev == NULL)
3715 hdr.len = 0;
3716 len = le16_to_cpu(hdr.len);
3717 if (len > AIRO_DEF_MTU) {
3718 airo_print_err(ai->dev->name, "Bad size %d", len);
3719 goto badrx;
3720 }
3721 if (len == 0)
3722 goto badrx;
3723
3724 fc = get_unaligned((__le16 *)ptr);
3725 hdrlen = header_len(fc);
3726
3727 skb = dev_alloc_skb( len + hdrlen + 2 );
3728 if ( !skb ) {
3729 ai->dev->stats.rx_dropped++;
3730 goto badrx;
3731 }
3732 buffer = skb_put(skb, len + hdrlen);
3733 memcpy ((char *)buffer, ptr, hdrlen);
3734 ptr += hdrlen;
3735 if (hdrlen == 24)
3736 ptr += 6;
3737 gap = get_unaligned_le16(ptr);
3738 ptr += sizeof(__le16);
3739 if (gap) {
3740 if (gap <= 8)
3741 ptr += gap;
3742 else
3743 airo_print_err(ai->dev->name,
3744 "gaplen too big. Problems will follow...");
3745 }
3746 memcpy ((char *)buffer + hdrlen, ptr, len);
3747 ptr += len;
3748#ifdef IW_WIRELESS_SPY
3749 if (ai->spy_data.spy_number > 0) {
3750 char *sa;
3751 struct iw_quality wstats;
3752
3753 sa = (char*)buffer + 10;
3754 wstats.qual = hdr.rssi[0];
3755 if (ai->rssi)
3756 wstats.level = 0x100 - ai->rssi[hdr.rssi[1]].rssidBm;
3757 else
3758 wstats.level = (hdr.rssi[1] + 321) / 2;
3759 wstats.noise = ai->wstats.qual.noise;
3760 wstats.updated = IW_QUAL_QUAL_UPDATED
3761 | IW_QUAL_LEVEL_UPDATED
3762 | IW_QUAL_DBM;
3763
3764 wireless_spy_update(ai->dev, sa, &wstats);
3765 }
3766#endif
3767 skb_reset_mac_header(skb);
3768 skb->pkt_type = PACKET_OTHERHOST;
3769 skb->dev = ai->wifidev;
3770 skb->protocol = htons(ETH_P_802_2);
3771 skb->ip_summed = CHECKSUM_NONE;
3772 netif_rx( skb );
3773
3774badrx:
3775 if (rxd.valid == 0) {
3776 rxd.valid = 1;
3777 rxd.rdy = 0;
3778 rxd.len = PKTSIZE;
3779 memcpy_toio(ai->rxfids[0].card_ram_off, &rxd, sizeof(rxd));
3780 }
3781}
3782
3783static inline void set_auth_type(struct airo_info *local, int auth_type)
3784{
3785 local->config.authType = auth_type;
3786
3787
3788
3789 if (auth_type == AUTH_OPEN || auth_type == AUTH_ENCRYPT)
3790 local->last_auth = auth_type;
3791}
3792
3793static u16 setup_card(struct airo_info *ai, u8 *mac, int lock)
3794{
3795 Cmd cmd;
3796 Resp rsp;
3797 int status;
3798 SsidRid mySsid;
3799 __le16 lastindex;
3800 WepKeyRid wkr;
3801 int rc;
3802
3803 memset( &mySsid, 0, sizeof( mySsid ) );
3804 kfree (ai->flash);
3805 ai->flash = NULL;
3806
3807
3808 cmd.cmd = NOP;
3809 cmd.parm0 = cmd.parm1 = cmd.parm2 = 0;
3810 if (lock && down_interruptible(&ai->sem))
3811 return ERROR;
3812 if ( issuecommand( ai, &cmd, &rsp ) != SUCCESS ) {
3813 if (lock)
3814 up(&ai->sem);
3815 return ERROR;
3816 }
3817 disable_MAC( ai, 0);
3818
3819
3820 if (!test_bit(FLAG_MPI,&ai->flags)) {
3821 cmd.cmd = CMD_ENABLEAUX;
3822 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
3823 if (lock)
3824 up(&ai->sem);
3825 airo_print_err(ai->dev->name, "Error checking for AUX port");
3826 return ERROR;
3827 }
3828 if (!aux_bap || rsp.status & 0xff00) {
3829 ai->bap_read = fast_bap_read;
3830 airo_print_dbg(ai->dev->name, "Doing fast bap_reads");
3831 } else {
3832 ai->bap_read = aux_bap_read;
3833 airo_print_dbg(ai->dev->name, "Doing AUX bap_reads");
3834 }
3835 }
3836 if (lock)
3837 up(&ai->sem);
3838 if (ai->config.len == 0) {
3839 int i;
3840 tdsRssiRid rssi_rid;
3841 CapabilityRid cap_rid;
3842
3843 kfree(ai->SSID);
3844 ai->SSID = NULL;
3845
3846 status = readConfigRid(ai, lock);
3847 if ( status != SUCCESS ) return ERROR;
3848
3849 status = readCapabilityRid(ai, &cap_rid, lock);
3850 if ( status != SUCCESS ) return ERROR;
3851
3852 status = PC4500_readrid(ai,RID_RSSI,&rssi_rid,sizeof(rssi_rid),lock);
3853 if ( status == SUCCESS ) {
3854 if (ai->rssi || (ai->rssi = kmalloc(512, GFP_KERNEL)) != NULL)
3855 memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512);
3856 }
3857 else {
3858 kfree(ai->rssi);
3859 ai->rssi = NULL;
3860 if (cap_rid.softCap & cpu_to_le16(8))
3861 ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
3862 else
3863 airo_print_warn(ai->dev->name, "unknown received signal "
3864 "level scale");
3865 }
3866 ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS;
3867 set_auth_type(ai, AUTH_OPEN);
3868 ai->config.modulation = MOD_CCK;
3869
3870 if (le16_to_cpu(cap_rid.len) >= sizeof(cap_rid) &&
3871 (cap_rid.extSoftCap & cpu_to_le16(1)) &&
3872 micsetup(ai) == SUCCESS) {
3873 ai->config.opmode |= MODE_MIC;
3874 set_bit(FLAG_MIC_CAPABLE, &ai->flags);
3875 }
3876
3877
3878 for( i = 0; i < ETH_ALEN; i++ ) {
3879 mac[i] = ai->config.macAddr[i];
3880 }
3881
3882
3883
3884 if ( rates[0] ) {
3885 memset(ai->config.rates,0,sizeof(ai->config.rates));
3886 for( i = 0; i < 8 && rates[i]; i++ ) {
3887 ai->config.rates[i] = rates[i];
3888 }
3889 }
3890 set_bit (FLAG_COMMIT, &ai->flags);
3891 }
3892
3893
3894 if ( ssids[0] ) {
3895 int i;
3896 for( i = 0; i < 3 && ssids[i]; i++ ) {
3897 size_t len = strlen(ssids[i]);
3898 if (len > 32)
3899 len = 32;
3900 mySsid.ssids[i].len = cpu_to_le16(len);
3901 memcpy(mySsid.ssids[i].ssid, ssids[i], len);
3902 }
3903 mySsid.len = cpu_to_le16(sizeof(mySsid));
3904 }
3905
3906 status = writeConfigRid(ai, lock);
3907 if ( status != SUCCESS ) return ERROR;
3908
3909
3910 if ( ssids[0] ) {
3911 status = writeSsidRid(ai, &mySsid, lock);
3912 if ( status != SUCCESS ) return ERROR;
3913 }
3914
3915 status = enable_MAC(ai, lock);
3916 if (status != SUCCESS)
3917 return ERROR;
3918
3919
3920 rc = readWepKeyRid(ai, &wkr, 1, lock);
3921 if (rc == SUCCESS) do {
3922 lastindex = wkr.kindex;
3923 if (wkr.kindex == cpu_to_le16(0xffff)) {
3924 ai->defindex = wkr.mac[0];
3925 }
3926 rc = readWepKeyRid(ai, &wkr, 0, lock);
3927 } while(lastindex != wkr.kindex);
3928
3929 try_auto_wep(ai);
3930
3931 return SUCCESS;
3932}
3933
3934static u16 issuecommand(struct airo_info *ai, Cmd *pCmd, Resp *pRsp) {
3935
3936 int max_tries = 600000;
3937
3938 if (IN4500(ai, EVSTAT) & EV_CMD)
3939 OUT4500(ai, EVACK, EV_CMD);
3940
3941 OUT4500(ai, PARAM0, pCmd->parm0);
3942 OUT4500(ai, PARAM1, pCmd->parm1);
3943 OUT4500(ai, PARAM2, pCmd->parm2);
3944 OUT4500(ai, COMMAND, pCmd->cmd);
3945
3946 while (max_tries-- && (IN4500(ai, EVSTAT) & EV_CMD) == 0) {
3947 if ((IN4500(ai, COMMAND)) == pCmd->cmd)
3948
3949 OUT4500(ai, COMMAND, pCmd->cmd);
3950 if (!in_atomic() && (max_tries & 255) == 0)
3951 schedule();
3952 }
3953
3954 if ( max_tries == -1 ) {
3955 airo_print_err(ai->dev->name,
3956 "Max tries exceeded when issuing command");
3957 if (IN4500(ai, COMMAND) & COMMAND_BUSY)
3958 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
3959 return ERROR;
3960 }
3961
3962
3963 pRsp->status = IN4500(ai, STATUS);
3964 pRsp->rsp0 = IN4500(ai, RESP0);
3965 pRsp->rsp1 = IN4500(ai, RESP1);
3966 pRsp->rsp2 = IN4500(ai, RESP2);
3967 if ((pRsp->status & 0xff00)!=0 && pCmd->cmd != CMD_SOFTRESET)
3968 airo_print_err(ai->dev->name,
3969 "cmd:%x status:%x rsp0:%x rsp1:%x rsp2:%x",
3970 pCmd->cmd, pRsp->status, pRsp->rsp0, pRsp->rsp1,
3971 pRsp->rsp2);
3972
3973
3974 if (IN4500(ai, COMMAND) & COMMAND_BUSY) {
3975 OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
3976 }
3977
3978 OUT4500(ai, EVACK, EV_CMD);
3979
3980 return SUCCESS;
3981}
3982
3983
3984
3985
3986static int bap_setup(struct airo_info *ai, u16 rid, u16 offset, int whichbap )
3987{
3988 int timeout = 50;
3989 int max_tries = 3;
3990
3991 OUT4500(ai, SELECT0+whichbap, rid);
3992 OUT4500(ai, OFFSET0+whichbap, offset);
3993 while (1) {
3994 int status = IN4500(ai, OFFSET0+whichbap);
3995 if (status & BAP_BUSY) {
3996
3997
3998 if (timeout--) {
3999 continue;
4000 }
4001 } else if ( status & BAP_ERR ) {
4002
4003 airo_print_err(ai->dev->name, "BAP error %x %d",
4004 status, whichbap );
4005 return ERROR;
4006 } else if (status & BAP_DONE) {
4007 return SUCCESS;
4008 }
4009 if ( !(max_tries--) ) {
4010 airo_print_err(ai->dev->name,
4011 "BAP setup error too many retries\n");
4012 return ERROR;
4013 }
4014
4015 OUT4500(ai, SELECT0+whichbap, rid);
4016 OUT4500(ai, OFFSET0+whichbap, offset);
4017 timeout = 50;
4018 }
4019}
4020
4021
4022
4023
4024static u16 aux_setup(struct airo_info *ai, u16 page,
4025 u16 offset, u16 *len)
4026{
4027 u16 next;
4028
4029 OUT4500(ai, AUXPAGE, page);
4030 OUT4500(ai, AUXOFF, 0);
4031 next = IN4500(ai, AUXDATA);
4032 *len = IN4500(ai, AUXDATA)&0xff;
4033 if (offset != 4) OUT4500(ai, AUXOFF, offset);
4034 return next;
4035}
4036
4037
4038static int aux_bap_read(struct airo_info *ai, __le16 *pu16Dst,
4039 int bytelen, int whichbap)
4040{
4041 u16 len;
4042 u16 page;
4043 u16 offset;
4044 u16 next;
4045 int words;
4046 int i;
4047 unsigned long flags;
4048
4049 spin_lock_irqsave(&ai->aux_lock, flags);
4050 page = IN4500(ai, SWS0+whichbap);
4051 offset = IN4500(ai, SWS2+whichbap);
4052 next = aux_setup(ai, page, offset, &len);
4053 words = (bytelen+1)>>1;
4054
4055 for (i=0; i<words;) {
4056 int count;
4057 count = (len>>1) < (words-i) ? (len>>1) : (words-i);
4058 if ( !do8bitIO )
4059 insw( ai->dev->base_addr+DATA0+whichbap,
4060 pu16Dst+i,count );
4061 else
4062 insb( ai->dev->base_addr+DATA0+whichbap,
4063 pu16Dst+i, count << 1 );
4064 i += count;
4065 if (i<words) {
4066 next = aux_setup(ai, next, 4, &len);
4067 }
4068 }
4069 spin_unlock_irqrestore(&ai->aux_lock, flags);
4070 return SUCCESS;
4071}
4072
4073
4074
4075static int fast_bap_read(struct airo_info *ai, __le16 *pu16Dst,
4076 int bytelen, int whichbap)
4077{
4078 bytelen = (bytelen + 1) & (~1);
4079 if ( !do8bitIO )
4080 insw( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen>>1 );
4081 else
4082 insb( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen );
4083 return SUCCESS;
4084}
4085
4086
4087static int bap_write(struct airo_info *ai, const __le16 *pu16Src,
4088 int bytelen, int whichbap)
4089{
4090 bytelen = (bytelen + 1) & (~1);
4091 if ( !do8bitIO )
4092 outsw( ai->dev->base_addr+DATA0+whichbap,
4093 pu16Src, bytelen>>1 );
4094 else
4095 outsb( ai->dev->base_addr+DATA0+whichbap, pu16Src, bytelen );
4096 return SUCCESS;
4097}
4098
4099static int PC4500_accessrid(struct airo_info *ai, u16 rid, u16 accmd)
4100{
4101 Cmd cmd;
4102 Resp rsp;
4103 u16 status;
4104
4105 memset(&cmd, 0, sizeof(cmd));
4106 cmd.cmd = accmd;
4107 cmd.parm0 = rid;
4108 status = issuecommand(ai, &cmd, &rsp);
4109 if (status != 0) return status;
4110 if ( (rsp.status & 0x7F00) != 0) {
4111 return (accmd << 8) + (rsp.rsp0 & 0xFF);
4112 }
4113 return 0;
4114}
4115
4116
4117
4118static int PC4500_readrid(struct airo_info *ai, u16 rid, void *pBuf, int len, int lock)
4119{
4120 u16 status;
4121 int rc = SUCCESS;
4122
4123 if (lock) {
4124 if (down_interruptible(&ai->sem))
4125 return ERROR;
4126 }
4127 if (test_bit(FLAG_MPI,&ai->flags)) {
4128 Cmd cmd;
4129 Resp rsp;
4130
4131 memset(&cmd, 0, sizeof(cmd));
4132 memset(&rsp, 0, sizeof(rsp));
4133 ai->config_desc.rid_desc.valid = 1;
4134 ai->config_desc.rid_desc.len = RIDSIZE;
4135 ai->config_desc.rid_desc.rid = 0;
4136 ai->config_desc.rid_desc.host_addr = ai->ridbus;
4137
4138 cmd.cmd = CMD_ACCESS;
4139 cmd.parm0 = rid;
4140
4141 memcpy_toio(ai->config_desc.card_ram_off,
4142 &ai->config_desc.rid_desc, sizeof(Rid));
4143
4144 rc = issuecommand(ai, &cmd, &rsp);
4145
4146 if (rsp.status & 0x7f00)
4147 rc = rsp.rsp0;
4148 if (!rc)
4149 memcpy(pBuf, ai->config_desc.virtual_host_addr, len);
4150 goto done;
4151 } else {
4152 if ((status = PC4500_accessrid(ai, rid, CMD_ACCESS))!=SUCCESS) {
4153 rc = status;
4154 goto done;
4155 }
4156 if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
4157 rc = ERROR;
4158 goto done;
4159 }
4160
4161 bap_read(ai, pBuf, 2, BAP1);
4162
4163 len = min(len, (int)le16_to_cpu(*(__le16*)pBuf)) - 2;
4164
4165 if ( len <= 2 ) {
4166 airo_print_err(ai->dev->name,
4167 "Rid %x has a length of %d which is too short",
4168 (int)rid, (int)len );
4169 rc = ERROR;
4170 goto done;
4171 }
4172
4173 rc = bap_read(ai, ((__le16*)pBuf)+1, len, BAP1);
4174 }
4175done:
4176 if (lock)
4177 up(&ai->sem);
4178 return rc;
4179}
4180
4181
4182
4183static int PC4500_writerid(struct airo_info *ai, u16 rid,
4184 const void *pBuf, int len, int lock)
4185{
4186 u16 status;
4187 int rc = SUCCESS;
4188
4189 *(__le16*)pBuf = cpu_to_le16((u16)len);
4190
4191 if (lock) {
4192 if (down_interruptible(&ai->sem))
4193 return ERROR;
4194 }
4195 if (test_bit(FLAG_MPI,&ai->flags)) {
4196 Cmd cmd;
4197 Resp rsp;
4198
4199 if (test_bit(FLAG_ENABLED, &ai->flags) && (RID_WEP_TEMP != rid))
4200 airo_print_err(ai->dev->name,
4201 "%s: MAC should be disabled (rid=%04x)",
4202 __func__, rid);
4203 memset(&cmd, 0, sizeof(cmd));
4204 memset(&rsp, 0, sizeof(rsp));
4205
4206 ai->config_desc.rid_desc.valid = 1;
4207 ai->config_desc.rid_desc.len = *((u16 *)pBuf);
4208 ai->config_desc.rid_desc.rid = 0;
4209
4210 cmd.cmd = CMD_WRITERID;
4211 cmd.parm0 = rid;
4212
4213 memcpy_toio(ai->config_desc.card_ram_off,
4214 &ai->config_desc.rid_desc, sizeof(Rid));
4215
4216 if (len < 4 || len > 2047) {
4217 airo_print_err(ai->dev->name, "%s: len=%d", __func__, len);
4218 rc = -1;
4219 } else {
4220 memcpy(ai->config_desc.virtual_host_addr,
4221 pBuf, len);
4222
4223 rc = issuecommand(ai, &cmd, &rsp);
4224 if ((rc & 0xff00) != 0) {
4225 airo_print_err(ai->dev->name, "%s: Write rid Error %d",
4226 __func__, rc);
4227 airo_print_err(ai->dev->name, "%s: Cmd=%04x",
4228 __func__, cmd.cmd);
4229 }
4230
4231 if ((rsp.status & 0x7f00))
4232 rc = rsp.rsp0;
4233 }
4234 } else {
4235
4236 if ( (status = PC4500_accessrid(ai, rid, CMD_ACCESS)) != 0) {
4237 rc = status;
4238 goto done;
4239 }
4240
4241 if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
4242 rc = ERROR;
4243 goto done;
4244 }
4245 bap_write(ai, pBuf, len, BAP1);
4246
4247 rc = PC4500_accessrid(ai, rid, 0x100|CMD_ACCESS);
4248 }
4249done:
4250 if (lock)
4251 up(&ai->sem);
4252 return rc;
4253}
4254
4255
4256
4257static u16 transmit_allocate(struct airo_info *ai, int lenPayload, int raw)
4258{
4259 unsigned int loop = 3000;
4260 Cmd cmd;
4261 Resp rsp;
4262 u16 txFid;
4263 __le16 txControl;
4264
4265 cmd.cmd = CMD_ALLOCATETX;
4266 cmd.parm0 = lenPayload;
4267 if (down_interruptible(&ai->sem))
4268 return ERROR;
4269 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
4270 txFid = ERROR;
4271 goto done;
4272 }
4273 if ( (rsp.status & 0xFF00) != 0) {
4274 txFid = ERROR;
4275 goto done;
4276 }
4277
4278
4279
4280 while (((IN4500(ai, EVSTAT) & EV_ALLOC) == 0) && --loop);
4281 if (!loop) {
4282 txFid = ERROR;
4283 goto done;
4284 }
4285
4286
4287 txFid = IN4500(ai, TXALLOCFID);
4288 OUT4500(ai, EVACK, EV_ALLOC);
4289
4290
4291
4292
4293
4294
4295 if (raw)
4296 txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_11
4297 | TXCTL_ETHERNET | TXCTL_NORELEASE);
4298 else
4299 txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_3
4300 | TXCTL_ETHERNET | TXCTL_NORELEASE);
4301 if (bap_setup(ai, txFid, 0x0008, BAP1) != SUCCESS)
4302 txFid = ERROR;
4303 else
4304 bap_write(ai, &txControl, sizeof(txControl), BAP1);
4305
4306done:
4307 up(&ai->sem);
4308
4309 return txFid;
4310}
4311
4312
4313
4314
4315static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket)
4316{
4317 __le16 payloadLen;
4318 Cmd cmd;
4319 Resp rsp;
4320 int miclen = 0;
4321 u16 txFid = len;
4322 MICBuffer pMic;
4323
4324 len >>= 16;
4325
4326 if (len <= ETH_ALEN * 2) {
4327 airo_print_warn(ai->dev->name, "Short packet %d", len);
4328 return ERROR;
4329 }
4330 len -= ETH_ALEN * 2;
4331
4332 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags) && ai->micstats.enabled &&
4333 (ntohs(((__be16 *)pPacket)[6]) != 0x888E)) {
4334 if (encapsulate(ai,(etherHead *)pPacket,&pMic,len) != SUCCESS)
4335 return ERROR;
4336 miclen = sizeof(pMic);
4337 }
4338
4339
4340 if (bap_setup(ai, txFid, 0x0036, BAP1) != SUCCESS) return ERROR;
4341
4342
4343 payloadLen = cpu_to_le16(len + miclen);
4344 bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
4345 bap_write(ai, (__le16*)pPacket, sizeof(etherHead), BAP1);
4346 if (miclen)
4347 bap_write(ai, (__le16*)&pMic, miclen, BAP1);
4348 bap_write(ai, (__le16*)(pPacket + sizeof(etherHead)), len, BAP1);
4349
4350 memset( &cmd, 0, sizeof( cmd ) );
4351 cmd.cmd = CMD_TRANSMIT;
4352 cmd.parm0 = txFid;
4353 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
4354 if ( (rsp.status & 0xFF00) != 0) return ERROR;
4355 return SUCCESS;
4356}
4357
4358static int transmit_802_11_packet(struct airo_info *ai, int len, char *pPacket)
4359{
4360 __le16 fc, payloadLen;
4361 Cmd cmd;
4362 Resp rsp;
4363 int hdrlen;
4364 static u8 tail[(30-10) + 2 + 6] = {[30-10] = 6};
4365
4366 u16 txFid = len;
4367 len >>= 16;
4368
4369 fc = *(__le16*)pPacket;
4370 hdrlen = header_len(fc);
4371
4372 if (len < hdrlen) {
4373 airo_print_warn(ai->dev->name, "Short packet %d", len);
4374 return ERROR;
4375 }
4376
4377
4378
4379 if (bap_setup(ai, txFid, 6, BAP1) != SUCCESS) return ERROR;
4380
4381
4382 payloadLen = cpu_to_le16(len-hdrlen);
4383 bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
4384 if (bap_setup(ai, txFid, 0x0014, BAP1) != SUCCESS) return ERROR;
4385 bap_write(ai, (__le16 *)pPacket, hdrlen, BAP1);
4386 bap_write(ai, (__le16 *)(tail + (hdrlen - 10)), 38 - hdrlen, BAP1);
4387
4388 bap_write(ai, (__le16 *)(pPacket + hdrlen), len - hdrlen, BAP1);
4389
4390 memset( &cmd, 0, sizeof( cmd ) );
4391 cmd.cmd = CMD_TRANSMIT;
4392 cmd.parm0 = txFid;
4393 if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
4394 if ( (rsp.status & 0xFF00) != 0) return ERROR;
4395 return SUCCESS;
4396}
4397
4398
4399
4400
4401
4402
4403static ssize_t proc_read( struct file *file,
4404 char __user *buffer,
4405 size_t len,
4406 loff_t *offset);
4407
4408static ssize_t proc_write( struct file *file,
4409 const char __user *buffer,
4410 size_t len,
4411 loff_t *offset );
4412static int proc_close( struct inode *inode, struct file *file );
4413
4414static int proc_stats_open( struct inode *inode, struct file *file );
4415static int proc_statsdelta_open( struct inode *inode, struct file *file );
4416static int proc_status_open( struct inode *inode, struct file *file );
4417static int proc_SSID_open( struct inode *inode, struct file *file );
4418static int proc_APList_open( struct inode *inode, struct file *file );
4419static int proc_BSSList_open( struct inode *inode, struct file *file );
4420static int proc_config_open( struct inode *inode, struct file *file );
4421static int proc_wepkey_open( struct inode *inode, struct file *file );
4422
4423static const struct file_operations proc_statsdelta_ops = {
4424 .owner = THIS_MODULE,
4425 .read = proc_read,
4426 .open = proc_statsdelta_open,
4427 .release = proc_close,
4428 .llseek = default_llseek,
4429};
4430
4431static const struct file_operations proc_stats_ops = {
4432 .owner = THIS_MODULE,
4433 .read = proc_read,
4434 .open = proc_stats_open,
4435 .release = proc_close,
4436 .llseek = default_llseek,
4437};
4438
4439static const struct file_operations proc_status_ops = {
4440 .owner = THIS_MODULE,
4441 .read = proc_read,
4442 .open = proc_status_open,
4443 .release = proc_close,
4444 .llseek = default_llseek,
4445};
4446
4447static const struct file_operations proc_SSID_ops = {
4448 .owner = THIS_MODULE,
4449 .read = proc_read,
4450 .write = proc_write,
4451 .open = proc_SSID_open,
4452 .release = proc_close,
4453 .llseek = default_llseek,
4454};
4455
4456static const struct file_operations proc_BSSList_ops = {
4457 .owner = THIS_MODULE,
4458 .read = proc_read,
4459 .write = proc_write,
4460 .open = proc_BSSList_open,
4461 .release = proc_close,
4462 .llseek = default_llseek,
4463};
4464
4465static const struct file_operations proc_APList_ops = {
4466 .owner = THIS_MODULE,
4467 .read = proc_read,
4468 .write = proc_write,
4469 .open = proc_APList_open,
4470 .release = proc_close,
4471 .llseek = default_llseek,
4472};
4473
4474static const struct file_operations proc_config_ops = {
4475 .owner = THIS_MODULE,
4476 .read = proc_read,
4477 .write = proc_write,
4478 .open = proc_config_open,
4479 .release = proc_close,
4480 .llseek = default_llseek,
4481};
4482
4483static const struct file_operations proc_wepkey_ops = {
4484 .owner = THIS_MODULE,
4485 .read = proc_read,
4486 .write = proc_write,
4487 .open = proc_wepkey_open,
4488 .release = proc_close,
4489 .llseek = default_llseek,
4490};
4491
4492static struct proc_dir_entry *airo_entry;
4493
4494struct proc_data {
4495 int release_buffer;
4496 int readlen;
4497 char *rbuffer;
4498 int writelen;
4499 int maxwritelen;
4500 char *wbuffer;
4501 void (*on_close) (struct inode *, struct file *);
4502};
4503
4504static int setup_proc_entry( struct net_device *dev,
4505 struct airo_info *apriv ) {
4506 struct proc_dir_entry *entry;
4507
4508
4509 strcpy(apriv->proc_name,dev->name);
4510 apriv->proc_entry = proc_mkdir_mode(apriv->proc_name, airo_perm,
4511 airo_entry);
4512 if (!apriv->proc_entry)
4513 return -ENOMEM;
4514 proc_set_user(apriv->proc_entry, proc_kuid, proc_kgid);
4515
4516
4517 entry = proc_create_data("StatsDelta", 0444 & proc_perm,
4518 apriv->proc_entry, &proc_statsdelta_ops, dev);
4519 if (!entry)
4520 goto fail;
4521 proc_set_user(entry, proc_kuid, proc_kgid);
4522
4523
4524 entry = proc_create_data("Stats", 0444 & proc_perm,
4525 apriv->proc_entry, &proc_stats_ops, dev);
4526 if (!entry)
4527 goto fail;
4528 proc_set_user(entry, proc_kuid, proc_kgid);
4529
4530
4531 entry = proc_create_data("Status", 0444 & proc_perm,
4532 apriv->proc_entry, &proc_status_ops, dev);
4533 if (!entry)
4534 goto fail;
4535 proc_set_user(entry, proc_kuid, proc_kgid);
4536
4537
4538 entry = proc_create_data("Config", proc_perm,
4539 apriv->proc_entry, &proc_config_ops, dev);
4540 if (!entry)
4541 goto fail;
4542 proc_set_user(entry, proc_kuid, proc_kgid);
4543
4544
4545 entry = proc_create_data("SSID", proc_perm,
4546 apriv->proc_entry, &proc_SSID_ops, dev);
4547 if (!entry)
4548 goto fail;
4549 proc_set_user(entry, proc_kuid, proc_kgid);
4550
4551
4552 entry = proc_create_data("APList", proc_perm,
4553 apriv->proc_entry, &proc_APList_ops, dev);
4554 if (!entry)
4555 goto fail;
4556 proc_set_user(entry, proc_kuid, proc_kgid);
4557
4558
4559 entry = proc_create_data("BSSList", proc_perm,
4560 apriv->proc_entry, &proc_BSSList_ops, dev);
4561 if (!entry)
4562 goto fail;
4563 proc_set_user(entry, proc_kuid, proc_kgid);
4564
4565
4566 entry = proc_create_data("WepKey", proc_perm,
4567 apriv->proc_entry, &proc_wepkey_ops, dev);
4568 if (!entry)
4569 goto fail;
4570 proc_set_user(entry, proc_kuid, proc_kgid);
4571 return 0;
4572
4573fail:
4574 remove_proc_subtree(apriv->proc_name, airo_entry);
4575 return -ENOMEM;
4576}
4577
4578static int takedown_proc_entry( struct net_device *dev,
4579 struct airo_info *apriv )
4580{
4581 remove_proc_subtree(apriv->proc_name, airo_entry);
4582 return 0;
4583}
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597static ssize_t proc_read( struct file *file,
4598 char __user *buffer,
4599 size_t len,
4600 loff_t *offset )
4601{
4602 struct proc_data *priv = file->private_data;
4603
4604 if (!priv->rbuffer)
4605 return -EINVAL;
4606
4607 return simple_read_from_buffer(buffer, len, offset, priv->rbuffer,
4608 priv->readlen);
4609}
4610
4611
4612
4613
4614
4615static ssize_t proc_write( struct file *file,
4616 const char __user *buffer,
4617 size_t len,
4618 loff_t *offset )
4619{
4620 ssize_t ret;
4621 struct proc_data *priv = file->private_data;
4622
4623 if (!priv->wbuffer)
4624 return -EINVAL;
4625
4626 ret = simple_write_to_buffer(priv->wbuffer, priv->maxwritelen, offset,
4627 buffer, len);
4628 if (ret > 0)
4629 priv->writelen = max_t(int, priv->writelen, *offset);
4630
4631 return ret;
4632}
4633
4634static int proc_status_open(struct inode *inode, struct file *file)
4635{
4636 struct proc_data *data;
4637 struct net_device *dev = PDE_DATA(inode);
4638 struct airo_info *apriv = dev->ml_priv;
4639 CapabilityRid cap_rid;
4640 StatusRid status_rid;
4641 u16 mode;
4642 int i;
4643
4644 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4645 return -ENOMEM;
4646 data = file->private_data;
4647 if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
4648 kfree (file->private_data);
4649 return -ENOMEM;
4650 }
4651
4652 readStatusRid(apriv, &status_rid, 1);
4653 readCapabilityRid(apriv, &cap_rid, 1);
4654
4655 mode = le16_to_cpu(status_rid.mode);
4656
4657 i = sprintf(data->rbuffer, "Status: %s%s%s%s%s%s%s%s%s\n",
4658 mode & 1 ? "CFG ": "",
4659 mode & 2 ? "ACT ": "",
4660 mode & 0x10 ? "SYN ": "",
4661 mode & 0x20 ? "LNK ": "",
4662 mode & 0x40 ? "LEAP ": "",
4663 mode & 0x80 ? "PRIV ": "",
4664 mode & 0x100 ? "KEY ": "",
4665 mode & 0x200 ? "WEP ": "",
4666 mode & 0x8000 ? "ERR ": "");
4667 sprintf( data->rbuffer+i, "Mode: %x\n"
4668 "Signal Strength: %d\n"
4669 "Signal Quality: %d\n"
4670 "SSID: %-.*s\n"
4671 "AP: %-.16s\n"
4672 "Freq: %d\n"
4673 "BitRate: %dmbs\n"
4674 "Driver Version: %s\n"
4675 "Device: %s\nManufacturer: %s\nFirmware Version: %s\n"
4676 "Radio type: %x\nCountry: %x\nHardware Version: %x\n"
4677 "Software Version: %x\nSoftware Subversion: %x\n"
4678 "Boot block version: %x\n",
4679 le16_to_cpu(status_rid.mode),
4680 le16_to_cpu(status_rid.normalizedSignalStrength),
4681 le16_to_cpu(status_rid.signalQuality),
4682 le16_to_cpu(status_rid.SSIDlen),
4683 status_rid.SSID,
4684 status_rid.apName,
4685 le16_to_cpu(status_rid.channel),
4686 le16_to_cpu(status_rid.currentXmitRate) / 2,
4687 version,
4688 cap_rid.prodName,
4689 cap_rid.manName,
4690 cap_rid.prodVer,
4691 le16_to_cpu(cap_rid.radioType),
4692 le16_to_cpu(cap_rid.country),
4693 le16_to_cpu(cap_rid.hardVer),
4694 le16_to_cpu(cap_rid.softVer),
4695 le16_to_cpu(cap_rid.softSubVer),
4696 le16_to_cpu(cap_rid.bootBlockVer));
4697 data->readlen = strlen( data->rbuffer );
4698 return 0;
4699}
4700
4701static int proc_stats_rid_open(struct inode*, struct file*, u16);
4702static int proc_statsdelta_open( struct inode *inode,
4703 struct file *file ) {
4704 if (file->f_mode&FMODE_WRITE) {
4705 return proc_stats_rid_open(inode, file, RID_STATSDELTACLEAR);
4706 }
4707 return proc_stats_rid_open(inode, file, RID_STATSDELTA);
4708}
4709
4710static int proc_stats_open( struct inode *inode, struct file *file ) {
4711 return proc_stats_rid_open(inode, file, RID_STATS);
4712}
4713
4714static int proc_stats_rid_open( struct inode *inode,
4715 struct file *file,
4716 u16 rid )
4717{
4718 struct proc_data *data;
4719 struct net_device *dev = PDE_DATA(inode);
4720 struct airo_info *apriv = dev->ml_priv;
4721 StatsRid stats;
4722 int i, j;
4723 __le32 *vals = stats.vals;
4724 int len;
4725
4726 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4727 return -ENOMEM;
4728 data = file->private_data;
4729 if ((data->rbuffer = kmalloc( 4096, GFP_KERNEL )) == NULL) {
4730 kfree (file->private_data);
4731 return -ENOMEM;
4732 }
4733
4734 readStatsRid(apriv, &stats, rid, 1);
4735 len = le16_to_cpu(stats.len);
4736
4737 j = 0;
4738 for(i=0; statsLabels[i]!=(char *)-1 && i*4<len; i++) {
4739 if (!statsLabels[i]) continue;
4740 if (j+strlen(statsLabels[i])+16>4096) {
4741 airo_print_warn(apriv->dev->name,
4742 "Potentially disastrous buffer overflow averted!");
4743 break;
4744 }
4745 j+=sprintf(data->rbuffer+j, "%s: %u\n", statsLabels[i],
4746 le32_to_cpu(vals[i]));
4747 }
4748 if (i*4 >= len) {
4749 airo_print_warn(apriv->dev->name, "Got a short rid");
4750 }
4751 data->readlen = j;
4752 return 0;
4753}
4754
4755static int get_dec_u16( char *buffer, int *start, int limit ) {
4756 u16 value;
4757 int valid = 0;
4758 for (value = 0; *start < limit && buffer[*start] >= '0' &&
4759 buffer[*start] <= '9'; (*start)++) {
4760 valid = 1;
4761 value *= 10;
4762 value += buffer[*start] - '0';
4763 }
4764 if ( !valid ) return -1;
4765 return value;
4766}
4767
4768static int airo_config_commit(struct net_device *dev,
4769 struct iw_request_info *info, void *zwrq,
4770 char *extra);
4771
4772static inline int sniffing_mode(struct airo_info *ai)
4773{
4774 return (le16_to_cpu(ai->config.rmode) & le16_to_cpu(RXMODE_MASK)) >=
4775 le16_to_cpu(RXMODE_RFMON);
4776}
4777
4778static void proc_config_on_close(struct inode *inode, struct file *file)
4779{
4780 struct proc_data *data = file->private_data;
4781 struct net_device *dev = PDE_DATA(inode);
4782 struct airo_info *ai = dev->ml_priv;
4783 char *line;
4784
4785 if ( !data->writelen ) return;
4786
4787 readConfigRid(ai, 1);
4788 set_bit (FLAG_COMMIT, &ai->flags);
4789
4790 line = data->wbuffer;
4791 while( line[0] ) {
4792
4793 if ( !strncmp( line, "Mode: ", 6 ) ) {
4794 line += 6;
4795 if (sniffing_mode(ai))
4796 set_bit (FLAG_RESET, &ai->flags);
4797 ai->config.rmode &= ~RXMODE_FULL_MASK;
4798 clear_bit (FLAG_802_11, &ai->flags);
4799 ai->config.opmode &= ~MODE_CFG_MASK;
4800 ai->config.scanMode = SCANMODE_ACTIVE;
4801 if ( line[0] == 'a' ) {
4802 ai->config.opmode |= MODE_STA_IBSS;
4803 } else {
4804 ai->config.opmode |= MODE_STA_ESS;
4805 if ( line[0] == 'r' ) {
4806 ai->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
4807 ai->config.scanMode = SCANMODE_PASSIVE;
4808 set_bit (FLAG_802_11, &ai->flags);
4809 } else if ( line[0] == 'y' ) {
4810 ai->config.rmode |= RXMODE_RFMON_ANYBSS | RXMODE_DISABLE_802_3_HEADER;
4811 ai->config.scanMode = SCANMODE_PASSIVE;
4812 set_bit (FLAG_802_11, &ai->flags);
4813 } else if ( line[0] == 'l' )
4814 ai->config.rmode |= RXMODE_LANMON;
4815 }
4816 set_bit (FLAG_COMMIT, &ai->flags);
4817 }
4818
4819
4820 else if (!strncmp(line,"Radio: ", 7)) {
4821 line += 7;
4822 if (!strncmp(line,"off",3)) {
4823 set_bit (FLAG_RADIO_OFF, &ai->flags);
4824 } else {
4825 clear_bit (FLAG_RADIO_OFF, &ai->flags);
4826 }
4827 }
4828
4829 else if ( !strncmp( line, "NodeName: ", 10 ) ) {
4830 int j;
4831
4832 line += 10;
4833 memset( ai->config.nodeName, 0, 16 );
4834
4835 for( j = 0; j < 16 && line[j] != '\n'; j++ ) {
4836 ai->config.nodeName[j] = line[j];
4837 }
4838 set_bit (FLAG_COMMIT, &ai->flags);
4839 }
4840
4841
4842 else if ( !strncmp( line, "PowerMode: ", 11 ) ) {
4843 line += 11;
4844 if ( !strncmp( line, "PSPCAM", 6 ) ) {
4845 ai->config.powerSaveMode = POWERSAVE_PSPCAM;
4846 set_bit (FLAG_COMMIT, &ai->flags);
4847 } else if ( !strncmp( line, "PSP", 3 ) ) {
4848 ai->config.powerSaveMode = POWERSAVE_PSP;
4849 set_bit (FLAG_COMMIT, &ai->flags);
4850 } else {
4851 ai->config.powerSaveMode = POWERSAVE_CAM;
4852 set_bit (FLAG_COMMIT, &ai->flags);
4853 }
4854 } else if ( !strncmp( line, "DataRates: ", 11 ) ) {
4855 int v, i = 0, k = 0;
4856
4857
4858 line += 11;
4859 while((v = get_dec_u16(line, &i, 3))!=-1) {
4860 ai->config.rates[k++] = (u8)v;
4861 line += i + 1;
4862 i = 0;
4863 }
4864 set_bit (FLAG_COMMIT, &ai->flags);
4865 } else if ( !strncmp( line, "Channel: ", 9 ) ) {
4866 int v, i = 0;
4867 line += 9;
4868 v = get_dec_u16(line, &i, i+3);
4869 if ( v != -1 ) {
4870 ai->config.channelSet = cpu_to_le16(v);
4871 set_bit (FLAG_COMMIT, &ai->flags);
4872 }
4873 } else if ( !strncmp( line, "XmitPower: ", 11 ) ) {
4874 int v, i = 0;
4875 line += 11;
4876 v = get_dec_u16(line, &i, i+3);
4877 if ( v != -1 ) {
4878 ai->config.txPower = cpu_to_le16(v);
4879 set_bit (FLAG_COMMIT, &ai->flags);
4880 }
4881 } else if ( !strncmp( line, "WEP: ", 5 ) ) {
4882 line += 5;
4883 switch( line[0] ) {
4884 case 's':
4885 set_auth_type(ai, AUTH_SHAREDKEY);
4886 break;
4887 case 'e':
4888 set_auth_type(ai, AUTH_ENCRYPT);
4889 break;
4890 default:
4891 set_auth_type(ai, AUTH_OPEN);
4892 break;
4893 }
4894 set_bit (FLAG_COMMIT, &ai->flags);
4895 } else if ( !strncmp( line, "LongRetryLimit: ", 16 ) ) {
4896 int v, i = 0;
4897
4898 line += 16;
4899 v = get_dec_u16(line, &i, 3);
4900 v = (v<0) ? 0 : ((v>255) ? 255 : v);
4901 ai->config.longRetryLimit = cpu_to_le16(v);
4902 set_bit (FLAG_COMMIT, &ai->flags);
4903 } else if ( !strncmp( line, "ShortRetryLimit: ", 17 ) ) {
4904 int v, i = 0;
4905
4906 line += 17;
4907 v = get_dec_u16(line, &i, 3);
4908 v = (v<0) ? 0 : ((v>255) ? 255 : v);
4909 ai->config.shortRetryLimit = cpu_to_le16(v);
4910 set_bit (FLAG_COMMIT, &ai->flags);
4911 } else if ( !strncmp( line, "RTSThreshold: ", 14 ) ) {
4912 int v, i = 0;
4913
4914 line += 14;
4915 v = get_dec_u16(line, &i, 4);
4916 v = (v<0) ? 0 : ((v>AIRO_DEF_MTU) ? AIRO_DEF_MTU : v);
4917 ai->config.rtsThres = cpu_to_le16(v);
4918 set_bit (FLAG_COMMIT, &ai->flags);
4919 } else if ( !strncmp( line, "TXMSDULifetime: ", 16 ) ) {
4920 int v, i = 0;
4921
4922 line += 16;
4923 v = get_dec_u16(line, &i, 5);
4924 v = (v<0) ? 0 : v;
4925 ai->config.txLifetime = cpu_to_le16(v);
4926 set_bit (FLAG_COMMIT, &ai->flags);
4927 } else if ( !strncmp( line, "RXMSDULifetime: ", 16 ) ) {
4928 int v, i = 0;
4929
4930 line += 16;
4931 v = get_dec_u16(line, &i, 5);
4932 v = (v<0) ? 0 : v;
4933 ai->config.rxLifetime = cpu_to_le16(v);
4934 set_bit (FLAG_COMMIT, &ai->flags);
4935 } else if ( !strncmp( line, "TXDiversity: ", 13 ) ) {
4936 ai->config.txDiversity =
4937 (line[13]=='l') ? 1 :
4938 ((line[13]=='r')? 2: 3);
4939 set_bit (FLAG_COMMIT, &ai->flags);
4940 } else if ( !strncmp( line, "RXDiversity: ", 13 ) ) {
4941 ai->config.rxDiversity =
4942 (line[13]=='l') ? 1 :
4943 ((line[13]=='r')? 2: 3);
4944 set_bit (FLAG_COMMIT, &ai->flags);
4945 } else if ( !strncmp( line, "FragThreshold: ", 15 ) ) {
4946 int v, i = 0;
4947
4948 line += 15;
4949 v = get_dec_u16(line, &i, 4);
4950 v = (v<256) ? 256 : ((v>AIRO_DEF_MTU) ? AIRO_DEF_MTU : v);
4951 v = v & 0xfffe;
4952 ai->config.fragThresh = cpu_to_le16(v);
4953 set_bit (FLAG_COMMIT, &ai->flags);
4954 } else if (!strncmp(line, "Modulation: ", 12)) {
4955 line += 12;
4956 switch(*line) {
4957 case 'd': ai->config.modulation=MOD_DEFAULT; set_bit(FLAG_COMMIT, &ai->flags); break;
4958 case 'c': ai->config.modulation=MOD_CCK; set_bit(FLAG_COMMIT, &ai->flags); break;
4959 case 'm': ai->config.modulation=MOD_MOK; set_bit(FLAG_COMMIT, &ai->flags); break;
4960 default: airo_print_warn(ai->dev->name, "Unknown modulation");
4961 }
4962 } else if (!strncmp(line, "Preamble: ", 10)) {
4963 line += 10;
4964 switch(*line) {
4965 case 'a': ai->config.preamble=PREAMBLE_AUTO; set_bit(FLAG_COMMIT, &ai->flags); break;
4966 case 'l': ai->config.preamble=PREAMBLE_LONG; set_bit(FLAG_COMMIT, &ai->flags); break;
4967 case 's': ai->config.preamble=PREAMBLE_SHORT; set_bit(FLAG_COMMIT, &ai->flags); break;
4968 default: airo_print_warn(ai->dev->name, "Unknown preamble");
4969 }
4970 } else {
4971 airo_print_warn(ai->dev->name, "Couldn't figure out %s", line);
4972 }
4973 while( line[0] && line[0] != '\n' ) line++;
4974 if ( line[0] ) line++;
4975 }
4976 airo_config_commit(dev, NULL, NULL, NULL);
4977}
4978
4979static const char *get_rmode(__le16 mode)
4980{
4981 switch(mode & RXMODE_MASK) {
4982 case RXMODE_RFMON: return "rfmon";
4983 case RXMODE_RFMON_ANYBSS: return "yna (any) bss rfmon";
4984 case RXMODE_LANMON: return "lanmon";
4985 }
4986 return "ESS";
4987}
4988
4989static int proc_config_open(struct inode *inode, struct file *file)
4990{
4991 struct proc_data *data;
4992 struct net_device *dev = PDE_DATA(inode);
4993 struct airo_info *ai = dev->ml_priv;
4994 int i;
4995 __le16 mode;
4996
4997 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
4998 return -ENOMEM;
4999 data = file->private_data;
5000 if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
5001 kfree (file->private_data);
5002 return -ENOMEM;
5003 }
5004 if ((data->wbuffer = kzalloc( 2048, GFP_KERNEL )) == NULL) {
5005 kfree (data->rbuffer);
5006 kfree (file->private_data);
5007 return -ENOMEM;
5008 }
5009 data->maxwritelen = 2048;
5010 data->on_close = proc_config_on_close;
5011
5012 readConfigRid(ai, 1);
5013
5014 mode = ai->config.opmode & MODE_CFG_MASK;
5015 i = sprintf( data->rbuffer,
5016 "Mode: %s\n"
5017 "Radio: %s\n"
5018 "NodeName: %-16s\n"
5019 "PowerMode: %s\n"
5020 "DataRates: %d %d %d %d %d %d %d %d\n"
5021 "Channel: %d\n"
5022 "XmitPower: %d\n",
5023 mode == MODE_STA_IBSS ? "adhoc" :
5024 mode == MODE_STA_ESS ? get_rmode(ai->config.rmode):
5025 mode == MODE_AP ? "AP" :
5026 mode == MODE_AP_RPTR ? "AP RPTR" : "Error",
5027 test_bit(FLAG_RADIO_OFF, &ai->flags) ? "off" : "on",
5028 ai->config.nodeName,
5029 ai->config.powerSaveMode == POWERSAVE_CAM ? "CAM" :
5030 ai->config.powerSaveMode == POWERSAVE_PSP ? "PSP" :
5031 ai->config.powerSaveMode == POWERSAVE_PSPCAM ? "PSPCAM" :
5032 "Error",
5033 (int)ai->config.rates[0],
5034 (int)ai->config.rates[1],
5035 (int)ai->config.rates[2],
5036 (int)ai->config.rates[3],
5037 (int)ai->config.rates[4],
5038 (int)ai->config.rates[5],
5039 (int)ai->config.rates[6],
5040 (int)ai->config.rates[7],
5041 le16_to_cpu(ai->config.channelSet),
5042 le16_to_cpu(ai->config.txPower)
5043 );
5044 sprintf( data->rbuffer + i,
5045 "LongRetryLimit: %d\n"
5046 "ShortRetryLimit: %d\n"
5047 "RTSThreshold: %d\n"
5048 "TXMSDULifetime: %d\n"
5049 "RXMSDULifetime: %d\n"
5050 "TXDiversity: %s\n"
5051 "RXDiversity: %s\n"
5052 "FragThreshold: %d\n"
5053 "WEP: %s\n"
5054 "Modulation: %s\n"
5055 "Preamble: %s\n",
5056 le16_to_cpu(ai->config.longRetryLimit),
5057 le16_to_cpu(ai->config.shortRetryLimit),
5058 le16_to_cpu(ai->config.rtsThres),
5059 le16_to_cpu(ai->config.txLifetime),
5060 le16_to_cpu(ai->config.rxLifetime),
5061 ai->config.txDiversity == 1 ? "left" :
5062 ai->config.txDiversity == 2 ? "right" : "both",
5063 ai->config.rxDiversity == 1 ? "left" :
5064 ai->config.rxDiversity == 2 ? "right" : "both",
5065 le16_to_cpu(ai->config.fragThresh),
5066 ai->config.authType == AUTH_ENCRYPT ? "encrypt" :
5067 ai->config.authType == AUTH_SHAREDKEY ? "shared" : "open",
5068 ai->config.modulation == MOD_DEFAULT ? "default" :
5069 ai->config.modulation == MOD_CCK ? "cck" :
5070 ai->config.modulation == MOD_MOK ? "mok" : "error",
5071 ai->config.preamble == PREAMBLE_AUTO ? "auto" :
5072 ai->config.preamble == PREAMBLE_LONG ? "long" :
5073 ai->config.preamble == PREAMBLE_SHORT ? "short" : "error"
5074 );
5075 data->readlen = strlen( data->rbuffer );
5076 return 0;
5077}
5078
5079static void proc_SSID_on_close(struct inode *inode, struct file *file)
5080{
5081 struct proc_data *data = file->private_data;
5082 struct net_device *dev = PDE_DATA(inode);
5083 struct airo_info *ai = dev->ml_priv;
5084 SsidRid SSID_rid;
5085 int i;
5086 char *p = data->wbuffer;
5087 char *end = p + data->writelen;
5088
5089 if (!data->writelen)
5090 return;
5091
5092 *end = '\n';
5093
5094 memset(&SSID_rid, 0, sizeof(SSID_rid));
5095
5096 for (i = 0; i < 3 && p < end; i++) {
5097 int j = 0;
5098
5099 while (*p != '\n' && j < 32)
5100 SSID_rid.ssids[i].ssid[j++] = *p++;
5101 if (j == 0)
5102 break;
5103 SSID_rid.ssids[i].len = cpu_to_le16(j);
5104
5105 while (*p++ != '\n')
5106 ;
5107 }
5108 if (i)
5109 SSID_rid.len = cpu_to_le16(sizeof(SSID_rid));
5110 disable_MAC(ai, 1);
5111 writeSsidRid(ai, &SSID_rid, 1);
5112 enable_MAC(ai, 1);
5113}
5114
5115static void proc_APList_on_close( struct inode *inode, struct file *file ) {
5116 struct proc_data *data = file->private_data;
5117 struct net_device *dev = PDE_DATA(inode);
5118 struct airo_info *ai = dev->ml_priv;
5119 APListRid *APList_rid = &ai->APList;
5120 int i;
5121
5122 if ( !data->writelen ) return;
5123
5124 memset(APList_rid, 0, sizeof(*APList_rid));
5125 APList_rid->len = cpu_to_le16(sizeof(*APList_rid));
5126
5127 for (i = 0; i < 4 && data->writelen >= (i + 1) * 6 * 3; i++)
5128 mac_pton(data->wbuffer + i * 6 * 3, APList_rid->ap[i]);
5129
5130 disable_MAC(ai, 1);
5131 writeAPListRid(ai, APList_rid, 1);
5132 enable_MAC(ai, 1);
5133}
5134
5135
5136static int do_writerid( struct airo_info *ai, u16 rid, const void *rid_data,
5137 int len, int dummy ) {
5138 int rc;
5139
5140 disable_MAC(ai, 1);
5141 rc = PC4500_writerid(ai, rid, rid_data, len, 1);
5142 enable_MAC(ai, 1);
5143 return rc;
5144}
5145
5146
5147
5148
5149static int get_wep_key(struct airo_info *ai, u16 index, char *buf, u16 buflen)
5150{
5151 WepKeyRid wkr;
5152 int rc;
5153 __le16 lastindex;
5154
5155 rc = readWepKeyRid(ai, &wkr, 1, 1);
5156 if (rc != SUCCESS)
5157 return -1;
5158 do {
5159 lastindex = wkr.kindex;
5160 if (le16_to_cpu(wkr.kindex) == index) {
5161 int klen = min_t(int, buflen, le16_to_cpu(wkr.klen));
5162 memcpy(buf, wkr.key, klen);
5163 return klen;
5164 }
5165 rc = readWepKeyRid(ai, &wkr, 0, 1);
5166 if (rc != SUCCESS)
5167 return -1;
5168 } while (lastindex != wkr.kindex);
5169 return -1;
5170}
5171
5172static int get_wep_tx_idx(struct airo_info *ai)
5173{
5174 WepKeyRid wkr;
5175 int rc;
5176 __le16 lastindex;
5177
5178 rc = readWepKeyRid(ai, &wkr, 1, 1);
5179 if (rc != SUCCESS)
5180 return -1;
5181 do {
5182 lastindex = wkr.kindex;
5183 if (wkr.kindex == cpu_to_le16(0xffff))
5184 return wkr.mac[0];
5185 rc = readWepKeyRid(ai, &wkr, 0, 1);
5186 if (rc != SUCCESS)
5187 return -1;
5188 } while (lastindex != wkr.kindex);
5189 return -1;
5190}
5191
5192static int set_wep_key(struct airo_info *ai, u16 index, const char *key,
5193 u16 keylen, int perm, int lock)
5194{
5195 static const unsigned char macaddr[ETH_ALEN] = { 0x01, 0, 0, 0, 0, 0 };
5196 WepKeyRid wkr;
5197 int rc;
5198
5199 if (WARN_ON(keylen == 0))
5200 return -1;
5201
5202 memset(&wkr, 0, sizeof(wkr));
5203 wkr.len = cpu_to_le16(sizeof(wkr));
5204 wkr.kindex = cpu_to_le16(index);
5205 wkr.klen = cpu_to_le16(keylen);
5206 memcpy(wkr.key, key, keylen);
5207 memcpy(wkr.mac, macaddr, ETH_ALEN);
5208
5209 if (perm) disable_MAC(ai, lock);
5210 rc = writeWepKeyRid(ai, &wkr, perm, lock);
5211 if (perm) enable_MAC(ai, lock);
5212 return rc;
5213}
5214
5215static int set_wep_tx_idx(struct airo_info *ai, u16 index, int perm, int lock)
5216{
5217 WepKeyRid wkr;
5218 int rc;
5219
5220 memset(&wkr, 0, sizeof(wkr));
5221 wkr.len = cpu_to_le16(sizeof(wkr));
5222 wkr.kindex = cpu_to_le16(0xffff);
5223 wkr.mac[0] = (char)index;
5224
5225 if (perm) {
5226 ai->defindex = (char)index;
5227 disable_MAC(ai, lock);
5228 }
5229
5230 rc = writeWepKeyRid(ai, &wkr, perm, lock);
5231
5232 if (perm)
5233 enable_MAC(ai, lock);
5234 return rc;
5235}
5236
5237static void proc_wepkey_on_close( struct inode *inode, struct file *file ) {
5238 struct proc_data *data;
5239 struct net_device *dev = PDE_DATA(inode);
5240 struct airo_info *ai = dev->ml_priv;
5241 int i, rc;
5242 char key[16];
5243 u16 index = 0;
5244 int j = 0;
5245
5246 memset(key, 0, sizeof(key));
5247
5248 data = file->private_data;
5249 if ( !data->writelen ) return;
5250
5251 if (data->wbuffer[0] >= '0' && data->wbuffer[0] <= '3' &&
5252 (data->wbuffer[1] == ' ' || data->wbuffer[1] == '\n')) {
5253 index = data->wbuffer[0] - '0';
5254 if (data->wbuffer[1] == '\n') {
5255 rc = set_wep_tx_idx(ai, index, 1, 1);
5256 if (rc < 0) {
5257 airo_print_err(ai->dev->name, "failed to set "
5258 "WEP transmit index to %d: %d.",
5259 index, rc);
5260 }
5261 return;
5262 }
5263 j = 2;
5264 } else {
5265 airo_print_err(ai->dev->name, "WepKey passed invalid key index");
5266 return;
5267 }
5268
5269 for( i = 0; i < 16*3 && data->wbuffer[i+j]; i++ ) {
5270 switch(i%3) {
5271 case 0:
5272 key[i/3] = hex_to_bin(data->wbuffer[i+j])<<4;
5273 break;
5274 case 1:
5275 key[i/3] |= hex_to_bin(data->wbuffer[i+j]);
5276 break;
5277 }
5278 }
5279
5280 rc = set_wep_key(ai, index, key, i/3, 1, 1);
5281 if (rc < 0) {
5282 airo_print_err(ai->dev->name, "failed to set WEP key at index "
5283 "%d: %d.", index, rc);
5284 }
5285}
5286
5287static int proc_wepkey_open( struct inode *inode, struct file *file )
5288{
5289 struct proc_data *data;
5290 struct net_device *dev = PDE_DATA(inode);
5291 struct airo_info *ai = dev->ml_priv;
5292 char *ptr;
5293 WepKeyRid wkr;
5294 __le16 lastindex;
5295 int j=0;
5296 int rc;
5297
5298 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5299 return -ENOMEM;
5300 memset(&wkr, 0, sizeof(wkr));
5301 data = file->private_data;
5302 if ((data->rbuffer = kzalloc( 180, GFP_KERNEL )) == NULL) {
5303 kfree (file->private_data);
5304 return -ENOMEM;
5305 }
5306 data->writelen = 0;
5307 data->maxwritelen = 80;
5308 if ((data->wbuffer = kzalloc( 80, GFP_KERNEL )) == NULL) {
5309 kfree (data->rbuffer);
5310 kfree (file->private_data);
5311 return -ENOMEM;
5312 }
5313 data->on_close = proc_wepkey_on_close;
5314
5315 ptr = data->rbuffer;
5316 strcpy(ptr, "No wep keys\n");
5317 rc = readWepKeyRid(ai, &wkr, 1, 1);
5318 if (rc == SUCCESS) do {
5319 lastindex = wkr.kindex;
5320 if (wkr.kindex == cpu_to_le16(0xffff)) {
5321 j += sprintf(ptr+j, "Tx key = %d\n",
5322 (int)wkr.mac[0]);
5323 } else {
5324 j += sprintf(ptr+j, "Key %d set with length = %d\n",
5325 le16_to_cpu(wkr.kindex),
5326 le16_to_cpu(wkr.klen));
5327 }
5328 readWepKeyRid(ai, &wkr, 0, 1);
5329 } while((lastindex != wkr.kindex) && (j < 180-30));
5330
5331 data->readlen = strlen( data->rbuffer );
5332 return 0;
5333}
5334
5335static int proc_SSID_open(struct inode *inode, struct file *file)
5336{
5337 struct proc_data *data;
5338 struct net_device *dev = PDE_DATA(inode);
5339 struct airo_info *ai = dev->ml_priv;
5340 int i;
5341 char *ptr;
5342 SsidRid SSID_rid;
5343
5344 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5345 return -ENOMEM;
5346 data = file->private_data;
5347 if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
5348 kfree (file->private_data);
5349 return -ENOMEM;
5350 }
5351 data->writelen = 0;
5352 data->maxwritelen = 33*3;
5353
5354 if ((data->wbuffer = kzalloc(33*3 + 1, GFP_KERNEL)) == NULL) {
5355 kfree (data->rbuffer);
5356 kfree (file->private_data);
5357 return -ENOMEM;
5358 }
5359 data->on_close = proc_SSID_on_close;
5360
5361 readSsidRid(ai, &SSID_rid);
5362 ptr = data->rbuffer;
5363 for (i = 0; i < 3; i++) {
5364 int j;
5365 size_t len = le16_to_cpu(SSID_rid.ssids[i].len);
5366 if (!len)
5367 break;
5368 if (len > 32)
5369 len = 32;
5370 for (j = 0; j < len && SSID_rid.ssids[i].ssid[j]; j++)
5371 *ptr++ = SSID_rid.ssids[i].ssid[j];
5372 *ptr++ = '\n';
5373 }
5374 *ptr = '\0';
5375 data->readlen = strlen( data->rbuffer );
5376 return 0;
5377}
5378
5379static int proc_APList_open( struct inode *inode, struct file *file ) {
5380 struct proc_data *data;
5381 struct net_device *dev = PDE_DATA(inode);
5382 struct airo_info *ai = dev->ml_priv;
5383 int i;
5384 char *ptr;
5385 APListRid *APList_rid = &ai->APList;
5386
5387 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5388 return -ENOMEM;
5389 data = file->private_data;
5390 if ((data->rbuffer = kmalloc( 104, GFP_KERNEL )) == NULL) {
5391 kfree (file->private_data);
5392 return -ENOMEM;
5393 }
5394 data->writelen = 0;
5395 data->maxwritelen = 4*6*3;
5396 if ((data->wbuffer = kzalloc( data->maxwritelen, GFP_KERNEL )) == NULL) {
5397 kfree (data->rbuffer);
5398 kfree (file->private_data);
5399 return -ENOMEM;
5400 }
5401 data->on_close = proc_APList_on_close;
5402
5403 ptr = data->rbuffer;
5404 for( i = 0; i < 4; i++ ) {
5405
5406 if ( !*(int*)APList_rid->ap[i] &&
5407 !*(int*)&APList_rid->ap[i][2]) break;
5408 ptr += sprintf(ptr, "%pM\n", APList_rid->ap[i]);
5409 }
5410 if (i==0) ptr += sprintf(ptr, "Not using specific APs\n");
5411
5412 *ptr = '\0';
5413 data->readlen = strlen( data->rbuffer );
5414 return 0;
5415}
5416
5417static int proc_BSSList_open( struct inode *inode, struct file *file ) {
5418 struct proc_data *data;
5419 struct net_device *dev = PDE_DATA(inode);
5420 struct airo_info *ai = dev->ml_priv;
5421 char *ptr;
5422 BSSListRid BSSList_rid;
5423 int rc;
5424
5425 int doLoseSync = -1;
5426
5427 if ((file->private_data = kzalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
5428 return -ENOMEM;
5429 data = file->private_data;
5430 if ((data->rbuffer = kmalloc( 1024, GFP_KERNEL )) == NULL) {
5431 kfree (file->private_data);
5432 return -ENOMEM;
5433 }
5434 data->writelen = 0;
5435 data->maxwritelen = 0;
5436 data->wbuffer = NULL;
5437 data->on_close = NULL;
5438
5439 if (file->f_mode & FMODE_WRITE) {
5440 if (!(file->f_mode & FMODE_READ)) {
5441 Cmd cmd;
5442 Resp rsp;
5443
5444 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
5445 memset(&cmd, 0, sizeof(cmd));
5446 cmd.cmd=CMD_LISTBSS;
5447 if (down_interruptible(&ai->sem))
5448 return -ERESTARTSYS;
5449 issuecommand(ai, &cmd, &rsp);
5450 up(&ai->sem);
5451 data->readlen = 0;
5452 return 0;
5453 }
5454 doLoseSync = 1;
5455 }
5456 ptr = data->rbuffer;
5457
5458
5459
5460 rc = readBSSListRid(ai, doLoseSync, &BSSList_rid);
5461 while(rc == 0 && BSSList_rid.index != cpu_to_le16(0xffff)) {
5462 ptr += sprintf(ptr, "%pM %.*s rssi = %d",
5463 BSSList_rid.bssid,
5464 (int)BSSList_rid.ssidLen,
5465 BSSList_rid.ssid,
5466 le16_to_cpu(BSSList_rid.dBm));
5467 ptr += sprintf(ptr, " channel = %d %s %s %s %s\n",
5468 le16_to_cpu(BSSList_rid.dsChannel),
5469 BSSList_rid.cap & CAP_ESS ? "ESS" : "",
5470 BSSList_rid.cap & CAP_IBSS ? "adhoc" : "",
5471 BSSList_rid.cap & CAP_PRIVACY ? "wep" : "",
5472 BSSList_rid.cap & CAP_SHORTHDR ? "shorthdr" : "");
5473 rc = readBSSListRid(ai, 0, &BSSList_rid);
5474 }
5475 *ptr = '\0';
5476 data->readlen = strlen( data->rbuffer );
5477 return 0;
5478}
5479
5480static int proc_close( struct inode *inode, struct file *file )
5481{
5482 struct proc_data *data = file->private_data;
5483
5484 if (data->on_close != NULL)
5485 data->on_close(inode, file);
5486 kfree(data->rbuffer);
5487 kfree(data->wbuffer);
5488 kfree(data);
5489 return 0;
5490}
5491
5492
5493
5494
5495
5496
5497static void timer_func( struct net_device *dev ) {
5498 struct airo_info *apriv = dev->ml_priv;
5499
5500
5501 readConfigRid(apriv, 0);
5502 disable_MAC(apriv, 0);
5503 switch(apriv->config.authType) {
5504 case AUTH_ENCRYPT:
5505
5506 apriv->config.authType = AUTH_OPEN;
5507 break;
5508 case AUTH_SHAREDKEY:
5509 if (apriv->keyindex < auto_wep) {
5510 set_wep_tx_idx(apriv, apriv->keyindex, 0, 0);
5511 apriv->config.authType = AUTH_SHAREDKEY;
5512 apriv->keyindex++;
5513 } else {
5514
5515 apriv->keyindex = 0;
5516 set_wep_tx_idx(apriv, apriv->defindex, 0, 0);
5517 apriv->config.authType = AUTH_ENCRYPT;
5518 }
5519 break;
5520 default:
5521 apriv->config.authType = AUTH_SHAREDKEY;
5522 }
5523 set_bit (FLAG_COMMIT, &apriv->flags);
5524 writeConfigRid(apriv, 0);
5525 enable_MAC(apriv, 0);
5526 up(&apriv->sem);
5527
5528
5529 clear_bit(JOB_AUTOWEP, &apriv->jobs);
5530 apriv->expires = RUN_AT(HZ*3);
5531}
5532
5533#ifdef CONFIG_PCI
5534static int airo_pci_probe(struct pci_dev *pdev,
5535 const struct pci_device_id *pent)
5536{
5537 struct net_device *dev;
5538
5539 if (pci_enable_device(pdev))
5540 return -ENODEV;
5541 pci_set_master(pdev);
5542
5543 if (pdev->device == 0x5000 || pdev->device == 0xa504)
5544 dev = _init_airo_card(pdev->irq, pdev->resource[0].start, 0, pdev, &pdev->dev);
5545 else
5546 dev = _init_airo_card(pdev->irq, pdev->resource[2].start, 0, pdev, &pdev->dev);
5547 if (!dev) {
5548 pci_disable_device(pdev);
5549 return -ENODEV;
5550 }
5551
5552 pci_set_drvdata(pdev, dev);
5553 return 0;
5554}
5555
5556static void airo_pci_remove(struct pci_dev *pdev)
5557{
5558 struct net_device *dev = pci_get_drvdata(pdev);
5559
5560 airo_print_info(dev->name, "Unregistering...");
5561 stop_airo_card(dev, 1);
5562 pci_disable_device(pdev);
5563}
5564
5565static int airo_pci_suspend(struct pci_dev *pdev, pm_message_t state)
5566{
5567 struct net_device *dev = pci_get_drvdata(pdev);
5568 struct airo_info *ai = dev->ml_priv;
5569 Cmd cmd;
5570 Resp rsp;
5571
5572 if (!ai->SSID)
5573 ai->SSID = kmalloc(sizeof(SsidRid), GFP_KERNEL);
5574 if (!ai->SSID)
5575 return -ENOMEM;
5576 readSsidRid(ai, ai->SSID);
5577 memset(&cmd, 0, sizeof(cmd));
5578
5579 if (down_interruptible(&ai->sem))
5580 return -EAGAIN;
5581 disable_MAC(ai, 0);
5582 netif_device_detach(dev);
5583 ai->power = state;
5584 cmd.cmd = HOSTSLEEP;
5585 issuecommand(ai, &cmd, &rsp);
5586
5587 pci_enable_wake(pdev, pci_choose_state(pdev, state), 1);
5588 pci_save_state(pdev);
5589 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5590 return 0;
5591}
5592
5593static int airo_pci_resume(struct pci_dev *pdev)
5594{
5595 struct net_device *dev = pci_get_drvdata(pdev);
5596 struct airo_info *ai = dev->ml_priv;
5597 pci_power_t prev_state = pdev->current_state;
5598
5599 pci_set_power_state(pdev, PCI_D0);
5600 pci_restore_state(pdev);
5601 pci_enable_wake(pdev, PCI_D0, 0);
5602
5603 if (prev_state != PCI_D1) {
5604 reset_card(dev, 0);
5605 mpi_init_descriptors(ai);
5606 setup_card(ai, dev->dev_addr, 0);
5607 clear_bit(FLAG_RADIO_OFF, &ai->flags);
5608 clear_bit(FLAG_PENDING_XMIT, &ai->flags);
5609 } else {
5610 OUT4500(ai, EVACK, EV_AWAKEN);
5611 OUT4500(ai, EVACK, EV_AWAKEN);
5612 msleep(100);
5613 }
5614
5615 set_bit(FLAG_COMMIT, &ai->flags);
5616 disable_MAC(ai, 0);
5617 msleep(200);
5618 if (ai->SSID) {
5619 writeSsidRid(ai, ai->SSID, 0);
5620 kfree(ai->SSID);
5621 ai->SSID = NULL;
5622 }
5623 writeAPListRid(ai, &ai->APList, 0);
5624 writeConfigRid(ai, 0);
5625 enable_MAC(ai, 0);
5626 ai->power = PMSG_ON;
5627 netif_device_attach(dev);
5628 netif_wake_queue(dev);
5629 enable_interrupts(ai);
5630 up(&ai->sem);
5631 return 0;
5632}
5633#endif
5634
5635static int __init airo_init_module( void )
5636{
5637 int i;
5638
5639 proc_kuid = make_kuid(&init_user_ns, proc_uid);
5640 proc_kgid = make_kgid(&init_user_ns, proc_gid);
5641 if (!uid_valid(proc_kuid) || !gid_valid(proc_kgid))
5642 return -EINVAL;
5643
5644 airo_entry = proc_mkdir_mode("driver/aironet", airo_perm, NULL);
5645
5646 if (airo_entry)
5647 proc_set_user(airo_entry, proc_kuid, proc_kgid);
5648
5649 for (i = 0; i < 4 && io[i] && irq[i]; i++) {
5650 airo_print_info("", "Trying to configure ISA adapter at irq=%d "
5651 "io=0x%x", irq[i], io[i] );
5652 if (init_airo_card( irq[i], io[i], 0, NULL ))
5653 ;
5654 }
5655
5656#ifdef CONFIG_PCI
5657 airo_print_info("", "Probing for PCI adapters");
5658 i = pci_register_driver(&airo_driver);
5659 airo_print_info("", "Finished probing for PCI adapters");
5660
5661 if (i) {
5662 remove_proc_entry("driver/aironet", NULL);
5663 return i;
5664 }
5665#endif
5666
5667
5668
5669
5670 return 0;
5671}
5672
5673static void __exit airo_cleanup_module( void )
5674{
5675 struct airo_info *ai;
5676 while(!list_empty(&airo_devices)) {
5677 ai = list_entry(airo_devices.next, struct airo_info, dev_list);
5678 airo_print_info(ai->dev->name, "Unregistering...");
5679 stop_airo_card(ai->dev, 1);
5680 }
5681#ifdef CONFIG_PCI
5682 pci_unregister_driver(&airo_driver);
5683#endif
5684 remove_proc_entry("driver/aironet", NULL);
5685}
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697static u8 airo_rssi_to_dbm (tdsRssiEntry *rssi_rid, u8 rssi)
5698{
5699 if (!rssi_rid)
5700 return 0;
5701
5702 return (0x100 - rssi_rid[rssi].rssidBm);
5703}
5704
5705static u8 airo_dbm_to_pct (tdsRssiEntry *rssi_rid, u8 dbm)
5706{
5707 int i;
5708
5709 if (!rssi_rid)
5710 return 0;
5711
5712 for (i = 0; i < 256; i++)
5713 if (rssi_rid[i].rssidBm == dbm)
5714 return rssi_rid[i].rssipct;
5715
5716 return 0;
5717}
5718
5719
5720static int airo_get_quality (StatusRid *status_rid, CapabilityRid *cap_rid)
5721{
5722 int quality = 0;
5723 u16 sq;
5724
5725 if ((status_rid->mode & cpu_to_le16(0x3f)) != cpu_to_le16(0x3f))
5726 return 0;
5727
5728 if (!(cap_rid->hardCap & cpu_to_le16(8)))
5729 return 0;
5730
5731 sq = le16_to_cpu(status_rid->signalQuality);
5732 if (memcmp(cap_rid->prodName, "350", 3))
5733 if (sq > 0x20)
5734 quality = 0;
5735 else
5736 quality = 0x20 - sq;
5737 else
5738 if (sq > 0xb0)
5739 quality = 0;
5740 else if (sq < 0x10)
5741 quality = 0xa0;
5742 else
5743 quality = 0xb0 - sq;
5744 return quality;
5745}
5746
5747#define airo_get_max_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x20 : 0xa0)
5748#define airo_get_avg_quality(cap_rid) (memcmp((cap_rid)->prodName, "350", 3) ? 0x10 : 0x50);
5749
5750
5751
5752
5753
5754static int airo_get_name(struct net_device *dev,
5755 struct iw_request_info *info,
5756 char *cwrq,
5757 char *extra)
5758{
5759 strcpy(cwrq, "IEEE 802.11-DS");
5760 return 0;
5761}
5762
5763
5764
5765
5766
5767static int airo_set_freq(struct net_device *dev,
5768 struct iw_request_info *info,
5769 struct iw_freq *fwrq,
5770 char *extra)
5771{
5772 struct airo_info *local = dev->ml_priv;
5773 int rc = -EINPROGRESS;
5774
5775
5776 if(fwrq->e == 1) {
5777 int f = fwrq->m / 100000;
5778
5779
5780 fwrq->e = 0;
5781 fwrq->m = ieee80211_frequency_to_channel(f);
5782 }
5783
5784 if (fwrq->m < 0 || fwrq->m > 1000 || fwrq->e > 0)
5785 rc = -EOPNOTSUPP;
5786 else {
5787 int channel = fwrq->m;
5788
5789
5790 if((channel < 1) || (channel > 14)) {
5791 airo_print_dbg(dev->name, "New channel value of %d is invalid!",
5792 fwrq->m);
5793 rc = -EINVAL;
5794 } else {
5795 readConfigRid(local, 1);
5796
5797 local->config.channelSet = cpu_to_le16(channel);
5798 set_bit (FLAG_COMMIT, &local->flags);
5799 }
5800 }
5801 return rc;
5802}
5803
5804
5805
5806
5807
5808static int airo_get_freq(struct net_device *dev,
5809 struct iw_request_info *info,
5810 struct iw_freq *fwrq,
5811 char *extra)
5812{
5813 struct airo_info *local = dev->ml_priv;
5814 StatusRid status_rid;
5815 int ch;
5816
5817 readConfigRid(local, 1);
5818 if ((local->config.opmode & MODE_CFG_MASK) == MODE_STA_ESS)
5819 status_rid.channel = local->config.channelSet;
5820 else
5821 readStatusRid(local, &status_rid, 1);
5822
5823 ch = le16_to_cpu(status_rid.channel);
5824 if((ch > 0) && (ch < 15)) {
5825 fwrq->m = 100000 *
5826 ieee80211_channel_to_frequency(ch, NL80211_BAND_2GHZ);
5827 fwrq->e = 1;
5828 } else {
5829 fwrq->m = ch;
5830 fwrq->e = 0;
5831 }
5832
5833 return 0;
5834}
5835
5836
5837
5838
5839
5840static int airo_set_essid(struct net_device *dev,
5841 struct iw_request_info *info,
5842 struct iw_point *dwrq,
5843 char *extra)
5844{
5845 struct airo_info *local = dev->ml_priv;
5846 SsidRid SSID_rid;
5847
5848
5849 readSsidRid(local, &SSID_rid);
5850
5851
5852 if (dwrq->flags == 0) {
5853
5854 memset(&SSID_rid, 0, sizeof(SSID_rid));
5855 } else {
5856 unsigned index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
5857
5858
5859 if (dwrq->length > IW_ESSID_MAX_SIZE)
5860 return -E2BIG ;
5861
5862
5863 if (index >= ARRAY_SIZE(SSID_rid.ssids))
5864 return -EINVAL;
5865
5866
5867 memset(SSID_rid.ssids[index].ssid, 0,
5868 sizeof(SSID_rid.ssids[index].ssid));
5869 memcpy(SSID_rid.ssids[index].ssid, extra, dwrq->length);
5870 SSID_rid.ssids[index].len = cpu_to_le16(dwrq->length);
5871 }
5872 SSID_rid.len = cpu_to_le16(sizeof(SSID_rid));
5873
5874 disable_MAC(local, 1);
5875 writeSsidRid(local, &SSID_rid, 1);
5876 enable_MAC(local, 1);
5877
5878 return 0;
5879}
5880
5881
5882
5883
5884
5885static int airo_get_essid(struct net_device *dev,
5886 struct iw_request_info *info,
5887 struct iw_point *dwrq,
5888 char *extra)
5889{
5890 struct airo_info *local = dev->ml_priv;
5891 StatusRid status_rid;
5892
5893 readStatusRid(local, &status_rid, 1);
5894
5895
5896
5897
5898
5899 memcpy(extra, status_rid.SSID, le16_to_cpu(status_rid.SSIDlen));
5900
5901
5902
5903 dwrq->length = le16_to_cpu(status_rid.SSIDlen);
5904 dwrq->flags = 1;
5905
5906 return 0;
5907}
5908
5909
5910
5911
5912
5913static int airo_set_wap(struct net_device *dev,
5914 struct iw_request_info *info,
5915 struct sockaddr *awrq,
5916 char *extra)
5917{
5918 struct airo_info *local = dev->ml_priv;
5919 Cmd cmd;
5920 Resp rsp;
5921 APListRid *APList_rid = &local->APList;
5922
5923 if (awrq->sa_family != ARPHRD_ETHER)
5924 return -EINVAL;
5925 else if (is_broadcast_ether_addr(awrq->sa_data) ||
5926 is_zero_ether_addr(awrq->sa_data)) {
5927 memset(&cmd, 0, sizeof(cmd));
5928 cmd.cmd=CMD_LOSE_SYNC;
5929 if (down_interruptible(&local->sem))
5930 return -ERESTARTSYS;
5931 issuecommand(local, &cmd, &rsp);
5932 up(&local->sem);
5933 } else {
5934 memset(APList_rid, 0, sizeof(*APList_rid));
5935 APList_rid->len = cpu_to_le16(sizeof(*APList_rid));
5936 memcpy(APList_rid->ap[0], awrq->sa_data, ETH_ALEN);
5937 disable_MAC(local, 1);
5938 writeAPListRid(local, APList_rid, 1);
5939 enable_MAC(local, 1);
5940 }
5941 return 0;
5942}
5943
5944
5945
5946
5947
5948static int airo_get_wap(struct net_device *dev,
5949 struct iw_request_info *info,
5950 struct sockaddr *awrq,
5951 char *extra)
5952{
5953 struct airo_info *local = dev->ml_priv;
5954 StatusRid status_rid;
5955
5956 readStatusRid(local, &status_rid, 1);
5957
5958
5959 memcpy(awrq->sa_data, status_rid.bssid[0], ETH_ALEN);
5960 awrq->sa_family = ARPHRD_ETHER;
5961
5962 return 0;
5963}
5964
5965
5966
5967
5968
5969static int airo_set_nick(struct net_device *dev,
5970 struct iw_request_info *info,
5971 struct iw_point *dwrq,
5972 char *extra)
5973{
5974 struct airo_info *local = dev->ml_priv;
5975
5976
5977 if(dwrq->length > 16) {
5978 return -E2BIG;
5979 }
5980 readConfigRid(local, 1);
5981 memset(local->config.nodeName, 0, sizeof(local->config.nodeName));
5982 memcpy(local->config.nodeName, extra, dwrq->length);
5983 set_bit (FLAG_COMMIT, &local->flags);
5984
5985 return -EINPROGRESS;
5986}
5987
5988
5989
5990
5991
5992static int airo_get_nick(struct net_device *dev,
5993 struct iw_request_info *info,
5994 struct iw_point *dwrq,
5995 char *extra)
5996{
5997 struct airo_info *local = dev->ml_priv;
5998
5999 readConfigRid(local, 1);
6000 strncpy(extra, local->config.nodeName, 16);
6001 extra[16] = '\0';
6002 dwrq->length = strlen(extra);
6003
6004 return 0;
6005}
6006
6007
6008
6009
6010
6011static int airo_set_rate(struct net_device *dev,
6012 struct iw_request_info *info,
6013 struct iw_param *vwrq,
6014 char *extra)
6015{
6016 struct airo_info *local = dev->ml_priv;
6017 CapabilityRid cap_rid;
6018 u8 brate = 0;
6019 int i;
6020
6021
6022 readCapabilityRid(local, &cap_rid, 1);
6023
6024
6025 if((vwrq->value < 8) && (vwrq->value >= 0)) {
6026
6027
6028 brate = cap_rid.supportedRates[vwrq->value];
6029 } else {
6030
6031 u8 normvalue = (u8) (vwrq->value/500000);
6032
6033
6034 for(i = 0 ; i < 8 ; i++) {
6035 if(normvalue == cap_rid.supportedRates[i]) {
6036 brate = normvalue;
6037 break;
6038 }
6039 }
6040 }
6041
6042 if(vwrq->value == -1) {
6043
6044 for(i = 0 ; i < 8 ; i++) {
6045 if(cap_rid.supportedRates[i] == 0)
6046 break;
6047 }
6048 if(i != 0)
6049 brate = cap_rid.supportedRates[i - 1];
6050 }
6051
6052 if(brate == 0) {
6053 return -EINVAL;
6054 }
6055
6056 readConfigRid(local, 1);
6057
6058 if(vwrq->fixed == 0) {
6059
6060 memset(local->config.rates, 0, 8);
6061 for(i = 0 ; i < 8 ; i++) {
6062 local->config.rates[i] = cap_rid.supportedRates[i];
6063 if(local->config.rates[i] == brate)
6064 break;
6065 }
6066 } else {
6067
6068
6069 memset(local->config.rates, 0, 8);
6070 local->config.rates[0] = brate;
6071 }
6072 set_bit (FLAG_COMMIT, &local->flags);
6073
6074 return -EINPROGRESS;
6075}
6076
6077
6078
6079
6080
6081static int airo_get_rate(struct net_device *dev,
6082 struct iw_request_info *info,
6083 struct iw_param *vwrq,
6084 char *extra)
6085{
6086 struct airo_info *local = dev->ml_priv;
6087 StatusRid status_rid;
6088
6089 readStatusRid(local, &status_rid, 1);
6090
6091 vwrq->value = le16_to_cpu(status_rid.currentXmitRate) * 500000;
6092
6093 readConfigRid(local, 1);
6094 vwrq->fixed = (local->config.rates[1] == 0);
6095
6096 return 0;
6097}
6098
6099
6100
6101
6102
6103static int airo_set_rts(struct net_device *dev,
6104 struct iw_request_info *info,
6105 struct iw_param *vwrq,
6106 char *extra)
6107{
6108 struct airo_info *local = dev->ml_priv;
6109 int rthr = vwrq->value;
6110
6111 if(vwrq->disabled)
6112 rthr = AIRO_DEF_MTU;
6113 if((rthr < 0) || (rthr > AIRO_DEF_MTU)) {
6114 return -EINVAL;
6115 }
6116 readConfigRid(local, 1);
6117 local->config.rtsThres = cpu_to_le16(rthr);
6118 set_bit (FLAG_COMMIT, &local->flags);
6119
6120 return -EINPROGRESS;
6121}
6122
6123
6124
6125
6126
6127static int airo_get_rts(struct net_device *dev,
6128 struct iw_request_info *info,
6129 struct iw_param *vwrq,
6130 char *extra)
6131{
6132 struct airo_info *local = dev->ml_priv;
6133
6134 readConfigRid(local, 1);
6135 vwrq->value = le16_to_cpu(local->config.rtsThres);
6136 vwrq->disabled = (vwrq->value >= AIRO_DEF_MTU);
6137 vwrq->fixed = 1;
6138
6139 return 0;
6140}
6141
6142
6143
6144
6145
6146static int airo_set_frag(struct net_device *dev,
6147 struct iw_request_info *info,
6148 struct iw_param *vwrq,
6149 char *extra)
6150{
6151 struct airo_info *local = dev->ml_priv;
6152 int fthr = vwrq->value;
6153
6154 if(vwrq->disabled)
6155 fthr = AIRO_DEF_MTU;
6156 if((fthr < 256) || (fthr > AIRO_DEF_MTU)) {
6157 return -EINVAL;
6158 }
6159 fthr &= ~0x1;
6160 readConfigRid(local, 1);
6161 local->config.fragThresh = cpu_to_le16(fthr);
6162 set_bit (FLAG_COMMIT, &local->flags);
6163
6164 return -EINPROGRESS;
6165}
6166
6167
6168
6169
6170
6171static int airo_get_frag(struct net_device *dev,
6172 struct iw_request_info *info,
6173 struct iw_param *vwrq,
6174 char *extra)
6175{
6176 struct airo_info *local = dev->ml_priv;
6177
6178 readConfigRid(local, 1);
6179 vwrq->value = le16_to_cpu(local->config.fragThresh);
6180 vwrq->disabled = (vwrq->value >= AIRO_DEF_MTU);
6181 vwrq->fixed = 1;
6182
6183 return 0;
6184}
6185
6186
6187
6188
6189
6190static int airo_set_mode(struct net_device *dev,
6191 struct iw_request_info *info,
6192 __u32 *uwrq,
6193 char *extra)
6194{
6195 struct airo_info *local = dev->ml_priv;
6196 int reset = 0;
6197
6198 readConfigRid(local, 1);
6199 if (sniffing_mode(local))
6200 reset = 1;
6201
6202 switch(*uwrq) {
6203 case IW_MODE_ADHOC:
6204 local->config.opmode &= ~MODE_CFG_MASK;
6205 local->config.opmode |= MODE_STA_IBSS;
6206 local->config.rmode &= ~RXMODE_FULL_MASK;
6207 local->config.scanMode = SCANMODE_ACTIVE;
6208 clear_bit (FLAG_802_11, &local->flags);
6209 break;
6210 case IW_MODE_INFRA:
6211 local->config.opmode &= ~MODE_CFG_MASK;
6212 local->config.opmode |= MODE_STA_ESS;
6213 local->config.rmode &= ~RXMODE_FULL_MASK;
6214 local->config.scanMode = SCANMODE_ACTIVE;
6215 clear_bit (FLAG_802_11, &local->flags);
6216 break;
6217 case IW_MODE_MASTER:
6218 local->config.opmode &= ~MODE_CFG_MASK;
6219 local->config.opmode |= MODE_AP;
6220 local->config.rmode &= ~RXMODE_FULL_MASK;
6221 local->config.scanMode = SCANMODE_ACTIVE;
6222 clear_bit (FLAG_802_11, &local->flags);
6223 break;
6224 case IW_MODE_REPEAT:
6225 local->config.opmode &= ~MODE_CFG_MASK;
6226 local->config.opmode |= MODE_AP_RPTR;
6227 local->config.rmode &= ~RXMODE_FULL_MASK;
6228 local->config.scanMode = SCANMODE_ACTIVE;
6229 clear_bit (FLAG_802_11, &local->flags);
6230 break;
6231 case IW_MODE_MONITOR:
6232 local->config.opmode &= ~MODE_CFG_MASK;
6233 local->config.opmode |= MODE_STA_ESS;
6234 local->config.rmode &= ~RXMODE_FULL_MASK;
6235 local->config.rmode |= RXMODE_RFMON | RXMODE_DISABLE_802_3_HEADER;
6236 local->config.scanMode = SCANMODE_PASSIVE;
6237 set_bit (FLAG_802_11, &local->flags);
6238 break;
6239 default:
6240 return -EINVAL;
6241 }
6242 if (reset)
6243 set_bit (FLAG_RESET, &local->flags);
6244 set_bit (FLAG_COMMIT, &local->flags);
6245
6246 return -EINPROGRESS;
6247}
6248
6249
6250
6251
6252
6253static int airo_get_mode(struct net_device *dev,
6254 struct iw_request_info *info,
6255 __u32 *uwrq,
6256 char *extra)
6257{
6258 struct airo_info *local = dev->ml_priv;
6259
6260 readConfigRid(local, 1);
6261
6262 switch (local->config.opmode & MODE_CFG_MASK) {
6263 case MODE_STA_ESS:
6264 *uwrq = IW_MODE_INFRA;
6265 break;
6266 case MODE_AP:
6267 *uwrq = IW_MODE_MASTER;
6268 break;
6269 case MODE_AP_RPTR:
6270 *uwrq = IW_MODE_REPEAT;
6271 break;
6272 default:
6273 *uwrq = IW_MODE_ADHOC;
6274 }
6275
6276 return 0;
6277}
6278
6279static inline int valid_index(struct airo_info *ai, int index)
6280{
6281 return (index >= 0) && (index <= ai->max_wep_idx);
6282}
6283
6284
6285
6286
6287
6288static int airo_set_encode(struct net_device *dev,
6289 struct iw_request_info *info,
6290 struct iw_point *dwrq,
6291 char *extra)
6292{
6293 struct airo_info *local = dev->ml_priv;
6294 int perm = (dwrq->flags & IW_ENCODE_TEMP ? 0 : 1);
6295 __le16 currentAuthType = local->config.authType;
6296 int rc = 0;
6297
6298 if (!local->wep_capable)
6299 return -EOPNOTSUPP;
6300
6301 readConfigRid(local, 1);
6302
6303
6304
6305
6306
6307
6308
6309 if (dwrq->length > 0) {
6310 wep_key_t key;
6311 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6312 int current_index;
6313
6314
6315 if (dwrq->length > MAX_KEY_SIZE) {
6316 return -EINVAL;
6317 }
6318
6319 current_index = get_wep_tx_idx(local);
6320 if (current_index < 0)
6321 current_index = 0;
6322
6323
6324 if (!valid_index(local, index))
6325 index = current_index;
6326
6327
6328 if (dwrq->length > MIN_KEY_SIZE)
6329 key.len = MAX_KEY_SIZE;
6330 else
6331 key.len = MIN_KEY_SIZE;
6332
6333 if(!(dwrq->flags & IW_ENCODE_NOKEY)) {
6334
6335 memset(key.key, 0, MAX_KEY_SIZE);
6336
6337 memcpy(key.key, extra, dwrq->length);
6338
6339 rc = set_wep_key(local, index, key.key, key.len, perm, 1);
6340 if (rc < 0) {
6341 airo_print_err(local->dev->name, "failed to set"
6342 " WEP key at index %d: %d.",
6343 index, rc);
6344 return rc;
6345 }
6346 }
6347
6348
6349
6350 if((index == current_index) && (key.len > 0) &&
6351 (local->config.authType == AUTH_OPEN))
6352 set_auth_type(local, AUTH_ENCRYPT);
6353 } else {
6354
6355 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6356 if (valid_index(local, index)) {
6357 rc = set_wep_tx_idx(local, index, perm, 1);
6358 if (rc < 0) {
6359 airo_print_err(local->dev->name, "failed to set"
6360 " WEP transmit index to %d: %d.",
6361 index, rc);
6362 return rc;
6363 }
6364 } else {
6365
6366 if (!(dwrq->flags & IW_ENCODE_MODE))
6367 return -EINVAL;
6368 }
6369 }
6370
6371 if (dwrq->flags & IW_ENCODE_DISABLED)
6372 set_auth_type(local, AUTH_OPEN);
6373 if(dwrq->flags & IW_ENCODE_RESTRICTED)
6374 set_auth_type(local, AUTH_SHAREDKEY);
6375 if (dwrq->flags & IW_ENCODE_OPEN)
6376 set_auth_type(local, AUTH_ENCRYPT);
6377
6378 if (local->config.authType != currentAuthType)
6379 set_bit (FLAG_COMMIT, &local->flags);
6380 return -EINPROGRESS;
6381}
6382
6383
6384
6385
6386
6387static int airo_get_encode(struct net_device *dev,
6388 struct iw_request_info *info,
6389 struct iw_point *dwrq,
6390 char *extra)
6391{
6392 struct airo_info *local = dev->ml_priv;
6393 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
6394 int wep_key_len;
6395 u8 buf[16];
6396
6397 if (!local->wep_capable)
6398 return -EOPNOTSUPP;
6399
6400 readConfigRid(local, 1);
6401
6402
6403 switch(local->config.authType) {
6404 case AUTH_ENCRYPT:
6405 dwrq->flags = IW_ENCODE_OPEN;
6406 break;
6407 case AUTH_SHAREDKEY:
6408 dwrq->flags = IW_ENCODE_RESTRICTED;
6409 break;
6410 default:
6411 case AUTH_OPEN:
6412 dwrq->flags = IW_ENCODE_DISABLED;
6413 break;
6414 }
6415
6416 dwrq->flags |= IW_ENCODE_NOKEY;
6417 memset(extra, 0, 16);
6418
6419
6420 if (!valid_index(local, index)) {
6421 index = get_wep_tx_idx(local);
6422 if (index < 0)
6423 index = 0;
6424 }
6425 dwrq->flags |= index + 1;
6426
6427
6428 wep_key_len = get_wep_key(local, index, &buf[0], sizeof(buf));
6429 if (wep_key_len < 0) {
6430 dwrq->length = 0;
6431 } else {
6432 dwrq->length = wep_key_len;
6433 memcpy(extra, buf, dwrq->length);
6434 }
6435
6436 return 0;
6437}
6438
6439
6440
6441
6442
6443static int airo_set_encodeext(struct net_device *dev,
6444 struct iw_request_info *info,
6445 union iwreq_data *wrqu,
6446 char *extra)
6447{
6448 struct airo_info *local = dev->ml_priv;
6449 struct iw_point *encoding = &wrqu->encoding;
6450 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6451 int perm = ( encoding->flags & IW_ENCODE_TEMP ? 0 : 1 );
6452 __le16 currentAuthType = local->config.authType;
6453 int idx, key_len, alg = ext->alg, set_key = 1, rc;
6454 wep_key_t key;
6455
6456 if (!local->wep_capable)
6457 return -EOPNOTSUPP;
6458
6459 readConfigRid(local, 1);
6460
6461
6462 idx = encoding->flags & IW_ENCODE_INDEX;
6463 if (idx) {
6464 if (!valid_index(local, idx - 1))
6465 return -EINVAL;
6466 idx--;
6467 } else {
6468 idx = get_wep_tx_idx(local);
6469 if (idx < 0)
6470 idx = 0;
6471 }
6472
6473 if (encoding->flags & IW_ENCODE_DISABLED)
6474 alg = IW_ENCODE_ALG_NONE;
6475
6476 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
6477
6478
6479
6480 rc = set_wep_tx_idx(local, idx, perm, 1);
6481 if (rc < 0) {
6482 airo_print_err(local->dev->name, "failed to set "
6483 "WEP transmit index to %d: %d.",
6484 idx, rc);
6485 return rc;
6486 }
6487 set_key = ext->key_len > 0 ? 1 : 0;
6488 }
6489
6490 if (set_key) {
6491
6492 memset(key.key, 0, MAX_KEY_SIZE);
6493 switch (alg) {
6494 case IW_ENCODE_ALG_NONE:
6495 key.len = 0;
6496 break;
6497 case IW_ENCODE_ALG_WEP:
6498 if (ext->key_len > MIN_KEY_SIZE) {
6499 key.len = MAX_KEY_SIZE;
6500 } else if (ext->key_len > 0) {
6501 key.len = MIN_KEY_SIZE;
6502 } else {
6503 return -EINVAL;
6504 }
6505 key_len = min (ext->key_len, key.len);
6506 memcpy(key.key, ext->key, key_len);
6507 break;
6508 default:
6509 return -EINVAL;
6510 }
6511 if (key.len == 0) {
6512 rc = set_wep_tx_idx(local, idx, perm, 1);
6513 if (rc < 0) {
6514 airo_print_err(local->dev->name,
6515 "failed to set WEP transmit index to %d: %d.",
6516 idx, rc);
6517 return rc;
6518 }
6519 } else {
6520 rc = set_wep_key(local, idx, key.key, key.len, perm, 1);
6521 if (rc < 0) {
6522 airo_print_err(local->dev->name,
6523 "failed to set WEP key at index %d: %d.",
6524 idx, rc);
6525 return rc;
6526 }
6527 }
6528 }
6529
6530
6531 if (encoding->flags & IW_ENCODE_DISABLED)
6532 set_auth_type(local, AUTH_OPEN);
6533 if(encoding->flags & IW_ENCODE_RESTRICTED)
6534 set_auth_type(local, AUTH_SHAREDKEY);
6535 if (encoding->flags & IW_ENCODE_OPEN)
6536 set_auth_type(local, AUTH_ENCRYPT);
6537
6538 if (local->config.authType != currentAuthType)
6539 set_bit (FLAG_COMMIT, &local->flags);
6540
6541 return -EINPROGRESS;
6542}
6543
6544
6545
6546
6547
6548
6549static int airo_get_encodeext(struct net_device *dev,
6550 struct iw_request_info *info,
6551 union iwreq_data *wrqu,
6552 char *extra)
6553{
6554 struct airo_info *local = dev->ml_priv;
6555 struct iw_point *encoding = &wrqu->encoding;
6556 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
6557 int idx, max_key_len, wep_key_len;
6558 u8 buf[16];
6559
6560 if (!local->wep_capable)
6561 return -EOPNOTSUPP;
6562
6563 readConfigRid(local, 1);
6564
6565 max_key_len = encoding->length - sizeof(*ext);
6566 if (max_key_len < 0)
6567 return -EINVAL;
6568
6569 idx = encoding->flags & IW_ENCODE_INDEX;
6570 if (idx) {
6571 if (!valid_index(local, idx - 1))
6572 return -EINVAL;
6573 idx--;
6574 } else {
6575 idx = get_wep_tx_idx(local);
6576 if (idx < 0)
6577 idx = 0;
6578 }
6579
6580 encoding->flags = idx + 1;
6581 memset(ext, 0, sizeof(*ext));
6582
6583
6584 switch(local->config.authType) {
6585 case AUTH_ENCRYPT:
6586 encoding->flags = IW_ENCODE_ALG_WEP | IW_ENCODE_ENABLED;
6587 break;
6588 case AUTH_SHAREDKEY:
6589 encoding->flags = IW_ENCODE_ALG_WEP | IW_ENCODE_ENABLED;
6590 break;
6591 default:
6592 case AUTH_OPEN:
6593 encoding->flags = IW_ENCODE_ALG_NONE | IW_ENCODE_DISABLED;
6594 break;
6595 }
6596
6597 encoding->flags |= IW_ENCODE_NOKEY;
6598 memset(extra, 0, 16);
6599
6600
6601 wep_key_len = get_wep_key(local, idx, &buf[0], sizeof(buf));
6602 if (wep_key_len < 0) {
6603 ext->key_len = 0;
6604 } else {
6605 ext->key_len = wep_key_len;
6606 memcpy(extra, buf, ext->key_len);
6607 }
6608
6609 return 0;
6610}
6611
6612
6613
6614
6615
6616
6617static int airo_set_auth(struct net_device *dev,
6618 struct iw_request_info *info,
6619 union iwreq_data *wrqu, char *extra)
6620{
6621 struct airo_info *local = dev->ml_priv;
6622 struct iw_param *param = &wrqu->param;
6623 __le16 currentAuthType = local->config.authType;
6624
6625 switch (param->flags & IW_AUTH_INDEX) {
6626 case IW_AUTH_WPA_VERSION:
6627 case IW_AUTH_CIPHER_PAIRWISE:
6628 case IW_AUTH_CIPHER_GROUP:
6629 case IW_AUTH_KEY_MGMT:
6630 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
6631 case IW_AUTH_PRIVACY_INVOKED:
6632
6633
6634
6635 break;
6636
6637 case IW_AUTH_DROP_UNENCRYPTED:
6638 if (param->value) {
6639
6640 if (currentAuthType == AUTH_OPEN)
6641 set_auth_type(local, AUTH_ENCRYPT);
6642 } else {
6643 set_auth_type(local, AUTH_OPEN);
6644 }
6645
6646
6647 if (local->config.authType != currentAuthType)
6648 set_bit (FLAG_COMMIT, &local->flags);
6649 break;
6650
6651 case IW_AUTH_80211_AUTH_ALG: {
6652 if (param->value & IW_AUTH_ALG_SHARED_KEY) {
6653 set_auth_type(local, AUTH_SHAREDKEY);
6654 } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) {
6655
6656
6657
6658
6659 set_auth_type(local, local->last_auth);
6660 } else
6661 return -EINVAL;
6662
6663
6664 if (local->config.authType != currentAuthType)
6665 set_bit (FLAG_COMMIT, &local->flags);
6666 break;
6667 }
6668
6669 case IW_AUTH_WPA_ENABLED:
6670
6671 if (param->value > 0)
6672 return -EOPNOTSUPP;
6673 break;
6674
6675 default:
6676 return -EOPNOTSUPP;
6677 }
6678 return -EINPROGRESS;
6679}
6680
6681
6682
6683
6684
6685
6686static int airo_get_auth(struct net_device *dev,
6687 struct iw_request_info *info,
6688 union iwreq_data *wrqu, char *extra)
6689{
6690 struct airo_info *local = dev->ml_priv;
6691 struct iw_param *param = &wrqu->param;
6692 __le16 currentAuthType = local->config.authType;
6693
6694 switch (param->flags & IW_AUTH_INDEX) {
6695 case IW_AUTH_DROP_UNENCRYPTED:
6696 switch (currentAuthType) {
6697 case AUTH_SHAREDKEY:
6698 case AUTH_ENCRYPT:
6699 param->value = 1;
6700 break;
6701 default:
6702 param->value = 0;
6703 break;
6704 }
6705 break;
6706
6707 case IW_AUTH_80211_AUTH_ALG:
6708 switch (currentAuthType) {
6709 case AUTH_SHAREDKEY:
6710 param->value = IW_AUTH_ALG_SHARED_KEY;
6711 break;
6712 case AUTH_ENCRYPT:
6713 default:
6714 param->value = IW_AUTH_ALG_OPEN_SYSTEM;
6715 break;
6716 }
6717 break;
6718
6719 case IW_AUTH_WPA_ENABLED:
6720 param->value = 0;
6721 break;
6722
6723 default:
6724 return -EOPNOTSUPP;
6725 }
6726 return 0;
6727}
6728
6729
6730
6731
6732
6733
6734static int airo_set_txpow(struct net_device *dev,
6735 struct iw_request_info *info,
6736 struct iw_param *vwrq,
6737 char *extra)
6738{
6739 struct airo_info *local = dev->ml_priv;
6740 CapabilityRid cap_rid;
6741 int i;
6742 int rc = -EINVAL;
6743 __le16 v = cpu_to_le16(vwrq->value);
6744
6745 readCapabilityRid(local, &cap_rid, 1);
6746
6747 if (vwrq->disabled) {
6748 set_bit (FLAG_RADIO_OFF, &local->flags);
6749 set_bit (FLAG_COMMIT, &local->flags);
6750 return -EINPROGRESS;
6751 }
6752 if (vwrq->flags != IW_TXPOW_MWATT) {
6753 return -EINVAL;
6754 }
6755 clear_bit (FLAG_RADIO_OFF, &local->flags);
6756 for (i = 0; i < 8 && cap_rid.txPowerLevels[i]; i++)
6757 if (v == cap_rid.txPowerLevels[i]) {
6758 readConfigRid(local, 1);
6759 local->config.txPower = v;
6760 set_bit (FLAG_COMMIT, &local->flags);
6761 rc = -EINPROGRESS;
6762 break;
6763 }
6764 return rc;
6765}
6766
6767
6768
6769
6770
6771static int airo_get_txpow(struct net_device *dev,
6772 struct iw_request_info *info,
6773 struct iw_param *vwrq,
6774 char *extra)
6775{
6776 struct airo_info *local = dev->ml_priv;
6777
6778 readConfigRid(local, 1);
6779 vwrq->value = le16_to_cpu(local->config.txPower);
6780 vwrq->fixed = 1;
6781 vwrq->disabled = test_bit(FLAG_RADIO_OFF, &local->flags);
6782 vwrq->flags = IW_TXPOW_MWATT;
6783
6784 return 0;
6785}
6786
6787
6788
6789
6790
6791static int airo_set_retry(struct net_device *dev,
6792 struct iw_request_info *info,
6793 struct iw_param *vwrq,
6794 char *extra)
6795{
6796 struct airo_info *local = dev->ml_priv;
6797 int rc = -EINVAL;
6798
6799 if(vwrq->disabled) {
6800 return -EINVAL;
6801 }
6802 readConfigRid(local, 1);
6803 if(vwrq->flags & IW_RETRY_LIMIT) {
6804 __le16 v = cpu_to_le16(vwrq->value);
6805 if(vwrq->flags & IW_RETRY_LONG)
6806 local->config.longRetryLimit = v;
6807 else if (vwrq->flags & IW_RETRY_SHORT)
6808 local->config.shortRetryLimit = v;
6809 else {
6810
6811 local->config.longRetryLimit = v;
6812 local->config.shortRetryLimit = v;
6813 }
6814 set_bit (FLAG_COMMIT, &local->flags);
6815 rc = -EINPROGRESS;
6816 }
6817 if(vwrq->flags & IW_RETRY_LIFETIME) {
6818 local->config.txLifetime = cpu_to_le16(vwrq->value / 1024);
6819 set_bit (FLAG_COMMIT, &local->flags);
6820 rc = -EINPROGRESS;
6821 }
6822 return rc;
6823}
6824
6825
6826
6827
6828
6829static int airo_get_retry(struct net_device *dev,
6830 struct iw_request_info *info,
6831 struct iw_param *vwrq,
6832 char *extra)
6833{
6834 struct airo_info *local = dev->ml_priv;
6835
6836 vwrq->disabled = 0;
6837
6838 readConfigRid(local, 1);
6839
6840 if((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
6841 vwrq->flags = IW_RETRY_LIFETIME;
6842 vwrq->value = le16_to_cpu(local->config.txLifetime) * 1024;
6843 } else if((vwrq->flags & IW_RETRY_LONG)) {
6844 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
6845 vwrq->value = le16_to_cpu(local->config.longRetryLimit);
6846 } else {
6847 vwrq->flags = IW_RETRY_LIMIT;
6848 vwrq->value = le16_to_cpu(local->config.shortRetryLimit);
6849 if(local->config.shortRetryLimit != local->config.longRetryLimit)
6850 vwrq->flags |= IW_RETRY_SHORT;
6851 }
6852
6853 return 0;
6854}
6855
6856
6857
6858
6859
6860static int airo_get_range(struct net_device *dev,
6861 struct iw_request_info *info,
6862 struct iw_point *dwrq,
6863 char *extra)
6864{
6865 struct airo_info *local = dev->ml_priv;
6866 struct iw_range *range = (struct iw_range *) extra;
6867 CapabilityRid cap_rid;
6868 int i;
6869 int k;
6870
6871 readCapabilityRid(local, &cap_rid, 1);
6872
6873 dwrq->length = sizeof(struct iw_range);
6874 memset(range, 0, sizeof(*range));
6875 range->min_nwid = 0x0000;
6876 range->max_nwid = 0x0000;
6877 range->num_channels = 14;
6878
6879
6880 k = 0;
6881 for(i = 0; i < 14; i++) {
6882 range->freq[k].i = i + 1;
6883 range->freq[k].m = 100000 *
6884 ieee80211_channel_to_frequency(i + 1, NL80211_BAND_2GHZ);
6885 range->freq[k++].e = 1;
6886 }
6887 range->num_frequency = k;
6888
6889 range->sensitivity = 65535;
6890
6891
6892 if (local->rssi)
6893 range->max_qual.qual = 100;
6894 else
6895 range->max_qual.qual = airo_get_max_quality(&cap_rid);
6896 range->max_qual.level = 0x100 - 120;
6897 range->max_qual.noise = 0x100 - 120;
6898
6899
6900
6901
6902 if (local->rssi) {
6903 range->avg_qual.qual = 50;
6904 range->avg_qual.level = 0x100 - 70;
6905 } else {
6906 range->avg_qual.qual = airo_get_avg_quality(&cap_rid);
6907 range->avg_qual.level = 0x100 - 80;
6908 }
6909 range->avg_qual.noise = 0x100 - 85;
6910
6911 for(i = 0 ; i < 8 ; i++) {
6912 range->bitrate[i] = cap_rid.supportedRates[i] * 500000;
6913 if(range->bitrate[i] == 0)
6914 break;
6915 }
6916 range->num_bitrates = i;
6917
6918
6919
6920
6921 if(i > 2)
6922 range->throughput = 5000 * 1000;
6923 else
6924 range->throughput = 1500 * 1000;
6925
6926 range->min_rts = 0;
6927 range->max_rts = AIRO_DEF_MTU;
6928 range->min_frag = 256;
6929 range->max_frag = AIRO_DEF_MTU;
6930
6931 if(cap_rid.softCap & cpu_to_le16(2)) {
6932
6933 range->encoding_size[0] = 5;
6934
6935 if (cap_rid.softCap & cpu_to_le16(0x100)) {
6936 range->encoding_size[1] = 13;
6937 range->num_encoding_sizes = 2;
6938 } else
6939 range->num_encoding_sizes = 1;
6940 range->max_encoding_tokens =
6941 cap_rid.softCap & cpu_to_le16(0x80) ? 4 : 1;
6942 } else {
6943 range->num_encoding_sizes = 0;
6944 range->max_encoding_tokens = 0;
6945 }
6946 range->min_pmp = 0;
6947 range->max_pmp = 5000000;
6948 range->min_pmt = 0;
6949 range->max_pmt = 65535 * 1024;
6950 range->pmp_flags = IW_POWER_PERIOD;
6951 range->pmt_flags = IW_POWER_TIMEOUT;
6952 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
6953
6954
6955 for(i = 0 ; i < 8 ; i++) {
6956 range->txpower[i] = le16_to_cpu(cap_rid.txPowerLevels[i]);
6957 if(range->txpower[i] == 0)
6958 break;
6959 }
6960 range->num_txpower = i;
6961 range->txpower_capa = IW_TXPOW_MWATT;
6962 range->we_version_source = 19;
6963 range->we_version_compiled = WIRELESS_EXT;
6964 range->retry_capa = IW_RETRY_LIMIT | IW_RETRY_LIFETIME;
6965 range->retry_flags = IW_RETRY_LIMIT;
6966 range->r_time_flags = IW_RETRY_LIFETIME;
6967 range->min_retry = 1;
6968 range->max_retry = 65535;
6969 range->min_r_time = 1024;
6970 range->max_r_time = 65535 * 1024;
6971
6972
6973 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
6974 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
6975 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
6976 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
6977 range->event_capa[1] = IW_EVENT_CAPA_K_1;
6978 range->event_capa[4] = IW_EVENT_CAPA_MASK(IWEVTXDROP);
6979 return 0;
6980}
6981
6982
6983
6984
6985
6986static int airo_set_power(struct net_device *dev,
6987 struct iw_request_info *info,
6988 struct iw_param *vwrq,
6989 char *extra)
6990{
6991 struct airo_info *local = dev->ml_priv;
6992
6993 readConfigRid(local, 1);
6994 if (vwrq->disabled) {
6995 if (sniffing_mode(local))
6996 return -EINVAL;
6997 local->config.powerSaveMode = POWERSAVE_CAM;
6998 local->config.rmode &= ~RXMODE_MASK;
6999 local->config.rmode |= RXMODE_BC_MC_ADDR;
7000 set_bit (FLAG_COMMIT, &local->flags);
7001 return -EINPROGRESS;
7002 }
7003 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
7004 local->config.fastListenDelay = cpu_to_le16((vwrq->value + 500) / 1024);
7005 local->config.powerSaveMode = POWERSAVE_PSPCAM;
7006 set_bit (FLAG_COMMIT, &local->flags);
7007 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
7008 local->config.fastListenInterval =
7009 local->config.listenInterval =
7010 cpu_to_le16((vwrq->value + 500) / 1024);
7011 local->config.powerSaveMode = POWERSAVE_PSPCAM;
7012 set_bit (FLAG_COMMIT, &local->flags);
7013 }
7014 switch (vwrq->flags & IW_POWER_MODE) {
7015 case IW_POWER_UNICAST_R:
7016 if (sniffing_mode(local))
7017 return -EINVAL;
7018 local->config.rmode &= ~RXMODE_MASK;
7019 local->config.rmode |= RXMODE_ADDR;
7020 set_bit (FLAG_COMMIT, &local->flags);
7021 break;
7022 case IW_POWER_ALL_R:
7023 if (sniffing_mode(local))
7024 return -EINVAL;
7025 local->config.rmode &= ~RXMODE_MASK;
7026 local->config.rmode |= RXMODE_BC_MC_ADDR;
7027 set_bit (FLAG_COMMIT, &local->flags);
7028 case IW_POWER_ON:
7029
7030 break;
7031 default:
7032 return -EINVAL;
7033 }
7034
7035
7036 return -EINPROGRESS;
7037}
7038
7039
7040
7041
7042
7043static int airo_get_power(struct net_device *dev,
7044 struct iw_request_info *info,
7045 struct iw_param *vwrq,
7046 char *extra)
7047{
7048 struct airo_info *local = dev->ml_priv;
7049 __le16 mode;
7050
7051 readConfigRid(local, 1);
7052 mode = local->config.powerSaveMode;
7053 if ((vwrq->disabled = (mode == POWERSAVE_CAM)))
7054 return 0;
7055 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
7056 vwrq->value = le16_to_cpu(local->config.fastListenDelay) * 1024;
7057 vwrq->flags = IW_POWER_TIMEOUT;
7058 } else {
7059 vwrq->value = le16_to_cpu(local->config.fastListenInterval) * 1024;
7060 vwrq->flags = IW_POWER_PERIOD;
7061 }
7062 if ((local->config.rmode & RXMODE_MASK) == RXMODE_ADDR)
7063 vwrq->flags |= IW_POWER_UNICAST_R;
7064 else
7065 vwrq->flags |= IW_POWER_ALL_R;
7066
7067 return 0;
7068}
7069
7070
7071
7072
7073
7074static int airo_set_sens(struct net_device *dev,
7075 struct iw_request_info *info,
7076 struct iw_param *vwrq,
7077 char *extra)
7078{
7079 struct airo_info *local = dev->ml_priv;
7080
7081 readConfigRid(local, 1);
7082 local->config.rssiThreshold =
7083 cpu_to_le16(vwrq->disabled ? RSSI_DEFAULT : vwrq->value);
7084 set_bit (FLAG_COMMIT, &local->flags);
7085
7086 return -EINPROGRESS;
7087}
7088
7089
7090
7091
7092
7093static int airo_get_sens(struct net_device *dev,
7094 struct iw_request_info *info,
7095 struct iw_param *vwrq,
7096 char *extra)
7097{
7098 struct airo_info *local = dev->ml_priv;
7099
7100 readConfigRid(local, 1);
7101 vwrq->value = le16_to_cpu(local->config.rssiThreshold);
7102 vwrq->disabled = (vwrq->value == 0);
7103 vwrq->fixed = 1;
7104
7105 return 0;
7106}
7107
7108
7109
7110
7111
7112
7113static int airo_get_aplist(struct net_device *dev,
7114 struct iw_request_info *info,
7115 struct iw_point *dwrq,
7116 char *extra)
7117{
7118 struct airo_info *local = dev->ml_priv;
7119 struct sockaddr *address = (struct sockaddr *) extra;
7120 struct iw_quality *qual;
7121 BSSListRid BSSList;
7122 int i;
7123 int loseSync = capable(CAP_NET_ADMIN) ? 1: -1;
7124
7125 qual = kmalloc_array(IW_MAX_AP, sizeof(*qual), GFP_KERNEL);
7126 if (!qual)
7127 return -ENOMEM;
7128
7129 for (i = 0; i < IW_MAX_AP; i++) {
7130 u16 dBm;
7131 if (readBSSListRid(local, loseSync, &BSSList))
7132 break;
7133 loseSync = 0;
7134 memcpy(address[i].sa_data, BSSList.bssid, ETH_ALEN);
7135 address[i].sa_family = ARPHRD_ETHER;
7136 dBm = le16_to_cpu(BSSList.dBm);
7137 if (local->rssi) {
7138 qual[i].level = 0x100 - dBm;
7139 qual[i].qual = airo_dbm_to_pct(local->rssi, dBm);
7140 qual[i].updated = IW_QUAL_QUAL_UPDATED
7141 | IW_QUAL_LEVEL_UPDATED
7142 | IW_QUAL_DBM;
7143 } else {
7144 qual[i].level = (dBm + 321) / 2;
7145 qual[i].qual = 0;
7146 qual[i].updated = IW_QUAL_QUAL_INVALID
7147 | IW_QUAL_LEVEL_UPDATED
7148 | IW_QUAL_DBM;
7149 }
7150 qual[i].noise = local->wstats.qual.noise;
7151 if (BSSList.index == cpu_to_le16(0xffff))
7152 break;
7153 }
7154 if (!i) {
7155 StatusRid status_rid;
7156 readStatusRid(local, &status_rid, 1);
7157 for (i = 0;
7158 i < min(IW_MAX_AP, 4) &&
7159 (status_rid.bssid[i][0]
7160 & status_rid.bssid[i][1]
7161 & status_rid.bssid[i][2]
7162 & status_rid.bssid[i][3]
7163 & status_rid.bssid[i][4]
7164 & status_rid.bssid[i][5])!=0xff &&
7165 (status_rid.bssid[i][0]
7166 | status_rid.bssid[i][1]
7167 | status_rid.bssid[i][2]
7168 | status_rid.bssid[i][3]
7169 | status_rid.bssid[i][4]
7170 | status_rid.bssid[i][5]);
7171 i++) {
7172 memcpy(address[i].sa_data,
7173 status_rid.bssid[i], ETH_ALEN);
7174 address[i].sa_family = ARPHRD_ETHER;
7175 }
7176 } else {
7177 dwrq->flags = 1;
7178 memcpy(extra + sizeof(struct sockaddr) * i, qual,
7179 sizeof(struct iw_quality) * i);
7180 }
7181 dwrq->length = i;
7182
7183 kfree(qual);
7184 return 0;
7185}
7186
7187
7188
7189
7190
7191static int airo_set_scan(struct net_device *dev,
7192 struct iw_request_info *info,
7193 struct iw_point *dwrq,
7194 char *extra)
7195{
7196 struct airo_info *ai = dev->ml_priv;
7197 Cmd cmd;
7198 Resp rsp;
7199 int wake = 0;
7200 APListRid APList_rid_empty;
7201
7202
7203
7204
7205
7206
7207
7208 if (ai->flags & FLAG_RADIO_MASK) return -ENETDOWN;
7209
7210 if (down_interruptible(&ai->sem))
7211 return -ERESTARTSYS;
7212
7213
7214
7215 if (ai->scan_timeout > 0)
7216 goto out;
7217
7218
7219 memset(&APList_rid_empty, 0, sizeof(APList_rid_empty));
7220 APList_rid_empty.len = cpu_to_le16(sizeof(APList_rid_empty));
7221 disable_MAC(ai, 2);
7222 writeAPListRid(ai, &APList_rid_empty, 0);
7223 enable_MAC(ai, 0);
7224
7225
7226 ai->scan_timeout = RUN_AT(3*HZ);
7227 memset(&cmd, 0, sizeof(cmd));
7228 cmd.cmd=CMD_LISTBSS;
7229 issuecommand(ai, &cmd, &rsp);
7230 wake = 1;
7231
7232out:
7233 up(&ai->sem);
7234 if (wake)
7235 wake_up_interruptible(&ai->thr_wait);
7236 return 0;
7237}
7238
7239
7240
7241
7242
7243
7244static inline char *airo_translate_scan(struct net_device *dev,
7245 struct iw_request_info *info,
7246 char *current_ev,
7247 char *end_buf,
7248 BSSListRid *bss)
7249{
7250 struct airo_info *ai = dev->ml_priv;
7251 struct iw_event iwe;
7252 __le16 capabilities;
7253 char * current_val;
7254 int i;
7255 char * buf;
7256 u16 dBm;
7257
7258
7259 iwe.cmd = SIOCGIWAP;
7260 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
7261 memcpy(iwe.u.ap_addr.sa_data, bss->bssid, ETH_ALEN);
7262 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7263 &iwe, IW_EV_ADDR_LEN);
7264
7265
7266
7267
7268 iwe.u.data.length = bss->ssidLen;
7269 if(iwe.u.data.length > 32)
7270 iwe.u.data.length = 32;
7271 iwe.cmd = SIOCGIWESSID;
7272 iwe.u.data.flags = 1;
7273 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
7274 &iwe, bss->ssid);
7275
7276
7277 iwe.cmd = SIOCGIWMODE;
7278 capabilities = bss->cap;
7279 if(capabilities & (CAP_ESS | CAP_IBSS)) {
7280 if(capabilities & CAP_ESS)
7281 iwe.u.mode = IW_MODE_MASTER;
7282 else
7283 iwe.u.mode = IW_MODE_ADHOC;
7284 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7285 &iwe, IW_EV_UINT_LEN);
7286 }
7287
7288
7289 iwe.cmd = SIOCGIWFREQ;
7290 iwe.u.freq.m = le16_to_cpu(bss->dsChannel);
7291 iwe.u.freq.m = 100000 *
7292 ieee80211_channel_to_frequency(iwe.u.freq.m, NL80211_BAND_2GHZ);
7293 iwe.u.freq.e = 1;
7294 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7295 &iwe, IW_EV_FREQ_LEN);
7296
7297 dBm = le16_to_cpu(bss->dBm);
7298
7299
7300 iwe.cmd = IWEVQUAL;
7301 if (ai->rssi) {
7302 iwe.u.qual.level = 0x100 - dBm;
7303 iwe.u.qual.qual = airo_dbm_to_pct(ai->rssi, dBm);
7304 iwe.u.qual.updated = IW_QUAL_QUAL_UPDATED
7305 | IW_QUAL_LEVEL_UPDATED
7306 | IW_QUAL_DBM;
7307 } else {
7308 iwe.u.qual.level = (dBm + 321) / 2;
7309 iwe.u.qual.qual = 0;
7310 iwe.u.qual.updated = IW_QUAL_QUAL_INVALID
7311 | IW_QUAL_LEVEL_UPDATED
7312 | IW_QUAL_DBM;
7313 }
7314 iwe.u.qual.noise = ai->wstats.qual.noise;
7315 current_ev = iwe_stream_add_event(info, current_ev, end_buf,
7316 &iwe, IW_EV_QUAL_LEN);
7317
7318
7319 iwe.cmd = SIOCGIWENCODE;
7320 if(capabilities & CAP_PRIVACY)
7321 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
7322 else
7323 iwe.u.data.flags = IW_ENCODE_DISABLED;
7324 iwe.u.data.length = 0;
7325 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
7326 &iwe, bss->ssid);
7327
7328
7329
7330 current_val = current_ev + iwe_stream_lcp_len(info);
7331
7332 iwe.cmd = SIOCGIWRATE;
7333
7334 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
7335
7336 for(i = 0 ; i < 8 ; i++) {
7337
7338 if(bss->rates[i] == 0)
7339 break;
7340
7341 iwe.u.bitrate.value = ((bss->rates[i] & 0x7f) * 500000);
7342
7343 current_val = iwe_stream_add_value(info, current_ev,
7344 current_val, end_buf,
7345 &iwe, IW_EV_PARAM_LEN);
7346 }
7347
7348 if ((current_val - current_ev) > iwe_stream_lcp_len(info))
7349 current_ev = current_val;
7350
7351
7352 buf = kmalloc(30, GFP_KERNEL);
7353 if (buf) {
7354 iwe.cmd = IWEVCUSTOM;
7355 sprintf(buf, "bcn_int=%d", bss->beaconInterval);
7356 iwe.u.data.length = strlen(buf);
7357 current_ev = iwe_stream_add_point(info, current_ev, end_buf,
7358 &iwe, buf);
7359 kfree(buf);
7360 }
7361
7362
7363 if (test_bit(FLAG_WPA_CAPABLE, &ai->flags)) {
7364 unsigned int num_null_ies = 0;
7365 u16 length = sizeof (bss->extra.iep);
7366 u8 *ie = (void *)&bss->extra.iep;
7367
7368 while ((length >= 2) && (num_null_ies < 2)) {
7369 if (2 + ie[1] > length) {
7370
7371 break;
7372 }
7373
7374 switch (ie[0]) {
7375 case WLAN_EID_SSID:
7376
7377
7378 if (!ie[1])
7379 num_null_ies++;
7380 break;
7381
7382 case WLAN_EID_VENDOR_SPECIFIC:
7383 if (ie[1] >= 4 &&
7384 ie[2] == 0x00 &&
7385 ie[3] == 0x50 &&
7386 ie[4] == 0xf2 &&
7387 ie[5] == 0x01) {
7388 iwe.cmd = IWEVGENIE;
7389
7390 iwe.u.data.length = min(ie[1] + 2,
7391 64);
7392 current_ev = iwe_stream_add_point(
7393 info, current_ev,
7394 end_buf, &iwe, ie);
7395 }
7396 break;
7397
7398 case WLAN_EID_RSN:
7399 iwe.cmd = IWEVGENIE;
7400
7401 iwe.u.data.length = min(ie[1] + 2, 64);
7402 current_ev = iwe_stream_add_point(
7403 info, current_ev, end_buf,
7404 &iwe, ie);
7405 break;
7406
7407 default:
7408 break;
7409 }
7410
7411 length -= 2 + ie[1];
7412 ie += 2 + ie[1];
7413 }
7414 }
7415 return current_ev;
7416}
7417
7418
7419
7420
7421
7422static int airo_get_scan(struct net_device *dev,
7423 struct iw_request_info *info,
7424 struct iw_point *dwrq,
7425 char *extra)
7426{
7427 struct airo_info *ai = dev->ml_priv;
7428 BSSListElement *net;
7429 int err = 0;
7430 char *current_ev = extra;
7431
7432
7433 if (ai->scan_timeout > 0)
7434 return -EAGAIN;
7435
7436 if (down_interruptible(&ai->sem))
7437 return -EAGAIN;
7438
7439 list_for_each_entry (net, &ai->network_list, list) {
7440
7441 current_ev = airo_translate_scan(dev, info, current_ev,
7442 extra + dwrq->length,
7443 &net->bss);
7444
7445
7446 if((extra + dwrq->length - current_ev) <= IW_EV_ADDR_LEN) {
7447
7448 err = -E2BIG;
7449 goto out;
7450 }
7451 }
7452
7453
7454 dwrq->length = (current_ev - extra);
7455 dwrq->flags = 0;
7456
7457out:
7458 up(&ai->sem);
7459 return err;
7460}
7461
7462
7463
7464
7465
7466static int airo_config_commit(struct net_device *dev,
7467 struct iw_request_info *info,
7468 void *zwrq,
7469 char *extra)
7470{
7471 struct airo_info *local = dev->ml_priv;
7472
7473 if (!test_bit (FLAG_COMMIT, &local->flags))
7474 return 0;
7475
7476
7477
7478 disable_MAC(local, 1);
7479 if (test_bit (FLAG_RESET, &local->flags)) {
7480 SsidRid SSID_rid;
7481
7482 readSsidRid(local, &SSID_rid);
7483 if (test_bit(FLAG_MPI,&local->flags))
7484 setup_card(local, dev->dev_addr, 1 );
7485 else
7486 reset_airo_card(dev);
7487 disable_MAC(local, 1);
7488 writeSsidRid(local, &SSID_rid, 1);
7489 writeAPListRid(local, &local->APList, 1);
7490 }
7491 if (down_interruptible(&local->sem))
7492 return -ERESTARTSYS;
7493 writeConfigRid(local, 0);
7494 enable_MAC(local, 0);
7495 if (test_bit (FLAG_RESET, &local->flags))
7496 airo_set_promisc(local);
7497 else
7498 up(&local->sem);
7499
7500 return 0;
7501}
7502
7503
7504
7505
7506
7507
7508static const struct iw_priv_args airo_private_args[] = {
7509
7510 { AIROIOCTL, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
7511 IW_PRIV_TYPE_BYTE | 2047, "airoioctl" },
7512 { AIROIDIFC, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof (aironet_ioctl),
7513 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "airoidifc" },
7514};
7515
7516static const iw_handler airo_handler[] =
7517{
7518 (iw_handler) airo_config_commit,
7519 (iw_handler) airo_get_name,
7520 (iw_handler) NULL,
7521 (iw_handler) NULL,
7522 (iw_handler) airo_set_freq,
7523 (iw_handler) airo_get_freq,
7524 (iw_handler) airo_set_mode,
7525 (iw_handler) airo_get_mode,
7526 (iw_handler) airo_set_sens,
7527 (iw_handler) airo_get_sens,
7528 (iw_handler) NULL,
7529 (iw_handler) airo_get_range,
7530 (iw_handler) NULL,
7531 (iw_handler) NULL,
7532 (iw_handler) NULL,
7533 (iw_handler) NULL,
7534 iw_handler_set_spy,
7535 iw_handler_get_spy,
7536 iw_handler_set_thrspy,
7537 iw_handler_get_thrspy,
7538 (iw_handler) airo_set_wap,
7539 (iw_handler) airo_get_wap,
7540 (iw_handler) NULL,
7541 (iw_handler) airo_get_aplist,
7542 (iw_handler) airo_set_scan,
7543 (iw_handler) airo_get_scan,
7544 (iw_handler) airo_set_essid,
7545 (iw_handler) airo_get_essid,
7546 (iw_handler) airo_set_nick,
7547 (iw_handler) airo_get_nick,
7548 (iw_handler) NULL,
7549 (iw_handler) NULL,
7550 (iw_handler) airo_set_rate,
7551 (iw_handler) airo_get_rate,
7552 (iw_handler) airo_set_rts,
7553 (iw_handler) airo_get_rts,
7554 (iw_handler) airo_set_frag,
7555 (iw_handler) airo_get_frag,
7556 (iw_handler) airo_set_txpow,
7557 (iw_handler) airo_get_txpow,
7558 (iw_handler) airo_set_retry,
7559 (iw_handler) airo_get_retry,
7560 (iw_handler) airo_set_encode,
7561 (iw_handler) airo_get_encode,
7562 (iw_handler) airo_set_power,
7563 (iw_handler) airo_get_power,
7564 (iw_handler) NULL,
7565 (iw_handler) NULL,
7566 (iw_handler) NULL,
7567 (iw_handler) NULL,
7568 (iw_handler) airo_set_auth,
7569 (iw_handler) airo_get_auth,
7570 (iw_handler) airo_set_encodeext,
7571 (iw_handler) airo_get_encodeext,
7572 (iw_handler) NULL,
7573};
7574
7575
7576
7577
7578
7579
7580
7581
7582static const iw_handler airo_private_handler[] =
7583{
7584 NULL,
7585};
7586
7587static const struct iw_handler_def airo_handler_def =
7588{
7589 .num_standard = ARRAY_SIZE(airo_handler),
7590 .num_private = ARRAY_SIZE(airo_private_handler),
7591 .num_private_args = ARRAY_SIZE(airo_private_args),
7592 .standard = airo_handler,
7593 .private = airo_private_handler,
7594 .private_args = airo_private_args,
7595 .get_wireless_stats = airo_get_wireless_stats,
7596};
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
7612{
7613 int rc = 0;
7614 struct airo_info *ai = dev->ml_priv;
7615
7616 if (ai->power.event)
7617 return 0;
7618
7619 switch (cmd) {
7620#ifdef CISCO_EXT
7621 case AIROIDIFC:
7622#ifdef AIROOLDIDIFC
7623 case AIROOLDIDIFC:
7624#endif
7625 {
7626 int val = AIROMAGIC;
7627 aironet_ioctl com;
7628 if (copy_from_user(&com,rq->ifr_data,sizeof(com)))
7629 rc = -EFAULT;
7630 else if (copy_to_user(com.data,(char *)&val,sizeof(val)))
7631 rc = -EFAULT;
7632 }
7633 break;
7634
7635 case AIROIOCTL:
7636#ifdef AIROOLDIOCTL
7637 case AIROOLDIOCTL:
7638#endif
7639
7640
7641
7642 {
7643 aironet_ioctl com;
7644 if (copy_from_user(&com,rq->ifr_data,sizeof(com))) {
7645 rc = -EFAULT;
7646 break;
7647 }
7648
7649
7650
7651 if ( com.command == AIRORSWVERSION ) {
7652 if (copy_to_user(com.data, swversion, sizeof(swversion)))
7653 rc = -EFAULT;
7654 else
7655 rc = 0;
7656 }
7657 else if ( com.command <= AIRORRID)
7658 rc = readrids(dev,&com);
7659 else if ( com.command >= AIROPCAP && com.command <= (AIROPLEAPUSR+2) )
7660 rc = writerids(dev,&com);
7661 else if ( com.command >= AIROFLSHRST && com.command <= AIRORESTART )
7662 rc = flashcard(dev,&com);
7663 else
7664 rc = -EINVAL;
7665 }
7666 break;
7667#endif
7668
7669
7670 default:
7671 rc = -EOPNOTSUPP;
7672 }
7673 return rc;
7674}
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685static void airo_read_wireless_stats(struct airo_info *local)
7686{
7687 StatusRid status_rid;
7688 StatsRid stats_rid;
7689 CapabilityRid cap_rid;
7690 __le32 *vals = stats_rid.vals;
7691
7692
7693 clear_bit(JOB_WSTATS, &local->jobs);
7694 if (local->power.event) {
7695 up(&local->sem);
7696 return;
7697 }
7698 readCapabilityRid(local, &cap_rid, 0);
7699 readStatusRid(local, &status_rid, 0);
7700 readStatsRid(local, &stats_rid, RID_STATS, 0);
7701 up(&local->sem);
7702
7703
7704 local->wstats.status = le16_to_cpu(status_rid.mode);
7705
7706
7707 if (local->rssi) {
7708 local->wstats.qual.level =
7709 airo_rssi_to_dbm(local->rssi,
7710 le16_to_cpu(status_rid.sigQuality));
7711
7712 local->wstats.qual.qual =
7713 le16_to_cpu(status_rid.normalizedSignalStrength);
7714 } else {
7715 local->wstats.qual.level =
7716 (le16_to_cpu(status_rid.normalizedSignalStrength) + 321) / 2;
7717 local->wstats.qual.qual = airo_get_quality(&status_rid, &cap_rid);
7718 }
7719 if (le16_to_cpu(status_rid.len) >= 124) {
7720 local->wstats.qual.noise = 0x100 - status_rid.noisedBm;
7721 local->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
7722 } else {
7723 local->wstats.qual.noise = 0;
7724 local->wstats.qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED | IW_QUAL_NOISE_INVALID | IW_QUAL_DBM;
7725 }
7726
7727
7728
7729 local->wstats.discard.nwid = le32_to_cpu(vals[56]) +
7730 le32_to_cpu(vals[57]) +
7731 le32_to_cpu(vals[58]);
7732 local->wstats.discard.code = le32_to_cpu(vals[6]);
7733 local->wstats.discard.fragment = le32_to_cpu(vals[30]);
7734 local->wstats.discard.retries = le32_to_cpu(vals[10]);
7735 local->wstats.discard.misc = le32_to_cpu(vals[1]) +
7736 le32_to_cpu(vals[32]);
7737 local->wstats.miss.beacon = le32_to_cpu(vals[34]);
7738}
7739
7740static struct iw_statistics *airo_get_wireless_stats(struct net_device *dev)
7741{
7742 struct airo_info *local = dev->ml_priv;
7743
7744 if (!test_bit(JOB_WSTATS, &local->jobs)) {
7745
7746 if (down_trylock(&local->sem) != 0) {
7747 set_bit(JOB_WSTATS, &local->jobs);
7748 wake_up_interruptible(&local->thr_wait);
7749 } else
7750 airo_read_wireless_stats(local);
7751 }
7752
7753 return &local->wstats;
7754}
7755
7756#ifdef CISCO_EXT
7757
7758
7759
7760
7761
7762
7763static int readrids(struct net_device *dev, aironet_ioctl *comp) {
7764 unsigned short ridcode;
7765 unsigned char *iobuf;
7766 int len;
7767 struct airo_info *ai = dev->ml_priv;
7768
7769 if (test_bit(FLAG_FLASHING, &ai->flags))
7770 return -EIO;
7771
7772 switch(comp->command)
7773 {
7774 case AIROGCAP: ridcode = RID_CAPABILITIES; break;
7775 case AIROGCFG: ridcode = RID_CONFIG;
7776 if (test_bit(FLAG_COMMIT, &ai->flags)) {
7777 disable_MAC (ai, 1);
7778 writeConfigRid (ai, 1);
7779 enable_MAC(ai, 1);
7780 }
7781 break;
7782 case AIROGSLIST: ridcode = RID_SSID; break;
7783 case AIROGVLIST: ridcode = RID_APLIST; break;
7784 case AIROGDRVNAM: ridcode = RID_DRVNAME; break;
7785 case AIROGEHTENC: ridcode = RID_ETHERENCAP; break;
7786 case AIROGWEPKTMP: ridcode = RID_WEP_TEMP;
7787
7788 if (!capable(CAP_NET_ADMIN))
7789 return -EPERM;
7790 break;
7791 case AIROGWEPKNV: ridcode = RID_WEP_PERM;
7792
7793 if (!capable(CAP_NET_ADMIN))
7794 return -EPERM;
7795 break;
7796 case AIROGSTAT: ridcode = RID_STATUS; break;
7797 case AIROGSTATSD32: ridcode = RID_STATSDELTA; break;
7798 case AIROGSTATSC32: ridcode = RID_STATS; break;
7799 case AIROGMICSTATS:
7800 if (copy_to_user(comp->data, &ai->micstats,
7801 min((int)comp->len,(int)sizeof(ai->micstats))))
7802 return -EFAULT;
7803 return 0;
7804 case AIRORRID: ridcode = comp->ridnum; break;
7805 default:
7806 return -EINVAL;
7807 }
7808
7809 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7810 return -ENOMEM;
7811
7812 PC4500_readrid(ai,ridcode,iobuf,RIDSIZE, 1);
7813
7814
7815
7816
7817 len = comp->len;
7818
7819 if (copy_to_user(comp->data, iobuf, min(len, (int)RIDSIZE))) {
7820 kfree (iobuf);
7821 return -EFAULT;
7822 }
7823 kfree (iobuf);
7824 return 0;
7825}
7826
7827
7828
7829
7830
7831static int writerids(struct net_device *dev, aironet_ioctl *comp) {
7832 struct airo_info *ai = dev->ml_priv;
7833 int ridcode;
7834 int enabled;
7835 int (*writer)(struct airo_info *, u16 rid, const void *, int, int);
7836 unsigned char *iobuf;
7837
7838
7839 if (!capable(CAP_NET_ADMIN))
7840 return -EPERM;
7841
7842 if (test_bit(FLAG_FLASHING, &ai->flags))
7843 return -EIO;
7844
7845 ridcode = 0;
7846 writer = do_writerid;
7847
7848 switch(comp->command)
7849 {
7850 case AIROPSIDS: ridcode = RID_SSID; break;
7851 case AIROPCAP: ridcode = RID_CAPABILITIES; break;
7852 case AIROPAPLIST: ridcode = RID_APLIST; break;
7853 case AIROPCFG: ai->config.len = 0;
7854 clear_bit(FLAG_COMMIT, &ai->flags);
7855 ridcode = RID_CONFIG; break;
7856 case AIROPWEPKEYNV: ridcode = RID_WEP_PERM; break;
7857 case AIROPLEAPUSR: ridcode = RID_LEAPUSERNAME; break;
7858 case AIROPLEAPPWD: ridcode = RID_LEAPPASSWORD; break;
7859 case AIROPWEPKEY: ridcode = RID_WEP_TEMP; writer = PC4500_writerid;
7860 break;
7861 case AIROPLEAPUSR+1: ridcode = 0xFF2A; break;
7862 case AIROPLEAPUSR+2: ridcode = 0xFF2B; break;
7863
7864
7865
7866
7867 case AIROPMACON:
7868 if (enable_MAC(ai, 1) != 0)
7869 return -EIO;
7870 return 0;
7871
7872
7873
7874
7875
7876 case AIROPMACOFF:
7877 disable_MAC(ai, 1);
7878 return 0;
7879
7880
7881
7882
7883
7884 case AIROPSTCLR:
7885 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7886 return -ENOMEM;
7887
7888 PC4500_readrid(ai,RID_STATSDELTACLEAR,iobuf,RIDSIZE, 1);
7889
7890 enabled = ai->micstats.enabled;
7891 memset(&ai->micstats,0,sizeof(ai->micstats));
7892 ai->micstats.enabled = enabled;
7893
7894 if (copy_to_user(comp->data, iobuf,
7895 min((int)comp->len, (int)RIDSIZE))) {
7896 kfree (iobuf);
7897 return -EFAULT;
7898 }
7899 kfree (iobuf);
7900 return 0;
7901
7902 default:
7903 return -EOPNOTSUPP;
7904 }
7905 if(comp->len > RIDSIZE)
7906 return -EINVAL;
7907
7908 if ((iobuf = kmalloc(RIDSIZE, GFP_KERNEL)) == NULL)
7909 return -ENOMEM;
7910
7911 if (copy_from_user(iobuf,comp->data,comp->len)) {
7912 kfree (iobuf);
7913 return -EFAULT;
7914 }
7915
7916 if (comp->command == AIROPCFG) {
7917 ConfigRid *cfg = (ConfigRid *)iobuf;
7918
7919 if (test_bit(FLAG_MIC_CAPABLE, &ai->flags))
7920 cfg->opmode |= MODE_MIC;
7921
7922 if ((cfg->opmode & MODE_CFG_MASK) == MODE_STA_IBSS)
7923 set_bit (FLAG_ADHOC, &ai->flags);
7924 else
7925 clear_bit (FLAG_ADHOC, &ai->flags);
7926 }
7927
7928 if((*writer)(ai, ridcode, iobuf,comp->len,1)) {
7929 kfree (iobuf);
7930 return -EIO;
7931 }
7932 kfree (iobuf);
7933 return 0;
7934}
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945static int flashcard(struct net_device *dev, aironet_ioctl *comp) {
7946 int z;
7947
7948
7949 if (!capable(CAP_NET_ADMIN))
7950 return -EPERM;
7951
7952 switch(comp->command)
7953 {
7954 case AIROFLSHRST:
7955 return cmdreset((struct airo_info *)dev->ml_priv);
7956
7957 case AIROFLSHSTFL:
7958 if (!AIRO_FLASH(dev) &&
7959 (AIRO_FLASH(dev) = kmalloc(FLASHSIZE, GFP_KERNEL)) == NULL)
7960 return -ENOMEM;
7961 return setflashmode((struct airo_info *)dev->ml_priv);
7962
7963 case AIROFLSHGCHR:
7964 if(comp->len != sizeof(int))
7965 return -EINVAL;
7966 if (copy_from_user(&z,comp->data,comp->len))
7967 return -EFAULT;
7968 return flashgchar((struct airo_info *)dev->ml_priv, z, 8000);
7969
7970 case AIROFLSHPCHR:
7971 if(comp->len != sizeof(int))
7972 return -EINVAL;
7973 if (copy_from_user(&z,comp->data,comp->len))
7974 return -EFAULT;
7975 return flashpchar((struct airo_info *)dev->ml_priv, z, 8000);
7976
7977 case AIROFLPUTBUF:
7978 if (!AIRO_FLASH(dev))
7979 return -ENOMEM;
7980 if(comp->len > FLASHSIZE)
7981 return -EINVAL;
7982 if (copy_from_user(AIRO_FLASH(dev), comp->data, comp->len))
7983 return -EFAULT;
7984
7985 flashputbuf((struct airo_info *)dev->ml_priv);
7986 return 0;
7987
7988 case AIRORESTART:
7989 if (flashrestart((struct airo_info *)dev->ml_priv, dev))
7990 return -EIO;
7991 return 0;
7992 }
7993 return -EINVAL;
7994}
7995
7996#define FLASH_COMMAND 0x7e7e
7997
7998
7999
8000
8001
8002
8003
8004static int cmdreset(struct airo_info *ai) {
8005 disable_MAC(ai, 1);
8006
8007 if(!waitbusy (ai)){
8008 airo_print_info(ai->dev->name, "Waitbusy hang before RESET");
8009 return -EBUSY;
8010 }
8011
8012 OUT4500(ai,COMMAND,CMD_SOFTRESET);
8013
8014 ssleep(1);
8015
8016 if(!waitbusy (ai)){
8017 airo_print_info(ai->dev->name, "Waitbusy hang AFTER RESET");
8018 return -EBUSY;
8019 }
8020 return 0;
8021}
8022
8023
8024
8025
8026
8027
8028static int setflashmode (struct airo_info *ai) {
8029 set_bit (FLAG_FLASHING, &ai->flags);
8030
8031 OUT4500(ai, SWS0, FLASH_COMMAND);
8032 OUT4500(ai, SWS1, FLASH_COMMAND);
8033 if (probe) {
8034 OUT4500(ai, SWS0, FLASH_COMMAND);
8035 OUT4500(ai, COMMAND,0x10);
8036 } else {
8037 OUT4500(ai, SWS2, FLASH_COMMAND);
8038 OUT4500(ai, SWS3, FLASH_COMMAND);
8039 OUT4500(ai, COMMAND,0);
8040 }
8041 msleep(500);
8042
8043 if(!waitbusy(ai)) {
8044 clear_bit (FLAG_FLASHING, &ai->flags);
8045 airo_print_info(ai->dev->name, "Waitbusy hang after setflash mode");
8046 return -EIO;
8047 }
8048 return 0;
8049}
8050
8051
8052
8053
8054
8055static int flashpchar(struct airo_info *ai,int byte,int dwelltime) {
8056 int echo;
8057 int waittime;
8058
8059 byte |= 0x8000;
8060
8061 if(dwelltime == 0 )
8062 dwelltime = 200;
8063
8064 waittime=dwelltime;
8065
8066
8067 while ((IN4500 (ai, SWS0) & 0x8000) && waittime > 0) {
8068 udelay (50);
8069 waittime -= 50;
8070 }
8071
8072
8073 if(waittime <= 0 ){
8074 airo_print_info(ai->dev->name, "flash putchar busywait timeout!");
8075 return -EBUSY;
8076 }
8077
8078
8079 do {
8080 OUT4500(ai,SWS0,byte);
8081 udelay(50);
8082 dwelltime -= 50;
8083 echo = IN4500(ai,SWS1);
8084 } while (dwelltime >= 0 && echo != byte);
8085
8086 OUT4500(ai,SWS1,0);
8087
8088 return (echo == byte) ? 0 : -EIO;
8089}
8090
8091
8092
8093
8094
8095static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime){
8096 int rchar;
8097 unsigned char rbyte=0;
8098
8099 do {
8100 rchar = IN4500(ai,SWS1);
8101
8102 if(dwelltime && !(0x8000 & rchar)){
8103 dwelltime -= 10;
8104 mdelay(10);
8105 continue;
8106 }
8107 rbyte = 0xff & rchar;
8108
8109 if( (rbyte == matchbyte) && (0x8000 & rchar) ){
8110 OUT4500(ai,SWS1,0);
8111 return 0;
8112 }
8113 if( rbyte == 0x81 || rbyte == 0x82 || rbyte == 0x83 || rbyte == 0x1a || 0xffff == rchar)
8114 break;
8115 OUT4500(ai,SWS1,0);
8116
8117 }while(dwelltime > 0);
8118 return -EIO;
8119}
8120
8121
8122
8123
8124
8125
8126static int flashputbuf(struct airo_info *ai){
8127 int nwords;
8128
8129
8130 if (test_bit(FLAG_MPI,&ai->flags))
8131 memcpy_toio(ai->pciaux + 0x8000, ai->flash, FLASHSIZE);
8132 else {
8133 OUT4500(ai,AUXPAGE,0x100);
8134 OUT4500(ai,AUXOFF,0);
8135
8136 for(nwords=0;nwords != FLASHSIZE / 2;nwords++){
8137 OUT4500(ai,AUXDATA,ai->flash[nwords] & 0xffff);
8138 }
8139 }
8140 OUT4500(ai,SWS0,0x8000);
8141
8142 return 0;
8143}
8144
8145
8146
8147
8148static int flashrestart(struct airo_info *ai,struct net_device *dev){
8149 int i,status;
8150
8151 ssleep(1);
8152 clear_bit (FLAG_FLASHING, &ai->flags);
8153 if (test_bit(FLAG_MPI, &ai->flags)) {
8154 status = mpi_init_descriptors(ai);
8155 if (status != SUCCESS)
8156 return status;
8157 }
8158 status = setup_card(ai, dev->dev_addr, 1);
8159
8160 if (!test_bit(FLAG_MPI,&ai->flags))
8161 for( i = 0; i < MAX_FIDS; i++ ) {
8162 ai->fids[i] = transmit_allocate
8163 ( ai, AIRO_DEF_MTU, i >= MAX_FIDS / 2 );
8164 }
8165
8166 ssleep(1);
8167 return status;
8168}
8169#endif
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210module_init(airo_init_module);
8211module_exit(airo_cleanup_module);
8212