Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 1 | #include <endian.h> |
| 2 | #include <string.h> |
| 3 | |
| 4 | #include "bios.h" |
| 5 | |
| 6 | int encode_get_date_time_req(uint8_t instance_id, struct pldm_msg *msg) |
| 7 | { |
| 8 | struct pldm_header_info header = {0}; |
| 9 | |
| 10 | if (msg == NULL) { |
| 11 | return PLDM_ERROR_INVALID_DATA; |
| 12 | } |
| 13 | |
| 14 | header.msg_type = PLDM_REQUEST; |
| 15 | header.instance = instance_id; |
| 16 | header.pldm_type = PLDM_BIOS; |
| 17 | header.command = PLDM_GET_DATE_TIME; |
| 18 | return pack_pldm_header(&header, &(msg->hdr)); |
| 19 | } |
| 20 | |
| 21 | int encode_get_date_time_resp(uint8_t instance_id, uint8_t completion_code, |
| 22 | uint8_t seconds, uint8_t minutes, uint8_t hours, |
| 23 | uint8_t day, uint8_t month, uint16_t year, |
| 24 | struct pldm_msg *msg) |
| 25 | { |
| 26 | struct pldm_header_info header = {0}; |
| 27 | int rc = PLDM_SUCCESS; |
| 28 | |
| 29 | if (msg == NULL) { |
| 30 | return PLDM_ERROR_INVALID_DATA; |
| 31 | } |
| 32 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 33 | header.msg_type = PLDM_RESPONSE; |
| 34 | header.instance = instance_id; |
| 35 | header.pldm_type = PLDM_BIOS; |
| 36 | header.command = PLDM_GET_DATE_TIME; |
Zahed Hossain | 4326452 | 2019-06-04 02:21:03 -0500 | [diff] [blame] | 37 | |
Priyanga | 5dcd180 | 2019-06-10 01:50:39 -0500 | [diff] [blame] | 38 | struct pldm_get_date_time_resp *response = |
| 39 | (struct pldm_get_date_time_resp *)msg->payload; |
| 40 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 41 | if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) { |
| 42 | return rc; |
| 43 | } |
| 44 | |
Priyanga | 5dcd180 | 2019-06-10 01:50:39 -0500 | [diff] [blame] | 45 | response->completion_code = completion_code; |
| 46 | if (response->completion_code == PLDM_SUCCESS) { |
| 47 | response->completion_code = completion_code; |
| 48 | response->seconds = seconds; |
| 49 | response->minutes = minutes; |
| 50 | response->hours = hours; |
| 51 | response->day = day; |
| 52 | response->month = month; |
| 53 | response->year = htole16(year); |
Zahed Hossain | 4326452 | 2019-06-04 02:21:03 -0500 | [diff] [blame] | 54 | } |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 55 | return PLDM_SUCCESS; |
| 56 | } |
| 57 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 58 | int decode_get_date_time_resp(const uint8_t *msg, size_t payload_length, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 59 | uint8_t *completion_code, uint8_t *seconds, |
| 60 | uint8_t *minutes, uint8_t *hours, uint8_t *day, |
| 61 | uint8_t *month, uint16_t *year) |
| 62 | { |
| 63 | if (msg == NULL || seconds == NULL || minutes == NULL || |
| 64 | hours == NULL || day == NULL || month == NULL || year == NULL || |
| 65 | completion_code == NULL) { |
| 66 | return PLDM_ERROR_INVALID_DATA; |
| 67 | } |
| 68 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 69 | if (payload_length != PLDM_GET_DATE_TIME_RESP_BYTES) { |
| 70 | return PLDM_ERROR_INVALID_LENGTH; |
| 71 | } |
| 72 | |
Priyanga | 5dcd180 | 2019-06-10 01:50:39 -0500 | [diff] [blame] | 73 | struct pldm_get_date_time_resp *response = |
| 74 | (struct pldm_get_date_time_resp *)msg; |
| 75 | *completion_code = response->completion_code; |
| 76 | |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 77 | if (PLDM_SUCCESS != *completion_code) { |
| 78 | return PLDM_SUCCESS; |
| 79 | } |
Priyanga | 5dcd180 | 2019-06-10 01:50:39 -0500 | [diff] [blame] | 80 | *seconds = response->seconds; |
| 81 | *minutes = response->minutes; |
| 82 | *hours = response->hours; |
| 83 | *day = response->day; |
| 84 | *month = response->month; |
| 85 | *year = le16toh(response->year); |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 86 | |
| 87 | return PLDM_SUCCESS; |
| 88 | } |