blob: 454f6c399d4d492f7d7ef6e52c0fdf4c04cf9b5f [file] [log] [blame]
George Liu9008d282020-03-12 11:20:35 +08001#include <endian.h>
2#include <string.h>
3
4#include "host.h"
5
6int encode_get_alert_status_req(uint8_t instance_id, uint8_t version_id,
7 struct pldm_msg *msg, size_t payload_length)
8{
9 struct pldm_header_info header = {0};
10 int rc = PLDM_SUCCESS;
11
12 header.msg_type = PLDM_REQUEST;
13 header.instance = instance_id;
14 header.pldm_type = PLDM_OEM;
15 header.command = PLDM_HOST_GET_ALERT_STATUS;
16
17 if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
18 return rc;
19 }
20
21 if (payload_length != PLDM_GET_ALERT_STATUS_REQ_BYTES) {
22 return PLDM_ERROR_INVALID_LENGTH;
23 }
24
25 msg->payload[0] = version_id;
26
27 return PLDM_SUCCESS;
28}
29
30int decode_get_alert_status_resp(const struct pldm_msg *msg,
31 size_t payload_length,
32 uint8_t *completion_code, uint32_t *rack_entry,
33 uint32_t *pri_cec_node)
34{
35 if (msg == NULL || completion_code == NULL || rack_entry == NULL ||
36 pri_cec_node == NULL) {
37 return PLDM_ERROR_INVALID_DATA;
38 }
39
40 *completion_code = msg->payload[0];
41 if (PLDM_SUCCESS != *completion_code) {
42 return PLDM_SUCCESS;
43 }
44
45 if (payload_length != PLDM_GET_ALERT_STATUS_RESP_BYTES) {
46 return PLDM_ERROR_INVALID_LENGTH;
47 }
48
49 struct pldm_get_alert_status_resp *response =
50 (struct pldm_get_alert_status_resp *)msg->payload;
51
52 *rack_entry = le32toh(response->rack_entry);
53 *pri_cec_node = le32toh(response->pri_cec_node);
54
55 return PLDM_SUCCESS;
George Liu81caca52020-03-12 12:14:11 +080056}
57
58int decode_get_alert_status_req(const struct pldm_msg *msg,
59 size_t payload_length, uint8_t *version_id)
60{
61 if (msg == NULL || version_id == NULL) {
62 return PLDM_ERROR_INVALID_DATA;
63 }
64
65 if (payload_length != PLDM_GET_ALERT_STATUS_REQ_BYTES) {
66 return PLDM_ERROR_INVALID_LENGTH;
67 }
68
69 *version_id = msg->payload[0];
70
71 return PLDM_SUCCESS;
72}
73
74int encode_get_alert_status_resp(uint8_t instance_id, uint8_t completion_code,
75 uint32_t rack_entry, uint32_t pri_cec_node,
76 struct pldm_msg *msg, size_t payload_length)
77{
78 struct pldm_header_info header = {0};
79 int rc = PLDM_SUCCESS;
80
81 header.msg_type = PLDM_RESPONSE;
82 header.instance = instance_id;
83 header.pldm_type = PLDM_OEM;
84 header.command = PLDM_HOST_GET_ALERT_STATUS;
85
86 if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
87 return rc;
88 }
89
90 if (payload_length != PLDM_GET_ALERT_STATUS_RESP_BYTES) {
91 return PLDM_ERROR_INVALID_DATA;
92 }
93
94 struct pldm_get_alert_status_resp *response =
95 (struct pldm_get_alert_status_resp *)msg->payload;
96
97 response->completion_code = completion_code;
98 response->rack_entry = htole32(rack_entry);
99 response->pri_cec_node = htole32(pri_cec_node);
100
101 return PLDM_SUCCESS;
102}