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

📄 sync.c

📁 台湾RALink公司的 rt2570无线 802.11g 网卡的 驱动的源代码 ,支持linux2.4以上的 内河
💻 C
📖 第 1 页 / 共 5 页
字号:
            if (INFRA_ON(pAd)) // && (pAd->PortCfg.PhyMode == PHY_11BG_MIXED))
            {
                BOOLEAN bUseShortSlot, bUseBGProtection;
                
                // decide to use/change to - 
                //      1. long slot (20 us) or short slot (9 us) time
                //      2. turn on/off RTS/CTS and/or CTS-to-self protection
                //      3. short preamble
                bUseShortSlot = (pAd->PortCfg.UseShortSlotTime == TRUE) && CAP_IS_SHORT_SLOT_TIME(CapabilityInfo);
                if (bUseShortSlot != pAd->PortCfg.ShortSlotInUsed)
                    AsicSetSlotTime(pAd, bUseShortSlot);

                bUseBGProtection = (pAd->PortCfg.UseBGProtection == 1) ||    // always use
                                   ((pAd->PortCfg.UseBGProtection == 0) && ERP_IS_USE_PROTECTION(Erp));
                if (bUseBGProtection != pAd->PortCfg.BGProtectionInUsed)
                {
                    pAd->PortCfg.BGProtectionInUsed = bUseBGProtection;
                    DBGPRINT(RT_DEBUG_TRACE, "SYNC - AP changed B/G protection to %d\n", bUseBGProtection);
                }

                if ((pAd->PortCfg.TxPreambleInUsed == Rt802_11PreambleShort) && ERP_IS_USE_BARKER_PREAMBLE(Erp))
                {
                    MlmeSetTxPreamble(pAd, Rt802_11PreambleLong);
                    DBGPRINT(RT_DEBUG_TRACE, "SYNC - AP forced to use LONG preamble\n");
                }
            }
            
            if (INFRA_ON(pAd))
            {
                if (pAd->PortCfg.Psm == PWR_SAVE)
                {
                    //  1. AP has backlogged unicast-to-me frame, stay AWAKE, send PSPOLL
                    //  2. AP has backlogged broadcast/multicast frame and we want those frames, stay AWAKE
                    //  3. we have outgoing frames in TxRing or PrioRing, better stay AWAKE
                    //  4. Psm change to PWR_SAVE, but AP not been informed yet, we better stay AWAKE
                    //  5. otherwise, put PHY back to sleep to save battery.
                    if (MessageToMe)
                    {
                        DBGPRINT_RAW(RT_DEBUG_TRACE, "SYNC - AP backlog unicast-to-me, stay AWAKE, send PSPOLL\n");
                        EnqueuePsPoll(pAd);
                    }
                    else if (BcastFlag && (DtimCount == 0) && pAd->PortCfg.RecvDtim)
                    {
                        DBGPRINT_RAW(RT_DEBUG_TRACE, "SYNC - AP backlog broadcast/multicast, stay AWAKE\n");
                    }
                    else
                    {
                        USHORT temp;
                        RTUSBSingleRead(pAd, 0x320, &temp);
                        if (pAd->BulkOutPending ||
                            (!LOCAL_TX_RING_EMPTY(pAd)) ||
                            (pAd->PrioRingTxCnt != 0) ||
                            // (pAd->PsPollContext.Ready == TRUE) ||
                            (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) ||
                            (!(temp & 0x80)))
                        {
//                          DBGPRINT_RAW(RT_DEBUG_TRACE, ("SYNC - outgoing frame in TxRing/PrioRing, stay AWAKE\n"));
                            if (pAd->BulkOutPending)
                                DBGPRINT_RAW(RT_DEBUG_TRACE, "Bulk Out Pending\n");
                            if (!LOCAL_TX_RING_EMPTY(pAd))
                                DBGPRINT_RAW(RT_DEBUG_TRACE, "Data Queue Non-empty\n");
                            if (pAd->PrioRingTxCnt != 0)
                                DBGPRINT_RAW(RT_DEBUG_TRACE, "MLME Queue Non-empty\n");
                            if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS))
                                DBGPRINT_RAW(RT_DEBUG_TRACE, "Scan In Progress\n");
                            if (!(temp & 0x80))
                                DBGPRINT_RAW(RT_DEBUG_TRACE, "Device Queue Non-empty\n");
                            DBGPRINT_RAW(RT_DEBUG_TRACE, "Stay AWAKE\n");
                        }
                        else
                        {
                            USHORT NextDtim = DtimCount;
                            if (NextDtim == 0)
                                NextDtim = DtimPeriod;
                            
                            TbttNumToNextWakeUp = pAd->PortCfg.DefaultListenCount;
                            if (pAd->PortCfg.RecvDtim && (TbttNumToNextWakeUp > NextDtim))
                                TbttNumToNextWakeUp = NextDtim;
                            
                            DBGPRINT_RAW(RT_DEBUG_TRACE, "SYNC - PHY sleeps for %d Tbcn\n", TbttNumToNextWakeUp);
                            AsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp);
                        }
                    }
                }
                else
                {
                    ULONG   PowerMode;
                        PowerMode = pAd->PortCfg.WindowsPowerMode;
                    
                    if ((PowerMode != Ndis802_11PowerModeCAM) &&
                        (pAd->BulkOutPending == FALSE) &&
                        (!LOCAL_TX_RING_EMPTY(pAd)) &&
//                      (pAd->MLMEQ.size == 0) &&
//                      (pAd->PsPollContext.Ready != TRUE) &&
                        (pAd->SendTxWaitQueue.Number == 0) &&
//                      (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) &&
                        (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE))
                    {
                        MlmeSetPsmBit(pAd, PWR_SAVE);
                        EnqueueNullFrame(pAd, pAd->PortCfg.TxRate);
                    }
                }               
            }
            
            // At least another peer in this IBSS, declare MediaState as CONNECTED
            if (ADHOC_ON(pAd) && (pAd->MediaState == NdisMediaStateDisconnected))
            {
                pAd->BeaconIntervalChangeAllowed = TRUE;
                pAd->SentBeaconsCount = 0;
                pAd->ReceivedBeaconsCount = 0;
                pAd->MediaState = NdisMediaStateConnected;
                NdisMIndicateStatus(pAd->AdapterHandle, NDIS_STATUS_MEDIA_CONNECT, (PVOID)NULL, 0);
                NdisMIndicateStatusComplete(pAd->AdapterHandle);

                // 2003/03/12 - john
                // Make sure this entry in "PortCfg.BssTab" table, thus complies to Microsoft's policy that
                // "site survey" result should always include the current connected network. 
                //
                Bssidx = BssTableSearch(&pAd->PortCfg.BssTab, &Bssid);
                if (Bssidx == BSS_NOT_FOUND)
                {
                    Bssidx = BssTableSetEntry(pAd, &pAd->PortCfg.BssTab, &Bssid, Ssid, SsidLen, 
                                BssType, BeaconPeriod, CfExist, &CfParm, AtimWin, CapabilityInfo, 
                                Rates, RatesLen, ExtendedRateIeExist, Channel, Elem->Rssi, TimeStamp, LenVIE, pVIE);
                }
            }
        }
        // not my BSSID, ignore it
    }
    // sanity check fail, ignore this frame
    else
                    DBGPRINT(RT_DEBUG_TRACE, " sanity check fail peerBEACON \n");

}

/* 
    ==========================================================================
    Description:
        Receive PROBE REQ from remote peer when operating in IBSS mode
    ==========================================================================
 */
VOID PeerProbeReqAction(
    IN PRT2570ADAPTER pAd, 
    IN MLME_QUEUE_ELEM *Elem) 
{
    MACADDR       Addr2;
    CHAR          Ssid[MAX_LEN_OF_SSID];
    UCHAR         SsidLen;
    MACHDR        ProbeRspHdr;
    NDIS_STATUS   NStatus;
    UCHAR         *OutBuffer = NULL;
    ULONG         FrameLen = 0;
    LARGE_INTEGER FakeTimestamp;
    UCHAR         SsidIe = IE_SSID, DsIe = IE_DS_PARM, IbssIe = IE_IBSS_PARM, SuppIe = IE_SUPP_RATES, 
                  DsLen = 1, IbssLen = 2;
    UCHAR         SupportedRatesLen;
    UCHAR         SupportedRates[MAX_LEN_OF_SUPPORTED_RATES];
    UCHAR         ExtRateIe = IE_EXT_SUPP_RATES, ExtRatesLen;
    UCHAR         ErpIe[3] = {IE_ERP, 1, 0};
    
    if (! ADHOC_ON(pAd))
        return;

    if (PeerProbeReqSanity(pAd, Elem->Msg, Elem->MsgLen, &Addr2, Ssid, &SsidLen)) //, Rates, &RatesLen))
    {
        if ((SsidLen == 0) || RTMPEqualMemory(Ssid, pAd->PortCfg.Ssid, (ULONG) SsidLen))
        {
            // 2003-12-10 802.11g WIFI spec disallow OFDM rates in 802.11g ADHOC mode
            //            make sure 1,2,5.5,11 are the firt 4 rates in PortCfg.SupportedRates[] array
            if ((pAd->PortCfg.PhyMode == PHY_11BG_MIXED) && (pAd->PortCfg.AdhocMode == 0))
            {
                int i;
                SupportedRatesLen=0;
                for (i=0;i<pAd->PortCfg.SupportedRatesLen;i++)
                {
                    switch (pAd->PortCfg.SupportedRates[i] & 0x7f)
                    {
                        case 2:
                        case 4:
                        case 11:
                        case 22:
                            SupportedRates[SupportedRatesLen] = pAd->PortCfg.SupportedRates[i];
                            SupportedRatesLen ++;
                            break;
                        default:
                            break;
                    }
                }
                // error handling - should never happen
                if (SupportedRatesLen != 4)
                {
                    SupportedRatesLen = 4;
                    SupportedRates[0] = 0x82;
                    SupportedRates[1] = 0x84;
                    SupportedRates[2] = 0x8b;
                    SupportedRates[3] = 0x96;
                }
            }
            else
            {
                SupportedRatesLen = pAd->PortCfg.SupportedRatesLen;
                NdisMoveMemory(SupportedRates, pAd->PortCfg.SupportedRates, SupportedRatesLen);
            }

            // allocate and send out ProbeRsp frame
            NStatus = MlmeAllocateMemory(pAd, (PVOID)&OutBuffer);  //Get an unused nonpaged memory
            if (NStatus != NDIS_STATUS_SUCCESS)
                return;
            
            pAd->PortCfg.AtimWin = 0;  // ??????
            DBGPRINT(RT_DEBUG_TRACE, "SYNC - Send PROBE_RSP to %02x:%02x:%02x:%02x:%02x:%02x...\n", 
                Addr2.Octet[0],Addr2.Octet[1],Addr2.Octet[2],Addr2.Octet[3],Addr2.Octet[4],Addr2.Octet[5] );
            MgtMacHeaderInit(pAd, &ProbeRspHdr, SUBTYPE_PROBE_RSP, 0, &Addr2, &pAd->PortCfg.Bssid);

            if (SupportedRatesLen <= 8)
            {
                MakeOutgoingFrame(OutBuffer,                        &FrameLen, 
                              MAC_HDR_LEN,                      &ProbeRspHdr, 
                              TIMESTAMP_LEN,                    &FakeTimestamp,
                              2,                                &pAd->PortCfg.BeaconPeriod,
                              2,                                &pAd->PortCfg.CapabilityInfo,
                              1,                                &SsidIe, 
                              1,                                &pAd->PortCfg.SsidLen, 
                              pAd->PortCfg.SsidLen,             pAd->PortCfg.Ssid,
                              1,                                &SuppIe, 
                              1,                                &SupportedRatesLen,
                              SupportedRatesLen,                SupportedRates, 
                              1,                                &DsIe, 
                              1,                                &DsLen, 
                              1,                                &pAd->PortCfg.Channel,
                              1,                                &IbssIe, 
                              1,                                &IbssLen, 
                              2,                                &pAd->PortCfg.AtimWin,
                              END_OF_ARGS);
            }
            else
            {
                ExtRatesLen = SupportedRatesLen - 8;
                SupportedRatesLen = 8;
                MakeOutgoingFrame(OutBuffer,                        &FrameLen, 
                              MAC_HDR_LEN,                      &ProbeRspHdr, 
                              TIMESTAMP_LEN,                    &FakeTimestamp,
                              2,                                &pAd->PortCfg.BeaconPeriod,
                              2,                                &pAd->PortCfg.CapabilityInfo,
                              1,                                &SsidIe, 
                              1,                                &pAd->PortCfg.SsidLen, 
                              pAd->PortCfg.SsidLen,             pAd->PortCfg.Ssid,
                              1,                                &SuppIe, 
                              1,                                &SupportedRatesLen,
                              SupportedRatesLen,                SupportedRates, 
                              1,                                &DsIe, 
                              1,                                &DsLen, 
                              1,                                &pAd->PortCfg.Channel,
                              1,                                &IbssIe, 
                              1,                                &IbssLen, 
                              2,                                &pAd->PortCfg.AtimWin,
                              3,                                ErpIe,
                              1,                                &ExtRateIe,
                              1,                                &ExtRatesLen,
                              ExtRatesLen,                      &SupportedRates[SupportedRatesLen],
                              END_OF_ARGS);
            }
            // If adhoc secruity is set for WPA-None, append the cipher suite IE
            if (pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
            {
                ULONG   tmp;
                UCHAR   WpaIe = IE_WPA;
                
                if (pAd->PortCfg.WepStatus == Ndis802_11Encryption2Enabled)     // Tkip
                {
                    MakeOutgoingFrame(OutBuffer + FrameLen,         &tmp,
                            1,                         &WpaIe,
                            1,                          &CipherSuiteWpaNoneTkipLen,
                            CipherSuiteWpaNoneTkipLen,  &CipherSuiteWpaNoneTkip[0],
                            END_OF_ARGS);
                    FrameLen += tmp;
                }
                else if (pAd->PortCfg.WepStatus == Ndis802_11Encryption3Enabled)    // Aes
                {
                    MakeOutgoingFrame(OutBuffer + FrameLen,         &tmp,
                            1,                         &WpaIe,
                            1,                          &CipherSuiteWpaNoneAesLen,
                            CipherSuiteWpaNoneAesLen,   &CipherSuiteWpaNoneAes[0],
                            END_OF_ARGS);
                    FrameLen += tmp;
                }
            }
            
            MiniportMMRequest(pAd, OutBuffer, FrameLen);
        }
    }
}

VOID BeaconTimeoutAtJoinAction(

⌨️ 快捷键说明

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