xref: /onnv-gate/usr/src/lib/libipmi/common/ipmi_sensor.c (revision 6726:d01b10854a9d)
13798Seschrock /*
23798Seschrock  * CDDL HEADER START
33798Seschrock  *
43798Seschrock  * The contents of this file are subject to the terms of the
53798Seschrock  * Common Development and Distribution License (the "License").
63798Seschrock  * You may not use this file except in compliance with the License.
73798Seschrock  *
83798Seschrock  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93798Seschrock  * or http://www.opensolaris.org/os/licensing.
103798Seschrock  * See the License for the specific language governing permissions
113798Seschrock  * and limitations under the License.
123798Seschrock  *
133798Seschrock  * When distributing Covered Code, include this CDDL HEADER in each
143798Seschrock  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153798Seschrock  * If applicable, add the following below this CDDL HEADER, with the
163798Seschrock  * fields enclosed by brackets "[]" replaced with your own identifying
173798Seschrock  * information: Portions Copyright [yyyy] [name of copyright owner]
183798Seschrock  *
193798Seschrock  * CDDL HEADER END
203798Seschrock  */
213798Seschrock /*
226360Srobj  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
233798Seschrock  * Use is subject to license terms.
243798Seschrock  */
253798Seschrock 
263798Seschrock #pragma ident	"%Z%%M%	%I%	%E% SMI"
273798Seschrock 
283798Seschrock #include <libipmi.h>
293798Seschrock #include <string.h>
303798Seschrock 
313798Seschrock #include "ipmi_impl.h"
323798Seschrock 
333798Seschrock ipmi_sensor_reading_t *
ipmi_get_sensor_reading(ipmi_handle_t * ihp,uint8_t id)343798Seschrock ipmi_get_sensor_reading(ipmi_handle_t *ihp, uint8_t id)
353798Seschrock {
363798Seschrock 	ipmi_cmd_t cmd, *resp;
373798Seschrock 	ipmi_sensor_reading_t *srp;
383798Seschrock 
393798Seschrock 	cmd.ic_netfn = IPMI_NETFN_SE;
403798Seschrock 	cmd.ic_cmd = IPMI_CMD_GET_SENSOR_READING;
413798Seschrock 	cmd.ic_lun = 0;
423798Seschrock 	cmd.ic_data = &id;
433798Seschrock 	cmd.ic_dlen = sizeof (id);
443798Seschrock 
453798Seschrock 	if ((resp = ipmi_send(ihp, &cmd)) == NULL)
463798Seschrock 		return (NULL);
473798Seschrock 
483798Seschrock 	/*
493798Seschrock 	 * The upper half of the state field is optional, so if it's not
503798Seschrock 	 * present, then set it to zero.  We also need to convert to the
513798Seschrock 	 * native endianness.
523798Seschrock 	 */
533798Seschrock 	if (resp->ic_dlen < sizeof (ipmi_sensor_reading_t) - sizeof (uint8_t)) {
543798Seschrock 		(void) ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL);
553798Seschrock 		return (NULL);
563798Seschrock 	}
573798Seschrock 	srp = resp->ic_data;
583798Seschrock 
593798Seschrock 	if (resp->ic_dlen < sizeof (ipmi_sensor_reading_t))
603798Seschrock 		(void) memset((char *)srp + resp->ic_dlen, '\0',
613798Seschrock 		    sizeof (ipmi_sensor_reading_t) - resp->ic_dlen);
623798Seschrock 
636360Srobj 	srp->isr_state = LE_IN16(&srp->isr_state);
643798Seschrock 	return (srp);
653798Seschrock }
663798Seschrock 
673798Seschrock int
ipmi_set_sensor_reading(ipmi_handle_t * ihp,ipmi_set_sensor_reading_t * req)683798Seschrock ipmi_set_sensor_reading(ipmi_handle_t *ihp, ipmi_set_sensor_reading_t *req)
693798Seschrock {
703798Seschrock 	ipmi_set_sensor_reading_t realreq;
713798Seschrock 	ipmi_cmd_t cmd, *resp;
72*6726Srobj 	uint16_t tmp;
733798Seschrock 
743798Seschrock 	/*
753798Seschrock 	 * Convert states to little endian.
763798Seschrock 	 */
773798Seschrock 	(void) memcpy(&realreq, req, sizeof (realreq));
783798Seschrock 
79*6726Srobj 	tmp = LE_IN16(&realreq.iss_assert_state);
80*6726Srobj 	(void) memcpy(&realreq.iss_assert_state, &tmp, sizeof (tmp));
81*6726Srobj 	tmp = LE_IN16(&realreq.iss_deassert_state);
82*6726Srobj 	(void) memcpy(&realreq.iss_deassert_state, &tmp, sizeof (tmp));
833798Seschrock 
843798Seschrock 	cmd.ic_netfn = IPMI_NETFN_SE;
853798Seschrock 	cmd.ic_cmd = IPMI_CMD_SET_SENSOR_READING;
863798Seschrock 	cmd.ic_lun = 0;
873798Seschrock 	cmd.ic_data = &realreq;
883798Seschrock 	cmd.ic_dlen = sizeof (realreq);
893798Seschrock 
903798Seschrock 	if ((resp = ipmi_send(ihp, &cmd)) == NULL)
913798Seschrock 		return (-1);
923798Seschrock 
933798Seschrock 	if (resp->ic_dlen != 0)
943798Seschrock 		return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
953798Seschrock 
963798Seschrock 	return (0);
973798Seschrock }
98