1 /* 2 * CDDL HEADER START 3 * 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. 7 * 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. 12 * 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] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #pragma ident "%Z%%M% %I% %E% SMI" 27 28 #include <libipmi.h> 29 #include <string.h> 30 31 #include "ipmi_impl.h" 32 33 ipmi_sensor_reading_t * 34 ipmi_get_sensor_reading(ipmi_handle_t *ihp, uint8_t id) 35 { 36 ipmi_cmd_t cmd, *resp; 37 ipmi_sensor_reading_t *srp; 38 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); 44 45 if ((resp = ipmi_send(ihp, &cmd)) == NULL) 46 return (NULL); 47 48 /* 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. 52 */ 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); 56 } 57 srp = resp->ic_data; 58 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); 62 63 srp->isr_state = LE_IN16(&srp->isr_state); 64 return (srp); 65 } 66 67 int 68 ipmi_set_sensor_reading(ipmi_handle_t *ihp, ipmi_set_sensor_reading_t *req) 69 { 70 ipmi_set_sensor_reading_t realreq; 71 ipmi_cmd_t cmd, *resp; 72 73 /* 74 * Convert states to little endian. 75 */ 76 (void) memcpy(&realreq, req, sizeof (realreq)); 77 78 realreq.iss_assert_state = LE_IN16(&realreq.iss_assert_state); 79 realreq.iss_deassert_state = LE_IN16(&realreq.iss_deassert_state); 80 81 cmd.ic_netfn = IPMI_NETFN_SE; 82 cmd.ic_cmd = IPMI_CMD_SET_SENSOR_READING; 83 cmd.ic_lun = 0; 84 cmd.ic_data = &realreq; 85 cmd.ic_dlen = sizeof (realreq); 86 87 if ((resp = ipmi_send(ihp, &cmd)) == NULL) 88 return (-1); 89 90 if (resp->ic_dlen != 0) 91 return (ipmi_set_error(ihp, EIPMI_BAD_RESPONSE_LENGTH, NULL)); 92 93 return (0); 94 } 95