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