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.
46 /*--------------------- Static Definitions -------------------------*/
48 /*--------------------- Static Classes ----------------------------*/
50 extern unsigned short TxRate_iwconfig; //2008-5-8 <add> by chester
51 /*--------------------- Static Variables --------------------------*/
52 static int msglevel = MSG_LEVEL_INFO;
53 static const unsigned char acbyIERate[MAX_RATE] =
54 {0x02, 0x04, 0x0B, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
56 #define AUTORATE_TXOK_CNT 0x0400
57 #define AUTORATE_TXFAIL_CNT 0x0064
58 #define AUTORATE_TIMEOUT 10
60 /*--------------------- Static Functions --------------------------*/
63 PKnownNodeDB psNodeDBTable
68 PKnownNodeDB psNodeDBTable
73 // clear statistic counter for auto_rate
74 for (ii = 0; ii <= MAX_RATE; ii++) {
75 psNodeDBTable->uTxOk[ii] = 0;
76 psNodeDBTable->uTxFail[ii] = 0;
80 /*--------------------- Export Variables --------------------------*/
82 /*--------------------- Export Functions --------------------------*/
87 * Get RateIdx from the value in SuppRates IE or ExtSuppRates IE
91 * unsigned char - Rate value in SuppRates IE or ExtSuppRates IE
95 * Return Value: RateIdx
105 //Erase basicRate flag.
106 byRate = byRate & 0x7F;//0111 1111
108 for (ii = 0; ii < MAX_RATE; ii++) {
109 if (acbyIERate[ii] == byRate)
117 * Routine Description:
118 * Rate fallback Algorithm Implementation
122 * pDevice - Pointer to the adapter
123 * psNodeDBTable - Pointer to Node Data Base
130 #define AUTORATE_TXCNT_THRESHOLD 20
131 #define AUTORATE_INC_THRESHOLD 30
136 * Get RateIdx from the value in SuppRates IE or ExtSuppRates IE
140 * unsigned char - Rate value in SuppRates IE or ExtSuppRates IE
144 * Return Value: RateIdx
154 //Erase basicRate flag.
155 byRate = byRate & 0x7F;//0111 1111
157 for (ii = 0; ii < MAX_RATE; ii++) {
158 if (acbyIERate[ii] == byRate)
167 * Parsing the highest basic & support rate in rate field of frame.
171 * pDevice - Pointer to the adapter
172 * pItemRates - Pointer to Rate field defined in 802.11 spec.
173 * pItemExtRates - Pointer to Extended Rate field defined in 802.11 spec.
175 * pwMaxBasicRate - Maximum Basic Rate
176 * pwMaxSuppRate - Maximum Supported Rate
177 * pbyTopCCKRate - Maximum Basic Rate in CCK mode
178 * pbyTopOFDMRate - Maximum Basic Rate in OFDM mode
185 void *pDeviceHandler,
186 PWLAN_IE_SUPP_RATES pItemRates,
187 PWLAN_IE_SUPP_RATES pItemExtRates,
188 bool bUpdateBasicRate,
189 unsigned short *pwMaxBasicRate,
190 unsigned short *pwMaxSuppRate,
191 unsigned short *pwSuppRate,
192 unsigned char *pbyTopCCKRate,
193 unsigned char *pbyTopOFDMRate
196 PSDevice pDevice = (PSDevice) pDeviceHandler;
198 unsigned char byHighSuppRate = 0;
199 unsigned char byRate = 0;
200 unsigned short wOldBasicRate = pDevice->wBasicRate;
201 unsigned int uRateLen;
203 if (pItemRates == NULL)
207 uRateLen = pItemRates->len;
209 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ParseMaxRate Len: %d\n", uRateLen);
210 if (pDevice->eCurrentPHYType != PHY_TYPE_11B) {
211 if (uRateLen > WLAN_RATES_MAXLEN)
212 uRateLen = WLAN_RATES_MAXLEN;
214 if (uRateLen > WLAN_RATES_MAXLEN_11B)
215 uRateLen = WLAN_RATES_MAXLEN_11B;
218 for (ii = 0; ii < uRateLen; ii++) {
219 byRate = (unsigned char)(pItemRates->abyRates[ii]);
220 if (WLAN_MGMT_IS_BASICRATE(byRate) && bUpdateBasicRate) {
221 // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate
222 CARDbAddBasicRate((void *)pDevice, wGetRateIdx(byRate));
223 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate));
225 byRate = (unsigned char)(pItemRates->abyRates[ii]&0x7F);
226 if (byHighSuppRate == 0)
227 byHighSuppRate = byRate;
228 if (byRate > byHighSuppRate)
229 byHighSuppRate = byRate;
230 *pwSuppRate |= (1<<wGetRateIdx(byRate));
232 if ((pItemExtRates != NULL) && (pItemExtRates->byElementID == WLAN_EID_EXTSUPP_RATES) &&
233 (pDevice->eCurrentPHYType != PHY_TYPE_11B)) {
234 unsigned int uExtRateLen = pItemExtRates->len;
236 if (uExtRateLen > WLAN_RATES_MAXLEN)
237 uExtRateLen = WLAN_RATES_MAXLEN;
239 for (ii = 0; ii < uExtRateLen; ii++) {
240 byRate = (unsigned char)(pItemExtRates->abyRates[ii]);
241 // select highest basic rate
242 if (WLAN_MGMT_IS_BASICRATE(pItemExtRates->abyRates[ii])) {
243 // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate
244 CARDbAddBasicRate((void *)pDevice, wGetRateIdx(byRate));
245 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate));
247 byRate = (unsigned char)(pItemExtRates->abyRates[ii]&0x7F);
248 if (byHighSuppRate == 0)
249 byHighSuppRate = byRate;
250 if (byRate > byHighSuppRate)
251 byHighSuppRate = byRate;
252 *pwSuppRate |= (1<<wGetRateIdx(byRate));
256 if ((pDevice->byPacketType == PK_TYPE_11GB) && CARDbIsOFDMinBasicRate((void *)pDevice)) {
257 pDevice->byPacketType = PK_TYPE_11GA;
260 *pbyTopCCKRate = pDevice->byTopCCKBasicRate;
261 *pbyTopOFDMRate = pDevice->byTopOFDMBasicRate;
262 *pwMaxSuppRate = wGetRateIdx(byHighSuppRate);
263 if ((pDevice->byPacketType == PK_TYPE_11B) || (pDevice->byPacketType == PK_TYPE_11GB))
264 *pwMaxBasicRate = pDevice->byTopCCKBasicRate;
266 *pwMaxBasicRate = pDevice->byTopOFDMBasicRate;
267 if (wOldBasicRate != pDevice->wBasicRate)
268 CARDvSetRSPINF((void *)pDevice, pDevice->eCurrentPHYType);
270 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Exit ParseMaxRate\n");
275 * Routine Description:
276 * Rate fallback Algorithm Implementaion
280 * pDevice - Pointer to the adapter
281 * psNodeDBTable - Pointer to Node Data Base
288 #define AUTORATE_TXCNT_THRESHOLD 20
289 #define AUTORATE_INC_THRESHOLD 30
293 void *pDeviceHandler,
294 PKnownNodeDB psNodeDBTable
297 PSDevice pDevice = (PSDevice) pDeviceHandler;
298 unsigned short wIdxDownRate = 0;
300 bool bAutoRate[MAX_RATE] = {true, true, true, true, false, false, true, true, true, true, true, true};
301 unsigned long dwThroughputTbl[MAX_RATE] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540};
302 unsigned long dwThroughput = 0;
303 unsigned short wIdxUpRate = 0;
304 unsigned long dwTxDiff = 0;
306 if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
307 // Don't do Fallback when scanning Channel
311 psNodeDBTable->uTimeCount++;
313 if (psNodeDBTable->uTxFail[MAX_RATE] > psNodeDBTable->uTxOk[MAX_RATE])
314 dwTxDiff = psNodeDBTable->uTxFail[MAX_RATE] - psNodeDBTable->uTxOk[MAX_RATE];
316 if ((psNodeDBTable->uTxOk[MAX_RATE] < AUTORATE_TXOK_CNT) &&
317 (dwTxDiff < AUTORATE_TXFAIL_CNT) &&
318 (psNodeDBTable->uTimeCount < AUTORATE_TIMEOUT)) {
322 if (psNodeDBTable->uTimeCount >= AUTORATE_TIMEOUT) {
323 psNodeDBTable->uTimeCount = 0;
326 for (ii = 0; ii < MAX_RATE; ii++) {
327 if (psNodeDBTable->wSuppRate & (0x0001<<ii)) {
329 wIdxUpRate = (unsigned short) ii;
332 bAutoRate[ii] = false;
336 for (ii = 0; ii <= psNodeDBTable->wTxDataRate; ii++) {
337 if ((psNodeDBTable->uTxOk[ii] != 0) ||
338 (psNodeDBTable->uTxFail[ii] != 0)) {
339 dwThroughputTbl[ii] *= psNodeDBTable->uTxOk[ii];
341 psNodeDBTable->uTxFail[ii] *= 4;
343 dwThroughputTbl[ii] /= (psNodeDBTable->uTxOk[ii] + psNodeDBTable->uTxFail[ii]);
346 dwThroughput = dwThroughputTbl[psNodeDBTable->wTxDataRate];
348 wIdxDownRate = psNodeDBTable->wTxDataRate;
349 for (ii = psNodeDBTable->wTxDataRate; ii > 0;) {
351 if ((dwThroughputTbl[ii] > dwThroughput) && bAutoRate[ii]) {
352 dwThroughput = dwThroughputTbl[ii];
353 wIdxDownRate = (unsigned short) ii;
356 psNodeDBTable->wTxDataRate = wIdxDownRate;
357 if (psNodeDBTable->uTxOk[MAX_RATE]) {
358 if (psNodeDBTable->uTxOk[MAX_RATE] >
359 (psNodeDBTable->uTxFail[MAX_RATE] * 4)) {
360 psNodeDBTable->wTxDataRate = wIdxUpRate;
362 } else { // adhoc, if uTxOk =0 & uTxFail = 0
363 if (psNodeDBTable->uTxFail[MAX_RATE] == 0)
364 psNodeDBTable->wTxDataRate = wIdxUpRate;
366 //2008-5-8 <add> by chester
367 TxRate_iwconfig = psNodeDBTable->wTxDataRate;
368 s_vResetCounter(psNodeDBTable);
376 * This routine is used to assemble available Rate IE.
388 PWLAN_IE_SUPP_RATES pSrcRates,
389 PWLAN_IE_SUPP_RATES pDstRates,
390 unsigned int uRateLen
393 unsigned int ii, uu, uRateCnt = 0;
395 if ((pSrcRates == NULL) || (pDstRates == NULL))
398 if (pSrcRates->len == 0)
401 for (ii = 0; ii < uRateLen; ii++) {
402 for (uu = 0; uu < pSrcRates->len; uu++) {
403 if ((pSrcRates->abyRates[uu] & 0x7F) == acbyIERate[ii]) {
404 pDstRates->abyRates[uRateCnt++] = pSrcRates->abyRates[uu];
409 return (unsigned char)uRateCnt;