]> git.decadent.org.uk Git - ap-utils.git/blob - lib/cmd.c
Imported Upstream version 1.5~pre1
[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
24 extern WINDOW *main_sub;
25 extern short ap_type;
26
27 void defaults()
28 {
29     char sysLoadDefaults[] =
30         { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01,
31         0x01, 0x04, 0x00
32     }, enable = 1;
33     varbind varbinds[1];
34
35     if (ap_type == ATMEL12350) {
36         sysLoadDefaults[5] = 0xE0;
37         sysLoadDefaults[6] = 0x3E;
38     }
39
40     print_top(NULL, _("Restore factory default configuration"));
41     mvwaddstr(main_sub, 3, 2,
42               _
43               ("After restoring factory defaults your current configuration"));
44     mvwaddstr(main_sub, 4, 2, _("will be lost."));
45     mvwaddstr(main_sub, 6, 20, _("Do you want to continue? "));
46     wrefresh(main_sub);
47
48     if (help_ysn())
49         goto quit;
50
51     print_help(WAIT_SET);
52
53     varbinds[0].oid = sysLoadDefaults;
54     varbinds[0].len_oid = sizeof(sysLoadDefaults);
55     varbinds[0].value = &enable;
56     varbinds[0].len_val = 1;
57     varbinds[0].type = INT_VALUE;
58     if (snmp(varbinds, 1, SET) <= 0)
59         print_helperr(ERR_SET);
60     else
61         print_help
62             (_
63              ("Factory default settings loaded. Press any key to continue."));
64     getch();
65   quit:
66     print_top(NULL, NULL);
67 }
68
69 void reset()
70 {
71     print_top(NULL, _("Reset Access Point"));
72     if(ap_type == ATMEL410) 
73         mvwaddstr(main_sub, 3, 5,
74               _("By reset you'll lose all non-uploaded configuration."));
75     mvwaddstr(main_sub, 5, 20, _("Do you want to continue? "));
76     wrefresh(main_sub);
77
78     if (help_ysn())
79         goto quit;
80
81     print_help(WAIT_SET);
82     if (SysReset())
83         print_helperr(ERR_SET);
84     else
85         print_help(_("Access Point reset. Press any key to continue."));
86     getch();
87   quit:
88     print_top(NULL, NULL);
89 }
90
91 int SysUpload()
92 {
93     char sysUpload[] =
94         { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x06,
95         0x00
96     }, enable = 1;
97     varbind varbinds[1];
98
99     if (ap_type == ATMEL12350) {
100         sysUpload[5] = 0xE0;
101         sysUpload[6] = 0x3E;
102     }
103
104     varbinds[0].oid = sysUpload;
105     varbinds[0].len_oid = sizeof(sysUpload);
106     varbinds[0].value = &enable;
107     varbinds[0].len_val = 1;
108     varbinds[0].type = INT_VALUE;
109     if (snmp(varbinds, 1, SET) <= 0)
110         return -1;
111     else
112         return 0;
113 }
114
115 void upload()
116 {
117     print_top(NULL, _("Upload configuration"));
118     mvwaddstr(main_sub, 3, 2,
119         _("You may need to upload the configuration only if you've"));
120     mvwaddstr(main_sub, 4, 2,
121         _("changed some option values before. Using this option may"));
122     mvwaddstr(main_sub, 5, 2,
123         _("cause loss of your current configuration."));
124     mvwaddstr(main_sub, 7, 20, ("Do you want to continue? "));
125     wrefresh(main_sub);
126
127     if (help_ysn())
128         goto quit;
129
130     print_help(WAIT_SET);
131     if (SysUpload())
132         print_helperr(ERR_SET);
133     else
134         print_help
135             (_("Configuration uploaded. Press any key to continue."));
136     getch();
137   quit:
138     print_top(NULL, NULL);
139 }
140