blob: 8d93a6abe8bb6d0923f26a4a64468adc43adc924 [file] [log] [blame]
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -05001#include "bios.h"
Xiaochao Ma39ae2a92019-11-12 20:30:34 +08002#include "utils.h"
Sampa Misra032bd502019-03-06 05:03:22 -06003#include <endian.h>
Xiaochao Ma39ae2a92019-11-12 20:30:34 +08004#include <stdbool.h>
Sampa Misra032bd502019-03-06 05:03:22 -06005#include <string.h>
6
Sampa Misra032bd502019-03-06 05:03:22 -06007int encode_get_date_time_req(uint8_t instance_id, struct pldm_msg *msg)
8{
Sampa Misra032bd502019-03-06 05:03:22 -06009 if (msg == NULL) {
10 return PLDM_ERROR_INVALID_DATA;
11 }
12
George Liub7095ff2021-06-14 16:01:57 +080013 struct pldm_header_info header = {0};
Sampa Misra032bd502019-03-06 05:03:22 -060014 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{
Sampa Misra032bd502019-03-06 05:03:22 -060026 if (msg == NULL) {
27 return PLDM_ERROR_INVALID_DATA;
28 }
29
George Liub7095ff2021-06-14 16:01:57 +080030 struct pldm_header_info header = {0};
Sampa Misra032bd502019-03-06 05:03:22 -060031 header.msg_type = PLDM_RESPONSE;
32 header.instance = instance_id;
33 header.pldm_type = PLDM_BIOS;
34 header.command = PLDM_GET_DATE_TIME;
Zahed Hossain43264522019-06-04 02:21:03 -050035
George Liub7095ff2021-06-14 16:01:57 +080036 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
37 if (rc != PLDM_SUCCESS) {
Sampa Misra032bd502019-03-06 05:03:22 -060038 return rc;
39 }
40
George Liub7095ff2021-06-14 16:01:57 +080041 struct pldm_get_date_time_resp *response =
42 (struct pldm_get_date_time_resp *)msg->payload;
Priyanga5dcd1802019-06-10 01:50:39 -050043 response->completion_code = completion_code;
44 if (response->completion_code == PLDM_SUCCESS) {
45 response->completion_code = completion_code;
46 response->seconds = seconds;
47 response->minutes = minutes;
48 response->hours = hours;
49 response->day = day;
50 response->month = month;
51 response->year = htole16(year);
Zahed Hossain43264522019-06-04 02:21:03 -050052 }
Sampa Misra032bd502019-03-06 05:03:22 -060053 return PLDM_SUCCESS;
54}
55
Zahed Hossain223a73d2019-07-04 12:46:18 -050056int decode_get_date_time_resp(const struct pldm_msg *msg, size_t payload_length,
Sampa Misra032bd502019-03-06 05:03:22 -060057 uint8_t *completion_code, uint8_t *seconds,
58 uint8_t *minutes, uint8_t *hours, uint8_t *day,
59 uint8_t *month, uint16_t *year)
60{
61 if (msg == NULL || seconds == NULL || minutes == NULL ||
62 hours == NULL || day == NULL || month == NULL || year == NULL ||
63 completion_code == NULL) {
64 return PLDM_ERROR_INVALID_DATA;
65 }
66
George Liu684a7162019-12-06 15:10:52 +080067 *completion_code = msg->payload[0];
68 if (PLDM_SUCCESS != *completion_code) {
69 return PLDM_SUCCESS;
70 }
71
vkaverapa6575b82019-04-03 05:33:52 -050072 if (payload_length != PLDM_GET_DATE_TIME_RESP_BYTES) {
73 return PLDM_ERROR_INVALID_LENGTH;
74 }
75
Priyanga5dcd1802019-06-10 01:50:39 -050076 struct pldm_get_date_time_resp *response =
Zahed Hossain223a73d2019-07-04 12:46:18 -050077 (struct pldm_get_date_time_resp *)msg->payload;
Priyanga5dcd1802019-06-10 01:50:39 -050078
Priyanga5dcd1802019-06-10 01:50:39 -050079 *seconds = response->seconds;
80 *minutes = response->minutes;
81 *hours = response->hours;
82 *day = response->day;
83 *month = response->month;
84 *year = le16toh(response->year);
Sampa Misra032bd502019-03-06 05:03:22 -060085
86 return PLDM_SUCCESS;
87}
Sampa Misrab37be312019-07-03 02:26:41 -050088
Xiaochao Ma39ae2a92019-11-12 20:30:34 +080089int encode_set_date_time_req(uint8_t instance_id, uint8_t seconds,
90 uint8_t minutes, uint8_t hours, uint8_t day,
91 uint8_t month, uint16_t year, struct pldm_msg *msg,
92 size_t payload_length)
93{
Xiaochao Ma39ae2a92019-11-12 20:30:34 +080094 if (msg == NULL) {
95 return PLDM_ERROR_INVALID_DATA;
96 }
97 if (payload_length != sizeof(struct pldm_set_date_time_req)) {
98 return PLDM_ERROR_INVALID_LENGTH;
99 }
100
101 if (!is_time_legal(seconds, minutes, hours, day, month, year)) {
102 return PLDM_ERROR_INVALID_DATA;
103 }
George Liub7095ff2021-06-14 16:01:57 +0800104
105 struct pldm_header_info header = {0};
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800106 header.instance = instance_id;
107 header.msg_type = PLDM_REQUEST;
108 header.pldm_type = PLDM_BIOS;
109 header.command = PLDM_SET_DATE_TIME;
George Liub7095ff2021-06-14 16:01:57 +0800110
111 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
112 if (rc != PLDM_SUCCESS) {
113 return rc;
114 }
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800115
116 struct pldm_set_date_time_req *request =
117 (struct pldm_set_date_time_req *)msg->payload;
118 request->seconds = dec2bcd8(seconds);
119 request->minutes = dec2bcd8(minutes);
120 request->hours = dec2bcd8(hours);
121 request->day = dec2bcd8(day);
122 request->month = dec2bcd8(month);
123 request->year = htole16(dec2bcd16(year));
124
125 return PLDM_SUCCESS;
126}
127
128int decode_set_date_time_req(const struct pldm_msg *msg, size_t payload_length,
129 uint8_t *seconds, uint8_t *minutes, uint8_t *hours,
130 uint8_t *day, uint8_t *month, uint16_t *year)
131{
132 if (msg == NULL || seconds == NULL || minutes == NULL ||
133 hours == NULL || day == NULL || month == NULL || year == NULL) {
134 return PLDM_ERROR_INVALID_DATA;
135 }
136 if (payload_length != sizeof(struct pldm_set_date_time_req)) {
137 return PLDM_ERROR_INVALID_LENGTH;
138 }
139
140 const struct pldm_set_date_time_req *request =
141 (struct pldm_set_date_time_req *)msg->payload;
142
143 *seconds = bcd2dec8(request->seconds);
144 *minutes = bcd2dec8(request->minutes);
145 *hours = bcd2dec8(request->hours);
146 *day = bcd2dec8(request->day);
147 *month = bcd2dec8(request->month);
148 *year = bcd2dec16(le16toh(request->year));
149
150 if (!is_time_legal(*seconds, *minutes, *hours, *day, *month, *year)) {
151 return PLDM_ERROR_INVALID_DATA;
152 }
153
154 return PLDM_SUCCESS;
155}
156
157int encode_set_date_time_resp(uint8_t instance_id, uint8_t completion_code,
158 struct pldm_msg *msg, size_t payload_length)
159{
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800160 if (msg == NULL) {
161 return PLDM_ERROR_INVALID_DATA;
162 }
163 if (payload_length != sizeof(struct pldm_only_cc_resp)) {
164 return PLDM_ERROR_INVALID_LENGTH;
165 }
166
George Liub7095ff2021-06-14 16:01:57 +0800167 struct pldm_header_info header = {0};
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800168 header.instance = instance_id;
169 header.msg_type = PLDM_RESPONSE;
170 header.pldm_type = PLDM_BIOS;
171 header.command = PLDM_SET_DATE_TIME;
George Liub7095ff2021-06-14 16:01:57 +0800172
173 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800174 if (rc != PLDM_SUCCESS) {
175 return rc;
176 }
177
178 struct pldm_only_cc_resp *response =
179 (struct pldm_only_cc_resp *)msg->payload;
180 response->completion_code = completion_code;
181
182 return PLDM_SUCCESS;
183}
184
185int decode_set_date_time_resp(const struct pldm_msg *msg, size_t payload_length,
186 uint8_t *completion_code)
187{
188 if (msg == NULL || completion_code == NULL) {
189 return PLDM_ERROR_INVALID_DATA;
190 }
191
George Liu684a7162019-12-06 15:10:52 +0800192 *completion_code = msg->payload[0];
193 if (PLDM_SUCCESS != *completion_code) {
194 return PLDM_SUCCESS;
195 }
196
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800197 if (payload_length != sizeof(struct pldm_only_cc_resp)) {
198 return PLDM_ERROR_INVALID_LENGTH;
199 }
200
Xiaochao Ma39ae2a92019-11-12 20:30:34 +0800201 return PLDM_SUCCESS;
202}
203
Sampa Misrab37be312019-07-03 02:26:41 -0500204int encode_get_bios_table_resp(uint8_t instance_id, uint8_t completion_code,
205 uint32_t next_transfer_handle,
206 uint8_t transfer_flag, uint8_t *table_data,
207 size_t payload_length, struct pldm_msg *msg)
208{
Sampa Misrab37be312019-07-03 02:26:41 -0500209 if (msg == NULL) {
210 return PLDM_ERROR_INVALID_DATA;
211 }
212
George Liub7095ff2021-06-14 16:01:57 +0800213 struct pldm_header_info header = {0};
Sampa Misrab37be312019-07-03 02:26:41 -0500214 header.msg_type = PLDM_RESPONSE;
215 header.instance = instance_id;
216 header.pldm_type = PLDM_BIOS;
217 header.command = PLDM_GET_BIOS_TABLE;
George Liub7095ff2021-06-14 16:01:57 +0800218
219 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
220 if (rc != PLDM_SUCCESS) {
Sampa Misrab37be312019-07-03 02:26:41 -0500221 return rc;
222 }
223
George Liub7095ff2021-06-14 16:01:57 +0800224 struct pldm_get_bios_table_resp *response =
225 (struct pldm_get_bios_table_resp *)msg->payload;
226 response->completion_code = completion_code;
Sampa Misrab37be312019-07-03 02:26:41 -0500227 if (response->completion_code == PLDM_SUCCESS) {
228
229 response->next_transfer_handle = htole32(next_transfer_handle);
230 response->transfer_flag = transfer_flag;
231 if (table_data != NULL &&
232 payload_length > (sizeof(struct pldm_msg_hdr) +
233 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES)) {
234 memcpy(response->table_data, table_data,
235 payload_length -
236 (sizeof(struct pldm_msg_hdr) +
237 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES));
238 }
239 }
240 return PLDM_SUCCESS;
241}
242
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500243int encode_get_bios_table_req(uint8_t instance_id, uint32_t transfer_handle,
244 uint8_t transfer_op_flag, uint8_t table_type,
245 struct pldm_msg *msg)
246{
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500247 if (msg == NULL) {
248 return PLDM_ERROR_INVALID_DATA;
249 }
250
George Liub7095ff2021-06-14 16:01:57 +0800251 struct pldm_header_info header = {0};
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500252 header.msg_type = PLDM_REQUEST;
253 header.instance = instance_id;
254 header.pldm_type = PLDM_BIOS;
255 header.command = PLDM_GET_BIOS_TABLE;
George Liub7095ff2021-06-14 16:01:57 +0800256
257 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
258 if (rc != PLDM_SUCCESS) {
259 return rc;
260 }
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500261
262 struct pldm_get_bios_table_req *request =
263 (struct pldm_get_bios_table_req *)msg->payload;
264
265 request->transfer_handle = htole32(transfer_handle);
266 request->transfer_op_flag = transfer_op_flag;
267 request->table_type = table_type;
268 return PLDM_SUCCESS;
269}
270
Sampa Misrab37be312019-07-03 02:26:41 -0500271int decode_get_bios_table_req(const struct pldm_msg *msg, size_t payload_length,
272 uint32_t *transfer_handle,
273 uint8_t *transfer_op_flag, uint8_t *table_type)
274{
275 if (msg == NULL || transfer_op_flag == NULL || table_type == NULL ||
276 transfer_handle == NULL) {
277 return PLDM_ERROR_INVALID_DATA;
278 }
279
280 if (payload_length != PLDM_GET_BIOS_TABLE_REQ_BYTES) {
281 return PLDM_ERROR_INVALID_LENGTH;
282 }
283
284 struct pldm_get_bios_table_req *request =
285 (struct pldm_get_bios_table_req *)msg->payload;
286 *transfer_handle = le32toh(request->transfer_handle);
287 *transfer_op_flag = request->transfer_op_flag;
288 *table_type = request->table_type;
289
290 return PLDM_SUCCESS;
291}
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500292
Sridevi Ramesh08efc7b2019-12-05 05:39:46 -0600293int decode_get_bios_table_resp(const struct pldm_msg *msg,
294 size_t payload_length, uint8_t *completion_code,
295 uint32_t *next_transfer_handle,
296 uint8_t *transfer_flag,
297 size_t *bios_table_offset)
298
299{
300 if (msg == NULL || transfer_flag == NULL ||
301 next_transfer_handle == NULL || completion_code == NULL) {
302 return PLDM_ERROR_INVALID_DATA;
303 }
304 if (payload_length <= PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES) {
305 return PLDM_ERROR_INVALID_LENGTH;
306 }
307
308 struct pldm_get_bios_table_resp *response =
309 (struct pldm_get_bios_table_resp *)msg->payload;
310
311 *completion_code = response->completion_code;
312
313 if (PLDM_SUCCESS != *completion_code) {
314 return PLDM_SUCCESS;
315 }
316
317 *next_transfer_handle = le32toh(response->next_transfer_handle);
318 *transfer_flag = response->transfer_flag;
319
320 *bios_table_offset = sizeof(*completion_code) +
321 sizeof(*next_transfer_handle) +
322 sizeof(*transfer_flag);
323
324 return PLDM_SUCCESS;
325}
326
Adair Lica37ccb2020-04-24 14:32:58 +0800327int encode_get_bios_attribute_current_value_by_handle_req(
328 uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_op_flag,
329 uint16_t attribute_handle, struct pldm_msg *msg)
330{
Adair Lica37ccb2020-04-24 14:32:58 +0800331 if (msg == NULL) {
332 return PLDM_ERROR_INVALID_DATA;
333 }
334
George Liub7095ff2021-06-14 16:01:57 +0800335 struct pldm_header_info header = {0};
Adair Lica37ccb2020-04-24 14:32:58 +0800336 header.msg_type = PLDM_REQUEST;
337 header.instance = instance_id;
338 header.pldm_type = PLDM_BIOS;
339 header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
George Liub7095ff2021-06-14 16:01:57 +0800340
341 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
342 if (rc != PLDM_SUCCESS) {
343 return rc;
344 }
Adair Lica37ccb2020-04-24 14:32:58 +0800345
346 struct pldm_get_bios_attribute_current_value_by_handle_req *request =
347 (struct pldm_get_bios_attribute_current_value_by_handle_req *)
348 msg->payload;
349
350 request->transfer_handle = htole32(transfer_handle);
351 request->transfer_op_flag = transfer_op_flag;
352 request->attribute_handle = htole16(attribute_handle);
353 return PLDM_SUCCESS;
354}
355
356int decode_get_bios_attribute_current_value_by_handle_resp(
357 const struct pldm_msg *msg, size_t payload_length, uint8_t *completion_code,
358 uint32_t *next_transfer_handle, uint8_t *transfer_flag,
359 struct variable_field *attribute_data)
360{
361 if (msg == NULL || transfer_flag == NULL ||
362 next_transfer_handle == NULL || completion_code == NULL) {
363 return PLDM_ERROR_INVALID_DATA;
364 }
365
366 struct pldm_get_bios_attribute_current_value_by_handle_resp *response =
367 (struct pldm_get_bios_attribute_current_value_by_handle_resp *)
368 msg->payload;
369
370 *completion_code = response->completion_code;
371
372 if (PLDM_SUCCESS != *completion_code) {
373 return PLDM_SUCCESS;
374 }
375
376 if (payload_length <=
377 PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_MIN_RESP_BYTES) {
378 return PLDM_ERROR_INVALID_LENGTH;
379 }
380
381 *next_transfer_handle = le32toh(response->next_transfer_handle);
382 *transfer_flag = response->transfer_flag;
383
384 attribute_data->ptr = response->attribute_data;
385 attribute_data->length = payload_length - sizeof(*response) + 1;
386
387 return PLDM_SUCCESS;
388}
389
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500390int decode_get_bios_attribute_current_value_by_handle_req(
391 const struct pldm_msg *msg, size_t payload_length,
392 uint32_t *transfer_handle, uint8_t *transfer_op_flag,
393 uint16_t *attribute_handle)
394{
395 if (msg == NULL || transfer_handle == NULL ||
396 transfer_op_flag == NULL || attribute_handle == NULL) {
397 return PLDM_ERROR_INVALID_DATA;
398 }
399
400 if (payload_length != PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_REQ_BYTES) {
401 return PLDM_ERROR_INVALID_LENGTH;
402 }
403
404 struct pldm_get_bios_attribute_current_value_by_handle_req *request =
405 (struct pldm_get_bios_attribute_current_value_by_handle_req *)
406 msg->payload;
407 *transfer_handle = le32toh(request->transfer_handle);
408 *transfer_op_flag = request->transfer_op_flag;
409 *attribute_handle = le16toh(request->attribute_handle);
410
411 return PLDM_SUCCESS;
412}
413
414int encode_get_bios_current_value_by_handle_resp(
415 uint8_t instance_id, uint8_t completion_code, uint32_t next_transfer_handle,
416 uint8_t transfer_flag, const uint8_t *attribute_data,
417 size_t attribute_length, struct pldm_msg *msg)
418{
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500419 if (msg == NULL || attribute_data == NULL) {
420 return PLDM_ERROR_INVALID_DATA;
421 }
422
George Liub7095ff2021-06-14 16:01:57 +0800423 struct pldm_header_info header = {0};
424 header.msg_type = PLDM_RESPONSE;
425 header.instance = instance_id;
426 header.pldm_type = PLDM_BIOS;
427 header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
428
429 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
430 if (rc != PLDM_SUCCESS) {
431 return rc;
432 }
433
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500434 struct pldm_get_bios_attribute_current_value_by_handle_resp *response =
435 (struct pldm_get_bios_attribute_current_value_by_handle_resp *)
436 msg->payload;
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500437 response->completion_code = completion_code;
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500438 if (response->completion_code == PLDM_SUCCESS) {
439
440 response->next_transfer_handle = htole32(next_transfer_handle);
441 response->transfer_flag = transfer_flag;
442 if (attribute_data != NULL) {
443 memcpy(response->attribute_data, attribute_data,
444 attribute_length);
445 }
446 }
447 return PLDM_SUCCESS;
448}
John Wang4d844792019-08-15 15:51:40 +0800449int encode_set_bios_attribute_current_value_req(
450 uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_flag,
451 const uint8_t *attribute_data, size_t attribute_length,
452 struct pldm_msg *msg, size_t payload_lenth)
453{
454 if (msg == NULL || attribute_data == NULL) {
455 return PLDM_ERROR_INVALID_DATA;
456 }
457 if (PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + attribute_length !=
458 payload_lenth) {
459 return PLDM_ERROR_INVALID_LENGTH;
460 }
461 struct pldm_header_info header = {0};
462 header.instance = instance_id;
463 header.msg_type = PLDM_REQUEST;
464 header.pldm_type = PLDM_BIOS;
465 header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
George Liub7095ff2021-06-14 16:01:57 +0800466
467 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
468 if (rc != PLDM_SUCCESS) {
469 return rc;
470 }
John Wang4d844792019-08-15 15:51:40 +0800471
472 struct pldm_set_bios_attribute_current_value_req *request =
473 (struct pldm_set_bios_attribute_current_value_req *)msg->payload;
474 request->transfer_handle = htole32(transfer_handle);
475 request->transfer_flag = transfer_flag;
476 memcpy(request->attribute_data, attribute_data, attribute_length);
477
478 return PLDM_SUCCESS;
479}
480
481int decode_set_bios_attribute_current_value_resp(const struct pldm_msg *msg,
482 size_t payload_length,
483 uint8_t *completion_code,
484 uint32_t *next_transfer_handle)
485{
486 if (msg == NULL || completion_code == NULL ||
487 next_transfer_handle == NULL) {
488 return PLDM_ERROR_INVALID_DATA;
489 }
George Liu684a7162019-12-06 15:10:52 +0800490
491 *completion_code = msg->payload[0];
492 if (PLDM_SUCCESS != *completion_code) {
493 return PLDM_SUCCESS;
494 }
495
John Wang4d844792019-08-15 15:51:40 +0800496 if (payload_length != PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES) {
497 return PLDM_ERROR_INVALID_LENGTH;
498 }
499
500 struct pldm_set_bios_attribute_current_value_resp *response =
501 (struct pldm_set_bios_attribute_current_value_resp *)msg->payload;
502
John Wang4d844792019-08-15 15:51:40 +0800503 *next_transfer_handle = le32toh(response->next_transfer_handle);
504
505 return PLDM_SUCCESS;
506}
507
John Wang08c05952019-12-20 15:40:39 +0800508int decode_set_bios_attribute_current_value_req(
509 const struct pldm_msg *msg, size_t payload_length,
510 uint32_t *transfer_handle, uint8_t *transfer_flag,
511 struct variable_field *attribute)
John Wang4d844792019-08-15 15:51:40 +0800512{
513 if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL ||
John Wang08c05952019-12-20 15:40:39 +0800514 attribute == NULL) {
John Wang4d844792019-08-15 15:51:40 +0800515 return PLDM_ERROR_INVALID_DATA;
516 }
517 if (payload_length < PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES) {
518 return PLDM_ERROR_INVALID_LENGTH;
519 }
520
521 struct pldm_set_bios_attribute_current_value_req *request =
522 (struct pldm_set_bios_attribute_current_value_req *)msg->payload;
523 *transfer_handle = le32toh(request->transfer_handle);
524 *transfer_flag = request->transfer_flag;
John Wang08c05952019-12-20 15:40:39 +0800525 attribute->length =
John Wang4d844792019-08-15 15:51:40 +0800526 payload_length - PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES;
John Wang08c05952019-12-20 15:40:39 +0800527 attribute->ptr = request->attribute_data;
John Wang4d844792019-08-15 15:51:40 +0800528 return PLDM_SUCCESS;
529}
530
531int encode_set_bios_attribute_current_value_resp(uint8_t instance_id,
532 uint8_t completion_code,
533 uint32_t next_transfer_handle,
534 struct pldm_msg *msg)
535{
536 if (msg == NULL) {
537 return PLDM_ERROR_INVALID_DATA;
538 }
539 struct pldm_header_info header = {0};
540 header.instance = instance_id;
541 header.msg_type = PLDM_RESPONSE;
542 header.pldm_type = PLDM_BIOS;
543 header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
544
George Liub7095ff2021-06-14 16:01:57 +0800545 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
John Wang4d844792019-08-15 15:51:40 +0800546 if (rc != PLDM_SUCCESS) {
547 return rc;
548 }
549
550 struct pldm_set_bios_attribute_current_value_resp *response =
551 (struct pldm_set_bios_attribute_current_value_resp *)msg->payload;
552 response->completion_code = completion_code;
553 response->next_transfer_handle = htole32(next_transfer_handle);
554
555 return PLDM_SUCCESS;
556}
George Liu3eabde62020-07-15 12:32:33 +0800557
558int encode_set_bios_table_req(uint8_t instance_id, uint32_t transfer_handle,
559 uint8_t transfer_flag, uint8_t table_type,
560 const uint8_t *table_data, size_t table_length,
561 struct pldm_msg *msg, size_t payload_length)
562{
George Liu3eabde62020-07-15 12:32:33 +0800563 if (msg == NULL || table_data == NULL) {
564 return PLDM_ERROR_INVALID_DATA;
565 }
566
567 if (PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES + table_length !=
568 payload_length) {
569 return PLDM_ERROR_INVALID_LENGTH;
570 }
571
572 struct pldm_header_info header = {0};
573 header.instance = instance_id;
574 header.msg_type = PLDM_REQUEST;
575 header.pldm_type = PLDM_BIOS;
576 header.command = PLDM_SET_BIOS_TABLE;
577
George Liub7095ff2021-06-14 16:01:57 +0800578 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
579 if (rc != PLDM_SUCCESS) {
George Liu3eabde62020-07-15 12:32:33 +0800580 return rc;
581 }
582
583 struct pldm_set_bios_table_req *request =
584 (struct pldm_set_bios_table_req *)msg->payload;
585 request->transfer_handle = htole32(transfer_handle);
586 request->transfer_flag = transfer_flag;
587 request->table_type = table_type;
588 memcpy(request->table_data, table_data, table_length);
589
590 return PLDM_SUCCESS;
591}
592
593int decode_set_bios_table_resp(const struct pldm_msg *msg,
594 size_t payload_length, uint8_t *completion_code,
595 uint32_t *next_transfer_handle)
596{
597 if (msg == NULL || completion_code == NULL ||
598 next_transfer_handle == NULL) {
599 return PLDM_ERROR_INVALID_DATA;
600 }
601
602 *completion_code = msg->payload[0];
603 if (PLDM_SUCCESS != *completion_code) {
604 return PLDM_SUCCESS;
605 }
606
607 if (payload_length != PLDM_SET_BIOS_TABLE_RESP_BYTES) {
608 return PLDM_ERROR_INVALID_LENGTH;
609 }
610
611 struct pldm_set_bios_table_resp *response =
612 (struct pldm_set_bios_table_resp *)msg->payload;
613
614 *next_transfer_handle = le32toh(response->next_transfer_handle);
615
616 return PLDM_SUCCESS;
617}
George Liub371f8d2020-07-15 14:13:17 +0800618
619int encode_set_bios_table_resp(uint8_t instance_id, uint8_t completion_code,
620 uint32_t next_transfer_handle,
621 struct pldm_msg *msg)
622{
George Liub371f8d2020-07-15 14:13:17 +0800623 if (msg == NULL) {
624 return PLDM_ERROR_INVALID_DATA;
625 }
626
627 struct pldm_header_info header = {0};
628 header.instance = instance_id;
629 header.msg_type = PLDM_RESPONSE;
630 header.pldm_type = PLDM_BIOS;
631 header.command = PLDM_SET_BIOS_TABLE;
632
George Liub7095ff2021-06-14 16:01:57 +0800633 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
634 if (rc != PLDM_SUCCESS) {
George Liub371f8d2020-07-15 14:13:17 +0800635 return rc;
636 }
637
638 struct pldm_set_bios_table_resp *response =
639 (struct pldm_set_bios_table_resp *)msg->payload;
640 response->completion_code = completion_code;
641 response->next_transfer_handle = htole32(next_transfer_handle);
642
643 return PLDM_SUCCESS;
644}
645
646int decode_set_bios_table_req(const struct pldm_msg *msg, size_t payload_length,
647 uint32_t *transfer_handle, uint8_t *transfer_flag,
648 uint8_t *table_type, struct variable_field *table)
649{
650 if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL ||
651 table_type == NULL || table == NULL) {
652 return PLDM_ERROR_INVALID_DATA;
653 }
654
655 if (payload_length < PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES) {
656 return PLDM_ERROR_INVALID_LENGTH;
657 }
658
659 struct pldm_set_bios_table_req *request =
660 (struct pldm_set_bios_table_req *)msg->payload;
661 *transfer_handle = le32toh(request->transfer_handle);
662 *transfer_flag = request->transfer_flag;
663 *table_type = request->table_type;
664 table->length = payload_length - PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES;
665 table->ptr = request->table_data;
666
667 return PLDM_SUCCESS;
668}