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
61 /*--------------------- Static Definitions -------------------------*/
63 /*--------------------- Static Classes ----------------------------*/
65 /*--------------------- Static Variables --------------------------*/
66 //static int msglevel =MSG_LEVEL_DEBUG;
67 static int msglevel
=MSG_LEVEL_INFO
;
69 const unsigned char acbyRxRate
[MAX_RATE
] =
70 {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
73 /*--------------------- Static Functions --------------------------*/
75 /*--------------------- Static Definitions -------------------------*/
77 /*--------------------- Static Functions --------------------------*/
79 static unsigned char s_byGetRateIdx(unsigned char byRate
);
83 s_vGetDASA(unsigned char *pbyRxBufferAddr
, unsigned int *pcbHeaderSize
,
84 PSEthernetHeader psEthHeader
);
87 s_vProcessRxMACHeader(PSDevice pDevice
, unsigned char *pbyRxBufferAddr
,
88 unsigned int cbPacketSize
, bool bIsWEP
, bool bExtIV
,
89 unsigned int *pcbHeadSize
);
91 static bool s_bAPModeRxCtl(
93 unsigned char *pbyFrame
,
99 static bool s_bAPModeRxData (
102 unsigned int FrameSize
,
103 unsigned int cbHeaderOffset
,
109 static bool s_bHandleRxEncryption(
111 unsigned char *pbyFrame
,
112 unsigned int FrameSize
,
113 unsigned char *pbyRsr
,
114 unsigned char *pbyNewRsr
,
117 unsigned short *pwRxTSC15_0
,
118 unsigned long *pdwRxTSC47_16
121 static bool s_bHostWepRxEncryption(
124 unsigned char *pbyFrame
,
125 unsigned int FrameSize
,
126 unsigned char *pbyRsr
,
129 unsigned char *pbyNewRsr
,
131 unsigned short *pwRxTSC15_0
,
132 unsigned long *pdwRxTSC47_16
136 /*--------------------- Export Variables --------------------------*/
141 * Translate Rcv 802.11 header to 802.3 header with Rx buffer
146 * dwRxBufferAddr - Address of Rcv Buffer
147 * cbPacketSize - Rcv Packet size
148 * bIsWEP - If Rcv with WEP
150 * pcbHeaderSize - 802.11 header size
156 s_vProcessRxMACHeader(PSDevice pDevice
, unsigned char *pbyRxBufferAddr
,
157 unsigned int cbPacketSize
, bool bIsWEP
, bool bExtIV
,
158 unsigned int *pcbHeadSize
)
160 unsigned char *pbyRxBuffer
;
161 unsigned int cbHeaderSize
= 0;
162 unsigned short *pwType
;
163 PS802_11Header pMACHeader
;
167 pMACHeader
= (PS802_11Header
) (pbyRxBufferAddr
+ cbHeaderSize
);
169 s_vGetDASA((unsigned char *)pMACHeader
, &cbHeaderSize
, &pDevice
->sRxEthHeader
);
173 // strip IV&ExtIV , add 8 byte
174 cbHeaderSize
+= (WLAN_HDR_ADDR3_LEN
+ 8);
176 // strip IV , add 4 byte
177 cbHeaderSize
+= (WLAN_HDR_ADDR3_LEN
+ 4);
181 cbHeaderSize
+= WLAN_HDR_ADDR3_LEN
;
184 pbyRxBuffer
= (unsigned char *) (pbyRxBufferAddr
+ cbHeaderSize
);
185 if (!compare_ether_addr(pbyRxBuffer
, &pDevice
->abySNAP_Bridgetunnel
[0])) {
188 else if (!compare_ether_addr(pbyRxBuffer
, &pDevice
->abySNAP_RFC1042
[0])) {
190 pwType
= (unsigned short *) (pbyRxBufferAddr
+ cbHeaderSize
);
191 if ((*pwType
!= TYPE_PKT_IPX
) && (*pwType
!= cpu_to_le16(0xF380))) {
195 pwType
= (unsigned short *) (pbyRxBufferAddr
+ cbHeaderSize
);
198 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 8); // 8 is IV&ExtIV
200 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 4); // 4 is IV
204 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
);
210 pwType
= (unsigned short *) (pbyRxBufferAddr
+ cbHeaderSize
);
213 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 8); // 8 is IV&ExtIV
215 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 4); // 4 is IV
219 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
);
223 cbHeaderSize
-= (ETH_ALEN
* 2);
224 pbyRxBuffer
= (unsigned char *) (pbyRxBufferAddr
+ cbHeaderSize
);
225 for(ii
=0;ii
<ETH_ALEN
;ii
++)
226 *pbyRxBuffer
++ = pDevice
->sRxEthHeader
.abyDstAddr
[ii
];
227 for(ii
=0;ii
<ETH_ALEN
;ii
++)
228 *pbyRxBuffer
++ = pDevice
->sRxEthHeader
.abySrcAddr
[ii
];
230 *pcbHeadSize
= cbHeaderSize
;
236 static unsigned char s_byGetRateIdx (unsigned char byRate
)
238 unsigned char byRateIdx
;
240 for (byRateIdx
= 0; byRateIdx
<MAX_RATE
; byRateIdx
++) {
241 if (acbyRxRate
[byRateIdx
%MAX_RATE
] == byRate
)
249 s_vGetDASA(unsigned char *pbyRxBufferAddr
, unsigned int *pcbHeaderSize
,
250 PSEthernetHeader psEthHeader
)
252 unsigned int cbHeaderSize
= 0;
253 PS802_11Header pMACHeader
;
256 pMACHeader
= (PS802_11Header
) (pbyRxBufferAddr
+ cbHeaderSize
);
258 if ((pMACHeader
->wFrameCtl
& FC_TODS
) == 0) {
259 if (pMACHeader
->wFrameCtl
& FC_FROMDS
) {
260 for(ii
=0;ii
<ETH_ALEN
;ii
++) {
261 psEthHeader
->abyDstAddr
[ii
] = pMACHeader
->abyAddr1
[ii
];
262 psEthHeader
->abySrcAddr
[ii
] = pMACHeader
->abyAddr3
[ii
];
267 for(ii
=0;ii
<ETH_ALEN
;ii
++) {
268 psEthHeader
->abyDstAddr
[ii
] = pMACHeader
->abyAddr1
[ii
];
269 psEthHeader
->abySrcAddr
[ii
] = pMACHeader
->abyAddr2
[ii
];
275 if (pMACHeader
->wFrameCtl
& FC_FROMDS
) {
276 for(ii
=0;ii
<ETH_ALEN
;ii
++) {
277 psEthHeader
->abyDstAddr
[ii
] = pMACHeader
->abyAddr3
[ii
];
278 psEthHeader
->abySrcAddr
[ii
] = pMACHeader
->abyAddr4
[ii
];
283 for(ii
=0;ii
<ETH_ALEN
;ii
++) {
284 psEthHeader
->abyDstAddr
[ii
] = pMACHeader
->abyAddr3
[ii
];
285 psEthHeader
->abySrcAddr
[ii
] = pMACHeader
->abyAddr2
[ii
];
289 *pcbHeaderSize
= cbHeaderSize
;
297 void MngWorkItem(void *Context
)
299 PSRxMgmtPacket pRxMgmtPacket
;
300 PSDevice pDevice
= (PSDevice
) Context
;
301 //printk("Enter MngWorkItem,Queue packet num is %d\n",pDevice->rxManeQueue.packet_num);
302 spin_lock_irq(&pDevice
->lock
);
303 while(pDevice
->rxManeQueue
.packet_num
!= 0)
305 pRxMgmtPacket
= DeQueue(pDevice
);
306 vMgrRxManagePacket(pDevice
, pDevice
->pMgmt
, pRxMgmtPacket
);
308 spin_unlock_irq(&pDevice
->lock
);
317 device_receive_frame (
323 PDEVICE_RD_INFO pRDInfo
= pCurrRD
->pRDInfo
;
325 //printk("device_receive_frame:pCurrRD is %x,pRDInfo is %x\n",pCurrRD,pCurrRD->pRDInfo);
327 struct net_device_stats
* pStats
=&pDevice
->stats
;
329 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
330 PSRxMgmtPacket pRxPacket
= &(pDevice
->pMgmt
->sRxPacket
);
331 PS802_11Header p802_11Header
;
332 unsigned char *pbyRsr
;
333 unsigned char *pbyNewRsr
;
334 unsigned char *pbyRSSI
;
336 unsigned short *pwFrameSize
;
337 unsigned char *pbyFrame
;
338 bool bDeFragRx
= false;
340 unsigned int cbHeaderOffset
;
341 unsigned int FrameSize
;
342 unsigned short wEtherType
= 0;
343 int iSANodeIndex
= -1;
344 int iDANodeIndex
= -1;
346 unsigned int cbIVOffset
;
348 unsigned char *pbyRxSts
;
349 unsigned char *pbyRxRate
;
350 unsigned char *pbySQ
;
351 unsigned int cbHeaderSize
;
352 PSKeyItem pKey
= NULL
;
353 unsigned short wRxTSC15_0
= 0;
354 unsigned long dwRxTSC47_16
= 0;
357 unsigned long dwDuration
= 0;
359 long ldBmThreshold
= 0;
360 PS802_11Header pMACHeader
;
361 bool bRxeapol_key
= false;
363 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- device_receive_frame---\n");
370 pci_unmap_single(pDevice
->pcid
, pRDInfo
->skb_dma
,
371 pDevice
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
374 pwFrameSize
= (unsigned short *)(skb
->data
+ 2);
375 FrameSize
= cpu_to_le16(pCurrRD
->m_rd1RD1
.wReqCount
) - cpu_to_le16(pCurrRD
->m_rd0RD0
.wResCount
);
377 // Max: 2312Payload + 30HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
378 // Min (ACK): 10HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
379 if ((FrameSize
> 2364)||(FrameSize
<= 32)) {
380 // Frame Size error drop this packet.
381 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---------- WRONG Length 1 \n");
385 pbyRxSts
= (unsigned char *) (skb
->data
);
386 pbyRxRate
= (unsigned char *) (skb
->data
+ 1);
387 pbyRsr
= (unsigned char *) (skb
->data
+ FrameSize
- 1);
388 pbyRSSI
= (unsigned char *) (skb
->data
+ FrameSize
- 2);
389 pbyNewRsr
= (unsigned char *) (skb
->data
+ FrameSize
- 3);
390 pbySQ
= (unsigned char *) (skb
->data
+ FrameSize
- 4);
391 pqwTSFTime
= (PQWORD
) (skb
->data
+ FrameSize
- 12);
392 pbyFrame
= (unsigned char *)(skb
->data
+ 4);
395 FrameSize
= cpu_to_le16(*pwFrameSize
);
397 if ((FrameSize
> 2346)|(FrameSize
< 14)) { // Max: 2312Payload + 30HD +4CRC
399 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---------- WRONG Length 2 \n");
404 // update receive statistic counter
405 STAvUpdateRDStatCounter(&pDevice
->scStatistic
,
414 pMACHeader
=(PS802_11Header
)((unsigned char *) (skb
->data
)+8);
416 if (pDevice
->bMeasureInProgress
== true) {
417 if ((*pbyRsr
& RSR_CRCOK
) != 0) {
418 pDevice
->byBasicMap
|= 0x01;
420 dwDuration
= (FrameSize
<< 4);
421 dwDuration
/= acbyRxRate
[*pbyRxRate
%MAX_RATE
];
422 if (*pbyRxRate
<= RATE_11M
) {
423 if (*pbyRxSts
& 0x01) {
433 RFvRSSITodBm(pDevice
, *pbyRSSI
, &ldBm
);
435 for (ii
= 7; ii
> 0;) {
436 if (ldBm
> ldBmThreshold
) {
442 pDevice
->dwRPIs
[ii
] += dwDuration
;
446 if (!is_multicast_ether_addr(pbyFrame
)) {
447 if (WCTLbIsDuplicate(&(pDevice
->sDupRxCache
), (PS802_11Header
) (skb
->data
+ 4))) {
448 pDevice
->s802_11Counter
.FrameDuplicateCount
++;
455 s_vGetDASA(skb
->data
+4, &cbHeaderSize
, &pDevice
->sRxEthHeader
);
457 // filter packet send from myself
458 if (!compare_ether_addr((unsigned char *)&(pDevice
->sRxEthHeader
.abySrcAddr
[0]), pDevice
->abyCurrentNetAddr
))
461 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) || (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
)) {
462 if (IS_CTL_PSPOLL(pbyFrame
) || !IS_TYPE_CONTROL(pbyFrame
)) {
463 p802_11Header
= (PS802_11Header
) (pbyFrame
);
465 if (BSSDBbIsSTAInNodeDB(pMgmt
, (unsigned char *)(p802_11Header
->abyAddr2
), &iSANodeIndex
)) {
466 pMgmt
->sNodeDBTable
[iSANodeIndex
].ulLastRxJiffer
= jiffies
;
467 pMgmt
->sNodeDBTable
[iSANodeIndex
].uInActiveCount
= 0;
472 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
473 if (s_bAPModeRxCtl(pDevice
, pbyFrame
, iSANodeIndex
) == true) {
479 if (IS_FC_WEP(pbyFrame
)) {
480 bool bRxDecryOK
= false;
482 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"rx WEP pkt\n");
484 if ((pDevice
->bEnableHostWEP
) && (iSANodeIndex
>= 0)) {
486 pKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[iSANodeIndex
].byCipherSuite
;
487 pKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[iSANodeIndex
].dwKeyIndex
;
488 pKey
->uKeyLength
= pMgmt
->sNodeDBTable
[iSANodeIndex
].uWepKeyLength
;
489 pKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[iSANodeIndex
].dwTSC47_16
;
490 pKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[iSANodeIndex
].wTSC15_0
;
492 &pMgmt
->sNodeDBTable
[iSANodeIndex
].abyWepKey
[0],
496 bRxDecryOK
= s_bHostWepRxEncryption(pDevice
,
500 pMgmt
->sNodeDBTable
[iSANodeIndex
].bOnFly
,
507 bRxDecryOK
= s_bHandleRxEncryption(pDevice
,
519 if ((*pbyNewRsr
& NEWRSR_DECRYPTOK
) == 0) {
520 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV Fail\n");
521 if ( (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPA
) ||
522 (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPAPSK
) ||
523 (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) ||
524 (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2
) ||
525 (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2PSK
)) {
527 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
528 pDevice
->s802_11Counter
.TKIPICVErrors
++;
529 } else if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_CCMP
)) {
530 pDevice
->s802_11Counter
.CCMPDecryptErrors
++;
531 } else if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_WEP
)) {
532 // pDevice->s802_11Counter.WEPICVErrorCount.QuadPart++;
538 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"WEP Func Fail\n");
541 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_CCMP
))
542 FrameSize
-= 8; // Message Integrity Code
544 FrameSize
-= 4; // 4 is ICV
551 //remove the CRC length
552 FrameSize
-= ETH_FCS_LEN
;
554 if (( !(*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
))) && // unicast address
555 (IS_FRAGMENT_PKT((skb
->data
+4)))
558 bDeFragRx
= WCTLbHandleFragment(pDevice
, (PS802_11Header
) (skb
->data
+4), FrameSize
, bIsWEP
, bExtIV
);
559 pDevice
->s802_11Counter
.ReceivedFragmentCount
++;
562 skb
= pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].skb
;
563 FrameSize
= pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].cbFrameLength
;
572 // Management & Control frame Handle
573 if ((IS_TYPE_DATA((skb
->data
+4))) == false) {
574 // Handle Control & Manage Frame
576 if (IS_TYPE_MGMT((skb
->data
+4))) {
577 unsigned char *pbyData1
;
578 unsigned char *pbyData2
;
580 pRxPacket
->p80211Header
= (PUWLAN_80211HDR
)(skb
->data
+4);
581 pRxPacket
->cbMPDULen
= FrameSize
;
582 pRxPacket
->uRSSI
= *pbyRSSI
;
583 pRxPacket
->bySQ
= *pbySQ
;
584 HIDWORD(pRxPacket
->qwLocalTSF
) = cpu_to_le32(HIDWORD(*pqwTSFTime
));
585 LODWORD(pRxPacket
->qwLocalTSF
) = cpu_to_le32(LODWORD(*pqwTSFTime
));
588 pbyData1
= WLAN_HDR_A3_DATA_PTR(skb
->data
+4);
589 pbyData2
= WLAN_HDR_A3_DATA_PTR(skb
->data
+4) + 4;
590 for (ii
= 0; ii
< (FrameSize
- 4); ii
++) {
591 *pbyData1
= *pbyData2
;
596 pRxPacket
->byRxRate
= s_byGetRateIdx(*pbyRxRate
);
597 pRxPacket
->byRxChannel
= (*pbyRxSts
) >> 2;
599 //EnQueue(pDevice,pRxPacket);
602 EnQueue(pDevice
,pRxPacket
);
604 //printk("enque time is %x\n",jiffies);
605 //up(&pDevice->mlme_semaphore);
606 //Enque (pDevice->FirstRecvMngList,pDevice->LastRecvMngList,pMgmt);
610 EnQueue(pDevice
,pRxPacket
);
611 tasklet_schedule(&pDevice
->RxMngWorkItem
);
614 vMgrRxManagePacket((void *)pDevice
, pDevice
->pMgmt
, pRxPacket
);
615 //tasklet_schedule(&pDevice->RxMngWorkItem);
620 //vMgrRxManagePacket((void *)pDevice, pDevice->pMgmt, pRxPacket);
621 // hostap Deamon handle 802.11 management
622 if (pDevice
->bEnableHostapd
) {
623 skb
->dev
= pDevice
->apdev
;
626 skb_put(skb
, FrameSize
);
627 skb_reset_mac_header(skb
);
628 skb
->pkt_type
= PACKET_OTHERHOST
;
629 skb
->protocol
= htons(ETH_P_802_2
);
630 memset(skb
->cb
, 0, sizeof(skb
->cb
));
641 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
642 //In AP mode, hw only check addr1(BSSID or RA) if equal to local MAC.
643 if ( !(*pbyRsr
& RSR_BSSIDOK
)) {
645 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
646 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
654 // discard DATA packet while not associate || BSSID error
655 if ((pDevice
->bLinkPass
== false) ||
656 !(*pbyRsr
& RSR_BSSIDOK
)) {
658 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
659 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
665 //mike add:station mode check eapol-key challenge--->
667 unsigned char Protocol_Version
; //802.1x Authentication
668 unsigned char Packet_Type
; //802.1x Authentication
673 wEtherType
= (skb
->data
[cbIVOffset
+ 8 + 24 + 6] << 8) |
674 skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1];
675 Protocol_Version
= skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1 +1];
676 Packet_Type
= skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1 +1+1];
677 if (wEtherType
== ETH_P_PAE
) { //Protocol Type in LLC-Header
678 if(((Protocol_Version
==1) ||(Protocol_Version
==2)) &&
679 (Packet_Type
==3)) { //802.1x OR eapol-key challenge frame receive
684 //mike add:station mode check eapol-key challenge<---
692 if (pDevice
->bEnablePSMode
) {
693 if (IS_FC_MOREDATA((skb
->data
+4))) {
694 if (*pbyRsr
& RSR_ADDROK
) {
695 //PSbSendPSPOLL((PSDevice)pDevice);
699 if (pDevice
->pMgmt
->bInTIMWake
== true) {
700 pDevice
->pMgmt
->bInTIMWake
= false;
705 // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps
706 if (pDevice
->bDiversityEnable
&& (FrameSize
>50) &&
707 (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) &&
708 (pDevice
->bLinkPass
== true)) {
709 //printk("device_receive_frame: RxRate is %d\n",*pbyRxRate);
710 BBvAntennaDiversity(pDevice
, s_byGetRateIdx(*pbyRxRate
), 0);
714 if (pDevice
->byLocalID
!= REV_ID_VT3253_B1
) {
715 pDevice
->uCurrRSSI
= *pbyRSSI
;
717 pDevice
->byCurrSQ
= *pbySQ
;
719 if ((*pbyRSSI
!= 0) &&
720 (pMgmt
->pCurrBSS
!=NULL
)) {
721 RFvRSSITodBm(pDevice
, *pbyRSSI
, &ldBm
);
722 // Moniter if RSSI is too strong.
723 pMgmt
->pCurrBSS
->byRSSIStatCnt
++;
724 pMgmt
->pCurrBSS
->byRSSIStatCnt
%= RSSI_STAT_COUNT
;
725 pMgmt
->pCurrBSS
->ldBmAverage
[pMgmt
->pCurrBSS
->byRSSIStatCnt
] = ldBm
;
726 for(ii
=0;ii
<RSSI_STAT_COUNT
;ii
++) {
727 if (pMgmt
->pCurrBSS
->ldBmAverage
[ii
] != 0) {
728 pMgmt
->pCurrBSS
->ldBmMAX
= max(pMgmt
->pCurrBSS
->ldBmAverage
[ii
], ldBm
);
733 // -----------------------------------------------
735 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) && (pDevice
->bEnable8021x
== true)){
736 unsigned char abyMacHdr
[24];
738 // Only 802.1x packet incoming allowed
743 wEtherType
= (skb
->data
[cbIVOffset
+ 4 + 24 + 6] << 8) |
744 skb
->data
[cbIVOffset
+ 4 + 24 + 6 + 1];
746 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wEtherType = %04x \n", wEtherType
);
747 if (wEtherType
== ETH_P_PAE
) {
748 skb
->dev
= pDevice
->apdev
;
750 if (bIsWEP
== true) {
751 // strip IV header(8)
752 memcpy(&abyMacHdr
[0], (skb
->data
+ 4), 24);
753 memcpy((skb
->data
+ 4 + cbIVOffset
), &abyMacHdr
[0], 24);
755 skb
->data
+= (cbIVOffset
+ 4);
756 skb
->tail
+= (cbIVOffset
+ 4);
757 skb_put(skb
, FrameSize
);
758 skb_reset_mac_header(skb
);
760 skb
->pkt_type
= PACKET_OTHERHOST
;
761 skb
->protocol
= htons(ETH_P_802_2
);
762 memset(skb
->cb
, 0, sizeof(skb
->cb
));
767 // check if 802.1x authorized
768 if (!(pMgmt
->sNodeDBTable
[iSANodeIndex
].dwFlags
& WLAN_STA_AUTHORIZED
))
773 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
775 FrameSize
-= 8; //MIC
779 //--------------------------------------------------------------------------------
781 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
783 unsigned long *pdwMIC_L
;
784 unsigned long *pdwMIC_R
;
785 unsigned long dwMIC_Priority
;
786 unsigned long dwMICKey0
= 0, dwMICKey1
= 0;
787 unsigned long dwLocalMIC_L
= 0;
788 unsigned long dwLocalMIC_R
= 0;
789 viawget_wpa_header
*wpahdr
;
792 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
793 dwMICKey0
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[24]));
794 dwMICKey1
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[28]));
797 if (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) {
798 dwMICKey0
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[16]));
799 dwMICKey1
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[20]));
800 } else if ((pKey
->dwKeyIndex
& BIT28
) == 0) {
801 dwMICKey0
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[16]));
802 dwMICKey1
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[20]));
804 dwMICKey0
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[24]));
805 dwMICKey1
= cpu_to_le32(*(unsigned long *)(&pKey
->abyKey
[28]));
809 MIC_vInit(dwMICKey0
, dwMICKey1
);
810 MIC_vAppend((unsigned char *)&(pDevice
->sRxEthHeader
.abyDstAddr
[0]), 12);
812 MIC_vAppend((unsigned char *)&dwMIC_Priority
, 4);
813 // 4 is Rcv buffer header, 24 is MAC Header, and 8 is IV and Ext IV.
814 MIC_vAppend((unsigned char *)(skb
->data
+ 4 + WLAN_HDR_ADDR3_LEN
+ 8),
815 FrameSize
- WLAN_HDR_ADDR3_LEN
- 8);
816 MIC_vGetMIC(&dwLocalMIC_L
, &dwLocalMIC_R
);
819 pdwMIC_L
= (unsigned long *)(skb
->data
+ 4 + FrameSize
);
820 pdwMIC_R
= (unsigned long *)(skb
->data
+ 4 + FrameSize
+ 4);
821 //DBG_PRN_GRP12(("RxL: %lx, RxR: %lx\n", *pdwMIC_L, *pdwMIC_R));
822 //DBG_PRN_GRP12(("LocalL: %lx, LocalR: %lx\n", dwLocalMIC_L, dwLocalMIC_R));
823 //DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"dwMICKey0= %lx,dwMICKey1= %lx \n", dwMICKey0, dwMICKey1);
826 if ((cpu_to_le32(*pdwMIC_L
) != dwLocalMIC_L
) || (cpu_to_le32(*pdwMIC_R
) != dwLocalMIC_R
) ||
827 (pDevice
->bRxMICFail
== true)) {
828 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC comparison is fail!\n");
829 pDevice
->bRxMICFail
= false;
830 //pDevice->s802_11Counter.TKIPLocalMICFailures.QuadPart++;
831 pDevice
->s802_11Counter
.TKIPLocalMICFailures
++;
833 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
834 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
838 //2008-0409-07, <Add> by Einsn Liu
839 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
840 //send event to wpa_supplicant
841 //if(pDevice->bWPADevEnable == true)
843 union iwreq_data wrqu
;
844 struct iw_michaelmicfailure ev
;
845 int keyidx
= pbyFrame
[cbHeaderSize
+3] >> 6; //top two-bits
846 memset(&ev
, 0, sizeof(ev
));
847 ev
.flags
= keyidx
& IW_MICFAILURE_KEY_ID
;
848 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
849 (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
) &&
850 (*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
)) == 0) {
851 ev
.flags
|= IW_MICFAILURE_PAIRWISE
;
853 ev
.flags
|= IW_MICFAILURE_GROUP
;
856 ev
.src_addr
.sa_family
= ARPHRD_ETHER
;
857 memcpy(ev
.src_addr
.sa_data
, pMACHeader
->abyAddr2
, ETH_ALEN
);
858 memset(&wrqu
, 0, sizeof(wrqu
));
859 wrqu
.data
.length
= sizeof(ev
);
860 wireless_send_event(pDevice
->dev
, IWEVMICHAELMICFAILURE
, &wrqu
, (char *)&ev
);
866 if ((pDevice
->bWPADEVUp
) && (pDevice
->skb
!= NULL
)) {
867 wpahdr
= (viawget_wpa_header
*)pDevice
->skb
->data
;
868 if ((pDevice
->pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
869 (pDevice
->pMgmt
->eCurrState
== WMAC_STATE_ASSOC
) &&
870 (*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
)) == 0) {
871 //s802_11_Status.Flags = NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR;
872 wpahdr
->type
= VIAWGET_PTK_MIC_MSG
;
874 //s802_11_Status.Flags = NDIS_802_11_AUTH_REQUEST_GROUP_ERROR;
875 wpahdr
->type
= VIAWGET_GTK_MIC_MSG
;
877 wpahdr
->resp_ie_len
= 0;
878 wpahdr
->req_ie_len
= 0;
879 skb_put(pDevice
->skb
, sizeof(viawget_wpa_header
));
880 pDevice
->skb
->dev
= pDevice
->wpadev
;
881 skb_reset_mac_header(pDevice
->skb
);
882 pDevice
->skb
->pkt_type
= PACKET_HOST
;
883 pDevice
->skb
->protocol
= htons(ETH_P_802_2
);
884 memset(pDevice
->skb
->cb
, 0, sizeof(pDevice
->skb
->cb
));
885 netif_rx(pDevice
->skb
);
886 pDevice
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
893 } //---end of SOFT MIC-----------------------------------------------------------------------
895 // ++++++++++ Reply Counter Check +++++++++++++
897 if ((pKey
!= NULL
) && ((pKey
->byCipherSuite
== KEY_CTL_TKIP
) ||
898 (pKey
->byCipherSuite
== KEY_CTL_CCMP
))) {
900 unsigned short wLocalTSC15_0
= 0;
901 unsigned long dwLocalTSC47_16
= 0;
902 unsigned long long RSC
= 0;
904 RSC
= *((unsigned long long *) &(pKey
->KeyRSC
));
905 wLocalTSC15_0
= (unsigned short) RSC
;
906 dwLocalTSC47_16
= (unsigned long) (RSC
>>16);
911 memcpy(&(pKey
->KeyRSC
), &RSC
, sizeof(QWORD
));
913 if ( (pDevice
->sMgmtObj
.eCurrMode
== WMAC_MODE_ESS_STA
) &&
914 (pDevice
->sMgmtObj
.eCurrState
== WMAC_STATE_ASSOC
)) {
916 if ( (wRxTSC15_0
< wLocalTSC15_0
) &&
917 (dwRxTSC47_16
<= dwLocalTSC47_16
) &&
918 !((dwRxTSC47_16
== 0) && (dwLocalTSC47_16
== 0xFFFFFFFF))) {
919 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"TSC is illegal~~!\n ");
920 if (pKey
->byCipherSuite
== KEY_CTL_TKIP
)
921 //pDevice->s802_11Counter.TKIPReplays.QuadPart++;
922 pDevice
->s802_11Counter
.TKIPReplays
++;
924 //pDevice->s802_11Counter.CCMPReplays.QuadPart++;
925 pDevice
->s802_11Counter
.CCMPReplays
++;
928 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
929 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
937 } // ----- End of Reply Counter Check --------------------------
941 if ((pKey
!= NULL
) && (bIsWEP
)) {
942 // pDevice->s802_11Counter.DecryptSuccessCount.QuadPart++;
946 s_vProcessRxMACHeader(pDevice
, (unsigned char *)(skb
->data
+4), FrameSize
, bIsWEP
, bExtIV
, &cbHeaderOffset
);
947 FrameSize
-= cbHeaderOffset
;
948 cbHeaderOffset
+= 4; // 4 is Rcv buffer header
950 // Null data, framesize = 14
954 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
955 if (s_bAPModeRxData(pDevice
,
964 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
965 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
972 // if(pDevice->bRxMICFail == false) {
973 // for (ii =0; ii < 100; ii++)
974 // printk(" %02x", *(skb->data + ii));
980 skb
->data
+= cbHeaderOffset
;
981 skb
->tail
+= cbHeaderOffset
;
982 skb_put(skb
, FrameSize
);
983 skb
->protocol
=eth_type_trans(skb
, skb
->dev
);
986 //drop frame not met IEEE 802.3
988 if (pDevice->flags & DEVICE_FLAGS_VAL_PKT_LEN) {
989 if ((skb->protocol==htons(ETH_P_802_3)) &&
990 (skb->len!=htons(skb->mac.ethernet->h_proto))) {
991 pStats->rx_length_errors++;
992 pStats->rx_dropped++;
994 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
995 DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
1004 skb
->ip_summed
=CHECKSUM_NONE
;
1005 pStats
->rx_bytes
+=skb
->len
;
1006 pStats
->rx_packets
++;
1010 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
1011 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
1012 pDevice
->dev
->name
);
1021 static bool s_bAPModeRxCtl (
1023 unsigned char *pbyFrame
,
1027 PS802_11Header p802_11Header
;
1029 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
1032 if (IS_CTL_PSPOLL(pbyFrame
) || !IS_TYPE_CONTROL(pbyFrame
)) {
1034 p802_11Header
= (PS802_11Header
) (pbyFrame
);
1035 if (!IS_TYPE_MGMT(pbyFrame
)) {
1037 // Data & PS-Poll packet
1038 // check frame class
1039 if (iSANodeIndex
> 0) {
1040 // frame class 3 fliter & checking
1041 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].eNodeState
< NODE_AUTH
) {
1042 // send deauth notification
1043 // reason = (6) class 2 received from nonauth sta
1044 vMgrDeAuthenBeginSta(pDevice
,
1046 (unsigned char *)(p802_11Header
->abyAddr2
),
1047 (WLAN_MGMT_REASON_CLASS2_NONAUTH
),
1050 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: send vMgrDeAuthenBeginSta 1\n");
1053 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].eNodeState
< NODE_ASSOC
) {
1054 // send deassoc notification
1055 // reason = (7) class 3 received from nonassoc sta
1056 vMgrDisassocBeginSta(pDevice
,
1058 (unsigned char *)(p802_11Header
->abyAddr2
),
1059 (WLAN_MGMT_REASON_CLASS3_NONASSOC
),
1062 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: send vMgrDisassocBeginSta 2\n");
1066 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
) {
1067 // delcare received ps-poll event
1068 if (IS_CTL_PSPOLL(pbyFrame
)) {
1069 pMgmt
->sNodeDBTable
[iSANodeIndex
].bRxPSPoll
= true;
1070 bScheduleCommand((void *)pDevice
, WLAN_CMD_RX_PSPOLL
, NULL
);
1071 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: WLAN_CMD_RX_PSPOLL 1\n");
1074 // check Data PS state
1075 // if PW bit off, send out all PS bufferring packets.
1076 if (!IS_FC_POWERMGT(pbyFrame
)) {
1077 pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
= false;
1078 pMgmt
->sNodeDBTable
[iSANodeIndex
].bRxPSPoll
= true;
1079 bScheduleCommand((void *)pDevice
, WLAN_CMD_RX_PSPOLL
, NULL
);
1080 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: WLAN_CMD_RX_PSPOLL 2\n");
1085 if (IS_FC_POWERMGT(pbyFrame
)) {
1086 pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
= true;
1087 // Once if STA in PS state, enable multicast bufferring
1088 pMgmt
->sNodeDBTable
[0].bPSEnable
= true;
1091 // clear all pending PS frame.
1092 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].wEnQueueCnt
> 0) {
1093 pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
= false;
1094 pMgmt
->sNodeDBTable
[iSANodeIndex
].bRxPSPoll
= true;
1095 bScheduleCommand((void *)pDevice
, WLAN_CMD_RX_PSPOLL
, NULL
);
1096 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: WLAN_CMD_RX_PSPOLL 3\n");
1103 vMgrDeAuthenBeginSta(pDevice
,
1105 (unsigned char *)(p802_11Header
->abyAddr2
),
1106 (WLAN_MGMT_REASON_CLASS2_NONAUTH
),
1109 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: send vMgrDeAuthenBeginSta 3\n");
1110 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"BSSID:%pM\n",
1111 p802_11Header
->abyAddr3
);
1112 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ADDR2:%pM\n",
1113 p802_11Header
->abyAddr2
);
1114 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ADDR1:%pM\n",
1115 p802_11Header
->abyAddr1
);
1116 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: wFrameCtl= %x\n", p802_11Header
->wFrameCtl
);
1117 VNSvInPortB(pDevice
->PortOffset
+ MAC_REG_RCR
, &(pDevice
->byRxMode
));
1118 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc:pDevice->byRxMode = %x\n", pDevice
->byRxMode
);
1127 static bool s_bHandleRxEncryption (
1129 unsigned char *pbyFrame
,
1130 unsigned int FrameSize
,
1131 unsigned char *pbyRsr
,
1132 unsigned char *pbyNewRsr
,
1135 unsigned short *pwRxTSC15_0
,
1136 unsigned long *pdwRxTSC47_16
1139 unsigned int PayloadLen
= FrameSize
;
1140 unsigned char *pbyIV
;
1141 unsigned char byKeyIdx
;
1142 PSKeyItem pKey
= NULL
;
1143 unsigned char byDecMode
= KEY_CTL_WEP
;
1144 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
1150 pbyIV
= pbyFrame
+ WLAN_HDR_ADDR3_LEN
;
1151 if ( WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame
) &&
1152 WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame
) ) {
1153 pbyIV
+= 6; // 6 is 802.11 address4
1156 byKeyIdx
= (*(pbyIV
+3) & 0xc0);
1158 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\nKeyIdx: %d\n", byKeyIdx
);
1160 if ((pMgmt
->eAuthenMode
== WMAC_AUTH_WPA
) ||
1161 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPAPSK
) ||
1162 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) ||
1163 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2
) ||
1164 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2PSK
)) {
1165 if (((*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
)) == 0) &&
1166 (pDevice
->pMgmt
->byCSSPK
!= KEY_CTL_NONE
)) {
1167 // unicast pkt use pairwise key
1168 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"unicast pkt\n");
1169 if (KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBSSID
, 0xFFFFFFFF, &pKey
) == true) {
1170 if (pDevice
->pMgmt
->byCSSPK
== KEY_CTL_TKIP
)
1171 byDecMode
= KEY_CTL_TKIP
;
1172 else if (pDevice
->pMgmt
->byCSSPK
== KEY_CTL_CCMP
)
1173 byDecMode
= KEY_CTL_CCMP
;
1175 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"unicast pkt: %d, %p\n", byDecMode
, pKey
);
1178 KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBSSID
, byKeyIdx
, &pKey
);
1179 if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_TKIP
)
1180 byDecMode
= KEY_CTL_TKIP
;
1181 else if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_CCMP
)
1182 byDecMode
= KEY_CTL_CCMP
;
1183 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"group pkt: %d, %d, %p\n", byKeyIdx
, byDecMode
, pKey
);
1186 // our WEP only support Default Key
1188 // use default group key
1189 KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBroadcastAddr
, byKeyIdx
, &pKey
);
1190 if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_TKIP
)
1191 byDecMode
= KEY_CTL_TKIP
;
1192 else if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_CCMP
)
1193 byDecMode
= KEY_CTL_CCMP
;
1197 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"AES:%d %d %d\n", pDevice
->pMgmt
->byCSSPK
, pDevice
->pMgmt
->byCSSGK
, byDecMode
);
1200 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey == NULL\n");
1201 if (byDecMode
== KEY_CTL_WEP
) {
1202 // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1203 } else if (pDevice
->bLinkPass
== true) {
1204 // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1208 if (byDecMode
!= pKey
->byCipherSuite
) {
1209 if (byDecMode
== KEY_CTL_WEP
) {
1210 // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1211 } else if (pDevice
->bLinkPass
== true) {
1212 // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1217 if (byDecMode
== KEY_CTL_WEP
) {
1219 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
) ||
1220 (((PSKeyTable
)(pKey
->pvKeyTable
))->bSoftWEP
== true)) {
1225 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1226 memcpy(pDevice
->abyPRNG
, pbyIV
, 3);
1227 memcpy(pDevice
->abyPRNG
+ 3, pKey
->abyKey
, pKey
->uKeyLength
);
1228 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, pKey
->uKeyLength
+ 3);
1229 rc4_encrypt(&pDevice
->SBox
, pbyIV
+4, pbyIV
+4, PayloadLen
);
1231 if (ETHbIsBufferCrc32Ok(pbyIV
+4, PayloadLen
)) {
1232 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1235 } else if ((byDecMode
== KEY_CTL_TKIP
) ||
1236 (byDecMode
== KEY_CTL_CCMP
)) {
1239 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1240 *pdwRxTSC47_16
= cpu_to_le32(*(unsigned long *)(pbyIV
+ 4));
1241 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ExtIV: %lx\n",*pdwRxTSC47_16
);
1242 if (byDecMode
== KEY_CTL_TKIP
) {
1243 *pwRxTSC15_0
= cpu_to_le16(MAKEWORD(*(pbyIV
+2), *pbyIV
));
1245 *pwRxTSC15_0
= cpu_to_le16(*(unsigned short *)pbyIV
);
1247 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"TSC0_15: %x\n", *pwRxTSC15_0
);
1249 if ((byDecMode
== KEY_CTL_TKIP
) &&
1250 (pDevice
->byLocalID
<= REV_ID_VT3253_A1
)) {
1253 PS802_11Header pMACHeader
= (PS802_11Header
) (pbyFrame
);
1254 TKIPvMixKey(pKey
->abyKey
, pMACHeader
->abyAddr2
, *pwRxTSC15_0
, *pdwRxTSC47_16
, pDevice
->abyPRNG
);
1255 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, TKIP_KEY_LEN
);
1256 rc4_encrypt(&pDevice
->SBox
, pbyIV
+8, pbyIV
+8, PayloadLen
);
1257 if (ETHbIsBufferCrc32Ok(pbyIV
+8, PayloadLen
)) {
1258 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1259 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV OK!\n");
1261 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV FAIL!!!\n");
1262 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PayloadLen = %d\n", PayloadLen
);
1267 if ((*(pbyIV
+3) & 0x20) != 0)
1273 static bool s_bHostWepRxEncryption (
1275 unsigned char *pbyFrame
,
1276 unsigned int FrameSize
,
1277 unsigned char *pbyRsr
,
1280 unsigned char *pbyNewRsr
,
1282 unsigned short *pwRxTSC15_0
,
1283 unsigned long *pdwRxTSC47_16
1286 unsigned int PayloadLen
= FrameSize
;
1287 unsigned char *pbyIV
;
1288 unsigned char byKeyIdx
;
1289 unsigned char byDecMode
= KEY_CTL_WEP
;
1290 PS802_11Header pMACHeader
;
1297 pbyIV
= pbyFrame
+ WLAN_HDR_ADDR3_LEN
;
1298 if ( WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame
) &&
1299 WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame
) ) {
1300 pbyIV
+= 6; // 6 is 802.11 address4
1303 byKeyIdx
= (*(pbyIV
+3) & 0xc0);
1305 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\nKeyIdx: %d\n", byKeyIdx
);
1308 if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_TKIP
)
1309 byDecMode
= KEY_CTL_TKIP
;
1310 else if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_CCMP
)
1311 byDecMode
= KEY_CTL_CCMP
;
1313 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"AES:%d %d %d\n", pDevice
->pMgmt
->byCSSPK
, pDevice
->pMgmt
->byCSSGK
, byDecMode
);
1315 if (byDecMode
!= pKey
->byCipherSuite
) {
1316 if (byDecMode
== KEY_CTL_WEP
) {
1317 // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1318 } else if (pDevice
->bLinkPass
== true) {
1319 // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1324 if (byDecMode
== KEY_CTL_WEP
) {
1326 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"byDecMode == KEY_CTL_WEP \n");
1327 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
) ||
1328 (((PSKeyTable
)(pKey
->pvKeyTable
))->bSoftWEP
== true) ||
1329 (bOnFly
== false)) {
1335 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1336 memcpy(pDevice
->abyPRNG
, pbyIV
, 3);
1337 memcpy(pDevice
->abyPRNG
+ 3, pKey
->abyKey
, pKey
->uKeyLength
);
1338 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, pKey
->uKeyLength
+ 3);
1339 rc4_encrypt(&pDevice
->SBox
, pbyIV
+4, pbyIV
+4, PayloadLen
);
1341 if (ETHbIsBufferCrc32Ok(pbyIV
+4, PayloadLen
)) {
1342 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1345 } else if ((byDecMode
== KEY_CTL_TKIP
) ||
1346 (byDecMode
== KEY_CTL_CCMP
)) {
1349 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1350 *pdwRxTSC47_16
= cpu_to_le32(*(unsigned long *)(pbyIV
+ 4));
1351 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ExtIV: %lx\n",*pdwRxTSC47_16
);
1353 if (byDecMode
== KEY_CTL_TKIP
) {
1354 *pwRxTSC15_0
= cpu_to_le16(MAKEWORD(*(pbyIV
+2), *pbyIV
));
1356 *pwRxTSC15_0
= cpu_to_le16(*(unsigned short *)pbyIV
);
1358 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"TSC0_15: %x\n", *pwRxTSC15_0
);
1360 if (byDecMode
== KEY_CTL_TKIP
) {
1362 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
) || (bOnFly
== false)) {
1366 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"soft KEY_CTL_TKIP \n");
1367 pMACHeader
= (PS802_11Header
) (pbyFrame
);
1368 TKIPvMixKey(pKey
->abyKey
, pMACHeader
->abyAddr2
, *pwRxTSC15_0
, *pdwRxTSC47_16
, pDevice
->abyPRNG
);
1369 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, TKIP_KEY_LEN
);
1370 rc4_encrypt(&pDevice
->SBox
, pbyIV
+8, pbyIV
+8, PayloadLen
);
1371 if (ETHbIsBufferCrc32Ok(pbyIV
+8, PayloadLen
)) {
1372 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1373 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV OK!\n");
1375 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV FAIL!!!\n");
1376 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PayloadLen = %d\n", PayloadLen
);
1381 if (byDecMode
== KEY_CTL_CCMP
) {
1382 if (bOnFly
== false) {
1385 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"soft KEY_CTL_CCMP\n");
1386 if (AESbGenCCMP(pKey
->abyKey
, pbyFrame
, FrameSize
)) {
1387 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1388 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CCMP MIC compare OK!\n");
1390 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CCMP MIC fail!\n");
1397 if ((*(pbyIV
+3) & 0x20) != 0)
1404 static bool s_bAPModeRxData (
1406 struct sk_buff
* skb
,
1407 unsigned int FrameSize
,
1408 unsigned int cbHeaderOffset
,
1413 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
1414 bool bRelayAndForward
= false;
1415 bool bRelayOnly
= false;
1416 unsigned char byMask
[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1417 unsigned short wAID
;
1420 struct sk_buff
* skbcpy
= NULL
;
1422 if (FrameSize
> CB_MAX_BUF_SIZE
)
1425 if(is_multicast_ether_addr((unsigned char *)(skb
->data
+cbHeaderOffset
))) {
1426 if (pMgmt
->sNodeDBTable
[0].bPSEnable
) {
1428 skbcpy
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
1430 // if any node in PS mode, buffer packet until DTIM.
1431 if (skbcpy
== NULL
) {
1432 DBG_PRT(MSG_LEVEL_NOTICE
, KERN_INFO
"relay multicast no skb available \n");
1435 skbcpy
->dev
= pDevice
->dev
;
1436 skbcpy
->len
= FrameSize
;
1437 memcpy(skbcpy
->data
, skb
->data
+cbHeaderOffset
, FrameSize
);
1438 skb_queue_tail(&(pMgmt
->sNodeDBTable
[0].sTxPSQueue
), skbcpy
);
1440 pMgmt
->sNodeDBTable
[0].wEnQueueCnt
++;
1442 pMgmt
->abyPSTxMap
[0] |= byMask
[0];
1446 bRelayAndForward
= true;
1451 if (BSSDBbIsSTAInNodeDB(pMgmt
, (unsigned char *)(skb
->data
+cbHeaderOffset
), &iDANodeIndex
)) {
1452 if (pMgmt
->sNodeDBTable
[iDANodeIndex
].eNodeState
>= NODE_ASSOC
) {
1453 if (pMgmt
->sNodeDBTable
[iDANodeIndex
].bPSEnable
) {
1454 // queue this skb until next PS tx, and then release.
1456 skb
->data
+= cbHeaderOffset
;
1457 skb
->tail
+= cbHeaderOffset
;
1458 skb_put(skb
, FrameSize
);
1459 skb_queue_tail(&pMgmt
->sNodeDBTable
[iDANodeIndex
].sTxPSQueue
, skb
);
1460 pMgmt
->sNodeDBTable
[iDANodeIndex
].wEnQueueCnt
++;
1461 wAID
= pMgmt
->sNodeDBTable
[iDANodeIndex
].wAID
;
1462 pMgmt
->abyPSTxMap
[wAID
>> 3] |= byMask
[wAID
& 7];
1463 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n",
1464 iDANodeIndex
, (wAID
>> 3), pMgmt
->abyPSTxMap
[wAID
>> 3]);
1474 if (bRelayOnly
|| bRelayAndForward
) {
1475 // relay this packet right now
1476 if (bRelayAndForward
)
1479 if ((pDevice
->uAssocCount
> 1) && (iDANodeIndex
>= 0)) {
1480 ROUTEbRelay(pDevice
, (unsigned char *)(skb
->data
+ cbHeaderOffset
), FrameSize
, (unsigned int)iDANodeIndex
);
1486 // none associate, don't forward
1487 if (pDevice
->uAssocCount
== 0)