static void ipmi_sim_handle_command(IPMIBmc *b,

                                    uint8_t *cmd, unsigned int cmd_len,

                                    unsigned int max_cmd_len,

                                    uint8_t msg_id)

{

    IPMIBmcSim *ibs = IPMI_BMC_SIMULATOR(b);

    IPMIInterface *s = ibs->parent.intf;

    IPMIInterfaceClass *k = IPMI_INTERFACE_GET_CLASS(s);

    unsigned int netfn;

    uint8_t rsp[MAX_IPMI_MSG_SIZE];

    unsigned int rsp_len_holder = 0;

    unsigned int *rsp_len = &rsp_len_holder;

    unsigned int max_rsp_len = sizeof(rsp);



    /* Set up the response, set the low bit of NETFN. */

    /* Note that max_rsp_len must be at least 3 */

    if (max_rsp_len < 3) {

        rsp[2] = IPMI_CC_REQUEST_DATA_TRUNCATED;

        goto out;

    }



    IPMI_ADD_RSP_DATA(cmd[0] | 0x04);

    IPMI_ADD_RSP_DATA(cmd[1]);

    IPMI_ADD_RSP_DATA(0); /* Assume success */



    /* If it's too short or it was truncated, return an error. */

    if (cmd_len < 2) {

        rsp[2] = IPMI_CC_REQUEST_DATA_LENGTH_INVALID;

        goto out;

    }

    if (cmd_len > max_cmd_len) {

        rsp[2] = IPMI_CC_REQUEST_DATA_TRUNCATED;

        goto out;

    }



    if ((cmd[0] & 0x03) != 0) {

        /* Only have stuff on LUN 0 */

        rsp[2] = IPMI_CC_COMMAND_INVALID_FOR_LUN;

        goto out;

    }



    netfn = cmd[0] >> 2;



    /* Odd netfns are not valid, make sure the command is registered */

    if ((netfn & 1) || !ibs->netfns[netfn / 2] ||

                        (cmd[1] >= ibs->netfns[netfn / 2]->cmd_nums) ||

                        (!ibs->netfns[netfn / 2]->cmd_handlers[cmd[1]])) {

        rsp[2] = IPMI_CC_INVALID_CMD;

        goto out;

    }



    ibs->netfns[netfn / 2]->cmd_handlers[cmd[1]](ibs, cmd, cmd_len, rsp, rsp_len,

                                                max_rsp_len);



 out:

    k->handle_rsp(s, msg_id, rsp, *rsp_len);



    next_timeout(ibs);

}

static void ipmi_sim_handle_command(IPMIBmc *b,

                                    uint8_t *cmd, unsigned int cmd_len,

                                    unsigned int max_cmd_len,

                                    uint8_t msg_id)

{

    IPMIBmcSim *ibs = IPMI_BMC_SIMULATOR(b);

    IPMIInterface *s = ibs->parent.intf;

    IPMIInterfaceClass *k = IPMI_INTERFACE_GET_CLASS(s);

    unsigned int netfn;

    uint8_t rsp[MAX_IPMI_MSG_SIZE];

    unsigned int rsp_len_holder = 0;

    unsigned int *rsp_len = &rsp_len_holder;

    unsigned int max_rsp_len = sizeof(rsp);



    

    

    if (max_rsp_len < 3) {

        rsp[2] = IPMI_CC_REQUEST_DATA_TRUNCATED;

        goto out;

    }



    IPMI_ADD_RSP_DATA(cmd[0] | 0x04);

    IPMI_ADD_RSP_DATA(cmd[1]);

    IPMI_ADD_RSP_DATA(0); 



    

    if (cmd_len < 2) {

        rsp[2] = IPMI_CC_REQUEST_DATA_LENGTH_INVALID;

        goto out;

    }

    if (cmd_len > max_cmd_len) {

        rsp[2] = IPMI_CC_REQUEST_DATA_TRUNCATED;

        goto out;

    }



    if ((cmd[0] & 0x03) != 0) {

        

        rsp[2] = IPMI_CC_COMMAND_INVALID_FOR_LUN;

        goto out;

    }



    netfn = cmd[0] >> 2;



    

    if ((netfn & 1) || !ibs->netfns[netfn / 2] ||

                        (cmd[1] >= ibs->netfns[netfn / 2]->cmd_nums) ||

                        (!ibs->netfns[netfn / 2]->cmd_handlers[cmd[1]])) {

        rsp[2] = IPMI_CC_INVALID_CMD;

        goto out;

    }



    ibs->netfns[netfn / 2]->cmd_handlers[cmd[1]](ibs, cmd, cmd_len, rsp, rsp_len,

                                                max_rsp_len);



 out:

    k->handle_rsp(s, msg_id, rsp, *rsp_len);



    next_timeout(ibs);

}

    unsigned int netfn;     netfn = cmd[0] >> 2;     if ((netfn & 1) || !ibs->netfns[netfn / 2] ||                         (cmd[1] >= ibs->netfns[netfn / 2]->cmd_nums) ||                         (!ibs->netfns[netfn / 2]->cmd_handlers[cmd[1]])) {     ibs->netfns[netfn / 2]->cmd_handlers[cmd[1]](ibs, cmd, cmd_len, rsp, rsp_len,                                                 max_rsp_len);
static void FUNC_0(IPMIBmc *VAR_0,

                                    uint8_t *VAR_1, unsigned int VAR_2,

                                    unsigned int VAR_3,

                                    uint8_t VAR_4)

{

    IPMIBmcSim *ibs = IPMI_BMC_SIMULATOR(VAR_0);

    IPMIInterface *s = ibs->parent.intf;

    IPMIInterfaceClass *k = IPMI_INTERFACE_GET_CLASS(s);

    unsigned int VAR_5;

    uint8_t rsp[MAX_IPMI_MSG_SIZE];

    unsigned int VAR_6 = 0;

    unsigned int *VAR_7 = &VAR_6;

    unsigned int VAR_8 = sizeof(rsp);



    

    

    if (VAR_8 < 3) {

        rsp[2] = IPMI_CC_REQUEST_DATA_TRUNCATED;

        goto out;

    }



    IPMI_ADD_RSP_DATA(VAR_1[0] | 0x04);

    IPMI_ADD_RSP_DATA(VAR_1[1]);

    IPMI_ADD_RSP_DATA(0); 



    

    if (VAR_2 < 2) {

        rsp[2] = IPMI_CC_REQUEST_DATA_LENGTH_INVALID;

        goto out;

    }

    if (VAR_2 > VAR_3) {

        rsp[2] = IPMI_CC_REQUEST_DATA_TRUNCATED;

        goto out;

    }



    if ((VAR_1[0] & 0x03) != 0) {

        

        rsp[2] = IPMI_CC_COMMAND_INVALID_FOR_LUN;

        goto out;

    }



    VAR_5 = VAR_1[0] >> 2;



    

    if ((VAR_5 & 1) || !ibs->netfns[VAR_5 / 2] ||

                        (VAR_1[1] >= ibs->netfns[VAR_5 / 2]->cmd_nums) ||

                        (!ibs->netfns[VAR_5 / 2]->cmd_handlers[VAR_1[1]])) {

        rsp[2] = IPMI_CC_INVALID_CMD;

        goto out;

    }



    ibs->netfns[VAR_5 / 2]->cmd_handlers[VAR_1[1]](ibs, VAR_1, VAR_2, rsp, VAR_7,

                                                VAR_8);



 out:

    k->handle_rsp(s, VAR_4, rsp, *VAR_7);



    next_timeout(ibs);

}

static void FUNC_0(IPMIBmc *VAR_0,
uint8_t *VAR_1, unsigned int VAR_2,
unsigned int VAR_3,
uint8_t VAR_4)
{ IPMIBmcSim *ibs = IPMI_BMC_SIMULATOR(VAR_0); IPMIInterface *s = ibs->parent.intf; IPMIInterfaceClass *k = IPMI_INTERFACE_GET_CLASS(s); unsigned int VAR_5; uint8_t rsp[MAX_IPMI_MSG_SIZE]; unsigned int VAR_6 = 0; unsigned int *VAR_7 = &VAR_6; unsigned int VAR_8 = sizeof(rsp); if (VAR_8 < 3) { rsp[2] = IPMI_CC_REQUEST_DATA_TRUNCATED; goto out; } IPMI_ADD_RSP_DATA(VAR_1[0] | 0x04); IPMI_ADD_RSP_DATA(VAR_1[1]); IPMI_ADD_RSP_DATA(0); if (VAR_2 < 2) { rsp[2] = IPMI_CC_REQUEST_DATA_LENGTH_INVALID; goto out; } if (VAR_2 > VAR_3) { rsp[2] = IPMI_CC_REQUEST_DATA_TRUNCATED; goto out; } if ((VAR_1[0] & 0x03) != 0) { rsp[2] = IPMI_CC_COMMAND_INVALID_FOR_LUN; goto out; } VAR_5 = VAR_1[0] >> 2; if ((VAR_5 & 1) || !ibs->netfns[VAR_5 / 2] ||
(VAR_1[1] >= ibs->netfns[VAR_5 / 2]->cmd_nums) ||
(!ibs->netfns[VAR_5 / 2]->cmd_handlers[VAR_1[1]])) { rsp[2] = IPMI_CC_INVALID_CMD; goto out; } ibs->netfns[VAR_5 / 2]->cmd_handlers[VAR_1[1]](ibs, VAR_1, VAR_2, rsp, VAR_7,
VAR_8); out:
k->handle_rsp(s, VAR_4, rsp, *VAR_7); next_timeout(ibs); }