]> git.decadent.org.uk Git - ap-utils.git/blob - lib/test.c
Imported Upstream version 1.5~pre1
[ap-utils.git] / lib / test.c
1 /*
2  *      test.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 #include <math.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include "ap-utils.h"
25
26 #define TEST_MODE _("[T] Test mode: ")
27 #define ANTENNA _("[A] Antenna: ")
28 #define SIGLEVEL _("[S] Signal level: ")
29 #define RATE _("[R] Rate: ")
30 #define FILER _("[F] TxFiler: ")
31 #define COMMAND _("[O] Command: ")
32 #define __HELP _("T - Test mode On/Off; CASRFO - set options; Q - quit to menu")
33
34 extern WINDOW *main_sub;
35 extern short ap_type;
36 extern char *channels[];
37
38 void test()
39 {
40     struct TestModeCommandStruct_ATMEL410 {
41         unsigned char Channel;
42         unsigned char Antenna;
43         unsigned char RegCR31;
44         unsigned char Rate;
45         unsigned char TxFiler;  //US 01 - JPN 02
46         unsigned char Command;  //CMD_CONTINUOUS_TX 0x01, CMD_CONTINUOUS_RX 0x02, CMD_CARRIER_ACCURACY 0x03, CMD_IDLE 0x04
47         unsigned char Res1;
48         unsigned char Res2;
49     } testmode;
50
51     struct TestModeStatistics {
52         unsigned long SuccessFrames;
53         unsigned long FailedFrames;
54     } *teststat = NULL;
55
56     char TestModeOnOff[] =
57         { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x08, 0x01,
58         0x00
59     };
60     char TestModeCommandStruct[] =
61         { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x08, 0x02,
62         0x00
63     };
64     char TestModeStatistics[] =
65         { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x08, 0x09,
66         0x00
67     };
68
69     char message[1024], *antenna[2] =
70         { _("Left"), _("Right") }, *filer[2] = {
71     "EN", "US"}, *rates[4] = {
72     "1", "2", "5.5", "11"};
73     char teston = 2, *commands[4] =
74         { "CONTINUOUS_TX", "CONTINUOUS_RX", "CARRIER_ACCURACY", "IDLE" };
75     varbind varbinds[5];
76
77     if (ap_type == ATMEL12350) {
78         TestModeOnOff[5] = 0xE0;
79         TestModeOnOff[6] = 0x3E;
80         TestModeCommandStruct[5] = 0xE0;
81         TestModeCommandStruct[6] = 0x3E;
82         TestModeStatistics[5] = 0xE0;
83         TestModeStatistics[6] = 0x3E;
84     }
85
86     print_top(NULL, _("Test mode"));
87     mvwaddstr(main_sub, 3, 6,
88               _
89               ("Using the \"Test mode\" may cause loss of your current"));
90     mvwaddstr(main_sub, 4, 6, _("configuration."));
91     mvwaddstr(main_sub, 6, 20, _("Do you want to continue? "));
92     wrefresh(main_sub);
93
94     if (help_ysn())
95         goto quit;
96
97     print_help(__HELP);
98
99     sprintf(message, "%s%s", TEST_MODE, OFF);
100     mvwaddstr(main_sub, 0, 0, message);
101
102     mvwaddstr(main_sub, 2, 1, _("Options:"));
103     testmode.Channel = 1;
104     sprintf(message, "%s%02u (%u MHz)", CHANNEL, testmode.Channel,
105             2407 + 5 * testmode.Channel);
106     mvwaddstr(main_sub, 3, 0, message);
107
108     testmode.Antenna = 1;
109     sprintf(message, "%s%s", ANTENNA, antenna[testmode.Antenna - 1]);
110     mvwaddstr(main_sub, 4, 0, message);
111
112     testmode.RegCR31 = 128;
113     sprintf(message, "%s%u", SIGLEVEL, testmode.RegCR31);
114     mvwaddstr(main_sub, 5, 0, message);
115
116     testmode.Rate = 2;
117     sprintf(message, "%s%.1f Mbit/s", RATE, (float) testmode.Rate / 2);
118     mvwaddstr(main_sub, 6, 0, message);
119
120     testmode.TxFiler = 1;
121     sprintf(message, "%s%s", FILER, filer[testmode.TxFiler - 1]);
122     mvwaddstr(main_sub, 7, 0, message);
123
124     testmode.Command = 1;
125     sprintf(message, "%s%s", COMMAND, commands[testmode.Command - 1]);
126     mvwaddstr(main_sub, 8, 0, message);
127
128     mvwaddstr(main_sub, 10, 1, _("Statistics:"));
129     mvwaddstr(main_sub, 11, 0, _("Success Frames: 0 Failed Frames: 0"));
130
131     wrefresh(main_sub);
132     noecho();
133     while (1) {
134         switch (getch()) {
135         case 'Q':
136         case 'q':
137             if (teston == 1) {
138                 teston = 2;
139                 varbinds[0].oid = TestModeOnOff;
140                 varbinds[0].len_oid = sizeof(TestModeOnOff);
141                 varbinds[0].value = &teston;
142                 varbinds[0].len_val = 1;
143                 varbinds[0].type = INT_VALUE;
144                 if (snmp(varbinds, 1, SET) <= 0) {
145                     print_helperr(ERR_RET);
146                     goto exit;
147                 }
148             }
149             goto quit;
150         case 'T':
151         case 't':
152             teston = on_off(0, 1 + strlen(TEST_MODE));
153
154             if (teston == 1) {
155                 clear_main_new(0, 1);
156                 print_menusel(0, 0, TEST_MODE, ON);
157                 varbinds[0].oid = TestModeOnOff;
158                 varbinds[0].len_oid = sizeof(TestModeOnOff);
159                 varbinds[0].value = &teston;
160                 varbinds[0].len_val = 1;
161                 varbinds[0].type = INT_VALUE;
162                 varbinds[1].oid = TestModeCommandStruct;
163                 varbinds[1].len_oid = sizeof(TestModeCommandStruct);
164                 varbinds[1].len_val = sizeof(testmode);
165                 varbinds[1].value = (char *) &testmode;
166                 varbinds[1].type = STRING_VALUE;
167                 if (snmp(varbinds, 2, SET) <= 0) {
168                     print_helperr(ERR_RET);
169                     goto exit;
170                 }
171             } else {
172                 varbinds[0].oid = TestModeStatistics;
173                 varbinds[0].len_oid = sizeof(TestModeStatistics);
174                 varbinds[0].value = TestModeStatistics;
175                 varbinds[0].len_val = 0;
176                 varbinds[0].type = NULL_VALUE;
177
178                 if (snmp(varbinds, 1, GET) <= 0) {
179                     print_helperr(ERR_RET);
180                     getch();
181                     print_help(__HELP);
182                 } else {
183                     teststat =
184                         (struct TestModeStatistics *) malloc(varbinds[0].
185                                                              len_val);
186                     memcpy(teststat, varbinds[0].value,
187                            sizeof(struct TestModeStatistics));
188                     clear_main_new(11, 12);
189                     sprintf(message,
190                             _("Success Frames: %lu Failed Frames: %lu"),
191                             swap4(teststat->SuccessFrames),
192                             swap4(teststat->FailedFrames));
193                     mvwaddstr(main_sub, 11, 0, message);
194                     free(teststat);
195                 }
196                 clear_main_new(0, 1);
197                 sprintf(message, "%s%s", TEST_MODE, OFF);
198                 mvwaddstr(main_sub, 0, 0, message);
199
200                 varbinds[0].oid = TestModeOnOff;
201                 varbinds[0].len_oid = sizeof(TestModeOnOff);
202                 varbinds[0].value = &teston;
203                 varbinds[0].len_val = 1;
204                 varbinds[0].type = INT_VALUE;
205
206                 if (snmp(varbinds, 1, SET) <= 0) {
207                     print_helperr(ERR_RET);
208                     goto exit;
209                 }
210                 wrefresh(main_sub);
211             }
212             continue;
213         case 'C':
214         case 'c':
215             testmode.Channel = menu_choose(3, strlen(CHANNEL), channels,
216                 14) + 1;
217             clear_main_new(3, 4);
218             sprintf(message, "%02u (%u MHz)", testmode.Channel,
219                 2407 + 5 * testmode.Channel);
220             print_menusel(3, 0, CHANNEL, message);
221             continue;
222         case 'R':
223         case 'r':
224             switch (menu_choose(6, strlen(RATE), rates, 4)) {
225             case 0:
226                 testmode.Rate = 2;
227                 break;
228             case 1:
229                 testmode.Rate = 4;
230                 break;
231             case 2:
232                 testmode.Rate = 11;
233                 break;
234             case 3:
235                 testmode.Rate = 22;
236             }
237             clear_main_new(6, 7);
238             sprintf(message, "%.1f Mbit/s", (float) testmode.Rate / 2);
239             print_menusel(6, 0, RATE, message);
240             continue;
241         case 'A':
242         case 'a':
243             testmode.Antenna = menu_choose(4, strlen(ANTENNA), antenna, 2) + 1;
244             clear_main_new(4, 5);
245             print_menusel(4, 0, ANTENNA, antenna[testmode.Antenna - 1]);
246             continue;
247         case 'O':
248         case 'o':
249             testmode.Command = menu_choose(8, strlen(COMMAND), commands, 4) + 1;
250             clear_main_new(8, 9);
251             print_menusel(8, 0, COMMAND, commands[testmode.Command - 1]);
252             continue;
253         case 'F':
254         case 'f':
255             testmode.TxFiler = menu_choose(7, strlen(FILER), filer, 2) + 1;
256             clear_main_new(7, 8);
257             print_menusel(7, 0, FILER, filer[testmode.TxFiler - 1]);
258             continue;
259         case 'S':
260         case 's':
261 //          make_field(5, strlen(SIGLEVEL), 4);
262             get_value(message, 5, strlen(SIGLEVEL), 4, INT_STRING, 0, 255,
263                 __HELP);
264             print_menusel(5, 0, SIGLEVEL, message);
265             testmode.RegCR31 = atoi(message) & 0xFF;
266             continue;
267         default:
268             continue;
269         }
270         break;
271     }
272
273     print_help(ANY_KEY);
274   exit:
275     getch();
276   quit:
277     print_top(NULL, NULL);
278     clear_main(0);
279 }