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_INFO;
66 static const unsigned char acbyRxRate[MAX_RATE] =
67 {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
69 /*--------------------- Static Functions --------------------------*/
71 /*--------------------- Static Definitions -------------------------*/
73 /*--------------------- Static Functions --------------------------*/
75 static unsigned char s_byGetRateIdx(unsigned char byRate);
78 s_vGetDASA(unsigned char *pbyRxBufferAddr, unsigned int *pcbHeaderSize,
79 PSEthernetHeader psEthHeader);
82 s_vProcessRxMACHeader(PSDevice pDevice, unsigned char *pbyRxBufferAddr,
83 unsigned int cbPacketSize, bool bIsWEP, bool bExtIV,
84 unsigned int *pcbHeadSize);
86 static bool s_bAPModeRxCtl(
88 unsigned char *pbyFrame,
92 static bool s_bAPModeRxData(
95 unsigned int FrameSize,
96 unsigned int cbHeaderOffset,
101 static bool s_bHandleRxEncryption(
103 unsigned char *pbyFrame,
104 unsigned int FrameSize,
105 unsigned char *pbyRsr,
106 unsigned char *pbyNewRsr,
109 unsigned short *pwRxTSC15_0,
110 unsigned long *pdwRxTSC47_16
113 static bool s_bHostWepRxEncryption(
116 unsigned char *pbyFrame,
117 unsigned int FrameSize,
118 unsigned char *pbyRsr,
121 unsigned char *pbyNewRsr,
123 unsigned short *pwRxTSC15_0,
124 unsigned long *pdwRxTSC47_16
128 /*--------------------- Export Variables --------------------------*/
133 * Translate Rcv 802.11 header to 802.3 header with Rx buffer
138 * dwRxBufferAddr - Address of Rcv Buffer
139 * cbPacketSize - Rcv Packet size
140 * bIsWEP - If Rcv with WEP
142 * pcbHeaderSize - 802.11 header size
148 s_vProcessRxMACHeader(PSDevice pDevice, unsigned char *pbyRxBufferAddr,
149 unsigned int cbPacketSize, bool bIsWEP, bool bExtIV,
150 unsigned int *pcbHeadSize)
152 unsigned char *pbyRxBuffer;
153 unsigned int cbHeaderSize = 0;
154 unsigned short *pwType;
155 PS802_11Header pMACHeader;
158 pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
160 s_vGetDASA((unsigned char *)pMACHeader, &cbHeaderSize, &pDevice->sRxEthHeader);
164 // strip IV&ExtIV , add 8 byte
165 cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 8);
167 // strip IV , add 4 byte
168 cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 4);
171 cbHeaderSize += WLAN_HDR_ADDR3_LEN;
174 pbyRxBuffer = (unsigned char *)(pbyRxBufferAddr + cbHeaderSize);
175 if (ether_addr_equal(pbyRxBuffer, pDevice->abySNAP_Bridgetunnel)) {
177 } else if (ether_addr_equal(pbyRxBuffer, pDevice->abySNAP_RFC1042)) {
179 pwType = (unsigned short *)(pbyRxBufferAddr + cbHeaderSize);
180 if ((*pwType != TYPE_PKT_IPX) && (*pwType != cpu_to_le16(0xF380))) {
183 pwType = (unsigned short *)(pbyRxBufferAddr + cbHeaderSize);
186 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8); // 8 is IV&ExtIV
188 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4); // 4 is IV
191 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
196 pwType = (unsigned short *)(pbyRxBufferAddr + cbHeaderSize);
199 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8); // 8 is IV&ExtIV
201 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4); // 4 is IV
204 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
208 cbHeaderSize -= (ETH_ALEN * 2);
209 pbyRxBuffer = (unsigned char *)(pbyRxBufferAddr + cbHeaderSize);
210 for (ii = 0; ii < ETH_ALEN; ii++)
211 *pbyRxBuffer++ = pDevice->sRxEthHeader.abyDstAddr[ii];
212 for (ii = 0; ii < ETH_ALEN; ii++)
213 *pbyRxBuffer++ = pDevice->sRxEthHeader.abySrcAddr[ii];
215 *pcbHeadSize = cbHeaderSize;
218 static unsigned char s_byGetRateIdx(unsigned char byRate)
220 unsigned char byRateIdx;
222 for (byRateIdx = 0; byRateIdx < MAX_RATE; byRateIdx++) {
223 if (acbyRxRate[byRateIdx % MAX_RATE] == byRate)
231 s_vGetDASA(unsigned char *pbyRxBufferAddr, unsigned int *pcbHeaderSize,
232 PSEthernetHeader psEthHeader)
234 unsigned int cbHeaderSize = 0;
235 PS802_11Header pMACHeader;
238 pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
240 if ((pMACHeader->wFrameCtl & FC_TODS) == 0) {
241 if (pMACHeader->wFrameCtl & FC_FROMDS) {
242 for (ii = 0; ii < ETH_ALEN; ii++) {
243 psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr1[ii];
244 psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr3[ii];
248 for (ii = 0; ii < ETH_ALEN; ii++) {
249 psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr1[ii];
250 psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr2[ii];
255 if (pMACHeader->wFrameCtl & FC_FROMDS) {
256 for (ii = 0; ii < ETH_ALEN; ii++) {
257 psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr3[ii];
258 psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr4[ii];
262 for (ii = 0; ii < ETH_ALEN; ii++) {
263 psEthHeader->abyDstAddr[ii] = pMACHeader->abyAddr3[ii];
264 psEthHeader->abySrcAddr[ii] = pMACHeader->abyAddr2[ii];
268 *pcbHeaderSize = cbHeaderSize;
272 device_receive_frame(
277 PDEVICE_RD_INFO pRDInfo = pCurrRD->pRDInfo;
278 struct net_device_stats *pStats = &pDevice->stats;
280 PSMgmtObject pMgmt = pDevice->pMgmt;
281 PSRxMgmtPacket pRxPacket = &(pDevice->pMgmt->sRxPacket);
282 PS802_11Header p802_11Header;
283 unsigned char *pbyRsr;
284 unsigned char *pbyNewRsr;
285 unsigned char *pbyRSSI;
287 unsigned short *pwFrameSize;
288 unsigned char *pbyFrame;
289 bool bDeFragRx = false;
291 unsigned int cbHeaderOffset;
292 unsigned int FrameSize;
293 unsigned short wEtherType = 0;
294 int iSANodeIndex = -1;
295 int iDANodeIndex = -1;
297 unsigned int cbIVOffset;
299 unsigned char *pbyRxSts;
300 unsigned char *pbyRxRate;
301 unsigned char *pbySQ;
302 unsigned int cbHeaderSize;
303 PSKeyItem pKey = NULL;
304 unsigned short wRxTSC15_0 = 0;
305 unsigned long dwRxTSC47_16 = 0;
308 unsigned long dwDuration = 0;
310 long ldBmThreshold = 0;
311 PS802_11Header pMACHeader;
312 bool bRxeapol_key = false;
317 pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
318 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
320 pwFrameSize = (unsigned short *)(skb->data + 2);
321 FrameSize = cpu_to_le16(pCurrRD->m_rd1RD1.wReqCount) - cpu_to_le16(pCurrRD->m_rd0RD0.wResCount);
323 // Max: 2312Payload + 30HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
324 // Min (ACK): 10HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
325 if ((FrameSize > 2364) || (FrameSize <= 32)) {
326 // Frame Size error drop this packet.
327 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---------- WRONG Length 1\n");
331 pbyRxSts = (unsigned char *)(skb->data);
332 pbyRxRate = (unsigned char *)(skb->data + 1);
333 pbyRsr = (unsigned char *)(skb->data + FrameSize - 1);
334 pbyRSSI = (unsigned char *)(skb->data + FrameSize - 2);
335 pbyNewRsr = (unsigned char *)(skb->data + FrameSize - 3);
336 pbySQ = (unsigned char *)(skb->data + FrameSize - 4);
337 pqwTSFTime = (PQWORD)(skb->data + FrameSize - 12);
338 pbyFrame = (unsigned char *)(skb->data + 4);
341 FrameSize = cpu_to_le16(*pwFrameSize);
343 if ((FrameSize > 2346)|(FrameSize < 14)) { // Max: 2312Payload + 30HD +4CRC
345 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---------- WRONG Length 2\n");
349 // update receive statistic counter
350 STAvUpdateRDStatCounter(&pDevice->scStatistic,
357 pMACHeader = (PS802_11Header)((unsigned char *)(skb->data) + 8);
359 if (pDevice->bMeasureInProgress) {
360 if ((*pbyRsr & RSR_CRCOK) != 0)
361 pDevice->byBasicMap |= 0x01;
363 dwDuration = (FrameSize << 4);
364 dwDuration /= acbyRxRate[*pbyRxRate%MAX_RATE];
365 if (*pbyRxRate <= RATE_11M) {
366 if (*pbyRxSts & 0x01) {
376 RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
378 for (ii = 7; ii > 0;) {
379 if (ldBm > ldBmThreshold)
385 pDevice->dwRPIs[ii] += dwDuration;
389 if (!is_multicast_ether_addr(pbyFrame)) {
390 if (WCTLbIsDuplicate(&(pDevice->sDupRxCache), (PS802_11Header)(skb->data + 4))) {
391 pDevice->s802_11Counter.FrameDuplicateCount++;
397 s_vGetDASA(skb->data+4, &cbHeaderSize, &pDevice->sRxEthHeader);
399 // filter packet send from myself
400 if (ether_addr_equal(pDevice->sRxEthHeader.abySrcAddr,
401 pDevice->abyCurrentNetAddr))
404 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
405 if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
406 p802_11Header = (PS802_11Header)(pbyFrame);
408 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(p802_11Header->abyAddr2), &iSANodeIndex)) {
409 pMgmt->sNodeDBTable[iSANodeIndex].ulLastRxJiffer = jiffies;
410 pMgmt->sNodeDBTable[iSANodeIndex].uInActiveCount = 0;
415 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
416 if (s_bAPModeRxCtl(pDevice, pbyFrame, iSANodeIndex))
420 if (IS_FC_WEP(pbyFrame)) {
421 bool bRxDecryOK = false;
423 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx WEP pkt\n");
425 if ((pDevice->bEnableHostWEP) && (iSANodeIndex >= 0)) {
427 pKey->byCipherSuite = pMgmt->sNodeDBTable[iSANodeIndex].byCipherSuite;
428 pKey->dwKeyIndex = pMgmt->sNodeDBTable[iSANodeIndex].dwKeyIndex;
429 pKey->uKeyLength = pMgmt->sNodeDBTable[iSANodeIndex].uWepKeyLength;
430 pKey->dwTSC47_16 = pMgmt->sNodeDBTable[iSANodeIndex].dwTSC47_16;
431 pKey->wTSC15_0 = pMgmt->sNodeDBTable[iSANodeIndex].wTSC15_0;
433 &pMgmt->sNodeDBTable[iSANodeIndex].abyWepKey[0],
437 bRxDecryOK = s_bHostWepRxEncryption(pDevice,
441 pMgmt->sNodeDBTable[iSANodeIndex].bOnFly,
448 bRxDecryOK = s_bHandleRxEncryption(pDevice,
460 if ((*pbyNewRsr & NEWRSR_DECRYPTOK) == 0) {
461 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ICV Fail\n");
462 if ((pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
463 (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
464 (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
465 (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
466 (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
467 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP))
468 pDevice->s802_11Counter.TKIPICVErrors++;
469 else if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP))
470 pDevice->s802_11Counter.CCMPDecryptErrors++;
475 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WEP Func Fail\n");
478 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP))
479 FrameSize -= 8; // Message Integrity Code
481 FrameSize -= 4; // 4 is ICV
487 //remove the CRC length
488 FrameSize -= ETH_FCS_LEN;
490 if ((!(*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI))) && // unicast address
491 (IS_FRAGMENT_PKT((skb->data+4)))
494 bDeFragRx = WCTLbHandleFragment(pDevice, (PS802_11Header)(skb->data+4), FrameSize, bIsWEP, bExtIV);
495 pDevice->s802_11Counter.ReceivedFragmentCount++;
498 skb = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb;
499 FrameSize = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength;
506 // Management & Control frame Handle
507 if ((IS_TYPE_DATA((skb->data+4))) == false) {
508 // Handle Control & Manage Frame
510 if (IS_TYPE_MGMT((skb->data+4))) {
511 unsigned char *pbyData1;
512 unsigned char *pbyData2;
514 pRxPacket->p80211Header = (PUWLAN_80211HDR)(skb->data+4);
515 pRxPacket->cbMPDULen = FrameSize;
516 pRxPacket->uRSSI = *pbyRSSI;
517 pRxPacket->bySQ = *pbySQ;
518 HIDWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(HIDWORD(*pqwTSFTime));
519 LODWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(LODWORD(*pqwTSFTime));
522 pbyData1 = WLAN_HDR_A3_DATA_PTR(skb->data+4);
523 pbyData2 = WLAN_HDR_A3_DATA_PTR(skb->data+4) + 4;
524 for (ii = 0; ii < (FrameSize - 4); ii++) {
525 *pbyData1 = *pbyData2;
530 pRxPacket->byRxRate = s_byGetRateIdx(*pbyRxRate);
531 pRxPacket->byRxChannel = (*pbyRxSts) >> 2;
533 vMgrRxManagePacket((void *)pDevice, pDevice->pMgmt, pRxPacket);
535 // hostap Deamon handle 802.11 management
536 if (pDevice->bEnableHostapd) {
537 skb->dev = pDevice->apdev;
540 skb_put(skb, FrameSize);
541 skb_reset_mac_header(skb);
542 skb->pkt_type = PACKET_OTHERHOST;
543 skb->protocol = htons(ETH_P_802_2);
544 memset(skb->cb, 0, sizeof(skb->cb));
552 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
553 //In AP mode, hw only check addr1(BSSID or RA) if equal to local MAC.
554 if (!(*pbyRsr & RSR_BSSIDOK)) {
556 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
557 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc more frag bufs\n",
564 // discard DATA packet while not associate || BSSID error
565 if (!pDevice->bLinkPass || !(*pbyRsr & RSR_BSSIDOK)) {
567 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
568 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc more frag bufs\n",
574 //mike add:station mode check eapol-key challenge--->
576 unsigned char Protocol_Version; //802.1x Authentication
577 unsigned char Packet_Type; //802.1x Authentication
583 wEtherType = (skb->data[cbIVOffset + 8 + 24 + 6] << 8) |
584 skb->data[cbIVOffset + 8 + 24 + 6 + 1];
585 Protocol_Version = skb->data[cbIVOffset + 8 + 24 + 6 + 1 + 1];
586 Packet_Type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 + 1 + 1];
587 if (wEtherType == ETH_P_PAE) { //Protocol Type in LLC-Header
588 if (((Protocol_Version == 1) || (Protocol_Version == 2)) &&
589 (Packet_Type == 3)) { //802.1x OR eapol-key challenge frame receive
594 //mike add:station mode check eapol-key challenge<---
600 if (pDevice->bEnablePSMode) {
601 if (!IS_FC_MOREDATA((skb->data+4))) {
602 if (pDevice->pMgmt->bInTIMWake == true)
603 pDevice->pMgmt->bInTIMWake = false;
607 // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps
608 if (pDevice->bDiversityEnable && (FrameSize > 50) &&
609 (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
610 pDevice->bLinkPass) {
611 BBvAntennaDiversity(pDevice, s_byGetRateIdx(*pbyRxRate), 0);
614 if (pDevice->byLocalID != REV_ID_VT3253_B1)
615 pDevice->uCurrRSSI = *pbyRSSI;
617 pDevice->byCurrSQ = *pbySQ;
619 if ((*pbyRSSI != 0) &&
620 (pMgmt->pCurrBSS != NULL)) {
621 RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
622 // Monitor if RSSI is too strong.
623 pMgmt->pCurrBSS->byRSSIStatCnt++;
624 pMgmt->pCurrBSS->byRSSIStatCnt %= RSSI_STAT_COUNT;
625 pMgmt->pCurrBSS->ldBmAverage[pMgmt->pCurrBSS->byRSSIStatCnt] = ldBm;
626 for (ii = 0; ii < RSSI_STAT_COUNT; ii++)
627 if (pMgmt->pCurrBSS->ldBmAverage[ii] != 0)
628 pMgmt->pCurrBSS->ldBmMAX = max(pMgmt->pCurrBSS->ldBmAverage[ii], ldBm);
632 // -----------------------------------------------
634 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && pDevice->bEnable8021x) {
635 unsigned char abyMacHdr[24];
637 // Only 802.1x packet incoming allowed
642 wEtherType = (skb->data[cbIVOffset + 4 + 24 + 6] << 8) |
643 skb->data[cbIVOffset + 4 + 24 + 6 + 1];
645 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wEtherType = %04x\n", wEtherType);
646 if (wEtherType == ETH_P_PAE) {
647 skb->dev = pDevice->apdev;
650 // strip IV header(8)
651 memcpy(&abyMacHdr[0], (skb->data + 4), 24);
652 memcpy((skb->data + 4 + cbIVOffset), &abyMacHdr[0], 24);
654 skb->data += (cbIVOffset + 4);
655 skb->tail += (cbIVOffset + 4);
656 skb_put(skb, FrameSize);
657 skb_reset_mac_header(skb);
659 skb->pkt_type = PACKET_OTHERHOST;
660 skb->protocol = htons(ETH_P_802_2);
661 memset(skb->cb, 0, sizeof(skb->cb));
666 // check if 802.1x authorized
667 if (!(pMgmt->sNodeDBTable[iSANodeIndex].dwFlags & WLAN_STA_AUTHORIZED))
671 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
673 FrameSize -= 8; //MIC
676 //--------------------------------------------------------------------------------
678 if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
682 __le32 dwMIC_Priority;
683 __le32 dwMICKey0 = 0, dwMICKey1 = 0;
684 u32 dwLocalMIC_L = 0;
685 u32 dwLocalMIC_R = 0;
686 viawget_wpa_header *wpahdr;
688 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
689 dwMICKey0 = cpu_to_le32(*(u32 *)(&pKey->abyKey[24]));
690 dwMICKey1 = cpu_to_le32(*(u32 *)(&pKey->abyKey[28]));
692 if (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
693 dwMICKey0 = cpu_to_le32(*(u32 *)(&pKey->abyKey[16]));
694 dwMICKey1 = cpu_to_le32(*(u32 *)(&pKey->abyKey[20]));
695 } else if ((pKey->dwKeyIndex & BIT28) == 0) {
696 dwMICKey0 = cpu_to_le32(*(u32 *)(&pKey->abyKey[16]));
697 dwMICKey1 = cpu_to_le32(*(u32 *)(&pKey->abyKey[20]));
699 dwMICKey0 = cpu_to_le32(*(u32 *)(&pKey->abyKey[24]));
700 dwMICKey1 = cpu_to_le32(*(u32 *)(&pKey->abyKey[28]));
704 MIC_vInit(dwMICKey0, dwMICKey1);
705 MIC_vAppend((unsigned char *)&(pDevice->sRxEthHeader.abyDstAddr[0]), 12);
707 MIC_vAppend((unsigned char *)&dwMIC_Priority, 4);
708 // 4 is Rcv buffer header, 24 is MAC Header, and 8 is IV and Ext IV.
709 MIC_vAppend((unsigned char *)(skb->data + 4 + WLAN_HDR_ADDR3_LEN + 8),
710 FrameSize - WLAN_HDR_ADDR3_LEN - 8);
711 MIC_vGetMIC(&dwLocalMIC_L, &dwLocalMIC_R);
714 pdwMIC_L = (__le32 *)(skb->data + 4 + FrameSize);
715 pdwMIC_R = (__le32 *)(skb->data + 4 + FrameSize + 4);
717 if ((le32_to_cpu(*pdwMIC_L) != dwLocalMIC_L) ||
718 (le32_to_cpu(*pdwMIC_R) != dwLocalMIC_R) ||
719 pDevice->bRxMICFail) {
720 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "MIC comparison is fail!\n");
721 pDevice->bRxMICFail = false;
722 pDevice->s802_11Counter.TKIPLocalMICFailures++;
724 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
725 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc more frag bufs\n",
729 //2008-0409-07, <Add> by Einsn Liu
730 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
731 //send event to wpa_supplicant
733 union iwreq_data wrqu;
734 struct iw_michaelmicfailure ev;
735 int keyidx = pbyFrame[cbHeaderSize+3] >> 6; //top two-bits
737 memset(&ev, 0, sizeof(ev));
738 ev.flags = keyidx & IW_MICFAILURE_KEY_ID;
739 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
740 (pMgmt->eCurrState == WMAC_STATE_ASSOC) &&
741 (*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) {
742 ev.flags |= IW_MICFAILURE_PAIRWISE;
744 ev.flags |= IW_MICFAILURE_GROUP;
747 ev.src_addr.sa_family = ARPHRD_ETHER;
748 memcpy(ev.src_addr.sa_data, pMACHeader->abyAddr2, ETH_ALEN);
749 memset(&wrqu, 0, sizeof(wrqu));
750 wrqu.data.length = sizeof(ev);
751 wireless_send_event(pDevice->dev, IWEVMICHAELMICFAILURE, &wrqu, (char *)&ev);
756 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
757 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
758 if ((pDevice->pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
759 (pDevice->pMgmt->eCurrState == WMAC_STATE_ASSOC) &&
760 (*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) {
761 wpahdr->type = VIAWGET_PTK_MIC_MSG;
763 wpahdr->type = VIAWGET_GTK_MIC_MSG;
765 wpahdr->resp_ie_len = 0;
766 wpahdr->req_ie_len = 0;
767 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
768 pDevice->skb->dev = pDevice->wpadev;
769 skb_reset_mac_header(pDevice->skb);
770 pDevice->skb->pkt_type = PACKET_HOST;
771 pDevice->skb->protocol = htons(ETH_P_802_2);
772 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
773 netif_rx(pDevice->skb);
774 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
781 } //---end of SOFT MIC-----------------------------------------------------------------------
783 // ++++++++++ Reply Counter Check +++++++++++++
785 if ((pKey != NULL) && ((pKey->byCipherSuite == KEY_CTL_TKIP) ||
786 (pKey->byCipherSuite == KEY_CTL_CCMP))) {
788 unsigned short wLocalTSC15_0 = 0;
789 unsigned long dwLocalTSC47_16 = 0;
790 unsigned long long RSC = 0;
792 RSC = *((unsigned long long *)&(pKey->KeyRSC));
793 wLocalTSC15_0 = (unsigned short)RSC;
794 dwLocalTSC47_16 = (unsigned long)(RSC>>16);
799 memcpy(&(pKey->KeyRSC), &RSC, sizeof(QWORD));
801 if ((pDevice->sMgmtObj.eCurrMode == WMAC_MODE_ESS_STA) &&
802 (pDevice->sMgmtObj.eCurrState == WMAC_STATE_ASSOC)) {
804 if ((wRxTSC15_0 < wLocalTSC15_0) &&
805 (dwRxTSC47_16 <= dwLocalTSC47_16) &&
806 !((dwRxTSC47_16 == 0) && (dwLocalTSC47_16 == 0xFFFFFFFF))) {
807 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "TSC is illegal~~!\n ");
808 if (pKey->byCipherSuite == KEY_CTL_TKIP)
809 pDevice->s802_11Counter.TKIPReplays++;
811 pDevice->s802_11Counter.CCMPReplays++;
814 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
815 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc more frag bufs\n",
823 } // ----- End of Reply Counter Check --------------------------
825 s_vProcessRxMACHeader(pDevice, (unsigned char *)(skb->data+4), FrameSize, bIsWEP, bExtIV, &cbHeaderOffset);
826 FrameSize -= cbHeaderOffset;
827 cbHeaderOffset += 4; // 4 is Rcv buffer header
829 // Null data, framesize = 14
833 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
834 if (!s_bAPModeRxData(pDevice,
842 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
843 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc more frag bufs\n",
851 skb->data += cbHeaderOffset;
852 skb->tail += cbHeaderOffset;
853 skb_put(skb, FrameSize);
854 skb->protocol = eth_type_trans(skb, skb->dev);
856 //drop frame not met IEEE 802.3
858 skb->ip_summed = CHECKSUM_NONE;
859 pStats->rx_bytes += skb->len;
860 pStats->rx_packets++;
864 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
865 DBG_PRT(MSG_LEVEL_ERR, KERN_ERR "%s: can not alloc more frag bufs\n",
874 static bool s_bAPModeRxCtl(
876 unsigned char *pbyFrame,
880 PS802_11Header p802_11Header;
882 PSMgmtObject pMgmt = pDevice->pMgmt;
884 if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
885 p802_11Header = (PS802_11Header)(pbyFrame);
886 if (!IS_TYPE_MGMT(pbyFrame)) {
887 // Data & PS-Poll packet
889 if (iSANodeIndex > 0) {
890 // frame class 3 fliter & checking
891 if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_AUTH) {
892 // send deauth notification
893 // reason = (6) class 2 received from nonauth sta
894 vMgrDeAuthenBeginSta(pDevice,
896 (unsigned char *)(p802_11Header->abyAddr2),
897 (WLAN_MGMT_REASON_CLASS2_NONAUTH),
900 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 1\n");
903 if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_ASSOC) {
904 // send deassoc notification
905 // reason = (7) class 3 received from nonassoc sta
906 vMgrDisassocBeginSta(pDevice,
908 (unsigned char *)(p802_11Header->abyAddr2),
909 (WLAN_MGMT_REASON_CLASS3_NONASSOC),
912 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDisassocBeginSta 2\n");
916 if (pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable) {
917 // delcare received ps-poll event
918 if (IS_CTL_PSPOLL(pbyFrame)) {
919 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true;
920 bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
921 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 1\n");
923 // check Data PS state
924 // if PW bit off, send out all PS bufferring packets.
925 if (!IS_FC_POWERMGT(pbyFrame)) {
926 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = false;
927 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true;
928 bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
929 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 2\n");
933 if (IS_FC_POWERMGT(pbyFrame)) {
934 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = true;
935 // Once if STA in PS state, enable multicast bufferring
936 pMgmt->sNodeDBTable[0].bPSEnable = true;
938 // clear all pending PS frame.
939 if (pMgmt->sNodeDBTable[iSANodeIndex].wEnQueueCnt > 0) {
940 pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = false;
941 pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = true;
942 bScheduleCommand((void *)pDevice, WLAN_CMD_RX_PSPOLL, NULL);
943 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 3\n");
949 vMgrDeAuthenBeginSta(pDevice,
951 (unsigned char *)(p802_11Header->abyAddr2),
952 (WLAN_MGMT_REASON_CLASS2_NONAUTH),
955 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 3\n");
956 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSID:%pM\n",
957 p802_11Header->abyAddr3);
958 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR2:%pM\n",
959 p802_11Header->abyAddr2);
960 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR1:%pM\n",
961 p802_11Header->abyAddr1);
962 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: wFrameCtl= %x\n", p802_11Header->wFrameCtl);
963 VNSvInPortB(pDevice->PortOffset + MAC_REG_RCR, &(pDevice->byRxMode));
964 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc:pDevice->byRxMode = %x\n", pDevice->byRxMode);
972 static bool s_bHandleRxEncryption(
974 unsigned char *pbyFrame,
975 unsigned int FrameSize,
976 unsigned char *pbyRsr,
977 unsigned char *pbyNewRsr,
980 unsigned short *pwRxTSC15_0,
981 unsigned long *pdwRxTSC47_16
984 unsigned int PayloadLen = FrameSize;
985 unsigned char *pbyIV;
986 unsigned char byKeyIdx;
987 PSKeyItem pKey = NULL;
988 unsigned char byDecMode = KEY_CTL_WEP;
989 PSMgmtObject pMgmt = pDevice->pMgmt;
994 pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
995 if (WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame) &&
996 WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame)) {
997 pbyIV += 6; // 6 is 802.11 address4
1000 byKeyIdx = (*(pbyIV+3) & 0xc0);
1002 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\nKeyIdx: %d\n", byKeyIdx);
1004 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
1005 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
1006 (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
1007 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
1008 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
1009 if (((*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) &&
1010 (pDevice->pMgmt->byCSSPK != KEY_CTL_NONE)) {
1011 // unicast pkt use pairwise key
1012 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "unicast pkt\n");
1013 if (KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, 0xFFFFFFFF, &pKey) == true) {
1014 if (pDevice->pMgmt->byCSSPK == KEY_CTL_TKIP)
1015 byDecMode = KEY_CTL_TKIP;
1016 else if (pDevice->pMgmt->byCSSPK == KEY_CTL_CCMP)
1017 byDecMode = KEY_CTL_CCMP;
1019 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "unicast pkt: %d, %p\n", byDecMode, pKey);
1022 KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, byKeyIdx, &pKey);
1023 if (pDevice->pMgmt->byCSSGK == KEY_CTL_TKIP)
1024 byDecMode = KEY_CTL_TKIP;
1025 else if (pDevice->pMgmt->byCSSGK == KEY_CTL_CCMP)
1026 byDecMode = KEY_CTL_CCMP;
1027 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "group pkt: %d, %d, %p\n", byKeyIdx, byDecMode, pKey);
1030 // our WEP only support Default Key
1032 // use default group key
1033 KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, byKeyIdx, &pKey);
1034 if (pDevice->pMgmt->byCSSGK == KEY_CTL_TKIP)
1035 byDecMode = KEY_CTL_TKIP;
1036 else if (pDevice->pMgmt->byCSSGK == KEY_CTL_CCMP)
1037 byDecMode = KEY_CTL_CCMP;
1041 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "AES:%d %d %d\n", pDevice->pMgmt->byCSSPK, pDevice->pMgmt->byCSSGK, byDecMode);
1044 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pKey == NULL\n");
1048 if (byDecMode != pKey->byCipherSuite) {
1053 if (byDecMode == KEY_CTL_WEP) {
1055 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
1056 (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == true)) {
1061 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1062 memcpy(pDevice->abyPRNG, pbyIV, 3);
1063 memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
1064 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
1065 rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
1067 if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen))
1068 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1071 } else if ((byDecMode == KEY_CTL_TKIP) ||
1072 (byDecMode == KEY_CTL_CCMP)) {
1075 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1076 *pdwRxTSC47_16 = cpu_to_le32(*(unsigned long *)(pbyIV + 4));
1077 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ExtIV: %lx\n", *pdwRxTSC47_16);
1078 if (byDecMode == KEY_CTL_TKIP)
1079 *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV + 2), *pbyIV));
1081 *pwRxTSC15_0 = cpu_to_le16(*(unsigned short *)pbyIV);
1083 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "TSC0_15: %x\n", *pwRxTSC15_0);
1085 if ((byDecMode == KEY_CTL_TKIP) &&
1086 (pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1089 PS802_11Header pMACHeader = (PS802_11Header)(pbyFrame);
1091 TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
1092 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
1093 rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
1094 if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
1095 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1096 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ICV OK!\n");
1098 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ICV FAIL!!!\n");
1099 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PayloadLen = %d\n", PayloadLen);
1104 if ((*(pbyIV+3) & 0x20) != 0)
1109 static bool s_bHostWepRxEncryption(
1111 unsigned char *pbyFrame,
1112 unsigned int FrameSize,
1113 unsigned char *pbyRsr,
1116 unsigned char *pbyNewRsr,
1118 unsigned short *pwRxTSC15_0,
1119 unsigned long *pdwRxTSC47_16
1122 unsigned int PayloadLen = FrameSize;
1123 unsigned char *pbyIV;
1124 unsigned char byKeyIdx;
1125 unsigned char byDecMode = KEY_CTL_WEP;
1126 PS802_11Header pMACHeader;
1131 pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
1132 if (WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame) &&
1133 WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame)) {
1134 pbyIV += 6; // 6 is 802.11 address4
1137 byKeyIdx = (*(pbyIV+3) & 0xc0);
1139 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "\nKeyIdx: %d\n", byKeyIdx);
1141 if (pDevice->pMgmt->byCSSGK == KEY_CTL_TKIP)
1142 byDecMode = KEY_CTL_TKIP;
1143 else if (pDevice->pMgmt->byCSSGK == KEY_CTL_CCMP)
1144 byDecMode = KEY_CTL_CCMP;
1146 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "AES:%d %d %d\n", pDevice->pMgmt->byCSSPK, pDevice->pMgmt->byCSSGK, byDecMode);
1148 if (byDecMode != pKey->byCipherSuite)
1151 if (byDecMode == KEY_CTL_WEP) {
1153 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "byDecMode == KEY_CTL_WEP\n");
1155 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
1156 (((PSKeyTable)(pKey->pvKeyTable))->bSoftWEP == true) ||
1163 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1164 memcpy(pDevice->abyPRNG, pbyIV, 3);
1165 memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
1166 rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
1167 rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
1169 if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen))
1170 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1173 } else if ((byDecMode == KEY_CTL_TKIP) ||
1174 (byDecMode == KEY_CTL_CCMP)) {
1177 PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1178 *pdwRxTSC47_16 = cpu_to_le32(*(unsigned long *)(pbyIV + 4));
1179 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ExtIV: %lx\n", *pdwRxTSC47_16);
1181 if (byDecMode == KEY_CTL_TKIP)
1182 *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
1184 *pwRxTSC15_0 = cpu_to_le16(*(unsigned short *)pbyIV);
1186 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "TSC0_15: %x\n", *pwRxTSC15_0);
1188 if (byDecMode == KEY_CTL_TKIP) {
1189 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || !bOnFly) {
1193 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "soft KEY_CTL_TKIP\n");
1194 pMACHeader = (PS802_11Header)(pbyFrame);
1195 TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
1196 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
1197 rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
1198 if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
1199 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1200 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ICV OK!\n");
1202 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ICV FAIL!!!\n");
1203 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PayloadLen = %d\n", PayloadLen);
1208 if (byDecMode == KEY_CTL_CCMP) {
1212 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "soft KEY_CTL_CCMP\n");
1213 if (AESbGenCCMP(pKey->abyKey, pbyFrame, FrameSize)) {
1214 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1215 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CCMP MIC compare OK!\n");
1217 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "CCMP MIC fail!\n");
1224 if ((*(pbyIV+3) & 0x20) != 0)
1229 static bool s_bAPModeRxData(
1231 struct sk_buff *skb,
1232 unsigned int FrameSize,
1233 unsigned int cbHeaderOffset,
1238 PSMgmtObject pMgmt = pDevice->pMgmt;
1239 bool bRelayAndForward = false;
1240 bool bRelayOnly = false;
1241 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1242 unsigned short wAID;
1244 struct sk_buff *skbcpy = NULL;
1246 if (FrameSize > CB_MAX_BUF_SIZE)
1249 if (is_multicast_ether_addr((unsigned char *)(skb->data+cbHeaderOffset))) {
1250 if (pMgmt->sNodeDBTable[0].bPSEnable) {
1251 skbcpy = dev_alloc_skb((int)pDevice->rx_buf_sz);
1253 // if any node in PS mode, buffer packet until DTIM.
1254 if (skbcpy == NULL) {
1255 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "relay multicast no skb available\n");
1257 skbcpy->dev = pDevice->dev;
1258 skbcpy->len = FrameSize;
1259 memcpy(skbcpy->data, skb->data+cbHeaderOffset, FrameSize);
1260 skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skbcpy);
1262 pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1264 pMgmt->abyPSTxMap[0] |= byMask[0];
1267 bRelayAndForward = true;
1271 if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(skb->data+cbHeaderOffset), &iDANodeIndex)) {
1272 if (pMgmt->sNodeDBTable[iDANodeIndex].eNodeState >= NODE_ASSOC) {
1273 if (pMgmt->sNodeDBTable[iDANodeIndex].bPSEnable) {
1274 // queue this skb until next PS tx, and then release.
1276 skb->data += cbHeaderOffset;
1277 skb->tail += cbHeaderOffset;
1278 skb_put(skb, FrameSize);
1279 skb_queue_tail(&pMgmt->sNodeDBTable[iDANodeIndex].sTxPSQueue, skb);
1280 pMgmt->sNodeDBTable[iDANodeIndex].wEnQueueCnt++;
1281 wAID = pMgmt->sNodeDBTable[iDANodeIndex].wAID;
1282 pMgmt->abyPSTxMap[wAID >> 3] |= byMask[wAID & 7];
1283 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n",
1284 iDANodeIndex, (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
1293 if (bRelayOnly || bRelayAndForward) {
1294 // relay this packet right now
1295 if (bRelayAndForward)
1298 if ((pDevice->uAssocCount > 1) && (iDANodeIndex >= 0))
1299 ROUTEbRelay(pDevice, (unsigned char *)(skb->data + cbHeaderOffset), FrameSize, (unsigned int)iDANodeIndex);
1304 // none associate, don't forward
1305 if (pDevice->uAssocCount == 0)