#include "ipmitoolintf.h"

#include <ipmitool/ipmi_intf.h>
#include <string.h>

extern struct ipmi_intf ipmi_open_intf;

int ipmiSendCommand(const uint8_t* bytes, int length, struct IpmiResponse* resp)
{
    struct ipmi_intf* intf = &ipmi_open_intf;

    /* The length needs to be at least two bytes [netfn][cmd] */
    if (length < 2)
    {
        return -1;
    }

    uint8_t data[MAX_PIPELINE_BANDWIDTH];
    struct ipmi_rq request;
    memset(&data[0], 0, sizeof(data));
    memset(&request, 0, sizeof(request));

    ipmi_intf_session_set_timeout(intf, 15);
    /* The retry here isn't used for the normal BT interface comms it appears.
     * Only references found in sol and serial, and lan.
     */
    ipmi_intf_session_set_retry(intf, 1);

    request.msg.netfn = bytes[0];
    request.msg.lun = 0x00;
    request.msg.cmd = bytes[1];
    request.msg.data = &data[0];

    /* Can you fit the request in the buffer? */
    if ((length - 2) > sizeof(data))
    {
        return -1;
    }

    /* Skip beyond netfn and command. */
    memcpy(request.msg.data, &bytes[2], length - 2);
    request.msg.data_len = length - 2;

    /* Actually send the command and check for a response. */
    struct ipmi_rs* response = intf->sendrecv(intf, &request);
    if (!response)
    {
        return -1;
    }

    /* If the caller wanted the response back. */
    if (resp)
    {
        resp->ccode = response->ccode;
        if (response->data_len <= sizeof(resp->data))
        {
            memcpy(resp->data, response->data, response->data_len);
            resp->dataLen = response->data_len;
            return 0;
        }
        /* TODO: deal with truncation... */
    }

    return 0;
}
