1 #include "base.h" 2 #include <endian.h> 3 #include <stdint.h> 4 #include <string.h> 5 6 #include "libpldm/host.h" 7 8 LIBPLDM_ABI_STABLE 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 20 struct pldm_header_info header = { 0 }; 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 35 LIBPLDM_ABI_STABLE 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 = 56 (struct pldm_get_alert_status_resp *)msg->payload; 57 58 *rack_entry = le32toh(response->rack_entry); 59 *pri_cec_node = le32toh(response->pri_cec_node); 60 61 return PLDM_SUCCESS; 62 } 63 64 LIBPLDM_ABI_STABLE 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 81 LIBPLDM_ABI_STABLE 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 94 struct pldm_header_info header = { 0 }; 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 = 105 (struct pldm_get_alert_status_resp *)msg->payload; 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 } 113