1 /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ 2 #include <libpldm/base.h> 3 #include <libpldm/platform.h> 4 #include <libpldm/oem/ibm/platform.h> 5 6 #include <string.h> 7 8 LIBPLDM_ABI_STABLE 9 int 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 28 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)) { 40 return PLDM_ERROR_INVALID_LENGTH; 41 } 42 43 struct pldm_header_info header = { 0 }; 44 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 = 54 (struct pldm_bios_attribute_update_event_req *)msg->payload; 55 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 } 64