-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.c
262 lines (238 loc) · 5.62 KB
/
util.c
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "util.h"
#include "gsinterface.h"
const char eciadsl_conf[] = CONF_DIR "/eciadsl.conf";
extern struct eci_device_t eci_device;
struct config_t config;
inline void get_unsigned_value(const char* param, unsigned int* var)
{
unsigned int value;
char* chk;
value = (unsigned int) strtoul(param, &chk, 10);
if (! *chk)
*var = value;
}
static inline void get_unsigned_short_value(const char* param, unsigned short int* var)
{
unsigned short int value;
char* chk;
value = (unsigned short int) strtoul(param, &chk, 10);
if (! *chk)
*var = value;
}
inline void get_signed_value(const char* param, int* var)
{
int value;
char* chk;
value = (int)strtol(param, &chk, 10);
if (!*chk)
*var = value;
}
static inline void get_signed_short_value(const char* param, short int* var)
{
short int value;
char* chk;
value = (short int) strtoul(param, &chk, 10);
if (! *chk)
*var = value;
}
inline void get_hexa_value(const char* param, unsigned int* var)
{
unsigned int value;
char* chk;
value = strtoul(param, &chk, 0);
if (!*chk)
*var = value;
}
inline char* strDup(char** var, const char* text)
{
*var=malloc((strlen(text)+1)*sizeof(char));
if (!*var)
return(NULL);
strcpy(*var, text);
return(*var);
}
#define COPY_HEXA(dest, src) \
strcpy(dest, "0x"); \
strncat(dest, src, 4);
inline void read_config_file(void)
{
FILE* file;
char line[8192];
char* ptr;
char* tmp;
char hexa[7];
unsigned long int num;
set_eci_modem_chipset("GS7070");
config.vid1=0;
config.pid1=0;
config.vid2=0;
config.pid2=0;
config.vpi=0xffffffff;
config.vci=0xffffffff;
config.mode=NULL;
config.synch=NULL;
config.firmware=NULL;
config.modem_chipset=ECIDC_GS7070;
config.alt_interface_ppp=-1;
config.alt_interface_synch=-1;
file=fopen(eciadsl_conf, "r");
if (file)
{
num=1;
while (!feof(file))
{
fgets(line, 8192, file);
if (*line)
{
/* strtrim */
ptr=line;
while ((*ptr) && (*ptr<=' '))
ptr++;
tmp=ptr;
if (*tmp)
{
while (*tmp++);
tmp--;
while ((tmp>=ptr) && (*tmp<=' '))
tmp--;
if (tmp<ptr)
*ptr=0;
else
*(++tmp)=0;
}
if (*ptr && (*ptr!='#'))
{
tmp=ptr;
while (*tmp)
{
if (*tmp=='=')
{
*tmp++=0;
/*
fputs(ptr, stderr); fputs(" ", stderr);
fputs(tmp, stderr); fputs("\n", stderr);
*/
/* new config parameters - kolja */
if (strcmp(ptr, "MODEM_CHIPSET")==0)
{
char* chipset;
strDup(&chipset, tmp);
set_eci_modem_chipset(chipset);
config.modem_chipset = eci_device.eci_modem_chipset;
}
else
if (strcmp(ptr, "SYNCH_ALTIFACE")==0)
{
get_signed_short_value(tmp, &config.alt_interface_synch);
}
else
if (strcmp(ptr, "PPPOECI_ALTIFACE")==0)
{
get_signed_short_value(tmp, &config.alt_interface_ppp);
}
else
if (strcmp(ptr, "VID1")==0)
{
COPY_HEXA(hexa, tmp);
get_hexa_value(hexa, &config.vid1);
}
else
if (strcmp(ptr, "PID1")==0)
{
COPY_HEXA(hexa, tmp);
get_hexa_value(hexa, &config.pid1);
}
else
if (strcmp(ptr, "VID2")==0)
{
COPY_HEXA(hexa, tmp);
get_hexa_value(hexa, &config.vid2);
}
else
if (strcmp(ptr, "PID2")==0)
{
COPY_HEXA(hexa, tmp);
get_hexa_value(hexa, &config.pid2);
}
else
if (strcmp(ptr, "VPI")==0)
get_unsigned_value(tmp, &config.vpi);
else
if (strcmp(ptr, "VCI")==0)
get_unsigned_value(tmp, &config.vci);
else
if (strcmp(ptr, "MODE")==0)
strDup(&config.mode, tmp);
else
if (strcmp(ptr, "SYNCH")==0)
strDup(&config.synch, tmp);
else
if (strcmp(ptr, "FIRMWARE")==0)
strDup(&config.firmware, tmp);
else
if (
(strcmp(ptr, "PPPD_USER")!=0)
&& (strcmp(ptr, "PPPD_PASSWD")!=0)
&& (strcmp(ptr, "STATICIP")!=0)
&& (strcmp(ptr, "GATEWAY")!=0)
&& (strcmp(ptr, "USE_STATICIP")!=0)
&& (strcmp(ptr, "USE_DHCP")!=0)
&& (strcmp(ptr, "SYNCH_ATTEMPTS")!=0)
&& (strcmp(ptr, "FIRMWARE_OPTIONS")!=0)
&& (strcmp(ptr, "SYNCH_OPTIONS")!=0)
&& (strcmp(ptr, "PPPOECI_OPTIONS")!=0)
&& (strcmp(ptr, "PREFERRED_USB_HUB")!=0)
&& (strcmp(ptr, "MODEM")!=0)
&& (strcmp(ptr, "PROVIDER")!=0)
&& (strcmp(ptr, "DNS1")!=0)
&& (strcmp(ptr, "DNS2")!=0)
)
fprintf(stderr,
"config: unrecognized entry '%s' at line %lu\n",
ptr, num);
}
tmp++;
}
}
}
num++;
}
fclose(file);
if (config.alt_interface_ppp==-1)
config.alt_interface_ppp= eci_device.alt_interface_ppp;
if (config.alt_interface_synch==-1)
config.alt_interface_synch= eci_device.alt_interface_synch;
}
else
fprintf(stderr, "couldn't access %s\n", eciadsl_conf);
/*
fprintf(stderr, "VID1=%04x\n"
"PID1=%04x\n"
"VID2=%04x\n"
"PID2=%04x\n"
"VPI=%d\n"
"VCI=%d\n"
"MODE=%s\n"
"SYNCH=%s\n"
"FIRMWARE=%s\n",
config.vid1, config.pid1, config.vid2, config.pid2,
config.vpi, config.vci,
config.mode,
config.synch, config.firmware
);
*/
}
/* function to show a 'progress bar' during synch sequence - kolja */
char* pchars = "-\\|/";
unsigned int ppos = 0;
inline void printprogres(void){
printf ("\r Please Wait.. Synchronisation in progress [%c]", (char)(pchars[ppos]));
ppos==3 ? ppos=0 : ppos++;
}
inline const char * config_filename()
{
return eciadsl_conf;
}