📄 airo.c
字号:
/*====================================================================== Aironet driver for 4500 and 4800 series cards The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. This code was developed by Benjamin Reed <breed@almaden.ibm.com> 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. ======================================================================*/#ifndef __KERNEL__#define __KERNEL__#endif#ifndef MODULE#define MODULE#endif#include <linux/config.h>#ifdef CONFIG_MODVERSIONS#define MODVERSIONS#include <linux/modversions.h>#endif #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 <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>#ifdef CONFIG_PCI# include <linux/pci.h>static struct { unsigned short vendor; unsigned short id;} card_ids[] = { { 0x14b9, 1 }, { 0x14b9, 0x4500 }, { 0x14b9, 0x4800 }, { 0x14b9, 0x0340 }, { 0x14b9, 0x0350 }, { 0, 0 } };#endif/* Include Wireless Extension definition and check version - Jean II */#include <linux/wireless.h>#if WIRELESS_EXT < 9#warning "Wireless extension v9 or newer required - please upgrade your kernel"#undef WIRELESS_EXT#endif#define WIRELESS_SPY // enable iwspy support#define CISCO_EXT // enable Cisco extensions#ifdef CISCO_EXT#include <linux/delay.h>#endif/* 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/* 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] = {0,0,0,0,0,0,0,0};static int basic_rate = 0;static char *ssids[3] = {0,0,0};static int io[4]={ 0,};static int irq[4]={ 0,};staticint maxencrypt = 0; /* The highest rate that the card can encrypt at. 0 means no limit. For old cards this was 4 */staticint auto_wep = 0; /* If set, it tries to figure out the wep mode */staticint aux_bap = 0; /* Checks to see if the aux ports are needed to read the bap, needed on some older cards and buses. */ staticint adhoc = 0;#if (LINUX_VERSION_CODE > 0x20155)/* new kernel */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("MPL");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.");#include <asm/uaccess.h>#define KFREE_SKB(a,b) dev_kfree_skb(a)#define PROC_REGISTER(a,b) proc_register(a,b)#else /* old kernel */#define capable(x) (suser())#define mdelay(x) udelay(1000*(x))#define SPIN_LOCK_UNLOCKED 0#define spinlock_t int#define spin_lock_irqsave(x, y) save_flags(y); cli()#define spin_unlock_irqrestore(x, y) restore_flags(y)#define timer_pending(a) (((a)->prev) != NULL)#define KFREE_SKB(a,b) dev_kfree_skb(a,b)#define PROC_REGISTER(a,b) proc_register_dynamic(a,b)#endif#if (LINUX_VERSION_CODE < 0x020311)#define PROC_UNREGISTER(root, entry) proc_unregister(root, (entry)->low_ino)#else#undef PROC_REGISTER#define PROC_REGISTER(root, entry) error#define PROC_UNREGISTER(root, entry) error#endif#define _min(x,y) ((x<y)?x:y)#define isalnum(x) ((x>='a'&&x<='z')||(x>='A'&&x<='Z')||(x>='0'&&x<='9'))/* 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 doesnt work though!!! */static int do8bitIO = 0;/* Return codes */#define SUCCESS 0#define ERROR -1#define NO_PACKET -2/* Commands */#define NOP 0x0010#define MAC_ENABLE 0x0001#define MAC_DISABLE 0x0002#define CMD_ACCESS 0x0021#define CMD_ALLOCATETX 0x000a#define CMD_TRANSMIT 0x000b#define HOSTSLEEP 0x85#define CMD_SETMODE 0x0009#define CMD_ENABLEAUX 0x0111#define CMD_SOFTRESET 0x0004/* 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 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 STATUS_INTS ( EV_AWAKE | EV_LINK | EV_TXEXC | EV_TX | EV_RX | EV_UNKNOWN)/* The RIDs */#define RID_CAPABILITIES 0xFF00#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_ACTUALCONFIG 0xFF20 /*readonly*/#define RID_LEAPUSERNAME 0xFF23#define RID_LEAPPASSWORD 0xFF24#define RID_STATUS 0xFF50#define RID_STATS 0xFF68#define RID_STATSDELTA 0xFF69#define RID_STATSDELTACLEAR 0xFF6A/* * 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 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[6]; 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 cmd; u16 parm0; u16 parm1; u16 parm2;} Cmd;typedef struct { u16 status; u16 rsp0; u16 rsp1; u16 rsp2;} Resp;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 */ 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[6]; 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -