From: Eric s. J. <esj...@us...> - 2002-09-04 21:46:17
|
Update of /cvsroot/ipcop/ipcop/src/install+setup/setup In directory usw-pr-cvs1:/tmp/cvs-serv28483/src/install+setup/setup Added Files: Tag: IPCOP_v0_1 pciadsl.c Log Message: teh rest of the PCI-ADSL code --- NEW FILE: pciadsl.c --- /* IPCOP PCI ADSL setup program. * * Based on isdn.c - * This program is distributed under the terms of the GNU General Public * Licence. See the file COPYING for details. * * (c) Lawrence Manning, 2001 * * modified by catnipboy 24/08/2002 * * $Id: pciadsl.c,v 1.1.2.1 2002/09/04 21:46:13 esjatharvee Exp $ * */ #include "setup.h" extern FILE *flog; extern char *log; extern char **ctr; extern int automode; void handlepciadslprotocol(char **protocolnames); int pciadslenabledpressed(void); int pciadsldisabledpressed(void); void handlepciadslvpi(void); void handlepciadslvci(void); void handlepciadslencap(char **encaptype); int handlepciadsl(void) { char *protocolnames[] = { "RFC2364", "RFC1483", NULL }; char *encaptype_2364[] = { ctr[TR_PCIADSL_VC], ctr[TR_PCIADSL_LLC], NULL }; char *encaptype_1483[] = { ctr[TR_PCIADSL_BRIDGED_ETHERNET_LLC], ctr[TR_PCIADSL_BRIDGED_ETHERNET_VC], ctr[TR_PCIADSL_ROUTED_IP_LLC], ctr[TR_PCIADSL_ROUTED_IP_VC], "RFC1577", NULL }; struct keyvalue *kv; int rc; char protocolname[STRING_SIZE] = ""; char encapname[STRING_SIZE] = ""; char vpi[STRING_SIZE] = ""; char vci[STRING_SIZE] = ""; char temps[STRING_SIZE]; int tempd; char message[1000]; char *sections[] = { ctr[TR_PCIADSL_PROTOCOL], ctr[TR_PCIADSL_VPI], ctr[TR_PCIADSL_VCI], ctr[TR_PCIADSL_ENCAP], NULL }; char sections_lang[5][STRING_SIZE]; int choice; char enableddisabled[STRING_SIZE]; FILE *f; if ((f = fopen(CONFIG_ROOT "/red/active", "r"))) { fclose(f); errorbox(ctr[TR_PCIADSL_RED_BUSY]); return 1; } /* pciadsl-cleanup is a small script to bring down ppp0 and kill pppd * and removes the modules. */ mysystem("/etc/ppp/pciadsl-cleanup"); choice = 0; for (;;) { kv = initkeyvalues(); if (!(readkeyvalues(kv, CONFIG_ROOT "/pciadsl/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } strcpy(enableddisabled, ctr[TR_DISABLED]); findkey(kv, "ENABLED", temps); if (strcmp(temps, "on") == 0) strcpy(enableddisabled, ctr[TR_ENABLED]); strcpy(temps, ""); findkey(kv, "PROTOCOL", temps); if ((!strcmp(temps, "RFC1483")) || (!strcmp(temps, "RFC2364"))) strcpy(protocolname, temps); else strcpy(protocolname, ctr[TR_UNSET]); strcpy(temps, ""); findkey(kv, "VPI", temps); if (strlen(temps)) strcpy(vpi, temps); else strcpy(vpi, ctr[TR_UNSET]); strcpy(temps, ""); findkey(kv, "VCI", temps); if (strlen(temps)) strcpy(vci, temps); else strcpy(vci, ctr[TR_UNSET]); strcpy(temps, "-1"); findkey(kv, "ENCAP", temps); tempd = atol(temps); if (!strlen(temps)) tempd=-1; if (strcmp(protocolname, "RFC1483")==0) { if (tempd < 0 || tempd > 4) strcpy(encapname, ctr[TR_UNSET]); else strcpy(encapname, encaptype_1483[tempd]); } else { if (tempd < 0 || tempd > 1) strcpy(encapname, ctr[TR_UNSET]); else strcpy(encapname, encaptype_2364[tempd]); } sprintf(message, "%s %s.\n\n" \ " %s: %s\n" \ " %s: %s\n" \ " %s: %s\n" \ " %s: %s\n\n", ctr[TR_PCIADSL_IS_CURRENTLY], enableddisabled, ctr[TR_PCIADSL_PROTOCOL], protocolname, ctr[TR_PCIADSL_VPI],vpi, ctr[TR_PCIADSL_VCI],vci, ctr[TR_PCIADSL_ENCAP], encapname); freekeyvalues(kv); rc = newtWinMenu(ctr[TR_PCIADSL_CONFIGURATION], message, 50, 5, 5, 6, sections, &choice, ctr[TR_OK], ctr[TR_PCIADSL_ENABLE], ctr[TR_PCIADSL_DISABLE], NULL); if (rc == 1 || rc == 0) { switch (choice) { case 0: handlepciadslprotocol(protocolnames); break; case 1: handlepciadslvpi(); break; case 2: handlepciadslvci(); break; case 3: if (!strcmp(protocolname, "RFC1483")) handlepciadslencap(encaptype_1483); else handlepciadslencap(encaptype_2364); break; default: break; } } else if (rc == 2) { if (!pciadslenabledpressed()) break; } else { if (!(pciadsldisabledpressed())) break; } } return 1; } /* Returns 0 if main PCI ADSL setup loop should exit. */ int pciadsldisabledpressed(void) { struct keyvalue *kv = initkeyvalues(); if (!(readkeyvalues(kv, CONFIG_ROOT "/pciadsl/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } replacekeyvalue(kv, "ENABLED", "off"); writekeyvalues(kv, CONFIG_ROOT "/pciadsl/settings"); freekeyvalues(kv); return 0; } /* Returns 0 if main PCI ADSL setup loop should exit. */ int pciadslenabledpressed(void) { struct keyvalue *kv = initkeyvalues(); char protocol[STRING_SIZE] = ""; char vpi[STRING_SIZE] = ""; char vci[STRING_SIZE] = ""; char encap[STRING_SIZE] = ""; int result = 0; if (!(readkeyvalues(kv, CONFIG_ROOT "/pciadsl/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return 0; } findkey(kv, "PROTOCOL", protocol); findkey(kv, "VPI", vpi); findkey(kv, "VCI", vci); findkey(kv, "ENCAP", encap); if (strlen(protocol) && strlen(vpi) && strlen(vci) && strlen(encap)) { replacekeyvalue(kv, "ENABLED", "on"); writekeyvalues(kv, CONFIG_ROOT "/pciadsl/settings"); /* don't bother restarting PCI ADSL if in automode */ if (automode == 0) { mysystem("/etc/rc.d/rc.pciadsl"); /* RFC1483 uses Ethernet, so restart networking */ if (!strcmp(protocol, "RFC1483")) { runcommandwithstatus("/etc/rc.d/rc.netaddress.down NOTGREEN", ctr[TR_PUSHING_NON_LOCAL_NETWORK_DOWN]); runcommandwithstatus("/etc/rc.d/rc.netaddress.up NOTGREEN", ctr[TR_PULLING_NETWORK_UP]); } } } else { errorbox(ctr[TR_PCIADSL_NOT_SETUP]); replacekeyvalue(kv, "ENABLED", "off"); writekeyvalues(kv, CONFIG_ROOT "/pciadsl/settings"); result = 1; } freekeyvalues(kv); return result; } void handlepciadslprotocol(char **protocolnames) { int rc; int choice = 0; struct keyvalue *kv = initkeyvalues(); if (!(readkeyvalues(kv, CONFIG_ROOT "/pciadsl/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return; } rc = newtWinMenu(ctr[TR_PCIADSL_PROTOCOL_SELECTION], ctr[TR_PCIADSL_CHOOSE_PROTOCOL], 50, 5, 5, 6, protocolnames, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 2) return; replacekeyvalue(kv, "PROTOCOL", protocolnames[choice]); /* blank the encapsulation value - this should depend on protocol */ replacekeyvalue(kv, "ENCAP", ""); writekeyvalues(kv, CONFIG_ROOT "/pciadsl/settings"); freekeyvalues(kv); } void handlepciadslvpi(void) { struct keyvalue *kv = initkeyvalues(); char vpi[STRING_SIZE] = ""; char *values[] = { vpi, NULL }; /* pointers for the values. */ struct newtWinEntry entries[] = { { "", &values[0], 0,}, { NULL, NULL, 0 } }; char title[STRING_SIZE]; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "/pciadsl/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return; } findkey(kv, "VPI", vpi); for (;;) { sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN); rc = newtWinEntries(title, ctr[TR_PCIADSL_ENTER_VPI], 50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 1) { if (!(strlen(values[0]))) errorbox(ctr[TR_PCIADSL_VPI_CANNOT_BE_EMPTY]); else { replacekeyvalue(kv, "VPI", values[0]); writekeyvalues(kv, CONFIG_ROOT "/pciadsl/settings"); free(values[0]); break; } } else break; } freekeyvalues(kv); } void handlepciadslvci(void) { struct keyvalue *kv = initkeyvalues(); char vci[STRING_SIZE] = ""; char *values[] = { vci, NULL }; /* pointers for the values. */ struct newtWinEntry entries[] = { { "", &values[0], 0,}, { NULL, NULL, 0 } }; char title[STRING_SIZE]; int rc; if (!(readkeyvalues(kv, CONFIG_ROOT "/pciadsl/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return; } findkey(kv, "VCI", vci); for (;;) { sprintf (title, "%s v%s - %s", NAME, VERSION, SLOGAN); rc = newtWinEntries(title, ctr[TR_PCIADSL_ENTER_VCI], 50, 5, 5, 40, entries, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 1) { if (!(strlen(values[0]))) errorbox(ctr[TR_PCIADSL_VCI_CANNOT_BE_EMPTY]); else { replacekeyvalue(kv, "VCI", values[0]); writekeyvalues(kv, CONFIG_ROOT "/pciadsl/settings"); free(values[0]); break; } } else break; } freekeyvalues(kv); } void handlepciadslencap(char **encaptype) { int rc; int choice; struct keyvalue *kv = initkeyvalues(); char temp[STRING_SIZE] = "0"; if (!(readkeyvalues(kv, CONFIG_ROOT "/pciadsl/settings"))) { freekeyvalues(kv); errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]); return; } findkey(kv, "ENCAP", temp); choice = atol(temp); rc = newtWinMenu(ctr[TR_PCIADSL_ENCAP_SELECT], ctr[TR_PCIADSL_CHOOSE_ENCAP], 50, 5, 5, 6, encaptype, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL); if (rc == 2) return; sprintf(temp, "%d", choice); replacekeyvalue(kv, "ENCAP", temp); writekeyvalues(kv, CONFIG_ROOT "/pciadsl/settings"); freekeyvalues(kv); } |