platform: Rework decode/encode_pldm_message_poll_event_data() APIs
Adds `struct pldm_message_poll_event` which includes `format_version`,
`event_id` and `data_transfer_handle` in `pldmMessagePollEvent` data.
Rework decode/encode_pldm_message_poll_event_data() APIs to use `struct
pldm_message_poll_event poll_event` as parameter.
Change-Id: I01c643ed320b17141d89068cb3e00b1a99162d77
Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 79ca67f..40a7612 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -30,6 +30,7 @@
### Changed
1. pdr: Stabilise related decode_entity_auxiliary_names_pdr() APIs
+2. platform: Rework decode/encode_pldm_message_poll_event_data() APIs
### Deprecated
diff --git a/include/libpldm/platform.h b/include/libpldm/platform.h
index 3bff9e6..159e514 100644
--- a/include/libpldm/platform.h
+++ b/include/libpldm/platform.h
@@ -1133,6 +1133,16 @@
uint8_t previous_op_state;
} __attribute__((packed));
+/** @struct pldm_message_poll_event
+ *
+ * structure representing pldmMessagePollEvent
+ */
+struct pldm_message_poll_event {
+ uint8_t format_version;
+ uint16_t event_id;
+ uint32_t data_transfer_handle;
+};
+
/** @struct pldm_platform_event_message_req
*
* structure representing PlatformEventMessage command request data
@@ -2136,36 +2146,27 @@
*
* @param[in] event_data - event data from the response message
* @param[in] event_data_length - length of the event data
- * @param[out] format_version - Version of the event format
- * @param[out] event_id - The event id
- * @param[out] data_transfer_handle - The data transfer handle
- * should be read from event data
- * @return pldm_completion_codes
+ * @param[out] poll_event - the decoded pldm_message_poll_event struct
+ * @return error code
* @note Caller is responsible for memory alloc and dealloc of param
* 'event_data'
*/
-int decode_pldm_message_poll_event_data(const uint8_t *event_data,
- size_t event_data_length,
- uint8_t *format_version,
- uint16_t *event_id,
- uint32_t *data_transfer_handle);
+int decode_pldm_message_poll_event_data(
+ const void *event_data, size_t event_data_length,
+ struct pldm_message_poll_event *poll_event);
/** @brief Encode pldmMessagePollEvent event data type
*
- * @param[in] format_version - Version of the event format
- * @param[in] event_id - The event id
- * @param[in] data_transfer_handle - The data transfer handle
+ * @param[in] poll_event - the encoded pldm_message_poll_event struct
* @param[out] event_data - event data to the response message
* @param[in] event_data_length - length of the event data
- * @return pldm_completion_codes
+ * @return error code
* @note The caller is responsible for allocating and deallocating the
* event_data
*/
-int encode_pldm_message_poll_event_data(uint8_t format_version,
- uint16_t event_id,
- uint32_t data_transfer_handle,
- uint8_t *event_data,
- size_t event_data_length);
+int encode_pldm_message_poll_event_data(
+ const struct pldm_message_poll_event *poll_event, void *event_data,
+ size_t event_data_length);
/** @brief Encode PLDM PDR Repository Change eventData
* @param[in] event_data_format - Format of this event data (e.g.
diff --git a/src/dsp/platform.c b/src/dsp/platform.c
index 4a5388c..4557d89 100644
--- a/src/dsp/platform.c
+++ b/src/dsp/platform.c
@@ -1903,71 +1903,62 @@
}
LIBPLDM_ABI_TESTING
-int decode_pldm_message_poll_event_data(const uint8_t *event_data,
- size_t event_data_length,
- uint8_t *format_version,
- uint16_t *event_id,
- uint32_t *data_transfer_handle)
+int decode_pldm_message_poll_event_data(
+ const void *event_data, size_t event_data_length,
+ struct pldm_message_poll_event *poll_event)
{
struct pldm_msgbuf _buf;
struct pldm_msgbuf *buf = &_buf;
int rc;
- if (event_data == NULL || format_version == NULL || event_id == NULL ||
- data_transfer_handle == NULL) {
- return PLDM_ERROR_INVALID_DATA;
+ if (!poll_event) {
+ return -EINVAL;
}
- rc = pldm_msgbuf_init_cc(buf, PLDM_MSG_POLL_EVENT_LENGTH, event_data,
- event_data_length);
+ rc = pldm_msgbuf_init_errno(buf, PLDM_MSG_POLL_EVENT_LENGTH, event_data,
+ event_data_length);
if (rc) {
return rc;
}
- pldm_msgbuf_extract_p(buf, format_version);
- rc = pldm_msgbuf_extract_p(buf, event_id);
+ pldm_msgbuf_extract(buf, poll_event->format_version);
+ rc = pldm_msgbuf_extract(buf, poll_event->event_id);
if (rc) {
return rc;
}
- if (*event_id == 0x0000 || *event_id == 0xffff) {
- return PLDM_ERROR_INVALID_DATA;
+ if (poll_event->event_id == 0x0000 || poll_event->event_id == 0xffff) {
+ return -EPROTO;
}
- pldm_msgbuf_extract_p(buf, data_transfer_handle);
+ pldm_msgbuf_extract(buf, poll_event->data_transfer_handle);
return pldm_msgbuf_destroy_consumed(buf);
}
LIBPLDM_ABI_TESTING
-int encode_pldm_message_poll_event_data(uint8_t format_version,
- uint16_t event_id,
- uint32_t data_transfer_handle,
- uint8_t *event_data,
- size_t event_data_length)
+int encode_pldm_message_poll_event_data(
+ const struct pldm_message_poll_event *poll_event, void *event_data,
+ size_t event_data_length)
{
struct pldm_msgbuf _buf;
struct pldm_msgbuf *buf = &_buf;
int rc;
- if (event_data == NULL) {
- return PLDM_ERROR_INVALID_DATA;
+ if (poll_event->event_id == 0x0000 || poll_event->event_id == 0xffff) {
+ return -EPROTO;
}
- if (event_id == 0x0000 || event_id == 0xffff) {
- return PLDM_ERROR_INVALID_DATA;
- }
-
- rc = pldm_msgbuf_init_cc(buf, PLDM_MSG_POLL_EVENT_LENGTH, event_data,
- event_data_length);
+ rc = pldm_msgbuf_init_errno(buf, PLDM_MSG_POLL_EVENT_LENGTH, event_data,
+ event_data_length);
if (rc) {
return rc;
}
- pldm_msgbuf_insert(buf, format_version);
- pldm_msgbuf_insert(buf, event_id);
- pldm_msgbuf_insert(buf, data_transfer_handle);
+ 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_destroy(buf);
+ return pldm_msgbuf_destroy_consumed(buf);
}
LIBPLDM_ABI_STABLE
diff --git a/tests/dsp/platform.cpp b/tests/dsp/platform.cpp
index 299c986..2b43b76 100644
--- a/tests/dsp/platform.cpp
+++ b/tests/dsp/platform.cpp
@@ -2141,18 +2141,16 @@
uint16_t eventID = 0x7788;
uint32_t dataTransferHandle = 0x11223344;
- uint8_t retFormatVersion;
- uint16_t reteventID;
- uint32_t retDataTransferHandle;
+ struct pldm_message_poll_event poll_event = {};
auto rc = decode_pldm_message_poll_event_data(
reinterpret_cast<uint8_t*>(eventData.data()), eventData.size(),
- &retFormatVersion, &reteventID, &retDataTransferHandle);
+ &poll_event);
EXPECT_EQ(rc, PLDM_SUCCESS);
- EXPECT_EQ(retFormatVersion, formatVersion);
- EXPECT_EQ(reteventID, eventID);
- EXPECT_EQ(retDataTransferHandle, dataTransferHandle);
+ EXPECT_EQ(poll_event.format_version, formatVersion);
+ EXPECT_EQ(poll_event.event_id, eventID);
+ EXPECT_EQ(poll_event.data_transfer_handle, dataTransferHandle);
}
#endif
@@ -2169,37 +2167,38 @@
0x44, 0x33, 0x22, 0x11 // Transfer Handle
};
- uint8_t retFormatVersion;
- uint16_t reteventID;
- uint32_t retDataTransferHandle;
+ struct pldm_message_poll_event poll_event = {};
- auto rc = decode_pldm_message_poll_event_data(
- NULL, eventData.size(), &retFormatVersion, &reteventID,
- &retDataTransferHandle);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ auto rc = decode_pldm_message_poll_event_data(NULL, eventData.size(),
+ &poll_event);
+ EXPECT_EQ(rc, -EINVAL);
+
+ rc = decode_pldm_message_poll_event_data(
+ reinterpret_cast<uint8_t*>(eventData.data()), eventData.size(), NULL);
+ EXPECT_EQ(rc, -EINVAL);
rc = decode_pldm_message_poll_event_data(
reinterpret_cast<uint8_t*>(eventData.data()), eventData.size() - 1,
- &retFormatVersion, &reteventID, &retDataTransferHandle);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_LENGTH);
+ &poll_event);
+ EXPECT_EQ(rc, -EOVERFLOW);
// Event id is 0x0000
eventData[1] = 0x00;
eventData[2] = 0x00;
rc = decode_pldm_message_poll_event_data(
reinterpret_cast<uint8_t*>(eventData.data()), eventData.size(),
- &retFormatVersion, &reteventID, &retDataTransferHandle);
+ &poll_event);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ EXPECT_EQ(rc, -EPROTO);
// Event id is 0xffff
eventData[1] = 0xff;
eventData[2] = 0xff;
rc = decode_pldm_message_poll_event_data(
reinterpret_cast<uint8_t*>(eventData.data()), eventData.size(),
- &retFormatVersion, &reteventID, &retDataTransferHandle);
+ &poll_event);
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ EXPECT_EQ(rc, -EPROTO);
}
#endif
@@ -2211,13 +2210,14 @@
PLDM_PLATFORM_EVENT_MESSAGE_TRANFER_HANDLE>
eventData{};
- uint8_t formatVersion = 0x01;
- uint16_t eventID = 0x7788;
- uint32_t dataTransferHandle = 0x11223344;
+ struct pldm_message_poll_event poll_event = {};
+ poll_event.format_version = 0x01;
+ poll_event.event_id = 0x7788;
+ poll_event.data_transfer_handle = 0x11223344;
int rc = encode_pldm_message_poll_event_data(
- formatVersion, eventID, dataTransferHandle,
- reinterpret_cast<uint8_t*>(eventData.data()), eventData.size());
+ &poll_event, reinterpret_cast<uint8_t*>(eventData.data()),
+ eventData.size());
EXPECT_EQ(rc, PLDM_SUCCESS);
@@ -2237,9 +2237,9 @@
EXPECT_EQ(pldm_msgbuf_extract_uint16(buf, &reteventID), PLDM_SUCCESS);
EXPECT_EQ(pldm_msgbuf_extract_uint32(buf, &retDataTransferHandle),
PLDM_SUCCESS);
- EXPECT_EQ(retFormatVersion, formatVersion);
- EXPECT_EQ(reteventID, eventID);
- EXPECT_EQ(retDataTransferHandle, dataTransferHandle);
+ EXPECT_EQ(retFormatVersion, poll_event.format_version);
+ EXPECT_EQ(reteventID, poll_event.event_id);
+ EXPECT_EQ(retDataTransferHandle, poll_event.data_transfer_handle);
EXPECT_EQ(pldm_msgbuf_destroy_consumed(buf), PLDM_SUCCESS);
}
#endif
@@ -2252,25 +2252,26 @@
PLDM_PLATFORM_EVENT_MESSAGE_TRANFER_HANDLE>
eventData{};
- uint8_t formatVersion = 0x01;
- uint16_t eventID = 0x7788;
- uint32_t dataTransferHandle = 0x11223344;
+ struct pldm_message_poll_event poll_event = {};
+ poll_event.format_version = 0x01;
+ poll_event.event_id = 0x7788;
+ poll_event.data_transfer_handle = 0x11223344;
- int rc = encode_pldm_message_poll_event_data(
- formatVersion, eventID, dataTransferHandle, NULL, eventData.size());
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ int rc = encode_pldm_message_poll_event_data(&poll_event, NULL,
+ eventData.size());
+ EXPECT_EQ(rc, -EINVAL);
- eventID = 0x0000;
+ poll_event.event_id = 0x0000;
rc = encode_pldm_message_poll_event_data(
- formatVersion, eventID, dataTransferHandle,
- reinterpret_cast<uint8_t*>(eventData.data()), eventData.size());
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ &poll_event, reinterpret_cast<uint8_t*>(eventData.data()),
+ eventData.size());
+ EXPECT_EQ(rc, -EPROTO);
- eventID = 0xffff;
+ poll_event.event_id = 0xffff;
rc = encode_pldm_message_poll_event_data(
- formatVersion, eventID, dataTransferHandle,
- reinterpret_cast<uint8_t*>(eventData.data()), eventData.size());
- EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+ &poll_event, reinterpret_cast<uint8_t*>(eventData.data()),
+ eventData.size());
+ EXPECT_EQ(rc, -EPROTO);
}
#endif