2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: handle dpc rx functions
28 * device_receive_frame - Rcv 802.11 frame function
29 * s_bAPModeRxCtl- AP Rcv frame filer Ctl.
30 * s_bAPModeRxData- AP Rcv data frame handle
31 * s_bHandleRxEncryption- Rcv decrypted data via on-fly
32 * s_bHostWepRxEncryption- Rcv encrypted data via host
33 * s_byGetRateIdx- get rate index
34 * s_vGetDASA- get data offset
35 * s_vProcessRxMACHeader- Rcv 802.11 and translate to 802.3
60 //static int msglevel =MSG_LEVEL_DEBUG;
61 static int msglevel
=MSG_LEVEL_INFO
;
63 static const u8 acbyRxRate
[MAX_RATE
] =
64 {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
66 static u8
s_byGetRateIdx(u8 byRate
);
72 unsigned int *pcbHeaderSize
,
73 struct ethhdr
*psEthHeader
76 static void s_vProcessRxMACHeader(struct vnt_private
*pDevice
,
77 u8
*pbyRxBufferAddr
, u32 cbPacketSize
, int bIsWEP
, int bExtIV
,
80 static int s_bAPModeRxCtl(struct vnt_private
*pDevice
, u8
*pbyFrame
,
83 static int s_bAPModeRxData(struct vnt_private
*pDevice
, struct sk_buff
*skb
,
84 u32 FrameSize
, u32 cbHeaderOffset
, s32 iSANodeIndex
, s32 iDANodeIndex
);
86 static int s_bHandleRxEncryption(struct vnt_private
*pDevice
, u8
*pbyFrame
,
87 u32 FrameSize
, u8
*pbyRsr
, u8
*pbyNewRsr
, PSKeyItem
*pKeyOut
,
88 s32
*pbExtIV
, u16
*pwRxTSC15_0
, u32
*pdwRxTSC47_16
);
90 static int s_bHostWepRxEncryption(struct vnt_private
*pDevice
, u8
*pbyFrame
,
91 u32 FrameSize
, u8
*pbyRsr
, int bOnFly
, PSKeyItem pKey
, u8
*pbyNewRsr
,
92 s32
*pbExtIV
, u16
*pwRxTSC15_0
, u32
*pdwRxTSC47_16
);
97 * Translate Rcv 802.11 header to 802.3 header with Rx buffer
102 * dwRxBufferAddr - Address of Rcv Buffer
103 * cbPacketSize - Rcv Packet size
104 * bIsWEP - If Rcv with WEP
106 * pcbHeaderSize - 802.11 header size
112 static void s_vProcessRxMACHeader(struct vnt_private
*pDevice
,
113 u8
*pbyRxBufferAddr
, u32 cbPacketSize
, int bIsWEP
, int bExtIV
,
117 u32 cbHeaderSize
= 0;
119 struct ieee80211_hdr
*pMACHeader
;
122 pMACHeader
= (struct ieee80211_hdr
*) (pbyRxBufferAddr
+ cbHeaderSize
);
124 s_vGetDASA((u8
*)pMACHeader
, &cbHeaderSize
, &pDevice
->sRxEthHeader
);
128 // strip IV&ExtIV , add 8 byte
129 cbHeaderSize
+= (WLAN_HDR_ADDR3_LEN
+ 8);
131 // strip IV , add 4 byte
132 cbHeaderSize
+= (WLAN_HDR_ADDR3_LEN
+ 4);
136 cbHeaderSize
+= WLAN_HDR_ADDR3_LEN
;
139 pbyRxBuffer
= (u8
*) (pbyRxBufferAddr
+ cbHeaderSize
);
140 if (ether_addr_equal(pbyRxBuffer
, pDevice
->abySNAP_Bridgetunnel
)) {
142 } else if (ether_addr_equal(pbyRxBuffer
, pDevice
->abySNAP_RFC1042
)) {
144 pwType
= (u16
*) (pbyRxBufferAddr
+ cbHeaderSize
);
145 if ((*pwType
== cpu_to_be16(ETH_P_IPX
)) ||
146 (*pwType
== cpu_to_le16(0xF380))) {
148 pwType
= (u16
*) (pbyRxBufferAddr
+ cbHeaderSize
);
151 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 8); // 8 is IV&ExtIV
153 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 4); // 4 is IV
157 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
);
163 pwType
= (u16
*) (pbyRxBufferAddr
+ cbHeaderSize
);
166 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 8); // 8 is IV&ExtIV
168 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
- 4); // 4 is IV
172 *pwType
= htons(cbPacketSize
- WLAN_HDR_ADDR3_LEN
);
176 cbHeaderSize
-= (ETH_ALEN
* 2);
177 pbyRxBuffer
= (u8
*) (pbyRxBufferAddr
+ cbHeaderSize
);
178 for (ii
= 0; ii
< ETH_ALEN
; ii
++)
179 *pbyRxBuffer
++ = pDevice
->sRxEthHeader
.h_dest
[ii
];
180 for (ii
= 0; ii
< ETH_ALEN
; ii
++)
181 *pbyRxBuffer
++ = pDevice
->sRxEthHeader
.h_source
[ii
];
183 *pcbHeadSize
= cbHeaderSize
;
186 static u8
s_byGetRateIdx(u8 byRate
)
190 for (byRateIdx
= 0; byRateIdx
<MAX_RATE
; byRateIdx
++) {
191 if (acbyRxRate
[byRateIdx
%MAX_RATE
] == byRate
)
200 u8
* pbyRxBufferAddr
,
201 unsigned int *pcbHeaderSize
,
202 struct ethhdr
*psEthHeader
205 unsigned int cbHeaderSize
= 0;
206 struct ieee80211_hdr
*pMACHeader
;
209 pMACHeader
= (struct ieee80211_hdr
*) (pbyRxBufferAddr
+ cbHeaderSize
);
211 if ((pMACHeader
->frame_control
& FC_TODS
) == 0) {
212 if (pMACHeader
->frame_control
& FC_FROMDS
) {
213 for (ii
= 0; ii
< ETH_ALEN
; ii
++) {
214 psEthHeader
->h_dest
[ii
] =
215 pMACHeader
->addr1
[ii
];
216 psEthHeader
->h_source
[ii
] =
217 pMACHeader
->addr3
[ii
];
221 for (ii
= 0; ii
< ETH_ALEN
; ii
++) {
222 psEthHeader
->h_dest
[ii
] =
223 pMACHeader
->addr1
[ii
];
224 psEthHeader
->h_source
[ii
] =
225 pMACHeader
->addr2
[ii
];
230 if (pMACHeader
->frame_control
& FC_FROMDS
) {
231 for (ii
= 0; ii
< ETH_ALEN
; ii
++) {
232 psEthHeader
->h_dest
[ii
] =
233 pMACHeader
->addr3
[ii
];
234 psEthHeader
->h_source
[ii
] =
235 pMACHeader
->addr4
[ii
];
239 for (ii
= 0; ii
< ETH_ALEN
; ii
++) {
240 psEthHeader
->h_dest
[ii
] =
241 pMACHeader
->addr3
[ii
];
242 psEthHeader
->h_source
[ii
] =
243 pMACHeader
->addr2
[ii
];
247 *pcbHeaderSize
= cbHeaderSize
;
250 int RXbBulkInProcessData(struct vnt_private
*pDevice
, struct vnt_rcb
*pRCB
,
251 unsigned long BytesToIndicate
)
253 struct net_device_stats
*pStats
= &pDevice
->stats
;
255 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
256 struct vnt_rx_mgmt
*pRxPacket
= &pMgmt
->sRxPacket
;
257 struct ieee80211_hdr
*p802_11Header
;
258 u8
*pbyRsr
, *pbyNewRsr
, *pbyRSSI
, *pbyFrame
;
260 u32 bDeFragRx
= false;
261 u32 cbHeaderOffset
, cbIVOffset
;
264 s32 iSANodeIndex
= -1, iDANodeIndex
= -1;
266 u8
*pbyRxSts
, *pbyRxRate
, *pbySQ
, *pby3SQ
;
268 PSKeyItem pKey
= NULL
;
270 u32 dwRxTSC47_16
= 0;
272 /* signed long ldBm = 0; */
273 int bIsWEP
= false; int bExtIV
= false;
275 struct vnt_rcb
*pRCBIndicate
= pRCB
;
278 u8 abyVaildRate
[MAX_RATE
]
279 = {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
280 u16 wPLCPwithPadding
;
281 struct ieee80211_hdr
*pMACHeader
;
282 int bRxeapol_key
= false;
284 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---------- RXbBulkInProcessData---\n");
288 /* [31:16]RcvByteCount ( not include 4-byte Status ) */
289 dwWbkStatus
= *((u32
*)(skb
->data
));
290 FrameSize
= dwWbkStatus
>> 16;
293 if (BytesToIndicate
!= FrameSize
) {
294 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"------- WRONG Length 1\n");
295 pStats
->rx_frame_errors
++;
299 if ((BytesToIndicate
> 2372) || (BytesToIndicate
<= 40)) {
300 // Frame Size error drop this packet.
301 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---------- WRONG Length 2\n");
302 pStats
->rx_frame_errors
++;
306 pbyDAddress
= (u8
*)(skb
->data
);
307 pbyRxSts
= pbyDAddress
+4;
308 pbyRxRate
= pbyDAddress
+5;
310 //real Frame Size = USBFrameSize -4WbkStatus - 4RxStatus - 8TSF - 4RSR - 4SQ3 - ?Padding
311 //if SQ3 the range is 24~27, if no SQ3 the range is 20~23
312 //real Frame size in PLCPLength field.
313 pwPLCP_Length
= (u16
*) (pbyDAddress
+ 6);
314 //Fix hardware bug => PLCP_Length error
315 if ( ((BytesToIndicate
- (*pwPLCP_Length
)) > 27) ||
316 ((BytesToIndicate
- (*pwPLCP_Length
)) < 24) ||
317 (BytesToIndicate
< (*pwPLCP_Length
)) ) {
319 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Wrong PLCP Length %x\n", (int) *pwPLCP_Length
);
320 pStats
->rx_frame_errors
++;
323 for ( ii
=RATE_1M
;ii
<MAX_RATE
;ii
++) {
324 if ( *pbyRxRate
== abyVaildRate
[ii
] ) {
328 if ( ii
==MAX_RATE
) {
329 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Wrong RxRate %x\n",(int) *pbyRxRate
);
333 wPLCPwithPadding
= ( (*pwPLCP_Length
/ 4) + ( (*pwPLCP_Length
% 4) ? 1:0 ) ) *4;
335 pqwTSFTime
= (u64
*)(pbyDAddress
+ 8 + wPLCPwithPadding
);
336 if(pDevice
->byBBType
== BB_TYPE_11G
) {
337 pby3SQ
= pbyDAddress
+ 8 + wPLCPwithPadding
+ 12;
341 pbySQ
= pbyDAddress
+ 8 + wPLCPwithPadding
+ 8;
344 pbyNewRsr
= pbyDAddress
+ 8 + wPLCPwithPadding
+ 9;
345 pbyRSSI
= pbyDAddress
+ 8 + wPLCPwithPadding
+ 10;
346 pbyRsr
= pbyDAddress
+ 8 + wPLCPwithPadding
+ 11;
348 FrameSize
= *pwPLCP_Length
;
350 pbyFrame
= pbyDAddress
+ 8;
352 pMACHeader
= (struct ieee80211_hdr
*) pbyFrame
;
354 //mike add: to judge if current AP is activated?
355 if ((pMgmt
->eCurrMode
== WMAC_MODE_STANDBY
) ||
356 (pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
)) {
357 if (pMgmt
->sNodeDBTable
[0].bActive
) {
358 if (ether_addr_equal(pMgmt
->abyCurrBSSID
, pMACHeader
->addr2
)) {
359 if (pMgmt
->sNodeDBTable
[0].uInActiveCount
!= 0)
360 pMgmt
->sNodeDBTable
[0].uInActiveCount
= 0;
365 if (!is_multicast_ether_addr(pMACHeader
->addr1
)) {
366 if (WCTLbIsDuplicate(&(pDevice
->sDupRxCache
), (struct ieee80211_hdr
*) pbyFrame
)) {
370 if (!ether_addr_equal(pDevice
->abyCurrentNetAddr
, pMACHeader
->addr1
)) {
376 s_vGetDASA(pbyFrame
, &cbHeaderSize
, &pDevice
->sRxEthHeader
);
378 if (ether_addr_equal((u8
*)pDevice
->sRxEthHeader
.h_source
,
379 pDevice
->abyCurrentNetAddr
))
382 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) || (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
)) {
383 if (IS_CTL_PSPOLL(pbyFrame
) || !IS_TYPE_CONTROL(pbyFrame
)) {
384 p802_11Header
= (struct ieee80211_hdr
*) (pbyFrame
);
386 if (BSSbIsSTAInNodeDB(pDevice
, (u8
*)(p802_11Header
->addr2
), &iSANodeIndex
)) {
387 pMgmt
->sNodeDBTable
[iSANodeIndex
].ulLastRxJiffer
= jiffies
;
388 pMgmt
->sNodeDBTable
[iSANodeIndex
].uInActiveCount
= 0;
393 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
394 if (s_bAPModeRxCtl(pDevice
, pbyFrame
, iSANodeIndex
) == true) {
399 if (IS_FC_WEP(pbyFrame
)) {
400 bool bRxDecryOK
= false;
402 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"rx WEP pkt\n");
404 if ((pDevice
->bEnableHostWEP
) && (iSANodeIndex
>= 0)) {
406 pKey
->byCipherSuite
= pMgmt
->sNodeDBTable
[iSANodeIndex
].byCipherSuite
;
407 pKey
->dwKeyIndex
= pMgmt
->sNodeDBTable
[iSANodeIndex
].dwKeyIndex
;
408 pKey
->uKeyLength
= pMgmt
->sNodeDBTable
[iSANodeIndex
].uWepKeyLength
;
409 pKey
->dwTSC47_16
= pMgmt
->sNodeDBTable
[iSANodeIndex
].dwTSC47_16
;
410 pKey
->wTSC15_0
= pMgmt
->sNodeDBTable
[iSANodeIndex
].wTSC15_0
;
412 &pMgmt
->sNodeDBTable
[iSANodeIndex
].abyWepKey
[0],
416 bRxDecryOK
= s_bHostWepRxEncryption(pDevice
,
420 pMgmt
->sNodeDBTable
[iSANodeIndex
].bOnFly
,
427 bRxDecryOK
= s_bHandleRxEncryption(pDevice
,
439 if ((*pbyNewRsr
& NEWRSR_DECRYPTOK
) == 0) {
440 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV Fail\n");
441 if ( (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA
) ||
442 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPAPSK
) ||
443 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) ||
444 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2
) ||
445 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2PSK
)) {
450 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"WEP Func Fail\n");
453 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_CCMP
))
454 FrameSize
-= 8; // Message Integrity Code
456 FrameSize
-= 4; // 4 is ICV
462 /* remove the FCS/CRC length */
463 FrameSize
-= ETH_FCS_LEN
;
465 if ( !(*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
)) && // unicast address
466 (IS_FRAGMENT_PKT((pbyFrame
)))
469 bDeFragRx
= WCTLbHandleFragment(pDevice
, (struct ieee80211_hdr
*) (pbyFrame
), FrameSize
, bIsWEP
, bExtIV
);
472 // TODO skb, pbyFrame
473 skb
= pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].skb
;
474 FrameSize
= pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
].cbFrameLength
;
475 pbyFrame
= skb
->data
+ 8;
483 // Management & Control frame Handle
485 if ((IS_TYPE_DATA((pbyFrame
))) == false) {
486 // Handle Control & Manage Frame
488 if (IS_TYPE_MGMT((pbyFrame
))) {
492 pRxPacket
= &(pRCB
->sMngPacket
);
493 pRxPacket
->p80211Header
= (PUWLAN_80211HDR
)(pbyFrame
);
494 pRxPacket
->cbMPDULen
= FrameSize
;
495 pRxPacket
->uRSSI
= *pbyRSSI
;
496 pRxPacket
->bySQ
= *pbySQ
;
497 pRxPacket
->qwLocalTSF
= cpu_to_le64(*pqwTSFTime
);
500 pbyData1
= WLAN_HDR_A3_DATA_PTR(pbyFrame
);
501 pbyData2
= WLAN_HDR_A3_DATA_PTR(pbyFrame
) + 4;
502 for (ii
= 0; ii
< (FrameSize
- 4); ii
++) {
503 *pbyData1
= *pbyData2
;
509 pRxPacket
->byRxRate
= s_byGetRateIdx(*pbyRxRate
);
511 if ( *pbyRxSts
== 0 ) {
512 //Discard beacon packet which channel is 0
513 if ( (WLAN_GET_FC_FSTYPE((pRxPacket
->p80211Header
->sA3
.wFrameCtl
)) == WLAN_FSTYPE_BEACON
) ||
514 (WLAN_GET_FC_FSTYPE((pRxPacket
->p80211Header
->sA3
.wFrameCtl
)) == WLAN_FSTYPE_PROBERESP
) ) {
518 pRxPacket
->byRxChannel
= (*pbyRxSts
) >> 2;
520 // hostap Deamon handle 802.11 management
521 if (pDevice
->bEnableHostapd
) {
522 skb
->dev
= pDevice
->apdev
;
527 skb_put(skb
, FrameSize
);
528 skb_reset_mac_header(skb
);
529 skb
->pkt_type
= PACKET_OTHERHOST
;
530 skb
->protocol
= htons(ETH_P_802_2
);
531 memset(skb
->cb
, 0, sizeof(skb
->cb
));
537 // Insert the RCB in the Recv Mng list
539 EnqueueRCB(pDevice
->FirstRecvMngList
, pDevice
->LastRecvMngList
, pRCBIndicate
);
540 pDevice
->NumRecvMngList
++;
541 if ( bDeFragRx
== false) {
544 if (pDevice
->bIsRxMngWorkItemQueued
== false) {
545 pDevice
->bIsRxMngWorkItemQueued
= true;
546 schedule_work(&pDevice
->rx_mng_work_item
);
556 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
557 //In AP mode, hw only check addr1(BSSID or RA) if equal to local MAC.
558 if ( !(*pbyRsr
& RSR_BSSIDOK
)) {
560 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
561 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
569 // discard DATA packet while not associate || BSSID error
570 if ((pDevice
->bLinkPass
== false) ||
571 !(*pbyRsr
& RSR_BSSIDOK
)) {
573 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
574 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
580 //mike add:station mode check eapol-key challenge--->
582 u8 Protocol_Version
; //802.1x Authentication
583 u8 Packet_Type
; //802.1x Authentication
590 wEtherType
= (skb
->data
[cbIVOffset
+ 8 + 24 + 6] << 8) |
591 skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1];
592 Protocol_Version
= skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1 +1];
593 Packet_Type
= skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1 +1+1];
594 if (wEtherType
== ETH_P_PAE
) { //Protocol Type in LLC-Header
595 if(((Protocol_Version
==1) ||(Protocol_Version
==2)) &&
596 (Packet_Type
==3)) { //802.1x OR eapol-key challenge frame receive
598 Descriptor_type
= skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1 +1+1+1+2];
599 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] ;
600 if(Descriptor_type
==2) { //RSN
601 // printk("WPA2_Rx_eapol-key_info<-----:%x\n",Key_info);
603 else if(Descriptor_type
==254) {
604 // printk("WPA_Rx_eapol-key_info<-----:%x\n",Key_info);
609 //mike add:station mode check eapol-key challenge<---
615 if (pDevice
->bEnablePSMode
) {
616 if (IS_FC_MOREDATA((pbyFrame
))) {
617 if (*pbyRsr
& RSR_ADDROK
) {
618 //PSbSendPSPOLL((PSDevice)pDevice);
622 if (pMgmt
->bInTIMWake
== true) {
623 pMgmt
->bInTIMWake
= false;
628 // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps
629 if (pDevice
->bDiversityEnable
&& (FrameSize
>50) &&
630 (pDevice
->eOPMode
== OP_MODE_INFRASTRUCTURE
) &&
631 (pDevice
->bLinkPass
== true)) {
632 BBvAntennaDiversity(pDevice
, s_byGetRateIdx(*pbyRxRate
), 0);
635 // ++++++++ For BaseBand Algorithm +++++++++++++++
636 pDevice
->uCurrRSSI
= *pbyRSSI
;
637 pDevice
->byCurrSQ
= *pbySQ
;
641 if ((*pbyRSSI != 0) &&
642 (pMgmt->pCurrBSS!=NULL)) {
643 RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
644 // Monitor if RSSI is too strong.
645 pMgmt->pCurrBSS->byRSSIStatCnt++;
646 pMgmt->pCurrBSS->byRSSIStatCnt %= RSSI_STAT_COUNT;
647 pMgmt->pCurrBSS->ldBmAverage[pMgmt->pCurrBSS->byRSSIStatCnt] = ldBm;
648 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
649 if (pMgmt->pCurrBSS->ldBmAverage[ii] != 0) {
650 pMgmt->pCurrBSS->ldBmMAX =
651 max(pMgmt->pCurrBSS->ldBmAverage[ii], ldBm);
657 // -----------------------------------------------
659 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) && (pDevice
->bEnable8021x
== true)){
662 // Only 802.1x packet incoming allowed
667 wEtherType
= (skb
->data
[cbIVOffset
+ 8 + 24 + 6] << 8) |
668 skb
->data
[cbIVOffset
+ 8 + 24 + 6 + 1];
670 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wEtherType = %04x \n", wEtherType
);
671 if (wEtherType
== ETH_P_PAE
) {
672 skb
->dev
= pDevice
->apdev
;
674 if (bIsWEP
== true) {
675 // strip IV header(8)
676 memcpy(&abyMacHdr
[0], (skb
->data
+ 8), 24);
677 memcpy((skb
->data
+ 8 + cbIVOffset
), &abyMacHdr
[0], 24);
680 skb
->data
+= (cbIVOffset
+ 8);
681 skb
->tail
+= (cbIVOffset
+ 8);
682 skb_put(skb
, FrameSize
);
683 skb_reset_mac_header(skb
);
684 skb
->pkt_type
= PACKET_OTHERHOST
;
685 skb
->protocol
= htons(ETH_P_802_2
);
686 memset(skb
->cb
, 0, sizeof(skb
->cb
));
691 // check if 802.1x authorized
692 if (!(pMgmt
->sNodeDBTable
[iSANodeIndex
].dwFlags
& WLAN_STA_AUTHORIZED
))
696 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
698 FrameSize
-= 8; //MIC
702 //--------------------------------------------------------------------------------
704 if ((pKey
!= NULL
) && (pKey
->byCipherSuite
== KEY_CTL_TKIP
)) {
709 u32 dwMICKey0
= 0, dwMICKey1
= 0;
710 u32 dwLocalMIC_L
= 0;
711 u32 dwLocalMIC_R
= 0;
713 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
714 dwMICKey0
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[24]));
715 dwMICKey1
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[28]));
718 if (pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) {
719 dwMICKey0
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[16]));
720 dwMICKey1
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[20]));
721 } else if ((pKey
->dwKeyIndex
& BIT28
) == 0) {
722 dwMICKey0
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[16]));
723 dwMICKey1
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[20]));
725 dwMICKey0
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[24]));
726 dwMICKey1
= cpu_to_le32(*(u32
*)(&pKey
->abyKey
[28]));
730 MIC_vInit(dwMICKey0
, dwMICKey1
);
731 MIC_vAppend((u8
*)&(pDevice
->sRxEthHeader
.h_dest
[0]), 12);
733 MIC_vAppend((u8
*)&dwMIC_Priority
, 4);
734 // 4 is Rcv buffer header, 24 is MAC Header, and 8 is IV and Ext IV.
735 MIC_vAppend((u8
*)(skb
->data
+ 8 + WLAN_HDR_ADDR3_LEN
+ 8),
736 FrameSize
- WLAN_HDR_ADDR3_LEN
- 8);
737 MIC_vGetMIC(&dwLocalMIC_L
, &dwLocalMIC_R
);
740 pdwMIC_L
= (u32
*)(skb
->data
+ 8 + FrameSize
);
741 pdwMIC_R
= (u32
*)(skb
->data
+ 8 + FrameSize
+ 4);
743 if ((cpu_to_le32(*pdwMIC_L
) != dwLocalMIC_L
) || (cpu_to_le32(*pdwMIC_R
) != dwLocalMIC_R
) ||
744 (pDevice
->bRxMICFail
== true)) {
745 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"MIC comparison is fail!\n");
746 pDevice
->bRxMICFail
= false;
748 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
749 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
753 //send event to wpa_supplicant
754 //if(pDevice->bWPASuppWextEnabled == true)
756 union iwreq_data wrqu
;
757 struct iw_michaelmicfailure ev
;
758 int keyidx
= pbyFrame
[cbHeaderSize
+3] >> 6; //top two-bits
759 memset(&ev
, 0, sizeof(ev
));
760 ev
.flags
= keyidx
& IW_MICFAILURE_KEY_ID
;
761 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
762 (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
) &&
763 (*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
)) == 0) {
764 ev
.flags
|= IW_MICFAILURE_PAIRWISE
;
766 ev
.flags
|= IW_MICFAILURE_GROUP
;
769 ev
.src_addr
.sa_family
= ARPHRD_ETHER
;
770 memcpy(ev
.src_addr
.sa_data
, pMACHeader
->addr2
, ETH_ALEN
);
771 memset(&wrqu
, 0, sizeof(wrqu
));
772 wrqu
.data
.length
= sizeof(ev
);
773 PRINT_K("wireless_send_event--->IWEVMICHAELMICFAILURE\n");
774 wireless_send_event(pDevice
->dev
, IWEVMICHAELMICFAILURE
, &wrqu
, (char *)&ev
);
782 } //---end of SOFT MIC-----------------------------------------------------------------------
784 // ++++++++++ Reply Counter Check +++++++++++++
786 if ((pKey
!= NULL
) && ((pKey
->byCipherSuite
== KEY_CTL_TKIP
) ||
787 (pKey
->byCipherSuite
== KEY_CTL_CCMP
))) {
789 u16 wLocalTSC15_0
= 0;
790 u32 dwLocalTSC47_16
= 0;
791 unsigned long long RSC
= 0;
793 RSC
= *((unsigned long long *) &(pKey
->KeyRSC
));
794 wLocalTSC15_0
= (u16
) RSC
;
795 dwLocalTSC47_16
= (u32
) (RSC
>>16);
800 memcpy(&(pKey
->KeyRSC
), &RSC
, sizeof(u64
));
802 if (pDevice
->vnt_mgmt
.eCurrMode
== WMAC_MODE_ESS_STA
&&
803 pDevice
->vnt_mgmt
.eCurrState
== WMAC_STATE_ASSOC
) {
805 if ( (wRxTSC15_0
< wLocalTSC15_0
) &&
806 (dwRxTSC47_16
<= dwLocalTSC47_16
) &&
807 !((dwRxTSC47_16
== 0) && (dwLocalTSC47_16
== 0xFFFFFFFF))) {
808 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"TSC is illegal~~!\n ");
811 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
812 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
820 } // ----- End of Reply Counter Check --------------------------
822 s_vProcessRxMACHeader(pDevice
, (u8
*)(skb
->data
+8), FrameSize
, bIsWEP
, bExtIV
, &cbHeaderOffset
);
823 FrameSize
-= cbHeaderOffset
;
824 cbHeaderOffset
+= 8; // 8 is Rcv buffer header
826 // Null data, framesize = 12
830 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
831 if (s_bAPModeRxData(pDevice
,
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",
850 skb
->data
+= cbHeaderOffset
;
851 skb
->tail
+= cbHeaderOffset
;
852 skb_put(skb
, FrameSize
);
853 skb
->protocol
=eth_type_trans(skb
, skb
->dev
);
854 skb
->ip_summed
=CHECKSUM_NONE
;
855 pStats
->rx_bytes
+=skb
->len
;
856 pStats
->rx_packets
++;
859 if (!device_alloc_frag_buf(pDevice
, &pDevice
->sRxDFCB
[pDevice
->uCurrentDFCBIdx
])) {
860 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
"%s: can not alloc more frag bufs\n",
869 static int s_bAPModeRxCtl(struct vnt_private
*pDevice
, u8
*pbyFrame
,
872 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
873 struct ieee80211_hdr
*p802_11Header
;
876 if (IS_CTL_PSPOLL(pbyFrame
) || !IS_TYPE_CONTROL(pbyFrame
)) {
878 p802_11Header
= (struct ieee80211_hdr
*) (pbyFrame
);
879 if (!IS_TYPE_MGMT(pbyFrame
)) {
881 // Data & PS-Poll packet
883 if (iSANodeIndex
> 0) {
884 // frame class 3 fliter & checking
885 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].eNodeState
< NODE_AUTH
) {
886 // send deauth notification
887 // reason = (6) class 2 received from nonauth sta
888 vMgrDeAuthenBeginSta(pDevice
,
890 (u8
*)(p802_11Header
->addr2
),
891 (WLAN_MGMT_REASON_CLASS2_NONAUTH
),
894 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: send vMgrDeAuthenBeginSta 1\n");
897 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].eNodeState
< NODE_ASSOC
) {
898 // send deassoc notification
899 // reason = (7) class 3 received from nonassoc sta
900 vMgrDisassocBeginSta(pDevice
,
902 (u8
*)(p802_11Header
->addr2
),
903 (WLAN_MGMT_REASON_CLASS3_NONASSOC
),
906 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: send vMgrDisassocBeginSta 2\n");
910 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
) {
911 // delcare received ps-poll event
912 if (IS_CTL_PSPOLL(pbyFrame
)) {
913 pMgmt
->sNodeDBTable
[iSANodeIndex
].bRxPSPoll
= true;
914 bScheduleCommand((void *) pDevice
,
917 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: WLAN_CMD_RX_PSPOLL 1\n");
920 // check Data PS state
921 // if PW bit off, send out all PS bufferring packets.
922 if (!IS_FC_POWERMGT(pbyFrame
)) {
923 pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
= false;
924 pMgmt
->sNodeDBTable
[iSANodeIndex
].bRxPSPoll
= true;
925 bScheduleCommand((void *) pDevice
,
928 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: WLAN_CMD_RX_PSPOLL 2\n");
933 if (IS_FC_POWERMGT(pbyFrame
)) {
934 pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
= true;
935 // Once if STA in PS state, enable multicast bufferring
936 pMgmt
->sNodeDBTable
[0].bPSEnable
= true;
939 // clear all pending PS frame.
940 if (pMgmt
->sNodeDBTable
[iSANodeIndex
].wEnQueueCnt
> 0) {
941 pMgmt
->sNodeDBTable
[iSANodeIndex
].bPSEnable
= false;
942 pMgmt
->sNodeDBTable
[iSANodeIndex
].bRxPSPoll
= true;
943 bScheduleCommand((void *) pDevice
,
946 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: WLAN_CMD_RX_PSPOLL 3\n");
953 vMgrDeAuthenBeginSta(pDevice
,
955 (u8
*)(p802_11Header
->addr2
),
956 (WLAN_MGMT_REASON_CLASS2_NONAUTH
),
959 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: send vMgrDeAuthenBeginSta 3\n");
960 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"BSSID:%pM\n",
961 p802_11Header
->addr3
);
962 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ADDR2:%pM\n",
963 p802_11Header
->addr2
);
964 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ADDR1:%pM\n",
965 p802_11Header
->addr1
);
966 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"dpc: frame_control= %x\n", p802_11Header
->frame_control
);
975 static int s_bHandleRxEncryption(struct vnt_private
*pDevice
, u8
*pbyFrame
,
976 u32 FrameSize
, u8
*pbyRsr
, u8
*pbyNewRsr
, PSKeyItem
*pKeyOut
,
977 s32
*pbExtIV
, u16
*pwRxTSC15_0
, u32
*pdwRxTSC47_16
)
979 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
980 u32 PayloadLen
= FrameSize
;
983 PSKeyItem pKey
= NULL
;
984 u8 byDecMode
= KEY_CTL_WEP
;
989 pbyIV
= pbyFrame
+ WLAN_HDR_ADDR3_LEN
;
990 if ( WLAN_GET_FC_TODS(*(u16
*)pbyFrame
) &&
991 WLAN_GET_FC_FROMDS(*(u16
*)pbyFrame
) ) {
992 pbyIV
+= 6; // 6 is 802.11 address4
995 byKeyIdx
= (*(pbyIV
+3) & 0xc0);
997 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\nKeyIdx: %d\n", byKeyIdx
);
999 if ((pMgmt
->eAuthenMode
== WMAC_AUTH_WPA
) ||
1000 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPAPSK
) ||
1001 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPANONE
) ||
1002 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2
) ||
1003 (pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2PSK
)) {
1004 if (((*pbyRsr
& (RSR_ADDRBROAD
| RSR_ADDRMULTI
)) == 0) &&
1005 (pMgmt
->byCSSPK
!= KEY_CTL_NONE
)) {
1006 // unicast pkt use pairwise key
1007 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"unicast pkt\n");
1008 if (KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBSSID
, 0xFFFFFFFF, &pKey
) == true) {
1009 if (pMgmt
->byCSSPK
== KEY_CTL_TKIP
)
1010 byDecMode
= KEY_CTL_TKIP
;
1011 else if (pMgmt
->byCSSPK
== KEY_CTL_CCMP
)
1012 byDecMode
= KEY_CTL_CCMP
;
1014 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"unicast pkt: %d, %p\n", byDecMode
, pKey
);
1017 KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBSSID
, byKeyIdx
, &pKey
);
1018 if (pMgmt
->byCSSGK
== KEY_CTL_TKIP
)
1019 byDecMode
= KEY_CTL_TKIP
;
1020 else if (pMgmt
->byCSSGK
== KEY_CTL_CCMP
)
1021 byDecMode
= KEY_CTL_CCMP
;
1022 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"group pkt: %d, %d, %p\n", byKeyIdx
, byDecMode
, pKey
);
1025 // our WEP only support Default Key
1027 // use default group key
1028 KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBroadcastAddr
, byKeyIdx
, &pKey
);
1029 if (pMgmt
->byCSSGK
== KEY_CTL_TKIP
)
1030 byDecMode
= KEY_CTL_TKIP
;
1031 else if (pMgmt
->byCSSGK
== KEY_CTL_CCMP
)
1032 byDecMode
= KEY_CTL_CCMP
;
1036 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"AES:%d %d %d\n", pMgmt
->byCSSPK
, pMgmt
->byCSSGK
, byDecMode
);
1039 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pKey == NULL\n");
1042 if (byDecMode
!= pKey
->byCipherSuite
) {
1046 if (byDecMode
== KEY_CTL_WEP
) {
1048 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
) ||
1049 (((PSKeyTable
)(pKey
->pvKeyTable
))->bSoftWEP
== true)) {
1054 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1055 memcpy(pDevice
->abyPRNG
, pbyIV
, 3);
1056 memcpy(pDevice
->abyPRNG
+ 3, pKey
->abyKey
, pKey
->uKeyLength
);
1057 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, pKey
->uKeyLength
+ 3);
1058 rc4_encrypt(&pDevice
->SBox
, pbyIV
+4, pbyIV
+4, PayloadLen
);
1060 if (ETHbIsBufferCrc32Ok(pbyIV
+4, PayloadLen
)) {
1061 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1064 } else if ((byDecMode
== KEY_CTL_TKIP
) ||
1065 (byDecMode
== KEY_CTL_CCMP
)) {
1068 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1069 *pdwRxTSC47_16
= cpu_to_le32(*(u32
*)(pbyIV
+ 4));
1070 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ExtIV: %x\n", *pdwRxTSC47_16
);
1071 if (byDecMode
== KEY_CTL_TKIP
) {
1072 *pwRxTSC15_0
= cpu_to_le16(MAKEWORD(*(pbyIV
+2), *pbyIV
));
1074 *pwRxTSC15_0
= cpu_to_le16(*(u16
*)pbyIV
);
1076 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"TSC0_15: %x\n", *pwRxTSC15_0
);
1078 if ((byDecMode
== KEY_CTL_TKIP
) &&
1079 (pDevice
->byLocalID
<= REV_ID_VT3253_A1
)) {
1082 struct ieee80211_hdr
*pMACHeader
= (struct ieee80211_hdr
*) (pbyFrame
);
1083 TKIPvMixKey(pKey
->abyKey
, pMACHeader
->addr2
, *pwRxTSC15_0
, *pdwRxTSC47_16
, pDevice
->abyPRNG
);
1084 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, TKIP_KEY_LEN
);
1085 rc4_encrypt(&pDevice
->SBox
, pbyIV
+8, pbyIV
+8, PayloadLen
);
1086 if (ETHbIsBufferCrc32Ok(pbyIV
+8, PayloadLen
)) {
1087 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1088 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV OK!\n");
1090 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV FAIL!!!\n");
1091 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PayloadLen = %d\n", PayloadLen
);
1096 if ((*(pbyIV
+3) & 0x20) != 0)
1101 static int s_bHostWepRxEncryption(struct vnt_private
*pDevice
, u8
*pbyFrame
,
1102 u32 FrameSize
, u8
*pbyRsr
, int bOnFly
, PSKeyItem pKey
, u8
*pbyNewRsr
,
1103 s32
*pbExtIV
, u16
*pwRxTSC15_0
, u32
*pdwRxTSC47_16
)
1105 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1106 struct ieee80211_hdr
*pMACHeader
;
1107 u32 PayloadLen
= FrameSize
;
1110 u8 byDecMode
= KEY_CTL_WEP
;
1115 pbyIV
= pbyFrame
+ WLAN_HDR_ADDR3_LEN
;
1116 if ( WLAN_GET_FC_TODS(*(u16
*)pbyFrame
) &&
1117 WLAN_GET_FC_FROMDS(*(u16
*)pbyFrame
) ) {
1118 pbyIV
+= 6; // 6 is 802.11 address4
1121 byKeyIdx
= (*(pbyIV
+3) & 0xc0);
1123 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"\nKeyIdx: %d\n", byKeyIdx
);
1125 if (pMgmt
->byCSSGK
== KEY_CTL_TKIP
)
1126 byDecMode
= KEY_CTL_TKIP
;
1127 else if (pMgmt
->byCSSGK
== KEY_CTL_CCMP
)
1128 byDecMode
= KEY_CTL_CCMP
;
1130 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"AES:%d %d %d\n", pMgmt
->byCSSPK
, pMgmt
->byCSSGK
, byDecMode
);
1132 if (byDecMode
!= pKey
->byCipherSuite
) {
1136 if (byDecMode
== KEY_CTL_WEP
) {
1138 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"byDecMode == KEY_CTL_WEP\n");
1139 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
) ||
1140 (((PSKeyTable
)(pKey
->pvKeyTable
))->bSoftWEP
== true) ||
1141 (bOnFly
== false)) {
1147 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1148 memcpy(pDevice
->abyPRNG
, pbyIV
, 3);
1149 memcpy(pDevice
->abyPRNG
+ 3, pKey
->abyKey
, pKey
->uKeyLength
);
1150 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, pKey
->uKeyLength
+ 3);
1151 rc4_encrypt(&pDevice
->SBox
, pbyIV
+4, pbyIV
+4, PayloadLen
);
1153 if (ETHbIsBufferCrc32Ok(pbyIV
+4, PayloadLen
)) {
1154 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1157 } else if ((byDecMode
== KEY_CTL_TKIP
) ||
1158 (byDecMode
== KEY_CTL_CCMP
)) {
1161 PayloadLen
-= (WLAN_HDR_ADDR3_LEN
+ 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1162 *pdwRxTSC47_16
= cpu_to_le32(*(u32
*)(pbyIV
+ 4));
1163 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ExtIV: %x\n", *pdwRxTSC47_16
);
1165 if (byDecMode
== KEY_CTL_TKIP
) {
1166 *pwRxTSC15_0
= cpu_to_le16(MAKEWORD(*(pbyIV
+2), *pbyIV
));
1168 *pwRxTSC15_0
= cpu_to_le16(*(u16
*)pbyIV
);
1170 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"TSC0_15: %x\n", *pwRxTSC15_0
);
1172 if (byDecMode
== KEY_CTL_TKIP
) {
1174 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
) || (bOnFly
== false)) {
1178 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"soft KEY_CTL_TKIP \n");
1179 pMACHeader
= (struct ieee80211_hdr
*) (pbyFrame
);
1180 TKIPvMixKey(pKey
->abyKey
, pMACHeader
->addr2
, *pwRxTSC15_0
, *pdwRxTSC47_16
, pDevice
->abyPRNG
);
1181 rc4_init(&pDevice
->SBox
, pDevice
->abyPRNG
, TKIP_KEY_LEN
);
1182 rc4_encrypt(&pDevice
->SBox
, pbyIV
+8, pbyIV
+8, PayloadLen
);
1183 if (ETHbIsBufferCrc32Ok(pbyIV
+8, PayloadLen
)) {
1184 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1185 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV OK!\n");
1187 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ICV FAIL!!!\n");
1188 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PayloadLen = %d\n", PayloadLen
);
1193 if (byDecMode
== KEY_CTL_CCMP
) {
1194 if (bOnFly
== false) {
1197 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"soft KEY_CTL_CCMP\n");
1198 if (AESbGenCCMP(pKey
->abyKey
, pbyFrame
, FrameSize
)) {
1199 *pbyNewRsr
|= NEWRSR_DECRYPTOK
;
1200 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CCMP MIC compare OK!\n");
1202 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"CCMP MIC fail!\n");
1209 if ((*(pbyIV
+3) & 0x20) != 0)
1214 static int s_bAPModeRxData(struct vnt_private
*pDevice
, struct sk_buff
*skb
,
1215 u32 FrameSize
, u32 cbHeaderOffset
, s32 iSANodeIndex
, s32 iDANodeIndex
)
1217 struct sk_buff
*skbcpy
;
1218 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1219 int bRelayAndForward
= false;
1220 int bRelayOnly
= false;
1221 u8 byMask
[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1224 if (FrameSize
> CB_MAX_BUF_SIZE
)
1227 if (is_multicast_ether_addr((u8
*)(skb
->data
+cbHeaderOffset
))) {
1228 if (pMgmt
->sNodeDBTable
[0].bPSEnable
) {
1230 skbcpy
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
1232 // if any node in PS mode, buffer packet until DTIM.
1233 if (skbcpy
== NULL
) {
1234 DBG_PRT(MSG_LEVEL_NOTICE
, KERN_INFO
"relay multicast no skb available \n");
1237 skbcpy
->dev
= pDevice
->dev
;
1238 skbcpy
->len
= FrameSize
;
1239 memcpy(skbcpy
->data
, skb
->data
+cbHeaderOffset
, FrameSize
);
1240 skb_queue_tail(&(pMgmt
->sNodeDBTable
[0].sTxPSQueue
), skbcpy
);
1241 pMgmt
->sNodeDBTable
[0].wEnQueueCnt
++;
1243 pMgmt
->abyPSTxMap
[0] |= byMask
[0];
1247 bRelayAndForward
= true;
1252 if (BSSbIsSTAInNodeDB(pDevice
, (u8
*)(skb
->data
+cbHeaderOffset
), &iDANodeIndex
)) {
1253 if (pMgmt
->sNodeDBTable
[iDANodeIndex
].eNodeState
>= NODE_ASSOC
) {
1254 if (pMgmt
->sNodeDBTable
[iDANodeIndex
].bPSEnable
) {
1255 // queue this skb until next PS tx, and then release.
1257 skb
->data
+= cbHeaderOffset
;
1258 skb
->tail
+= cbHeaderOffset
;
1259 skb_put(skb
, FrameSize
);
1260 skb_queue_tail(&pMgmt
->sNodeDBTable
[iDANodeIndex
].sTxPSQueue
, skb
);
1262 pMgmt
->sNodeDBTable
[iDANodeIndex
].wEnQueueCnt
++;
1263 wAID
= pMgmt
->sNodeDBTable
[iDANodeIndex
].wAID
;
1264 pMgmt
->abyPSTxMap
[wAID
>> 3] |= byMask
[wAID
& 7];
1265 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n",
1266 iDANodeIndex
, (wAID
>> 3), pMgmt
->abyPSTxMap
[wAID
>> 3]);
1276 if (bRelayOnly
|| bRelayAndForward
) {
1277 // relay this packet right now
1278 if (bRelayAndForward
)
1281 if ((pDevice
->uAssocCount
> 1) && (iDANodeIndex
>= 0)) {
1282 bRelayPacketSend(pDevice
, (u8
*) (skb
->data
+ cbHeaderOffset
),
1283 FrameSize
, (unsigned int) iDANodeIndex
);
1289 // none associate, don't forward
1290 if (pDevice
->uAssocCount
== 0)
1296 void RXvWorkItem(struct work_struct
*work
)
1298 struct vnt_private
*pDevice
=
1299 container_of(work
, struct vnt_private
, read_work_item
);
1301 struct vnt_rcb
*pRCB
= NULL
;
1303 if (pDevice
->Flags
& fMP_DISCONNECTED
)
1306 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---->Rx Polling Thread\n");
1307 spin_lock_irq(&pDevice
->lock
);
1309 while ((pDevice
->Flags
& fMP_POST_READS
) &&
1310 MP_IS_READY(pDevice
) &&
1311 (pDevice
->NumRecvFreeList
!= 0) ) {
1312 pRCB
= pDevice
->FirstRecvFreeList
;
1313 pDevice
->NumRecvFreeList
--;
1314 DequeueRCB(pDevice
->FirstRecvFreeList
, pDevice
->LastRecvFreeList
);
1315 ntStatus
= PIPEnsBulkInUsbRead(pDevice
, pRCB
);
1317 pDevice
->bIsRxWorkItemQueued
= false;
1318 spin_unlock_irq(&pDevice
->lock
);
1322 void RXvFreeRCB(struct vnt_rcb
*pRCB
, int bReAllocSkb
)
1324 struct vnt_private
*pDevice
= pRCB
->pDevice
;
1326 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---->RXvFreeRCB\n");
1328 if (bReAllocSkb
== false) {
1329 kfree_skb(pRCB
->skb
);
1333 if (bReAllocSkb
== true) {
1334 pRCB
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
1335 // todo error handling
1336 if (pRCB
->skb
== NULL
) {
1337 DBG_PRT(MSG_LEVEL_ERR
,KERN_ERR
" Failed to re-alloc rx skb\n");
1339 pRCB
->skb
->dev
= pDevice
->dev
;
1343 // Insert the RCB back in the Recv free list
1345 EnqueueRCB(pDevice
->FirstRecvFreeList
, pDevice
->LastRecvFreeList
, pRCB
);
1346 pDevice
->NumRecvFreeList
++;
1348 if ((pDevice
->Flags
& fMP_POST_READS
) && MP_IS_READY(pDevice
) &&
1349 (pDevice
->bIsRxWorkItemQueued
== false) ) {
1351 pDevice
->bIsRxWorkItemQueued
= true;
1352 schedule_work(&pDevice
->read_work_item
);
1354 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"<----RXFreeRCB %d %d\n",pDevice
->NumRecvFreeList
, pDevice
->NumRecvMngList
);
1357 void RXvMngWorkItem(struct work_struct
*work
)
1359 struct vnt_private
*pDevice
=
1360 container_of(work
, struct vnt_private
, rx_mng_work_item
);
1361 struct vnt_rcb
*pRCB
= NULL
;
1362 struct vnt_rx_mgmt
*pRxPacket
;
1363 int bReAllocSkb
= false;
1365 if (pDevice
->Flags
& fMP_DISCONNECTED
)
1368 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"---->Rx Mng Thread\n");
1370 spin_lock_irq(&pDevice
->lock
);
1371 while (pDevice
->NumRecvMngList
!=0)
1373 pRCB
= pDevice
->FirstRecvMngList
;
1374 pDevice
->NumRecvMngList
--;
1375 DequeueRCB(pDevice
->FirstRecvMngList
, pDevice
->LastRecvMngList
);
1379 pRxPacket
= &(pRCB
->sMngPacket
);
1380 vMgrRxManagePacket(pDevice
, &pDevice
->vnt_mgmt
, pRxPacket
);
1382 if(pRCB
->Ref
== 0) {
1383 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"RxvFreeMng %d %d\n",pDevice
->NumRecvFreeList
, pDevice
->NumRecvMngList
);
1384 RXvFreeRCB(pRCB
, bReAllocSkb
);
1386 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Rx Mng Only we have the right to free RCB\n");
1390 pDevice
->bIsRxMngWorkItemQueued
= false;
1391 spin_unlock_irq(&pDevice
->lock
);