Staging: rt28x0: remove private RTPRIV_IOCTL_GSITESURVEY ioctl
[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 #define MAC_LINE_LEN    (14+4+4+10+10+10+6+6)   // Addr+aid+psm+datatime+rxbyte+txbyte+current tx rate+last tx rate
1973 VOID RTMPIoctlGetMacTable(
1974         IN PRTMP_ADAPTER pAd,
1975         IN struct iwreq *wrq)
1976 {
1977         INT i;
1978         RT_802_11_MAC_TABLE MacTab;
1979         char *msg;
1980
1981         MacTab.Num = 0;
1982         for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
1983         {
1984                 if (pAd->MacTab.Content[i].ValidAsCLI && (pAd->MacTab.Content[i].Sst == SST_ASSOC))
1985                 {
1986                         COPY_MAC_ADDR(MacTab.Entry[MacTab.Num].Addr, &pAd->MacTab.Content[i].Addr);
1987                         MacTab.Entry[MacTab.Num].Aid = (UCHAR)pAd->MacTab.Content[i].Aid;
1988                         MacTab.Entry[MacTab.Num].Psm = pAd->MacTab.Content[i].PsMode;
1989                         MacTab.Entry[MacTab.Num].MimoPs = pAd->MacTab.Content[i].MmpsMode;
1990
1991                         // Fill in RSSI per entry
1992                         MacTab.Entry[MacTab.Num].AvgRssi0 = pAd->MacTab.Content[i].RssiSample.AvgRssi0;
1993                         MacTab.Entry[MacTab.Num].AvgRssi1 = pAd->MacTab.Content[i].RssiSample.AvgRssi1;
1994                         MacTab.Entry[MacTab.Num].AvgRssi2 = pAd->MacTab.Content[i].RssiSample.AvgRssi2;
1995
1996                         // the connected time per entry
1997                         MacTab.Entry[MacTab.Num].ConnectedTime = pAd->MacTab.Content[i].StaConnectTime;
1998                         MacTab.Entry[MacTab.Num].TxRate.field.MCS = pAd->MacTab.Content[i].HTPhyMode.field.MCS;
1999                         MacTab.Entry[MacTab.Num].TxRate.field.BW = pAd->MacTab.Content[i].HTPhyMode.field.BW;
2000                         MacTab.Entry[MacTab.Num].TxRate.field.ShortGI = pAd->MacTab.Content[i].HTPhyMode.field.ShortGI;
2001                         MacTab.Entry[MacTab.Num].TxRate.field.STBC = pAd->MacTab.Content[i].HTPhyMode.field.STBC;
2002                         MacTab.Entry[MacTab.Num].TxRate.field.rsv = pAd->MacTab.Content[i].HTPhyMode.field.rsv;
2003                         MacTab.Entry[MacTab.Num].TxRate.field.MODE = pAd->MacTab.Content[i].HTPhyMode.field.MODE;
2004                         MacTab.Entry[MacTab.Num].TxRate.word = pAd->MacTab.Content[i].HTPhyMode.word;
2005
2006                         MacTab.Num += 1;
2007                 }
2008         }
2009         wrq->u.data.length = sizeof(RT_802_11_MAC_TABLE);
2010         if (copy_to_user(wrq->u.data.pointer, &MacTab, wrq->u.data.length))
2011         {
2012                 DBGPRINT(RT_DEBUG_TRACE, ("%s: copy_to_user() fail\n", __func__));
2013         }
2014
2015         msg = kmalloc(sizeof(CHAR)*(MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN), MEM_ALLOC_FLAG);
2016         if (msg == NULL)
2017         {
2018                 DBGPRINT(RT_DEBUG_ERROR, ("%s():Alloc memory failed\n", __func__));
2019                 return;
2020         }
2021         memset(msg, 0 ,MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN );
2022         sprintf(msg,"%s","\n");
2023         sprintf(msg+strlen(msg),"%-14s%-4s%-4s%-10s%-10s%-10s%-6s%-6s\n",
2024                 "MAC", "AID", "PSM", "LDT", "RxB", "TxB","CTxR", "LTxR");
2025
2026         for (i=0; i<MAX_LEN_OF_MAC_TABLE; i++)
2027         {
2028                 PMAC_TABLE_ENTRY pEntry = &pAd->MacTab.Content[i];
2029                 if (pEntry->ValidAsCLI && (pEntry->Sst == SST_ASSOC))
2030                 {
2031                         if((strlen(msg)+MAC_LINE_LEN ) >= (MAX_LEN_OF_MAC_TABLE*MAC_LINE_LEN) )
2032                                 break;
2033                         sprintf(msg+strlen(msg),"%02x%02x%02x%02x%02x%02x  ",
2034                                 pEntry->Addr[0], pEntry->Addr[1], pEntry->Addr[2],
2035                                 pEntry->Addr[3], pEntry->Addr[4], pEntry->Addr[5]);
2036                         sprintf(msg+strlen(msg),"%-4d", (int)pEntry->Aid);
2037                         sprintf(msg+strlen(msg),"%-4d", (int)pEntry->PsMode);
2038                         sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.LastDataPacketTime*/); // ToDo
2039                         sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.TotalRxByteCount*/); // ToDo
2040                         sprintf(msg+strlen(msg),"%-10d",0/*pAd->MacTab.Content[i].HSCounter.TotalTxByteCount*/); // ToDo
2041                         sprintf(msg+strlen(msg),"%-6d",RateIdToMbps[pAd->MacTab.Content[i].CurrTxRate]);
2042                         sprintf(msg+strlen(msg),"%-6d\n",0/*RateIdToMbps[pAd->MacTab.Content[i].LastTxRate]*/); // ToDo
2043                 }
2044         }
2045         // for compatible with old API just do the printk to console
2046         //wrq->u.data.length = strlen(msg);
2047         //if (copy_to_user(wrq->u.data.pointer, msg, wrq->u.data.length))
2048         {
2049                 DBGPRINT(RT_DEBUG_TRACE, ("%s", msg));
2050         }
2051
2052         kfree(msg);
2053 }
2054
2055
2056 INT     Set_BASetup_Proc(
2057         IN      PRTMP_ADAPTER   pAd,
2058         IN      PSTRING                 arg)
2059 {
2060     UCHAR mac[6], tid;
2061         PSTRING token;
2062         STRING sepValue[] = ":", DASH = '-';
2063         INT i;
2064     MAC_TABLE_ENTRY *pEntry;
2065
2066 /*
2067         The BASetup inupt string format should be xx:xx:xx:xx:xx:xx-d,
2068                 =>The six 2 digit hex-decimal number previous are the Mac address,
2069                 =>The seventh decimal number is the tid value.
2070 */
2071         //DBGPRINT(RT_DEBUG_TRACE,("\n%s\n", arg));
2072
2073         if(strlen(arg) < 19)  //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.
2074                 return FALSE;
2075
2076         token = strchr(arg, DASH);
2077         if ((token != NULL) && (strlen(token)>1))
2078         {
2079                 tid = (UCHAR) simple_strtol((token+1), 0, 10);
2080                 if (tid > 15)
2081                         return FALSE;
2082
2083                 *token = '\0';
2084                 for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
2085                 {
2086                         if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
2087                                 return FALSE;
2088                         AtoH(token, (&mac[i]), 1);
2089                 }
2090                 if(i != 6)
2091                         return FALSE;
2092
2093                 DBGPRINT(RT_DEBUG_OFF, ("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x\n",
2094                                                                 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], tid));
2095
2096             pEntry = MacTableLookup(pAd, (PUCHAR) mac);
2097
2098         if (pEntry) {
2099                 DBGPRINT(RT_DEBUG_OFF, ("\nSetup BA Session: Tid = %d\n", tid));
2100                 BAOriSessionSetUp(pAd, pEntry, tid, 0, 100, TRUE);
2101         }
2102
2103                 return TRUE;
2104         }
2105
2106         return FALSE;
2107
2108 }
2109
2110 INT     Set_BADecline_Proc(
2111         IN      PRTMP_ADAPTER   pAd,
2112         IN      PSTRING                 arg)
2113 {
2114         ULONG bBADecline;
2115
2116         bBADecline = simple_strtol(arg, 0, 10);
2117
2118         if (bBADecline == 0)
2119         {
2120                 pAd->CommonCfg.bBADecline = FALSE;
2121         }
2122         else if (bBADecline == 1)
2123         {
2124                 pAd->CommonCfg.bBADecline = TRUE;
2125         }
2126         else
2127         {
2128                 return FALSE; //Invalid argument
2129         }
2130
2131         DBGPRINT(RT_DEBUG_TRACE, ("Set_BADecline_Proc::(BADecline=%d)\n", pAd->CommonCfg.bBADecline));
2132
2133         return TRUE;
2134 }
2135
2136 INT     Set_BAOriTearDown_Proc(
2137         IN      PRTMP_ADAPTER   pAd,
2138         IN      PSTRING                 arg)
2139 {
2140     UCHAR mac[6], tid;
2141         PSTRING token;
2142         STRING sepValue[] = ":", DASH = '-';
2143         INT i;
2144     MAC_TABLE_ENTRY *pEntry;
2145
2146     //DBGPRINT(RT_DEBUG_TRACE,("\n%s\n", arg));
2147 /*
2148         The BAOriTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d,
2149                 =>The six 2 digit hex-decimal number previous are the Mac address,
2150                 =>The seventh decimal number is the tid value.
2151 */
2152     if(strlen(arg) < 19)  //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.
2153                 return FALSE;
2154
2155         token = strchr(arg, DASH);
2156         if ((token != NULL) && (strlen(token)>1))
2157         {
2158                 tid = simple_strtol((token+1), 0, 10);
2159                 if (tid > NUM_OF_TID)
2160                         return FALSE;
2161
2162                 *token = '\0';
2163                 for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
2164                 {
2165                         if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
2166                                 return FALSE;
2167                         AtoH(token, (&mac[i]), 1);
2168                 }
2169                 if(i != 6)
2170                         return FALSE;
2171
2172             DBGPRINT(RT_DEBUG_OFF, ("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x",
2173                                                                 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], tid));
2174
2175             pEntry = MacTableLookup(pAd, (PUCHAR) mac);
2176
2177             if (pEntry) {
2178                 DBGPRINT(RT_DEBUG_OFF, ("\nTear down Ori BA Session: Tid = %d\n", tid));
2179         BAOriSessionTearDown(pAd, pEntry->Aid, tid, FALSE, TRUE);
2180             }
2181
2182                 return TRUE;
2183         }
2184
2185         return FALSE;
2186
2187 }
2188
2189 INT     Set_BARecTearDown_Proc(
2190         IN      PRTMP_ADAPTER   pAd,
2191         IN      PSTRING                 arg)
2192 {
2193     UCHAR mac[6], tid;
2194         PSTRING token;
2195         STRING sepValue[] = ":", DASH = '-';
2196         INT i;
2197     MAC_TABLE_ENTRY *pEntry;
2198
2199     //DBGPRINT(RT_DEBUG_TRACE,("\n%s\n", arg));
2200 /*
2201         The BARecTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d,
2202                 =>The six 2 digit hex-decimal number previous are the Mac address,
2203                 =>The seventh decimal number is the tid value.
2204 */
2205     if(strlen(arg) < 19)  //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and tid value in decimal format.
2206                 return FALSE;
2207
2208         token = strchr(arg, DASH);
2209         if ((token != NULL) && (strlen(token)>1))
2210         {
2211                 tid = simple_strtol((token+1), 0, 10);
2212                 if (tid > NUM_OF_TID)
2213                         return FALSE;
2214
2215                 *token = '\0';
2216                 for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
2217                 {
2218                         if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
2219                                 return FALSE;
2220                         AtoH(token, (&mac[i]), 1);
2221                 }
2222                 if(i != 6)
2223                         return FALSE;
2224
2225                 DBGPRINT(RT_DEBUG_OFF, ("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x",
2226                                                                 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], tid));
2227
2228                 pEntry = MacTableLookup(pAd, (PUCHAR) mac);
2229
2230                 if (pEntry) {
2231                     DBGPRINT(RT_DEBUG_OFF, ("\nTear down Rec BA Session: Tid = %d\n", tid));
2232                     BARecSessionTearDown(pAd, pEntry->Aid, tid, FALSE);
2233                 }
2234
2235                 return TRUE;
2236         }
2237
2238         return FALSE;
2239
2240 }
2241
2242 INT     Set_HtBw_Proc(
2243         IN      PRTMP_ADAPTER   pAd,
2244         IN      PSTRING                 arg)
2245 {
2246         ULONG HtBw;
2247
2248         HtBw = simple_strtol(arg, 0, 10);
2249         if (HtBw == BW_40)
2250                 pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_40;
2251         else if (HtBw == BW_20)
2252                 pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_20;
2253         else
2254                 return FALSE;  //Invalid argument
2255
2256         SetCommonHT(pAd);
2257
2258         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtBw_Proc::(HtBw=%d)\n", pAd->CommonCfg.RegTransmitSetting.field.BW));
2259
2260         return TRUE;
2261 }
2262
2263 INT     Set_HtMcs_Proc(
2264         IN      PRTMP_ADAPTER   pAd,
2265         IN      PSTRING                 arg)
2266 {
2267         ULONG HtMcs, Mcs_tmp;
2268     BOOLEAN bAutoRate = FALSE;
2269
2270         Mcs_tmp = simple_strtol(arg, 0, 10);
2271
2272         if (Mcs_tmp <= 15 || Mcs_tmp == 32)
2273                 HtMcs = Mcs_tmp;
2274         else
2275                 HtMcs = MCS_AUTO;
2276
2277         {
2278                 pAd->StaCfg.DesiredTransmitSetting.field.MCS = HtMcs;
2279                 pAd->StaCfg.bAutoTxRateSwitch = (HtMcs == MCS_AUTO) ? TRUE:FALSE;
2280                 DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMcs_Proc::(HtMcs=%d, bAutoTxRateSwitch = %d)\n",
2281                                                 pAd->StaCfg.DesiredTransmitSetting.field.MCS, pAd->StaCfg.bAutoTxRateSwitch));
2282
2283                 if ((pAd->CommonCfg.PhyMode < PHY_11ABGN_MIXED) ||
2284                         (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE < MODE_HTMIX))
2285                 {
2286                 if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) &&
2287                                 (HtMcs >= 0 && HtMcs <= 3) &&
2288                     (pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_CCK))
2289                         {
2290                                 RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs] * 1000000));
2291                         }
2292                 else if ((pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) &&
2293                                         (HtMcs >= 0 && HtMcs <= 7) &&
2294                         (pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode == FIXED_TXMODE_OFDM))
2295                         {
2296                                 RTMPSetDesiredRates(pAd, (LONG) (RateIdToMbps[HtMcs+4] * 1000000));
2297                         }
2298                         else
2299                                 bAutoRate = TRUE;
2300
2301                         if (bAutoRate)
2302                         {
2303                     pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
2304                                 RTMPSetDesiredRates(pAd, -1);
2305                         }
2306                 DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMcs_Proc::(FixedTxMode=%d)\n",pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode));
2307                 }
2308         if (ADHOC_ON(pAd))
2309             return TRUE;
2310         }
2311
2312         SetCommonHT(pAd);
2313
2314         return TRUE;
2315 }
2316
2317 INT     Set_HtGi_Proc(
2318         IN      PRTMP_ADAPTER   pAd,
2319         IN      PSTRING                 arg)
2320 {
2321         ULONG HtGi;
2322
2323         HtGi = simple_strtol(arg, 0, 10);
2324
2325         if ( HtGi == GI_400)
2326                 pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_400;
2327         else if ( HtGi == GI_800 )
2328                 pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_800;
2329         else
2330                 return FALSE; //Invalid argument
2331
2332         SetCommonHT(pAd);
2333
2334         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtGi_Proc::(ShortGI=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.ShortGI));
2335
2336         return TRUE;
2337 }
2338
2339
2340 INT     Set_HtTxBASize_Proc(
2341         IN      PRTMP_ADAPTER   pAd,
2342         IN      PSTRING                 arg)
2343 {
2344         UCHAR Size;
2345
2346         Size = simple_strtol(arg, 0, 10);
2347
2348         if (Size <=0 || Size >=64)
2349         {
2350                 Size = 8;
2351         }
2352         pAd->CommonCfg.TxBASize = Size-1;
2353         DBGPRINT(RT_DEBUG_ERROR, ("Set_HtTxBASize ::(TxBASize= %d)\n", Size));
2354
2355         return TRUE;
2356 }
2357
2358 INT     Set_HtDisallowTKIP_Proc(
2359         IN      PRTMP_ADAPTER   pAd,
2360         IN      PSTRING                 arg)
2361 {
2362         ULONG Value;
2363
2364         Value = simple_strtol(arg, 0, 10);
2365
2366         if (Value == 1)
2367         {
2368                 pAd->CommonCfg.HT_DisallowTKIP = TRUE;
2369         }
2370         else
2371         {
2372                 pAd->CommonCfg.HT_DisallowTKIP = FALSE;
2373         }
2374
2375         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtDisallowTKIP_Proc ::%s\n",
2376                                 (pAd->CommonCfg.HT_DisallowTKIP == TRUE) ? "enabled" : "disabled"));
2377
2378         return TRUE;
2379 }
2380
2381 INT     Set_HtOpMode_Proc(
2382         IN      PRTMP_ADAPTER   pAd,
2383         IN      PSTRING                 arg)
2384 {
2385
2386         ULONG Value;
2387
2388         Value = simple_strtol(arg, 0, 10);
2389
2390         if (Value == HTMODE_GF)
2391                 pAd->CommonCfg.RegTransmitSetting.field.HTMODE  = HTMODE_GF;
2392         else if ( Value == HTMODE_MM )
2393                 pAd->CommonCfg.RegTransmitSetting.field.HTMODE  = HTMODE_MM;
2394         else
2395                 return FALSE; //Invalid argument
2396
2397         SetCommonHT(pAd);
2398
2399         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtOpMode_Proc::(HtOpMode=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.HTMODE));
2400
2401         return TRUE;
2402
2403 }
2404
2405 INT     Set_HtStbc_Proc(
2406         IN      PRTMP_ADAPTER   pAd,
2407         IN      PSTRING                 arg)
2408 {
2409
2410         ULONG Value;
2411
2412         Value = simple_strtol(arg, 0, 10);
2413
2414         if (Value == STBC_USE)
2415                 pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_USE;
2416         else if ( Value == STBC_NONE )
2417                 pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_NONE;
2418         else
2419                 return FALSE; //Invalid argument
2420
2421         SetCommonHT(pAd);
2422
2423         DBGPRINT(RT_DEBUG_TRACE, ("Set_Stbc_Proc::(HtStbc=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.STBC));
2424
2425         return TRUE;
2426 }
2427
2428 INT     Set_HtHtc_Proc(
2429         IN      PRTMP_ADAPTER   pAd,
2430         IN      PSTRING                 arg)
2431 {
2432
2433         ULONG Value;
2434
2435         Value = simple_strtol(arg, 0, 10);
2436         if (Value == 0)
2437                 pAd->HTCEnable = FALSE;
2438         else if ( Value ==1 )
2439                 pAd->HTCEnable = TRUE;
2440         else
2441                 return FALSE; //Invalid argument
2442
2443         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtHtc_Proc::(HtHtc=%d)\n",pAd->HTCEnable));
2444
2445         return TRUE;
2446 }
2447
2448 INT     Set_HtExtcha_Proc(
2449         IN      PRTMP_ADAPTER   pAd,
2450         IN      PSTRING                 arg)
2451 {
2452
2453         ULONG Value;
2454
2455         Value = simple_strtol(arg, 0, 10);
2456
2457         if (Value == 0)
2458                 pAd->CommonCfg.RegTransmitSetting.field.EXTCHA  = EXTCHA_BELOW;
2459         else if ( Value ==1 )
2460         pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
2461         else
2462                 return FALSE; //Invalid argument
2463
2464         SetCommonHT(pAd);
2465
2466         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtExtcha_Proc::(HtExtcha=%d)\n",pAd->CommonCfg.RegTransmitSetting.field.EXTCHA));
2467
2468         return TRUE;
2469 }
2470
2471 INT     Set_HtMpduDensity_Proc(
2472         IN      PRTMP_ADAPTER   pAd,
2473         IN      PSTRING                 arg)
2474 {
2475         ULONG Value;
2476
2477         Value = simple_strtol(arg, 0, 10);
2478
2479         if (Value <=7 && Value >= 0)
2480                 pAd->CommonCfg.BACapability.field.MpduDensity = Value;
2481         else
2482                 pAd->CommonCfg.BACapability.field.MpduDensity = 4;
2483
2484         SetCommonHT(pAd);
2485
2486         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMpduDensity_Proc::(HtMpduDensity=%d)\n",pAd->CommonCfg.BACapability.field.MpduDensity));
2487
2488         return TRUE;
2489 }
2490
2491 INT     Set_HtBaWinSize_Proc(
2492         IN      PRTMP_ADAPTER   pAd,
2493         IN      PSTRING                 arg)
2494 {
2495         ULONG Value;
2496
2497         Value = simple_strtol(arg, 0, 10);
2498
2499
2500         if (Value >=1 && Value <= 64)
2501         {
2502                 pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = Value;
2503                 pAd->CommonCfg.BACapability.field.RxBAWinLimit = Value;
2504         }
2505         else
2506         {
2507         pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = 64;
2508                 pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64;
2509         }
2510
2511         SetCommonHT(pAd);
2512
2513         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtBaWinSize_Proc::(HtBaWinSize=%d)\n",pAd->CommonCfg.BACapability.field.RxBAWinLimit));
2514
2515         return TRUE;
2516 }
2517
2518 INT     Set_HtRdg_Proc(
2519         IN      PRTMP_ADAPTER   pAd,
2520         IN      PSTRING                 arg)
2521 {
2522         ULONG Value;
2523
2524         Value = simple_strtol(arg, 0, 10);
2525
2526         if (Value == 0)
2527                 pAd->CommonCfg.bRdg = FALSE;
2528         else if ( Value ==1 )
2529         {
2530                 pAd->HTCEnable = TRUE;
2531                 pAd->CommonCfg.bRdg = TRUE;
2532         }
2533         else
2534                 return FALSE; //Invalid argument
2535
2536         SetCommonHT(pAd);
2537
2538         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtRdg_Proc::(HtRdg=%d)\n",pAd->CommonCfg.bRdg));
2539
2540         return TRUE;
2541 }
2542
2543 INT     Set_HtLinkAdapt_Proc(
2544         IN      PRTMP_ADAPTER   pAd,
2545         IN      PSTRING                 arg)
2546 {
2547         ULONG Value;
2548
2549         Value = simple_strtol(arg, 0, 10);
2550         if (Value == 0)
2551                 pAd->bLinkAdapt = FALSE;
2552         else if ( Value ==1 )
2553         {
2554                         pAd->HTCEnable = TRUE;
2555                         pAd->bLinkAdapt = TRUE;
2556         }
2557         else
2558                 return FALSE; //Invalid argument
2559
2560         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtLinkAdapt_Proc::(HtLinkAdapt=%d)\n",pAd->bLinkAdapt));
2561
2562         return TRUE;
2563 }
2564
2565 INT     Set_HtAmsdu_Proc(
2566         IN      PRTMP_ADAPTER   pAd,
2567         IN      PSTRING                 arg)
2568 {
2569         ULONG Value;
2570
2571         Value = simple_strtol(arg, 0, 10);
2572         if (Value == 0)
2573                 pAd->CommonCfg.BACapability.field.AmsduEnable = FALSE;
2574         else if ( Value == 1 )
2575         pAd->CommonCfg.BACapability.field.AmsduEnable = TRUE;
2576         else
2577                 return FALSE; //Invalid argument
2578
2579         SetCommonHT(pAd);
2580
2581         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtAmsdu_Proc::(HtAmsdu=%d)\n",pAd->CommonCfg.BACapability.field.AmsduEnable));
2582
2583         return TRUE;
2584 }
2585
2586 INT     Set_HtAutoBa_Proc(
2587         IN      PRTMP_ADAPTER   pAd,
2588         IN      PSTRING                 arg)
2589 {
2590         ULONG Value;
2591
2592         Value = simple_strtol(arg, 0, 10);
2593         if (Value == 0)
2594         {
2595                 pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
2596                 pAd->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
2597         }
2598     else if (Value == 1)
2599         {
2600                 pAd->CommonCfg.BACapability.field.AutoBA = TRUE;
2601                 pAd->CommonCfg.BACapability.field.Policy = IMMED_BA;
2602         }
2603         else
2604                 return FALSE; //Invalid argument
2605
2606     pAd->CommonCfg.REGBACapability.field.AutoBA = pAd->CommonCfg.BACapability.field.AutoBA;
2607     pAd->CommonCfg.REGBACapability.field.Policy = pAd->CommonCfg.BACapability.field.Policy;
2608
2609         SetCommonHT(pAd);
2610
2611         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtAutoBa_Proc::(HtAutoBa=%d)\n",pAd->CommonCfg.BACapability.field.AutoBA));
2612
2613         return TRUE;
2614
2615 }
2616
2617 INT     Set_HtProtect_Proc(
2618         IN      PRTMP_ADAPTER   pAd,
2619         IN      PSTRING                 arg)
2620 {
2621         ULONG Value;
2622
2623         Value = simple_strtol(arg, 0, 10);
2624         if (Value == 0)
2625                 pAd->CommonCfg.bHTProtect = FALSE;
2626     else if (Value == 1)
2627                 pAd->CommonCfg.bHTProtect = TRUE;
2628         else
2629                 return FALSE; //Invalid argument
2630
2631         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtProtect_Proc::(HtProtect=%d)\n",pAd->CommonCfg.bHTProtect));
2632
2633         return TRUE;
2634 }
2635
2636 INT     Set_SendPSMPAction_Proc(
2637         IN      PRTMP_ADAPTER   pAd,
2638         IN      PSTRING                 arg)
2639 {
2640     UCHAR mac[6], mode;
2641         PSTRING token;
2642         STRING sepValue[] = ":", DASH = '-';
2643         INT i;
2644     MAC_TABLE_ENTRY *pEntry;
2645
2646     //DBGPRINT(RT_DEBUG_TRACE,("\n%s\n", arg));
2647 /*
2648         The BARecTearDown inupt string format should be xx:xx:xx:xx:xx:xx-d,
2649                 =>The six 2 digit hex-decimal number previous are the Mac address,
2650                 =>The seventh decimal number is the mode value.
2651 */
2652     if(strlen(arg) < 19)  //Mac address acceptable format 01:02:03:04:05:06 length 17 plus the "-" and mode value in decimal format.
2653                 return FALSE;
2654
2655         token = strchr(arg, DASH);
2656         if ((token != NULL) && (strlen(token)>1))
2657         {
2658                 mode = simple_strtol((token+1), 0, 10);
2659                 if (mode > MMPS_ENABLE)
2660                         return FALSE;
2661
2662                 *token = '\0';
2663                 for (i = 0, token = rstrtok(arg, &sepValue[0]); token; token = rstrtok(NULL, &sepValue[0]), i++)
2664                 {
2665                         if((strlen(token) != 2) || (!isxdigit(*token)) || (!isxdigit(*(token+1))))
2666                                 return FALSE;
2667                         AtoH(token, (&mac[i]), 1);
2668                 }
2669                 if(i != 6)
2670                         return FALSE;
2671
2672                 DBGPRINT(RT_DEBUG_OFF, ("\n%02x:%02x:%02x:%02x:%02x:%02x-%02x",
2673                                                                 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], mode));
2674
2675                 pEntry = MacTableLookup(pAd, mac);
2676
2677                 if (pEntry) {
2678                     DBGPRINT(RT_DEBUG_OFF, ("\nSendPSMPAction MIPS mode = %d\n", mode));
2679                     SendPSMPAction(pAd, pEntry->Aid, mode);
2680                 }
2681
2682                 return TRUE;
2683         }
2684
2685         return FALSE;
2686
2687
2688 }
2689
2690 INT     Set_HtMIMOPSmode_Proc(
2691         IN      PRTMP_ADAPTER   pAd,
2692         IN      PSTRING                 arg)
2693 {
2694         ULONG Value;
2695
2696         Value = simple_strtol(arg, 0, 10);
2697
2698         if (Value <=3 && Value >= 0)
2699                 pAd->CommonCfg.BACapability.field.MMPSmode = Value;
2700         else
2701                 pAd->CommonCfg.BACapability.field.MMPSmode = 3;
2702
2703         SetCommonHT(pAd);
2704
2705         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMIMOPSmode_Proc::(MIMOPS mode=%d)\n",pAd->CommonCfg.BACapability.field.MMPSmode));
2706
2707         return TRUE;
2708 }
2709
2710
2711 INT     Set_ForceShortGI_Proc(
2712         IN      PRTMP_ADAPTER   pAd,
2713         IN      PSTRING                 arg)
2714 {
2715         ULONG Value;
2716
2717         Value = simple_strtol(arg, 0, 10);
2718         if (Value == 0)
2719                 pAd->WIFItestbed.bShortGI = FALSE;
2720         else if (Value == 1)
2721                 pAd->WIFItestbed.bShortGI = TRUE;
2722         else
2723                 return FALSE; //Invalid argument
2724
2725         SetCommonHT(pAd);
2726
2727         DBGPRINT(RT_DEBUG_TRACE, ("Set_ForceShortGI_Proc::(ForceShortGI=%d)\n", pAd->WIFItestbed.bShortGI));
2728
2729         return TRUE;
2730 }
2731
2732
2733
2734 INT     Set_ForceGF_Proc(
2735         IN      PRTMP_ADAPTER   pAd,
2736         IN      PSTRING                 arg)
2737 {
2738         ULONG Value;
2739
2740         Value = simple_strtol(arg, 0, 10);
2741         if (Value == 0)
2742                 pAd->WIFItestbed.bGreenField = FALSE;
2743         else if (Value == 1)
2744                 pAd->WIFItestbed.bGreenField = TRUE;
2745         else
2746                 return FALSE; //Invalid argument
2747
2748         SetCommonHT(pAd);
2749
2750         DBGPRINT(RT_DEBUG_TRACE, ("Set_ForceGF_Proc::(ForceGF=%d)\n", pAd->WIFItestbed.bGreenField));
2751
2752         return TRUE;
2753 }
2754
2755 INT     Set_HtMimoPs_Proc(
2756         IN      PRTMP_ADAPTER   pAd,
2757         IN      PSTRING                 arg)
2758 {
2759         ULONG Value;
2760
2761         Value = simple_strtol(arg, 0, 10);
2762         if (Value == 0)
2763                 pAd->CommonCfg.bMIMOPSEnable = FALSE;
2764         else if (Value == 1)
2765                 pAd->CommonCfg.bMIMOPSEnable = TRUE;
2766         else
2767                 return FALSE; //Invalid argument
2768
2769         DBGPRINT(RT_DEBUG_TRACE, ("Set_HtMimoPs_Proc::(HtMimoPs=%d)\n",pAd->CommonCfg.bMIMOPSEnable));
2770
2771         return TRUE;
2772 }
2773
2774 INT     SetCommonHT(
2775         IN      PRTMP_ADAPTER   pAd)
2776 {
2777         OID_SET_HT_PHYMODE              SetHT;
2778
2779         if (pAd->CommonCfg.PhyMode < PHY_11ABGN_MIXED)
2780                 return FALSE;
2781
2782         SetHT.PhyMode = pAd->CommonCfg.PhyMode;
2783         SetHT.TransmitNo = ((UCHAR)pAd->Antenna.field.TxPath);
2784         SetHT.HtMode = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.HTMODE;
2785         SetHT.ExtOffset = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.EXTCHA;
2786         SetHT.MCS = MCS_AUTO;
2787         SetHT.BW = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.BW;
2788         SetHT.STBC = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.STBC;
2789         SetHT.SHORTGI = (UCHAR)pAd->CommonCfg.RegTransmitSetting.field.ShortGI;
2790
2791         RTMPSetHT(pAd, &SetHT);
2792
2793         return TRUE;
2794 }
2795
2796 INT     Set_FixedTxMode_Proc(
2797         IN      PRTMP_ADAPTER   pAd,
2798         IN      PSTRING                 arg)
2799 {
2800         UCHAR   fix_tx_mode = FIXED_TXMODE_HT;
2801
2802         if (strcmp(arg, "OFDM") == 0 || strcmp(arg, "ofdm") == 0)
2803         {
2804                 fix_tx_mode = FIXED_TXMODE_OFDM;
2805         }
2806         else if (strcmp(arg, "CCK") == 0 || strcmp(arg, "cck") == 0)
2807         {
2808         fix_tx_mode = FIXED_TXMODE_CCK;
2809         }
2810
2811         pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode = fix_tx_mode;
2812
2813         DBGPRINT(RT_DEBUG_TRACE, ("Set_FixedTxMode_Proc::(FixedTxMode=%d)\n", fix_tx_mode));
2814
2815         return TRUE;
2816 }
2817
2818 #if defined(RT305x)||defined(RT3070)
2819 INT Set_HiPower_Proc(
2820     IN  PRTMP_ADAPTER   pAdapter,
2821     IN  PSTRING          arg)
2822 {
2823         pAdapter->CommonCfg.HighPowerPatchDisabled = !(simple_strtol(arg, 0, 10));
2824
2825         if (pAdapter->CommonCfg.HighPowerPatchDisabled != 0)
2826         {
2827                 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R82, 0x62);
2828                 RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R67, 0x20);
2829 #ifdef RT3070
2830                 if ((IS_RT3070(pAdapter) && ((pAdapter->MACVersion & 0xffff) < 0x0201)))
2831 #endif // RT3070 //
2832                 RT30xxWriteRFRegister(pAdapter, RF_R27, 0x23);
2833         }
2834         return TRUE;
2835 }
2836 #endif
2837
2838 INT Set_LongRetryLimit_Proc(
2839         IN      PRTMP_ADAPTER   pAdapter,
2840         IN      PSTRING                 arg)
2841 {
2842         TX_RTY_CFG_STRUC        tx_rty_cfg;
2843         UCHAR                           LongRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
2844
2845         RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
2846         tx_rty_cfg.field.LongRtyLimit = LongRetryLimit;
2847         RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
2848         DBGPRINT(RT_DEBUG_TRACE, ("IF Set_LongRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
2849         return TRUE;
2850 }
2851
2852 INT Set_ShortRetryLimit_Proc(
2853         IN      PRTMP_ADAPTER   pAdapter,
2854         IN      PSTRING                 arg)
2855 {
2856         TX_RTY_CFG_STRUC        tx_rty_cfg;
2857         UCHAR                           ShortRetryLimit = (UCHAR)simple_strtol(arg, 0, 10);
2858
2859         RTMP_IO_READ32(pAdapter, TX_RTY_CFG, &tx_rty_cfg.word);
2860         tx_rty_cfg.field.ShortRtyLimit = ShortRetryLimit;
2861         RTMP_IO_WRITE32(pAdapter, TX_RTY_CFG, tx_rty_cfg.word);
2862         DBGPRINT(RT_DEBUG_TRACE, ("IF Set_ShortRetryLimit_Proc::(tx_rty_cfg=0x%x)\n", tx_rty_cfg.word));
2863         return TRUE;
2864 }
2865
2866
2867 /////////////////////////////////////////////////////////////////////////
2868 PSTRING RTMPGetRalinkAuthModeStr(
2869     IN  NDIS_802_11_AUTHENTICATION_MODE authMode)
2870 {
2871         switch(authMode)
2872         {
2873                 case Ndis802_11AuthModeOpen:
2874                         return "OPEN";
2875                 case Ndis802_11AuthModeWPAPSK:
2876                         return "WPAPSK";
2877                 case Ndis802_11AuthModeShared:
2878                         return "SHARED";
2879                 case Ndis802_11AuthModeWPA:
2880                         return "WPA";
2881                 case Ndis802_11AuthModeWPA2:
2882                         return "WPA2";
2883                 case Ndis802_11AuthModeWPA2PSK:
2884                         return "WPA2PSK";
2885         case Ndis802_11AuthModeWPA1PSKWPA2PSK:
2886                         return "WPAPSKWPA2PSK";
2887         case Ndis802_11AuthModeWPA1WPA2:
2888                         return "WPA1WPA2";
2889                 case Ndis802_11AuthModeWPANone:
2890                         return "WPANONE";
2891                 default:
2892                         return "UNKNOW";
2893         }
2894 }
2895
2896 PSTRING RTMPGetRalinkEncryModeStr(
2897     IN  USHORT encryMode)
2898 {
2899         switch(encryMode)
2900         {
2901                 case Ndis802_11WEPDisabled:
2902                         return "NONE";
2903                 case Ndis802_11WEPEnabled:
2904                         return "WEP";
2905                 case Ndis802_11Encryption2Enabled:
2906                         return "TKIP";
2907                 case Ndis802_11Encryption3Enabled:
2908                         return "AES";
2909         case Ndis802_11Encryption4Enabled:
2910                         return "TKIPAES";
2911                 default:
2912                         return "UNKNOW";
2913         }
2914 }
2915
2916 INT RTMPShowCfgValue(
2917         IN      PRTMP_ADAPTER   pAd,
2918         IN      PSTRING                 pName,
2919         IN      PSTRING                 pBuf)
2920 {
2921         INT     Status = 0;
2922
2923         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++)
2924         {
2925                 if (!strcmp(pName, PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name))
2926                 {
2927                         if(PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->show_proc(pAd, pBuf))
2928                                 Status = -EINVAL;
2929                         break;  //Exit for loop.
2930                 }
2931         }
2932
2933         if(PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name == NULL)
2934         {
2935                 sprintf(pBuf, "\n");
2936                 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++)
2937                         sprintf(pBuf + strlen(pBuf), "%s\n", PRTMP_PRIVATE_STA_SHOW_CFG_VALUE_PROC->name);
2938         }
2939
2940         return Status;
2941 }
2942
2943 INT     Show_SSID_Proc(
2944         IN      PRTMP_ADAPTER   pAd,
2945         OUT     PSTRING                 pBuf)
2946 {
2947         sprintf(pBuf, "\t%s", pAd->CommonCfg.Ssid);
2948         return 0;
2949 }
2950
2951 INT     Show_WirelessMode_Proc(
2952         IN      PRTMP_ADAPTER   pAd,
2953         OUT     PSTRING                 pBuf)
2954 {
2955         switch(pAd->CommonCfg.PhyMode)
2956         {
2957                 case PHY_11BG_MIXED:
2958                         sprintf(pBuf, "\t11B/G");
2959                         break;
2960                 case PHY_11B:
2961                         sprintf(pBuf, "\t11B");
2962                         break;
2963                 case PHY_11A:
2964                         sprintf(pBuf, "\t11A");
2965                         break;
2966                 case PHY_11ABG_MIXED:
2967                         sprintf(pBuf, "\t11A/B/G");
2968                         break;
2969                 case PHY_11G:
2970                         sprintf(pBuf, "\t11G");
2971                         break;
2972                 case PHY_11ABGN_MIXED:
2973                         sprintf(pBuf, "\t11A/B/G/N");
2974                         break;
2975                 case PHY_11N_2_4G:
2976                         sprintf(pBuf, "\t11N only with 2.4G");
2977                         break;
2978                 case PHY_11GN_MIXED:
2979                         sprintf(pBuf, "\t11G/N");
2980                         break;
2981                 case PHY_11AN_MIXED:
2982                         sprintf(pBuf, "\t11A/N");
2983                         break;
2984                 case PHY_11BGN_MIXED:
2985                         sprintf(pBuf, "\t11B/G/N");
2986                         break;
2987                 case PHY_11AGN_MIXED:
2988                         sprintf(pBuf, "\t11A/G/N");
2989                         break;
2990                 case PHY_11N_5G:
2991                         sprintf(pBuf, "\t11N only with 5G");
2992                         break;
2993                 default:
2994                         sprintf(pBuf, "\tUnknow Value(%d)", pAd->CommonCfg.PhyMode);
2995                         break;
2996         }
2997         return 0;
2998 }
2999
3000
3001 INT     Show_TxBurst_Proc(
3002         IN      PRTMP_ADAPTER   pAd,
3003         OUT     PSTRING                 pBuf)
3004 {
3005         sprintf(pBuf, "\t%s", pAd->CommonCfg.bEnableTxBurst ? "TRUE":"FALSE");
3006         return 0;
3007 }
3008
3009 INT     Show_TxPreamble_Proc(
3010         IN      PRTMP_ADAPTER   pAd,
3011         OUT     PSTRING                 pBuf)
3012 {
3013         switch(pAd->CommonCfg.TxPreamble)
3014         {
3015                 case Rt802_11PreambleShort:
3016                         sprintf(pBuf, "\tShort");
3017                         break;
3018                 case Rt802_11PreambleLong:
3019                         sprintf(pBuf, "\tLong");
3020                         break;
3021                 case Rt802_11PreambleAuto:
3022                         sprintf(pBuf, "\tAuto");
3023                         break;
3024                 default:
3025                         sprintf(pBuf, "\tUnknow Value(%lu)", pAd->CommonCfg.TxPreamble);
3026                         break;
3027         }
3028
3029         return 0;
3030 }
3031
3032 INT     Show_TxPower_Proc(
3033         IN      PRTMP_ADAPTER   pAd,
3034         OUT     PSTRING                 pBuf)
3035 {
3036         sprintf(pBuf, "\t%lu", pAd->CommonCfg.TxPowerPercentage);
3037         return 0;
3038 }
3039
3040 INT     Show_Channel_Proc(
3041         IN      PRTMP_ADAPTER   pAd,
3042         OUT     PSTRING                 pBuf)
3043 {
3044         sprintf(pBuf, "\t%d", pAd->CommonCfg.Channel);
3045         return 0;
3046 }
3047
3048 INT     Show_BGProtection_Proc(
3049         IN      PRTMP_ADAPTER   pAd,
3050         OUT     PSTRING                 pBuf)
3051 {
3052         switch(pAd->CommonCfg.UseBGProtection)
3053         {
3054                 case 1: //Always On
3055                         sprintf(pBuf, "\tON");
3056                         break;
3057                 case 2: //Always OFF
3058                         sprintf(pBuf, "\tOFF");
3059                         break;
3060                 case 0: //AUTO
3061                         sprintf(pBuf, "\tAuto");
3062                         break;
3063                 default:
3064                         sprintf(pBuf, "\tUnknow Value(%lu)", pAd->CommonCfg.UseBGProtection);
3065                         break;
3066         }
3067         return 0;
3068 }
3069
3070 INT     Show_RTSThreshold_Proc(
3071         IN      PRTMP_ADAPTER   pAd,
3072         OUT     PSTRING                 pBuf)
3073 {
3074         sprintf(pBuf, "\t%u", pAd->CommonCfg.RtsThreshold);
3075         return 0;
3076 }
3077
3078 INT     Show_FragThreshold_Proc(
3079         IN      PRTMP_ADAPTER   pAd,
3080         OUT     PSTRING                 pBuf)
3081 {
3082         sprintf(pBuf, "\t%u", pAd->CommonCfg.FragmentThreshold);
3083         return 0;
3084 }
3085
3086 INT     Show_HtBw_Proc(
3087         IN      PRTMP_ADAPTER   pAd,
3088         OUT     PSTRING                 pBuf)
3089 {
3090         if (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)
3091         {
3092                 sprintf(pBuf, "\t40 MHz");
3093         }
3094         else
3095         {
3096         sprintf(pBuf, "\t20 MHz");
3097         }
3098         return 0;
3099 }
3100
3101 INT     Show_HtMcs_Proc(
3102         IN      PRTMP_ADAPTER   pAd,
3103         OUT     PSTRING                 pBuf)
3104 {
3105         sprintf(pBuf, "\t%u", pAd->StaCfg.DesiredTransmitSetting.field.MCS);
3106         return 0;
3107 }
3108
3109 INT     Show_HtGi_Proc(
3110         IN      PRTMP_ADAPTER   pAd,
3111         OUT     PSTRING                 pBuf)
3112 {
3113         switch(pAd->CommonCfg.RegTransmitSetting.field.ShortGI)
3114         {
3115                 case GI_400:
3116                         sprintf(pBuf, "\tGI_400");
3117                         break;
3118                 case GI_800:
3119                         sprintf(pBuf, "\tGI_800");
3120                         break;
3121                 default:
3122                         sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.ShortGI);
3123                         break;
3124         }
3125         return 0;
3126 }
3127
3128 INT     Show_HtOpMode_Proc(
3129         IN      PRTMP_ADAPTER   pAd,
3130         OUT     PSTRING                 pBuf)
3131 {
3132         switch(pAd->CommonCfg.RegTransmitSetting.field.HTMODE)
3133         {
3134                 case HTMODE_GF:
3135                         sprintf(pBuf, "\tGF");
3136                         break;
3137                 case HTMODE_MM:
3138                         sprintf(pBuf, "\tMM");
3139                         break;
3140                 default:
3141                         sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.HTMODE);
3142                         break;
3143         }
3144         return 0;
3145 }
3146
3147 INT     Show_HtExtcha_Proc(
3148         IN      PRTMP_ADAPTER   pAd,
3149         OUT     PSTRING                 pBuf)
3150 {
3151         switch(pAd->CommonCfg.RegTransmitSetting.field.EXTCHA)
3152         {
3153                 case EXTCHA_BELOW:
3154                         sprintf(pBuf, "\tBelow");
3155                         break;
3156                 case EXTCHA_ABOVE:
3157                         sprintf(pBuf, "\tAbove");
3158                         break;
3159                 default:
3160                         sprintf(pBuf, "\tUnknow Value(%u)", pAd->CommonCfg.RegTransmitSetting.field.EXTCHA);
3161                         break;
3162         }
3163         return 0;
3164 }
3165
3166
3167 INT     Show_HtMpduDensity_Proc(
3168         IN      PRTMP_ADAPTER   pAd,
3169         OUT     PSTRING                 pBuf)
3170 {
3171         sprintf(pBuf, "\t%u", pAd->CommonCfg.BACapability.field.MpduDensity);
3172         return 0;
3173 }
3174
3175 INT     Show_HtBaWinSize_Proc(
3176         IN      PRTMP_ADAPTER   pAd,
3177         OUT     PSTRING                 pBuf)
3178 {
3179         sprintf(pBuf, "\t%u", pAd->CommonCfg.BACapability.field.RxBAWinLimit);
3180         return 0;
3181 }
3182
3183 INT     Show_HtRdg_Proc(
3184         IN      PRTMP_ADAPTER   pAd,
3185         OUT     PSTRING                 pBuf)
3186 {
3187         sprintf(pBuf, "\t%s", pAd->CommonCfg.bRdg ? "TRUE":"FALSE");
3188         return 0;
3189 }
3190
3191 INT     Show_HtAmsdu_Proc(
3192         IN      PRTMP_ADAPTER   pAd,
3193         OUT     PSTRING                 pBuf)
3194 {
3195         sprintf(pBuf, "\t%s", pAd->CommonCfg.BACapability.field.AmsduEnable ? "TRUE":"FALSE");
3196         return 0;
3197 }
3198
3199 INT     Show_HtAutoBa_Proc(
3200         IN      PRTMP_ADAPTER   pAd,
3201         OUT     PSTRING                 pBuf)
3202 {
3203         sprintf(pBuf, "\t%s", pAd->CommonCfg.BACapability.field.AutoBA ? "TRUE":"FALSE");
3204         return 0;
3205 }
3206
3207 INT     Show_CountryRegion_Proc(
3208         IN      PRTMP_ADAPTER   pAd,
3209         OUT     PSTRING                 pBuf)
3210 {
3211         sprintf(pBuf, "\t%d", pAd->CommonCfg.CountryRegion);
3212         return 0;
3213 }
3214
3215 INT     Show_CountryRegionABand_Proc(
3216         IN      PRTMP_ADAPTER   pAd,
3217         OUT     PSTRING                 pBuf)
3218 {
3219         sprintf(pBuf, "\t%d", pAd->CommonCfg.CountryRegionForABand);
3220         return 0;
3221 }
3222
3223 INT     Show_CountryCode_Proc(
3224         IN      PRTMP_ADAPTER   pAd,
3225         OUT     PSTRING                 pBuf)
3226 {
3227         sprintf(pBuf, "\t%s", pAd->CommonCfg.CountryCode);
3228         return 0;
3229 }
3230
3231 #ifdef AGGREGATION_SUPPORT
3232 INT     Show_PktAggregate_Proc(
3233         IN      PRTMP_ADAPTER   pAd,
3234         OUT     PSTRING                 pBuf)
3235 {
3236         sprintf(pBuf, "\t%s", pAd->CommonCfg.bAggregationCapable ? "TRUE":"FALSE");
3237         return 0;
3238 }
3239 #endif // AGGREGATION_SUPPORT //
3240
3241 #ifdef WMM_SUPPORT
3242 INT     Show_WmmCapable_Proc(
3243         IN      PRTMP_ADAPTER   pAd,
3244         OUT     PSTRING                 pBuf)
3245 {
3246         sprintf(pBuf, "\t%s", pAd->CommonCfg.bWmmCapable ? "TRUE":"FALSE");
3247
3248         return 0;
3249 }
3250 #endif // WMM_SUPPORT //
3251
3252 INT     Show_IEEE80211H_Proc(
3253         IN      PRTMP_ADAPTER   pAd,
3254         OUT     PSTRING                 pBuf)
3255 {
3256         sprintf(pBuf, "\t%s", pAd->CommonCfg.bIEEE80211H ? "TRUE":"FALSE");
3257         return 0;
3258 }
3259
3260 INT     Show_NetworkType_Proc(
3261         IN      PRTMP_ADAPTER   pAd,
3262         OUT     PSTRING                 pBuf)
3263 {
3264         switch(pAd->StaCfg.BssType)
3265         {
3266                 case BSS_ADHOC:
3267                         sprintf(pBuf, "\tAdhoc");
3268                         break;
3269                 case BSS_INFRA:
3270                         sprintf(pBuf, "\tInfra");
3271                         break;
3272                 case BSS_ANY:
3273                         sprintf(pBuf, "\tAny");
3274                         break;
3275                 case BSS_MONITOR:
3276                         sprintf(pBuf, "\tMonitor");
3277                         break;
3278                 default:
3279                         sprintf(pBuf, "\tUnknow Value(%d)", pAd->StaCfg.BssType);
3280                         break;
3281         }
3282         return 0;
3283 }
3284
3285
3286
3287 INT     Show_AuthMode_Proc(
3288         IN      PRTMP_ADAPTER   pAd,
3289         OUT     PSTRING                 pBuf)
3290 {
3291         NDIS_802_11_AUTHENTICATION_MODE AuthMode = Ndis802_11AuthModeOpen;
3292
3293         AuthMode = pAd->StaCfg.AuthMode;
3294
3295         if ((AuthMode >= Ndis802_11AuthModeOpen) &&
3296                 (AuthMode <= Ndis802_11AuthModeWPA1PSKWPA2PSK))
3297                 sprintf(pBuf, "\t%s", RTMPGetRalinkAuthModeStr(AuthMode));
3298         else
3299                 sprintf(pBuf, "\tUnknow Value(%d)", AuthMode);
3300
3301         return 0;
3302 }
3303
3304 INT     Show_EncrypType_Proc(
3305         IN      PRTMP_ADAPTER   pAd,
3306         OUT     PSTRING                 pBuf)
3307 {
3308         NDIS_802_11_WEP_STATUS  WepStatus = Ndis802_11WEPDisabled;
3309
3310         WepStatus = pAd->StaCfg.WepStatus;
3311
3312         if ((WepStatus >= Ndis802_11WEPEnabled) &&
3313                 (WepStatus <= Ndis802_11Encryption4KeyAbsent))
3314                 sprintf(pBuf, "\t%s", RTMPGetRalinkEncryModeStr(WepStatus));
3315         else
3316                 sprintf(pBuf, "\tUnknow Value(%d)", WepStatus);
3317
3318         return 0;
3319 }
3320
3321 INT     Show_DefaultKeyID_Proc(
3322         IN      PRTMP_ADAPTER   pAd,
3323         OUT     PSTRING                 pBuf)
3324 {
3325         UCHAR DefaultKeyId = 0;
3326
3327         DefaultKeyId = pAd->StaCfg.DefaultKeyId;
3328
3329         sprintf(pBuf, "\t%d", DefaultKeyId);
3330
3331         return 0;
3332 }
3333
3334 INT     Show_WepKey_Proc(
3335         IN      PRTMP_ADAPTER   pAd,
3336         IN  INT                         KeyIdx,
3337         OUT     PSTRING                 pBuf)
3338 {
3339         UCHAR   Key[16] = {0}, KeyLength = 0;
3340         INT             index = BSS0;
3341
3342         KeyLength = pAd->SharedKey[index][KeyIdx].KeyLen;
3343         NdisMoveMemory(Key, pAd->SharedKey[index][KeyIdx].Key, KeyLength);
3344
3345         //check key string is ASCII or not
3346     if (RTMPCheckStrPrintAble((PCHAR)Key, KeyLength))
3347         sprintf(pBuf, "\t%s", Key);
3348     else
3349     {
3350         int idx;
3351         sprintf(pBuf, "\t");
3352         for (idx = 0; idx < KeyLength; idx++)
3353             sprintf(pBuf+strlen(pBuf), "%02X", Key[idx]);
3354     }
3355         return 0;
3356 }
3357
3358 INT     Show_Key1_Proc(
3359         IN      PRTMP_ADAPTER   pAd,
3360         OUT     PSTRING                 pBuf)
3361 {
3362         Show_WepKey_Proc(pAd, 0, pBuf);
3363         return 0;
3364 }
3365
3366 INT     Show_Key2_Proc(
3367         IN      PRTMP_ADAPTER   pAd,
3368         OUT     PSTRING                 pBuf)
3369 {
3370         Show_WepKey_Proc(pAd, 1, pBuf);
3371         return 0;
3372 }
3373
3374 INT     Show_Key3_Proc(
3375         IN      PRTMP_ADAPTER   pAd,
3376         OUT     PSTRING                 pBuf)
3377 {
3378         Show_WepKey_Proc(pAd, 2, pBuf);
3379         return 0;
3380 }
3381
3382 INT     Show_Key4_Proc(
3383         IN      PRTMP_ADAPTER   pAd,
3384         OUT     PSTRING                 pBuf)
3385 {
3386         Show_WepKey_Proc(pAd, 3, pBuf);
3387         return 0;
3388 }
3389
3390 INT     Show_WPAPSK_Proc(
3391         IN      PRTMP_ADAPTER   pAd,
3392         OUT     PSTRING                 pBuf)
3393 {
3394         INT     idx;
3395         UCHAR   PMK[32] = {0};
3396
3397         NdisMoveMemory(PMK, pAd->StaCfg.PMK, 32);
3398
3399     sprintf(pBuf, "\tPMK = ");
3400     for (idx = 0; idx < 32; idx++)
3401         sprintf(pBuf+strlen(pBuf), "%02X", PMK[idx]);
3402
3403         return 0;
3404 }
3405