blob: 70f4d28a8144997aabd3713dd0636d44a4ec9caf [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
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093013 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093014 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
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093030 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093031 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 =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093042 (struct pldm_get_date_time_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093043 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 =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093077 (struct pldm_get_date_time_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093078
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
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930105 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930106 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 =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930117 (struct pldm_set_date_time_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930118 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 =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930141 (struct pldm_set_date_time_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930142
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
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930167 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930168 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 =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930179 (struct pldm_only_cc_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930180 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
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930213 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930214 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 =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930225 (struct pldm_get_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930226 response->completion_code = completion_code;
227 if (response->completion_code == PLDM_SUCCESS) {
Andrew Jeffery9c766792022-08-10 23:12:49 +0930228 response->next_transfer_handle = htole32(next_transfer_handle);
229 response->transfer_flag = transfer_flag;
230 if (table_data != NULL &&
231 payload_length > (sizeof(struct pldm_msg_hdr) +
232 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES)) {
233 memcpy(response->table_data, table_data,
234 payload_length -
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930235 (sizeof(struct pldm_msg_hdr) +
236 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES));
Andrew Jeffery9c766792022-08-10 23:12:49 +0930237 }
238 }
239 return PLDM_SUCCESS;
240}
241
242int encode_get_bios_table_req(uint8_t instance_id, uint32_t transfer_handle,
243 uint8_t transfer_op_flag, uint8_t table_type,
244 struct pldm_msg *msg)
245{
246 if (msg == NULL) {
247 return PLDM_ERROR_INVALID_DATA;
248 }
249
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930250 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930251 header.msg_type = PLDM_REQUEST;
252 header.instance = instance_id;
253 header.pldm_type = PLDM_BIOS;
254 header.command = PLDM_GET_BIOS_TABLE;
255
256 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
257 if (rc != PLDM_SUCCESS) {
258 return rc;
259 }
260
261 struct pldm_get_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930262 (struct pldm_get_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930263
264 request->transfer_handle = htole32(transfer_handle);
265 request->transfer_op_flag = transfer_op_flag;
266 request->table_type = table_type;
267 return PLDM_SUCCESS;
268}
269
270int decode_get_bios_table_req(const struct pldm_msg *msg, size_t payload_length,
271 uint32_t *transfer_handle,
272 uint8_t *transfer_op_flag, uint8_t *table_type)
273{
274 if (msg == NULL || transfer_op_flag == NULL || table_type == NULL ||
275 transfer_handle == NULL) {
276 return PLDM_ERROR_INVALID_DATA;
277 }
278
279 if (payload_length != PLDM_GET_BIOS_TABLE_REQ_BYTES) {
280 return PLDM_ERROR_INVALID_LENGTH;
281 }
282
283 struct pldm_get_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930284 (struct pldm_get_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930285 *transfer_handle = le32toh(request->transfer_handle);
286 *transfer_op_flag = request->transfer_op_flag;
287 *table_type = request->table_type;
288
289 return PLDM_SUCCESS;
290}
291
292int decode_get_bios_table_resp(const struct pldm_msg *msg,
293 size_t payload_length, uint8_t *completion_code,
294 uint32_t *next_transfer_handle,
295 uint8_t *transfer_flag,
296 size_t *bios_table_offset)
297
298{
299 if (msg == NULL || transfer_flag == NULL ||
300 next_transfer_handle == NULL || completion_code == NULL) {
301 return PLDM_ERROR_INVALID_DATA;
302 }
303 if (payload_length <= PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES) {
304 return PLDM_ERROR_INVALID_LENGTH;
305 }
306
307 struct pldm_get_bios_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930308 (struct pldm_get_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930309
310 *completion_code = response->completion_code;
311
312 if (PLDM_SUCCESS != *completion_code) {
313 return PLDM_SUCCESS;
314 }
315
316 *next_transfer_handle = le32toh(response->next_transfer_handle);
317 *transfer_flag = response->transfer_flag;
318
319 *bios_table_offset = sizeof(*completion_code) +
320 sizeof(*next_transfer_handle) +
321 sizeof(*transfer_flag);
322
323 return PLDM_SUCCESS;
324}
325
326int encode_get_bios_attribute_current_value_by_handle_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930327 uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_op_flag,
328 uint16_t attribute_handle, struct pldm_msg *msg)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930329{
330 if (msg == NULL) {
331 return PLDM_ERROR_INVALID_DATA;
332 }
333
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930334 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930335 header.msg_type = PLDM_REQUEST;
336 header.instance = instance_id;
337 header.pldm_type = PLDM_BIOS;
338 header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
339
340 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
341 if (rc != PLDM_SUCCESS) {
342 return rc;
343 }
344
345 struct pldm_get_bios_attribute_current_value_by_handle_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930346 (struct pldm_get_bios_attribute_current_value_by_handle_req *)
347 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930348
349 request->transfer_handle = htole32(transfer_handle);
350 request->transfer_op_flag = transfer_op_flag;
351 request->attribute_handle = htole16(attribute_handle);
352 return PLDM_SUCCESS;
353}
354
355int decode_get_bios_attribute_current_value_by_handle_resp(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930356 const struct pldm_msg *msg, size_t payload_length,
357 uint8_t *completion_code, uint32_t *next_transfer_handle,
358 uint8_t *transfer_flag, struct variable_field *attribute_data)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930359{
360 if (msg == NULL || transfer_flag == NULL ||
361 next_transfer_handle == NULL || completion_code == NULL) {
362 return PLDM_ERROR_INVALID_DATA;
363 }
364
365 struct pldm_get_bios_attribute_current_value_by_handle_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930366 (struct pldm_get_bios_attribute_current_value_by_handle_resp *)
367 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930368
369 *completion_code = response->completion_code;
370
371 if (PLDM_SUCCESS != *completion_code) {
372 return PLDM_SUCCESS;
373 }
374
375 if (payload_length <=
376 PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_MIN_RESP_BYTES) {
377 return PLDM_ERROR_INVALID_LENGTH;
378 }
379
380 *next_transfer_handle = le32toh(response->next_transfer_handle);
381 *transfer_flag = response->transfer_flag;
382
383 attribute_data->ptr = response->attribute_data;
384 attribute_data->length = payload_length - sizeof(*response) + 1;
385
386 return PLDM_SUCCESS;
387}
388
389int decode_get_bios_attribute_current_value_by_handle_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930390 const struct pldm_msg *msg, size_t payload_length,
391 uint32_t *transfer_handle, uint8_t *transfer_op_flag,
392 uint16_t *attribute_handle)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930393{
394 if (msg == NULL || transfer_handle == NULL ||
395 transfer_op_flag == NULL || attribute_handle == NULL) {
396 return PLDM_ERROR_INVALID_DATA;
397 }
398
399 if (payload_length != PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_REQ_BYTES) {
400 return PLDM_ERROR_INVALID_LENGTH;
401 }
402
403 struct pldm_get_bios_attribute_current_value_by_handle_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930404 (struct pldm_get_bios_attribute_current_value_by_handle_req *)
405 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930406 *transfer_handle = le32toh(request->transfer_handle);
407 *transfer_op_flag = request->transfer_op_flag;
408 *attribute_handle = le16toh(request->attribute_handle);
409
410 return PLDM_SUCCESS;
411}
412
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930413int encode_get_bios_current_value_by_handle_resp(uint8_t instance_id,
414 uint8_t completion_code,
415 uint32_t next_transfer_handle,
416 uint8_t transfer_flag,
417 const uint8_t *attribute_data,
418 size_t attribute_length,
419 struct pldm_msg *msg)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930420{
421 if (msg == NULL || attribute_data == NULL) {
422 return PLDM_ERROR_INVALID_DATA;
423 }
424
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930425 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930426 header.msg_type = PLDM_RESPONSE;
427 header.instance = instance_id;
428 header.pldm_type = PLDM_BIOS;
429 header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
430
431 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
432 if (rc != PLDM_SUCCESS) {
433 return rc;
434 }
435
436 struct pldm_get_bios_attribute_current_value_by_handle_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930437 (struct pldm_get_bios_attribute_current_value_by_handle_resp *)
438 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930439 response->completion_code = completion_code;
440 if (response->completion_code == PLDM_SUCCESS) {
Andrew Jeffery9c766792022-08-10 23:12:49 +0930441 response->next_transfer_handle = htole32(next_transfer_handle);
442 response->transfer_flag = transfer_flag;
443 if (attribute_data != NULL) {
444 memcpy(response->attribute_data, attribute_data,
445 attribute_length);
446 }
447 }
448 return PLDM_SUCCESS;
449}
450int encode_set_bios_attribute_current_value_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930451 uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_flag,
452 const uint8_t *attribute_data, size_t attribute_length,
453 struct pldm_msg *msg, size_t payload_length)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930454{
455 if (msg == NULL || attribute_data == NULL) {
456 return PLDM_ERROR_INVALID_DATA;
457 }
458 if (PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + attribute_length !=
Andrew Jeffery9145a412023-04-05 20:24:50 +0930459 payload_length) {
Andrew Jeffery9c766792022-08-10 23:12:49 +0930460 return PLDM_ERROR_INVALID_LENGTH;
461 }
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930462 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930463 header.instance = instance_id;
464 header.msg_type = PLDM_REQUEST;
465 header.pldm_type = PLDM_BIOS;
466 header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
467
468 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
469 if (rc != PLDM_SUCCESS) {
470 return rc;
471 }
472
473 struct pldm_set_bios_attribute_current_value_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930474 (struct pldm_set_bios_attribute_current_value_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930475 request->transfer_handle = htole32(transfer_handle);
476 request->transfer_flag = transfer_flag;
477 memcpy(request->attribute_data, attribute_data, attribute_length);
478
479 return PLDM_SUCCESS;
480}
481
482int decode_set_bios_attribute_current_value_resp(const struct pldm_msg *msg,
483 size_t payload_length,
484 uint8_t *completion_code,
485 uint32_t *next_transfer_handle)
486{
487 if (msg == NULL || completion_code == NULL ||
488 next_transfer_handle == NULL) {
489 return PLDM_ERROR_INVALID_DATA;
490 }
491
492 *completion_code = msg->payload[0];
493 if (PLDM_SUCCESS != *completion_code) {
494 return PLDM_SUCCESS;
495 }
496
497 if (payload_length != PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES) {
498 return PLDM_ERROR_INVALID_LENGTH;
499 }
500
501 struct pldm_set_bios_attribute_current_value_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930502 (struct pldm_set_bios_attribute_current_value_resp *)
503 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930504
505 *next_transfer_handle = le32toh(response->next_transfer_handle);
506
507 return PLDM_SUCCESS;
508}
509
510int decode_set_bios_attribute_current_value_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930511 const struct pldm_msg *msg, size_t payload_length,
512 uint32_t *transfer_handle, uint8_t *transfer_flag,
513 struct variable_field *attribute)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930514{
515 if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL ||
516 attribute == NULL) {
517 return PLDM_ERROR_INVALID_DATA;
518 }
519 if (payload_length < PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES) {
520 return PLDM_ERROR_INVALID_LENGTH;
521 }
522
523 struct pldm_set_bios_attribute_current_value_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930524 (struct pldm_set_bios_attribute_current_value_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930525 *transfer_handle = le32toh(request->transfer_handle);
526 *transfer_flag = request->transfer_flag;
527 attribute->length =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930528 payload_length - PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930529 attribute->ptr = request->attribute_data;
530 return PLDM_SUCCESS;
531}
532
533int encode_set_bios_attribute_current_value_resp(uint8_t instance_id,
534 uint8_t completion_code,
535 uint32_t next_transfer_handle,
536 struct pldm_msg *msg)
537{
538 if (msg == NULL) {
539 return PLDM_ERROR_INVALID_DATA;
540 }
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930541 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930542 header.instance = instance_id;
543 header.msg_type = PLDM_RESPONSE;
544 header.pldm_type = PLDM_BIOS;
545 header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
546
547 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
548 if (rc != PLDM_SUCCESS) {
549 return rc;
550 }
551
552 struct pldm_set_bios_attribute_current_value_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930553 (struct pldm_set_bios_attribute_current_value_resp *)
554 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930555 response->completion_code = completion_code;
556 response->next_transfer_handle = htole32(next_transfer_handle);
557
558 return PLDM_SUCCESS;
559}
560
561int encode_set_bios_table_req(uint8_t instance_id, uint32_t transfer_handle,
562 uint8_t transfer_flag, uint8_t table_type,
563 const uint8_t *table_data, size_t table_length,
564 struct pldm_msg *msg, size_t payload_length)
565{
566 if (msg == NULL || table_data == NULL) {
567 return PLDM_ERROR_INVALID_DATA;
568 }
569
570 if (PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES + table_length !=
571 payload_length) {
572 return PLDM_ERROR_INVALID_LENGTH;
573 }
574
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930575 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930576 header.instance = instance_id;
577 header.msg_type = PLDM_REQUEST;
578 header.pldm_type = PLDM_BIOS;
579 header.command = PLDM_SET_BIOS_TABLE;
580
581 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
582 if (rc != PLDM_SUCCESS) {
583 return rc;
584 }
585
586 struct pldm_set_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930587 (struct pldm_set_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930588 request->transfer_handle = htole32(transfer_handle);
589 request->transfer_flag = transfer_flag;
590 request->table_type = table_type;
591 memcpy(request->table_data, table_data, table_length);
592
593 return PLDM_SUCCESS;
594}
595
596int decode_set_bios_table_resp(const struct pldm_msg *msg,
597 size_t payload_length, uint8_t *completion_code,
598 uint32_t *next_transfer_handle)
599{
600 if (msg == NULL || completion_code == NULL ||
601 next_transfer_handle == NULL) {
602 return PLDM_ERROR_INVALID_DATA;
603 }
604
605 *completion_code = msg->payload[0];
606 if (PLDM_SUCCESS != *completion_code) {
607 return PLDM_SUCCESS;
608 }
609
610 if (payload_length != PLDM_SET_BIOS_TABLE_RESP_BYTES) {
611 return PLDM_ERROR_INVALID_LENGTH;
612 }
613
614 struct pldm_set_bios_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930615 (struct pldm_set_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930616
617 *next_transfer_handle = le32toh(response->next_transfer_handle);
618
619 return PLDM_SUCCESS;
620}
621
622int encode_set_bios_table_resp(uint8_t instance_id, uint8_t completion_code,
623 uint32_t next_transfer_handle,
624 struct pldm_msg *msg)
625{
626 if (msg == NULL) {
627 return PLDM_ERROR_INVALID_DATA;
628 }
629
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930630 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930631 header.instance = instance_id;
632 header.msg_type = PLDM_RESPONSE;
633 header.pldm_type = PLDM_BIOS;
634 header.command = PLDM_SET_BIOS_TABLE;
635
636 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
637 if (rc != PLDM_SUCCESS) {
638 return rc;
639 }
640
641 struct pldm_set_bios_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930642 (struct pldm_set_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930643 response->completion_code = completion_code;
644 response->next_transfer_handle = htole32(next_transfer_handle);
645
646 return PLDM_SUCCESS;
647}
648
649int decode_set_bios_table_req(const struct pldm_msg *msg, size_t payload_length,
650 uint32_t *transfer_handle, uint8_t *transfer_flag,
651 uint8_t *table_type, struct variable_field *table)
652{
653 if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL ||
654 table_type == NULL || table == NULL) {
655 return PLDM_ERROR_INVALID_DATA;
656 }
657
658 if (payload_length < PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES) {
659 return PLDM_ERROR_INVALID_LENGTH;
660 }
661
662 struct pldm_set_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930663 (struct pldm_set_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930664 *transfer_handle = le32toh(request->transfer_handle);
665 *transfer_flag = request->transfer_flag;
666 *table_type = request->table_type;
667 table->length = payload_length - PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES;
668 table->ptr = request->table_data;
669
670 return PLDM_SUCCESS;
671}