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 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 58 | int decode_set_state_effecter_states_resp(const struct pldm_msg *msg, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 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 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 70 | *completion_code = msg->payload[0]; |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 71 | |
| 72 | return PLDM_SUCCESS; |
| 73 | } |
| 74 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 75 | int decode_set_state_effecter_states_req(const struct pldm_msg *msg, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 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 = |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 91 | (struct pldm_set_state_effecter_states_req *)msg->payload; |
Priyanga | 7257fdf | 2019-06-10 01:59:45 -0500 | [diff] [blame] | 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 | } |
Sampa Misra | 7fcfb66 | 2019-05-08 13:13:53 -0500 | [diff] [blame] | 100 | |
| 101 | int decode_get_pdr_req(const struct pldm_msg *msg, size_t payload_length, |
| 102 | uint32_t *record_hndl, uint32_t *data_transfer_hndl, |
| 103 | uint8_t *transfer_op_flag, uint16_t *request_cnt, |
| 104 | uint16_t *record_chg_num) |
| 105 | { |
| 106 | if (msg == NULL || record_hndl == NULL || data_transfer_hndl == NULL || |
| 107 | transfer_op_flag == NULL || request_cnt == NULL || |
| 108 | record_chg_num == NULL) { |
| 109 | return PLDM_ERROR_INVALID_DATA; |
| 110 | } |
| 111 | if (payload_length != PLDM_GET_PDR_REQ_BYTES) { |
| 112 | return PLDM_ERROR_INVALID_LENGTH; |
| 113 | } |
| 114 | |
| 115 | struct pldm_get_pdr_req *request = |
| 116 | (struct pldm_get_pdr_req *)msg->payload; |
| 117 | *record_hndl = le32toh(request->record_handle); |
| 118 | *data_transfer_hndl = le32toh(request->data_transfer_handle); |
| 119 | *transfer_op_flag = request->transfer_op_flag; |
| 120 | *request_cnt = le16toh(request->request_count); |
| 121 | *record_chg_num = le16toh(request->record_change_number); |
| 122 | |
| 123 | return PLDM_SUCCESS; |
| 124 | } |
| 125 | |
| 126 | int encode_get_pdr_resp(uint8_t instance_id, uint8_t completion_code, |
| 127 | uint32_t next_record_hndl, |
| 128 | uint32_t next_data_transfer_hndl, uint8_t transfer_flag, |
| 129 | uint16_t resp_cnt, const uint8_t *record_data, |
| 130 | uint8_t transfer_crc, struct pldm_msg *msg) |
| 131 | { |
| 132 | struct pldm_header_info header = {0}; |
| 133 | int rc = PLDM_SUCCESS; |
| 134 | |
| 135 | if (msg == NULL) { |
| 136 | return PLDM_ERROR_INVALID_DATA; |
| 137 | } |
| 138 | struct pldm_get_pdr_resp *response = |
| 139 | (struct pldm_get_pdr_resp *)msg->payload; |
| 140 | |
| 141 | response->completion_code = completion_code; |
| 142 | |
| 143 | header.msg_type = PLDM_RESPONSE; |
| 144 | header.instance = instance_id; |
| 145 | header.pldm_type = PLDM_PLATFORM; |
| 146 | header.command = PLDM_GET_PDR; |
| 147 | if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) { |
| 148 | return rc; |
| 149 | } |
| 150 | |
| 151 | if (response->completion_code == PLDM_SUCCESS) { |
| 152 | response->next_record_handle = htole32(next_record_hndl); |
| 153 | response->next_data_transfer_handle = |
| 154 | htole32(next_data_transfer_hndl); |
| 155 | response->transfer_flag = transfer_flag; |
| 156 | response->response_count = htole16(resp_cnt); |
| 157 | if (record_data != NULL && resp_cnt > 0) { |
| 158 | memcpy(response->record_data, record_data, resp_cnt); |
| 159 | } |
| 160 | uint8_t *dst = msg->payload; |
| 161 | dst += (sizeof(struct pldm_get_pdr_resp) - 1) + resp_cnt; |
| 162 | *dst = transfer_crc; |
| 163 | } |
| 164 | |
| 165 | return PLDM_SUCCESS; |
| 166 | } |