]> Pileus Git - ~andy/linux/blob - drivers/staging/vt6656/dpc.c
Merge branch 'kbuild/rc-fixes' into kbuild/kconfig
[~andy/linux] / drivers / staging / vt6656 / dpc.c
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
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.
9  *
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.
14  *
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.
18  *
19  * File: dpc.c
20  *
21  * Purpose: handle dpc rx functions
22  *
23  * Author: Lyndon Chen
24  *
25  * Date: May 20, 2003
26  *
27  * 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
36  *
37  * Revision History:
38  *
39  */
40
41 #include "device.h"
42 #include "rxtx.h"
43 #include "tether.h"
44 #include "card.h"
45 #include "bssdb.h"
46 #include "mac.h"
47 #include "baseband.h"
48 #include "michael.h"
49 #include "tkip.h"
50 #include "tcrc.h"
51 #include "wctl.h"
52 #include "hostap.h"
53 #include "rf.h"
54 #include "iowpa.h"
55 #include "aes_ccmp.h"
56 #include "datarate.h"
57 #include "usbpipe.h"
58
59 /*---------------------  Static Definitions -------------------------*/
60
61 /*---------------------  Static Classes  ----------------------------*/
62
63 /*---------------------  Static Variables  --------------------------*/
64 //static int          msglevel                =MSG_LEVEL_DEBUG;
65 static int          msglevel                =MSG_LEVEL_INFO;
66
67 const BYTE acbyRxRate[MAX_RATE] =
68 {2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108};
69
70
71 /*---------------------  Static Functions  --------------------------*/
72
73 /*---------------------  Static Definitions -------------------------*/
74
75 /*---------------------  Static Functions  --------------------------*/
76
77 static BYTE s_byGetRateIdx(BYTE byRate);
78
79 static
80 void
81 s_vGetDASA(
82       PBYTE pbyRxBufferAddr,
83      unsigned int *pcbHeaderSize,
84      PSEthernetHeader psEthHeader
85     );
86
87 static
88 void
89 s_vProcessRxMACHeader (
90       PSDevice pDevice,
91       PBYTE pbyRxBufferAddr,
92       unsigned int cbPacketSize,
93       BOOL bIsWEP,
94       BOOL bExtIV,
95      unsigned int *pcbHeadSize
96     );
97
98 static BOOL s_bAPModeRxCtl(
99      PSDevice pDevice,
100      PBYTE    pbyFrame,
101      signed int      iSANodeIndex
102     );
103
104
105
106 static BOOL s_bAPModeRxData (
107      PSDevice pDevice,
108      struct sk_buff *skb,
109      unsigned int     FrameSize,
110      unsigned int     cbHeaderOffset,
111      signed int      iSANodeIndex,
112      signed int      iDANodeIndex
113     );
114
115
116 static BOOL s_bHandleRxEncryption(
117      PSDevice     pDevice,
118      PBYTE        pbyFrame,
119      unsigned int         FrameSize,
120      PBYTE        pbyRsr,
121      PBYTE       pbyNewRsr,
122      PSKeyItem   * pKeyOut,
123     int *       pbExtIV,
124      PWORD       pwRxTSC15_0,
125      PDWORD      pdwRxTSC47_16
126     );
127
128 static BOOL s_bHostWepRxEncryption(
129
130      PSDevice     pDevice,
131      PBYTE        pbyFrame,
132      unsigned int         FrameSize,
133      PBYTE        pbyRsr,
134      BOOL         bOnFly,
135      PSKeyItem    pKey,
136      PBYTE       pbyNewRsr,
137     int *       pbExtIV,
138      PWORD       pwRxTSC15_0,
139      PDWORD      pdwRxTSC47_16
140
141     );
142
143 /*---------------------  Export Variables  --------------------------*/
144
145 /*+
146  *
147  * Description:
148  *    Translate Rcv 802.11 header to 802.3 header with Rx buffer
149  *
150  * Parameters:
151  *  In:
152  *      pDevice
153  *      dwRxBufferAddr  - Address of Rcv Buffer
154  *      cbPacketSize    - Rcv Packet size
155  *      bIsWEP          - If Rcv with WEP
156  *  Out:
157  *      pcbHeaderSize   - 802.11 header size
158  *
159  * Return Value: None
160  *
161 -*/
162 static
163 void
164 s_vProcessRxMACHeader (
165       PSDevice pDevice,
166       PBYTE pbyRxBufferAddr,
167       unsigned int cbPacketSize,
168       BOOL bIsWEP,
169       BOOL bExtIV,
170      unsigned int *pcbHeadSize
171     )
172 {
173     PBYTE           pbyRxBuffer;
174     unsigned int            cbHeaderSize = 0;
175     PWORD           pwType;
176     PS802_11Header  pMACHeader;
177     int             ii;
178
179
180     pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
181
182     s_vGetDASA((PBYTE)pMACHeader, &cbHeaderSize, &pDevice->sRxEthHeader);
183
184     if (bIsWEP) {
185         if (bExtIV) {
186             // strip IV&ExtIV , add 8 byte
187             cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 8);
188         } else {
189             // strip IV , add 4 byte
190             cbHeaderSize += (WLAN_HDR_ADDR3_LEN + 4);
191         }
192     }
193     else {
194         cbHeaderSize += WLAN_HDR_ADDR3_LEN;
195     };
196
197     pbyRxBuffer = (PBYTE) (pbyRxBufferAddr + cbHeaderSize);
198     if (!compare_ether_addr(pbyRxBuffer, &pDevice->abySNAP_Bridgetunnel[0])) {
199         cbHeaderSize += 6;
200     } else if (!compare_ether_addr(pbyRxBuffer, &pDevice->abySNAP_RFC1042[0])) {
201         cbHeaderSize += 6;
202         pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
203         if ((*pwType == cpu_to_be16(ETH_P_IPX)) ||
204             (*pwType == cpu_to_le16(0xF380))) {
205                 cbHeaderSize -= 8;
206             pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
207             if (bIsWEP) {
208                 if (bExtIV) {
209                     *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8);    // 8 is IV&ExtIV
210                 } else {
211                     *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4);    // 4 is IV
212                 }
213             }
214             else {
215                 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
216             }
217         }
218     }
219     else {
220         cbHeaderSize -= 2;
221         pwType = (PWORD) (pbyRxBufferAddr + cbHeaderSize);
222         if (bIsWEP) {
223             if (bExtIV) {
224                 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 8);    // 8 is IV&ExtIV
225             } else {
226                 *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN - 4);    // 4 is IV
227             }
228         }
229         else {
230             *pwType = htons(cbPacketSize - WLAN_HDR_ADDR3_LEN);
231         }
232     }
233
234     cbHeaderSize -= (ETH_ALEN * 2);
235     pbyRxBuffer = (PBYTE) (pbyRxBufferAddr + cbHeaderSize);
236     for (ii = 0; ii < ETH_ALEN; ii++)
237         *pbyRxBuffer++ = pDevice->sRxEthHeader.abyDstAddr[ii];
238     for (ii = 0; ii < ETH_ALEN; ii++)
239         *pbyRxBuffer++ = pDevice->sRxEthHeader.abySrcAddr[ii];
240
241     *pcbHeadSize = cbHeaderSize;
242 }
243
244
245
246
247 static BYTE s_byGetRateIdx(BYTE byRate)
248 {
249     BYTE    byRateIdx;
250
251     for (byRateIdx = 0; byRateIdx <MAX_RATE ; byRateIdx++) {
252         if (acbyRxRate[byRateIdx%MAX_RATE] == byRate)
253             return byRateIdx;
254     }
255     return 0;
256 }
257
258
259 static
260 void
261 s_vGetDASA (
262       PBYTE pbyRxBufferAddr,
263      unsigned int *pcbHeaderSize,
264      PSEthernetHeader psEthHeader
265     )
266 {
267         unsigned int            cbHeaderSize = 0;
268         PS802_11Header  pMACHeader;
269         int             ii;
270
271         pMACHeader = (PS802_11Header) (pbyRxBufferAddr + cbHeaderSize);
272
273         if ((pMACHeader->wFrameCtl & FC_TODS) == 0) {
274                 if (pMACHeader->wFrameCtl & FC_FROMDS) {
275                         for (ii = 0; ii < ETH_ALEN; ii++) {
276                                 psEthHeader->abyDstAddr[ii] =
277                                         pMACHeader->abyAddr1[ii];
278                                 psEthHeader->abySrcAddr[ii] =
279                                         pMACHeader->abyAddr3[ii];
280                         }
281                 } else {
282                         /* IBSS mode */
283                         for (ii = 0; ii < ETH_ALEN; ii++) {
284                                 psEthHeader->abyDstAddr[ii] =
285                                         pMACHeader->abyAddr1[ii];
286                                 psEthHeader->abySrcAddr[ii] =
287                                         pMACHeader->abyAddr2[ii];
288                         }
289                 }
290         } else {
291                 /* Is AP mode.. */
292                 if (pMACHeader->wFrameCtl & FC_FROMDS) {
293                         for (ii = 0; ii < ETH_ALEN; ii++) {
294                                 psEthHeader->abyDstAddr[ii] =
295                                         pMACHeader->abyAddr3[ii];
296                                 psEthHeader->abySrcAddr[ii] =
297                                         pMACHeader->abyAddr4[ii];
298                                 cbHeaderSize += 6;
299                         }
300                 } else {
301                         for (ii = 0; ii < ETH_ALEN; ii++) {
302                                 psEthHeader->abyDstAddr[ii] =
303                                         pMACHeader->abyAddr3[ii];
304                                 psEthHeader->abySrcAddr[ii] =
305                                         pMACHeader->abyAddr2[ii];
306                         }
307                 }
308         };
309     *pcbHeaderSize = cbHeaderSize;
310 }
311
312
313
314
315 BOOL
316 RXbBulkInProcessData (
317      PSDevice         pDevice,
318      PRCB             pRCB,
319      unsigned long            BytesToIndicate
320     )
321 {
322
323     struct net_device_stats* pStats=&pDevice->stats;
324     struct sk_buff* skb;
325     PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
326     PSRxMgmtPacket  pRxPacket = &(pMgmt->sRxPacket);
327     PS802_11Header  p802_11Header;
328     PBYTE           pbyRsr;
329     PBYTE           pbyNewRsr;
330     PBYTE           pbyRSSI;
331     PQWORD          pqwTSFTime;
332     PBYTE           pbyFrame;
333     BOOL            bDeFragRx = FALSE;
334     unsigned int            cbHeaderOffset;
335         u32 FrameSize;
336     WORD            wEtherType = 0;
337     signed int             iSANodeIndex = -1;
338     signed int             iDANodeIndex = -1;
339     unsigned int            ii;
340     unsigned int            cbIVOffset;
341     PBYTE           pbyRxSts;
342     PBYTE           pbyRxRate;
343     PBYTE           pbySQ;
344     PBYTE           pby3SQ;
345     unsigned int            cbHeaderSize;
346     PSKeyItem       pKey = NULL;
347     WORD            wRxTSC15_0 = 0;
348     DWORD           dwRxTSC47_16 = 0;
349     SKeyItem        STempKey;
350     // 802.11h RPI
351     /* signed long ldBm = 0; */
352     BOOL            bIsWEP = FALSE;
353     BOOL            bExtIV = FALSE;
354         u32 dwWbkStatus;
355     PRCB            pRCBIndicate = pRCB;
356     PBYTE           pbyDAddress;
357     PWORD           pwPLCP_Length;
358     BYTE            abyVaildRate[MAX_RATE] = {2,4,11,22,12,18,24,36,48,72,96,108};
359     WORD            wPLCPwithPadding;
360     PS802_11Header  pMACHeader;
361     BOOL            bRxeapol_key = FALSE;
362
363
364
365     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---------- RXbBulkInProcessData---\n");
366
367     skb = pRCB->skb;
368
369         /* [31:16]RcvByteCount ( not include 4-byte Status ) */
370         dwWbkStatus = *((u32 *)(skb->data));
371         FrameSize = dwWbkStatus >> 16;
372         FrameSize += 4;
373
374         if (BytesToIndicate != FrameSize) {
375                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"------- WRONG Length 1\n");
376                 return FALSE;
377         }
378
379     if ((BytesToIndicate > 2372) || (BytesToIndicate <= 40)) {
380         // Frame Size error drop this packet.
381         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---------- WRONG Length 2\n");
382         return FALSE;
383     }
384
385     pbyDAddress = (PBYTE)(skb->data);
386     pbyRxSts = pbyDAddress+4;
387     pbyRxRate = pbyDAddress+5;
388
389     //real Frame Size = USBFrameSize -4WbkStatus - 4RxStatus - 8TSF - 4RSR - 4SQ3 - ?Padding
390     //if SQ3 the range is 24~27, if no SQ3 the range is 20~23
391     //real Frame size in PLCPLength field.
392     pwPLCP_Length = (PWORD) (pbyDAddress + 6);
393     //Fix hardware bug => PLCP_Length error
394     if ( ((BytesToIndicate - (*pwPLCP_Length)) > 27) ||
395          ((BytesToIndicate - (*pwPLCP_Length)) < 24) ||
396          (BytesToIndicate < (*pwPLCP_Length)) ) {
397
398         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Wrong PLCP Length %x\n", (int) *pwPLCP_Length);
399         ASSERT(0);
400         return FALSE;
401     }
402     for ( ii=RATE_1M;ii<MAX_RATE;ii++) {
403         if ( *pbyRxRate == abyVaildRate[ii] ) {
404             break;
405         }
406     }
407     if ( ii==MAX_RATE ) {
408         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Wrong RxRate %x\n",(int) *pbyRxRate);
409         return FALSE;
410     }
411
412     wPLCPwithPadding = ( (*pwPLCP_Length / 4) + ( (*pwPLCP_Length % 4) ? 1:0 ) ) *4;
413
414     pqwTSFTime = (PQWORD) (pbyDAddress + 8 + wPLCPwithPadding);
415   if(pDevice->byBBType == BB_TYPE_11G)  {
416       pby3SQ = pbyDAddress + 8 + wPLCPwithPadding + 12;
417       pbySQ = pby3SQ;
418     }
419   else {
420    pbySQ = pbyDAddress + 8 + wPLCPwithPadding + 8;
421    pby3SQ = pbySQ;
422   }
423     pbyNewRsr = pbyDAddress + 8 + wPLCPwithPadding + 9;
424     pbyRSSI = pbyDAddress + 8 + wPLCPwithPadding + 10;
425     pbyRsr = pbyDAddress + 8 + wPLCPwithPadding + 11;
426
427     FrameSize = *pwPLCP_Length;
428
429     pbyFrame = pbyDAddress + 8;
430     // update receive statistic counter
431
432     STAvUpdateRDStatCounter(&pDevice->scStatistic,
433                             *pbyRsr,
434                             *pbyNewRsr,
435                             *pbyRxSts,
436                             *pbyRxRate,
437                             pbyFrame,
438                             FrameSize
439                             );
440
441
442     pMACHeader = (PS802_11Header) pbyFrame;
443
444 //mike add: to judge if current AP is activated?
445     if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
446         (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
447        if (pMgmt->sNodeDBTable[0].bActive) {
448          if (!compare_ether_addr(pMgmt->abyCurrBSSID, pMACHeader->abyAddr2)) {
449             if (pMgmt->sNodeDBTable[0].uInActiveCount != 0)
450                   pMgmt->sNodeDBTable[0].uInActiveCount = 0;
451            }
452        }
453     }
454
455     if (!is_multicast_ether_addr(pMACHeader->abyAddr1)) {
456         if ( WCTLbIsDuplicate(&(pDevice->sDupRxCache), (PS802_11Header) pbyFrame) ) {
457             pDevice->s802_11Counter.FrameDuplicateCount++;
458             return FALSE;
459         }
460
461         if (compare_ether_addr(pDevice->abyCurrentNetAddr,
462                                pMACHeader->abyAddr1)) {
463                 return FALSE;
464         }
465     }
466
467
468     // Use for TKIP MIC
469     s_vGetDASA(pbyFrame, &cbHeaderSize, &pDevice->sRxEthHeader);
470
471     if (!compare_ether_addr((PBYTE)&(pDevice->sRxEthHeader.abySrcAddr[0]),
472                             pDevice->abyCurrentNetAddr))
473         return FALSE;
474
475     if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
476         if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
477             p802_11Header = (PS802_11Header) (pbyFrame);
478             // get SA NodeIndex
479             if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(p802_11Header->abyAddr2), &iSANodeIndex)) {
480                 pMgmt->sNodeDBTable[iSANodeIndex].ulLastRxJiffer = jiffies;
481                 pMgmt->sNodeDBTable[iSANodeIndex].uInActiveCount = 0;
482             }
483         }
484     }
485
486     if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
487         if (s_bAPModeRxCtl(pDevice, pbyFrame, iSANodeIndex) == TRUE) {
488             return FALSE;
489         }
490     }
491
492
493     if (IS_FC_WEP(pbyFrame)) {
494         BOOL     bRxDecryOK = FALSE;
495
496         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"rx WEP pkt\n");
497         bIsWEP = TRUE;
498         if ((pDevice->bEnableHostWEP) && (iSANodeIndex >= 0)) {
499             pKey = &STempKey;
500             pKey->byCipherSuite = pMgmt->sNodeDBTable[iSANodeIndex].byCipherSuite;
501             pKey->dwKeyIndex = pMgmt->sNodeDBTable[iSANodeIndex].dwKeyIndex;
502             pKey->uKeyLength = pMgmt->sNodeDBTable[iSANodeIndex].uWepKeyLength;
503             pKey->dwTSC47_16 = pMgmt->sNodeDBTable[iSANodeIndex].dwTSC47_16;
504             pKey->wTSC15_0 = pMgmt->sNodeDBTable[iSANodeIndex].wTSC15_0;
505             memcpy(pKey->abyKey,
506                 &pMgmt->sNodeDBTable[iSANodeIndex].abyWepKey[0],
507                 pKey->uKeyLength
508                 );
509
510             bRxDecryOK = s_bHostWepRxEncryption(pDevice,
511                                                 pbyFrame,
512                                                 FrameSize,
513                                                 pbyRsr,
514                                                 pMgmt->sNodeDBTable[iSANodeIndex].bOnFly,
515                                                 pKey,
516                                                 pbyNewRsr,
517                                                 &bExtIV,
518                                                 &wRxTSC15_0,
519                                                 &dwRxTSC47_16);
520         } else {
521             bRxDecryOK = s_bHandleRxEncryption(pDevice,
522                                                 pbyFrame,
523                                                 FrameSize,
524                                                 pbyRsr,
525                                                 pbyNewRsr,
526                                                 &pKey,
527                                                 &bExtIV,
528                                                 &wRxTSC15_0,
529                                                 &dwRxTSC47_16);
530         }
531
532         if (bRxDecryOK) {
533             if ((*pbyNewRsr & NEWRSR_DECRYPTOK) == 0) {
534                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV Fail\n");
535                 if ( (pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
536                     (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
537                     (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
538                     (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
539                     (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
540
541                     if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
542                         pDevice->s802_11Counter.TKIPICVErrors++;
543                     } else if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP)) {
544                         pDevice->s802_11Counter.CCMPDecryptErrors++;
545                     } else if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_WEP)) {
546 //                      pDevice->s802_11Counter.WEPICVErrorCount.QuadPart++;
547                     }
548                 }
549                 return FALSE;
550             }
551         } else {
552             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"WEP Func Fail\n");
553             return FALSE;
554         }
555         if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP))
556             FrameSize -= 8;         // Message Integrity Code
557         else
558             FrameSize -= 4;         // 4 is ICV
559     }
560
561
562     //
563     // RX OK
564     //
565     /* remove the FCS/CRC length */
566     FrameSize -= ETH_FCS_LEN;
567
568     if ( !(*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) && // unicast address
569         (IS_FRAGMENT_PKT((pbyFrame)))
570         ) {
571         // defragment
572         bDeFragRx = WCTLbHandleFragment(pDevice, (PS802_11Header) (pbyFrame), FrameSize, bIsWEP, bExtIV);
573         pDevice->s802_11Counter.ReceivedFragmentCount++;
574         if (bDeFragRx) {
575             // defrag complete
576             // TODO skb, pbyFrame
577             skb = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb;
578             FrameSize = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength;
579             pbyFrame = skb->data + 8;
580         }
581         else {
582             return FALSE;
583         }
584     }
585
586     //
587     // Management & Control frame Handle
588     //
589     if ((IS_TYPE_DATA((pbyFrame))) == FALSE) {
590         // Handle Control & Manage Frame
591
592         if (IS_TYPE_MGMT((pbyFrame))) {
593             PBYTE pbyData1;
594             PBYTE pbyData2;
595
596             pRxPacket = &(pRCB->sMngPacket);
597             pRxPacket->p80211Header = (PUWLAN_80211HDR)(pbyFrame);
598             pRxPacket->cbMPDULen = FrameSize;
599             pRxPacket->uRSSI = *pbyRSSI;
600             pRxPacket->bySQ = *pbySQ;
601             HIDWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(HIDWORD(*pqwTSFTime));
602             LODWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(LODWORD(*pqwTSFTime));
603             if (bIsWEP) {
604                 // strip IV
605                 pbyData1 = WLAN_HDR_A3_DATA_PTR(pbyFrame);
606                 pbyData2 = WLAN_HDR_A3_DATA_PTR(pbyFrame) + 4;
607                 for (ii = 0; ii < (FrameSize - 4); ii++) {
608                     *pbyData1 = *pbyData2;
609                      pbyData1++;
610                      pbyData2++;
611                 }
612             }
613
614             pRxPacket->byRxRate = s_byGetRateIdx(*pbyRxRate);
615
616             if ( *pbyRxSts == 0 ) {
617                 //Discard beacon packet which channel is 0
618                 if ( (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) == WLAN_FSTYPE_BEACON) ||
619                      (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) == WLAN_FSTYPE_PROBERESP) ) {
620                         return FALSE;
621                 }
622             }
623             pRxPacket->byRxChannel = (*pbyRxSts) >> 2;
624
625             // hostap Deamon handle 802.11 management
626             if (pDevice->bEnableHostapd) {
627                     skb->dev = pDevice->apdev;
628                     //skb->data += 4;
629                     //skb->tail += 4;
630                     skb->data += 8;
631                     skb->tail += 8;
632                 skb_put(skb, FrameSize);
633                 skb_reset_mac_header(skb);
634                     skb->pkt_type = PACKET_OTHERHOST;
635                 skb->protocol = htons(ETH_P_802_2);
636                     memset(skb->cb, 0, sizeof(skb->cb));
637                     netif_rx(skb);
638                 return TRUE;
639                 }
640
641             //
642             // Insert the RCB in the Recv Mng list
643             //
644             EnqueueRCB(pDevice->FirstRecvMngList, pDevice->LastRecvMngList, pRCBIndicate);
645             pDevice->NumRecvMngList++;
646             if ( bDeFragRx == FALSE) {
647                 pRCB->Ref++;
648             }
649             if (pDevice->bIsRxMngWorkItemQueued == FALSE) {
650                 pDevice->bIsRxMngWorkItemQueued = TRUE;
651                 tasklet_schedule(&pDevice->RxMngWorkItem);
652             }
653
654         }
655         else {
656             // Control Frame
657         };
658         return FALSE;
659     }
660     else {
661         if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
662             //In AP mode, hw only check addr1(BSSID or RA) if equal to local MAC.
663             if ( !(*pbyRsr & RSR_BSSIDOK)) {
664                 if (bDeFragRx) {
665                     if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
666                         DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
667                         pDevice->dev->name);
668                     }
669                 }
670                 return FALSE;
671             }
672         }
673         else {
674             // discard DATA packet while not associate || BSSID error
675             if ((pDevice->bLinkPass == FALSE) ||
676                 !(*pbyRsr & RSR_BSSIDOK)) {
677                 if (bDeFragRx) {
678                     if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
679                         DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
680                         pDevice->dev->name);
681                     }
682                 }
683                 return FALSE;
684             }
685    //mike add:station mode check eapol-key challenge--->
686           {
687             BYTE  Protocol_Version;    //802.1x Authentication
688             BYTE  Packet_Type;           //802.1x Authentication
689             BYTE  Descriptor_type;
690              WORD Key_info;
691               if (bIsWEP)
692                   cbIVOffset = 8;
693               else
694                   cbIVOffset = 0;
695               wEtherType = (skb->data[cbIVOffset + 8 + 24 + 6] << 8) |
696                           skb->data[cbIVOffset + 8 + 24 + 6 + 1];
697               Protocol_Version = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1];
698               Packet_Type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1];
699              if (wEtherType == ETH_P_PAE) {         //Protocol Type in LLC-Header
700                   if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
701                      (Packet_Type==3)) {  //802.1x OR eapol-key challenge frame receive
702                         bRxeapol_key = TRUE;
703                       Descriptor_type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2];
704                       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] ;
705                       if(Descriptor_type==2) {    //RSN
706                          //  printk("WPA2_Rx_eapol-key_info<-----:%x\n",Key_info);
707                       }
708                      else  if(Descriptor_type==254) {
709                         //  printk("WPA_Rx_eapol-key_info<-----:%x\n",Key_info);
710                      }
711                   }
712               }
713           }
714     //mike add:station mode check eapol-key challenge<---
715         }
716     }
717
718
719 // Data frame Handle
720
721
722     if (pDevice->bEnablePSMode) {
723         if (IS_FC_MOREDATA((pbyFrame))) {
724             if (*pbyRsr & RSR_ADDROK) {
725                 //PSbSendPSPOLL((PSDevice)pDevice);
726             }
727         }
728         else {
729             if (pMgmt->bInTIMWake == TRUE) {
730                 pMgmt->bInTIMWake = FALSE;
731             }
732         }
733     }
734
735     // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps
736     if (pDevice->bDiversityEnable && (FrameSize>50) &&
737        (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
738        (pDevice->bLinkPass == TRUE)) {
739         BBvAntennaDiversity(pDevice, s_byGetRateIdx(*pbyRxRate), 0);
740     }
741
742     // ++++++++ For BaseBand Algorithm +++++++++++++++
743     pDevice->uCurrRSSI = *pbyRSSI;
744     pDevice->byCurrSQ = *pbySQ;
745
746     // todo
747 /*
748     if ((*pbyRSSI != 0) &&
749         (pMgmt->pCurrBSS!=NULL)) {
750         RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
751         // Monitor if RSSI is too strong.
752         pMgmt->pCurrBSS->byRSSIStatCnt++;
753         pMgmt->pCurrBSS->byRSSIStatCnt %= RSSI_STAT_COUNT;
754         pMgmt->pCurrBSS->ldBmAverage[pMgmt->pCurrBSS->byRSSIStatCnt] = ldBm;
755         for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
756                 if (pMgmt->pCurrBSS->ldBmAverage[ii] != 0) {
757                         pMgmt->pCurrBSS->ldBmMAX =
758                                 max(pMgmt->pCurrBSS->ldBmAverage[ii], ldBm);
759                 }
760         }
761     }
762 */
763
764
765     // -----------------------------------------------
766
767     if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnable8021x == TRUE)){
768         BYTE    abyMacHdr[24];
769
770         // Only 802.1x packet incoming allowed
771         if (bIsWEP)
772             cbIVOffset = 8;
773         else
774             cbIVOffset = 0;
775         wEtherType = (skb->data[cbIVOffset + 8 + 24 + 6] << 8) |
776                     skb->data[cbIVOffset + 8 + 24 + 6 + 1];
777
778             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wEtherType = %04x \n", wEtherType);
779         if (wEtherType == ETH_P_PAE) {
780             skb->dev = pDevice->apdev;
781
782             if (bIsWEP == TRUE) {
783                 // strip IV header(8)
784                 memcpy(&abyMacHdr[0], (skb->data + 8), 24);
785                 memcpy((skb->data + 8 + cbIVOffset), &abyMacHdr[0], 24);
786             }
787
788             skb->data +=  (cbIVOffset + 8);
789             skb->tail +=  (cbIVOffset + 8);
790             skb_put(skb, FrameSize);
791             skb_reset_mac_header(skb);
792             skb->pkt_type = PACKET_OTHERHOST;
793             skb->protocol = htons(ETH_P_802_2);
794             memset(skb->cb, 0, sizeof(skb->cb));
795             netif_rx(skb);
796             return TRUE;
797
798         }
799         // check if 802.1x authorized
800         if (!(pMgmt->sNodeDBTable[iSANodeIndex].dwFlags & WLAN_STA_AUTHORIZED))
801             return FALSE;
802     }
803
804
805     if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
806         if (bIsWEP) {
807             FrameSize -= 8;  //MIC
808         }
809     }
810
811     //--------------------------------------------------------------------------------
812     // Soft MIC
813     if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
814         if (bIsWEP) {
815             PDWORD          pdwMIC_L;
816             PDWORD          pdwMIC_R;
817             DWORD           dwMIC_Priority;
818             DWORD           dwMICKey0 = 0, dwMICKey1 = 0;
819             DWORD           dwLocalMIC_L = 0;
820             DWORD           dwLocalMIC_R = 0;
821
822
823             if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
824                 dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[24]));
825                 dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[28]));
826             }
827             else {
828                 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
829                     dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[16]));
830                     dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[20]));
831                 } else if ((pKey->dwKeyIndex & BIT28) == 0) {
832                     dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[16]));
833                     dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[20]));
834                 } else {
835                     dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[24]));
836                     dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[28]));
837                 }
838             }
839
840             MIC_vInit(dwMICKey0, dwMICKey1);
841             MIC_vAppend((PBYTE)&(pDevice->sRxEthHeader.abyDstAddr[0]), 12);
842             dwMIC_Priority = 0;
843             MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
844             // 4 is Rcv buffer header, 24 is MAC Header, and 8 is IV and Ext IV.
845             MIC_vAppend((PBYTE)(skb->data + 8 + WLAN_HDR_ADDR3_LEN + 8),
846                         FrameSize - WLAN_HDR_ADDR3_LEN - 8);
847             MIC_vGetMIC(&dwLocalMIC_L, &dwLocalMIC_R);
848             MIC_vUnInit();
849
850             pdwMIC_L = (PDWORD)(skb->data + 8 + FrameSize);
851             pdwMIC_R = (PDWORD)(skb->data + 8 + FrameSize + 4);
852
853
854             if ((cpu_to_le32(*pdwMIC_L) != dwLocalMIC_L) || (cpu_to_le32(*pdwMIC_R) != dwLocalMIC_R) ||
855                 (pDevice->bRxMICFail == TRUE)) {
856                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC comparison is fail!\n");
857                 pDevice->bRxMICFail = FALSE;
858                 //pDevice->s802_11Counter.TKIPLocalMICFailures.QuadPart++;
859                 pDevice->s802_11Counter.TKIPLocalMICFailures++;
860                 if (bDeFragRx) {
861                     if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
862                         DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
863                             pDevice->dev->name);
864                     }
865                 }
866                                 //send event to wpa_supplicant
867                                 //if(pDevice->bWPASuppWextEnabled == TRUE)
868                                 {
869                                         union iwreq_data wrqu;
870                                         struct iw_michaelmicfailure ev;
871                                         int keyidx = pbyFrame[cbHeaderSize+3] >> 6; //top two-bits
872                                         memset(&ev, 0, sizeof(ev));
873                                         ev.flags = keyidx & IW_MICFAILURE_KEY_ID;
874                                         if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
875                                                         (pMgmt->eCurrState == WMAC_STATE_ASSOC) &&
876                                                                 (*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) {
877                                                 ev.flags |= IW_MICFAILURE_PAIRWISE;
878                                         } else {
879                                                 ev.flags |= IW_MICFAILURE_GROUP;
880                                         }
881
882                                         ev.src_addr.sa_family = ARPHRD_ETHER;
883                                         memcpy(ev.src_addr.sa_data, pMACHeader->abyAddr2, ETH_ALEN);
884                                         memset(&wrqu, 0, sizeof(wrqu));
885                                         wrqu.data.length = sizeof(ev);
886                         PRINT_K("wireless_send_event--->IWEVMICHAELMICFAILURE\n");
887                                         wireless_send_event(pDevice->dev, IWEVMICHAELMICFAILURE, &wrqu, (char *)&ev);
888
889                                 }
890
891                 return FALSE;
892
893             }
894         }
895     } //---end of SOFT MIC-----------------------------------------------------------------------
896
897     // ++++++++++ Reply Counter Check +++++++++++++
898
899     if ((pKey != NULL) && ((pKey->byCipherSuite == KEY_CTL_TKIP) ||
900                            (pKey->byCipherSuite == KEY_CTL_CCMP))) {
901         if (bIsWEP) {
902             WORD        wLocalTSC15_0 = 0;
903             DWORD       dwLocalTSC47_16 = 0;
904             unsigned long long       RSC = 0;
905             // endian issues
906             RSC = *((unsigned long long *) &(pKey->KeyRSC));
907             wLocalTSC15_0 = (WORD) RSC;
908             dwLocalTSC47_16 = (DWORD) (RSC>>16);
909
910             RSC = dwRxTSC47_16;
911             RSC <<= 16;
912             RSC += wRxTSC15_0;
913             memcpy(&(pKey->KeyRSC), &RSC,  sizeof(QWORD));
914
915             if ( (pDevice->sMgmtObj.eCurrMode == WMAC_MODE_ESS_STA) &&
916                  (pDevice->sMgmtObj.eCurrState == WMAC_STATE_ASSOC)) {
917                 // check RSC
918                 if ( (wRxTSC15_0 < wLocalTSC15_0) &&
919                      (dwRxTSC47_16 <= dwLocalTSC47_16) &&
920                      !((dwRxTSC47_16 == 0) && (dwLocalTSC47_16 == 0xFFFFFFFF))) {
921                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC is illegal~~!\n ");
922                     if (pKey->byCipherSuite == KEY_CTL_TKIP)
923                         //pDevice->s802_11Counter.TKIPReplays.QuadPart++;
924                         pDevice->s802_11Counter.TKIPReplays++;
925                     else
926                         //pDevice->s802_11Counter.CCMPReplays.QuadPart++;
927                         pDevice->s802_11Counter.CCMPReplays++;
928
929                     if (bDeFragRx) {
930                         if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
931                             DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
932                                 pDevice->dev->name);
933                         }
934                     }
935                     return FALSE;
936                 }
937             }
938         }
939     } // ----- End of Reply Counter Check --------------------------
940
941
942     s_vProcessRxMACHeader(pDevice, (PBYTE)(skb->data+8), FrameSize, bIsWEP, bExtIV, &cbHeaderOffset);
943     FrameSize -= cbHeaderOffset;
944     cbHeaderOffset += 8;        // 8 is Rcv buffer header
945
946     // Null data, framesize = 12
947     if (FrameSize < 12)
948         return FALSE;
949
950     if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
951         if (s_bAPModeRxData(pDevice,
952                             skb,
953                             FrameSize,
954                             cbHeaderOffset,
955                             iSANodeIndex,
956                             iDANodeIndex
957                             ) == FALSE) {
958
959             if (bDeFragRx) {
960                 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
961                     DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
962                     pDevice->dev->name);
963                 }
964             }
965             return FALSE;
966         }
967
968     }
969
970         skb->data += cbHeaderOffset;
971         skb->tail += cbHeaderOffset;
972     skb_put(skb, FrameSize);
973     skb->protocol=eth_type_trans(skb, skb->dev);
974     skb->ip_summed=CHECKSUM_NONE;
975     pStats->rx_bytes +=skb->len;
976     pStats->rx_packets++;
977     netif_rx(skb);
978     if (bDeFragRx) {
979         if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
980             DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
981                 pDevice->dev->name);
982         }
983         return FALSE;
984     }
985
986     return TRUE;
987 }
988
989
990 static BOOL s_bAPModeRxCtl (
991      PSDevice pDevice,
992      PBYTE    pbyFrame,
993      signed int      iSANodeIndex
994     )
995 {
996     PS802_11Header      p802_11Header;
997     CMD_STATUS          Status;
998     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
999
1000
1001     if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
1002
1003         p802_11Header = (PS802_11Header) (pbyFrame);
1004         if (!IS_TYPE_MGMT(pbyFrame)) {
1005
1006             // Data & PS-Poll packet
1007             // check frame class
1008             if (iSANodeIndex > 0) {
1009                 // frame class 3 fliter & checking
1010                 if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_AUTH) {
1011                     // send deauth notification
1012                     // reason = (6) class 2 received from nonauth sta
1013                     vMgrDeAuthenBeginSta(pDevice,
1014                                          pMgmt,
1015                                          (PBYTE)(p802_11Header->abyAddr2),
1016                                          (WLAN_MGMT_REASON_CLASS2_NONAUTH),
1017                                          &Status
1018                                          );
1019                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 1\n");
1020                     return TRUE;
1021                 }
1022                 if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_ASSOC) {
1023                     // send deassoc notification
1024                     // reason = (7) class 3 received from nonassoc sta
1025                     vMgrDisassocBeginSta(pDevice,
1026                                          pMgmt,
1027                                          (PBYTE)(p802_11Header->abyAddr2),
1028                                          (WLAN_MGMT_REASON_CLASS3_NONASSOC),
1029                                          &Status
1030                                          );
1031                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDisassocBeginSta 2\n");
1032                     return TRUE;
1033                 }
1034
1035                 if (pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable) {
1036                     // delcare received ps-poll event
1037                     if (IS_CTL_PSPOLL(pbyFrame)) {
1038                         pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE;
1039                         bScheduleCommand((void *) pDevice,
1040                                          WLAN_CMD_RX_PSPOLL,
1041                                          NULL);
1042                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 1\n");
1043                     }
1044                     else {
1045                         // check Data PS state
1046                         // if PW bit off, send out all PS bufferring packets.
1047                         if (!IS_FC_POWERMGT(pbyFrame)) {
1048                             pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = FALSE;
1049                             pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE;
1050                                 bScheduleCommand((void *) pDevice,
1051                                                  WLAN_CMD_RX_PSPOLL,
1052                                                  NULL);
1053                             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 2\n");
1054                         }
1055                     }
1056                 }
1057                 else {
1058                    if (IS_FC_POWERMGT(pbyFrame)) {
1059                        pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = TRUE;
1060                        // Once if STA in PS state, enable multicast bufferring
1061                        pMgmt->sNodeDBTable[0].bPSEnable = TRUE;
1062                    }
1063                    else {
1064                       // clear all pending PS frame.
1065                       if (pMgmt->sNodeDBTable[iSANodeIndex].wEnQueueCnt > 0) {
1066                           pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = FALSE;
1067                           pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE;
1068                         bScheduleCommand((void *) pDevice,
1069                                          WLAN_CMD_RX_PSPOLL,
1070                                          NULL);
1071                          DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 3\n");
1072
1073                       }
1074                    }
1075                 }
1076             }
1077             else {
1078                   vMgrDeAuthenBeginSta(pDevice,
1079                                        pMgmt,
1080                                        (PBYTE)(p802_11Header->abyAddr2),
1081                                        (WLAN_MGMT_REASON_CLASS2_NONAUTH),
1082                                        &Status
1083                                        );
1084                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 3\n");
1085                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSID:%pM\n",
1086                                 p802_11Header->abyAddr3);
1087                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR2:%pM\n",
1088                                 p802_11Header->abyAddr2);
1089                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR1:%pM\n",
1090                                 p802_11Header->abyAddr1);
1091                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: wFrameCtl= %x\n", p802_11Header->wFrameCtl );
1092                     return TRUE;
1093             }
1094         }
1095     }
1096     return FALSE;
1097
1098 }
1099
1100 static BOOL s_bHandleRxEncryption (
1101      PSDevice     pDevice,
1102      PBYTE        pbyFrame,
1103      unsigned int         FrameSize,
1104      PBYTE        pbyRsr,
1105      PBYTE       pbyNewRsr,
1106      PSKeyItem   * pKeyOut,
1107     int *       pbExtIV,
1108      PWORD       pwRxTSC15_0,
1109      PDWORD      pdwRxTSC47_16
1110     )
1111 {
1112     unsigned int            PayloadLen = FrameSize;
1113     PBYTE           pbyIV;
1114     BYTE            byKeyIdx;
1115     PSKeyItem       pKey = NULL;
1116     BYTE            byDecMode = KEY_CTL_WEP;
1117     PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
1118
1119
1120     *pwRxTSC15_0 = 0;
1121     *pdwRxTSC47_16 = 0;
1122
1123     pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
1124     if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) &&
1125          WLAN_GET_FC_FROMDS(*(PWORD)pbyFrame) ) {
1126          pbyIV += 6;             // 6 is 802.11 address4
1127          PayloadLen -= 6;
1128     }
1129     byKeyIdx = (*(pbyIV+3) & 0xc0);
1130     byKeyIdx >>= 6;
1131     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\nKeyIdx: %d\n", byKeyIdx);
1132
1133     if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
1134         (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
1135         (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
1136         (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
1137         (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
1138         if (((*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) &&
1139             (pMgmt->byCSSPK != KEY_CTL_NONE)) {
1140             // unicast pkt use pairwise key
1141             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"unicast pkt\n");
1142             if (KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, 0xFFFFFFFF, &pKey) == TRUE) {
1143                 if (pMgmt->byCSSPK == KEY_CTL_TKIP)
1144                     byDecMode = KEY_CTL_TKIP;
1145                 else if (pMgmt->byCSSPK == KEY_CTL_CCMP)
1146                     byDecMode = KEY_CTL_CCMP;
1147             }
1148             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"unicast pkt: %d, %p\n", byDecMode, pKey);
1149         } else {
1150             // use group key
1151             KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, byKeyIdx, &pKey);
1152             if (pMgmt->byCSSGK == KEY_CTL_TKIP)
1153                 byDecMode = KEY_CTL_TKIP;
1154             else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
1155                 byDecMode = KEY_CTL_CCMP;
1156             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"group pkt: %d, %d, %p\n", byKeyIdx, byDecMode, pKey);
1157         }
1158     }
1159     // our WEP only support Default Key
1160     if (pKey == NULL) {
1161         // use default group key
1162         KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, byKeyIdx, &pKey);
1163         if (pMgmt->byCSSGK == KEY_CTL_TKIP)
1164             byDecMode = KEY_CTL_TKIP;
1165         else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
1166             byDecMode = KEY_CTL_CCMP;
1167     }
1168     *pKeyOut = pKey;
1169
1170     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"AES:%d %d %d\n", pMgmt->byCSSPK, pMgmt->byCSSGK, byDecMode);
1171
1172     if (pKey == NULL) {
1173         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey == NULL\n");
1174         if (byDecMode == KEY_CTL_WEP) {
1175 //            pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1176         } else if (pDevice->bLinkPass == TRUE) {
1177 //            pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1178         }
1179         return FALSE;
1180     }
1181     if (byDecMode != pKey->byCipherSuite) {
1182         if (byDecMode == KEY_CTL_WEP) {
1183 //            pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1184         } else if (pDevice->bLinkPass == TRUE) {
1185 //            pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1186         }
1187         *pKeyOut = NULL;
1188         return FALSE;
1189     }
1190     if (byDecMode == KEY_CTL_WEP) {
1191         // handle WEP
1192         if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
1193                 (((PSKeyTable)(&pKey->pvKeyTable))->bSoftWEP == TRUE)) {
1194             // Software WEP
1195             // 1. 3253A
1196             // 2. WEP 256
1197
1198             PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1199             memcpy(pDevice->abyPRNG, pbyIV, 3);
1200             memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
1201             rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
1202             rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
1203
1204             if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen)) {
1205                 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1206             }
1207         }
1208     } else if ((byDecMode == KEY_CTL_TKIP) ||
1209                (byDecMode == KEY_CTL_CCMP)) {
1210         // TKIP/AES
1211
1212         PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1213         *pdwRxTSC47_16 = cpu_to_le32(*(PDWORD)(pbyIV + 4));
1214         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ExtIV: %x\n", *pdwRxTSC47_16);
1215         if (byDecMode == KEY_CTL_TKIP) {
1216             *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
1217         } else {
1218             *pwRxTSC15_0 = cpu_to_le16(*(PWORD)pbyIV);
1219         }
1220         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC0_15: %x\n", *pwRxTSC15_0);
1221
1222         if ((byDecMode == KEY_CTL_TKIP) &&
1223             (pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1224             // Software TKIP
1225             // 1. 3253 A
1226             PS802_11Header  pMACHeader = (PS802_11Header) (pbyFrame);
1227             TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
1228             rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
1229             rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
1230             if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
1231                 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1232                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV OK!\n");
1233             } else {
1234                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV FAIL!!!\n");
1235                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PayloadLen = %d\n", PayloadLen);
1236             }
1237         }
1238     }// end of TKIP/AES
1239
1240     if ((*(pbyIV+3) & 0x20) != 0)
1241         *pbExtIV = TRUE;
1242     return TRUE;
1243 }
1244
1245
1246 static BOOL s_bHostWepRxEncryption (
1247      PSDevice     pDevice,
1248      PBYTE        pbyFrame,
1249      unsigned int         FrameSize,
1250      PBYTE        pbyRsr,
1251      BOOL         bOnFly,
1252      PSKeyItem    pKey,
1253      PBYTE       pbyNewRsr,
1254     int *       pbExtIV,
1255      PWORD       pwRxTSC15_0,
1256      PDWORD      pdwRxTSC47_16
1257     )
1258 {
1259     PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
1260     unsigned int            PayloadLen = FrameSize;
1261     PBYTE           pbyIV;
1262     BYTE            byKeyIdx;
1263     BYTE            byDecMode = KEY_CTL_WEP;
1264     PS802_11Header  pMACHeader;
1265
1266
1267
1268     *pwRxTSC15_0 = 0;
1269     *pdwRxTSC47_16 = 0;
1270
1271     pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
1272     if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) &&
1273          WLAN_GET_FC_FROMDS(*(PWORD)pbyFrame) ) {
1274          pbyIV += 6;             // 6 is 802.11 address4
1275          PayloadLen -= 6;
1276     }
1277     byKeyIdx = (*(pbyIV+3) & 0xc0);
1278     byKeyIdx >>= 6;
1279     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\nKeyIdx: %d\n", byKeyIdx);
1280
1281
1282     if (pMgmt->byCSSGK == KEY_CTL_TKIP)
1283         byDecMode = KEY_CTL_TKIP;
1284     else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
1285         byDecMode = KEY_CTL_CCMP;
1286
1287     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"AES:%d %d %d\n", pMgmt->byCSSPK, pMgmt->byCSSGK, byDecMode);
1288
1289     if (byDecMode != pKey->byCipherSuite) {
1290         if (byDecMode == KEY_CTL_WEP) {
1291 //            pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1292         } else if (pDevice->bLinkPass == TRUE) {
1293 //            pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1294         }
1295         return FALSE;
1296     }
1297
1298     if (byDecMode == KEY_CTL_WEP) {
1299         // handle WEP
1300         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byDecMode == KEY_CTL_WEP\n");
1301         if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
1302                 (((PSKeyTable)(&pKey->pvKeyTable))->bSoftWEP == TRUE) ||
1303             (bOnFly == FALSE)) {
1304             // Software WEP
1305             // 1. 3253A
1306             // 2. WEP 256
1307             // 3. NotOnFly
1308
1309             PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1310             memcpy(pDevice->abyPRNG, pbyIV, 3);
1311             memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
1312             rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
1313             rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
1314
1315             if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen)) {
1316                 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1317             }
1318         }
1319     } else if ((byDecMode == KEY_CTL_TKIP) ||
1320                (byDecMode == KEY_CTL_CCMP)) {
1321         // TKIP/AES
1322
1323         PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1324         *pdwRxTSC47_16 = cpu_to_le32(*(PDWORD)(pbyIV + 4));
1325         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ExtIV: %x\n", *pdwRxTSC47_16);
1326
1327         if (byDecMode == KEY_CTL_TKIP) {
1328             *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
1329         } else {
1330             *pwRxTSC15_0 = cpu_to_le16(*(PWORD)pbyIV);
1331         }
1332         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC0_15: %x\n", *pwRxTSC15_0);
1333
1334         if (byDecMode == KEY_CTL_TKIP) {
1335
1336             if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || (bOnFly == FALSE)) {
1337                 // Software TKIP
1338                 // 1. 3253 A
1339                 // 2. NotOnFly
1340                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_TKIP \n");
1341                 pMACHeader = (PS802_11Header) (pbyFrame);
1342                 TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
1343                 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
1344                 rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
1345                 if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
1346                     *pbyNewRsr |= NEWRSR_DECRYPTOK;
1347                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV OK!\n");
1348                 } else {
1349                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV FAIL!!!\n");
1350                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PayloadLen = %d\n", PayloadLen);
1351                 }
1352             }
1353         }
1354
1355         if (byDecMode == KEY_CTL_CCMP) {
1356             if (bOnFly == FALSE) {
1357                 // Software CCMP
1358                 // NotOnFly
1359                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_CCMP\n");
1360                 if (AESbGenCCMP(pKey->abyKey, pbyFrame, FrameSize)) {
1361                     *pbyNewRsr |= NEWRSR_DECRYPTOK;
1362                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CCMP MIC compare OK!\n");
1363                 } else {
1364                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CCMP MIC fail!\n");
1365                 }
1366             }
1367         }
1368
1369     }// end of TKIP/AES
1370
1371     if ((*(pbyIV+3) & 0x20) != 0)
1372         *pbExtIV = TRUE;
1373     return TRUE;
1374 }
1375
1376
1377
1378 static BOOL s_bAPModeRxData (
1379      PSDevice pDevice,
1380      struct sk_buff *skb,
1381      unsigned int     FrameSize,
1382      unsigned int     cbHeaderOffset,
1383      signed int      iSANodeIndex,
1384      signed int      iDANodeIndex
1385     )
1386
1387 {
1388     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
1389     BOOL                bRelayAndForward = FALSE;
1390     BOOL                bRelayOnly = FALSE;
1391     BYTE                byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1392     WORD                wAID;
1393
1394
1395     struct sk_buff* skbcpy = NULL;
1396
1397     if (FrameSize > CB_MAX_BUF_SIZE)
1398         return FALSE;
1399     // check DA
1400     if (is_multicast_ether_addr((PBYTE)(skb->data+cbHeaderOffset))) {
1401        if (pMgmt->sNodeDBTable[0].bPSEnable) {
1402
1403            skbcpy = dev_alloc_skb((int)pDevice->rx_buf_sz);
1404
1405         // if any node in PS mode, buffer packet until DTIM.
1406            if (skbcpy == NULL) {
1407                DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "relay multicast no skb available \n");
1408            }
1409            else {
1410                skbcpy->dev = pDevice->dev;
1411                skbcpy->len = FrameSize;
1412                memcpy(skbcpy->data, skb->data+cbHeaderOffset, FrameSize);
1413                skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skbcpy);
1414                pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1415                // set tx map
1416                pMgmt->abyPSTxMap[0] |= byMask[0];
1417            }
1418        }
1419        else {
1420            bRelayAndForward = TRUE;
1421        }
1422     }
1423     else {
1424         // check if relay
1425         if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(skb->data+cbHeaderOffset), &iDANodeIndex)) {
1426             if (pMgmt->sNodeDBTable[iDANodeIndex].eNodeState >= NODE_ASSOC) {
1427                 if (pMgmt->sNodeDBTable[iDANodeIndex].bPSEnable) {
1428                     // queue this skb until next PS tx, and then release.
1429
1430                         skb->data += cbHeaderOffset;
1431                         skb->tail += cbHeaderOffset;
1432                     skb_put(skb, FrameSize);
1433                     skb_queue_tail(&pMgmt->sNodeDBTable[iDANodeIndex].sTxPSQueue, skb);
1434
1435                     pMgmt->sNodeDBTable[iDANodeIndex].wEnQueueCnt++;
1436                     wAID = pMgmt->sNodeDBTable[iDANodeIndex].wAID;
1437                     pMgmt->abyPSTxMap[wAID >> 3] |=  byMask[wAID & 7];
1438                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n",
1439                                iDANodeIndex, (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
1440                     return TRUE;
1441                 }
1442                 else {
1443                     bRelayOnly = TRUE;
1444                 }
1445             }
1446         }
1447     }
1448
1449     if (bRelayOnly || bRelayAndForward) {
1450         // relay this packet right now
1451         if (bRelayAndForward)
1452             iDANodeIndex = 0;
1453
1454         if ((pDevice->uAssocCount > 1) && (iDANodeIndex >= 0)) {
1455                 bRelayPacketSend(pDevice, (PBYTE) (skb->data + cbHeaderOffset),
1456                                  FrameSize, (unsigned int) iDANodeIndex);
1457         }
1458
1459         if (bRelayOnly)
1460             return FALSE;
1461     }
1462     // none associate, don't forward
1463     if (pDevice->uAssocCount == 0)
1464         return FALSE;
1465
1466     return TRUE;
1467 }
1468
1469
1470
1471
1472 void RXvWorkItem(void *Context)
1473 {
1474     PSDevice pDevice = (PSDevice) Context;
1475     int ntStatus;
1476     PRCB            pRCB=NULL;
1477
1478     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Rx Polling Thread\n");
1479     spin_lock_irq(&pDevice->lock);
1480
1481     while ((pDevice->Flags & fMP_POST_READS) &&
1482             MP_IS_READY(pDevice) &&
1483             (pDevice->NumRecvFreeList != 0) ) {
1484         pRCB = pDevice->FirstRecvFreeList;
1485         pDevice->NumRecvFreeList--;
1486         ASSERT(pRCB);// cannot be NULL
1487         DequeueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList);
1488         ntStatus = PIPEnsBulkInUsbRead(pDevice, pRCB);
1489     }
1490     pDevice->bIsRxWorkItemQueued = FALSE;
1491     spin_unlock_irq(&pDevice->lock);
1492
1493 }
1494
1495
1496 void
1497 RXvFreeRCB(
1498      PRCB pRCB,
1499      BOOL bReAllocSkb
1500     )
1501 {
1502     PSDevice pDevice = (PSDevice)pRCB->pDevice;
1503
1504
1505     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->RXvFreeRCB\n");
1506
1507     ASSERT(!pRCB->Ref);     // should be 0
1508     ASSERT(pRCB->pDevice);  // shouldn't be NULL
1509
1510         if (bReAllocSkb == FALSE) {
1511                 kfree_skb(pRCB->skb);
1512                 bReAllocSkb = TRUE;
1513         }
1514
1515     if (bReAllocSkb == TRUE) {
1516         pRCB->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1517         // todo error handling
1518         if (pRCB->skb == NULL) {
1519             DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to re-alloc rx skb\n");
1520         }else {
1521             pRCB->skb->dev = pDevice->dev;
1522         }
1523     }
1524     //
1525     // Insert the RCB back in the Recv free list
1526     //
1527     EnqueueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList, pRCB);
1528     pDevice->NumRecvFreeList++;
1529
1530
1531     if ((pDevice->Flags & fMP_POST_READS) && MP_IS_READY(pDevice) &&
1532         (pDevice->bIsRxWorkItemQueued == FALSE) ) {
1533
1534         pDevice->bIsRxWorkItemQueued = TRUE;
1535         tasklet_schedule(&pDevice->ReadWorkItem);
1536     }
1537     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----RXFreeRCB %d %d\n",pDevice->NumRecvFreeList, pDevice->NumRecvMngList);
1538 }
1539
1540
1541 void RXvMngWorkItem(void *Context)
1542 {
1543     PSDevice pDevice = (PSDevice) Context;
1544     PRCB            pRCB=NULL;
1545     PSRxMgmtPacket  pRxPacket;
1546     BOOL            bReAllocSkb = FALSE;
1547
1548     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Rx Mng Thread\n");
1549
1550     spin_lock_irq(&pDevice->lock);
1551     while (pDevice->NumRecvMngList!=0)
1552     {
1553         pRCB = pDevice->FirstRecvMngList;
1554         pDevice->NumRecvMngList--;
1555         DequeueRCB(pDevice->FirstRecvMngList, pDevice->LastRecvMngList);
1556         if(!pRCB){
1557             break;
1558         }
1559         ASSERT(pRCB);// cannot be NULL
1560         pRxPacket = &(pRCB->sMngPacket);
1561         vMgrRxManagePacket((void *) pDevice, &(pDevice->sMgmtObj), pRxPacket);
1562         pRCB->Ref--;
1563         if(pRCB->Ref == 0) {
1564             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeMng %d %d\n",pDevice->NumRecvFreeList, pDevice->NumRecvMngList);
1565             RXvFreeRCB(pRCB, bReAllocSkb);
1566         } else {
1567             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rx Mng Only we have the right to free RCB\n");
1568         }
1569     }
1570
1571         pDevice->bIsRxMngWorkItemQueued = FALSE;
1572         spin_unlock_irq(&pDevice->lock);
1573
1574 }
1575
1576