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