Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 1 | #include "base.h" |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 2 | #include <endian.h> |
Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 3 | #include <stdint.h> |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 4 | #include <string.h> |
| 5 | |
| 6 | #include "libpldm/host.h" |
| 7 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 8 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 9 | int 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 Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 20 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 21 | 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 Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 35 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 36 | int 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 Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 56 | (struct pldm_get_alert_status_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 57 | |
| 58 | *rack_entry = le32toh(response->rack_entry); |
| 59 | *pri_cec_node = le32toh(response->pri_cec_node); |
| 60 | |
| 61 | return PLDM_SUCCESS; |
| 62 | } |
| 63 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 64 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 65 | int 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 Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 81 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 82 | int 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 Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 94 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 95 | 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 Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 105 | (struct pldm_get_alert_status_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 106 | |
| 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 | } |