linux/drivers/staging/rtl8192e/ieee80211/rtl819x_HTProc.c
<<
>>
Prefs
   1
   2//As this function is mainly ported from Windows driver, so leave the name little changed. If any confusion caused, tell me. Created by WB. 2008.05.08
   3#include "ieee80211.h"
   4#include "rtl819x_HT.h"
   5u8 MCS_FILTER_ALL[16] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
   6
   7u8 MCS_FILTER_1SS[16] = {0xff, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
   8
   9u16 MCS_DATA_RATE[2][2][77] =
  10        {       {       {13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78 ,104, 156, 208, 234, 260,
  11                        39, 78, 117, 234, 312, 351, 390, 52, 104, 156, 208, 312, 416, 468, 520,
  12                        0, 78, 104, 130, 117, 156, 195, 104, 130, 130, 156, 182, 182, 208, 156, 195,
  13                        195, 234, 273, 273, 312, 130, 156, 181, 156, 181, 208, 234, 208, 234, 260, 260,
  14                        286, 195, 234, 273, 234, 273, 312, 351, 312, 351, 390, 390, 429},                       // Long GI, 20MHz
  15                        {14, 29, 43, 58, 87, 116, 130, 144, 29, 58, 87, 116, 173, 231, 260, 289,
  16                        43, 87, 130, 173, 260, 347, 390, 433, 58, 116, 173, 231, 347, 462, 520, 578,
  17                        0, 87, 116, 144, 130, 173, 217, 116, 144, 144, 173, 202, 202, 231, 173, 217,
  18                        217, 260, 303, 303, 347, 144, 173, 202, 173, 202, 231, 260, 231, 260, 289, 289,
  19                        318, 217, 260, 303, 260, 303, 347, 390, 347, 390, 433, 433, 477}        },              // Short GI, 20MHz
  20                {       {27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540,
  21                        81, 162, 243, 324, 486, 648, 729, 810, 108, 216, 324, 432, 648, 864, 972, 1080,
  22                        12, 162, 216, 270, 243, 324, 405, 216, 270, 270, 324, 378, 378, 432, 324, 405,
  23                        405, 486, 567, 567, 648, 270, 324, 378, 324, 378, 432, 486, 432, 486, 540, 540,
  24                        594, 405, 486, 567, 486, 567, 648, 729, 648, 729, 810, 810, 891},       // Long GI, 40MHz
  25                        {30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600,
  26                        90, 180, 270, 360, 540, 720, 810, 900, 120, 240, 360, 480, 720, 960, 1080, 1200,
  27                        13, 180, 240, 300, 270, 360, 450, 240, 300, 300, 360, 420, 420, 480, 360, 450,
  28                        450, 540, 630, 630, 720, 300, 360, 420, 360, 420, 480, 540, 480, 540, 600, 600,
  29                        660, 450, 540, 630, 540, 630, 720, 810, 720, 810, 900, 900, 990}        }       // Short GI, 40MHz
  30        };
  31
  32static u8 UNKNOWN_BORADCOM[3] = {0x00, 0x14, 0xbf};
  33static u8 LINKSYSWRT330_LINKSYSWRT300_BROADCOM[3] = {0x00, 0x1a, 0x70};
  34static u8 LINKSYSWRT350_LINKSYSWRT150_BROADCOM[3] = {0x00, 0x1d, 0x7e};
  35static u8 NETGEAR834Bv2_BROADCOM[3] = {0x00, 0x1b, 0x2f};
  36static u8 BELKINF5D8233V1_RALINK[3] = {0x00, 0x17, 0x3f};       //cosa 03202008
  37static u8 BELKINF5D82334V3_RALINK[3] = {0x00, 0x1c, 0xdf};
  38static u8 PCI_RALINK[3] = {0x00, 0x90, 0xcc};
  39static u8 EDIMAX_RALINK[3] = {0x00, 0x0e, 0x2e};
  40static u8 AIRLINK_RALINK[3] = {0x00, 0x18, 0x02};
  41static u8 DLINK_ATHEROS[3] = {0x00, 0x1c, 0xf0};
  42static u8 CISCO_BROADCOM[3] = {0x00, 0x17, 0x94};
  43
  44// 2008/04/01 MH For Cisco G mode RX TP We need to change FW duration. Shoud we put the
  45// code in other place??
  46//static u8 WIFI_CISCO_G_AP[3] = {0x00, 0x40, 0x96};
  47/********************************************************************************************************************
  48 *function:  This function update default settings in pHTInfo structure
  49 *   input:  PRT_HIGH_THROUGHPUT        pHTInfo
  50 *  output:  none
  51 *  return:  none
  52 *  notice:  These value need be modified if any changes.
  53 * *****************************************************************************************************************/
  54void HTUpdateDefaultSetting(struct ieee80211_device* ieee)
  55{
  56        PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
  57        //const typeof( ((struct ieee80211_device *)0)->pHTInfo ) *__mptr = &pHTInfo;
  58
  59        //printk("pHTinfo:%p, &pHTinfo:%p, mptr:%p,  offsetof:%x\n", pHTInfo, &pHTInfo, __mptr, offsetof(struct ieee80211_device, pHTInfo));
  60        //printk("===>ieee:%p,\n", ieee);
  61        // ShortGI support
  62        pHTInfo->bRegShortGI20MHz= 1;
  63        pHTInfo->bRegShortGI40MHz= 1;
  64
  65        // 40MHz channel support
  66        pHTInfo->bRegBW40MHz = 1;
  67
  68        // CCK rate support in 40MHz channel
  69        if(pHTInfo->bRegBW40MHz)
  70                pHTInfo->bRegSuppCCK = 1;
  71        else
  72                pHTInfo->bRegSuppCCK = true;
  73
  74        // AMSDU related
  75        pHTInfo->nAMSDU_MaxSize = 7935UL;
  76        pHTInfo->bAMSDU_Support = 0;
  77
  78        // AMPDU related
  79        pHTInfo->bAMPDUEnable = 1;
  80        pHTInfo->AMPDU_Factor = 2; //// 0: 2n13(8K), 1:2n14(16K), 2:2n15(32K), 3:2n16(64k)
  81        pHTInfo->MPDU_Density = 0;// 0: No restriction, 1: 1/8usec, 2: 1/4usec, 3: 1/2usec, 4: 1usec, 5: 2usec, 6: 4usec, 7:8usec
  82
  83        // MIMO Power Save
  84        pHTInfo->SelfMimoPs = 3;// 0: Static Mimo Ps, 1: Dynamic Mimo Ps, 3: No Limitation, 2: Reserved(Set to 3 automatically.)
  85        if(pHTInfo->SelfMimoPs == 2)
  86                pHTInfo->SelfMimoPs = 3;
  87        // 8190 only. Assign rate operation mode to firmware
  88        ieee->bTxDisableRateFallBack = 0;
  89        ieee->bTxUseDriverAssingedRate = 0;
  90
  91#ifdef  TO_DO_LIST
  92        // 8190 only. Assign duration operation mode to firmware
  93        pMgntInfo->bTxEnableFwCalcDur = (BOOLEAN)pNdisCommon->bRegTxEnableFwCalcDur;
  94#endif
  95        // 8190 only, Realtek proprietary aggregation mode
  96        // Set MPDUDensity=2,   1: Set MPDUDensity=2(32k)  for Realtek AP and set MPDUDensity=0(8k) for others
  97        pHTInfo->bRegRT2RTAggregation = 1;//0: Set MPDUDensity=2,   1: Set MPDUDensity=2(32k)  for Realtek AP and set MPDUDensity=0(8k) for others
  98
  99        // For Rx Reorder Control
 100        pHTInfo->bRegRxReorderEnable = 1;
 101        pHTInfo->RxReorderWinSize = 64;
 102        pHTInfo->RxReorderPendingTime = 30;
 103
 104#ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
 105        pHTInfo->UsbTxAggrNum = 4;
 106#endif
 107#ifdef USB_RX_AGGREGATION_SUPPORT
 108        pHTInfo->UsbRxFwAggrEn = 1;
 109        pHTInfo->UsbRxFwAggrPageNum = 24;
 110        pHTInfo->UsbRxFwAggrPacketNum = 8;
 111        pHTInfo->UsbRxFwAggrTimeout = 16; ////usb rx FW aggregation timeout threshold.It's in units of 64us
 112#endif
 113
 114
 115}
 116/********************************************************************************************************************
 117 *function:  This function print out each field on HT capability IE mainly from (Beacon/ProbeRsp/AssocReq)
 118 *   input:  u8*        CapIE       //Capability IE to be printed out
 119 *           u8*        TitleString //mainly print out caller function
 120 *  output:  none
 121 *  return:  none
 122 *  notice:  Driver should not print out this message by default.
 123 * *****************************************************************************************************************/
 124void HTDebugHTCapability(u8* CapIE, u8* TitleString )
 125{
 126
 127        static u8       EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33};       // For 11n EWC definition, 2007.07.17, by Emily
 128        PHT_CAPABILITY_ELE              pCapELE;
 129
 130        if(!memcmp(CapIE, EWC11NHTCap, sizeof(EWC11NHTCap)))
 131        {
 132                //EWC IE
 133                IEEE80211_DEBUG(IEEE80211_DL_HT, "EWC IE in %s()\n", __FUNCTION__);
 134                pCapELE = (PHT_CAPABILITY_ELE)(&CapIE[4]);
 135        }else
 136                pCapELE = (PHT_CAPABILITY_ELE)(&CapIE[0]);
 137
 138        IEEE80211_DEBUG(IEEE80211_DL_HT, "<Log HT Capability>. Called by %s\n", TitleString );
 139
 140        IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tSupported Channel Width = %s\n", (pCapELE->ChlWidth)?"20MHz": "20/40MHz");
 141        IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tSupport Short GI for 20M = %s\n", (pCapELE->ShortGI20Mhz)?"YES": "NO");
 142        IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tSupport Short GI for 40M = %s\n", (pCapELE->ShortGI40Mhz)?"YES": "NO");
 143        IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tSupport TX STBC = %s\n", (pCapELE->TxSTBC)?"YES": "NO");
 144        IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tMax AMSDU Size = %s\n", (pCapELE->MaxAMSDUSize)?"3839": "7935");
 145        IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tSupport CCK in 20/40 mode = %s\n", (pCapELE->DssCCk)?"YES": "NO");
 146        IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tMax AMPDU Factor = %d\n", pCapELE->MaxRxAMPDUFactor);
 147        IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tMPDU Density = %d\n", pCapELE->MPDUDensity);
 148        IEEE80211_DEBUG(IEEE80211_DL_HT,  "\tMCS Rate Set = [%x][%x][%x][%x][%x]\n", pCapELE->MCS[0],\
 149                                pCapELE->MCS[1], pCapELE->MCS[2], pCapELE->MCS[3], pCapELE->MCS[4]);
 150        return;
 151
 152}
 153/********************************************************************************************************************
 154 *function:  This function print out each field on HT Information IE mainly from (Beacon/ProbeRsp)
 155 *   input:  u8*        InfoIE       //Capability IE to be printed out
 156 *           u8*        TitleString //mainly print out caller function
 157 *  output:  none
 158 *  return:  none
 159 *  notice:  Driver should not print out this message by default.
 160 * *****************************************************************************************************************/
 161void HTDebugHTInfo(u8*  InfoIE, u8* TitleString)
 162{
 163
 164        static u8       EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34};      // For 11n EWC definition, 2007.07.17, by Emily
 165        PHT_INFORMATION_ELE             pHTInfoEle;
 166
 167        if(!memcmp(InfoIE, EWC11NHTInfo, sizeof(EWC11NHTInfo)))
 168        {
 169                // Not EWC IE
 170                IEEE80211_DEBUG(IEEE80211_DL_HT, "EWC IE in %s()\n", __FUNCTION__);
 171                pHTInfoEle = (PHT_INFORMATION_ELE)(&InfoIE[4]);
 172        }else
 173                pHTInfoEle = (PHT_INFORMATION_ELE)(&InfoIE[0]);
 174
 175
 176        IEEE80211_DEBUG(IEEE80211_DL_HT, "<Log HT Information Element>. Called by %s\n", TitleString);
 177
 178        IEEE80211_DEBUG(IEEE80211_DL_HT, "\tPrimary channel = %d\n", pHTInfoEle->ControlChl);
 179        IEEE80211_DEBUG(IEEE80211_DL_HT, "\tSenondary channel =");
 180        switch(pHTInfoEle->ExtChlOffset)
 181        {
 182                case 0:
 183                        IEEE80211_DEBUG(IEEE80211_DL_HT, "Not Present\n");
 184                        break;
 185                case 1:
 186                        IEEE80211_DEBUG(IEEE80211_DL_HT, "Upper channel\n");
 187                        break;
 188                case 2:
 189                        IEEE80211_DEBUG(IEEE80211_DL_HT, "Reserved. Eooro!!!\n");
 190                        break;
 191                case 3:
 192                        IEEE80211_DEBUG(IEEE80211_DL_HT, "Lower Channel\n");
 193                        break;
 194        }
 195        IEEE80211_DEBUG(IEEE80211_DL_HT, "\tRecommended channel width = %s\n", (pHTInfoEle->RecommemdedTxWidth)?"20Mhz": "40Mhz");
 196
 197        IEEE80211_DEBUG(IEEE80211_DL_HT, "\tOperation mode for protection = ");
 198        switch(pHTInfoEle->OptMode)
 199        {
 200                case 0:
 201                        IEEE80211_DEBUG(IEEE80211_DL_HT, "No Protection\n");
 202                        break;
 203                case 1:
 204                        IEEE80211_DEBUG(IEEE80211_DL_HT, "HT non-member protection mode\n");
 205                        break;
 206                case 2:
 207                        IEEE80211_DEBUG(IEEE80211_DL_HT, "Suggest to open protection\n");
 208                        break;
 209                case 3:
 210                        IEEE80211_DEBUG(IEEE80211_DL_HT, "HT mixed mode\n");
 211                        break;
 212        }
 213
 214        IEEE80211_DEBUG(IEEE80211_DL_HT, "\tBasic MCS Rate Set = [%x][%x][%x][%x][%x]\n", pHTInfoEle->BasicMSC[0],\
 215                                pHTInfoEle->BasicMSC[1], pHTInfoEle->BasicMSC[2], pHTInfoEle->BasicMSC[3], pHTInfoEle->BasicMSC[4]);
 216        return;
 217}
 218
 219/*
 220*       Return:         true if station in half n mode and AP supports 40 bw
 221*/
 222bool IsHTHalfNmode40Bandwidth(struct ieee80211_device* ieee)
 223{
 224        bool                    retValue = false;
 225        PRT_HIGH_THROUGHPUT      pHTInfo = ieee->pHTInfo;
 226
 227        if(pHTInfo->bCurrentHTSupport == false )        // wireless is n mode
 228                retValue = false;
 229        else if(pHTInfo->bRegBW40MHz == false)  // station supports 40 bw
 230                retValue = false;
 231        else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))      // station in half n mode
 232                retValue = false;
 233        else if(((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ChlWidth) // ap support 40 bw
 234                retValue = true;
 235        else
 236                retValue = false;
 237
 238        return retValue;
 239}
 240
 241bool IsHTHalfNmodeSGI(struct ieee80211_device* ieee, bool is40MHz)
 242{
 243        bool                    retValue = false;
 244        PRT_HIGH_THROUGHPUT      pHTInfo = ieee->pHTInfo;
 245
 246        if(pHTInfo->bCurrentHTSupport == false )        // wireless is n mode
 247                retValue = false;
 248        else if(!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))      // station in half n mode
 249                retValue = false;
 250        else if(is40MHz) // ap support 40 bw
 251        {
 252                if(((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ShortGI40Mhz) // ap support 40 bw short GI
 253                        retValue = true;
 254                else
 255                        retValue = false;
 256        }
 257        else
 258        {
 259                if(((PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf))->ShortGI20Mhz) // ap support 40 bw short GI
 260                        retValue = true;
 261                else
 262                        retValue = false;
 263        }
 264
 265        return retValue;
 266}
 267
 268u16 HTHalfMcsToDataRate(struct ieee80211_device* ieee,  u8      nMcsRate)
 269{
 270
 271        u8      is40MHz;
 272        u8      isShortGI;
 273
 274        is40MHz  =  (IsHTHalfNmode40Bandwidth(ieee))?1:0;
 275        isShortGI = (IsHTHalfNmodeSGI(ieee, is40MHz))? 1:0;
 276
 277        return MCS_DATA_RATE[is40MHz][isShortGI][(nMcsRate&0x7f)];
 278}
 279
 280
 281u16 HTMcsToDataRate( struct ieee80211_device* ieee, u8 nMcsRate)
 282{
 283        PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
 284
 285        u8      is40MHz = (pHTInfo->bCurBW40MHz)?1:0;
 286        u8      isShortGI = (pHTInfo->bCurBW40MHz)?
 287                                                ((pHTInfo->bCurShortGI40MHz)?1:0):
 288                                                ((pHTInfo->bCurShortGI20MHz)?1:0);
 289        return MCS_DATA_RATE[is40MHz][isShortGI][(nMcsRate&0x7f)];
 290}
 291
 292/********************************************************************************************************************
 293 *function:  This function returns current datarate.
 294 *   input:  struct ieee80211_device*   ieee
 295 *           u8                         nDataRate
 296 *  output:  none
 297 *  return:  tx rate
 298 *  notice:  quite unsure about how to use this function //wb
 299 * *****************************************************************************************************************/
 300u16  TxCountToDataRate( struct ieee80211_device* ieee, u8 nDataRate)
 301{
 302        //PRT_HIGH_THROUGHPUT   pHTInfo = ieee->pHTInfo;
 303        u16             CCKOFDMRate[12] = {0x02 , 0x04 , 0x0b , 0x16 , 0x0c , 0x12 , 0x18 , 0x24 , 0x30 , 0x48 , 0x60 , 0x6c};
 304        u8      is40MHz = 0;
 305        u8      isShortGI = 0;
 306
 307        if(nDataRate < 12)
 308        {
 309                return CCKOFDMRate[nDataRate];
 310        }
 311        else
 312        {
 313                if (nDataRate >= 0x10 && nDataRate <= 0x1f)//if(nDataRate > 11 && nDataRate < 28 )
 314                {
 315                        is40MHz = 0;
 316                        isShortGI = 0;
 317
 318                      // nDataRate = nDataRate - 12;
 319                }
 320                else if(nDataRate >=0x20  && nDataRate <= 0x2f ) //(27, 44)
 321                {
 322                        is40MHz = 1;
 323                        isShortGI = 0;
 324
 325                        //nDataRate = nDataRate - 28;
 326                }
 327                else if(nDataRate >= 0x30  && nDataRate <= 0x3f )  //(43, 60)
 328                {
 329                        is40MHz = 0;
 330                        isShortGI = 1;
 331
 332                        //nDataRate = nDataRate - 44;
 333                }
 334                else if(nDataRate >= 0x40  && nDataRate <= 0x4f ) //(59, 76)
 335                {
 336                        is40MHz = 1;
 337                        isShortGI = 1;
 338
 339                        //nDataRate = nDataRate - 60;
 340                }
 341                return MCS_DATA_RATE[is40MHz][isShortGI][nDataRate&0xf];
 342        }
 343}
 344
 345
 346
 347bool IsHTHalfNmodeAPs(struct ieee80211_device* ieee)
 348{
 349        bool                    retValue = false;
 350        struct ieee80211_network* net = &ieee->current_network;
 351#if 0
 352        if(pMgntInfo->bHalfNMode == false)
 353                retValue = false;
 354        else
 355#endif
 356        if((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3)==0) ||
 357                     (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3)==0) ||
 358                     (memcmp(net->bssid, PCI_RALINK, 3)==0) ||
 359                     (memcmp(net->bssid, EDIMAX_RALINK, 3)==0) ||
 360                     (memcmp(net->bssid, AIRLINK_RALINK, 3)==0) ||
 361                     (net->ralink_cap_exist))
 362                retValue = true;
 363        else if((memcmp(net->bssid, UNKNOWN_BORADCOM, 3)==0) ||
 364                    (memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3)==0)||
 365                    (memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3)==0)||
 366                    (memcmp(net->bssid, NETGEAR834Bv2_BROADCOM, 3)==0) ||
 367                    (net->broadcom_cap_exist))
 368                  retValue = true;
 369        else if(net->bssht.bdRT2RTAggregation)
 370                retValue = true;
 371        else
 372                retValue = false;
 373
 374        return retValue;
 375}
 376
 377/********************************************************************************************************************
 378 *function:  This function returns peer IOT.
 379 *   input:  struct ieee80211_device*   ieee
 380 *  output:  none
 381 *  return:
 382 *  notice:
 383 * *****************************************************************************************************************/
 384void HTIOTPeerDetermine(struct ieee80211_device* ieee)
 385{
 386        PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
 387        struct ieee80211_network* net = &ieee->current_network;
 388        if(net->bssht.bdRT2RTAggregation)
 389                pHTInfo->IOTPeer = HT_IOT_PEER_REALTEK;
 390        else if(net->broadcom_cap_exist)
 391                pHTInfo->IOTPeer = HT_IOT_PEER_BROADCOM;
 392        else if((memcmp(net->bssid, UNKNOWN_BORADCOM, 3)==0) ||
 393                        (memcmp(net->bssid, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3)==0)||
 394                        (memcmp(net->bssid, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3)==0)||
 395                        (memcmp(net->bssid, NETGEAR834Bv2_BROADCOM, 3)==0) )
 396                pHTInfo->IOTPeer = HT_IOT_PEER_BROADCOM;
 397        else if((memcmp(net->bssid, BELKINF5D8233V1_RALINK, 3)==0) ||
 398                        (memcmp(net->bssid, BELKINF5D82334V3_RALINK, 3)==0) ||
 399                        (memcmp(net->bssid, PCI_RALINK, 3)==0) ||
 400                        (memcmp(net->bssid, EDIMAX_RALINK, 3)==0) ||
 401                        (memcmp(net->bssid, AIRLINK_RALINK, 3)==0) ||
 402                         net->ralink_cap_exist)
 403                pHTInfo->IOTPeer = HT_IOT_PEER_RALINK;
 404        else if((net->atheros_cap_exist )|| (memcmp(net->bssid, DLINK_ATHEROS, 3) == 0))
 405                pHTInfo->IOTPeer = HT_IOT_PEER_ATHEROS;
 406        else if(memcmp(net->bssid, CISCO_BROADCOM, 3)==0)
 407                pHTInfo->IOTPeer = HT_IOT_PEER_CISCO;
 408        else
 409                pHTInfo->IOTPeer = HT_IOT_PEER_UNKNOWN;
 410
 411        IEEE80211_DEBUG(IEEE80211_DL_IOT, "Joseph debug!! IOTPEER: %x\n", pHTInfo->IOTPeer);
 412}
 413/********************************************************************************************************************
 414 *function:  Check whether driver should declare received rate up to MCS13 only since some chipset is not good
 415 *           at receiving MCS14~15 frame from some AP.
 416 *   input:  struct ieee80211_device*   ieee
 417 *           u8 *                       PeerMacAddr
 418 *  output:  none
 419 *  return:  return 1 if driver should declare MCS13 only(otherwise return 0)
 420  * *****************************************************************************************************************/
 421u8 HTIOTActIsDisableMCS14(struct ieee80211_device* ieee, u8* PeerMacAddr)
 422{
 423        u8 ret = 0;
 424#if 0
 425        // Apply for 819u only
 426#if (HAL_CODE_BASE==RTL8192 && DEV_BUS_TYPE==USB_INTERFACE)
 427        if((memcmp(PeerMacAddr, UNKNOWN_BORADCOM, 3)==0) ||
 428                (memcmp(PeerMacAddr, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3)==0)
 429            )
 430        {
 431                ret = 1;
 432        }
 433
 434
 435        if(pHTInfo->bCurrentRT2RTAggregation)
 436        {
 437                // The parameter of pHTInfo->bCurrentRT2RTAggregation must be decided previously
 438                ret = 1;
 439        }
 440#endif
 441#endif
 442        return ret;
 443 }
 444
 445
 446/**
 447* Function:     HTIOTActIsDisableMCS15
 448*
 449* Overview:     Check whether driver should declare capability of receving MCS15
 450*
 451* Input:
 452*                       PADAPTER                Adapter,
 453*
 454* Output:               None
 455* Return:       true if driver should disable MCS15
 456* 2008.04.15    Emily
 457*/
 458bool HTIOTActIsDisableMCS15(struct ieee80211_device* ieee)
 459{
 460        bool retValue = false;
 461
 462#ifdef TODO
 463        // Apply for 819u only
 464#if (HAL_CODE_BASE==RTL8192)
 465
 466#if (DEV_BUS_TYPE == USB_INTERFACE)
 467        // Alway disable MCS15 by Jerry Chang's request.by Emily, 2008.04.15
 468        retValue = true;
 469#elif (DEV_BUS_TYPE == PCI_INTERFACE)
 470        // Enable MCS15 if the peer is Cisco AP. by Emily, 2008.05.12
 471//      if(pBssDesc->bCiscoCapExist)
 472//              retValue = false;
 473//      else
 474                retValue = false;
 475#endif
 476#endif
 477#endif
 478        // Jerry Chang suggest that 8190 1x2 does not need to disable MCS15
 479
 480        return retValue;
 481}
 482
 483/**
 484* Function:     HTIOTActIsDisableMCSTwoSpatialStream
 485*
 486* Overview:     Check whether driver should declare capability of receving All 2 ss packets
 487*
 488* Input:
 489*                       PADAPTER                Adapter,
 490*
 491* Output:               None
 492* Return:       true if driver should disable all two spatial stream packet
 493* 2008.04.21    Emily
 494*/
 495bool HTIOTActIsDisableMCSTwoSpatialStream(struct ieee80211_device* ieee, u8 *PeerMacAddr)
 496{
 497        bool retValue = false;
 498
 499#ifdef TODO
 500        // Apply for 819u only
 501//#if (HAL_CODE_BASE==RTL8192)
 502
 503        //This rule only apply to Belkin(Ralink) AP
 504        if(IS_UNDER_11N_AES_MODE(Adapter))
 505        {
 506                if((PlatformCompareMemory(PeerMacAddr, BELKINF5D8233V1_RALINK, 3)==0) ||
 507                                (PlatformCompareMemory(PeerMacAddr, PCI_RALINK, 3)==0) ||
 508                                (PlatformCompareMemory(PeerMacAddr, EDIMAX_RALINK, 3)==0))
 509                {
 510                        //Set True to disable this function. Disable by default, Emily, 2008.04.23
 511                        retValue = false;
 512                }
 513        }
 514
 515//#endif
 516#endif
 517        return retValue;
 518}
 519
 520/********************************************************************************************************************
 521 *function:  Check whether driver should disable EDCA turbo mode
 522 *   input:  struct ieee80211_device*   ieee
 523 *           u8*                        PeerMacAddr
 524 *  output:  none
 525 *  return:  return 1 if driver should disable EDCA turbo mode(otherwise return 0)
 526  * *****************************************************************************************************************/
 527u8 HTIOTActIsDisableEDCATurbo(struct ieee80211_device*  ieee, u8* PeerMacAddr)
 528{
 529        u8      retValue = false;       // default enable EDCA Turbo mode.
 530        // Set specific EDCA parameter for different AP in DM handler.
 531
 532        return retValue;
 533#if 0
 534        if((memcmp(PeerMacAddr, UNKNOWN_BORADCOM, 3)==0)||
 535                (memcmp(PeerMacAddr, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3)==0)||
 536                (memcmp(PeerMacAddr, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3)==0)||
 537                (memcmp(PeerMacAddr, NETGEAR834Bv2_BROADCOM, 3)==0))
 538
 539        {
 540                retValue = 1;   //Linksys disable EDCA turbo mode
 541        }
 542
 543        return retValue;
 544#endif
 545}
 546
 547/********************************************************************************************************************
 548 *function:  Check whether we need to use OFDM to sned MGNT frame for broadcom AP
 549 *   input:  struct ieee80211_network *network   //current network we live
 550 *  output:  none
 551 *  return:  return 1 if true
 552  * *****************************************************************************************************************/
 553u8 HTIOTActIsMgntUseCCK6M(struct ieee80211_network *network)
 554{
 555        u8      retValue = 0;
 556
 557        // 2008/01/25 MH Judeg if we need to use OFDM to sned MGNT frame for broadcom AP.
 558        // 2008/01/28 MH We must prevent that we select null bssid to link.
 559
 560        if(network->broadcom_cap_exist)
 561        {
 562                retValue = 1;
 563        }
 564
 565        return retValue;
 566}
 567
 568u8 HTIOTActIsCCDFsync(u8* PeerMacAddr)
 569{
 570        u8      retValue = 0;
 571        if(     (memcmp(PeerMacAddr, UNKNOWN_BORADCOM, 3)==0) ||
 572                (memcmp(PeerMacAddr, LINKSYSWRT330_LINKSYSWRT300_BROADCOM, 3)==0) ||
 573                (memcmp(PeerMacAddr, LINKSYSWRT350_LINKSYSWRT150_BROADCOM, 3) ==0))
 574        {
 575                retValue = 1;
 576        }
 577
 578        return retValue;
 579}
 580
 581void HTResetIOTSetting(
 582        PRT_HIGH_THROUGHPUT             pHTInfo
 583)
 584{
 585        pHTInfo->IOTAction = 0;
 586        pHTInfo->IOTPeer = HT_IOT_PEER_UNKNOWN;
 587}
 588
 589
 590/********************************************************************************************************************
 591 *function:  Construct Capablility Element in Beacon... if HTEnable is turned on
 592 *   input:  struct ieee80211_device*   ieee
 593 *           u8*                        posHTCap //pointer to store Capability Ele
 594 *           u8*                        len //store length of CE
 595 *           u8                         IsEncrypt //whether encrypt, needed further
 596 *  output:  none
 597 *  return:  none
 598 *  notice:  posHTCap can't be null and should be initialized before.
 599  * *****************************************************************************************************************/
 600void HTConstructCapabilityElement(struct ieee80211_device* ieee, u8* posHTCap, u8* len, u8 IsEncrypt)
 601{
 602        PRT_HIGH_THROUGHPUT     pHT = ieee->pHTInfo;
 603        PHT_CAPABILITY_ELE      pCapELE = NULL;
 604        //u8 bIsDeclareMCS13;
 605
 606        if ((posHTCap == NULL) || (pHT == NULL))
 607        {
 608                IEEE80211_DEBUG(IEEE80211_DL_ERR, "posHTCap or pHTInfo can't be null in HTConstructCapabilityElement()\n");
 609                return;
 610        }
 611        memset(posHTCap, 0, *len);
 612        if(pHT->ePeerHTSpecVer == HT_SPEC_VER_EWC)
 613        {
 614                u8      EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33};       // For 11n EWC definition, 2007.07.17, by Emily
 615                memcpy(posHTCap, EWC11NHTCap, sizeof(EWC11NHTCap));
 616                pCapELE = (PHT_CAPABILITY_ELE)&(posHTCap[4]);
 617        }else
 618        {
 619                pCapELE = (PHT_CAPABILITY_ELE)posHTCap;
 620        }
 621
 622
 623        //HT capability info
 624        pCapELE->AdvCoding              = 0; // This feature is not supported now!!
 625        if(ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
 626        {
 627                pCapELE->ChlWidth = 0;
 628        }
 629        else
 630        {
 631                pCapELE->ChlWidth = (pHT->bRegBW40MHz?1:0);
 632        }
 633
 634//      pCapELE->ChlWidth               = (pHT->bRegBW40MHz?1:0);
 635        pCapELE->MimoPwrSave            = pHT->SelfMimoPs;
 636        pCapELE->GreenField             = 0; // This feature is not supported now!!
 637        pCapELE->ShortGI20Mhz           = 1; // We can receive Short GI!!
 638        pCapELE->ShortGI40Mhz           = 1; // We can receive Short GI!!
 639        //DbgPrint("TX HT cap/info ele BW=%d SG20=%d SG40=%d\n\r",
 640                //pCapELE->ChlWidth, pCapELE->ShortGI20Mhz, pCapELE->ShortGI40Mhz);
 641        pCapELE->TxSTBC                 = 1;
 642        pCapELE->RxSTBC                 = 0;
 643        pCapELE->DelayBA                = 0;    // Do not support now!!
 644        pCapELE->MaxAMSDUSize   = (MAX_RECEIVE_BUFFER_SIZE>=7935)?1:0;
 645        pCapELE->DssCCk                 = ((pHT->bRegBW40MHz)?(pHT->bRegSuppCCK?1:0):0);
 646        pCapELE->PSMP                   = 0; // Do not support now!!
 647        pCapELE->LSigTxopProtect        = 0; // Do not support now!!
 648
 649
 650        //MAC HT parameters info
 651        // TODO: Nedd to take care of this part
 652        IEEE80211_DEBUG(IEEE80211_DL_HT, "TX HT cap/info ele BW=%d MaxAMSDUSize:%d DssCCk:%d\n", pCapELE->ChlWidth, pCapELE->MaxAMSDUSize, pCapELE->DssCCk);
 653
 654        if( IsEncrypt)
 655        {
 656                pCapELE->MPDUDensity    = 7; // 8us
 657                pCapELE->MaxRxAMPDUFactor       = 2; // 2 is for 32 K and 3 is 64K
 658        }
 659        else
 660        {
 661                pCapELE->MaxRxAMPDUFactor       = 3; // 2 is for 32 K and 3 is 64K
 662                pCapELE->MPDUDensity    = 0; // no density
 663        }
 664
 665        //Supported MCS set
 666        memcpy(pCapELE->MCS, ieee->Regdot11HTOperationalRateSet, 16);
 667        if(pHT->IOTAction & HT_IOT_ACT_DISABLE_MCS15)
 668                pCapELE->MCS[1] &= 0x7f;
 669
 670        if(pHT->IOTAction & HT_IOT_ACT_DISABLE_MCS14)
 671                pCapELE->MCS[1] &= 0xbf;
 672
 673        if(pHT->IOTAction & HT_IOT_ACT_DISABLE_ALL_2SS)
 674                pCapELE->MCS[1] &= 0x00;
 675
 676        // 2008.06.12
 677        // For RTL819X, if pairwisekey = wep/tkip, ap is ralink, we support only MCS0~7.
 678        if(ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
 679        {
 680                int i;
 681                for(i = 1; i< 16; i++)
 682                        pCapELE->MCS[i] = 0;
 683        }
 684
 685        //Extended HT Capability Info
 686        memset(&pCapELE->ExtHTCapInfo, 0, 2);
 687
 688
 689        //TXBF Capabilities
 690        memset(pCapELE->TxBFCap, 0, 4);
 691
 692        //Antenna Selection Capabilities
 693        pCapELE->ASCap = 0;
 694//add 2 to give space for element ID and len when construct frames
 695        if(pHT->ePeerHTSpecVer == HT_SPEC_VER_EWC)
 696                *len = 30 + 2;
 697        else
 698                *len = 26 + 2;
 699
 700
 701
 702//      IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_HT, posHTCap, *len -2);
 703
 704        //Print each field in detail. Driver should not print out this message by default
 705//      HTDebugHTCapability(posHTCap, (u8*)"HTConstructCapability()");
 706        return;
 707
 708}
 709/********************************************************************************************************************
 710 *function:  Construct  Information Element in Beacon... if HTEnable is turned on
 711 *   input:  struct ieee80211_device*   ieee
 712 *           u8*                        posHTCap //pointer to store Information Ele
 713 *           u8*                        len   //store len of
 714 *           u8                         IsEncrypt //whether encrypt, needed further
 715 *  output:  none
 716 *  return:  none
 717 *  notice:  posHTCap can't be null and be initialized before. only AP and IBSS sta should do this
 718  * *****************************************************************************************************************/
 719void HTConstructInfoElement(struct ieee80211_device* ieee, u8* posHTInfo, u8* len, u8 IsEncrypt)
 720{
 721        PRT_HIGH_THROUGHPUT     pHT = ieee->pHTInfo;
 722        PHT_INFORMATION_ELE             pHTInfoEle = (PHT_INFORMATION_ELE)posHTInfo;
 723        if ((posHTInfo == NULL) || (pHTInfoEle == NULL))
 724        {
 725                IEEE80211_DEBUG(IEEE80211_DL_ERR, "posHTInfo or pHTInfoEle can't be null in HTConstructInfoElement()\n");
 726                return;
 727        }
 728
 729        memset(posHTInfo, 0, *len);
 730        if ( (ieee->iw_mode == IW_MODE_ADHOC) || (ieee->iw_mode == IW_MODE_MASTER)) //ap mode is not currently supported
 731        {
 732                pHTInfoEle->ControlChl                  = ieee->current_network.channel;
 733                pHTInfoEle->ExtChlOffset                        = ((pHT->bRegBW40MHz == false)?HT_EXTCHNL_OFFSET_NO_EXT:
 734                                                                                        (ieee->current_network.channel<=6)?
 735                                                                                                HT_EXTCHNL_OFFSET_UPPER:HT_EXTCHNL_OFFSET_LOWER);
 736                pHTInfoEle->RecommemdedTxWidth  = pHT->bRegBW40MHz;
 737                pHTInfoEle->RIFS                                        = 0;
 738                pHTInfoEle->PSMPAccessOnly              = 0;
 739                pHTInfoEle->SrvIntGranularity           = 0;
 740                pHTInfoEle->OptMode                             = pHT->CurrentOpMode;
 741                pHTInfoEle->NonGFDevPresent             = 0;
 742                pHTInfoEle->DualBeacon                  = 0;
 743                pHTInfoEle->SecondaryBeacon             = 0;
 744                pHTInfoEle->LSigTxopProtectFull         = 0;
 745                pHTInfoEle->PcoActive                           = 0;
 746                pHTInfoEle->PcoPhase                            = 0;
 747
 748                memset(pHTInfoEle->BasicMSC, 0, 16);
 749
 750
 751                *len = 22 + 2; //same above
 752
 753        }
 754        else
 755        {
 756                //STA should not generate High Throughput Information Element
 757                *len = 0;
 758        }
 759        //IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA | IEEE80211_DL_HT, posHTInfo, *len - 2);
 760        //HTDebugHTInfo(posHTInfo, "HTConstructInforElement");
 761        return;
 762}
 763
 764/*
 765  *  According to experiment, Realtek AP to STA (based on rtl8190) may achieve best performance
 766  *  if both STA and AP set limitation of aggregation size to 32K, that is, set AMPDU density to 2
 767  *  (Ref: IEEE 11n specification). However, if Realtek STA associates to other AP, STA should set
 768  *  limitation of aggregation size to 8K, otherwise, performance of traffic stream from STA to AP
 769  *  will be much less than the traffic stream from AP to STA if both of the stream runs concurrently
 770  *  at the same time.
 771  *
 772  *  Frame Format
 773  *  Element ID         Length          OUI                     Type1           Reserved
 774  *  1 byte                     1 byte          3 bytes         1 byte          1 byte
 775  *
 776  *  OUI                = 0x00, 0xe0, 0x4c,
 777  *  Type       = 0x02
 778  *  Reserved   = 0x00
 779  *
 780  *  2007.8.21 by Emily
 781*/
 782/********************************************************************************************************************
 783 *function:  Construct  Information Element in Beacon... in RT2RT condition
 784 *   input:  struct ieee80211_device*   ieee
 785 *           u8*                        posRT2RTAgg //pointer to store Information Ele
 786 *           u8*                        len   //store len
 787 *  output:  none
 788 *  return:  none
 789 *  notice:
 790  * *****************************************************************************************************************/
 791void HTConstructRT2RTAggElement(struct ieee80211_device* ieee, u8* posRT2RTAgg, u8* len)
 792{
 793        if (posRT2RTAgg == NULL) {
 794                IEEE80211_DEBUG(IEEE80211_DL_ERR, "posRT2RTAgg can't be null in HTConstructRT2RTAggElement()\n");
 795                return;
 796        }
 797        memset(posRT2RTAgg, 0, *len);
 798        *posRT2RTAgg++ = 0x00;
 799        *posRT2RTAgg++ = 0xe0;
 800        *posRT2RTAgg++ = 0x4c;
 801        *posRT2RTAgg++ = 0x02;
 802        *posRT2RTAgg++ = 0x01;
 803        *posRT2RTAgg = 0x10;//*posRT2RTAgg = 0x02;
 804
 805        if(ieee->bSupportRemoteWakeUp) {
 806                *posRT2RTAgg |= 0x08;//RT_HT_CAP_USE_WOW;
 807        }
 808
 809        *len = 6 + 2;
 810        return;
 811#ifdef TODO
 812#if(HAL_CODE_BASE == RTL8192 && DEV_BUS_TYPE == USB_INTERFACE)
 813        /*
 814        //Emily. If it is required to Ask Realtek AP to send AMPDU during AES mode, enable this
 815           section of code.
 816        if(IS_UNDER_11N_AES_MODE(Adapter))
 817        {
 818                posRT2RTAgg->Octet[5] |=RT_HT_CAP_USE_AMPDU;
 819        }else
 820        {
 821                posRT2RTAgg->Octet[5] &= 0xfb;
 822        }
 823        */
 824
 825#else
 826        // Do Nothing
 827#endif
 828
 829        posRT2RTAgg->Length = 6;
 830#endif
 831
 832
 833
 834
 835}
 836
 837
 838/********************************************************************************************************************
 839 *function:  Pick the right Rate Adaptive table to use
 840 *   input:  struct ieee80211_device*   ieee
 841 *           u8*                        pOperateMCS //A pointer to MCS rate bitmap
 842 *  return:  always we return true
 843 *  notice:
 844  * *****************************************************************************************************************/
 845u8 HT_PickMCSRate(struct ieee80211_device* ieee, u8* pOperateMCS)
 846{
 847        u8                                      i;
 848        if (pOperateMCS == NULL)
 849        {
 850                IEEE80211_DEBUG(IEEE80211_DL_ERR, "pOperateMCS can't be null in HT_PickMCSRate()\n");
 851                return false;
 852        }
 853
 854        switch(ieee->mode)
 855        {
 856        case IEEE_A:
 857        case IEEE_B:
 858        case IEEE_G:
 859                        //legacy rate routine handled at selectedrate
 860
 861                        //no MCS rate
 862                        for(i=0;i<=15;i++){
 863                                pOperateMCS[i] = 0;
 864                        }
 865                        break;
 866
 867        case IEEE_N_24G:        //assume CCK rate ok
 868        case IEEE_N_5G:
 869                        // Legacy part we only use 6, 5.5,2,1 for N_24G and 6 for N_5G.
 870                        // Legacy part shall be handled at SelectRateSet().
 871
 872                        //HT part
 873                        // TODO: may be different if we have different number of antenna
 874                        pOperateMCS[0] &=RATE_ADPT_1SS_MASK;    //support MCS 0~7
 875                        pOperateMCS[1] &=RATE_ADPT_2SS_MASK;
 876                        pOperateMCS[3] &=RATE_ADPT_MCS32_MASK;
 877                        break;
 878
 879        //should never reach here
 880        default:
 881
 882                        break;
 883
 884        }
 885
 886        return true;
 887}
 888
 889/*
 890*       Description:
 891*               This function will get the highest speed rate in input MCS set.
 892*
 893*       /param  Adapter                 Pionter to Adapter entity
 894*                       pMCSRateSet             Pointer to MCS rate bitmap
 895*                       pMCSFilter              Pointer to MCS rate filter
 896*
 897*       /return Highest MCS rate included in pMCSRateSet and filtered by pMCSFilter.
 898*
 899*/
 900/********************************************************************************************************************
 901 *function:  This function will get the highest speed rate in input MCS set.
 902 *   input:  struct ieee80211_device*   ieee
 903 *           u8*                        pMCSRateSet //Pointer to MCS rate bitmap
 904 *           u8*                        pMCSFilter //Pointer to MCS rate filter
 905 *  return:  Highest MCS rate included in pMCSRateSet and filtered by pMCSFilter
 906 *  notice:
 907  * *****************************************************************************************************************/
 908u8 HTGetHighestMCSRate(struct ieee80211_device* ieee, u8* pMCSRateSet, u8* pMCSFilter)
 909{
 910        u8              i, j;
 911        u8              bitMap;
 912        u8              mcsRate = 0;
 913        u8              availableMcsRate[16];
 914        if (pMCSRateSet == NULL || pMCSFilter == NULL)
 915        {
 916                IEEE80211_DEBUG(IEEE80211_DL_ERR, "pMCSRateSet or pMCSFilter can't be null in HTGetHighestMCSRate()\n");
 917                return false;
 918        }
 919        for(i=0; i<16; i++)
 920                availableMcsRate[i] = pMCSRateSet[i] & pMCSFilter[i];
 921
 922        for(i = 0; i < 16; i++)
 923        {
 924                if(availableMcsRate[i] != 0)
 925                        break;
 926        }
 927        if(i == 16)
 928                return false;
 929
 930        for(i = 0; i < 16; i++)
 931        {
 932                if(availableMcsRate[i] != 0)
 933                {
 934                        bitMap = availableMcsRate[i];
 935                        for(j = 0; j < 8; j++)
 936                        {
 937                                if((bitMap%2) != 0)
 938                                {
 939                                        if(HTMcsToDataRate(ieee, (8*i+j)) > HTMcsToDataRate(ieee, mcsRate))
 940                                                mcsRate = (8*i+j);
 941                                }
 942                                bitMap = bitMap>>1;
 943                        }
 944                }
 945        }
 946        return (mcsRate|0x80);
 947}
 948
 949
 950
 951/*
 952**
 953**1.Filter our operation rate set with AP's rate set
 954**2.shall reference channel bandwidth, STBC, Antenna number
 955**3.generate rate adative table for firmware
 956**David 20060906
 957**
 958** \pHTSupportedCap: the connected STA's supported rate Capability element
 959*/
 960u8 HTFilterMCSRate( struct ieee80211_device* ieee, u8* pSupportMCS, u8* pOperateMCS)
 961{
 962
 963        u8 i=0;
 964
 965        // filter out operational rate set not supported by AP, the lenth of it is 16
 966        for(i=0;i<=15;i++){
 967                pOperateMCS[i] = ieee->Regdot11HTOperationalRateSet[i]&pSupportMCS[i];
 968        }
 969
 970
 971        // TODO: adjust our operational rate set  according to our channel bandwidth, STBC and Antenna number
 972
 973        // TODO: fill suggested rate adaptive rate index and give firmware info using Tx command packet
 974        // we also shall suggested the first start rate set according to our singal strength
 975        HT_PickMCSRate(ieee, pOperateMCS);
 976
 977        // For RTL819X, if pairwisekey = wep/tkip, we support only MCS0~7.
 978        if(ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev))
 979                pOperateMCS[1] = 0;
 980
 981        //
 982        // For RTL819X, we support only MCS0~15.
 983        // And also, we do not know how to use MCS32 now.
 984        //
 985        for(i=2; i<=15; i++)
 986                pOperateMCS[i] = 0;
 987
 988        return true;
 989}
 990void HTSetConnectBwMode(struct ieee80211_device* ieee, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET    Offset);
 991#if 0
 992//I need move this function to other places, such as rx?
 993#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
 994void HTOnAssocRsp_wq(struct work_struct *work)
 995{
 996        struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, ht_onAssRsp);
 997#else
 998void HTOnAssocRsp_wq(struct ieee80211_device *ieee)
 999{
1000#endif
1001#endif
1002void HTOnAssocRsp(struct ieee80211_device *ieee)
1003{
1004        PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
1005        PHT_CAPABILITY_ELE              pPeerHTCap = NULL;
1006        PHT_INFORMATION_ELE             pPeerHTInfo = NULL;
1007        u16     nMaxAMSDUSize = 0;
1008        u8*     pMcsFilter = NULL;
1009
1010        static u8                               EWC11NHTCap[] = {0x00, 0x90, 0x4c, 0x33};               // For 11n EWC definition, 2007.07.17, by Emily
1011        static u8                               EWC11NHTInfo[] = {0x00, 0x90, 0x4c, 0x34};      // For 11n EWC definition, 2007.07.17, by Emily
1012
1013        if( pHTInfo->bCurrentHTSupport == false )
1014        {
1015                IEEE80211_DEBUG(IEEE80211_DL_ERR, "<=== HTOnAssocRsp(): HT_DISABLE\n");
1016                return;
1017        }
1018        IEEE80211_DEBUG(IEEE80211_DL_HT, "===> HTOnAssocRsp_wq(): HT_ENABLE\n");
1019//      IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, pHTInfo->PeerHTCapBuf, sizeof(HT_CAPABILITY_ELE));
1020//      IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA, pHTInfo->PeerHTInfoBuf, sizeof(HT_INFORMATION_ELE));
1021
1022//      HTDebugHTCapability(pHTInfo->PeerHTCapBuf,"HTOnAssocRsp_wq");
1023//      HTDebugHTInfo(pHTInfo->PeerHTInfoBuf,"HTOnAssocRsp_wq");
1024        //
1025        if(!memcmp(pHTInfo->PeerHTCapBuf,EWC11NHTCap, sizeof(EWC11NHTCap)))
1026                pPeerHTCap = (PHT_CAPABILITY_ELE)(&pHTInfo->PeerHTCapBuf[4]);
1027        else
1028                pPeerHTCap = (PHT_CAPABILITY_ELE)(pHTInfo->PeerHTCapBuf);
1029
1030        if(!memcmp(pHTInfo->PeerHTInfoBuf, EWC11NHTInfo, sizeof(EWC11NHTInfo)))
1031                pPeerHTInfo = (PHT_INFORMATION_ELE)(&pHTInfo->PeerHTInfoBuf[4]);
1032        else
1033                pPeerHTInfo = (PHT_INFORMATION_ELE)(pHTInfo->PeerHTInfoBuf);
1034
1035
1036        ////////////////////////////////////////////////////////
1037        // Configurations:
1038        ////////////////////////////////////////////////////////
1039        IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_HT, pPeerHTCap, sizeof(HT_CAPABILITY_ELE));
1040//      IEEE80211_DEBUG_DATA(IEEE80211_DL_DATA|IEEE80211_DL_HT, pPeerHTInfo, sizeof(HT_INFORMATION_ELE));
1041        // Config Supported Channel Width setting
1042        //
1043        HTSetConnectBwMode(ieee, (HT_CHANNEL_WIDTH)(pPeerHTCap->ChlWidth), (HT_EXTCHNL_OFFSET)(pPeerHTInfo->ExtChlOffset));
1044
1045//      if(pHTInfo->bCurBW40MHz == true)
1046                pHTInfo->bCurTxBW40MHz = ((pPeerHTInfo->RecommemdedTxWidth == 1)?true:false);
1047
1048        //
1049        // Update short GI/ long GI setting
1050        //
1051        // TODO:
1052        pHTInfo->bCurShortGI20MHz=
1053                ((pHTInfo->bRegShortGI20MHz)?((pPeerHTCap->ShortGI20Mhz==1)?true:false):false);
1054        pHTInfo->bCurShortGI40MHz=
1055                ((pHTInfo->bRegShortGI40MHz)?((pPeerHTCap->ShortGI40Mhz==1)?true:false):false);
1056
1057        //
1058        // Config TX STBC setting
1059        //
1060        // TODO:
1061
1062        //
1063        // Config DSSS/CCK  mode in 40MHz mode
1064        //
1065        // TODO:
1066        pHTInfo->bCurSuppCCK =
1067                ((pHTInfo->bRegSuppCCK)?((pPeerHTCap->DssCCk==1)?true:false):false);
1068
1069
1070        //
1071        // Config and configure A-MSDU setting
1072        //
1073        pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support;
1074
1075        nMaxAMSDUSize = (pPeerHTCap->MaxAMSDUSize==0)?3839:7935;
1076
1077        if(pHTInfo->nAMSDU_MaxSize > nMaxAMSDUSize )
1078                pHTInfo->nCurrent_AMSDU_MaxSize = nMaxAMSDUSize;
1079        else
1080                pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize;
1081
1082
1083        //
1084        // Config A-MPDU setting
1085        //
1086        pHTInfo->bCurrentAMPDUEnable = pHTInfo->bAMPDUEnable;
1087
1088        // <1> Decide AMPDU Factor
1089
1090        // By Emily
1091        if(!pHTInfo->bRegRT2RTAggregation)
1092        {
1093                // Decide AMPDU Factor according to protocol handshake
1094                if(pHTInfo->AMPDU_Factor > pPeerHTCap->MaxRxAMPDUFactor)
1095                        pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor;
1096                else
1097                        pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor;
1098
1099        }else
1100        {
1101                // Set MPDU density to 2 to Realtek AP, and set it to 0 for others
1102                // Replace MPDU factor declared in original association response frame format. 2007.08.20 by Emily
1103#if 0
1104                osTmp= PacketGetElement( asocpdu, EID_Vendor, OUI_SUB_REALTEK_AGG, OUI_SUBTYPE_DONT_CARE);
1105                if(osTmp.Length >= 5)   //00:e0:4c:02:00
1106#endif
1107                if (ieee->current_network.bssht.bdRT2RTAggregation)
1108                {
1109                        if( ieee->pairwise_key_type != KEY_TYPE_NA)
1110                                // Realtek may set 32k in security mode and 64k for others
1111                                pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor;
1112                        else
1113                                pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_64K;
1114                }else
1115                {
1116                        if(pPeerHTCap->MaxRxAMPDUFactor < HT_AGG_SIZE_32K)
1117                                pHTInfo->CurrentAMPDUFactor = pPeerHTCap->MaxRxAMPDUFactor;
1118                        else
1119                                pHTInfo->CurrentAMPDUFactor = HT_AGG_SIZE_32K;
1120                }
1121        }
1122
1123        // <2> Set AMPDU Minimum MPDU Start Spacing
1124        // 802.11n 3.0 section 9.7d.3
1125#if 1
1126        if(pHTInfo->MPDU_Density > pPeerHTCap->MPDUDensity)
1127                pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density;
1128        else
1129                pHTInfo->CurrentMPDUDensity = pPeerHTCap->MPDUDensity;
1130        if(ieee->pairwise_key_type != KEY_TYPE_NA )
1131                pHTInfo->CurrentMPDUDensity     = 7; // 8us
1132#else
1133        if(pHTInfo->MPDU_Density > pPeerHTCap->MPDUDensity)
1134                pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density;
1135        else
1136                pHTInfo->CurrentMPDUDensity = pPeerHTCap->MPDUDensity;
1137#endif
1138        // Force TX AMSDU
1139
1140        // Lanhsin: mark for tmp to avoid deauth by ap from  s3
1141        //if(memcmp(pMgntInfo->Bssid, NETGEAR834Bv2_BROADCOM, 3)==0)
1142        if(0)
1143                {
1144
1145                        pHTInfo->bCurrentAMPDUEnable = false;
1146                        pHTInfo->ForcedAMSDUMode = HT_AGG_FORCE_ENABLE;
1147                        pHTInfo->ForcedAMSDUMaxSize = 7935;
1148
1149                pHTInfo->IOTAction |=  HT_IOT_ACT_TX_USE_AMSDU_8K;
1150        }
1151
1152        // Rx Reorder Setting
1153        pHTInfo->bCurRxReorderEnable = pHTInfo->bRegRxReorderEnable;
1154
1155        //
1156        // Filter out unsupported HT rate for this AP
1157        // Update RATR table
1158        // This is only for 8190 ,8192 or later product which using firmware to handle rate adaptive mechanism.
1159        //
1160
1161        // Handle Ralink AP bad MCS rate set condition. Joseph.
1162        // This fix the bug of Ralink AP. This may be removed in the future.
1163        if(pPeerHTCap->MCS[0] == 0)
1164                pPeerHTCap->MCS[0] = 0xff;
1165
1166        HTFilterMCSRate(ieee, pPeerHTCap->MCS, ieee->dot11HTOperationalRateSet);
1167
1168        //
1169        // Config MIMO Power Save setting
1170        //
1171        pHTInfo->PeerMimoPs = pPeerHTCap->MimoPwrSave;
1172        if(pHTInfo->PeerMimoPs == MIMO_PS_STATIC)
1173                pMcsFilter = MCS_FILTER_1SS;
1174        else
1175                pMcsFilter = MCS_FILTER_ALL;
1176        //WB add for MCS8 bug
1177//      pMcsFilter = MCS_FILTER_1SS;
1178        ieee->HTHighestOperaRate = HTGetHighestMCSRate(ieee, ieee->dot11HTOperationalRateSet, pMcsFilter);
1179        ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate;
1180
1181        //
1182        // Config current operation mode.
1183        //
1184        pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode;
1185
1186
1187
1188}
1189
1190void HTSetConnectBwModeCallback(struct ieee80211_device* ieee);
1191/********************************************************************************************************************
1192 *function:  initialize HT info(struct PRT_HIGH_THROUGHPUT)
1193 *   input:  struct ieee80211_device*   ieee
1194 *  output:  none
1195 *  return:  none
1196 *  notice: This function is called when *  (1) MPInitialization Phase *  (2) Receiving of Deauthentication from AP
1197********************************************************************************************************************/
1198// TODO: Should this funciton be called when receiving of Disassociation?
1199void HTInitializeHTInfo(struct ieee80211_device* ieee)
1200{
1201        PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1202
1203        //
1204        // These parameters will be reset when receiving deauthentication packet
1205        //
1206        IEEE80211_DEBUG(IEEE80211_DL_HT, "===========>%s()\n", __FUNCTION__);
1207        pHTInfo->bCurrentHTSupport = false;
1208
1209        // 40MHz channel support
1210        pHTInfo->bCurBW40MHz = false;
1211        pHTInfo->bCurTxBW40MHz = false;
1212
1213        // Short GI support
1214        pHTInfo->bCurShortGI20MHz = false;
1215        pHTInfo->bCurShortGI40MHz = false;
1216        pHTInfo->bForcedShortGI = false;
1217
1218        // CCK rate support
1219        // This flag is set to true to support CCK rate by default.
1220        // It will be affected by "pHTInfo->bRegSuppCCK" and AP capabilities only when associate to
1221        // 11N BSS.
1222        pHTInfo->bCurSuppCCK = true;
1223
1224        // AMSDU related
1225        pHTInfo->bCurrent_AMSDU_Support = false;
1226        pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize;
1227
1228        // AMPUD related
1229        pHTInfo->CurrentMPDUDensity = pHTInfo->MPDU_Density;
1230        pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor;
1231
1232
1233
1234        // Initialize all of the parameters related to 11n
1235        memset((void*)(&(pHTInfo->SelfHTCap)), 0, sizeof(pHTInfo->SelfHTCap));
1236        memset((void*)(&(pHTInfo->SelfHTInfo)), 0, sizeof(pHTInfo->SelfHTInfo));
1237        memset((void*)(&(pHTInfo->PeerHTCapBuf)), 0, sizeof(pHTInfo->PeerHTCapBuf));
1238        memset((void*)(&(pHTInfo->PeerHTInfoBuf)), 0, sizeof(pHTInfo->PeerHTInfoBuf));
1239
1240        pHTInfo->bSwBwInProgress = false;
1241        pHTInfo->ChnlOp = CHNLOP_NONE;
1242
1243        // Set default IEEE spec for Draft N
1244        pHTInfo->ePeerHTSpecVer = HT_SPEC_VER_IEEE;
1245
1246        // Realtek proprietary aggregation mode
1247        pHTInfo->bCurrentRT2RTAggregation = false;
1248        pHTInfo->bCurrentRT2RTLongSlotTime = false;
1249        pHTInfo->IOTPeer = 0;
1250        pHTInfo->IOTAction = 0;
1251
1252        //MCS rate initialized here
1253        {
1254                u8* RegHTSuppRateSets = &(ieee->RegHTSuppRateSet[0]);
1255                RegHTSuppRateSets[0] = 0xFF;    //support MCS 0~7
1256                RegHTSuppRateSets[1] = 0xFF;    //support MCS 8~15
1257                RegHTSuppRateSets[4] = 0x01;    //support MCS 32
1258        }
1259}
1260/********************************************************************************************************************
1261 *function:  initialize Bss HT structure(struct PBSS_HT)
1262 *   input:  PBSS_HT pBssHT //to be initialized
1263 *  output:  none
1264 *  return:  none
1265 *  notice: This function is called when initialize network structure
1266********************************************************************************************************************/
1267void HTInitializeBssDesc(PBSS_HT pBssHT)
1268{
1269
1270        pBssHT->bdSupportHT = false;
1271        memset(pBssHT->bdHTCapBuf, 0, sizeof(pBssHT->bdHTCapBuf));
1272        pBssHT->bdHTCapLen = 0;
1273        memset(pBssHT->bdHTInfoBuf, 0, sizeof(pBssHT->bdHTInfoBuf));
1274        pBssHT->bdHTInfoLen = 0;
1275
1276        pBssHT->bdHTSpecVer= HT_SPEC_VER_IEEE;
1277
1278        pBssHT->bdRT2RTAggregation = false;
1279        pBssHT->bdRT2RTLongSlotTime = false;
1280}
1281#if 0
1282//below function has merged into ieee80211_network_init() in ieee80211_rx.c
1283void
1284HTParsingHTCapElement(
1285        IN      PADAPTER                Adapter,
1286        IN      OCTET_STRING    HTCapIE,
1287        OUT     PRT_WLAN_BSS    pBssDesc
1288)
1289{
1290        PMGNT_INFO                              pMgntInfo = &Adapter->MgntInfo;
1291
1292        if( HTCapIE.Length > sizeof(pBssDesc->BssHT.bdHTCapBuf) )
1293        {
1294                RT_TRACE( COMP_HT, DBG_LOUD, ("HTParsingHTCapElement(): HT Capability Element length is too long!\n") );
1295                return;
1296        }
1297
1298        // TODO: Check the correctness of HT Cap
1299        //Print each field in detail. Driver should not print out this message by default
1300        if(!pMgntInfo->mActingAsAp && !pMgntInfo->mAssoc)
1301                HTDebugHTCapability(DBG_TRACE, Adapter, &HTCapIE, (pu8)"HTParsingHTCapElement()");
1302
1303        HTCapIE.Length = HTCapIE.Length > sizeof(pBssDesc->BssHT.bdHTCapBuf)?\
1304                sizeof(pBssDesc->BssHT.bdHTCapBuf):HTCapIE.Length;      //prevent from overflow
1305
1306        CopyMem(pBssDesc->BssHT.bdHTCapBuf, HTCapIE.Octet, HTCapIE.Length);
1307        pBssDesc->BssHT.bdHTCapLen = HTCapIE.Length;
1308
1309}
1310
1311
1312void
1313HTParsingHTInfoElement(
1314        PADAPTER                Adapter,
1315        OCTET_STRING    HTInfoIE,
1316        PRT_WLAN_BSS    pBssDesc
1317)
1318{
1319        PMGNT_INFO                              pMgntInfo = &Adapter->MgntInfo;
1320
1321        if( HTInfoIE.Length > sizeof(pBssDesc->BssHT.bdHTInfoBuf))
1322        {
1323                RT_TRACE( COMP_HT, DBG_LOUD, ("HTParsingHTInfoElement(): HT Information Element length is too long!\n") );
1324                return;
1325        }
1326
1327        // TODO: Check the correctness of HT Info
1328        //Print each field in detail. Driver should not print out this message by default
1329        if(!pMgntInfo->mActingAsAp && !pMgntInfo->mAssoc)
1330                HTDebugHTInfo(DBG_TRACE, Adapter, &HTInfoIE, (pu8)"HTParsingHTInfoElement()");
1331
1332        HTInfoIE.Length = HTInfoIE.Length > sizeof(pBssDesc->BssHT.bdHTInfoBuf)?\
1333                sizeof(pBssDesc->BssHT.bdHTInfoBuf):HTInfoIE.Length;    //prevent from overflow
1334
1335        CopyMem( pBssDesc->BssHT.bdHTInfoBuf, HTInfoIE.Octet, HTInfoIE.Length);
1336        pBssDesc->BssHT.bdHTInfoLen = HTInfoIE.Length;
1337}
1338
1339/*
1340  * Get HT related information from beacon and save it in BssDesc
1341  *
1342  * (1) Parse HTCap, and HTInfo, and record whether it is 11n AP
1343  * (2) If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
1344  * (3) Check whether peer is Realtek AP (for Realtek proprietary aggregation mode).
1345  * Input:
1346  *             PADAPTER        Adapter
1347  *
1348  * Output:
1349  *             PRT_TCB         BssDesc
1350  *
1351*/
1352void HTGetValueFromBeaconOrProbeRsp(
1353        PADAPTER                        Adapter,
1354        POCTET_STRING           pSRCmmpdu,
1355        PRT_WLAN_BSS            bssDesc
1356)
1357{
1358        PMGNT_INFO                              pMgntInfo = &Adapter->MgntInfo;
1359        PRT_HIGH_THROUGHPUT             pHTInfo = GET_HT_INFO(pMgntInfo);
1360        OCTET_STRING                            HTCapIE, HTInfoIE, HTRealtekAgg, mmpdu;
1361        OCTET_STRING                            BroadcomElement, CiscoElement;
1362
1363        mmpdu.Octet = pSRCmmpdu->Octet;
1364        mmpdu.Length = pSRCmmpdu->Length;
1365
1366        //2Note:
1367        //   Mark for IOT testing using  Linksys WRT350N, This AP does not contain WMM IE  when
1368        //   it is configured at pure-N mode.
1369        //      if(bssDesc->BssQos.bdQoSMode & QOS_WMM)
1370        //
1371
1372        HTInitializeBssDesc (&bssDesc->BssHT);
1373
1374        //2<1> Parse HTCap, and HTInfo
1375        // Get HT Capability IE: (1) Get IEEE Draft N IE or (2) Get EWC IE
1376        HTCapIE = PacketGetElement(mmpdu, EID_HTCapability, OUI_SUB_DONT_CARE, OUI_SUBTYPE_DONT_CARE);
1377        if(HTCapIE.Length == 0)
1378        {
1379                HTCapIE = PacketGetElement(mmpdu, EID_Vendor, OUI_SUB_11N_EWC_HT_CAP, OUI_SUBTYPE_DONT_CARE);
1380                if(HTCapIE.Length != 0)
1381                        bssDesc->BssHT.bdHTSpecVer= HT_SPEC_VER_EWC;
1382        }
1383        if(HTCapIE.Length != 0)
1384                HTParsingHTCapElement(Adapter, HTCapIE, bssDesc);
1385
1386        // Get HT Information IE: (1) Get IEEE Draft N IE or (2) Get EWC IE
1387        HTInfoIE = PacketGetElement(mmpdu, EID_HTInfo, OUI_SUB_DONT_CARE, OUI_SUBTYPE_DONT_CARE);
1388        if(HTInfoIE.Length == 0)
1389        {
1390                HTInfoIE = PacketGetElement(mmpdu, EID_Vendor, OUI_SUB_11N_EWC_HT_INFO, OUI_SUBTYPE_DONT_CARE);
1391                if(HTInfoIE.Length != 0)
1392                                bssDesc->BssHT.bdHTSpecVer  = HT_SPEC_VER_EWC;
1393        }
1394        if(HTInfoIE.Length != 0)
1395                HTParsingHTInfoElement(Adapter, HTInfoIE, bssDesc);
1396
1397        //2<2>If peer is HT, but not WMM, call QosSetLegacyWMMParamWithHT()
1398        if(HTCapIE.Length != 0)
1399        {
1400                bssDesc->BssHT.bdSupportHT = true;
1401                if(bssDesc->BssQos.bdQoSMode == QOS_DISABLE)
1402                        QosSetLegacyWMMParamWithHT(Adapter, bssDesc);
1403        }
1404        else
1405        {
1406                bssDesc->BssHT.bdSupportHT = false;
1407        }
1408
1409        //2<3>Check whether the peer is Realtek AP/STA
1410        if(pHTInfo->bRegRT2RTAggregation)
1411        {
1412                if(bssDesc->BssHT.bdSupportHT)
1413                {
1414                        HTRealtekAgg = PacketGetElement(mmpdu, EID_Vendor, OUI_SUB_REALTEK_AGG, OUI_SUBTYPE_DONT_CARE);
1415                        if(HTRealtekAgg.Length >=5 )
1416                        {
1417                                bssDesc->BssHT.bdRT2RTAggregation = true;
1418
1419                                if((HTRealtekAgg.Octet[4]==1) && (HTRealtekAgg.Octet[5] & 0x02))
1420                                        bssDesc->BssHT.bdRT2RTLongSlotTime = true;
1421                        }
1422                }
1423        }
1424
1425        //
1426        // 2008/01/25 MH Get Broadcom AP IE for manamgent frame CCK rate problem.
1427        // AP can not receive CCK managemtn from from 92E.
1428        //
1429
1430        // Initialize every new bss broadcom cap exist as false..
1431        bssDesc->bBroadcomCapExist= false;
1432
1433        if(HTCapIE.Length != 0 || HTInfoIE.Length != 0)
1434        {
1435                u4Byte  Length = 0;
1436
1437                FillOctetString(BroadcomElement, NULL, 0);
1438
1439                BroadcomElement = PacketGetElement( mmpdu, EID_Vendor, OUI_SUB_BROADCOM_IE_1, OUI_SUBTYPE_DONT_CARE);
1440                Length += BroadcomElement.Length;
1441                BroadcomElement = PacketGetElement( mmpdu, EID_Vendor, OUI_SUB_BROADCOM_IE_2, OUI_SUBTYPE_DONT_CARE);
1442                Length += BroadcomElement.Length;
1443                BroadcomElement = PacketGetElement( mmpdu, EID_Vendor, OUI_SUB_BROADCOM_IE_3, OUI_SUBTYPE_DONT_CARE);
1444                Length += BroadcomElement.Length;
1445
1446                if(Length > 0)
1447                        bssDesc->bBroadcomCapExist = true;
1448        }
1449
1450
1451        // For Cisco IOT issue
1452        CiscoElement = PacketGetElement( mmpdu, EID_Vendor, OUI_SUB_CISCO_IE, OUI_SUBTYPE_DONT_CARE);
1453        if(CiscoElement.Length != 0){ // 3: 0x00, 0x40, 0x96 ....
1454                bssDesc->bCiscoCapExist = true;
1455        }else{
1456                bssDesc->bCiscoCapExist = false;
1457        }
1458}
1459
1460
1461#endif
1462/********************************************************************************************************************
1463 *function:  initialize Bss HT structure(struct PBSS_HT)
1464 *   input:  struct ieee80211_device    *ieee
1465 *           struct ieee80211_network   *pNetwork //usually current network we are live in
1466 *  output:  none
1467 *  return:  none
1468 *  notice: This function should ONLY be called before association
1469********************************************************************************************************************/
1470void HTResetSelfAndSavePeerSetting(struct ieee80211_device* ieee,       struct ieee80211_network * pNetwork)
1471{
1472        PRT_HIGH_THROUGHPUT             pHTInfo = ieee->pHTInfo;
1473//      u16                                             nMaxAMSDUSize;
1474//      PHT_CAPABILITY_ELE              pPeerHTCap = (PHT_CAPABILITY_ELE)pNetwork->bssht.bdHTCapBuf;
1475//      PHT_INFORMATION_ELE             pPeerHTInfo = (PHT_INFORMATION_ELE)pNetwork->bssht.bdHTInfoBuf;
1476//      u8*     pMcsFilter;
1477        u8      bIOTAction = 0;
1478
1479        //
1480        //  Save Peer Setting before Association
1481        //
1482        IEEE80211_DEBUG(IEEE80211_DL_HT, "==============>%s()\n", __FUNCTION__);
1483        /*unmark bEnableHT flag here is the same reason why unmarked in function ieee80211_softmac_new_net. WB 2008.09.10*/
1484//      if( pHTInfo->bEnableHT &&  pNetwork->bssht.bdSupportHT)
1485        if (pNetwork->bssht.bdSupportHT)
1486        {
1487                pHTInfo->bCurrentHTSupport = true;
1488                pHTInfo->ePeerHTSpecVer = pNetwork->bssht.bdHTSpecVer;
1489
1490                // Save HTCap and HTInfo information Element
1491                if(pNetwork->bssht.bdHTCapLen > 0 &&    pNetwork->bssht.bdHTCapLen <= sizeof(pHTInfo->PeerHTCapBuf))
1492                        memcpy(pHTInfo->PeerHTCapBuf, pNetwork->bssht.bdHTCapBuf, pNetwork->bssht.bdHTCapLen);
1493
1494                if(pNetwork->bssht.bdHTInfoLen > 0 && pNetwork->bssht.bdHTInfoLen <= sizeof(pHTInfo->PeerHTInfoBuf))
1495                        memcpy(pHTInfo->PeerHTInfoBuf, pNetwork->bssht.bdHTInfoBuf, pNetwork->bssht.bdHTInfoLen);
1496
1497                // Check whether RT to RT aggregation mode is enabled
1498                if(pHTInfo->bRegRT2RTAggregation)
1499                {
1500                        pHTInfo->bCurrentRT2RTAggregation = pNetwork->bssht.bdRT2RTAggregation;
1501                        pHTInfo->bCurrentRT2RTLongSlotTime = pNetwork->bssht.bdRT2RTLongSlotTime;
1502                }
1503                else
1504                {
1505                        pHTInfo->bCurrentRT2RTAggregation = false;
1506                        pHTInfo->bCurrentRT2RTLongSlotTime = false;
1507                }
1508
1509                // Determine the IOT Peer Vendor.
1510                HTIOTPeerDetermine(ieee);
1511
1512                // Decide IOT Action
1513                // Must be called after the parameter of pHTInfo->bCurrentRT2RTAggregation is decided
1514                pHTInfo->IOTAction = 0;
1515                bIOTAction = HTIOTActIsDisableMCS14(ieee, pNetwork->bssid);
1516                if(bIOTAction)
1517                        pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_MCS14;
1518
1519                bIOTAction = HTIOTActIsDisableMCS15(ieee);
1520                if(bIOTAction)
1521                        pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_MCS15;
1522
1523                bIOTAction = HTIOTActIsDisableMCSTwoSpatialStream(ieee, pNetwork->bssid);
1524                if(bIOTAction)
1525                        pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_ALL_2SS;
1526
1527
1528                bIOTAction = HTIOTActIsDisableEDCATurbo(ieee, pNetwork->bssid);
1529                if(bIOTAction)
1530                        pHTInfo->IOTAction |= HT_IOT_ACT_DISABLE_EDCA_TURBO;
1531
1532                bIOTAction = HTIOTActIsMgntUseCCK6M(pNetwork);
1533                if(bIOTAction)
1534                        pHTInfo->IOTAction |= HT_IOT_ACT_MGNT_USE_CCK_6M;
1535
1536                bIOTAction = HTIOTActIsCCDFsync(pNetwork->bssid);
1537                if(bIOTAction)
1538                        pHTInfo->IOTAction |= HT_IOT_ACT_CDD_FSYNC;
1539
1540
1541        }
1542        else
1543        {
1544                pHTInfo->bCurrentHTSupport = false;
1545                pHTInfo->bCurrentRT2RTAggregation = false;
1546                pHTInfo->bCurrentRT2RTLongSlotTime = false;
1547
1548                pHTInfo->IOTAction = 0;
1549        }
1550
1551}
1552
1553void HTUpdateSelfAndPeerSetting(struct ieee80211_device* ieee,  struct ieee80211_network * pNetwork)
1554{
1555        PRT_HIGH_THROUGHPUT     pHTInfo = ieee->pHTInfo;
1556//      PHT_CAPABILITY_ELE              pPeerHTCap = (PHT_CAPABILITY_ELE)pNetwork->bssht.bdHTCapBuf;
1557        PHT_INFORMATION_ELE             pPeerHTInfo = (PHT_INFORMATION_ELE)pNetwork->bssht.bdHTInfoBuf;
1558
1559        if(pHTInfo->bCurrentHTSupport)
1560        {
1561                //
1562                // Config current operation mode.
1563                //
1564                if(pNetwork->bssht.bdHTInfoLen != 0)
1565                        pHTInfo->CurrentOpMode = pPeerHTInfo->OptMode;
1566
1567                //
1568                // <TODO: Config according to OBSS non-HT STA present!!>
1569                //
1570        }
1571}
1572
1573void HTUseDefaultSetting(struct ieee80211_device* ieee)
1574{
1575        PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1576//      u8      regBwOpMode;
1577
1578        if(pHTInfo->bEnableHT)
1579        {
1580                pHTInfo->bCurrentHTSupport = true;
1581
1582                pHTInfo->bCurSuppCCK = pHTInfo->bRegSuppCCK;
1583
1584                pHTInfo->bCurBW40MHz = pHTInfo->bRegBW40MHz;
1585
1586                pHTInfo->bCurShortGI20MHz= pHTInfo->bRegShortGI20MHz;
1587
1588                pHTInfo->bCurShortGI40MHz= pHTInfo->bRegShortGI40MHz;
1589
1590                pHTInfo->bCurrent_AMSDU_Support = pHTInfo->bAMSDU_Support;
1591
1592                pHTInfo->nCurrent_AMSDU_MaxSize = pHTInfo->nAMSDU_MaxSize;
1593
1594                pHTInfo->bCurrentAMPDUEnable = pHTInfo->bAMPDUEnable;
1595
1596                pHTInfo->CurrentAMPDUFactor = pHTInfo->AMPDU_Factor;
1597
1598                pHTInfo->CurrentMPDUDensity = pHTInfo->CurrentMPDUDensity;
1599
1600                // Set BWOpMode register
1601
1602                //update RATR index0
1603                HTFilterMCSRate(ieee, ieee->Regdot11HTOperationalRateSet, ieee->dot11HTOperationalRateSet);
1604        //function below is not implemented at all. WB
1605#ifdef TODO
1606                Adapter->HalFunc.InitHalRATRTableHandler( Adapter, &pMgntInfo->dot11OperationalRateSet, pMgntInfo->dot11HTOperationalRateSet);
1607#endif
1608                ieee->HTHighestOperaRate = HTGetHighestMCSRate(ieee, ieee->dot11HTOperationalRateSet, MCS_FILTER_ALL);
1609                ieee->HTCurrentOperaRate = ieee->HTHighestOperaRate;
1610
1611        }
1612        else
1613        {
1614                pHTInfo->bCurrentHTSupport = false;
1615        }
1616        return;
1617}
1618/********************************************************************************************************************
1619 *function:  check whether HT control field exists
1620 *   input:  struct ieee80211_device    *ieee
1621 *           u8*                        pFrame //coming skb->data
1622 *  output:  none
1623 *  return:  return true if HT control field exists(false otherwise)
1624 *  notice:
1625********************************************************************************************************************/
1626u8 HTCCheck(struct ieee80211_device* ieee, u8*  pFrame)
1627{
1628        if(ieee->pHTInfo->bCurrentHTSupport)
1629        {
1630                if( (IsQoSDataFrame(pFrame) && Frame_Order(pFrame)) == 1)
1631                {
1632                        IEEE80211_DEBUG(IEEE80211_DL_HT, "HT CONTROL FILED EXIST!!\n");
1633                        return true;
1634                }
1635        }
1636        return false;
1637}
1638
1639//
1640// This function set bandwidth mode in protocol layer.
1641//
1642void HTSetConnectBwMode(struct ieee80211_device* ieee, HT_CHANNEL_WIDTH Bandwidth, HT_EXTCHNL_OFFSET    Offset)
1643{
1644        PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1645//      u32 flags = 0;
1646
1647        if(pHTInfo->bRegBW40MHz == false)
1648                return;
1649
1650
1651
1652        // To reduce dummy operation
1653//      if((pHTInfo->bCurBW40MHz==false && Bandwidth==HT_CHANNEL_WIDTH_20) ||
1654//         (pHTInfo->bCurBW40MHz==true && Bandwidth==HT_CHANNEL_WIDTH_20_40 && Offset==pHTInfo->CurSTAExtChnlOffset))
1655//              return;
1656
1657//      spin_lock_irqsave(&(ieee->bw_spinlock), flags);
1658        if(pHTInfo->bSwBwInProgress) {
1659//              spin_unlock_irqrestore(&(ieee->bw_spinlock), flags);
1660                return;
1661        }
1662        //if in half N mode, set to 20M bandwidth please 09.08.2008 WB.
1663        if(Bandwidth==HT_CHANNEL_WIDTH_20_40 && (!ieee->GetHalfNmodeSupportByAPsHandler(ieee->dev)))
1664         {
1665                        // Handle Illegal extention channel offset!!
1666                if(ieee->current_network.channel<2 && Offset==HT_EXTCHNL_OFFSET_LOWER)
1667                        Offset = HT_EXTCHNL_OFFSET_NO_EXT;
1668                if(Offset==HT_EXTCHNL_OFFSET_UPPER || Offset==HT_EXTCHNL_OFFSET_LOWER) {
1669                        pHTInfo->bCurBW40MHz = true;
1670                        pHTInfo->CurSTAExtChnlOffset = Offset;
1671                } else {
1672                        pHTInfo->bCurBW40MHz = false;
1673                        pHTInfo->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT;
1674                }
1675        } else {
1676                pHTInfo->bCurBW40MHz = false;
1677                pHTInfo->CurSTAExtChnlOffset = HT_EXTCHNL_OFFSET_NO_EXT;
1678        }
1679
1680        pHTInfo->bSwBwInProgress = true;
1681
1682        // TODO: 2007.7.13 by Emily Wait 2000ms  in order to garantee that switching
1683        //   bandwidth is executed after scan is finished. It is a temporal solution
1684        //   because software should ganrantee the last operation of switching bandwidth
1685        //   is executed properlly.
1686        HTSetConnectBwModeCallback(ieee);
1687
1688//      spin_unlock_irqrestore(&(ieee->bw_spinlock), flags);
1689}
1690
1691void HTSetConnectBwModeCallback(struct ieee80211_device* ieee)
1692{
1693        PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1694
1695        IEEE80211_DEBUG(IEEE80211_DL_HT, "======>%s()\n", __FUNCTION__);
1696
1697        if(pHTInfo->bCurBW40MHz)
1698        {
1699                if(pHTInfo->CurSTAExtChnlOffset==HT_EXTCHNL_OFFSET_UPPER)
1700                        ieee->set_chan(ieee->dev, ieee->current_network.channel+2);
1701                else if(pHTInfo->CurSTAExtChnlOffset==HT_EXTCHNL_OFFSET_LOWER)
1702                        ieee->set_chan(ieee->dev, ieee->current_network.channel-2);
1703                else
1704                        ieee->set_chan(ieee->dev, ieee->current_network.channel);
1705
1706                ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20_40, pHTInfo->CurSTAExtChnlOffset);
1707        } else {
1708                ieee->set_chan(ieee->dev, ieee->current_network.channel);
1709                ieee->SetBWModeHandler(ieee->dev, HT_CHANNEL_WIDTH_20, HT_EXTCHNL_OFFSET_NO_EXT);
1710        }
1711
1712        pHTInfo->bSwBwInProgress = false;
1713}
1714
1715#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1716//EXPORT_SYMBOL_NOVERS(HTUpdateSelfAndPeerSetting);
1717#else
1718//EXPORT_SYMBOL(HTUpdateSelfAndPeerSetting);
1719#endif
1720