xref: /titanic_52/usr/src/lib/libipmi/common/ipmi_sensor.c (revision e1a24155fa4a9f69c2b1a6759fbe0180645724f0)
19113a79cSeschrock /*
29113a79cSeschrock  * CDDL HEADER START
39113a79cSeschrock  *
49113a79cSeschrock  * The contents of this file are subject to the terms of the
59113a79cSeschrock  * Common Development and Distribution License (the "License").
69113a79cSeschrock  * You may not use this file except in compliance with the License.
79113a79cSeschrock  *
89113a79cSeschrock  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
99113a79cSeschrock  * or http://www.opensolaris.org/os/licensing.
109113a79cSeschrock  * See the License for the specific language governing permissions
119113a79cSeschrock  * and limitations under the License.
129113a79cSeschrock  *
139113a79cSeschrock  * When distributing Covered Code, include this CDDL HEADER in each
149113a79cSeschrock  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
159113a79cSeschrock  * If applicable, add the following below this CDDL HEADER, with the
169113a79cSeschrock  * fields enclosed by brackets "[]" replaced with your own identifying
179113a79cSeschrock  * information: Portions Copyright [yyyy] [name of copyright owner]
189113a79cSeschrock  *
199113a79cSeschrock  * CDDL HEADER END
209113a79cSeschrock  */
219113a79cSeschrock /*
22918a0d8aSrobj  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
239113a79cSeschrock  * Use is subject to license terms.
249113a79cSeschrock  */
259113a79cSeschrock 
269113a79cSeschrock #pragma ident	"%Z%%M%	%I%	%E% SMI"
279113a79cSeschrock 
289113a79cSeschrock #include <libipmi.h>
299113a79cSeschrock #include <string.h>
309113a79cSeschrock 
319113a79cSeschrock #include "ipmi_impl.h"
329113a79cSeschrock 
339113a79cSeschrock ipmi_sensor_reading_t *
349113a79cSeschrock ipmi_get_sensor_reading(ipmi_handle_t *ihp, uint8_t id)
359113a79cSeschrock {
369113a79cSeschrock 	ipmi_cmd_t cmd, *resp;
379113a79cSeschrock 	ipmi_sensor_reading_t *srp;
389113a79cSeschrock 
399113a79cSeschrock 	cmd.ic_netfn = IPMI_NETFN_SE;
409113a79cSeschrock 	cmd.ic_cmd = IPMI_CMD_GET_SENSOR_READING;
419113a79cSeschrock 	cmd.ic_lun = 0;
429113a79cSeschrock 	cmd.ic_data = &id;
439113a79cSeschrock 	cmd.ic_dlen = sizeof (id);
449113a79cSeschrock 
459113a79cSeschrock 	if ((resp = ipmi_send(ihp, &cmd)) == NULL)
469113a79cSeschrock 		return (NULL);
479113a79cSeschrock 
489113a79cSeschrock 	/*
499113a79cSeschrock 	 * The upper half of the state field is optional, so if it's not
509113a79cSeschrock 	 * present, then set it to zero.  We also need to convert to the
519113a79cSeschrock 	 * native endianness.
529113a79cSeschrock 	 */
539113a79cSeschrock 	if (resp->ic_dlen < sizeof (ipmi_sensor_reading_t) - sizeof (uint8_t)) {
549113a79cSeschrock 		(void) ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL);
559113a79cSeschrock 		return (NULL);
569113a79cSeschrock 	}
579113a79cSeschrock 	srp = resp->ic_data;
589113a79cSeschrock 
599113a79cSeschrock 	if (resp->ic_dlen < sizeof (ipmi_sensor_reading_t))
609113a79cSeschrock 		(void) memset((char *)srp + resp->ic_dlen, '\0',
619113a79cSeschrock 		    sizeof (ipmi_sensor_reading_t) - resp->ic_dlen);
629113a79cSeschrock 
63918a0d8aSrobj 	srp->isr_state = LE_IN16(&srp->isr_state);
649113a79cSeschrock 	return (srp);
659113a79cSeschrock }
669113a79cSeschrock 
679113a79cSeschrock int
689113a79cSeschrock ipmi_set_sensor_reading(ipmi_handle_t *ihp, ipmi_set_sensor_reading_t *req)
699113a79cSeschrock {
709113a79cSeschrock 	ipmi_set_sensor_reading_t realreq;
719113a79cSeschrock 	ipmi_cmd_t cmd, *resp;
72*e1a24155Srobj 	uint16_t tmp;
739113a79cSeschrock 
749113a79cSeschrock 	/*
759113a79cSeschrock 	 * Convert states to little endian.
769113a79cSeschrock 	 */
779113a79cSeschrock 	(void) memcpy(&realreq, req, sizeof (realreq));
789113a79cSeschrock 
79*e1a24155Srobj 	tmp = LE_IN16(&realreq.iss_assert_state);
80*e1a24155Srobj 	(void) memcpy(&realreq.iss_assert_state, &tmp, sizeof (tmp));
81*e1a24155Srobj 	tmp = LE_IN16(&realreq.iss_deassert_state);
82*e1a24155Srobj 	(void) memcpy(&realreq.iss_deassert_state, &tmp, sizeof (tmp));
839113a79cSeschrock 
849113a79cSeschrock 	cmd.ic_netfn = IPMI_NETFN_SE;
859113a79cSeschrock 	cmd.ic_cmd = IPMI_CMD_SET_SENSOR_READING;
869113a79cSeschrock 	cmd.ic_lun = 0;
879113a79cSeschrock 	cmd.ic_data = &realreq;
889113a79cSeschrock 	cmd.ic_dlen = sizeof (realreq);
899113a79cSeschrock 
909113a79cSeschrock 	if ((resp = ipmi_send(ihp, &cmd)) == NULL)
919113a79cSeschrock 		return (-1);
929113a79cSeschrock 
939113a79cSeschrock 	if (resp->ic_dlen != 0)
949113a79cSeschrock 		return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL));
959113a79cSeschrock 
969113a79cSeschrock 	return (0);
979113a79cSeschrock }
98