blob: 00abf7f10ca9f9f0b5cfa47132fddaa965afb362 [file] [log] [blame]
Patrick Williams691668f2023-11-01 08:19:10 -05001/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
Andrew Jefferyb0c1d202023-11-07 22:08:44 +10302#include <libpldm/base.h>
3#include <libpldm/bios.h>
4#include <libpldm/utils.h>
5
Andrew Jeffery9c766792022-08-10 23:12:49 +09306#include <endian.h>
Andrew Jeffery9c766792022-08-10 23:12:49 +09307#include <string.h>
8
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09309LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093010int encode_get_date_time_req(uint8_t instance_id, struct pldm_msg *msg)
11{
12 if (msg == NULL) {
13 return PLDM_ERROR_INVALID_DATA;
14 }
15
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093016 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093017 header.msg_type = PLDM_REQUEST;
18 header.instance = instance_id;
19 header.pldm_type = PLDM_BIOS;
20 header.command = PLDM_GET_DATE_TIME;
21 return pack_pldm_header(&header, &(msg->hdr));
22}
23
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093024LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093025int encode_get_date_time_resp(uint8_t instance_id, uint8_t completion_code,
26 uint8_t seconds, uint8_t minutes, uint8_t hours,
27 uint8_t day, uint8_t month, uint16_t year,
28 struct pldm_msg *msg)
29{
30 if (msg == NULL) {
31 return PLDM_ERROR_INVALID_DATA;
32 }
33
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093034 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093035 header.msg_type = PLDM_RESPONSE;
36 header.instance = instance_id;
37 header.pldm_type = PLDM_BIOS;
38 header.command = PLDM_GET_DATE_TIME;
39
40 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
41 if (rc != PLDM_SUCCESS) {
42 return rc;
43 }
44
45 struct pldm_get_date_time_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093046 (struct pldm_get_date_time_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093047 response->completion_code = completion_code;
48 if (response->completion_code == PLDM_SUCCESS) {
49 response->completion_code = completion_code;
50 response->seconds = seconds;
51 response->minutes = minutes;
52 response->hours = hours;
53 response->day = day;
54 response->month = month;
55 response->year = htole16(year);
56 }
57 return PLDM_SUCCESS;
58}
59
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093060LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093061int decode_get_date_time_resp(const struct pldm_msg *msg, size_t payload_length,
62 uint8_t *completion_code, uint8_t *seconds,
63 uint8_t *minutes, uint8_t *hours, uint8_t *day,
64 uint8_t *month, uint16_t *year)
65{
66 if (msg == NULL || seconds == NULL || minutes == NULL ||
67 hours == NULL || day == NULL || month == NULL || year == NULL ||
68 completion_code == NULL) {
69 return PLDM_ERROR_INVALID_DATA;
70 }
71
72 *completion_code = msg->payload[0];
73 if (PLDM_SUCCESS != *completion_code) {
74 return PLDM_SUCCESS;
75 }
76
77 if (payload_length != PLDM_GET_DATE_TIME_RESP_BYTES) {
78 return PLDM_ERROR_INVALID_LENGTH;
79 }
80
81 struct pldm_get_date_time_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093082 (struct pldm_get_date_time_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093083
84 *seconds = response->seconds;
85 *minutes = response->minutes;
86 *hours = response->hours;
87 *day = response->day;
88 *month = response->month;
89 *year = le16toh(response->year);
90
91 return PLDM_SUCCESS;
92}
93
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093094LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093095int encode_set_date_time_req(uint8_t instance_id, uint8_t seconds,
96 uint8_t minutes, uint8_t hours, uint8_t day,
97 uint8_t month, uint16_t year, struct pldm_msg *msg,
98 size_t payload_length)
99{
100 if (msg == NULL) {
101 return PLDM_ERROR_INVALID_DATA;
102 }
103 if (payload_length != sizeof(struct pldm_set_date_time_req)) {
104 return PLDM_ERROR_INVALID_LENGTH;
105 }
106
107 if (!is_time_legal(seconds, minutes, hours, day, month, year)) {
108 return PLDM_ERROR_INVALID_DATA;
109 }
110
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930111 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930112 header.instance = instance_id;
113 header.msg_type = PLDM_REQUEST;
114 header.pldm_type = PLDM_BIOS;
115 header.command = PLDM_SET_DATE_TIME;
116
117 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
118 if (rc != PLDM_SUCCESS) {
119 return rc;
120 }
121
122 struct pldm_set_date_time_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930123 (struct pldm_set_date_time_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930124 request->seconds = dec2bcd8(seconds);
125 request->minutes = dec2bcd8(minutes);
126 request->hours = dec2bcd8(hours);
127 request->day = dec2bcd8(day);
128 request->month = dec2bcd8(month);
129 request->year = htole16(dec2bcd16(year));
130
131 return PLDM_SUCCESS;
132}
133
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930134LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930135int decode_set_date_time_req(const struct pldm_msg *msg, size_t payload_length,
136 uint8_t *seconds, uint8_t *minutes, uint8_t *hours,
137 uint8_t *day, uint8_t *month, uint16_t *year)
138{
139 if (msg == NULL || seconds == NULL || minutes == NULL ||
140 hours == NULL || day == NULL || month == NULL || year == NULL) {
141 return PLDM_ERROR_INVALID_DATA;
142 }
143 if (payload_length != sizeof(struct pldm_set_date_time_req)) {
144 return PLDM_ERROR_INVALID_LENGTH;
145 }
146
147 const struct pldm_set_date_time_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930148 (struct pldm_set_date_time_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930149
150 *seconds = bcd2dec8(request->seconds);
151 *minutes = bcd2dec8(request->minutes);
152 *hours = bcd2dec8(request->hours);
153 *day = bcd2dec8(request->day);
154 *month = bcd2dec8(request->month);
155 *year = bcd2dec16(le16toh(request->year));
156
157 if (!is_time_legal(*seconds, *minutes, *hours, *day, *month, *year)) {
158 return PLDM_ERROR_INVALID_DATA;
159 }
160
161 return PLDM_SUCCESS;
162}
163
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930164LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930165int encode_set_date_time_resp(uint8_t instance_id, uint8_t completion_code,
166 struct pldm_msg *msg, size_t payload_length)
167{
168 if (msg == NULL) {
169 return PLDM_ERROR_INVALID_DATA;
170 }
171 if (payload_length != sizeof(struct pldm_only_cc_resp)) {
172 return PLDM_ERROR_INVALID_LENGTH;
173 }
174
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930175 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930176 header.instance = instance_id;
177 header.msg_type = PLDM_RESPONSE;
178 header.pldm_type = PLDM_BIOS;
179 header.command = PLDM_SET_DATE_TIME;
180
181 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
182 if (rc != PLDM_SUCCESS) {
183 return rc;
184 }
185
186 struct pldm_only_cc_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930187 (struct pldm_only_cc_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930188 response->completion_code = completion_code;
189
190 return PLDM_SUCCESS;
191}
192
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930193LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930194int decode_set_date_time_resp(const struct pldm_msg *msg, size_t payload_length,
195 uint8_t *completion_code)
196{
197 if (msg == NULL || completion_code == NULL) {
198 return PLDM_ERROR_INVALID_DATA;
199 }
200
201 *completion_code = msg->payload[0];
202 if (PLDM_SUCCESS != *completion_code) {
203 return PLDM_SUCCESS;
204 }
205
206 if (payload_length != sizeof(struct pldm_only_cc_resp)) {
207 return PLDM_ERROR_INVALID_LENGTH;
208 }
209
210 return PLDM_SUCCESS;
211}
212
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930213LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930214int encode_get_bios_table_resp(uint8_t instance_id, uint8_t completion_code,
215 uint32_t next_transfer_handle,
216 uint8_t transfer_flag, uint8_t *table_data,
217 size_t payload_length, struct pldm_msg *msg)
218{
219 if (msg == NULL) {
220 return PLDM_ERROR_INVALID_DATA;
221 }
222
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930223 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930224 header.msg_type = PLDM_RESPONSE;
225 header.instance = instance_id;
226 header.pldm_type = PLDM_BIOS;
227 header.command = PLDM_GET_BIOS_TABLE;
228
229 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
230 if (rc != PLDM_SUCCESS) {
231 return rc;
232 }
233
234 struct pldm_get_bios_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930235 (struct pldm_get_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930236 response->completion_code = completion_code;
237 if (response->completion_code == PLDM_SUCCESS) {
Andrew Jeffery9c766792022-08-10 23:12:49 +0930238 response->next_transfer_handle = htole32(next_transfer_handle);
239 response->transfer_flag = transfer_flag;
240 if (table_data != NULL &&
241 payload_length > (sizeof(struct pldm_msg_hdr) +
242 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES)) {
243 memcpy(response->table_data, table_data,
244 payload_length -
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930245 (sizeof(struct pldm_msg_hdr) +
246 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES));
Andrew Jeffery9c766792022-08-10 23:12:49 +0930247 }
248 }
249 return PLDM_SUCCESS;
250}
251
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930252LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930253int encode_get_bios_table_req(uint8_t instance_id, uint32_t transfer_handle,
254 uint8_t transfer_op_flag, uint8_t table_type,
255 struct pldm_msg *msg)
256{
257 if (msg == NULL) {
258 return PLDM_ERROR_INVALID_DATA;
259 }
260
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930261 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930262 header.msg_type = PLDM_REQUEST;
263 header.instance = instance_id;
264 header.pldm_type = PLDM_BIOS;
265 header.command = PLDM_GET_BIOS_TABLE;
266
267 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
268 if (rc != PLDM_SUCCESS) {
269 return rc;
270 }
271
272 struct pldm_get_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930273 (struct pldm_get_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930274
275 request->transfer_handle = htole32(transfer_handle);
276 request->transfer_op_flag = transfer_op_flag;
277 request->table_type = table_type;
278 return PLDM_SUCCESS;
279}
280
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930281LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930282int decode_get_bios_table_req(const struct pldm_msg *msg, size_t payload_length,
283 uint32_t *transfer_handle,
284 uint8_t *transfer_op_flag, uint8_t *table_type)
285{
286 if (msg == NULL || transfer_op_flag == NULL || table_type == NULL ||
287 transfer_handle == NULL) {
288 return PLDM_ERROR_INVALID_DATA;
289 }
290
291 if (payload_length != PLDM_GET_BIOS_TABLE_REQ_BYTES) {
292 return PLDM_ERROR_INVALID_LENGTH;
293 }
294
295 struct pldm_get_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930296 (struct pldm_get_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930297 *transfer_handle = le32toh(request->transfer_handle);
298 *transfer_op_flag = request->transfer_op_flag;
299 *table_type = request->table_type;
300
301 return PLDM_SUCCESS;
302}
303
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930304LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930305int decode_get_bios_table_resp(const struct pldm_msg *msg,
306 size_t payload_length, uint8_t *completion_code,
307 uint32_t *next_transfer_handle,
308 uint8_t *transfer_flag,
309 size_t *bios_table_offset)
310
311{
312 if (msg == NULL || transfer_flag == NULL ||
313 next_transfer_handle == NULL || completion_code == NULL) {
314 return PLDM_ERROR_INVALID_DATA;
315 }
316 if (payload_length <= PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES) {
317 return PLDM_ERROR_INVALID_LENGTH;
318 }
319
320 struct pldm_get_bios_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930321 (struct pldm_get_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930322
323 *completion_code = response->completion_code;
324
325 if (PLDM_SUCCESS != *completion_code) {
326 return PLDM_SUCCESS;
327 }
328
329 *next_transfer_handle = le32toh(response->next_transfer_handle);
330 *transfer_flag = response->transfer_flag;
331
332 *bios_table_offset = sizeof(*completion_code) +
333 sizeof(*next_transfer_handle) +
334 sizeof(*transfer_flag);
335
336 return PLDM_SUCCESS;
337}
338
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930339LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930340int encode_get_bios_attribute_current_value_by_handle_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930341 uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_op_flag,
342 uint16_t attribute_handle, struct pldm_msg *msg)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930343{
344 if (msg == NULL) {
345 return PLDM_ERROR_INVALID_DATA;
346 }
347
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930348 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930349 header.msg_type = PLDM_REQUEST;
350 header.instance = instance_id;
351 header.pldm_type = PLDM_BIOS;
352 header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
353
354 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
355 if (rc != PLDM_SUCCESS) {
356 return rc;
357 }
358
359 struct pldm_get_bios_attribute_current_value_by_handle_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930360 (struct pldm_get_bios_attribute_current_value_by_handle_req *)
361 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930362
363 request->transfer_handle = htole32(transfer_handle);
364 request->transfer_op_flag = transfer_op_flag;
365 request->attribute_handle = htole16(attribute_handle);
366 return PLDM_SUCCESS;
367}
368
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930369LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930370int decode_get_bios_attribute_current_value_by_handle_resp(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930371 const struct pldm_msg *msg, size_t payload_length,
372 uint8_t *completion_code, uint32_t *next_transfer_handle,
373 uint8_t *transfer_flag, struct variable_field *attribute_data)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930374{
375 if (msg == NULL || transfer_flag == NULL ||
376 next_transfer_handle == NULL || completion_code == NULL) {
377 return PLDM_ERROR_INVALID_DATA;
378 }
379
380 struct pldm_get_bios_attribute_current_value_by_handle_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930381 (struct pldm_get_bios_attribute_current_value_by_handle_resp *)
382 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930383
384 *completion_code = response->completion_code;
385
386 if (PLDM_SUCCESS != *completion_code) {
387 return PLDM_SUCCESS;
388 }
389
390 if (payload_length <=
391 PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_MIN_RESP_BYTES) {
392 return PLDM_ERROR_INVALID_LENGTH;
393 }
394
395 *next_transfer_handle = le32toh(response->next_transfer_handle);
396 *transfer_flag = response->transfer_flag;
397
398 attribute_data->ptr = response->attribute_data;
399 attribute_data->length = payload_length - sizeof(*response) + 1;
400
401 return PLDM_SUCCESS;
402}
403
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930404LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930405int decode_get_bios_attribute_current_value_by_handle_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930406 const struct pldm_msg *msg, size_t payload_length,
407 uint32_t *transfer_handle, uint8_t *transfer_op_flag,
408 uint16_t *attribute_handle)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930409{
410 if (msg == NULL || transfer_handle == NULL ||
411 transfer_op_flag == NULL || attribute_handle == NULL) {
412 return PLDM_ERROR_INVALID_DATA;
413 }
414
415 if (payload_length != PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_REQ_BYTES) {
416 return PLDM_ERROR_INVALID_LENGTH;
417 }
418
419 struct pldm_get_bios_attribute_current_value_by_handle_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930420 (struct pldm_get_bios_attribute_current_value_by_handle_req *)
421 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930422 *transfer_handle = le32toh(request->transfer_handle);
423 *transfer_op_flag = request->transfer_op_flag;
424 *attribute_handle = le16toh(request->attribute_handle);
425
426 return PLDM_SUCCESS;
427}
428
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930429LIBPLDM_ABI_STABLE
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930430int encode_get_bios_current_value_by_handle_resp(uint8_t instance_id,
431 uint8_t completion_code,
432 uint32_t next_transfer_handle,
433 uint8_t transfer_flag,
434 const uint8_t *attribute_data,
435 size_t attribute_length,
436 struct pldm_msg *msg)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930437{
438 if (msg == NULL || attribute_data == NULL) {
439 return PLDM_ERROR_INVALID_DATA;
440 }
441
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930442 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930443 header.msg_type = PLDM_RESPONSE;
444 header.instance = instance_id;
445 header.pldm_type = PLDM_BIOS;
446 header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
447
448 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
449 if (rc != PLDM_SUCCESS) {
450 return rc;
451 }
452
453 struct pldm_get_bios_attribute_current_value_by_handle_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930454 (struct pldm_get_bios_attribute_current_value_by_handle_resp *)
455 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930456 response->completion_code = completion_code;
457 if (response->completion_code == PLDM_SUCCESS) {
Andrew Jeffery9c766792022-08-10 23:12:49 +0930458 response->next_transfer_handle = htole32(next_transfer_handle);
459 response->transfer_flag = transfer_flag;
460 if (attribute_data != NULL) {
461 memcpy(response->attribute_data, attribute_data,
462 attribute_length);
463 }
464 }
465 return PLDM_SUCCESS;
466}
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930467
468LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930469int encode_set_bios_attribute_current_value_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930470 uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_flag,
471 const uint8_t *attribute_data, size_t attribute_length,
472 struct pldm_msg *msg, size_t payload_length)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930473{
474 if (msg == NULL || attribute_data == NULL) {
475 return PLDM_ERROR_INVALID_DATA;
476 }
477 if (PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + attribute_length !=
Andrew Jeffery9145a412023-04-05 20:24:50 +0930478 payload_length) {
Andrew Jeffery9c766792022-08-10 23:12:49 +0930479 return PLDM_ERROR_INVALID_LENGTH;
480 }
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930481 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930482 header.instance = instance_id;
483 header.msg_type = PLDM_REQUEST;
484 header.pldm_type = PLDM_BIOS;
485 header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
486
487 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
488 if (rc != PLDM_SUCCESS) {
489 return rc;
490 }
491
492 struct pldm_set_bios_attribute_current_value_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930493 (struct pldm_set_bios_attribute_current_value_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930494 request->transfer_handle = htole32(transfer_handle);
495 request->transfer_flag = transfer_flag;
496 memcpy(request->attribute_data, attribute_data, attribute_length);
497
498 return PLDM_SUCCESS;
499}
500
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930501LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930502int decode_set_bios_attribute_current_value_resp(const struct pldm_msg *msg,
503 size_t payload_length,
504 uint8_t *completion_code,
505 uint32_t *next_transfer_handle)
506{
507 if (msg == NULL || completion_code == NULL ||
508 next_transfer_handle == NULL) {
509 return PLDM_ERROR_INVALID_DATA;
510 }
511
512 *completion_code = msg->payload[0];
513 if (PLDM_SUCCESS != *completion_code) {
514 return PLDM_SUCCESS;
515 }
516
517 if (payload_length != PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES) {
518 return PLDM_ERROR_INVALID_LENGTH;
519 }
520
521 struct pldm_set_bios_attribute_current_value_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930522 (struct pldm_set_bios_attribute_current_value_resp *)
523 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930524
525 *next_transfer_handle = le32toh(response->next_transfer_handle);
526
527 return PLDM_SUCCESS;
528}
529
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930530LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930531int decode_set_bios_attribute_current_value_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930532 const struct pldm_msg *msg, size_t payload_length,
533 uint32_t *transfer_handle, uint8_t *transfer_flag,
534 struct variable_field *attribute)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930535{
536 if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL ||
537 attribute == NULL) {
538 return PLDM_ERROR_INVALID_DATA;
539 }
540 if (payload_length < PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES) {
541 return PLDM_ERROR_INVALID_LENGTH;
542 }
543
544 struct pldm_set_bios_attribute_current_value_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930545 (struct pldm_set_bios_attribute_current_value_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930546 *transfer_handle = le32toh(request->transfer_handle);
547 *transfer_flag = request->transfer_flag;
548 attribute->length =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930549 payload_length - PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930550 attribute->ptr = request->attribute_data;
551 return PLDM_SUCCESS;
552}
553
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930554LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930555int encode_set_bios_attribute_current_value_resp(uint8_t instance_id,
556 uint8_t completion_code,
557 uint32_t next_transfer_handle,
558 struct pldm_msg *msg)
559{
560 if (msg == NULL) {
561 return PLDM_ERROR_INVALID_DATA;
562 }
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930563 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930564 header.instance = instance_id;
565 header.msg_type = PLDM_RESPONSE;
566 header.pldm_type = PLDM_BIOS;
567 header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
568
569 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
570 if (rc != PLDM_SUCCESS) {
571 return rc;
572 }
573
574 struct pldm_set_bios_attribute_current_value_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930575 (struct pldm_set_bios_attribute_current_value_resp *)
576 msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930577 response->completion_code = completion_code;
578 response->next_transfer_handle = htole32(next_transfer_handle);
579
580 return PLDM_SUCCESS;
581}
582
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930583LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930584int encode_set_bios_table_req(uint8_t instance_id, uint32_t transfer_handle,
585 uint8_t transfer_flag, uint8_t table_type,
586 const uint8_t *table_data, size_t table_length,
587 struct pldm_msg *msg, size_t payload_length)
588{
589 if (msg == NULL || table_data == NULL) {
590 return PLDM_ERROR_INVALID_DATA;
591 }
592
593 if (PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES + table_length !=
594 payload_length) {
595 return PLDM_ERROR_INVALID_LENGTH;
596 }
597
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930598 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930599 header.instance = instance_id;
600 header.msg_type = PLDM_REQUEST;
601 header.pldm_type = PLDM_BIOS;
602 header.command = PLDM_SET_BIOS_TABLE;
603
604 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
605 if (rc != PLDM_SUCCESS) {
606 return rc;
607 }
608
609 struct pldm_set_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930610 (struct pldm_set_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930611 request->transfer_handle = htole32(transfer_handle);
612 request->transfer_flag = transfer_flag;
613 request->table_type = table_type;
614 memcpy(request->table_data, table_data, table_length);
615
616 return PLDM_SUCCESS;
617}
618
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930619LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930620int decode_set_bios_table_resp(const struct pldm_msg *msg,
621 size_t payload_length, uint8_t *completion_code,
622 uint32_t *next_transfer_handle)
623{
624 if (msg == NULL || completion_code == NULL ||
625 next_transfer_handle == NULL) {
626 return PLDM_ERROR_INVALID_DATA;
627 }
628
629 *completion_code = msg->payload[0];
630 if (PLDM_SUCCESS != *completion_code) {
631 return PLDM_SUCCESS;
632 }
633
634 if (payload_length != PLDM_SET_BIOS_TABLE_RESP_BYTES) {
635 return PLDM_ERROR_INVALID_LENGTH;
636 }
637
638 struct pldm_set_bios_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930639 (struct pldm_set_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930640
641 *next_transfer_handle = le32toh(response->next_transfer_handle);
642
643 return PLDM_SUCCESS;
644}
645
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930646LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930647int encode_set_bios_table_resp(uint8_t instance_id, uint8_t completion_code,
648 uint32_t next_transfer_handle,
649 struct pldm_msg *msg)
650{
651 if (msg == NULL) {
652 return PLDM_ERROR_INVALID_DATA;
653 }
654
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930655 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930656 header.instance = instance_id;
657 header.msg_type = PLDM_RESPONSE;
658 header.pldm_type = PLDM_BIOS;
659 header.command = PLDM_SET_BIOS_TABLE;
660
661 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
662 if (rc != PLDM_SUCCESS) {
663 return rc;
664 }
665
666 struct pldm_set_bios_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930667 (struct pldm_set_bios_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930668 response->completion_code = completion_code;
669 response->next_transfer_handle = htole32(next_transfer_handle);
670
671 return PLDM_SUCCESS;
672}
673
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930674LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930675int decode_set_bios_table_req(const struct pldm_msg *msg, size_t payload_length,
676 uint32_t *transfer_handle, uint8_t *transfer_flag,
677 uint8_t *table_type, struct variable_field *table)
678{
679 if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL ||
680 table_type == NULL || table == NULL) {
681 return PLDM_ERROR_INVALID_DATA;
682 }
683
684 if (payload_length < PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES) {
685 return PLDM_ERROR_INVALID_LENGTH;
686 }
687
688 struct pldm_set_bios_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930689 (struct pldm_set_bios_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930690 *transfer_handle = le32toh(request->transfer_handle);
691 *transfer_flag = request->transfer_flag;
692 *table_type = request->table_type;
693 table->length = payload_length - PLDM_SET_BIOS_TABLE_MIN_REQ_BYTES;
694 table->ptr = request->table_data;
695
696 return PLDM_SUCCESS;
697}