• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * osRgstry_parser.c
3  *
4  * Copyright(c) 1998 - 2010 Texas Instruments. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  *  * Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *  * Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  *  * Neither the name Texas Instruments nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 
35 /*
36  * src/osRgstry_parser.c
37  *
38  */
39 
40 #include "osRgstry_parser.h"
41 
42 extern void regReadLastDbgState(TWlanDrvIfObjPtr pAdapter);
43 
44 static char *init_file      = NULL;
45 static int init_file_length = 0;
46 static PNDIS_CONFIGURATION_PARAMETER pNdisParm;
47 
osInitTable_IniFile(TI_HANDLE hOs,TInitTable * InitTable,char * file_buf,int file_length)48 int osInitTable_IniFile (TI_HANDLE hOs, TInitTable *InitTable, char *file_buf, int file_length)
49 {
50     TWlanDrvIfObjPtr drv = (TWlanDrvIfObjPtr)hOs;
51     static NDIS_CONFIGURATION_PARAMETER vNdisParm;
52 
53     init_file         = file_buf;
54     init_file_length  = file_length;
55     pNdisParm = &vNdisParm;
56 
57     regFillInitTable (drv, InitTable);
58 #ifdef TI_DBG
59     regReadLastDbgState(drv);
60 #endif
61     return 0;
62 }
63 
64 unsigned long TiDebugFlag;
65 
66 /* void PRINT( char * type, char *format, ... )*/
67 /* {*/
68 /*     return ;*/
69 /* }*/
70 
NdisUnicodeStringToAnsiString(IN OUT PANSI_STRING DestinationString,IN PUNICODE_STRING SourceString)71 NDIS_STATUS NdisUnicodeStringToAnsiString( IN OUT PANSI_STRING  DestinationString,
72     IN PUNICODE_STRING  SourceString )
73 {
74     if( DestinationString->MaximumLength < SourceString->Length )
75         return NDIS_STATUS_BUFFER_TOO_SHORT;
76 
77     DestinationString->Length = SourceString->Length;
78     os_memoryCopy( NULL, DestinationString->Buffer, SourceString->Buffer, SourceString->Length );
79     return NDIS_STATUS_SUCCESS;
80 
81 }
82 
83 #ifndef tolower
84 #define tolower(c)  ( (c) | 0x20)
85 #endif
86 
87     /* Search sub-string in memory buffer */
88     /* From '#' to EOL ---- remarks */
mem_str(char * buf,char * str,char * end_buf)89 char *mem_str(char *buf, char *str, char *end_buf)
90 {
91     int i;
92 
93     for( ; buf <= end_buf; buf++ )
94     {
95         if( *buf == '#' )
96         {
97             buf = strchr(buf+1, '\n' );
98             if( !buf )
99                 return NULL;
100 
101         }
102         for( i=0; &buf[i] <= end_buf && buf[i] && str[i] && (tolower(buf[i]) == tolower(str[i])); i++ ) ;
103 
104         if ((!str[i]) && (!((tolower(*(buf-1))>='a') && (tolower(*(buf-1))<='z'))))
105             return buf;
106     }
107     return NULL;
108 }
109 
ltrim(char * s)110 char * ltrim(char *s )
111 {
112     while( *s == ' ' || *s == '\t' ) s++;
113     return s;
114 }
115 
NdisReadConfiguration(OUT PNDIS_STATUS status,OUT PNDIS_CONFIGURATION_PARAMETER * param_value,IN NDIS_HANDLE config_handle,IN PNDIS_STRING keyword,IN NDIS_PARAMETER_TYPE param_type)116 void NdisReadConfiguration( OUT PNDIS_STATUS  status, OUT PNDIS_CONFIGURATION_PARAMETER  *param_value,
117     IN NDIS_HANDLE  config_handle, IN PNDIS_STRING  keyword, IN NDIS_PARAMETER_TYPE  param_type )
118 {
119     char *name = keyword->Buffer;
120     char *s, *buf = init_file, *end_buf = init_file + init_file_length;
121     static int count = 0;
122 
123     *status = NDIS_STATUS_FAILURE;
124     *param_value = pNdisParm;
125 
126     if( !count )
127     {
128         print_deb("\n++++++++++++\n%s+++++++++++\n", init_file);
129         count++;
130     }
131 
132     if( !name || !*name || !init_file || !init_file_length )
133         return ;
134 
135     memset(pNdisParm, 0, sizeof(NDIS_CONFIGURATION_PARAMETER));
136 
137     while(buf < end_buf)
138     {
139         buf = ltrim(buf);
140         s = mem_str(buf, name, end_buf);
141         if( !s )
142             break;
143 
144         buf = ltrim(s + strlen(name));
145         if( *buf == '=' )
146             buf++;
147         else {
148             /*print_err("\n...init_config err: delim not found (=): ** %s **\n", buf );*/
149             buf = s + 1; /*strlen(name);*/
150             continue;
151         }
152         buf = ltrim(buf);
153         if( param_type == NdisParameterString )
154         {
155             char *remark = NULL;
156 
157             s = strchr(buf, '\n');
158             if( !s )
159                 s = buf+strlen(buf);
160 
161             remark = memchr(buf, '#', s - buf);        /* skip remarks */
162             if( remark )
163             {
164                 do {        /* remove whitespace  */
165                     remark--;
166                 } while( *remark == ' ' || *remark == '\t' );
167 
168                 pNdisParm->ParameterData.StringData.Length = remark - buf + 1;
169             }
170             else
171                 pNdisParm->ParameterData.StringData.Length = s - buf;
172 
173             pNdisParm->ParameterData.StringData.Buffer = (TI_UINT8*)&pNdisParm->StringBuffer[0];
174             pNdisParm->ParameterData.StringData.MaximumLength = NDIS_MAX_STRING_LEN;
175             if( !pNdisParm->ParameterData.StringData.Length > NDIS_MAX_STRING_LEN )
176             {
177                 *status = NDIS_STATUS_BUFFER_TOO_SHORT;
178                 return;
179             }
180             memcpy(pNdisParm->ParameterData.StringData.Buffer, buf, pNdisParm->ParameterData.StringData.Length);
181             print_info("NdisReadConfiguration(): %s = (%d)'%s'\n", name, pNdisParm->ParameterData.StringData.Length, pNdisParm->ParameterData.StringData.Buffer);
182         }
183         else if( param_type == NdisParameterInteger )
184         {
185 	    char *end_p;
186             pNdisParm->ParameterData.IntegerData = simple_strtol(buf, &end_p, 0);
187             if (end_p && *end_p && *end_p!=' ' && *end_p!='\n'
188 		&& *end_p!='\r' && *end_p!='\t')
189             {
190                 print_err("\n...init_config: invalid int value for <%s> : %s\n", name, buf );
191                 return;
192             }
193             /*print_deb(" NdisReadConfiguration(): buf = %p (%.20s)\n", buf, buf );*/
194             print_info("NdisReadConfiguration(): %s = %d\n", name, (TI_INT32) pNdisParm->ParameterData.IntegerData);
195         }
196         else
197         {
198             print_err("NdisReadConfiguration(): unknow parameter type %d for %s\n", param_type, name );
199             return;
200         }
201         *status = NDIS_STATUS_SUCCESS;
202         return;
203 
204     }
205     return ;
206 }
207 
NdisWriteConfiguration(OUT PNDIS_STATUS Status,IN NDIS_HANDLE ConfigurationHandle,IN PNDIS_STRING Keyword,IN PNDIS_CONFIGURATION_PARAMETER ParameterValue)208 void NdisWriteConfiguration( OUT PNDIS_STATUS  Status,
209                 IN NDIS_HANDLE  ConfigurationHandle,
210                 IN PNDIS_STRING  Keyword,
211                 IN PNDIS_CONFIGURATION_PARAMETER  ParameterValue )
212 {
213     print_err(" NdisWriteConfiguration(): ** not implemented yet ...\n");
214 }
215 
NdisMIndicateStatus(NDIS_HANDLE MiniportAdapterHandle,NDIS_STATUS GeneralStatus,void * StatusBuffer,TI_UINT32 StatusBufferSize)216 void NdisMIndicateStatus(
217   NDIS_HANDLE MiniportAdapterHandle,
218   NDIS_STATUS GeneralStatus,
219   void* StatusBuffer,
220   TI_UINT32 StatusBufferSize
221 )
222 {
223 }
224