| Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame^] | 1 | #include <endian.h> | 
 | 2 | #include <string.h> | 
 | 3 |  | 
 | 4 | #include "base.h" | 
 | 5 |  | 
 | 6 | int encode_get_types_req(uint8_t instance_id, struct pldm_msg *msg) | 
 | 7 | { | 
 | 8 | 	if (msg == NULL) { | 
 | 9 | 		return PLDM_ERROR_INVALID_DATA; | 
 | 10 | 	} | 
 | 11 |  | 
 | 12 | 	return PLDM_SUCCESS; | 
 | 13 | } | 
 | 14 |  | 
 | 15 | int encode_get_commands_req(uint8_t instance_id, uint8_t type, | 
 | 16 | 			    struct pldm_version version, struct pldm_msg *msg) | 
 | 17 | { | 
 | 18 | 	if (msg == NULL) { | 
 | 19 | 		return PLDM_ERROR_INVALID_DATA; | 
 | 20 | 	} | 
 | 21 |  | 
 | 22 | 	uint8_t *dst = msg->body.payload; | 
 | 23 | 	memcpy(dst, &type, sizeof(type)); | 
 | 24 | 	dst += sizeof(type); | 
 | 25 | 	memcpy(dst, &version, sizeof(version)); | 
 | 26 |  | 
 | 27 | 	return PLDM_SUCCESS; | 
 | 28 | } | 
 | 29 |  | 
 | 30 | int encode_get_types_resp(uint8_t instance_id, uint8_t completion_code, | 
 | 31 | 			  const uint8_t *types, struct pldm_msg *msg) | 
 | 32 | { | 
 | 33 | 	if (msg == NULL) { | 
 | 34 | 		return PLDM_ERROR_INVALID_DATA; | 
 | 35 | 	} | 
 | 36 |  | 
 | 37 | 	msg->body.payload[0] = completion_code; | 
 | 38 | 	if (msg->body.payload[0] == PLDM_SUCCESS) { | 
 | 39 | 		if (types == NULL) { | 
 | 40 | 			return PLDM_ERROR_INVALID_DATA; | 
 | 41 | 		} | 
 | 42 | 		uint8_t *dst = msg->body.payload + sizeof(msg->body.payload[0]); | 
 | 43 | 		memcpy(dst, types, PLDM_MAX_TYPES / 8); | 
 | 44 | 	} | 
 | 45 |  | 
 | 46 | 	return PLDM_SUCCESS; | 
 | 47 | } | 
 | 48 |  | 
 | 49 | int decode_get_commands_req(const struct pldm_msg_payload *msg, uint8_t *type, | 
 | 50 | 			    struct pldm_version *version) | 
 | 51 | { | 
 | 52 | 	if (msg == NULL || type == NULL || version == NULL) { | 
 | 53 | 		return PLDM_ERROR_INVALID_DATA; | 
 | 54 | 	} | 
 | 55 |  | 
 | 56 | 	const uint8_t *start = msg->payload; | 
 | 57 | 	*type = *start; | 
 | 58 | 	memcpy(version, (struct pldm_version *)(start + sizeof(*type)), | 
 | 59 | 	       sizeof(*version)); | 
 | 60 |  | 
 | 61 | 	return PLDM_SUCCESS; | 
 | 62 | } | 
 | 63 |  | 
 | 64 | int encode_get_commands_resp(uint8_t instance_id, uint8_t completion_code, | 
 | 65 | 			     const uint8_t *commands, struct pldm_msg *msg) | 
 | 66 | { | 
 | 67 | 	if (msg == NULL) { | 
 | 68 | 		return PLDM_ERROR_INVALID_DATA; | 
 | 69 | 	} | 
 | 70 |  | 
 | 71 | 	msg->body.payload[0] = completion_code; | 
 | 72 | 	if (msg->body.payload[0] == PLDM_SUCCESS) { | 
 | 73 | 		if (commands == NULL) { | 
 | 74 | 			return PLDM_ERROR_INVALID_DATA; | 
 | 75 | 		} | 
 | 76 | 		uint8_t *dst = msg->body.payload + sizeof(msg->body.payload[0]); | 
 | 77 | 		memcpy(dst, commands, PLDM_MAX_CMDS_PER_TYPE / 8); | 
 | 78 | 	} | 
 | 79 |  | 
 | 80 | 	return PLDM_SUCCESS; | 
 | 81 | } | 
 | 82 |  | 
 | 83 | int decode_get_types_resp(const struct pldm_msg_payload *msg, uint8_t *types) | 
 | 84 | { | 
 | 85 | 	if (msg == NULL || types == NULL) { | 
 | 86 | 		return PLDM_ERROR_INVALID_DATA; | 
 | 87 | 	} | 
 | 88 | 	const uint8_t *src = msg->payload + sizeof(uint8_t); | 
 | 89 | 	memcpy(types, src, PLDM_MAX_TYPES / 8); | 
 | 90 |  | 
 | 91 | 	return PLDM_SUCCESS; | 
 | 92 | } | 
 | 93 |  | 
 | 94 | int decode_get_commands_resp(const struct pldm_msg_payload *msg, | 
 | 95 | 			     uint8_t *commands) | 
 | 96 | { | 
 | 97 | 	if (msg == NULL || commands == NULL) { | 
 | 98 | 		return PLDM_ERROR_INVALID_DATA; | 
 | 99 | 	} | 
 | 100 | 	const uint8_t *src = msg->payload + sizeof(uint8_t); | 
 | 101 | 	memcpy(commands, src, PLDM_MAX_CMDS_PER_TYPE / 8); | 
 | 102 |  | 
 | 103 | 	return PLDM_SUCCESS; | 
 | 104 | } |