]> git.decadent.org.uk Git - ap-utils.git/blob - lib/sysinfo.c
4f6b564818370b3e4be9a8e05e264914cd648d09
[ap-utils.git] / lib / sysinfo.c
1 /*
2  *      sysinfo.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
21 #include <unistd.h>
22 #include <stdlib.h>
23 #include <fcntl.h>
24 #include <signal.h>
25 #include <string.h>
26 #include <sys/types.h>
27 #include <sys/wait.h>
28 #include "ap-utils.h"
29 #include "ap-curses.h"
30
31 #define SYS_DESCR _("System Description: ")
32
33 #define OID_NUM 11
34
35 extern WINDOW *main_sub;
36 extern int LINES;
37
38 void atmel_sysinfo()
39 {
40     char sysDescr[] =
41         { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01,
42         0x01, 0x01, 0x00
43     };
44     char sysDeviceInfo[] =
45         { 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01,
46         0x01, 0x05, 0x00
47     };
48
49     char message[200];
50     int i;
51     varbind varbinds[2];
52     extern short ap_type;
53         struct SysDeviceInfo_ATMEL410 ptr410;
54         struct SysDeviceInfo_ATMEL12350 ptr12350;
55
56     /*
57      * These have to represent used SysDeviceInfo_{ATMEL410,ATMEL12350} members
58      */
59     uint32_t ap_sversion;
60     char *ap_macaddr;
61     uint32_t ap_regdomain;
62     uint32_t ap_prodtype;
63     char *ap_oemname;
64     uint32_t ap_oemid;
65     char *ap_prodname;
66     uint32_t ap_hwrev;
67
68     if (ap_type == ATMEL12350) {
69         sysDescr[5] = 0xE0;
70         sysDescr[6] = 0x3E;
71         sysDeviceInfo[5] = 0xE0;
72         sysDeviceInfo[6] = 0x3E;
73     }
74
75     varbinds[0].oid = sysDescr;
76     varbinds[0].len_oid = sizeof(sysDescr);
77     varbinds[0].value = sysDescr;
78     varbinds[0].type = NULL_VALUE;
79     varbinds[0].len_val = 0;
80
81     varbinds[1].oid = sysDeviceInfo;
82     varbinds[1].len_oid = sizeof(sysDeviceInfo);
83     varbinds[1].value = sysDescr;
84     varbinds[1].len_val = 0;
85     varbinds[1].type = NULL_VALUE;
86
87     print_help(WAIT_RET);
88     if (snmp(varbinds, 2, GET) <= 0) {
89         print_helperr(ERR_RET);
90         goto exit;
91     }
92
93     print_title(_("System Info"));
94
95     mvwaddstr(main_sub, 0, 0, _("Device hardware/software/name info:"));
96     for (i = 0; i < varbinds[0].len_val && *(varbinds[0].value + i); i++) {
97         mvwaddch(main_sub, 1, i + 1, *(varbinds[0].value + i));
98     }
99
100     if (ap_type == ATMEL410) {
101         
102         memcpy(&ptr410, varbinds[1].value, sizeof(struct SysDeviceInfo_ATMEL410));
103         ap_sversion = ptr410.StructVersion;
104         ap_macaddr = ptr410.MacAddress;
105         ap_regdomain = swap4(ptr410.RegulationDomain);
106         ap_prodtype = ptr410.ProductType;
107         ap_oemname = ptr410.OEMName;
108         ap_oemid = ptr410.OEMID;
109         ap_prodname = ptr410.ProductName;
110         ap_hwrev = ptr410.HardwareRevision;
111     } else { /* ATMEL12350 */
112         
113         memcpy(&ptr12350, varbinds[1].value, sizeof(struct SysDeviceInfo_ATMEL12350));
114         ap_regdomain=ptr12350.RegulationDomain;
115         ap_sversion = ptr12350.StructVersion;
116         ap_macaddr = ptr12350.MacAddress;
117         ap_prodtype = ptr12350.ProductType;
118         ap_oemname = ptr12350.OEMName;
119         ap_oemid = ptr12350.OEMID;
120         ap_prodname = ptr12350.ProductName;
121         ap_hwrev = ptr12350.HardwareRevision;
122     }
123
124     sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC,
125             ap_macaddr[0] & 0xFF, ap_macaddr[1] & 0xFF,
126             ap_macaddr[2] & 0xFF, ap_macaddr[3] & 0xFF,
127             ap_macaddr[4] & 0xFF, ap_macaddr[5] & 0xFF);
128     mvwaddstr(main_sub, 2, 0, message);
129
130     mvwaddstr(main_sub, 3, 0, _("Product name:"));
131     for (i = 0; i < 32 && ap_prodname[i]; i++) {
132         mvwaddch(main_sub, 3, i + 14, ap_prodname[i]);
133     }
134
135     sprintf(message, _("Product type: %u"), swap4(ap_prodtype));
136     mvwaddstr(main_sub, 4, 0, message);
137
138     sprintf(message, _("Hardware revision: %u"), swap4(ap_hwrev));
139     mvwaddstr(main_sub, 5, 0, message);
140
141     mvwaddstr(main_sub, 6, 0, _("OEM name:"));
142     for (i = 0; i < 32 && ap_oemname[i]; i++) {
143         mvwaddch(main_sub, 6, i + 10, ap_oemname[i]);
144     }
145
146     sprintf(message, "OEM ID: %u", swap4(ap_oemid));
147     mvwaddstr(main_sub, 7, 0, message);
148
149     sprintf(message, _("Regulation domain: %s [%d]"),
150             (ap_regdomain == 0x10) ? _("FCC (USA)") :
151             (ap_regdomain == 0x20) ? _("DOC (Canada)") :
152             (ap_regdomain == 0x30) ? _("ETSI (Europe)") :
153             (ap_regdomain == 0x31) ? _("Spain") :
154             (ap_regdomain == 0x32) ? _("France") :
155             (ap_regdomain == 0x40) ? _("MKK (Japan)") : _("unknown"), ap_regdomain);
156     mvwaddstr(main_sub, 8, 0, message);
157
158     sprintf(message, _("Info structure version: %u"), swap4(ap_sversion));
159     mvwaddstr(main_sub, 9, 0, message);
160
161     sprintf(message, _("Manufacturer OUI: %02X %02X %02X (%s)"),
162         ap_macaddr[0] & 0xFF, ap_macaddr[1] & 0xFF, ap_macaddr[2] & 0xFF,
163         oui2manufacturer(ap_macaddr));
164     mvwaddstr(main_sub, 10, 0, message);
165
166     wrefresh(main_sub);
167     print_help(ANY_KEY);
168   exit:
169     getch();
170     print_title("");
171     clear_main(0);
172 }
173
174 int get_RegDomain()
175 {
176     char oid_dot11CurrentRegDomain[] =
177         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x01, 0x01, 0x02, 0x01 };
178     varbind varbinds[1];
179
180     varbinds[0].oid = oid_dot11CurrentRegDomain;
181     varbinds[0].len_oid = sizeof(oid_dot11CurrentRegDomain);
182     varbinds[0].value = oid_dot11CurrentRegDomain;
183     varbinds[0].type = NULL_VALUE;
184     varbinds[0].len_val = 0;
185
186     if (snmp(varbinds, 1, GET) <= 0)
187         return 0;
188     return *(varbinds[0].value);
189
190 }
191
192 void nwn_sysinfo()
193 {
194     char oid_mac[] =
195         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x02, 0x01, 0x01, 0x01, 0x01 };
196     char oid_manufacturerID[] =
197         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x02, 0x01, 0x01, 0x08, 0x01 };
198     char oid_productID[] =
199         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x02, 0x01, 0x01, 0x09, 0x01 };
200     char oid_dot11manufacturerOUI[] =
201         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x01,
202         0x01
203     };
204     char oid_dot11manufacturerName[] =
205         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x02,
206         0x01
207     };
208     char oid_dot11manufacturerProductName[] =
209         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x03,
210         0x01
211     };
212     char oid_dot11manufacturerProductVersion[] =
213         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x04,
214         0x01
215     };
216     char oid_dot11PHYType[] =
217         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x01, 0x01, 0x01, 0x01 };
218     char oid_dot11TempType[] =
219         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x01, 0x01, 0x03, 0x01 };
220     char oid_TxPowerLevel1[] =
221         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x03, 0x01, 0x02, 0x01 };
222     char oid_dot11PrivacyOptionImplemented[] =
223         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x01, 0x01, 0x07, 0x01 };
224     char oid_dot11DiversitySupport[] =
225         { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x02, 0x01, 0x03, 0x01 };
226     char oid_sysDescr[] =
227         { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x01, 0x00 };
228     char oid_sysUptime[] =
229         { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x03, 0x00 };
230     char oid_ip[] =
231         { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x04, 0x14, 0x01, 0x01 };
232     char *types[3] =
233         { _("FHSS 2.4 GHz"), _("DSSS 2.4 GHz"), _("IR Baseband") };
234     char *temp[3] = { _("Commercial range 0..40 C"),
235         _("Industrial range -30..70 C"),
236         _("unknown")
237     }, *diversity[3] = {
238     _("manual"), _("notsupported"), _("dynamic")};
239
240     char message[300];
241     int i, hand, c, min, sec;
242     struct in_addr ip;
243     varbind varbinds[OID_NUM];
244     size_t time_stamp;
245
246     for (i = 0; i < OID_NUM; i++) {
247         varbinds[i].value = oid_mac;
248         varbinds[i].type = NULL_VALUE;
249         varbinds[i].len_val = 0;
250     }
251     varbinds[0].oid = oid_mac;
252     varbinds[0].len_oid = sizeof(oid_mac);
253     varbinds[1].oid = oid_manufacturerID;
254     varbinds[1].len_oid = sizeof(oid_manufacturerID);
255     varbinds[2].oid = oid_productID;
256     varbinds[2].len_oid = sizeof(oid_productID);
257     varbinds[3].oid = oid_dot11manufacturerOUI;
258     varbinds[3].len_oid = sizeof(oid_dot11manufacturerOUI);
259     varbinds[4].oid = oid_dot11manufacturerName;
260     varbinds[4].len_oid = sizeof(oid_dot11manufacturerName);
261     varbinds[5].oid = oid_dot11manufacturerProductName;
262     varbinds[5].len_oid = sizeof(oid_dot11manufacturerProductName);
263     varbinds[6].oid = oid_dot11manufacturerProductVersion;
264     varbinds[6].len_oid = sizeof(oid_dot11manufacturerProductVersion);
265     varbinds[7].oid = oid_dot11PHYType;
266     varbinds[7].len_oid = sizeof(oid_dot11PHYType);
267     varbinds[8].oid = oid_dot11TempType;
268     varbinds[8].len_oid = sizeof(oid_dot11TempType);
269     varbinds[9].oid = oid_TxPowerLevel1;
270     varbinds[9].len_oid = sizeof(oid_TxPowerLevel1);
271
272     print_help(WAIT_RET);
273     if (snmp(varbinds, OID_NUM - 1, GET) <= 0) {
274         print_helperr(ERR_RET);
275         goto exit;
276     }
277     print_title(_("System Info"));
278
279
280
281     sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC,
282             varbinds[0].value[0] & 0xFF, varbinds[0].value[1] & 0xFF,
283             varbinds[0].value[2] & 0xFF, varbinds[0].value[3] & 0xFF,
284             varbinds[0].value[4] & 0xFF, varbinds[0].value[5] & 0xFF);
285     mvwaddstr(main_sub, 0, 0, message);
286
287     mvwaddstr(main_sub, 3, 0, _("Manufacturer:"));
288     i = 0;
289     while (varbinds[4].len_val > i) {
290         mvwaddch(main_sub, 3, i + 20, *(varbinds[4].value + i++));
291     }
292
293     mvwaddstr(main_sub, 4, 0, _("Manufacturer ID:"));
294     i = 0;
295     while (varbinds[1].len_val > i) {
296         mvwaddch(main_sub, 4, i + 20, *(varbinds[1].value + i++));
297     }
298
299     sprintf(message, _("Manufacturer OUI: %02X %02X %02X (%s)"),
300             varbinds[3].value[0] & 0xFF, varbinds[3].value[1] & 0xFF,
301             varbinds[3].value[2] & 0xFF,
302             oui2manufacturer(varbinds[3].value));
303     mvwaddstr(main_sub, 5, 0, message);
304
305     sprintf(message, _("Product Name:"));
306     mvwaddstr(main_sub, 6, 0, message);
307     i = 0;
308     while (varbinds[5].len_val > i) {
309         mvwaddch(main_sub, 6, i + 20, *(varbinds[5].value + i++));
310     }
311
312     sprintf(message, _("Product ID:"));
313     mvwaddstr(main_sub, 7, 0, message);
314     i = 0;
315     while (varbinds[2].len_val > i) {
316         mvwaddch(main_sub, 7, i + 20, *(varbinds[2].value + i++));
317     }
318     sprintf(message, _("Product Version:"));
319     mvwaddstr(main_sub, 8, 0, message);
320     i = 0;
321     while (varbinds[6].len_val > i) {
322         mvwaddch(main_sub, 8, i + 20, *(varbinds[6].value + i++));
323     }
324
325
326     sprintf(message, _("PHYType: %s"), types[*(varbinds[7].value) - 1]);
327     mvwaddstr(main_sub, 9, 0, message);
328
329     sprintf(message, _("Temperature: %s"), temp[*(varbinds[8].value) - 1]);
330     mvwaddstr(main_sub, 10, 0, message);
331
332     if ((i = get_RegDomain()) == 0) {
333         print_helperr(ERR_RET);
334         goto exit;
335     }
336     sprintf(message, _("Regulation Domain: %s"),
337             (i == 0x10) ? _("FCC (USA)") :
338             (i == 0x20) ? _("DOC (Canada)") :
339             (i == 0x30) ? _("ETSI (Europe)") :
340             (i == 0x31) ? _("Spain") :
341             (i == 0x32) ? _("France") :
342             (i == 0x40) ? _("MKK (Japan)") : _("unknown"));
343     mvwaddstr(main_sub, 11, 0, message);
344
345     sprintf(message, _("Transmit Power: %u mW"), *(varbinds[9].value));
346     mvwaddstr(main_sub, 12, 0, message);
347
348     varbinds[0].oid = oid_dot11PrivacyOptionImplemented;
349     varbinds[0].len_oid = sizeof(oid_dot11PrivacyOptionImplemented);
350     varbinds[0].value = oid_mac;
351     varbinds[0].type = NULL_VALUE;
352     varbinds[0].len_val = 0;
353     varbinds[1].oid = oid_dot11DiversitySupport;
354     varbinds[1].len_oid = sizeof(oid_dot11DiversitySupport);
355     varbinds[1].value = oid_mac;
356     varbinds[1].type = NULL_VALUE;
357     varbinds[1].len_val = 0;
358     varbinds[2].oid = oid_sysDescr;
359     varbinds[2].len_oid = sizeof(oid_sysDescr);
360     varbinds[2].value = oid_mac;
361     varbinds[2].type = NULL_VALUE;
362     varbinds[2].len_val = 0;
363     varbinds[3].oid = oid_sysUptime;
364     varbinds[3].len_oid = sizeof(oid_sysUptime);
365     varbinds[3].value = oid_mac;
366     varbinds[3].type = NULL_VALUE;
367     varbinds[3].len_val = 0;
368
369     print_help(WAIT_RET);
370     if (snmp(varbinds, 4, GET) <= 0) {
371         print_helperr(ERR_RET);
372         goto exit;
373     }
374
375     sprintf(message, _("WEP inplemented: %s"),
376             (*(varbinds[0].value) == 1) ? ON : OFF);
377     mvwaddstr(main_sub, 13, 0, message);
378     sprintf(message, _("Diversity: %s"),
379             diversity[*(varbinds[1].value) - 1]);
380     mvwaddstr(main_sub, 14, 0, message);
381     mvwaddstr(main_sub, LINES - 8, 0, SYS_DESCR);
382     i = 0;
383     while (varbinds[2].len_val > i && varbinds[2].value[i]) {
384         message[i] = varbinds[2].value[i];
385         i++;
386     }
387     message[i] = '\0';
388     mvwaddstr(main_sub, LINES - 8, strlen(SYS_DESCR) + 1, message);
389
390     time_stamp = 0;
391     i = 1;
392
393     for (c = 1; c <= varbinds[3].len_val; c++) {
394         time_stamp +=
395             (unsigned char) varbinds[3].value[varbinds[3].len_val - c] * i;
396         i *= 256;
397     }
398
399     hand = time_stamp % 100;
400     time_stamp = time_stamp / 100;
401     sec = time_stamp % 60;
402     time_stamp = time_stamp / 60;
403     min = time_stamp % 60;
404     time_stamp = time_stamp / 60;
405
406     sprintf(message, _("Uptime: %u:%02u:%02u.%02u"), time_stamp, min, sec,
407             hand);
408     mvwaddstr(main_sub, 15, 0, message);
409
410     varbinds[0].oid = oid_ip;
411     varbinds[0].len_oid = sizeof(oid_ip);
412     varbinds[0].value = oid_mac;
413     varbinds[0].type = NULL_VALUE;
414     varbinds[0].len_val = 0;
415
416     print_help(WAIT_RET);
417     if (snmp(varbinds, 1, GET_NEXT) <= 0) {
418         print_helperr(ERR_RET);
419         goto exit;
420     }
421     memcpy(&ip.s_addr, varbinds[0].value, 4);
422     sprintf(message, _("IP  Address: %s"), inet_ntoa(ip));
423     mvwaddstr(main_sub, 1, 0, message);
424
425     wrefresh(main_sub);
426     print_help(ANY_KEY);
427   exit:
428     getch();
429     print_title("");
430     clear_main(0);
431 }