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