📄 assoc.c
字号:
VarIesOffset += pAd->PortCfg.SupportedRatesLen; // End Add by James MgtMacHeaderInit(pAd, &AssocHdr, SUBTYPE_ASSOC_REQ, 0, &ApAddr, &ApAddr); // Build basic frame first MakeOutgoingFrame( OutBuffer, &FrameLen, sizeof(MACHDR), &AssocHdr, 2, &CapabilityInfo, 2, &ListenIntv, 1, &SsidIe, 1, &pAd->PortCfg.SsidLen, pAd->PortCfg.SsidLen, pAd->PortCfg.Ssid, 1, &RateIe, 1, &pAd->PortCfg.SupRateLen, pAd->PortCfg.SupRateLen, pAd->PortCfg.SupRate, END_OF_ARGS); if (pAd->PortCfg.ExtRateLen != 0) { MakeOutgoingFrame( OutBuffer + FrameLen, &tmp, 1, &ExtRateIe, 1, &pAd->PortCfg.ExtRateLen, pAd->PortCfg.ExtRateLen, pAd->PortCfg.ExtRate, END_OF_ARGS); FrameLen += tmp; } // For WPA / WPA-PSK if ((pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPA) || (pAd->PortCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) { // Copy WPA template to buffer CipherTmpLen = sizeof(CipherWpaTemplate); memcpy(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( OutBuffer + FrameLen, &tmp, CipherTmpLen, &CipherTmp[0], END_OF_ARGS); FrameLen += tmp; // Append Variable IE memcpy(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); memcpy(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 (memcmp(&ApAddr, &pAd->PortCfg.SavedPMK[idx], 6) == 0) { FoundPMK = TRUE; break; } } if (FoundPMK) { // Update length within RSN IE CipherTmp[1] += 18; // Set PMK number *(PUSHORT) &CipherTmp[CipherTmpLen] = 1; memcpy(&CipherTmp[CipherTmpLen + 2], &pAd->PortCfg.SavedPMK[idx].PMKID, 16); CipherTmpLen += 18; } } // Make outgoing frame MakeOutgoingFrame( OutBuffer + FrameLen, &tmp, CipherTmpLen, &CipherTmp[0], END_OF_ARGS); FrameLen += tmp; // Append Variable IE memcpy(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 ; } MiniportMMRequest(pAd, OutBuffer, FrameLen); RTMPSetTimer(pAd, &pAd->Mlme.AssocAux.AssocTimer, Timeout); /* in mSec */ 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; MlmeCntlConfirm(pAd, MT2_ASSOC_CONF, MLME_INVALID_FORMAT); }}/* ========================================================================== 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) IRQL = DISPATCH_LEVEL ========================================================================== */VOID MlmeReassocReqAction( IN PRT2570ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { MACADDR ApAddr; MACHDR ReassocHdr; UCHAR SsidIe = IE_SSID, RateIe = IE_SUPP_RATES, ExtRateIe = IE_EXT_SUPP_RATES; USHORT CapabilityInfo, ListenIntv; ULONG Timeout; ULONG FrameLen = 0; NDIS_STATUS NStatus; ULONG tmp; UCHAR *OutBuffer = NULL; // 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; MlmeCntlConfirm(pAd, MT2_ASSOC_CONF, MLME_STATE_MACHINE_REJECT); } // the parameters are the same as the association else if(MlmeAssocReqSanity(pAd, Elem->Msg, Elem->MsgLen, &ApAddr, &CapabilityInfo, &Timeout, &ListenIntv)) { RTMPCancelTimer(&pAd->Mlme.AssocAux.ReassocTimer); NStatus = MlmeAllocateMemory(pAd, (PVOID)&OutBuffer); //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; MlmeCntlConfirm(pAd, MT2_REASSOC_CONF, MLME_FAIL_NO_RESOURCE); return; } // Mask out unnecessary capability information CapabilityInfo &= SUPPORTED_CAPABILITY_INFO; // pAd->PortCfg.SupportedCapabilityInfo; pAd->Mlme.AssocAux.CapabilityInfo = CapabilityInfo; COPY_MAC_ADDR(&pAd->Mlme.AssocAux.Addr, &ApAddr); pAd->Mlme.AssocAux.ListenIntv = ListenIntv; // 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(OutBuffer, &FrameLen, sizeof(MACHDR), &ReassocHdr, 2, &CapabilityInfo, 2, &ListenIntv, MAC_ADDR_LEN, &ApAddr, 1, &SsidIe, 1, &pAd->PortCfg.SsidLen, pAd->PortCfg.SsidLen, pAd->PortCfg.Ssid, 1, &RateIe, 1, &pAd->PortCfg.SupRateLen, pAd->PortCfg.SupRateLen, pAd->PortCfg.SupRate, END_OF_ARGS); if (pAd->PortCfg.ExtRateLen != 0) { MakeOutgoingFrame(OutBuffer + FrameLen, &tmp, 1, &ExtRateIe, 1, &pAd->PortCfg.ExtRateLen, pAd->PortCfg.ExtRateLen, pAd->PortCfg.ExtRate, END_OF_ARGS); FrameLen += tmp; } MiniportMMRequest(pAd, OutBuffer, FrameLen); RTMPSetTimer(pAd, &pAd->Mlme.AssocAux.ReassocTimer, Timeout); /* in mSec */ 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; MlmeCntlConfirm(pAd, MT2_REASSOC_CONF, MLME_INVALID_FORMAT); }}/* ========================================================================== Description: Upper layer issues disassoc request Parameters: Elem - IRQL = PASSIVE_LEVEL ========================================================================== */VOID MlmeDisassocReqAction( IN PRT2570ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { MLME_DISASSOC_REQ_STRUCT *DisassocReq; MACHDR DisassocHdr; CHAR *OutBuffer = NULL; ULONG FrameLen = 0; NDIS_STATUS NStatus; ULONG Timeout = 0; // skip sanity check DisassocReq = (MLME_DISASSOC_REQ_STRUCT *)(Elem->Msg); NStatus = MlmeAllocateMemory(pAd, (PVOID)&OutBuffer); //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; MlmeCntlConfirm(pAd, MT2_DISASSOC_CONF, MLME_FAIL_NO_RESOURCE); return; } RTMPCancelTimer(&pAd->Mlme.AssocAux.DisassocTimer); DBGPRINT(RT_DEBUG_TRACE, "ASSOC - Send DISASSOC request\n"); MgtMacHeaderInit(pAd, &DisassocHdr, SUBTYPE_DISASSOC, 0, &pAd->PortCfg.Bssid, &pAd->PortCfg.Bssid); MakeOutgoingFrame(OutBuffer, &FrameLen, sizeof(MACHDR), &DisassocHdr, 2, &DisassocReq->Reason, END_OF_ARGS); MiniportMMRequest(pAd, OutBuffer, FrameLen); memset(&(pAd->PortCfg.Bssid), 0, MAC_ADDR_LEN); pAd->PortCfg.DisassocReason = REASON_DISASSOC_STA_LEAVING; COPY_MAC_ADDR(&pAd->PortCfg.DisassocSta, &DisassocReq->Addr); RTMPSetTimer(pAd, &pAd->Mlme.AssocAux.DisassocTimer, Timeout); /* in mSec */ pAd->Mlme.AssocMachine.CurrState = DISASSOC_WAIT_RSP;}/* ========================================================================== Description: peer sends assoc rsp back Parameters: Elme - MLME message containing the received frame IRQL = DISPATCH_LEVEL ========================================================================== */VOID PeerAssocRspAction( IN PRT2570ADAPTER pAd, IN MLME_QUEUE_ELEM *Elem) { USHORT CapabilityInfo, Status, Aid; UCHAR Rates[MAX_LEN_OF_SUPPORTED_RATES], RatesLen; MACADDR Addr2; BOOLEAN ExtendedRateIeExist; if (PeerAssocRspSanity(pAd, Elem->Msg, Elem->MsgLen, &Addr2, &CapabilityInfo, &Status, &Aid, Rates, &RatesLen, &ExtendedRateIeExist)) { // The frame is for me ? if(MAC_ADDR_EQUAL(&Addr2, &pAd->Mlme.AssocAux.Addr)) { DBGPRINT(RT_DEBUG_INFO, "ASSOC - receive ASSOC_RSP to me (status=%d)\n", Status); RTMPCancelTimer(&pAd->Mlme.AssocAux.AssocTimer); if(Status == MLME_SUCCESS) { // go to procedure listed on page 376
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -