blob: fc9cc5664a88798f3f2b28939d3ffe279e9ad15d [file] [log] [blame]
Sampa Misra0db1dfa2019-03-19 00:15:31 -05001#include <endian.h>
2#include <string.h>
3
4#include "platform.h"
5
6int 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
vkaverapa6575b82019-04-03 05:33:52 -050013 msg->payload[0] = completion_code;
Sampa Misra0db1dfa2019-03-19 00:15:31 -050014
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
vkaverap98a2c192019-04-03 05:33:52 -050025int 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
Priyanga7257fdf2019-06-10 01:59:45 -050047 struct pldm_set_state_effecter_states_req *request =
48 (struct pldm_set_state_effecter_states_req *)msg->payload;
vkaverap98a2c192019-04-03 05:33:52 -050049 effecter_id = htole16(effecter_id);
Priyanga7257fdf2019-06-10 01:59:45 -050050 request->effecter_id = effecter_id;
51 request->comp_effecter_count = comp_effecter_count;
52 memcpy(request->field, field,
vkaverap98a2c192019-04-03 05:33:52 -050053 (sizeof(set_effecter_state_field) * comp_effecter_count));
54
55 return PLDM_SUCCESS;
56}
57
Zahed Hossain223a73d2019-07-04 12:46:18 -050058int decode_set_state_effecter_states_resp(const struct pldm_msg *msg,
vkaverapa6575b82019-04-03 05:33:52 -050059 size_t payload_length,
vkaverap98a2c192019-04-03 05:33:52 -050060 uint8_t *completion_code)
61{
62 if (msg == NULL || completion_code == NULL) {
63 return PLDM_ERROR_INVALID_DATA;
64 }
65
vkaverapa6575b82019-04-03 05:33:52 -050066 if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES) {
67 return PLDM_ERROR_INVALID_LENGTH;
68 }
69
Zahed Hossain223a73d2019-07-04 12:46:18 -050070 *completion_code = msg->payload[0];
vkaverap98a2c192019-04-03 05:33:52 -050071
72 return PLDM_SUCCESS;
73}
74
Zahed Hossain223a73d2019-07-04 12:46:18 -050075int decode_set_state_effecter_states_req(const struct pldm_msg *msg,
vkaverapa6575b82019-04-03 05:33:52 -050076 size_t payload_length,
Sampa Misra0db1dfa2019-03-19 00:15:31 -050077 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 }
vkaverapa6575b82019-04-03 05:33:52 -050085
86 if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) {
87 return PLDM_ERROR_INVALID_LENGTH;
88 }
89
Priyanga7257fdf2019-06-10 01:59:45 -050090 struct pldm_set_state_effecter_states_req *request =
Zahed Hossain223a73d2019-07-04 12:46:18 -050091 (struct pldm_set_state_effecter_states_req *)msg->payload;
Priyanga7257fdf2019-06-10 01:59:45 -050092
93 *effecter_id = le16toh(request->effecter_id);
94 *comp_effecter_count = request->comp_effecter_count;
95 memcpy(field, request->field,
Sampa Misra0db1dfa2019-03-19 00:15:31 -050096 (sizeof(set_effecter_state_field) * (*comp_effecter_count)));
97
98 return PLDM_SUCCESS;
99}
Sampa Misra7fcfb662019-05-08 13:13:53 -0500100
101int 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
126int 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}