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 | |
| 8 | int 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 Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 19 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 20 | 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 | |
| 34 | int 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 Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 54 | (struct pldm_get_alert_status_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 55 | |
| 56 | *rack_entry = le32toh(response->rack_entry); |
| 57 | *pri_cec_node = le32toh(response->pri_cec_node); |
| 58 | |
| 59 | return PLDM_SUCCESS; |
| 60 | } |
| 61 | |
| 62 | int 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 | |
| 78 | int 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 Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 90 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 91 | 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 Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 101 | (struct pldm_get_alert_status_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 102 | |
| 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 | } |