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