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 | |
Zach Clark | b728eee | 2020-06-18 10:01:31 -0500 | [diff] [blame] | 6 | int encode_state_effecter_pdr( |
| 7 | struct pldm_state_effecter_pdr *const effecter, |
| 8 | const size_t allocation_size, |
| 9 | const struct state_effecter_possible_states *const possible_states, |
| 10 | const size_t possible_states_size, size_t *const actual_size) |
| 11 | { |
| 12 | // Encode possible states |
| 13 | |
| 14 | size_t calculated_possible_states_size = 0; |
| 15 | |
| 16 | { |
| 17 | char *states_ptr = (char *)possible_states; |
| 18 | char *const begin_states_ptr = states_ptr; |
| 19 | |
| 20 | for (int i = 0; i < effecter->composite_effecter_count; ++i) { |
| 21 | struct state_effecter_possible_states *states = |
| 22 | (struct state_effecter_possible_states *)states_ptr; |
| 23 | |
| 24 | HTOLE16(states->state_set_id); |
| 25 | |
| 26 | states_ptr += |
| 27 | (sizeof(*states) - sizeof(states->states) + |
| 28 | states->possible_states_size); |
| 29 | } |
| 30 | |
| 31 | calculated_possible_states_size = states_ptr - begin_states_ptr; |
| 32 | } |
| 33 | |
| 34 | // Check lengths |
| 35 | |
| 36 | if (possible_states_size != calculated_possible_states_size) { |
| 37 | *actual_size = 0; |
| 38 | return PLDM_ERROR; |
| 39 | } |
| 40 | |
| 41 | *actual_size = |
| 42 | (sizeof(struct pldm_state_effecter_pdr) + possible_states_size - |
| 43 | sizeof(effecter->possible_states)); |
| 44 | |
| 45 | if (allocation_size < *actual_size) { |
| 46 | *actual_size = 0; |
| 47 | return PLDM_ERROR_INVALID_LENGTH; |
| 48 | } |
| 49 | |
| 50 | // Encode rest of PDR |
| 51 | |
| 52 | effecter->hdr.version = 1; |
| 53 | effecter->hdr.type = PLDM_STATE_EFFECTER_PDR; |
| 54 | effecter->hdr.length = *actual_size - sizeof(struct pldm_pdr_hdr); |
| 55 | |
| 56 | memcpy(effecter->possible_states, possible_states, |
| 57 | possible_states_size); |
| 58 | |
| 59 | // Convert effecter PDR body |
| 60 | HTOLE16(effecter->terminus_handle); |
| 61 | HTOLE16(effecter->effecter_id); |
| 62 | HTOLE16(effecter->entity_type); |
| 63 | HTOLE16(effecter->entity_instance); |
| 64 | HTOLE16(effecter->container_id); |
| 65 | HTOLE16(effecter->effecter_semantic_id); |
| 66 | |
| 67 | // Convert header |
| 68 | HTOLE32(effecter->hdr.record_handle); |
| 69 | HTOLE16(effecter->hdr.record_change_num); |
| 70 | HTOLE16(effecter->hdr.length); |
| 71 | |
| 72 | return PLDM_SUCCESS; |
| 73 | } |
| 74 | |
| 75 | int encode_state_sensor_pdr( |
| 76 | struct pldm_state_sensor_pdr *const sensor, const size_t allocation_size, |
| 77 | const struct state_sensor_possible_states *const possible_states, |
| 78 | const size_t possible_states_size, size_t *const actual_size) |
| 79 | { |
| 80 | // Encode possible states |
| 81 | |
| 82 | size_t calculated_possible_states_size = 0; |
| 83 | |
| 84 | { |
| 85 | char *states_ptr = (char *)possible_states, |
| 86 | *const begin_states_ptr = states_ptr; |
| 87 | |
| 88 | for (int i = 0; i < sensor->composite_sensor_count; ++i) { |
| 89 | struct state_sensor_possible_states *states = |
| 90 | (struct state_sensor_possible_states *)states_ptr; |
| 91 | |
| 92 | HTOLE16(states->state_set_id); |
| 93 | |
| 94 | states_ptr += |
| 95 | (sizeof(*states) - sizeof(states->states) + |
| 96 | states->possible_states_size); |
| 97 | } |
| 98 | |
| 99 | calculated_possible_states_size = states_ptr - begin_states_ptr; |
| 100 | } |
| 101 | |
| 102 | // Check lengths |
| 103 | |
| 104 | if (possible_states_size != calculated_possible_states_size) { |
| 105 | *actual_size = 0; |
| 106 | return PLDM_ERROR; |
| 107 | } |
| 108 | |
| 109 | *actual_size = (sizeof(struct pldm_state_sensor_pdr) + |
| 110 | possible_states_size - sizeof(sensor->possible_states)); |
| 111 | |
| 112 | if (allocation_size < *actual_size) { |
| 113 | *actual_size = 0; |
| 114 | return PLDM_ERROR_INVALID_LENGTH; |
| 115 | } |
| 116 | |
| 117 | // Encode rest of PDR |
| 118 | |
| 119 | sensor->hdr.version = 1; |
| 120 | sensor->hdr.type = PLDM_STATE_SENSOR_PDR; |
| 121 | sensor->hdr.length = *actual_size - sizeof(struct pldm_pdr_hdr); |
| 122 | |
| 123 | memcpy(sensor->possible_states, possible_states, possible_states_size); |
| 124 | |
| 125 | // Convert sensor PDR body |
| 126 | HTOLE16(sensor->terminus_handle); |
| 127 | HTOLE16(sensor->sensor_id); |
| 128 | HTOLE16(sensor->entity_type); |
| 129 | HTOLE16(sensor->entity_instance); |
| 130 | HTOLE16(sensor->container_id); |
| 131 | |
| 132 | // Convert header |
| 133 | HTOLE32(sensor->hdr.record_handle); |
| 134 | HTOLE16(sensor->hdr.record_change_num); |
| 135 | HTOLE16(sensor->hdr.length); |
| 136 | |
| 137 | return PLDM_SUCCESS; |
| 138 | } |
| 139 | |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 140 | int encode_set_state_effecter_states_resp(uint8_t instance_id, |
| 141 | uint8_t completion_code, |
| 142 | struct pldm_msg *msg) |
| 143 | { |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 144 | if (msg == NULL) { |
| 145 | return PLDM_ERROR_INVALID_DATA; |
| 146 | } |
| 147 | |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 148 | struct pldm_header_info header = {0}; |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 149 | header.msg_type = PLDM_RESPONSE; |
| 150 | header.instance = instance_id; |
| 151 | header.pldm_type = PLDM_PLATFORM; |
| 152 | header.command = PLDM_SET_STATE_EFFECTER_STATES; |
| 153 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 154 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 155 | if (rc != PLDM_SUCCESS) { |
| 156 | return rc; |
| 157 | } |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 158 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 159 | msg->payload[0] = completion_code; |
| 160 | |
| 161 | return PLDM_SUCCESS; |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 162 | } |
| 163 | |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 164 | int encode_set_state_effecter_states_req(uint8_t instance_id, |
| 165 | uint16_t effecter_id, |
| 166 | uint8_t comp_effecter_count, |
| 167 | set_effecter_state_field *field, |
| 168 | struct pldm_msg *msg) |
| 169 | { |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 170 | if (msg == NULL) { |
| 171 | return PLDM_ERROR_INVALID_DATA; |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 172 | } |
| 173 | |
Tom Joseph | 250c475 | 2020-04-15 10:32:45 +0530 | [diff] [blame] | 174 | if (comp_effecter_count < 0x1 || comp_effecter_count > 0x8 || |
| 175 | field == NULL) { |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 176 | return PLDM_ERROR_INVALID_DATA; |
| 177 | } |
| 178 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 179 | struct pldm_header_info header = {0}; |
| 180 | header.msg_type = PLDM_REQUEST; |
| 181 | header.instance = instance_id; |
| 182 | header.pldm_type = PLDM_PLATFORM; |
| 183 | header.command = PLDM_SET_STATE_EFFECTER_STATES; |
| 184 | |
| 185 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 186 | if (rc != PLDM_SUCCESS) { |
| 187 | return rc; |
| 188 | } |
| 189 | |
Priyanga | 7257fdf | 2019-06-10 01:59:45 -0500 | [diff] [blame] | 190 | struct pldm_set_state_effecter_states_req *request = |
| 191 | (struct pldm_set_state_effecter_states_req *)msg->payload; |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 192 | effecter_id = htole16(effecter_id); |
Priyanga | 7257fdf | 2019-06-10 01:59:45 -0500 | [diff] [blame] | 193 | request->effecter_id = effecter_id; |
| 194 | request->comp_effecter_count = comp_effecter_count; |
| 195 | memcpy(request->field, field, |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 196 | (sizeof(set_effecter_state_field) * comp_effecter_count)); |
| 197 | |
| 198 | return PLDM_SUCCESS; |
| 199 | } |
| 200 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 201 | int decode_set_state_effecter_states_resp(const struct pldm_msg *msg, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 202 | size_t payload_length, |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 203 | uint8_t *completion_code) |
| 204 | { |
| 205 | if (msg == NULL || completion_code == NULL) { |
| 206 | return PLDM_ERROR_INVALID_DATA; |
| 207 | } |
| 208 | |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 209 | *completion_code = msg->payload[0]; |
| 210 | if (PLDM_SUCCESS != *completion_code) { |
| 211 | return PLDM_SUCCESS; |
| 212 | } |
| 213 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 214 | if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES) { |
| 215 | return PLDM_ERROR_INVALID_LENGTH; |
| 216 | } |
| 217 | |
vkaverap | 98a2c19 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 218 | return PLDM_SUCCESS; |
| 219 | } |
| 220 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 221 | int decode_set_state_effecter_states_req(const struct pldm_msg *msg, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 222 | size_t payload_length, |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 223 | uint16_t *effecter_id, |
| 224 | uint8_t *comp_effecter_count, |
| 225 | set_effecter_state_field *field) |
| 226 | { |
| 227 | if (msg == NULL || effecter_id == NULL || comp_effecter_count == NULL || |
| 228 | field == NULL) { |
| 229 | return PLDM_ERROR_INVALID_DATA; |
| 230 | } |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 231 | |
| 232 | if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) { |
| 233 | return PLDM_ERROR_INVALID_LENGTH; |
| 234 | } |
| 235 | |
Priyanga | 7257fdf | 2019-06-10 01:59:45 -0500 | [diff] [blame] | 236 | struct pldm_set_state_effecter_states_req *request = |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 237 | (struct pldm_set_state_effecter_states_req *)msg->payload; |
Priyanga | 7257fdf | 2019-06-10 01:59:45 -0500 | [diff] [blame] | 238 | |
| 239 | *effecter_id = le16toh(request->effecter_id); |
| 240 | *comp_effecter_count = request->comp_effecter_count; |
| 241 | memcpy(field, request->field, |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 242 | (sizeof(set_effecter_state_field) * (*comp_effecter_count))); |
| 243 | |
| 244 | return PLDM_SUCCESS; |
| 245 | } |
Sampa Misra | 7fcfb66 | 2019-05-08 13:13:53 -0500 | [diff] [blame] | 246 | |
| 247 | int decode_get_pdr_req(const struct pldm_msg *msg, size_t payload_length, |
| 248 | uint32_t *record_hndl, uint32_t *data_transfer_hndl, |
| 249 | uint8_t *transfer_op_flag, uint16_t *request_cnt, |
| 250 | uint16_t *record_chg_num) |
| 251 | { |
| 252 | if (msg == NULL || record_hndl == NULL || data_transfer_hndl == NULL || |
| 253 | transfer_op_flag == NULL || request_cnt == NULL || |
| 254 | record_chg_num == NULL) { |
| 255 | return PLDM_ERROR_INVALID_DATA; |
| 256 | } |
| 257 | if (payload_length != PLDM_GET_PDR_REQ_BYTES) { |
| 258 | return PLDM_ERROR_INVALID_LENGTH; |
| 259 | } |
| 260 | |
| 261 | struct pldm_get_pdr_req *request = |
| 262 | (struct pldm_get_pdr_req *)msg->payload; |
| 263 | *record_hndl = le32toh(request->record_handle); |
| 264 | *data_transfer_hndl = le32toh(request->data_transfer_handle); |
| 265 | *transfer_op_flag = request->transfer_op_flag; |
| 266 | *request_cnt = le16toh(request->request_count); |
| 267 | *record_chg_num = le16toh(request->record_change_number); |
| 268 | |
| 269 | return PLDM_SUCCESS; |
| 270 | } |
| 271 | |
| 272 | int encode_get_pdr_resp(uint8_t instance_id, uint8_t completion_code, |
| 273 | uint32_t next_record_hndl, |
| 274 | uint32_t next_data_transfer_hndl, uint8_t transfer_flag, |
| 275 | uint16_t resp_cnt, const uint8_t *record_data, |
| 276 | uint8_t transfer_crc, struct pldm_msg *msg) |
| 277 | { |
Sampa Misra | 7fcfb66 | 2019-05-08 13:13:53 -0500 | [diff] [blame] | 278 | if (msg == NULL) { |
| 279 | return PLDM_ERROR_INVALID_DATA; |
| 280 | } |
Sampa Misra | 7fcfb66 | 2019-05-08 13:13:53 -0500 | [diff] [blame] | 281 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 282 | struct pldm_header_info header = {0}; |
Sampa Misra | 7fcfb66 | 2019-05-08 13:13:53 -0500 | [diff] [blame] | 283 | header.msg_type = PLDM_RESPONSE; |
| 284 | header.instance = instance_id; |
| 285 | header.pldm_type = PLDM_PLATFORM; |
| 286 | header.command = PLDM_GET_PDR; |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 287 | |
| 288 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 289 | if (rc != PLDM_SUCCESS) { |
Sampa Misra | 7fcfb66 | 2019-05-08 13:13:53 -0500 | [diff] [blame] | 290 | return rc; |
| 291 | } |
| 292 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 293 | struct pldm_get_pdr_resp *response = |
| 294 | (struct pldm_get_pdr_resp *)msg->payload; |
| 295 | response->completion_code = completion_code; |
| 296 | |
Sampa Misra | 7fcfb66 | 2019-05-08 13:13:53 -0500 | [diff] [blame] | 297 | if (response->completion_code == PLDM_SUCCESS) { |
| 298 | response->next_record_handle = htole32(next_record_hndl); |
| 299 | response->next_data_transfer_handle = |
| 300 | htole32(next_data_transfer_hndl); |
| 301 | response->transfer_flag = transfer_flag; |
| 302 | response->response_count = htole16(resp_cnt); |
| 303 | if (record_data != NULL && resp_cnt > 0) { |
| 304 | memcpy(response->record_data, record_data, resp_cnt); |
| 305 | } |
Deepak Kodihalli | e4b16ee | 2019-08-14 06:54:38 -0500 | [diff] [blame] | 306 | if (transfer_flag == PLDM_END) { |
| 307 | uint8_t *dst = msg->payload; |
| 308 | dst += |
| 309 | (sizeof(struct pldm_get_pdr_resp) - 1) + resp_cnt; |
| 310 | *dst = transfer_crc; |
| 311 | } |
Sampa Misra | 7fcfb66 | 2019-05-08 13:13:53 -0500 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | return PLDM_SUCCESS; |
| 315 | } |
George Liu | 820a9a5 | 2019-11-26 14:43:59 +0800 | [diff] [blame] | 316 | |
| 317 | int encode_get_pdr_req(uint8_t instance_id, uint32_t record_hndl, |
| 318 | uint32_t data_transfer_hndl, uint8_t transfer_op_flag, |
| 319 | uint16_t request_cnt, uint16_t record_chg_num, |
| 320 | struct pldm_msg *msg, size_t payload_length) |
| 321 | { |
George Liu | 820a9a5 | 2019-11-26 14:43:59 +0800 | [diff] [blame] | 322 | if (msg == NULL) { |
| 323 | return PLDM_ERROR_INVALID_DATA; |
| 324 | } |
George Liu | 820a9a5 | 2019-11-26 14:43:59 +0800 | [diff] [blame] | 325 | |
| 326 | if (payload_length != PLDM_GET_PDR_REQ_BYTES) { |
| 327 | return PLDM_ERROR_INVALID_LENGTH; |
| 328 | } |
| 329 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 330 | struct pldm_header_info header = {0}; |
| 331 | header.msg_type = PLDM_REQUEST; |
| 332 | header.instance = instance_id; |
| 333 | header.pldm_type = PLDM_PLATFORM; |
| 334 | header.command = PLDM_GET_PDR; |
| 335 | |
| 336 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 337 | if (rc != PLDM_SUCCESS) { |
| 338 | return rc; |
| 339 | } |
| 340 | |
| 341 | struct pldm_get_pdr_req *request = |
| 342 | (struct pldm_get_pdr_req *)msg->payload; |
George Liu | 820a9a5 | 2019-11-26 14:43:59 +0800 | [diff] [blame] | 343 | request->record_handle = htole32(record_hndl); |
| 344 | request->data_transfer_handle = htole32(data_transfer_hndl); |
| 345 | request->transfer_op_flag = transfer_op_flag; |
| 346 | request->request_count = htole16(request_cnt); |
| 347 | request->record_change_number = htole16(record_chg_num); |
| 348 | |
| 349 | return PLDM_SUCCESS; |
| 350 | } |
| 351 | |
| 352 | int decode_get_pdr_resp(const struct pldm_msg *msg, size_t payload_length, |
| 353 | uint8_t *completion_code, uint32_t *next_record_hndl, |
| 354 | uint32_t *next_data_transfer_hndl, |
| 355 | uint8_t *transfer_flag, uint16_t *resp_cnt, |
| 356 | uint8_t *record_data, size_t record_data_length, |
| 357 | uint8_t *transfer_crc) |
| 358 | { |
| 359 | if (msg == NULL || completion_code == NULL || |
| 360 | next_record_hndl == NULL || next_data_transfer_hndl == NULL || |
Zach Clark | 3dba2bf | 2020-03-31 10:58:03 -0500 | [diff] [blame] | 361 | transfer_flag == NULL || resp_cnt == NULL || transfer_crc == NULL) { |
George Liu | 820a9a5 | 2019-11-26 14:43:59 +0800 | [diff] [blame] | 362 | return PLDM_ERROR_INVALID_DATA; |
| 363 | } |
| 364 | |
| 365 | *completion_code = msg->payload[0]; |
| 366 | if (PLDM_SUCCESS != *completion_code) { |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 367 | return PLDM_SUCCESS; |
George Liu | 820a9a5 | 2019-11-26 14:43:59 +0800 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | if (payload_length < PLDM_GET_PDR_MIN_RESP_BYTES) { |
| 371 | return PLDM_ERROR_INVALID_LENGTH; |
| 372 | } |
| 373 | |
| 374 | struct pldm_get_pdr_resp *response = |
| 375 | (struct pldm_get_pdr_resp *)msg->payload; |
| 376 | |
| 377 | *next_record_hndl = le32toh(response->next_record_handle); |
| 378 | *next_data_transfer_hndl = le32toh(response->next_data_transfer_handle); |
| 379 | *transfer_flag = response->transfer_flag; |
| 380 | *resp_cnt = le16toh(response->response_count); |
| 381 | |
| 382 | if (*transfer_flag != PLDM_END && |
| 383 | (int)payload_length != PLDM_GET_PDR_MIN_RESP_BYTES + *resp_cnt) { |
| 384 | return PLDM_ERROR_INVALID_LENGTH; |
| 385 | } |
| 386 | |
| 387 | if (*transfer_flag == PLDM_END && |
| 388 | (int)payload_length != |
| 389 | PLDM_GET_PDR_MIN_RESP_BYTES + *resp_cnt + 1) { |
| 390 | return PLDM_ERROR_INVALID_LENGTH; |
| 391 | } |
| 392 | |
Zach Clark | 3dba2bf | 2020-03-31 10:58:03 -0500 | [diff] [blame] | 393 | if (*resp_cnt > 0 && record_data != NULL) { |
George Liu | 820a9a5 | 2019-11-26 14:43:59 +0800 | [diff] [blame] | 394 | if (record_data_length < *resp_cnt) { |
| 395 | return PLDM_ERROR_INVALID_LENGTH; |
| 396 | } |
| 397 | memcpy(record_data, response->record_data, *resp_cnt); |
| 398 | } |
| 399 | |
| 400 | if (*transfer_flag == PLDM_END) { |
| 401 | *transfer_crc = |
| 402 | msg->payload[PLDM_GET_PDR_MIN_RESP_BYTES + *resp_cnt]; |
| 403 | } |
| 404 | |
| 405 | return PLDM_SUCCESS; |
| 406 | } |
George Liu | 30b859f | 2020-01-07 15:03:22 +0800 | [diff] [blame] | 407 | |
| 408 | int decode_set_numeric_effecter_value_req(const struct pldm_msg *msg, |
| 409 | size_t payload_length, |
| 410 | uint16_t *effecter_id, |
| 411 | uint8_t *effecter_data_size, |
| 412 | uint8_t *effecter_value) |
| 413 | { |
| 414 | if (msg == NULL || effecter_id == NULL || effecter_data_size == NULL || |
| 415 | effecter_value == NULL) { |
| 416 | return PLDM_ERROR_INVALID_DATA; |
| 417 | } |
| 418 | |
| 419 | if (payload_length < PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES) { |
| 420 | return PLDM_ERROR_INVALID_LENGTH; |
| 421 | } |
| 422 | |
| 423 | struct pldm_set_numeric_effecter_value_req *request = |
| 424 | (struct pldm_set_numeric_effecter_value_req *)msg->payload; |
| 425 | *effecter_id = le16toh(request->effecter_id); |
| 426 | *effecter_data_size = request->effecter_data_size; |
| 427 | |
| 428 | if (*effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 429 | return PLDM_ERROR_INVALID_DATA; |
| 430 | } |
| 431 | |
| 432 | if (*effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 || |
| 433 | *effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) { |
| 434 | |
| 435 | if (payload_length != |
| 436 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES) { |
| 437 | return PLDM_ERROR_INVALID_LENGTH; |
| 438 | } |
| 439 | |
| 440 | *effecter_value = request->effecter_value[0]; |
| 441 | } |
| 442 | |
| 443 | if (*effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 444 | *effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT16) { |
| 445 | |
| 446 | if (payload_length != |
| 447 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1) { |
| 448 | return PLDM_ERROR_INVALID_LENGTH; |
| 449 | } |
| 450 | |
| 451 | memcpy(effecter_value, request->effecter_value, 2); |
George Liu | da75abe | 2020-04-09 13:36:13 +0800 | [diff] [blame] | 452 | uint16_t *val = (uint16_t *)(effecter_value); |
| 453 | *val = le16toh(*val); |
George Liu | 30b859f | 2020-01-07 15:03:22 +0800 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | if (*effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 457 | *effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 458 | |
| 459 | if (payload_length != |
| 460 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3) { |
| 461 | return PLDM_ERROR_INVALID_LENGTH; |
| 462 | } |
| 463 | |
| 464 | memcpy(effecter_value, request->effecter_value, 4); |
George Liu | da75abe | 2020-04-09 13:36:13 +0800 | [diff] [blame] | 465 | uint32_t *val = (uint32_t *)(effecter_value); |
| 466 | *val = le32toh(*val); |
George Liu | 30b859f | 2020-01-07 15:03:22 +0800 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | return PLDM_SUCCESS; |
| 470 | } |
| 471 | |
| 472 | int encode_set_numeric_effecter_value_resp(uint8_t instance_id, |
| 473 | uint8_t completion_code, |
| 474 | struct pldm_msg *msg, |
| 475 | size_t payload_length) |
| 476 | { |
George Liu | 30b859f | 2020-01-07 15:03:22 +0800 | [diff] [blame] | 477 | if (msg == NULL) { |
| 478 | return PLDM_ERROR_INVALID_DATA; |
| 479 | } |
| 480 | |
| 481 | if (payload_length != PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES) { |
| 482 | return PLDM_ERROR_INVALID_LENGTH; |
| 483 | } |
| 484 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 485 | struct pldm_header_info header = {0}; |
George Liu | 30b859f | 2020-01-07 15:03:22 +0800 | [diff] [blame] | 486 | header.msg_type = PLDM_RESPONSE; |
| 487 | header.instance = instance_id; |
| 488 | header.pldm_type = PLDM_PLATFORM; |
| 489 | header.command = PLDM_SET_NUMERIC_EFFECTER_VALUE; |
| 490 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 491 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 492 | if (rc != PLDM_SUCCESS) { |
| 493 | return rc; |
| 494 | } |
| 495 | |
| 496 | msg->payload[0] = completion_code; |
George Liu | 30b859f | 2020-01-07 15:03:22 +0800 | [diff] [blame] | 497 | |
| 498 | return rc; |
| 499 | } |
| 500 | |
| 501 | int encode_set_numeric_effecter_value_req( |
| 502 | uint8_t instance_id, uint16_t effecter_id, uint8_t effecter_data_size, |
| 503 | uint8_t *effecter_value, struct pldm_msg *msg, size_t payload_length) |
| 504 | { |
George Liu | 30b859f | 2020-01-07 15:03:22 +0800 | [diff] [blame] | 505 | if (msg == NULL || effecter_value == NULL) { |
| 506 | return PLDM_ERROR_INVALID_DATA; |
| 507 | } |
George Liu | 30b859f | 2020-01-07 15:03:22 +0800 | [diff] [blame] | 508 | |
| 509 | if (effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 510 | return PLDM_ERROR_INVALID_DATA; |
| 511 | } |
| 512 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 513 | struct pldm_header_info header = {0}; |
| 514 | header.msg_type = PLDM_REQUEST; |
| 515 | header.instance = instance_id; |
| 516 | header.pldm_type = PLDM_PLATFORM; |
| 517 | header.command = PLDM_SET_NUMERIC_EFFECTER_VALUE; |
| 518 | |
| 519 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 520 | if (rc != PLDM_SUCCESS) { |
| 521 | return rc; |
| 522 | } |
| 523 | |
| 524 | struct pldm_set_numeric_effecter_value_req *request = |
| 525 | (struct pldm_set_numeric_effecter_value_req *)msg->payload; |
George Liu | 30b859f | 2020-01-07 15:03:22 +0800 | [diff] [blame] | 526 | if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 || |
| 527 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) { |
| 528 | if (payload_length != |
| 529 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES) { |
| 530 | return PLDM_ERROR_INVALID_LENGTH; |
| 531 | } |
| 532 | request->effecter_value[0] = *effecter_value; |
| 533 | } else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 534 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT16) { |
| 535 | if (payload_length != |
| 536 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1) { |
| 537 | return PLDM_ERROR_INVALID_LENGTH; |
| 538 | } |
| 539 | |
George Liu | ab74950 | 2020-04-15 13:16:35 +0800 | [diff] [blame] | 540 | uint16_t val = *(uint16_t *)(effecter_value); |
| 541 | val = htole16(val); |
| 542 | memcpy(request->effecter_value, &val, sizeof(uint16_t)); |
| 543 | |
George Liu | 30b859f | 2020-01-07 15:03:22 +0800 | [diff] [blame] | 544 | } else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 545 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 546 | if (payload_length != |
| 547 | PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3) { |
| 548 | return PLDM_ERROR_INVALID_LENGTH; |
| 549 | } |
| 550 | |
George Liu | ab74950 | 2020-04-15 13:16:35 +0800 | [diff] [blame] | 551 | uint32_t val = *(uint32_t *)(effecter_value); |
| 552 | val = htole32(val); |
| 553 | memcpy(request->effecter_value, &val, sizeof(uint32_t)); |
George Liu | 30b859f | 2020-01-07 15:03:22 +0800 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | request->effecter_id = htole16(effecter_id); |
| 557 | request->effecter_data_size = effecter_data_size; |
| 558 | |
| 559 | return PLDM_SUCCESS; |
| 560 | } |
| 561 | |
| 562 | int decode_set_numeric_effecter_value_resp(const struct pldm_msg *msg, |
| 563 | size_t payload_length, |
| 564 | uint8_t *completion_code) |
| 565 | { |
| 566 | if (msg == NULL || completion_code == NULL) { |
| 567 | return PLDM_ERROR_INVALID_DATA; |
| 568 | } |
| 569 | |
| 570 | if (payload_length != PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES) { |
| 571 | return PLDM_ERROR_INVALID_LENGTH; |
| 572 | } |
| 573 | |
| 574 | *completion_code = msg->payload[0]; |
| 575 | |
| 576 | return PLDM_SUCCESS; |
| 577 | } |
Jolie Ku | 3557bad | 2020-03-02 16:22:57 +0800 | [diff] [blame] | 578 | |
| 579 | int encode_get_state_sensor_readings_resp(uint8_t instance_id, |
| 580 | uint8_t completion_code, |
| 581 | uint8_t comp_sensor_count, |
| 582 | get_sensor_state_field *field, |
| 583 | struct pldm_msg *msg) |
| 584 | { |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 585 | if (msg == NULL) { |
| 586 | return PLDM_ERROR_INVALID_DATA; |
| 587 | } |
Jolie Ku | 3557bad | 2020-03-02 16:22:57 +0800 | [diff] [blame] | 588 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 589 | if (comp_sensor_count < 0x1 || comp_sensor_count > 0x8) { |
| 590 | return PLDM_ERROR_INVALID_DATA; |
| 591 | } |
| 592 | |
| 593 | struct pldm_header_info header = {0}; |
Jolie Ku | 3557bad | 2020-03-02 16:22:57 +0800 | [diff] [blame] | 594 | header.msg_type = PLDM_RESPONSE; |
| 595 | header.instance = instance_id; |
| 596 | header.pldm_type = PLDM_PLATFORM; |
| 597 | header.command = PLDM_GET_STATE_SENSOR_READINGS; |
| 598 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 599 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 600 | if (rc != PLDM_SUCCESS) { |
Jolie Ku | 3557bad | 2020-03-02 16:22:57 +0800 | [diff] [blame] | 601 | return rc; |
| 602 | } |
| 603 | |
Jolie Ku | 3557bad | 2020-03-02 16:22:57 +0800 | [diff] [blame] | 604 | struct pldm_get_state_sensor_readings_resp *response = |
| 605 | (struct pldm_get_state_sensor_readings_resp *)msg->payload; |
| 606 | |
| 607 | response->completion_code = completion_code; |
| 608 | response->comp_sensor_count = comp_sensor_count; |
| 609 | memcpy(response->field, field, |
| 610 | (sizeof(get_sensor_state_field) * comp_sensor_count)); |
| 611 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 612 | return PLDM_SUCCESS; |
Jolie Ku | 3557bad | 2020-03-02 16:22:57 +0800 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | int encode_get_state_sensor_readings_req(uint8_t instance_id, |
| 616 | uint16_t sensor_id, |
| 617 | bitfield8_t sensor_rearm, |
| 618 | uint8_t reserved, struct pldm_msg *msg) |
| 619 | { |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 620 | if (msg == NULL) { |
| 621 | return PLDM_ERROR_INVALID_DATA; |
| 622 | } |
Jolie Ku | 3557bad | 2020-03-02 16:22:57 +0800 | [diff] [blame] | 623 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 624 | struct pldm_header_info header = {0}; |
Jolie Ku | 3557bad | 2020-03-02 16:22:57 +0800 | [diff] [blame] | 625 | header.msg_type = PLDM_REQUEST; |
| 626 | header.instance = instance_id; |
| 627 | header.pldm_type = PLDM_PLATFORM; |
| 628 | header.command = PLDM_GET_STATE_SENSOR_READINGS; |
| 629 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 630 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 631 | if (rc != PLDM_SUCCESS) { |
Jolie Ku | 3557bad | 2020-03-02 16:22:57 +0800 | [diff] [blame] | 632 | return rc; |
| 633 | } |
| 634 | |
| 635 | struct pldm_get_state_sensor_readings_req *request = |
| 636 | (struct pldm_get_state_sensor_readings_req *)msg->payload; |
| 637 | |
| 638 | request->sensor_id = htole16(sensor_id); |
| 639 | request->reserved = reserved; |
| 640 | request->sensor_rearm = sensor_rearm; |
| 641 | |
| 642 | return PLDM_SUCCESS; |
| 643 | } |
| 644 | |
| 645 | int decode_get_state_sensor_readings_resp(const struct pldm_msg *msg, |
| 646 | size_t payload_length, |
| 647 | uint8_t *completion_code, |
| 648 | uint8_t *comp_sensor_count, |
| 649 | get_sensor_state_field *field) |
| 650 | { |
| 651 | if (msg == NULL || completion_code == NULL || |
| 652 | comp_sensor_count == NULL || field == NULL) { |
| 653 | return PLDM_ERROR_INVALID_DATA; |
| 654 | } |
| 655 | |
| 656 | *completion_code = msg->payload[0]; |
| 657 | if (PLDM_SUCCESS != *completion_code) { |
| 658 | return PLDM_SUCCESS; |
| 659 | } |
| 660 | |
Jolie Ku | 3557bad | 2020-03-02 16:22:57 +0800 | [diff] [blame] | 661 | struct pldm_get_state_sensor_readings_resp *response = |
| 662 | (struct pldm_get_state_sensor_readings_resp *)msg->payload; |
| 663 | |
| 664 | if (response->comp_sensor_count < 0x1 || |
| 665 | response->comp_sensor_count > 0x8) { |
| 666 | return PLDM_ERROR_INVALID_DATA; |
| 667 | } |
George Liu | 38eaa27 | 2021-01-21 19:30:15 +0800 | [diff] [blame] | 668 | |
| 669 | if (payload_length > |
| 670 | PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES + |
| 671 | sizeof(get_sensor_state_field) * response->comp_sensor_count) { |
Jolie Ku | 3557bad | 2020-03-02 16:22:57 +0800 | [diff] [blame] | 672 | return PLDM_ERROR_INVALID_LENGTH; |
| 673 | } |
George Liu | 38eaa27 | 2021-01-21 19:30:15 +0800 | [diff] [blame] | 674 | |
Jolie Ku | 3557bad | 2020-03-02 16:22:57 +0800 | [diff] [blame] | 675 | *comp_sensor_count = response->comp_sensor_count; |
| 676 | |
| 677 | memcpy(field, response->field, |
| 678 | (sizeof(get_sensor_state_field) * (*comp_sensor_count))); |
| 679 | |
| 680 | return PLDM_SUCCESS; |
| 681 | } |
| 682 | |
| 683 | int decode_get_state_sensor_readings_req(const struct pldm_msg *msg, |
| 684 | size_t payload_length, |
| 685 | uint16_t *sensor_id, |
| 686 | bitfield8_t *sensor_rearm, |
| 687 | uint8_t *reserved) |
| 688 | { |
| 689 | if (msg == NULL || sensor_id == NULL || sensor_rearm == NULL) { |
| 690 | return PLDM_ERROR_INVALID_DATA; |
| 691 | } |
| 692 | |
| 693 | if (payload_length != PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES) { |
| 694 | return PLDM_ERROR_INVALID_LENGTH; |
| 695 | } |
| 696 | |
| 697 | struct pldm_get_state_sensor_readings_req *request = |
| 698 | (struct pldm_get_state_sensor_readings_req *)msg->payload; |
| 699 | |
| 700 | *sensor_id = le16toh(request->sensor_id); |
| 701 | *reserved = request->reserved; |
| 702 | memcpy(&(sensor_rearm->byte), &(request->sensor_rearm.byte), |
| 703 | sizeof(request->sensor_rearm.byte)); |
| 704 | |
| 705 | return PLDM_SUCCESS; |
| 706 | } |
Zahed Hossain | d4abab1 | 2020-02-06 03:36:43 -0600 | [diff] [blame] | 707 | |
Zach Clark | b728eee | 2020-06-18 10:01:31 -0500 | [diff] [blame] | 708 | int encode_sensor_event_data( |
| 709 | struct pldm_sensor_event_data *const event_data, |
| 710 | const size_t event_data_size, const uint16_t sensor_id, |
| 711 | const enum sensor_event_class_states sensor_event_class, |
| 712 | const uint8_t sensor_offset, const uint8_t event_state, |
| 713 | const uint8_t previous_event_state, size_t *const actual_event_data_size) |
| 714 | { |
| 715 | *actual_event_data_size = |
| 716 | (sizeof(*event_data) - sizeof(event_data->event_class) + |
| 717 | sizeof(struct pldm_sensor_event_state_sensor_state)); |
| 718 | |
| 719 | if (!event_data) { |
| 720 | return PLDM_SUCCESS; |
| 721 | } |
| 722 | |
| 723 | if (event_data_size < *actual_event_data_size) { |
| 724 | *actual_event_data_size = 0; |
| 725 | return PLDM_ERROR_INVALID_LENGTH; |
| 726 | } |
| 727 | |
Christian Geddes | 1aad2f9 | 2021-02-08 10:03:43 -0600 | [diff] [blame] | 728 | event_data->sensor_id = htole16(sensor_id); |
Zach Clark | b728eee | 2020-06-18 10:01:31 -0500 | [diff] [blame] | 729 | event_data->sensor_event_class_type = sensor_event_class; |
| 730 | |
| 731 | struct pldm_sensor_event_state_sensor_state *const state_data = |
| 732 | (struct pldm_sensor_event_state_sensor_state *) |
| 733 | event_data->event_class; |
| 734 | |
| 735 | state_data->sensor_offset = sensor_offset; |
| 736 | state_data->event_state = event_state; |
| 737 | state_data->previous_event_state = previous_event_state; |
| 738 | |
| 739 | return PLDM_SUCCESS; |
| 740 | } |
| 741 | |
Zahed Hossain | d4abab1 | 2020-02-06 03:36:43 -0600 | [diff] [blame] | 742 | int decode_platform_event_message_req(const struct pldm_msg *msg, |
| 743 | size_t payload_length, |
| 744 | uint8_t *format_version, uint8_t *tid, |
| 745 | uint8_t *event_class, |
| 746 | size_t *event_data_offset) |
| 747 | { |
| 748 | |
| 749 | if (msg == NULL || format_version == NULL || tid == NULL || |
| 750 | event_class == NULL || event_data_offset == NULL) { |
| 751 | return PLDM_ERROR_INVALID_DATA; |
| 752 | } |
| 753 | |
| 754 | if (payload_length <= PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES) { |
| 755 | return PLDM_ERROR_INVALID_LENGTH; |
| 756 | } |
| 757 | struct pldm_platform_event_message_req *response = |
| 758 | (struct pldm_platform_event_message_req *)msg->payload; |
| 759 | |
| 760 | *format_version = response->format_version; |
| 761 | *tid = response->tid; |
| 762 | *event_class = response->event_class; |
| 763 | *event_data_offset = |
| 764 | sizeof(*format_version) + sizeof(*tid) + sizeof(*event_class); |
| 765 | |
| 766 | return PLDM_SUCCESS; |
| 767 | } |
| 768 | |
| 769 | int encode_platform_event_message_resp(uint8_t instance_id, |
Pavithra Barithaya | 2ea1f07 | 2020-04-03 09:30:23 -0500 | [diff] [blame] | 770 | uint8_t completion_code, |
| 771 | uint8_t platform_event_status, |
Zahed Hossain | d4abab1 | 2020-02-06 03:36:43 -0600 | [diff] [blame] | 772 | struct pldm_msg *msg) |
| 773 | { |
Zahed Hossain | d4abab1 | 2020-02-06 03:36:43 -0600 | [diff] [blame] | 774 | if (msg == NULL) { |
| 775 | return PLDM_ERROR_INVALID_DATA; |
| 776 | } |
| 777 | |
Pavithra Barithaya | 2ea1f07 | 2020-04-03 09:30:23 -0500 | [diff] [blame] | 778 | if (platform_event_status > PLDM_EVENT_LOGGING_REJECTED) { |
| 779 | return PLDM_ERROR_INVALID_DATA; |
| 780 | } |
| 781 | |
Zahed Hossain | d4abab1 | 2020-02-06 03:36:43 -0600 | [diff] [blame] | 782 | struct pldm_header_info header = {0}; |
| 783 | header.msg_type = PLDM_RESPONSE; |
| 784 | header.instance = instance_id; |
| 785 | header.pldm_type = PLDM_PLATFORM; |
| 786 | header.command = PLDM_PLATFORM_EVENT_MESSAGE; |
| 787 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 788 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 789 | if (rc != PLDM_SUCCESS) { |
Zahed Hossain | d4abab1 | 2020-02-06 03:36:43 -0600 | [diff] [blame] | 790 | return rc; |
| 791 | } |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 792 | |
| 793 | struct pldm_platform_event_message_resp *response = |
| 794 | (struct pldm_platform_event_message_resp *)msg->payload; |
| 795 | response->completion_code = completion_code; |
| 796 | response->platform_event_status = platform_event_status; |
| 797 | |
Zahed Hossain | d4abab1 | 2020-02-06 03:36:43 -0600 | [diff] [blame] | 798 | return PLDM_SUCCESS; |
| 799 | } |
Zahed Hossain | 1c86171 | 2020-03-04 08:55:19 -0600 | [diff] [blame] | 800 | |
Christian Geddes | 3bdb3c2 | 2020-05-01 14:55:39 -0500 | [diff] [blame] | 801 | int encode_platform_event_message_req( |
| 802 | uint8_t instance_id, uint8_t format_version, uint8_t tid, |
| 803 | uint8_t event_class, const uint8_t *event_data, size_t event_data_length, |
| 804 | struct pldm_msg *msg, size_t payload_length) |
Pavithra Barithaya | 35f2b2c | 2020-04-08 01:35:56 -0500 | [diff] [blame] | 805 | |
| 806 | { |
Pavithra Barithaya | 35f2b2c | 2020-04-08 01:35:56 -0500 | [diff] [blame] | 807 | if (format_version != 1) { |
| 808 | return PLDM_ERROR_INVALID_DATA; |
| 809 | } |
| 810 | |
| 811 | if (msg == NULL || event_data == NULL) { |
| 812 | return PLDM_ERROR_INVALID_DATA; |
| 813 | } |
| 814 | |
| 815 | if (event_data_length == 0) { |
| 816 | return PLDM_ERROR_INVALID_DATA; |
| 817 | } |
| 818 | |
Christian Geddes | 3bdb3c2 | 2020-05-01 14:55:39 -0500 | [diff] [blame] | 819 | if (payload_length != |
| 820 | PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + event_data_length) { |
| 821 | return PLDM_ERROR_INVALID_LENGTH; |
| 822 | } |
| 823 | |
Pavithra Barithaya | 35f2b2c | 2020-04-08 01:35:56 -0500 | [diff] [blame] | 824 | if (event_class > PLDM_HEARTBEAT_TIMER_ELAPSED_EVENT && |
| 825 | !(event_class >= 0xF0 && event_class <= 0xFE)) { |
| 826 | return PLDM_ERROR_INVALID_DATA; |
| 827 | } |
| 828 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 829 | struct pldm_header_info header = {0}; |
| 830 | header.msg_type = PLDM_REQUEST; |
| 831 | header.instance = instance_id; |
| 832 | header.pldm_type = PLDM_PLATFORM; |
| 833 | header.command = PLDM_PLATFORM_EVENT_MESSAGE; |
| 834 | |
| 835 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 836 | if (rc != PLDM_SUCCESS) { |
Pavithra Barithaya | 35f2b2c | 2020-04-08 01:35:56 -0500 | [diff] [blame] | 837 | return rc; |
| 838 | } |
| 839 | |
| 840 | struct pldm_platform_event_message_req *request = |
| 841 | (struct pldm_platform_event_message_req *)msg->payload; |
| 842 | request->format_version = format_version; |
| 843 | request->tid = tid; |
| 844 | request->event_class = event_class; |
| 845 | memcpy(request->event_data, event_data, event_data_length); |
| 846 | |
| 847 | return PLDM_SUCCESS; |
| 848 | } |
| 849 | |
| 850 | int decode_platform_event_message_resp(const struct pldm_msg *msg, |
| 851 | size_t payload_length, |
| 852 | uint8_t *completion_code, |
| 853 | uint8_t *platform_event_status) |
| 854 | { |
| 855 | if (msg == NULL || completion_code == NULL || |
| 856 | platform_event_status == NULL) { |
| 857 | return PLDM_ERROR_INVALID_DATA; |
| 858 | } |
| 859 | |
| 860 | *completion_code = msg->payload[0]; |
| 861 | if (PLDM_SUCCESS != *completion_code) { |
| 862 | return PLDM_SUCCESS; |
| 863 | } |
| 864 | if (payload_length != PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES) { |
| 865 | return PLDM_ERROR_INVALID_LENGTH; |
| 866 | } |
| 867 | |
| 868 | struct pldm_platform_event_message_resp *response = |
| 869 | (struct pldm_platform_event_message_resp *)msg->payload; |
| 870 | *platform_event_status = response->platform_event_status; |
| 871 | |
| 872 | if (*platform_event_status > PLDM_EVENT_LOGGING_REJECTED) { |
| 873 | return PLDM_ERROR_INVALID_DATA; |
| 874 | } |
| 875 | |
| 876 | return PLDM_SUCCESS; |
| 877 | } |
| 878 | |
Zahed Hossain | 1c86171 | 2020-03-04 08:55:19 -0600 | [diff] [blame] | 879 | int decode_sensor_event_data(const uint8_t *event_data, |
| 880 | size_t event_data_length, uint16_t *sensor_id, |
| 881 | uint8_t *sensor_event_class_type, |
| 882 | size_t *event_class_data_offset) |
| 883 | { |
| 884 | if (event_data == NULL) { |
| 885 | return PLDM_ERROR_INVALID_DATA; |
| 886 | } |
| 887 | if (event_data_length < PLDM_SENSOR_EVENT_DATA_MIN_LENGTH) { |
| 888 | return PLDM_ERROR_INVALID_LENGTH; |
| 889 | } |
| 890 | |
| 891 | size_t event_class_data_length = |
| 892 | event_data_length - PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES; |
| 893 | |
| 894 | struct pldm_sensor_event_data *sensor_event_data = |
| 895 | (struct pldm_sensor_event_data *)event_data; |
| 896 | *sensor_id = sensor_event_data->sensor_id; |
| 897 | *sensor_event_class_type = sensor_event_data->sensor_event_class_type; |
| 898 | if (sensor_event_data->sensor_event_class_type == |
| 899 | PLDM_SENSOR_OP_STATE) { |
| 900 | if (event_class_data_length != |
| 901 | PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH) { |
| 902 | return PLDM_ERROR_INVALID_LENGTH; |
| 903 | } |
| 904 | } else if (sensor_event_data->sensor_event_class_type == |
| 905 | PLDM_STATE_SENSOR_STATE) { |
| 906 | if (event_class_data_length != |
| 907 | PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH) { |
| 908 | return PLDM_ERROR_INVALID_LENGTH; |
| 909 | } |
| 910 | } else if (sensor_event_data->sensor_event_class_type == |
| 911 | PLDM_NUMERIC_SENSOR_STATE) { |
| 912 | if (event_class_data_length < |
| 913 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MIN_DATA_LENGTH || |
| 914 | event_class_data_length > |
| 915 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH) { |
| 916 | return PLDM_ERROR_INVALID_LENGTH; |
| 917 | } |
| 918 | } else { |
| 919 | return PLDM_ERROR_INVALID_DATA; |
| 920 | } |
| 921 | *event_class_data_offset = |
| 922 | sizeof(*sensor_id) + sizeof(*sensor_event_class_type); |
| 923 | return PLDM_SUCCESS; |
| 924 | } |
| 925 | |
| 926 | int decode_sensor_op_data(const uint8_t *sensor_data, size_t sensor_data_length, |
| 927 | uint8_t *present_op_state, uint8_t *previous_op_state) |
| 928 | { |
| 929 | if (sensor_data == NULL || present_op_state == NULL || |
| 930 | previous_op_state == NULL) { |
| 931 | return PLDM_ERROR_INVALID_DATA; |
| 932 | } |
| 933 | if (sensor_data_length != |
| 934 | PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH) { |
| 935 | return PLDM_ERROR_INVALID_LENGTH; |
| 936 | } |
| 937 | |
| 938 | struct pldm_sensor_event_sensor_op_state *sensor_op_data = |
| 939 | (struct pldm_sensor_event_sensor_op_state *)sensor_data; |
| 940 | *present_op_state = sensor_op_data->present_op_state; |
| 941 | *previous_op_state = sensor_op_data->previous_op_state; |
| 942 | return PLDM_SUCCESS; |
| 943 | } |
| 944 | |
| 945 | int decode_state_sensor_data(const uint8_t *sensor_data, |
| 946 | size_t sensor_data_length, uint8_t *sensor_offset, |
| 947 | uint8_t *event_state, |
| 948 | uint8_t *previous_event_state) |
| 949 | { |
| 950 | if (sensor_data == NULL || sensor_offset == NULL || |
| 951 | event_state == NULL || previous_event_state == NULL) { |
| 952 | return PLDM_ERROR_INVALID_DATA; |
| 953 | } |
| 954 | if (sensor_data_length != |
| 955 | PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH) { |
| 956 | return PLDM_ERROR_INVALID_LENGTH; |
| 957 | } |
| 958 | |
| 959 | struct pldm_sensor_event_state_sensor_state *sensor_state_data = |
| 960 | (struct pldm_sensor_event_state_sensor_state *)sensor_data; |
| 961 | *sensor_offset = sensor_state_data->sensor_offset; |
| 962 | *event_state = sensor_state_data->event_state; |
| 963 | *previous_event_state = sensor_state_data->previous_event_state; |
| 964 | return PLDM_SUCCESS; |
| 965 | } |
| 966 | |
| 967 | int decode_numeric_sensor_data(const uint8_t *sensor_data, |
| 968 | size_t sensor_data_length, uint8_t *event_state, |
| 969 | uint8_t *previous_event_state, |
| 970 | uint8_t *sensor_data_size, |
| 971 | uint32_t *present_reading) |
| 972 | { |
| 973 | if (sensor_data == NULL || sensor_data_size == NULL || |
| 974 | event_state == NULL || previous_event_state == NULL || |
| 975 | present_reading == NULL) { |
| 976 | return PLDM_ERROR_INVALID_DATA; |
| 977 | } |
| 978 | if (sensor_data_length < |
| 979 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MIN_DATA_LENGTH || |
| 980 | sensor_data_length > |
| 981 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH) { |
| 982 | return PLDM_ERROR_INVALID_LENGTH; |
| 983 | } |
| 984 | struct pldm_sensor_event_numeric_sensor_state *numeric_sensor_data = |
| 985 | (struct pldm_sensor_event_numeric_sensor_state *)sensor_data; |
| 986 | *event_state = numeric_sensor_data->event_state; |
| 987 | *previous_event_state = numeric_sensor_data->previous_event_state; |
| 988 | *sensor_data_size = numeric_sensor_data->sensor_data_size; |
| 989 | uint8_t *present_reading_ptr = numeric_sensor_data->present_reading; |
| 990 | |
| 991 | switch (*sensor_data_size) { |
| 992 | case PLDM_SENSOR_DATA_SIZE_UINT8: |
| 993 | case PLDM_SENSOR_DATA_SIZE_SINT8: |
| 994 | if (sensor_data_length != |
| 995 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_8BIT_DATA_LENGTH) { |
| 996 | return PLDM_ERROR_INVALID_LENGTH; |
| 997 | } |
| 998 | *present_reading = present_reading_ptr[0]; |
| 999 | break; |
| 1000 | case PLDM_SENSOR_DATA_SIZE_UINT16: |
| 1001 | case PLDM_SENSOR_DATA_SIZE_SINT16: |
| 1002 | if (sensor_data_length != |
| 1003 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_16BIT_DATA_LENGTH) { |
| 1004 | return PLDM_ERROR_INVALID_LENGTH; |
| 1005 | } |
| 1006 | *present_reading = le16toh(present_reading_ptr[1] | |
| 1007 | (present_reading_ptr[0] << 8)); |
| 1008 | break; |
| 1009 | case PLDM_SENSOR_DATA_SIZE_UINT32: |
| 1010 | case PLDM_SENSOR_DATA_SIZE_SINT32: |
| 1011 | if (sensor_data_length != |
| 1012 | PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_32BIT_DATA_LENGTH) { |
| 1013 | return PLDM_ERROR_INVALID_LENGTH; |
| 1014 | } |
| 1015 | *present_reading = le32toh(present_reading_ptr[3] | |
| 1016 | (present_reading_ptr[2] << 8) | |
| 1017 | (present_reading_ptr[1] << 16) | |
| 1018 | (present_reading_ptr[0] << 24)); |
| 1019 | break; |
| 1020 | default: |
| 1021 | return PLDM_ERROR_INVALID_DATA; |
| 1022 | } |
| 1023 | return PLDM_SUCCESS; |
| 1024 | } |
Jolie Ku | 6787f17 | 2020-03-19 11:15:53 +0800 | [diff] [blame] | 1025 | |
| 1026 | int encode_get_numeric_effecter_value_req(uint8_t instance_id, |
| 1027 | uint16_t effecter_id, |
| 1028 | struct pldm_msg *msg) |
| 1029 | { |
Jolie Ku | 6787f17 | 2020-03-19 11:15:53 +0800 | [diff] [blame] | 1030 | if (msg == NULL) { |
| 1031 | return PLDM_ERROR_INVALID_DATA; |
| 1032 | } |
| 1033 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 1034 | struct pldm_header_info header = {0}; |
Jolie Ku | 6787f17 | 2020-03-19 11:15:53 +0800 | [diff] [blame] | 1035 | header.msg_type = PLDM_REQUEST; |
| 1036 | header.instance = instance_id; |
| 1037 | header.pldm_type = PLDM_PLATFORM; |
| 1038 | header.command = PLDM_GET_NUMERIC_EFFECTER_VALUE; |
| 1039 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 1040 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1041 | if (rc != PLDM_SUCCESS) { |
Jolie Ku | 6787f17 | 2020-03-19 11:15:53 +0800 | [diff] [blame] | 1042 | return rc; |
| 1043 | } |
| 1044 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 1045 | struct pldm_get_numeric_effecter_value_req *request = |
| 1046 | (struct pldm_get_numeric_effecter_value_req *)msg->payload; |
Jolie Ku | 6787f17 | 2020-03-19 11:15:53 +0800 | [diff] [blame] | 1047 | request->effecter_id = htole16(effecter_id); |
| 1048 | |
| 1049 | return PLDM_SUCCESS; |
| 1050 | } |
| 1051 | |
| 1052 | int encode_get_numeric_effecter_value_resp( |
| 1053 | uint8_t instance_id, uint8_t completion_code, uint8_t effecter_data_size, |
| 1054 | uint8_t effecter_oper_state, uint8_t *pending_value, uint8_t *present_value, |
| 1055 | struct pldm_msg *msg, size_t payload_length) |
| 1056 | { |
Jolie Ku | 6787f17 | 2020-03-19 11:15:53 +0800 | [diff] [blame] | 1057 | if (msg == NULL || pending_value == NULL || present_value == NULL) { |
| 1058 | return PLDM_ERROR_INVALID_DATA; |
| 1059 | } |
| 1060 | |
| 1061 | if (effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 1062 | return PLDM_ERROR_INVALID_DATA; |
| 1063 | } |
| 1064 | |
| 1065 | if (effecter_oper_state > EFFECTER_OPER_STATE_INTEST) { |
| 1066 | return PLDM_ERROR_INVALID_DATA; |
| 1067 | } |
| 1068 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 1069 | struct pldm_header_info header = {0}; |
Jolie Ku | 6787f17 | 2020-03-19 11:15:53 +0800 | [diff] [blame] | 1070 | header.msg_type = PLDM_RESPONSE; |
| 1071 | header.instance = instance_id; |
| 1072 | header.pldm_type = PLDM_PLATFORM; |
| 1073 | header.command = PLDM_GET_NUMERIC_EFFECTER_VALUE; |
| 1074 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 1075 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1076 | if (rc != PLDM_SUCCESS) { |
Jolie Ku | 6787f17 | 2020-03-19 11:15:53 +0800 | [diff] [blame] | 1077 | return rc; |
| 1078 | } |
| 1079 | |
| 1080 | struct pldm_get_numeric_effecter_value_resp *response = |
| 1081 | (struct pldm_get_numeric_effecter_value_resp *)msg->payload; |
| 1082 | |
| 1083 | response->completion_code = completion_code; |
| 1084 | response->effecter_data_size = effecter_data_size; |
| 1085 | response->effecter_oper_state = effecter_oper_state; |
| 1086 | |
| 1087 | if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 || |
| 1088 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) { |
| 1089 | if (payload_length != |
| 1090 | PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES) { |
| 1091 | return PLDM_ERROR_INVALID_LENGTH; |
| 1092 | } |
| 1093 | response->pending_and_present_values[0] = *pending_value; |
| 1094 | response->pending_and_present_values[1] = *present_value; |
| 1095 | |
| 1096 | } else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 1097 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT16) { |
| 1098 | if (payload_length != |
| 1099 | PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 2) { |
| 1100 | return PLDM_ERROR_INVALID_LENGTH; |
| 1101 | } |
Jolie Ku | 3cdbcfb | 2020-04-17 10:30:59 +0800 | [diff] [blame] | 1102 | uint16_t val_pending = *(uint16_t *)pending_value; |
| 1103 | val_pending = htole16(val_pending); |
| 1104 | memcpy(response->pending_and_present_values, &val_pending, |
| 1105 | sizeof(uint16_t)); |
| 1106 | uint16_t val_present = *(uint16_t *)present_value; |
| 1107 | val_present = htole16(val_present); |
| 1108 | memcpy( |
| 1109 | (response->pending_and_present_values + sizeof(uint16_t)), |
| 1110 | &val_present, sizeof(uint16_t)); |
Jolie Ku | 6787f17 | 2020-03-19 11:15:53 +0800 | [diff] [blame] | 1111 | |
| 1112 | } else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 1113 | effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 1114 | if (payload_length != |
| 1115 | PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 6) { |
| 1116 | return PLDM_ERROR_INVALID_LENGTH; |
| 1117 | } |
Jolie Ku | 3cdbcfb | 2020-04-17 10:30:59 +0800 | [diff] [blame] | 1118 | uint32_t val_pending = *(uint32_t *)pending_value; |
| 1119 | val_pending = htole32(val_pending); |
| 1120 | memcpy(response->pending_and_present_values, &val_pending, |
| 1121 | sizeof(uint32_t)); |
| 1122 | uint32_t val_present = *(uint32_t *)present_value; |
| 1123 | val_present = htole32(val_present); |
| 1124 | memcpy( |
| 1125 | (response->pending_and_present_values + sizeof(uint32_t)), |
| 1126 | &val_present, sizeof(uint32_t)); |
Jolie Ku | 6787f17 | 2020-03-19 11:15:53 +0800 | [diff] [blame] | 1127 | } |
| 1128 | return PLDM_SUCCESS; |
| 1129 | } |
| 1130 | |
| 1131 | int decode_get_numeric_effecter_value_req(const struct pldm_msg *msg, |
| 1132 | size_t payload_length, |
| 1133 | uint16_t *effecter_id) |
| 1134 | { |
| 1135 | if (msg == NULL || effecter_id == NULL) { |
| 1136 | return PLDM_ERROR_INVALID_DATA; |
| 1137 | } |
| 1138 | |
| 1139 | if (payload_length != PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES) { |
| 1140 | return PLDM_ERROR_INVALID_LENGTH; |
| 1141 | } |
| 1142 | |
| 1143 | struct pldm_get_numeric_effecter_value_req *request = |
| 1144 | (struct pldm_get_numeric_effecter_value_req *)msg->payload; |
| 1145 | |
| 1146 | *effecter_id = le16toh(request->effecter_id); |
| 1147 | |
| 1148 | return PLDM_SUCCESS; |
| 1149 | } |
| 1150 | |
| 1151 | int decode_get_numeric_effecter_value_resp( |
| 1152 | const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code, |
| 1153 | uint8_t *effecter_data_size, uint8_t *effecter_oper_state, |
| 1154 | uint8_t *pending_value, uint8_t *present_value) |
| 1155 | { |
| 1156 | if (msg == NULL || effecter_data_size == NULL || |
| 1157 | effecter_oper_state == NULL || pending_value == NULL || |
| 1158 | present_value == NULL) { |
| 1159 | return PLDM_ERROR_INVALID_DATA; |
| 1160 | } |
| 1161 | |
| 1162 | *completion_code = msg->payload[0]; |
| 1163 | if (PLDM_SUCCESS != *completion_code) { |
| 1164 | return PLDM_SUCCESS; |
| 1165 | } |
| 1166 | |
| 1167 | if (payload_length < PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES) { |
| 1168 | return PLDM_ERROR_INVALID_LENGTH; |
| 1169 | } |
| 1170 | |
| 1171 | struct pldm_get_numeric_effecter_value_resp *response = |
| 1172 | (struct pldm_get_numeric_effecter_value_resp *)msg->payload; |
| 1173 | |
| 1174 | *effecter_data_size = response->effecter_data_size; |
| 1175 | *effecter_oper_state = response->effecter_oper_state; |
| 1176 | |
| 1177 | if (*effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 1178 | return PLDM_ERROR_INVALID_DATA; |
| 1179 | } |
| 1180 | |
| 1181 | if (*effecter_oper_state > EFFECTER_OPER_STATE_INTEST) { |
| 1182 | return PLDM_ERROR_INVALID_DATA; |
| 1183 | } |
| 1184 | |
| 1185 | if (*effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 || |
| 1186 | *effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) { |
| 1187 | if (payload_length != |
| 1188 | PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES) { |
| 1189 | return PLDM_ERROR_INVALID_LENGTH; |
| 1190 | } |
| 1191 | memcpy(pending_value, response->pending_and_present_values, 1); |
| 1192 | memcpy(present_value, &response->pending_and_present_values[1], |
| 1193 | 1); |
| 1194 | |
| 1195 | } else if (*effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 1196 | *effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT16) { |
| 1197 | if (payload_length != |
| 1198 | PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 2) { |
| 1199 | return PLDM_ERROR_INVALID_LENGTH; |
| 1200 | } |
Jolie Ku | 3cdbcfb | 2020-04-17 10:30:59 +0800 | [diff] [blame] | 1201 | memcpy(pending_value, response->pending_and_present_values, |
| 1202 | sizeof(uint16_t)); |
| 1203 | uint16_t *val_pending = (uint16_t *)pending_value; |
| 1204 | *val_pending = le16toh(*val_pending); |
| 1205 | memcpy( |
| 1206 | present_value, |
| 1207 | (response->pending_and_present_values + sizeof(uint16_t)), |
| 1208 | sizeof(uint16_t)); |
| 1209 | uint16_t *val_present = (uint16_t *)present_value; |
| 1210 | *val_present = le16toh(*val_present); |
Jolie Ku | 6787f17 | 2020-03-19 11:15:53 +0800 | [diff] [blame] | 1211 | |
| 1212 | } else if (*effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 1213 | *effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 1214 | if (payload_length != |
| 1215 | PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 6) { |
| 1216 | return PLDM_ERROR_INVALID_LENGTH; |
| 1217 | } |
Jolie Ku | 3cdbcfb | 2020-04-17 10:30:59 +0800 | [diff] [blame] | 1218 | memcpy(pending_value, response->pending_and_present_values, |
| 1219 | sizeof(uint32_t)); |
| 1220 | uint32_t *val_pending = (uint32_t *)pending_value; |
| 1221 | *val_pending = le32toh(*val_pending); |
| 1222 | memcpy( |
| 1223 | present_value, |
| 1224 | (response->pending_and_present_values + sizeof(uint32_t)), |
| 1225 | sizeof(uint32_t)); |
| 1226 | uint32_t *val_present = (uint32_t *)present_value; |
| 1227 | *val_present = le32toh(*val_present); |
Jolie Ku | 6787f17 | 2020-03-19 11:15:53 +0800 | [diff] [blame] | 1228 | } |
| 1229 | return PLDM_SUCCESS; |
Zach Clark | 3dba2bf | 2020-03-31 10:58:03 -0500 | [diff] [blame] | 1230 | } |
Zahed Hossain | 9be087c | 2020-04-02 02:26:41 -0500 | [diff] [blame] | 1231 | |
Zach Clark | 36ad1f5 | 2020-04-13 07:04:15 -0500 | [diff] [blame] | 1232 | int encode_pldm_pdr_repository_chg_event_data( |
| 1233 | uint8_t event_data_format, uint8_t number_of_change_records, |
| 1234 | const uint8_t *event_data_operations, |
| 1235 | const uint8_t *numbers_of_change_entries, |
| 1236 | const uint32_t *const *change_entries, |
| 1237 | struct pldm_pdr_repository_chg_event_data *event_data, |
| 1238 | size_t *actual_change_records_size, size_t max_change_records_size) |
| 1239 | { |
| 1240 | if (event_data_operations == NULL || |
| 1241 | numbers_of_change_entries == NULL || change_entries == NULL) { |
| 1242 | return PLDM_ERROR_INVALID_DATA; |
| 1243 | } |
| 1244 | |
| 1245 | size_t expected_size = |
| 1246 | sizeof(event_data_format) + sizeof(number_of_change_records); |
| 1247 | |
| 1248 | expected_size += |
| 1249 | sizeof(*event_data_operations) * number_of_change_records; |
| 1250 | expected_size += |
| 1251 | sizeof(*numbers_of_change_entries) * number_of_change_records; |
| 1252 | |
| 1253 | for (uint8_t i = 0; i < number_of_change_records; ++i) { |
| 1254 | expected_size += |
| 1255 | sizeof(*change_entries[0]) * numbers_of_change_entries[i]; |
| 1256 | } |
| 1257 | |
| 1258 | *actual_change_records_size = expected_size; |
| 1259 | |
| 1260 | if (event_data == NULL) { |
| 1261 | return PLDM_SUCCESS; |
| 1262 | } |
| 1263 | |
| 1264 | if (max_change_records_size < expected_size) { |
| 1265 | return PLDM_ERROR_INVALID_LENGTH; |
| 1266 | } |
| 1267 | |
| 1268 | event_data->event_data_format = event_data_format; |
| 1269 | event_data->number_of_change_records = number_of_change_records; |
| 1270 | |
| 1271 | struct pldm_pdr_repository_change_record_data *record_data = |
| 1272 | (struct pldm_pdr_repository_change_record_data *) |
| 1273 | event_data->change_records; |
| 1274 | |
| 1275 | for (uint8_t i = 0; i < number_of_change_records; ++i) { |
| 1276 | record_data->event_data_operation = event_data_operations[i]; |
| 1277 | record_data->number_of_change_entries = |
| 1278 | numbers_of_change_entries[i]; |
| 1279 | |
| 1280 | for (uint8_t j = 0; j < record_data->number_of_change_entries; |
| 1281 | ++j) { |
| 1282 | record_data->change_entry[j] = |
| 1283 | htole32(change_entries[i][j]); |
| 1284 | } |
| 1285 | |
| 1286 | record_data = (struct pldm_pdr_repository_change_record_data |
| 1287 | *)(record_data->change_entry + |
| 1288 | record_data->number_of_change_entries); |
| 1289 | } |
| 1290 | |
| 1291 | return PLDM_SUCCESS; |
| 1292 | } |
| 1293 | |
Zahed Hossain | 9be087c | 2020-04-02 02:26:41 -0500 | [diff] [blame] | 1294 | int decode_pldm_pdr_repository_chg_event_data(const uint8_t *event_data, |
| 1295 | size_t event_data_size, |
| 1296 | uint8_t *event_data_format, |
| 1297 | uint8_t *number_of_change_records, |
| 1298 | size_t *change_record_data_offset) |
| 1299 | { |
| 1300 | if (event_data == NULL || event_data_format == NULL || |
| 1301 | number_of_change_records == NULL || |
| 1302 | change_record_data_offset == NULL) { |
| 1303 | return PLDM_ERROR_INVALID_DATA; |
| 1304 | } |
| 1305 | if (event_data_size < PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH) { |
| 1306 | return PLDM_ERROR_INVALID_LENGTH; |
| 1307 | } |
| 1308 | |
| 1309 | struct pldm_pdr_repository_chg_event_data |
| 1310 | *pdr_repository_chg_event_data = |
| 1311 | (struct pldm_pdr_repository_chg_event_data *)event_data; |
| 1312 | |
| 1313 | *event_data_format = pdr_repository_chg_event_data->event_data_format; |
| 1314 | *number_of_change_records = |
| 1315 | pdr_repository_chg_event_data->number_of_change_records; |
| 1316 | *change_record_data_offset = |
| 1317 | sizeof(*event_data_format) + sizeof(*number_of_change_records); |
| 1318 | |
| 1319 | return PLDM_SUCCESS; |
| 1320 | } |
| 1321 | |
| 1322 | int decode_pldm_pdr_repository_change_record_data( |
| 1323 | const uint8_t *change_record_data, size_t change_record_data_size, |
| 1324 | uint8_t *event_data_operation, uint8_t *number_of_change_entries, |
| 1325 | size_t *change_entry_data_offset) |
| 1326 | { |
| 1327 | if (change_record_data == NULL || event_data_operation == NULL || |
| 1328 | number_of_change_entries == NULL || |
| 1329 | change_entry_data_offset == NULL) { |
| 1330 | return PLDM_ERROR_INVALID_DATA; |
| 1331 | } |
| 1332 | if (change_record_data_size < |
| 1333 | PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH) { |
| 1334 | return PLDM_ERROR_INVALID_LENGTH; |
| 1335 | } |
| 1336 | |
| 1337 | struct pldm_pdr_repository_change_record_data |
| 1338 | *pdr_repository_change_record_data = |
| 1339 | (struct pldm_pdr_repository_change_record_data *) |
| 1340 | change_record_data; |
| 1341 | |
| 1342 | *event_data_operation = |
| 1343 | pdr_repository_change_record_data->event_data_operation; |
| 1344 | *number_of_change_entries = |
| 1345 | pdr_repository_change_record_data->number_of_change_entries; |
| 1346 | *change_entry_data_offset = |
| 1347 | sizeof(*event_data_operation) + sizeof(*number_of_change_entries); |
| 1348 | |
| 1349 | return PLDM_SUCCESS; |
| 1350 | } |
Jolie Ku | f798c8f | 2020-04-14 11:18:06 +0800 | [diff] [blame] | 1351 | |
| 1352 | int encode_get_sensor_reading_req(uint8_t instance_id, uint16_t sensor_id, |
| 1353 | uint8_t rearm_event_state, |
| 1354 | struct pldm_msg *msg) |
| 1355 | { |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 1356 | if (msg == NULL) { |
| 1357 | return PLDM_ERROR_INVALID_DATA; |
| 1358 | } |
Jolie Ku | f798c8f | 2020-04-14 11:18:06 +0800 | [diff] [blame] | 1359 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 1360 | struct pldm_header_info header = {0}; |
Jolie Ku | f798c8f | 2020-04-14 11:18:06 +0800 | [diff] [blame] | 1361 | header.msg_type = PLDM_REQUEST; |
| 1362 | header.instance = instance_id; |
| 1363 | header.pldm_type = PLDM_PLATFORM; |
| 1364 | header.command = PLDM_GET_SENSOR_READING; |
| 1365 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 1366 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1367 | if (rc != PLDM_SUCCESS) { |
Jolie Ku | f798c8f | 2020-04-14 11:18:06 +0800 | [diff] [blame] | 1368 | return rc; |
| 1369 | } |
| 1370 | |
| 1371 | struct pldm_get_sensor_reading_req *request = |
| 1372 | (struct pldm_get_sensor_reading_req *)msg->payload; |
| 1373 | |
| 1374 | request->sensor_id = htole16(sensor_id); |
| 1375 | request->rearm_event_state = rearm_event_state; |
| 1376 | |
| 1377 | return PLDM_SUCCESS; |
| 1378 | } |
| 1379 | |
| 1380 | int decode_get_sensor_reading_resp( |
| 1381 | const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code, |
| 1382 | uint8_t *sensor_data_size, uint8_t *sensor_operational_state, |
| 1383 | uint8_t *sensor_event_message_enable, uint8_t *present_state, |
| 1384 | uint8_t *previous_state, uint8_t *event_state, uint8_t *present_reading) |
| 1385 | { |
| 1386 | if (msg == NULL || completion_code == NULL || |
| 1387 | sensor_data_size == NULL || sensor_operational_state == NULL || |
| 1388 | sensor_event_message_enable == NULL || present_state == NULL || |
| 1389 | previous_state == NULL || event_state == NULL || |
| 1390 | present_reading == NULL) { |
| 1391 | return PLDM_ERROR_INVALID_DATA; |
| 1392 | } |
| 1393 | |
| 1394 | *completion_code = msg->payload[0]; |
| 1395 | if (PLDM_SUCCESS != *completion_code) { |
| 1396 | return PLDM_SUCCESS; |
| 1397 | } |
| 1398 | |
| 1399 | if (payload_length < PLDM_GET_SENSOR_READING_MIN_RESP_BYTES) { |
| 1400 | return PLDM_ERROR_INVALID_LENGTH; |
| 1401 | } |
| 1402 | |
| 1403 | struct pldm_get_sensor_reading_resp *response = |
| 1404 | (struct pldm_get_sensor_reading_resp *)msg->payload; |
| 1405 | |
| 1406 | if (response->sensor_data_size > PLDM_SENSOR_DATA_SIZE_SINT32) { |
| 1407 | return PLDM_ERROR_INVALID_DATA; |
| 1408 | } |
| 1409 | if (response->sensor_data_size > *sensor_data_size) { |
| 1410 | return PLDM_ERROR_INVALID_LENGTH; |
| 1411 | } |
| 1412 | |
| 1413 | *sensor_data_size = response->sensor_data_size; |
| 1414 | *sensor_operational_state = response->sensor_operational_state; |
| 1415 | *sensor_event_message_enable = response->sensor_event_message_enable; |
| 1416 | *present_state = response->present_state; |
| 1417 | *previous_state = response->previous_state; |
| 1418 | *event_state = response->event_state; |
| 1419 | |
| 1420 | if (*sensor_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 || |
| 1421 | *sensor_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) { |
| 1422 | if (payload_length != PLDM_GET_SENSOR_READING_MIN_RESP_BYTES) { |
| 1423 | return PLDM_ERROR_INVALID_LENGTH; |
| 1424 | } |
| 1425 | *present_reading = response->present_reading[0]; |
| 1426 | |
| 1427 | } else if (*sensor_data_size == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 1428 | *sensor_data_size == PLDM_EFFECTER_DATA_SIZE_SINT16) { |
| 1429 | if (payload_length != |
| 1430 | PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 1) { |
| 1431 | return PLDM_ERROR_INVALID_LENGTH; |
| 1432 | } |
| 1433 | memcpy(present_reading, response->present_reading, 2); |
| 1434 | uint16_t *val = (uint16_t *)(present_reading); |
| 1435 | *val = le16toh(*val); |
| 1436 | |
| 1437 | } else if (*sensor_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 1438 | *sensor_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 1439 | if (payload_length != |
| 1440 | PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 3) { |
| 1441 | return PLDM_ERROR_INVALID_LENGTH; |
| 1442 | } |
| 1443 | memcpy(present_reading, response->present_reading, 4); |
| 1444 | uint32_t *val = (uint32_t *)(present_reading); |
| 1445 | *val = le32toh(*val); |
| 1446 | } |
| 1447 | |
| 1448 | return PLDM_SUCCESS; |
| 1449 | } |
| 1450 | |
| 1451 | int encode_get_sensor_reading_resp( |
| 1452 | uint8_t instance_id, uint8_t completion_code, uint8_t sensor_data_size, |
| 1453 | uint8_t sensor_operational_state, uint8_t sensor_event_message_enable, |
| 1454 | uint8_t present_state, uint8_t previous_state, uint8_t event_state, |
| 1455 | uint8_t *present_reading, struct pldm_msg *msg, size_t payload_length) |
| 1456 | { |
Jolie Ku | f798c8f | 2020-04-14 11:18:06 +0800 | [diff] [blame] | 1457 | if (msg == NULL || present_reading == NULL) { |
| 1458 | return PLDM_ERROR_INVALID_DATA; |
| 1459 | } |
| 1460 | |
| 1461 | if (sensor_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 1462 | return PLDM_ERROR_INVALID_DATA; |
| 1463 | } |
| 1464 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 1465 | struct pldm_header_info header = {0}; |
Jolie Ku | f798c8f | 2020-04-14 11:18:06 +0800 | [diff] [blame] | 1466 | header.msg_type = PLDM_RESPONSE; |
| 1467 | header.instance = instance_id; |
| 1468 | header.pldm_type = PLDM_PLATFORM; |
| 1469 | header.command = PLDM_GET_SENSOR_READING; |
| 1470 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 1471 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1472 | if (rc != PLDM_SUCCESS) { |
Jolie Ku | f798c8f | 2020-04-14 11:18:06 +0800 | [diff] [blame] | 1473 | return rc; |
| 1474 | } |
| 1475 | |
| 1476 | struct pldm_get_sensor_reading_resp *response = |
| 1477 | (struct pldm_get_sensor_reading_resp *)msg->payload; |
| 1478 | |
| 1479 | response->completion_code = completion_code; |
| 1480 | response->sensor_data_size = sensor_data_size; |
| 1481 | response->sensor_operational_state = sensor_operational_state; |
| 1482 | response->sensor_event_message_enable = sensor_event_message_enable; |
| 1483 | response->present_state = present_state; |
| 1484 | response->previous_state = previous_state; |
| 1485 | response->event_state = event_state; |
| 1486 | |
| 1487 | if (sensor_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 || |
| 1488 | sensor_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) { |
| 1489 | if (payload_length != PLDM_GET_SENSOR_READING_MIN_RESP_BYTES) { |
| 1490 | return PLDM_ERROR_INVALID_LENGTH; |
| 1491 | } |
| 1492 | response->present_reading[0] = *present_reading; |
| 1493 | |
| 1494 | } else if (sensor_data_size == PLDM_EFFECTER_DATA_SIZE_UINT16 || |
| 1495 | sensor_data_size == PLDM_EFFECTER_DATA_SIZE_SINT16) { |
| 1496 | if (payload_length != |
| 1497 | PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 1) { |
| 1498 | return PLDM_ERROR_INVALID_LENGTH; |
| 1499 | } |
| 1500 | uint16_t val = *(uint16_t *)present_reading; |
| 1501 | val = htole16(val); |
| 1502 | memcpy(response->present_reading, &val, 2); |
| 1503 | |
| 1504 | } else if (sensor_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 || |
| 1505 | sensor_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) { |
| 1506 | if (payload_length != |
| 1507 | PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 3) { |
| 1508 | return PLDM_ERROR_INVALID_LENGTH; |
| 1509 | } |
| 1510 | uint32_t val = *(uint32_t *)present_reading; |
| 1511 | val = htole32(val); |
| 1512 | memcpy(response->present_reading, &val, 4); |
| 1513 | } |
| 1514 | |
| 1515 | return PLDM_SUCCESS; |
| 1516 | } |
| 1517 | |
| 1518 | int decode_get_sensor_reading_req(const struct pldm_msg *msg, |
| 1519 | size_t payload_length, uint16_t *sensor_id, |
| 1520 | uint8_t *rearm_event_state) |
| 1521 | { |
| 1522 | if (msg == NULL || sensor_id == NULL || rearm_event_state == NULL) { |
| 1523 | return PLDM_ERROR_INVALID_DATA; |
| 1524 | } |
| 1525 | |
| 1526 | if (payload_length != PLDM_GET_SENSOR_READING_REQ_BYTES) { |
| 1527 | return PLDM_ERROR_INVALID_LENGTH; |
| 1528 | } |
| 1529 | |
| 1530 | struct pldm_get_sensor_reading_req *request = |
| 1531 | (struct pldm_get_sensor_reading_req *)msg->payload; |
| 1532 | |
| 1533 | *sensor_id = le16toh(request->sensor_id); |
| 1534 | *rearm_event_state = request->rearm_event_state; |
| 1535 | |
| 1536 | return PLDM_SUCCESS; |
| 1537 | } |
Sagar Srinivas | 535bccd | 2021-03-24 12:18:26 -0500 | [diff] [blame] | 1538 | |
| 1539 | int encode_set_event_receiver_req(uint8_t instance_id, |
| 1540 | uint8_t event_message_global_enable, |
| 1541 | uint8_t transport_protocol_type, |
| 1542 | uint8_t event_receiver_address_info, |
| 1543 | uint16_t heartbeat_timer, |
| 1544 | struct pldm_msg *msg) |
| 1545 | { |
Sagar Srinivas | 535bccd | 2021-03-24 12:18:26 -0500 | [diff] [blame] | 1546 | if (msg == NULL) { |
| 1547 | return PLDM_ERROR_INVALID_DATA; |
| 1548 | } |
| 1549 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 1550 | if (transport_protocol_type != PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP) { |
| 1551 | return PLDM_ERROR_INVALID_DATA; |
| 1552 | } |
| 1553 | |
| 1554 | struct pldm_header_info header = {0}; |
Sagar Srinivas | 535bccd | 2021-03-24 12:18:26 -0500 | [diff] [blame] | 1555 | header.msg_type = PLDM_REQUEST; |
| 1556 | header.instance = instance_id; |
| 1557 | header.pldm_type = PLDM_PLATFORM; |
| 1558 | header.command = PLDM_SET_EVENT_RECEIVER; |
| 1559 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 1560 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1561 | if (rc != PLDM_SUCCESS) { |
Sagar Srinivas | 535bccd | 2021-03-24 12:18:26 -0500 | [diff] [blame] | 1562 | return rc; |
| 1563 | } |
| 1564 | |
| 1565 | struct pldm_set_event_receiver_req *request = |
| 1566 | (struct pldm_set_event_receiver_req *)msg->payload; |
| 1567 | request->event_message_global_enable = event_message_global_enable; |
| 1568 | |
Sagar Srinivas | 535bccd | 2021-03-24 12:18:26 -0500 | [diff] [blame] | 1569 | request->transport_protocol_type = transport_protocol_type; |
| 1570 | request->event_receiver_address_info = event_receiver_address_info; |
| 1571 | |
| 1572 | if (event_message_global_enable == |
| 1573 | PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE) { |
| 1574 | if (heartbeat_timer == 0) { |
| 1575 | return PLDM_ERROR_INVALID_DATA; |
| 1576 | } |
| 1577 | request->heartbeat_timer = htole16(heartbeat_timer); |
| 1578 | } |
| 1579 | |
| 1580 | return PLDM_SUCCESS; |
| 1581 | } |
| 1582 | |
| 1583 | int decode_set_event_receiver_resp(const struct pldm_msg *msg, |
| 1584 | size_t payload_length, |
| 1585 | uint8_t *completion_code) |
| 1586 | { |
| 1587 | if (msg == NULL || completion_code == NULL) { |
| 1588 | return PLDM_ERROR_INVALID_DATA; |
| 1589 | } |
| 1590 | |
| 1591 | *completion_code = msg->payload[0]; |
| 1592 | if (PLDM_SUCCESS != *completion_code) { |
| 1593 | return PLDM_SUCCESS; |
| 1594 | } |
| 1595 | |
| 1596 | if (payload_length > PLDM_SET_EVENT_RECEIVER_RESP_BYTES) { |
| 1597 | return PLDM_ERROR_INVALID_LENGTH; |
| 1598 | } |
| 1599 | |
| 1600 | return PLDM_SUCCESS; |
| 1601 | } |
Sridevi Ramesh | 7418752 | 2021-04-08 09:50:22 -0500 | [diff] [blame] | 1602 | |
| 1603 | int decode_set_event_receiver_req(const struct pldm_msg *msg, |
| 1604 | size_t payload_length, |
| 1605 | uint8_t *event_message_global_enable, |
| 1606 | uint8_t *transport_protocol_type, |
| 1607 | uint8_t *event_receiver_address_info, |
| 1608 | uint16_t *heartbeat_timer) |
| 1609 | |
| 1610 | { |
| 1611 | if (msg == NULL || event_message_global_enable == NULL || |
| 1612 | transport_protocol_type == NULL || |
| 1613 | event_receiver_address_info == NULL || heartbeat_timer == NULL) { |
| 1614 | return PLDM_ERROR_INVALID_DATA; |
| 1615 | } |
| 1616 | |
| 1617 | if (payload_length != PLDM_SET_EVENT_RECEIVER_REQ_BYTES) { |
| 1618 | return PLDM_ERROR_INVALID_LENGTH; |
| 1619 | } |
| 1620 | |
| 1621 | struct pldm_set_event_receiver_req *request = |
| 1622 | (struct pldm_set_event_receiver_req *)msg->payload; |
| 1623 | |
| 1624 | if ((*event_message_global_enable == |
| 1625 | PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE) && |
| 1626 | (*heartbeat_timer == 0)) { |
| 1627 | return PLDM_ERROR_INVALID_DATA; |
| 1628 | } |
| 1629 | |
| 1630 | *event_message_global_enable = request->event_message_global_enable, |
| 1631 | *transport_protocol_type = request->transport_protocol_type, |
| 1632 | *event_receiver_address_info = request->event_receiver_address_info, |
| 1633 | *heartbeat_timer = le16toh(request->heartbeat_timer); |
| 1634 | |
| 1635 | return PLDM_SUCCESS; |
| 1636 | } |
| 1637 | |
| 1638 | int encode_set_event_receiver_resp(uint8_t instance_id, uint8_t completion_code, |
| 1639 | struct pldm_msg *msg) |
| 1640 | |
| 1641 | { |
Sridevi Ramesh | 7418752 | 2021-04-08 09:50:22 -0500 | [diff] [blame] | 1642 | if (msg == NULL) { |
| 1643 | return PLDM_ERROR_INVALID_DATA; |
| 1644 | } |
| 1645 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 1646 | struct pldm_header_info header = {0}; |
Sridevi Ramesh | 7418752 | 2021-04-08 09:50:22 -0500 | [diff] [blame] | 1647 | header.instance = instance_id; |
| 1648 | header.msg_type = PLDM_RESPONSE; |
| 1649 | header.pldm_type = PLDM_PLATFORM; |
| 1650 | header.command = PLDM_SET_EVENT_RECEIVER; |
| 1651 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 1652 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1653 | if (rc != PLDM_SUCCESS) { |
| 1654 | return rc; |
| 1655 | } |
Sridevi Ramesh | 7418752 | 2021-04-08 09:50:22 -0500 | [diff] [blame] | 1656 | |
George Liu | b7095ff | 2021-06-14 16:01:57 +0800 | [diff] [blame] | 1657 | msg->payload[0] = completion_code; |
| 1658 | |
| 1659 | return PLDM_SUCCESS; |
Sridevi Ramesh | 7418752 | 2021-04-08 09:50:22 -0500 | [diff] [blame] | 1660 | } |