mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-11 02:57:22 +00:00
106 lines
3.2 KiB
C
106 lines
3.2 KiB
C
/*
|
|
* 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
|
|
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
|
|
* SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
|
|
* FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
|
|
* OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
|
|
* SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
|
|
* OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
|
|
* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
|
|
* LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
|
|
* EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
*
|
|
* You acknowledge that this software is not designed or intended for use
|
|
* in the design, construction, operation or maintenance of any nuclear
|
|
* facility.
|
|
*/
|
|
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
#include <ipmitool/ipmi.h>
|
|
#include <ipmitool/ipmi_intf.h>
|
|
#include <ipmitool/ipmi_raw.h>
|
|
|
|
int ipmi_raw_main(struct ipmi_intf * intf, int argc, char ** argv)
|
|
{
|
|
struct ipmi_rs * rsp;
|
|
struct ipmi_rq req;
|
|
unsigned char netfn, cmd;
|
|
int i;
|
|
unsigned char data[32];
|
|
|
|
if (argc < 2 || !strncmp(argv[0], "help", 4)) {
|
|
printf("RAW Commands: raw <netfn> <cmd> [data]\n");
|
|
return -1;
|
|
}
|
|
|
|
netfn = (unsigned char)strtol(argv[0], NULL, 0);
|
|
cmd = (unsigned char)strtol(argv[1], NULL, 0);
|
|
|
|
memset(data, 0, sizeof(data));
|
|
memset(&req, 0, sizeof(req));
|
|
req.msg.netfn = netfn;
|
|
req.msg.cmd = cmd;
|
|
req.msg.data = data;
|
|
|
|
for (i=2; i<argc; i++) {
|
|
unsigned char val = (unsigned char)strtol(argv[i], NULL, 0);
|
|
req.msg.data[i-2] = val;
|
|
req.msg.data_len++;
|
|
}
|
|
if (verbose && req.msg.data_len) {
|
|
for (i=0; i<req.msg.data_len; i++) {
|
|
if (((i%16) == 0) && (i != 0))
|
|
printf("\n");
|
|
printf(" %2.2x", req.msg.data[i]);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
if (verbose)
|
|
printf("RAW REQ (netfn=0x%x cmd=0x%x data_len=%d)\n",
|
|
req.msg.netfn, req.msg.cmd, req.msg.data_len);
|
|
|
|
rsp = intf->sendrecv(intf, &req);
|
|
|
|
if (!rsp || rsp->ccode) {
|
|
printf("Error:%x sending RAW command\n",
|
|
rsp ? rsp->ccode : 0);
|
|
return -1;
|
|
}
|
|
|
|
if (verbose)
|
|
printf("RAW RSP (%d bytes)\n", rsp->data_len);
|
|
|
|
for (i=0; i<rsp->data_len; i++) {
|
|
if (((i%16) == 0) && (i != 0))
|
|
printf("\n");
|
|
printf(" %2.2x", rsp->data[i]);
|
|
}
|
|
printf("\n");
|
|
|
|
return 0;
|
|
}
|
|
|