uprobes: Introduce MMF_HAS_UPROBES
[linux/fpc-iii.git] / drivers / staging / vt6656 / bssdb.c
blob099936771e6994a1c130be952deaced47ebcaca0
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 * BSSbIsSTAInNodeDB - Search Node DB table to find the index of matched DstAddr
29 * BSSvCreateOneNode - Allocate an Node for Node DB
30 * BSSvUpdateAPNode - Update AP Node content in Index 0 of KnownNodeDB
31 * BSSvSecondCallBack - One second timer callback function to update Node DB info & AP link status
32 * BSSvUpdateNodeTxCounter - Update Tx attemps, Tx failure counter in Node DB for auto-fall back rate control
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 "mac.h"
57 #include "wpa2.h"
58 #include "control.h"
59 #include "rndis.h"
60 #include "iowpa.h"
62 /*--------------------- Static Definitions -------------------------*/
67 /*--------------------- Static Classes ----------------------------*/
69 /*--------------------- Static Variables --------------------------*/
70 static int msglevel =MSG_LEVEL_INFO;
71 //static int msglevel =MSG_LEVEL_DEBUG;
75 const WORD awHWRetry0[5][5] = {
76 {RATE_18M, RATE_18M, RATE_12M, RATE_12M, RATE_12M},
77 {RATE_24M, RATE_24M, RATE_18M, RATE_12M, RATE_12M},
78 {RATE_36M, RATE_36M, RATE_24M, RATE_18M, RATE_18M},
79 {RATE_48M, RATE_48M, RATE_36M, RATE_24M, RATE_24M},
80 {RATE_54M, RATE_54M, RATE_48M, RATE_36M, RATE_36M}
82 const WORD awHWRetry1[5][5] = {
83 {RATE_18M, RATE_18M, RATE_12M, RATE_6M, RATE_6M},
84 {RATE_24M, RATE_24M, RATE_18M, RATE_6M, RATE_6M},
85 {RATE_36M, RATE_36M, RATE_24M, RATE_12M, RATE_12M},
86 {RATE_48M, RATE_48M, RATE_24M, RATE_12M, RATE_12M},
87 {RATE_54M, RATE_54M, RATE_36M, RATE_18M, RATE_18M}
92 /*--------------------- Static Functions --------------------------*/
94 void s_vCheckSensitivity(void *hDeviceContext);
95 void s_vCheckPreEDThreshold(void *hDeviceContext);
96 void s_uCalculateLinkQual(void *hDeviceContext);
98 /*--------------------- Export Variables --------------------------*/
101 /*--------------------- Export Functions --------------------------*/
109 * Routine Description:
110 * Search known BSS list for Desire SSID or BSSID.
112 * Return Value:
113 * PTR to KnownBSS or NULL
117 PKnownBSS BSSpSearchBSSList(void *hDeviceContext,
118 PBYTE pbyDesireBSSID,
119 PBYTE pbyDesireSSID,
120 CARD_PHY_TYPE ePhyType)
122 PSDevice pDevice = (PSDevice)hDeviceContext;
123 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
124 PBYTE pbyBSSID = NULL;
125 PWLAN_IE_SSID pSSID = NULL;
126 PKnownBSS pCurrBSS = NULL;
127 PKnownBSS pSelect = NULL;
128 BYTE ZeroBSSID[WLAN_BSSID_LEN]={0x00,0x00,0x00,0x00,0x00,0x00};
129 unsigned int ii = 0;
130 unsigned int jj = 0;
131 if (pbyDesireBSSID != NULL) {
132 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
133 "BSSpSearchBSSList BSSID[%pM]\n", pbyDesireBSSID);
134 if ((!is_broadcast_ether_addr(pbyDesireBSSID)) &&
135 (memcmp(pbyDesireBSSID, ZeroBSSID, 6)!= 0)){
136 pbyBSSID = pbyDesireBSSID;
139 if (pbyDesireSSID != NULL) {
140 if (((PWLAN_IE_SSID)pbyDesireSSID)->len != 0) {
141 pSSID = (PWLAN_IE_SSID) pbyDesireSSID;
145 if ((pbyBSSID != NULL)&&(pDevice->bRoaming == FALSE)) {
146 // match BSSID first
147 for (ii = 0; ii <MAX_BSS_NUM; ii++) {
148 pCurrBSS = &(pMgmt->sBSSList[ii]);
150 pCurrBSS->bSelected = FALSE;
152 if ((pCurrBSS->bActive) &&
153 (pCurrBSS->bSelected == FALSE)) {
154 if (!compare_ether_addr(pCurrBSS->abyBSSID, pbyBSSID)) {
155 if (pSSID != NULL) {
156 // compare ssid
157 if ( !memcmp(pSSID->abySSID,
158 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
159 pSSID->len)) {
160 if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
161 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
162 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
164 pCurrBSS->bSelected = TRUE;
165 return(pCurrBSS);
168 } else {
169 if ((pMgmt->eConfigMode == WMAC_CONFIG_AUTO) ||
170 ((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo)) ||
171 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo))
173 pCurrBSS->bSelected = TRUE;
174 return(pCurrBSS);
180 } else {
181 // ignore BSSID
182 for (ii = 0; ii <MAX_BSS_NUM; ii++) {
183 pCurrBSS = &(pMgmt->sBSSList[ii]);
185 //2007-0721-01<Mark>by MikeLiu
186 // if ((pCurrBSS->bActive) &&
187 // (pCurrBSS->bSelected == FALSE)) {
189 pCurrBSS->bSelected = FALSE;
190 if (pCurrBSS->bActive) {
192 if (pSSID != NULL) {
193 // matched SSID
194 if (memcmp(pSSID->abySSID,
195 ((PWLAN_IE_SSID)pCurrBSS->abySSID)->abySSID,
196 pSSID->len) ||
197 (pSSID->len != ((PWLAN_IE_SSID)pCurrBSS->abySSID)->len)) {
198 // SSID not match skip this BSS
199 continue;
202 if (((pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) && WLAN_GET_CAP_INFO_ESS(pCurrBSS->wCapInfo)) ||
203 ((pMgmt->eConfigMode == WMAC_CONFIG_ESS_STA) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS->wCapInfo))
205 // Type not match skip this BSS
206 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSS type mismatch.... Config[%d] BSS[0x%04x]\n", pMgmt->eConfigMode, pCurrBSS->wCapInfo);
207 continue;
210 if (ePhyType != PHY_TYPE_AUTO) {
211 if (((ePhyType == PHY_TYPE_11A) && (PHY_TYPE_11A != pCurrBSS->eNetworkTypeInUse)) ||
212 ((ePhyType != PHY_TYPE_11A) && (PHY_TYPE_11A == pCurrBSS->eNetworkTypeInUse))) {
213 // PhyType not match skip this BSS
214 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Physical type mismatch.... ePhyType[%d] BSS[%d]\n", ePhyType, pCurrBSS->eNetworkTypeInUse);
215 continue;
219 pMgmt->pSameBSS[jj].uChannel = pCurrBSS->uChannel;
220 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
221 "BSSpSearchBSSList pSelect1[%pM]\n",
222 pCurrBSS->abyBSSID);
223 jj++;
226 if (pSelect == NULL) {
227 pSelect = pCurrBSS;
228 } else {
229 // compare RSSI, select signal strong one
230 if (pCurrBSS->uRSSI < pSelect->uRSSI) {
231 pSelect = pCurrBSS;
237 pDevice->bSameBSSMaxNum = jj;
239 if (pSelect != NULL) {
240 pSelect->bSelected = TRUE;
241 if (pDevice->bRoaming == FALSE) {
242 // Einsn Add @20070907
243 memset(pbyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
244 memcpy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1) ;
247 return(pSelect);
250 return(NULL);
257 * Routine Description:
258 * Clear BSS List
260 * Return Value:
261 * None.
266 void BSSvClearBSSList(void *hDeviceContext, BOOL bKeepCurrBSSID)
268 PSDevice pDevice = (PSDevice)hDeviceContext;
269 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
270 unsigned int ii;
272 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
273 if (bKeepCurrBSSID) {
274 if (pMgmt->sBSSList[ii].bActive &&
275 !compare_ether_addr(pMgmt->sBSSList[ii].abyBSSID,
276 pMgmt->abyCurrBSSID)) {
277 //mike mark: there are two same BSSID in list if that AP is in hidden ssid mode,one 's SSID is null,
278 // but other's is obvious, so if it acssociate with your STA exactly,you must keep two
279 // of them!!!!!!!!!
280 // bKeepCurrBSSID = FALSE;
281 continue;
285 pMgmt->sBSSList[ii].bActive = FALSE;
286 memset(&pMgmt->sBSSList[ii], 0, sizeof(KnownBSS));
288 BSSvClearAnyBSSJoinRecord(pDevice);
295 * Routine Description:
296 * search BSS list by BSSID & SSID if matched
298 * Return Value:
299 * TRUE if found.
302 PKnownBSS BSSpAddrIsInBSSList(void *hDeviceContext,
303 PBYTE abyBSSID,
304 PWLAN_IE_SSID pSSID)
306 PSDevice pDevice = (PSDevice)hDeviceContext;
307 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
308 PKnownBSS pBSSList = NULL;
309 unsigned int ii;
311 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
312 pBSSList = &(pMgmt->sBSSList[ii]);
313 if (pBSSList->bActive) {
314 if (!compare_ether_addr(pBSSList->abyBSSID, abyBSSID)) {
315 if (pSSID->len == ((PWLAN_IE_SSID)pBSSList->abySSID)->len){
316 if (memcmp(pSSID->abySSID,
317 ((PWLAN_IE_SSID)pBSSList->abySSID)->abySSID,
318 pSSID->len) == 0)
319 return pBSSList;
325 return NULL;
332 * Routine Description:
333 * Insert a BSS set into known BSS list
335 * Return Value:
336 * TRUE if success.
340 BOOL BSSbInsertToBSSList(void *hDeviceContext,
341 PBYTE abyBSSIDAddr,
342 QWORD qwTimestamp,
343 WORD wBeaconInterval,
344 WORD wCapInfo,
345 BYTE byCurrChannel,
346 PWLAN_IE_SSID pSSID,
347 PWLAN_IE_SUPP_RATES pSuppRates,
348 PWLAN_IE_SUPP_RATES pExtSuppRates,
349 PERPObject psERP,
350 PWLAN_IE_RSN pRSN,
351 PWLAN_IE_RSN_EXT pRSNWPA,
352 PWLAN_IE_COUNTRY pIE_Country,
353 PWLAN_IE_QUIET pIE_Quiet,
354 unsigned int uIELength,
355 PBYTE pbyIEs,
356 void *pRxPacketContext)
359 PSDevice pDevice = (PSDevice)hDeviceContext;
360 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
361 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
362 PKnownBSS pBSSList = NULL;
363 unsigned int ii;
364 BOOL bParsingQuiet = FALSE;
368 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[0]);
370 for (ii = 0; ii < MAX_BSS_NUM; ii++) {
371 pBSSList = (PKnownBSS)&(pMgmt->sBSSList[ii]);
372 if (!pBSSList->bActive)
373 break;
376 if (ii == MAX_BSS_NUM){
377 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Get free KnowBSS node failed.\n");
378 return FALSE;
380 // save the BSS info
381 pBSSList->bActive = TRUE;
382 memcpy( pBSSList->abyBSSID, abyBSSIDAddr, WLAN_BSSID_LEN);
383 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
384 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
385 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
386 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
387 pBSSList->uClearCount = 0;
389 if (pSSID->len > WLAN_SSID_MAXLEN)
390 pSSID->len = WLAN_SSID_MAXLEN;
391 memcpy( pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
393 pBSSList->uChannel = byCurrChannel;
395 if (pSuppRates->len > WLAN_RATES_MAXLEN)
396 pSuppRates->len = WLAN_RATES_MAXLEN;
397 memcpy( pBSSList->abySuppRates, pSuppRates, pSuppRates->len + WLAN_IEHDR_LEN);
399 if (pExtSuppRates != NULL) {
400 if (pExtSuppRates->len > WLAN_RATES_MAXLEN)
401 pExtSuppRates->len = WLAN_RATES_MAXLEN;
402 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates, pExtSuppRates->len + WLAN_IEHDR_LEN);
403 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"BSSbInsertToBSSList: pExtSuppRates->len = %d\n", pExtSuppRates->len);
405 } else {
406 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
408 pBSSList->sERP.byERP = psERP->byERP;
409 pBSSList->sERP.bERPExist = psERP->bERPExist;
411 // Check if BSS is 802.11a/b/g
412 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
413 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
414 } else {
415 if (pBSSList->sERP.bERPExist == TRUE) {
416 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
417 } else {
418 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
422 pBSSList->byRxRate = pRxPacket->byRxRate;
423 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
424 pBSSList->uRSSI = pRxPacket->uRSSI;
425 pBSSList->bySQ = pRxPacket->bySQ;
427 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
428 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
429 // assoc with BSS
430 if (pBSSList == pMgmt->pCurrBSS) {
431 bParsingQuiet = TRUE;
435 WPA_ClearRSN(pBSSList);
437 if (pRSNWPA != NULL) {
438 unsigned int uLen = pRSNWPA->len + 2;
440 if (uLen <= (uIELength -
441 (unsigned int) (ULONG_PTR) ((PBYTE) pRSNWPA - pbyIEs))) {
442 pBSSList->wWPALen = uLen;
443 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
444 WPA_ParseRSN(pBSSList, pRSNWPA);
448 WPA2_ClearRSN(pBSSList);
450 if (pRSN != NULL) {
451 unsigned int uLen = pRSN->len + 2;
453 if (uLen <= (uIELength -
454 (unsigned int) (ULONG_PTR) ((PBYTE) pRSN - pbyIEs))) {
455 pBSSList->wRSNLen = uLen;
456 memcpy(pBSSList->byRSNIE, pRSN, uLen);
457 WPA2vParseRSN(pBSSList, pRSN);
461 if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) || (pBSSList->bWPA2Valid == TRUE)) {
463 PSKeyItem pTransmitKey = NULL;
464 BOOL bIs802_1x = FALSE;
466 for (ii = 0; ii < pBSSList->wAKMSSAuthCount; ii ++) {
467 if (pBSSList->abyAKMSSAuthType[ii] == WLAN_11i_AKMSS_802_1X) {
468 bIs802_1x = TRUE;
469 break;
472 if ((bIs802_1x == TRUE) && (pSSID->len == ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->len) &&
473 ( !memcmp(pSSID->abySSID, ((PWLAN_IE_SSID)pMgmt->abyDesireSSID)->abySSID, pSSID->len))) {
475 bAdd_PMKID_Candidate((void *) pDevice,
476 pBSSList->abyBSSID,
477 &pBSSList->sRSNCapObj);
479 if ((pDevice->bLinkPass == TRUE) && (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
480 if ((KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, PAIRWISE_KEY, &pTransmitKey) == TRUE) ||
481 (KeybGetTransmitKey(&(pDevice->sKey), pDevice->abyBSSID, GROUP_KEY, &pTransmitKey) == TRUE)) {
482 pDevice->gsPMKIDCandidate.StatusType = Ndis802_11StatusType_PMKID_CandidateList;
483 pDevice->gsPMKIDCandidate.Version = 1;
491 if (pDevice->bUpdateBBVGA) {
492 // Moniter if RSSI is too strong.
493 pBSSList->byRSSIStatCnt = 0;
494 RFvRSSITodBm(pDevice, (BYTE)(pRxPacket->uRSSI), &pBSSList->ldBmMAX);
495 pBSSList->ldBmAverage[0] = pBSSList->ldBmMAX;
496 pBSSList->ldBmAverRange = pBSSList->ldBmMAX;
497 for (ii = 1; ii < RSSI_STAT_COUNT; ii++)
498 pBSSList->ldBmAverage[ii] = 0;
501 pBSSList->uIELength = uIELength;
502 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
503 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
504 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
506 return TRUE;
512 * Routine Description:
513 * Update BSS set in known BSS list
515 * Return Value:
516 * TRUE if success.
519 // TODO: input structure modify
521 BOOL BSSbUpdateToBSSList(void *hDeviceContext,
522 QWORD qwTimestamp,
523 WORD wBeaconInterval,
524 WORD wCapInfo,
525 BYTE byCurrChannel,
526 BOOL bChannelHit,
527 PWLAN_IE_SSID pSSID,
528 PWLAN_IE_SUPP_RATES pSuppRates,
529 PWLAN_IE_SUPP_RATES pExtSuppRates,
530 PERPObject psERP,
531 PWLAN_IE_RSN pRSN,
532 PWLAN_IE_RSN_EXT pRSNWPA,
533 PWLAN_IE_COUNTRY pIE_Country,
534 PWLAN_IE_QUIET pIE_Quiet,
535 PKnownBSS pBSSList,
536 unsigned int uIELength,
537 PBYTE pbyIEs,
538 void *pRxPacketContext)
540 int ii, jj;
541 PSDevice pDevice = (PSDevice)hDeviceContext;
542 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
543 PSRxMgmtPacket pRxPacket = (PSRxMgmtPacket)pRxPacketContext;
544 signed long ldBm, ldBmSum;
545 BOOL bParsingQuiet = FALSE;
547 if (pBSSList == NULL)
548 return FALSE;
551 HIDWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(HIDWORD(qwTimestamp));
552 LODWORD(pBSSList->qwBSSTimestamp) = cpu_to_le32(LODWORD(qwTimestamp));
553 pBSSList->wBeaconInterval = cpu_to_le16(wBeaconInterval);
554 pBSSList->wCapInfo = cpu_to_le16(wCapInfo);
555 pBSSList->uClearCount = 0;
556 pBSSList->uChannel = byCurrChannel;
558 if (pSSID->len > WLAN_SSID_MAXLEN)
559 pSSID->len = WLAN_SSID_MAXLEN;
561 if ((pSSID->len != 0) && (pSSID->abySSID[0] != 0))
562 memcpy(pBSSList->abySSID, pSSID, pSSID->len + WLAN_IEHDR_LEN);
563 memcpy(pBSSList->abySuppRates, pSuppRates,pSuppRates->len + WLAN_IEHDR_LEN);
565 if (pExtSuppRates != NULL) {
566 memcpy(pBSSList->abyExtSuppRates, pExtSuppRates,pExtSuppRates->len + WLAN_IEHDR_LEN);
567 } else {
568 memset(pBSSList->abyExtSuppRates, 0, WLAN_IEHDR_LEN + WLAN_RATES_MAXLEN + 1);
570 pBSSList->sERP.byERP = psERP->byERP;
571 pBSSList->sERP.bERPExist = psERP->bERPExist;
573 // Check if BSS is 802.11a/b/g
574 if (pBSSList->uChannel > CB_MAX_CHANNEL_24G) {
575 pBSSList->eNetworkTypeInUse = PHY_TYPE_11A;
576 } else {
577 if (pBSSList->sERP.bERPExist == TRUE) {
578 pBSSList->eNetworkTypeInUse = PHY_TYPE_11G;
579 } else {
580 pBSSList->eNetworkTypeInUse = PHY_TYPE_11B;
584 pBSSList->byRxRate = pRxPacket->byRxRate;
585 pBSSList->qwLocalTSF = pRxPacket->qwLocalTSF;
586 if(bChannelHit)
587 pBSSList->uRSSI = pRxPacket->uRSSI;
588 pBSSList->bySQ = pRxPacket->bySQ;
590 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) &&
591 (pMgmt->eCurrState == WMAC_STATE_ASSOC)) {
592 // assoc with BSS
593 if (pBSSList == pMgmt->pCurrBSS) {
594 bParsingQuiet = TRUE;
598 WPA_ClearRSN(pBSSList); //mike update
600 if (pRSNWPA != NULL) {
601 unsigned int uLen = pRSNWPA->len + 2;
602 if (uLen <= (uIELength -
603 (unsigned int) (ULONG_PTR) ((PBYTE) pRSNWPA - pbyIEs))) {
604 pBSSList->wWPALen = uLen;
605 memcpy(pBSSList->byWPAIE, pRSNWPA, uLen);
606 WPA_ParseRSN(pBSSList, pRSNWPA);
610 WPA2_ClearRSN(pBSSList); //mike update
612 if (pRSN != NULL) {
613 unsigned int uLen = pRSN->len + 2;
614 if (uLen <= (uIELength -
615 (unsigned int) (ULONG_PTR) ((PBYTE) pRSN - pbyIEs))) {
616 pBSSList->wRSNLen = uLen;
617 memcpy(pBSSList->byRSNIE, pRSN, uLen);
618 WPA2vParseRSN(pBSSList, pRSN);
622 if (pRxPacket->uRSSI != 0) {
623 RFvRSSITodBm(pDevice, (BYTE)(pRxPacket->uRSSI), &ldBm);
624 // Moniter if RSSI is too strong.
625 pBSSList->byRSSIStatCnt++;
626 pBSSList->byRSSIStatCnt %= RSSI_STAT_COUNT;
627 pBSSList->ldBmAverage[pBSSList->byRSSIStatCnt] = ldBm;
628 ldBmSum = 0;
629 for (ii = 0, jj = 0; ii < RSSI_STAT_COUNT; ii++) {
630 if (pBSSList->ldBmAverage[ii] != 0) {
631 pBSSList->ldBmMAX =
632 max(pBSSList->ldBmAverage[ii], ldBm);
633 ldBmSum +=
634 pBSSList->ldBmAverage[ii];
635 jj++;
638 pBSSList->ldBmAverRange = ldBmSum /jj;
641 pBSSList->uIELength = uIELength;
642 if (pBSSList->uIELength > WLAN_BEACON_FR_MAXLEN)
643 pBSSList->uIELength = WLAN_BEACON_FR_MAXLEN;
644 memcpy(pBSSList->abyIEs, pbyIEs, pBSSList->uIELength);
646 return TRUE;
655 * Routine Description:
656 * Search Node DB table to find the index of matched DstAddr
658 * Return Value:
659 * None
663 BOOL BSSbIsSTAInNodeDB(void *hDeviceContext,
664 PBYTE abyDstAddr,
665 unsigned int *puNodeIndex)
667 PSDevice pDevice = (PSDevice)hDeviceContext;
668 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
669 unsigned int ii;
671 // Index = 0 reserved for AP Node
672 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
673 if (pMgmt->sNodeDBTable[ii].bActive) {
674 if (!compare_ether_addr(abyDstAddr,
675 pMgmt->sNodeDBTable[ii].abyMACAddr)) {
676 *puNodeIndex = ii;
677 return TRUE;
682 return FALSE;
689 * Routine Description:
690 * Find an empty node and allocated; if no empty found,
691 * instand used of most inactive one.
693 * Return Value:
694 * None
697 void BSSvCreateOneNode(void *hDeviceContext, unsigned int *puNodeIndex)
700 PSDevice pDevice = (PSDevice)hDeviceContext;
701 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
702 unsigned int ii;
703 unsigned int BigestCount = 0;
704 unsigned int SelectIndex;
705 struct sk_buff *skb;
706 // Index = 0 reserved for AP Node (In STA mode)
707 // Index = 0 reserved for Broadcast/MultiCast (In AP mode)
708 SelectIndex = 1;
709 for (ii = 1; ii < (MAX_NODE_NUM + 1); ii++) {
710 if (pMgmt->sNodeDBTable[ii].bActive) {
711 if (pMgmt->sNodeDBTable[ii].uInActiveCount > BigestCount) {
712 BigestCount = pMgmt->sNodeDBTable[ii].uInActiveCount;
713 SelectIndex = ii;
716 else {
717 break;
721 // if not found replace uInActiveCount is largest one.
722 if ( ii == (MAX_NODE_NUM + 1)) {
723 *puNodeIndex = SelectIndex;
724 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Replace inactive node = %d\n", SelectIndex);
725 // clear ps buffer
726 if (pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue.next != NULL) {
727 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue)) != NULL)
728 dev_kfree_skb(skb);
731 else {
732 *puNodeIndex = ii;
735 memset(&pMgmt->sNodeDBTable[*puNodeIndex], 0, sizeof(KnownNodeDB));
736 pMgmt->sNodeDBTable[*puNodeIndex].bActive = TRUE;
737 pMgmt->sNodeDBTable[*puNodeIndex].uRatePollTimeout = FALLBACK_POLL_SECOND;
738 // for AP mode PS queue
739 skb_queue_head_init(&pMgmt->sNodeDBTable[*puNodeIndex].sTxPSQueue);
740 pMgmt->sNodeDBTable[*puNodeIndex].byAuthSequence = 0;
741 pMgmt->sNodeDBTable[*puNodeIndex].wEnQueueCnt = 0;
742 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Create node index = %d\n", ii);
749 * Routine Description:
750 * Remove Node by NodeIndex
753 * Return Value:
754 * None
758 void BSSvRemoveOneNode(void *hDeviceContext, unsigned int uNodeIndex)
761 PSDevice pDevice = (PSDevice)hDeviceContext;
762 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
763 BYTE byMask[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
764 struct sk_buff *skb;
767 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[uNodeIndex].sTxPSQueue)) != NULL)
768 dev_kfree_skb(skb);
769 // clear context
770 memset(&pMgmt->sNodeDBTable[uNodeIndex], 0, sizeof(KnownNodeDB));
771 // clear tx bit map
772 pMgmt->abyPSTxMap[pMgmt->sNodeDBTable[uNodeIndex].wAID >> 3] &= ~byMask[pMgmt->sNodeDBTable[uNodeIndex].wAID & 7];
776 * Routine Description:
777 * Update AP Node content in Index 0 of KnownNodeDB
780 * Return Value:
781 * None
785 void BSSvUpdateAPNode(void *hDeviceContext,
786 PWORD pwCapInfo,
787 PWLAN_IE_SUPP_RATES pSuppRates,
788 PWLAN_IE_SUPP_RATES pExtSuppRates)
790 PSDevice pDevice = (PSDevice)hDeviceContext;
791 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
792 unsigned int uRateLen = WLAN_RATES_MAXLEN;
794 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
796 pMgmt->sNodeDBTable[0].bActive = TRUE;
797 if (pDevice->byBBType == BB_TYPE_11B) {
798 uRateLen = WLAN_RATES_MAXLEN_11B;
800 pMgmt->abyCurrSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pSuppRates,
801 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
802 uRateLen);
803 pMgmt->abyCurrExtSuppRates[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES)pExtSuppRates,
804 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
805 uRateLen);
806 RATEvParseMaxRate((void *) pDevice,
807 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
808 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
809 TRUE,
810 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
811 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
812 &(pMgmt->sNodeDBTable[0].wSuppRate),
813 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
814 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
816 memcpy(pMgmt->sNodeDBTable[0].abyMACAddr, pMgmt->abyCurrBSSID, WLAN_ADDR_LEN);
817 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxSuppRate;
818 pMgmt->sNodeDBTable[0].bShortPreamble = WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo);
819 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
820 // Auto rate fallback function initiation.
821 // RATEbInit(pDevice);
822 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"pMgmt->sNodeDBTable[0].wTxDataRate = %d \n", pMgmt->sNodeDBTable[0].wTxDataRate);
828 * Routine Description:
829 * Add Multicast Node content in Index 0 of KnownNodeDB
832 * Return Value:
833 * None
837 void BSSvAddMulticastNode(void *hDeviceContext)
839 PSDevice pDevice = (PSDevice)hDeviceContext;
840 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
842 if (!pDevice->bEnableHostWEP)
843 memset(&pMgmt->sNodeDBTable[0], 0, sizeof(KnownNodeDB));
844 memset(pMgmt->sNodeDBTable[0].abyMACAddr, 0xff, WLAN_ADDR_LEN);
845 pMgmt->sNodeDBTable[0].bActive = TRUE;
846 pMgmt->sNodeDBTable[0].bPSEnable = FALSE;
847 skb_queue_head_init(&pMgmt->sNodeDBTable[0].sTxPSQueue);
848 RATEvParseMaxRate((void *) pDevice,
849 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrSuppRates,
850 (PWLAN_IE_SUPP_RATES)pMgmt->abyCurrExtSuppRates,
851 TRUE,
852 &(pMgmt->sNodeDBTable[0].wMaxBasicRate),
853 &(pMgmt->sNodeDBTable[0].wMaxSuppRate),
854 &(pMgmt->sNodeDBTable[0].wSuppRate),
855 &(pMgmt->sNodeDBTable[0].byTopCCKBasicRate),
856 &(pMgmt->sNodeDBTable[0].byTopOFDMBasicRate)
858 pMgmt->sNodeDBTable[0].wTxDataRate = pMgmt->sNodeDBTable[0].wMaxBasicRate;
859 pMgmt->sNodeDBTable[0].uRatePollTimeout = FALLBACK_POLL_SECOND;
865 * Routine Description:
868 * Second call back function to update Node DB info & AP link status
871 * Return Value:
872 * none.
876 void BSSvSecondCallBack(void *hDeviceContext)
878 PSDevice pDevice = (PSDevice)hDeviceContext;
879 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
880 unsigned int ii;
881 PWLAN_IE_SSID pItemSSID, pCurrSSID;
882 unsigned int uSleepySTACnt = 0;
883 unsigned int uNonShortSlotSTACnt = 0;
884 unsigned int uLongPreambleSTACnt = 0;
885 viawget_wpa_header *wpahdr;
887 spin_lock_irq(&pDevice->lock);
889 pDevice->uAssocCount = 0;
891 //Power Saving Mode Tx Burst
892 if ( pDevice->bEnablePSMode == TRUE ) {
893 pDevice->ulPSModeWaitTx++;
894 if ( pDevice->ulPSModeWaitTx >= 2 ) {
895 pDevice->ulPSModeWaitTx = 0;
896 pDevice->bPSModeTxBurst = FALSE;
900 pDevice->byERPFlag &=
901 ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
903 if (pDevice->wUseProtectCntDown > 0) {
904 pDevice->wUseProtectCntDown --;
906 else {
907 // disable protect mode
908 pDevice->byERPFlag &= ~(WLAN_SET_ERP_USE_PROTECTION(1));
911 if(pDevice->byReAssocCount > 0) {
912 pDevice->byReAssocCount++;
913 if((pDevice->byReAssocCount > 10) && (pDevice->bLinkPass != TRUE)) { //10 sec timeout
914 printk("Re-association timeout!!!\n");
915 pDevice->byReAssocCount = 0;
916 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
917 // if(pDevice->bWPASuppWextEnabled == TRUE)
919 union iwreq_data wrqu;
920 memset(&wrqu, 0, sizeof (wrqu));
921 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
922 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
923 wireless_send_event(pDevice->dev, SIOCGIWAP, &wrqu, NULL);
925 #endif
927 else if(pDevice->bLinkPass == TRUE)
928 pDevice->byReAssocCount = 0;
931 if((pMgmt->eCurrState!=WMAC_STATE_ASSOC) &&
932 (pMgmt->eLastState==WMAC_STATE_ASSOC))
934 union iwreq_data wrqu;
935 memset(&wrqu, 0, sizeof(wrqu));
936 wrqu.data.flags = RT_DISCONNECTED_EVENT_FLAG;
937 wireless_send_event(pDevice->dev, IWEVCUSTOM, &wrqu, NULL);
939 pMgmt->eLastState = pMgmt->eCurrState ;
941 s_uCalculateLinkQual((void *)pDevice);
943 for (ii = 0; ii < (MAX_NODE_NUM + 1); ii++) {
945 if (pMgmt->sNodeDBTable[ii].bActive) {
946 // Increase in-activity counter
947 pMgmt->sNodeDBTable[ii].uInActiveCount++;
949 if (ii > 0) {
950 if (pMgmt->sNodeDBTable[ii].uInActiveCount > MAX_INACTIVE_COUNT) {
951 BSSvRemoveOneNode(pDevice, ii);
952 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO
953 "Inactive timeout [%d] sec, STA index = [%d] remove\n", MAX_INACTIVE_COUNT, ii);
954 continue;
957 if (pMgmt->sNodeDBTable[ii].eNodeState >= NODE_ASSOC) {
959 pDevice->uAssocCount++;
961 // check if Non ERP exist
962 if (pMgmt->sNodeDBTable[ii].uInActiveCount < ERP_RECOVER_COUNT) {
963 if (!pMgmt->sNodeDBTable[ii].bShortPreamble) {
964 pDevice->byERPFlag |= WLAN_SET_ERP_BARKER_MODE(1);
965 uLongPreambleSTACnt ++;
967 if (!pMgmt->sNodeDBTable[ii].bERPExist) {
968 pDevice->byERPFlag |= WLAN_SET_ERP_NONERP_PRESENT(1);
969 pDevice->byERPFlag |= WLAN_SET_ERP_USE_PROTECTION(1);
971 if (!pMgmt->sNodeDBTable[ii].bShortSlotTime)
972 uNonShortSlotSTACnt++;
976 // check if any STA in PS mode
977 if (pMgmt->sNodeDBTable[ii].bPSEnable)
978 uSleepySTACnt++;
983 // Rate fallback check
984 if (!pDevice->bFixRate) {
985 if (ii > 0) {
986 // ii = 0 for multicast node (AP & Adhoc)
987 RATEvTxRateFallBack((void *)pDevice,
988 &(pMgmt->sNodeDBTable[ii]));
990 else {
991 // ii = 0 reserved for unicast AP node (Infra STA)
992 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)
993 RATEvTxRateFallBack((void *)pDevice,
994 &(pMgmt->sNodeDBTable[ii]));
999 // check if pending PS queue
1000 if (pMgmt->sNodeDBTable[ii].wEnQueueCnt != 0) {
1001 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Index= %d, Queue = %d pending \n",
1002 ii, pMgmt->sNodeDBTable[ii].wEnQueueCnt);
1003 if ((ii >0) && (pMgmt->sNodeDBTable[ii].wEnQueueCnt > 15)) {
1004 BSSvRemoveOneNode(pDevice, ii);
1005 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Pending many queues PS STA Index = %d remove \n", ii);
1006 continue;
1014 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) && (pDevice->byBBType == BB_TYPE_11G)) {
1016 // on/off protect mode
1017 if (WLAN_GET_ERP_USE_PROTECTION(pDevice->byERPFlag)) {
1018 if (!pDevice->bProtectMode) {
1019 MACvEnableProtectMD(pDevice);
1020 pDevice->bProtectMode = TRUE;
1023 else {
1024 if (pDevice->bProtectMode) {
1025 MACvDisableProtectMD(pDevice);
1026 pDevice->bProtectMode = FALSE;
1029 // on/off short slot time
1031 if (uNonShortSlotSTACnt > 0) {
1032 if (pDevice->bShortSlotTime) {
1033 pDevice->bShortSlotTime = FALSE;
1034 BBvSetShortSlotTime(pDevice);
1035 vUpdateIFS((void *)pDevice);
1038 else {
1039 if (!pDevice->bShortSlotTime) {
1040 pDevice->bShortSlotTime = TRUE;
1041 BBvSetShortSlotTime(pDevice);
1042 vUpdateIFS((void *)pDevice);
1046 // on/off barker long preamble mode
1048 if (uLongPreambleSTACnt > 0) {
1049 if (!pDevice->bBarkerPreambleMd) {
1050 MACvEnableBarkerPreambleMd(pDevice);
1051 pDevice->bBarkerPreambleMd = TRUE;
1054 else {
1055 if (pDevice->bBarkerPreambleMd) {
1056 MACvDisableBarkerPreambleMd(pDevice);
1057 pDevice->bBarkerPreambleMd = FALSE;
1064 // Check if any STA in PS mode, enable DTIM multicast deliver
1065 if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
1066 if (uSleepySTACnt > 0)
1067 pMgmt->sNodeDBTable[0].bPSEnable = TRUE;
1068 else
1069 pMgmt->sNodeDBTable[0].bPSEnable = FALSE;
1072 pItemSSID = (PWLAN_IE_SSID)pMgmt->abyDesireSSID;
1073 pCurrSSID = (PWLAN_IE_SSID)pMgmt->abyCurrSSID;
1075 if ((pMgmt->eCurrMode == WMAC_MODE_STANDBY) ||
1076 (pMgmt->eCurrMode == WMAC_MODE_ESS_STA)) {
1078 if (pMgmt->sNodeDBTable[0].bActive) { // Assoc with BSS
1080 if (pDevice->bUpdateBBVGA) {
1081 /* s_vCheckSensitivity((void *) pDevice); */
1082 s_vCheckPreEDThreshold((void *) pDevice);
1085 if ((pMgmt->sNodeDBTable[0].uInActiveCount >= (LOST_BEACON_COUNT/2)) &&
1086 (pDevice->byBBVGACurrent != pDevice->abyBBVGA[0]) ) {
1087 pDevice->byBBVGANew = pDevice->abyBBVGA[0];
1088 bScheduleCommand((void *) pDevice,
1089 WLAN_CMD_CHANGE_BBSENSITIVITY,
1090 NULL);
1093 if (pMgmt->sNodeDBTable[0].uInActiveCount >= LOST_BEACON_COUNT) {
1094 pMgmt->sNodeDBTable[0].bActive = FALSE;
1095 pMgmt->eCurrMode = WMAC_MODE_STANDBY;
1096 pMgmt->eCurrState = WMAC_STATE_IDLE;
1097 netif_stop_queue(pDevice->dev);
1098 pDevice->bLinkPass = FALSE;
1099 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
1100 pDevice->bRoaming = TRUE;
1101 pDevice->bIsRoaming = FALSE;
1103 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost AP beacon [%d] sec, disconnected !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1104 /* let wpa supplicant know AP may disconnect */
1105 if ((pDevice->bWPADEVUp) && (pDevice->skb != NULL)) {
1106 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1107 wpahdr->type = VIAWGET_DISASSOC_MSG;
1108 wpahdr->resp_ie_len = 0;
1109 wpahdr->req_ie_len = 0;
1110 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1111 pDevice->skb->dev = pDevice->wpadev;
1112 skb_reset_mac_header(pDevice->skb);
1113 pDevice->skb->pkt_type = PACKET_HOST;
1114 pDevice->skb->protocol = htons(ETH_P_802_2);
1115 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1116 netif_rx(pDevice->skb);
1117 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1119 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1121 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);
1127 #endif
1130 else if (pItemSSID->len != 0) {
1131 //Davidwang
1132 if ((pDevice->bEnableRoaming == TRUE)&&(!(pMgmt->Cisco_cckm))) {
1133 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bRoaming %d, !\n", pDevice->bRoaming );
1134 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "bIsRoaming %d, !\n", pDevice->bIsRoaming );
1135 if ((pDevice->bRoaming == TRUE)&&(pDevice->bIsRoaming == TRUE)){
1136 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Fast Roaming ...\n");
1137 BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass);
1138 bScheduleCommand((void *) pDevice,
1139 WLAN_CMD_BSSID_SCAN,
1140 pMgmt->abyDesireSSID);
1141 bScheduleCommand((void *) pDevice,
1142 WLAN_CMD_SSID,
1143 pMgmt->abyDesireSSID);
1144 pDevice->uAutoReConnectTime = 0;
1145 pDevice->uIsroamingTime = 0;
1146 pDevice->bRoaming = FALSE;
1148 wpahdr = (viawget_wpa_header *)pDevice->skb->data;
1149 wpahdr->type = VIAWGET_CCKM_ROAM_MSG;
1150 wpahdr->resp_ie_len = 0;
1151 wpahdr->req_ie_len = 0;
1152 skb_put(pDevice->skb, sizeof(viawget_wpa_header));
1153 pDevice->skb->dev = pDevice->wpadev;
1154 skb_reset_mac_header(pDevice->skb);
1155 pDevice->skb->pkt_type = PACKET_HOST;
1156 pDevice->skb->protocol = htons(ETH_P_802_2);
1157 memset(pDevice->skb->cb, 0, sizeof(pDevice->skb->cb));
1158 netif_rx(pDevice->skb);
1159 pDevice->skb = dev_alloc_skb((int)pDevice->rx_buf_sz);
1162 else if ((pDevice->bRoaming == FALSE)&&(pDevice->bIsRoaming == TRUE)) {
1163 pDevice->uIsroamingTime++;
1164 if (pDevice->uIsroamingTime >= 20)
1165 pDevice->bIsRoaming = FALSE;
1169 else {
1170 if (pDevice->uAutoReConnectTime < 10) {
1171 pDevice->uAutoReConnectTime++;
1172 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1173 //network manager support need not do Roaming scan???
1174 if(pDevice->bWPASuppWextEnabled ==TRUE)
1175 pDevice->uAutoReConnectTime = 0;
1176 #endif
1178 else {
1179 //mike use old encryption status for wpa reauthen
1180 if(pDevice->bWPADEVUp)
1181 pDevice->eEncryptionStatus = pDevice->eOldEncryptionStatus;
1183 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Roaming ...\n");
1184 BSSvClearBSSList((void *) pDevice, pDevice->bLinkPass);
1185 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1186 bScheduleCommand((void *) pDevice,
1187 WLAN_CMD_BSSID_SCAN,
1188 pMgmt->abyDesireSSID);
1189 bScheduleCommand((void *) pDevice,
1190 WLAN_CMD_SSID,
1191 pMgmt->abyDesireSSID);
1192 pDevice->uAutoReConnectTime = 0;
1198 if (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) {
1199 // if adhoc started which essid is NULL string, rescanning.
1200 if ((pMgmt->eCurrState == WMAC_STATE_STARTED) && (pCurrSSID->len == 0)) {
1201 if (pDevice->uAutoReConnectTime < 10) {
1202 pDevice->uAutoReConnectTime++;
1204 else {
1205 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Adhoc re-scanning ...\n");
1206 pMgmt->eScanType = WMAC_SCAN_ACTIVE;
1207 bScheduleCommand((void *) pDevice, WLAN_CMD_BSSID_SCAN, NULL);
1208 bScheduleCommand((void *) pDevice, WLAN_CMD_SSID, NULL);
1209 pDevice->uAutoReConnectTime = 0;
1212 if (pMgmt->eCurrState == WMAC_STATE_JOINTED) {
1214 if (pDevice->bUpdateBBVGA) {
1215 /* s_vCheckSensitivity((void *) pDevice); */
1216 s_vCheckPreEDThreshold((void *) pDevice);
1218 if (pMgmt->sNodeDBTable[0].uInActiveCount >=ADHOC_LOST_BEACON_COUNT) {
1219 DBG_PRT(MSG_LEVEL_NOTICE, KERN_INFO "Lost other STA beacon [%d] sec, started !\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1220 pMgmt->sNodeDBTable[0].uInActiveCount = 0;
1221 pMgmt->eCurrState = WMAC_STATE_STARTED;
1222 netif_stop_queue(pDevice->dev);
1223 pDevice->bLinkPass = FALSE;
1224 ControlvMaskByte(pDevice,MESSAGE_REQUEST_MACREG,MAC_REG_PAPEDELAY,LEDSTS_STS,LEDSTS_SLOW);
1229 if (pDevice->bLinkPass == TRUE) {
1230 if (netif_queue_stopped(pDevice->dev))
1231 netif_wake_queue(pDevice->dev);
1234 spin_unlock_irq(&pDevice->lock);
1236 pMgmt->sTimerSecondCallback.expires = RUN_AT(HZ);
1237 add_timer(&pMgmt->sTimerSecondCallback);
1242 * Routine Description:
1245 * Update Tx attemps, Tx failure counter in Node DB
1248 * Return Value:
1249 * none.
1253 void BSSvUpdateNodeTxCounter(void *hDeviceContext,
1254 PSStatCounter pStatistic,
1255 BYTE byTSR,
1256 BYTE byPktNO)
1258 PSDevice pDevice = (PSDevice)hDeviceContext;
1259 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1260 unsigned int uNodeIndex = 0;
1261 BYTE byTxRetry;
1262 WORD wRate;
1263 WORD wFallBackRate = RATE_1M;
1264 BYTE byFallBack;
1265 unsigned int ii;
1266 PBYTE pbyDestAddr;
1267 BYTE byPktNum;
1268 WORD wFIFOCtl;
1270 byPktNum = (byPktNO & 0x0F) >> 4;
1271 byTxRetry = (byTSR & 0xF0) >> 4;
1272 wRate = (WORD) (byPktNO & 0xF0) >> 4;
1273 wFIFOCtl = pStatistic->abyTxPktInfo[byPktNum].wFIFOCtl;
1274 pbyDestAddr = (PBYTE) &( pStatistic->abyTxPktInfo[byPktNum].abyDestAddr[0]);
1276 if (wFIFOCtl & FIFOCTL_AUTO_FB_0) {
1277 byFallBack = AUTO_FB_0;
1278 } else if (wFIFOCtl & FIFOCTL_AUTO_FB_1) {
1279 byFallBack = AUTO_FB_1;
1280 } else {
1281 byFallBack = AUTO_FB_NONE;
1284 // Only Unicast using support rates
1285 if (wFIFOCtl & FIFOCTL_NEEDACK) {
1286 if (pMgmt->eCurrMode == WMAC_MODE_ESS_STA) {
1287 pMgmt->sNodeDBTable[0].uTxAttempts += 1;
1288 if ( !(byTSR & (TSR_TMO | TSR_RETRYTMO))) {
1289 // transmit success, TxAttempts at least plus one
1290 pMgmt->sNodeDBTable[0].uTxOk[MAX_RATE]++;
1291 if ( (byFallBack == AUTO_FB_NONE) ||
1292 (wRate < RATE_18M) ) {
1293 wFallBackRate = wRate;
1294 } else if (byFallBack == AUTO_FB_0) {
1295 if (byTxRetry < 5)
1296 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1297 else
1298 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1299 } else if (byFallBack == AUTO_FB_1) {
1300 if (byTxRetry < 5)
1301 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1302 else
1303 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1305 pMgmt->sNodeDBTable[0].uTxOk[wFallBackRate]++;
1306 } else {
1307 pMgmt->sNodeDBTable[0].uTxFailures ++;
1309 pMgmt->sNodeDBTable[0].uTxRetry += byTxRetry;
1310 if (byTxRetry != 0) {
1311 pMgmt->sNodeDBTable[0].uTxFail[MAX_RATE]+=byTxRetry;
1312 if ( (byFallBack == AUTO_FB_NONE) ||
1313 (wRate < RATE_18M) ) {
1314 pMgmt->sNodeDBTable[0].uTxFail[wRate]+=byTxRetry;
1315 } else if (byFallBack == AUTO_FB_0) {
1316 for (ii = 0; ii < byTxRetry; ii++) {
1317 if (ii < 5)
1318 wFallBackRate =
1319 awHWRetry0[wRate-RATE_18M][ii];
1320 else
1321 wFallBackRate =
1322 awHWRetry0[wRate-RATE_18M][4];
1323 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1325 } else if (byFallBack == AUTO_FB_1) {
1326 for (ii = 0; ii < byTxRetry; ii++) {
1327 if (ii < 5)
1328 wFallBackRate =
1329 awHWRetry1[wRate-RATE_18M][ii];
1330 else
1331 wFallBackRate =
1332 awHWRetry1[wRate-RATE_18M][4];
1333 pMgmt->sNodeDBTable[0].uTxFail[wFallBackRate]++;
1339 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) ||
1340 (pMgmt->eCurrMode == WMAC_MODE_ESS_AP)) {
1342 if (BSSbIsSTAInNodeDB((void *) pDevice,
1343 pbyDestAddr,
1344 &uNodeIndex)) {
1345 pMgmt->sNodeDBTable[uNodeIndex].uTxAttempts += 1;
1346 if ( !(byTSR & (TSR_TMO | TSR_RETRYTMO))) {
1347 // transmit success, TxAttempts at least plus one
1348 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[MAX_RATE]++;
1349 if ( (byFallBack == AUTO_FB_NONE) ||
1350 (wRate < RATE_18M) ) {
1351 wFallBackRate = wRate;
1352 } else if (byFallBack == AUTO_FB_0) {
1353 if (byTxRetry < 5)
1354 wFallBackRate = awHWRetry0[wRate-RATE_18M][byTxRetry];
1355 else
1356 wFallBackRate = awHWRetry0[wRate-RATE_18M][4];
1357 } else if (byFallBack == AUTO_FB_1) {
1358 if (byTxRetry < 5)
1359 wFallBackRate = awHWRetry1[wRate-RATE_18M][byTxRetry];
1360 else
1361 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1363 pMgmt->sNodeDBTable[uNodeIndex].uTxOk[wFallBackRate]++;
1364 } else {
1365 pMgmt->sNodeDBTable[uNodeIndex].uTxFailures ++;
1367 pMgmt->sNodeDBTable[uNodeIndex].uTxRetry += byTxRetry;
1368 if (byTxRetry != 0) {
1369 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[MAX_RATE]+=byTxRetry;
1370 if ( (byFallBack == AUTO_FB_NONE) ||
1371 (wRate < RATE_18M) ) {
1372 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wRate]+=byTxRetry;
1373 } else if (byFallBack == AUTO_FB_0) {
1374 for (ii = 0; ii < byTxRetry; ii++) {
1375 if (ii < 5)
1376 wFallBackRate =
1377 awHWRetry0[wRate-RATE_18M][ii];
1378 else
1379 wFallBackRate =
1380 awHWRetry0[wRate-RATE_18M][4];
1381 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1383 } else if (byFallBack == AUTO_FB_1) {
1384 for (ii = 0; ii < byTxRetry; ii++) {
1385 if (ii < 5)
1386 wFallBackRate = awHWRetry1[wRate-RATE_18M][ii];
1387 else
1388 wFallBackRate = awHWRetry1[wRate-RATE_18M][4];
1389 pMgmt->sNodeDBTable[uNodeIndex].uTxFail[wFallBackRate]++;
1400 * Routine Description:
1401 * Clear Nodes & skb in DB Table
1404 * Parameters:
1405 * In:
1406 * hDeviceContext - The adapter context.
1407 * uStartIndex - starting index
1408 * Out:
1409 * none
1411 * Return Value:
1412 * None.
1416 void BSSvClearNodeDBTable(void *hDeviceContext,
1417 unsigned int uStartIndex)
1419 PSDevice pDevice = (PSDevice)hDeviceContext;
1420 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1421 struct sk_buff *skb;
1422 unsigned int ii;
1424 for (ii = uStartIndex; ii < (MAX_NODE_NUM + 1); ii++) {
1425 if (pMgmt->sNodeDBTable[ii].bActive) {
1426 // check if sTxPSQueue has been initial
1427 if (pMgmt->sNodeDBTable[ii].sTxPSQueue.next != NULL) {
1428 while ((skb = skb_dequeue(&pMgmt->sNodeDBTable[ii].sTxPSQueue)) != NULL){
1429 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "PS skb != NULL %d\n", ii);
1430 dev_kfree_skb(skb);
1433 memset(&pMgmt->sNodeDBTable[ii], 0, sizeof(KnownNodeDB));
1438 void s_vCheckSensitivity(void *hDeviceContext)
1440 PSDevice pDevice = (PSDevice)hDeviceContext;
1441 PKnownBSS pBSSList = NULL;
1442 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1443 int ii;
1445 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1446 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1447 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1448 if (pBSSList != NULL) {
1449 /* Update BB register if RSSI is too strong */
1450 signed long LocalldBmAverage = 0;
1451 signed long uNumofdBm = 0;
1452 for (ii = 0; ii < RSSI_STAT_COUNT; ii++) {
1453 if (pBSSList->ldBmAverage[ii] != 0) {
1454 uNumofdBm ++;
1455 LocalldBmAverage += pBSSList->ldBmAverage[ii];
1458 if (uNumofdBm > 0) {
1459 LocalldBmAverage = LocalldBmAverage/uNumofdBm;
1460 for (ii=0;ii<BB_VGA_LEVEL;ii++) {
1461 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"LocalldBmAverage:%ld, %ld %02x\n", LocalldBmAverage, pDevice->ldBmThreshold[ii], pDevice->abyBBVGA[ii]);
1462 if (LocalldBmAverage < pDevice->ldBmThreshold[ii]) {
1463 pDevice->byBBVGANew = pDevice->abyBBVGA[ii];
1464 break;
1467 if (pDevice->byBBVGANew != pDevice->byBBVGACurrent) {
1468 pDevice->uBBVGADiffCount++;
1469 if (pDevice->uBBVGADiffCount >= BB_VGA_CHANGE_THRESHOLD)
1470 bScheduleCommand((void *) pDevice,
1471 WLAN_CMD_CHANGE_BBSENSITIVITY,
1472 NULL);
1473 } else {
1474 pDevice->uBBVGADiffCount = 0;
1481 void s_uCalculateLinkQual(void *hDeviceContext)
1483 PSDevice pDevice = (PSDevice)hDeviceContext;
1484 unsigned long TxOkRatio, TxCnt;
1485 unsigned long RxOkRatio, RxCnt;
1486 unsigned long RssiRatio;
1487 long ldBm;
1489 TxCnt = pDevice->scStatistic.TxNoRetryOkCount +
1490 pDevice->scStatistic.TxRetryOkCount +
1491 pDevice->scStatistic.TxFailCount;
1492 RxCnt = pDevice->scStatistic.RxFcsErrCnt +
1493 pDevice->scStatistic.RxOkCnt;
1494 TxOkRatio = (TxCnt < 6) ? 4000:((pDevice->scStatistic.TxNoRetryOkCount * 4000) / TxCnt);
1495 RxOkRatio = (RxCnt < 6) ? 2000:((pDevice->scStatistic.RxOkCnt * 2000) / RxCnt);
1496 //decide link quality
1497 if(pDevice->bLinkPass !=TRUE)
1499 pDevice->scStatistic.LinkQuality = 0;
1500 pDevice->scStatistic.SignalStren = 0;
1502 else
1504 RFvRSSITodBm(pDevice, (BYTE)(pDevice->uCurrRSSI), &ldBm);
1505 if(-ldBm < 50) {
1506 RssiRatio = 4000;
1508 else if(-ldBm > 90) {
1509 RssiRatio = 0;
1511 else {
1512 RssiRatio = (40-(-ldBm-50))*4000/40;
1514 pDevice->scStatistic.SignalStren = RssiRatio/40;
1515 pDevice->scStatistic.LinkQuality = (RssiRatio+TxOkRatio+RxOkRatio)/100;
1517 pDevice->scStatistic.RxFcsErrCnt = 0;
1518 pDevice->scStatistic.RxOkCnt = 0;
1519 pDevice->scStatistic.TxFailCount = 0;
1520 pDevice->scStatistic.TxNoRetryOkCount = 0;
1521 pDevice->scStatistic.TxRetryOkCount = 0;
1524 void BSSvClearAnyBSSJoinRecord(void *hDeviceContext)
1526 PSDevice pDevice = (PSDevice)hDeviceContext;
1527 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1528 unsigned int ii;
1530 for (ii = 0; ii < MAX_BSS_NUM; ii++)
1531 pMgmt->sBSSList[ii].bSelected = FALSE;
1534 void s_vCheckPreEDThreshold(void *hDeviceContext)
1536 PSDevice pDevice = (PSDevice)hDeviceContext;
1537 PKnownBSS pBSSList = NULL;
1538 PSMgmtObject pMgmt = &(pDevice->sMgmtObj);
1540 if ((pMgmt->eCurrState == WMAC_STATE_ASSOC) ||
1541 ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) && (pMgmt->eCurrState == WMAC_STATE_JOINTED))) {
1542 pBSSList = BSSpAddrIsInBSSList(pDevice, pMgmt->abyCurrBSSID, (PWLAN_IE_SSID)pMgmt->abyCurrSSID);
1543 if (pBSSList != NULL) {
1544 pDevice->byBBPreEDRSSI = (BYTE) (~(pBSSList->ldBmAverRange) + 1);
1545 BBvUpdatePreEDThreshold(pDevice, FALSE);