]> git.decadent.org.uk Git - ap-utils.git/blob - lib/cmd.c
61a553417a24b1ce20f8c77cd7f35b10d94eed80
[ap-utils.git] / lib / cmd.c
1 /*
2  *     cmd.c from Access Point SNMP Utils for Linux
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 <unistd.h>
22 #include "ap-utils.h"
23 #include "ap-curses.h"
24
25 #define ANSW_NO _("(Y - Yes; N - No (it's safer to answer No, unless you really need this.)")
26
27 extern WINDOW *main_sub;
28 extern short ap_type;
29
30 void defaults()
31 {
32     char sysLoadDefaults[] =
33         { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01,
34         0x01, 0x04, 0x00
35     }, enable = 1;
36     varbind varbinds[1];
37     int i;
38
39     if (ap_type == ATMEL12350) {
40         sysLoadDefaults[5] = 0xE0;
41         sysLoadDefaults[6] = 0x3E;
42     }
43
44     print_title(_("Restore factory default configuration"));
45     mvwaddstr(main_sub, 3, 2,
46               _
47               ("After restoring factory defaults your current configuration."));
48     mvwaddstr(main_sub, 4, 2, _("will be lost."));
49     mvwaddstr(main_sub, 6, 20, _("Do you want to continue? "));
50     wrefresh(main_sub);
51     print_help(ANSW_NO);
52     i = 1;
53     while (i)
54         switch (getch()) {
55         case 'Y':
56         case 'y':
57             clear_main(3);
58             i = 0;
59             break;
60         case 'n':
61         case 'N':
62             clear_main(3);
63             goto quit;
64         }
65
66     print_help(WAIT_SET);
67
68
69     varbinds[0].oid = sysLoadDefaults;
70     varbinds[0].len_oid = sizeof(sysLoadDefaults);
71     varbinds[0].value = &enable;
72     varbinds[0].len_val = 1;
73     varbinds[0].type = INT_VALUE;
74     if (snmp(varbinds, 1, SET) <= 0)
75         print_helperr(ERR_SET);
76     else
77         print_help
78             (_
79              ("Factory default settings loaded. Press any key to continue."));
80     getch();
81   quit:
82     print_title("");
83 }
84
85 void reset()
86 {
87     int i;
88     print_title(_("Reset Access Point"));
89     if(ap_type == ATMEL410) 
90         mvwaddstr(main_sub, 3, 5,
91               _("By reset you'll lose all non-uploaded configuration."));
92     mvwaddstr(main_sub, 5, 20, _("Do you want to continue? "));
93     wrefresh(main_sub);
94     print_help(ANSW_NO);
95     i = 1;
96     while (i)
97         switch (getch()) {
98         case 'Y':
99         case 'y':
100             clear_main(3);
101             i = 0;
102             break;
103         case 'n':
104         case 'N':
105             clear_main(3);
106             goto quit;
107         }
108
109     print_help(WAIT_SET);
110     if (SysReset())
111         print_helperr(ERR_SET);
112     else
113         print_help(_("Access Point reset. Press any key to continue."));
114     getch();
115   quit:
116     print_title("");
117 }
118
119 int SysUpload()
120 {
121     char sysUpload[] =
122         { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x06,
123         0x00
124     }, enable = 1;
125     varbind varbinds[1];
126
127     if (ap_type == ATMEL12350) {
128         sysUpload[5] = 0xE0;
129         sysUpload[6] = 0x3E;
130     }
131
132     varbinds[0].oid = sysUpload;
133     varbinds[0].len_oid = sizeof(sysUpload);
134     varbinds[0].value = &enable;
135     varbinds[0].len_val = 1;
136     varbinds[0].type = INT_VALUE;
137     if (snmp(varbinds, 1, SET) <= 0)
138         return -1;
139     else
140         return 0;
141 }
142
143 void upload()
144 {
145     int i;
146     print_title(_("Upload configuration"));
147     mvwaddstr(main_sub, 3, 2,
148               _
149               ("You need to upload the configuration only if you've changed"));
150     mvwaddstr(main_sub, 4, 2,
151               _
152               ("some option values before. Using this option may cause loss"));
153     mvwaddstr(main_sub, 5, 2, _("of your current configuration."));
154     mvwaddstr(main_sub, 7, 20, ("Do you want to continue? "));
155     wrefresh(main_sub);
156     print_help(ANSW_NO);
157     i = 1;
158     while (i)
159         switch (getch()) {
160         case 'Y':
161         case 'y':
162             clear_main(3);
163             i = 0;
164             break;
165         case 'n':
166         case 'N':
167             clear_main(3);
168             goto quit;
169         }
170
171     print_help(WAIT_SET);
172     if (SysUpload())
173         print_helperr(ERR_SET);
174     else
175         print_help
176             (_("Configuration uploaded. Press any key to continue."));
177     getch();
178   quit:
179     print_title("");
180 }
181