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