1 /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
2 #include <libpldm/platform.h>
3 #include <libpldm/oem/ibm/platform.h>
4
5 #include <string.h>
6
7 LIBPLDM_ABI_STABLE
encode_bios_attribute_update_event_req(uint8_t instance_id,uint8_t format_version,uint8_t tid,uint8_t num_handles,const uint8_t * list_of_handles,size_t payload_length,struct pldm_msg * msg)8 int encode_bios_attribute_update_event_req(uint8_t instance_id,
9 uint8_t format_version, uint8_t tid,
10 uint8_t num_handles,
11 const uint8_t *list_of_handles,
12 size_t payload_length,
13 struct pldm_msg *msg)
14 {
15 if (format_version != 1) {
16 return PLDM_ERROR_INVALID_DATA;
17 }
18
19 if (msg == NULL || list_of_handles == NULL) {
20 return PLDM_ERROR_INVALID_DATA;
21 }
22
23 if (num_handles == 0) {
24 return PLDM_ERROR_INVALID_DATA;
25 }
26
27 if (payload_length !=
28 (PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + sizeof(num_handles) +
29 (num_handles * sizeof(uint16_t)))) {
30 return PLDM_ERROR_INVALID_LENGTH;
31 }
32
33 struct pldm_header_info header = { 0 };
34 header.msg_type = PLDM_REQUEST;
35 header.instance = instance_id;
36 header.pldm_type = PLDM_PLATFORM;
37 header.command = PLDM_PLATFORM_EVENT_MESSAGE;
38 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
39 if (rc != PLDM_SUCCESS) {
40 return rc;
41 }
42
43 struct pldm_bios_attribute_update_event_req *request =
44 (struct pldm_bios_attribute_update_event_req *)msg->payload;
45 request->format_version = format_version;
46 request->tid = tid;
47 request->event_class = PLDM_EVENT_TYPE_OEM_EVENT_BIOS_ATTRIBUTE_UPDATE;
48 request->num_handles = num_handles;
49 memcpy(request->bios_attribute_handles, list_of_handles,
50 num_handles * sizeof(uint16_t));
51
52 return PLDM_SUCCESS;
53 }
54