oem/libpldm: platform: implement responder flow for GetAlertStatus

For the responder, need to encode responder data and send requester,
waiting for recive requester data to decode, so need to implement
encode/decode(Responder flow only) for GetAlertStatus.

The GetAlertStatus is a custom oem command to report enclosure ids of
system, alert status and flags, and config ID.

Request Data:
 Type - Request Data
  uint8 - Version of the command/response format. 0x0 for this format.

Response Data:
 Type - Response Data
  enum8 - completionCode.value{PLDM_BASE_CODES, UNSUPPORTED_FORMAT_VERSION=0x81}
  uint32 - Enclosure ID, AlertStatus, Flags, Config ID.(rack entry)
  uint32 - Enclosure ID, AlertStatus, Flags, Config ID.(pri cec node)

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I968056bbabf5cc724a3b6a9646dc271df4847ed2
diff --git a/oem/ibm/libpldm/host.c b/oem/ibm/libpldm/host.c
index 6628bd5..454f6c3 100644
--- a/oem/ibm/libpldm/host.c
+++ b/oem/ibm/libpldm/host.c
@@ -53,4 +53,50 @@
 	*pri_cec_node = le32toh(response->pri_cec_node);
 
 	return PLDM_SUCCESS;
-}
\ No newline at end of file
+}
+
+int decode_get_alert_status_req(const struct pldm_msg *msg,
+				size_t payload_length, uint8_t *version_id)
+{
+	if (msg == NULL || version_id == NULL) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+
+	if (payload_length != PLDM_GET_ALERT_STATUS_REQ_BYTES) {
+		return PLDM_ERROR_INVALID_LENGTH;
+	}
+
+	*version_id = msg->payload[0];
+
+	return PLDM_SUCCESS;
+}
+
+int encode_get_alert_status_resp(uint8_t instance_id, uint8_t completion_code,
+				 uint32_t rack_entry, uint32_t pri_cec_node,
+				 struct pldm_msg *msg, size_t payload_length)
+{
+	struct pldm_header_info header = {0};
+	int rc = PLDM_SUCCESS;
+
+	header.msg_type = PLDM_RESPONSE;
+	header.instance = instance_id;
+	header.pldm_type = PLDM_OEM;
+	header.command = PLDM_HOST_GET_ALERT_STATUS;
+
+	if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
+		return rc;
+	}
+
+	if (payload_length != PLDM_GET_ALERT_STATUS_RESP_BYTES) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+
+	struct pldm_get_alert_status_resp *response =
+	    (struct pldm_get_alert_status_resp *)msg->payload;
+
+	response->completion_code = completion_code;
+	response->rack_entry = htole32(rack_entry);
+	response->pri_cec_node = htole32(pri_cec_node);
+
+	return PLDM_SUCCESS;
+}
diff --git a/oem/ibm/libpldm/host.h b/oem/ibm/libpldm/host.h
index 700c3e6..ed121ae 100644
--- a/oem/ibm/libpldm/host.h
+++ b/oem/ibm/libpldm/host.h
@@ -71,6 +71,36 @@
 				 uint8_t *completion_code, uint32_t *rack_entry,
 				 uint32_t *pri_cec_node);
 
+/* Responder */
+
+/* GetAlertStatus */
+
+/** @brief Decode GetAlertStatus request data
+ *
+ *  @param[in] msg - Request message
+ *  @param[in] payload_length - Length of request message payload
+ *  @param[out] version_id - the command/response format. 0x00 for this format
+ *  @return pldm_completion_codes
+ */
+int decode_get_alert_status_req(const struct pldm_msg *msg,
+				size_t payload_length, uint8_t *version_id);
+
+/** @brief Create a PLDM OEM response message for GetAlertStatus
+ *
+ *  @param[in] instance_id - Message's instance id
+ *  @param[in] completion_code - PLDM completion code
+ *  @param[in] rack_entry - Enclosure ID, Alert Status, Flags, Config ID
+ *  @param[in] pri_cec_node - Enclosure ID, Alert Status, Flags, Config ID
+ *  @param[out] msg - Message will be written to this
+ *  @param[in] payload_length - Length of request message payload
+ *  @return pldm_completion_codes
+ *  @note  Caller is responsible for memory alloc and dealloc of param
+ *         'msg.body.payload'
+ */
+int encode_get_alert_status_resp(uint8_t instance_id, uint8_t completion_code,
+				 uint32_t rack_entry, uint32_t pri_cec_node,
+				 struct pldm_msg *msg, size_t payload_length);
+
 #ifdef __cplusplus
 }
 #endif