OMAP2/3: PM: shared pm.c
[linux-ginger.git] / drivers / staging / rt2860 / rt_profile.c
blob3bc41f83f624ce0a2d176d08b3eb4fd86f9e5ae4
1 /*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
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 *************************************************************************
28 #include "rt_config.h"
30 static void HTParametersHook(
31 IN PRTMP_ADAPTER pAd,
32 IN CHAR *pValueStr,
33 IN CHAR *pInput);
35 #define ETH_MAC_ADDR_STR_LEN 17 // in format of xx:xx:xx:xx:xx:xx
37 // We assume the s1 is a sting, s2 is a memory space with 6 bytes. and content of s1 will be changed.
38 BOOLEAN rtstrmactohex(char *s1, char *s2)
40 int i = 0;
41 char *ptokS = s1, *ptokE = s1;
43 if (strlen(s1) != ETH_MAC_ADDR_STR_LEN)
44 return FALSE;
46 while((*ptokS) != '\0')
48 if((ptokE = strchr(ptokS, ':')) != NULL)
49 *ptokE++ = '\0';
50 if ((strlen(ptokS) != 2) || (!isxdigit(*ptokS)) || (!isxdigit(*(ptokS+1))))
51 break; // fail
52 AtoH(ptokS, &s2[i++], 1);
53 ptokS = ptokE;
54 if (i == 6)
55 break; // parsing finished
58 return ( i == 6 ? TRUE : FALSE);
63 // we assume the s1 and s2 both are strings.
64 BOOLEAN rtstrcasecmp(char *s1, char *s2)
66 char *p1 = s1, *p2 = s2;
68 if (strlen(s1) != strlen(s2))
69 return FALSE;
71 while(*p1 != '\0')
73 if((*p1 != *p2) && ((*p1 ^ *p2) != 0x20))
74 return FALSE;
75 p1++;
76 p2++;
79 return TRUE;
82 // we assume the s1 (buffer) and s2 (key) both are strings.
83 char * rtstrstruncasecmp(char * s1, char * s2)
85 INT l1, l2, i;
86 char temp1, temp2;
88 l2 = strlen(s2);
89 if (!l2)
90 return (char *) s1;
92 l1 = strlen(s1);
94 while (l1 >= l2)
96 l1--;
98 for(i=0; i<l2; i++)
100 temp1 = *(s1+i);
101 temp2 = *(s2+i);
103 if (('a' <= temp1) && (temp1 <= 'z'))
104 temp1 = 'A'+(temp1-'a');
105 if (('a' <= temp2) && (temp2 <= 'z'))
106 temp2 = 'A'+(temp2-'a');
108 if (temp1 != temp2)
109 break;
112 if (i == l2)
113 return (char *) s1;
115 s1++;
118 return NULL; // not found
121 //add by kathy
124 * strstr - Find the first substring in a %NUL terminated string
125 * @s1: The string to be searched
126 * @s2: The string to search for
128 char * rtstrstr(const char * s1,const char * s2)
130 INT l1, l2;
132 l2 = strlen(s2);
133 if (!l2)
134 return (char *) s1;
136 l1 = strlen(s1);
138 while (l1 >= l2)
140 l1--;
141 if (!memcmp(s1,s2,l2))
142 return (char *) s1;
143 s1++;
146 return NULL;
150 * rstrtok - Split a string into tokens
151 * @s: The string to be searched
152 * @ct: The characters to search for
153 * * WARNING: strtok is deprecated, use strsep instead. However strsep is not compatible with old architecture.
155 char * __rstrtok;
156 char * rstrtok(char * s,const char * ct)
158 char *sbegin, *send;
160 sbegin = s ? s : __rstrtok;
161 if (!sbegin)
163 return NULL;
166 sbegin += strspn(sbegin,ct);
167 if (*sbegin == '\0')
169 __rstrtok = NULL;
170 return( NULL );
173 send = strpbrk( sbegin, ct);
174 if (send && *send != '\0')
175 *send++ = '\0';
177 __rstrtok = send;
179 return (sbegin);
183 * delimitcnt - return the count of a given delimiter in a given string.
184 * @s: The string to be searched.
185 * @ct: The delimiter to search for.
186 * Notice : We suppose the delimiter is a single-char string(for example : ";").
188 INT delimitcnt(char * s,const char * ct)
190 INT count = 0;
191 /* point to the beginning of the line */
192 const char *token = s;
194 for ( ;; )
196 token = strpbrk(token, ct); /* search for delimiters */
198 if ( token == NULL )
200 /* advanced to the terminating null character */
201 break;
203 /* skip the delimiter */
204 ++token;
207 * Print the found text: use len with %.*s to specify field width.
210 /* accumulate delimiter count */
211 ++count;
213 return count;
217 * converts the Internet host address from the standard numbers-and-dots notation
218 * into binary data.
219 * returns nonzero if the address is valid, zero if not.
221 int rtinet_aton(const char *cp, unsigned int *addr)
223 unsigned int val;
224 int base, n;
225 char c;
226 unsigned int parts[4];
227 unsigned int *pp = parts;
229 for (;;)
232 * Collect number up to ``.''.
233 * Values are specified as for C:
234 * 0x=hex, 0=octal, other=decimal.
236 val = 0;
237 base = 10;
238 if (*cp == '0')
240 if (*++cp == 'x' || *cp == 'X')
241 base = 16, cp++;
242 else
243 base = 8;
245 while ((c = *cp) != '\0')
247 if (isdigit((unsigned char) c))
249 val = (val * base) + (c - '0');
250 cp++;
251 continue;
253 if (base == 16 && isxdigit((unsigned char) c))
255 val = (val << 4) +
256 (c + 10 - (islower((unsigned char) c) ? 'a' : 'A'));
257 cp++;
258 continue;
260 break;
262 if (*cp == '.')
265 * Internet format: a.b.c.d a.b.c (with c treated as 16-bits)
266 * a.b (with b treated as 24 bits)
268 if (pp >= parts + 3 || val > 0xff)
269 return 0;
270 *pp++ = val, cp++;
272 else
273 break;
277 * Check for trailing junk.
279 while (*cp)
280 if (!isspace((unsigned char) *cp++))
281 return 0;
284 * Concoct the address according to the number of parts specified.
286 n = pp - parts + 1;
287 switch (n)
290 case 1: /* a -- 32 bits */
291 break;
293 case 2: /* a.b -- 8.24 bits */
294 if (val > 0xffffff)
295 return 0;
296 val |= parts[0] << 24;
297 break;
299 case 3: /* a.b.c -- 8.8.16 bits */
300 if (val > 0xffff)
301 return 0;
302 val |= (parts[0] << 24) | (parts[1] << 16);
303 break;
305 case 4: /* a.b.c.d -- 8.8.8.8 bits */
306 if (val > 0xff)
307 return 0;
308 val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
309 break;
312 *addr = htonl(val);
313 return 1;
318 ========================================================================
320 Routine Description:
321 Find key section for Get key parameter.
323 Arguments:
324 buffer Pointer to the buffer to start find the key section
325 section the key of the secion to be find
327 Return Value:
328 NULL Fail
329 Others Success
330 ========================================================================
332 PUCHAR RTMPFindSection(
333 IN PCHAR buffer)
335 CHAR temp_buf[32];
336 PUCHAR ptr;
338 strcpy(temp_buf, "Default");
340 if((ptr = rtstrstr(buffer, temp_buf)) != NULL)
341 return (ptr+strlen("\n"));
342 else
343 return NULL;
347 ========================================================================
349 Routine Description:
350 Get key parameter.
352 Arguments:
353 key Pointer to key string
354 dest Pointer to destination
355 destsize The datasize of the destination
356 buffer Pointer to the buffer to start find the key
358 Return Value:
359 TRUE Success
360 FALSE Fail
362 Note:
363 This routine get the value with the matched key (case case-sensitive)
364 ========================================================================
366 INT RTMPGetKeyParameter(
367 IN PCHAR key,
368 OUT PCHAR dest,
369 IN INT destsize,
370 IN PCHAR buffer)
372 UCHAR *temp_buf1 = NULL;
373 UCHAR *temp_buf2 = NULL;
374 CHAR *start_ptr;
375 CHAR *end_ptr;
376 CHAR *ptr;
377 CHAR *offset = 0;
378 INT len;
380 //temp_buf1 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
381 os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);
383 if(temp_buf1 == NULL)
384 return (FALSE);
386 //temp_buf2 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
387 os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE);
388 if(temp_buf2 == NULL)
390 os_free_mem(NULL, temp_buf1);
391 return (FALSE);
394 //find section
395 if((offset = RTMPFindSection(buffer)) == NULL)
397 os_free_mem(NULL, temp_buf1);
398 os_free_mem(NULL, temp_buf2);
399 return (FALSE);
402 strcpy(temp_buf1, "\n");
403 strcat(temp_buf1, key);
404 strcat(temp_buf1, "=");
406 //search key
407 if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
409 os_free_mem(NULL, temp_buf1);
410 os_free_mem(NULL, temp_buf2);
411 return (FALSE);
414 start_ptr+=strlen("\n");
415 if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
416 end_ptr=start_ptr+strlen(start_ptr);
418 if (end_ptr<start_ptr)
420 os_free_mem(NULL, temp_buf1);
421 os_free_mem(NULL, temp_buf2);
422 return (FALSE);
425 NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
426 temp_buf2[end_ptr-start_ptr]='\0';
427 len = strlen(temp_buf2);
428 strcpy(temp_buf1, temp_buf2);
429 if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
431 os_free_mem(NULL, temp_buf1);
432 os_free_mem(NULL, temp_buf2);
433 return (FALSE);
436 strcpy(temp_buf2, start_ptr+1);
437 ptr = temp_buf2;
438 //trim space or tab
439 while(*ptr != 0x00)
441 if( (*ptr == ' ') || (*ptr == '\t') )
442 ptr++;
443 else
444 break;
447 len = strlen(ptr);
448 memset(dest, 0x00, destsize);
449 strncpy(dest, ptr, len >= destsize ? destsize: len);
451 os_free_mem(NULL, temp_buf1);
452 os_free_mem(NULL, temp_buf2);
453 return TRUE;
457 ========================================================================
459 Routine Description:
460 Get key parameter.
462 Arguments:
463 key Pointer to key string
464 dest Pointer to destination
465 destsize The datasize of the destination
466 buffer Pointer to the buffer to start find the key
468 Return Value:
469 TRUE Success
470 FALSE Fail
472 Note:
473 This routine get the value with the matched key (case case-sensitive).
474 It is called for parsing SSID and any key string.
475 ========================================================================
477 INT RTMPGetCriticalParameter(
478 IN PCHAR key,
479 OUT PCHAR dest,
480 IN INT destsize,
481 IN PCHAR buffer)
483 UCHAR *temp_buf1 = NULL;
484 UCHAR *temp_buf2 = NULL;
485 CHAR *start_ptr;
486 CHAR *end_ptr;
487 CHAR *ptr;
488 CHAR *offset = 0;
489 INT len;
491 //temp_buf1 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
492 os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);
494 if(temp_buf1 == NULL)
495 return (FALSE);
497 //temp_buf2 = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
498 os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE);
499 if(temp_buf2 == NULL)
501 os_free_mem(NULL, temp_buf1);
502 return (FALSE);
505 //find section
506 if((offset = RTMPFindSection(buffer)) == NULL)
508 os_free_mem(NULL, temp_buf1);
509 os_free_mem(NULL, temp_buf2);
510 return (FALSE);
513 strcpy(temp_buf1, "\n");
514 strcat(temp_buf1, key);
515 strcat(temp_buf1, "=");
517 //search key
518 if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
520 os_free_mem(NULL, temp_buf1);
521 os_free_mem(NULL, temp_buf2);
522 return (FALSE);
525 start_ptr+=strlen("\n");
526 if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
527 end_ptr=start_ptr+strlen(start_ptr);
529 if (end_ptr<start_ptr)
531 os_free_mem(NULL, temp_buf1);
532 os_free_mem(NULL, temp_buf2);
533 return (FALSE);
536 NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
537 temp_buf2[end_ptr-start_ptr]='\0';
538 len = strlen(temp_buf2);
539 strcpy(temp_buf1, temp_buf2);
540 if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
542 os_free_mem(NULL, temp_buf1);
543 os_free_mem(NULL, temp_buf2);
544 return (FALSE);
547 strcpy(temp_buf2, start_ptr+1);
548 ptr = temp_buf2;
550 //trim tab
551 /* We cannot trim space(' ') for SSID and key string. */
552 while(*ptr != 0x00)
554 //if( (*ptr == ' ') || (*ptr == '\t') )
555 if( (*ptr == '\t') )
556 ptr++;
557 else
558 break;
561 len = strlen(ptr);
562 memset(dest, 0x00, destsize);
563 strncpy(dest, ptr, len >= destsize ? destsize: len);
565 os_free_mem(NULL, temp_buf1);
566 os_free_mem(NULL, temp_buf2);
567 return TRUE;
571 ========================================================================
573 Routine Description:
574 Get multiple key parameter.
576 Arguments:
577 key Pointer to key string
578 dest Pointer to destination
579 destsize The datasize of the destination
580 buffer Pointer to the buffer to start find the key
582 Return Value:
583 TRUE Success
584 FALSE Fail
586 Note:
587 This routine get the value with the matched key (case case-sensitive)
588 ========================================================================
590 INT RTMPGetKeyParameterWithOffset(
591 IN PCHAR key,
592 OUT PCHAR dest,
593 OUT USHORT *end_offset,
594 IN INT destsize,
595 IN PCHAR buffer,
596 IN BOOLEAN bTrimSpace)
598 UCHAR *temp_buf1 = NULL;
599 UCHAR *temp_buf2 = NULL;
600 CHAR *start_ptr;
601 CHAR *end_ptr;
602 CHAR *ptr;
603 CHAR *offset = 0;
604 INT len;
606 if (*end_offset >= MAX_INI_BUFFER_SIZE)
607 return (FALSE);
609 os_alloc_mem(NULL, &temp_buf1, MAX_PARAM_BUFFER_SIZE);
611 if(temp_buf1 == NULL)
612 return (FALSE);
614 os_alloc_mem(NULL, &temp_buf2, MAX_PARAM_BUFFER_SIZE);
615 if(temp_buf2 == NULL)
617 os_free_mem(NULL, temp_buf1);
618 return (FALSE);
621 //find section
622 if(*end_offset == 0)
624 if ((offset = RTMPFindSection(buffer)) == NULL)
626 os_free_mem(NULL, temp_buf1);
627 os_free_mem(NULL, temp_buf2);
628 return (FALSE);
631 else
632 offset = buffer + (*end_offset);
634 strcpy(temp_buf1, "\n");
635 strcat(temp_buf1, key);
636 strcat(temp_buf1, "=");
638 //search key
639 if((start_ptr=rtstrstr(offset, temp_buf1))==NULL)
641 os_free_mem(NULL, temp_buf1);
642 os_free_mem(NULL, temp_buf2);
643 return (FALSE);
646 start_ptr+=strlen("\n");
647 if((end_ptr=rtstrstr(start_ptr, "\n"))==NULL)
648 end_ptr=start_ptr+strlen(start_ptr);
650 if (end_ptr<start_ptr)
652 os_free_mem(NULL, temp_buf1);
653 os_free_mem(NULL, temp_buf2);
654 return (FALSE);
657 *end_offset = end_ptr - buffer;
659 NdisMoveMemory(temp_buf2, start_ptr, end_ptr-start_ptr);
660 temp_buf2[end_ptr-start_ptr]='\0';
661 len = strlen(temp_buf2);
662 strcpy(temp_buf1, temp_buf2);
663 if((start_ptr=rtstrstr(temp_buf1, "=")) == NULL)
665 os_free_mem(NULL, temp_buf1);
666 os_free_mem(NULL, temp_buf2);
667 return (FALSE);
670 strcpy(temp_buf2, start_ptr+1);
671 ptr = temp_buf2;
672 //trim space or tab
673 while(*ptr != 0x00)
675 if((bTrimSpace && (*ptr == ' ')) || (*ptr == '\t') )
676 ptr++;
677 else
678 break;
681 len = strlen(ptr);
682 memset(dest, 0x00, destsize);
683 strncpy(dest, ptr, len >= destsize ? destsize: len);
685 os_free_mem(NULL, temp_buf1);
686 os_free_mem(NULL, temp_buf2);
687 return TRUE;
691 static int rtmp_parse_key_buffer_from_file(IN PRTMP_ADAPTER pAd,IN char *buffer,IN ULONG KeyType,IN INT BSSIdx,IN INT KeyIdx)
693 PUCHAR keybuff;
694 INT i = BSSIdx, idx = KeyIdx;
695 ULONG KeyLen;
696 UCHAR CipherAlg = CIPHER_WEP64;
698 keybuff = buffer;
699 KeyLen = strlen(keybuff);
701 if (KeyType == 1)
702 {//Ascii
703 if( (KeyLen == 5) || (KeyLen == 13))
705 pAd->SharedKey[i][idx].KeyLen = KeyLen;
706 NdisMoveMemory(pAd->SharedKey[i][idx].Key, keybuff, KeyLen);
707 if (KeyLen == 5)
708 CipherAlg = CIPHER_WEP64;
709 else
710 CipherAlg = CIPHER_WEP128;
711 pAd->SharedKey[i][idx].CipherAlg = CipherAlg;
713 DBGPRINT(RT_DEBUG_TRACE, ("I/F(wlan%d) Key%dStr=%s and type=%s\n", i, idx+1, keybuff, (KeyType == 0) ? "Hex":"Ascii"));
714 return 1;
716 else
717 {//Invalid key length
718 DBGPRINT(RT_DEBUG_ERROR, ("Key%dStr is Invalid key length! KeyLen = %ld!\n", idx+1, KeyLen));
719 return 0;
722 else
723 {//Hex type
724 if( (KeyLen == 10) || (KeyLen == 26))
726 pAd->SharedKey[i][idx].KeyLen = KeyLen / 2;
727 AtoH(keybuff, pAd->SharedKey[i][idx].Key, KeyLen / 2);
728 if (KeyLen == 10)
729 CipherAlg = CIPHER_WEP64;
730 else
731 CipherAlg = CIPHER_WEP128;
732 pAd->SharedKey[i][idx].CipherAlg = CipherAlg;
734 DBGPRINT(RT_DEBUG_TRACE, ("I/F(wlan%d) Key%dStr=%s and type=%s\n", i, idx+1, keybuff, (KeyType == 0) ? "Hex":"Ascii"));
735 return 1;
737 else
738 {//Invalid key length
739 DBGPRINT(RT_DEBUG_ERROR, ("I/F(wlan%d) Key%dStr is Invalid key length! KeyLen = %ld!\n", i, idx+1, KeyLen));
740 return 0;
744 static void rtmp_read_key_parms_from_file(IN PRTMP_ADAPTER pAd, char *tmpbuf, char *buffer)
746 char tok_str[16];
747 PUCHAR macptr;
748 INT i = 0, idx;
749 ULONG KeyType[MAX_MBSSID_NUM];
750 ULONG KeyIdx;
752 NdisZeroMemory(KeyType, MAX_MBSSID_NUM);
754 //DefaultKeyID
755 if(RTMPGetKeyParameter("DefaultKeyID", tmpbuf, 25, buffer))
758 KeyIdx = simple_strtol(tmpbuf, 0, 10);
759 if((KeyIdx >= 1 ) && (KeyIdx <= 4))
760 pAd->StaCfg.DefaultKeyId = (UCHAR) (KeyIdx - 1);
761 else
762 pAd->StaCfg.DefaultKeyId = 0;
764 DBGPRINT(RT_DEBUG_TRACE, ("DefaultKeyID(0~3)=%d\n", pAd->StaCfg.DefaultKeyId));
769 for (idx = 0; idx < 4; idx++)
771 sprintf(tok_str, "Key%dType", idx + 1);
772 //Key1Type
773 if (RTMPGetKeyParameter(tok_str, tmpbuf, 128, buffer))
775 for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
777 KeyType[i] = simple_strtol(macptr, 0, 10);
781 sprintf(tok_str, "Key%dStr", idx + 1);
782 if (RTMPGetCriticalParameter(tok_str, tmpbuf, 128, buffer))
784 rtmp_parse_key_buffer_from_file(pAd, tmpbuf, KeyType[BSS0], BSS0, idx);
791 static void rtmp_read_sta_wmm_parms_from_file(IN PRTMP_ADAPTER pAd, char *tmpbuf, char *buffer)
793 PUCHAR macptr;
794 INT i=0;
795 BOOLEAN bWmmEnable = FALSE;
797 //WmmCapable
798 if(RTMPGetKeyParameter("WmmCapable", tmpbuf, 32, buffer))
800 if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
802 pAd->CommonCfg.bWmmCapable = TRUE;
803 bWmmEnable = TRUE;
805 else //Disable
807 pAd->CommonCfg.bWmmCapable = FALSE;
810 DBGPRINT(RT_DEBUG_TRACE, ("WmmCapable=%d\n", pAd->CommonCfg.bWmmCapable));
813 //AckPolicy for AC_BK, AC_BE, AC_VI, AC_VO
814 if(RTMPGetKeyParameter("AckPolicy", tmpbuf, 32, buffer))
816 for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
818 pAd->CommonCfg.AckPolicy[i] = (UCHAR)simple_strtol(macptr, 0, 10);
820 DBGPRINT(RT_DEBUG_TRACE, ("AckPolicy[%d]=%d\n", i, pAd->CommonCfg.AckPolicy[i]));
824 if (bWmmEnable)
826 //APSDCapable
827 if(RTMPGetKeyParameter("APSDCapable", tmpbuf, 10, buffer))
829 if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
830 pAd->CommonCfg.bAPSDCapable = TRUE;
831 else
832 pAd->CommonCfg.bAPSDCapable = FALSE;
834 DBGPRINT(RT_DEBUG_TRACE, ("APSDCapable=%d\n", pAd->CommonCfg.bAPSDCapable));
837 //APSDAC for AC_BE, AC_BK, AC_VI, AC_VO
838 if(RTMPGetKeyParameter("APSDAC", tmpbuf, 32, buffer))
840 BOOLEAN apsd_ac[4];
842 for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
844 apsd_ac[i] = (BOOLEAN)simple_strtol(macptr, 0, 10);
846 DBGPRINT(RT_DEBUG_TRACE, ("APSDAC%d %d\n", i, apsd_ac[i]));
849 pAd->CommonCfg.bAPSDAC_BE = apsd_ac[0];
850 pAd->CommonCfg.bAPSDAC_BK = apsd_ac[1];
851 pAd->CommonCfg.bAPSDAC_VI = apsd_ac[2];
852 pAd->CommonCfg.bAPSDAC_VO = apsd_ac[3];
858 NDIS_STATUS RTMPReadParametersHook(
859 IN PRTMP_ADAPTER pAd)
861 PUCHAR src = NULL;
862 struct file *srcf;
863 INT retval;
864 mm_segment_t orgfs;
865 CHAR *buffer;
866 CHAR *tmpbuf;
867 ULONG RtsThresh;
868 ULONG FragThresh;
869 UCHAR keyMaterial[40];
871 PUCHAR macptr;
872 INT i = 0;
874 buffer = kmalloc(MAX_INI_BUFFER_SIZE, MEM_ALLOC_FLAG);
875 if(buffer == NULL)
876 return NDIS_STATUS_FAILURE;
878 tmpbuf = kmalloc(MAX_PARAM_BUFFER_SIZE, MEM_ALLOC_FLAG);
879 if(tmpbuf == NULL)
881 kfree(buffer);
882 return NDIS_STATUS_FAILURE;
885 src = STA_PROFILE_PATH;
887 orgfs = get_fs();
888 set_fs(KERNEL_DS);
890 if (src && *src)
892 srcf = filp_open(src, O_RDONLY, 0);
893 if (IS_ERR(srcf))
895 DBGPRINT(RT_DEBUG_ERROR, ("--> Error %ld opening %s\n", -PTR_ERR(srcf),src));
897 else
899 // The object must have a read method
900 if (srcf->f_op && srcf->f_op->read)
902 memset(buffer, 0x00, MAX_INI_BUFFER_SIZE);
903 retval=srcf->f_op->read(srcf, buffer, MAX_INI_BUFFER_SIZE, &srcf->f_pos);
904 if (retval < 0)
906 DBGPRINT(RT_DEBUG_TRACE, ("--> Read %s error %d\n", src, -retval));
908 else
910 // set file parameter to portcfg
911 //CountryRegion
912 if(RTMPGetKeyParameter("CountryRegion", tmpbuf, 25, buffer))
914 pAd->CommonCfg.CountryRegion = (UCHAR) simple_strtol(tmpbuf, 0, 10);
915 DBGPRINT(RT_DEBUG_TRACE, ("CountryRegion=%d\n", pAd->CommonCfg.CountryRegion));
917 //CountryRegionABand
918 if(RTMPGetKeyParameter("CountryRegionABand", tmpbuf, 25, buffer))
920 pAd->CommonCfg.CountryRegionForABand= (UCHAR) simple_strtol(tmpbuf, 0, 10);
921 DBGPRINT(RT_DEBUG_TRACE, ("CountryRegionABand=%d\n", pAd->CommonCfg.CountryRegionForABand));
923 //CountryCode
924 if(RTMPGetKeyParameter("CountryCode", tmpbuf, 25, buffer))
926 NdisMoveMemory(pAd->CommonCfg.CountryCode, tmpbuf , 2);
928 if (strlen(pAd->CommonCfg.CountryCode) != 0)
930 pAd->CommonCfg.bCountryFlag = TRUE;
932 DBGPRINT(RT_DEBUG_TRACE, ("CountryCode=%s\n", pAd->CommonCfg.CountryCode));
934 //ChannelGeography
935 if(RTMPGetKeyParameter("ChannelGeography", tmpbuf, 25, buffer))
937 UCHAR Geography = (UCHAR) simple_strtol(tmpbuf, 0, 10);
938 if (Geography <= BOTH)
940 pAd->CommonCfg.Geography = Geography;
941 pAd->CommonCfg.CountryCode[2] =
942 (pAd->CommonCfg.Geography == BOTH) ? ' ' : ((pAd->CommonCfg.Geography == IDOR) ? 'I' : 'O');
943 DBGPRINT(RT_DEBUG_TRACE, ("ChannelGeography=%d\n", pAd->CommonCfg.Geography));
946 else
948 pAd->CommonCfg.Geography = BOTH;
949 pAd->CommonCfg.CountryCode[2] = ' ';
953 //SSID
954 if (RTMPGetCriticalParameter("SSID", tmpbuf, 256, buffer))
956 if (strlen(tmpbuf) <= 32)
958 pAd->CommonCfg.SsidLen = (UCHAR) strlen(tmpbuf);
959 NdisZeroMemory(pAd->CommonCfg.Ssid, NDIS_802_11_LENGTH_SSID);
960 NdisMoveMemory(pAd->CommonCfg.Ssid, tmpbuf, pAd->CommonCfg.SsidLen);
961 pAd->MlmeAux.AutoReconnectSsidLen = pAd->CommonCfg.SsidLen;
962 NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, NDIS_802_11_LENGTH_SSID);
963 NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, tmpbuf, pAd->MlmeAux.AutoReconnectSsidLen);
964 pAd->MlmeAux.SsidLen = pAd->CommonCfg.SsidLen;
965 NdisZeroMemory(pAd->MlmeAux.Ssid, NDIS_802_11_LENGTH_SSID);
966 NdisMoveMemory(pAd->MlmeAux.Ssid, tmpbuf, pAd->MlmeAux.SsidLen);
967 DBGPRINT(RT_DEBUG_TRACE, ("%s::(SSID=%s)\n", __func__, tmpbuf));
973 //NetworkType
974 if (RTMPGetKeyParameter("NetworkType", tmpbuf, 25, buffer))
976 pAd->bConfigChanged = TRUE;
977 if (strcmp(tmpbuf, "Adhoc") == 0)
978 pAd->StaCfg.BssType = BSS_ADHOC;
979 else //Default Infrastructure mode
980 pAd->StaCfg.BssType = BSS_INFRA;
981 // Reset Ralink supplicant to not use, it will be set to start when UI set PMK key
982 pAd->StaCfg.WpaState = SS_NOTUSE;
983 DBGPRINT(RT_DEBUG_TRACE, ("%s::(NetworkType=%d)\n", __func__, pAd->StaCfg.BssType));
987 //Channel
988 if(RTMPGetKeyParameter("Channel", tmpbuf, 10, buffer))
990 pAd->CommonCfg.Channel = (UCHAR) simple_strtol(tmpbuf, 0, 10);
991 DBGPRINT(RT_DEBUG_TRACE, ("Channel=%d\n", pAd->CommonCfg.Channel));
993 //WirelessMode
994 if(RTMPGetKeyParameter("WirelessMode", tmpbuf, 10, buffer))
996 int value = 0, maxPhyMode = PHY_11G;
998 maxPhyMode = PHY_11N_5G;
1000 value = simple_strtol(tmpbuf, 0, 10);
1002 if (value <= maxPhyMode)
1004 pAd->CommonCfg.PhyMode = value;
1006 DBGPRINT(RT_DEBUG_TRACE, ("PhyMode=%d\n", pAd->CommonCfg.PhyMode));
1008 //BasicRate
1009 if(RTMPGetKeyParameter("BasicRate", tmpbuf, 10, buffer))
1011 pAd->CommonCfg.BasicRateBitmap = (ULONG) simple_strtol(tmpbuf, 0, 10);
1012 DBGPRINT(RT_DEBUG_TRACE, ("BasicRate=%ld\n", pAd->CommonCfg.BasicRateBitmap));
1014 //BeaconPeriod
1015 if(RTMPGetKeyParameter("BeaconPeriod", tmpbuf, 10, buffer))
1017 pAd->CommonCfg.BeaconPeriod = (USHORT) simple_strtol(tmpbuf, 0, 10);
1018 DBGPRINT(RT_DEBUG_TRACE, ("BeaconPeriod=%d\n", pAd->CommonCfg.BeaconPeriod));
1020 //TxPower
1021 if(RTMPGetKeyParameter("TxPower", tmpbuf, 10, buffer))
1023 pAd->CommonCfg.TxPowerPercentage = (ULONG) simple_strtol(tmpbuf, 0, 10);
1025 pAd->CommonCfg.TxPowerDefault = pAd->CommonCfg.TxPowerPercentage;
1027 DBGPRINT(RT_DEBUG_TRACE, ("TxPower=%ld\n", pAd->CommonCfg.TxPowerPercentage));
1029 //BGProtection
1030 if(RTMPGetKeyParameter("BGProtection", tmpbuf, 10, buffer))
1032 switch (simple_strtol(tmpbuf, 0, 10))
1034 case 1: //Always On
1035 pAd->CommonCfg.UseBGProtection = 1;
1036 break;
1037 case 2: //Always OFF
1038 pAd->CommonCfg.UseBGProtection = 2;
1039 break;
1040 case 0: //AUTO
1041 default:
1042 pAd->CommonCfg.UseBGProtection = 0;
1043 break;
1045 DBGPRINT(RT_DEBUG_TRACE, ("BGProtection=%ld\n", pAd->CommonCfg.UseBGProtection));
1047 //OLBCDetection
1048 if(RTMPGetKeyParameter("DisableOLBC", tmpbuf, 10, buffer))
1050 switch (simple_strtol(tmpbuf, 0, 10))
1052 case 1: //disable OLBC Detection
1053 pAd->CommonCfg.DisableOLBCDetect = 1;
1054 break;
1055 case 0: //enable OLBC Detection
1056 pAd->CommonCfg.DisableOLBCDetect = 0;
1057 break;
1058 default:
1059 pAd->CommonCfg.DisableOLBCDetect= 0;
1060 break;
1062 DBGPRINT(RT_DEBUG_TRACE, ("OLBCDetection=%ld\n", pAd->CommonCfg.DisableOLBCDetect));
1064 //TxPreamble
1065 if(RTMPGetKeyParameter("TxPreamble", tmpbuf, 10, buffer))
1067 switch (simple_strtol(tmpbuf, 0, 10))
1069 case Rt802_11PreambleShort:
1070 pAd->CommonCfg.TxPreamble = Rt802_11PreambleShort;
1071 break;
1072 case Rt802_11PreambleLong:
1073 default:
1074 pAd->CommonCfg.TxPreamble = Rt802_11PreambleLong;
1075 break;
1077 DBGPRINT(RT_DEBUG_TRACE, ("TxPreamble=%ld\n", pAd->CommonCfg.TxPreamble));
1079 //RTSThreshold
1080 if(RTMPGetKeyParameter("RTSThreshold", tmpbuf, 10, buffer))
1082 RtsThresh = simple_strtol(tmpbuf, 0, 10);
1083 if( (RtsThresh >= 1) && (RtsThresh <= MAX_RTS_THRESHOLD) )
1084 pAd->CommonCfg.RtsThreshold = (USHORT)RtsThresh;
1085 else
1086 pAd->CommonCfg.RtsThreshold = MAX_RTS_THRESHOLD;
1088 DBGPRINT(RT_DEBUG_TRACE, ("RTSThreshold=%d\n", pAd->CommonCfg.RtsThreshold));
1090 //FragThreshold
1091 if(RTMPGetKeyParameter("FragThreshold", tmpbuf, 10, buffer))
1093 FragThresh = simple_strtol(tmpbuf, 0, 10);
1094 pAd->CommonCfg.bUseZeroToDisableFragment = FALSE;
1096 if (FragThresh > MAX_FRAG_THRESHOLD || FragThresh < MIN_FRAG_THRESHOLD)
1097 { //illegal FragThresh so we set it to default
1098 pAd->CommonCfg.FragmentThreshold = MAX_FRAG_THRESHOLD;
1099 pAd->CommonCfg.bUseZeroToDisableFragment = TRUE;
1101 else if (FragThresh % 2 == 1)
1103 // The length of each fragment shall always be an even number of octets, except for the last fragment
1104 // of an MSDU or MMPDU, which may be either an even or an odd number of octets.
1105 pAd->CommonCfg.FragmentThreshold = (USHORT)(FragThresh - 1);
1107 else
1109 pAd->CommonCfg.FragmentThreshold = (USHORT)FragThresh;
1111 //pAd->CommonCfg.AllowFragSize = (pAd->CommonCfg.FragmentThreshold) - LENGTH_802_11 - LENGTH_CRC;
1112 DBGPRINT(RT_DEBUG_TRACE, ("FragThreshold=%d\n", pAd->CommonCfg.FragmentThreshold));
1114 //TxBurst
1115 if(RTMPGetKeyParameter("TxBurst", tmpbuf, 10, buffer))
1117 if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
1118 pAd->CommonCfg.bEnableTxBurst = TRUE;
1119 else //Disable
1120 pAd->CommonCfg.bEnableTxBurst = FALSE;
1121 DBGPRINT(RT_DEBUG_TRACE, ("TxBurst=%d\n", pAd->CommonCfg.bEnableTxBurst));
1124 #ifdef AGGREGATION_SUPPORT
1125 //PktAggregate
1126 if(RTMPGetKeyParameter("PktAggregate", tmpbuf, 10, buffer))
1128 if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
1129 pAd->CommonCfg.bAggregationCapable = TRUE;
1130 else //Disable
1131 pAd->CommonCfg.bAggregationCapable = FALSE;
1132 #ifdef PIGGYBACK_SUPPORT
1133 pAd->CommonCfg.bPiggyBackCapable = pAd->CommonCfg.bAggregationCapable;
1134 #endif // PIGGYBACK_SUPPORT //
1135 DBGPRINT(RT_DEBUG_TRACE, ("PktAggregate=%d\n", pAd->CommonCfg.bAggregationCapable));
1137 #else
1138 pAd->CommonCfg.bAggregationCapable = FALSE;
1139 pAd->CommonCfg.bPiggyBackCapable = FALSE;
1140 #endif // AGGREGATION_SUPPORT //
1142 // WmmCapable
1143 rtmp_read_sta_wmm_parms_from_file(pAd, tmpbuf, buffer);
1145 //ShortSlot
1146 if(RTMPGetKeyParameter("ShortSlot", tmpbuf, 10, buffer))
1148 if(simple_strtol(tmpbuf, 0, 10) != 0) //Enable
1149 pAd->CommonCfg.bUseShortSlotTime = TRUE;
1150 else //Disable
1151 pAd->CommonCfg.bUseShortSlotTime = FALSE;
1153 DBGPRINT(RT_DEBUG_TRACE, ("ShortSlot=%d\n", pAd->CommonCfg.bUseShortSlotTime));
1155 //IEEE80211H
1156 if(RTMPGetKeyParameter("IEEE80211H", tmpbuf, 10, buffer))
1158 for (i = 0, macptr = rstrtok(tmpbuf,";"); macptr; macptr = rstrtok(NULL,";"), i++)
1160 if(simple_strtol(macptr, 0, 10) != 0) //Enable
1161 pAd->CommonCfg.bIEEE80211H = TRUE;
1162 else //Disable
1163 pAd->CommonCfg.bIEEE80211H = FALSE;
1165 DBGPRINT(RT_DEBUG_TRACE, ("IEEE80211H=%d\n", pAd->CommonCfg.bIEEE80211H));
1168 //CSPeriod
1169 if(RTMPGetKeyParameter("CSPeriod", tmpbuf, 10, buffer))
1171 if(simple_strtol(tmpbuf, 0, 10) != 0)
1172 pAd->CommonCfg.RadarDetect.CSPeriod = simple_strtol(tmpbuf, 0, 10);
1173 else
1174 pAd->CommonCfg.RadarDetect.CSPeriod = 0;
1176 DBGPRINT(RT_DEBUG_TRACE, ("CSPeriod=%d\n", pAd->CommonCfg.RadarDetect.CSPeriod));
1179 //RDRegion
1180 if(RTMPGetKeyParameter("RDRegion", tmpbuf, 128, buffer))
1182 if ((strncmp(tmpbuf, "JAP_W53", 7) == 0) || (strncmp(tmpbuf, "jap_w53", 7) == 0))
1184 pAd->CommonCfg.RadarDetect.RDDurRegion = JAP_W53;
1185 pAd->CommonCfg.RadarDetect.DfsSessionTime = 15;
1187 else if ((strncmp(tmpbuf, "JAP_W56", 7) == 0) || (strncmp(tmpbuf, "jap_w56", 7) == 0))
1189 pAd->CommonCfg.RadarDetect.RDDurRegion = JAP_W56;
1190 pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
1192 else if ((strncmp(tmpbuf, "JAP", 3) == 0) || (strncmp(tmpbuf, "jap", 3) == 0))
1194 pAd->CommonCfg.RadarDetect.RDDurRegion = JAP;
1195 pAd->CommonCfg.RadarDetect.DfsSessionTime = 5;
1197 else if ((strncmp(tmpbuf, "FCC", 3) == 0) || (strncmp(tmpbuf, "fcc", 3) == 0))
1199 pAd->CommonCfg.RadarDetect.RDDurRegion = FCC;
1200 pAd->CommonCfg.RadarDetect.DfsSessionTime = 5;
1202 else if ((strncmp(tmpbuf, "CE", 2) == 0) || (strncmp(tmpbuf, "ce", 2) == 0))
1204 pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
1205 pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
1207 else
1209 pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
1210 pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
1213 DBGPRINT(RT_DEBUG_TRACE, ("RDRegion=%d\n", pAd->CommonCfg.RadarDetect.RDDurRegion));
1215 else
1217 pAd->CommonCfg.RadarDetect.RDDurRegion = CE;
1218 pAd->CommonCfg.RadarDetect.DfsSessionTime = 13;
1221 //WirelessEvent
1222 if(RTMPGetKeyParameter("WirelessEvent", tmpbuf, 10, buffer))
1224 if(simple_strtol(tmpbuf, 0, 10) != 0)
1225 pAd->CommonCfg.bWirelessEvent = simple_strtol(tmpbuf, 0, 10);
1226 else
1227 pAd->CommonCfg.bWirelessEvent = 0; // disable
1228 DBGPRINT(RT_DEBUG_TRACE, ("WirelessEvent=%d\n", pAd->CommonCfg.bWirelessEvent));
1230 if(RTMPGetKeyParameter("WiFiTest", tmpbuf, 10, buffer))
1232 if(simple_strtol(tmpbuf, 0, 10) != 0)
1233 pAd->CommonCfg.bWiFiTest= simple_strtol(tmpbuf, 0, 10);
1234 else
1235 pAd->CommonCfg.bWiFiTest = 0; // disable
1237 DBGPRINT(RT_DEBUG_TRACE, ("WiFiTest=%d\n", pAd->CommonCfg.bWiFiTest));
1239 //AuthMode
1240 if(RTMPGetKeyParameter("AuthMode", tmpbuf, 128, buffer))
1243 if ((strcmp(tmpbuf, "WEPAUTO") == 0) || (strcmp(tmpbuf, "wepauto") == 0))
1244 pAd->StaCfg.AuthMode = Ndis802_11AuthModeAutoSwitch;
1245 else if ((strcmp(tmpbuf, "SHARED") == 0) || (strcmp(tmpbuf, "shared") == 0))
1246 pAd->StaCfg.AuthMode = Ndis802_11AuthModeShared;
1247 else if ((strcmp(tmpbuf, "WPAPSK") == 0) || (strcmp(tmpbuf, "wpapsk") == 0))
1248 pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK;
1249 else if ((strcmp(tmpbuf, "WPANONE") == 0) || (strcmp(tmpbuf, "wpanone") == 0))
1250 pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPANone;
1251 else if ((strcmp(tmpbuf, "WPA2PSK") == 0) || (strcmp(tmpbuf, "wpa2psk") == 0))
1252 pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK;
1253 else if ((strcmp(tmpbuf, "WPA") == 0) || (strcmp(tmpbuf, "wpa") == 0))
1254 pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA;
1255 else if ((strcmp(tmpbuf, "WPA2") == 0) || (strcmp(tmpbuf, "wpa2") == 0))
1256 pAd->StaCfg.AuthMode = Ndis802_11AuthModeWPA2;
1257 else
1258 pAd->StaCfg.AuthMode = Ndis802_11AuthModeOpen;
1260 pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED;
1262 DBGPRINT(RT_DEBUG_TRACE, ("%s::(EncrypType=%d)\n", __func__, pAd->StaCfg.WepStatus));
1265 //EncrypType
1266 if(RTMPGetKeyParameter("EncrypType", tmpbuf, 128, buffer))
1269 if ((strcmp(tmpbuf, "WEP") == 0) || (strcmp(tmpbuf, "wep") == 0))
1270 pAd->StaCfg.WepStatus = Ndis802_11WEPEnabled;
1271 else if ((strcmp(tmpbuf, "TKIP") == 0) || (strcmp(tmpbuf, "tkip") == 0))
1272 pAd->StaCfg.WepStatus = Ndis802_11Encryption2Enabled;
1273 else if ((strcmp(tmpbuf, "AES") == 0) || (strcmp(tmpbuf, "aes") == 0))
1274 pAd->StaCfg.WepStatus = Ndis802_11Encryption3Enabled;
1275 else
1276 pAd->StaCfg.WepStatus = Ndis802_11WEPDisabled;
1278 // Update all wepstatus related
1279 pAd->StaCfg.PairCipher = pAd->StaCfg.WepStatus;
1280 pAd->StaCfg.GroupCipher = pAd->StaCfg.WepStatus;
1281 pAd->StaCfg.OrigWepStatus = pAd->StaCfg.WepStatus;
1282 pAd->StaCfg.bMixCipher = FALSE;
1284 DBGPRINT(RT_DEBUG_TRACE, ("%s::(EncrypType=%d)\n", __func__, pAd->StaCfg.WepStatus));
1289 if(RTMPGetCriticalParameter("WPAPSK", tmpbuf, 512, buffer))
1291 int err=0;
1293 tmpbuf[strlen(tmpbuf)] = '\0'; // make STA can process .$^& for WPAPSK input
1295 if ((pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPAPSK) &&
1296 (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPA2PSK) &&
1297 (pAd->StaCfg.AuthMode != Ndis802_11AuthModeWPANone)
1300 err = 1;
1302 else if ((strlen(tmpbuf) >= 8) && (strlen(tmpbuf) < 64))
1304 PasswordHash((char *)tmpbuf, pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, keyMaterial);
1305 NdisMoveMemory(pAd->StaCfg.PMK, keyMaterial, 32);
1308 else if (strlen(tmpbuf) == 64)
1310 AtoH(tmpbuf, keyMaterial, 32);
1311 NdisMoveMemory(pAd->StaCfg.PMK, keyMaterial, 32);
1313 else
1315 err = 1;
1316 DBGPRINT(RT_DEBUG_ERROR, ("%s::(WPAPSK key-string required 8 ~ 64 characters!)\n", __func__));
1319 if (err == 0)
1321 if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) ||
1322 (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK))
1324 // Start STA supplicant state machine
1325 pAd->StaCfg.WpaState = SS_START;
1327 else if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone)
1329 pAd->StaCfg.WpaState = SS_NOTUSE;
1332 DBGPRINT(RT_DEBUG_TRACE, ("%s::(WPAPSK=%s)\n", __func__, tmpbuf));
1337 //DefaultKeyID, KeyType, KeyStr
1338 rtmp_read_key_parms_from_file(pAd, tmpbuf, buffer);
1340 HTParametersHook(pAd, tmpbuf, buffer);
1343 //PSMode
1344 #ifdef RT2860
1345 if (RTMPGetKeyParameter("PSMode", tmpbuf, 32, buffer))
1346 #endif
1347 #ifdef RT2870
1348 if (RTMPGetKeyParameter("PSMode", tmpbuf, 10, buffer))
1349 #endif
1351 if (pAd->StaCfg.BssType == BSS_INFRA)
1353 if ((strcmp(tmpbuf, "MAX_PSP") == 0) || (strcmp(tmpbuf, "max_psp") == 0))
1355 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1356 // to exclude certain situations.
1357 // MlmeSetPsm(pAd, PWR_SAVE);
1358 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1359 if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1360 pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeMAX_PSP;
1361 pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeMAX_PSP;
1362 pAd->StaCfg.DefaultListenCount = 5;
1364 else if ((strcmp(tmpbuf, "Fast_PSP") == 0) || (strcmp(tmpbuf, "fast_psp") == 0)
1365 || (strcmp(tmpbuf, "FAST_PSP") == 0))
1367 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1368 // to exclude certain situations.
1369 // MlmeSetPsmBit(pAd, PWR_SAVE);
1370 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1371 if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1372 pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeFast_PSP;
1373 pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeFast_PSP;
1374 pAd->StaCfg.DefaultListenCount = 3;
1376 else if ((strcmp(tmpbuf, "Legacy_PSP") == 0) || (strcmp(tmpbuf, "legacy_psp") == 0)
1377 || (strcmp(tmpbuf, "LEGACY_PSP") == 0))
1379 // do NOT turn on PSM bit here, wait until MlmeCheckForPsmChange()
1380 // to exclude certain situations.
1381 // MlmeSetPsmBit(pAd, PWR_SAVE);
1382 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1383 if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1384 pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeLegacy_PSP;
1385 pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeLegacy_PSP;
1386 pAd->StaCfg.DefaultListenCount = 3;
1388 else
1389 { //Default Ndis802_11PowerModeCAM
1390 // clear PSM bit immediately
1391 MlmeSetPsmBit(pAd, PWR_ACTIVE);
1392 OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM);
1393 if (pAd->StaCfg.bWindowsACCAMEnable == FALSE)
1394 pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM;
1395 pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM;
1397 DBGPRINT(RT_DEBUG_TRACE, ("PSMode=%ld\n", pAd->StaCfg.WindowsPowerMode));
1400 // FastRoaming
1401 if (RTMPGetKeyParameter("FastRoaming", tmpbuf, 32, buffer))
1403 if (simple_strtol(tmpbuf, 0, 10) == 0)
1404 pAd->StaCfg.bFastRoaming = FALSE;
1405 else
1406 pAd->StaCfg.bFastRoaming = TRUE;
1408 DBGPRINT(RT_DEBUG_TRACE, ("FastRoaming=%d\n", pAd->StaCfg.bFastRoaming));
1410 // RoamThreshold
1411 if (RTMPGetKeyParameter("RoamThreshold", tmpbuf, 32, buffer))
1413 long lInfo = simple_strtol(tmpbuf, 0, 10);
1415 if (lInfo > 90 || lInfo < 60)
1416 pAd->StaCfg.dBmToRoam = -70;
1417 else
1418 pAd->StaCfg.dBmToRoam = (CHAR)(-1)*lInfo;
1420 DBGPRINT(RT_DEBUG_TRACE, ("RoamThreshold=%d dBm\n", pAd->StaCfg.dBmToRoam));
1423 if(RTMPGetKeyParameter("TGnWifiTest", tmpbuf, 10, buffer))
1425 if(simple_strtol(tmpbuf, 0, 10) == 0)
1426 pAd->StaCfg.bTGnWifiTest = FALSE;
1427 else
1428 pAd->StaCfg.bTGnWifiTest = TRUE;
1429 DBGPRINT(RT_DEBUG_TRACE, ("TGnWifiTest=%d\n", pAd->StaCfg.bTGnWifiTest));
1434 else
1436 DBGPRINT(RT_DEBUG_TRACE, ("--> %s does not have a write method\n", src));
1439 retval=filp_close(srcf,NULL);
1441 if (retval)
1443 DBGPRINT(RT_DEBUG_TRACE, ("--> Error %d closing %s\n", -retval, src));
1448 set_fs(orgfs);
1450 kfree(buffer);
1451 kfree(tmpbuf);
1453 return (NDIS_STATUS_SUCCESS);
1456 static void HTParametersHook(
1457 IN PRTMP_ADAPTER pAd,
1458 IN CHAR *pValueStr,
1459 IN CHAR *pInput)
1462 INT Value;
1464 if (RTMPGetKeyParameter("HT_PROTECT", pValueStr, 25, pInput))
1466 Value = simple_strtol(pValueStr, 0, 10);
1467 if (Value == 0)
1469 pAd->CommonCfg.bHTProtect = FALSE;
1471 else
1473 pAd->CommonCfg.bHTProtect = TRUE;
1475 DBGPRINT(RT_DEBUG_TRACE, ("HT: Protection = %s\n", (Value==0) ? "Disable" : "Enable"));
1478 if (RTMPGetKeyParameter("HT_MIMOPSEnable", pValueStr, 25, pInput))
1480 Value = simple_strtol(pValueStr, 0, 10);
1481 if (Value == 0)
1483 pAd->CommonCfg.bMIMOPSEnable = FALSE;
1485 else
1487 pAd->CommonCfg.bMIMOPSEnable = TRUE;
1489 DBGPRINT(RT_DEBUG_TRACE, ("HT: MIMOPSEnable = %s\n", (Value==0) ? "Disable" : "Enable"));
1493 if (RTMPGetKeyParameter("HT_MIMOPSMode", pValueStr, 25, pInput))
1495 Value = simple_strtol(pValueStr, 0, 10);
1496 if (Value > MMPS_ENABLE)
1498 pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
1500 else
1502 //TODO: add mimo power saving mechanism
1503 pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE;
1504 //pAd->CommonCfg.BACapability.field.MMPSmode = Value;
1506 DBGPRINT(RT_DEBUG_TRACE, ("HT: MIMOPS Mode = %d\n", Value));
1509 if (RTMPGetKeyParameter("HT_BADecline", pValueStr, 25, pInput))
1511 Value = simple_strtol(pValueStr, 0, 10);
1512 if (Value == 0)
1514 pAd->CommonCfg.bBADecline = FALSE;
1516 else
1518 pAd->CommonCfg.bBADecline = TRUE;
1520 DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Decline = %s\n", (Value==0) ? "Disable" : "Enable"));
1524 if (RTMPGetKeyParameter("HT_DisableReordering", pValueStr, 25, pInput))
1526 Value = simple_strtol(pValueStr, 0, 10);
1527 if (Value == 0)
1529 pAd->CommonCfg.bDisableReordering = FALSE;
1531 else
1533 pAd->CommonCfg.bDisableReordering = TRUE;
1535 DBGPRINT(RT_DEBUG_TRACE, ("HT: DisableReordering = %s\n", (Value==0) ? "Disable" : "Enable"));
1538 if (RTMPGetKeyParameter("HT_AutoBA", pValueStr, 25, pInput))
1540 Value = simple_strtol(pValueStr, 0, 10);
1541 if (Value == 0)
1543 pAd->CommonCfg.BACapability.field.AutoBA = FALSE;
1544 pAd->CommonCfg.BACapability.field.Policy = BA_NOTUSE;
1546 else
1548 pAd->CommonCfg.BACapability.field.AutoBA = TRUE;
1549 pAd->CommonCfg.BACapability.field.Policy = IMMED_BA;
1551 pAd->CommonCfg.REGBACapability.field.AutoBA = pAd->CommonCfg.BACapability.field.AutoBA;
1552 pAd->CommonCfg.REGBACapability.field.Policy = pAd->CommonCfg.BACapability.field.Policy;
1553 DBGPRINT(RT_DEBUG_TRACE, ("HT: Auto BA = %s\n", (Value==0) ? "Disable" : "Enable"));
1556 // Tx_+HTC frame
1557 if (RTMPGetKeyParameter("HT_HTC", pValueStr, 25, pInput))
1559 Value = simple_strtol(pValueStr, 0, 10);
1560 if (Value == 0)
1562 pAd->HTCEnable = FALSE;
1564 else
1566 pAd->HTCEnable = TRUE;
1568 DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx +HTC frame = %s\n", (Value==0) ? "Disable" : "Enable"));
1571 // Enable HT Link Adaptation Control
1572 if (RTMPGetKeyParameter("HT_LinkAdapt", pValueStr, 25, pInput))
1574 Value = simple_strtol(pValueStr, 0, 10);
1575 if (Value == 0)
1577 pAd->bLinkAdapt = FALSE;
1579 else
1581 pAd->HTCEnable = TRUE;
1582 pAd->bLinkAdapt = TRUE;
1584 DBGPRINT(RT_DEBUG_TRACE, ("HT: Link Adaptation Control = %s\n", (Value==0) ? "Disable" : "Enable(+HTC)"));
1587 // Reverse Direction Mechanism
1588 if (RTMPGetKeyParameter("HT_RDG", pValueStr, 25, pInput))
1590 Value = simple_strtol(pValueStr, 0, 10);
1591 if (Value == 0)
1593 pAd->CommonCfg.bRdg = FALSE;
1595 else
1597 pAd->HTCEnable = TRUE;
1598 pAd->CommonCfg.bRdg = TRUE;
1600 DBGPRINT(RT_DEBUG_TRACE, ("HT: RDG = %s\n", (Value==0) ? "Disable" : "Enable(+HTC)"));
1606 // Tx A-MSUD ?
1607 if (RTMPGetKeyParameter("HT_AMSDU", pValueStr, 25, pInput))
1609 Value = simple_strtol(pValueStr, 0, 10);
1610 if (Value == 0)
1612 pAd->CommonCfg.BACapability.field.AmsduEnable = FALSE;
1614 else
1616 pAd->CommonCfg.BACapability.field.AmsduEnable = TRUE;
1618 DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx A-MSDU = %s\n", (Value==0) ? "Disable" : "Enable"));
1621 // MPDU Density
1622 if (RTMPGetKeyParameter("HT_MpduDensity", pValueStr, 25, pInput))
1624 Value = simple_strtol(pValueStr, 0, 10);
1625 if (Value <=7 && Value >= 0)
1627 pAd->CommonCfg.BACapability.field.MpduDensity = Value;
1628 DBGPRINT(RT_DEBUG_TRACE, ("HT: MPDU Density = %d\n", Value));
1630 else
1632 pAd->CommonCfg.BACapability.field.MpduDensity = 4;
1633 DBGPRINT(RT_DEBUG_TRACE, ("HT: MPDU Density = %d (Default)\n", 4));
1637 // Max Rx BA Window Size
1638 if (RTMPGetKeyParameter("HT_BAWinSize", pValueStr, 25, pInput))
1640 Value = simple_strtol(pValueStr, 0, 10);
1642 if (Value >=1 && Value <= 64)
1644 pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = Value;
1645 pAd->CommonCfg.BACapability.field.RxBAWinLimit = Value;
1646 DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Windw Size = %d\n", Value));
1648 else
1650 pAd->CommonCfg.REGBACapability.field.RxBAWinLimit = 64;
1651 pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64;
1652 DBGPRINT(RT_DEBUG_TRACE, ("HT: BA Windw Size = 64 (Defualt)\n"));
1657 // Guard Interval
1658 if (RTMPGetKeyParameter("HT_GI", pValueStr, 25, pInput))
1660 Value = simple_strtol(pValueStr, 0, 10);
1662 if (Value == GI_400)
1664 pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_400;
1666 else
1668 pAd->CommonCfg.RegTransmitSetting.field.ShortGI = GI_800;
1671 DBGPRINT(RT_DEBUG_TRACE, ("HT: Guard Interval = %s\n", (Value==GI_400) ? "400" : "800" ));
1674 // HT Operation Mode : Mixed Mode , Green Field
1675 if (RTMPGetKeyParameter("HT_OpMode", pValueStr, 25, pInput))
1677 Value = simple_strtol(pValueStr, 0, 10);
1679 if (Value == HTMODE_GF)
1682 pAd->CommonCfg.RegTransmitSetting.field.HTMODE = HTMODE_GF;
1684 else
1686 pAd->CommonCfg.RegTransmitSetting.field.HTMODE = HTMODE_MM;
1689 DBGPRINT(RT_DEBUG_TRACE, ("HT: Operate Mode = %s\n", (Value==HTMODE_GF) ? "Green Field" : "Mixed Mode" ));
1692 // Fixed Tx mode : CCK, OFDM
1693 if (RTMPGetKeyParameter("FixedTxMode", pValueStr, 25, pInput))
1695 UCHAR fix_tx_mode;
1698 fix_tx_mode = FIXED_TXMODE_HT;
1700 if (strcmp(pValueStr, "OFDM") == 0 || strcmp(pValueStr, "ofdm") == 0)
1702 fix_tx_mode = FIXED_TXMODE_OFDM;
1704 else if (strcmp(pValueStr, "CCK") == 0 || strcmp(pValueStr, "cck") == 0)
1706 fix_tx_mode = FIXED_TXMODE_CCK;
1708 else if (strcmp(pValueStr, "HT") == 0 || strcmp(pValueStr, "ht") == 0)
1710 fix_tx_mode = FIXED_TXMODE_HT;
1712 else
1714 Value = simple_strtol(pValueStr, 0, 10);
1715 // 1 : CCK
1716 // 2 : OFDM
1717 // otherwise : HT
1718 if (Value == FIXED_TXMODE_CCK || Value == FIXED_TXMODE_OFDM)
1719 fix_tx_mode = Value;
1720 else
1721 fix_tx_mode = FIXED_TXMODE_HT;
1724 pAd->StaCfg.DesiredTransmitSetting.field.FixedTxMode = fix_tx_mode;
1725 DBGPRINT(RT_DEBUG_TRACE, ("Fixed Tx Mode = %d\n", fix_tx_mode));
1731 // Channel Width
1732 if (RTMPGetKeyParameter("HT_BW", pValueStr, 25, pInput))
1734 Value = simple_strtol(pValueStr, 0, 10);
1736 if (Value == BW_40)
1738 pAd->CommonCfg.RegTransmitSetting.field.BW = BW_40;
1740 else
1742 pAd->CommonCfg.RegTransmitSetting.field.BW = BW_20;
1745 #ifdef MCAST_RATE_SPECIFIC
1746 pAd->CommonCfg.MCastPhyMode.field.BW = pAd->CommonCfg.RegTransmitSetting.field.BW;
1747 #endif // MCAST_RATE_SPECIFIC //
1749 DBGPRINT(RT_DEBUG_TRACE, ("HT: Channel Width = %s\n", (Value==BW_40) ? "40 MHz" : "20 MHz" ));
1752 if (RTMPGetKeyParameter("HT_EXTCHA", pValueStr, 25, pInput))
1754 Value = simple_strtol(pValueStr, 0, 10);
1756 if (Value == 0)
1759 pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_BELOW;
1761 else
1763 pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_ABOVE;
1766 DBGPRINT(RT_DEBUG_TRACE, ("HT: Ext Channel = %s\n", (Value==0) ? "BELOW" : "ABOVE" ));
1769 // MSC
1770 if (RTMPGetKeyParameter("HT_MCS", pValueStr, 50, pInput))
1773 Value = simple_strtol(pValueStr, 0, 10);
1775 if ((Value >= 0 && Value <= 23) || (Value == 32)) // 3*3
1777 pAd->StaCfg.DesiredTransmitSetting.field.MCS = Value;
1778 pAd->StaCfg.bAutoTxRateSwitch = FALSE;
1779 DBGPRINT(RT_DEBUG_TRACE, ("HT: MCS = %d\n", pAd->StaCfg.DesiredTransmitSetting.field.MCS));
1781 else
1783 pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO;
1784 pAd->StaCfg.bAutoTxRateSwitch = TRUE;
1785 DBGPRINT(RT_DEBUG_TRACE, ("HT: MCS = AUTO\n"));
1790 // STBC
1791 if (RTMPGetKeyParameter("HT_STBC", pValueStr, 25, pInput))
1793 Value = simple_strtol(pValueStr, 0, 10);
1794 if (Value == STBC_USE)
1796 pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_USE;
1798 else
1800 pAd->CommonCfg.RegTransmitSetting.field.STBC = STBC_NONE;
1802 DBGPRINT(RT_DEBUG_TRACE, ("HT: STBC = %d\n", pAd->CommonCfg.RegTransmitSetting.field.STBC));
1805 // 40_Mhz_Intolerant
1806 if (RTMPGetKeyParameter("HT_40MHZ_INTOLERANT", pValueStr, 25, pInput))
1808 Value = simple_strtol(pValueStr, 0, 10);
1809 if (Value == 0)
1811 pAd->CommonCfg.bForty_Mhz_Intolerant = FALSE;
1813 else
1815 pAd->CommonCfg.bForty_Mhz_Intolerant = TRUE;
1817 DBGPRINT(RT_DEBUG_TRACE, ("HT: 40MHZ INTOLERANT = %d\n", pAd->CommonCfg.bForty_Mhz_Intolerant));
1819 //HT_TxStream
1820 if(RTMPGetKeyParameter("HT_TxStream", pValueStr, 10, pInput))
1822 switch (simple_strtol(pValueStr, 0, 10))
1824 case 1:
1825 pAd->CommonCfg.TxStream = 1;
1826 break;
1827 case 2:
1828 pAd->CommonCfg.TxStream = 2;
1829 break;
1830 case 3: // 3*3
1831 default:
1832 pAd->CommonCfg.TxStream = 3;
1834 if (pAd->MACVersion < RALINK_2883_VERSION)
1835 pAd->CommonCfg.TxStream = 2; // only 2 tx streams for RT2860 series
1836 break;
1838 DBGPRINT(RT_DEBUG_TRACE, ("HT: Tx Stream = %d\n", pAd->CommonCfg.TxStream));
1840 //HT_RxStream
1841 if(RTMPGetKeyParameter("HT_RxStream", pValueStr, 10, pInput))
1843 switch (simple_strtol(pValueStr, 0, 10))
1845 case 1:
1846 pAd->CommonCfg.RxStream = 1;
1847 break;
1848 case 2:
1849 pAd->CommonCfg.RxStream = 2;
1850 break;
1851 case 3:
1852 default:
1853 pAd->CommonCfg.RxStream = 3;
1855 if (pAd->MACVersion < RALINK_2883_VERSION)
1856 pAd->CommonCfg.RxStream = 2; // only 2 rx streams for RT2860 series
1857 break;
1859 DBGPRINT(RT_DEBUG_TRACE, ("HT: Rx Stream = %d\n", pAd->CommonCfg.RxStream));