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