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