xref: /openbmc/libpldm/src/oem/ibm/host.c (revision a7989cd6)
1 /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
2 #include <libpldm/base.h>
3 #include <libpldm/oem/ibm/host.h>
4 
5 #include <endian.h>
6 #include <stdint.h>
7 #include <string.h>
8 
9 LIBPLDM_ABI_STABLE
encode_get_alert_status_req(uint8_t instance_id,uint8_t version_id,struct pldm_msg * msg,size_t payload_length)10 int encode_get_alert_status_req(uint8_t instance_id, uint8_t version_id,
11 				struct pldm_msg *msg, size_t payload_length)
12 {
13 	if (msg == NULL) {
14 		return PLDM_ERROR_INVALID_LENGTH;
15 	}
16 
17 	if (payload_length != PLDM_GET_ALERT_STATUS_REQ_BYTES) {
18 		return PLDM_ERROR_INVALID_LENGTH;
19 	}
20 
21 	struct pldm_header_info header = { 0 };
22 	header.msg_type = PLDM_REQUEST;
23 	header.instance = instance_id;
24 	header.pldm_type = PLDM_OEM;
25 	header.command = PLDM_HOST_GET_ALERT_STATUS;
26 	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
27 	if (rc != PLDM_SUCCESS) {
28 		return rc;
29 	}
30 
31 	msg->payload[0] = version_id;
32 
33 	return PLDM_SUCCESS;
34 }
35 
36 LIBPLDM_ABI_STABLE
decode_get_alert_status_resp(const struct pldm_msg * msg,size_t payload_length,uint8_t * completion_code,uint32_t * rack_entry,uint32_t * pri_cec_node)37 int decode_get_alert_status_resp(const struct pldm_msg *msg,
38 				 size_t payload_length,
39 				 uint8_t *completion_code, uint32_t *rack_entry,
40 				 uint32_t *pri_cec_node)
41 {
42 	if (msg == NULL || completion_code == NULL || rack_entry == NULL ||
43 	    pri_cec_node == NULL) {
44 		return PLDM_ERROR_INVALID_DATA;
45 	}
46 
47 	*completion_code = msg->payload[0];
48 	if (PLDM_SUCCESS != *completion_code) {
49 		return PLDM_SUCCESS;
50 	}
51 
52 	if (payload_length != PLDM_GET_ALERT_STATUS_RESP_BYTES) {
53 		return PLDM_ERROR_INVALID_LENGTH;
54 	}
55 
56 	struct pldm_get_alert_status_resp *response =
57 		(struct pldm_get_alert_status_resp *)msg->payload;
58 
59 	*rack_entry = le32toh(response->rack_entry);
60 	*pri_cec_node = le32toh(response->pri_cec_node);
61 
62 	return PLDM_SUCCESS;
63 }
64 
65 LIBPLDM_ABI_STABLE
decode_get_alert_status_req(const struct pldm_msg * msg,size_t payload_length,uint8_t * version_id)66 int decode_get_alert_status_req(const struct pldm_msg *msg,
67 				size_t payload_length, uint8_t *version_id)
68 {
69 	if (msg == NULL || version_id == NULL) {
70 		return PLDM_ERROR_INVALID_DATA;
71 	}
72 
73 	if (payload_length != PLDM_GET_ALERT_STATUS_REQ_BYTES) {
74 		return PLDM_ERROR_INVALID_LENGTH;
75 	}
76 
77 	*version_id = msg->payload[0];
78 
79 	return PLDM_SUCCESS;
80 }
81 
82 LIBPLDM_ABI_STABLE
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)83 int encode_get_alert_status_resp(uint8_t instance_id, uint8_t completion_code,
84 				 uint32_t rack_entry, uint32_t pri_cec_node,
85 				 struct pldm_msg *msg, size_t payload_length)
86 {
87 	if (msg == NULL) {
88 		return PLDM_ERROR_INVALID_LENGTH;
89 	}
90 
91 	if (payload_length != PLDM_GET_ALERT_STATUS_RESP_BYTES) {
92 		return PLDM_ERROR_INVALID_DATA;
93 	}
94 
95 	struct pldm_header_info header = { 0 };
96 	header.msg_type = PLDM_RESPONSE;
97 	header.instance = instance_id;
98 	header.pldm_type = PLDM_OEM;
99 	header.command = PLDM_HOST_GET_ALERT_STATUS;
100 	uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
101 	if (rc != PLDM_SUCCESS) {
102 		return rc;
103 	}
104 
105 	struct pldm_get_alert_status_resp *response =
106 		(struct pldm_get_alert_status_resp *)msg->payload;
107 
108 	response->completion_code = completion_code;
109 	response->rack_entry = htole32(rack_entry);
110 	response->pri_cec_node = htole32(pri_cec_node);
111 
112 	return PLDM_SUCCESS;
113 }
114