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