blob: 212ed79f0404564d4238b168e374cc2b7c3ebde7 [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}
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500151
152int decode_get_bios_attribute_current_value_by_handle_req(
153 const struct pldm_msg *msg, size_t payload_length,
154 uint32_t *transfer_handle, uint8_t *transfer_op_flag,
155 uint16_t *attribute_handle)
156{
157 if (msg == NULL || transfer_handle == NULL ||
158 transfer_op_flag == NULL || attribute_handle == NULL) {
159 return PLDM_ERROR_INVALID_DATA;
160 }
161
162 if (payload_length != PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_REQ_BYTES) {
163 return PLDM_ERROR_INVALID_LENGTH;
164 }
165
166 struct pldm_get_bios_attribute_current_value_by_handle_req *request =
167 (struct pldm_get_bios_attribute_current_value_by_handle_req *)
168 msg->payload;
169 *transfer_handle = le32toh(request->transfer_handle);
170 *transfer_op_flag = request->transfer_op_flag;
171 *attribute_handle = le16toh(request->attribute_handle);
172
173 return PLDM_SUCCESS;
174}
175
176int encode_get_bios_current_value_by_handle_resp(
177 uint8_t instance_id, uint8_t completion_code, uint32_t next_transfer_handle,
178 uint8_t transfer_flag, const uint8_t *attribute_data,
179 size_t attribute_length, struct pldm_msg *msg)
180{
181 struct pldm_header_info header = {0};
182 int rc = PLDM_SUCCESS;
183
184 if (msg == NULL || attribute_data == NULL) {
185 return PLDM_ERROR_INVALID_DATA;
186 }
187
188 struct pldm_get_bios_attribute_current_value_by_handle_resp *response =
189 (struct pldm_get_bios_attribute_current_value_by_handle_resp *)
190 msg->payload;
191
192 response->completion_code = completion_code;
193 header.msg_type = PLDM_RESPONSE;
194 header.instance = instance_id;
195 header.pldm_type = PLDM_BIOS;
196 header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
197 if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
198 return rc;
199 }
200 if (response->completion_code == PLDM_SUCCESS) {
201
202 response->next_transfer_handle = htole32(next_transfer_handle);
203 response->transfer_flag = transfer_flag;
204 if (attribute_data != NULL) {
205 memcpy(response->attribute_data, attribute_data,
206 attribute_length);
207 }
208 }
209 return PLDM_SUCCESS;
210}