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