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