blob: 04ba5f383b312512416a07dcb2d3f45ea57089c4 [file] [log] [blame]
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05301#include "base.h"
Andrew Jeffery9c766792022-08-10 23:12:49 +09302#include <endian.h>
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05303#include <stdint.h>
Andrew Jeffery9c766792022-08-10 23:12:49 +09304#include <string.h>
5
6#include "libpldm/host.h"
7
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09308LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +09309int encode_get_alert_status_req(uint8_t instance_id, uint8_t version_id,
10 struct pldm_msg *msg, size_t payload_length)
11{
12 if (msg == NULL) {
13 return PLDM_ERROR_INVALID_LENGTH;
14 }
15
16 if (payload_length != PLDM_GET_ALERT_STATUS_REQ_BYTES) {
17 return PLDM_ERROR_INVALID_LENGTH;
18 }
19
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093020 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093021 header.msg_type = PLDM_REQUEST;
22 header.instance = instance_id;
23 header.pldm_type = PLDM_OEM;
24 header.command = PLDM_HOST_GET_ALERT_STATUS;
25 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
26 if (rc != PLDM_SUCCESS) {
27 return rc;
28 }
29
30 msg->payload[0] = version_id;
31
32 return PLDM_SUCCESS;
33}
34
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093035LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093036int decode_get_alert_status_resp(const struct pldm_msg *msg,
37 size_t payload_length,
38 uint8_t *completion_code, uint32_t *rack_entry,
39 uint32_t *pri_cec_node)
40{
41 if (msg == NULL || completion_code == NULL || rack_entry == NULL ||
42 pri_cec_node == NULL) {
43 return PLDM_ERROR_INVALID_DATA;
44 }
45
46 *completion_code = msg->payload[0];
47 if (PLDM_SUCCESS != *completion_code) {
48 return PLDM_SUCCESS;
49 }
50
51 if (payload_length != PLDM_GET_ALERT_STATUS_RESP_BYTES) {
52 return PLDM_ERROR_INVALID_LENGTH;
53 }
54
55 struct pldm_get_alert_status_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093056 (struct pldm_get_alert_status_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093057
58 *rack_entry = le32toh(response->rack_entry);
59 *pri_cec_node = le32toh(response->pri_cec_node);
60
61 return PLDM_SUCCESS;
62}
63
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093064LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093065int decode_get_alert_status_req(const struct pldm_msg *msg,
66 size_t payload_length, uint8_t *version_id)
67{
68 if (msg == NULL || version_id == NULL) {
69 return PLDM_ERROR_INVALID_DATA;
70 }
71
72 if (payload_length != PLDM_GET_ALERT_STATUS_REQ_BYTES) {
73 return PLDM_ERROR_INVALID_LENGTH;
74 }
75
76 *version_id = msg->payload[0];
77
78 return PLDM_SUCCESS;
79}
80
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093081LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093082int encode_get_alert_status_resp(uint8_t instance_id, uint8_t completion_code,
83 uint32_t rack_entry, uint32_t pri_cec_node,
84 struct pldm_msg *msg, size_t payload_length)
85{
86 if (msg == NULL) {
87 return PLDM_ERROR_INVALID_LENGTH;
88 }
89
90 if (payload_length != PLDM_GET_ALERT_STATUS_RESP_BYTES) {
91 return PLDM_ERROR_INVALID_DATA;
92 }
93
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093094 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093095 header.msg_type = PLDM_RESPONSE;
96 header.instance = instance_id;
97 header.pldm_type = PLDM_OEM;
98 header.command = PLDM_HOST_GET_ALERT_STATUS;
99 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
100 if (rc != PLDM_SUCCESS) {
101 return rc;
102 }
103
104 struct pldm_get_alert_status_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930105 (struct pldm_get_alert_status_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930106
107 response->completion_code = completion_code;
108 response->rack_entry = htole32(rack_entry);
109 response->pri_cec_node = htole32(pri_cec_node);
110
111 return PLDM_SUCCESS;
112}