]> git.decadent.org.uk Git - ap-utils.git/blob - ap-gl/ap-gl.c
Imported Upstream version 1.5~pre3~a
[ap-utils.git] / ap-gl / ap-gl.c
1 /*
2  *      ap-gl.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, *name;
32 int sockfd, atmel410_filter = 1, wait_mode = WAIT_FOREVER;
33 struct in_addr ap_ip;
34 char *prog_title = "Wireless AP Configurator for GlobalSun";
35 char set_oeminfo_allowed = 0;
36 extern char *ap_types[];
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    set_oeminfo_allowed++;
54    uni_menu(umenu_atmel, sizeof(umenu_atmel) / sizeof(umenu_atmel[0]));
55    set_oeminfo_allowed--;
56 }
57
58
59 void command_menu()
60 {
61     struct umitems command_umenu_atmel[] = {
62         {_("Upload"), _("Activate current configuration"), upload, 0},
63         {_("Defaults"), _("Restore factory default settings"), defaults, 0},
64         {_("Reset"),
65          _("Reset AP. All not uploaded configuration will be lost"), reset, 0},
66         {_("TestMode"), _("Put Access Point in test mode"), test, 0},
67         {"..", MAIN_MENU, NULL, 0},
68         {0, 0, NULL, 0}
69     };
70
71     ap_types[1] = "ATMEL_PRISM";
72
73     uni_menu(command_umenu_atmel, sizeof(command_umenu_atmel) / sizeof(command_umenu_atmel[0]));
74 }
75
76 void stat_menu()
77 {
78     struct umitems umenu_atmel[] = {
79         {_("SysInfo"), MENU_SYSINFO, atmel_sysinfo, 0},
80         {_("Ethernet"), _("Get ethernet port statistics"), EthStat, 0},
81         {_("Wireless"), MENU_WIRELESS, WirelessStat, 0},
82         {_("Stations"), MENU_STAS, atmel_stations, 0},
83         {_("KnownAPs"), _("Get info about known Access Points"), APs, 0},
84         {"..", MAIN_MENU, NULL, 0},
85         {0, 0, NULL, 0}
86     };
87     
88     uni_menu(umenu_atmel, sizeof(umenu_atmel) / sizeof(umenu_atmel[0]));
89 }
90
91 void _auth()
92 {
93     if (get_opts() == 0)
94         connect_options((unsigned long) NULL, ATMEL410+1);
95 }
96
97 void main_menu()
98 {
99     struct umitems config_umenu[] = {
100         {_("Info"), MENU_INFO, stat_menu, 1},
101         {_("Config"), MENU_CONFIG, config_menu, 1},
102         {_("Commands"), _("Execute commands on Access Point"),
103          command_menu, 1},
104         {_("Connect"), MENU_CONNECT, _auth, 0},
105         {_("Search"), MENU_SEARCH, ap_search, 0},
106         {_("About"), MENU_ABOUT, about, 0},
107         {_("Shell"), MENU_SHELL, exit_shell, 0},
108         {_("Exit"), MENU_EXIT, exit_program, 0},
109         {0, 0, NULL, 0}
110     };
111     uni_menu(config_umenu, sizeof(config_umenu) / sizeof(config_umenu[0]));
112 }
113
114
115
116 int main( /*int argc, char **argv */ )
117 {
118     int i;
119     WINDOW *win_for_title;
120     char message[100];
121
122     ap_types[0]="ATMEL_PRISM";
123
124 #ifdef HAVE_GETTEXT
125     /* locale support init */
126     setlocale(LC_ALL, "");
127     bindtextdomain("ap-utils", LOCALEDIR);
128     textdomain("ap-utils");
129 #endif
130
131     initscr();
132     if (has_colors()) {
133         start_color();
134
135         /* Never trust that these are defined by default. */
136         init_pair (COLOR_RED, COLOR_RED, COLOR_BLACK );
137         init_pair (COLOR_GREEN, COLOR_GREEN, COLOR_BLACK);
138         init_pair (COLOR_YELLOW, COLOR_YELLOW, COLOR_BLACK);
139         init_pair (COLOR_BLUE, COLOR_BLUE, COLOR_BLACK);
140         init_pair (COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK );
141         init_pair (COLOR_CYAN, COLOR_CYAN, COLOR_BLACK);
142
143         init_pair(11, COLOR_BLACK, COLOR_CYAN);
144         init_pair(12, COLOR_BLACK, COLOR_WHITE);
145         init_pair(13, COLOR_BLACK, COLOR_GREEN);
146         init_pair(14, COLOR_WHITE, COLOR_RED);
147     }
148
149     noraw();
150     cbreak();
151     noecho();
152     scrollok(stdscr, TRUE);
153     idlok(stdscr, TRUE);
154     keypad(stdscr, TRUE);
155     refresh();
156
157 /* draw help win */
158     win_for_help = newwin(1, COLS, LINES - 1, 0);
159     wattrset(win_for_help, COLOR_PAIR(11));
160     print_help("");
161
162 /* draw title win */
163     win_for_title = newwin(1, COLS, 0, 0);
164     wattrset(win_for_title, COLOR_PAIR(11));
165     for (i = 0; i < COLS; i++)
166         waddch(win_for_title, ' ');
167     sprintf(message, _("Wireless Access Point Configurator ver. %s"),
168             VERSION);
169     mvwaddstr(win_for_title, 0, (COLS - strlen(message)) / 2, message);
170     wrefresh(win_for_title);
171
172 /* draw menu win */
173     win_for_menu = newwin(LINES - 2, MCOLS, 1, 0);
174     sub_for_menu = derwin(win_for_menu, LINES - 5, MCOLS - 2, 2, 1);
175     set_menu_win(NULL, win_for_menu);
176     set_menu_sub(NULL, sub_for_menu);
177     attrset(COLOR_PAIR(11));
178
179     /* íÁÌÀÀ ÒÁÍËÕ */
180     waddch(win_for_menu, ACS_BSSB);
181     for (i = 0; i < MCOLS - 2; i++)
182         waddch(win_for_menu, ACS_BSBS);
183     waddch(win_for_menu, ACS_BSSS);
184     for (i = 0; i < LINES - 4; i++) {
185         waddch(win_for_menu, ACS_SBSB);
186         mvwaddch(win_for_menu, i + 1, MCOLS - 1, ACS_SBSB);
187     }
188     waddch(win_for_menu, ACS_SSBB);
189     for (i = 0; i < MCOLS - 2; i++)
190         waddch(win_for_menu, ACS_BSBS);
191     waddch(win_for_menu, ACS_SSBS);
192     wrefresh(win_for_menu);
193
194 /* draw_main_win */
195     main_win = newwin(LINES - 2, COLS - MCOLS, 1, MCOLS);
196     /* íÁÌÀÀ ÒÁÍËÕ */
197     for (i = 0; i < COLS - MCOLS - 1; i++)
198         waddch(main_win, ACS_BSBS);
199     waddch(main_win, ACS_BBSS);
200     for (i = 0; i < LINES - 4; i++)
201         mvwaddch(main_win, i + 1, COLS - MCOLS - 1, ACS_SBSB);
202     for (i = 0; i < COLS - MCOLS - 1; i++)
203         waddch(main_win, ACS_BSBS);
204     waddch(main_win, ACS_SBBS);
205     main_sub = derwin(main_win, LINES - 4, COLS - MCOLS - 1, 1, 0);
206     wclear(main_sub);
207     wrefresh(main_win);
208
209     about();
210     if (get_opts() == 0)
211         connect_options((unsigned long) NULL, ATMEL410+1);
212
213     while (1)
214         main_menu();
215
216 /* Not reachable */
217     return 0;
218 }
219