1 /* 2 * osRgstry_parser.c 3 * 4 * Copyright(c) 1998 - 2009 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 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 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 */ 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 110 char * ltrim(char *s ) 111 { 112 while( *s == ' ' || *s == '\t' ) s++; 113 return s; 114 } 115 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 if( !(s = mem_str(buf, name, end_buf)) ) 141 break; 142 143 buf = ltrim(s + strlen(name)); 144 if( *buf == '=' ) 145 buf++; 146 else { 147 /*print_err("\n...init_config err: delim not found (=): ** %s **\n", buf );*/ 148 buf = s + 1; /*strlen(name);*/ 149 continue; 150 } 151 buf = ltrim(buf); 152 if( param_type == NdisParameterString ) 153 { 154 char *remark = NULL; 155 156 s = strchr(buf, '\n'); 157 if( !s ) 158 s = buf+strlen(buf); 159 160 remark = memchr(buf, '#', s - buf); /* skip remarks */ 161 if( remark ) 162 { 163 do { /* remove whitespace */ 164 remark--; 165 } while( *remark == ' ' || *remark == '\t' ); 166 167 pNdisParm->ParameterData.StringData.Length = remark - buf + 1; 168 } 169 else 170 pNdisParm->ParameterData.StringData.Length = s - buf; 171 172 pNdisParm->ParameterData.StringData.Buffer = (TI_UINT8*)&pNdisParm->StringBuffer[0]; 173 pNdisParm->ParameterData.StringData.MaximumLength = NDIS_MAX_STRING_LEN; 174 if( !pNdisParm->ParameterData.StringData.Length > NDIS_MAX_STRING_LEN ) 175 { 176 *status = NDIS_STATUS_BUFFER_TOO_SHORT; 177 return; 178 } 179 memcpy(pNdisParm->ParameterData.StringData.Buffer, buf, pNdisParm->ParameterData.StringData.Length); 180 print_info("NdisReadConfiguration(): %s = (%d)'%s'\n", name, pNdisParm->ParameterData.StringData.Length, pNdisParm->ParameterData.StringData.Buffer); 181 } 182 else if( param_type == NdisParameterInteger ) 183 { 184 char *end_p; 185 pNdisParm->ParameterData.IntegerData = simple_strtol(buf, &end_p, 0); 186 if (end_p && *end_p && *end_p!=' ' && *end_p!='\n' 187 && *end_p!='\r' && *end_p!='\t') 188 { 189 print_err("\n...init_config: invalid int value for <%s> : %s\n", name, buf ); 190 return; 191 } 192 /*print_deb(" NdisReadConfiguration(): buf = %p (%.20s)\n", buf, buf );*/ 193 print_info("NdisReadConfiguration(): %s = %d\n", name, (TI_INT32) pNdisParm->ParameterData.IntegerData); 194 } 195 else 196 { 197 print_err("NdisReadConfiguration(): unknow parameter type %d for %s\n", param_type, name ); 198 return; 199 } 200 *status = NDIS_STATUS_SUCCESS; 201 return; 202 203 } 204 return ; 205 } 206 207 void NdisWriteConfiguration( OUT PNDIS_STATUS Status, 208 IN NDIS_HANDLE ConfigurationHandle, 209 IN PNDIS_STRING Keyword, 210 IN PNDIS_CONFIGURATION_PARAMETER ParameterValue ) 211 { 212 print_err(" NdisWriteConfiguration(): ** not implemented yet ...\n"); 213 } 214 215 void NdisMIndicateStatus( 216 NDIS_HANDLE MiniportAdapterHandle, 217 NDIS_STATUS GeneralStatus, 218 void* StatusBuffer, 219 TI_UINT32 StatusBufferSize 220 ) 221 { 222 } 223