summaryrefslogtreecommitdiff
path: root/wilink_6_1/platforms/os/linux/src/osRgstry_parser.c
blob: 8aa108b60b2ff8d6233e6008b16d72c6087e4019 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
 * osRgstry_parser.c
 *
 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.      
 * All rights reserved.                                                  
 *                                                                       
 * Redistribution and use in source and binary forms, with or without    
 * modification, are permitted provided that the following conditions    
 * are met:                                                              
 *                                                                       
 *  * Redistributions of source code must retain the above copyright     
 *    notice, this list of conditions and the following disclaimer.      
 *  * Redistributions in binary form must reproduce the above copyright  
 *    notice, this list of conditions and the following disclaimer in    
 *    the documentation and/or other materials provided with the         
 *    distribution.                                                      
 *  * Neither the name Texas Instruments nor the names of its            
 *    contributors may be used to endorse or promote products derived    
 *    from this software without specific prior written permission.      
 *                                                                       
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


/*
 * src/osRgstry_parser.c 
 *
 */

#include "osRgstry_parser.h"

extern void regReadLastDbgState(TWlanDrvIfObjPtr pAdapter);

static char *init_file      = NULL;
static int init_file_length = 0;
static PNDIS_CONFIGURATION_PARAMETER pNdisParm;

int osInitTable_IniFile (TI_HANDLE hOs, TInitTable *InitTable, char *file_buf, int file_length)
{
    TWlanDrvIfObjPtr drv = (TWlanDrvIfObjPtr)hOs;
    static NDIS_CONFIGURATION_PARAMETER vNdisParm;

    init_file         = file_buf;
    init_file_length  = file_length;
    pNdisParm = &vNdisParm;
    
    regFillInitTable (drv, InitTable);
#ifdef TI_DBG
    regReadLastDbgState(drv);
#endif
    return 0;
}

unsigned long TiDebugFlag;

/* void PRINT( char * type, char *format, ... )*/
/* {*/
/*     return ;*/
/* }*/

NDIS_STATUS NdisUnicodeStringToAnsiString( IN OUT PANSI_STRING  DestinationString,
    IN PUNICODE_STRING  SourceString )
{
    if( DestinationString->MaximumLength < SourceString->Length )
        return NDIS_STATUS_BUFFER_TOO_SHORT;

    DestinationString->Length = SourceString->Length;
    os_memoryCopy( NULL, DestinationString->Buffer, SourceString->Buffer, SourceString->Length );
    return NDIS_STATUS_SUCCESS;

}

#ifndef tolower
#define tolower(c)  ( (c) | 0x20)
#endif

    /* Search sub-string in memory buffer */
    /* From '#' to EOL ---- remarks */
char *mem_str(char *buf, char *str, char *end_buf)
{
    int i;

    for( ; buf <= end_buf; buf++ )
    {
        if( *buf == '#' )
        {
            buf = strchr(buf+1, '\n' );
            if( !buf )
                return NULL;

        }
        for( i=0; &buf[i] <= end_buf && buf[i] && str[i] && (tolower(buf[i]) == tolower(str[i])); i++ ) ;

        if ((!str[i]) && (!((tolower(*(buf-1))>='a') && (tolower(*(buf-1))<='z'))))
            return buf;
    }
    return NULL;
}

char * ltrim(char *s )
{
    while( *s == ' ' || *s == '\t' ) s++;
    return s;
}

void 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 )
{
    char *name = keyword->Buffer;
    char *s, *buf = init_file, *end_buf = init_file + init_file_length;
    static int count = 0;

    *status = NDIS_STATUS_FAILURE;
    *param_value = pNdisParm;

    if( !count )
    {
        print_deb("\n++++++++++++\n%s+++++++++++\n", init_file);
        count++;
    }

    if( !name || !*name || !init_file || !init_file_length )
        return ;

    memset(pNdisParm, 0, sizeof(NDIS_CONFIGURATION_PARAMETER));

    while(buf < end_buf)
    {
        buf = ltrim(buf);
        if( !(s = mem_str(buf, name, end_buf)) )
            break;

        buf = ltrim(s + strlen(name));
        if( *buf == '=' )
            buf++;
        else {
            /*print_err("\n...init_config err: delim not found (=): ** %s **\n", buf );*/
            buf = s + 1; /*strlen(name);*/
            continue;
        }
        buf = ltrim(buf);
        if( param_type == NdisParameterString )
        {
            char *remark = NULL;

            s = strchr(buf, '\n');
            if( !s )
                s = buf+strlen(buf);
            
            remark = memchr(buf, '#', s - buf);        /* skip remarks */
            if( remark )
            {
                do {        /* remove whitespace  */
                    remark--;
                } while( *remark == ' ' || *remark == '\t' );    
                
                pNdisParm->ParameterData.StringData.Length = remark - buf + 1;
            }
            else
                pNdisParm->ParameterData.StringData.Length = s - buf;
                   
            pNdisParm->ParameterData.StringData.Buffer = (TI_UINT8*)&pNdisParm->StringBuffer[0];
            pNdisParm->ParameterData.StringData.MaximumLength = NDIS_MAX_STRING_LEN;
            if( !pNdisParm->ParameterData.StringData.Length > NDIS_MAX_STRING_LEN )
            {
                *status = NDIS_STATUS_BUFFER_TOO_SHORT;
                return;
            }
            memcpy(pNdisParm->ParameterData.StringData.Buffer, buf, pNdisParm->ParameterData.StringData.Length);
            print_info("NdisReadConfiguration(): %s = (%d)'%s'\n", name, pNdisParm->ParameterData.StringData.Length, pNdisParm->ParameterData.StringData.Buffer);
        }
        else if( param_type == NdisParameterInteger )
        {
	    char *end_p;
            pNdisParm->ParameterData.IntegerData = simple_strtol(buf, &end_p, 0);
            if (end_p && *end_p && *end_p!=' ' && *end_p!='\n'
		&& *end_p!='\r' && *end_p!='\t')
            {
                print_err("\n...init_config: invalid int value for <%s> : %s\n", name, buf );
                return;
            }
            /*print_deb(" NdisReadConfiguration(): buf = %p (%.20s)\n", buf, buf );*/
            print_info("NdisReadConfiguration(): %s = %d\n", name, (TI_INT32) pNdisParm->ParameterData.IntegerData);
        }
        else
        {
            print_err("NdisReadConfiguration(): unknow parameter type %d for %s\n", param_type, name );
            return;
        }
        *status = NDIS_STATUS_SUCCESS;
        return;

    }
    return ;
}

void NdisWriteConfiguration( OUT PNDIS_STATUS  Status, 
                IN NDIS_HANDLE  ConfigurationHandle,
                IN PNDIS_STRING  Keyword, 
                IN PNDIS_CONFIGURATION_PARAMETER  ParameterValue )
{
    print_err(" NdisWriteConfiguration(): ** not implemented yet ...\n");
}

void NdisMIndicateStatus(
  NDIS_HANDLE MiniportAdapterHandle,
  NDIS_STATUS GeneralStatus,
  void* StatusBuffer,
  TI_UINT32 StatusBufferSize
)
{
}