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