blob: d2c297ac000b99748fded2a29efdce4c0d948f63 [file] [log] [blame]
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09301#include "config.h"
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05302#include "base.h"
Andrew Jeffery9c766792022-08-10 23:12:49 +09303#include <endian.h>
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05304#include <stdint.h>
Andrew Jeffery9c766792022-08-10 23:12:49 +09305#include <string.h>
6
7#include "libpldm/host.h"
8
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09309LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093010int 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
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093021 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093022 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
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093036LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093037int 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 =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093057 (struct pldm_get_alert_status_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093058
59 *rack_entry = le32toh(response->rack_entry);
60 *pri_cec_node = le32toh(response->pri_cec_node);
61
62 return PLDM_SUCCESS;
63}
64
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093065LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093066int 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
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093082LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093083int 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
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093095 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093096 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 =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930106 (struct pldm_get_alert_status_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930107
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}