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