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 | 57d9a2e | 2024-10-03 15:03:25 +0930 | [diff] [blame^] | 2 | #include <libpldm/base.h> |
Andrew Jeffery | b0c1d20 | 2023-11-07 22:08:44 +1030 | [diff] [blame] | 3 | #include <libpldm/platform.h> |
Pavithra Barithaya | a7989cd | 2023-10-30 08:52:28 -0500 | [diff] [blame] | 4 | #include <libpldm/oem/ibm/platform.h> |
Andrew Jeffery | b0c1d20 | 2023-11-07 22:08:44 +1030 | [diff] [blame] | 5 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 6 | #include <string.h> |
| 7 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 8 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 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 | |
Andrew Jeffery | 57d9a2e | 2024-10-03 15:03:25 +0930 | [diff] [blame^] | 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)) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 40 | return PLDM_ERROR_INVALID_LENGTH; |
| 41 | } |
| 42 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 43 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 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 = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 54 | (struct pldm_bios_attribute_update_event_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 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 | } |