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