Add autotools infrastructure for ibm-pldm-oem
base.h, pldm_types.h and base.c is copied from the PLDM repository
till the bitbake recipe files are ready. This enables to write the
encode/decode for file I/O PLDM oem commands. These files will be
reverted once the recipe changes are in.
Change-Id: I0313c3fe2ed01b70fadd373a1e9f979e25c2dce2
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/Makefile.am b/Makefile.am
new file mode 100644
index 0000000..d2456ab
--- /dev/null
+++ b/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = libpldm
diff --git a/bootstrap.sh b/bootstrap.sh
new file mode 100755
index 0000000..50b75b7
--- /dev/null
+++ b/bootstrap.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+AUTOCONF_FILES="Makefile.in aclocal.m4 ar-lib autom4te.cache compile \
+ config.guess config.h.in config.sub configure depcomp install-sh \
+ ltmain.sh missing *libtool test-driver"
+
+case $1 in
+ clean)
+ test -f Makefile && make maintainer-clean
+ for file in ${AUTOCONF_FILES}; do
+ find -name "$file" | xargs -r rm -rf
+ done
+ exit 0
+ ;;
+esac
+
+autoreconf -i
+echo 'Run "./configure ${CONFIGURE_FLAGS} && make"'
diff --git a/configure.ac b/configure.ac
new file mode 100644
index 0000000..6c9895c
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1,25 @@
+# Initialization
+AC_PREREQ([2.69])
+AC_INIT([pldm], [1.0],
+ [https://github.com/openbmc/ibm-pldm-oem/issues])
+AC_LANG([C++])
+AC_CONFIG_HEADERS([config.h])
+AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror foreign dist-xz])
+AM_SILENT_RULES([yes])
+
+# Checks for programs.
+AC_PROG_CXX
+AC_PROG_CC
+AM_PROG_AR
+AC_PROG_INSTALL
+
+# Checks for typedefs, structures, and compiler characteristics.
+AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
+AX_APPEND_COMPILE_FLAGS([-Wall -Werror], [CXXFLAGS])
+
+# For linking
+LT_INIT
+
+# Create configured output
+AC_CONFIG_FILES([Makefile libpldm/Makefile])
+AC_OUTPUT
diff --git a/libpldm/Makefile.am b/libpldm/Makefile.am
new file mode 100644
index 0000000..59da344
--- /dev/null
+++ b/libpldm/Makefile.am
@@ -0,0 +1,7 @@
+libpldmoem_LTLIBRARIES = libpldmoem.la
+libpldmoemdir = ${libdir}
+libpldmoem_la_SOURCES = \
+ base.c
+
+libpldmoem_la_LDFLAGS = \
+ -version-info 1:0:0 -shared
diff --git a/libpldm/base.c b/libpldm/base.c
new file mode 100644
index 0000000..473dc53
--- /dev/null
+++ b/libpldm/base.c
@@ -0,0 +1,63 @@
+#include <endian.h>
+#include <string.h>
+
+#include "base.h"
+
+int pack_pldm_header(const struct pldm_header_info *hdr,
+ struct pldm_msg_hdr *msg)
+{
+ if (msg == NULL || hdr == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (hdr->msg_type != PLDM_RESPONSE && hdr->msg_type != PLDM_REQUEST &&
+ hdr->msg_type != PLDM_ASYNC_REQUEST_NOTIFY) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (hdr->instance > PLDM_INSTANCE_MAX) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (hdr->pldm_type > (PLDM_MAX_TYPES - 1)) {
+ return PLDM_ERROR_INVALID_PLDM_TYPE;
+ }
+
+ uint8_t datagram = (hdr->msg_type == PLDM_ASYNC_REQUEST_NOTIFY) ? 1 : 0;
+
+ if (hdr->msg_type == PLDM_RESPONSE) {
+ msg->request = PLDM_RESPONSE;
+ } else if (hdr->msg_type == PLDM_REQUEST ||
+ hdr->msg_type == PLDM_ASYNC_REQUEST_NOTIFY) {
+ msg->request = PLDM_REQUEST;
+ }
+ msg->datagram = datagram;
+ msg->reserved = 0;
+ msg->instance_id = hdr->instance;
+ msg->header_ver = 0;
+ msg->type = hdr->pldm_type;
+ msg->command = hdr->command;
+
+ return PLDM_SUCCESS;
+}
+
+int unpack_pldm_header(const struct pldm_msg_hdr *msg,
+ struct pldm_header_info *hdr)
+{
+ if (msg == NULL) {
+ return PLDM_ERROR_INVALID_DATA;
+ }
+
+ if (msg->request == PLDM_RESPONSE) {
+ hdr->msg_type = PLDM_RESPONSE;
+ } else {
+ hdr->msg_type =
+ msg->datagram ? PLDM_ASYNC_REQUEST_NOTIFY : PLDM_REQUEST;
+ }
+
+ hdr->instance = msg->instance_id;
+ hdr->pldm_type = msg->type;
+ hdr->command = msg->command;
+
+ return PLDM_SUCCESS;
+}
diff --git a/libpldm/base.h b/libpldm/base.h
new file mode 100644
index 0000000..085a3a5
--- /dev/null
+++ b/libpldm/base.h
@@ -0,0 +1,154 @@
+#ifndef BASE_H
+#define BASE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <asm/byteorder.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include "pldm_types.h"
+
+/** @brief PLDM Types
+ */
+enum pldm_supported_types {
+ PLDM_BASE = 0x00,
+};
+
+/** @brief PLDM Commands
+ */
+enum pldm_supported_commands {
+ PLDM_GET_PLDM_VERSION = 0x3,
+ PLDM_GET_PLDM_TYPES = 0x4,
+ PLDM_GET_PLDM_COMMANDS = 0x5
+};
+
+/** @brief PLDM base codes
+ */
+enum pldm_completion_codes {
+ PLDM_SUCCESS = 0x00,
+ PLDM_ERROR = 0x01,
+ PLDM_ERROR_INVALID_DATA = 0x02,
+ PLDM_ERROR_INVALID_LENGTH = 0x03,
+ PLDM_ERROR_NOT_READY = 0x04,
+ PLDM_ERROR_UNSUPPORTED_PLDM_CMD = 0x05,
+ PLDM_ERROR_INVALID_PLDM_TYPE = 0x20
+};
+
+enum transfer_op_flag {
+ PLDM_GET_NEXTPART = 0,
+ PLDM_GET_FIRSTPART = 1,
+};
+
+enum transfer_resp_flag {
+ PLDM_START = 0x01,
+ PLDM_MIDDLE = 0x02,
+ PLDM_END = 0x04,
+ PLDM_START_AND_END = 0x05,
+};
+
+/** @enum MessageType
+ *
+ * The different message types supported by the PLDM specification.
+ */
+typedef enum {
+ PLDM_RESPONSE, //!< PLDM response
+ PLDM_REQUEST, //!< PLDM request
+ PLDM_RESERVED, //!< Reserved
+ PLDM_ASYNC_REQUEST_NOTIFY, //!< Unacknowledged PLDM request messages
+} MessageType;
+
+#define PLDM_INSTANCE_MAX 31
+#define PLDM_MAX_TYPES 64
+#define PLDM_MAX_CMDS_PER_TYPE 256
+
+/* Message payload lengths */
+#define PLDM_GET_COMMANDS_REQ_BYTES 5
+#define PLDM_GET_VERSION_REQ_BYTES 6
+
+/* Response lengths are inclusive of completion code */
+#define PLDM_GET_TYPES_RESP_BYTES 9
+#define PLDM_GET_COMMANDS_RESP_BYTES 33
+/* Response data has only one version and does not contain the checksum */
+#define PLDM_GET_VERSION_RESP_BYTES 10
+
+/** @struct pldm_msg_hdr
+ *
+ * Structure representing PLDM message header fields
+ */
+struct pldm_msg_hdr {
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+ uint8_t instance_id : 5; //!< Instance ID
+ uint8_t reserved : 1; //!< Reserved
+ uint8_t datagram : 1; //!< Datagram bit
+ uint8_t request : 1; //!< Request bit
+#elif defined(__BIG_ENDIAN_BITFIELD)
+ uint8_t request : 1; //!< Request bit
+ uint8_t datagram : 1; //!< Datagram bit
+ uint8_t reserved : 1; //!< Reserved
+ uint8_t instance_id : 5; //!< Instance ID
+#endif
+
+#if defined(__LITTLE_ENDIAN_BITFIELD)
+ uint8_t type : 6; //!< PLDM type
+ uint8_t header_ver : 2; //!< Header version
+#elif defined(__BIG_ENDIAN_BITFIELD)
+ uint8_t header_ver : 2; //!< Header version
+ uint8_t type : 6; //!< PLDM type
+#endif
+ uint8_t command; //!< PLDM command code
+} __attribute__((packed));
+
+/** @struct pldm_msg
+ *
+ * Structure representing PLDM message
+ */
+struct pldm_msg {
+ struct pldm_msg_hdr hdr; //!< PLDM message header
+ uint8_t payload[1]; //!< Starting byte of the message payload
+} __attribute__((packed));
+
+/** @struct pldm_header_info
+ *
+ * The information needed to prepare PLDM header and this is passed to the
+ * pack_pldm_header and unpack_pldm_header API.
+ */
+struct pldm_header_info {
+ MessageType msg_type; //!< PLDM message type
+ uint8_t instance; //!< PLDM instance id
+ uint8_t pldm_type; //!< PLDM type
+ uint8_t command; //!< PLDM command code
+ uint8_t completion_code; //!< PLDM completion code, applies for response
+};
+
+/**
+ * @brief Populate the PLDM message with the PLDM header.The caller of this API
+ * allocates buffer for the PLDM header when forming the PLDM message.
+ * The buffer is passed to this API to pack the PLDM header.
+ *
+ * @param[in] hdr - Pointer to the PLDM header information
+ * @param[out] msg - Pointer to PLDM message header
+ *
+ * @return 0 on success, otherwise PLDM error codes.
+ */
+int pack_pldm_header(const struct pldm_header_info *hdr,
+ struct pldm_msg_hdr *msg);
+
+/**
+ * @brief Unpack the PLDM header from the PLDM message.
+ *
+ * @param[in] msg - Pointer to the PLDM message header
+ * @param[out] hdr - Pointer to the PLDM header information
+ *
+ * @return 0 on success, otherwise PLDM error codes.
+ */
+int unpack_pldm_header(const struct pldm_msg_hdr *msg,
+ struct pldm_header_info *hdr);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* BASE_H */
diff --git a/libpldm/pldm_types.h b/libpldm/pldm_types.h
new file mode 100644
index 0000000..7ff1527
--- /dev/null
+++ b/libpldm/pldm_types.h
@@ -0,0 +1,30 @@
+#ifndef PLDM_TYPES_H
+#define PLDM_TYPES_H
+
+#include <stdint.h>
+
+typedef union {
+ uint8_t byte;
+ struct {
+ uint8_t bit0 : 1;
+ uint8_t bit1 : 1;
+ uint8_t bit2 : 1;
+ uint8_t bit3 : 1;
+ uint8_t bit5 : 1;
+ uint8_t bit6 : 1;
+ uint8_t bit7 : 1;
+ } __attribute__((packed)) bits;
+} bitfield8_t;
+
+/** @struct pldm_version
+ *
+ *
+ */
+typedef struct pldm_version {
+ uint8_t major;
+ uint8_t minor;
+ uint8_t update;
+ uint8_t alpha;
+} __attribute__((packed)) ver32_t;
+
+#endif /* PLDM_TYPES_H */