2 * wep.c from Access Point SNMP Utils for Linux
4 * Copyright (c) 2002 Roman Festchook <roma at polesye dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License Version 2 from
8 * June 1991 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #define PRIVSETTINGS _("Privacy Settings")
29 #define ENCRYPT _("[E] Standard encryption mechanism: ")
30 #define ALLOW _("[A] Allow unencrypted: ")
31 #define DEFAULT _("[K] Default WEP key: ")
32 #define PUBLIC _("[P] Public key: ")
34 extern WINDOW *main_sub;
39 char defaultWEPKey[4][12] = {
40 {0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x02, 0x01, 0x00},
41 {0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x02, 0x02, 0x00},
42 {0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x02, 0x03, 0x00},
43 {0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x02, 0x04, 0x00}
45 char privacyWEPEnable[] =
46 {0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x02, 0x05, 0x00
48 char privacyDefaultWEPKeyID[] =
49 {0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x02, 0x02, 0x06, 0x00
52 char message[1024], m_wep = 0, m_wepid = 0, wepkey[4][13],
53 m_wepkey[4] = { 0, 0, 0, 0 };
54 char *weps[3] = { "WEP64", OFF, "WEP128" }, *keys[4] = {"1", "2", "3", "4"};
55 int wep, wepid, i, c = 0;
57 unsigned int wepid_hw, wep_hw;
59 if (ap_type == ATMEL12350) {
60 privacyDefaultWEPKeyID[5] = 0xE0;
61 privacyDefaultWEPKeyID[6] = 0x3E;
62 privacyWEPEnable[5] = 0xE0;
63 privacyWEPEnable[6] = 0x3E;
64 for (i = 0; i < 4; i++) {
65 defaultWEPKey[i][5] = 0xE0;
66 defaultWEPKey[i][6] = 0x3E;
70 varbinds[0].oid = privacyWEPEnable;
71 varbinds[0].len_oid = sizeof(privacyWEPEnable);
72 varbinds[0].type = NULL_VALUE;
73 varbinds[0].len_val = 0;
74 varbinds[1].oid = privacyDefaultWEPKeyID;
75 varbinds[1].len_oid = sizeof(privacyDefaultWEPKeyID);
76 varbinds[1].type = NULL_VALUE;
77 varbinds[1].len_val = 0;
79 if (snmp(varbinds, 2, GET) < 2) {
80 print_helperr(ERR_RET);
83 wep = *(varbinds[0].value);
84 wepid = *(varbinds[1].value);
85 print_help(_("EK1234 - set; W - write conf; Q - quit to menu"));
87 print_top(NULL, PRIVSETTINGS);
89 sprintf(message, "%s%s", ENCRYPT, weps[wep - 1]);
90 mvwaddstr(main_sub, 0, 0, message);
91 sprintf(message, "%s%d", DEFAULT, wepid);
92 mvwaddstr(main_sub, 1, 0, message);
94 mvwaddstr(main_sub, 3, 2, _("Key WEP"));
96 for (i = 0; i < 4; i++) {
97 sprintf(message, "[%d] 00.00.00.00.00.00.00.00.00.00.00.00.00",
99 mvwaddstr(main_sub, i + 4, 2, message);
101 mvwaddstr(main_sub, LAST_ROW, 1, _("Hint! Confused by WEP key values? See man ap-config for info..."));
114 wep = menu_choose(0, strlen(ENCRYPT), weps, 3) + 1;
115 clear_main_new(0, 1);
116 print_menusel(0, 0, ENCRYPT, weps[wep - 1]);
121 wepid = menu_choose(1, strlen(DEFAULT), keys, 4) + 1;
122 clear_main_new(1, 2);
123 sprintf(message, "%d", wepid);
124 print_menusel(1, 0, DEFAULT, message);
135 c = strtol(message, NULL, 16);
136 for (i = 0; i < 13; i++)
138 for (i = 0; i < 13; i++) {
139 get_value(message, c + 3, 7 + i * 3, 3, HEX_STRING,
141 wepkey[c - 1][i] = strtol(message, NULL, 16);
150 varbinds[i].oid = privacyWEPEnable;
151 varbinds[i].len_oid = sizeof(privacyWEPEnable);
152 varbinds[i].type = INT_VALUE;
153 varbinds[i].value = (char *) &wep_hw;
154 varbinds[i].len_val = 1;
158 wepid_hw = swap4(wepid);
159 varbinds[i].oid = privacyDefaultWEPKeyID;
160 varbinds[i].len_oid = sizeof(privacyDefaultWEPKeyID);
161 varbinds[i].type = INT_VALUE;
162 varbinds[i].value = (char *) &wepid_hw;
163 varbinds[i].len_val = 1;
166 for (c = 0; c < 4; c++)
168 varbinds[i].oid = defaultWEPKey[c];
169 varbinds[i].len_oid = sizeof(defaultWEPKey[c]);
170 varbinds[i].type = STRING_VALUE;
171 varbinds[i].value = wepkey[c];
172 varbinds[i].len_val = 13;
175 print_help(WAIT_SET);
176 if (snmp(varbinds, i, SET) <= 0) {
177 print_helperr(ERR_SET);
180 print_help(DONE_SET);
189 print_top(NULL, NULL);
197 char defaultWEPKey[4][11] = {
198 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x03, 0x01, 0x02, 0x01, 0x01},
199 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x03, 0x01, 0x02, 0x01, 0x02},
200 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x03, 0x01, 0x02, 0x01, 0x03},
201 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x03, 0x01, 0x02, 0x01, 0x04},
204 char privacyWEPEnable[] =
205 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x05, 0x01, 0x01, 0x01 };
206 char privacyDefaultWEPKeyID[] =
207 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x05, 0x01, 0x02, 0x01 };
209 char oid_dot11ExcludeUnencrypted[] =
210 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x05, 0x01, 0x04, 0x01 };
211 char oid_smtPublicKeyEnable[] =
212 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x02, 0x01,
215 char message[1024], m_wep = 0, m_wepid = 0, wepkey[4][5],
216 m_wepkey[4] = { 0, 0, 0, 0 }, exclude, m_exclude = 0;
217 char *weps[2] = { "WEP64", OFF }, publickey, m_publickey = 0, *keys[4] = {"1", "2", "3", "4"}, wepid=0, wepid_hw;
219 varbind varbinds[15];
221 varbinds[0].oid = privacyWEPEnable;
222 varbinds[0].len_oid = sizeof(privacyWEPEnable);
223 varbinds[0].type = NULL_VALUE;
224 varbinds[0].len_val = 0;
225 varbinds[1].oid = oid_smtPublicKeyEnable;
226 varbinds[1].len_oid = sizeof(oid_smtPublicKeyEnable);
227 varbinds[1].type = NULL_VALUE;
228 varbinds[1].len_val = 0;
229 varbinds[2].oid = oid_dot11ExcludeUnencrypted;
230 varbinds[2].len_oid = sizeof(oid_dot11ExcludeUnencrypted);
231 varbinds[2].type = NULL_VALUE;
232 varbinds[2].len_val = 0;
233 varbinds[3].oid = privacyDefaultWEPKeyID;
234 varbinds[3].len_oid = sizeof(privacyDefaultWEPKeyID);
235 varbinds[3].type = NULL_VALUE;
236 varbinds[3].len_val = 0;
238 print_help(WAIT_RET);
239 if (snmp(varbinds, 4, GET) < 4) {
240 print_helperr(ERR_RET);
243 wep = *(varbinds[0].value);
244 exclude = *(varbinds[2].value);
245 publickey = *(varbinds[1].value);
246 wepid=*(varbinds[3].value);
247 print_help(_("AEPK1234 - set options; W - write conf; Q - quit to menu"));
249 print_top(NULL, PRIVSETTINGS);
251 sprintf(message, "%s%s", ENCRYPT, weps[wep - 1]);
252 mvwaddstr(main_sub, 1, 0, message);
253 sprintf(message, "%s%s", ALLOW, (exclude == 2) ? ON : OFF);
254 mvwaddstr(main_sub, 2, 0, message);
256 sprintf(message, "%s%d", DEFAULT, wepid+1);
257 mvwaddstr(main_sub, 3, 0, message);
260 sprintf(message, "%s%s", PUBLIC, (publickey == 1) ? ON : OFF);
261 mvwaddstr(main_sub, 10, 0, message);
263 mvwaddstr(main_sub, 4, 2, _("Key WEP"));
264 for (i = 0; i < 4; i++) {
265 sprintf(message, "[%d] 00.00.00.00.00", i + 1);
266 mvwaddstr(main_sub, i + 5, 2, message);
274 switch (c = getch()) {
280 wep = menu_choose(1, strlen(ENCRYPT), weps, 2) + 1;
281 clear_main_new(1, 2);
282 print_menusel(1, 0, ENCRYPT, weps[wep - 1]);
287 exclude = on_off(2, strlen(ALLOW));
288 exclude = (exclude == 2) ? 1 : 2;
289 clear_main_new(2, 3);
290 print_menusel(2, 0, ALLOW, (exclude == 2) ? ON : OFF);
295 publickey = on_off(10, strlen(PUBLIC));
296 clear_main_new(10, 11);
297 print_menusel(10, 0, PUBLIC, (publickey == 1) ? ON : OFF);
302 wepid = menu_choose(3, strlen(DEFAULT), keys, 4);
303 clear_main_new(3, 4);
304 sprintf(message, "%d", wepid+1);
305 print_menusel(3, 0, DEFAULT, message);
313 // message[1] = '\0';
314 // c = strtol(message, NULL, 16);
316 /* for (i = 0; i < 5; i++)*/
317 for (i = 0; i < 5; i++) {
318 get_value(message, c + 4, 7 + i * 3, 3, HEX_STRING,
320 wepkey[c - 1][i] = strtol(message, NULL, 16);
326 for (i = 0; i < 5; i++) {
327 get_value(message, 5, 7 + i * 3, 3, HEX_STRING, 0, 0, NULL);
328 wepkey[i] = strtol(message, NULL, 16);
336 varbinds[i].oid = privacyWEPEnable;
337 varbinds[i].len_oid = sizeof(privacyWEPEnable);
338 varbinds[i].type = 0x02;
339 varbinds[i].value = (char *) &wep;
340 varbinds[i].len_val = 1;
345 varbinds[i].oid = privacyDefaultWEPKeyID;
346 varbinds[i].len_oid = sizeof(privacyDefaultWEPKeyID);
347 varbinds[i].type = INT_VALUE;
348 varbinds[i].value = &m_wep;
349 varbinds[i].len_val = 1;
353 varbinds[i].oid = oid_dot11ExcludeUnencrypted;
354 varbinds[i].len_oid = sizeof(oid_dot11ExcludeUnencrypted);
355 varbinds[i].type = 0x02;
356 varbinds[i].value = &exclude;
357 varbinds[i].len_val = 1;
361 varbinds[i].oid = oid_smtPublicKeyEnable;
362 varbinds[i].len_oid = sizeof(oid_smtPublicKeyEnable);
363 varbinds[i].type = 0x02;
364 varbinds[i].value = &publickey;
365 varbinds[i].len_val = 1;
369 varbinds[i].oid = defaultWEPKey;
370 varbinds[i].len_oid = sizeof(defaultWEPKey);
371 varbinds[i].type = STRING_VALUE;
372 varbinds[i].value = wepkey;
373 varbinds[i].len_val = 5;
378 wepid_hw = swap4(wepid);
379 varbinds[i].oid = privacyDefaultWEPKeyID;
380 varbinds[i].len_oid = sizeof(privacyDefaultWEPKeyID);
381 varbinds[i].type = INT_VALUE;
382 varbinds[i].value = (char *) &wepid_hw;
383 varbinds[i].len_val = 1;
388 print_help(WAIT_SET);
389 if (snmp(varbinds, i, SET) <= 0) {
390 print_helperr(ERR_SET);
394 for (c = 0; c < 4; c++)
396 varbinds[i].oid = defaultWEPKey[c];
397 varbinds[i].len_oid = sizeof(defaultWEPKey[c]);
398 varbinds[i].type = STRING_VALUE;
399 varbinds[i].value = wepkey[c];
400 varbinds[i].len_val = 5;
403 if (snmp(varbinds, i, SET) <= 0) {
404 print_helperr(ERR_SET);
408 print_help(DONE_SET);
418 print_top(NULL, NULL);