1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #pragma ident "%Z%%M% %I% %E% SMI" 27 28 #include <libipmi.h> 29 #include <stdio.h> 30 #include <string.h> 31 32 /*ARGSUSED*/ 33 static int 34 sdr_print(ipmi_handle_t *ihp, ipmi_entity_t *ep, const char *name, 35 ipmi_sdr_t *sdrp, void *data) 36 { 37 int indentation = (uintptr_t)data; 38 ipmi_sdr_compact_sensor_t *csp; 39 ipmi_sdr_full_sensor_t *fsp; 40 uint8_t sensor_number, sensor_type, reading_type; 41 boolean_t get_reading = B_FALSE; 42 ipmi_sensor_reading_t *srp; 43 char sensor_name[128]; 44 char reading_name[128]; 45 46 if (name == NULL) 47 return (0); 48 49 switch (sdrp->is_type) { 50 case IPMI_SDR_TYPE_COMPACT_SENSOR: 51 csp = (ipmi_sdr_compact_sensor_t *)sdrp->is_record; 52 sensor_number = csp->is_cs_number; 53 sensor_type = csp->is_cs_type; 54 reading_type = csp->is_cs_reading_type; 55 get_reading = B_TRUE; 56 break; 57 58 case IPMI_SDR_TYPE_FULL_SENSOR: 59 fsp = (ipmi_sdr_full_sensor_t *)sdrp->is_record; 60 sensor_number = fsp->is_fs_number; 61 sensor_type = fsp->is_fs_type; 62 reading_type = fsp->is_fs_reading_type; 63 get_reading = B_TRUE; 64 break; 65 } 66 67 (void) printf("%*s%-*s", indentation, "", 68 36 - indentation, name); 69 70 if (get_reading) { 71 ipmi_sensor_type_name(sensor_type, sensor_name, 72 sizeof (sensor_name)); 73 ipmi_sensor_reading_name(sensor_type, reading_type, 74 reading_name, sizeof (reading_name)); 75 (void) printf("%12s %12s", sensor_name, reading_name); 76 if ((srp = ipmi_get_sensor_reading(ihp, 77 sensor_number)) == NULL) { 78 if (ipmi_errno(ihp) == EIPMI_NOT_PRESENT) { 79 (void) printf(" -\n"); 80 } else { 81 (void) printf("\n"); 82 return (-1); 83 } 84 } else { 85 (void) printf(" %04x\n", srp->isr_state); 86 } 87 } else { 88 (void) printf("\n"); 89 } 90 91 return (0); 92 } 93 94 static int 95 entity_print(ipmi_handle_t *ihp, ipmi_entity_t *ep, void *data) 96 { 97 int indentation = (uintptr_t)data; 98 char name[128]; 99 boolean_t present; 100 101 ipmi_entity_name(ep->ie_type, name, sizeof (name)); 102 (void) snprintf(name + strlen(name), sizeof (name) - strlen(name), 103 " %d", ep->ie_instance); 104 105 if (ipmi_entity_present(ihp, ep, &present) != 0) { 106 (void) printf("%*s%-*s %s (%s)\n", indentation, "", 107 24 - indentation, name, "unknown", ipmi_errmsg(ihp)); 108 } else { 109 (void) printf("%*s%-*s %s\n", indentation, "", 110 24 - indentation, name, present ? "present" : "absent"); 111 } 112 ipmi_entity_iter_sdr(ihp, ep, sdr_print, (void *)(indentation + 2)); 113 114 if (ep->ie_children != 0) 115 (void) ipmi_entity_iter_children(ihp, ep, entity_print, 116 (void *)(indentation + 2)); 117 return (0); 118 } 119 120 /*ARGSUSED*/ 121 int 122 main(int argc, char **argv) 123 { 124 ipmi_handle_t *ihp; 125 char *errmsg; 126 int err; 127 128 if ((ihp = ipmi_open(&err, &errmsg)) == NULL) { 129 (void) fprintf(stderr, "failed to open libipmi: %s\n", 130 errmsg); 131 return (1); 132 } 133 134 (void) printf("%-24s %-8s %12s %12s %5s\n", 135 "ENTITY/SENSOR", "PRESENT", "SENSOR", "READING", "STATE"); 136 (void) printf("----------------------- -------- ------------- " 137 "------------ -----\n"); 138 if (ipmi_entity_iter(ihp, entity_print, NULL) != 0) { 139 (void) fprintf(stderr, "failed to iterate entities: %s\n", 140 ipmi_errmsg(ihp)); 141 return (1); 142 } 143 144 ipmi_close(ihp); 145 146 return (0); 147 } 148