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

📄 hwacproc.c

📁 marvell8385 GSPI开发驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
/******************* ?Marvell Semiconductor, Inc., 2001-2004 *****************
 *
 *  Purpose:    This module has implmentation of station command 
 *              processing functions
 *
 *  $Author: heb $
 *
 *  $Date: 2007/07/13 08:01:35 $
 *
 *  $Revision: 1.14.2.8 $
 *
 *****************************************************************************/

/*
===============================================================================
                                 INCLUDE FILES
===============================================================================
*/

#include "precomp.h"
//////////////added by zhangb////////////////
#include "ParaRoamingProc.h"
#include "If.h"
//////////////added by zhangb////////////////
#include "logmain.h"
DWORD  g_AssociationDuration = 0;

/*
===============================================================================
                                 CLOBAL CONSTANT
===============================================================================
*/
#ifdef DEBUG_PARA_ROAMING
extern PRIVATE_PARAROAMING_ADAPTER priv;
extern void wlan_RMMLinkLost(IN PMRVDRV_ADAPTER adapter);
#endif
extern ULONG DSFeqList[];
extern USHORT RegionCodeToIndex[MRVDRV_MAX_REGION_CODE];
extern UCHAR IEEERegionChannel[MRVDRV_MAX_REGION_CODE][MRVDRV_MAX_CHANNEL_NUMBER];

//static 
    NDIS_STATUS Deactivate_Host_Sleep_Cfg(PMRVDRV_ADAPTER Adapter);
/*
===============================================================================
                           CODED PUBLIC PROCEDURES
===============================================================================
*/

UCHAR EAPOLStartPacket[] = { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // dest
                             0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // src
                             0x88, 0x8e, 0x01, 0x01, 0x0, 0x0, 0x0 }; 



#ifdef AUTO_REASSOCIATION
/*
    return: 1 - Reassociation has been started OK.
               0 - Reassociation has not been started.
*/
UINT StartReassociation( IN PMRVDRV_ADAPTER pAdapter, IN UINT uIntCode )
{
    UINT    nRetCode = 0;
    BOOLEAN timerStatus;
    DBGPRINT( DBG_MACEVENT, ("+ StartReassociation\n") );

#ifdef CONFIG_WLAN_PMU
#ifndef DEBUG_PARA_ROAMING
    wlan_PMULinkStatusIndicator(1);
#endif
#endif
	NdisMCancelTimer(&Adapter->MrvDrvRssiHighTimer, &timerStatus);
    if ( pAdapter->ReAssociationInProgress )
    {
        DBGPRINT( DBG_MACEVENT, ("  Still in reassociating\n") );
        nRetCode = 1;
    }
    else if ( pAdapter->MediaConnectStatus == NdisMediaStateConnected )
    {       
        if ( pAdapter->WPAEnabled == FALSE )
        {
            DBGPRINT( DBG_MACEVENT, ("    Invoked reassociation\n") );
            DBGPRINT( DBG_MACEVENT, ("    tick=%d\n", GetTickCount()) );
            pAdapter->ReAssociationInProgress = TRUE;
            pAdapter->bIsSendCmdImterSet = TRUE;
            pAdapter->uCurrentRetryForReassociation = 0;
            NdisMCancelTimer(&pAdapter->MrvDrvSendCmdTimer, &timerStatus);
            NdisMSetTimer( &pAdapter->MrvDrvSendCmdTimer, pAdapter->uDelayForReAssociation );
            nRetCode = 1;
        }
        else
        {
            DBGPRINT( DBG_MACEVENT, ("    WPA is enabled, driver doesn't support reassociation currently\n") );
            nRetCode = 0;
        }
    }
    else if ( pAdapter->MediaConnectStatus == NdisMediaStateDisconnected )
    {
        DBGPRINT( DBG_MACEVENT, ("  Media state is disconnected\n") );
        nRetCode = 0;
    }else
        nRetCode = 0;

    DBGPRINT( DBG_MACEVENT, ("- StartReassociation [%d]\n", nRetCode) );

    return nRetCode;
}

/*
    return: 1 - Send out (Re)Assoc(Ext) command successfully.
               0 - Others.
*/
UINT DoReAssociation( IN PMRVDRV_ADAPTER pAdapter )
{
    UINT            nRetCode = 0;
    UCHAR           nIndex;
    NDIS_STATUS     nStatus;
    NDIS_WLAN_BSSID_EX      *pCurrentBssid;
    UCHAR           ucScanCmdEnd, ucScanCmdStart;
    BOOLEAN timerStatus;
    
    DBGPRINT( DBG_MACEVENT, ("+ DoReAssociation\n") );

    ucScanCmdEnd = ( (pAdapter->CurCmd->Pad[2] & MRVDRV_SCAN_CMD_END) ? 1 : 0 );
    ucScanCmdStart = ( (pAdapter->CurCmd->Pad[2] & MRVDRV_SCAN_CMD_START) ? 1 : 0 );
    
    if ( ucScanCmdStart || ((ucScanCmdEnd==0 && pAdapter->ulNumOfBSSIDs==0)) )
    {
        DBGPRINT( DBG_MACEVENT, ("    SCAN is still in progress, skip this\n") );
        DBGPRINT( DBG_MACEVENT, ("- DoReAssociation\n") );
        return 0;
    }

    pCurrentBssid = &(pAdapter->BSSIDList[pAdapter->ulCurrentBSSIDIndex]);

//  nIndex = FindBSSIDInList( pAdapter, pAdapter->CurrentBSSID );
    nIndex = FindSSIDInList( pAdapter, &(pAdapter->CurrentSSID) );
    DBGPRINT( DBG_MACEVENT, ("    tick=%d\n", GetTickCount()) );

    if ( nIndex == 0xff )
    {
        DBGPRINT( DBG_MACEVENT, ("    Total number of BSSIDs is %d\n", pAdapter->ulNumOfBSSIDs) );
        DBGPRINT( DBG_MACEVENT, 
            ("    Could NOT find the current BSSID, reassociation is failed [BSSID: %x:%x:%x:%x:%x:%x]\n",
               pAdapter->CurrentBSSID[0], 
               pAdapter->CurrentBSSID[1], 
               pAdapter->CurrentBSSID[2], 
               pAdapter->CurrentBSSID[3],
               pAdapter->CurrentBSSID[4],
               pAdapter->CurrentBSSID[5] ) );

        if ( ucScanCmdEnd )
        {
            pAdapter->uCurrentRetryForReassociation ++;
            if ( pAdapter->uCurrentRetryForReassociation < pAdapter->uRetryForReassociation )
            {
                DBGPRINT( DBG_MACEVENT, ("    Retry reassociation [%d/%d]\n", pAdapter->uCurrentRetryForReassociation, pAdapter->uRetryForReassociation) );
                NdisMCancelTimer(&pAdapter->MrvDrvSendCmdTimer, &timerStatus);
                NdisMSetTimer( &pAdapter->MrvDrvSendCmdTimer, pAdapter->uDelayForReAssociation );
            }
            else
            {
                DBGPRINT( DBG_MACEVENT, ("   Reassociation is failed, stop it and indicate disconnection\n") );
                pAdapter->ReAssociationInProgress = FALSE;
                MacEventDisconnected( pAdapter, pAdapter->TimerInterval, FALSE);
				  WriteCommonLogFile(WIFI_LOG,"AP is disconnected(Reason=3)  (DoReAssociation)!...\r\n",
				  strlen("AP is disconnected(Reason=3)  (DoReAssociation)!...\r\n"));	
				  if(g_AssociationDuration != 0)
				  {
					char logstr[200];
					sprintf(logstr,"Association Duration is %d seconds\r\n", (GetTickCount() - g_AssociationDuration)/1000);
					WriteCommonLogFile(WIFI_LOG,logstr, strlen(logstr));
					g_AssociationDuration = 0;
				  }
            }
        }
    }
    else
    {
        DBGPRINT( DBG_MACEVENT, ("    Found the current BSSID\n") );

        if ( pAdapter->InfrastructureMode == Ndis802_11Infrastructure )
        {
            DBGPRINT( DBG_MACEVENT, ("    Send out AssociateExt for ReAssociation\n") );

            nStatus = PrepareAndSendCommand(
                        pAdapter,
                        HostCmd_CMD_802_11_ASSOCIATE_EXT,
                        0,
                        HostCmd_OPTION_USE_INT,
                        (NDIS_OID)0,
                        HostCmd_PENDING_ON_NONE,
                        0,
                        FALSE,
                        NULL,
                        NULL,
                        NULL,
                        &(pAdapter->CurrentSSID));
        }
        else if ( pAdapter->InfrastructureMode == Ndis802_11IBSS )
        {
            DBGPRINT( DBG_MACEVENT, ("    Send out AdHocJoin\n") );
            
            nStatus = PrepareAndSendCommand(
                        pAdapter,
                        HostCmd_CMD_802_11_AD_HOC_JOIN,
                        0, 
                        HostCmd_OPTION_USE_INT,
                        (NDIS_OID) 0,
                        HostCmd_PENDING_ON_CMD,
                        0, FALSE,
                        NULL, NULL, NULL,
                        &(pAdapter->CurrentSSID));
        }
        else
        {
            DBGPRINT( DBG_MACEVENT, ("    WRONG InfrastructureMode!!!\n") );
            nStatus = NDIS_STATUS_SUCCESS + 1; //Set to a NON-success
        }

        if ( NDIS_SUCCESS( nStatus ) )
        {
            DBGPRINT( DBG_MACEVENT, ("    -> OK\n") );
            nRetCode = 1;
        }
        else
        {
            DBGPRINT( DBG_MACEVENT, ("    -> Failed\n") );
            nRetCode = 0;
        }

        if ( pAdapter->WEPStatus == Ndis802_11WEPEnabled
            || pAdapter->AuthenticationMode == Ndis802_11AuthModeShared ) 
        {
            DBGPRINT( DBG_MACEVENT, ("    Set wep key\n") );

            // TODO: Need to do more tests for this block. Do we need OID_802_11_ADD_WEP (pendding OID)?
            
            nStatus = PrepareAndSendCommand(
                        pAdapter, 
                        HostCmd_CMD_802_11_SET_WEP,
                        0, 
                        HostCmd_OPTION_USE_INT,
                        OID_802_11_ADD_WEP,
                        HostCmd_PENDING_ON_CMD,
                        0, FALSE,
                        NULL, NULL, NULL,
                        &pAdapter->CurrentWEPKey);

            if ( NDIS_SUCCESS( nStatus ) )
            {
                DBGPRINT( DBG_MACEVENT, ("    -> OK\n") );
                nRetCode = 1;
            }
            else
            {
                DBGPRINT( DBG_MACEVENT, ("    -> Failed\n") );
                nRetCode = 0;
            }

        }
    } // if ( nIndex == 0xff )

    if ( nRetCode )
        pAdapter->ReAssociationInProgress = FALSE;

    DBGPRINT( DBG_MACEVENT, ("- DoReAssociation\n") );

    return nRetCode;
}

#endif // AUTO_REASSOCIATION



#ifdef ADHOCAES
VOID
HandleAdhocAES( IN PMRVDRV_ADAPTER Adapter,
          IN PHostCmd_DS_802_11_PWK_KEY pKeyReturn,
          IN PVOID info,
          IN PULONG BytesWritten
          )

{   
  PMRVL_ADHOC_AES_KEY pKey;
  
  pKey = (PMRVL_ADHOC_AES_KEY)info;
  pKey->Length = 16;  
  NdisMoveMemory(pKey->KeyBody, pKeyReturn->TkipEncryptKey, 16);
  *BytesWritten = 16 + 4;

  return ;
}
#endif
/******************************************************************************



/******************************************************************************
 *
 *  Name: HandleMicError()
 *
 *  Description: handle MIC error
 *
 *  Arguments:  PMRVDRV_ADAPTER Adapter
 *        UINT ErrorType
 *    
 *  Return Value:        
 * 
 *  Notes:               
 *
 *****************************************************************************/

VOID
HandleMicError(
               IN PMRVDRV_ADAPTER Adapter, 
             IN UINT ErrorType)
{
    WPA_NOTIFY_OS   message;
    ULONG           ulCurrTime;
    ULONG           ulTimeDiff;

    NdisZeroMemory(&message, sizeof(WPA_NOTIFY_OS));
    NdisMoveMemory(message.request.Bssid, Adapter->CurrentBSSID, 
                sizeof(Adapter->CurrentBSSID));
    message.request.Length = sizeof(NDIS_802_11_AUTHENTICATION_REQUEST);
    message.status = Ndis802_11StatusType_Authentication;
    
    switch (ErrorType)
    {

    case MACREG_INT_CODE_WPA_MIC_ERR_UNICAST:
        message.request.Flags = NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR;
        DBGPRINT(DBG_WARNING, ("Pairwise MIC Error!\n"));
        break;

    case MACREG_INT_CODE_WPA_MIC_ERR_MULTICAST:
        message.request.Flags = NDIS_802_11_AUTH_REQUEST_GROUP_ERROR;
        DBGPRINT(DBG_WARNING, ("Groupwise MIC Error!\n"));
        break;

    default:
        DBGPRINT(DBG_ERROR, ("HandleMicError(): do not know how to handle error code 0x%x!\n",
                            ErrorType));
        // skip the indication
        return;
    }

    NdisMIndicateStatus(Adapter->MrvDrvAdapterHdl,
                        NDIS_STATUS_MEDIA_SPECIFIC_INDICATION,
                        &message,
                        sizeof(WPA_NOTIFY_OS));
    NdisMIndicateStatusComplete(Adapter->MrvDrvAdapterHdl);
    DBGPRINT(DBG_WARNING, ("Indicated MIC error!\n"));
#ifdef DEBUG_PARA_ROAMING_PRINT
	RETAILMSG(1,(TEXT("Indicated MIC error!!...\n")));
#endif
    NdisGetSystemUpTime(&ulCurrTime);
    
    if ( ulCurrTime > Adapter->ulLastMICErrorTime )
    {
        ulTimeDiff = ulCurrTime - Adapter->ulLastMICErrorTime;
    }
    else
    {
        ulTimeDiff = 0xFFFFFFFF - Adapter->ulLastMICErrorTime + ulCurrTime;
    }

    NdisMSleep(20000);
    
    if ( (Adapter->ulLastMICErrorTime != 0) && (ulTimeDiff < MRVDRV_MIC_ERROR_PERIOD) )
    {   
        USHORT          usCommand;

       
        if ( Adapter->InfrastructureMode == Ndis802_11Infrastructure )
        {
            usCommand = HostCmd_CMD_802_11_DEAUTHENTICATE;
        }
        else
        {
            usCommand = HostCmd_CMD_802_11_AD_HOC_STOP;
        }

        // completely clean up
        PrepareAndSendCommand(
                  Adapter,
                  usCommand,
                  0,
                  HostCmd_OPTION_USE_INT,
                  0,
                  HostCmd_PENDING_ON_NONE,
                  0,
                  FALSE,
                  NULL,
                  NULL,
                  NULL,
                  NULL);

⌨️ 快捷键说明

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