blob: f9c83518fbc5c578ca6cc5ac81fc933eddf54ffe [file] [log] [blame]
#include <endian.h>
#include <string.h>
#include "platform.h"
int encode_set_state_effecter_states_resp(uint8_t instance_id,
uint8_t completion_code,
struct pldm_msg *msg)
{
struct pldm_header_info header = {0};
int rc = PLDM_SUCCESS;
msg->payload[0] = completion_code;
header.msg_type = PLDM_RESPONSE;
header.instance = instance_id;
header.pldm_type = PLDM_PLATFORM;
header.command = PLDM_SET_STATE_EFFECTER_STATES;
rc = pack_pldm_header(&header, &(msg->hdr));
return rc;
}
int encode_set_state_effecter_states_req(uint8_t instance_id,
uint16_t effecter_id,
uint8_t comp_effecter_count,
set_effecter_state_field *field,
struct pldm_msg *msg)
{
struct pldm_header_info header = {0};
int rc = PLDM_SUCCESS;
header.msg_type = PLDM_REQUEST;
header.instance = instance_id;
header.pldm_type = PLDM_PLATFORM;
header.command = PLDM_SET_STATE_EFFECTER_STATES;
if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
return rc;
}
if (comp_effecter_count < 0x1 || comp_effecter_count > 0x8) {
return PLDM_ERROR_INVALID_DATA;
}
struct pldm_set_state_effecter_states_req *request =
(struct pldm_set_state_effecter_states_req *)msg->payload;
effecter_id = htole16(effecter_id);
request->effecter_id = effecter_id;
request->comp_effecter_count = comp_effecter_count;
memcpy(request->field, field,
(sizeof(set_effecter_state_field) * comp_effecter_count));
return PLDM_SUCCESS;
}
int decode_set_state_effecter_states_resp(const struct pldm_msg *msg,
size_t payload_length,
uint8_t *completion_code)
{
if (msg == NULL || completion_code == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES) {
return PLDM_ERROR_INVALID_LENGTH;
}
*completion_code = msg->payload[0];
return PLDM_SUCCESS;
}
int decode_set_state_effecter_states_req(const struct pldm_msg *msg,
size_t payload_length,
uint16_t *effecter_id,
uint8_t *comp_effecter_count,
set_effecter_state_field *field)
{
if (msg == NULL || effecter_id == NULL || comp_effecter_count == NULL ||
field == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) {
return PLDM_ERROR_INVALID_LENGTH;
}
struct pldm_set_state_effecter_states_req *request =
(struct pldm_set_state_effecter_states_req *)msg->payload;
*effecter_id = le16toh(request->effecter_id);
*comp_effecter_count = request->comp_effecter_count;
memcpy(field, request->field,
(sizeof(set_effecter_state_field) * (*comp_effecter_count)));
return PLDM_SUCCESS;
}