?? rtusb_data.c
字號:
do
{
if (pRxContext->pUrb->actual_length >= (sizeof(RXD_STRUC) + LENGTH_802_11))//blue
{
pData = pRxContext->TransferBuffer;
pManage = (PVOID) pData;
pRxD = (PRXD_STRUC)(pData + pRxContext->pUrb->actual_length - sizeof(RXD_STRUC));
pHeader = (PHEADER_802_11)pData;
if (pRxD->DataByteCnt < 4)
Status = NDIS_STATUS_FAILURE;
else
{
pAdapter->PortCfg.Pss = PWR_ACTIVE;
// Increase Total receive byte counter after real data received no mater any error or not
pAdapter->RalinkCounters.ReceivedByteCount += (pRxD->DataByteCnt - 4);
// Check for all RxD errors
Status = RTMPCheckRxDescriptor(pAdapter, pRxD);
}
if (Status == NDIS_STATUS_SUCCESS)
{
// Apply packet filtering rule based on microsoft requirements.
Status = RTMPApplyPacketFilter(pAdapter, pRxD, pHeader);
}
// Add receive counters
if (Status == NDIS_STATUS_SUCCESS)
{
// Increase 802.11 counters & general receive counters
INC_COUNTER(pAdapter->WlanCounters.ReceivedFragmentCount);
}
else
{
// Increase general counters
pAdapter->Counters.RxErrors++;
}
// Check for retry bit, if this bit is on, search the cache with SA & sequence
// as index, if matched, discard this frame, otherwise, update cache
// This check only apply to unicast data & management frames
if ((pRxD->U2M) && (Status == NDIS_STATUS_SUCCESS) && (pHeader->Controlhead.Frame.Type != BTYPE_CNTL))
{
if (pHeader->Controlhead.Frame.Retry)
{
if (RTMPSearchTupleCache(pAdapter, pHeader) == TRUE)
{
// Found retry frame in tuple cache, Discard this frame / fragment
// Increase 802.11 counters
INC_COUNTER(pAdapter->WlanCounters.FrameDuplicateCount);
DBGPRINT_RAW(RT_DEBUG_INFO, "duplicate frame\n");//steven:for debug
Status = NDIS_STATUS_FAILURE;
}
else
{
RTMPUpdateTupleCache(pAdapter, pHeader);
}
}
else // Update Tuple Cache
{
RTMPUpdateTupleCache(pAdapter, pHeader);
}
}
// Check and set the cipher variable
if (pRxD->U2M)
Cipher = pAdapter->PortCfg.PairCipher;
else
Cipher = pAdapter->PortCfg.GroupCipher;
Cipher = pAdapter->PortCfg.WepStatus;
//
// Do RxD release operation for all failure frames
//
if (Status == NDIS_STATUS_SUCCESS)
{
//
// Start of main loop to parse receiving frames.
// The sequence will be Type first, then subtype...
//
switch (pHeader->Controlhead.Frame.Type)
{
// Frame with data type
case BTYPE_DATA:
// pData : Pointer skip the first 24 bytes, 802.11 HEADER
pData += LENGTH_802_11;
PacketSize = pRxD->DataByteCnt - LENGTH_802_11 - 4; //Minus FCS[4]. default for NoneWep.
// Drop not my BSS frame
if (INFRA_ON(pAdapter))
{
// Infrastructure mode, check address 2 for BSSID
if (!RTMPEqualMemory(&pHeader->Controlhead.Addr2, &pAdapter->PortCfg.Bssid, 6))
break; // Receive frame not my BSSID
else
atomic_inc(&(pAdapter->PortCfg.DataPacketsFromAP));
}
else // Ad-Hoc mode or Not associated
{
// Ad-Hoc mode, check address 3 for BSSID
if (!RTMPEqualMemory(&pHeader->Addr3, &pAdapter->PortCfg.Bssid, 6))
break; // Receive frame not my BSSID
// Drop frame from AP while we are in Ad-hoc mode or not associated
if (pHeader->Controlhead.Frame.FrDs)
break;
}
// Drop Null data frame, or CF with NULL data frame
if ((pHeader->Controlhead.Frame.Subtype == SUBTYPE_NULL_FUNC) ||
(pHeader->Controlhead.Frame.Subtype == SUBTYPE_CFACK) ||
(pHeader->Controlhead.Frame.Subtype == SUBTYPE_CFPOLL) ||
(pHeader->Controlhead.Frame.Subtype == SUBTYPE_CFACK_CFPOLL))
{
break;
}
// Process Broadcast & Multicast data frame
if (pRxD->Bcast || pRxD->Mcast)
{
// Multicast 802.11 Counter
INC_COUNTER(pAdapter->WlanCounters.MulticastReceivedFrameCount);
DBGPRINT(RT_DEBUG_INFO,"Receiving multicast frame\n");
// Drop Mcast / Bcast frame with fragment bit on
if (pHeader->Controlhead.Frame.MoreFrag)
{
DBGPRINT_RAW(RT_DEBUG_ERROR,"Receiving multicast frame with fragment bit on\n");
break;
}
// Filter out Bcast frame which AP relayed for us
if ((RTMPEqualMemory(&pHeader->Addr3, pAdapter->CurrentAddress, 6)) && pHeader->Controlhead.Frame.FrDs)
break;
// WEP encrypted frame
if (pHeader->Controlhead.Frame.Wep)
{
// Check our WEP setting, if no WEP turning on, just drop this frame
if (Cipher == Ndis802_11Encryption1Enabled) // WEP
{
if (pRxD->CiErr)
break;
else
{
pData = pData + 4; //Offset skip IV[4]
pRxD->DataByteCnt = pRxD->DataByteCnt - 8; //Minus ICV[4] & FCS[4].
}
PacketSize = pRxD->DataByteCnt - LENGTH_802_11 - 4; //Minus IV[4].
}
else if (Cipher == Ndis802_11Encryption2Enabled) // TKIP
{
if (pRxD->CiErr)
{
DBGPRINT_RAW(RT_DEBUG_ERROR,"pRxD->CiErr\n");
break;
}
else
{
pData = pData + 8; //Offset skip IV[8]
//
// the MIC is stored on the last one no more Fragment.
// that is only last MPDU only need to check MIC.
//
if (pHeader->Controlhead.Frame.MoreFrag == TRUE)
{
// No MIC here.
pRxD->DataByteCnt = pRxD->DataByteCnt - 8; //ICV[4] &FCS[4].
}
else
{
if (pHeader->Frag != 0)
pRxD->DataByteCnt = pRxD->DataByteCnt - 8; //MIC been frag ICV[4] & FCS[4]
else
pRxD->DataByteCnt = pRxD->DataByteCnt - 16; //Minus MIC[8] & ICV[4] &FCS[4].
}
}
PacketSize = pRxD->DataByteCnt - LENGTH_802_11 - 8; //Minus IV+EIV[8].
}
else if (Cipher == Ndis802_11Encryption3Enabled) // AES
{
if (pRxD->CiErr)
break;
else
{
pData = pData + 8; //Offset skip RSN[8]
pRxD->DataByteCnt = pRxD->DataByteCnt - 12; //Minus MIC[8] & ICV[4]
}
PacketSize = pRxD->DataByteCnt - LENGTH_802_11 - 8; //Minus RSN[8]
}
else
break;
}
}//if (pRxD->Bcast || pRxD->Mcast)
// Begin process unicast to me frame
else if (pRxD->U2M)
{
//
// Begin frame processing
//
// DA is always address 1
pDestMac = (PUCHAR) &(pHeader->Controlhead.Addr1);
// Seclect SA by different mode
if (INFRA_ON(pAdapter)) // For infrastructure, SA is address 3
{
pSrcMac = (PUCHAR) &(pHeader->Addr3);
}
else // For IBSS mode, SA is address 2
{
pSrcMac = (PUCHAR) &(pHeader->Controlhead.Addr2);
}
// WEP encrypted frame
if (Cipher == Ndis802_11Encryption1Enabled) // WEP
{
if (pHeader->Controlhead.Frame.Wep)
{
if (pRxD->CiErr)
break;
else
{
pData = pData + 4; //Offset skip IV[4]
pRxD->DataByteCnt = pRxD->DataByteCnt - 8; //Minus ICV[4] & FCS[4].
}
PacketSize = pRxD->DataByteCnt - LENGTH_802_11 - 4; //Minus IV[4].
}
else if ((pAdapter->PortCfg.PrivacyFilter == Ndis802_11PrivFilter8021xWEP) &&
(pHeader->Frag == 0))
{
// Check 802.1x frame, if not drop it.
if (!RTMPEqualMemory(EAPOL, pData + 6, 2))
{
// Not 802.1X frames
// Add error counter
break;
}
}
}
else if (Cipher == Ndis802_11Encryption2Enabled) // TKIP
{
if (pHeader->Controlhead.Frame.Wep)
{
if (pRxD->CiErr)
{
DBGPRINT(RT_DEBUG_TEMP,"pRxD->CiErr\n");
break;
}
else
{
pData = pData + 8; //Offset skip IV[8]
//
// the MIC is stored on the last one no more Fragment.
// that is only last MPDU only need to check MIC.
//
if (pHeader->Controlhead.Frame.MoreFrag == TRUE)
{
//No MIC here.
pRxD->DataByteCnt = pRxD->DataByteCnt - 8; //ICV[4] &FCS[4].
}
else
{
if (pHeader->Frag != 0)
pRxD->DataByteCnt = pRxD->DataByteCnt - 8; //MIC been frag ICV[4] & FCS[4]
else
pRxD->DataByteCnt = pRxD->DataByteCnt - 16; //Minus MIC[8] & ICV[4] & FCS[4].
}
}
PacketSize = pRxD->DataByteCnt - LENGTH_802_11 - 8; //Minus IV+EIV[8].
}
else if ((pAdapter->PortCfg.PrivacyFilter == Ndis802_11PrivFilter8021xWEP) &&
(pHeader->Frag == 0))
{
// Check 802.1x frame, if not drop it.
if (!RTMPEqualMemory(EAPOL, pData + 6, 2))
{
DBGPRINT(RT_DEBUG_TEMP,"Not 802.1X frames\n");
// Not 802.1X frames
// Add error counter
break;
}
DBGPRINT(RT_DEBUG_TEMP," 802.1X EAPOL frames\n");
}
}
else if (Cipher == Ndis802_11Encryption3Enabled) // AES
{
if (pHeader->Controlhead.Frame.Wep)
{
if (pRxD->CiErr)
break;
else
{
pData = pData + 8; //Offset skip IV[8]
pRxD->DataByteCnt = pRxD->DataByteCnt - 12; //Minus MIC[8] & ICV[4]
}
PacketSize = pRxD->DataByteCnt - LENGTH_802_11 - 8; //Minus RSN[8]
}
else if ((pAdapter->PortCfg.PrivacyFilter == Ndis802_11PrivFilter8021xWEP) &&
(pHeader->Frag == 0))
{
// Check 802.1x frame, if not drop it.
if (!RTMPEqualMemory(EAPOL, pData + 6, 2))
{
// Not 802.1X frames
// Add error counter
break;
}
}
}
else if (pHeader->Controlhead.Frame.Wep)
{
// Drop WEP frame when PrivacyInvoked is FALSE
break;
}
}//else if (pRxD->U2M)
// The total available payload should exclude 24-byte 802.11 Header
//packetSize = pRxD->DataByteCnt - LENGTH_802_11 - 4;
// Find the WPA key, either Group or Pairwise Key
// Although the data has been decrypted by ASIC,
// driver has to calculate the RxMIC which required the key.
// The failed case should not happen. If it did, drop it.
if ((pAdapter->PortCfg.CipherAlg == CIPHER_TKIP) && (pHeader->Controlhead.Frame.Wep))
{
INT idx;
pWpaKey = (PWPA_KEY) NULL;
// First lookup the DA, if it's a group address, use GROUP key
if (pRxD->Bcast || pRxD->Mcast)
{
idx = (pRxD->Iv & 0xc0000000) >> 30;
if ((pAdapter->PortCfg.GroupKey[idx].KeyLen != 0) &&
((INFRA_ON(pAdapter) && (NdisEqualMemory(&pHeader->Controlhead.Addr2, &pAdapter->PortCfg.Bssid, 6))) ||
(ADHOC_ON(pAdapter) && (NdisEqualMemory(&pHeader->Addr3, &pAdapter->PortCfg.Bssid, 6)))))
{
pWpaKey = (PWPA_KEY) &pAdapter->PortCfg.GroupKey[idx];
pWpaKey->Type = GROUP_KEY;
DBGPRINT(RT_DEBUG_INFO, "Rx Use Group Key %d\n", idx);
}
}
// Try to find the Pairwise Key
else
{
for (idx = 0; idx < PAIRWISE_KEY_NO; idx++)
{
if ((NdisEqualMemory(&pHeader->Controlhead.Addr2, pAdapter->PortCfg.PairwiseKey[idx].BssId, 6)) &&
(pAdapter->PortCfg.PairwiseKey[idx].KeyLen != 0))
{
pWpaKey = (PWPA_KEY) &pAdapter->PortCfg.PairwiseKey[idx];
pWpaKey->Type = PAIRWISE_KEY;
DBGPRINT(RT_DEBUG_TEMP, "Rx Use Pairwise Key %d\n",idx);
break;
}
}
// Use default Group Key if there is no Pairwise key present
if ((pWpaKey == NULL) && (pAdapter->PortCfg.GroupKey[pAdapter->PortCfg.DefaultKeyId].KeyLen != 0))
{
pWpaKey = (PWPA_KEY) &pAdapter->PortCfg.GroupKey[pAdapter->PortCfg.DefaultKeyId];
pWpaKey->Type = GROUP_KEY;
DBGPRINT(RT_DEBUG_INFO, "Rx Use Group Key\n");
}
}
if (pWpaKey == NULL)
break;
}
// DA is always address 1
pDestMac = (PUCHAR) &(pHeader->Controlhead.Addr1);
// Seclect SA by different mode
if (INFRA_ON(pAdapter))
{
// For infrastructure, SA is address 3
pSrcMac = (PUCHAR) &(pHeader->Addr3);
}
else
{
// For IBSS mode, SA is address 2
pSrcMac = (PUCHAR) &(pHeader->Controlhead.Addr2);
}
// Process Broadcast & Multicast data frame
if (pRxD->Bcast || pRxD->Mcast)
{
// Save encapaturation starting pointer
pEncap = pData;
// For TKIP frame, calculate the MIC value
if ((pAdapter->PortCfg.CipherAlg == CIPHER_TKIP) && (pHeader->Controlhead.Frame.Wep))
{
i = 0;
if (RTMPTkipCompareMICValue(pAdapter,
pData,
pDestMac,
pSrcMac,
pWpaKey->RxMic,
PacketSize) == FALSE)
{
DBGPRINT_RAW(RT_DEBUG_ERROR,"BroadCast/Multicast Rx MIC Value error\n");
RTMPReportMicError(pAdapter, pWpaKey);
Status = NDIS_STATUS_FAILURE;
break;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -