blob: b02bf4d29e9a499286f13b03b8f0d8a21027c914 [file] [log] [blame]
Patrick Williams691668f2023-11-01 08:19:10 -05001/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
Andrew Jeffery57d9a2e2024-10-03 15:03:25 +09302#include <libpldm/base.h>
Andrew Jefferyb0c1d202023-11-07 22:08:44 +10303#include <libpldm/platform.h>
Pavithra Barithayaa7989cd2023-10-30 08:52:28 -05004#include <libpldm/oem/ibm/platform.h>
Andrew Jefferyb0c1d202023-11-07 22:08:44 +10305
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_bios_attribute_update_event_req(uint8_t instance_id,
10 uint8_t format_version, uint8_t tid,
11 uint8_t num_handles,
12 const uint8_t *list_of_handles,
13 size_t payload_length,
14 struct pldm_msg *msg)
15{
16 if (format_version != 1) {
17 return PLDM_ERROR_INVALID_DATA;
18 }
19
20 if (msg == NULL || list_of_handles == NULL) {
21 return PLDM_ERROR_INVALID_DATA;
22 }
23
24 if (num_handles == 0) {
25 return PLDM_ERROR_INVALID_DATA;
26 }
27
Andrew Jeffery57d9a2e2024-10-03 15:03:25 +093028 if (SIZE_MAX / num_handles < sizeof(uint16_t)) {
29 return PLDM_ERROR_INVALID_LENGTH;
30 }
31
32 if (payload_length <
33 PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + sizeof(num_handles)) {
34 return PLDM_ERROR_INVALID_LENGTH;
35 }
36
37 if (payload_length - (PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES +
38 sizeof(num_handles)) <
39 num_handles * sizeof(uint16_t)) {
Andrew Jeffery9c766792022-08-10 23:12:49 +093040 return PLDM_ERROR_INVALID_LENGTH;
41 }
42
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093043 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093044 header.msg_type = PLDM_REQUEST;
45 header.instance = instance_id;
46 header.pldm_type = PLDM_PLATFORM;
47 header.command = PLDM_PLATFORM_EVENT_MESSAGE;
48 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
49 if (rc != PLDM_SUCCESS) {
50 return rc;
51 }
52
53 struct pldm_bios_attribute_update_event_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093054 (struct pldm_bios_attribute_update_event_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093055 request->format_version = format_version;
56 request->tid = tid;
57 request->event_class = PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE;
58 request->num_handles = num_handles;
59 memcpy(request->bios_attribute_handles, list_of_handles,
60 num_handles * sizeof(uint16_t));
61
62 return PLDM_SUCCESS;
63}