blob: 3027f6ccb5855e602e6d9c92122118191b280193 [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
Zahed Hossain223a73d2019-07-04 12:46:18 -050058int decode_get_date_time_resp(const struct pldm_msg *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 =
Zahed Hossain223a73d2019-07-04 12:46:18 -050074 (struct pldm_get_date_time_resp *)msg->payload;
Priyanga5dcd1802019-06-10 01:50:39 -050075 *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}
Sampa Misrab37be312019-07-03 02:26:41 -050089
90int encode_get_bios_table_resp(uint8_t instance_id, uint8_t completion_code,
91 uint32_t next_transfer_handle,
92 uint8_t transfer_flag, uint8_t *table_data,
93 size_t payload_length, struct pldm_msg *msg)
94{
95 struct pldm_header_info header = {0};
96 int rc = PLDM_SUCCESS;
97
98 if (msg == NULL) {
99 return PLDM_ERROR_INVALID_DATA;
100 }
101
102 struct pldm_get_bios_table_resp *response =
103 (struct pldm_get_bios_table_resp *)msg->payload;
104
105 response->completion_code = completion_code;
106 header.msg_type = PLDM_RESPONSE;
107 header.instance = instance_id;
108 header.pldm_type = PLDM_BIOS;
109 header.command = PLDM_GET_BIOS_TABLE;
110 if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
111 return rc;
112 }
113
114 if (response->completion_code == PLDM_SUCCESS) {
115
116 response->next_transfer_handle = htole32(next_transfer_handle);
117 response->transfer_flag = transfer_flag;
118 if (table_data != NULL &&
119 payload_length > (sizeof(struct pldm_msg_hdr) +
120 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES)) {
121 memcpy(response->table_data, table_data,
122 payload_length -
123 (sizeof(struct pldm_msg_hdr) +
124 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES));
125 }
126 }
127 return PLDM_SUCCESS;
128}
129
130int decode_get_bios_table_req(const struct pldm_msg *msg, size_t payload_length,
131 uint32_t *transfer_handle,
132 uint8_t *transfer_op_flag, uint8_t *table_type)
133{
134 if (msg == NULL || transfer_op_flag == NULL || table_type == NULL ||
135 transfer_handle == NULL) {
136 return PLDM_ERROR_INVALID_DATA;
137 }
138
139 if (payload_length != PLDM_GET_BIOS_TABLE_REQ_BYTES) {
140 return PLDM_ERROR_INVALID_LENGTH;
141 }
142
143 struct pldm_get_bios_table_req *request =
144 (struct pldm_get_bios_table_req *)msg->payload;
145 *transfer_handle = le32toh(request->transfer_handle);
146 *transfer_op_flag = request->transfer_op_flag;
147 *table_type = request->table_type;
148
149 return PLDM_SUCCESS;
150}