1 /*
2 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistribution of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistribution in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * Neither the name of Sun Microsystems, Inc. or the names of
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * This software is provided "AS IS," without a warranty of any kind.
20 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
21 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
22 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
23 * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
24 * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
25 * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
26 * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
27 * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
28 * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
29 * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
30 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31 */
32
33 #include <stdio.h>
34 #include <fcntl.h>
35 #include <unistd.h>
36 #include <sys/ioctl.h>
37 #include <errno.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <sys/types.h>
41 #include <sys/stropts.h>
42
43 #include <ipmitool/ipmi.h>
44 #include <ipmitool/ipmi_intf.h>
45
46 #include <sys/lipmi/lipmi_intf.h>
47
48 #define IPMI_LIPMI_DEV "/dev/lipmi"
49
50 extern int verbose;
51
ipmi_lipmi_open(struct ipmi_intf * intf)52 static int ipmi_lipmi_open(struct ipmi_intf * intf)
53 {
54 intf->fd = open(IPMI_LIPMI_DEV, O_RDWR);
55 if (intf->fd < 0) {
56 perror("Could not open lipmi device");
57 return -1;
58 }
59 intf->opened = 1;
60 intf->manufacturer_id = ipmi_get_oem(intf);
61 return intf->fd;
62 }
63
ipmi_lipmi_close(struct ipmi_intf * intf)64 static void ipmi_lipmi_close(struct ipmi_intf * intf)
65 {
66 if (intf && intf->fd >= 0)
67 close(intf->fd);
68 intf->fd = -1;
69 intf->opened = 0;
70 intf->manufacturer_id = IPMI_OEM_UNKNOWN;
71 }
72
ipmi_lipmi_send_cmd(struct ipmi_intf * intf,struct ipmi_rq * req)73 static struct ipmi_rs * ipmi_lipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
74 {
75 struct strioctl istr;
76 static struct lipmi_reqrsp reqrsp;
77 static struct ipmi_rs rsp;
78 static int curr_seq = 0;
79
80 if (!intf || !req)
81 return NULL;
82
83 if (!intf->opened && intf->open && intf->open(intf) < 0)
84 return NULL;
85
86 memset(&reqrsp, 0, sizeof(reqrsp));
87 reqrsp.req.fn = req->msg.netfn;
88 reqrsp.req.lun = 0;
89 reqrsp.req.cmd = req->msg.cmd;
90 reqrsp.req.datalength = req->msg.data_len;
91 memcpy(reqrsp.req.data, req->msg.data, req->msg.data_len);
92 reqrsp.rsp.datalength = RECV_MAX_PAYLOAD_SIZE;
93
94 istr.ic_cmd = IOCTL_IPMI_KCS_ACTION;
95 istr.ic_timout = 0;
96 istr.ic_dp = (char *)&reqrsp;
97 istr.ic_len = sizeof(struct lipmi_reqrsp);
98
99 if (verbose > 1) {
100 printf("LIPMI req.fn : %x\n", reqrsp.req.fn);
101 printf("LIPMI req.lun : %x\n", reqrsp.req.lun);
102 printf("LIPMI req.cmd : %x\n", reqrsp.req.cmd);
103 printf("LIPMI req.datalength : %d\n", reqrsp.req.datalength);
104 }
105
106 if (ioctl(intf->fd, I_STR, &istr) < 0) {
107 perror("LIPMI IOCTL: I_STR");
108 return NULL;
109 }
110
111 memset(&rsp, 0, sizeof(struct ipmi_rs));
112 rsp.ccode = reqrsp.rsp.ccode;
113 rsp.data_len = reqrsp.rsp.datalength;
114
115 if (!rsp.ccode && rsp.data_len)
116 memcpy(rsp.data, reqrsp.rsp.data, rsp.data_len);
117
118 return &rsp;
119 }
120
121 struct ipmi_intf ipmi_lipmi_intf = {
122 name: "lipmi",
123 desc: "Solaris x86 LIPMI Interface",
124 open: ipmi_lipmi_open,
125 close: ipmi_lipmi_close,
126 sendrecv: ipmi_lipmi_send_cmd,
127 target_addr: IPMI_BMC_SLAVE_ADDR,
128 };
129
130