]> git.decadent.org.uk Git - ap-utils.git/blob - src/nwn_latest.c
56b02f26b99c6df8aa8c4f2ccbfbb59d68b22296
[ap-utils.git] / src / nwn_latest.c
1 /*
2  *      latest.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 <unistd.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <fcntl.h>
25 #include "ap-utils.h"
26 #include "ap-curses.h"
27
28 extern WINDOW *main_sub;
29
30 #define OID_NUM 8
31 #define DESCR _("Reason: %u Station: %02X%02X%02X%02X%02X%02X")
32
33 void latest()
34 {
35     char oid_dot11DisassociateReason[] =
36         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x01, 0x01, 0x0f, 0x01 };
37     char oid_dot11DisassociateStation[] =
38         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x01, 0x01, 0x10, 0x01 };
39     char oid_dot11DeauthenticateReason[] =
40         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x01, 0x01, 0x11, 0x01 };
41     char oid_dot11DeauthenticateStation[] =
42         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x01, 0x01, 0x12, 0x01 };
43     char oid_dot11AuthenticateFailStatus[] =
44         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x01, 0x01, 0x13, 0x01 };
45     char oid_dot11AuthenticateFailStation[] =
46         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x01, 0x01, 0x14, 0x01 };
47     char oid_secLastError[] =
48         { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
49         0x03, 0x00
50     };
51     char oid_secLastErrorAddress[] =
52         { 0x2b, 0x06, 0x01, 0x04, 0x01, 0x87, 0x29, 0x03, 0x01, 0x03, 0x02,
53         0x04, 0x00
54     };
55     char message[1024];
56
57     int i;
58     varbind varbinds[OID_NUM];
59     noecho();
60     print_help(WAIT_RET);
61
62     for (i = 0; i < OID_NUM; i++) {
63         varbinds[i].value = oid_dot11DisassociateReason;
64         varbinds[i].len_val = 0;
65         varbinds[i].type = NULL_VALUE;
66     }
67     varbinds[0].oid = oid_dot11DisassociateReason;
68     varbinds[0].len_oid = sizeof(oid_dot11DisassociateReason);
69     varbinds[1].oid = oid_dot11DisassociateStation;
70     varbinds[1].len_oid = sizeof(oid_dot11DisassociateStation);
71     varbinds[2].oid = oid_dot11DeauthenticateReason;
72     varbinds[2].len_oid = sizeof(oid_dot11DeauthenticateReason);
73     varbinds[3].oid = oid_dot11DeauthenticateStation;
74     varbinds[3].len_oid = sizeof(oid_dot11DeauthenticateStation);
75     varbinds[4].oid = oid_dot11AuthenticateFailStatus;
76     varbinds[4].len_oid = sizeof(oid_dot11AuthenticateFailStatus);
77     varbinds[5].oid = oid_dot11AuthenticateFailStation;
78     varbinds[5].len_oid = sizeof(oid_dot11AuthenticateFailStation);
79     varbinds[6].oid = oid_secLastError;
80     varbinds[6].len_oid = sizeof(oid_secLastError);
81     varbinds[7].oid = oid_secLastErrorAddress;
82     varbinds[7].len_oid = sizeof(oid_secLastErrorAddress);
83
84     if (snmp(varbinds, OID_NUM, GET) <= 0) {
85         print_help(ERR_RET);
86         goto exit;
87     }
88
89     print_title(_("Latest Events"));
90     mvwaddstr(main_sub, 1, 0, _("Disassociate:"));
91     sprintf(message, DESCR,
92             *varbinds[0].value,
93             varbinds[1].value[0] & 0xFF, varbinds[1].value[1] & 0xFF,
94             varbinds[1].value[2] & 0xFF, varbinds[1].value[3] & 0xFF,
95             varbinds[1].value[4] & 0xFF, varbinds[1].value[5] & 0xFF);
96     mvwaddstr(main_sub, 2, 0, message);
97     mvwaddstr(main_sub, 4, 0, _("Deauthenticate:"));
98     sprintf(message, DESCR,
99             *varbinds[2].value,
100             varbinds[3].value[0] & 0xFF, varbinds[3].value[1] & 0xFF,
101             varbinds[3].value[2] & 0xFF, varbinds[3].value[3] & 0xFF,
102             varbinds[3].value[4] & 0xFF, varbinds[3].value[5] & 0xFF);
103     mvwaddstr(main_sub, 5, 0, message);
104     mvwaddstr(main_sub, 7, 0, _("Authenticate Fail:"));
105     sprintf(message, DESCR, *varbinds[4].value,
106             varbinds[5].value[0] & 0xFF, varbinds[5].value[1] & 0xFF,
107             varbinds[5].value[2] & 0xFF, varbinds[5].value[3] & 0xFF,
108             varbinds[5].value[4] & 0xFF, varbinds[5].value[5] & 0xFF);
109     mvwaddstr(main_sub, 8, 0, message);
110     mvwaddstr(main_sub, 10, 0, _("Last error:"));
111     mvwaddstr(main_sub, 11, 0, _("Error:"));
112     i = 0;
113     while (varbinds[6].len_val > i && *(varbinds[6].value + i))
114         mvwaddch(main_sub, 11, i + 15, *(varbinds[6].value + i++));
115
116     sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC,
117             varbinds[7].value[0] & 0xFF, varbinds[7].value[1] & 0xFF,
118             varbinds[7].value[2] & 0xFF, varbinds[7].value[3] & 0xFF,
119             varbinds[7].value[4] & 0xFF, varbinds[7].value[5] & 0xFF);
120     mvwaddstr(main_sub, 12, 0, message);
121
122     wrefresh(main_sub);
123
124     print_help(ANY_KEY);
125   exit:
126     getch();
127     print_title("");
128     clear_main(0);
129 }