Encode & Decode APIs for PlatformEventMessage

Added the encode and decode APIs for the PlatformEventMessage command.

Currently supported PLDM event classes are,
  - sensorEvent
  - pldmPDRRepositoryChgEvent
Corresponding C structures were also defined which will
enable a user to typecast the event data that is part of the
PlatformEventMessage request.

Added Unit tests for the APIs.

Change-Id: Ia64944ef51c414423ad49f19ff9f88bab78cc224
Signed-off-by: Zahed Hossain <zahzahed@in.ibm.com>
diff --git a/libpldm/platform.c b/libpldm/platform.c
index cd332e6..45abf5a 100644
--- a/libpldm/platform.c
+++ b/libpldm/platform.c
@@ -555,3 +555,57 @@
 
 	return PLDM_SUCCESS;
 }
+
+int decode_platform_event_message_req(const struct pldm_msg *msg,
+				      size_t payload_length,
+				      uint8_t *format_version, uint8_t *tid,
+				      uint8_t *event_class,
+				      size_t *event_data_offset)
+{
+
+	if (msg == NULL || format_version == NULL || tid == NULL ||
+	    event_class == NULL || event_data_offset == NULL) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+
+	if (payload_length <= PLDM_PLATFORM_EVENT_MESSAGE_MIN_REQ_BYTES) {
+		return PLDM_ERROR_INVALID_LENGTH;
+	}
+	struct pldm_platform_event_message_req *response =
+	    (struct pldm_platform_event_message_req *)msg->payload;
+
+	*format_version = response->format_version;
+	*tid = response->tid;
+	*event_class = response->event_class;
+	*event_data_offset =
+	    sizeof(*format_version) + sizeof(*tid) + sizeof(*event_class);
+
+	return PLDM_SUCCESS;
+}
+
+int encode_platform_event_message_resp(uint8_t instance_id,
+				       uint8_t completion_code, uint8_t status,
+				       struct pldm_msg *msg)
+{
+	int rc = PLDM_SUCCESS;
+
+	if (msg == NULL) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+
+	struct pldm_platform_event_message_resp *response =
+	    (struct pldm_platform_event_message_resp *)msg->payload;
+	response->completion_code = completion_code;
+	response->status = status;
+
+	struct pldm_header_info header = {0};
+	header.msg_type = PLDM_RESPONSE;
+	header.instance = instance_id;
+	header.pldm_type = PLDM_PLATFORM;
+	header.command = PLDM_PLATFORM_EVENT_MESSAGE;
+
+	if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+		return rc;
+	}
+	return PLDM_SUCCESS;
+}