]> git.decadent.org.uk Git - ap-utils.git/blob - src/ap-config.c
Pass correct platform options to configure
[ap-utils.git] / src / ap-config.c
1 /*
2  *      ap-config.c from Wireless Access Point Utilites for Unix
3  *
4  * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License Version 2 from
8  * June 1991 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  */
20
21 #include <stdlib.h>
22 #include <string.h>
23 #include <menu.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <sys/ioctl.h>
28 #include "ap-utils.h"
29
30 extern short ap_type;
31 extern int snmp_quit_by_keypress;
32
33 WINDOW *win_for_menu, *sub_for_menu, *win_for_help, *main_win, *main_sub;
34 char *community;
35 int atmel410_filter = 0, wait_mode = WAIT_FOREVER;
36 struct in_addr ap_ip;
37 char *prog_title = "Wireless Access Point Configurator";
38 char set_oeminfo_allowed = 0;
39
40 void config_menu()
41 {
42     struct umitems umenu_atmel[] = {
43         {_("Bridging"), _("Set bridging and IP-related options"), bridging,
44          0},
45         {_("Wireless"), _("Set wireless options"), atmel_wireless, 0},
46         {_("Privacy"), MENU_ENCRYPT, wep, 0},
47         {_("Auth"), MENU_AUTH, atmel_auth, 0},
48         {_("Community"), MENU_COMMUNITY, AuthorizedSettings, 0},
49         {_("Radio"), _("Set radio signal power and antenna options"),
50          power, 0},
51         {"..", MAIN_MENU, NULL, 0},
52         {0, 0, NULL, 0}
53     };
54
55     struct umitems umenu_nwn[] = {
56         {_("General"), _("Set general options"), nwn_wireless, 0},
57         {_("Advanced"), _("Set advanced options"), advanced, 0},
58         {_("Privacy"), MENU_ENCRYPT, nwn_wep, 0},
59         {_("MAC auth"), MENU_AUTH, nwn_auth_mac, 0},
60         {_("Community"), MENU_COMMUNITY, AuthorizedSettings, 0},
61         {"..", MAIN_MENU, NULL, 0},
62         {0, 0, NULL, 0}
63     };
64     
65     switch (ap_type) {
66         case ATMEL410:
67         case ATMEL12350:
68             set_oeminfo_allowed++;
69             uni_menu(umenu_atmel, sizeof(umenu_atmel) / sizeof(umenu_atmel[0]));
70             set_oeminfo_allowed--;
71             break;
72         case NWN:
73             uni_menu(umenu_nwn, sizeof(umenu_nwn) / sizeof(umenu_nwn[0]));
74             break;
75     }
76 }
77
78
79 void command_menu()
80 {
81     struct umitems command_umenu_atmel[] = {
82         {_("Upload"), _("Activate current configuration"), upload, 0},
83         {_("Defaults"), _("Restore factory default settings"), defaults, 0},
84         {_("Reset"),
85          _("Reset AP. All not uploaded configuration will be lost"), reset, 0},
86         {_("TestMode"), _("Put Access Point in test mode"), test, 0},
87         {"..", MAIN_MENU, NULL, 0},
88         {0, 0, NULL, 0}
89     };
90     struct umitems command_umenu_nwn[] = {
91         {_("Reset"), _("Reset AP."), reset, 0},
92         {"..", MAIN_MENU, NULL, 0},
93         {0, 0, NULL, 0}
94     };
95
96     switch (ap_type) {
97         case ATMEL410:
98         case ATMEL12350:
99             uni_menu(command_umenu_atmel,
100                 sizeof(command_umenu_atmel) / sizeof(command_umenu_atmel[0]));
101             break;      
102         case NWN:
103             uni_menu(command_umenu_nwn,
104                 sizeof(command_umenu_nwn) / sizeof(command_umenu_nwn[0]));
105             break;
106     }    
107 }
108
109 void stat_menu()
110 {
111     struct umitems umenu_atmel[] = {
112         {_("SysInfo"), MENU_SYSINFO, atmel_sysinfo, 0},
113         {_("Ethernet"), _("Get ethernet port statistics"), EthStat, 0},
114         {_("Wireless"), MENU_WIRELESS, WirelessStat, 0},
115         {_("Stations"), MENU_STAS, atmel_stations, 0},
116         {_("AP link"), MENU_APLINK, atmel_aplink, 0},
117         {_("KnownAPs"), _("Get info about known Access Points"), APs, 0},
118         {"..", MAIN_MENU, NULL, 0},
119         {0, 0, NULL, 0}
120     };
121     struct umitems umenu_nwn[] = {
122         {_("SysInfo"), MENU_SYSINFO, nwn_sysinfo, 0},
123         {_("Wireless"), MENU_WIRELESS, nwn_wireless_stat, 0},
124         {_("Stations"), MENU_STAS, nwn_stations, 0},
125         {_("Latest"), _("Get info about latest events"), latest, 0},
126         {"..", MAIN_MENU, NULL, 0},
127         {0, 0, NULL, 0}
128     };
129     
130     switch (ap_type) {
131         case ATMEL410:
132         case ATMEL12350:
133             uni_menu(umenu_atmel, sizeof(umenu_atmel) / sizeof(umenu_atmel[0]));
134             break;      
135         case NWN:
136             uni_menu(umenu_nwn, sizeof(umenu_nwn) / sizeof(umenu_nwn[0]));
137             break;
138     }    
139 }
140
141 void _auth()
142 {
143     if (get_opts() == 0)
144         connect_options((unsigned long) NULL, (int) NULL);
145 }
146
147 void main_menu()
148 {
149     struct umitems config_umenu[] = {
150         {_("Info"), MENU_INFO, stat_menu, 1},
151         {_("Config"), MENU_CONFIG, config_menu, 1},
152         {_("Commands"), _("Execute commands on Access Point"),
153          command_menu, 1},
154         {_("Connect"), MENU_CONNECT, _auth, 0},
155         {_("Search"), MENU_SEARCH, ap_search, 0},
156         {_("Polling"), MENU_POLLING, polling_interval, 0},
157         {_("Shell"), MENU_SHELL, exit_shell, 0},
158         {_("About"), MENU_ABOUT, about, 0},
159         {_("Exit"), MENU_EXIT, exit_program, 0},
160         {0, 0, NULL, 0}
161     };
162
163     uni_menu(config_umenu, sizeof(config_umenu) / sizeof(config_umenu[0]));
164 }
165
166
167
168 int main( /*int argc, char **argv */ )
169 {
170     int i;
171     WINDOW *win_for_title;
172     char message[100];
173
174 #ifdef HAVE_GETTEXT
175     /* locale support init */
176     setlocale(LC_ALL, "");
177     bindtextdomain("ap-utils", LOCALEDIR);
178     textdomain("ap-utils");
179 #endif
180
181     initscr();
182     if (has_colors()) {
183         start_color();
184
185         /* Never trust that these are defined by default. */
186         init_pair (COLOR_RED, COLOR_RED, COLOR_BLACK );
187         init_pair (COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
188         init_pair (COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
189         init_pair (COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
190         init_pair (COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK);
191         init_pair (COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
192
193         init_pair(11, COLOR_BLACK, COLOR_CYAN);
194         init_pair(12, COLOR_BLACK, COLOR_WHITE);
195         init_pair(13, COLOR_BLACK, COLOR_GREEN);
196         init_pair(14, COLOR_WHITE, COLOR_RED);
197     }
198
199     noraw();
200     cbreak();
201     noecho();
202     scrollok(stdscr, TRUE);
203     idlok(stdscr, TRUE);
204     keypad(stdscr, TRUE);
205     snmp_quit_by_keypress = 1;
206     refresh();
207
208 /* draw help win */
209     win_for_help = newwin(1, COLS, LINES - 1, 0);
210     wattrset(win_for_help, COLOR_PAIR(11));
211     print_help("");
212
213 /* draw title win */
214     win_for_title = newwin(1, COLS, 0, 0);
215     wattrset(win_for_title, COLOR_PAIR(11));
216     for (i = 0; i < COLS; i++)
217         waddch(win_for_title, ' ');
218     sprintf(message, _("Wireless Access Point Configurator ver. %s"),
219             VERSION);
220     mvwaddstr(win_for_title, 0, (COLS - strlen(message)) / 2, message);
221     wrefresh(win_for_title);
222
223 /* draw menu win */
224     win_for_menu = newwin(LINES - 2, MCOLS, 1, 0);
225     sub_for_menu = derwin(win_for_menu, LINES - 5, MCOLS - 2, 2, 1);
226     set_menu_win(NULL, win_for_menu);
227     set_menu_sub(NULL, sub_for_menu);
228     attrset(COLOR_PAIR(11));
229
230     /* íÁÌÀÀ ÒÁÍËÕ */
231     waddch(win_for_menu, ACS_BSSB);
232     for (i = 0; i < MCOLS - 2; i++)
233         waddch(win_for_menu, ACS_BSBS);
234     waddch(win_for_menu, ACS_BSSS);
235     for (i = 0; i < LINES - 4; i++) {
236         waddch(win_for_menu, ACS_SBSB);
237         mvwaddch(win_for_menu, i + 1, MCOLS - 1, ACS_SBSB);
238     }
239     waddch(win_for_menu, ACS_SSBB);
240     for (i = 0; i < MCOLS - 2; i++)
241         waddch(win_for_menu, ACS_BSBS);
242     waddch(win_for_menu, ACS_SSBS);
243     wrefresh(win_for_menu);
244
245 /* draw_main_win */
246     main_win = newwin(LINES - 2, COLS - MCOLS, 1, MCOLS);
247     /* íÁÌÀÀ ÒÁÍËÕ */
248     for (i = 0; i < COLS - MCOLS - 1; i++)
249         waddch(main_win, ACS_BSBS);
250     waddch(main_win, ACS_BBSS);
251     for (i = 0; i < LINES - 4; i++)
252         mvwaddch(main_win, i + 1, COLS - MCOLS - 1, ACS_SBSB);
253     for (i = 0; i < COLS - MCOLS - 1; i++)
254         waddch(main_win, ACS_BSBS);
255     waddch(main_win, ACS_SBBS);
256     main_sub = derwin(main_win, LINES - 4, COLS - MCOLS - 1, 1, 0);
257     wclear(main_sub);
258     wrefresh(main_win);
259
260     about();
261     if (get_opts() == 0)
262         connect_options((unsigned long) NULL, (int) NULL);
263
264     while (1)
265         main_menu();
266
267 /* Not reachable */
268     return 0;
269 }