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