2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: handle dpc rx functions
28 * device_receive_frame - Rcv 802.11 frame function
29 * s_bAPModeRxCtl- AP Rcv frame filer Ctl.
30 * s_bAPModeRxData- AP Rcv data frame handle
31 * s_bHandleRxEncryption- Rcv decrypted data via on-fly
32 * s_bHostWepRxEncryption- Rcv encrypted data via host
33 * s_byGetRateIdx- get rate index
34 * s_vGetDASA- get data offset
35 * s_vProcessRxMACHeader- Rcv 802.11 and translate to 802.3
59 //static int msglevel =MSG_LEVEL_DEBUG;
60 static int msglevel
=MSG_LEVEL_INFO
;
62 const u8 acbyRxRate
[MAX_RATE
] =
63 {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
65 static u8
s_byGetRateIdx(u8 byRate
);
71 unsigned int *pcbHeaderSize
,
72 struct ethhdr
*psEthHeader
75 static void s_vProcessRxMACHeader(struct vnt_private
*pDevice
,
76 u8
*pbyRxBufferAddr
, u32 cbPacketSize
, int bIsWEP
, int bExtIV
,
79 static int s_bAPModeRxCtl(struct vnt_private
*pDevice
, u8
*pbyFrame
,
82 static int s_bAPModeRxData(struct vnt_private
*pDevice
, struct sk_buff
*skb
,
83 u32 FrameSize
, u32 cbHeaderOffset
, s32 iSANodeIndex
, s32 iDANodeIndex
);
85 static int s_bHandleRxEncryption(struct vnt_private
*pDevice
, u8
*pbyFrame
,
86 u32 FrameSize
, u8
*pbyRsr
, u8
*pbyNewRsr
, PSKeyItem
*pKeyOut
,
87 s32
*pbExtIV
, u16
*pwRxTSC15_0
, u32
*pdwRxTSC47_16
);
89 static int s_bHostWepRxEncryption(struct vnt_private
*pDevice
, u8
*pbyFrame
,
90 u32 FrameSize
, u8
*pbyRsr
, int bOnFly
, PSKeyItem pKey
, u8
*pbyNewRsr
,
91 s32
*pbExtIV
, u16
*pwRxTSC15_0
, u32
*pdwRxTSC47_16
);
96 * Translate Rcv 802.11 header to 802.3 header with Rx buffer
101 * dwRxBufferAddr - Address of Rcv Buffer
102 * cbPacketSize - Rcv Packet size
103 * bIsWEP - If Rcv with WEP
105 * pcbHeaderSize - 802.11 header size
111 static void s_vProcessRxMACHeader(struct vnt_private
*pDevice
,
112 u8
*pbyRxBufferAddr
, u32 cbPacketSize
, int bIsWEP
, int bExtIV
,
116 u32 cbHeaderSize
= 0;
118 struct ieee80211_hdr
*pMACHeader
;
121 pMACHeader
= (struct ieee80211_hdr
*) (pbyRxBufferAddr
+ cbHeaderSize
);
123 s_vGetDASA((u8
*)pMACHeader
, &cbHeaderSize
, &pDevice
->sRxEthHeader
);
127 // strip IV&ExtIV , add 8 byte
128 cbHeaderSize
+= (WLAN_HDR_ADDR3_LEN
+ 8);
130 // strip IV , add 4 byte
131 cbHeaderSize
+= (WLAN_HDR_ADDR3_LEN
+ 4);
135 cbHeaderSize
+= WLAN_HDR_ADDR3_LEN
;
138 pbyRxBuffer
= (u8
*) (pbyRxBufferAddr
+ cbHeaderSize
);
139 if (!compare_ether_addr(pbyRxBuffer
, &pDevice
->abySNAP_Bridgetunnel
[0])) {
141 } else if (!compare_ether_addr(pbyRxBuffer
, &pDevice
->abySNAP_RFC1042
[0])) {
143 pwType
= (u16
*) (pbyRxBufferAddr
+ cbHeaderSize
);
144 if ((*pwType
== cpu_to_be16(ETH_P_IPX
)) ||
145 (*pwType
== cpu_to_le16(0xF380))) {
147 pwType
= (u16
*) (pbyRxBufferAddr
+ cbHeaderSize
);
150 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 8); // 8 is IV&ExtIV
152 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 4); // 4 is IV
156 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
);
162 pwType
= (u16
*) (pbyRxBufferAddr
+ cbHeaderSize
);
165 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 8); // 8 is IV&ExtIV
167 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 4); // 4 is IV
171 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
);
175 cbHeaderSize
-= (ETH_ALEN
* 2);
176 pbyRxBuffer
= (u8
*) (pbyRxBufferAddr
+ cbHeaderSize
);
177 for (ii
= 0; ii
< ETH_ALEN
; ii
++)
178 *pbyRxBuffer
++ = pDevice
->sRxEthHeader
.h_dest
[ii
];
179 for (ii
= 0; ii
< ETH_ALEN
; ii
++)
180 *pbyRxBuffer
++ = pDevice
->sRxEthHeader
.h_source
[ii
];
182 *pcbHeadSize
= cbHeaderSize
;
185 static u8
s_byGetRateIdx(u8 byRate
)
189 for (byRateIdx
= 0; byRateIdx
<MAX_RATE
; byRateIdx
++) {
190 if (acbyRxRate
[byRateIdx
%MAX_RATE
] == byRate
)
199 u8
* pbyRxBufferAddr
,
200 unsigned int *pcbHeaderSize
,
201 struct ethhdr
*psEthHeader
204 unsigned int cbHeaderSize
= 0;
205 struct ieee80211_hdr
*pMACHeader
;
208 pMACHeader
= (struct ieee80211_hdr
*) (pbyRxBufferAddr
+ cbHeaderSize
);
210 if ((pMACHeader
->frame_control
& FC_TODS
) == 0) {
211 if (pMACHeader
->frame_control
& FC_FROMDS
) {
212 for (ii
= 0; ii
< ETH_ALEN
; ii
++) {
213 psEthHeader
->h_dest
[ii
] =
214 pMACHeader
->addr1
[ii
];
215 psEthHeader
->h_source
[ii
] =
216 pMACHeader
->addr3
[ii
];
220 for (ii
= 0; ii
< ETH_ALEN
; ii
++) {
221 psEthHeader
->h_dest
[ii
] =
222 pMACHeader
->addr1
[ii
];
223 psEthHeader
->h_source
[ii
] =
224 pMACHeader
->addr2
[ii
];
229 if (pMACHeader
->frame_control
& FC_FROMDS
) {
230 for (ii
= 0; ii
< ETH_ALEN
; ii
++) {
231 psEthHeader
->h_dest
[ii
] =
232 pMACHeader
->addr3
[ii
];
233 psEthHeader
->h_source
[ii
] =
234 pMACHeader
->addr4
[ii
];
238 for (ii
= 0; ii
< ETH_ALEN
; ii
++) {
239 psEthHeader
->h_dest
[ii
] =
240 pMACHeader
->addr3
[ii
];
241 psEthHeader
->h_source
[ii
] =
242 pMACHeader
->addr2
[ii
];
246 *pcbHeaderSize
= cbHeaderSize
;
249 int RXbBulkInProcessData(struct vnt_private
*pDevice
, struct vnt_rcb
*pRCB
,
250 unsigned long BytesToIndicate
)
252 struct net_device_stats
*pStats
= &pDevice
->stats
;
254 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
255 struct vnt_rx_mgmt
*pRxPacket
= &pMgmt
->sRxPacket
;
256 struct ieee80211_hdr
*p802_11Header
;
257 u8
*pbyRsr
, *pbyNewRsr
, *pbyRSSI
, *pbyFrame
;
259 u32 bDeFragRx
= false;
260 u32 cbHeaderOffset
, cbIVOffset
;
263 s32 iSANodeIndex
= -1, iDANodeIndex
= -1;
265 u8
*pbyRxSts
, *pbyRxRate
, *pbySQ
, *pby3SQ
;
267 PSKeyItem pKey
= NULL
;
269 u32 dwRxTSC47_16
= 0;
271 /* signed long ldBm = 0; */
272 int bIsWEP
= false; int bExtIV
= false;
274 struct vnt_rcb
*pRCBIndicate
= pRCB
;
277 u8 abyVaildRate
[MAX_RATE
]
278 = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
279 u16 wPLCPwithPadding
;
280 struct ieee80211_hdr
*pMACHeader
;
281 int bRxeapol_key
= false;
283 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---------- RXbBulkInProcessData---\n");
287 /* [31:16]RcvByteCount ( not include 4-byte Status ) */
288 dwWbkStatus
= *((u32
*)(skb
->data
));
289 FrameSize
= dwWbkStatus
>> 16;
292 if (BytesToIndicate
!= FrameSize
) {
293 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"------- WRONG Length 1\n");
297 if ((BytesToIndicate
> 2372) || (BytesToIndicate
<= 40)) {
298 // Frame Size error drop this packet.
299 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---------- WRONG Length 2\n");
303 pbyDAddress
= (u8
*)(skb
->data
);
304 pbyRxSts
= pbyDAddress
+4;
305 pbyRxRate
= pbyDAddress
+5;
307 //real Frame Size = USBFrameSize -4WbkStatus - 4RxStatus - 8TSF - 4RSR - 4SQ3 - ?Padding
308 //if SQ3 the range is 24~27, if no SQ3 the range is 20~23
309 //real Frame size in PLCPLength field.
310 pwPLCP_Length
= (u16
*) (pbyDAddress
+ 6);
311 //Fix hardware bug => PLCP_Length error
312 if ( ((BytesToIndicate
- (*pwPLCP_Length
)) > 27) ||
313 ((BytesToIndicate
- (*pwPLCP_Length
)) < 24) ||
314 (BytesToIndicate
< (*pwPLCP_Length
)) ) {
316 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Wrong PLCP Length %x\n", (int) *pwPLCP_Length
);
319 for ( ii
=RATE_1M
;ii
<MAX_RATE
;ii
++) {
320 if ( *pbyRxRate
== abyVaildRate
[ii
] ) {
324 if ( ii
==MAX_RATE
) {
325 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Wrong RxRate %x\n",(int) *pbyRxRate
);
329 wPLCPwithPadding
= ( (*pwPLCP_Length
/ 4) + ( (*pwPLCP_Length
% 4) ? 1:0 ) ) *4;
331 pqwTSFTime
= (u64
*)(pbyDAddress
+ 8 + wPLCPwithPadding
);
332 if(pDevice
->byBBType
== BB_TYPE_11G
) {
333 pby3SQ
= pbyDAddress
+ 8 + wPLCPwithPadding
+ 12;
337 pbySQ
= pbyDAddress
+ 8 + wPLCPwithPadding
+ 8;
340 pbyNewRsr
= pbyDAddress
+ 8 + wPLCPwithPadding
+ 9;
341 pbyRSSI
= pbyDAddress
+ 8 + wPLCPwithPadding
+ 10;
342 pbyRsr
= pbyDAddress
+ 8 + wPLCPwithPadding
+ 11;
344 FrameSize
= *pwPLCP_Length
;
346 pbyFrame
= pbyDAddress
+ 8;
347 // update receive statistic counter
349 STAvUpdateRDStatCounter(&pDevice
->scStatistic
,
358 pMACHeader
= (struct ieee80211_hdr
*) pbyFrame
;
360 //mike add: to judge if current AP is activated?
361 if ((pMgmt
->eCurrMode
== WMAC_MODE_STANDBY
) ||
362 (pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
)) {
363 if (pMgmt
->sNodeDBTable
[0].bActive
) {
364 if (!compare_ether_addr(pMgmt
->abyCurrBSSID
, pMACHeader
->addr2
)) {
365 if (pMgmt
->sNodeDBTable
[0].uInActiveCount
!= 0)
366 pMgmt
->sNodeDBTable
[0].uInActiveCount
= 0;
371 if (!is_multicast_ether_addr(pMACHeader
->addr1
)) {
372 if (WCTLbIsDuplicate(&(pDevice
->sDupRxCache
), (struct ieee80211_hdr
*) pbyFrame
)) {
373 pDevice
->s802_11Counter
.FrameDuplicateCount
++;
377 if (compare_ether_addr(pDevice
->abyCurrentNetAddr
,
378 pMACHeader
->addr1
)) {
384 s_vGetDASA(pbyFrame
, &cbHeaderSize
, &pDevice
->sRxEthHeader
);
386 if (!compare_ether_addr((u8
*)&(pDevice
->sRxEthHeader
.h_source
[0]),
387 pDevice
->abyCurrentNetAddr
))
390 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) || (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
)) {
391 if (IS_CTL_PSPOLL(pbyFrame
) || !IS_TYPE_CONTROL(pbyFrame
)) {
392 p802_11Header
= (struct ieee80211_hdr
*) (pbyFrame
);
394 if (BSSbIsSTAInNodeDB(pDevice
, (u8
*)(p802_11Header
->addr2
), &iSANodeIndex
)) {
395 pMgmt
->sNodeDBTable
[iSANodeIndex
].ulLastRxJiffer
= jiffies
;
396 pMgmt
->sNodeDBTable
[iSANodeIndex
].uInActiveCount
= 0;
401 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
402 if (s_bAPModeRxCtl(pDevice
, pbyFrame
, iSANodeIndex
) == true) {
407 if (IS_FC_WEP(pbyFrame
)) {
408 bool bRxDecryOK
= false;
410 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"rx WEP pkt\n");
412 if ((pDevice
->bEnableHostWEP
) && (iSANodeIndex
>= 0)) {
414 pKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[iSANodeIndex
].byCipherSuite
;
415 pKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[iSANodeIndex
].dwKeyIndex
;
416 pKey
->uKeyLength
= pMgmt
->sNodeDBTable
[iSANodeIndex
].uWepKeyLength
;
417 pKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[iSANodeIndex
].dwTSC47_16
;
418 pKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[iSANodeIndex
].wTSC15_0
;
420 &pMgmt
->sNodeDBTable
[iSANodeIndex
].abyWepKey
[0],
424 bRxDecryOK
= s_bHostWepRxEncryption(pDevice
,
428 pMgmt
->sNodeDBTable
[iSANodeIndex
].bOnFly
,
435 bRxDecryOK
= s_bHandleRxEncryption(pDevice
,
447 if ((*pbyNewRsr
& NEWRSR_DECRYPTOK
) == 0) {
448 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV Fail\n");
449 if ( (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA
) ||
450 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPAPSK
) ||
451 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) ||
452 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2
) ||
453 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2PSK
)) {
455 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
456 pDevice
->s802_11Counter
.TKIPICVErrors
++;
457 } else if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_CCMP
)) {
458 pDevice
->s802_11Counter
.CCMPDecryptErrors
++;
459 } else if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_WEP
)) {
460 // pDevice->s802_11Counter.WEPICVErrorCount.QuadPart++;
466 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"WEP Func Fail\n");
469 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_CCMP
))
470 FrameSize
-= 8; // Message Integrity Code
472 FrameSize
-= 4; // 4 is ICV
478 /* remove the FCS/CRC length */
479 FrameSize
-= ETH_FCS_LEN
;
481 if ( !(*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
)) && // unicast address
482 (IS_FRAGMENT_PKT((pbyFrame
)))
485 bDeFragRx
= WCTLbHandleFragment(pDevice
, (struct ieee80211_hdr
*) (pbyFrame
), FrameSize
, bIsWEP
, bExtIV
);
486 pDevice
->s802_11Counter
.ReceivedFragmentCount
++;
489 // TODO skb, pbyFrame
490 skb
= pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].skb
;
491 FrameSize
= pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].cbFrameLength
;
492 pbyFrame
= skb
->data
+ 8;
500 // Management & Control frame Handle
502 if ((IS_TYPE_DATA((pbyFrame
))) == false) {
503 // Handle Control & Manage Frame
505 if (IS_TYPE_MGMT((pbyFrame
))) {
509 pRxPacket
= &(pRCB
->sMngPacket
);
510 pRxPacket
->p80211Header
= (PUWLAN_80211HDR
)(pbyFrame
);
511 pRxPacket
->cbMPDULen
= FrameSize
;
512 pRxPacket
->uRSSI
= *pbyRSSI
;
513 pRxPacket
->bySQ
= *pbySQ
;
514 pRxPacket
->qwLocalTSF
= cpu_to_le64(*pqwTSFTime
);
517 pbyData1
= WLAN_HDR_A3_DATA_PTR(pbyFrame
);
518 pbyData2
= WLAN_HDR_A3_DATA_PTR(pbyFrame
) + 4;
519 for (ii
= 0; ii
< (FrameSize
- 4); ii
++) {
520 *pbyData1
= *pbyData2
;
526 pRxPacket
->byRxRate
= s_byGetRateIdx(*pbyRxRate
);
528 if ( *pbyRxSts
== 0 ) {
529 //Discard beacon packet which channel is 0
530 if ( (WLAN_GET_FC_FSTYPE((pRxPacket
->p80211Header
->sA3
.wFrameCtl
)) == WLAN_FSTYPE_BEACON
) ||
531 (WLAN_GET_FC_FSTYPE((pRxPacket
->p80211Header
->sA3
.wFrameCtl
)) == WLAN_FSTYPE_PROBERESP
) ) {
535 pRxPacket
->byRxChannel
= (*pbyRxSts
) >> 2;
537 // hostap Deamon handle 802.11 management
538 if (pDevice
->bEnableHostapd
) {
539 skb
->dev
= pDevice
->apdev
;
544 skb_put(skb
, FrameSize
);
545 skb_reset_mac_header(skb
);
546 skb
->pkt_type
= PACKET_OTHERHOST
;
547 skb
->protocol
= htons(ETH_P_802_2
);
548 memset(skb
->cb
, 0, sizeof(skb
->cb
));
554 // Insert the RCB in the Recv Mng list
556 EnqueueRCB(pDevice
->FirstRecvMngList
, pDevice
->LastRecvMngList
, pRCBIndicate
);
557 pDevice
->NumRecvMngList
++;
558 if ( bDeFragRx
== false) {
561 if (pDevice
->bIsRxMngWorkItemQueued
== false) {
562 pDevice
->bIsRxMngWorkItemQueued
= true;
563 tasklet_schedule(&pDevice
->RxMngWorkItem
);
573 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
574 //In AP mode, hw only check addr1(BSSID or RA) if equal to local MAC.
575 if ( !(*pbyRsr
& RSR_BSSIDOK
)) {
577 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
578 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
586 // discard DATA packet while not associate || BSSID error
587 if ((pDevice
->bLinkPass
== false) ||
588 !(*pbyRsr
& RSR_BSSIDOK
)) {
590 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
591 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
597 //mike add:station mode check eapol-key challenge--->
599 u8 Protocol_Version
; //802.1x Authentication
600 u8 Packet_Type
; //802.1x Authentication
607 wEtherType
= (skb
->data
[cbIVOffset
+ 8 + 24 + 6] << 8) |
608 skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1];
609 Protocol_Version
= skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1 +1];
610 Packet_Type
= skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1 +1+1];
611 if (wEtherType
== ETH_P_PAE
) { //Protocol Type in LLC-Header
612 if(((Protocol_Version
==1) ||(Protocol_Version
==2)) &&
613 (Packet_Type
==3)) { //802.1x OR eapol-key challenge frame receive
615 Descriptor_type
= skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1 +1+1+1+2];
616 Key_info
= (skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1 +1+1+1+2+1]<<8) |skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1 +1+1+1+2+2] ;
617 if(Descriptor_type
==2) { //RSN
618 // printk("WPA2_Rx_eapol-key_info<-----:%x\n",Key_info);
620 else if(Descriptor_type
==254) {
621 // printk("WPA_Rx_eapol-key_info<-----:%x\n",Key_info);
626 //mike add:station mode check eapol-key challenge<---
632 if (pDevice
->bEnablePSMode
) {
633 if (IS_FC_MOREDATA((pbyFrame
))) {
634 if (*pbyRsr
& RSR_ADDROK
) {
635 //PSbSendPSPOLL((PSDevice)pDevice);
639 if (pMgmt
->bInTIMWake
== true) {
640 pMgmt
->bInTIMWake
= false;
645 // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps
646 if (pDevice
->bDiversityEnable
&& (FrameSize
>50) &&
647 (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) &&
648 (pDevice
->bLinkPass
== true)) {
649 BBvAntennaDiversity(pDevice
, s_byGetRateIdx(*pbyRxRate
), 0);
652 // ++++++++ For BaseBand Algorithm +++++++++++++++
653 pDevice
->uCurrRSSI
= *pbyRSSI
;
654 pDevice
->byCurrSQ
= *pbySQ
;
658 if ((*pbyRSSI != 0) &&
659 (pMgmt->pCurrBSS!=NULL)) {
660 RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
661 // Monitor if RSSI is too strong.
662 pMgmt->pCurrBSS->byRSSIStatCnt++;
663 pMgmt->pCurrBSS->byRSSIStatCnt %= RSSI_STAT_COUNT;
664 pMgmt->pCurrBSS->ldBmAverage[pMgmt->pCurrBSS->byRSSIStatCnt] = ldBm;
665 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
666 if (pMgmt->pCurrBSS->ldBmAverage[ii] != 0) {
667 pMgmt->pCurrBSS->ldBmMAX =
668 max(pMgmt->pCurrBSS->ldBmAverage[ii], ldBm);
674 // -----------------------------------------------
676 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) && (pDevice
->bEnable8021x
== true)){
679 // Only 802.1x packet incoming allowed
684 wEtherType
= (skb
->data
[cbIVOffset
+ 8 + 24 + 6] << 8) |
685 skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1];
687 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wEtherType = %04x \n", wEtherType
);
688 if (wEtherType
== ETH_P_PAE
) {
689 skb
->dev
= pDevice
->apdev
;
691 if (bIsWEP
== true) {
692 // strip IV header(8)
693 memcpy(&abyMacHdr
[0], (skb
->data
+ 8), 24);
694 memcpy((skb
->data
+ 8 + cbIVOffset
), &abyMacHdr
[0], 24);
697 skb
->data
+= (cbIVOffset
+ 8);
698 skb
->tail
+= (cbIVOffset
+ 8);
699 skb_put(skb
, FrameSize
);
700 skb_reset_mac_header(skb
);
701 skb
->pkt_type
= PACKET_OTHERHOST
;
702 skb
->protocol
= htons(ETH_P_802_2
);
703 memset(skb
->cb
, 0, sizeof(skb
->cb
));
708 // check if 802.1x authorized
709 if (!(pMgmt
->sNodeDBTable
[iSANodeIndex
].dwFlags
& WLAN_STA_AUTHORIZED
))
713 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
715 FrameSize
-= 8; //MIC
719 //--------------------------------------------------------------------------------
721 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
726 u32 dwMICKey0
= 0, dwMICKey1
= 0;
727 u32 dwLocalMIC_L
= 0;
728 u32 dwLocalMIC_R
= 0;
730 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
731 dwMICKey0
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[24]));
732 dwMICKey1
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[28]));
735 if (pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) {
736 dwMICKey0
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[16]));
737 dwMICKey1
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[20]));
738 } else if ((pKey
->dwKeyIndex
& BIT28
) == 0) {
739 dwMICKey0
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[16]));
740 dwMICKey1
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[20]));
742 dwMICKey0
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[24]));
743 dwMICKey1
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[28]));
747 MIC_vInit(dwMICKey0
, dwMICKey1
);
748 MIC_vAppend((u8
*)&(pDevice
->sRxEthHeader
.h_dest
[0]), 12);
750 MIC_vAppend((u8
*)&dwMIC_Priority
, 4);
751 // 4 is Rcv buffer header, 24 is MAC Header, and 8 is IV and Ext IV.
752 MIC_vAppend((u8
*)(skb
->data
+ 8 + WLAN_HDR_ADDR3_LEN
+ 8),
753 FrameSize
- WLAN_HDR_ADDR3_LEN
- 8);
754 MIC_vGetMIC(&dwLocalMIC_L
, &dwLocalMIC_R
);
757 pdwMIC_L
= (u32
*)(skb
->data
+ 8 + FrameSize
);
758 pdwMIC_R
= (u32
*)(skb
->data
+ 8 + FrameSize
+ 4);
760 if ((cpu_to_le32(*pdwMIC_L
) != dwLocalMIC_L
) || (cpu_to_le32(*pdwMIC_R
) != dwLocalMIC_R
) ||
761 (pDevice
->bRxMICFail
== true)) {
762 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC comparison is fail!\n");
763 pDevice
->bRxMICFail
= false;
764 //pDevice->s802_11Counter.TKIPLocalMICFailures.QuadPart++;
765 pDevice
->s802_11Counter
.TKIPLocalMICFailures
++;
767 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
768 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
772 //send event to wpa_supplicant
773 //if(pDevice->bWPASuppWextEnabled == true)
775 union iwreq_data wrqu
;
776 struct iw_michaelmicfailure ev
;
777 int keyidx
= pbyFrame
[cbHeaderSize
+3] >> 6; //top two-bits
778 memset(&ev
, 0, sizeof(ev
));
779 ev
.flags
= keyidx
& IW_MICFAILURE_KEY_ID
;
780 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
781 (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
) &&
782 (*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
)) == 0) {
783 ev
.flags
|= IW_MICFAILURE_PAIRWISE
;
785 ev
.flags
|= IW_MICFAILURE_GROUP
;
788 ev
.src_addr
.sa_family
= ARPHRD_ETHER
;
789 memcpy(ev
.src_addr
.sa_data
, pMACHeader
->addr2
, ETH_ALEN
);
790 memset(&wrqu
, 0, sizeof(wrqu
));
791 wrqu
.data
.length
= sizeof(ev
);
792 PRINT_K("wireless_send_event--->IWEVMICHAELMICFAILURE\n");
793 wireless_send_event(pDevice
->dev
, IWEVMICHAELMICFAILURE
, &wrqu
, (char *)&ev
);
801 } //---end of SOFT MIC-----------------------------------------------------------------------
803 // ++++++++++ Reply Counter Check +++++++++++++
805 if ((pKey
!= NULL
) && ((pKey
->byCipherSuite
== KEY_CTL_TKIP
) ||
806 (pKey
->byCipherSuite
== KEY_CTL_CCMP
))) {
808 u16 wLocalTSC15_0
= 0;
809 u32 dwLocalTSC47_16
= 0;
810 unsigned long long RSC
= 0;
812 RSC
= *((unsigned long long *) &(pKey
->KeyRSC
));
813 wLocalTSC15_0
= (u16
) RSC
;
814 dwLocalTSC47_16
= (u32
) (RSC
>>16);
819 memcpy(&(pKey
->KeyRSC
), &RSC
, sizeof(u64
));
821 if (pDevice
->vnt_mgmt
.eCurrMode
== WMAC_MODE_ESS_STA
&&
822 pDevice
->vnt_mgmt
.eCurrState
== WMAC_STATE_ASSOC
) {
824 if ( (wRxTSC15_0
< wLocalTSC15_0
) &&
825 (dwRxTSC47_16
<= dwLocalTSC47_16
) &&
826 !((dwRxTSC47_16
== 0) && (dwLocalTSC47_16
== 0xFFFFFFFF))) {
827 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"TSC is illegal~~!\n ");
828 if (pKey
->byCipherSuite
== KEY_CTL_TKIP
)
829 //pDevice->s802_11Counter.TKIPReplays.QuadPart++;
830 pDevice
->s802_11Counter
.TKIPReplays
++;
832 //pDevice->s802_11Counter.CCMPReplays.QuadPart++;
833 pDevice
->s802_11Counter
.CCMPReplays
++;
836 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
837 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
845 } // ----- End of Reply Counter Check --------------------------
847 s_vProcessRxMACHeader(pDevice
, (u8
*)(skb
->data
+8), FrameSize
, bIsWEP
, bExtIV
, &cbHeaderOffset
);
848 FrameSize
-= cbHeaderOffset
;
849 cbHeaderOffset
+= 8; // 8 is Rcv buffer header
851 // Null data, framesize = 12
855 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
856 if (s_bAPModeRxData(pDevice
,
865 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
866 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
875 skb
->data
+= cbHeaderOffset
;
876 skb
->tail
+= cbHeaderOffset
;
877 skb_put(skb
, FrameSize
);
878 skb
->protocol
=eth_type_trans(skb
, skb
->dev
);
879 skb
->ip_summed
=CHECKSUM_NONE
;
880 pStats
->rx_bytes
+=skb
->len
;
881 pStats
->rx_packets
++;
884 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
885 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
894 static int s_bAPModeRxCtl(struct vnt_private
*pDevice
, u8
*pbyFrame
,
897 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
898 struct ieee80211_hdr
*p802_11Header
;
901 if (IS_CTL_PSPOLL(pbyFrame
) || !IS_TYPE_CONTROL(pbyFrame
)) {
903 p802_11Header
= (struct ieee80211_hdr
*) (pbyFrame
);
904 if (!IS_TYPE_MGMT(pbyFrame
)) {
906 // Data & PS-Poll packet
908 if (iSANodeIndex
> 0) {
909 // frame class 3 fliter & checking
910 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].eNodeState
< NODE_AUTH
) {
911 // send deauth notification
912 // reason = (6) class 2 received from nonauth sta
913 vMgrDeAuthenBeginSta(pDevice
,
915 (u8
*)(p802_11Header
->addr2
),
916 (WLAN_MGMT_REASON_CLASS2_NONAUTH
),
919 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: send vMgrDeAuthenBeginSta 1\n");
922 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].eNodeState
< NODE_ASSOC
) {
923 // send deassoc notification
924 // reason = (7) class 3 received from nonassoc sta
925 vMgrDisassocBeginSta(pDevice
,
927 (u8
*)(p802_11Header
->addr2
),
928 (WLAN_MGMT_REASON_CLASS3_NONASSOC
),
931 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: send vMgrDisassocBeginSta 2\n");
935 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
) {
936 // delcare received ps-poll event
937 if (IS_CTL_PSPOLL(pbyFrame
)) {
938 pMgmt
->sNodeDBTable
[iSANodeIndex
].bRxPSPoll
= true;
939 bScheduleCommand((void *) pDevice
,
942 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: WLAN_CMD_RX_PSPOLL 1\n");
945 // check Data PS state
946 // if PW bit off, send out all PS bufferring packets.
947 if (!IS_FC_POWERMGT(pbyFrame
)) {
948 pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
= false;
949 pMgmt
->sNodeDBTable
[iSANodeIndex
].bRxPSPoll
= true;
950 bScheduleCommand((void *) pDevice
,
953 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: WLAN_CMD_RX_PSPOLL 2\n");
958 if (IS_FC_POWERMGT(pbyFrame
)) {
959 pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
= true;
960 // Once if STA in PS state, enable multicast bufferring
961 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
,
971 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: WLAN_CMD_RX_PSPOLL 3\n");
978 vMgrDeAuthenBeginSta(pDevice
,
980 (u8
*)(p802_11Header
->addr2
),
981 (WLAN_MGMT_REASON_CLASS2_NONAUTH
),
984 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: send vMgrDeAuthenBeginSta 3\n");
985 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"BSSID:%pM\n",
986 p802_11Header
->addr3
);
987 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ADDR2:%pM\n",
988 p802_11Header
->addr2
);
989 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ADDR1:%pM\n",
990 p802_11Header
->addr1
);
991 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: frame_control= %x\n", p802_11Header
->frame_control
);
1000 static int s_bHandleRxEncryption(struct vnt_private
*pDevice
, u8
*pbyFrame
,
1001 u32 FrameSize
, u8
*pbyRsr
, u8
*pbyNewRsr
, PSKeyItem
*pKeyOut
,
1002 s32
*pbExtIV
, u16
*pwRxTSC15_0
, u32
*pdwRxTSC47_16
)
1004 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1005 u32 PayloadLen
= FrameSize
;
1008 PSKeyItem pKey
= NULL
;
1009 u8 byDecMode
= KEY_CTL_WEP
;
1014 pbyIV
= pbyFrame
+ WLAN_HDR_ADDR3_LEN
;
1015 if ( WLAN_GET_FC_TODS(*(u16
*)pbyFrame
) &&
1016 WLAN_GET_FC_FROMDS(*(u16
*)pbyFrame
) ) {
1017 pbyIV
+= 6; // 6 is 802.11 address4
1020 byKeyIdx
= (*(pbyIV
+3) & 0xc0);
1022 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\nKeyIdx: %d\n", byKeyIdx
);
1024 if ((pMgmt
->eAuthenMode
== WMAC_AUTH_WPA
) ||
1025 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPAPSK
) ||
1026 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) ||
1027 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2
) ||
1028 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2PSK
)) {
1029 if (((*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
)) == 0) &&
1030 (pMgmt
->byCSSPK
!= KEY_CTL_NONE
)) {
1031 // unicast pkt use pairwise key
1032 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"unicast pkt\n");
1033 if (KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBSSID
, 0xFFFFFFFF, &pKey
) == true) {
1034 if (pMgmt
->byCSSPK
== KEY_CTL_TKIP
)
1035 byDecMode
= KEY_CTL_TKIP
;
1036 else if (pMgmt
->byCSSPK
== KEY_CTL_CCMP
)
1037 byDecMode
= KEY_CTL_CCMP
;
1039 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"unicast pkt: %d, %p\n", byDecMode
, pKey
);
1042 KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBSSID
, byKeyIdx
, &pKey
);
1043 if (pMgmt
->byCSSGK
== KEY_CTL_TKIP
)
1044 byDecMode
= KEY_CTL_TKIP
;
1045 else if (pMgmt
->byCSSGK
== KEY_CTL_CCMP
)
1046 byDecMode
= KEY_CTL_CCMP
;
1047 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"group pkt: %d, %d, %p\n", byKeyIdx
, byDecMode
, pKey
);
1050 // our WEP only support Default Key
1052 // use default group key
1053 KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBroadcastAddr
, byKeyIdx
, &pKey
);
1054 if (pMgmt
->byCSSGK
== KEY_CTL_TKIP
)
1055 byDecMode
= KEY_CTL_TKIP
;
1056 else if (pMgmt
->byCSSGK
== KEY_CTL_CCMP
)
1057 byDecMode
= KEY_CTL_CCMP
;
1061 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"AES:%d %d %d\n", pMgmt
->byCSSPK
, pMgmt
->byCSSGK
, byDecMode
);
1064 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey == NULL\n");
1065 if (byDecMode
== KEY_CTL_WEP
) {
1066 // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1067 } else if (pDevice
->bLinkPass
== true) {
1068 // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1072 if (byDecMode
!= pKey
->byCipherSuite
) {
1073 if (byDecMode
== KEY_CTL_WEP
) {
1074 // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1075 } else if (pDevice
->bLinkPass
== true) {
1076 // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1081 if (byDecMode
== KEY_CTL_WEP
) {
1083 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
) ||
1084 (((PSKeyTable
)(pKey
->pvKeyTable
))->bSoftWEP
== true)) {
1089 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1090 memcpy(pDevice
->abyPRNG
, pbyIV
, 3);
1091 memcpy(pDevice
->abyPRNG
+ 3, pKey
->abyKey
, pKey
->uKeyLength
);
1092 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, pKey
->uKeyLength
+ 3);
1093 rc4_encrypt(&pDevice
->SBox
, pbyIV
+4, pbyIV
+4, PayloadLen
);
1095 if (ETHbIsBufferCrc32Ok(pbyIV
+4, PayloadLen
)) {
1096 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1099 } else if ((byDecMode
== KEY_CTL_TKIP
) ||
1100 (byDecMode
== KEY_CTL_CCMP
)) {
1103 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1104 *pdwRxTSC47_16
= cpu_to_le32(*(u32
*)(pbyIV
+ 4));
1105 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ExtIV: %x\n", *pdwRxTSC47_16
);
1106 if (byDecMode
== KEY_CTL_TKIP
) {
1107 *pwRxTSC15_0
= cpu_to_le16(MAKEWORD(*(pbyIV
+2), *pbyIV
));
1109 *pwRxTSC15_0
= cpu_to_le16(*(u16
*)pbyIV
);
1111 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"TSC0_15: %x\n", *pwRxTSC15_0
);
1113 if ((byDecMode
== KEY_CTL_TKIP
) &&
1114 (pDevice
->byLocalID
<= REV_ID_VT3253_A1
)) {
1117 struct ieee80211_hdr
*pMACHeader
= (struct ieee80211_hdr
*) (pbyFrame
);
1118 TKIPvMixKey(pKey
->abyKey
, pMACHeader
->addr2
, *pwRxTSC15_0
, *pdwRxTSC47_16
, pDevice
->abyPRNG
);
1119 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, TKIP_KEY_LEN
);
1120 rc4_encrypt(&pDevice
->SBox
, pbyIV
+8, pbyIV
+8, PayloadLen
);
1121 if (ETHbIsBufferCrc32Ok(pbyIV
+8, PayloadLen
)) {
1122 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1123 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV OK!\n");
1125 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV FAIL!!!\n");
1126 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PayloadLen = %d\n", PayloadLen
);
1131 if ((*(pbyIV
+3) & 0x20) != 0)
1136 static int s_bHostWepRxEncryption(struct vnt_private
*pDevice
, u8
*pbyFrame
,
1137 u32 FrameSize
, u8
*pbyRsr
, int bOnFly
, PSKeyItem pKey
, u8
*pbyNewRsr
,
1138 s32
*pbExtIV
, u16
*pwRxTSC15_0
, u32
*pdwRxTSC47_16
)
1140 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1141 struct ieee80211_hdr
*pMACHeader
;
1142 u32 PayloadLen
= FrameSize
;
1145 u8 byDecMode
= KEY_CTL_WEP
;
1150 pbyIV
= pbyFrame
+ WLAN_HDR_ADDR3_LEN
;
1151 if ( WLAN_GET_FC_TODS(*(u16
*)pbyFrame
) &&
1152 WLAN_GET_FC_FROMDS(*(u16
*)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
->byCSSGK
== KEY_CTL_TKIP
)
1161 byDecMode
= KEY_CTL_TKIP
;
1162 else if (pMgmt
->byCSSGK
== KEY_CTL_CCMP
)
1163 byDecMode
= KEY_CTL_CCMP
;
1165 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"AES:%d %d %d\n", pMgmt
->byCSSPK
, pMgmt
->byCSSGK
, byDecMode
);
1167 if (byDecMode
!= pKey
->byCipherSuite
) {
1168 if (byDecMode
== KEY_CTL_WEP
) {
1169 // pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1170 } else if (pDevice
->bLinkPass
== true) {
1171 // pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
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) ||
1181 (bOnFly
== false)) {
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(*(u32
*)(pbyIV
+ 4));
1203 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ExtIV: %x\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(*(u16
*)pbyIV
);
1210 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"TSC0_15: %x\n", *pwRxTSC15_0
);
1212 if (byDecMode
== KEY_CTL_TKIP
) {
1214 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
) || (bOnFly
== false)) {
1218 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"soft KEY_CTL_TKIP \n");
1219 pMACHeader
= (struct ieee80211_hdr
*) (pbyFrame
);
1220 TKIPvMixKey(pKey
->abyKey
, pMACHeader
->addr2
, *pwRxTSC15_0
, *pdwRxTSC47_16
, pDevice
->abyPRNG
);
1221 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, TKIP_KEY_LEN
);
1222 rc4_encrypt(&pDevice
->SBox
, pbyIV
+8, pbyIV
+8, PayloadLen
);
1223 if (ETHbIsBufferCrc32Ok(pbyIV
+8, PayloadLen
)) {
1224 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1225 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV OK!\n");
1227 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV FAIL!!!\n");
1228 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PayloadLen = %d\n", PayloadLen
);
1233 if (byDecMode
== KEY_CTL_CCMP
) {
1234 if (bOnFly
== false) {
1237 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"soft KEY_CTL_CCMP\n");
1238 if (AESbGenCCMP(pKey
->abyKey
, pbyFrame
, FrameSize
)) {
1239 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1240 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CCMP MIC compare OK!\n");
1242 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CCMP MIC fail!\n");
1249 if ((*(pbyIV
+3) & 0x20) != 0)
1254 static int s_bAPModeRxData(struct vnt_private
*pDevice
, struct sk_buff
*skb
,
1255 u32 FrameSize
, u32 cbHeaderOffset
, s32 iSANodeIndex
, s32 iDANodeIndex
)
1257 struct sk_buff
*skbcpy
;
1258 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1259 int bRelayAndForward
= false;
1260 int bRelayOnly
= false;
1261 u8 byMask
[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1264 if (FrameSize
> CB_MAX_BUF_SIZE
)
1267 if (is_multicast_ether_addr((u8
*)(skb
->data
+cbHeaderOffset
))) {
1268 if (pMgmt
->sNodeDBTable
[0].bPSEnable
) {
1270 skbcpy
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
1272 // if any node in PS mode, buffer packet until DTIM.
1273 if (skbcpy
== NULL
) {
1274 DBG_PRT(MSG_LEVEL_NOTICE
, KERN_INFO
"relay multicast no skb available \n");
1277 skbcpy
->dev
= pDevice
->dev
;
1278 skbcpy
->len
= FrameSize
;
1279 memcpy(skbcpy
->data
, skb
->data
+cbHeaderOffset
, FrameSize
);
1280 skb_queue_tail(&(pMgmt
->sNodeDBTable
[0].sTxPSQueue
), skbcpy
);
1281 pMgmt
->sNodeDBTable
[0].wEnQueueCnt
++;
1283 pMgmt
->abyPSTxMap
[0] |= byMask
[0];
1287 bRelayAndForward
= true;
1292 if (BSSbIsSTAInNodeDB(pDevice
, (u8
*)(skb
->data
+cbHeaderOffset
), &iDANodeIndex
)) {
1293 if (pMgmt
->sNodeDBTable
[iDANodeIndex
].eNodeState
>= NODE_ASSOC
) {
1294 if (pMgmt
->sNodeDBTable
[iDANodeIndex
].bPSEnable
) {
1295 // queue this skb until next PS tx, and then release.
1297 skb
->data
+= cbHeaderOffset
;
1298 skb
->tail
+= cbHeaderOffset
;
1299 skb_put(skb
, FrameSize
);
1300 skb_queue_tail(&pMgmt
->sNodeDBTable
[iDANodeIndex
].sTxPSQueue
, skb
);
1302 pMgmt
->sNodeDBTable
[iDANodeIndex
].wEnQueueCnt
++;
1303 wAID
= pMgmt
->sNodeDBTable
[iDANodeIndex
].wAID
;
1304 pMgmt
->abyPSTxMap
[wAID
>> 3] |= byMask
[wAID
& 7];
1305 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n",
1306 iDANodeIndex
, (wAID
>> 3), pMgmt
->abyPSTxMap
[wAID
>> 3]);
1316 if (bRelayOnly
|| bRelayAndForward
) {
1317 // relay this packet right now
1318 if (bRelayAndForward
)
1321 if ((pDevice
->uAssocCount
> 1) && (iDANodeIndex
>= 0)) {
1322 bRelayPacketSend(pDevice
, (u8
*) (skb
->data
+ cbHeaderOffset
),
1323 FrameSize
, (unsigned int) iDANodeIndex
);
1329 // none associate, don't forward
1330 if (pDevice
->uAssocCount
== 0)
1336 void RXvWorkItem(struct vnt_private
*pDevice
)
1339 struct vnt_rcb
*pRCB
= NULL
;
1341 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---->Rx Polling Thread\n");
1342 spin_lock_irq(&pDevice
->lock
);
1344 while ((pDevice
->Flags
& fMP_POST_READS
) &&
1345 MP_IS_READY(pDevice
) &&
1346 (pDevice
->NumRecvFreeList
!= 0) ) {
1347 pRCB
= pDevice
->FirstRecvFreeList
;
1348 pDevice
->NumRecvFreeList
--;
1349 DequeueRCB(pDevice
->FirstRecvFreeList
, pDevice
->LastRecvFreeList
);
1350 ntStatus
= PIPEnsBulkInUsbRead(pDevice
, pRCB
);
1352 pDevice
->bIsRxWorkItemQueued
= false;
1353 spin_unlock_irq(&pDevice
->lock
);
1357 void RXvFreeRCB(struct vnt_rcb
*pRCB
, int bReAllocSkb
)
1359 struct vnt_private
*pDevice
= pRCB
->pDevice
;
1361 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---->RXvFreeRCB\n");
1363 if (bReAllocSkb
== false) {
1364 kfree_skb(pRCB
->skb
);
1368 if (bReAllocSkb
== true) {
1369 pRCB
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
1370 // todo error handling
1371 if (pRCB
->skb
== NULL
) {
1372 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
" Failed to re-alloc rx skb\n");
1374 pRCB
->skb
->dev
= pDevice
->dev
;
1378 // Insert the RCB back in the Recv free list
1380 EnqueueRCB(pDevice
->FirstRecvFreeList
, pDevice
->LastRecvFreeList
, pRCB
);
1381 pDevice
->NumRecvFreeList
++;
1383 if ((pDevice
->Flags
& fMP_POST_READS
) && MP_IS_READY(pDevice
) &&
1384 (pDevice
->bIsRxWorkItemQueued
== false) ) {
1386 pDevice
->bIsRxWorkItemQueued
= true;
1387 tasklet_schedule(&pDevice
->ReadWorkItem
);
1389 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"<----RXFreeRCB %d %d\n",pDevice
->NumRecvFreeList
, pDevice
->NumRecvMngList
);
1392 void RXvMngWorkItem(struct vnt_private
*pDevice
)
1394 struct vnt_rcb
*pRCB
= NULL
;
1395 struct vnt_rx_mgmt
*pRxPacket
;
1396 int bReAllocSkb
= false;
1398 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---->Rx Mng Thread\n");
1400 spin_lock_irq(&pDevice
->lock
);
1401 while (pDevice
->NumRecvMngList
!=0)
1403 pRCB
= pDevice
->FirstRecvMngList
;
1404 pDevice
->NumRecvMngList
--;
1405 DequeueRCB(pDevice
->FirstRecvMngList
, pDevice
->LastRecvMngList
);
1409 pRxPacket
= &(pRCB
->sMngPacket
);
1410 vMgrRxManagePacket(pDevice
, &pDevice
->vnt_mgmt
, pRxPacket
);
1412 if(pRCB
->Ref
== 0) {
1413 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"RxvFreeMng %d %d\n",pDevice
->NumRecvFreeList
, pDevice
->NumRecvMngList
);
1414 RXvFreeRCB(pRCB
, bReAllocSkb
);
1416 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Rx Mng Only we have the right to free RCB\n");
1420 pDevice
->bIsRxMngWorkItemQueued
= false;
1421 spin_unlock_irq(&pDevice
->lock
);