]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/staging/rt2870/rt_profile.c
Staging: rt2870: remove DOT11_N_SUPPORT ifdefs
[mv-sheeva.git] / drivers / staging / rt2870 / rt_profile.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 static void HTParametersHook(
31         IN      PRTMP_ADAPTER pAd,
32         IN      CHAR              *pValueStr,
33         IN      CHAR              *pInput);
34
35 #define ETH_MAC_ADDR_STR_LEN 17  // in format of xx:xx:xx:xx:xx:xx
36
37 // We assume the s1 is a sting, s2 is a memory space with 6 bytes. and content of s1 will be changed.
38 BOOLEAN rtstrmactohex(char *s1, char *s2)
39 {
40         int i = 0;
41         char *ptokS = s1, *ptokE = s1;
42
43         if (strlen(s1) != ETH_MAC_ADDR_STR_LEN)
44                 return FALSE;
45
46         while((*ptokS) != '\0')
47         {
48                 if((ptokE = strchr(ptokS, ':')) != NULL)
49                         *ptokE++ = '\0';
50                 if ((strlen(ptokS) != 2) || (!isxdigit(*ptokS)) || (!isxdigit(*(ptokS+1))))
51                         break; // fail
52                 AtoH(ptokS, &s2[i++], 1);
53                 ptokS = ptokE;
54                 if (i == 6)
55                         break; // parsing finished
56         }
57
58         return ( i == 6 ? TRUE : FALSE);
59
60 }
61
62
63 // we assume the s1 and s2 both are strings.
64 BOOLEAN rtstrcasecmp(char *s1, char *s2)
65 {
66         char *p1 = s1, *p2 = s2;
67
68         if (strlen(s1) != strlen(s2))
69                 return FALSE;
70
71         while(*p1 != '\0')
72         {
73                 if((*p1 != *p2) && ((*p1 ^ *p2) != 0x20))
74                         return FALSE;
75                 p1++;
76                 p2++;
77         }
78
79         return TRUE;
80 }
81
82 // we assume the s1 (buffer) and s2 (key) both are strings.
83 char * rtstrstruncasecmp(char * s1, char * s2)
84 {
85         INT l1, l2, i;
86         char temp1, temp2;
87
88         l2 = strlen(s2);
89         if (!l2)
90                 return (char *) s1;
91
92         l1 = strlen(s1);
93
94         while (l1 >= l2)
95         {
96                 l1--;
97
98                 for(i=0; i<l2; i++)
99                 {
100                         temp1 = *(s1+i);
101                         temp2 = *(s2+i);
102
103                         if (('a' <= temp1) && (temp1 <= 'z'))
104                                 temp1 = 'A'+(temp1-'a');
105                         if (('a' <= temp2) && (temp2 <= 'z'))
106                                 temp2 = 'A'+(temp2-'a');
107
108                         if (temp1 != temp2)
109                                 break;
110                 }
111
112                 if (i == l2)
113                         return (char *) s1;
114
115                 s1++;
116         }
117
118         return NULL; // not found
119 }
120
121 //add by kathy
122
123  /**
124   * strstr - Find the first substring in a %NUL terminated string
125   * @s1: The string to be searched
126   * @s2: The string to search for
127   */
128 char * rtstrstr(const char * s1,const char * s2)
129 {
130         INT l1, l2;
131
132         l2 = strlen(s2);
133         if (!l2)
134                 return (char *) s1;
135
136         l1 = strlen(s1);
137
138         while (l1 >= l2)
139         {
140                 l1--;
141                 if (!memcmp(s1,s2,l2))
142                         return (char *) s1;
143                 s1++;
144         }
145
146         return NULL;
147 }
148
149 /**
150  * rstrtok - Split a string into tokens
151  * @s: The string to be searched
152  * @ct: The characters to search for
153  * * WARNING: strtok is deprecated, use strsep instead. However strsep is not compatible with old architecture.
154  */
155 char * __rstrtok;
156 char * rstrtok(char * s,const char * ct)
157 {
158         char *sbegin, *send;
159
160         sbegin  = s ? s : __rstrtok;
161         if (!sbegin)
162         {
163                 return NULL;
164         }
165
166         sbegin += strspn(sbegin,ct);
167         if (*sbegin == '\0')
168         {
169                 __rstrtok = NULL;
170                 return( NULL );
171         }
172
173         send = strpbrk( sbegin, ct);
174         if (send && *send != '\0')
175                 *send++ = '\0';
176
177         __rstrtok = send;
178
179         return (sbegin);
180 }
181
182 /**
183  * delimitcnt - return the count of a given delimiter in a given string.
184  * @s: The string to be searched.
185  * @ct: The delimiter to search for.
186  * Notice : We suppose the delimiter is a single-char string(for example : ";").
187  */
188 INT delimitcnt(char * s,const char * ct)
189 {
190         INT count = 0;
191         /* point to the beginning of the line */
192         const char *token = s;
193
194         for ( ;; )
195         {
196                 token = strpbrk(token, ct); /* search for delimiters */
197
198         if ( token == NULL )
199                 {
200                         /* advanced to the terminating null character */
201                         break;
202                 }
203                 /* skip the delimiter */
204             ++token;
205
206                 /*
207                  * Print the found text: use len with %.*s to specify field width.
208                  */
209
210                 /* accumulate delimiter count */
211             ++count;
212         }
213     return count;
214 }
215
216 /*
217   * converts the Internet host address from the standard numbers-and-dots notation
218   * into binary data.
219   * returns nonzero if the address is valid, zero if not.
220   */
221 int rtinet_aton(const char *cp, unsigned int *addr)
222 {
223         unsigned int    val;
224         int             base, n;
225         char            c;
226         unsigned int    parts[4];
227         unsigned int    *pp = parts;
228
229         for (;;)
230     {
231          /*
232           * Collect number up to ``.''.
233           * Values are specified as for C:
234           *     0x=hex, 0=octal, other=decimal.
235           */
236          val = 0;
237          base = 10;
238          if (*cp == '0')
239          {
240              if (*++cp == 'x' || *cp == 'X')
241                  base = 16, cp++;
242              else
243                  base = 8;
244          }
245          while ((c = *cp) != '\0')
246          {
247              if (isdigit((unsigned char) c))
248              {
249                  val = (val * base) + (c - '0');
250                  cp++;
251                  continue;
252              }
253              if (base == 16 && isxdigit((unsigned char) c))
254              {
255                  val = (val << 4) +
256                      (c + 10 - (islower((unsigned char) c) ? 'a' : 'A'));
257                  cp++;
258                  continue;
259              }
260              break;
261          }
262          if (*cp == '.')
263          {
264              /*
265               * Internet format: a.b.c.d a.b.c   (with c treated as 16-bits)
266               * a.b     (with b treated as 24 bits)
267               */
268              if (pp >= parts + 3 || val > 0xff)
269                  return 0;
270              *pp++ = val, cp++;
271          }
272          else
273              break;
274      }
275
276      /*
277       * Check for trailing junk.
278       */
279      while (*cp)
280          if (!isspace((unsigned char) *cp++))
281              return 0;
282
283      /*
284       * Concoct the address according to the number of parts specified.
285       */
286      n = pp - parts + 1;
287      switch (n)
288      {
289
290          case 1:         /* a -- 32 bits */
291              break;
292
293          case 2:         /* a.b -- 8.24 bits */
294              if (val > 0xffffff)
295                  return 0;
296              val |= parts[0] << 24;
297              break;
298
299          case 3:         /* a.b.c -- 8.8.16 bits */
300              if (val > 0xffff)
301                  return 0;
302              val |= (parts[0] << 24) | (parts[1] << 16);
303              break;
304
305          case 4:         /* a.b.c.d -- 8.8.8.8 bits */
306              if (val > 0xff)
307                  return 0;
308              val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
309              break;
310      }
311
312      *addr = htonl(val);
313      return 1;
314
315 }
316
317 /*
318     ========================================================================
319
320     Routine Description:
321         Find key section for Get key parameter.
322
323     Arguments:
324         buffer                      Pointer to the buffer to start find the key section
325         section                     the key of the secion to be find
326
327     Return Value:
328         NULL                        Fail
329         Others                      Success
330     ========================================================================
331 */
332 PUCHAR  RTMPFindSection(
333     IN  PCHAR   buffer)
334 {
335     CHAR temp_buf[32];
336     PUCHAR  ptr;
337
338     strcpy(temp_buf, "Default");
339
340     if((ptr = rtstrstr(buffer, temp_buf)) != NULL)
341             return (ptr+strlen("\n"));
342         else
343             return NULL;
344 }
345
346 /*
347     ========================================================================
348
349     Routine Description:
350         Get key parameter.
351
352     Arguments:
353         key                         Pointer to key string
354         dest                        Pointer to destination
355         destsize                    The datasize of the destination
356         buffer                      Pointer to the buffer to start find the key
357
358     Return Value:
359         TRUE                        Success
360         FALSE                       Fail
361
362     Note:
363         This routine get the value with the matched key (case case-sensitive)
364     ========================================================================
365 */
366 INT RTMPGetKeyParameter(
367     IN  PCHAR   key,
368     OUT PCHAR   dest,
369     IN  INT     destsize,
370     IN  PCHAR   buffer)
371 {
372     UCHAR *temp_buf1 = NULL;
373     UCHAR *temp_buf2 = NULL;
374     CHAR *start_ptr;
375     CHAR *end_ptr;
376     CHAR *ptr;
377     CHAR *offset = 0;
378     INT  len;
379
380         //temp_buf1 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
381         os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);
382
383         if(temp_buf1 == NULL)
384         return (FALSE);
385
386         //temp_buf2 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
387         os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE);
388         if(temp_buf2 == NULL)
389         {
390                 os_free_mem(NULL, temp_buf1);
391         return (FALSE);
392         }
393
394     //find section
395     if((offset = RTMPFindSection(buffer)) == NULL)
396     {
397         os_free_mem(NULL, temp_buf1);
398         os_free_mem(NULL, temp_buf2);
399         return (FALSE);
400     }
401
402     strcpy(temp_buf1, "\n");
403     strcat(temp_buf1, key);
404     strcat(temp_buf1, "=");
405
406     //search key
407     if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
408     {
409                 os_free_mem(NULL, temp_buf1);
410         os_free_mem(NULL, temp_buf2);
411         return (FALSE);
412     }
413
414     start_ptr+=strlen("\n");
415     if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
416        end_ptr=start_ptr+strlen(start_ptr);
417
418     if (end_ptr<start_ptr)
419     {
420                 os_free_mem(NULL, temp_buf1);
421         os_free_mem(NULL, temp_buf2);
422         return (FALSE);
423     }
424
425     NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
426     temp_buf2[end_ptr-start_ptr]='\0';
427     len = strlen(temp_buf2);
428     strcpy(temp_buf1, temp_buf2);
429     if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
430     {
431                 os_free_mem(NULL, temp_buf1);
432         os_free_mem(NULL, temp_buf2);
433         return (FALSE);
434     }
435
436     strcpy(temp_buf2, start_ptr+1);
437     ptr = temp_buf2;
438     //trim space or tab
439     while(*ptr != 0x00)
440     {
441         if( (*ptr == ' ') || (*ptr == '\t') )
442             ptr++;
443         else
444            break;
445     }
446
447     len = strlen(ptr);
448     memset(dest, 0x00, destsize);
449     strncpy(dest, ptr, len >= destsize ?  destsize: len);
450
451         os_free_mem(NULL, temp_buf1);
452     os_free_mem(NULL, temp_buf2);
453     return TRUE;
454 }
455
456 /*
457     ========================================================================
458
459     Routine Description:
460         Get key parameter.
461
462     Arguments:
463         key                         Pointer to key string
464         dest                        Pointer to destination
465         destsize                    The datasize of the destination
466         buffer                      Pointer to the buffer to start find the key
467
468     Return Value:
469         TRUE                        Success
470         FALSE                       Fail
471
472     Note:
473         This routine get the value with the matched key (case case-sensitive).
474         It is called for parsing SSID and any key string.
475     ========================================================================
476 */
477 INT RTMPGetCriticalParameter(
478     IN  PCHAR   key,
479     OUT PCHAR   dest,
480     IN  INT     destsize,
481     IN  PCHAR   buffer)
482 {
483     UCHAR *temp_buf1 = NULL;
484     UCHAR *temp_buf2 = NULL;
485     CHAR *start_ptr;
486     CHAR *end_ptr;
487     CHAR *ptr;
488     CHAR *offset = 0;
489     INT  len;
490
491         //temp_buf1 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
492         os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);
493
494         if(temp_buf1 == NULL)
495         return (FALSE);
496
497         //temp_buf2 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
498         os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE);
499         if(temp_buf2 == NULL)
500         {
501                 os_free_mem(NULL, temp_buf1);
502         return (FALSE);
503         }
504
505     //find section
506     if((offset = RTMPFindSection(buffer)) == NULL)
507     {
508         os_free_mem(NULL, temp_buf1);
509         os_free_mem(NULL, temp_buf2);
510         return (FALSE);
511     }
512
513     strcpy(temp_buf1, "\n");
514     strcat(temp_buf1, key);
515     strcat(temp_buf1, "=");
516
517     //search key
518     if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
519     {
520                 os_free_mem(NULL, temp_buf1);
521         os_free_mem(NULL, temp_buf2);
522         return (FALSE);
523     }
524
525     start_ptr+=strlen("\n");
526     if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
527        end_ptr=start_ptr+strlen(start_ptr);
528
529     if (end_ptr<start_ptr)
530     {
531                 os_free_mem(NULL, temp_buf1);
532         os_free_mem(NULL, temp_buf2);
533         return (FALSE);
534     }
535
536     NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
537     temp_buf2[end_ptr-start_ptr]='\0';
538     len = strlen(temp_buf2);
539     strcpy(temp_buf1, temp_buf2);
540     if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
541     {
542                 os_free_mem(NULL, temp_buf1);
543         os_free_mem(NULL, temp_buf2);
544         return (FALSE);
545     }
546
547     strcpy(temp_buf2, start_ptr+1);
548     ptr = temp_buf2;
549
550     //trim tab
551     /* We cannot trim space(' ') for SSID and key string. */
552     while(*ptr != 0x00)
553     {
554         //if( (*ptr == ' ') || (*ptr == '\t') )
555         if( (*ptr == '\t') )
556             ptr++;
557         else
558            break;
559     }
560
561     len = strlen(ptr);
562     memset(dest, 0x00, destsize);
563     strncpy(dest, ptr, len >= destsize ?  destsize: len);
564
565         os_free_mem(NULL, temp_buf1);
566     os_free_mem(NULL, temp_buf2);
567     return TRUE;
568 }
569
570 /*
571     ========================================================================
572
573     Routine Description:
574         Get multiple key parameter.
575
576     Arguments:
577         key                         Pointer to key string
578         dest                        Pointer to destination
579         destsize                    The datasize of the destination
580         buffer                      Pointer to the buffer to start find the key
581
582     Return Value:
583         TRUE                        Success
584         FALSE                       Fail
585
586     Note:
587         This routine get the value with the matched key (case case-sensitive)
588     ========================================================================
589 */
590 INT RTMPGetKeyParameterWithOffset(
591     IN  PCHAR   key,
592     OUT PCHAR   dest,
593     OUT USHORT  *end_offset,
594     IN  INT     destsize,
595     IN  PCHAR   buffer,
596     IN  BOOLEAN bTrimSpace)
597 {
598     UCHAR *temp_buf1 = NULL;
599     UCHAR *temp_buf2 = NULL;
600     CHAR *start_ptr;
601     CHAR *end_ptr;
602     CHAR *ptr;
603     CHAR *offset = 0;
604     INT  len;
605
606         if (*end_offset >= MAX_INI_BUFFER_SIZE)
607                 return (FALSE);
608
609         os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);
610
611         if(temp_buf1 == NULL)
612         return (FALSE);
613
614         os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE);
615         if(temp_buf2 == NULL)
616         {
617                 os_free_mem(NULL, temp_buf1);
618         return (FALSE);
619         }
620
621     //find section
622         if(*end_offset == 0)
623     {
624                 if ((offset = RTMPFindSection(buffer)) == NULL)
625                 {
626                         os_free_mem(NULL, temp_buf1);
627                 os_free_mem(NULL, temp_buf2);
628             return (FALSE);
629                 }
630     }
631         else
632                 offset = buffer + (*end_offset);
633
634     strcpy(temp_buf1, "\n");
635     strcat(temp_buf1, key);
636     strcat(temp_buf1, "=");
637
638     //search key
639     if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
640     {
641                 os_free_mem(NULL, temp_buf1);
642         os_free_mem(NULL, temp_buf2);
643         return (FALSE);
644     }
645
646     start_ptr+=strlen("\n");
647     if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
648        end_ptr=start_ptr+strlen(start_ptr);
649
650     if (end_ptr<start_ptr)
651     {
652                 os_free_mem(NULL, temp_buf1);
653         os_free_mem(NULL, temp_buf2);
654         return (FALSE);
655     }
656
657         *end_offset = end_ptr - buffer;
658
659     NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
660     temp_buf2[end_ptr-start_ptr]='\0';
661     len = strlen(temp_buf2);
662     strcpy(temp_buf1, temp_buf2);
663     if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
664     {
665                 os_free_mem(NULL, temp_buf1);
666         os_free_mem(NULL, temp_buf2);
667         return (FALSE);
668     }
669
670     strcpy(temp_buf2, start_ptr+1);
671     ptr = temp_buf2;
672     //trim space or tab
673     while(*ptr != 0x00)
674     {
675         if((bTrimSpace && (*ptr == ' ')) || (*ptr == '\t') )
676             ptr++;
677         else
678            break;
679     }
680
681     len = strlen(ptr);
682     memset(dest, 0x00, destsize);
683     strncpy(dest, ptr, len >= destsize ?  destsize: len);
684
685         os_free_mem(NULL, temp_buf1);
686     os_free_mem(NULL, temp_buf2);
687     return TRUE;
688 }
689
690
691 static int rtmp_parse_key_buffer_from_file(IN  PRTMP_ADAPTER pAd,IN  char *buffer,IN  ULONG KeyType,IN  INT BSSIdx,IN  INT KeyIdx)
692 {
693         PUCHAR          keybuff;
694         INT                     i = BSSIdx, idx = KeyIdx;
695         ULONG           KeyLen;
696         UCHAR           CipherAlg = CIPHER_WEP64;
697
698         keybuff = buffer;
699         KeyLen = strlen(keybuff);
700
701         if (KeyType == 1)
702         {//Ascii
703                 if( (KeyLen == 5) || (KeyLen == 13))
704                 {
705                         pAd->SharedKey[i][idx].KeyLen = KeyLen;
706                         NdisMoveMemory(pAd->SharedKey[i][idx].Key, keybuff, KeyLen);
707                         if (KeyLen == 5)
708                                 CipherAlg = CIPHER_WEP64;
709                         else
710                                 CipherAlg = CIPHER_WEP128;
711                         pAd->SharedKey[i][idx].CipherAlg = CipherAlg;
712
713                         DBGPRINT(RT_DEBUG_TRACE, ("I/F(ra%d) Key%dStr=%s and type=%s\n", i, idx+1, keybuff, (KeyType == 0) ? "Hex":"Ascii"));
714                         return 1;
715                 }
716                 else
717                 {//Invalid key length
718                         DBGPRINT(RT_DEBUG_ERROR, ("Key%dStr is Invalid key length! KeyLen = %ld!\n", idx+1, KeyLen));
719                         return 0;
720                 }
721         }
722         else
723         {//Hex type
724                 if( (KeyLen == 10) || (KeyLen == 26))
725                 {
726                         pAd->SharedKey[i][idx].KeyLen = KeyLen / 2;
727                         AtoH(keybuff, pAd->SharedKey[i][idx].Key, KeyLen / 2);
728                         if (KeyLen == 10)
729                                 CipherAlg = CIPHER_WEP64;
730                         else
731                                 CipherAlg = CIPHER_WEP128;
732                         pAd->SharedKey[i][idx].CipherAlg = CipherAlg;
733
734                         DBGPRINT(RT_DEBUG_TRACE, ("I/F(ra%d) Key%dStr=%s and type=%s\n", i, idx+1, keybuff, (KeyType == 0) ? "Hex":"Ascii"));
735                         return 1;
736                 }
737                 else
738                 {//Invalid key length
739                         DBGPRINT(RT_DEBUG_ERROR, ("I/F(ra%d) Key%dStr is Invalid key length! KeyLen = %ld!\n", i, idx+1, KeyLen));
740                         return 0;
741                 }
742         }
743 }
744 static void rtmp_read_key_parms_from_file(IN  PRTMP_ADAPTER pAd, char *tmpbuf, char *buffer)
745 {
746         char            tok_str[16];
747         PUCHAR          macptr;
748         INT                     i = 0, idx;
749         ULONG           KeyType[MAX_MBSSID_NUM];
750         ULONG           KeyIdx;
751
752         NdisZeroMemory(KeyType, MAX_MBSSID_NUM);
753
754         //DefaultKeyID
755         if(RTMPGetKeyParameter("DefaultKeyID", tmpbuf, 25, buffer))
756         {
757                 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
758                 {
759                         KeyIdx = simple_strtol(tmpbuf, 0, 10);
760                         if((KeyIdx >= 1 ) && (KeyIdx <= 4))
761                                 pAd->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1);
762                         else
763                                 pAd->StaCfg.DefaultKeyId = 0;
764
765                         DBGPRINT(RT_DEBUG_TRACE, ("DefaultKeyID(0~3)=%d\n", pAd->StaCfg.DefaultKeyId));
766                 }
767         }
768
769
770         for (idx = 0; idx < 4; idx++)
771         {
772                 sprintf(tok_str, "Key%dType", idx + 1);
773                 //Key1Type
774                 if (RTMPGetKeyParameter(tok_str, tmpbuf, 128, buffer))
775                 {
776                     for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
777                     {
778                             KeyType[i] = simple_strtol(macptr, 0, 10);
779                     }
780
781                         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
782                         {
783                                 sprintf(tok_str, "Key%dStr", idx + 1);
784                                 if (RTMPGetCriticalParameter(tok_str, tmpbuf, 128, buffer))
785                                 {
786                                         rtmp_parse_key_buffer_from_file(pAd, tmpbuf, KeyType[BSS0], BSS0, idx);
787                                 }
788                         }
789                 }
790         }
791 }
792
793 static void rtmp_read_sta_wmm_parms_from_file(IN  PRTMP_ADAPTER pAd, char *tmpbuf, char *buffer)
794 {
795         PUCHAR                                  macptr;
796         INT                                             i=0;
797         BOOLEAN                                 bWmmEnable = FALSE;
798
799         //WmmCapable
800         if(RTMPGetKeyParameter("WmmCapable", tmpbuf, 32, buffer))
801         {
802                 if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
803                 {
804                         pAd->CommonCfg.bWmmCapable = TRUE;
805                         bWmmEnable = TRUE;
806                 }
807                 else //Disable
808                 {
809                         pAd->CommonCfg.bWmmCapable = FALSE;
810                 }
811
812                 DBGPRINT(RT_DEBUG_TRACE, ("WmmCapable=%d\n", pAd->CommonCfg.bWmmCapable));
813         }
814
815         //AckPolicy for AC_BK, AC_BE, AC_VI, AC_VO
816         if(RTMPGetKeyParameter("AckPolicy", tmpbuf, 32, buffer))
817         {
818                 for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
819                 {
820                         pAd->CommonCfg.AckPolicy[i] = (UCHAR)simple_strtol(macptr, 0, 10);
821
822                         DBGPRINT(RT_DEBUG_TRACE, ("AckPolicy[%d]=%d\n", i, pAd->CommonCfg.AckPolicy[i]));
823                 }
824         }
825
826         if (bWmmEnable)
827         {
828                 //APSDCapable
829                 if(RTMPGetKeyParameter("APSDCapable", tmpbuf, 10, buffer))
830                 {
831                         if(simple_strtol(tmpbuf, 0, 10) != 0)  //Enable
832                                 pAd->CommonCfg.bAPSDCapable = TRUE;
833                         else
834                                 pAd->CommonCfg.bAPSDCapable = FALSE;
835
836                         DBGPRINT(RT_DEBUG_TRACE, ("APSDCapable=%d\n", pAd->CommonCfg.bAPSDCapable));
837                 }
838
839                 //APSDAC for AC_BE, AC_BK, AC_VI, AC_VO
840                 if(RTMPGetKeyParameter("APSDAC", tmpbuf, 32, buffer))
841                 {
842                         BOOLEAN apsd_ac[4];
843
844                         for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
845                         {
846                                 apsd_ac[i] = (BOOLEAN)simple_strtol(macptr, 0, 10);
847
848                                 DBGPRINT(RT_DEBUG_TRACE, ("APSDAC%d  %d\n", i,  apsd_ac[i]));
849                         }
850
851                         pAd->CommonCfg.bAPSDAC_BE = apsd_ac[0];
852                         pAd->CommonCfg.bAPSDAC_BK = apsd_ac[1];
853                         pAd->CommonCfg.bAPSDAC_VI = apsd_ac[2];
854                         pAd->CommonCfg.bAPSDAC_VO = apsd_ac[3];
855                 }
856         }
857
858 }
859
860 NDIS_STATUS     RTMPReadParametersHook(
861         IN      PRTMP_ADAPTER pAd)
862 {
863         PUCHAR                                  src = NULL;
864         struct file                             *srcf;
865         INT                                     retval, orgfsuid, orgfsgid;
866         mm_segment_t                    orgfs;
867         CHAR                                    *buffer;
868         CHAR                                    *tmpbuf;
869         ULONG                                   RtsThresh;
870         ULONG                                   FragThresh;
871         UCHAR                   keyMaterial[40];
872
873         PUCHAR                                  macptr;
874         INT                                             i = 0;
875
876         buffer = kmalloc(MAX_INI_BUFFER_SIZE, MEM_ALLOC_FLAG);
877         if(buffer == NULL)
878         return NDIS_STATUS_FAILURE;
879
880         tmpbuf = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
881         if(tmpbuf == NULL)
882         {
883                 kfree(buffer);
884         return NDIS_STATUS_FAILURE;
885         }
886
887         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
888                 src = STA_PROFILE_PATH;
889
890         // Save uid and gid used for filesystem access.
891         // Set user and group to 0 (root)
892         orgfsuid = current_fsuid();
893         orgfsgid = current_fsgid();
894         /* Hm, can't really do this nicely anymore, so rely on these files
895          * being set to the proper permission to read them... */
896         /* current->cred->fsuid = current->cred->fsgid = 0; */
897     orgfs = get_fs();
898     set_fs(KERNEL_DS);
899
900         if (src && *src)
901         {
902                 srcf = filp_open(src, O_RDONLY, 0);
903                 if (IS_ERR(srcf))
904                 {
905                         DBGPRINT(RT_DEBUG_ERROR, ("--> Error %ld opening %s\n", -PTR_ERR(srcf),src));
906                 }
907                 else
908                 {
909                         // The object must have a read method
910                         if (srcf->f_op && srcf->f_op->read)
911                         {
912                                 memset(buffer, 0x00, MAX_INI_BUFFER_SIZE);
913                                 retval=srcf->f_op->read(srcf, buffer, MAX_INI_BUFFER_SIZE, &srcf->f_pos);
914                                 if (retval < 0)
915                                 {
916                                         DBGPRINT(RT_DEBUG_TRACE, ("--> Read %s error %d\n", src, -retval));
917                                 }
918                                 else
919                                 {
920                                         // set file parameter to portcfg
921                                         //CountryRegion
922                                         if(RTMPGetKeyParameter("CountryRegion", tmpbuf, 25, buffer))
923                                         {
924                                                 pAd->CommonCfg.CountryRegion = (UCHAR) simple_strtol(tmpbuf, 0, 10);
925                                                 DBGPRINT(RT_DEBUG_TRACE, ("CountryRegion=%d\n", pAd->CommonCfg.CountryRegion));
926                                         }
927                                         //CountryRegionABand
928                                         if(RTMPGetKeyParameter("CountryRegionABand", tmpbuf, 25, buffer))
929                                         {
930                                                 pAd->CommonCfg.CountryRegionForABand= (UCHAR) simple_strtol(tmpbuf, 0, 10);
931                                                 DBGPRINT(RT_DEBUG_TRACE, ("CountryRegionABand=%d\n", pAd->CommonCfg.CountryRegionForABand));
932                                         }
933                                         //CountryCode
934                                         if(RTMPGetKeyParameter("CountryCode", tmpbuf, 25, buffer))
935                                         {
936                                                 NdisMoveMemory(pAd->CommonCfg.CountryCode, tmpbuf , 2);
937
938                                                 if (strlen(pAd->CommonCfg.CountryCode) != 0)
939                                                 {
940                                                         pAd->CommonCfg.bCountryFlag = TRUE;
941                                                 }
942                                                 DBGPRINT(RT_DEBUG_TRACE, ("CountryCode=%s\n", pAd->CommonCfg.CountryCode));
943                                         }
944                                         //ChannelGeography
945                                         if(RTMPGetKeyParameter("ChannelGeography", tmpbuf, 25, buffer))
946                                         {
947                                                 UCHAR Geography = (UCHAR) simple_strtol(tmpbuf, 0, 10);
948                                                 if (Geography <= BOTH)
949                                                 {
950                                                         pAd->CommonCfg.Geography = Geography;
951                                                         pAd->CommonCfg.CountryCode[2] =
952                                                                 (pAd->CommonCfg.Geography == BOTH) ? ' ' : ((pAd->CommonCfg.Geography == IDOR) ? 'I' : 'O');
953                                                         DBGPRINT(RT_DEBUG_TRACE, ("ChannelGeography=%d\n", pAd->CommonCfg.Geography));
954                                                 }
955                                         }
956                                         else
957                                         {
958                                                 pAd->CommonCfg.Geography = BOTH;
959                                                 pAd->CommonCfg.CountryCode[2] = ' ';
960                                         }
961
962                                         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
963                                         {
964                                                 //SSID
965                                                 if (RTMPGetCriticalParameter("SSID", tmpbuf, 256, buffer))
966                                                 {
967                                                         if (strlen(tmpbuf) <= 32)
968                                                         {
969                                                                 pAd->CommonCfg.SsidLen = (UCHAR) strlen(tmpbuf);
970                                                                 NdisZeroMemory(pAd->CommonCfg.Ssid, NDIS_802_11_LENGTH_SSID);
971                                                                 NdisMoveMemory(pAd->CommonCfg.Ssid, tmpbuf, pAd->CommonCfg.SsidLen);
972                                                                 pAd->MlmeAux.AutoReconnectSsidLen = pAd->CommonCfg.SsidLen;
973                                                                 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, NDIS_802_11_LENGTH_SSID);
974                                                                 NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, tmpbuf, pAd->MlmeAux.AutoReconnectSsidLen);
975                                                                 pAd->MlmeAux.SsidLen = pAd->CommonCfg.SsidLen;
976                                                                 NdisZeroMemory(pAd->MlmeAux.Ssid, NDIS_802_11_LENGTH_SSID);
977                                                                 NdisMoveMemory(pAd->MlmeAux.Ssid, tmpbuf, pAd->MlmeAux.SsidLen);
978                                                                 DBGPRINT(RT_DEBUG_TRACE, ("%s::(SSID=%s)\n", __func__, tmpbuf));
979                                                         }
980                                                 }
981                                         }
982
983                                         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
984                                         {
985                                                 //NetworkType
986                                                 if (RTMPGetKeyParameter("NetworkType", tmpbuf, 25, buffer))
987                                                 {
988                                                         pAd->bConfigChanged = TRUE;
989                                                         if (strcmp(tmpbuf, "Adhoc") == 0)
990                                                                 pAd->StaCfg.BssType = BSS_ADHOC;
991                                                         else //Default Infrastructure mode
992                                                                 pAd->StaCfg.BssType = BSS_INFRA;
993                                                         // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
994                                                         pAd->StaCfg.WpaState = SS_NOTUSE;
995                                                         DBGPRINT(RT_DEBUG_TRACE, ("%s::(NetworkType=%d)\n", __func__, pAd->StaCfg.BssType));
996                                                 }
997                                         }
998
999                                         //Channel
1000                                         if(RTMPGetKeyParameter("Channel", tmpbuf, 10, buffer))
1001                                         {
1002                                                 pAd->CommonCfg.Channel = (UCHAR) simple_strtol(tmpbuf, 0, 10);
1003                                                 DBGPRINT(RT_DEBUG_TRACE, ("Channel=%d\n", pAd->CommonCfg.Channel));
1004                                         }
1005                                         //WirelessMode
1006                                         if(RTMPGetKeyParameter("WirelessMode", tmpbuf, 10, buffer))
1007                                         {
1008                                                 int value  = 0, maxPhyMode = PHY_11G;
1009
1010                                                 maxPhyMode = PHY_11N_5G;
1011
1012                                                 value = simple_strtol(tmpbuf, 0, 10);
1013
1014                                                 if (value <= maxPhyMode)
1015                                                 {
1016                                                         pAd->CommonCfg.PhyMode = value;
1017                                                 }
1018                                                 DBGPRINT(RT_DEBUG_TRACE, ("PhyMode=%d\n", pAd->CommonCfg.PhyMode));
1019                                         }
1020                     //BasicRate
1021                                         if(RTMPGetKeyParameter("BasicRate", tmpbuf, 10, buffer))
1022                                         {
1023                                                 pAd->CommonCfg.BasicRateBitmap = (ULONG) simple_strtol(tmpbuf, 0, 10);
1024                                                 DBGPRINT(RT_DEBUG_TRACE, ("BasicRate=%ld\n", pAd->CommonCfg.BasicRateBitmap));
1025                                         }
1026                                         //BeaconPeriod
1027                                         if(RTMPGetKeyParameter("BeaconPeriod", tmpbuf, 10, buffer))
1028                                         {
1029                                                 pAd->CommonCfg.BeaconPeriod = (USHORT) simple_strtol(tmpbuf, 0, 10);
1030                                                 DBGPRINT(RT_DEBUG_TRACE, ("BeaconPeriod=%d\n", pAd->CommonCfg.BeaconPeriod));
1031                                         }
1032                     //TxPower
1033                                         if(RTMPGetKeyParameter("TxPower", tmpbuf, 10, buffer))
1034                                         {
1035                                                 pAd->CommonCfg.TxPowerPercentage = (ULONG) simple_strtol(tmpbuf, 0, 10);
1036
1037                                                 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1038                                                         pAd->CommonCfg.TxPowerDefault = pAd->CommonCfg.TxPowerPercentage;
1039
1040                                                 DBGPRINT(RT_DEBUG_TRACE, ("TxPower=%ld\n", pAd->CommonCfg.TxPowerPercentage));
1041                                         }
1042                                         //BGProtection
1043                                         if(RTMPGetKeyParameter("BGProtection", tmpbuf, 10, buffer))
1044                                         {
1045                                                 switch (simple_strtol(tmpbuf, 0, 10))
1046                                                 {
1047                                                         case 1: //Always On
1048                                                                 pAd->CommonCfg.UseBGProtection = 1;
1049                                                                 break;
1050                                                         case 2: //Always OFF
1051                                                                 pAd->CommonCfg.UseBGProtection = 2;
1052                                                                 break;
1053                                                         case 0: //AUTO
1054                                                         default:
1055                                                                 pAd->CommonCfg.UseBGProtection = 0;
1056                                                                 break;
1057                                                 }
1058                                                 DBGPRINT(RT_DEBUG_TRACE, ("BGProtection=%ld\n", pAd->CommonCfg.UseBGProtection));
1059                                         }
1060                                         //OLBCDetection
1061                                         if(RTMPGetKeyParameter("DisableOLBC", tmpbuf, 10, buffer))
1062                                         {
1063                                                 switch (simple_strtol(tmpbuf, 0, 10))
1064                                                 {
1065                                                         case 1: //disable OLBC Detection
1066                                                                 pAd->CommonCfg.DisableOLBCDetect = 1;
1067                                                                 break;
1068                                                         case 0: //enable OLBC Detection
1069                                                                 pAd->CommonCfg.DisableOLBCDetect = 0;
1070                                                                 break;
1071                                                         default:
1072                                                                 pAd->CommonCfg.DisableOLBCDetect= 0;
1073                                                                 break;
1074                                                 }
1075                                                 DBGPRINT(RT_DEBUG_TRACE, ("OLBCDetection=%ld\n", pAd->CommonCfg.DisableOLBCDetect));
1076                                         }
1077                                         //TxPreamble
1078                                         if(RTMPGetKeyParameter("TxPreamble", tmpbuf, 10, buffer))
1079                                         {
1080                                                 switch (simple_strtol(tmpbuf, 0, 10))
1081                                                 {
1082                                                         case Rt802_11PreambleShort:
1083                                                                 pAd->CommonCfg.TxPreamble = Rt802_11PreambleShort;
1084                                                                 break;
1085                                                         case Rt802_11PreambleLong:
1086                                                         default:
1087                                                                 pAd->CommonCfg.TxPreamble = Rt802_11PreambleLong;
1088                                                                 break;
1089                                                 }
1090                                                 DBGPRINT(RT_DEBUG_TRACE, ("TxPreamble=%ld\n", pAd->CommonCfg.TxPreamble));
1091                                         }
1092                                         //RTSThreshold
1093                                         if(RTMPGetKeyParameter("RTSThreshold", tmpbuf, 10, buffer))
1094                                         {
1095                                                 RtsThresh = simple_strtol(tmpbuf, 0, 10);
1096                                                 if( (RtsThresh >= 1) && (RtsThresh <= MAX_RTS_THRESHOLD) )
1097                                                         pAd->CommonCfg.RtsThreshold  = (USHORT)RtsThresh;
1098                                                 else
1099                                                         pAd->CommonCfg.RtsThreshold = MAX_RTS_THRESHOLD;
1100
1101                                                 DBGPRINT(RT_DEBUG_TRACE, ("RTSThreshold=%d\n", pAd->CommonCfg.RtsThreshold));
1102                                         }
1103                                         //FragThreshold
1104                                         if(RTMPGetKeyParameter("FragThreshold", tmpbuf, 10, buffer))
1105                                         {
1106                                                 FragThresh = simple_strtol(tmpbuf, 0, 10);
1107                                                 pAd->CommonCfg.bUseZeroToDisableFragment = FALSE;
1108
1109                                                 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
1110                                                 { //illegal FragThresh so we set it to default
1111                                                         pAd->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
1112                                                         pAd->CommonCfg.bUseZeroToDisableFragment = TRUE;
1113                                                 }
1114                                                 else if (FragThresh % 2 == 1)
1115                                                 {
1116                                                         // The length of each fragment shall always be an even number of octets, except for the last fragment
1117                                                         // of an MSDU or MMPDU, which may be either an even or an odd number of octets.
1118                                                         pAd->CommonCfg.FragmentThreshold = (USHORT)(FragThresh - 1);
1119                                                 }
1120                                                 else
1121                                                 {
1122                                                         pAd->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
1123                                                 }
1124                                                 //pAd->CommonCfg.AllowFragSize = (pAd->CommonCfg.FragmentThreshold) - LENGTH_802_11 - LENGTH_CRC;
1125                                                 DBGPRINT(RT_DEBUG_TRACE, ("FragThreshold=%d\n", pAd->CommonCfg.FragmentThreshold));
1126                                         }
1127                                         //TxBurst
1128                                         if(RTMPGetKeyParameter("TxBurst", tmpbuf, 10, buffer))
1129                                         {
1130 //#ifdef WIFI_TEST
1131 //                                              pAd->CommonCfg.bEnableTxBurst = FALSE;
1132 //#else
1133                                                 if(simple_strtol(tmpbuf, 0, 10) != 0)  //Enable
1134                                                         pAd->CommonCfg.bEnableTxBurst = TRUE;
1135                                                 else //Disable
1136                                                         pAd->CommonCfg.bEnableTxBurst = FALSE;
1137 //#endif
1138                                                 DBGPRINT(RT_DEBUG_TRACE, ("TxBurst=%d\n", pAd->CommonCfg.bEnableTxBurst));
1139                                         }
1140
1141 #ifdef AGGREGATION_SUPPORT
1142                                         //PktAggregate
1143                                         if(RTMPGetKeyParameter("PktAggregate", tmpbuf, 10, buffer))
1144                                         {
1145                                                 if(simple_strtol(tmpbuf, 0, 10) != 0)  //Enable
1146                                                         pAd->CommonCfg.bAggregationCapable = TRUE;
1147                                                 else //Disable
1148                                                         pAd->CommonCfg.bAggregationCapable = FALSE;
1149 #ifdef PIGGYBACK_SUPPORT
1150                                                 pAd->CommonCfg.bPiggyBackCapable = pAd->CommonCfg.bAggregationCapable;
1151 #endif // PIGGYBACK_SUPPORT //
1152                                                 DBGPRINT(RT_DEBUG_TRACE, ("PktAggregate=%d\n", pAd->CommonCfg.bAggregationCapable));
1153                                         }
1154 #else
1155                                         pAd->CommonCfg.bAggregationCapable = FALSE;
1156                                         pAd->CommonCfg.bPiggyBackCapable = FALSE;
1157 #endif // AGGREGATION_SUPPORT //
1158
1159                                         // WmmCapable
1160                                         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1161                                                 rtmp_read_sta_wmm_parms_from_file(pAd, tmpbuf, buffer);
1162
1163                                         //ShortSlot
1164                                         if(RTMPGetKeyParameter("ShortSlot", tmpbuf, 10, buffer))
1165                                         {
1166                                                 if(simple_strtol(tmpbuf, 0, 10) != 0)  //Enable
1167                                                         pAd->CommonCfg.bUseShortSlotTime = TRUE;
1168                                                 else //Disable
1169                                                         pAd->CommonCfg.bUseShortSlotTime = FALSE;
1170
1171                                                 DBGPRINT(RT_DEBUG_TRACE, ("ShortSlot=%d\n", pAd->CommonCfg.bUseShortSlotTime));
1172                                         }
1173                                         //IEEE80211H
1174                                         if(RTMPGetKeyParameter("IEEE80211H", tmpbuf, 10, buffer))
1175                                         {
1176                                             for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
1177                                             {
1178                                                 if(simple_strtol(macptr, 0, 10) != 0)  //Enable
1179                                                         pAd->CommonCfg.bIEEE80211H = TRUE;
1180                                                 else //Disable
1181                                                         pAd->CommonCfg.bIEEE80211H = FALSE;
1182
1183                                                 DBGPRINT(RT_DEBUG_TRACE, ("IEEE80211H=%d\n", pAd->CommonCfg.bIEEE80211H));
1184                                             }
1185                                         }
1186                                         //CSPeriod
1187                                         if(RTMPGetKeyParameter("CSPeriod", tmpbuf, 10, buffer))
1188                                         {
1189                                             if(simple_strtol(tmpbuf, 0, 10) != 0)
1190                                                         pAd->CommonCfg.RadarDetect.CSPeriod = simple_strtol(tmpbuf, 0, 10);
1191                                                 else
1192                                                         pAd->CommonCfg.RadarDetect.CSPeriod = 0;
1193
1194                                                 DBGPRINT(RT_DEBUG_TRACE, ("CSPeriod=%d\n", pAd->CommonCfg.RadarDetect.CSPeriod));
1195                                         }
1196
1197                                         //RDRegion
1198                                         if(RTMPGetKeyParameter("RDRegion", tmpbuf, 128, buffer))
1199                                         {
1200                                                 if ((strncmp(tmpbuf, "JAP_W53", 7) == 0) || (strncmp(tmpbuf, "jap_w53", 7) == 0))
1201                                                 {
1202                                                         pAd->CommonCfg.RadarDetect.RDDurRegion = JAP_W53;
1203                                                         pAd->CommonCfg.RadarDetect.DfsSessionTime = 15;
1204                                                 }
1205                                                 else if ((strncmp(tmpbuf, "JAP_W56", 7) == 0) || (strncmp(tmpbuf, "jap_w56", 7) == 0))
1206                                                 {
1207                                                         pAd->CommonCfg.RadarDetect.RDDurRegion = JAP_W56;
1208                                                         pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
1209                                                 }
1210                                                 else if ((strncmp(tmpbuf, "JAP", 3) == 0) || (strncmp(tmpbuf, "jap", 3) == 0))
1211                                                 {
1212                                                         pAd->CommonCfg.RadarDetect.RDDurRegion = JAP;
1213                                                         pAd->CommonCfg.RadarDetect.DfsSessionTime = 5;
1214                                                 }
1215                                                 else  if ((strncmp(tmpbuf, "FCC", 3) == 0) || (strncmp(tmpbuf, "fcc", 3) == 0))
1216                                                 {
1217                                                         pAd->CommonCfg.RadarDetect.RDDurRegion = FCC;
1218                                                         pAd->CommonCfg.RadarDetect.DfsSessionTime = 5;
1219                                                 }
1220                                                 else if ((strncmp(tmpbuf, "CE", 2) == 0) || (strncmp(tmpbuf, "ce", 2) == 0))
1221                                                 {
1222                                                         pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
1223                                                         pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
1224                                                 }
1225                                                 else
1226                                                 {
1227                                                         pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
1228                                                         pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
1229                                                 }
1230
1231                                                 DBGPRINT(RT_DEBUG_TRACE, ("RDRegion=%d\n", pAd->CommonCfg.RadarDetect.RDDurRegion));
1232                                         }
1233                                         else
1234                                         {
1235                                                 pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
1236                                                 pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
1237                                         }
1238
1239                                         //WirelessEvent
1240                                         if(RTMPGetKeyParameter("WirelessEvent", tmpbuf, 10, buffer))
1241                                         {
1242 #if WIRELESS_EXT >= 15
1243                                             if(simple_strtol(tmpbuf, 0, 10) != 0)
1244                                                         pAd->CommonCfg.bWirelessEvent = simple_strtol(tmpbuf, 0, 10);
1245                                                 else
1246                                                         pAd->CommonCfg.bWirelessEvent = 0;      // disable
1247 #else
1248                                                 pAd->CommonCfg.bWirelessEvent = 0;      // disable
1249 #endif
1250                                                 DBGPRINT(RT_DEBUG_TRACE, ("WirelessEvent=%d\n", pAd->CommonCfg.bWirelessEvent));
1251                                         }
1252                                         if(RTMPGetKeyParameter("WiFiTest", tmpbuf, 10, buffer))
1253                                         {
1254                                             if(simple_strtol(tmpbuf, 0, 10) != 0)
1255                                                         pAd->CommonCfg.bWiFiTest= simple_strtol(tmpbuf, 0, 10);
1256                                                 else
1257                                                         pAd->CommonCfg.bWiFiTest = 0;   // disable
1258
1259                                                 DBGPRINT(RT_DEBUG_TRACE, ("WiFiTest=%d\n", pAd->CommonCfg.bWiFiTest));
1260                                         }
1261                                         //AuthMode
1262                                         if(RTMPGetKeyParameter("AuthMode", tmpbuf, 128, buffer))
1263                                         {
1264                                                 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1265                                                 {
1266                                                         if ((strcmp(tmpbuf, "WEPAUTO") == 0) || (strcmp(tmpbuf, "wepauto") == 0))
1267                                                             pAd->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
1268                                                         else if ((strcmp(tmpbuf, "SHARED") == 0) || (strcmp(tmpbuf, "shared") == 0))
1269                                                             pAd->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1270                                                         else if ((strcmp(tmpbuf, "WPAPSK") == 0) || (strcmp(tmpbuf, "wpapsk") == 0))
1271                                                             pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
1272                                                         else if ((strcmp(tmpbuf, "WPANONE") == 0) || (strcmp(tmpbuf, "wpanone") == 0))
1273                                                             pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
1274                                                         else if ((strcmp(tmpbuf, "WPA2PSK") == 0) || (strcmp(tmpbuf, "wpa2psk") == 0))
1275                                                             pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
1276                                                         else if ((strcmp(tmpbuf, "WPA") == 0) || (strcmp(tmpbuf, "wpa") == 0))
1277                                                             pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
1278                                                         else if ((strcmp(tmpbuf, "WPA2") == 0) || (strcmp(tmpbuf, "wpa2") == 0))
1279                                                             pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
1280                                                         else
1281                                                             pAd->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1282
1283                                                         pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
1284
1285                                                         DBGPRINT(RT_DEBUG_TRACE, ("%s::(EncrypType=%d)\n", __func__, pAd->StaCfg.WepStatus));
1286                                                 }
1287                                         }
1288                                         //EncrypType
1289                                         if(RTMPGetKeyParameter("EncrypType", tmpbuf, 128, buffer))
1290                                         {
1291                                                 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1292                                                 {
1293                                                         if ((strcmp(tmpbuf, "WEP") == 0) || (strcmp(tmpbuf, "wep") == 0))
1294                                                                 pAd->StaCfg.WepStatus   = Ndis802_11WEPEnabled;
1295                                                         else if ((strcmp(tmpbuf, "TKIP") == 0) || (strcmp(tmpbuf, "tkip") == 0))
1296                                                                 pAd->StaCfg.WepStatus   = Ndis802_11Encryption2Enabled;
1297                                                         else if ((strcmp(tmpbuf, "AES") == 0) || (strcmp(tmpbuf, "aes") == 0))
1298                                                                 pAd->StaCfg.WepStatus   = Ndis802_11Encryption3Enabled;
1299                                                         else
1300                                                                 pAd->StaCfg.WepStatus   = Ndis802_11WEPDisabled;
1301
1302                                                         // Update all wepstatus related
1303                                                         pAd->StaCfg.PairCipher          = pAd->StaCfg.WepStatus;
1304                                                         pAd->StaCfg.GroupCipher         = pAd->StaCfg.WepStatus;
1305                                                         pAd->StaCfg.OrigWepStatus       = pAd->StaCfg.WepStatus;
1306                                                         pAd->StaCfg.bMixCipher          = FALSE;
1307
1308                                                         //RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0);
1309                                                         DBGPRINT(RT_DEBUG_TRACE, ("%s::(EncrypType=%d)\n", __func__, pAd->StaCfg.WepStatus));
1310                                                 }
1311                                         }
1312
1313                                         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1314                                         {
1315                                                 if(RTMPGetCriticalParameter("WPAPSK", tmpbuf, 512, buffer))
1316                                                 {
1317                                                         int     err=0;
1318
1319                                                         tmpbuf[strlen(tmpbuf)] = '\0'; // make STA can process .$^& for WPAPSK input
1320
1321                                                         if ((pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
1322                                                                 (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
1323                                                                 (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
1324                                                                 )
1325                                                         {
1326                                                                 err = 1;
1327                                                         }
1328                                                         else if ((strlen(tmpbuf) >= 8) && (strlen(tmpbuf) < 64))
1329                                                         {
1330                                                                 PasswordHash((char *)tmpbuf, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, keyMaterial);
1331                                                                 NdisMoveMemory(pAd->StaCfg.PMK, keyMaterial, 32);
1332
1333                                                         }
1334                                                         else if (strlen(tmpbuf) == 64)
1335                                                         {
1336                                                                 AtoH(tmpbuf, keyMaterial, 32);
1337                                                                 NdisMoveMemory(pAd->StaCfg.PMK, keyMaterial, 32);
1338                                                         }
1339                                                         else
1340                                                         {
1341                                                                 err = 1;
1342                                                                 DBGPRINT(RT_DEBUG_ERROR, ("%s::(WPAPSK key-string required 8 ~ 64 characters!)\n", __func__));
1343                                                         }
1344
1345                                                         if (err == 0)
1346                                                         {
1347                                                                 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
1348                                                                         (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
1349                                                                 {
1350                                                                         // Start STA supplicant state machine
1351                                                                         pAd->StaCfg.WpaState = SS_START;
1352                                                                 }
1353                                                                 else if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
1354                                                                 {
1355         /*
1356                                                                         NdisZeroMemory(&pAd->SharedKey[BSS0][0], sizeof(CIPHER_KEY));
1357                                                                         pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK;
1358                                                                         NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, pAd->StaCfg.PMK, LEN_TKIP_EK);
1359                                                                         NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_RXMICK);
1360                                                                         NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, &pAd->StaCfg.PMK[16], LEN_TKIP_TXMICK);
1361
1362                                                                         // Decide its ChiperAlg
1363                                                                         if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled)
1364                                                                                 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP;
1365                                                                         else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled)
1366                                                                                 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES;
1367                                                                         else
1368                                                                                 pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE;
1369         */
1370                                                                         pAd->StaCfg.WpaState = SS_NOTUSE;
1371                                                                 }
1372
1373                                                                 DBGPRINT(RT_DEBUG_TRACE, ("%s::(WPAPSK=%s)\n", __func__, tmpbuf));
1374                                                         }
1375                                                 }
1376                                         }
1377
1378                                         //DefaultKeyID, KeyType, KeyStr
1379                                         rtmp_read_key_parms_from_file(pAd, tmpbuf, buffer);
1380
1381
1382                                         //HSCounter
1383                                         /*if(RTMPGetKeyParameter("HSCounter", tmpbuf, 10, buffer))
1384                                         {
1385                                                 switch (simple_strtol(tmpbuf, 0, 10))
1386                                                 {
1387                                                         case 1: //Enable
1388                                                                 pAd->CommonCfg.bEnableHSCounter = TRUE;
1389                                                                 break;
1390                                                         case 0: //Disable
1391                                                         default:
1392                                                                 pAd->CommonCfg.bEnableHSCounter = FALSE;
1393                                                                 break;
1394                                                 }
1395                                                 DBGPRINT(RT_DEBUG_TRACE, "HSCounter=%d\n", pAd->CommonCfg.bEnableHSCounter);
1396                                         }*/
1397
1398                                         HTParametersHook(pAd, tmpbuf, buffer);
1399
1400                                         IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1401                                         {
1402                                                 //PSMode
1403                                                 if (RTMPGetKeyParameter("PSMode", tmpbuf, 10, buffer))
1404                                                 {
1405                                                         if (pAd->StaCfg.BssType == BSS_INFRA)
1406                                                         {
1407                                                                 if ((strcmp(tmpbuf, "MAX_PSP") == 0) || (strcmp(tmpbuf, "max_psp") == 0))
1408                                                                 {
1409                                                                         // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1410                                                                         // to exclude certain situations.
1411                                                                         //         MlmeSetPsm(pAd, PWR_SAVE);
1412                                                                         OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1413                                                                         if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1414                                                                                 pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
1415                                                                         pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
1416                                                                         pAd->StaCfg.DefaultListenCount = 5;
1417                                                                 }
1418                                                                 else if ((strcmp(tmpbuf, "Fast_PSP") == 0) || (strcmp(tmpbuf, "fast_psp") == 0)
1419                                                                         || (strcmp(tmpbuf, "FAST_PSP") == 0))
1420                                                                 {
1421                                                                         // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1422                                                                         // to exclude certain situations.
1423                                                                         //         MlmeSetPsmBit(pAd, PWR_SAVE);
1424                                                                         OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1425                                                                         if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1426                                                                                 pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
1427                                                                         pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
1428                                                                         pAd->StaCfg.DefaultListenCount = 3;
1429                                                                 }
1430                                                                 else if ((strcmp(tmpbuf, "Legacy_PSP") == 0) || (strcmp(tmpbuf, "legacy_psp") == 0)
1431                                                                         || (strcmp(tmpbuf, "LEGACY_PSP") == 0))
1432                                                                 {
1433                                                                         // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1434                                                                         // to exclude certain situations.
1435                                                                         //         MlmeSetPsmBit(pAd, PWR_SAVE);
1436                                                                         OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1437                                                                         if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1438                                                                                 pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
1439                                                                         pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
1440                                                                         pAd->StaCfg.DefaultListenCount = 3;
1441                                                                 }
1442                                                                 else
1443                                                                 { //Default Ndis802_11PowerModeCAM
1444                                                                         // clear PSM bit immediately
1445                                                                         MlmeSetPsmBit(pAd, PWR_ACTIVE);
1446                                                                         OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1447                                                                         if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1448                                                                                 pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
1449                                                                         pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
1450                                                                 }
1451                                                                 DBGPRINT(RT_DEBUG_TRACE, ("PSMode=%ld\n", pAd->StaCfg.WindowsPowerMode));
1452                                                         }
1453                                                 }
1454                                                 // FastRoaming
1455                                                 if (RTMPGetKeyParameter("FastRoaming", tmpbuf, 32, buffer))
1456                                                 {
1457                                                         if (simple_strtol(tmpbuf, 0, 10) == 0)
1458                                                                 pAd->StaCfg.bFastRoaming = FALSE;
1459                                                         else
1460                                                                 pAd->StaCfg.bFastRoaming = TRUE;
1461
1462                                                         DBGPRINT(RT_DEBUG_TRACE, ("FastRoaming=%d\n", pAd->StaCfg.bFastRoaming));
1463                                                 }
1464                                                 // RoamThreshold
1465                                                 if (RTMPGetKeyParameter("RoamThreshold", tmpbuf, 32, buffer))
1466                                                 {
1467                                                         long lInfo = simple_strtol(tmpbuf, 0, 10);
1468
1469                                                         if (lInfo > 90 || lInfo < 60)
1470                                                                 pAd->StaCfg.dBmToRoam = -70;
1471                                                         else
1472                                                                 pAd->StaCfg.dBmToRoam = (CHAR)(-1)*lInfo;
1473
1474                                                         DBGPRINT(RT_DEBUG_TRACE, ("RoamThreshold=%d  dBm\n", pAd->StaCfg.dBmToRoam));
1475                                                 }
1476
1477                                                 if(RTMPGetKeyParameter("TGnWifiTest", tmpbuf, 10, buffer))
1478                                                 {
1479                                                         if(simple_strtol(tmpbuf, 0, 10) == 0)
1480                                                                 pAd->StaCfg.bTGnWifiTest = FALSE;
1481                                                         else
1482                                                                 pAd->StaCfg.bTGnWifiTest = TRUE;
1483                                                                 DBGPRINT(RT_DEBUG_TRACE, ("TGnWifiTest=%d\n", pAd->StaCfg.bTGnWifiTest));
1484                                                 }
1485                                         }
1486                                 }
1487                         }
1488                         else
1489                         {
1490                                 DBGPRINT(RT_DEBUG_TRACE, ("--> %s does not have a write method\n", src));
1491                         }
1492
1493                         retval=filp_close(srcf,NULL);
1494
1495                         if (retval)
1496                         {
1497                                 DBGPRINT(RT_DEBUG_TRACE, ("--> Error %d closing %s\n", -retval, src));
1498                         }
1499                 }
1500         }
1501
1502         set_fs(orgfs);
1503 #if 0
1504         current->fsuid = orgfsuid;
1505         current->fsgid = orgfsgid;
1506 #endif
1507
1508         kfree(buffer);
1509         kfree(tmpbuf);
1510
1511         return (NDIS_STATUS_SUCCESS);
1512 }
1513
1514 static void     HTParametersHook(
1515         IN      PRTMP_ADAPTER pAd,
1516         IN      CHAR              *pValueStr,
1517         IN      CHAR              *pInput)
1518 {
1519
1520         INT Value;
1521
1522     if (RTMPGetKeyParameter("HT_PROTECT", pValueStr, 25, pInput))
1523     {
1524         Value = simple_strtol(pValueStr, 0, 10);
1525         if (Value == 0)
1526         {
1527             pAd->CommonCfg.bHTProtect = FALSE;
1528         }
1529         else
1530         {
1531             pAd->CommonCfg.bHTProtect = TRUE;
1532         }
1533         DBGPRINT(RT_DEBUG_TRACE, ("HT: Protection  = %s\n", (Value==0) ? "Disable" : "Enable"));
1534     }
1535
1536     if (RTMPGetKeyParameter("HT_MIMOPSEnable", pValueStr, 25, pInput))
1537     {
1538         Value = simple_strtol(pValueStr, 0, 10);
1539         if (Value == 0)
1540         {
1541             pAd->CommonCfg.bMIMOPSEnable = FALSE;
1542         }
1543         else
1544         {
1545             pAd->CommonCfg.bMIMOPSEnable = TRUE;
1546         }
1547         DBGPRINT(RT_DEBUG_TRACE, ("HT: MIMOPSEnable  = %s\n", (Value==0) ? "Disable" : "Enable"));
1548     }
1549
1550
1551     if (RTMPGetKeyParameter("HT_MIMOPSMode", pValueStr, 25, pInput))
1552     {
1553         Value = simple_strtol(pValueStr, 0, 10);
1554         if (Value > MMPS_ENABLE)
1555         {
1556                         pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
1557         }
1558         else
1559         {
1560             //TODO: add mimo power saving mechanism
1561             pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
1562                         //pAd->CommonCfg.BACapability.field.MMPSmode = Value;
1563         }
1564         DBGPRINT(RT_DEBUG_TRACE, ("HT: MIMOPS Mode  = %d\n", Value));
1565     }
1566
1567     if (RTMPGetKeyParameter("HT_BADecline", pValueStr, 25, pInput))
1568     {
1569         Value = simple_strtol(pValueStr, 0, 10);
1570         if (Value == 0)
1571         {
1572             pAd->CommonCfg.bBADecline = FALSE;
1573         }
1574         else
1575         {
1576             pAd->CommonCfg.bBADecline = TRUE;
1577         }
1578         DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Decline  = %s\n", (Value==0) ? "Disable" : "Enable"));
1579     }
1580
1581
1582     if (RTMPGetKeyParameter("HT_DisableReordering", pValueStr, 25, pInput))
1583     {
1584         Value = simple_strtol(pValueStr, 0, 10);
1585         if (Value == 0)
1586         {
1587             pAd->CommonCfg.bDisableReordering = FALSE;
1588         }
1589         else
1590         {
1591             pAd->CommonCfg.bDisableReordering = TRUE;
1592         }
1593         DBGPRINT(RT_DEBUG_TRACE, ("HT: DisableReordering  = %s\n", (Value==0) ? "Disable" : "Enable"));
1594     }
1595
1596     if (RTMPGetKeyParameter("HT_AutoBA", pValueStr, 25, pInput))
1597     {
1598         Value = simple_strtol(pValueStr, 0, 10);
1599         if (Value == 0)
1600         {
1601             pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
1602         }
1603         else
1604         {
1605             pAd->CommonCfg.BACapability.field.AutoBA = TRUE;
1606         }
1607         pAd->CommonCfg.REGBACapability.field.AutoBA = pAd->CommonCfg.BACapability.field.AutoBA;
1608         DBGPRINT(RT_DEBUG_TRACE, ("HT: Auto BA  = %s\n", (Value==0) ? "Disable" : "Enable"));
1609     }
1610
1611         // Tx_+HTC frame
1612     if (RTMPGetKeyParameter("HT_HTC", pValueStr, 25, pInput))
1613         {
1614                 Value = simple_strtol(pValueStr, 0, 10);
1615                 if (Value == 0)
1616                 {
1617                         pAd->HTCEnable = FALSE;
1618                 }
1619                 else
1620                 {
1621                         pAd->HTCEnable = TRUE;
1622                 }
1623                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx +HTC frame = %s\n", (Value==0) ? "Disable" : "Enable"));
1624         }
1625
1626         // Enable HT Link Adaptation Control
1627         if (RTMPGetKeyParameter("HT_LinkAdapt", pValueStr, 25, pInput))
1628         {
1629                 Value = simple_strtol(pValueStr, 0, 10);
1630                 if (Value == 0)
1631                 {
1632                         pAd->bLinkAdapt = FALSE;
1633                 }
1634                 else
1635                 {
1636                         pAd->HTCEnable = TRUE;
1637                         pAd->bLinkAdapt = TRUE;
1638                 }
1639                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Link Adaptation Control = %s\n", (Value==0) ? "Disable" : "Enable(+HTC)"));
1640         }
1641
1642         // Reverse Direction Mechanism
1643     if (RTMPGetKeyParameter("HT_RDG", pValueStr, 25, pInput))
1644         {
1645                 Value = simple_strtol(pValueStr, 0, 10);
1646                 if (Value == 0)
1647                 {
1648                         pAd->CommonCfg.bRdg = FALSE;
1649                 }
1650                 else
1651                 {
1652                         pAd->HTCEnable = TRUE;
1653             pAd->CommonCfg.bRdg = TRUE;
1654                 }
1655                 DBGPRINT(RT_DEBUG_TRACE, ("HT: RDG = %s\n", (Value==0) ? "Disable" : "Enable(+HTC)"));
1656         }
1657
1658
1659
1660
1661         // Tx A-MSUD ?
1662     if (RTMPGetKeyParameter("HT_AMSDU", pValueStr, 25, pInput))
1663         {
1664                 Value = simple_strtol(pValueStr, 0, 10);
1665                 if (Value == 0)
1666                 {
1667                         pAd->CommonCfg.BACapability.field.AmsduEnable = FALSE;
1668                 }
1669                 else
1670                 {
1671             pAd->CommonCfg.BACapability.field.AmsduEnable = TRUE;
1672                 }
1673                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx A-MSDU = %s\n", (Value==0) ? "Disable" : "Enable"));
1674         }
1675
1676         // MPDU Density
1677     if (RTMPGetKeyParameter("HT_MpduDensity", pValueStr, 25, pInput))
1678         {
1679                 Value = simple_strtol(pValueStr, 0, 10);
1680                 if (Value <=7 && Value >= 0)
1681                 {
1682                         pAd->CommonCfg.BACapability.field.MpduDensity = Value;
1683                         DBGPRINT(RT_DEBUG_TRACE, ("HT: MPDU Density = %d\n", Value));
1684                 }
1685                 else
1686                 {
1687                         pAd->CommonCfg.BACapability.field.MpduDensity = 4;
1688                         DBGPRINT(RT_DEBUG_TRACE, ("HT: MPDU Density = %d (Default)\n", 4));
1689                 }
1690         }
1691
1692         // Max Rx BA Window Size
1693     if (RTMPGetKeyParameter("HT_BAWinSize", pValueStr, 25, pInput))
1694         {
1695                 Value = simple_strtol(pValueStr, 0, 10);
1696
1697                 if (Value >=1 && Value <= 64)
1698                 {
1699                         pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = Value;
1700                         pAd->CommonCfg.BACapability.field.RxBAWinLimit = Value;
1701                         DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Windw Size = %d\n", Value));
1702                 }
1703                 else
1704                 {
1705             pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = 64;
1706                         pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64;
1707                         DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Windw Size = 64 (Defualt)\n"));
1708                 }
1709
1710         }
1711
1712         // Guard Interval
1713         if (RTMPGetKeyParameter("HT_GI", pValueStr, 25, pInput))
1714         {
1715                 Value = simple_strtol(pValueStr, 0, 10);
1716
1717                 if (Value == GI_400)
1718                 {
1719                         pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_400;
1720                 }
1721                 else
1722                 {
1723                         pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_800;
1724                 }
1725
1726                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Guard Interval = %s\n", (Value==GI_400) ? "400" : "800" ));
1727         }
1728
1729         // HT Operation Mode : Mixed Mode , Green Field
1730         if (RTMPGetKeyParameter("HT_OpMode", pValueStr, 25, pInput))
1731         {
1732                 Value = simple_strtol(pValueStr, 0, 10);
1733
1734                 if (Value == HTMODE_GF)
1735                 {
1736
1737                         pAd->CommonCfg.RegTransmitSetting.field.HTMODE  = HTMODE_GF;
1738                 }
1739                 else
1740                 {
1741                         pAd->CommonCfg.RegTransmitSetting.field.HTMODE  = HTMODE_MM;
1742                 }
1743
1744                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Operate Mode = %s\n", (Value==HTMODE_GF) ? "Green Field" : "Mixed Mode" ));
1745         }
1746
1747         // Fixed Tx mode : CCK, OFDM
1748         if (RTMPGetKeyParameter("FixedTxMode", pValueStr, 25, pInput))
1749         {
1750                 UCHAR   fix_tx_mode;
1751
1752                 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1753                 {
1754                         fix_tx_mode = FIXED_TXMODE_HT;
1755
1756                         if (strcmp(pValueStr, "OFDM") == 0 || strcmp(pValueStr, "ofdm") == 0)
1757                         {
1758                                 fix_tx_mode = FIXED_TXMODE_OFDM;
1759                         }
1760                         else if (strcmp(pValueStr, "CCK") == 0 || strcmp(pValueStr, "cck") == 0)
1761                         {
1762                         fix_tx_mode = FIXED_TXMODE_CCK;
1763                         }
1764                         else if (strcmp(pValueStr, "HT") == 0 || strcmp(pValueStr, "ht") == 0)
1765                         {
1766                         fix_tx_mode = FIXED_TXMODE_HT;
1767                 }
1768                 else
1769                 {
1770                                 Value = simple_strtol(pValueStr, 0, 10);
1771                                 // 1 : CCK
1772                                 // 2 : OFDM
1773                                 // otherwise : HT
1774                                 if (Value == FIXED_TXMODE_CCK || Value == FIXED_TXMODE_OFDM)
1775                                         fix_tx_mode = Value;
1776                                 else
1777                                         fix_tx_mode = FIXED_TXMODE_HT;
1778                 }
1779
1780                         pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode = fix_tx_mode;
1781                         DBGPRINT(RT_DEBUG_TRACE, ("Fixed Tx Mode = %d\n", fix_tx_mode));
1782
1783                 }
1784         }
1785
1786
1787         // Channel Width
1788         if (RTMPGetKeyParameter("HT_BW", pValueStr, 25, pInput))
1789         {
1790                 Value = simple_strtol(pValueStr, 0, 10);
1791
1792                 if (Value == BW_40)
1793                 {
1794                         pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_40;
1795                 }
1796                 else
1797                 {
1798             pAd->CommonCfg.RegTransmitSetting.field.BW  = BW_20;
1799                 }
1800
1801 #ifdef MCAST_RATE_SPECIFIC
1802                 pAd->CommonCfg.MCastPhyMode.field.BW = pAd->CommonCfg.RegTransmitSetting.field.BW;
1803 #endif // MCAST_RATE_SPECIFIC //
1804
1805                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Channel Width = %s\n", (Value==BW_40) ? "40 MHz" : "20 MHz" ));
1806         }
1807
1808         if (RTMPGetKeyParameter("HT_EXTCHA", pValueStr, 25, pInput))
1809         {
1810                 Value = simple_strtol(pValueStr, 0, 10);
1811
1812                 if (Value == 0)
1813                 {
1814
1815                         pAd->CommonCfg.RegTransmitSetting.field.EXTCHA  = EXTCHA_BELOW;
1816                 }
1817                 else
1818                 {
1819             pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
1820                 }
1821
1822                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Ext Channel = %s\n", (Value==0) ? "BELOW" : "ABOVE" ));
1823         }
1824
1825         // MSC
1826         if (RTMPGetKeyParameter("HT_MCS", pValueStr, 50, pInput))
1827         {
1828                 IF_DEV_CONFIG_OPMODE_ON_STA(pAd)
1829                 {
1830                         Value = simple_strtol(pValueStr, 0, 10);
1831
1832 //                      if ((Value >= 0 && Value <= 15) || (Value == 32))
1833                         if ((Value >= 0 && Value <= 23) || (Value == 32)) // 3*3
1834                 {
1835                                 pAd->StaCfg.DesiredTransmitSetting.field.MCS  = Value;
1836                                 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
1837                                 DBGPRINT(RT_DEBUG_TRACE, ("HT: MCS = %d\n", pAd->StaCfg.DesiredTransmitSetting.field.MCS));
1838                 }
1839                 else
1840                 {
1841                                 pAd->StaCfg.DesiredTransmitSetting.field.MCS  = MCS_AUTO;
1842                                 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
1843                                 DBGPRINT(RT_DEBUG_TRACE, ("HT: MCS = AUTO\n"));
1844                 }
1845         }
1846         }
1847
1848         // STBC
1849     if (RTMPGetKeyParameter("HT_STBC", pValueStr, 25, pInput))
1850         {
1851                 Value = simple_strtol(pValueStr, 0, 10);
1852                 if (Value == STBC_USE)
1853                 {
1854                         pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_USE;
1855                 }
1856                 else
1857                 {
1858                         pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_NONE;
1859                 }
1860                 DBGPRINT(RT_DEBUG_TRACE, ("HT: STBC = %d\n", pAd->CommonCfg.RegTransmitSetting.field.STBC));
1861         }
1862
1863         // 40_Mhz_Intolerant
1864         if (RTMPGetKeyParameter("HT_40MHZ_INTOLERANT", pValueStr, 25, pInput))
1865         {
1866                 Value = simple_strtol(pValueStr, 0, 10);
1867                 if (Value == 0)
1868                 {
1869                         pAd->CommonCfg.bForty_Mhz_Intolerant = FALSE;
1870                 }
1871                 else
1872                 {
1873                         pAd->CommonCfg.bForty_Mhz_Intolerant = TRUE;
1874                 }
1875                 DBGPRINT(RT_DEBUG_TRACE, ("HT: 40MHZ INTOLERANT = %d\n", pAd->CommonCfg.bForty_Mhz_Intolerant));
1876         }
1877         //HT_TxStream
1878         if(RTMPGetKeyParameter("HT_TxStream", pValueStr, 10, pInput))
1879         {
1880                 switch (simple_strtol(pValueStr, 0, 10))
1881                 {
1882                         case 1:
1883                                 pAd->CommonCfg.TxStream = 1;
1884                                 break;
1885                         case 2:
1886                                 pAd->CommonCfg.TxStream = 2;
1887                                 break;
1888                         case 3: // 3*3
1889                         default:
1890                                 pAd->CommonCfg.TxStream = 3;
1891
1892                                 if (pAd->MACVersion < RALINK_2883_VERSION)
1893                                         pAd->CommonCfg.TxStream = 2; // only 2 tx streams for RT2860 series
1894                                 break;
1895                 }
1896                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx Stream = %d\n", pAd->CommonCfg.TxStream));
1897         }
1898         //HT_RxStream
1899         if(RTMPGetKeyParameter("HT_RxStream", pValueStr, 10, pInput))
1900         {
1901                 switch (simple_strtol(pValueStr, 0, 10))
1902                 {
1903                         case 1:
1904                                 pAd->CommonCfg.RxStream = 1;
1905                                 break;
1906                         case 2:
1907                                 pAd->CommonCfg.RxStream = 2;
1908                                 break;
1909                         case 3:
1910                         default:
1911                                 pAd->CommonCfg.RxStream = 3;
1912
1913                                 if (pAd->MACVersion < RALINK_2883_VERSION)
1914                                         pAd->CommonCfg.RxStream = 2; // only 2 rx streams for RT2860 series
1915                                 break;
1916                 }
1917                 DBGPRINT(RT_DEBUG_TRACE, ("HT: Rx Stream = %d\n", pAd->CommonCfg.RxStream));
1918         }
1919
1920 }