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
58 /*--------------------- Static Definitions -------------------------*/
60 /*--------------------- Static Classes ----------------------------*/
62 /*--------------------- Static Variables --------------------------*/
63 static int msglevel
= MSG_LEVEL_INFO
;
65 const unsigned char acbyRxRate
[MAX_RATE
] =
66 {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
68 /*--------------------- Static Functions --------------------------*/
70 /*--------------------- Static Definitions -------------------------*/
72 /*--------------------- Static Functions --------------------------*/
74 static unsigned char s_byGetRateIdx(unsigned char byRate
);
77 s_vGetDASA(unsigned char *pbyRxBufferAddr
, unsigned int *pcbHeaderSize
,
78 PSEthernetHeader psEthHeader
);
81 s_vProcessRxMACHeader(PSDevice pDevice
, unsigned char *pbyRxBufferAddr
,
82 unsigned int cbPacketSize
, bool bIsWEP
, bool bExtIV
,
83 unsigned int *pcbHeadSize
);
85 static bool s_bAPModeRxCtl(
87 unsigned char *pbyFrame
,
91 static bool s_bAPModeRxData(
94 unsigned int FrameSize
,
95 unsigned int cbHeaderOffset
,
100 static bool s_bHandleRxEncryption(
102 unsigned char *pbyFrame
,
103 unsigned int FrameSize
,
104 unsigned char *pbyRsr
,
105 unsigned char *pbyNewRsr
,
108 unsigned short *pwRxTSC15_0
,
109 unsigned long *pdwRxTSC47_16
112 static bool s_bHostWepRxEncryption(
115 unsigned char *pbyFrame
,
116 unsigned int FrameSize
,
117 unsigned char *pbyRsr
,
120 unsigned char *pbyNewRsr
,
122 unsigned short *pwRxTSC15_0
,
123 unsigned long *pdwRxTSC47_16
127 /*--------------------- Export Variables --------------------------*/
132 * Translate Rcv 802.11 header to 802.3 header with Rx buffer
137 * dwRxBufferAddr - Address of Rcv Buffer
138 * cbPacketSize - Rcv Packet size
139 * bIsWEP - If Rcv with WEP
141 * pcbHeaderSize - 802.11 header size
147 s_vProcessRxMACHeader(PSDevice pDevice
, unsigned char *pbyRxBufferAddr
,
148 unsigned int cbPacketSize
, bool bIsWEP
, bool bExtIV
,
149 unsigned int *pcbHeadSize
)
151 unsigned char *pbyRxBuffer
;
152 unsigned int cbHeaderSize
= 0;
153 unsigned short *pwType
;
154 PS802_11Header pMACHeader
;
157 pMACHeader
= (PS802_11Header
) (pbyRxBufferAddr
+ cbHeaderSize
);
159 s_vGetDASA((unsigned char *)pMACHeader
, &cbHeaderSize
, &pDevice
->sRxEthHeader
);
163 // strip IV&ExtIV , add 8 byte
164 cbHeaderSize
+= (WLAN_HDR_ADDR3_LEN
+ 8);
166 // strip IV , add 4 byte
167 cbHeaderSize
+= (WLAN_HDR_ADDR3_LEN
+ 4);
170 cbHeaderSize
+= WLAN_HDR_ADDR3_LEN
;
173 pbyRxBuffer
= (unsigned char *)(pbyRxBufferAddr
+ cbHeaderSize
);
174 if (ether_addr_equal(pbyRxBuffer
, pDevice
->abySNAP_Bridgetunnel
)) {
176 } else if (ether_addr_equal(pbyRxBuffer
, pDevice
->abySNAP_RFC1042
)) {
178 pwType
= (unsigned short *)(pbyRxBufferAddr
+ cbHeaderSize
);
179 if ((*pwType
!= TYPE_PKT_IPX
) && (*pwType
!= cpu_to_le16(0xF380))) {
182 pwType
= (unsigned short *)(pbyRxBufferAddr
+ cbHeaderSize
);
185 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 8); // 8 is IV&ExtIV
187 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 4); // 4 is IV
190 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
);
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
203 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
);
207 cbHeaderSize
-= (ETH_ALEN
* 2);
208 pbyRxBuffer
= (unsigned char *)(pbyRxBufferAddr
+ cbHeaderSize
);
209 for (ii
= 0; ii
< ETH_ALEN
; ii
++)
210 *pbyRxBuffer
++ = pDevice
->sRxEthHeader
.abyDstAddr
[ii
];
211 for (ii
= 0; ii
< ETH_ALEN
; ii
++)
212 *pbyRxBuffer
++ = pDevice
->sRxEthHeader
.abySrcAddr
[ii
];
214 *pcbHeadSize
= cbHeaderSize
;
217 static unsigned char s_byGetRateIdx(unsigned char byRate
)
219 unsigned char byRateIdx
;
221 for (byRateIdx
= 0; byRateIdx
< MAX_RATE
; byRateIdx
++) {
222 if (acbyRxRate
[byRateIdx
% MAX_RATE
] == byRate
)
230 s_vGetDASA(unsigned char *pbyRxBufferAddr
, unsigned int *pcbHeaderSize
,
231 PSEthernetHeader psEthHeader
)
233 unsigned int cbHeaderSize
= 0;
234 PS802_11Header pMACHeader
;
237 pMACHeader
= (PS802_11Header
) (pbyRxBufferAddr
+ cbHeaderSize
);
239 if ((pMACHeader
->wFrameCtl
& FC_TODS
) == 0) {
240 if (pMACHeader
->wFrameCtl
& FC_FROMDS
) {
241 for (ii
= 0; ii
< ETH_ALEN
; ii
++) {
242 psEthHeader
->abyDstAddr
[ii
] = pMACHeader
->abyAddr1
[ii
];
243 psEthHeader
->abySrcAddr
[ii
] = pMACHeader
->abyAddr3
[ii
];
247 for (ii
= 0; ii
< ETH_ALEN
; ii
++) {
248 psEthHeader
->abyDstAddr
[ii
] = pMACHeader
->abyAddr1
[ii
];
249 psEthHeader
->abySrcAddr
[ii
] = pMACHeader
->abyAddr2
[ii
];
254 if (pMACHeader
->wFrameCtl
& FC_FROMDS
) {
255 for (ii
= 0; ii
< ETH_ALEN
; ii
++) {
256 psEthHeader
->abyDstAddr
[ii
] = pMACHeader
->abyAddr3
[ii
];
257 psEthHeader
->abySrcAddr
[ii
] = pMACHeader
->abyAddr4
[ii
];
261 for (ii
= 0; ii
< ETH_ALEN
; ii
++) {
262 psEthHeader
->abyDstAddr
[ii
] = pMACHeader
->abyAddr3
[ii
];
263 psEthHeader
->abySrcAddr
[ii
] = pMACHeader
->abyAddr2
[ii
];
267 *pcbHeaderSize
= cbHeaderSize
;
272 void MngWorkItem(void *Context
)
274 PSRxMgmtPacket pRxMgmtPacket
;
275 PSDevice pDevice
= (PSDevice
) Context
;
277 spin_lock_irq(&pDevice
->lock
);
278 while (pDevice
->rxManeQueue
.packet_num
!= 0) {
279 pRxMgmtPacket
= DeQueue(pDevice
);
280 vMgrRxManagePacket(pDevice
, pDevice
->pMgmt
, pRxMgmtPacket
);
282 spin_unlock_irq(&pDevice
->lock
);
288 device_receive_frame(
293 PDEVICE_RD_INFO pRDInfo
= pCurrRD
->pRDInfo
;
294 struct net_device_stats
*pStats
= &pDevice
->stats
;
296 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
297 PSRxMgmtPacket pRxPacket
= &(pDevice
->pMgmt
->sRxPacket
);
298 PS802_11Header p802_11Header
;
299 unsigned char *pbyRsr
;
300 unsigned char *pbyNewRsr
;
301 unsigned char *pbyRSSI
;
303 unsigned short *pwFrameSize
;
304 unsigned char *pbyFrame
;
305 bool bDeFragRx
= false;
307 unsigned int cbHeaderOffset
;
308 unsigned int FrameSize
;
309 unsigned short wEtherType
= 0;
310 int iSANodeIndex
= -1;
311 int iDANodeIndex
= -1;
313 unsigned int cbIVOffset
;
315 unsigned char *pbyRxSts
;
316 unsigned char *pbyRxRate
;
317 unsigned char *pbySQ
;
318 unsigned int cbHeaderSize
;
319 PSKeyItem pKey
= NULL
;
320 unsigned short wRxTSC15_0
= 0;
321 unsigned long dwRxTSC47_16
= 0;
324 unsigned long dwDuration
= 0;
326 long ldBmThreshold
= 0;
327 PS802_11Header pMACHeader
;
328 bool bRxeapol_key
= false;
333 pci_unmap_single(pDevice
->pcid
, pRDInfo
->skb_dma
,
334 pDevice
->rx_buf_sz
, PCI_DMA_FROMDEVICE
);
336 pwFrameSize
= (unsigned short *)(skb
->data
+ 2);
337 FrameSize
= cpu_to_le16(pCurrRD
->m_rd1RD1
.wReqCount
) - cpu_to_le16(pCurrRD
->m_rd0RD0
.wResCount
);
339 // Max: 2312Payload + 30HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
340 // Min (ACK): 10HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
341 if ((FrameSize
> 2364) || (FrameSize
<= 32)) {
342 // Frame Size error drop this packet.
343 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---------- WRONG Length 1 \n");
347 pbyRxSts
= (unsigned char *)(skb
->data
);
348 pbyRxRate
= (unsigned char *)(skb
->data
+ 1);
349 pbyRsr
= (unsigned char *)(skb
->data
+ FrameSize
- 1);
350 pbyRSSI
= (unsigned char *)(skb
->data
+ FrameSize
- 2);
351 pbyNewRsr
= (unsigned char *)(skb
->data
+ FrameSize
- 3);
352 pbySQ
= (unsigned char *)(skb
->data
+ FrameSize
- 4);
353 pqwTSFTime
= (PQWORD
)(skb
->data
+ FrameSize
- 12);
354 pbyFrame
= (unsigned char *)(skb
->data
+ 4);
357 FrameSize
= cpu_to_le16(*pwFrameSize
);
359 if ((FrameSize
> 2346)|(FrameSize
< 14)) { // Max: 2312Payload + 30HD +4CRC
361 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---------- WRONG Length 2 \n");
365 // update receive statistic counter
366 STAvUpdateRDStatCounter(&pDevice
->scStatistic
,
373 pMACHeader
= (PS802_11Header
)((unsigned char *)(skb
->data
) + 8);
375 if (pDevice
->bMeasureInProgress
) {
376 if ((*pbyRsr
& RSR_CRCOK
) != 0)
377 pDevice
->byBasicMap
|= 0x01;
379 dwDuration
= (FrameSize
<< 4);
380 dwDuration
/= acbyRxRate
[*pbyRxRate
%MAX_RATE
];
381 if (*pbyRxRate
<= RATE_11M
) {
382 if (*pbyRxSts
& 0x01) {
392 RFvRSSITodBm(pDevice
, *pbyRSSI
, &ldBm
);
394 for (ii
= 7; ii
> 0;) {
395 if (ldBm
> ldBmThreshold
)
401 pDevice
->dwRPIs
[ii
] += dwDuration
;
405 if (!is_multicast_ether_addr(pbyFrame
)) {
406 if (WCTLbIsDuplicate(&(pDevice
->sDupRxCache
), (PS802_11Header
)(skb
->data
+ 4))) {
407 pDevice
->s802_11Counter
.FrameDuplicateCount
++;
413 s_vGetDASA(skb
->data
+4, &cbHeaderSize
, &pDevice
->sRxEthHeader
);
415 // filter packet send from myself
416 if (ether_addr_equal(pDevice
->sRxEthHeader
.abySrcAddr
,
417 pDevice
->abyCurrentNetAddr
))
420 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) || (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
)) {
421 if (IS_CTL_PSPOLL(pbyFrame
) || !IS_TYPE_CONTROL(pbyFrame
)) {
422 p802_11Header
= (PS802_11Header
)(pbyFrame
);
424 if (BSSDBbIsSTAInNodeDB(pMgmt
, (unsigned char *)(p802_11Header
->abyAddr2
), &iSANodeIndex
)) {
425 pMgmt
->sNodeDBTable
[iSANodeIndex
].ulLastRxJiffer
= jiffies
;
426 pMgmt
->sNodeDBTable
[iSANodeIndex
].uInActiveCount
= 0;
431 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
432 if (s_bAPModeRxCtl(pDevice
, pbyFrame
, iSANodeIndex
))
436 if (IS_FC_WEP(pbyFrame
)) {
437 bool bRxDecryOK
= false;
439 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"rx WEP pkt\n");
441 if ((pDevice
->bEnableHostWEP
) && (iSANodeIndex
>= 0)) {
443 pKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[iSANodeIndex
].byCipherSuite
;
444 pKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[iSANodeIndex
].dwKeyIndex
;
445 pKey
->uKeyLength
= pMgmt
->sNodeDBTable
[iSANodeIndex
].uWepKeyLength
;
446 pKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[iSANodeIndex
].dwTSC47_16
;
447 pKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[iSANodeIndex
].wTSC15_0
;
449 &pMgmt
->sNodeDBTable
[iSANodeIndex
].abyWepKey
[0],
453 bRxDecryOK
= s_bHostWepRxEncryption(pDevice
,
457 pMgmt
->sNodeDBTable
[iSANodeIndex
].bOnFly
,
464 bRxDecryOK
= s_bHandleRxEncryption(pDevice
,
476 if ((*pbyNewRsr
& NEWRSR_DECRYPTOK
) == 0) {
477 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV Fail\n");
478 if ((pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPA
) ||
479 (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPAPSK
) ||
480 (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) ||
481 (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2
) ||
482 (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2PSK
)) {
483 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_TKIP
))
484 pDevice
->s802_11Counter
.TKIPICVErrors
++;
485 else if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_CCMP
))
486 pDevice
->s802_11Counter
.CCMPDecryptErrors
++;
491 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"WEP Func Fail\n");
494 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_CCMP
))
495 FrameSize
-= 8; // Message Integrity Code
497 FrameSize
-= 4; // 4 is ICV
503 //remove the CRC length
504 FrameSize
-= ETH_FCS_LEN
;
506 if ((!(*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
))) && // unicast address
507 (IS_FRAGMENT_PKT((skb
->data
+4)))
510 bDeFragRx
= WCTLbHandleFragment(pDevice
, (PS802_11Header
)(skb
->data
+4), FrameSize
, bIsWEP
, bExtIV
);
511 pDevice
->s802_11Counter
.ReceivedFragmentCount
++;
514 skb
= pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].skb
;
515 FrameSize
= pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].cbFrameLength
;
522 // Management & Control frame Handle
523 if ((IS_TYPE_DATA((skb
->data
+4))) == false) {
524 // Handle Control & Manage Frame
526 if (IS_TYPE_MGMT((skb
->data
+4))) {
527 unsigned char *pbyData1
;
528 unsigned char *pbyData2
;
530 pRxPacket
->p80211Header
= (PUWLAN_80211HDR
)(skb
->data
+4);
531 pRxPacket
->cbMPDULen
= FrameSize
;
532 pRxPacket
->uRSSI
= *pbyRSSI
;
533 pRxPacket
->bySQ
= *pbySQ
;
534 HIDWORD(pRxPacket
->qwLocalTSF
) = cpu_to_le32(HIDWORD(*pqwTSFTime
));
535 LODWORD(pRxPacket
->qwLocalTSF
) = cpu_to_le32(LODWORD(*pqwTSFTime
));
538 pbyData1
= WLAN_HDR_A3_DATA_PTR(skb
->data
+4);
539 pbyData2
= WLAN_HDR_A3_DATA_PTR(skb
->data
+4) + 4;
540 for (ii
= 0; ii
< (FrameSize
- 4); ii
++) {
541 *pbyData1
= *pbyData2
;
546 pRxPacket
->byRxRate
= s_byGetRateIdx(*pbyRxRate
);
547 pRxPacket
->byRxChannel
= (*pbyRxSts
) >> 2;
551 EnQueue(pDevice
, pRxPacket
);
555 EnQueue(pDevice
, pRxPacket
);
556 tasklet_schedule(&pDevice
->RxMngWorkItem
);
558 vMgrRxManagePacket((void *)pDevice
, pDevice
->pMgmt
, pRxPacket
);
563 // hostap Deamon handle 802.11 management
564 if (pDevice
->bEnableHostapd
) {
565 skb
->dev
= pDevice
->apdev
;
568 skb_put(skb
, FrameSize
);
569 skb_reset_mac_header(skb
);
570 skb
->pkt_type
= PACKET_OTHERHOST
;
571 skb
->protocol
= htons(ETH_P_802_2
);
572 memset(skb
->cb
, 0, sizeof(skb
->cb
));
580 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
581 //In AP mode, hw only check addr1(BSSID or RA) if equal to local MAC.
582 if (!(*pbyRsr
& RSR_BSSIDOK
)) {
584 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
585 DBG_PRT(MSG_LEVEL_ERR
, KERN_ERR
"%s: can not alloc more frag bufs\n",
592 // discard DATA packet while not associate || BSSID error
593 if (!pDevice
->bLinkPass
|| !(*pbyRsr
& RSR_BSSIDOK
)) {
595 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
596 DBG_PRT(MSG_LEVEL_ERR
, KERN_ERR
"%s: can not alloc more frag bufs\n",
602 //mike add:station mode check eapol-key challenge--->
604 unsigned char Protocol_Version
; //802.1x Authentication
605 unsigned char Packet_Type
; //802.1x Authentication
610 wEtherType
= (skb
->data
[cbIVOffset
+ 8 + 24 + 6] << 8) |
611 skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1];
612 Protocol_Version
= skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1 + 1];
613 Packet_Type
= skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1 + 1 + 1];
614 if (wEtherType
== ETH_P_PAE
) { //Protocol Type in LLC-Header
615 if (((Protocol_Version
== 1) || (Protocol_Version
== 2)) &&
616 (Packet_Type
== 3)) { //802.1x OR eapol-key challenge frame receive
621 //mike add:station mode check eapol-key challenge<---
627 if (pDevice
->bEnablePSMode
) {
628 if (!IS_FC_MOREDATA((skb
->data
+4))) {
629 if (pDevice
->pMgmt
->bInTIMWake
== true)
630 pDevice
->pMgmt
->bInTIMWake
= false;
634 // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps
635 if (pDevice
->bDiversityEnable
&& (FrameSize
> 50) &&
636 (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) &&
637 pDevice
->bLinkPass
) {
638 BBvAntennaDiversity(pDevice
, s_byGetRateIdx(*pbyRxRate
), 0);
641 if (pDevice
->byLocalID
!= REV_ID_VT3253_B1
)
642 pDevice
->uCurrRSSI
= *pbyRSSI
;
644 pDevice
->byCurrSQ
= *pbySQ
;
646 if ((*pbyRSSI
!= 0) &&
647 (pMgmt
->pCurrBSS
!= NULL
)) {
648 RFvRSSITodBm(pDevice
, *pbyRSSI
, &ldBm
);
649 // Monitor if RSSI is too strong.
650 pMgmt
->pCurrBSS
->byRSSIStatCnt
++;
651 pMgmt
->pCurrBSS
->byRSSIStatCnt
%= RSSI_STAT_COUNT
;
652 pMgmt
->pCurrBSS
->ldBmAverage
[pMgmt
->pCurrBSS
->byRSSIStatCnt
] = ldBm
;
653 for (ii
= 0; ii
< RSSI_STAT_COUNT
; ii
++)
654 if (pMgmt
->pCurrBSS
->ldBmAverage
[ii
] != 0)
655 pMgmt
->pCurrBSS
->ldBmMAX
= max(pMgmt
->pCurrBSS
->ldBmAverage
[ii
], ldBm
);
659 // -----------------------------------------------
661 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) && pDevice
->bEnable8021x
) {
662 unsigned char abyMacHdr
[24];
664 // Only 802.1x packet incoming allowed
669 wEtherType
= (skb
->data
[cbIVOffset
+ 4 + 24 + 6] << 8) |
670 skb
->data
[cbIVOffset
+ 4 + 24 + 6 + 1];
672 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wEtherType = %04x \n", wEtherType
);
673 if (wEtherType
== ETH_P_PAE
) {
674 skb
->dev
= pDevice
->apdev
;
677 // strip IV header(8)
678 memcpy(&abyMacHdr
[0], (skb
->data
+ 4), 24);
679 memcpy((skb
->data
+ 4 + cbIVOffset
), &abyMacHdr
[0], 24);
681 skb
->data
+= (cbIVOffset
+ 4);
682 skb
->tail
+= (cbIVOffset
+ 4);
683 skb_put(skb
, FrameSize
);
684 skb_reset_mac_header(skb
);
686 skb
->pkt_type
= PACKET_OTHERHOST
;
687 skb
->protocol
= htons(ETH_P_802_2
);
688 memset(skb
->cb
, 0, sizeof(skb
->cb
));
693 // check if 802.1x authorized
694 if (!(pMgmt
->sNodeDBTable
[iSANodeIndex
].dwFlags
& WLAN_STA_AUTHORIZED
))
698 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
700 FrameSize
-= 8; //MIC
703 //--------------------------------------------------------------------------------
705 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
709 __le32 dwMIC_Priority
;
710 __le32 dwMICKey0
= 0, dwMICKey1
= 0;
711 u32 dwLocalMIC_L
= 0;
712 u32 dwLocalMIC_R
= 0;
713 viawget_wpa_header
*wpahdr
;
715 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
716 dwMICKey0
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[24]));
717 dwMICKey1
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[28]));
719 if (pDevice
->pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) {
720 dwMICKey0
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[16]));
721 dwMICKey1
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[20]));
722 } else if ((pKey
->dwKeyIndex
& BIT28
) == 0) {
723 dwMICKey0
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[16]));
724 dwMICKey1
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[20]));
726 dwMICKey0
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[24]));
727 dwMICKey1
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[28]));
731 MIC_vInit(dwMICKey0
, dwMICKey1
);
732 MIC_vAppend((unsigned char *)&(pDevice
->sRxEthHeader
.abyDstAddr
[0]), 12);
734 MIC_vAppend((unsigned char *)&dwMIC_Priority
, 4);
735 // 4 is Rcv buffer header, 24 is MAC Header, and 8 is IV and Ext IV.
736 MIC_vAppend((unsigned char *)(skb
->data
+ 4 + WLAN_HDR_ADDR3_LEN
+ 8),
737 FrameSize
- WLAN_HDR_ADDR3_LEN
- 8);
738 MIC_vGetMIC(&dwLocalMIC_L
, &dwLocalMIC_R
);
741 pdwMIC_L
= (__le32
*)(skb
->data
+ 4 + FrameSize
);
742 pdwMIC_R
= (__le32
*)(skb
->data
+ 4 + FrameSize
+ 4);
744 if ((le32_to_cpu(*pdwMIC_L
) != dwLocalMIC_L
) ||
745 (le32_to_cpu(*pdwMIC_R
) != dwLocalMIC_R
) ||
746 pDevice
->bRxMICFail
) {
747 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC comparison is fail!\n");
748 pDevice
->bRxMICFail
= false;
749 pDevice
->s802_11Counter
.TKIPLocalMICFailures
++;
751 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
752 DBG_PRT(MSG_LEVEL_ERR
, KERN_ERR
"%s: can not alloc more frag bufs\n",
756 //2008-0409-07, <Add> by Einsn Liu
757 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
758 //send event to wpa_supplicant
760 union iwreq_data wrqu
;
761 struct iw_michaelmicfailure ev
;
762 int keyidx
= pbyFrame
[cbHeaderSize
+3] >> 6; //top two-bits
763 memset(&ev
, 0, sizeof(ev
));
764 ev
.flags
= keyidx
& IW_MICFAILURE_KEY_ID
;
765 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
766 (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
) &&
767 (*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
)) == 0) {
768 ev
.flags
|= IW_MICFAILURE_PAIRWISE
;
770 ev
.flags
|= IW_MICFAILURE_GROUP
;
773 ev
.src_addr
.sa_family
= ARPHRD_ETHER
;
774 memcpy(ev
.src_addr
.sa_data
, pMACHeader
->abyAddr2
, ETH_ALEN
);
775 memset(&wrqu
, 0, sizeof(wrqu
));
776 wrqu
.data
.length
= sizeof(ev
);
777 wireless_send_event(pDevice
->dev
, IWEVMICHAELMICFAILURE
, &wrqu
, (char *)&ev
);
782 if ((pDevice
->bWPADEVUp
) && (pDevice
->skb
!= NULL
)) {
783 wpahdr
= (viawget_wpa_header
*)pDevice
->skb
->data
;
784 if ((pDevice
->pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
785 (pDevice
->pMgmt
->eCurrState
== WMAC_STATE_ASSOC
) &&
786 (*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
)) == 0) {
787 wpahdr
->type
= VIAWGET_PTK_MIC_MSG
;
789 wpahdr
->type
= VIAWGET_GTK_MIC_MSG
;
791 wpahdr
->resp_ie_len
= 0;
792 wpahdr
->req_ie_len
= 0;
793 skb_put(pDevice
->skb
, sizeof(viawget_wpa_header
));
794 pDevice
->skb
->dev
= pDevice
->wpadev
;
795 skb_reset_mac_header(pDevice
->skb
);
796 pDevice
->skb
->pkt_type
= PACKET_HOST
;
797 pDevice
->skb
->protocol
= htons(ETH_P_802_2
);
798 memset(pDevice
->skb
->cb
, 0, sizeof(pDevice
->skb
->cb
));
799 netif_rx(pDevice
->skb
);
800 pDevice
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
807 } //---end of SOFT MIC-----------------------------------------------------------------------
809 // ++++++++++ Reply Counter Check +++++++++++++
811 if ((pKey
!= NULL
) && ((pKey
->byCipherSuite
== KEY_CTL_TKIP
) ||
812 (pKey
->byCipherSuite
== KEY_CTL_CCMP
))) {
814 unsigned short wLocalTSC15_0
= 0;
815 unsigned long dwLocalTSC47_16
= 0;
816 unsigned long long RSC
= 0;
818 RSC
= *((unsigned long long *)&(pKey
->KeyRSC
));
819 wLocalTSC15_0
= (unsigned short)RSC
;
820 dwLocalTSC47_16
= (unsigned long)(RSC
>>16);
825 memcpy(&(pKey
->KeyRSC
), &RSC
, sizeof(QWORD
));
827 if ((pDevice
->sMgmtObj
.eCurrMode
== WMAC_MODE_ESS_STA
) &&
828 (pDevice
->sMgmtObj
.eCurrState
== WMAC_STATE_ASSOC
)) {
830 if ((wRxTSC15_0
< wLocalTSC15_0
) &&
831 (dwRxTSC47_16
<= dwLocalTSC47_16
) &&
832 !((dwRxTSC47_16
== 0) && (dwLocalTSC47_16
== 0xFFFFFFFF))) {
833 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"TSC is illegal~~!\n ");
834 if (pKey
->byCipherSuite
== KEY_CTL_TKIP
)
835 pDevice
->s802_11Counter
.TKIPReplays
++;
837 pDevice
->s802_11Counter
.CCMPReplays
++;
840 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
841 DBG_PRT(MSG_LEVEL_ERR
, KERN_ERR
"%s: can not alloc more frag bufs\n",
849 } // ----- End of Reply Counter Check --------------------------
851 s_vProcessRxMACHeader(pDevice
, (unsigned char *)(skb
->data
+4), FrameSize
, bIsWEP
, bExtIV
, &cbHeaderOffset
);
852 FrameSize
-= cbHeaderOffset
;
853 cbHeaderOffset
+= 4; // 4 is Rcv buffer header
855 // Null data, framesize = 14
859 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
860 if (!s_bAPModeRxData(pDevice
,
868 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
869 DBG_PRT(MSG_LEVEL_ERR
, KERN_ERR
"%s: can not alloc more frag bufs\n",
877 skb
->data
+= cbHeaderOffset
;
878 skb
->tail
+= cbHeaderOffset
;
879 skb_put(skb
, FrameSize
);
880 skb
->protocol
= eth_type_trans(skb
, skb
->dev
);
882 //drop frame not met IEEE 802.3
884 skb
->ip_summed
= CHECKSUM_NONE
;
885 pStats
->rx_bytes
+= skb
->len
;
886 pStats
->rx_packets
++;
890 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
891 DBG_PRT(MSG_LEVEL_ERR
, KERN_ERR
"%s: can not alloc more frag bufs\n",
900 static bool s_bAPModeRxCtl(
902 unsigned char *pbyFrame
,
906 PS802_11Header p802_11Header
;
908 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
910 if (IS_CTL_PSPOLL(pbyFrame
) || !IS_TYPE_CONTROL(pbyFrame
)) {
911 p802_11Header
= (PS802_11Header
)(pbyFrame
);
912 if (!IS_TYPE_MGMT(pbyFrame
)) {
913 // Data & PS-Poll packet
915 if (iSANodeIndex
> 0) {
916 // frame class 3 fliter & checking
917 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].eNodeState
< NODE_AUTH
) {
918 // send deauth notification
919 // reason = (6) class 2 received from nonauth sta
920 vMgrDeAuthenBeginSta(pDevice
,
922 (unsigned char *)(p802_11Header
->abyAddr2
),
923 (WLAN_MGMT_REASON_CLASS2_NONAUTH
),
926 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: send vMgrDeAuthenBeginSta 1\n");
929 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].eNodeState
< NODE_ASSOC
) {
930 // send deassoc notification
931 // reason = (7) class 3 received from nonassoc sta
932 vMgrDisassocBeginSta(pDevice
,
934 (unsigned char *)(p802_11Header
->abyAddr2
),
935 (WLAN_MGMT_REASON_CLASS3_NONASSOC
),
938 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: send vMgrDisassocBeginSta 2\n");
942 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
) {
943 // delcare received ps-poll event
944 if (IS_CTL_PSPOLL(pbyFrame
)) {
945 pMgmt
->sNodeDBTable
[iSANodeIndex
].bRxPSPoll
= true;
946 bScheduleCommand((void *)pDevice
, WLAN_CMD_RX_PSPOLL
, NULL
);
947 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: WLAN_CMD_RX_PSPOLL 1\n");
949 // check Data PS state
950 // if PW bit off, send out all PS bufferring packets.
951 if (!IS_FC_POWERMGT(pbyFrame
)) {
952 pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
= false;
953 pMgmt
->sNodeDBTable
[iSANodeIndex
].bRxPSPoll
= true;
954 bScheduleCommand((void *)pDevice
, WLAN_CMD_RX_PSPOLL
, NULL
);
955 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: WLAN_CMD_RX_PSPOLL 2\n");
959 if (IS_FC_POWERMGT(pbyFrame
)) {
960 pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
= true;
961 // Once if STA in PS state, enable multicast bufferring
962 pMgmt
->sNodeDBTable
[0].bPSEnable
= true;
964 // clear all pending PS frame.
965 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].wEnQueueCnt
> 0) {
966 pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
= false;
967 pMgmt
->sNodeDBTable
[iSANodeIndex
].bRxPSPoll
= true;
968 bScheduleCommand((void *)pDevice
, WLAN_CMD_RX_PSPOLL
, NULL
);
969 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: WLAN_CMD_RX_PSPOLL 3\n");
975 vMgrDeAuthenBeginSta(pDevice
,
977 (unsigned char *)(p802_11Header
->abyAddr2
),
978 (WLAN_MGMT_REASON_CLASS2_NONAUTH
),
981 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: send vMgrDeAuthenBeginSta 3\n");
982 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"BSSID:%pM\n",
983 p802_11Header
->abyAddr3
);
984 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ADDR2:%pM\n",
985 p802_11Header
->abyAddr2
);
986 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ADDR1:%pM\n",
987 p802_11Header
->abyAddr1
);
988 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: wFrameCtl= %x\n", p802_11Header
->wFrameCtl
);
989 VNSvInPortB(pDevice
->PortOffset
+ MAC_REG_RCR
, &(pDevice
->byRxMode
));
990 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc:pDevice->byRxMode = %x\n", pDevice
->byRxMode
);
998 static bool s_bHandleRxEncryption(
1000 unsigned char *pbyFrame
,
1001 unsigned int FrameSize
,
1002 unsigned char *pbyRsr
,
1003 unsigned char *pbyNewRsr
,
1006 unsigned short *pwRxTSC15_0
,
1007 unsigned long *pdwRxTSC47_16
1010 unsigned int PayloadLen
= FrameSize
;
1011 unsigned char *pbyIV
;
1012 unsigned char byKeyIdx
;
1013 PSKeyItem pKey
= NULL
;
1014 unsigned char byDecMode
= KEY_CTL_WEP
;
1015 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
1020 pbyIV
= pbyFrame
+ WLAN_HDR_ADDR3_LEN
;
1021 if (WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame
) &&
1022 WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame
)) {
1023 pbyIV
+= 6; // 6 is 802.11 address4
1026 byKeyIdx
= (*(pbyIV
+3) & 0xc0);
1028 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\nKeyIdx: %d\n", byKeyIdx
);
1030 if ((pMgmt
->eAuthenMode
== WMAC_AUTH_WPA
) ||
1031 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPAPSK
) ||
1032 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) ||
1033 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2
) ||
1034 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2PSK
)) {
1035 if (((*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
)) == 0) &&
1036 (pDevice
->pMgmt
->byCSSPK
!= KEY_CTL_NONE
)) {
1037 // unicast pkt use pairwise key
1038 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"unicast pkt\n");
1039 if (KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBSSID
, 0xFFFFFFFF, &pKey
) == true) {
1040 if (pDevice
->pMgmt
->byCSSPK
== KEY_CTL_TKIP
)
1041 byDecMode
= KEY_CTL_TKIP
;
1042 else if (pDevice
->pMgmt
->byCSSPK
== KEY_CTL_CCMP
)
1043 byDecMode
= KEY_CTL_CCMP
;
1045 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"unicast pkt: %d, %p\n", byDecMode
, pKey
);
1048 KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBSSID
, byKeyIdx
, &pKey
);
1049 if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_TKIP
)
1050 byDecMode
= KEY_CTL_TKIP
;
1051 else if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_CCMP
)
1052 byDecMode
= KEY_CTL_CCMP
;
1053 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"group pkt: %d, %d, %p\n", byKeyIdx
, byDecMode
, pKey
);
1056 // our WEP only support Default Key
1058 // use default group key
1059 KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBroadcastAddr
, byKeyIdx
, &pKey
);
1060 if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_TKIP
)
1061 byDecMode
= KEY_CTL_TKIP
;
1062 else if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_CCMP
)
1063 byDecMode
= KEY_CTL_CCMP
;
1067 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"AES:%d %d %d\n", pDevice
->pMgmt
->byCSSPK
, pDevice
->pMgmt
->byCSSGK
, byDecMode
);
1070 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey == NULL\n");
1074 if (byDecMode
!= pKey
->byCipherSuite
) {
1079 if (byDecMode
== KEY_CTL_WEP
) {
1081 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
) ||
1082 (((PSKeyTable
)(pKey
->pvKeyTable
))->bSoftWEP
== true)) {
1087 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1088 memcpy(pDevice
->abyPRNG
, pbyIV
, 3);
1089 memcpy(pDevice
->abyPRNG
+ 3, pKey
->abyKey
, pKey
->uKeyLength
);
1090 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, pKey
->uKeyLength
+ 3);
1091 rc4_encrypt(&pDevice
->SBox
, pbyIV
+4, pbyIV
+4, PayloadLen
);
1093 if (ETHbIsBufferCrc32Ok(pbyIV
+4, PayloadLen
))
1094 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1097 } else if ((byDecMode
== KEY_CTL_TKIP
) ||
1098 (byDecMode
== KEY_CTL_CCMP
)) {
1101 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1102 *pdwRxTSC47_16
= cpu_to_le32(*(unsigned long *)(pbyIV
+ 4));
1103 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ExtIV: %lx\n", *pdwRxTSC47_16
);
1104 if (byDecMode
== KEY_CTL_TKIP
)
1105 *pwRxTSC15_0
= cpu_to_le16(MAKEWORD(*(pbyIV
+ 2), *pbyIV
));
1107 *pwRxTSC15_0
= cpu_to_le16(*(unsigned short *)pbyIV
);
1109 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"TSC0_15: %x\n", *pwRxTSC15_0
);
1111 if ((byDecMode
== KEY_CTL_TKIP
) &&
1112 (pDevice
->byLocalID
<= REV_ID_VT3253_A1
)) {
1115 PS802_11Header pMACHeader
= (PS802_11Header
)(pbyFrame
);
1116 TKIPvMixKey(pKey
->abyKey
, pMACHeader
->abyAddr2
, *pwRxTSC15_0
, *pdwRxTSC47_16
, pDevice
->abyPRNG
);
1117 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, TKIP_KEY_LEN
);
1118 rc4_encrypt(&pDevice
->SBox
, pbyIV
+8, pbyIV
+8, PayloadLen
);
1119 if (ETHbIsBufferCrc32Ok(pbyIV
+8, PayloadLen
)) {
1120 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1121 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV OK!\n");
1123 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV FAIL!!!\n");
1124 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PayloadLen = %d\n", PayloadLen
);
1129 if ((*(pbyIV
+3) & 0x20) != 0)
1134 static bool s_bHostWepRxEncryption(
1136 unsigned char *pbyFrame
,
1137 unsigned int FrameSize
,
1138 unsigned char *pbyRsr
,
1141 unsigned char *pbyNewRsr
,
1143 unsigned short *pwRxTSC15_0
,
1144 unsigned long *pdwRxTSC47_16
1147 unsigned int PayloadLen
= FrameSize
;
1148 unsigned char *pbyIV
;
1149 unsigned char byKeyIdx
;
1150 unsigned char byDecMode
= KEY_CTL_WEP
;
1151 PS802_11Header pMACHeader
;
1156 pbyIV
= pbyFrame
+ WLAN_HDR_ADDR3_LEN
;
1157 if (WLAN_GET_FC_TODS(*(unsigned short *)pbyFrame
) &&
1158 WLAN_GET_FC_FROMDS(*(unsigned short *)pbyFrame
)) {
1159 pbyIV
+= 6; // 6 is 802.11 address4
1162 byKeyIdx
= (*(pbyIV
+3) & 0xc0);
1164 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\nKeyIdx: %d\n", byKeyIdx
);
1166 if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_TKIP
)
1167 byDecMode
= KEY_CTL_TKIP
;
1168 else if (pDevice
->pMgmt
->byCSSGK
== KEY_CTL_CCMP
)
1169 byDecMode
= KEY_CTL_CCMP
;
1171 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"AES:%d %d %d\n", pDevice
->pMgmt
->byCSSPK
, pDevice
->pMgmt
->byCSSGK
, byDecMode
);
1173 if (byDecMode
!= pKey
->byCipherSuite
)
1176 if (byDecMode
== KEY_CTL_WEP
) {
1178 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"byDecMode == KEY_CTL_WEP \n");
1179 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
) ||
1180 (((PSKeyTable
)(pKey
->pvKeyTable
))->bSoftWEP
== true) ||
1187 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1188 memcpy(pDevice
->abyPRNG
, pbyIV
, 3);
1189 memcpy(pDevice
->abyPRNG
+ 3, pKey
->abyKey
, pKey
->uKeyLength
);
1190 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, pKey
->uKeyLength
+ 3);
1191 rc4_encrypt(&pDevice
->SBox
, pbyIV
+4, pbyIV
+4, PayloadLen
);
1193 if (ETHbIsBufferCrc32Ok(pbyIV
+4, PayloadLen
))
1194 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1197 } else if ((byDecMode
== KEY_CTL_TKIP
) ||
1198 (byDecMode
== KEY_CTL_CCMP
)) {
1201 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1202 *pdwRxTSC47_16
= cpu_to_le32(*(unsigned long *)(pbyIV
+ 4));
1203 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ExtIV: %lx\n", *pdwRxTSC47_16
);
1205 if (byDecMode
== KEY_CTL_TKIP
)
1206 *pwRxTSC15_0
= cpu_to_le16(MAKEWORD(*(pbyIV
+2), *pbyIV
));
1208 *pwRxTSC15_0
= cpu_to_le16(*(unsigned short *)pbyIV
);
1210 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"TSC0_15: %x\n", *pwRxTSC15_0
);
1212 if (byDecMode
== KEY_CTL_TKIP
) {
1213 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
) || !bOnFly
) {
1217 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"soft KEY_CTL_TKIP \n");
1218 pMACHeader
= (PS802_11Header
)(pbyFrame
);
1219 TKIPvMixKey(pKey
->abyKey
, pMACHeader
->abyAddr2
, *pwRxTSC15_0
, *pdwRxTSC47_16
, pDevice
->abyPRNG
);
1220 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, TKIP_KEY_LEN
);
1221 rc4_encrypt(&pDevice
->SBox
, pbyIV
+8, pbyIV
+8, PayloadLen
);
1222 if (ETHbIsBufferCrc32Ok(pbyIV
+8, PayloadLen
)) {
1223 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1224 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV OK!\n");
1226 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV FAIL!!!\n");
1227 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PayloadLen = %d\n", PayloadLen
);
1232 if (byDecMode
== KEY_CTL_CCMP
) {
1236 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"soft KEY_CTL_CCMP\n");
1237 if (AESbGenCCMP(pKey
->abyKey
, pbyFrame
, FrameSize
)) {
1238 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1239 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CCMP MIC compare OK!\n");
1241 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CCMP MIC fail!\n");
1248 if ((*(pbyIV
+3) & 0x20) != 0)
1253 static bool s_bAPModeRxData(
1255 struct sk_buff
*skb
,
1256 unsigned int FrameSize
,
1257 unsigned int cbHeaderOffset
,
1262 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
1263 bool bRelayAndForward
= false;
1264 bool bRelayOnly
= false;
1265 unsigned char byMask
[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1266 unsigned short wAID
;
1268 struct sk_buff
*skbcpy
= NULL
;
1270 if (FrameSize
> CB_MAX_BUF_SIZE
)
1273 if (is_multicast_ether_addr((unsigned char *)(skb
->data
+cbHeaderOffset
))) {
1274 if (pMgmt
->sNodeDBTable
[0].bPSEnable
) {
1275 skbcpy
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
1277 // if any node in PS mode, buffer packet until DTIM.
1278 if (skbcpy
== NULL
) {
1279 DBG_PRT(MSG_LEVEL_NOTICE
, KERN_INFO
"relay multicast no skb available \n");
1281 skbcpy
->dev
= pDevice
->dev
;
1282 skbcpy
->len
= FrameSize
;
1283 memcpy(skbcpy
->data
, skb
->data
+cbHeaderOffset
, FrameSize
);
1284 skb_queue_tail(&(pMgmt
->sNodeDBTable
[0].sTxPSQueue
), skbcpy
);
1286 pMgmt
->sNodeDBTable
[0].wEnQueueCnt
++;
1288 pMgmt
->abyPSTxMap
[0] |= byMask
[0];
1291 bRelayAndForward
= true;
1295 if (BSSDBbIsSTAInNodeDB(pMgmt
, (unsigned char *)(skb
->data
+cbHeaderOffset
), &iDANodeIndex
)) {
1296 if (pMgmt
->sNodeDBTable
[iDANodeIndex
].eNodeState
>= NODE_ASSOC
) {
1297 if (pMgmt
->sNodeDBTable
[iDANodeIndex
].bPSEnable
) {
1298 // queue this skb until next PS tx, and then release.
1300 skb
->data
+= cbHeaderOffset
;
1301 skb
->tail
+= cbHeaderOffset
;
1302 skb_put(skb
, FrameSize
);
1303 skb_queue_tail(&pMgmt
->sNodeDBTable
[iDANodeIndex
].sTxPSQueue
, skb
);
1304 pMgmt
->sNodeDBTable
[iDANodeIndex
].wEnQueueCnt
++;
1305 wAID
= pMgmt
->sNodeDBTable
[iDANodeIndex
].wAID
;
1306 pMgmt
->abyPSTxMap
[wAID
>> 3] |= byMask
[wAID
& 7];
1307 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n",
1308 iDANodeIndex
, (wAID
>> 3), pMgmt
->abyPSTxMap
[wAID
>> 3]);
1317 if (bRelayOnly
|| bRelayAndForward
) {
1318 // relay this packet right now
1319 if (bRelayAndForward
)
1322 if ((pDevice
->uAssocCount
> 1) && (iDANodeIndex
>= 0))
1323 ROUTEbRelay(pDevice
, (unsigned char *)(skb
->data
+ cbHeaderOffset
), FrameSize
, (unsigned int)iDANodeIndex
);
1328 // none associate, don't forward
1329 if (pDevice
->uAssocCount
== 0)