tty/serial: atmel_serial: whitespace and braces modifications
[zen-stable.git] / drivers / staging / vt6656 / bssdb.c
blobaf006df4c8e95253e1fe21937a0b2c2c9ed792a7
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
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.
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.
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.
19 * File: bssdb.c
21 * Purpose: Handles the Basic Service Set & Node Database functions
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
34 * Revision History:
36 * Author: Lyndon Chen
38 * Date: July 17, 2002
42 #include "ttype.h"
43 #include "tmacro.h"
44 #include "tether.h"
45 #include "device.h"
46 #include "80211hdr.h"
47 #include "bssdb.h"
48 #include "wmgr.h"
49 #include "datarate.h"
50 #include "desc.h"
51 #include "wcmd.h"
52 #include "wpa.h"
53 #include "baseband.h"
54 #include "rf.h"
55 #include "card.h"
56 #include "mac.h"
57 #include "wpa2.h"
58 #include "control.h"
59 #include "rndis.h"
60 #include "iowpa.h"
62 /*--------------------- Static Definitions -------------------------*/
67 /*--------------------- Static Classes ----------------------------*/
69 /*--------------------- Static Variables --------------------------*/
70 static int msglevel =MSG_LEVEL_INFO;
71 //static int msglevel =MSG_LEVEL_DEBUG;
75 const 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}
82 const 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}
92 /*--------------------- Static Functions --------------------------*/
94 void s_vCheckSensitivity(void *hDeviceContext);
95 void s_vCheckPreEDThreshold(void *hDeviceContext);
96 void s_uCalculateLinkQual(void *hDeviceContext);
98 /*--------------------- Export Variables --------------------------*/
101 /*--------------------- Export Functions --------------------------*/
109 * Routine Description:
110 * Search known BSS list for Desire SSID or BSSID.
112 * Return Value:
113 * PTR to KnownBSS or NULL
117 PKnownBSS BSSpSearchBSSList(void *hDeviceContext,
118 PBYTE pbyDesireBSSID,
119 PBYTE pbyDesireSSID,
120 CARD_PHY_TYPE ePhyType)
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};
129 unsigned int ii = 0;
130 unsigned int jj = 0;
131 if (pbyDesireBSSID != NULL) {
132 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSpSearchBSSList BSSID[%02X %02X %02X-%02X %02X %02X]\n",
133 *pbyDesireBSSID,*(pbyDesireBSSID+1),*(pbyDesireBSSID+2),
134 *(pbyDesireBSSID+3),*(pbyDesireBSSID+4),*(pbyDesireBSSID+5));
135 if ((!is_broadcast_ether_addr(pbyDesireBSSID)) &&
136 (memcmp(pbyDesireBSSID, ZeroBSSID, 6)!= 0)){
137 pbyBSSID = pbyDesireBSSID;
140 if (pbyDesireSSID != NULL) {
141 if (((PWLAN_IE_SSID)pbyDesireSSID)->len != 0) {
142 pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
146 if ((pbyBSSID != NULL)&&(pDevice->bRoaming == FALSE)) {
147 // match BSSID first
148 for (ii = 0; ii <MAX_BSS_NUM; ii++) {
149 pCurrBSS = &(pMgmt->sBSSList[ii]);
151 pCurrBSS->bSelected = FALSE;
153 if ((pCurrBSS->bActive) &&
154 (pCurrBSS->bSelected == FALSE)) {
155 if (!compare_ether_addr(pCurrBSS->abyBSSID, pbyBSSID)) {
156 if (pSSID != NULL) {
157 // compare ssid
158 if ( !memcmp(pSSID->abySSID,
159 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
160 pSSID->len)) {
161 if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
162 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
163 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
165 pCurrBSS->bSelected = TRUE;
166 return(pCurrBSS);
169 } else {
170 if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
171 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
172 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
174 pCurrBSS->bSelected = TRUE;
175 return(pCurrBSS);
181 } else {
182 // ignore BSSID
183 for (ii = 0; ii <MAX_BSS_NUM; ii++) {
184 pCurrBSS = &(pMgmt->sBSSList[ii]);
186 //2007-0721-01<Mark>by MikeLiu
187 // if ((pCurrBSS->bActive) &&
188 // (pCurrBSS->bSelected == FALSE)) {
190 pCurrBSS->bSelected = FALSE;
191 if (pCurrBSS->bActive) {
193 if (pSSID != NULL) {
194 // matched SSID
195 if (memcmp(pSSID->abySSID,
196 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
197 pSSID->len) ||
198 (pSSID->len != ((PWLAN_IE_SSID)pCurrBSS->abySSID)->len)) {
199 // SSID not match skip this BSS
200 continue;
203 if (((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) ||
204 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo))
206 // Type not match skip this BSS
207 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSS type mismatch.... Config[%d] BSS[0x%04x]\n", pMgmt->eConfigMode, pCurrBSS->wCapInfo);
208 continue;
211 if (ePhyType != PHY_TYPE_AUTO) {
212 if (((ePhyType == PHY_TYPE_11A) && (PHY_TYPE_11A != pCurrBSS->eNetworkTypeInUse)) ||
213 ((ePhyType != PHY_TYPE_11A) && (PHY_TYPE_11A == pCurrBSS->eNetworkTypeInUse))) {
214 // PhyType not match skip this BSS
215 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Physical type mismatch.... ePhyType[%d] BSS[%d]\n", ePhyType, pCurrBSS->eNetworkTypeInUse);
216 continue;
220 if (pMgmt->eAuthenMode < WMAC_AUTH_WPA) {
221 if (pCurrBSS->bWPAValid == TRUE) {
222 // WPA AP will reject connection of station without WPA enable.
223 continue;
225 } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
226 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
227 if (pCurrBSS->bWPAValid == FALSE) {
228 // station with WPA enable can't join NonWPA AP.
229 continue;
231 } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
232 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
233 if (pCurrBSS->bWPA2Valid == FALSE) {
234 // station with WPA2 enable can't join NonWPA2 AP.
235 continue;
240 pMgmt->pSameBSS[jj].uChannel = pCurrBSS->uChannel;
241 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSpSearchBSSList pSelect1[%02X %02X %02X-%02X %02X %02X]\n",*pCurrBSS->abyBSSID,*(pCurrBSS->abyBSSID+1),*(pCurrBSS->abyBSSID+2),*(pCurrBSS->abyBSSID+3),*(pCurrBSS->abyBSSID+4),*(pCurrBSS->abyBSSID+5));
242 jj++;
245 if (pSelect == NULL) {
246 pSelect = pCurrBSS;
247 } else {
248 // compare RSSI, select signal strong one
249 if (pCurrBSS->uRSSI < pSelect->uRSSI) {
250 pSelect = pCurrBSS;
256 pDevice->bSameBSSMaxNum = jj;
258 if (pSelect != NULL) {
259 pSelect->bSelected = TRUE;
260 if (pDevice->bRoaming == FALSE) {
261 // Einsn Add @20070907
262 memset(pbyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
263 memcpy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1) ;
266 return(pSelect);
269 return(NULL);
276 * Routine Description:
277 * Clear BSS List
279 * Return Value:
280 * None.
285 void BSSvClearBSSList(void *hDeviceContext, BOOL bKeepCurrBSSID)
287 PSDevice pDevice = (PSDevice)hDeviceContext;
288 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
289 unsigned int ii;
291 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
292 if (bKeepCurrBSSID) {
293 if (pMgmt->sBSSList[ii].bActive &&
294 !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID,
295 pMgmt->abyCurrBSSID)) {
296 //mike mark: there are two same BSSID in list if that AP is in hidden ssid mode,one 's SSID is null,
297 // but other's is obvious, so if it acssociate with your STA exactly,you must keep two
298 // of them!!!!!!!!!
299 // bKeepCurrBSSID = FALSE;
300 continue;
304 if ((pMgmt->sBSSList[ii].bActive) && (pMgmt->sBSSList[ii].uClearCount < BSS_CLEAR_COUNT)) {
305 pMgmt->sBSSList[ii].uClearCount ++;
306 continue;
309 pMgmt->sBSSList[ii].bActive = FALSE;
310 memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS));
312 BSSvClearAnyBSSJoinRecord(pDevice);
314 return;
321 * Routine Description:
322 * search BSS list by BSSID & SSID if matched
324 * Return Value:
325 * TRUE if found.
328 PKnownBSS BSSpAddrIsInBSSList(void *hDeviceContext,
329 PBYTE abyBSSID,
330 PWLAN_IE_SSID pSSID)
332 PSDevice pDevice = (PSDevice)hDeviceContext;
333 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
334 PKnownBSS pBSSList = NULL;
335 unsigned int ii;
337 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
338 pBSSList = &(pMgmt->sBSSList[ii]);
339 if (pBSSList->bActive) {
340 if (!compare_ether_addr(pBSSList->abyBSSID, abyBSSID)) {
341 if (pSSID->len == ((PWLAN_IE_SSID)pBSSList->abySSID)->len){
342 if (memcmp(pSSID->abySSID,
343 ((PWLAN_IE_SSID)pBSSList->abySSID)->abySSID,
344 pSSID->len) == 0)
345 return pBSSList;
351 return NULL;
358 * Routine Description:
359 * Insert a BSS set into known BSS list
361 * Return Value:
362 * TRUE if success.
366 BOOL BSSbInsertToBSSList(void *hDeviceContext,
367 PBYTE abyBSSIDAddr,
368 QWORD qwTimestamp,
369 WORD wBeaconInterval,
370 WORD wCapInfo,
371 BYTE byCurrChannel,
372 PWLAN_IE_SSID pSSID,
373 PWLAN_IE_SUPP_RATES pSuppRates,
374 PWLAN_IE_SUPP_RATES pExtSuppRates,
375 PERPObject psERP,
376 PWLAN_IE_RSN pRSN,
377 PWLAN_IE_RSN_EXT pRSNWPA,
378 PWLAN_IE_COUNTRY pIE_Country,
379 PWLAN_IE_QUIET pIE_Quiet,
380 unsigned int uIELength,
381 PBYTE pbyIEs,
382 void *pRxPacketContext)
385 PSDevice pDevice = (PSDevice)hDeviceContext;
386 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
387 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
388 PKnownBSS pBSSList = NULL;
389 unsigned int ii;
390 BOOL bParsingQuiet = FALSE;
394 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
396 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
397 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[ii]);
398 if (!pBSSList->bActive)
399 break;
402 if (ii == MAX_BSS_NUM){
403 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n");
404 return FALSE;
406 // save the BSS info
407 pBSSList->bActive = TRUE;
408 memcpy( pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
409 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
410 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
411 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
412 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
413 pBSSList->uClearCount = 0;
415 if (pSSID->len > WLAN_SSID_MAXLEN)
416 pSSID->len = WLAN_SSID_MAXLEN;
417 memcpy( pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
419 pBSSList->uChannel = byCurrChannel;
421 if (pSuppRates->len > WLAN_RATES_MAXLEN)
422 pSuppRates->len = WLAN_RATES_MAXLEN;
423 memcpy( pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
425 if (pExtSuppRates != NULL) {
426 if (pExtSuppRates->len > WLAN_RATES_MAXLEN)
427 pExtSuppRates->len = WLAN_RATES_MAXLEN;
428 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
429 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSbInsertToBSSList: pExtSuppRates->len = %d\n", pExtSuppRates->len);
431 } else {
432 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
434 pBSSList->sERP.byERP = psERP->byERP;
435 pBSSList->sERP.bERPExist = psERP->bERPExist;
437 // Check if BSS is 802.11a/b/g
438 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
439 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
440 } else {
441 if (pBSSList->sERP.bERPExist == TRUE) {
442 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
443 } else {
444 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
448 pBSSList->byRxRate = pRxPacket->byRxRate;
449 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
450 pBSSList->uRSSI = pRxPacket->uRSSI;
451 pBSSList->bySQ = pRxPacket->bySQ;
453 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
454 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
455 // assoc with BSS
456 if (pBSSList == pMgmt->pCurrBSS) {
457 bParsingQuiet = TRUE;
461 WPA_ClearRSN(pBSSList);
463 if (pRSNWPA != NULL) {
464 unsigned int uLen = pRSNWPA->len + 2;
466 if (uLen <= (uIELength -
467 (unsigned int) (ULONG_PTR) ((PBYTE) pRSNWPA - pbyIEs))) {
468 pBSSList->wWPALen = uLen;
469 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
470 WPA_ParseRSN(pBSSList, pRSNWPA);
474 WPA2_ClearRSN(pBSSList);
476 if (pRSN != NULL) {
477 unsigned int uLen = pRSN->len + 2;
479 if (uLen <= (uIELength -
480 (unsigned int) (ULONG_PTR) ((PBYTE) pRSN - pbyIEs))) {
481 pBSSList->wRSNLen = uLen;
482 memcpy(pBSSList->byRSNIE, pRSN, uLen);
483 WPA2vParseRSN(pBSSList, pRSN);
487 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == TRUE)) {
489 PSKeyItem pTransmitKey = NULL;
490 BOOL bIs802_1x = FALSE;
492 for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii ++) {
493 if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
494 bIs802_1x = TRUE;
495 break;
498 if ((bIs802_1x == TRUE) && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
499 ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
501 bAdd_PMKID_Candidate((void *) pDevice,
502 pBSSList->abyBSSID,
503 &pBSSList->sRSNCapObj);
505 if ((pDevice->bLinkPass == TRUE) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
506 if ((KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE) ||
507 (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey) == TRUE)) {
508 pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
509 pDevice->gsPMKIDCandidate.Version = 1;
517 if (pDevice->bUpdateBBVGA) {
518 // Moniter if RSSI is too strong.
519 pBSSList->byRSSIStatCnt = 0;
520 RFvRSSITodBm(pDevice, (BYTE)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
521 pBSSList->ldBmAverage[0] = pBSSList->ldBmMAX;
522 pBSSList->ldBmAverRange = pBSSList->ldBmMAX;
523 for (ii = 1; ii < RSSI_STAT_COUNT; ii++)
524 pBSSList->ldBmAverage[ii] = 0;
528 if ((pIE_Country != NULL) &&
529 (pMgmt->b11hEnable == TRUE)) {
530 CARDvSetCountryInfo(pMgmt->pAdapter,
531 pBSSList->eNetworkTypeInUse,
532 pIE_Country);
535 if ((bParsingQuiet == TRUE) && (pIE_Quiet != NULL)) {
536 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
537 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
538 // valid EID
539 if (pQuiet == NULL) {
540 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
541 CARDbSetQuiet( pMgmt->pAdapter,
542 TRUE,
543 pQuiet->byQuietCount,
544 pQuiet->byQuietPeriod,
545 *((PWORD)pQuiet->abyQuietDuration),
546 *((PWORD)pQuiet->abyQuietOffset)
548 } else {
549 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
550 CARDbSetQuiet( pMgmt->pAdapter,
551 FALSE,
552 pQuiet->byQuietCount,
553 pQuiet->byQuietPeriod,
554 *((PWORD)pQuiet->abyQuietDuration),
555 *((PWORD)pQuiet->abyQuietOffset)
561 if ((bParsingQuiet == TRUE) &&
562 (pQuiet != NULL)) {
563 CARDbStartQuiet(pMgmt->pAdapter);
567 pBSSList->uIELength = uIELength;
568 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
569 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
570 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
572 return TRUE;
578 * Routine Description:
579 * Update BSS set in known BSS list
581 * Return Value:
582 * TRUE if success.
585 // TODO: input structure modify
587 BOOL BSSbUpdateToBSSList(void *hDeviceContext,
588 QWORD qwTimestamp,
589 WORD wBeaconInterval,
590 WORD wCapInfo,
591 BYTE byCurrChannel,
592 BOOL bChannelHit,
593 PWLAN_IE_SSID pSSID,
594 PWLAN_IE_SUPP_RATES pSuppRates,
595 PWLAN_IE_SUPP_RATES pExtSuppRates,
596 PERPObject psERP,
597 PWLAN_IE_RSN pRSN,
598 PWLAN_IE_RSN_EXT pRSNWPA,
599 PWLAN_IE_COUNTRY pIE_Country,
600 PWLAN_IE_QUIET pIE_Quiet,
601 PKnownBSS pBSSList,
602 unsigned int uIELength,
603 PBYTE pbyIEs,
604 void *pRxPacketContext)
606 int ii, jj;
607 PSDevice pDevice = (PSDevice)hDeviceContext;
608 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
609 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
610 signed long ldBm, ldBmSum;
611 BOOL bParsingQuiet = FALSE;
612 // BYTE abyTmpSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
615 if (pBSSList == NULL)
616 return FALSE;
619 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
620 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
621 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
622 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
623 pBSSList->uClearCount = 0;
624 pBSSList->uChannel = byCurrChannel;
625 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSbUpdateToBSSList: pBSSList->uChannel: %d\n", pBSSList->uChannel);
627 if (pSSID->len > WLAN_SSID_MAXLEN)
628 pSSID->len = WLAN_SSID_MAXLEN;
630 if ((pSSID->len != 0) && (pSSID->abySSID[0] != 0))
631 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
632 memcpy(pBSSList->abySuppRates, pSuppRates,pSuppRates->len + WLAN_IEHDR_LEN);
634 if (pExtSuppRates != NULL) {
635 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates,pExtSuppRates->len + WLAN_IEHDR_LEN);
636 } else {
637 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
639 pBSSList->sERP.byERP = psERP->byERP;
640 pBSSList->sERP.bERPExist = psERP->bERPExist;
642 // Check if BSS is 802.11a/b/g
643 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
644 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
645 } else {
646 if (pBSSList->sERP.bERPExist == TRUE) {
647 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
648 } else {
649 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
653 pBSSList->byRxRate = pRxPacket->byRxRate;
654 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
655 if(bChannelHit)
656 pBSSList->uRSSI = pRxPacket->uRSSI;
657 pBSSList->bySQ = pRxPacket->bySQ;
659 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
660 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
661 // assoc with BSS
662 if (pBSSList == pMgmt->pCurrBSS) {
663 bParsingQuiet = TRUE;
667 WPA_ClearRSN(pBSSList); //mike update
669 if (pRSNWPA != NULL) {
670 unsigned int uLen = pRSNWPA->len + 2;
671 if (uLen <= (uIELength -
672 (unsigned int) (ULONG_PTR) ((PBYTE) pRSNWPA - pbyIEs))) {
673 pBSSList->wWPALen = uLen;
674 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
675 WPA_ParseRSN(pBSSList, pRSNWPA);
679 WPA2_ClearRSN(pBSSList); //mike update
681 if (pRSN != NULL) {
682 unsigned int uLen = pRSN->len + 2;
683 if (uLen <= (uIELength -
684 (unsigned int) (ULONG_PTR) ((PBYTE) pRSN - pbyIEs))) {
685 pBSSList->wRSNLen = uLen;
686 memcpy(pBSSList->byRSNIE, pRSN, uLen);
687 WPA2vParseRSN(pBSSList, pRSN);
691 if (pRxPacket->uRSSI != 0) {
692 RFvRSSITodBm(pDevice, (BYTE)(pRxPacket->uRSSI), &ldBm);
693 // Moniter if RSSI is too strong.
694 pBSSList->byRSSIStatCnt++;
695 pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
696 pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
697 ldBmSum = 0;
698 for (ii = 0, jj = 0; ii < RSSI_STAT_COUNT; ii++) {
699 if (pBSSList->ldBmAverage[ii] != 0) {
700 pBSSList->ldBmMAX =
701 max(pBSSList->ldBmAverage[ii], ldBm);
702 ldBmSum +=
703 pBSSList->ldBmAverage[ii];
704 jj++;
707 pBSSList->ldBmAverRange = ldBmSum /jj;
710 pBSSList->uIELength = uIELength;
711 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
712 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
713 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
715 return TRUE;
724 * Routine Description:
725 * Search Node DB table to find the index of matched DstAddr
727 * Return Value:
728 * None
732 BOOL BSSbIsSTAInNodeDB(void *hDeviceContext,
733 PBYTE abyDstAddr,
734 unsigned int *puNodeIndex)
736 PSDevice pDevice = (PSDevice)hDeviceContext;
737 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
738 unsigned int ii;
740 // Index = 0 reserved for AP Node
741 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
742 if (pMgmt->sNodeDBTable[ii].bActive) {
743 if (!compare_ether_addr(abyDstAddr,
744 pMgmt->sNodeDBTable[ii].abyMACAddr)) {
745 *puNodeIndex = ii;
746 return TRUE;
751 return FALSE;
758 * Routine Description:
759 * Find an empty node and allocated; if no empty found,
760 * instand used of most inactive one.
762 * Return Value:
763 * None
766 void BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex)
769 PSDevice pDevice = (PSDevice)hDeviceContext;
770 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
771 unsigned int ii;
772 unsigned int BigestCount = 0;
773 unsigned int SelectIndex;
774 struct sk_buff *skb;
775 // Index = 0 reserved for AP Node (In STA mode)
776 // Index = 0 reserved for Broadcast/MultiCast (In AP mode)
777 SelectIndex = 1;
778 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
779 if (pMgmt->sNodeDBTable[ii].bActive) {
780 if (pMgmt->sNodeDBTable[ii].uInActiveCount > BigestCount) {
781 BigestCount = pMgmt->sNodeDBTable[ii].uInActiveCount;
782 SelectIndex = ii;
785 else {
786 break;
790 // if not found replace uInActiveCount is largest one.
791 if ( ii == (MAX_NODE_NUM + 1)) {
792 *puNodeIndex = SelectIndex;
793 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Replace inactive node = %d\n", SelectIndex);
794 // clear ps buffer
795 if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
796 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
797 dev_kfree_skb(skb);
800 else {
801 *puNodeIndex = ii;
804 memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
805 pMgmt->sNodeDBTable[*puNodeIndex].bActive = TRUE;
806 pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
807 // for AP mode PS queue
808 skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
809 pMgmt->sNodeDBTable[*puNodeIndex].byAuthSequence = 0;
810 pMgmt->sNodeDBTable[*puNodeIndex].wEnQueueCnt = 0;
811 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create node index = %d\n", ii);
812 return;
819 * Routine Description:
820 * Remove Node by NodeIndex
823 * Return Value:
824 * None
828 void BSSvRemoveOneNode(void *hDeviceContext, unsigned int uNodeIndex)
831 PSDevice pDevice = (PSDevice)hDeviceContext;
832 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
833 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
834 struct sk_buff *skb;
837 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
838 dev_kfree_skb(skb);
839 // clear context
840 memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
841 // clear tx bit map
842 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &= ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
844 return;
848 * Routine Description:
849 * Update AP Node content in Index 0 of KnownNodeDB
852 * Return Value:
853 * None
857 void BSSvUpdateAPNode(void *hDeviceContext,
858 PWORD pwCapInfo,
859 PWLAN_IE_SUPP_RATES pSuppRates,
860 PWLAN_IE_SUPP_RATES pExtSuppRates)
862 PSDevice pDevice = (PSDevice)hDeviceContext;
863 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
864 unsigned int uRateLen = WLAN_RATES_MAXLEN;
866 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
868 pMgmt->sNodeDBTable[0].bActive = TRUE;
869 if (pDevice->byBBType == BB_TYPE_11B) {
870 uRateLen = WLAN_RATES_MAXLEN_11B;
872 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
873 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
874 uRateLen);
875 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
876 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
877 uRateLen);
878 RATEvParseMaxRate((void *) pDevice,
879 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
880 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
881 TRUE,
882 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
883 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
884 &(pMgmt->sNodeDBTable[0].wSuppRate),
885 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
886 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
888 memcpy(pMgmt->sNodeDBTable[0].abyMACAddr, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
889 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxSuppRate;
890 pMgmt->sNodeDBTable[0].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo);
891 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
892 // Auto rate fallback function initiation.
893 // RATEbInit(pDevice);
894 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pMgmt->sNodeDBTable[0].wTxDataRate = %d \n", pMgmt->sNodeDBTable[0].wTxDataRate);
900 * Routine Description:
901 * Add Multicast Node content in Index 0 of KnownNodeDB
904 * Return Value:
905 * None
909 void BSSvAddMulticastNode(void *hDeviceContext)
911 PSDevice pDevice = (PSDevice)hDeviceContext;
912 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
914 if (!pDevice->bEnableHostWEP)
915 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
916 memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
917 pMgmt->sNodeDBTable[0].bActive = TRUE;
918 pMgmt->sNodeDBTable[0].bPSEnable = FALSE;
919 skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
920 RATEvParseMaxRate((void *) pDevice,
921 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
922 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
923 TRUE,
924 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
925 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
926 &(pMgmt->sNodeDBTable[0].wSuppRate),
927 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
928 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
930 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
931 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
937 * Routine Description:
940 * Second call back function to update Node DB info & AP link status
943 * Return Value:
944 * none.
948 void BSSvSecondCallBack(void *hDeviceContext)
950 PSDevice pDevice = (PSDevice)hDeviceContext;
951 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
952 unsigned int ii;
953 PWLAN_IE_SSID pItemSSID, pCurrSSID;
954 unsigned int uSleepySTACnt = 0;
955 unsigned int uNonShortSlotSTACnt = 0;
956 unsigned int uLongPreambleSTACnt = 0;
957 viawget_wpa_header *wpahdr;
959 spin_lock_irq(&pDevice->lock);
961 pDevice->uAssocCount = 0;
963 //Power Saving Mode Tx Burst
964 if ( pDevice->bEnablePSMode == TRUE ) {
965 pDevice->ulPSModeWaitTx++;
966 if ( pDevice->ulPSModeWaitTx >= 2 ) {
967 pDevice->ulPSModeWaitTx = 0;
968 pDevice->bPSModeTxBurst = FALSE;
972 pDevice->byERPFlag &=
973 ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
975 if (pDevice->wUseProtectCntDown > 0) {
976 pDevice->wUseProtectCntDown --;
978 else {
979 // disable protect mode
980 pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
983 if(pDevice->byReAssocCount > 0) {
984 pDevice->byReAssocCount++;
985 if((pDevice->byReAssocCount > 10) && (pDevice->bLinkPass != TRUE)) { //10 sec timeout
986 printk("Re-association timeout!!!\n");
987 pDevice->byReAssocCount = 0;
988 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
989 // if(pDevice->bWPASuppWextEnabled == TRUE)
991 union iwreq_data wrqu;
992 memset(&wrqu, 0, sizeof (wrqu));
993 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
994 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
995 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
997 #endif
999 else if(pDevice->bLinkPass == TRUE)
1000 pDevice->byReAssocCount = 0;
1003 if((pMgmt->eCurrState!=WMAC_STATE_ASSOC) &&
1004 (pMgmt->eLastState==WMAC_STATE_ASSOC))
1006 union iwreq_data wrqu;
1007 memset(&wrqu, 0, sizeof(wrqu));
1008 wrqu.data.flags = RT_DISCONNECTED_EVENT_FLAG;
1009 wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, NULL);
1011 pMgmt->eLastState = pMgmt->eCurrState ;
1013 s_uCalculateLinkQual((void *)pDevice);
1015 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
1017 if (pMgmt->sNodeDBTable[ii].bActive) {
1018 // Increase in-activity counter
1019 pMgmt->sNodeDBTable[ii].uInActiveCount++;
1021 if (ii > 0) {
1022 if (pMgmt->sNodeDBTable[ii].uInActiveCount > MAX_INACTIVE_COUNT) {
1023 BSSvRemoveOneNode(pDevice, ii);
1024 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1025 "Inactive timeout [%d] sec, STA index = [%d] remove\n", MAX_INACTIVE_COUNT, ii);
1026 continue;
1029 if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
1031 pDevice->uAssocCount++;
1033 // check if Non ERP exist
1034 if (pMgmt->sNodeDBTable[ii].uInActiveCount < ERP_RECOVER_COUNT) {
1035 if (!pMgmt->sNodeDBTable[ii].bShortPreamble) {
1036 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
1037 uLongPreambleSTACnt ++;
1039 if (!pMgmt->sNodeDBTable[ii].bERPExist) {
1040 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
1041 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1043 if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
1044 uNonShortSlotSTACnt++;
1048 // check if any STA in PS mode
1049 if (pMgmt->sNodeDBTable[ii].bPSEnable)
1050 uSleepySTACnt++;
1055 // Rate fallback check
1056 if (!pDevice->bFixRate) {
1058 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (ii == 0))
1059 RATEvTxRateFallBack(pDevice, &(pMgmt->sNodeDBTable[ii]));
1061 if (ii > 0) {
1062 // ii = 0 for multicast node (AP & Adhoc)
1063 RATEvTxRateFallBack((void *)pDevice,
1064 &(pMgmt->sNodeDBTable[ii]));
1066 else {
1067 // ii = 0 reserved for unicast AP node (Infra STA)
1068 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
1069 RATEvTxRateFallBack((void *)pDevice,
1070 &(pMgmt->sNodeDBTable[ii]));
1075 // check if pending PS queue
1076 if (pMgmt->sNodeDBTable[ii].wEnQueueCnt != 0) {
1077 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index= %d, Queue = %d pending \n",
1078 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
1079 if ((ii >0) && (pMgmt->sNodeDBTable[ii].wEnQueueCnt > 15)) {
1080 BSSvRemoveOneNode(pDevice, ii);
1081 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Pending many queues PS STA Index = %d remove \n", ii);
1082 continue;
1090 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->byBBType == BB_TYPE_11G)) {
1092 // on/off protect mode
1093 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
1094 if (!pDevice->bProtectMode) {
1095 MACvEnableProtectMD(pDevice);
1096 pDevice->bProtectMode = TRUE;
1099 else {
1100 if (pDevice->bProtectMode) {
1101 MACvDisableProtectMD(pDevice);
1102 pDevice->bProtectMode = FALSE;
1105 // on/off short slot time
1107 if (uNonShortSlotSTACnt > 0) {
1108 if (pDevice->bShortSlotTime) {
1109 pDevice->bShortSlotTime = FALSE;
1110 BBvSetShortSlotTime(pDevice);
1111 vUpdateIFS((void *)pDevice);
1114 else {
1115 if (!pDevice->bShortSlotTime) {
1116 pDevice->bShortSlotTime = TRUE;
1117 BBvSetShortSlotTime(pDevice);
1118 vUpdateIFS((void *)pDevice);
1122 // on/off barker long preamble mode
1124 if (uLongPreambleSTACnt > 0) {
1125 if (!pDevice->bBarkerPreambleMd) {
1126 MACvEnableBarkerPreambleMd(pDevice);
1127 pDevice->bBarkerPreambleMd = TRUE;
1130 else {
1131 if (pDevice->bBarkerPreambleMd) {
1132 MACvDisableBarkerPreambleMd(pDevice);
1133 pDevice->bBarkerPreambleMd = FALSE;
1140 // Check if any STA in PS mode, enable DTIM multicast deliver
1141 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1142 if (uSleepySTACnt > 0)
1143 pMgmt->sNodeDBTable[0].bPSEnable = TRUE;
1144 else
1145 pMgmt->sNodeDBTable[0].bPSEnable = FALSE;
1148 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
1149 pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
1151 if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
1152 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
1154 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
1155 // DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Callback inactive Count = [%d]\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1157 if (pDevice->bUpdateBBVGA) {
1158 /* s_vCheckSensitivity((void *) pDevice); */
1159 s_vCheckPreEDThreshold((void *) pDevice);
1162 if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
1163 (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0]) ) {
1164 pDevice->byBBVGANew = pDevice->abyBBVGA[0];
1165 bScheduleCommand((void *) pDevice,
1166 WLAN_CMD_CHANGE_BBSENSITIVITY,
1167 NULL);
1170 if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
1171 pMgmt->sNodeDBTable[0].bActive = FALSE;
1172 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1173 pMgmt->eCurrState = WMAC_STATE_IDLE;
1174 netif_stop_queue(pDevice->dev);
1175 pDevice->bLinkPass = FALSE;
1176 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
1177 pDevice->bRoaming = TRUE;
1178 pDevice->bIsRoaming = FALSE;
1180 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1181 /* let wpa supplicant know AP may disconnect */
1182 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1183 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1184 wpahdr->type = VIAWGET_DISASSOC_MSG;
1185 wpahdr->resp_ie_len = 0;
1186 wpahdr->req_ie_len = 0;
1187 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1188 pDevice->skb->dev = pDevice->wpadev;
1189 skb_reset_mac_header(pDevice->skb);
1190 pDevice->skb->pkt_type = PACKET_HOST;
1191 pDevice->skb->protocol = htons(ETH_P_802_2);
1192 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1193 netif_rx(pDevice->skb);
1194 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1196 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1197 // if(pDevice->bWPASuppWextEnabled == TRUE)
1199 union iwreq_data wrqu;
1200 memset(&wrqu, 0, sizeof (wrqu));
1201 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1202 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1203 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1205 #endif
1208 else if (pItemSSID->len != 0) {
1209 //Davidwang
1210 if ((pDevice->bEnableRoaming == TRUE)&&(!(pMgmt->Cisco_cckm))) {
1211 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bRoaming %d, !\n", pDevice->bRoaming );
1212 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bIsRoaming %d, !\n", pDevice->bIsRoaming );
1213 if ((pDevice->bRoaming == TRUE)&&(pDevice->bIsRoaming == TRUE)){
1214 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fast Roaming ...\n");
1215 BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass);
1216 bScheduleCommand((void *) pDevice,
1217 WLAN_CMD_BSSID_SCAN,
1218 pMgmt->abyDesireSSID);
1219 bScheduleCommand((void *) pDevice,
1220 WLAN_CMD_SSID,
1221 pMgmt->abyDesireSSID);
1222 pDevice->uAutoReConnectTime = 0;
1223 pDevice->uIsroamingTime = 0;
1224 pDevice->bRoaming = FALSE;
1226 // if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1227 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1228 wpahdr->type = VIAWGET_CCKM_ROAM_MSG;
1229 wpahdr->resp_ie_len = 0;
1230 wpahdr->req_ie_len = 0;
1231 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1232 pDevice->skb->dev = pDevice->wpadev;
1233 skb_reset_mac_header(pDevice->skb);
1234 pDevice->skb->pkt_type = PACKET_HOST;
1235 pDevice->skb->protocol = htons(ETH_P_802_2);
1236 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1237 netif_rx(pDevice->skb);
1238 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1240 // }
1242 else if ((pDevice->bRoaming == FALSE)&&(pDevice->bIsRoaming == TRUE)) {
1243 pDevice->uIsroamingTime++;
1244 if (pDevice->uIsroamingTime >= 20)
1245 pDevice->bIsRoaming = FALSE;
1249 else {
1250 if (pDevice->uAutoReConnectTime < 10) {
1251 pDevice->uAutoReConnectTime++;
1252 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1253 //network manager support need not do Roaming scan???
1254 if(pDevice->bWPASuppWextEnabled ==TRUE)
1255 pDevice->uAutoReConnectTime = 0;
1256 #endif
1258 else {
1259 //mike use old encryption status for wpa reauthen
1260 if(pDevice->bWPADEVUp)
1261 pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
1263 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming ...\n");
1264 BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass);
1265 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1266 bScheduleCommand((void *) pDevice,
1267 WLAN_CMD_BSSID_SCAN,
1268 pMgmt->abyDesireSSID);
1269 bScheduleCommand((void *) pDevice,
1270 WLAN_CMD_SSID,
1271 pMgmt->abyDesireSSID);
1272 pDevice->uAutoReConnectTime = 0;
1278 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1279 // if adhoc started which essid is NULL string, rescaning.
1280 if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
1281 if (pDevice->uAutoReConnectTime < 10) {
1282 pDevice->uAutoReConnectTime++;
1284 else {
1285 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Adhoc re-scaning ...\n");
1286 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1287 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1288 bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
1289 pDevice->uAutoReConnectTime = 0;
1292 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
1294 if (pDevice->bUpdateBBVGA) {
1295 /* s_vCheckSensitivity((void *) pDevice); */
1296 s_vCheckPreEDThreshold((void *) pDevice);
1298 if (pMgmt->sNodeDBTable[0].uInActiveCount >=ADHOC_LOST_BEACON_COUNT) {
1299 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1300 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1301 pMgmt->eCurrState = WMAC_STATE_STARTED;
1302 netif_stop_queue(pDevice->dev);
1303 pDevice->bLinkPass = FALSE;
1304 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
1309 if (pDevice->bLinkPass == TRUE) {
1310 if (netif_queue_stopped(pDevice->dev))
1311 netif_wake_queue(pDevice->dev);
1314 spin_unlock_irq(&pDevice->lock);
1316 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
1317 add_timer(&pMgmt->sTimerSecondCallback);
1318 return;
1323 * Routine Description:
1326 * Update Tx attemps, Tx failure counter in Node DB
1329 * Return Value:
1330 * none.
1334 void BSSvUpdateNodeTxCounter(void *hDeviceContext,
1335 PSStatCounter pStatistic,
1336 BYTE byTSR,
1337 BYTE byPktNO)
1339 PSDevice pDevice = (PSDevice)hDeviceContext;
1340 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1341 unsigned int uNodeIndex = 0;
1342 BYTE byTxRetry;
1343 WORD wRate;
1344 WORD wFallBackRate = RATE_1M;
1345 BYTE byFallBack;
1346 unsigned int ii;
1347 PBYTE pbyDestAddr;
1348 BYTE byPktNum;
1349 WORD wFIFOCtl;
1351 byPktNum = (byPktNO & 0x0F) >> 4;
1352 byTxRetry = (byTSR & 0xF0) >> 4;
1353 wRate = (WORD) (byPktNO & 0xF0) >> 4;
1354 wFIFOCtl = pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl;
1355 pbyDestAddr = (PBYTE) &( pStatistic->abyTxPktInfo[byPktNum].abyDestAddr[0]);
1357 if (wFIFOCtl & FIFOCTL_AUTO_FB_0) {
1358 byFallBack = AUTO_FB_0;
1359 } else if (wFIFOCtl & FIFOCTL_AUTO_FB_1) {
1360 byFallBack = AUTO_FB_1;
1361 } else {
1362 byFallBack = AUTO_FB_NONE;
1365 // Only Unicast using support rates
1366 if (wFIFOCtl & FIFOCTL_NEEDACK) {
1367 //DBG_PRN_GRP21(("Device %08X, wRate %04X, byTSR %02X\n", hDeviceContext, wRate, byTSR));
1368 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
1369 pMgmt->sNodeDBTable[0].uTxAttempts += 1;
1370 if ( !(byTSR & (TSR_TMO | TSR_RETRYTMO))) {
1371 // transmit success, TxAttempts at least plus one
1372 pMgmt->sNodeDBTable[0].uTxOk[MAX_RATE]++;
1373 if ( (byFallBack == AUTO_FB_NONE) ||
1374 (wRate < RATE_18M) ) {
1375 wFallBackRate = wRate;
1376 } else if (byFallBack == AUTO_FB_0) {
1377 if (byTxRetry < 5)
1378 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1379 else
1380 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1381 } else if (byFallBack == AUTO_FB_1) {
1382 if (byTxRetry < 5)
1383 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1384 else
1385 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1387 pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
1388 } else {
1389 pMgmt->sNodeDBTable[0].uTxFailures ++;
1391 pMgmt->sNodeDBTable[0].uTxRetry += byTxRetry;
1392 if (byTxRetry != 0) {
1393 pMgmt->sNodeDBTable[0].uTxFail[MAX_RATE]+=byTxRetry;
1394 if ( (byFallBack == AUTO_FB_NONE) ||
1395 (wRate < RATE_18M) ) {
1396 pMgmt->sNodeDBTable[0].uTxFail[wRate]+=byTxRetry;
1397 } else if (byFallBack == AUTO_FB_0) {
1398 for (ii = 0; ii < byTxRetry; ii++) {
1399 if (ii < 5)
1400 wFallBackRate =
1401 awHWRetry0[wRate-RATE_18M][ii];
1402 else
1403 wFallBackRate =
1404 awHWRetry0[wRate-RATE_18M][4];
1405 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1407 } else if (byFallBack == AUTO_FB_1) {
1408 for (ii = 0; ii < byTxRetry; ii++) {
1409 if (ii < 5)
1410 wFallBackRate =
1411 awHWRetry1[wRate-RATE_18M][ii];
1412 else
1413 wFallBackRate =
1414 awHWRetry1[wRate-RATE_18M][4];
1415 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1421 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
1422 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1424 if (BSSbIsSTAInNodeDB((void *) pDevice,
1425 pbyDestAddr,
1426 &uNodeIndex)) {
1427 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
1428 if ( !(byTSR & (TSR_TMO | TSR_RETRYTMO))) {
1429 // transmit success, TxAttempts at least plus one
1430 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
1431 if ( (byFallBack == AUTO_FB_NONE) ||
1432 (wRate < RATE_18M) ) {
1433 wFallBackRate = wRate;
1434 } else if (byFallBack == AUTO_FB_0) {
1435 if (byTxRetry < 5)
1436 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1437 else
1438 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1439 } else if (byFallBack == AUTO_FB_1) {
1440 if (byTxRetry < 5)
1441 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1442 else
1443 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1445 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
1446 } else {
1447 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures ++;
1449 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += byTxRetry;
1450 if (byTxRetry != 0) {
1451 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[MAX_RATE]+=byTxRetry;
1452 if ( (byFallBack == AUTO_FB_NONE) ||
1453 (wRate < RATE_18M) ) {
1454 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wRate]+=byTxRetry;
1455 } else if (byFallBack == AUTO_FB_0) {
1456 for (ii = 0; ii < byTxRetry; ii++) {
1457 if (ii < 5)
1458 wFallBackRate =
1459 awHWRetry0[wRate-RATE_18M][ii];
1460 else
1461 wFallBackRate =
1462 awHWRetry0[wRate-RATE_18M][4];
1463 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1465 } else if (byFallBack == AUTO_FB_1) {
1466 for (ii = 0; ii < byTxRetry; ii++) {
1467 if (ii < 5)
1468 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1469 else
1470 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1471 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1479 return;
1486 * Routine Description:
1487 * Clear Nodes & skb in DB Table
1490 * Parameters:
1491 * In:
1492 * hDeviceContext - The adapter context.
1493 * uStartIndex - starting index
1494 * Out:
1495 * none
1497 * Return Value:
1498 * None.
1502 void BSSvClearNodeDBTable(void *hDeviceContext,
1503 unsigned int uStartIndex)
1505 PSDevice pDevice = (PSDevice)hDeviceContext;
1506 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1507 struct sk_buff *skb;
1508 unsigned int ii;
1510 for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
1511 if (pMgmt->sNodeDBTable[ii].bActive) {
1512 // check if sTxPSQueue has been initial
1513 if (pMgmt->sNodeDBTable[ii].sTxPSQueue.next != NULL) {
1514 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL){
1515 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS skb != NULL %d\n", ii);
1516 dev_kfree_skb(skb);
1519 memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
1523 return;
1526 void s_vCheckSensitivity(void *hDeviceContext)
1528 PSDevice pDevice = (PSDevice)hDeviceContext;
1529 PKnownBSS pBSSList = NULL;
1530 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1531 int ii;
1533 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1534 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1535 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1536 if (pBSSList != NULL) {
1537 /* Update BB register if RSSI is too strong */
1538 signed long LocalldBmAverage = 0;
1539 signed long uNumofdBm = 0;
1540 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
1541 if (pBSSList->ldBmAverage[ii] != 0) {
1542 uNumofdBm ++;
1543 LocalldBmAverage += pBSSList->ldBmAverage[ii];
1546 if (uNumofdBm > 0) {
1547 LocalldBmAverage = LocalldBmAverage/uNumofdBm;
1548 for (ii=0;ii<BB_VGA_LEVEL;ii++) {
1549 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LocalldBmAverage:%ld, %ld %02x\n", LocalldBmAverage, pDevice->ldBmThreshold[ii], pDevice->abyBBVGA[ii]);
1550 if (LocalldBmAverage < pDevice->ldBmThreshold[ii]) {
1551 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1552 break;
1555 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1556 pDevice->uBBVGADiffCount++;
1557 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
1558 bScheduleCommand((void *) pDevice,
1559 WLAN_CMD_CHANGE_BBSENSITIVITY,
1560 NULL);
1561 } else {
1562 pDevice->uBBVGADiffCount = 0;
1569 void s_uCalculateLinkQual(void *hDeviceContext)
1571 PSDevice pDevice = (PSDevice)hDeviceContext;
1572 unsigned long TxOkRatio, TxCnt;
1573 unsigned long RxOkRatio, RxCnt;
1574 unsigned long RssiRatio;
1575 long ldBm;
1577 TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
1578 pDevice->scStatistic.TxRetryOkCount +
1579 pDevice->scStatistic.TxFailCount;
1580 RxCnt = pDevice->scStatistic.RxFcsErrCnt +
1581 pDevice->scStatistic.RxOkCnt;
1582 TxOkRatio = (TxCnt < 6) ? 4000:((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
1583 RxOkRatio = (RxCnt < 6) ? 2000:((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
1584 //decide link quality
1585 if(pDevice->bLinkPass !=TRUE)
1587 // printk("s_uCalculateLinkQual-->Link disconnect and Poor quality**\n");
1588 pDevice->scStatistic.LinkQuality = 0;
1589 pDevice->scStatistic.SignalStren = 0;
1591 else
1593 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
1594 if(-ldBm < 50) {
1595 RssiRatio = 4000;
1597 else if(-ldBm > 90) {
1598 RssiRatio = 0;
1600 else {
1601 RssiRatio = (40-(-ldBm-50))*4000/40;
1603 pDevice->scStatistic.SignalStren = RssiRatio/40;
1604 pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
1606 pDevice->scStatistic.RxFcsErrCnt = 0;
1607 pDevice->scStatistic.RxOkCnt = 0;
1608 pDevice->scStatistic.TxFailCount = 0;
1609 pDevice->scStatistic.TxNoRetryOkCount = 0;
1610 pDevice->scStatistic.TxRetryOkCount = 0;
1611 return;
1614 void BSSvClearAnyBSSJoinRecord(void *hDeviceContext)
1616 PSDevice pDevice = (PSDevice)hDeviceContext;
1617 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1618 unsigned int ii;
1620 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
1621 pMgmt->sBSSList[ii].bSelected = FALSE;
1623 return;
1626 void s_vCheckPreEDThreshold(void *hDeviceContext)
1628 PSDevice pDevice = (PSDevice)hDeviceContext;
1629 PKnownBSS pBSSList = NULL;
1630 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1632 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1633 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1634 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1635 if (pBSSList != NULL) {
1636 pDevice->byBBPreEDRSSI = (BYTE) (~(pBSSList->ldBmAverRange) + 1);
1637 BBvUpdatePreEDThreshold(pDevice, FALSE);
1640 return;