📄 rtusb_data.c
字号:
// 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); } /* Only recieve valid packets in to monitor mode */ if (pAdapter->PortCfg.BssType == BSS_MONITOR && Status == NDIS_STATUS_SUCCESS) { struct sk_buff *skb; if ((skb = __dev_alloc_skb(2048, GFP_DMA|GFP_ATOMIC)) != NULL) { if (pAdapter->PortCfg.MallowRFMONTx == TRUE) { if (pAdapter->PortCfg.ForcePrismHeader != 1) goto rfmontx_80211_receive; } else { if (pAdapter->PortCfg.ForcePrismHeader == 2) goto rfmontx_80211_receive; } // setup the wlan-ng prismheader if (skb_headroom(skb) < sizeof(wlan_ng_prism2_header)) pskb_expand_head(skb, sizeof(wlan_ng_prism2_header), 0, GFP_ATOMIC); ph = (wlan_ng_prism2_header *) skb_push(skb, sizeof(wlan_ng_prism2_header)); memset(ph, 0, sizeof(wlan_ng_prism2_header)); ph->msgcode = DIDmsg_lnxind_wlansniffrm; ph->msglen = sizeof(wlan_ng_prism2_header); strcpy(ph->devname, pAdapter->net->name); ph->hosttime.did = DIDmsg_lnxind_wlansniffrm_hosttime; ph->mactime.did = DIDmsg_lnxind_wlansniffrm_mactime; ph->channel.did = DIDmsg_lnxind_wlansniffrm_channel; ph->rssi.did = DIDmsg_lnxind_wlansniffrm_rssi; ph->signal.did = DIDmsg_lnxind_wlansniffrm_signal; ph->noise.did = DIDmsg_lnxind_wlansniffrm_noise; ph->rate.did = DIDmsg_lnxind_wlansniffrm_rate; ph->istx.did = DIDmsg_lnxind_wlansniffrm_istx; ph->frmlen.did = DIDmsg_lnxind_wlansniffrm_frmlen; ph->hosttime.len = 4; ph->mactime.len = 4; ph->channel.len = 4; ph->rssi.len = 4; ph->signal.len = 4; ph->noise.len = 4; ph->rate.len = 4; ph->istx.len = 4; ph->frmlen.len = 4; ph->hosttime.data = jiffies; ph->channel.data = pAdapter->PortCfg.IbssConfig.Channel; ph->signal.data = pRxD->BBR1; ph->noise.data = pAdapter->PortCfg.LastR17Value; ph->rssi.data = ph->signal.data - ph->noise.data; ph->frmlen.data = pRxD->DataByteCnt; if (pRxD->Ofdm == 1) { for (i = 4; i < 12; i++) if (pRxD->BBR0 == PlcpSignal[i]) ph->rate.data = _11G_RATES[i] * 2; } else ph->rate.data = pRxD->BBR0 / 5; // end prismheader setup rfmontx_80211_receive: skb->dev = pAdapter->net; memcpy(skb_put(skb, pRxD->DataByteCnt-4), pData, pRxD->DataByteCnt-4); skb->mac.raw = skb->data; skb->pkt_type = PACKET_OTHERHOST; skb->protocol = htons(ETH_P_802_2); skb->ip_summed = CHECKSUM_NONE; netif_rx(skb); } if ((!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RESET_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BULKIN_RESET)) && (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_RADIO_OFF)) && (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_HALT_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_REMOVE_IN_PROGRESS))) RTUSBBulkReceive(pAdapter); continue; } 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 (memcmp(&pHeader->Controlhead.Addr2, &pAdapter->PortCfg.Bssid, 6) != 0) 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 (memcmp(&pHeader->Addr3, &pAdapter->PortCfg.Bssid, 6) != 0) 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 (((memcmp(&pHeader->Addr3, pAdapter->CurrentAddress, 6) == 0)) && 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 (memcmp(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 (memcmp(EAPOL, pData + 6, 2) != 0) { 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 (memcmp(EAPOL, pData + 6, 2) != 0) { // 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) {#ifdef BIG_ENDIAN idx = (pRxD->Iv & 0xc0000000) >> 30;#else idx = (pRxD->Iv & 0x000000c0) >> 6;#endif if ((pAdapter->PortCfg.GroupKey[idx].KeyLen != 0) && ((INFRA_ON(pAdapter) && ((memcmp(&pHeader->Controlhead.Addr2, &pAdapter->PortCfg.Bssid, 6) == 0))) || (ADHOC_ON(pAdapter) && ((memcmp(&pHeader->Addr3, &pAdapter->PortCfg.Bssid, 6) == 0))))) { 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -