2 * test.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
25 #include "ap-curses.h"
27 #define TEST_MODE _("[T] Test mode: ")
28 #define ANTENNA _("[A] Antenna: ")
29 #define SIGLEVEL _("[S] Signal level: ")
30 #define RATE _("[R] Rate: ")
31 #define FILER _("[F] TxFiler: ")
32 #define COMMAND _("[O] Command: ")
33 #define __HELP _("T - Test mode On/Off; CASRFO - set options; Q - quit to menu")
35 extern WINDOW *main_sub;
41 struct TestModeCommandStruct_ATMEL410 {
42 unsigned char Channel;
43 unsigned char Antenna;
44 unsigned char RegCR31;
46 unsigned char TxFiler; //US 01 - JPN 02
47 unsigned char Command; //CMD_CONTINUOUS_TX 0x01, CMD_CONTINUOUS_RX 0x02, CMD_CARRIER_ACCURACY 0x03, CMD_IDLE 0x04
52 struct TestModeStatistics {
53 unsigned long SuccessFrames;
54 unsigned long FailedFrames;
57 char TestModeOnOff[] =
58 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x08, 0x01,
61 char TestModeCommandStruct[] =
62 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x08, 0x02,
65 char TestModeStatistics[] =
66 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x08, 0x09,
70 char message[1024], *antenna[2] =
71 { _("Left"), _("Right") }, *filer[2] = {
72 "EN", "US"}, *rates[4] = {
73 "1", "2", "5.5", "11"}, *item_name[14];
74 char teston = 2, *commands[4] =
75 { "CONTINUOUS_TX", "CONTINUOUS_RX", "CARRIER_ACCURACY", "IDLE" };
79 if (ap_type == ATMEL12350) {
80 TestModeOnOff[5] = 0xE0;
81 TestModeOnOff[6] = 0x3E;
82 TestModeCommandStruct[5] = 0xE0;
83 TestModeCommandStruct[6] = 0x3E;
84 TestModeStatistics[5] = 0xE0;
85 TestModeStatistics[6] = 0x3E;
88 print_title(_("Test mode"));
89 mvwaddstr(main_sub, 3, 6,
91 ("Using the \"Test mode\" may cause loss of your current"));
92 mvwaddstr(main_sub, 4, 6, _("configuration."));
93 mvwaddstr(main_sub, 6, 20, _("Do you want to continue? "));
95 print_help(_("(Y - Yes; N - No (it's safer to answer No.)"));
110 if ((ch_num = ch_list(0, item_name)) == 0) {
111 print_helperr(ERR_RET);
115 sprintf(message, "%s%s", TEST_MODE, OFF);
116 mvwaddstr(main_sub, 0, 0, message);
118 mvwaddstr(main_sub, 2, 1, _("Options:"));
119 testmode.Channel = 1;
120 sprintf(message, "%s%02u (%u MHz)", CHANNEL, testmode.Channel,
121 2407 + 5 * testmode.Channel);
122 mvwaddstr(main_sub, 3, 0, message);
124 testmode.Antenna = 1;
125 sprintf(message, "%s%s", ANTENNA, antenna[testmode.Antenna - 1]);
126 mvwaddstr(main_sub, 4, 0, message);
128 testmode.RegCR31 = 128;
129 sprintf(message, "%s%u", SIGLEVEL, testmode.RegCR31);
130 mvwaddstr(main_sub, 5, 0, message);
133 sprintf(message, "%s%.1f Mbit/s", RATE, (float) testmode.Rate / 2);
134 mvwaddstr(main_sub, 6, 0, message);
136 testmode.TxFiler = 1;
137 sprintf(message, "%s%s", FILER, filer[testmode.TxFiler - 1]);
138 mvwaddstr(main_sub, 7, 0, message);
140 testmode.Command = 1;
141 sprintf(message, "%s%s", COMMAND, commands[testmode.Command - 1]);
142 mvwaddstr(main_sub, 8, 0, message);
144 mvwaddstr(main_sub, 10, 1, _("Statistics:"));
145 mvwaddstr(main_sub, 11, 0, _("Success Frames: 0 Failed Frames: 0"));
156 varbinds[0].oid = TestModeOnOff;
157 varbinds[0].len_oid = sizeof(TestModeOnOff);
158 varbinds[0].value = &teston;
159 varbinds[0].len_val = 1;
160 varbinds[0].type = INT_VALUE;
161 if (snmp(varbinds, 1, SET) <= 0) {
162 print_helperr(ERR_RET);
169 teston = on_off(0, 1 + strlen(TEST_MODE));
172 clear_main_new(0, 1);
173 print_menusel(0, 0, TEST_MODE, ON);
174 varbinds[0].oid = TestModeOnOff;
175 varbinds[0].len_oid = sizeof(TestModeOnOff);
176 varbinds[0].value = &teston;
177 varbinds[0].len_val = 1;
178 varbinds[0].type = INT_VALUE;
179 varbinds[1].oid = TestModeCommandStruct;
180 varbinds[1].len_oid = sizeof(TestModeCommandStruct);
181 varbinds[1].len_val = sizeof(testmode);
182 varbinds[1].value = (char *) &testmode;
183 varbinds[1].type = STRING_VALUE;
184 if (snmp(varbinds, 2, SET) <= 0) {
185 print_helperr(ERR_RET);
189 varbinds[0].oid = TestModeStatistics;
190 varbinds[0].len_oid = sizeof(TestModeStatistics);
191 varbinds[0].value = TestModeStatistics;
192 varbinds[0].len_val = 0;
193 varbinds[0].type = NULL_VALUE;
195 if (snmp(varbinds, 1, GET) <= 0) {
196 print_helperr(ERR_RET);
201 (struct TestModeStatistics *) malloc(varbinds[0].
203 memcpy(teststat, varbinds[0].value,
204 sizeof(struct TestModeStatistics));
205 clear_main_new(11, 12);
207 _("Success Frames: %lu Failed Frames: %lu"),
208 swap4(teststat->SuccessFrames),
209 swap4(teststat->FailedFrames));
210 mvwaddstr(main_sub, 11, 0, message);
213 clear_main_new(0, 1);
214 sprintf(message, "%s%s", TEST_MODE, OFF);
215 mvwaddstr(main_sub, 0, 0, message);
217 varbinds[0].oid = TestModeOnOff;
218 varbinds[0].len_oid = sizeof(TestModeOnOff);
219 varbinds[0].value = &teston;
220 varbinds[0].len_val = 1;
221 varbinds[0].type = INT_VALUE;
223 if (snmp(varbinds, 1, SET) <= 0) {
224 print_helperr(ERR_RET);
232 testmode.Channel = menu_choose(3, strlen(CHANNEL), item_name,
234 clear_main_new(3, 4);
235 sprintf(message, "%02u (%u MHz)", testmode.Channel,
236 2407 + 5 * testmode.Channel);
237 print_menusel(3, 0, CHANNEL, message);
241 switch (menu_choose(6, strlen(RATE), rates, 4)) {
254 clear_main_new(6, 7);
255 sprintf(message, "%.1f Mbit/s", (float) testmode.Rate / 2);
256 print_menusel(6, 0, RATE, message);
260 testmode.Antenna = menu_choose(4, strlen(ANTENNA), antenna, 2) + 1;
261 clear_main_new(4, 5);
262 print_menusel(4, 0, ANTENNA, antenna[testmode.Antenna - 1]);
266 testmode.Command = menu_choose(8, strlen(COMMAND), commands, 4) + 1;
267 clear_main_new(8, 9);
268 print_menusel(8, 0, COMMAND, commands[testmode.Command - 1]);
272 testmode.TxFiler = menu_choose(7, strlen(FILER), filer, 2) + 1;
273 clear_main_new(7, 8);
274 print_menusel(7, 0, FILER, filer[testmode.TxFiler - 1]);
278 // make_field(5, strlen(SIGLEVEL), 4);
279 get_value(message, 5, strlen(SIGLEVEL), 4, INT_STRING, 0, 255,
281 print_menusel(5, 0, SIGLEVEL, message);
282 testmode.RegCR31 = atoi(message) & 0xFF;
293 /* free memory allocated for channel list */
294 for (i = 0; i < ch_num; i++)