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