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 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 13 | msg->payload[0] = completion_code; |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 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 | |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 25 | int encode_set_state_effecter_states_req(uint8_t instance_id, |
| 26 | uint16_t effecter_id, |
| 27 | uint8_t comp_effecter_count, |
| 28 | set_effecter_state_field *field, |
| 29 | struct pldm_msg *msg) |
| 30 | { |
| 31 | struct pldm_header_info header = {0}; |
| 32 | int rc = PLDM_SUCCESS; |
| 33 | |
| 34 | header.msg_type = PLDM_REQUEST; |
| 35 | header.instance = instance_id; |
| 36 | header.pldm_type = PLDM_PLATFORM; |
| 37 | header.command = PLDM_SET_STATE_EFFECTER_STATES; |
| 38 | |
| 39 | if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) { |
| 40 | return rc; |
| 41 | } |
| 42 | |
| 43 | if (comp_effecter_count < 0x1 || comp_effecter_count > 0x8) { |
| 44 | return PLDM_ERROR_INVALID_DATA; |
| 45 | } |
| 46 | |
Priyanga | 7257fdf | 2019-06-10 01:59:45 -0500 | [diff] [blame] | 47 | struct pldm_set_state_effecter_states_req *request = |
| 48 | (struct pldm_set_state_effecter_states_req *)msg->payload; |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 49 | effecter_id = htole16(effecter_id); |
Priyanga | 7257fdf | 2019-06-10 01:59:45 -0500 | [diff] [blame] | 50 | request->effecter_id = effecter_id; |
| 51 | request->comp_effecter_count = comp_effecter_count; |
| 52 | memcpy(request->field, field, |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 53 | (sizeof(set_effecter_state_field) * comp_effecter_count)); |
| 54 | |
| 55 | return PLDM_SUCCESS; |
| 56 | } |
| 57 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 58 | int decode_set_state_effecter_states_resp(const uint8_t *msg, |
| 59 | size_t payload_length, |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 60 | uint8_t *completion_code) |
| 61 | { |
| 62 | if (msg == NULL || completion_code == NULL) { |
| 63 | return PLDM_ERROR_INVALID_DATA; |
| 64 | } |
| 65 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 66 | if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES) { |
| 67 | return PLDM_ERROR_INVALID_LENGTH; |
| 68 | } |
| 69 | |
| 70 | *completion_code = msg[0]; |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 71 | |
| 72 | return PLDM_SUCCESS; |
| 73 | } |
| 74 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 75 | int decode_set_state_effecter_states_req(const uint8_t *msg, |
| 76 | size_t payload_length, |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 77 | uint16_t *effecter_id, |
| 78 | uint8_t *comp_effecter_count, |
| 79 | set_effecter_state_field *field) |
| 80 | { |
| 81 | if (msg == NULL || effecter_id == NULL || comp_effecter_count == NULL || |
| 82 | field == NULL) { |
| 83 | return PLDM_ERROR_INVALID_DATA; |
| 84 | } |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 85 | |
| 86 | if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) { |
| 87 | return PLDM_ERROR_INVALID_LENGTH; |
| 88 | } |
| 89 | |
Priyanga | 7257fdf | 2019-06-10 01:59:45 -0500 | [diff] [blame] | 90 | struct pldm_set_state_effecter_states_req *request = |
| 91 | (struct pldm_set_state_effecter_states_req *)msg; |
| 92 | |
| 93 | *effecter_id = le16toh(request->effecter_id); |
| 94 | *comp_effecter_count = request->comp_effecter_count; |
| 95 | memcpy(field, request->field, |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 96 | (sizeof(set_effecter_state_field) * (*comp_effecter_count))); |
| 97 | |
| 98 | return PLDM_SUCCESS; |
| 99 | } |