Jinu Joy Thomas | 7f57f44 | 2019-06-13 20:38:49 +0530 | [diff] [blame] | 1 | #include "file_io.h" |
| 2 | #include <endian.h> |
| 3 | #include <string.h> |
| 4 | |
| 5 | int decode_rw_file_memory_req(const uint8_t *msg, size_t payload_length, |
| 6 | uint32_t *file_handle, uint32_t *offset, |
| 7 | uint32_t *length, uint64_t *address) |
| 8 | { |
| 9 | if (msg == NULL || file_handle == NULL || offset == NULL || |
| 10 | length == NULL || address == NULL) { |
| 11 | return PLDM_ERROR_INVALID_DATA; |
| 12 | } |
| 13 | |
| 14 | if (payload_length != PLDM_RW_FILE_MEM_REQ_BYTES) { |
| 15 | return PLDM_ERROR_INVALID_LENGTH; |
| 16 | } |
| 17 | |
| 18 | *file_handle = le32toh(*((uint32_t *)msg)); |
| 19 | *offset = le32toh(*((uint32_t *)(msg + sizeof(*file_handle)))); |
| 20 | *length = le32toh( |
| 21 | *((uint32_t *)(msg + sizeof(*file_handle) + sizeof(*offset)))); |
| 22 | *address = le64toh(*((uint64_t *)(msg + sizeof(*file_handle) + |
| 23 | sizeof(*offset) + sizeof(*length)))); |
| 24 | |
| 25 | return PLDM_SUCCESS; |
| 26 | } |
| 27 | |
| 28 | int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command, |
| 29 | uint8_t completion_code, uint32_t length, |
| 30 | struct pldm_msg *msg) |
| 31 | { |
| 32 | struct pldm_header_info header = {0}; |
| 33 | int rc = PLDM_SUCCESS; |
| 34 | |
| 35 | uint8_t *payload = msg->payload; |
| 36 | *payload = completion_code; |
| 37 | |
| 38 | header.msg_type = PLDM_RESPONSE; |
| 39 | header.instance = instance_id; |
| 40 | header.pldm_type = PLDM_IBM_OEM_TYPE; |
| 41 | header.command = command; |
| 42 | |
| 43 | if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) { |
| 44 | return rc; |
| 45 | } |
| 46 | |
| 47 | if (msg->payload[0] == PLDM_SUCCESS) { |
| 48 | uint8_t *dst = msg->payload + sizeof(completion_code); |
| 49 | length = htole32(length); |
| 50 | memcpy(dst, &length, sizeof(length)); |
| 51 | } |
| 52 | |
| 53 | return PLDM_SUCCESS; |
| 54 | } |