⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utility.c

📁 mx27 f14v2 源代码。包括ADS板上诸多驱动的源码。
💻 C
📖 第 1 页 / 共 2 页
字号:
//---------------------------------------------------------------------------
// Copyright (C) 2006, Freescale Semiconductor, Inc. All Rights Reserved.
// THIS SOURCE CODE, AND ITS USE AND DISTRIBUTION, IS SUBJECT TO THE TERMS
// AND CONDITIONS OF THE APPLICABLE LICENSE AGREEMENT 
//--------------------------------------------------------------------------
//
// File:  utility.c
// Source file for platform specific SDIO WLAN functions
//------------------------------------------------------------------------------


/*************************************************************************/
/***                      Included Header Files                          */
/*************************************************************************/

#include "precomp.h"


/*************************************************************************/
/***                     #defines, constants, ...                        */
/*************************************************************************/


/*************************************************************************/
/***                   Type definitions                                  */
/*************************************************************************/


/*************************************************************************/
/***                 Static function prototypes                          */
/*************************************************************************/


/*************************************************************************/
/***                Global variable definitions                          */
/*************************************************************************/


/*************************************************************************/
/***                File scope static variable definitions               */
/*************************************************************************/

// CE doesn't support WPA2
STATIC NDIS_802_11_AUTHENTICATION_ENCRYPTION sDriverAuthEncCapabilities[] =
{{Ndis802_11AuthModeOpen,    Ndis802_11EncryptionDisabled}, // No encryption
 {Ndis802_11AuthModeOpen,    Ndis802_11Encryption1Enabled}, // WEP
 {Ndis802_11AuthModeWPA,     Ndis802_11Encryption2Enabled}, // WPA TKIP
 {Ndis802_11AuthModeWPA,     Ndis802_11Encryption3Enabled}, // WPA AES CCMP
 {Ndis802_11AuthModeWPAPSK,  Ndis802_11Encryption2Enabled}, // WPAPSK TKIP
 {Ndis802_11AuthModeWPAPSK,  Ndis802_11Encryption3Enabled}, // WPAPSK AES
 {Ndis802_11AuthModeWPA2,    Ndis802_11Encryption2Enabled}, // WPA2 TKIP
 {Ndis802_11AuthModeWPA2,    Ndis802_11Encryption3Enabled}, // WPA2 AES
 {Ndis802_11AuthModeWPA2PSK, Ndis802_11Encryption2Enabled}, // WPA2PSK TKIP
 {Ndis802_11AuthModeWPA2PSK, Ndis802_11Encryption3Enabled}};// WPA2PSK AES

/*************************************************************************/
/***                Public function definitions                          */
/*************************************************************************/

/*****************************************************************************
**
** NAME         vENDInitializeWLAN
**
** PARAMETERS   psWlan     Pointer to WLAN context.
**          psCFG    Pointer to Configuration context.
**
** DESCRIPTION  This function initializes WLAN block based on the 
**          configurations and hardware default settings.
**
******************************************************************************/
VOID
vENDInitializeWLAN( OUT PWLAN_CONTEXT psWlan, IN PCFG_CONTEXT psCFG )
{
    USHORT  usChannel;

    // Get BSSID from configuration.
    vCFGgetBSSIDandChannel( psCFG, (IEEE_ADDR *)psWlan->ucBSSID, &usChannel );

    // Get SSID from configuration.
    psWlan->sSSID.SsidLength = psCFG->sESSID.u8Length;
    OS_MEMCPY( psWlan->sSSID.Ssid, psCFG->sESSID.acESSID, psCFG->sESSID.u8Length );

    // Network types support: 802.11b, 802.11a and 802.11g.
    psWlan->ulNumOfNetworkType = 3;
    psWlan->ulNetworkType[0] = Ndis802_11DS;
    psWlan->ulNetworkType[1] = Ndis802_11OFDM5;
    psWlan->ulNetworkType[2] = Ndis802_11OFDM24;

    // Network type in use.
    if ( psCFG->eProtocolType == CFG_80211A )
    {
        psWlan->ulNetworkTypeInUse = Ndis802_11OFDM5;
    }
    else if ( psCFG->eProtocolType == CFG_80211B )
    {
        psWlan->ulNetworkTypeInUse = Ndis802_11DS;
    }
    else
    {
        psWlan->ulNetworkTypeInUse = Ndis802_11OFDM24;
    }

    // Default supported rates and desired rates.
    vENDsetDefaultRateSet( psWlan->ulNetworkTypeInUse, psWlan->ucSupportedRates, psWlan->ucDesiredRates );

    // Infrastructure mode.
    if ( psCFG->eNetworkType == CFG_ADHOC_STATION )
        psWlan->ulInfraMode = Ndis802_11IBSS;
    else
        psWlan->ulInfraMode = Ndis802_11Infrastructure;

    // Fragmentation threshold.
    psWlan->ulFragmentThreshold = psCFG->usFragmentThreshold;

    // RTS threshold.
    psWlan->ulRTSThreshold = psCFG->usRTSCTSThreshold;

    // Number of antennas and Rx, Tx antenna selected.
    psWlan->ulNumOfRxAntennas = 2;
    psWlan->ulNumOfTxAntennas = 2;
    psWlan->ulRxAntennaSelected = 0xffffffff;
    psWlan->ulTxAntennaSelected = 0xffffffff;

    // Radio configuration.
    psWlan->sRadioConfig.Length = sizeof( NDIS_802_11_CONFIGURATION );
    //   psWlan->sRadioConfig.BeaconPeriod = psCFG->usBeaconPeriod;

    psWlan->sRadioConfig.ATIMWindow = 4;        // default 4 ms
    // vENDgetChannelFrequency( usChannel, &psWlan->sRadioConfig.DSConfig );

    // Power mode.
    if ( boCFGisPowerSavingEnabled( psCFG ) )
        psWlan->ulPowerMode = Ndis802_11PowerModeMAX_PSP;
    else
        psWlan->ulPowerMode = Ndis802_11PowerModeCAM;

    // Authentication mode.
    OS_MEMZERO(psWlan->auth_params, 11*sizeof(UINT));
    psWlan->auth_params[IW_AUTH_WPA_VERSION] = IW_AUTH_WPA_VERSION_DISABLED;
    psWlan->auth_params[IW_AUTH_CIPHER_PAIRWISE] = IW_AUTH_CIPHER_NONE;
    psWlan->auth_params[IW_AUTH_CIPHER_GROUP] = IW_AUTH_CIPHER_NONE;
    psWlan->auth_params[IW_AUTH_80211_AUTH_ALG] = IW_AUTH_ALG_OPEN_SYSTEM;

    psWlan->encoding_enabled = FALSE;
	  // modify
	  DBG_LEV1(("configure Capability.\n"));
    psWlan->sDriverCapability.Version = DRIVER_OID_802_11_CAPABILITY_VERSION;
    // Must claim to support between 3 and 16 PMKIDs to make XP happy
    psWlan->sDriverCapability.NoOfPMKIDs = 0;   
    OS_MEMCPY(psWlan->sDriverCapability.AuthenticationEncryptionSupported,
              sDriverAuthEncCapabilities,
              sizeof(sDriverAuthEncCapabilities));
    // Calculate number of entries in above array
    psWlan->sDriverCapability.NoOfAuthEncryptPairsSupported =
        (sizeof(sDriverAuthEncCapabilities) /
         sizeof(NDIS_802_11_AUTHENTICATION_ENCRYPTION));
    psWlan->sDriverCapability.Length =
        FIELD_OFFSET(NDIS_802_11_CAPABILITY, AuthenticationEncryptionSupported) +
        (psWlan->sDriverCapability.NoOfAuthEncryptPairsSupported *
         sizeof(NDIS_802_11_AUTHENTICATION_ENCRYPTION));



    // Short preamble.
    psWlan->boShortPreamble = psCFG->boShortPreamble;

    // UWA Sensitivity Lockout.
    psWlan->boUwaSensLockout = psCFG->boUwaSensLockout;

    // Commasic config info
    // MAC address
    psWlan->ucMacAddr[0] = psCFG->sMACID.au8Addr[0];
    psWlan->ucMacAddr[1] = psCFG->sMACID.au8Addr[1];
    psWlan->ucMacAddr[2] = psCFG->sMACID.au8Addr[2];
    psWlan->ucMacAddr[3] = psCFG->sMACID.au8Addr[3];
    psWlan->ucMacAddr[4] = psCFG->sMACID.au8Addr[4];
    psWlan->ucMacAddr[5] = psCFG->sMACID.au8Addr[5];

    // Forced rate
    psWlan->ulForcedRate = psCFG->eRateSelect;

    // Listen interval
    psWlan->ulListenInterval = psCFG->usListenInterval;

    // Restricted channel
    psWlan->ulRestrChannel = psCFG->usChannel;

    psWlan->boBGIbss54g = psCFG->boIbss54g;


    // Ibss channel
    psWlan->ulIbssChannel = psCFG->usIbssChannel;


    // Regulatory Domain
    psWlan->ulRegDomain = psCFG->eDomain;


    // Radio setting.
    psWlan->boDesiredRadio = psCFG->boRadio;
    psWlan->boRadioOn = TRUE;

    // Media Stream Mode
    psWlan->ulMediaStreamModeInUse = Ndis802_11MediaStreamOff;
  
    if ( psCFG->eProtocolType == CFG_80211A ){
    	psWlan->sBckGrndScanConfig.ulCamScanInterval = psCFG->ulCamBckGrndScanInterval80211a;
    	psWlan->sBckGrndScanConfig.ulPsScanInterval = psCFG->ulPsBckGrndScanInterval80211a;
    }
    else{
	psWlan->sBckGrndScanConfig.ulCamScanInterval = psCFG->ulCamBckGrndScanInterval80211bg;
	psWlan->sBckGrndScanConfig.ulPsScanInterval = psCFG->ulPsBckGrndScanInterval80211bg;    	
    }

    
    psWlan->boMultiDomainCapabilityEnabled = psCFG->boMultiDomainCapabilityEnabled;
    psWlan->boRadioMeasurementCapabilityEnabled = psCFG->boRadioMeasurementCapabilityEnabled;
    psWlan->boCcxCapabilityEnabled = psCFG->boCcxCapabilityEnabled;

    psWlan->boBluetoothCoexCapabilityEnabled = psCFG->boBluetoothCoexCapabilityEnabled;



    // Backup and check domain and channel settings.
    psWlan->ulARestrChannel = psWlan->ulRestrChannel;
    psWlan->ulAIbssChannel = psWlan->ulIbssChannel;
    psWlan->ulARegDomain = psWlan->ulRegDomain;
    psWlan->ulBGRestrChannel = psWlan->ulRestrChannel;
    psWlan->ulBGIbssChannel = psWlan->ulIbssChannel;
    psWlan->ulBGRegDomain = psWlan->ulRegDomain;
    vENDcheckDomainChannel( psWlan->ulNetworkTypeInUse, &psWlan->ulRegDomain, 
                            &psWlan->ulRestrChannel, &psWlan->ulIbssChannel );
}


/*****************************************************************************
**
** NAME         vENDcheckDomainChannel
**
** PARAMETERS   ulProtocolType      802.11a, 802.11b or 802.11g mode.
**              pulDomain           Pointer to domain setting.
**              pulChannel          Pointer to restricted channel setting.
**              pulIbssChannel      Pointer to IBSS channel setting.
**
** DESCRIPTION  This function checks domain setting according to protocol type 
**              and checks channel and IBSS channel settings according to 
**              protocol type and domain. Set default value if not available.
**
******************************************************************************/
VOID
vENDcheckDomainChannel( IN ULONG ulProtocolType, IN OUT PULONG pulDomain, 
                        IN OUT PULONG pulChannel, IN OUT PULONG pulIbssChannel )
{

/* 
 * CM00001500: Sario fixed the China domain bug. 
 * FIXME: China domain should be 0x51. you can reference from 18.4.6.
 * 
 */
#define END_BG_DOMAIN_NUMBER    8 
#define END_A_DOMAIN_NUMBER     6
    // B/G mode domain-channel table.
    END_CHANNEL_SET sBGChannelSet[END_BG_DOMAIN_NUMBER] = {
        { 0x10, 11, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
        { 0x20, 11, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
        { 0x30, 13, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
        { 0x31, 2,  {10, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
        { 0x32, 4,  {10, 11, 12, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
        { 0x40, 1,  {14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
        { 0x41, 13, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} }, 
        /* CM00001500: Sario fixed the China domain bug. */
        { 0x70, 13, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} } 
    };
    // A mode domain-channel table.
    END_CHANNEL_SET sAChannelSet[END_A_DOMAIN_NUMBER] = {
        { 0x10, 24, {36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165} },
        { 0x20, 24, {36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165} },
        { 0x30, 19, {36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 0, 0, 0, 0, 0} },
        { 0x40, 9,  {7, 8, 9, 11, 12, 34, 38, 42, 46, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
        { 0x41, 9,  {7, 8, 9, 11, 12, 34, 38, 42, 46, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} },
        { 0x70, 1,  {145, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} } };
    PEND_CHANNEL_SET    psChannelSet;
    ULONG   i, j, ulMax;

    if ( ulProtocolType == Ndis802_11OFDM5 )
    {
        ulMax = END_A_DOMAIN_NUMBER;
        psChannelSet = &sAChannelSet[0];
    }
    else
    {
        ulMax = END_BG_DOMAIN_NUMBER;
        psChannelSet = &sBGChannelSet[0];
    }

    // Check domain setting, default FCC 0x10.
    for ( i=0; i<ulMax; i++ )
    {
        if ( psChannelSet[i].ulDomain == *pulDomain )
            break;
    }
    if ( i >= ulMax )
    {
        i = 0;
        *pulDomain = 0x10;
    }

    // Check channel setting, default 0 (auto).
    if ( *pulChannel != 0 )
    {
        for ( j=0; j<psChannelSet[i].ulChannelNum; j++ )
        {
            if ( psChannelSet[i].ulChannelList[j] == *pulChannel )
                break;
        }
        if ( j >= psChannelSet[i].ulChannelNum )
            *pulChannel = 0;
    }

    // For ad-hoc mode, channels 52-140 are not allowed.
    if ( *pulIbssChannel >= 52 && *pulIbssChannel <= 140 )
        *pulIbssChannel = 0;

    // Check IBSS channel setting, default 0 (auto).
    if ( *pulIbssChannel != 0 )
    {
        for ( j=0; j<psChannelSet[i].ulChannelNum; j++ )
        {
            if ( psChannelSet[i].ulChannelList[j] == *pulIbssChannel )
                break;
        }
        if ( j >= psChannelSet[i].ulChannelNum )
            *pulIbssChannel = 0;
    }
}


/*****************************************************************************
**
** NAME         vENDgetChannelFrequency
**
** PARAMETERS   ulChannelFreq    Channel number or frequency.
**          pulFreqChannel    Pointer to frequency or channel number.
**
** DESCRIPTION  This function returns frequency value of specified channel 
**          or channel number of specified frequency.
**
******************************************************************************/
VOID
vENDgetChannelFrequency( IN ULONG ulChannelFreq, OUT PULONG pulFreqChannel )
{
    // Number of channel-frequency pairs in table.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -