|
Packit |
d14fb6 |
/*
|
|
Packit |
d14fb6 |
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
|
|
Packit |
d14fb6 |
*
|
|
Packit |
d14fb6 |
* Redistribution and use in source and binary forms, with or without
|
|
Packit |
d14fb6 |
* modification, are permitted provided that the following conditions
|
|
Packit |
d14fb6 |
* are met:
|
|
Packit |
d14fb6 |
*
|
|
Packit |
d14fb6 |
* Redistribution of source code must retain the above copyright
|
|
Packit |
d14fb6 |
* notice, this list of conditions and the following disclaimer.
|
|
Packit |
d14fb6 |
*
|
|
Packit |
d14fb6 |
* Redistribution in binary form must reproduce the above copyright
|
|
Packit |
d14fb6 |
* notice, this list of conditions and the following disclaimer in the
|
|
Packit |
d14fb6 |
* documentation and/or other materials provided with the distribution.
|
|
Packit |
d14fb6 |
*
|
|
Packit |
d14fb6 |
* Neither the name of Sun Microsystems, Inc. or the names of
|
|
Packit |
d14fb6 |
* contributors may be used to endorse or promote products derived
|
|
Packit |
d14fb6 |
* from this software without specific prior written permission.
|
|
Packit |
d14fb6 |
*
|
|
Packit |
d14fb6 |
* This software is provided "AS IS," without a warranty of any kind.
|
|
Packit |
d14fb6 |
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
|
|
Packit |
d14fb6 |
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
|
|
Packit |
d14fb6 |
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
|
|
Packit |
d14fb6 |
* SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
|
|
Packit |
d14fb6 |
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
|
|
Packit |
d14fb6 |
* OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
|
|
Packit |
d14fb6 |
* SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
|
|
Packit |
d14fb6 |
* OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
|
|
Packit |
d14fb6 |
* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
|
|
Packit |
d14fb6 |
* LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
|
|
Packit |
d14fb6 |
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
Packit |
d14fb6 |
*/
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
#include <stdio.h>
|
|
Packit |
d14fb6 |
#include <fcntl.h>
|
|
Packit |
d14fb6 |
#include <unistd.h>
|
|
Packit |
d14fb6 |
#include <sys/ioctl.h>
|
|
Packit |
d14fb6 |
#include <errno.h>
|
|
Packit |
d14fb6 |
#include <stdlib.h>
|
|
Packit |
d14fb6 |
#include <string.h>
|
|
Packit |
d14fb6 |
#include <sys/types.h>
|
|
Packit |
d14fb6 |
#include <sys/stropts.h>
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
#include <ipmitool/ipmi.h>
|
|
Packit |
d14fb6 |
#include <ipmitool/ipmi_intf.h>
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
#include <sys/lipmi/lipmi_intf.h>
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
#define IPMI_LIPMI_DEV "/dev/lipmi"
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
extern int verbose;
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
static int ipmi_lipmi_open(struct ipmi_intf * intf)
|
|
Packit |
d14fb6 |
{
|
|
Packit |
d14fb6 |
intf->fd = open(IPMI_LIPMI_DEV, O_RDWR);
|
|
Packit |
d14fb6 |
if (intf->fd < 0) {
|
|
Packit |
d14fb6 |
perror("Could not open lipmi device");
|
|
Packit |
d14fb6 |
return -1;
|
|
Packit |
d14fb6 |
}
|
|
Packit |
d14fb6 |
intf->opened = 1;
|
|
Packit |
d14fb6 |
intf->manufacturer_id = ipmi_get_oem(intf);
|
|
Packit |
d14fb6 |
return intf->fd;
|
|
Packit |
d14fb6 |
}
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
static void ipmi_lipmi_close(struct ipmi_intf * intf)
|
|
Packit |
d14fb6 |
{
|
|
Packit |
d14fb6 |
if (intf && intf->fd >= 0)
|
|
Packit |
d14fb6 |
close(intf->fd);
|
|
Packit |
d14fb6 |
intf->fd = -1;
|
|
Packit |
d14fb6 |
intf->opened = 0;
|
|
Packit |
d14fb6 |
intf->manufacturer_id = IPMI_OEM_UNKNOWN;
|
|
Packit |
d14fb6 |
}
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
static struct ipmi_rs * ipmi_lipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
|
|
Packit |
d14fb6 |
{
|
|
Packit |
d14fb6 |
struct strioctl istr;
|
|
Packit |
d14fb6 |
static struct lipmi_reqrsp reqrsp;
|
|
Packit |
d14fb6 |
static struct ipmi_rs rsp;
|
|
Packit |
d14fb6 |
static int curr_seq = 0;
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
if (!intf || !req)
|
|
Packit |
d14fb6 |
return NULL;
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
if (!intf->opened && intf->open && intf->open(intf) < 0)
|
|
Packit |
d14fb6 |
return NULL;
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
memset(&reqrsp, 0, sizeof(reqrsp));
|
|
Packit |
d14fb6 |
reqrsp.req.fn = req->msg.netfn;
|
|
Packit |
d14fb6 |
reqrsp.req.lun = 0;
|
|
Packit |
d14fb6 |
reqrsp.req.cmd = req->msg.cmd;
|
|
Packit |
d14fb6 |
reqrsp.req.datalength = req->msg.data_len;
|
|
Packit |
d14fb6 |
memcpy(reqrsp.req.data, req->msg.data, req->msg.data_len);
|
|
Packit |
d14fb6 |
reqrsp.rsp.datalength = RECV_MAX_PAYLOAD_SIZE;
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
istr.ic_cmd = IOCTL_IPMI_KCS_ACTION;
|
|
Packit |
d14fb6 |
istr.ic_timout = 0;
|
|
Packit |
d14fb6 |
istr.ic_dp = (char *)&reqrsp;
|
|
Packit |
d14fb6 |
istr.ic_len = sizeof(struct lipmi_reqrsp);
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
if (verbose > 1) {
|
|
Packit |
d14fb6 |
printf("LIPMI req.fn : %x\n", reqrsp.req.fn);
|
|
Packit |
d14fb6 |
printf("LIPMI req.lun : %x\n", reqrsp.req.lun);
|
|
Packit |
d14fb6 |
printf("LIPMI req.cmd : %x\n", reqrsp.req.cmd);
|
|
Packit |
d14fb6 |
printf("LIPMI req.datalength : %d\n", reqrsp.req.datalength);
|
|
Packit |
d14fb6 |
}
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
if (ioctl(intf->fd, I_STR, &istr) < 0) {
|
|
Packit |
d14fb6 |
perror("LIPMI IOCTL: I_STR");
|
|
Packit |
d14fb6 |
return NULL;
|
|
Packit |
d14fb6 |
}
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
memset(&rsp, 0, sizeof(struct ipmi_rs));
|
|
Packit |
d14fb6 |
rsp.ccode = reqrsp.rsp.ccode;
|
|
Packit |
d14fb6 |
rsp.data_len = reqrsp.rsp.datalength;
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
if (!rsp.ccode && rsp.data_len)
|
|
Packit |
d14fb6 |
memcpy(rsp.data, reqrsp.rsp.data, rsp.data_len);
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
return &rsp;
|
|
Packit |
d14fb6 |
}
|
|
Packit |
d14fb6 |
|
|
Packit |
d14fb6 |
struct ipmi_intf ipmi_lipmi_intf = {
|
|
Packit |
d14fb6 |
name: "lipmi",
|
|
Packit |
d14fb6 |
desc: "Solaris x86 LIPMI Interface",
|
|
Packit |
d14fb6 |
open: ipmi_lipmi_open,
|
|
Packit |
d14fb6 |
close: ipmi_lipmi_close,
|
|
Packit |
d14fb6 |
sendrecv: ipmi_lipmi_send_cmd,
|
|
Packit |
d14fb6 |
target_addr: IPMI_BMC_SLAVE_ADDR,
|
|
Packit |
d14fb6 |
};
|
|
Packit |
d14fb6 |
|