Patrick Williams | 691668f | 2023-11-01 08:19:10 -0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ |
Andrew Jeffery | b0c1d20 | 2023-11-07 22:08:44 +1030 | [diff] [blame^] | 2 | #include <libpldm/platform.h> |
| 3 | #include <libpldm/oem/ibm/libpldm/platform_oem_ibm.h> |
| 4 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 5 | #include <string.h> |
| 6 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 7 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 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 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 33 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 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 = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 44 | (struct pldm_bios_attribute_update_event_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 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 | } |