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