]> git.decadent.org.uk Git - ap-utils.git/blob - src/ap-config.c
4ef92872b66cd571cb90848d2fcb9f26023e6f3c
[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 char *ap_types[3] = {
31     "ATMEL410",
32     "NWN",
33     "ATMEL12350"
34 };
35
36 WINDOW *win_for_menu, *sub_for_menu, *win_for_help, *main_win, *main_sub;
37 short ap_type;
38 char *community;
39 int sockfd, atmel410_filter=0;
40 struct in_addr ap_ip;
41 char *prog_title = "Wireless Access Point Configurator";
42
43 extern char IS_ATMEL410_SBRIDGES;
44 extern char IS_ATMEL12350_TELLUS;
45 extern char IS_ATMEL12350_VERNET;
46
47 void config_menu()
48 {
49     struct umitems umenu_atmel[] = {
50         {_("Bridging"), _("Set bridging and IP-related options"), bridging,
51          0},
52         {_("Wireless"), _("Set wireless options"), atmel_wireless, 0},
53         {_("Privacy"), MENU_ENCRYPT, wep, 0},
54         {_("MAC auth"), MENU_MAC, atmel_auth_mac, 0},
55         {_("Community"), MENU_COMMUNITY, AuthorizedSettings, 0},
56         {_("Radio"), _("Set radio signal power and antenna options"),
57          power, 0},
58         {"..", MAIN_MENU, NULL, 0},
59         {0, 0, NULL, 0}
60     };
61
62     struct umitems umenu_nwn[] = {
63         {_("General"), _("Set general options"), nwn_wireless, 0},
64         {_("Advanced"), _("Set advanced options"), advanced, 0},
65         {_("Privacy"), MENU_ENCRYPT, nwn_wep, 0},
66         {_("MAC auth"), MENU_MAC, nwn_auth_mac, 0},
67         {_("Community"), MENU_COMMUNITY, AuthorizedSettings, 0},
68         {"..", MAIN_MENU, NULL, 0},
69         {0, 0, NULL, 0}
70     };
71     
72     switch (ap_type) {
73         case ATMEL410:
74         case ATMEL12350:
75             uni_menu(umenu_atmel, sizeof(umenu_atmel) / sizeof(umenu_atmel[0]));
76             break;
77         case NWN:
78             uni_menu(umenu_nwn, sizeof(umenu_nwn) / sizeof(umenu_nwn[0]));
79             break;
80     }
81 }
82
83
84 void command_menu()
85 {
86     struct umitems command_umenu_atmel[] = {
87         {_("Upload"), _("Make current configuration active"), upload, 0},
88         {_("Defaults"), _("Restore factory default settings"), defaults, 0},
89         {_("Reset"),
90          _("Reset AP. All not uploaded configuration will be lost"),
91          reset, 0},
92         {_("TestMode"), _("Put Access Point in test mode"), test, 0},
93         {"..", MAIN_MENU, NULL, 0},
94         {0, 0, NULL, 0}
95     };
96     struct umitems command_umenu_nwn[] = {
97         {_("Reset"), _("Reset AP."), reset, 0},
98         {"..", MAIN_MENU, NULL, 0},
99         {0, 0, NULL, 0}
100     };
101
102     switch (ap_type) {
103         case ATMEL410:
104         case ATMEL12350:
105             uni_menu(command_umenu_atmel,
106                 sizeof(command_umenu_atmel) / sizeof(command_umenu_atmel[0]));
107             break;      
108         case NWN:
109             uni_menu(command_umenu_nwn,
110                 sizeof(command_umenu_nwn) / sizeof(command_umenu_nwn[0]));
111             break;
112     }    
113 }
114
115 void stat_menu()
116 {
117     struct umitems umenu_atmel[] = {
118         {_("SysInfo"), MENU_SYSINFO, atmel_sysinfo, 0},
119         {_("Ethernet"), _("Get ethernet port statistics"), EthStat, 0},
120         {_("Wireless"), MENU_WIRELESS, WirelessStat, 0},
121         {_("Stations"), MENU_STAS, stations,
122          0},
123         {_("KnownAPs"), _("Get info about known Access Points"), APs, 0},
124         {"..", MAIN_MENU, NULL, 0},
125         {0, 0, NULL, 0}
126     };
127     struct umitems umenu_nwn[] = {
128         {_("SysInfo"), MENU_SYSINFO, nwn_sysinfo, 0},
129         {_("Wireless"), MENU_WIRELESS, nwn_wireless_stat, 0},
130         {_("Stations"), MENU_STAS, nwn_stations, 0},
131         {_("Latest"), _("Get info about latest events"), latest, 0},
132         {"..", MAIN_MENU, NULL, 0},
133         {0, 0, NULL, 0}
134     };
135     
136      switch (ap_type) {
137         case ATMEL410:
138         case ATMEL12350:
139             uni_menu(umenu_atmel, sizeof(umenu_atmel) / sizeof(umenu_atmel[0]));
140             break;      
141         case NWN:
142             uni_menu(umenu_nwn, sizeof(umenu_nwn) / sizeof(umenu_nwn[0]));
143             break;
144     }    
145 }
146
147 void _auth()
148 {
149     if(get_opts() == 0)
150         connect_options((unsigned long) NULL, (int) NULL);
151 }
152
153 void main_menu()
154 {
155     struct umitems config_umenu[] = {
156         {_("Info"), MENU_INFO, stat_menu, 1},
157         {_("Config"), MENU_CONFIG, config_menu, 1},
158         {_("Commands"), _("Execute commands on Access Point"),
159          command_menu, 1},
160         {_("Connect"), MENU_CONNECT, _auth, 0},
161         {_("Search"), MENU_SEARCH, ap_search, 0},
162         {_("About"), MENU_ABOUT, about, 0},
163         {_("Shell"), MENU_SHELL, exit_shell, 0},
164         {_("Exit"), MENU_EXIT, exit_program, 0},
165         {0, 0, NULL, 0}
166     };
167     uni_menu(config_umenu, sizeof(config_umenu) / sizeof(config_umenu[0]));
168 }
169
170
171
172 int main( /*int argc, char **argv */ )
173 {
174     int i;
175     WINDOW *win_for_title;
176     char message[100];
177
178 #ifdef HAVE_GETTEXT
179     /* locale support init */
180     setlocale(LC_ALL, "");
181     bindtextdomain("ap-utils", LOCALEDIR);
182     textdomain("ap-utils");
183 #endif
184
185     initscr();
186     if (has_colors()) {
187         start_color();
188         init_pair(1, COLOR_BLACK, COLOR_CYAN);
189         init_pair(2, COLOR_BLACK, COLOR_WHITE);
190         init_pair(3, COLOR_BLACK, COLOR_GREEN);
191         init_pair(4, COLOR_WHITE, COLOR_RED);
192     }
193
194     noraw();
195     cbreak();
196     noecho();
197     scrollok(stdscr, TRUE);
198     idlok(stdscr, TRUE);
199     keypad(stdscr, TRUE);
200     refresh();
201
202 /* draw help win */
203     win_for_help = newwin(1, COLS, LINES - 1, 0);
204     wattrset(win_for_help, COLOR_PAIR(1));
205     print_help("");
206
207 /* draw title win */
208     win_for_title = newwin(1, COLS, 0, 0);
209     wattrset(win_for_title, COLOR_PAIR(1));
210     for (i = 0; i < COLS; i++)
211         waddch(win_for_title, ' ');
212     sprintf(message, _("Wireless Access Point Configurator ver. %s"),
213             VERSION);
214     mvwaddstr(win_for_title, 0, (COLS - strlen(message)) / 2, message);
215     wrefresh(win_for_title);
216
217 /* draw menu win */
218     win_for_menu = newwin(LINES - 2, MCOLS, 1, 0);
219     sub_for_menu = derwin(win_for_menu, LINES - 5, MCOLS - 2, 2, 1);
220     set_menu_win(NULL, win_for_menu);
221     set_menu_sub(NULL, sub_for_menu);
222     attrset(COLOR_PAIR(1));
223
224     /* íÁÌÀÀ ÒÁÍËÕ */
225     waddch(win_for_menu, ACS_BSSB);
226     for (i = 0; i < MCOLS - 2; i++)
227         waddch(win_for_menu, ACS_BSBS);
228     waddch(win_for_menu, ACS_BSSS);
229     for (i = 0; i < LINES - 4; i++) {
230         waddch(win_for_menu, ACS_SBSB);
231         mvwaddch(win_for_menu, i + 1, MCOLS - 1, ACS_SBSB);
232     }
233     waddch(win_for_menu, ACS_SSBB);
234     for (i = 0; i < MCOLS - 2; i++)
235         waddch(win_for_menu, ACS_BSBS);
236     waddch(win_for_menu, ACS_SSBS);
237     wrefresh(win_for_menu);
238
239 /* draw_main_win */
240     main_win = newwin(LINES - 2, COLS - MCOLS, 1, MCOLS);
241     /* íÁÌÀÀ ÒÁÍËÕ */
242     for (i = 0; i < COLS - MCOLS - 1; i++)
243         waddch(main_win, ACS_BSBS);
244     waddch(main_win, ACS_BBSS);
245     for (i = 0; i < LINES - 4; i++)
246         mvwaddch(main_win, i + 1, COLS - MCOLS - 1, ACS_SBSB);
247     for (i = 0; i < COLS - MCOLS - 1; i++)
248         waddch(main_win, ACS_BSBS);
249     waddch(main_win, ACS_SBBS);
250     main_sub = derwin(main_win, LINES - 4, COLS - MCOLS - 1, 1, 0);
251     wclear(main_sub);
252     wrefresh(main_win);
253
254     about();
255     if (get_opts() == 0)
256         connect_options((unsigned long) NULL, (int) NULL);
257
258     while (1)
259         main_menu();
260
261 /* Not reachable */
262     return 0;
263 }
264