2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
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.
21 * Purpose: Handles the Basic Service Set & Node Database 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
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);
98 void s_uCalculateLinkQual(void *hDeviceContext);
101 /*--------------------- Export Variables --------------------------*/
104 /*--------------------- Export Functions --------------------------*/
112 * Routine Description:
113 * Search known BSS list for Desire SSID or BSSID.
116 * PTR to KnownBSS or NULL
120 PKnownBSS BSSpSearchBSSList(void *hDeviceContext,
121 PBYTE pbyDesireBSSID,
123 CARD_PHY_TYPE ePhyType)
125 PSDevice pDevice = (PSDevice)hDeviceContext;
126 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
127 PBYTE pbyBSSID = NULL;
128 PWLAN_IE_SSID pSSID = NULL;
129 PKnownBSS pCurrBSS = NULL;
130 PKnownBSS pSelect = NULL;
131 BYTE ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
134 if (pbyDesireBSSID != NULL) {
135 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSpSearchBSSList BSSID[%02X %02X %02X-%02X %02X %02X]\n",
136 *pbyDesireBSSID,*(pbyDesireBSSID+1),*(pbyDesireBSSID+2),
137 *(pbyDesireBSSID+3),*(pbyDesireBSSID+4),*(pbyDesireBSSID+5));
138 if ((!is_broadcast_ether_addr(pbyDesireBSSID)) &&
139 (memcmp(pbyDesireBSSID, ZeroBSSID, 6)!= 0)){
140 pbyBSSID = pbyDesireBSSID;
143 if (pbyDesireSSID != NULL) {
144 if (((PWLAN_IE_SSID)pbyDesireSSID)->len != 0) {
145 pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
149 if ((pbyBSSID != NULL)&&(pDevice->bRoaming == FALSE)) {
151 for (ii = 0; ii <MAX_BSS_NUM; ii++) {
152 pCurrBSS = &(pMgmt->sBSSList[ii]);
154 //2008-0718-01<Add>by MikeLiu
155 pCurrBSS->bSelected = FALSE;
157 if ((pCurrBSS->bActive) &&
158 (pCurrBSS->bSelected == FALSE)) {
159 if (!compare_ether_addr(pCurrBSS->abyBSSID, pbyBSSID)) {
162 if ( !memcmp(pSSID->abySSID,
163 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
165 if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
166 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
167 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
169 pCurrBSS->bSelected = TRUE;
174 if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
175 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
176 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
178 pCurrBSS->bSelected = TRUE;
187 for (ii = 0; ii <MAX_BSS_NUM; ii++) {
188 pCurrBSS = &(pMgmt->sBSSList[ii]);
190 //2007-0721-01<Mark>by MikeLiu
191 // if ((pCurrBSS->bActive) &&
192 // (pCurrBSS->bSelected == FALSE)) {
194 //2007-0721-01<Add>by MikeLiu
195 pCurrBSS->bSelected = FALSE;
196 if (pCurrBSS->bActive) {
200 if (memcmp(pSSID->abySSID,
201 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
203 (pSSID->len != ((PWLAN_IE_SSID)pCurrBSS->abySSID)->len)) {
204 // SSID not match skip this BSS
208 if (((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) ||
209 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo))
211 // Type not match skip this BSS
212 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSS type mismatch.... Config[%d] BSS[0x%04x]\n", pMgmt->eConfigMode, pCurrBSS->wCapInfo);
216 if (ePhyType != PHY_TYPE_AUTO) {
217 if (((ePhyType == PHY_TYPE_11A) && (PHY_TYPE_11A != pCurrBSS->eNetworkTypeInUse)) ||
218 ((ePhyType != PHY_TYPE_11A) && (PHY_TYPE_11A == pCurrBSS->eNetworkTypeInUse))) {
219 // PhyType not match skip this BSS
220 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Physical type mismatch.... ePhyType[%d] BSS[%d]\n", ePhyType, pCurrBSS->eNetworkTypeInUse);
225 if (pMgmt->eAuthenMode < WMAC_AUTH_WPA) {
226 if (pCurrBSS->bWPAValid == TRUE) {
227 // WPA AP will reject connection of station without WPA enable.
230 } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
231 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
232 if (pCurrBSS->bWPAValid == FALSE) {
233 // station with WPA enable can't join NonWPA AP.
236 } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
237 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
238 if (pCurrBSS->bWPA2Valid == FALSE) {
239 // station with WPA2 enable can't join NonWPA2 AP.
245 pMgmt->pSameBSS[jj].uChannel = pCurrBSS->uChannel;
246 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));
250 if (pSelect == NULL) {
253 // compare RSSI, select signal strong one
254 if (pCurrBSS->uRSSI < pSelect->uRSSI) {
261 pDevice->bSameBSSMaxNum = jj;
263 if (pSelect != NULL) {
264 pSelect->bSelected = TRUE;
265 if (pDevice->bRoaming == FALSE) {
266 // Einsn Add @20070907
267 memset(pbyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
268 memcpy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1) ;
281 * Routine Description:
290 void BSSvClearBSSList(void *hDeviceContext, BOOL bKeepCurrBSSID)
292 PSDevice pDevice = (PSDevice)hDeviceContext;
293 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
296 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
297 if (bKeepCurrBSSID) {
298 if (pMgmt->sBSSList[ii].bActive &&
299 !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID,
300 pMgmt->abyCurrBSSID)) {
301 //mike mark: there are two same BSSID in list if that AP is in hidden ssid mode,one 's SSID is null,
302 // but other's is obvious, so if it acssociate with your STA exactly,you must keep two
304 // bKeepCurrBSSID = FALSE;
309 if ((pMgmt->sBSSList[ii].bActive) && (pMgmt->sBSSList[ii].uClearCount < BSS_CLEAR_COUNT)) {
310 pMgmt->sBSSList[ii].uClearCount ++;
314 pMgmt->sBSSList[ii].bActive = FALSE;
315 memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS));
317 BSSvClearAnyBSSJoinRecord(pDevice);
326 * Routine Description:
327 * search BSS list by BSSID & SSID if matched
333 PKnownBSS BSSpAddrIsInBSSList(void *hDeviceContext,
337 PSDevice pDevice = (PSDevice)hDeviceContext;
338 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
339 PKnownBSS pBSSList = NULL;
342 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
343 pBSSList = &(pMgmt->sBSSList[ii]);
344 if (pBSSList->bActive) {
345 if (!compare_ether_addr(pBSSList->abyBSSID, abyBSSID)) {
346 if (pSSID->len == ((PWLAN_IE_SSID)pBSSList->abySSID)->len){
347 if (memcmp(pSSID->abySSID,
348 ((PWLAN_IE_SSID)pBSSList->abySSID)->abySSID,
363 * Routine Description:
364 * Insert a BSS set into known BSS list
371 BOOL BSSbInsertToBSSList(void *hDeviceContext,
374 WORD wBeaconInterval,
378 PWLAN_IE_SUPP_RATES pSuppRates,
379 PWLAN_IE_SUPP_RATES pExtSuppRates,
382 PWLAN_IE_RSN_EXT pRSNWPA,
383 PWLAN_IE_COUNTRY pIE_Country,
384 PWLAN_IE_QUIET pIE_Quiet,
385 unsigned int uIELength,
387 void *pRxPacketContext)
390 PSDevice pDevice = (PSDevice)hDeviceContext;
391 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
392 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
393 PKnownBSS pBSSList = NULL;
395 BOOL bParsingQuiet = FALSE;
399 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
401 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
402 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[ii]);
403 if (!pBSSList->bActive)
407 if (ii == MAX_BSS_NUM){
408 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n");
412 pBSSList->bActive = TRUE;
413 memcpy( pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
414 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
415 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
416 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
417 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
418 pBSSList->uClearCount = 0;
420 if (pSSID->len > WLAN_SSID_MAXLEN)
421 pSSID->len = WLAN_SSID_MAXLEN;
422 memcpy( pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
424 pBSSList->uChannel = byCurrChannel;
426 if (pSuppRates->len > WLAN_RATES_MAXLEN)
427 pSuppRates->len = WLAN_RATES_MAXLEN;
428 memcpy( pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
430 if (pExtSuppRates != NULL) {
431 if (pExtSuppRates->len > WLAN_RATES_MAXLEN)
432 pExtSuppRates->len = WLAN_RATES_MAXLEN;
433 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
434 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSbInsertToBSSList: pExtSuppRates->len = %d\n", pExtSuppRates->len);
437 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
439 pBSSList->sERP.byERP = psERP->byERP;
440 pBSSList->sERP.bERPExist = psERP->bERPExist;
442 // Check if BSS is 802.11a/b/g
443 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
444 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
446 if (pBSSList->sERP.bERPExist == TRUE) {
447 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
449 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
453 pBSSList->byRxRate = pRxPacket->byRxRate;
454 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
455 pBSSList->uRSSI = pRxPacket->uRSSI;
456 pBSSList->bySQ = pRxPacket->bySQ;
458 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
459 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
461 if (pBSSList == pMgmt->pCurrBSS) {
462 bParsingQuiet = TRUE;
466 WPA_ClearRSN(pBSSList);
468 if (pRSNWPA != NULL) {
469 unsigned int uLen = pRSNWPA->len + 2;
471 if (uLen <= (uIELength -
472 (unsigned int) (ULONG_PTR) ((PBYTE) pRSNWPA - pbyIEs))) {
473 pBSSList->wWPALen = uLen;
474 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
475 WPA_ParseRSN(pBSSList, pRSNWPA);
479 WPA2_ClearRSN(pBSSList);
482 unsigned int uLen = pRSN->len + 2;
484 if (uLen <= (uIELength -
485 (unsigned int) (ULONG_PTR) ((PBYTE) pRSN - pbyIEs))) {
486 pBSSList->wRSNLen = uLen;
487 memcpy(pBSSList->byRSNIE, pRSN, uLen);
488 WPA2vParseRSN(pBSSList, pRSN);
492 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == TRUE)) {
494 PSKeyItem pTransmitKey = NULL;
495 BOOL bIs802_1x = FALSE;
497 for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii ++) {
498 if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
503 if ((bIs802_1x == TRUE) && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
504 ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
506 bAdd_PMKID_Candidate((void *) pDevice,
508 &pBSSList->sRSNCapObj);
510 if ((pDevice->bLinkPass == TRUE) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
511 if ((KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE) ||
512 (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey) == TRUE)) {
513 pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
514 pDevice->gsPMKIDCandidate.Version = 1;
522 if (pDevice->bUpdateBBVGA) {
523 // Moniter if RSSI is too strong.
524 pBSSList->byRSSIStatCnt = 0;
525 RFvRSSITodBm(pDevice, (BYTE)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
526 pBSSList->ldBmAverage[0] = pBSSList->ldBmMAX;
527 pBSSList->ldBmAverRange = pBSSList->ldBmMAX;
528 for (ii = 1; ii < RSSI_STAT_COUNT; ii++)
529 pBSSList->ldBmAverage[ii] = 0;
533 if ((pIE_Country != NULL) &&
534 (pMgmt->b11hEnable == TRUE)) {
535 CARDvSetCountryInfo(pMgmt->pAdapter,
536 pBSSList->eNetworkTypeInUse,
540 if ((bParsingQuiet == TRUE) && (pIE_Quiet != NULL)) {
541 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
542 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
544 if (pQuiet == NULL) {
545 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
546 CARDbSetQuiet( pMgmt->pAdapter,
548 pQuiet->byQuietCount,
549 pQuiet->byQuietPeriod,
550 *((PWORD)pQuiet->abyQuietDuration),
551 *((PWORD)pQuiet->abyQuietOffset)
554 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
555 CARDbSetQuiet( pMgmt->pAdapter,
557 pQuiet->byQuietCount,
558 pQuiet->byQuietPeriod,
559 *((PWORD)pQuiet->abyQuietDuration),
560 *((PWORD)pQuiet->abyQuietOffset)
566 if ((bParsingQuiet == TRUE) &&
568 CARDbStartQuiet(pMgmt->pAdapter);
572 pBSSList->uIELength = uIELength;
573 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
574 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
575 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
583 * Routine Description:
584 * Update BSS set in known BSS list
590 // TODO: input structure modify
592 BOOL BSSbUpdateToBSSList(void *hDeviceContext,
594 WORD wBeaconInterval,
599 PWLAN_IE_SUPP_RATES pSuppRates,
600 PWLAN_IE_SUPP_RATES pExtSuppRates,
603 PWLAN_IE_RSN_EXT pRSNWPA,
604 PWLAN_IE_COUNTRY pIE_Country,
605 PWLAN_IE_QUIET pIE_Quiet,
607 unsigned int uIELength,
609 void *pRxPacketContext)
612 PSDevice pDevice = (PSDevice)hDeviceContext;
613 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
614 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
615 signed long ldBm, ldBmSum;
616 BOOL bParsingQuiet = FALSE;
617 // BYTE abyTmpSSID[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1];
620 if (pBSSList == NULL)
624 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
625 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
626 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
627 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
628 pBSSList->uClearCount = 0;
629 pBSSList->uChannel = byCurrChannel;
630 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSbUpdateToBSSList: pBSSList->uChannel: %d\n", pBSSList->uChannel);
632 if (pSSID->len > WLAN_SSID_MAXLEN)
633 pSSID->len = WLAN_SSID_MAXLEN;
635 if ((pSSID->len != 0) && (pSSID->abySSID[0] != 0))
636 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
637 memcpy(pBSSList->abySuppRates, pSuppRates,pSuppRates->len + WLAN_IEHDR_LEN);
639 if (pExtSuppRates != NULL) {
640 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates,pExtSuppRates->len + WLAN_IEHDR_LEN);
642 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
644 pBSSList->sERP.byERP = psERP->byERP;
645 pBSSList->sERP.bERPExist = psERP->bERPExist;
647 // Check if BSS is 802.11a/b/g
648 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
649 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
651 if (pBSSList->sERP.bERPExist == TRUE) {
652 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
654 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
658 pBSSList->byRxRate = pRxPacket->byRxRate;
659 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
661 pBSSList->uRSSI = pRxPacket->uRSSI;
662 pBSSList->bySQ = pRxPacket->bySQ;
664 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
665 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
667 if (pBSSList == pMgmt->pCurrBSS) {
668 bParsingQuiet = TRUE;
672 WPA_ClearRSN(pBSSList); //mike update
674 if (pRSNWPA != NULL) {
675 unsigned int uLen = pRSNWPA->len + 2;
676 if (uLen <= (uIELength -
677 (unsigned int) (ULONG_PTR) ((PBYTE) pRSNWPA - pbyIEs))) {
678 pBSSList->wWPALen = uLen;
679 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
680 WPA_ParseRSN(pBSSList, pRSNWPA);
684 WPA2_ClearRSN(pBSSList); //mike update
687 unsigned int uLen = pRSN->len + 2;
688 if (uLen <= (uIELength -
689 (unsigned int) (ULONG_PTR) ((PBYTE) pRSN - pbyIEs))) {
690 pBSSList->wRSNLen = uLen;
691 memcpy(pBSSList->byRSNIE, pRSN, uLen);
692 WPA2vParseRSN(pBSSList, pRSN);
696 if (pRxPacket->uRSSI != 0) {
697 RFvRSSITodBm(pDevice, (BYTE)(pRxPacket->uRSSI), &ldBm);
698 // Moniter if RSSI is too strong.
699 pBSSList->byRSSIStatCnt++;
700 pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
701 pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
703 for (ii = 0, jj = 0; ii < RSSI_STAT_COUNT; ii++) {
704 if (pBSSList->ldBmAverage[ii] != 0) {
706 max(pBSSList->ldBmAverage[ii], ldBm);
708 pBSSList->ldBmAverage[ii];
712 pBSSList->ldBmAverRange = ldBmSum /jj;
715 pBSSList->uIELength = uIELength;
716 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
717 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
718 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
729 * Routine Description:
730 * Search Node DB table to find the index of matched DstAddr
737 BOOL BSSbIsSTAInNodeDB(void *hDeviceContext,
741 PSDevice pDevice = (PSDevice)hDeviceContext;
742 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
745 // Index = 0 reserved for AP Node
746 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
747 if (pMgmt->sNodeDBTable[ii].bActive) {
748 if (!compare_ether_addr(abyDstAddr,
749 pMgmt->sNodeDBTable[ii].abyMACAddr)) {
763 * Routine Description:
764 * Find an empty node and allocated; if no empty found,
765 * instand used of most inactive one.
771 void BSSvCreateOneNode(void *hDeviceContext, PUINT puNodeIndex)
774 PSDevice pDevice = (PSDevice)hDeviceContext;
775 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
777 unsigned int BigestCount = 0;
778 unsigned int SelectIndex;
780 // Index = 0 reserved for AP Node (In STA mode)
781 // Index = 0 reserved for Broadcast/MultiCast (In AP mode)
783 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
784 if (pMgmt->sNodeDBTable[ii].bActive) {
785 if (pMgmt->sNodeDBTable[ii].uInActiveCount > BigestCount) {
786 BigestCount = pMgmt->sNodeDBTable[ii].uInActiveCount;
795 // if not found replace uInActiveCount is largest one.
796 if ( ii == (MAX_NODE_NUM + 1)) {
797 *puNodeIndex = SelectIndex;
798 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Replace inactive node = %d\n", SelectIndex);
800 if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
801 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
809 memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
810 pMgmt->sNodeDBTable[*puNodeIndex].bActive = TRUE;
811 pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
812 // for AP mode PS queue
813 skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
814 pMgmt->sNodeDBTable[*puNodeIndex].byAuthSequence = 0;
815 pMgmt->sNodeDBTable[*puNodeIndex].wEnQueueCnt = 0;
816 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create node index = %d\n", ii);
824 * Routine Description:
825 * Remove Node by NodeIndex
833 void BSSvRemoveOneNode(void *hDeviceContext, unsigned int uNodeIndex)
836 PSDevice pDevice = (PSDevice)hDeviceContext;
837 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
838 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
842 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
845 memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
847 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &= ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
853 * Routine Description:
854 * Update AP Node content in Index 0 of KnownNodeDB
862 void BSSvUpdateAPNode(void *hDeviceContext,
864 PWLAN_IE_SUPP_RATES pSuppRates,
865 PWLAN_IE_SUPP_RATES pExtSuppRates)
867 PSDevice pDevice = (PSDevice)hDeviceContext;
868 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
869 unsigned int uRateLen = WLAN_RATES_MAXLEN;
871 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
873 pMgmt->sNodeDBTable[0].bActive = TRUE;
874 if (pDevice->byBBType == BB_TYPE_11B) {
875 uRateLen = WLAN_RATES_MAXLEN_11B;
877 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
878 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
880 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
881 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
883 RATEvParseMaxRate((void *) pDevice,
884 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
885 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
887 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
888 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
889 &(pMgmt->sNodeDBTable[0].wSuppRate),
890 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
891 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
893 memcpy(pMgmt->sNodeDBTable[0].abyMACAddr, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
894 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxSuppRate;
895 pMgmt->sNodeDBTable[0].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo);
896 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
897 // Auto rate fallback function initiation.
898 // RATEbInit(pDevice);
899 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pMgmt->sNodeDBTable[0].wTxDataRate = %d \n", pMgmt->sNodeDBTable[0].wTxDataRate);
905 * Routine Description:
906 * Add Multicast Node content in Index 0 of KnownNodeDB
914 void BSSvAddMulticastNode(void *hDeviceContext)
916 PSDevice pDevice = (PSDevice)hDeviceContext;
917 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
919 if (!pDevice->bEnableHostWEP)
920 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
921 memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
922 pMgmt->sNodeDBTable[0].bActive = TRUE;
923 pMgmt->sNodeDBTable[0].bPSEnable = FALSE;
924 skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
925 RATEvParseMaxRate((void *) pDevice,
926 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
927 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
929 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
930 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
931 &(pMgmt->sNodeDBTable[0].wSuppRate),
932 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
933 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
935 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
936 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
942 * Routine Description:
945 * Second call back function to update Node DB info & AP link status
953 void BSSvSecondCallBack(void *hDeviceContext)
955 PSDevice pDevice = (PSDevice)hDeviceContext;
956 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
958 PWLAN_IE_SSID pItemSSID, pCurrSSID;
959 unsigned int uSleepySTACnt = 0;
960 unsigned int uNonShortSlotSTACnt = 0;
961 unsigned int uLongPreambleSTACnt = 0;
962 viawget_wpa_header *wpahdr; //DavidWang
964 spin_lock_irq(&pDevice->lock);
966 pDevice->uAssocCount = 0;
968 //Power Saving Mode Tx Burst
969 if ( pDevice->bEnablePSMode == TRUE ) {
970 pDevice->ulPSModeWaitTx++;
971 if ( pDevice->ulPSModeWaitTx >= 2 ) {
972 pDevice->ulPSModeWaitTx = 0;
973 pDevice->bPSModeTxBurst = FALSE;
977 pDevice->byERPFlag &=
978 ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
980 if (pDevice->wUseProtectCntDown > 0) {
981 pDevice->wUseProtectCntDown --;
984 // disable protect mode
985 pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
988 if(pDevice->byReAssocCount > 0) {
989 pDevice->byReAssocCount++;
990 if((pDevice->byReAssocCount > 10) && (pDevice->bLinkPass != TRUE)) { //10 sec timeout
991 printk("Re-association timeout!!!\n");
992 pDevice->byReAssocCount = 0;
993 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
994 // if(pDevice->bWPASuppWextEnabled == TRUE)
996 union iwreq_data wrqu;
997 memset(&wrqu, 0, sizeof (wrqu));
998 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
999 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1000 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1004 else if(pDevice->bLinkPass == TRUE)
1005 pDevice->byReAssocCount = 0;
1008 if((pMgmt->eCurrState!=WMAC_STATE_ASSOC) &&
1009 (pMgmt->eLastState==WMAC_STATE_ASSOC))
1011 union iwreq_data wrqu;
1012 memset(&wrqu, 0, sizeof(wrqu));
1013 wrqu.data.flags = RT_DISCONNECTED_EVENT_FLAG;
1014 wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, NULL);
1016 pMgmt->eLastState = pMgmt->eCurrState ;
1018 #ifdef Calcu_LinkQual
1019 s_uCalculateLinkQual((void *)pDevice);
1022 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
1024 if (pMgmt->sNodeDBTable[ii].bActive) {
1025 // Increase in-activity counter
1026 pMgmt->sNodeDBTable[ii].uInActiveCount++;
1029 if (pMgmt->sNodeDBTable[ii].uInActiveCount > MAX_INACTIVE_COUNT) {
1030 BSSvRemoveOneNode(pDevice, ii);
1031 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1032 "Inactive timeout [%d] sec, STA index = [%d] remove\n", MAX_INACTIVE_COUNT, ii);
1036 if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
1038 pDevice->uAssocCount++;
1040 // check if Non ERP exist
1041 if (pMgmt->sNodeDBTable[ii].uInActiveCount < ERP_RECOVER_COUNT) {
1042 if (!pMgmt->sNodeDBTable[ii].bShortPreamble) {
1043 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
1044 uLongPreambleSTACnt ++;
1046 if (!pMgmt->sNodeDBTable[ii].bERPExist) {
1047 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
1048 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1050 if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
1051 uNonShortSlotSTACnt++;
1055 // check if any STA in PS mode
1056 if (pMgmt->sNodeDBTable[ii].bPSEnable)
1062 // Rate fallback check
1063 if (!pDevice->bFixRate) {
1065 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (ii == 0))
1066 RATEvTxRateFallBack(pDevice, &(pMgmt->sNodeDBTable[ii]));
1069 // ii = 0 for multicast node (AP & Adhoc)
1070 RATEvTxRateFallBack((void *)pDevice,
1071 &(pMgmt->sNodeDBTable[ii]));
1074 // ii = 0 reserved for unicast AP node (Infra STA)
1075 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
1076 RATEvTxRateFallBack((void *)pDevice,
1077 &(pMgmt->sNodeDBTable[ii]));
1082 // check if pending PS queue
1083 if (pMgmt->sNodeDBTable[ii].wEnQueueCnt != 0) {
1084 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index= %d, Queue = %d pending \n",
1085 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
1086 if ((ii >0) && (pMgmt->sNodeDBTable[ii].wEnQueueCnt > 15)) {
1087 BSSvRemoveOneNode(pDevice, ii);
1088 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Pending many queues PS STA Index = %d remove \n", ii);
1097 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->byBBType == BB_TYPE_11G)) {
1099 // on/off protect mode
1100 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
1101 if (!pDevice->bProtectMode) {
1102 MACvEnableProtectMD(pDevice);
1103 pDevice->bProtectMode = TRUE;
1107 if (pDevice->bProtectMode) {
1108 MACvDisableProtectMD(pDevice);
1109 pDevice->bProtectMode = FALSE;
1112 // on/off short slot time
1114 if (uNonShortSlotSTACnt > 0) {
1115 if (pDevice->bShortSlotTime) {
1116 pDevice->bShortSlotTime = FALSE;
1117 BBvSetShortSlotTime(pDevice);
1118 vUpdateIFS((void *)pDevice);
1122 if (!pDevice->bShortSlotTime) {
1123 pDevice->bShortSlotTime = TRUE;
1124 BBvSetShortSlotTime(pDevice);
1125 vUpdateIFS((void *)pDevice);
1129 // on/off barker long preamble mode
1131 if (uLongPreambleSTACnt > 0) {
1132 if (!pDevice->bBarkerPreambleMd) {
1133 MACvEnableBarkerPreambleMd(pDevice);
1134 pDevice->bBarkerPreambleMd = TRUE;
1138 if (pDevice->bBarkerPreambleMd) {
1139 MACvDisableBarkerPreambleMd(pDevice);
1140 pDevice->bBarkerPreambleMd = FALSE;
1147 // Check if any STA in PS mode, enable DTIM multicast deliver
1148 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1149 if (uSleepySTACnt > 0)
1150 pMgmt->sNodeDBTable[0].bPSEnable = TRUE;
1152 pMgmt->sNodeDBTable[0].bPSEnable = FALSE;
1155 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
1156 pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
1158 if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
1159 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
1161 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
1162 // DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Callback inactive Count = [%d]\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1164 if (pDevice->bUpdateBBVGA) {
1165 /* s_vCheckSensitivity((void *) pDevice); */
1166 s_vCheckPreEDThreshold((void *) pDevice);
1169 if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
1170 (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0]) ) {
1171 pDevice->byBBVGANew = pDevice->abyBBVGA[0];
1172 bScheduleCommand((void *) pDevice,
1173 WLAN_CMD_CHANGE_BBSENSITIVITY,
1177 if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
1178 pMgmt->sNodeDBTable[0].bActive = FALSE;
1179 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1180 pMgmt->eCurrState = WMAC_STATE_IDLE;
1181 netif_stop_queue(pDevice->dev);
1182 pDevice->bLinkPass = FALSE;
1183 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
1184 pDevice->bRoaming = TRUE;
1185 pDevice->bIsRoaming = FALSE;
1187 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1188 //let wpa supplicant know AP may disconnect.//20080717-01,<Add> by James Li
1189 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1190 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1191 wpahdr->type = VIAWGET_DISASSOC_MSG;
1192 wpahdr->resp_ie_len = 0;
1193 wpahdr->req_ie_len = 0;
1194 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1195 pDevice->skb->dev = pDevice->wpadev;
1196 skb_reset_mac_header(pDevice->skb);
1197 pDevice->skb->pkt_type = PACKET_HOST;
1198 pDevice->skb->protocol = htons(ETH_P_802_2);
1199 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1200 netif_rx(pDevice->skb);
1201 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1203 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1204 // if(pDevice->bWPASuppWextEnabled == TRUE)
1206 union iwreq_data wrqu;
1207 memset(&wrqu, 0, sizeof (wrqu));
1208 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1209 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1210 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1215 else if (pItemSSID->len != 0) {
1217 if ((pDevice->bEnableRoaming == TRUE)&&(!(pMgmt->Cisco_cckm))) {
1218 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bRoaming %d, !\n", pDevice->bRoaming );
1219 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bIsRoaming %d, !\n", pDevice->bIsRoaming );
1220 if ((pDevice->bRoaming == TRUE)&&(pDevice->bIsRoaming == TRUE)){
1221 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fast Roaming ...\n");
1222 BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass);
1223 bScheduleCommand((void *) pDevice,
1224 WLAN_CMD_BSSID_SCAN,
1225 pMgmt->abyDesireSSID);
1226 bScheduleCommand((void *) pDevice,
1228 pMgmt->abyDesireSSID);
1229 pDevice->uAutoReConnectTime = 0;
1230 pDevice->uIsroamingTime = 0;
1231 pDevice->bRoaming = FALSE;
1233 // if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1234 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1235 wpahdr->type = VIAWGET_CCKM_ROAM_MSG;
1236 wpahdr->resp_ie_len = 0;
1237 wpahdr->req_ie_len = 0;
1238 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1239 pDevice->skb->dev = pDevice->wpadev;
1240 skb_reset_mac_header(pDevice->skb);
1241 pDevice->skb->pkt_type = PACKET_HOST;
1242 pDevice->skb->protocol = htons(ETH_P_802_2);
1243 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1244 netif_rx(pDevice->skb);
1245 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1249 else if ((pDevice->bRoaming == FALSE)&&(pDevice->bIsRoaming == TRUE)) {
1250 pDevice->uIsroamingTime++;
1251 if (pDevice->uIsroamingTime >= 20)
1252 pDevice->bIsRoaming = FALSE;
1257 if (pDevice->uAutoReConnectTime < 10) {
1258 pDevice->uAutoReConnectTime++;
1259 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1260 //network manager support need not do Roaming scan???
1261 if(pDevice->bWPASuppWextEnabled ==TRUE)
1262 pDevice->uAutoReConnectTime = 0;
1266 //mike use old encryption status for wpa reauthen
1267 if(pDevice->bWPADEVUp)
1268 pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
1270 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming ...\n");
1271 BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass);
1272 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1273 bScheduleCommand((void *) pDevice,
1274 WLAN_CMD_BSSID_SCAN,
1275 pMgmt->abyDesireSSID);
1276 bScheduleCommand((void *) pDevice,
1278 pMgmt->abyDesireSSID);
1279 pDevice->uAutoReConnectTime = 0;
1285 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1286 // if adhoc started which essid is NULL string, rescaning.
1287 if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
1288 if (pDevice->uAutoReConnectTime < 10) {
1289 pDevice->uAutoReConnectTime++;
1292 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Adhoc re-scaning ...\n");
1293 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1294 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1295 bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
1296 pDevice->uAutoReConnectTime = 0;
1299 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
1301 if (pDevice->bUpdateBBVGA) {
1302 /* s_vCheckSensitivity((void *) pDevice); */
1303 s_vCheckPreEDThreshold((void *) pDevice);
1305 if (pMgmt->sNodeDBTable[0].uInActiveCount >=ADHOC_LOST_BEACON_COUNT) {
1306 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1307 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1308 pMgmt->eCurrState = WMAC_STATE_STARTED;
1309 netif_stop_queue(pDevice->dev);
1310 pDevice->bLinkPass = FALSE;
1311 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
1316 if (pDevice->bLinkPass == TRUE) {
1317 if (netif_queue_stopped(pDevice->dev))
1318 netif_wake_queue(pDevice->dev);
1321 spin_unlock_irq(&pDevice->lock);
1323 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
1324 add_timer(&pMgmt->sTimerSecondCallback);
1330 * Routine Description:
1333 * Update Tx attemps, Tx failure counter in Node DB
1341 void BSSvUpdateNodeTxCounter(void *hDeviceContext,
1342 PSStatCounter pStatistic,
1346 PSDevice pDevice = (PSDevice)hDeviceContext;
1347 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1348 unsigned int uNodeIndex = 0;
1351 WORD wFallBackRate = RATE_1M;
1358 byPktNum = (byPktNO & 0x0F) >> 4;
1359 byTxRetry = (byTSR & 0xF0) >> 4;
1360 wRate = (WORD) (byPktNO & 0xF0) >> 4;
1361 wFIFOCtl = pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl;
1362 pbyDestAddr = (PBYTE) &( pStatistic->abyTxPktInfo[byPktNum].abyDestAddr[0]);
1364 if (wFIFOCtl & FIFOCTL_AUTO_FB_0) {
1365 byFallBack = AUTO_FB_0;
1366 } else if (wFIFOCtl & FIFOCTL_AUTO_FB_1) {
1367 byFallBack = AUTO_FB_1;
1369 byFallBack = AUTO_FB_NONE;
1372 // Only Unicast using support rates
1373 if (wFIFOCtl & FIFOCTL_NEEDACK) {
1374 //DBG_PRN_GRP21(("Device %08X, wRate %04X, byTSR %02X\n", hDeviceContext, wRate, byTSR));
1375 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
1376 pMgmt->sNodeDBTable[0].uTxAttempts += 1;
1377 if ( !(byTSR & (TSR_TMO | TSR_RETRYTMO))) {
1378 // transmit success, TxAttempts at least plus one
1379 pMgmt->sNodeDBTable[0].uTxOk[MAX_RATE]++;
1380 if ( (byFallBack == AUTO_FB_NONE) ||
1381 (wRate < RATE_18M) ) {
1382 wFallBackRate = wRate;
1383 } else if (byFallBack == AUTO_FB_0) {
1385 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1387 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1388 } else if (byFallBack == AUTO_FB_1) {
1390 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1392 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1394 pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
1396 pMgmt->sNodeDBTable[0].uTxFailures ++;
1398 pMgmt->sNodeDBTable[0].uTxRetry += byTxRetry;
1399 if (byTxRetry != 0) {
1400 pMgmt->sNodeDBTable[0].uTxFail[MAX_RATE]+=byTxRetry;
1401 if ( (byFallBack == AUTO_FB_NONE) ||
1402 (wRate < RATE_18M) ) {
1403 pMgmt->sNodeDBTable[0].uTxFail[wRate]+=byTxRetry;
1404 } else if (byFallBack == AUTO_FB_0) {
1405 for (ii = 0; ii < byTxRetry; ii++) {
1408 awHWRetry0[wRate-RATE_18M][ii];
1411 awHWRetry0[wRate-RATE_18M][4];
1412 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1414 } else if (byFallBack == AUTO_FB_1) {
1415 for (ii = 0; ii < byTxRetry; ii++) {
1418 awHWRetry1[wRate-RATE_18M][ii];
1421 awHWRetry1[wRate-RATE_18M][4];
1422 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1428 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
1429 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1431 if (BSSbIsSTAInNodeDB((void *) pDevice,
1434 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
1435 if ( !(byTSR & (TSR_TMO | TSR_RETRYTMO))) {
1436 // transmit success, TxAttempts at least plus one
1437 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
1438 if ( (byFallBack == AUTO_FB_NONE) ||
1439 (wRate < RATE_18M) ) {
1440 wFallBackRate = wRate;
1441 } else if (byFallBack == AUTO_FB_0) {
1443 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1445 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1446 } else if (byFallBack == AUTO_FB_1) {
1448 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1450 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1452 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
1454 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures ++;
1456 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += byTxRetry;
1457 if (byTxRetry != 0) {
1458 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[MAX_RATE]+=byTxRetry;
1459 if ( (byFallBack == AUTO_FB_NONE) ||
1460 (wRate < RATE_18M) ) {
1461 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wRate]+=byTxRetry;
1462 } else if (byFallBack == AUTO_FB_0) {
1463 for (ii = 0; ii < byTxRetry; ii++) {
1466 awHWRetry0[wRate-RATE_18M][ii];
1469 awHWRetry0[wRate-RATE_18M][4];
1470 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1472 } else if (byFallBack == AUTO_FB_1) {
1473 for (ii = 0; ii < byTxRetry; ii++) {
1475 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1477 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1478 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1493 * Routine Description:
1494 * Clear Nodes & skb in DB Table
1499 * hDeviceContext - The adapter context.
1500 * uStartIndex - starting index
1509 void BSSvClearNodeDBTable(void *hDeviceContext,
1510 unsigned int uStartIndex)
1512 PSDevice pDevice = (PSDevice)hDeviceContext;
1513 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1514 struct sk_buff *skb;
1517 for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
1518 if (pMgmt->sNodeDBTable[ii].bActive) {
1519 // check if sTxPSQueue has been initial
1520 if (pMgmt->sNodeDBTable[ii].sTxPSQueue.next != NULL) {
1521 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL){
1522 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS skb != NULL %d\n", ii);
1526 memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
1533 void s_vCheckSensitivity(void *hDeviceContext)
1535 PSDevice pDevice = (PSDevice)hDeviceContext;
1536 PKnownBSS pBSSList = NULL;
1537 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1540 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1541 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1542 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1543 if (pBSSList != NULL) {
1544 /* Update BB register if RSSI is too strong */
1545 signed long LocalldBmAverage = 0;
1546 signed long uNumofdBm = 0;
1547 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
1548 if (pBSSList->ldBmAverage[ii] != 0) {
1550 LocalldBmAverage += pBSSList->ldBmAverage[ii];
1553 if (uNumofdBm > 0) {
1554 LocalldBmAverage = LocalldBmAverage/uNumofdBm;
1555 for (ii=0;ii<BB_VGA_LEVEL;ii++) {
1556 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LocalldBmAverage:%ld, %ld %02x\n", LocalldBmAverage, pDevice->ldBmThreshold[ii], pDevice->abyBBVGA[ii]);
1557 if (LocalldBmAverage < pDevice->ldBmThreshold[ii]) {
1558 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1562 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1563 pDevice->uBBVGADiffCount++;
1564 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
1565 bScheduleCommand((void *) pDevice,
1566 WLAN_CMD_CHANGE_BBSENSITIVITY,
1569 pDevice->uBBVGADiffCount = 0;
1576 #ifdef Calcu_LinkQual
1577 void s_uCalculateLinkQual(void *hDeviceContext)
1579 PSDevice pDevice = (PSDevice)hDeviceContext;
1580 unsigned long TxOkRatio, TxCnt;
1581 unsigned long RxOkRatio, RxCnt;
1582 unsigned long RssiRatio;
1585 TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
1586 pDevice->scStatistic.TxRetryOkCount +
1587 pDevice->scStatistic.TxFailCount;
1588 RxCnt = pDevice->scStatistic.RxFcsErrCnt +
1589 pDevice->scStatistic.RxOkCnt;
1590 TxOkRatio = (TxCnt < 6) ? 4000:((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
1591 RxOkRatio = (RxCnt < 6) ? 2000:((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
1592 //decide link quality
1593 if(pDevice->bLinkPass !=TRUE)
1595 // printk("s_uCalculateLinkQual-->Link disconnect and Poor quality**\n");
1596 pDevice->scStatistic.LinkQuality = 0;
1597 pDevice->scStatistic.SignalStren = 0;
1601 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
1605 else if(-ldBm > 90) {
1609 RssiRatio = (40-(-ldBm-50))*4000/40;
1611 pDevice->scStatistic.SignalStren = RssiRatio/40;
1612 pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
1614 pDevice->scStatistic.RxFcsErrCnt = 0;
1615 pDevice->scStatistic.RxOkCnt = 0;
1616 pDevice->scStatistic.TxFailCount = 0;
1617 pDevice->scStatistic.TxNoRetryOkCount = 0;
1618 pDevice->scStatistic.TxRetryOkCount = 0;
1623 void BSSvClearAnyBSSJoinRecord(void *hDeviceContext)
1625 PSDevice pDevice = (PSDevice)hDeviceContext;
1626 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1629 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
1630 pMgmt->sBSSList[ii].bSelected = FALSE;
1635 void s_vCheckPreEDThreshold(void *hDeviceContext)
1637 PSDevice pDevice = (PSDevice)hDeviceContext;
1638 PKnownBSS pBSSList = NULL;
1639 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1641 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1642 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1643 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1644 if (pBSSList != NULL) {
1645 pDevice->byBBPreEDRSSI = (BYTE) (~(pBSSList->ldBmAverRange) + 1);
1646 BBvUpdatePreEDThreshold(pDevice, FALSE);