* (c) Lawrence Manning, 2001
* Contains network library functions.
*
- * $Id: netstuff.c,v 1.19.2.7 2004/11/05 23:40:17 alanh Exp $
- *
*/
#include "libsmooth.h"
extern char **ctr;
+extern struct nic nics[];
+extern struct knic knics[];
+
+int scanned_nics_read_done = 0;
+
newtComponent networkform;
newtComponent addressentry;
newtComponent netmaskentry;
}
return 1;
}
-
-/* Network probing! */
-struct nic nics[] = {
- { "100VG-AnyLan Network Adapters, HP J2585B, J2585A, etc", "hp100" },
- { "3Com EtherLink III", "3c509" },
- { "3Com 3c501", "3c501" },
- { "3Com ISA EtherLink XL", "3c515" },
- { "3Com 3c503 and 3c503/16", "3c503" },
- { "3Com EtherLink MC (3c523)", "3c523" },
- { "3Com EtherLink MC/32 (3c527)", "3c527" },
- { "3Com EtherLink Plus (3c505)", "3c505" },
- { "3Com EtherLink 16", "3c507" },
- { "3Com \"Corkscrew\" EtherLink PCI III/XL, etc.", "3c59x" },
- { "3Com Typhoon Family (3C990, 3CR990, and variants)", "typhoon" },
- { "Adaptec Starfire/DuraLAN", "starfire" },
- { "Alteon AceNIC/3Com 3C985/Netgear GA620 Gigabit", "acenic" },
- { "AMD8111 based 10/100 Ethernet Controller", "amd8111e" },
- { "AMD LANCE/PCnetAllied Telesis AT1500, J2405A, etc", "lance" },
- { "AMD PCnet32 and AMD PCnetPCI", "pcnet32" },
- { "Ansel Communications EISA 3200", "ac3200" },
- { "Apricot 680x0 VME, 82596 chipset", "82596" },
- { "AT1700/1720", "at1700" },
- { "Broadcom 4400", "b44" },
- { "Broadcom Tigon3", "tg3" },
- { "Cabletron E2100 series ethercards", "e2100" },
- { "CATC USB NetMate-based Ethernet", "catc" },
- { "CDC USB Ethernet", "CDCEther" },
- { "Crystal LAN CS8900/CS8920", "cs89x0" },
- { "Compaq Netelligent 10/100 TX PCI UTP, etc", "tlan" },
- { "D-Link DL2000-based Gigabit Ethernet", "dl2k" },
- { "Digi Intl. RightSwitch SE-X EISA and PCI", "dgrs" },
- { "Digital 21x4x Tulip PCI ethernet cards, etc.", "tulip" },
- { "Digital DEPCA & EtherWORKS,DEPCA, DE100, etc", "depca" },
- { "DM9102 PCI Fast Ethernet Adapter", "dmfe", },
- { "Dummy Network Card (testing)", "dummy", },
- { "EtherWORKS DE425 TP/COAX EISA, DE434 TP PCI, etc.", "de4x5" },
- { "EtherWORKS 3 (DE203, DE204 and DE205)", "ewrk3" },
- { "HP PCLAN/plus", "hp-plus" },
- { "HP LAN ethernet", "hp" },
- { "IBM LANA", "ibmlana" },
- { "ICL EtherTeam 16i/32" ,"eth16i" },
- { "Intel i82557/i82558 PCI EtherExpressPro", "e100" },
- { "Intel EtherExpress Cardbus Ethernet", "eepro100_cb" },
- { "Intel i82595 ISA EtherExpressPro10/10+ driver" ,"eepro" },
- { "Intel EtherExpress 16 (i82586)", "eexpress" },
- { "Intel Panther onboard i82596 driver", "lp486e" },
- { "Intel PRO/1000 Gigabit Ethernet", "e1000" },
- { "KLSI USB KL5USB101-based", "kaweth" },
- { "MiCom-Interlan NI5010 ethercard", "ni5010" },
- { "Mylex EISA LNE390A/B", "lne390", },
- { "Myson MTD-8xx PCI Ethernet", "fealnx" },
- { "National Semiconductor DP8381x" , "natsemi" },
- { "National Semiconductor DP83820" , "ns83820" },
- { "NE/2 MCA", "ne2" },
- { "NE2000 PCI cards, RealTEk RTL-8029, etc", "ne2k-pci" },
- { "NE1000 / NE2000 (non-pci)", "ne" },
- { "NI50 card (i82586 Ethernet chip)", "ni52" },
- { "NI6510, ni6510 EtherBlaster", "ni65" },
- { "Novell/Eagle/Microdyne NE3210 EISA", "ne3210" },
- { "NVidia Nforce2 Driver", "forcedeth" },
- { "Packet Engines Hamachi GNIC-II", "hamachi" },
- { "Packet Engines Yellowfin Gigabit-NIC", "yellowfin" },
- { "Pegasus/Pegasus-II USB ethernet", "pegasus" },
- { "PureData PDUC8028,WD8003 and WD8013 compatibles", "wd" },
- { "Racal-Interlan EISA ES3210", "es3210" },
- { "RealTek RTL-8139 Fast Ethernet", "8139too" },
- { "RealTek RTL-8139C+ series 10/100 PCI Ethernet", "8139cp" },
- { "RealTek RTL-8150 USB ethernet", "rtl8150" },
- { "RealTek RTL-8169 Gigabit Ethernet", "r8169" },
- { "SiS 900 PCI", "sis900" },
- { "SKnet MCA", "sk_mca" },
- { "SMC 9000 series of ethernet cards", "smc9194" },
- { "SMC EtherPower II", "epic100" },
- { "SMC Ultra/EtherEZ ISA/PnP Ethernet", "smc-ultra" },
- { "SMC Ultra32 EISA Ethernet", "smc-ultra32" },
- { "SMC Ultra MCA Ethernet", "smc-mca" },
- { "Sundance Alta", "sundance" },
- { "SysKonnect SK-98xx", "sk98lin" },
- { "Toshiba TC35815 Ethernet", "tc35815" },
- { "Tulip chipset Cardbus Ethernet", "tulip_cb" },
- { "USB Ethernet", "usbnet" },
- { "VIA Rhine PCI Fast Ethernet, etc", "via-rhine" },
- { "Winbond W89c840 Ethernet", "winbond-840" },
- { "Xircom Cardbus Ethernet", "xircom_cb" },
- { "Xircom (tulip-like) Cardbus Ethernet", "xircom_tulip_cb" },
- { NULL, NULL }
-};
/* Funky routine for loading all drivers (cept those are already loaded.). */
int probecards(char *driver, char *driveroptions)
{
- int c;
- char **sections;
- char drivercount;
- int rc;
- int choice;
- int done = 0;
- char message[1000];
+ return 0;
+}
+
+/* ### alter strupper ###
+char *strupper(char *s)
+{
+ int n;
+ for (n=0;s[n];n++) s[n]=toupper(s[n]);
+ return s;
+}
+*/
+
+/* neuer StringUpper, wird zur Zeit nicht benutzt da UTF-8 nicht geht.
+void strupper(unsigned char *string)
+{
+ unsigned char *str;
+ for (str = string; *str != '\0'; str++)
+ if (!(*str & 0x80) && islower(*str))
+ *str = toupper(*str);
+}
+*/
+
+int write_configs_netudev(char *description, char *macaddr, char *colour)
+{
+ #define UDEV_NET_CONF "/etc/udev/rules.d/30-persistent-network.rules"
+ FILE *fp;
char commandstring[STRING_SIZE];
- FILE *handle;
- char line[STRING_SIZE];
-
- /* Count all nics. */
- mysystem("/bin/probenic.sh count");
- if ((handle = fopen("/drivercount", "r")))
- fgets(line, STRING_SIZE-1, handle);
- fclose(handle);
- //system("rm -f /drivercount");
- line[strlen(line) - 1] = 0;
- drivercount = strtok(line, ".");
- fprintf(flog, "Detected %s NICs in your system.\n", drivercount);
- if (!drivercount > 0) {
- return 1;
- }
+ struct keyvalue *kv = initkeyvalues();
+ char temp1[STRING_SIZE], temp2[STRING_SIZE], temp3[STRING_SIZE];
+ char ucolour[STRING_SIZE];
- sections = malloc(drivercount * sizeof(char *));
+// sprintf(ucolour, colour);
+// strupper(ucolour);
- struct driver drivers[drivercount];
- strcpy(drivers[0].modulename, "pcnet32");
+ switch (*colour)
+ {
+ case 'g': sprintf(ucolour, "GREEN");
+ strcpy(knics[_GREEN_CARD_].description, description);
+ strcpy(knics[_GREEN_CARD_].macaddr, macaddr);
+ break;
+ case 'r': sprintf(ucolour, "RED");
+ strcpy(knics[_RED_CARD_].description, description);
+ strcpy(knics[_RED_CARD_].macaddr, macaddr);
+ break;
+ case 'o': sprintf(ucolour, "ORANGE");
+ strcpy(knics[_ORANGE_CARD_].description, description);
+ strcpy(knics[_ORANGE_CARD_].macaddr, macaddr);
+ break;
+ case 'b': sprintf(ucolour, "BLUE");
+ strcpy(knics[_BLUE_CARD_].description, description);
+ strcpy(knics[_BLUE_CARD_].macaddr, macaddr);
+ break;
+ default: sprintf(ucolour, "DUMMY");
+ break;
+ }
- fprintf(flog, "TEST0.\n");
- c = 0;
- while (drivers[c - 1].modulename)
+ if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
{
- sections[c] = drivers[c - 1].description;
- fprintf(flog, "TEST1.\n");
- c++;
+ freekeyvalues(kv);
+ errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
+ return 0;
}
- sections[c] = NULL;
- fprintf(flog, "TEST2.\n");
+
+ sprintf(temp1, "%s_DEV", ucolour);
+ sprintf(temp2, "%s_MACADDR", ucolour);
+ sprintf(temp3, "%s0", colour);
+ replacekeyvalue(kv, temp1, temp3);
+ replacekeyvalue(kv, temp2, macaddr);
+ sprintf(temp1, "%s_DESCRIPTION", ucolour);
+ replacekeyvalue(kv, temp1, description);
+
+ writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
+ freekeyvalues(kv);
- strcpy(driver, "");
- strcpy(driveroptions, "");
+ // Make sure that there is no conflict
+ snprintf(commandstring, STRING_SIZE, "/usr/bin/touch "UDEV_NET_CONF" >/dev/null 2>&1");
+ system(commandstring);
+
+ snprintf(commandstring, STRING_SIZE, "/bin/cat "UDEV_NET_CONF" | /bin/grep -v \"%s\" > "UDEV_NET_CONF" 2>/dev/null", macaddr);
+ system(commandstring);
+
+ snprintf(commandstring, STRING_SIZE, "/bin/cat "UDEV_NET_CONF" | /bin/grep -v \"%s\" > "UDEV_NET_CONF" 2>/dev/null", colour);
+ system(commandstring);
- done = 0; choice = 1;
- while (!done)
+ if( (fp = fopen(UDEV_NET_CONF, "a")) == NULL )
{
- rc = newtWinMenu(ctr[TR_SELECT_NETWORK_DRIVER],
- ctr[TR_SELECT_NETWORK_DRIVER_LONG], 50, 5, 5, 6,
- sections, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL);
- if (rc == 0 || rc == 1)
- {
- if (choice > 0)
- {
- /* Find module number, load module. */
- c = choice - 1;
-
- if (!checkformodule(nics[c].modulename))
- {
- sprintf(commandstring, "/sbin/modprobe %s", nics[c].modulename);
- sprintf(message, ctr[TR_LOOKING_FOR_NIC], nics[c].description);
- if (runcommandwithstatus(commandstring, message) == 0)
- {
- strcpy(driver, nics[c].modulename);
- strcpy(driveroptions, "");
- done = 1;
- }
- else
- errorbox(ctr[TR_UNABLE_TO_LOAD_DRIVER_MODULE]);
- }
- else
- errorbox(ctr[TR_THIS_DRIVER_MODULE_IS_ALREADY_LOADED]);
- }
- else
- {
- manualdriver(driver, driveroptions);
- if (strlen(driver))
- done = 1;
- }
- }
- else
- done = 1;
+ fprintf(stderr,"Couldn't open" UDEV_NET_CONF);
+ return 1;
}
+ fprintf(fp,"ACTION==\"add\", SUBSYSTEM==\"net\", SYSFS{address}==\"%s\", NAME=\"%s0\" # %s\n", macaddr, colour, description);
+ fclose(fp);
return 0;
}
-/* A listbox for selected the card... with a * MANUAL * entry at top for
- * manual module names. */
-int choosecards(char *driver, char *driveroptions)
+int scan_network_cards(void)
{
- int c;
- char **sections;
- int drivercount;
- int rc;
- int choice;
- char commandstring[STRING_SIZE];
- char message[STRING_SIZE];
- int done = 0;
-
- /* Count 'em */
- c = 0; drivercount = 0;
- while (nics[c].modulename)
- {
- drivercount++;
- c++;
- }
- drivercount++;
- sections = malloc((drivercount + 1) * sizeof(char *));
+ FILE *fp;
+ char description[STRING_SIZE], macaddr[STRING_SIZE], temp_line[STRING_SIZE];
+ int count = 0;
- /* Copy 'em. */
- c = 0;
- sections[c] = ctr[TR_MANUAL];
- c++;
- while (nics[c - 1].modulename)
+ if (!(scanned_nics_read_done))
{
- sections[c] = nics[c - 1].description;
- c++;
+ fprintf(flog,"Enter scan_network_cards\n"); // #### Debug ####
+ mysystem("/bin/probenic.sh");
+ // Read our scanned nics
+ if( (fp = fopen(SCANNED_NICS, "r")) == NULL )
+ {
+ fprintf(stderr,"Couldn't open "SCANNED_NICS);
+ return 1;
+ }
+ while (fgets(temp_line, STRING_SIZE, fp) != NULL)
+ {
+ strcpy(description, strtok(temp_line,";"));
+ strcpy(macaddr, strtok(NULL,";"));
+ if ( strlen(macaddr) ) {
+ strcpy(nics[count].description , description );
+ strcpy(nics[count].macaddr , macaddr );
+ count++;
+ }
+ }
+ fclose(fp);
}
- sections[c] = NULL;
-
- strcpy(driver, "");
- strcpy(driveroptions, "");
+ scanned_nics_read_done = 1;
+ return count;
+}
+
+
+
+int nicmenu(char *colour)
+{
+ int rc, choise = 0, count = 0, kcount = 0, mcount = 0, i, j, nic_in_use;
+ int found_NIC_as_Card[4];
+ char message[STRING_SIZE];
+
+ char cMenuInhalt[STRING_SIZE];
+ char MenuInhalt[20][180];
+ char *pMenuInhalt[20];
- done = 0; choice = 1;
- while (!done)
- {
- rc = newtWinMenu(ctr[TR_SELECT_NETWORK_DRIVER],
- ctr[TR_SELECT_NETWORK_DRIVER_LONG], 50, 5, 5, 6,
- sections, &choice, ctr[TR_OK], ctr[TR_CANCEL], NULL);
- if (rc == 0 || rc == 1)
+// strcpy( message , pnics[count].macaddr);
+// while (strcmp(message, "")) {
+// count++;
+// strcpy( message , pnics[count].macaddr);
+// }
+
+ while (strcmp(nics[count].macaddr, "")) count++; // 2 find how many nics in system
+ for ( i=0 ; i<4;i++) if (strcmp(knics[i].macaddr, "")) kcount++; // loop to find all knowing nics
+ fprintf(flog, "Enter NicMenu\n"); // #### Debug ####
+ fprintf(flog, "count nics %i\ncount knics %i\n", count, kcount); // #### Debug ####
+
+ // If new nics are found...
+ if (count > kcount) {
+ for (i=0 ; i < count ; i++)
{
- if (choice > 0)
- {
- /* Find module number, load module. */
- c = choice - 1;
-
- if (!checkformodule(nics[c].modulename))
- {
- sprintf(commandstring, "/sbin/modprobe %s", nics[c].modulename);
- sprintf(message, ctr[TR_LOOKING_FOR_NIC], nics[c].description);
- if (runcommandwithstatus(commandstring, message) == 0)
- {
- strcpy(driver, nics[c].modulename);
- strcpy(driveroptions, "");
- done = 1;
- }
- else
- errorbox(ctr[TR_UNABLE_TO_LOAD_DRIVER_MODULE]);
+ nic_in_use = 0;
+ for (j=0 ; j <= kcount ; j++) {
+ if (strcmp(nics[ i ].macaddr, knics[ j ].macaddr) == 0 ) {
+ nic_in_use = 1;
+ fprintf(flog,"NIC \"%s\" is in use.\n", nics[ i ].macaddr); // #### Debug ####
+ break;
}
- else
- errorbox(ctr[TR_THIS_DRIVER_MODULE_IS_ALREADY_LOADED]);
}
- else
- {
- manualdriver(driver, driveroptions);
- if (strlen(driver))
- done = 1;
+ if (!(nic_in_use)) {
+ fprintf(flog,"NIC \"%s\" is free.\n", nics[ i ].macaddr); // #### Debug ####
+ if ( strlen(nics[i].description) < 55 )
+ sprintf(MenuInhalt[mcount], "%.*s", strlen(nics[i].description)-2, nics[i].description+1);
+ else {
+ sprintf(cMenuInhalt, "%.50s", nics[i].description + 1);
+ strncpy(MenuInhalt[mcount], cMenuInhalt,(strrchr(cMenuInhalt,' ') - cMenuInhalt));
+ strcat (MenuInhalt[mcount], "...");
+ }
+
+ while ( strlen(MenuInhalt[mcount]) < 50) strcat(MenuInhalt[mcount], " "); // Fill with space.
+
+ strcat(MenuInhalt[mcount], " (");
+ strcat(MenuInhalt[mcount], nics[i].macaddr);
+ strcat(MenuInhalt[mcount], ")");
+ pMenuInhalt[mcount] = MenuInhalt[mcount];
+ found_NIC_as_Card[mcount]=i;
+ mcount++;
}
}
- else
- done = 1;
+
+ pMenuInhalt[mcount] = NULL;
+
+// sprintf(message, "Es wurde(n) %d freie Netzwerkkarte(n) in Ihrem System gefunden.\nBitte waehlen Sie im naechsten Dialog eine davon aus.\n", count);
+// newtWinMessage("NetcardMenu", ctr[TR_OK], message);
+
+ sprintf(message, "(TR) Bitte waehlen Sie eine der untenstehenden Netzwerkkarten fuer die Schnittstelle \"%s\" aus.\n", colour);
+ rc = newtWinMenu("(TR) NetcardMenu2", message, 50, 5, 5, 6, pMenuInhalt, &choise, ctr[TR_OK], ctr[TR_SELECT], ctr[TR_CANCEL], NULL);
+
+ if ( rc == 0 || rc == 1) {
+ write_configs_netudev(nics[choise].description, nics[found_NIC_as_Card[choise]].macaddr, colour);
+ } else if (rc == 2) {
+// manualdriver("pcnet32","");
+ }
+ return 0;
+ } else {
+ // We have to add here that you can manually add a device
+ errorbox("(TR) Es wurden leider keine freien Netzwerkkarten fuer die Schnittstelle in ihrem System gefunden.");
+ return 1;
}
+}
- return 1;
+int remove_nic_entry(char *colour)
+{
+ struct keyvalue *kv = initkeyvalues();
+ char message[STRING_SIZE];
+ char temp1[STRING_SIZE], temp2[STRING_SIZE];
+ char ucolour[STRING_SIZE];
+ int rc;
+
+
+ if (!(readkeyvalues(kv, CONFIG_ROOT "/ethernet/settings")))
+ {
+ freekeyvalues(kv);
+ errorbox(ctr[TR_UNABLE_TO_OPEN_SETTINGS_FILE]);
+ return 0;
+ }
+
+ switch (*colour)
+ {
+ case 'g': sprintf(ucolour, "GREEN");
+ strcpy(knics[_GREEN_CARD_].description, ctr[TR_UNSET]);
+ strcpy(knics[_GREEN_CARD_].macaddr, "");
+ strcpy(knics[_GREEN_CARD_].colour, "");
+ break;
+ case 'r': sprintf(ucolour, "RED");
+ strcpy(knics[_RED_CARD_].description, ctr[TR_UNSET]);
+ strcpy(knics[_RED_CARD_].macaddr, "");
+ strcpy(knics[_RED_CARD_].colour, "");
+ break;
+ case 'o': sprintf(ucolour, "ORANGE");
+ strcpy(knics[_ORANGE_CARD_].description, ctr[TR_UNSET]);
+ strcpy(knics[_ORANGE_CARD_].macaddr, "");
+ strcpy(knics[_ORANGE_CARD_].colour, "");
+ break;
+ case 'b': sprintf(ucolour, "BLUE");
+ strcpy(knics[_BLUE_CARD_].description, ctr[TR_UNSET]);
+ strcpy(knics[_BLUE_CARD_].macaddr, "");
+ strcpy(knics[_BLUE_CARD_].colour, "");
+ break;
+ default: sprintf(ucolour, "DUMMY");
+ break;
+ }
+
+ sprintf(message, "(TR) Soll die Netzwerkkarte \"%s\" entfernt werden ?\n", colour);
+ rc = newtWinChoice(ctr[TR_WARNING], ctr[TR_OK], ctr[TR_CANCEL], message);
+
+ if ( rc = 0 || rc == 1) {
+ sprintf(temp1, "%s_DEV", ucolour);
+ sprintf(temp2, "%s_MACADDR", ucolour);
+ replacekeyvalue(kv, temp1, "");
+ replacekeyvalue(kv, temp2, "");
+ sprintf(temp1, "%s_DESCRIPTION", ucolour);
+ replacekeyvalue(kv, temp1, "");
+
+ writekeyvalues(kv, CONFIG_ROOT "/ethernet/settings");
+ } else return 1;
+
+ freekeyvalues(kv);
+ return 0;
}
/* Manual entry for gurus. */
return 1;
}
-
-/* Returns the total number of nics current available as ethX devices. */
-int countcards(void)
-{
- FILE *file;
- char buffer[STRING_SIZE];
- char *start;
- int niccount = 0;
-
- if (!(file = fopen("/proc/net/dev", "r")))
- {
- fprintf(flog, "Unable to open /proc/net/dev in countnics()\n");
- return 0;
- }
-
- while (fgets(buffer, STRING_SIZE, file))
- {
- start = buffer;
- while (*start == ' ') start++;
- if (strncmp(start, "eth", strlen("eth")) == 0)
- niccount++;
- if (strncmp(start, "dummy", strlen("dummy")) == 0)
- niccount++;
- }
-
- fclose(file);
-
- return niccount;
-}
-
-/* Finds the listed module name and copies the card description back. */
-int findnicdescription(char *modulename, char *description)
-{
- int c = 0;
-
- if (strcmp(modulename, "pcmcia") == 0) {
- strcpy(description, "PCMCIA Ethernet card");
- return 0;
- }
-
- while (nics[c].description)
- {
- if (strcmp(nics[c].modulename, modulename) == 0)
- {
- strcpy(description, nics[c].description);
- return 1;
- }
- c++;
- }
-
- strcpy(description, "UNKNOWN");
- return 0;
-}