2 * auth.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
25 #include "ap-curses.h"
27 #define MAX_LINES LINES-6
28 #define PACKET_ERROR _("AuthorizedMacTableString packet error")
30 #define MAC_AUTH _("[A] MAC authorization: ")
31 #define MAC_ADD _("Enter MAC: ")
32 #define MAC_DEL _("Delete Num: ")
33 #define MAC_TITLE _("Authorized MAC addresses")
34 #define MAC_HEADER _("NUM MAC address")
35 #define MAC_HELP _("A - auth; N - new; D - del; arrows - scroll; W - write conf; Q - quit")
37 extern WINDOW *main_sub;
43 struct AuthorizedMacTableString {
44 unsigned int short Action;
45 unsigned int short NumOfAllTableAddresses;
46 unsigned int short NumOfCurrentAddress;
47 unsigned char MacAddress[6];
48 } *AuthMac = NULL, get;
50 struct MacListStat *pmac, *first = NULL, *curr = NULL;
53 char EnableAuthMAC[] =
54 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01,
55 0x02, 0x06, 0x01, 0x00
57 char AutorizedMac[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01,
58 0x02, 0x06, 0x02, 0x00
61 char message[1024], m_authmac = 0;
62 int i, total_mac, auth_mac = 0, mac_num = 0, begin, end;
65 if (ap_type == ATMEL12350) {
66 EnableAuthMAC[5] = 0xE0;
67 EnableAuthMAC[6] = 0x3E;
68 AutorizedMac[5] = 0xE0;
69 AutorizedMac[6] = 0x3E;
72 varbinds[0].oid = EnableAuthMAC;
73 varbinds[0].len_oid = sizeof(EnableAuthMAC);
74 varbinds[0].type = NULL_VALUE;
75 varbinds[0].len_val = 0;
77 if (snmp(varbinds, 1, GET) <= 0) {
78 print_helperr(ERR_RET);
81 print_title(MAC_TITLE);
83 auth_mac = *(varbinds[0].value);
84 sprintf(message, "%s%s", MAC_AUTH, (auth_mac == 1) ? ON : OFF);
85 mvwaddstr(main_sub, 0, 0, message);
86 mvwaddstr(main_sub, 2, 5, MAC_HEADER);
92 while (mac_num <= total_mac) {
93 get.Action = 0x02; rshort(get.Action);
94 get.NumOfAllTableAddresses = total_mac; rshort(get.NumOfAllTableAddresses);
95 get.NumOfCurrentAddress = mac_num; rshort(get.NumOfCurrentAddress);
97 varbinds[0].oid = AutorizedMac;
98 varbinds[0].len_oid = sizeof(AutorizedMac);
99 varbinds[0].value = (char *) &get;
100 varbinds[0].len_val = 12;
101 varbinds[0].type = STRING_VALUE;
103 if (snmp(varbinds, 1, SET) <= 0) {
104 print_helperr(ERR_RET);
108 if (varbinds[0].len_val == 12) {
112 (struct AuthorizedMacTableString *) malloc(varbinds[0].
114 memcpy(AuthMac, varbinds[0].value, varbinds[0].len_val);
116 (struct AuthorizedMacTableString *) varbinds[0].value;*/
118 print_helperr(PACKET_ERROR);
122 rshort(AuthMac->NumOfAllTableAddresses);
124 (AuthMac->NumOfAllTableAddresses ==
125 65535) ? 0 : AuthMac->NumOfAllTableAddresses;
129 first = (struct MacListStat *)
130 malloc(sizeof(struct MacListStat));
133 curr->next = (struct MacListStat *)
134 malloc(sizeof(struct MacListStat));
137 memcpy(curr->addr, AuthMac->MacAddress, 6);
144 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
145 scroll_rows(first, begin, end, 3, 0);
149 print_help(MAC_HELP);
157 auth_mac = on_off(0, strlen(MAC_AUTH));
158 clear_main_new(0, 1);
159 print_menusel(0, 0, MAC_AUTH, (auth_mac == 1) ? ON : OFF);
164 mvwaddstr(main_sub, 1, 0, MAC_DEL);
165 get_value(message, 1, strlen(MAC_DEL), 5, INT_STRING,
166 1, mac_num - 1, NULL);
177 curr->next = pmac->next;
182 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
183 scroll_rows(first, begin, end, 3, 0);
184 clear_main_new(1, 2);
188 mvwaddstr(main_sub, 1, 0, MAC_ADD);
190 while (curr && curr->next)
193 first = (struct MacListStat *)
194 malloc(sizeof(struct MacListStat));
197 curr->next = (struct MacListStat *)
198 malloc(sizeof(struct MacListStat));
203 /* get_value(message, 1, strlen(MAC_ADD), 13, ANY_STRING, 0, 0,
206 for (i = 0; i < 6; i++) {
207 mess[0] = message[2 * i];
208 mess[1] = message[2 * i + 1];
210 curr->addr[i] = strtol(mess, NULL, 16);
212 clear_main_new(1, 2);
214 get_mac(curr->addr, 1, strlen(MAC_ADD));
216 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
217 scroll_rows(first, begin, end, 3, 0);
218 clear_main_new(1, 2);
223 auth_mac_hw = swap4(auth_mac);
224 varbinds[0].oid = EnableAuthMAC;
225 varbinds[0].len_oid = sizeof(EnableAuthMAC);
226 varbinds[0].type = INT_VALUE;
227 varbinds[0].value = (char *) &auth_mac_hw;
228 varbinds[0].len_val = 1;
229 print_help(WAIT_SET);
230 if (snmp(varbinds, 1, SET) <= 0) {
231 print_helperr(ERR_RET);
237 while (curr != NULL) {
238 get.Action = 0x01; rshort(get.Action);
239 get.NumOfAllTableAddresses = mac_num - 1; rshort(get.NumOfAllTableAddresses);
240 get.NumOfCurrentAddress = i; rshort(get.NumOfCurrentAddress);
241 memcpy(get.MacAddress, curr->addr, 6);
242 varbinds[0].oid = AutorizedMac;
243 varbinds[0].len_oid = sizeof(AutorizedMac);
244 varbinds[0].value = (char *) &get;
245 varbinds[0].len_val = 12;
246 varbinds[0].type = STRING_VALUE;
247 print_help(WAIT_SET);
248 if (snmp(varbinds, 1, SET) <= 0) {
249 print_helperr(ERR_RET);
252 if (varbinds[0].len_val != 12) {
253 print_helperr(PACKET_ERROR);
259 print_help(DONE_SET);
266 scroll_rows(first, begin, end, 3, 0);
274 scroll_rows(first, begin, end, 3, 0);
285 while ((curr = first)) {
297 struct MacListStat *pmac, *first = NULL, *curr = NULL;
299 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
300 0x02, 0x01, 0x02, 0x00
303 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
304 0x02, 0x01, 0x03, 0x00
306 char MacRowStatus[] =
307 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
308 0x02, 0x01, 0x04, 0x00
310 char message[1024], auth_enable[] =
311 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
312 char destroy = 6, create = 4, allow = 1;
313 int i, auth_mac = 0, mac_num = 0, begin, end;
315 print_title(MAC_TITLE);
317 mvwaddstr(main_sub, 2, 5, MAC_HEADER);
319 print_help(WAIT_RET);
322 varbinds[0].oid = Mac;
323 varbinds[0].len_oid = sizeof(Mac);
324 varbinds[0].value = Mac;
325 varbinds[0].len_val = 0;
326 varbinds[0].type = NULL_VALUE;
327 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
328 print_helperr(ERR_RET);
332 while (memcmp(varbinds[0].oid, Mac, sizeof(Mac) - 1) == 0) {
334 Mac[sizeof(Mac) - 1] = varbinds[0].oid[sizeof(Mac) - 1];
335 MacAllow[sizeof(MacAllow) - 1] = varbinds[0].oid[sizeof(Mac) - 1];
336 MacRowStatus[sizeof(MacRowStatus) - 1] =
337 varbinds[0].oid[sizeof(Mac) - 1];
339 varbinds[0].oid = Mac;
340 varbinds[0].len_oid = sizeof(Mac);
341 varbinds[0].value = Mac;
342 varbinds[0].len_val = 0;
343 varbinds[0].type = NULL_VALUE;
344 varbinds[1].oid = MacAllow;
345 varbinds[1].len_oid = sizeof(MacAllow);
346 varbinds[1].value = Mac;
347 varbinds[1].len_val = 0;
348 varbinds[1].type = NULL_VALUE;
349 varbinds[2].oid = MacRowStatus;
350 varbinds[2].len_oid = sizeof(MacRowStatus);
351 varbinds[2].value = Mac;
352 varbinds[2].len_val = 0;
353 varbinds[2].type = NULL_VALUE;
354 if (snmp(varbinds, 3, GET) <= 0) {
355 print_helperr(ERR_RET);
358 if (memcmp(auth_enable, varbinds[0].value, 6)) {
360 first = (struct MacListStat *)
361 malloc(sizeof(struct MacListStat));
364 curr->next = (struct MacListStat *)
365 malloc(sizeof(struct MacListStat));
368 memcpy(curr->addr, varbinds[0].value, 6);
375 varbinds[0].oid = Mac;
376 varbinds[0].len_oid = sizeof(Mac);
377 varbinds[0].value = Mac;
378 varbinds[0].len_val = 0;
379 varbinds[0].type = NULL_VALUE;
380 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
381 print_helperr(ERR_RET);
387 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
389 sprintf(message, "%s%s", MAC_AUTH, (auth_mac) ? OFF : ON);
390 mvwaddstr(main_sub, 0, 0, message);
392 scroll_rows(first, begin, end, 3, 0);
396 print_help(MAC_HELP);
403 auth_mac = on_off(0, strlen(MAC_AUTH)) - 1;
404 clear_main_new(0, 1);
405 print_menusel(0, 0, MAC_AUTH, (auth_mac) ? OFF : ON);
408 mvwaddstr(main_sub, 1, 0, MAC_DEL);
409 get_value(message, 1, strlen(MAC_DEL), 5, INT_STRING,
410 1, mac_num - 1, NULL);
421 curr->next = pmac->next;
426 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
427 scroll_rows(first, begin, end, 3, 0);
428 clear_main_new(1, 2);
432 mvwaddstr(main_sub, 1, 0, MAC_ADD);
434 while (curr && curr->next)
437 first = (struct MacListStat *)
438 malloc(sizeof(struct MacListStat));
441 curr->next = (struct MacListStat *)
442 malloc(sizeof(struct MacListStat));
447 get_mac(curr->addr, 1, strlen(MAC_ADD));
449 for (i = 0; i < 6; i++) {
450 get_value(message, 1, 20 + i * 3, 3, ANY_STRING, 0, 0, NULL);
451 curr->addr[i] = strtol(message, NULL, 16);
453 clear_main_new(1, 2);
456 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
457 scroll_rows(first, begin, end, 3, 0);
461 print_help(WAIT_SET);
463 Mac[sizeof(Mac) - 1] = 0;
465 varbinds[0].oid = Mac;
466 varbinds[0].len_oid = sizeof(Mac);
467 varbinds[0].value = Mac;
468 varbinds[0].len_val = 0;
469 varbinds[0].type = NULL_VALUE;
470 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
471 print_helperr(ERR_RET);
474 while (memcmp(varbinds[0].oid, Mac, sizeof(Mac) - 1) == 0) {
476 MacRowStatus[sizeof(MacRowStatus) - 1] =
477 varbinds[0].oid[sizeof(Mac) - 1];
478 varbinds[0].oid = MacRowStatus;
479 varbinds[0].len_oid = sizeof(MacRowStatus);
480 varbinds[0].value = &destroy;
481 varbinds[0].len_val = 1;
482 varbinds[0].type = INT_VALUE;
483 if (snmp(varbinds, 1, SET) <= 0) {
484 print_helperr(ERR_RET);
487 varbinds[0].oid = Mac;
488 varbinds[0].len_oid = sizeof(Mac);
489 varbinds[0].value = Mac;
490 varbinds[0].len_val = 0;
491 varbinds[0].type = NULL_VALUE;
492 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
493 print_helperr(ERR_RET);
503 Mac[sizeof(Mac) - 1] = i;
504 MacAllow[sizeof(MacAllow) - 1] = i;
505 MacRowStatus[sizeof(MacRowStatus) - 1] = i;
507 varbinds[0].oid = MacRowStatus;
508 varbinds[0].len_oid = sizeof(MacRowStatus);
509 varbinds[0].value = &create;
510 varbinds[0].len_val = 1;
511 varbinds[0].type = INT_VALUE;
512 varbinds[1].oid = Mac;
513 varbinds[1].len_oid = sizeof(Mac);
514 varbinds[1].value = auth_enable;
515 varbinds[1].len_val = 6;
516 varbinds[1].type = STRING_VALUE;
517 varbinds[2].oid = MacAllow;
518 varbinds[2].len_oid = sizeof(MacAllow);
519 varbinds[2].value = &allow;
520 varbinds[2].len_val = 1;
521 varbinds[2].type = INT_VALUE;
522 print_help(WAIT_SET);
523 if (snmp(varbinds, 3, SET) <= 0) {
524 print_helperr(ERR_RET);
533 while (curr != NULL) {
534 Mac[sizeof(Mac) - 1] = i;
535 MacAllow[sizeof(MacAllow) - 1] = i;
536 MacRowStatus[sizeof(MacRowStatus) - 1] = i;
538 varbinds[0].oid = MacRowStatus;
539 varbinds[0].len_oid = sizeof(MacRowStatus);
540 varbinds[0].value = &create;
541 varbinds[0].len_val = 1;
542 varbinds[0].type = INT_VALUE;
543 varbinds[1].oid = Mac;
544 varbinds[1].len_oid = sizeof(Mac);
545 varbinds[1].value = curr->addr;
546 varbinds[1].len_val = 6;
547 varbinds[1].type = STRING_VALUE;
548 varbinds[2].oid = MacAllow;
549 varbinds[2].len_oid = sizeof(MacAllow);
550 varbinds[2].value = &allow;
551 varbinds[2].len_val = 1;
552 varbinds[2].type = INT_VALUE;
553 print_help(WAIT_SET);
554 if (snmp(varbinds, 3, SET) <= 0) {
555 print_helperr(ERR_RET);
561 print_help(DONE_SET);
568 scroll_rows(first, begin, end, 3, 0);
577 scroll_rows(first, begin, end, 3, 0);
588 while ((curr = first)) {