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
26 #define MAX_LINES LINES-6
27 #define PACKET_ERROR _("AuthorizedMacTableString packet error")
29 #define MAC_AUTH _("[A] MAC authorization: ")
30 #define MAC_ADD _("Enter MAC: ")
31 #define MAC_DEL _("Delete Num: ")
32 #define MAC_TITLE _("Authorized MAC addresses")
33 #define MAC_HEADER _("NUM MAC address")
34 #define MAC_HELP _("A - auth; N - new; D - del; arrows - scroll; W - write conf; Q - quit")
36 extern WINDOW *main_sub;
42 struct AuthorizedMacTableString {
43 unsigned int short Action;
44 unsigned int short NumOfAllTableAddresses;
45 unsigned int short NumOfCurrentAddress;
46 unsigned char MacAddress[6];
47 } *AuthMac = NULL, get;
49 struct MacListStat *pmac, *first = NULL, *curr = NULL;
52 char EnableAuthMAC[] =
53 { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01,
54 0x02, 0x06, 0x01, 0x00
56 char AutorizedMac[] = { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01,
57 0x02, 0x06, 0x02, 0x00
60 char message[1024], m_authmac = 0;
61 int i, total_mac, auth_mac = 0, mac_num = 0, begin, end;
64 if (ap_type == ATMEL12350) {
65 EnableAuthMAC[5] = 0xE0;
66 EnableAuthMAC[6] = 0x3E;
67 AutorizedMac[5] = 0xE0;
68 AutorizedMac[6] = 0x3E;
71 varbinds[0].oid = EnableAuthMAC;
72 varbinds[0].len_oid = sizeof(EnableAuthMAC);
73 varbinds[0].type = NULL_VALUE;
74 varbinds[0].len_val = 0;
76 if (snmp(varbinds, 1, GET) <= 0) {
77 print_helperr(ERR_RET);
80 print_top(NULL, MAC_TITLE);
82 auth_mac = *(varbinds[0].value);
83 sprintf(message, "%s%s", MAC_AUTH, (auth_mac == 1) ? ON : OFF);
84 mvwaddstr(main_sub, 0, 0, message);
85 mvwaddstr(main_sub, 2, 1, MAC_HEADER);
91 while (mac_num <= total_mac) {
92 get.Action = 0x02; rshort(get.Action);
93 get.NumOfAllTableAddresses = total_mac; rshort(get.NumOfAllTableAddresses);
94 get.NumOfCurrentAddress = mac_num; rshort(get.NumOfCurrentAddress);
96 varbinds[0].oid = AutorizedMac;
97 varbinds[0].len_oid = sizeof(AutorizedMac);
98 varbinds[0].value = (char *) &get;
99 varbinds[0].len_val = 12;
100 varbinds[0].type = STRING_VALUE;
102 if (snmp(varbinds, 1, SET) <= 0) {
103 print_helperr(ERR_RET);
107 if (varbinds[0].len_val == 12) {
111 (struct AuthorizedMacTableString *) malloc(varbinds[0].
113 memcpy(AuthMac, varbinds[0].value, varbinds[0].len_val);
115 (struct AuthorizedMacTableString *) varbinds[0].value;*/
117 print_helperr(PACKET_ERROR);
121 rshort(AuthMac->NumOfAllTableAddresses);
123 (AuthMac->NumOfAllTableAddresses ==
124 65535) ? 0 : AuthMac->NumOfAllTableAddresses;
128 first = (struct MacListStat *)
129 malloc(sizeof(struct MacListStat));
132 curr->next = (struct MacListStat *)
133 malloc(sizeof(struct MacListStat));
136 memcpy(curr->addr, AuthMac->MacAddress, 6);
143 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
144 scroll_rows(first, begin, end, 3, 0);
148 print_help(MAC_HELP);
156 auth_mac = on_off(0, strlen(MAC_AUTH));
157 clear_main_new(0, 1);
158 print_menusel(0, 0, MAC_AUTH, (auth_mac == 1) ? ON : OFF);
163 mvwaddstr(main_sub, 1, 0, MAC_DEL);
164 get_value(message, 1, strlen(MAC_DEL), 5, INT_STRING,
165 1, mac_num - 1, NULL);
176 curr->next = pmac->next;
181 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
182 scroll_rows(first, begin, end, 3, 0);
183 clear_main_new(1, 2);
187 mvwaddstr(main_sub, 1, 0, MAC_ADD);
189 while (curr && curr->next)
192 first = (struct MacListStat *)
193 malloc(sizeof(struct MacListStat));
196 curr->next = (struct MacListStat *)
197 malloc(sizeof(struct MacListStat));
202 /* get_value(message, 1, strlen(MAC_ADD), 13, ANY_STRING, 0, 0,
205 for (i = 0; i < 6; i++) {
206 mess[0] = message[2 * i];
207 mess[1] = message[2 * i + 1];
209 curr->addr[i] = strtol(mess, NULL, 16);
211 clear_main_new(1, 2);
213 get_mac(curr->addr, 1, strlen(MAC_ADD));
215 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
216 scroll_rows(first, begin, end, 3, 0);
217 clear_main_new(1, 2);
222 auth_mac_hw = swap4(auth_mac);
223 varbinds[0].oid = EnableAuthMAC;
224 varbinds[0].len_oid = sizeof(EnableAuthMAC);
225 varbinds[0].type = INT_VALUE;
226 varbinds[0].value = (char *) &auth_mac_hw;
227 varbinds[0].len_val = 1;
228 print_help(WAIT_SET);
229 if (snmp(varbinds, 1, SET) <= 0) {
230 print_helperr(ERR_RET);
236 while (curr != NULL) {
237 get.Action = 0x01; rshort(get.Action);
238 get.NumOfAllTableAddresses = mac_num - 1; rshort(get.NumOfAllTableAddresses);
239 get.NumOfCurrentAddress = i; rshort(get.NumOfCurrentAddress);
240 memcpy(get.MacAddress, curr->addr, 6);
241 varbinds[0].oid = AutorizedMac;
242 varbinds[0].len_oid = sizeof(AutorizedMac);
243 varbinds[0].value = (char *) &get;
244 varbinds[0].len_val = 12;
245 varbinds[0].type = STRING_VALUE;
246 print_help(WAIT_SET);
247 if (snmp(varbinds, 1, SET) <= 0) {
248 print_helperr(ERR_RET);
251 if (varbinds[0].len_val != 12) {
252 print_helperr(PACKET_ERROR);
258 print_help(DONE_SET);
265 scroll_rows(first, begin, end, 3, 0);
273 scroll_rows(first, begin, end, 3, 0);
284 while ((curr = first)) {
290 print_top(NULL, NULL);
296 struct MacListStat *pmac, *first = NULL, *curr = NULL;
298 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
299 0x02, 0x01, 0x02, 0x00
302 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
303 0x02, 0x01, 0x03, 0x00
305 char MacRowStatus[] =
306 { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
307 0x02, 0x01, 0x04, 0x00
309 char message[1024], auth_enable[] =
310 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
311 char destroy = 6, create = 4, allow = 1;
312 int i, auth_mac = 0, mac_num = 0, begin, end;
314 print_top(NULL, MAC_TITLE);
316 mvwaddstr(main_sub, 2, 5, MAC_HEADER);
318 print_help(WAIT_RET);
321 varbinds[0].oid = Mac;
322 varbinds[0].len_oid = sizeof(Mac);
323 varbinds[0].value = Mac;
324 varbinds[0].len_val = 0;
325 varbinds[0].type = NULL_VALUE;
326 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
327 print_helperr(ERR_RET);
331 while (memcmp(varbinds[0].oid, Mac, sizeof(Mac) - 1) == 0) {
333 Mac[sizeof(Mac) - 1] = varbinds[0].oid[sizeof(Mac) - 1];
334 MacAllow[sizeof(MacAllow) - 1] = varbinds[0].oid[sizeof(Mac) - 1];
335 MacRowStatus[sizeof(MacRowStatus) - 1] =
336 varbinds[0].oid[sizeof(Mac) - 1];
338 varbinds[0].oid = Mac;
339 varbinds[0].len_oid = sizeof(Mac);
340 varbinds[0].value = Mac;
341 varbinds[0].len_val = 0;
342 varbinds[0].type = NULL_VALUE;
343 varbinds[1].oid = MacAllow;
344 varbinds[1].len_oid = sizeof(MacAllow);
345 varbinds[1].value = Mac;
346 varbinds[1].len_val = 0;
347 varbinds[1].type = NULL_VALUE;
348 varbinds[2].oid = MacRowStatus;
349 varbinds[2].len_oid = sizeof(MacRowStatus);
350 varbinds[2].value = Mac;
351 varbinds[2].len_val = 0;
352 varbinds[2].type = NULL_VALUE;
353 if (snmp(varbinds, 3, GET) <= 0) {
354 print_helperr(ERR_RET);
357 if (memcmp(auth_enable, varbinds[0].value, 6)) {
359 first = (struct MacListStat *)
360 malloc(sizeof(struct MacListStat));
363 curr->next = (struct MacListStat *)
364 malloc(sizeof(struct MacListStat));
367 memcpy(curr->addr, varbinds[0].value, 6);
374 varbinds[0].oid = Mac;
375 varbinds[0].len_oid = sizeof(Mac);
376 varbinds[0].value = Mac;
377 varbinds[0].len_val = 0;
378 varbinds[0].type = NULL_VALUE;
379 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
380 print_helperr(ERR_RET);
386 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
388 sprintf(message, "%s%s", MAC_AUTH, (auth_mac) ? OFF : ON);
389 mvwaddstr(main_sub, 0, 0, message);
391 scroll_rows(first, begin, end, 3, 0);
395 print_help(MAC_HELP);
402 auth_mac = on_off(0, strlen(MAC_AUTH)) - 1;
403 clear_main_new(0, 1);
404 print_menusel(0, 0, MAC_AUTH, (auth_mac) ? OFF : ON);
407 mvwaddstr(main_sub, 1, 0, MAC_DEL);
408 get_value(message, 1, strlen(MAC_DEL), 5, INT_STRING,
409 1, mac_num - 1, NULL);
420 curr->next = pmac->next;
425 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
426 scroll_rows(first, begin, end, 3, 0);
427 clear_main_new(1, 2);
431 mvwaddstr(main_sub, 1, 0, MAC_ADD);
433 while (curr && curr->next)
436 first = (struct MacListStat *)
437 malloc(sizeof(struct MacListStat));
440 curr->next = (struct MacListStat *)
441 malloc(sizeof(struct MacListStat));
446 get_mac(curr->addr, 1, strlen(MAC_ADD));
448 for (i = 0; i < 6; i++) {
449 get_value(message, 1, 20 + i * 3, 3, ANY_STRING, 0, 0, NULL);
450 curr->addr[i] = strtol(message, NULL, 16);
452 clear_main_new(1, 2);
455 end = (MAX_LINES < mac_num) ? MAX_LINES : mac_num;
456 scroll_rows(first, begin, end, 3, 0);
460 print_help(WAIT_SET);
462 Mac[sizeof(Mac) - 1] = 0;
464 varbinds[0].oid = Mac;
465 varbinds[0].len_oid = sizeof(Mac);
466 varbinds[0].value = Mac;
467 varbinds[0].len_val = 0;
468 varbinds[0].type = NULL_VALUE;
469 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
470 print_helperr(ERR_RET);
473 while (memcmp(varbinds[0].oid, Mac, sizeof(Mac) - 1) == 0) {
475 MacRowStatus[sizeof(MacRowStatus) - 1] =
476 varbinds[0].oid[sizeof(Mac) - 1];
477 varbinds[0].oid = MacRowStatus;
478 varbinds[0].len_oid = sizeof(MacRowStatus);
479 varbinds[0].value = &destroy;
480 varbinds[0].len_val = 1;
481 varbinds[0].type = INT_VALUE;
482 if (snmp(varbinds, 1, SET) <= 0) {
483 print_helperr(ERR_RET);
486 varbinds[0].oid = Mac;
487 varbinds[0].len_oid = sizeof(Mac);
488 varbinds[0].value = Mac;
489 varbinds[0].len_val = 0;
490 varbinds[0].type = NULL_VALUE;
491 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
492 print_helperr(ERR_RET);
502 Mac[sizeof(Mac) - 1] = i;
503 MacAllow[sizeof(MacAllow) - 1] = i;
504 MacRowStatus[sizeof(MacRowStatus) - 1] = i;
506 varbinds[0].oid = MacRowStatus;
507 varbinds[0].len_oid = sizeof(MacRowStatus);
508 varbinds[0].value = &create;
509 varbinds[0].len_val = 1;
510 varbinds[0].type = INT_VALUE;
511 varbinds[1].oid = Mac;
512 varbinds[1].len_oid = sizeof(Mac);
513 varbinds[1].value = auth_enable;
514 varbinds[1].len_val = 6;
515 varbinds[1].type = STRING_VALUE;
516 varbinds[2].oid = MacAllow;
517 varbinds[2].len_oid = sizeof(MacAllow);
518 varbinds[2].value = &allow;
519 varbinds[2].len_val = 1;
520 varbinds[2].type = INT_VALUE;
521 print_help(WAIT_SET);
522 if (snmp(varbinds, 3, SET) <= 0) {
523 print_helperr(ERR_RET);
532 while (curr != NULL) {
533 Mac[sizeof(Mac) - 1] = i;
534 MacAllow[sizeof(MacAllow) - 1] = i;
535 MacRowStatus[sizeof(MacRowStatus) - 1] = i;
537 varbinds[0].oid = MacRowStatus;
538 varbinds[0].len_oid = sizeof(MacRowStatus);
539 varbinds[0].value = &create;
540 varbinds[0].len_val = 1;
541 varbinds[0].type = INT_VALUE;
542 varbinds[1].oid = Mac;
543 varbinds[1].len_oid = sizeof(Mac);
544 varbinds[1].value = curr->addr;
545 varbinds[1].len_val = 6;
546 varbinds[1].type = STRING_VALUE;
547 varbinds[2].oid = MacAllow;
548 varbinds[2].len_oid = sizeof(MacAllow);
549 varbinds[2].value = &allow;
550 varbinds[2].len_val = 1;
551 varbinds[2].type = INT_VALUE;
552 print_help(WAIT_SET);
553 if (snmp(varbinds, 3, SET) <= 0) {
554 print_helperr(ERR_RET);
560 print_help(DONE_SET);
567 scroll_rows(first, begin, end, 3, 0);
576 scroll_rows(first, begin, end, 3, 0);
587 while ((curr = first)) {
591 print_top(NULL, NULL);