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.
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.
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]
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
30 static const char *pname
;
31 static const char optstr
[] = "h:p:u:t:";
36 (void) fprintf(stderr
,
37 "Usage: %s [-t <bmc|lan>] [-h hostname] [-u username] "
38 "[-p password]\n", pname
);
43 sdr_print(ipmi_handle_t
*ihp
, ipmi_entity_t
*ep
, const char *name
,
44 ipmi_sdr_t
*sdrp
, void *data
)
46 int indentation
= (uintptr_t)data
;
47 ipmi_sdr_compact_sensor_t
*csp
;
48 ipmi_sdr_full_sensor_t
*fsp
;
49 uint8_t sensor_number
, sensor_type
, reading_type
;
50 boolean_t get_reading
= B_FALSE
;
51 ipmi_sensor_reading_t
*srp
;
52 char sensor_name
[128];
53 char reading_name
[128];
58 switch (sdrp
->is_type
) {
59 case IPMI_SDR_TYPE_COMPACT_SENSOR
:
60 csp
= (ipmi_sdr_compact_sensor_t
*)sdrp
->is_record
;
61 sensor_number
= csp
->is_cs_number
;
62 sensor_type
= csp
->is_cs_type
;
63 reading_type
= csp
->is_cs_reading_type
;
67 case IPMI_SDR_TYPE_FULL_SENSOR
:
68 fsp
= (ipmi_sdr_full_sensor_t
*)sdrp
->is_record
;
69 sensor_number
= fsp
->is_fs_number
;
70 sensor_type
= fsp
->is_fs_type
;
71 reading_type
= fsp
->is_fs_reading_type
;
76 (void) printf("%*s%-*s", indentation
, "",
77 36 - indentation
, name
);
80 ipmi_sensor_type_name(sensor_type
, sensor_name
,
81 sizeof (sensor_name
));
82 ipmi_sensor_reading_name(sensor_type
, reading_type
,
83 reading_name
, sizeof (reading_name
));
84 (void) printf("%12s %12s", sensor_name
, reading_name
);
85 if ((srp
= ipmi_get_sensor_reading(ihp
,
86 sensor_number
)) == NULL
) {
87 if (ipmi_errno(ihp
) == EIPMI_NOT_PRESENT
) {
88 (void) printf(" -\n");
94 (void) printf(" %04x\n", srp
->isr_state
);
104 entity_print(ipmi_handle_t
*ihp
, ipmi_entity_t
*ep
, void *data
)
106 int indentation
= (uintptr_t)data
;
110 ipmi_entity_name(ep
->ie_type
, name
, sizeof (name
));
111 (void) snprintf(name
+ strlen(name
), sizeof (name
) - strlen(name
),
112 " %d", ep
->ie_instance
);
114 if (ipmi_entity_present(ihp
, ep
, &present
) != 0) {
115 (void) printf("%*s%-*s %s (%s)\n", indentation
, "",
116 24 - indentation
, name
, "unknown", ipmi_errmsg(ihp
));
118 (void) printf("%*s%-*s %s\n", indentation
, "",
119 24 - indentation
, name
, present
? "present" : "absent");
121 (void) ipmi_entity_iter_sdr(ihp
, ep
, sdr_print
,
122 (void *)(indentation
+ 2));
124 if (ep
->ie_children
!= 0)
125 (void) ipmi_entity_iter_children(ihp
, ep
, entity_print
,
126 (void *)(indentation
+ 2));
131 main(int argc
, char **argv
)
136 char c
, *host
= NULL
, *user
= NULL
, *passwd
= NULL
;
138 nvlist_t
*params
= NULL
;
141 while (optind
< argc
) {
142 while ((c
= getopt(argc
, argv
, optstr
)) != -1)
151 if (strcmp(optarg
, "bmc") == 0)
152 xport_type
= IPMI_TRANSPORT_BMC
;
153 else if (strcmp(optarg
, "lan") == 0)
154 xport_type
= IPMI_TRANSPORT_LAN
;
156 (void) fprintf(stderr
,
157 "ABORT: Invalid transport type\n");
170 if (xport_type
== IPMI_TRANSPORT_LAN
&&
171 (host
== NULL
|| passwd
== NULL
|| user
== NULL
)) {
172 (void) fprintf(stderr
, "-h/-u/-p must all be specified for "
173 "transport type \"lan\"\n");
177 if (xport_type
== IPMI_TRANSPORT_LAN
) {
178 if (nvlist_alloc(¶ms
, NV_UNIQUE_NAME
, 0) ||
179 nvlist_add_string(params
, IPMI_LAN_HOST
, host
) ||
180 nvlist_add_string(params
, IPMI_LAN_USER
, user
) ||
181 nvlist_add_string(params
, IPMI_LAN_PASSWD
, passwd
)) {
182 (void) fprintf(stderr
,
183 "ABORT: nvlist construction failed\n");
187 if ((ihp
= ipmi_open(&err
, &errmsg
, xport_type
, params
)) == NULL
) {
188 (void) fprintf(stderr
, "failed to open libipmi: %s\n",
193 (void) printf("%-24s %-8s %12s %12s %5s\n",
194 "ENTITY/SENSOR", "PRESENT", "SENSOR", "READING", "STATE");
195 (void) printf("----------------------- -------- ------------- "
196 "------------ -----\n");
197 if (ipmi_entity_iter(ihp
, entity_print
, NULL
) != 0) {
198 (void) fprintf(stderr
, "failed to iterate entities: %s\n",