decode APIs: decode completion code as well

Have the decode APIs decode PLDM completion code as well, instead on
relying on the caller to do this. If the code indicates failure, bail
out from further decoding.

Change-Id: I43c9cc924b1d182df40fbf05702cd89a7d5e5a3f
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/libpldm/base.c b/libpldm/base.c
index 3aca2c3..afba5a1 100644
--- a/libpldm/base.c
+++ b/libpldm/base.c
@@ -165,11 +165,18 @@
 }
 
 int decode_get_types_resp(const struct pldm_msg_payload *msg,
-			  bitfield8_t *types)
+			  uint8_t *completion_code, bitfield8_t *types)
 {
-	if (msg == NULL || types == NULL) {
+	if (msg == NULL || types == NULL || msg->payload == NULL ||
+	    completion_code == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
+
+	*completion_code = msg->payload[0];
+	if (PLDM_SUCCESS != *completion_code) {
+		return PLDM_SUCCESS;
+	};
+
 	const uint8_t *src = msg->payload + sizeof(uint8_t);
 	memcpy(&(types->byte), src, PLDM_MAX_TYPES / 8);
 
@@ -177,11 +184,18 @@
 }
 
 int decode_get_commands_resp(const struct pldm_msg_payload *msg,
-			     bitfield8_t *commands)
+			     uint8_t *completion_code, bitfield8_t *commands)
 {
-	if (msg == NULL || commands == NULL) {
+	if (msg == NULL || commands == NULL || msg->payload == NULL ||
+	    completion_code == NULL) {
 		return PLDM_ERROR_INVALID_DATA;
 	}
+
+	*completion_code = msg->payload[0];
+	if (PLDM_SUCCESS != *completion_code) {
+		return PLDM_SUCCESS;
+	};
+
 	const uint8_t *src = msg->payload + sizeof(uint8_t);
 	memcpy(&(commands->byte), src, PLDM_MAX_CMDS_PER_TYPE / 8);
 
@@ -269,9 +283,21 @@
 }
 
 int decode_get_version_resp(const struct pldm_msg_payload *msg,
+			    uint8_t *completion_code,
 			    uint32_t *next_transfer_handle,
 			    uint8_t *transfer_flag, ver32_t *version)
 {
+	if (msg == NULL || next_transfer_handle == NULL ||
+	    transfer_flag == NULL || msg->payload == NULL ||
+	    completion_code == NULL) {
+		return PLDM_ERROR_INVALID_DATA;
+	}
+
+	*completion_code = msg->payload[0];
+	if (PLDM_SUCCESS != *completion_code) {
+		return PLDM_SUCCESS;
+	};
+
 	const uint8_t *start = msg->payload + sizeof(uint8_t);
 	*next_transfer_handle = le32toh(*((uint32_t *)start));
 	*transfer_flag = *(start + sizeof(*next_transfer_handle));