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 int msglevel = MSG_LEVEL_DEBUG; */
47 static int msglevel
=MSG_LEVEL_INFO
;
48 const u8 acbyIERate
[MAX_RATE
] =
49 {0x02, 0x04, 0x0B, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
51 #define AUTORATE_TXOK_CNT 0x0400
52 #define AUTORATE_TXFAIL_CNT 0x0064
53 #define AUTORATE_TIMEOUT 10
55 void s_vResetCounter(PKnownNodeDB psNodeDBTable
);
57 void s_vResetCounter(PKnownNodeDB psNodeDBTable
)
61 /* clear statistics counter for auto_rate */
62 for (ii
= 0; ii
<= MAX_RATE
; ii
++) {
63 psNodeDBTable
->uTxOk
[ii
] = 0;
64 psNodeDBTable
->uTxFail
[ii
] = 0;
70 * Routine Description:
71 * Rate fallback Algorithm Implementaion
75 * pDevice - Pointer to the adapter
76 * psNodeDBTable - Pointer to Node Data Base
83 #define AUTORATE_TXCNT_THRESHOLD 20
84 #define AUTORATE_INC_THRESHOLD 30
89 * Get RateIdx from the value in SuppRates IE or ExtSuppRates IE
93 * u8 - Rate value in SuppRates IE or ExtSuppRates IE
97 * Return Value: RateIdx
107 /* erase BasicRate flag */
108 byRate
= byRate
& 0x7F;
110 for (ii
= 0; ii
< MAX_RATE
; ii
++) {
111 if (acbyIERate
[ii
] == byRate
)
120 * Parsing the highest basic & support rate in rate field of frame.
124 * pDevice - Pointer to the adapter
125 * pItemRates - Pointer to Rate field defined in 802.11 spec.
126 * pItemExtRates - Pointer to Extended Rate field defined in 802.11 spec.
128 * pwMaxBasicRate - Maximum Basic Rate
129 * pwMaxSuppRate - Maximum Supported Rate
130 * pbyTopCCKRate - Maximum Basic Rate in CCK mode
131 * pbyTopOFDMRate - Maximum Basic Rate in OFDM mode
137 void RATEvParseMaxRate(struct vnt_private
*pDevice
,
138 PWLAN_IE_SUPP_RATES pItemRates
, PWLAN_IE_SUPP_RATES pItemExtRates
,
139 int bUpdateBasicRate
, u16
*pwMaxBasicRate
, u16
*pwMaxSuppRate
,
140 u16
*pwSuppRate
, u8
*pbyTopCCKRate
, u8
*pbyTopOFDMRate
)
143 u8 byHighSuppRate
= 0, byRate
= 0;
144 u16 wOldBasicRate
= pDevice
->wBasicRate
;
147 if (pItemRates
== NULL
)
151 uRateLen
= pItemRates
->len
;
153 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ParseMaxRate Len: %d\n", uRateLen
);
154 if (pDevice
->byBBType
!= BB_TYPE_11B
) {
155 if (uRateLen
> WLAN_RATES_MAXLEN
)
156 uRateLen
= WLAN_RATES_MAXLEN
;
158 if (uRateLen
> WLAN_RATES_MAXLEN_11B
)
159 uRateLen
= WLAN_RATES_MAXLEN_11B
;
162 for (ii
= 0; ii
< uRateLen
; ii
++) {
163 byRate
= (u8
)(pItemRates
->abyRates
[ii
]);
164 if (WLAN_MGMT_IS_BASICRATE(byRate
) &&
165 (bUpdateBasicRate
== true)) {
167 * add to basic rate set, update pDevice->byTopCCKBasicRate and
168 * pDevice->byTopOFDMBasicRate
170 CARDbAddBasicRate((void *)pDevice
, RATEwGetRateIdx(byRate
));
171 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ParseMaxRate AddBasicRate: %d\n", RATEwGetRateIdx(byRate
));
173 byRate
= (u8
)(pItemRates
->abyRates
[ii
]&0x7F);
174 if (byHighSuppRate
== 0)
175 byHighSuppRate
= byRate
;
176 if (byRate
> byHighSuppRate
)
177 byHighSuppRate
= byRate
;
178 *pwSuppRate
|= (1<<RATEwGetRateIdx(byRate
));
180 if ((pItemExtRates
!= NULL
) && (pItemExtRates
->byElementID
== WLAN_EID_EXTSUPP_RATES
) &&
181 (pDevice
->byBBType
!= BB_TYPE_11B
)) {
183 unsigned int uExtRateLen
= pItemExtRates
->len
;
185 if (uExtRateLen
> WLAN_RATES_MAXLEN
)
186 uExtRateLen
= WLAN_RATES_MAXLEN
;
188 for (ii
= 0; ii
< uExtRateLen
; ii
++) {
189 byRate
= (u8
)(pItemExtRates
->abyRates
[ii
]);
190 /* select highest basic rate */
191 if (WLAN_MGMT_IS_BASICRATE(pItemExtRates
->abyRates
[ii
])) {
193 * add to basic rate set, update pDevice->byTopCCKBasicRate and
194 * pDevice->byTopOFDMBasicRate
196 CARDbAddBasicRate((void *)pDevice
, RATEwGetRateIdx(byRate
));
197 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"ParseMaxRate AddBasicRate: %d\n", RATEwGetRateIdx(byRate
));
199 byRate
= (u8
)(pItemExtRates
->abyRates
[ii
]&0x7F);
200 if (byHighSuppRate
== 0)
201 byHighSuppRate
= byRate
;
202 if (byRate
> byHighSuppRate
)
203 byHighSuppRate
= byRate
;
204 *pwSuppRate
|= (1<<RATEwGetRateIdx(byRate
));
206 /* DBG_PRN_GRP09(("ParseMaxRate : HighSuppRate: %d, %X\n",
207 RATEwGetRateIdx(byRate), byRate)); */
211 if ((pDevice
->byPacketType
== PK_TYPE_11GB
)
212 && CARDbIsOFDMinBasicRate((void *)pDevice
)) {
213 pDevice
->byPacketType
= PK_TYPE_11GA
;
216 *pbyTopCCKRate
= pDevice
->byTopCCKBasicRate
;
217 *pbyTopOFDMRate
= pDevice
->byTopOFDMBasicRate
;
218 *pwMaxSuppRate
= RATEwGetRateIdx(byHighSuppRate
);
219 if ((pDevice
->byPacketType
==PK_TYPE_11B
) || (pDevice
->byPacketType
==PK_TYPE_11GB
))
220 *pwMaxBasicRate
= pDevice
->byTopCCKBasicRate
;
222 *pwMaxBasicRate
= pDevice
->byTopOFDMBasicRate
;
223 if (wOldBasicRate
!= pDevice
->wBasicRate
)
224 CARDvSetRSPINF((void *)pDevice
, pDevice
->byBBType
);
226 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Exit ParseMaxRate\n");
231 * Routine Description:
232 * Rate fallback Algorithm Implementaion
236 * pDevice - Pointer to the adapter
237 * psNodeDBTable - Pointer to Node Data Base
244 #define AUTORATE_TXCNT_THRESHOLD 20
245 #define AUTORATE_INC_THRESHOLD 30
247 void RATEvTxRateFallBack(struct vnt_private
*pDevice
,
248 PKnownNodeDB psNodeDBTable
)
250 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
251 u16 wIdxDownRate
= 0;
253 int bAutoRate
[MAX_RATE
] = {true, true, true, true, false, false, true,
254 true, true, true, true, true};
255 u32 dwThroughputTbl
[MAX_RATE
] = {10, 20, 55, 110, 60, 90, 120, 180,
257 u32 dwThroughput
= 0;
261 if (pMgmt
->eScanState
!= WMAC_NO_SCANNING
)
262 return; /* Don't do Fallback when scanning Channel */
264 psNodeDBTable
->uTimeCount
++;
266 if (psNodeDBTable
->uTxFail
[MAX_RATE
] > psNodeDBTable
->uTxOk
[MAX_RATE
])
267 dwTxDiff
= psNodeDBTable
->uTxFail
[MAX_RATE
] - psNodeDBTable
->uTxOk
[MAX_RATE
];
269 if ((psNodeDBTable
->uTxOk
[MAX_RATE
] < AUTORATE_TXOK_CNT
) &&
270 (dwTxDiff
< AUTORATE_TXFAIL_CNT
) &&
271 (psNodeDBTable
->uTimeCount
< AUTORATE_TIMEOUT
)) {
275 if (psNodeDBTable
->uTimeCount
>= AUTORATE_TIMEOUT
) {
276 psNodeDBTable
->uTimeCount
= 0;
279 for (ii
= 0; ii
< MAX_RATE
; ii
++) {
280 if (psNodeDBTable
->wSuppRate
& (0x0001<<ii
)) {
281 if (bAutoRate
[ii
] == true) {
282 wIdxUpRate
= (u16
) ii
;
285 bAutoRate
[ii
] = false;
289 for (ii
= 0; ii
<= psNodeDBTable
->wTxDataRate
; ii
++) {
290 if ( (psNodeDBTable
->uTxOk
[ii
] != 0) ||
291 (psNodeDBTable
->uTxFail
[ii
] != 0) ) {
292 dwThroughputTbl
[ii
] *= psNodeDBTable
->uTxOk
[ii
];
294 psNodeDBTable
->uTxFail
[ii
] *= 4;
296 dwThroughputTbl
[ii
] /= (psNodeDBTable
->uTxOk
[ii
] + psNodeDBTable
->uTxFail
[ii
]);
298 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Rate %d,Ok: %d, Fail:%d, Throughput:%d\n",
299 ii
, (int)psNodeDBTable
->uTxOk
[ii
], (int)psNodeDBTable
->uTxFail
[ii
], (int)dwThroughputTbl
[ii
]);
301 dwThroughput
= dwThroughputTbl
[psNodeDBTable
->wTxDataRate
];
303 wIdxDownRate
= psNodeDBTable
->wTxDataRate
;
304 for (ii
= psNodeDBTable
->wTxDataRate
; ii
> 0;) {
306 if ( (dwThroughputTbl
[ii
] > dwThroughput
) &&
307 (bAutoRate
[ii
]==true) ) {
308 dwThroughput
= dwThroughputTbl
[ii
];
309 wIdxDownRate
= (u16
) ii
;
312 psNodeDBTable
->wTxDataRate
= wIdxDownRate
;
313 if (psNodeDBTable
->uTxOk
[MAX_RATE
]) {
314 if (psNodeDBTable
->uTxOk
[MAX_RATE
] >
315 (psNodeDBTable
->uTxFail
[MAX_RATE
] * 4) ) {
316 psNodeDBTable
->wTxDataRate
= wIdxUpRate
;
318 } else { /* adhoc, if uTxOk(total) == 0 & uTxFail(total) == 0 */
319 if (psNodeDBTable
->uTxFail
[MAX_RATE
] == 0)
320 psNodeDBTable
->wTxDataRate
= wIdxUpRate
;
323 if (pDevice
->byBBType
== BB_TYPE_11A
) {
324 if (psNodeDBTable
->wTxDataRate
<= RATE_11M
)
325 psNodeDBTable
->wTxDataRate
= RATE_6M
;
327 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"uTxOk[MAX_RATE] %d, uTxFail[MAX_RATE]:%d\n",(int)psNodeDBTable
->uTxOk
[MAX_RATE
], (int)psNodeDBTable
->uTxFail
[MAX_RATE
]);
328 s_vResetCounter(psNodeDBTable
);
329 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Rate: %d, U:%d, D:%d\n", (int)psNodeDBTable
->wTxDataRate
, (int)wIdxUpRate
, (int)wIdxDownRate
);
336 * This routine is used to assemble available Rate IE.
348 PWLAN_IE_SUPP_RATES pSrcRates
,
349 PWLAN_IE_SUPP_RATES pDstRates
,
350 unsigned int uRateLen
353 unsigned int ii
, uu
, uRateCnt
= 0;
355 if ((pSrcRates
== NULL
) || (pDstRates
== NULL
))
358 if (pSrcRates
->len
== 0)
361 for (ii
= 0; ii
< uRateLen
; ii
++) {
362 for (uu
= 0; uu
< pSrcRates
->len
; uu
++) {
363 if ((pSrcRates
->abyRates
[uu
] & 0x7F) == acbyIERate
[ii
]) {
364 pDstRates
->abyRates
[uRateCnt
++] = pSrcRates
->abyRates
[uu
];