blob: d833293da3c2d0c693fb26c6a3a399c2af01fcf2 [file] [log] [blame]
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09301#include "config.h"
Andrew Jeffery9c766792022-08-10 23:12:49 +09302#include "bios.h"
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05303#include "base.h"
Andrew Jeffery9c766792022-08-10 23:12:49 +09304#include "utils.h"
5#include <endian.h>
Andrew Jeffery9c766792022-08-10 23:12:49 +09306#include <string.h>
7
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09308LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +09309int encode_get_date_time_req(uint8_t instance_id, struct pldm_msg *msg)
10{
11 if (msg == NULL) {
12 return PLDM_ERROR_INVALID_DATA;
13 }
14
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093015 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093016 header.msg_type = PLDM_REQUEST;
17 header.instance = instance_id;
18 header.pldm_type = PLDM_BIOS;
19 header.command = PLDM_GET_DATE_TIME;
20 return pack_pldm_header(&header, &(msg->hdr));
21}
22
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093023LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093024int encode_get_date_time_resp(uint8_t instance_id, uint8_t completion_code,
25 uint8_t seconds, uint8_t minutes, uint8_t hours,
26 uint8_t day, uint8_t month, uint16_t year,
27 struct pldm_msg *msg)
28{
29 if (msg == NULL) {
30 return PLDM_ERROR_INVALID_DATA;
31 }
32
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093033 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093034 header.msg_type = PLDM_RESPONSE;
35 header.instance = instance_id;
36 header.pldm_type = PLDM_BIOS;
37 header.command = PLDM_GET_DATE_TIME;
38
39 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
40 if (rc != PLDM_SUCCESS) {
41 return rc;
42 }
43
44 struct pldm_get_date_time_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093045 (struct pldm_get_date_time_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093046 response->completion_code = completion_code;
47 if (response->completion_code == PLDM_SUCCESS) {
48 response->completion_code = completion_code;
49 response->seconds = seconds;
50 response->minutes = minutes;
51 response->hours = hours;
52 response->day = day;
53 response->month = month;
54 response->year = htole16(year);
55 }
56 return PLDM_SUCCESS;
57}
58
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093059LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093060int decode_get_date_time_resp(const struct pldm_msg *msg, size_t payload_length,
61 uint8_t *completion_code, uint8_t *seconds,
62 uint8_t *minutes, uint8_t *hours, uint8_t *day,
63 uint8_t *month, uint16_t *year)
64{
65 if (msg == NULL || seconds == NULL || minutes == NULL ||
66 hours == NULL || day == NULL || month == NULL || year == NULL ||
67 completion_code == NULL) {
68 return PLDM_ERROR_INVALID_DATA;
69 }
70
71 *completion_code = msg->payload[0];
72 if (PLDM_SUCCESS != *completion_code) {
73 return PLDM_SUCCESS;
74 }
75
76 if (payload_length != PLDM_GET_DATE_TIME_RESP_BYTES) {
77 return PLDM_ERROR_INVALID_LENGTH;
78 }
79
80 struct pldm_get_date_time_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093081 (struct pldm_get_date_time_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093082
83 *seconds = response->seconds;
84 *minutes = response->minutes;
85 *hours = response->hours;
86 *day = response->day;
87 *month = response->month;
88 *year = le16toh(response->year);
89
90 return PLDM_SUCCESS;
91}
92
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093093LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093094int encode_set_date_time_req(uint8_t instance_id, uint8_t seconds,
95 uint8_t minutes, uint8_t hours, uint8_t day,
96 uint8_t month, uint16_t year, struct pldm_msg *msg,
97 size_t payload_length)
98{
99 if (msg == NULL) {
100 return PLDM_ERROR_INVALID_DATA;
101 }
102 if (payload_length != sizeof(struct pldm_set_date_time_req)) {
103 return PLDM_ERROR_INVALID_LENGTH;
104 }
105
106 if (!is_time_legal(seconds, minutes, hours, day, month, year)) {
107 return PLDM_ERROR_INVALID_DATA;
108 }
109
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930110 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930111 header.instance = instance_id;
112 header.msg_type = PLDM_REQUEST;
113 header.pldm_type = PLDM_BIOS;
114 header.command = PLDM_SET_DATE_TIME;
115
116 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
117 if (rc != PLDM_SUCCESS) {
118 return rc;
119 }
120
121 struct pldm_set_date_time_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930122 (struct pldm_set_date_time_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930123 request->seconds = dec2bcd8(seconds);
124 request->minutes = dec2bcd8(minutes);
125 request->hours = dec2bcd8(hours);
126 request->day = dec2bcd8(day);
127 request->month = dec2bcd8(month);
128 request->year = htole16(dec2bcd16(year));
129
130 return PLDM_SUCCESS;
131}
132
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930133LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930134int decode_set_date_time_req(const struct pldm_msg *msg, size_t payload_length,
135 uint8_t *seconds, uint8_t *minutes, uint8_t *hours,
136 uint8_t *day, uint8_t *month, uint16_t *year)
137{
138 if (msg == NULL || seconds == NULL || minutes == NULL ||
139 hours == NULL || day == NULL || month == NULL || year == NULL) {
140 return PLDM_ERROR_INVALID_DATA;
141 }
142 if (payload_length != sizeof(struct pldm_set_date_time_req)) {
143 return PLDM_ERROR_INVALID_LENGTH;
144 }
145
146 const struct pldm_set_date_time_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930147 (struct pldm_set_date_time_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930148
149 *seconds = bcd2dec8(request->seconds);
150 *minutes = bcd2dec8(request->minutes);
151 *hours = bcd2dec8(request->hours);
152 *day = bcd2dec8(request->day);
153 *month = bcd2dec8(request->month);
154 *year = bcd2dec16(le16toh(request->year));
155
156 if (!is_time_legal(*seconds, *minutes, *hours, *day, *month, *year)) {
157 return PLDM_ERROR_INVALID_DATA;
158 }
159
160 return PLDM_SUCCESS;
161}
162
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930163LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930164int encode_set_date_time_resp(uint8_t instance_id, uint8_t completion_code,
165 struct pldm_msg *msg, size_t payload_length)
166{
167 if (msg == NULL) {
168 return PLDM_ERROR_INVALID_DATA;
169 }
170 if (payload_length != sizeof(struct pldm_only_cc_resp)) {
171 return PLDM_ERROR_INVALID_LENGTH;
172 }
173
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930174 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930175 header.instance = instance_id;
176 header.msg_type = PLDM_RESPONSE;
177 header.pldm_type = PLDM_BIOS;
178 header.command = PLDM_SET_DATE_TIME;
179
180 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
181 if (rc != PLDM_SUCCESS) {
182 return rc;
183 }
184
185 struct pldm_only_cc_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930186 (struct pldm_only_cc_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930187 response->completion_code = completion_code;
188
189 return PLDM_SUCCESS;
190}
191
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930192LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930193int decode_set_date_time_resp(const struct pldm_msg *msg, size_t payload_length,
194 uint8_t *completion_code)
195{
196 if (msg == NULL || completion_code == NULL) {
197 return PLDM_ERROR_INVALID_DATA;
198 }
199
200 *completion_code = msg->payload[0];
201 if (PLDM_SUCCESS != *completion_code) {
202 return PLDM_SUCCESS;
203 }
204
205 if (payload_length != sizeof(struct pldm_only_cc_resp)) {
206 return PLDM_ERROR_INVALID_LENGTH;
207 }
208
209 return PLDM_SUCCESS;
210}
211
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930212LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930213int encode_get_bios_table_resp(uint8_t instance_id, uint8_t completion_code,
214 uint32_t next_transfer_handle,
215 uint8_t transfer_flag, uint8_t *table_data,
216 size_t payload_length, struct pldm_msg *msg)
217{
218 if (msg == NULL) {
219 return PLDM_ERROR_INVALID_DATA;
220 }
221
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930222 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930223 header.msg_type = PLDM_RESPONSE;
224 header.instance = instance_id;
225 header.pldm_type = PLDM_BIOS;
226 header.command = PLDM_GET_BIOS_TABLE;
227
228 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
229 if (rc != PLDM_SUCCESS) {
230 return rc;
231 }
232
233 struct pldm_get_bios_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930234 (struct pldm_get_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930235 response->completion_code = completion_code;
236 if (response->completion_code == PLDM_SUCCESS) {
Andrew Jeffery9c766792022-08-10 23:12:49 +0930237 response->next_transfer_handle = htole32(next_transfer_handle);
238 response->transfer_flag = transfer_flag;
239 if (table_data != NULL &&
240 payload_length > (sizeof(struct pldm_msg_hdr) +
241 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES)) {
242 memcpy(response->table_data, table_data,
243 payload_length -
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930244 (sizeof(struct pldm_msg_hdr) +
245 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES));
Andrew Jeffery9c766792022-08-10 23:12:49 +0930246 }
247 }
248 return PLDM_SUCCESS;
249}
250
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930251LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930252int encode_get_bios_table_req(uint8_t instance_id, uint32_t transfer_handle,
253 uint8_t transfer_op_flag, uint8_t table_type,
254 struct pldm_msg *msg)
255{
256 if (msg == NULL) {
257 return PLDM_ERROR_INVALID_DATA;
258 }
259
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930260 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930261 header.msg_type = PLDM_REQUEST;
262 header.instance = instance_id;
263 header.pldm_type = PLDM_BIOS;
264 header.command = PLDM_GET_BIOS_TABLE;
265
266 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
267 if (rc != PLDM_SUCCESS) {
268 return rc;
269 }
270
271 struct pldm_get_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930272 (struct pldm_get_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930273
274 request->transfer_handle = htole32(transfer_handle);
275 request->transfer_op_flag = transfer_op_flag;
276 request->table_type = table_type;
277 return PLDM_SUCCESS;
278}
279
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930280LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930281int decode_get_bios_table_req(const struct pldm_msg *msg, size_t payload_length,
282 uint32_t *transfer_handle,
283 uint8_t *transfer_op_flag, uint8_t *table_type)
284{
285 if (msg == NULL || transfer_op_flag == NULL || table_type == NULL ||
286 transfer_handle == NULL) {
287 return PLDM_ERROR_INVALID_DATA;
288 }
289
290 if (payload_length != PLDM_GET_BIOS_TABLE_REQ_BYTES) {
291 return PLDM_ERROR_INVALID_LENGTH;
292 }
293
294 struct pldm_get_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930295 (struct pldm_get_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930296 *transfer_handle = le32toh(request->transfer_handle);
297 *transfer_op_flag = request->transfer_op_flag;
298 *table_type = request->table_type;
299
300 return PLDM_SUCCESS;
301}
302
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930303LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930304int decode_get_bios_table_resp(const struct pldm_msg *msg,
305 size_t payload_length, uint8_t *completion_code,
306 uint32_t *next_transfer_handle,
307 uint8_t *transfer_flag,
308 size_t *bios_table_offset)
309
310{
311 if (msg == NULL || transfer_flag == NULL ||
312 next_transfer_handle == NULL || completion_code == NULL) {
313 return PLDM_ERROR_INVALID_DATA;
314 }
315 if (payload_length <= PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES) {
316 return PLDM_ERROR_INVALID_LENGTH;
317 }
318
319 struct pldm_get_bios_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930320 (struct pldm_get_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930321
322 *completion_code = response->completion_code;
323
324 if (PLDM_SUCCESS != *completion_code) {
325 return PLDM_SUCCESS;
326 }
327
328 *next_transfer_handle = le32toh(response->next_transfer_handle);
329 *transfer_flag = response->transfer_flag;
330
331 *bios_table_offset = sizeof(*completion_code) +
332 sizeof(*next_transfer_handle) +
333 sizeof(*transfer_flag);
334
335 return PLDM_SUCCESS;
336}
337
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930338LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930339int encode_get_bios_attribute_current_value_by_handle_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930340 uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_op_flag,
341 uint16_t attribute_handle, struct pldm_msg *msg)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930342{
343 if (msg == NULL) {
344 return PLDM_ERROR_INVALID_DATA;
345 }
346
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930347 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930348 header.msg_type = PLDM_REQUEST;
349 header.instance = instance_id;
350 header.pldm_type = PLDM_BIOS;
351 header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
352
353 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
354 if (rc != PLDM_SUCCESS) {
355 return rc;
356 }
357
358 struct pldm_get_bios_attribute_current_value_by_handle_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930359 (struct pldm_get_bios_attribute_current_value_by_handle_req *)
360 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930361
362 request->transfer_handle = htole32(transfer_handle);
363 request->transfer_op_flag = transfer_op_flag;
364 request->attribute_handle = htole16(attribute_handle);
365 return PLDM_SUCCESS;
366}
367
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930368LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930369int decode_get_bios_attribute_current_value_by_handle_resp(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930370 const struct pldm_msg *msg, size_t payload_length,
371 uint8_t *completion_code, uint32_t *next_transfer_handle,
372 uint8_t *transfer_flag, struct variable_field *attribute_data)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930373{
374 if (msg == NULL || transfer_flag == NULL ||
375 next_transfer_handle == NULL || completion_code == NULL) {
376 return PLDM_ERROR_INVALID_DATA;
377 }
378
379 struct pldm_get_bios_attribute_current_value_by_handle_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930380 (struct pldm_get_bios_attribute_current_value_by_handle_resp *)
381 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930382
383 *completion_code = response->completion_code;
384
385 if (PLDM_SUCCESS != *completion_code) {
386 return PLDM_SUCCESS;
387 }
388
389 if (payload_length <=
390 PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_MIN_RESP_BYTES) {
391 return PLDM_ERROR_INVALID_LENGTH;
392 }
393
394 *next_transfer_handle = le32toh(response->next_transfer_handle);
395 *transfer_flag = response->transfer_flag;
396
397 attribute_data->ptr = response->attribute_data;
398 attribute_data->length = payload_length - sizeof(*response) + 1;
399
400 return PLDM_SUCCESS;
401}
402
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930403LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930404int decode_get_bios_attribute_current_value_by_handle_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930405 const struct pldm_msg *msg, size_t payload_length,
406 uint32_t *transfer_handle, uint8_t *transfer_op_flag,
407 uint16_t *attribute_handle)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930408{
409 if (msg == NULL || transfer_handle == NULL ||
410 transfer_op_flag == NULL || attribute_handle == NULL) {
411 return PLDM_ERROR_INVALID_DATA;
412 }
413
414 if (payload_length != PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_REQ_BYTES) {
415 return PLDM_ERROR_INVALID_LENGTH;
416 }
417
418 struct pldm_get_bios_attribute_current_value_by_handle_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930419 (struct pldm_get_bios_attribute_current_value_by_handle_req *)
420 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930421 *transfer_handle = le32toh(request->transfer_handle);
422 *transfer_op_flag = request->transfer_op_flag;
423 *attribute_handle = le16toh(request->attribute_handle);
424
425 return PLDM_SUCCESS;
426}
427
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930428LIBPLDM_ABI_STABLE
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930429int encode_get_bios_current_value_by_handle_resp(uint8_t instance_id,
430 uint8_t completion_code,
431 uint32_t next_transfer_handle,
432 uint8_t transfer_flag,
433 const uint8_t *attribute_data,
434 size_t attribute_length,
435 struct pldm_msg *msg)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930436{
437 if (msg == NULL || attribute_data == NULL) {
438 return PLDM_ERROR_INVALID_DATA;
439 }
440
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930441 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930442 header.msg_type = PLDM_RESPONSE;
443 header.instance = instance_id;
444 header.pldm_type = PLDM_BIOS;
445 header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
446
447 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
448 if (rc != PLDM_SUCCESS) {
449 return rc;
450 }
451
452 struct pldm_get_bios_attribute_current_value_by_handle_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930453 (struct pldm_get_bios_attribute_current_value_by_handle_resp *)
454 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930455 response->completion_code = completion_code;
456 if (response->completion_code == PLDM_SUCCESS) {
Andrew Jeffery9c766792022-08-10 23:12:49 +0930457 response->next_transfer_handle = htole32(next_transfer_handle);
458 response->transfer_flag = transfer_flag;
459 if (attribute_data != NULL) {
460 memcpy(response->attribute_data, attribute_data,
461 attribute_length);
462 }
463 }
464 return PLDM_SUCCESS;
465}
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930466
467LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930468int encode_set_bios_attribute_current_value_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930469 uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_flag,
470 const uint8_t *attribute_data, size_t attribute_length,
471 struct pldm_msg *msg, size_t payload_length)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930472{
473 if (msg == NULL || attribute_data == NULL) {
474 return PLDM_ERROR_INVALID_DATA;
475 }
476 if (PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + attribute_length !=
Andrew Jeffery9145a412023-04-05 20:24:50 +0930477 payload_length) {
Andrew Jeffery9c766792022-08-10 23:12:49 +0930478 return PLDM_ERROR_INVALID_LENGTH;
479 }
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930480 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930481 header.instance = instance_id;
482 header.msg_type = PLDM_REQUEST;
483 header.pldm_type = PLDM_BIOS;
484 header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
485
486 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
487 if (rc != PLDM_SUCCESS) {
488 return rc;
489 }
490
491 struct pldm_set_bios_attribute_current_value_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930492 (struct pldm_set_bios_attribute_current_value_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930493 request->transfer_handle = htole32(transfer_handle);
494 request->transfer_flag = transfer_flag;
495 memcpy(request->attribute_data, attribute_data, attribute_length);
496
497 return PLDM_SUCCESS;
498}
499
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930500LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930501int decode_set_bios_attribute_current_value_resp(const struct pldm_msg *msg,
502 size_t payload_length,
503 uint8_t *completion_code,
504 uint32_t *next_transfer_handle)
505{
506 if (msg == NULL || completion_code == NULL ||
507 next_transfer_handle == NULL) {
508 return PLDM_ERROR_INVALID_DATA;
509 }
510
511 *completion_code = msg->payload[0];
512 if (PLDM_SUCCESS != *completion_code) {
513 return PLDM_SUCCESS;
514 }
515
516 if (payload_length != PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES) {
517 return PLDM_ERROR_INVALID_LENGTH;
518 }
519
520 struct pldm_set_bios_attribute_current_value_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930521 (struct pldm_set_bios_attribute_current_value_resp *)
522 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930523
524 *next_transfer_handle = le32toh(response->next_transfer_handle);
525
526 return PLDM_SUCCESS;
527}
528
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930529LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930530int decode_set_bios_attribute_current_value_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930531 const struct pldm_msg *msg, size_t payload_length,
532 uint32_t *transfer_handle, uint8_t *transfer_flag,
533 struct variable_field *attribute)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930534{
535 if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL ||
536 attribute == NULL) {
537 return PLDM_ERROR_INVALID_DATA;
538 }
539 if (payload_length < PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES) {
540 return PLDM_ERROR_INVALID_LENGTH;
541 }
542
543 struct pldm_set_bios_attribute_current_value_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930544 (struct pldm_set_bios_attribute_current_value_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930545 *transfer_handle = le32toh(request->transfer_handle);
546 *transfer_flag = request->transfer_flag;
547 attribute->length =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930548 payload_length - PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930549 attribute->ptr = request->attribute_data;
550 return PLDM_SUCCESS;
551}
552
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930553LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930554int encode_set_bios_attribute_current_value_resp(uint8_t instance_id,
555 uint8_t completion_code,
556 uint32_t next_transfer_handle,
557 struct pldm_msg *msg)
558{
559 if (msg == NULL) {
560 return PLDM_ERROR_INVALID_DATA;
561 }
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930562 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930563 header.instance = instance_id;
564 header.msg_type = PLDM_RESPONSE;
565 header.pldm_type = PLDM_BIOS;
566 header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
567
568 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
569 if (rc != PLDM_SUCCESS) {
570 return rc;
571 }
572
573 struct pldm_set_bios_attribute_current_value_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930574 (struct pldm_set_bios_attribute_current_value_resp *)
575 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930576 response->completion_code = completion_code;
577 response->next_transfer_handle = htole32(next_transfer_handle);
578
579 return PLDM_SUCCESS;
580}
581
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930582LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930583int encode_set_bios_table_req(uint8_t instance_id, uint32_t transfer_handle,
584 uint8_t transfer_flag, uint8_t table_type,
585 const uint8_t *table_data, size_t table_length,
586 struct pldm_msg *msg, size_t payload_length)
587{
588 if (msg == NULL || table_data == NULL) {
589 return PLDM_ERROR_INVALID_DATA;
590 }
591
592 if (PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES + table_length !=
593 payload_length) {
594 return PLDM_ERROR_INVALID_LENGTH;
595 }
596
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930597 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930598 header.instance = instance_id;
599 header.msg_type = PLDM_REQUEST;
600 header.pldm_type = PLDM_BIOS;
601 header.command = PLDM_SET_BIOS_TABLE;
602
603 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
604 if (rc != PLDM_SUCCESS) {
605 return rc;
606 }
607
608 struct pldm_set_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930609 (struct pldm_set_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930610 request->transfer_handle = htole32(transfer_handle);
611 request->transfer_flag = transfer_flag;
612 request->table_type = table_type;
613 memcpy(request->table_data, table_data, table_length);
614
615 return PLDM_SUCCESS;
616}
617
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930618LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930619int decode_set_bios_table_resp(const struct pldm_msg *msg,
620 size_t payload_length, uint8_t *completion_code,
621 uint32_t *next_transfer_handle)
622{
623 if (msg == NULL || completion_code == NULL ||
624 next_transfer_handle == NULL) {
625 return PLDM_ERROR_INVALID_DATA;
626 }
627
628 *completion_code = msg->payload[0];
629 if (PLDM_SUCCESS != *completion_code) {
630 return PLDM_SUCCESS;
631 }
632
633 if (payload_length != PLDM_SET_BIOS_TABLE_RESP_BYTES) {
634 return PLDM_ERROR_INVALID_LENGTH;
635 }
636
637 struct pldm_set_bios_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930638 (struct pldm_set_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930639
640 *next_transfer_handle = le32toh(response->next_transfer_handle);
641
642 return PLDM_SUCCESS;
643}
644
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930645LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930646int encode_set_bios_table_resp(uint8_t instance_id, uint8_t completion_code,
647 uint32_t next_transfer_handle,
648 struct pldm_msg *msg)
649{
650 if (msg == NULL) {
651 return PLDM_ERROR_INVALID_DATA;
652 }
653
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930654 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930655 header.instance = instance_id;
656 header.msg_type = PLDM_RESPONSE;
657 header.pldm_type = PLDM_BIOS;
658 header.command = PLDM_SET_BIOS_TABLE;
659
660 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
661 if (rc != PLDM_SUCCESS) {
662 return rc;
663 }
664
665 struct pldm_set_bios_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930666 (struct pldm_set_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930667 response->completion_code = completion_code;
668 response->next_transfer_handle = htole32(next_transfer_handle);
669
670 return PLDM_SUCCESS;
671}
672
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930673LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930674int decode_set_bios_table_req(const struct pldm_msg *msg, size_t payload_length,
675 uint32_t *transfer_handle, uint8_t *transfer_flag,
676 uint8_t *table_type, struct variable_field *table)
677{
678 if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL ||
679 table_type == NULL || table == NULL) {
680 return PLDM_ERROR_INVALID_DATA;
681 }
682
683 if (payload_length < PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES) {
684 return PLDM_ERROR_INVALID_LENGTH;
685 }
686
687 struct pldm_set_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930688 (struct pldm_set_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930689 *transfer_handle = le32toh(request->transfer_handle);
690 *transfer_flag = request->transfer_flag;
691 *table_type = request->table_type;
692 table->length = payload_length - PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES;
693 table->ptr = request->table_data;
694
695 return PLDM_SUCCESS;
696}