📄 sync.c
字号:
pAd->Mlme.SyncAux.Channel = NextChannel(pAd, pAd->Mlme.SyncAux.Channel); ScanNextChannel(pAd); }}/* ========================================================================== Description: Scan next channel ========================================================================== */VOID ScanNextChannel( IN PRT2570ADAPTER pAd) { MACHDR Hdr; UCHAR SsidIe = IE_SSID, SuppRateIe = IE_SUPP_RATES; VOID *OutBuffer = NULL; VOID *OutBuffer2 = NULL; NDIS_STATUS NStatus; ULONG FrameLen = 0; UCHAR SsidLen = 0; int i=0; if ((pAd->Mlme.SyncAux.Channel == 0) ) { DBGPRINT(RT_DEBUG_TRACE, "SYNC - End of SCAN, restore to channel %d, find %d BSS\n",pAd->PortCfg.Channel, pAd->PortCfg.BssTab.BssNr); for (i=0;i<pAd->PortCfg.BssTab.BssNr;i++) { DBGPRINT(RT_DEBUG_TRACE, "BSS%d: %s\n", i, pAd->PortCfg.BssTab.BssEntry[i].Ssid); } AsicSwitchChannel(pAd, pAd->PortCfg.Channel); AsicLockChannel(pAd, pAd->PortCfg.Channel); pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; MlmeCntlConfirm(pAd, MT2_SCAN_CONF, MLME_SUCCESS); } else if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS)) { pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; MlmeCntlConfirm(pAd, MT2_SCAN_CONF, MLME_FAIL_NO_RESOURCE); } else { AsicSwitchChannel(pAd, pAd->Mlme.SyncAux.Channel); AsicLockChannel(pAd, pAd->Mlme.SyncAux.Channel); // Total SCAN time still limits within 3 sec (DDK constraint). // TODO: We need more intelligent rules here to further improve out-of-service issue. // e.g. temporary stop copying NDIS packet to TxRing until SCAN complete // We need to shorten active scan time in order for WZC connect issue if (pAd->Mlme.SyncAux.ScanType == SCAN_ACTIVE) { RTMPSetTimer(pAd, &pAd->Mlme.SyncAux.ScanTimer, ACTIVE_SCAN_TIME); } else if (pAd->PortCfg.PhyMode == PHY_11ABG_MIXED) { RTMPSetTimer(pAd, &pAd->Mlme.SyncAux.ScanTimer, MIN_CHANNEL_TIME); } else { RTMPSetTimer(pAd, &pAd->Mlme.SyncAux.ScanTimer, MAX_CHANNEL_TIME); } MgtMacHeaderInit(pAd, &Hdr, SUBTYPE_PROBE_REQ, 0, &pAd->PortCfg.Broadcast, &pAd->PortCfg.Broadcast); // There is no need to send broadcast probe request if active scan is in effect. // The same rulr should apply to passive scan also. if (pAd->Mlme.SyncAux.ScanType == SCAN_PASSIVE) { // Send the first probe request with empty SSID NStatus = MlmeAllocateMemory(pAd, (PVOID)&OutBuffer); //Get an unused nonpaged memory if (NStatus != NDIS_STATUS_SUCCESS) { DBGPRINT(RT_DEBUG_TRACE, "SYNC - ScanNextChannel() allocate memory fail\n"); pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; MlmeCntlConfirm(pAd, MT2_SCAN_CONF, MLME_FAIL_NO_RESOURCE); return; } DBGPRINT(RT_DEBUG_INFO, "SYNC - send passive ProbeReq @ channel=%d...\n", pAd->Mlme.SyncAux.Channel); SsidLen = 0; MakeOutgoingFrame(OutBuffer, &FrameLen, sizeof(MACHDR), (UCHAR*)&Hdr, 1, &SsidIe, 1, &SsidLen, 1, &SuppRateIe, 1, &pAd->PortCfg.SupportedRatesLen, pAd->PortCfg.SupportedRatesLen, pAd->PortCfg.SupportedRates, END_OF_ARGS); MiniportMMRequest(pAd, OutBuffer, FrameLen); } else if (pAd->Mlme.SyncAux.ScanType == SCAN_ACTIVE) { // Allocate another for probe scan with SSID NStatus = MlmeAllocateMemory(pAd, (PVOID)&OutBuffer2); //Get an unused nonpaged memory if (NStatus != NDIS_STATUS_SUCCESS) { DBGPRINT(RT_DEBUG_TRACE, "SYNC - ScanNextChannel() allocate memory fail\n"); pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; MlmeCntlConfirm(pAd, MT2_SCAN_CONF, MLME_FAIL_NO_RESOURCE); return; } // make another probe scan with SSID from mlme.cntlaux.ssid SsidLen = pAd->PortCfg.SsidLen; MakeOutgoingFrame(OutBuffer2, &FrameLen, sizeof(MACHDR), &Hdr, 1, &SsidIe, 1, &SsidLen, SsidLen, pAd->PortCfg.Ssid, 1, &SuppRateIe, 1, &pAd->PortCfg.SupportedRatesLen, pAd->PortCfg.SupportedRatesLen, pAd->PortCfg.SupportedRates, END_OF_ARGS); MiniportMMRequest(pAd, OutBuffer2, FrameLen); DBGPRINT(RT_DEBUG_INFO, "SYNC - send active ProbeReq @ channel=%d with essid=%s\n", pAd->Mlme.SyncAux.Channel, pAd->PortCfg.Ssid); } pAd->Mlme.SyncMachine.CurrState = SCAN_LISTEN; }}/* ========================================================================== Description: ========================================================================== */VOID InvalidStateWhenScan( IN PRT2570ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { DBGPRINT(RT_DEBUG_TRACE, "AYNC - InvalidStateWhenScan(state=%d). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState); pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; MlmeCntlConfirm(pAd, MT2_SCAN_CONF, MLME_STATE_MACHINE_REJECT);}/* ========================================================================== Description: ========================================================================== */VOID InvalidStateWhenJoin( IN PRT2570ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { DBGPRINT(RT_DEBUG_TRACE, "InvalidStateWhenJoin(state=%d). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState); pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; MlmeCntlConfirm(pAd, MT2_JOIN_CONF, MLME_STATE_MACHINE_REJECT);}/* ========================================================================== Description: ========================================================================== */VOID InvalidStateWhenStart( IN PRT2570ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { DBGPRINT(RT_DEBUG_TRACE, "InvalidStateWhenStart(state=%d). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState); pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; MlmeCntlConfirm(pAd, MT2_START_CONF, MLME_STATE_MACHINE_REJECT);}/* ========================================================================== Description: ========================================================================== */VOID EnqueuePsPoll( IN PRT2570ADAPTER pAdapter) { PTX_CONTEXT pPsPollContext; PSPOLL_FRAME *pPsPollFrame; if ((RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RESET_IN_PROGRESS)) || (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BULKOUT_RESET)) || (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_REMOVE_IN_PROGRESS))) { return; } pPsPollContext = &(pAdapter->PsPollContext); pPsPollFrame = (PSPOLL_FRAME*)pAdapter->PsPollContext.TransferBuffer->WirelessPacket; if (pPsPollContext->InUse == FALSE) { PTXD_STRUC pTxD; pPsPollContext->InUse = TRUE; pTxD = &(pPsPollContext->TransferBuffer->TxDesc); memset(pTxD, 0, sizeof(TXD_STRUC)); RTUSBWriteTxDescriptor(pTxD, FALSE, 0, FALSE, FALSE, TRUE, IFS_BACKOFF, sizeof(PSPOLL_FRAME), FALSE, 0, CW_MIN_IN_BITS, CW_MAX_IN_BITS, sizeof(PSPOLL_FRAME) + 4, pAdapter->PortCfg.MlmeRate, 4, pAdapter->PortCfg.TxPreambleInUsed); pPsPollFrame->PwrMgmt = 0; // Fill out frame length information for global Bulk out arbitor pPsPollContext->BulkOutSize = sizeof(PS_POLL_BUFFER); RTUSB_SET_BULK_FLAG(pAdapter, fRTUSB_BULK_OUT_PSPOLL); // Kick bulk out RTUSBKickBulkOut(pAdapter); }}/* ========================================================================== Description: Send out a NULL frame to AP. The prpose is to inform AP this client current PSM bit. NOTE: This routine should only be used in infrastructure mode. ========================================================================== */VOID EnqueueNullFrame( IN PRT2570ADAPTER pAdapter, IN UCHAR TxRate) { PTX_CONTEXT pNullContext; PTXD_STRUC pTxD; HEADER_802_11 *pNullFrame; if ((RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RESET_IN_PROGRESS)) || (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BULKOUT_RESET)) || (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_HALT_IN_PROGRESS)) || (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_REMOVE_IN_PROGRESS))) { return; } // WPA 802.1x secured port control if (((pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAdapter->PortCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) && (pAdapter->PortCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)) { return; } pNullFrame = (HEADER_802_11*)pAdapter->NullContext.TransferBuffer->WirelessPacket; pNullContext = &(pAdapter->NullContext); if (pNullContext->InUse == FALSE) { // Set the in use bit pNullContext->InUse = TRUE; // Fill Null frame body and TxD pTxD = &(pNullContext->TransferBuffer->TxDesc); memset(pTxD, 0, sizeof(TXD_STRUC)); RTUSBWriteTxDescriptor(pTxD, FALSE, 7, TRUE, FALSE, TRUE, IFS_BACKOFF, sizeof(MACHDR), FALSE, 0, CW_MIN_IN_BITS, CW_MAX_IN_BITS, sizeof(MACHDR) + 4, TxRate, 4, pAdapter->PortCfg.TxPreambleInUsed); pNullFrame->Controlhead.Duration = RTUSBCalcDuration(pAdapter, TxRate, 14); pNullFrame->Controlhead.Frame.PwrMgt = (pAdapter->PortCfg.Psm == PWR_SAVE); DBGPRINT(RT_DEBUG_TRACE, "SYNC - send NULL Frame @%d Mbps...\n", RateIdToMbps[TxRate]); // Fill out frame length information for global Bulk out arbitor pNullContext->BulkOutSize = sizeof(TXD_STRUC) + sizeof(HEADER_802_11); RTUSB_SET_BULK_FLAG(pAdapter, fRTUSB_BULK_OUT_DATA_NULL); // Kick bulk out RTUSBKickBulkOut(pAdapter); }}/* ========================================================================== Description: Update PortCfg->ChannelList[] according to 1) Country Region 2) RF IC type, and 3) PHY-mode user selected. The outcome is used by driver when doing site survey. ========================================================================== */VOID BuildChannelList( IN PRT2570ADAPTER pAd){ UCHAR i, index = 0; memset(pAd->PortCfg.ChannelList, 0, MAX_LEN_OF_CHANNELS); // if not 11a-only mode, channel list starts from 2.4Ghz band if (pAd->PortCfg.PhyMode != PHY_11A) { switch (pAd->PortCfg.CountryRegion) { case REGION_FCC: // 1 - 11 memcpy(&pAd->PortCfg.ChannelList[index], Ra24Ghz_FCC, sizeof(Ra24Ghz_FCC)); index += sizeof(Ra24Ghz_FCC); break; case REGION_IC: // 1 -11 memcpy(&pAd->PortCfg.ChannelList[index], Ra24Ghz_IC, sizeof(Ra24Ghz_IC)); index += sizeof(Ra24Ghz_IC); break; case REGION_ISRAEL: // 3 - 9 memcpy(&pAd->PortCfg.ChannelList[index], Ra24Ghz_ISRAEL, sizeof(Ra24Ghz_ISRAEL)); index += sizeof(Ra24Ghz_ISRAEL); break; case REGION_ETSI: // 1 - 13 memcpy(&pAd->PortCfg.ChannelList[index], Ra24Ghz_ESTI, sizeof(Ra24Ghz_ESTI)); index += sizeof(Ra24Ghz_ESTI)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -