diff options
Diffstat (limited to 'drivers/staging/rt2860/sta/wpa.c')
-rw-r--r-- | drivers/staging/rt2860/sta/wpa.c | 272 |
1 files changed, 127 insertions, 145 deletions
diff --git a/drivers/staging/rt2860/sta/wpa.c b/drivers/staging/rt2860/sta/wpa.c index c6c3f3bc418..0a45643eedd 100644 --- a/drivers/staging/rt2860/sta/wpa.c +++ b/drivers/staging/rt2860/sta/wpa.c @@ -37,7 +37,7 @@ */ #include "../rt_config.h" -void inc_byte_array(UCHAR *counter, int len); +void inc_byte_array(UCHAR * counter, int len); /* ======================================================================== @@ -58,33 +58,29 @@ void inc_byte_array(UCHAR *counter, int len); ======================================================================== */ -VOID RTMPReportMicError( - IN PRTMP_ADAPTER pAd, - IN PCIPHER_KEY pWpaKey) +VOID RTMPReportMicError(IN PRTMP_ADAPTER pAd, IN PCIPHER_KEY pWpaKey) { - ULONG Now; - UCHAR unicastKey = (pWpaKey->Type == PAIRWISE_KEY ? 1:0); + ULONG Now; + UCHAR unicastKey = (pWpaKey->Type == PAIRWISE_KEY ? 1 : 0); // Record Last MIC error time and count NdisGetSystemUpTime(&Now); - if (pAd->StaCfg.MicErrCnt == 0) - { + if (pAd->StaCfg.MicErrCnt == 0) { pAd->StaCfg.MicErrCnt++; pAd->StaCfg.LastMicErrorTime = Now; - NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8); - } - else if (pAd->StaCfg.MicErrCnt == 1) - { - if ((pAd->StaCfg.LastMicErrorTime + (60 * OS_HZ)) < Now) - { + NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8); + } else if (pAd->StaCfg.MicErrCnt == 1) { + if ((pAd->StaCfg.LastMicErrorTime + (60 * OS_HZ)) < Now) { // Update Last MIC error time, this did not violate two MIC errors within 60 seconds pAd->StaCfg.LastMicErrorTime = Now; - } - else - { + } else { if (pAd->CommonCfg.bWirelessEvent) - RTMPSendWirelessEvent(pAd, IW_COUNTER_MEASURES_EVENT_FLAG, pAd->MacTab.Content[BSSID_WCID].Addr, BSS0, 0); + RTMPSendWirelessEvent(pAd, + IW_COUNTER_MEASURES_EVENT_FLAG, + pAd->MacTab. + Content[BSSID_WCID].Addr, + BSS0, 0); pAd->StaCfg.LastMicErrorTime = Now; // Violate MIC error counts, MIC countermeasures kicks in @@ -101,154 +97,139 @@ VOID RTMPReportMicError( // RTMPRingCleanUp(pAd, QID_AC_VO); // RTMPRingCleanUp(pAd, QID_HCCA); } - } - else - { + } else { // MIC error count >= 2 // This should not happen ; } - MlmeEnqueue(pAd, - MLME_CNTL_STATE_MACHINE, - OID_802_11_MIC_FAILURE_REPORT_FRAME, - 1, - &unicastKey); - - if (pAd->StaCfg.MicErrCnt == 2) - { - RTMPSetTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, 100); - } + MlmeEnqueue(pAd, + MLME_CNTL_STATE_MACHINE, + OID_802_11_MIC_FAILURE_REPORT_FRAME, 1, &unicastKey); + + if (pAd->StaCfg.MicErrCnt == 2) { + RTMPSetTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, 100); + } } #define LENGTH_EAP_H 4 // If the received frame is EAP-Packet ,find out its EAP-Code (Request(0x01), Response(0x02), Success(0x03), Failure(0x04)). -INT WpaCheckEapCode( - IN PRTMP_ADAPTER pAd, - IN PUCHAR pFrame, - IN USHORT FrameLen, - IN USHORT OffSet) +INT WpaCheckEapCode(IN PRTMP_ADAPTER pAd, + IN PUCHAR pFrame, IN USHORT FrameLen, IN USHORT OffSet) { - PUCHAR pData; - INT result = 0; + PUCHAR pData; + INT result = 0; - if( FrameLen < OffSet + LENGTH_EAPOL_H + LENGTH_EAP_H ) + if (FrameLen < OffSet + LENGTH_EAPOL_H + LENGTH_EAP_H) return result; - pData = pFrame + OffSet; // skip offset bytes + pData = pFrame + OffSet; // skip offset bytes - if(*(pData+1) == EAPPacket) // 802.1x header - Packet Type + if (*(pData + 1) == EAPPacket) // 802.1x header - Packet Type { - result = *(pData+4); // EAP header - Code + result = *(pData + 4); // EAP header - Code } return result; } -VOID WpaSendMicFailureToWpaSupplicant( - IN PRTMP_ADAPTER pAd, - IN BOOLEAN bUnicast) +VOID WpaSendMicFailureToWpaSupplicant(IN PRTMP_ADAPTER pAd, IN BOOLEAN bUnicast) { - char custom[IW_CUSTOM_MAX] = {0}; + char custom[IW_CUSTOM_MAX] = { 0 }; - sprintf(custom, "MLME-MICHAELMICFAILURE.indication"); - if(bUnicast) - sprintf(custom, "%s unicast", custom); + sprintf(custom, "MLME-MICHAELMICFAILURE.indication"); + if (bUnicast) + sprintf(custom, "%s unicast", custom); - RtmpOSWrielessEventSend(pAd, IWEVCUSTOM, -1, NULL, (PUCHAR)custom, strlen(custom)); + RtmpOSWrielessEventSend(pAd, IWEVCUSTOM, -1, NULL, (PUCHAR) custom, + strlen(custom)); - return; + return; } -VOID WpaMicFailureReportFrame( - IN PRTMP_ADAPTER pAd, - IN MLME_QUEUE_ELEM *Elem) +VOID WpaMicFailureReportFrame(IN PRTMP_ADAPTER pAd, IN MLME_QUEUE_ELEM * Elem) { - PUCHAR pOutBuffer = NULL; - UCHAR Header802_3[14]; - ULONG FrameLen = 0; - EAPOL_PACKET Packet; - UCHAR Mic[16]; - BOOLEAN bUnicast; + PUCHAR pOutBuffer = NULL; + UCHAR Header802_3[14]; + ULONG FrameLen = 0; + EAPOL_PACKET Packet; + UCHAR Mic[16]; + BOOLEAN bUnicast; DBGPRINT(RT_DEBUG_TRACE, ("WpaMicFailureReportFrame ----->\n")); - bUnicast = (Elem->Msg[0] == 1 ? TRUE:FALSE); + bUnicast = (Elem->Msg[0] == 1 ? TRUE : FALSE); pAd->Sequence = ((pAd->Sequence) + 1) & (MAX_SEQ_NUMBER); // init 802.3 header and Fill Packet - MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, pAd->CurrentAddress, EAPOL); + MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, + pAd->CurrentAddress, EAPOL); NdisZeroMemory(&Packet, sizeof(Packet)); - Packet.ProVer = EAPOL_VER; - Packet.ProType = EAPOLKey; + Packet.ProVer = EAPOL_VER; + Packet.ProType = EAPOLKey; Packet.KeyDesc.Type = WPA1_KEY_DESC; - // Request field presented - Packet.KeyDesc.KeyInfo.Request = 1; + // Request field presented + Packet.KeyDesc.KeyInfo.Request = 1; - if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled) - { + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled) { Packet.KeyDesc.KeyInfo.KeyDescVer = 2; - } - else // TKIP + } else // TKIP { Packet.KeyDesc.KeyInfo.KeyDescVer = 1; } - Packet.KeyDesc.KeyInfo.KeyType = (bUnicast ? PAIRWISEKEY : GROUPKEY); + Packet.KeyDesc.KeyInfo.KeyType = (bUnicast ? PAIRWISEKEY : GROUPKEY); // KeyMic field presented - Packet.KeyDesc.KeyInfo.KeyMic = 1; + Packet.KeyDesc.KeyInfo.KeyMic = 1; - // Error field presented - Packet.KeyDesc.KeyInfo.Error = 1; + // Error field presented + Packet.KeyDesc.KeyInfo.Error = 1; // Update packet length after decide Key data payload SET_UINT16_TO_ARRARY(Packet.Body_Len, LEN_EAPOL_KEY_MSG) - - // Key Replay Count - NdisMoveMemory(Packet.KeyDesc.ReplayCounter, pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY); - inc_byte_array(pAd->StaCfg.ReplayCounter, 8); + // Key Replay Count + NdisMoveMemory(Packet.KeyDesc.ReplayCounter, + pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY); + inc_byte_array(pAd->StaCfg.ReplayCounter, 8); // Convert to little-endian format. - *((USHORT *)&Packet.KeyDesc.KeyInfo) = cpu2le16(*((USHORT *)&Packet.KeyDesc.KeyInfo)); - + *((USHORT *) & Packet.KeyDesc.KeyInfo) = + cpu2le16(*((USHORT *) & Packet.KeyDesc.KeyInfo)); - MlmeAllocateMemory(pAd, (PUCHAR *)&pOutBuffer); // allocate memory - if(pOutBuffer == NULL) - { + MlmeAllocateMemory(pAd, (PUCHAR *) & pOutBuffer); // allocate memory + if (pOutBuffer == NULL) { return; } - // Prepare EAPOL frame for MIC calculation // Be careful, only EAPOL frame is counted for MIC calculation - MakeOutgoingFrame(pOutBuffer, &FrameLen, - CONV_ARRARY_TO_UINT16(Packet.Body_Len) + 4, &Packet, - END_OF_ARGS); + MakeOutgoingFrame(pOutBuffer, &FrameLen, + CONV_ARRARY_TO_UINT16(Packet.Body_Len) + 4, &Packet, + END_OF_ARGS); // Prepare and Fill MIC value NdisZeroMemory(Mic, sizeof(Mic)); - if(pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled) - { // AES - UCHAR digest[20] = {0}; - HMAC_SHA1(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, digest, SHA1_DIGEST_SIZE); + if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled) { // AES + UCHAR digest[20] = { 0 }; + HMAC_SHA1(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, + digest, SHA1_DIGEST_SIZE); NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC); - } - else - { // TKIP - HMAC_MD5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, Mic, MD5_DIGEST_SIZE); + } else { // TKIP + HMAC_MD5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, + Mic, MD5_DIGEST_SIZE); } NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC); // copy frame to Tx ring and send MIC failure report frame to authenticator RTMPToWirelessSta(pAd, &pAd->MacTab.Content[BSSID_WCID], - Header802_3, LENGTH_802_3, - (PUCHAR)&Packet, - CONV_ARRARY_TO_UINT16(Packet.Body_Len) + 4, FALSE); + Header802_3, LENGTH_802_3, + (PUCHAR) & Packet, + CONV_ARRARY_TO_UINT16(Packet.Body_Len) + 4, FALSE); - MlmeFreeMemory(pAd, (PUCHAR)pOutBuffer); + MlmeFreeMemory(pAd, (PUCHAR) pOutBuffer); DBGPRINT(RT_DEBUG_TRACE, ("WpaMicFailureReportFrame <-----\n")); } @@ -262,7 +243,7 @@ VOID WpaMicFailureReportFrame( * rolling over to more significant bytes if the byte was incremented from * 0xff to 0x00. */ -void inc_byte_array(UCHAR *counter, int len) +void inc_byte_array(UCHAR * counter, int len) { int pos = len - 1; while (pos >= 0) { @@ -273,26 +254,27 @@ void inc_byte_array(UCHAR *counter, int len) } } -VOID WpaDisassocApAndBlockAssoc( - IN PVOID SystemSpecific1, - IN PVOID FunctionContext, - IN PVOID SystemSpecific2, - IN PVOID SystemSpecific3) +VOID WpaDisassocApAndBlockAssoc(IN PVOID SystemSpecific1, + IN PVOID FunctionContext, + IN PVOID SystemSpecific2, + IN PVOID SystemSpecific3) { - RTMP_ADAPTER *pAd = (PRTMP_ADAPTER)FunctionContext; - MLME_DISASSOC_REQ_STRUCT DisassocReq; + RTMP_ADAPTER *pAd = (PRTMP_ADAPTER) FunctionContext; + MLME_DISASSOC_REQ_STRUCT DisassocReq; // disassoc from current AP first - DBGPRINT(RT_DEBUG_TRACE, ("RTMPReportMicError - disassociate with current AP after sending second continuous EAPOL frame\n")); - DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, REASON_MIC_FAILURE); - MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq); + DBGPRINT(RT_DEBUG_TRACE, + ("RTMPReportMicError - disassociate with current AP after sending second continuous EAPOL frame\n")); + DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, + REASON_MIC_FAILURE); + MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, + sizeof(MLME_DISASSOC_REQ_STRUCT), &DisassocReq); pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC; pAd->StaCfg.bBlockAssoc = TRUE; } -VOID WpaStaPairwiseKeySetting( - IN PRTMP_ADAPTER pAd) +VOID WpaStaPairwiseKeySetting(IN PRTMP_ADAPTER pAd) { PCIPHER_KEY pSharedKey; PMAC_TABLE_ENTRY pEntry; @@ -307,9 +289,11 @@ VOID WpaStaPairwiseKeySetting( // Prepare pair-wise key information into shared key table NdisZeroMemory(pSharedKey, sizeof(CIPHER_KEY)); pSharedKey->KeyLen = LEN_TKIP_EK; - NdisMoveMemory(pSharedKey->Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK); - NdisMoveMemory(pSharedKey->RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK); - NdisMoveMemory(pSharedKey->TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK); + NdisMoveMemory(pSharedKey->Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK); + NdisMoveMemory(pSharedKey->RxMic, &pAd->StaCfg.PTK[48], + LEN_TKIP_RXMICK); + NdisMoveMemory(pSharedKey->TxMic, + &pAd->StaCfg.PTK[48 + LEN_TKIP_RXMICK], LEN_TKIP_TXMICK); // Decide its ChiperAlg if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled) @@ -320,37 +304,35 @@ VOID WpaStaPairwiseKeySetting( pSharedKey->CipherAlg = CIPHER_NONE; // Update these related information to MAC_TABLE_ENTRY - NdisMoveMemory(pEntry->PairwiseKey.Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK); - NdisMoveMemory(pEntry->PairwiseKey.RxMic, &pAd->StaCfg.PTK[48], LEN_TKIP_RXMICK); - NdisMoveMemory(pEntry->PairwiseKey.TxMic, &pAd->StaCfg.PTK[48+LEN_TKIP_RXMICK], LEN_TKIP_TXMICK); + NdisMoveMemory(pEntry->PairwiseKey.Key, &pAd->StaCfg.PTK[32], + LEN_TKIP_EK); + NdisMoveMemory(pEntry->PairwiseKey.RxMic, &pAd->StaCfg.PTK[48], + LEN_TKIP_RXMICK); + NdisMoveMemory(pEntry->PairwiseKey.TxMic, + &pAd->StaCfg.PTK[48 + LEN_TKIP_RXMICK], LEN_TKIP_TXMICK); pEntry->PairwiseKey.CipherAlg = pSharedKey->CipherAlg; // Update pairwise key information to ASIC Shared Key Table AsicAddSharedKeyEntry(pAd, - BSS0, - 0, - pSharedKey->CipherAlg, - pSharedKey->Key, - pSharedKey->TxMic, - pSharedKey->RxMic); + BSS0, + 0, + pSharedKey->CipherAlg, + pSharedKey->Key, + pSharedKey->TxMic, pSharedKey->RxMic); // Update ASIC WCID attribute table and IVEIV table - RTMPAddWcidAttributeEntry(pAd, - BSS0, - 0, - pSharedKey->CipherAlg, - pEntry); + RTMPAddWcidAttributeEntry(pAd, BSS0, 0, pSharedKey->CipherAlg, pEntry); STA_PORT_SECURED(pAd); pAd->IndicateMediaState = NdisMediaStateConnected; - DBGPRINT(RT_DEBUG_TRACE, ("%s : AID(%d) port secured\n", __func__, pEntry->Aid)); + DBGPRINT(RT_DEBUG_TRACE, + ("%s : AID(%d) port secured\n", __func__, pEntry->Aid)); } -VOID WpaStaGroupKeySetting( - IN PRTMP_ADAPTER pAd) +VOID WpaStaGroupKeySetting(IN PRTMP_ADAPTER pAd) { - PCIPHER_KEY pSharedKey; + PCIPHER_KEY pSharedKey; pSharedKey = &pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId]; @@ -358,8 +340,10 @@ VOID WpaStaGroupKeySetting( NdisZeroMemory(pSharedKey, sizeof(CIPHER_KEY)); pSharedKey->KeyLen = LEN_TKIP_EK; NdisMoveMemory(pSharedKey->Key, pAd->StaCfg.GTK, LEN_TKIP_EK); - NdisMoveMemory(pSharedKey->RxMic, &pAd->StaCfg.GTK[16], LEN_TKIP_RXMICK); - NdisMoveMemory(pSharedKey->TxMic, &pAd->StaCfg.GTK[24], LEN_TKIP_TXMICK); + NdisMoveMemory(pSharedKey->RxMic, &pAd->StaCfg.GTK[16], + LEN_TKIP_RXMICK); + NdisMoveMemory(pSharedKey->TxMic, &pAd->StaCfg.GTK[24], + LEN_TKIP_TXMICK); // Update Shared Key CipherAlg pSharedKey->CipherAlg = CIPHER_NONE; @@ -374,18 +358,16 @@ VOID WpaStaGroupKeySetting( // Update group key information to ASIC Shared Key Table AsicAddSharedKeyEntry(pAd, - BSS0, - pAd->StaCfg.DefaultKeyId, - pSharedKey->CipherAlg, - pSharedKey->Key, - pSharedKey->TxMic, - pSharedKey->RxMic); + BSS0, + pAd->StaCfg.DefaultKeyId, + pSharedKey->CipherAlg, + pSharedKey->Key, + pSharedKey->TxMic, pSharedKey->RxMic); // Update ASIC WCID attribute table and IVEIV table RTMPAddWcidAttributeEntry(pAd, - BSS0, - pAd->StaCfg.DefaultKeyId, - pSharedKey->CipherAlg, - NULL); + BSS0, + pAd->StaCfg.DefaultKeyId, + pSharedKey->CipherAlg, NULL); } |