x86/PCI: use host bridge _CRS info on ASUS M2V-MX SE
[linux-btrfs-devel.git] / drivers / staging / vt6655 / bssdb.c
blob577599ed70ada2db901ba87c465dc69db9dd714b
1 /*
2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3 * All rights reserved.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 * File: bssdb.c
21 * Purpose: Handles the Basic Service Set & Node Database functions
23 * Functions:
24 * BSSpSearchBSSList - Search known BSS list for Desire SSID or BSSID
25 * BSSvClearBSSList - Clear BSS List
26 * BSSbInsertToBSSList - Insert a BSS set into known BSS list
27 * BSSbUpdateToBSSList - Update BSS set in known BSS list
28 * 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
34 * Revision History:
36 * Author: Lyndon Chen
38 * Date: July 17, 2002
42 #include "ttype.h"
43 #include "tmacro.h"
44 #include "tether.h"
45 #include "device.h"
46 #include "80211hdr.h"
47 #include "bssdb.h"
48 #include "wmgr.h"
49 #include "datarate.h"
50 #include "desc.h"
51 #include "wcmd.h"
52 #include "wpa.h"
53 #include "baseband.h"
54 #include "rf.h"
55 #include "card.h"
56 #include "channel.h"
57 #include "mac.h"
58 #include "wpa2.h"
59 #include "iowpa.h"
61 //#define PLICE_DEBUG
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 unsigned short 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 unsigned short awHWRetry1[5][5] = {
83 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
84 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
85 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
86 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
87 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
92 /*--------------------- Static Functions --------------------------*/
94 void s_vCheckSensitivity(
95 void *hDeviceContext
98 #ifdef Calcu_LinkQual
99 void s_uCalculateLinkQual(
100 void *hDeviceContext
102 #endif
105 void s_vCheckPreEDThreshold(
106 void *hDeviceContext
108 /*--------------------- Export Variables --------------------------*/
111 /*--------------------- Export Functions --------------------------*/
119 * Routine Description:
120 * Search known BSS list for Desire SSID or BSSID.
122 * Return Value:
123 * PTR to KnownBSS or NULL
127 PKnownBSS
128 BSSpSearchBSSList(
129 void *hDeviceContext,
130 unsigned char *pbyDesireBSSID,
131 unsigned char *pbyDesireSSID,
132 CARD_PHY_TYPE ePhyType
135 PSDevice pDevice = (PSDevice)hDeviceContext;
136 PSMgmtObject pMgmt = pDevice->pMgmt;
137 unsigned char *pbyBSSID = NULL;
138 PWLAN_IE_SSID pSSID = NULL;
139 PKnownBSS pCurrBSS = NULL;
140 PKnownBSS pSelect = NULL;
141 unsigned char ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
142 unsigned int ii = 0;
144 if (pbyDesireBSSID != NULL) {
145 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSpSearchBSSList BSSID[%02X %02X %02X-%02X %02X %02X]\n",
146 *pbyDesireBSSID,*(pbyDesireBSSID+1),*(pbyDesireBSSID+2),
147 *(pbyDesireBSSID+3),*(pbyDesireBSSID+4),*(pbyDesireBSSID+5));
148 if ((!is_broadcast_ether_addr(pbyDesireBSSID)) &&
149 (memcmp(pbyDesireBSSID, ZeroBSSID, 6)!= 0)){
150 pbyBSSID = pbyDesireBSSID;
153 if (pbyDesireSSID != NULL) {
154 if (((PWLAN_IE_SSID)pbyDesireSSID)->len != 0) {
155 pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
159 if (pbyBSSID != NULL) {
160 // match BSSID first
161 for (ii = 0; ii <MAX_BSS_NUM; ii++) {
162 pCurrBSS = &(pMgmt->sBSSList[ii]);
163 if(pDevice->bLinkPass==false) pCurrBSS->bSelected = false;
164 if ((pCurrBSS->bActive) &&
165 (pCurrBSS->bSelected == false)) {
166 if (!compare_ether_addr(pCurrBSS->abyBSSID, pbyBSSID)) {
167 if (pSSID != NULL) {
168 // compare ssid
169 if ( !memcmp(pSSID->abySSID,
170 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
171 pSSID->len)) {
172 if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
173 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
174 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
176 pCurrBSS->bSelected = true;
177 return(pCurrBSS);
180 } else {
181 if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
182 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
183 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
185 pCurrBSS->bSelected = true;
186 return(pCurrBSS);
192 } else {
193 // ignore BSSID
194 for (ii = 0; ii <MAX_BSS_NUM; ii++) {
195 pCurrBSS = &(pMgmt->sBSSList[ii]);
196 //2007-0721-01<Add>by MikeLiu
197 pCurrBSS->bSelected = false;
198 if (pCurrBSS->bActive) {
200 if (pSSID != NULL) {
201 // matched SSID
202 if (! !memcmp(pSSID->abySSID,
203 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
204 pSSID->len) ||
205 (pSSID->len != ((PWLAN_IE_SSID)pCurrBSS->abySSID)->len)) {
206 // SSID not match skip this BSS
207 continue;
210 if (((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) ||
211 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo))
213 // Type not match skip this BSS
214 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSS type mismatch.... Config[%d] BSS[0x%04x]\n", pMgmt->eConfigMode, pCurrBSS->wCapInfo);
215 continue;
218 if (ePhyType != PHY_TYPE_AUTO) {
219 if (((ePhyType == PHY_TYPE_11A) && (PHY_TYPE_11A != pCurrBSS->eNetworkTypeInUse)) ||
220 ((ePhyType != PHY_TYPE_11A) && (PHY_TYPE_11A == pCurrBSS->eNetworkTypeInUse))) {
221 // PhyType not match skip this BSS
222 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Physical type mismatch.... ePhyType[%d] BSS[%d]\n", ePhyType, pCurrBSS->eNetworkTypeInUse);
223 continue;
227 if (pMgmt->eAuthenMode < WMAC_AUTH_WPA) {
228 if (pCurrBSS->bWPAValid == true) {
229 // WPA AP will reject connection of station without WPA enable.
230 continue;
232 } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
233 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
234 if (pCurrBSS->bWPAValid == false) {
235 // station with WPA enable can't join NonWPA AP.
236 continue;
238 } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
239 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
240 if (pCurrBSS->bWPA2Valid == false) {
241 // station with WPA2 enable can't join NonWPA2 AP.
242 continue;
246 if (pSelect == NULL) {
247 pSelect = pCurrBSS;
248 } else {
249 // compare RSSI, select signal strong one
250 if (pCurrBSS->uRSSI < pSelect->uRSSI) {
251 pSelect = pCurrBSS;
256 if (pSelect != NULL) {
257 pSelect->bSelected = true;
259 if (pDevice->bRoaming == false) {
260 // Einsn Add @20070907
261 memset(pbyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
262 memcpy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1) ;
265 return(pSelect);
268 return(NULL);
275 * Routine Description:
276 * Clear BSS List
278 * Return Value:
279 * None.
284 void
285 BSSvClearBSSList(
286 void *hDeviceContext,
287 bool bKeepCurrBSSID
290 PSDevice pDevice = (PSDevice)hDeviceContext;
291 PSMgmtObject pMgmt = pDevice->pMgmt;
292 unsigned int ii;
294 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
295 if (bKeepCurrBSSID) {
296 if (pMgmt->sBSSList[ii].bActive &&
297 !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID, pMgmt->abyCurrBSSID)) {
298 // bKeepCurrBSSID = false;
299 continue;
303 if ((pMgmt->sBSSList[ii].bActive) && (pMgmt->sBSSList[ii].uClearCount < BSS_CLEAR_COUNT)) {
304 pMgmt->sBSSList[ii].uClearCount ++;
305 continue;
308 pMgmt->sBSSList[ii].bActive = false;
309 memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS));
311 BSSvClearAnyBSSJoinRecord(pDevice);
313 return;
320 * Routine Description:
321 * search BSS list by BSSID & SSID if matched
323 * Return Value:
324 * true if found.
327 PKnownBSS
328 BSSpAddrIsInBSSList(
329 void *hDeviceContext,
330 unsigned char *abyBSSID,
331 PWLAN_IE_SSID pSSID
334 PSDevice pDevice = (PSDevice)hDeviceContext;
335 PSMgmtObject pMgmt = pDevice->pMgmt;
336 PKnownBSS pBSSList = NULL;
337 unsigned int ii;
339 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
340 pBSSList = &(pMgmt->sBSSList[ii]);
341 if (pBSSList->bActive) {
342 if (!compare_ether_addr(pBSSList->abyBSSID, abyBSSID)) {
343 // if (pSSID == NULL)
344 // return pBSSList;
345 if (pSSID->len == ((PWLAN_IE_SSID)pBSSList->abySSID)->len){
346 if (memcmp(pSSID->abySSID,
347 ((PWLAN_IE_SSID)pBSSList->abySSID)->abySSID,
348 pSSID->len) == 0)
349 return pBSSList;
355 return NULL;
362 * Routine Description:
363 * Insert a BSS set into known BSS list
365 * Return Value:
366 * true if success.
370 bool
371 BSSbInsertToBSSList (
372 void *hDeviceContext,
373 unsigned char *abyBSSIDAddr,
374 QWORD qwTimestamp,
375 unsigned short wBeaconInterval,
376 unsigned short wCapInfo,
377 unsigned char byCurrChannel,
378 PWLAN_IE_SSID pSSID,
379 PWLAN_IE_SUPP_RATES pSuppRates,
380 PWLAN_IE_SUPP_RATES pExtSuppRates,
381 PERPObject psERP,
382 PWLAN_IE_RSN pRSN,
383 PWLAN_IE_RSN_EXT pRSNWPA,
384 PWLAN_IE_COUNTRY pIE_Country,
385 PWLAN_IE_QUIET pIE_Quiet,
386 unsigned int uIELength,
387 unsigned char *pbyIEs,
388 void *pRxPacketContext
392 PSDevice pDevice = (PSDevice)hDeviceContext;
393 PSMgmtObject pMgmt = pDevice->pMgmt;
394 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
395 PKnownBSS pBSSList = NULL;
396 unsigned int ii;
397 bool bParsingQuiet = false;
398 PWLAN_IE_QUIET pQuiet = NULL;
402 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
404 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
405 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[ii]);
406 if (!pBSSList->bActive)
407 break;
410 if (ii == MAX_BSS_NUM){
411 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n");
412 return false;
414 // save the BSS info
415 pBSSList->bActive = true;
416 memcpy( pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
417 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
418 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
419 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
420 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
421 pBSSList->uClearCount = 0;
423 if (pSSID->len > WLAN_SSID_MAXLEN)
424 pSSID->len = WLAN_SSID_MAXLEN;
425 memcpy( pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
427 pBSSList->uChannel = byCurrChannel;
429 if (pSuppRates->len > WLAN_RATES_MAXLEN)
430 pSuppRates->len = WLAN_RATES_MAXLEN;
431 memcpy( pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
433 if (pExtSuppRates != NULL) {
434 if (pExtSuppRates->len > WLAN_RATES_MAXLEN)
435 pExtSuppRates->len = WLAN_RATES_MAXLEN;
436 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
437 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSbInsertToBSSList: pExtSuppRates->len = %d\n", pExtSuppRates->len);
439 } else {
440 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
442 pBSSList->sERP.byERP = psERP->byERP;
443 pBSSList->sERP.bERPExist = psERP->bERPExist;
445 // Check if BSS is 802.11a/b/g
446 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
447 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
448 } else {
449 if (pBSSList->sERP.bERPExist == true) {
450 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
451 } else {
452 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
456 pBSSList->byRxRate = pRxPacket->byRxRate;
457 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
458 pBSSList->uRSSI = pRxPacket->uRSSI;
459 pBSSList->bySQ = pRxPacket->bySQ;
461 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
462 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
463 // assoc with BSS
464 if (pBSSList == pMgmt->pCurrBSS) {
465 bParsingQuiet = true;
469 WPA_ClearRSN(pBSSList);
471 if (pRSNWPA != NULL) {
472 unsigned int uLen = pRSNWPA->len + 2;
474 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
475 pBSSList->wWPALen = uLen;
476 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
477 WPA_ParseRSN(pBSSList, pRSNWPA);
481 WPA2_ClearRSN(pBSSList);
483 if (pRSN != NULL) {
484 unsigned int uLen = pRSN->len + 2;
485 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
486 pBSSList->wRSNLen = uLen;
487 memcpy(pBSSList->byRSNIE, pRSN, uLen);
488 WPA2vParseRSN(pBSSList, pRSN);
492 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == true)) {
494 PSKeyItem pTransmitKey = NULL;
495 bool bIs802_1x = false;
497 for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii ++) {
498 if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
499 bIs802_1x = true;
500 break;
503 if ((bIs802_1x == true) && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
504 ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
506 bAdd_PMKID_Candidate((void *)pDevice, pBSSList->abyBSSID, &pBSSList->sRSNCapObj);
508 if ((pDevice->bLinkPass == true) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
509 if ((KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) == true) ||
510 (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey) == true)) {
511 pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
512 pDevice->gsPMKIDCandidate.Version = 1;
520 if (pDevice->bUpdateBBVGA) {
521 // Moniter if RSSI is too strong.
522 pBSSList->byRSSIStatCnt = 0;
523 RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
524 pBSSList->ldBmAverage[0] = pBSSList->ldBmMAX;
525 for (ii = 1; ii < RSSI_STAT_COUNT; ii++)
526 pBSSList->ldBmAverage[ii] = 0;
529 if ((pIE_Country != NULL) &&
530 (pMgmt->b11hEnable == true)) {
531 set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
532 pIE_Country);
535 if ((bParsingQuiet == true) && (pIE_Quiet != NULL)) {
536 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
537 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
538 // valid EID
539 if (pQuiet == NULL) {
540 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
541 CARDbSetQuiet( pMgmt->pAdapter,
542 true,
543 pQuiet->byQuietCount,
544 pQuiet->byQuietPeriod,
545 *((unsigned short *)pQuiet->abyQuietDuration),
546 *((unsigned short *)pQuiet->abyQuietOffset)
548 } else {
549 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
550 CARDbSetQuiet( pMgmt->pAdapter,
551 false,
552 pQuiet->byQuietCount,
553 pQuiet->byQuietPeriod,
554 *((unsigned short *)pQuiet->abyQuietDuration),
555 *((unsigned short *)pQuiet->abyQuietOffset)
561 if ((bParsingQuiet == true) &&
562 (pQuiet != NULL)) {
563 CARDbStartQuiet(pMgmt->pAdapter);
566 pBSSList->uIELength = uIELength;
567 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
568 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
569 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
571 return true;
577 * Routine Description:
578 * Update BSS set in known BSS list
580 * Return Value:
581 * true if success.
584 // TODO: input structure modify
586 bool
587 BSSbUpdateToBSSList (
588 void *hDeviceContext,
589 QWORD qwTimestamp,
590 unsigned short wBeaconInterval,
591 unsigned short wCapInfo,
592 unsigned char byCurrChannel,
593 bool bChannelHit,
594 PWLAN_IE_SSID pSSID,
595 PWLAN_IE_SUPP_RATES pSuppRates,
596 PWLAN_IE_SUPP_RATES pExtSuppRates,
597 PERPObject psERP,
598 PWLAN_IE_RSN pRSN,
599 PWLAN_IE_RSN_EXT pRSNWPA,
600 PWLAN_IE_COUNTRY pIE_Country,
601 PWLAN_IE_QUIET pIE_Quiet,
602 PKnownBSS pBSSList,
603 unsigned int uIELength,
604 unsigned char *pbyIEs,
605 void *pRxPacketContext
608 int ii;
609 PSDevice pDevice = (PSDevice)hDeviceContext;
610 PSMgmtObject pMgmt = pDevice->pMgmt;
611 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
612 long ldBm;
613 bool bParsingQuiet = false;
614 PWLAN_IE_QUIET pQuiet = NULL;
618 if (pBSSList == NULL)
619 return false;
622 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
623 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
624 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
625 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
626 pBSSList->uClearCount = 0;
627 pBSSList->uChannel = byCurrChannel;
628 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSbUpdateToBSSList: pBSSList->uChannel: %d\n", pBSSList->uChannel);
630 if (pSSID->len > WLAN_SSID_MAXLEN)
631 pSSID->len = WLAN_SSID_MAXLEN;
633 if ((pSSID->len != 0) && (pSSID->abySSID[0] != 0))
634 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
635 memcpy(pBSSList->abySuppRates, pSuppRates,pSuppRates->len + WLAN_IEHDR_LEN);
637 if (pExtSuppRates != NULL) {
638 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates,pExtSuppRates->len + WLAN_IEHDR_LEN);
639 } else {
640 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
642 pBSSList->sERP.byERP = psERP->byERP;
643 pBSSList->sERP.bERPExist = psERP->bERPExist;
645 // Check if BSS is 802.11a/b/g
646 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
647 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
648 } else {
649 if (pBSSList->sERP.bERPExist == true) {
650 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
651 } else {
652 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
656 pBSSList->byRxRate = pRxPacket->byRxRate;
657 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
658 if(bChannelHit)
659 pBSSList->uRSSI = pRxPacket->uRSSI;
660 pBSSList->bySQ = pRxPacket->bySQ;
662 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
663 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
664 // assoc with BSS
665 if (pBSSList == pMgmt->pCurrBSS) {
666 bParsingQuiet = true;
670 WPA_ClearRSN(pBSSList); //mike update
672 if (pRSNWPA != NULL) {
673 unsigned int uLen = pRSNWPA->len + 2;
674 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSNWPA - pbyIEs))) {
675 pBSSList->wWPALen = uLen;
676 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
677 WPA_ParseRSN(pBSSList, pRSNWPA);
681 WPA2_ClearRSN(pBSSList); //mike update
683 if (pRSN != NULL) {
684 unsigned int uLen = pRSN->len + 2;
685 if (uLen <= (uIELength - (unsigned int)((unsigned char *)pRSN - pbyIEs))) {
686 pBSSList->wRSNLen = uLen;
687 memcpy(pBSSList->byRSNIE, pRSN, uLen);
688 WPA2vParseRSN(pBSSList, pRSN);
692 if (pRxPacket->uRSSI != 0) {
693 RFvRSSITodBm(pDevice, (unsigned char)(pRxPacket->uRSSI), &ldBm);
694 // Moniter if RSSI is too strong.
695 pBSSList->byRSSIStatCnt++;
696 pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
697 pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
698 for(ii=0;ii<RSSI_STAT_COUNT;ii++) {
699 if (pBSSList->ldBmAverage[ii] != 0) {
700 pBSSList->ldBmMAX = max(pBSSList->ldBmAverage[ii], ldBm);
705 if ((pIE_Country != NULL) &&
706 (pMgmt->b11hEnable == true)) {
707 set_country_info(pMgmt->pAdapter, pBSSList->eNetworkTypeInUse,
708 pIE_Country);
711 if ((bParsingQuiet == true) && (pIE_Quiet != NULL)) {
712 if ((((PWLAN_IE_QUIET)pIE_Quiet)->len == 8) &&
713 (((PWLAN_IE_QUIET)pIE_Quiet)->byQuietCount != 0)) {
714 // valid EID
715 if (pQuiet == NULL) {
716 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
717 CARDbSetQuiet( pMgmt->pAdapter,
718 true,
719 pQuiet->byQuietCount,
720 pQuiet->byQuietPeriod,
721 *((unsigned short *)pQuiet->abyQuietDuration),
722 *((unsigned short *)pQuiet->abyQuietOffset)
724 } else {
725 pQuiet = (PWLAN_IE_QUIET)pIE_Quiet;
726 CARDbSetQuiet( pMgmt->pAdapter,
727 false,
728 pQuiet->byQuietCount,
729 pQuiet->byQuietPeriod,
730 *((unsigned short *)pQuiet->abyQuietDuration),
731 *((unsigned short *)pQuiet->abyQuietOffset)
737 if ((bParsingQuiet == true) &&
738 (pQuiet != NULL)) {
739 CARDbStartQuiet(pMgmt->pAdapter);
742 pBSSList->uIELength = uIELength;
743 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
744 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
745 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
747 return true;
756 * Routine Description:
757 * Search Node DB table to find the index of matched DstAddr
759 * Return Value:
760 * None
764 bool
765 BSSDBbIsSTAInNodeDB(void *pMgmtObject, unsigned char *abyDstAddr,
766 unsigned int *puNodeIndex)
768 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
769 unsigned int ii;
771 // Index = 0 reserved for AP Node
772 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
773 if (pMgmt->sNodeDBTable[ii].bActive) {
774 if (!compare_ether_addr(abyDstAddr, pMgmt->sNodeDBTable[ii].abyMACAddr)) {
775 *puNodeIndex = ii;
776 return true;
781 return false;
788 * Routine Description:
789 * Find an empty node and allocated; if no empty found,
790 * instand used of most inactive one.
792 * Return Value:
793 * None
796 void
797 BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex)
800 PSDevice pDevice = (PSDevice)hDeviceContext;
801 PSMgmtObject pMgmt = pDevice->pMgmt;
802 unsigned int ii;
803 unsigned int BigestCount = 0;
804 unsigned int SelectIndex;
805 struct sk_buff *skb;
806 // Index = 0 reserved for AP Node (In STA mode)
807 // Index = 0 reserved for Broadcast/MultiCast (In AP mode)
808 SelectIndex = 1;
809 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
810 if (pMgmt->sNodeDBTable[ii].bActive) {
811 if (pMgmt->sNodeDBTable[ii].uInActiveCount > BigestCount) {
812 BigestCount = pMgmt->sNodeDBTable[ii].uInActiveCount;
813 SelectIndex = ii;
816 else {
817 break;
821 // if not found replace uInActiveCount is largest one.
822 if ( ii == (MAX_NODE_NUM + 1)) {
823 *puNodeIndex = SelectIndex;
824 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Replace inactive node = %d\n", SelectIndex);
825 // clear ps buffer
826 if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
827 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
828 dev_kfree_skb(skb);
831 else {
832 *puNodeIndex = ii;
835 memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
836 pMgmt->sNodeDBTable[*puNodeIndex].bActive = true;
837 pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
838 // for AP mode PS queue
839 skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
840 pMgmt->sNodeDBTable[*puNodeIndex].byAuthSequence = 0;
841 pMgmt->sNodeDBTable[*puNodeIndex].wEnQueueCnt = 0;
842 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create node index = %d\n", ii);
843 return;
850 * Routine Description:
851 * Remove Node by NodeIndex
854 * Return Value:
855 * None
858 void
859 BSSvRemoveOneNode(
860 void *hDeviceContext,
861 unsigned int uNodeIndex
865 PSDevice pDevice = (PSDevice)hDeviceContext;
866 PSMgmtObject pMgmt = pDevice->pMgmt;
867 unsigned char byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
868 struct sk_buff *skb;
871 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
872 dev_kfree_skb(skb);
873 // clear context
874 memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
875 // clear tx bit map
876 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &= ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
878 return;
882 * Routine Description:
883 * Update AP Node content in Index 0 of KnownNodeDB
886 * Return Value:
887 * None
891 void
892 BSSvUpdateAPNode(
893 void *hDeviceContext,
894 unsigned short *pwCapInfo,
895 PWLAN_IE_SUPP_RATES pSuppRates,
896 PWLAN_IE_SUPP_RATES pExtSuppRates
899 PSDevice pDevice = (PSDevice)hDeviceContext;
900 PSMgmtObject pMgmt = pDevice->pMgmt;
901 unsigned int uRateLen = WLAN_RATES_MAXLEN;
903 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
905 pMgmt->sNodeDBTable[0].bActive = true;
906 if (pDevice->eCurrentPHYType == PHY_TYPE_11B) {
907 uRateLen = WLAN_RATES_MAXLEN_11B;
909 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
910 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
911 uRateLen);
912 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
913 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
914 uRateLen);
915 RATEvParseMaxRate((void *)pDevice,
916 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
917 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
918 true,
919 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
920 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
921 &(pMgmt->sNodeDBTable[0].wSuppRate),
922 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
923 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
925 memcpy(pMgmt->sNodeDBTable[0].abyMACAddr, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
926 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxSuppRate;
927 pMgmt->sNodeDBTable[0].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo);
928 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
929 #ifdef PLICE_DEBUG
930 printk("BSSvUpdateAPNode:MaxSuppRate is %d\n",pMgmt->sNodeDBTable[0].wMaxSuppRate);
931 #endif
932 // Auto rate fallback function initiation.
933 // RATEbInit(pDevice);
934 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pMgmt->sNodeDBTable[0].wTxDataRate = %d \n", pMgmt->sNodeDBTable[0].wTxDataRate);
944 * Routine Description:
945 * Add Multicast Node content in Index 0 of KnownNodeDB
948 * Return Value:
949 * None
954 void
955 BSSvAddMulticastNode(
956 void *hDeviceContext
959 PSDevice pDevice = (PSDevice)hDeviceContext;
960 PSMgmtObject pMgmt = pDevice->pMgmt;
962 if (!pDevice->bEnableHostWEP)
963 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
964 memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
965 pMgmt->sNodeDBTable[0].bActive = true;
966 pMgmt->sNodeDBTable[0].bPSEnable = false;
967 skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
968 RATEvParseMaxRate((void *)pDevice,
969 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
970 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
971 true,
972 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
973 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
974 &(pMgmt->sNodeDBTable[0].wSuppRate),
975 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
976 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
978 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
979 #ifdef PLICE_DEBUG
980 printk("BSSvAddMultiCastNode:pMgmt->sNodeDBTable[0].wTxDataRate is %d\n",pMgmt->sNodeDBTable[0].wTxDataRate);
981 #endif
982 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
992 * Routine Description:
995 * Second call back function to update Node DB info & AP link status
998 * Return Value:
999 * none.
1002 //2008-4-14 <add> by chester for led issue
1003 #ifdef FOR_LED_ON_NOTEBOOK
1004 bool cc=false;
1005 unsigned int status;
1006 #endif
1007 void
1008 BSSvSecondCallBack(
1009 void *hDeviceContext
1012 PSDevice pDevice = (PSDevice)hDeviceContext;
1013 PSMgmtObject pMgmt = pDevice->pMgmt;
1014 unsigned int ii;
1015 PWLAN_IE_SSID pItemSSID, pCurrSSID;
1016 unsigned int uSleepySTACnt = 0;
1017 unsigned int uNonShortSlotSTACnt = 0;
1018 unsigned int uLongPreambleSTACnt = 0;
1019 viawget_wpa_header* wpahdr; //DavidWang
1021 spin_lock_irq(&pDevice->lock);
1023 pDevice->uAssocCount = 0;
1025 pDevice->byERPFlag &=
1026 ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
1027 //2008-4-14 <add> by chester for led issue
1028 #ifdef FOR_LED_ON_NOTEBOOK
1029 MACvGPIOIn(pDevice->PortOffset, &pDevice->byGPIO);
1030 if ((( !(pDevice->byGPIO & GPIO0_DATA)&&(pDevice->bHWRadioOff == false))||((pDevice->byGPIO & GPIO0_DATA)&&(pDevice->bHWRadioOff == true)))&&(cc==false)){
1031 cc=true;
1033 else if(cc==true){
1035 if(pDevice->bHWRadioOff == true){
1036 if ( !(pDevice->byGPIO & GPIO0_DATA))
1037 //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
1038 {if(status==1) goto start;
1039 status=1;
1040 CARDbRadioPowerOff(pDevice);
1041 pMgmt->sNodeDBTable[0].bActive = false;
1042 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1043 pMgmt->eCurrState = WMAC_STATE_IDLE;
1044 //netif_stop_queue(pDevice->dev);
1045 pDevice->bLinkPass = false;
1048 if (pDevice->byGPIO &GPIO0_DATA)
1049 //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
1050 {if(status==2) goto start;
1051 status=2;
1052 CARDbRadioPowerOn(pDevice);
1054 else{
1055 if (pDevice->byGPIO & GPIO0_DATA)
1056 //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
1057 {if(status==3) goto start;
1058 status=3;
1059 CARDbRadioPowerOff(pDevice);
1060 pMgmt->sNodeDBTable[0].bActive = false;
1061 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1062 pMgmt->eCurrState = WMAC_STATE_IDLE;
1063 //netif_stop_queue(pDevice->dev);
1064 pDevice->bLinkPass = false;
1067 if ( !(pDevice->byGPIO & GPIO0_DATA))
1068 //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
1069 {if(status==4) goto start;
1070 status=4;
1071 CARDbRadioPowerOn(pDevice);
1074 start:
1075 #endif
1078 if (pDevice->wUseProtectCntDown > 0) {
1079 pDevice->wUseProtectCntDown --;
1081 else {
1082 // disable protect mode
1083 pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
1087 pDevice->byReAssocCount++;
1088 if((pDevice->byReAssocCount > 10) && (pDevice->bLinkPass != true)) { //10 sec timeout
1089 printk("Re-association timeout!!!\n");
1090 pDevice->byReAssocCount = 0;
1091 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1092 // if(pDevice->bWPASuppWextEnabled == true)
1094 union iwreq_data wrqu;
1095 memset(&wrqu, 0, sizeof (wrqu));
1096 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1097 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1098 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1100 #endif
1102 else if(pDevice->bLinkPass == true)
1103 pDevice->byReAssocCount = 0;
1106 #ifdef Calcu_LinkQual
1107 s_uCalculateLinkQual((void *)pDevice);
1108 #endif
1110 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
1112 if (pMgmt->sNodeDBTable[ii].bActive) {
1113 // Increase in-activity counter
1114 pMgmt->sNodeDBTable[ii].uInActiveCount++;
1116 if (ii > 0) {
1117 if (pMgmt->sNodeDBTable[ii].uInActiveCount > MAX_INACTIVE_COUNT) {
1118 BSSvRemoveOneNode(pDevice, ii);
1119 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
1120 "Inactive timeout [%d] sec, STA index = [%d] remove\n", MAX_INACTIVE_COUNT, ii);
1121 continue;
1124 if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
1126 pDevice->uAssocCount++;
1128 // check if Non ERP exist
1129 if (pMgmt->sNodeDBTable[ii].uInActiveCount < ERP_RECOVER_COUNT) {
1130 if (!pMgmt->sNodeDBTable[ii].bShortPreamble) {
1131 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
1132 uLongPreambleSTACnt ++;
1134 if (!pMgmt->sNodeDBTable[ii].bERPExist) {
1135 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
1136 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
1138 if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
1139 uNonShortSlotSTACnt++;
1143 // check if any STA in PS mode
1144 if (pMgmt->sNodeDBTable[ii].bPSEnable)
1145 uSleepySTACnt++;
1150 // Rate fallback check
1151 if (!pDevice->bFixRate) {
1153 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (ii == 0))
1154 RATEvTxRateFallBack(pDevice, &(pMgmt->sNodeDBTable[ii]));
1156 if (ii > 0) {
1157 // ii = 0 for multicast node (AP & Adhoc)
1158 RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
1160 else {
1161 // ii = 0 reserved for unicast AP node (Infra STA)
1162 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
1163 #ifdef PLICE_DEBUG
1164 printk("SecondCallback:Before:TxDataRate is %d\n",pMgmt->sNodeDBTable[0].wTxDataRate);
1165 #endif
1166 RATEvTxRateFallBack((void *)pDevice, &(pMgmt->sNodeDBTable[ii]));
1167 #ifdef PLICE_DEBUG
1168 printk("SecondCallback:After:TxDataRate is %d\n",pMgmt->sNodeDBTable[0].wTxDataRate);
1169 #endif
1175 // check if pending PS queue
1176 if (pMgmt->sNodeDBTable[ii].wEnQueueCnt != 0) {
1177 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index= %d, Queue = %d pending \n",
1178 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
1179 if ((ii >0) && (pMgmt->sNodeDBTable[ii].wEnQueueCnt > 15)) {
1180 BSSvRemoveOneNode(pDevice, ii);
1181 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Pending many queues PS STA Index = %d remove \n", ii);
1182 continue;
1190 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->eCurrentPHYType == PHY_TYPE_11G)) {
1192 // on/off protect mode
1193 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
1194 if (!pDevice->bProtectMode) {
1195 MACvEnableProtectMD(pDevice->PortOffset);
1196 pDevice->bProtectMode = true;
1199 else {
1200 if (pDevice->bProtectMode) {
1201 MACvDisableProtectMD(pDevice->PortOffset);
1202 pDevice->bProtectMode = false;
1205 // on/off short slot time
1207 if (uNonShortSlotSTACnt > 0) {
1208 if (pDevice->bShortSlotTime) {
1209 pDevice->bShortSlotTime = false;
1210 BBvSetShortSlotTime(pDevice);
1211 vUpdateIFS((void *)pDevice);
1214 else {
1215 if (!pDevice->bShortSlotTime) {
1216 pDevice->bShortSlotTime = true;
1217 BBvSetShortSlotTime(pDevice);
1218 vUpdateIFS((void *)pDevice);
1222 // on/off barker long preamble mode
1224 if (uLongPreambleSTACnt > 0) {
1225 if (!pDevice->bBarkerPreambleMd) {
1226 MACvEnableBarkerPreambleMd(pDevice->PortOffset);
1227 pDevice->bBarkerPreambleMd = true;
1230 else {
1231 if (pDevice->bBarkerPreambleMd) {
1232 MACvDisableBarkerPreambleMd(pDevice->PortOffset);
1233 pDevice->bBarkerPreambleMd = false;
1240 // Check if any STA in PS mode, enable DTIM multicast deliver
1241 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1242 if (uSleepySTACnt > 0)
1243 pMgmt->sNodeDBTable[0].bPSEnable = true;
1244 else
1245 pMgmt->sNodeDBTable[0].bPSEnable = false;
1248 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
1249 pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
1251 if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
1252 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
1254 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
1255 // DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Callback inactive Count = [%d]\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1256 //if (pDevice->bUpdateBBVGA) {
1257 // s_vCheckSensitivity((void *) pDevice);
1260 if (pDevice->bUpdateBBVGA) {
1261 // s_vCheckSensitivity((void *) pDevice);
1262 s_vCheckPreEDThreshold((void *)pDevice);
1265 if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
1266 (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0]) ) {
1267 pDevice->byBBVGANew = pDevice->abyBBVGA[0];
1268 bScheduleCommand((void *) pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1271 if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
1272 pMgmt->sNodeDBTable[0].bActive = false;
1273 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1274 pMgmt->eCurrState = WMAC_STATE_IDLE;
1275 netif_stop_queue(pDevice->dev);
1276 pDevice->bLinkPass = false;
1277 pDevice->bRoaming = true;
1278 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1279 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1280 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1281 wpahdr->type = VIAWGET_DISASSOC_MSG;
1282 wpahdr->resp_ie_len = 0;
1283 wpahdr->req_ie_len = 0;
1284 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1285 pDevice->skb->dev = pDevice->wpadev;
1286 skb_reset_mac_header(pDevice->skb);
1287 pDevice->skb->pkt_type = PACKET_HOST;
1288 pDevice->skb->protocol = htons(ETH_P_802_2);
1289 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1290 netif_rx(pDevice->skb);
1291 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1293 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1294 // if(pDevice->bWPASuppWextEnabled == true)
1296 union iwreq_data wrqu;
1297 memset(&wrqu, 0, sizeof (wrqu));
1298 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
1299 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1300 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
1302 #endif
1305 else if (pItemSSID->len != 0) {
1306 if (pDevice->uAutoReConnectTime < 10) {
1307 pDevice->uAutoReConnectTime++;
1308 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1309 //network manager support need not do Roaming scan???
1310 if(pDevice->bWPASuppWextEnabled ==true)
1311 pDevice->uAutoReConnectTime = 0;
1312 #endif
1314 else {
1315 //mike use old encryption status for wpa reauthen
1316 if(pDevice->bWPADEVUp)
1317 pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
1319 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming ...\n");
1320 BSSvClearBSSList((void *)pDevice, pDevice->bLinkPass);
1321 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1322 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, pMgmt->abyDesireSSID);
1323 bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, pMgmt->abyDesireSSID);
1324 pDevice->uAutoReConnectTime = 0;
1329 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1330 // if adhoc started which essid is NULL string, rescaning.
1331 if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
1332 if (pDevice->uAutoReConnectTime < 10) {
1333 pDevice->uAutoReConnectTime++;
1335 else {
1336 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Adhoc re-scaning ...\n");
1337 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1338 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1339 bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
1340 pDevice->uAutoReConnectTime = 0;
1343 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
1345 if (pDevice->bUpdateBBVGA) {
1346 //s_vCheckSensitivity((void *) pDevice);
1347 s_vCheckPreEDThreshold((void *)pDevice);
1349 if (pMgmt->sNodeDBTable[0].uInActiveCount >=ADHOC_LOST_BEACON_COUNT) {
1350 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1351 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1352 pMgmt->eCurrState = WMAC_STATE_STARTED;
1353 netif_stop_queue(pDevice->dev);
1354 pDevice->bLinkPass = false;
1359 spin_unlock_irq(&pDevice->lock);
1361 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
1362 add_timer(&pMgmt->sTimerSecondCallback);
1363 return;
1371 * Routine Description:
1374 * Update Tx attemps, Tx failure counter in Node DB
1377 * Return Value:
1378 * none.
1384 void
1385 BSSvUpdateNodeTxCounter(
1386 void *hDeviceContext,
1387 unsigned char byTsr0,
1388 unsigned char byTsr1,
1389 unsigned char *pbyBuffer,
1390 unsigned int uFIFOHeaderSize
1393 PSDevice pDevice = (PSDevice)hDeviceContext;
1394 PSMgmtObject pMgmt = pDevice->pMgmt;
1395 unsigned int uNodeIndex = 0;
1396 unsigned char byTxRetry = (byTsr0 & TSR0_NCR);
1397 PSTxBufHead pTxBufHead;
1398 PS802_11Header pMACHeader;
1399 unsigned short wRate;
1400 unsigned short wFallBackRate = RATE_1M;
1401 unsigned char byFallBack;
1402 unsigned int ii;
1403 // unsigned int txRetryTemp;
1404 //PLICE_DEBUG->
1405 //txRetryTemp = byTxRetry;
1406 //if (txRetryTemp== 8)
1407 //txRetryTemp -=3;
1408 //PLICE_DEBUG <-
1409 pTxBufHead = (PSTxBufHead) pbyBuffer;
1410 if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_0) {
1411 byFallBack = AUTO_FB_0;
1412 } else if (pTxBufHead->wFIFOCtl & FIFOCTL_AUTO_FB_1) {
1413 byFallBack = AUTO_FB_1;
1414 } else {
1415 byFallBack = AUTO_FB_NONE;
1417 wRate = pTxBufHead->wReserved; //?wRate
1418 //printk("BSSvUpdateNodeTxCounter:byTxRetry is %d\n",byTxRetry);
1420 //printk("BSSvUpdateNodeTx:wRate is %d,byFallback is %d\n",wRate,byFallBack);
1421 //#ifdef PLICE_DEBUG
1422 //printk("BSSvUpdateNodeTx: wRate is %d\n",wRate);
1423 ////#endif
1424 // Only Unicast using support rates
1425 if (pTxBufHead->wFIFOCtl & FIFOCTL_NEEDACK) {
1426 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"wRate %04X, byTsr0 %02X, byTsr1 %02X\n", wRate, byTsr0, byTsr1);
1427 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
1428 pMgmt->sNodeDBTable[0].uTxAttempts += 1;
1429 if ((byTsr1 & TSR1_TERR) == 0) {
1430 // transmit success, TxAttempts at least plus one
1431 pMgmt->sNodeDBTable[0].uTxOk[MAX_RATE]++;
1432 if ( (byFallBack == AUTO_FB_NONE) ||
1433 (wRate < RATE_18M) ) {
1434 wFallBackRate = wRate;
1435 } else if (byFallBack == AUTO_FB_0) {
1436 //PLICE_DEBUG
1437 if (byTxRetry < 5)
1438 //if (txRetryTemp < 5)
1439 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1440 //wFallBackRate = awHWRetry0[wRate-RATE_12M][byTxRetry];
1441 //wFallBackRate = awHWRetry0[wRate-RATE_18M][txRetryTemp] +1;
1442 else
1443 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1444 //wFallBackRate = awHWRetry0[wRate-RATE_12M][4];
1445 } else if (byFallBack == AUTO_FB_1) {
1446 if (byTxRetry < 5)
1447 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1448 else
1449 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1451 pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
1452 } else {
1453 pMgmt->sNodeDBTable[0].uTxFailures ++;
1455 pMgmt->sNodeDBTable[0].uTxRetry += byTxRetry;
1456 if (byTxRetry != 0) {
1457 pMgmt->sNodeDBTable[0].uTxFail[MAX_RATE]+=byTxRetry;
1458 if ( (byFallBack == AUTO_FB_NONE) ||
1459 (wRate < RATE_18M) ) {
1460 pMgmt->sNodeDBTable[0].uTxFail[wRate]+=byTxRetry;
1461 } else if (byFallBack == AUTO_FB_0) {
1462 //PLICE_DEBUG
1463 for(ii=0;ii<byTxRetry;ii++)
1464 //for (ii=0;ii<txRetryTemp;ii++)
1466 if (ii < 5)
1469 //PLICE_DEBUG
1470 wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
1471 //printk(" II is %d:BSSvUpdateNodeTx:wFallBackRate is %d\n",ii,wFallBackRate);
1472 //wFallBackRate = awHWRetry0[wRate-RATE_12M][ii];
1474 else
1476 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1477 //printk("ii is %d BSSvUpdateNodeTx:wFallBackRate is %d\n",ii,wFallBackRate);
1478 //wFallBackRate = awHWRetry0[wRate-RATE_12M][4];
1480 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1482 } else if (byFallBack == AUTO_FB_1) {
1483 for(ii=0;ii<byTxRetry;ii++) {
1484 if (ii < 5)
1485 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1486 else
1487 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1488 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1494 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
1495 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1497 pMACHeader = (PS802_11Header)(pbyBuffer + uFIFOHeaderSize);
1499 if (BSSDBbIsSTAInNodeDB((void *)pMgmt, &(pMACHeader->abyAddr1[0]), &uNodeIndex)){
1500 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
1501 if ((byTsr1 & TSR1_TERR) == 0) {
1502 // transmit success, TxAttempts at least plus one
1503 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
1504 if ( (byFallBack == AUTO_FB_NONE) ||
1505 (wRate < RATE_18M) ) {
1506 wFallBackRate = wRate;
1507 } else if (byFallBack == AUTO_FB_0) {
1508 if (byTxRetry < 5)
1509 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1510 else
1511 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1512 } else if (byFallBack == AUTO_FB_1) {
1513 if (byTxRetry < 5)
1514 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1515 else
1516 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1518 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
1519 } else {
1520 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures ++;
1522 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += byTxRetry;
1523 if (byTxRetry != 0) {
1524 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[MAX_RATE]+=byTxRetry;
1525 if ( (byFallBack == AUTO_FB_NONE) ||
1526 (wRate < RATE_18M) ) {
1527 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wRate]+=byTxRetry;
1528 } else if (byFallBack == AUTO_FB_0) {
1529 for(ii=0;ii<byTxRetry;ii++) {
1530 if (ii < 5)
1531 wFallBackRate = awHWRetry0[wRate-RATE_18M][ii];
1532 else
1533 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1534 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1536 } else if (byFallBack == AUTO_FB_1) {
1537 for(ii=0;ii<byTxRetry;ii++) {
1538 if (ii < 5)
1539 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1540 else
1541 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1542 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1550 return;
1560 * Routine Description:
1561 * Clear Nodes & skb in DB Table
1564 * Parameters:
1565 * In:
1566 * hDeviceContext - The adapter context.
1567 * uStartIndex - starting index
1568 * Out:
1569 * none
1571 * Return Value:
1572 * None.
1577 void
1578 BSSvClearNodeDBTable(
1579 void *hDeviceContext,
1580 unsigned int uStartIndex
1584 PSDevice pDevice = (PSDevice)hDeviceContext;
1585 PSMgmtObject pMgmt = pDevice->pMgmt;
1586 struct sk_buff *skb;
1587 unsigned int ii;
1589 for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
1590 if (pMgmt->sNodeDBTable[ii].bActive) {
1591 // check if sTxPSQueue has been initial
1592 if (pMgmt->sNodeDBTable[ii].sTxPSQueue.next != NULL) {
1593 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL){
1594 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS skb != NULL %d\n", ii);
1595 dev_kfree_skb(skb);
1598 memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
1602 return;
1606 void s_vCheckSensitivity(
1607 void *hDeviceContext
1610 PSDevice pDevice = (PSDevice)hDeviceContext;
1611 PKnownBSS pBSSList = NULL;
1612 PSMgmtObject pMgmt = pDevice->pMgmt;
1613 int ii;
1615 if ((pDevice->byLocalID <= REV_ID_VT3253_A1) && (pDevice->byRFType == RF_RFMD2959) &&
1616 (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
1617 return;
1620 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1621 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1622 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1623 if (pBSSList != NULL) {
1624 // Updata BB Reg if RSSI is too strong.
1625 long LocalldBmAverage = 0;
1626 long uNumofdBm = 0;
1627 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
1628 if (pBSSList->ldBmAverage[ii] != 0) {
1629 uNumofdBm ++;
1630 LocalldBmAverage += pBSSList->ldBmAverage[ii];
1633 if (uNumofdBm > 0) {
1634 LocalldBmAverage = LocalldBmAverage/uNumofdBm;
1635 for (ii=0;ii<BB_VGA_LEVEL;ii++) {
1636 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LocalldBmAverage:%ld, %ld %02x\n", LocalldBmAverage, pDevice->ldBmThreshold[ii], pDevice->abyBBVGA[ii]);
1637 if (LocalldBmAverage < pDevice->ldBmThreshold[ii]) {
1638 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1639 break;
1642 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1643 pDevice->uBBVGADiffCount++;
1644 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
1645 bScheduleCommand((void *) pDevice, WLAN_CMD_CHANGE_BBSENSITIVITY, NULL);
1646 } else {
1647 pDevice->uBBVGADiffCount = 0;
1655 void
1656 BSSvClearAnyBSSJoinRecord (
1657 void *hDeviceContext
1660 PSDevice pDevice = (PSDevice)hDeviceContext;
1661 PSMgmtObject pMgmt = pDevice->pMgmt;
1662 unsigned int ii;
1664 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
1665 pMgmt->sBSSList[ii].bSelected = false;
1667 return;
1670 #ifdef Calcu_LinkQual
1671 void s_uCalculateLinkQual(
1672 void *hDeviceContext
1675 PSDevice pDevice = (PSDevice)hDeviceContext;
1676 unsigned long TxOkRatio, TxCnt;
1677 unsigned long RxOkRatio,RxCnt;
1678 unsigned long RssiRatio;
1679 long ldBm;
1681 TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
1682 pDevice->scStatistic.TxRetryOkCount +
1683 pDevice->scStatistic.TxFailCount;
1684 RxCnt = pDevice->scStatistic.RxFcsErrCnt +
1685 pDevice->scStatistic.RxOkCnt;
1686 TxOkRatio = (TxCnt < 6) ? 4000:((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
1687 RxOkRatio = (RxCnt < 6) ? 2000:((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
1688 //decide link quality
1689 if(pDevice->bLinkPass !=true)
1691 // printk("s_uCalculateLinkQual-->Link disconnect and Poor quality**\n");
1692 pDevice->scStatistic.LinkQuality = 0;
1693 pDevice->scStatistic.SignalStren = 0;
1695 else
1697 RFvRSSITodBm(pDevice, (unsigned char)(pDevice->uCurrRSSI), &ldBm);
1698 if(-ldBm < 50) {
1699 RssiRatio = 4000;
1701 else if(-ldBm > 90) {
1702 RssiRatio = 0;
1704 else {
1705 RssiRatio = (40-(-ldBm-50))*4000/40;
1707 pDevice->scStatistic.SignalStren = RssiRatio/40;
1708 pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
1710 pDevice->scStatistic.RxFcsErrCnt = 0;
1711 pDevice->scStatistic.RxOkCnt = 0;
1712 pDevice->scStatistic.TxFailCount = 0;
1713 pDevice->scStatistic.TxNoRetryOkCount = 0;
1714 pDevice->scStatistic.TxRetryOkCount = 0;
1715 return;
1717 #endif
1719 void s_vCheckPreEDThreshold(
1720 void *hDeviceContext
1723 PSDevice pDevice = (PSDevice)hDeviceContext;
1724 PKnownBSS pBSSList = NULL;
1725 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1727 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1728 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1729 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1730 if (pBSSList != NULL) {
1731 pDevice->byBBPreEDRSSI = (unsigned char) (~(pBSSList->ldBmAverRange) + 1);
1732 //BBvUpdatePreEDThreshold(pDevice, false);
1735 return;