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