2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: handle dpc rx functions
28 * device_receive_frame - Rcv 802.11 frame function
29 * s_bAPModeRxCtl- AP Rcv frame filer Ctl.
30 * s_bAPModeRxData- AP Rcv data frame handle
31 * s_bHandleRxEncryption- Rcv decrypted data via on-fly
32 * s_bHostWepRxEncryption- Rcv encrypted data via host
33 * s_byGetRateIdx- get rate index
34 * s_vGetDASA- get data offset
35 * s_vProcessRxMACHeader- Rcv 802.11 and translate to 802.3
59 /*--------------------- Static Definitions -------------------------*/
61 /*--------------------- Static Classes ----------------------------*/
63 /*--------------------- Static Variables --------------------------*/
64 //static int msglevel =MSG_LEVEL_DEBUG;
65 static int msglevel =MSG_LEVEL_INFO;
67 const BYTE acbyRxRate[MAX_RATE] =
68 {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
71 /*--------------------- Static Functions --------------------------*/
73 /*--------------------- Static Definitions -------------------------*/
75 /*--------------------- Static Functions --------------------------*/
77 static BYTE s_byGetRateIdx(BYTE byRate);
82 PBYTE pbyRxBufferAddr,
83 unsigned int *pcbHeaderSize,
84 PSEthernetHeader psEthHeader
89 s_vProcessRxMACHeader (
91 PBYTE pbyRxBufferAddr,
92 unsigned int cbPacketSize,
95 unsigned int *pcbHeadSize
98 static BOOL s_bAPModeRxCtl(
101 signed int iSANodeIndex
106 static BOOL s_bAPModeRxData (
109 unsigned int FrameSize,
110 unsigned int cbHeaderOffset,
111 signed int iSANodeIndex,
112 signed int iDANodeIndex
116 static BOOL s_bHandleRxEncryption(
119 unsigned int FrameSize,
128 static BOOL s_bHostWepRxEncryption(
132 unsigned int FrameSize,
143 /*--------------------- Export Variables --------------------------*/
148 * Translate Rcv 802.11 header to 802.3 header with Rx buffer
153 * dwRxBufferAddr - Address of Rcv Buffer
154 * cbPacketSize - Rcv Packet size
155 * bIsWEP - If Rcv with WEP
157 * pcbHeaderSize - 802.11 header size
164 s_vProcessRxMACHeader (
166 PBYTE pbyRxBufferAddr,
167 unsigned int cbPacketSize,
170 unsigned int *pcbHeadSize
174 unsigned int cbHeaderSize = 0;
176 PS802_11Header pMACHeader;
180 pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
182 s_vGetDASA((PBYTE)pMACHeader, &cbHeaderSize, &pDevice->sRxEthHeader);
186 // strip IV&ExtIV , add 8 byte
187 cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 8);
189 // strip IV , add 4 byte
190 cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 4);
194 cbHeaderSize += WLAN_HDR_ADDR3_LEN;
197 pbyRxBuffer = (PBYTE) (pbyRxBufferAddr + cbHeaderSize);
198 if (!compare_ether_addr(pbyRxBuffer, &pDevice->abySNAP_Bridgetunnel[0])) {
200 } else if (!compare_ether_addr(pbyRxBuffer, &pDevice->abySNAP_RFC1042[0])) {
202 pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
203 if ((*pwType == cpu_to_be16(ETH_P_IPX)) ||
204 (*pwType == cpu_to_le16(0xF380))) {
206 pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
209 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8); // 8 is IV&ExtIV
211 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4); // 4 is IV
215 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
221 pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
224 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8); // 8 is IV&ExtIV
226 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4); // 4 is IV
230 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
234 cbHeaderSize -= (ETH_ALEN * 2);
235 pbyRxBuffer = (PBYTE) (pbyRxBufferAddr + cbHeaderSize);
236 for (ii = 0; ii < ETH_ALEN; ii++)
237 *pbyRxBuffer++ = pDevice->sRxEthHeader.abyDstAddr[ii];
238 for (ii = 0; ii < ETH_ALEN; ii++)
239 *pbyRxBuffer++ = pDevice->sRxEthHeader.abySrcAddr[ii];
241 *pcbHeadSize = cbHeaderSize;
247 static BYTE s_byGetRateIdx(BYTE byRate)
251 for (byRateIdx = 0; byRateIdx <MAX_RATE ; byRateIdx++) {
252 if (acbyRxRate[byRateIdx%MAX_RATE] == byRate)
262 PBYTE pbyRxBufferAddr,
263 unsigned int *pcbHeaderSize,
264 PSEthernetHeader psEthHeader
267 unsigned int cbHeaderSize = 0;
268 PS802_11Header pMACHeader;
271 pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
273 if ((pMACHeader->wFrameCtl & FC_TODS) == 0) {
274 if (pMACHeader->wFrameCtl & FC_FROMDS) {
275 for (ii = 0; ii < ETH_ALEN; ii++) {
276 psEthHeader->abyDstAddr[ii] =
277 pMACHeader->abyAddr1[ii];
278 psEthHeader->abySrcAddr[ii] =
279 pMACHeader->abyAddr3[ii];
283 for (ii = 0; ii < ETH_ALEN; ii++) {
284 psEthHeader->abyDstAddr[ii] =
285 pMACHeader->abyAddr1[ii];
286 psEthHeader->abySrcAddr[ii] =
287 pMACHeader->abyAddr2[ii];
292 if (pMACHeader->wFrameCtl & FC_FROMDS) {
293 for (ii = 0; ii < ETH_ALEN; ii++) {
294 psEthHeader->abyDstAddr[ii] =
295 pMACHeader->abyAddr3[ii];
296 psEthHeader->abySrcAddr[ii] =
297 pMACHeader->abyAddr4[ii];
301 for (ii = 0; ii < ETH_ALEN; ii++) {
302 psEthHeader->abyDstAddr[ii] =
303 pMACHeader->abyAddr3[ii];
304 psEthHeader->abySrcAddr[ii] =
305 pMACHeader->abyAddr2[ii];
309 *pcbHeaderSize = cbHeaderSize;
316 RXbBulkInProcessData (
319 unsigned long BytesToIndicate
323 struct net_device_stats* pStats=&pDevice->stats;
325 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
326 PSRxMgmtPacket pRxPacket = &(pMgmt->sRxPacket);
327 PS802_11Header p802_11Header;
333 BOOL bDeFragRx = FALSE;
334 unsigned int cbHeaderOffset;
337 signed int iSANodeIndex = -1;
338 signed int iDANodeIndex = -1;
340 unsigned int cbIVOffset;
345 unsigned int cbHeaderSize;
346 PSKeyItem pKey = NULL;
348 DWORD dwRxTSC47_16 = 0;
351 /* signed long ldBm = 0; */
355 PRCB pRCBIndicate = pRCB;
358 BYTE abyVaildRate[MAX_RATE] = {2,4,11,22,12,18,24,36,48,72,96,108};
359 WORD wPLCPwithPadding;
360 PS802_11Header pMACHeader;
361 BOOL bRxeapol_key = FALSE;
365 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- RXbBulkInProcessData---\n");
369 /* [31:16]RcvByteCount ( not include 4-byte Status ) */
370 dwWbkStatus = *((u32 *)(skb->data));
371 FrameSize = dwWbkStatus >> 16;
374 if (BytesToIndicate != FrameSize) {
375 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"------- WRONG Length 1\n");
379 if ((BytesToIndicate > 2372) || (BytesToIndicate <= 40)) {
380 // Frame Size error drop this packet.
381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---------- WRONG Length 2\n");
385 pbyDAddress = (PBYTE)(skb->data);
386 pbyRxSts = pbyDAddress+4;
387 pbyRxRate = pbyDAddress+5;
389 //real Frame Size = USBFrameSize -4WbkStatus - 4RxStatus - 8TSF - 4RSR - 4SQ3 - ?Padding
390 //if SQ3 the range is 24~27, if no SQ3 the range is 20~23
391 //real Frame size in PLCPLength field.
392 pwPLCP_Length = (PWORD) (pbyDAddress + 6);
393 //Fix hardware bug => PLCP_Length error
394 if ( ((BytesToIndicate - (*pwPLCP_Length)) > 27) ||
395 ((BytesToIndicate - (*pwPLCP_Length)) < 24) ||
396 (BytesToIndicate < (*pwPLCP_Length)) ) {
398 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Wrong PLCP Length %x\n", (int) *pwPLCP_Length);
402 for ( ii=RATE_1M;ii<MAX_RATE;ii++) {
403 if ( *pbyRxRate == abyVaildRate[ii] ) {
407 if ( ii==MAX_RATE ) {
408 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Wrong RxRate %x\n",(int) *pbyRxRate);
412 wPLCPwithPadding = ( (*pwPLCP_Length / 4) + ( (*pwPLCP_Length % 4) ? 1:0 ) ) *4;
414 pqwTSFTime = (u64 *)(pbyDAddress + 8 + wPLCPwithPadding);
415 if(pDevice->byBBType == BB_TYPE_11G) {
416 pby3SQ = pbyDAddress + 8 + wPLCPwithPadding + 12;
420 pbySQ = pbyDAddress + 8 + wPLCPwithPadding + 8;
423 pbyNewRsr = pbyDAddress + 8 + wPLCPwithPadding + 9;
424 pbyRSSI = pbyDAddress + 8 + wPLCPwithPadding + 10;
425 pbyRsr = pbyDAddress + 8 + wPLCPwithPadding + 11;
427 FrameSize = *pwPLCP_Length;
429 pbyFrame = pbyDAddress + 8;
430 // update receive statistic counter
432 STAvUpdateRDStatCounter(&pDevice->scStatistic,
442 pMACHeader = (PS802_11Header) pbyFrame;
444 //mike add: to judge if current AP is activated?
445 if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
446 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
447 if (pMgmt->sNodeDBTable[0].bActive) {
448 if (!compare_ether_addr(pMgmt->abyCurrBSSID, pMACHeader->abyAddr2)) {
449 if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
450 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
455 if (!is_multicast_ether_addr(pMACHeader->abyAddr1)) {
456 if ( WCTLbIsDuplicate(&(pDevice->sDupRxCache), (PS802_11Header) pbyFrame) ) {
457 pDevice->s802_11Counter.FrameDuplicateCount++;
461 if (compare_ether_addr(pDevice->abyCurrentNetAddr,
462 pMACHeader->abyAddr1)) {
469 s_vGetDASA(pbyFrame, &cbHeaderSize, &pDevice->sRxEthHeader);
471 if (!compare_ether_addr((PBYTE)&(pDevice->sRxEthHeader.abySrcAddr[0]),
472 pDevice->abyCurrentNetAddr))
475 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
476 if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
477 p802_11Header = (PS802_11Header) (pbyFrame);
479 if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(p802_11Header->abyAddr2), &iSANodeIndex)) {
480 pMgmt->sNodeDBTable[iSANodeIndex].ulLastRxJiffer = jiffies;
481 pMgmt->sNodeDBTable[iSANodeIndex].uInActiveCount = 0;
486 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
487 if (s_bAPModeRxCtl(pDevice, pbyFrame, iSANodeIndex) == TRUE) {
493 if (IS_FC_WEP(pbyFrame)) {
494 BOOL bRxDecryOK = FALSE;
496 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"rx WEP pkt\n");
498 if ((pDevice->bEnableHostWEP) && (iSANodeIndex >= 0)) {
500 pKey->byCipherSuite = pMgmt->sNodeDBTable[iSANodeIndex].byCipherSuite;
501 pKey->dwKeyIndex = pMgmt->sNodeDBTable[iSANodeIndex].dwKeyIndex;
502 pKey->uKeyLength = pMgmt->sNodeDBTable[iSANodeIndex].uWepKeyLength;
503 pKey->dwTSC47_16 = pMgmt->sNodeDBTable[iSANodeIndex].dwTSC47_16;
504 pKey->wTSC15_0 = pMgmt->sNodeDBTable[iSANodeIndex].wTSC15_0;
506 &pMgmt->sNodeDBTable[iSANodeIndex].abyWepKey[0],
510 bRxDecryOK = s_bHostWepRxEncryption(pDevice,
514 pMgmt->sNodeDBTable[iSANodeIndex].bOnFly,
521 bRxDecryOK = s_bHandleRxEncryption(pDevice,
533 if ((*pbyNewRsr & NEWRSR_DECRYPTOK) == 0) {
534 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV Fail\n");
535 if ( (pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
536 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
537 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
538 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
539 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
541 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
542 pDevice->s802_11Counter.TKIPICVErrors++;
543 } else if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP)) {
544 pDevice->s802_11Counter.CCMPDecryptErrors++;
545 } else if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_WEP)) {
546 // pDevice->s802_11Counter.WEPICVErrorCount.QuadPart++;
552 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WEP Func Fail\n");
555 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP))
556 FrameSize -= 8; // Message Integrity Code
558 FrameSize -= 4; // 4 is ICV
565 /* remove the FCS/CRC length */
566 FrameSize -= ETH_FCS_LEN;
568 if ( !(*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) && // unicast address
569 (IS_FRAGMENT_PKT((pbyFrame)))
572 bDeFragRx = WCTLbHandleFragment(pDevice, (PS802_11Header) (pbyFrame), FrameSize, bIsWEP, bExtIV);
573 pDevice->s802_11Counter.ReceivedFragmentCount++;
576 // TODO skb, pbyFrame
577 skb = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb;
578 FrameSize = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength;
579 pbyFrame = skb->data + 8;
587 // Management & Control frame Handle
589 if ((IS_TYPE_DATA((pbyFrame))) == FALSE) {
590 // Handle Control & Manage Frame
592 if (IS_TYPE_MGMT((pbyFrame))) {
596 pRxPacket = &(pRCB->sMngPacket);
597 pRxPacket->p80211Header = (PUWLAN_80211HDR)(pbyFrame);
598 pRxPacket->cbMPDULen = FrameSize;
599 pRxPacket->uRSSI = *pbyRSSI;
600 pRxPacket->bySQ = *pbySQ;
601 pRxPacket->qwLocalTSF = cpu_to_le64(*pqwTSFTime);
604 pbyData1 = WLAN_HDR_A3_DATA_PTR(pbyFrame);
605 pbyData2 = WLAN_HDR_A3_DATA_PTR(pbyFrame) + 4;
606 for (ii = 0; ii < (FrameSize - 4); ii++) {
607 *pbyData1 = *pbyData2;
613 pRxPacket->byRxRate = s_byGetRateIdx(*pbyRxRate);
615 if ( *pbyRxSts == 0 ) {
616 //Discard beacon packet which channel is 0
617 if ( (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) == WLAN_FSTYPE_BEACON) ||
618 (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) == WLAN_FSTYPE_PROBERESP) ) {
622 pRxPacket->byRxChannel = (*pbyRxSts) >> 2;
624 // hostap Deamon handle 802.11 management
625 if (pDevice->bEnableHostapd) {
626 skb->dev = pDevice->apdev;
631 skb_put(skb, FrameSize);
632 skb_reset_mac_header(skb);
633 skb->pkt_type = PACKET_OTHERHOST;
634 skb->protocol = htons(ETH_P_802_2);
635 memset(skb->cb, 0, sizeof(skb->cb));
641 // Insert the RCB in the Recv Mng list
643 EnqueueRCB(pDevice->FirstRecvMngList, pDevice->LastRecvMngList, pRCBIndicate);
644 pDevice->NumRecvMngList++;
645 if ( bDeFragRx == FALSE) {
648 if (pDevice->bIsRxMngWorkItemQueued == FALSE) {
649 pDevice->bIsRxMngWorkItemQueued = TRUE;
650 tasklet_schedule(&pDevice->RxMngWorkItem);
660 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
661 //In AP mode, hw only check addr1(BSSID or RA) if equal to local MAC.
662 if ( !(*pbyRsr & RSR_BSSIDOK)) {
664 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
665 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
673 // discard DATA packet while not associate || BSSID error
674 if ((pDevice->bLinkPass == FALSE) ||
675 !(*pbyRsr & RSR_BSSIDOK)) {
677 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
678 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
684 //mike add:station mode check eapol-key challenge--->
686 BYTE Protocol_Version; //802.1x Authentication
687 BYTE Packet_Type; //802.1x Authentication
688 BYTE Descriptor_type;
694 wEtherType = (skb->data[cbIVOffset + 8 + 24 + 6] << 8) |
695 skb->data[cbIVOffset + 8 + 24 + 6 + 1];
696 Protocol_Version = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1];
697 Packet_Type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1];
698 if (wEtherType == ETH_P_PAE) { //Protocol Type in LLC-Header
699 if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
700 (Packet_Type==3)) { //802.1x OR eapol-key challenge frame receive
702 Descriptor_type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2];
703 Key_info = (skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2+1]<<8) |skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2+2] ;
704 if(Descriptor_type==2) { //RSN
705 // printk("WPA2_Rx_eapol-key_info<-----:%x\n",Key_info);
707 else if(Descriptor_type==254) {
708 // printk("WPA_Rx_eapol-key_info<-----:%x\n",Key_info);
713 //mike add:station mode check eapol-key challenge<---
721 if (pDevice->bEnablePSMode) {
722 if (IS_FC_MOREDATA((pbyFrame))) {
723 if (*pbyRsr & RSR_ADDROK) {
724 //PSbSendPSPOLL((PSDevice)pDevice);
728 if (pMgmt->bInTIMWake == TRUE) {
729 pMgmt->bInTIMWake = FALSE;
734 // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps
735 if (pDevice->bDiversityEnable && (FrameSize>50) &&
736 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
737 (pDevice->bLinkPass == TRUE)) {
738 BBvAntennaDiversity(pDevice, s_byGetRateIdx(*pbyRxRate), 0);
741 // ++++++++ For BaseBand Algorithm +++++++++++++++
742 pDevice->uCurrRSSI = *pbyRSSI;
743 pDevice->byCurrSQ = *pbySQ;
747 if ((*pbyRSSI != 0) &&
748 (pMgmt->pCurrBSS!=NULL)) {
749 RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
750 // Monitor if RSSI is too strong.
751 pMgmt->pCurrBSS->byRSSIStatCnt++;
752 pMgmt->pCurrBSS->byRSSIStatCnt %= RSSI_STAT_COUNT;
753 pMgmt->pCurrBSS->ldBmAverage[pMgmt->pCurrBSS->byRSSIStatCnt] = ldBm;
754 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
755 if (pMgmt->pCurrBSS->ldBmAverage[ii] != 0) {
756 pMgmt->pCurrBSS->ldBmMAX =
757 max(pMgmt->pCurrBSS->ldBmAverage[ii], ldBm);
764 // -----------------------------------------------
766 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnable8021x == TRUE)){
769 // Only 802.1x packet incoming allowed
774 wEtherType = (skb->data[cbIVOffset + 8 + 24 + 6] << 8) |
775 skb->data[cbIVOffset + 8 + 24 + 6 + 1];
777 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wEtherType = %04x \n", wEtherType);
778 if (wEtherType == ETH_P_PAE) {
779 skb->dev = pDevice->apdev;
781 if (bIsWEP == TRUE) {
782 // strip IV header(8)
783 memcpy(&abyMacHdr[0], (skb->data + 8), 24);
784 memcpy((skb->data + 8 + cbIVOffset), &abyMacHdr[0], 24);
787 skb->data += (cbIVOffset + 8);
788 skb->tail += (cbIVOffset + 8);
789 skb_put(skb, FrameSize);
790 skb_reset_mac_header(skb);
791 skb->pkt_type = PACKET_OTHERHOST;
792 skb->protocol = htons(ETH_P_802_2);
793 memset(skb->cb, 0, sizeof(skb->cb));
798 // check if 802.1x authorized
799 if (!(pMgmt->sNodeDBTable[iSANodeIndex].dwFlags & WLAN_STA_AUTHORIZED))
804 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
806 FrameSize -= 8; //MIC
810 //--------------------------------------------------------------------------------
812 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
816 DWORD dwMIC_Priority;
817 DWORD dwMICKey0 = 0, dwMICKey1 = 0;
818 DWORD dwLocalMIC_L = 0;
819 DWORD dwLocalMIC_R = 0;
822 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
823 dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[24]));
824 dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[28]));
827 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
828 dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[16]));
829 dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[20]));
830 } else if ((pKey->dwKeyIndex & BIT28) == 0) {
831 dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[16]));
832 dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[20]));
834 dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[24]));
835 dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[28]));
839 MIC_vInit(dwMICKey0, dwMICKey1);
840 MIC_vAppend((PBYTE)&(pDevice->sRxEthHeader.abyDstAddr[0]), 12);
842 MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
843 // 4 is Rcv buffer header, 24 is MAC Header, and 8 is IV and Ext IV.
844 MIC_vAppend((PBYTE)(skb->data + 8 + WLAN_HDR_ADDR3_LEN + 8),
845 FrameSize - WLAN_HDR_ADDR3_LEN - 8);
846 MIC_vGetMIC(&dwLocalMIC_L, &dwLocalMIC_R);
849 pdwMIC_L = (PDWORD)(skb->data + 8 + FrameSize);
850 pdwMIC_R = (PDWORD)(skb->data + 8 + FrameSize + 4);
853 if ((cpu_to_le32(*pdwMIC_L) != dwLocalMIC_L) || (cpu_to_le32(*pdwMIC_R) != dwLocalMIC_R) ||
854 (pDevice->bRxMICFail == TRUE)) {
855 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC comparison is fail!\n");
856 pDevice->bRxMICFail = FALSE;
857 //pDevice->s802_11Counter.TKIPLocalMICFailures.QuadPart++;
858 pDevice->s802_11Counter.TKIPLocalMICFailures++;
860 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
861 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
865 //send event to wpa_supplicant
866 //if(pDevice->bWPASuppWextEnabled == TRUE)
868 union iwreq_data wrqu;
869 struct iw_michaelmicfailure ev;
870 int keyidx = pbyFrame[cbHeaderSize+3] >> 6; //top two-bits
871 memset(&ev, 0, sizeof(ev));
872 ev.flags = keyidx & IW_MICFAILURE_KEY_ID;
873 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
874 (pMgmt->eCurrState == WMAC_STATE_ASSOC) &&
875 (*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) {
876 ev.flags |= IW_MICFAILURE_PAIRWISE;
878 ev.flags |= IW_MICFAILURE_GROUP;
881 ev.src_addr.sa_family = ARPHRD_ETHER;
882 memcpy(ev.src_addr.sa_data, pMACHeader->abyAddr2, ETH_ALEN);
883 memset(&wrqu, 0, sizeof(wrqu));
884 wrqu.data.length = sizeof(ev);
885 PRINT_K("wireless_send_event--->IWEVMICHAELMICFAILURE\n");
886 wireless_send_event(pDevice->dev, IWEVMICHAELMICFAILURE, &wrqu, (char *)&ev);
894 } //---end of SOFT MIC-----------------------------------------------------------------------
896 // ++++++++++ Reply Counter Check +++++++++++++
898 if ((pKey != NULL) && ((pKey->byCipherSuite == KEY_CTL_TKIP) ||
899 (pKey->byCipherSuite == KEY_CTL_CCMP))) {
901 WORD wLocalTSC15_0 = 0;
902 DWORD dwLocalTSC47_16 = 0;
903 unsigned long long RSC = 0;
905 RSC = *((unsigned long long *) &(pKey->KeyRSC));
906 wLocalTSC15_0 = (WORD) RSC;
907 dwLocalTSC47_16 = (DWORD) (RSC>>16);
912 memcpy(&(pKey->KeyRSC), &RSC, sizeof(u64));
914 if ( (pDevice->sMgmtObj.eCurrMode == WMAC_MODE_ESS_STA) &&
915 (pDevice->sMgmtObj.eCurrState == WMAC_STATE_ASSOC)) {
917 if ( (wRxTSC15_0 < wLocalTSC15_0) &&
918 (dwRxTSC47_16 <= dwLocalTSC47_16) &&
919 !((dwRxTSC47_16 == 0) && (dwLocalTSC47_16 == 0xFFFFFFFF))) {
920 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC is illegal~~!\n ");
921 if (pKey->byCipherSuite == KEY_CTL_TKIP)
922 //pDevice->s802_11Counter.TKIPReplays.QuadPart++;
923 pDevice->s802_11Counter.TKIPReplays++;
925 //pDevice->s802_11Counter.CCMPReplays.QuadPart++;
926 pDevice->s802_11Counter.CCMPReplays++;
929 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
930 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
938 } // ----- End of Reply Counter Check --------------------------
941 s_vProcessRxMACHeader(pDevice, (PBYTE)(skb->data+8), FrameSize, bIsWEP, bExtIV, &cbHeaderOffset);
942 FrameSize -= cbHeaderOffset;
943 cbHeaderOffset += 8; // 8 is Rcv buffer header
945 // Null data, framesize = 12
949 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
950 if (s_bAPModeRxData(pDevice,
959 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
960 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
969 skb->data += cbHeaderOffset;
970 skb->tail += cbHeaderOffset;
971 skb_put(skb, FrameSize);
972 skb->protocol=eth_type_trans(skb, skb->dev);
973 skb->ip_summed=CHECKSUM_NONE;
974 pStats->rx_bytes +=skb->len;
975 pStats->rx_packets++;
978 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
979 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
989 static BOOL s_bAPModeRxCtl (
992 signed int iSANodeIndex
995 PS802_11Header p802_11Header;
997 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1000 if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
1002 p802_11Header = (PS802_11Header) (pbyFrame);
1003 if (!IS_TYPE_MGMT(pbyFrame)) {
1005 // Data & PS-Poll packet
1006 // check frame class
1007 if (iSANodeIndex > 0) {
1008 // frame class 3 fliter & checking
1009 if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_AUTH) {
1010 // send deauth notification
1011 // reason = (6) class 2 received from nonauth sta
1012 vMgrDeAuthenBeginSta(pDevice,
1014 (PBYTE)(p802_11Header->abyAddr2),
1015 (WLAN_MGMT_REASON_CLASS2_NONAUTH),
1018 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 1\n");
1021 if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_ASSOC) {
1022 // send deassoc notification
1023 // reason = (7) class 3 received from nonassoc sta
1024 vMgrDisassocBeginSta(pDevice,
1026 (PBYTE)(p802_11Header->abyAddr2),
1027 (WLAN_MGMT_REASON_CLASS3_NONASSOC),
1030 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDisassocBeginSta 2\n");
1034 if (pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable) {
1035 // delcare received ps-poll event
1036 if (IS_CTL_PSPOLL(pbyFrame)) {
1037 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE;
1038 bScheduleCommand((void *) pDevice,
1041 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 1\n");
1044 // check Data PS state
1045 // if PW bit off, send out all PS bufferring packets.
1046 if (!IS_FC_POWERMGT(pbyFrame)) {
1047 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = FALSE;
1048 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE;
1049 bScheduleCommand((void *) pDevice,
1052 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 2\n");
1057 if (IS_FC_POWERMGT(pbyFrame)) {
1058 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = TRUE;
1059 // Once if STA in PS state, enable multicast bufferring
1060 pMgmt->sNodeDBTable[0].bPSEnable = TRUE;
1063 // clear all pending PS frame.
1064 if (pMgmt->sNodeDBTable[iSANodeIndex].wEnQueueCnt > 0) {
1065 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = FALSE;
1066 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE;
1067 bScheduleCommand((void *) pDevice,
1070 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 3\n");
1077 vMgrDeAuthenBeginSta(pDevice,
1079 (PBYTE)(p802_11Header->abyAddr2),
1080 (WLAN_MGMT_REASON_CLASS2_NONAUTH),
1083 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 3\n");
1084 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSID:%pM\n",
1085 p802_11Header->abyAddr3);
1086 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR2:%pM\n",
1087 p802_11Header->abyAddr2);
1088 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR1:%pM\n",
1089 p802_11Header->abyAddr1);
1090 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: wFrameCtl= %x\n", p802_11Header->wFrameCtl );
1099 static BOOL s_bHandleRxEncryption (
1102 unsigned int FrameSize,
1105 PSKeyItem * pKeyOut,
1108 PDWORD pdwRxTSC47_16
1111 unsigned int PayloadLen = FrameSize;
1114 PSKeyItem pKey = NULL;
1115 BYTE byDecMode = KEY_CTL_WEP;
1116 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1122 pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
1123 if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) &&
1124 WLAN_GET_FC_FROMDS(*(PWORD)pbyFrame) ) {
1125 pbyIV += 6; // 6 is 802.11 address4
1128 byKeyIdx = (*(pbyIV+3) & 0xc0);
1130 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\nKeyIdx: %d\n", byKeyIdx);
1132 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
1133 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
1134 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
1135 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
1136 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
1137 if (((*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) &&
1138 (pMgmt->byCSSPK != KEY_CTL_NONE)) {
1139 // unicast pkt use pairwise key
1140 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"unicast pkt\n");
1141 if (KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, 0xFFFFFFFF, &pKey) == TRUE) {
1142 if (pMgmt->byCSSPK == KEY_CTL_TKIP)
1143 byDecMode = KEY_CTL_TKIP;
1144 else if (pMgmt->byCSSPK == KEY_CTL_CCMP)
1145 byDecMode = KEY_CTL_CCMP;
1147 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"unicast pkt: %d, %p\n", byDecMode, pKey);
1150 KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, byKeyIdx, &pKey);
1151 if (pMgmt->byCSSGK == KEY_CTL_TKIP)
1152 byDecMode = KEY_CTL_TKIP;
1153 else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
1154 byDecMode = KEY_CTL_CCMP;
1155 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"group pkt: %d, %d, %p\n", byKeyIdx, byDecMode, pKey);
1158 // our WEP only support Default Key
1160 // use default group key
1161 KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, byKeyIdx, &pKey);
1162 if (pMgmt->byCSSGK == KEY_CTL_TKIP)
1163 byDecMode = KEY_CTL_TKIP;
1164 else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
1165 byDecMode = KEY_CTL_CCMP;
1169 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"AES:%d %d %d\n", pMgmt->byCSSPK, pMgmt->byCSSGK, byDecMode);
1172 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey == NULL\n");
1173 if (byDecMode == KEY_CTL_WEP) {
1174 // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1175 } else if (pDevice->bLinkPass == TRUE) {
1176 // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1180 if (byDecMode != pKey->byCipherSuite) {
1181 if (byDecMode == KEY_CTL_WEP) {
1182 // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1183 } else if (pDevice->bLinkPass == TRUE) {
1184 // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1189 if (byDecMode == KEY_CTL_WEP) {
1191 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
1192 (((PSKeyTable)(&pKey->pvKeyTable))->bSoftWEP == TRUE)) {
1197 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1198 memcpy(pDevice->abyPRNG, pbyIV, 3);
1199 memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
1200 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
1201 rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
1203 if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen)) {
1204 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1207 } else if ((byDecMode == KEY_CTL_TKIP) ||
1208 (byDecMode == KEY_CTL_CCMP)) {
1211 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1212 *pdwRxTSC47_16 = cpu_to_le32(*(PDWORD)(pbyIV + 4));
1213 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ExtIV: %x\n", *pdwRxTSC47_16);
1214 if (byDecMode == KEY_CTL_TKIP) {
1215 *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
1217 *pwRxTSC15_0 = cpu_to_le16(*(PWORD)pbyIV);
1219 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC0_15: %x\n", *pwRxTSC15_0);
1221 if ((byDecMode == KEY_CTL_TKIP) &&
1222 (pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1225 PS802_11Header pMACHeader = (PS802_11Header) (pbyFrame);
1226 TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
1227 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
1228 rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
1229 if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
1230 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1231 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV OK!\n");
1233 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV FAIL!!!\n");
1234 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PayloadLen = %d\n", PayloadLen);
1239 if ((*(pbyIV+3) & 0x20) != 0)
1245 static BOOL s_bHostWepRxEncryption (
1248 unsigned int FrameSize,
1255 PDWORD pdwRxTSC47_16
1258 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1259 unsigned int PayloadLen = FrameSize;
1262 BYTE byDecMode = KEY_CTL_WEP;
1263 PS802_11Header pMACHeader;
1270 pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
1271 if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) &&
1272 WLAN_GET_FC_FROMDS(*(PWORD)pbyFrame) ) {
1273 pbyIV += 6; // 6 is 802.11 address4
1276 byKeyIdx = (*(pbyIV+3) & 0xc0);
1278 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\nKeyIdx: %d\n", byKeyIdx);
1281 if (pMgmt->byCSSGK == KEY_CTL_TKIP)
1282 byDecMode = KEY_CTL_TKIP;
1283 else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
1284 byDecMode = KEY_CTL_CCMP;
1286 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"AES:%d %d %d\n", pMgmt->byCSSPK, pMgmt->byCSSGK, byDecMode);
1288 if (byDecMode != pKey->byCipherSuite) {
1289 if (byDecMode == KEY_CTL_WEP) {
1290 // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1291 } else if (pDevice->bLinkPass == TRUE) {
1292 // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1297 if (byDecMode == KEY_CTL_WEP) {
1299 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byDecMode == KEY_CTL_WEP\n");
1300 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
1301 (((PSKeyTable)(&pKey->pvKeyTable))->bSoftWEP == TRUE) ||
1302 (bOnFly == FALSE)) {
1308 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1309 memcpy(pDevice->abyPRNG, pbyIV, 3);
1310 memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
1311 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
1312 rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
1314 if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen)) {
1315 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1318 } else if ((byDecMode == KEY_CTL_TKIP) ||
1319 (byDecMode == KEY_CTL_CCMP)) {
1322 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1323 *pdwRxTSC47_16 = cpu_to_le32(*(PDWORD)(pbyIV + 4));
1324 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ExtIV: %x\n", *pdwRxTSC47_16);
1326 if (byDecMode == KEY_CTL_TKIP) {
1327 *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
1329 *pwRxTSC15_0 = cpu_to_le16(*(PWORD)pbyIV);
1331 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC0_15: %x\n", *pwRxTSC15_0);
1333 if (byDecMode == KEY_CTL_TKIP) {
1335 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || (bOnFly == FALSE)) {
1339 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_TKIP \n");
1340 pMACHeader = (PS802_11Header) (pbyFrame);
1341 TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
1342 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
1343 rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
1344 if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
1345 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1346 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV OK!\n");
1348 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV FAIL!!!\n");
1349 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PayloadLen = %d\n", PayloadLen);
1354 if (byDecMode == KEY_CTL_CCMP) {
1355 if (bOnFly == FALSE) {
1358 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_CCMP\n");
1359 if (AESbGenCCMP(pKey->abyKey, pbyFrame, FrameSize)) {
1360 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1361 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CCMP MIC compare OK!\n");
1363 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CCMP MIC fail!\n");
1370 if ((*(pbyIV+3) & 0x20) != 0)
1377 static BOOL s_bAPModeRxData (
1379 struct sk_buff *skb,
1380 unsigned int FrameSize,
1381 unsigned int cbHeaderOffset,
1382 signed int iSANodeIndex,
1383 signed int iDANodeIndex
1387 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1388 BOOL bRelayAndForward = FALSE;
1389 BOOL bRelayOnly = FALSE;
1390 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1394 struct sk_buff* skbcpy = NULL;
1396 if (FrameSize > CB_MAX_BUF_SIZE)
1399 if (is_multicast_ether_addr((PBYTE)(skb->data+cbHeaderOffset))) {
1400 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1402 skbcpy = dev_alloc_skb((int)pDevice->rx_buf_sz);
1404 // if any node in PS mode, buffer packet until DTIM.
1405 if (skbcpy == NULL) {
1406 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "relay multicast no skb available \n");
1409 skbcpy->dev = pDevice->dev;
1410 skbcpy->len = FrameSize;
1411 memcpy(skbcpy->data, skb->data+cbHeaderOffset, FrameSize);
1412 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skbcpy);
1413 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1415 pMgmt->abyPSTxMap[0] |= byMask[0];
1419 bRelayAndForward = TRUE;
1424 if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(skb->data+cbHeaderOffset), &iDANodeIndex)) {
1425 if (pMgmt->sNodeDBTable[iDANodeIndex].eNodeState >= NODE_ASSOC) {
1426 if (pMgmt->sNodeDBTable[iDANodeIndex].bPSEnable) {
1427 // queue this skb until next PS tx, and then release.
1429 skb->data += cbHeaderOffset;
1430 skb->tail += cbHeaderOffset;
1431 skb_put(skb, FrameSize);
1432 skb_queue_tail(&pMgmt->sNodeDBTable[iDANodeIndex].sTxPSQueue, skb);
1434 pMgmt->sNodeDBTable[iDANodeIndex].wEnQueueCnt++;
1435 wAID = pMgmt->sNodeDBTable[iDANodeIndex].wAID;
1436 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1437 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n",
1438 iDANodeIndex, (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
1448 if (bRelayOnly || bRelayAndForward) {
1449 // relay this packet right now
1450 if (bRelayAndForward)
1453 if ((pDevice->uAssocCount > 1) && (iDANodeIndex >= 0)) {
1454 bRelayPacketSend(pDevice, (PBYTE) (skb->data + cbHeaderOffset),
1455 FrameSize, (unsigned int) iDANodeIndex);
1461 // none associate, don't forward
1462 if (pDevice->uAssocCount == 0)
1471 void RXvWorkItem(void *Context)
1473 PSDevice pDevice = (PSDevice) Context;
1477 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Rx Polling Thread\n");
1478 spin_lock_irq(&pDevice->lock);
1480 while ((pDevice->Flags & fMP_POST_READS) &&
1481 MP_IS_READY(pDevice) &&
1482 (pDevice->NumRecvFreeList != 0) ) {
1483 pRCB = pDevice->FirstRecvFreeList;
1484 pDevice->NumRecvFreeList--;
1485 ASSERT(pRCB);// cannot be NULL
1486 DequeueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList);
1487 ntStatus = PIPEnsBulkInUsbRead(pDevice, pRCB);
1489 pDevice->bIsRxWorkItemQueued = FALSE;
1490 spin_unlock_irq(&pDevice->lock);
1501 PSDevice pDevice = (PSDevice)pRCB->pDevice;
1504 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->RXvFreeRCB\n");
1506 ASSERT(!pRCB->Ref); // should be 0
1507 ASSERT(pRCB->pDevice); // shouldn't be NULL
1509 if (bReAllocSkb == FALSE) {
1510 kfree_skb(pRCB->skb);
1514 if (bReAllocSkb == TRUE) {
1515 pRCB->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1516 // todo error handling
1517 if (pRCB->skb == NULL) {
1518 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to re-alloc rx skb\n");
1520 pRCB->skb->dev = pDevice->dev;
1524 // Insert the RCB back in the Recv free list
1526 EnqueueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList, pRCB);
1527 pDevice->NumRecvFreeList++;
1530 if ((pDevice->Flags & fMP_POST_READS) && MP_IS_READY(pDevice) &&
1531 (pDevice->bIsRxWorkItemQueued == FALSE) ) {
1533 pDevice->bIsRxWorkItemQueued = TRUE;
1534 tasklet_schedule(&pDevice->ReadWorkItem);
1536 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----RXFreeRCB %d %d\n",pDevice->NumRecvFreeList, pDevice->NumRecvMngList);
1540 void RXvMngWorkItem(void *Context)
1542 PSDevice pDevice = (PSDevice) Context;
1544 PSRxMgmtPacket pRxPacket;
1545 BOOL bReAllocSkb = FALSE;
1547 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Rx Mng Thread\n");
1549 spin_lock_irq(&pDevice->lock);
1550 while (pDevice->NumRecvMngList!=0)
1552 pRCB = pDevice->FirstRecvMngList;
1553 pDevice->NumRecvMngList--;
1554 DequeueRCB(pDevice->FirstRecvMngList, pDevice->LastRecvMngList);
1558 ASSERT(pRCB);// cannot be NULL
1559 pRxPacket = &(pRCB->sMngPacket);
1560 vMgrRxManagePacket((void *) pDevice, &(pDevice->sMgmtObj), pRxPacket);
1562 if(pRCB->Ref == 0) {
1563 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeMng %d %d\n",pDevice->NumRecvFreeList, pDevice->NumRecvMngList);
1564 RXvFreeRCB(pRCB, bReAllocSkb);
1566 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rx Mng Only we have the right to free RCB\n");
1570 pDevice->bIsRxMngWorkItemQueued = FALSE;
1571 spin_unlock_irq(&pDevice->lock);