blob: 017ae4aef90bee37b6670626ca762102b3590feb [file] [log] [blame]
Sampa Misra032bd502019-03-06 05:03:22 -06001#include <endian.h>
2#include <string.h>
3
4#include "bios.h"
5
6int encode_get_date_time_req(uint8_t instance_id, struct pldm_msg *msg)
7{
8 struct pldm_header_info header = {0};
9
10 if (msg == NULL) {
11 return PLDM_ERROR_INVALID_DATA;
12 }
13
14 header.msg_type = PLDM_REQUEST;
15 header.instance = instance_id;
16 header.pldm_type = PLDM_BIOS;
17 header.command = PLDM_GET_DATE_TIME;
18 return pack_pldm_header(&header, &(msg->hdr));
19}
20
21int encode_get_date_time_resp(uint8_t instance_id, uint8_t completion_code,
22 uint8_t seconds, uint8_t minutes, uint8_t hours,
23 uint8_t day, uint8_t month, uint16_t year,
24 struct pldm_msg *msg)
25{
26 struct pldm_header_info header = {0};
27 int rc = PLDM_SUCCESS;
28
29 if (msg == NULL) {
30 return PLDM_ERROR_INVALID_DATA;
31 }
32
Sampa Misra032bd502019-03-06 05:03:22 -060033 header.msg_type = PLDM_RESPONSE;
34 header.instance = instance_id;
35 header.pldm_type = PLDM_BIOS;
36 header.command = PLDM_GET_DATE_TIME;
Zahed Hossain43264522019-06-04 02:21:03 -050037
Priyanga5dcd1802019-06-10 01:50:39 -050038 struct pldm_get_date_time_resp *response =
39 (struct pldm_get_date_time_resp *)msg->payload;
40
Sampa Misra032bd502019-03-06 05:03:22 -060041 if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
42 return rc;
43 }
44
Priyanga5dcd1802019-06-10 01:50:39 -050045 response->completion_code = completion_code;
46 if (response->completion_code == PLDM_SUCCESS) {
47 response->completion_code = completion_code;
48 response->seconds = seconds;
49 response->minutes = minutes;
50 response->hours = hours;
51 response->day = day;
52 response->month = month;
53 response->year = htole16(year);
Zahed Hossain43264522019-06-04 02:21:03 -050054 }
Sampa Misra032bd502019-03-06 05:03:22 -060055 return PLDM_SUCCESS;
56}
57
Zahed Hossain223a73d2019-07-04 12:46:18 -050058int decode_get_date_time_resp(const struct pldm_msg *msg, size_t payload_length,
Sampa Misra032bd502019-03-06 05:03:22 -060059 uint8_t *completion_code, uint8_t *seconds,
60 uint8_t *minutes, uint8_t *hours, uint8_t *day,
61 uint8_t *month, uint16_t *year)
62{
63 if (msg == NULL || seconds == NULL || minutes == NULL ||
64 hours == NULL || day == NULL || month == NULL || year == NULL ||
65 completion_code == NULL) {
66 return PLDM_ERROR_INVALID_DATA;
67 }
68
vkaverapa6575b82019-04-03 05:33:52 -050069 if (payload_length != PLDM_GET_DATE_TIME_RESP_BYTES) {
70 return PLDM_ERROR_INVALID_LENGTH;
71 }
72
Priyanga5dcd1802019-06-10 01:50:39 -050073 struct pldm_get_date_time_resp *response =
Zahed Hossain223a73d2019-07-04 12:46:18 -050074 (struct pldm_get_date_time_resp *)msg->payload;
Priyanga5dcd1802019-06-10 01:50:39 -050075 *completion_code = response->completion_code;
76
Sampa Misra032bd502019-03-06 05:03:22 -060077 if (PLDM_SUCCESS != *completion_code) {
78 return PLDM_SUCCESS;
79 }
Priyanga5dcd1802019-06-10 01:50:39 -050080 *seconds = response->seconds;
81 *minutes = response->minutes;
82 *hours = response->hours;
83 *day = response->day;
84 *month = response->month;
85 *year = le16toh(response->year);
Sampa Misra032bd502019-03-06 05:03:22 -060086
87 return PLDM_SUCCESS;
88}
Sampa Misrab37be312019-07-03 02:26:41 -050089
90int encode_get_bios_table_resp(uint8_t instance_id, uint8_t completion_code,
91 uint32_t next_transfer_handle,
92 uint8_t transfer_flag, uint8_t *table_data,
93 size_t payload_length, struct pldm_msg *msg)
94{
95 struct pldm_header_info header = {0};
96 int rc = PLDM_SUCCESS;
97
98 if (msg == NULL) {
99 return PLDM_ERROR_INVALID_DATA;
100 }
101
102 struct pldm_get_bios_table_resp *response =
103 (struct pldm_get_bios_table_resp *)msg->payload;
104
105 response->completion_code = completion_code;
106 header.msg_type = PLDM_RESPONSE;
107 header.instance = instance_id;
108 header.pldm_type = PLDM_BIOS;
109 header.command = PLDM_GET_BIOS_TABLE;
110 if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
111 return rc;
112 }
113
114 if (response->completion_code == PLDM_SUCCESS) {
115
116 response->next_transfer_handle = htole32(next_transfer_handle);
117 response->transfer_flag = transfer_flag;
118 if (table_data != NULL &&
119 payload_length > (sizeof(struct pldm_msg_hdr) +
120 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES)) {
121 memcpy(response->table_data, table_data,
122 payload_length -
123 (sizeof(struct pldm_msg_hdr) +
124 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES));
125 }
126 }
127 return PLDM_SUCCESS;
128}
129
130int decode_get_bios_table_req(const struct pldm_msg *msg, size_t payload_length,
131 uint32_t *transfer_handle,
132 uint8_t *transfer_op_flag, uint8_t *table_type)
133{
134 if (msg == NULL || transfer_op_flag == NULL || table_type == NULL ||
135 transfer_handle == NULL) {
136 return PLDM_ERROR_INVALID_DATA;
137 }
138
139 if (payload_length != PLDM_GET_BIOS_TABLE_REQ_BYTES) {
140 return PLDM_ERROR_INVALID_LENGTH;
141 }
142
143 struct pldm_get_bios_table_req *request =
144 (struct pldm_get_bios_table_req *)msg->payload;
145 *transfer_handle = le32toh(request->transfer_handle);
146 *transfer_op_flag = request->transfer_op_flag;
147 *table_type = request->table_type;
148
149 return PLDM_SUCCESS;
150}
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500151
152int decode_get_bios_attribute_current_value_by_handle_req(
153 const struct pldm_msg *msg, size_t payload_length,
154 uint32_t *transfer_handle, uint8_t *transfer_op_flag,
155 uint16_t *attribute_handle)
156{
157 if (msg == NULL || transfer_handle == NULL ||
158 transfer_op_flag == NULL || attribute_handle == NULL) {
159 return PLDM_ERROR_INVALID_DATA;
160 }
161
162 if (payload_length != PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_REQ_BYTES) {
163 return PLDM_ERROR_INVALID_LENGTH;
164 }
165
166 struct pldm_get_bios_attribute_current_value_by_handle_req *request =
167 (struct pldm_get_bios_attribute_current_value_by_handle_req *)
168 msg->payload;
169 *transfer_handle = le32toh(request->transfer_handle);
170 *transfer_op_flag = request->transfer_op_flag;
171 *attribute_handle = le16toh(request->attribute_handle);
172
173 return PLDM_SUCCESS;
174}
175
176int encode_get_bios_current_value_by_handle_resp(
177 uint8_t instance_id, uint8_t completion_code, uint32_t next_transfer_handle,
178 uint8_t transfer_flag, const uint8_t *attribute_data,
179 size_t attribute_length, struct pldm_msg *msg)
180{
181 struct pldm_header_info header = {0};
182 int rc = PLDM_SUCCESS;
183
184 if (msg == NULL || attribute_data == NULL) {
185 return PLDM_ERROR_INVALID_DATA;
186 }
187
188 struct pldm_get_bios_attribute_current_value_by_handle_resp *response =
189 (struct pldm_get_bios_attribute_current_value_by_handle_resp *)
190 msg->payload;
191
192 response->completion_code = completion_code;
193 header.msg_type = PLDM_RESPONSE;
194 header.instance = instance_id;
195 header.pldm_type = PLDM_BIOS;
196 header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
197 if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
198 return rc;
199 }
200 if (response->completion_code == PLDM_SUCCESS) {
201
202 response->next_transfer_handle = htole32(next_transfer_handle);
203 response->transfer_flag = transfer_flag;
204 if (attribute_data != NULL) {
205 memcpy(response->attribute_data, attribute_data,
206 attribute_length);
207 }
208 }
209 return PLDM_SUCCESS;
210}
John Wang4d844792019-08-15 15:51:40 +0800211int encode_set_bios_attribute_current_value_req(
212 uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_flag,
213 const uint8_t *attribute_data, size_t attribute_length,
214 struct pldm_msg *msg, size_t payload_lenth)
215{
216 if (msg == NULL || attribute_data == NULL) {
217 return PLDM_ERROR_INVALID_DATA;
218 }
219 if (PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + attribute_length !=
220 payload_lenth) {
221 return PLDM_ERROR_INVALID_LENGTH;
222 }
223 struct pldm_header_info header = {0};
224 header.instance = instance_id;
225 header.msg_type = PLDM_REQUEST;
226 header.pldm_type = PLDM_BIOS;
227 header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
228 pack_pldm_header(&header, &msg->hdr);
229
230 struct pldm_set_bios_attribute_current_value_req *request =
231 (struct pldm_set_bios_attribute_current_value_req *)msg->payload;
232 request->transfer_handle = htole32(transfer_handle);
233 request->transfer_flag = transfer_flag;
234 memcpy(request->attribute_data, attribute_data, attribute_length);
235
236 return PLDM_SUCCESS;
237}
238
239int decode_set_bios_attribute_current_value_resp(const struct pldm_msg *msg,
240 size_t payload_length,
241 uint8_t *completion_code,
242 uint32_t *next_transfer_handle)
243{
244 if (msg == NULL || completion_code == NULL ||
245 next_transfer_handle == NULL) {
246 return PLDM_ERROR_INVALID_DATA;
247 }
248 if (payload_length != PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES) {
249 return PLDM_ERROR_INVALID_LENGTH;
250 }
251
252 struct pldm_set_bios_attribute_current_value_resp *response =
253 (struct pldm_set_bios_attribute_current_value_resp *)msg->payload;
254
255 *completion_code = response->completion_code;
256 if (PLDM_SUCCESS != *completion_code) {
257 return PLDM_SUCCESS;
258 }
259 *next_transfer_handle = le32toh(response->next_transfer_handle);
260
261 return PLDM_SUCCESS;
262}
263
264int decode_set_bios_attribute_current_value_req(const struct pldm_msg *msg,
265 size_t payload_length,
266 uint32_t *transfer_handle,
267 uint8_t *transfer_flag,
268 uint8_t *attribute_data,
269 size_t *attribute_length)
270{
271 if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL ||
272 attribute_data == NULL || attribute_length == NULL) {
273 return PLDM_ERROR_INVALID_DATA;
274 }
275 if (payload_length < PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES) {
276 return PLDM_ERROR_INVALID_LENGTH;
277 }
278
279 struct pldm_set_bios_attribute_current_value_req *request =
280 (struct pldm_set_bios_attribute_current_value_req *)msg->payload;
281 *transfer_handle = le32toh(request->transfer_handle);
282 *transfer_flag = request->transfer_flag;
283 *attribute_length =
284 payload_length - PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES;
285 memcpy(attribute_data, request->attribute_data, *attribute_length);
286
287 return PLDM_SUCCESS;
288}
289
290int encode_set_bios_attribute_current_value_resp(uint8_t instance_id,
291 uint8_t completion_code,
292 uint32_t next_transfer_handle,
293 struct pldm_msg *msg)
294{
295 if (msg == NULL) {
296 return PLDM_ERROR_INVALID_DATA;
297 }
298 struct pldm_header_info header = {0};
299 header.instance = instance_id;
300 header.msg_type = PLDM_RESPONSE;
301 header.pldm_type = PLDM_BIOS;
302 header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
303
304 int rc = pack_pldm_header(&header, &msg->hdr);
305 if (rc != PLDM_SUCCESS) {
306 return rc;
307 }
308
309 struct pldm_set_bios_attribute_current_value_resp *response =
310 (struct pldm_set_bios_attribute_current_value_resp *)msg->payload;
311 response->completion_code = completion_code;
312 response->next_transfer_handle = htole32(next_transfer_handle);
313
314 return PLDM_SUCCESS;
315}