📄 connect.c
字号:
#if 0 // set OrigWepStatus in OID_802_11_WEP_STATUS
// Change the wepstatus to original wepstatus
pAd->PortCfg.WepStatus = pAd->PortCfg.OrigWepStatus;
pAd->PortCfg.PairCipher = pAd->PortCfg.OrigWepStatus;
pAd->PortCfg.GroupCipher = pAd->PortCfg.OrigWepStatus;
#endif
BssIdx = pAd->MlmeAux.BssIdx;
if (BssIdx < pAd->MlmeAux.SsidBssTab.BssNr)
{
// Check cipher suite, AP must have more secured cipher than station setting
// Set the Pairwise and Group cipher to match the intended AP setting
// We can only connect to AP with less secured cipher setting
if ((pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPAPSK))
{
pAd->PortCfg.GroupCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.GroupCipher;
if (pAd->PortCfg.WepStatus == pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipher)
pAd->PortCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipher;
else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipherAux != Ndis802_11WEPDisabled)
pAd->PortCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA.PairCipherAux;
else // There is no PairCipher Aux, downgrade our capability to TKIP
pAd->PortCfg.PairCipher = Ndis802_11Encryption2Enabled;
}
else if ((pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA2) || (pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
{
pAd->PortCfg.GroupCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.GroupCipher;
if (pAd->PortCfg.WepStatus == pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipher)
pAd->PortCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipher;
else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipherAux != Ndis802_11WEPDisabled)
pAd->PortCfg.PairCipher = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.PairCipherAux;
else // There is no PairCipher Aux, downgrade our capability to TKIP
pAd->PortCfg.PairCipher = Ndis802_11Encryption2Enabled;
// RSN capability
pAd->PortCfg.RsnCapability = pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2.RsnCapability;
}
// Set Mix cipher flag
if (pAd->PortCfg.PairCipher != pAd->PortCfg.GroupCipher)
pAd->PortCfg.bMixCipher = TRUE;
DBGPRINT(RT_DEBUG_TRACE, "CNTL - iterate BSS %d of %d\n", BssIdx, pAd->MlmeAux.SsidBssTab.BssNr);
JoinParmFill(pAd, &JoinReq, BssIdx);
MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ, sizeof(MLME_JOIN_REQ_STRUCT), &JoinReq);
pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN;
}
else if (pAd->PortCfg.BssType == BSS_ADHOC)
{
DBGPRINT(RT_DEBUG_TRACE, "CNTL - All BSS fail; start a new ADHOC (Ssid=%s)...\n",pAd->MlmeAux.Ssid);
StartParmFill(pAd, &StartReq, pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen);
MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, sizeof(MLME_START_REQ_STRUCT), &StartReq);
pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START;
}
else // no more BSS
{
DBGPRINT(RT_DEBUG_TRACE, "CNTL - All roaming failed, stay @ ch #%d\n", pAd->PortCfg.Channel);
AsicSwitchChannel(pAd, pAd->PortCfg.Channel);
AsicLockChannel(pAd, pAd->PortCfg.Channel);
pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
}
}
// for re-association only
VOID IterateOnBssTab2(
IN PRTMP_ADAPTER pAd)
{
MLME_REASSOC_REQ_STRUCT ReassocReq;
ULONG BssIdx;
BSS_ENTRY *pBss;
BssIdx = pAd->MlmeAux.RoamIdx;
pBss = &pAd->MlmeAux.RoamTab.BssEntry[BssIdx];
if (BssIdx < pAd->MlmeAux.RoamTab.BssNr)
{
DBGPRINT(RT_DEBUG_TRACE, "CNTL - iterate BSS %d of %d\n", BssIdx, pAd->MlmeAux.RoamTab.BssNr);
AsicSwitchChannel(pAd, pBss->Channel);
AsicLockChannel(pAd, pBss->Channel);
// reassociate message has the same structure as associate message
AssocParmFill(pAd, &ReassocReq, pBss->Bssid, pBss->CapabilityInfo,
ASSOC_TIMEOUT, pAd->PortCfg.DefaultListenCount);
MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_REASSOC_REQ,
sizeof(MLME_REASSOC_REQ_STRUCT), &ReassocReq);
pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_REASSOC;
}
else // no more BSS
{
DBGPRINT(RT_DEBUG_TRACE, "CNTL - All fast roaming failed, back to ch #%d\n",pAd->PortCfg.Channel);
AsicSwitchChannel(pAd, pAd->PortCfg.Channel);
AsicLockChannel(pAd, pAd->PortCfg.Channel);
pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE;
}
}
/*
==========================================================================
Description:
==========================================================================
*/
VOID JoinParmFill(
IN PRTMP_ADAPTER pAd,
IN OUT MLME_JOIN_REQ_STRUCT *JoinReq,
IN ULONG BssIdx)
{
JoinReq->BssIdx = BssIdx;
}
/*
==========================================================================
Description:
==========================================================================
*/
VOID AssocParmFill(
IN PRTMP_ADAPTER pAd,
IN OUT MLME_ASSOC_REQ_STRUCT *AssocReq,
IN PUCHAR pAddr,
IN USHORT CapabilityInfo,
IN ULONG Timeout,
IN USHORT ListenIntv)
{
COPY_MAC_ADDR(AssocReq->Addr, pAddr);
// Add mask to support 802.11b mode only
AssocReq->CapabilityInfo = CapabilityInfo & SUPPORTED_CAPABILITY_INFO; // not cf-pollable, not cf-poll-request
AssocReq->Timeout = Timeout;
AssocReq->ListenIntv = ListenIntv;
}
/*
==========================================================================
Description:
==========================================================================
*/
VOID ScanParmFill(
IN PRTMP_ADAPTER pAd,
IN OUT MLME_SCAN_REQ_STRUCT *ScanReq,
IN CHAR Ssid[],
IN UCHAR SsidLen,
IN UCHAR BssType,
IN UCHAR ScanType)
{
ScanReq->SsidLen = SsidLen;
NdisMoveMemory(ScanReq->Ssid, Ssid, SsidLen);
ScanReq->BssType = BssType;
ScanReq->ScanType = ScanType;
}
/*
==========================================================================
Description:
==========================================================================
*/
VOID DisassocParmFill(
IN PRTMP_ADAPTER pAd,
IN OUT MLME_DISASSOC_REQ_STRUCT *DisassocReq,
IN PUCHAR pAddr,
IN USHORT Reason)
{
COPY_MAC_ADDR(DisassocReq->Addr, pAddr);
DisassocReq->Reason = Reason;
}
/*
==========================================================================
Description:
==========================================================================
*/
VOID StartParmFill(
IN PRTMP_ADAPTER pAd,
IN OUT MLME_START_REQ_STRUCT *StartReq,
IN CHAR Ssid[],
IN UCHAR SsidLen)
{
NdisMoveMemory(StartReq->Ssid, Ssid, SsidLen);
StartReq->SsidLen = SsidLen;
}
/*
==========================================================================
Description:
==========================================================================
*/
VOID AuthParmFill(
IN PRTMP_ADAPTER pAd,
IN OUT MLME_AUTH_REQ_STRUCT *AuthReq,
IN PUCHAR pAddr,
IN USHORT Alg)
{
COPY_MAC_ADDR(AuthReq->Addr, pAddr);
AuthReq->Alg = Alg;
AuthReq->Timeout = AUTH_TIMEOUT;
}
/*
==========================================================================
Description:
==========================================================================
*/
VOID ComposePsPoll(
IN PRTMP_ADAPTER pAd)
{
NdisZeroMemory(&pAd->PsPollFrame, sizeof(PSPOLL_FRAME));
pAd->PsPollFrame.FC.Type = BTYPE_CNTL;
pAd->PsPollFrame.FC.SubType = SUBTYPE_PS_POLL;
pAd->PsPollFrame.Aid = pAd->ActiveCfg.Aid | 0xC000;
COPY_MAC_ADDR(pAd->PsPollFrame.Bssid, pAd->PortCfg.Bssid);
COPY_MAC_ADDR(pAd->PsPollFrame.Ta, pAd->CurrentAddress);
}
VOID ComposeNullFrame(
IN PRTMP_ADAPTER pAd)
{
NdisZeroMemory(&pAd->NullFrame, sizeof(HEADER_802_11));
pAd->NullFrame.FC.Type = BTYPE_DATA;
pAd->NullFrame.FC.SubType = SUBTYPE_NULL_FUNC;
pAd->NullFrame.FC.ToDs = 1;
COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->PortCfg.Bssid);
COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->CurrentAddress);
COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->PortCfg.Bssid);
}
/*
==========================================================================
Description:
Pre-build a BEACON frame in the shared memory
==========================================================================
*/
ULONG MakeIbssBeacon(
IN PRTMP_ADAPTER pAd)
{
UCHAR DsLen = 1, IbssLen = 2;
UCHAR LocalErpIe[3] = {IE_ERP, 1, 0x04};
HEADER_802_11 BcnHdr;
USHORT CapabilityInfo;
LARGE_INTEGER FakeTimestamp;
ULONG FrameLen=0;
PTXD_STRUC pTxD = &pAd->BeaconTxD;
CHAR *pBeaconFrame = pAd->BeaconBuf;
BOOLEAN Privacy;
UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES];
UCHAR SupRateLen = 0;
UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES];
UCHAR ExtRateLen = 0;
// 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.PhyMode == PHY_11ABG_MIXED)) &&
(pAd->PortCfg.AdhocMode == ADHOC_11B))
{
SupRate[0] = 0x82; // 1 mbps
SupRate[1] = 0x84; // 2 mbps
SupRate[2] = 0x8b; // 5.5 mbps
SupRate[3] = 0x96; // 11 mbps
SupRateLen = 4;
ExtRateLen = 0;
}
else if (pAd->PortCfg.AdhocMode == ADHOC_11BG_MIXED) //Adhoc Mode 1: B/G mixed.
{
SupRate[0] = 0x82; // 1 mbps
SupRate[1] = 0x84; // 2 mbps
SupRate[2] = 0x8b; // 5.5 mbps
SupRate[3] = 0x96; // 11 mbps
SupRateLen = 4;
ExtRate[0] = 0x0C; // 6 mbps, in units of 0.5 Mbps
ExtRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
ExtRate[2] = 0x18; // 12 mbps, in units of 0.5 Mbps
ExtRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
ExtRate[4] = 0x30; // 24 mbps, in units of 0.5 Mbps
ExtRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
ExtRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
ExtRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
ExtRateLen = 8;
}
else if ((pAd->PortCfg.AdhocMode == ADHOC_11G) || (pAd->PortCfg.AdhocMode == ADHOC_11A) || //Adhoc Mode 2: 11g only 3: 11a only
((pAd->PortCfg.PhyMode == PHY_11ABG_MIXED) && (pAd->PortCfg.Channel > 14)))
{
SupRate[0] = 0x8C; // 6 mbps, in units of 0.5 Mbps, basic rate
SupRate[1] = 0x12; // 9 mbps, in units of 0.5 Mbps
SupRate[2] = 0x98; // 12 mbps, in units of 0.5 Mbps, basic rate
SupRate[3] = 0x24; // 18 mbps, in units of 0.5 Mbps
SupRate[4] = 0xb0; // 24 mbps, in units of 0.5 Mbps, basic rate
SupRate[5] = 0x48; // 36 mbps, in units of 0.5 Mbps
SupRate[6] = 0x60; // 48 mbps, in units of 0.5 Mbps
SupRate[7] = 0x6c; // 54 mbps, in units of 0.5 Mbps
SupRateLen = 8;
ExtRateLen = 0;
//
// Also Update MlmeRate & RtsRate for G only & A only
//
pAd->PortCfg.MlmeRate = RATE_6;
pAd->PortCfg.RtsRate = RATE_6;
}
else
{
SupRateLen = pAd->PortCfg.SupRateLen;
NdisMoveMemory(SupRate, pAd->PortCfg.SupRate, SupRateLen);
ExtRateLen = pAd->PortCfg.ExtRateLen;
NdisMoveMemory(ExtRate, pAd->PortCfg.ExtRate, ExtRateLen);
}
pAd->ActiveCfg.SupRateLen = SupRateLen;
NdisMoveMemory(pAd->ActiveCfg.SupRate, SupRate, SupRateLen);
pAd->ActiveCfg.ExtRateLen = ExtRateLen;
NdisMoveMemory(pAd->ActiveCfg.ExtRate, ExtRate, ExtRateLen);
// compose IBSS beacon frame
MgtMacHeaderInit(pAd, &BcnHdr, SUBTYPE_BEACON, 0, BROADCAST_ADDR, pAd->PortCfg.Bssid);
Privacy = (pAd->PortCfg.WepStatus == Ndis802_11Encryption1Enabled) ||
(pAd->PortCfg.WepStatus == Ndis802_11Encryption2Enabled) ||
(pAd->PortCfg.WepStatus == Ndis802_11Encryption3Enabled);
CapabilityInfo = CAP_GENERATE(0, 1, Privacy, (pAd->PortCfg.TxPreamble == Rt802_11PreambleShort), 0);
MakeOutgoingFrame(pBeaconFrame, &FrameLen,
sizeof(HEADER_802_11), &BcnHdr,
TIMESTAMP_LEN, &FakeTimestamp,
2, &pAd->PortCfg.BeaconPeriod,
2, &CapabilityInfo,
1, &SsidIe,
1, &pAd->PortCfg.SsidLen,
pAd->PortCfg.SsidLen, pAd->PortCfg.Ssid,
1, &SupRateIe,
1, &SupRateLen,
SupRateLen, SupRate,
1, &DsIe,
1, &DsLen,
1, &pAd->PortCfg.Channel,
1, &IbssIe,
1, &IbssLen,
2, &pAd->ActiveCfg.AtimWin,
END_OF_ARGS);
// add ERP_IE and EXT_RAE IE of in 802.11g
if (ExtRateLen)
{
ULONG tmp;
MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,
3, LocalErpIe,
1, &ExtRateIe,
1, &ExtRateLen,
ExtRateLen, ExtRate,
END_OF_ARGS);
FrameLen += tmp;
}
// If adhoc secruity is set for WPA-None, append the cipher suite IE
if (pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPANone)
{
ULONG tmp;
if (pAd->PortCfg.WepStatus == Ndis802_11Encryption2Enabled) // Tkip
{
MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,
1, &WpaIe,
1, &CipherSuiteWpaNoneTkipLen,
CipherSuiteWpaNoneTkipLen, &CipherSuiteWpaNoneTkip[0],
END_OF_ARGS);
FrameLen += tmp;
}
else if (pAd->PortCfg.WepStatus == Ndis802_11Encryption3Enabled) // Aes
{
MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp,
1, &WpaIe,
1, &CipherSuiteWpaNoneAesLen,
CipherSuiteWpaNoneAesLen, &CipherSuiteWpaNoneAes[0],
END_OF_ARGS);
FrameLen += tmp;
}
}
#ifdef BIG_ENDIAN
RTMPFrameEndianChange(pAd, pBeaconFrame, DIR_WRITE, FALSE);
#endif
RTUSBWriteTxDescriptor(pAd, pTxD, CIPHER_NONE, 0,0, FALSE, FALSE, TRUE, SHORT_RETRY,
IFS_BACKOFF, pAd->PortCfg.MlmeRate, FrameLen, QID_MGMT, PID_MGMT_FRAME, FALSE);
//
// For WiFi four stations beacon fair generation issue.
// Modify Beacon's TxD cwmin. Recommend by Jerry.
// 1.) Modify MAC register TXRX_CSR10 Bit 7:0
// or
// 2.) Modify cwmin.
//
pTxD->Cwmin = 2;
DBGPRINT(RT_DEBUG_TRACE, "MakeIbssBeacon (len=%d)\n", FrameLen);
return FrameLen;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -