2 * sysinfo.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 <sys/types.h>
29 #define SYS_DESCR _("System Description: ")
30 #define SYSINFO _("System Info")
34 extern WINDOW *main_sub;
39 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x01, 0x00
41 char sysDeviceInfo[] = {
42 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x05, 0x00
44 /* This one is ATMEL12350 VERNET MIB specific. */
46 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x09, 0x01, 0x00
52 struct sysDeviceInfo_ATMEL410 str410;
53 struct sysDeviceInfo_ATMEL12350 str12350;
54 extern short ap_type, ap_vendorext;
55 extern int LINES, wait_mode;
56 extern rdprops regdom_types[];
59 * These have to represent used sysDeviceInfo_{ATMEL410,ATMEL12350} members
63 uint32_t ap_regdomain;
70 if (ap_type == ATMEL12350) {
73 sysDeviceInfo[5] = 0xE0;
74 sysDeviceInfo[6] = 0x3E;
77 print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, SYSINFO);
79 if (wait_mode == WAIT_TIMEOUT)
85 varbinds[0].oid = sysDescr;
86 varbinds[0].len_oid = sizeof(sysDescr);
87 varbinds[0].value = sysDescr;
88 varbinds[0].type = NULL_VALUE;
89 varbinds[0].len_val = 0;
92 varbinds[1].oid = sysDeviceInfo;
93 varbinds[1].len_oid = sizeof(sysDeviceInfo);
94 varbinds[1].value = sysDeviceInfo;
95 varbinds[1].len_val = 0;
96 varbinds[1].type = NULL_VALUE;
99 if (ap_vendorext == VERNET) {
100 varbinds[2].oid = UpTime;
101 varbinds[2].len_oid = sizeof(UpTime);
102 varbinds[2].value = UpTime;
103 varbinds[2].len_val = 0;
104 varbinds[2].type = NULL_VALUE;
108 if (wait_mode == WAIT_FOREVER)
109 print_help(WAIT_RET);
111 if (snmp(varbinds, i, GET) <= 0) {
112 print_helperr(ERR_RET);
117 if (wait_mode == WAIT_FOREVER)
120 mvwaddstr(main_sub, 0, 0, _("Device hardware/software/name info:"));
121 for (i = 0; i < varbinds[0].len_val && *(varbinds[0].value + i); i++)
122 mvwaddch(main_sub, 1, i + 1, *(varbinds[0].value + i));
124 if (ap_type == ATMEL410) {
125 memcpy(&str410, varbinds[1].value,
126 sizeof(struct sysDeviceInfo_ATMEL410));
127 ap_sversion = str410.StructVersion;
128 ap_macaddr = str410.MacAddress;
129 ap_regdomain = swap4(str410.RegulatoryDomain);
130 ap_prodtype = str410.ProductType;
131 ap_oemname = str410.OEMName;
132 ap_oemid = str410.OEMID;
133 ap_prodname = str410.ProductName;
134 ap_hwrev = str410.HardwareRevision;
135 } else { /* ATMEL12350 */
136 memcpy(&str12350, varbinds[1].value,
137 sizeof(struct sysDeviceInfo_ATMEL12350));
138 ap_regdomain = str12350.RegulatoryDomain;
139 ap_sversion = str12350.StructVersion;
140 ap_macaddr = str12350.MacAddress;
141 ap_prodtype = str12350.ProductType;
142 ap_oemname = str12350.OEMName;
143 ap_oemid = str12350.OEMID;
144 ap_prodname = str12350.ProductName;
145 ap_hwrev = str12350.HardwareRevision;
148 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC,
149 ap_macaddr[0] & 0xFF, ap_macaddr[1] & 0xFF,
150 ap_macaddr[2] & 0xFF, ap_macaddr[3] & 0xFF,
151 ap_macaddr[4] & 0xFF, ap_macaddr[5] & 0xFF);
152 mvwaddstr(main_sub, 2, 0, message);
154 mvwaddstr(main_sub, 3, 0, _("Product name:"));
155 for (i = 0; i < 32 && ap_prodname[i]; i++)
156 mvwaddch(main_sub, 3, i + 14, ap_prodname[i]);
158 sprintf(message, _("Product type: %u"), swap4(ap_prodtype));
159 mvwaddstr(main_sub, 4, 0, message);
161 mvwaddstr(main_sub, 5, 0, _("OEM name:"));
162 for (i = 0; i < 32 && ap_oemname[i]; i++)
163 mvwaddch(main_sub, 5, i + 10, ap_oemname[i]);
165 sprintf(message, "OEM ID: %u", swap4(ap_oemid));
166 mvwaddstr(main_sub, 6, 0, message);
168 sprintf(message, _("Hardware revision: %u"), swap4(ap_hwrev));
169 mvwaddstr(main_sub, 7, 0, message);
171 i = regdom_idx(ap_regdomain);
172 sprintf(message, "Regulatory domain: %s [%d]",
173 regdom_types[i].desc, ap_regdomain);
174 mvwaddstr(main_sub, 8, 0, message);
176 sprintf(message, _("Info structure version: %u"), swap4(ap_sversion));
177 mvwaddstr(main_sub, 9, 0, message);
179 sprintf(message, _("Manufacturer OUI: %02X %02X %02X (%s)"),
180 ap_macaddr[0] & 0xFF, ap_macaddr[1] & 0xFF, ap_macaddr[2] & 0xFF,
181 oui2manufacturer(ap_macaddr));
182 mvwaddstr(main_sub, 10, 0, message);
184 if (ap_vendorext == VERNET) {
187 if (varbinds[2].len_val > 1) {
188 for (i = 0; i < varbinds[2].len_val; i++)
189 j |= (varbinds[2].value[i]
190 << (8 * (varbinds[2].len_val - i - 1)));
192 j = varbinds[2].value[0] & 0x80 ?
193 0xff00 | varbinds[2].value[0] : varbinds[2].value[0];
196 _("Uptime: %u days, %02u:%02u:%02u hours:mins:secs"),
197 j / 60 / 60 / 24, j / 60 / 60 % 24, j / 60 % 60, j % 60);
198 mvwaddstr(main_sub, 11, 0, message);
213 wait_mode = (wait_mode == WAIT_FOREVER ?
214 WAIT_TIMEOUT : WAIT_FOREVER);
215 print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF,
219 /* either timeout for user input (i == 0) or invalid key => continue */
222 print_top(NULL, NULL);
228 char oid_dot11CurrentRegDomain[] =
229 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x01, 0x01, 0x02, 0x01 };
232 varbinds[0].oid = oid_dot11CurrentRegDomain;
233 varbinds[0].len_oid = sizeof(oid_dot11CurrentRegDomain);
234 varbinds[0].value = oid_dot11CurrentRegDomain;
235 varbinds[0].type = NULL_VALUE;
236 varbinds[0].len_val = 0;
238 if (snmp(varbinds, 1, GET) <= 0)
240 return *(varbinds[0].value);
246 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x02, 0x01, 0x01, 0x01, 0x01 };
247 char oid_manufacturerID[] =
248 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x02, 0x01, 0x01, 0x08, 0x01 };
249 char oid_productID[] =
250 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x02, 0x01, 0x01, 0x09, 0x01 };
251 char oid_dot11manufacturerOUI[] =
252 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x01,
255 char oid_dot11manufacturerName[] =
256 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x02,
259 char oid_dot11manufacturerProductName[] =
260 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x03,
263 char oid_dot11manufacturerProductVersion[] =
264 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x04,
267 char oid_dot11PHYType[] =
268 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x01, 0x01, 0x01, 0x01 };
269 char oid_dot11TempType[] =
270 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x01, 0x01, 0x03, 0x01 };
271 char oid_TxPowerLevel1[] =
272 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x03, 0x01, 0x02, 0x01 };
273 char oid_dot11PrivacyOptionImplemented[] =
274 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x01, 0x01, 0x07, 0x01 };
275 char oid_dot11DiversitySupport[] =
276 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x02, 0x01, 0x03, 0x01 };
277 char oid_sysDescr[] =
278 { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x01, 0x00 };
279 char oid_sysUptime[] =
280 { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x03, 0x00 };
282 { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x04, 0x14, 0x01, 0x01 };
284 { _("FHSS 2.4 GHz"), _("DSSS 2.4 GHz"), _("IR Baseband") };
285 char *temp[3] = { _("Commercial range 0..40 C"),
286 _("Industrial range -30..70 C"),
289 _("manual"), _("notsupported"), _("dynamic")};
292 int i, hand, c, min, sec;
294 varbind varbinds[OID_NUM];
296 extern int wait_mode;
298 print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, SYSINFO);
300 if (wait_mode == WAIT_TIMEOUT)
304 for (i = 0; i < OID_NUM; i++) {
305 varbinds[i].value = oid_mac;
306 varbinds[i].type = NULL_VALUE;
307 varbinds[i].len_val = 0;
309 varbinds[0].oid = oid_mac;
310 varbinds[0].len_oid = sizeof(oid_mac);
311 varbinds[1].oid = oid_manufacturerID;
312 varbinds[1].len_oid = sizeof(oid_manufacturerID);
313 varbinds[2].oid = oid_productID;
314 varbinds[2].len_oid = sizeof(oid_productID);
315 varbinds[3].oid = oid_dot11manufacturerOUI;
316 varbinds[3].len_oid = sizeof(oid_dot11manufacturerOUI);
317 varbinds[4].oid = oid_dot11manufacturerName;
318 varbinds[4].len_oid = sizeof(oid_dot11manufacturerName);
319 varbinds[5].oid = oid_dot11manufacturerProductName;
320 varbinds[5].len_oid = sizeof(oid_dot11manufacturerProductName);
321 varbinds[6].oid = oid_dot11manufacturerProductVersion;
322 varbinds[6].len_oid = sizeof(oid_dot11manufacturerProductVersion);
323 varbinds[7].oid = oid_dot11PHYType;
324 varbinds[7].len_oid = sizeof(oid_dot11PHYType);
325 varbinds[8].oid = oid_dot11TempType;
326 varbinds[8].len_oid = sizeof(oid_dot11TempType);
327 varbinds[9].oid = oid_TxPowerLevel1;
328 varbinds[9].len_oid = sizeof(oid_TxPowerLevel1);
330 if (wait_mode == WAIT_FOREVER)
331 print_help(WAIT_RET);
333 if (snmp(varbinds, OID_NUM - 1, GET) <= 0) {
334 print_helperr(ERR_RET);
339 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC,
340 varbinds[0].value[0] & 0xFF, varbinds[0].value[1] & 0xFF,
341 varbinds[0].value[2] & 0xFF, varbinds[0].value[3] & 0xFF,
342 varbinds[0].value[4] & 0xFF, varbinds[0].value[5] & 0xFF);
343 mvwaddstr(main_sub, 0, 0, message);
345 mvwaddstr(main_sub, 3, 0, _("Manufacturer:"));
347 while (varbinds[4].len_val > i)
348 mvwaddch(main_sub, 3, i + 20, *(varbinds[4].value + i++));
350 mvwaddstr(main_sub, 4, 0, _("Manufacturer ID:"));
352 while (varbinds[1].len_val > i)
353 mvwaddch(main_sub, 4, i + 20, *(varbinds[1].value + i++));
355 sprintf(message, _("Manufacturer OUI: %02X %02X %02X (%s)"),
356 varbinds[3].value[0] & 0xFF, varbinds[3].value[1] & 0xFF,
357 varbinds[3].value[2] & 0xFF,
358 oui2manufacturer(varbinds[3].value));
359 mvwaddstr(main_sub, 5, 0, message);
361 sprintf(message, _("Product Name:"));
362 mvwaddstr(main_sub, 6, 0, message);
364 while (varbinds[5].len_val > i)
365 mvwaddch(main_sub, 6, i + 20, *(varbinds[5].value + i++));
367 sprintf(message, _("Product ID:"));
368 mvwaddstr(main_sub, 7, 0, message);
370 while (varbinds[2].len_val > i)
371 mvwaddch(main_sub, 7, i + 20, *(varbinds[2].value + i++));
373 sprintf(message, _("Product Version:"));
374 mvwaddstr(main_sub, 8, 0, message);
376 while (varbinds[6].len_val > i)
377 mvwaddch(main_sub, 8, i + 20, *(varbinds[6].value + i++));
379 sprintf(message, _("PHYType: %s"), types[*(varbinds[7].value) - 1]);
380 mvwaddstr(main_sub, 9, 0, message);
382 sprintf(message, _("Temperature: %s"), temp[*(varbinds[8].value) - 1]);
383 mvwaddstr(main_sub, 10, 0, message);
385 if ((i = get_RegDomain()) == 0) {
386 print_helperr(ERR_RET);
390 sprintf(message, _("Regulatory Domain: %s"),
391 (i == 0x10) ? _("FCC (USA)") :
392 (i == 0x20) ? _("DOC (Canada)") :
393 (i == 0x30) ? _("ETSI (Europe)") :
394 (i == 0x31) ? _("Spain") :
395 (i == 0x32) ? _("France") :
396 (i == 0x40) ? _("MKK (Japan)") : _("unknown"));
397 mvwaddstr(main_sub, 11, 0, message);
399 sprintf(message, _("Transmit Power: %u mW"), *(varbinds[9].value));
400 mvwaddstr(main_sub, 12, 0, message);
402 varbinds[0].oid = oid_dot11PrivacyOptionImplemented;
403 varbinds[0].len_oid = sizeof(oid_dot11PrivacyOptionImplemented);
404 varbinds[0].value = oid_mac;
405 varbinds[0].type = NULL_VALUE;
406 varbinds[0].len_val = 0;
407 varbinds[1].oid = oid_dot11DiversitySupport;
408 varbinds[1].len_oid = sizeof(oid_dot11DiversitySupport);
409 varbinds[1].value = oid_mac;
410 varbinds[1].type = NULL_VALUE;
411 varbinds[1].len_val = 0;
412 varbinds[2].oid = oid_sysDescr;
413 varbinds[2].len_oid = sizeof(oid_sysDescr);
414 varbinds[2].value = oid_mac;
415 varbinds[2].type = NULL_VALUE;
416 varbinds[2].len_val = 0;
417 varbinds[3].oid = oid_sysUptime;
418 varbinds[3].len_oid = sizeof(oid_sysUptime);
419 varbinds[3].value = oid_mac;
420 varbinds[3].type = NULL_VALUE;
421 varbinds[3].len_val = 0;
423 if (snmp(varbinds, 4, GET) <= 0) {
424 print_helperr(ERR_RET);
429 sprintf(message, _("WEP implemented: %s"),
430 (*(varbinds[0].value) == 1) ? ON : OFF);
431 mvwaddstr(main_sub, 13, 0, message);
432 sprintf(message, _("Diversity: %s"),
433 diversity[*(varbinds[1].value) - 1]);
434 mvwaddstr(main_sub, 14, 0, message);
435 mvwaddstr(main_sub, LINES - 8, 0, SYS_DESCR);
437 while (varbinds[2].len_val > i && varbinds[2].value[i]) {
438 message[i] = varbinds[2].value[i];
442 mvwaddstr(main_sub, LINES - 8, strlen(SYS_DESCR) + 1, message);
447 for (c = 1; c <= varbinds[3].len_val; c++) {
449 (unsigned char) varbinds[3].value[varbinds[3].len_val - c] * i;
453 hand = time_stamp % 100;
454 time_stamp = time_stamp / 100;
455 sec = time_stamp % 60;
456 time_stamp = time_stamp / 60;
457 min = time_stamp % 60;
458 time_stamp = time_stamp / 60;
460 sprintf(message, _("Uptime: %u:%02u:%02u.%02u"), time_stamp, min, sec,
462 mvwaddstr(main_sub, 15, 0, message);
464 varbinds[0].oid = oid_ip;
465 varbinds[0].len_oid = sizeof(oid_ip);
466 varbinds[0].value = oid_mac;
467 varbinds[0].type = NULL_VALUE;
468 varbinds[0].len_val = 0;
470 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
471 print_helperr(ERR_RET);
476 if (wait_mode == WAIT_FOREVER)
479 memcpy(&ip.s_addr, varbinds[0].value, 4);
480 sprintf(message, _("IP Address: %s"), inet_ntoa(ip));
481 mvwaddstr(main_sub, 1, 0, message);
494 wait_mode = (wait_mode == WAIT_FOREVER ?
495 WAIT_TIMEOUT : WAIT_FOREVER);
496 print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF,
500 /* either timeout for user input (i == 0) or invalid key => continue */
503 print_top(NULL, NULL);