airo.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:169k
- /*======================================================================
- Aironet driver for 4500 and 4800 series cards
- This code is released under both the GPL version 2 and BSD licenses.
- Either license may be used. The respective licenses are found at
- the end of this file.
- This code was developed by Benjamin Reed <breed@users.sourceforge.net>
- including portions of which come from the Aironet PC4500
- Developer's Reference Manual and used with permission. Copyright
- (C) 1999 Benjamin Reed. All Rights Reserved. Permission to use
- code in the Developer's manual was granted for this driver by
- Aironet. Major code contributions were received from Javier Achirica
- <achirica@users.sourceforge.net> and Jean Tourrilhes <jt@hpl.hp.com>.
- Code was also integrated from the Cisco Aironet driver for Linux.
- ======================================================================*/
- #include <linux/config.h>
- #include <linux/version.h>
- #include <linux/init.h>
- #include <linux/kernel.h>
- #include <linux/module.h>
- #include <linux/proc_fs.h>
- #include <linux/sched.h>
- #include <linux/ptrace.h>
- #include <linux/slab.h>
- #include <linux/string.h>
- #include <linux/timer.h>
- #include <linux/interrupt.h>
- #include <linux/in.h>
- #include <linux/tqueue.h>
- #include <asm/io.h>
- #include <asm/system.h>
- #include <asm/bitops.h>
- #include <linux/netdevice.h>
- #include <linux/etherdevice.h>
- #include <linux/skbuff.h>
- #include <linux/if_arp.h>
- #include <linux/ioport.h>
- #include <linux/config.h>
- #include <linux/pci.h>
- #include <asm/uaccess.h>
- #ifdef CONFIG_PCI
- static struct pci_device_id card_ids[] __devinitdata = {
- { 0x14b9, 1, PCI_ANY_ID, PCI_ANY_ID, },
- { 0x14b9, 0x4500, PCI_ANY_ID, PCI_ANY_ID },
- { 0x14b9, 0x4800, PCI_ANY_ID, PCI_ANY_ID, },
- { 0x14b9, 0x0340, PCI_ANY_ID, PCI_ANY_ID, },
- { 0x14b9, 0x0350, PCI_ANY_ID, PCI_ANY_ID, },
- { 0, }
- };
- MODULE_DEVICE_TABLE(pci, card_ids);
- static int airo_pci_probe(struct pci_dev *, const struct pci_device_id *);
- static void airo_pci_remove(struct pci_dev *);
- static struct pci_driver airo_driver = {
- name: "airo",
- id_table: card_ids,
- probe: airo_pci_probe,
- remove: __devexit_p(airo_pci_remove),
- };
- #endif /* CONFIG_PCI */
- /* Include Wireless Extension definition and check version - Jean II */
- #include <linux/wireless.h>
- #define WIRELESS_SPY // enable iwspy support
- #if WIRELESS_EXT > 12
- #include <net/iw_handler.h> // New driver API
- #endif /* WIRELESS_EXT > 12 */
- #define CISCO_EXT // enable Cisco extensions
- #ifdef CISCO_EXT
- #include <linux/delay.h>
- #endif
- /* Support Cisco MIC feature */
- /* As this feature requires the AES encryption algorithm, it is not included
- in the kernel tree. If you want to enable it, you need to download the
- aes.h, aestab.h and mic.h files from the CVS at
- http://sf.net/projects/airo-linux/ Put the files in the same directory
- as airo.c and compile normally */
- #undef MICSUPPORT
- /* Hack to do some power saving */
- #define POWER_ON_DOWN
- /* As you can see this list is HUGH!
- I really don't know what a lot of these counts are about, but they
- are all here for completeness. If the IGNLABEL macro is put in
- infront of the label, that statistic will not be included in the list
- of statistics in the /proc filesystem */
- #define IGNLABEL 0&(int)
- static char *statsLabels[] = {
- "RxOverrun",
- IGNLABEL "RxPlcpCrcErr",
- IGNLABEL "RxPlcpFormatErr",
- IGNLABEL "RxPlcpLengthErr",
- "RxMacCrcErr",
- "RxMacCrcOk",
- "RxWepErr",
- "RxWepOk",
- "RetryLong",
- "RetryShort",
- "MaxRetries",
- "NoAck",
- "NoCts",
- "RxAck",
- "RxCts",
- "TxAck",
- "TxRts",
- "TxCts",
- "TxMc",
- "TxBc",
- "TxUcFrags",
- "TxUcPackets",
- "TxBeacon",
- "RxBeacon",
- "TxSinColl",
- "TxMulColl",
- "DefersNo",
- "DefersProt",
- "DefersEngy",
- "DupFram",
- "RxFragDisc",
- "TxAged",
- "RxAged",
- "LostSync-MaxRetry",
- "LostSync-MissedBeacons",
- "LostSync-ArlExceeded",
- "LostSync-Deauth",
- "LostSync-Disassoced",
- "LostSync-TsfTiming",
- "HostTxMc",
- "HostTxBc",
- "HostTxUc",
- "HostTxFail",
- "HostRxMc",
- "HostRxBc",
- "HostRxUc",
- "HostRxDiscard",
- IGNLABEL "HmacTxMc",
- IGNLABEL "HmacTxBc",
- IGNLABEL "HmacTxUc",
- IGNLABEL "HmacTxFail",
- IGNLABEL "HmacRxMc",
- IGNLABEL "HmacRxBc",
- IGNLABEL "HmacRxUc",
- IGNLABEL "HmacRxDiscard",
- IGNLABEL "HmacRxAccepted",
- "SsidMismatch",
- "ApMismatch",
- "RatesMismatch",
- "AuthReject",
- "AuthTimeout",
- "AssocReject",
- "AssocTimeout",
- IGNLABEL "ReasonOutsideTable",
- IGNLABEL "ReasonStatus1",
- IGNLABEL "ReasonStatus2",
- IGNLABEL "ReasonStatus3",
- IGNLABEL "ReasonStatus4",
- IGNLABEL "ReasonStatus5",
- IGNLABEL "ReasonStatus6",
- IGNLABEL "ReasonStatus7",
- IGNLABEL "ReasonStatus8",
- IGNLABEL "ReasonStatus9",
- IGNLABEL "ReasonStatus10",
- IGNLABEL "ReasonStatus11",
- IGNLABEL "ReasonStatus12",
- IGNLABEL "ReasonStatus13",
- IGNLABEL "ReasonStatus14",
- IGNLABEL "ReasonStatus15",
- IGNLABEL "ReasonStatus16",
- IGNLABEL "ReasonStatus17",
- IGNLABEL "ReasonStatus18",
- IGNLABEL "ReasonStatus19",
- "RxMan",
- "TxMan",
- "RxRefresh",
- "TxRefresh",
- "RxPoll",
- "TxPoll",
- "HostRetries",
- "LostSync-HostReq",
- "HostTxBytes",
- "HostRxBytes",
- "ElapsedUsec",
- "ElapsedSec",
- "LostSyncBetterAP",
- "PrivacyMismatch",
- "Jammed",
- "DiscRxNotWepped",
- "PhyEleMismatch",
- (char*)-1 };
- #ifndef RUN_AT
- #define RUN_AT(x) (jiffies+(x))
- #endif
- #if LINUX_VERSION_CODE < 0x020500
- static inline struct proc_dir_entry *PDE(const struct inode *inode)
- {
- return inode->u.generic_ip;
- }
- #endif
- /* These variables are for insmod, since it seems that the rates
- can only be set in setup_card. Rates should be a comma separated
- (no spaces) list of rates (up to 8). */
- static int rates[8];
- static int basic_rate;
- static char *ssids[3];
- static int io[4];
- static int irq[4];
- static
- int maxencrypt /* = 0 */; /* The highest rate that the card can encrypt at.
- 0 means no limit. For old cards this was 4 */
- static int auto_wep /* = 0 */; /* If set, it tries to figure out the wep mode */
- static int aux_bap /* = 0 */; /* Checks to see if the aux ports are needed to read
- the bap, needed on some older cards and buses. */
- static int adhoc;
- static int probe = 1;
- static int proc_uid /* = 0 */;
- static int proc_gid /* = 0 */;
- static int airo_perm = 0555;
- static int proc_perm = 0644;
- MODULE_AUTHOR("Benjamin Reed");
- MODULE_DESCRIPTION("Support for Cisco/Aironet 802.11 wireless ethernet
- cards. Direct support for ISA/PCI cards and support
- for PCMCIA when used with airo_cs.");
- MODULE_LICENSE("Dual BSD/GPL");
- MODULE_SUPPORTED_DEVICE("Aironet 4500, 4800 and Cisco 340");
- MODULE_PARM(io,"1-4i");
- MODULE_PARM(irq,"1-4i");
- MODULE_PARM(basic_rate,"i");
- MODULE_PARM(rates,"1-8i");
- MODULE_PARM(ssids,"1-3s");
- MODULE_PARM(auto_wep,"i");
- MODULE_PARM_DESC(auto_wep, "If non-zero, the driver will keep looping through
- the authentication options until an association is made. The value of
- auto_wep is number of the wep keys to check. A value of 2 will try using
- the key at index 0 and index 1.");
- MODULE_PARM(aux_bap,"i");
- MODULE_PARM_DESC(aux_bap, "If non-zero, the driver will switch into a mode
- than seems to work better for older cards with some older buses. Before
- switching it checks that the switch is needed.");
- MODULE_PARM(maxencrypt, "i");
- MODULE_PARM_DESC(maxencrypt, "The maximum speed that the card can do
- encryption. Units are in 512kbs. Zero (default) means there is no limit.
- Older cards used to be limited to 2mbs (4).");
- MODULE_PARM(adhoc, "i");
- MODULE_PARM_DESC(adhoc, "If non-zero, the card will start in adhoc mode.");
- MODULE_PARM(probe, "i");
- MODULE_PARM_DESC(probe, "If zero, the driver won't start the card.");
- MODULE_PARM(proc_uid, "i");
- MODULE_PARM_DESC(proc_uid, "The uid that the /proc files will belong to.");
- MODULE_PARM(proc_gid, "i");
- MODULE_PARM_DESC(proc_gid, "The gid that the /proc files will belong to.");
- MODULE_PARM(airo_perm, "i");
- MODULE_PARM_DESC(airo_perm, "The permission bits of /proc/[driver/]aironet.");
- MODULE_PARM(proc_perm, "i");
- MODULE_PARM_DESC(proc_perm, "The permission bits of the files in /proc");
- /* This is a kind of sloppy hack to get this information to OUT4500 and
- IN4500. I would be extremely interested in the situation where this
- doesn't work though!!! */
- static int do8bitIO = 0;
- /* Return codes */
- #define SUCCESS 0
- #define ERROR -1
- #define NO_PACKET -2
- /* Commands */
- #define NOP2 0x0000
- #define MAC_ENABLE 0x0001
- #define MAC_DISABLE 0x0002
- #define CMD_LOSE_SYNC 0x0003 /* Not sure what this does... */
- #define CMD_SOFTRESET 0x0004
- #define HOSTSLEEP 0x0005
- #define CMD_MAGIC_PKT 0x0006
- #define CMD_SETWAKEMASK 0x0007
- #define CMD_READCFG 0x0008
- #define CMD_SETMODE 0x0009
- #define CMD_ALLOCATETX 0x000a
- #define CMD_TRANSMIT 0x000b
- #define CMD_DEALLOCATETX 0x000c
- #define NOP 0x0010
- #define CMD_WORKAROUND 0x0011
- #define CMD_ACCESS 0x0021
- #define CMD_PCIBAP 0x0022
- #define CMD_PCIAUX 0x0023
- #define CMD_ALLOCBUF 0x0028
- #define CMD_GETTLV 0x0029
- #define CMD_PUTTLV 0x002a
- #define CMD_DELTLV 0x002b
- #define CMD_FINDNEXTTLV 0x002c
- #define CMD_PSPNODES 0x0030
- #define CMD_SETCW 0x0031
- #define CMD_SETPCF 0x0032
- #define CMD_SETPHYREG 0x003e
- #define CMD_TXTEST 0x003f
- #define MAC_ENABLETX 0x0101
- #define CMD_LISTBSS 0x0103
- #define CMD_SAVECFG 0x0108
- #define CMD_ENABLEAUX 0x0111
- #define CMD_WRITERID 0x0121
- #define CMD_USEPSPNODES 0x0130
- #define MAC_ENABLERX 0x0201
- /* Command errors */
- #define ERROR_QUALIF 0x00
- #define ERROR_ILLCMD 0x01
- #define ERROR_ILLFMT 0x02
- #define ERROR_INVFID 0x03
- #define ERROR_INVRID 0x04
- #define ERROR_LARGE 0x05
- #define ERROR_NDISABL 0x06
- #define ERROR_ALLOCBSY 0x07
- #define ERROR_NORD 0x0B
- #define ERROR_NOWR 0x0C
- #define ERROR_INVFIDTX 0x0D
- #define ERROR_TESTACT 0x0E
- #define ERROR_TAGNFND 0x12
- #define ERROR_DECODE 0x20
- #define ERROR_DESCUNAV 0x21
- #define ERROR_BADLEN 0x22
- #define ERROR_MODE 0x80
- #define ERROR_HOP 0x81
- #define ERROR_BINTER 0x82
- #define ERROR_RXMODE 0x83
- #define ERROR_MACADDR 0x84
- #define ERROR_RATES 0x85
- #define ERROR_ORDER 0x86
- #define ERROR_SCAN 0x87
- #define ERROR_AUTH 0x88
- #define ERROR_PSMODE 0x89
- #define ERROR_RTYPE 0x8A
- #define ERROR_DIVER 0x8B
- #define ERROR_SSID 0x8C
- #define ERROR_APLIST 0x8D
- #define ERROR_AUTOWAKE 0x8E
- #define ERROR_LEAP 0x8F
- /* Registers */
- #define COMMAND 0x00
- #define PARAM0 0x02
- #define PARAM1 0x04
- #define PARAM2 0x06
- #define STATUS 0x08
- #define RESP0 0x0a
- #define RESP1 0x0c
- #define RESP2 0x0e
- #define LINKSTAT 0x10
- #define SELECT0 0x18
- #define OFFSET0 0x1c
- #define RXFID 0x20
- #define TXALLOCFID 0x22
- #define TXCOMPLFID 0x24
- #define DATA0 0x36
- #define EVSTAT 0x30
- #define EVINTEN 0x32
- #define EVACK 0x34
- #define SWS0 0x28
- #define SWS1 0x2a
- #define SWS2 0x2c
- #define SWS3 0x2e
- #define AUXPAGE 0x3A
- #define AUXOFF 0x3C
- #define AUXDATA 0x3E
- /* BAP selectors */
- #define BAP0 0 // Used for receiving packets
- #define BAP1 2 // Used for xmiting packets and working with RIDS
- /* Flags */
- #define COMMAND_BUSY 0x8000
- #define BAP_BUSY 0x8000
- #define BAP_ERR 0x4000
- #define BAP_DONE 0x2000
- #define PROMISC 0xffff
- #define NOPROMISC 0x0000
- #define EV_CMD 0x10
- #define EV_CLEARCOMMANDBUSY 0x4000
- #define EV_RX 0x01
- #define EV_TX 0x02
- #define EV_TXEXC 0x04
- #define EV_ALLOC 0x08
- #define EV_LINK 0x80
- #define EV_AWAKE 0x100
- #define EV_UNKNOWN 0x800
- #define EV_MIC 0x1000 /* Message Integrity Check Interrupt */
- #define STATUS_INTS ( EV_AWAKE | EV_LINK | EV_TXEXC | EV_TX | EV_RX | EV_MIC )
- #ifdef CHECK_UNKNOWN_INTS
- #define IGNORE_INTS ( EV_CMD | EV_UNKNOWN)
- #else
- #define IGNORE_INTS (~STATUS_INTS)
- #endif
- /* The RIDs */
- #define RID_CAPABILITIES 0xFF00
- #define RID_APINFO 0xFF01
- #define RID_RADIOINFO 0xFF02
- #define RID_UNKNOWN3 0xFF03
- #define RID_RSSI 0xFF04
- #define RID_CONFIG 0xFF10
- #define RID_SSID 0xFF11
- #define RID_APLIST 0xFF12
- #define RID_DRVNAME 0xFF13
- #define RID_ETHERENCAP 0xFF14
- #define RID_WEP_TEMP 0xFF15
- #define RID_WEP_PERM 0xFF16
- #define RID_MODULATION 0xFF17
- #define RID_OPTIONS 0xFF18
- #define RID_ACTUALCONFIG 0xFF20 /*readonly*/
- #define RID_FACTORYCONFIG 0xFF21
- #define RID_UNKNOWN22 0xFF22
- #define RID_LEAPUSERNAME 0xFF23
- #define RID_LEAPPASSWORD 0xFF24
- #define RID_STATUS 0xFF50
- #define RID_BEACON_HST 0xFF51
- #define RID_BUSY_HST 0xFF52
- #define RID_RETRIES_HST 0xFF53
- #define RID_UNKNOWN54 0xFF54
- #define RID_UNKNOWN55 0xFF55
- #define RID_UNKNOWN56 0xFF56
- #define RID_MIC 0xFF57
- #define RID_STATS16 0xFF60
- #define RID_STATS16DELTA 0xFF61
- #define RID_STATS16DELTACLEAR 0xFF62
- #define RID_STATS 0xFF68
- #define RID_STATSDELTA 0xFF69
- #define RID_STATSDELTACLEAR 0xFF6A
- #define RID_ECHOTEST_RID 0xFF70
- #define RID_ECHOTEST_RESULTS 0xFF71
- #define RID_BSSLISTFIRST 0xFF72
- #define RID_BSSLISTNEXT 0xFF73
- typedef struct {
- u16 cmd;
- u16 parm0;
- u16 parm1;
- u16 parm2;
- } Cmd;
- typedef struct {
- u16 status;
- u16 rsp0;
- u16 rsp1;
- u16 rsp2;
- } Resp;
- /*
- * Rids and endian-ness: The Rids will always be in cpu endian, since
- * this all the patches from the big-endian guys end up doing that.
- * so all rid access should use the read/writeXXXRid routines.
- */
- /* This is redundant for x86 archs, but it seems necessary for ARM */
- #pragma pack(1)
- /* This structure came from an email sent to me from an engineer at
- aironet for inclusion into this driver */
- typedef struct {
- u16 len;
- u16 kindex;
- u8 mac[ETH_ALEN];
- u16 klen;
- u8 key[16];
- } WepKeyRid;
- /* These structures are from the Aironet's PC4500 Developers Manual */
- typedef struct {
- u16 len;
- u8 ssid[32];
- } Ssid;
- typedef struct {
- u16 len;
- Ssid ssids[3];
- } SsidRid;
- typedef struct {
- u16 len;
- u16 modulation;
- #define MOD_DEFAULT 0
- #define MOD_CCK 1
- #define MOD_MOK 2
- } ModulationRid;
- typedef struct {
- u16 len; /* sizeof(ConfigRid) */
- u16 opmode; /* operating mode */
- #define MODE_STA_IBSS 0
- #define MODE_STA_ESS 1
- #define MODE_AP 2
- #define MODE_AP_RPTR 3
- #define MODE_ETHERNET_HOST (0<<8) /* rx payloads converted */
- #define MODE_LLC_HOST (1<<8) /* rx payloads left as is */
- #define MODE_AIRONET_EXTEND (1<<9) /* enable Aironet extenstions */
- #define MODE_AP_INTERFACE (1<<10) /* enable ap interface extensions */
- #define MODE_ANTENNA_ALIGN (1<<11) /* enable antenna alignment */
- #define MODE_ETHER_LLC (1<<12) /* enable ethernet LLC */
- #define MODE_LEAF_NODE (1<<13) /* enable leaf node bridge */
- #define MODE_CF_POLLABLE (1<<14) /* enable CF pollable */
- #define MODE_MIC (1<<15) /* enable MIC */
- u16 rmode; /* receive mode */
- #define RXMODE_BC_MC_ADDR 0
- #define RXMODE_BC_ADDR 1 /* ignore multicasts */
- #define RXMODE_ADDR 2 /* ignore multicast and broadcast */
- #define RXMODE_RFMON 3 /* wireless monitor mode */
- #define RXMODE_RFMON_ANYBSS 4
- #define RXMODE_LANMON 5 /* lan style monitor -- data packets only */
- #define RXMODE_DISABLE_802_3_HEADER (1<<8) /* disables 802.3 header on rx */
- #define RXMODE_NORMALIZED_RSSI (1<<9) /* return normalized RSSI */
- u16 fragThresh;
- u16 rtsThres;
- u8 macAddr[ETH_ALEN];
- u8 rates[8];
- u16 shortRetryLimit;
- u16 longRetryLimit;
- u16 txLifetime; /* in kusec */
- u16 rxLifetime; /* in kusec */
- u16 stationary;
- u16 ordering;
- u16 u16deviceType; /* for overriding device type */
- u16 cfpRate;
- u16 cfpDuration;
- u16 _reserved1[3];
- /*---------- Scanning/Associating ----------*/
- u16 scanMode;
- #define SCANMODE_ACTIVE 0
- #define SCANMODE_PASSIVE 1
- #define SCANMODE_AIROSCAN 2
- u16 probeDelay; /* in kusec */
- u16 probeEnergyTimeout; /* in kusec */
- u16 probeResponseTimeout;
- u16 beaconListenTimeout;
- u16 joinNetTimeout;
- u16 authTimeout;
- u16 authType;
- #define AUTH_OPEN 0x1
- #define AUTH_ENCRYPT 0x101
- #define AUTH_SHAREDKEY 0x102
- #define AUTH_ALLOW_UNENCRYPTED 0x200
- u16 associationTimeout;
- u16 specifiedApTimeout;
- u16 offlineScanInterval;
- u16 offlineScanDuration;
- u16 linkLossDelay;
- u16 maxBeaconLostTime;
- u16 refreshInterval;
- #define DISABLE_REFRESH 0xFFFF
- u16 _reserved1a[1];
- /*---------- Power save operation ----------*/
- u16 powerSaveMode;
- #define POWERSAVE_CAM 0
- #define POWERSAVE_PSP 1
- #define POWERSAVE_PSPCAM 2
- u16 sleepForDtims;
- u16 listenInterval;
- u16 fastListenInterval;
- u16 listenDecay;
- u16 fastListenDelay;
- u16 _reserved2[2];
- /*---------- Ap/Ibss config items ----------*/
- u16 beaconPeriod;
- u16 atimDuration;
- u16 hopPeriod;
- u16 channelSet;
- u16 channel;
- u16 dtimPeriod;
- u16 bridgeDistance;
- u16 radioID;
- /*---------- Radio configuration ----------*/
- u16 radioType;
- #define RADIOTYPE_DEFAULT 0
- #define RADIOTYPE_802_11 1
- #define RADIOTYPE_LEGACY 2
- u8 rxDiversity;
- u8 txDiversity;
- u16 txPower;
- #define TXPOWER_DEFAULT 0
- u16 rssiThreshold;
- #define RSSI_DEFAULT 0
- u16 modulation;
- #define PREAMBLE_AUTO 0
- #define PREAMBLE_LONG 1
- #define PREAMBLE_SHORT 2
- u16 preamble;
- u16 homeProduct;
- u16 radioSpecific;
- /*---------- Aironet Extensions ----------*/
- u8 nodeName[16];
- u16 arlThreshold;
- u16 arlDecay;
- u16 arlDelay;
- u16 _reserved4[1];
- /*---------- Aironet Extensions ----------*/
- u16 magicAction;
- #define MAGIC_ACTION_STSCHG 1
- #define MACIC_ACTION_RESUME 2
- #define MAGIC_IGNORE_MCAST (1<<8)
- #define MAGIC_IGNORE_BCAST (1<<9)
- #define MAGIC_SWITCH_TO_PSP (0<<10)
- #define MAGIC_STAY_IN_CAM (1<<10)
- u16 magicControl;
- u16 autoWake;
- } ConfigRid;
- typedef struct {
- u16 len;
- u8 mac[ETH_ALEN];
- u16 mode;
- u16 errorCode;
- u16 sigQuality;
- u16 SSIDlen;
- char SSID[32];
- char apName[16];
- char bssid[4][ETH_ALEN];
- u16 beaconPeriod;
- u16 dimPeriod;
- u16 atimDuration;
- u16 hopPeriod;
- u16 channelSet;
- u16 channel;
- u16 hopsToBackbone;
- u16 apTotalLoad;
- u16 generatedLoad;
- u16 accumulatedArl;
- u16 signalQuality;
- u16 currentXmitRate;
- u16 apDevExtensions;
- u16 normalizedSignalStrength;
- u16 _reserved1;
- u8 apIP[4];
- u16 _reserved[7];
- } StatusRid;
- typedef struct {
- u16 len;
- u16 spacer;
- u32 vals[100];
- } StatsRid;
- typedef struct {
- u16 len;
- u8 ap[4][ETH_ALEN];
- } APListRid;
- typedef struct {
- u16 len;
- char oui[3];
- char zero;
- u16 prodNum;
- char manName[32];
- char prodName[16];
- char prodVer[8];
- char factoryAddr[ETH_ALEN];
- char aironetAddr[ETH_ALEN];
- u16 radioType;
- u16 country;
- char callid[ETH_ALEN];
- char supportedRates[8];
- char rxDiversity;
- char txDiversity;
- u16 txPowerLevels[8];
- u16 hardVer;
- u16 hardCap;
- u16 tempRange;
- u16 softVer;
- u16 softSubVer;
- u16 interfaceVer;
- u16 softCap;
- u16 bootBlockVer;
- u16 requiredHard;
- u16 extSoftCap;
- } CapabilityRid;
- typedef struct {
- u16 len;
- u16 index; /* First is 0 and 0xffff means end of list */
- #define RADIO_FH 1 /* Frequency hopping radio type */
- #define RADIO_DS 2 /* Direct sequence radio type */
- #define RADIO_TMA 4 /* Proprietary radio used in old cards (2500) */
- u16 radioType;
- u8 bssid[ETH_ALEN]; /* Mac address of the BSS */
- u8 zero;
- u8 ssidLen;
- u8 ssid[32];
- u16 rssi;
- #define CAP_ESS (1<<0)
- #define CAP_IBSS (1<<1)
- #define CAP_PRIVACY (1<<4)
- #define CAP_SHORTHDR (1<<5)
- u16 cap;
- u16 beaconInterval;
- u8 rates[8]; /* Same as rates for config rid */
- struct { /* For frequency hopping only */
- u16 dwell;
- u8 hopSet;
- u8 hopPattern;
- u8 hopIndex;
- u8 fill;
- } fh;
- u16 dsChannel;
- u16 atimWindow;
- } BSSListRid;
- typedef struct {
- u8 rssipct;
- u8 rssidBm;
- } tdsRssiEntry;
- typedef struct {
- u16 len;
- tdsRssiEntry x[256];
- } tdsRssiRid;
- typedef struct {
- u16 len;
- u16 state;
- u16 multicastValid;
- u8 multicast[16];
- u16 unicastValid;
- u8 unicast[16];
- } MICRid;
- typedef struct {
- u16 typelen;
- union {
- u8 snap[8];
- struct {
- u8 dsap;
- u8 ssap;
- u8 control;
- u8 orgcode[3];
- u8 fieldtype[2];
- } llc;
- } u;
- u32 mic;
- u32 seq;
- } MICBuffer;
- typedef struct {
- u8 da[ETH_ALEN];
- u8 sa[ETH_ALEN];
- } etherHead;
- #pragma pack()
- #define TXCTL_TXOK (1<<1) /* report if tx is ok */
- #define TXCTL_TXEX (1<<2) /* report if tx fails */
- #define TXCTL_802_3 (0<<3) /* 802.3 packet */
- #define TXCTL_802_11 (1<<3) /* 802.11 mac packet */
- #define TXCTL_ETHERNET (0<<4) /* payload has ethertype */
- #define TXCTL_LLC (1<<4) /* payload is llc */
- #define TXCTL_RELEASE (0<<5) /* release after completion */
- #define TXCTL_NORELEASE (1<<5) /* on completion returns to host */
- #define BUSY_FID 0x10000
- #ifdef CISCO_EXT
- #define AIROMAGIC 0xa55a
- /* Warning : SIOCDEVPRIVATE may disapear during 2.5.X - Jean II */
- #ifdef SIOCIWFIRSTPRIV
- #ifdef SIOCDEVPRIVATE
- #define AIROOLDIOCTL SIOCDEVPRIVATE
- #define AIROOLDIDIFC AIROOLDIOCTL + 1
- #endif /* SIOCDEVPRIVATE */
- #else /* SIOCIWFIRSTPRIV */
- #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
- #endif /* SIOCIWFIRSTPRIV */
- /* This may be wrong. When using the new SIOCIWFIRSTPRIV range, we probably
- * should use only "GET" ioctls (last bit set to 1). "SET" ioctls are root
- * only and don't return the modified struct ifreq to the application which
- * is usually a problem. - Jean II */
- #define AIROIOCTL SIOCIWFIRSTPRIV
- #define AIROIDIFC AIROIOCTL + 1
- /* Ioctl constants to be used in airo_ioctl.command */
- #define AIROGCAP 0 // Capability rid
- #define AIROGCFG 1 // USED A LOT
- #define AIROGSLIST 2 // System ID list
- #define AIROGVLIST 3 // List of specified AP's
- #define AIROGDRVNAM 4 // NOTUSED
- #define AIROGEHTENC 5 // NOTUSED
- #define AIROGWEPKTMP 6
- #define AIROGWEPKNV 7
- #define AIROGSTAT 8
- #define AIROGSTATSC32 9
- #define AIROGSTATSD32 10
- #define AIROGMICRID 11
- #define AIROGMICSTATS 12
- #define AIROGFLAGS 13
- /* Leave gap of 40 commands after AIROGSTATSD32 for future */
- #define AIROPCAP AIROGSTATSD32 + 40
- #define AIROPVLIST AIROPCAP + 1
- #define AIROPSLIST AIROPVLIST + 1
- #define AIROPCFG AIROPSLIST + 1
- #define AIROPSIDS AIROPCFG + 1
- #define AIROPAPLIST AIROPSIDS + 1
- #define AIROPMACON AIROPAPLIST + 1 /* Enable mac */
- #define AIROPMACOFF AIROPMACON + 1 /* Disable mac */
- #define AIROPSTCLR AIROPMACOFF + 1
- #define AIROPWEPKEY AIROPSTCLR + 1
- #define AIROPWEPKEYNV AIROPWEPKEY + 1
- #define AIROPLEAPPWD AIROPWEPKEYNV + 1
- #define AIROPLEAPUSR AIROPLEAPPWD + 1
- /* Flash codes */
- #define AIROFLSHRST AIROPWEPKEYNV + 40
- #define AIROFLSHGCHR AIROFLSHRST + 1
- #define AIROFLSHSTFL AIROFLSHGCHR + 1
- #define AIROFLSHPCHR AIROFLSHSTFL + 1
- #define AIROFLPUTBUF AIROFLSHPCHR + 1
- #define AIRORESTART AIROFLPUTBUF + 1
- #define FLASHSIZE 32768
- typedef struct aironet_ioctl {
- unsigned short command; // What to do
- unsigned short len; // Len of data
- unsigned char *data; // d-data
- } aironet_ioctl;
- #endif /* CISCO_EXT */
- #define NUM_MODULES 2
- #define MIC_MSGLEN_MAX 2400
- #define EMMH32_MSGLEN_MAX MIC_MSGLEN_MAX
- typedef struct {
- u32 size; // size
- u8 enabled; // MIC enabled or not
- u32 rxSuccess; // successful packets received
- u32 rxIncorrectMIC; // pkts dropped due to incorrect MIC comparison
- u32 rxNotMICed; // pkts dropped due to not being MIC'd
- u32 rxMICPlummed; // pkts dropped due to not having a MIC plummed
- u32 rxWrongSequence; // pkts dropped due to sequence number violation
- u32 reserve[32];
- } mic_statistics;
- typedef struct {
- u32 coeff[((EMMH32_MSGLEN_MAX)+3)>>2];
- u64 accum; // accumulated mic, reduced to u32 in final()
- int position; // current position (byte offset) in message
- union {
- u8 d8[4];
- u32 d32;
- } part; // saves partial message word across update() calls
- } emmh32_context;
- typedef struct {
- emmh32_context seed; // Context - the seed
- u32 rx; // Received sequence number
- u32 tx; // Tx sequence number
- u32 window; // Start of window
- u8 valid; // Flag to say if context is valid or not
- u8 key[16];
- } miccntx;
- typedef struct {
- miccntx mCtx; // Multicast context
- miccntx uCtx; // Unicast context
- } mic_module;
- #ifdef WIRELESS_EXT
- // Frequency list (map channels to frequencies)
- const long frequency_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
- 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
- // A few details needed for WEP (Wireless Equivalent Privacy)
- #define MAX_KEY_SIZE 13 // 128 (?) bits
- #define MIN_KEY_SIZE 5 // 40 bits RC4 - WEP
- typedef struct wep_key_t {
- u16 len;
- u8 key[16]; /* 40-bit and 104-bit keys */
- } wep_key_t;
- /* Backward compatibility */
- #ifndef IW_ENCODE_NOKEY
- #define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */
- #define IW_ENCODE_MODE (IW_ENCODE_DISABLED | IW_ENCODE_RESTRICTED | IW_ENCODE_OPEN)
- #endif /* IW_ENCODE_NOKEY */
- #if WIRELESS_EXT > 12
- /* List of Wireless Handlers (new API) */
- static const struct iw_handler_def airo_handler_def;
- #else /* WIRELESS_EXT > 12 */
- /* More Wireless Extensions backward compatibility */
- /* Part of iw_handler prototype we need (apart that we don't need it) */
- struct iw_request_info {};
- #endif /* WIRELESS_EXT > 12 */
- #endif /* WIRELESS_EXT */
- static const char version[] = "airo.c 0.6 (Ben Reed & Javier Achirica)";
- struct airo_info;
- static int get_dec_u16( char *buffer, int *start, int limit );
- static void OUT4500( struct airo_info *, u16 register, u16 value );
- static unsigned short IN4500( struct airo_info *, u16 register );
- static u16 setup_card(struct airo_info*, u8 *mac);
- static int enable_MAC( struct airo_info *ai, Resp *rsp );
- static void disable_MAC(struct airo_info *ai);
- static void enable_interrupts(struct airo_info*);
- static void disable_interrupts(struct airo_info*);
- static u16 issuecommand(struct airo_info*, Cmd *pCmd, Resp *pRsp);
- static u16 sendcommand(struct airo_info *ai, Cmd *pCmd);
- static void completecommand(struct airo_info *ai, Resp *pRsp);
- static int bap_setup(struct airo_info*, u16 rid, u16 offset, int whichbap);
- static int aux_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen,
- int whichbap);
- static int fast_bap_read(struct airo_info*, u16 *pu16Dst, int bytelen,
- int whichbap);
- static int bap_write(struct airo_info*, const u16 *pu16Src, int bytelen,
- int whichbap);
- static int PC4500_accessrid(struct airo_info*, u16 rid, u16 accmd);
- static int PC4500_readrid(struct airo_info*, u16 rid, void *pBuf, int len);
- static int PC4500_writerid(struct airo_info*, u16 rid, const void
- *pBuf, int len);
- static int do_writerid( struct airo_info*, u16 rid, const void *rid_data,
- int len );
- static u16 transmit_allocate(struct airo_info*, int lenPayload, int raw);
- static int transmit_802_3_packet(struct airo_info*, int len, char *pPacket);
- static int transmit_802_11_packet(struct airo_info*, int len, char *pPacket);
- static void airo_interrupt( int irq, void* dev_id, struct pt_regs
- *regs);
- static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
- #ifdef WIRELESS_EXT
- struct iw_statistics *airo_get_wireless_stats (struct net_device *dev);
- #endif /* WIRELESS_EXT */
- #ifdef CISCO_EXT
- static int readrids(struct net_device *dev, aironet_ioctl *comp);
- static int writerids(struct net_device *dev, aironet_ioctl *comp);
- int flashcard(struct net_device *dev, aironet_ioctl *comp);
- #endif /* CISCO_EXT */
- #ifdef MICSUPPORT
- static void micinit(struct airo_info *ai, MICRid *micr);
- static void micsetup(struct airo_info *ai);
- static int encapsulate(struct airo_info *ai, etherHead *pPacket, MICBuffer *buffer, int len);
- static int decapsulate(struct airo_info *ai, MICBuffer *mic, etherHead *pPacket, u16 payLen);
- #endif
- struct airo_info {
- struct net_device_stats stats;
- int open;
- struct net_device *dev;
- /* Note, we can have MAX_FIDS outstanding. FIDs are 16-bits, so we
- use the high bit to mark wether it is in use. */
- #define MAX_FIDS 6
- int fids[MAX_FIDS];
- int registered;
- ConfigRid config;
- int need_commit; // Need to set config
- char keyindex; // Used with auto wep
- char defindex; // Used with auto wep
- struct timer_list timer;
- struct proc_dir_entry *proc_entry;
- struct airo_info *next;
- spinlock_t aux_lock;
- unsigned long flags;
- #define FLAG_PROMISC IFF_PROMISC /* 0x100 - include/linux/if.h */
- #define FLAG_RADIO_OFF 0x02 /* User disabling of MAC */
- #define FLAG_RADIO_DOWN 0x08 /* ifup/ifdown disabling of MAC */
- #define FLAG_LOCKED 2 /* 0x04 - use as a bit offset */
- #define FLAG_FLASHING 0x10
- #define FLAG_ADHOC 0x01 /* Needed by MIC */
- #define FLAG_MIC_CAPABLE 0x20
- #define FLAG_UPDATE_MULTI 0x40
- #define FLAG_UPDATE_UNI 0x80
- #define FLAG_802_11 0x200
- int (*bap_read)(struct airo_info*, u16 *pu16Dst, int bytelen,
- int whichbap);
- unsigned short *flash;
- tdsRssiEntry *rssi;
- struct semaphore sem;
- struct task_struct *task;
- struct tq_struct promisc_task;
- struct {
- struct sk_buff *skb;
- int fid;
- struct tq_struct task;
- } xmit, xmit11;
- struct net_device *wifidev;
- #ifdef WIRELESS_EXT
- struct iw_statistics wstats; // wireless stats
- unsigned long scan_timestamp; /* Time started to scan */
- struct tq_struct event_task;
- #ifdef WIRELESS_SPY
- int spy_number;
- u_char spy_address[IW_MAX_SPY][ETH_ALEN];
- struct iw_quality spy_stat[IW_MAX_SPY];
- #endif /* WIRELESS_SPY */
- #endif /* WIRELESS_EXT */
- /* MIC stuff */
- mic_module mod[2];
- mic_statistics micstats;
- struct tq_struct mic_task;
- };
- static inline int bap_read(struct airo_info *ai, u16 *pu16Dst, int bytelen,
- int whichbap) {
- return ai->bap_read(ai, pu16Dst, bytelen, whichbap);
- }
- static int setup_proc_entry( struct net_device *dev,
- struct airo_info *apriv );
- static int takedown_proc_entry( struct net_device *dev,
- struct airo_info *apriv );
- #ifdef MICSUPPORT
- #include "mic.h"
- #endif
- static int readBSSListRid(struct airo_info *ai, int first,
- BSSListRid *list) {
- int rc;
- Cmd cmd;
- Resp rsp;
- if (first == 1) {
- memset(&cmd, 0, sizeof(cmd));
- cmd.cmd=CMD_LISTBSS;
- if (down_interruptible(&ai->sem))
- return -ERESTARTSYS;
- issuecommand(ai, &cmd, &rsp);
- up(&ai->sem);
- /* Let the command take effect */
- set_current_state (TASK_INTERRUPTIBLE);
- ai->task = current;
- schedule_timeout (3*HZ);
- ai->task = NULL;
- }
- rc = PC4500_readrid(ai, first ? RID_BSSLISTFIRST : RID_BSSLISTNEXT,
- list, sizeof(*list));
- list->len = le16_to_cpu(list->len);
- list->index = le16_to_cpu(list->index);
- list->radioType = le16_to_cpu(list->radioType);
- list->cap = le16_to_cpu(list->cap);
- list->beaconInterval = le16_to_cpu(list->beaconInterval);
- list->fh.dwell = le16_to_cpu(list->fh.dwell);
- list->dsChannel = le16_to_cpu(list->dsChannel);
- list->atimWindow = le16_to_cpu(list->atimWindow);
- return rc;
- }
- static int readWepKeyRid(struct airo_info*ai, WepKeyRid *wkr, int temp) {
- int rc = PC4500_readrid(ai, temp ? RID_WEP_TEMP : RID_WEP_PERM,
- wkr, sizeof(*wkr));
- wkr->len = le16_to_cpu(wkr->len);
- wkr->kindex = le16_to_cpu(wkr->kindex);
- wkr->klen = le16_to_cpu(wkr->klen);
- return rc;
- }
- /* In the writeXXXRid routines we copy the rids so that we don't screwup
- * the originals when we endian them... */
- static int writeWepKeyRid(struct airo_info*ai, WepKeyRid *pwkr, int perm) {
- int rc;
- WepKeyRid wkr = *pwkr;
- wkr.len = cpu_to_le16(wkr.len);
- wkr.kindex = cpu_to_le16(wkr.kindex);
- wkr.klen = cpu_to_le16(wkr.klen);
- rc = PC4500_writerid(ai, RID_WEP_TEMP, &wkr, sizeof(wkr));
- if (rc!=SUCCESS) printk(KERN_ERR "airo: WEP_TEMP set %xn", rc);
- if (perm) {
- rc = PC4500_writerid(ai, RID_WEP_PERM, &wkr, sizeof(wkr));
- if (rc!=SUCCESS) {
- printk(KERN_ERR "airo: WEP_PERM set %xn", rc);
- }
- }
- return rc;
- }
- static int readSsidRid(struct airo_info*ai, SsidRid *ssidr) {
- int i;
- int rc = PC4500_readrid(ai, RID_SSID, ssidr, sizeof(*ssidr));
- ssidr->len = le16_to_cpu(ssidr->len);
- for(i = 0; i < 3; i++) {
- ssidr->ssids[i].len = le16_to_cpu(ssidr->ssids[i].len);
- }
- return rc;
- }
- static int writeSsidRid(struct airo_info*ai, SsidRid *pssidr) {
- int rc;
- int i;
- SsidRid ssidr = *pssidr;
- ssidr.len = cpu_to_le16(ssidr.len);
- for(i = 0; i < 3; i++) {
- ssidr.ssids[i].len = cpu_to_le16(ssidr.ssids[i].len);
- }
- rc = PC4500_writerid(ai, RID_SSID, &ssidr, sizeof(ssidr));
- return rc;
- }
- static int readConfigRid(struct airo_info*ai) {
- int rc;
- u16 *s;
- ConfigRid cfg;
- if (ai->config.len)
- return SUCCESS;
- rc = PC4500_readrid(ai, RID_ACTUALCONFIG, &cfg, sizeof(cfg));
- if (rc != SUCCESS)
- return rc;
- for(s = &cfg.len; s <= &cfg.rtsThres; s++) *s = le16_to_cpu(*s);
- for(s = &cfg.shortRetryLimit; s <= &cfg.radioType; s++)
- *s = le16_to_cpu(*s);
- for(s = &cfg.txPower; s <= &cfg.radioSpecific; s++)
- *s = le16_to_cpu(*s);
- for(s = &cfg.arlThreshold; s <= &cfg.autoWake; s++)
- *s = le16_to_cpu(*s);
- ai->config = cfg;
- return SUCCESS;
- }
- static inline void checkThrottle(struct airo_info *ai) {
- int i;
- /* Old hardware had a limit on encryption speed */
- if (ai->config.authType != AUTH_OPEN && maxencrypt) {
- for(i=0; i<8; i++) {
- if (ai->config.rates[i] > maxencrypt) {
- ai->config.rates[i] = 0;
- }
- }
- }
- }
- static int writeConfigRid(struct airo_info*ai) {
- u16 *s;
- ConfigRid cfgr;
- if (!ai->need_commit)
- return SUCCESS;
- ai->need_commit = 0;
- checkThrottle(ai);
- if ((cfgr.opmode & 0xFF) == MODE_STA_IBSS)
- ai->flags |= FLAG_ADHOC;
- else
- ai->flags &= ~FLAG_ADHOC;
- cfgr = ai->config;
- for(s = &cfgr.len; s <= &cfgr.rtsThres; s++) *s = cpu_to_le16(*s);
- for(s = &cfgr.shortRetryLimit; s <= &cfgr.radioType; s++)
- *s = cpu_to_le16(*s);
- for(s = &cfgr.txPower; s <= &cfgr.radioSpecific; s++)
- *s = cpu_to_le16(*s);
- for(s = &cfgr.arlThreshold; s <= &cfgr.autoWake; s++)
- *s = cpu_to_le16(*s);
- return PC4500_writerid( ai, RID_CONFIG, &cfgr, sizeof(cfgr));
- }
- static int readStatusRid(struct airo_info*ai, StatusRid *statr) {
- int rc = PC4500_readrid(ai, RID_STATUS, statr, sizeof(*statr));
- u16 *s;
- statr->len = le16_to_cpu(statr->len);
- for(s = &statr->mode; s <= &statr->SSIDlen; s++) *s = le16_to_cpu(*s);
- for(s = &statr->beaconPeriod; s <= &statr->_reserved[9]; s++)
- *s = le16_to_cpu(*s);
- return rc;
- }
- static int readAPListRid(struct airo_info*ai, APListRid *aplr) {
- int rc = PC4500_readrid(ai, RID_APLIST, aplr, sizeof(*aplr));
- aplr->len = le16_to_cpu(aplr->len);
- return rc;
- }
- static int writeAPListRid(struct airo_info*ai, APListRid *aplr) {
- int rc;
- aplr->len = cpu_to_le16(aplr->len);
- rc = PC4500_writerid(ai, RID_APLIST, aplr, sizeof(*aplr));
- return rc;
- }
- static int readCapabilityRid(struct airo_info*ai, CapabilityRid *capr) {
- int rc = PC4500_readrid(ai, RID_CAPABILITIES, capr, sizeof(*capr));
- u16 *s;
- capr->len = le16_to_cpu(capr->len);
- capr->prodNum = le16_to_cpu(capr->prodNum);
- capr->radioType = le16_to_cpu(capr->radioType);
- capr->country = le16_to_cpu(capr->country);
- for(s = &capr->txPowerLevels[0]; s <= &capr->requiredHard; s++)
- *s = le16_to_cpu(*s);
- return rc;
- }
- static int readStatsRid(struct airo_info*ai, StatsRid *sr, int rid) {
- int rc = PC4500_readrid(ai, rid, sr, sizeof(*sr));
- u32 *i;
- sr->len = le16_to_cpu(sr->len);
- for(i = &sr->vals[0]; i <= &sr->vals[99]; i++) *i = le32_to_cpu(*i);
- return rc;
- }
- static int airo_open(struct net_device *dev) {
- struct airo_info *info = dev->priv;
- Resp rsp;
- if (info->flags & FLAG_FLASHING)
- return -EIO;
- /* Make sure the card is configured.
- * Wireless Extensions may postpone config changes until the card
- * is open (to pipeline changes and speed-up card setup). If
- * those changes are not yet commited, do it now - Jean II */
- if(info->need_commit) {
- disable_MAC(info);
- writeConfigRid(info);
- }
- if (info->wifidev != dev) {
- /* Power on the MAC controller (which may have been disabled) */
- info->flags &= ~FLAG_RADIO_DOWN;
- enable_interrupts(info);
- }
- enable_MAC(info, &rsp);
- netif_start_queue(dev);
- return 0;
- }
- static void get_tx_error(struct airo_info *ai, u32 fid)
- {
- u16 status;
- if (bap_setup(ai, ai->fids[fid] & 0xffff, 4, BAP0) == SUCCESS) {
- bap_read(ai, &status, 2, BAP0);
- if (le16_to_cpu(status) & 2) /* Too many retries */
- ai->stats.tx_aborted_errors++;
- if (le16_to_cpu(status) & 4) /* Transmit lifetime exceeded */
- ai->stats.tx_heartbeat_errors++;
- if (le16_to_cpu(status) & 8) /* Aid fail */
- { }
- if (le16_to_cpu(status) & 0x10) /* MAC disabled */
- ai->stats.tx_carrier_errors++;
- if (le16_to_cpu(status) & 0x20) /* Association lost */
- { }
- #if WIRELESS_EXT > 13
- /* We produce a TXDROP event only for retry or lifetime
- * exceeded, because that's the only status that really mean
- * that this particular node went away.
- * Other errors means that *we* screwed up. - Jean II */
- if ((le16_to_cpu(status) & 2) ||
- (le16_to_cpu(status) & 4)) {
- union iwreq_data wrqu;
- char junk[0x18];
- /* Faster to skip over useless data than to do
- * another bap_setup(). We are at offset 0x6 and
- * need to go to 0x18 and read 6 bytes - Jean II */
- bap_read(ai, (u16 *) junk, 0x18, BAP0);
- /* Copy 802.11 dest address.
- * We use the 802.11 header because the frame may
- * not be 802.3 or may be mangled...
- * In Ad-Hoc mode, it will be the node address.
- * In managed mode, it will be most likely the AP addr
- * User space will figure out how to convert it to
- * whatever it needs (IP address or else).
- * - Jean II */
- memcpy(wrqu.addr.sa_data, junk + 0x12, ETH_ALEN);
- wrqu.addr.sa_family = ARPHRD_ETHER;
- /* Send event to user space */
- wireless_send_event(ai->dev, IWEVTXDROP, &wrqu, NULL);
- }
- #endif /* WIRELESS_EXT > 13 */
- }
- }
- static void airo_do_xmit(struct net_device *dev) {
- u16 status;
- int i;
- struct airo_info *priv = dev->priv;
- struct sk_buff *skb = priv->xmit.skb;
- int fid = priv->xmit.fid;
- u32 *fids = priv->fids;
- if (down_trylock(&priv->sem) != 0) {
- netif_stop_queue(dev);
- priv->xmit.task.routine = (void (*)(void *))airo_do_xmit;
- priv->xmit.task.data = (void *)dev;
- schedule_task(&priv->xmit.task);
- return;
- }
- status = transmit_802_3_packet (priv, fids[fid], skb->data);
- up(&priv->sem);
- i = 0;
- if ( status == SUCCESS ) {
- dev->trans_start = jiffies;
- for (; i < MAX_FIDS / 2 && (priv->fids[i] & 0xffff0000); i++);
- } else {
- priv->fids[fid] &= 0xffff;
- priv->stats.tx_window_errors++;
- }
- if (i < MAX_FIDS / 2)
- netif_wake_queue(dev);
- else
- netif_stop_queue(dev);
- dev_kfree_skb(skb);
- }
- static int airo_start_xmit(struct sk_buff *skb, struct net_device *dev) {
- s16 len;
- int i;
- struct airo_info *priv = dev->priv;
- u32 *fids = priv->fids;
- if ( skb == NULL ) {
- printk( KERN_ERR "airo: skb == NULL!!!n" );
- return 0;
- }
- /* Find a vacant FID */
- for( i = 0; i < MAX_FIDS / 2 && (fids[i] & 0xffff0000); i++ );
- if ( i == MAX_FIDS / 2 ) {
- priv->stats.tx_fifo_errors++;
- dev_kfree_skb(skb);
- } else {
- /* check min length*/
- len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
- /* Mark fid as used & save length for later */
- fids[i] |= (len << 16);
- priv->xmit.skb = skb;
- priv->xmit.fid = i;
- airo_do_xmit(dev);
- }
- return 0;
- }
- static void airo_do_xmit11(struct net_device *dev) {
- u16 status;
- int i;
- struct airo_info *priv = dev->priv;
- struct sk_buff *skb = priv->xmit11.skb;
- int fid = priv->xmit11.fid;
- u32 *fids = priv->fids;
- if (down_trylock(&priv->sem) != 0) {
- netif_stop_queue(dev);
- priv->xmit11.task.routine = (void (*)(void *))airo_do_xmit11;
- priv->xmit11.task.data = (void *)dev;
- schedule_task(&priv->xmit11.task);
- return;
- }
- status = transmit_802_11_packet (priv, fids[fid], skb->data);
- up(&priv->sem);
- i = MAX_FIDS / 2;
- if ( status == SUCCESS ) {
- dev->trans_start = jiffies;
- for (; i < MAX_FIDS && (priv->fids[i] & 0xffff0000); i++);
- } else {
- priv->fids[fid] &= 0xffff;
- priv->stats.tx_window_errors++;
- }
- if (i < MAX_FIDS)
- netif_wake_queue(dev);
- else
- netif_stop_queue(dev);
- dev_kfree_skb(skb);
- }
- static int airo_start_xmit11(struct sk_buff *skb, struct net_device *dev) {
- s16 len;
- int i;
- struct airo_info *priv = dev->priv;
- u32 *fids = priv->fids;
- if ( skb == NULL ) {
- printk( KERN_ERR "airo: skb == NULL!!!n" );
- return 0;
- }
- /* Find a vacant FID */
- for( i = MAX_FIDS / 2; i < MAX_FIDS && (fids[i] & 0xffff0000); i++ );
- if ( i == MAX_FIDS ) {
- priv->stats.tx_fifo_errors++;
- dev_kfree_skb(skb);
- } else {
- /* check min length*/
- len = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
- /* Mark fid as used & save length for later */
- fids[i] |= (len << 16);
- priv->xmit11.skb = skb;
- priv->xmit11.fid = i;
- airo_do_xmit11(dev);
- }
- return 0;
- }
- struct net_device_stats *airo_get_stats(struct net_device *dev)
- {
- struct airo_info *local = dev->priv;
- StatsRid stats_rid;
- u32 *vals = stats_rid.vals;
- /* Get stats out of the card */
- readStatsRid(local, &stats_rid, RID_STATS);
- local->stats.rx_packets = vals[43] + vals[44] + vals[45];
- local->stats.tx_packets = vals[39] + vals[40] + vals[41];
- local->stats.rx_bytes = vals[92];
- local->stats.tx_bytes = vals[91];
- local->stats.rx_errors = vals[0] + vals[2] + vals[3] + vals[4];
- local->stats.tx_errors = vals[42] + local->stats.tx_fifo_errors;
- local->stats.multicast = vals[43];
- local->stats.collisions = vals[89];
- /* detailed rx_errors: */
- local->stats.rx_length_errors = vals[3];
- local->stats.rx_crc_errors = vals[4];
- local->stats.rx_frame_errors = vals[2];
- local->stats.rx_fifo_errors = vals[0];
- return &local->stats;
- }
- static void airo_end_promisc(struct airo_info *ai) {
- Resp rsp;
- if ((IN4500(ai, EVSTAT) & EV_CMD) != 0) {
- completecommand(ai, &rsp);
- up(&ai->sem);
- } else {
- ai->promisc_task.routine = (void (*)(void *))airo_end_promisc;
- ai->promisc_task.data = (void *)ai;
- schedule_task(&ai->promisc_task);
- }
- }
- static void airo_set_promisc(struct airo_info *ai) {
- Cmd cmd;
- if (down_trylock(&ai->sem) == 0) {
- memset(&cmd, 0, sizeof(cmd));
- cmd.cmd=CMD_SETMODE;
- cmd.parm0=(ai->flags&IFF_PROMISC) ? PROMISC : NOPROMISC;
- sendcommand(ai, &cmd);
- airo_end_promisc(ai);
- } else {
- ai->promisc_task.routine = (void (*)(void *))airo_set_promisc;
- ai->promisc_task.data = (void *)ai;
- schedule_task(&ai->promisc_task);
- }
- }
- static void airo_set_multicast_list(struct net_device *dev) {
- struct airo_info *ai = dev->priv;
- if ((dev->flags ^ ai->flags) & IFF_PROMISC) {
- ai->flags ^= IFF_PROMISC;
- airo_set_promisc(ai);
- }
- if ((dev->flags&IFF_ALLMULTI)||dev->mc_count>0) {
- /* Turn on multicast. (Should be already setup...) */
- }
- }
- static int airo_set_mac_address(struct net_device *dev, void *p)
- {
- struct airo_info *ai = dev->priv;
- struct sockaddr *addr = p;
- Resp rsp;
- memcpy (ai->config.macAddr, addr->sa_data, dev->addr_len);
- ai->need_commit = 1;
- disable_MAC(ai);
- writeConfigRid (ai);
- enable_MAC(ai, &rsp);
- memcpy (ai->dev->dev_addr, addr->sa_data, dev->addr_len);
- if (ai->wifidev)
- memcpy (ai->wifidev->dev_addr, addr->sa_data, dev->addr_len);
- return 0;
- }
- static int airo_change_mtu(struct net_device *dev, int new_mtu)
- {
- if ((new_mtu < 68) || (new_mtu > 2400))
- return -EINVAL;
- dev->mtu = new_mtu;
- return 0;
- }
- static int airo_close(struct net_device *dev) {
- struct airo_info *ai = dev->priv;
- netif_stop_queue(dev);
- if (ai->wifidev != dev) {
- #ifdef POWER_ON_DOWN
- /* Shut power to the card. The idea is that the user can save
- * power when he doesn't need the card with "ifconfig down".
- * That's the method that is most friendly towards the network
- * stack (i.e. the network stack won't try to broadcast
- * anything on the interface and routes are gone. Jean II */
- ai->flags |= FLAG_RADIO_DOWN;
- disable_MAC(ai);
- #endif
- disable_interrupts( ai );
- }
- return 0;
- }
- static void del_airo_dev( struct net_device *dev );
- void stop_airo_card( struct net_device *dev, int freeres )
- {
- struct airo_info *ai = dev->priv;
- flush_scheduled_tasks();
- if (ai->flash)
- kfree(ai->flash);
- if (ai->rssi)
- kfree(ai->rssi);
- takedown_proc_entry( dev, ai );
- if (ai->registered) {
- unregister_netdev( dev );
- if (ai->wifidev) {
- unregister_netdev(ai->wifidev);
- kfree(ai->wifidev);
- ai->wifidev = 0;
- }
- ai->registered = 0;
- }
- disable_interrupts(ai);
- free_irq( dev->irq, dev );
- if (auto_wep) del_timer_sync(&ai->timer);
- if (freeres) {
- /* PCMCIA frees this stuff, so only for PCI and ISA */
- release_region( dev->base_addr, 64 );
- }
- del_airo_dev( dev );
- kfree( dev );
- }
- EXPORT_SYMBOL(stop_airo_card);
- static int add_airo_dev( struct net_device *dev );
- int wll_header_parse(struct sk_buff *skb, unsigned char *haddr)
- {
- memcpy(haddr, skb->mac.raw + 10, ETH_ALEN);
- return ETH_ALEN;
- }
- static void wifi_setup(struct net_device *dev, struct net_device *ethdev)
- {
- struct airo_info *ai = ethdev->priv;
- dev->priv = ai;
- dev->hard_header = 0;
- dev->rebuild_header = 0;
- dev->hard_header_cache = 0;
- dev->header_cache_update= 0;
- dev->hard_header_parse = wll_header_parse;
- dev->hard_start_xmit = &airo_start_xmit11;
- dev->get_stats = &airo_get_stats;
- dev->set_mac_address = &airo_set_mac_address;
- dev->do_ioctl = &airo_ioctl;
- #ifdef WIRELESS_EXT
- dev->get_wireless_stats = airo_get_wireless_stats;
- #if WIRELESS_EXT > 12
- dev->wireless_handlers = (struct iw_handler_def *)&airo_handler_def;
- #endif /* WIRELESS_EXT > 12 */
- #endif /* WIRELESS_EXT */
- dev->change_mtu = &airo_change_mtu;
- dev->open = &airo_open;
- dev->stop = &airo_close;
- dev->irq = ethdev->irq;
- dev->base_addr = ethdev->base_addr;
- dev->type = ARPHRD_IEEE80211;
- dev->hard_header_len = ETH_HLEN;
- dev->mtu = 2312;
- dev->addr_len = ETH_ALEN;
- memcpy(dev->dev_addr, ethdev->dev_addr, dev->addr_len);
- dev->tx_queue_len = 100;
- memset(dev->broadcast,0xFF, ETH_ALEN);
- dev->flags = IFF_BROADCAST|IFF_MULTICAST;
- }
- static struct net_device *init_wifidev(struct airo_info *ai,
- struct net_device *ethdev)
- {
- int err;
- struct net_device *dev = (struct net_device*)kmalloc(sizeof *dev,GFP_KERNEL);
- if (!dev) return 0;
- memset(dev, 0, sizeof(*dev));
- strcpy(dev->name, "wifi%d");
- dev->priv = ai;
- wifi_setup(dev, ethdev);
- err = register_netdev(dev);
- if (err<0) {
- kfree(dev);
- return 0;
- }
- return dev;
- }
- struct net_device *init_airo_card( unsigned short irq, int port, int is_pcmcia )
- {
- struct net_device *dev;
- struct airo_info *ai;
- int i, rc;
- /* Create the network device object. */
- dev = alloc_etherdev(sizeof(*ai));
- if (!dev) {
- printk(KERN_ERR "airo: Couldn't alloc_etherdevn");
- return NULL;
- }
- if (dev_alloc_name(dev, dev->name) < 0) {
- printk(KERN_ERR "airo: Couldn't get name!n");
- goto err_out_free;
- }
- ai = dev->priv;
- ai->wifidev = 0;
- ai->registered = 0;
- ai->dev = dev;
- ai->aux_lock = SPIN_LOCK_UNLOCKED;
- sema_init(&ai->sem, 1);
- ai->need_commit = 0;
- ai->config.len = 0;
- rc = add_airo_dev( dev );
- if (rc)
- goto err_out_free;
- /* The Airo-specific entries in the device structure. */
- dev->hard_start_xmit = &airo_start_xmit;
- dev->get_stats = &airo_get_stats;
- dev->set_multicast_list = &airo_set_multicast_list;
- dev->set_mac_address = &airo_set_mac_address;
- dev->do_ioctl = &airo_ioctl;
- #ifdef WIRELESS_EXT
- dev->get_wireless_stats = airo_get_wireless_stats;
- #if WIRELESS_EXT > 12
- dev->wireless_handlers = (struct iw_handler_def *)&airo_handler_def;
- #endif /* WIRELESS_EXT > 12 */
- #endif /* WIRELESS_EXT */
- dev->change_mtu = &airo_change_mtu;
- dev->open = &airo_open;
- dev->stop = &airo_close;
- dev->irq = irq;
- dev->base_addr = port;
- rc = request_irq( dev->irq, airo_interrupt, SA_SHIRQ, dev->name, dev );
- if (rc) {
- printk(KERN_ERR "airo: register interrupt %d failed, rc %dn", irq, rc );
- goto err_out_unlink;
- }
- if (!is_pcmcia) {
- if (!request_region( dev->base_addr, 64, dev->name )) {
- rc = -EBUSY;
- goto err_out_irq;
- }
- }
- if (probe) {
- if ( setup_card( ai, dev->dev_addr ) != SUCCESS ) {
- printk( KERN_ERR "airo: MAC could not be enabledn" );
- rc = -EIO;
- goto err_out_res;
- }
- } else {
- ai->bap_read = fast_bap_read;
- ai->flags |= FLAG_FLASHING;
- }
- rc = register_netdev(dev);
- if (rc)
- goto err_out_res;
- ai->wifidev = init_wifidev(ai, dev);
- ai->registered = 1;
- printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%xn",
- dev->name,
- dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
- dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5] );
- /* Allocate the transmit buffers */
- if (probe)
- for( i = 0; i < MAX_FIDS; i++ )
- ai->fids[i] = transmit_allocate(ai,2312,i>=MAX_FIDS/2);
- setup_proc_entry( dev, dev->priv ); /* XXX check for failure */
- netif_start_queue(dev);
- SET_MODULE_OWNER(dev);
- return dev;
- err_out_res:
- if (!is_pcmcia)
- release_region( dev->base_addr, 64 );
- err_out_irq:
- free_irq(dev->irq, dev);
- err_out_unlink:
- del_airo_dev(dev);
- err_out_free:
- kfree(dev);
- return NULL;
- }
- EXPORT_SYMBOL(init_airo_card);
- static int waitbusy (struct airo_info *ai) {
- int delay = 0;
- while ((IN4500 (ai, COMMAND) & COMMAND_BUSY) & (delay < 10000)) {
- udelay (10);
- if (++delay % 20)
- OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
- }
- return delay < 10000;
- }
- int reset_airo_card( struct net_device *dev ) {
- int i;
- struct airo_info *ai = dev->priv;
- waitbusy (ai);
- OUT4500(ai,COMMAND,CMD_SOFTRESET);
- set_current_state (TASK_UNINTERRUPTIBLE);
- schedule_timeout (HZ/5);
- waitbusy (ai);
- set_current_state (TASK_UNINTERRUPTIBLE);
- schedule_timeout (HZ/5);
- if ( setup_card(ai, dev->dev_addr ) != SUCCESS ) {
- printk( KERN_ERR "airo: MAC could not be enabledn" );
- return -1;
- } else {
- printk( KERN_INFO "airo: MAC enabled %s %x:%x:%x:%x:%x:%xn",
- dev->name,
- dev->dev_addr[0],
- dev->dev_addr[1],
- dev->dev_addr[2],
- dev->dev_addr[3],
- dev->dev_addr[4],
- dev->dev_addr[5]
- );
- /* Allocate the transmit buffers */
- for( i = 0; i < MAX_FIDS; i++ )
- ai->fids[i] = transmit_allocate(ai,2312,i>=MAX_FIDS/2);
- }
- enable_interrupts( ai );
- netif_wake_queue(dev);
- return 0;
- }
- EXPORT_SYMBOL(reset_airo_card);
- #if WIRELESS_EXT > 13
- static void airo_send_event(struct net_device *dev) {
- struct airo_info *ai = dev->priv;
- union iwreq_data wrqu;
- StatusRid status_rid;
- if (down_trylock(&ai->sem) == 0) {
- __set_bit(FLAG_LOCKED, &ai->flags);
- PC4500_readrid(ai, RID_STATUS, &status_rid, sizeof(status_rid));
- clear_bit(FLAG_LOCKED, &ai->flags);
- up(&ai->sem);
- wrqu.data.length = 0;
- wrqu.data.flags = 0;
- memcpy(wrqu.ap_addr.sa_data, status_rid.bssid[0], ETH_ALEN);
- wrqu.ap_addr.sa_family = ARPHRD_ETHER;
- /* Send event to user space */
- wireless_send_event(dev, SIOCGIWAP, &wrqu, NULL);
- } else {
- ai->event_task.routine = (void (*)(void *))airo_send_event;
- ai->event_task.data = (void *)dev;
- schedule_task(&ai->event_task);
- }
- }
- #endif
- static void airo_read_mic(struct airo_info *ai) {
- MICRid mic_rid;
- if (down_trylock(&ai->sem) == 0) {
- __set_bit(FLAG_LOCKED, &ai->flags);
- PC4500_readrid(ai, RID_MIC, &mic_rid, sizeof(mic_rid));
- clear_bit(FLAG_LOCKED, &ai->flags);
- up(&ai->sem);
- #ifdef MICSUPPORT
- micinit (ai, &mic_rid);
- #endif
- } else {
- ai->mic_task.routine = (void (*)(void *))airo_read_mic;
- ai->mic_task.data = (void *)ai;
- schedule_task(&ai->mic_task);
- }
- }
- static void airo_interrupt ( int irq, void* dev_id, struct pt_regs *regs) {
- struct net_device *dev = (struct net_device *)dev_id;
- u16 status;
- u16 fid;
- struct airo_info *apriv = dev->priv;
- u16 savedInterrupts = 0;
- if (!netif_device_present(dev))
- return;
- for (;;) {
- status = IN4500( apriv, EVSTAT );
- if ( !(status & STATUS_INTS) || status == 0xffff ) break;
- if ( status & EV_AWAKE ) {
- OUT4500( apriv, EVACK, EV_AWAKE );
- OUT4500( apriv, EVACK, EV_AWAKE );
- }
- if (!savedInterrupts) {
- savedInterrupts = IN4500( apriv, EVINTEN );
- OUT4500( apriv, EVINTEN, 0 );
- }
- if ( status & EV_MIC ) {
- OUT4500( apriv, EVACK, EV_MIC );
- airo_read_mic( apriv );
- }
- if ( status & EV_LINK ) {
- #if WIRELESS_EXT > 13
- union iwreq_data wrqu;
- #endif /* WIRELESS_EXT > 13 */
- /* The link status has changed, if you want to put a
- monitor hook in, do it here. (Remember that
- interrupts are still disabled!)
- */
- u16 newStatus = IN4500(apriv, LINKSTAT);
- OUT4500( apriv, EVACK, EV_LINK);
- /* Here is what newStatus means: */
- #define NOBEACON 0x8000 /* Loss of sync - missed beacons */
- #define MAXRETRIES 0x8001 /* Loss of sync - max retries */
- #define MAXARL 0x8002 /* Loss of sync - average retry level exceeded*/
- #define FORCELOSS 0x8003 /* Loss of sync - host request */
- #define TSFSYNC 0x8004 /* Loss of sync - TSF synchronization */
- #define DEAUTH 0x8100 /* Deauthentication (low byte is reason code) */
- #define DISASS 0x8200 /* Disassociation (low byte is reason code) */
- #define ASSFAIL 0x8400 /* Association failure (low byte is reason
- code) */
- #define AUTHFAIL 0x0300 /* Authentication failure (low byte is reason
- code) */
- #define ASSOCIATED 0x0400 /* Assocatied */
- #define RC_RESERVED 0 /* Reserved return code */
- #define RC_NOREASON 1 /* Unspecified reason */
- #define RC_AUTHINV 2 /* Previous authentication invalid */
- #define RC_DEAUTH 3 /* Deauthenticated because sending station is
- leaving */
- #define RC_NOACT 4 /* Disassociated due to inactivity */
- #define RC_MAXLOAD 5 /* Disassociated because AP is unable to handle
- all currently associated stations */
- #define RC_BADCLASS2 6 /* Class 2 frame received from
- non-Authenticated station */
- #define RC_BADCLASS3 7 /* Class 3 frame received from
- non-Associated station */
- #define RC_STATLEAVE 8 /* Disassociated because sending station is
- leaving BSS */
- #define RC_NOAUTH 9 /* Station requesting (Re)Association is not
- Authenticated with the responding station */
- if (newStatus != ASSOCIATED) {
- if (auto_wep && !timer_pending(&apriv->timer)) {
- apriv->timer.expires = RUN_AT(HZ*3);
- add_timer(&apriv->timer);
- }
- } else {
- struct task_struct *task = apriv->task;
- if (task)
- wake_up_process (task);
- apriv->flags|=FLAG_UPDATE_UNI|FLAG_UPDATE_MULTI;
- }
- #if WIRELESS_EXT > 13
- /* Question : is ASSOCIATED the only status
- * that is valid ? We want to catch handover
- * and reassociations as valid status
- * Jean II */
- if(newStatus == ASSOCIATED) {
- if (apriv->scan_timestamp) {
- /* Send an empty event to user space.
- * We don't send the received data on
- * the event because it would require
- * us to do complex transcoding, and
- * we want to minimise the work done in
- * the irq handler. Use a request to
- * extract the data - Jean II */
- wrqu.data.length = 0;
- wrqu.data.flags = 0;
- wireless_send_event(dev, SIOCGIWSCAN, &wrqu, NULL);
- apriv->scan_timestamp = 0;
- }
- airo_send_event(dev);
- } else {
- memset(wrqu.ap_addr.sa_data, ' ', ETH_ALEN);
- wrqu.ap_addr.sa_family = ARPHRD_ETHER;
- /* Send event to user space */
- wireless_send_event(dev, SIOCGIWAP, &wrqu,NULL);
- }
- #endif /* WIRELESS_EXT > 13 */
- }
- /* Check to see if there is something to receive */
- if ( status & EV_RX ) {
- struct sk_buff *skb = NULL;
- u16 fc, len, hdrlen = 0;
- #pragma pack(1)
- struct {
- u16 status, len;
- u8 rssi[2];
- u8 rate;
- u8 freq;
- u16 tmp[4];
- } hdr;
- #pragma pack()
- u16 gap;
- u16 tmpbuf[4];
- u16 *buffer;
- fid = IN4500( apriv, RXFID );
- /* Get the packet length */
- if (apriv->flags & FLAG_802_11) {
- bap_setup (apriv, fid, 4, BAP0);
- bap_read (apriv, (u16*)&hdr, sizeof(hdr), BAP0);
- /* Bad CRC. Ignore packet */
- if (le16_to_cpu(hdr.status) & 2)
- hdr.len = 0;
- if (apriv->wifidev == NULL)
- hdr.len = 0;
- } else {
- bap_setup (apriv, fid, 0x36, BAP0);
- bap_read (apriv, (u16*)&hdr.len, 2, BAP0);
- }
- len = le16_to_cpu(hdr.len);
- if (len > 2312) {
- printk( KERN_ERR "airo: Bad size %dn", len );
- len = 0;
- }
- if (len) {
- if (apriv->flags & FLAG_802_11) {
- bap_read (apriv, (u16*)&fc, sizeof(fc), BAP0);
- fc = le16_to_cpu(fc);
- switch (fc & 0xc) {
- case 4:
- if ((fc & 0xe0) == 0xc0)
- hdrlen = 10;
- else
- hdrlen = 16;
- break;
- case 8:
- if ((fc&0x300)==0x300){
- hdrlen = 30;
- break;
- }
- default:
- hdrlen = 24;
- }
- } else
- hdrlen = ETH_ALEN * 2;
- skb = dev_alloc_skb( len + hdrlen + 2 );
- if ( !skb ) {
- apriv->stats.rx_dropped++;
- len = 0;
- }
- }
- if (len) {
- buffer = (u16*)skb_put (skb, len + hdrlen);
- if (apriv->flags & FLAG_802_11) {
- buffer[0] = fc;
- bap_read (apriv, buffer + 1, hdrlen - 2, BAP0);
- if (hdrlen == 24)
- bap_read (apriv, tmpbuf, 6, BAP0);
- bap_read (apriv, &gap, sizeof(gap), BAP0);
- gap = le16_to_cpu(gap);
- if (gap) {
- if (gap <= 8)
- bap_read (apriv, tmpbuf, gap, BAP0);
- else
- printk(KERN_ERR "airo: gaplen too big. Problems will follow...n");
- }
- bap_read (apriv, buffer + hdrlen/2, len, BAP0);
- } else {
- MICBuffer micbuf;
- bap_read (apriv, buffer, ETH_ALEN*2, BAP0);
- if (apriv->micstats.enabled) {
- bap_read (apriv,(u16*)&micbuf,sizeof(micbuf),BAP0);
- if (ntohs(micbuf.typelen) > 0x05DC)
- bap_setup (apriv, fid, 0x44, BAP0);
- else {
- len -= sizeof(micbuf);
- if (len < 48)
- len = 48;
- skb_trim (skb, len + hdrlen);
- }
- }
- bap_read(apriv,buffer+ETH_ALEN,len,BAP0);
- #ifdef MICSUPPORT
- if (decapsulate(apriv,&micbuf,(etherHead*)buffer,len)) {
- dev_kfree_skb_irq (skb);
- len = 0;
- }
- #endif
- }
- }
- if (len) {
- #ifdef WIRELESS_SPY
- if (apriv->spy_number > 0) {
- int i;
- char *sa;
- sa = (char*)buffer + ((apriv->flags & FLAG_802_11) ? 10 : 6);
- for (i=0; i<apriv->spy_number; i++)
- if (!memcmp(sa,apriv->spy_address[i],ETH_ALEN))
- {
- if (!(apriv->flags & FLAG_802_11)) {
- bap_setup (apriv, fid, 8, BAP0);
- bap_read (apriv, (u16*)hdr.rssi, 2, BAP0);
- }
- apriv->spy_stat[i].qual = hdr.rssi[0];
- if (apriv->rssi)
- apriv->spy_stat[i].level = 0x100 - apriv->rssi[hdr.rssi[1]].rssidBm;
- else
- apriv->spy_stat[i].level = (hdr.rssi[1] + 321) / 2;
- apriv->spy_stat[i].noise = 0;
- apriv->spy_stat[i].updated = 3;
- break;
- }
- }
- #endif /* WIRELESS_SPY */
- OUT4500( apriv, EVACK, EV_RX);
- if (apriv->flags & FLAG_802_11) {
- skb->mac.raw = skb->data;
- skb->pkt_type = PACKET_OTHERHOST;
- skb->dev = apriv->wifidev;
- skb->protocol = htons(ETH_P_802_2);
- } else {
- skb->dev = dev;
- skb->protocol = eth_type_trans(skb,dev);
- }
- skb->dev->last_rx = jiffies;
- skb->ip_summed = CHECKSUM_NONE;
- netif_rx( skb );
- } else
- OUT4500( apriv, EVACK, EV_RX);
- }
- /* Check to see if a packet has been transmitted */
- if ( status & ( EV_TX|EV_TXEXC ) ) {
- int i;
- int len = 0;
- int index = -1;
- fid = IN4500(apriv, TXCOMPLFID);
- for( i = 0; i < MAX_FIDS; i++ ) {
- if ( ( apriv->fids[i] & 0xffff ) == fid ) {
- len = apriv->fids[i] >> 16;
- index = i;
- /* Set up to be used again */
- apriv->fids[i] &= 0xffff;
- }
- }
- if (index != -1) {
- netif_wake_queue(dev);
- if (status & EV_TXEXC)
- get_tx_error(apriv, index);
- }
- OUT4500( apriv, EVACK, status & (EV_TX | EV_TXEXC));
- if (index==-1) {
- printk( KERN_ERR "airo: Unallocated FID was used to xmitn" );
- }
- }
- if ( status & ~STATUS_INTS & ~IGNORE_INTS )
- printk( KERN_WARNING "airo: Got weird status %xn",
- status & ~STATUS_INTS & ~IGNORE_INTS );
- }
- if (savedInterrupts)
- OUT4500( apriv, EVINTEN, savedInterrupts );
- /* done.. */
- return;
- }
- /*
- * Routines to talk to the card
- */
- /*
- * This was originally written for the 4500, hence the name
- * NOTE: If use with 8bit mode and SMP bad things will happen!
- * Why would some one do 8 bit IO in an SMP machine?!?
- */
- static void OUT4500( struct airo_info *ai, u16 reg, u16 val ) {
- if ( !do8bitIO )
- outw( val, ai->dev->base_addr + reg );
- else {
- outb( val & 0xff, ai->dev->base_addr + reg );
- outb( val >> 8, ai->dev->base_addr + reg + 1 );
- }
- }
- static u16 IN4500( struct airo_info *ai, u16 reg ) {
- unsigned short rc;
- if ( !do8bitIO )
- rc = inw( ai->dev->base_addr + reg );
- else {
- rc = inb( ai->dev->base_addr + reg );
- rc += ((int)inb( ai->dev->base_addr + reg + 1 )) << 8;
- }
- return rc;
- }
- static int enable_MAC( struct airo_info *ai, Resp *rsp ) {
- int rc;
- Cmd cmd;
- /* FLAG_RADIO_OFF : Radio disabled via /proc or Wireless Extensions
- * FLAG_RADIO_DOWN : Radio disabled via "ifconfig ethX down"
- * Note : we could try to use !netif_running(dev) in enable_MAC()
- * instead of this flag, but I don't trust it *within* the
- * open/close functions, and testing both flags together is
- * "cheaper" - Jean II */
- if (ai->flags & (FLAG_RADIO_OFF|FLAG_RADIO_DOWN)) return SUCCESS;
- memset(&cmd, 0, sizeof(cmd));
- cmd.cmd = MAC_ENABLE;
- if (test_bit(FLAG_LOCKED, &ai->flags) != 0)
- return issuecommand(ai, &cmd, rsp);
- if (down_interruptible(&ai->sem))
- return -ERESTARTSYS;
- rc = issuecommand(ai, &cmd, rsp);
- up(&ai->sem);
- return rc;
- }
- static void disable_MAC( struct airo_info *ai ) {
- Cmd cmd;
- Resp rsp;
- memset(&cmd, 0, sizeof(cmd));
- cmd.cmd = MAC_DISABLE; // disable in case already enabled
- if (test_bit(FLAG_LOCKED, &ai->flags) != 0) {
- issuecommand(ai, &cmd, &rsp);
- return;
- }
- if (down_interruptible(&ai->sem))
- return;
- issuecommand(ai, &cmd, &rsp);
- up(&ai->sem);
- }
- static void enable_interrupts( struct airo_info *ai ) {
- /* Reset the status register */
- u16 status = IN4500( ai, EVSTAT );
- OUT4500( ai, EVACK, status );
- /* Enable the interrupts */
- OUT4500( ai, EVINTEN, STATUS_INTS );
- /* Note there is a race condition between the last two lines that
- I dont know how to get rid of right now... */
- }
- static void disable_interrupts( struct airo_info *ai ) {
- OUT4500( ai, EVINTEN, 0 );
- }
- static u16 setup_card(struct airo_info *ai, u8 *mac)
- {
- Cmd cmd;
- Resp rsp;
- int status;
- int i;
- SsidRid mySsid;
- u16 lastindex;
- WepKeyRid wkr;
- int rc;
- memset( &mySsid, 0, sizeof( mySsid ) );
- if (ai->flash) {
- kfree (ai->flash);
- ai->flash = NULL;
- }
- /* The NOP is the first step in getting the card going */
- cmd.cmd = NOP;
- cmd.parm0 = cmd.parm1 = cmd.parm2 = 0;
- if (down_interruptible(&ai->sem))
- return ERROR;
- if ( issuecommand( ai, &cmd, &rsp ) != SUCCESS ) {
- up(&ai->sem);
- return ERROR;
- }
- memset(&cmd, 0, sizeof(cmd));
- cmd.cmd = MAC_DISABLE; // disable in case already enabled
- if ( issuecommand( ai, &cmd, &rsp ) != SUCCESS ) {
- up(&ai->sem);
- return ERROR;
- }
- // Let's figure out if we need to use the AUX port
- cmd.cmd = CMD_ENABLEAUX;
- if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
- up(&ai->sem);
- printk(KERN_ERR "airo: Error checking for AUX portn");
- return ERROR;
- }
- if (!aux_bap || rsp.status & 0xff00) {
- ai->bap_read = fast_bap_read;
- printk(KERN_DEBUG "airo: Doing fast bap_readsn");
- } else {
- ai->bap_read = aux_bap_read;
- printk(KERN_DEBUG "airo: Doing AUX bap_readsn");
- }
- up(&ai->sem);
- if (ai->config.len == 0) {
- tdsRssiRid rssi_rid;
- CapabilityRid cap_rid;
- // general configuration (read/modify/write)
- status = readConfigRid(ai);
- if ( status != SUCCESS ) return ERROR;
- status = readCapabilityRid(ai, &cap_rid);
- if ( status != SUCCESS ) return ERROR;
- status = PC4500_readrid(ai,RID_RSSI,&rssi_rid,sizeof(rssi_rid));
- if ( status == SUCCESS ) {
- if (ai->rssi || (ai->rssi = kmalloc(512, GFP_KERNEL)) != NULL)
- memcpy(ai->rssi, (u8*)&rssi_rid + 2, 512);
- }
- else {
- if (ai->rssi) {
- kfree(ai->rssi);
- ai->rssi = NULL;
- }
- if (cap_rid.softCap & 8)
- ai->config.rmode |= RXMODE_NORMALIZED_RSSI;
- else
- printk(KERN_WARNING "airo: unknown received signal level scalen");
- }
- ai->config.opmode = adhoc ? MODE_STA_IBSS : MODE_STA_ESS;
- #ifdef MICSUPPORT
- if ((cap_rid.len==sizeof(cap_rid)) && (cap_rid.extSoftCap&1)) {
- ai->config.opmode |= MODE_MIC;
- ai->flags |= FLAG_MIC_CAPABLE;
- micsetup(ai);
- }
- #endif
- /* Save off the MAC */
- for( i = 0; i < ETH_ALEN; i++ ) {
- mac[i] = ai->config.macAddr[i];
- }
- /* Check to see if there are any insmod configured
- rates to add */
- if ( rates ) {
- int i = 0;
- if ( rates[0] ) memset(ai->config.rates,0,sizeof(ai->config.rates));
- for( i = 0; i < 8 && rates[i]; i++ ) {
- ai->config.rates[i] = rates[i];
- }
- }
- if ( basic_rate > 0 ) {
- int i;
- for( i = 0; i < 8; i++ ) {
- if ( ai->config.rates[i] == basic_rate ||
- !ai->config.rates ) {
- ai->config.rates[i] = basic_rate | 0x80;
- break;
- }
- }
- }
- ai->need_commit = 1;
- }
- /* Setup the SSIDs if present */
- if ( ssids[0] ) {
- int i;
- for( i = 0; i < 3 && ssids[i]; i++ ) {
- mySsid.ssids[i].len = strlen(ssids[i]);
- if ( mySsid.ssids[i].len > 32 )
- mySsid.ssids[i].len = 32;
- memcpy(mySsid.ssids[i].ssid, ssids[i],
- mySsid.ssids[i].len);
- }
- }
- status = writeConfigRid(ai);
- if ( status != SUCCESS ) return ERROR;
- /* Set up the SSID list */
- status = writeSsidRid(ai, &mySsid);
- if ( status != SUCCESS ) return ERROR;
- status = enable_MAC(ai, &rsp);
- if ( status != SUCCESS || (rsp.status & 0xFF00) != 0) {
- printk( KERN_ERR "airo: Bad MAC enable reason = %x, rid = %x, offset = %dn", rsp.rsp0, rsp.rsp1, rsp.rsp2 );
- return ERROR;
- }
- /* Grab the initial wep key, we gotta save it for auto_wep */
- rc = readWepKeyRid(ai, &wkr, 1);
- if (rc == SUCCESS) do {
- lastindex = wkr.kindex;
- if (wkr.kindex == 0xffff) {
- ai->defindex = wkr.mac[0];
- }
- rc = readWepKeyRid(ai, &wkr, 0);
- } while(lastindex != wkr.kindex);
- if (auto_wep && !timer_pending(&ai->timer)) {
- ai->timer.expires = RUN_AT(HZ*3);
- add_timer(&ai->timer);
- }
- return SUCCESS;
- }
- static u16 issuecommand(struct airo_info *ai, Cmd *pCmd, Resp *pRsp) {
- // Im really paranoid about letting it run forever!
- int max_tries = 600000;
- if (sendcommand(ai, pCmd) == (u16)ERROR)
- return ERROR;
- while (max_tries-- && (IN4500(ai, EVSTAT) & EV_CMD) == 0) {
- if (!in_interrupt() && (max_tries & 255) == 0)
- schedule();
- }
- if ( max_tries == -1 ) {
- printk( KERN_ERR
- "airo: Max tries exceeded waiting for commandn" );
- return ERROR;
- }
- completecommand(ai, pRsp);
- return SUCCESS;
- }
- static u16 sendcommand(struct airo_info *ai, Cmd *pCmd) {
- // Im really paranoid about letting it run forever!
- int max_tries = 600000;
- u16 cmd;
- OUT4500(ai, PARAM0, pCmd->parm0);
- OUT4500(ai, PARAM1, pCmd->parm1);
- OUT4500(ai, PARAM2, pCmd->parm2);
- OUT4500(ai, COMMAND, pCmd->cmd);
- while ( max_tries-- && (IN4500(ai, EVSTAT) & EV_CMD) == 0 &&
- (cmd = IN4500(ai, COMMAND)) != 0 )
- if (cmd == pCmd->cmd)
- // PC4500 didn't notice command, try again
- OUT4500(ai, COMMAND, pCmd->cmd);
- if ( max_tries == -1 ) {
- printk( KERN_ERR
- "airo: Max tries exceeded when issueing commandn" );
- return ERROR;
- }
- return SUCCESS;
- }
- static void completecommand(struct airo_info *ai, Resp *pRsp) {
- // command completed
- pRsp->status = IN4500(ai, STATUS);
- pRsp->rsp0 = IN4500(ai, RESP0);
- pRsp->rsp1 = IN4500(ai, RESP1);
- pRsp->rsp2 = IN4500(ai, RESP2);
- // clear stuck command busy if necessary
- if (IN4500(ai, COMMAND) & COMMAND_BUSY) {
- OUT4500(ai, EVACK, EV_CLEARCOMMANDBUSY);
- }
- // acknowledge processing the status/response
- OUT4500(ai, EVACK, EV_CMD);
- }
- /* Sets up the bap to start exchange data. whichbap should
- * be one of the BAP0 or BAP1 defines. Locks should be held before
- * calling! */
- static int bap_setup(struct airo_info *ai, u16 rid, u16 offset, int whichbap )
- {
- int timeout = 50;
- int max_tries = 3;
- OUT4500(ai, SELECT0+whichbap, rid);
- OUT4500(ai, OFFSET0+whichbap, offset);
- while (1) {
- int status = IN4500(ai, OFFSET0+whichbap);
- if (status & BAP_BUSY) {
- /* This isn't really a timeout, but its kinda
- close */
- if (timeout--) {
- continue;
- }
- } else if ( status & BAP_ERR ) {
- /* invalid rid or offset */
- printk( KERN_ERR "airo: BAP error %x %dn",
- status, whichbap );
- return ERROR;
- } else if (status & BAP_DONE) { // success
- return SUCCESS;
- }
- if ( !(max_tries--) ) {
- printk( KERN_ERR
- "airo: BAP setup error too many retriesn" );
- return ERROR;
- }
- // -- PC4500 missed it, try again
- OUT4500(ai, SELECT0+whichbap, rid);
- OUT4500(ai, OFFSET0+whichbap, offset);
- timeout = 50;
- }
- }
- /* should only be called by aux_bap_read. This aux function and the
- following use concepts not documented in the developers guide. I
- got them from a patch given to my by Aironet */
- static u16 aux_setup(struct airo_info *ai, u16 page,
- u16 offset, u16 *len)
- {
- u16 next;
- OUT4500(ai, AUXPAGE, page);
- OUT4500(ai, AUXOFF, 0);
- next = IN4500(ai, AUXDATA);
- *len = IN4500(ai, AUXDATA)&0xff;
- if (offset != 4) OUT4500(ai, AUXOFF, offset);
- return next;
- }
- /* requires call to bap_setup() first */
- static int aux_bap_read(struct airo_info *ai, u16 *pu16Dst,
- int bytelen, int whichbap)
- {
- u16 len;
- u16 page;
- u16 offset;
- u16 next;
- int words;
- int i;
- long flags;
- spin_lock_irqsave(&ai->aux_lock, flags);
- page = IN4500(ai, SWS0+whichbap);
- offset = IN4500(ai, SWS2+whichbap);
- next = aux_setup(ai, page, offset, &len);
- words = (bytelen+1)>>1;
- for (i=0; i<words;) {
- int count;
- count = (len>>1) < (words-i) ? (len>>1) : (words-i);
- if ( !do8bitIO )
- insw( ai->dev->base_addr+DATA0+whichbap,
- pu16Dst+i,count );
- else
- insb( ai->dev->base_addr+DATA0+whichbap,
- pu16Dst+i, count << 1 );
- i += count;
- if (i<words) {
- next = aux_setup(ai, next, 4, &len);
- }
- }
- spin_unlock_irqrestore(&ai->aux_lock, flags);
- return SUCCESS;
- }
- /* requires call to bap_setup() first */
- static int fast_bap_read(struct airo_info *ai, u16 *pu16Dst,
- int bytelen, int whichbap)
- {
- bytelen = (bytelen + 1) & (~1); // round up to even value
- if ( !do8bitIO )
- insw( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen>>1 );
- else
- insb( ai->dev->base_addr+DATA0+whichbap, pu16Dst, bytelen );
- return SUCCESS;
- }
- /* requires call to bap_setup() first */
- static int bap_write(struct airo_info *ai, const u16 *pu16Src,
- int bytelen, int whichbap)
- {
- bytelen = (bytelen + 1) & (~1); // round up to even value
- if ( !do8bitIO )
- outsw( ai->dev->base_addr+DATA0+whichbap,
- pu16Src, bytelen>>1 );
- else
- outsb( ai->dev->base_addr+DATA0+whichbap, pu16Src, bytelen );
- return SUCCESS;
- }
- static int PC4500_accessrid(struct airo_info *ai, u16 rid, u16 accmd)
- {
- Cmd cmd; /* for issuing commands */
- Resp rsp; /* response from commands */
- u16 status;
- memset(&cmd, 0, sizeof(cmd));
- cmd.cmd = accmd;
- cmd.parm0 = rid;
- status = issuecommand(ai, &cmd, &rsp);
- if (status != 0) return status;
- if ( (rsp.status & 0x7F00) != 0) {
- return (accmd << 8) + (rsp.rsp0 & 0xFF);
- }
- return 0;
- }
- /* Note, that we are using BAP1 which is also used by transmit, so
- * we must get a lock. */
- static int PC4500_readrid(struct airo_info *ai, u16 rid, void *pBuf, int len)
- {
- u16 status, dolock = 0;
- int rc = SUCCESS;
- if (test_bit(FLAG_LOCKED, &ai->flags) == 0) {
- dolock = 1;
- if (down_interruptible(&ai->sem))
- return ERROR;
- }
- if ( (status = PC4500_accessrid(ai, rid, CMD_ACCESS)) != SUCCESS) {
- rc = status;
- goto done;
- }
- if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
- rc = ERROR;
- goto done;
- }
- // read the rid length field
- bap_read(ai, pBuf, 2, BAP1);
- // length for remaining part of rid
- len = min(len, (int)le16_to_cpu(*(u16*)pBuf)) - 2;
- if ( len <= 2 ) {
- printk( KERN_ERR
- "airo: Rid %x has a length of %d which is too shortn",
- (int)rid,
- (int)len );
- rc = ERROR;
- goto done;
- }
- // read remainder of the rid
- rc = bap_read(ai, ((u16*)pBuf)+1, len, BAP1);
- done:
- if (dolock)
- up(&ai->sem);
- return rc;
- }
- /* Note, that we are using BAP1 which is also used by transmit, so
- * make sure this isnt called when a transmit is happening */
- static int PC4500_writerid(struct airo_info *ai, u16 rid,
- const void *pBuf, int len)
- {
- u16 status, dolock = 0;
- int rc = SUCCESS;
- if (test_bit(FLAG_LOCKED, &ai->flags) == 0) {
- dolock = 1;
- if (down_interruptible(&ai->sem))
- return ERROR;
- }
- // --- first access so that we can write the rid data
- if ( (status = PC4500_accessrid(ai, rid, CMD_ACCESS)) != 0) {
- rc = status;
- goto done;
- }
- // --- now write the rid data
- if (bap_setup(ai, rid, 0, BAP1) != SUCCESS) {
- rc = ERROR;
- goto done;
- }
- bap_write(ai, pBuf, len, BAP1);
- // ---now commit the rid data
- rc = PC4500_accessrid(ai, rid, 0x100|CMD_ACCESS);
- done:
- if (dolock)
- up(&ai->sem);
- return rc;
- }
- /* Allocates a FID to be used for transmitting packets. We only use
- one for now. */
- static u16 transmit_allocate(struct airo_info *ai, int lenPayload, int raw)
- {
- Cmd cmd;
- Resp rsp;
- u16 txFid;
- u16 txControl;
- cmd.cmd = CMD_ALLOCATETX;
- cmd.parm0 = lenPayload;
- if (down_interruptible(&ai->sem))
- return ERROR;
- if (issuecommand(ai, &cmd, &rsp) != SUCCESS) {
- txFid = 0;
- goto done;
- }
- if ( (rsp.status & 0xFF00) != 0) {
- txFid = 0;
- goto done;
- }
- /* wait for the allocate event/indication
- * It makes me kind of nervous that this can just sit here and spin,
- * but in practice it only loops like four times. */
- while ( (IN4500(ai, EVSTAT) & EV_ALLOC) == 0) ;
- // get the allocated fid and acknowledge
- txFid = IN4500(ai, TXALLOCFID);
- OUT4500(ai, EVACK, EV_ALLOC);
- /* The CARD is pretty cool since it converts the ethernet packet
- * into 802.11. Also note that we don't release the FID since we
- * will be using the same one over and over again. */
- /* We only have to setup the control once since we are not
- * releasing the fid. */
- if (raw)
- txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_11
- | TXCTL_ETHERNET | TXCTL_NORELEASE);
- else
- txControl = cpu_to_le16(TXCTL_TXOK | TXCTL_TXEX | TXCTL_802_3
- | TXCTL_ETHERNET | TXCTL_NORELEASE);
- if (bap_setup(ai, txFid, 0x0008, BAP1) != SUCCESS)
- txFid = ERROR;
- else
- bap_write(ai, &txControl, sizeof(txControl), BAP1);
- done:
- up(&ai->sem);
- return txFid;
- }
- /* In general BAP1 is dedicated to transmiting packets. However,
- since we need a BAP when accessing RIDs, we also use BAP1 for that.
- Make sure the BAP1 spinlock is held when this is called. */
- static int transmit_802_3_packet(struct airo_info *ai, int len, char *pPacket)
- {
- u16 payloadLen;
- Cmd cmd;
- Resp rsp;
- int miclen = 0;
- u16 txFid = len;
- MICBuffer pMic;
- len >>= 16;
- if (len < ETH_ALEN * 2) {
- printk( KERN_WARNING "Short packet %dn", len );
- return ERROR;
- }
- len -= ETH_ALEN * 2;
- #ifdef MICSUPPORT
- if ((ai->flags & FLAG_MIC_CAPABLE) && ai->micstats.enabled &&
- (ntohs(((u16 *)pPacket)[6]) != 0x888E)) {
- if (encapsulate(ai,(etherHead *)pPacket,&pMic,len) != SUCCESS)
- return ERROR;
- miclen = sizeof(pMic);
- }
- #endif
- // packet is destination[6], source[6], payload[len-12]
- // write the payload length and dst/src/payload
- if (bap_setup(ai, txFid, 0x0036, BAP1) != SUCCESS) return ERROR;
- /* The hardware addresses aren't counted as part of the payload, so
- * we have to subtract the 12 bytes for the addresses off */
- payloadLen = cpu_to_le16(len + miclen);
- bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
- bap_write(ai, (const u16*)pPacket, sizeof(etherHead), BAP1);
- if (miclen)
- bap_write(ai, (const u16*)&pMic, miclen, BAP1);
- bap_write(ai, (const u16*)(pPacket + sizeof(etherHead)), len, BAP1);
- // issue the transmit command
- memset( &cmd, 0, sizeof( cmd ) );
- cmd.cmd = CMD_TRANSMIT;
- cmd.parm0 = txFid;
- if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
- if ( (rsp.status & 0xFF00) != 0) return ERROR;
- return SUCCESS;
- }
- static int transmit_802_11_packet(struct airo_info *ai, int len, char *pPacket)
- {
- u16 fc, payloadLen;
- Cmd cmd;
- Resp rsp;
- int hdrlen;
- struct {
- u8 addr4[ETH_ALEN];
- u16 gaplen;
- u8 gap[6];
- } gap;
- u16 txFid = len;
- len >>= 16;
- gap.gaplen = 6;
- fc = le16_to_cpu(*(const u16*)pPacket);
- switch (fc & 0xc) {
- case 4:
- if ((fc & 0xe0) == 0xc0)
- hdrlen = 10;
- else
- hdrlen = 16;
- break;
- case 8:
- if ((fc&0x300)==0x300){
- hdrlen = 30;
- break;
- }
- default:
- hdrlen = 24;
- }
- if (len < hdrlen) {
- printk( KERN_WARNING "Short packet %dn", len );
- return ERROR;
- }
- /* packet is 802.11 header + payload
- * write the payload length and dst/src/payload */
- if (bap_setup(ai, txFid, 6, BAP1) != SUCCESS) return ERROR;
- /* The 802.11 header aren't counted as part of the payload, so
- * we have to subtract the header bytes off */
- payloadLen = cpu_to_le16(len-hdrlen);
- bap_write(ai, &payloadLen, sizeof(payloadLen),BAP1);
- if (bap_setup(ai, txFid, 0x0014, BAP1) != SUCCESS) return ERROR;
- bap_write(ai, (const u16*)pPacket, hdrlen, BAP1);
- bap_write(ai, hdrlen == 30 ?
- (const u16*)&gap.gaplen : (const u16*)&gap, 38 - hdrlen, BAP1);
- bap_write(ai, (const u16*)(pPacket + hdrlen), len - hdrlen, BAP1);
- // issue the transmit command
- memset( &cmd, 0, sizeof( cmd ) );
- cmd.cmd = CMD_TRANSMIT;
- cmd.parm0 = txFid;
- if (issuecommand(ai, &cmd, &rsp) != SUCCESS) return ERROR;
- if ( (rsp.status & 0xFF00) != 0) return ERROR;
- return SUCCESS;
- }
- /*
- * This is the proc_fs routines. It is a bit messier than I would
- * like! Feel free to clean it up!
- */
- static ssize_t proc_read( struct file *file,
- char *buffer,
- size_t len,
- loff_t *offset);
- static ssize_t proc_write( struct file *file,
- const char *buffer,
- size_t len,
- loff_t *offset );
- static int proc_close( struct inode *inode, struct file *file );
- static int proc_stats_open( struct inode *inode, struct file *file );
- static int proc_statsdelta_open( struct inode *inode, struct file *file );
- static int proc_status_open( struct inode *inode, struct file *file );
- static int proc_SSID_open( struct inode *inode, struct file *file );
- static int proc_APList_open( struct inode *inode, struct file *file );
- static int proc_BSSList_open( struct inode *inode, struct file *file );
- static int proc_config_open( struct inode *inode, struct file *file );
- static int proc_wepkey_open( struct inode *inode, struct file *file );
- static struct file_operations proc_statsdelta_ops = {
- read: proc_read,
- open: proc_statsdelta_open,
- release: proc_close
- };
- static struct file_operations proc_stats_ops = {
- read: proc_read,
- open: proc_stats_open,
- release: proc_close
- };
- static struct file_operations proc_status_ops = {
- read: proc_read,
- open: proc_status_open,
- release: proc_close
- };
- static struct file_operations proc_SSID_ops = {
- read: proc_read,
- write: proc_write,
- open: proc_SSID_open,
- release: proc_close
- };
- static struct file_operations proc_BSSList_ops = {
- read: proc_read,
- write: proc_write,
- open: proc_BSSList_open,
- release: proc_close
- };
- static struct file_operations proc_APList_ops = {
- read: proc_read,
- write: proc_write,
- open: proc_APList_open,
- release: proc_close
- };
- static struct file_operations proc_config_ops = {
- read: proc_read,
- write: proc_write,
- open: proc_config_open,
- release: proc_close
- };
- static struct file_operations proc_wepkey_ops = {
- read: proc_read,
- write: proc_write,
- open: proc_wepkey_open,
- release: proc_close
- };
- static struct proc_dir_entry *airo_entry = 0;
- struct proc_data {
- int release_buffer;
- int readlen;
- char *rbuffer;
- int writelen;
- int maxwritelen;
- char *wbuffer;
- void (*on_close) (struct inode *, struct file *);
- };
- #ifndef SETPROC_OPS
- #define SETPROC_OPS(entry, ops) (entry)->proc_fops = &(ops)
- #endif
- static int setup_proc_entry( struct net_device *dev,
- struct airo_info *apriv ) {
- struct proc_dir_entry *entry;
- /* First setup the device directory */
- apriv->proc_entry = create_proc_entry(dev->name,
- S_IFDIR|airo_perm,
- airo_entry);
- apriv->proc_entry->uid = proc_uid;
- apriv->proc_entry->gid = proc_gid;
- /* Setup the StatsDelta */
- entry = create_proc_entry("StatsDelta",
- S_IFREG | (S_IRUGO&proc_perm),
- apriv->proc_entry);
- entry->uid = proc_uid;
- entry->gid = proc_gid;
- entry->data = dev;
- SETPROC_OPS(entry, proc_statsdelta_ops);
- /* Setup the Stats */
- entry = create_proc_entry("Stats",
- S_IFREG | (S_IRUGO&proc_perm),
- apriv->proc_entry);
- entry->uid = proc_uid;
- entry->gid = proc_gid;
- entry->data = dev;
- SETPROC_OPS(entry, proc_stats_ops);
- /* Setup the Status */
- entry = create_proc_entry("Status",
- S_IFREG | (S_IRUGO&proc_perm),
- apriv->proc_entry);
- entry->uid = proc_uid;
- entry->gid = proc_gid;
- entry->data = dev;
- SETPROC_OPS(entry, proc_status_ops);
- /* Setup the Config */
- entry = create_proc_entry("Config",
- S_IFREG | proc_perm,
- apriv->proc_entry);
- entry->uid = proc_uid;
- entry->gid = proc_gid;
- entry->data = dev;
- SETPROC_OPS(entry, proc_config_ops);
- /* Setup the SSID */
- entry = create_proc_entry("SSID",
- S_IFREG | proc_perm,
- apriv->proc_entry);
- entry->uid = proc_uid;
- entry->gid = proc_gid;
- entry->data = dev;
- SETPROC_OPS(entry, proc_SSID_ops);
- /* Setup the APList */
- entry = create_proc_entry("APList",
- S_IFREG | proc_perm,
- apriv->proc_entry);
- entry->uid = proc_uid;
- entry->gid = proc_gid;
- entry->data = dev;
- SETPROC_OPS(entry, proc_APList_ops);
- /* Setup the BSSList */
- entry = create_proc_entry("BSSList",
- S_IFREG | proc_perm,
- apriv->proc_entry);
- entry->uid = proc_uid;
- entry->gid = proc_gid;
- entry->data = dev;
- SETPROC_OPS(entry, proc_BSSList_ops);
- /* Setup the WepKey */
- entry = create_proc_entry("WepKey",
- S_IFREG | proc_perm,
- apriv->proc_entry);
- entry->uid = proc_uid;
- entry->gid = proc_gid;
- entry->data = dev;
- SETPROC_OPS(entry, proc_wepkey_ops);
- return 0;
- }
- static int takedown_proc_entry( struct net_device *dev,
- struct airo_info *apriv ) {
- if ( !apriv->proc_entry->namelen ) return 0;
- remove_proc_entry("Stats",apriv->proc_entry);
- remove_proc_entry("StatsDelta",apriv->proc_entry);
- remove_proc_entry("Status",apriv->proc_entry);
- remove_proc_entry("Config",apriv->proc_entry);
- remove_proc_entry("SSID",apriv->proc_entry);
- remove_proc_entry("APList",apriv->proc_entry);
- remove_proc_entry("BSSList",apriv->proc_entry);
- remove_proc_entry("WepKey",apriv->proc_entry);
- remove_proc_entry(dev->name,airo_entry);
- return 0;
- }
- /*
- * What we want from the proc_fs is to be able to efficiently read
- * and write the configuration. To do this, we want to read the
- * configuration when the file is opened and write it when the file is
- * closed. So basically we allocate a read buffer at open and fill it
- * with data, and allocate a write buffer and read it at close.
- */
- /*
- * The read routine is generic, it relies on the preallocated rbuffer
- * to supply the data.
- */
- static ssize_t proc_read( struct file *file,
- char *buffer,
- size_t len,
- loff_t *offset )
- {
- int i;
- int pos;
- struct proc_data *priv = (struct proc_data*)file->private_data;
- if( !priv->rbuffer ) return -EINVAL;
- pos = *offset;
- for( i = 0; i+pos < priv->readlen && i < len; i++ ) {
- if (put_user( priv->rbuffer[i+pos], buffer+i ))
- return -EFAULT;
- }
- *offset += i;
- return i;
- }
- /*
- * The write routine is generic, it fills in a preallocated rbuffer
- * to supply the data.
- */
- static ssize_t proc_write( struct file *file,
- const char *buffer,
- size_t len,
- loff_t *offset )
- {
- int i;
- int pos;
- struct proc_data *priv = (struct proc_data*)file->private_data;
- if ( !priv->wbuffer ) {
- return -EINVAL;
- }
- pos = *offset;
- for( i = 0; i + pos < priv->maxwritelen &&
- i < len; i++ ) {
- if (get_user( priv->wbuffer[i+pos], buffer + i ))
- return -EFAULT;
- }
- if ( i+pos > priv->writelen ) priv->writelen = i+file->f_pos;
- *offset += i;
- return i;
- }
- static int proc_status_open( struct inode *inode, struct file *file ) {
- struct proc_data *data;
- struct proc_dir_entry *dp = PDE(inode);
- struct net_device *dev = dp->data;
- struct airo_info *apriv = dev->priv;
- CapabilityRid cap_rid;
- StatusRid status_rid;
- int i;
- MOD_INC_USE_COUNT;
- if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
- return -ENOMEM;
- memset(file->private_data, 0, sizeof(struct proc_data));
- data = (struct proc_data *)file->private_data;
- if ((data->rbuffer = kmalloc( 2048, GFP_KERNEL )) == NULL) {
- kfree (file->private_data);
- return -ENOMEM;
- }
- readStatusRid(apriv, &status_rid);
- readCapabilityRid(apriv, &cap_rid);
- i = sprintf(data->rbuffer, "Status: %s%s%s%s%s%s%s%s%sn",
- status_rid.mode & 1 ? "CFG ": "",
- status_rid.mode & 2 ? "ACT ": "",
- status_rid.mode & 0x10 ? "SYN ": "",
- status_rid.mode & 0x20 ? "LNK ": "",
- status_rid.mode & 0x40 ? "LEAP ": "",
- status_rid.mode & 0x80 ? "PRIV ": "",
- status_rid.mode & 0x100 ? "KEY ": "",
- status_rid.mode & 0x200 ? "WEP ": "",
- status_rid.mode & 0x8000 ? "ERR ": "");
- sprintf( data->rbuffer+i, "Mode: %xn"
- "Signal Strength: %dn"
- "Signal Quality: %dn"
- "SSID: %-.*sn"
- "AP: %-.16sn"
- "Freq: %dn"
- "BitRate: %dmbsn"
- "Driver Version: %sn"
- "Device: %snManufacturer: %snFirmware Version: %sn"
- "Radio type: %xnCountry: %xnHardware Version: %xn"
- "Software Version: %xnSoftware Subversion: %xn"
- "Boot block version: %xn",
- (int)status_rid.mode,
- (int)status_rid.normalizedSignalStrength,
- (int)status_rid.signalQuality,
- (int)status_rid.SSIDlen,
- status_rid.SSID,
- status_rid.apName,
- (int)status_rid.channel,
- (int)status_rid.currentXmitRate/2,
- version,
- cap_rid.prodName,
- cap_rid.manName,
- cap_rid.prodVer,
- cap_rid.radioType,
- cap_rid.country,
- cap_rid.hardVer,
- (int)cap_rid.softVer,
- (int)cap_rid.softSubVer,
- (int)cap_rid.bootBlockVer );
- data->readlen = strlen( data->rbuffer );
- return 0;
- }
- static int proc_stats_rid_open(struct inode*, struct file*, u16);
- static int proc_statsdelta_open( struct inode *inode,
- struct file *file ) {
- if (file->f_mode&FMODE_WRITE) {
- return proc_stats_rid_open(inode, file, RID_STATSDELTACLEAR);
- }
- return proc_stats_rid_open(inode, file, RID_STATSDELTA);
- }
- static int proc_stats_open( struct inode *inode, struct file *file ) {
- return proc_stats_rid_open(inode, file, RID_STATS);
- }
- static int proc_stats_rid_open( struct inode *inode,
- struct file *file,
- u16 rid ) {
- struct proc_data *data;
- struct proc_dir_entry *dp = PDE(inode);
- struct net_device *dev = dp->data;
- struct airo_info *apriv = dev->priv;
- StatsRid stats;
- int i, j;
- int *vals = stats.vals;
- MOD_INC_USE_COUNT;
- if ((file->private_data = kmalloc(sizeof(struct proc_data ), GFP_KERNEL)) == NULL)
- return -ENOMEM;
- memset(file->private_data, 0, sizeof(struct proc_data));
- data = (struct proc_data *)file->private_data;
- if ((data->rbuffer = kmalloc( 4096, GFP_KERNEL )) == NULL) {
- kfree (file->private_data);
- return -ENOMEM;
- }
- readStatsRid(apriv, &stats, rid);
- j = 0;