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