blob: 79fd9f7e89bf400da33730d7ddb0ecb372c0ac52 [file] [log] [blame]
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +05301#include <endian.h>
2#include <string.h>
3
4#include "fru.h"
5
6int 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
25int 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
63int 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}