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