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