ASoC: tlv320aic23: Convert to params_width()
[cascardo/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)
146                                 pCurrBSS->bSelected = false;
147                         if ((pCurrBSS->bActive) &&
148                             (!pCurrBSS->bSelected)) {
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)
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) {
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 && (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 && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
449                                 if (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) ||
450                                     KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey)) {
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) && pMgmt->b11hEnable) {
470                 set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
471                                  pIE_Country);
472         }
473
474         if (bParsingQuiet && (pIE_Quiet != NULL)) {
475                 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
476                     (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
477                         /* valid EID */
478                         if (pQuiet == NULL) {
479                                 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
480                                 CARDbSetQuiet(pMgmt->pAdapter,
481                                               true,
482                                               pQuiet->byQuietCount,
483                                               pQuiet->byQuietPeriod,
484                                               *((unsigned short *)pQuiet->abyQuietDuration),
485                                               *((unsigned short *)pQuiet->abyQuietOffset)
486 );
487                         } else {
488                                 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
489                                 CARDbSetQuiet(pMgmt->pAdapter,
490                                               false,
491                                               pQuiet->byQuietCount,
492                                               pQuiet->byQuietPeriod,
493                                               *((unsigned short *)pQuiet->abyQuietDuration),
494                                               *((unsigned short *)pQuiet->abyQuietOffset)
495                                         );
496                         }
497                 }
498         }
499
500         if (bParsingQuiet && (pQuiet != NULL))
501                 CARDbStartQuiet(pMgmt->pAdapter);
502
503         pBSSList->uIELength = uIELength;
504         if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
505                 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
506         memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
507
508         return true;
509 }
510
511 /*+
512  *
513  * Routine Description:
514  *    Update BSS set in known BSS list
515  *
516  * Return Value:
517  *    true if success.
518  *
519  -*/
520 /* TODO: input structure modify */
521
522 bool
523 BSSbUpdateToBSSList(
524         void *hDeviceContext,
525         QWORD qwTimestamp,
526         unsigned short wBeaconInterval,
527         unsigned short wCapInfo,
528         unsigned char byCurrChannel,
529         bool bChannelHit,
530         PWLAN_IE_SSID pSSID,
531         PWLAN_IE_SUPP_RATES pSuppRates,
532         PWLAN_IE_SUPP_RATES pExtSuppRates,
533         PERPObject psERP,
534         PWLAN_IE_RSN pRSN,
535         PWLAN_IE_RSN_EXT pRSNWPA,
536         PWLAN_IE_COUNTRY pIE_Country,
537         PWLAN_IE_QUIET pIE_Quiet,
538         PKnownBSS pBSSList,
539         unsigned int uIELength,
540         unsigned char *pbyIEs,
541         void *pRxPacketContext
542 )
543 {
544         int             ii;
545         PSDevice        pDevice = (PSDevice)hDeviceContext;
546         PSMgmtObject    pMgmt = pDevice->pMgmt;
547         PSRxMgmtPacket  pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
548         long            ldBm;
549         bool bParsingQuiet = false;
550         PWLAN_IE_QUIET  pQuiet = NULL;
551
552         if (pBSSList == NULL)
553                 return false;
554
555         HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
556         LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
557         pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
558         pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
559         pBSSList->uClearCount = 0;
560         pBSSList->uChannel = byCurrChannel;
561
562         if (pSSID->len > WLAN_SSID_MAXLEN)
563                 pSSID->len = WLAN_SSID_MAXLEN;
564
565         if ((pSSID->len != 0) && (pSSID->abySSID[0] != 0))
566                 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
567         memcpy(pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
568
569         if (pExtSuppRates != NULL)
570                 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
571         else
572                 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
573         pBSSList->sERP.byERP = psERP->byERP;
574         pBSSList->sERP.bERPExist = psERP->bERPExist;
575
576         /* check if BSS is 802.11a/b/g */
577         if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
578                 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
579         } else {
580                 if (pBSSList->sERP.bERPExist)
581                         pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
582                 else
583                         pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
584         }
585
586         pBSSList->byRxRate = pRxPacket->byRxRate;
587         pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
588         if (bChannelHit)
589                 pBSSList->uRSSI = pRxPacket->uRSSI;
590         pBSSList->bySQ = pRxPacket->bySQ;
591
592         if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
593             (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
594                 /* assoc with BSS */
595                 if (pBSSList == pMgmt->pCurrBSS)
596                         bParsingQuiet = true;
597         }
598
599         WPA_ClearRSN(pBSSList);         /* mike update */
600
601         if (pRSNWPA != NULL) {
602                 unsigned int uLen = pRSNWPA->len + 2;
603                 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
604                         pBSSList->wWPALen = uLen;
605                         memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
606                         WPA_ParseRSN(pBSSList, pRSNWPA);
607                 }
608         }
609
610         WPA2_ClearRSN(pBSSList);  /* mike update */
611
612         if (pRSN != NULL) {
613                 unsigned int uLen = pRSN->len + 2;
614                 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
615                         pBSSList->wRSNLen = uLen;
616                         memcpy(pBSSList->byRSNIE, pRSN, uLen);
617                         WPA2vParseRSN(pBSSList, pRSN);
618                 }
619         }
620
621         if (pRxPacket->uRSSI != 0) {
622                 RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &ldBm);
623                 /* monitor if RSSI is too strong */
624                 pBSSList->byRSSIStatCnt++;
625                 pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
626                 pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
627                 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
628                         if (pBSSList->ldBmAverage[ii] != 0)
629                                 pBSSList->ldBmMAX = max(pBSSList->ldBmAverage[ii], ldBm);
630                 }
631         }
632
633         if ((pIE_Country != NULL) && pMgmt->b11hEnable) {
634                 set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
635                                  pIE_Country);
636         }
637
638         if (bParsingQuiet && (pIE_Quiet != NULL)) {
639                 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
640                     (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
641                         /* valid EID */
642                         if (pQuiet == NULL) {
643                                 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
644                                 CARDbSetQuiet(pMgmt->pAdapter,
645                                               true,
646                                               pQuiet->byQuietCount,
647                                               pQuiet->byQuietPeriod,
648                                               *((unsigned short *)pQuiet->abyQuietDuration),
649                                               *((unsigned short *)pQuiet->abyQuietOffset)
650 );
651                         } else {
652                                 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
653                                 CARDbSetQuiet(pMgmt->pAdapter,
654                                               false,
655                                               pQuiet->byQuietCount,
656                                               pQuiet->byQuietPeriod,
657                                               *((unsigned short *)pQuiet->abyQuietDuration),
658                                               *((unsigned short *)pQuiet->abyQuietOffset)
659                                         );
660                         }
661                 }
662         }
663
664         if (bParsingQuiet && (pQuiet != NULL))
665                 CARDbStartQuiet(pMgmt->pAdapter);
666
667         pBSSList->uIELength = uIELength;
668         if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
669                 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
670         memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
671
672         return true;
673 }
674
675 /*+
676  *
677  * Routine Description:
678  *    Search Node DB table to find the index of matched DstAddr
679  *
680  * Return Value:
681  *    None
682  *
683  -*/
684
685 bool
686 BSSDBbIsSTAInNodeDB(void *pMgmtObject, unsigned char *abyDstAddr,
687                     unsigned int *puNodeIndex)
688 {
689         PSMgmtObject    pMgmt = (PSMgmtObject) pMgmtObject;
690         unsigned int ii;
691
692         /* Index = 0 reserved for AP Node */
693         for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
694                 if (pMgmt->sNodeDBTable[ii].bActive) {
695                         if (ether_addr_equal(abyDstAddr,
696                                              pMgmt->sNodeDBTable[ii].abyMACAddr)) {
697                                 *puNodeIndex = ii;
698                                 return true;
699                         }
700                 }
701         }
702
703         return false;
704 };
705
706 /*+
707  *
708  * Routine Description:
709  *    Find an empty node and allocat it; if there is no empty node,
710  *    then use the most inactive one.
711  *
712  * Return Value:
713  *    None
714  *
715  -*/
716 void
717 BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex)
718 {
719         PSDevice     pDevice = (PSDevice)hDeviceContext;
720         PSMgmtObject    pMgmt = pDevice->pMgmt;
721         unsigned int ii;
722         unsigned int BigestCount = 0;
723         unsigned int SelectIndex;
724         struct sk_buff  *skb;
725         /*
726          * Index = 0 reserved for AP Node (In STA mode)
727          * Index = 0 reserved for Broadcast/MultiCast (In AP mode)
728          */
729         SelectIndex = 1;
730         for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
731                 if (pMgmt->sNodeDBTable[ii].bActive) {
732                         if (pMgmt->sNodeDBTable[ii].uInActiveCount > BigestCount) {
733                                 BigestCount = pMgmt->sNodeDBTable[ii].uInActiveCount;
734                                 SelectIndex = ii;
735                         }
736                 } else {
737                         break;
738                 }
739         }
740
741         /* if not found replace uInActiveCount is largest one */
742         if (ii == (MAX_NODE_NUM + 1)) {
743                 *puNodeIndex = SelectIndex;
744                 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Replace inactive node = %d\n", SelectIndex);
745                 /* clear ps buffer */
746                 if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
747                         while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
748                                 dev_kfree_skb(skb);
749                 }
750         } else {
751                 *puNodeIndex = ii;
752         }
753
754         memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
755         pMgmt->sNodeDBTable[*puNodeIndex].bActive = true;
756         pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
757         /* for AP mode PS queue */
758         skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
759         pMgmt->sNodeDBTable[*puNodeIndex].byAuthSequence = 0;
760         pMgmt->sNodeDBTable[*puNodeIndex].wEnQueueCnt = 0;
761         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create node index = %d\n", ii);
762         return;
763 };
764
765 /*+
766  *
767  * Routine Description:
768  *    Remove Node by NodeIndex
769  *
770  *
771  * Return Value:
772  *    None
773  *
774  -*/
775 void
776 BSSvRemoveOneNode(
777         void *hDeviceContext,
778         unsigned int uNodeIndex
779 )
780 {
781         PSDevice        pDevice = (PSDevice)hDeviceContext;
782         PSMgmtObject    pMgmt = pDevice->pMgmt;
783         unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
784         struct sk_buff  *skb;
785
786         while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
787                 dev_kfree_skb(skb);
788         /* clear context */
789         memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
790         /* clear tx bit map */
791         pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &=  ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
792
793         return;
794 };
795 /*+
796  *
797  * Routine Description:
798  *    Update AP Node content in Index 0 of KnownNodeDB
799  *
800  *
801  * Return Value:
802  *    None
803  *
804  -*/
805
806 void
807 BSSvUpdateAPNode(
808         void *hDeviceContext,
809         unsigned short *pwCapInfo,
810         PWLAN_IE_SUPP_RATES pSuppRates,
811         PWLAN_IE_SUPP_RATES pExtSuppRates
812 )
813 {
814         PSDevice     pDevice = (PSDevice)hDeviceContext;
815         PSMgmtObject    pMgmt = pDevice->pMgmt;
816         unsigned int uRateLen = WLAN_RATES_MAXLEN;
817
818         memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
819
820         pMgmt->sNodeDBTable[0].bActive = true;
821         if (pDevice->eCurrentPHYType == PHY_TYPE_11B)
822                 uRateLen = WLAN_RATES_MAXLEN_11B;
823         pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
824                                                 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
825                                                 uRateLen);
826         pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
827                                                    (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
828                                                    uRateLen);
829         RATEvParseMaxRate((void *)pDevice,
830                           (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
831                           (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
832                           true,
833                           &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
834                           &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
835                           &(pMgmt->sNodeDBTable[0].wSuppRate),
836                           &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
837                           &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
838 );
839         memcpy(pMgmt->sNodeDBTable[0].abyMACAddr, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
840         pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxSuppRate;
841         pMgmt->sNodeDBTable[0].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo);
842         pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
843         netdev_dbg(pDevice->dev, "BSSvUpdateAPNode:MaxSuppRate is %d\n",
844                    pMgmt->sNodeDBTable[0].wMaxSuppRate);
845         /* auto rate fallback function initiation */
846         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->sNodeDBTable[0].wTxDataRate = %d\n", pMgmt->sNodeDBTable[0].wTxDataRate);
847 };
848
849 /*+
850  *
851  * Routine Description:
852  *    Add Multicast Node content in Index 0 of KnownNodeDB
853  *
854  *
855  * Return Value:
856  *    None
857  *
858  -*/
859
860 void
861 BSSvAddMulticastNode(
862         void *hDeviceContext
863 )
864 {
865         PSDevice     pDevice = (PSDevice)hDeviceContext;
866         PSMgmtObject    pMgmt = pDevice->pMgmt;
867
868         if (!pDevice->bEnableHostWEP)
869                 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
870         memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
871         pMgmt->sNodeDBTable[0].bActive = true;
872         pMgmt->sNodeDBTable[0].bPSEnable = false;
873         skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
874         RATEvParseMaxRate((void *)pDevice,
875                           (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
876                           (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
877                           true,
878                           &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
879                           &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
880                           &(pMgmt->sNodeDBTable[0].wSuppRate),
881                           &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
882                           &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
883 );
884         pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
885         netdev_dbg(pDevice->dev,
886                    "BSSvAddMultiCastNode:pMgmt->sNodeDBTable[0].wTxDataRate is %d\n",
887                    pMgmt->sNodeDBTable[0].wTxDataRate);
888         pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
889 };
890
891 /*+
892  *
893  * Routine Description:
894  *
895  *
896  *  Second call back function to update Node DB info & AP link status
897  *
898  *
899  * Return Value:
900  *    none.
901  *
902  -*/
903 /* 2008-4-14 <add> by chester for led issue */
904 #ifdef FOR_LED_ON_NOTEBOOK
905 bool cc = false;
906 unsigned int status;
907 #endif
908 void
909 BSSvSecondCallBack(
910         void *hDeviceContext
911 )
912 {
913         PSDevice        pDevice = (PSDevice)hDeviceContext;
914         PSMgmtObject    pMgmt = pDevice->pMgmt;
915         unsigned int ii;
916         PWLAN_IE_SSID   pItemSSID, pCurrSSID;
917         unsigned int uSleepySTACnt = 0;
918         unsigned int uNonShortSlotSTACnt = 0;
919         unsigned int uLongPreambleSTACnt = 0;
920         viawget_wpa_header *wpahdr;  /* DavidWang */
921
922         spin_lock_irq(&pDevice->lock);
923
924         pDevice->uAssocCount = 0;
925
926         pDevice->byERPFlag &=
927                 ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
928         /* 2008-4-14 <add> by chester for led issue */
929 #ifdef FOR_LED_ON_NOTEBOOK
930         MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
931         if (((!(pDevice->byGPIO & GPIO0_DATA) && (!pDevice->bHWRadioOff)) ||
932              ((pDevice->byGPIO & GPIO0_DATA) && pDevice->bHWRadioOff)) &&
933             (!cc)) {
934                 cc = true;
935         } else if (cc) {
936                 if (pDevice->bHWRadioOff) {
937                         if (!(pDevice->byGPIO & GPIO0_DATA)) {
938                                 if (status == 1)
939                                         goto start;
940                                 status = 1;
941                                 CARDbRadioPowerOff(pDevice);
942                                 pMgmt->sNodeDBTable[0].bActive = false;
943                                 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
944                                 pMgmt->eCurrState = WMAC_STATE_IDLE;
945                                 pDevice->bLinkPass = false;
946
947                         }
948                         if (pDevice->byGPIO & GPIO0_DATA) {
949                                 if (status == 2)
950                                         goto start;
951                                 status = 2;
952                                 CARDbRadioPowerOn(pDevice);
953                         }
954                 } else {
955                         if (pDevice->byGPIO & GPIO0_DATA) {
956                                 if (status == 3)
957                                         goto start;
958                                 status = 3;
959                                 CARDbRadioPowerOff(pDevice);
960                                 pMgmt->sNodeDBTable[0].bActive = false;
961                                 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
962                                 pMgmt->eCurrState = WMAC_STATE_IDLE;
963                                 pDevice->bLinkPass = false;
964
965                         }
966                         if (!(pDevice->byGPIO & GPIO0_DATA)) {
967                                 if (status == 4)
968                                         goto start;
969                                 status = 4;
970                                 CARDbRadioPowerOn(pDevice);
971                         }
972                 }
973         }
974 start:
975 #endif
976
977         if (pDevice->wUseProtectCntDown > 0) {
978                 pDevice->wUseProtectCntDown--;
979         } else {
980                 /* disable protect mode */
981                 pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
982         }
983
984         {
985                 pDevice->byReAssocCount++;
986                 /* 10 sec timeout */
987                 if ((pDevice->byReAssocCount > 10) && (!pDevice->bLinkPass)) {
988                         netdev_info(pDevice->dev, "Re-association timeout!!!\n");
989                         pDevice->byReAssocCount = 0;
990 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
991                         {
992                                 union iwreq_data  wrqu;
993                                 memset(&wrqu, 0, sizeof(wrqu));
994                                 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
995                                 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
996                                 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
997                         }
998 #endif
999                 } else if (pDevice->bLinkPass)
1000                         pDevice->byReAssocCount = 0;
1001         }
1002
1003 #ifdef Calcu_LinkQual
1004         s_uCalculateLinkQual((void *)pDevice);
1005 #endif
1006
1007         for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
1008                 if (pMgmt->sNodeDBTable[ii].bActive) {
1009                         /* increase in-activity counter */
1010                         pMgmt->sNodeDBTable[ii].uInActiveCount++;
1011
1012                         if (ii > 0) {
1013                                 if (pMgmt->sNodeDBTable[ii].uInActiveCount > MAX_INACTIVE_COUNT) {
1014                                         BSSvRemoveOneNode(pDevice, ii);
1015                                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1016                                                 "Inactive timeout [%d] sec, STA index = [%d] remove\n", MAX_INACTIVE_COUNT, ii);
1017                                         continue;
1018                                 }
1019
1020                                 if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
1021                                         pDevice->uAssocCount++;
1022
1023                                         /* check if Non ERP exist */
1024                                         if (pMgmt->sNodeDBTable[ii].uInActiveCount < ERP_RECOVER_COUNT) {
1025                                                 if (!pMgmt->sNodeDBTable[ii].bShortPreamble) {
1026                                                         pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
1027                                                         uLongPreambleSTACnt++;
1028                                                 }
1029                                                 if (!pMgmt->sNodeDBTable[ii].bERPExist) {
1030                                                         pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
1031                                                         pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1032                                                 }
1033                                                 if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
1034                                                         uNonShortSlotSTACnt++;
1035                                         }
1036                                 }
1037
1038                                 /* check if any STA in PS mode */
1039                                 if (pMgmt->sNodeDBTable[ii].bPSEnable)
1040                                         uSleepySTACnt++;
1041
1042                         }
1043
1044                         /* rate fallback check */
1045                         if (!pDevice->bFixRate) {
1046                                 if (ii > 0) {
1047                                         /* ii = 0 for multicast node (AP & Adhoc) */
1048                                         RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
1049                                 } else {
1050                                         /* ii = 0 reserved for unicast AP node (Infra STA) */
1051                                         if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
1052                                                 netdev_dbg(pDevice->dev,
1053                                                            "SecondCallback:Before:TxDataRate is %d\n",
1054                                                            pMgmt->sNodeDBTable[0].wTxDataRate);
1055                                         RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
1056                                         netdev_dbg(pDevice->dev,
1057                                                    "SecondCallback:After:TxDataRate is %d\n",
1058                                                    pMgmt->sNodeDBTable[0].wTxDataRate);
1059
1060                                 }
1061
1062                         }
1063
1064                         /* check if pending PS queue */
1065                         if (pMgmt->sNodeDBTable[ii].wEnQueueCnt != 0) {
1066                                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index= %d, Queue = %d pending\n",
1067                                         ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
1068                                 if ((ii > 0) && (pMgmt->sNodeDBTable[ii].wEnQueueCnt > 15)) {
1069                                         BSSvRemoveOneNode(pDevice, ii);
1070                                         DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Pending many queues PS STA Index = %d remove\n", ii);
1071                                         continue;
1072                                 }
1073                         }
1074                 }
1075
1076         }
1077
1078         if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->eCurrentPHYType == PHY_TYPE_11G)) {
1079                 /* on/off protect mode */
1080                 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
1081                         if (!pDevice->bProtectMode) {
1082                                 MACvEnableProtectMD(pDevice->PortOffset);
1083                                 pDevice->bProtectMode = true;
1084                         }
1085                 } else {
1086                         if (pDevice->bProtectMode) {
1087                                 MACvDisableProtectMD(pDevice->PortOffset);
1088                                 pDevice->bProtectMode = false;
1089                         }
1090                 }
1091                 /* on/off short slot time */
1092
1093                 if (uNonShortSlotSTACnt > 0) {
1094                         if (pDevice->bShortSlotTime) {
1095                                 pDevice->bShortSlotTime = false;
1096                                 BBvSetShortSlotTime(pDevice);
1097                                 vUpdateIFS((void *)pDevice);
1098                         }
1099                 } else {
1100                         if (!pDevice->bShortSlotTime) {
1101                                 pDevice->bShortSlotTime = true;
1102                                 BBvSetShortSlotTime(pDevice);
1103                                 vUpdateIFS((void *)pDevice);
1104                         }
1105                 }
1106
1107                 /* on/off barker long preamble mode */
1108
1109                 if (uLongPreambleSTACnt > 0) {
1110                         if (!pDevice->bBarkerPreambleMd) {
1111                                 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
1112                                 pDevice->bBarkerPreambleMd = true;
1113                         }
1114                 } else {
1115                         if (pDevice->bBarkerPreambleMd) {
1116                                 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
1117                                 pDevice->bBarkerPreambleMd = false;
1118                         }
1119                 }
1120
1121         }
1122
1123         /* check if any STA in PS mode, enable DTIM multicast deliver */
1124         if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1125                 if (uSleepySTACnt > 0)
1126                         pMgmt->sNodeDBTable[0].bPSEnable = true;
1127                 else
1128                         pMgmt->sNodeDBTable[0].bPSEnable = false;
1129         }
1130
1131         pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
1132         pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
1133
1134         if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
1135             (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
1136                 /* assoc with BSS */
1137                 if (pMgmt->sNodeDBTable[0].bActive) {
1138                         if (pDevice->bUpdateBBVGA)
1139                                 s_vCheckPreEDThreshold((void *)pDevice);
1140
1141                         if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
1142                             (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0])) {
1143                                 pDevice->byBBVGANew = pDevice->abyBBVGA[0];
1144                                 bScheduleCommand((void *)pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1145                         }
1146
1147                         if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
1148                                 pMgmt->sNodeDBTable[0].bActive = false;
1149                                 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1150                                 pMgmt->eCurrState = WMAC_STATE_IDLE;
1151                                 netif_stop_queue(pDevice->dev);
1152                                 pDevice->bLinkPass = false;
1153                                 pDevice->bRoaming = true;
1154                                 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1155                                 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1156                                         wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1157                                         wpahdr->type = VIAWGET_DISASSOC_MSG;
1158                                         wpahdr->resp_ie_len = 0;
1159                                         wpahdr->req_ie_len = 0;
1160                                         skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1161                                         pDevice->skb->dev = pDevice->wpadev;
1162                                         skb_reset_mac_header(pDevice->skb);
1163                                         pDevice->skb->pkt_type = PACKET_HOST;
1164                                         pDevice->skb->protocol = htons(ETH_P_802_2);
1165                                         memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1166                                         netif_rx(pDevice->skb);
1167                                         pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1168                                 }
1169 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1170                                 {
1171                                         union iwreq_data  wrqu;
1172                                         memset(&wrqu, 0, sizeof(wrqu));
1173                                         wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1174                                         PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1175                                         wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1176                                 }
1177 #endif
1178                         }
1179                 } else if (pItemSSID->len != 0) {
1180                         if (pDevice->uAutoReConnectTime < 10) {
1181                                 pDevice->uAutoReConnectTime++;
1182 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1183                                 /*
1184                                  * network manager support need not do
1185                                  * Roaming scan???
1186                                  */
1187                                 if (pDevice->bWPASuppWextEnabled)
1188                                         pDevice->uAutoReConnectTime = 0;
1189 #endif
1190                         } else {
1191                                 /*
1192                                  * mike use old encryption status
1193                                  * for wpa reauthentication
1194                                  */
1195                                 if (pDevice->bWPADEVUp)
1196                                         pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
1197
1198                                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming ...\n");
1199                                 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
1200                                 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1201                                 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
1202                                 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
1203                                 pDevice->uAutoReConnectTime = 0;
1204                         }
1205                 }
1206         }
1207
1208         if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1209                 /* if adhoc started which essid is NULL string, rescanning */
1210                 if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
1211                         if (pDevice->uAutoReConnectTime < 10) {
1212                                 pDevice->uAutoReConnectTime++;
1213                         } else {
1214                                 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Adhoc re-scanning ...\n");
1215                                 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1216                                 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1217                                 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
1218                                 pDevice->uAutoReConnectTime = 0;
1219                         }
1220                 }
1221                 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
1222                         if (pDevice->bUpdateBBVGA)
1223                                 s_vCheckPreEDThreshold((void *)pDevice);
1224                         if (pMgmt->sNodeDBTable[0].uInActiveCount >= ADHOC_LOST_BEACON_COUNT) {
1225                                 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1226                                 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1227                                 pMgmt->eCurrState = WMAC_STATE_STARTED;
1228                                 netif_stop_queue(pDevice->dev);
1229                                 pDevice->bLinkPass = false;
1230                         }
1231                 }
1232         }
1233
1234         spin_unlock_irq(&pDevice->lock);
1235
1236         pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
1237         add_timer(&pMgmt->sTimerSecondCallback);
1238         return;
1239 }
1240
1241 /*+
1242  *
1243  * Routine Description:
1244  *
1245  *
1246  *  Update Tx attemps, Tx failure counter in Node DB
1247  *
1248  *
1249  * Return Value:
1250  *    none.
1251  *
1252  -*/
1253
1254 void
1255 BSSvUpdateNodeTxCounter(
1256         void *hDeviceContext,
1257         unsigned char byTsr0,
1258         unsigned char byTsr1,
1259         unsigned char *pbyBuffer,
1260         unsigned int uFIFOHeaderSize
1261 )
1262 {
1263         PSDevice        pDevice = (PSDevice)hDeviceContext;
1264         PSMgmtObject    pMgmt = pDevice->pMgmt;
1265         unsigned int uNodeIndex = 0;
1266         unsigned char byTxRetry = (byTsr0 & TSR0_NCR);
1267         PSTxBufHead     pTxBufHead;
1268         PS802_11Header  pMACHeader;
1269         unsigned short wRate;
1270         unsigned short wFallBackRate = RATE_1M;
1271         unsigned char byFallBack;
1272         unsigned int ii;
1273         pTxBufHead = (PSTxBufHead) pbyBuffer;
1274         if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_0)
1275                 byFallBack = AUTO_FB_0;
1276         else if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_1)
1277                 byFallBack = AUTO_FB_1;
1278         else
1279                 byFallBack = AUTO_FB_NONE;
1280         wRate = pTxBufHead->wReserved;
1281
1282         /* Only Unicast using support rates */
1283         if (pTxBufHead->wFIFOCtl & FIFOCTL_NEEDACK) {
1284                 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wRate %04X, byTsr0 %02X, byTsr1 %02X\n", wRate, byTsr0, byTsr1);
1285                 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
1286                         pMgmt->sNodeDBTable[0].uTxAttempts += 1;
1287                         if ((byTsr1 & TSR1_TERR) == 0) {
1288                                 /* transmit success, TxAttempts at least plus one */
1289                                 pMgmt->sNodeDBTable[0].uTxOk[MAX_RATE]++;
1290                                 if ((byFallBack == AUTO_FB_NONE) ||
1291                                     (wRate < RATE_18M)) {
1292                                         wFallBackRate = wRate;
1293                                 } else if (byFallBack == AUTO_FB_0) {
1294                                         if (byTxRetry < 5)
1295                                                 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1296                                         else
1297                                                 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1298                                 } else if (byFallBack == AUTO_FB_1) {
1299                                         if (byTxRetry < 5)
1300                                                 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1301                                         else
1302                                                 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1303                                 }
1304                                 pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
1305                         } else {
1306                                 pMgmt->sNodeDBTable[0].uTxFailures++;
1307                         }
1308                         pMgmt->sNodeDBTable[0].uTxRetry += byTxRetry;
1309                         if (byTxRetry != 0) {
1310                                 pMgmt->sNodeDBTable[0].uTxFail[MAX_RATE] += byTxRetry;
1311                                 if ((byFallBack == AUTO_FB_NONE) ||
1312                                     (wRate < RATE_18M)) {
1313                                         pMgmt->sNodeDBTable[0].uTxFail[wRate] += byTxRetry;
1314                                 } else if (byFallBack == AUTO_FB_0) {
1315                                         for (ii = 0; ii < byTxRetry; ii++) {
1316                                                 if (ii < 5)
1317                                                         wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
1318                                                 else
1319                                                         wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1320                                                 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1321                                         }
1322                                 } else if (byFallBack == AUTO_FB_1) {
1323                                         for (ii = 0; ii < byTxRetry; ii++) {
1324                                                 if (ii < 5)
1325                                                         wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1326                                                 else
1327                                                         wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1328                                                 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1329                                         }
1330                                 }
1331                         }
1332                 }
1333
1334                 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
1335                     (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1336                         pMACHeader = (PS802_11Header)(pbyBuffer + uFIFOHeaderSize);
1337
1338                         if (BSSDBbIsSTAInNodeDB((void *)pMgmt,  &(pMACHeader->abyAddr1[0]), &uNodeIndex)) {
1339                                 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
1340                                 if ((byTsr1 & TSR1_TERR) == 0) {
1341                                         /* transmit success, TxAttempts at least plus one */
1342                                         pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
1343                                         if ((byFallBack == AUTO_FB_NONE) ||
1344                                             (wRate < RATE_18M)) {
1345                                                 wFallBackRate = wRate;
1346                                         } else if (byFallBack == AUTO_FB_0) {
1347                                                 if (byTxRetry < 5)
1348                                                         wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1349                                                 else
1350                                                         wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1351                                         } else if (byFallBack == AUTO_FB_1) {
1352                                                 if (byTxRetry < 5)
1353                                                         wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1354                                                 else
1355                                                         wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1356                                         }
1357                                         pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
1358                                 } else {
1359                                         pMgmt->sNodeDBTable[uNodeIndex].uTxFailures++;
1360                                 }
1361                                 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += byTxRetry;
1362                                 if (byTxRetry != 0) {
1363                                         pMgmt->sNodeDBTable[uNodeIndex].uTxFail[MAX_RATE] += byTxRetry;
1364                                         if ((byFallBack == AUTO_FB_NONE) ||
1365                                             (wRate < RATE_18M)) {
1366                                                 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wRate] += byTxRetry;
1367                                         } else if (byFallBack == AUTO_FB_0) {
1368                                                 for (ii = 0; ii < byTxRetry; ii++) {
1369                                                         if (ii < 5)
1370                                                                 wFallBackRate = awHWRetry0[wRate - RATE_18M][ii];
1371                                                         else
1372                                                                 wFallBackRate = awHWRetry0[wRate - RATE_18M][4];
1373                                                         pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1374                                                 }
1375                                         } else if (byFallBack == AUTO_FB_1) {
1376                                                 for (ii = 0; ii < byTxRetry; ii++) {
1377                                                         if (ii < 5)
1378                                                                 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1379                                                         else
1380                                                                 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1381                                                         pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1382                                                 }
1383                                         }
1384                                 }
1385                         }
1386                 }
1387         }
1388
1389         return;
1390 }
1391
1392 /*+
1393  *
1394  * Routine Description:
1395  *    Clear Nodes & skb in DB Table
1396  *
1397  *
1398  * Parameters:
1399  *  In:
1400  *      hDeviceContext        - The adapter context.
1401  *      uStartIndex           - starting index
1402  *  Out:
1403  *      none
1404  *
1405  * Return Value:
1406  *    None.
1407  *
1408  -*/
1409
1410 void
1411 BSSvClearNodeDBTable(
1412         void *hDeviceContext,
1413         unsigned int uStartIndex
1414 )
1415
1416 {
1417         PSDevice     pDevice = (PSDevice)hDeviceContext;
1418         PSMgmtObject    pMgmt = pDevice->pMgmt;
1419         struct sk_buff  *skb;
1420         unsigned int ii;
1421
1422         for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
1423                 if (pMgmt->sNodeDBTable[ii].bActive) {
1424                         /* check if sTxPSQueue has been initial */
1425                         if (pMgmt->sNodeDBTable[ii].sTxPSQueue.next != NULL) {
1426                                 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
1427                                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS skb != NULL %d\n", ii);
1428                                         dev_kfree_skb(skb);
1429                                 }
1430                         }
1431                         memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
1432                 }
1433         }
1434
1435         return;
1436 };
1437
1438 void s_vCheckSensitivity(
1439         void *hDeviceContext
1440 )
1441 {
1442         PSDevice        pDevice = (PSDevice)hDeviceContext;
1443         PKnownBSS       pBSSList = NULL;
1444         PSMgmtObject    pMgmt = pDevice->pMgmt;
1445         int             ii;
1446
1447         if ((pDevice->byLocalID <= REV_ID_VT3253_A1) && (pDevice->byRFType == RF_RFMD2959) &&
1448             (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
1449                 return;
1450         }
1451
1452         if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1453             ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1454                 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1455                 if (pBSSList != NULL) {
1456                         /* Update BB Reg if RSSI is too strong */
1457                         long    LocalldBmAverage = 0;
1458                         long    uNumofdBm = 0;
1459                         for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
1460                                 if (pBSSList->ldBmAverage[ii] != 0) {
1461                                         uNumofdBm++;
1462                                         LocalldBmAverage += pBSSList->ldBmAverage[ii];
1463                                 }
1464                         }
1465                         if (uNumofdBm > 0) {
1466                                 LocalldBmAverage = LocalldBmAverage/uNumofdBm;
1467                                 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
1468                                         DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "LocalldBmAverage:%ld, %ld %02x\n", LocalldBmAverage, pDevice->ldBmThreshold[ii], pDevice->abyBBVGA[ii]);
1469                                         if (LocalldBmAverage < pDevice->ldBmThreshold[ii]) {
1470                                                 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1471                                                 break;
1472                                         }
1473                                 }
1474                                 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1475                                         pDevice->uBBVGADiffCount++;
1476                                         if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
1477                                                 bScheduleCommand((void *)pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1478                                 } else {
1479                                         pDevice->uBBVGADiffCount = 0;
1480                                 }
1481                         }
1482                 }
1483         }
1484 }
1485
1486 void
1487 BSSvClearAnyBSSJoinRecord(
1488         void *hDeviceContext
1489 )
1490 {
1491         PSDevice        pDevice = (PSDevice)hDeviceContext;
1492         PSMgmtObject    pMgmt = pDevice->pMgmt;
1493         unsigned int ii;
1494
1495         for (ii = 0; ii < MAX_BSS_NUM; ii++)
1496                 pMgmt->sBSSList[ii].bSelected = false;
1497         return;
1498 }
1499
1500 #ifdef Calcu_LinkQual
1501 void s_uCalculateLinkQual(
1502         void *hDeviceContext
1503 )
1504 {
1505         PSDevice        pDevice = (PSDevice)hDeviceContext;
1506         unsigned long TxOkRatio, TxCnt;
1507         unsigned long RxOkRatio, RxCnt;
1508         unsigned long RssiRatio;
1509         long ldBm;
1510
1511         TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
1512                 pDevice->scStatistic.TxRetryOkCount +
1513                 pDevice->scStatistic.TxFailCount;
1514         RxCnt = pDevice->scStatistic.RxFcsErrCnt +
1515                 pDevice->scStatistic.RxOkCnt;
1516         TxOkRatio = (TxCnt < 6) ? 4000 : ((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
1517         RxOkRatio = (RxCnt < 6) ? 2000 : ((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
1518         /* decide link quality */
1519         if (!pDevice->bLinkPass) {
1520                 pDevice->scStatistic.LinkQuality = 0;
1521                 pDevice->scStatistic.SignalStren = 0;
1522         } else {
1523                 RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
1524                 if (-ldBm < 50)
1525                         RssiRatio = 4000;
1526                 else if (-ldBm > 90)
1527                         RssiRatio = 0;
1528                 else
1529                         RssiRatio = (40-(-ldBm-50))*4000/40;
1530                 pDevice->scStatistic.SignalStren = RssiRatio/40;
1531                 pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
1532         }
1533         pDevice->scStatistic.RxFcsErrCnt = 0;
1534         pDevice->scStatistic.RxOkCnt = 0;
1535         pDevice->scStatistic.TxFailCount = 0;
1536         pDevice->scStatistic.TxNoRetryOkCount = 0;
1537         pDevice->scStatistic.TxRetryOkCount = 0;
1538         return;
1539 }
1540 #endif
1541
1542 void s_vCheckPreEDThreshold(
1543         void *hDeviceContext
1544 )
1545 {
1546         PSDevice        pDevice = (PSDevice)hDeviceContext;
1547         PKnownBSS       pBSSList = NULL;
1548         PSMgmtObject    pMgmt = &(pDevice->sMgmtObj);
1549
1550         if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1551             ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1552                 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1553                 if (pBSSList != NULL)
1554                         pDevice->byBBPreEDRSSI = (unsigned char) (~(pBSSList->ldBmAverRange) + 1);
1555         }
1556         return;
1557 }