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;
35 extern char* bridge_modes[6];
36 extern int poll_delay;
41 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x01, 0x00
43 char sysDeviceInfo[] = {
44 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x05, 0x00
46 char bridgeOperationalMode[] = {
47 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x01, 0x00
49 /* This one is ATMEL12350 EZYNET MIB specific. */
51 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x09, 0x01, 0x00
54 char *bridge_modes[6] = {
55 _("Wireless Bridge Point to MultiPoint"),
57 _("Access Point client"),
58 _("Wireless Bridge Point to Point"),
67 struct sysDeviceInfo_128 str128;
68 struct sysDeviceInfo_160 str160;
69 extern short ap_type, ap_vendorext;
70 extern int LINES, wait_mode;
71 extern rdprops regdom_types[];
74 * These have to represent used sysDeviceInfo_{128,160} members
78 uint32_t ap_regdomain;
85 if (ap_type == ATMEL12350) {
88 sysDeviceInfo[5] = 0xE0;
89 sysDeviceInfo[6] = 0x3E;
90 bridgeOperationalMode[5] = 0xE0;
91 bridgeOperationalMode[6] = 0x3E;
94 print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, SYSINFO);
96 if (wait_mode == WAIT_TIMEOUT)
102 varbinds[i].oid = sysDescr;
103 varbinds[i].len_oid = sizeof(sysDescr);
104 varbinds[i].value = sysDescr;
105 varbinds[i].type = NULL_VALUE;
106 varbinds[i].len_val = 0;
109 varbinds[i].oid = sysDeviceInfo;
110 varbinds[i].len_oid = sizeof(sysDeviceInfo);
111 varbinds[i].value = sysDeviceInfo;
112 varbinds[i].len_val = 0;
113 varbinds[i].type = NULL_VALUE;
116 varbinds[i].oid = bridgeOperationalMode;
117 varbinds[i].len_oid = sizeof(bridgeOperationalMode);
118 varbinds[i].value = bridgeOperationalMode;
119 varbinds[i].len_val = 0;
120 varbinds[i].type = NULL_VALUE;
123 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
124 varbinds[i].oid = UpTime;
125 varbinds[i].len_oid = sizeof(UpTime);
126 varbinds[i].value = UpTime;
127 varbinds[i].len_val = 0;
128 varbinds[i].type = NULL_VALUE;
132 if (wait_mode == WAIT_FOREVER)
133 print_help(WAIT_RET);
135 if (snmp(varbinds, i, GET) < i) {
136 print_helperr(ERR_RET);
141 if (wait_mode == WAIT_FOREVER)
144 mvwaddstr(main_sub, 0, 0, _("Device hardware/software/name info:"));
145 for (i = 0; i < varbinds[0].len_val && *(varbinds[0].value + i); i++)
146 mvwaddch(main_sub, 1, i + 1, *(varbinds[0].value + i));
148 if (varbinds[1].len_val == 92 || varbinds[1].len_val == 128) {
149 memcpy(&str128, varbinds[1].value,
150 sizeof(struct sysDeviceInfo_128));
151 ap_sversion = str128.StructVersion;
152 ap_macaddr = str128.MacAddress;
153 ap_regdomain = swap4(str128.RegulatoryDomain);
154 ap_prodtype = str128.ProductType;
155 ap_oemname = str128.OEMName;
156 ap_oemid = str128.OEMID;
157 ap_prodname = str128.ProductName;
158 ap_hwrev = str128.HardwareRevision;
159 } else { /* varbinds[1].len_val == 160 */
160 memcpy(&str160, varbinds[1].value,
161 sizeof(struct sysDeviceInfo_160));
162 ap_regdomain = str160.RegulatoryDomain;
163 ap_sversion = str160.StructVersion;
164 ap_macaddr = str160.MacAddress;
165 ap_prodtype = str160.ProductType;
166 ap_oemname = str160.OEMName;
167 ap_oemid = str160.OEMID;
168 ap_prodname = str160.ProductName;
169 ap_hwrev = str160.HardwareRevision;
172 sprintf(message, _("Operational mode: %s"),
173 bridge_modes[*(varbinds[2].value) - 1]);
174 mvwaddstr(main_sub, 2, 0, message);
176 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC,
177 ap_macaddr[0] & 0xFF, ap_macaddr[1] & 0xFF,
178 ap_macaddr[2] & 0xFF, ap_macaddr[3] & 0xFF,
179 ap_macaddr[4] & 0xFF, ap_macaddr[5] & 0xFF);
180 mvwaddstr(main_sub, 3, 0, message);
182 mvwaddstr(main_sub, 4, 0, _("Product name: "));
183 for (i = 0; i < 32 && ap_prodname[i]; i++)
184 waddch(main_sub, ap_prodname[i]);
186 sprintf(message, _("Product type: %u"), swap4(ap_prodtype));
187 mvwaddstr(main_sub, 5, 0, message);
189 mvwaddstr(main_sub, 6, 0, _("OEM name: "));
190 for (i = 0; i < 32 && ap_oemname[i]; i++)
191 waddch(main_sub, ap_oemname[i]);
193 sprintf(message, "OEM ID: %u", swap4(ap_oemid));
194 mvwaddstr(main_sub, 7, 0, message);
196 sprintf(message, _("Hardware revision: %u"), swap4(ap_hwrev));
197 mvwaddstr(main_sub, 8, 0, message);
199 i = regdom_idx(ap_regdomain);
200 sprintf(message, "Regulatory domain: %s [%d]",
201 regdom_types[i].desc, ap_regdomain);
202 mvwaddstr(main_sub, 9, 0, message);
204 sprintf(message, _("Info structure version: %u"), swap4(ap_sversion));
205 mvwaddstr(main_sub, 10, 0, message);
207 sprintf(message, _("Manufacturer OUI: %02X %02X %02X (%s)"),
208 ap_macaddr[0] & 0xFF, ap_macaddr[1] & 0xFF, ap_macaddr[2] & 0xFF,
209 oui2manufacturer(ap_macaddr));
210 mvwaddstr(main_sub, 11, 0, message);
212 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
215 if (varbinds[3].len_val > 1) {
216 for (i = 0; i < varbinds[3].len_val; i++)
217 j |= (varbinds[3].value[i]
218 << (8 * (varbinds[3].len_val - i - 1)));
220 j = varbinds[3].value[0] & 0x80 ?
221 0xff00 | varbinds[3].value[0] : varbinds[3].value[0];
224 _("Uptime: %u days, %02u:%02u:%02u hours:mins:secs"),
225 j / 60 / 60 / 24, j / 60 / 60 % 24, j / 60 % 60, j % 60);
226 mvwaddstr(main_sub, 12, 0, message);
231 i = wait_key(poll_delay);
241 wait_mode = (wait_mode == WAIT_FOREVER ?
242 WAIT_TIMEOUT : WAIT_FOREVER);
243 print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF,
247 /* either timeout for user input (i == 0) or invalid key => continue */
250 print_top(NULL, NULL);
256 char oid_dot11CurrentRegDomain[] =
257 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x01, 0x01, 0x02, 0x01 };
260 varbinds[0].oid = oid_dot11CurrentRegDomain;
261 varbinds[0].len_oid = sizeof(oid_dot11CurrentRegDomain);
262 varbinds[0].value = oid_dot11CurrentRegDomain;
263 varbinds[0].type = NULL_VALUE;
264 varbinds[0].len_val = 0;
266 if (snmp(varbinds, 1, GET) <= 0)
268 return *(varbinds[0].value);
274 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x02, 0x01, 0x01, 0x01, 0x01 };
275 char oid_manufacturerID[] =
276 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x02, 0x01, 0x01, 0x08, 0x01 };
277 char oid_productID[] =
278 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x02, 0x01, 0x01, 0x09, 0x01 };
279 char oid_dot11manufacturerOUI[] =
280 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x01,
283 char oid_dot11manufacturerName[] =
284 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x02,
287 char oid_dot11manufacturerProductName[] =
288 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x03,
291 char oid_dot11manufacturerProductVersion[] =
292 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x04,
295 char oid_dot11PHYType[] =
296 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x01, 0x01, 0x01, 0x01 };
297 char oid_dot11TempType[] =
298 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x01, 0x01, 0x03, 0x01 };
299 char oid_TxPowerLevel1[] =
300 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x03, 0x01, 0x02, 0x01 };
301 char oid_dot11PrivacyOptionImplemented[] =
302 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x01, 0x01, 0x07, 0x01 };
303 char oid_dot11DiversitySupport[] =
304 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x02, 0x01, 0x03, 0x01 };
305 char oid_sysDescr[] =
306 { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x01, 0x00 };
307 char oid_sysUptime[] =
308 { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x03, 0x00 };
310 { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x04, 0x14, 0x01, 0x01 };
312 { _("FHSS 2.4 GHz"), _("DSSS 2.4 GHz"), _("IR Baseband") };
313 char *temp[3] = { _("Commercial range 0..40 C"),
314 _("Industrial range -30..70 C"),
317 _("manual"), _("notsupported"), _("dynamic")};
320 int i, hand, c, min, sec;
322 varbind varbinds[OID_NUM];
324 extern int wait_mode;
326 print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, SYSINFO);
328 if (wait_mode == WAIT_TIMEOUT)
332 for (i = 0; i < OID_NUM; i++) {
333 varbinds[i].value = oid_mac;
334 varbinds[i].type = NULL_VALUE;
335 varbinds[i].len_val = 0;
337 varbinds[0].oid = oid_mac;
338 varbinds[0].len_oid = sizeof(oid_mac);
339 varbinds[1].oid = oid_manufacturerID;
340 varbinds[1].len_oid = sizeof(oid_manufacturerID);
341 varbinds[2].oid = oid_productID;
342 varbinds[2].len_oid = sizeof(oid_productID);
343 varbinds[3].oid = oid_dot11manufacturerOUI;
344 varbinds[3].len_oid = sizeof(oid_dot11manufacturerOUI);
345 varbinds[4].oid = oid_dot11manufacturerName;
346 varbinds[4].len_oid = sizeof(oid_dot11manufacturerName);
347 varbinds[5].oid = oid_dot11manufacturerProductName;
348 varbinds[5].len_oid = sizeof(oid_dot11manufacturerProductName);
349 varbinds[6].oid = oid_dot11manufacturerProductVersion;
350 varbinds[6].len_oid = sizeof(oid_dot11manufacturerProductVersion);
351 varbinds[7].oid = oid_dot11PHYType;
352 varbinds[7].len_oid = sizeof(oid_dot11PHYType);
353 varbinds[8].oid = oid_dot11TempType;
354 varbinds[8].len_oid = sizeof(oid_dot11TempType);
355 varbinds[9].oid = oid_TxPowerLevel1;
356 varbinds[9].len_oid = sizeof(oid_TxPowerLevel1);
358 if (wait_mode == WAIT_FOREVER)
359 print_help(WAIT_RET);
361 if (snmp(varbinds, OID_NUM - 1, GET) < OID_NUM - 1) {
362 print_helperr(ERR_RET);
367 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC,
368 varbinds[0].value[0] & 0xFF, varbinds[0].value[1] & 0xFF,
369 varbinds[0].value[2] & 0xFF, varbinds[0].value[3] & 0xFF,
370 varbinds[0].value[4] & 0xFF, varbinds[0].value[5] & 0xFF);
371 mvwaddstr(main_sub, 0, 0, message);
373 mvwaddstr(main_sub, 3, 0, _("Manufacturer:"));
375 while (varbinds[4].len_val > i)
376 mvwaddch(main_sub, 3, i + 20, *(varbinds[4].value + i++));
378 mvwaddstr(main_sub, 4, 0, _("Manufacturer ID:"));
380 while (varbinds[1].len_val > i)
381 mvwaddch(main_sub, 4, i + 20, *(varbinds[1].value + i++));
383 sprintf(message, _("Manufacturer OUI: %02X %02X %02X (%s)"),
384 varbinds[3].value[0] & 0xFF, varbinds[3].value[1] & 0xFF,
385 varbinds[3].value[2] & 0xFF,
386 oui2manufacturer(varbinds[3].value));
387 mvwaddstr(main_sub, 5, 0, message);
389 sprintf(message, _("Product Name:"));
390 mvwaddstr(main_sub, 6, 0, message);
392 while (varbinds[5].len_val > i)
393 mvwaddch(main_sub, 6, i + 20, *(varbinds[5].value + i++));
395 sprintf(message, _("Product ID:"));
396 mvwaddstr(main_sub, 7, 0, message);
398 while (varbinds[2].len_val > i)
399 mvwaddch(main_sub, 7, i + 20, *(varbinds[2].value + i++));
401 sprintf(message, _("Product Version:"));
402 mvwaddstr(main_sub, 8, 0, message);
404 while (varbinds[6].len_val > i)
405 mvwaddch(main_sub, 8, i + 20, *(varbinds[6].value + i++));
407 sprintf(message, _("PHYType: %s"), types[*(varbinds[7].value) - 1]);
408 mvwaddstr(main_sub, 9, 0, message);
410 sprintf(message, _("Temperature: %s"), temp[*(varbinds[8].value) - 1]);
411 mvwaddstr(main_sub, 10, 0, message);
413 if ((i = get_RegDomain()) == 0) {
414 print_helperr(ERR_RET);
418 sprintf(message, _("Regulatory Domain: %s"),
419 (i == 0x10) ? _("FCC (USA)") :
420 (i == 0x20) ? _("DOC (Canada)") :
421 (i == 0x30) ? _("ETSI (Europe)") :
422 (i == 0x31) ? _("Spain") :
423 (i == 0x32) ? _("France") :
424 (i == 0x40) ? _("MKK (Japan)") : _("unknown"));
425 mvwaddstr(main_sub, 11, 0, message);
427 sprintf(message, _("Transmit Power: %u mW"), *(varbinds[9].value));
428 mvwaddstr(main_sub, 12, 0, message);
430 varbinds[0].oid = oid_dot11PrivacyOptionImplemented;
431 varbinds[0].len_oid = sizeof(oid_dot11PrivacyOptionImplemented);
432 varbinds[0].value = oid_mac;
433 varbinds[0].type = NULL_VALUE;
434 varbinds[0].len_val = 0;
435 varbinds[1].oid = oid_dot11DiversitySupport;
436 varbinds[1].len_oid = sizeof(oid_dot11DiversitySupport);
437 varbinds[1].value = oid_mac;
438 varbinds[1].type = NULL_VALUE;
439 varbinds[1].len_val = 0;
440 varbinds[2].oid = oid_sysDescr;
441 varbinds[2].len_oid = sizeof(oid_sysDescr);
442 varbinds[2].value = oid_mac;
443 varbinds[2].type = NULL_VALUE;
444 varbinds[2].len_val = 0;
445 varbinds[3].oid = oid_sysUptime;
446 varbinds[3].len_oid = sizeof(oid_sysUptime);
447 varbinds[3].value = oid_mac;
448 varbinds[3].type = NULL_VALUE;
449 varbinds[3].len_val = 0;
451 if (snmp(varbinds, 4, GET) < 4) {
452 print_helperr(ERR_RET);
457 sprintf(message, _("WEP implemented: %s"),
458 (*(varbinds[0].value) == 1) ? ON : OFF);
459 mvwaddstr(main_sub, 13, 0, message);
460 sprintf(message, _("Diversity: %s"),
461 diversity[*(varbinds[1].value) - 1]);
462 mvwaddstr(main_sub, 14, 0, message);
463 mvwaddstr(main_sub, LINES - 8, 0, SYS_DESCR);
465 while (varbinds[2].len_val > i && varbinds[2].value[i]) {
466 message[i] = varbinds[2].value[i];
470 mvwaddstr(main_sub, LINES - 8, strlen(SYS_DESCR) + 1, message);
475 for (c = 1; c <= varbinds[3].len_val; c++) {
477 (unsigned char) varbinds[3].value[varbinds[3].len_val - c] * i;
481 hand = time_stamp % 100;
482 time_stamp = time_stamp / 100;
483 sec = time_stamp % 60;
484 time_stamp = time_stamp / 60;
485 min = time_stamp % 60;
486 time_stamp = time_stamp / 60;
488 sprintf(message, _("Uptime: %u:%02u:%02u.%02u"), time_stamp, min, sec,
490 mvwaddstr(main_sub, 15, 0, message);
492 varbinds[0].oid = oid_ip;
493 varbinds[0].len_oid = sizeof(oid_ip);
494 varbinds[0].value = oid_mac;
495 varbinds[0].type = NULL_VALUE;
496 varbinds[0].len_val = 0;
498 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
499 print_helperr(ERR_RET);
504 if (wait_mode == WAIT_FOREVER)
507 memcpy(&ip.s_addr, varbinds[0].value, 4);
508 sprintf(message, _("IP Address: %s"), inet_ntoa(ip));
509 mvwaddstr(main_sub, 1, 0, message);
512 i = wait_key(poll_delay);
522 wait_mode = (wait_mode == WAIT_FOREVER ?
523 WAIT_TIMEOUT : WAIT_FOREVER);
524 print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF,
528 /* either timeout for user input (i == 0) or invalid key => continue */
531 print_top(NULL, NULL);