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