2 * common.c from Access Point SNMP Utils for Linux
4 * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
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.
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.
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
24 #include <sys/types.h>
27 #include <sys/ioctl.h>
30 #define AUTODETECT _("Autodetect AP type? ")
31 #define APIP _("Access Point IP-address: ")
32 #define APPASS _("Password (community): ")
33 #define APTYPE _("AP type: ")
34 #define SAVESETTINGS _("Save connect-settings: ")
36 extern WINDOW *main_sub;
37 extern char *community, *prog_title;
40 extern struct in_addr ap_ip;
41 extern char *ap_types[];
45 int nrow = 12, ncol = 47, brow = (LINES - 4 - nrow) / 2, bcol =
46 (COLS - MCOLS - 2 - ncol) / 2, i;
52 print_title(_("About"));
55 mvwaddch(main_sub, brow, bcol, ACS_ULCORNER);
56 mvwaddch(main_sub, brow, bcol + ncol, ACS_URCORNER);
57 mvwaddch(main_sub, brow + nrow, bcol, ACS_LLCORNER);
58 mvwaddch(main_sub, brow + nrow, bcol + ncol, ACS_LRCORNER);
59 for (i = 1; i < ncol; i++) {
60 mvwaddch(main_sub, brow, bcol + i, ACS_HLINE);
61 mvwaddch(main_sub, brow + nrow, bcol + i, ACS_HLINE);
63 for (i = 1; i < nrow; i++) {
64 mvwaddch(main_sub, brow + i, bcol, ACS_VLINE);
65 mvwaddch(main_sub, brow + i, bcol + ncol, ACS_VLINE);
68 mvwaddstr(main_sub, brow + 1, bcol + 2, prog_title);
69 sprintf(message, _("From %s"), TITLE);
70 mvwaddstr(main_sub, brow + 2, bcol + 2, message);
71 sprintf(message, _("Version %s"), VERSION);
72 mvwaddstr(main_sub, brow + 3, bcol + 2, message);
73 mvwaddstr(main_sub, brow + 5, bcol + 2,
74 _("Written by Roman Festchook roma@polesye.net"));
75 mvwaddstr(main_sub, brow + 6, bcol + 2,
76 _("Copyright (c) Roman Festchook 2001-2004"));
77 mvwaddstr(main_sub, brow + 7, bcol + 2, "http://ap-utils.polesye.net/");
78 mvwaddstr(main_sub, brow + 9, bcol + 2,
79 _("This program is distributed under the terms"));
80 mvwaddstr(main_sub, brow +10, bcol + 2,
81 _("of the GNU General Public License version 2."));
82 mvwaddstr(main_sub, brow + 11, bcol + 2,
83 _("See the included COPYING file for details."));
96 void connect_options(unsigned long int ip, int type)
99 struct sockaddr_in client;
100 unsigned char message[16];
103 char save_settings=1;
104 char sysDescr_NWN[] = { 0x2B, 0x06, 0x01, 0x02, 0x01, 0x01, 0x01, 0x00 };
105 char sysDescr_ATMEL410[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A,
106 0x01, 0x01, 0x01, 0x01, 0x00 };
107 char sysDescr_ATMEL12350[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E,
108 0x01, 0x01, 0x01, 0x01, 0x00 };
112 memset(&client, 0, sizeof client);
113 client.sin_family = AF_INET;
114 client.sin_port = INADDR_ANY;
115 client.sin_addr.s_addr = INADDR_ANY;
120 if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
121 print_helperr(CREATE_SOCKET_ERROR);
126 if (bind(sockfd, (struct sockaddr *) &client, SIZE) == -1) {
127 print_helperr(BIND_SOCKET_ERROR);
135 print_title(_("Connect options"));
138 mvwaddstr(main_sub, 1, 1, APIP);
141 mvwaddstr(main_sub, 1, 1 + strlen(APIP), inet_ntoa(ap_ip));
143 print_help(_("Enter IP address of your Access Point."));
144 get_ip(&ap_ip, 1, 1 + strlen(APIP), NULL);
147 mvwaddstr(main_sub, 2, 1, APPASS);
148 print_help(_("Entered characters will not be displayed "
149 "for security reason."));
150 get_pass(message, 2, 1 + strlen(APPASS), 16);
153 i = strlen(message) + 1;
154 community = (char *) malloc(i);
155 strncpy(community, message, i);
160 mvwaddstr(main_sub, 3, 1, APTYPE);
162 mvwaddstr(main_sub, 3, 1, AUTODETECT);
164 i = yes_no(3, 1 + strlen(AUTODETECT));
165 clear_main_new(3, 4);
166 mvwaddstr(main_sub, 3, 1, APTYPE);
167 if (i == 2) { /* NO */
169 ap_type = menu_choose(3, 1 + strlen(APTYPE), ap_types, 3);
171 print_help(_("Determining AP type. Please wait..."));
172 varbinds[0].oid = sysDescr_NWN;
173 varbinds[0].len_oid = sizeof(sysDescr_NWN);
174 varbinds[0].value = NULL;
175 varbinds[0].len_val = 0;
176 varbinds[0].type = NULL_VALUE;
177 if (snmp(varbinds, 1, GET) > 0) {
180 varbinds[0].oid = sysDescr_ATMEL410;
181 varbinds[0].len_oid = sizeof(sysDescr_ATMEL410);
182 varbinds[0].value = NULL;
183 varbinds[0].len_val = 0;
184 varbinds[0].type = NULL_VALUE;
185 if (snmp(varbinds, 1, GET) > 0) {
188 varbinds[0].oid = sysDescr_ATMEL12350;
189 varbinds[0].len_oid = sizeof(sysDescr_ATMEL12350);
190 varbinds[0].value = NULL;
191 varbinds[0].len_val = 0;
192 varbinds[0].type = NULL_VALUE;
193 if (snmp(varbinds, 1, GET) > 0) {
194 ap_type = ATMEL12350;
196 print_helperr(_("Unable to determine AP type "
197 "(no response). Press any key."));
199 clear_main_new(1, 4);
205 wattrset(main_sub, A_BOLD);
207 waddstr(main_sub, ap_types[ap_type]);
208 wattrset(main_sub, A_NORMAL);
210 mvwaddstr(main_sub, 4, 1, SAVESETTINGS);
212 save_settings = on_off(4, 1 + strlen(SAVESETTINGS));
214 print_bottom(inet_ntoa(ap_ip));
216 if(save_settings == 1) {
217 if ((home_dir = getenv("HOME"))) {
218 sprintf(message, "%s/.ap-config", home_dir);
219 if ((fd = open(message, O_CREAT | O_WRONLY | O_APPEND, 0600)) != -1) {
220 sprintf(message, "%s:%s:%d\n", inet_ntoa(ap_ip),
222 write(fd, message, strlen(message));
250 * Fill channels list string array using regulation domain
251 * restrictions and return number of the channels
253 int ch_list(int regulation_domain, char **list)
255 int FIRST_CHANNEL, LAST_CHANNEL, i;
257 #ifndef NO_REG_DOMAIN
258 switch (regulation_domain) {
276 default: /* also case 0x40 */
280 #ifndef NO_REG_DOMAIN
284 for (i = 0; i < LAST_CHANNEL - FIRST_CHANNEL + 1; i++) {
285 list[i] = (char *) malloc(3);
286 sprintf(list[i], "%02u", FIRST_CHANNEL + i);