Patrick Williams | 691668f | 2023-11-01 08:19:10 -0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ |
Andrew Jeffery | b0c1d20 | 2023-11-07 22:08:44 +1030 | [diff] [blame] | 2 | #include <libpldm/base.h> |
Pavithra Barithaya | a7989cd | 2023-10-30 08:52:28 -0500 | [diff] [blame] | 3 | #include <libpldm/oem/ibm/host.h> |
Andrew Jeffery | b0c1d20 | 2023-11-07 22:08:44 +1030 | [diff] [blame] | 4 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 5 | #include <endian.h> |
Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 6 | #include <stdint.h> |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 7 | #include <string.h> |
| 8 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 9 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 10 | int 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 Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 21 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 22 | 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 Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 36 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 37 | int 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 Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 57 | (struct pldm_get_alert_status_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 58 | |
| 59 | *rack_entry = le32toh(response->rack_entry); |
| 60 | *pri_cec_node = le32toh(response->pri_cec_node); |
| 61 | |
| 62 | return PLDM_SUCCESS; |
| 63 | } |
| 64 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 65 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 66 | int 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 Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 82 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 83 | int 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 Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 95 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 96 | 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 Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 106 | (struct pldm_get_alert_status_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 107 | |
| 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 | } |