📄 sync.c
字号:
// leave PSM during scanning. otherwise we may lost ProbeRsp & BEACON
if (pAd->PortCfg.Psm == PWR_SAVE)
MlmeSetPsmBit(pAd, PWR_ACTIVE);
AsicSwitchChannel(pAd, pAd->MlmeAux.Channel);
AsicLockChannel(pAd, pAd->MlmeAux.Channel);
// G band - set BBP_R62 to 0x02 when site survey or rssi<-82
// A band - always set BBP_R62 to 0x04
if (pAd->MlmeAux.Channel <= 14)
{
//
// For the high power and False CCA issue.(Gary)
//
RTUSBWriteBBPRegister(pAd, BBP_R62, 0x04);
RTUSBWriteBBPRegister(pAd, 17, pAd->BbpTuning.R17LowerBoundG); }
else
{
if ((pAd->PortCfg.bIEEE80211H == 1) && RadarChannelCheck(pAd, pAd->MlmeAux.Channel))
ScanType = SCAN_PASSIVE;
RTUSBWriteBBPRegister(pAd, 17, pAd->BbpTuning.R17LowerBoundA);
RTUSBWriteBBPRegister(pAd, BBP_R62, 0x04);
}
// We need to shorten active scan time in order for WZC connect issue
// Chnage the channel scan time for CISCO stuff based on its IAPP announcement
if (ScanType == FAST_SCAN_ACTIVE)
{
RTMPSetTimer(pAd, &pAd->MlmeAux.ScanTimer, FAST_ACTIVE_SCAN_TIME);
}
else // must be SCAN_PASSIVE or SCAN_ACTIVE
{
if (pAd->PortCfg.PhyMode == PHY_11ABG_MIXED)
RTMPSetTimer(pAd, &pAd->MlmeAux.ScanTimer, MIN_CHANNEL_TIME);
else
RTMPSetTimer(pAd, &pAd->MlmeAux.ScanTimer, MAX_CHANNEL_TIME);
}
if ((pAd->MlmeAux.Channel == 34) || (pAd->MlmeAux.Channel == 38) ||
(pAd->MlmeAux.Channel == 42) || (pAd->MlmeAux.Channel == 46))
{
ScanType = SCAN_PASSIVE;
}
if ((ScanType == SCAN_ACTIVE) || (ScanType == FAST_SCAN_ACTIVE))
{
NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //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;
Status = MLME_FAIL_NO_RESOURCE;
MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status);
return;
}
// There is no need to send broadcast probe request if active scan is in effect.
SsidLen = pAd->MlmeAux.SsidLen;
if (pAd->MlmeAux.Channel <= 14)
{
// B&G band use 1,2,5.5,11
pSupRate = pAd->PortCfg.SupRate;
SupRateLen = pAd->PortCfg.SupRateLen;
pExtRate = pAd->PortCfg.ExtRate;
ExtRateLen = pAd->PortCfg.ExtRateLen;
}
else // A band use OFDM rate
{
//
// Overwrite Support Rate, CCK rate are not allowed
//
pSupRate = ASupRate;
SupRateLen = ASupRateLen;
ExtRateLen = 0;
}
MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, BROADCAST_ADDR, BROADCAST_ADDR);
MakeOutgoingFrame(pOutBuffer, &FrameLen,
sizeof(HEADER_802_11), &Hdr80211,
1, &SsidIe,
1, &SsidLen,
SsidLen, pAd->MlmeAux.Ssid,
1, &SupRateIe,
1, &SupRateLen,
SupRateLen, pSupRate,
END_OF_ARGS);
if (ExtRateLen)
{
ULONG Tmp;
MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
1, &ExtRateIe,
1, &ExtRateLen,
ExtRateLen, pExtRate,
END_OF_ARGS);
FrameLen += Tmp;
}
// add Simple Config Information Element
if (pAd->PortCfg.bWscCapable && pAd->PortCfg.WscIEProbeReq.ValueLen)
{
ULONG WscTmpLen = 0;
MakeOutgoingFrame(pOutBuffer+FrameLen, &WscTmpLen,
pAd->PortCfg.WscIEProbeReq.ValueLen, pAd->PortCfg.WscIEProbeReq.Value,
END_OF_ARGS);
FrameLen += WscTmpLen;
}
if (pAd->PortCfg.bGetAPConfig)
{
UCHAR RalinkSpecificIEForGetCfg[6] = {IE_VENDOR_SPECIFIC, 4, 0x00, 0x0c, 0x43, 0x80};
ULONG Tmp = 0;
MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
6, RalinkSpecificIEForGetCfg,
END_OF_ARGS);
FrameLen += Tmp;
}
MiniportMMRequest(pAd, pOutBuffer, FrameLen);
DBGPRINT(RT_DEBUG_INFO, "SYNC - send ProbeReq @ channel=%d, Len=%d\n", pAd->MlmeAux.Channel, FrameLen);
}
// For SCAN_CISCO_PASSIVE, do nothing and silently wait for beacon or other probe reponse
pAd->Mlme.SyncMachine.CurrState = SCAN_LISTEN;
}
}
/*
==========================================================================
Description:
==========================================================================
*/
VOID InvalidStateWhenScan(
IN PRTMP_ADAPTER pAd,
IN MLME_QUEUE_ELEM *Elem)
{
USHORT Status;
DBGPRINT(RT_DEBUG_TRACE, "AYNC - InvalidStateWhenScan(state=%d). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState);
pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
Status = MLME_STATE_MACHINE_REJECT;
MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status);
}
/*
==========================================================================
Description:
==========================================================================
*/
VOID InvalidStateWhenJoin(
IN PRTMP_ADAPTER pAd,
IN MLME_QUEUE_ELEM *Elem)
{
USHORT Status;
DBGPRINT(RT_DEBUG_TRACE, "AYNC - InvalidStateWhenJoin(state=%d). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState);
pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
Status = MLME_STATE_MACHINE_REJECT;
MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status);
}
/*
==========================================================================
Description:
==========================================================================
*/
VOID InvalidStateWhenStart(
IN PRTMP_ADAPTER pAd,
IN MLME_QUEUE_ELEM *Elem)
{
USHORT Status;
DBGPRINT(RT_DEBUG_TRACE, "AYNC - InvalidStateWhenStart(state=%d). Reset SYNC machine\n", pAd->Mlme.SyncMachine.CurrState);
pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE;
Status = MLME_STATE_MACHINE_REJECT;
MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, &Status);
}
/*
==========================================================================
Description:
==========================================================================
*/
VOID EnqueuePsPoll(
IN PRTMP_ADAPTER pAd)
{
DBGPRINT(RT_DEBUG_TRACE, "SYNC - send PsPoll ...\n");
MiniportMMRequest(pAd, (PUCHAR)&pAd->PsPollFrame, sizeof(PSPOLL_FRAME));
}
// 2003-04-17 john
// driver force send out a BEACON frame to cover ADHOC mode BEACON starving issue
// that is, in ADHOC mode, driver guarantee itself can send out at least a BEACON
// per a specified duration, even the peer's clock is faster than us and win all the
// hardware-based BEACON TX oppertunity.
// we may remove this software feature once 2560 IC fix this problem in ASIC.
VOID EnqueueBeaconFrame(
IN PRTMP_ADAPTER pAd)
{
PTXD_STRUC pTxD;
#ifdef BIG_ENDIAN
PTXD_STRUC pDestTxD;
TXD_STRUC TxD;
#endif
PCHAR pBeaconFrame = pAd->BeaconBuf;
PUCHAR pOutBuffer = NULL;
LARGE_INTEGER Tsf;
NDIS_STATUS NStatus;
#ifndef BIG_ENDIAN
pTxD = &pAd->BeaconTxD;
#else
pDestTxD = &pAd->BeaconTxD;
TxD = *pDestTxD;
pTxD = &TxD;
RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD);
#endif
DBGPRINT(RT_DEBUG_TRACE, "SYNC - driver sent BEACON (len=%d)...\n",pTxD->DataByteCnt);
NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
if (NStatus != NDIS_STATUS_SUCCESS)
{
DBGPRINT(RT_DEBUG_TRACE, "EnqueueBeaconFrame allocate memory fail\n");
return;
}
RTUSBReadMACRegister(pAd, TXRX_CSR13, &Tsf.vv.HighPart);
RTUSBReadMACRegister(pAd, TXRX_CSR12, &Tsf.vv.LowPart);
// TODO: not good if porting to big endian platform - TSF byte order ???
NdisMoveMemory(pBeaconFrame + sizeof(HEADER_802_11), &Tsf, TIMESTAMP_LEN);
NdisMoveMemory(pOutBuffer, pBeaconFrame, 256);
MiniportMMRequest(pAd, pOutBuffer, pTxD->DataByteCnt);
#ifdef BIG_ENDIAN
RTMPDescriptorEndianChange((PUCHAR)pTxD, TYPE_TXD);
WriteBackToDescriptor((PUCHAR)pDestTxD, (PUCHAR)pTxD, FALSE, TYPE_TXD);
#endif
}
/*
==========================================================================
Description:
==========================================================================
*/
VOID EnqueueProbeRequest(
IN PRTMP_ADAPTER pAd)
{
PUCHAR pOutBuffer;
ULONG FrameLen = 0;
HEADER_802_11 Hdr80211;
USHORT NStatus;
DBGPRINT(RT_DEBUG_TRACE, "force out a ProbeRequest ...\n");
NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
if (NStatus != NDIS_STATUS_SUCCESS)
{
DBGPRINT(RT_DEBUG_TRACE, "EnqueueProbeRequest() allocate memory fail\n");
return;
}
else
{
MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, BROADCAST_ADDR, BROADCAST_ADDR);
// this ProbeRequest explicitly specify SSID to reduce unwanted ProbeResponse
MakeOutgoingFrame(pOutBuffer, &FrameLen,
sizeof(HEADER_802_11), &Hdr80211,
1, &SsidIe,
1, &pAd->PortCfg.SsidLen,
pAd->PortCfg.SsidLen, pAd->PortCfg.Ssid,
1, &SupRateIe,
1, &pAd->ActiveCfg.SupRateLen,
pAd->ActiveCfg.SupRateLen, pAd->ActiveCfg.SupRate,
END_OF_ARGS);
// add Simple Config Information Element
if (pAd->PortCfg.bWscCapable && pAd->PortCfg.WscIEProbeReq.ValueLen)
{
ULONG WscTmpLen = 0;
MakeOutgoingFrame(pOutBuffer+FrameLen, &WscTmpLen,
pAd->PortCfg.WscIEProbeReq.ValueLen, pAd->PortCfg.WscIEProbeReq.Value,
END_OF_ARGS);
FrameLen += WscTmpLen;
}
if (pAd->PortCfg.bGetAPConfig)
{
UCHAR RalinkSpecificIEForGetCfg[6] = {IE_VENDOR_SPECIFIC, 4, 0x00, 0x0c, 0x43, 0x80};
ULONG Tmp = 0;
MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp,
6, RalinkSpecificIEForGetCfg,
END_OF_ARGS);
FrameLen += Tmp;
}
MiniportMMRequest(pAd, pOutBuffer, FrameLen);
}
}
/*
==========================================================================
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.
============================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -