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