1 /*
2 * Copyright (c) 2004 Dell Computers. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistribution of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistribution in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * Neither the name of Dell Computers, or the names of
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * This software is provided "AS IS," without a warranty of any kind.
20 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
21 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
22 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
23 * DELL COMPUTERS ("DELL") AND ITS LICENSORS SHALL NOT BE LIABLE
24 * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
25 * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
26 * DELL OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
27 * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
28 * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
29 * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
30 * EVEN IF DELL HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31 */
32
33 #include <string.h>
34 #include <math.h>
35 #include <time.h>
36
37 #include <ipmitool/bswap.h>
38 #include <ipmitool/helper.h>
39 #include <ipmitool/log.h>
40 #include <ipmitool/ipmi.h>
41 #include <ipmitool/ipmi_intf.h>
42 #include <ipmitool/ipmi_pef.h>
43
44 extern int verbose;
45 /*
46 // common kywd/value printf() templates
47 */
48 static const char * pef_fld_fmts[][2] = {
49 {"%-*s : %u\n", " | %u"}, /* F_DEC: unsigned value */
50 {"%-*s : %d\n", " | %d"}, /* F_INT: signed value */
51 {"%-*s : %s\n", " | %s"}, /* F_STR: string value */
52 {"%-*s : 0x%x\n", " | 0x%x"}, /* F_HEX: "N hex digits" */
53 {"%-*s : 0x%04x\n", " | 0x%04x"}, /* F_2XD: "2 hex digits" */
54 {"%-*s : 0x%02x\n", " | 0x%02x"}, /* F_1XD: "1 hex digit" */
55 {"%-*s : %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\n",
56 " | %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x"},
57 };
58 typedef enum {
59 F_DEC,
60 F_INT,
61 F_STR,
62 F_HEX,
63 F_2XD,
64 F_1XD,
65 F_UID,
66 } fmt_e;
67 #define KYWD_LENGTH 24
68 static int first_field = 1;
69
70 static const char * pef_flag_fmts[][3] = {
71 {"", "false", "true"},
72 {"supported", "un", ""},
73 {"active", "in", ""},
74 {"abled", "dis", "en"},
75 };
76 static const char * listitem[] = {" | %s", ",%s", "%s"};
77
78 const char *
ipmi_pef_bit_desc(struct bit_desc_map * map,uint32_t value)79 ipmi_pef_bit_desc(struct bit_desc_map * map, uint32_t value)
80 { /*
81 // return description/text label(s) for the given value.
82 // NB: uses a static buffer
83 */
84 static char buf[128];
85 char * p;
86 struct desc_map * pmap;
87 uint32_t match, index;
88
89 *(p = buf) = '\0';
90 index = 2;
91 for (pmap=map->desc_maps; pmap && pmap->desc; pmap++) {
92 if (map->desc_map_type == BIT_DESC_MAP_LIST)
93 match = (value == pmap->mask);
94 else
95 match = ((value & pmap->mask) == pmap->mask);
96
97 if (match) {
98 sprintf(p, listitem[index], pmap->desc);
99 p = strchr(p, '\0');
100 if (map->desc_map_type != BIT_DESC_MAP_ALL)
101 break;
102 index = 1;
103 }
104 }
105 if (p == buf)
106 return("None");
107
108 return((const char *)buf);
109 }
110
111 void
ipmi_pef_print_flags(struct bit_desc_map * map,flg_e type,uint32_t val)112 ipmi_pef_print_flags(struct bit_desc_map * map, flg_e type, uint32_t val)
113 { /*
114 // print features/flags, using val (a bitmask), according to map.
115 // observe the verbose flag, and print any labels, etc. based on type
116 */
117 struct desc_map * pmap;
118 uint32_t maskval, index;
119
120 index = 0;
121 for (pmap=map->desc_maps; pmap && pmap->desc; pmap++) {
122 maskval = (val & pmap->mask);
123 if (verbose)
124 printf("%-*s : %s%s\n", KYWD_LENGTH,
125 ipmi_pef_bit_desc(map, pmap->mask),
126 pef_flag_fmts[type][1 + (maskval != 0)],
127 pef_flag_fmts[type][0]);
128 else if (maskval != 0) {
129 printf(listitem[index], ipmi_pef_bit_desc(map, maskval));
130 index = 1;
131 }
132 }
133 }
134
135 static void
ipmi_pef_print_field(const char * fmt[2],const char * label,unsigned long val)136 ipmi_pef_print_field(const char * fmt[2], const char * label, unsigned long val)
137 { /*
138 // print a 'field' (observes 'verbose' flag)
139 */
140 if (verbose)
141 printf(fmt[0], KYWD_LENGTH, label, val);
142 else if (first_field)
143 printf(&fmt[1][2], val); /* skip field separator */
144 else
145 printf(fmt[1], val);
146
147 first_field = 0;
148 }
149
150 void
ipmi_pef_print_dec(const char * text,uint32_t val)151 ipmi_pef_print_dec(const char * text, uint32_t val)
152 { /* unsigned */
153 ipmi_pef_print_field(pef_fld_fmts[F_DEC], text, val);
154 }
155
156 void
ipmi_pef_print_int(const char * text,uint32_t val)157 ipmi_pef_print_int(const char * text, uint32_t val)
158 { /* signed */
159 ipmi_pef_print_field(pef_fld_fmts[F_INT], text, val);
160 }
161
162 void
ipmi_pef_print_hex(const char * text,uint32_t val)163 ipmi_pef_print_hex(const char * text, uint32_t val)
164 { /* hex */
165 ipmi_pef_print_field(pef_fld_fmts[F_HEX], text, val);
166 }
167
168 void
ipmi_pef_print_str(const char * text,const char * val)169 ipmi_pef_print_str(const char * text, const char * val)
170 { /* string */
171 ipmi_pef_print_field(pef_fld_fmts[F_STR], text, (unsigned long)val);
172 }
173
174 void
ipmi_pef_print_2xd(const char * text,uint8_t u1,uint8_t u2)175 ipmi_pef_print_2xd(const char * text, uint8_t u1, uint8_t u2)
176 { /* 2 hex digits */
177 uint32_t val = ((u1 << 8) + u2) & 0xffff;
178 ipmi_pef_print_field(pef_fld_fmts[F_2XD], text, val);
179 }
180
181 void
ipmi_pef_print_1xd(const char * text,uint32_t val)182 ipmi_pef_print_1xd(const char * text, uint32_t val)
183 { /* 1 hex digit */
184 ipmi_pef_print_field(pef_fld_fmts[F_1XD], text, val);
185 }
186
187 static struct ipmi_rs *
ipmi_pef_msg_exchange(struct ipmi_intf * intf,struct ipmi_rq * req,char * txt)188 ipmi_pef_msg_exchange(struct ipmi_intf * intf, struct ipmi_rq * req, char * txt)
189 { /*
190 // common IPMItool rqst/resp handling
191 */
192 struct ipmi_rs * rsp = intf->sendrecv(intf, req);
193 if (!rsp) {
194 return(NULL);
195 } else if (rsp->ccode == 0x80) {
196 return(NULL); /* Do not output error, just unsupported parameters */
197 } else if (rsp->ccode) {
198 lprintf(LOG_ERR, " **Error %x in '%s' command", rsp->ccode, txt);
199 return(NULL);
200 }
201 if (verbose > 2) {
202 printbuf(rsp->data, rsp->data_len, txt);
203 }
204 return(rsp);
205 }
206
207 static uint8_t
ipmi_pef_get_policy_table(struct ipmi_intf * intf,struct pef_cfgparm_policy_table_entry ** table)208 ipmi_pef_get_policy_table(struct ipmi_intf * intf,
209 struct pef_cfgparm_policy_table_entry ** table)
210 { /*
211 // get the PEF policy table: allocate space, fillin, and return its size
212 // NB: the caller must free the returned area (when returned size > 0)
213 */
214 struct ipmi_rs * rsp;
215 struct ipmi_rq req;
216 struct pef_cfgparm_selector psel;
217 struct pef_cfgparm_policy_table_entry * ptbl, * ptmp;
218 uint32_t i;
219 uint8_t tbl_size;
220
221 memset(&psel, 0, sizeof(psel));
222 psel.id = PEF_CFGPARM_ID_PEF_ALERT_POLICY_TABLE_SIZE;
223 memset(&req, 0, sizeof(req));
224 req.msg.netfn = IPMI_NETFN_SE;
225 req.msg.cmd = IPMI_CMD_GET_PEF_CONFIG_PARMS;
226 req.msg.data = (uint8_t *)&psel;
227 req.msg.data_len = sizeof(psel);
228 rsp = ipmi_pef_msg_exchange(intf, &req, "Alert policy table size");
229 if (!rsp)
230 return(0);
231 tbl_size = (rsp->data[1] & PEF_POLICY_TABLE_SIZE_MASK);
232 i = (tbl_size * sizeof(struct pef_cfgparm_policy_table_entry));
233 if (!i
234 || (ptbl = (struct pef_cfgparm_policy_table_entry *)malloc(i)) == NULL)
235 return(0);
236
237 memset(&psel, 0, sizeof(psel));
238 psel.id = PEF_CFGPARM_ID_PEF_ALERT_POLICY_TABLE_ENTRY;
239 for (ptmp=ptbl, i=1; i<=tbl_size; i++) {
240 psel.set = (i & PEF_POLICY_TABLE_ID_MASK);
241 rsp = ipmi_pef_msg_exchange(intf, &req, "Alert policy table entry");
242 if (!rsp
243 || i != (rsp->data[1] & PEF_POLICY_TABLE_ID_MASK)) {
244 lprintf(LOG_ERR, " **Error retrieving %s",
245 "Alert policy table entry");
246 free(ptbl);
247 ptbl = NULL;
248 tbl_size = 0;
249 break;
250 }
251 memcpy(ptmp, &rsp->data[1], sizeof(*ptmp));
252 ptmp++;
253 }
254
255 *table = ptbl;
256 return(tbl_size);
257 }
258
259 static void
ipmi_pef_print_lan_dest(struct ipmi_intf * intf,uint8_t ch,uint8_t dest)260 ipmi_pef_print_lan_dest(struct ipmi_intf * intf, uint8_t ch, uint8_t dest)
261 { /*
262 // print LAN alert destination info
263 */
264 struct ipmi_rs * rsp;
265 struct ipmi_rq req;
266 struct pef_lan_cfgparm_selector lsel;
267 struct pef_lan_cfgparm_dest_type * ptype;
268 struct pef_lan_cfgparm_dest_info * pinfo;
269 char buf[32];
270 uint8_t tbl_size, dsttype, timeout, retries;
271
272 memset(&lsel, 0, sizeof(lsel));
273 lsel.id = PEF_LAN_CFGPARM_ID_DEST_COUNT;
274 lsel.ch = ch;
275 memset(&req, 0, sizeof(req));
276 req.msg.netfn = IPMI_NETFN_TRANSPORT;
277 req.msg.cmd = IPMI_CMD_LAN_GET_CONFIG;
278 req.msg.data = (uint8_t *)&lsel;
279 req.msg.data_len = sizeof(lsel);
280 rsp = ipmi_pef_msg_exchange(intf, &req, "Alert destination count");
281 if (!rsp) {
282 lprintf(LOG_ERR, " **Error retrieving %s",
283 "Alert destination count");
284 return;
285 }
286 tbl_size = (rsp->data[1] & PEF_LAN_DEST_TABLE_SIZE_MASK);
287 //if (tbl_size == 0 || dest == 0) /* LAN alerting not supported */
288 // return;
289
290 lsel.id = PEF_LAN_CFGPARM_ID_DESTTYPE;
291 lsel.set = dest;
292 rsp = ipmi_pef_msg_exchange(intf, &req, "Alert destination type");
293 if (!rsp || rsp->data[1] != lsel.set) {
294 lprintf(LOG_ERR, " **Error retrieving %s",
295 "Alert destination type");
296 return;
297 }
298 ptype = (struct pef_lan_cfgparm_dest_type *)&rsp->data[1];
299 dsttype = (ptype->dest_type & PEF_LAN_DEST_TYPE_MASK);
300 timeout = ptype->alert_timeout;
301 retries = (ptype->retries & PEF_LAN_RETRIES_MASK);
302 ipmi_pef_print_str("Alert destination type",
303 ipmi_pef_bit_desc(&pef_b2s_lan_desttype, dsttype));
304 if (dsttype == PEF_LAN_DEST_TYPE_PET) {
305 lsel.id = PEF_LAN_CFGPARM_ID_PET_COMMUNITY;
306 lsel.set = 0;
307 rsp = ipmi_pef_msg_exchange(intf, &req, "PET community");
308 if (!rsp)
309 lprintf(LOG_ERR, " **Error retrieving %s",
310 "PET community");
311 else {
312 rsp->data[19] = '\0';
313 ipmi_pef_print_str("PET Community", (const char *)&rsp->data[1]);
314 }
315 }
316 ipmi_pef_print_dec("ACK timeout/retry (secs)", timeout);
317 ipmi_pef_print_dec("Retries", retries);
318
319 lsel.id = PEF_LAN_CFGPARM_ID_DESTADDR;
320 lsel.set = dest;
321 rsp = ipmi_pef_msg_exchange(intf, &req, "Alert destination info");
322 if (!rsp || rsp->data[1] != lsel.set)
323 lprintf(LOG_ERR, " **Error retrieving %s",
324 "Alert destination info");
325 else {
326 pinfo = (struct pef_lan_cfgparm_dest_info *)&rsp->data[1];
327 sprintf(buf, "%u.%u.%u.%u",
328 pinfo->ip[0], pinfo->ip[1], pinfo->ip[2], pinfo->ip[3]);
329 ipmi_pef_print_str("IP address", buf);
330
331 sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
332 pinfo->mac[0], pinfo->mac[1], pinfo->mac[2],
333 pinfo->mac[3], pinfo->mac[4], pinfo->mac[5]);
334 ipmi_pef_print_str("MAC address", buf);
335 }
336 }
337
338 static void
ipmi_pef_print_serial_dest_dial(struct ipmi_intf * intf,char * label,struct pef_serial_cfgparm_selector * ssel)339 ipmi_pef_print_serial_dest_dial(struct ipmi_intf * intf, char * label,
340 struct pef_serial_cfgparm_selector * ssel)
341 { /*
342 // print a dial string
343 */
344 #define BLOCK_SIZE 16
345 struct ipmi_rs * rsp;
346 struct ipmi_rq req;
347 struct pef_serial_cfgparm_selector tmp;
348 char * p, strval[(6 * BLOCK_SIZE) + 1];
349
350 memset(&tmp, 0, sizeof(tmp));
351 tmp.id = PEF_SERIAL_CFGPARM_ID_DEST_DIAL_STRING_COUNT;
352 memset(&req, 0, sizeof(req));
353 req.msg.netfn = IPMI_NETFN_TRANSPORT;
354 req.msg.cmd = IPMI_CMD_SERIAL_GET_CONFIG;
355 req.msg.data = (uint8_t *)&tmp;
356 req.msg.data_len = sizeof(tmp);
357 rsp = ipmi_pef_msg_exchange(intf, &req, "Dial string count");
358 if (!rsp || (rsp->data[1] & PEF_SERIAL_DIAL_STRING_COUNT_MASK) == 0)
359 return; /* sssh, not supported */
360
361 memcpy(&tmp, ssel, sizeof(tmp));
362 tmp.id = PEF_SERIAL_CFGPARM_ID_DEST_DIAL_STRING;
363 tmp.block = 1;
364 memset(strval, 0, sizeof(strval));
365 p = strval;
366 for (;;) {
367 rsp = ipmi_pef_msg_exchange(intf, &req, label);
368 if (!rsp
369 || (rsp->data[1] != ssel->id)
370 || (rsp->data[2] != tmp.block)) {
371 lprintf(LOG_ERR, " **Error retrieving %s", label);
372 return;
373 }
374 memcpy(p, &rsp->data[3], BLOCK_SIZE);
375 if (strchr(p, '\0') <= (p + BLOCK_SIZE))
376 break;
377 if ((p += BLOCK_SIZE) >= &strval[sizeof(strval)-1])
378 break;
379 tmp.block++;
380 }
381
382 ipmi_pef_print_str(label, strval);
383 #undef BLOCK_SIZE
384 }
385
386 static void
ipmi_pef_print_serial_dest_tap(struct ipmi_intf * intf,struct pef_serial_cfgparm_selector * ssel)387 ipmi_pef_print_serial_dest_tap(struct ipmi_intf * intf,
388 struct pef_serial_cfgparm_selector * ssel)
389 { /*
390 // print TAP destination info
391 */
392 struct ipmi_rs * rsp;
393 struct ipmi_rq req;
394 struct pef_serial_cfgparm_selector tmp;
395 struct pef_serial_cfgparm_tap_svc_settings * pset;
396 uint8_t dialstr_id, setting_id;
397
398 memset(&tmp, 0, sizeof(tmp));
399 tmp.id = PEF_SERIAL_CFGPARM_ID_TAP_ACCT_COUNT;
400 memset(&req, 0, sizeof(req));
401 req.msg.netfn = IPMI_NETFN_TRANSPORT;
402 req.msg.cmd = IPMI_CMD_SERIAL_GET_CONFIG;
403 req.msg.data = (uint8_t *)&tmp;
404 req.msg.data_len = sizeof(tmp);
405 rsp = ipmi_pef_msg_exchange(intf, &req, "Number of TAP accounts");
406 if (!rsp || (rsp->data[1] & PEF_SERIAL_TAP_ACCT_COUNT_MASK) == 0)
407 return; /* sssh, not supported */
408
409 memcpy(&tmp, ssel, sizeof(tmp));
410 tmp.id = PEF_SERIAL_CFGPARM_ID_TAP_ACCT_INFO;
411 rsp = ipmi_pef_msg_exchange(intf, &req, "TAP account info");
412 if (!rsp || (rsp->data[1] != tmp.set)) {
413 lprintf(LOG_ERR, " **Error retrieving %s",
414 "TAP account info");
415 return;
416 }
417 dialstr_id = (rsp->data[2] & PEF_SERIAL_TAP_ACCT_INFO_DIAL_STRING_ID_MASK);
418 dialstr_id >>= PEF_SERIAL_TAP_ACCT_INFO_DIAL_STRING_ID_SHIFT;
419 setting_id = (rsp->data[2] & PEF_SERIAL_TAP_ACCT_INFO_SVC_SETTINGS_ID_MASK);
420 tmp.set = dialstr_id;
421 ipmi_pef_print_serial_dest_dial(intf, "TAP Dial string", &tmp);
422
423 tmp.set = setting_id;
424 rsp = ipmi_pef_msg_exchange(intf, &req, "TAP service settings");
425 if (!rsp || (rsp->data[1] != tmp.set)) {
426 lprintf(LOG_ERR, " **Error retrieving %s",
427 "TAP service settings");
428 return;
429 }
430 pset = (struct pef_serial_cfgparm_tap_svc_settings *)&rsp->data[1];
431 ipmi_pef_print_str("TAP confirmation",
432 ipmi_pef_bit_desc(&pef_b2s_tap_svc_confirm, pset->confirmation_flags));
433
434 /* TODO : additional TAP settings? */
435 }
436
437 static void
ipmi_pef_print_serial_dest_ppp(struct ipmi_intf * intf,struct pef_serial_cfgparm_selector * ssel)438 ipmi_pef_print_serial_dest_ppp(struct ipmi_intf * intf,
439 struct pef_serial_cfgparm_selector * ssel)
440 { /*
441 // print PPP destination info
442 */
443
444 /* TODO */
445 }
446
447 static void
ipmi_pef_print_serial_dest_callback(struct ipmi_intf * intf,struct pef_serial_cfgparm_selector * ssel)448 ipmi_pef_print_serial_dest_callback(struct ipmi_intf * intf,
449 struct pef_serial_cfgparm_selector * ssel)
450 { /*
451 // print callback destination info
452 */
453
454 /* TODO */
455 }
456
457 static void
ipmi_pef_print_serial_dest(struct ipmi_intf * intf,uint8_t ch,uint8_t dest)458 ipmi_pef_print_serial_dest(struct ipmi_intf * intf, uint8_t ch, uint8_t dest)
459 { /*
460 // print Serial/PPP alert destination info
461 */
462 struct ipmi_rs * rsp;
463 struct ipmi_rq req;
464 struct pef_serial_cfgparm_selector ssel;
465 uint8_t tbl_size, wrk;
466 struct pef_serial_cfgparm_dest_info * pinfo;
467
468 memset(&ssel, 0, sizeof(ssel));
469 ssel.id = PEF_SERIAL_CFGPARM_ID_DEST_COUNT;
470 ssel.ch = ch;
471 memset(&req, 0, sizeof(req));
472 req.msg.netfn = IPMI_NETFN_TRANSPORT;
473 req.msg.cmd = IPMI_CMD_SERIAL_GET_CONFIG;
474 req.msg.data = (uint8_t *)&ssel;
475 req.msg.data_len = sizeof(ssel);
476 rsp = ipmi_pef_msg_exchange(intf, &req, "Alert destination count");
477 if (!rsp) {
478 lprintf(LOG_ERR, " **Error retrieving %s",
479 "Alert destination count");
480 return;
481 }
482 tbl_size = (rsp->data[1] & PEF_SERIAL_DEST_TABLE_SIZE_MASK);
483 if (!dest || tbl_size == 0) /* Page alerting not supported */
484 return;
485
486 ssel.id = PEF_SERIAL_CFGPARM_ID_DESTINFO;
487 ssel.set = dest;
488 rsp = ipmi_pef_msg_exchange(intf, &req, "Alert destination info");
489 if (!rsp || rsp->data[1] != ssel.set)
490 lprintf(LOG_ERR, " **Error retrieving %s",
491 "Alert destination info");
492 else {
493 pinfo = (struct pef_serial_cfgparm_dest_info *)rsp->data;
494 wrk = (pinfo->dest_type & PEF_SERIAL_DEST_TYPE_MASK);
495 ipmi_pef_print_str("Alert destination type",
496 ipmi_pef_bit_desc(&pef_b2s_serial_desttype, wrk));
497 ipmi_pef_print_dec("ACK timeout (secs)",
498 pinfo->alert_timeout);
499 ipmi_pef_print_dec("Retries",
500 (pinfo->retries & PEF_SERIAL_RETRIES_MASK));
501 switch (wrk) {
502 case PEF_SERIAL_DEST_TYPE_DIAL:
503 ipmi_pef_print_serial_dest_dial(intf, "Serial dial string", &ssel);
504 break;
505 case PEF_SERIAL_DEST_TYPE_TAP:
506 ipmi_pef_print_serial_dest_tap(intf, &ssel);
507 break;
508 case PEF_SERIAL_DEST_TYPE_PPP:
509 ipmi_pef_print_serial_dest_ppp(intf, &ssel);
510 break;
511 case PEF_SERIAL_DEST_TYPE_BASIC_CALLBACK:
512 case PEF_SERIAL_DEST_TYPE_PPP_CALLBACK:
513 ipmi_pef_print_serial_dest_callback(intf, &ssel);
514 break;
515 }
516 }
517 }
518
519 static void
ipmi_pef_print_dest(struct ipmi_intf * intf,uint8_t ch,uint8_t dest)520 ipmi_pef_print_dest(struct ipmi_intf * intf, uint8_t ch, uint8_t dest)
521 { /*
522 // print generic alert destination info
523 */
524 ipmi_pef_print_dec("Destination ID", dest);
525 }
526
527 void
ipmi_pef_print_event_info(struct pef_cfgparm_filter_table_entry * pef,char * buf)528 ipmi_pef_print_event_info(struct pef_cfgparm_filter_table_entry * pef, char * buf)
529 { /*
530 // print PEF entry Event info: class, severity, trigger, etc.
531 */
532 static char * classes[] = {"Discrete", "Threshold", "OEM"};
533 uint16_t offmask;
534 char * p;
535 int i;
536 uint8_t t;
537
538 ipmi_pef_print_str("Event severity",
539 ipmi_pef_bit_desc(&pef_b2s_severities, pef->entry.severity));
540
541 t = pef->entry.event_trigger;
542 if (t == PEF_EVENT_TRIGGER_THRESHOLD)
543 i = 1;
544 else if (t > PEF_EVENT_TRIGGER_SENSOR_SPECIFIC)
545 i = 2;
546 else
547 i = 0;
548 ipmi_pef_print_str("Event class", classes[i]);
549
550 offmask = ((pef->entry.event_data_1_offset_mask[1] << 8)
551 + pef->entry.event_data_1_offset_mask[0]);
552
553 if (offmask == 0xffff || t == PEF_EVENT_TRIGGER_MATCH_ANY)
554 strcpy(buf, "Any");
555 else if (t == PEF_EVENT_TRIGGER_UNSPECIFIED)
556 strcpy(buf, "Unspecified");
557 else if (t == PEF_EVENT_TRIGGER_SENSOR_SPECIFIC)
558 strcpy(buf, "Sensor-specific");
559 else if (t > PEF_EVENT_TRIGGER_SENSOR_SPECIFIC)
560 strcpy(buf, "OEM");
561 else {
562 sprintf(buf, "(0x%02x/0x%04x)", t, offmask);
563 p = strchr(buf, '\0');
564 for (i=0; i<PEF_B2S_GENERIC_ER_ENTRIES; i++) {
565 if (offmask & 1) {
566 if ((t-1) >= PEF_B2S_GENERIC_ER_ENTRIES) {
567 sprintf(p, ", Unrecognized event trigger");
568 } else {
569 sprintf(p, ",%s", ipmi_pef_bit_desc(pef_b2s_generic_ER[t-1], i));
570 }
571 p = strchr(p, '\0');
572 }
573 offmask >>= 1;
574 }
575 }
576
577 ipmi_pef_print_str("Event trigger(s)", buf);
578 }
579
580 static void
ipmi_pef_print_entry(struct ipmi_rs * rsp,uint8_t id,struct pef_cfgparm_filter_table_entry * pef)581 ipmi_pef_print_entry(struct ipmi_rs * rsp, uint8_t id,
582 struct pef_cfgparm_filter_table_entry * pef)
583 { /*
584 // print a PEF table entry
585 */
586 uint8_t wrk, set;
587 char buf[128];
588
589 ipmi_pef_print_dec("PEF table entry", id);
590
591 wrk = !!(pef->entry.config & PEF_CONFIG_ENABLED);
592 sprintf(buf, "%sactive", (wrk ? "" : "in"));
593 if (pef->entry.config & PEF_CONFIG_PRECONFIGURED)
594 strcat(buf, ", pre-configured");
595
596 ipmi_pef_print_str("Status", buf);
597
598 if (wrk != 0) {
599 ipmi_pef_print_1xd("Version", rsp->data[0]);
600 ipmi_pef_print_str("Sensor type",
601 ipmi_pef_bit_desc(&pef_b2s_sensortypes, pef->entry.sensor_type));
602
603 if (pef->entry.sensor_number == PEF_SENSOR_NUMBER_MATCH_ANY)
604 ipmi_pef_print_str("Sensor number", "Any");
605 else
606 ipmi_pef_print_dec("Sensor number", pef->entry.sensor_number);
607
608 ipmi_pef_print_event_info(pef, buf);
609 ipmi_pef_print_str("Action",
610 ipmi_pef_bit_desc(&pef_b2s_actions, pef->entry.action));
611
612 if (pef->entry.action & PEF_ACTION_ALERT) {
613 set = (pef->entry.policy_number & PEF_POLICY_NUMBER_MASK);
614 ipmi_pef_print_int("Policy set", set);
615 }
616 }
617 }
618
619 static void
ipmi_pef_list_entries(struct ipmi_intf * intf)620 ipmi_pef_list_entries(struct ipmi_intf * intf)
621 { /*
622 // list all PEF table entries
623 */
624 struct ipmi_rs * rsp;
625 struct ipmi_rq req;
626 struct pef_cfgparm_selector psel;
627 struct pef_cfgparm_filter_table_entry * pcfg;
628 uint32_t i;
629 uint8_t max_filters;
630
631 memset(&req, 0, sizeof(req));
632 req.msg.netfn = IPMI_NETFN_SE;
633 req.msg.cmd = IPMI_CMD_GET_PEF_CAPABILITIES;
634 rsp = ipmi_pef_msg_exchange(intf, &req, "PEF capabilities");
635 if (!rsp
636 || (max_filters = ((struct pef_capabilities *)rsp->data)->tblsize) == 0)
637 return; /* sssh, not supported */
638
639 memset(&psel, 0, sizeof(psel));
640 psel.id = PEF_CFGPARM_ID_PEF_FILTER_TABLE_ENTRY;
641 memset(&req, 0, sizeof(req));
642 req.msg.netfn = IPMI_NETFN_SE;
643 req.msg.cmd = IPMI_CMD_GET_PEF_CONFIG_PARMS;
644 req.msg.data = (uint8_t *)&psel;
645 req.msg.data_len = sizeof(psel);
646 for (i=1; i<=max_filters; i++) {
647 if (i > 1)
648 printf("\n");
649 psel.set = (i & PEF_FILTER_TABLE_ID_MASK);
650 rsp = ipmi_pef_msg_exchange(intf, &req, "PEF table entry");
651 if (!rsp
652 || (psel.set != (rsp->data[1] & PEF_FILTER_TABLE_ID_MASK))) {
653 lprintf(LOG_ERR, " **Error retrieving %s",
654 "PEF table entry");
655 continue;
656 }
657 pcfg = (struct pef_cfgparm_filter_table_entry *)&rsp->data[1];
658 first_field = 1;
659 ipmi_pef_print_entry(rsp, psel.set, pcfg);
660 }
661 }
662
663 static void
ipmi_pef_list_policies(struct ipmi_intf * intf)664 ipmi_pef_list_policies(struct ipmi_intf * intf)
665 { /*
666 // list PEF alert policies
667 */
668 struct ipmi_rs * rsp;
669 struct ipmi_rq req;
670 struct pef_cfgparm_policy_table_entry * ptbl = NULL;
671 struct pef_cfgparm_policy_table_entry * ptmp = NULL;
672 uint32_t i;
673 uint8_t wrk, ch, medium, tbl_size;
674
675 tbl_size = ipmi_pef_get_policy_table(intf, &ptbl);
676 if (!tbl_size) {
677 if (ptbl != NULL) {
678 free(ptbl);
679 ptbl = NULL;
680 }
681 return;
682 }
683 memset(&req, 0, sizeof(req));
684 req.msg.netfn = IPMI_NETFN_APP;
685 req.msg.cmd = IPMI_CMD_GET_CHANNEL_INFO;
686 req.msg.data = &ch;
687 req.msg.data_len = sizeof(ch);
688 for (ptmp=ptbl, i=1; i<=tbl_size; i++, ptmp++) {
689 if ((ptmp->entry.policy & PEF_POLICY_ENABLED) == PEF_POLICY_ENABLED) {
690 if (i > 1)
691 printf("\n");
692 first_field = 1;
693 ipmi_pef_print_dec("Alert policy table entry",
694 (ptmp->data1 & PEF_POLICY_TABLE_ID_MASK));
695 ipmi_pef_print_dec("Policy set",
696 (ptmp->entry.policy & PEF_POLICY_ID_MASK) >> PEF_POLICY_ID_SHIFT);
697 ipmi_pef_print_str("Policy entry rule",
698 ipmi_pef_bit_desc(&pef_b2s_policies, (ptmp->entry.policy & PEF_POLICY_FLAGS_MASK)));
699
700 if (ptmp->entry.alert_string_key & PEF_POLICY_EVENT_SPECIFIC) {
701 ipmi_pef_print_str("Event-specific", "true");
702 // continue;
703 }
704 wrk = ptmp->entry.chan_dest;
705
706 /* channel/description */
707 ch = (wrk & PEF_POLICY_CHANNEL_MASK) >> PEF_POLICY_CHANNEL_SHIFT;
708 rsp = ipmi_pef_msg_exchange(intf, &req, "Channel info");
709 if (!rsp || rsp->data[0] != ch) {
710 lprintf(LOG_ERR, " **Error retrieving %s",
711 "Channel info");
712 continue;
713 }
714 medium = rsp->data[1];
715 ipmi_pef_print_dec("Channel number", ch);
716 ipmi_pef_print_str("Channel medium",
717 ipmi_pef_bit_desc(&pef_b2s_ch_medium, medium));
718
719 /* destination/description */
720 wrk &= PEF_POLICY_DESTINATION_MASK;
721 switch (medium) {
722 case PEF_CH_MEDIUM_TYPE_LAN:
723 ipmi_pef_print_lan_dest(intf, ch, wrk);
724 break;
725 case PEF_CH_MEDIUM_TYPE_SERIAL:
726 ipmi_pef_print_serial_dest(intf, ch, wrk);
727 break;
728 default:
729 ipmi_pef_print_dest(intf, ch, wrk);
730 break;
731 }
732 }
733 }
734 free(ptbl);
735 ptbl = NULL;
736 }
737
738 static void
ipmi_pef_get_status(struct ipmi_intf * intf)739 ipmi_pef_get_status(struct ipmi_intf * intf)
740 { /*
741 // report the PEF status
742 */
743 struct ipmi_rs * rsp;
744 struct ipmi_rq req;
745 struct pef_cfgparm_selector psel;
746 char tbuf[40];
747 uint32_t timei;
748 time_t ts;
749
750 memset(&req, 0, sizeof(req));
751 req.msg.netfn = IPMI_NETFN_SE;
752 req.msg.cmd = IPMI_CMD_GET_LAST_PROCESSED_EVT_ID;
753 rsp = ipmi_pef_msg_exchange(intf, &req, "Last S/W processed ID");
754 if (!rsp) {
755 lprintf(LOG_ERR, " **Error retrieving %s",
756 "Last S/W processed ID");
757 return;
758 }
759 memcpy(&timei, rsp->data, sizeof(timei));
760 #if WORDS_BIGENDIAN
761 timei = BSWAP_32(timei);
762 #endif
763 ts = (time_t)timei;
764
765 strftime(tbuf, sizeof(tbuf), "%m/%d/%Y %H:%M:%S", gmtime(&ts));
766
767 ipmi_pef_print_str("Last SEL addition", tbuf);
768 ipmi_pef_print_2xd("Last SEL record ID", rsp->data[5], rsp->data[4]);
769 ipmi_pef_print_2xd("Last S/W processed ID", rsp->data[7], rsp->data[6]);
770 ipmi_pef_print_2xd("Last BMC processed ID", rsp->data[9], rsp->data[8]);
771
772 memset(&psel, 0, sizeof(psel));
773 psel.id = PEF_CFGPARM_ID_PEF_CONTROL;
774 memset(&req, 0, sizeof(req));
775 req.msg.netfn = IPMI_NETFN_SE;
776 req.msg.cmd = IPMI_CMD_GET_PEF_CONFIG_PARMS;
777 req.msg.data = (uint8_t *)&psel;
778 req.msg.data_len = sizeof(psel);
779 rsp = ipmi_pef_msg_exchange(intf, &req, "PEF control");
780 if (!rsp) {
781 lprintf(LOG_ERR, " **Error retrieving %s",
782 "PEF control");
783 return;
784 }
785 ipmi_pef_print_flags(&pef_b2s_control, P_ABLE, rsp->data[1]);
786
787 psel.id = PEF_CFGPARM_ID_PEF_ACTION;
788 rsp = ipmi_pef_msg_exchange(intf, &req, "PEF action");
789 if (!rsp) {
790 lprintf(LOG_ERR, " **Error retrieving %s",
791 "PEF action");
792 return;
793 }
794 ipmi_pef_print_flags(&pef_b2s_actions, P_ACTV, rsp->data[1]);
795 }
796
797 static void
ipmi_pef_get_info(struct ipmi_intf * intf)798 ipmi_pef_get_info(struct ipmi_intf * intf)
799 { /*
800 // report PEF capabilities + System GUID
801 */
802 struct ipmi_rs * rsp;
803 struct ipmi_rq req;
804 struct pef_capabilities * pcap;
805 struct pef_cfgparm_selector psel;
806 struct pef_cfgparm_policy_table_entry * ptbl = NULL;
807 uint8_t * uid;
808 uint8_t actions, tbl_size;
809
810 tbl_size = ipmi_pef_get_policy_table(intf, &ptbl);
811 if (ptbl != NULL) {
812 free(ptbl);
813 ptbl = NULL;
814 }
815
816 memset(&req, 0, sizeof(req));
817 req.msg.netfn = IPMI_NETFN_SE;
818 req.msg.cmd = IPMI_CMD_GET_PEF_CAPABILITIES;
819 rsp = ipmi_pef_msg_exchange(intf, &req, "PEF capabilities");
820 if (!rsp)
821 return;
822 pcap = (struct pef_capabilities *)rsp->data;
823
824 ipmi_pef_print_1xd("Version", pcap->version);
825 ipmi_pef_print_dec("PEF table size", pcap->tblsize);
826 ipmi_pef_print_dec("Alert policy table size", tbl_size);
827 actions = pcap->actions;
828
829 memset(&psel, 0, sizeof(psel));
830 psel.id = PEF_CFGPARM_ID_SYSTEM_GUID;
831 memset(&req, 0, sizeof(req));
832 req.msg.netfn = IPMI_NETFN_SE;
833 req.msg.cmd = IPMI_CMD_GET_PEF_CONFIG_PARMS;
834 req.msg.data = (uint8_t *)&psel;
835 req.msg.data_len = sizeof(psel);
836 rsp = ipmi_pef_msg_exchange(intf, &req, "System GUID");
837 uid = NULL;
838 if (rsp && (rsp->data[1] & PEF_SYSTEM_GUID_USED_IN_PET))
839 uid = &rsp->data[2];
840 else {
841 memset(&req, 0, sizeof(req));
842 req.msg.netfn = IPMI_NETFN_APP;
843 req.msg.cmd = IPMI_CMD_GET_SYSTEM_GUID;
844 rsp = ipmi_pef_msg_exchange(intf, &req, "System GUID");
845 if (rsp)
846 uid = &rsp->data[0];
847 }
848 if (uid) { /* got GUID? */
849 if (verbose)
850 printf(pef_fld_fmts[F_UID][0], KYWD_LENGTH, "System GUID",
851 uid[0], uid[1], uid[2], uid[3], uid[4], uid[5], uid[6], uid[7],
852 uid[8], uid[9], uid[10],uid[11],uid[12],uid[13],uid[14],uid[15]);
853 else
854 printf(pef_fld_fmts[F_UID][1],
855 uid[0], uid[1], uid[2], uid[3], uid[4], uid[5], uid[6], uid[7],
856 uid[8], uid[9], uid[10],uid[11],uid[12],uid[13],uid[14],uid[15]);
857 }
858 ipmi_pef_print_flags(&pef_b2s_actions, P_SUPP, actions);
859 }
860
ipmi_pef_main(struct ipmi_intf * intf,int argc,char ** argv)861 int ipmi_pef_main(struct ipmi_intf * intf, int argc, char ** argv)
862 { /*
863 // PEF subcommand handling
864 */
865 int help = 0;
866 int rc = 0;
867
868 if (!argc || !strncmp(argv[0], "info", 4))
869 ipmi_pef_get_info(intf);
870 else if (!strncmp(argv[0], "help", 4))
871 help = 1;
872 else if (!strncmp(argv[0], "status", 6))
873 ipmi_pef_get_status(intf);
874 else if (!strncmp(argv[0], "policy", 6))
875 ipmi_pef_list_policies(intf);
876 else if (!strncmp(argv[0], "list", 4))
877 ipmi_pef_list_entries(intf);
878 else {
879 help = 1;
880 rc = -1;
881 lprintf(LOG_ERR, "Invalid PEF command: '%s'\n", argv[0]);
882 }
883
884 if (help)
885 lprintf(LOG_NOTICE, "PEF commands: info status policy list");
886 else if (!verbose)
887 printf("\n");
888
889 return rc;
890 }
891