platform: Add decode_pldm_cper_event_data() API
Support decoder for `cperEvent` event class as table `Table 27 -
CPEREvent class eventData format` in DSP0248 V1.3.0.
Change-Id: I6165980e0570bbb21158af9e6adee15894b3bf3a
Signed-off-by: Thu Nguyen <thu@os.amperecomputing.com>
diff --git a/src/dsp/platform.c b/src/dsp/platform.c
index f826f3c..9439e12 100644
--- a/src/dsp/platform.c
+++ b/src/dsp/platform.c
@@ -2856,3 +2856,60 @@
return pldm_msgbuf_destroy_consumed(buf);
}
+
+LIBPLDM_ABI_TESTING
+int decode_pldm_platform_cper_event_data(
+ const void *event_data, size_t event_data_length,
+ struct pldm_platform_cper_event *cper_event, size_t cper_event_length)
+{
+ struct pldm_msgbuf _buf;
+ struct pldm_msgbuf *buf = &_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 rc;
+ }
+ if (cper_event->format_type != PLDM_PLATFORM_CPER_EVENT_WITH_HEADER &&
+ cper_event->format_type !=
+ PLDM_PLATFORM_CPER_EVENT_WITHOUT_HEADER) {
+ return -EPROTO;
+ }
+
+ rc = pldm_msgbuf_extract(buf, cper_event->event_data_length);
+ if (rc) {
+ return rc;
+ }
+
+ if (cper_event->event_data_length >
+ (cper_event_length - sizeof(*cper_event))) {
+ return -EOVERFLOW;
+ }
+
+ pldm_msgbuf_extract_array_uint8(buf, cper_event->event_data,
+ cper_event->event_data_length);
+
+ return pldm_msgbuf_destroy_consumed(buf);
+}
+
+LIBPLDM_ABI_TESTING
+uint8_t *
+pldm_platform_cper_event_event_data(struct pldm_platform_cper_event *event)
+{
+ return event->event_data;
+}