~ubuntu-branches/ubuntu/maverick/ipmitool/maverick

« back to all changes in this revision

Viewing changes to src/plugins/lipmi/lipmi.c

  • Committer: Bazaar Package Importer
  • Author(s): Petter Reinholdtsen
  • Date: 2005-04-07 01:18:44 UTC
  • Revision ID: james.westby@ubuntu.com-20050407011844-a1b206z5iefiu5vi
Tags: upstream-1.8.1
ImportĀ upstreamĀ versionĀ 1.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 * You acknowledge that this software is not designed or intended for use
 
33
 * in the design, construction, operation or maintenance of any nuclear
 
34
 * facility.
 
35
 */
 
36
 
 
37
#include <stdio.h>
 
38
#include <fcntl.h>
 
39
#include <unistd.h>
 
40
#include <sys/ioctl.h>
 
41
#include <errno.h>
 
42
#include <stdlib.h>
 
43
#include <string.h>
 
44
#include <sys/types.h>
 
45
#include <sys/stropts.h>
 
46
 
 
47
#include <ipmitool/ipmi.h>
 
48
#include <ipmitool/ipmi_intf.h>
 
49
 
 
50
#include <sys/lipmi/lipmi_intf.h>
 
51
 
 
52
#define IPMI_LIPMI_DEV          "/dev/lipmi"
 
53
 
 
54
extern int verbose;
 
55
 
 
56
static int ipmi_lipmi_open(struct ipmi_intf * intf)
 
57
{
 
58
        intf->fd = open(IPMI_LIPMI_DEV, O_RDWR);
 
59
        if (intf->fd < 0) {
 
60
                perror("Could not open lipmi device");
 
61
                return -1;
 
62
        }
 
63
        intf->opened = 1;
 
64
        return intf->fd;
 
65
}
 
66
 
 
67
static void ipmi_lipmi_close(struct ipmi_intf * intf)
 
68
{
 
69
        if (intf && intf->fd >= 0)
 
70
                close(intf->fd);
 
71
        intf->fd = -1;
 
72
        intf->opened = 0;
 
73
}
 
74
 
 
75
static struct ipmi_rs * ipmi_lipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
 
76
{
 
77
        struct strioctl istr;
 
78
        static struct lipmi_reqrsp reqrsp;
 
79
        static struct ipmi_rs rsp;      
 
80
        static int curr_seq = 0;
 
81
 
 
82
        if (!intf || !req)
 
83
                return NULL;
 
84
 
 
85
        if (!intf->opened && intf->open && intf->open(intf) < 0)
 
86
                return NULL;
 
87
 
 
88
        memset(&reqrsp, 0, sizeof(reqrsp));
 
89
        reqrsp.req.fn = req->msg.netfn;
 
90
        reqrsp.req.lun = 0;
 
91
        reqrsp.req.cmd = req->msg.cmd;
 
92
        reqrsp.req.datalength = req->msg.data_len;
 
93
        memcpy(reqrsp.req.data, req->msg.data, req->msg.data_len);
 
94
        reqrsp.rsp.datalength = RECV_MAX_PAYLOAD_SIZE;
 
95
 
 
96
        istr.ic_cmd = IOCTL_IPMI_KCS_ACTION;
 
97
        istr.ic_timout = 0;
 
98
        istr.ic_dp = (char *)&reqrsp;
 
99
        istr.ic_len = sizeof(struct lipmi_reqrsp);
 
100
 
 
101
        if (verbose > 1) {
 
102
                printf("LIPMI req.fn         : %x\n", reqrsp.req.fn);
 
103
                printf("LIPMI req.lun        : %x\n", reqrsp.req.lun);
 
104
                printf("LIPMI req.cmd        : %x\n", reqrsp.req.cmd);
 
105
                printf("LIPMI req.datalength : %d\n", reqrsp.req.datalength);
 
106
        }
 
107
 
 
108
        if (ioctl(intf->fd, I_STR, &istr) < 0) {
 
109
                perror("LIPMI IOCTL: I_STR");
 
110
                return NULL;
 
111
        }
 
112
 
 
113
        memset(&rsp, 0, sizeof(struct ipmi_rs));
 
114
        rsp.ccode = reqrsp.rsp.ccode;
 
115
        rsp.data_len = reqrsp.rsp.datalength;
 
116
 
 
117
        if (!rsp.ccode && rsp.data_len)
 
118
                memcpy(rsp.data, reqrsp.rsp.data, rsp.data_len);
 
119
 
 
120
        return &rsp;
 
121
}
 
122
 
 
123
struct ipmi_intf ipmi_lipmi_intf = {
 
124
        name:           "lipmi",
 
125
        desc:           "Solaris x86 LIPMI Interface",
 
126
        open:           ipmi_lipmi_open,
 
127
        close:          ipmi_lipmi_close,
 
128
        sendrecv:       ipmi_lipmi_send_cmd,
 
129
        target_addr:    IPMI_BMC_SLAVE_ADDR,
 
130
};
 
131