|
Packit Service |
ed0f68 |
/*
|
|
Packit Service |
ed0f68 |
* Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved.
|
|
Packit Service |
ed0f68 |
*
|
|
Packit Service |
ed0f68 |
* Redistribution and use in source and binary forms, with or without
|
|
Packit Service |
ed0f68 |
* modification, are permitted provided that the following conditions
|
|
Packit Service |
ed0f68 |
* are met:
|
|
Packit Service |
ed0f68 |
*
|
|
Packit Service |
ed0f68 |
* Redistribution of source code must retain the above copyright
|
|
Packit Service |
ed0f68 |
* notice, this list of conditions and the following disclaimer.
|
|
Packit Service |
ed0f68 |
*
|
|
Packit Service |
ed0f68 |
* Redistribution in binary form must reproduce the above copyright
|
|
Packit Service |
ed0f68 |
* notice, this list of conditions and the following disclaimer in the
|
|
Packit Service |
ed0f68 |
* documentation and/or other materials provided with the distribution.
|
|
Packit Service |
ed0f68 |
*
|
|
Packit Service |
ed0f68 |
* Neither the name of Sun Microsystems, Inc. or the names of
|
|
Packit Service |
ed0f68 |
* contributors may be used to endorse or promote products derived
|
|
Packit Service |
ed0f68 |
* from this software without specific prior written permission.
|
|
Packit Service |
ed0f68 |
*
|
|
Packit Service |
ed0f68 |
* This software is provided "AS IS," without a warranty of any kind.
|
|
Packit Service |
ed0f68 |
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
|
|
Packit Service |
ed0f68 |
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
|
|
Packit Service |
ed0f68 |
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
|
|
Packit Service |
ed0f68 |
* SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
|
|
Packit Service |
ed0f68 |
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
|
|
Packit Service |
ed0f68 |
* OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
|
|
Packit Service |
ed0f68 |
* SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
|
|
Packit Service |
ed0f68 |
* OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
|
|
Packit Service |
ed0f68 |
* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
|
|
Packit Service |
ed0f68 |
* LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
|
|
Packit Service |
ed0f68 |
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
Packit Service |
ed0f68 |
*/
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
#include <string.h>
|
|
Packit Service |
ed0f68 |
#include <stdlib.h>
|
|
Packit Service |
ed0f68 |
#include <stdio.h>
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
#include <ipmitool/ipmi.h>
|
|
Packit Service |
ed0f68 |
#include <ipmitool/log.h>
|
|
Packit Service |
ed0f68 |
#include <ipmitool/helper.h>
|
|
Packit Service |
ed0f68 |
#include <ipmitool/ipmi_intf.h>
|
|
Packit Service |
ed0f68 |
#include <ipmitool/ipmi_raw.h>
|
|
Packit Service |
ed0f68 |
#include <ipmitool/ipmi_strings.h>
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
#define IPMI_I2C_MASTER_MAX_SIZE 0x40 /* 64 bytes */
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
static int is_valid_param(const char *input_param, uint8_t *uchr_ptr,
|
|
Packit Service |
ed0f68 |
const char *label);
|
|
Packit Service |
ed0f68 |
int ipmi_spd_print(uint8_t *, int);
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
/* ipmi_master_write_read - Perform I2C write/read transactions
|
|
Packit Service |
ed0f68 |
*
|
|
Packit Service |
ed0f68 |
* This function performs an I2C master write-read function through
|
|
Packit Service |
ed0f68 |
* IPMI interface. It has a maximum transfer size of 32 bytes.
|
|
Packit Service |
ed0f68 |
*
|
|
Packit Service |
ed0f68 |
* @intf: ipmi interface
|
|
Packit Service |
ed0f68 |
* @bus: channel number, i2c bus id and type
|
|
Packit Service |
ed0f68 |
* @addr: i2c slave address
|
|
Packit Service |
ed0f68 |
* @wdata: data to write
|
|
Packit Service |
ed0f68 |
* @wsize: length of data to write (max 64 bytes)
|
|
Packit Service |
ed0f68 |
* @rsize: length of data to read (max 64 bytes)
|
|
Packit Service |
ed0f68 |
*
|
|
Packit Service |
ed0f68 |
* Returns pointer to IPMI Response
|
|
Packit Service |
ed0f68 |
*/
|
|
Packit Service |
ed0f68 |
struct ipmi_rs *
|
|
Packit Service |
ed0f68 |
ipmi_master_write_read(struct ipmi_intf * intf, uint8_t bus, uint8_t addr,
|
|
Packit Service |
ed0f68 |
uint8_t * wdata, uint8_t wsize, uint8_t rsize)
|
|
Packit Service |
ed0f68 |
{
|
|
Packit Service |
ed0f68 |
struct ipmi_rq req;
|
|
Packit Service |
ed0f68 |
struct ipmi_rs * rsp;
|
|
Packit Service |
ed0f68 |
uint8_t rqdata[IPMI_I2C_MASTER_MAX_SIZE + 3];
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (rsize > IPMI_I2C_MASTER_MAX_SIZE) {
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "Master Write-Read: Too many bytes (%d) to read", rsize);
|
|
Packit Service |
ed0f68 |
return NULL;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
if (wsize > IPMI_I2C_MASTER_MAX_SIZE) {
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "Master Write-Read: Too many bytes (%d) to write", wsize);
|
|
Packit Service |
ed0f68 |
return NULL;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
memset(&req, 0, sizeof(struct ipmi_rq));
|
|
Packit Service |
ed0f68 |
req.msg.netfn = IPMI_NETFN_APP;
|
|
Packit Service |
ed0f68 |
req.msg.cmd = 0x52; /* master write-read */
|
|
Packit Service |
ed0f68 |
req.msg.data = rqdata;
|
|
Packit Service |
ed0f68 |
req.msg.data_len = 3;
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
memset(rqdata, 0, IPMI_I2C_MASTER_MAX_SIZE + 3);
|
|
Packit Service |
ed0f68 |
rqdata[0] = bus; /* channel number, bus id, bus type */
|
|
Packit Service |
ed0f68 |
rqdata[1] = addr; /* slave address */
|
|
Packit Service |
ed0f68 |
rqdata[2] = rsize; /* number of bytes to read */
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (wsize > 0) {
|
|
Packit Service |
ed0f68 |
/* copy in data to write */
|
|
Packit Service |
ed0f68 |
memcpy(rqdata+3, wdata, wsize);
|
|
Packit Service |
ed0f68 |
req.msg.data_len += wsize;
|
|
Packit Service |
ed0f68 |
lprintf(LOG_DEBUG, "Writing %d bytes to i2cdev %02Xh", wsize, addr);
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (rsize > 0) {
|
|
Packit Service |
ed0f68 |
lprintf(LOG_DEBUG, "Reading %d bytes from i2cdev %02Xh", rsize, addr);
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
rsp = intf->sendrecv(intf, &req;;
|
|
Packit Service |
ed0f68 |
if (rsp == NULL) {
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "I2C Master Write-Read command failed");
|
|
Packit Service |
ed0f68 |
return NULL;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
else if (rsp->ccode > 0) {
|
|
Packit Service |
ed0f68 |
switch (rsp->ccode) {
|
|
Packit Service |
ed0f68 |
case 0x81:
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "I2C Master Write-Read command failed: Lost Arbitration");
|
|
Packit Service |
ed0f68 |
break;
|
|
Packit Service |
ed0f68 |
case 0x82:
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "I2C Master Write-Read command failed: Bus Error");
|
|
Packit Service |
ed0f68 |
break;
|
|
Packit Service |
ed0f68 |
case 0x83:
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "I2C Master Write-Read command failed: NAK on Write");
|
|
Packit Service |
ed0f68 |
break;
|
|
Packit Service |
ed0f68 |
case 0x84:
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "I2C Master Write-Read command failed: Truncated Read");
|
|
Packit Service |
ed0f68 |
break;
|
|
Packit Service |
ed0f68 |
default:
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "I2C Master Write-Read command failed: %s",
|
|
Packit Service |
ed0f68 |
val2str(rsp->ccode, completion_code_vals));
|
|
Packit Service |
ed0f68 |
break;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
return NULL;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
return rsp;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
#define RAW_SPD_SIZE 512
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
int
|
|
Packit Service |
ed0f68 |
ipmi_rawspd_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|
Packit Service |
ed0f68 |
{
|
|
Packit Service |
ed0f68 |
struct ipmi_rs *rsp;
|
|
Packit Service |
ed0f68 |
uint8_t msize = IPMI_I2C_MASTER_MAX_SIZE; /* allow to override default */
|
|
Packit Service |
ed0f68 |
uint8_t channel = 0;
|
|
Packit Service |
ed0f68 |
uint8_t i2cbus = 0;
|
|
Packit Service |
ed0f68 |
uint8_t i2caddr = 0;
|
|
Packit Service |
ed0f68 |
uint8_t spd_data[RAW_SPD_SIZE];
|
|
Packit Service |
ed0f68 |
int i;
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
memset(spd_data, 0, RAW_SPD_SIZE);
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (argc < 2 || strncmp(argv[0], "help", 4) == 0) {
|
|
Packit Service |
ed0f68 |
lprintf(LOG_NOTICE, "usage: spd <i2cbus> <i2caddr> [channel] [maxread]");
|
|
Packit Service |
ed0f68 |
return 0;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (is_valid_param(argv[0], &i2cbus, "i2cbus") != 0)
|
|
Packit Service |
ed0f68 |
return (-1);
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (is_valid_param(argv[1], &i2caddr, "i2caddr") != 0)
|
|
Packit Service |
ed0f68 |
return (-1);
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (argc >= 3) {
|
|
Packit Service |
ed0f68 |
if (is_valid_param(argv[2], &channel, "channel") != 0)
|
|
Packit Service |
ed0f68 |
return (-1);
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (argc >= 4) {
|
|
Packit Service |
ed0f68 |
if (is_valid_param(argv[3], &msize, "maxread") != 0)
|
|
Packit Service |
ed0f68 |
return (-1);
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
i2cbus = ((channel & 0xF) << 4) | ((i2cbus & 7) << 1) | 1;
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
for (i = 0; i < RAW_SPD_SIZE; i+= msize) {
|
|
Packit Service |
ed0f68 |
rsp = ipmi_master_write_read(intf, i2cbus, i2caddr,
|
|
Packit Service |
ed0f68 |
(uint8_t *)&i, 1, msize );
|
|
Packit Service |
ed0f68 |
if (rsp == NULL) {
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "Unable to perform I2C Master Write-Read");
|
|
Packit Service |
ed0f68 |
return -1;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
memcpy(spd_data+i, rsp->data, msize);
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
ipmi_spd_print(spd_data, i);
|
|
Packit Service |
ed0f68 |
return 0;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
static void rawi2c_usage(void)
|
|
Packit Service |
ed0f68 |
{
|
|
Packit Service |
ed0f68 |
lprintf(LOG_NOTICE, "usage: i2c [bus=public|# [chan=#] <i2caddr> <read bytes> [write data]");
|
|
Packit Service |
ed0f68 |
lprintf(LOG_NOTICE, " bus=public is default");
|
|
Packit Service |
ed0f68 |
lprintf(LOG_NOTICE, " chan=0 is default, bus= must be specified to use chan=");
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
int
|
|
Packit Service |
ed0f68 |
ipmi_rawi2c_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|
Packit Service |
ed0f68 |
{
|
|
Packit Service |
ed0f68 |
struct ipmi_rs * rsp;
|
|
Packit Service |
ed0f68 |
uint8_t wdata[IPMI_I2C_MASTER_MAX_SIZE];
|
|
Packit Service |
ed0f68 |
uint8_t i2caddr = 0;
|
|
Packit Service |
ed0f68 |
uint8_t rsize = 0;
|
|
Packit Service |
ed0f68 |
uint8_t wsize = 0;
|
|
Packit Service |
ed0f68 |
unsigned int rbus = 0;
|
|
Packit Service |
ed0f68 |
uint8_t bus = 0;
|
|
Packit Service |
ed0f68 |
int i = 0;
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
/* handle bus= argument */
|
|
Packit Service |
ed0f68 |
if (argc > 2 && strncmp(argv[0], "bus=", 4) == 0) {
|
|
Packit Service |
ed0f68 |
i = 1;
|
|
Packit Service |
ed0f68 |
if (strncmp(argv[0], "bus=public", 10) == 0)
|
|
Packit Service |
ed0f68 |
bus = 0;
|
|
Packit Service |
ed0f68 |
else if (sscanf(argv[0], "bus=%u", &rbus) == 1)
|
|
Packit Service |
ed0f68 |
bus = ((rbus & 7) << 1) | 1;
|
|
Packit Service |
ed0f68 |
else
|
|
Packit Service |
ed0f68 |
bus = 0;
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
/* handle channel= argument
|
|
Packit Service |
ed0f68 |
* the bus= argument must be supplied first on command line */
|
|
Packit Service |
ed0f68 |
if (argc > 3 && strncmp(argv[1], "chan=", 5) == 0) {
|
|
Packit Service |
ed0f68 |
i = 2;
|
|
Packit Service |
ed0f68 |
if (sscanf(argv[1], "chan=%u", &rbus) == 1)
|
|
Packit Service |
ed0f68 |
bus |= rbus << 4;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if ((argc-i) < 2 || strncmp(argv[0], "help", 4) == 0) {
|
|
Packit Service |
ed0f68 |
rawi2c_usage();
|
|
Packit Service |
ed0f68 |
return 0;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
else if (argc-i-2 > IPMI_I2C_MASTER_MAX_SIZE) {
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "Raw command input limit (%d bytes) exceeded",
|
|
Packit Service |
ed0f68 |
IPMI_I2C_MASTER_MAX_SIZE);
|
|
Packit Service |
ed0f68 |
return -1;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (is_valid_param(argv[i++], &i2caddr, "i2caddr") != 0)
|
|
Packit Service |
ed0f68 |
return (-1);
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (is_valid_param(argv[i++], &rsize, "read size") != 0)
|
|
Packit Service |
ed0f68 |
return (-1);
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (i2caddr == 0) {
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "Invalid I2C address 0");
|
|
Packit Service |
ed0f68 |
rawi2c_usage();
|
|
Packit Service |
ed0f68 |
return -1;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
memset(wdata, 0, IPMI_I2C_MASTER_MAX_SIZE);
|
|
Packit Service |
ed0f68 |
for (; i < argc; i++) {
|
|
Packit Service |
ed0f68 |
uint8_t val = 0;
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (is_valid_param(argv[i], &val, "parameter") != 0)
|
|
Packit Service |
ed0f68 |
return (-1);
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
wdata[wsize] = val;
|
|
Packit Service |
ed0f68 |
wsize++;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
lprintf(LOG_INFO, "RAW I2C REQ (i2caddr=%x readbytes=%d writebytes=%d)",
|
|
Packit Service |
ed0f68 |
i2caddr, rsize, wsize);
|
|
Packit Service |
ed0f68 |
printbuf(wdata, wsize, "WRITE DATA");
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
rsp = ipmi_master_write_read(intf, bus, i2caddr, wdata, wsize, rsize);
|
|
Packit Service |
ed0f68 |
if (rsp == NULL) {
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "Unable to perform I2C Master Write-Read");
|
|
Packit Service |
ed0f68 |
return -1;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (wsize > 0) {
|
|
Packit Service |
ed0f68 |
if (verbose || rsize == 0)
|
|
Packit Service |
ed0f68 |
printf("Wrote %d bytes to I2C device %02Xh\n", wsize, i2caddr);
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (rsize > 0) {
|
|
Packit Service |
ed0f68 |
if (verbose || wsize == 0)
|
|
Packit Service |
ed0f68 |
printf("Read %d bytes from I2C device %02Xh\n", rsp->data_len, i2caddr);
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (rsp->data_len < rsize)
|
|
Packit Service |
ed0f68 |
return -1;
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
/* print the raw response buffer */
|
|
Packit Service |
ed0f68 |
for (i=0; i<rsp->data_len; i++) {
|
|
Packit Service |
ed0f68 |
if (((i%16) == 0) && (i != 0))
|
|
Packit Service |
ed0f68 |
printf("\n");
|
|
Packit Service |
ed0f68 |
printf(" %2.2x", rsp->data[i]);
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
printf("\n");
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (rsp->data_len <= 4) {
|
|
Packit Service |
ed0f68 |
uint32_t bit;
|
|
Packit Service |
ed0f68 |
int j;
|
|
Packit Service |
ed0f68 |
for (i = 0; i < rsp->data_len; i++) {
|
|
Packit Service |
ed0f68 |
for (j = 1, bit = 0x80; bit > 0; bit /= 2, j++) {
|
|
Packit Service |
ed0f68 |
printf("%s", (rsp->data[i] & bit) ? "1" : "0");
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
printf(" ");
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
printf("\n");
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
return 0;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
/* ipmi_raw_help() - print 'raw' help text
|
|
Packit Service |
ed0f68 |
*
|
|
Packit Service |
ed0f68 |
* returns void
|
|
Packit Service |
ed0f68 |
*/
|
|
Packit Service |
ed0f68 |
void
|
|
Packit Service |
ed0f68 |
ipmi_raw_help()
|
|
Packit Service |
ed0f68 |
{
|
|
Packit Service |
ed0f68 |
lprintf(LOG_NOTICE, "RAW Commands: raw <netfn> <cmd> [data]");
|
|
Packit Service |
ed0f68 |
print_valstr(ipmi_netfn_vals, "Network Function Codes", LOG_NOTICE);
|
|
Packit Service |
ed0f68 |
lprintf(LOG_NOTICE, "(can also use raw hex values)");
|
|
Packit Service |
ed0f68 |
} /* ipmi_raw_help() */
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
int
|
|
Packit Service |
ed0f68 |
ipmi_raw_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|
Packit Service |
ed0f68 |
{
|
|
Packit Service |
ed0f68 |
struct ipmi_rs * rsp;
|
|
Packit Service |
ed0f68 |
struct ipmi_rq req;
|
|
Packit Service |
ed0f68 |
uint8_t netfn, cmd, lun;
|
|
Packit Service |
ed0f68 |
uint16_t netfn_tmp = 0;
|
|
Packit Service |
ed0f68 |
int i;
|
|
Packit Service |
ed0f68 |
uint8_t data[256];
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (argc == 1 && strncmp(argv[0], "help", 4) == 0) {
|
|
Packit Service |
ed0f68 |
ipmi_raw_help();
|
|
Packit Service |
ed0f68 |
return 0;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
else if (argc < 2) {
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "Not enough parameters given.");
|
|
Packit Service |
ed0f68 |
ipmi_raw_help();
|
|
Packit Service |
ed0f68 |
return (-1);
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
else if (argc > sizeof(data))
|
|
Packit Service |
ed0f68 |
{
|
|
Packit Service |
ed0f68 |
lprintf(LOG_NOTICE, "Raw command input limit (256 bytes) exceeded");
|
|
Packit Service |
ed0f68 |
return -1;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
lun = intf->target_lun;
|
|
Packit Service |
ed0f68 |
netfn_tmp = str2val(argv[0], ipmi_netfn_vals);
|
|
Packit Service |
ed0f68 |
if (netfn_tmp == 0xff) {
|
|
Packit Service |
ed0f68 |
if (is_valid_param(argv[0], &netfn, "netfn") != 0)
|
|
Packit Service |
ed0f68 |
return (-1);
|
|
Packit Service |
ed0f68 |
} else {
|
|
Packit Service |
ed0f68 |
if (netfn_tmp >= UINT8_MAX) {
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "Given netfn \"%s\" is out of range.", argv[0]);
|
|
Packit Service |
ed0f68 |
return (-1);
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
netfn = netfn_tmp;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (is_valid_param(argv[1], &cmd, "command") != 0)
|
|
Packit Service |
ed0f68 |
return (-1);
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
memset(data, 0, sizeof(data));
|
|
Packit Service |
ed0f68 |
memset(&req, 0, sizeof(req));
|
|
Packit Service |
ed0f68 |
req.msg.netfn = netfn;
|
|
Packit Service |
ed0f68 |
req.msg.lun = lun;
|
|
Packit Service |
ed0f68 |
req.msg.cmd = cmd;
|
|
Packit Service |
ed0f68 |
req.msg.data = data;
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
for (i=2; i
|
|
Packit Service |
ed0f68 |
uint8_t val = 0;
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (is_valid_param(argv[i], &val, "data") != 0)
|
|
Packit Service |
ed0f68 |
return (-1);
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
req.msg.data[i-2] = val;
|
|
Packit Service |
ed0f68 |
req.msg.data_len++;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
lprintf(LOG_INFO,
|
|
Packit Service |
ed0f68 |
"RAW REQ (channel=0x%x netfn=0x%x lun=0x%x cmd=0x%x data_len=%d)",
|
|
Packit Service |
ed0f68 |
intf->target_channel & 0x0f, req.msg.netfn,req.msg.lun ,
|
|
Packit Service |
ed0f68 |
req.msg.cmd, req.msg.data_len);
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
printbuf(req.msg.data, req.msg.data_len, "RAW REQUEST");
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
rsp = intf->sendrecv(intf, &req;;
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
if (rsp == NULL) {
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "Unable to send RAW command "
|
|
Packit Service |
ed0f68 |
"(channel=0x%x netfn=0x%x lun=0x%x cmd=0x%x)",
|
|
Packit Service |
ed0f68 |
intf->target_channel & 0x0f, req.msg.netfn, req.msg.lun, req.msg.cmd);
|
|
Packit Service |
ed0f68 |
return -1;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
if (rsp->ccode > 0) {
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "Unable to send RAW command "
|
|
Packit Service |
ed0f68 |
"(channel=0x%x netfn=0x%x lun=0x%x cmd=0x%x rsp=0x%x): %s",
|
|
Packit Service |
ed0f68 |
intf->target_channel & 0x0f, req.msg.netfn, req.msg.lun, req.msg.cmd, rsp->ccode,
|
|
Packit Service |
ed0f68 |
val2str(rsp->ccode, completion_code_vals));
|
|
Packit Service |
ed0f68 |
return -1;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
lprintf(LOG_INFO, "RAW RSP (%d bytes)", rsp->data_len);
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
/* print the raw response buffer */
|
|
Packit Service |
ed0f68 |
for (i=0; i<rsp->data_len; i++) {
|
|
Packit Service |
ed0f68 |
if (((i%16) == 0) && (i != 0))
|
|
Packit Service |
ed0f68 |
printf("\n");
|
|
Packit Service |
ed0f68 |
printf(" %2.2x", rsp->data[i]);
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
printf("\n");
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
return 0;
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
/* is_valid_param -
|
|
Packit Service |
ed0f68 |
*
|
|
Packit Service |
ed0f68 |
* @input_param: string to convert from
|
|
Packit Service |
ed0f68 |
* @uchr_ptr: pointer where to store converted value
|
|
Packit Service |
ed0f68 |
* @label: string used in error message
|
|
Packit Service |
ed0f68 |
*
|
|
Packit Service |
ed0f68 |
* returns 0 if parameter is valid
|
|
Packit Service |
ed0f68 |
* returns (-1) if parameter is invalid/on error
|
|
Packit Service |
ed0f68 |
*/
|
|
Packit Service |
ed0f68 |
int
|
|
Packit Service |
ed0f68 |
is_valid_param(const char *input_param, uint8_t *uchr_ptr, const char *label) {
|
|
Packit Service |
ed0f68 |
if (input_param == NULL || label == NULL) {
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERROR, "ERROR: NULL pointer passed.");
|
|
Packit Service |
ed0f68 |
return (-1);
|
|
Packit Service |
ed0f68 |
}
|
|
Packit Service |
ed0f68 |
if (str2uchar(input_param, uchr_ptr) == 0)
|
|
Packit Service |
ed0f68 |
return 0;
|
|
Packit Service |
ed0f68 |
|
|
Packit Service |
ed0f68 |
lprintf(LOG_ERR, "Given %s \"%s\" is invalid.", label, input_param);
|
|
Packit Service |
ed0f68 |
return (-1);
|
|
Packit Service |
ed0f68 |
}
|