1 /**************************************************************************** 2 **+-----------------------------------------------------------------------+** 3 **| |** 4 **| Copyright(c) 1998 - 2008 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 #include "osrgstry_parser.h" 37 38 extern VOID regReadLastDbgState(PTIWLN_ADAPTER_T pAdapter); 39 40 static char *init_file = NULL; 41 static int init_file_length= 0; 42 static PNDIS_CONFIGURATION_PARAMETER pNdisParm; 43 44 extern int osInitTable_IniFile(tiwlan_net_dev_t *drv, initTable_t *InitTable, char *file_buf, int file_length) 45 { 46 NDIS_CONFIGURATION_PARAMETER parm; 47 48 init_file = file_buf; 49 init_file_length = file_length; 50 pNdisParm = &parm; 51 52 regFillInitTable( &drv->adapter, InitTable ); 53 #ifdef TI_DBG 54 regReadLastDbgState(&drv->adapter); 55 #endif 56 57 return 0; 58 } 59 60 unsigned long TiDebugFlag; 61 62 /* void PRINT( char * type, char *format, ... )*/ 63 /* {*/ 64 /* return ;*/ 65 /* }*/ 66 67 NDIS_STATUS NdisUnicodeStringToAnsiString( IN OUT PANSI_STRING DestinationString, 68 IN PUNICODE_STRING SourceString ) 69 { 70 if( DestinationString->MaximumLength < SourceString->Length ) 71 return NDIS_STATUS_BUFFER_TOO_SHORT; 72 73 DestinationString->Length = SourceString->Length; 74 os_memoryCopy( NULL, DestinationString->Buffer, SourceString->Buffer, SourceString->Length ); 75 return NDIS_STATUS_SUCCESS; 76 77 } 78 79 #ifndef tolower 80 #define tolower(c) ( (c) | 0x20) 81 #endif 82 83 /* Search sub-string in memory buffer */ 84 /* From '#' to EOL ---- remarks */ 85 char *mem_str(char *buf, char *str, char *end_buf) 86 { 87 int i; 88 89 for( ; buf <= end_buf; buf++ ) 90 { 91 if( *buf == '#' ) 92 { 93 buf = strchr(buf+1, '\n' ); 94 if( !buf ) 95 return NULL; 96 97 } 98 for( i=0; &buf[i] <= end_buf && buf[i] && str[i] && (tolower(buf[i]) == tolower(str[i])); i++ ) ; 99 100 if ((!str[i]) && (!((tolower(*(buf-1))>='a') && (tolower(*(buf-1))<='z')))) 101 return buf; 102 } 103 return NULL; 104 } 105 106 char * ltrim(char *s ) 107 { 108 while( *s == ' ' || *s == '\t' ) s++; 109 return s; 110 } 111 112 VOID NdisReadConfiguration( OUT PNDIS_STATUS status, OUT PNDIS_CONFIGURATION_PARAMETER *param_value, 113 IN NDIS_HANDLE config_handle, IN PNDIS_STRING keyword, IN NDIS_PARAMETER_TYPE param_type ) 114 { 115 #ifdef USE_INIT_FILE 116 char *name = keyword->Buffer; 117 char *s, *buf = init_file, *end_buf = init_file + init_file_length; 118 static int count = 0; 119 120 *status = NDIS_STATUS_FAILURE; 121 *param_value = pNdisParm; 122 123 if( !count ) 124 { 125 print_deb("\n++++++++++++\n%s+++++++++++\n", init_file); 126 count++; 127 } 128 129 if( !name || !*name || !init_file || !init_file_length ) 130 return ; 131 132 memset(pNdisParm, 0, sizeof(NDIS_CONFIGURATION_PARAMETER)); 133 134 while(buf < end_buf) 135 { 136 buf = ltrim(buf); 137 if( !(s = mem_str(buf, name, end_buf)) ) 138 break; 139 140 buf = ltrim(s + strlen(name)); 141 if( *buf == '=' ) 142 buf++; 143 else { 144 /*print_err("\n...init_config err: delim not found (=): ** %s **\n", buf );*/ 145 buf = s + 1; /*strlen(name);*/ 146 continue; 147 } 148 buf = ltrim(buf); 149 if( param_type == NdisParameterString ) 150 { 151 char *remark = NULL; 152 153 s = strchr(buf, '\n'); 154 if( !s ) 155 s = buf+strlen(buf); 156 157 remark = memchr(buf, '#', s - buf); /* skip remarks */ 158 if( remark ) 159 { 160 do { /* remove whitespace */ 161 remark--; 162 } while( *remark == ' ' || *remark == '\t' ); 163 164 pNdisParm->ParameterData.StringData.Length = remark - buf + 1; 165 } 166 else 167 pNdisParm->ParameterData.StringData.Length = s - buf; 168 169 pNdisParm->ParameterData.StringData.Buffer = (PUCHAR)&pNdisParm->StringBuffer[0]; 170 pNdisParm->ParameterData.StringData.MaximumLength = NDIS_MAX_STRING_LEN; 171 if( !pNdisParm->ParameterData.StringData.Length > NDIS_MAX_STRING_LEN ) 172 { 173 *status = NDIS_STATUS_BUFFER_TOO_SHORT; 174 return; 175 } 176 memcpy(pNdisParm->ParameterData.StringData.Buffer, buf, pNdisParm->ParameterData.StringData.Length); 177 print_info("NdisReadConfiguration(): %s = (%d)'%s'\n", name, pNdisParm->ParameterData.StringData.Length, pNdisParm->ParameterData.StringData.Buffer); 178 } 179 else if( param_type == NdisParameterInteger ) 180 { 181 char *end_p; 182 pNdisParm->ParameterData.IntegerData = simple_strtol(buf, &end_p, 0); 183 if (end_p && *end_p && *end_p!=' ' && *end_p!='\n' 184 && *end_p!='\r' && *end_p!='\t') 185 { 186 print_err("\n...init_config: invalid int value for <%s> : %s\n", name, buf ); 187 return; 188 } 189 /*print_deb(" NdisReadConfiguration(): buf = %p (%.20s)\n", buf, buf );*/ 190 print_info("NdisReadConfiguration(): %s = %d\n", name, (INT32) pNdisParm->ParameterData.IntegerData); 191 } 192 else 193 { 194 print_err("NdisReadConfiguration(): unknow parameter type %d for %s\n", param_type, name ); 195 return; 196 } 197 *status = NDIS_STATUS_SUCCESS; 198 return; 199 200 } 201 /* print_deb("NdisReadConfiguration(%d): (%c)%s - not found\n", init_file_length,*/ 202 /* (param_type == NdisParameterString) ? 'S' : 'D', name );*/ 203 #else 204 /* No init file support */ 205 *status = NDIS_STATUS_FAILURE; 206 207 #endif 208 return ; 209 } 210 211 VOID NdisWriteConfiguration( OUT PNDIS_STATUS Status, 212 IN NDIS_HANDLE ConfigurationHandle, 213 IN PNDIS_STRING Keyword, 214 IN PNDIS_CONFIGURATION_PARAMETER ParameterValue ) 215 { 216 print_err(" NdisWriteConfiguration(): ** not implemented yet ...\n"); 217 } 218 219 VOID NdisReadNetworkAddress( OUT PNDIS_STATUS Status, OUT PVOID *NetworkAddress, OUT PUINT NetworkAddressLength, 220 IN NDIS_HANDLE ConfigurationHandle ) 221 { 222 print_err(" NdisReadNetworkAddress(): ** not implemented yet ...\n"); 223 } 224 225 VOID NdisMIndicateStatus( 226 NDIS_HANDLE MiniportAdapterHandle, 227 NDIS_STATUS GeneralStatus, 228 PVOID StatusBuffer, 229 UINT StatusBufferSize 230 ) 231 { 232 } 233