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