Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 1 | #include <endian.h> |
| 2 | #include <string.h> |
| 3 | |
| 4 | #include "fru.h" |
| 5 | |
| 6 | int encode_get_fru_record_table_metadata_req(uint8_t instance_id, |
| 7 | struct pldm_msg *msg) |
| 8 | { |
| 9 | if (msg == NULL) { |
| 10 | return PLDM_ERROR_INVALID_DATA; |
| 11 | } |
| 12 | |
| 13 | struct pldm_header_info header = {0}; |
| 14 | header.instance = instance_id; |
| 15 | header.msg_type = PLDM_REQUEST; |
| 16 | header.pldm_type = PLDM_FRU; |
| 17 | header.command = PLDM_GET_FRU_RECORD_TABLE_METADATA; |
| 18 | int rc = pack_pldm_header(&header, &(msg->hdr)); |
| 19 | if (PLDM_SUCCESS != rc) { |
| 20 | return rc; |
| 21 | } |
| 22 | return PLDM_SUCCESS; |
| 23 | } |
| 24 | |
| 25 | int decode_get_fru_record_table_metadata_resp( |
| 26 | const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code, |
| 27 | uint8_t *fru_data_major_version, uint8_t *fru_data_minor_version, |
| 28 | uint32_t *fru_table_maximum_size, uint32_t *fru_table_length, |
| 29 | uint16_t *total_record_set_identifiers, uint16_t *total_table_records, |
| 30 | uint32_t *checksum) |
| 31 | { |
| 32 | if (msg == NULL || completion_code == NULL || |
| 33 | fru_data_major_version == NULL || fru_data_minor_version == NULL || |
| 34 | fru_table_maximum_size == NULL || fru_table_length == NULL || |
| 35 | total_record_set_identifiers == NULL || |
| 36 | total_table_records == NULL || checksum == NULL) { |
| 37 | return PLDM_ERROR_INVALID_DATA; |
| 38 | } |
| 39 | |
| 40 | if (payload_length != PLDM_GET_FRU_RECORD_TABLE_METADATA_RESP_BYTES) { |
| 41 | return PLDM_ERROR_INVALID_LENGTH; |
| 42 | } |
| 43 | |
| 44 | struct pldm_get_fru_record_table_metadata_resp *response = |
| 45 | (struct pldm_get_fru_record_table_metadata_resp *)msg->payload; |
| 46 | *completion_code = response->completion_code; |
| 47 | if (PLDM_SUCCESS != *completion_code) { |
| 48 | return PLDM_SUCCESS; |
| 49 | }; |
| 50 | |
| 51 | *fru_data_major_version = response->fru_data_major_version; |
| 52 | *fru_data_minor_version = response->fru_data_minor_version; |
| 53 | *fru_table_maximum_size = le32toh(response->fru_table_maximum_size); |
| 54 | *fru_table_length = le32toh(response->fru_table_length); |
| 55 | *total_record_set_identifiers = |
| 56 | le16toh(response->total_record_set_identifiers); |
| 57 | *total_table_records = le16toh(response->total_table_records); |
| 58 | *checksum = le32toh(response->checksum); |
| 59 | |
| 60 | return PLDM_SUCCESS; |
| 61 | } |
| 62 | |
| 63 | int encode_get_fru_record_table_metadata_resp( |
| 64 | uint8_t instance_id, uint8_t completion_code, |
| 65 | uint8_t fru_data_major_version, uint8_t fru_data_minor_version, |
| 66 | uint32_t fru_table_maximum_size, uint32_t fru_table_length, |
| 67 | uint16_t total_record_set_identifiers, uint16_t total_table_records, |
| 68 | uint32_t checksum, struct pldm_msg *msg) |
| 69 | { |
| 70 | |
| 71 | if (msg == NULL) { |
| 72 | return PLDM_ERROR_INVALID_DATA; |
| 73 | } |
| 74 | |
| 75 | struct pldm_header_info header = {0}; |
| 76 | header.msg_type = PLDM_RESPONSE; |
| 77 | header.instance = instance_id; |
| 78 | header.pldm_type = PLDM_FRU; |
| 79 | header.command = PLDM_GET_FRU_RECORD_TABLE_METADATA; |
| 80 | int rc = pack_pldm_header(&header, &(msg->hdr)); |
| 81 | if (PLDM_SUCCESS != rc) { |
| 82 | return rc; |
| 83 | } |
| 84 | |
| 85 | struct pldm_get_fru_record_table_metadata_resp *response = |
| 86 | (struct pldm_get_fru_record_table_metadata_resp *)msg->payload; |
| 87 | response->completion_code = completion_code; |
| 88 | if (response->completion_code == PLDM_SUCCESS) { |
| 89 | response->fru_data_major_version = fru_data_major_version; |
| 90 | response->fru_data_minor_version = fru_data_minor_version; |
| 91 | response->fru_table_maximum_size = |
| 92 | htole32(fru_table_maximum_size); |
| 93 | response->fru_table_length = htole32(fru_table_length); |
| 94 | response->total_record_set_identifiers = |
| 95 | htole16(total_record_set_identifiers); |
| 96 | response->total_table_records = htole16(total_table_records); |
| 97 | response->checksum = htole32(checksum); |
| 98 | } |
| 99 | |
| 100 | return PLDM_SUCCESS; |
| 101 | } |
PriyangaRamasamy | 497665a | 2019-07-30 12:48:25 +0530 | [diff] [blame] | 102 | |
| 103 | int decode_get_fru_record_table_req(const struct pldm_msg *msg, |
| 104 | size_t payload_length, |
| 105 | uint32_t *data_transfer_handle, |
| 106 | uint8_t *transfer_operation_flag) |
| 107 | { |
| 108 | if (msg == NULL || data_transfer_handle == NULL || |
| 109 | transfer_operation_flag == NULL) { |
| 110 | return PLDM_ERROR_INVALID_DATA; |
| 111 | } |
| 112 | |
| 113 | if (payload_length != PLDM_GET_FRU_RECORD_TABLE_REQ_BYTES) { |
| 114 | return PLDM_ERROR_INVALID_LENGTH; |
| 115 | } |
| 116 | |
| 117 | struct pldm_get_fru_record_table_req *req = |
| 118 | (struct pldm_get_fru_record_table_req *)msg->payload; |
| 119 | |
| 120 | *data_transfer_handle = le32toh(req->data_transfer_handle); |
| 121 | *transfer_operation_flag = req->transfer_operation_flag; |
| 122 | |
| 123 | return PLDM_SUCCESS; |
| 124 | } |
| 125 | |
| 126 | int encode_get_fru_record_table_resp(uint8_t instance_id, |
| 127 | uint8_t completion_code, |
| 128 | uint32_t next_data_transfer_handle, |
| 129 | uint8_t transfer_flag, |
| 130 | struct pldm_msg *msg) |
| 131 | { |
| 132 | struct pldm_header_info header = {0}; |
| 133 | int rc = PLDM_ERROR_INVALID_DATA; |
| 134 | |
| 135 | header.msg_type = PLDM_RESPONSE; |
| 136 | header.instance = instance_id; |
| 137 | header.pldm_type = PLDM_FRU; |
| 138 | header.command = PLDM_GET_FRU_RECORD_TABLE; |
| 139 | |
| 140 | if (msg == NULL) { |
| 141 | return rc; |
| 142 | } |
| 143 | |
| 144 | if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) { |
| 145 | return rc; |
| 146 | } |
| 147 | |
| 148 | struct pldm_get_fru_record_table_resp *resp = |
| 149 | (struct pldm_get_fru_record_table_resp *)msg->payload; |
| 150 | |
| 151 | resp->completion_code = completion_code; |
| 152 | |
| 153 | if (resp->completion_code == PLDM_SUCCESS) { |
| 154 | |
| 155 | resp->next_data_transfer_handle = |
| 156 | htole32(next_data_transfer_handle); |
| 157 | resp->transfer_flag = transfer_flag; |
| 158 | } |
| 159 | |
| 160 | return PLDM_SUCCESS; |
| 161 | } |