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 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 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 == false)
146 pCurrBSS->bSelected = false;
147 if ((pCurrBSS->bActive) &&
148 (pCurrBSS->bSelected == false)) {
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);
271 * Routine Description:
272 * search BSS list by BSSID & SSID if matched
280 void *hDeviceContext,
281 unsigned char *abyBSSID,
285 PSDevice pDevice = (PSDevice)hDeviceContext;
286 PSMgmtObject pMgmt = pDevice->pMgmt;
287 PKnownBSS pBSSList = NULL;
290 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
291 pBSSList = &(pMgmt->sBSSList[ii]);
292 if (pBSSList->bActive) {
293 if (ether_addr_equal(pBSSList->abyBSSID, abyBSSID)) {
294 if (pSSID->len == ((PWLAN_IE_SSID)pBSSList->abySSID)->len) {
295 if (memcmp(pSSID->abySSID,
296 ((PWLAN_IE_SSID)pBSSList->abySSID)->abySSID,
309 * Routine Description:
310 * Insert a BSS set into known BSS list
319 void *hDeviceContext,
320 unsigned char *abyBSSIDAddr,
322 unsigned short wBeaconInterval,
323 unsigned short wCapInfo,
324 unsigned char byCurrChannel,
326 PWLAN_IE_SUPP_RATES pSuppRates,
327 PWLAN_IE_SUPP_RATES pExtSuppRates,
330 PWLAN_IE_RSN_EXT pRSNWPA,
331 PWLAN_IE_COUNTRY pIE_Country,
332 PWLAN_IE_QUIET pIE_Quiet,
333 unsigned int uIELength,
334 unsigned char *pbyIEs,
335 void *pRxPacketContext
338 PSDevice pDevice = (PSDevice)hDeviceContext;
339 PSMgmtObject pMgmt = pDevice->pMgmt;
340 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
341 PKnownBSS pBSSList = NULL;
343 bool bParsingQuiet = false;
344 PWLAN_IE_QUIET pQuiet = NULL;
346 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
348 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
349 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[ii]);
350 if (!pBSSList->bActive)
354 if (ii == MAX_BSS_NUM) {
355 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n");
358 /* save the BSS info */
359 pBSSList->bActive = true;
360 memcpy(pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
361 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
362 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
363 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
364 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
365 pBSSList->uClearCount = 0;
367 if (pSSID->len > WLAN_SSID_MAXLEN)
368 pSSID->len = WLAN_SSID_MAXLEN;
369 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
371 pBSSList->uChannel = byCurrChannel;
373 if (pSuppRates->len > WLAN_RATES_MAXLEN)
374 pSuppRates->len = WLAN_RATES_MAXLEN;
375 memcpy(pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
377 if (pExtSuppRates != NULL) {
378 if (pExtSuppRates->len > WLAN_RATES_MAXLEN)
379 pExtSuppRates->len = WLAN_RATES_MAXLEN;
380 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
381 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "BSSbInsertToBSSList: pExtSuppRates->len = %d\n", pExtSuppRates->len);
384 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
386 pBSSList->sERP.byERP = psERP->byERP;
387 pBSSList->sERP.bERPExist = psERP->bERPExist;
389 /* check if BSS is 802.11a/b/g */
390 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
391 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
393 if (pBSSList->sERP.bERPExist == true)
394 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
396 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
399 pBSSList->byRxRate = pRxPacket->byRxRate;
400 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
401 pBSSList->uRSSI = pRxPacket->uRSSI;
402 pBSSList->bySQ = pRxPacket->bySQ;
404 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
405 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
407 if (pBSSList == pMgmt->pCurrBSS)
408 bParsingQuiet = true;
411 WPA_ClearRSN(pBSSList);
413 if (pRSNWPA != NULL) {
414 unsigned int uLen = pRSNWPA->len + 2;
416 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
417 pBSSList->wWPALen = uLen;
418 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
419 WPA_ParseRSN(pBSSList, pRSNWPA);
423 WPA2_ClearRSN(pBSSList);
426 unsigned int uLen = pRSN->len + 2;
427 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
428 pBSSList->wRSNLen = uLen;
429 memcpy(pBSSList->byRSNIE, pRSN, uLen);
430 WPA2vParseRSN(pBSSList, pRSN);
434 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == true)) {
435 PSKeyItem pTransmitKey = NULL;
436 bool bIs802_1x = false;
438 for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii++) {
439 if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
444 if ((bIs802_1x == true) && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
445 (!memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
446 bAdd_PMKID_Candidate((void *)pDevice, pBSSList->abyBSSID, &pBSSList->sRSNCapObj);
448 if ((pDevice->bLinkPass == true) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
449 if ((KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) == true) ||
450 (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey) == true)) {
451 pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
452 pDevice->gsPMKIDCandidate.Version = 1;
460 if (pDevice->bUpdateBBVGA) {
461 /* monitor if RSSI is too strong */
462 pBSSList->byRSSIStatCnt = 0;
463 RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
464 pBSSList->ldBmAverage[0] = pBSSList->ldBmMAX;
465 for (ii = 1; ii < RSSI_STAT_COUNT; ii++)
466 pBSSList->ldBmAverage[ii] = 0;
469 if ((pIE_Country != NULL) &&
470 (pMgmt->b11hEnable == true)) {
471 set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
475 if ((bParsingQuiet == true) && (pIE_Quiet != NULL)) {
476 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
477 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
479 if (pQuiet == NULL) {
480 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
481 CARDbSetQuiet(pMgmt->pAdapter,
483 pQuiet->byQuietCount,
484 pQuiet->byQuietPeriod,
485 *((unsigned short *)pQuiet->abyQuietDuration),
486 *((unsigned short *)pQuiet->abyQuietOffset)
489 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
490 CARDbSetQuiet(pMgmt->pAdapter,
492 pQuiet->byQuietCount,
493 pQuiet->byQuietPeriod,
494 *((unsigned short *)pQuiet->abyQuietDuration),
495 *((unsigned short *)pQuiet->abyQuietOffset)
501 if ((bParsingQuiet == true) &&
503 CARDbStartQuiet(pMgmt->pAdapter);
506 pBSSList->uIELength = uIELength;
507 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
508 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
509 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
516 * Routine Description:
517 * Update BSS set in known BSS list
523 /* TODO: input structure modify */
527 void *hDeviceContext,
529 unsigned short wBeaconInterval,
530 unsigned short wCapInfo,
531 unsigned char byCurrChannel,
534 PWLAN_IE_SUPP_RATES pSuppRates,
535 PWLAN_IE_SUPP_RATES pExtSuppRates,
538 PWLAN_IE_RSN_EXT pRSNWPA,
539 PWLAN_IE_COUNTRY pIE_Country,
540 PWLAN_IE_QUIET pIE_Quiet,
542 unsigned int uIELength,
543 unsigned char *pbyIEs,
544 void *pRxPacketContext
548 PSDevice pDevice = (PSDevice)hDeviceContext;
549 PSMgmtObject pMgmt = pDevice->pMgmt;
550 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
552 bool bParsingQuiet = false;
553 PWLAN_IE_QUIET pQuiet = NULL;
555 if (pBSSList == NULL)
558 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
559 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
560 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
561 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
562 pBSSList->uClearCount = 0;
563 pBSSList->uChannel = byCurrChannel;
565 if (pSSID->len > WLAN_SSID_MAXLEN)
566 pSSID->len = WLAN_SSID_MAXLEN;
568 if ((pSSID->len != 0) && (pSSID->abySSID[0] != 0))
569 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
570 memcpy(pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
572 if (pExtSuppRates != NULL)
573 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
575 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
576 pBSSList->sERP.byERP = psERP->byERP;
577 pBSSList->sERP.bERPExist = psERP->bERPExist;
579 /* check if BSS is 802.11a/b/g */
580 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
581 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
583 if (pBSSList->sERP.bERPExist == true)
584 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
586 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
589 pBSSList->byRxRate = pRxPacket->byRxRate;
590 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
592 pBSSList->uRSSI = pRxPacket->uRSSI;
593 pBSSList->bySQ = pRxPacket->bySQ;
595 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
596 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
598 if (pBSSList == pMgmt->pCurrBSS)
599 bParsingQuiet = true;
602 WPA_ClearRSN(pBSSList); /* mike update */
604 if (pRSNWPA != NULL) {
605 unsigned int uLen = pRSNWPA->len + 2;
606 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
607 pBSSList->wWPALen = uLen;
608 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
609 WPA_ParseRSN(pBSSList, pRSNWPA);
613 WPA2_ClearRSN(pBSSList); /* mike update */
616 unsigned int uLen = pRSN->len + 2;
617 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
618 pBSSList->wRSNLen = uLen;
619 memcpy(pBSSList->byRSNIE, pRSN, uLen);
620 WPA2vParseRSN(pBSSList, pRSN);
624 if (pRxPacket->uRSSI != 0) {
625 RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &ldBm);
626 /* monitor if RSSI is too strong */
627 pBSSList->byRSSIStatCnt++;
628 pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
629 pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
630 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
631 if (pBSSList->ldBmAverage[ii] != 0)
632 pBSSList->ldBmMAX = max(pBSSList->ldBmAverage[ii], ldBm);
636 if ((pIE_Country != NULL) &&
637 (pMgmt->b11hEnable == true)) {
638 set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
642 if ((bParsingQuiet == true) && (pIE_Quiet != NULL)) {
643 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
644 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
646 if (pQuiet == NULL) {
647 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
648 CARDbSetQuiet(pMgmt->pAdapter,
650 pQuiet->byQuietCount,
651 pQuiet->byQuietPeriod,
652 *((unsigned short *)pQuiet->abyQuietDuration),
653 *((unsigned short *)pQuiet->abyQuietOffset)
656 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
657 CARDbSetQuiet(pMgmt->pAdapter,
659 pQuiet->byQuietCount,
660 pQuiet->byQuietPeriod,
661 *((unsigned short *)pQuiet->abyQuietDuration),
662 *((unsigned short *)pQuiet->abyQuietOffset)
668 if ((bParsingQuiet == true) &&
670 CARDbStartQuiet(pMgmt->pAdapter);
673 pBSSList->uIELength = uIELength;
674 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
675 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
676 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
683 * Routine Description:
684 * Search Node DB table to find the index of matched DstAddr
692 BSSDBbIsSTAInNodeDB(void *pMgmtObject, unsigned char *abyDstAddr,
693 unsigned int *puNodeIndex)
695 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
698 /* Index = 0 reserved for AP Node */
699 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
700 if (pMgmt->sNodeDBTable[ii].bActive) {
701 if (ether_addr_equal(abyDstAddr,
702 pMgmt->sNodeDBTable[ii].abyMACAddr)) {
714 * Routine Description:
715 * Find an empty node and allocat it; if there is no empty node,
716 * then use the most inactive one.
723 BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex)
725 PSDevice pDevice = (PSDevice)hDeviceContext;
726 PSMgmtObject pMgmt = pDevice->pMgmt;
728 unsigned int BigestCount = 0;
729 unsigned int SelectIndex;
732 * Index = 0 reserved for AP Node (In STA mode)
733 * Index = 0 reserved for Broadcast/MultiCast (In AP mode)
736 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
737 if (pMgmt->sNodeDBTable[ii].bActive) {
738 if (pMgmt->sNodeDBTable[ii].uInActiveCount > BigestCount) {
739 BigestCount = pMgmt->sNodeDBTable[ii].uInActiveCount;
747 /* if not found replace uInActiveCount is largest one */
748 if (ii == (MAX_NODE_NUM + 1)) {
749 *puNodeIndex = SelectIndex;
750 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Replace inactive node = %d\n", SelectIndex);
751 /* clear ps buffer */
752 if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
753 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
760 memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
761 pMgmt->sNodeDBTable[*puNodeIndex].bActive = true;
762 pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
763 /* for AP mode PS queue */
764 skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
765 pMgmt->sNodeDBTable[*puNodeIndex].byAuthSequence = 0;
766 pMgmt->sNodeDBTable[*puNodeIndex].wEnQueueCnt = 0;
767 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create node index = %d\n", ii);
773 * Routine Description:
774 * Remove Node by NodeIndex
783 void *hDeviceContext,
784 unsigned int uNodeIndex
787 PSDevice pDevice = (PSDevice)hDeviceContext;
788 PSMgmtObject pMgmt = pDevice->pMgmt;
789 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
792 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
795 memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
796 /* clear tx bit map */
797 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &= ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
803 * Routine Description:
804 * Update AP Node content in Index 0 of KnownNodeDB
814 void *hDeviceContext,
815 unsigned short *pwCapInfo,
816 PWLAN_IE_SUPP_RATES pSuppRates,
817 PWLAN_IE_SUPP_RATES pExtSuppRates
820 PSDevice pDevice = (PSDevice)hDeviceContext;
821 PSMgmtObject pMgmt = pDevice->pMgmt;
822 unsigned int uRateLen = WLAN_RATES_MAXLEN;
824 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
826 pMgmt->sNodeDBTable[0].bActive = true;
827 if (pDevice->eCurrentPHYType == PHY_TYPE_11B)
828 uRateLen = WLAN_RATES_MAXLEN_11B;
829 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
830 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
832 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
833 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
835 RATEvParseMaxRate((void *)pDevice,
836 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
837 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
839 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
840 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
841 &(pMgmt->sNodeDBTable[0].wSuppRate),
842 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
843 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
845 memcpy(pMgmt->sNodeDBTable[0].abyMACAddr, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
846 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxSuppRate;
847 pMgmt->sNodeDBTable[0].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo);
848 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
849 netdev_dbg(pDevice->dev, "BSSvUpdateAPNode:MaxSuppRate is %d\n",
850 pMgmt->sNodeDBTable[0].wMaxSuppRate);
851 /* auto rate fallback function initiation */
852 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "pMgmt->sNodeDBTable[0].wTxDataRate = %d\n", pMgmt->sNodeDBTable[0].wTxDataRate);
857 * Routine Description:
858 * Add Multicast Node content in Index 0 of KnownNodeDB
867 BSSvAddMulticastNode(
871 PSDevice pDevice = (PSDevice)hDeviceContext;
872 PSMgmtObject pMgmt = pDevice->pMgmt;
874 if (!pDevice->bEnableHostWEP)
875 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
876 memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
877 pMgmt->sNodeDBTable[0].bActive = true;
878 pMgmt->sNodeDBTable[0].bPSEnable = false;
879 skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
880 RATEvParseMaxRate((void *)pDevice,
881 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
882 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
884 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
885 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
886 &(pMgmt->sNodeDBTable[0].wSuppRate),
887 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
888 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
890 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
891 netdev_dbg(pDevice->dev,
892 "BSSvAddMultiCastNode:pMgmt->sNodeDBTable[0].wTxDataRate is %d\n",
893 pMgmt->sNodeDBTable[0].wTxDataRate);
894 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
899 * Routine Description:
902 * Second call back function to update Node DB info & AP link status
909 /* 2008-4-14 <add> by chester for led issue */
910 #ifdef FOR_LED_ON_NOTEBOOK
919 PSDevice pDevice = (PSDevice)hDeviceContext;
920 PSMgmtObject pMgmt = pDevice->pMgmt;
922 PWLAN_IE_SSID pItemSSID, pCurrSSID;
923 unsigned int uSleepySTACnt = 0;
924 unsigned int uNonShortSlotSTACnt = 0;
925 unsigned int uLongPreambleSTACnt = 0;
926 viawget_wpa_header *wpahdr; /* DavidWang */
928 spin_lock_irq(&pDevice->lock);
930 pDevice->uAssocCount = 0;
932 pDevice->byERPFlag &=
933 ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
934 /* 2008-4-14 <add> by chester for led issue */
935 #ifdef FOR_LED_ON_NOTEBOOK
936 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
937 if (((!(pDevice->byGPIO & GPIO0_DATA) && (pDevice->bHWRadioOff == false)) || ((pDevice->byGPIO & GPIO0_DATA) && (pDevice->bHWRadioOff == true))) && (cc == false)) {
939 } else if (cc == true) {
940 if (pDevice->bHWRadioOff == true) {
941 if (!(pDevice->byGPIO & GPIO0_DATA)) {
945 CARDbRadioPowerOff(pDevice);
946 pMgmt->sNodeDBTable[0].bActive = false;
947 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
948 pMgmt->eCurrState = WMAC_STATE_IDLE;
949 pDevice->bLinkPass = false;
952 if (pDevice->byGPIO & GPIO0_DATA) {
956 CARDbRadioPowerOn(pDevice);
959 if (pDevice->byGPIO & GPIO0_DATA) {
963 CARDbRadioPowerOff(pDevice);
964 pMgmt->sNodeDBTable[0].bActive = false;
965 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
966 pMgmt->eCurrState = WMAC_STATE_IDLE;
967 pDevice->bLinkPass = false;
970 if (!(pDevice->byGPIO & GPIO0_DATA)) {
974 CARDbRadioPowerOn(pDevice);
981 if (pDevice->wUseProtectCntDown > 0) {
982 pDevice->wUseProtectCntDown--;
984 /* disable protect mode */
985 pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
989 pDevice->byReAssocCount++;
991 if ((pDevice->byReAssocCount > 10) && (pDevice->bLinkPass != true)) {
992 netdev_info(pDevice->dev, "Re-association timeout!!!\n");
993 pDevice->byReAssocCount = 0;
994 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
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);
1003 } else if (pDevice->bLinkPass == true)
1004 pDevice->byReAssocCount = 0;
1007 #ifdef Calcu_LinkQual
1008 s_uCalculateLinkQual((void *)pDevice);
1011 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
1012 if (pMgmt->sNodeDBTable[ii].bActive) {
1013 /* increase in-activity counter */
1014 pMgmt->sNodeDBTable[ii].uInActiveCount++;
1017 if (pMgmt->sNodeDBTable[ii].uInActiveCount > MAX_INACTIVE_COUNT) {
1018 BSSvRemoveOneNode(pDevice, ii);
1019 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1020 "Inactive timeout [%d] sec, STA index = [%d] remove\n", MAX_INACTIVE_COUNT, ii);
1024 if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
1025 pDevice->uAssocCount++;
1027 /* check if Non ERP exist */
1028 if (pMgmt->sNodeDBTable[ii].uInActiveCount < ERP_RECOVER_COUNT) {
1029 if (!pMgmt->sNodeDBTable[ii].bShortPreamble) {
1030 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
1031 uLongPreambleSTACnt++;
1033 if (!pMgmt->sNodeDBTable[ii].bERPExist) {
1034 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
1035 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1037 if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
1038 uNonShortSlotSTACnt++;
1042 /* check if any STA in PS mode */
1043 if (pMgmt->sNodeDBTable[ii].bPSEnable)
1048 /* rate fallback check */
1049 if (!pDevice->bFixRate) {
1051 /* ii = 0 for multicast node (AP & Adhoc) */
1052 RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
1054 /* ii = 0 reserved for unicast AP node (Infra STA) */
1055 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
1056 netdev_dbg(pDevice->dev,
1057 "SecondCallback:Before:TxDataRate is %d\n",
1058 pMgmt->sNodeDBTable[0].wTxDataRate);
1059 RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
1060 netdev_dbg(pDevice->dev,
1061 "SecondCallback:After:TxDataRate is %d\n",
1062 pMgmt->sNodeDBTable[0].wTxDataRate);
1068 /* check if pending PS queue */
1069 if (pMgmt->sNodeDBTable[ii].wEnQueueCnt != 0) {
1070 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index= %d, Queue = %d pending\n",
1071 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
1072 if ((ii > 0) && (pMgmt->sNodeDBTable[ii].wEnQueueCnt > 15)) {
1073 BSSvRemoveOneNode(pDevice, ii);
1074 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Pending many queues PS STA Index = %d remove\n", ii);
1082 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->eCurrentPHYType == PHY_TYPE_11G)) {
1083 /* on/off protect mode */
1084 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
1085 if (!pDevice->bProtectMode) {
1086 MACvEnableProtectMD(pDevice->PortOffset);
1087 pDevice->bProtectMode = true;
1090 if (pDevice->bProtectMode) {
1091 MACvDisableProtectMD(pDevice->PortOffset);
1092 pDevice->bProtectMode = false;
1095 /* on/off short slot time */
1097 if (uNonShortSlotSTACnt > 0) {
1098 if (pDevice->bShortSlotTime) {
1099 pDevice->bShortSlotTime = false;
1100 BBvSetShortSlotTime(pDevice);
1101 vUpdateIFS((void *)pDevice);
1104 if (!pDevice->bShortSlotTime) {
1105 pDevice->bShortSlotTime = true;
1106 BBvSetShortSlotTime(pDevice);
1107 vUpdateIFS((void *)pDevice);
1111 /* on/off barker long preamble mode */
1113 if (uLongPreambleSTACnt > 0) {
1114 if (!pDevice->bBarkerPreambleMd) {
1115 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
1116 pDevice->bBarkerPreambleMd = true;
1119 if (pDevice->bBarkerPreambleMd) {
1120 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
1121 pDevice->bBarkerPreambleMd = false;
1127 /* check if any STA in PS mode, enable DTIM multicast deliver */
1128 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1129 if (uSleepySTACnt > 0)
1130 pMgmt->sNodeDBTable[0].bPSEnable = true;
1132 pMgmt->sNodeDBTable[0].bPSEnable = false;
1135 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
1136 pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
1138 if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
1139 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
1140 /* assoc with BSS */
1141 if (pMgmt->sNodeDBTable[0].bActive) {
1142 if (pDevice->bUpdateBBVGA)
1143 s_vCheckPreEDThreshold((void *)pDevice);
1145 if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
1146 (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0])) {
1147 pDevice->byBBVGANew = pDevice->abyBBVGA[0];
1148 bScheduleCommand((void *)pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1151 if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
1152 pMgmt->sNodeDBTable[0].bActive = false;
1153 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1154 pMgmt->eCurrState = WMAC_STATE_IDLE;
1155 netif_stop_queue(pDevice->dev);
1156 pDevice->bLinkPass = false;
1157 pDevice->bRoaming = true;
1158 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1159 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1160 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1161 wpahdr->type = VIAWGET_DISASSOC_MSG;
1162 wpahdr->resp_ie_len = 0;
1163 wpahdr->req_ie_len = 0;
1164 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1165 pDevice->skb->dev = pDevice->wpadev;
1166 skb_reset_mac_header(pDevice->skb);
1167 pDevice->skb->pkt_type = PACKET_HOST;
1168 pDevice->skb->protocol = htons(ETH_P_802_2);
1169 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1170 netif_rx(pDevice->skb);
1171 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1173 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1175 union iwreq_data wrqu;
1176 memset(&wrqu, 0, sizeof(wrqu));
1177 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1178 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1179 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1183 } else if (pItemSSID->len != 0) {
1184 if (pDevice->uAutoReConnectTime < 10) {
1185 pDevice->uAutoReConnectTime++;
1186 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1188 * network manager support need not do
1191 if (pDevice->bWPASuppWextEnabled == true)
1192 pDevice->uAutoReConnectTime = 0;
1196 * mike use old encryption status
1197 * for wpa reauthentication
1199 if (pDevice->bWPADEVUp)
1200 pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
1202 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming ...\n");
1203 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
1204 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1205 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
1206 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
1207 pDevice->uAutoReConnectTime = 0;
1212 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1213 /* if adhoc started which essid is NULL string, rescanning */
1214 if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
1215 if (pDevice->uAutoReConnectTime < 10) {
1216 pDevice->uAutoReConnectTime++;
1218 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Adhoc re-scanning ...\n");
1219 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1220 bScheduleCommand((void *)pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1221 bScheduleCommand((void *)pDevice, WLAN_CMD_SSID, NULL);
1222 pDevice->uAutoReConnectTime = 0;
1225 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
1226 if (pDevice->bUpdateBBVGA)
1227 s_vCheckPreEDThreshold((void *)pDevice);
1228 if (pMgmt->sNodeDBTable[0].uInActiveCount >= ADHOC_LOST_BEACON_COUNT) {
1229 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1230 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1231 pMgmt->eCurrState = WMAC_STATE_STARTED;
1232 netif_stop_queue(pDevice->dev);
1233 pDevice->bLinkPass = false;
1238 spin_unlock_irq(&pDevice->lock);
1240 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
1241 add_timer(&pMgmt->sTimerSecondCallback);
1247 * Routine Description:
1250 * Update Tx attemps, Tx failure counter in Node DB
1259 BSSvUpdateNodeTxCounter(
1260 void *hDeviceContext,
1261 unsigned char byTsr0,
1262 unsigned char byTsr1,
1263 unsigned char *pbyBuffer,
1264 unsigned int uFIFOHeaderSize
1267 PSDevice pDevice = (PSDevice)hDeviceContext;
1268 PSMgmtObject pMgmt = pDevice->pMgmt;
1269 unsigned int uNodeIndex = 0;
1270 unsigned char byTxRetry = (byTsr0 & TSR0_NCR);
1271 PSTxBufHead pTxBufHead;
1272 PS802_11Header pMACHeader;
1273 unsigned short wRate;
1274 unsigned short wFallBackRate = RATE_1M;
1275 unsigned char byFallBack;
1277 pTxBufHead = (PSTxBufHead) pbyBuffer;
1278 if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_0)
1279 byFallBack = AUTO_FB_0;
1280 else if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_1)
1281 byFallBack = AUTO_FB_1;
1283 byFallBack = AUTO_FB_NONE;
1284 wRate = pTxBufHead->wReserved;
1286 /* Only Unicast using support rates */
1287 if (pTxBufHead->wFIFOCtl & FIFOCTL_NEEDACK) {
1288 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "wRate %04X, byTsr0 %02X, byTsr1 %02X\n", wRate, byTsr0, byTsr1);
1289 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
1290 pMgmt->sNodeDBTable[0].uTxAttempts += 1;
1291 if ((byTsr1 & TSR1_TERR) == 0) {
1292 /* transmit success, TxAttempts at least plus one */
1293 pMgmt->sNodeDBTable[0].uTxOk[MAX_RATE]++;
1294 if ((byFallBack == AUTO_FB_NONE) ||
1295 (wRate < RATE_18M)) {
1296 wFallBackRate = wRate;
1297 } else if (byFallBack == AUTO_FB_0) {
1299 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1301 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1302 } else if (byFallBack == AUTO_FB_1) {
1304 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1306 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1308 pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
1310 pMgmt->sNodeDBTable[0].uTxFailures++;
1312 pMgmt->sNodeDBTable[0].uTxRetry += byTxRetry;
1313 if (byTxRetry != 0) {
1314 pMgmt->sNodeDBTable[0].uTxFail[MAX_RATE] += byTxRetry;
1315 if ((byFallBack == AUTO_FB_NONE) ||
1316 (wRate < RATE_18M)) {
1317 pMgmt->sNodeDBTable[0].uTxFail[wRate] += byTxRetry;
1318 } else if (byFallBack == AUTO_FB_0) {
1319 for (ii = 0; ii < byTxRetry; ii++) {
1321 wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
1323 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1324 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1326 } else if (byFallBack == AUTO_FB_1) {
1327 for (ii = 0; ii < byTxRetry; ii++) {
1329 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1331 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1332 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1338 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
1339 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1340 pMACHeader = (PS802_11Header)(pbyBuffer + uFIFOHeaderSize);
1342 if (BSSDBbIsSTAInNodeDB((void *)pMgmt, &(pMACHeader->abyAddr1[0]), &uNodeIndex)) {
1343 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
1344 if ((byTsr1 & TSR1_TERR) == 0) {
1345 /* transmit success, TxAttempts at least plus one */
1346 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
1347 if ((byFallBack == AUTO_FB_NONE) ||
1348 (wRate < RATE_18M)) {
1349 wFallBackRate = wRate;
1350 } else if (byFallBack == AUTO_FB_0) {
1352 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1354 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1355 } else if (byFallBack == AUTO_FB_1) {
1357 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1359 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1361 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
1363 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures++;
1365 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += byTxRetry;
1366 if (byTxRetry != 0) {
1367 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[MAX_RATE] += byTxRetry;
1368 if ((byFallBack == AUTO_FB_NONE) ||
1369 (wRate < RATE_18M)) {
1370 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wRate] += byTxRetry;
1371 } else if (byFallBack == AUTO_FB_0) {
1372 for (ii = 0; ii < byTxRetry; ii++) {
1374 wFallBackRate = awHWRetry0[wRate - RATE_18M][ii];
1376 wFallBackRate = awHWRetry0[wRate - RATE_18M][4];
1377 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1379 } else if (byFallBack == AUTO_FB_1) {
1380 for (ii = 0; ii < byTxRetry; ii++) {
1382 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1384 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1385 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1398 * Routine Description:
1399 * Clear Nodes & skb in DB Table
1404 * hDeviceContext - The adapter context.
1405 * uStartIndex - starting index
1415 BSSvClearNodeDBTable(
1416 void *hDeviceContext,
1417 unsigned int uStartIndex
1421 PSDevice pDevice = (PSDevice)hDeviceContext;
1422 PSMgmtObject pMgmt = pDevice->pMgmt;
1423 struct sk_buff *skb;
1426 for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
1427 if (pMgmt->sNodeDBTable[ii].bActive) {
1428 /* check if sTxPSQueue has been initial */
1429 if (pMgmt->sNodeDBTable[ii].sTxPSQueue.next != NULL) {
1430 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL) {
1431 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS skb != NULL %d\n", ii);
1435 memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
1442 void s_vCheckSensitivity(
1443 void *hDeviceContext
1446 PSDevice pDevice = (PSDevice)hDeviceContext;
1447 PKnownBSS pBSSList = NULL;
1448 PSMgmtObject pMgmt = pDevice->pMgmt;
1451 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) && (pDevice->byRFType == RF_RFMD2959) &&
1452 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
1456 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1457 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1458 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1459 if (pBSSList != NULL) {
1460 /* Update BB Reg if RSSI is too strong */
1461 long LocalldBmAverage = 0;
1463 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
1464 if (pBSSList->ldBmAverage[ii] != 0) {
1466 LocalldBmAverage += pBSSList->ldBmAverage[ii];
1469 if (uNumofdBm > 0) {
1470 LocalldBmAverage = LocalldBmAverage/uNumofdBm;
1471 for (ii = 0; ii < BB_VGA_LEVEL; ii++) {
1472 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "LocalldBmAverage:%ld, %ld %02x\n", LocalldBmAverage, pDevice->ldBmThreshold[ii], pDevice->abyBBVGA[ii]);
1473 if (LocalldBmAverage < pDevice->ldBmThreshold[ii]) {
1474 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1478 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1479 pDevice->uBBVGADiffCount++;
1480 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
1481 bScheduleCommand((void *)pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1483 pDevice->uBBVGADiffCount = 0;
1491 BSSvClearAnyBSSJoinRecord(
1492 void *hDeviceContext
1495 PSDevice pDevice = (PSDevice)hDeviceContext;
1496 PSMgmtObject pMgmt = pDevice->pMgmt;
1499 for (ii = 0; ii < MAX_BSS_NUM; ii++)
1500 pMgmt->sBSSList[ii].bSelected = false;
1504 #ifdef Calcu_LinkQual
1505 void s_uCalculateLinkQual(
1506 void *hDeviceContext
1509 PSDevice pDevice = (PSDevice)hDeviceContext;
1510 unsigned long TxOkRatio, TxCnt;
1511 unsigned long RxOkRatio, RxCnt;
1512 unsigned long RssiRatio;
1515 TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
1516 pDevice->scStatistic.TxRetryOkCount +
1517 pDevice->scStatistic.TxFailCount;
1518 RxCnt = pDevice->scStatistic.RxFcsErrCnt +
1519 pDevice->scStatistic.RxOkCnt;
1520 TxOkRatio = (TxCnt < 6) ? 4000 : ((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
1521 RxOkRatio = (RxCnt < 6) ? 2000 : ((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
1522 /* decide link quality */
1523 if (pDevice->bLinkPass != true) {
1524 pDevice->scStatistic.LinkQuality = 0;
1525 pDevice->scStatistic.SignalStren = 0;
1527 RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
1530 else if (-ldBm > 90)
1533 RssiRatio = (40-(-ldBm-50))*4000/40;
1534 pDevice->scStatistic.SignalStren = RssiRatio/40;
1535 pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
1537 pDevice->scStatistic.RxFcsErrCnt = 0;
1538 pDevice->scStatistic.RxOkCnt = 0;
1539 pDevice->scStatistic.TxFailCount = 0;
1540 pDevice->scStatistic.TxNoRetryOkCount = 0;
1541 pDevice->scStatistic.TxRetryOkCount = 0;
1546 void s_vCheckPreEDThreshold(
1547 void *hDeviceContext
1550 PSDevice pDevice = (PSDevice)hDeviceContext;
1551 PKnownBSS pBSSList = NULL;
1552 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1554 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1555 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1556 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1557 if (pBSSList != NULL)
1558 pDevice->byBBPreEDRSSI = (unsigned char) (~(pBSSList->ldBmAverRange) + 1);