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
60 /*--------------------- Static Definitions -------------------------*/
62 /*--------------------- Static Classes ----------------------------*/
64 /*--------------------- Static Variables --------------------------*/
65 //static int msglevel =MSG_LEVEL_DEBUG;
66 static int msglevel
=MSG_LEVEL_INFO
;
68 const unsigned char acbyRxRate
[MAX_RATE
] =
69 {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
72 /*--------------------- Static Functions --------------------------*/
74 /*--------------------- Static Definitions -------------------------*/
76 /*--------------------- Static Functions --------------------------*/
78 static unsigned char s_byGetRateIdx(unsigned char byRate
);
82 s_vGetDASA(unsigned char *pbyRxBufferAddr
, unsigned int *pcbHeaderSize
,
83 PSEthernetHeader psEthHeader
);
86 s_vProcessRxMACHeader(PSDevice pDevice
, unsigned char *pbyRxBufferAddr
,
87 unsigned int cbPacketSize
, bool bIsWEP
, bool bExtIV
,
88 unsigned int *pcbHeadSize
);
90 static bool s_bAPModeRxCtl(
92 unsigned char *pbyFrame
,
98 static bool s_bAPModeRxData (
101 unsigned int FrameSize
,
102 unsigned int cbHeaderOffset
,
108 static bool s_bHandleRxEncryption(
110 unsigned char *pbyFrame
,
111 unsigned int FrameSize
,
112 unsigned char *pbyRsr
,
113 unsigned char *pbyNewRsr
,
116 unsigned short *pwRxTSC15_0
,
117 unsigned long *pdwRxTSC47_16
120 static bool s_bHostWepRxEncryption(
123 unsigned char *pbyFrame
,
124 unsigned int FrameSize
,
125 unsigned char *pbyRsr
,
128 unsigned char *pbyNewRsr
,
130 unsigned short *pwRxTSC15_0
,
131 unsigned long *pdwRxTSC47_16
135 /*--------------------- Export Variables --------------------------*/
140 * Translate Rcv 802.11 header to 802.3 header with Rx buffer
145 * dwRxBufferAddr - Address of Rcv Buffer
146 * cbPacketSize - Rcv Packet size
147 * bIsWEP - If Rcv with WEP
149 * pcbHeaderSize - 802.11 header size
155 s_vProcessRxMACHeader(PSDevice pDevice
, unsigned char *pbyRxBufferAddr
,
156 unsigned int cbPacketSize
, bool bIsWEP
, bool bExtIV
,
157 unsigned int *pcbHeadSize
)
159 unsigned char *pbyRxBuffer
;
160 unsigned int cbHeaderSize
= 0;
161 unsigned short *pwType
;
162 PS802_11Header pMACHeader
;
166 pMACHeader
= (PS802_11Header
) (pbyRxBufferAddr
+ cbHeaderSize
);
168 s_vGetDASA((unsigned char *)pMACHeader
, &cbHeaderSize
, &pDevice
->sRxEthHeader
);
172 // strip IV&ExtIV , add 8 byte
173 cbHeaderSize
+= (WLAN_HDR_ADDR3_LEN
+ 8);
175 // strip IV , add 4 byte
176 cbHeaderSize
+= (WLAN_HDR_ADDR3_LEN
+ 4);
180 cbHeaderSize
+= WLAN_HDR_ADDR3_LEN
;
183 pbyRxBuffer
= (unsigned char *) (pbyRxBufferAddr
+ cbHeaderSize
);
184 if (!compare_ether_addr(pbyRxBuffer
, &pDevice
->abySNAP_Bridgetunnel
[0])) {
187 else if (!compare_ether_addr(pbyRxBuffer
, &pDevice
->abySNAP_RFC1042
[0])) {
189 pwType
= (unsigned short *) (pbyRxBufferAddr
+ cbHeaderSize
);
190 if ((*pwType
!= TYPE_PKT_IPX
) && (*pwType
!= cpu_to_le16(0xF380))) {
194 pwType
= (unsigned short *) (pbyRxBufferAddr
+ cbHeaderSize
);
197 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 8); // 8 is IV&ExtIV
199 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 4); // 4 is IV
203 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
);
209 pwType
= (unsigned short *) (pbyRxBufferAddr
+ cbHeaderSize
);
212 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 8); // 8 is IV&ExtIV
214 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 4); // 4 is IV
218 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
);
222 cbHeaderSize
-= (ETH_ALEN
* 2);
223 pbyRxBuffer
= (unsigned char *) (pbyRxBufferAddr
+ cbHeaderSize
);
224 for(ii
=0;ii
<ETH_ALEN
;ii
++)
225 *pbyRxBuffer
++ = pDevice
->sRxEthHeader
.abyDstAddr
[ii
];
226 for(ii
=0;ii
<ETH_ALEN
;ii
++)
227 *pbyRxBuffer
++ = pDevice
->sRxEthHeader
.abySrcAddr
[ii
];
229 *pcbHeadSize
= cbHeaderSize
;
235 static unsigned char s_byGetRateIdx (unsigned char byRate
)
237 unsigned char byRateIdx
;
239 for (byRateIdx
= 0; byRateIdx
<MAX_RATE
; byRateIdx
++) {
240 if (acbyRxRate
[byRateIdx
%MAX_RATE
] == byRate
)
248 s_vGetDASA(unsigned char *pbyRxBufferAddr
, unsigned int *pcbHeaderSize
,
249 PSEthernetHeader psEthHeader
)
251 unsigned int cbHeaderSize
= 0;
252 PS802_11Header pMACHeader
;
255 pMACHeader
= (PS802_11Header
) (pbyRxBufferAddr
+ cbHeaderSize
);
257 if ((pMACHeader
->wFrameCtl
& FC_TODS
) == 0) {
258 if (pMACHeader
->wFrameCtl
& FC_FROMDS
) {
259 for(ii
=0;ii
<ETH_ALEN
;ii
++) {
260 psEthHeader
->abyDstAddr
[ii
] = pMACHeader
->abyAddr1
[ii
];
261 psEthHeader
->abySrcAddr
[ii
] = pMACHeader
->abyAddr3
[ii
];
266 for(ii
=0;ii
<ETH_ALEN
;ii
++) {
267 psEthHeader
->abyDstAddr
[ii
] = pMACHeader
->abyAddr1
[ii
];
268 psEthHeader
->abySrcAddr
[ii
] = pMACHeader
->abyAddr2
[ii
];
274 if (pMACHeader
->wFrameCtl
& FC_FROMDS
) {
275 for(ii
=0;ii
<ETH_ALEN
;ii
++) {
276 psEthHeader
->abyDstAddr
[ii
] = pMACHeader
->abyAddr3
[ii
];
277 psEthHeader
->abySrcAddr
[ii
] = pMACHeader
->abyAddr4
[ii
];
282 for(ii
=0;ii
<ETH_ALEN
;ii
++) {
283 psEthHeader
->abyDstAddr
[ii
] = pMACHeader
->abyAddr3
[ii
];
284 psEthHeader
->abySrcAddr
[ii
] = pMACHeader
->abyAddr2
[ii
];
288 *pcbHeaderSize
= cbHeaderSize
;
296 void MngWorkItem(void *Context
)
298 PSRxMgmtPacket pRxMgmtPacket
;
299 PSDevice pDevice
= (PSDevice
) Context
;
300 //printk("Enter MngWorkItem,Queue packet num is %d\n",pDevice->rxManeQueue.packet_num);
301 spin_lock_irq(&pDevice
->lock
);
302 while(pDevice
->rxManeQueue
.packet_num
!= 0)
304 pRxMgmtPacket
= DeQueue(pDevice
);
305 vMgrRxManagePacket(pDevice
, pDevice
->pMgmt
, pRxMgmtPacket
);
307 spin_unlock_irq(&pDevice
->lock
);
316 device_receive_frame (
322 PDEVICE_RD_INFO pRDInfo
= pCurrRD
->pRDInfo
;
324 //printk("device_receive_frame:pCurrRD is %x,pRDInfo is %x\n",pCurrRD,pCurrRD->pRDInfo);
326 struct net_device_stats
* pStats
=&pDevice
->stats
;
328 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
329 PSRxMgmtPacket pRxPacket
= &(pDevice
->pMgmt
->sRxPacket
);
330 PS802_11Header p802_11Header
;
331 unsigned char *pbyRsr
;
332 unsigned char *pbyNewRsr
;
333 unsigned char *pbyRSSI
;
335 unsigned short *pwFrameSize
;
336 unsigned char *pbyFrame
;
337 bool bDeFragRx
= false;
339 unsigned int cbHeaderOffset
;
340 unsigned int FrameSize
;
341 unsigned short wEtherType
= 0;
342 int iSANodeIndex
= -1;
343 int iDANodeIndex
= -1;
345 unsigned int cbIVOffset
;
347 unsigned char *pbyRxSts
;
348 unsigned char *pbyRxRate
;
349 unsigned char *pbySQ
;
350 unsigned int cbHeaderSize
;
351 PSKeyItem pKey
= NULL
;
352 unsigned short wRxTSC15_0
= 0;
353 unsigned long dwRxTSC47_16
= 0;
356 unsigned long dwDuration
= 0;
358 long ldBmThreshold
= 0;
359 PS802_11Header pMACHeader
;
360 bool bRxeapol_key
= false;
362 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- device_receive_frame---\n");
369 pci_unmap_single(pDevice
->pcid
, pRDInfo
->skb_dma
,
370 pDevice
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
373 pwFrameSize
= (unsigned short *)(skb
->data
+ 2);
374 FrameSize
= cpu_to_le16(pCurrRD
->m_rd1RD1
.wReqCount
) - cpu_to_le16(pCurrRD
->m_rd0RD0
.wResCount
);
376 // Max: 2312Payload + 30HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
377 // Min (ACK): 10HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
378 if ((FrameSize
> 2364)||(FrameSize
<= 32)) {
379 // Frame Size error drop this packet.
380 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---------- WRONG Length 1 \n");
384 pbyRxSts
= (unsigned char *) (skb
->data
);
385 pbyRxRate
= (unsigned char *) (skb
->data
+ 1);
386 pbyRsr
= (unsigned char *) (skb
->data
+ FrameSize
- 1);
387 pbyRSSI
= (unsigned char *) (skb
->data
+ FrameSize
- 2);
388 pbyNewRsr
= (unsigned char *) (skb
->data
+ FrameSize
- 3);
389 pbySQ
= (unsigned char *) (skb
->data
+ FrameSize
- 4);
390 pqwTSFTime
= (PQWORD
) (skb
->data
+ FrameSize
- 12);
391 pbyFrame
= (unsigned char *)(skb
->data
+ 4);
394 FrameSize
= cpu_to_le16(*pwFrameSize
);
396 if ((FrameSize
> 2346)|(FrameSize
< 14)) { // Max: 2312Payload + 30HD +4CRC
398 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---------- WRONG Length 2 \n");
403 // update receive statistic counter
404 STAvUpdateRDStatCounter(&pDevice
->scStatistic
,
413 pMACHeader
=(PS802_11Header
)((unsigned char *) (skb
->data
)+8);
415 if (pDevice
->bMeasureInProgress
== true) {
416 if ((*pbyRsr
& RSR_CRCOK
) != 0) {
417 pDevice
->byBasicMap
|= 0x01;
419 dwDuration
= (FrameSize
<< 4);
420 dwDuration
/= acbyRxRate
[*pbyRxRate
%MAX_RATE
];
421 if (*pbyRxRate
<= RATE_11M
) {
422 if (*pbyRxSts
& 0x01) {
432 RFvRSSITodBm(pDevice
, *pbyRSSI
, &ldBm
);
434 for (ii
= 7; ii
> 0;) {
435 if (ldBm
> ldBmThreshold
) {
441 pDevice
->dwRPIs
[ii
] += dwDuration
;
445 if (!is_multicast_ether_addr(pbyFrame
)) {
446 if (WCTLbIsDuplicate(&(pDevice
->sDupRxCache
), (PS802_11Header
) (skb
->data
+ 4))) {
447 pDevice
->s802_11Counter
.FrameDuplicateCount
++;
454 s_vGetDASA(skb
->data
+4, &cbHeaderSize
, &pDevice
->sRxEthHeader
);
456 // filter packet send from myself
457 if (!compare_ether_addr((unsigned char *)&(pDevice
->sRxEthHeader
.abySrcAddr
[0]), pDevice
->abyCurrentNetAddr
))
460 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) || (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
)) {
461 if (IS_CTL_PSPOLL(pbyFrame
) || !IS_TYPE_CONTROL(pbyFrame
)) {
462 p802_11Header
= (PS802_11Header
) (pbyFrame
);
464 if (BSSDBbIsSTAInNodeDB(pMgmt
, (unsigned char *)(p802_11Header
->abyAddr2
), &iSANodeIndex
)) {
465 pMgmt
->sNodeDBTable
[iSANodeIndex
].ulLastRxJiffer
= jiffies
;
466 pMgmt
->sNodeDBTable
[iSANodeIndex
].uInActiveCount
= 0;
471 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
472 if (s_bAPModeRxCtl(pDevice
, pbyFrame
, iSANodeIndex
) == true) {
478 if (IS_FC_WEP(pbyFrame
)) {
479 bool bRxDecryOK
= false;
481 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"rx WEP pkt\n");
483 if ((pDevice
->bEnableHostWEP
) && (iSANodeIndex
>= 0)) {
485 pKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[iSANodeIndex
].byCipherSuite
;
486 pKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[iSANodeIndex
].dwKeyIndex
;
487 pKey
->uKeyLength
= pMgmt
->sNodeDBTable
[iSANodeIndex
].uWepKeyLength
;
488 pKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[iSANodeIndex
].dwTSC47_16
;
489 pKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[iSANodeIndex
].wTSC15_0
;
491 &pMgmt
->sNodeDBTable
[iSANodeIndex
].abyWepKey
[0],
495 bRxDecryOK
= s_bHostWepRxEncryption(pDevice
,
499 pMgmt
->sNodeDBTable
[iSANodeIndex
].bOnFly
,
506 bRxDecryOK
= s_bHandleRxEncryption(pDevice
,
518 if ((*pbyNewRsr
& NEWRSR_DECRYPTOK
) == 0) {
519 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV Fail\n");
520 if ( (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPA
) ||
521 (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPAPSK
) ||
522 (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) ||
523 (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2
) ||
524 (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2PSK
)) {
526 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
527 pDevice
->s802_11Counter
.TKIPICVErrors
++;
528 } else if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_CCMP
)) {
529 pDevice
->s802_11Counter
.CCMPDecryptErrors
++;
530 } else if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_WEP
)) {
531 // pDevice->s802_11Counter.WEPICVErrorCount.QuadPart++;
537 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"WEP Func Fail\n");
540 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_CCMP
))
541 FrameSize
-= 8; // Message Integrity Code
543 FrameSize
-= 4; // 4 is ICV
550 //remove the CRC length
551 FrameSize
-= ETH_FCS_LEN
;
553 if (( !(*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
))) && // unicast address
554 (IS_FRAGMENT_PKT((skb
->data
+4)))
557 bDeFragRx
= WCTLbHandleFragment(pDevice
, (PS802_11Header
) (skb
->data
+4), FrameSize
, bIsWEP
, bExtIV
);
558 pDevice
->s802_11Counter
.ReceivedFragmentCount
++;
561 skb
= pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].skb
;
562 FrameSize
= pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].cbFrameLength
;
571 // Management & Control frame Handle
572 if ((IS_TYPE_DATA((skb
->data
+4))) == false) {
573 // Handle Control & Manage Frame
575 if (IS_TYPE_MGMT((skb
->data
+4))) {
576 unsigned char *pbyData1
;
577 unsigned char *pbyData2
;
579 pRxPacket
->p80211Header
= (PUWLAN_80211HDR
)(skb
->data
+4);
580 pRxPacket
->cbMPDULen
= FrameSize
;
581 pRxPacket
->uRSSI
= *pbyRSSI
;
582 pRxPacket
->bySQ
= *pbySQ
;
583 HIDWORD(pRxPacket
->qwLocalTSF
) = cpu_to_le32(HIDWORD(*pqwTSFTime
));
584 LODWORD(pRxPacket
->qwLocalTSF
) = cpu_to_le32(LODWORD(*pqwTSFTime
));
587 pbyData1
= WLAN_HDR_A3_DATA_PTR(skb
->data
+4);
588 pbyData2
= WLAN_HDR_A3_DATA_PTR(skb
->data
+4) + 4;
589 for (ii
= 0; ii
< (FrameSize
- 4); ii
++) {
590 *pbyData1
= *pbyData2
;
595 pRxPacket
->byRxRate
= s_byGetRateIdx(*pbyRxRate
);
596 pRxPacket
->byRxChannel
= (*pbyRxSts
) >> 2;
598 //EnQueue(pDevice,pRxPacket);
601 EnQueue(pDevice
,pRxPacket
);
603 //printk("enque time is %x\n",jiffies);
604 //up(&pDevice->mlme_semaphore);
605 //Enque (pDevice->FirstRecvMngList,pDevice->LastRecvMngList,pMgmt);
609 EnQueue(pDevice
,pRxPacket
);
610 tasklet_schedule(&pDevice
->RxMngWorkItem
);
613 vMgrRxManagePacket((void *)pDevice
, pDevice
->pMgmt
, pRxPacket
);
614 //tasklet_schedule(&pDevice->RxMngWorkItem);
619 //vMgrRxManagePacket((void *)pDevice, pDevice->pMgmt, pRxPacket);
620 // hostap Deamon handle 802.11 management
621 if (pDevice
->bEnableHostapd
) {
622 skb
->dev
= pDevice
->apdev
;
625 skb_put(skb
, FrameSize
);
626 skb_reset_mac_header(skb
);
627 skb
->pkt_type
= PACKET_OTHERHOST
;
628 skb
->protocol
= htons(ETH_P_802_2
);
629 memset(skb
->cb
, 0, sizeof(skb
->cb
));
640 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
641 //In AP mode, hw only check addr1(BSSID or RA) if equal to local MAC.
642 if ( !(*pbyRsr
& RSR_BSSIDOK
)) {
644 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
645 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
653 // discard DATA packet while not associate || BSSID error
654 if ((pDevice
->bLinkPass
== false) ||
655 !(*pbyRsr
& RSR_BSSIDOK
)) {
657 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
658 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
664 //mike add:station mode check eapol-key challenge--->
666 unsigned char Protocol_Version
; //802.1x Authentication
667 unsigned char Packet_Type
; //802.1x Authentication
672 wEtherType
= (skb
->data
[cbIVOffset
+ 8 + 24 + 6] << 8) |
673 skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1];
674 Protocol_Version
= skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1 +1];
675 Packet_Type
= skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1 +1+1];
676 if (wEtherType
== ETH_P_PAE
) { //Protocol Type in LLC-Header
677 if(((Protocol_Version
==1) ||(Protocol_Version
==2)) &&
678 (Packet_Type
==3)) { //802.1x OR eapol-key challenge frame receive
683 //mike add:station mode check eapol-key challenge<---
691 if (pDevice
->bEnablePSMode
) {
692 if (IS_FC_MOREDATA((skb
->data
+4))) {
693 if (*pbyRsr
& RSR_ADDROK
) {
694 //PSbSendPSPOLL((PSDevice)pDevice);
698 if (pDevice
->pMgmt
->bInTIMWake
== true) {
699 pDevice
->pMgmt
->bInTIMWake
= false;
704 // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps
705 if (pDevice
->bDiversityEnable
&& (FrameSize
>50) &&
706 (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) &&
707 (pDevice
->bLinkPass
== true)) {
708 //printk("device_receive_frame: RxRate is %d\n",*pbyRxRate);
709 BBvAntennaDiversity(pDevice
, s_byGetRateIdx(*pbyRxRate
), 0);
713 if (pDevice
->byLocalID
!= REV_ID_VT3253_B1
) {
714 pDevice
->uCurrRSSI
= *pbyRSSI
;
716 pDevice
->byCurrSQ
= *pbySQ
;
718 if ((*pbyRSSI
!= 0) &&
719 (pMgmt
->pCurrBSS
!=NULL
)) {
720 RFvRSSITodBm(pDevice
, *pbyRSSI
, &ldBm
);
721 // Moniter if RSSI is too strong.
722 pMgmt
->pCurrBSS
->byRSSIStatCnt
++;
723 pMgmt
->pCurrBSS
->byRSSIStatCnt
%= RSSI_STAT_COUNT
;
724 pMgmt
->pCurrBSS
->ldBmAverage
[pMgmt
->pCurrBSS
->byRSSIStatCnt
] = ldBm
;
725 for(ii
=0;ii
<RSSI_STAT_COUNT
;ii
++) {
726 if (pMgmt
->pCurrBSS
->ldBmAverage
[ii
] != 0) {
727 pMgmt
->pCurrBSS
->ldBmMAX
= max(pMgmt
->pCurrBSS
->ldBmAverage
[ii
], ldBm
);
732 // -----------------------------------------------
734 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) && (pDevice
->bEnable8021x
== true)){
735 unsigned char abyMacHdr
[24];
737 // Only 802.1x packet incoming allowed
742 wEtherType
= (skb
->data
[cbIVOffset
+ 4 + 24 + 6] << 8) |
743 skb
->data
[cbIVOffset
+ 4 + 24 + 6 + 1];
745 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wEtherType = %04x \n", wEtherType
);
746 if (wEtherType
== ETH_P_PAE
) {
747 skb
->dev
= pDevice
->apdev
;
749 if (bIsWEP
== true) {
750 // strip IV header(8)
751 memcpy(&abyMacHdr
[0], (skb
->data
+ 4), 24);
752 memcpy((skb
->data
+ 4 + cbIVOffset
), &abyMacHdr
[0], 24);
754 skb
->data
+= (cbIVOffset
+ 4);
755 skb
->tail
+= (cbIVOffset
+ 4);
756 skb_put(skb
, FrameSize
);
757 skb_reset_mac_header(skb
);
759 skb
->pkt_type
= PACKET_OTHERHOST
;
760 skb
->protocol
= htons(ETH_P_802_2
);
761 memset(skb
->cb
, 0, sizeof(skb
->cb
));
766 // check if 802.1x authorized
767 if (!(pMgmt
->sNodeDBTable
[iSANodeIndex
].dwFlags
& WLAN_STA_AUTHORIZED
))
772 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
774 FrameSize
-= 8; //MIC
778 //--------------------------------------------------------------------------------
780 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
782 unsigned long *pdwMIC_L
;
783 unsigned long *pdwMIC_R
;
784 unsigned long dwMIC_Priority
;
785 unsigned long dwMICKey0
= 0, dwMICKey1
= 0;
786 unsigned long dwLocalMIC_L
= 0;
787 unsigned long dwLocalMIC_R
= 0;
788 viawget_wpa_header
*wpahdr
;
791 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
792 dwMICKey0
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[24]));
793 dwMICKey1
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[28]));
796 if (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) {
797 dwMICKey0
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[16]));
798 dwMICKey1
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[20]));
799 } else if ((pKey
->dwKeyIndex
& BIT28
) == 0) {
800 dwMICKey0
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[16]));
801 dwMICKey1
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[20]));
803 dwMICKey0
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[24]));
804 dwMICKey1
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[28]));
808 MIC_vInit(dwMICKey0
, dwMICKey1
);
809 MIC_vAppend((unsigned char *)&(pDevice
->sRxEthHeader
.abyDstAddr
[0]), 12);
811 MIC_vAppend((unsigned char *)&dwMIC_Priority
, 4);
812 // 4 is Rcv buffer header, 24 is MAC Header, and 8 is IV and Ext IV.
813 MIC_vAppend((unsigned char *)(skb
->data
+ 4 + WLAN_HDR_ADDR3_LEN
+ 8),
814 FrameSize
- WLAN_HDR_ADDR3_LEN
- 8);
815 MIC_vGetMIC(&dwLocalMIC_L
, &dwLocalMIC_R
);
818 pdwMIC_L
= (unsigned long *)(skb
->data
+ 4 + FrameSize
);
819 pdwMIC_R
= (unsigned long *)(skb
->data
+ 4 + FrameSize
+ 4);
820 //DBG_PRN_GRP12(("RxL: %lx, RxR: %lx\n", *pdwMIC_L, *pdwMIC_R));
821 //DBG_PRN_GRP12(("LocalL: %lx, LocalR: %lx\n", dwLocalMIC_L, dwLocalMIC_R));
822 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"dwMICKey0= %lx,dwMICKey1= %lx \n", dwMICKey0, dwMICKey1);
825 if ((cpu_to_le32(*pdwMIC_L
) != dwLocalMIC_L
) || (cpu_to_le32(*pdwMIC_R
) != dwLocalMIC_R
) ||
826 (pDevice
->bRxMICFail
== true)) {
827 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC comparison is fail!\n");
828 pDevice
->bRxMICFail
= false;
829 //pDevice->s802_11Counter.TKIPLocalMICFailures.QuadPart++;
830 pDevice
->s802_11Counter
.TKIPLocalMICFailures
++;
832 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
833 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
837 //2008-0409-07, <Add> by Einsn Liu
838 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
839 //send event to wpa_supplicant
840 //if(pDevice->bWPADevEnable == true)
842 union iwreq_data wrqu
;
843 struct iw_michaelmicfailure ev
;
844 int keyidx
= pbyFrame
[cbHeaderSize
+3] >> 6; //top two-bits
845 memset(&ev
, 0, sizeof(ev
));
846 ev
.flags
= keyidx
& IW_MICFAILURE_KEY_ID
;
847 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
848 (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
) &&
849 (*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
)) == 0) {
850 ev
.flags
|= IW_MICFAILURE_PAIRWISE
;
852 ev
.flags
|= IW_MICFAILURE_GROUP
;
855 ev
.src_addr
.sa_family
= ARPHRD_ETHER
;
856 memcpy(ev
.src_addr
.sa_data
, pMACHeader
->abyAddr2
, ETH_ALEN
);
857 memset(&wrqu
, 0, sizeof(wrqu
));
858 wrqu
.data
.length
= sizeof(ev
);
859 wireless_send_event(pDevice
->dev
, IWEVMICHAELMICFAILURE
, &wrqu
, (char *)&ev
);
865 if ((pDevice
->bWPADEVUp
) && (pDevice
->skb
!= NULL
)) {
866 wpahdr
= (viawget_wpa_header
*)pDevice
->skb
->data
;
867 if ((pDevice
->pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
868 (pDevice
->pMgmt
->eCurrState
== WMAC_STATE_ASSOC
) &&
869 (*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
)) == 0) {
870 //s802_11_Status.Flags = NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR;
871 wpahdr
->type
= VIAWGET_PTK_MIC_MSG
;
873 //s802_11_Status.Flags = NDIS_802_11_AUTH_REQUEST_GROUP_ERROR;
874 wpahdr
->type
= VIAWGET_GTK_MIC_MSG
;
876 wpahdr
->resp_ie_len
= 0;
877 wpahdr
->req_ie_len
= 0;
878 skb_put(pDevice
->skb
, sizeof(viawget_wpa_header
));
879 pDevice
->skb
->dev
= pDevice
->wpadev
;
880 skb_reset_mac_header(pDevice
->skb
);
881 pDevice
->skb
->pkt_type
= PACKET_HOST
;
882 pDevice
->skb
->protocol
= htons(ETH_P_802_2
);
883 memset(pDevice
->skb
->cb
, 0, sizeof(pDevice
->skb
->cb
));
884 netif_rx(pDevice
->skb
);
885 pDevice
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
892 } //---end of SOFT MIC-----------------------------------------------------------------------
894 // ++++++++++ Reply Counter Check +++++++++++++
896 if ((pKey
!= NULL
) && ((pKey
->byCipherSuite
== KEY_CTL_TKIP
) ||
897 (pKey
->byCipherSuite
== KEY_CTL_CCMP
))) {
899 unsigned short wLocalTSC15_0
= 0;
900 unsigned long dwLocalTSC47_16
= 0;
901 unsigned long long RSC
= 0;
903 RSC
= *((unsigned long long *) &(pKey
->KeyRSC
));
904 wLocalTSC15_0
= (unsigned short) RSC
;
905 dwLocalTSC47_16
= (unsigned long) (RSC
>>16);
910 memcpy(&(pKey
->KeyRSC
), &RSC
, sizeof(QWORD
));
912 if ( (pDevice
->sMgmtObj
.eCurrMode
== WMAC_MODE_ESS_STA
) &&
913 (pDevice
->sMgmtObj
.eCurrState
== WMAC_STATE_ASSOC
)) {
915 if ( (wRxTSC15_0
< wLocalTSC15_0
) &&
916 (dwRxTSC47_16
<= dwLocalTSC47_16
) &&
917 !((dwRxTSC47_16
== 0) && (dwLocalTSC47_16
== 0xFFFFFFFF))) {
918 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"TSC is illegal~~!\n ");
919 if (pKey
->byCipherSuite
== KEY_CTL_TKIP
)
920 //pDevice->s802_11Counter.TKIPReplays.QuadPart++;
921 pDevice
->s802_11Counter
.TKIPReplays
++;
923 //pDevice->s802_11Counter.CCMPReplays.QuadPart++;
924 pDevice
->s802_11Counter
.CCMPReplays
++;
927 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
928 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
936 } // ----- End of Reply Counter Check --------------------------
940 if ((pKey
!= NULL
) && (bIsWEP
)) {
941 // pDevice->s802_11Counter.DecryptSuccessCount.QuadPart++;
945 s_vProcessRxMACHeader(pDevice
, (unsigned char *)(skb
->data
+4), FrameSize
, bIsWEP
, bExtIV
, &cbHeaderOffset
);
946 FrameSize
-= cbHeaderOffset
;
947 cbHeaderOffset
+= 4; // 4 is Rcv buffer header
949 // Null data, framesize = 14
953 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
954 if (s_bAPModeRxData(pDevice
,
963 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
964 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
971 // if(pDevice->bRxMICFail == false) {
972 // for (ii =0; ii < 100; ii++)
973 // printk(" %02x", *(skb->data + ii));
979 skb
->data
+= cbHeaderOffset
;
980 skb
->tail
+= cbHeaderOffset
;
981 skb_put(skb
, FrameSize
);
982 skb
->protocol
=eth_type_trans(skb
, skb
->dev
);
985 //drop frame not met IEEE 802.3
987 if (pDevice->flags & DEVICE_FLAGS_VAL_PKT_LEN) {
988 if ((skb->protocol==htons(ETH_P_802_3)) &&
989 (skb->len!=htons(skb->mac.ethernet->h_proto))) {
990 pStats->rx_length_errors++;
991 pStats->rx_dropped++;
993 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
994 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
1003 skb
->ip_summed
=CHECKSUM_NONE
;
1004 pStats
->rx_bytes
+=skb
->len
;
1005 pStats
->rx_packets
++;
1009 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
1010 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
1011 pDevice
->dev
->name
);
1020 static bool s_bAPModeRxCtl (
1022 unsigned char *pbyFrame
,
1026 PS802_11Header p802_11Header
;
1028 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
1031 if (IS_CTL_PSPOLL(pbyFrame
) || !IS_TYPE_CONTROL(pbyFrame
)) {
1033 p802_11Header
= (PS802_11Header
) (pbyFrame
);
1034 if (!IS_TYPE_MGMT(pbyFrame
)) {
1036 // Data & PS-Poll packet
1037 // check frame class
1038 if (iSANodeIndex
> 0) {
1039 // frame class 3 fliter & checking
1040 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].eNodeState
< NODE_AUTH
) {
1041 // send deauth notification
1042 // reason = (6) class 2 received from nonauth sta
1043 vMgrDeAuthenBeginSta(pDevice
,
1045 (unsigned char *)(p802_11Header
->abyAddr2
),
1046 (WLAN_MGMT_REASON_CLASS2_NONAUTH
),
1049 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: send vMgrDeAuthenBeginSta 1\n");
1052 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].eNodeState
< NODE_ASSOC
) {
1053 // send deassoc notification
1054 // reason = (7) class 3 received from nonassoc sta
1055 vMgrDisassocBeginSta(pDevice
,
1057 (unsigned char *)(p802_11Header
->abyAddr2
),
1058 (WLAN_MGMT_REASON_CLASS3_NONASSOC
),
1061 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: send vMgrDisassocBeginSta 2\n");
1065 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
) {
1066 // delcare received ps-poll event
1067 if (IS_CTL_PSPOLL(pbyFrame
)) {
1068 pMgmt
->sNodeDBTable
[iSANodeIndex
].bRxPSPoll
= true;
1069 bScheduleCommand((void *)pDevice
, WLAN_CMD_RX_PSPOLL
, NULL
);
1070 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: WLAN_CMD_RX_PSPOLL 1\n");
1073 // check Data PS state
1074 // if PW bit off, send out all PS bufferring packets.
1075 if (!IS_FC_POWERMGT(pbyFrame
)) {
1076 pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
= false;
1077 pMgmt
->sNodeDBTable
[iSANodeIndex
].bRxPSPoll
= true;
1078 bScheduleCommand((void *)pDevice
, WLAN_CMD_RX_PSPOLL
, NULL
);
1079 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: WLAN_CMD_RX_PSPOLL 2\n");
1084 if (IS_FC_POWERMGT(pbyFrame
)) {
1085 pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
= true;
1086 // Once if STA in PS state, enable multicast bufferring
1087 pMgmt
->sNodeDBTable
[0].bPSEnable
= true;
1090 // clear all pending PS frame.
1091 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].wEnQueueCnt
> 0) {
1092 pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
= false;
1093 pMgmt
->sNodeDBTable
[iSANodeIndex
].bRxPSPoll
= true;
1094 bScheduleCommand((void *)pDevice
, WLAN_CMD_RX_PSPOLL
, NULL
);
1095 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: WLAN_CMD_RX_PSPOLL 3\n");
1102 vMgrDeAuthenBeginSta(pDevice
,
1104 (unsigned char *)(p802_11Header
->abyAddr2
),
1105 (WLAN_MGMT_REASON_CLASS2_NONAUTH
),
1108 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: send vMgrDeAuthenBeginSta 3\n");
1109 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"BSSID:%pM\n",
1110 p802_11Header
->abyAddr3
);
1111 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ADDR2:%pM\n",
1112 p802_11Header
->abyAddr2
);
1113 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ADDR1:%pM\n",
1114 p802_11Header
->abyAddr1
);
1115 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: wFrameCtl= %x\n", p802_11Header
->wFrameCtl
);
1116 VNSvInPortB(pDevice
->PortOffset
+ MAC_REG_RCR
, &(pDevice
->byRxMode
));
1117 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc:pDevice->byRxMode = %x\n", pDevice
->byRxMode
);
1126 static bool s_bHandleRxEncryption (
1128 unsigned char *pbyFrame
,
1129 unsigned int FrameSize
,
1130 unsigned char *pbyRsr
,
1131 unsigned char *pbyNewRsr
,
1134 unsigned short *pwRxTSC15_0
,
1135 unsigned long *pdwRxTSC47_16
1138 unsigned int PayloadLen
= FrameSize
;
1139 unsigned char *pbyIV
;
1140 unsigned char byKeyIdx
;
1141 PSKeyItem pKey
= NULL
;
1142 unsigned char byDecMode
= KEY_CTL_WEP
;
1143 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
1149 pbyIV
= pbyFrame
+ WLAN_HDR_ADDR3_LEN
;
1150 if ( WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame
) &&
1151 WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame
) ) {
1152 pbyIV
+= 6; // 6 is 802.11 address4
1155 byKeyIdx
= (*(pbyIV
+3) & 0xc0);
1157 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\nKeyIdx: %d\n", byKeyIdx
);
1159 if ((pMgmt
->eAuthenMode
== WMAC_AUTH_WPA
) ||
1160 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPAPSK
) ||
1161 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) ||
1162 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2
) ||
1163 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2PSK
)) {
1164 if (((*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
)) == 0) &&
1165 (pDevice
->pMgmt
->byCSSPK
!= KEY_CTL_NONE
)) {
1166 // unicast pkt use pairwise key
1167 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"unicast pkt\n");
1168 if (KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBSSID
, 0xFFFFFFFF, &pKey
) == true) {
1169 if (pDevice
->pMgmt
->byCSSPK
== KEY_CTL_TKIP
)
1170 byDecMode
= KEY_CTL_TKIP
;
1171 else if (pDevice
->pMgmt
->byCSSPK
== KEY_CTL_CCMP
)
1172 byDecMode
= KEY_CTL_CCMP
;
1174 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"unicast pkt: %d, %p\n", byDecMode
, pKey
);
1177 KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBSSID
, byKeyIdx
, &pKey
);
1178 if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_TKIP
)
1179 byDecMode
= KEY_CTL_TKIP
;
1180 else if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_CCMP
)
1181 byDecMode
= KEY_CTL_CCMP
;
1182 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"group pkt: %d, %d, %p\n", byKeyIdx
, byDecMode
, pKey
);
1185 // our WEP only support Default Key
1187 // use default group key
1188 KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBroadcastAddr
, byKeyIdx
, &pKey
);
1189 if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_TKIP
)
1190 byDecMode
= KEY_CTL_TKIP
;
1191 else if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_CCMP
)
1192 byDecMode
= KEY_CTL_CCMP
;
1196 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"AES:%d %d %d\n", pDevice
->pMgmt
->byCSSPK
, pDevice
->pMgmt
->byCSSGK
, byDecMode
);
1199 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey == NULL\n");
1200 if (byDecMode
== KEY_CTL_WEP
) {
1201 // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1202 } else if (pDevice
->bLinkPass
== true) {
1203 // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1207 if (byDecMode
!= pKey
->byCipherSuite
) {
1208 if (byDecMode
== KEY_CTL_WEP
) {
1209 // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1210 } else if (pDevice
->bLinkPass
== true) {
1211 // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1216 if (byDecMode
== KEY_CTL_WEP
) {
1218 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
) ||
1219 (((PSKeyTable
)(pKey
->pvKeyTable
))->bSoftWEP
== true)) {
1224 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1225 memcpy(pDevice
->abyPRNG
, pbyIV
, 3);
1226 memcpy(pDevice
->abyPRNG
+ 3, pKey
->abyKey
, pKey
->uKeyLength
);
1227 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, pKey
->uKeyLength
+ 3);
1228 rc4_encrypt(&pDevice
->SBox
, pbyIV
+4, pbyIV
+4, PayloadLen
);
1230 if (ETHbIsBufferCrc32Ok(pbyIV
+4, PayloadLen
)) {
1231 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1234 } else if ((byDecMode
== KEY_CTL_TKIP
) ||
1235 (byDecMode
== KEY_CTL_CCMP
)) {
1238 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1239 *pdwRxTSC47_16
= cpu_to_le32(*(unsigned long *)(pbyIV
+ 4));
1240 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ExtIV: %lx\n",*pdwRxTSC47_16
);
1241 if (byDecMode
== KEY_CTL_TKIP
) {
1242 *pwRxTSC15_0
= cpu_to_le16(MAKEWORD(*(pbyIV
+2), *pbyIV
));
1244 *pwRxTSC15_0
= cpu_to_le16(*(unsigned short *)pbyIV
);
1246 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"TSC0_15: %x\n", *pwRxTSC15_0
);
1248 if ((byDecMode
== KEY_CTL_TKIP
) &&
1249 (pDevice
->byLocalID
<= REV_ID_VT3253_A1
)) {
1252 PS802_11Header pMACHeader
= (PS802_11Header
) (pbyFrame
);
1253 TKIPvMixKey(pKey
->abyKey
, pMACHeader
->abyAddr2
, *pwRxTSC15_0
, *pdwRxTSC47_16
, pDevice
->abyPRNG
);
1254 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, TKIP_KEY_LEN
);
1255 rc4_encrypt(&pDevice
->SBox
, pbyIV
+8, pbyIV
+8, PayloadLen
);
1256 if (ETHbIsBufferCrc32Ok(pbyIV
+8, PayloadLen
)) {
1257 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1258 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV OK!\n");
1260 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV FAIL!!!\n");
1261 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PayloadLen = %d\n", PayloadLen
);
1266 if ((*(pbyIV
+3) & 0x20) != 0)
1272 static bool s_bHostWepRxEncryption (
1274 unsigned char *pbyFrame
,
1275 unsigned int FrameSize
,
1276 unsigned char *pbyRsr
,
1279 unsigned char *pbyNewRsr
,
1281 unsigned short *pwRxTSC15_0
,
1282 unsigned long *pdwRxTSC47_16
1285 unsigned int PayloadLen
= FrameSize
;
1286 unsigned char *pbyIV
;
1287 unsigned char byKeyIdx
;
1288 unsigned char byDecMode
= KEY_CTL_WEP
;
1289 PS802_11Header pMACHeader
;
1296 pbyIV
= pbyFrame
+ WLAN_HDR_ADDR3_LEN
;
1297 if ( WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame
) &&
1298 WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame
) ) {
1299 pbyIV
+= 6; // 6 is 802.11 address4
1302 byKeyIdx
= (*(pbyIV
+3) & 0xc0);
1304 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\nKeyIdx: %d\n", byKeyIdx
);
1307 if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_TKIP
)
1308 byDecMode
= KEY_CTL_TKIP
;
1309 else if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_CCMP
)
1310 byDecMode
= KEY_CTL_CCMP
;
1312 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"AES:%d %d %d\n", pDevice
->pMgmt
->byCSSPK
, pDevice
->pMgmt
->byCSSGK
, byDecMode
);
1314 if (byDecMode
!= pKey
->byCipherSuite
) {
1315 if (byDecMode
== KEY_CTL_WEP
) {
1316 // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1317 } else if (pDevice
->bLinkPass
== true) {
1318 // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1323 if (byDecMode
== KEY_CTL_WEP
) {
1325 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"byDecMode == KEY_CTL_WEP \n");
1326 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
) ||
1327 (((PSKeyTable
)(pKey
->pvKeyTable
))->bSoftWEP
== true) ||
1328 (bOnFly
== false)) {
1334 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1335 memcpy(pDevice
->abyPRNG
, pbyIV
, 3);
1336 memcpy(pDevice
->abyPRNG
+ 3, pKey
->abyKey
, pKey
->uKeyLength
);
1337 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, pKey
->uKeyLength
+ 3);
1338 rc4_encrypt(&pDevice
->SBox
, pbyIV
+4, pbyIV
+4, PayloadLen
);
1340 if (ETHbIsBufferCrc32Ok(pbyIV
+4, PayloadLen
)) {
1341 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1344 } else if ((byDecMode
== KEY_CTL_TKIP
) ||
1345 (byDecMode
== KEY_CTL_CCMP
)) {
1348 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1349 *pdwRxTSC47_16
= cpu_to_le32(*(unsigned long *)(pbyIV
+ 4));
1350 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ExtIV: %lx\n",*pdwRxTSC47_16
);
1352 if (byDecMode
== KEY_CTL_TKIP
) {
1353 *pwRxTSC15_0
= cpu_to_le16(MAKEWORD(*(pbyIV
+2), *pbyIV
));
1355 *pwRxTSC15_0
= cpu_to_le16(*(unsigned short *)pbyIV
);
1357 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"TSC0_15: %x\n", *pwRxTSC15_0
);
1359 if (byDecMode
== KEY_CTL_TKIP
) {
1361 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
) || (bOnFly
== false)) {
1365 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"soft KEY_CTL_TKIP \n");
1366 pMACHeader
= (PS802_11Header
) (pbyFrame
);
1367 TKIPvMixKey(pKey
->abyKey
, pMACHeader
->abyAddr2
, *pwRxTSC15_0
, *pdwRxTSC47_16
, pDevice
->abyPRNG
);
1368 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, TKIP_KEY_LEN
);
1369 rc4_encrypt(&pDevice
->SBox
, pbyIV
+8, pbyIV
+8, PayloadLen
);
1370 if (ETHbIsBufferCrc32Ok(pbyIV
+8, PayloadLen
)) {
1371 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1372 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV OK!\n");
1374 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV FAIL!!!\n");
1375 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PayloadLen = %d\n", PayloadLen
);
1380 if (byDecMode
== KEY_CTL_CCMP
) {
1381 if (bOnFly
== false) {
1384 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"soft KEY_CTL_CCMP\n");
1385 if (AESbGenCCMP(pKey
->abyKey
, pbyFrame
, FrameSize
)) {
1386 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1387 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CCMP MIC compare OK!\n");
1389 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CCMP MIC fail!\n");
1396 if ((*(pbyIV
+3) & 0x20) != 0)
1403 static bool s_bAPModeRxData (
1405 struct sk_buff
* skb
,
1406 unsigned int FrameSize
,
1407 unsigned int cbHeaderOffset
,
1412 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
1413 bool bRelayAndForward
= false;
1414 bool bRelayOnly
= false;
1415 unsigned char byMask
[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1416 unsigned short wAID
;
1419 struct sk_buff
* skbcpy
= NULL
;
1421 if (FrameSize
> CB_MAX_BUF_SIZE
)
1424 if(is_multicast_ether_addr((unsigned char *)(skb
->data
+cbHeaderOffset
))) {
1425 if (pMgmt
->sNodeDBTable
[0].bPSEnable
) {
1427 skbcpy
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
1429 // if any node in PS mode, buffer packet until DTIM.
1430 if (skbcpy
== NULL
) {
1431 DBG_PRT(MSG_LEVEL_NOTICE
, KERN_INFO
"relay multicast no skb available \n");
1434 skbcpy
->dev
= pDevice
->dev
;
1435 skbcpy
->len
= FrameSize
;
1436 memcpy(skbcpy
->data
, skb
->data
+cbHeaderOffset
, FrameSize
);
1437 skb_queue_tail(&(pMgmt
->sNodeDBTable
[0].sTxPSQueue
), skbcpy
);
1439 pMgmt
->sNodeDBTable
[0].wEnQueueCnt
++;
1441 pMgmt
->abyPSTxMap
[0] |= byMask
[0];
1445 bRelayAndForward
= true;
1450 if (BSSDBbIsSTAInNodeDB(pMgmt
, (unsigned char *)(skb
->data
+cbHeaderOffset
), &iDANodeIndex
)) {
1451 if (pMgmt
->sNodeDBTable
[iDANodeIndex
].eNodeState
>= NODE_ASSOC
) {
1452 if (pMgmt
->sNodeDBTable
[iDANodeIndex
].bPSEnable
) {
1453 // queue this skb until next PS tx, and then release.
1455 skb
->data
+= cbHeaderOffset
;
1456 skb
->tail
+= cbHeaderOffset
;
1457 skb_put(skb
, FrameSize
);
1458 skb_queue_tail(&pMgmt
->sNodeDBTable
[iDANodeIndex
].sTxPSQueue
, skb
);
1459 pMgmt
->sNodeDBTable
[iDANodeIndex
].wEnQueueCnt
++;
1460 wAID
= pMgmt
->sNodeDBTable
[iDANodeIndex
].wAID
;
1461 pMgmt
->abyPSTxMap
[wAID
>> 3] |= byMask
[wAID
& 7];
1462 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n",
1463 iDANodeIndex
, (wAID
>> 3), pMgmt
->abyPSTxMap
[wAID
>> 3]);
1473 if (bRelayOnly
|| bRelayAndForward
) {
1474 // relay this packet right now
1475 if (bRelayAndForward
)
1478 if ((pDevice
->uAssocCount
> 1) && (iDANodeIndex
>= 0)) {
1479 ROUTEbRelay(pDevice
, (unsigned char *)(skb
->data
+ cbHeaderOffset
), FrameSize
, (unsigned int)iDANodeIndex
);
1485 // none associate, don't forward
1486 if (pDevice
->uAssocCount
== 0)