#include "bios_table.h"
#include "base.h"
#include "bios.h"
#include "utils.h"
#include <assert.h>
#include <endian.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#define POINTER_CHECK(pointer)                                                 \
	do {                                                                   \
		if ((pointer) == NULL)                                         \
			return PLDM_ERROR_INVALID_DATA;                        \
	} while (0)

#define ATTR_TYPE_EXPECT(type, expected)                                       \
	do {                                                                   \
		if ((type) != (expected) && (type) != ((expected) | 0x80))     \
			return PLDM_ERROR_INVALID_DATA;                        \
	} while (0)

#define BUFFER_SIZE_EXPECT(current_size, expected_size)                        \
	do {                                                                   \
		if ((current_size) < (expected_size))                          \
			return PLDM_ERROR_INVALID_LENGTH;                      \
	} while (0)

#define MEMBER_SIZE(type, member) sizeof(((struct type *)0)->member)

static void set_errmsg(const char **errmsg, const char *msg)
{
	if (errmsg != NULL) {
		*errmsg = msg;
	}
}

static int get_bios_string_handle(uint16_t *val)
{
	static uint16_t handle = 0;
	assert(handle != UINT16_MAX);
	if (handle == UINT16_MAX) {
		return PLDM_ERROR_INVALID_DATA;
	}

	*val = handle++;
	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
size_t pldm_bios_table_string_entry_encode_length(uint16_t string_length)
{
	return sizeof(struct pldm_bios_string_table_entry) -
	       MEMBER_SIZE(pldm_bios_string_table_entry, name) + string_length;
}

LIBPLDM_ABI_STABLE
int pldm_bios_table_string_entry_encode_check(void *entry, size_t entry_length,
					      const char *str,
					      uint16_t str_length)
{
	if (str_length == 0) {
		return PLDM_ERROR_INVALID_DATA;
	}
	POINTER_CHECK(entry);
	POINTER_CHECK(str);
	size_t length = pldm_bios_table_string_entry_encode_length(str_length);
	BUFFER_SIZE_EXPECT(entry_length, length);
	struct pldm_bios_string_table_entry *string_entry = entry;
	uint16_t handle;
	int rc = get_bios_string_handle(&handle);
	if (rc != PLDM_SUCCESS) {
		return rc;
	}
	string_entry->string_handle = htole16(handle);
	string_entry->string_length = htole16(str_length);
	memcpy(string_entry->name, str, str_length);
	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
uint16_t pldm_bios_table_string_entry_decode_handle(
	const struct pldm_bios_string_table_entry *entry)
{
	return le16toh(entry->string_handle);
}

LIBPLDM_ABI_STABLE
uint16_t pldm_bios_table_string_entry_decode_string_length(
	const struct pldm_bios_string_table_entry *entry)
{
	return le16toh(entry->string_length);
}

LIBPLDM_ABI_STABLE
int pldm_bios_table_string_entry_decode_string_check(
	const struct pldm_bios_string_table_entry *entry, char *buffer,
	size_t size)
{
	POINTER_CHECK(entry);
	POINTER_CHECK(buffer);
	if (size == 0) {
		return PLDM_ERROR_INVALID_LENGTH;
	}
	size_t length =
		pldm_bios_table_string_entry_decode_string_length(entry);
	length = length < (size - 1) ? length : (size - 1);
	memcpy(buffer, entry->name, length);
	buffer[length] = 0;
	return PLDM_SUCCESS;
}

static ssize_t string_table_entry_length(const void *table_entry)
{
	const struct pldm_bios_string_table_entry *entry = table_entry;
	size_t len = sizeof(*entry) - sizeof(entry->name) +
		     pldm_bios_table_string_entry_decode_string_length(entry);
	if (len > SSIZE_MAX) {
		return -1;
	}
	return (ssize_t)len;
}

static int get_bios_attr_handle(uint16_t *val)
{
	static uint16_t handle = 0;
	assert(handle != UINT16_MAX);
	if (handle == UINT16_MAX) {
		return PLDM_ERROR_INVALID_DATA;
	}

	*val = handle++;
	return PLDM_SUCCESS;
}

static int attr_table_entry_encode_header(void *entry, size_t length,
					  uint8_t attr_type,
					  uint16_t string_handle)
{
	struct pldm_bios_attr_table_entry *attr_entry = entry;

	assert(sizeof(*attr_entry) <= length);
	if (sizeof(*attr_entry) > length) {
		return PLDM_ERROR_INVALID_LENGTH;
	}

	uint16_t handle;
	int rc = get_bios_attr_handle(&handle);
	if (rc != PLDM_SUCCESS) {
		return rc;
	}

	attr_entry->attr_handle = htole16(handle);
	attr_entry->attr_type = attr_type;
	attr_entry->string_handle = htole16(string_handle);

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
uint16_t pldm_bios_table_attr_entry_decode_attribute_handle(
	const struct pldm_bios_attr_table_entry *entry)
{
	return le16toh(entry->attr_handle);
}

LIBPLDM_ABI_STABLE
uint8_t pldm_bios_table_attr_entry_decode_attribute_type(
	const struct pldm_bios_attr_table_entry *entry)
{
	return entry->attr_type;
}

LIBPLDM_ABI_STABLE
uint16_t pldm_bios_table_attr_entry_decode_string_handle(
	const struct pldm_bios_attr_table_entry *entry)
{
	return le16toh(entry->string_handle);
}

LIBPLDM_ABI_STABLE
size_t pldm_bios_table_attr_entry_enum_encode_length(uint8_t pv_num,
						     uint8_t def_num)
{
	return sizeof(struct pldm_bios_attr_table_entry) -
	       MEMBER_SIZE(pldm_bios_attr_table_entry, metadata) +
	       sizeof(pv_num) + pv_num * sizeof(uint16_t) + sizeof(def_num) +
	       def_num;
}

LIBPLDM_ABI_STABLE
int pldm_bios_table_attr_entry_enum_encode_check(
	void *entry, size_t entry_length,
	const struct pldm_bios_table_attr_entry_enum_info *info)
{
	POINTER_CHECK(entry);
	POINTER_CHECK(info);
	size_t length = pldm_bios_table_attr_entry_enum_encode_length(
		info->pv_num, info->def_num);
	BUFFER_SIZE_EXPECT(entry_length, length);
	uint8_t attr_type = info->read_only ? PLDM_BIOS_ENUMERATION_READ_ONLY :
					      PLDM_BIOS_ENUMERATION;
	int rc = attr_table_entry_encode_header(entry, entry_length, attr_type,
						info->name_handle);
	if (rc != PLDM_SUCCESS) {
		return rc;
	}
	struct pldm_bios_attr_table_entry *attr_entry = entry;
	attr_entry->metadata[0] = info->pv_num;
	uint16_t *pv_hdls =
		(uint16_t *)(attr_entry->metadata + 1 /* sizeof(pv num) */);
	size_t i;
	for (i = 0; i < info->pv_num; i++) {
		pv_hdls[i] = htole16(info->pv_handle[i]);
	}
	attr_entry->metadata[1 + info->pv_num * sizeof(uint16_t)] =
		info->def_num;
	memcpy(attr_entry->metadata + 1 /* sizeof(pv num) */ +
		       info->pv_num * sizeof(uint16_t) + 1 /* sizeof(def num)*/,
	       info->def_index, info->def_num);
	return PLDM_SUCCESS;
}

#define ATTR_TYPE_EXPECT(type, expected)                                       \
	do {                                                                   \
		if ((type) != (expected) && (type) != ((expected) | 0x80))     \
			return PLDM_ERROR_INVALID_DATA;                        \
	} while (0)

LIBPLDM_ABI_STABLE
int pldm_bios_table_attr_entry_enum_decode_pv_num_check(
	const struct pldm_bios_attr_table_entry *entry, uint8_t *pv_num)
{
	POINTER_CHECK(entry);
	POINTER_CHECK(pv_num);
	ATTR_TYPE_EXPECT(entry->attr_type, PLDM_BIOS_ENUMERATION);
	*pv_num = entry->metadata[0];
	return PLDM_SUCCESS;
}

static uint8_t pldm_bios_table_attr_entry_enum_decode_def_num(
	const struct pldm_bios_attr_table_entry *entry)
{
	uint8_t pv_num = entry->metadata[0];
	return entry->metadata[sizeof(uint8_t) /* pv_num */ +
			       sizeof(uint16_t) * pv_num];
}

LIBPLDM_ABI_STABLE
int pldm_bios_table_attr_entry_enum_decode_def_num_check(
	const struct pldm_bios_attr_table_entry *entry, uint8_t *def_num)
{
	POINTER_CHECK(entry);
	POINTER_CHECK(def_num);
	ATTR_TYPE_EXPECT(entry->attr_type, PLDM_BIOS_ENUMERATION);
	*def_num = pldm_bios_table_attr_entry_enum_decode_def_num(entry);
	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int pldm_bios_table_attr_entry_enum_decode_pv_hdls_check(
	const struct pldm_bios_attr_table_entry *entry, uint16_t *pv_hdls,
	uint8_t pv_num)
{
	POINTER_CHECK(entry);
	POINTER_CHECK(pv_hdls);
	ATTR_TYPE_EXPECT(entry->attr_type, PLDM_BIOS_ENUMERATION);
	uint8_t num = entry->metadata[0];
	num = num < pv_num ? num : pv_num;
	size_t i;
	for (i = 0; i < num; i++) {
		uint16_t *hdl = (uint16_t *)(entry->metadata + sizeof(uint8_t) +
					     i * sizeof(uint16_t));
		pv_hdls[i] = le16toh(*hdl);
	}
	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
uint8_t pldm_bios_table_attr_entry_enum_decode_def_indices(
	const struct pldm_bios_attr_table_entry *entry, uint8_t *def_indices,
	uint8_t def_num)
{
	uint8_t num = pldm_bios_table_attr_entry_enum_decode_def_num(entry);
	num = num < def_num ? num : def_num;
	uint8_t pv_num = entry->metadata[0];
	const uint8_t *p = entry->metadata +
			   sizeof(uint8_t) /* number of possible values*/
			   + pv_num * sizeof(uint16_t) /* possible values */
			   + sizeof(uint8_t); /* number of default values */
	memcpy(def_indices, p, num);
	return num;
}

/** @brief Get length of an enum attribute entry
 */
static ssize_t attr_table_entry_length_enum(const void *arg)
{
	const struct pldm_bios_attr_table_entry *entry = arg;
	uint8_t pv_num = entry->metadata[0];
	uint8_t def_num = pldm_bios_table_attr_entry_enum_decode_def_num(entry);
	size_t len =
		pldm_bios_table_attr_entry_enum_encode_length(pv_num, def_num);
	if (len > SSIZE_MAX) {
		return -1;
	}
	return (ssize_t)len;
}

struct attr_table_string_entry_fields {
	uint8_t string_type;
	uint16_t min_length;
	uint16_t max_length;
	uint16_t def_length;
	uint8_t def_string[1];
} __attribute__((packed));

LIBPLDM_ABI_STABLE
size_t pldm_bios_table_attr_entry_string_encode_length(uint16_t def_str_len)
{
	return sizeof(struct pldm_bios_attr_table_entry) -
	       MEMBER_SIZE(pldm_bios_attr_table_entry, metadata) +
	       sizeof(struct attr_table_string_entry_fields) -
	       MEMBER_SIZE(attr_table_string_entry_fields, def_string) +
	       def_str_len;
}

#define PLDM_STRING_TYPE_MAX	5
#define PLDM_STRING_TYPE_VENDOR 0xff

LIBPLDM_ABI_STABLE
int pldm_bios_table_attr_entry_string_info_check(
	const struct pldm_bios_table_attr_entry_string_info *info,
	const char **errmsg)
{
	if (info->min_length > info->max_length) {
		set_errmsg(errmsg, "MinimumStingLength should not be greater "
				   "than MaximumStringLength");
		return PLDM_ERROR_INVALID_DATA;
	}
	if (info->min_length == info->max_length &&
	    info->def_length != info->min_length) {
		set_errmsg(errmsg, "Wrong DefaultStringLength");
		return PLDM_ERROR_INVALID_DATA;
	}
	if (info->def_length > info->max_length ||
	    info->def_length < info->min_length) {
		set_errmsg(errmsg, "Wrong DefaultStringLength");
		return PLDM_ERROR_INVALID_DATA;
	}
	if (info->string_type > PLDM_STRING_TYPE_MAX &&
	    info->string_type != PLDM_STRING_TYPE_VENDOR) {
		set_errmsg(errmsg, "Wrong StringType");
		return PLDM_ERROR_INVALID_DATA;
	}
	if (info->def_string && info->def_length != strlen(info->def_string)) {
		set_errmsg(errmsg, "Length of DefaultString should be equal to "
				   "DefaultStringLength");
		return PLDM_ERROR_INVALID_DATA;
	}

	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int pldm_bios_table_attr_entry_string_encode_check(
	void *entry, size_t entry_length,
	const struct pldm_bios_table_attr_entry_string_info *info)
{
	POINTER_CHECK(entry);
	POINTER_CHECK(info);
	size_t length = pldm_bios_table_attr_entry_string_encode_length(
		info->def_length);
	BUFFER_SIZE_EXPECT(entry_length, length);
	if (pldm_bios_table_attr_entry_string_info_check(info, NULL) !=
	    PLDM_SUCCESS) {
		return PLDM_ERROR_INVALID_DATA;
	}
	uint8_t attr_type = info->read_only ? PLDM_BIOS_STRING_READ_ONLY :
					      PLDM_BIOS_STRING;
	int rc = attr_table_entry_encode_header(entry, entry_length, attr_type,
						info->name_handle);
	if (rc != PLDM_SUCCESS) {
		return rc;
	}
	struct pldm_bios_attr_table_entry *attr_entry = entry;
	struct attr_table_string_entry_fields *attr_fields =
		(struct attr_table_string_entry_fields *)attr_entry->metadata;
	attr_fields->string_type = info->string_type;
	attr_fields->min_length = htole16(info->min_length);
	attr_fields->max_length = htole16(info->max_length);
	attr_fields->def_length = htole16(info->def_length);
	if (info->def_length != 0 && info->def_string != NULL) {
		memcpy(attr_fields->def_string, info->def_string,
		       info->def_length);
	}
	return PLDM_SUCCESS;
}

static uint16_t pldm_bios_table_attr_entry_string_decode_def_string_length(
	const struct pldm_bios_attr_table_entry *entry)
{
	struct attr_table_string_entry_fields *fields =
		(struct attr_table_string_entry_fields *)entry->metadata;
	return le16toh(fields->def_length);
}

LIBPLDM_ABI_STABLE
int pldm_bios_table_attr_entry_string_decode_def_string_length_check(
	const struct pldm_bios_attr_table_entry *entry,
	uint16_t *def_string_length)
{
	POINTER_CHECK(entry);
	POINTER_CHECK(def_string_length);
	ATTR_TYPE_EXPECT(entry->attr_type, PLDM_BIOS_STRING);
	*def_string_length =
		pldm_bios_table_attr_entry_string_decode_def_string_length(
			entry);
	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
uint8_t pldm_bios_table_attr_entry_string_decode_string_type(
	const struct pldm_bios_attr_table_entry *entry)
{
	struct attr_table_string_entry_fields *fields =
		(struct attr_table_string_entry_fields *)entry->metadata;
	return fields->string_type;
}

LIBPLDM_ABI_STABLE
uint16_t pldm_bios_table_attr_entry_string_decode_max_length(
	const struct pldm_bios_attr_table_entry *entry)
{
	struct attr_table_string_entry_fields *fields =
		(struct attr_table_string_entry_fields *)entry->metadata;
	return le16toh(fields->max_length);
}

LIBPLDM_ABI_STABLE
uint16_t pldm_bios_table_attr_entry_string_decode_min_length(
	const struct pldm_bios_attr_table_entry *entry)
{
	struct attr_table_string_entry_fields *fields =
		(struct attr_table_string_entry_fields *)entry->metadata;
	return le16toh(fields->min_length);
}

LIBPLDM_ABI_STABLE
uint16_t pldm_bios_table_attr_entry_string_decode_def_string(
	const struct pldm_bios_attr_table_entry *entry, char *buffer,
	size_t size)
{
	uint16_t length =
		pldm_bios_table_attr_entry_string_decode_def_string_length(
			entry);
	length = length < (size - 1) ? length : (size - 1);
	struct attr_table_string_entry_fields *fields =
		(struct attr_table_string_entry_fields *)entry->metadata;
	memcpy(buffer, fields->def_string, length);
	buffer[length] = 0;
	return length;
}

/** @brief Get length of a string attribute entry
 */
static ssize_t attr_table_entry_length_string(const void *entry)
{
	uint16_t def_str_len =
		pldm_bios_table_attr_entry_string_decode_def_string_length(
			entry);
	size_t len =
		pldm_bios_table_attr_entry_string_encode_length(def_str_len);
	if (len > SSIZE_MAX) {
		return -1;
	}
	return (ssize_t)len;
}

struct attr_table_integer_entry_fields {
	uint64_t lower_bound;
	uint64_t upper_bound;
	uint32_t scalar_increment;
	uint64_t default_value;
} __attribute__((packed));

LIBPLDM_ABI_STABLE
size_t pldm_bios_table_attr_entry_integer_encode_length(void)
{
	return sizeof(struct pldm_bios_attr_table_entry) - 1 +
	       sizeof(struct attr_table_integer_entry_fields);
}

LIBPLDM_ABI_STABLE
int pldm_bios_table_attr_entry_integer_info_check(
	const struct pldm_bios_table_attr_entry_integer_info *info,
	const char **errmsg)
{
	if (info->lower_bound == info->upper_bound) {
		if (info->default_value != info->lower_bound) {
			set_errmsg(errmsg, "Wrong DefaultValue");
			return PLDM_ERROR_INVALID_DATA;
		}
		if (info->scalar_increment != 0) {
			set_errmsg(errmsg, "Wrong ScalarIncrement");
			return PLDM_ERROR_INVALID_DATA;
		}
		return PLDM_SUCCESS;
	}
	if (info->lower_bound > info->upper_bound) {
		set_errmsg(errmsg,
			   "LowerBound should not be greater than UpperBound");
		return PLDM_ERROR_INVALID_DATA;
	}
	if (info->default_value > info->upper_bound ||
	    info->default_value < info->lower_bound) {
		set_errmsg(errmsg, "Wrong DefaultValue");
		return PLDM_ERROR_INVALID_DATA;
	}
	if (info->scalar_increment == 0) {
		set_errmsg(errmsg, "ScalarIncrement should not be zero when "
				   "lower_bound != upper_bound");
		return PLDM_ERROR_INVALID_DATA;
	}
	if ((info->default_value - info->lower_bound) %
		    info->scalar_increment !=
	    0) {
		set_errmsg(errmsg, "Wrong DefaultValue or ScalarIncrement");
		return PLDM_ERROR_INVALID_DATA;
	}
	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
int pldm_bios_table_attr_entry_integer_encode_check(
	void *entry, size_t entry_length,
	const struct pldm_bios_table_attr_entry_integer_info *info)
{
	POINTER_CHECK(entry);
	POINTER_CHECK(info);
	size_t length = pldm_bios_table_attr_entry_integer_encode_length();
	BUFFER_SIZE_EXPECT(entry_length, length);
	if (pldm_bios_table_attr_entry_integer_info_check(info, NULL) !=
	    PLDM_SUCCESS) {
		return PLDM_ERROR_INVALID_DATA;
	}
	uint8_t attr_type = info->read_only ? PLDM_BIOS_INTEGER_READ_ONLY :
					      PLDM_BIOS_INTEGER;
	int rc = attr_table_entry_encode_header(entry, entry_length, attr_type,
						info->name_handle);
	if (rc != PLDM_SUCCESS) {
		return rc;
	}
	struct pldm_bios_attr_table_entry *attr_entry = entry;
	struct attr_table_integer_entry_fields *attr_fields =
		(struct attr_table_integer_entry_fields *)attr_entry->metadata;
	attr_fields->lower_bound = htole64(info->lower_bound);
	attr_fields->upper_bound = htole64(info->upper_bound);
	attr_fields->scalar_increment = htole32(info->scalar_increment);
	attr_fields->default_value = htole64(info->default_value);
	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
void pldm_bios_table_attr_entry_integer_decode(
	const struct pldm_bios_attr_table_entry *entry, uint64_t *lower,
	uint64_t *upper, uint32_t *scalar, uint64_t *def)
{
	struct attr_table_integer_entry_fields *fields =
		(struct attr_table_integer_entry_fields *)entry->metadata;
	*lower = le64toh(fields->lower_bound);
	*upper = le64toh(fields->upper_bound);
	*scalar = le32toh(fields->scalar_increment);
	*def = le64toh(fields->default_value);
}

static ssize_t attr_table_entry_length_integer(const void *entry)
{
	(void)entry;
	size_t len = pldm_bios_table_attr_entry_integer_encode_length();
	if (len > SSIZE_MAX) {
		return -1;
	}
	return (ssize_t)len;
}

struct table_entry_length {
	uint8_t attr_type;
	ssize_t (*entry_length_handler)(const void *);
};

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

static const struct table_entry_length *
find_table_entry_length_by_type(uint8_t attr_type,
				const struct table_entry_length *handlers,
				size_t count)
{
	size_t i;
	for (i = 0; i < count; i++) {
		if (attr_type == handlers[i].attr_type) {
			return &handlers[i];
		}
	}
	return NULL;
}

static const struct table_entry_length attr_table_entries[] = {
	{ .attr_type = PLDM_BIOS_ENUMERATION,
	  .entry_length_handler = attr_table_entry_length_enum },
	{ .attr_type = PLDM_BIOS_ENUMERATION_READ_ONLY,
	  .entry_length_handler = attr_table_entry_length_enum },
	{ .attr_type = PLDM_BIOS_STRING,
	  .entry_length_handler = attr_table_entry_length_string },
	{ .attr_type = PLDM_BIOS_STRING_READ_ONLY,
	  .entry_length_handler = attr_table_entry_length_string },
	{ .attr_type = PLDM_BIOS_INTEGER,
	  .entry_length_handler = attr_table_entry_length_integer },
	{ .attr_type = PLDM_BIOS_INTEGER_READ_ONLY,
	  .entry_length_handler = attr_table_entry_length_integer },
};

static ssize_t attr_table_entry_length(const void *table_entry)
{
	const struct pldm_bios_attr_table_entry *entry = table_entry;
	const struct table_entry_length *attr_table_entry =
		find_table_entry_length_by_type(entry->attr_type,
						attr_table_entries,
						ARRAY_SIZE(attr_table_entries));
	assert(attr_table_entry != NULL);
	if (!attr_table_entry) {
		return -1;
	}
	assert(attr_table_entry->entry_length_handler != NULL);
	if (!attr_table_entry->entry_length_handler) {
		return -1;
	}

	return attr_table_entry->entry_length_handler(entry);
}

LIBPLDM_ABI_STABLE
uint16_t pldm_bios_table_attr_value_entry_decode_attribute_handle(
	const struct pldm_bios_attr_val_table_entry *entry)
{
	return le16toh(entry->attr_handle);
}

LIBPLDM_ABI_STABLE
uint8_t pldm_bios_table_attr_value_entry_decode_attribute_type(
	const struct pldm_bios_attr_val_table_entry *entry)
{
	return entry->attr_type;
}

LIBPLDM_ABI_STABLE
size_t pldm_bios_table_attr_value_entry_encode_enum_length(uint8_t count)
{
	return sizeof(struct pldm_bios_attr_val_table_entry) - 1 +
	       sizeof(count) + count;
}

LIBPLDM_ABI_STABLE
uint8_t pldm_bios_table_attr_value_entry_enum_decode_number(
	const struct pldm_bios_attr_val_table_entry *entry)
{
	return entry->value[0];
}

LIBPLDM_ABI_STABLE
uint8_t pldm_bios_table_attr_value_entry_enum_decode_handles(
	const struct pldm_bios_attr_val_table_entry *entry, uint8_t *handles,
	uint8_t number)
{
	uint8_t curr_num =
		pldm_bios_table_attr_value_entry_enum_decode_number(entry);
	number = number < curr_num ? number : curr_num;
	memcpy(handles, &entry->value[1], number);

	return number;
}

LIBPLDM_ABI_STABLE
int pldm_bios_table_attr_value_entry_encode_enum_check(
	void *entry, size_t entry_length, uint16_t attr_handle,
	uint8_t attr_type, uint8_t count, const uint8_t *handles)
{
	POINTER_CHECK(entry);
	POINTER_CHECK(handles);
	if (count != 0 && handles == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}
	ATTR_TYPE_EXPECT(attr_type, PLDM_BIOS_ENUMERATION);
	size_t length =
		pldm_bios_table_attr_value_entry_encode_enum_length(count);
	BUFFER_SIZE_EXPECT(entry_length, length);
	struct pldm_bios_attr_val_table_entry *table_entry = entry;
	table_entry->attr_handle = htole16(attr_handle);
	table_entry->attr_type = attr_type;
	table_entry->value[0] = count;
	if (count != 0) {
		memcpy(&table_entry->value[1], handles, count);
	}
	return PLDM_SUCCESS;
}

static ssize_t attr_value_table_entry_length_enum(const void *entry)
{
	uint8_t number =
		pldm_bios_table_attr_value_entry_enum_decode_number(entry);
	size_t len =
		pldm_bios_table_attr_value_entry_encode_enum_length(number);
	if (len > SSIZE_MAX) {
		return -1;
	}
	return (ssize_t)len;
}

LIBPLDM_ABI_STABLE
size_t
pldm_bios_table_attr_value_entry_encode_string_length(uint16_t string_length)
{
	return sizeof(struct pldm_bios_attr_val_table_entry) - 1 +
	       sizeof(string_length) + string_length;
}

LIBPLDM_ABI_DEPRECATED
void pldm_bios_table_attr_value_entry_encode_string(
	void *entry, size_t entry_length, uint16_t attr_handle,
	uint8_t attr_type, uint16_t str_length, const char *str)
{
	int rc = pldm_bios_table_attr_value_entry_encode_string_check(
		entry, entry_length, attr_handle, attr_type, str_length, str);
	(void)rc;
	assert(rc == PLDM_SUCCESS);
}

LIBPLDM_ABI_STABLE
uint16_t pldm_bios_table_attr_value_entry_string_decode_length(
	const struct pldm_bios_attr_val_table_entry *entry)
{
	uint16_t str_length = 0;
	memcpy(&str_length, entry->value, sizeof(str_length));
	return le16toh(str_length);
}

LIBPLDM_ABI_STABLE
void pldm_bios_table_attr_value_entry_string_decode_string(
	const struct pldm_bios_attr_val_table_entry *entry,
	struct variable_field *current_string)
{
	current_string->length =
		pldm_bios_table_attr_value_entry_string_decode_length(entry);
	current_string->ptr =
		entry->value + sizeof(uint16_t); // sizeof(CurrentStringLength)
}

LIBPLDM_ABI_STABLE
int pldm_bios_table_attr_value_entry_encode_string_check(
	void *entry, size_t entry_length, uint16_t attr_handle,
	uint8_t attr_type, uint16_t str_length, const char *str)
{
	POINTER_CHECK(entry);
	if (str_length != 0 && str == NULL) {
		return PLDM_ERROR_INVALID_DATA;
	}
	ATTR_TYPE_EXPECT(attr_type, PLDM_BIOS_STRING);
	size_t length = pldm_bios_table_attr_value_entry_encode_string_length(
		str_length);
	BUFFER_SIZE_EXPECT(entry_length, length);
	struct pldm_bios_attr_val_table_entry *table_entry = entry;
	table_entry->attr_handle = htole16(attr_handle);
	table_entry->attr_type = attr_type;
	if (str_length != 0) {
		memcpy(table_entry->value + sizeof(str_length), str,
		       str_length);
	}
	str_length = htole16(str_length);
	memcpy(table_entry->value, &str_length, sizeof(str_length));
	return PLDM_SUCCESS;
}

static ssize_t attr_value_table_entry_length_string(const void *entry)
{
	uint16_t str_length =
		pldm_bios_table_attr_value_entry_string_decode_length(entry);
	size_t len = pldm_bios_table_attr_value_entry_encode_string_length(
		str_length);
	if (len > SSIZE_MAX) {
		return -1;
	}
	return (ssize_t)len;
}

LIBPLDM_ABI_STABLE
size_t pldm_bios_table_attr_value_entry_encode_integer_length(void)
{
	return sizeof(struct pldm_bios_attr_val_table_entry) - 1 +
	       sizeof(uint64_t);
}

LIBPLDM_ABI_DEPRECATED
void pldm_bios_table_attr_value_entry_encode_integer(void *entry,
						     size_t entry_length,
						     uint16_t attr_handle,
						     uint8_t attr_type,
						     uint64_t cv)
{
	int rc = pldm_bios_table_attr_value_entry_encode_integer_check(
		entry, entry_length, attr_handle, attr_type, cv);
	(void)rc;
	assert(rc == PLDM_SUCCESS);
}

LIBPLDM_ABI_STABLE
int pldm_bios_table_attr_value_entry_encode_integer_check(void *entry,
							  size_t entry_length,
							  uint16_t attr_handle,
							  uint8_t attr_type,
							  uint64_t cv)
{
	POINTER_CHECK(entry);
	size_t length =
		pldm_bios_table_attr_value_entry_encode_integer_length();
	ATTR_TYPE_EXPECT(attr_type, PLDM_BIOS_INTEGER);
	BUFFER_SIZE_EXPECT(entry_length, length);
	struct pldm_bios_attr_val_table_entry *table_entry = entry;
	table_entry->attr_handle = htole16(attr_handle);
	table_entry->attr_type = attr_type;
	cv = htole64(cv);
	memcpy(table_entry->value, &cv, sizeof(uint64_t));
	return PLDM_SUCCESS;
}

LIBPLDM_ABI_STABLE
uint64_t pldm_bios_table_attr_value_entry_integer_decode_cv(
	const struct pldm_bios_attr_val_table_entry *entry)
{
	uint64_t cv = 0;
	memcpy(&cv, entry->value, sizeof(cv));
	cv = le64toh(cv);
	return cv;
}

static ssize_t attr_value_table_entry_length_integer(const void *entry)
{
	(void)entry;
	size_t len = pldm_bios_table_attr_value_entry_encode_integer_length();
	if (len > SSIZE_MAX) {
		return -1;
	}
	return (ssize_t)len;
}

static const struct table_entry_length attr_value_table_entries[] = {
	{ .attr_type = PLDM_BIOS_ENUMERATION,
	  .entry_length_handler = attr_value_table_entry_length_enum },
	{ .attr_type = PLDM_BIOS_ENUMERATION_READ_ONLY,
	  .entry_length_handler = attr_value_table_entry_length_enum },
	{ .attr_type = PLDM_BIOS_STRING,
	  .entry_length_handler = attr_value_table_entry_length_string },
	{ .attr_type = PLDM_BIOS_STRING_READ_ONLY,
	  .entry_length_handler = attr_value_table_entry_length_string },
	{ .attr_type = PLDM_BIOS_INTEGER,
	  .entry_length_handler = attr_value_table_entry_length_integer },
	{ .attr_type = PLDM_BIOS_INTEGER_READ_ONLY,
	  .entry_length_handler = attr_value_table_entry_length_integer },
};

static ssize_t attr_value_table_entry_length(const void *table_entry)
{
	const struct pldm_bios_attr_val_table_entry *entry = table_entry;
	const struct table_entry_length *entry_length =
		find_table_entry_length_by_type(
			entry->attr_type, attr_value_table_entries,
			ARRAY_SIZE(attr_value_table_entries));
	assert(entry_length != NULL);
	if (!entry_length) {
		return -1;
	}
	assert(entry_length->entry_length_handler != NULL);
	if (!entry_length->entry_length_handler) {
		return -1;
	}

	return entry_length->entry_length_handler(entry);
}

LIBPLDM_ABI_STABLE
size_t pldm_bios_table_attr_value_entry_length(
	const struct pldm_bios_attr_val_table_entry *entry)
{
	return attr_value_table_entry_length(entry);
}

LIBPLDM_ABI_STABLE
uint16_t pldm_bios_table_attr_value_entry_decode_handle(
	const struct pldm_bios_attr_val_table_entry *entry)
{
	return le16toh(entry->attr_handle);
}

static size_t pad_size_get(size_t size_without_pad)
{
	return ((size_without_pad % 4) ? (4 - size_without_pad % 4) : 0);
}

static uint8_t *pad_append(uint8_t *table_end, size_t pad_size)
{
	while (pad_size--) {
		*table_end++ = 0;
	}

	return table_end;
}

static uint8_t *checksum_append(uint8_t *table_end, uint32_t checksum)
{
	checksum = htole32(checksum);
	memcpy(table_end, &checksum, sizeof(checksum));

	return table_end + sizeof(checksum);
}

LIBPLDM_ABI_STABLE
size_t pldm_bios_table_pad_checksum_size(size_t size_without_pad)
{
	size_t size = pad_size_get(size_without_pad) +
		      sizeof(uint32_t) /*sizeof(checksum)*/;
	return size;
}

LIBPLDM_ABI_DEPRECATED
size_t pldm_bios_table_append_pad_checksum(void *table, size_t capacity,
					   size_t size)
{
	int rc = pldm_bios_table_append_pad_checksum_check(table, capacity,
							   &size);
	(void)rc;
	assert(rc == PLDM_SUCCESS);
	return size;
}

LIBPLDM_ABI_STABLE
int pldm_bios_table_append_pad_checksum_check(void *table, size_t capacity,
					      size_t *size)
{
	if (!table || !size) {
		return PLDM_ERROR_INVALID_DATA;
	}

	size_t pad_checksum_size = pldm_bios_table_pad_checksum_size(*size);
	size_t total_length = *size + pad_checksum_size;
	if (capacity < total_length) {
		return PLDM_ERROR_INVALID_LENGTH;
	}

	uint8_t *table_end = (uint8_t *)table + *size;
	size_t pad_size = pad_size_get(*size);
	table_end = pad_append(table_end, pad_size);

	uint32_t checksum = crc32(table, *size + pad_size);
	checksum_append(table_end, checksum);
	*size = total_length;

	return PLDM_SUCCESS;
}

struct pldm_bios_table_iter {
	const uint8_t *table_data;
	size_t table_len;
	size_t current_pos;
	ssize_t (*entry_length_handler)(const void *table_entry);
};

LIBPLDM_ABI_STABLE
struct pldm_bios_table_iter *
pldm_bios_table_iter_create(const void *table, size_t length,
			    enum pldm_bios_table_types type)
{
	struct pldm_bios_table_iter *iter = malloc(sizeof(*iter));
	assert(iter != NULL);
	if (!iter) {
		return NULL;
	}
	iter->table_data = table;
	iter->table_len = length;
	iter->current_pos = 0;
	iter->entry_length_handler = NULL;
	switch (type) {
	case PLDM_BIOS_STRING_TABLE:
		iter->entry_length_handler = string_table_entry_length;
		break;
	case PLDM_BIOS_ATTR_TABLE:
		iter->entry_length_handler = attr_table_entry_length;
		break;
	case PLDM_BIOS_ATTR_VAL_TABLE:
		iter->entry_length_handler = attr_value_table_entry_length;
		break;
	}

	return iter;
}

LIBPLDM_ABI_STABLE
void pldm_bios_table_iter_free(struct pldm_bios_table_iter *iter)
{
	free(iter);
}

#define pad_and_check_max 7
LIBPLDM_ABI_STABLE
bool pldm_bios_table_iter_is_end(const struct pldm_bios_table_iter *iter)
{
	ssize_t len;

	if (iter->table_len - iter->current_pos <= pad_and_check_max) {
		return true;
	}

	len = iter->entry_length_handler(iter->table_data + iter->current_pos);

	return len < 0;
}

LIBPLDM_ABI_STABLE
void pldm_bios_table_iter_next(struct pldm_bios_table_iter *iter)
{
	if (pldm_bios_table_iter_is_end(iter)) {
		return;
	}
	const void *entry = iter->table_data + iter->current_pos;
	ssize_t rc = iter->entry_length_handler(entry);
	/* Prevent bad behaviour by acting as if we've hit the end of the iterator */
	if (rc < 0) {
		return;
	}
	iter->current_pos += rc;
}

LIBPLDM_ABI_STABLE
const void *pldm_bios_table_iter_value(struct pldm_bios_table_iter *iter)
{
	return iter->table_data + iter->current_pos;
}

typedef bool (*equal_handler)(const void *entry, const void *key);

static const void *
pldm_bios_table_entry_find_by_iter(struct pldm_bios_table_iter *iter,
				   const void *key, equal_handler equal)
{
	const void *entry;
	while (!pldm_bios_table_iter_is_end(iter)) {
		entry = pldm_bios_table_iter_value(iter);
		if (equal(entry, key)) {
			return entry;
		}
		pldm_bios_table_iter_next(iter);
	}
	return NULL;
}

static const void *
pldm_bios_table_entry_find_from_table(const void *table, size_t length,
				      enum pldm_bios_table_types type,
				      equal_handler equal, const void *key)
{
	struct pldm_bios_table_iter *iter =
		pldm_bios_table_iter_create(table, length, type);
	const void *entry =
		pldm_bios_table_entry_find_by_iter(iter, key, equal);
	pldm_bios_table_iter_free(iter);
	return entry;
}

static bool string_table_handle_equal(const void *entry, const void *key)
{
	const struct pldm_bios_string_table_entry *string_entry = entry;
	uint16_t handle = *(uint16_t *)key;
	if (pldm_bios_table_string_entry_decode_handle(string_entry) ==
	    handle) {
		return true;
	}
	return false;
}

LIBPLDM_ABI_STABLE
const struct pldm_bios_string_table_entry *
pldm_bios_table_string_find_by_handle(const void *table, size_t length,
				      uint16_t handle)
{
	return pldm_bios_table_entry_find_from_table(table, length,
						     PLDM_BIOS_STRING_TABLE,
						     string_table_handle_equal,
						     &handle);
}

struct string_equal_arg {
	uint16_t str_length;
	const char *str;
};

static bool string_table_string_equal(const void *entry, const void *key)
{
	const struct pldm_bios_string_table_entry *string_entry = entry;
	const struct string_equal_arg *arg = key;
	if (arg->str_length !=
	    pldm_bios_table_string_entry_decode_string_length(string_entry)) {
		return false;
	}
	if (memcmp(string_entry->name, arg->str, arg->str_length) != 0) {
		return false;
	}
	return true;
}

LIBPLDM_ABI_STABLE
const struct pldm_bios_string_table_entry *
pldm_bios_table_string_find_by_string(const void *table, size_t length,
				      const char *str)
{
	uint16_t str_length = strlen(str);
	struct string_equal_arg arg = { str_length, str };
	return pldm_bios_table_entry_find_from_table(table, length,
						     PLDM_BIOS_STRING_TABLE,
						     string_table_string_equal,
						     &arg);
}

static bool attr_table_handle_equal(const void *entry, const void *key)
{
	uint16_t handle = *(uint16_t *)key;
	return pldm_bios_table_attr_entry_decode_attribute_handle(entry) ==
	       handle;
}

LIBPLDM_ABI_STABLE
const struct pldm_bios_attr_table_entry *
pldm_bios_table_attr_find_by_handle(const void *table, size_t length,
				    uint16_t handle)
{
	return pldm_bios_table_entry_find_from_table(table, length,
						     PLDM_BIOS_ATTR_TABLE,
						     attr_table_handle_equal,
						     &handle);
}

static bool attr_table_string_handle_equal(const void *entry, const void *key)
{
	uint16_t handle = *(uint16_t *)key;
	return pldm_bios_table_attr_entry_decode_string_handle(entry) == handle;
}

LIBPLDM_ABI_STABLE
const struct pldm_bios_attr_table_entry *
pldm_bios_table_attr_find_by_string_handle(const void *table, size_t length,
					   uint16_t handle)
{
	return pldm_bios_table_entry_find_from_table(
		table, length, PLDM_BIOS_ATTR_TABLE,
		attr_table_string_handle_equal, &handle);
}

static bool attr_value_table_handle_equal(const void *entry, const void *key)
{
	uint16_t handle = *(uint16_t *)key;
	return pldm_bios_table_attr_value_entry_decode_handle(entry) == handle;
}

LIBPLDM_ABI_STABLE
const struct pldm_bios_attr_val_table_entry *
pldm_bios_table_attr_value_find_by_handle(const void *table, size_t length,
					  uint16_t handle)
{
	return pldm_bios_table_entry_find_from_table(
		table, length, PLDM_BIOS_ATTR_VAL_TABLE,
		attr_value_table_handle_equal, &handle);
}

LIBPLDM_ABI_STABLE
int pldm_bios_table_attr_value_copy_and_update(
	const void *src_table, size_t src_length, void *dest_table,
	size_t *dest_length, const void *entry, size_t entry_length)
{
	struct pldm_bios_table_iter *iter = pldm_bios_table_iter_create(
		src_table, src_length, PLDM_BIOS_ATTR_VAL_TABLE);

	int rc = PLDM_SUCCESS;
	const struct pldm_bios_attr_val_table_entry *tmp;
	const struct pldm_bios_attr_val_table_entry *to_update = entry;
	size_t buffer_length = *dest_length;
	size_t copied_length = 0;
	size_t length = 0;
	while (!pldm_bios_table_iter_is_end(iter)) {
		tmp = pldm_bios_table_iter_attr_value_entry_value(iter);
		length = attr_value_table_entry_length(tmp);

		/* we need the tmp's entry_length here, iter_next will calculate
		 * it too, use current_pos directly to avoid calculating it
		 * twice */
		iter->current_pos += length;
		if (tmp->attr_handle == to_update->attr_handle) {
			if (tmp->attr_type != to_update->attr_type) {
				rc = PLDM_ERROR_INVALID_DATA;
				goto out;
			}
			length = entry_length;
			tmp = entry;
		}
		if (copied_length + length > buffer_length) {
			rc = PLDM_ERROR_INVALID_LENGTH;
			goto out;
		}
		memcpy((uint8_t *)dest_table + copied_length, tmp, length);
		copied_length += length;
	}

	size_t pad_checksum_size =
		pldm_bios_table_pad_checksum_size(copied_length);
	if ((pad_checksum_size + copied_length) > buffer_length) {
		rc = PLDM_ERROR_INVALID_LENGTH;
		goto out;
	}

	*dest_length = pldm_bios_table_append_pad_checksum(
		dest_table, buffer_length, copied_length);
out:
	pldm_bios_table_iter_free(iter);
	return rc;
}

LIBPLDM_ABI_STABLE
bool pldm_bios_table_checksum(const uint8_t *table, size_t size)
{
	if (table == NULL) {
		return false;
	}

	// 12: BIOSStringHandle(uint16) + BIOSStringLength(uint16) +
	//     Variable(4) + checksum(uint32)
	if (size < 12) {
		return false;
	}

	uint32_t src_crc = le32toh(*(uint32_t *)(table + size - 4));
	uint32_t dst_crc = crc32(table, size - 4);

	return src_crc == dst_crc;
}
