blob: 45dc897e1a1a139705972548f14e45f63a1f25c9 [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
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09307LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +09308int encode_get_date_time_req(uint8_t instance_id, struct pldm_msg *msg)
9{
10 if (msg == NULL) {
11 return PLDM_ERROR_INVALID_DATA;
12 }
13
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093014 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093015 header.msg_type = PLDM_REQUEST;
16 header.instance = instance_id;
17 header.pldm_type = PLDM_BIOS;
18 header.command = PLDM_GET_DATE_TIME;
19 return pack_pldm_header(&header, &(msg->hdr));
20}
21
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093022LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093023int encode_get_date_time_resp(uint8_t instance_id, uint8_t completion_code,
24 uint8_t seconds, uint8_t minutes, uint8_t hours,
25 uint8_t day, uint8_t month, uint16_t year,
26 struct pldm_msg *msg)
27{
28 if (msg == NULL) {
29 return PLDM_ERROR_INVALID_DATA;
30 }
31
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093032 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093033 header.msg_type = PLDM_RESPONSE;
34 header.instance = instance_id;
35 header.pldm_type = PLDM_BIOS;
36 header.command = PLDM_GET_DATE_TIME;
37
38 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
39 if (rc != PLDM_SUCCESS) {
40 return rc;
41 }
42
43 struct pldm_get_date_time_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093044 (struct pldm_get_date_time_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093045 response->completion_code = completion_code;
46 if (response->completion_code == PLDM_SUCCESS) {
47 response->completion_code = completion_code;
48 response->seconds = seconds;
49 response->minutes = minutes;
50 response->hours = hours;
51 response->day = day;
52 response->month = month;
53 response->year = htole16(year);
54 }
55 return PLDM_SUCCESS;
56}
57
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093058LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093059int decode_get_date_time_resp(const struct pldm_msg *msg, size_t payload_length,
60 uint8_t *completion_code, uint8_t *seconds,
61 uint8_t *minutes, uint8_t *hours, uint8_t *day,
62 uint8_t *month, uint16_t *year)
63{
64 if (msg == NULL || seconds == NULL || minutes == NULL ||
65 hours == NULL || day == NULL || month == NULL || year == NULL ||
66 completion_code == NULL) {
67 return PLDM_ERROR_INVALID_DATA;
68 }
69
70 *completion_code = msg->payload[0];
71 if (PLDM_SUCCESS != *completion_code) {
72 return PLDM_SUCCESS;
73 }
74
75 if (payload_length != PLDM_GET_DATE_TIME_RESP_BYTES) {
76 return PLDM_ERROR_INVALID_LENGTH;
77 }
78
79 struct pldm_get_date_time_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093080 (struct pldm_get_date_time_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093081
82 *seconds = response->seconds;
83 *minutes = response->minutes;
84 *hours = response->hours;
85 *day = response->day;
86 *month = response->month;
87 *year = le16toh(response->year);
88
89 return PLDM_SUCCESS;
90}
91
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093092LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093093int encode_set_date_time_req(uint8_t instance_id, uint8_t seconds,
94 uint8_t minutes, uint8_t hours, uint8_t day,
95 uint8_t month, uint16_t year, struct pldm_msg *msg,
96 size_t payload_length)
97{
98 if (msg == NULL) {
99 return PLDM_ERROR_INVALID_DATA;
100 }
101 if (payload_length != sizeof(struct pldm_set_date_time_req)) {
102 return PLDM_ERROR_INVALID_LENGTH;
103 }
104
105 if (!is_time_legal(seconds, minutes, hours, day, month, year)) {
106 return PLDM_ERROR_INVALID_DATA;
107 }
108
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930109 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930110 header.instance = instance_id;
111 header.msg_type = PLDM_REQUEST;
112 header.pldm_type = PLDM_BIOS;
113 header.command = PLDM_SET_DATE_TIME;
114
115 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
116 if (rc != PLDM_SUCCESS) {
117 return rc;
118 }
119
120 struct pldm_set_date_time_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930121 (struct pldm_set_date_time_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930122 request->seconds = dec2bcd8(seconds);
123 request->minutes = dec2bcd8(minutes);
124 request->hours = dec2bcd8(hours);
125 request->day = dec2bcd8(day);
126 request->month = dec2bcd8(month);
127 request->year = htole16(dec2bcd16(year));
128
129 return PLDM_SUCCESS;
130}
131
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930132LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930133int decode_set_date_time_req(const struct pldm_msg *msg, size_t payload_length,
134 uint8_t *seconds, uint8_t *minutes, uint8_t *hours,
135 uint8_t *day, uint8_t *month, uint16_t *year)
136{
137 if (msg == NULL || seconds == NULL || minutes == NULL ||
138 hours == NULL || day == NULL || month == NULL || year == NULL) {
139 return PLDM_ERROR_INVALID_DATA;
140 }
141 if (payload_length != sizeof(struct pldm_set_date_time_req)) {
142 return PLDM_ERROR_INVALID_LENGTH;
143 }
144
145 const struct pldm_set_date_time_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930146 (struct pldm_set_date_time_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930147
148 *seconds = bcd2dec8(request->seconds);
149 *minutes = bcd2dec8(request->minutes);
150 *hours = bcd2dec8(request->hours);
151 *day = bcd2dec8(request->day);
152 *month = bcd2dec8(request->month);
153 *year = bcd2dec16(le16toh(request->year));
154
155 if (!is_time_legal(*seconds, *minutes, *hours, *day, *month, *year)) {
156 return PLDM_ERROR_INVALID_DATA;
157 }
158
159 return PLDM_SUCCESS;
160}
161
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930162LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930163int encode_set_date_time_resp(uint8_t instance_id, uint8_t completion_code,
164 struct pldm_msg *msg, size_t payload_length)
165{
166 if (msg == NULL) {
167 return PLDM_ERROR_INVALID_DATA;
168 }
169 if (payload_length != sizeof(struct pldm_only_cc_resp)) {
170 return PLDM_ERROR_INVALID_LENGTH;
171 }
172
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930173 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930174 header.instance = instance_id;
175 header.msg_type = PLDM_RESPONSE;
176 header.pldm_type = PLDM_BIOS;
177 header.command = PLDM_SET_DATE_TIME;
178
179 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
180 if (rc != PLDM_SUCCESS) {
181 return rc;
182 }
183
184 struct pldm_only_cc_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930185 (struct pldm_only_cc_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930186 response->completion_code = completion_code;
187
188 return PLDM_SUCCESS;
189}
190
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930191LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930192int decode_set_date_time_resp(const struct pldm_msg *msg, size_t payload_length,
193 uint8_t *completion_code)
194{
195 if (msg == NULL || completion_code == NULL) {
196 return PLDM_ERROR_INVALID_DATA;
197 }
198
199 *completion_code = msg->payload[0];
200 if (PLDM_SUCCESS != *completion_code) {
201 return PLDM_SUCCESS;
202 }
203
204 if (payload_length != sizeof(struct pldm_only_cc_resp)) {
205 return PLDM_ERROR_INVALID_LENGTH;
206 }
207
208 return PLDM_SUCCESS;
209}
210
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930211LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930212int encode_get_bios_table_resp(uint8_t instance_id, uint8_t completion_code,
213 uint32_t next_transfer_handle,
214 uint8_t transfer_flag, uint8_t *table_data,
215 size_t payload_length, struct pldm_msg *msg)
216{
217 if (msg == NULL) {
218 return PLDM_ERROR_INVALID_DATA;
219 }
220
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930221 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930222 header.msg_type = PLDM_RESPONSE;
223 header.instance = instance_id;
224 header.pldm_type = PLDM_BIOS;
225 header.command = PLDM_GET_BIOS_TABLE;
226
227 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
228 if (rc != PLDM_SUCCESS) {
229 return rc;
230 }
231
232 struct pldm_get_bios_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930233 (struct pldm_get_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930234 response->completion_code = completion_code;
235 if (response->completion_code == PLDM_SUCCESS) {
Andrew Jeffery9c766792022-08-10 23:12:49 +0930236 response->next_transfer_handle = htole32(next_transfer_handle);
237 response->transfer_flag = transfer_flag;
238 if (table_data != NULL &&
239 payload_length > (sizeof(struct pldm_msg_hdr) +
240 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES)) {
241 memcpy(response->table_data, table_data,
242 payload_length -
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930243 (sizeof(struct pldm_msg_hdr) +
244 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES));
Andrew Jeffery9c766792022-08-10 23:12:49 +0930245 }
246 }
247 return PLDM_SUCCESS;
248}
249
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930250LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930251int encode_get_bios_table_req(uint8_t instance_id, uint32_t transfer_handle,
252 uint8_t transfer_op_flag, uint8_t table_type,
253 struct pldm_msg *msg)
254{
255 if (msg == NULL) {
256 return PLDM_ERROR_INVALID_DATA;
257 }
258
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930259 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930260 header.msg_type = PLDM_REQUEST;
261 header.instance = instance_id;
262 header.pldm_type = PLDM_BIOS;
263 header.command = PLDM_GET_BIOS_TABLE;
264
265 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
266 if (rc != PLDM_SUCCESS) {
267 return rc;
268 }
269
270 struct pldm_get_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930271 (struct pldm_get_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930272
273 request->transfer_handle = htole32(transfer_handle);
274 request->transfer_op_flag = transfer_op_flag;
275 request->table_type = table_type;
276 return PLDM_SUCCESS;
277}
278
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930279LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930280int decode_get_bios_table_req(const struct pldm_msg *msg, size_t payload_length,
281 uint32_t *transfer_handle,
282 uint8_t *transfer_op_flag, uint8_t *table_type)
283{
284 if (msg == NULL || transfer_op_flag == NULL || table_type == NULL ||
285 transfer_handle == NULL) {
286 return PLDM_ERROR_INVALID_DATA;
287 }
288
289 if (payload_length != PLDM_GET_BIOS_TABLE_REQ_BYTES) {
290 return PLDM_ERROR_INVALID_LENGTH;
291 }
292
293 struct pldm_get_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930294 (struct pldm_get_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930295 *transfer_handle = le32toh(request->transfer_handle);
296 *transfer_op_flag = request->transfer_op_flag;
297 *table_type = request->table_type;
298
299 return PLDM_SUCCESS;
300}
301
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930302LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930303int decode_get_bios_table_resp(const struct pldm_msg *msg,
304 size_t payload_length, uint8_t *completion_code,
305 uint32_t *next_transfer_handle,
306 uint8_t *transfer_flag,
307 size_t *bios_table_offset)
308
309{
310 if (msg == NULL || transfer_flag == NULL ||
311 next_transfer_handle == NULL || completion_code == NULL) {
312 return PLDM_ERROR_INVALID_DATA;
313 }
314 if (payload_length <= PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES) {
315 return PLDM_ERROR_INVALID_LENGTH;
316 }
317
318 struct pldm_get_bios_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930319 (struct pldm_get_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930320
321 *completion_code = response->completion_code;
322
323 if (PLDM_SUCCESS != *completion_code) {
324 return PLDM_SUCCESS;
325 }
326
327 *next_transfer_handle = le32toh(response->next_transfer_handle);
328 *transfer_flag = response->transfer_flag;
329
330 *bios_table_offset = sizeof(*completion_code) +
331 sizeof(*next_transfer_handle) +
332 sizeof(*transfer_flag);
333
334 return PLDM_SUCCESS;
335}
336
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930337LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930338int encode_get_bios_attribute_current_value_by_handle_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930339 uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_op_flag,
340 uint16_t attribute_handle, struct pldm_msg *msg)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930341{
342 if (msg == NULL) {
343 return PLDM_ERROR_INVALID_DATA;
344 }
345
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930346 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930347 header.msg_type = PLDM_REQUEST;
348 header.instance = instance_id;
349 header.pldm_type = PLDM_BIOS;
350 header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
351
352 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
353 if (rc != PLDM_SUCCESS) {
354 return rc;
355 }
356
357 struct pldm_get_bios_attribute_current_value_by_handle_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930358 (struct pldm_get_bios_attribute_current_value_by_handle_req *)
359 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930360
361 request->transfer_handle = htole32(transfer_handle);
362 request->transfer_op_flag = transfer_op_flag;
363 request->attribute_handle = htole16(attribute_handle);
364 return PLDM_SUCCESS;
365}
366
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930367LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930368int decode_get_bios_attribute_current_value_by_handle_resp(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930369 const struct pldm_msg *msg, size_t payload_length,
370 uint8_t *completion_code, uint32_t *next_transfer_handle,
371 uint8_t *transfer_flag, struct variable_field *attribute_data)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930372{
373 if (msg == NULL || transfer_flag == NULL ||
374 next_transfer_handle == NULL || completion_code == NULL) {
375 return PLDM_ERROR_INVALID_DATA;
376 }
377
378 struct pldm_get_bios_attribute_current_value_by_handle_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930379 (struct pldm_get_bios_attribute_current_value_by_handle_resp *)
380 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930381
382 *completion_code = response->completion_code;
383
384 if (PLDM_SUCCESS != *completion_code) {
385 return PLDM_SUCCESS;
386 }
387
388 if (payload_length <=
389 PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_MIN_RESP_BYTES) {
390 return PLDM_ERROR_INVALID_LENGTH;
391 }
392
393 *next_transfer_handle = le32toh(response->next_transfer_handle);
394 *transfer_flag = response->transfer_flag;
395
396 attribute_data->ptr = response->attribute_data;
397 attribute_data->length = payload_length - sizeof(*response) + 1;
398
399 return PLDM_SUCCESS;
400}
401
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930402LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930403int decode_get_bios_attribute_current_value_by_handle_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930404 const struct pldm_msg *msg, size_t payload_length,
405 uint32_t *transfer_handle, uint8_t *transfer_op_flag,
406 uint16_t *attribute_handle)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930407{
408 if (msg == NULL || transfer_handle == NULL ||
409 transfer_op_flag == NULL || attribute_handle == NULL) {
410 return PLDM_ERROR_INVALID_DATA;
411 }
412
413 if (payload_length != PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_REQ_BYTES) {
414 return PLDM_ERROR_INVALID_LENGTH;
415 }
416
417 struct pldm_get_bios_attribute_current_value_by_handle_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930418 (struct pldm_get_bios_attribute_current_value_by_handle_req *)
419 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930420 *transfer_handle = le32toh(request->transfer_handle);
421 *transfer_op_flag = request->transfer_op_flag;
422 *attribute_handle = le16toh(request->attribute_handle);
423
424 return PLDM_SUCCESS;
425}
426
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930427LIBPLDM_ABI_STABLE
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930428int encode_get_bios_current_value_by_handle_resp(uint8_t instance_id,
429 uint8_t completion_code,
430 uint32_t next_transfer_handle,
431 uint8_t transfer_flag,
432 const uint8_t *attribute_data,
433 size_t attribute_length,
434 struct pldm_msg *msg)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930435{
436 if (msg == NULL || attribute_data == NULL) {
437 return PLDM_ERROR_INVALID_DATA;
438 }
439
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930440 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930441 header.msg_type = PLDM_RESPONSE;
442 header.instance = instance_id;
443 header.pldm_type = PLDM_BIOS;
444 header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
445
446 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
447 if (rc != PLDM_SUCCESS) {
448 return rc;
449 }
450
451 struct pldm_get_bios_attribute_current_value_by_handle_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930452 (struct pldm_get_bios_attribute_current_value_by_handle_resp *)
453 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930454 response->completion_code = completion_code;
455 if (response->completion_code == PLDM_SUCCESS) {
Andrew Jeffery9c766792022-08-10 23:12:49 +0930456 response->next_transfer_handle = htole32(next_transfer_handle);
457 response->transfer_flag = transfer_flag;
458 if (attribute_data != NULL) {
459 memcpy(response->attribute_data, attribute_data,
460 attribute_length);
461 }
462 }
463 return PLDM_SUCCESS;
464}
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930465
466LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930467int encode_set_bios_attribute_current_value_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930468 uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_flag,
469 const uint8_t *attribute_data, size_t attribute_length,
470 struct pldm_msg *msg, size_t payload_length)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930471{
472 if (msg == NULL || attribute_data == NULL) {
473 return PLDM_ERROR_INVALID_DATA;
474 }
475 if (PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + attribute_length !=
Andrew Jeffery9145a412023-04-05 20:24:50 +0930476 payload_length) {
Andrew Jeffery9c766792022-08-10 23:12:49 +0930477 return PLDM_ERROR_INVALID_LENGTH;
478 }
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930479 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930480 header.instance = instance_id;
481 header.msg_type = PLDM_REQUEST;
482 header.pldm_type = PLDM_BIOS;
483 header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
484
485 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
486 if (rc != PLDM_SUCCESS) {
487 return rc;
488 }
489
490 struct pldm_set_bios_attribute_current_value_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930491 (struct pldm_set_bios_attribute_current_value_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930492 request->transfer_handle = htole32(transfer_handle);
493 request->transfer_flag = transfer_flag;
494 memcpy(request->attribute_data, attribute_data, attribute_length);
495
496 return PLDM_SUCCESS;
497}
498
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930499LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930500int decode_set_bios_attribute_current_value_resp(const struct pldm_msg *msg,
501 size_t payload_length,
502 uint8_t *completion_code,
503 uint32_t *next_transfer_handle)
504{
505 if (msg == NULL || completion_code == NULL ||
506 next_transfer_handle == NULL) {
507 return PLDM_ERROR_INVALID_DATA;
508 }
509
510 *completion_code = msg->payload[0];
511 if (PLDM_SUCCESS != *completion_code) {
512 return PLDM_SUCCESS;
513 }
514
515 if (payload_length != PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES) {
516 return PLDM_ERROR_INVALID_LENGTH;
517 }
518
519 struct pldm_set_bios_attribute_current_value_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930520 (struct pldm_set_bios_attribute_current_value_resp *)
521 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930522
523 *next_transfer_handle = le32toh(response->next_transfer_handle);
524
525 return PLDM_SUCCESS;
526}
527
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930528LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930529int decode_set_bios_attribute_current_value_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930530 const struct pldm_msg *msg, size_t payload_length,
531 uint32_t *transfer_handle, uint8_t *transfer_flag,
532 struct variable_field *attribute)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930533{
534 if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL ||
535 attribute == NULL) {
536 return PLDM_ERROR_INVALID_DATA;
537 }
538 if (payload_length < PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES) {
539 return PLDM_ERROR_INVALID_LENGTH;
540 }
541
542 struct pldm_set_bios_attribute_current_value_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930543 (struct pldm_set_bios_attribute_current_value_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930544 *transfer_handle = le32toh(request->transfer_handle);
545 *transfer_flag = request->transfer_flag;
546 attribute->length =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930547 payload_length - PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930548 attribute->ptr = request->attribute_data;
549 return PLDM_SUCCESS;
550}
551
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930552LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930553int encode_set_bios_attribute_current_value_resp(uint8_t instance_id,
554 uint8_t completion_code,
555 uint32_t next_transfer_handle,
556 struct pldm_msg *msg)
557{
558 if (msg == NULL) {
559 return PLDM_ERROR_INVALID_DATA;
560 }
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930561 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930562 header.instance = instance_id;
563 header.msg_type = PLDM_RESPONSE;
564 header.pldm_type = PLDM_BIOS;
565 header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
566
567 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
568 if (rc != PLDM_SUCCESS) {
569 return rc;
570 }
571
572 struct pldm_set_bios_attribute_current_value_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930573 (struct pldm_set_bios_attribute_current_value_resp *)
574 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930575 response->completion_code = completion_code;
576 response->next_transfer_handle = htole32(next_transfer_handle);
577
578 return PLDM_SUCCESS;
579}
580
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930581LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930582int encode_set_bios_table_req(uint8_t instance_id, uint32_t transfer_handle,
583 uint8_t transfer_flag, uint8_t table_type,
584 const uint8_t *table_data, size_t table_length,
585 struct pldm_msg *msg, size_t payload_length)
586{
587 if (msg == NULL || table_data == NULL) {
588 return PLDM_ERROR_INVALID_DATA;
589 }
590
591 if (PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES + table_length !=
592 payload_length) {
593 return PLDM_ERROR_INVALID_LENGTH;
594 }
595
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930596 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930597 header.instance = instance_id;
598 header.msg_type = PLDM_REQUEST;
599 header.pldm_type = PLDM_BIOS;
600 header.command = PLDM_SET_BIOS_TABLE;
601
602 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
603 if (rc != PLDM_SUCCESS) {
604 return rc;
605 }
606
607 struct pldm_set_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930608 (struct pldm_set_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930609 request->transfer_handle = htole32(transfer_handle);
610 request->transfer_flag = transfer_flag;
611 request->table_type = table_type;
612 memcpy(request->table_data, table_data, table_length);
613
614 return PLDM_SUCCESS;
615}
616
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930617LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930618int decode_set_bios_table_resp(const struct pldm_msg *msg,
619 size_t payload_length, uint8_t *completion_code,
620 uint32_t *next_transfer_handle)
621{
622 if (msg == NULL || completion_code == NULL ||
623 next_transfer_handle == NULL) {
624 return PLDM_ERROR_INVALID_DATA;
625 }
626
627 *completion_code = msg->payload[0];
628 if (PLDM_SUCCESS != *completion_code) {
629 return PLDM_SUCCESS;
630 }
631
632 if (payload_length != PLDM_SET_BIOS_TABLE_RESP_BYTES) {
633 return PLDM_ERROR_INVALID_LENGTH;
634 }
635
636 struct pldm_set_bios_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930637 (struct pldm_set_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930638
639 *next_transfer_handle = le32toh(response->next_transfer_handle);
640
641 return PLDM_SUCCESS;
642}
643
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930644LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930645int encode_set_bios_table_resp(uint8_t instance_id, uint8_t completion_code,
646 uint32_t next_transfer_handle,
647 struct pldm_msg *msg)
648{
649 if (msg == NULL) {
650 return PLDM_ERROR_INVALID_DATA;
651 }
652
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930653 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930654 header.instance = instance_id;
655 header.msg_type = PLDM_RESPONSE;
656 header.pldm_type = PLDM_BIOS;
657 header.command = PLDM_SET_BIOS_TABLE;
658
659 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
660 if (rc != PLDM_SUCCESS) {
661 return rc;
662 }
663
664 struct pldm_set_bios_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930665 (struct pldm_set_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930666 response->completion_code = completion_code;
667 response->next_transfer_handle = htole32(next_transfer_handle);
668
669 return PLDM_SUCCESS;
670}
671
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930672LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930673int decode_set_bios_table_req(const struct pldm_msg *msg, size_t payload_length,
674 uint32_t *transfer_handle, uint8_t *transfer_flag,
675 uint8_t *table_type, struct variable_field *table)
676{
677 if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL ||
678 table_type == NULL || table == NULL) {
679 return PLDM_ERROR_INVALID_DATA;
680 }
681
682 if (payload_length < PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES) {
683 return PLDM_ERROR_INVALID_LENGTH;
684 }
685
686 struct pldm_set_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930687 (struct pldm_set_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930688 *transfer_handle = le32toh(request->transfer_handle);
689 *transfer_flag = request->transfer_flag;
690 *table_type = request->table_type;
691 table->length = payload_length - PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES;
692 table->ptr = request->table_data;
693
694 return PLDM_SUCCESS;
695}