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 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 * Copyright (c) 2018, Joyent, Inc.
32 #include "ipmi_impl.h"
34 ipmi_sensor_reading_t
*
35 ipmi_get_sensor_reading(ipmi_handle_t
*ihp
, uint8_t id
)
37 ipmi_cmd_t cmd
, *resp
;
38 ipmi_sensor_reading_t
*srp
;
40 cmd
.ic_netfn
= IPMI_NETFN_SE
;
41 cmd
.ic_cmd
= IPMI_CMD_GET_SENSOR_READING
;
44 cmd
.ic_dlen
= sizeof (id
);
46 if ((resp
= ipmi_send(ihp
, &cmd
)) == NULL
)
50 * The upper half of the state field is optional, so if it's not
51 * present, then set it to zero. We also need to convert to the
54 if (resp
->ic_dlen
< sizeof (ipmi_sensor_reading_t
) - sizeof (uint8_t)) {
55 (void) ipmi_set_error(ihp
, EIPMI_BAD_RESPONSE_LENGTH
, NULL
);
60 if (resp
->ic_dlen
< sizeof (ipmi_sensor_reading_t
))
61 (void) memset((char *)srp
+ resp
->ic_dlen
, '\0',
62 sizeof (ipmi_sensor_reading_t
) - resp
->ic_dlen
);
64 srp
->isr_state
= LE_IN16(&srp
->isr_state
);
69 ipmi_set_sensor_reading(ipmi_handle_t
*ihp
, ipmi_set_sensor_reading_t
*req
)
71 ipmi_set_sensor_reading_t realreq
;
72 ipmi_cmd_t cmd
, *resp
;
76 * Convert states to little endian.
78 (void) memcpy(&realreq
, req
, sizeof (realreq
));
80 tmp
= LE_IN16(&realreq
.iss_assert_state
);
81 (void) memcpy(&realreq
.iss_assert_state
, &tmp
, sizeof (tmp
));
82 tmp
= LE_IN16(&realreq
.iss_deassert_state
);
83 (void) memcpy(&realreq
.iss_deassert_state
, &tmp
, sizeof (tmp
));
85 cmd
.ic_netfn
= IPMI_NETFN_SE
;
86 cmd
.ic_cmd
= IPMI_CMD_SET_SENSOR_READING
;
88 cmd
.ic_data
= &realreq
;
89 cmd
.ic_dlen
= sizeof (realreq
);
91 if ((resp
= ipmi_send(ihp
, &cmd
)) == NULL
)
94 if (resp
->ic_dlen
!= 0)
95 return (ipmi_set_error(ihp
, EIPMI_BAD_RESPONSE_LENGTH
, NULL
));
101 ipmi_get_sensor_thresholds(ipmi_handle_t
*ihp
, ipmi_sensor_thresholds_t
*thresh
,
104 ipmi_cmd_t cmd
, *resp
;
106 cmd
.ic_netfn
= IPMI_NETFN_SE
;
107 cmd
.ic_cmd
= IPMI_CMD_GET_SENSOR_THRESHOLDS
;
110 cmd
.ic_dlen
= sizeof (id
);
112 if ((resp
= ipmi_send(ihp
, &cmd
)) == NULL
)
115 if (resp
->ic_dlen
< sizeof (ipmi_sensor_thresholds_t
)) {
116 return (ipmi_set_error(ihp
, EIPMI_BAD_RESPONSE_LENGTH
, NULL
));
119 (void) memcpy(thresh
, resp
->ic_data
, sizeof (ipmi_sensor_thresholds_t
));