Define pldm data types
This commit defines some data types as per PLDM DSP0240. Only types that
are used are defined.
Change-Id: Id932d638587b4b34c2941d6d0714cd0e1f1be264
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/libpldm/base.c b/libpldm/base.c
index 8d336e5..3aca2c3 100644
--- a/libpldm/base.c
+++ b/libpldm/base.c
@@ -77,8 +77,8 @@
return PLDM_SUCCESS;
}
-int encode_get_commands_req(uint8_t instance_id, uint8_t type,
- struct pldm_version version, struct pldm_msg *msg)
+int encode_get_commands_req(uint8_t instance_id, uint8_t type, ver32_t version,
+ struct pldm_msg *msg)
{
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
@@ -99,7 +99,7 @@
}
int encode_get_types_resp(uint8_t instance_id, uint8_t completion_code,
- const uint8_t *types, struct pldm_msg *msg)
+ const bitfield8_t *types, struct pldm_msg *msg)
{
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
@@ -118,14 +118,14 @@
return PLDM_ERROR_INVALID_DATA;
}
uint8_t *dst = msg->body.payload + sizeof(msg->body.payload[0]);
- memcpy(dst, types, PLDM_MAX_TYPES / 8);
+ memcpy(dst, &(types->byte), PLDM_MAX_TYPES / 8);
}
return PLDM_SUCCESS;
}
int decode_get_commands_req(const struct pldm_msg_payload *msg, uint8_t *type,
- struct pldm_version *version)
+ ver32_t *version)
{
if (msg == NULL || type == NULL || version == NULL) {
return PLDM_ERROR_INVALID_DATA;
@@ -133,14 +133,13 @@
const uint8_t *start = msg->payload;
*type = *start;
- memcpy(version, (struct pldm_version *)(start + sizeof(*type)),
- sizeof(*version));
+ memcpy(version, (ver32_t *)(start + sizeof(*type)), sizeof(*version));
return PLDM_SUCCESS;
}
int encode_get_commands_resp(uint8_t instance_id, uint8_t completion_code,
- const uint8_t *commands, struct pldm_msg *msg)
+ const bitfield8_t *commands, struct pldm_msg *msg)
{
if (msg == NULL) {
return PLDM_ERROR_INVALID_DATA;
@@ -159,31 +158,32 @@
return PLDM_ERROR_INVALID_DATA;
}
uint8_t *dst = msg->body.payload + sizeof(msg->body.payload[0]);
- memcpy(dst, commands, PLDM_MAX_CMDS_PER_TYPE / 8);
+ memcpy(dst, &(commands->byte), PLDM_MAX_CMDS_PER_TYPE / 8);
}
return PLDM_SUCCESS;
}
-int decode_get_types_resp(const struct pldm_msg_payload *msg, uint8_t *types)
+int decode_get_types_resp(const struct pldm_msg_payload *msg,
+ bitfield8_t *types)
{
if (msg == NULL || types == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
const uint8_t *src = msg->payload + sizeof(uint8_t);
- memcpy(types, src, PLDM_MAX_TYPES / 8);
+ memcpy(&(types->byte), src, PLDM_MAX_TYPES / 8);
return PLDM_SUCCESS;
}
int decode_get_commands_resp(const struct pldm_msg_payload *msg,
- uint8_t *commands)
+ bitfield8_t *commands)
{
if (msg == NULL || commands == NULL) {
return PLDM_ERROR_INVALID_DATA;
}
const uint8_t *src = msg->payload + sizeof(uint8_t);
- memcpy(commands, src, PLDM_MAX_CMDS_PER_TYPE / 8);
+ memcpy(&(commands->byte), src, PLDM_MAX_CMDS_PER_TYPE / 8);
return PLDM_SUCCESS;
}
@@ -223,8 +223,7 @@
int encode_get_version_resp(uint8_t instance_id, uint8_t completion_code,
uint32_t next_transfer_handle,
- uint8_t transfer_flag,
- const struct pldm_version *version_data,
+ uint8_t transfer_flag, const ver32_t *version_data,
size_t version_size, struct pldm_msg *msg)
{
struct pldm_header_info header = {0};
@@ -271,16 +270,14 @@
int decode_get_version_resp(const struct pldm_msg_payload *msg,
uint32_t *next_transfer_handle,
- uint8_t *transfer_flag,
- struct pldm_version *version)
+ uint8_t *transfer_flag, ver32_t *version)
{
const uint8_t *start = msg->payload + sizeof(uint8_t);
*next_transfer_handle = le32toh(*((uint32_t *)start));
*transfer_flag = *(start + sizeof(*next_transfer_handle));
- *version =
- *((struct pldm_version *)(start + sizeof(*next_transfer_handle) +
- sizeof(*transfer_flag)));
+ *version = *((ver32_t *)(start + sizeof(*next_transfer_handle) +
+ sizeof(*transfer_flag)));
return PLDM_SUCCESS;
}
diff --git a/libpldm/base.h b/libpldm/base.h
index b2050a5..e0362f4 100644
--- a/libpldm/base.h
+++ b/libpldm/base.h
@@ -9,6 +9,8 @@
#include <stddef.h>
#include <stdint.h>
+#include "pldm_types.h"
+
/** @brief PLDM Types
*/
enum pldm_supported_types {
@@ -117,17 +119,6 @@
struct pldm_msg_payload body; //!< PLDM message payload
} __attribute__((packed));
-/** @struct pldm_version
- *
- * Structure representing PLDM ver32 type
- */
-struct pldm_version {
- uint8_t major;
- uint8_t minor;
- uint8_t update;
- uint8_t alpha;
-} __attribute__((packed));
-
/** @struct pldm_header_info
*
* The information needed to prepare PLDM header and this is passed to the
@@ -182,11 +173,12 @@
/** @brief Decode a GetPLDMTypes response message
*
* @param[in] msg - Response message payload
- * @param[out] types - pointer to array uint8_t[8] containing supported
+ * @param[out] types - pointer to array bitfield8_t[8] containing supported
* types (MAX_TYPES/8) = 8), as per DSP0240
* @return pldm_completion_codes
*/
-int decode_get_types_resp(const struct pldm_msg_payload *msg, uint8_t *types);
+int decode_get_types_resp(const struct pldm_msg_payload *msg,
+ bitfield8_t *types);
/* GetPLDMCommands */
@@ -200,18 +192,18 @@
* @note Caller is responsible for memory alloc and dealloc of param
* 'msg.body.payload'
*/
-int encode_get_commands_req(uint8_t instance_id, uint8_t type,
- struct pldm_version version, struct pldm_msg *msg);
+int encode_get_commands_req(uint8_t instance_id, uint8_t type, ver32_t version,
+ struct pldm_msg *msg);
/** @brief Decode a GetPLDMCommands response message
*
* @param[in] msg - Response message payload
- * @param[in] commands - pointer to array uint8_t[32] containing supported
+ * @param[in] commands - pointer to array bitfield8_t[32] containing supported
* commands (PLDM_MAX_CMDS_PER_TYPE/8) = 32), as per DSP0240
* @return pldm_completion_codes
*/
int decode_get_commands_resp(const struct pldm_msg_payload *msg,
- uint8_t *commands);
+ bitfield8_t *commands);
/* GetPLDMVersion */
@@ -242,8 +234,7 @@
*/
int decode_get_version_resp(const struct pldm_msg_payload *msg,
uint32_t *next_transfer_handle,
- uint8_t *transfer_flag,
- struct pldm_version *version);
+ uint8_t *transfer_flag, ver32_t *version);
/* Responder */
@@ -253,7 +244,7 @@
*
* @param[in] instance_id - Message's instance id
* @param[in] completion_code - PLDM completion code
- * @param[in] types - pointer to array uint8_t[8] containing supported
+ * @param[in] types - pointer to array bitfield8_t[8] containing supported
* types (MAX_TYPES/8) = 8), as per DSP0240
* @param[in,out] msg - Message will be written to this
* @return pldm_completion_codes
@@ -261,7 +252,7 @@
* 'msg.body.payload'
*/
int encode_get_types_resp(uint8_t instance_id, uint8_t completion_code,
- const uint8_t *types, struct pldm_msg *msg);
+ const bitfield8_t *types, struct pldm_msg *msg);
/* GetPLDMCommands */
@@ -273,13 +264,13 @@
* @return pldm_completion_codes
*/
int decode_get_commands_req(const struct pldm_msg_payload *msg, uint8_t *type,
- struct pldm_version *version);
+ ver32_t *version);
/** @brief Create a PLDM response message for GetPLDMCommands
*
* @param[in] instance_id - Message's instance id
* @param[in] completion_code - PLDM completion code
- * @param[in] commands - pointer to array uint8_t[32] containing supported
+ * @param[in] commands - pointer to array bitfield8_t[32] containing supported
* commands (PLDM_MAX_CMDS_PER_TYPE/8) = 32), as per DSP0240
* @param[in,out] msg - Message will be written to this
* @return pldm_completion_codes
@@ -287,7 +278,7 @@
* 'msg.body.payload'
*/
int encode_get_commands_resp(uint8_t instance_id, uint8_t completion_code,
- const uint8_t *commands, struct pldm_msg *msg);
+ const bitfield8_t *commands, struct pldm_msg *msg);
/* GetPLDMVersion */
@@ -307,8 +298,7 @@
*/
int encode_get_version_resp(uint8_t instance_id, uint8_t completion_code,
uint32_t next_transfer_handle,
- uint8_t transfer_flag,
- const struct pldm_version *version_data,
+ uint8_t transfer_flag, const ver32_t *version_data,
size_t version_size, struct pldm_msg *msg);
/** @brief Decode a GetPLDMVersion request message
diff --git a/libpldm/pldm_types.h b/libpldm/pldm_types.h
new file mode 100644
index 0000000..32228d7
--- /dev/null
+++ b/libpldm/pldm_types.h
@@ -0,0 +1,25 @@
+#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;