1 /* SmoothWall setup program.
3 * This program is distributed under the terms of the GNU General Public
4 * Licence. See the file COPYING for details.
6 * (c) Lawrence Manning, 2001
9 * $Id: isdn.c,v 1.6.2.1 2004/04/14 22:05:41 gespinasse Exp $
28 struct card cards
[] = {
32 { "Teles 16.3 (non PnP)", 3 },
33 { "Teles 16.3c", 14 },
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 },
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 },
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 },
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);
78 char *protocolnames
[] = { ctr
[TR_GERMAN_1TR6
], ctr
[TR_EURO_EDSS1
],
79 ctr
[TR_LEASED_LINE
], ctr
[TR_US_NI1
], NULL
};
82 char protocolname
[STRING_SIZE
] = "";
83 char cardname
[STRING_SIZE
] = "";
84 char msn
[STRING_SIZE
] = "";
85 char temps
[STRING_SIZE
];
89 char *sections
[] = { ctr
[TR_PROTOCOL_COUNTRY
],
90 ctr
[TR_SET_ADDITIONAL_MODULE_PARAMETERS
], ctr
[TR_ISDN_CARD
],
91 ctr
[TR_MSN_CONFIGURATION
], NULL
};
93 char enableddisabled
[STRING_SIZE
];
96 if ((f
= fopen(CONFIG_ROOT
"/red/active", "r")))
99 errorbox(ctr
[TR_RED_IN_USE
]);
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");
110 kv
= initkeyvalues();
111 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/isdn/settings")))
114 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
118 strcpy(enableddisabled
, ctr
[TR_DISABLED
]);
119 findkey(kv
, "ENABLED", temps
);
120 if (strcmp(temps
, "on") == 0)
121 strcpy(enableddisabled
, ctr
[TR_ENABLED
]);
124 findkey(kv
, "PROTOCOL", temps
);
126 if (tempd
< 1 || tempd
> 4)
127 strcpy(protocolname
, ctr
[TR_UNSET
]);
129 strcpy(protocolname
, protocolnames
[tempd
- 1]);
132 findkey(kv
, "TYPE", temps
);
135 while (cards
[c
].name
)
137 if (cards
[c
].type
== tempd
)
139 strcpy(cardname
, cards
[c
].name
);
144 if (!strlen(cardname
))
145 strcpy(cardname
, ctr
[TR_UNSET
]);
148 findkey(kv
, "MSN", temps
);
152 strcpy(msn
, ctr
[TR_UNSET
]);
153 sprintf(message
, ctr
[TR_ISDN_STATUS
], enableddisabled
, protocolname
,
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
);
162 if (rc
== 1 || rc
== 0)
167 handleisdnprotocol(protocolnames
);
171 handlemoduleparams();
189 if (!isdnenabledpressed())
194 if (!(isdndisabledpressed()))
202 /* Returns 0 if main ISDN setup loop should exit. */
203 int isdndisabledpressed(void)
205 struct keyvalue
*kv
= initkeyvalues();
207 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/isdn/settings")))
210 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
214 replacekeyvalue(kv
, "ENABLED", "off");
215 writekeyvalues(kv
, CONFIG_ROOT
"/isdn/settings");
222 /* Returns 0 if main ISDN setup loop should exit. */
223 int isdnenabledpressed(void)
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
];
233 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/isdn/settings")))
236 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
240 findkey(kv
, "PROTOCOL", protocol
);
241 findkey(kv
, "TYPE", type
);
242 findkey(kv
, "MSN", msn
);
243 findkey(kv
, "MODULE_PARAMS", moduleparams
);
245 if (strlen(protocol
) && strlen(type
) && strlen(msn
))
247 if (atol(type
) == 998)
249 sprintf(commandstring
, "/sbin/modprobe hisax_st5481 protocol=%s %s",
250 protocol
, moduleparams
);
252 else if (atol(type
) == 999)
254 sprintf(commandstring
, "/sbin/modprobe hisax_fcpcipnp protocol=%s %s",
255 protocol
, moduleparams
);
259 sprintf(commandstring
, "/sbin/modprobe hisax protocol=%s type=%s %s",
260 protocol
, type
, moduleparams
);
262 if (runcommandwithstatus(commandstring
, ctr
[TR_INITIALISING_ISDN
]) != 0)
264 errorbox(ctr
[TR_UNABLE_TO_INITIALISE_ISDN
]);
265 replacekeyvalue(kv
, "ENABLED", "off");
269 replacekeyvalue(kv
, "ENABLED", "on");
273 errorbox(ctr
[TR_ISDN_NOT_SETUP
]);
274 replacekeyvalue(kv
, "ENABLED", "off");
277 writekeyvalues(kv
, CONFIG_ROOT
"/isdn/settings");
284 void handleisdnprotocol(char **protocolnames
)
288 struct keyvalue
*kv
= initkeyvalues();
289 char temp
[STRING_SIZE
] = "1";
291 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/isdn/settings")))
294 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
297 findkey(kv
, "PROTOCOL", temp
);
298 choice
= atol(temp
) - 1;
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
);
306 sprintf(temp
, "%d", choice
+ 1);
307 replacekeyvalue(kv
, "PROTOCOL", temp
);
308 writekeyvalues(kv
, CONFIG_ROOT
"/isdn/settings");
312 void handlemoduleparams(void)
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
];
322 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/isdn/settings")))
325 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
329 findkey(kv
, "MODULE_PARAMS", moduleparams
);
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
);
339 replacekeyvalue(kv
, "MODULE_PARAMS", values
[0]);
340 writekeyvalues(kv
, CONFIG_ROOT
"/isdn/settings");
350 void handleisdncard(void)
357 struct keyvalue
*kv
= initkeyvalues();
358 char temp
[STRING_SIZE
] = "0";
360 char message
[STRING_SIZE
];
361 char commandstring
[STRING_SIZE
];
362 char moduleparams
[STRING_SIZE
] = "";
365 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/isdn/settings")))
368 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
372 findkey(kv
, "TYPE", temp
);
374 findkey(kv
, "MODULE_PARAMS", moduleparams
);
378 while (cards
[c
].name
) c
++;
379 selection
= malloc((c
+ 1) * sizeof(char *));
381 /* Fill out section. */
383 selection
[c
] = ctr
[TR_AUTODETECT
];
385 while (cards
[c
].name
)
387 selection
[c
] = cards
[c
].name
;
392 /* Determine inital value for choice. */
394 while (cards
[c
].name
)
396 if (cards
[c
].type
== type
)
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
);
414 card
= probeisdncard();
417 sprintf(message
, ctr
[TR_CHECKING_FOR
], cards
[choice
].name
);
418 if (cards
[choice
].type
== 998)
420 sprintf(commandstring
, "/sbin/modprobe hisax_st5481 protocol=1 %s",
423 else if (cards
[choice
].type
== 999)
425 sprintf(commandstring
, "/sbin/modprobe hisax_fcpcipnp protocol=1 %s",
430 sprintf(commandstring
, "/sbin/modprobe hisax type=%d protocol=1 %s",
431 cards
[choice
].type
, moduleparams
);
433 if (runcommandwithstatus(commandstring
, message
) == 0)
434 card
= cards
[choice
].type
;
437 errorbox(ctr
[TR_ISDN_CARD_NOT_DETECTED
]);
440 mysystem("/etc/rc.d/rc.isdn stop");
445 sprintf(temp
, "%d", card
);
446 replacekeyvalue(kv
, "TYPE", temp
);
447 writekeyvalues(kv
, CONFIG_ROOT
"/isdn/settings");
457 int probeusbisdncard(char *s
)
460 char buf
[STRING_SIZE
];
463 if (!(file
= fopen("/proc/bus/usb/devices", "r")))
465 fprintf(flog
, "Unable to open /proc/bus/usb/devices in probeusbisdncard()\n");
469 while (fgets(buf
, STRING_SIZE
, file
)) {
470 if (strstr(buf
, s
)) {
480 int probeisdncard(void)
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
];
490 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/isdn/settings")))
493 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
496 findkey(kv
, "MODULE_PARAMS", moduleparams
);
499 while (cards
[c
].name
)
501 sprintf(message
, ctr
[TR_CHECKING_FOR
], cards
[c
].name
);
502 if (cards
[c
].type
== 998)
504 /* Try to find if it exists, but should generalize
505 * probeusbisdncard to pass Vendor and ProdID
506 * independently, rather than a string
508 if (probeusbisdncard("Vendor=0483 ProdID=481"))
509 sprintf(commandstring
, "/sbin/modprobe hisax_st5481 protocol=1 %s", moduleparams
);
511 else if (cards
[c
].type
== 999)
513 sprintf(commandstring
, "/sbin/modprobe hisax_fcpcipnp protocol=1 %s",
518 sprintf(commandstring
, "/sbin/modprobe hisax type=%d protocol=1 %s",
519 cards
[c
].type
, moduleparams
);
521 if (runcommandwithstatus(commandstring
, message
) == 0)
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
;
533 errorbox(ctr
[TR_UNABLE_TO_FIND_AN_ISDN_CARD
]);
541 void handleisdnmsn(void)
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
];
551 if (!(readkeyvalues(kv
, CONFIG_ROOT
"/isdn/settings")))
554 errorbox(ctr
[TR_UNABLE_TO_OPEN_SETTINGS_FILE
]);
557 findkey(kv
, "MSN", msn
);
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
);
567 if (!(strlen(values
[0])))
568 errorbox(ctr
[TR_PHONENUMBER_CANNOT_BE_EMPTY
]);
571 replacekeyvalue(kv
, "MSN", values
[0]);
572 writekeyvalues(kv
, CONFIG_ROOT
"/isdn/settings");