summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Venture <venture@google.com>2018-11-26 10:26:25 -0800
committerAlexander Amelkin <mocbuhtig@amelkin.msk.ru>2019-02-20 18:29:09 +0300
commit3bfa1da201997efb5d728b6d1bcbc0825175b5b2 (patch)
tree8a92b60f0d2e3ac1291ceec33d38a066438da193
parent08348f1b72de27681549894f7a506674fba19ff2 (diff)
downloadipmitool-3bfa1da201997efb5d728b6d1bcbc0825175b5b2.tar.gz
open: fix whitespace
Apply whitespace fixes via clang-format-6.0 to src/plugins/open/open.c to cleanup spaces and fixup line lengths, etc. Signed-off-by: Patrick Venture <venture@google.com>
-rw-r--r--src/plugins/open/open.c369
1 files changed, 190 insertions, 179 deletions
diff --git a/src/plugins/open/open.c b/src/plugins/open/open.c
index 63f3624..4fdabeb 100644
--- a/src/plugins/open/open.c
+++ b/src/plugins/open/open.c
@@ -1,21 +1,21 @@
/*
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
- *
+ *
* Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* Neither the name of Sun Microsystems, Inc. or the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -88,8 +88,9 @@
extern int verbose;
-static int
-ipmi_openipmi_open(struct ipmi_intf * intf)
+static
+int
+ipmi_openipmi_open(struct ipmi_intf *intf)
{
char ipmi_dev[16];
char ipmi_devfs[16];
@@ -112,7 +113,7 @@ ipmi_openipmi_open(struct ipmi_intf * intf)
}
if (intf->fd < 0) {
lperror(LOG_ERR, "Could not open device at %s or %s or %s",
- ipmi_dev, ipmi_devfs , ipmi_devfs2);
+ ipmi_dev, ipmi_devfs, ipmi_devfs2);
return -1;
}
}
@@ -123,23 +124,24 @@ ipmi_openipmi_open(struct ipmi_intf * intf)
lperror(LOG_ERR, "Could not enable event receiver");
return -1;
}
-
+
intf->opened = 1;
- /* This is never set to 0, the default is IPMI_BMC_SLAVE_ADDR */
+ /* This is never set to 0, the default is IPMI_BMC_SLAVE_ADDR */
if (intf->my_addr != 0) {
if (intf->set_my_addr(intf, intf->my_addr) < 0) {
lperror(LOG_ERR, "Could not set IPMB address");
return -1;
}
- lprintf(LOG_DEBUG, "Set IPMB address to 0x%x",
- intf->my_addr );
+ lprintf(LOG_DEBUG, "Set IPMB address to 0x%x", intf->my_addr);
}
intf->manufacturer_id = ipmi_get_oem(intf);
return intf->fd;
}
-static int
+
+static
+int
ipmi_openipmi_set_my_addr(struct ipmi_intf *intf, uint8_t addr)
{
unsigned int a = addr;
@@ -151,8 +153,9 @@ ipmi_openipmi_set_my_addr(struct ipmi_intf *intf, uint8_t addr)
return 0;
}
-static void
-ipmi_openipmi_close(struct ipmi_intf * intf)
+static
+void
+ipmi_openipmi_close(struct ipmi_intf *intf)
{
if (intf->fd >= 0) {
close(intf->fd);
@@ -163,8 +166,9 @@ ipmi_openipmi_close(struct ipmi_intf * intf)
intf->manufacturer_id = IPMI_OEM_UNKNOWN;
}
-static struct ipmi_rs *
-ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
+static
+struct ipmi_rs *
+ipmi_openipmi_send_cmd(struct ipmi_intf *intf, struct ipmi_rq *req)
{
struct ipmi_recv recv;
struct ipmi_addr addr;
@@ -181,11 +185,10 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
static int curr_seq = 0;
fd_set rset;
- uint8_t * data = NULL;
+ uint8_t *data = NULL;
int data_len = 0;
int retval = 0;
-
if (!intf || !req)
return NULL;
@@ -197,12 +200,11 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
if (verbose > 2) {
fprintf(stderr, "OpenIPMI Request Message Header:\n");
- fprintf(stderr, " netfn = 0x%x\n", req->msg.netfn );
+ fprintf(stderr, " netfn = 0x%x\n", req->msg.netfn);
fprintf(stderr, " cmd = 0x%x\n", req->msg.cmd);
- printbuf(req->msg.data, req->msg.data_len, "OpenIPMI Request Message Data");
+ printbuf(req->msg.data, req->msg.data_len,
+ "OpenIPMI Request Message Data");
}
-
-
/*
* setup and send message
@@ -211,111 +213,116 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
memset(&_req, 0, sizeof(struct ipmi_req));
if (intf->target_addr != 0 &&
- intf->target_addr != intf->my_addr) {
+ intf->target_addr != intf->my_addr)
+ {
/* use IPMB address if needed */
ipmb_addr.slave_addr = intf->target_addr;
ipmb_addr.lun = req->msg.lun;
- lprintf(LOG_DEBUG, "Sending request 0x%x to "
- "IPMB target @ 0x%x:0x%x (from 0x%x)",
- req->msg.cmd,
- intf->target_addr,intf->target_channel, intf->my_addr);
-
- if(intf->transit_addr != 0 && intf->transit_addr != intf->my_addr) {
- uint8_t index = 0;
-
- lprintf(LOG_DEBUG, "Encapsulating data sent to "
- "end target [0x%02x,0x%02x] using transit [0x%02x,0x%02x] from 0x%x ",
- (0x40 | intf->target_channel),
- intf->target_addr,
- intf->transit_channel,
- intf->transit_addr,
- intf->my_addr
- );
-
- /* Convert Message to 'Send Message' */
- /* Supplied req : req , internal req : _req */
-
- if (verbose > 4) {
- fprintf(stderr, "Converting message:\n");
- fprintf(stderr, " netfn = 0x%x\n", req->msg.netfn );
- fprintf(stderr, " cmd = 0x%x\n", req->msg.cmd);
- if (req->msg.data && req->msg.data_len) {
- fprintf(stderr, " data_len = %d\n", req->msg.data_len);
- fprintf(stderr, " data = %s\n",
- buf2str(req->msg.data,req->msg.data_len));
- }
- }
-
- /* Modify target address to use 'transit' instead */
- ipmb_addr.slave_addr = intf->transit_addr;
- ipmb_addr.channel = intf->transit_channel;
-
- /* FIXME backup "My address" */
- data_len = req->msg.data_len + 8;
- data = malloc(data_len);
- if (!data) {
- lprintf(LOG_ERR, "ipmitool: malloc failure");
- return NULL;
- }
-
- memset(data, 0, data_len);
-
- data[index++] = (0x40|intf->target_channel);
- data[index++] = intf->target_addr;
- data[index++] = ( req->msg.netfn << 2 ) | req->msg.lun ;
- data[index++] = ipmi_csum(data+1, 2);
- data[index++] = 0xFF; /* normally 0x20 , overwritten by IPMC */
- data[index++] = ( (0) << 2) | 0 ; /* FIXME */
- data[index++] = req->msg.cmd;
- memcpy( (data+index) , req->msg.data, req->msg.data_len);
- index += req->msg.data_len;
- data[index++] = ipmi_csum( (data+4),(req->msg.data_len + 3) );
-
- if (verbose > 4) {
- fprintf(stderr, "Encapsulated message:\n");
- fprintf(stderr, " netfn = 0x%x\n", IPMI_NETFN_APP );
- fprintf(stderr, " cmd = 0x%x\n", 0x34 );
- if (data && data_len) {
- fprintf(stderr, " data_len = %d\n", data_len);
- fprintf(stderr, " data = %s\n",
- buf2str(data,data_len));
- }
- }
+ lprintf(LOG_DEBUG,
+ "Sending request 0x%x to "
+ "IPMB target @ 0x%x:0x%x (from 0x%x)",
+ req->msg.cmd, intf->target_addr, intf->target_channel,
+ intf->my_addr);
+
+ if (intf->transit_addr != 0 &&
+ intf->transit_addr != intf->my_addr)
+ {
+ uint8_t index = 0;
+
+ lprintf(LOG_DEBUG,
+ "Encapsulating data sent to "
+ "end target [0x%02x,0x%02x] using "
+ "transit [0x%02x,0x%02x] from 0x%x ",
+ (0x40 | intf->target_channel),
+ intf->target_addr,
+ intf->transit_channel,
+ intf->transit_addr,
+ intf->my_addr);
+
+ /* Convert Message to 'Send Message' */
+ /* Supplied req : req , internal req : _req */
+
+ if (verbose > 4) {
+ fprintf(stderr, "Converting message:\n");
+ fprintf(stderr, " netfn = 0x%x\n", req->msg.netfn);
+ fprintf(stderr, " cmd = 0x%x\n", req->msg.cmd);
+ if (req->msg.data && req->msg.data_len) {
+ fprintf(stderr, " data_len = %d\n", req->msg.data_len);
+ fprintf(stderr, " data = %s\n",
+ buf2str(req->msg.data, req->msg.data_len));
+ }
+ }
+
+ /* Modify target address to use 'transit' instead */
+ ipmb_addr.slave_addr = intf->transit_addr;
+ ipmb_addr.channel = intf->transit_channel;
+
+ /* FIXME backup "My address" */
+ data_len = req->msg.data_len + 8;
+ data = malloc(data_len);
+ if (!data) {
+ lprintf(LOG_ERR, "ipmitool: malloc failure");
+ return NULL;
+ }
+
+ memset(data, 0, data_len);
+
+ data[index++] = (0x40 | intf->target_channel);
+ data[index++] = intf->target_addr;
+ data[index++] = (req->msg.netfn << 2) | req->msg.lun;
+ data[index++] = ipmi_csum(data + 1, 2);
+ data[index++] = 0xFF; /* normally 0x20 , overwritten by IPMC */
+ data[index++] = ((0) << 2) | 0; /* FIXME */
+ data[index++] = req->msg.cmd;
+ memcpy((data + index), req->msg.data, req->msg.data_len);
+ index += req->msg.data_len;
+ data[index++] = ipmi_csum((data + 4), (req->msg.data_len + 3));
+
+ if (verbose > 4) {
+ fprintf(stderr, "Encapsulated message:\n");
+ fprintf(stderr, " netfn = 0x%x\n", IPMI_NETFN_APP);
+ fprintf(stderr, " cmd = 0x%x\n", 0x34);
+ if (data && data_len) {
+ fprintf(stderr, " data_len = %d\n", data_len);
+ fprintf(stderr, " data = %s\n",
+ buf2str(data, data_len));
+ }
+ }
}
- _req.addr = (unsigned char *) &ipmb_addr;
+ _req.addr = (unsigned char *)&ipmb_addr;
_req.addr_len = sizeof(ipmb_addr);
} else {
- /* otherwise use system interface */
- lprintf(LOG_DEBUG+2, "Sending request 0x%x to "
- "System Interface", req->msg.cmd);
- bmc_addr.lun = req->msg.lun;
- _req.addr = (unsigned char *) &bmc_addr;
- _req.addr_len = sizeof(bmc_addr);
+ /* otherwise use system interface */
+ lprintf(LOG_DEBUG + 2, "Sending request 0x%x to System Interface",
+ req->msg.cmd);
+ bmc_addr.lun = req->msg.lun;
+ _req.addr = (unsigned char *)&bmc_addr;
+ _req.addr_len = sizeof(bmc_addr);
}
_req.msgid = curr_seq++;
/* In case of a bridge request */
if (data && data_len != 0) {
- _req.msg.data = data;
- _req.msg.data_len = data_len;
- _req.msg.netfn = IPMI_NETFN_APP;
- _req.msg.cmd = 0x34;
+ _req.msg.data = data;
+ _req.msg.data_len = data_len;
+ _req.msg.netfn = IPMI_NETFN_APP;
+ _req.msg.cmd = 0x34;
} else {
- _req.msg.data = req->msg.data;
- _req.msg.data_len = req->msg.data_len;
- _req.msg.netfn = req->msg.netfn;
- _req.msg.cmd = req->msg.cmd;
+ _req.msg.data = req->msg.data;
+ _req.msg.data_len = req->msg.data_len;
+ _req.msg.netfn = req->msg.netfn;
+ _req.msg.cmd = req->msg.cmd;
}
-
+
if (ioctl(intf->fd, IPMICTL_SEND_COMMAND, &_req) < 0) {
- lperror(LOG_ERR, "Unable to send command");
- if (data) {
- free(data);
- data = NULL;
- }
- return NULL;
+ lperror(LOG_ERR, "Unable to send command");
+ if (data) {
+ free(data);
+ data = NULL;
+ }
+ return NULL;
}
/*
@@ -323,11 +330,11 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
*/
if (intf->noanswer) {
- if (data) {
- free(data);
- data = NULL;
- }
- return NULL;
+ if (data) {
+ free(data);
+ data = NULL;
+ }
+ return NULL;
}
FD_ZERO(&rset);
@@ -335,15 +342,15 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
read_timeout.tv_sec = IPMI_OPENIPMI_READ_TIMEOUT;
read_timeout.tv_usec = 0;
do {
- retval = select(intf->fd+1, &rset, NULL, NULL, &read_timeout);
+ retval = select(intf->fd + 1, &rset, NULL, NULL, &read_timeout);
} while (retval < 0 && errno == EINTR);
if (retval < 0) {
- lperror(LOG_ERR, "I/O Error");
- if (data) {
- free(data);
- data = NULL;
- }
- return NULL;
+ lperror(LOG_ERR, "I/O Error");
+ if (data) {
+ free(data);
+ data = NULL;
+ }
+ return NULL;
} else if (retval == 0) {
lprintf(LOG_ERR, "No data available");
if (data) {
@@ -353,71 +360,74 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
return NULL;
}
if (FD_ISSET(intf->fd, &rset) == 0) {
- lprintf(LOG_ERR, "No data available");
- if (data) {
- free(data);
- data = NULL;
- }
- return NULL;
+ lprintf(LOG_ERR, "No data available");
+ if (data) {
+ free(data);
+ data = NULL;
+ }
+ return NULL;
}
- recv.addr = (unsigned char *) &addr;
+ recv.addr = (unsigned char *)&addr;
recv.addr_len = sizeof(addr);
recv.msg.data = rsp.data;
recv.msg.data_len = sizeof(rsp.data);
/* get data */
if (ioctl(intf->fd, IPMICTL_RECEIVE_MSG_TRUNC, &recv) < 0) {
- lperror(LOG_ERR, "Error receiving message");
- if (errno != EMSGSIZE) {
- if (data) {
- free(data);
- data = NULL;
- }
- return NULL;
- }
+ lperror(LOG_ERR, "Error receiving message");
+ if (errno != EMSGSIZE) {
+ if (data) {
+ free(data);
+ data = NULL;
+ }
+ return NULL;
+ }
}
if (verbose > 4) {
- fprintf(stderr, "Got message:");
- fprintf(stderr, " type = %d\n", recv.recv_type);
- fprintf(stderr, " channel = 0x%x\n", addr.channel);
- fprintf(stderr, " msgid = %ld\n", recv.msgid);
- fprintf(stderr, " netfn = 0x%x\n", recv.msg.netfn);
- fprintf(stderr, " cmd = 0x%x\n", recv.msg.cmd);
- if (recv.msg.data && recv.msg.data_len) {
- fprintf(stderr, " data_len = %d\n", recv.msg.data_len);
- fprintf(stderr, " data = %s\n",
- buf2str(recv.msg.data, recv.msg.data_len));
- }
+ fprintf(stderr, "Got message:");
+ fprintf(stderr, " type = %d\n", recv.recv_type);
+ fprintf(stderr, " channel = 0x%x\n", addr.channel);
+ fprintf(stderr, " msgid = %ld\n", recv.msgid);
+ fprintf(stderr, " netfn = 0x%x\n", recv.msg.netfn);
+ fprintf(stderr, " cmd = 0x%x\n", recv.msg.cmd);
+ if (recv.msg.data && recv.msg.data_len) {
+ fprintf(stderr, " data_len = %d\n", recv.msg.data_len);
+ fprintf(stderr, " data = %s\n",
+ buf2str(recv.msg.data, recv.msg.data_len));
+ }
}
- if(intf->transit_addr != 0 && intf->transit_addr != intf->my_addr) {
- /* ipmb_addr.transit_slave_addr = intf->transit_addr; */
- lprintf(LOG_DEBUG, "Decapsulating data received from transit "
- "IPMB target @ 0x%x", intf->transit_addr);
-
- /* comp code */
- /* Check data */
-
- if( recv.msg.data[0] == 0 ) {
- recv.msg.netfn = recv.msg.data[2] >> 2;
- recv.msg.cmd = recv.msg.data[6];
-
- recv.msg.data = memmove(recv.msg.data ,recv.msg.data+7 , recv.msg.data_len - 7);
- recv.msg.data_len -=8;
-
- if (verbose > 4) {
- fprintf(stderr, "Decapsulated message:\n");
- fprintf(stderr, " netfn = 0x%x\n", recv.msg.netfn );
- fprintf(stderr, " cmd = 0x%x\n", recv.msg.cmd);
- if (recv.msg.data && recv.msg.data_len) {
- fprintf(stderr, " data_len = %d\n", recv.msg.data_len);
- fprintf(stderr, " data = %s\n",
- buf2str(recv.msg.data,recv.msg.data_len));
- }
- }
- }
+ if (intf->transit_addr != 0 && intf->transit_addr != intf->my_addr) {
+ /* ipmb_addr.transit_slave_addr = intf->transit_addr; */
+ lprintf(LOG_DEBUG,
+ "Decapsulating data received from transit "
+ "IPMB target @ 0x%x",
+ intf->transit_addr);
+
+ /* comp code */
+ /* Check data */
+
+ if (recv.msg.data[0] == 0) {
+ recv.msg.netfn = recv.msg.data[2] >> 2;
+ recv.msg.cmd = recv.msg.data[6];
+
+ recv.msg.data = memmove(recv.msg.data, recv.msg.data + 7,
+ recv.msg.data_len - 7);
+ recv.msg.data_len -= 8;
+
+ if (verbose > 4) {
+ fprintf(stderr, "Decapsulated message:\n");
+ fprintf(stderr, " netfn = 0x%x\n", recv.msg.netfn);
+ fprintf(stderr, " cmd = 0x%x\n", recv.msg.cmd);
+ if (recv.msg.data && recv.msg.data_len) {
+ fprintf(stderr, " data_len = %d\n", recv.msg.data_len);
+ fprintf(stderr, " data = %s\n",
+ buf2str(recv.msg.data, recv.msg.data_len));
+ }
+ }
+ }
}
/* save completion code */
@@ -426,8 +436,8 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
/* save response data for caller */
if (!rsp.ccode && rsp.data_len > 0) {
- memmove(rsp.data, rsp.data + 1, rsp.data_len);
- rsp.data[rsp.data_len] = 0;
+ memmove(rsp.data, rsp.data + 1, rsp.data_len);
+ rsp.data[rsp.data_len] = 0;
}
if (data) {
@@ -438,7 +448,8 @@ ipmi_openipmi_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req)
return &rsp;
}
-int ipmi_openipmi_setup(struct ipmi_intf * intf)
+int
+ipmi_openipmi_setup(struct ipmi_intf *intf)
{
/* set default payload size */
intf->max_request_data_size = IPMI_OPENIPMI_MAX_RQ_DATA_SIZE;