/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
#include "api.h"
#include "compiler.h"
#include "dsp/base.h"
#include "msgbuf.h"
#include "msgbuf/platform.h"

#include <libpldm/base.h>
#include <libpldm/platform.h>
#include <libpldm/pldm_types.h>

#include <endian.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <uchar.h>

LIBPLDM_ABI_STABLE
int encode_state_effecter_pdr(
	struct pldm_state_effecter_pdr *const effecter,
	const size_t allocation_size,
	const struct state_effecter_possible_states *const possible_states,
	const size_t possible_states_size, size_t *const actual_size)
{
	size_t calculated_possible_states_size = 0;

	if (!effecter || !possible_states || !actual_size) {
		return PLDM_ERROR;
	}

	if (SIZE_MAX - (sizeof(*effecter) - sizeof(effecter->possible_states)) <
	    possible_states_size) {
		return PLDM_ERROR;
	}

	if (allocation_size <
	    (sizeof(*effecter) - sizeof(effecter->possible_states)) +
		    possible_states_size) {
		return PLDM_ERROR_INVALID_LENGTH;
	}

	// Encode possible states

	{
		char *states_ptr = (char *)possible_states;
		char *const begin_states_ptr = states_ptr;

		for (int i = 0; i < effecter->composite_effecter_count; ++i) {
			struct state_effecter_possible_states *states =
				(struct state_effecter_possible_states *)
					states_ptr;

			HTOLE16(states->state_set_id);

			states_ptr +=
				(sizeof(*states) - sizeof(states->states) +
				 states->possible_states_size);
		}

		calculated_possible_states_size = states_ptr - begin_states_ptr;
	}

	// Check lengths

	if (possible_states_size != calculated_possible_states_size) {
		*actual_size = 0;
		return PLDM_ERROR;
	}

	*actual_size =
		(sizeof(struct pldm_state_effecter_pdr) + possible_states_size -
		 sizeof(effecter->possible_states));

	// Encode rest of PDR

	effecter->hdr.version = 1;
	effecter->hdr.type = PLDM_STATE_EFFECTER_PDR;
	effecter->hdr.length = *actual_size - sizeof(struct pldm_pdr_hdr);

	memcpy(effecter->possible_states, possible_states,
	       possible_states_size);

	// Convert effecter PDR body
	HTOLE16(effecter->terminus_handle);
	HTOLE16(effecter->effecter_id);
	HTOLE16(effecter->entity_type);
	HTOLE16(effecter->entity_instance);
	HTOLE16(effecter->container_id);
	HTOLE16(effecter->effecter_semantic_id);

	// Convert header
	HTOLE32(effecter->hdr.record_handle);
	HTOLE16(effecter->hdr.record_change_num);
	HTOLE16(effecter->hdr.length);

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_state_sensor_pdr(
	struct pldm_state_sensor_pdr *const sensor,
	const size_t allocation_size,
	const struct state_sensor_possible_states *const possible_states,
	const size_t possible_states_size, size_t *const actual_size)
{
	size_t calculated_possible_states_size = 0;

	if (!sensor || !possible_states || !actual_size) {
		return PLDM_ERROR;
	}

	if (SIZE_MAX - (sizeof(*sensor) - sizeof(sensor->possible_states)) <
	    possible_states_size) {
		return PLDM_ERROR;
	}

	if (allocation_size <
	    (sizeof(*sensor) - sizeof(sensor->possible_states) +
	     possible_states_size)) {
		return PLDM_ERROR_INVALID_LENGTH;
	}

	{
		// Encode possible states
		char *states_ptr = (char *)possible_states;
		char *const begin_states_ptr = states_ptr;

		for (int i = 0; i < sensor->composite_sensor_count; ++i) {
			struct state_sensor_possible_states *states =
				(struct state_sensor_possible_states *)
					states_ptr;

			HTOLE16(states->state_set_id);

			states_ptr +=
				(sizeof(*states) - sizeof(states->states) +
				 states->possible_states_size);
		}

		calculated_possible_states_size = states_ptr - begin_states_ptr;
	}

	// Check lengths

	if (possible_states_size != calculated_possible_states_size) {
		*actual_size = 0;
		return PLDM_ERROR;
	}

	*actual_size = (sizeof(struct pldm_state_sensor_pdr) +
			possible_states_size - sizeof(sensor->possible_states));

	// Encode rest of PDR

	sensor->hdr.version = 1;
	sensor->hdr.type = PLDM_STATE_SENSOR_PDR;
	sensor->hdr.length = *actual_size - sizeof(struct pldm_pdr_hdr);

	memcpy(sensor->possible_states, possible_states, possible_states_size);

	// Convert sensor PDR body
	HTOLE16(sensor->terminus_handle);
	HTOLE16(sensor->sensor_id);
	HTOLE16(sensor->entity_type);
	HTOLE16(sensor->entity_instance);
	HTOLE16(sensor->container_id);

	// Convert header
	HTOLE32(sensor->hdr.record_handle);
	HTOLE16(sensor->hdr.record_change_num);
	HTOLE16(sensor->hdr.length);

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_set_state_effecter_states_resp(uint8_t instance_id,
					  uint8_t completion_code,
					  struct pldm_msg *msg)
{
	if (msg == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_RESPONSE;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_SET_STATE_EFFECTER_STATES;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	msg->payload[0] = completion_code;

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_set_state_effecter_states_req(uint8_t instance_id,
					 uint16_t effecter_id,
					 uint8_t comp_effecter_count,
					 set_effecter_state_field *field,
					 struct pldm_msg *msg)
{
	if (msg == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (comp_effecter_count < 0x1 || comp_effecter_count > 0x8 ||
	    field == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_REQUEST;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_SET_STATE_EFFECTER_STATES;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_set_state_effecter_states_req *request =
		(struct pldm_set_state_effecter_states_req *)msg->payload;
	effecter_id = htole16(effecter_id);
	request->effecter_id = effecter_id;
	request->comp_effecter_count = comp_effecter_count;
	memcpy(request->field, field,
	       (sizeof(set_effecter_state_field) * comp_effecter_count));

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_set_state_effecter_states_resp(const struct pldm_msg *msg,
					  size_t payload_length,
					  uint8_t *completion_code)
{
	if (msg == NULL || completion_code == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	*completion_code = msg->payload[0];
	if (PLDM_SUCCESS != *completion_code) {
		return PLDM_SUCCESS;
	}

	if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_RESP_BYTES) {
		return PLDM_ERROR_INVALID_LENGTH;
	}

	return PLDM_SUCCESS;
}

#define PLDM_SET_STATE_EFFECTER_STATES_MIN_SIZE 3
LIBPLDM_ABI_STABLE
int decode_set_state_effecter_states_req(const struct pldm_msg *msg,
					 size_t payload_length,
					 uint16_t *effecter_id,
					 uint8_t *comp_effecter_count,
					 set_effecter_state_field *field)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;
	int i;

	if (msg == NULL || effecter_id == NULL || comp_effecter_count == NULL ||
	    field == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (payload_length > PLDM_SET_STATE_EFFECTER_STATES_REQ_BYTES) {
		return PLDM_ERROR_INVALID_LENGTH;
	}

	rc = pldm_msgbuf_init_errno(buf,
				    PLDM_SET_STATE_EFFECTER_STATES_MIN_SIZE,
				    msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_extract_p(buf, effecter_id);
	rc = pldm_msgbuf_extract_p(buf, comp_effecter_count);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (*comp_effecter_count > 8) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	for (i = 0; i < *comp_effecter_count; i++) {
		pldm_msgbuf_extract(buf, field[i].set_request);
		pldm_msgbuf_extract(buf, field[i].effecter_state);
	}

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_get_pdr_req(const struct pldm_msg *msg, size_t payload_length,
		       uint32_t *record_hndl, uint32_t *data_transfer_hndl,
		       uint8_t *transfer_op_flag, uint16_t *request_cnt,
		       uint16_t *record_chg_num)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || record_hndl == NULL || data_transfer_hndl == NULL ||
	    transfer_op_flag == NULL || request_cnt == NULL ||
	    record_chg_num == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (payload_length != PLDM_GET_PDR_REQ_BYTES) {
		return PLDM_ERROR_INVALID_LENGTH;
	}

	rc = pldm_msgbuf_init_errno(buf, PLDM_GET_PDR_REQ_BYTES, msg->payload,
				    payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_extract_p(buf, record_hndl);
	pldm_msgbuf_extract_p(buf, data_transfer_hndl);
	pldm_msgbuf_extract_p(buf, transfer_op_flag);
	pldm_msgbuf_extract_p(buf, request_cnt);
	pldm_msgbuf_extract_p(buf, record_chg_num);

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_DEPRECATED_UNSAFE
int encode_get_pdr_resp(uint8_t instance_id, uint8_t completion_code,
			uint32_t next_record_hndl,
			uint32_t next_data_transfer_hndl, uint8_t transfer_flag,
			uint16_t resp_cnt, const uint8_t *record_data,
			uint8_t transfer_crc, struct pldm_msg *msg)
{
	if (msg == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_RESPONSE;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_GET_PDR;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_get_pdr_resp *response =
		(struct pldm_get_pdr_resp *)msg->payload;
	response->completion_code = completion_code;

	if (response->completion_code == PLDM_SUCCESS) {
		response->next_record_handle = htole32(next_record_hndl);
		response->next_data_transfer_handle =
			htole32(next_data_transfer_hndl);
		response->transfer_flag = transfer_flag;
		response->response_count = htole16(resp_cnt);
		if (record_data != NULL && resp_cnt > 0) {
			memcpy(response->record_data, record_data, resp_cnt);
		}
		if (transfer_flag == PLDM_END) {
			uint8_t *dst = msg->payload;
			dst += (sizeof(struct pldm_get_pdr_resp) - 1) +
			       resp_cnt;
			*dst = transfer_crc;
		}
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_TESTING
int encode_get_pdr_repository_info_req(uint8_t instance_id,
				       struct pldm_msg *msg,
				       size_t payload_length LIBPLDM_CC_UNUSED)
{
	if (!msg) {
		return -EINVAL;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_REQUEST;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_GET_PDR_REPOSITORY_INFO;

	return pack_pldm_header_errno(&header, &(msg->hdr));
}

LIBPLDM_ABI_STABLE
int encode_get_pdr_repository_info_resp(
	uint8_t instance_id, uint8_t completion_code, uint8_t repository_state,
	const uint8_t *update_time, const uint8_t *oem_update_time,
	uint32_t record_count, uint32_t repository_size,
	uint32_t largest_record_size, uint8_t data_transfer_handle_timeout,
	struct pldm_msg *msg)
{
	if (msg == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_RESPONSE;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_GET_PDR_REPOSITORY_INFO;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_pdr_repository_info_resp *response =
		(struct pldm_pdr_repository_info_resp *)msg->payload;
	response->completion_code = completion_code;

	if (response->completion_code == PLDM_SUCCESS) {
		response->repository_state = repository_state;
		if (update_time != NULL) {
			memcpy(response->update_time, update_time,
			       PLDM_TIMESTAMP104_SIZE);
		}
		if (oem_update_time != NULL) {
			memcpy(response->oem_update_time, oem_update_time,
			       PLDM_TIMESTAMP104_SIZE);
		}
		response->record_count = htole32(record_count);
		response->repository_size = htole32(repository_size);
		response->largest_record_size = htole32(largest_record_size);
		response->data_transfer_handle_timeout =
			data_transfer_handle_timeout;
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_DEPRECATED
int decode_get_pdr_repository_info_resp(
	const struct pldm_msg *msg, size_t payload_length,
	uint8_t *completion_code, uint8_t *repository_state,
	uint8_t *update_time, uint8_t *oem_update_time, uint32_t *record_count,
	uint32_t *repository_size, uint32_t *largest_record_size,
	uint8_t *data_transfer_handle_timeout)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || completion_code == NULL ||
	    repository_state == NULL || update_time == NULL ||
	    oem_update_time == NULL || record_count == NULL ||
	    repository_size == NULL || largest_record_size == NULL ||
	    data_transfer_handle_timeout == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf,
				    PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	rc = pldm_msgbuf_extract_p(buf, completion_code);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}
	if (PLDM_SUCCESS != *completion_code) {
		return PLDM_SUCCESS;
	}

	rc = pldm_msgbuf_extract_p(buf, repository_state);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (*repository_state > PLDM_FAILED) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	/* NOTE: Memory safety */
	rc = pldm_msgbuf_extract_array(buf, PLDM_TIMESTAMP104_SIZE, update_time,
				       PLDM_TIMESTAMP104_SIZE);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	/* NOTE: Memory safety */
	rc = pldm_msgbuf_extract_array(buf, PLDM_TIMESTAMP104_SIZE,
				       oem_update_time, PLDM_TIMESTAMP104_SIZE);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	pldm_msgbuf_extract_p(buf, record_count);
	pldm_msgbuf_extract_p(buf, repository_size);
	pldm_msgbuf_extract_p(buf, largest_record_size);
	pldm_msgbuf_extract_p(buf, data_transfer_handle_timeout);

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_TESTING
int decode_get_pdr_repository_info_resp_safe(
	const struct pldm_msg *msg, size_t payload_length,
	struct pldm_pdr_repository_info_resp *resp)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || resp == NULL) {
		return -EINVAL;
	}

	rc = pldm_msg_has_error(msg, payload_length);
	if (rc) {
		resp->completion_code = rc;
		return 0;
	}

	rc = pldm_msgbuf_init_errno(buf,
				    PLDM_GET_PDR_REPOSITORY_INFO_RESP_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return rc;
	}

	rc = pldm_msgbuf_extract(buf, resp->completion_code);
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}

	pldm_msgbuf_extract(buf, resp->repository_state);

	rc = pldm_msgbuf_extract_array(buf, sizeof(resp->update_time),
				       resp->update_time,
				       sizeof(resp->update_time));
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}

	rc = pldm_msgbuf_extract_array(buf, sizeof(resp->oem_update_time),
				       resp->oem_update_time,
				       sizeof(resp->oem_update_time));
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}

	pldm_msgbuf_extract(buf, resp->record_count);
	pldm_msgbuf_extract(buf, resp->repository_size);
	pldm_msgbuf_extract(buf, resp->largest_record_size);
	pldm_msgbuf_extract(buf, resp->data_transfer_handle_timeout);

	return pldm_msgbuf_complete_consumed(buf);
}

LIBPLDM_ABI_STABLE
int encode_get_pdr_req(uint8_t instance_id, uint32_t record_hndl,
		       uint32_t data_transfer_hndl, uint8_t transfer_op_flag,
		       uint16_t request_cnt, uint16_t record_chg_num,
		       struct pldm_msg *msg, size_t payload_length)
{
	if (msg == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (payload_length != PLDM_GET_PDR_REQ_BYTES) {
		return PLDM_ERROR_INVALID_LENGTH;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_REQUEST;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_GET_PDR;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_get_pdr_req *request =
		(struct pldm_get_pdr_req *)msg->payload;
	request->record_handle = htole32(record_hndl);
	request->data_transfer_handle = htole32(data_transfer_hndl);
	request->transfer_op_flag = transfer_op_flag;
	request->request_count = htole16(request_cnt);
	request->record_change_number = htole16(record_chg_num);

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_DEPRECATED
int decode_get_pdr_resp(const struct pldm_msg *msg, size_t payload_length,
			uint8_t *completion_code, uint32_t *next_record_hndl,
			uint32_t *next_data_transfer_hndl,
			uint8_t *transfer_flag, uint16_t *resp_cnt,
			uint8_t *record_data, size_t record_data_length,
			uint8_t *transfer_crc)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || completion_code == NULL ||
	    next_record_hndl == NULL || next_data_transfer_hndl == NULL ||
	    transfer_flag == NULL || resp_cnt == NULL || transfer_crc == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf, PLDM_GET_PDR_MIN_RESP_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	rc = pldm_msgbuf_extract_p(buf, completion_code);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (PLDM_SUCCESS != *completion_code) {
		return pldm_msgbuf_complete(buf);
	}

	pldm_msgbuf_extract_p(buf, next_record_hndl);
	pldm_msgbuf_extract_p(buf, next_data_transfer_hndl);
	pldm_msgbuf_extract_p(buf, transfer_flag);
	rc = pldm_msgbuf_extract_p(buf, resp_cnt);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (*resp_cnt > 0 && record_data != NULL) {
		if (record_data_length < *resp_cnt) {
			return pldm_msgbuf_discard(buf,
						   PLDM_ERROR_INVALID_LENGTH);
		}
		/* NOTE: Memory safety */
		rc = pldm_msgbuf_extract_array(buf, *resp_cnt, record_data,
					       *resp_cnt);
		if (rc) {
			return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
		}
	}

	if (*transfer_flag == PLDM_END) {
		pldm_msgbuf_extract_p(buf, transfer_crc);
	}

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_TESTING
int decode_get_pdr_resp_safe(const struct pldm_msg *msg, size_t payload_length,
			     struct pldm_get_pdr_resp *resp, size_t resp_len,
			     uint8_t *transfer_crc)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || resp == NULL || transfer_crc == NULL) {
		return -EINVAL;
	}

	rc = pldm_msg_has_error(msg, payload_length);
	if (rc) {
		resp->completion_code = rc;
		return 0;
	}

	rc = pldm_msgbuf_init_errno(buf, PLDM_GET_PDR_MIN_RESP_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return rc;
	}

	pldm_msgbuf_extract(buf, resp->completion_code);
	pldm_msgbuf_extract(buf, resp->next_record_handle);
	pldm_msgbuf_extract(buf, resp->next_data_transfer_handle);

	rc = pldm_msgbuf_extract(buf, resp->transfer_flag);
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}

	rc = pldm_msgbuf_extract(buf, resp->response_count);
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}

	rc = pldm_msgbuf_extract_array(
		buf, resp->response_count, resp->record_data,
		resp_len - (sizeof(*resp) - sizeof(resp->record_data)));
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}

	if (resp->transfer_flag == PLDM_END) {
		pldm_msgbuf_extract_p(buf, transfer_crc);
	}

	return pldm_msgbuf_complete_consumed(buf);
}

LIBPLDM_ABI_STABLE
int decode_set_numeric_effecter_value_req(const struct pldm_msg *msg,
					  size_t payload_length,
					  uint16_t *effecter_id,
					  uint8_t *effecter_data_size,
					  uint8_t effecter_value[4])
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || effecter_id == NULL || effecter_data_size == NULL ||
	    effecter_value == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(
		buf, PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES,
		msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_extract_p(buf, effecter_id);
	rc = pldm_msgbuf_extract_p(buf, effecter_data_size);
	if (rc) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	if (*effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	pldm_msgbuf_extract_effecter_value(buf, *effecter_data_size,
					   effecter_value);

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_set_numeric_effecter_value_resp(uint8_t instance_id,
					   uint8_t completion_code,
					   struct pldm_msg *msg,
					   size_t payload_length)
{
	if (msg == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (payload_length != PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES) {
		return PLDM_ERROR_INVALID_LENGTH;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_RESPONSE;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_SET_NUMERIC_EFFECTER_VALUE;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	msg->payload[0] = completion_code;

	return rc;
}

LIBPLDM_ABI_STABLE
int encode_set_numeric_effecter_value_req(uint8_t instance_id,
					  uint16_t effecter_id,
					  uint8_t effecter_data_size,
					  const uint8_t *effecter_value,
					  struct pldm_msg *msg,
					  size_t payload_length)
{
	if (msg == NULL || effecter_value == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_REQUEST;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_SET_NUMERIC_EFFECTER_VALUE;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_set_numeric_effecter_value_req *request =
		(struct pldm_set_numeric_effecter_value_req *)msg->payload;
	if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 ||
	    effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) {
		if (payload_length !=
		    PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES) {
			return PLDM_ERROR_INVALID_LENGTH;
		}
		request->effecter_value[0] = *effecter_value;
	} else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT16 ||
		   effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT16) {
		if (payload_length !=
		    PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 1) {
			return PLDM_ERROR_INVALID_LENGTH;
		}

		uint16_t val = *(uint16_t *)(effecter_value);
		val = htole16(val);
		memcpy(request->effecter_value, &val, sizeof(uint16_t));

	} else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
		   effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) {
		if (payload_length !=
		    PLDM_SET_NUMERIC_EFFECTER_VALUE_MIN_REQ_BYTES + 3) {
			return PLDM_ERROR_INVALID_LENGTH;
		}

		uint32_t val = *(uint32_t *)(effecter_value);
		val = htole32(val);
		memcpy(request->effecter_value, &val, sizeof(uint32_t));
	}

	request->effecter_id = htole16(effecter_id);
	request->effecter_data_size = effecter_data_size;

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_set_numeric_effecter_value_resp(const struct pldm_msg *msg,
					   size_t payload_length,
					   uint8_t *completion_code)
{
	if (msg == NULL || completion_code == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (payload_length != PLDM_SET_NUMERIC_EFFECTER_VALUE_RESP_BYTES) {
		return PLDM_ERROR_INVALID_LENGTH;
	}

	*completion_code = msg->payload[0];

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_get_state_sensor_readings_resp(uint8_t instance_id,
					  uint8_t completion_code,
					  uint8_t comp_sensor_count,
					  get_sensor_state_field *field,
					  struct pldm_msg *msg)
{
	if (msg == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (comp_sensor_count < 0x1 || comp_sensor_count > 0x8) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_RESPONSE;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_GET_STATE_SENSOR_READINGS;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_get_state_sensor_readings_resp *response =
		(struct pldm_get_state_sensor_readings_resp *)msg->payload;

	response->completion_code = completion_code;
	response->comp_sensor_count = comp_sensor_count;
	memcpy(response->field, field,
	       (sizeof(get_sensor_state_field) * comp_sensor_count));

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_get_state_sensor_readings_req(uint8_t instance_id,
					 uint16_t sensor_id,
					 bitfield8_t sensor_rearm,
					 uint8_t reserved, struct pldm_msg *msg)
{
	if (msg == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_REQUEST;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_GET_STATE_SENSOR_READINGS;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_get_state_sensor_readings_req *request =
		(struct pldm_get_state_sensor_readings_req *)msg->payload;

	request->sensor_id = htole16(sensor_id);
	request->reserved = reserved;
	request->sensor_rearm = sensor_rearm;

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_get_state_sensor_readings_resp(const struct pldm_msg *msg,
					  size_t payload_length,
					  uint8_t *completion_code,
					  uint8_t *comp_sensor_count,
					  get_sensor_state_field *field)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	uint8_t i;
	int rc;

	if (msg == NULL || completion_code == NULL ||
	    comp_sensor_count == NULL || field == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(
		buf, PLDM_GET_STATE_SENSOR_READINGS_MIN_RESP_BYTES,
		msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	rc = pldm_msgbuf_extract_p(buf, completion_code);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (PLDM_SUCCESS != *completion_code) {
		return pldm_msgbuf_discard(buf, PLDM_SUCCESS);
	}

	rc = pldm_msgbuf_extract_p(buf, comp_sensor_count);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (*comp_sensor_count < 0x1 || *comp_sensor_count > 0x8) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	for (i = 0; i < *comp_sensor_count; i++) {
		pldm_msgbuf_extract(buf, field[i].sensor_op_state);
		pldm_msgbuf_extract(buf, field[i].present_state);
		pldm_msgbuf_extract(buf, field[i].previous_state);
		pldm_msgbuf_extract(buf, field[i].event_state);
	}

	rc = pldm_msgbuf_complete_consumed(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_get_state_sensor_readings_req(const struct pldm_msg *msg,
					 size_t payload_length,
					 uint16_t *sensor_id,
					 bitfield8_t *sensor_rearm,
					 uint8_t *reserved)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || sensor_id == NULL || sensor_rearm == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf,
				    PLDM_GET_STATE_SENSOR_READINGS_REQ_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_extract_p(buf, sensor_id);
	pldm_msgbuf_extract(buf, sensor_rearm->byte);
	pldm_msgbuf_extract_p(buf, reserved);

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_sensor_event_data(
	struct pldm_sensor_event_data *const event_data,
	const size_t event_data_size, const uint16_t sensor_id,
	const enum sensor_event_class_states sensor_event_class,
	const uint8_t sensor_offset, const uint8_t event_state,
	const uint8_t previous_event_state,
	size_t *const actual_event_data_size)
{
	*actual_event_data_size =
		(sizeof(*event_data) - sizeof(event_data->event_class) +
		 sizeof(struct pldm_sensor_event_state_sensor_state));

	if (!event_data) {
		return PLDM_SUCCESS;
	}

	if (event_data_size < *actual_event_data_size) {
		*actual_event_data_size = 0;
		return PLDM_ERROR_INVALID_LENGTH;
	}

	event_data->sensor_id = htole16(sensor_id);
	event_data->sensor_event_class_type = sensor_event_class;

	struct pldm_sensor_event_state_sensor_state *const state_data =
		(struct pldm_sensor_event_state_sensor_state *)
			event_data->event_class;

	state_data->sensor_offset = sensor_offset;
	state_data->event_state = event_state;
	state_data->previous_event_state = previous_event_state;

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_platform_event_message_req(const struct pldm_msg *msg,
				      size_t payload_length,
				      uint8_t *format_version, uint8_t *tid,
				      uint8_t *event_class,
				      size_t *event_data_offset)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || format_version == NULL || tid == NULL ||
	    event_class == NULL || event_data_offset == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf,
				    PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_extract_p(buf, format_version);
	pldm_msgbuf_extract_p(buf, tid);
	pldm_msgbuf_extract_p(buf, event_class);

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	*event_data_offset =
		sizeof(*format_version) + sizeof(*tid) + sizeof(*event_class);

	return PLDM_SUCCESS;
}

static int pldm_platform_poll_for_platform_event_message_validate(
	uint8_t transfer_operation_flag, uint16_t event_id_to_acknowledge)
{
	if (((transfer_operation_flag == PLDM_GET_FIRSTPART) &&
	     (event_id_to_acknowledge != PLDM_PLATFORM_EVENT_ID_NULL)) ||
	    ((transfer_operation_flag == PLDM_GET_NEXTPART) &&
	     (event_id_to_acknowledge != PLDM_PLATFORM_EVENT_ID_FRAGMENT)) ||
	    ((transfer_operation_flag == PLDM_ACKNOWLEDGEMENT_ONLY) &&
	     (event_id_to_acknowledge == PLDM_PLATFORM_EVENT_ID_FRAGMENT)) ||
	    ((transfer_operation_flag == PLDM_ACKNOWLEDGEMENT_ONLY) &&
	     (event_id_to_acknowledge == PLDM_PLATFORM_EVENT_ID_NULL)) ||
	    (transfer_operation_flag > PLDM_ACKNOWLEDGEMENT_ONLY)) {
		return -EPROTO;
	}

	return 0;
}

LIBPLDM_ABI_STABLE
int decode_poll_for_platform_event_message_req(
	const struct pldm_msg *msg, size_t payload_length,
	uint8_t *format_version, uint8_t *transfer_operation_flag,
	uint32_t *data_transfer_handle, uint16_t *event_id_to_acknowledge)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || format_version == NULL ||
	    transfer_operation_flag == NULL || data_transfer_handle == NULL ||
	    event_id_to_acknowledge == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(
		buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_REQ_BYTES,
		msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_extract_p(buf, format_version);
	rc = pldm_msgbuf_extract_p(buf, transfer_operation_flag);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}
	if (*transfer_operation_flag > PLDM_ACKNOWLEDGEMENT_ONLY) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	pldm_msgbuf_extract_p(buf, data_transfer_handle);
	rc = pldm_msgbuf_extract_p(buf, event_id_to_acknowledge);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	rc = pldm_platform_poll_for_platform_event_message_validate(
		*transfer_operation_flag, *event_id_to_acknowledge);
	if (rc < 0) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_platform_event_message_resp(uint8_t instance_id,
				       uint8_t completion_code,
				       uint8_t platform_event_status,
				       struct pldm_msg *msg)
{
	if (msg == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (platform_event_status > PLDM_EVENT_LOGGING_REJECTED) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_RESPONSE;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_PLATFORM_EVENT_MESSAGE;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_platform_event_message_resp *response =
		(struct pldm_platform_event_message_resp *)msg->payload;
	response->completion_code = completion_code;
	response->platform_event_status = platform_event_status;

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_poll_for_platform_event_message_resp(
	uint8_t instance_id, uint8_t completion_code, uint8_t tid,
	uint16_t event_id, uint32_t next_data_transfer_handle,
	uint8_t transfer_flag, uint8_t event_class, uint32_t event_data_size,
	uint8_t *event_data, uint32_t checksum, struct pldm_msg *msg,
	size_t payload_length)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (!msg) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_RESPONSE;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE;

	rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	rc = pldm_msgbuf_init_errno(
		buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
		msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_insert(buf, completion_code);
	pldm_msgbuf_insert(buf, tid);
	rc = pldm_msgbuf_insert(buf, event_id);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (event_id == 0xffff || event_id == 0x0000) {
		if (PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES !=
		    payload_length) {
			return pldm_msgbuf_discard(buf,
						   PLDM_ERROR_INVALID_LENGTH);
		}

		rc = pldm_msgbuf_complete(buf);
		if (rc) {
			return pldm_xlate_errno(rc);
		}

		return PLDM_SUCCESS;
	}

	if ((event_data == NULL) && (event_data_size > 0)) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	pldm_msgbuf_insert(buf, next_data_transfer_handle);
	pldm_msgbuf_insert(buf, transfer_flag);
	pldm_msgbuf_insert(buf, event_class);
	rc = pldm_msgbuf_insert(buf, event_data_size);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if ((event_data_size > 0) && event_data) {
		rc = pldm_msgbuf_insert_array(buf, event_data_size, event_data,
					      event_data_size);
		if (rc) {
			return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
		}
	}

	if (transfer_flag == PLDM_END || transfer_flag == PLDM_START_AND_END) {
		pldm_msgbuf_insert(buf, checksum);
	}

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_platform_event_message_req(
	uint8_t instance_id, uint8_t format_version, uint8_t tid,
	uint8_t event_class, const uint8_t *event_data,
	size_t event_data_length, struct pldm_msg *msg, size_t payload_length)

{
	if (format_version != 1) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (msg == NULL || event_data == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (event_data_length == 0) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if ((SIZE_MAX - PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES) <
	    event_data_length) {
		return PLDM_ERROR_INVALID_LENGTH;
	}

	if (payload_length !=
	    PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES + event_data_length) {
		return PLDM_ERROR_INVALID_LENGTH;
	}

	if (event_class > PLDM_CPER_EVENT &&
	    !(event_class >= 0xf0 && event_class <= 0xfe)) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_REQUEST;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_PLATFORM_EVENT_MESSAGE;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_platform_event_message_req *request =
		(struct pldm_platform_event_message_req *)msg->payload;
	request->format_version = format_version;
	request->tid = tid;
	request->event_class = event_class;
	memcpy(request->event_data, event_data, event_data_length);

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_platform_event_message_resp(const struct pldm_msg *msg,
				       size_t payload_length,
				       uint8_t *completion_code,
				       uint8_t *platform_event_status)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || completion_code == NULL ||
	    platform_event_status == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf, PLDM_PLATFORM_EVENT_MESSAGE_RESP_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	rc = pldm_msgbuf_extract_p(buf, completion_code);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (PLDM_SUCCESS != *completion_code) {
		return pldm_msgbuf_discard(buf, PLDM_SUCCESS);
	}

	rc = pldm_msgbuf_extract_p(buf, platform_event_status);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (*platform_event_status > PLDM_EVENT_LOGGING_REJECTED) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_event_message_buffer_size_req(uint8_t instance_id,
					 uint16_t event_receiver_max_buffer_size,
					 struct pldm_msg *msg)
{
	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_REQUEST;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_EVENT_MESSAGE_BUFFER_SIZE;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_event_message_buffer_size_req *request =
		(struct pldm_event_message_buffer_size_req *)msg->payload;
	request->event_receiver_max_buffer_size =
		event_receiver_max_buffer_size;

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_event_message_buffer_size_resp(const struct pldm_msg *msg,
					  size_t payload_length,
					  uint8_t *completion_code,
					  uint16_t *terminus_max_buffer_size)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || completion_code == NULL ||
	    terminus_max_buffer_size == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf,
				    PLDM_EVENT_MESSAGE_BUFFER_SIZE_RESP_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	rc = pldm_msgbuf_extract_p(buf, completion_code);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (PLDM_SUCCESS != *completion_code) {
		return pldm_msgbuf_discard(buf, PLDM_SUCCESS);
	}

	pldm_msgbuf_extract_p(buf, terminus_max_buffer_size);

	rc = pldm_msgbuf_complete_consumed(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_event_message_supported_req(uint8_t instance_id,
				       uint8_t format_version,
				       struct pldm_msg *msg)
{
	if (format_version != 1) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (msg == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_REQUEST;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_EVENT_MESSAGE_SUPPORTED;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_event_message_supported_req *request =
		(struct pldm_event_message_supported_req *)msg->payload;
	request->format_version = format_version;

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_event_message_supported_resp(const struct pldm_msg *msg,
					size_t payload_length,
					uint8_t *completion_code,
					uint8_t *synchrony_config,
					bitfield8_t *synchrony_config_support,
					uint8_t *number_event_class_returned,
					uint8_t *event_class,
					uint8_t event_class_count)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int i;
	int rc;

	if (msg == NULL || completion_code == NULL ||
	    synchrony_config == NULL || synchrony_config_support == NULL ||
	    number_event_class_returned == NULL || event_class == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf,
				    PLDM_EVENT_MESSAGE_SUPPORTED_MIN_RESP_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	rc = pldm_msgbuf_extract_p(buf, completion_code);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (PLDM_SUCCESS != *completion_code) {
		return pldm_msgbuf_discard(buf, PLDM_SUCCESS);
	}

	rc = pldm_msgbuf_extract_p(buf, synchrony_config);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (*synchrony_config > PLDM_MESSAGE_TYPE_ASYNCHRONOUS_WITH_HEARTBEAT) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	pldm_msgbuf_extract_p(buf, &synchrony_config_support->byte);

	rc = pldm_msgbuf_extract_p(buf, number_event_class_returned);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (*number_event_class_returned == 0) {
		rc = pldm_msgbuf_complete(buf);
		if (rc) {
			return pldm_xlate_errno(rc);
		}

		return PLDM_SUCCESS;
	}

	if (event_class_count < *number_event_class_returned) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_LENGTH);
	}

	for (i = 0; i < *number_event_class_returned; i++) {
		pldm_msgbuf_extract(buf, event_class[i]);
	}

	rc = pldm_msgbuf_complete_consumed(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_sensor_event_data(const uint8_t *event_data,
			     size_t event_data_length, uint16_t *sensor_id,
			     uint8_t *sensor_event_class_type,
			     size_t *event_class_data_offset)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (event_data == NULL || sensor_id == NULL ||
	    sensor_event_class_type == NULL ||
	    event_class_data_offset == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf, PLDM_SENSOR_EVENT_DATA_MIN_LENGTH,
				    event_data, event_data_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	if (event_data_length < PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_LENGTH);
	}

	size_t event_class_data_length =
		event_data_length - PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES;

	pldm_msgbuf_extract_p(buf, sensor_id);
	rc = pldm_msgbuf_extract_p(buf, sensor_event_class_type);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (*sensor_event_class_type == PLDM_SENSOR_OP_STATE) {
		if (event_class_data_length !=
		    PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH) {
			return pldm_msgbuf_discard(buf,
						   PLDM_ERROR_INVALID_LENGTH);
		}
	} else if (*sensor_event_class_type == PLDM_STATE_SENSOR_STATE) {
		if (event_class_data_length !=
		    PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH) {
			return pldm_msgbuf_discard(buf,
						   PLDM_ERROR_INVALID_LENGTH);
		}
	} else if (*sensor_event_class_type == PLDM_NUMERIC_SENSOR_STATE) {
		if (event_class_data_length <
			    PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MIN_DATA_LENGTH ||
		    event_class_data_length >
			    PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH) {
			return pldm_msgbuf_discard(buf,
						   PLDM_ERROR_INVALID_LENGTH);
		}
	} else {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	*event_class_data_offset =
		sizeof(*sensor_id) + sizeof(*sensor_event_class_type);

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_sensor_op_data(const uint8_t *sensor_data, size_t sensor_data_length,
			  uint8_t *present_op_state, uint8_t *previous_op_state)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (sensor_data == NULL || present_op_state == NULL ||
	    previous_op_state == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(
		buf, PLDM_SENSOR_EVENT_SENSOR_OP_STATE_DATA_LENGTH, sensor_data,
		sensor_data_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_extract_p(buf, present_op_state);
	pldm_msgbuf_extract_p(buf, previous_op_state);

	rc = pldm_msgbuf_complete_consumed(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_state_sensor_data(const uint8_t *sensor_data,
			     size_t sensor_data_length, uint8_t *sensor_offset,
			     uint8_t *event_state,
			     uint8_t *previous_event_state)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (sensor_data == NULL || sensor_offset == NULL ||
	    event_state == NULL || previous_event_state == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(
		buf, PLDM_SENSOR_EVENT_STATE_SENSOR_STATE_DATA_LENGTH,
		sensor_data, sensor_data_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_extract_p(buf, sensor_offset);
	pldm_msgbuf_extract_p(buf, event_state);
	pldm_msgbuf_extract_p(buf, previous_event_state);

	rc = pldm_msgbuf_complete_consumed(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_numeric_sensor_data(const uint8_t *sensor_data,
			       size_t sensor_data_length, uint8_t *event_state,
			       uint8_t *previous_event_state,
			       uint8_t *sensor_data_size,
			       uint32_t *present_reading)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (sensor_data == NULL || sensor_data_size == NULL ||
	    event_state == NULL || previous_event_state == NULL ||
	    present_reading == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (sensor_data_length >
	    PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MAX_DATA_LENGTH) {
		return PLDM_ERROR_INVALID_LENGTH;
	}

	rc = pldm_msgbuf_init_errno(
		buf, PLDM_SENSOR_EVENT_NUMERIC_SENSOR_STATE_MIN_DATA_LENGTH,
		sensor_data, sensor_data_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_extract_p(buf, event_state);
	pldm_msgbuf_extract_p(buf, previous_event_state);
	rc = pldm_msgbuf_extract_p(buf, sensor_data_size);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	/*
	 * The implementation below is bonkers, but it's because the function
	 * prototype is bonkers. The `present_reading` argument should have been
	 * a tagged union.
	 */
	switch (*sensor_data_size) {
	case PLDM_SENSOR_DATA_SIZE_UINT8: {
		uint8_t val;
		if (!pldm_msgbuf_extract(buf, val)) {
			*present_reading = (uint32_t)val;
		}
		break;
	}
	case PLDM_SENSOR_DATA_SIZE_SINT8: {
		int8_t val;
		if (!pldm_msgbuf_extract(buf, val)) {
			*present_reading = (uint32_t)(int32_t)val;
		}
		break;
	}
	case PLDM_SENSOR_DATA_SIZE_UINT16: {
		uint16_t val;
		if (!pldm_msgbuf_extract(buf, val)) {
			*present_reading = (uint32_t)val;
		}
		break;
	}
	case PLDM_SENSOR_DATA_SIZE_SINT16: {
		int16_t val;
		if (!pldm_msgbuf_extract(buf, val)) {
			*present_reading = (uint32_t)(int32_t)val;
		}
		break;
	}
	case PLDM_SENSOR_DATA_SIZE_UINT32: {
		uint32_t val;
		if (!pldm_msgbuf_extract(buf, val)) {
			*present_reading = (uint32_t)val;
		}
		break;
	}
	case PLDM_SENSOR_DATA_SIZE_SINT32: {
		int32_t val;
		if (!pldm_msgbuf_extract(buf, val)) {
			*present_reading = (uint32_t)val;
		}
		break;
	}
	default:
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	rc = pldm_msgbuf_complete_consumed(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_numeric_sensor_pdr_data(
	const void *pdr_data, size_t pdr_data_length,
	struct pldm_numeric_sensor_value_pdr *pdr_value)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (!pdr_data || !pdr_value) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf, PLDM_PDR_NUMERIC_SENSOR_PDR_MIN_LENGTH,
				    pdr_data, pdr_data_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	rc = pldm_msgbuf_extract_value_pdr_hdr(
		buf, &pdr_value->hdr, PLDM_PDR_NUMERIC_SENSOR_PDR_MIN_LENGTH,
		pdr_data_length);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	pldm_msgbuf_extract(buf, pdr_value->terminus_handle);
	pldm_msgbuf_extract(buf, pdr_value->sensor_id);
	pldm_msgbuf_extract(buf, pdr_value->entity_type);
	pldm_msgbuf_extract(buf, pdr_value->entity_instance_num);
	pldm_msgbuf_extract(buf, pdr_value->container_id);
	pldm_msgbuf_extract(buf, pdr_value->sensor_init);
	pldm_msgbuf_extract(buf, pdr_value->sensor_auxiliary_names_pdr);
	pldm_msgbuf_extract(buf, pdr_value->base_unit);
	pldm_msgbuf_extract(buf, pdr_value->unit_modifier);
	pldm_msgbuf_extract(buf, pdr_value->rate_unit);
	pldm_msgbuf_extract(buf, pdr_value->base_oem_unit_handle);
	pldm_msgbuf_extract(buf, pdr_value->aux_unit);
	pldm_msgbuf_extract(buf, pdr_value->aux_unit_modifier);
	pldm_msgbuf_extract(buf, pdr_value->aux_rate_unit);
	pldm_msgbuf_extract(buf, pdr_value->rel);
	pldm_msgbuf_extract(buf, pdr_value->aux_oem_unit_handle);
	pldm_msgbuf_extract(buf, pdr_value->is_linear);

	rc = pldm_msgbuf_extract(buf, pdr_value->sensor_data_size);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}
	if (pdr_value->sensor_data_size > PLDM_SENSOR_DATA_SIZE_MAX) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	pldm_msgbuf_extract(buf, pdr_value->resolution);
	pldm_msgbuf_extract(buf, pdr_value->offset);
	pldm_msgbuf_extract(buf, pdr_value->accuracy);
	pldm_msgbuf_extract(buf, pdr_value->plus_tolerance);
	pldm_msgbuf_extract(buf, pdr_value->minus_tolerance);
	pldm_msgbuf_extract_sensor_data(buf, pdr_value->sensor_data_size,
					&pdr_value->hysteresis);
	pldm_msgbuf_extract(buf, pdr_value->supported_thresholds.byte);
	pldm_msgbuf_extract(
		buf, pdr_value->threshold_and_hysteresis_volatility.byte);
	pldm_msgbuf_extract(buf, pdr_value->state_transition_interval);
	pldm_msgbuf_extract(buf, pdr_value->update_interval);
	pldm_msgbuf_extract_sensor_data(buf, pdr_value->sensor_data_size,
					&pdr_value->max_readable);
	pldm_msgbuf_extract_sensor_data(buf, pdr_value->sensor_data_size,
					&pdr_value->min_readable);

	rc = pldm_msgbuf_extract(buf, pdr_value->range_field_format);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}
	if (pdr_value->range_field_format > PLDM_RANGE_FIELD_FORMAT_MAX) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	pldm_msgbuf_extract(buf, pdr_value->range_field_support.byte);
	pldm_msgbuf_extract_range_field_format(
		buf, pdr_value->range_field_format, pdr_value->nominal_value);
	pldm_msgbuf_extract_range_field_format(
		buf, pdr_value->range_field_format, pdr_value->normal_max);
	pldm_msgbuf_extract_range_field_format(
		buf, pdr_value->range_field_format, pdr_value->normal_min);
	pldm_msgbuf_extract_range_field_format(
		buf, pdr_value->range_field_format, pdr_value->warning_high);
	pldm_msgbuf_extract_range_field_format(
		buf, pdr_value->range_field_format, pdr_value->warning_low);
	pldm_msgbuf_extract_range_field_format(
		buf, pdr_value->range_field_format, pdr_value->critical_high);
	pldm_msgbuf_extract_range_field_format(
		buf, pdr_value->range_field_format, pdr_value->critical_low);
	pldm_msgbuf_extract_range_field_format(
		buf, pdr_value->range_field_format, pdr_value->fatal_high);
	pldm_msgbuf_extract_range_field_format(
		buf, pdr_value->range_field_format, pdr_value->fatal_low);

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_get_numeric_effecter_value_req(uint8_t instance_id,
					  uint16_t effecter_id,
					  struct pldm_msg *msg)
{
	if (msg == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_REQUEST;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_GET_NUMERIC_EFFECTER_VALUE;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_get_numeric_effecter_value_req *request =
		(struct pldm_get_numeric_effecter_value_req *)msg->payload;
	request->effecter_id = htole16(effecter_id);

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_get_numeric_effecter_value_resp(
	uint8_t instance_id, uint8_t completion_code,
	uint8_t effecter_data_size, uint8_t effecter_oper_state,
	const uint8_t *pending_value, const uint8_t *present_value,
	struct pldm_msg *msg, size_t payload_length)
{
	if (msg == NULL || pending_value == NULL || present_value == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (effecter_oper_state > EFFECTER_OPER_STATE_INTEST) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_RESPONSE;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_GET_NUMERIC_EFFECTER_VALUE;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_get_numeric_effecter_value_resp *response =
		(struct pldm_get_numeric_effecter_value_resp *)msg->payload;

	response->completion_code = completion_code;
	response->effecter_data_size = effecter_data_size;
	response->effecter_oper_state = effecter_oper_state;

	if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 ||
	    effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) {
		if (payload_length !=
		    PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES) {
			return PLDM_ERROR_INVALID_LENGTH;
		}
		response->pending_and_present_values[0] = *pending_value;
		response->pending_and_present_values[1] = *present_value;

	} else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT16 ||
		   effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT16) {
		if (payload_length !=
		    PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 2) {
			return PLDM_ERROR_INVALID_LENGTH;
		}
		uint16_t val_pending = *(uint16_t *)pending_value;
		val_pending = htole16(val_pending);
		memcpy(response->pending_and_present_values, &val_pending,
		       sizeof(uint16_t));
		uint16_t val_present = *(uint16_t *)present_value;
		val_present = htole16(val_present);
		memcpy((response->pending_and_present_values +
			sizeof(uint16_t)),
		       &val_present, sizeof(uint16_t));

	} else if (effecter_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
		   effecter_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) {
		if (payload_length !=
		    PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES + 6) {
			return PLDM_ERROR_INVALID_LENGTH;
		}
		uint32_t val_pending = *(uint32_t *)pending_value;
		val_pending = htole32(val_pending);
		memcpy(response->pending_and_present_values, &val_pending,
		       sizeof(uint32_t));
		uint32_t val_present = *(uint32_t *)present_value;
		val_present = htole32(val_present);
		memcpy((response->pending_and_present_values +
			sizeof(uint32_t)),
		       &val_present, sizeof(uint32_t));
	}
	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_get_numeric_effecter_value_req(const struct pldm_msg *msg,
					  size_t payload_length,
					  uint16_t *effecter_id)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || effecter_id == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf,
				    PLDM_GET_NUMERIC_EFFECTER_VALUE_REQ_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_extract_p(buf, effecter_id);

	rc = pldm_msgbuf_complete_consumed(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_get_numeric_effecter_value_resp(const struct pldm_msg *msg,
					   size_t payload_length,
					   uint8_t *completion_code,
					   uint8_t *effecter_data_size,
					   uint8_t *effecter_oper_state,
					   uint8_t *pending_value,
					   uint8_t *present_value)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || effecter_data_size == NULL ||
	    effecter_oper_state == NULL || pending_value == NULL ||
	    present_value == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(
		buf, PLDM_GET_NUMERIC_EFFECTER_VALUE_MIN_RESP_BYTES,
		msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	rc = pldm_msgbuf_extract_p(buf, completion_code);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (PLDM_SUCCESS != *completion_code) {
		return pldm_msgbuf_discard(buf, PLDM_SUCCESS);
	}

	rc = pldm_msgbuf_extract_p(buf, effecter_data_size);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (*effecter_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	rc = pldm_msgbuf_extract_p(buf, effecter_oper_state);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (*effecter_oper_state > EFFECTER_OPER_STATE_INTEST) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	pldm_msgbuf_extract_effecter_value(buf, *effecter_data_size,
					   pending_value);
	pldm_msgbuf_extract_effecter_value(buf, *effecter_data_size,
					   present_value);

	rc = pldm_msgbuf_complete_consumed(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_pldm_pdr_repository_chg_event_data(
	uint8_t event_data_format, uint8_t number_of_change_records,
	const uint8_t *event_data_operations,
	const uint8_t *numbers_of_change_entries,
	const uint32_t *const *change_entries,
	struct pldm_pdr_repository_chg_event_data *event_data,
	size_t *actual_change_records_size, size_t max_change_records_size)
{
	if (event_data_operations == NULL ||
	    numbers_of_change_entries == NULL || change_entries == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	size_t expected_size =
		sizeof(event_data_format) + sizeof(number_of_change_records);

	expected_size +=
		sizeof(*event_data_operations) * number_of_change_records;
	expected_size +=
		sizeof(*numbers_of_change_entries) * number_of_change_records;

	for (uint8_t i = 0; i < number_of_change_records; ++i) {
		expected_size += sizeof(*change_entries[0]) *
				 numbers_of_change_entries[i];
	}

	*actual_change_records_size = expected_size;

	if (event_data == NULL) {
		return PLDM_SUCCESS;
	}

	if (max_change_records_size < expected_size) {
		return PLDM_ERROR_INVALID_LENGTH;
	}

	event_data->event_data_format = event_data_format;
	event_data->number_of_change_records = number_of_change_records;

	struct pldm_pdr_repository_change_record_data *record_data =
		(struct pldm_pdr_repository_change_record_data *)
			event_data->change_records;

	for (uint8_t i = 0; i < number_of_change_records; ++i) {
		record_data->event_data_operation = event_data_operations[i];
		record_data->number_of_change_entries =
			numbers_of_change_entries[i];

		for (uint8_t j = 0; j < record_data->number_of_change_entries;
		     ++j) {
			record_data->change_entry[j] =
				htole32(change_entries[i][j]);
		}

		record_data =
			(struct pldm_pdr_repository_change_record_data
				 *)(record_data->change_entry +
				    record_data->number_of_change_entries);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_pldm_pdr_repository_chg_event_data(const uint8_t *event_data,
					      size_t event_data_size,
					      uint8_t *event_data_format,
					      uint8_t *number_of_change_records,
					      size_t *change_record_data_offset)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (event_data == NULL || event_data_format == NULL ||
	    number_of_change_records == NULL ||
	    change_record_data_offset == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf,
				    PLDM_PDR_REPOSITORY_CHG_EVENT_MIN_LENGTH,
				    event_data, event_data_size);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_extract_p(buf, event_data_format);
	pldm_msgbuf_extract_p(buf, number_of_change_records);

	*change_record_data_offset =
		sizeof(*event_data_format) + sizeof(*number_of_change_records);

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_pldm_message_poll_event_data(
	const void *event_data, size_t event_data_length,
	struct pldm_message_poll_event *poll_event)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (!event_data || !poll_event) {
		return -EINVAL;
	}

	rc = pldm_msgbuf_init_errno(buf, PLDM_MSG_POLL_EVENT_LENGTH, event_data,
				    event_data_length);
	if (rc) {
		return rc;
	}

	pldm_msgbuf_extract(buf, poll_event->format_version);
	rc = pldm_msgbuf_extract(buf, poll_event->event_id);
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}

	if (poll_event->event_id == 0x0000 || poll_event->event_id == 0xffff) {
		return pldm_msgbuf_discard(buf, -EPROTO);
	}

	pldm_msgbuf_extract(buf, poll_event->data_transfer_handle);

	return pldm_msgbuf_complete_consumed(buf);
}

LIBPLDM_ABI_TESTING
int encode_pldm_message_poll_event_data(
	const struct pldm_message_poll_event *poll_event, void *event_data,
	size_t event_data_length)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (poll_event == NULL || event_data == NULL) {
		return -EINVAL;
	}

	if (poll_event->event_id == 0x0000 || poll_event->event_id == 0xffff) {
		return -EPROTO;
	}

	rc = pldm_msgbuf_init_errno(buf, PLDM_MSG_POLL_EVENT_LENGTH, event_data,
				    event_data_length);
	if (rc) {
		return rc;
	}
	pldm_msgbuf_insert(buf, poll_event->format_version);
	pldm_msgbuf_insert(buf, poll_event->event_id);
	pldm_msgbuf_insert(buf, poll_event->data_transfer_handle);

	return pldm_msgbuf_complete_consumed(buf);
}

LIBPLDM_ABI_STABLE
int decode_pldm_pdr_repository_change_record_data(
	const uint8_t *change_record_data, size_t change_record_data_size,
	uint8_t *event_data_operation, uint8_t *number_of_change_entries,
	size_t *change_entry_data_offset)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (change_record_data == NULL || event_data_operation == NULL ||
	    number_of_change_entries == NULL ||
	    change_entry_data_offset == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(
		buf, PLDM_PDR_REPOSITORY_CHANGE_RECORD_MIN_LENGTH,
		change_record_data, change_record_data_size);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_extract_p(buf, event_data_operation);
	pldm_msgbuf_extract_p(buf, number_of_change_entries);

	*change_entry_data_offset = sizeof(*event_data_operation) +
				    sizeof(*number_of_change_entries);

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_get_sensor_reading_req(uint8_t instance_id, uint16_t sensor_id,
				  uint8_t rearm_event_state,
				  struct pldm_msg *msg)
{
	if (msg == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_REQUEST;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_GET_SENSOR_READING;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_get_sensor_reading_req *request =
		(struct pldm_get_sensor_reading_req *)msg->payload;

	request->sensor_id = htole16(sensor_id);
	request->rearm_event_state = rearm_event_state;

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_get_sensor_reading_resp(
	const struct pldm_msg *msg, size_t payload_length,
	uint8_t *completion_code, uint8_t *sensor_data_size,
	uint8_t *sensor_operational_state, uint8_t *sensor_event_message_enable,
	uint8_t *present_state, uint8_t *previous_state, uint8_t *event_state,
	uint8_t *present_reading)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || completion_code == NULL ||
	    sensor_data_size == NULL || sensor_operational_state == NULL ||
	    sensor_event_message_enable == NULL || present_state == NULL ||
	    previous_state == NULL || event_state == NULL ||
	    present_reading == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf, PLDM_GET_SENSOR_READING_MIN_RESP_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	rc = pldm_msgbuf_extract_p(buf, completion_code);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (PLDM_SUCCESS != *completion_code) {
		return pldm_msgbuf_discard(buf, PLDM_SUCCESS);
	}

	rc = pldm_msgbuf_extract_p(buf, sensor_data_size);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	if (*sensor_data_size > PLDM_SENSOR_DATA_SIZE_SINT32) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	pldm_msgbuf_extract_p(buf, sensor_operational_state);
	pldm_msgbuf_extract_p(buf, sensor_event_message_enable);
	pldm_msgbuf_extract_p(buf, present_state);
	pldm_msgbuf_extract_p(buf, previous_state);
	pldm_msgbuf_extract_p(buf, event_state);

	pldm_msgbuf_extract_sensor_value(buf, *sensor_data_size,
					 present_reading);

	rc = pldm_msgbuf_complete_consumed(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_get_sensor_reading_resp(uint8_t instance_id, uint8_t completion_code,
				   uint8_t sensor_data_size,
				   uint8_t sensor_operational_state,
				   uint8_t sensor_event_message_enable,
				   uint8_t present_state,
				   uint8_t previous_state, uint8_t event_state,
				   const uint8_t *present_reading,
				   struct pldm_msg *msg, size_t payload_length)
{
	if (msg == NULL || present_reading == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (sensor_data_size > PLDM_EFFECTER_DATA_SIZE_SINT32) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_RESPONSE;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_GET_SENSOR_READING;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_get_sensor_reading_resp *response =
		(struct pldm_get_sensor_reading_resp *)msg->payload;

	response->completion_code = completion_code;
	response->sensor_data_size = sensor_data_size;
	response->sensor_operational_state = sensor_operational_state;
	response->sensor_event_message_enable = sensor_event_message_enable;
	response->present_state = present_state;
	response->previous_state = previous_state;
	response->event_state = event_state;

	if (sensor_data_size == PLDM_EFFECTER_DATA_SIZE_UINT8 ||
	    sensor_data_size == PLDM_EFFECTER_DATA_SIZE_SINT8) {
		if (payload_length != PLDM_GET_SENSOR_READING_MIN_RESP_BYTES) {
			return PLDM_ERROR_INVALID_LENGTH;
		}
		response->present_reading[0] = *present_reading;

	} else if (sensor_data_size == PLDM_EFFECTER_DATA_SIZE_UINT16 ||
		   sensor_data_size == PLDM_EFFECTER_DATA_SIZE_SINT16) {
		if (payload_length !=
		    PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 1) {
			return PLDM_ERROR_INVALID_LENGTH;
		}
		uint16_t val = *(uint16_t *)present_reading;
		val = htole16(val);
		memcpy(response->present_reading, &val, 2);

	} else if (sensor_data_size == PLDM_EFFECTER_DATA_SIZE_UINT32 ||
		   sensor_data_size == PLDM_EFFECTER_DATA_SIZE_SINT32) {
		if (payload_length !=
		    PLDM_GET_SENSOR_READING_MIN_RESP_BYTES + 3) {
			return PLDM_ERROR_INVALID_LENGTH;
		}
		uint32_t val = *(uint32_t *)present_reading;
		val = htole32(val);
		memcpy(response->present_reading, &val, 4);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_get_sensor_reading_req(const struct pldm_msg *msg,
				  size_t payload_length, uint16_t *sensor_id,
				  uint8_t *rearm_event_state)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || sensor_id == NULL || rearm_event_state == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf, PLDM_GET_SENSOR_READING_REQ_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_extract_p(buf, sensor_id);
	pldm_msgbuf_extract_p(buf, rearm_event_state);

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_TESTING
int decode_set_numeric_sensor_enable_req(
	const struct pldm_msg *msg, size_t payload_length,
	struct pldm_set_numeric_sensor_enable_req *req)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	uint8_t event_enable = 0;
	uint8_t op_state = 0;
	int rc;

	if (msg == NULL || req == NULL) {
		return -EINVAL;
	}

	rc = pldm_msgbuf_init_errno(buf, 0, msg->payload, payload_length);
	if (rc) {
		return rc;
	}

	pldm_msgbuf_extract(buf, req->sensor_id);
	pldm_msgbuf_extract(buf, op_state);
	pldm_msgbuf_extract(buf, event_enable);

	rc = pldm_msgbuf_complete_consumed(buf);
	if (rc) {
		return rc;
	}

	if (op_state > PLDM_SET_SENSOR_UNAVAILABLE) {
		return -EPROTO;
	}

	if (event_enable > PLDM_STATE_EVENTS_ONLY_ENABLED) {
		return -EPROTO;
	}

	req->op_state = op_state;
	req->event_enable = event_enable;

	return 0;
}

LIBPLDM_ABI_TESTING
int decode_set_state_sensor_enables_req(
	const struct pldm_msg *msg, size_t payload_length,
	struct pldm_set_state_sensor_enables_req *req)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || req == NULL) {
		return -EINVAL;
	}

	rc = pldm_msgbuf_init_errno(buf, 3, msg->payload, payload_length);
	if (rc) {
		return rc;
	}

	pldm_msgbuf_extract(buf, req->sensor_id);
	rc = pldm_msgbuf_extract(buf, req->field_count);
	if (rc) {
		return rc;
	}

	if (req->field_count < 1 ||
	    req->field_count > PLDM_SET_STATE_SENSOR_ENABLES_MAX_COUNT) {
		return -EPROTO;
	}

	for (uint8_t i = 0; i < req->field_count; i++) {
		uint8_t event_enable_val = 0;
		uint8_t op_state_val = 0;

		pldm_msgbuf_extract(buf, op_state_val);
		rc = pldm_msgbuf_extract(buf, event_enable_val);
		if (rc) {
			return pldm_msgbuf_discard(buf, rc);
		}

		if (op_state_val > PLDM_SET_SENSOR_UNAVAILABLE) {
			return pldm_msgbuf_discard(buf, -EPROTO);
		}

		if (event_enable_val > PLDM_STATE_EVENTS_ONLY_ENABLED) {
			return pldm_msgbuf_discard(buf, -EPROTO);
		}

		req->fields[i].op_state = op_state_val;
		req->fields[i].event_enable = event_enable_val;
	}

	return pldm_msgbuf_complete_consumed(buf);
}

LIBPLDM_ABI_TESTING
int encode_get_event_receiver_req(uint8_t instance_id, struct pldm_msg *msg,
				  size_t payload_length LIBPLDM_CC_UNUSED)
{
	struct pldm_header_info header;
	header.msg_type = PLDM_REQUEST;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_GET_EVENT_RECEIVER;

	if (!msg) {
		return -EINVAL;
	}

	return pack_pldm_header_errno(&header, &(msg->hdr));
}

LIBPLDM_ABI_TESTING
int encode_get_event_receiver_resp(
	uint8_t instance_id,
	struct pldm_get_event_receiver_resp *event_receiver_info,
	struct pldm_msg *msg, size_t *payload_length)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;
	if (!msg || !event_receiver_info) {
		return -EINVAL;
	}

	/* See Table 2, DSP0245 v1.4.0 */
	if (event_receiver_info->transport_protocol_type !=
	    PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP) {
		return -ENOTSUP;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_RESPONSE;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_GET_EVENT_RECEIVER;

	rc = pack_pldm_header_errno(&header, &(msg->hdr));
	if (rc) {
		return rc;
	}
	rc = pldm_msgbuf_init_errno(buf, PLDM_GET_EVENT_RECEIVER_MIN_RESP_BYTES,
				    msg->payload, *payload_length);
	if (rc) {
		return rc;
	}

	pldm_msgbuf_insert(buf, event_receiver_info->completion_code);
	pldm_msgbuf_insert(buf, event_receiver_info->transport_protocol_type);
	pldm_msgbuf_insert(
		buf, event_receiver_info->event_receiver_address.mctp_eid);
	return pldm_msgbuf_complete_used(buf, *payload_length, payload_length);
}

LIBPLDM_ABI_STABLE
int decode_get_event_receiver_resp(const struct pldm_msg *msg,
				   size_t payload_length,
				   struct pldm_get_event_receiver_resp *resp)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;
	if (!msg) {
		return -EINVAL;
	}

	rc = pldm_msg_has_error(msg, payload_length);
	if (rc) {
		resp->completion_code = rc;
		return 0;
	}

	rc = pldm_msgbuf_init_errno(buf, PLDM_GET_EVENT_RECEIVER_MIN_RESP_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return rc;
	}
	pldm_msgbuf_extract(buf, resp->completion_code);
	rc = pldm_msgbuf_extract(buf, resp->transport_protocol_type);
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}
	if (resp->transport_protocol_type ==
	    PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP) {
		pldm_msgbuf_extract(buf, resp->event_receiver_address.mctp_eid);
	} else {
		return pldm_msgbuf_discard(buf, -ENOTSUP);
	}
	return pldm_msgbuf_complete_consumed(buf);
}

LIBPLDM_ABI_STABLE
int encode_set_event_receiver_req(uint8_t instance_id,
				  uint8_t event_message_global_enable,
				  uint8_t transport_protocol_type,
				  uint8_t event_receiver_address_info,
				  uint16_t heartbeat_timer,
				  struct pldm_msg *msg)
{
	if (msg == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	if (transport_protocol_type != PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_REQUEST;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_SET_EVENT_RECEIVER;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	struct pldm_set_event_receiver_req *request =
		(struct pldm_set_event_receiver_req *)msg->payload;
	request->event_message_global_enable = event_message_global_enable;

	request->transport_protocol_type = transport_protocol_type;
	request->event_receiver_address_info = event_receiver_address_info;

	if (event_message_global_enable ==
	    PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE) {
		if (heartbeat_timer == 0) {
			return PLDM_ERROR_INVALID_DATA;
		}
		request->heartbeat_timer = htole16(heartbeat_timer);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_set_event_receiver_resp(const struct pldm_msg *msg,
				   size_t payload_length,
				   uint8_t *completion_code)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || completion_code == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf, PLDM_SET_EVENT_RECEIVER_RESP_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_extract_p(buf, completion_code);

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_set_event_receiver_req(const struct pldm_msg *msg,
				  size_t payload_length,
				  uint8_t *event_message_global_enable,
				  uint8_t *transport_protocol_type,
				  uint8_t *event_receiver_address_info,
				  uint16_t *heartbeat_timer)

{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || event_message_global_enable == NULL ||
	    transport_protocol_type == NULL ||
	    event_receiver_address_info == NULL || heartbeat_timer == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf, PLDM_SET_EVENT_RECEIVER_MIN_REQ_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_extract_p(buf, event_message_global_enable);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	pldm_msgbuf_extract_p(buf, transport_protocol_type);
	pldm_msgbuf_extract_p(buf, event_receiver_address_info);
	if (*event_message_global_enable ==
	    PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE) {
		pldm_msgbuf_extract_p(buf, heartbeat_timer);
	}

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	if ((*event_message_global_enable ==
	     PLDM_EVENT_MESSAGE_GLOBAL_ENABLE_ASYNC_KEEP_ALIVE) &&
	    (*heartbeat_timer == 0)) {
		return PLDM_ERROR_INVALID_DATA;
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_set_event_receiver_resp(uint8_t instance_id, uint8_t completion_code,
				   struct pldm_msg *msg)

{
	if (msg == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.instance = instance_id;
	header.msg_type = PLDM_RESPONSE;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_SET_EVENT_RECEIVER;

	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	msg->payload[0] = completion_code;

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_poll_for_platform_event_message_req(uint8_t instance_id,
					       uint8_t format_version,
					       uint8_t transfer_operation_flag,
					       uint32_t data_transfer_handle,
					       uint16_t event_id_to_acknowledge,
					       struct pldm_msg *msg,
					       size_t payload_length)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_platform_poll_for_platform_event_message_validate(
		transfer_operation_flag, event_id_to_acknowledge);
	if (rc < 0) {
		return PLDM_ERROR_INVALID_DATA;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_REQUEST;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE;

	rc = pack_pldm_header(&header, &(msg->hdr));
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	rc = pldm_msgbuf_init_errno(
		buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
		msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	pldm_msgbuf_insert(buf, format_version);
	pldm_msgbuf_insert(buf, transfer_operation_flag);
	pldm_msgbuf_insert(buf, data_transfer_handle);
	pldm_msgbuf_insert(buf, event_id_to_acknowledge);

	rc = pldm_msgbuf_complete(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int decode_poll_for_platform_event_message_resp(
	const struct pldm_msg *msg, size_t payload_length,
	uint8_t *completion_code, uint8_t *tid, uint16_t *event_id,
	uint32_t *next_data_transfer_handle, uint8_t *transfer_flag,
	uint8_t *event_class, uint32_t *event_data_size, void **event_data,
	uint32_t *event_data_integrity_checksum)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || completion_code == NULL || tid == NULL ||
	    event_id == NULL || next_data_transfer_handle == NULL ||
	    transfer_flag == NULL || event_class == NULL ||
	    event_data_size == NULL || event_data == NULL ||
	    event_data_integrity_checksum == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(
		buf, PLDM_POLL_FOR_PLATFORM_EVENT_MESSAGE_MIN_RESP_BYTES,
		msg->payload, payload_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	rc = pldm_msgbuf_extract_p(buf, completion_code);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}
	if (PLDM_SUCCESS != *completion_code) {
		return pldm_msgbuf_discard(buf, *completion_code);
	}

	pldm_msgbuf_extract_p(buf, tid);
	rc = pldm_msgbuf_extract_p(buf, event_id);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}
	if ((*event_id == 0) || (*event_id == 0xffff)) {
		return pldm_msgbuf_discard(buf, PLDM_SUCCESS);
	}

	pldm_msgbuf_extract_p(buf, next_data_transfer_handle);
	rc = pldm_msgbuf_extract_p(buf, transfer_flag);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}

	pldm_msgbuf_extract_p(buf, event_class);
	rc = pldm_msgbuf_extract_p(buf, event_data_size);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}
	if (*event_data_size > payload_length) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	if (*event_data_size > 0) {
		pldm_msgbuf_span_required(buf, *event_data_size, event_data);
	}

	if (*transfer_flag == PLDM_END ||
	    *transfer_flag == PLDM_START_AND_END) {
		pldm_msgbuf_extract_p(buf, event_data_integrity_checksum);
	}

	rc = pldm_msgbuf_complete_consumed(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_TESTING
int decode_numeric_effecter_pdr_data(
	const void *pdr_data, size_t pdr_data_length,
	struct pldm_numeric_effecter_value_pdr *pdr_value)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	struct pldm_value_pdr_hdr hdr;
	int rc;

	if (!pdr_data || !pdr_value) {
		return PLDM_ERROR_INVALID_DATA;
	}

	rc = pldm_msgbuf_init_errno(buf,
				    PLDM_PDR_NUMERIC_EFFECTER_PDR_MIN_LENGTH,
				    pdr_data, pdr_data_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	rc = pldm_msgbuf_extract_value_pdr_hdr(
		buf, &hdr, PLDM_PDR_NUMERIC_EFFECTER_PDR_MIN_LENGTH,
		pdr_data_length);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	memcpy(&pdr_value->hdr, &hdr, sizeof(hdr));

	pldm_msgbuf_extract(buf, pdr_value->terminus_handle);
	pldm_msgbuf_extract(buf, pdr_value->effecter_id);
	pldm_msgbuf_extract(buf, pdr_value->entity_type);
	pldm_msgbuf_extract(buf, pdr_value->entity_instance);
	pldm_msgbuf_extract(buf, pdr_value->container_id);
	pldm_msgbuf_extract(buf, pdr_value->effecter_semantic_id);
	pldm_msgbuf_extract(buf, pdr_value->effecter_init);
	pldm_msgbuf_extract(buf, pdr_value->effecter_auxiliary_names);
	pldm_msgbuf_extract(buf, pdr_value->base_unit);
	pldm_msgbuf_extract(buf, pdr_value->unit_modifier);
	pldm_msgbuf_extract(buf, pdr_value->rate_unit);
	pldm_msgbuf_extract(buf, pdr_value->base_oem_unit_handle);
	pldm_msgbuf_extract(buf, pdr_value->aux_unit);
	pldm_msgbuf_extract(buf, pdr_value->aux_unit_modifier);
	pldm_msgbuf_extract(buf, pdr_value->aux_rate_unit);
	pldm_msgbuf_extract(buf, pdr_value->aux_oem_unit_handle);
	pldm_msgbuf_extract(buf, pdr_value->is_linear);

	rc = pldm_msgbuf_extract(buf, pdr_value->effecter_data_size);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}
	if (pdr_value->effecter_data_size > PLDM_SENSOR_DATA_SIZE_MAX) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	pldm_msgbuf_extract(buf, pdr_value->resolution);
	pldm_msgbuf_extract(buf, pdr_value->offset);
	pldm_msgbuf_extract(buf, pdr_value->accuracy);
	pldm_msgbuf_extract(buf, pdr_value->plus_tolerance);
	pldm_msgbuf_extract(buf, pdr_value->minus_tolerance);
	pldm_msgbuf_extract(buf, pdr_value->state_transition_interval);
	pldm_msgbuf_extract(buf, pdr_value->transition_interval);
	pldm_msgbuf_extract_effecter_data(buf, pdr_value->effecter_data_size,
					  pdr_value->max_settable);
	pldm_msgbuf_extract_effecter_data(buf, pdr_value->effecter_data_size,
					  pdr_value->min_settable);

	rc = pldm_msgbuf_extract(buf, pdr_value->range_field_format);
	if (rc) {
		return pldm_xlate_errno(pldm_msgbuf_discard(buf, rc));
	}
	if (pdr_value->range_field_format > PLDM_RANGE_FIELD_FORMAT_MAX) {
		return pldm_msgbuf_discard(buf, PLDM_ERROR_INVALID_DATA);
	}

	pldm_msgbuf_extract(buf, pdr_value->range_field_support.byte);
	pldm_msgbuf_extract_range_field_format(
		buf, pdr_value->range_field_format, pdr_value->nominal_value);
	pldm_msgbuf_extract_range_field_format(
		buf, pdr_value->range_field_format, pdr_value->normal_max);
	pldm_msgbuf_extract_range_field_format(
		buf, pdr_value->range_field_format, pdr_value->normal_min);
	pldm_msgbuf_extract_range_field_format(
		buf, pdr_value->range_field_format, pdr_value->rated_max);
	pldm_msgbuf_extract_range_field_format(
		buf, pdr_value->range_field_format, pdr_value->rated_min);

	rc = pldm_msgbuf_complete_consumed(buf);
	if (rc) {
		return pldm_xlate_errno(rc);
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int encode_get_state_effecter_states_req(uint8_t instance_id,
					 uint16_t effecter_id,
					 struct pldm_msg *msg,
					 size_t payload_length)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL) {
		return -EINVAL;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_REQUEST;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_GET_STATE_EFFECTER_STATES;

	rc = pack_pldm_header_errno(&header, &msg->hdr);
	if (rc < 0) {
		return rc;
	}

	rc = pldm_msgbuf_init_errno(buf,
				    PLDM_GET_STATE_EFFECTER_STATES_REQ_BYTES,
				    msg->payload, payload_length);
	if (rc) {
		return rc;
	}

	pldm_msgbuf_insert(buf, effecter_id);

	return pldm_msgbuf_complete_consumed(buf);
}

LIBPLDM_ABI_STABLE
int decode_get_state_effecter_states_req(const struct pldm_msg *msg,
					 size_t payload_length,
					 uint16_t *effecter_id)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (msg == NULL || effecter_id == NULL) {
		return -EINVAL;
	}

	rc = pldm_msgbuf_init_errno(
		buf, PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES,
		msg->payload, payload_length);
	if (rc) {
		return rc;
	}

	pldm_msgbuf_extract_p(buf, effecter_id);

	return pldm_msgbuf_complete_consumed(buf);
}

LIBPLDM_ABI_STABLE
int decode_get_state_effecter_states_resp(
	const struct pldm_msg *msg, size_t payload_length,
	struct pldm_get_state_effecter_states_resp *resp)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	get_effecter_state_field *field;
	int rc;
	int i;

	if (msg == NULL || resp == NULL) {
		return -EINVAL;
	}

	rc = pldm_msgbuf_init_errno(
		buf, PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES,
		msg->payload, payload_length);
	if (rc) {
		return rc;
	}

	rc = pldm_msgbuf_extract(buf, resp->completion_code);
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}

	if (PLDM_SUCCESS != resp->completion_code) {
		return pldm_msgbuf_complete(buf);
	}

	rc = pldm_msgbuf_extract(buf, resp->comp_effecter_count);
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}

	uint8_t comp_effecter_count = resp->comp_effecter_count;

	if (comp_effecter_count < PLDM_GET_EFFECTER_STATE_FIELD_COUNT_MIN ||
	    comp_effecter_count > PLDM_GET_EFFECTER_STATE_FIELD_COUNT_MAX) {
		return pldm_msgbuf_discard(buf, -EBADMSG);
	}

	for (i = 0, field = resp->field; i < comp_effecter_count;
	     i++, field++) {
		pldm_msgbuf_extract(buf, field->effecter_op_state);
		pldm_msgbuf_extract(buf, field->pending_state);
		pldm_msgbuf_extract(buf, field->present_state);
	}

	return pldm_msgbuf_complete_consumed(buf);
}

LIBPLDM_ABI_STABLE
int encode_get_state_effecter_states_resp(
	uint8_t instance_id, struct pldm_get_state_effecter_states_resp *resp,
	struct pldm_msg *msg, size_t payload_length)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	get_effecter_state_field *field;
	int rc;
	int i;

	if (msg == NULL || resp == NULL) {
		return -EINVAL;
	}

	uint8_t comp_effecter_count = resp->comp_effecter_count;

	if (comp_effecter_count < PLDM_GET_EFFECTER_STATE_FIELD_COUNT_MIN ||
	    comp_effecter_count > PLDM_GET_EFFECTER_STATE_FIELD_COUNT_MAX) {
		return -EBADMSG;
	}

	struct pldm_header_info header = { 0 };
	header.msg_type = PLDM_RESPONSE;
	header.instance = instance_id;
	header.pldm_type = PLDM_PLATFORM;
	header.command = PLDM_GET_STATE_EFFECTER_STATES;

	rc = pack_pldm_header_errno(&header, &msg->hdr);
	if (rc < 0) {
		return rc;
	}

	rc = pldm_msgbuf_init_errno(
		buf, PLDM_GET_STATE_EFFECTER_STATES_MIN_RESP_BYTES,
		msg->payload, payload_length);
	if (rc) {
		return rc;
	}

	pldm_msgbuf_insert(buf, resp->completion_code);
	pldm_msgbuf_insert(buf, comp_effecter_count);

	for (i = 0, field = resp->field; i < comp_effecter_count;
	     i++, field++) {
		pldm_msgbuf_insert(buf, field->effecter_op_state);
		pldm_msgbuf_insert(buf, field->pending_state);
		pldm_msgbuf_insert(buf, field->present_state);
	}

	return pldm_msgbuf_complete_consumed(buf);
}

LIBPLDM_ABI_STABLE
int decode_entity_auxiliary_names_pdr(
	const void *data, size_t data_length,
	struct pldm_entity_auxiliary_names_pdr *pdr, size_t pdr_length)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	PLDM_MSGBUF_DEFINE_P(src);
	PLDM_MSGBUF_DEFINE_P(dst);
	size_t names_len = 0;
	void *names = NULL;
	int rc;
	int i;

	if (!data || !pdr) {
		return -EINVAL;
	}

	/*
	 * Alignment of auxiliary_name_data is an invariant as we statically assert
	 * its behaviour in the header.
	 */
	assert(!((uintptr_t)pdr->auxiliary_name_data &
		 (alignof(pldm_utf16be) - 1)));

	/* Reject any lengths that are obviously invalid */
	if (pdr_length < data_length || pdr_length < sizeof(*pdr)) {
		return -EINVAL;
	}

	rc = pldm_msgbuf_init_errno(
		buf, PLDM_PDR_ENTITY_AUXILIARY_NAME_PDR_MIN_LENGTH, data,
		data_length);
	if (rc) {
		return rc;
	}

	rc = pldm_msgbuf_extract_value_pdr_hdr(
		buf, &pdr->hdr, PLDM_PDR_ENTITY_AUXILIARY_NAME_PDR_MIN_LENGTH,
		data_length);
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}

	pldm_msgbuf_extract(buf, pdr->container.entity_type);
	pldm_msgbuf_extract(buf, pdr->container.entity_instance_num);
	pldm_msgbuf_extract(buf, pdr->container.entity_container_id);
	pldm_msgbuf_extract(buf, pdr->shared_name_count);
	rc = pldm_msgbuf_extract(buf, pdr->name_string_count);
	if (rc < 0) {
		return pldm_msgbuf_discard(buf, rc);
	}

	rc = pldm_msgbuf_span_remaining(buf, &names, &names_len);
	if (rc < 0) {
		return rc;
	}
	assert(names);

	rc = pldm_msgbuf_complete_consumed(buf);
	if (rc) {
		return rc;
	}

	pdr->auxiliary_name_data_size = pdr_length - sizeof(*pdr);

	rc = pldm_msgbuf_init_errno(dst, pdr->auxiliary_name_data_size,
				    pdr->auxiliary_name_data,
				    pdr->auxiliary_name_data_size);
	if (rc < 0) {
		return rc;
	}

	/*
	 * Below we do two passes over the same region. This is to first pack the
	 * UTF16-BE strings into auxiliary_name_data, followed by the ASCII strings,
	 * to maintain appropriate alignment.
	 */

	/* Initialise for the first pass to extract the UTF16-BE name strings */
	rc = pldm_msgbuf_init_errno(src, names_len, names, names_len);
	if (rc < 0) {
		goto cleanup_msgbuf_dst;
	}

	for (i = 0; i < pdr->name_string_count; i++) {
		pldm_msgbuf_span_string_ascii(src, NULL, NULL);
		rc = pldm_msgbuf_copy_string_utf16(dst, src);
		if (rc) {
			goto cleanup_msgbuf_src;
		}
	}

	rc = pldm_msgbuf_complete_consumed(src);
	if (rc < 0) {
		goto cleanup_msgbuf_dst;
	}

	/* Reinitialise for the second pass to extract the ASCII tag strings */
	rc = pldm_msgbuf_init_errno(src, names_len, names, names_len);
	if (rc < 0) {
		goto cleanup_msgbuf_dst;
	}

	for (i = 0; i < pdr->name_string_count; i++) {
		rc = pldm_msgbuf_copy_string_ascii(dst, src);
		if (rc) {
			goto cleanup_msgbuf_src;
		}
		pldm_msgbuf_span_string_utf16(src, NULL, NULL);
	}

	rc = pldm_msgbuf_complete(src);
	if (rc) {
		goto cleanup_msgbuf_dst;
	}

	return pldm_msgbuf_complete(dst);

cleanup_msgbuf_src:
	rc = pldm_msgbuf_discard(src, rc);
cleanup_msgbuf_dst:
	return pldm_msgbuf_discard(dst, rc);
}

LIBPLDM_ABI_STABLE
int decode_pldm_entity_auxiliary_names_pdr_index(
	struct pldm_entity_auxiliary_names_pdr *pdr)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;
	int i;

	if (!pdr) {
		return -EINVAL;
	}

	if (pdr->name_string_count == 0 && pdr->names) {
		return -EINVAL;
	}

	if (pdr->name_string_count > 0 && !pdr->names) {
		return -EINVAL;
	}

	if (pdr->name_string_count == 0) {
		return 0;
	}

	/*
	 * Minimum size is one NUL for each member of each entry
	 *
	 * Note that the definition of nameLanguageTag in DSP0248 v1.2.2
	 * states the following:
	 *
	 * > A null-terminated ISO646 ASCII string ...
	 * >
	 * > special value: null string = 0x0000 = unspecified.
	 *
	 * Until proven otherwise we will assume the "0x0000" is a
	 * misrepresentation of an ASCII NUL, and that ASCII NUL is
	 * represented by a single byte.
	 */
	rc = pldm_msgbuf_init_errno(
		buf, pdr->name_string_count * (sizeof(char) + sizeof(char16_t)),
		pdr->auxiliary_name_data, pdr->auxiliary_name_data_size);
	if (rc) {
		return rc;
	}

	for (i = 0; i < pdr->name_string_count; i++) {
		void *loc = NULL;
		pldm_msgbuf_span_string_utf16(buf, &loc, NULL);
		pdr->names[i].name = loc;
	}

	for (i = 0; i < pdr->name_string_count; i++) {
		void *loc = NULL;
		pldm_msgbuf_span_string_ascii(buf, &loc, NULL);
		pdr->names[i].tag = loc;
	}

	return pldm_msgbuf_complete_consumed(buf);
}

LIBPLDM_ABI_STABLE
int decode_pldm_platform_cper_event(const void *event_data,
				    size_t event_data_length,
				    struct pldm_platform_cper_event *cper_event,
				    size_t cper_event_length)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (!cper_event || !event_data) {
		return -EINVAL;
	}

	if (cper_event_length < sizeof(*cper_event)) {
		return -EINVAL;
	}

	rc = pldm_msgbuf_init_errno(buf, PLDM_PLATFORM_CPER_EVENT_MIN_LENGTH,
				    event_data, event_data_length);
	if (rc) {
		return rc;
	}

	pldm_msgbuf_extract(buf, cper_event->format_version);
	rc = pldm_msgbuf_extract(buf, cper_event->format_type);
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}
	if (cper_event->format_type != PLDM_PLATFORM_CPER_EVENT_WITH_HEADER &&
	    cper_event->format_type !=
		    PLDM_PLATFORM_CPER_EVENT_WITHOUT_HEADER) {
		return pldm_msgbuf_discard(buf, -EPROTO);
	}

	rc = pldm_msgbuf_extract(buf, cper_event->event_data_length);
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}

	if (cper_event->event_data_length >
	    (cper_event_length - sizeof(*cper_event))) {
		return pldm_msgbuf_discard(buf, -EOVERFLOW);
	}

	rc = pldm_msgbuf_extract_array_uint8(
		buf, cper_event->event_data_length, cper_event->event_data,
		cper_event_length - sizeof(*cper_event));
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}

	return pldm_msgbuf_complete_consumed(buf);
}

LIBPLDM_ABI_STABLE
uint8_t *
pldm_platform_cper_event_event_data(struct pldm_platform_cper_event *event)
{
	return event->event_data;
}

LIBPLDM_ABI_TESTING
int decode_pldm_platform_file_descriptor_pdr(
	const void *data, size_t data_length,
	struct pldm_platform_file_descriptor_pdr *pdr)
{
	PLDM_MSGBUF_DEFINE_P(buf);
	int rc;

	if (!data || !pdr) {
		return -EINVAL;
	}

	rc = pldm_msgbuf_init_errno(buf,
				    PLDM_PDR_FILE_DESCRIPTOR_PDR_MIN_LENGTH,
				    data, data_length);
	if (rc) {
		return rc;
	}

	rc = pldm_msgbuf_extract_value_pdr_hdr(
		buf, &pdr->hdr, PLDM_PDR_FILE_DESCRIPTOR_PDR_MIN_LENGTH,
		data_length);
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}

	pldm_msgbuf_extract(buf, pdr->terminus_handle);
	pldm_msgbuf_extract(buf, pdr->file_identifier);
	pldm_msgbuf_extract(buf, pdr->container.entity_type);
	pldm_msgbuf_extract(buf, pdr->container.entity_instance_num);
	pldm_msgbuf_extract(buf, pdr->container.entity_container_id);
	pldm_msgbuf_extract(buf, pdr->superior_directory_file_identifier);
	pldm_msgbuf_extract(buf, pdr->file_classification);
	pldm_msgbuf_extract(buf, pdr->oem_file_classification);
	pldm_msgbuf_extract(buf, pdr->file_capabilities.value);
	pldm_msgbuf_extract(buf, pdr->file_version.alpha);
	pldm_msgbuf_extract(buf, pdr->file_version.update);
	pldm_msgbuf_extract(buf, pdr->file_version.minor);
	pldm_msgbuf_extract(buf, pdr->file_version.major);
	pldm_msgbuf_extract(buf, pdr->file_maximum_size);
	pldm_msgbuf_extract(buf, pdr->file_maximum_file_descriptor_count);
	rc = pldm_msgbuf_extract_uint8_to_size(buf, pdr->file_name.length);
	if (rc) {
		return pldm_msgbuf_discard(buf, rc);
	}

	pldm_msgbuf_span_required(buf, pdr->file_name.length,
				  (void **)&pdr->file_name.ptr);

	pdr->oem_file_classification_name.length = 0;

	if (pdr->oem_file_classification) {
		rc = pldm_msgbuf_extract_uint8_to_size(
			buf, pdr->oem_file_classification_name.length);
		if (rc) {
			return pldm_msgbuf_discard(buf, rc);
		}

		pldm_msgbuf_span_required(
			buf, pdr->oem_file_classification_name.length,
			(void **)&pdr->oem_file_classification_name.ptr);
	}

	return pldm_msgbuf_complete_consumed(buf);
}
