2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: Handles the Basic Service Set & Node Database functions
24 * BSSpSearchBSSList - Search known BSS list for Desire SSID or BSSID
25 * BSSvClearBSSList - Clear BSS List
26 * BSSbInsertToBSSList - Insert a BSS set into known BSS list
27 * BSSbUpdateToBSSList - Update BSS set in known BSS list
28 * BSSDBbIsSTAInNodeDB - Search Node DB table to find the index of matched DstAddr
29 * BSSvCreateOneNode - Allocate an Node for Node DB
30 * BSSvUpdateAPNode - Update AP Node content in Index 0 of KnownNodeDB
31 * BSSvSecondCallBack - One second timer callback function to update Node DB info & AP link status
32 * BSSvUpdateNodeTxCounter - Update Tx attemps, Tx failure counter in Node DB for auto-fall back rate control
61 /*--------------------- Static Definitions -------------------------*/
66 /*--------------------- Static Classes ----------------------------*/
68 /*--------------------- Static Variables --------------------------*/
69 static int msglevel
=MSG_LEVEL_INFO
;
70 //static int msglevel =MSG_LEVEL_DEBUG;
74 const WORD awHWRetry0
[5][5] = {
75 {RATE_18M
, RATE_18M
, RATE_12M
, RATE_12M
, RATE_12M
},
76 {RATE_24M
, RATE_24M
, RATE_18M
, RATE_12M
, RATE_12M
},
77 {RATE_36M
, RATE_36M
, RATE_24M
, RATE_18M
, RATE_18M
},
78 {RATE_48M
, RATE_48M
, RATE_36M
, RATE_24M
, RATE_24M
},
79 {RATE_54M
, RATE_54M
, RATE_48M
, RATE_36M
, RATE_36M
}
81 const WORD awHWRetry1
[5][5] = {
82 {RATE_18M
, RATE_18M
, RATE_12M
, RATE_6M
, RATE_6M
},
83 {RATE_24M
, RATE_24M
, RATE_18M
, RATE_6M
, RATE_6M
},
84 {RATE_36M
, RATE_36M
, RATE_24M
, RATE_12M
, RATE_12M
},
85 {RATE_48M
, RATE_48M
, RATE_24M
, RATE_12M
, RATE_12M
},
86 {RATE_54M
, RATE_54M
, RATE_36M
, RATE_18M
, RATE_18M
}
91 /*--------------------- Static Functions --------------------------*/
93 VOID
s_vCheckSensitivity(
94 IN HANDLE hDeviceContext
98 VOID
s_uCalculateLinkQual(
99 IN HANDLE hDeviceContext
104 VOID
s_vCheckPreEDThreshold(
105 IN HANDLE hDeviceContext
107 /*--------------------- Export Variables --------------------------*/
110 /*--------------------- Export Functions --------------------------*/
118 * Routine Description:
119 * Search known BSS list for Desire SSID or BSSID.
122 * PTR to KnownBSS or NULL
128 IN HANDLE hDeviceContext
,
129 IN PBYTE pbyDesireBSSID
,
130 IN PBYTE pbyDesireSSID
,
131 IN CARD_PHY_TYPE ePhyType
134 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
135 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
136 PBYTE pbyBSSID
= NULL
;
137 PWLAN_IE_SSID pSSID
= NULL
;
138 PKnownBSS pCurrBSS
= NULL
;
139 PKnownBSS pSelect
= NULL
;
140 BYTE ZeroBSSID
[WLAN_BSSID_LEN
]={0x00,0x00,0x00,0x00,0x00,0x00};
142 // UINT jj = 0; //DavidWang
143 if (pbyDesireBSSID
!= NULL
) {
144 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"BSSpSearchBSSList BSSID[%02X %02X %02X-%02X %02X %02X]\n",
145 *pbyDesireBSSID
,*(pbyDesireBSSID
+1),*(pbyDesireBSSID
+2),
146 *(pbyDesireBSSID
+3),*(pbyDesireBSSID
+4),*(pbyDesireBSSID
+5));
147 if ((!IS_BROADCAST_ADDRESS(pbyDesireBSSID
)) &&
148 (memcmp(pbyDesireBSSID
, ZeroBSSID
, 6)!= 0)){
149 pbyBSSID
= pbyDesireBSSID
;
152 if (pbyDesireSSID
!= NULL
) {
153 if (((PWLAN_IE_SSID
)pbyDesireSSID
)->len
!= 0) {
154 pSSID
= (PWLAN_IE_SSID
) pbyDesireSSID
;
158 if (pbyBSSID
!= NULL
) {
160 for (ii
= 0; ii
<MAX_BSS_NUM
; ii
++) {
161 pCurrBSS
= &(pMgmt
->sBSSList
[ii
]);
162 if(pDevice
->bLinkPass
==FALSE
) pCurrBSS
->bSelected
= FALSE
;
163 if ((pCurrBSS
->bActive
) &&
164 (pCurrBSS
->bSelected
== FALSE
)) {
165 if (IS_ETH_ADDRESS_EQUAL(pCurrBSS
->abyBSSID
, pbyBSSID
)) {
168 if ( !memcmp(pSSID
->abySSID
,
169 ((PWLAN_IE_SSID
)pCurrBSS
->abySSID
)->abySSID
,
171 if ((pMgmt
->eConfigMode
== WMAC_CONFIG_AUTO
) ||
172 ((pMgmt
->eConfigMode
== WMAC_CONFIG_IBSS_STA
) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS
->wCapInfo
)) ||
173 ((pMgmt
->eConfigMode
== WMAC_CONFIG_ESS_STA
) && WLAN_GET_CAP_INFO_ESS(pCurrBSS
->wCapInfo
))
175 pCurrBSS
->bSelected
= TRUE
;
180 if ((pMgmt
->eConfigMode
== WMAC_CONFIG_AUTO
) ||
181 ((pMgmt
->eConfigMode
== WMAC_CONFIG_IBSS_STA
) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS
->wCapInfo
)) ||
182 ((pMgmt
->eConfigMode
== WMAC_CONFIG_ESS_STA
) && WLAN_GET_CAP_INFO_ESS(pCurrBSS
->wCapInfo
))
184 pCurrBSS
->bSelected
= TRUE
;
193 for (ii
= 0; ii
<MAX_BSS_NUM
; ii
++) {
194 pCurrBSS
= &(pMgmt
->sBSSList
[ii
]);
195 //2007-0721-01<Add>by MikeLiu
196 pCurrBSS
->bSelected
= FALSE
;
197 if (pCurrBSS
->bActive
) {
201 if (! !memcmp(pSSID
->abySSID
,
202 ((PWLAN_IE_SSID
)pCurrBSS
->abySSID
)->abySSID
,
204 (pSSID
->len
!= ((PWLAN_IE_SSID
)pCurrBSS
->abySSID
)->len
)) {
205 // SSID not match skip this BSS
209 if (((pMgmt
->eConfigMode
== WMAC_CONFIG_IBSS_STA
) && WLAN_GET_CAP_INFO_ESS(pCurrBSS
->wCapInfo
)) ||
210 ((pMgmt
->eConfigMode
== WMAC_CONFIG_ESS_STA
) && WLAN_GET_CAP_INFO_IBSS(pCurrBSS
->wCapInfo
))
212 // Type not match skip this BSS
213 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"BSS type mismatch.... Config[%d] BSS[0x%04x]\n", pMgmt
->eConfigMode
, pCurrBSS
->wCapInfo
);
217 if (ePhyType
!= PHY_TYPE_AUTO
) {
218 if (((ePhyType
== PHY_TYPE_11A
) && (PHY_TYPE_11A
!= pCurrBSS
->eNetworkTypeInUse
)) ||
219 ((ePhyType
!= PHY_TYPE_11A
) && (PHY_TYPE_11A
== pCurrBSS
->eNetworkTypeInUse
))) {
220 // PhyType not match skip this BSS
221 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Physical type mismatch.... ePhyType[%d] BSS[%d]\n", ePhyType
, pCurrBSS
->eNetworkTypeInUse
);
226 if (pMgmt->eAuthenMode < WMAC_AUTH_WPA) {
227 if (pCurrBSS->bWPAValid == TRUE) {
228 // WPA AP will reject connection of station without WPA enable.
231 } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
232 (pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK)) {
233 if (pCurrBSS->bWPAValid == FALSE) {
234 // station with WPA enable can't join NonWPA AP.
237 } else if ((pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
238 (pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
239 if (pCurrBSS->bWPA2Valid == FALSE) {
240 // station with WPA2 enable can't join NonWPA2 AP.
245 if (pSelect
== NULL
) {
248 // compare RSSI, select signal strong one
249 if (pCurrBSS
->uRSSI
< pSelect
->uRSSI
) {
255 if (pSelect
!= NULL
) {
256 pSelect
->bSelected
= TRUE
;
258 if (pDevice->bRoaming == FALSE) {
259 // Einsn Add @20070907
260 memset(pbyDesireSSID, 0, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1);
261 memcpy(pbyDesireSSID,pCurrBSS->abySSID,WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN + 1) ;
274 * Routine Description:
285 IN HANDLE hDeviceContext
,
286 IN BOOL bKeepCurrBSSID
289 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
290 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
293 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
294 if (bKeepCurrBSSID
) {
295 if (pMgmt
->sBSSList
[ii
].bActive
&&
296 IS_ETH_ADDRESS_EQUAL(pMgmt
->sBSSList
[ii
].abyBSSID
, pMgmt
->abyCurrBSSID
)) {
297 // bKeepCurrBSSID = FALSE;
302 if ((pMgmt
->sBSSList
[ii
].bActive
) && (pMgmt
->sBSSList
[ii
].uClearCount
< BSS_CLEAR_COUNT
)) {
303 pMgmt
->sBSSList
[ii
].uClearCount
++;
307 pMgmt
->sBSSList
[ii
].bActive
= FALSE
;
308 memset(&pMgmt
->sBSSList
[ii
], 0, sizeof(KnownBSS
));
310 BSSvClearAnyBSSJoinRecord(pDevice
);
319 * Routine Description:
320 * search BSS list by BSSID & SSID if matched
328 IN HANDLE hDeviceContext
,
330 IN PWLAN_IE_SSID pSSID
333 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
334 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
335 PKnownBSS pBSSList
= NULL
;
338 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
339 pBSSList
= &(pMgmt
->sBSSList
[ii
]);
340 if (pBSSList
->bActive
) {
341 if (IS_ETH_ADDRESS_EQUAL(pBSSList
->abyBSSID
, abyBSSID
)) {
342 // if (pSSID == NULL)
344 if (pSSID
->len
== ((PWLAN_IE_SSID
)pBSSList
->abySSID
)->len
){
345 if (memcmp(pSSID
->abySSID
,
346 ((PWLAN_IE_SSID
)pBSSList
->abySSID
)->abySSID
,
361 * Routine Description:
362 * Insert a BSS set into known BSS list
370 BSSbInsertToBSSList (
371 IN HANDLE hDeviceContext
,
372 IN PBYTE abyBSSIDAddr
,
373 IN QWORD qwTimestamp
,
374 IN WORD wBeaconInterval
,
376 IN BYTE byCurrChannel
,
377 IN PWLAN_IE_SSID pSSID
,
378 IN PWLAN_IE_SUPP_RATES pSuppRates
,
379 IN PWLAN_IE_SUPP_RATES pExtSuppRates
,
381 IN PWLAN_IE_RSN pRSN
,
382 IN PWLAN_IE_RSN_EXT pRSNWPA
,
383 IN PWLAN_IE_COUNTRY pIE_Country
,
384 IN PWLAN_IE_QUIET pIE_Quiet
,
387 IN HANDLE pRxPacketContext
391 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
392 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
393 PSRxMgmtPacket pRxPacket
= (PSRxMgmtPacket
)pRxPacketContext
;
394 PKnownBSS pBSSList
= NULL
;
396 BOOL bParsingQuiet
= FALSE
;
397 PWLAN_IE_QUIET pQuiet
= NULL
;
401 pBSSList
= (PKnownBSS
)&(pMgmt
->sBSSList
[0]);
403 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
404 pBSSList
= (PKnownBSS
)&(pMgmt
->sBSSList
[ii
]);
405 if (!pBSSList
->bActive
)
409 if (ii
== MAX_BSS_NUM
){
410 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Get free KnowBSS node failed.\n");
414 pBSSList
->bActive
= TRUE
;
415 memcpy( pBSSList
->abyBSSID
, abyBSSIDAddr
, WLAN_BSSID_LEN
);
416 HIDWORD(pBSSList
->qwBSSTimestamp
) = cpu_to_le32(HIDWORD(qwTimestamp
));
417 LODWORD(pBSSList
->qwBSSTimestamp
) = cpu_to_le32(LODWORD(qwTimestamp
));
418 pBSSList
->wBeaconInterval
= cpu_to_le16(wBeaconInterval
);
419 pBSSList
->wCapInfo
= cpu_to_le16(wCapInfo
);
420 pBSSList
->uClearCount
= 0;
422 if (pSSID
->len
> WLAN_SSID_MAXLEN
)
423 pSSID
->len
= WLAN_SSID_MAXLEN
;
424 memcpy( pBSSList
->abySSID
, pSSID
, pSSID
->len
+ WLAN_IEHDR_LEN
);
426 pBSSList
->uChannel
= byCurrChannel
;
428 if (pSuppRates
->len
> WLAN_RATES_MAXLEN
)
429 pSuppRates
->len
= WLAN_RATES_MAXLEN
;
430 memcpy( pBSSList
->abySuppRates
, pSuppRates
, pSuppRates
->len
+ WLAN_IEHDR_LEN
);
432 if (pExtSuppRates
!= NULL
) {
433 if (pExtSuppRates
->len
> WLAN_RATES_MAXLEN
)
434 pExtSuppRates
->len
= WLAN_RATES_MAXLEN
;
435 memcpy(pBSSList
->abyExtSuppRates
, pExtSuppRates
, pExtSuppRates
->len
+ WLAN_IEHDR_LEN
);
436 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"BSSbInsertToBSSList: pExtSuppRates->len = %d\n", pExtSuppRates
->len
);
439 memset(pBSSList
->abyExtSuppRates
, 0, WLAN_IEHDR_LEN
+ WLAN_RATES_MAXLEN
+ 1);
441 pBSSList
->sERP
.byERP
= psERP
->byERP
;
442 pBSSList
->sERP
.bERPExist
= psERP
->bERPExist
;
444 // Check if BSS is 802.11a/b/g
445 if (pBSSList
->uChannel
> CB_MAX_CHANNEL_24G
) {
446 pBSSList
->eNetworkTypeInUse
= PHY_TYPE_11A
;
448 if (pBSSList
->sERP
.bERPExist
== TRUE
) {
449 pBSSList
->eNetworkTypeInUse
= PHY_TYPE_11G
;
451 pBSSList
->eNetworkTypeInUse
= PHY_TYPE_11B
;
455 pBSSList
->byRxRate
= pRxPacket
->byRxRate
;
456 pBSSList
->qwLocalTSF
= pRxPacket
->qwLocalTSF
;
457 pBSSList
->uRSSI
= pRxPacket
->uRSSI
;
458 pBSSList
->bySQ
= pRxPacket
->bySQ
;
460 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
461 (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
)) {
463 if (pBSSList
== pMgmt
->pCurrBSS
) {
464 bParsingQuiet
= TRUE
;
468 WPA_ClearRSN(pBSSList
);
470 if (pRSNWPA
!= NULL
) {
471 UINT uLen
= pRSNWPA
->len
+ 2;
473 if (uLen
<= (uIELength
- (UINT
)(ULONG_PTR
)((PBYTE
)pRSNWPA
- pbyIEs
))) {
474 pBSSList
->wWPALen
= uLen
;
475 memcpy(pBSSList
->byWPAIE
, pRSNWPA
, uLen
);
476 WPA_ParseRSN(pBSSList
, pRSNWPA
);
480 WPA2_ClearRSN(pBSSList
);
483 UINT uLen
= pRSN
->len
+ 2;
484 if (uLen
<= (uIELength
- (UINT
)(ULONG_PTR
)((PBYTE
)pRSN
- pbyIEs
))) {
485 pBSSList
->wRSNLen
= uLen
;
486 memcpy(pBSSList
->byRSNIE
, pRSN
, uLen
);
487 WPA2vParseRSN(pBSSList
, pRSN
);
491 if ((pMgmt
->eAuthenMode
== WMAC_AUTH_WPA2
) || (pBSSList
->bWPA2Valid
== TRUE
)) {
493 PSKeyItem pTransmitKey
= NULL
;
494 BOOL bIs802_1x
= FALSE
;
496 for (ii
= 0; ii
< pBSSList
->wAKMSSAuthCount
; ii
++) {
497 if (pBSSList
->abyAKMSSAuthType
[ii
] == WLAN_11i_AKMSS_802_1X
) {
502 if ((bIs802_1x
== TRUE
) && (pSSID
->len
== ((PWLAN_IE_SSID
)pMgmt
->abyDesireSSID
)->len
) &&
503 ( !memcmp(pSSID
->abySSID
, ((PWLAN_IE_SSID
)pMgmt
->abyDesireSSID
)->abySSID
, pSSID
->len
))) {
505 bAdd_PMKID_Candidate((HANDLE
)pDevice
, pBSSList
->abyBSSID
, &pBSSList
->sRSNCapObj
);
507 if ((pDevice
->bLinkPass
== TRUE
) && (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
)) {
508 if ((KeybGetTransmitKey(&(pDevice
->sKey
), pDevice
->abyBSSID
, PAIRWISE_KEY
, &pTransmitKey
) == TRUE
) ||
509 (KeybGetTransmitKey(&(pDevice
->sKey
), pDevice
->abyBSSID
, GROUP_KEY
, &pTransmitKey
) == TRUE
)) {
510 pDevice
->gsPMKIDCandidate
.StatusType
= Ndis802_11StatusType_PMKID_CandidateList
;
511 pDevice
->gsPMKIDCandidate
.Version
= 1;
519 if (pDevice
->bUpdateBBVGA
) {
520 // Moniter if RSSI is too strong.
521 pBSSList
->byRSSIStatCnt
= 0;
522 RFvRSSITodBm(pDevice
, (BYTE
)(pRxPacket
->uRSSI
), &pBSSList
->ldBmMAX
);
523 pBSSList
->ldBmAverage
[0] = pBSSList
->ldBmMAX
;
524 for (ii
= 1; ii
< RSSI_STAT_COUNT
; ii
++)
525 pBSSList
->ldBmAverage
[ii
] = 0;
528 if ((pIE_Country
!= NULL
) &&
529 (pMgmt
->b11hEnable
== TRUE
)) {
530 CARDvSetCountryInfo(pMgmt
->pAdapter
,
531 pBSSList
->eNetworkTypeInUse
,
535 if ((bParsingQuiet
== TRUE
) && (pIE_Quiet
!= NULL
)) {
536 if ((((PWLAN_IE_QUIET
)pIE_Quiet
)->len
== 8) &&
537 (((PWLAN_IE_QUIET
)pIE_Quiet
)->byQuietCount
!= 0)) {
539 if (pQuiet
== NULL
) {
540 pQuiet
= (PWLAN_IE_QUIET
)pIE_Quiet
;
541 CARDbSetQuiet( pMgmt
->pAdapter
,
543 pQuiet
->byQuietCount
,
544 pQuiet
->byQuietPeriod
,
545 *((PWORD
)pQuiet
->abyQuietDuration
),
546 *((PWORD
)pQuiet
->abyQuietOffset
)
549 pQuiet
= (PWLAN_IE_QUIET
)pIE_Quiet
;
550 CARDbSetQuiet( pMgmt
->pAdapter
,
552 pQuiet
->byQuietCount
,
553 pQuiet
->byQuietPeriod
,
554 *((PWORD
)pQuiet
->abyQuietDuration
),
555 *((PWORD
)pQuiet
->abyQuietOffset
)
561 if ((bParsingQuiet
== TRUE
) &&
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
);
577 * Routine Description:
578 * Update BSS set in known BSS list
584 // TODO: input structure modify
587 BSSbUpdateToBSSList (
588 IN HANDLE hDeviceContext
,
589 IN QWORD qwTimestamp
,
590 IN WORD wBeaconInterval
,
592 IN BYTE byCurrChannel
,
594 IN PWLAN_IE_SSID pSSID
,
595 IN PWLAN_IE_SUPP_RATES pSuppRates
,
596 IN PWLAN_IE_SUPP_RATES pExtSuppRates
,
598 IN PWLAN_IE_RSN pRSN
,
599 IN PWLAN_IE_RSN_EXT pRSNWPA
,
600 IN PWLAN_IE_COUNTRY pIE_Country
,
601 IN PWLAN_IE_QUIET pIE_Quiet
,
602 IN PKnownBSS pBSSList
,
605 IN HANDLE pRxPacketContext
609 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
610 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
611 PSRxMgmtPacket pRxPacket
= (PSRxMgmtPacket
)pRxPacketContext
;
613 BOOL bParsingQuiet
= FALSE
;
614 PWLAN_IE_QUIET pQuiet
= NULL
;
618 if (pBSSList
== NULL
)
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
);
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
;
649 if (pBSSList
->sERP
.bERPExist
== TRUE
) {
650 pBSSList
->eNetworkTypeInUse
= PHY_TYPE_11G
;
652 pBSSList
->eNetworkTypeInUse
= PHY_TYPE_11B
;
656 pBSSList
->byRxRate
= pRxPacket
->byRxRate
;
657 pBSSList
->qwLocalTSF
= pRxPacket
->qwLocalTSF
;
659 pBSSList
->uRSSI
= pRxPacket
->uRSSI
;
660 pBSSList
->bySQ
= pRxPacket
->bySQ
;
662 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) &&
663 (pMgmt
->eCurrState
== WMAC_STATE_ASSOC
)) {
665 if (pBSSList
== pMgmt
->pCurrBSS
) {
666 bParsingQuiet
= TRUE
;
670 WPA_ClearRSN(pBSSList
); //mike update
672 if (pRSNWPA
!= NULL
) {
673 UINT uLen
= pRSNWPA
->len
+ 2;
674 if (uLen
<= (uIELength
- (UINT
)(ULONG_PTR
)((PBYTE
)pRSNWPA
- pbyIEs
))) {
675 pBSSList
->wWPALen
= uLen
;
676 memcpy(pBSSList
->byWPAIE
, pRSNWPA
, uLen
);
677 WPA_ParseRSN(pBSSList
, pRSNWPA
);
681 WPA2_ClearRSN(pBSSList
); //mike update
684 UINT uLen
= pRSN
->len
+ 2;
685 if (uLen
<= (uIELength
- (UINT
)(ULONG_PTR
)((PBYTE
)pRSN
- pbyIEs
))) {
686 pBSSList
->wRSNLen
= uLen
;
687 memcpy(pBSSList
->byRSNIE
, pRSN
, uLen
);
688 WPA2vParseRSN(pBSSList
, pRSN
);
692 if (pRxPacket
->uRSSI
!= 0) {
693 RFvRSSITodBm(pDevice
, (BYTE
)(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 CARDvSetCountryInfo(pMgmt
->pAdapter
,
708 pBSSList
->eNetworkTypeInUse
,
712 if ((bParsingQuiet
== TRUE
) && (pIE_Quiet
!= NULL
)) {
713 if ((((PWLAN_IE_QUIET
)pIE_Quiet
)->len
== 8) &&
714 (((PWLAN_IE_QUIET
)pIE_Quiet
)->byQuietCount
!= 0)) {
716 if (pQuiet
== NULL
) {
717 pQuiet
= (PWLAN_IE_QUIET
)pIE_Quiet
;
718 CARDbSetQuiet( pMgmt
->pAdapter
,
720 pQuiet
->byQuietCount
,
721 pQuiet
->byQuietPeriod
,
722 *((PWORD
)pQuiet
->abyQuietDuration
),
723 *((PWORD
)pQuiet
->abyQuietOffset
)
726 pQuiet
= (PWLAN_IE_QUIET
)pIE_Quiet
;
727 CARDbSetQuiet( pMgmt
->pAdapter
,
729 pQuiet
->byQuietCount
,
730 pQuiet
->byQuietPeriod
,
731 *((PWORD
)pQuiet
->abyQuietDuration
),
732 *((PWORD
)pQuiet
->abyQuietOffset
)
738 if ((bParsingQuiet
== TRUE
) &&
740 CARDbStartQuiet(pMgmt
->pAdapter
);
743 pBSSList
->uIELength
= uIELength
;
744 if (pBSSList
->uIELength
> WLAN_BEACON_FR_MAXLEN
)
745 pBSSList
->uIELength
= WLAN_BEACON_FR_MAXLEN
;
746 memcpy(pBSSList
->abyIEs
, pbyIEs
, pBSSList
->uIELength
);
757 * Routine Description:
758 * Search Node DB table to find the index of matched DstAddr
767 IN PVOID pMgmtObject
,
769 OUT PUINT puNodeIndex
772 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
775 // Index = 0 reserved for AP Node
776 for (ii
= 1; ii
< (MAX_NODE_NUM
+ 1); ii
++) {
777 if (pMgmt
->sNodeDBTable
[ii
].bActive
) {
778 if (IS_ETH_ADDRESS_EQUAL(abyDstAddr
, pMgmt
->sNodeDBTable
[ii
].abyMACAddr
)) {
792 * Routine Description:
793 * Find an empty node and allocated; if no empty found,
794 * instand used of most inactive one.
802 IN HANDLE hDeviceContext
,
803 OUT PUINT puNodeIndex
807 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
808 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
810 UINT BigestCount
= 0;
813 // Index = 0 reserved for AP Node (In STA mode)
814 // Index = 0 reserved for Broadcast/MultiCast (In AP mode)
816 for (ii
= 1; ii
< (MAX_NODE_NUM
+ 1); ii
++) {
817 if (pMgmt
->sNodeDBTable
[ii
].bActive
) {
818 if (pMgmt
->sNodeDBTable
[ii
].uInActiveCount
> BigestCount
) {
819 BigestCount
= pMgmt
->sNodeDBTable
[ii
].uInActiveCount
;
828 // if not found replace uInActiveCount is largest one.
829 if ( ii
== (MAX_NODE_NUM
+ 1)) {
830 *puNodeIndex
= SelectIndex
;
831 DBG_PRT(MSG_LEVEL_NOTICE
, KERN_INFO
"Replace inactive node = %d\n", SelectIndex
);
833 if (pMgmt
->sNodeDBTable
[*puNodeIndex
].sTxPSQueue
.next
!= NULL
) {
834 while ((skb
= skb_dequeue(&pMgmt
->sNodeDBTable
[*puNodeIndex
].sTxPSQueue
)) != NULL
)
842 memset(&pMgmt
->sNodeDBTable
[*puNodeIndex
], 0, sizeof(KnownNodeDB
));
843 pMgmt
->sNodeDBTable
[*puNodeIndex
].bActive
= TRUE
;
844 pMgmt
->sNodeDBTable
[*puNodeIndex
].uRatePollTimeout
= FALLBACK_POLL_SECOND
;
845 // for AP mode PS queue
846 skb_queue_head_init(&pMgmt
->sNodeDBTable
[*puNodeIndex
].sTxPSQueue
);
847 pMgmt
->sNodeDBTable
[*puNodeIndex
].byAuthSequence
= 0;
848 pMgmt
->sNodeDBTable
[*puNodeIndex
].wEnQueueCnt
= 0;
849 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Create node index = %d\n", ii
);
857 * Routine Description:
858 * Remove Node by NodeIndex
867 IN HANDLE hDeviceContext
,
872 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
873 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
874 BYTE byMask
[8] = {1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80};
878 while ((skb
= skb_dequeue(&pMgmt
->sNodeDBTable
[uNodeIndex
].sTxPSQueue
)) != NULL
)
881 memset(&pMgmt
->sNodeDBTable
[uNodeIndex
], 0, sizeof(KnownNodeDB
));
883 pMgmt
->abyPSTxMap
[pMgmt
->sNodeDBTable
[uNodeIndex
].wAID
>> 3] &= ~byMask
[pMgmt
->sNodeDBTable
[uNodeIndex
].wAID
& 7];
889 * Routine Description:
890 * Update AP Node content in Index 0 of KnownNodeDB
900 IN HANDLE hDeviceContext
,
902 IN PWLAN_IE_SUPP_RATES pSuppRates
,
903 IN PWLAN_IE_SUPP_RATES pExtSuppRates
906 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
907 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
908 UINT uRateLen
= WLAN_RATES_MAXLEN
;
910 memset(&pMgmt
->sNodeDBTable
[0], 0, sizeof(KnownNodeDB
));
912 pMgmt
->sNodeDBTable
[0].bActive
= TRUE
;
913 if (pDevice
->eCurrentPHYType
== PHY_TYPE_11B
) {
914 uRateLen
= WLAN_RATES_MAXLEN_11B
;
916 pMgmt
->abyCurrSuppRates
[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES
)pSuppRates
,
917 (PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
,
919 pMgmt
->abyCurrExtSuppRates
[1] = RATEuSetIE((PWLAN_IE_SUPP_RATES
)pExtSuppRates
,
920 (PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
,
922 RATEvParseMaxRate((PVOID
) pDevice
,
923 (PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
,
924 (PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
,
926 &(pMgmt
->sNodeDBTable
[0].wMaxBasicRate
),
927 &(pMgmt
->sNodeDBTable
[0].wMaxSuppRate
),
928 &(pMgmt
->sNodeDBTable
[0].wSuppRate
),
929 &(pMgmt
->sNodeDBTable
[0].byTopCCKBasicRate
),
930 &(pMgmt
->sNodeDBTable
[0].byTopOFDMBasicRate
)
932 memcpy(pMgmt
->sNodeDBTable
[0].abyMACAddr
, pMgmt
->abyCurrBSSID
, WLAN_ADDR_LEN
);
933 pMgmt
->sNodeDBTable
[0].wTxDataRate
= pMgmt
->sNodeDBTable
[0].wMaxSuppRate
;
934 pMgmt
->sNodeDBTable
[0].bShortPreamble
= WLAN_GET_CAP_INFO_SHORTPREAMBLE(*pwCapInfo
);
935 pMgmt
->sNodeDBTable
[0].uRatePollTimeout
= FALLBACK_POLL_SECOND
;
937 printk("BSSvUpdateAPNode:MaxSuppRate is %d\n",pMgmt
->sNodeDBTable
[0].wMaxSuppRate
);
939 // Auto rate fallback function initiation.
940 // RATEbInit(pDevice);
941 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"pMgmt->sNodeDBTable[0].wTxDataRate = %d \n", pMgmt
->sNodeDBTable
[0].wTxDataRate
);
951 * Routine Description:
952 * Add Multicast Node content in Index 0 of KnownNodeDB
962 BSSvAddMulticastNode(
963 IN HANDLE hDeviceContext
966 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
967 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
969 if (!pDevice
->bEnableHostWEP
)
970 memset(&pMgmt
->sNodeDBTable
[0], 0, sizeof(KnownNodeDB
));
971 memset(pMgmt
->sNodeDBTable
[0].abyMACAddr
, 0xff, WLAN_ADDR_LEN
);
972 pMgmt
->sNodeDBTable
[0].bActive
= TRUE
;
973 pMgmt
->sNodeDBTable
[0].bPSEnable
= FALSE
;
974 skb_queue_head_init(&pMgmt
->sNodeDBTable
[0].sTxPSQueue
);
975 RATEvParseMaxRate((PVOID
) pDevice
,
976 (PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrSuppRates
,
977 (PWLAN_IE_SUPP_RATES
)pMgmt
->abyCurrExtSuppRates
,
979 &(pMgmt
->sNodeDBTable
[0].wMaxBasicRate
),
980 &(pMgmt
->sNodeDBTable
[0].wMaxSuppRate
),
981 &(pMgmt
->sNodeDBTable
[0].wSuppRate
),
982 &(pMgmt
->sNodeDBTable
[0].byTopCCKBasicRate
),
983 &(pMgmt
->sNodeDBTable
[0].byTopOFDMBasicRate
)
985 pMgmt
->sNodeDBTable
[0].wTxDataRate
= pMgmt
->sNodeDBTable
[0].wMaxBasicRate
;
987 printk("BSSvAddMultiCastNode:pMgmt->sNodeDBTable[0].wTxDataRate is %d\n",pMgmt
->sNodeDBTable
[0].wTxDataRate
);
989 pMgmt
->sNodeDBTable
[0].uRatePollTimeout
= FALLBACK_POLL_SECOND
;
999 * Routine Description:
1002 * Second call back function to update Node DB info & AP link status
1009 //2008-4-14 <add> by chester for led issue
1010 #ifdef FOR_LED_ON_NOTEBOOK
1016 IN HANDLE hDeviceContext
1019 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
1020 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
1022 PWLAN_IE_SSID pItemSSID
, pCurrSSID
;
1023 UINT uSleepySTACnt
= 0;
1024 UINT uNonShortSlotSTACnt
= 0;
1025 UINT uLongPreambleSTACnt
= 0;
1026 viawget_wpa_header
* wpahdr
; //DavidWang
1028 spin_lock_irq(&pDevice
->lock
);
1030 pDevice
->uAssocCount
= 0;
1032 pDevice
->byERPFlag
&=
1033 ~(WLAN_SET_ERP_BARKER_MODE(1) | WLAN_SET_ERP_NONERP_PRESENT(1));
1034 //2008-4-14 <add> by chester for led issue
1035 #ifdef FOR_LED_ON_NOTEBOOK
1036 MACvGPIOIn(pDevice
->PortOffset
, &pDevice
->byGPIO
);
1037 if ((( !(pDevice
->byGPIO
& GPIO0_DATA
)&&(pDevice
->bHWRadioOff
== FALSE
))||((pDevice
->byGPIO
& GPIO0_DATA
)&&(pDevice
->bHWRadioOff
== TRUE
)))&&(cc
==FALSE
)){
1042 if(pDevice
->bHWRadioOff
== TRUE
){
1043 if ( !(pDevice
->byGPIO
& GPIO0_DATA
))
1044 //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
1045 {if(status
==1) goto start
;
1047 CARDbRadioPowerOff(pDevice
);
1048 pMgmt
->sNodeDBTable
[0].bActive
= FALSE
;
1049 pMgmt
->eCurrMode
= WMAC_MODE_STANDBY
;
1050 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
1051 //netif_stop_queue(pDevice->dev);
1052 pDevice
->bLinkPass
= FALSE
;
1055 if (pDevice
->byGPIO
&GPIO0_DATA
)
1056 //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
1057 {if(status
==2) goto start
;
1059 CARDbRadioPowerOn(pDevice
);
1062 if (pDevice
->byGPIO
& GPIO0_DATA
)
1063 //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
1064 {if(status
==3) goto start
;
1066 CARDbRadioPowerOff(pDevice
);
1067 pMgmt
->sNodeDBTable
[0].bActive
= FALSE
;
1068 pMgmt
->eCurrMode
= WMAC_MODE_STANDBY
;
1069 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
1070 //netif_stop_queue(pDevice->dev);
1071 pDevice
->bLinkPass
= FALSE
;
1074 if ( !(pDevice
->byGPIO
& GPIO0_DATA
))
1075 //||( !(pDevice->byGPIO & GPIO0_DATA) && (pDevice->byRadioCtl & EEP_RADIOCTL_INV)))
1076 {if(status
==4) goto start
;
1078 CARDbRadioPowerOn(pDevice
);
1085 if (pDevice
->wUseProtectCntDown
> 0) {
1086 pDevice
->wUseProtectCntDown
--;
1089 // disable protect mode
1090 pDevice
->byERPFlag
&= ~(WLAN_SET_ERP_USE_PROTECTION(1));
1094 pDevice
->byReAssocCount
++;
1095 if((pDevice
->byReAssocCount
> 10) && (pDevice
->bLinkPass
!= TRUE
)) { //10 sec timeout
1096 printk("Re-association timeout!!!\n");
1097 pDevice
->byReAssocCount
= 0;
1098 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1099 // if(pDevice->bWPASuppWextEnabled == TRUE)
1101 union iwreq_data wrqu
;
1102 memset(&wrqu
, 0, sizeof (wrqu
));
1103 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1104 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1105 wireless_send_event(pDevice
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
1109 else if(pDevice
->bLinkPass
== TRUE
)
1110 pDevice
->byReAssocCount
= 0;
1113 #ifdef Calcu_LinkQual
1114 s_uCalculateLinkQual((HANDLE
)pDevice
);
1117 for (ii
= 0; ii
< (MAX_NODE_NUM
+ 1); ii
++) {
1119 if (pMgmt
->sNodeDBTable
[ii
].bActive
) {
1120 // Increase in-activity counter
1121 pMgmt
->sNodeDBTable
[ii
].uInActiveCount
++;
1124 if (pMgmt
->sNodeDBTable
[ii
].uInActiveCount
> MAX_INACTIVE_COUNT
) {
1125 BSSvRemoveOneNode(pDevice
, ii
);
1126 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
1127 "Inactive timeout [%d] sec, STA index = [%d] remove\n", MAX_INACTIVE_COUNT
, ii
);
1131 if (pMgmt
->sNodeDBTable
[ii
].eNodeState
>= NODE_ASSOC
) {
1133 pDevice
->uAssocCount
++;
1135 // check if Non ERP exist
1136 if (pMgmt
->sNodeDBTable
[ii
].uInActiveCount
< ERP_RECOVER_COUNT
) {
1137 if (!pMgmt
->sNodeDBTable
[ii
].bShortPreamble
) {
1138 pDevice
->byERPFlag
|= WLAN_SET_ERP_BARKER_MODE(1);
1139 uLongPreambleSTACnt
++;
1141 if (!pMgmt
->sNodeDBTable
[ii
].bERPExist
) {
1142 pDevice
->byERPFlag
|= WLAN_SET_ERP_NONERP_PRESENT(1);
1143 pDevice
->byERPFlag
|= WLAN_SET_ERP_USE_PROTECTION(1);
1145 if (!pMgmt
->sNodeDBTable
[ii
].bShortSlotTime
)
1146 uNonShortSlotSTACnt
++;
1150 // check if any STA in PS mode
1151 if (pMgmt
->sNodeDBTable
[ii
].bPSEnable
)
1157 // Rate fallback check
1158 if (!pDevice
->bFixRate
) {
1160 if ((pMgmt->eCurrMode == WMAC_MODE_ESS_STA) && (ii == 0))
1161 RATEvTxRateFallBack(pDevice, &(pMgmt->sNodeDBTable[ii]));
1164 // ii = 0 for multicast node (AP & Adhoc)
1165 RATEvTxRateFallBack((PVOID
)pDevice
, &(pMgmt
->sNodeDBTable
[ii
]));
1168 // ii = 0 reserved for unicast AP node (Infra STA)
1169 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
)
1171 printk("SecondCallback:Before:TxDataRate is %d\n",pMgmt
->sNodeDBTable
[0].wTxDataRate
);
1173 RATEvTxRateFallBack((PVOID
)pDevice
, &(pMgmt
->sNodeDBTable
[ii
]));
1175 printk("SecondCallback:After:TxDataRate is %d\n",pMgmt
->sNodeDBTable
[0].wTxDataRate
);
1182 // check if pending PS queue
1183 if (pMgmt
->sNodeDBTable
[ii
].wEnQueueCnt
!= 0) {
1184 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Index= %d, Queue = %d pending \n",
1185 ii
, pMgmt
->sNodeDBTable
[ii
].wEnQueueCnt
);
1186 if ((ii
>0) && (pMgmt
->sNodeDBTable
[ii
].wEnQueueCnt
> 15)) {
1187 BSSvRemoveOneNode(pDevice
, ii
);
1188 DBG_PRT(MSG_LEVEL_NOTICE
, KERN_INFO
"Pending many queues PS STA Index = %d remove \n", ii
);
1197 if ((pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) && (pDevice
->eCurrentPHYType
== PHY_TYPE_11G
)) {
1199 // on/off protect mode
1200 if (WLAN_GET_ERP_USE_PROTECTION(pDevice
->byERPFlag
)) {
1201 if (!pDevice
->bProtectMode
) {
1202 MACvEnableProtectMD(pDevice
->PortOffset
);
1203 pDevice
->bProtectMode
= TRUE
;
1207 if (pDevice
->bProtectMode
) {
1208 MACvDisableProtectMD(pDevice
->PortOffset
);
1209 pDevice
->bProtectMode
= FALSE
;
1212 // on/off short slot time
1214 if (uNonShortSlotSTACnt
> 0) {
1215 if (pDevice
->bShortSlotTime
) {
1216 pDevice
->bShortSlotTime
= FALSE
;
1217 BBvSetShortSlotTime(pDevice
);
1218 vUpdateIFS((PVOID
)pDevice
);
1222 if (!pDevice
->bShortSlotTime
) {
1223 pDevice
->bShortSlotTime
= TRUE
;
1224 BBvSetShortSlotTime(pDevice
);
1225 vUpdateIFS((PVOID
)pDevice
);
1229 // on/off barker long preamble mode
1231 if (uLongPreambleSTACnt
> 0) {
1232 if (!pDevice
->bBarkerPreambleMd
) {
1233 MACvEnableBarkerPreambleMd(pDevice
->PortOffset
);
1234 pDevice
->bBarkerPreambleMd
= TRUE
;
1238 if (pDevice
->bBarkerPreambleMd
) {
1239 MACvDisableBarkerPreambleMd(pDevice
->PortOffset
);
1240 pDevice
->bBarkerPreambleMd
= FALSE
;
1247 // Check if any STA in PS mode, enable DTIM multicast deliver
1248 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
1249 if (uSleepySTACnt
> 0)
1250 pMgmt
->sNodeDBTable
[0].bPSEnable
= TRUE
;
1252 pMgmt
->sNodeDBTable
[0].bPSEnable
= FALSE
;
1255 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyDesireSSID
;
1256 pCurrSSID
= (PWLAN_IE_SSID
)pMgmt
->abyCurrSSID
;
1258 if ((pMgmt
->eCurrMode
== WMAC_MODE_STANDBY
) ||
1259 (pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
)) {
1261 if (pMgmt
->sNodeDBTable
[0].bActive
) { // Assoc with BSS
1262 // DBG_PRT(MSG_LEVEL_INFO, KERN_INFO "Callback inactive Count = [%d]\n", pMgmt->sNodeDBTable[0].uInActiveCount);
1263 //if (pDevice->bUpdateBBVGA) {
1264 // s_vCheckSensitivity((HANDLE) pDevice);
1267 if (pDevice
->bUpdateBBVGA
) {
1268 // s_vCheckSensitivity((HANDLE) pDevice);
1269 s_vCheckPreEDThreshold((HANDLE
)pDevice
);
1272 if ((pMgmt
->sNodeDBTable
[0].uInActiveCount
>= (LOST_BEACON_COUNT
/2)) &&
1273 (pDevice
->byBBVGACurrent
!= pDevice
->abyBBVGA
[0]) ) {
1274 pDevice
->byBBVGANew
= pDevice
->abyBBVGA
[0];
1275 bScheduleCommand((HANDLE
) pDevice
, WLAN_CMD_CHANGE_BBSENSITIVITY
, NULL
);
1278 if (pMgmt
->sNodeDBTable
[0].uInActiveCount
>= LOST_BEACON_COUNT
) {
1279 pMgmt
->sNodeDBTable
[0].bActive
= FALSE
;
1280 pMgmt
->eCurrMode
= WMAC_MODE_STANDBY
;
1281 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
1282 netif_stop_queue(pDevice
->dev
);
1283 pDevice
->bLinkPass
= FALSE
;
1284 pDevice
->bRoaming
= TRUE
;
1285 DBG_PRT(MSG_LEVEL_NOTICE
, KERN_INFO
"Lost AP beacon [%d] sec, disconnected !\n", pMgmt
->sNodeDBTable
[0].uInActiveCount
);
1286 if ((pDevice
->bWPADEVUp
) && (pDevice
->skb
!= NULL
)) {
1287 wpahdr
= (viawget_wpa_header
*)pDevice
->skb
->data
;
1288 wpahdr
->type
= VIAWGET_DISASSOC_MSG
;
1289 wpahdr
->resp_ie_len
= 0;
1290 wpahdr
->req_ie_len
= 0;
1291 skb_put(pDevice
->skb
, sizeof(viawget_wpa_header
));
1292 pDevice
->skb
->dev
= pDevice
->wpadev
;
1293 skb_reset_mac_header(pDevice
->skb
);
1294 pDevice
->skb
->pkt_type
= PACKET_HOST
;
1295 pDevice
->skb
->protocol
= htons(ETH_P_802_2
);
1296 memset(pDevice
->skb
->cb
, 0, sizeof(pDevice
->skb
->cb
));
1297 netif_rx(pDevice
->skb
);
1298 pDevice
->skb
= dev_alloc_skb((int)pDevice
->rx_buf_sz
);
1300 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1301 // if(pDevice->bWPASuppWextEnabled == TRUE)
1303 union iwreq_data wrqu
;
1304 memset(&wrqu
, 0, sizeof (wrqu
));
1305 wrqu
.ap_addr
.sa_family
= ARPHRD_ETHER
;
1306 PRINT_K("wireless_send_event--->SIOCGIWAP(disassociated)\n");
1307 wireless_send_event(pDevice
->dev
, SIOCGIWAP
, &wrqu
, NULL
);
1312 else if (pItemSSID
->len
!= 0) {
1313 if (pDevice
->uAutoReConnectTime
< 10) {
1314 pDevice
->uAutoReConnectTime
++;
1315 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1316 //network manager support need not do Roaming scan???
1317 if(pDevice
->bWPASuppWextEnabled
==TRUE
)
1318 pDevice
->uAutoReConnectTime
= 0;
1322 //mike use old encryption status for wpa reauthen
1323 if(pDevice
->bWPADEVUp
)
1324 pDevice
->eEncryptionStatus
= pDevice
->eOldEncryptionStatus
;
1326 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Roaming ...\n");
1327 BSSvClearBSSList((HANDLE
)pDevice
, pDevice
->bLinkPass
);
1328 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
1329 bScheduleCommand((HANDLE
) pDevice
, WLAN_CMD_BSSID_SCAN
, pMgmt
->abyDesireSSID
);
1330 bScheduleCommand((HANDLE
) pDevice
, WLAN_CMD_SSID
, pMgmt
->abyDesireSSID
);
1331 pDevice
->uAutoReConnectTime
= 0;
1336 if (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) {
1337 // if adhoc started which essid is NULL string, rescaning.
1338 if ((pMgmt
->eCurrState
== WMAC_STATE_STARTED
) && (pCurrSSID
->len
== 0)) {
1339 if (pDevice
->uAutoReConnectTime
< 10) {
1340 pDevice
->uAutoReConnectTime
++;
1343 DBG_PRT(MSG_LEVEL_NOTICE
, KERN_INFO
"Adhoc re-scaning ...\n");
1344 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
1345 bScheduleCommand((HANDLE
) pDevice
, WLAN_CMD_BSSID_SCAN
, NULL
);
1346 bScheduleCommand((HANDLE
) pDevice
, WLAN_CMD_SSID
, NULL
);
1347 pDevice
->uAutoReConnectTime
= 0;
1350 if (pMgmt
->eCurrState
== WMAC_STATE_JOINTED
) {
1352 if (pDevice
->bUpdateBBVGA
) {
1353 //s_vCheckSensitivity((HANDLE) pDevice);
1354 s_vCheckPreEDThreshold((HANDLE
)pDevice
);
1356 if (pMgmt
->sNodeDBTable
[0].uInActiveCount
>=ADHOC_LOST_BEACON_COUNT
) {
1357 DBG_PRT(MSG_LEVEL_NOTICE
, KERN_INFO
"Lost other STA beacon [%d] sec, started !\n", pMgmt
->sNodeDBTable
[0].uInActiveCount
);
1358 pMgmt
->sNodeDBTable
[0].uInActiveCount
= 0;
1359 pMgmt
->eCurrState
= WMAC_STATE_STARTED
;
1360 netif_stop_queue(pDevice
->dev
);
1361 pDevice
->bLinkPass
= FALSE
;
1366 spin_unlock_irq(&pDevice
->lock
);
1368 pMgmt
->sTimerSecondCallback
.expires
= RUN_AT(HZ
);
1369 add_timer(&pMgmt
->sTimerSecondCallback
);
1378 * Routine Description:
1381 * Update Tx attemps, Tx failure counter in Node DB
1392 BSSvUpdateNodeTxCounter(
1393 IN HANDLE hDeviceContext
,
1397 IN UINT uFIFOHeaderSize
1400 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
1401 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
1402 UINT uNodeIndex
= 0;
1403 BYTE byTxRetry
= (byTsr0
& TSR0_NCR
);
1404 PSTxBufHead pTxBufHead
;
1405 PS802_11Header pMACHeader
;
1407 WORD wFallBackRate
= RATE_1M
;
1410 // UINT txRetryTemp;
1412 //txRetryTemp = byTxRetry;
1413 //if (txRetryTemp== 8)
1416 pTxBufHead
= (PSTxBufHead
) pbyBuffer
;
1417 if (pTxBufHead
->wFIFOCtl
& FIFOCTL_AUTO_FB_0
) {
1418 byFallBack
= AUTO_FB_0
;
1419 } else if (pTxBufHead
->wFIFOCtl
& FIFOCTL_AUTO_FB_1
) {
1420 byFallBack
= AUTO_FB_1
;
1422 byFallBack
= AUTO_FB_NONE
;
1424 wRate
= pTxBufHead
->wReserved
; //?wRate
1425 //printk("BSSvUpdateNodeTxCounter:byTxRetry is %d\n",byTxRetry);
1427 //printk("BSSvUpdateNodeTx:wRate is %d,byFallback is %d\n",wRate,byFallBack);
1428 //#ifdef PLICE_DEBUG
1429 //printk("BSSvUpdateNodeTx: wRate is %d\n",wRate);
1431 // Only Unicast using support rates
1432 if (pTxBufHead
->wFIFOCtl
& FIFOCTL_NEEDACK
) {
1433 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"wRate %04X, byTsr0 %02X, byTsr1 %02X\n", wRate
, byTsr0
, byTsr1
);
1434 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_STA
) {
1435 pMgmt
->sNodeDBTable
[0].uTxAttempts
+= 1;
1436 if ((byTsr1
& TSR1_TERR
) == 0) {
1437 // transmit success, TxAttempts at least plus one
1438 pMgmt
->sNodeDBTable
[0].uTxOk
[MAX_RATE
]++;
1439 if ( (byFallBack
== AUTO_FB_NONE
) ||
1440 (wRate
< RATE_18M
) ) {
1441 wFallBackRate
= wRate
;
1442 } else if (byFallBack
== AUTO_FB_0
) {
1445 //if (txRetryTemp < 5)
1446 wFallBackRate
= awHWRetry0
[wRate
-RATE_18M
][byTxRetry
];
1447 //wFallBackRate = awHWRetry0[wRate-RATE_12M][byTxRetry];
1448 //wFallBackRate = awHWRetry0[wRate-RATE_18M][txRetryTemp] +1;
1450 wFallBackRate
= awHWRetry0
[wRate
-RATE_18M
][4];
1451 //wFallBackRate = awHWRetry0[wRate-RATE_12M][4];
1452 } else if (byFallBack
== AUTO_FB_1
) {
1454 wFallBackRate
= awHWRetry1
[wRate
-RATE_18M
][byTxRetry
];
1456 wFallBackRate
= awHWRetry1
[wRate
-RATE_18M
][4];
1458 pMgmt
->sNodeDBTable
[0].uTxOk
[wFallBackRate
]++;
1460 pMgmt
->sNodeDBTable
[0].uTxFailures
++;
1462 pMgmt
->sNodeDBTable
[0].uTxRetry
+= byTxRetry
;
1463 if (byTxRetry
!= 0) {
1464 pMgmt
->sNodeDBTable
[0].uTxFail
[MAX_RATE
]+=byTxRetry
;
1465 if ( (byFallBack
== AUTO_FB_NONE
) ||
1466 (wRate
< RATE_18M
) ) {
1467 pMgmt
->sNodeDBTable
[0].uTxFail
[wRate
]+=byTxRetry
;
1468 } else if (byFallBack
== AUTO_FB_0
) {
1470 for(ii
=0;ii
<byTxRetry
;ii
++)
1471 //for (ii=0;ii<txRetryTemp;ii++)
1477 wFallBackRate
= awHWRetry0
[wRate
-RATE_18M
][ii
];
1478 //printk(" II is %d:BSSvUpdateNodeTx:wFallBackRate is %d\n",ii,wFallBackRate);
1479 //wFallBackRate = awHWRetry0[wRate-RATE_12M][ii];
1483 wFallBackRate
= awHWRetry0
[wRate
-RATE_18M
][4];
1484 //printk("ii is %d BSSvUpdateNodeTx:wFallBackRate is %d\n",ii,wFallBackRate);
1485 //wFallBackRate = awHWRetry0[wRate-RATE_12M][4];
1487 pMgmt
->sNodeDBTable
[0].uTxFail
[wFallBackRate
]++;
1489 } else if (byFallBack
== AUTO_FB_1
) {
1490 for(ii
=0;ii
<byTxRetry
;ii
++) {
1492 wFallBackRate
= awHWRetry1
[wRate
-RATE_18M
][ii
];
1494 wFallBackRate
= awHWRetry1
[wRate
-RATE_18M
][4];
1495 pMgmt
->sNodeDBTable
[0].uTxFail
[wFallBackRate
]++;
1501 if ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ||
1502 (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)) {
1504 pMACHeader
= (PS802_11Header
)(pbyBuffer
+ uFIFOHeaderSize
);
1506 if (BSSDBbIsSTAInNodeDB((HANDLE
)pMgmt
, &(pMACHeader
->abyAddr1
[0]), &uNodeIndex
)){
1507 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxAttempts
+= 1;
1508 if ((byTsr1
& TSR1_TERR
) == 0) {
1509 // transmit success, TxAttempts at least plus one
1510 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxOk
[MAX_RATE
]++;
1511 if ( (byFallBack
== AUTO_FB_NONE
) ||
1512 (wRate
< RATE_18M
) ) {
1513 wFallBackRate
= wRate
;
1514 } else if (byFallBack
== AUTO_FB_0
) {
1516 wFallBackRate
= awHWRetry0
[wRate
-RATE_18M
][byTxRetry
];
1518 wFallBackRate
= awHWRetry0
[wRate
-RATE_18M
][4];
1519 } else if (byFallBack
== AUTO_FB_1
) {
1521 wFallBackRate
= awHWRetry1
[wRate
-RATE_18M
][byTxRetry
];
1523 wFallBackRate
= awHWRetry1
[wRate
-RATE_18M
][4];
1525 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxOk
[wFallBackRate
]++;
1527 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxFailures
++;
1529 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxRetry
+= byTxRetry
;
1530 if (byTxRetry
!= 0) {
1531 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxFail
[MAX_RATE
]+=byTxRetry
;
1532 if ( (byFallBack
== AUTO_FB_NONE
) ||
1533 (wRate
< RATE_18M
) ) {
1534 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxFail
[wRate
]+=byTxRetry
;
1535 } else if (byFallBack
== AUTO_FB_0
) {
1536 for(ii
=0;ii
<byTxRetry
;ii
++) {
1538 wFallBackRate
= awHWRetry0
[wRate
-RATE_18M
][ii
];
1540 wFallBackRate
= awHWRetry0
[wRate
-RATE_18M
][4];
1541 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxFail
[wFallBackRate
]++;
1543 } else if (byFallBack
== AUTO_FB_1
) {
1544 for(ii
=0;ii
<byTxRetry
;ii
++) {
1546 wFallBackRate
= awHWRetry1
[wRate
-RATE_18M
][ii
];
1548 wFallBackRate
= awHWRetry1
[wRate
-RATE_18M
][4];
1549 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxFail
[wFallBackRate
]++;
1567 * Routine Description:
1568 * Clear Nodes & skb in DB Table
1573 * hDeviceContext - The adapter context.
1574 * uStartIndex - starting index
1585 BSSvClearNodeDBTable(
1586 IN HANDLE hDeviceContext
,
1591 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
1592 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
1593 struct sk_buff
*skb
;
1596 for (ii
= uStartIndex
; ii
< (MAX_NODE_NUM
+ 1); ii
++) {
1597 if (pMgmt
->sNodeDBTable
[ii
].bActive
) {
1598 // check if sTxPSQueue has been initial
1599 if (pMgmt
->sNodeDBTable
[ii
].sTxPSQueue
.next
!= NULL
) {
1600 while ((skb
= skb_dequeue(&pMgmt
->sNodeDBTable
[ii
].sTxPSQueue
)) != NULL
){
1601 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"PS skb != NULL %d\n", ii
);
1605 memset(&pMgmt
->sNodeDBTable
[ii
], 0, sizeof(KnownNodeDB
));
1613 VOID
s_vCheckSensitivity(
1614 IN HANDLE hDeviceContext
1617 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
1618 PKnownBSS pBSSList
= NULL
;
1619 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
1622 if ((pDevice
->byLocalID
<= REV_ID_VT3253_A1
) && (pDevice
->byRFType
== RF_RFMD2959
) &&
1623 (pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
)) {
1627 if ((pMgmt
->eCurrState
== WMAC_STATE_ASSOC
) ||
1628 ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) && (pMgmt
->eCurrState
== WMAC_STATE_JOINTED
))) {
1629 pBSSList
= BSSpAddrIsInBSSList(pDevice
, pMgmt
->abyCurrBSSID
, (PWLAN_IE_SSID
)pMgmt
->abyCurrSSID
);
1630 if (pBSSList
!= NULL
) {
1631 // Updata BB Reg if RSSI is too strong.
1632 LONG LocalldBmAverage
= 0;
1634 for (ii
= 0; ii
< RSSI_STAT_COUNT
; ii
++) {
1635 if (pBSSList
->ldBmAverage
[ii
] != 0) {
1637 LocalldBmAverage
+= pBSSList
->ldBmAverage
[ii
];
1640 if (uNumofdBm
> 0) {
1641 LocalldBmAverage
= LocalldBmAverage
/uNumofdBm
;
1642 for (ii
=0;ii
<BB_VGA_LEVEL
;ii
++) {
1643 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"LocalldBmAverage:%ld, %ld %02x\n", LocalldBmAverage
, pDevice
->ldBmThreshold
[ii
], pDevice
->abyBBVGA
[ii
]);
1644 if (LocalldBmAverage
< pDevice
->ldBmThreshold
[ii
]) {
1645 pDevice
->byBBVGANew
= pDevice
->abyBBVGA
[ii
];
1649 if (pDevice
->byBBVGANew
!= pDevice
->byBBVGACurrent
) {
1650 pDevice
->uBBVGADiffCount
++;
1651 if (pDevice
->uBBVGADiffCount
>= BB_VGA_CHANGE_THRESHOLD
)
1652 bScheduleCommand((HANDLE
) pDevice
, WLAN_CMD_CHANGE_BBSENSITIVITY
, NULL
);
1654 pDevice
->uBBVGADiffCount
= 0;
1663 BSSvClearAnyBSSJoinRecord (
1664 IN HANDLE hDeviceContext
1667 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
1668 PSMgmtObject pMgmt
= pDevice
->pMgmt
;
1671 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
1672 pMgmt
->sBSSList
[ii
].bSelected
= FALSE
;
1677 #ifdef Calcu_LinkQual
1678 VOID
s_uCalculateLinkQual(
1679 IN HANDLE hDeviceContext
1682 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
1683 ULONG TxOkRatio
, TxCnt
;
1684 ULONG RxOkRatio
,RxCnt
;
1688 TxCnt
= pDevice
->scStatistic
.TxNoRetryOkCount
+
1689 pDevice
->scStatistic
.TxRetryOkCount
+
1690 pDevice
->scStatistic
.TxFailCount
;
1691 RxCnt
= pDevice
->scStatistic
.RxFcsErrCnt
+
1692 pDevice
->scStatistic
.RxOkCnt
;
1693 TxOkRatio
= (TxCnt
< 6) ? 4000:((pDevice
->scStatistic
.TxNoRetryOkCount
* 4000) / TxCnt
);
1694 RxOkRatio
= (RxCnt
< 6) ? 2000:((pDevice
->scStatistic
.RxOkCnt
* 2000) / RxCnt
);
1695 //decide link quality
1696 if(pDevice
->bLinkPass
!=TRUE
)
1698 // printk("s_uCalculateLinkQual-->Link disconnect and Poor quality**\n");
1699 pDevice
->scStatistic
.LinkQuality
= 0;
1700 pDevice
->scStatistic
.SignalStren
= 0;
1704 RFvRSSITodBm(pDevice
, (BYTE
)(pDevice
->uCurrRSSI
), &ldBm
);
1708 else if(-ldBm
> 90) {
1712 RssiRatio
= (40-(-ldBm
-50))*4000/40;
1714 pDevice
->scStatistic
.SignalStren
= RssiRatio
/40;
1715 pDevice
->scStatistic
.LinkQuality
= (RssiRatio
+TxOkRatio
+RxOkRatio
)/100;
1717 pDevice
->scStatistic
.RxFcsErrCnt
= 0;
1718 pDevice
->scStatistic
.RxOkCnt
= 0;
1719 pDevice
->scStatistic
.TxFailCount
= 0;
1720 pDevice
->scStatistic
.TxNoRetryOkCount
= 0;
1721 pDevice
->scStatistic
.TxRetryOkCount
= 0;
1726 VOID
s_vCheckPreEDThreshold(
1727 IN HANDLE hDeviceContext
1730 PSDevice pDevice
= (PSDevice
)hDeviceContext
;
1731 PKnownBSS pBSSList
= NULL
;
1732 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1734 if ((pMgmt
->eCurrState
== WMAC_STATE_ASSOC
) ||
1735 ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) && (pMgmt
->eCurrState
== WMAC_STATE_JOINTED
))) {
1736 pBSSList
= BSSpAddrIsInBSSList(pDevice
, pMgmt
->abyCurrBSSID
, (PWLAN_IE_SSID
)pMgmt
->abyCurrSSID
);
1737 if (pBSSList
!= NULL
) {
1738 pDevice
->byBBPreEDRSSI
= (BYTE
) (~(pBSSList
->ldBmAverRange
) + 1);
1739 //BBvUpdatePreEDThreshold(pDevice, FALSE);