blob: b68d454a5091c13d88d8f60c988b0e2bb683b923 [file] [log] [blame]
Patrick Venture7dc46702018-08-08 09:43:33 -07001#include "ipmitoolintf.h"
2
3#include <ipmitool/ipmi_intf.h>
4#include <string.h>
5
6extern struct ipmi_intf ipmi_open_intf;
7
8int ipmiSendCommand(const uint8_t* bytes, int length, struct IpmiResponse* resp)
9{
10 struct ipmi_intf* intf = &ipmi_open_intf;
11
12 /* The length needs to be at least two bytes [netfn][cmd] */
13 if (length < 2)
14 {
15 return -1;
16 }
17
18 uint8_t data[MAX_PIPELINE_BANDWIDTH];
19 struct ipmi_rq request;
20 memset(&data[0], 0, sizeof(data));
21 memset(&request, 0, sizeof(request));
22
23 ipmi_intf_session_set_timeout(intf, 15);
24 /* The retry here isn't used for the normal BT interface comms it appears.
25 * Only references found in sol and serial, and lan.
26 */
27 ipmi_intf_session_set_retry(intf, 1);
28
29 request.msg.netfn = bytes[0];
30 request.msg.lun = 0x00;
31 request.msg.cmd = bytes[1];
32 request.msg.data = &data[0];
33
34 /* Can you fit the request in the buffer? */
35 if ((length - 2) > sizeof(data))
36 {
37 return -1;
38 }
39
40 /* Skip beyond netfn and command. */
41 memcpy(request.msg.data, &bytes[2], length - 2);
42 request.msg.data_len = length - 2;
43
44 /* Actually send the command and check for a response. */
45 struct ipmi_rs* response = intf->sendrecv(intf, &request);
46 if (!response)
47 {
48 return -1;
49 }
50
51 /* If the caller wanted the response back. */
52 if (resp)
53 {
54 resp->ccode = response->ccode;
55 if (response->data_len <= sizeof(resp->data))
56 {
57 memcpy(resp->data, response->data, response->data_len);
58 resp->dataLen = response->data_len;
59 return 0;
60 }
61 /* TODO: deal with truncation... */
62 }
63
64 return 0;
65}