blob: aa8cc1525469d48228965282c38c65035b7bd92e [file] [log] [blame]
Andrew Jeffery9c766792022-08-10 23:12:49 +09301#include "bios.h"
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05302#include "base.h"
Andrew Jeffery9c766792022-08-10 23:12:49 +09303#include "utils.h"
4#include <endian.h>
Andrew Jeffery9c766792022-08-10 23:12:49 +09305#include <string.h>
6
7int encode_get_date_time_req(uint8_t instance_id, 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.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 if (msg == NULL) {
27 return PLDM_ERROR_INVALID_DATA;
28 }
29
30 struct pldm_header_info header = {0};
31 header.msg_type = PLDM_RESPONSE;
32 header.instance = instance_id;
33 header.pldm_type = PLDM_BIOS;
34 header.command = PLDM_GET_DATE_TIME;
35
36 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
37 if (rc != PLDM_SUCCESS) {
38 return rc;
39 }
40
41 struct pldm_get_date_time_resp *response =
42 (struct pldm_get_date_time_resp *)msg->payload;
43 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);
52 }
53 return PLDM_SUCCESS;
54}
55
56int decode_get_date_time_resp(const struct pldm_msg *msg, size_t payload_length,
57 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
67 *completion_code = msg->payload[0];
68 if (PLDM_SUCCESS != *completion_code) {
69 return PLDM_SUCCESS;
70 }
71
72 if (payload_length != PLDM_GET_DATE_TIME_RESP_BYTES) {
73 return PLDM_ERROR_INVALID_LENGTH;
74 }
75
76 struct pldm_get_date_time_resp *response =
77 (struct pldm_get_date_time_resp *)msg->payload;
78
79 *seconds = response->seconds;
80 *minutes = response->minutes;
81 *hours = response->hours;
82 *day = response->day;
83 *month = response->month;
84 *year = le16toh(response->year);
85
86 return PLDM_SUCCESS;
87}
88
89int 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{
94 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 }
104
105 struct pldm_header_info header = {0};
106 header.instance = instance_id;
107 header.msg_type = PLDM_REQUEST;
108 header.pldm_type = PLDM_BIOS;
109 header.command = PLDM_SET_DATE_TIME;
110
111 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
112 if (rc != PLDM_SUCCESS) {
113 return rc;
114 }
115
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{
160 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
167 struct pldm_header_info header = {0};
168 header.instance = instance_id;
169 header.msg_type = PLDM_RESPONSE;
170 header.pldm_type = PLDM_BIOS;
171 header.command = PLDM_SET_DATE_TIME;
172
173 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
174 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
192 *completion_code = msg->payload[0];
193 if (PLDM_SUCCESS != *completion_code) {
194 return PLDM_SUCCESS;
195 }
196
197 if (payload_length != sizeof(struct pldm_only_cc_resp)) {
198 return PLDM_ERROR_INVALID_LENGTH;
199 }
200
201 return PLDM_SUCCESS;
202}
203
204int 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{
209 if (msg == NULL) {
210 return PLDM_ERROR_INVALID_DATA;
211 }
212
213 struct pldm_header_info header = {0};
214 header.msg_type = PLDM_RESPONSE;
215 header.instance = instance_id;
216 header.pldm_type = PLDM_BIOS;
217 header.command = PLDM_GET_BIOS_TABLE;
218
219 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
220 if (rc != PLDM_SUCCESS) {
221 return rc;
222 }
223
224 struct pldm_get_bios_table_resp *response =
225 (struct pldm_get_bios_table_resp *)msg->payload;
226 response->completion_code = completion_code;
227 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
243int 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{
247 if (msg == NULL) {
248 return PLDM_ERROR_INVALID_DATA;
249 }
250
251 struct pldm_header_info header = {0};
252 header.msg_type = PLDM_REQUEST;
253 header.instance = instance_id;
254 header.pldm_type = PLDM_BIOS;
255 header.command = PLDM_GET_BIOS_TABLE;
256
257 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
258 if (rc != PLDM_SUCCESS) {
259 return rc;
260 }
261
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
271int 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}
292
293int 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
327int 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{
331 if (msg == NULL) {
332 return PLDM_ERROR_INVALID_DATA;
333 }
334
335 struct pldm_header_info header = {0};
336 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;
340
341 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
342 if (rc != PLDM_SUCCESS) {
343 return rc;
344 }
345
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
390int 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{
419 if (msg == NULL || attribute_data == NULL) {
420 return PLDM_ERROR_INVALID_DATA;
421 }
422
423 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
434 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;
437 response->completion_code = completion_code;
438 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}
449int 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,
Andrew Jeffery9145a412023-04-05 20:24:50 +0930452 struct pldm_msg *msg, size_t payload_length)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930453{
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 !=
Andrew Jeffery9145a412023-04-05 20:24:50 +0930458 payload_length) {
Andrew Jeffery9c766792022-08-10 23:12:49 +0930459 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;
466
467 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
468 if (rc != PLDM_SUCCESS) {
469 return rc;
470 }
471
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 }
490
491 *completion_code = msg->payload[0];
492 if (PLDM_SUCCESS != *completion_code) {
493 return PLDM_SUCCESS;
494 }
495
496 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
503 *next_transfer_handle = le32toh(response->next_transfer_handle);
504
505 return PLDM_SUCCESS;
506}
507
508int 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)
512{
513 if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL ||
514 attribute == NULL) {
515 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;
525 attribute->length =
526 payload_length - PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES;
527 attribute->ptr = request->attribute_data;
528 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
545 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
546 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}
557
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{
563 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
578 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
579 if (rc != PLDM_SUCCESS) {
580 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}
618
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{
623 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
633 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
634 if (rc != PLDM_SUCCESS) {
635 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}