Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 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. |
| 9 | * |
| 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. |
| 14 | * |
| 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. |
| 18 | * |
| 19 | * File: datarate.c |
| 20 | * |
| 21 | * Purpose: Handles the auto fallback & data rates functions |
| 22 | * |
| 23 | * Author: Lyndon Chen |
| 24 | * |
| 25 | * Date: July 17, 2002 |
| 26 | * |
| 27 | * 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. |
| 31 | * |
| 32 | * Revision History: |
| 33 | * |
| 34 | */ |
| 35 | |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 36 | #include "ttype.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 37 | #include "tmacro.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 38 | #include "mac.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 39 | #include "80211mgr.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 40 | #include "bssdb.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 41 | #include "datarate.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 42 | #include "card.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 43 | #include "baseband.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 44 | #include "srom.h" |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 45 | |
| 46 | /*--------------------- Static Definitions -------------------------*/ |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | /*--------------------- Static Classes ----------------------------*/ |
| 52 | |
| 53 | |
Charles Clément | 2986db5 | 2010-06-24 11:02:26 -0700 | [diff] [blame] | 54 | extern unsigned short TxRate_iwconfig; //2008-5-8 <add> by chester |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 55 | /*--------------------- Static Variables --------------------------*/ |
| 56 | //static int msglevel =MSG_LEVEL_DEBUG; |
| 57 | static int msglevel =MSG_LEVEL_INFO; |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 58 | const unsigned char acbyIERate[MAX_RATE] = |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 59 | {0x02, 0x04, 0x0B, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C}; |
| 60 | |
| 61 | #define AUTORATE_TXOK_CNT 0x0400 |
| 62 | #define AUTORATE_TXFAIL_CNT 0x0064 |
| 63 | #define AUTORATE_TIMEOUT 10 |
| 64 | |
| 65 | /*--------------------- Static Functions --------------------------*/ |
| 66 | |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 67 | void s_vResetCounter ( |
Charles Clément | 3a215e0 | 2010-05-12 20:54:39 -0700 | [diff] [blame] | 68 | PKnownNodeDB psNodeDBTable |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 69 | ); |
| 70 | |
| 71 | |
| 72 | |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 73 | void |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 74 | s_vResetCounter ( |
Charles Clément | 3a215e0 | 2010-05-12 20:54:39 -0700 | [diff] [blame] | 75 | PKnownNodeDB psNodeDBTable |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 76 | ) |
| 77 | { |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 78 | unsigned char ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 79 | |
| 80 | // clear statistic counter for auto_rate |
| 81 | for(ii=0;ii<=MAX_RATE;ii++) { |
| 82 | psNodeDBTable->uTxOk[ii] = 0; |
| 83 | psNodeDBTable->uTxFail[ii] = 0; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /*--------------------- Export Variables --------------------------*/ |
| 88 | |
| 89 | |
| 90 | /*--------------------- Export Functions --------------------------*/ |
| 91 | |
| 92 | |
| 93 | /*+ |
| 94 | * |
| 95 | * Description: |
| 96 | * Get RateIdx from the value in SuppRates IE or ExtSuppRates IE |
| 97 | * |
| 98 | * Parameters: |
| 99 | * In: |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 100 | * unsigned char - Rate value in SuppRates IE or ExtSuppRates IE |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 101 | * Out: |
| 102 | * none |
| 103 | * |
| 104 | * Return Value: RateIdx |
| 105 | * |
| 106 | -*/ |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 107 | unsigned char |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 108 | DATARATEbyGetRateIdx ( |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 109 | unsigned char byRate |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 110 | ) |
| 111 | { |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 112 | unsigned char ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 113 | |
| 114 | //Erase basicRate flag. |
| 115 | byRate = byRate & 0x7F;//0111 1111 |
| 116 | |
| 117 | for (ii = 0; ii < MAX_RATE; ii ++) { |
| 118 | if (acbyIERate[ii] == byRate) |
| 119 | return ii; |
| 120 | } |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | |
| 125 | |
| 126 | /*+ |
| 127 | * |
| 128 | * Routine Description: |
| 129 | * Rate fallback Algorithm Implementaion |
| 130 | * |
| 131 | * Parameters: |
| 132 | * In: |
| 133 | * pDevice - Pointer to the adapter |
| 134 | * psNodeDBTable - Pointer to Node Data Base |
| 135 | * Out: |
| 136 | * none |
| 137 | * |
| 138 | * Return Value: none |
| 139 | * |
| 140 | -*/ |
| 141 | #define AUTORATE_TXCNT_THRESHOLD 20 |
| 142 | #define AUTORATE_INC_THRESHOLD 30 |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | /*+ |
| 148 | * |
| 149 | * Description: |
| 150 | * Get RateIdx from the value in SuppRates IE or ExtSuppRates IE |
| 151 | * |
| 152 | * Parameters: |
| 153 | * In: |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 154 | * unsigned char - Rate value in SuppRates IE or ExtSuppRates IE |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 155 | * Out: |
| 156 | * none |
| 157 | * |
| 158 | * Return Value: RateIdx |
| 159 | * |
| 160 | -*/ |
Charles Clément | 2986db5 | 2010-06-24 11:02:26 -0700 | [diff] [blame] | 161 | unsigned short |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 162 | wGetRateIdx( |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 163 | unsigned char byRate |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 164 | ) |
| 165 | { |
Charles Clément | 2986db5 | 2010-06-24 11:02:26 -0700 | [diff] [blame] | 166 | unsigned short ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 167 | |
| 168 | //Erase basicRate flag. |
| 169 | byRate = byRate & 0x7F;//0111 1111 |
| 170 | |
| 171 | for (ii = 0; ii < MAX_RATE; ii ++) { |
| 172 | if (acbyIERate[ii] == byRate) |
| 173 | return ii; |
| 174 | } |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | /*+ |
| 179 | * |
| 180 | * Description: |
| 181 | * Parsing the highest basic & support rate in rate field of frame. |
| 182 | * |
| 183 | * Parameters: |
| 184 | * In: |
| 185 | * pDevice - Pointer to the adapter |
| 186 | * pItemRates - Pointer to Rate field defined in 802.11 spec. |
| 187 | * pItemExtRates - Pointer to Extended Rate field defined in 802.11 spec. |
| 188 | * Out: |
| 189 | * pwMaxBasicRate - Maximum Basic Rate |
| 190 | * pwMaxSuppRate - Maximum Supported Rate |
| 191 | * pbyTopCCKRate - Maximum Basic Rate in CCK mode |
| 192 | * pbyTopOFDMRate - Maximum Basic Rate in OFDM mode |
| 193 | * |
| 194 | * Return Value: none |
| 195 | * |
| 196 | -*/ |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 197 | void |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 198 | RATEvParseMaxRate ( |
Charles Clément | 3a215e0 | 2010-05-12 20:54:39 -0700 | [diff] [blame] | 199 | void *pDeviceHandler, |
| 200 | PWLAN_IE_SUPP_RATES pItemRates, |
| 201 | PWLAN_IE_SUPP_RATES pItemExtRates, |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 202 | bool bUpdateBasicRate, |
Charles Clément | 15df6c2 | 2010-06-05 15:13:48 -0700 | [diff] [blame] | 203 | unsigned short *pwMaxBasicRate, |
| 204 | unsigned short *pwMaxSuppRate, |
| 205 | unsigned short *pwSuppRate, |
Charles Clément | 2989e96 | 2010-06-05 15:13:47 -0700 | [diff] [blame] | 206 | unsigned char *pbyTopCCKRate, |
| 207 | unsigned char *pbyTopOFDMRate |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 208 | ) |
| 209 | { |
| 210 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 211 | unsigned int ii; |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 212 | unsigned char byHighSuppRate = 0; |
| 213 | unsigned char byRate = 0; |
Charles Clément | 2986db5 | 2010-06-24 11:02:26 -0700 | [diff] [blame] | 214 | unsigned short wOldBasicRate = pDevice->wBasicRate; |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 215 | unsigned int uRateLen; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 216 | |
| 217 | |
| 218 | if (pItemRates == NULL) |
| 219 | return; |
| 220 | |
| 221 | *pwSuppRate = 0; |
| 222 | uRateLen = pItemRates->len; |
| 223 | |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 224 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate Len: %d\n", uRateLen); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 225 | if (pDevice->eCurrentPHYType != PHY_TYPE_11B) { |
| 226 | if (uRateLen > WLAN_RATES_MAXLEN) |
| 227 | uRateLen = WLAN_RATES_MAXLEN; |
| 228 | } else { |
| 229 | if (uRateLen > WLAN_RATES_MAXLEN_11B) |
| 230 | uRateLen = WLAN_RATES_MAXLEN_11B; |
| 231 | } |
| 232 | |
| 233 | for (ii = 0; ii < uRateLen; ii++) { |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 234 | byRate = (unsigned char)(pItemRates->abyRates[ii]); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 235 | if (WLAN_MGMT_IS_BASICRATE(byRate) && |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 236 | (bUpdateBasicRate == true)) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 237 | // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate |
Charles Clément | 830a619 | 2010-05-07 12:30:20 -0700 | [diff] [blame] | 238 | CARDbAddBasicRate((void *)pDevice, wGetRateIdx(byRate)); |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 239 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 240 | } |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 241 | byRate = (unsigned char)(pItemRates->abyRates[ii]&0x7F); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 242 | if (byHighSuppRate == 0) |
| 243 | byHighSuppRate = byRate; |
| 244 | if (byRate > byHighSuppRate) |
| 245 | byHighSuppRate = byRate; |
| 246 | *pwSuppRate |= (1<<wGetRateIdx(byRate)); |
| 247 | } |
| 248 | if ((pItemExtRates != NULL) && (pItemExtRates->byElementID == WLAN_EID_EXTSUPP_RATES) && |
| 249 | (pDevice->eCurrentPHYType != PHY_TYPE_11B)) { |
| 250 | |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 251 | unsigned int uExtRateLen = pItemExtRates->len; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 252 | |
| 253 | if (uExtRateLen > WLAN_RATES_MAXLEN) |
| 254 | uExtRateLen = WLAN_RATES_MAXLEN; |
| 255 | |
| 256 | for (ii = 0; ii < uExtRateLen ; ii++) { |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 257 | byRate = (unsigned char)(pItemExtRates->abyRates[ii]); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 258 | // select highest basic rate |
| 259 | if (WLAN_MGMT_IS_BASICRATE(pItemExtRates->abyRates[ii])) { |
| 260 | // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate |
Charles Clément | 830a619 | 2010-05-07 12:30:20 -0700 | [diff] [blame] | 261 | CARDbAddBasicRate((void *)pDevice, wGetRateIdx(byRate)); |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 262 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate)); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 263 | } |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 264 | byRate = (unsigned char)(pItemExtRates->abyRates[ii]&0x7F); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 265 | if (byHighSuppRate == 0) |
| 266 | byHighSuppRate = byRate; |
| 267 | if (byRate > byHighSuppRate) |
| 268 | byHighSuppRate = byRate; |
| 269 | *pwSuppRate |= (1<<wGetRateIdx(byRate)); |
| 270 | //DBG_PRN_GRP09(("ParseMaxRate : HighSuppRate: %d, %X\n", wGetRateIdx(byRate), byRate)); |
| 271 | } |
| 272 | } //if(pItemExtRates != NULL) |
| 273 | |
Charles Clément | 830a619 | 2010-05-07 12:30:20 -0700 | [diff] [blame] | 274 | if ((pDevice->byPacketType == PK_TYPE_11GB) && CARDbIsOFDMinBasicRate((void *)pDevice)) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 275 | pDevice->byPacketType = PK_TYPE_11GA; |
| 276 | } |
| 277 | |
| 278 | *pbyTopCCKRate = pDevice->byTopCCKBasicRate; |
| 279 | *pbyTopOFDMRate = pDevice->byTopOFDMBasicRate; |
| 280 | *pwMaxSuppRate = wGetRateIdx(byHighSuppRate); |
| 281 | if ((pDevice->byPacketType==PK_TYPE_11B) || (pDevice->byPacketType==PK_TYPE_11GB)) |
| 282 | *pwMaxBasicRate = pDevice->byTopCCKBasicRate; |
| 283 | else |
| 284 | *pwMaxBasicRate = pDevice->byTopOFDMBasicRate; |
| 285 | if (wOldBasicRate != pDevice->wBasicRate) |
Charles Clément | 830a619 | 2010-05-07 12:30:20 -0700 | [diff] [blame] | 286 | CARDvSetRSPINF((void *)pDevice, pDevice->eCurrentPHYType); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 287 | |
Jim Lieb | 7e809a9 | 2009-07-30 10:27:21 -0700 | [diff] [blame] | 288 | DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Exit ParseMaxRate\n"); |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | |
| 292 | /*+ |
| 293 | * |
| 294 | * Routine Description: |
| 295 | * Rate fallback Algorithm Implementaion |
| 296 | * |
| 297 | * Parameters: |
| 298 | * In: |
| 299 | * pDevice - Pointer to the adapter |
| 300 | * psNodeDBTable - Pointer to Node Data Base |
| 301 | * Out: |
| 302 | * none |
| 303 | * |
| 304 | * Return Value: none |
| 305 | * |
| 306 | -*/ |
| 307 | #define AUTORATE_TXCNT_THRESHOLD 20 |
| 308 | #define AUTORATE_INC_THRESHOLD 30 |
| 309 | |
Charles Clément | 6b35b7b | 2010-05-07 12:30:19 -0700 | [diff] [blame] | 310 | void |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 311 | RATEvTxRateFallBack ( |
Charles Clément | 3a215e0 | 2010-05-12 20:54:39 -0700 | [diff] [blame] | 312 | void *pDeviceHandler, |
| 313 | PKnownNodeDB psNodeDBTable |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 314 | ) |
| 315 | { |
| 316 | PSDevice pDevice = (PSDevice) pDeviceHandler; |
Charles Clément | 2986db5 | 2010-06-24 11:02:26 -0700 | [diff] [blame] | 317 | unsigned short wIdxDownRate = 0; |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 318 | unsigned int ii; |
Charles Clément | 0f4c60d | 2010-06-24 11:02:25 -0700 | [diff] [blame] | 319 | //unsigned long dwRateTable[MAX_RATE] = {1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54}; |
Charles Clément | 7b6a001 | 2010-08-01 17:15:50 +0200 | [diff] [blame] | 320 | bool bAutoRate[MAX_RATE] = {true,true,true,true,false,false,true,true,true,true,true,true}; |
Charles Clément | 0f4c60d | 2010-06-24 11:02:25 -0700 | [diff] [blame] | 321 | unsigned long dwThroughputTbl[MAX_RATE] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540}; |
| 322 | unsigned long dwThroughput = 0; |
Charles Clément | 2986db5 | 2010-06-24 11:02:26 -0700 | [diff] [blame] | 323 | unsigned short wIdxUpRate = 0; |
Charles Clément | 0f4c60d | 2010-06-24 11:02:25 -0700 | [diff] [blame] | 324 | unsigned long dwTxDiff = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 325 | |
| 326 | if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) { |
| 327 | // Don't do Fallback when scanning Channel |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | psNodeDBTable->uTimeCount ++; |
| 332 | |
| 333 | if (psNodeDBTable->uTxFail[MAX_RATE] > psNodeDBTable->uTxOk[MAX_RATE]) |
| 334 | dwTxDiff = psNodeDBTable->uTxFail[MAX_RATE] - psNodeDBTable->uTxOk[MAX_RATE]; |
| 335 | |
| 336 | if ((psNodeDBTable->uTxOk[MAX_RATE] < AUTORATE_TXOK_CNT) && |
| 337 | (dwTxDiff < AUTORATE_TXFAIL_CNT) && |
| 338 | (psNodeDBTable->uTimeCount < AUTORATE_TIMEOUT)) { |
| 339 | return; |
| 340 | } |
| 341 | |
| 342 | if (psNodeDBTable->uTimeCount >= AUTORATE_TIMEOUT) { |
| 343 | psNodeDBTable->uTimeCount = 0; |
| 344 | } |
| 345 | |
| 346 | |
| 347 | for(ii=0;ii<MAX_RATE;ii++) { |
| 348 | if (psNodeDBTable->wSuppRate & (0x0001<<ii)) { |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 349 | if (bAutoRate[ii] == true) { |
Charles Clément | 2986db5 | 2010-06-24 11:02:26 -0700 | [diff] [blame] | 350 | wIdxUpRate = (unsigned short) ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 351 | } |
| 352 | } else { |
Charles Clément | 5a5a2a6 | 2010-08-01 17:15:49 +0200 | [diff] [blame] | 353 | bAutoRate[ii] = false; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
| 357 | for(ii=0;ii<=psNodeDBTable->wTxDataRate;ii++) { |
| 358 | if ( (psNodeDBTable->uTxOk[ii] != 0) || |
| 359 | (psNodeDBTable->uTxFail[ii] != 0) ) { |
| 360 | dwThroughputTbl[ii] *= psNodeDBTable->uTxOk[ii]; |
| 361 | if (ii < RATE_11M) { |
| 362 | psNodeDBTable->uTxFail[ii] *= 4; |
| 363 | } |
| 364 | dwThroughputTbl[ii] /= (psNodeDBTable->uTxOk[ii] + psNodeDBTable->uTxFail[ii]); |
| 365 | } |
| 366 | // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rate %d,Ok: %d, Fail:%d, Throughput:%d\n", |
| 367 | // ii, psNodeDBTable->uTxOk[ii], psNodeDBTable->uTxFail[ii], dwThroughputTbl[ii]); |
| 368 | } |
| 369 | dwThroughput = dwThroughputTbl[psNodeDBTable->wTxDataRate]; |
| 370 | |
| 371 | wIdxDownRate = psNodeDBTable->wTxDataRate; |
| 372 | for(ii = psNodeDBTable->wTxDataRate; ii > 0;) { |
| 373 | ii--; |
| 374 | if ( (dwThroughputTbl[ii] > dwThroughput) && |
Charles Clément | 1b12068 | 2010-08-01 17:15:48 +0200 | [diff] [blame] | 375 | (bAutoRate[ii]==true) ) { |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 376 | dwThroughput = dwThroughputTbl[ii]; |
Charles Clément | 2986db5 | 2010-06-24 11:02:26 -0700 | [diff] [blame] | 377 | wIdxDownRate = (unsigned short) ii; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | psNodeDBTable->wTxDataRate = wIdxDownRate; |
| 381 | if (psNodeDBTable->uTxOk[MAX_RATE]) { |
| 382 | if (psNodeDBTable->uTxOk[MAX_RATE] > |
| 383 | (psNodeDBTable->uTxFail[MAX_RATE] * 4) ) { |
| 384 | psNodeDBTable->wTxDataRate = wIdxUpRate; |
| 385 | } |
| 386 | }else { // adhoc, if uTxOk =0 & uTxFail = 0 |
| 387 | if (psNodeDBTable->uTxFail[MAX_RATE] == 0) |
| 388 | psNodeDBTable->wTxDataRate = wIdxUpRate; |
| 389 | } |
| 390 | //2008-5-8 <add> by chester |
| 391 | TxRate_iwconfig=psNodeDBTable->wTxDataRate; |
| 392 | s_vResetCounter(psNodeDBTable); |
| 393 | // DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rate: %d, U:%d, D:%d\n", psNodeDBTable->wTxDataRate, wIdxUpRate, wIdxDownRate); |
| 394 | |
| 395 | return; |
| 396 | |
| 397 | } |
| 398 | |
| 399 | /*+ |
| 400 | * |
| 401 | * Description: |
| 402 | * This routine is used to assemble available Rate IE. |
| 403 | * |
| 404 | * Parameters: |
| 405 | * In: |
| 406 | * pDevice |
| 407 | * Out: |
| 408 | * |
| 409 | * Return Value: None |
| 410 | * |
| 411 | -*/ |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 412 | unsigned char |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 413 | RATEuSetIE ( |
Charles Clément | 3a215e0 | 2010-05-12 20:54:39 -0700 | [diff] [blame] | 414 | PWLAN_IE_SUPP_RATES pSrcRates, |
| 415 | PWLAN_IE_SUPP_RATES pDstRates, |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 416 | unsigned int uRateLen |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 417 | ) |
| 418 | { |
Charles Clément | b6e95cd | 2010-06-02 09:52:01 -0700 | [diff] [blame] | 419 | unsigned int ii, uu, uRateCnt = 0; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 420 | |
| 421 | if ((pSrcRates == NULL) || (pDstRates == NULL)) |
| 422 | return 0; |
| 423 | |
| 424 | if (pSrcRates->len == 0) |
| 425 | return 0; |
| 426 | |
| 427 | for (ii = 0; ii < uRateLen; ii++) { |
| 428 | for (uu = 0; uu < pSrcRates->len; uu++) { |
| 429 | if ((pSrcRates->abyRates[uu] & 0x7F) == acbyIERate[ii]) { |
| 430 | pDstRates->abyRates[uRateCnt ++] = pSrcRates->abyRates[uu]; |
| 431 | break; |
| 432 | } |
| 433 | } |
| 434 | } |
Charles Clément | 3fc9b58 | 2010-06-24 11:02:27 -0700 | [diff] [blame] | 435 | return (unsigned char)uRateCnt; |
Forest Bond | 5449c68 | 2009-04-25 10:30:44 -0400 | [diff] [blame] | 436 | } |
| 437 | |