8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / libipmi / common / ipmi_sensor.c
blob0b035709a3861c65d44ce2650ab22c6dd4bb0330
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
28 #include <libipmi.h>
29 #include <string.h>
31 #include "ipmi_impl.h"
33 ipmi_sensor_reading_t *
34 ipmi_get_sensor_reading(ipmi_handle_t *ihp, uint8_t id)
36 ipmi_cmd_t cmd, *resp;
37 ipmi_sensor_reading_t *srp;
39 cmd.ic_netfn = IPMI_NETFN_SE;
40 cmd.ic_cmd = IPMI_CMD_GET_SENSOR_READING;
41 cmd.ic_lun = 0;
42 cmd.ic_data = &id;
43 cmd.ic_dlen = sizeof (id);
45 if ((resp = ipmi_send(ihp, &cmd)) == NULL)
46 return (NULL);
49 * The upper half of the state field is optional, so if it's not
50 * present, then set it to zero. We also need to convert to the
51 * native endianness.
53 if (resp->ic_dlen < sizeof (ipmi_sensor_reading_t) - sizeof (uint8_t)) {
54 (void) ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL);
55 return (NULL);
57 srp = resp->ic_data;
59 if (resp->ic_dlen < sizeof (ipmi_sensor_reading_t))
60 (void) memset((char *)srp + resp->ic_dlen, '\0',
61 sizeof (ipmi_sensor_reading_t) - resp->ic_dlen);
63 srp->isr_state = LE_IN16(&srp->isr_state);
64 return (srp);
67 int
68 ipmi_set_sensor_reading(ipmi_handle_t *ihp, ipmi_set_sensor_reading_t *req)
70 ipmi_set_sensor_reading_t realreq;
71 ipmi_cmd_t cmd, *resp;
72 uint16_t tmp;
75 * Convert states to little endian.
77 (void) memcpy(&realreq, req, sizeof (realreq));
79 tmp = LE_IN16(&realreq.iss_assert_state);
80 (void) memcpy(&realreq.iss_assert_state, &tmp, sizeof (tmp));
81 tmp = LE_IN16(&realreq.iss_deassert_state);
82 (void) memcpy(&realreq.iss_deassert_state, &tmp, sizeof (tmp));
84 cmd.ic_netfn = IPMI_NETFN_SE;
85 cmd.ic_cmd = IPMI_CMD_SET_SENSOR_READING;
86 cmd.ic_lun = 0;
87 cmd.ic_data = &realreq;
88 cmd.ic_dlen = sizeof (realreq);
90 if ((resp = ipmi_send(ihp, &cmd)) == NULL)
91 return (-1);
93 if (resp->ic_dlen != 0)
94 return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
96 return (0);