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
26 #include <sys/types.h>
29 #include "ap-curses.h"
31 #define SYS_DESCR _("System Description: ")
35 extern WINDOW *main_sub;
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 /* This one is ATMEL12350 VERNET MIB specific. */
48 0x2B, 0x06, 0x01, 0x04, 0x01, 0xE0, 0x3E, 0x01, 0x02, 0x09, 0x01, 0x00
54 struct SysDeviceInfo_ATMEL410 ptr410;
55 struct SysDeviceInfo_ATMEL12350 ptr12350;
57 extern char IS_ATMEL12350_VERNET;
60 * These have to represent used SysDeviceInfo_{ATMEL410,ATMEL12350} members
64 uint32_t ap_regdomain;
71 if (ap_type == ATMEL12350) {
74 sysDeviceInfo[5] = 0xE0;
75 sysDeviceInfo[6] = 0x3E;
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;
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;
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;
103 print_help(WAIT_RET);
104 if (snmp(varbinds, i, GET) <= 0) {
105 print_helperr(ERR_RET);
109 print_title(_("System Info"));
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));
116 if (ap_type == ATMEL410) {
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 */
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;
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);
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]);
151 sprintf(message, _("Product type: %u"), swap4(ap_prodtype));
152 mvwaddstr(main_sub, 4, 0, message);
154 sprintf(message, _("Hardware revision: %u"), swap4(ap_hwrev));
155 mvwaddstr(main_sub, 5, 0, message);
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]);
162 sprintf(message, "OEM ID: %u", swap4(ap_oemid));
163 mvwaddstr(main_sub, 7, 0, message);
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);
174 sprintf(message, _("Info structure version: %u"), swap4(ap_sversion));
175 mvwaddstr(main_sub, 9, 0, message);
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);
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);
202 char oid_dot11CurrentRegDomain[] =
203 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x04, 0x01, 0x01, 0x02, 0x01 };
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;
212 if (snmp(varbinds, 1, GET) <= 0)
214 return *(varbinds[0].value);
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,
230 char oid_dot11manufacturerName[] =
231 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x02,
234 char oid_dot11manufacturerProductName[] =
235 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x03,
238 char oid_dot11manufacturerProductVersion[] =
239 { 0x2a, 0x86, 0x48, 0xce, 0x34, 0x03, 0x01, 0x02, 0x01, 0x04,
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 };
257 { 0x2b, 0x06, 0x01, 0x02, 0x01, 0x04, 0x14, 0x01, 0x01 };
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"),
264 _("manual"), _("notsupported"), _("dynamic")};
267 int i, hand, c, min, sec;
269 varbind varbinds[OID_NUM];
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;
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);
298 print_help(WAIT_RET);
299 if (snmp(varbinds, OID_NUM - 1, GET) <= 0) {
300 print_helperr(ERR_RET);
303 print_title(_("System Info"));
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);
313 mvwaddstr(main_sub, 3, 0, _("Manufacturer:"));
315 while (varbinds[4].len_val > i) {
316 mvwaddch(main_sub, 3, i + 20, *(varbinds[4].value + i++));
319 mvwaddstr(main_sub, 4, 0, _("Manufacturer ID:"));
321 while (varbinds[1].len_val > i) {
322 mvwaddch(main_sub, 4, i + 20, *(varbinds[1].value + i++));
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);
331 sprintf(message, _("Product Name:"));
332 mvwaddstr(main_sub, 6, 0, message);
334 while (varbinds[5].len_val > i) {
335 mvwaddch(main_sub, 6, i + 20, *(varbinds[5].value + i++));
338 sprintf(message, _("Product ID:"));
339 mvwaddstr(main_sub, 7, 0, message);
341 while (varbinds[2].len_val > i) {
342 mvwaddch(main_sub, 7, i + 20, *(varbinds[2].value + i++));
344 sprintf(message, _("Product Version:"));
345 mvwaddstr(main_sub, 8, 0, message);
347 while (varbinds[6].len_val > i) {
348 mvwaddch(main_sub, 8, i + 20, *(varbinds[6].value + i++));
352 sprintf(message, _("PHYType: %s"), types[*(varbinds[7].value) - 1]);
353 mvwaddstr(main_sub, 9, 0, message);
355 sprintf(message, _("Temperature: %s"), temp[*(varbinds[8].value) - 1]);
356 mvwaddstr(main_sub, 10, 0, message);
358 if ((i = get_RegDomain()) == 0) {
359 print_helperr(ERR_RET);
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);
371 sprintf(message, _("Transmit Power: %u mW"), *(varbinds[9].value));
372 mvwaddstr(main_sub, 12, 0, message);
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;
395 print_help(WAIT_RET);
396 if (snmp(varbinds, 4, GET) <= 0) {
397 print_helperr(ERR_RET);
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);
409 while (varbinds[2].len_val > i && varbinds[2].value[i]) {
410 message[i] = varbinds[2].value[i];
414 mvwaddstr(main_sub, LINES - 8, strlen(SYS_DESCR) + 1, message);
419 for (c = 1; c <= varbinds[3].len_val; c++) {
421 (unsigned char) varbinds[3].value[varbinds[3].len_val - c] * i;
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;
432 sprintf(message, _("Uptime: %u:%02u:%02u.%02u"), time_stamp, min, sec,
434 mvwaddstr(main_sub, 15, 0, message);
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;
442 print_help(WAIT_RET);
443 if (snmp(varbinds, 1, GET_NEXT) <= 0) {
444 print_helperr(ERR_RET);
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);