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