linux/drivers/staging/rt2860/common/cmm_info.c
<<
>>
Prefs
   1/*
   2 *************************************************************************
   3 * Ralink Tech Inc.
   4 * 5F., No.36, Taiyuan St., Jhubei City,
   5 * Hsinchu County 302,
   6 * Taiwan, R.O.C.
   7 *
   8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
   9 *
  10 * This program is free software; you can redistribute it and/or modify  *
  11 * it under the terms of the GNU General Public License as published by  *
  12 * the Free Software Foundation; either version 2 of the License, or     *
  13 * (at your option) any later version.                                   *
  14 *                                                                       *
  15 * This program is distributed in the hope that it will be useful,       *
  16 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  18 * GNU General Public License for more details.                          *
  19 *                                                                       *
  20 * You should have received a copy of the GNU General Public License     *
  21 * along with this program; if not, write to the                         *
  22 * Free Software Foundation, Inc.,                                       *
  23 * 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  24 *                                                                       *
  25 *************************************************************************
  26*/
  27
  28#include <linux/sched.h>
  29#include "../rt_config.h"
  30
  31INT     Show_SSID_Proc(
  32        IN      PRTMP_ADAPTER   pAd,
  33        OUT     PUCHAR                  pBuf);
  34
  35INT     Show_WirelessMode_Proc(
  36        IN      PRTMP_ADAPTER   pAd,
  37        OUT     PUCHAR                  pBuf);
  38
  39INT     Show_TxBurst_Proc(
  40        IN      PRTMP_ADAPTER   pAd,
  41        OUT     PUCHAR                  pBuf);
  42
  43INT     Show_TxPreamble_Proc(
  44        IN      PRTMP_ADAPTER   pAd,
  45        OUT     PUCHAR                  pBuf);
  46
  47INT     Show_TxPower_Proc(
  48        IN      PRTMP_ADAPTER   pAd,
  49        OUT     PUCHAR                  pBuf);
  50
  51INT     Show_Channel_Proc(
  52        IN      PRTMP_ADAPTER   pAd,
  53        OUT     PUCHAR                  pBuf);
  54
  55INT     Show_BGProtection_Proc(
  56        IN      PRTMP_ADAPTER   pAd,
  57        OUT     PUCHAR                  pBuf);
  58
  59INT     Show_RTSThreshold_Proc(
  60        IN      PRTMP_ADAPTER   pAd,
  61        OUT     PUCHAR                  pBuf);
  62
  63INT     Show_FragThreshold_Proc(
  64        IN      PRTMP_ADAPTER   pAd,
  65        OUT     PUCHAR                  pBuf);
  66
  67INT     Show_HtBw_Proc(
  68        IN      PRTMP_ADAPTER   pAd,
  69        OUT     PUCHAR                  pBuf);
  70
  71INT     Show_HtMcs_Proc(
  72        IN      PRTMP_ADAPTER   pAd,
  73        OUT     PUCHAR                  pBuf);
  74
  75INT     Show_HtGi_Proc(
  76        IN      PRTMP_ADAPTER   pAd,
  77        OUT     PUCHAR                  pBuf);
  78
  79INT     Show_HtOpMode_Proc(
  80        IN      PRTMP_ADAPTER   pAd,
  81        OUT     PUCHAR                  pBuf);
  82
  83INT     Show_HtExtcha_Proc(
  84        IN      PRTMP_ADAPTER   pAd,
  85        OUT     PUCHAR                  pBuf);
  86
  87INT     Show_HtMpduDensity_Proc(
  88        IN      PRTMP_ADAPTER   pAd,
  89        OUT     PUCHAR                  pBuf);
  90
  91INT     Show_HtBaWinSize_Proc(
  92        IN      PRTMP_ADAPTER   pAd,
  93        OUT     PUCHAR                  pBuf);
  94
  95INT     Show_HtRdg_Proc(
  96        IN      PRTMP_ADAPTER   pAd,
  97        OUT     PUCHAR                  pBuf);
  98
  99INT     Show_HtAmsdu_Proc(
 100        IN      PRTMP_ADAPTER   pAd,
 101        OUT     PUCHAR                  pBuf);
 102
 103INT     Show_HtAutoBa_Proc(
 104        IN      PRTMP_ADAPTER   pAd,
 105        OUT     PUCHAR                  pBuf);
 106
 107INT     Show_CountryRegion_Proc(
 108        IN      PRTMP_ADAPTER   pAd,
 109        OUT     PUCHAR                  pBuf);
 110
 111INT     Show_CountryRegionABand_Proc(
 112        IN      PRTMP_ADAPTER   pAd,
 113        OUT     PUCHAR                  pBuf);
 114
 115INT     Show_CountryCode_Proc(
 116        IN      PRTMP_ADAPTER   pAd,
 117        OUT     PUCHAR                  pBuf);
 118
 119#ifdef AGGREGATION_SUPPORT
 120INT     Show_PktAggregate_Proc(
 121        IN      PRTMP_ADAPTER   pAd,
 122        OUT     PUCHAR                  pBuf);
 123#endif // AGGREGATION_SUPPORT //
 124
 125#ifdef WMM_SUPPORT
 126INT     Show_WmmCapable_Proc(
 127        IN      PRTMP_ADAPTER   pAd,
 128        OUT     PUCHAR                  pBuf);
 129#endif // WMM_SUPPORT //
 130
 131INT     Show_IEEE80211H_Proc(
 132        IN      PRTMP_ADAPTER   pAd,
 133        OUT     PUCHAR                  pBuf);
 134
 135INT     Show_NetworkType_Proc(
 136        IN      PRTMP_ADAPTER   pAd,
 137        OUT     PUCHAR                  pBuf);
 138
 139INT     Show_AuthMode_Proc(
 140        IN      PRTMP_ADAPTER   pAd,
 141        OUT     PUCHAR                  pBuf);
 142
 143INT     Show_EncrypType_Proc(
 144        IN      PRTMP_ADAPTER   pAd,
 145        OUT     PUCHAR                  pBuf);
 146
 147INT     Show_DefaultKeyID_Proc(
 148        IN      PRTMP_ADAPTER   pAd,
 149        OUT     PUCHAR                  pBuf);
 150
 151INT     Show_Key1_Proc(
 152        IN      PRTMP_ADAPTER   pAd,
 153        OUT     PUCHAR                  pBuf);
 154
 155INT     Show_Key2_Proc(
 156        IN      PRTMP_ADAPTER   pAd,
 157        OUT     PUCHAR                  pBuf);
 158
 159INT     Show_Key3_Proc(
 160        IN      PRTMP_ADAPTER   pAd,
 161        OUT     PUCHAR                  pBuf);
 162
 163INT     Show_Key4_Proc(
 164        IN      PRTMP_ADAPTER   pAd,
 165        OUT     PUCHAR                  pBuf);
 166
 167INT     Show_WPAPSK_Proc(
 168        IN      PRTMP_ADAPTER   pAd,
 169        OUT     PUCHAR                  pBuf);
 170
 171static struct {
 172        CHAR *name;
 173        INT (*show_proc)(PRTMP_ADAPTER pAdapter, PUCHAR arg);
 174} *PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC, RTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC[] = {
 175        {"SSID",                                        Show_SSID_Proc},
 176        {"WirelessMode",                        Show_WirelessMode_Proc},
 177        {"TxBurst",                                     Show_TxBurst_Proc},
 178        {"TxPreamble",                          Show_TxPreamble_Proc},
 179        {"TxPower",                                     Show_TxPower_Proc},
 180        {"Channel",                                     Show_Channel_Proc},
 181        {"BGProtection",                        Show_BGProtection_Proc},
 182        {"RTSThreshold",                        Show_RTSThreshold_Proc},
 183        {"FragThreshold",                       Show_FragThreshold_Proc},
 184        {"HtBw",                                        Show_HtBw_Proc},
 185        {"HtMcs",                                       Show_HtMcs_Proc},
 186        {"HtGi",                                        Show_HtGi_Proc},
 187        {"HtOpMode",                            Show_HtOpMode_Proc},
 188        {"HtExtcha",                            Show_HtExtcha_Proc},
 189        {"HtMpduDensity",                       Show_HtMpduDensity_Proc},
 190        {"HtBaWinSize",                 Show_HtBaWinSize_Proc},
 191        {"HtRdg",                               Show_HtRdg_Proc},
 192        {"HtAmsdu",                             Show_HtAmsdu_Proc},
 193        {"HtAutoBa",                    Show_HtAutoBa_Proc},
 194        {"CountryRegion",                       Show_CountryRegion_Proc},
 195        {"CountryRegionABand",          Show_CountryRegionABand_Proc},
 196        {"CountryCode",                         Show_CountryCode_Proc},
 197#ifdef AGGREGATION_SUPPORT
 198        {"PktAggregate",                        Show_PktAggregate_Proc},
 199#endif
 200
 201#ifdef WMM_SUPPORT
 202        {"WmmCapable",                          Show_WmmCapable_Proc},
 203#endif
 204        {"IEEE80211H",                          Show_IEEE80211H_Proc},
 205    {"NetworkType",                             Show_NetworkType_Proc},
 206        {"AuthMode",                            Show_AuthMode_Proc},
 207        {"EncrypType",                          Show_EncrypType_Proc},
 208        {"DefaultKeyID",                        Show_DefaultKeyID_Proc},
 209        {"Key1",                                        Show_Key1_Proc},
 210        {"Key2",                                        Show_Key2_Proc},
 211        {"Key3",                                        Show_Key3_Proc},
 212        {"Key4",                                        Show_Key4_Proc},
 213        {"WPAPSK",                                      Show_WPAPSK_Proc},
 214        {NULL, NULL}
 215};
 216
 217/*
 218    ==========================================================================
 219    Description:
 220        Get Driver version.
 221
 222    Return:
 223    ==========================================================================
 224*/
 225INT Set_DriverVersion_Proc(
 226        IN      PRTMP_ADAPTER   pAd,
 227        IN      PUCHAR                  arg)
 228{
 229        DBGPRINT(RT_DEBUG_TRACE, ("Driver version-%s\n", STA_DRIVER_VERSION));
 230
 231    return TRUE;
 232}
 233
 234/*
 235    ==========================================================================
 236    Description:
 237        Set Country Region.
 238        This command will not work, if the field of CountryRegion in eeprom is programmed.
 239    Return:
 240        TRUE if all parameters are OK, FALSE otherwise
 241    ==========================================================================
 242*/
 243INT Set_CountryRegion_Proc(
 244        IN      PRTMP_ADAPTER   pAd,
 245        IN      PUCHAR                  arg)
 246{
 247        ULONG region;
 248
 249        region = simple_strtol(arg, 0, 10);
 250
 251        // Country can be set only when EEPROM not programmed
 252        if (pAd->CommonCfg.CountryRegion & 0x80)
 253        {
 254                DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegion_Proc::parameter of CountryRegion in eeprom is programmed \n"));
 255                return FALSE;
 256        }
 257
 258        if((region >= 0) && (region <= REGION_MAXIMUM_BG_BAND))
 259        {
 260                pAd->CommonCfg.CountryRegion = (UCHAR) region;
 261        }
 262        else if (region == REGION_31_BG_BAND)
 263        {
 264                pAd->CommonCfg.CountryRegion = (UCHAR) region;
 265        }
 266        else
 267        {
 268                DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegion_Proc::parameters out of range\n"));
 269                return FALSE;
 270        }
 271
 272        // if set country region, driver needs to be reset
 273        BuildChannelList(pAd);
 274
 275        DBGPRINT(RT_DEBUG_TRACE, ("Set_CountryRegion_Proc::(CountryRegion=%d)\n", pAd->CommonCfg.CountryRegion));
 276
 277        return TRUE;
 278}
 279
 280/*
 281    ==========================================================================
 282    Description:
 283        Set Country Region for A band.
 284        This command will not work, if the field of CountryRegion in eeprom is programmed.
 285    Return:
 286        TRUE if all parameters are OK, FALSE otherwise
 287    ==========================================================================
 288*/
 289INT Set_CountryRegionABand_Proc(
 290        IN      PRTMP_ADAPTER   pAd,
 291        IN      PUCHAR                  arg)
 292{
 293        ULONG region;
 294
 295        region = simple_strtol(arg, 0, 10);
 296
 297        // Country can be set only when EEPROM not programmed
 298        if (pAd->CommonCfg.CountryRegionForABand & 0x80)
 299        {
 300                DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegionABand_Proc::parameter of CountryRegion in eeprom is programmed \n"));
 301                return FALSE;
 302        }
 303
 304        if((region >= 0) && (region <= REGION_MAXIMUM_A_BAND))
 305        {
 306                pAd->CommonCfg.CountryRegionForABand = (UCHAR) region;
 307        }
 308        else
 309        {
 310                DBGPRINT(RT_DEBUG_ERROR, ("Set_CountryRegionABand_Proc::parameters out of range\n"));
 311                return FALSE;
 312        }
 313
 314        // if set country region, driver needs to be reset
 315        BuildChannelList(pAd);
 316
 317        DBGPRINT(RT_DEBUG_TRACE, ("Set_CountryRegionABand_Proc::(CountryRegion=%d)\n", pAd->CommonCfg.CountryRegionForABand));
 318
 319        return TRUE;
 320}
 321
 322/*
 323    ==========================================================================
 324    Description:
 325        Set Wireless Mode
 326    Return:
 327        TRUE if all parameters are OK, FALSE otherwise
 328    ==========================================================================
 329*/
 330INT     Set_WirelessMode_Proc(
 331        IN      PRTMP_ADAPTER   pAd,
 332        IN      PUCHAR                  arg)
 333{
 334        ULONG   WirelessMode;
 335        INT             success = TRUE;
 336
 337        WirelessMode = simple_strtol(arg, 0, 10);
 338
 339        {
 340                INT MaxPhyMode = PHY_11G;
 341
 342                MaxPhyMode = PHY_11N_5G;
 343
 344                if (WirelessMode <= MaxPhyMode)
 345                {
 346                        RTMPSetPhyMode(pAd, WirelessMode);
 347
 348                        if (WirelessMode >= PHY_11ABGN_MIXED)
 349                        {
 350                                pAd->CommonCfg.BACapability.field.AutoBA = TRUE;
 351                                pAd->CommonCfg.REGBACapability.field.AutoBA = TRUE;
 352                        }
 353                        else
 354                        {
 355                                pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
 356                                pAd->CommonCfg.REGBACapability.field.AutoBA = FALSE;
 357                        }
 358
 359                        // Set AdhocMode rates
 360                        if (pAd->StaCfg.BssType == BSS_ADHOC)
 361                        {
 362                                MlmeUpdateTxRates(pAd, FALSE, 0);
 363                                MakeIbssBeacon(pAd);           // re-build BEACON frame
 364                                AsicEnableIbssSync(pAd);       // copy to on-chip memory
 365                        }
 366                }
 367                else
 368                {
 369                        success = FALSE;
 370                }
 371        }
 372
 373        // it is needed to set SSID to take effect
 374        if (success == TRUE)
 375        {
 376                SetCommonHT(pAd);
 377                DBGPRINT(RT_DEBUG_TRACE, ("Set_WirelessMode_Proc::(=%ld)\n", WirelessMode));
 378        }
 379        else
 380        {
 381                DBGPRINT(RT_DEBUG_ERROR, ("Set_WirelessMode_Proc::parameters out of range\n"));
 382        }
 383
 384        return success;
 385}
 386
 387/*
 388    ==========================================================================
 389    Description:
 390        Set Channel
 391    Return:
 392        TRUE if all parameters are OK, FALSE otherwise
 393    ==========================================================================
 394*/
 395INT     Set_Channel_Proc(
 396        IN      PRTMP_ADAPTER   pAd,
 397        IN      PUCHAR                  arg)
 398{
 399        INT             success = TRUE;
 400        UCHAR   Channel;
 401
 402        Channel = (UCHAR) simple_strtol(arg, 0, 10);
 403
 404        // check if this channel is valid
 405        if (ChannelSanity(pAd, Channel) == TRUE)
 406        {
 407                {
 408                        pAd->CommonCfg.Channel = Channel;
 409
 410                        if (MONITOR_ON(pAd))
 411                        {
 412                                N_ChannelCheck(pAd);
 413                                if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED &&
 414                                        pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)
 415                                {
 416                                        N_SetCenCh(pAd);
 417                                        AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE);
 418                                        AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel);
 419                                        DBGPRINT(RT_DEBUG_TRACE, ("BW_40, control_channel(%d), CentralChannel(%d) \n",
 420                                                                pAd->CommonCfg.Channel, pAd->CommonCfg.CentralChannel));
 421                                }
 422                                else
 423                                {
 424                                        AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE);
 425                                        AsicLockChannel(pAd, pAd->CommonCfg.Channel);
 426                                        DBGPRINT(RT_DEBUG_TRACE, ("BW_20, Channel(%d)\n", pAd->CommonCfg.Channel));
 427                                }
 428                        }
 429                }
 430                success = TRUE;
 431        }
 432        else
 433        {
 434                success = FALSE;
 435        }
 436
 437
 438        if (success == TRUE)
 439                DBGPRINT(RT_DEBUG_TRACE, ("Set_Channel_Proc::(Channel=%d)\n", pAd->CommonCfg.Channel));
 440
 441        return success;
 442}
 443
 444/*
 445    ==========================================================================
 446    Description:
 447        Set Short Slot Time Enable or Disable
 448    Return:
 449        TRUE if all parameters are OK, FALSE otherwise
 450    ==========================================================================
 451*/
 452INT     Set_ShortSlot_Proc(
 453        IN      PRTMP_ADAPTER   pAd,
 454        IN      PUCHAR                  arg)
 455{
 456        ULONG ShortSlot;
 457
 458        ShortSlot = simple_strtol(arg, 0, 10);
 459
 460        if (ShortSlot == 1)
 461                pAd->CommonCfg.bUseShortSlotTime = TRUE;
 462        else if (ShortSlot == 0)
 463                pAd->CommonCfg.bUseShortSlotTime = FALSE;
 464        else
 465                return FALSE;  //Invalid argument
 466
 467        DBGPRINT(RT_DEBUG_TRACE, ("Set_ShortSlot_Proc::(ShortSlot=%d)\n", pAd->CommonCfg.bUseShortSlotTime));
 468
 469        return TRUE;
 470}
 471
 472/*
 473    ==========================================================================
 474    Description:
 475        Set Tx power
 476    Return:
 477        TRUE if all parameters are OK, FALSE otherwise
 478    ==========================================================================
 479*/
 480INT     Set_TxPower_Proc(
 481        IN      PRTMP_ADAPTER   pAd,
 482        IN      PUCHAR                  arg)
 483{
 484        ULONG TxPower;
 485        INT   success = FALSE;
 486
 487        TxPower = (ULONG) simple_strtol(arg, 0, 10);
 488        if (TxPower <= 100)
 489        {
 490                {
 491                        pAd->CommonCfg.TxPowerDefault = TxPower;
 492                        pAd->CommonCfg.TxPowerPercentage = pAd->CommonCfg.TxPowerDefault;
 493                }
 494                success = TRUE;
 495        }
 496        else
 497                success = FALSE;
 498
 499        DBGPRINT(RT_DEBUG_TRACE, ("Set_TxPower_Proc::(TxPowerPercentage=%ld)\n", pAd->CommonCfg.TxPowerPercentage));
 500
 501        return success;
 502}
 503
 504/*
 505    ==========================================================================
 506    Description:
 507        Set 11B/11G Protection
 508    Return:
 509        TRUE if all parameters are OK, FALSE otherwise
 510    ==========================================================================
 511*/
 512INT     Set_BGProtection_Proc(
 513        IN      PRTMP_ADAPTER   pAd,
 514        IN      PUCHAR                  arg)
 515{
 516        switch (simple_strtol(arg, 0, 10))
 517        {
 518                case 0: //AUTO
 519                        pAd->CommonCfg.UseBGProtection = 0;
 520                        break;
 521                case 1: //Always On
 522                        pAd->CommonCfg.UseBGProtection = 1;
 523                        break;
 524                case 2: //Always OFF
 525                        pAd->CommonCfg.UseBGProtection = 2;
 526                        break;
 527                default:  //Invalid argument
 528                        return FALSE;
 529        }
 530
 531
 532        DBGPRINT(RT_DEBUG_TRACE, ("Set_BGProtection_Proc::(BGProtection=%ld)\n", pAd->CommonCfg.UseBGProtection));
 533
 534        return TRUE;
 535}
 536
 537/*
 538    ==========================================================================
 539    Description:
 540        Set TxPreamble
 541    Return:
 542        TRUE if all parameters are OK, FALSE otherwise
 543    ==========================================================================
 544*/
 545INT     Set_TxPreamble_Proc(
 546        IN      PRTMP_ADAPTER   pAd,
 547        IN      PUCHAR                  arg)
 548{
 549        RT_802_11_PREAMBLE      Preamble;
 550
 551        Preamble = simple_strtol(arg, 0, 10);
 552
 553
 554        switch (Preamble)
 555        {
 556                case Rt802_11PreambleShort:
 557                        pAd->CommonCfg.TxPreamble = Preamble;
 558
 559                        MlmeSetTxPreamble(pAd, Rt802_11PreambleShort);
 560                        break;
 561                case Rt802_11PreambleLong:
 562                case Rt802_11PreambleAuto:
 563                        // if user wants AUTO, initialize to LONG here, then change according to AP's
 564                        // capability upon association.
 565                        pAd->CommonCfg.TxPreamble = Preamble;
 566
 567                        MlmeSetTxPreamble(pAd, Rt802_11PreambleLong);
 568                        break;
 569                default: //Invalid argument
 570                        return FALSE;
 571        }
 572
 573        DBGPRINT(RT_DEBUG_TRACE, ("Set_TxPreamble_Proc::(TxPreamble=%ld)\n", pAd->CommonCfg.TxPreamble));
 574
 575        return TRUE;
 576}
 577
 578/*
 579    ==========================================================================
 580    Description:
 581        Set RTS Threshold
 582    Return:
 583        TRUE if all parameters are OK, FALSE otherwise
 584    ==========================================================================
 585*/
 586INT     Set_RTSThreshold_Proc(
 587        IN      PRTMP_ADAPTER   pAd,
 588        IN      PUCHAR                  arg)
 589{
 590         NDIS_802_11_RTS_THRESHOLD           RtsThresh;
 591
 592        RtsThresh = simple_strtol(arg, 0, 10);
 593
 594        if((RtsThresh > 0) && (RtsThresh <= MAX_RTS_THRESHOLD))
 595                pAd->CommonCfg.RtsThreshold  = (USHORT)RtsThresh;
 596        else if (RtsThresh == 0)
 597                pAd->CommonCfg.RtsThreshold = MAX_RTS_THRESHOLD;
 598        else
 599                return FALSE; //Invalid argument
 600
 601        DBGPRINT(RT_DEBUG_TRACE, ("Set_RTSThreshold_Proc::(RTSThreshold=%d)\n", pAd->CommonCfg.RtsThreshold));
 602
 603        return TRUE;
 604}
 605
 606/*
 607    ==========================================================================
 608    Description:
 609        Set Fragment Threshold
 610    Return:
 611        TRUE if all parameters are OK, FALSE otherwise
 612    ==========================================================================
 613*/
 614INT     Set_FragThreshold_Proc(
 615        IN      PRTMP_ADAPTER   pAd,
 616        IN      PUCHAR                  arg)
 617{
 618         NDIS_802_11_FRAGMENTATION_THRESHOLD     FragThresh;
 619
 620        FragThresh = simple_strtol(arg, 0, 10);
 621
 622        if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
 623        {
 624                //Illegal FragThresh so we set it to default
 625                pAd->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
 626        }
 627        else if (FragThresh % 2 == 1)
 628        {
 629                // The length of each fragment shall always be an even number of octets, except for the last fragment
 630                // of an MSDU or MMPDU, which may be either an even or an odd number of octets.
 631                pAd->CommonCfg.FragmentThreshold = (USHORT)(FragThresh - 1);
 632        }
 633        else
 634        {
 635                pAd->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
 636        }
 637
 638        {
 639                if (pAd->CommonCfg.FragmentThreshold == MAX_FRAG_THRESHOLD)
 640                        pAd->CommonCfg.bUseZeroToDisableFragment = TRUE;
 641                else
 642                        pAd->CommonCfg.bUseZeroToDisableFragment = FALSE;
 643        }
 644
 645        DBGPRINT(RT_DEBUG_TRACE, ("Set_FragThreshold_Proc::(FragThreshold=%d)\n", pAd->CommonCfg.FragmentThreshold));
 646
 647        return TRUE;
 648}
 649
 650/*
 651    ==========================================================================
 652    Description:
 653        Set TxBurst
 654    Return:
 655        TRUE if all parameters are OK, FALSE otherwise
 656    ==========================================================================
 657*/
 658INT     Set_TxBurst_Proc(
 659        IN      PRTMP_ADAPTER   pAd,
 660        IN      PUCHAR                  arg)
 661{
 662        ULONG TxBurst;
 663
 664        TxBurst = simple_strtol(arg, 0, 10);
 665        if (TxBurst == 1)
 666                pAd->CommonCfg.bEnableTxBurst = TRUE;
 667        else if (TxBurst == 0)
 668                pAd->CommonCfg.bEnableTxBurst = FALSE;
 669        else
 670                return FALSE;  //Invalid argument
 671
 672        DBGPRINT(RT_DEBUG_TRACE, ("Set_TxBurst_Proc::(TxBurst=%d)\n", pAd->CommonCfg.bEnableTxBurst));
 673
 674        return TRUE;
 675}
 676
 677#ifdef AGGREGATION_SUPPORT
 678/*
 679    ==========================================================================
 680    Description:
 681        Set TxBurst
 682    Return:
 683        TRUE if all parameters are OK, FALSE otherwise
 684    ==========================================================================
 685*/
 686INT     Set_PktAggregate_Proc(
 687        IN      PRTMP_ADAPTER   pAd,
 688        IN      PUCHAR                  arg)
 689{
 690        ULONG aggre;
 691
 692        aggre = simple_strtol(arg, 0, 10);
 693
 694        if (aggre == 1)
 695                pAd->CommonCfg.bAggregationCapable = TRUE;
 696        else if (aggre == 0)
 697                pAd->CommonCfg.bAggregationCapable = FALSE;
 698        else
 699                return FALSE;  //Invalid argument
 700
 701
 702        DBGPRINT(RT_DEBUG_TRACE, ("Set_PktAggregate_Proc::(AGGRE=%d)\n", pAd->CommonCfg.bAggregationCapable));
 703
 704        return TRUE;
 705}
 706#endif
 707
 708/*
 709    ==========================================================================
 710    Description:
 711        Set IEEE80211H.
 712        This parameter is 1 when needs radar detection, otherwise 0
 713    Return:
 714        TRUE if all parameters are OK, FALSE otherwise
 715    ==========================================================================
 716*/
 717INT     Set_IEEE80211H_Proc(
 718        IN      PRTMP_ADAPTER   pAd,
 719        IN      PUCHAR                  arg)
 720{
 721    ULONG ieee80211h;
 722
 723        ieee80211h = simple_strtol(arg, 0, 10);
 724
 725        if (ieee80211h == 1)
 726                pAd->CommonCfg.bIEEE80211H = TRUE;
 727        else if (ieee80211h == 0)
 728                pAd->CommonCfg.bIEEE80211H = FALSE;
 729        else
 730                return FALSE;  //Invalid argument
 731
 732        DBGPRINT(RT_DEBUG_TRACE, ("Set_IEEE80211H_Proc::(IEEE80211H=%d)\n", pAd->CommonCfg.bIEEE80211H));
 733
 734        return TRUE;
 735}
 736
 737
 738#ifdef DBG
 739/*
 740    ==========================================================================
 741    Description:
 742        For Debug information
 743    Return:
 744        TRUE if all parameters are OK, FALSE otherwise
 745    ==========================================================================
 746*/
 747INT     Set_Debug_Proc(
 748        IN      PRTMP_ADAPTER   pAd,
 749        IN      PUCHAR                  arg)
 750{
 751        DBGPRINT(RT_DEBUG_TRACE, ("==> Set_Debug_Proc *******************\n"));
 752
 753    if(simple_strtol(arg, 0, 10) <= RT_DEBUG_LOUD)
 754        RTDebugLevel = simple_strtol(arg, 0, 10);
 755
 756        DBGPRINT(RT_DEBUG_TRACE, ("<== Set_Debug_Proc(RTDebugLevel = %ld)\n", RTDebugLevel));
 757
 758        return TRUE;
 759}
 760#endif
 761
 762INT     Show_DescInfo_Proc(
 763        IN      PRTMP_ADAPTER   pAd,
 764        IN      PUCHAR                  arg)
 765{
 766#ifdef RT2860
 767        INT i, QueIdx=0;
 768        PRT28XX_RXD_STRUC pRxD;
 769    PTXD_STRUC pTxD;
 770        PRTMP_TX_RING   pTxRing = &pAd->TxRing[QueIdx];
 771        PRTMP_MGMT_RING pMgmtRing = &pAd->MgmtRing;
 772        PRTMP_RX_RING   pRxRing = &pAd->RxRing;
 773
 774        for(i=0;i<TX_RING_SIZE;i++)
 775        {
 776            pTxD = (PTXD_STRUC) pTxRing->Cell[i].AllocVa;
 777            printk("Desc #%d\n",i);
 778            hex_dump("Tx Descriptor", (char *)pTxD, 16);
 779            printk("pTxD->DMADONE = %x\n", pTxD->DMADONE);
 780        }
 781        printk("---------------------------------------------------\n");
 782        for(i=0;i<MGMT_RING_SIZE;i++)
 783        {
 784            pTxD = (PTXD_STRUC) pMgmtRing->Cell[i].AllocVa;
 785            printk("Desc #%d\n",i);
 786            hex_dump("Mgmt Descriptor", (char *)pTxD, 16);
 787            printk("pMgmt->DMADONE = %x\n", pTxD->DMADONE);
 788        }
 789        printk("---------------------------------------------------\n");
 790        for(i=0;i<RX_RING_SIZE;i++)
 791        {
 792            pRxD = (PRT28XX_RXD_STRUC) pRxRing->Cell[i].AllocVa;
 793            printk("Desc #%d\n",i);
 794            hex_dump("Rx Descriptor", (char *)pRxD, 16);
 795                printk("pRxD->DDONE = %x\n", pRxD->DDONE);
 796        }
 797#endif /* RT2860 */
 798        return TRUE;
 799}
 800
 801/*
 802    ==========================================================================
 803    Description:
 804        Reset statistics counter
 805
 806    Arguments:
 807        pAdapter            Pointer to our adapter
 808        arg
 809
 810    Return:
 811        TRUE if all parameters are OK, FALSE otherwise
 812    ==========================================================================
 813*/
 814INT     Set_ResetStatCounter_Proc(
 815        IN      PRTMP_ADAPTER   pAd,
 816        IN      PUCHAR                  arg)
 817{
 818        DBGPRINT(RT_DEBUG_TRACE, ("==>Set_ResetStatCounter_Proc\n"));
 819
 820        // add the most up-to-date h/w raw counters into software counters
 821        NICUpdateRawCounters(pAd);
 822
 823        NdisZeroMemory(&pAd->WlanCounters, sizeof(COUNTER_802_11));
 824        NdisZeroMemory(&pAd->Counters8023, sizeof(COUNTER_802_3));
 825        NdisZeroMemory(&pAd->RalinkCounters, sizeof(COUNTER_RALINK));
 826
 827        return TRUE;
 828}
 829
 830BOOLEAN RTMPCheckStrPrintAble(
 831    IN  CHAR *pInPutStr,
 832    IN  UCHAR strLen)
 833{
 834    UCHAR i=0;
 835
 836    for (i=0; i<strLen; i++)
 837    {
 838        if ((pInPutStr[i] < 0x21) ||
 839            (pInPutStr[i] > 0x7E))
 840            return FALSE;
 841    }
 842
 843    return TRUE;
 844}
 845
 846/*
 847        ========================================================================
 848
 849        Routine Description:
 850                Remove WPA Key process
 851
 852        Arguments:
 853                pAd                                     Pointer to our adapter
 854                pBuf                                                    Pointer to the where the key stored
 855
 856        Return Value:
 857                NDIS_SUCCESS                                    Add key successfully
 858
 859        IRQL = DISPATCH_LEVEL
 860
 861        Note:
 862
 863        ========================================================================
 864*/
 865VOID    RTMPSetDesiredRates(
 866    IN  PRTMP_ADAPTER   pAdapter,
 867    IN  LONG            Rates)
 868{
 869    NDIS_802_11_RATES aryRates;
 870
 871    memset(&aryRates, 0x00, sizeof(NDIS_802_11_RATES));
 872    switch (pAdapter->CommonCfg.PhyMode)
 873    {
 874        case PHY_11A: // A only
 875            switch (Rates)
 876            {
 877                case 6000000: //6M
 878                    aryRates[0] = 0x0c; // 6M
 879                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_0;
 880                    break;
 881                case 9000000: //9M
 882                    aryRates[0] = 0x12; // 9M
 883                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_1;
 884                    break;
 885                case 12000000: //12M
 886                    aryRates[0] = 0x18; // 12M
 887                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_2;
 888                    break;
 889                case 18000000: //18M
 890                    aryRates[0] = 0x24; // 18M
 891                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_3;
 892                    break;
 893                case 24000000: //24M
 894                    aryRates[0] = 0x30; // 24M
 895                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_4;
 896                    break;
 897                case 36000000: //36M
 898                    aryRates[0] = 0x48; // 36M
 899                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_5;
 900                    break;
 901                case 48000000: //48M
 902                    aryRates[0] = 0x60; // 48M
 903                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_6;
 904                    break;
 905                case 54000000: //54M
 906                    aryRates[0] = 0x6c; // 54M
 907                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_7;
 908                    break;
 909                case -1: //Auto
 910                default:
 911                    aryRates[0] = 0x6c; // 54Mbps
 912                    aryRates[1] = 0x60; // 48Mbps
 913                    aryRates[2] = 0x48; // 36Mbps
 914                    aryRates[3] = 0x30; // 24Mbps
 915                    aryRates[4] = 0x24; // 18M
 916                    aryRates[5] = 0x18; // 12M
 917                    aryRates[6] = 0x12; // 9M
 918                    aryRates[7] = 0x0c; // 6M
 919                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
 920                    break;
 921            }
 922            break;
 923        case PHY_11BG_MIXED: // B/G Mixed
 924        case PHY_11B: // B only
 925        case PHY_11ABG_MIXED: // A/B/G Mixed
 926        default:
 927            switch (Rates)
 928            {
 929                case 1000000: //1M
 930                    aryRates[0] = 0x02;
 931                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_0;
 932                    break;
 933                case 2000000: //2M
 934                    aryRates[0] = 0x04;
 935                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_1;
 936                    break;
 937                case 5000000: //5.5M
 938                    aryRates[0] = 0x0b; // 5.5M
 939                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_2;
 940                    break;
 941                case 11000000: //11M
 942                    aryRates[0] = 0x16; // 11M
 943                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_3;
 944                    break;
 945                case 6000000: //6M
 946                    aryRates[0] = 0x0c; // 6M
 947                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_0;
 948                    break;
 949                case 9000000: //9M
 950                    aryRates[0] = 0x12; // 9M
 951                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_1;
 952                    break;
 953                case 12000000: //12M
 954                    aryRates[0] = 0x18; // 12M
 955                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_2;
 956                    break;
 957                case 18000000: //18M
 958                    aryRates[0] = 0x24; // 18M
 959                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_3;
 960                    break;
 961                case 24000000: //24M
 962                    aryRates[0] = 0x30; // 24M
 963                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_4;
 964                    break;
 965                case 36000000: //36M
 966                    aryRates[0] = 0x48; // 36M
 967                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_5;
 968                    break;
 969                case 48000000: //48M
 970                    aryRates[0] = 0x60; // 48M
 971                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_6;
 972                    break;
 973                case 54000000: //54M
 974                    aryRates[0] = 0x6c; // 54M
 975                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_7;
 976                    break;
 977                case -1: //Auto
 978                default:
 979                    if (pAdapter->CommonCfg.PhyMode == PHY_11B)
 980                    { //B Only
 981                        aryRates[0] = 0x16; // 11Mbps
 982                        aryRates[1] = 0x0b; // 5.5Mbps
 983                        aryRates[2] = 0x04; // 2Mbps
 984                        aryRates[3] = 0x02; // 1Mbps
 985                    }
 986                    else
 987                    { //(B/G) Mixed or (A/B/G) Mixed
 988                        aryRates[0] = 0x6c; // 54Mbps
 989                        aryRates[1] = 0x60; // 48Mbps
 990                        aryRates[2] = 0x48; // 36Mbps
 991                        aryRates[3] = 0x30; // 24Mbps
 992                        aryRates[4] = 0x16; // 11Mbps
 993                        aryRates[5] = 0x0b; // 5.5Mbps
 994                        aryRates[6] = 0x04; // 2Mbps
 995                        aryRates[7] = 0x02; // 1Mbps
 996                    }
 997                    pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
 998                    break;
 999            }
1000            break;
1001    }
1002
1003    NdisZeroMemory(pAdapter->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
1004    NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, sizeof(NDIS_802_11_RATES));
1005    DBGPRINT(RT_DEBUG_TRACE, (" RTMPSetDesiredRates (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n",
1006        pAdapter->CommonCfg.DesireRate[0],pAdapter->CommonCfg.DesireRate[1],
1007        pAdapter->CommonCfg.DesireRate[2],pAdapter->CommonCfg.DesireRate[3],
1008        pAdapter->CommonCfg.DesireRate[4],pAdapter->CommonCfg.DesireRate[5],
1009        pAdapter->CommonCfg.DesireRate[6],pAdapter->CommonCfg.DesireRate[7] ));
1010    // Changing DesiredRate may affect the MAX TX rate we used to TX frames out
1011    MlmeUpdateTxRates(pAdapter, FALSE, 0);
1012}
1013
1014NDIS_STATUS RTMPWPARemoveKeyProc(
1015        IN      PRTMP_ADAPTER   pAd,
1016        IN      PVOID                   pBuf)
1017{
1018        PNDIS_802_11_REMOVE_KEY pKey;
1019        ULONG                                   KeyIdx;
1020        NDIS_STATUS                     Status = NDIS_STATUS_FAILURE;
1021        BOOLEAN         bTxKey;                 // Set the key as transmit key
1022        BOOLEAN         bPairwise;              // Indicate the key is pairwise key
1023        BOOLEAN         bKeyRSC;                // indicate the receive  SC set by KeyRSC value.
1024                                                                // Otherwise, it will set by the NIC.
1025        BOOLEAN         bAuthenticator; // indicate key is set by authenticator.
1026        INT             i;
1027
1028        DBGPRINT(RT_DEBUG_TRACE,("---> RTMPWPARemoveKeyProc\n"));
1029
1030        pKey = (PNDIS_802_11_REMOVE_KEY) pBuf;
1031        KeyIdx = pKey->KeyIndex & 0xff;
1032        // Bit 31 of Add-key, Tx Key
1033        bTxKey             = (pKey->KeyIndex & 0x80000000) ? TRUE : FALSE;
1034        // Bit 30 of Add-key PairwiseKey
1035        bPairwise          = (pKey->KeyIndex & 0x40000000) ? TRUE : FALSE;
1036        // Bit 29 of Add-key KeyRSC
1037        bKeyRSC            = (pKey->KeyIndex & 0x20000000) ? TRUE : FALSE;
1038        // Bit 28 of Add-key Authenticator
1039        bAuthenticator = (pKey->KeyIndex & 0x10000000) ? TRUE : FALSE;
1040
1041        // 1. If bTx is TRUE, return failure information
1042        if (bTxKey == TRUE)
1043                return(NDIS_STATUS_INVALID_DATA);
1044
1045        // 2. Check Pairwise Key
1046        if (bPairwise)
1047        {
1048                // a. If BSSID is broadcast, remove all pairwise keys.
1049                // b. If not broadcast, remove the pairwise specified by BSSID
1050                for (i = 0; i < SHARE_KEY_NUM; i++)
1051                {
1052                        if (MAC_ADDR_EQUAL(pAd->SharedKey[BSS0][i].BssId, pKey->BSSID))
1053                        {
1054                                DBGPRINT(RT_DEBUG_TRACE,("RTMPWPARemoveKeyProc(KeyIdx=%d)\n", i));
1055                                pAd->SharedKey[BSS0][i].KeyLen = 0;
1056                                pAd->SharedKey[BSS0][i].CipherAlg = CIPHER_NONE;
1057                                AsicRemoveSharedKeyEntry(pAd, BSS0, (UCHAR)i);
1058                                Status = NDIS_STATUS_SUCCESS;
1059                                break;
1060                        }
1061                }
1062        }
1063        // 3. Group Key
1064        else
1065        {
1066                // a. If BSSID is broadcast, remove all group keys indexed
1067                // b. If BSSID matched, delete the group key indexed.
1068                DBGPRINT(RT_DEBUG_TRACE,("RTMPWPARemoveKeyProc(KeyIdx=%ld)\n", KeyIdx));
1069                pAd->SharedKey[BSS0][KeyIdx].KeyLen = 0;
1070                pAd->SharedKey[BSS0][KeyIdx].CipherAlg = CIPHER_NONE;
1071                AsicRemoveSharedKeyEntry(pAd, BSS0, (UCHAR)KeyIdx);
1072                Status = NDIS_STATUS_SUCCESS;
1073        }
1074
1075        return (Status);
1076}
1077
1078/*
1079        ========================================================================
1080
1081        Routine Description:
1082                Remove All WPA Keys
1083
1084        Arguments:
1085                pAd                                     Pointer to our adapter
1086
1087        Return Value:
1088                None
1089
1090        IRQL = DISPATCH_LEVEL
1091
1092        Note:
1093
1094        ========================================================================
1095*/
1096VOID    RTMPWPARemoveAllKeys(
1097        IN      PRTMP_ADAPTER   pAd)
1098{
1099
1100        UCHAR   i;
1101
1102        DBGPRINT(RT_DEBUG_TRACE,("RTMPWPARemoveAllKeys(AuthMode=%d, WepStatus=%d)\n", pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus));
1103
1104        // For WEP/CKIP, there is no need to remove it, since WinXP won't set it again after
1105        // Link up. And it will be replaced if user changed it.
1106        if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA)
1107                return;
1108
1109        // For WPA-None, there is no need to remove it, since WinXP won't set it again after
1110        // Link up. And it will be replaced if user changed it.
1111        if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
1112                return;
1113
1114        // set BSSID wcid entry of the Pair-wise Key table as no-security mode
1115        AsicRemovePairwiseKeyEntry(pAd, BSS0, BSSID_WCID);
1116
1117        // set all shared key mode as no-security.
1118        for (i = 0; i < SHARE_KEY_NUM; i++)
1119    {
1120                DBGPRINT(RT_DEBUG_TRACE,("remove %s key #%d\n", CipherName[pAd->SharedKey[BSS0][i].CipherAlg], i));
1121                NdisZeroMemory(&pAd->SharedKey[BSS0][i], sizeof(CIPHER_KEY));
1122
1123                AsicRemoveSharedKeyEntry(pAd, BSS0, i);
1124        }
1125
1126}
1127
1128/*
1129        ========================================================================
1130        Routine Description:
1131                Change NIC PHY mode. Re-association may be necessary. possible settings
1132                include - PHY_11B, PHY_11BG_MIXED, PHY_11A, and PHY_11ABG_MIXED
1133
1134        Arguments:
1135                pAd - Pointer to our adapter
1136                phymode  -
1137
1138        IRQL = PASSIVE_LEVEL
1139        IRQL = DISPATCH_LEVEL
1140
1141        ========================================================================
1142*/
1143VOID    RTMPSetPhyMode(
1144        IN      PRTMP_ADAPTER   pAd,
1145        IN      ULONG phymode)
1146{
1147        INT i;
1148        // the selected phymode must be supported by the RF IC encoded in E2PROM
1149
1150        pAd->CommonCfg.PhyMode = (UCHAR)phymode;
1151
1152        DBGPRINT(RT_DEBUG_TRACE,("RTMPSetPhyMode : PhyMode=%d, channel=%d \n", pAd->CommonCfg.PhyMode, pAd->CommonCfg.Channel));
1153
1154        BuildChannelList(pAd);
1155
1156        // sanity check user setting
1157        for (i = 0; i < pAd->ChannelListNum; i++)
1158        {
1159                if (pAd->CommonCfg.Channel == pAd->ChannelList[i].Channel)
1160                        break;
1161        }
1162
1163        if (i == pAd->ChannelListNum)
1164        {
1165                pAd->CommonCfg.Channel = FirstChannel(pAd);
1166                DBGPRINT(RT_DEBUG_ERROR, ("RTMPSetPhyMode: channel is out of range, use first channel=%d \n", pAd->CommonCfg.Channel));
1167        }
1168
1169        NdisZeroMemory(pAd->CommonCfg.SupRate, MAX_LEN_OF_SUPPORTED_RATES);
1170        NdisZeroMemory(pAd->CommonCfg.ExtRate, MAX_LEN_OF_SUPPORTED_RATES);
1171        NdisZeroMemory(pAd->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES);
1172        switch (phymode) {
1173                case PHY_11B:
1174                        pAd->CommonCfg.SupRate[0]  = 0x82;        // 1 mbps, in units of 0.5 Mbps, basic rate
1175                        pAd->CommonCfg.SupRate[1]  = 0x84;        // 2 mbps, in units of 0.5 Mbps, basic rate
1176                        pAd->CommonCfg.SupRate[2]  = 0x8B;        // 5.5 mbps, in units of 0.5 Mbps, basic rate
1177                        pAd->CommonCfg.SupRate[3]  = 0x96;        // 11 mbps, in units of 0.5 Mbps, basic rate
1178                        pAd->CommonCfg.SupRateLen  = 4;
1179                        pAd->CommonCfg.ExtRateLen  = 0;
1180                        pAd->CommonCfg.DesireRate[0]  = 2;         // 1 mbps, in units of 0.5 Mbps
1181                        pAd->CommonCfg.DesireRate[1]  = 4;         // 2 mbps, in units of 0.5 Mbps
1182                        pAd->CommonCfg.DesireRate[2]  = 11;    // 5.5 mbps, in units of 0.5 Mbps
1183                        pAd->CommonCfg.DesireRate[3]  = 22;    // 11 mbps, in units of 0.5 Mbps
1184                        //pAd->CommonCfg.HTPhyMode.field.MODE = MODE_CCK; // This MODE is only FYI. not use
1185                        break;
1186
1187                case PHY_11G:
1188                case PHY_11BG_MIXED:
1189                case PHY_11ABG_MIXED:
1190                case PHY_11N_2_4G:
1191                case PHY_11ABGN_MIXED:
1192                case PHY_11BGN_MIXED:
1193                case PHY_11GN_MIXED:
1194                        pAd->CommonCfg.SupRate[0]  = 0x82;        // 1 mbps, in units of 0.5 Mbps, basic rate
1195                        pAd->CommonCfg.SupRate[1]  = 0x84;        // 2 mbps, in units of 0.5 Mbps, basic rate
1196                        pAd->CommonCfg.SupRate[2]  = 0x8B;        // 5.5 mbps, in units of 0.5 Mbps, basic rate
1197                        pAd->CommonCfg.SupRate[3]  = 0x96;        // 11 mbps, in units of 0.5 Mbps, basic rate
1198                        pAd->CommonCfg.SupRate[4]  = 0x12;        // 9 mbps, in units of 0.5 Mbps
1199                        pAd->CommonCfg.SupRate[5]  = 0x24;        // 18 mbps, in units of 0.5 Mbps
1200                        pAd->CommonCfg.SupRate[6]  = 0x48;        // 36 mbps, in units of 0.5 Mbps
1201                        pAd->CommonCfg.SupRate[7]  = 0x6c;        // 54 mbps, in units of 0.5 Mbps
1202                        pAd->CommonCfg.SupRateLen  = 8;
1203                        pAd->CommonCfg.ExtRate[0]  = 0x0C;        // 6 mbps, in units of 0.5 Mbps
1204                        pAd->CommonCfg.ExtRate[1]  = 0x18;        // 12 mbps, in units of 0.5 Mbps
1205                        pAd->CommonCfg.ExtRate[2]  = 0x30;        // 24 mbps, in units of 0.5 Mbps
1206                        pAd->CommonCfg.ExtRate[3]  = 0x60;        // 48 mbps, in units of 0.5 Mbps
1207                        pAd->CommonCfg.ExtRateLen  = 4;
1208                        pAd->CommonCfg.DesireRate[0]  = 2;         // 1 mbps, in units of 0.5 Mbps
1209                        pAd->CommonCfg.DesireRate[1]  = 4;         // 2 mbps, in units of 0.5 Mbps
1210                        pAd->CommonCfg.DesireRate[2]  = 11;    // 5.5 mbps, in units of 0.5 Mbps
1211                        pAd->CommonCfg.DesireRate[3]  = 22;    // 11 mbps, in units of 0.5 Mbps
1212                        pAd->CommonCfg.DesireRate[4]  = 12;    // 6 mbps, in units of 0.5 Mbps
1213                        pAd->CommonCfg.DesireRate[5]  = 18;    // 9 mbps, in units of 0.5 Mbps
1214                        pAd->CommonCfg.DesireRate[6]  = 24;    // 12 mbps, in units of 0.5 Mbps
1215                        pAd->CommonCfg.DesireRate[7]  = 36;    // 18 mbps, in units of 0.5 Mbps
1216                        pAd->CommonCfg.DesireRate[8]  = 48;    // 24 mbps, in units of 0.5 Mbps
1217                        pAd->CommonCfg.DesireRate[9]  = 72;    // 36 mbps, in units of 0.5 Mbps
1218                        pAd->CommonCfg.DesireRate[10] = 96;    // 48 mbps, in units of 0.5 Mbps
1219                        pAd->CommonCfg.DesireRate[11] = 108;   // 54 mbps, in units of 0.5 Mbps
1220                        break;
1221
1222                case PHY_11A:
1223                case PHY_11AN_MIXED:
1224                case PHY_11AGN_MIXED:
1225                case PHY_11N_5G:
1226                        pAd->CommonCfg.SupRate[0]  = 0x8C;        // 6 mbps, in units of 0.5 Mbps, basic rate
1227                        pAd->CommonCfg.SupRate[1]  = 0x12;        // 9 mbps, in units of 0.5 Mbps
1228                        pAd->CommonCfg.SupRate[2]  = 0x98;        // 12 mbps, in units of 0.5 Mbps, basic rate
1229                        pAd->CommonCfg.SupRate[3]  = 0x24;        // 18 mbps, in units of 0.5 Mbps
1230                        pAd->CommonCfg.SupRate[4]  = 0xb0;        // 24 mbps, in units of 0.5 Mbps, basic rate
1231                        pAd->CommonCfg.SupRate[5]  = 0x48;        // 36 mbps, in units of 0.5 Mbps
1232                        pAd->CommonCfg.SupRate[6]  = 0x60;        // 48 mbps, in units of 0.5 Mbps
1233                        pAd->CommonCfg.SupRate[7]  = 0x6c;        // 54 mbps, in units of 0.5 Mbps
1234                        pAd->CommonCfg.SupRateLen  = 8;
1235                        pAd->CommonCfg.ExtRateLen  = 0;
1236                        pAd->CommonCfg.DesireRate[0]  = 12;    // 6 mbps, in units of 0.5 Mbps
1237                        pAd->CommonCfg.DesireRate[1]  = 18;    // 9 mbps, in units of 0.5 Mbps
1238                        pAd->CommonCfg.DesireRate[2]  = 24;    // 12 mbps, in units of 0.5 Mbps
1239                        pAd->CommonCfg.DesireRate[3]  = 36;    // 18 mbps, in units of 0.5 Mbps
1240                        pAd->CommonCfg.DesireRate[4]  = 48;    // 24 mbps, in units of 0.5 Mbps
1241                        pAd->CommonCfg.DesireRate[5]  = 72;    // 36 mbps, in units of 0.5 Mbps
1242                        pAd->CommonCfg.DesireRate[6]  = 96;    // 48 mbps, in units of 0.5 Mbps
1243                        pAd->CommonCfg.DesireRate[7]  = 108;   // 54 mbps, in units of 0.5 Mbps
1244                        //pAd->CommonCfg.HTPhyMode.field.MODE = MODE_OFDM; // This MODE is only FYI. not use
1245                        break;
1246
1247                default:
1248                        break;
1249        }
1250
1251
1252        pAd->CommonCfg.BandState = UNKNOWN_BAND;
1253}
1254
1255/*
1256        ========================================================================
1257        Routine Description:
1258                Caller ensures we has 802.11n support.
1259                Calls at setting HT from AP/STASetinformation
1260
1261        Arguments:
1262                pAd - Pointer to our adapter
1263                phymode  -
1264
1265        ========================================================================
1266*/
1267VOID    RTMPSetHT(
1268        IN      PRTMP_ADAPTER   pAd,
1269        IN      OID_SET_HT_PHYMODE *pHTPhyMode)
1270{
1271        //ULONG *pmcs;
1272        UINT32  Value = 0;
1273        UCHAR   BBPValue = 0;
1274        UCHAR   BBP3Value = 0;
1275        UCHAR   RxStream = pAd->CommonCfg.RxStream;
1276
1277        DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetHT : HT_mode(%d), ExtOffset(%d), MCS(%d), BW(%d), STBC(%d), SHORTGI(%d)\n",
1278                                                                                pHTPhyMode->HtMode, pHTPhyMode->ExtOffset,
1279                                                                                pHTPhyMode->MCS, pHTPhyMode->BW,
1280                                                                                pHTPhyMode->STBC, pHTPhyMode->SHORTGI));
1281
1282        // Don't zero supportedHyPhy structure.
1283        RTMPZeroMemory(&pAd->CommonCfg.HtCapability, sizeof(pAd->CommonCfg.HtCapability));
1284        RTMPZeroMemory(&pAd->CommonCfg.AddHTInfo, sizeof(pAd->CommonCfg.AddHTInfo));
1285        RTMPZeroMemory(&pAd->CommonCfg.NewExtChanOffset, sizeof(pAd->CommonCfg.NewExtChanOffset));
1286        RTMPZeroMemory(&pAd->CommonCfg.DesiredHtPhy, sizeof(pAd->CommonCfg.DesiredHtPhy));
1287
1288        if (pAd->CommonCfg.bRdg)
1289        {
1290                pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 1;
1291                pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 1;
1292        }
1293        else
1294        {
1295                pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 0;
1296                pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 0;
1297        }
1298
1299        pAd->CommonCfg.HtCapability.HtCapParm.MaxRAmpduFactor = 3;
1300        pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor = 3;
1301
1302        DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetHT : RxBAWinLimit = %d\n", pAd->CommonCfg.BACapability.field.RxBAWinLimit));
1303
1304        // Mimo power save, A-MSDU size,
1305        pAd->CommonCfg.DesiredHtPhy.AmsduEnable = (USHORT)pAd->CommonCfg.BACapability.field.AmsduEnable;
1306        pAd->CommonCfg.DesiredHtPhy.AmsduSize = (UCHAR)pAd->CommonCfg.BACapability.field.AmsduSize;
1307        pAd->CommonCfg.DesiredHtPhy.MimoPs = (UCHAR)pAd->CommonCfg.BACapability.field.MMPSmode;
1308        pAd->CommonCfg.DesiredHtPhy.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
1309
1310        pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = (USHORT)pAd->CommonCfg.BACapability.field.AmsduSize;
1311        pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = (USHORT)pAd->CommonCfg.BACapability.field.MMPSmode;
1312        pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = (UCHAR)pAd->CommonCfg.BACapability.field.MpduDensity;
1313
1314        DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetHT : AMsduSize = %d, MimoPs = %d, MpduDensity = %d, MaxRAmpduFactor = %d\n",
1315                                                                                                        pAd->CommonCfg.DesiredHtPhy.AmsduSize,
1316                                                                                                        pAd->CommonCfg.DesiredHtPhy.MimoPs,
1317                                                                                                        pAd->CommonCfg.DesiredHtPhy.MpduDensity,
1318                                                                                                        pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor));
1319
1320        if(pHTPhyMode->HtMode == HTMODE_GF)
1321        {
1322                pAd->CommonCfg.HtCapability.HtCapInfo.GF = 1;
1323                pAd->CommonCfg.DesiredHtPhy.GF = 1;
1324        }
1325        else
1326                pAd->CommonCfg.DesiredHtPhy.GF = 0;
1327
1328        // Decide Rx MCSSet
1329        switch (RxStream)
1330        {
1331                case 1:
1332                        pAd->CommonCfg.HtCapability.MCSSet[0] =  0xff;
1333                        pAd->CommonCfg.HtCapability.MCSSet[1] =  0x00;
1334                        break;
1335
1336                case 2:
1337                        pAd->CommonCfg.HtCapability.MCSSet[0] =  0xff;
1338                        pAd->CommonCfg.HtCapability.MCSSet[1] =  0xff;
1339                        break;
1340
1341                case 3: // 3*3
1342                        pAd->CommonCfg.HtCapability.MCSSet[0] =  0xff;
1343                        pAd->CommonCfg.HtCapability.MCSSet[1] =  0xff;
1344                        pAd->CommonCfg.HtCapability.MCSSet[2] =  0xff;
1345                        break;
1346        }
1347
1348        if (pAd->CommonCfg.bForty_Mhz_Intolerant && (pAd->CommonCfg.Channel <= 14) && (pHTPhyMode->BW == BW_40) )
1349        {
1350                pHTPhyMode->BW = BW_20;
1351                pAd->CommonCfg.HtCapability.HtCapInfo.Forty_Mhz_Intolerant = 1;
1352        }
1353
1354        if(pHTPhyMode->BW == BW_40)
1355        {
1356                pAd->CommonCfg.HtCapability.MCSSet[4] = 0x1; // MCS 32
1357                pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 1;
1358                if (pAd->CommonCfg.Channel <= 14)
1359                        pAd->CommonCfg.HtCapability.HtCapInfo.CCKmodein40 = 1;
1360
1361                pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 1;
1362                pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 1;
1363                pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset = (pHTPhyMode->ExtOffset == EXTCHA_BELOW)? (EXTCHA_BELOW): EXTCHA_ABOVE;
1364                // Set Regsiter for extension channel position.
1365                RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value);
1366                RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBP3Value);
1367                if ((pHTPhyMode->ExtOffset == EXTCHA_BELOW))
1368                {
1369                        Value |= 0x1;
1370                        BBP3Value |= (0x20);
1371                        RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
1372                }
1373                else if ((pHTPhyMode->ExtOffset == EXTCHA_ABOVE))
1374                {
1375                        Value &= 0xfe;
1376                        BBP3Value &= (~0x20);
1377                        RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value);
1378                }
1379
1380                // Turn on BBP 40MHz mode now only as AP .
1381                // Sta can turn on BBP 40MHz after connection with 40MHz AP. Sta only broadcast 40MHz capability before connection.
1382                if ((pAd->OpMode == OPMODE_AP) || INFRA_ON(pAd) || ADHOC_ON(pAd)
1383                        )
1384                {
1385                        RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
1386                        BBPValue &= (~0x18);
1387                        BBPValue |= 0x10;
1388                        RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
1389
1390                        RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBP3Value);
1391                        pAd->CommonCfg.BBPCurrentBW = BW_40;
1392                }
1393        }
1394        else
1395        {
1396                pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 0;
1397                pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 0;
1398                pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 0;
1399                pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset = EXTCHA_NONE;
1400                pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel;
1401                // Turn on BBP 20MHz mode by request here.
1402                {
1403                        RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue);
1404                        BBPValue &= (~0x18);
1405                        RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue);
1406                        pAd->CommonCfg.BBPCurrentBW = BW_20;
1407                }
1408        }
1409
1410        if(pHTPhyMode->STBC == STBC_USE)
1411        {
1412                pAd->CommonCfg.HtCapability.HtCapInfo.TxSTBC = 1;
1413                pAd->CommonCfg.DesiredHtPhy.TxSTBC = 1;
1414                pAd->CommonCfg.HtCapability.HtCapInfo.RxSTBC = 1;
1415                pAd->CommonCfg.DesiredHtPhy.RxSTBC = 1;
1416        }
1417        else
1418        {
1419                pAd->CommonCfg.DesiredHtPhy.TxSTBC = 0;
1420                pAd->CommonCfg.DesiredHtPhy.RxSTBC = 0;
1421        }
1422
1423        if(pHTPhyMode->SHORTGI == GI_400)
1424        {
1425                pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 1;
1426                pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 1;
1427                pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 1;
1428                pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 1;
1429        }
1430        else
1431        {
1432                pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 0;
1433                pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 0;
1434                pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 0;
1435                pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 0;
1436        }
1437
1438        // We support link adaptation for unsolicit MCS feedback, set to 2.
1439        pAd->CommonCfg.HtCapability.ExtHtCapInfo.MCSFeedback = MCSFBK_NONE; //MCSFBK_UNSOLICIT;
1440        pAd->CommonCfg.AddHTInfo.ControlChan = pAd->CommonCfg.Channel;
1441        // 1, the extension channel above the control channel.
1442
1443        // EDCA parameters used for AP's own transmission
1444        if (pAd->CommonCfg.APEdcaParm.bValid == FALSE)
1445        {
1446                pAd->CommonCfg.APEdcaParm.bValid = TRUE;
1447                pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3;
1448                pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7;
1449                pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1;
1450                pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1;
1451
1452                pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4;
1453                pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4;
1454                pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3;
1455                pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2;
1456
1457                pAd->CommonCfg.APEdcaParm.Cwmax[0] = 6;
1458                pAd->CommonCfg.APEdcaParm.Cwmax[1] = 10;
1459                pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4;
1460                pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3;
1461
1462                pAd->CommonCfg.APEdcaParm.Txop[0]  = 0;
1463                pAd->CommonCfg.APEdcaParm.Txop[1]  = 0;
1464                pAd->CommonCfg.APEdcaParm.Txop[2]  = 94;
1465                pAd->CommonCfg.APEdcaParm.Txop[3]  = 47;
1466        }
1467        AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm);
1468
1469        RTMPSetIndividualHT(pAd, 0);
1470}
1471
1472/*
1473        ========================================================================
1474        Routine Description:
1475                Caller ensures we has 802.11n support.
1476                Calls at setting HT from AP/STASetinformation
1477
1478        Arguments:
1479                pAd - Pointer to our adapter
1480                phymode  -
1481
1482        ========================================================================
1483*/
1484VOID    RTMPSetIndividualHT(
1485        IN      PRTMP_ADAPTER           pAd,
1486        IN      UCHAR                           apidx)
1487{
1488        PRT_HT_PHY_INFO         pDesired_ht_phy = NULL;
1489        UCHAR   TxStream = pAd->CommonCfg.TxStream;
1490        UCHAR   DesiredMcs      = MCS_AUTO;
1491
1492        do
1493        {
1494                {
1495                        pDesired_ht_phy = &pAd->StaCfg.DesiredHtPhyInfo;
1496                        DesiredMcs = pAd->StaCfg.DesiredTransmitSetting.field.MCS;
1497                        //pAd->StaCfg.bAutoTxRateSwitch = (DesiredMcs == MCS_AUTO) ? TRUE : FALSE;
1498                                break;
1499                }
1500        } while (FALSE);
1501
1502        if (pDesired_ht_phy == NULL)
1503        {
1504                DBGPRINT(RT_DEBUG_ERROR, ("RTMPSetIndividualHT: invalid apidx(%d)\n", apidx));
1505                return;
1506        }
1507        RTMPZeroMemory(pDesired_ht_phy, sizeof(RT_HT_PHY_INFO));
1508
1509        DBGPRINT(RT_DEBUG_TRACE, ("RTMPSetIndividualHT : Desired MCS = %d\n", DesiredMcs));
1510        // Check the validity of MCS
1511        if ((TxStream == 1) && ((DesiredMcs >= MCS_8) && (DesiredMcs <= MCS_15)))
1512        {
1513                DBGPRINT(RT_DEBUG_WARN, ("RTMPSetIndividualHT: MCS(%d) is invalid in 1S, reset it as MCS_7\n", DesiredMcs));
1514                DesiredMcs = MCS_7;
1515        }
1516
1517        if ((pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_20) && (DesiredMcs == MCS_32))
1518        {
1519                DBGPRINT(RT_DEBUG_WARN, ("RTMPSetIndividualHT: MCS_32 is only supported in 40-MHz, reset it as MCS_0\n"));
1520                DesiredMcs = MCS_0;
1521        }
1522
1523        pDesired_ht_phy->bHtEnable = TRUE;
1524
1525        // Decide desired Tx MCS
1526        switch (TxStream)
1527        {
1528                case 1:
1529                        if (DesiredMcs == MCS_AUTO)
1530                        {
1531                                pDesired_ht_phy->MCSSet[0]= 0xff;
1532                                pDesired_ht_phy->MCSSet[1]= 0x00;
1533                        }
1534                        else if (DesiredMcs <= MCS_7)
1535                        {
1536                                pDesired_ht_phy->MCSSet[0]= 1<<DesiredMcs;
1537                                pDesired_ht_phy->MCSSet[1]= 0x00;
1538                        }
1539                        break;
1540
1541                case 2:
1542                        if (DesiredMcs == MCS_AUTO)
1543                        {
1544                                pDesired_ht_phy->MCSSet[0]= 0xff;
1545                                pDesired_ht_phy->MCSSet[1]= 0xff;
1546                        }
1547                        else if (DesiredMcs <= MCS_15)
1548                        {
1549                                ULONG mode;
1550
1551                                mode = DesiredMcs / 8;
1552                                if (mode < 2)
1553                                        pDesired_ht_phy->MCSSet[mode] = (1 << (DesiredMcs - mode * 8));
1554                        }
1555                        break;
1556
1557                case 3: // 3*3
1558                        if (DesiredMcs == MCS_AUTO)
1559                        {
1560                                /* MCS0 ~ MCS23, 3 bytes */
1561                                pDesired_ht_phy->MCSSet[0]= 0xff;
1562                                pDesired_ht_phy->MCSSet[1]= 0xff;
1563                                pDesired_ht_phy->MCSSet[2]= 0xff;
1564                        }
1565                        else if (DesiredMcs <= MCS_23)
1566                        {
1567                                ULONG mode;
1568
1569                                mode = DesiredMcs / 8;
1570                                if (mode < 3)
1571                                        pDesired_ht_phy->MCSSet[mode] = (1 << (DesiredMcs - mode * 8));
1572                        }
1573                        break;
1574        }
1575
1576        if(pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_40)
1577        {
1578                if (DesiredMcs == MCS_AUTO || DesiredMcs == MCS_32)
1579                        pDesired_ht_phy->MCSSet[4] = 0x1;
1580        }
1581
1582        // update HT Rate setting
1583    if (pAd->OpMode == OPMODE_STA)
1584        MlmeUpdateHtTxRates(pAd, BSS0);
1585    else
1586            MlmeUpdateHtTxRates(pAd, apidx);
1587}
1588
1589
1590/*
1591        ========================================================================
1592        Routine Description:
1593                Update HT IE from our capability.
1594
1595        Arguments:
1596                Send all HT IE in beacon/probe rsp/assoc rsp/action frame.
1597
1598
1599        ========================================================================
1600*/
1601VOID    RTMPUpdateHTIE(
1602        IN      RT_HT_CAPABILITY        *pRtHt,
1603        IN              UCHAR                           *pMcsSet,
1604        OUT             HT_CAPABILITY_IE *pHtCapability,
1605        OUT             ADD_HT_INFO_IE          *pAddHtInfo)
1606{
1607        RTMPZeroMemory(pHtCapability, sizeof(HT_CAPABILITY_IE));
1608        RTMPZeroMemory(pAddHtInfo, sizeof(ADD_HT_INFO_IE));
1609
1610                pHtCapability->HtCapInfo.ChannelWidth = pRtHt->ChannelWidth;
1611                pHtCapability->HtCapInfo.MimoPs = pRtHt->MimoPs;
1612                pHtCapability->HtCapInfo.GF = pRtHt->GF;
1613                pHtCapability->HtCapInfo.ShortGIfor20 = pRtHt->ShortGIfor20;
1614                pHtCapability->HtCapInfo.ShortGIfor40 = pRtHt->ShortGIfor40;
1615                pHtCapability->HtCapInfo.TxSTBC = pRtHt->TxSTBC;
1616                pHtCapability->HtCapInfo.RxSTBC = pRtHt->RxSTBC;
1617                pHtCapability->HtCapInfo.AMsduSize = pRtHt->AmsduSize;
1618                pHtCapability->HtCapParm.MaxRAmpduFactor = pRtHt->MaxRAmpduFactor;
1619                pHtCapability->HtCapParm.MpduDensity = pRtHt->MpduDensity;
1620
1621                pAddHtInfo->AddHtInfo.ExtChanOffset = pRtHt->ExtChanOffset ;
1622                pAddHtInfo->AddHtInfo.RecomWidth = pRtHt->RecomWidth;
1623                pAddHtInfo->AddHtInfo2.OperaionMode = pRtHt->OperaionMode;
1624                pAddHtInfo->AddHtInfo2.NonGfPresent = pRtHt->NonGfPresent;
1625                RTMPMoveMemory(pAddHtInfo->MCSSet, /*pRtHt->MCSSet*/pMcsSet, 4); // rt2860 only support MCS max=32, no need to copy all 16 uchar.
1626
1627        DBGPRINT(RT_DEBUG_TRACE,("RTMPUpdateHTIE <== \n"));
1628}
1629
1630/*
1631        ========================================================================
1632        Description:
1633                Add Client security information into ASIC WCID table and IVEIV table.
1634    Return:
1635        ========================================================================
1636*/
1637VOID    RTMPAddWcidAttributeEntry(
1638        IN      PRTMP_ADAPTER   pAd,
1639        IN      UCHAR                   BssIdx,
1640        IN      UCHAR                   KeyIdx,
1641        IN      UCHAR                   CipherAlg,
1642        IN      MAC_TABLE_ENTRY *pEntry)
1643{
1644        UINT32          WCIDAttri = 0;
1645        USHORT          offset;
1646        UCHAR           IVEIV = 0;
1647        USHORT          Wcid = 0;
1648
1649        {
1650                {
1651                        if (BssIdx > BSS0)
1652                        {
1653                                DBGPRINT(RT_DEBUG_ERROR, ("RTMPAddWcidAttributeEntry: The BSS-index(%d) is out of range for Infra link. \n", BssIdx));
1654                                return;
1655                        }
1656
1657                        // 1.   In ADHOC mode, the AID is wcid number. And NO mesh link exists.
1658                        // 2.   In Infra mode, the AID:1 MUST be wcid of infra STA.
1659                        //                                         the AID:2~ assign to mesh link entry.
1660                        if (pEntry && ADHOC_ON(pAd))
1661                                Wcid = pEntry->Aid;
1662                        else if (pEntry && INFRA_ON(pAd))
1663                        {
1664                                Wcid = BSSID_WCID;
1665                        }
1666                        else
1667                                Wcid = MCAST_WCID;
1668                }
1669        }
1670
1671        // Update WCID attribute table
1672        offset = MAC_WCID_ATTRIBUTE_BASE + (Wcid * HW_WCID_ATTRI_SIZE);
1673
1674        {
1675                if (pEntry && pEntry->ValidAsMesh)
1676                        WCIDAttri = (CipherAlg<<1) | PAIRWISEKEYTABLE;
1677                else
1678                        WCIDAttri = (CipherAlg<<1) | SHAREDKEYTABLE;
1679        }
1680
1681        RTMP_IO_WRITE32(pAd, offset, WCIDAttri);
1682
1683
1684        // Update IV/EIV table
1685        offset = MAC_IVEIV_TABLE_BASE + (Wcid * HW_IVEIV_ENTRY_SIZE);
1686
1687        // WPA mode
1688        if ((CipherAlg == CIPHER_TKIP) || (CipherAlg == CIPHER_TKIP_NO_MIC) || (CipherAlg == CIPHER_AES))
1689        {
1690                // Eiv bit on. keyid always is 0 for pairwise key
1691                IVEIV = (KeyIdx <<6) | 0x20;
1692        }
1693        else
1694        {
1695                // WEP KeyIdx is default tx key.
1696                IVEIV = (KeyIdx << 6);
1697        }
1698
1699        // For key index and ext IV bit, so only need to update the position(offset+3).
1700#ifdef RT2860
1701        RTMP_IO_WRITE8(pAd, offset+3, IVEIV);
1702#endif
1703#ifdef RT2870
1704        RTUSBMultiWrite_OneByte(pAd, offset+3, &IVEIV);
1705#endif // RT2870 //
1706
1707        DBGPRINT(RT_DEBUG_TRACE,("RTMPAddWcidAttributeEntry: WCID #%d, KeyIndex #%d, Alg=%s\n",Wcid, KeyIdx, CipherName[CipherAlg]));
1708        DBGPRINT(RT_DEBUG_TRACE,("      WCIDAttri = 0x%x \n",  WCIDAttri));
1709
1710}
1711
1712/*
1713    ==========================================================================
1714    Description:
1715        Parse encryption type
1716Arguments:
1717    pAdapter                    Pointer to our adapter
1718    wrq                         Pointer to the ioctl argument
1719
1720    Return Value:
1721        None
1722
1723    Note:
1724    ==========================================================================
1725*/
1726CHAR *GetEncryptType(CHAR enc)
1727{
1728    if(enc == Ndis802_11WEPDisabled)
1729        return "NONE";
1730    if(enc == Ndis802_11WEPEnabled)
1731        return "WEP";
1732    if(enc == Ndis802_11Encryption2Enabled)
1733        return "TKIP";
1734    if(enc == Ndis802_11Encryption3Enabled)
1735        return "AES";
1736        if(enc == Ndis802_11Encryption4Enabled)
1737        return "TKIPAES";
1738    else
1739        return "UNKNOW";
1740}
1741
1742CHAR *GetAuthMode(CHAR auth)
1743{
1744    if(auth == Ndis802_11AuthModeOpen)
1745        return "OPEN";
1746    if(auth == Ndis802_11AuthModeShared)
1747        return "SHARED";
1748        if(auth == Ndis802_11AuthModeAutoSwitch)
1749        return "AUTOWEP";
1750    if(auth == Ndis802_11AuthModeWPA)
1751        return "WPA";
1752    if(auth == Ndis802_11AuthModeWPAPSK)
1753        return "WPAPSK";
1754    if(auth == Ndis802_11AuthModeWPANone)
1755        return "WPANONE";
1756    if(auth == Ndis802_11AuthModeWPA2)
1757        return "WPA2";
1758    if(auth == Ndis802_11AuthModeWPA2PSK)
1759        return "WPA2PSK";
1760        if(auth == Ndis802_11AuthModeWPA1WPA2)
1761        return "WPA1WPA2";
1762        if(auth == Ndis802_11AuthModeWPA1PSKWPA2PSK)
1763        return "WPA1PSKWPA2PSK";
1764
1765        return "UNKNOW";
1766}
1767
1768/*
1769    ==========================================================================
1770    Description:
1771        Get site survey results
1772        Arguments:
1773            pAdapter                    Pointer to our adapter
1774            wrq                         Pointer to the ioctl argument
1775
1776    Return Value:
1777        None
1778
1779    Note:
1780        Usage:
1781                        1.) UI needs to wait 4 seconds after issue a site survey command
1782                        2.) iwpriv ra0 get_site_survey
1783                        3.) UI needs to prepare at least 4096bytes to get the results
1784    ==========================================================================
1785*/
1786#define LINE_LEN        (4+33+20+8+10+9+7+3)    // Channel+SSID+Bssid+WepStatus+AuthMode+Signal+WiressMode+NetworkType
1787VOID RTMPIoctlGetSiteSurvey(
1788        IN      PRTMP_ADAPTER   pAdapter,
1789        IN      struct iwreq    *wrq)
1790{
1791        CHAR            *msg;
1792        INT             i=0;
1793        INT                     WaitCnt;
1794        INT             Status=0;
1795        CHAR            Ssid[MAX_LEN_OF_SSID +1];
1796    INT         Rssi = 0, max_len = LINE_LEN;
1797        UINT        Rssi_Quality = 0;
1798        NDIS_802_11_NETWORK_TYPE    wireless_mode;
1799
1800        os_alloc_mem(NULL, (PUCHAR *)&msg, sizeof(CHAR)*((MAX_LEN_OF_BSS_TABLE)*max_len));
1801
1802        if (msg == NULL)
1803        {
1804                DBGPRINT(RT_DEBUG_TRACE, ("RTMPIoctlGetSiteSurvey - msg memory alloc fail.\n"));
1805                return;
1806        }
1807
1808        memset(msg, 0 ,(MAX_LEN_OF_BSS_TABLE)*max_len );
1809        memset(Ssid, 0 ,(MAX_LEN_OF_SSID +1));
1810        sprintf(msg,"%s","\n");
1811        sprintf(msg+strlen(msg),"%-4s%-33s%-20s%-8s%-10s%-9s%-7s%-3s\n",
1812            "Ch", "SSID", "BSSID", "Enc", "Auth", "Siganl(%)", "W-Mode", " NT");
1813
1814        WaitCnt = 0;
1815        pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE;
1816
1817        while ((ScanRunning(pAdapter) == TRUE) && (WaitCnt++ < 200))
1818                OS_WAIT(500);
1819
1820        for(i=0; i<pAdapter->ScanTab.BssNr ;i++)
1821        {
1822                if( pAdapter->ScanTab.BssEntry[i].Channel==0)
1823                        break;
1824
1825                if((strlen(msg)+max_len ) >= IW_SCAN_MAX_DATA)
1826                        break;
1827
1828                //Channel
1829                sprintf(msg+strlen(msg),"%-4d", pAdapter->ScanTab.BssEntry[i].Channel);
1830                //SSID
1831                memcpy(Ssid, pAdapter->ScanTab.BssEntry[i].Ssid, pAdapter->ScanTab.BssEntry[i].SsidLen);
1832                Ssid[pAdapter->ScanTab.BssEntry[i].SsidLen] = '\0';
1833                sprintf(msg+strlen(msg),"%-33s", Ssid);
1834                //BSSID
1835                sprintf(msg+strlen(msg),"%02x:%02x:%02x:%02x:%02x:%02x   ",
1836                        pAdapter->ScanTab.BssEntry[i].Bssid[0],
1837                        pAdapter->ScanTab.BssEntry[i].Bssid[1],
1838                        pAdapter->ScanTab.BssEntry[i].Bssid[2],
1839                        pAdapter->ScanTab.BssEntry[i].Bssid[3],
1840                        pAdapter->ScanTab.BssEntry[i].Bssid[4],
1841                        pAdapter->ScanTab.BssEntry[i].Bssid[5]);
1842                //Encryption Type
1843                sprintf(msg+strlen(msg),"%-8s",GetEncryptType(pAdapter->ScanTab.BssEntry[i].WepStatus));
1844                //Authentication Mode
1845                if (pAdapter->ScanTab.BssEntry[i].WepStatus == Ndis802_11WEPEnabled)
1846                        sprintf(msg+strlen(msg),"%-10s", "UNKNOW");
1847                else
1848                        sprintf(msg+strlen(msg),"%-10s",GetAuthMode(pAdapter->ScanTab.BssEntry[i].AuthMode));
1849                // Rssi
1850                Rssi = (INT)pAdapter->ScanTab.BssEntry[i].Rssi;
1851                if (Rssi >= -50)
1852                        Rssi_Quality = 100;
1853                else if (Rssi >= -80)    // between -50 ~ -80dbm
1854                        Rssi_Quality = (UINT)(24 + ((Rssi + 80) * 26)/10);
1855                else if (Rssi >= -90)   // between -80 ~ -90dbm
1856                        Rssi_Quality = (UINT)(((Rssi + 90) * 26)/10);
1857                else    // < -84 dbm
1858                        Rssi_Quality = 0;
1859                sprintf(msg+strlen(msg),"%-9d", Rssi_Quality);
1860                // Wireless Mode
1861                wireless_mode = NetworkTypeInUseSanity(&pAdapter->ScanTab.BssEntry[i]);
1862                if (wireless_mode == Ndis802_11FH ||
1863                        wireless_mode == Ndis802_11DS)
1864                        sprintf(msg+strlen(msg),"%-7s", "11b");
1865                else if (wireless_mode == Ndis802_11OFDM5)
1866                        sprintf(msg+strlen(msg),"%-7s", "11a");
1867                else if (wireless_mode == Ndis802_11OFDM5_N)
1868                        sprintf(msg+strlen(msg),"%-7s", "11a/n");
1869                else if (wireless_mode == Ndis802_11OFDM24)
1870                        sprintf(msg+strlen(msg),"%-7s", "11b/g");
1871                else if (wireless_mode == Ndis802_11OFDM24_N)
1872                        sprintf(msg+strlen(msg),"%-7s", "11b/g/n");
1873                else
1874                        sprintf(msg+strlen(msg),"%-7s", "unknow");
1875                //Network Type
1876                if (pAdapter->ScanTab.BssEntry[i].BssType == BSS_ADHOC)
1877                        sprintf(msg+strlen(msg),"%-3s", " Ad");
1878                else
1879                        sprintf(msg+strlen(msg),"%-3s", " In");
1880
1881        sprintf(msg+strlen(msg),"\n");
1882        }
1883
1884        pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE;
1885        wrq->u.data.length = strlen(msg);
1886        Status = copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length);
1887
1888        DBGPRINT(RT_DEBUG_TRACE, ("RTMPIoctlGetSiteSurvey - wrq->u.data.length = %d\n", wrq->u.data.length));
1889        os_free_mem(NULL, (PUCHAR)msg);
1890}
1891
1892
1893#define MAC_LINE_LEN    (14+4+4+10+10+10+6+6)   // Addr+aid+psm+datatime+rxbyte+txbyte+current tx rate+last tx rate
1894VOID RTMPIoctlGetMacTable(
1895        IN PRTMP_ADAPTER pAd,
1896        IN struct iwreq *wrq)
1897{
1898        INT i;
1899        RT_802_11_MAC_TABLE MacTab;
1900        char *msg;
1901
1902        MacTab.Num = 0;
1903        for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
1904        {
1905                if (pAd->MacTab.Content[i].ValidAsCLI && (pAd->MacTab.Content[i].Sst == SST_ASSOC))
1906                {
1907                        COPY_MAC_ADDR(MacTab.Entry[MacTab.Num].Addr, &pAd->MacTab.Content[i].Addr);
1908                        MacTab.Entry[MacTab.Num].Aid = (UCHAR)pAd->MacTab.Content[i].Aid;
1909                        MacTab.Entry[MacTab.Num].Psm = pAd->MacTab.Content[i].PsMode;
1910                        MacTab.Entry[MacTab.Num].MimoPs = pAd->MacTab.Content[i].MmpsMode;
1911
1912                        // Fill in RSSI per entry
1913                        MacTab.Entry[MacTab.Num].AvgRssi0 = pAd->MacTab.Content[i].RssiSample.AvgRssi0;
1914                        MacTab.Entry[MacTab.Num].AvgRssi1 = pAd->MacTab.Content[i].RssiSample.AvgRssi1;
1915                        MacTab.Entry[MacTab.Num].AvgRssi2 = pAd->MacTab.Content[i].RssiSample.AvgRssi2;
1916
1917                        // the connected time per entry
1918                        MacTab.Entry[MacTab.Num].ConnectedTime = pAd->MacTab.Content[i].StaConnectTime;
1919                        MacTab.Entry[MacTab.Num].TxRate.field.MCS = pAd->MacTab.Content[i].HTPhyMode.field.MCS;
1920                        MacTab.Entry[MacTab.Num].TxRate.field.BW = pAd->MacTab.Content[i].HTPhyMode.field.BW;
1921                        MacTab.Entry[MacTab.Num].TxRate.field.ShortGI = pAd->MacTab.Content[i].HTPhyMode.field.ShortGI;
1922                        MacTab.Entry[MacTab.Num].TxRate.field.STBC = pAd->MacTab.Content[i].HTPhyMode.field.STBC;
1923                        MacTab.Entry[MacTab.Num].TxRate.field.rsv = pAd->MacTab.Content[i].HTPhyMode.field.rsv;
1924                        MacTab.Entry[MacTab.Num].TxRate.field.MODE = pAd->MacTab.Content[i].HTPhyMode.field.MODE;
1925                        MacTab.Entry[MacTab.Num].TxRate.word = pAd->MacTab.Content[i].HTPhyMode.word;
1926
1927                        MacTab.Num += 1;
1928                }
1929        }
1930        wrq->u.data.length = sizeof(RT_802_11_MAC_TABLE);
1931        if (copy_to_user(wrq->u.data.pointer, &MacTab, wrq->u.data.length))
1932        {
1933                DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __func__));
1934        }
1935
1936        msg = (CHAR *) kmalloc(sizeof(CHAR)*(MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN), MEM_ALLOC_FLAG);
1937        memset(msg, 0 ,MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN );
1938        sprintf(msg,"%s","\n");
1939        sprintf(msg+strlen(msg),"%-14s%-4s%-4s%-10s%-10s%-10s%-6s%-6s\n",
1940                "MAC", "AID", "PSM", "LDT", "RxB", "TxB","CTxR", "LTxR");
1941
1942        for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
1943        {
1944                PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
1945                if (pEntry->ValidAsCLI && (pEntry->Sst == SST_ASSOC))
1946                {
1947                        if((strlen(msg)+MAC_LINE_LEN ) >= (MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN) )
1948                                break;
1949                        sprintf(msg+strlen(msg),"%02x%02x%02x%02x%02x%02x  ",
1950                                pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
1951                                pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
1952                        sprintf(msg+strlen(msg),"%-4d", (int)pEntry->Aid);
1953                        sprintf(msg+strlen(msg),"%-4d", (int)pEntry->PsMode);
1954                        sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.LastDataPacketTime*/); // ToDo
1955                        sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.TotalRxByteCount*/); // ToDo
1956                        sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.TotalTxByteCount*/); // ToDo
1957                        sprintf(msg+strlen(msg),"%-6d",RateIdToMbps[pAd->MacTab.Content[i].CurrTxRate]);
1958                        sprintf(msg+strlen(msg),"%-6d\n",0/*RateIdToMbps[pAd->MacTab.Content[i].LastTxRate]*/); // ToDo
1959                }
1960        }
1961        // for compatible with old API just do the printk to console
1962        //wrq->u.data.length = strlen(msg);
1963        //if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length))
1964        {
1965                DBGPRINT(RT_DEBUG_TRACE, ("%s", msg));
1966        }
1967
1968        kfree(msg);
1969}
1970
1971INT     Set_BASetup_Proc(
1972        IN      PRTMP_ADAPTER   pAd,
1973        IN      PUCHAR                  arg)
1974{
1975    UCHAR mac[6], tid;
1976        char *token, sepValue[] = ":", DASH = '-';
1977        INT i;
1978    MAC_TABLE_ENTRY *pEntry;
1979
1980/*
1981        The BASetup inupt string format should be xx:xx:xx:xx:xx:xx-d,
1982                =>The six 2 digit hex-decimal number previous are the Mac address,
1983                =>The seventh decimal number is the tid value.
1984*/
1985
1986        if(strlen(arg) < 19)  //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.
1987                return FALSE;
1988
1989        token = strchr(arg, DASH);
1990        if ((token != NULL) && (strlen(token)>1))
1991        {
1992                tid = simple_strtol((token+1), 0, 10);
1993                if (tid > 15)
1994                        return FALSE;
1995
1996                *token = '\0';
1997                for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
1998                {
1999                        if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
2000                                return FALSE;
2001                        AtoH(token, (PUCHAR)(&mac[i]), 1);
2002                }
2003                if(i != 6)
2004                        return FALSE;
2005
2006                printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x\n", mac[0], mac[1],
2007                                mac[2], mac[3], mac[4], mac[5], tid);
2008
2009            pEntry = MacTableLookup(pAd, mac);
2010
2011        if (pEntry) {
2012                printk("\nSetup BA Session: Tid = %d\n", tid);
2013                BAOriSessionSetUp(pAd, pEntry, tid, 0, 100, TRUE);
2014        }
2015
2016                return TRUE;
2017        }
2018
2019        return FALSE;
2020
2021}
2022
2023INT     Set_BADecline_Proc(
2024        IN      PRTMP_ADAPTER   pAd,
2025        IN      PUCHAR                  arg)
2026{
2027        ULONG bBADecline;
2028
2029        bBADecline = simple_strtol(arg, 0, 10);
2030
2031        if (bBADecline == 0)
2032        {
2033                pAd->CommonCfg.bBADecline = FALSE;
2034        }
2035        else if (bBADecline == 1)
2036        {
2037                pAd->CommonCfg.bBADecline = TRUE;
2038        }
2039        else
2040        {
2041                return FALSE; //Invalid argument
2042        }
2043
2044        DBGPRINT(RT_DEBUG_TRACE, ("Set_BADecline_Proc::(BADecline=%d)\n", pAd->CommonCfg.bBADecline));
2045
2046        return TRUE;
2047}
2048
2049INT     Set_BAOriTearDown_Proc(
2050        IN      PRTMP_ADAPTER   pAd,
2051        IN      PUCHAR                  arg)
2052{
2053    UCHAR mac[6], tid;
2054        char *token, sepValue[] = ":", DASH = '-';
2055        INT i;
2056    MAC_TABLE_ENTRY *pEntry;
2057
2058/*
2059        The BAOriTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d,
2060                =>The six 2 digit hex-decimal number previous are the Mac address,
2061                =>The seventh decimal number is the tid value.
2062*/
2063    if(strlen(arg) < 19)  //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.
2064                return FALSE;
2065
2066        token = strchr(arg, DASH);
2067        if ((token != NULL) && (strlen(token)>1))
2068        {
2069                tid = simple_strtol((token+1), 0, 10);
2070                if (tid > NUM_OF_TID)
2071                        return FALSE;
2072
2073                *token = '\0';
2074                for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
2075                {
2076                        if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
2077                                return FALSE;
2078                        AtoH(token, (PUCHAR)(&mac[i]), 1);
2079                }
2080                if(i != 6)
2081                        return FALSE;
2082
2083            printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x", mac[0], mac[1],
2084                   mac[2], mac[3], mac[4], mac[5], tid);
2085
2086            pEntry = MacTableLookup(pAd, mac);
2087
2088            if (pEntry) {
2089                printk("\nTear down Ori BA Session: Tid = %d\n", tid);
2090        BAOriSessionTearDown(pAd, pEntry->Aid, tid, FALSE, TRUE);
2091            }
2092
2093                return TRUE;
2094        }
2095
2096        return FALSE;
2097
2098}
2099
2100INT     Set_BARecTearDown_Proc(
2101        IN      PRTMP_ADAPTER   pAd,
2102        IN      PUCHAR                  arg)
2103{
2104    UCHAR mac[6], tid;
2105        char *token, sepValue[] = ":", DASH = '-';
2106        INT i;
2107    MAC_TABLE_ENTRY *pEntry;
2108
2109    //printk("\n%s\n", arg);
2110/*
2111        The BARecTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d,
2112                =>The six 2 digit hex-decimal number previous are the Mac address,
2113                =>The seventh decimal number is the tid value.
2114*/
2115    if(strlen(arg) < 19)  //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.
2116                return FALSE;
2117
2118        token = strchr(arg, DASH);
2119        if ((token != NULL) && (strlen(token)>1))
2120        {
2121                tid = simple_strtol((token+1), 0, 10);
2122                if (tid > NUM_OF_TID)
2123                        return FALSE;
2124
2125                *token = '\0';
2126                for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
2127                {
2128                        if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
2129                                return FALSE;
2130                        AtoH(token, (PUCHAR)(&mac[i]), 1);
2131                }
2132                if(i != 6)
2133                        return FALSE;
2134
2135                printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x", mac[0], mac[1],
2136                       mac[2], mac[3], mac[4], mac[5], tid);
2137
2138                pEntry = MacTableLookup(pAd, mac);
2139
2140                if (pEntry) {
2141                    printk("\nTear down Rec BA Session: Tid = %d\n", tid);
2142                    BARecSessionTearDown(pAd, pEntry->Aid, tid, FALSE);
2143                }
2144
2145                return TRUE;
2146        }
2147
2148        return FALSE;
2149
2150}
2151
2152INT     Set_HtBw_Proc(
2153        IN      PRTMP_ADAPTER   pAd,
2154        IN      PUCHAR                  arg)
2155{
2156        ULONG HtBw;
2157
2158        HtBw = simple_strtol(arg, 0, 10);
2159        if (HtBw == BW_40)
2160                pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_40;
2161        else if (HtBw == BW_20)
2162                pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_20;
2163        else
2164                return FALSE;  //Invalid argument
2165
2166        SetCommonHT(pAd);
2167
2168        DBGPRINT(RT_DEBUG_TRACE, ("Set_HtBw_Proc::(HtBw=%d)\n", pAd->CommonCfg.RegTransmitSetting.field.BW));
2169
2170        return TRUE;
2171}
2172
2173INT     Set_HtMcs_Proc(
2174        IN      PRTMP_ADAPTER   pAd,
2175        IN      PUCHAR                  arg)
2176{
2177        ULONG HtMcs, Mcs_tmp;
2178    BOOLEAN bAutoRate = FALSE;
2179
2180        Mcs_tmp = simple_strtol(arg, 0, 10);
2181
2182        if (Mcs_tmp <= 15 || Mcs_tmp == 32)
2183                HtMcs = Mcs_tmp;
2184        else
2185                HtMcs = MCS_AUTO;
2186
2187        {
2188                pAd->StaCfg.DesiredTransmitSetting.field.MCS = HtMcs;
2189                pAd->StaCfg.bAutoTxRateSwitch = (HtMcs == MCS_AUTO) ? TRUE:FALSE;
2190                DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMcs_Proc::(HtMcs=%d, bAutoTxRateSwitch = %d)\n",
2191                                                pAd->StaCfg.DesiredTransmitSetting.field.MCS, pAd->StaCfg.bAutoTxRateSwitch));
2192
2193                if ((pAd->CommonCfg.PhyMode < PHY_11ABGN_MIXED) ||
2194                        (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE < MODE_HTMIX))
2195                {
2196                if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) &&
2197                                (HtMcs >= 0 && HtMcs <= 3) &&
2198                    (pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_CCK))
2199                        {
2200                                RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs] * 1000000));
2201                        }
2202                else if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) &&
2203                                        (HtMcs >= 0 && HtMcs <= 7) &&
2204                        (pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_OFDM))
2205                        {
2206                                RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs+4] * 1000000));
2207                        }
2208                        else
2209                                bAutoRate = TRUE;
2210
2211                        if (bAutoRate)
2212                        {
2213                    pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2214                                RTMPSetDesiredRates(pAd, -1);
2215                        }
2216                DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMcs_Proc::(FixedTxMode=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode));
2217                }
2218        if (ADHOC_ON(pAd))
2219            return TRUE;
2220        }
2221
2222        SetCommonHT(pAd);
2223
2224        return TRUE;
2225}
2226
2227INT     Set_HtGi_Proc(
2228        IN      PRTMP_ADAPTER   pAd,
2229        IN      PUCHAR                  arg)
2230{
2231        ULONG HtGi;
2232
2233        HtGi = simple_strtol(arg, 0, 10);
2234
2235        if ( HtGi == GI_400)
2236                pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_400;
2237        else if ( HtGi == GI_800 )
2238                pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_800;
2239        else
2240                return FALSE; //Invalid argument
2241
2242        SetCommonHT(pAd);
2243
2244        DBGPRINT(RT_DEBUG_TRACE, ("Set_HtGi_Proc::(ShortGI=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.ShortGI));
2245
2246        return TRUE;
2247}
2248
2249
2250INT     Set_HtTxBASize_Proc(
2251        IN      PRTMP_ADAPTER   pAd,
2252        IN      PUCHAR                  arg)
2253{
2254        UCHAR Size;
2255
2256        Size = simple_strtol(arg, 0, 10);
2257
2258        if (Size <=0 || Size >=64)
2259        {
2260                Size = 8;
2261        }
2262        pAd->CommonCfg.TxBASize = Size-1;
2263        DBGPRINT(RT_DEBUG_ERROR, ("Set_HtTxBASize ::(TxBASize= %d)\n", Size));
2264
2265        return TRUE;
2266}
2267
2268
2269INT     Set_HtOpMode_Proc(
2270        IN      PRTMP_ADAPTER   pAd,
2271        IN      PUCHAR                  arg)
2272{
2273
2274        ULONG Value;
2275
2276        Value = simple_strtol(arg, 0, 10);
2277
2278        if (Value == HTMODE_GF)
2279                pAd->CommonCfg.RegTransmitSetting.field.HTMODE  = HTMODE_GF;
2280        else if ( Value == HTMODE_MM )
2281                pAd->CommonCfg.RegTransmitSetting.field.HTMODE  = HTMODE_MM;
2282        else
2283                return FALSE; //Invalid argument
2284
2285        SetCommonHT(pAd);
2286
2287        DBGPRINT(RT_DEBUG_TRACE, ("Set_HtOpMode_Proc::(HtOpMode=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.HTMODE));
2288
2289        return TRUE;
2290
2291}
2292
2293INT     Set_HtStbc_Proc(
2294        IN      PRTMP_ADAPTER   pAd,
2295        IN      PUCHAR                  arg)
2296{
2297
2298        ULONG Value;
2299
2300        Value = simple_strtol(arg, 0, 10);
2301
2302        if (Value == STBC_USE)
2303                pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_USE;
2304        else if ( Value == STBC_NONE )
2305                pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_NONE;
2306        else
2307                return FALSE; //Invalid argument
2308
2309        SetCommonHT(pAd);
2310
2311        DBGPRINT(RT_DEBUG_TRACE, ("Set_Stbc_Proc::(HtStbc=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.STBC));
2312
2313        return TRUE;
2314}
2315
2316INT     Set_HtHtc_Proc(
2317        IN      PRTMP_ADAPTER   pAd,
2318        IN      PUCHAR                  arg)
2319{
2320
2321        ULONG Value;
2322
2323        Value = simple_strtol(arg, 0, 10);
2324        if (Value == 0)
2325                pAd->HTCEnable = FALSE;
2326        else if ( Value ==1 )
2327                pAd->HTCEnable = TRUE;
2328        else
2329                return FALSE; //Invalid argument
2330
2331        DBGPRINT(RT_DEBUG_TRACE, ("Set_HtHtc_Proc::(HtHtc=%d)\n",pAd->HTCEnable));
2332
2333        return TRUE;
2334}
2335
2336INT     Set_HtExtcha_Proc(
2337        IN      PRTMP_ADAPTER   pAd,
2338        IN      PUCHAR                  arg)
2339{
2340
2341        ULONG Value;
2342
2343        Value = simple_strtol(arg, 0, 10);
2344
2345        if (Value == 0)
2346                pAd->CommonCfg.RegTransmitSetting.field.EXTCHA  = EXTCHA_BELOW;
2347        else if ( Value ==1 )
2348        pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
2349        else
2350                return FALSE; //Invalid argument
2351
2352        SetCommonHT(pAd);
2353
2354        DBGPRINT(RT_DEBUG_TRACE, ("Set_HtExtcha_Proc::(HtExtcha=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.EXTCHA));
2355
2356        return TRUE;
2357}
2358
2359INT     Set_HtMpduDensity_Proc(
2360        IN      PRTMP_ADAPTER   pAd,
2361        IN      PUCHAR                  arg)
2362{
2363        ULONG Value;
2364
2365        Value = simple_strtol(arg, 0, 10);
2366
2367        if (Value <=7 && Value >= 0)
2368                pAd->CommonCfg.BACapability.field.MpduDensity = Value;
2369        else
2370                pAd->CommonCfg.BACapability.field.MpduDensity = 4;
2371
2372        SetCommonHT(pAd);
2373
2374        DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMpduDensity_Proc::(HtMpduDensity=%d)\n",pAd->CommonCfg.BACapability.field.MpduDensity));
2375
2376        return TRUE;
2377}
2378
2379INT     Set_HtBaWinSize_Proc(
2380        IN      PRTMP_ADAPTER   pAd,
2381        IN      PUCHAR                  arg)
2382{
2383        ULONG Value;
2384
2385        Value = simple_strtol(arg, 0, 10);
2386
2387
2388        if (Value >=1 && Value <= 64)
2389        {
2390                pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = Value;
2391                pAd->CommonCfg.BACapability.field.RxBAWinLimit = Value;
2392        }
2393        else
2394        {
2395        pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = 64;
2396                pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64;
2397        }
2398
2399        SetCommonHT(pAd);
2400
2401        DBGPRINT(RT_DEBUG_TRACE, ("Set_HtBaWinSize_Proc::(HtBaWinSize=%d)\n",pAd->CommonCfg.BACapability.field.RxBAWinLimit));
2402
2403        return TRUE;
2404}
2405
2406INT     Set_HtRdg_Proc(
2407        IN      PRTMP_ADAPTER   pAd,
2408        IN      PUCHAR                  arg)
2409{
2410        ULONG Value;
2411
2412        Value = simple_strtol(arg, 0, 10);
2413
2414        if (Value == 0)
2415                pAd->CommonCfg.bRdg = FALSE;
2416        else if ( Value ==1 )
2417        {
2418                pAd->HTCEnable = TRUE;
2419                pAd->CommonCfg.bRdg = TRUE;
2420        }
2421        else
2422                return FALSE; //Invalid argument
2423
2424        SetCommonHT(pAd);
2425
2426        DBGPRINT(RT_DEBUG_TRACE, ("Set_HtRdg_Proc::(HtRdg=%d)\n",pAd->CommonCfg.bRdg));
2427
2428        return TRUE;
2429}
2430
2431INT     Set_HtLinkAdapt_Proc(
2432        IN      PRTMP_ADAPTER   pAd,
2433        IN      PUCHAR                  arg)
2434{
2435        ULONG Value;
2436
2437        Value = simple_strtol(arg, 0, 10);
2438        if (Value == 0)
2439                pAd->bLinkAdapt = FALSE;
2440        else if ( Value ==1 )
2441        {
2442                        pAd->HTCEnable = TRUE;
2443                        pAd->bLinkAdapt = TRUE;
2444        }
2445        else
2446                return FALSE; //Invalid argument
2447
2448        DBGPRINT(RT_DEBUG_TRACE, ("Set_HtLinkAdapt_Proc::(HtLinkAdapt=%d)\n",pAd->bLinkAdapt));
2449
2450        return TRUE;
2451}
2452
2453INT     Set_HtAmsdu_Proc(
2454        IN      PRTMP_ADAPTER   pAd,
2455        IN      PUCHAR                  arg)
2456{
2457        ULONG Value;
2458
2459        Value = simple_strtol(arg, 0, 10);
2460        if (Value == 0)
2461                pAd->CommonCfg.BACapability.field.AmsduEnable = FALSE;
2462        else if ( Value == 1 )
2463        pAd->CommonCfg.BACapability.field.AmsduEnable = TRUE;
2464        else
2465                return FALSE; //Invalid argument
2466
2467        SetCommonHT(pAd);
2468
2469        DBGPRINT(RT_DEBUG_TRACE, ("Set_HtAmsdu_Proc::(HtAmsdu=%d)\n",pAd->CommonCfg.BACapability.field.AmsduEnable));
2470
2471        return TRUE;
2472}
2473
2474INT     Set_HtAutoBa_Proc(
2475        IN      PRTMP_ADAPTER   pAd,
2476        IN      PUCHAR                  arg)
2477{
2478        ULONG Value;
2479
2480        Value = simple_strtol(arg, 0, 10);
2481        if (Value == 0)
2482        {
2483                pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
2484                pAd->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
2485        }
2486    else if (Value == 1)
2487        {
2488                pAd->CommonCfg.BACapability.field.AutoBA = TRUE;
2489                pAd->CommonCfg.BACapability.field.Policy = IMMED_BA;
2490        }
2491        else
2492                return FALSE; //Invalid argument
2493
2494    pAd->CommonCfg.REGBACapability.field.AutoBA = pAd->CommonCfg.BACapability.field.AutoBA;
2495    pAd->CommonCfg.REGBACapability.field.Policy = pAd->CommonCfg.BACapability.field.Policy;
2496
2497        SetCommonHT(pAd);
2498
2499        DBGPRINT(RT_DEBUG_TRACE, ("Set_HtAutoBa_Proc::(HtAutoBa=%d)\n",pAd->CommonCfg.BACapability.field.AutoBA));
2500
2501        return TRUE;
2502
2503}
2504
2505INT     Set_HtProtect_Proc(
2506        IN      PRTMP_ADAPTER   pAd,
2507        IN      PUCHAR                  arg)
2508{
2509        ULONG Value;
2510
2511        Value = simple_strtol(arg, 0, 10);
2512        if (Value == 0)
2513                pAd->CommonCfg.bHTProtect = FALSE;
2514    else if (Value == 1)
2515                pAd->CommonCfg.bHTProtect = TRUE;
2516        else
2517                return FALSE; //Invalid argument
2518
2519        DBGPRINT(RT_DEBUG_TRACE, ("Set_HtProtect_Proc::(HtProtect=%d)\n",pAd->CommonCfg.bHTProtect));
2520
2521        return TRUE;
2522}
2523
2524INT     Set_SendPSMPAction_Proc(
2525        IN      PRTMP_ADAPTER   pAd,
2526        IN      PUCHAR                  arg)
2527{
2528    UCHAR mac[6], mode;
2529        char *token, sepValue[] = ":", DASH = '-';
2530        INT i;
2531    MAC_TABLE_ENTRY *pEntry;
2532
2533    //printk("\n%s\n", arg);
2534/*
2535        The BARecTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d,
2536                =>The six 2 digit hex-decimal number previous are the Mac address,
2537                =>The seventh decimal number is the mode value.
2538*/
2539    if(strlen(arg) < 19)  //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and mode value in decimal format.
2540                return FALSE;
2541
2542        token = strchr(arg, DASH);
2543        if ((token != NULL) && (strlen(token)>1))
2544        {
2545                mode = simple_strtol((token+1), 0, 10);
2546                if (mode > MMPS_ENABLE)
2547                        return FALSE;
2548
2549                *token = '\0';
2550                for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
2551                {
2552                        if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
2553                                return FALSE;
2554                        AtoH(token, (PUCHAR)(&mac[i]), 1);
2555                }
2556                if(i != 6)
2557                        return FALSE;
2558
2559                printk("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x", mac[0], mac[1],
2560                       mac[2], mac[3], mac[4], mac[5], mode);
2561
2562                pEntry = MacTableLookup(pAd, mac);
2563
2564                if (pEntry) {
2565                    printk("\nSendPSMPAction MIPS mode = %d\n", mode);
2566                    SendPSMPAction(pAd, pEntry->Aid, mode);
2567                }
2568
2569                return TRUE;
2570        }
2571
2572        return FALSE;
2573
2574
2575}
2576
2577INT     Set_HtMIMOPSmode_Proc(
2578        IN      PRTMP_ADAPTER   pAd,
2579        IN      PUCHAR                  arg)
2580{
2581        ULONG Value;
2582
2583        Value = simple_strtol(arg, 0, 10);
2584
2585        if (Value <=3 && Value >= 0)
2586                pAd->CommonCfg.BACapability.field.MMPSmode = Value;
2587        else
2588                pAd->CommonCfg.BACapability.field.MMPSmode = 3;
2589
2590        SetCommonHT(pAd);
2591
2592        DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMIMOPSmode_Proc::(MIMOPS mode=%d)\n",pAd->CommonCfg.BACapability.field.MMPSmode));
2593
2594        return TRUE;
2595}
2596
2597
2598INT     Set_ForceShortGI_Proc(
2599        IN      PRTMP_ADAPTER   pAd,
2600        IN      PUCHAR                  arg)
2601{
2602        ULONG Value;
2603
2604        Value = simple_strtol(arg, 0, 10);
2605        if (Value == 0)
2606                pAd->WIFItestbed.bShortGI = FALSE;
2607        else if (Value == 1)
2608                pAd->WIFItestbed.bShortGI = TRUE;
2609        else
2610                return FALSE; //Invalid argument
2611
2612        SetCommonHT(pAd);
2613
2614        DBGPRINT(RT_DEBUG_TRACE, ("Set_ForceShortGI_Proc::(ForceShortGI=%d)\n", pAd->WIFItestbed.bShortGI));
2615
2616        return TRUE;
2617}
2618
2619
2620
2621INT     Set_ForceGF_Proc(
2622        IN      PRTMP_ADAPTER   pAd,
2623        IN      PUCHAR                  arg)
2624{
2625        ULONG Value;
2626
2627        Value = simple_strtol(arg, 0, 10);
2628        if (Value == 0)
2629                pAd->WIFItestbed.bGreenField = FALSE;
2630        else if (Value == 1)
2631                pAd->WIFItestbed.bGreenField = TRUE;
2632        else
2633                return FALSE; //Invalid argument
2634
2635        SetCommonHT(pAd);
2636
2637        DBGPRINT(RT_DEBUG_TRACE, ("Set_ForceGF_Proc::(ForceGF=%d)\n", pAd->WIFItestbed.bGreenField));
2638
2639        return TRUE;
2640}
2641
2642INT     Set_HtMimoPs_Proc(
2643        IN      PRTMP_ADAPTER   pAd,
2644        IN      PUCHAR                  arg)
2645{
2646        ULONG Value;
2647
2648        Value = simple_strtol(arg, 0, 10);
2649        if (Value == 0)
2650                pAd->CommonCfg.bMIMOPSEnable = FALSE;
2651        else if (Value == 1)
2652                pAd->CommonCfg.bMIMOPSEnable = TRUE;
2653        else
2654                return FALSE; //Invalid argument
2655
2656        DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMimoPs_Proc::(HtMimoPs=%d)\n",pAd->CommonCfg.bMIMOPSEnable));
2657
2658        return TRUE;
2659}
2660
2661INT     SetCommonHT(
2662        IN      PRTMP_ADAPTER   pAd)
2663{
2664        OID_SET_HT_PHYMODE              SetHT;
2665
2666        if (pAd->CommonCfg.PhyMode < PHY_11ABGN_MIXED)
2667                return FALSE;
2668
2669        SetHT.PhyMode = pAd->CommonCfg.PhyMode;
2670        SetHT.TransmitNo = ((UCHAR)pAd->Antenna.field.TxPath);
2671        SetHT.HtMode = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.HTMODE;
2672        SetHT.ExtOffset = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.EXTCHA;
2673        SetHT.MCS = MCS_AUTO;
2674        SetHT.BW = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.BW;
2675        SetHT.STBC = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.STBC;
2676        SetHT.SHORTGI = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.ShortGI;
2677
2678        RTMPSetHT(pAd, &SetHT);
2679
2680        return TRUE;
2681}
2682
2683INT     Set_FixedTxMode_Proc(
2684        IN      PRTMP_ADAPTER   pAd,
2685        IN      PUCHAR                  arg)
2686{
2687        UCHAR   fix_tx_mode = FIXED_TXMODE_HT;
2688
2689        if (strcmp(arg, "OFDM") == 0 || strcmp(arg, "ofdm") == 0)
2690        {
2691                fix_tx_mode = FIXED_TXMODE_OFDM;
2692        }
2693        else if (strcmp(arg, "CCK") == 0 || strcmp(arg, "cck") == 0)
2694        {
2695        fix_tx_mode = FIXED_TXMODE_CCK;
2696        }
2697
2698        pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode = fix_tx_mode;
2699
2700        DBGPRINT(RT_DEBUG_TRACE, ("Set_FixedTxMode_Proc::(FixedTxMode=%d)\n", fix_tx_mode));
2701
2702        return TRUE;
2703}
2704
2705/////////////////////////////////////////////////////////////////////////
2706PCHAR   RTMPGetRalinkAuthModeStr(
2707    IN  NDIS_802_11_AUTHENTICATION_MODE authMode)
2708{
2709        switch(authMode)
2710        {
2711                case Ndis802_11AuthModeOpen:
2712                        return "OPEN";
2713                case Ndis802_11AuthModeWPAPSK:
2714                        return "WPAPSK";
2715                case Ndis802_11AuthModeShared:
2716                        return "SHARED";
2717                case Ndis802_11AuthModeWPA:
2718                        return "WPA";
2719                case Ndis802_11AuthModeWPA2:
2720                        return "WPA2";
2721                case Ndis802_11AuthModeWPA2PSK:
2722                        return "WPA2PSK";
2723        case Ndis802_11AuthModeWPA1PSKWPA2PSK:
2724                        return "WPAPSKWPA2PSK";
2725        case Ndis802_11AuthModeWPA1WPA2:
2726                        return "WPA1WPA2";
2727                case Ndis802_11AuthModeWPANone:
2728                        return "WPANONE";
2729                default:
2730                        return "UNKNOW";
2731        }
2732}
2733
2734PCHAR   RTMPGetRalinkEncryModeStr(
2735    IN  USHORT encryMode)
2736{
2737        switch(encryMode)
2738        {
2739#if defined(RT2860) || defined(RT30xx)
2740            default:
2741#endif
2742                case Ndis802_11WEPDisabled:
2743                        return "NONE";
2744                case Ndis802_11WEPEnabled:
2745                        return "WEP";
2746                case Ndis802_11Encryption2Enabled:
2747                        return "TKIP";
2748                case Ndis802_11Encryption3Enabled:
2749                        return "AES";
2750        case Ndis802_11Encryption4Enabled:
2751                        return "TKIPAES";
2752#if !defined(RT2860) && !defined(RT30xx)
2753                default:
2754                        return "UNKNOW";
2755#endif
2756        }
2757}
2758
2759INT RTMPShowCfgValue(
2760        IN      PRTMP_ADAPTER   pAd,
2761        IN      PUCHAR                  pName,
2762        IN      PUCHAR                  pBuf)
2763{
2764        INT     Status = 0;
2765
2766        for (PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC = RTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC++)
2767        {
2768                if (!strcmp(pName, PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name))
2769                {
2770                        if(PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->show_proc(pAd, pBuf))
2771                                Status = -EINVAL;
2772                        break;  //Exit for loop.
2773                }
2774        }
2775
2776        if(PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name == NULL)
2777        {
2778                sprintf(pBuf, "\n");
2779                for (PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC = RTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name; PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC++)
2780                        sprintf(pBuf + strlen(pBuf), "%s\n", PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name);
2781        }
2782
2783        return Status;
2784}
2785
2786INT     Show_SSID_Proc(
2787        IN      PRTMP_ADAPTER   pAd,
2788        OUT     PUCHAR                  pBuf)
2789{
2790        sprintf(pBuf, "\t%s", pAd->CommonCfg.Ssid);
2791        return 0;
2792}
2793
2794INT     Show_WirelessMode_Proc(
2795        IN      PRTMP_ADAPTER   pAd,
2796        OUT     PUCHAR                  pBuf)
2797{
2798        switch(pAd->CommonCfg.PhyMode)
2799        {
2800                case PHY_11BG_MIXED:
2801                        sprintf(pBuf, "\t11B/G");
2802                        break;
2803                case PHY_11B:
2804                        sprintf(pBuf, "\t11B");
2805                        break;
2806                case PHY_11A:
2807                        sprintf(pBuf, "\t11A");
2808                        break;
2809                case PHY_11ABG_MIXED:
2810                        sprintf(pBuf, "\t11A/B/G");
2811                        break;
2812                case PHY_11G:
2813                        sprintf(pBuf, "\t11G");
2814                        break;
2815                case PHY_11ABGN_MIXED:
2816                        sprintf(pBuf, "\t11A/B/G/N");
2817                        break;
2818                case PHY_11N_2_4G:
2819                        sprintf(pBuf, "\t11N only with 2.4G");
2820                        break;
2821                case PHY_11GN_MIXED:
2822                        sprintf(pBuf, "\t11G/N");
2823                        break;
2824                case PHY_11AN_MIXED:
2825                        sprintf(pBuf, "\t11A/N");
2826                        break;
2827                case PHY_11BGN_MIXED:
2828                        sprintf(pBuf, "\t11B/G/N");
2829                        break;
2830                case PHY_11AGN_MIXED:
2831                        sprintf(pBuf, "\t11A/G/N");
2832                        break;
2833                case PHY_11N_5G:
2834                        sprintf(pBuf, "\t11N only with 5G");
2835                        break;
2836                default:
2837                        sprintf(pBuf, "\tUnknow Value(%d)", pAd->CommonCfg.PhyMode);
2838                        break;
2839        }
2840        return 0;
2841}
2842
2843
2844INT     Show_TxBurst_Proc(
2845        IN      PRTMP_ADAPTER   pAd,
2846        OUT     PUCHAR                  pBuf)
2847{
2848        sprintf(pBuf, "\t%s", pAd->CommonCfg.bEnableTxBurst ? "TRUE":"FALSE");
2849        return 0;
2850}
2851
2852INT     Show_TxPreamble_Proc(
2853        IN      PRTMP_ADAPTER   pAd,
2854        OUT     PUCHAR                  pBuf)
2855{
2856        switch(pAd->CommonCfg.TxPreamble)
2857        {
2858                case Rt802_11PreambleShort:
2859                        sprintf(pBuf, "\tShort");
2860                        break;
2861                case Rt802_11PreambleLong:
2862                        sprintf(pBuf, "\tLong");
2863                        break;
2864                case Rt802_11PreambleAuto:
2865                        sprintf(pBuf, "\tAuto");
2866                        break;
2867                default:
2868                        sprintf(pBuf, "\tUnknow Value(%lu)", pAd->CommonCfg.TxPreamble);
2869                        break;
2870        }
2871
2872        return 0;
2873}
2874
2875INT     Show_TxPower_Proc(
2876        IN      PRTMP_ADAPTER   pAd,
2877        OUT     PUCHAR                  pBuf)
2878{
2879        sprintf(pBuf, "\t%lu", pAd->CommonCfg.TxPowerPercentage);
2880        return 0;
2881}
2882
2883INT     Show_Channel_Proc(
2884        IN      PRTMP_ADAPTER   pAd,
2885        OUT     PUCHAR                  pBuf)
2886{
2887        sprintf(pBuf, "\t%d", pAd->CommonCfg.Channel);
2888        return 0;
2889}
2890
2891INT     Show_BGProtection_Proc(
2892        IN      PRTMP_ADAPTER   pAd,
2893        OUT     PUCHAR                  pBuf)
2894{
2895        switch(pAd->CommonCfg.UseBGProtection)
2896        {
2897                case 1: //Always On
2898                        sprintf(pBuf, "\tON");
2899                        break;
2900                case 2: //Always OFF
2901                        sprintf(pBuf, "\tOFF");
2902                        break;
2903                case 0: //AUTO
2904                        sprintf(pBuf, "\tAuto");
2905                        break;
2906                default:
2907                        sprintf(pBuf, "\tUnknow Value(%lu)", pAd->CommonCfg.UseBGProtection);
2908                        break;
2909        }
2910        return 0;
2911}
2912
2913INT     Show_RTSThreshold_Proc(
2914        IN      PRTMP_ADAPTER   pAd,
2915        OUT     PUCHAR                  pBuf)
2916{
2917        sprintf(pBuf, "\t%u", pAd->CommonCfg.RtsThreshold);
2918        return 0;
2919}
2920
2921INT     Show_FragThreshold_Proc(
2922        IN      PRTMP_ADAPTER   pAd,
2923        OUT     PUCHAR                  pBuf)
2924{
2925        sprintf(pBuf, "\t%u", pAd->CommonCfg.FragmentThreshold);
2926        return 0;
2927}
2928
2929INT     Show_HtBw_Proc(
2930        IN      PRTMP_ADAPTER   pAd,
2931        OUT     PUCHAR                  pBuf)
2932{
2933        if (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)
2934        {
2935                sprintf(pBuf, "\t40 MHz");
2936        }
2937        else
2938        {
2939        sprintf(pBuf, "\t20 MHz");
2940        }
2941        return 0;
2942}
2943
2944INT     Show_HtMcs_Proc(
2945        IN      PRTMP_ADAPTER   pAd,
2946        OUT     PUCHAR                  pBuf)
2947{
2948        sprintf(pBuf, "\t%u", pAd->StaCfg.DesiredTransmitSetting.field.MCS);
2949        return 0;
2950}
2951
2952INT     Show_HtGi_Proc(
2953        IN      PRTMP_ADAPTER   pAd,
2954        OUT     PUCHAR                  pBuf)
2955{
2956        switch(pAd->CommonCfg.RegTransmitSetting.field.ShortGI)
2957        {
2958                case GI_400:
2959                        sprintf(pBuf, "\tGI_400");
2960                        break;
2961                case GI_800:
2962                        sprintf(pBuf, "\tGI_800");
2963                        break;
2964                default:
2965                        sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.ShortGI);
2966                        break;
2967        }
2968        return 0;
2969}
2970
2971INT     Show_HtOpMode_Proc(
2972        IN      PRTMP_ADAPTER   pAd,
2973        OUT     PUCHAR                  pBuf)
2974{
2975        switch(pAd->CommonCfg.RegTransmitSetting.field.HTMODE)
2976        {
2977                case HTMODE_GF:
2978                        sprintf(pBuf, "\tGF");
2979                        break;
2980                case HTMODE_MM:
2981                        sprintf(pBuf, "\tMM");
2982                        break;
2983                default:
2984                        sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.HTMODE);
2985                        break;
2986        }
2987        return 0;
2988}
2989
2990INT     Show_HtExtcha_Proc(
2991        IN      PRTMP_ADAPTER   pAd,
2992        OUT     PUCHAR                  pBuf)
2993{
2994        switch(pAd->CommonCfg.RegTransmitSetting.field.EXTCHA)
2995        {
2996                case EXTCHA_BELOW:
2997                        sprintf(pBuf, "\tBelow");
2998                        break;
2999                case EXTCHA_ABOVE:
3000                        sprintf(pBuf, "\tAbove");
3001                        break;
3002                default:
3003                        sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.EXTCHA);
3004                        break;
3005        }
3006        return 0;
3007}
3008
3009
3010INT     Show_HtMpduDensity_Proc(
3011        IN      PRTMP_ADAPTER   pAd,
3012        OUT     PUCHAR                  pBuf)
3013{
3014        sprintf(pBuf, "\t%u", pAd->CommonCfg.BACapability.field.MpduDensity);
3015        return 0;
3016}
3017
3018INT     Show_HtBaWinSize_Proc(
3019        IN      PRTMP_ADAPTER   pAd,
3020        OUT     PUCHAR                  pBuf)
3021{
3022        sprintf(pBuf, "\t%u", pAd->CommonCfg.BACapability.field.RxBAWinLimit);
3023        return 0;
3024}
3025
3026INT     Show_HtRdg_Proc(
3027        IN      PRTMP_ADAPTER   pAd,
3028        OUT     PUCHAR                  pBuf)
3029{
3030        sprintf(pBuf, "\t%s", pAd->CommonCfg.bRdg ? "TRUE":"FALSE");
3031        return 0;
3032}
3033
3034INT     Show_HtAmsdu_Proc(
3035        IN      PRTMP_ADAPTER   pAd,
3036        OUT     PUCHAR                  pBuf)
3037{
3038        sprintf(pBuf, "\t%s", pAd->CommonCfg.BACapability.field.AmsduEnable ? "TRUE":"FALSE");
3039        return 0;
3040}
3041
3042INT     Show_HtAutoBa_Proc(
3043        IN      PRTMP_ADAPTER   pAd,
3044        OUT     PUCHAR                  pBuf)
3045{
3046        sprintf(pBuf, "\t%s", pAd->CommonCfg.BACapability.field.AutoBA ? "TRUE":"FALSE");
3047        return 0;
3048}
3049
3050INT     Show_CountryRegion_Proc(
3051        IN      PRTMP_ADAPTER   pAd,
3052        OUT     PUCHAR                  pBuf)
3053{
3054        sprintf(pBuf, "\t%d", pAd->CommonCfg.CountryRegion);
3055        return 0;
3056}
3057
3058INT     Show_CountryRegionABand_Proc(
3059        IN      PRTMP_ADAPTER   pAd,
3060        OUT     PUCHAR                  pBuf)
3061{
3062        sprintf(pBuf, "\t%d", pAd->CommonCfg.CountryRegionForABand);
3063        return 0;
3064}
3065
3066INT     Show_CountryCode_Proc(
3067        IN      PRTMP_ADAPTER   pAd,
3068        OUT     PUCHAR                  pBuf)
3069{
3070        sprintf(pBuf, "\t%s", pAd->CommonCfg.CountryCode);
3071        return 0;
3072}
3073
3074#ifdef AGGREGATION_SUPPORT
3075INT     Show_PktAggregate_Proc(
3076        IN      PRTMP_ADAPTER   pAd,
3077        OUT     PUCHAR                  pBuf)
3078{
3079        sprintf(pBuf, "\t%s", pAd->CommonCfg.bAggregationCapable ? "TRUE":"FALSE");
3080        return 0;
3081}
3082#endif // AGGREGATION_SUPPORT //
3083
3084#ifdef WMM_SUPPORT
3085INT     Show_WmmCapable_Proc(
3086        IN      PRTMP_ADAPTER   pAd,
3087        OUT     PUCHAR                  pBuf)
3088{
3089        sprintf(pBuf, "\t%s", pAd->CommonCfg.bWmmCapable ? "TRUE":"FALSE");
3090
3091        return 0;
3092}
3093#endif // WMM_SUPPORT //
3094
3095INT     Show_IEEE80211H_Proc(
3096        IN      PRTMP_ADAPTER   pAd,
3097        OUT     PUCHAR                  pBuf)
3098{
3099        sprintf(pBuf, "\t%s", pAd->CommonCfg.bIEEE80211H ? "TRUE":"FALSE");
3100        return 0;
3101}
3102
3103INT     Show_NetworkType_Proc(
3104        IN      PRTMP_ADAPTER   pAd,
3105        OUT     PUCHAR                  pBuf)
3106{
3107        switch(pAd->StaCfg.BssType)
3108        {
3109                case BSS_ADHOC:
3110                        sprintf(pBuf, "\tAdhoc");
3111                        break;
3112                case BSS_INFRA:
3113                        sprintf(pBuf, "\tInfra");
3114                        break;
3115                case BSS_ANY:
3116                        sprintf(pBuf, "\tAny");
3117                        break;
3118                case BSS_MONITOR:
3119                        sprintf(pBuf, "\tMonitor");
3120                        break;
3121                default:
3122                        sprintf(pBuf, "\tUnknow Value(%d)", pAd->StaCfg.BssType);
3123                        break;
3124        }
3125        return 0;
3126}
3127
3128INT     Show_AuthMode_Proc(
3129        IN      PRTMP_ADAPTER   pAd,
3130        OUT     PUCHAR                  pBuf)
3131{
3132        NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeOpen;
3133
3134        AuthMode = pAd->StaCfg.AuthMode;
3135
3136        if ((AuthMode >= Ndis802_11AuthModeOpen) &&
3137                (AuthMode <= Ndis802_11AuthModeWPA1PSKWPA2PSK))
3138                sprintf(pBuf, "\t%s", RTMPGetRalinkAuthModeStr(AuthMode));
3139        else
3140                sprintf(pBuf, "\tUnknow Value(%d)", AuthMode);
3141
3142        return 0;
3143}
3144
3145INT     Show_EncrypType_Proc(
3146        IN      PRTMP_ADAPTER   pAd,
3147        OUT     PUCHAR                  pBuf)
3148{
3149        NDIS_802_11_WEP_STATUS  WepStatus = Ndis802_11WEPDisabled;
3150
3151        WepStatus = pAd->StaCfg.WepStatus;
3152
3153        if ((WepStatus >= Ndis802_11WEPEnabled) &&
3154                (WepStatus <= Ndis802_11Encryption4KeyAbsent))
3155                sprintf(pBuf, "\t%s", RTMPGetRalinkEncryModeStr(WepStatus));
3156        else
3157                sprintf(pBuf, "\tUnknow Value(%d)", WepStatus);
3158
3159        return 0;
3160}
3161
3162INT     Show_DefaultKeyID_Proc(
3163        IN      PRTMP_ADAPTER   pAd,
3164        OUT     PUCHAR                  pBuf)
3165{
3166        UCHAR DefaultKeyId = 0;
3167
3168        DefaultKeyId = pAd->StaCfg.DefaultKeyId;
3169
3170        sprintf(pBuf, "\t%d", DefaultKeyId);
3171
3172        return 0;
3173}
3174
3175INT     Show_WepKey_Proc(
3176        IN      PRTMP_ADAPTER   pAd,
3177        IN  INT                         KeyIdx,
3178        OUT     PUCHAR                  pBuf)
3179{
3180        UCHAR   Key[16] = {0}, KeyLength = 0;
3181        INT             index = BSS0;
3182
3183        KeyLength = pAd->SharedKey[index][KeyIdx].KeyLen;
3184        NdisMoveMemory(Key, pAd->SharedKey[index][KeyIdx].Key, KeyLength);
3185
3186        //check key string is ASCII or not
3187    if (RTMPCheckStrPrintAble(Key, KeyLength))
3188        sprintf(pBuf, "\t%s", Key);
3189    else
3190    {
3191        int idx;
3192        sprintf(pBuf, "\t");
3193        for (idx = 0; idx < KeyLength; idx++)
3194            sprintf(pBuf+strlen(pBuf), "%02X", Key[idx]);
3195    }
3196        return 0;
3197}
3198
3199INT     Show_Key1_Proc(
3200        IN      PRTMP_ADAPTER   pAd,
3201        OUT     PUCHAR                  pBuf)
3202{
3203        Show_WepKey_Proc(pAd, 0, pBuf);
3204        return 0;
3205}
3206
3207INT     Show_Key2_Proc(
3208        IN      PRTMP_ADAPTER   pAd,
3209        OUT     PUCHAR                  pBuf)
3210{
3211        Show_WepKey_Proc(pAd, 1, pBuf);
3212        return 0;
3213}
3214
3215INT     Show_Key3_Proc(
3216        IN      PRTMP_ADAPTER   pAd,
3217        OUT     PUCHAR                  pBuf)
3218{
3219        Show_WepKey_Proc(pAd, 2, pBuf);
3220        return 0;
3221}
3222
3223INT     Show_Key4_Proc(
3224        IN      PRTMP_ADAPTER   pAd,
3225        OUT     PUCHAR                  pBuf)
3226{
3227        Show_WepKey_Proc(pAd, 3, pBuf);
3228        return 0;
3229}
3230
3231INT     Show_WPAPSK_Proc(
3232        IN      PRTMP_ADAPTER   pAd,
3233        OUT     PUCHAR                  pBuf)
3234{
3235        INT     idx;
3236        UCHAR   PMK[32] = {0};
3237
3238        NdisMoveMemory(PMK, pAd->StaCfg.PMK, 32);
3239
3240    sprintf(pBuf, "\tPMK = ");
3241    for (idx = 0; idx < 32; idx++)
3242        sprintf(pBuf+strlen(pBuf), "%02X", PMK[idx]);
3243
3244        return 0;
3245}
3246
3247