665e0d040612b1b40a6235c72e9ea5df5d543112
[people/pmueller/ipfire-2.x.git] / src / install+setup / install / nic.c
1 /* SmoothWall install 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 * Contains stuff related to firing up the network card, including a crude
8 * autodector.
9 *
10 */
11
12 #include "install.h"
13
14 #include <sys/socket.h>
15 #include <netinet/in.h>
16 #include <arpa/inet.h>
17
18 extern FILE *flog;
19 extern char *mylog;
20
21 extern char **ctr;
22
23 extern struct nic nics[];
24
25 int networkmenu(struct keyvalue *ethernetkv)
26 {
27 int i;
28 int count;
29 char nics;
30 char number;
31 char cbValue;
32 char driver[STRING_SIZE] = "";
33 char driveroptions[STRING_SIZE] = "";
34 struct keyvalue *kv = initkeyvalues();
35 int result = 0;
36 char commandstring[STRING_SIZE];
37 char address[STRING_SIZE], netmask[STRING_SIZE];
38 FILE *handle;
39 char description[1000];
40 char message[1000];
41 char title[STRING_SIZE];
42
43 /* Detect and count nics */
44 count = mysystem("/bin/probenic.sh count");
45 fprintf(flog, "Number of detected nics: %s\n", count);
46
47 /* sprintf(commandstring, "/bin/probenic.sh");
48 sprintf(message, ctr[TR_PROBING_FOR_NICS]);
49 runcommandwithstatus(commandstring, message); */
50
51 /* handle = fopen("/nicdriver", "r");
52 fgets(nics, STRING_SIZE, handle);
53 fclose(handle); */
54
55 /* fprintf(flog, "Detected NIC drivers: %s\n",driver); */
56
57 /* sprintf (title, "%s %s - %s", NAME, VERSION, SLOGAN);
58 sprintf(message, ctr[TR_FOUND_NIC], NAME, description);
59 newtWinMessage(title, ctr[TR_OK], message); */
60
61 newtComponent form, checkbox, rb[count], button;
62 newtOpenWindow(10, 5, 60, 11, "Checkboxes and Radio buttons");
63
64 for (i = 1; i <= 2; i++)
65 {
66 fprintf(flog, "Scan: %d\n", i);
67 snprintf(commandstring, STRING_SIZE, "/bin/probenic.sh %i", i);
68 mysystem(commandstring);
69 if ((handle = fopen("/nicdriver", "r")) == NULL) {
70 errorbox(ctr[TR_ERROR]);
71 goto EXIT;
72 }
73 fgets(driver, STRING_SIZE, handle);
74 fclose(handle);
75 findnicdescription(driver, description);
76 if ( i == 0 )
77 rb[i] = newtRadiobutton(1, i+2, description, 1, NULL);
78 else
79 rb[i] = newtRadiobutton(1, i+2, description, 0, rb[i-1]);
80 }
81
82 button = newtButton(1, count+3, "OK");
83
84 form = newtForm(NULL, NULL, 0);
85 newtFormAddComponent(form, checkbox);
86 for (i = 1; i <= 2; i++) {
87 fprintf(flog, "Add: %d\n", i);
88 newtFormAddComponent(form, rb[i]);
89 }
90 newtFormAddComponent(form, button);
91
92 newtRunForm(form);
93 newtFinished();
94
95 for (i = 1; i <= 2; i++)
96 if (newtRadioGetCurrent(rb[0]) == rb[i])
97 printf("radio button picked: %d\n", i);
98 newtFormDestroy(form);
99
100
101 /* snprintf(commandstring, STRING_SIZE, "/bin/probenic.sh 1");
102 mysystem(commandstring);
103 if ((handle = fopen("/nicdriver", "r")) == NULL) {
104 errorbox(ctr[TR_ERROR]);
105 goto EXIT;
106 }
107 fgets(driver, STRING_SIZE, handle);
108 fprintf(flog, "Green nic driver: %s\n", driver);
109 fclose(handle); */
110
111 /* Default is a GREEN nic only. */
112 /* Smoothie is not untarred yet, so we have to delay actually writing the
113 * settings till later. */
114 replacekeyvalue(ethernetkv, "CONFIG_TYPE", "0");
115 replacekeyvalue(ethernetkv, "GREEN_DRIVER", driver);
116 replacekeyvalue(ethernetkv, "GREEN_DRIVER_OPTIONS", driveroptions);
117 replacekeyvalue(ethernetkv, "GREEN_DEV", "eth0");
118 replacekeyvalue(ethernetkv, "GREEN_DISPLAYDRIVER", driver);
119
120 if (!(changeaddress(ethernetkv, "GREEN", 0, "")))
121 goto EXIT;
122
123 strcpy(address, ""); findkey(ethernetkv, "GREEN_ADDRESS", address);
124 strcpy(netmask, ""); findkey(ethernetkv, "GREEN_NETMASK", netmask);
125
126 snprintf(commandstring, STRING_SIZE, "/bin/ifconfig eth0 %s netmask %s up",
127 address, netmask);
128 if (mysystem(commandstring))
129 {
130 errorbox(ctr[TR_INTERFACE_FAILED_TO_COME_UP]);
131 goto EXIT;
132 }
133
134 result = 1;
135
136 EXIT:
137 freekeyvalues(kv);
138
139 return result;
140 }
141