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 u16 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 u16 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 static void s_vCheckSensitivity(struct vnt_private *pDevice);
95 static void s_vCheckPreEDThreshold(struct vnt_private *pDevice);
96 static void s_uCalculateLinkQual(struct vnt_private *pDevice);
98 /*--------------------- Export Variables --------------------------*/
101 /*--------------------- Export Functions --------------------------*/
109 * Routine Description:
110 * Search known BSS list for Desire SSID or BSSID.
113 * PTR to KnownBSS or NULL
117 PKnownBSS BSSpSearchBSSList(struct vnt_private *pDevice,
118 u8 *pbyDesireBSSID, u8 *pbyDesireSSID,
119 CARD_PHY_TYPE ePhyType)
121 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
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};
130 if (pbyDesireBSSID != NULL) {
131 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
132 "BSSpSearchBSSList BSSID[%pM]\n", pbyDesireBSSID);
133 if ((!is_broadcast_ether_addr(pbyDesireBSSID)) &&
134 (memcmp(pbyDesireBSSID, ZeroBSSID, 6)!= 0)){
135 pbyBSSID = pbyDesireBSSID;
138 if (pbyDesireSSID != NULL) {
139 if (((PWLAN_IE_SSID)pbyDesireSSID)->len != 0) {
140 pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
144 if ((pbyBSSID != NULL)&&(pDevice->bRoaming == false)) {
146 for (ii = 0; ii <MAX_BSS_NUM; ii++) {
147 pCurrBSS = &(pMgmt->sBSSList[ii]);
149 pCurrBSS->bSelected = false;
151 if ((pCurrBSS->bActive) &&
152 (pCurrBSS->bSelected == false)) {
153 if (!compare_ether_addr(pCurrBSS->abyBSSID, pbyBSSID)) {
156 if ( !memcmp(pSSID->abySSID,
157 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
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))
163 pCurrBSS->bSelected = true;
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))
172 pCurrBSS->bSelected = true;
181 for (ii = 0; ii <MAX_BSS_NUM; ii++) {
182 pCurrBSS = &(pMgmt->sBSSList[ii]);
184 //2007-0721-01<Mark>by MikeLiu
185 // if ((pCurrBSS->bActive) &&
186 // (pCurrBSS->bSelected == false)) {
188 pCurrBSS->bSelected = false;
189 if (pCurrBSS->bActive) {
193 if (memcmp(pSSID->abySSID,
194 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
196 (pSSID->len != ((PWLAN_IE_SSID)pCurrBSS->abySSID)->len)) {
197 // SSID not match skip this BSS
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))
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);
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);
218 pMgmt->pSameBSS[jj].uChannel = pCurrBSS->uChannel;
219 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
220 "BSSpSearchBSSList pSelect1[%pM]\n",
225 if (pSelect == NULL) {
228 // compare RSSI, select the strongest signal
229 if (pCurrBSS->uRSSI < pSelect->uRSSI) {
236 pDevice->bSameBSSMaxNum = jj;
238 if (pSelect != NULL) {
239 pSelect->bSelected = true;
240 if (pDevice->bRoaming == false) {
241 // Einsn Add @20070907
242 memcpy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1) ;
255 * Routine Description:
264 void BSSvClearBSSList(struct vnt_private *pDevice, int bKeepCurrBSSID)
266 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
269 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
270 if (bKeepCurrBSSID) {
271 if (pMgmt->sBSSList[ii].bActive &&
272 !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID,
273 pMgmt->abyCurrBSSID)) {
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!!
277 // bKeepCurrBSSID = false;
282 pMgmt->sBSSList[ii].bActive = false;
283 memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS));
285 BSSvClearAnyBSSJoinRecord(pDevice);
292 * Routine Description:
293 * search BSS list by BSSID & SSID if matched
299 PKnownBSS BSSpAddrIsInBSSList(struct vnt_private *pDevice,
300 u8 *abyBSSID, PWLAN_IE_SSID pSSID)
302 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
303 PKnownBSS pBSSList = NULL;
306 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
307 pBSSList = &(pMgmt->sBSSList[ii]);
308 if (pBSSList->bActive) {
309 if (!compare_ether_addr(pBSSList->abyBSSID, abyBSSID)) {
310 if (pSSID->len == ((PWLAN_IE_SSID)pBSSList->abySSID)->len){
311 if (memcmp(pSSID->abySSID,
312 ((PWLAN_IE_SSID)pBSSList->abySSID)->abySSID,
327 * Routine Description:
328 * Insert a BSS set into known BSS list
335 int BSSbInsertToBSSList(struct vnt_private *pDevice,
342 PWLAN_IE_SUPP_RATES pSuppRates,
343 PWLAN_IE_SUPP_RATES pExtSuppRates,
346 PWLAN_IE_RSN_EXT pRSNWPA,
347 PWLAN_IE_COUNTRY pIE_Country,
348 PWLAN_IE_QUIET pIE_Quiet,
351 void *pRxPacketContext)
353 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
354 struct vnt_rx_mgmt *pRxPacket =
355 (struct vnt_rx_mgmt *)pRxPacketContext;
356 PKnownBSS pBSSList = NULL;
358 bool bParsingQuiet = false;
361 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
363 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
364 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[ii]);
365 if (!pBSSList->bActive)
369 if (ii == MAX_BSS_NUM){
370 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n");
374 pBSSList->bActive = true;
375 memcpy( pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
376 pBSSList->qwBSSTimestamp = cpu_to_le64(qwTimestamp);
377 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
378 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
379 pBSSList->uClearCount = 0;
381 if (pSSID->len > WLAN_SSID_MAXLEN)
382 pSSID->len = WLAN_SSID_MAXLEN;
383 memcpy( pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
385 pBSSList->uChannel = byCurrChannel;
387 if (pSuppRates->len > WLAN_RATES_MAXLEN)
388 pSuppRates->len = WLAN_RATES_MAXLEN;
389 memcpy( pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
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);
398 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
400 pBSSList->sERP.byERP = psERP->byERP;
401 pBSSList->sERP.bERPExist = psERP->bERPExist;
403 // Check if BSS is 802.11a/b/g
404 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
405 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
407 if (pBSSList->sERP.bERPExist == true) {
408 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
410 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
414 pBSSList->byRxRate = pRxPacket->byRxRate;
415 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
416 pBSSList->uRSSI = pRxPacket->uRSSI;
417 pBSSList->bySQ = pRxPacket->bySQ;
419 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
420 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
422 if (pBSSList == pMgmt->pCurrBSS) {
423 bParsingQuiet = true;
427 WPA_ClearRSN(pBSSList);
429 if (pRSNWPA != NULL) {
430 unsigned int uLen = pRSNWPA->len + 2;
432 if (uLen <= (uIELength -
433 (unsigned int) (u32) ((u8 *) pRSNWPA - pbyIEs))) {
434 pBSSList->wWPALen = uLen;
435 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
436 WPA_ParseRSN(pBSSList, pRSNWPA);
440 WPA2_ClearRSN(pBSSList);
443 unsigned int uLen = pRSN->len + 2;
445 if (uLen <= (uIELength -
446 (unsigned int) (u32) ((u8 *) pRSN - pbyIEs))) {
447 pBSSList->wRSNLen = uLen;
448 memcpy(pBSSList->byRSNIE, pRSN, uLen);
449 WPA2vParseRSN(pBSSList, pRSN);
453 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == true)) {
455 PSKeyItem pTransmitKey = NULL;
456 bool bIs802_1x = false;
458 for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii ++) {
459 if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
464 if ((bIs802_1x == true) && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
465 ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
467 bAdd_PMKID_Candidate((void *) pDevice,
469 &pBSSList->sRSNCapObj);
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)) {
474 pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
475 pDevice->gsPMKIDCandidate.Version = 1;
483 if (pDevice->bUpdateBBVGA) {
484 // Monitor if RSSI is too strong.
485 pBSSList->byRSSIStatCnt = 0;
486 RFvRSSITodBm(pDevice, (u8)(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;
493 pBSSList->uIELength = uIELength;
494 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
495 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
496 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
504 * Routine Description:
505 * Update BSS set in known BSS list
511 // TODO: input structure modify
513 int BSSbUpdateToBSSList(struct vnt_private *pDevice,
520 PWLAN_IE_SUPP_RATES pSuppRates,
521 PWLAN_IE_SUPP_RATES pExtSuppRates,
524 PWLAN_IE_RSN_EXT pRSNWPA,
525 PWLAN_IE_COUNTRY pIE_Country,
526 PWLAN_IE_QUIET pIE_Quiet,
530 void *pRxPacketContext)
532 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
533 struct vnt_rx_mgmt *pRxPacket =
534 (struct vnt_rx_mgmt *)pRxPacketContext;
536 signed long ldBm, ldBmSum;
537 bool bParsingQuiet = false;
539 if (pBSSList == NULL)
543 pBSSList->qwBSSTimestamp = cpu_to_le64(qwTimestamp);
545 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
546 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
547 pBSSList->uClearCount = 0;
548 pBSSList->uChannel = byCurrChannel;
550 if (pSSID->len > WLAN_SSID_MAXLEN)
551 pSSID->len = WLAN_SSID_MAXLEN;
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);
557 if (pExtSuppRates != NULL) {
558 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates,pExtSuppRates->len + WLAN_IEHDR_LEN);
560 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
562 pBSSList->sERP.byERP = psERP->byERP;
563 pBSSList->sERP.bERPExist = psERP->bERPExist;
565 // Check if BSS is 802.11a/b/g
566 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
567 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
569 if (pBSSList->sERP.bERPExist == true) {
570 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
572 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
576 pBSSList->byRxRate = pRxPacket->byRxRate;
577 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
579 pBSSList->uRSSI = pRxPacket->uRSSI;
580 pBSSList->bySQ = pRxPacket->bySQ;
582 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
583 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
585 if (pBSSList == pMgmt->pCurrBSS) {
586 bParsingQuiet = true;
590 WPA_ClearRSN(pBSSList); //mike update
592 if (pRSNWPA != NULL) {
593 unsigned int uLen = pRSNWPA->len + 2;
594 if (uLen <= (uIELength -
595 (unsigned int) (u32) ((u8 *) pRSNWPA - pbyIEs))) {
596 pBSSList->wWPALen = uLen;
597 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
598 WPA_ParseRSN(pBSSList, pRSNWPA);
602 WPA2_ClearRSN(pBSSList); //mike update
605 unsigned int uLen = pRSN->len + 2;
606 if (uLen <= (uIELength -
607 (unsigned int) (u32) ((u8 *) pRSN - pbyIEs))) {
608 pBSSList->wRSNLen = uLen;
609 memcpy(pBSSList->byRSNIE, pRSN, uLen);
610 WPA2vParseRSN(pBSSList, pRSN);
614 if (pRxPacket->uRSSI != 0) {
615 RFvRSSITodBm(pDevice, (u8)(pRxPacket->uRSSI), &ldBm);
616 // Monitor if RSSI is too strong.
617 pBSSList->byRSSIStatCnt++;
618 pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
619 pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
621 for (ii = 0, jj = 0; ii < RSSI_STAT_COUNT; ii++) {
622 if (pBSSList->ldBmAverage[ii] != 0) {
624 max(pBSSList->ldBmAverage[ii], ldBm);
626 pBSSList->ldBmAverage[ii];
630 pBSSList->ldBmAverRange = ldBmSum /jj;
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);
647 * Routine Description:
648 * Search Node DB table to find the index of matched DstAddr
655 int BSSbIsSTAInNodeDB(struct vnt_private *pDevice,
656 u8 *abyDstAddr, u32 *puNodeIndex)
658 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
661 // Index = 0 reserved for AP Node
662 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
663 if (pMgmt->sNodeDBTable[ii].bActive) {
664 if (!compare_ether_addr(abyDstAddr,
665 pMgmt->sNodeDBTable[ii].abyMACAddr)) {
679 * Routine Description:
680 * Find an empty node and allocate it; if no empty node
681 * is found, then use the most inactive one.
687 void BSSvCreateOneNode(struct vnt_private *pDevice, u32 *puNodeIndex)
689 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
695 // Index = 0 reserved for AP Node (In STA mode)
696 // Index = 0 reserved for Broadcast/MultiCast (In AP mode)
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;
710 // if not found replace uInActiveCount with the largest one.
711 if ( ii == (MAX_NODE_NUM + 1)) {
712 *puNodeIndex = SelectIndex;
713 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Replace inactive node = %d\n", SelectIndex);
715 if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
716 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
724 memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
725 pMgmt->sNodeDBTable[*puNodeIndex].bActive = true;
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);
738 * Routine Description:
739 * Remove Node by NodeIndex
747 void BSSvRemoveOneNode(struct vnt_private *pDevice, u32 uNodeIndex)
749 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
750 u8 byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
754 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
757 memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
759 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &= ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
763 * Routine Description:
764 * Update AP Node content in Index 0 of KnownNodeDB
772 void BSSvUpdateAPNode(struct vnt_private *pDevice, u16 *pwCapInfo,
773 PWLAN_IE_SUPP_RATES pSuppRates, PWLAN_IE_SUPP_RATES pExtSuppRates)
775 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
776 u32 uRateLen = WLAN_RATES_MAXLEN;
778 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
780 pMgmt->sNodeDBTable[0].bActive = true;
781 if (pDevice->byBBType == BB_TYPE_11B) {
782 uRateLen = WLAN_RATES_MAXLEN_11B;
784 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
785 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
787 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
788 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
790 RATEvParseMaxRate((void *) pDevice,
791 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
792 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
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)
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);
812 * Routine Description:
813 * Add Multicast Node content in Index 0 of KnownNodeDB
821 void BSSvAddMulticastNode(struct vnt_private *pDevice)
823 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
825 if (!pDevice->bEnableHostWEP)
826 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
827 memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
828 pMgmt->sNodeDBTable[0].bActive = true;
829 pMgmt->sNodeDBTable[0].bPSEnable = false;
830 skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
831 RATEvParseMaxRate((void *) pDevice,
832 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
833 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
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)
841 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
842 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
848 * Routine Description:
851 * Second call back function to update Node DB info & AP link status
859 void BSSvSecondCallBack(struct vnt_private *pDevice)
861 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
863 PWLAN_IE_SSID pItemSSID, pCurrSSID;
864 u32 uSleepySTACnt = 0;
865 u32 uNonShortSlotSTACnt = 0;
866 u32 uLongPreambleSTACnt = 0;
868 spin_lock_irq(&pDevice->lock);
870 pDevice->uAssocCount = 0;
872 //Power Saving Mode Tx Burst
873 if ( pDevice->bEnablePSMode == true ) {
874 pDevice->ulPSModeWaitTx++;
875 if ( pDevice->ulPSModeWaitTx >= 2 ) {
876 pDevice->ulPSModeWaitTx = 0;
877 pDevice->bPSModeTxBurst = false;
881 pDevice->byERPFlag &=
882 ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
884 if (pDevice->wUseProtectCntDown > 0) {
885 pDevice->wUseProtectCntDown --;
888 // disable protect mode
889 pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
892 if(pDevice->byReAssocCount > 0) {
893 pDevice->byReAssocCount++;
894 if((pDevice->byReAssocCount > 10) && (pDevice->bLinkPass != true)) { //10 sec timeout
895 printk("Re-association timeout!!!\n");
896 pDevice->byReAssocCount = 0;
897 // if(pDevice->bWPASuppWextEnabled == true)
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);
906 else if(pDevice->bLinkPass == true)
907 pDevice->byReAssocCount = 0;
910 pMgmt->eLastState = pMgmt->eCurrState ;
912 s_uCalculateLinkQual(pDevice);
914 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
916 if (pMgmt->sNodeDBTable[ii].bActive) {
917 // Increase in-activity counter
918 pMgmt->sNodeDBTable[ii].uInActiveCount++;
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);
928 if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
930 pDevice->uAssocCount++;
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 ++;
938 if (!pMgmt->sNodeDBTable[ii].bERPExist) {
939 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
940 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
942 if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
943 uNonShortSlotSTACnt++;
947 // check if any STA in PS mode
948 if (pMgmt->sNodeDBTable[ii].bPSEnable)
954 // Rate fallback check
955 if (!pDevice->bFixRate) {
957 // ii = 0 for multicast node (AP & Adhoc)
958 RATEvTxRateFallBack((void *)pDevice,
959 &(pMgmt->sNodeDBTable[ii]));
962 // ii = 0 reserved for unicast AP node (Infra STA)
963 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
964 RATEvTxRateFallBack((void *)pDevice,
965 &(pMgmt->sNodeDBTable[ii]));
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);
985 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->byBBType == BB_TYPE_11G)) {
987 // on/off protect mode
988 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
989 if (!pDevice->bProtectMode) {
990 MACvEnableProtectMD(pDevice);
991 pDevice->bProtectMode = true;
995 if (pDevice->bProtectMode) {
996 MACvDisableProtectMD(pDevice);
997 pDevice->bProtectMode = false;
1000 // on/off short slot time
1002 if (uNonShortSlotSTACnt > 0) {
1003 if (pDevice->bShortSlotTime) {
1004 pDevice->bShortSlotTime = false;
1005 BBvSetShortSlotTime(pDevice);
1006 vUpdateIFS((void *)pDevice);
1010 if (!pDevice->bShortSlotTime) {
1011 pDevice->bShortSlotTime = true;
1012 BBvSetShortSlotTime(pDevice);
1013 vUpdateIFS((void *)pDevice);
1017 // on/off barker long preamble mode
1019 if (uLongPreambleSTACnt > 0) {
1020 if (!pDevice->bBarkerPreambleMd) {
1021 MACvEnableBarkerPreambleMd(pDevice);
1022 pDevice->bBarkerPreambleMd = true;
1026 if (pDevice->bBarkerPreambleMd) {
1027 MACvDisableBarkerPreambleMd(pDevice);
1028 pDevice->bBarkerPreambleMd = false;
1035 // Check if any STA in PS mode, enable DTIM multicast deliver
1036 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1037 if (uSleepySTACnt > 0)
1038 pMgmt->sNodeDBTable[0].bPSEnable = true;
1040 pMgmt->sNodeDBTable[0].bPSEnable = false;
1043 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
1044 pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
1046 if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
1047 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
1049 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
1051 if (pDevice->bUpdateBBVGA) {
1052 s_vCheckSensitivity(pDevice);
1053 s_vCheckPreEDThreshold(pDevice);
1056 if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
1057 (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0]) ) {
1058 pDevice->byBBVGANew = pDevice->abyBBVGA[0];
1059 bScheduleCommand((void *) pDevice,
1060 WLAN_CMD_CHANGE_BBSENSITIVITY,
1064 if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
1065 pMgmt->sNodeDBTable[0].bActive = false;
1066 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1067 pMgmt->eCurrState = WMAC_STATE_IDLE;
1068 netif_stop_queue(pDevice->dev);
1069 pDevice->bLinkPass = false;
1070 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
1071 pDevice->bRoaming = true;
1072 pDevice->bIsRoaming = false;
1074 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1075 /* let wpa supplicant know AP may disconnect */
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);
1085 else if (pItemSSID->len != 0) {
1087 if ((pDevice->bEnableRoaming == true)&&(!(pMgmt->Cisco_cckm))) {
1088 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bRoaming %d, !\n", pDevice->bRoaming );
1089 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bIsRoaming %d, !\n", pDevice->bIsRoaming );
1090 if ((pDevice->bRoaming == true)&&(pDevice->bIsRoaming == true)){
1091 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fast Roaming ...\n");
1092 BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass);
1093 bScheduleCommand((void *) pDevice,
1094 WLAN_CMD_BSSID_SCAN,
1095 pMgmt->abyDesireSSID);
1096 bScheduleCommand((void *) pDevice,
1098 pMgmt->abyDesireSSID);
1099 pDevice->uAutoReConnectTime = 0;
1100 pDevice->uIsroamingTime = 0;
1101 pDevice->bRoaming = false;
1103 else if ((pDevice->bRoaming == false)&&(pDevice->bIsRoaming == true)) {
1104 pDevice->uIsroamingTime++;
1105 if (pDevice->uIsroamingTime >= 20)
1106 pDevice->bIsRoaming = false;
1111 if (pDevice->uAutoReConnectTime < 10) {
1112 pDevice->uAutoReConnectTime++;
1113 //network manager support need not do Roaming scan???
1114 if(pDevice->bWPASuppWextEnabled ==true)
1115 pDevice->uAutoReConnectTime = 0;
1118 //mike use old encryption status for wpa reauthen
1119 if(pDevice->bWPADEVUp)
1120 pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
1122 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming ...\n");
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,
1130 pMgmt->abyDesireSSID);
1131 pDevice->uAutoReConnectTime = 0;
1137 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1138 // if adhoc started which essid is NULL string, rescanning.
1139 if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
1140 if (pDevice->uAutoReConnectTime < 10) {
1141 pDevice->uAutoReConnectTime++;
1144 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Adhoc re-scanning ...\n");
1145 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1146 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1147 bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
1148 pDevice->uAutoReConnectTime = 0;
1151 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
1153 if (pDevice->bUpdateBBVGA) {
1154 s_vCheckSensitivity(pDevice);
1155 s_vCheckPreEDThreshold(pDevice);
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);
1162 pDevice->bLinkPass = false;
1163 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
1168 if (pDevice->bLinkPass == true) {
1169 if (netif_queue_stopped(pDevice->dev))
1170 netif_wake_queue(pDevice->dev);
1173 spin_unlock_irq(&pDevice->lock);
1175 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
1176 add_timer(&pMgmt->sTimerSecondCallback);
1181 * Routine Description:
1184 * Update Tx attemps, Tx failure counter in Node DB
1192 void BSSvUpdateNodeTxCounter(struct vnt_private *pDevice,
1193 PSStatCounter pStatistic, u8 byTSR, u8 byPktNO)
1195 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1199 u16 wFallBackRate = RATE_1M;
1206 byPktNum = (byPktNO & 0x0F) >> 4;
1207 byTxRetry = (byTSR & 0xF0) >> 4;
1208 wRate = (u16) (byPktNO & 0xF0) >> 4;
1209 wFIFOCtl = pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl;
1210 pbyDestAddr = (u8 *) &( pStatistic->abyTxPktInfo[byPktNum].abyDestAddr[0]);
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;
1217 byFallBack = AUTO_FB_NONE;
1220 // Only Unicast using support rates
1221 if (wFIFOCtl & FIFOCTL_NEEDACK) {
1222 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
1223 pMgmt->sNodeDBTable[0].uTxAttempts += 1;
1224 if ( !(byTSR & (TSR_TMO | TSR_RETRYTMO))) {
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) {
1232 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1234 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1235 } else if (byFallBack == AUTO_FB_1) {
1237 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1239 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1241 pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
1243 pMgmt->sNodeDBTable[0].uTxFailures ++;
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) {
1252 for (ii = 0; ii < byTxRetry; ii++) {
1255 awHWRetry0[wRate-RATE_18M][ii];
1258 awHWRetry0[wRate-RATE_18M][4];
1259 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1261 } else if (byFallBack == AUTO_FB_1) {
1262 for (ii = 0; ii < byTxRetry; ii++) {
1265 awHWRetry1[wRate-RATE_18M][ii];
1268 awHWRetry1[wRate-RATE_18M][4];
1269 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1275 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
1276 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1278 if (BSSbIsSTAInNodeDB((void *) pDevice,
1281 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
1282 if ( !(byTSR & (TSR_TMO | TSR_RETRYTMO))) {
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) {
1290 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1292 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1293 } else if (byFallBack == AUTO_FB_1) {
1295 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1297 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1299 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
1301 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures ++;
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) {
1310 for (ii = 0; ii < byTxRetry; ii++) {
1313 awHWRetry0[wRate-RATE_18M][ii];
1316 awHWRetry0[wRate-RATE_18M][4];
1317 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1319 } else if (byFallBack == AUTO_FB_1) {
1320 for (ii = 0; ii < byTxRetry; ii++) {
1322 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1324 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1325 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1336 * Routine Description:
1337 * Clear Nodes & skb in DB Table
1342 * hDeviceContext - The adapter context.
1343 * uStartIndex - starting index
1352 void BSSvClearNodeDBTable(struct vnt_private *pDevice, u32 uStartIndex)
1354 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1355 struct sk_buff *skb;
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);
1367 memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
1372 static void s_vCheckSensitivity(struct vnt_private *pDevice)
1374 PKnownBSS pBSSList = NULL;
1375 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
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) {
1382 /* Update BB register if RSSI is too strong */
1383 signed long LocalldBmAverage = 0;
1384 signed long uNumofdBm = 0;
1385 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
1386 if (pBSSList->ldBmAverage[ii] != 0) {
1388 LocalldBmAverage += pBSSList->ldBmAverage[ii];
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];
1400 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1401 pDevice->uBBVGADiffCount++;
1402 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
1403 bScheduleCommand(pDevice,
1404 WLAN_CMD_CHANGE_BBSENSITIVITY,
1407 pDevice->uBBVGADiffCount = 0;
1414 static void s_uCalculateLinkQual(struct vnt_private *pDevice)
1416 unsigned long TxOkRatio, TxCnt;
1417 unsigned long RxOkRatio, RxCnt;
1418 unsigned long RssiRatio;
1421 TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
1422 pDevice->scStatistic.TxRetryOkCount +
1423 pDevice->scStatistic.TxFailCount;
1424 RxCnt = pDevice->scStatistic.RxFcsErrCnt +
1425 pDevice->scStatistic.RxOkCnt;
1426 TxOkRatio = (TxCnt < 6) ? 4000:((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
1427 RxOkRatio = (RxCnt < 6) ? 2000:((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
1428 //decide link quality
1429 if(pDevice->bLinkPass !=true)
1431 pDevice->scStatistic.LinkQuality = 0;
1432 pDevice->scStatistic.SignalStren = 0;
1436 RFvRSSITodBm(pDevice, (u8)(pDevice->uCurrRSSI), &ldBm);
1440 else if(-ldBm > 90) {
1444 RssiRatio = (40-(-ldBm-50))*4000/40;
1446 pDevice->scStatistic.SignalStren = RssiRatio/40;
1447 pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
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;
1456 void BSSvClearAnyBSSJoinRecord(struct vnt_private *pDevice)
1458 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
1461 for (ii = 0; ii < MAX_BSS_NUM; ii++)
1462 pMgmt->sBSSList[ii].bSelected = false;
1467 static void s_vCheckPreEDThreshold(struct vnt_private *pDevice)
1469 PKnownBSS pBSSList = NULL;
1470 struct vnt_manager *pMgmt = &pDevice->vnt_mgmt;
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 = (u8) (~(pBSSList->ldBmAverRange) + 1);
1477 BBvUpdatePreEDThreshold(pDevice, false);