]> git.decadent.org.uk Git - ap-utils.git/blob - lib/wlan.c
Imported Upstream version 1.5~pre1
[ap-utils.git] / lib / wlan.c
1 /*
2  *      wlan.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 <string.h>
21 #include <stdlib.h>
22 #include <menu.h>
23 #include <unistd.h>
24 #include <sys/types.h>
25 #include "ap-utils.h"
26
27 #define ESSID _("[E] ESSID: ")
28 #define AP_NAME _("[N] AP name: ")
29
30 #define CONTACT _("[K] AP contact: ")
31 #define LOCATION _("[L] AP location: ")
32
33 #define RTS_TR _("[R] RTS threshold: ")
34 #define FRG_TR _("[F] Fragmentation threshold: ")
35 #define PREAMBULE _("[P] Preambule type: ")
36 #define AUTH _("[A] Auth type: ")
37 #define   OSYS _("Open system")
38 #define   SH_KEY _("Shared key")
39 #define   BOTH_TYPE _("Both types")
40 #define RETRAIN _("[U] Auto rate fallback: ")
41 #define HIDE_ESSID _("[S] Insert ESSID in broadcast packets: ")
42 #define RATES _("Basic and Supported rates:")
43 #define RATES_HEAD _("Key   Rate  Status")
44 #define   RATES_RECORD "[%d]  %4.1fM   "
45 #define INT_ROAMING _("[I] International roaming: ")
46 #define BEACON_PER _("[B] Beacon period (msec): ")
47 #define DTIM_I _("[D] DTIM sending interval (beacons): ")
48 #define SIFS_T _("[T] SIFS time (msec): ")
49 #define WLAN_HELP _("[key] - set option; W - write conf; Q - quit to menu")
50
51 extern short ap_type, ap_vendorext;
52
53 void atmel_wireless()
54 {
55     char sysDeviceInfo[] = {
56         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x05, 0x00
57     };
58
59     char operChannelID[] = {
60         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x01, 0x01, 0x00
61     };
62     char operESSIDLength[] = {
63         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x01, 0x02, 0x00
64     };
65     char operESSID[] = {
66         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x01, 0x03, 0x00
67     };
68     char operRTSThreshold[] = {
69         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x01, 0x04, 0x00
70     };
71     char operFragmentationThreshold[] = {
72         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x01, 0x05, 0x00
73     };
74     char operPreambleType[] = {
75         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x01, 0x06, 0x00
76     };
77     char operAuthenticationType[] = {
78         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x01, 0x07, 0x00
79     };
80     char operBasicRates[] = {
81         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x01, 0x08, 0x00
82     };
83     char operAutoRateFallBack[] = {
84         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x01, 0x09, 0x00
85     };
86     char operAccessPointName[] = {
87         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x01, 0x0A, 0x00
88     };
89     char operSSIDBroadcasting[] = {
90         0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x01, 0x0B, 0x00
91     };
92
93     /* This one is ATMEL12350 MIB specific. */
94     char operInterRoaming[] = {
95         0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x01, 0x0D, 0x00
96     };
97     /* These two are ATMEL12350 TELLUS MIB specific. */
98     char operBeaconPeriod[] = {
99         0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x01, 0x0E, 0x00
100     };
101     char operDTIM[] = {
102         0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x01, 0x0F, 0x00
103     };
104     /* This one is ATMEL12350 VERNET MIB specific. */
105     char operSIFSTIME[] = {
106         0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x01, 0x10, 0x00
107     };
108
109     extern WINDOW *main_sub;
110     extern rdprops regdom_types[];
111     extern char *channels[];
112     varbind varbinds[16];
113     unsigned short int RTSThreshold, FragmentationThreshold,
114         InterRoaming, m_basic_rates = 0, BeaconPeriod = 0, sifs = 0;
115     unsigned char dtim, ch;
116     char *AuthenticationTypes[3] = { OSYS, SH_KEY, BOTH_TYPE },
117         message[1024];
118     char domain[32], basic_rates[4], AutoRateFallBack, SSIDBroadcasting,
119         ap_name[32], PreambleType, AuthenticationType, channel;
120     char m_channel = 0, m_essid = 0, m_broadcast = 0, m_rts = 0,
121         m_fragment = 0, m_auth = 0, m_ap_name = 0, m_preambule = 0,
122         m_auto_rate = 0, m_inter_roaming = 0, m_beacon = 0, m_dtim = 0,
123         m_sifs = 0;
124     char *rates[3] = { ON, OFF, BASIC }, *preambules[2] = {
125     _("Short"), _("Long")};
126     short __rates[4] = { 2, 4, 11, 22 };
127     int i, c = 0, rd_idx;
128     unsigned short ap_regdomain;
129     struct sysDeviceInfo_ATMEL410 str410;
130     struct sysDeviceInfo_ATMEL12350 str12350;
131
132
133     if (ap_type == ATMEL12350) {
134         sysDeviceInfo[5] = 0xE0;
135         sysDeviceInfo[6] = 0x3E;
136         operChannelID[5] = 0xE0;
137         operChannelID[6] = 0x3E;
138         operESSIDLength[5] = 0xE0;
139         operESSIDLength[6] = 0x3E;
140         operESSID[5] = 0xE0;
141         operESSID[6] = 0x3E;
142         operRTSThreshold[5] = 0xE0;
143         operRTSThreshold[6] = 0x3E;
144         operFragmentationThreshold[5] = 0xE0;
145         operFragmentationThreshold[6] = 0x3E;
146         operPreambleType[5] = 0xE0;
147         operPreambleType[6] = 0x3E;
148         operAuthenticationType[5] = 0xE0;
149         operAuthenticationType[6] = 0x3E;
150         operBasicRates[5] = 0xE0;
151         operBasicRates[6] = 0x3E;
152         operAutoRateFallBack[5] = 0xE0;
153         operAutoRateFallBack[6] = 0x3E;
154         operAccessPointName[5] = 0xE0;
155         operAccessPointName[6] = 0x3E;
156         operSSIDBroadcasting[5] = 0xE0;
157         operSSIDBroadcasting[6] = 0x3E;
158     }
159
160     for (i = 0; i < 16; i++) {
161         varbinds[i].type = NULL_VALUE;
162         varbinds[i].len_val = 0;
163         varbinds[i].len_oid = sizeof(operChannelID);
164     }
165
166     i = 0;
167
168     varbinds[i++].oid = operChannelID;
169     varbinds[i++].oid = operESSIDLength;
170     varbinds[i++].oid = operESSID;
171     varbinds[i++].oid = operSSIDBroadcasting;
172     varbinds[i++].oid = operBasicRates;
173     varbinds[i++].oid = operAutoRateFallBack;
174     varbinds[i++].oid = operRTSThreshold;
175     varbinds[i++].oid = operFragmentationThreshold;
176     varbinds[i++].oid = operPreambleType;
177     varbinds[i++].oid = operAuthenticationType;
178     varbinds[i++].oid = operAccessPointName;
179     varbinds[i++].oid = sysDeviceInfo;
180     if (ap_type == ATMEL12350) {
181         varbinds[i++].oid = operInterRoaming;
182         if (ap_vendorext == TELLUS || ap_vendorext == VERNET) {
183             varbinds[i++].oid = operBeaconPeriod;
184             varbinds[i++].oid = operDTIM;
185         }
186         if (ap_vendorext == VERNET)
187             varbinds[i++].oid = operSIFSTIME;
188     }
189
190     print_help(WAIT_RET);
191     if (snmp(varbinds, i, GET) <= 0) {
192         print_helperr(ERR_RET);
193         goto exit;
194     }
195
196     channel = *(varbinds[0].value);
197     c = *(varbinds[1].value);
198     memcpy(domain, varbinds[2].value, 32);
199     SSIDBroadcasting = *(varbinds[3].value);
200     memcpy(basic_rates, varbinds[4].value, 4);
201     AutoRateFallBack = *(varbinds[5].value);
202     memcpy(&RTSThreshold, varbinds[6].value, 2);
203     RTSThreshold = ntohs(RTSThreshold);
204     memcpy(&FragmentationThreshold, varbinds[7].value, 2);
205     FragmentationThreshold = ntohs(FragmentationThreshold);
206     PreambleType = *(varbinds[8].value);
207     AuthenticationType = *(varbinds[9].value);
208     memcpy(ap_name, varbinds[10].value, 32);
209     if (ap_type == ATMEL12350) {
210         InterRoaming = *(varbinds[12].value);
211         if (ap_vendorext == TELLUS || ap_vendorext == VERNET) {
212             BeaconPeriod = varbinds[13].len_val == 2 ?
213                 (varbinds[13].value[0] << 8) | varbinds[13].value[1] :
214                 varbinds[13].value[0] < 0x80 ?
215                 varbinds[13].value[0] : 0xff00 | varbinds[13].value[0];
216             dtim = *(varbinds[14].value);
217         }
218         if (ap_vendorext == VERNET)
219             sifs = varbinds[15].len_val == 2 ?
220                 (varbinds[15].value[0] << 8) | varbinds[15].value[1] :
221                 varbinds[15].value[0] < 0x80 ?
222                 varbinds[15].value[0] : 0xff00 | varbinds[15].value[0];
223     }
224
225     if (ap_type == ATMEL12350) {
226         memcpy(&str12350, varbinds[11].value,
227             sizeof(struct sysDeviceInfo_ATMEL12350));
228         ap_regdomain=str12350.RegulatoryDomain;
229     } else /* ATMEL410 */{
230         memcpy(&str410, varbinds[11].value,
231             sizeof(struct sysDeviceInfo_ATMEL410));
232         ap_regdomain = swap4(str410.RegulatoryDomain);
233     }
234
235     rd_idx = regdom_idx(ap_regdomain);
236
237     print_top(NULL, _("Wireless Settings"));
238
239     sprintf(message, "%s%02u (%u MHz)", CHANNEL, channel, 2407 + 5 * channel);
240     mvwaddstr(main_sub, 0, 0, message);
241     mvwaddstr(main_sub, 1, 0, ESSID);
242     waddnstr(main_sub, domain, c);
243     mvwaddstr(main_sub, 2, 0, AP_NAME);
244     for (i = 0; i < 32 && ap_name[i]; i++)
245         mvwaddch(main_sub, 2, strlen(AP_NAME) + i, ap_name[i]);
246     sprintf(message, "%s%d", RTS_TR, RTSThreshold);
247     mvwaddstr(main_sub, 3, 0, message);
248     sprintf(message, "%s%d", FRG_TR, FragmentationThreshold);
249     mvwaddstr(main_sub, 4, 0, message);
250     sprintf(message, "%s%s", PREAMBULE, preambules[PreambleType - 1]);
251     mvwaddstr(main_sub, 5, 0, message);
252     sprintf(message, "%s%s", AUTH, AuthenticationTypes[AuthenticationType - 1]);
253     mvwaddstr(main_sub, 6, 0, message);
254     sprintf(message, "%s%s", RETRAIN, (AutoRateFallBack == 1) ? ON : OFF);
255     mvwaddstr(main_sub, 7, 0, message);
256     sprintf(message, "%s%s", HIDE_ESSID, (SSIDBroadcasting == 1) ? ON : OFF);
257     mvwaddstr(main_sub, 8, 0, message);
258     mvwaddstr(main_sub, 9, 0, RATES);
259     mvwaddstr(main_sub, 10, 2, RATES_HEAD);
260     for (i = 0; i < 4; i++) {
261         sprintf(message, RATES_RECORD "%s", i + 1, (float) __rates[i] / 2,
262                 basic(basic_rates[i]));
263         mvwaddstr(main_sub, 11 + i, 2, message);
264     }
265     if (ap_type == ATMEL12350) {
266         sprintf(message, "%s%s", INT_ROAMING, (InterRoaming == 1) ? ON : OFF);
267         mvwaddstr(main_sub, 15, 0, message);
268         if (ap_vendorext == TELLUS || ap_vendorext == VERNET) {
269             sprintf(message, "%s%u", BEACON_PER, BeaconPeriod);
270             mvwaddstr(main_sub, 16, 0, message);
271             sprintf(message, "%s%u", DTIM_I, dtim);
272             mvwaddstr(main_sub, 17, 0, message);
273         }
274         if (ap_vendorext == VERNET) {
275             sprintf(message, "%s%u", SIFS_T, sifs);
276             mvwaddstr(main_sub, 18, 0, message);
277         }
278     }
279
280     wrefresh(main_sub);
281     noecho();
282     print_help(WLAN_HELP);
283
284     while (1) {
285         c = getch();
286         switch (c) {
287         case 'Q':
288         case 'q':
289             goto quit;
290         case '1':
291         case '2':
292         case '3':
293         case '4':
294             message[0] = c;
295             message[1] = '\0';
296             i = atoi(message);
297             switch (menu_choose(10 + i, 15, rates, 3)) {
298             case 0:
299                 basic_rates[i - 1] = __rates[i - 1];
300                 break;
301             case 1:
302                 basic_rates[i - 1] = 0;
303                 break;
304             case 2:
305                 basic_rates[i - 1] = __rates[i - 1] + 0x80;
306             }
307             clear_main_new(10 + i, 11 + i);
308             sprintf(message, RATES_RECORD, i, (float) __rates[i - 1] / 2);
309             print_menusel(10 + i, 2, message, basic(basic_rates[i - 1]));
310             m_basic_rates = 1;
311             break;
312         case 'C':
313         case 'c':
314             channel = menu_choose(0, strlen(CHANNEL),
315 #ifndef NO_REG_DOMAIN
316                 channels + regdom_types[rd_idx].first_ch - 1,
317                 regdom_types[rd_idx].chans) + regdom_types[rd_idx].first_ch;
318 #else
319                 channels, 14) + 1;
320 #endif
321             sprintf(message, "%02u (%u MHz)", channel, 2407 + 5 * channel);
322             print_menusel(0, 0, CHANNEL, message);
323             m_channel = 1;
324             continue;
325         case 'A':
326         case 'a':
327             AuthenticationType =
328                 menu_choose(6, strlen(AUTH), AuthenticationTypes, 3) + 1;
329             clear_main_new(6, 7);
330             print_menusel(6, 0, AUTH,
331                     AuthenticationTypes[AuthenticationType - 1]);
332             m_auth = 1;
333             continue;
334         case 'P':
335         case 'p':
336             PreambleType = menu_choose(5, strlen(PREAMBULE), preambules, 2) + 1;
337             clear_main_new(5, 6);
338             print_menusel(5, 0, PREAMBULE, preambules[PreambleType - 1]);
339             m_preambule = 1;
340             continue;
341         case 'U':
342         case 'u':
343             AutoRateFallBack = on_off(7, strlen(RETRAIN));
344             clear_main_new(7, 8);
345             print_menusel(7, 0, RETRAIN, (AutoRateFallBack == 1) ? ON : OFF);
346             m_auto_rate = 1;
347             continue;
348         case 'S':
349         case 's':
350             SSIDBroadcasting = on_off(8, strlen(HIDE_ESSID));
351             clear_main_new(8, 9);
352             print_menusel(8, 0, HIDE_ESSID, (SSIDBroadcasting == 1) ? ON : OFF);
353             m_broadcast = 1;
354             continue;
355         case 'N':
356         case 'n':
357 //          make_field(2, strlen(AP_NAME), 32);
358             get_value(ap_name, 2, strlen(AP_NAME), -32, ANY_STRING, 0, 0, NULL);
359             m_ap_name = 1;
360             continue;
361         case 'E':
362         case 'e':
363 //          make_field(1, strlen(ESSID), 32);
364             get_value(domain, 1, strlen(ESSID), 32, ANY_STRING, 0, 0, NULL);
365             m_essid = 1;
366             continue;
367         case 'F':
368         case 'f':
369 //          make_field(4, strlen(FRG_TR), 6);
370             get_value(message, 4, strlen(FRG_TR), 6, INT_STRING, 256, 2346,
371                 WLAN_HELP);
372             FragmentationThreshold = atoi(message);
373             m_fragment = 1;
374             continue;
375         case 'R':
376         case 'r':
377 //          make_field(3, strlen(RTS_TR), 6);
378             get_value(message, 3, strlen(RTS_TR), 6, INT_STRING, 0, 2347,
379                 WLAN_HELP);
380             RTSThreshold = atoi(message);
381             m_rts = 1;
382             continue;
383         case 'I':
384         case 'i':
385             if (ap_type == ATMEL410)
386                 continue;
387             InterRoaming = on_off(15, strlen(INT_ROAMING));
388             clear_main_new(15, 16);
389             print_menusel(15, 0, INT_ROAMING, (InterRoaming == 1) ? ON : OFF);
390             m_inter_roaming = 1;
391             continue;
392         case 'B':
393         case 'b':
394             if (ap_vendorext != TELLUS && ap_vendorext != VERNET)
395                 continue;
396             get_value(message, 16, strlen(BEACON_PER), 6, INT_STRING, 0, 65535,
397                 WLAN_HELP);
398             BeaconPeriod = atoi(message);
399             m_beacon = 1;
400             continue;
401         case 'D':
402         case 'd':
403             if (ap_vendorext != TELLUS && ap_vendorext != VERNET)
404                 continue;
405             get_value(message, 17, strlen(DTIM_I), 4, INT_STRING, 0, 255,
406                 WLAN_HELP);
407             dtim = atoi(message);
408             m_dtim = 1;
409             continue;
410         case 'T':
411         case 't':
412             if (ap_vendorext != VERNET)
413                 continue;
414             get_value(message, 18, strlen(SIFS_T), 6, INT_STRING, 0, 65535,
415                 WLAN_HELP);
416             sifs = atoi(message);
417             m_sifs = 1;
418             continue;
419         case 'w':
420         case 'W':
421             i = 0;
422             if (m_channel) {
423                 varbinds[i].oid = operChannelID;
424                 varbinds[i].len_oid = sizeof(operChannelID);
425                 varbinds[i].value = (char *) &channel;
426                 varbinds[i].len_val = 1;
427                 varbinds[i].type = INT_VALUE;
428                 i++;
429             }
430             if (m_basic_rates) {
431                 for (m_basic_rates = 0; m_basic_rates < 2; m_basic_rates++) {
432                     c = basic_rates[3 - m_basic_rates];
433                     basic_rates[3 - m_basic_rates] =
434                         basic_rates[m_basic_rates];
435                     basic_rates[m_basic_rates] = c;
436                 }
437                 varbinds[i].oid = operBasicRates;
438                 varbinds[i].len_oid = sizeof(operBasicRates);
439                 varbinds[i].value = basic_rates;
440                 varbinds[i].len_val = 4;
441                 varbinds[i].type = INT_VALUE;
442                 i++;
443             }
444             if (m_broadcast) {
445                 varbinds[i].oid = operSSIDBroadcasting;
446                 varbinds[i].len_oid = sizeof(operSSIDBroadcasting);
447                 varbinds[i].value = (char *) &SSIDBroadcasting;
448                 varbinds[i].len_val = 1;
449                 varbinds[i].type = INT_VALUE;
450                 i++;
451             }
452             if (m_auth) {
453                 varbinds[i].oid = operAuthenticationType;
454                 varbinds[i].len_oid = sizeof(operAuthenticationType);
455                 varbinds[i].value = &AuthenticationType;
456                 varbinds[i].len_val = 1;
457                 varbinds[i].type = INT_VALUE;
458                 i++;
459             }
460             if (m_preambule) {
461                 varbinds[i].oid = operPreambleType;
462                 varbinds[i].len_oid = sizeof(operPreambleType);
463                 varbinds[i].value = &PreambleType;
464                 varbinds[i].len_val = 1;
465                 varbinds[i].type = INT_VALUE;
466                 i++;
467             }
468             if (m_auto_rate) {
469                 varbinds[i].oid = operAutoRateFallBack;
470                 varbinds[i].len_oid = sizeof(operAutoRateFallBack);
471                 varbinds[i].value = &AutoRateFallBack;
472                 varbinds[i].len_val = 1;
473                 varbinds[i].type = INT_VALUE;
474                 i++;
475             }
476             if (m_ap_name) {
477                 c = strlen(ap_name);
478                 varbinds[i].oid = operAccessPointName;
479                 varbinds[i].len_oid = sizeof(operAccessPointName);
480                 varbinds[i].value = ap_name;
481                 varbinds[i].len_val = c;
482                 varbinds[i].type = STRING_VALUE;
483                 i++;
484             }
485             if (m_fragment) {
486                 varbinds[i].oid = operFragmentationThreshold;
487                 varbinds[i].len_oid = sizeof(operFragmentationThreshold);
488                 FragmentationThreshold = htons(FragmentationThreshold);
489                 varbinds[i].value = (char *) &FragmentationThreshold;
490                 varbinds[i].len_val = 2;
491                 varbinds[i].type = INT_VALUE;
492                 i++;
493             }
494             if (m_rts) {
495                 varbinds[i].oid = operRTSThreshold;
496                 varbinds[i].len_oid = sizeof(operRTSThreshold);
497                 RTSThreshold = htons(RTSThreshold);
498                 varbinds[i].value = (char *) &RTSThreshold;
499                 varbinds[i].len_val = 2;
500                 varbinds[i].type = INT_VALUE;
501                 i++;
502             }
503             if (m_essid) {
504                 ch = strlen(domain);
505                 varbinds[i].oid = operESSIDLength;
506                 varbinds[i].len_oid = sizeof(operESSIDLength);
507                 varbinds[i].value = (char *)&ch;
508                 varbinds[i].len_val = 1;
509                 varbinds[i].type = INT_VALUE;
510                 i++;
511                 varbinds[i].oid = operESSID;
512                 varbinds[i].len_oid = sizeof(operESSID);
513                 varbinds[i].value = domain;
514                 varbinds[i].len_val = ch;
515                 varbinds[i].type = STRING_VALUE;
516                 i++;
517             }
518             if (m_inter_roaming) {
519                 varbinds[i].oid = operInterRoaming;
520                 varbinds[i].len_oid = sizeof(operInterRoaming);
521                 varbinds[i].value = (char *) &InterRoaming;
522                 varbinds[i].len_val = 1;
523                 varbinds[i].type = INT_VALUE;
524                 i++;
525             }
526             if (m_beacon) {
527                 varbinds[i].oid = operBeaconPeriod;
528                 varbinds[i].len_oid = sizeof(operBeaconPeriod);
529                 BeaconPeriod = htons(BeaconPeriod);
530                 varbinds[i].value = (char *) &BeaconPeriod;
531                 varbinds[i].len_val = 2;
532                 varbinds[i].type = INT_VALUE;
533                 i++;
534             }
535             if (m_dtim) {
536                 varbinds[i].oid = operDTIM;
537                 varbinds[i].len_oid = sizeof(operDTIM);
538                 varbinds[i].value = (char *) &dtim;
539                 varbinds[i].len_val = 1;
540                 varbinds[i].type = INT_VALUE;
541                 i++;
542             }
543             if (m_sifs) {
544                 varbinds[i].oid = operSIFSTIME;
545                 varbinds[i].len_oid = sizeof(operSIFSTIME);
546                 sifs = htons(sifs);
547                 varbinds[i].value = (char *) &sifs;
548                 varbinds[i].len_val = 2;
549                 varbinds[i].type = INT_VALUE;
550                 i++;
551             }
552
553             print_help(WAIT_SET);
554             if (snmp(varbinds, i, SET) <= 0) {
555                 print_helperr(ERR_SET);
556                 goto exit;
557             }
558             print_help(DONE_SET);
559             goto exit;
560         }
561     }
562
563   exit:
564     getch();
565   quit:
566     print_top(NULL, NULL);
567     clear_main(0);
568 }
569
570 void nwn_wireless()
571 {
572     char operESSID[] =
573         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x01, 0x01, 0x09, 0x01 };
574     char operBasicRates[] =
575         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x01, 0x01, 0x0b, 0x01 };
576     char OpenSystem[] =
577         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x02, 0x01, 0x03, 0x01, 0x01 };
578     char SharedKey[] =
579         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x02, 0x01, 0x03, 0x01, 0x02 };
580     char operRTSThreshold[] =
581         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x02, 0x01, 0x01, 0x02, 0x01 };
582     char operFragmentationThreshold[] =
583         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x02, 0x01, 0x01, 0x05, 0x01 };
584     char operChannelID[] =
585         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x05, 0x01, 0x01, 0x01 };
586     char oid_dot11SupportedAntenna[][11] = {
587         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x08, 0x01, 0x02, 0x01, 0x01 },
588         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x08, 0x01, 0x02, 0x01, 0x02 },
589         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x08, 0x01, 0x03, 0x01, 0x01 },
590         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x08, 0x01, 0x03, 0x01, 0x02 },
591         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x08, 0x01, 0x04, 0x01, 0x01 },
592         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x08, 0x01, 0x04, 0x01, 0x02 }
593     };
594     char operAccessPointContact[] =
595         { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x04, 0x00 };
596     char operAccessPointName[] =
597         { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x05, 0x00 };
598     char operAccessPointLocation[] =
599         { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x06, 0x00 };
600     char sysTrapSwitch[] =
601         { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x0b, 0x1e, 0x00 };
602     char ChannelPref[] =
603         { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x02, 0x01,
604         0x06, 0x00 };
605
606     unsigned short int i, RTSThreshold, FragmentationThreshold,
607         m_basic_rates = 0, authi;
608     char *auth[3] = { OSYS, SH_KEY, BOTH_TYPE },
609          *rates[3] = { ON, OFF, BASIC },
610          message[1024],
611          m_antenna[6] = { 0, 0, 0, 0, 0, 0 },
612          antenna[6],
613          channel_pref[2] = { 0, 0 };
614     extern WINDOW *main_sub;
615     extern rdprops regdom_types[];
616     extern char *channels[];
617     char *domain, basic_rates[] =
618         { 0, 0, 0, 0 }, *ap_name, ap_location[32], ap_contact[32],
619         m_ap_contact = 0, m_ap_location = 0;
620     char m_channel = 0, m_essid = 0, m_rts = 0, m_fragment = 0, m_auth =
621         0, m_ap_name = 0, channel, traps, m_traps = 0;
622     varbind varbinds[11];
623     int c = 0, reg_domain = 0, rd_idx;
624     short __rates[4] = { 2, 4, 11, 22};
625
626     domain = (char *) calloc(32, 1);
627     ap_name = (char *) calloc(32, 1);
628
629     for (i = 0; i < 8; i++) {
630         varbinds[i].len_val = 0;
631         varbinds[i].type = NULL_VALUE;
632     }
633     varbinds[0].oid = operChannelID;
634     varbinds[0].len_oid = sizeof(operChannelID);
635     varbinds[1].oid = operESSID;
636     varbinds[1].len_oid = sizeof(operESSID);
637     varbinds[2].oid = operRTSThreshold;
638     varbinds[2].len_oid = sizeof(operRTSThreshold);
639     varbinds[3].oid = operFragmentationThreshold;
640     varbinds[3].len_oid = sizeof(operFragmentationThreshold);
641     varbinds[4].oid = operBasicRates;
642     varbinds[4].len_oid = sizeof(operBasicRates);
643     varbinds[5].oid = OpenSystem;
644     varbinds[5].len_oid = sizeof(OpenSystem);
645     varbinds[6].oid = SharedKey;
646     varbinds[6].len_oid = sizeof(SharedKey);
647     varbinds[7].oid = operAccessPointName;
648     varbinds[7].len_oid = sizeof(operAccessPointName);
649     print_help(WAIT_RET);
650     if (snmp(varbinds, 8, GET) <= 0) {
651         print_helperr(ERR_RET);
652         goto exit;
653     }
654
655     channel = *(varbinds[0].value);
656     memcpy(domain, varbinds[1].value, varbinds[1].len_val);
657     memcpy(basic_rates, varbinds[4].value, varbinds[4].len_val);
658     memcpy(&RTSThreshold, (varbinds[2].value), 2);
659     RTSThreshold = ntohs(RTSThreshold);
660     memcpy(&FragmentationThreshold, (varbinds[3].value), 2);
661     FragmentationThreshold = ntohs(FragmentationThreshold);
662     authi = (*(varbinds[5].value) == 1 && *(varbinds[6].value) == 1) ? 2 :
663         (*(varbinds[5].value) == 1) ? 0 : 1;
664     memcpy(ap_name, varbinds[7].value, varbinds[7].len_val);
665
666     sprintf(message, "%s%02u (%u MHz)", CHANNEL, channel, 2407 + 5 * channel);
667     mvwaddstr(main_sub, 0, 0, message);
668     mvwaddstr(main_sub, 1, 0, ESSID);
669     for (i = 0; i < 32 && domain[i]; i++)
670         mvwaddch(main_sub, 1, strlen(ESSID) + i, domain[i]);
671     mvwaddstr(main_sub, 2, 0, AP_NAME);
672     for (i = 0; i < 32 && ap_name[i]; i++)
673         mvwaddch(main_sub, 2, strlen(AP_NAME) + i, ap_name[i]);
674     sprintf(message, "%s%d", RTS_TR, RTSThreshold);
675     mvwaddstr(main_sub, 3, 0, message);
676     sprintf(message, "%s%d", FRG_TR, FragmentationThreshold);
677     mvwaddstr(main_sub, 4, 0, message);
678     sprintf(message, "%s%s", AUTH, auth[authi]);
679     mvwaddstr(main_sub, 6, 0, message);
680     mvwaddstr(main_sub, 9, 0, RATES);
681     mvwaddstr(main_sub, 10, 2, RATES_HEAD);
682     for(i = 0; i < 4; i++) {
683         sprintf(message, RATES_RECORD "%s", i + 1, (float) __rates[i] / 2,
684                 basic(basic_rates[i]));
685         mvwaddstr(main_sub, 11+i, 2, message);
686     }
687
688     reg_domain = get_RegDomain();
689     rd_idx = regdom_idx(reg_domain);
690
691     for (i = 0; i < 9; i++) {
692         varbinds[i].len_val = 0;
693         varbinds[i].type = NULL_VALUE;
694     }
695
696     for (i = 0; i < 6; i++) {
697         varbinds[i].oid = oid_dot11SupportedAntenna[i];
698         varbinds[i].len_oid = sizeof(oid_dot11SupportedAntenna[i]);
699     }
700     varbinds[6].oid = sysTrapSwitch;
701     varbinds[6].len_oid = sizeof(sysTrapSwitch);
702     varbinds[7].oid = operAccessPointContact;
703     varbinds[7].len_oid = sizeof(operAccessPointContact);
704     varbinds[8].oid = operAccessPointLocation;
705     varbinds[8].len_oid = sizeof(operAccessPointLocation);
706
707     if (snmp(varbinds, 9, GET) <= 0) {
708         print_helperr(ERR_RET);
709         goto exit;
710     }
711
712     for (i = 0; i < 6; i++) {
713         antenna[i] = *varbinds[i].value;
714     }
715
716     traps = *(varbinds[6].value);
717     memcpy(ap_contact, varbinds[7].value, varbinds[7].len_val);
718     if (varbinds[7].len_val < 32)
719         ap_contact[varbinds[7].len_val] = '\0';
720     memcpy(ap_location, varbinds[8].value, varbinds[8].len_val);
721     if (varbinds[8].len_val < 32)
722         ap_location[varbinds[8].len_val] = '\0';
723
724     sprintf(message, "%s%s", LOCATION, ap_location);
725     mvwaddstr(main_sub, 7, 0, message);
726     sprintf(message, "%s%s", CONTACT, ap_contact);
727     mvwaddstr(main_sub, 8, 0, message);
728     sprintf(message, "%s%s", TRAPS, (traps == 1) ? ON : OFF);
729     mvwaddstr(main_sub, 5, 0, message);
730
731     mvwaddstr(main_sub, 16, 0, _("Antenna Configuration:"));
732     sprintf(message, "%s %s %3s, %s %3s",
733             ANTENNA_RX,
734             ANTENNA_RX_LEFT, (antenna[2] == 1) ? ON : OFF,
735             ANTENNA_RX_RIGHT, (antenna[3] == 1) ? ON : OFF);
736     mvwaddstr(main_sub, 17, 1, message);
737     sprintf(message, "%s %s %3s, %s %3s",
738             ANTENNA_TX,
739             ANTENNA_TX_LEFT, (antenna[0] == 1) ? ON : OFF,
740             ANTENNA_TX_RIGHT, (antenna[1] == 1) ? ON : OFF);
741     mvwaddstr(main_sub, 18, 1, message);
742     sprintf(message, "%s %s %3s, %s %3s",
743             ANTENNA_DV,
744             ANTENNA_DV_LEFT, (antenna[4] == 1) ? ON : OFF,
745             ANTENNA_DV_RIGHT, (antenna[5] == 1) ? ON : OFF);
746     mvwaddstr(main_sub, 19, 1, message);
747
748     print_top(NULL, _("General Options"));
749     print_help(_
750                ("UIOPTY - antenna; SCANLEDFR1234 - options; W - write conf; Q - quit to menu"));
751     wrefresh(main_sub);
752
753
754     noecho();
755     while (1) {
756         c = getch();
757         switch (c) {
758         case 'i':
759         case 'I':
760             i = strlen(ANTENNA_RX) + 1 +
761                 strlen(ANTENNA_RX_LEFT) + 6 +
762                 strlen(ANTENNA_RX_RIGHT) + 2;
763             antenna[3] = on_off(17, i);
764             sprintf(message, "%3s", (antenna[3] == 1) ? ON : OFF);
765             print_menusel(17, i, NULL, message);
766             m_antenna[3] = 1;
767             continue;
768         case 'u':
769         case 'U':
770             i = strlen(ANTENNA_RX) + 1 +
771                 strlen(ANTENNA_RX_LEFT) + 2;
772             antenna[2] = on_off(17, i);
773             sprintf(message, "%3s", (antenna[2] == 1) ? ON : OFF);
774             print_menusel(17, i, NULL, message);
775             m_antenna[2] = 1;
776             continue;
777         case 'p':
778         case 'P':
779             i = strlen(ANTENNA_TX) + 1 +
780                 strlen(ANTENNA_TX_LEFT) + 6 +
781                 strlen(ANTENNA_TX_RIGHT) + 2;
782             antenna[1] = on_off(18, i);
783             sprintf(message, "%3s", (antenna[1] == 1) ? ON : OFF);
784             print_menusel(18, i, NULL, message);
785             m_antenna[1] = 1;
786             continue;
787         case 'o':
788         case 'O':
789             i = strlen(ANTENNA_TX) + 1 +
790                 strlen(ANTENNA_TX_LEFT) + 2;
791             antenna[0] = on_off(18, i);
792             sprintf(message, "%3s", (antenna[0] == 1) ? ON : OFF);
793             print_menusel(18, i, NULL, message);
794             m_antenna[0] = 1;
795             continue;
796         case 'T':
797         case 't':
798             i = strlen(ANTENNA_DV) + 1 +
799                 strlen(ANTENNA_DV_LEFT) + 2;
800             antenna[4] = on_off(19, i);
801             sprintf(message, "%3s", (antenna[4] == 1) ? ON : OFF);
802             print_menusel(19, i, NULL, message);
803             m_antenna[4] = 1;
804             continue;
805         case 'Y':
806         case 'y':
807             i = strlen(ANTENNA_DV) + 1 +
808                 strlen(ANTENNA_DV_LEFT) + 6 +
809                 strlen(ANTENNA_DV_RIGHT) + 2;
810             antenna[5] = on_off(19, i);
811             sprintf(message, "%3s", (antenna[5] == 1) ? ON : OFF);
812             print_menusel(19, i, NULL, message);
813             m_antenna[5] = 1;
814             continue;
815         case 'S':
816         case 's':
817             traps = on_off(5, strlen(TRAPS));
818             clear_main_new(5, 6);
819             print_menusel(5, 0, TRAPS, (traps == 1) ? ON : OFF);
820             m_traps = 1;
821             continue;
822         case 'Q':
823         case 'q':
824             goto quit;
825         case '1':
826         case '2':
827         case '3':
828         case '4':
829                 i = c - '0';
830             switch (menu_choose(10 + i, 15, rates, 3)) {
831                 case 0:
832                     basic_rates[i-1] = __rates[i-1];
833                     break;
834                 case 1:
835                     basic_rates[i-1] = 0;
836                     break;
837                 case 2:
838                     basic_rates[i-1] = __rates[i-1] + 0x80;
839                 }
840             clear_main_new(10 + i, 11 + i);
841             sprintf(message, RATES_RECORD, i, (float) __rates[i-1] / 2);
842             print_menusel(10 + i, 2, message, basic(basic_rates[i-1]));
843             m_basic_rates = 1;
844             break;
845         case 'C':
846         case 'c':
847             channel = menu_choose(0, strlen(CHANNEL),
848 #ifndef NO_REG_DOMAIN
849                 channels + regdom_types[rd_idx].first_ch - 1,
850                 regdom_types[rd_idx].chans) + regdom_types[rd_idx].first_ch;
851 #else
852                 channels, 14) + 1;
853 #endif
854             sprintf(message, "%02u (%u MHz)", channel, 2407 + 5 * channel);
855             print_menusel(0, 0, CHANNEL, message);
856             m_channel = 1;
857             continue;
858         case 'A':
859         case 'a':
860             authi = menu_choose(6, strlen(AUTH), auth, 3);
861             clear_main_new(6, 7);
862             print_menusel(6, 0, AUTH, auth[authi]);
863             m_auth = 1;
864             continue;
865         case 'N':
866         case 'n':
867             get_value(ap_name, 2, strlen(AP_NAME), 32, ANY_STRING, 0, 0, NULL);
868             m_ap_name = 1;
869             continue;
870         case 'L':
871         case 'l':
872             get_value(ap_location, 7, strlen(LOCATION), 32, ANY_STRING, 0, 0,
873                 NULL);
874             m_ap_location = 1;
875             continue;
876         case 'K':
877         case 'k':
878             get_value(ap_contact, 8, strlen(CONTACT), 32, ANY_STRING, 0, 0,
879                 NULL);
880             m_ap_contact = 1;
881             continue;
882         case 'E':
883         case 'e':
884             get_value(domain, 1, strlen(ESSID), 32, ANY_STRING, 0, 0, NULL);
885             m_essid = 1;
886             continue;
887         case 'F':
888         case 'f':
889             get_value(message, 4, strlen(FRG_TR), 6, INT_STRING, 256, 2346,
890                 WLAN_HELP);
891             FragmentationThreshold = atoi(message);
892             m_fragment = 1;
893             continue;
894         case 'R':
895         case 'r':
896             get_value(message, 3, strlen(RTS_TR), 6, INT_STRING, 0, 2347,
897                 WLAN_HELP);
898             RTSThreshold = atoi(message);
899             m_rts = 1;
900             continue;
901         case 'w':
902         case 'W':
903             i = 0;
904             if (m_channel) {
905                 channel_pref[0] = channel;
906                 varbinds[i].oid = ChannelPref;
907                 varbinds[i].len_oid = sizeof(ChannelPref);
908                 varbinds[i].value = channel_pref;
909                 varbinds[i].len_val = 2;
910                 varbinds[i].type = STRING_VALUE;
911                 i++;
912                 varbinds[i].oid = operChannelID;
913                 varbinds[i].len_oid = sizeof(operChannelID);
914                 varbinds[i].value = (char *) &channel;
915                 varbinds[i].len_val = 1;
916                 varbinds[i].type = 0x02;
917                 i++;
918             }
919
920             if (m_basic_rates) {
921                 varbinds[i].oid = operBasicRates;
922                 varbinds[i].len_oid = sizeof(operBasicRates);
923                 varbinds[i].value = basic_rates;
924                 varbinds[i].len_val = 4;
925                 varbinds[i].type = STRING_VALUE;
926                 i++;
927             }
928
929                 print_help(WAIT_SET);
930                 if (snmp(varbinds, i, SET) <= 0) {
931                     print_helperr(ERR_SET);
932                     goto exit;
933                 }
934             i = 0;
935
936             if (m_auth) {
937                 m_auth = (authi == 1) ? 2 : 1;
938                 m_basic_rates = (authi == 0) ? 2 : 1;
939                 varbinds[i].oid = OpenSystem;
940                 varbinds[i].len_oid = sizeof(OpenSystem);
941                 varbinds[i].value = (char *) &m_auth;
942                 varbinds[i].len_val = 1;
943                 varbinds[i].type = INT_VALUE;
944                 i++;
945                 varbinds[i].oid = SharedKey;
946                 varbinds[i].len_oid = sizeof(SharedKey);
947                 varbinds[i].value = (char *) &m_basic_rates;
948                 varbinds[i].len_val = 1;
949                 varbinds[i].type = INT_VALUE;
950                 i++;
951             }
952                 print_help(WAIT_SET);
953                 if (snmp(varbinds, i, SET) <= 0) {
954                     print_helperr(ERR_SET);
955                     goto exit;
956                 }
957             i = 0;
958
959             if (m_ap_name) {
960                 c = strlen(ap_name);
961                 varbinds[i].oid = operAccessPointName;
962                 varbinds[i].len_oid = sizeof(operAccessPointName);
963                 varbinds[i].value = ap_name;
964                 varbinds[i].len_val = c;
965                 varbinds[i].type = STRING_VALUE;
966                 i++;
967             }
968
969             if (m_ap_location) {
970                 c = strlen(ap_location);
971                 varbinds[i].oid = operAccessPointLocation;
972                 varbinds[i].len_oid = sizeof(operAccessPointLocation);
973                 varbinds[i].value = ap_location;
974                 varbinds[i].len_val = c;
975                 varbinds[i].type = STRING_VALUE;
976                 i++;
977             }
978
979                 print_help(WAIT_SET);
980                 if (snmp(varbinds, i, SET) <= 0) {
981                     print_helperr(ERR_SET);
982                     goto exit;
983                 }
984
985             i = 0;
986             if (m_ap_contact) {
987                 c = strlen(ap_contact);
988                 varbinds[i].oid = operAccessPointContact;
989                 varbinds[i].len_oid = sizeof(operAccessPointContact);
990                 varbinds[i].value = ap_contact;
991                 varbinds[i].len_val = c;
992                 varbinds[i].type = STRING_VALUE;
993                 i++;
994             }
995             if (m_fragment) {
996                 varbinds[i].oid = operFragmentationThreshold;
997                 varbinds[i].len_oid = sizeof(operFragmentationThreshold);
998                 FragmentationThreshold = htons(FragmentationThreshold);
999                 varbinds[i].value = (char *) &FragmentationThreshold;
1000                 varbinds[i].len_val = 2;
1001                 varbinds[i].type = 0x02;
1002                 i++;
1003             }
1004             if (m_rts) {
1005                 varbinds[i].oid = operRTSThreshold;
1006                 varbinds[i].len_oid = sizeof(operRTSThreshold);
1007                 RTSThreshold = htons(RTSThreshold);
1008                 varbinds[i].value = (char *) &RTSThreshold;
1009                 varbinds[i].len_val = 2;
1010                 varbinds[i].type = 0x02;
1011                 i++;
1012             }
1013             if (m_traps) {
1014                 varbinds[i].oid = sysTrapSwitch;
1015                 varbinds[i].len_oid = sizeof(sysTrapSwitch);
1016                 varbinds[i].value = &traps;
1017                 varbinds[i].len_val = 1;
1018                 varbinds[i].type = 0x02;
1019                 i++;
1020             }
1021                 print_help(WAIT_SET);
1022                 if (snmp(varbinds, i, SET) <= 0) {
1023                     print_helperr(ERR_SET);
1024                     goto exit;
1025                 }
1026             c = 0;
1027             for (i = 0; i < 4; i++)
1028                 if (m_antenna[i]) {
1029                     varbinds[c].oid = oid_dot11SupportedAntenna[i];
1030                     varbinds[c].len_oid =
1031                         sizeof(oid_dot11SupportedAntenna[i]);
1032                     varbinds[c].value = &antenna[i];
1033                     varbinds[c].len_val = 1;
1034                     varbinds[c].type = INT_VALUE;
1035                     c++;
1036                 }
1037                 print_help(WAIT_SET);
1038                 if (snmp(varbinds, c, SET) <= 0) {
1039                     print_helperr(ERR_SET);
1040                     goto exit;
1041                 }
1042             c = 0;
1043             for (i = i; i < 6; i++)
1044                 if (m_antenna[i]) {
1045                     varbinds[c].oid = oid_dot11SupportedAntenna[i];
1046                     varbinds[c].len_oid =
1047                         sizeof(oid_dot11SupportedAntenna[i]);
1048                     varbinds[c].value = &antenna[i];
1049                     varbinds[c].len_val = 1;
1050                     varbinds[c].type = INT_VALUE;
1051                     c++;
1052                 }
1053                 print_help(WAIT_SET);
1054                 if (snmp(varbinds, c, SET) <= 0) {
1055                     print_helperr(ERR_SET);
1056                     goto exit;
1057             }
1058             i = 0;
1059             if (m_essid) {
1060                 c = strlen(domain);
1061                 varbinds[i].oid = operESSID;
1062                 varbinds[i].len_oid = sizeof(operESSID);
1063                 varbinds[i].value = domain;
1064                 varbinds[i].len_val = c;
1065                 varbinds[i].type = 0x04;
1066                 i++;
1067             }
1068                 print_help(WAIT_SET);
1069                 if (snmp(varbinds, i, SET) <= 0) {
1070                     print_helperr(ERR_SET);
1071                     goto exit;
1072                 }
1073
1074             print_help(DONE_SET);
1075             goto exit;
1076         default:
1077             continue;
1078         }
1079     }
1080
1081   exit:
1082     getch();
1083   quit:
1084     print_top(NULL, NULL);
1085
1086     free(domain);
1087     free(ap_name);
1088     clear_main(0);
1089 }