blob: 6534e5be83e8b0cf16f6d358dda5080e45fbbe45 [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
8int encode_get_alert_status_req(uint8_t instance_id, uint8_t version_id,
9 struct pldm_msg *msg, size_t payload_length)
10{
11 if (msg == NULL) {
12 return PLDM_ERROR_INVALID_LENGTH;
13 }
14
15 if (payload_length != PLDM_GET_ALERT_STATUS_REQ_BYTES) {
16 return PLDM_ERROR_INVALID_LENGTH;
17 }
18
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093019 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093020 header.msg_type = PLDM_REQUEST;
21 header.instance = instance_id;
22 header.pldm_type = PLDM_OEM;
23 header.command = PLDM_HOST_GET_ALERT_STATUS;
24 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
25 if (rc != PLDM_SUCCESS) {
26 return rc;
27 }
28
29 msg->payload[0] = version_id;
30
31 return PLDM_SUCCESS;
32}
33
34int decode_get_alert_status_resp(const struct pldm_msg *msg,
35 size_t payload_length,
36 uint8_t *completion_code, uint32_t *rack_entry,
37 uint32_t *pri_cec_node)
38{
39 if (msg == NULL || completion_code == NULL || rack_entry == NULL ||
40 pri_cec_node == NULL) {
41 return PLDM_ERROR_INVALID_DATA;
42 }
43
44 *completion_code = msg->payload[0];
45 if (PLDM_SUCCESS != *completion_code) {
46 return PLDM_SUCCESS;
47 }
48
49 if (payload_length != PLDM_GET_ALERT_STATUS_RESP_BYTES) {
50 return PLDM_ERROR_INVALID_LENGTH;
51 }
52
53 struct pldm_get_alert_status_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093054 (struct pldm_get_alert_status_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093055
56 *rack_entry = le32toh(response->rack_entry);
57 *pri_cec_node = le32toh(response->pri_cec_node);
58
59 return PLDM_SUCCESS;
60}
61
62int decode_get_alert_status_req(const struct pldm_msg *msg,
63 size_t payload_length, uint8_t *version_id)
64{
65 if (msg == NULL || version_id == NULL) {
66 return PLDM_ERROR_INVALID_DATA;
67 }
68
69 if (payload_length != PLDM_GET_ALERT_STATUS_REQ_BYTES) {
70 return PLDM_ERROR_INVALID_LENGTH;
71 }
72
73 *version_id = msg->payload[0];
74
75 return PLDM_SUCCESS;
76}
77
78int encode_get_alert_status_resp(uint8_t instance_id, uint8_t completion_code,
79 uint32_t rack_entry, uint32_t pri_cec_node,
80 struct pldm_msg *msg, size_t payload_length)
81{
82 if (msg == NULL) {
83 return PLDM_ERROR_INVALID_LENGTH;
84 }
85
86 if (payload_length != PLDM_GET_ALERT_STATUS_RESP_BYTES) {
87 return PLDM_ERROR_INVALID_DATA;
88 }
89
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093090 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093091 header.msg_type = PLDM_RESPONSE;
92 header.instance = instance_id;
93 header.pldm_type = PLDM_OEM;
94 header.command = PLDM_HOST_GET_ALERT_STATUS;
95 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
96 if (rc != PLDM_SUCCESS) {
97 return rc;
98 }
99
100 struct pldm_get_alert_status_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930101 (struct pldm_get_alert_status_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930102
103 response->completion_code = completion_code;
104 response->rack_entry = htole32(rack_entry);
105 response->pri_cec_node = htole32(pri_cec_node);
106
107 return PLDM_SUCCESS;
108}