]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/vt6655/bssdb.c
37a3f18bc51ef116a4fc57aa596b898253a5d37a
[karo-tx-linux.git] / drivers / staging / vt6655 / bssdb.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: bssdb.c
20  *
21  * Purpose: Handles the Basic Service Set & Node Database functions
22  *
23  * Functions:
24  *      BSSpSearchBSSList - Search known BSS list for Desire SSID or BSSID
25  *      BSSvClearBSSList - Clear BSS List
26  *      BSSbInsertToBSSList - Insert a BSS set into known BSS list
27  *      BSSbUpdateToBSSList - Update BSS set in known BSS list
28  *      BSSDBbIsSTAInNodeDB - Search Node DB table to find the index of matched DstAddr
29  *      BSSvCreateOneNode - Allocate an Node for Node DB
30  *      BSSvUpdateAPNode - Update AP Node content in Index 0 of KnownNodeDB
31  *      BSSvSecondCallBack - One second timer callback function to update Node DB info & AP link status
32  *      BSSvUpdateNodeTxCounter - Update Tx attemps, Tx failure counter in Node DB for auto-fall back rate control
33  *
34  * Revision History:
35  *
36  * Author: Lyndon Chen
37  *
38  * Date: July 17, 2002
39  *
40  */
41
42 #include "ttype.h"
43 #include "tmacro.h"
44 #include "tether.h"
45 #include "device.h"
46 #include "80211hdr.h"
47 #include "bssdb.h"
48 #include "wmgr.h"
49 #include "datarate.h"
50 #include "desc.h"
51 #include "wcmd.h"
52 #include "wpa.h"
53 #include "baseband.h"
54 #include "rf.h"
55 #include "card.h"
56 #include "channel.h"
57 #include "mac.h"
58 #include "wpa2.h"
59 #include "iowpa.h"
60
61 //#define       PLICE_DEBUG
62 /*---------------------  Static Definitions -------------------------*/
63
64
65
66
67 /*---------------------  Static Classes  ----------------------------*/
68
69 /*---------------------  Static Variables  --------------------------*/
70 static int          msglevel                =MSG_LEVEL_INFO;
71 //static int          msglevel                =MSG_LEVEL_DEBUG;
72
73
74
75 const unsigned short awHWRetry0[5][5] = {
76                                             {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
77                                             {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
78                                             {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
79                                             {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
80                                             {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
81                                            };
82 const unsigned short awHWRetry1[5][5] = {
83                                             {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
84                                             {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
85                                             {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
86                                             {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
87                                             {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
88                                            };
89
90
91
92 /*---------------------  Static Functions  --------------------------*/
93
94 void s_vCheckSensitivity(
95     void *hDeviceContext
96     );
97
98 #ifdef Calcu_LinkQual
99 void s_uCalculateLinkQual(
100     void *hDeviceContext
101     );
102 #endif
103
104
105 void s_vCheckPreEDThreshold(
106     void *hDeviceContext
107     );
108 /*---------------------  Export Variables  --------------------------*/
109
110
111 /*---------------------  Export Functions  --------------------------*/
112
113
114
115
116
117 /*+
118  *
119  * Routine Description:
120  *    Search known BSS list for Desire SSID or BSSID.
121  *
122  * Return Value:
123  *    PTR to KnownBSS or NULL
124  *
125 -*/
126
127 PKnownBSS
128 BSSpSearchBSSList(
129     void *hDeviceContext,
130     unsigned char *pbyDesireBSSID,
131     unsigned char *pbyDesireSSID,
132     CARD_PHY_TYPE  ePhyType
133     )
134 {
135     PSDevice        pDevice = (PSDevice)hDeviceContext;
136     PSMgmtObject    pMgmt = pDevice->pMgmt;
137     unsigned char *pbyBSSID = NULL;
138     PWLAN_IE_SSID   pSSID = NULL;
139     PKnownBSS       pCurrBSS = NULL;
140     PKnownBSS       pSelect = NULL;
141     unsigned char ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
142     unsigned int ii = 0;
143
144     if (pbyDesireBSSID != NULL) {
145         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSpSearchBSSList BSSID[%02X %02X %02X-%02X %02X %02X]\n",
146                             *pbyDesireBSSID,*(pbyDesireBSSID+1),*(pbyDesireBSSID+2),
147                             *(pbyDesireBSSID+3),*(pbyDesireBSSID+4),*(pbyDesireBSSID+5));
148         if ((!is_broadcast_ether_addr(pbyDesireBSSID)) &&
149              (memcmp(pbyDesireBSSID, ZeroBSSID, 6)!= 0)){
150             pbyBSSID = pbyDesireBSSID;
151         }
152     }
153     if (pbyDesireSSID != NULL) {
154         if (((PWLAN_IE_SSID)pbyDesireSSID)->len != 0) {
155             pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
156         }
157     }
158
159     if (pbyBSSID != NULL) {
160         // match BSSID first
161         for (ii = 0; ii <MAX_BSS_NUM; ii++) {
162             pCurrBSS = &(pMgmt->sBSSList[ii]);
163 if(pDevice->bLinkPass==FALSE) pCurrBSS->bSelected = FALSE;
164             if ((pCurrBSS->bActive) &&
165                 (pCurrBSS->bSelected == FALSE)) {
166                 if (!compare_ether_addr(pCurrBSS->abyBSSID, pbyBSSID)) {
167                     if (pSSID != NULL) {
168                         // compare ssid
169                         if ( !memcmp(pSSID->abySSID,
170                             ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
171                             pSSID->len)) {
172                             if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
173                                 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
174                                 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
175                                 ) {
176                                 pCurrBSS->bSelected = TRUE;
177                                 return(pCurrBSS);
178                             }
179                         }
180                     } else {
181                         if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
182                             ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
183                             ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
184                             ) {
185                             pCurrBSS->bSelected = TRUE;
186                             return(pCurrBSS);
187                         }
188                     }
189                 }
190             }
191         }
192     } else {
193         // ignore BSSID
194         for (ii = 0; ii <MAX_BSS_NUM; ii++) {
195             pCurrBSS = &(pMgmt->sBSSList[ii]);
196         //2007-0721-01<Add>by MikeLiu
197           pCurrBSS->bSelected = FALSE;
198           if (pCurrBSS->bActive) {
199
200                 if (pSSID != NULL) {
201                     // matched SSID
202                     if (! !memcmp(pSSID->abySSID,
203                         ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
204                         pSSID->len) ||
205                         (pSSID->len != ((PWLAN_IE_SSID)pCurrBSS->abySSID)->len)) {
206                         // SSID not match skip this BSS
207                         continue;
208                       }
209                 }
210                 if (((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) ||
211                     ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo))
212                     ){
213                     // Type not match skip this BSS
214                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSS type mismatch.... Config[%d] BSS[0x%04x]\n", pMgmt->eConfigMode, pCurrBSS->wCapInfo);
215                     continue;
216                 }
217
218                 if (ePhyType != PHY_TYPE_AUTO) {
219                     if (((ePhyType == PHY_TYPE_11A) && (PHY_TYPE_11A != pCurrBSS->eNetworkTypeInUse)) ||
220                         ((ePhyType != PHY_TYPE_11A) && (PHY_TYPE_11A == pCurrBSS->eNetworkTypeInUse))) {
221                         // PhyType not match skip this BSS
222                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Physical type mismatch.... ePhyType[%d] BSS[%d]\n", ePhyType, pCurrBSS->eNetworkTypeInUse);
223                         continue;
224                     }
225                 }
226 /*
227                 if (pMgmt->eAuthenMode < WMAC_AUTH_WPA) {
228                     if (pCurrBSS->bWPAValid == TRUE) {
229                         // WPA AP will reject connection of station without WPA enable.
230                         continue;
231                     }
232                 } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
233                            (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
234                     if (pCurrBSS->bWPAValid == FALSE) {
235                         // station with WPA enable can't join NonWPA AP.
236                         continue;
237                     }
238                 } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
239                            (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
240                     if (pCurrBSS->bWPA2Valid == FALSE) {
241                         // station with WPA2 enable can't join NonWPA2 AP.
242                         continue;
243                     }
244                 }
245 */
246                 if (pSelect == NULL) {
247                     pSelect = pCurrBSS;
248                 } else {
249                     // compare RSSI, select signal strong one
250                     if (pCurrBSS->uRSSI < pSelect->uRSSI) {
251                         pSelect = pCurrBSS;
252                     }
253                 }
254             }
255         }
256         if (pSelect != NULL) {
257             pSelect->bSelected = TRUE;
258 /*
259                         if (pDevice->bRoaming == FALSE)  {
260         //       Einsn Add @20070907
261                         memset(pbyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
262                         memcpy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1) ;
263                                                 }*/
264
265             return(pSelect);
266         }
267     }
268     return(NULL);
269
270 }
271
272
273 /*+
274  *
275  * Routine Description:
276  *    Clear BSS List
277  *
278  * Return Value:
279  *    None.
280  *
281 -*/
282
283
284 void
285 BSSvClearBSSList(
286     void *hDeviceContext,
287     BOOL bKeepCurrBSSID
288     )
289 {
290     PSDevice     pDevice = (PSDevice)hDeviceContext;
291     PSMgmtObject    pMgmt = pDevice->pMgmt;
292     unsigned int ii;
293
294     for (ii = 0; ii < MAX_BSS_NUM; ii++) {
295         if (bKeepCurrBSSID) {
296             if (pMgmt->sBSSList[ii].bActive &&
297                 !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID, pMgmt->abyCurrBSSID)) {
298                // bKeepCurrBSSID = FALSE;
299                 continue;
300             }
301         }
302
303         if ((pMgmt->sBSSList[ii].bActive) && (pMgmt->sBSSList[ii].uClearCount < BSS_CLEAR_COUNT)) {
304              pMgmt->sBSSList[ii].uClearCount ++;
305              continue;
306         }
307
308         pMgmt->sBSSList[ii].bActive = FALSE;
309         memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS));
310     }
311     BSSvClearAnyBSSJoinRecord(pDevice);
312
313     return;
314 }
315
316
317
318 /*+
319  *
320  * Routine Description:
321  *    search BSS list by BSSID & SSID if matched
322  *
323  * Return Value:
324  *    TRUE if found.
325  *
326 -*/
327 PKnownBSS
328 BSSpAddrIsInBSSList(
329     void *hDeviceContext,
330     unsigned char *abyBSSID,
331     PWLAN_IE_SSID pSSID
332     )
333 {
334     PSDevice     pDevice = (PSDevice)hDeviceContext;
335     PSMgmtObject    pMgmt = pDevice->pMgmt;
336     PKnownBSS       pBSSList = NULL;
337     unsigned int ii;
338
339     for (ii = 0; ii < MAX_BSS_NUM; ii++) {
340         pBSSList = &(pMgmt->sBSSList[ii]);
341         if (pBSSList->bActive) {
342             if (!compare_ether_addr(pBSSList->abyBSSID, abyBSSID)) {
343 //                if (pSSID == NULL)
344 //                    return pBSSList;
345                 if (pSSID->len == ((PWLAN_IE_SSID)pBSSList->abySSID)->len){
346                     if (memcmp(pSSID->abySSID,
347                             ((PWLAN_IE_SSID)pBSSList->abySSID)->abySSID,
348                             pSSID->len) == 0)
349                         return pBSSList;
350                 }
351             }
352         }
353     }
354
355     return NULL;
356 };
357
358
359
360 /*+
361  *
362  * Routine Description:
363  *    Insert a BSS set into known BSS list
364  *
365  * Return Value:
366  *    TRUE if success.
367  *
368 -*/
369
370 BOOL
371 BSSbInsertToBSSList (
372     void *hDeviceContext,
373     unsigned char *abyBSSIDAddr,
374     QWORD qwTimestamp,
375     unsigned short wBeaconInterval,
376     unsigned short wCapInfo,
377     unsigned char byCurrChannel,
378     PWLAN_IE_SSID pSSID,
379     PWLAN_IE_SUPP_RATES pSuppRates,
380     PWLAN_IE_SUPP_RATES pExtSuppRates,
381     PERPObject psERP,
382     PWLAN_IE_RSN pRSN,
383     PWLAN_IE_RSN_EXT pRSNWPA,
384     PWLAN_IE_COUNTRY pIE_Country,
385     PWLAN_IE_QUIET pIE_Quiet,
386     unsigned int uIELength,
387     unsigned char *pbyIEs,
388     void *pRxPacketContext
389     )
390 {
391
392     PSDevice     pDevice = (PSDevice)hDeviceContext;
393     PSMgmtObject    pMgmt = pDevice->pMgmt;
394     PSRxMgmtPacket  pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
395     PKnownBSS       pBSSList = NULL;
396     unsigned int ii;
397     BOOL            bParsingQuiet = FALSE;
398     PWLAN_IE_QUIET  pQuiet = NULL;
399
400
401
402     pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
403
404     for (ii = 0; ii < MAX_BSS_NUM; ii++) {
405         pBSSList = (PKnownBSS)&(pMgmt->sBSSList[ii]);
406         if (!pBSSList->bActive)
407                 break;
408     }
409
410     if (ii == MAX_BSS_NUM){
411         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n");
412         return FALSE;
413     }
414     // save the BSS info
415     pBSSList->bActive = TRUE;
416     memcpy( pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
417     HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
418     LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
419     pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
420     pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
421     pBSSList->uClearCount = 0;
422
423     if (pSSID->len > WLAN_SSID_MAXLEN)
424         pSSID->len = WLAN_SSID_MAXLEN;
425     memcpy( pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
426
427     pBSSList->uChannel = byCurrChannel;
428
429     if (pSuppRates->len > WLAN_RATES_MAXLEN)
430         pSuppRates->len = WLAN_RATES_MAXLEN;
431     memcpy( pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
432
433     if (pExtSuppRates != NULL) {
434         if (pExtSuppRates->len > WLAN_RATES_MAXLEN)
435             pExtSuppRates->len = WLAN_RATES_MAXLEN;
436         memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
437         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSbInsertToBSSList: pExtSuppRates->len = %d\n", pExtSuppRates->len);
438
439     } else {
440         memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
441     }
442     pBSSList->sERP.byERP = psERP->byERP;
443     pBSSList->sERP.bERPExist = psERP->bERPExist;
444
445     // Check if BSS is 802.11a/b/g
446     if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
447         pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
448     } else {
449         if (pBSSList->sERP.bERPExist == TRUE) {
450             pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
451         } else {
452             pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
453         }
454     }
455
456     pBSSList->byRxRate = pRxPacket->byRxRate;
457     pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
458     pBSSList->uRSSI = pRxPacket->uRSSI;
459     pBSSList->bySQ = pRxPacket->bySQ;
460
461    if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
462         (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
463         // assoc with BSS
464         if (pBSSList == pMgmt->pCurrBSS) {
465             bParsingQuiet = TRUE;
466         }
467     }
468
469     WPA_ClearRSN(pBSSList);
470
471     if (pRSNWPA != NULL) {
472         unsigned int uLen = pRSNWPA->len + 2;
473
474         if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
475             pBSSList->wWPALen = uLen;
476             memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
477             WPA_ParseRSN(pBSSList, pRSNWPA);
478         }
479     }
480
481     WPA2_ClearRSN(pBSSList);
482
483     if (pRSN != NULL) {
484         unsigned int uLen = pRSN->len + 2;
485         if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
486             pBSSList->wRSNLen = uLen;
487             memcpy(pBSSList->byRSNIE, pRSN, uLen);
488             WPA2vParseRSN(pBSSList, pRSN);
489         }
490     }
491
492     if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == TRUE)) {
493
494         PSKeyItem  pTransmitKey = NULL;
495         BOOL       bIs802_1x = FALSE;
496
497         for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii ++) {
498             if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
499                 bIs802_1x = TRUE;
500                 break;
501             }
502         }
503         if ((bIs802_1x == TRUE) && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
504             ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
505
506             bAdd_PMKID_Candidate((void *)pDevice, pBSSList->abyBSSID, &pBSSList->sRSNCapObj);
507
508             if ((pDevice->bLinkPass == TRUE) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
509                 if ((KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE) ||
510                     (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey) == TRUE)) {
511                     pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
512                     pDevice->gsPMKIDCandidate.Version = 1;
513
514                 }
515
516             }
517         }
518     }
519
520     if (pDevice->bUpdateBBVGA) {
521         // Moniter if RSSI is too strong.
522         pBSSList->byRSSIStatCnt = 0;
523         RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
524         pBSSList->ldBmAverage[0] = pBSSList->ldBmMAX;
525         for (ii = 1; ii < RSSI_STAT_COUNT; ii++)
526             pBSSList->ldBmAverage[ii] = 0;
527     }
528
529     if ((pIE_Country != NULL) &&
530         (pMgmt->b11hEnable == TRUE)) {
531         set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
532                             pIE_Country);
533     }
534
535     if ((bParsingQuiet == TRUE) && (pIE_Quiet != NULL)) {
536         if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
537             (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
538             // valid EID
539             if (pQuiet == NULL) {
540                 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
541                 CARDbSetQuiet(  pMgmt->pAdapter,
542                                 TRUE,
543                                 pQuiet->byQuietCount,
544                                 pQuiet->byQuietPeriod,
545                                 *((unsigned short *)pQuiet->abyQuietDuration),
546                                 *((unsigned short *)pQuiet->abyQuietOffset)
547                                 );
548             } else {
549                 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
550                 CARDbSetQuiet(  pMgmt->pAdapter,
551                                 FALSE,
552                                 pQuiet->byQuietCount,
553                                 pQuiet->byQuietPeriod,
554                                 *((unsigned short *)pQuiet->abyQuietDuration),
555                                 *((unsigned short *)pQuiet->abyQuietOffset)
556                                 );
557             }
558         }
559     }
560
561     if ((bParsingQuiet == TRUE) &&
562         (pQuiet != NULL)) {
563         CARDbStartQuiet(pMgmt->pAdapter);
564     }
565
566     pBSSList->uIELength = uIELength;
567     if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
568         pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
569     memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
570
571     return TRUE;
572 }
573
574
575 /*+
576  *
577  * Routine Description:
578  *    Update BSS set in known BSS list
579  *
580  * Return Value:
581  *    TRUE if success.
582  *
583 -*/
584 // TODO: input structure modify
585
586 BOOL
587 BSSbUpdateToBSSList (
588     void *hDeviceContext,
589     QWORD qwTimestamp,
590     unsigned short wBeaconInterval,
591     unsigned short wCapInfo,
592     unsigned char byCurrChannel,
593     BOOL bChannelHit,
594     PWLAN_IE_SSID pSSID,
595     PWLAN_IE_SUPP_RATES pSuppRates,
596     PWLAN_IE_SUPP_RATES pExtSuppRates,
597     PERPObject psERP,
598     PWLAN_IE_RSN pRSN,
599     PWLAN_IE_RSN_EXT pRSNWPA,
600     PWLAN_IE_COUNTRY pIE_Country,
601     PWLAN_IE_QUIET pIE_Quiet,
602     PKnownBSS pBSSList,
603     unsigned int uIELength,
604     unsigned char *pbyIEs,
605     void *pRxPacketContext
606     )
607 {
608     int             ii;
609     PSDevice        pDevice = (PSDevice)hDeviceContext;
610     PSMgmtObject    pMgmt = pDevice->pMgmt;
611     PSRxMgmtPacket  pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
612     long            ldBm;
613     BOOL            bParsingQuiet = FALSE;
614     PWLAN_IE_QUIET  pQuiet = NULL;
615
616
617
618     if (pBSSList == NULL)
619         return FALSE;
620
621
622     HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
623     LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
624     pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
625     pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
626     pBSSList->uClearCount = 0;
627     pBSSList->uChannel = byCurrChannel;
628 //    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSbUpdateToBSSList: pBSSList->uChannel: %d\n", pBSSList->uChannel);
629
630     if (pSSID->len > WLAN_SSID_MAXLEN)
631         pSSID->len = WLAN_SSID_MAXLEN;
632
633     if ((pSSID->len != 0) && (pSSID->abySSID[0] != 0))
634         memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
635     memcpy(pBSSList->abySuppRates, pSuppRates,pSuppRates->len + WLAN_IEHDR_LEN);
636
637     if (pExtSuppRates != NULL) {
638         memcpy(pBSSList->abyExtSuppRates, pExtSuppRates,pExtSuppRates->len + WLAN_IEHDR_LEN);
639     } else {
640         memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
641     }
642     pBSSList->sERP.byERP = psERP->byERP;
643     pBSSList->sERP.bERPExist = psERP->bERPExist;
644
645     // Check if BSS is 802.11a/b/g
646     if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
647         pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
648     } else {
649         if (pBSSList->sERP.bERPExist == TRUE) {
650             pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
651         } else {
652             pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
653         }
654     }
655
656     pBSSList->byRxRate = pRxPacket->byRxRate;
657     pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
658     if(bChannelHit)
659         pBSSList->uRSSI = pRxPacket->uRSSI;
660     pBSSList->bySQ = pRxPacket->bySQ;
661
662    if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
663         (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
664         // assoc with BSS
665         if (pBSSList == pMgmt->pCurrBSS) {
666             bParsingQuiet = TRUE;
667         }
668     }
669
670    WPA_ClearRSN(pBSSList);         //mike update
671
672     if (pRSNWPA != NULL) {
673         unsigned int uLen = pRSNWPA->len + 2;
674         if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
675             pBSSList->wWPALen = uLen;
676             memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
677             WPA_ParseRSN(pBSSList, pRSNWPA);
678         }
679     }
680
681    WPA2_ClearRSN(pBSSList);  //mike update
682
683     if (pRSN != NULL) {
684         unsigned int uLen = pRSN->len + 2;
685         if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
686             pBSSList->wRSNLen = uLen;
687             memcpy(pBSSList->byRSNIE, pRSN, uLen);
688             WPA2vParseRSN(pBSSList, pRSN);
689         }
690     }
691
692     if (pRxPacket->uRSSI != 0) {
693         RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &ldBm);
694         // Moniter if RSSI is too strong.
695         pBSSList->byRSSIStatCnt++;
696         pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
697         pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
698         for(ii=0;ii<RSSI_STAT_COUNT;ii++) {
699             if (pBSSList->ldBmAverage[ii] != 0) {
700                 pBSSList->ldBmMAX = max(pBSSList->ldBmAverage[ii], ldBm);
701             }
702         }
703     }
704
705     if ((pIE_Country != NULL) &&
706         (pMgmt->b11hEnable == TRUE)) {
707         set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
708                             pIE_Country);
709     }
710
711     if ((bParsingQuiet == TRUE) && (pIE_Quiet != NULL)) {
712         if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
713             (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
714             // valid EID
715             if (pQuiet == NULL) {
716                 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
717                 CARDbSetQuiet(  pMgmt->pAdapter,
718                                 TRUE,
719                                 pQuiet->byQuietCount,
720                                 pQuiet->byQuietPeriod,
721                                 *((unsigned short *)pQuiet->abyQuietDuration),
722                                 *((unsigned short *)pQuiet->abyQuietOffset)
723                                 );
724             } else {
725                 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
726                 CARDbSetQuiet(  pMgmt->pAdapter,
727                                 FALSE,
728                                 pQuiet->byQuietCount,
729                                 pQuiet->byQuietPeriod,
730                                 *((unsigned short *)pQuiet->abyQuietDuration),
731                                 *((unsigned short *)pQuiet->abyQuietOffset)
732                                 );
733             }
734         }
735     }
736
737     if ((bParsingQuiet == TRUE) &&
738         (pQuiet != NULL)) {
739         CARDbStartQuiet(pMgmt->pAdapter);
740     }
741
742     pBSSList->uIELength = uIELength;
743     if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
744         pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
745     memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
746
747     return TRUE;
748 }
749
750
751
752
753
754 /*+
755  *
756  * Routine Description:
757  *    Search Node DB table to find the index of matched DstAddr
758  *
759  * Return Value:
760  *    None
761  *
762 -*/
763
764 BOOL
765 BSSDBbIsSTAInNodeDB(
766     void *pMgmtObject,
767     unsigned char *abyDstAddr,
768     PUINT puNodeIndex
769     )
770 {
771     PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
772     unsigned int ii;
773
774     // Index = 0 reserved for AP Node
775     for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
776         if (pMgmt->sNodeDBTable[ii].bActive) {
777             if (!compare_ether_addr(abyDstAddr, pMgmt->sNodeDBTable[ii].abyMACAddr)) {
778                 *puNodeIndex = ii;
779                 return TRUE;
780             }
781         }
782     }
783
784    return FALSE;
785 };
786
787
788
789 /*+
790  *
791  * Routine Description:
792  *    Find an empty node and allocated; if no empty found,
793  *    instand used of most inactive one.
794  *
795  * Return Value:
796  *    None
797  *
798 -*/
799 void
800 BSSvCreateOneNode(
801     void *hDeviceContext,
802     PUINT puNodeIndex
803     )
804 {
805
806     PSDevice     pDevice = (PSDevice)hDeviceContext;
807     PSMgmtObject    pMgmt = pDevice->pMgmt;
808     unsigned int ii;
809     unsigned int BigestCount = 0;
810     unsigned int SelectIndex;
811     struct sk_buff  *skb;
812     // Index = 0 reserved for AP Node (In STA mode)
813     // Index = 0 reserved for Broadcast/MultiCast (In AP mode)
814     SelectIndex = 1;
815     for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
816         if (pMgmt->sNodeDBTable[ii].bActive) {
817             if (pMgmt->sNodeDBTable[ii].uInActiveCount > BigestCount) {
818                 BigestCount = pMgmt->sNodeDBTable[ii].uInActiveCount;
819                 SelectIndex = ii;
820             }
821         }
822         else {
823             break;
824         }
825     }
826
827     // if not found replace uInActiveCount is largest one.
828     if ( ii == (MAX_NODE_NUM + 1)) {
829         *puNodeIndex = SelectIndex;
830         DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Replace inactive node = %d\n", SelectIndex);
831         // clear ps buffer
832         if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
833             while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
834             dev_kfree_skb(skb);
835         }
836     }
837     else {
838         *puNodeIndex = ii;
839     }
840
841     memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
842     pMgmt->sNodeDBTable[*puNodeIndex].bActive = TRUE;
843     pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
844     // for AP mode PS queue
845     skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
846     pMgmt->sNodeDBTable[*puNodeIndex].byAuthSequence = 0;
847     pMgmt->sNodeDBTable[*puNodeIndex].wEnQueueCnt = 0;
848     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create node index = %d\n", ii);
849     return;
850 };
851
852
853
854 /*+
855  *
856  * Routine Description:
857  *    Remove Node by NodeIndex
858  *
859  *
860  * Return Value:
861  *    None
862  *
863 -*/
864 void
865 BSSvRemoveOneNode(
866     void *hDeviceContext,
867     unsigned int uNodeIndex
868     )
869 {
870
871     PSDevice        pDevice = (PSDevice)hDeviceContext;
872     PSMgmtObject    pMgmt = pDevice->pMgmt;
873     unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
874     struct sk_buff  *skb;
875
876
877     while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
878             dev_kfree_skb(skb);
879     // clear context
880     memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
881     // clear tx bit map
882     pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &=  ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
883
884     return;
885 };
886 /*+
887  *
888  * Routine Description:
889  *    Update AP Node content in Index 0 of KnownNodeDB
890  *
891  *
892  * Return Value:
893  *    None
894  *
895 -*/
896
897 void
898 BSSvUpdateAPNode(
899     void *hDeviceContext,
900     unsigned short *pwCapInfo,
901     PWLAN_IE_SUPP_RATES pSuppRates,
902     PWLAN_IE_SUPP_RATES pExtSuppRates
903     )
904 {
905     PSDevice     pDevice = (PSDevice)hDeviceContext;
906     PSMgmtObject    pMgmt = pDevice->pMgmt;
907     unsigned int uRateLen = WLAN_RATES_MAXLEN;
908
909     memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
910
911     pMgmt->sNodeDBTable[0].bActive = TRUE;
912     if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
913         uRateLen = WLAN_RATES_MAXLEN_11B;
914     }
915     pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
916                                             (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
917                                             uRateLen);
918     pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
919                                             (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
920                                             uRateLen);
921     RATEvParseMaxRate((void *)pDevice,
922                        (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
923                        (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
924                        TRUE,
925                        &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
926                        &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
927                        &(pMgmt->sNodeDBTable[0].wSuppRate),
928                        &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
929                        &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
930                       );
931     memcpy(pMgmt->sNodeDBTable[0].abyMACAddr, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
932     pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxSuppRate;
933     pMgmt->sNodeDBTable[0].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo);
934     pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
935 #ifdef  PLICE_DEBUG
936         printk("BSSvUpdateAPNode:MaxSuppRate is %d\n",pMgmt->sNodeDBTable[0].wMaxSuppRate);
937 #endif
938     // Auto rate fallback function initiation.
939     // RATEbInit(pDevice);
940     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pMgmt->sNodeDBTable[0].wTxDataRate = %d \n", pMgmt->sNodeDBTable[0].wTxDataRate);
941
942 };
943
944
945
946
947
948 /*+
949  *
950  * Routine Description:
951  *    Add Multicast Node content in Index 0 of KnownNodeDB
952  *
953  *
954  * Return Value:
955  *    None
956  *
957 -*/
958
959
960 void
961 BSSvAddMulticastNode(
962     void *hDeviceContext
963     )
964 {
965     PSDevice     pDevice = (PSDevice)hDeviceContext;
966     PSMgmtObject    pMgmt = pDevice->pMgmt;
967
968     if (!pDevice->bEnableHostWEP)
969         memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
970     memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
971     pMgmt->sNodeDBTable[0].bActive = TRUE;
972     pMgmt->sNodeDBTable[0].bPSEnable = FALSE;
973     skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
974     RATEvParseMaxRate((void *)pDevice,
975                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
976                       (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
977                       TRUE,
978                       &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
979                       &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
980                        &(pMgmt->sNodeDBTable[0].wSuppRate),
981                       &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
982                       &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
983                      );
984     pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
985 #ifdef  PLICE_DEBUG
986         printk("BSSvAddMultiCastNode:pMgmt->sNodeDBTable[0].wTxDataRate is %d\n",pMgmt->sNodeDBTable[0].wTxDataRate);
987 #endif
988     pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
989
990 };
991
992
993
994
995
996 /*+
997  *
998  * Routine Description:
999  *
1000  *
1001  *  Second call back function to update Node DB info & AP link status
1002  *
1003  *
1004  * Return Value:
1005  *    none.
1006  *
1007 -*/
1008  //2008-4-14 <add> by chester for led issue
1009  #ifdef FOR_LED_ON_NOTEBOOK
1010 BOOL cc=FALSE;
1011 unsigned int status;
1012 #endif
1013 void
1014 BSSvSecondCallBack(
1015     void *hDeviceContext
1016     )
1017 {
1018     PSDevice        pDevice = (PSDevice)hDeviceContext;
1019     PSMgmtObject    pMgmt = pDevice->pMgmt;
1020     unsigned int ii;
1021     PWLAN_IE_SSID   pItemSSID, pCurrSSID;
1022     unsigned int uSleepySTACnt = 0;
1023     unsigned int uNonShortSlotSTACnt = 0;
1024     unsigned int uLongPreambleSTACnt = 0;
1025     viawget_wpa_header* wpahdr;  //DavidWang
1026
1027     spin_lock_irq(&pDevice->lock);
1028
1029     pDevice->uAssocCount = 0;
1030
1031     pDevice->byERPFlag &=
1032         ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
1033  //2008-4-14 <add> by chester for led issue
1034 #ifdef FOR_LED_ON_NOTEBOOK
1035 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
1036 if ((( !(pDevice->byGPIO & GPIO0_DATA)&&(pDevice->bHWRadioOff == FALSE))||((pDevice->byGPIO & GPIO0_DATA)&&(pDevice->bHWRadioOff == TRUE)))&&(cc==FALSE)){
1037 cc=TRUE;
1038 }
1039 else if(cc==TRUE){
1040
1041 if(pDevice->bHWRadioOff == TRUE){
1042             if ( !(pDevice->byGPIO & GPIO0_DATA))
1043 //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
1044 {if(status==1) goto start;
1045 status=1;
1046 CARDbRadioPowerOff(pDevice);
1047                 pMgmt->sNodeDBTable[0].bActive = FALSE;
1048                 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1049                 pMgmt->eCurrState = WMAC_STATE_IDLE;
1050                 //netif_stop_queue(pDevice->dev);
1051                 pDevice->bLinkPass = FALSE;
1052
1053 }
1054   if (pDevice->byGPIO &GPIO0_DATA)
1055 //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
1056 {if(status==2) goto start;
1057 status=2;
1058 CARDbRadioPowerOn(pDevice);
1059 } }
1060 else{
1061             if (pDevice->byGPIO & GPIO0_DATA)
1062 //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
1063 {if(status==3) goto start;
1064 status=3;
1065 CARDbRadioPowerOff(pDevice);
1066                 pMgmt->sNodeDBTable[0].bActive = FALSE;
1067                 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1068                 pMgmt->eCurrState = WMAC_STATE_IDLE;
1069                 //netif_stop_queue(pDevice->dev);
1070                 pDevice->bLinkPass = FALSE;
1071
1072 }
1073   if ( !(pDevice->byGPIO & GPIO0_DATA))
1074 //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
1075 {if(status==4) goto start;
1076 status=4;
1077 CARDbRadioPowerOn(pDevice);
1078 } }
1079 }
1080 start:
1081 #endif
1082
1083
1084     if (pDevice->wUseProtectCntDown > 0) {
1085         pDevice->wUseProtectCntDown --;
1086     }
1087     else {
1088         // disable protect mode
1089         pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
1090     }
1091
1092 {
1093        pDevice->byReAssocCount++;
1094    if((pDevice->byReAssocCount > 10) && (pDevice->bLinkPass != TRUE)) {  //10 sec timeout
1095                      printk("Re-association timeout!!!\n");
1096                    pDevice->byReAssocCount = 0;
1097                      #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1098                     // if(pDevice->bWPASuppWextEnabled == TRUE)
1099                         {
1100                         union iwreq_data  wrqu;
1101                         memset(&wrqu, 0, sizeof (wrqu));
1102                           wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1103                         PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1104                         wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1105                        }
1106                     #endif
1107      }
1108    else if(pDevice->bLinkPass == TRUE)
1109         pDevice->byReAssocCount = 0;
1110 }
1111
1112 #ifdef Calcu_LinkQual
1113    s_uCalculateLinkQual((void *)pDevice);
1114 #endif
1115
1116     for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
1117
1118         if (pMgmt->sNodeDBTable[ii].bActive) {
1119             // Increase in-activity counter
1120             pMgmt->sNodeDBTable[ii].uInActiveCount++;
1121
1122             if (ii > 0) {
1123                 if (pMgmt->sNodeDBTable[ii].uInActiveCount > MAX_INACTIVE_COUNT) {
1124                     BSSvRemoveOneNode(pDevice, ii);
1125                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1126                         "Inactive timeout [%d] sec, STA index = [%d] remove\n", MAX_INACTIVE_COUNT, ii);
1127                     continue;
1128                 }
1129
1130                 if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
1131
1132                     pDevice->uAssocCount++;
1133
1134                     // check if Non ERP exist
1135                     if (pMgmt->sNodeDBTable[ii].uInActiveCount < ERP_RECOVER_COUNT) {
1136                         if (!pMgmt->sNodeDBTable[ii].bShortPreamble) {
1137                             pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
1138                             uLongPreambleSTACnt ++;
1139                         }
1140                         if (!pMgmt->sNodeDBTable[ii].bERPExist) {
1141                             pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
1142                             pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1143                         }
1144                         if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
1145                             uNonShortSlotSTACnt++;
1146                     }
1147                 }
1148
1149                 // check if any STA in PS mode
1150                 if (pMgmt->sNodeDBTable[ii].bPSEnable)
1151                     uSleepySTACnt++;
1152
1153
1154             }
1155
1156             // Rate fallback check
1157             if (!pDevice->bFixRate) {
1158 /*
1159                 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (ii == 0))
1160                     RATEvTxRateFallBack(pDevice, &(pMgmt->sNodeDBTable[ii]));
1161 */
1162                 if (ii > 0) {
1163                     // ii = 0 for multicast node (AP & Adhoc)
1164                     RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
1165                 }
1166                 else {
1167                     // ii = 0 reserved for unicast AP node (Infra STA)
1168                     if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
1169 #ifdef  PLICE_DEBUG
1170                 printk("SecondCallback:Before:TxDataRate is %d\n",pMgmt->sNodeDBTable[0].wTxDataRate);
1171 #endif
1172                         RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
1173 #ifdef  PLICE_DEBUG
1174                 printk("SecondCallback:After:TxDataRate is %d\n",pMgmt->sNodeDBTable[0].wTxDataRate);
1175 #endif
1176
1177                 }
1178
1179             }
1180
1181             // check if pending PS queue
1182             if (pMgmt->sNodeDBTable[ii].wEnQueueCnt != 0) {
1183                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index= %d, Queue = %d pending \n",
1184                            ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
1185                 if ((ii >0) && (pMgmt->sNodeDBTable[ii].wEnQueueCnt > 15)) {
1186                     BSSvRemoveOneNode(pDevice, ii);
1187                     DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Pending many queues PS STA Index = %d remove \n", ii);
1188                     continue;
1189                 }
1190             }
1191         }
1192
1193     }
1194
1195
1196     if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->eCurrentPHYType == PHY_TYPE_11G)) {
1197
1198         // on/off protect mode
1199         if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
1200             if (!pDevice->bProtectMode) {
1201                 MACvEnableProtectMD(pDevice->PortOffset);
1202                 pDevice->bProtectMode = TRUE;
1203             }
1204         }
1205         else {
1206             if (pDevice->bProtectMode) {
1207                 MACvDisableProtectMD(pDevice->PortOffset);
1208                 pDevice->bProtectMode = FALSE;
1209             }
1210         }
1211         // on/off short slot time
1212
1213         if (uNonShortSlotSTACnt > 0) {
1214             if (pDevice->bShortSlotTime) {
1215                 pDevice->bShortSlotTime = FALSE;
1216                 BBvSetShortSlotTime(pDevice);
1217                 vUpdateIFS((void *)pDevice);
1218             }
1219         }
1220         else {
1221             if (!pDevice->bShortSlotTime) {
1222                 pDevice->bShortSlotTime = TRUE;
1223                 BBvSetShortSlotTime(pDevice);
1224                 vUpdateIFS((void *)pDevice);
1225             }
1226         }
1227
1228         // on/off barker long preamble mode
1229
1230         if (uLongPreambleSTACnt > 0) {
1231             if (!pDevice->bBarkerPreambleMd) {
1232                 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
1233                 pDevice->bBarkerPreambleMd = TRUE;
1234             }
1235         }
1236         else {
1237             if (pDevice->bBarkerPreambleMd) {
1238                 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
1239                 pDevice->bBarkerPreambleMd = FALSE;
1240             }
1241         }
1242
1243     }
1244
1245
1246     // Check if any STA in PS mode, enable DTIM multicast deliver
1247     if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1248         if (uSleepySTACnt > 0)
1249             pMgmt->sNodeDBTable[0].bPSEnable = TRUE;
1250         else
1251             pMgmt->sNodeDBTable[0].bPSEnable = FALSE;
1252     }
1253
1254     pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
1255     pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
1256
1257     if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
1258         (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
1259
1260         if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
1261            // DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Callback inactive Count = [%d]\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1262             //if (pDevice->bUpdateBBVGA) {
1263             //  s_vCheckSensitivity((void *) pDevice);
1264             //}
1265
1266             if (pDevice->bUpdateBBVGA) {
1267                // s_vCheckSensitivity((void *) pDevice);
1268                s_vCheckPreEDThreshold((void *)pDevice);
1269             }
1270
1271             if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
1272                 (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0]) ) {
1273                 pDevice->byBBVGANew = pDevice->abyBBVGA[0];
1274                 bScheduleCommand((void *) pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1275             }
1276
1277                 if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
1278                 pMgmt->sNodeDBTable[0].bActive = FALSE;
1279                 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1280                 pMgmt->eCurrState = WMAC_STATE_IDLE;
1281                 netif_stop_queue(pDevice->dev);
1282                 pDevice->bLinkPass = FALSE;
1283                 pDevice->bRoaming = TRUE;
1284                 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1285         if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1286              wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1287              wpahdr->type = VIAWGET_DISASSOC_MSG;
1288              wpahdr->resp_ie_len = 0;
1289              wpahdr->req_ie_len = 0;
1290              skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1291              pDevice->skb->dev = pDevice->wpadev;
1292              skb_reset_mac_header(pDevice->skb);
1293              pDevice->skb->pkt_type = PACKET_HOST;
1294              pDevice->skb->protocol = htons(ETH_P_802_2);
1295              memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1296              netif_rx(pDevice->skb);
1297              pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1298          };
1299    #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1300   // if(pDevice->bWPASuppWextEnabled == TRUE)
1301       {
1302         union iwreq_data  wrqu;
1303         memset(&wrqu, 0, sizeof (wrqu));
1304         wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1305         PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1306         wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1307      }
1308   #endif
1309             }
1310         }
1311         else if (pItemSSID->len != 0) {
1312             if (pDevice->uAutoReConnectTime < 10) {
1313                 pDevice->uAutoReConnectTime++;
1314                #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1315                 //network manager support need not do Roaming scan???
1316                 if(pDevice->bWPASuppWextEnabled ==TRUE)
1317                  pDevice->uAutoReConnectTime = 0;
1318              #endif
1319             }
1320             else {
1321            //mike use old encryption status for wpa reauthen
1322               if(pDevice->bWPADEVUp)
1323                   pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
1324
1325                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming ...\n");
1326                 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
1327               pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1328                 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
1329                 bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
1330                 pDevice->uAutoReConnectTime = 0;
1331             }
1332         }
1333     }
1334
1335     if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1336         // if adhoc started which essid is NULL string, rescaning.
1337         if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
1338             if (pDevice->uAutoReConnectTime < 10) {
1339                 pDevice->uAutoReConnectTime++;
1340             }
1341             else {
1342                 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Adhoc re-scaning ...\n");
1343               pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1344                 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1345                 bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
1346                 pDevice->uAutoReConnectTime = 0;
1347             };
1348         }
1349         if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
1350
1351             if (pDevice->bUpdateBBVGA) {
1352                //s_vCheckSensitivity((void *) pDevice);
1353                s_vCheckPreEDThreshold((void *)pDevice);
1354             }
1355                 if (pMgmt->sNodeDBTable[0].uInActiveCount >=ADHOC_LOST_BEACON_COUNT) {
1356                     DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1357                 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1358                 pMgmt->eCurrState = WMAC_STATE_STARTED;
1359                 netif_stop_queue(pDevice->dev);
1360                 pDevice->bLinkPass = FALSE;
1361             }
1362         }
1363     }
1364
1365     spin_unlock_irq(&pDevice->lock);
1366
1367     pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
1368     add_timer(&pMgmt->sTimerSecondCallback);
1369     return;
1370 }
1371
1372
1373
1374
1375 /*+
1376  *
1377  * Routine Description:
1378  *
1379  *
1380  *  Update Tx attemps, Tx failure counter in Node DB
1381  *
1382  *
1383  * Return Value:
1384  *    none.
1385  *
1386 -*/
1387
1388
1389
1390 void
1391 BSSvUpdateNodeTxCounter(
1392     void *hDeviceContext,
1393     unsigned char byTsr0,
1394     unsigned char byTsr1,
1395     unsigned char *pbyBuffer,
1396     unsigned int uFIFOHeaderSize
1397     )
1398 {
1399     PSDevice        pDevice = (PSDevice)hDeviceContext;
1400     PSMgmtObject    pMgmt = pDevice->pMgmt;
1401     unsigned int uNodeIndex = 0;
1402     unsigned char byTxRetry = (byTsr0 & TSR0_NCR);
1403     PSTxBufHead     pTxBufHead;
1404     PS802_11Header  pMACHeader;
1405     unsigned short wRate;
1406     unsigned short wFallBackRate = RATE_1M;
1407     unsigned char byFallBack;
1408     unsigned int ii;
1409 //      unsigned int txRetryTemp;
1410 //PLICE_DEBUG->
1411         //txRetryTemp = byTxRetry;
1412         //if (txRetryTemp== 8)
1413         //txRetryTemp -=3;
1414 //PLICE_DEBUG <-
1415     pTxBufHead = (PSTxBufHead) pbyBuffer;
1416     if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_0) {
1417         byFallBack = AUTO_FB_0;
1418     } else if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_1) {
1419         byFallBack = AUTO_FB_1;
1420     } else {
1421         byFallBack = AUTO_FB_NONE;
1422     }
1423     wRate = pTxBufHead->wReserved; //?wRate
1424     //printk("BSSvUpdateNodeTxCounter:byTxRetry is %d\n",byTxRetry);
1425
1426 //printk("BSSvUpdateNodeTx:wRate is %d,byFallback is %d\n",wRate,byFallBack);
1427 //#ifdef        PLICE_DEBUG
1428         //printk("BSSvUpdateNodeTx: wRate is %d\n",wRate);
1429 ////#endif
1430     // Only Unicast using support rates
1431     if (pTxBufHead->wFIFOCtl & FIFOCTL_NEEDACK) {
1432         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wRate %04X, byTsr0 %02X, byTsr1 %02X\n", wRate, byTsr0, byTsr1);
1433         if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
1434             pMgmt->sNodeDBTable[0].uTxAttempts += 1;
1435             if ((byTsr1 & TSR1_TERR) == 0) {
1436                 // transmit success, TxAttempts at least plus one
1437                 pMgmt->sNodeDBTable[0].uTxOk[MAX_RATE]++;
1438                 if ( (byFallBack == AUTO_FB_NONE) ||
1439                      (wRate < RATE_18M) ) {
1440                     wFallBackRate = wRate;
1441                 } else if (byFallBack == AUTO_FB_0) {
1442 //PLICE_DEBUG
1443                                   if (byTxRetry < 5)
1444                                 //if (txRetryTemp < 5)
1445                                         wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1446                         //wFallBackRate = awHWRetry0[wRate-RATE_12M][byTxRetry];
1447                         //wFallBackRate = awHWRetry0[wRate-RATE_18M][txRetryTemp] +1;
1448                 else
1449                         wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1450                         //wFallBackRate = awHWRetry0[wRate-RATE_12M][4];
1451                 } else if (byFallBack == AUTO_FB_1) {
1452                     if (byTxRetry < 5)
1453                         wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1454                     else
1455                         wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1456                 }
1457                 pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
1458             } else {
1459                 pMgmt->sNodeDBTable[0].uTxFailures ++;
1460             }
1461             pMgmt->sNodeDBTable[0].uTxRetry += byTxRetry;
1462             if (byTxRetry != 0) {
1463                 pMgmt->sNodeDBTable[0].uTxFail[MAX_RATE]+=byTxRetry;
1464                 if ( (byFallBack == AUTO_FB_NONE) ||
1465                      (wRate < RATE_18M) ) {
1466                     pMgmt->sNodeDBTable[0].uTxFail[wRate]+=byTxRetry;
1467                 } else if (byFallBack == AUTO_FB_0) {
1468 //PLICE_DEBUG
1469                                    for(ii=0;ii<byTxRetry;ii++)
1470                 //for (ii=0;ii<txRetryTemp;ii++)
1471                 {
1472                         if (ii < 5)
1473                                 {
1474
1475 //PLICE_DEBUG
1476                                                 wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
1477                                         //printk(" II is %d:BSSvUpdateNodeTx:wFallBackRate is %d\n",ii,wFallBackRate);
1478                                 //wFallBackRate = awHWRetry0[wRate-RATE_12M][ii];
1479                                 }
1480                         else
1481                                 {
1482                         wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1483                         //printk("ii is %d BSSvUpdateNodeTx:wFallBackRate is %d\n",ii,wFallBackRate);
1484                                 //wFallBackRate = awHWRetry0[wRate-RATE_12M][4];
1485                                 }
1486                                                 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1487                     }
1488                 } else if (byFallBack == AUTO_FB_1) {
1489                     for(ii=0;ii<byTxRetry;ii++) {
1490                         if (ii < 5)
1491                             wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1492                         else
1493                             wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1494                         pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1495                     }
1496                 }
1497             }
1498         };
1499
1500         if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
1501             (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1502
1503             pMACHeader = (PS802_11Header)(pbyBuffer + uFIFOHeaderSize);
1504
1505             if (BSSDBbIsSTAInNodeDB((void *)pMgmt, &(pMACHeader->abyAddr1[0]), &uNodeIndex)){
1506                 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
1507                 if ((byTsr1 & TSR1_TERR) == 0) {
1508                     // transmit success, TxAttempts at least plus one
1509                     pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
1510                     if ( (byFallBack == AUTO_FB_NONE) ||
1511                          (wRate < RATE_18M) ) {
1512                         wFallBackRate = wRate;
1513                     } else if (byFallBack == AUTO_FB_0) {
1514                         if (byTxRetry < 5)
1515                             wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1516                         else
1517                             wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1518                     } else if (byFallBack == AUTO_FB_1) {
1519                         if (byTxRetry < 5)
1520                             wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1521                         else
1522                             wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1523                     }
1524                     pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
1525                 } else {
1526                     pMgmt->sNodeDBTable[uNodeIndex].uTxFailures ++;
1527                 }
1528                 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += byTxRetry;
1529                 if (byTxRetry != 0) {
1530                     pMgmt->sNodeDBTable[uNodeIndex].uTxFail[MAX_RATE]+=byTxRetry;
1531                     if ( (byFallBack == AUTO_FB_NONE) ||
1532                          (wRate < RATE_18M) ) {
1533                         pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wRate]+=byTxRetry;
1534                     } else if (byFallBack == AUTO_FB_0) {
1535                         for(ii=0;ii<byTxRetry;ii++) {
1536                             if (ii < 5)
1537                                 wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
1538                             else
1539                                 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1540                             pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1541                         }
1542                     } else if (byFallBack == AUTO_FB_1) {
1543                         for(ii=0;ii<byTxRetry;ii++) {
1544                             if (ii < 5)
1545                                 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1546                             else
1547                                 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1548                             pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1549                         }
1550                     }
1551                 }
1552             };
1553         }
1554     };
1555
1556     return;
1557
1558
1559 }
1560
1561
1562
1563
1564 /*+
1565  *
1566  * Routine Description:
1567  *    Clear Nodes & skb in DB Table
1568  *
1569  *
1570  * Parameters:
1571  *  In:
1572  *      hDeviceContext        - The adapter context.
1573  *      uStartIndex           - starting index
1574  *  Out:
1575  *      none
1576  *
1577  * Return Value:
1578  *    None.
1579  *
1580 -*/
1581
1582
1583 void
1584 BSSvClearNodeDBTable(
1585     void *hDeviceContext,
1586     unsigned int uStartIndex
1587     )
1588
1589 {
1590     PSDevice     pDevice = (PSDevice)hDeviceContext;
1591     PSMgmtObject    pMgmt = pDevice->pMgmt;
1592     struct sk_buff  *skb;
1593     unsigned int ii;
1594
1595     for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
1596         if (pMgmt->sNodeDBTable[ii].bActive) {
1597             // check if sTxPSQueue has been initial
1598             if (pMgmt->sNodeDBTable[ii].sTxPSQueue.next != NULL) {
1599                 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL){
1600                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS skb != NULL %d\n", ii);
1601                         dev_kfree_skb(skb);
1602                 }
1603             }
1604             memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
1605         }
1606     }
1607
1608     return;
1609 };
1610
1611
1612 void s_vCheckSensitivity(
1613     void *hDeviceContext
1614     )
1615 {
1616     PSDevice        pDevice = (PSDevice)hDeviceContext;
1617     PKnownBSS       pBSSList = NULL;
1618     PSMgmtObject    pMgmt = pDevice->pMgmt;
1619     int             ii;
1620
1621     if ((pDevice->byLocalID <= REV_ID_VT3253_A1) && (pDevice->byRFType == RF_RFMD2959) &&
1622         (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
1623         return;
1624     }
1625
1626     if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1627         ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1628         pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1629         if (pBSSList != NULL) {
1630             // Updata BB Reg if RSSI is too strong.
1631             long    LocalldBmAverage = 0;
1632             long    uNumofdBm = 0;
1633             for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
1634                 if (pBSSList->ldBmAverage[ii] != 0) {
1635                     uNumofdBm ++;
1636                     LocalldBmAverage += pBSSList->ldBmAverage[ii];
1637                 }
1638             }
1639             if (uNumofdBm > 0) {
1640                 LocalldBmAverage = LocalldBmAverage/uNumofdBm;
1641                 for (ii=0;ii<BB_VGA_LEVEL;ii++) {
1642                     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LocalldBmAverage:%ld, %ld %02x\n", LocalldBmAverage, pDevice->ldBmThreshold[ii], pDevice->abyBBVGA[ii]);
1643                     if (LocalldBmAverage < pDevice->ldBmThreshold[ii]) {
1644                             pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1645                         break;
1646                     }
1647                 }
1648                 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1649                     pDevice->uBBVGADiffCount++;
1650                     if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
1651                         bScheduleCommand((void *) pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1652                 } else {
1653                     pDevice->uBBVGADiffCount = 0;
1654                 }
1655             }
1656         }
1657     }
1658 }
1659
1660
1661 void
1662 BSSvClearAnyBSSJoinRecord (
1663     void *hDeviceContext
1664     )
1665 {
1666     PSDevice        pDevice = (PSDevice)hDeviceContext;
1667     PSMgmtObject    pMgmt = pDevice->pMgmt;
1668     unsigned int ii;
1669
1670     for (ii = 0; ii < MAX_BSS_NUM; ii++) {
1671         pMgmt->sBSSList[ii].bSelected = FALSE;
1672     }
1673     return;
1674 }
1675
1676 #ifdef Calcu_LinkQual
1677 void s_uCalculateLinkQual(
1678     void *hDeviceContext
1679     )
1680 {
1681    PSDevice        pDevice = (PSDevice)hDeviceContext;
1682    unsigned long TxOkRatio, TxCnt;
1683    unsigned long RxOkRatio,RxCnt;
1684    unsigned long RssiRatio;
1685    long ldBm;
1686
1687 TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
1688               pDevice->scStatistic.TxRetryOkCount +
1689               pDevice->scStatistic.TxFailCount;
1690 RxCnt = pDevice->scStatistic.RxFcsErrCnt +
1691               pDevice->scStatistic.RxOkCnt;
1692 TxOkRatio = (TxCnt < 6) ? 4000:((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
1693 RxOkRatio = (RxCnt < 6) ? 2000:((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
1694 //decide link quality
1695 if(pDevice->bLinkPass !=TRUE)
1696 {
1697  //  printk("s_uCalculateLinkQual-->Link disconnect and Poor quality**\n");
1698    pDevice->scStatistic.LinkQuality = 0;
1699    pDevice->scStatistic.SignalStren = 0;
1700 }
1701 else
1702 {
1703    RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
1704    if(-ldBm < 50)  {
1705         RssiRatio = 4000;
1706      }
1707    else if(-ldBm > 90) {
1708         RssiRatio = 0;
1709      }
1710    else {
1711         RssiRatio = (40-(-ldBm-50))*4000/40;
1712      }
1713    pDevice->scStatistic.SignalStren = RssiRatio/40;
1714    pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
1715 }
1716    pDevice->scStatistic.RxFcsErrCnt = 0;
1717    pDevice->scStatistic.RxOkCnt = 0;
1718    pDevice->scStatistic.TxFailCount = 0;
1719    pDevice->scStatistic.TxNoRetryOkCount = 0;
1720    pDevice->scStatistic.TxRetryOkCount = 0;
1721    return;
1722 }
1723 #endif
1724
1725 void s_vCheckPreEDThreshold(
1726     void *hDeviceContext
1727     )
1728 {
1729     PSDevice        pDevice = (PSDevice)hDeviceContext;
1730     PKnownBSS       pBSSList = NULL;
1731     PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
1732
1733     if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1734         ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1735         pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1736         if (pBSSList != NULL) {
1737             pDevice->byBBPreEDRSSI = (unsigned char) (~(pBSSList->ldBmAverRange) + 1);
1738             //BBvUpdatePreEDThreshold(pDevice, FALSE);
1739         }
1740     }
1741     return;
1742 }
1743