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

📄 cardx500.cpp

📁 WinCE5.0部分核心源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        //
        //StoreHostActiveInterrupts(card);
        //card->m_IntActive &= ~(EVNT_DO_SLEEP | EVNT_DO_WAKEUP);

    } while(0 && card->m_IntActive && card->m_IntActive != ~(EVNT_DO_SLEEP | EVNT_DO_WAKEUP) );

    if( card->m_MaxPSP && 0==card->KeepAwake )
        cmdSleep(card);

    EnableHostInterrupts(card);     // enable
}

//------------------------------------------------------------------
void UpdateLinkSpeed (PCARD card)
{
    // 
    // Added this to stop "jerkiness" when in MaxPSP mode (jmb 11/28/00)
    // 
    if( ! card->IsAwake )
        return;

    STSTATUS    status;
    if( ! cmdStatusGet(card, &status ) )
        return;                         
//    ULONG   LinkSpeed = status.LinkSpeed & 0xFF;
    // 
    // field name changed from status.LinkSpeed to status.u16CurrentTxRate
    // 
    ULONG   LinkSpeed = status.u16CurrentTxRate & 0xFF;
    card->m_LinkSpeed   = LinkSpeed * 10000 / 2;
}   

//===========================================================================
    void CheckAutoConfig (PCARD card)
//===========================================================================
// 
// Description: Start the auto config damper tick if we're not associated.
//    
//      Inputs: card    - pointer to card structure.
//    
//     Returns: nothing.
//    
//      (10/30/00)
//---------------------------------------------------------------------------
{
    // 
    // See if we're associated.
    // 
    STSTATUS    st;
    BOOLEAN     ret         = cmdStatusGet(card, &st);
    BOOLEAN     associated  = 0x20 & st.u16OperationalMode;
    if (!associated                 && 
        card->m_autoConfigEnabled   && 
        (card->m_numProfiles > 1)) {
        setAutoConfigTimer(card, TRUE);
        }
}

//===========================================================================
    void UpdateLinkStatus (PCARD card)
//===========================================================================
// 
// Description: Updates the Link status whenever a link event interrupt is
//              received.
//    
//      Inputs:  PCARD - pointer to the card structure
//
//     Caveats: Should only be called from within the Interrupt Handler.
//    
//     Returns: None
//
//---------------------------------------------------------------------------
{
    STSTATUS    st;
    BOOLEAN     IsAssociated;
    USHORT      usWord;

    //Use link event register to check for association.
    NdisRawReadPortUshort(card->m_IOBase+REG_LINKSTATUS, &usWord );

    IsAssociated = (0x8000 != (usWord & 0x8000));

    //If we are associated, then we need to get the status for the BSSID
    if (IsAssociated) {
        cmdStatusGet(card, &st);
    }


    #ifdef DEBUG_AUTO_CONFIG
    DbgPrint("Link Status=%x, Operational Mode=%x\n",usWord,st.u16OperationalMode & 0x20);
    #endif

    BOOLEAN  oldAssociation = card->IsAssociated;
    card->IsAssociated  = IsAssociated;

    //  Indicate Link event if: 
    //  a- We associated and we previously indicated to NDIS that we were disconnected
    //  b- We associated to a new BSSID
    //  c- We are disassocaited and the m_MediaDisconnectDamper has expired

    BOOLEAN doIndicate = FALSE;

    if (card->IsAssociated) {
        #ifdef DEBUG_AUTO_CONFIG
        DbgPrint("UpdateLinkStatus: Associated\n");
        #endif

        // Just became associated.  Because of damper, we need to compare current BSSID
        // with the previous BSSID. Indicate connect status if different.  This causes
        // DHCP to renew.
        UINT    result;
        ETH_COMPARE_NETWORK_ADDRESSES_EQ( st.au8CurrentBssid, card->m_BSSID, &result);
        doIndicate = (0 != result) || (NDIS_STATUS_MEDIA_DISCONNECT == card->m_MSenceStatus);

        //Save new BSSID
        //Note:  Per Doug,if we ever get a FF:FF:FF:FF for the BSSID, then there
        //is something wrong in the NIC.  The only time this is possible is after
        //we have disabled/enabled the NIC. Once associated, the status will always
        //indicate the last BSSID the NIC associated to.  Therefore it will never
        //be FFFFFFFFF.        
        NdisMoveMemory(card->m_BSSID, st.au8CurrentBssid, sizeof(MacAddr)); 
 
        card->m_SSID.SsidLength = (st.SSIDlength < 32)?st.SSIDlength:32;
        NdisMoveMemory(card->m_SSID.Ssid,st.SSID,card->m_SSID.SsidLength);
    }
    else {
        //Protect from 2 back to back media disconnects happening (they do happen)
        if (card->IsAssociated != oldAssociation) {
            // We're no longer associated.  Start media disconnect damper tick or send event.
            doIndicate = (0 == card->m_MediaDisconnectDamper);
            card->m_MediaDisconnectDamperTick = card->m_MediaDisconnectDamper;
        }

        #ifdef DEBUG_AUTO_CONFIG
        DbgPrint("UpdateLinkStatus: NOT Associated\n");
        #endif
    }

    // Indicate status based on current association state.
    if (doIndicate) {
        card->m_MSenceStatus = card->IsAssociated ? NDIS_STATUS_MEDIA_CONNECT : NDIS_STATUS_MEDIA_DISCONNECT; 
        NdisMIndicateStatus(card->m_MAHandle, card->m_MSenceStatus, 0, 0);
        NdisMIndicateStatusComplete(card->m_MAHandle);

        #ifdef DEBUG_AUTO_CONFIG
        if (card->IsAssociated)
            DbgPrint("UpdateLinkStatus: Indicating NDIS_STATUS_MEDIA_CONNECT\n");
        else 
            DbgPrint("UpdateLinkStatus: Indicating NDIS_STATUS_MEDIA_DISCONNECT\n");
        #endif
    }
}

void SetPromiscuousMode(PCARD card, ULONG mode)
{
    // called from outside of the INTDPC.
    // nothing changes, do nothing
    if( (mode && card->m_PromiscuousMode) ||
        (!mode && !card->m_PromiscuousMode) )
        return;
        
    card->m_PromiscuousMode = mode;
    
    USHORT param    = mode ? 0xFFFF : card->m_PowerSaveMode;
    
    if( ! card->m_MaxPSP ){

        cmdSetOpMode(card, param);
    }
    else{
        if( 0xFFFF != param )
            param -= 2;

        int     KeepAwake = card->KeepAwake;

        card->KeepAwake = 1;
        cmdAwaken( card, TRUE );        // wait for upto 100 ms 
        cmdSetOpMode(card, param);
        card->KeepAwake = KeepAwake;
    
        if( 0==card->KeepAwake )
            cmdSleep(card);
    }
}

//===========================================================================
    BOOLEAN InitHW (PCARD card)
//===========================================================================
// 
// Description: 
//    
//      Inputs: 
//    
//     Returns: 
//---------------------------------------------------------------------------
{
    card->m_RcvReg  = card->m_IOBase+REG_BAPrx_DATA;
    card->m_XmitReg = card->m_IOBase+REG_BAPtx_DATA;

    if (FALSE == FindCard(card)) {
        LogError( card, NDIS_ERROR_CODE_ADAPTER_NOT_FOUND, 0x00010000 | ADAPTER_NOT_FOUND);
        return FALSE;
        }
    
//  if (0xFFFF != (0xFFFF&card->m_MagicPacketMode)) {
//      InitStatusChangeReg( card );
//      }
    BOOLEAN retval = InitFW(card);
    return retval ? TRUE : card->m_CardFirmwareErr; 
}

//===========================================================================
    void InitStatusChangeReg ( PCARD card )
//===========================================================================
// 
// Description: 
//    
//      Inputs: 
//    
//     Returns: 
//---------------------------------------------------------------------------
{
    int StatusRegOff        = 0x3e2; 
    int PinReplaceRegOff    = 0x3e4; 

#ifndef UNDER_CE
    UCHAR   uChar;
#endif

#if (NDISVER < 5) || (NDISVER == 41)        //spbMgc
    if (card->m_AttribMemRegistered) {
        NdisWriteRegisterUchar(card->m_pAttribMemBase+PinReplaceRegOff, 0x0F);
        DelayMS(50);
        NdisReadRegisterUchar(card->m_pAttribMemBase+StatusRegOff, &uChar);
        NdisWriteRegisterUchar(card->m_pAttribMemBase+StatusRegOff, uChar | 0x40);

#if DBG 
        NdisReadRegisterUchar(card->m_pAttribMemBase+StatusRegOff, &uChar);
#endif
    }
#else
    USHORT uShort=0x0F;
    NdisWritePcmciaAttributeMemory(card->m_MAHandle,PinReplaceRegOff/2,&uShort,1);
    DelayMS(50);
    NdisReadPcmciaAttributeMemory(card->m_MAHandle,StatusRegOff/2,&uShort,1);
    uShort|=0x40;
    NdisWritePcmciaAttributeMemory(card->m_MAHandle,StatusRegOff/2,&uShort,1);

#if DBG 
    USHORT tmp=0;
    NdisReadPcmciaAttributeMemory(card->m_MAHandle,StatusRegOff/2,&tmp,1);
#endif
#endif
}

//===========================================================================
    BOOLEAN InitFW (PCARD card, BOOLEAN useCurrentConfig)
//===========================================================================
// 
// Description: Initialize the radio firmware
//    
//      Inputs: card              - pointer to card structure
//              useCurrentConfig  - set true use re-use the current config info (as in after 
//                                  hibernating). This forces use of the existing config info 
//                                  contained in the card structure rather re-initializing 
//                                  from the registry.  (default = false).
//    
//     Returns: TRUE if successful, FALSE otherwise.
//---------------------------------------------------------------------------
{

/*
: reset elapsed time = 1051 ms
: AckCmdInterrupt elapsed time = 2093 ms
: config elapsed time = 2423 ms
: command elapsed time = 4836 ms
: elapsed time = 4846 ms
: elapsed time = 5187 ms
*/
    card->m_PrevCmdDone     = TRUE;
    card->m_IsPolling       = TRUE;
    card->IsAwake           = TRUE;             
    
    CQReset(card->m_Q);
    CQReset(card->fidQ);
    RESETSTACK();

    //spb001 We need to do this now because of the loadVXD function needs this info
    cmdCapsGet(card, &card->capabilities);
    
    if (0 == strcmp("????????", card->m_CardName)) { 
        RADIOTYPE   *pRt    = RadioTypesArray;
    
        for ( ;pRt->CardName; pRt++) {
            extern USHORT Pci_Dev_Id;
            if (pRt->ProductNum != card->capabilities.ProuctNum) {
                continue;
                }
            strcpy(card->m_CardName, pRt->CardName);
            card->m_FrequencyType   = pRt->FrequencyType;
            card->m_CardType        = pRt->CardType;
            Pci_Dev_Id              = pRt->Pci_Dev_Id;
            break;
            }
        }
        
    if (0 == strcmp(card->m_CardName, "PC2500")) {
        memcpy( card->m_ESS_ID1, card->m_SystemID, sizeof(UINT)); 
        card->m_ESS_IDLen1 = sizeof(UINT);
        }

#ifdef MICROSOFT
    //spb026
    if (!card->wasFlashChecked) {
        card->wasFlashChecked = TRUE;
        if (CheckRev(card)) {
            #if DBG
                DbgPrint("Firmware is old.\n");
            #endif
            card->flashCard=TRUE;
            card->initComplete=TRUE;    //so we fall through
        }
    }
#endif

    //--------------------------------------------------------------------------
    // reset the firmware
    cmdReset(card);

    //This will cause a Link Event Status to be sent up the stack 
    //when we reassociate
    NdisZeroMemory(card->m_BSSID, sizeof(MacAddr)); 

    //This will make sure we send a link down if we don't reassociate
    //MediaDisconnectDamperTick must be greater than 0 for this to happen, hence the check.
    card->m_MediaDisconnectDamperTick = MAX((ULONG)card->m_MediaDisconnectDamper,(ULONG)2);
    card->IsAssociated                = FALSE;

    //spb001 Initialization just started
    if (!card->initComplete) {
        return TRUE;
    }

    return InitFW1(card,useCurrentConfig);
}

//===========================================================================
    BOOLEAN InitFW1 (PCARD card, BOOLEAN useCurrentConfig)
//===========================================================================
// 
// Description: Initialize the radio firmware (Part 2)
//    
//      Inputs: card              - pointer to card structure
//              useCurrentConfig  - set true use re-use the current config info (as in after 
//                                  hibernating). This forces use of the existing config info 
//                                  contained in the card structure rather re-initializing 
//                                  from the registry.  (default = false).
//    
//     Returns: TRUE if successful, FALSE otherwise.
//---------------------------------------------------------------------------
{
    USHORT usWord = 0;

    card->initComplete=TRUE;        //spb001

    //spb023
    DelayMS(1000);
    NdisRawWritePortUshort( card->m_IOBase+REG_CMD, CMD_X500_NOP10 );

    int j;
    for (j = 1000; j && (0 == usWord); j--) {
        NdisRawReadPortUshort(card->m_IOBase+REG_INT_STAT, &usWord);
        usWord &= EVNT_STAT_CMD;
        DelayMS( 1 );       
    }

    AckCmdInterrupt(card);

    if (0xFFFF != (0xFFFF & card->m_MagicPacketMode)) {
        InitStatusChangeReg( card );
    }

    // Try to read dBm table from card (if supported).
    card->dBmTable = cmdDBMTableGet(card);

    // Use the existing config info contained in the card structure.  Otherwise, we need to 
    // read the default values from the radio, mod them with values from the registry, and 
    // stuff them back into the radio.
    if (useCurrentConfig) {
        cmdConfigSet(card);
        cmdSSIDSet(card);
        cmdAPsSet(card);
        }
    else {
        // This flag will be set on startup when there are no zflags in the registry.
        // In this case we'll read the card's stored config and use that as the default.
        // The flag is cleared so this only happens once.
        if (card->m_readCardConfig) {
            cmdConfigGet(card, &card->m_profiles[0].zFlags.cfg);
            cmdSSIDGet(card, &card->m_profiles[0].zFlags.SSIDList);
            cmdAPsGet(card, &card->m_profiles[0].zFlags.APList);
            card->m_readCardConfig = FALSE;
            }

        CFG_X500 cfg;
        if (!cmdConfigGet(card, &cfg)) {
            LogError( card, NDIS_ERROR_CODE_HARDWARE_FAILURE, 0x00020000 | HARDWARE_FAILURE);
            return FALSE;
            }
        SetUserConfig(card, cfg);                           // update it    
        if (!cmdConfigSet(card, &cfg)) {
            LogError( card, NDIS_ERROR_CODE_HARDWARE_FAILURE, 0x00030000 | HARDWARE_FAILURE);
            return FALSE;
            }

        STSSID ssid;
        if (!cmdSSIDGet(card, &ssid)) {
            LogError( card, NDIS_ERROR_CODE_HARDWARE_FAILURE, 0x00040000 |HARDWARE_FAILURE);
            return FALSE;
            }
        SetUserSSID(card, ssid);                            // update it
        if (!cmdSSIDSet(card, &ssid)) {
            LogError( card,  NDIS_ERROR_CODE_HARDWARE_FAILURE, 0x00050000 |HARDWARE_FAILURE);
            return FALSE;
            }

        STAPLIST aps;
        if (!cmdAPsGet(card, & aps )) {
            LogError( card,  NDIS_ERROR_CODE_HARDWARE_FAILURE, 0x00060000 |HARDWARE_FAILURE);
            return FALSE;
            }
        SetUserAPs(card, aps);                          // update it
        if (!cmdAPsSet(card, & aps)) {
            LogError( card,  NDIS_ERROR_CODE_HARDWARE_FAILURE, 0x00070000 |HARDWARE_FAILURE);
            return FALSE;
            }
        }

    //--------------------------------------------------------------------------
    // Set auto config timer.  In case we don't associate, this will allow us to
    // automatically switch to another profile.
    setAutoConfigTimer(card);

⌨️ 快捷键说明

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