assoc.c
字号:
NdisMoveMemory(CipherTmp, CipherWpaTemplate, CipherTmpLen);
// Modify Group cipher
CipherTmp[11] = ((pAd->PortCfg.GroupCipher == Ndis802_11Encryption2Enabled) ? 0x2 : 0x4);
// Modify Pairwise cipher
CipherTmp[17] = ((pAd->PortCfg.PairCipher == Ndis802_11Encryption2Enabled) ? 0x2 : 0x4);
// Modify AKM
CipherTmp[23] = ((pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA) ? 0x1 : 0x2);
// Make outgoing frame
MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
CipherTmpLen, &CipherTmp[0],
END_OF_ARGS);
FrameLen += tmp;
// Append Variable IE
NdisMoveMemory(pAd->PortCfg.ReqVarIEs + VarIesOffset, CipherTmp, CipherTmpLen);
VarIesOffset += CipherTmpLen;
// Set Variable IEs Length
pAd->PortCfg.ReqVarIELen = VarIesOffset;
pAd->PortCfg.AssocInfo.RequestIELength = VarIesOffset;
// OffsetResponseIEs follow ReqVarIE
pAd->PortCfg.AssocInfo.OffsetResponseIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION) + pAd->PortCfg.ReqVarIELen;
}
// For WPA2 / WPA2-PSK
else if ((pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA2) ||
(pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
{
// Copy WPA2 template to buffer
CipherTmpLen = sizeof(CipherWpa2Template);
NdisMoveMemory(CipherTmp, CipherWpa2Template, CipherTmpLen);
// Modify Group cipher
CipherTmp[7] = ((pAd->PortCfg.GroupCipher == Ndis802_11Encryption2Enabled) ? 0x2 : 0x4);
// Modify Pairwise cipher
CipherTmp[13] = ((pAd->PortCfg.PairCipher == Ndis802_11Encryption2Enabled) ? 0x2 : 0x4);
// Modify AKM
CipherTmp[19] = ((pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA2) ? 0x1 : 0x2);
// Check for WPA PMK cache list
if (pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA2)
{
// Search chched PMKID, append it if existed
for (idx = 0; idx < PMKID_NO; idx++)
{
if (NdisEqualMemory(ApAddr, &pAd->PortCfg.SavedPMK[idx].BSSID, 6))
{
FoundPMK = TRUE;
break;
}
}
if (FoundPMK)
{
// Update length within RSN IE
CipherTmp[1] += 18;
// Set PMK number
*(PUSHORT) &CipherTmp[CipherTmpLen] = 1;
NdisMoveMemory(&CipherTmp[CipherTmpLen + 2], &pAd->PortCfg.SavedPMK[idx].PMKID, 16);
CipherTmpLen += 18;
}
}
// Make outgoing frame
MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
CipherTmpLen, &CipherTmp[0],
END_OF_ARGS);
FrameLen += tmp;
// Append Variable IE
NdisMoveMemory(pAd->PortCfg.ReqVarIEs + VarIesOffset, CipherTmp, CipherTmpLen);
VarIesOffset += CipherTmpLen;
// Set Variable IEs Length
pAd->PortCfg.ReqVarIELen = VarIesOffset;
pAd->PortCfg.AssocInfo.RequestIELength = VarIesOffset;
// OffsetResponseIEs follow ReqVarIE
pAd->PortCfg.AssocInfo.OffsetResponseIEs = sizeof(NDIS_802_11_ASSOCIATION_INFORMATION) + pAd->PortCfg.ReqVarIELen;
}
else
{
// Do nothing
;
}
#if 0 //AGGREGATION_SUPPORT
// add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION, only when -
// 1. user enable aggregation, AND
// 2. AP annouces it's AGGREGATION-capable in BEACON
if (pAd->PortCfg.bAggregationCapable && (pAd->MlmeAux.APRalinkIe & 0x00000001))
{
ULONG TmpLen;
UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x01, 0x00, 0x00, 0x00};
MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,
9, RalinkIe,
END_OF_ARGS);
FrameLen += TmpLen;
}
#endif
MiniportMMRequest(pAd, pOutBuffer, FrameLen);
RTMPSetTimer(pAd, &pAd->MlmeAux.AssocTimer, Timeout);
pAd->Mlme.AssocMachine.CurrState = ASSOC_WAIT_RSP;
}
else
{
DBGPRINT(RT_DEBUG_TRACE,"ASSOC - MlmeAssocReqAction() sanity check failed. BUG!!!!!! \n");
pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
Status = MLME_INVALID_FORMAT;
MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status, FALSE);
}
}
/*
==========================================================================
Description:
mlme reassoc req handling procedure
Parameters:
Elem -
Pre:
-# SSID (Adapter->PortCfg.ssid[])
-# BSSID (AP address, Adapter->PortCfg.bssid)
-# Supported rates (Adapter->PortCfg.supported_rates[])
-# Supported rates length (Adapter->PortCfg.supported_rates_len)
-# Tx power (Adapter->PortCfg.tx_power)
==========================================================================
*/
VOID MlmeReassocReqAction(
IN PRTMP_ADAPTER pAd,
IN MLME_QUEUE_ELEM *Elem)
{
UCHAR ApAddr[6];
HEADER_802_11 ReassocHdr;
UCHAR WmeIe[9] = {IE_VENDOR_SPECIFIC, 0x07, 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, STA_QOS_CAPABILITY};
USHORT CapabilityInfo, ListenIntv;
ULONG Timeout;
ULONG FrameLen = 0;
ULONG tmp;
PUCHAR pOutBuffer = NULL;
USHORT Status;
USHORT NStatus;
// Block all authentication request durning WPA block period
if (pAd->PortCfg.bBlockAssoc == TRUE)
{
DBGPRINT(RT_DEBUG_TRACE, "ASSOC - Block ReAssoc request durning WPA block period!\n");
pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
Status = MLME_STATE_MACHINE_REJECT;
MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status, FALSE);
}
// the parameters are the same as the association
else if(MlmeAssocReqSanity(pAd, Elem->Msg, Elem->MsgLen, ApAddr, &CapabilityInfo, &Timeout, &ListenIntv))
{
RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer);
// allocate and send out ReassocReq frame
NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
if (NStatus != NDIS_STATUS_SUCCESS)
{
DBGPRINT(RT_DEBUG_TRACE,"ASSOC - MlmeReassocReqAction() allocate memory failed \n");
pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
Status = MLME_FAIL_NO_RESOURCE;
MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status, FALSE);
return;
}
COPY_MAC_ADDR(pAd->MlmeAux.Bssid, ApAddr);
// make frame, use bssid as the AP address??
DBGPRINT(RT_DEBUG_TRACE, "ASSOC - Send RE-ASSOC request...\n");
MgtMacHeaderInit(pAd, &ReassocHdr, SUBTYPE_REASSOC_REQ, 0, ApAddr, ApAddr);
MakeOutgoingFrame(pOutBuffer, &FrameLen,
sizeof(HEADER_802_11), &ReassocHdr,
2, &CapabilityInfo,
2, &ListenIntv,
MAC_ADDR_LEN, ApAddr,
1, &SsidIe,
1, &pAd->MlmeAux.SsidLen,
pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid,
1, &SupRateIe,
1, &pAd->MlmeAux.SupRateLen,
pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate,
END_OF_ARGS);
if (pAd->MlmeAux.ExtRateLen != 0)
{
MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
1, &ExtRateIe,
1, &pAd->MlmeAux.ExtRateLen,
pAd->MlmeAux.ExtRateLen, pAd->MlmeAux.ExtRate,
END_OF_ARGS);
FrameLen += tmp;
}
if (pAd->MlmeAux.APEdcaParm.bValid)
{
WmeIe[8] |= (pAd->MlmeAux.APEdcaParm.EdcaUpdateCount & 0x0f);
MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp,
9, &WmeIe[0],
END_OF_ARGS);
FrameLen += tmp;
}
#if 0 //AGGREGATION_SUPPORT
// add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION, only when -
// 1. user enable aggregation, AND
// 2. AP annouces it's AGGREGATION-capable in BEACON
if (pAd->PortCfg.bAggregationCapable && (pAd->MlmeAux.APRalinkIe & 0x00000001))
{
ULONG TmpLen;
UCHAR RalinkIe[9] = {IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x01, 0x00, 0x00, 0x00};
MakeOutgoingFrame(pOutBuffer+FrameLen, &TmpLen,
9, RalinkIe,
END_OF_ARGS);
FrameLen += TmpLen;
}
#endif
MiniportMMRequest(pAd, pOutBuffer, FrameLen);
RTMPSetTimer(pAd, &pAd->MlmeAux.ReassocTimer, Timeout);
pAd->Mlme.AssocMachine.CurrState = REASSOC_WAIT_RSP;
}
else
{
DBGPRINT(RT_DEBUG_TRACE,"ASSOC - MlmeReassocReqAction() sanity check failed. BUG!!!! \n");
pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
Status = MLME_INVALID_FORMAT;
MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status, FALSE);
}
}
/*
==========================================================================
Description:
Upper layer issues disassoc request
Parameters:
Elem -
==========================================================================
*/
VOID MlmeDisassocReqAction(
IN PRTMP_ADAPTER pAd,
IN MLME_QUEUE_ELEM *Elem)
{
PMLME_DISASSOC_REQ_STRUCT pDisassocReq;
HEADER_802_11 DisassocHdr;
PCHAR pOutBuffer = NULL;
ULONG FrameLen = 0;
ULONG Timeout = 0;
USHORT Status;
USHORT NStatus;
// skip sanity check
pDisassocReq = (PMLME_DISASSOC_REQ_STRUCT)(Elem->Msg);
// allocate and send out DeassocReq frame
NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer); //Get an unused nonpaged memory
if (NStatus != NDIS_STATUS_SUCCESS)
{
DBGPRINT(RT_DEBUG_TRACE, "ASSOC - MlmeDisassocReqAction() allocate memory failed\n");
pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE;
Status = MLME_FAIL_NO_RESOURCE;
MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2, &Status, FALSE);
return;
}
RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer);
DBGPRINT(RT_DEBUG_TRACE, "ASSOC - Send DISASSOC request\n");
MgtMacHeaderInit(pAd, &DisassocHdr, SUBTYPE_DISASSOC, 0, pDisassocReq->Addr, pDisassocReq->Addr);
MakeOutgoingFrame(pOutBuffer, &FrameLen,
sizeof(HEADER_802_11),&DisassocHdr,
2, &pDisassocReq->Reason,
END_OF_ARGS);
MiniportMMRequest(pAd, pOutBuffer, FrameLen);
// Set the control aux SSID to prevent it reconnect to old SSID
// Since calling this indicate user don't want to connect to that SSID anymore.
// 2004-11-10 can't reset this info, cause it may be the new SSID that user requests for
// pAd->MlmeAux.SsidLen = MAX_LEN_OF_SSID;
// NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID);
// NdisZeroMemory(pAd->MlmeAux.Bssid, MAC_ADDR_LEN);
pAd->PortCfg.DisassocReason = REASON_DISASSOC_STA_LEAVING;
COPY_MAC_ADDR(pAd->PortCfg.DisassocSta, pDisassocReq->Addr);
RTMPSetTimer(pAd, &pAd->MlmeAux.DisassocTimer, Timeout);
pAd->Mlme.AssocMachine.CurrState = DISASSOC_WAIT_RSP;
}
/*
==========================================================================
Description:
peer sends assoc rsp back
Parameters:
Elme - MLME message containing the received frame
==========================================================================
*/
VOID PeerAssocRspAction(
IN PRTMP_ADAPTER pAd,
IN MLME_QUEUE_ELEM *Elem)
{
USHORT CapabilityInfo, Status, Aid;
UCHAR SupRate[MAX_LEN_OF_SUPPORTED_RATES], SupRateLen;
UCHAR ExtRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRateLen;
UCHAR Addr2[MAC_ADDR_LEN];
EDCA_PARM EdcaParm;
if (PeerAssocRspSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &CapabilityInfo, &Status, &Aid, SupRate, &SupRateLen, ExtRate, &ExtRateLen, &EdcaParm))
{
// The frame is for me ?
if(MAC_ADDR_EQUAL(Addr2, pAd->MlmeAux.Bssid))
{
DBGPRINT(RT_DEBUG_TRACE, "ASSOC - receive ASSOC_RSP to me (status=%d)\n", Status);
RTMPCancelTimer(&pAd->MlmeAux.AssocTimer);
if(Status == MLME_SUCCESS)
{
//
// There may some packets will be drop, if we haven't set the BSS type!
// For example: EAPOL packet and the case of WHQL lost Packets.
// Since this may some delays to set those variables at LinkUp(..) on this (Mlme) thread.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -