staging: vt6656: Remove QWORD from source and replace with u64.
[pandora-kernel.git] / 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         u64 *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 = (u64 *)(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                 pRxPacket->qwLocalTSF = cpu_to_le64(*pqwTSFTime);
602             if (bIsWEP) {
603                 // strip IV
604                 pbyData1 = WLAN_HDR_A3_DATA_PTR(pbyFrame);
605                 pbyData2 = WLAN_HDR_A3_DATA_PTR(pbyFrame) + 4;
606                 for (ii = 0; ii < (FrameSize - 4); ii++) {
607                     *pbyData1 = *pbyData2;
608                      pbyData1++;
609                      pbyData2++;
610                 }
611             }
612
613             pRxPacket->byRxRate = s_byGetRateIdx(*pbyRxRate);
614
615             if ( *pbyRxSts == 0 ) {
616                 //Discard beacon packet which channel is 0
617                 if ( (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) == WLAN_FSTYPE_BEACON) ||
618                      (WLAN_GET_FC_FSTYPE((pRxPacket->p80211Header->sA3.wFrameCtl)) == WLAN_FSTYPE_PROBERESP) ) {
619                         return FALSE;
620                 }
621             }
622             pRxPacket->byRxChannel = (*pbyRxSts) >> 2;
623
624             // hostap Deamon handle 802.11 management
625             if (pDevice->bEnableHostapd) {
626                     skb->dev = pDevice->apdev;
627                     //skb->data += 4;
628                     //skb->tail += 4;
629                     skb->data += 8;
630                     skb->tail += 8;
631                 skb_put(skb, FrameSize);
632                 skb_reset_mac_header(skb);
633                     skb->pkt_type = PACKET_OTHERHOST;
634                 skb->protocol = htons(ETH_P_802_2);
635                     memset(skb->cb, 0, sizeof(skb->cb));
636                     netif_rx(skb);
637                 return TRUE;
638                 }
639
640             //
641             // Insert the RCB in the Recv Mng list
642             //
643             EnqueueRCB(pDevice->FirstRecvMngList, pDevice->LastRecvMngList, pRCBIndicate);
644             pDevice->NumRecvMngList++;
645             if ( bDeFragRx == FALSE) {
646                 pRCB->Ref++;
647             }
648             if (pDevice->bIsRxMngWorkItemQueued == FALSE) {
649                 pDevice->bIsRxMngWorkItemQueued = TRUE;
650                 tasklet_schedule(&pDevice->RxMngWorkItem);
651             }
652
653         }
654         else {
655             // Control Frame
656         };
657         return FALSE;
658     }
659     else {
660         if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
661             //In AP mode, hw only check addr1(BSSID or RA) if equal to local MAC.
662             if ( !(*pbyRsr & RSR_BSSIDOK)) {
663                 if (bDeFragRx) {
664                     if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
665                         DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
666                         pDevice->dev->name);
667                     }
668                 }
669                 return FALSE;
670             }
671         }
672         else {
673             // discard DATA packet while not associate || BSSID error
674             if ((pDevice->bLinkPass == FALSE) ||
675                 !(*pbyRsr & RSR_BSSIDOK)) {
676                 if (bDeFragRx) {
677                     if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
678                         DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
679                         pDevice->dev->name);
680                     }
681                 }
682                 return FALSE;
683             }
684    //mike add:station mode check eapol-key challenge--->
685           {
686             BYTE  Protocol_Version;    //802.1x Authentication
687             BYTE  Packet_Type;           //802.1x Authentication
688             BYTE  Descriptor_type;
689              WORD Key_info;
690               if (bIsWEP)
691                   cbIVOffset = 8;
692               else
693                   cbIVOffset = 0;
694               wEtherType = (skb->data[cbIVOffset + 8 + 24 + 6] << 8) |
695                           skb->data[cbIVOffset + 8 + 24 + 6 + 1];
696               Protocol_Version = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1];
697               Packet_Type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1];
698              if (wEtherType == ETH_P_PAE) {         //Protocol Type in LLC-Header
699                   if(((Protocol_Version==1) ||(Protocol_Version==2)) &&
700                      (Packet_Type==3)) {  //802.1x OR eapol-key challenge frame receive
701                         bRxeapol_key = TRUE;
702                       Descriptor_type = skb->data[cbIVOffset + 8 + 24 + 6 + 1 +1+1+1+2];
703                       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] ;
704                       if(Descriptor_type==2) {    //RSN
705                          //  printk("WPA2_Rx_eapol-key_info<-----:%x\n",Key_info);
706                       }
707                      else  if(Descriptor_type==254) {
708                         //  printk("WPA_Rx_eapol-key_info<-----:%x\n",Key_info);
709                      }
710                   }
711               }
712           }
713     //mike add:station mode check eapol-key challenge<---
714         }
715     }
716
717
718 // Data frame Handle
719
720
721     if (pDevice->bEnablePSMode) {
722         if (IS_FC_MOREDATA((pbyFrame))) {
723             if (*pbyRsr & RSR_ADDROK) {
724                 //PSbSendPSPOLL((PSDevice)pDevice);
725             }
726         }
727         else {
728             if (pMgmt->bInTIMWake == TRUE) {
729                 pMgmt->bInTIMWake = FALSE;
730             }
731         }
732     }
733
734     // Now it only supports 802.11g Infrastructure Mode, and support rate must up to 54 Mbps
735     if (pDevice->bDiversityEnable && (FrameSize>50) &&
736        (pDevice->eOPMode == OP_MODE_INFRASTRUCTURE) &&
737        (pDevice->bLinkPass == TRUE)) {
738         BBvAntennaDiversity(pDevice, s_byGetRateIdx(*pbyRxRate), 0);
739     }
740
741     // ++++++++ For BaseBand Algorithm +++++++++++++++
742     pDevice->uCurrRSSI = *pbyRSSI;
743     pDevice->byCurrSQ = *pbySQ;
744
745     // todo
746 /*
747     if ((*pbyRSSI != 0) &&
748         (pMgmt->pCurrBSS!=NULL)) {
749         RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
750         // Monitor if RSSI is too strong.
751         pMgmt->pCurrBSS->byRSSIStatCnt++;
752         pMgmt->pCurrBSS->byRSSIStatCnt %= RSSI_STAT_COUNT;
753         pMgmt->pCurrBSS->ldBmAverage[pMgmt->pCurrBSS->byRSSIStatCnt] = ldBm;
754         for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
755                 if (pMgmt->pCurrBSS->ldBmAverage[ii] != 0) {
756                         pMgmt->pCurrBSS->ldBmMAX =
757                                 max(pMgmt->pCurrBSS->ldBmAverage[ii], ldBm);
758                 }
759         }
760     }
761 */
762
763
764     // -----------------------------------------------
765
766     if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->bEnable8021x == TRUE)){
767         BYTE    abyMacHdr[24];
768
769         // Only 802.1x packet incoming allowed
770         if (bIsWEP)
771             cbIVOffset = 8;
772         else
773             cbIVOffset = 0;
774         wEtherType = (skb->data[cbIVOffset + 8 + 24 + 6] << 8) |
775                     skb->data[cbIVOffset + 8 + 24 + 6 + 1];
776
777             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wEtherType = %04x \n", wEtherType);
778         if (wEtherType == ETH_P_PAE) {
779             skb->dev = pDevice->apdev;
780
781             if (bIsWEP == TRUE) {
782                 // strip IV header(8)
783                 memcpy(&abyMacHdr[0], (skb->data + 8), 24);
784                 memcpy((skb->data + 8 + cbIVOffset), &abyMacHdr[0], 24);
785             }
786
787             skb->data +=  (cbIVOffset + 8);
788             skb->tail +=  (cbIVOffset + 8);
789             skb_put(skb, FrameSize);
790             skb_reset_mac_header(skb);
791             skb->pkt_type = PACKET_OTHERHOST;
792             skb->protocol = htons(ETH_P_802_2);
793             memset(skb->cb, 0, sizeof(skb->cb));
794             netif_rx(skb);
795             return TRUE;
796
797         }
798         // check if 802.1x authorized
799         if (!(pMgmt->sNodeDBTable[iSANodeIndex].dwFlags & WLAN_STA_AUTHORIZED))
800             return FALSE;
801     }
802
803
804     if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
805         if (bIsWEP) {
806             FrameSize -= 8;  //MIC
807         }
808     }
809
810     //--------------------------------------------------------------------------------
811     // Soft MIC
812     if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP)) {
813         if (bIsWEP) {
814             PDWORD          pdwMIC_L;
815             PDWORD          pdwMIC_R;
816             DWORD           dwMIC_Priority;
817             DWORD           dwMICKey0 = 0, dwMICKey1 = 0;
818             DWORD           dwLocalMIC_L = 0;
819             DWORD           dwLocalMIC_R = 0;
820
821
822             if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
823                 dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[24]));
824                 dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[28]));
825             }
826             else {
827                 if (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) {
828                     dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[16]));
829                     dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[20]));
830                 } else if ((pKey->dwKeyIndex & BIT28) == 0) {
831                     dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[16]));
832                     dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[20]));
833                 } else {
834                     dwMICKey0 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[24]));
835                     dwMICKey1 = cpu_to_le32(*(PDWORD)(&pKey->abyKey[28]));
836                 }
837             }
838
839             MIC_vInit(dwMICKey0, dwMICKey1);
840             MIC_vAppend((PBYTE)&(pDevice->sRxEthHeader.abyDstAddr[0]), 12);
841             dwMIC_Priority = 0;
842             MIC_vAppend((PBYTE)&dwMIC_Priority, 4);
843             // 4 is Rcv buffer header, 24 is MAC Header, and 8 is IV and Ext IV.
844             MIC_vAppend((PBYTE)(skb->data + 8 + WLAN_HDR_ADDR3_LEN + 8),
845                         FrameSize - WLAN_HDR_ADDR3_LEN - 8);
846             MIC_vGetMIC(&dwLocalMIC_L, &dwLocalMIC_R);
847             MIC_vUnInit();
848
849             pdwMIC_L = (PDWORD)(skb->data + 8 + FrameSize);
850             pdwMIC_R = (PDWORD)(skb->data + 8 + FrameSize + 4);
851
852
853             if ((cpu_to_le32(*pdwMIC_L) != dwLocalMIC_L) || (cpu_to_le32(*pdwMIC_R) != dwLocalMIC_R) ||
854                 (pDevice->bRxMICFail == TRUE)) {
855                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"MIC comparison is fail!\n");
856                 pDevice->bRxMICFail = FALSE;
857                 //pDevice->s802_11Counter.TKIPLocalMICFailures.QuadPart++;
858                 pDevice->s802_11Counter.TKIPLocalMICFailures++;
859                 if (bDeFragRx) {
860                     if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
861                         DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
862                             pDevice->dev->name);
863                     }
864                 }
865                                 //send event to wpa_supplicant
866                                 //if(pDevice->bWPASuppWextEnabled == TRUE)
867                                 {
868                                         union iwreq_data wrqu;
869                                         struct iw_michaelmicfailure ev;
870                                         int keyidx = pbyFrame[cbHeaderSize+3] >> 6; //top two-bits
871                                         memset(&ev, 0, sizeof(ev));
872                                         ev.flags = keyidx & IW_MICFAILURE_KEY_ID;
873                                         if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
874                                                         (pMgmt->eCurrState == WMAC_STATE_ASSOC) &&
875                                                                 (*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) {
876                                                 ev.flags |= IW_MICFAILURE_PAIRWISE;
877                                         } else {
878                                                 ev.flags |= IW_MICFAILURE_GROUP;
879                                         }
880
881                                         ev.src_addr.sa_family = ARPHRD_ETHER;
882                                         memcpy(ev.src_addr.sa_data, pMACHeader->abyAddr2, ETH_ALEN);
883                                         memset(&wrqu, 0, sizeof(wrqu));
884                                         wrqu.data.length = sizeof(ev);
885                         PRINT_K("wireless_send_event--->IWEVMICHAELMICFAILURE\n");
886                                         wireless_send_event(pDevice->dev, IWEVMICHAELMICFAILURE, &wrqu, (char *)&ev);
887
888                                 }
889
890                 return FALSE;
891
892             }
893         }
894     } //---end of SOFT MIC-----------------------------------------------------------------------
895
896     // ++++++++++ Reply Counter Check +++++++++++++
897
898     if ((pKey != NULL) && ((pKey->byCipherSuite == KEY_CTL_TKIP) ||
899                            (pKey->byCipherSuite == KEY_CTL_CCMP))) {
900         if (bIsWEP) {
901             WORD        wLocalTSC15_0 = 0;
902             DWORD       dwLocalTSC47_16 = 0;
903             unsigned long long       RSC = 0;
904             // endian issues
905             RSC = *((unsigned long long *) &(pKey->KeyRSC));
906             wLocalTSC15_0 = (WORD) RSC;
907             dwLocalTSC47_16 = (DWORD) (RSC>>16);
908
909             RSC = dwRxTSC47_16;
910             RSC <<= 16;
911             RSC += wRxTSC15_0;
912                 memcpy(&(pKey->KeyRSC), &RSC,  sizeof(u64));
913
914             if ( (pDevice->sMgmtObj.eCurrMode == WMAC_MODE_ESS_STA) &&
915                  (pDevice->sMgmtObj.eCurrState == WMAC_STATE_ASSOC)) {
916                 // check RSC
917                 if ( (wRxTSC15_0 < wLocalTSC15_0) &&
918                      (dwRxTSC47_16 <= dwLocalTSC47_16) &&
919                      !((dwRxTSC47_16 == 0) && (dwLocalTSC47_16 == 0xFFFFFFFF))) {
920                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC is illegal~~!\n ");
921                     if (pKey->byCipherSuite == KEY_CTL_TKIP)
922                         //pDevice->s802_11Counter.TKIPReplays.QuadPart++;
923                         pDevice->s802_11Counter.TKIPReplays++;
924                     else
925                         //pDevice->s802_11Counter.CCMPReplays.QuadPart++;
926                         pDevice->s802_11Counter.CCMPReplays++;
927
928                     if (bDeFragRx) {
929                         if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
930                             DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
931                                 pDevice->dev->name);
932                         }
933                     }
934                     return FALSE;
935                 }
936             }
937         }
938     } // ----- End of Reply Counter Check --------------------------
939
940
941     s_vProcessRxMACHeader(pDevice, (PBYTE)(skb->data+8), FrameSize, bIsWEP, bExtIV, &cbHeaderOffset);
942     FrameSize -= cbHeaderOffset;
943     cbHeaderOffset += 8;        // 8 is Rcv buffer header
944
945     // Null data, framesize = 12
946     if (FrameSize < 12)
947         return FALSE;
948
949     if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
950         if (s_bAPModeRxData(pDevice,
951                             skb,
952                             FrameSize,
953                             cbHeaderOffset,
954                             iSANodeIndex,
955                             iDANodeIndex
956                             ) == FALSE) {
957
958             if (bDeFragRx) {
959                 if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
960                     DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
961                     pDevice->dev->name);
962                 }
963             }
964             return FALSE;
965         }
966
967     }
968
969         skb->data += cbHeaderOffset;
970         skb->tail += cbHeaderOffset;
971     skb_put(skb, FrameSize);
972     skb->protocol=eth_type_trans(skb, skb->dev);
973     skb->ip_summed=CHECKSUM_NONE;
974     pStats->rx_bytes +=skb->len;
975     pStats->rx_packets++;
976     netif_rx(skb);
977     if (bDeFragRx) {
978         if (!device_alloc_frag_buf(pDevice, &pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx])) {
979             DBG_PRT(MSG_LEVEL_ERR,KERN_ERR "%s: can not alloc more frag bufs\n",
980                 pDevice->dev->name);
981         }
982         return FALSE;
983     }
984
985     return TRUE;
986 }
987
988
989 static BOOL s_bAPModeRxCtl (
990      PSDevice pDevice,
991      PBYTE    pbyFrame,
992      signed int      iSANodeIndex
993     )
994 {
995     PS802_11Header      p802_11Header;
996     CMD_STATUS          Status;
997     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
998
999
1000     if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
1001
1002         p802_11Header = (PS802_11Header) (pbyFrame);
1003         if (!IS_TYPE_MGMT(pbyFrame)) {
1004
1005             // Data & PS-Poll packet
1006             // check frame class
1007             if (iSANodeIndex > 0) {
1008                 // frame class 3 fliter & checking
1009                 if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_AUTH) {
1010                     // send deauth notification
1011                     // reason = (6) class 2 received from nonauth sta
1012                     vMgrDeAuthenBeginSta(pDevice,
1013                                          pMgmt,
1014                                          (PBYTE)(p802_11Header->abyAddr2),
1015                                          (WLAN_MGMT_REASON_CLASS2_NONAUTH),
1016                                          &Status
1017                                          );
1018                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 1\n");
1019                     return TRUE;
1020                 }
1021                 if (pMgmt->sNodeDBTable[iSANodeIndex].eNodeState < NODE_ASSOC) {
1022                     // send deassoc notification
1023                     // reason = (7) class 3 received from nonassoc sta
1024                     vMgrDisassocBeginSta(pDevice,
1025                                          pMgmt,
1026                                          (PBYTE)(p802_11Header->abyAddr2),
1027                                          (WLAN_MGMT_REASON_CLASS3_NONASSOC),
1028                                          &Status
1029                                          );
1030                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDisassocBeginSta 2\n");
1031                     return TRUE;
1032                 }
1033
1034                 if (pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable) {
1035                     // delcare received ps-poll event
1036                     if (IS_CTL_PSPOLL(pbyFrame)) {
1037                         pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE;
1038                         bScheduleCommand((void *) pDevice,
1039                                          WLAN_CMD_RX_PSPOLL,
1040                                          NULL);
1041                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 1\n");
1042                     }
1043                     else {
1044                         // check Data PS state
1045                         // if PW bit off, send out all PS bufferring packets.
1046                         if (!IS_FC_POWERMGT(pbyFrame)) {
1047                             pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = FALSE;
1048                             pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE;
1049                                 bScheduleCommand((void *) pDevice,
1050                                                  WLAN_CMD_RX_PSPOLL,
1051                                                  NULL);
1052                             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 2\n");
1053                         }
1054                     }
1055                 }
1056                 else {
1057                    if (IS_FC_POWERMGT(pbyFrame)) {
1058                        pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = TRUE;
1059                        // Once if STA in PS state, enable multicast bufferring
1060                        pMgmt->sNodeDBTable[0].bPSEnable = TRUE;
1061                    }
1062                    else {
1063                       // clear all pending PS frame.
1064                       if (pMgmt->sNodeDBTable[iSANodeIndex].wEnQueueCnt > 0) {
1065                           pMgmt->sNodeDBTable[iSANodeIndex].bPSEnable = FALSE;
1066                           pMgmt->sNodeDBTable[iSANodeIndex].bRxPSPoll = TRUE;
1067                         bScheduleCommand((void *) pDevice,
1068                                          WLAN_CMD_RX_PSPOLL,
1069                                          NULL);
1070                          DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: WLAN_CMD_RX_PSPOLL 3\n");
1071
1072                       }
1073                    }
1074                 }
1075             }
1076             else {
1077                   vMgrDeAuthenBeginSta(pDevice,
1078                                        pMgmt,
1079                                        (PBYTE)(p802_11Header->abyAddr2),
1080                                        (WLAN_MGMT_REASON_CLASS2_NONAUTH),
1081                                        &Status
1082                                        );
1083                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: send vMgrDeAuthenBeginSta 3\n");
1084                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSID:%pM\n",
1085                                 p802_11Header->abyAddr3);
1086                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR2:%pM\n",
1087                                 p802_11Header->abyAddr2);
1088                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ADDR1:%pM\n",
1089                                 p802_11Header->abyAddr1);
1090                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "dpc: wFrameCtl= %x\n", p802_11Header->wFrameCtl );
1091                     return TRUE;
1092             }
1093         }
1094     }
1095     return FALSE;
1096
1097 }
1098
1099 static BOOL s_bHandleRxEncryption (
1100      PSDevice     pDevice,
1101      PBYTE        pbyFrame,
1102      unsigned int         FrameSize,
1103      PBYTE        pbyRsr,
1104      PBYTE       pbyNewRsr,
1105      PSKeyItem   * pKeyOut,
1106     int *       pbExtIV,
1107      PWORD       pwRxTSC15_0,
1108      PDWORD      pdwRxTSC47_16
1109     )
1110 {
1111     unsigned int            PayloadLen = FrameSize;
1112     PBYTE           pbyIV;
1113     BYTE            byKeyIdx;
1114     PSKeyItem       pKey = NULL;
1115     BYTE            byDecMode = KEY_CTL_WEP;
1116     PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
1117
1118
1119     *pwRxTSC15_0 = 0;
1120     *pdwRxTSC47_16 = 0;
1121
1122     pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
1123     if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) &&
1124          WLAN_GET_FC_FROMDS(*(PWORD)pbyFrame) ) {
1125          pbyIV += 6;             // 6 is 802.11 address4
1126          PayloadLen -= 6;
1127     }
1128     byKeyIdx = (*(pbyIV+3) & 0xc0);
1129     byKeyIdx >>= 6;
1130     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\nKeyIdx: %d\n", byKeyIdx);
1131
1132     if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
1133         (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
1134         (pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
1135         (pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
1136         (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
1137         if (((*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI)) == 0) &&
1138             (pMgmt->byCSSPK != KEY_CTL_NONE)) {
1139             // unicast pkt use pairwise key
1140             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"unicast pkt\n");
1141             if (KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, 0xFFFFFFFF, &pKey) == TRUE) {
1142                 if (pMgmt->byCSSPK == KEY_CTL_TKIP)
1143                     byDecMode = KEY_CTL_TKIP;
1144                 else if (pMgmt->byCSSPK == KEY_CTL_CCMP)
1145                     byDecMode = KEY_CTL_CCMP;
1146             }
1147             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"unicast pkt: %d, %p\n", byDecMode, pKey);
1148         } else {
1149             // use group key
1150             KeybGetKey(&(pDevice->sKey), pDevice->abyBSSID, byKeyIdx, &pKey);
1151             if (pMgmt->byCSSGK == KEY_CTL_TKIP)
1152                 byDecMode = KEY_CTL_TKIP;
1153             else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
1154                 byDecMode = KEY_CTL_CCMP;
1155             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"group pkt: %d, %d, %p\n", byKeyIdx, byDecMode, pKey);
1156         }
1157     }
1158     // our WEP only support Default Key
1159     if (pKey == NULL) {
1160         // use default group key
1161         KeybGetKey(&(pDevice->sKey), pDevice->abyBroadcastAddr, byKeyIdx, &pKey);
1162         if (pMgmt->byCSSGK == KEY_CTL_TKIP)
1163             byDecMode = KEY_CTL_TKIP;
1164         else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
1165             byDecMode = KEY_CTL_CCMP;
1166     }
1167     *pKeyOut = pKey;
1168
1169     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"AES:%d %d %d\n", pMgmt->byCSSPK, pMgmt->byCSSGK, byDecMode);
1170
1171     if (pKey == NULL) {
1172         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pKey == NULL\n");
1173         if (byDecMode == KEY_CTL_WEP) {
1174 //            pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1175         } else if (pDevice->bLinkPass == TRUE) {
1176 //            pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1177         }
1178         return FALSE;
1179     }
1180     if (byDecMode != pKey->byCipherSuite) {
1181         if (byDecMode == KEY_CTL_WEP) {
1182 //            pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1183         } else if (pDevice->bLinkPass == TRUE) {
1184 //            pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1185         }
1186         *pKeyOut = NULL;
1187         return FALSE;
1188     }
1189     if (byDecMode == KEY_CTL_WEP) {
1190         // handle WEP
1191         if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
1192                 (((PSKeyTable)(&pKey->pvKeyTable))->bSoftWEP == TRUE)) {
1193             // Software WEP
1194             // 1. 3253A
1195             // 2. WEP 256
1196
1197             PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1198             memcpy(pDevice->abyPRNG, pbyIV, 3);
1199             memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
1200             rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
1201             rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
1202
1203             if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen)) {
1204                 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1205             }
1206         }
1207     } else if ((byDecMode == KEY_CTL_TKIP) ||
1208                (byDecMode == KEY_CTL_CCMP)) {
1209         // TKIP/AES
1210
1211         PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1212         *pdwRxTSC47_16 = cpu_to_le32(*(PDWORD)(pbyIV + 4));
1213         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ExtIV: %x\n", *pdwRxTSC47_16);
1214         if (byDecMode == KEY_CTL_TKIP) {
1215             *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
1216         } else {
1217             *pwRxTSC15_0 = cpu_to_le16(*(PWORD)pbyIV);
1218         }
1219         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC0_15: %x\n", *pwRxTSC15_0);
1220
1221         if ((byDecMode == KEY_CTL_TKIP) &&
1222             (pDevice->byLocalID <= REV_ID_VT3253_A1)) {
1223             // Software TKIP
1224             // 1. 3253 A
1225             PS802_11Header  pMACHeader = (PS802_11Header) (pbyFrame);
1226             TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
1227             rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
1228             rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
1229             if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
1230                 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1231                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV OK!\n");
1232             } else {
1233                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV FAIL!!!\n");
1234                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PayloadLen = %d\n", PayloadLen);
1235             }
1236         }
1237     }// end of TKIP/AES
1238
1239     if ((*(pbyIV+3) & 0x20) != 0)
1240         *pbExtIV = TRUE;
1241     return TRUE;
1242 }
1243
1244
1245 static BOOL s_bHostWepRxEncryption (
1246      PSDevice     pDevice,
1247      PBYTE        pbyFrame,
1248      unsigned int         FrameSize,
1249      PBYTE        pbyRsr,
1250      BOOL         bOnFly,
1251      PSKeyItem    pKey,
1252      PBYTE       pbyNewRsr,
1253     int *       pbExtIV,
1254      PWORD       pwRxTSC15_0,
1255      PDWORD      pdwRxTSC47_16
1256     )
1257 {
1258     PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
1259     unsigned int            PayloadLen = FrameSize;
1260     PBYTE           pbyIV;
1261     BYTE            byKeyIdx;
1262     BYTE            byDecMode = KEY_CTL_WEP;
1263     PS802_11Header  pMACHeader;
1264
1265
1266
1267     *pwRxTSC15_0 = 0;
1268     *pdwRxTSC47_16 = 0;
1269
1270     pbyIV = pbyFrame + WLAN_HDR_ADDR3_LEN;
1271     if ( WLAN_GET_FC_TODS(*(PWORD)pbyFrame) &&
1272          WLAN_GET_FC_FROMDS(*(PWORD)pbyFrame) ) {
1273          pbyIV += 6;             // 6 is 802.11 address4
1274          PayloadLen -= 6;
1275     }
1276     byKeyIdx = (*(pbyIV+3) & 0xc0);
1277     byKeyIdx >>= 6;
1278     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"\nKeyIdx: %d\n", byKeyIdx);
1279
1280
1281     if (pMgmt->byCSSGK == KEY_CTL_TKIP)
1282         byDecMode = KEY_CTL_TKIP;
1283     else if (pMgmt->byCSSGK == KEY_CTL_CCMP)
1284         byDecMode = KEY_CTL_CCMP;
1285
1286     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"AES:%d %d %d\n", pMgmt->byCSSPK, pMgmt->byCSSGK, byDecMode);
1287
1288     if (byDecMode != pKey->byCipherSuite) {
1289         if (byDecMode == KEY_CTL_WEP) {
1290 //            pDevice->s802_11Counter.WEPUndecryptableCount.QuadPart++;
1291         } else if (pDevice->bLinkPass == TRUE) {
1292 //            pDevice->s802_11Counter.DecryptFailureCount.QuadPart++;
1293         }
1294         return FALSE;
1295     }
1296
1297     if (byDecMode == KEY_CTL_WEP) {
1298         // handle WEP
1299         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"byDecMode == KEY_CTL_WEP\n");
1300         if ((pDevice->byLocalID <= REV_ID_VT3253_A1) ||
1301                 (((PSKeyTable)(&pKey->pvKeyTable))->bSoftWEP == TRUE) ||
1302             (bOnFly == FALSE)) {
1303             // Software WEP
1304             // 1. 3253A
1305             // 2. WEP 256
1306             // 3. NotOnFly
1307
1308             PayloadLen -= (WLAN_HDR_ADDR3_LEN + 4 + 4); // 24 is 802.11 header,4 is IV, 4 is crc
1309             memcpy(pDevice->abyPRNG, pbyIV, 3);
1310             memcpy(pDevice->abyPRNG + 3, pKey->abyKey, pKey->uKeyLength);
1311             rc4_init(&pDevice->SBox, pDevice->abyPRNG, pKey->uKeyLength + 3);
1312             rc4_encrypt(&pDevice->SBox, pbyIV+4, pbyIV+4, PayloadLen);
1313
1314             if (ETHbIsBufferCrc32Ok(pbyIV+4, PayloadLen)) {
1315                 *pbyNewRsr |= NEWRSR_DECRYPTOK;
1316             }
1317         }
1318     } else if ((byDecMode == KEY_CTL_TKIP) ||
1319                (byDecMode == KEY_CTL_CCMP)) {
1320         // TKIP/AES
1321
1322         PayloadLen -= (WLAN_HDR_ADDR3_LEN + 8 + 4); // 24 is 802.11 header, 8 is IV&ExtIV, 4 is crc
1323         *pdwRxTSC47_16 = cpu_to_le32(*(PDWORD)(pbyIV + 4));
1324         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ExtIV: %x\n", *pdwRxTSC47_16);
1325
1326         if (byDecMode == KEY_CTL_TKIP) {
1327             *pwRxTSC15_0 = cpu_to_le16(MAKEWORD(*(pbyIV+2), *pbyIV));
1328         } else {
1329             *pwRxTSC15_0 = cpu_to_le16(*(PWORD)pbyIV);
1330         }
1331         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"TSC0_15: %x\n", *pwRxTSC15_0);
1332
1333         if (byDecMode == KEY_CTL_TKIP) {
1334
1335             if ((pDevice->byLocalID <= REV_ID_VT3253_A1) || (bOnFly == FALSE)) {
1336                 // Software TKIP
1337                 // 1. 3253 A
1338                 // 2. NotOnFly
1339                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_TKIP \n");
1340                 pMACHeader = (PS802_11Header) (pbyFrame);
1341                 TKIPvMixKey(pKey->abyKey, pMACHeader->abyAddr2, *pwRxTSC15_0, *pdwRxTSC47_16, pDevice->abyPRNG);
1342                 rc4_init(&pDevice->SBox, pDevice->abyPRNG, TKIP_KEY_LEN);
1343                 rc4_encrypt(&pDevice->SBox, pbyIV+8, pbyIV+8, PayloadLen);
1344                 if (ETHbIsBufferCrc32Ok(pbyIV+8, PayloadLen)) {
1345                     *pbyNewRsr |= NEWRSR_DECRYPTOK;
1346                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV OK!\n");
1347                 } else {
1348                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ICV FAIL!!!\n");
1349                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"PayloadLen = %d\n", PayloadLen);
1350                 }
1351             }
1352         }
1353
1354         if (byDecMode == KEY_CTL_CCMP) {
1355             if (bOnFly == FALSE) {
1356                 // Software CCMP
1357                 // NotOnFly
1358                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"soft KEY_CTL_CCMP\n");
1359                 if (AESbGenCCMP(pKey->abyKey, pbyFrame, FrameSize)) {
1360                     *pbyNewRsr |= NEWRSR_DECRYPTOK;
1361                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CCMP MIC compare OK!\n");
1362                 } else {
1363                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"CCMP MIC fail!\n");
1364                 }
1365             }
1366         }
1367
1368     }// end of TKIP/AES
1369
1370     if ((*(pbyIV+3) & 0x20) != 0)
1371         *pbExtIV = TRUE;
1372     return TRUE;
1373 }
1374
1375
1376
1377 static BOOL s_bAPModeRxData (
1378      PSDevice pDevice,
1379      struct sk_buff *skb,
1380      unsigned int     FrameSize,
1381      unsigned int     cbHeaderOffset,
1382      signed int      iSANodeIndex,
1383      signed int      iDANodeIndex
1384     )
1385
1386 {
1387     PSMgmtObject        pMgmt = &(pDevice->sMgmtObj);
1388     BOOL                bRelayAndForward = FALSE;
1389     BOOL                bRelayOnly = FALSE;
1390     BYTE                byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
1391     WORD                wAID;
1392
1393
1394     struct sk_buff* skbcpy = NULL;
1395
1396     if (FrameSize > CB_MAX_BUF_SIZE)
1397         return FALSE;
1398     // check DA
1399     if (is_multicast_ether_addr((PBYTE)(skb->data+cbHeaderOffset))) {
1400        if (pMgmt->sNodeDBTable[0].bPSEnable) {
1401
1402            skbcpy = dev_alloc_skb((int)pDevice->rx_buf_sz);
1403
1404         // if any node in PS mode, buffer packet until DTIM.
1405            if (skbcpy == NULL) {
1406                DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "relay multicast no skb available \n");
1407            }
1408            else {
1409                skbcpy->dev = pDevice->dev;
1410                skbcpy->len = FrameSize;
1411                memcpy(skbcpy->data, skb->data+cbHeaderOffset, FrameSize);
1412                skb_queue_tail(&(pMgmt->sNodeDBTable[0].sTxPSQueue), skbcpy);
1413                pMgmt->sNodeDBTable[0].wEnQueueCnt++;
1414                // set tx map
1415                pMgmt->abyPSTxMap[0] |= byMask[0];
1416            }
1417        }
1418        else {
1419            bRelayAndForward = TRUE;
1420        }
1421     }
1422     else {
1423         // check if relay
1424         if (BSSbIsSTAInNodeDB(pDevice, (PBYTE)(skb->data+cbHeaderOffset), &iDANodeIndex)) {
1425             if (pMgmt->sNodeDBTable[iDANodeIndex].eNodeState >= NODE_ASSOC) {
1426                 if (pMgmt->sNodeDBTable[iDANodeIndex].bPSEnable) {
1427                     // queue this skb until next PS tx, and then release.
1428
1429                         skb->data += cbHeaderOffset;
1430                         skb->tail += cbHeaderOffset;
1431                     skb_put(skb, FrameSize);
1432                     skb_queue_tail(&pMgmt->sNodeDBTable[iDANodeIndex].sTxPSQueue, skb);
1433
1434                     pMgmt->sNodeDBTable[iDANodeIndex].wEnQueueCnt++;
1435                     wAID = pMgmt->sNodeDBTable[iDANodeIndex].wAID;
1436                     pMgmt->abyPSTxMap[wAID >> 3] |=  byMask[wAID & 7];
1437                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "relay: index= %d, pMgmt->abyPSTxMap[%d]= %d\n",
1438                                iDANodeIndex, (wAID >> 3), pMgmt->abyPSTxMap[wAID >> 3]);
1439                     return TRUE;
1440                 }
1441                 else {
1442                     bRelayOnly = TRUE;
1443                 }
1444             }
1445         }
1446     }
1447
1448     if (bRelayOnly || bRelayAndForward) {
1449         // relay this packet right now
1450         if (bRelayAndForward)
1451             iDANodeIndex = 0;
1452
1453         if ((pDevice->uAssocCount > 1) && (iDANodeIndex >= 0)) {
1454                 bRelayPacketSend(pDevice, (PBYTE) (skb->data + cbHeaderOffset),
1455                                  FrameSize, (unsigned int) iDANodeIndex);
1456         }
1457
1458         if (bRelayOnly)
1459             return FALSE;
1460     }
1461     // none associate, don't forward
1462     if (pDevice->uAssocCount == 0)
1463         return FALSE;
1464
1465     return TRUE;
1466 }
1467
1468
1469
1470
1471 void RXvWorkItem(void *Context)
1472 {
1473     PSDevice pDevice = (PSDevice) Context;
1474     int ntStatus;
1475     PRCB            pRCB=NULL;
1476
1477     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Rx Polling Thread\n");
1478     spin_lock_irq(&pDevice->lock);
1479
1480     while ((pDevice->Flags & fMP_POST_READS) &&
1481             MP_IS_READY(pDevice) &&
1482             (pDevice->NumRecvFreeList != 0) ) {
1483         pRCB = pDevice->FirstRecvFreeList;
1484         pDevice->NumRecvFreeList--;
1485         ASSERT(pRCB);// cannot be NULL
1486         DequeueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList);
1487         ntStatus = PIPEnsBulkInUsbRead(pDevice, pRCB);
1488     }
1489     pDevice->bIsRxWorkItemQueued = FALSE;
1490     spin_unlock_irq(&pDevice->lock);
1491
1492 }
1493
1494
1495 void
1496 RXvFreeRCB(
1497      PRCB pRCB,
1498      BOOL bReAllocSkb
1499     )
1500 {
1501     PSDevice pDevice = (PSDevice)pRCB->pDevice;
1502
1503
1504     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->RXvFreeRCB\n");
1505
1506     ASSERT(!pRCB->Ref);     // should be 0
1507     ASSERT(pRCB->pDevice);  // shouldn't be NULL
1508
1509         if (bReAllocSkb == FALSE) {
1510                 kfree_skb(pRCB->skb);
1511                 bReAllocSkb = TRUE;
1512         }
1513
1514     if (bReAllocSkb == TRUE) {
1515         pRCB->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1516         // todo error handling
1517         if (pRCB->skb == NULL) {
1518             DBG_PRT(MSG_LEVEL_ERR,KERN_ERR" Failed to re-alloc rx skb\n");
1519         }else {
1520             pRCB->skb->dev = pDevice->dev;
1521         }
1522     }
1523     //
1524     // Insert the RCB back in the Recv free list
1525     //
1526     EnqueueRCB(pDevice->FirstRecvFreeList, pDevice->LastRecvFreeList, pRCB);
1527     pDevice->NumRecvFreeList++;
1528
1529
1530     if ((pDevice->Flags & fMP_POST_READS) && MP_IS_READY(pDevice) &&
1531         (pDevice->bIsRxWorkItemQueued == FALSE) ) {
1532
1533         pDevice->bIsRxWorkItemQueued = TRUE;
1534         tasklet_schedule(&pDevice->ReadWorkItem);
1535     }
1536     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"<----RXFreeRCB %d %d\n",pDevice->NumRecvFreeList, pDevice->NumRecvMngList);
1537 }
1538
1539
1540 void RXvMngWorkItem(void *Context)
1541 {
1542     PSDevice pDevice = (PSDevice) Context;
1543     PRCB            pRCB=NULL;
1544     PSRxMgmtPacket  pRxPacket;
1545     BOOL            bReAllocSkb = FALSE;
1546
1547     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"---->Rx Mng Thread\n");
1548
1549     spin_lock_irq(&pDevice->lock);
1550     while (pDevice->NumRecvMngList!=0)
1551     {
1552         pRCB = pDevice->FirstRecvMngList;
1553         pDevice->NumRecvMngList--;
1554         DequeueRCB(pDevice->FirstRecvMngList, pDevice->LastRecvMngList);
1555         if(!pRCB){
1556             break;
1557         }
1558         ASSERT(pRCB);// cannot be NULL
1559         pRxPacket = &(pRCB->sMngPacket);
1560         vMgrRxManagePacket((void *) pDevice, &(pDevice->sMgmtObj), pRxPacket);
1561         pRCB->Ref--;
1562         if(pRCB->Ref == 0) {
1563             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"RxvFreeMng %d %d\n",pDevice->NumRecvFreeList, pDevice->NumRecvMngList);
1564             RXvFreeRCB(pRCB, bReAllocSkb);
1565         } else {
1566             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rx Mng Only we have the right to free RCB\n");
1567         }
1568     }
1569
1570         pDevice->bIsRxMngWorkItemQueued = FALSE;
1571         spin_unlock_irq(&pDevice->lock);
1572
1573 }
1574
1575