blob: 358fb38cf5b780410786b37442996deedd05104d [file] [log] [blame]
Sampa Misra032bd502019-03-06 05:03:22 -06001#include <endian.h>
2#include <string.h>
3
4#include "bios.h"
5
6int 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
21int 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 Misra032bd502019-03-06 05:03:22 -060033 header.msg_type = PLDM_RESPONSE;
34 header.instance = instance_id;
35 header.pldm_type = PLDM_BIOS;
36 header.command = PLDM_GET_DATE_TIME;
Zahed Hossain43264522019-06-04 02:21:03 -050037
Priyanga5dcd1802019-06-10 01:50:39 -050038 struct pldm_get_date_time_resp *response =
39 (struct pldm_get_date_time_resp *)msg->payload;
40
Sampa Misra032bd502019-03-06 05:03:22 -060041 if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
42 return rc;
43 }
44
Priyanga5dcd1802019-06-10 01:50:39 -050045 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 Hossain43264522019-06-04 02:21:03 -050054 }
Sampa Misra032bd502019-03-06 05:03:22 -060055 return PLDM_SUCCESS;
56}
57
vkaverapa6575b82019-04-03 05:33:52 -050058int decode_get_date_time_resp(const uint8_t *msg, size_t payload_length,
Sampa Misra032bd502019-03-06 05:03:22 -060059 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
vkaverapa6575b82019-04-03 05:33:52 -050069 if (payload_length != PLDM_GET_DATE_TIME_RESP_BYTES) {
70 return PLDM_ERROR_INVALID_LENGTH;
71 }
72
Priyanga5dcd1802019-06-10 01:50:39 -050073 struct pldm_get_date_time_resp *response =
74 (struct pldm_get_date_time_resp *)msg;
75 *completion_code = response->completion_code;
76
Sampa Misra032bd502019-03-06 05:03:22 -060077 if (PLDM_SUCCESS != *completion_code) {
78 return PLDM_SUCCESS;
79 }
Priyanga5dcd1802019-06-10 01:50:39 -050080 *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 Misra032bd502019-03-06 05:03:22 -060086
87 return PLDM_SUCCESS;
88}