📄 cisaironethw.c
字号:
/* cisAironetHw.c - Hardware driver for the Cisco Aironet 340/350 WLAN card *//* Copyright 2001-2003 Wind River Systems, Inc. *//*modification history--------------------02i,09may03,rb Removed warnings caused by IPv6 integration02h,03apr03,ggg Added native card support for LEAP02g,18mar03,ss Fixed SPR 86841 Link Status value not accurate02f,26feb03,ss Fixed diab compiler warnings02e,13feb03,rb Fix for SPR 8513902d,31oct02,ss Removed 'Use RTS' bit from Tx Control Field02c,25oct02,ss Fixed bug in cisAironetCmdIssue - potential infinite loop02b,10may02,dxb Updated powersave routines.02a,03may02,dxb Updated header comments.01z,22apr02,dxb More fixes to init routine.01y,19apr02,eja Added support for 802.1X.01x,17apr02,dxb Fixed init bugs.01w,10apr02,dxb Updated pDev->txRate.01v,09apr02,ss Updated to reflect macro redefinitions01u,08apr02,dxb Added firmware and power management checking at power up.01t,08apr02,eja Code clean up before FCS.01s,05apr02,eja quick x86 bug fix.01r,05apr02,eja Added code to clear temp ssid buffer.01q,05apr02,eja Got rid of packet sniffing method.01p,05apr02,eja Fixed endianess bug.01o,21mar02,dxb Removed compiler warnings.01n,08mar02,eja Bug fixes for power save mode and 128 bit wep.01m,28feb02,eja Allow the setting of 128 bit encryption key.01l,14feb02,eja Got rid of references to DOT11.01k,06feb02,dxb More changes for wlanEnd.h.01j,05feb02,dxb Updated to include changes in wlanEnd.h01i,04feb02,eja Moved Ioctl to seperate file, and optimized card access routines.01h,14jan02,dxb Changed CISCO cardtype value from 3 to 4.01g,27nov01,eja Fixed endianess issue with default BSS name.01f,27nov01,eja Changed error level in link int status show routine to DEBUG_FLOOD.01e,23nov01,eja Added some test API's, and got rid of ioctl test.01d,22nov01,eja Got rid of macro to include cisAironetShow.c.01c,19nov01,rb Made driver big endian compatible01b,13nov01,eja Added line to include cisAironetShow.c into build.01a,07nov01,eja Fix header path error.*//*DESCRIPTIONThis module contains the hardware-specific support routines for the CiscoAironet 340/350 wireless 802.11b driver.CARD ACCESSBoth configuration records and packet data is maintained on the card inbuffers. When you want to access some of this data such as reading areceived packet, sending a packet, or writing a config record, you must usea Buffer Access Path (BAP). Each BAP (there are two on the card) consists ofa <select> register, an <offset> register, and a <data> register. To pointthe BAP at a structure on the card, which is usually a Frame ID (FID) forpackets or a Record ID (RID) for configuration structures, the FID or RIDis written to the <select> register. The offset from the start of thestructure (in 8-bit BYTES) is written to the <offset> register, and thendata may be transferred 16 bits at time to and from the <data> register forthat BAP.INCLUDE FILES: cisAironet.h, wlanEnd.hSEE ALSO: cisAironetEnd.c, cisAironetIoctl.c*/#include <vxWorks.h>#include <string.h>#include <ioLib.h>#include <stdio.h>#include <logLib.h>#include <taskLib.h>#include <sysLib.h>#include <intLib.h>#include <rngLib.h>#include <tickLib.h>#include <pingLib.h>#include "wrn/wlan/cisAironet.h"#include "wrn/wlan/wlanEnd.h"#undef INCLUDE_CISCO_LEAP /* enable 802.1X directly on card, needs MD4 support */#ifdef INCLUDE_CISCO_LEAP#include "rwos.h" /* For MD4 algorithm to store LEAP password. Add */ /* target/h/wrn/rwos and target/h/wrn to include path */#endif /* INCLUDE_CISCO_LEAP */#undef INCLUDE_TEST_CODE /* define this to use test routines */#define ANET_FIRMWARE_VERSION 0x425 /* support version 4.25 or higher */#define ANET_FIRMWARE_STRING "4.25" /* defined as a string *//* Api - to get the default bsp config parameters */IMPORT STATUS sysWlanCfgParamGet (UINT32 cmd, INT32 data);/* Link status - loss of sync reasons */LOCAL char * lossOfSync [] = { "missed beacons", "mac retries", "average retry level (ARL) exceeded", "host request", "TSF synchronization" };/* Link status messages */LOCAL char * linkStsReason [] = { "Reserved", "Unspecified reason", "Previous authentication no longer valid", "Deauthenticated because sending station has left IBSS or ESS", "Diassociated due to inactivity", "Diassociated because AP is unable to handle all stations", "Class 2 frame received from non-associated station", "Class 3 frame received from non-associated station", "Diassociated because sending station has left BSS" "Station requesting re-association is not authenticated" };/* Command error descriptions */LOCAL char * errorDesc [] = { "Illegal format (Command)", "Already enabled", "Invalid RID", "Invalid Mode", "Invalid Receive Mode", "Invalid Mac Address", "Invalid Ordering Selection", "Invalid ScanMode", "Invalid Authentication Type", "Invalid Power Save Mode", "Invalid Beacon Interval", "Invalid Hop Interval", "Invalid Radio Type", "Invalid Diversity", "Invalid SSID list entry", "Invalid Specified AP entry", "MAC is already disabled", "Not Active MAC must be enabled", "Illegal command - cannot be a root AP", "Illegal command - not supported", "Allocation size is too large", "Alloc is already busy", "Invalid FID", "FD.DataLen field is too long", "Cannot write to this RID while MAC enabled", "RID is write only", "RID is read only", "No buffer space", "Unknown command", "Unknown error" };/* error descriptor */LOCAL CARD_ERR_T cisAironetHwErrors = { {0, 0, 0, 0}, {0, 0, 0, 0}, NULL };/* Default SSID list */LOCAL SSID_RID_T ssidList = { 0, { { 0,"" }, { 0,"" } } };/* Local Methods */LOCAL INT16 bapWrite (CARD_CTRL_T *, UINT16, UINT32, UINT16, UINT16 *, INT32);LOCAL STATUS bapRead (CARD_CTRL_T *, UINT16, UINT32, UINT16, UINT16 *, INT32);LOCAL INT16 cisAironetHwErrorCheck (CARD_CTRL_T *);LOCAL STATUS cisAironetHwCmdIssue (CARD_CTRL_T *);LOCAL STATUS cisAironetHwBapSetup (CARD_CTRL_T *, UINT16, UINT16, INT32);LOCAL INT16 cisAironetHwRidAccess (CARD_CTRL_T *, UINT16, UINT16);LOCAL INT16 cisAironetHwBapRead (CARD_CTRL_T *, UINT16 *, UINT32, UINT32);LOCAL INT16 cisAironetHwBapWrite (CARD_CTRL_T *, UINT16 *, UINT32, UINT32);LOCAL INT16 cisAironetHwErrorCheck (CARD_CTRL_T *);LOCAL void * cisAironetHwErrorDesc (void);LOCAL STATUS cisAironetHwMacAddrGet (CARD_CTRL_T *);LOCAL STATUS cisAironetHwCardInit (CARD_CTRL_T *);LOCAL STATUS cisAironetHwCardInit (CARD_CTRL_T *);LOCAL STATUS cisAironetHwRidWepTGet (CARD_CTRL_T *, void *);LOCAL STATUS cisAironetHwRidWepPGet (CARD_CTRL_T *, void *);LOCAL STATUS cisAironetHwRidWepTSet (CARD_CTRL_T *, void *);LOCAL STATUS cisAironetHwRidWepPSet (CARD_CTRL_T *, void *);/* local reference to driver control structure */LOCAL CARD_CTRL_T * pDrv = NULL;/**************************************************************************** cisAironetHwInit - Initializes the Cisco 340/350 card into a known state. ** Initializes the card. If the card fails the init sequence an error is * returned.* * RETURNS : OK if successful, ERROR if a null pointer is passed in or if* the card could be not correctly initialized. ** ERRNO : N/A** SEE ALSO:* Cisco Aironet 340/350 Driver Programmer's Manual*/STATUS cisAironetHwInit ( CARD_CTRL_T * pDev /* Pointer to the device handle for this card */ ) { UINT8* pBuf; CFG_RID_T cfg; CFG_RID_T * pCfg = (CFG_RID_T *) &cfg; ANET_SSID_T * pSsid = (ANET_SSID_T *) &ssidList.ssids[0]; CAP_RID_T cap; CAP_RID_T * pCap = (CAP_RID_T *) ∩ INT16 powerSave; INT16 authType; INT32 count = 0; UINT8 rate = 0; INT16 basicRatesStatus; char manufacturer[32]; char product[16]; UINT8 rates[8]; /* Sanity check */ if (pDev == NULL) { ANET_DEBUG(DEBUG_ERROR, ("cisAironetHwInit: Error NULL pointer\n")); return (ERROR); } /* Save the pointer to the mac base address */ pDev->macReg = (ANET_ACCESS_T *) pDev->ioBase; /* Disable the Mac before rids are accessed */ if ( cisAironetHwMacDisable (pDev) == ERROR ) { return (ERROR); } /* Init the card */ if ( cisAironetHwCardInit(pDev) == ERROR ) { return (ERROR); } /* Get the card capabilities RID */ if ( cisAironetHwRidCapGet (pDev, (void *) pCap) == ERROR ) { ANET_DEBUG(DEBUG_ERROR, ("cisAironetCapShow: Error reading CAP RID\n")); return (ERROR); } /* Get manufacturer and model info */ (void) cisAironetBcopy (pDev, (const UINT8 *) pCap->manName, (UINT8 *) manufacturer, NELEMENTS(pCap->manName)); (void) cisAironetBcopy (pDev, (const UINT8 *) pCap->prodName, (UINT8 *) product, NELEMENTS(pCap->prodName)); /* Print out status message */ ANET_DEBUG(DEBUG_ERROR, ("cisAironetInit: Detected WLAN card - %s %s\n", manufacturer, product)); /* Check for correct firmware */ if ( pCap->softVer < ANET_FIRMWARE_VERSION ) { ANET_DEBUG(DEBUG_ERROR, ("cisAironetInit: WARNING!\n")); ANET_DEBUG(DEBUG_ERROR, ("cisAironetInit: Card firmware is version: " "%s\n", pCap->prodVer)); ANET_DEBUG(DEBUG_ERROR, ("cisAironetInit: Supported firmware is " "minimum version: %s\n", ANET_FIRMWARE_STRING)); } /* Save the cards mac address */ if ( cisAironetHwMacAddrGet (pDev) == ERROR ) { return (ERROR); } /* Get the card config RID */ if ( cisAironetHwRidConfigGet (pDev, (void *) pCfg) == ERROR ) { return (ERROR); } /* Get the byte ordering */ (void) sysWlanCfgParamGet (WLAN_BYTE_ORDER, (INT32) &pDev->byteOrder); /* Enable aironet extensions */ pCfg->opmode |= ANET_MODE_AIRONET_EXTEND; /* Get the station mode (IBSS or BSS) and write to config RID */ (void) sysWlanCfgParamGet (WLAN_STATION_MODE, (INT32) &pCfg->opmode); pDev->ibssMode = (pCfg->opmode == WLAN_IBSS_MODE); /* If IBSS mode is selected, then set the channel in the config RID */ if (cfg.opmode == WLAN_IBSS_MODE) { (void) sysWlanCfgParamGet (WLAN_CHANNEL, (INT32) &pCfg->dsChannel); } /* Get the encryption mode (WEP enabled or disabled) */ (void) sysWlanCfgParamGet (WLAN_WEP_ENABLE, (INT32) &pDev->wepEnable); /* Get the wep type (40 or 128 bit) encryption */ (void) sysWlanCfgParamGet (WLAN_WEP_TYPE, (INT32) &pDev->wepType); /* Get authentication type (open or shared key) */ (void) sysWlanCfgParamGet (WLAN_AUTH_TYPE, (INT32) &authType); if (authType != WLAN_AUTHENTICATION_ANY) /* _ANY not supported */ { pCfg->authType = authType; /* set the config RID */ pDev->authType = authType; } /* Check to see if wep is enabled */ if (pDev->wepEnable == WLAN_WEP_ENABLED) { UINT8* key = NULL; UINT8 keySize = 0; /* Allocate a buffer and get the default key */ if (pDev->wepType == WLAN_WEP_TYPE_128) { /* alloc a temp buffer */ key = (UINT8*) calloc (1, DOT11_128_BIT_KEY_SIZE); /* Save the key size */ keySize = DOT11_128_BIT_KEY_SIZE; /* Get the default 128 bit wep key */ (void) sysWlanCfgParamGet (WLAN_WEP_KEY0_128, (INT32) key); } else { /* alloc a temp buffer */ key = (UINT8*) calloc (1, DOT11_40_BIT_KEY_SIZE); /* Save the key size */ keySize = DOT11_40_BIT_KEY_SIZE; /* Get the default 40 bit wep key */ (void) sysWlanCfgParamGet (WLAN_WEP_KEY0_64, (INT32) key); } /* Set up the WEP key to be used for transmit */ if ( cisAironetHwWepKeySet (pDev, (char *) key, cisAironetHwWepKeyGet (pDev, ANET_TX_KEY), keySize, FALSE) == ERROR ) { ANET_DEBUG(DEBUG_FATAL, ("cisAironetHwInit: error setting wep key\n")); return (ERROR); } /* Enable wep on the card */ pCfg->authType |= ANET_WEP_ENABLE; /* Save the wep key to the driver control structure */ (void) bcopy ((char *)key, (char *) pDev->wepKey[0], keySize); /* free up the memory */ free (key); } /* Get the basic rates status (enabled/disabled, only used in AP mode) */ (void) sysWlanCfgParamGet (WLAN_BRATES_ENABLE, (INT32) &basicRatesStatus); /* If basic rates enabled, save the OR'd bitmask of basic rates */ if (basicRatesStatus == WLAN_BRATES_ENABLED) { (void) sysWlanCfgParamGet (WLAN_BRATES_ENABLE, (INT32) &pDev->basicRates); } else { pDev->basicRates = 0; } /* Get supported data rates as an OR'd bitmask (used in STA mode) */ (void) sysWlanCfgParamGet (WLAN_TX_RATE, (INT32) &pDev->txRate); /* Parse the basic and/or supported rates */ if (pDev->txRate & WLAN_1_MBIT) /* 1 MBit */ { rate = 0x02; if (pDev->basicRates & WLAN_1_MBIT) { rate |= ANET_BASIC_RATE_SET; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -