]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/install+setup/setup/isdn.c
PPP Menue angepasst
[people/pmueller/ipfire-2.x.git] / src / install+setup / setup / isdn.c
1 /* SmoothWall setup program.
2 *
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
5 *
6 * (c) Lawrence Manning, 2001
7 * ISDN probing.
8 *
9 * $Id: isdn.c,v 1.6.2.1 2004/04/14 22:05:41 gespinasse Exp $
10 *
11 */
12
13 #include "setup.h"
14
15 extern FILE *flog;
16 extern char *mylog;
17
18 extern char **ctr;
19
20 extern int automode;
21
22 struct card
23 {
24 char *name;
25 int type;
26 };
27
28 struct card cards[] = {
29 { "", 0 },
30 { "Teles 16.0", 1 },
31 { "Teles 8.0", 2 },
32 { "Teles 16.3 (non PnP)", 3 },
33 { "Teles 16.3c", 14 },
34 { "Teles PCI", 21 },
35 { "Creatix/Teles PnP", 4 },
36 { "AVM A1 (Fritz)", 5 },
37 { "AVM ISA/PCI", 27 },
38 { "AVM PCI/PNP (EXPERIMENTAL driver)", 999 },
39 { "ELSA PCC/PCF cards", 6 },
40 { "ELSA Quickstep 1000", 7 },
41 { "ELSA Quickstep 1000PCI", 18 },
42 { "Eicon Diva ISA Pnp and PCI", 11 },
43 { "ASUS COM ISDNLink", 12 },
44 { "HFC-2BS0 based cards", 13 },
45 { "HFC 2BDS0 PCI", 35 },
46 { "Sedlbauer cards", 15 },
47 { "USR Sportster internal", 16 },
48 { "MIC Card", 17 },
49 { "Compaq ISDN S00 ISA", 19 },
50 { "NETjet PCI card", 20 },
51 { "Dr. Neuhauss Niccy ISA/PCI", 24 },
52 { "Teles S0Box", 25 },
53 { "Sedlbauer Speed Fax+", 28 },
54 { "Siemens I-Surf 1.0", 29 },
55 { "ACER P10", 30 },
56 { "HST Saphir", 31 },
57 { "Telekom A4T", 32 },
58 { "Scitel Quadro", 33 },
59 { "Gazel ISA/PCI", 34 },
60 { "W6692 based PCI cards", 36 },
61 { "ITK ix1-micro Rev.2", 9 },
62 { "NETspider U PCI card", 38 },
63 { "USB ST5481", 998 },
64 { NULL, 0 }
65 };
66
67 void handleisdnprotocol(char **protocolnames);
68 int isdnenabledpressed(void);
69 int isdndisabledpressed(void);
70 void handleisdncard(void);
71 void handlemoduleparams(void);
72 int probeisdncard(void);
73 int probeusbisdncard(char *s);
74 void handleisdnmsn(void);
75
76 int handleisdn(void)
77 {
78 char *protocolnames[] = { ctr[TR_GERMAN_1TR6], ctr[TR_EURO_EDSS1],
79 ctr[TR_LEASED_LINE], ctr[TR_US_NI1], NULL };
80 struct keyvalue *kv;
81 int rc;
82 char protocolname[STRING_SIZE] = "";
83 char cardname[STRING_SIZE] = "";
84 char msn[STRING_SIZE] = "";
85 char temps[STRING_SIZE];
86 int tempd;
87 char message[1000];
88 int c;
89 char *sections[] = { ctr[TR_PROTOCOL_COUNTRY],
90 ctr[TR_SET_ADDITIONAL_MODULE_PARAMETERS], ctr[TR_ISDN_CARD],
91 ctr[TR_MSN_CONFIGURATION], NULL };
92 int choice;
93 char enableddisabled[STRING_SIZE];
94 FILE *f;
95
96 if ((f = fopen(CONFIG_ROOT "/red/active", "r")))
97 {
98 fclose(f);
99 errorbox(ctr[TR_RED_IN_USE]);
100 return 1;
101 }
102
103 /* rc.isdn is a small script to bring down ippp0 and kill ipppd
104 * and removes the ISDN modules. */
105 mysystem("/etc/rc.d/rc.isdn stop");
106
107 choice = 0;
108 for (;;)
109 {
110 kv = initkeyvalues();
111 if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
112 {
113 freekeyvalues(kv);
114 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
115 return 0;
116 }
117
118 strcpy(enableddisabled, ctr[TR_DISABLED]);
119 findkey(kv, "ENABLED", temps);
120 if (strcmp(temps, "on") == 0)
121 strcpy(enableddisabled, ctr[TR_ENABLED]);
122
123 strcpy(temps, "-1");
124 findkey(kv, "PROTOCOL", temps);
125 tempd = atol(temps);
126 if (tempd < 1 || tempd > 4)
127 strcpy(protocolname, ctr[TR_UNSET]);
128 else
129 strcpy(protocolname, protocolnames[tempd - 1]);
130
131 strcpy(temps, "-1");
132 findkey(kv, "TYPE", temps);
133 tempd = atol(temps);
134 c = 0;
135 while (cards[c].name)
136 {
137 if (cards[c].type == tempd)
138 {
139 strcpy(cardname, cards[c].name);
140 break;
141 }
142 c++;
143 }
144 if (!strlen(cardname))
145 strcpy(cardname, ctr[TR_UNSET]);
146
147 strcpy(temps, "");
148 findkey(kv, "MSN", temps);
149 if (strlen(temps))
150 strcpy(msn, temps);
151 else
152 strcpy(msn, ctr[TR_UNSET]);
153 sprintf(message, ctr[TR_ISDN_STATUS], enableddisabled, protocolname,
154 cardname, msn);
155
156 freekeyvalues(kv);
157
158 rc = newtWinMenu(ctr[TR_ISDN_CONFIGURATION_MENU], message, 50, 5, 5, 6,
159 sections, &choice, ctr[TR_OK], ctr[TR_ENABLE_ISDN],
160 ctr[TR_DISABLE_ISDN], NULL);
161
162 if (rc == 1 || rc == 0)
163 {
164 switch (choice)
165 {
166 case 0:
167 handleisdnprotocol(protocolnames);
168 break;
169
170 case 1:
171 handlemoduleparams();
172 break;
173
174 case 2:
175 handleisdncard();
176 break;
177
178 case 3:
179 handleisdnmsn();
180 break;
181
182 default:
183 break;
184 }
185 }
186
187 else if (rc == 2)
188 {
189 if (!isdnenabledpressed())
190 break;
191 }
192 else
193 {
194 if (!(isdndisabledpressed()))
195 break;
196 }
197 }
198
199 return 1;
200 }
201
202 /* Returns 0 if main ISDN setup loop should exit. */
203 int isdndisabledpressed(void)
204 {
205 struct keyvalue *kv = initkeyvalues();
206
207 if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
208 {
209 freekeyvalues(kv);
210 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
211 return 0;
212 }
213
214 replacekeyvalue(kv, "ENABLED", "off");
215 writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
216
217 freekeyvalues(kv);
218
219 return 0;
220 }
221
222 /* Returns 0 if main ISDN setup loop should exit. */
223 int isdnenabledpressed(void)
224 {
225 struct keyvalue *kv = initkeyvalues();
226 char protocol[STRING_SIZE] = "";
227 char type[STRING_SIZE] = "";
228 char msn[STRING_SIZE] = "";
229 char moduleparams[STRING_SIZE] = "";
230 char commandstring[STRING_SIZE];
231 int result = 0;
232
233 if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
234 {
235 freekeyvalues(kv);
236 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
237 return 0;
238 }
239
240 findkey(kv, "PROTOCOL", protocol);
241 findkey(kv, "TYPE", type);
242 findkey(kv, "MSN", msn);
243 findkey(kv, "MODULE_PARAMS", moduleparams);
244
245 if (strlen(protocol) && strlen(type) && strlen(msn))
246 {
247 if (atol(type) == 998)
248 {
249 sprintf(commandstring, "/sbin/modprobe hisax_st5481 protocol=%s %s",
250 protocol, moduleparams);
251 }
252 else if (atol(type) == 999)
253 {
254 sprintf(commandstring, "/sbin/modprobe hisax_fcpcipnp protocol=%s %s",
255 protocol, moduleparams);
256 }
257 else
258 {
259 sprintf(commandstring, "/sbin/modprobe hisax protocol=%s type=%s %s",
260 protocol, type, moduleparams);
261 }
262 if (runcommandwithstatus(commandstring, ctr[TR_INITIALISING_ISDN]) != 0)
263 {
264 errorbox(ctr[TR_UNABLE_TO_INITIALISE_ISDN]);
265 replacekeyvalue(kv, "ENABLED", "off");
266 result = 1;
267 }
268 else
269 replacekeyvalue(kv, "ENABLED", "on");
270 }
271 else
272 {
273 errorbox(ctr[TR_ISDN_NOT_SETUP]);
274 replacekeyvalue(kv, "ENABLED", "off");
275 result = 1;
276 }
277 writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
278
279 freekeyvalues(kv);
280
281 return result;
282 }
283
284 void handleisdnprotocol(char **protocolnames)
285 {
286 int rc;
287 int choice;
288 struct keyvalue *kv = initkeyvalues();
289 char temp[STRING_SIZE] = "1";
290
291 if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
292 {
293 freekeyvalues(kv);
294 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
295 return;
296 }
297 findkey(kv, "PROTOCOL", temp);
298 choice = atol(temp) - 1;
299
300 rc = newtWinMenu(ctr[TR_ISDN_PROTOCOL_SELECTION], ctr[TR_CHOOSE_THE_ISDN_PROTOCOL],
301 50, 5, 5, 6, protocolnames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL);
302
303 if (rc == 2)
304 return;
305
306 sprintf(temp, "%d", choice + 1);
307 replacekeyvalue(kv, "PROTOCOL", temp);
308 writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
309 freekeyvalues(kv);
310 }
311
312 void handlemoduleparams(void)
313 {
314 struct keyvalue *kv = initkeyvalues();
315 char moduleparams[STRING_SIZE] = "";
316 char *values[] = { moduleparams, NULL }; /* pointers for the values. */
317 struct newtWinEntry entries[] =
318 { { "", &values[0], 0,}, { NULL, NULL, 0 } };
319 char title[STRING_SIZE];
320 int rc;
321
322 if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
323 {
324 freekeyvalues(kv);
325 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
326 return;
327 }
328
329 findkey(kv, "MODULE_PARAMS", moduleparams);
330
331 for (;;)
332 {
333 sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
334 rc = newtWinEntries(title, ctr[TR_ENTER_ADDITIONAL_MODULE_PARAMS],
335 50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
336
337 if (rc == 1)
338 {
339 replacekeyvalue(kv, "MODULE_PARAMS", values[0]);
340 writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
341 free(values[0]);
342 break;
343 }
344 else
345 break;
346 }
347 freekeyvalues(kv);
348 }
349
350 void handleisdncard(void)
351 {
352 char **selection;
353 int c;
354 int rc;
355 int choice;
356 int type;
357 struct keyvalue *kv = initkeyvalues();
358 char temp[STRING_SIZE] = "0";
359 int card;
360 char message[STRING_SIZE];
361 char commandstring[STRING_SIZE];
362 char moduleparams[STRING_SIZE] = "";
363 int done = 0;
364
365 if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
366 {
367 freekeyvalues(kv);
368 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
369 return;
370 }
371
372 findkey(kv, "TYPE", temp);
373 type = atol(temp);
374 findkey(kv, "MODULE_PARAMS", moduleparams);
375
376 /* Count cards. */
377 c = 0;
378 while (cards[c].name) c++;
379 selection = malloc((c + 1) * sizeof(char *));
380
381 /* Fill out section. */
382 c = 0;
383 selection[c] = ctr[TR_AUTODETECT];
384 c++;
385 while (cards[c].name)
386 {
387 selection[c] = cards[c].name;
388 c++;
389 }
390 selection[c] = NULL;
391
392 /* Determine inital value for choice. */
393 c = 0; choice = 0;
394 while (cards[c].name)
395 {
396 if (cards[c].type == type)
397 {
398 choice = c;
399 break;
400 }
401 c++;
402 }
403
404 while (!done)
405 {
406 rc = newtWinMenu(ctr[TR_ISDN_CARD_SELECTION], ctr[TR_CHOOSE_THE_ISDN_CARD_INSTALLED],
407 50, 5, 5, 10, selection, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL);
408
409 if (rc == 2)
410 done = 1;
411 else
412 {
413 if (choice == 0)
414 card = probeisdncard();
415 else
416 {
417 sprintf(message, ctr[TR_CHECKING_FOR], cards[choice].name);
418 if (cards[choice].type == 998)
419 {
420 sprintf(commandstring, "/sbin/modprobe hisax_st5481 protocol=1 %s",
421 moduleparams);
422 }
423 else if (cards[choice].type == 999)
424 {
425 sprintf(commandstring, "/sbin/modprobe hisax_fcpcipnp protocol=1 %s",
426 moduleparams);
427 }
428 else
429 {
430 sprintf(commandstring, "/sbin/modprobe hisax type=%d protocol=1 %s",
431 cards[choice].type, moduleparams);
432 }
433 if (runcommandwithstatus(commandstring, message) == 0)
434 card = cards[choice].type;
435 else
436 {
437 errorbox(ctr[TR_ISDN_CARD_NOT_DETECTED]);
438 card = -1;
439 }
440 mysystem("/etc/rc.d/rc.isdn stop");
441 }
442
443 if (card != -1)
444 {
445 sprintf(temp, "%d", card);
446 replacekeyvalue(kv, "TYPE", temp);
447 writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
448 done = 1;
449 }
450 }
451 }
452
453 free(selection);
454 freekeyvalues(kv);
455 }
456
457 int probeusbisdncard(char *s)
458 {
459 FILE *file;
460 char buf[STRING_SIZE];
461 int found = 0;
462
463 if (!(file = fopen("/proc/bus/usb/devices", "r")))
464 {
465 fprintf(flog, "Unable to open /proc/bus/usb/devices in probeusbisdncard()\n");
466 return 0;
467 }
468
469 while (fgets(buf, STRING_SIZE, file)) {
470 if (strstr(buf, s)) {
471 found = 1;
472 }
473 }
474
475 fclose(file);
476
477 return found;
478 }
479
480 int probeisdncard(void)
481 {
482 int c;
483 char message[STRING_SIZE];
484 char commandstring[STRING_SIZE];
485 char moduleparams[STRING_SIZE] = "";
486 struct keyvalue *kv = initkeyvalues();
487 char title[STRING_SIZE];
488 int result = -1;
489
490 if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
491 {
492 freekeyvalues(kv);
493 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
494 return -1;
495 }
496 findkey(kv, "MODULE_PARAMS", moduleparams);
497
498 c = 1;
499 while (cards[c].name)
500 {
501 sprintf(message, ctr[TR_CHECKING_FOR], cards[c].name);
502 if (cards[c].type == 998)
503 {
504 /* Try to find if it exists, but should generalize
505 * probeusbisdncard to pass Vendor and ProdID
506 * independently, rather than a string
507 */
508 if (probeusbisdncard("Vendor=0483 ProdID=481"))
509 sprintf(commandstring, "/sbin/modprobe hisax_st5481 protocol=1 %s", moduleparams);
510 }
511 else if (cards[c].type == 999)
512 {
513 sprintf(commandstring, "/sbin/modprobe hisax_fcpcipnp protocol=1 %s",
514 moduleparams);
515 }
516 else
517 {
518 sprintf(commandstring, "/sbin/modprobe hisax type=%d protocol=1 %s",
519 cards[c].type, moduleparams);
520 }
521 if (runcommandwithstatus(commandstring, message) == 0)
522 {
523 mysystem("/etc/rc.d/rc.isdn stop");
524 sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
525 sprintf(message, ctr[TR_DETECTED], cards[c].name);
526 newtWinMessage(title, ctr[TR_OK], message);
527 result = cards[c].type;
528 goto EXIT;
529 }
530 c++;
531 }
532
533 errorbox(ctr[TR_UNABLE_TO_FIND_AN_ISDN_CARD]);
534
535 EXIT:
536 freekeyvalues(kv);
537
538 return result;
539 }
540
541 void handleisdnmsn(void)
542 {
543 struct keyvalue *kv = initkeyvalues();
544 char msn[STRING_SIZE] = "";
545 char *values[] = { msn, NULL }; /* pointers for the values. */
546 struct newtWinEntry entries[] =
547 { { "", &values[0], 0,}, { NULL, NULL, 0 } };
548 char title[STRING_SIZE];
549 int rc;
550
551 if (!(readkeyvalues(kv, CONFIG_ROOT "/isdn/settings")))
552 {
553 freekeyvalues(kv);
554 errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
555 return;
556 }
557 findkey(kv, "MSN", msn);
558
559 for (;;)
560 {
561 sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN);
562 rc = newtWinEntries(title, ctr[TR_ENTER_THE_LOCAL_MSN],
563 50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL);
564
565 if (rc == 1)
566 {
567 if (!(strlen(values[0])))
568 errorbox(ctr[TR_PHONENUMBER_CANNOT_BE_EMPTY]);
569 else
570 {
571 replacekeyvalue(kv, "MSN", values[0]);
572 writekeyvalues(kv, CONFIG_ROOT "/isdn/settings");
573 free(values[0]);
574 break;
575 }
576 }
577 else
578 break;
579 }
580 freekeyvalues(kv);
581 }