Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 1 | #include <endian.h> |
| 2 | #include <string.h> |
| 3 | |
| 4 | #include "platform.h" |
| 5 | |
| 6 | int encode_set_state_effecter_states_resp(uint8_t instance_id, |
| 7 | uint8_t completion_code, |
| 8 | struct pldm_msg *msg) |
| 9 | { |
| 10 | struct pldm_header_info header = {0}; |
| 11 | int rc = PLDM_SUCCESS; |
| 12 | |
| 13 | msg->body.payload[0] = completion_code; |
| 14 | |
| 15 | header.msg_type = PLDM_RESPONSE; |
| 16 | header.instance = instance_id; |
| 17 | header.pldm_type = PLDM_PLATFORM; |
| 18 | header.command = PLDM_SET_STATE_EFFECTER_STATES; |
| 19 | |
| 20 | rc = pack_pldm_header(&header, &(msg->hdr)); |
| 21 | |
| 22 | return rc; |
| 23 | } |
| 24 | |
| 25 | int decode_set_state_effecter_states_req(const struct pldm_msg_payload *msg, |
| 26 | uint16_t *effecter_id, |
| 27 | uint8_t *comp_effecter_count, |
| 28 | set_effecter_state_field *field) |
| 29 | { |
| 30 | if (msg == NULL || effecter_id == NULL || comp_effecter_count == NULL || |
| 31 | field == NULL) { |
| 32 | return PLDM_ERROR_INVALID_DATA; |
| 33 | } |
| 34 | const uint8_t *start = msg->payload; |
| 35 | *effecter_id = le16toh(*((uint16_t *)start)); |
| 36 | *comp_effecter_count = *(start + sizeof(*effecter_id)); |
| 37 | memcpy(field, |
| 38 | (start + sizeof(*effecter_id) + sizeof(*comp_effecter_count)), |
| 39 | (sizeof(set_effecter_state_field) * (*comp_effecter_count))); |
| 40 | |
| 41 | return PLDM_SUCCESS; |
| 42 | } |