15449c685a4b39534f18869a93896370224463715Forest Bond/*
25449c685a4b39534f18869a93896370224463715Forest Bond * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
35449c685a4b39534f18869a93896370224463715Forest Bond * All rights reserved.
45449c685a4b39534f18869a93896370224463715Forest Bond *
55449c685a4b39534f18869a93896370224463715Forest Bond * This program is free software; you can redistribute it and/or modify
65449c685a4b39534f18869a93896370224463715Forest Bond * it under the terms of the GNU General Public License as published by
75449c685a4b39534f18869a93896370224463715Forest Bond * the Free Software Foundation; either version 2 of the License, or
85449c685a4b39534f18869a93896370224463715Forest Bond * (at your option) any later version.
95449c685a4b39534f18869a93896370224463715Forest Bond *
105449c685a4b39534f18869a93896370224463715Forest Bond * This program is distributed in the hope that it will be useful,
115449c685a4b39534f18869a93896370224463715Forest Bond * but WITHOUT ANY WARRANTY; without even the implied warranty of
125449c685a4b39534f18869a93896370224463715Forest Bond * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
135449c685a4b39534f18869a93896370224463715Forest Bond * GNU General Public License for more details.
145449c685a4b39534f18869a93896370224463715Forest Bond *
155449c685a4b39534f18869a93896370224463715Forest Bond * You should have received a copy of the GNU General Public License along
165449c685a4b39534f18869a93896370224463715Forest Bond * with this program; if not, write to the Free Software Foundation, Inc.,
175449c685a4b39534f18869a93896370224463715Forest Bond * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
185449c685a4b39534f18869a93896370224463715Forest Bond *
195449c685a4b39534f18869a93896370224463715Forest Bond * File: datarate.c
205449c685a4b39534f18869a93896370224463715Forest Bond *
215449c685a4b39534f18869a93896370224463715Forest Bond * Purpose: Handles the auto fallback & data rates functions
225449c685a4b39534f18869a93896370224463715Forest Bond *
235449c685a4b39534f18869a93896370224463715Forest Bond * Author: Lyndon Chen
245449c685a4b39534f18869a93896370224463715Forest Bond *
255449c685a4b39534f18869a93896370224463715Forest Bond * Date: July 17, 2002
265449c685a4b39534f18869a93896370224463715Forest Bond *
275449c685a4b39534f18869a93896370224463715Forest Bond * Functions:
285449c685a4b39534f18869a93896370224463715Forest Bond *      RATEvParseMaxRate - Parsing the highest basic & support rate in rate field of frame
295449c685a4b39534f18869a93896370224463715Forest Bond *      RATEvTxRateFallBack - Rate fallback Algorithm Implementaion
305449c685a4b39534f18869a93896370224463715Forest Bond *      RATEuSetIE- Set rate IE field.
315449c685a4b39534f18869a93896370224463715Forest Bond *
325449c685a4b39534f18869a93896370224463715Forest Bond * Revision History:
335449c685a4b39534f18869a93896370224463715Forest Bond *
345449c685a4b39534f18869a93896370224463715Forest Bond */
355449c685a4b39534f18869a93896370224463715Forest Bond
365449c685a4b39534f18869a93896370224463715Forest Bond#include "ttype.h"
375449c685a4b39534f18869a93896370224463715Forest Bond#include "tmacro.h"
385449c685a4b39534f18869a93896370224463715Forest Bond#include "mac.h"
395449c685a4b39534f18869a93896370224463715Forest Bond#include "80211mgr.h"
405449c685a4b39534f18869a93896370224463715Forest Bond#include "bssdb.h"
415449c685a4b39534f18869a93896370224463715Forest Bond#include "datarate.h"
425449c685a4b39534f18869a93896370224463715Forest Bond#include "card.h"
435449c685a4b39534f18869a93896370224463715Forest Bond#include "baseband.h"
445449c685a4b39534f18869a93896370224463715Forest Bond#include "srom.h"
455449c685a4b39534f18869a93896370224463715Forest Bond
465449c685a4b39534f18869a93896370224463715Forest Bond/*---------------------  Static Definitions -------------------------*/
475449c685a4b39534f18869a93896370224463715Forest Bond
485449c685a4b39534f18869a93896370224463715Forest Bond
495449c685a4b39534f18869a93896370224463715Forest Bond
505449c685a4b39534f18869a93896370224463715Forest Bond
515449c685a4b39534f18869a93896370224463715Forest Bond/*---------------------  Static Classes  ----------------------------*/
525449c685a4b39534f18869a93896370224463715Forest Bond
535449c685a4b39534f18869a93896370224463715Forest Bond
542986db5fd31e312206d3ebfa4786aac04bdbe486Charles Clément extern unsigned short TxRate_iwconfig; //2008-5-8 <add> by chester
555449c685a4b39534f18869a93896370224463715Forest Bond/*---------------------  Static Variables  --------------------------*/
565449c685a4b39534f18869a93896370224463715Forest Bond//static int          msglevel                =MSG_LEVEL_DEBUG;
575449c685a4b39534f18869a93896370224463715Forest Bondstatic int          msglevel                =MSG_LEVEL_INFO;
583fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clémentconst unsigned char acbyIERate[MAX_RATE] =
595449c685a4b39534f18869a93896370224463715Forest Bond{0x02, 0x04, 0x0B, 0x16, 0x0C, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C};
605449c685a4b39534f18869a93896370224463715Forest Bond
615449c685a4b39534f18869a93896370224463715Forest Bond#define AUTORATE_TXOK_CNT       0x0400
625449c685a4b39534f18869a93896370224463715Forest Bond#define AUTORATE_TXFAIL_CNT     0x0064
635449c685a4b39534f18869a93896370224463715Forest Bond#define AUTORATE_TIMEOUT        10
645449c685a4b39534f18869a93896370224463715Forest Bond
655449c685a4b39534f18869a93896370224463715Forest Bond/*---------------------  Static Functions  --------------------------*/
665449c685a4b39534f18869a93896370224463715Forest Bond
676b35b7b3798b652a57fbce480f350aac851431c4Charles Clémentvoid s_vResetCounter (
683a215e0ff4184314f7f1a099354a272ddedff289Charles Clément    PKnownNodeDB psNodeDBTable
695449c685a4b39534f18869a93896370224463715Forest Bond    );
705449c685a4b39534f18869a93896370224463715Forest Bond
715449c685a4b39534f18869a93896370224463715Forest Bond
725449c685a4b39534f18869a93896370224463715Forest Bond
736b35b7b3798b652a57fbce480f350aac851431c4Charles Clémentvoid
745449c685a4b39534f18869a93896370224463715Forest Bonds_vResetCounter (
753a215e0ff4184314f7f1a099354a272ddedff289Charles Clément    PKnownNodeDB psNodeDBTable
765449c685a4b39534f18869a93896370224463715Forest Bond    )
775449c685a4b39534f18869a93896370224463715Forest Bond{
783fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clément    unsigned char ii;
795449c685a4b39534f18869a93896370224463715Forest Bond
805449c685a4b39534f18869a93896370224463715Forest Bond    // clear statistic counter for auto_rate
815449c685a4b39534f18869a93896370224463715Forest Bond    for(ii=0;ii<=MAX_RATE;ii++) {
825449c685a4b39534f18869a93896370224463715Forest Bond        psNodeDBTable->uTxOk[ii] = 0;
835449c685a4b39534f18869a93896370224463715Forest Bond        psNodeDBTable->uTxFail[ii] = 0;
845449c685a4b39534f18869a93896370224463715Forest Bond    }
855449c685a4b39534f18869a93896370224463715Forest Bond}
865449c685a4b39534f18869a93896370224463715Forest Bond
875449c685a4b39534f18869a93896370224463715Forest Bond/*---------------------  Export Variables  --------------------------*/
885449c685a4b39534f18869a93896370224463715Forest Bond
895449c685a4b39534f18869a93896370224463715Forest Bond
905449c685a4b39534f18869a93896370224463715Forest Bond/*---------------------  Export Functions  --------------------------*/
915449c685a4b39534f18869a93896370224463715Forest Bond
925449c685a4b39534f18869a93896370224463715Forest Bond
935449c685a4b39534f18869a93896370224463715Forest Bond/*+
945449c685a4b39534f18869a93896370224463715Forest Bond *
955449c685a4b39534f18869a93896370224463715Forest Bond * Description:
965449c685a4b39534f18869a93896370224463715Forest Bond *      Get RateIdx from the value in SuppRates IE or ExtSuppRates IE
975449c685a4b39534f18869a93896370224463715Forest Bond *
985449c685a4b39534f18869a93896370224463715Forest Bond * Parameters:
995449c685a4b39534f18869a93896370224463715Forest Bond *  In:
1003fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clément *      unsigned char - Rate value in SuppRates IE or ExtSuppRates IE
1015449c685a4b39534f18869a93896370224463715Forest Bond *  Out:
1025449c685a4b39534f18869a93896370224463715Forest Bond *      none
1035449c685a4b39534f18869a93896370224463715Forest Bond *
1045449c685a4b39534f18869a93896370224463715Forest Bond * Return Value: RateIdx
1055449c685a4b39534f18869a93896370224463715Forest Bond *
1065449c685a4b39534f18869a93896370224463715Forest Bond-*/
1073fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clémentunsigned char
1085449c685a4b39534f18869a93896370224463715Forest BondDATARATEbyGetRateIdx (
1093fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clément    unsigned char byRate
1105449c685a4b39534f18869a93896370224463715Forest Bond    )
1115449c685a4b39534f18869a93896370224463715Forest Bond{
1123fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clément    unsigned char ii;
1135449c685a4b39534f18869a93896370224463715Forest Bond
1145449c685a4b39534f18869a93896370224463715Forest Bond    //Erase basicRate flag.
1155449c685a4b39534f18869a93896370224463715Forest Bond    byRate = byRate & 0x7F;//0111 1111
1165449c685a4b39534f18869a93896370224463715Forest Bond
1175449c685a4b39534f18869a93896370224463715Forest Bond    for (ii = 0; ii < MAX_RATE; ii ++) {
1185449c685a4b39534f18869a93896370224463715Forest Bond        if (acbyIERate[ii] == byRate)
1195449c685a4b39534f18869a93896370224463715Forest Bond            return ii;
1205449c685a4b39534f18869a93896370224463715Forest Bond    }
1215449c685a4b39534f18869a93896370224463715Forest Bond    return 0;
1225449c685a4b39534f18869a93896370224463715Forest Bond}
1235449c685a4b39534f18869a93896370224463715Forest Bond
1245449c685a4b39534f18869a93896370224463715Forest Bond
1255449c685a4b39534f18869a93896370224463715Forest Bond
1265449c685a4b39534f18869a93896370224463715Forest Bond/*+
1275449c685a4b39534f18869a93896370224463715Forest Bond *
1285449c685a4b39534f18869a93896370224463715Forest Bond * Routine Description:
1295449c685a4b39534f18869a93896370224463715Forest Bond *      Rate fallback Algorithm Implementaion
1305449c685a4b39534f18869a93896370224463715Forest Bond *
1315449c685a4b39534f18869a93896370224463715Forest Bond * Parameters:
1325449c685a4b39534f18869a93896370224463715Forest Bond *  In:
1335449c685a4b39534f18869a93896370224463715Forest Bond *      pDevice         - Pointer to the adapter
1345449c685a4b39534f18869a93896370224463715Forest Bond *      psNodeDBTable   - Pointer to Node Data Base
1355449c685a4b39534f18869a93896370224463715Forest Bond *  Out:
1365449c685a4b39534f18869a93896370224463715Forest Bond *      none
1375449c685a4b39534f18869a93896370224463715Forest Bond *
1385449c685a4b39534f18869a93896370224463715Forest Bond * Return Value: none
1395449c685a4b39534f18869a93896370224463715Forest Bond *
1405449c685a4b39534f18869a93896370224463715Forest Bond-*/
1415449c685a4b39534f18869a93896370224463715Forest Bond#define AUTORATE_TXCNT_THRESHOLD        20
1425449c685a4b39534f18869a93896370224463715Forest Bond#define AUTORATE_INC_THRESHOLD          30
1435449c685a4b39534f18869a93896370224463715Forest Bond
1445449c685a4b39534f18869a93896370224463715Forest Bond
1455449c685a4b39534f18869a93896370224463715Forest Bond
1465449c685a4b39534f18869a93896370224463715Forest Bond
1475449c685a4b39534f18869a93896370224463715Forest Bond/*+
1485449c685a4b39534f18869a93896370224463715Forest Bond *
1495449c685a4b39534f18869a93896370224463715Forest Bond * Description:
1505449c685a4b39534f18869a93896370224463715Forest Bond *      Get RateIdx from the value in SuppRates IE or ExtSuppRates IE
1515449c685a4b39534f18869a93896370224463715Forest Bond *
1525449c685a4b39534f18869a93896370224463715Forest Bond * Parameters:
1535449c685a4b39534f18869a93896370224463715Forest Bond *  In:
1543fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clément *      unsigned char - Rate value in SuppRates IE or ExtSuppRates IE
1555449c685a4b39534f18869a93896370224463715Forest Bond *  Out:
1565449c685a4b39534f18869a93896370224463715Forest Bond *      none
1575449c685a4b39534f18869a93896370224463715Forest Bond *
1585449c685a4b39534f18869a93896370224463715Forest Bond * Return Value: RateIdx
1595449c685a4b39534f18869a93896370224463715Forest Bond *
1605449c685a4b39534f18869a93896370224463715Forest Bond-*/
1612986db5fd31e312206d3ebfa4786aac04bdbe486Charles Clémentunsigned short
1625449c685a4b39534f18869a93896370224463715Forest BondwGetRateIdx(
1633fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clément    unsigned char byRate
1645449c685a4b39534f18869a93896370224463715Forest Bond    )
1655449c685a4b39534f18869a93896370224463715Forest Bond{
1662986db5fd31e312206d3ebfa4786aac04bdbe486Charles Clément    unsigned short ii;
1675449c685a4b39534f18869a93896370224463715Forest Bond
1685449c685a4b39534f18869a93896370224463715Forest Bond    //Erase basicRate flag.
1695449c685a4b39534f18869a93896370224463715Forest Bond    byRate = byRate & 0x7F;//0111 1111
1705449c685a4b39534f18869a93896370224463715Forest Bond
1715449c685a4b39534f18869a93896370224463715Forest Bond    for (ii = 0; ii < MAX_RATE; ii ++) {
1725449c685a4b39534f18869a93896370224463715Forest Bond        if (acbyIERate[ii] == byRate)
1735449c685a4b39534f18869a93896370224463715Forest Bond            return ii;
1745449c685a4b39534f18869a93896370224463715Forest Bond    }
1755449c685a4b39534f18869a93896370224463715Forest Bond    return 0;
1765449c685a4b39534f18869a93896370224463715Forest Bond}
1775449c685a4b39534f18869a93896370224463715Forest Bond
1785449c685a4b39534f18869a93896370224463715Forest Bond/*+
1795449c685a4b39534f18869a93896370224463715Forest Bond *
1805449c685a4b39534f18869a93896370224463715Forest Bond * Description:
1815449c685a4b39534f18869a93896370224463715Forest Bond *      Parsing the highest basic & support rate in rate field of frame.
1825449c685a4b39534f18869a93896370224463715Forest Bond *
1835449c685a4b39534f18869a93896370224463715Forest Bond * Parameters:
1845449c685a4b39534f18869a93896370224463715Forest Bond *  In:
1855449c685a4b39534f18869a93896370224463715Forest Bond *      pDevice         - Pointer to the adapter
1865449c685a4b39534f18869a93896370224463715Forest Bond *      pItemRates      - Pointer to Rate field defined in 802.11 spec.
1875449c685a4b39534f18869a93896370224463715Forest Bond *      pItemExtRates      - Pointer to Extended Rate field defined in 802.11 spec.
1885449c685a4b39534f18869a93896370224463715Forest Bond *  Out:
1895449c685a4b39534f18869a93896370224463715Forest Bond *      pwMaxBasicRate  - Maximum Basic Rate
1905449c685a4b39534f18869a93896370224463715Forest Bond *      pwMaxSuppRate   - Maximum Supported Rate
1915449c685a4b39534f18869a93896370224463715Forest Bond *      pbyTopCCKRate   - Maximum Basic Rate in CCK mode
1925449c685a4b39534f18869a93896370224463715Forest Bond *      pbyTopOFDMRate  - Maximum Basic Rate in OFDM mode
1935449c685a4b39534f18869a93896370224463715Forest Bond *
1945449c685a4b39534f18869a93896370224463715Forest Bond * Return Value: none
1955449c685a4b39534f18869a93896370224463715Forest Bond *
1965449c685a4b39534f18869a93896370224463715Forest Bond-*/
1976b35b7b3798b652a57fbce480f350aac851431c4Charles Clémentvoid
1985449c685a4b39534f18869a93896370224463715Forest BondRATEvParseMaxRate (
1993a215e0ff4184314f7f1a099354a272ddedff289Charles Clément    void *pDeviceHandler,
2003a215e0ff4184314f7f1a099354a272ddedff289Charles Clément    PWLAN_IE_SUPP_RATES pItemRates,
2013a215e0ff4184314f7f1a099354a272ddedff289Charles Clément    PWLAN_IE_SUPP_RATES pItemExtRates,
2027b6a001313a9b11a1f0985de05fff514db41d72dCharles Clément    bool bUpdateBasicRate,
20315df6c2b922de3088203ad90347a30d31ccca67eCharles Clément    unsigned short *pwMaxBasicRate,
20415df6c2b922de3088203ad90347a30d31ccca67eCharles Clément    unsigned short *pwMaxSuppRate,
20515df6c2b922de3088203ad90347a30d31ccca67eCharles Clément    unsigned short *pwSuppRate,
2062989e96f17f2dcbd73aee37856899c2885df0686Charles Clément    unsigned char *pbyTopCCKRate,
2072989e96f17f2dcbd73aee37856899c2885df0686Charles Clément    unsigned char *pbyTopOFDMRate
2085449c685a4b39534f18869a93896370224463715Forest Bond    )
2095449c685a4b39534f18869a93896370224463715Forest Bond{
2105449c685a4b39534f18869a93896370224463715Forest BondPSDevice  pDevice = (PSDevice) pDeviceHandler;
211b6e95cd52a81079abc1def7867e27bf541953089Charles Clémentunsigned int ii;
2123fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clémentunsigned char byHighSuppRate = 0;
2133fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clémentunsigned char byRate = 0;
2142986db5fd31e312206d3ebfa4786aac04bdbe486Charles Clémentunsigned short wOldBasicRate = pDevice->wBasicRate;
215b6e95cd52a81079abc1def7867e27bf541953089Charles Clémentunsigned int uRateLen;
2165449c685a4b39534f18869a93896370224463715Forest Bond
2175449c685a4b39534f18869a93896370224463715Forest Bond
2185449c685a4b39534f18869a93896370224463715Forest Bond    if (pItemRates == NULL)
2195449c685a4b39534f18869a93896370224463715Forest Bond        return;
2205449c685a4b39534f18869a93896370224463715Forest Bond
2215449c685a4b39534f18869a93896370224463715Forest Bond    *pwSuppRate = 0;
2225449c685a4b39534f18869a93896370224463715Forest Bond    uRateLen = pItemRates->len;
2235449c685a4b39534f18869a93896370224463715Forest Bond
2247e809a9b10ab5ee985e23dea537e0236f026d1caJim Lieb    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate Len: %d\n", uRateLen);
2255449c685a4b39534f18869a93896370224463715Forest Bond    if (pDevice->eCurrentPHYType != PHY_TYPE_11B) {
2265449c685a4b39534f18869a93896370224463715Forest Bond        if (uRateLen > WLAN_RATES_MAXLEN)
2275449c685a4b39534f18869a93896370224463715Forest Bond            uRateLen = WLAN_RATES_MAXLEN;
2285449c685a4b39534f18869a93896370224463715Forest Bond    } else {
2295449c685a4b39534f18869a93896370224463715Forest Bond        if (uRateLen > WLAN_RATES_MAXLEN_11B)
2305449c685a4b39534f18869a93896370224463715Forest Bond            uRateLen = WLAN_RATES_MAXLEN_11B;
2315449c685a4b39534f18869a93896370224463715Forest Bond    }
2325449c685a4b39534f18869a93896370224463715Forest Bond
2335449c685a4b39534f18869a93896370224463715Forest Bond    for (ii = 0; ii < uRateLen; ii++) {
2343fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clément    	byRate = (unsigned char)(pItemRates->abyRates[ii]);
2355449c685a4b39534f18869a93896370224463715Forest Bond        if (WLAN_MGMT_IS_BASICRATE(byRate) &&
2361b12068a804711ae2f4fd2876d5706542c1d7ad9Charles Clément            (bUpdateBasicRate == true))  {
2375449c685a4b39534f18869a93896370224463715Forest Bond            // Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate
238830a619c02a53d52c86534f7d857b2e8d0ba893fCharles Clément            CARDbAddBasicRate((void *)pDevice, wGetRateIdx(byRate));
2397e809a9b10ab5ee985e23dea537e0236f026d1caJim Lieb            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate));
2405449c685a4b39534f18869a93896370224463715Forest Bond        }
2413fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clément        byRate = (unsigned char)(pItemRates->abyRates[ii]&0x7F);
2425449c685a4b39534f18869a93896370224463715Forest Bond        if (byHighSuppRate == 0)
2435449c685a4b39534f18869a93896370224463715Forest Bond            byHighSuppRate = byRate;
2445449c685a4b39534f18869a93896370224463715Forest Bond        if (byRate > byHighSuppRate)
2455449c685a4b39534f18869a93896370224463715Forest Bond            byHighSuppRate = byRate;
2465449c685a4b39534f18869a93896370224463715Forest Bond        *pwSuppRate |= (1<<wGetRateIdx(byRate));
2475449c685a4b39534f18869a93896370224463715Forest Bond    }
2485449c685a4b39534f18869a93896370224463715Forest Bond    if ((pItemExtRates != NULL) && (pItemExtRates->byElementID == WLAN_EID_EXTSUPP_RATES) &&
2495449c685a4b39534f18869a93896370224463715Forest Bond        (pDevice->eCurrentPHYType != PHY_TYPE_11B)) {
2505449c685a4b39534f18869a93896370224463715Forest Bond
251b6e95cd52a81079abc1def7867e27bf541953089Charles Clément        unsigned int uExtRateLen = pItemExtRates->len;
2525449c685a4b39534f18869a93896370224463715Forest Bond
2535449c685a4b39534f18869a93896370224463715Forest Bond        if (uExtRateLen > WLAN_RATES_MAXLEN)
2545449c685a4b39534f18869a93896370224463715Forest Bond            uExtRateLen = WLAN_RATES_MAXLEN;
2555449c685a4b39534f18869a93896370224463715Forest Bond
2565449c685a4b39534f18869a93896370224463715Forest Bond        for (ii = 0; ii < uExtRateLen ; ii++) {
2573fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clément            byRate = (unsigned char)(pItemExtRates->abyRates[ii]);
2585449c685a4b39534f18869a93896370224463715Forest Bond            // select highest basic rate
2595449c685a4b39534f18869a93896370224463715Forest Bond            if (WLAN_MGMT_IS_BASICRATE(pItemExtRates->abyRates[ii])) {
2605449c685a4b39534f18869a93896370224463715Forest Bond            	// Add to basic rate set, update pDevice->byTopCCKBasicRate and pDevice->byTopOFDMBasicRate
261830a619c02a53d52c86534f7d857b2e8d0ba893fCharles Clément                CARDbAddBasicRate((void *)pDevice, wGetRateIdx(byRate));
2627e809a9b10ab5ee985e23dea537e0236f026d1caJim Lieb                DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"ParseMaxRate AddBasicRate: %d\n", wGetRateIdx(byRate));
2635449c685a4b39534f18869a93896370224463715Forest Bond            }
2643fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clément            byRate = (unsigned char)(pItemExtRates->abyRates[ii]&0x7F);
2655449c685a4b39534f18869a93896370224463715Forest Bond            if (byHighSuppRate == 0)
2665449c685a4b39534f18869a93896370224463715Forest Bond                byHighSuppRate = byRate;
2675449c685a4b39534f18869a93896370224463715Forest Bond            if (byRate > byHighSuppRate)
2685449c685a4b39534f18869a93896370224463715Forest Bond                byHighSuppRate = byRate;
2695449c685a4b39534f18869a93896370224463715Forest Bond            *pwSuppRate |= (1<<wGetRateIdx(byRate));
2705449c685a4b39534f18869a93896370224463715Forest Bond            //DBG_PRN_GRP09(("ParseMaxRate : HighSuppRate: %d, %X\n", wGetRateIdx(byRate), byRate));
2715449c685a4b39534f18869a93896370224463715Forest Bond        }
2725449c685a4b39534f18869a93896370224463715Forest Bond    } //if(pItemExtRates != NULL)
2735449c685a4b39534f18869a93896370224463715Forest Bond
274830a619c02a53d52c86534f7d857b2e8d0ba893fCharles Clément    if ((pDevice->byPacketType == PK_TYPE_11GB) && CARDbIsOFDMinBasicRate((void *)pDevice)) {
2755449c685a4b39534f18869a93896370224463715Forest Bond        pDevice->byPacketType = PK_TYPE_11GA;
2765449c685a4b39534f18869a93896370224463715Forest Bond    }
2775449c685a4b39534f18869a93896370224463715Forest Bond
2785449c685a4b39534f18869a93896370224463715Forest Bond    *pbyTopCCKRate = pDevice->byTopCCKBasicRate;
2795449c685a4b39534f18869a93896370224463715Forest Bond    *pbyTopOFDMRate = pDevice->byTopOFDMBasicRate;
2805449c685a4b39534f18869a93896370224463715Forest Bond    *pwMaxSuppRate = wGetRateIdx(byHighSuppRate);
2815449c685a4b39534f18869a93896370224463715Forest Bond    if ((pDevice->byPacketType==PK_TYPE_11B) || (pDevice->byPacketType==PK_TYPE_11GB))
2825449c685a4b39534f18869a93896370224463715Forest Bond       *pwMaxBasicRate = pDevice->byTopCCKBasicRate;
2835449c685a4b39534f18869a93896370224463715Forest Bond    else
2845449c685a4b39534f18869a93896370224463715Forest Bond       *pwMaxBasicRate = pDevice->byTopOFDMBasicRate;
2855449c685a4b39534f18869a93896370224463715Forest Bond    if (wOldBasicRate != pDevice->wBasicRate)
286830a619c02a53d52c86534f7d857b2e8d0ba893fCharles Clément        CARDvSetRSPINF((void *)pDevice, pDevice->eCurrentPHYType);
2875449c685a4b39534f18869a93896370224463715Forest Bond
2887e809a9b10ab5ee985e23dea537e0236f026d1caJim Lieb     DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Exit ParseMaxRate\n");
2895449c685a4b39534f18869a93896370224463715Forest Bond}
2905449c685a4b39534f18869a93896370224463715Forest Bond
2915449c685a4b39534f18869a93896370224463715Forest Bond
2925449c685a4b39534f18869a93896370224463715Forest Bond/*+
2935449c685a4b39534f18869a93896370224463715Forest Bond *
2945449c685a4b39534f18869a93896370224463715Forest Bond * Routine Description:
2955449c685a4b39534f18869a93896370224463715Forest Bond *      Rate fallback Algorithm Implementaion
2965449c685a4b39534f18869a93896370224463715Forest Bond *
2975449c685a4b39534f18869a93896370224463715Forest Bond * Parameters:
2985449c685a4b39534f18869a93896370224463715Forest Bond *  In:
2995449c685a4b39534f18869a93896370224463715Forest Bond *      pDevice         - Pointer to the adapter
3005449c685a4b39534f18869a93896370224463715Forest Bond *      psNodeDBTable   - Pointer to Node Data Base
3015449c685a4b39534f18869a93896370224463715Forest Bond *  Out:
3025449c685a4b39534f18869a93896370224463715Forest Bond *      none
3035449c685a4b39534f18869a93896370224463715Forest Bond *
3045449c685a4b39534f18869a93896370224463715Forest Bond * Return Value: none
3055449c685a4b39534f18869a93896370224463715Forest Bond *
3065449c685a4b39534f18869a93896370224463715Forest Bond-*/
3075449c685a4b39534f18869a93896370224463715Forest Bond#define AUTORATE_TXCNT_THRESHOLD        20
3085449c685a4b39534f18869a93896370224463715Forest Bond#define AUTORATE_INC_THRESHOLD          30
3095449c685a4b39534f18869a93896370224463715Forest Bond
3106b35b7b3798b652a57fbce480f350aac851431c4Charles Clémentvoid
3115449c685a4b39534f18869a93896370224463715Forest BondRATEvTxRateFallBack (
3123a215e0ff4184314f7f1a099354a272ddedff289Charles Clément    void *pDeviceHandler,
3133a215e0ff4184314f7f1a099354a272ddedff289Charles Clément    PKnownNodeDB psNodeDBTable
3145449c685a4b39534f18869a93896370224463715Forest Bond    )
3155449c685a4b39534f18869a93896370224463715Forest Bond{
3165449c685a4b39534f18869a93896370224463715Forest BondPSDevice        pDevice = (PSDevice) pDeviceHandler;
3172986db5fd31e312206d3ebfa4786aac04bdbe486Charles Clémentunsigned short wIdxDownRate = 0;
318b6e95cd52a81079abc1def7867e27bf541953089Charles Clémentunsigned int ii;
3190f4c60d61e9c10a0733eacd650c101189bdf75cdCharles Clément//unsigned long dwRateTable[MAX_RATE]  = {1,   2,   5,   11,  6,    9,    12,   18,  24,  36,  48,  54};
3207b6a001313a9b11a1f0985de05fff514db41d72dCharles Clémentbool bAutoRate[MAX_RATE]    = {true,true,true,true,false,false,true,true,true,true,true,true};
3210f4c60d61e9c10a0733eacd650c101189bdf75cdCharles Clément	unsigned long dwThroughputTbl[MAX_RATE] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540};
3220f4c60d61e9c10a0733eacd650c101189bdf75cdCharles Clément	unsigned long dwThroughput = 0;
3232986db5fd31e312206d3ebfa4786aac04bdbe486Charles Clément	unsigned short wIdxUpRate = 0;
3240f4c60d61e9c10a0733eacd650c101189bdf75cdCharles Clément	unsigned long dwTxDiff = 0;
3255449c685a4b39534f18869a93896370224463715Forest Bond
3265449c685a4b39534f18869a93896370224463715Forest Bond    if (pDevice->pMgmt->eScanState != WMAC_NO_SCANNING) {
3275449c685a4b39534f18869a93896370224463715Forest Bond        // Don't do Fallback when scanning Channel
3285449c685a4b39534f18869a93896370224463715Forest Bond        return;
3295449c685a4b39534f18869a93896370224463715Forest Bond    }
3305449c685a4b39534f18869a93896370224463715Forest Bond
3315449c685a4b39534f18869a93896370224463715Forest Bond    psNodeDBTable->uTimeCount ++;
3325449c685a4b39534f18869a93896370224463715Forest Bond
3335449c685a4b39534f18869a93896370224463715Forest Bond    if (psNodeDBTable->uTxFail[MAX_RATE] > psNodeDBTable->uTxOk[MAX_RATE])
3345449c685a4b39534f18869a93896370224463715Forest Bond        dwTxDiff = psNodeDBTable->uTxFail[MAX_RATE] - psNodeDBTable->uTxOk[MAX_RATE];
3355449c685a4b39534f18869a93896370224463715Forest Bond
3365449c685a4b39534f18869a93896370224463715Forest Bond    if ((psNodeDBTable->uTxOk[MAX_RATE] < AUTORATE_TXOK_CNT) &&
3375449c685a4b39534f18869a93896370224463715Forest Bond        (dwTxDiff < AUTORATE_TXFAIL_CNT) &&
3385449c685a4b39534f18869a93896370224463715Forest Bond        (psNodeDBTable->uTimeCount < AUTORATE_TIMEOUT)) {
3395449c685a4b39534f18869a93896370224463715Forest Bond        return;
3405449c685a4b39534f18869a93896370224463715Forest Bond    }
3415449c685a4b39534f18869a93896370224463715Forest Bond
3425449c685a4b39534f18869a93896370224463715Forest Bond    if (psNodeDBTable->uTimeCount >= AUTORATE_TIMEOUT) {
3435449c685a4b39534f18869a93896370224463715Forest Bond        psNodeDBTable->uTimeCount = 0;
3445449c685a4b39534f18869a93896370224463715Forest Bond    }
3455449c685a4b39534f18869a93896370224463715Forest Bond
3465449c685a4b39534f18869a93896370224463715Forest Bond
3475449c685a4b39534f18869a93896370224463715Forest Bond    for(ii=0;ii<MAX_RATE;ii++) {
3485449c685a4b39534f18869a93896370224463715Forest Bond        if (psNodeDBTable->wSuppRate & (0x0001<<ii)) {
3491b12068a804711ae2f4fd2876d5706542c1d7ad9Charles Clément            if (bAutoRate[ii] == true) {
3502986db5fd31e312206d3ebfa4786aac04bdbe486Charles Clément                wIdxUpRate = (unsigned short) ii;
3515449c685a4b39534f18869a93896370224463715Forest Bond            }
3525449c685a4b39534f18869a93896370224463715Forest Bond        } else {
3535a5a2a6ad4aa2467bcc34fa50e85c2afc90bab05Charles Clément            bAutoRate[ii] = false;
3545449c685a4b39534f18869a93896370224463715Forest Bond        }
3555449c685a4b39534f18869a93896370224463715Forest Bond    }
3565449c685a4b39534f18869a93896370224463715Forest Bond
3575449c685a4b39534f18869a93896370224463715Forest Bond    for(ii=0;ii<=psNodeDBTable->wTxDataRate;ii++) {
3585449c685a4b39534f18869a93896370224463715Forest Bond        if ( (psNodeDBTable->uTxOk[ii] != 0) ||
3595449c685a4b39534f18869a93896370224463715Forest Bond             (psNodeDBTable->uTxFail[ii] != 0) ) {
3605449c685a4b39534f18869a93896370224463715Forest Bond            dwThroughputTbl[ii] *= psNodeDBTable->uTxOk[ii];
3615449c685a4b39534f18869a93896370224463715Forest Bond            if (ii < RATE_11M) {
3625449c685a4b39534f18869a93896370224463715Forest Bond                psNodeDBTable->uTxFail[ii] *= 4;
3635449c685a4b39534f18869a93896370224463715Forest Bond            }
3645449c685a4b39534f18869a93896370224463715Forest Bond            dwThroughputTbl[ii] /= (psNodeDBTable->uTxOk[ii] + psNodeDBTable->uTxFail[ii]);
3655449c685a4b39534f18869a93896370224463715Forest Bond        }
3665449c685a4b39534f18869a93896370224463715Forest Bond//        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rate %d,Ok: %d, Fail:%d, Throughput:%d\n",
3675449c685a4b39534f18869a93896370224463715Forest Bond//                       ii, psNodeDBTable->uTxOk[ii], psNodeDBTable->uTxFail[ii], dwThroughputTbl[ii]);
3685449c685a4b39534f18869a93896370224463715Forest Bond    }
3695449c685a4b39534f18869a93896370224463715Forest Bond    dwThroughput = dwThroughputTbl[psNodeDBTable->wTxDataRate];
3705449c685a4b39534f18869a93896370224463715Forest Bond
3715449c685a4b39534f18869a93896370224463715Forest Bond    wIdxDownRate = psNodeDBTable->wTxDataRate;
3725449c685a4b39534f18869a93896370224463715Forest Bond    for(ii = psNodeDBTable->wTxDataRate; ii > 0;) {
3735449c685a4b39534f18869a93896370224463715Forest Bond        ii--;
3745449c685a4b39534f18869a93896370224463715Forest Bond        if ( (dwThroughputTbl[ii] > dwThroughput) &&
3751b12068a804711ae2f4fd2876d5706542c1d7ad9Charles Clément             (bAutoRate[ii]==true) ) {
3765449c685a4b39534f18869a93896370224463715Forest Bond            dwThroughput = dwThroughputTbl[ii];
3772986db5fd31e312206d3ebfa4786aac04bdbe486Charles Clément            wIdxDownRate = (unsigned short) ii;
3785449c685a4b39534f18869a93896370224463715Forest Bond        }
3795449c685a4b39534f18869a93896370224463715Forest Bond    }
3805449c685a4b39534f18869a93896370224463715Forest Bond    psNodeDBTable->wTxDataRate = wIdxDownRate;
3815449c685a4b39534f18869a93896370224463715Forest Bond    if (psNodeDBTable->uTxOk[MAX_RATE]) {
3825449c685a4b39534f18869a93896370224463715Forest Bond        if (psNodeDBTable->uTxOk[MAX_RATE] >
3835449c685a4b39534f18869a93896370224463715Forest Bond           (psNodeDBTable->uTxFail[MAX_RATE] * 4) ) {
3845449c685a4b39534f18869a93896370224463715Forest Bond            psNodeDBTable->wTxDataRate = wIdxUpRate;
3855449c685a4b39534f18869a93896370224463715Forest Bond        }
3865449c685a4b39534f18869a93896370224463715Forest Bond    }else { // adhoc, if uTxOk =0 & uTxFail = 0
3875449c685a4b39534f18869a93896370224463715Forest Bond        if (psNodeDBTable->uTxFail[MAX_RATE] == 0)
3885449c685a4b39534f18869a93896370224463715Forest Bond            psNodeDBTable->wTxDataRate = wIdxUpRate;
3895449c685a4b39534f18869a93896370224463715Forest Bond    }
3905449c685a4b39534f18869a93896370224463715Forest Bond//2008-5-8 <add> by chester
3915449c685a4b39534f18869a93896370224463715Forest BondTxRate_iwconfig=psNodeDBTable->wTxDataRate;
3925449c685a4b39534f18869a93896370224463715Forest Bond    s_vResetCounter(psNodeDBTable);
3935449c685a4b39534f18869a93896370224463715Forest Bond//    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Rate: %d, U:%d, D:%d\n", psNodeDBTable->wTxDataRate, wIdxUpRate, wIdxDownRate);
3945449c685a4b39534f18869a93896370224463715Forest Bond
3955449c685a4b39534f18869a93896370224463715Forest Bond    return;
3965449c685a4b39534f18869a93896370224463715Forest Bond
3975449c685a4b39534f18869a93896370224463715Forest Bond}
3985449c685a4b39534f18869a93896370224463715Forest Bond
3995449c685a4b39534f18869a93896370224463715Forest Bond/*+
4005449c685a4b39534f18869a93896370224463715Forest Bond *
4015449c685a4b39534f18869a93896370224463715Forest Bond * Description:
4025449c685a4b39534f18869a93896370224463715Forest Bond *    This routine is used to assemble available Rate IE.
4035449c685a4b39534f18869a93896370224463715Forest Bond *
4045449c685a4b39534f18869a93896370224463715Forest Bond * Parameters:
4055449c685a4b39534f18869a93896370224463715Forest Bond *  In:
4065449c685a4b39534f18869a93896370224463715Forest Bond *    pDevice
4075449c685a4b39534f18869a93896370224463715Forest Bond *  Out:
4085449c685a4b39534f18869a93896370224463715Forest Bond *
4095449c685a4b39534f18869a93896370224463715Forest Bond * Return Value: None
4105449c685a4b39534f18869a93896370224463715Forest Bond *
4115449c685a4b39534f18869a93896370224463715Forest Bond-*/
4123fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clémentunsigned char
4135449c685a4b39534f18869a93896370224463715Forest BondRATEuSetIE (
4143a215e0ff4184314f7f1a099354a272ddedff289Charles Clément    PWLAN_IE_SUPP_RATES pSrcRates,
4153a215e0ff4184314f7f1a099354a272ddedff289Charles Clément    PWLAN_IE_SUPP_RATES pDstRates,
416b6e95cd52a81079abc1def7867e27bf541953089Charles Clément    unsigned int uRateLen
4175449c685a4b39534f18869a93896370224463715Forest Bond    )
4185449c685a4b39534f18869a93896370224463715Forest Bond{
419b6e95cd52a81079abc1def7867e27bf541953089Charles Clément    unsigned int ii, uu, uRateCnt = 0;
4205449c685a4b39534f18869a93896370224463715Forest Bond
4215449c685a4b39534f18869a93896370224463715Forest Bond    if ((pSrcRates == NULL) || (pDstRates == NULL))
4225449c685a4b39534f18869a93896370224463715Forest Bond        return 0;
4235449c685a4b39534f18869a93896370224463715Forest Bond
4245449c685a4b39534f18869a93896370224463715Forest Bond    if (pSrcRates->len == 0)
4255449c685a4b39534f18869a93896370224463715Forest Bond        return 0;
4265449c685a4b39534f18869a93896370224463715Forest Bond
4275449c685a4b39534f18869a93896370224463715Forest Bond    for (ii = 0; ii < uRateLen; ii++) {
4285449c685a4b39534f18869a93896370224463715Forest Bond        for (uu = 0; uu < pSrcRates->len; uu++) {
4295449c685a4b39534f18869a93896370224463715Forest Bond            if ((pSrcRates->abyRates[uu] & 0x7F) == acbyIERate[ii]) {
4305449c685a4b39534f18869a93896370224463715Forest Bond                pDstRates->abyRates[uRateCnt ++] = pSrcRates->abyRates[uu];
4315449c685a4b39534f18869a93896370224463715Forest Bond                break;
4325449c685a4b39534f18869a93896370224463715Forest Bond            }
4335449c685a4b39534f18869a93896370224463715Forest Bond        }
4345449c685a4b39534f18869a93896370224463715Forest Bond    }
4353fc9b584c28095fe0d46cfb8bddafdf93947042eCharles Clément    return (unsigned char)uRateCnt;
4365449c685a4b39534f18869a93896370224463715Forest Bond}
4375449c685a4b39534f18869a93896370224463715Forest Bond
438