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];
40 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x01, 0x00
42 char sysDeviceInfo[] = {
43 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x01, 0x05, 0x00
45 char bridgeOperationalMode[] = {
46 0x2B, 0x06, 0x01, 0x04, 0x01, 0x83, 0x1A, 0x01, 0x01, 0x04, 0x01, 0x00
48 /* This one is ATMEL12350 EZYNET MIB specific. */
50 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x09, 0x01, 0x00
53 char *bridge_modes[6] = {
54 _("Wireless Bridge Point to MultiPoint"),
56 _("Access Point client"),
57 _("Wireless Bridge Point to Point"),
66 struct sysDeviceInfo_128 str128;
67 struct sysDeviceInfo_160 str160;
68 extern short ap_type, ap_vendorext;
69 extern int LINES, wait_mode;
70 extern rdprops regdom_types[];
73 * These have to represent used sysDeviceInfo_{128,160} members
77 uint32_t ap_regdomain;
84 if (ap_type == ATMEL12350) {
87 sysDeviceInfo[5] = 0xE0;
88 sysDeviceInfo[6] = 0x3E;
89 bridgeOperationalMode[5] = 0xE0;
90 bridgeOperationalMode[6] = 0x3E;
93 print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, SYSINFO);
95 if (wait_mode == WAIT_TIMEOUT)
101 varbinds[i].oid = sysDescr;
102 varbinds[i].len_oid = sizeof(sysDescr);
103 varbinds[i].value = sysDescr;
104 varbinds[i].type = NULL_VALUE;
105 varbinds[i].len_val = 0;
108 varbinds[i].oid = sysDeviceInfo;
109 varbinds[i].len_oid = sizeof(sysDeviceInfo);
110 varbinds[i].value = sysDeviceInfo;
111 varbinds[i].len_val = 0;
112 varbinds[i].type = NULL_VALUE;
115 varbinds[i].oid = bridgeOperationalMode;
116 varbinds[i].len_oid = sizeof(bridgeOperationalMode);
117 varbinds[i].value = bridgeOperationalMode;
118 varbinds[i].len_val = 0;
119 varbinds[i].type = NULL_VALUE;
122 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
123 varbinds[i].oid = UpTime;
124 varbinds[i].len_oid = sizeof(UpTime);
125 varbinds[i].value = UpTime;
126 varbinds[i].len_val = 0;
127 varbinds[i].type = NULL_VALUE;
131 if (wait_mode == WAIT_FOREVER)
132 print_help(WAIT_RET);
134 if (snmp(varbinds, i, GET) < i) {
135 print_helperr(ERR_RET);
140 if (wait_mode == WAIT_FOREVER)
143 mvwaddstr(main_sub, 0, 0, _("Device hardware/software/name info:"));
144 for (i = 0; i < varbinds[0].len_val && *(varbinds[0].value + i); i++)
145 mvwaddch(main_sub, 1, i + 1, *(varbinds[0].value + i));
147 if (varbinds[1].len_val == 128) {
148 memcpy(&str128, varbinds[1].value,
149 sizeof(struct sysDeviceInfo_128));
150 ap_sversion = str128.StructVersion;
151 ap_macaddr = str128.MacAddress;
152 ap_regdomain = swap4(str128.RegulatoryDomain);
153 ap_prodtype = str128.ProductType;
154 ap_oemname = str128.OEMName;
155 ap_oemid = str128.OEMID;
156 ap_prodname = str128.ProductName;
157 ap_hwrev = str128.HardwareRevision;
158 } else { /* varbinds[1].len_val == 160 */
159 memcpy(&str160, varbinds[1].value,
160 sizeof(struct sysDeviceInfo_160));
161 ap_regdomain = str160.RegulatoryDomain;
162 ap_sversion = str160.StructVersion;
163 ap_macaddr = str160.MacAddress;
164 ap_prodtype = str160.ProductType;
165 ap_oemname = str160.OEMName;
166 ap_oemid = str160.OEMID;
167 ap_prodname = str160.ProductName;
168 ap_hwrev = str160.HardwareRevision;
171 sprintf(message, _("Operational mode: %s"),
172 bridge_modes[*(varbinds[2].value) - 1]);
173 mvwaddstr(main_sub, 2, 0, message);
175 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC,
176 ap_macaddr[0] & 0xFF, ap_macaddr[1] & 0xFF,
177 ap_macaddr[2] & 0xFF, ap_macaddr[3] & 0xFF,
178 ap_macaddr[4] & 0xFF, ap_macaddr[5] & 0xFF);
179 mvwaddstr(main_sub, 3, 0, message);
181 mvwaddstr(main_sub, 4, 0, _("Product name: "));
182 for (i = 0; i < 32 && ap_prodname[i]; i++)
183 waddch(main_sub, ap_prodname[i]);
185 sprintf(message, _("Product type: %u"), swap4(ap_prodtype));
186 mvwaddstr(main_sub, 5, 0, message);
188 mvwaddstr(main_sub, 6, 0, _("OEM name: "));
189 for (i = 0; i < 32 && ap_oemname[i]; i++)
190 waddch(main_sub, ap_oemname[i]);
192 sprintf(message, "OEM ID: %u", swap4(ap_oemid));
193 mvwaddstr(main_sub, 7, 0, message);
195 sprintf(message, _("Hardware revision: %u"), swap4(ap_hwrev));
196 mvwaddstr(main_sub, 8, 0, message);
198 i = regdom_idx(ap_regdomain);
199 sprintf(message, "Regulatory domain: %s [%d]",
200 regdom_types[i].desc, ap_regdomain);
201 mvwaddstr(main_sub, 9, 0, message);
203 sprintf(message, _("Info structure version: %u"), swap4(ap_sversion));
204 mvwaddstr(main_sub, 10, 0, message);
206 sprintf(message, _("Manufacturer OUI: %02X %02X %02X (%s)"),
207 ap_macaddr[0] & 0xFF, ap_macaddr[1] & 0xFF, ap_macaddr[2] & 0xFF,
208 oui2manufacturer(ap_macaddr));
209 mvwaddstr(main_sub, 11, 0, message);
211 if (ap_type == ATMEL12350 && ap_vendorext == EZYNET) {
214 if (varbinds[3].len_val > 1) {
215 for (i = 0; i < varbinds[3].len_val; i++)
216 j |= (varbinds[3].value[i]
217 << (8 * (varbinds[3].len_val - i - 1)));
219 j = varbinds[3].value[0] & 0x80 ?
220 0xff00 | varbinds[3].value[0] : varbinds[3].value[0];
223 _("Uptime: %u days, %02u:%02u:%02u hours:mins:secs"),
224 j / 60 / 60 / 24, j / 60 / 60 % 24, j / 60 % 60, j % 60);
225 mvwaddstr(main_sub, 12, 0, message);
240 wait_mode = (wait_mode == WAIT_FOREVER ?
241 WAIT_TIMEOUT : WAIT_FOREVER);
242 print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF,
246 /* either timeout for user input (i == 0) or invalid key => continue */
249 print_top(NULL, NULL);
255 char oid_dot11CurrentRegDomain[] =
256 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x01, 0x01, 0x02, 0x01 };
259 varbinds[0].oid = oid_dot11CurrentRegDomain;
260 varbinds[0].len_oid = sizeof(oid_dot11CurrentRegDomain);
261 varbinds[0].value = oid_dot11CurrentRegDomain;
262 varbinds[0].type = NULL_VALUE;
263 varbinds[0].len_val = 0;
265 if (snmp(varbinds, 1, GET) <= 0)
267 return *(varbinds[0].value);
273 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x02, 0x01, 0x01, 0x01, 0x01 };
274 char oid_manufacturerID[] =
275 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x02, 0x01, 0x01, 0x08, 0x01 };
276 char oid_productID[] =
277 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x02, 0x01, 0x01, 0x09, 0x01 };
278 char oid_dot11manufacturerOUI[] =
279 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x01,
282 char oid_dot11manufacturerName[] =
283 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x02,
286 char oid_dot11manufacturerProductName[] =
287 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x03,
290 char oid_dot11manufacturerProductVersion[] =
291 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x04,
294 char oid_dot11PHYType[] =
295 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x01, 0x01, 0x01, 0x01 };
296 char oid_dot11TempType[] =
297 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x01, 0x01, 0x03, 0x01 };
298 char oid_TxPowerLevel1[] =
299 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x03, 0x01, 0x02, 0x01 };
300 char oid_dot11PrivacyOptionImplemented[] =
301 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x01, 0x01, 0x01, 0x07, 0x01 };
302 char oid_dot11DiversitySupport[] =
303 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x02, 0x01, 0x03, 0x01 };
304 char oid_sysDescr[] =
305 { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x01, 0x00 };
306 char oid_sysUptime[] =
307 { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x01, 0x03, 0x00 };
309 { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x04, 0x14, 0x01, 0x01 };
311 { _("FHSS 2.4 GHz"), _("DSSS 2.4 GHz"), _("IR Baseband") };
312 char *temp[3] = { _("Commercial range 0..40 C"),
313 _("Industrial range -30..70 C"),
316 _("manual"), _("notsupported"), _("dynamic")};
319 int i, hand, c, min, sec;
321 varbind varbinds[OID_NUM];
323 extern int wait_mode;
325 print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF, SYSINFO);
327 if (wait_mode == WAIT_TIMEOUT)
331 for (i = 0; i < OID_NUM; i++) {
332 varbinds[i].value = oid_mac;
333 varbinds[i].type = NULL_VALUE;
334 varbinds[i].len_val = 0;
336 varbinds[0].oid = oid_mac;
337 varbinds[0].len_oid = sizeof(oid_mac);
338 varbinds[1].oid = oid_manufacturerID;
339 varbinds[1].len_oid = sizeof(oid_manufacturerID);
340 varbinds[2].oid = oid_productID;
341 varbinds[2].len_oid = sizeof(oid_productID);
342 varbinds[3].oid = oid_dot11manufacturerOUI;
343 varbinds[3].len_oid = sizeof(oid_dot11manufacturerOUI);
344 varbinds[4].oid = oid_dot11manufacturerName;
345 varbinds[4].len_oid = sizeof(oid_dot11manufacturerName);
346 varbinds[5].oid = oid_dot11manufacturerProductName;
347 varbinds[5].len_oid = sizeof(oid_dot11manufacturerProductName);
348 varbinds[6].oid = oid_dot11manufacturerProductVersion;
349 varbinds[6].len_oid = sizeof(oid_dot11manufacturerProductVersion);
350 varbinds[7].oid = oid_dot11PHYType;
351 varbinds[7].len_oid = sizeof(oid_dot11PHYType);
352 varbinds[8].oid = oid_dot11TempType;
353 varbinds[8].len_oid = sizeof(oid_dot11TempType);
354 varbinds[9].oid = oid_TxPowerLevel1;
355 varbinds[9].len_oid = sizeof(oid_TxPowerLevel1);
357 if (wait_mode == WAIT_FOREVER)
358 print_help(WAIT_RET);
360 if (snmp(varbinds, OID_NUM - 1, GET) < OID_NUM - 1) {
361 print_helperr(ERR_RET);
366 sprintf(message, "%s%02X%02X%02X%02X%02X%02X", MAC,
367 varbinds[0].value[0] & 0xFF, varbinds[0].value[1] & 0xFF,
368 varbinds[0].value[2] & 0xFF, varbinds[0].value[3] & 0xFF,
369 varbinds[0].value[4] & 0xFF, varbinds[0].value[5] & 0xFF);
370 mvwaddstr(main_sub, 0, 0, message);
372 mvwaddstr(main_sub, 3, 0, _("Manufacturer:"));
374 while (varbinds[4].len_val > i)
375 mvwaddch(main_sub, 3, i + 20, *(varbinds[4].value + i++));
377 mvwaddstr(main_sub, 4, 0, _("Manufacturer ID:"));
379 while (varbinds[1].len_val > i)
380 mvwaddch(main_sub, 4, i + 20, *(varbinds[1].value + i++));
382 sprintf(message, _("Manufacturer OUI: %02X %02X %02X (%s)"),
383 varbinds[3].value[0] & 0xFF, varbinds[3].value[1] & 0xFF,
384 varbinds[3].value[2] & 0xFF,
385 oui2manufacturer(varbinds[3].value));
386 mvwaddstr(main_sub, 5, 0, message);
388 sprintf(message, _("Product Name:"));
389 mvwaddstr(main_sub, 6, 0, message);
391 while (varbinds[5].len_val > i)
392 mvwaddch(main_sub, 6, i + 20, *(varbinds[5].value + i++));
394 sprintf(message, _("Product ID:"));
395 mvwaddstr(main_sub, 7, 0, message);
397 while (varbinds[2].len_val > i)
398 mvwaddch(main_sub, 7, i + 20, *(varbinds[2].value + i++));
400 sprintf(message, _("Product Version:"));
401 mvwaddstr(main_sub, 8, 0, message);
403 while (varbinds[6].len_val > i)
404 mvwaddch(main_sub, 8, i + 20, *(varbinds[6].value + i++));
406 sprintf(message, _("PHYType: %s"), types[*(varbinds[7].value) - 1]);
407 mvwaddstr(main_sub, 9, 0, message);
409 sprintf(message, _("Temperature: %s"), temp[*(varbinds[8].value) - 1]);
410 mvwaddstr(main_sub, 10, 0, message);
412 if ((i = get_RegDomain()) == 0) {
413 print_helperr(ERR_RET);
417 sprintf(message, _("Regulatory Domain: %s"),
418 (i == 0x10) ? _("FCC (USA)") :
419 (i == 0x20) ? _("DOC (Canada)") :
420 (i == 0x30) ? _("ETSI (Europe)") :
421 (i == 0x31) ? _("Spain") :
422 (i == 0x32) ? _("France") :
423 (i == 0x40) ? _("MKK (Japan)") : _("unknown"));
424 mvwaddstr(main_sub, 11, 0, message);
426 sprintf(message, _("Transmit Power: %u mW"), *(varbinds[9].value));
427 mvwaddstr(main_sub, 12, 0, message);
429 varbinds[0].oid = oid_dot11PrivacyOptionImplemented;
430 varbinds[0].len_oid = sizeof(oid_dot11PrivacyOptionImplemented);
431 varbinds[0].value = oid_mac;
432 varbinds[0].type = NULL_VALUE;
433 varbinds[0].len_val = 0;
434 varbinds[1].oid = oid_dot11DiversitySupport;
435 varbinds[1].len_oid = sizeof(oid_dot11DiversitySupport);
436 varbinds[1].value = oid_mac;
437 varbinds[1].type = NULL_VALUE;
438 varbinds[1].len_val = 0;
439 varbinds[2].oid = oid_sysDescr;
440 varbinds[2].len_oid = sizeof(oid_sysDescr);
441 varbinds[2].value = oid_mac;
442 varbinds[2].type = NULL_VALUE;
443 varbinds[2].len_val = 0;
444 varbinds[3].oid = oid_sysUptime;
445 varbinds[3].len_oid = sizeof(oid_sysUptime);
446 varbinds[3].value = oid_mac;
447 varbinds[3].type = NULL_VALUE;
448 varbinds[3].len_val = 0;
450 if (snmp(varbinds, 4, GET) < 4) {
451 print_helperr(ERR_RET);
456 sprintf(message, _("WEP implemented: %s"),
457 (*(varbinds[0].value) == 1) ? ON : OFF);
458 mvwaddstr(main_sub, 13, 0, message);
459 sprintf(message, _("Diversity: %s"),
460 diversity[*(varbinds[1].value) - 1]);
461 mvwaddstr(main_sub, 14, 0, message);
462 mvwaddstr(main_sub, LINES - 8, 0, SYS_DESCR);
464 while (varbinds[2].len_val > i && varbinds[2].value[i]) {
465 message[i] = varbinds[2].value[i];
469 mvwaddstr(main_sub, LINES - 8, strlen(SYS_DESCR) + 1, message);
474 for (c = 1; c <= varbinds[3].len_val; c++) {
476 (unsigned char) varbinds[3].value[varbinds[3].len_val - c] * i;
480 hand = time_stamp % 100;
481 time_stamp = time_stamp / 100;
482 sec = time_stamp % 60;
483 time_stamp = time_stamp / 60;
484 min = time_stamp % 60;
485 time_stamp = time_stamp / 60;
487 sprintf(message, _("Uptime: %u:%02u:%02u.%02u"), time_stamp, min, sec,
489 mvwaddstr(main_sub, 15, 0, message);
491 varbinds[0].oid = oid_ip;
492 varbinds[0].len_oid = sizeof(oid_ip);
493 varbinds[0].value = oid_mac;
494 varbinds[0].type = NULL_VALUE;
495 varbinds[0].len_val = 0;
497 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
498 print_helperr(ERR_RET);
503 if (wait_mode == WAIT_FOREVER)
506 memcpy(&ip.s_addr, varbinds[0].value, 4);
507 sprintf(message, _("IP Address: %s"), inet_ntoa(ip));
508 mvwaddstr(main_sub, 1, 0, message);
521 wait_mode = (wait_mode == WAIT_FOREVER ?
522 WAIT_TIMEOUT : WAIT_FOREVER);
523 print_top(wait_mode == WAIT_TIMEOUT ? POLL_ON : POLL_OFF,
527 /* either timeout for user input (i == 0) or invalid key => continue */
530 print_top(NULL, NULL);