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