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 auto fallback & data rates functions
28 * RATEvParseMaxRate - Parsing the highest basic & support rate in rate field of frame
29 * RATEvTxRateFallBack - Rate fallback Algorithm Implementaion
30 * RATEuSetIE- Set rate IE field.
36 #if !defined(__TTYPE_H__)
39 #if !defined(__TMACRO_H__)
42 #if !defined(__MAC_H__)
45 #if !defined(__80211MGR_H__)
48 #if !defined(__BSSDB_H__)
51 #if !defined(__DATARATE_H__)
54 #if !defined(__CARD_H__)
57 #if !defined(__BASEBAND_H__)
60 #if !defined(__SROM_H__)
64 /*--------------------- Static Definitions -------------------------*/
69 /*--------------------- Static Classes ----------------------------*/
72 extern WORD TxRate_iwconfig
; //2008-5-8 <add> by chester
73 /*--------------------- Static Variables --------------------------*/
74 //static int msglevel =MSG_LEVEL_DEBUG;
75 static int msglevel
=MSG_LEVEL_INFO
;
76 const BYTE acbyIERate
[MAX_RATE
] =
77 {0x02, 0x04, 0x0B, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
79 #define AUTORATE_TXOK_CNT 0x0400
80 #define AUTORATE_TXFAIL_CNT 0x0064
81 #define AUTORATE_TIMEOUT 10
83 /*--------------------- Static Functions --------------------------*/
85 VOID
s_vResetCounter (
86 IN PKnownNodeDB psNodeDBTable
93 IN PKnownNodeDB psNodeDBTable
98 // clear statistic counter for auto_rate
99 for(ii
=0;ii
<=MAX_RATE
;ii
++) {
100 psNodeDBTable
->uTxOk
[ii
] = 0;
101 psNodeDBTable
->uTxFail
[ii
] = 0;
105 /*--------------------- Export Variables --------------------------*/
108 /*--------------------- Export Functions --------------------------*/
114 * Get RateIdx from the value in SuppRates IE or ExtSuppRates IE
118 * BYTE - Rate value in SuppRates IE or ExtSuppRates IE
122 * Return Value: RateIdx
126 DATARATEbyGetRateIdx (
132 //Erase basicRate flag.
133 byRate
= byRate
& 0x7F;//0111 1111
135 for (ii
= 0; ii
< MAX_RATE
; ii
++) {
136 if (acbyIERate
[ii
] == byRate
)
146 * Routine Description:
147 * Rate fallback Algorithm Implementaion
151 * pDevice - Pointer to the adapter
152 * psNodeDBTable - Pointer to Node Data Base
159 #define AUTORATE_TXCNT_THRESHOLD 20
160 #define AUTORATE_INC_THRESHOLD 30
168 * Get RateIdx from the value in SuppRates IE or ExtSuppRates IE
172 * BYTE - Rate value in SuppRates IE or ExtSuppRates IE
176 * Return Value: RateIdx
186 //Erase basicRate flag.
187 byRate
= byRate
& 0x7F;//0111 1111
189 for (ii
= 0; ii
< MAX_RATE
; ii
++) {
190 if (acbyIERate
[ii
] == byRate
)
199 * Parsing the highest basic & support rate in rate field of frame.
203 * pDevice - Pointer to the adapter
204 * pItemRates - Pointer to Rate field defined in 802.11 spec.
205 * pItemExtRates - Pointer to Extended Rate field defined in 802.11 spec.
207 * pwMaxBasicRate - Maximum Basic Rate
208 * pwMaxSuppRate - Maximum Supported Rate
209 * pbyTopCCKRate - Maximum Basic Rate in CCK mode
210 * pbyTopOFDMRate - Maximum Basic Rate in OFDM mode
217 IN PVOID pDeviceHandler
,
218 IN PWLAN_IE_SUPP_RATES pItemRates
,
219 IN PWLAN_IE_SUPP_RATES pItemExtRates
,
220 IN BOOL bUpdateBasicRate
,
221 OUT PWORD pwMaxBasicRate
,
222 OUT PWORD pwMaxSuppRate
,
223 OUT PWORD pwSuppRate
,
224 OUT PBYTE pbyTopCCKRate
,
225 OUT PBYTE pbyTopOFDMRate
228 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
230 BYTE byHighSuppRate
= 0;
232 WORD wOldBasicRate
= pDevice
->wBasicRate
;
236 if (pItemRates
== NULL
)
240 uRateLen
= pItemRates
->len
;
242 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ParseMaxRate Len: %d\n", uRateLen
);
243 if (pDevice
->eCurrentPHYType
!= PHY_TYPE_11B
) {
244 if (uRateLen
> WLAN_RATES_MAXLEN
)
245 uRateLen
= WLAN_RATES_MAXLEN
;
247 if (uRateLen
> WLAN_RATES_MAXLEN_11B
)
248 uRateLen
= WLAN_RATES_MAXLEN_11B
;
251 for (ii
= 0; ii
< uRateLen
; ii
++) {
252 byRate
= (BYTE
)(pItemRates
->abyRates
[ii
]);
253 if (WLAN_MGMT_IS_BASICRATE(byRate
) &&
254 (bUpdateBasicRate
== TRUE
)) {
255 // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate
256 CARDbAddBasicRate((PVOID
)pDevice
, wGetRateIdx(byRate
));
257 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate
));
259 byRate
= (BYTE
)(pItemRates
->abyRates
[ii
]&0x7F);
260 if (byHighSuppRate
== 0)
261 byHighSuppRate
= byRate
;
262 if (byRate
> byHighSuppRate
)
263 byHighSuppRate
= byRate
;
264 *pwSuppRate
|= (1<<wGetRateIdx(byRate
));
266 if ((pItemExtRates
!= NULL
) && (pItemExtRates
->byElementID
== WLAN_EID_EXTSUPP_RATES
) &&
267 (pDevice
->eCurrentPHYType
!= PHY_TYPE_11B
)) {
269 UINT uExtRateLen
= pItemExtRates
->len
;
271 if (uExtRateLen
> WLAN_RATES_MAXLEN
)
272 uExtRateLen
= WLAN_RATES_MAXLEN
;
274 for (ii
= 0; ii
< uExtRateLen
; ii
++) {
275 byRate
= (BYTE
)(pItemExtRates
->abyRates
[ii
]);
276 // select highest basic rate
277 if (WLAN_MGMT_IS_BASICRATE(pItemExtRates
->abyRates
[ii
])) {
278 // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate
279 CARDbAddBasicRate((PVOID
)pDevice
, wGetRateIdx(byRate
));
280 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate
));
282 byRate
= (BYTE
)(pItemExtRates
->abyRates
[ii
]&0x7F);
283 if (byHighSuppRate
== 0)
284 byHighSuppRate
= byRate
;
285 if (byRate
> byHighSuppRate
)
286 byHighSuppRate
= byRate
;
287 *pwSuppRate
|= (1<<wGetRateIdx(byRate
));
288 //DBG_PRN_GRP09(("ParseMaxRate : HighSuppRate: %d, %X\n", wGetRateIdx(byRate), byRate));
290 } //if(pItemExtRates != NULL)
292 if ((pDevice
->byPacketType
== PK_TYPE_11GB
) && CARDbIsOFDMinBasicRate((PVOID
)pDevice
)) {
293 pDevice
->byPacketType
= PK_TYPE_11GA
;
296 *pbyTopCCKRate
= pDevice
->byTopCCKBasicRate
;
297 *pbyTopOFDMRate
= pDevice
->byTopOFDMBasicRate
;
298 *pwMaxSuppRate
= wGetRateIdx(byHighSuppRate
);
299 if ((pDevice
->byPacketType
==PK_TYPE_11B
) || (pDevice
->byPacketType
==PK_TYPE_11GB
))
300 *pwMaxBasicRate
= pDevice
->byTopCCKBasicRate
;
302 *pwMaxBasicRate
= pDevice
->byTopOFDMBasicRate
;
303 if (wOldBasicRate
!= pDevice
->wBasicRate
)
304 CARDvSetRSPINF((PVOID
)pDevice
, pDevice
->eCurrentPHYType
);
306 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Exit ParseMaxRate\n");
312 * Routine Description:
313 * Rate fallback Algorithm Implementaion
317 * pDevice - Pointer to the adapter
318 * psNodeDBTable - Pointer to Node Data Base
325 #define AUTORATE_TXCNT_THRESHOLD 20
326 #define AUTORATE_INC_THRESHOLD 30
329 RATEvTxRateFallBack (
330 IN PVOID pDeviceHandler
,
331 IN PKnownNodeDB psNodeDBTable
334 PSDevice pDevice
= (PSDevice
) pDeviceHandler
;
335 WORD wIdxDownRate
= 0;
337 //DWORD dwRateTable[MAX_RATE] = {1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54};
338 BOOL bAutoRate
[MAX_RATE
] = {TRUE
,TRUE
,TRUE
,TRUE
,FALSE
,FALSE
,TRUE
,TRUE
,TRUE
,TRUE
,TRUE
,TRUE
};
339 DWORD dwThroughputTbl
[MAX_RATE
] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540};
340 DWORD dwThroughput
= 0;
344 if (pDevice
->pMgmt
->eScanState
!= WMAC_NO_SCANNING
) {
345 // Don't do Fallback when scanning Channel
349 psNodeDBTable
->uTimeCount
++;
351 if (psNodeDBTable
->uTxFail
[MAX_RATE
] > psNodeDBTable
->uTxOk
[MAX_RATE
])
352 dwTxDiff
= psNodeDBTable
->uTxFail
[MAX_RATE
] - psNodeDBTable
->uTxOk
[MAX_RATE
];
354 if ((psNodeDBTable
->uTxOk
[MAX_RATE
] < AUTORATE_TXOK_CNT
) &&
355 (dwTxDiff
< AUTORATE_TXFAIL_CNT
) &&
356 (psNodeDBTable
->uTimeCount
< AUTORATE_TIMEOUT
)) {
360 if (psNodeDBTable
->uTimeCount
>= AUTORATE_TIMEOUT
) {
361 psNodeDBTable
->uTimeCount
= 0;
365 for(ii
=0;ii
<MAX_RATE
;ii
++) {
366 if (psNodeDBTable
->wSuppRate
& (0x0001<<ii
)) {
367 if (bAutoRate
[ii
] == TRUE
) {
368 wIdxUpRate
= (WORD
) ii
;
371 bAutoRate
[ii
] = FALSE
;
375 for(ii
=0;ii
<=psNodeDBTable
->wTxDataRate
;ii
++) {
376 if ( (psNodeDBTable
->uTxOk
[ii
] != 0) ||
377 (psNodeDBTable
->uTxFail
[ii
] != 0) ) {
378 dwThroughputTbl
[ii
] *= psNodeDBTable
->uTxOk
[ii
];
380 psNodeDBTable
->uTxFail
[ii
] *= 4;
382 dwThroughputTbl
[ii
] /= (psNodeDBTable
->uTxOk
[ii
] + psNodeDBTable
->uTxFail
[ii
]);
384 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rate %d,Ok: %d, Fail:%d, Throughput:%d\n",
385 // ii, psNodeDBTable->uTxOk[ii], psNodeDBTable->uTxFail[ii], dwThroughputTbl[ii]);
387 dwThroughput
= dwThroughputTbl
[psNodeDBTable
->wTxDataRate
];
389 wIdxDownRate
= psNodeDBTable
->wTxDataRate
;
390 for(ii
= psNodeDBTable
->wTxDataRate
; ii
> 0;) {
392 if ( (dwThroughputTbl
[ii
] > dwThroughput
) &&
393 (bAutoRate
[ii
]==TRUE
) ) {
394 dwThroughput
= dwThroughputTbl
[ii
];
395 wIdxDownRate
= (WORD
) ii
;
398 psNodeDBTable
->wTxDataRate
= wIdxDownRate
;
399 if (psNodeDBTable
->uTxOk
[MAX_RATE
]) {
400 if (psNodeDBTable
->uTxOk
[MAX_RATE
] >
401 (psNodeDBTable
->uTxFail
[MAX_RATE
] * 4) ) {
402 psNodeDBTable
->wTxDataRate
= wIdxUpRate
;
404 }else { // adhoc, if uTxOk =0 & uTxFail = 0
405 if (psNodeDBTable
->uTxFail
[MAX_RATE
] == 0)
406 psNodeDBTable
->wTxDataRate
= wIdxUpRate
;
408 //2008-5-8 <add> by chester
409 TxRate_iwconfig
=psNodeDBTable
->wTxDataRate
;
410 s_vResetCounter(psNodeDBTable
);
411 // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rate: %d, U:%d, D:%d\n", psNodeDBTable->wTxDataRate, wIdxUpRate, wIdxDownRate);
420 * This routine is used to assemble available Rate IE.
432 IN PWLAN_IE_SUPP_RATES pSrcRates
,
433 IN PWLAN_IE_SUPP_RATES pDstRates
,
437 UINT ii
, uu
, uRateCnt
= 0;
439 if ((pSrcRates
== NULL
) || (pDstRates
== NULL
))
442 if (pSrcRates
->len
== 0)
445 for (ii
= 0; ii
< uRateLen
; ii
++) {
446 for (uu
= 0; uu
< pSrcRates
->len
; uu
++) {
447 if ((pSrcRates
->abyRates
[uu
] & 0x7F) == acbyIERate
[ii
]) {
448 pDstRates
->abyRates
[uRateCnt
++] = pSrcRates
->abyRates
[uu
];
453 return (BYTE
)uRateCnt
;