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 * BSSDBbIsSTAInNodeDB - 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
61 /*--------------------- Static Definitions -------------------------*/
63 /*--------------------- Static Classes ----------------------------*/
65 /*--------------------- Static Variables --------------------------*/
66 static int msglevel = MSG_LEVEL_INFO;
68 static const unsigned short awHWRetry0[5][5] = {
69 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
70 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
71 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
72 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
73 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
75 static const unsigned short awHWRetry1[5][5] = {
76 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
77 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
78 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
79 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
80 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
83 /*--------------------- Static Functions --------------------------*/
85 void s_vCheckSensitivity(
90 void s_uCalculateLinkQual(
95 void s_vCheckPreEDThreshold(
98 /*--------------------- Export Variables --------------------------*/
100 /*--------------------- Export Functions --------------------------*/
104 * Routine Description:
105 * Search known BSS list for Desire SSID or BSSID.
108 * PTR to KnownBSS or NULL
114 void *hDeviceContext,
115 unsigned char *pbyDesireBSSID,
116 unsigned char *pbyDesireSSID,
117 CARD_PHY_TYPE ePhyType
120 PSDevice pDevice = (PSDevice)hDeviceContext;
121 PSMgmtObject pMgmt = pDevice->pMgmt;
122 unsigned char *pbyBSSID = NULL;
123 PWLAN_IE_SSID pSSID = NULL;
124 PKnownBSS pCurrBSS = NULL;
125 PKnownBSS pSelect = NULL;
126 unsigned char ZeroBSSID[WLAN_BSSID_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
129 if (pbyDesireBSSID != NULL) {
130 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
131 "BSSpSearchBSSList BSSID[%pM]\n", pbyDesireBSSID);
132 if ((!is_broadcast_ether_addr(pbyDesireBSSID)) &&
133 (memcmp(pbyDesireBSSID, ZeroBSSID, 6) != 0))
134 pbyBSSID = pbyDesireBSSID;
136 if (pbyDesireSSID != NULL) {
137 if (((PWLAN_IE_SSID)pbyDesireSSID)->len != 0)
138 pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
141 if (pbyBSSID != NULL) {
142 /* match BSSID first */
143 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
144 pCurrBSS = &(pMgmt->sBSSList[ii]);
145 if (!pDevice->bLinkPass)
146 pCurrBSS->bSelected = false;
147 if ((pCurrBSS->bActive) &&
148 (!pCurrBSS->bSelected)) {
149 if (ether_addr_equal(pCurrBSS->abyBSSID,
153 if (!memcmp(pSSID->abySSID,
154 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
156 if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
157 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
158 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
160 pCurrBSS->bSelected = true;
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;
178 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
179 pCurrBSS = &(pMgmt->sBSSList[ii]);
180 /* 2007-0721-01<Add>by MikeLiu */
181 pCurrBSS->bSelected = false;
182 if (pCurrBSS->bActive) {
185 if (!!memcmp(pSSID->abySSID,
186 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
188 (pSSID->len != ((PWLAN_IE_SSID)pCurrBSS->abySSID)->len)) {
189 /* SSID not match skip this BSS */
193 if (((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) ||
194 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo))
196 /* Type not match skip this BSS */
197 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSS type mismatch.... Config[%d] BSS[0x%04x]\n", pMgmt->eConfigMode, pCurrBSS->wCapInfo);
201 if (ePhyType != PHY_TYPE_AUTO) {
202 if (((ePhyType == PHY_TYPE_11A) && (PHY_TYPE_11A != pCurrBSS->eNetworkTypeInUse)) ||
203 ((ePhyType != PHY_TYPE_11A) && (PHY_TYPE_11A == pCurrBSS->eNetworkTypeInUse))) {
204 /* PhyType not match skip this BSS */
205 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Physical type mismatch.... ePhyType[%d] BSS[%d]\n", ePhyType, pCurrBSS->eNetworkTypeInUse);
210 if (pSelect == NULL) {
213 /* compare RSSI, select signal strong one */
214 if (pCurrBSS->uRSSI < pSelect->uRSSI)
219 if (pSelect != NULL) {
220 pSelect->bSelected = true;
229 * Routine Description:
239 void *hDeviceContext,
243 PSDevice pDevice = (PSDevice)hDeviceContext;
244 PSMgmtObject pMgmt = pDevice->pMgmt;
247 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
248 if (bKeepCurrBSSID) {
249 if (pMgmt->sBSSList[ii].bActive &&
250 ether_addr_equal(pMgmt->sBSSList[ii].abyBSSID,
251 pMgmt->abyCurrBSSID)) {
256 if ((pMgmt->sBSSList[ii].bActive) && (pMgmt->sBSSList[ii].uClearCount < BSS_CLEAR_COUNT)) {
257 pMgmt->sBSSList[ii].uClearCount++;
261 pMgmt->sBSSList[ii].bActive = false;
262 memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS));
264 BSSvClearAnyBSSJoinRecord(pDevice);
269 * Routine Description:
270 * search BSS list by BSSID & SSID if matched
278 void *hDeviceContext,
279 unsigned char *abyBSSID,
283 PSDevice pDevice = (PSDevice)hDeviceContext;
284 PSMgmtObject pMgmt = pDevice->pMgmt;
285 PKnownBSS pBSSList = NULL;
288 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
289 pBSSList = &(pMgmt->sBSSList[ii]);
290 if (pBSSList->bActive) {
291 if (ether_addr_equal(pBSSList->abyBSSID, abyBSSID)) {
292 if (pSSID->len == ((PWLAN_IE_SSID)pBSSList->abySSID)->len) {
293 if (memcmp(pSSID->abySSID,
294 ((PWLAN_IE_SSID)pBSSList->abySSID)->abySSID,
307 * Routine Description:
308 * Insert a BSS set into known BSS list
317 void *hDeviceContext,
318 unsigned char *abyBSSIDAddr,
320 unsigned short wBeaconInterval,
321 unsigned short wCapInfo,
322 unsigned char byCurrChannel,
324 PWLAN_IE_SUPP_RATES pSuppRates,
325 PWLAN_IE_SUPP_RATES pExtSuppRates,
328 PWLAN_IE_RSN_EXT pRSNWPA,
329 PWLAN_IE_COUNTRY pIE_Country,
330 PWLAN_IE_QUIET pIE_Quiet,
331 unsigned int uIELength,
332 unsigned char *pbyIEs,
333 void *pRxPacketContext
336 PSDevice pDevice = (PSDevice)hDeviceContext;
337 PSMgmtObject pMgmt = pDevice->pMgmt;
338 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
339 PKnownBSS pBSSList = NULL;
341 bool bParsingQuiet = false;
342 PWLAN_IE_QUIET pQuiet = NULL;
344 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
346 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
347 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[ii]);
348 if (!pBSSList->bActive)
352 if (ii == MAX_BSS_NUM) {
353 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n");
356 /* save the BSS info */
357 pBSSList->bActive = true;
358 memcpy(pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
359 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
360 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
361 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
362 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
363 pBSSList->uClearCount = 0;
365 if (pSSID->len > WLAN_SSID_MAXLEN)
366 pSSID->len = WLAN_SSID_MAXLEN;
367 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
369 pBSSList->uChannel = byCurrChannel;
371 if (pSuppRates->len > WLAN_RATES_MAXLEN)
372 pSuppRates->len = WLAN_RATES_MAXLEN;
373 memcpy(pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
375 if (pExtSuppRates != NULL) {
376 if (pExtSuppRates->len > WLAN_RATES_MAXLEN)
377 pExtSuppRates->len = WLAN_RATES_MAXLEN;
378 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
379 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSbInsertToBSSList: pExtSuppRates->len = %d\n", pExtSuppRates->len);
382 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
384 pBSSList->sERP.byERP = psERP->byERP;
385 pBSSList->sERP.bERPExist = psERP->bERPExist;
387 /* check if BSS is 802.11a/b/g */
388 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
389 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
391 if (pBSSList->sERP.bERPExist)
392 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
394 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
397 pBSSList->byRxRate = pRxPacket->byRxRate;
398 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
399 pBSSList->uRSSI = pRxPacket->uRSSI;
400 pBSSList->bySQ = pRxPacket->bySQ;
402 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
403 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
405 if (pBSSList == pMgmt->pCurrBSS)
406 bParsingQuiet = true;
409 WPA_ClearRSN(pBSSList);
411 if (pRSNWPA != NULL) {
412 unsigned int uLen = pRSNWPA->len + 2;
414 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
415 pBSSList->wWPALen = uLen;
416 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
417 WPA_ParseRSN(pBSSList, pRSNWPA);
421 WPA2_ClearRSN(pBSSList);
424 unsigned int uLen = pRSN->len + 2;
426 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
427 pBSSList->wRSNLen = uLen;
428 memcpy(pBSSList->byRSNIE, pRSN, uLen);
429 WPA2vParseRSN(pBSSList, pRSN);
433 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || pBSSList->bWPA2Valid) {
434 PSKeyItem pTransmitKey = NULL;
435 bool bIs802_1x = false;
437 for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii++) {
438 if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
443 if (bIs802_1x && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
444 (!memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
445 bAdd_PMKID_Candidate((void *)pDevice, pBSSList->abyBSSID, &pBSSList->sRSNCapObj);
447 if (pDevice->bLinkPass && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
448 if (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) ||
449 KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey)) {
450 pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
451 pDevice->gsPMKIDCandidate.Version = 1;
459 if (pDevice->bUpdateBBVGA) {
460 /* monitor if RSSI is too strong */
461 pBSSList->byRSSIStatCnt = 0;
462 RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
463 pBSSList->ldBmAverage[0] = pBSSList->ldBmMAX;
464 for (ii = 1; ii < RSSI_STAT_COUNT; ii++)
465 pBSSList->ldBmAverage[ii] = 0;
468 if ((pIE_Country != NULL) && pMgmt->b11hEnable) {
469 set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
473 if (bParsingQuiet && (pIE_Quiet != NULL)) {
474 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
475 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
477 if (pQuiet == NULL) {
478 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
479 CARDbSetQuiet(pMgmt->pAdapter,
481 pQuiet->byQuietCount,
482 pQuiet->byQuietPeriod,
483 *((unsigned short *)pQuiet->abyQuietDuration),
484 *((unsigned short *)pQuiet->abyQuietOffset)
487 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
488 CARDbSetQuiet(pMgmt->pAdapter,
490 pQuiet->byQuietCount,
491 pQuiet->byQuietPeriod,
492 *((unsigned short *)pQuiet->abyQuietDuration),
493 *((unsigned short *)pQuiet->abyQuietOffset)
499 if (bParsingQuiet && (pQuiet != NULL))
500 CARDbStartQuiet(pMgmt->pAdapter);
502 pBSSList->uIELength = uIELength;
503 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
504 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
505 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
512 * Routine Description:
513 * Update BSS set in known BSS list
519 /* TODO: input structure modify */
523 void *hDeviceContext,
525 unsigned short wBeaconInterval,
526 unsigned short wCapInfo,
527 unsigned char byCurrChannel,
530 PWLAN_IE_SUPP_RATES pSuppRates,
531 PWLAN_IE_SUPP_RATES pExtSuppRates,
534 PWLAN_IE_RSN_EXT pRSNWPA,
535 PWLAN_IE_COUNTRY pIE_Country,
536 PWLAN_IE_QUIET pIE_Quiet,
538 unsigned int uIELength,
539 unsigned char *pbyIEs,
540 void *pRxPacketContext
544 PSDevice pDevice = (PSDevice)hDeviceContext;
545 PSMgmtObject pMgmt = pDevice->pMgmt;
546 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
548 bool bParsingQuiet = false;
549 PWLAN_IE_QUIET pQuiet = NULL;
551 if (pBSSList == NULL)
554 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
555 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
556 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
557 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
558 pBSSList->uClearCount = 0;
559 pBSSList->uChannel = byCurrChannel;
561 if (pSSID->len > WLAN_SSID_MAXLEN)
562 pSSID->len = WLAN_SSID_MAXLEN;
564 if ((pSSID->len != 0) && (pSSID->abySSID[0] != 0))
565 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
566 memcpy(pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
568 if (pExtSuppRates != NULL)
569 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
571 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
572 pBSSList->sERP.byERP = psERP->byERP;
573 pBSSList->sERP.bERPExist = psERP->bERPExist;
575 /* check if BSS is 802.11a/b/g */
576 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
577 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
579 if (pBSSList->sERP.bERPExist)
580 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
582 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
585 pBSSList->byRxRate = pRxPacket->byRxRate;
586 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
588 pBSSList->uRSSI = pRxPacket->uRSSI;
589 pBSSList->bySQ = pRxPacket->bySQ;
591 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
592 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
594 if (pBSSList == pMgmt->pCurrBSS)
595 bParsingQuiet = true;
598 WPA_ClearRSN(pBSSList); /* mike update */
600 if (pRSNWPA != NULL) {
601 unsigned int uLen = pRSNWPA->len + 2;
603 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
604 pBSSList->wWPALen = uLen;
605 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
606 WPA_ParseRSN(pBSSList, pRSNWPA);
610 WPA2_ClearRSN(pBSSList); /* mike update */
613 unsigned int uLen = pRSN->len + 2;
615 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
616 pBSSList->wRSNLen = uLen;
617 memcpy(pBSSList->byRSNIE, pRSN, uLen);
618 WPA2vParseRSN(pBSSList, pRSN);
622 if (pRxPacket->uRSSI != 0) {
623 RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &ldBm);
624 /* monitor if RSSI is too strong */
625 pBSSList->byRSSIStatCnt++;
626 pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
627 pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
628 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
629 if (pBSSList->ldBmAverage[ii] != 0)
630 pBSSList->ldBmMAX = max(pBSSList->ldBmAverage[ii], ldBm);
634 if ((pIE_Country != NULL) && pMgmt->b11hEnable) {
635 set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
639 if (bParsingQuiet && (pIE_Quiet != NULL)) {
640 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
641 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
643 if (pQuiet == NULL) {
644 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
645 CARDbSetQuiet(pMgmt->pAdapter,
647 pQuiet->byQuietCount,
648 pQuiet->byQuietPeriod,
649 *((unsigned short *)pQuiet->abyQuietDuration),
650 *((unsigned short *)pQuiet->abyQuietOffset)
653 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
654 CARDbSetQuiet(pMgmt->pAdapter,
656 pQuiet->byQuietCount,
657 pQuiet->byQuietPeriod,
658 *((unsigned short *)pQuiet->abyQuietDuration),
659 *((unsigned short *)pQuiet->abyQuietOffset)
665 if (bParsingQuiet && (pQuiet != NULL))
666 CARDbStartQuiet(pMgmt->pAdapter);
668 pBSSList->uIELength = uIELength;
669 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
670 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
671 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
678 * Routine Description:
679 * Search Node DB table to find the index of matched DstAddr
687 BSSDBbIsSTAInNodeDB(void *pMgmtObject, unsigned char *abyDstAddr,
688 unsigned int *puNodeIndex)
690 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
693 /* Index = 0 reserved for AP Node */
694 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
695 if (pMgmt->sNodeDBTable[ii].bActive) {
696 if (ether_addr_equal(abyDstAddr,
697 pMgmt->sNodeDBTable[ii].abyMACAddr)) {
709 * Routine Description:
710 * Find an empty node and allocat it; if there is no empty node,
711 * then use the most inactive one.
718 BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex)
720 PSDevice pDevice = (PSDevice)hDeviceContext;
721 PSMgmtObject pMgmt = pDevice->pMgmt;
723 unsigned int BigestCount = 0;
724 unsigned int SelectIndex;
727 * Index = 0 reserved for AP Node (In STA mode)
728 * Index = 0 reserved for Broadcast/MultiCast (In AP mode)
731 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
732 if (pMgmt->sNodeDBTable[ii].bActive) {
733 if (pMgmt->sNodeDBTable[ii].uInActiveCount > BigestCount) {
734 BigestCount = pMgmt->sNodeDBTable[ii].uInActiveCount;
742 /* if not found replace uInActiveCount is largest one */
743 if (ii == (MAX_NODE_NUM + 1)) {
744 *puNodeIndex = SelectIndex;
745 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Replace inactive node = %d\n", SelectIndex);
746 /* clear ps buffer */
747 if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
748 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
755 memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
756 pMgmt->sNodeDBTable[*puNodeIndex].bActive = true;
757 pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
758 /* for AP mode PS queue */
759 skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
760 pMgmt->sNodeDBTable[*puNodeIndex].byAuthSequence = 0;
761 pMgmt->sNodeDBTable[*puNodeIndex].wEnQueueCnt = 0;
762 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create node index = %d\n", ii);
768 * Routine Description:
769 * Remove Node by NodeIndex
778 void *hDeviceContext,
779 unsigned int uNodeIndex
782 PSDevice pDevice = (PSDevice)hDeviceContext;
783 PSMgmtObject pMgmt = pDevice->pMgmt;
784 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
787 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
790 memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
791 /* clear tx bit map */
792 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &= ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
798 * Routine Description:
799 * Update AP Node content in Index 0 of KnownNodeDB
809 void *hDeviceContext,
810 unsigned short *pwCapInfo,
811 PWLAN_IE_SUPP_RATES pSuppRates,
812 PWLAN_IE_SUPP_RATES pExtSuppRates
815 PSDevice pDevice = (PSDevice)hDeviceContext;
816 PSMgmtObject pMgmt = pDevice->pMgmt;
817 unsigned int uRateLen = WLAN_RATES_MAXLEN;
819 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
821 pMgmt->sNodeDBTable[0].bActive = true;
822 if (pDevice->eCurrentPHYType == PHY_TYPE_11B)
823 uRateLen = WLAN_RATES_MAXLEN_11B;
824 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
825 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
827 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
828 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
830 RATEvParseMaxRate((void *)pDevice,
831 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
832 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
834 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
835 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
836 &(pMgmt->sNodeDBTable[0].wSuppRate),
837 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
838 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
840 memcpy(pMgmt->sNodeDBTable[0].abyMACAddr, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
841 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxSuppRate;
842 pMgmt->sNodeDBTable[0].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo);
843 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
844 netdev_dbg(pDevice->dev, "BSSvUpdateAPNode:MaxSuppRate is %d\n",
845 pMgmt->sNodeDBTable[0].wMaxSuppRate);
846 /* auto rate fallback function initiation */
847 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->sNodeDBTable[0].wTxDataRate = %d\n", pMgmt->sNodeDBTable[0].wTxDataRate);
852 * Routine Description:
853 * Add Multicast Node content in Index 0 of KnownNodeDB
862 BSSvAddMulticastNode(
866 PSDevice pDevice = (PSDevice)hDeviceContext;
867 PSMgmtObject pMgmt = pDevice->pMgmt;
869 if (!pDevice->bEnableHostWEP)
870 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
871 memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
872 pMgmt->sNodeDBTable[0].bActive = true;
873 pMgmt->sNodeDBTable[0].bPSEnable = false;
874 skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
875 RATEvParseMaxRate((void *)pDevice,
876 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
877 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
879 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
880 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
881 &(pMgmt->sNodeDBTable[0].wSuppRate),
882 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
883 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
885 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
886 netdev_dbg(pDevice->dev,
887 "BSSvAddMultiCastNode:pMgmt->sNodeDBTable[0].wTxDataRate is %d\n",
888 pMgmt->sNodeDBTable[0].wTxDataRate);
889 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
894 * Routine Description:
897 * Second call back function to update Node DB info & AP link status
909 PSDevice pDevice = (PSDevice)hDeviceContext;
910 PSMgmtObject pMgmt = pDevice->pMgmt;
912 PWLAN_IE_SSID pItemSSID, pCurrSSID;
913 unsigned int uSleepySTACnt = 0;
914 unsigned int uNonShortSlotSTACnt = 0;
915 unsigned int uLongPreambleSTACnt = 0;
916 viawget_wpa_header *wpahdr; /* DavidWang */
918 spin_lock_irq(&pDevice->lock);
920 pDevice->uAssocCount = 0;
922 pDevice->byERPFlag &=
923 ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
925 if (pDevice->wUseProtectCntDown > 0) {
926 pDevice->wUseProtectCntDown--;
928 /* disable protect mode */
929 pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
932 if (pDevice->eCommandState == WLAN_ASSOCIATE_WAIT) {
933 pDevice->byReAssocCount++;
935 if ((pDevice->byReAssocCount > 10) && (!pDevice->bLinkPass)) {
936 netdev_info(pDevice->dev, "Re-association timeout!!!\n");
937 pDevice->byReAssocCount = 0;
938 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
940 union iwreq_data wrqu;
942 memset(&wrqu, 0, sizeof(wrqu));
943 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
944 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
945 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
948 } else if (pDevice->bLinkPass)
949 pDevice->byReAssocCount = 0;
952 #ifdef Calcu_LinkQual
953 s_uCalculateLinkQual((void *)pDevice);
956 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
957 if (pMgmt->sNodeDBTable[ii].bActive) {
958 /* increase in-activity counter */
959 pMgmt->sNodeDBTable[ii].uInActiveCount++;
962 if (pMgmt->sNodeDBTable[ii].uInActiveCount > MAX_INACTIVE_COUNT) {
963 BSSvRemoveOneNode(pDevice, ii);
964 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
965 "Inactive timeout [%d] sec, STA index = [%d] remove\n", MAX_INACTIVE_COUNT, ii);
969 if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
970 pDevice->uAssocCount++;
972 /* check if Non ERP exist */
973 if (pMgmt->sNodeDBTable[ii].uInActiveCount < ERP_RECOVER_COUNT) {
974 if (!pMgmt->sNodeDBTable[ii].bShortPreamble) {
975 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
976 uLongPreambleSTACnt++;
978 if (!pMgmt->sNodeDBTable[ii].bERPExist) {
979 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
980 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
982 if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
983 uNonShortSlotSTACnt++;
987 /* check if any STA in PS mode */
988 if (pMgmt->sNodeDBTable[ii].bPSEnable)
993 /* rate fallback check */
994 if (!pDevice->bFixRate) {
996 /* ii = 0 for multicast node (AP & Adhoc) */
997 RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
999 /* ii = 0 reserved for unicast AP node (Infra STA) */
1000 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
1001 netdev_dbg(pDevice->dev,
1002 "SecondCallback:Before:TxDataRate is %d\n",
1003 pMgmt->sNodeDBTable[0].wTxDataRate);
1004 RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
1005 netdev_dbg(pDevice->dev,
1006 "SecondCallback:After:TxDataRate is %d\n",
1007 pMgmt->sNodeDBTable[0].wTxDataRate);
1013 /* check if pending PS queue */
1014 if (pMgmt->sNodeDBTable[ii].wEnQueueCnt != 0) {
1015 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index= %d, Queue = %d pending\n",
1016 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
1017 if ((ii > 0) && (pMgmt->sNodeDBTable[ii].wEnQueueCnt > 15)) {
1018 BSSvRemoveOneNode(pDevice, ii);
1019 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Pending many queues PS STA Index = %d remove\n", ii);
1027 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->eCurrentPHYType == PHY_TYPE_11G)) {
1028 /* on/off protect mode */
1029 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
1030 if (!pDevice->bProtectMode) {
1031 MACvEnableProtectMD(pDevice->PortOffset);
1032 pDevice->bProtectMode = true;
1035 if (pDevice->bProtectMode) {
1036 MACvDisableProtectMD(pDevice->PortOffset);
1037 pDevice->bProtectMode = false;
1040 /* on/off short slot time */
1042 if (uNonShortSlotSTACnt > 0) {
1043 if (pDevice->bShortSlotTime) {
1044 pDevice->bShortSlotTime = false;
1045 BBvSetShortSlotTime(pDevice);
1046 vUpdateIFS((void *)pDevice);
1049 if (!pDevice->bShortSlotTime) {
1050 pDevice->bShortSlotTime = true;
1051 BBvSetShortSlotTime(pDevice);
1052 vUpdateIFS((void *)pDevice);
1056 /* on/off barker long preamble mode */
1058 if (uLongPreambleSTACnt > 0) {
1059 if (!pDevice->bBarkerPreambleMd) {
1060 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
1061 pDevice->bBarkerPreambleMd = true;
1064 if (pDevice->bBarkerPreambleMd) {
1065 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
1066 pDevice->bBarkerPreambleMd = false;
1072 /* check if any STA in PS mode, enable DTIM multicast deliver */
1073 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1074 if (uSleepySTACnt > 0)
1075 pMgmt->sNodeDBTable[0].bPSEnable = true;
1077 pMgmt->sNodeDBTable[0].bPSEnable = false;
1080 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
1081 pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
1083 if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
1084 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
1085 /* assoc with BSS */
1086 if (pMgmt->sNodeDBTable[0].bActive) {
1087 if (pDevice->bUpdateBBVGA)
1088 s_vCheckPreEDThreshold((void *)pDevice);
1090 if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
1091 (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0])) {
1092 pDevice->byBBVGANew = pDevice->abyBBVGA[0];
1093 bScheduleCommand((void *)pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1096 if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
1097 pMgmt->sNodeDBTable[0].bActive = false;
1098 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1099 pMgmt->eCurrState = WMAC_STATE_IDLE;
1100 netif_stop_queue(pDevice->dev);
1101 pDevice->bLinkPass = false;
1102 pDevice->bRoaming = true;
1103 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1104 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1105 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1106 wpahdr->type = VIAWGET_DISASSOC_MSG;
1107 wpahdr->resp_ie_len = 0;
1108 wpahdr->req_ie_len = 0;
1109 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1110 pDevice->skb->dev = pDevice->wpadev;
1111 skb_reset_mac_header(pDevice->skb);
1112 pDevice->skb->pkt_type = PACKET_HOST;
1113 pDevice->skb->protocol = htons(ETH_P_802_2);
1114 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1115 netif_rx(pDevice->skb);
1116 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1118 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1120 union iwreq_data wrqu;
1122 memset(&wrqu, 0, sizeof(wrqu));
1123 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1124 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1125 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1129 } else if (pItemSSID->len != 0) {
1130 if (pDevice->uAutoReConnectTime < 10) {
1131 pDevice->uAutoReConnectTime++;
1132 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1134 * network manager support need not do
1137 if (pDevice->bWPASuppWextEnabled)
1138 pDevice->uAutoReConnectTime = 0;
1142 * mike use old encryption status
1143 * for wpa reauthentication
1145 if (pDevice->bWPADEVUp)
1146 pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
1148 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming ...\n");
1149 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
1150 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1151 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
1152 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
1153 pDevice->uAutoReConnectTime = 0;
1158 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1159 /* if adhoc started which essid is NULL string, rescanning */
1160 if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
1161 if (pDevice->uAutoReConnectTime < 10) {
1162 pDevice->uAutoReConnectTime++;
1164 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Adhoc re-scanning ...\n");
1165 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1166 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1167 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
1168 pDevice->uAutoReConnectTime = 0;
1171 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
1172 if (pDevice->bUpdateBBVGA)
1173 s_vCheckPreEDThreshold((void *)pDevice);
1174 if (pMgmt->sNodeDBTable[0].uInActiveCount >= ADHOC_LOST_BEACON_COUNT) {
1175 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1176 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1177 pMgmt->eCurrState = WMAC_STATE_STARTED;
1178 netif_stop_queue(pDevice->dev);
1179 pDevice->bLinkPass = false;
1184 spin_unlock_irq(&pDevice->lock);
1186 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
1187 add_timer(&pMgmt->sTimerSecondCallback);
1192 * Routine Description:
1195 * Update Tx attemps, Tx failure counter in Node DB
1204 BSSvUpdateNodeTxCounter(
1205 void *hDeviceContext,
1206 unsigned char byTsr0,
1207 unsigned char byTsr1,
1208 unsigned char *pbyBuffer,
1209 unsigned int uFIFOHeaderSize
1212 PSDevice pDevice = (PSDevice)hDeviceContext;
1213 PSMgmtObject pMgmt = pDevice->pMgmt;
1214 unsigned int uNodeIndex = 0;
1215 unsigned char byTxRetry = (byTsr0 & TSR0_NCR);
1216 PSTxBufHead pTxBufHead;
1217 PS802_11Header pMACHeader;
1218 unsigned short wRate;
1219 unsigned short wFallBackRate = RATE_1M;
1220 unsigned char byFallBack;
1223 pTxBufHead = (PSTxBufHead) pbyBuffer;
1224 if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_0)
1225 byFallBack = AUTO_FB_0;
1226 else if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_1)
1227 byFallBack = AUTO_FB_1;
1229 byFallBack = AUTO_FB_NONE;
1230 wRate = pTxBufHead->wReserved;
1232 /* Only Unicast using support rates */
1233 if (pTxBufHead->wFIFOCtl & FIFOCTL_NEEDACK) {
1234 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wRate %04X, byTsr0 %02X, byTsr1 %02X\n", wRate, byTsr0, byTsr1);
1235 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
1236 pMgmt->sNodeDBTable[0].uTxAttempts += 1;
1237 if ((byTsr1 & TSR1_TERR) == 0) {
1238 /* transmit success, TxAttempts at least plus one */
1239 pMgmt->sNodeDBTable[0].uTxOk[MAX_RATE]++;
1240 if ((byFallBack == AUTO_FB_NONE) ||
1241 (wRate < RATE_18M)) {
1242 wFallBackRate = wRate;
1243 } else if (byFallBack == AUTO_FB_0) {
1245 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1247 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1248 } else if (byFallBack == AUTO_FB_1) {
1250 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1252 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1254 pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
1256 pMgmt->sNodeDBTable[0].uTxFailures++;
1258 pMgmt->sNodeDBTable[0].uTxRetry += byTxRetry;
1259 if (byTxRetry != 0) {
1260 pMgmt->sNodeDBTable[0].uTxFail[MAX_RATE] += byTxRetry;
1261 if ((byFallBack == AUTO_FB_NONE) ||
1262 (wRate < RATE_18M)) {
1263 pMgmt->sNodeDBTable[0].uTxFail[wRate] += byTxRetry;
1264 } else if (byFallBack == AUTO_FB_0) {
1265 for (ii = 0; ii < byTxRetry; ii++) {
1267 wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
1269 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1270 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1272 } else if (byFallBack == AUTO_FB_1) {
1273 for (ii = 0; ii < byTxRetry; ii++) {
1275 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1277 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1278 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1284 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
1285 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1286 pMACHeader = (PS802_11Header)(pbyBuffer + uFIFOHeaderSize);
1288 if (BSSDBbIsSTAInNodeDB((void *)pMgmt, &(pMACHeader->abyAddr1[0]), &uNodeIndex)) {
1289 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
1290 if ((byTsr1 & TSR1_TERR) == 0) {
1291 /* transmit success, TxAttempts at least plus one */
1292 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
1293 if ((byFallBack == AUTO_FB_NONE) ||
1294 (wRate < RATE_18M)) {
1295 wFallBackRate = wRate;
1296 } else if (byFallBack == AUTO_FB_0) {
1298 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1300 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1301 } else if (byFallBack == AUTO_FB_1) {
1303 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1305 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1307 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
1309 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures++;
1311 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += byTxRetry;
1312 if (byTxRetry != 0) {
1313 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[MAX_RATE] += byTxRetry;
1314 if ((byFallBack == AUTO_FB_NONE) ||
1315 (wRate < RATE_18M)) {
1316 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wRate] += byTxRetry;
1317 } else if (byFallBack == AUTO_FB_0) {
1318 for (ii = 0; ii < byTxRetry; ii++) {
1320 wFallBackRate = awHWRetry0[wRate - RATE_18M][ii];
1322 wFallBackRate = awHWRetry0[wRate - RATE_18M][4];
1323 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1325 } else if (byFallBack == AUTO_FB_1) {
1326 for (ii = 0; ii < byTxRetry; ii++) {
1328 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1330 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1331 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1342 * Routine Description:
1343 * Clear Nodes & skb in DB Table
1348 * hDeviceContext - The adapter context.
1349 * uStartIndex - starting index
1359 BSSvClearNodeDBTable(
1360 void *hDeviceContext,
1361 unsigned int uStartIndex
1365 PSDevice pDevice = (PSDevice)hDeviceContext;
1366 PSMgmtObject pMgmt = pDevice->pMgmt;
1367 struct sk_buff *skb;
1370 for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
1371 if (pMgmt->sNodeDBTable[ii].bActive) {
1372 /* check if sTxPSQueue has been initial */
1373 if (pMgmt->sNodeDBTable[ii].sTxPSQueue.next != NULL) {
1374 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
1375 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS skb != NULL %d\n", ii);
1379 memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
1386 void s_vCheckSensitivity(
1387 void *hDeviceContext
1390 PSDevice pDevice = (PSDevice)hDeviceContext;
1391 PKnownBSS pBSSList = NULL;
1392 PSMgmtObject pMgmt = pDevice->pMgmt;
1395 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) && (pDevice->byRFType == RF_RFMD2959) &&
1396 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
1400 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1401 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1402 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1403 if (pBSSList != NULL) {
1404 /* Update BB Reg if RSSI is too strong */
1405 long LocalldBmAverage = 0;
1408 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
1409 if (pBSSList->ldBmAverage[ii] != 0) {
1411 LocalldBmAverage += pBSSList->ldBmAverage[ii];
1414 if (uNumofdBm > 0) {
1415 LocalldBmAverage = LocalldBmAverage/uNumofdBm;
1416 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
1417 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "LocalldBmAverage:%ld, %ld %02x\n", LocalldBmAverage, pDevice->ldBmThreshold[ii], pDevice->abyBBVGA[ii]);
1418 if (LocalldBmAverage < pDevice->ldBmThreshold[ii]) {
1419 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1423 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1424 pDevice->uBBVGADiffCount++;
1425 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
1426 bScheduleCommand((void *)pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1428 pDevice->uBBVGADiffCount = 0;
1436 BSSvClearAnyBSSJoinRecord(
1437 void *hDeviceContext
1440 PSDevice pDevice = (PSDevice)hDeviceContext;
1441 PSMgmtObject pMgmt = pDevice->pMgmt;
1444 for (ii = 0; ii < MAX_BSS_NUM; ii++)
1445 pMgmt->sBSSList[ii].bSelected = false;
1448 #ifdef Calcu_LinkQual
1449 void s_uCalculateLinkQual(
1450 void *hDeviceContext
1453 PSDevice pDevice = (PSDevice)hDeviceContext;
1454 unsigned long TxOkRatio, TxCnt;
1455 unsigned long RxOkRatio, RxCnt;
1456 unsigned long RssiRatio;
1459 TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
1460 pDevice->scStatistic.TxRetryOkCount +
1461 pDevice->scStatistic.TxFailCount;
1462 RxCnt = pDevice->scStatistic.RxFcsErrCnt +
1463 pDevice->scStatistic.RxOkCnt;
1464 TxOkRatio = (TxCnt < 6) ? 4000 : ((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
1465 RxOkRatio = (RxCnt < 6) ? 2000 : ((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
1466 /* decide link quality */
1467 if (!pDevice->bLinkPass) {
1468 pDevice->scStatistic.LinkQuality = 0;
1469 pDevice->scStatistic.SignalStren = 0;
1471 RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
1474 else if (-ldBm > 90)
1477 RssiRatio = (40-(-ldBm-50))*4000/40;
1478 pDevice->scStatistic.SignalStren = RssiRatio/40;
1479 pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
1481 pDevice->scStatistic.RxFcsErrCnt = 0;
1482 pDevice->scStatistic.RxOkCnt = 0;
1483 pDevice->scStatistic.TxFailCount = 0;
1484 pDevice->scStatistic.TxNoRetryOkCount = 0;
1485 pDevice->scStatistic.TxRetryOkCount = 0;
1489 void s_vCheckPreEDThreshold(
1490 void *hDeviceContext
1493 PSDevice pDevice = (PSDevice)hDeviceContext;
1494 PKnownBSS pBSSList = NULL;
1495 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1497 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1498 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1499 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1500 if (pBSSList != NULL)
1501 pDevice->byBBPreEDRSSI = (unsigned char) (~(pBSSList->ldBmAverRange) + 1);