blob: abf7df42a3a0b29e3c909149eba8f04e4dfb338e [file] [log] [blame]
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -05001#include "bios.h"
Sampa Misra032bd502019-03-06 05:03:22 -06002#include <endian.h>
3#include <string.h>
4
Sampa Misra032bd502019-03-06 05:03:22 -06005int encode_get_date_time_req(uint8_t instance_id, struct pldm_msg *msg)
6{
7 struct pldm_header_info header = {0};
8
9 if (msg == NULL) {
10 return PLDM_ERROR_INVALID_DATA;
11 }
12
13 header.msg_type = PLDM_REQUEST;
14 header.instance = instance_id;
15 header.pldm_type = PLDM_BIOS;
16 header.command = PLDM_GET_DATE_TIME;
17 return pack_pldm_header(&header, &(msg->hdr));
18}
19
20int encode_get_date_time_resp(uint8_t instance_id, uint8_t completion_code,
21 uint8_t seconds, uint8_t minutes, uint8_t hours,
22 uint8_t day, uint8_t month, uint16_t year,
23 struct pldm_msg *msg)
24{
25 struct pldm_header_info header = {0};
26 int rc = PLDM_SUCCESS;
27
28 if (msg == NULL) {
29 return PLDM_ERROR_INVALID_DATA;
30 }
31
Sampa Misra032bd502019-03-06 05:03:22 -060032 header.msg_type = PLDM_RESPONSE;
33 header.instance = instance_id;
34 header.pldm_type = PLDM_BIOS;
35 header.command = PLDM_GET_DATE_TIME;
Zahed Hossain43264522019-06-04 02:21:03 -050036
Priyanga5dcd1802019-06-10 01:50:39 -050037 struct pldm_get_date_time_resp *response =
38 (struct pldm_get_date_time_resp *)msg->payload;
39
Sampa Misra032bd502019-03-06 05:03:22 -060040 if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
41 return rc;
42 }
43
Priyanga5dcd1802019-06-10 01:50:39 -050044 response->completion_code = completion_code;
45 if (response->completion_code == PLDM_SUCCESS) {
46 response->completion_code = completion_code;
47 response->seconds = seconds;
48 response->minutes = minutes;
49 response->hours = hours;
50 response->day = day;
51 response->month = month;
52 response->year = htole16(year);
Zahed Hossain43264522019-06-04 02:21:03 -050053 }
Sampa Misra032bd502019-03-06 05:03:22 -060054 return PLDM_SUCCESS;
55}
56
Zahed Hossain223a73d2019-07-04 12:46:18 -050057int decode_get_date_time_resp(const struct pldm_msg *msg, size_t payload_length,
Sampa Misra032bd502019-03-06 05:03:22 -060058 uint8_t *completion_code, uint8_t *seconds,
59 uint8_t *minutes, uint8_t *hours, uint8_t *day,
60 uint8_t *month, uint16_t *year)
61{
62 if (msg == NULL || seconds == NULL || minutes == NULL ||
63 hours == NULL || day == NULL || month == NULL || year == NULL ||
64 completion_code == NULL) {
65 return PLDM_ERROR_INVALID_DATA;
66 }
67
vkaverapa6575b82019-04-03 05:33:52 -050068 if (payload_length != PLDM_GET_DATE_TIME_RESP_BYTES) {
69 return PLDM_ERROR_INVALID_LENGTH;
70 }
71
Priyanga5dcd1802019-06-10 01:50:39 -050072 struct pldm_get_date_time_resp *response =
Zahed Hossain223a73d2019-07-04 12:46:18 -050073 (struct pldm_get_date_time_resp *)msg->payload;
Priyanga5dcd1802019-06-10 01:50:39 -050074 *completion_code = response->completion_code;
75
Sampa Misra032bd502019-03-06 05:03:22 -060076 if (PLDM_SUCCESS != *completion_code) {
77 return PLDM_SUCCESS;
78 }
Priyanga5dcd1802019-06-10 01:50:39 -050079 *seconds = response->seconds;
80 *minutes = response->minutes;
81 *hours = response->hours;
82 *day = response->day;
83 *month = response->month;
84 *year = le16toh(response->year);
Sampa Misra032bd502019-03-06 05:03:22 -060085
86 return PLDM_SUCCESS;
87}
Sampa Misrab37be312019-07-03 02:26:41 -050088
89int encode_get_bios_table_resp(uint8_t instance_id, uint8_t completion_code,
90 uint32_t next_transfer_handle,
91 uint8_t transfer_flag, uint8_t *table_data,
92 size_t payload_length, struct pldm_msg *msg)
93{
94 struct pldm_header_info header = {0};
95 int rc = PLDM_SUCCESS;
96
97 if (msg == NULL) {
98 return PLDM_ERROR_INVALID_DATA;
99 }
100
101 struct pldm_get_bios_table_resp *response =
102 (struct pldm_get_bios_table_resp *)msg->payload;
103
104 response->completion_code = completion_code;
105 header.msg_type = PLDM_RESPONSE;
106 header.instance = instance_id;
107 header.pldm_type = PLDM_BIOS;
108 header.command = PLDM_GET_BIOS_TABLE;
109 if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
110 return rc;
111 }
112
113 if (response->completion_code == PLDM_SUCCESS) {
114
115 response->next_transfer_handle = htole32(next_transfer_handle);
116 response->transfer_flag = transfer_flag;
117 if (table_data != NULL &&
118 payload_length > (sizeof(struct pldm_msg_hdr) +
119 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES)) {
120 memcpy(response->table_data, table_data,
121 payload_length -
122 (sizeof(struct pldm_msg_hdr) +
123 PLDM_GET_BIOS_TABLE_MIN_RESP_BYTES));
124 }
125 }
126 return PLDM_SUCCESS;
127}
128
Sridevi Rameshd3d5fa82019-10-29 11:45:16 -0500129int encode_get_bios_table_req(uint8_t instance_id, uint32_t transfer_handle,
130 uint8_t transfer_op_flag, uint8_t table_type,
131 struct pldm_msg *msg)
132{
133 struct pldm_header_info header = {0};
134
135 if (msg == NULL) {
136 return PLDM_ERROR_INVALID_DATA;
137 }
138
139 header.msg_type = PLDM_REQUEST;
140 header.instance = instance_id;
141 header.pldm_type = PLDM_BIOS;
142 header.command = PLDM_GET_BIOS_TABLE;
143 pack_pldm_header(&header, &(msg->hdr));
144
145 struct pldm_get_bios_table_req *request =
146 (struct pldm_get_bios_table_req *)msg->payload;
147
148 request->transfer_handle = htole32(transfer_handle);
149 request->transfer_op_flag = transfer_op_flag;
150 request->table_type = table_type;
151 return PLDM_SUCCESS;
152}
153
Sampa Misrab37be312019-07-03 02:26:41 -0500154int decode_get_bios_table_req(const struct pldm_msg *msg, size_t payload_length,
155 uint32_t *transfer_handle,
156 uint8_t *transfer_op_flag, uint8_t *table_type)
157{
158 if (msg == NULL || transfer_op_flag == NULL || table_type == NULL ||
159 transfer_handle == NULL) {
160 return PLDM_ERROR_INVALID_DATA;
161 }
162
163 if (payload_length != PLDM_GET_BIOS_TABLE_REQ_BYTES) {
164 return PLDM_ERROR_INVALID_LENGTH;
165 }
166
167 struct pldm_get_bios_table_req *request =
168 (struct pldm_get_bios_table_req *)msg->payload;
169 *transfer_handle = le32toh(request->transfer_handle);
170 *transfer_op_flag = request->transfer_op_flag;
171 *table_type = request->table_type;
172
173 return PLDM_SUCCESS;
174}
Zahed Hossaind69af0b2019-07-30 01:33:31 -0500175
176int decode_get_bios_attribute_current_value_by_handle_req(
177 const struct pldm_msg *msg, size_t payload_length,
178 uint32_t *transfer_handle, uint8_t *transfer_op_flag,
179 uint16_t *attribute_handle)
180{
181 if (msg == NULL || transfer_handle == NULL ||
182 transfer_op_flag == NULL || attribute_handle == NULL) {
183 return PLDM_ERROR_INVALID_DATA;
184 }
185
186 if (payload_length != PLDM_GET_BIOS_ATTR_CURR_VAL_BY_HANDLE_REQ_BYTES) {
187 return PLDM_ERROR_INVALID_LENGTH;
188 }
189
190 struct pldm_get_bios_attribute_current_value_by_handle_req *request =
191 (struct pldm_get_bios_attribute_current_value_by_handle_req *)
192 msg->payload;
193 *transfer_handle = le32toh(request->transfer_handle);
194 *transfer_op_flag = request->transfer_op_flag;
195 *attribute_handle = le16toh(request->attribute_handle);
196
197 return PLDM_SUCCESS;
198}
199
200int encode_get_bios_current_value_by_handle_resp(
201 uint8_t instance_id, uint8_t completion_code, uint32_t next_transfer_handle,
202 uint8_t transfer_flag, const uint8_t *attribute_data,
203 size_t attribute_length, struct pldm_msg *msg)
204{
205 struct pldm_header_info header = {0};
206 int rc = PLDM_SUCCESS;
207
208 if (msg == NULL || attribute_data == NULL) {
209 return PLDM_ERROR_INVALID_DATA;
210 }
211
212 struct pldm_get_bios_attribute_current_value_by_handle_resp *response =
213 (struct pldm_get_bios_attribute_current_value_by_handle_resp *)
214 msg->payload;
215
216 response->completion_code = completion_code;
217 header.msg_type = PLDM_RESPONSE;
218 header.instance = instance_id;
219 header.pldm_type = PLDM_BIOS;
220 header.command = PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE;
221 if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) {
222 return rc;
223 }
224 if (response->completion_code == PLDM_SUCCESS) {
225
226 response->next_transfer_handle = htole32(next_transfer_handle);
227 response->transfer_flag = transfer_flag;
228 if (attribute_data != NULL) {
229 memcpy(response->attribute_data, attribute_data,
230 attribute_length);
231 }
232 }
233 return PLDM_SUCCESS;
234}
John Wang4d844792019-08-15 15:51:40 +0800235int encode_set_bios_attribute_current_value_req(
236 uint8_t instance_id, uint32_t transfer_handle, uint8_t transfer_flag,
237 const uint8_t *attribute_data, size_t attribute_length,
238 struct pldm_msg *msg, size_t payload_lenth)
239{
240 if (msg == NULL || attribute_data == NULL) {
241 return PLDM_ERROR_INVALID_DATA;
242 }
243 if (PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES + attribute_length !=
244 payload_lenth) {
245 return PLDM_ERROR_INVALID_LENGTH;
246 }
247 struct pldm_header_info header = {0};
248 header.instance = instance_id;
249 header.msg_type = PLDM_REQUEST;
250 header.pldm_type = PLDM_BIOS;
251 header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
252 pack_pldm_header(&header, &msg->hdr);
253
254 struct pldm_set_bios_attribute_current_value_req *request =
255 (struct pldm_set_bios_attribute_current_value_req *)msg->payload;
256 request->transfer_handle = htole32(transfer_handle);
257 request->transfer_flag = transfer_flag;
258 memcpy(request->attribute_data, attribute_data, attribute_length);
259
260 return PLDM_SUCCESS;
261}
262
263int decode_set_bios_attribute_current_value_resp(const struct pldm_msg *msg,
264 size_t payload_length,
265 uint8_t *completion_code,
266 uint32_t *next_transfer_handle)
267{
268 if (msg == NULL || completion_code == NULL ||
269 next_transfer_handle == NULL) {
270 return PLDM_ERROR_INVALID_DATA;
271 }
272 if (payload_length != PLDM_SET_BIOS_ATTR_CURR_VAL_RESP_BYTES) {
273 return PLDM_ERROR_INVALID_LENGTH;
274 }
275
276 struct pldm_set_bios_attribute_current_value_resp *response =
277 (struct pldm_set_bios_attribute_current_value_resp *)msg->payload;
278
279 *completion_code = response->completion_code;
280 if (PLDM_SUCCESS != *completion_code) {
281 return PLDM_SUCCESS;
282 }
283 *next_transfer_handle = le32toh(response->next_transfer_handle);
284
285 return PLDM_SUCCESS;
286}
287
288int decode_set_bios_attribute_current_value_req(const struct pldm_msg *msg,
289 size_t payload_length,
290 uint32_t *transfer_handle,
291 uint8_t *transfer_flag,
292 uint8_t *attribute_data,
293 size_t *attribute_length)
294{
295 if (msg == NULL || transfer_handle == NULL || transfer_flag == NULL ||
296 attribute_data == NULL || attribute_length == NULL) {
297 return PLDM_ERROR_INVALID_DATA;
298 }
299 if (payload_length < PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES) {
300 return PLDM_ERROR_INVALID_LENGTH;
301 }
302
303 struct pldm_set_bios_attribute_current_value_req *request =
304 (struct pldm_set_bios_attribute_current_value_req *)msg->payload;
305 *transfer_handle = le32toh(request->transfer_handle);
306 *transfer_flag = request->transfer_flag;
307 *attribute_length =
308 payload_length - PLDM_SET_BIOS_ATTR_CURR_VAL_MIN_REQ_BYTES;
309 memcpy(attribute_data, request->attribute_data, *attribute_length);
310
311 return PLDM_SUCCESS;
312}
313
314int encode_set_bios_attribute_current_value_resp(uint8_t instance_id,
315 uint8_t completion_code,
316 uint32_t next_transfer_handle,
317 struct pldm_msg *msg)
318{
319 if (msg == NULL) {
320 return PLDM_ERROR_INVALID_DATA;
321 }
322 struct pldm_header_info header = {0};
323 header.instance = instance_id;
324 header.msg_type = PLDM_RESPONSE;
325 header.pldm_type = PLDM_BIOS;
326 header.command = PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE;
327
328 int rc = pack_pldm_header(&header, &msg->hdr);
329 if (rc != PLDM_SUCCESS) {
330 return rc;
331 }
332
333 struct pldm_set_bios_attribute_current_value_resp *response =
334 (struct pldm_set_bios_attribute_current_value_resp *)msg->payload;
335 response->completion_code = completion_code;
336 response->next_transfer_handle = htole32(next_transfer_handle);
337
338 return PLDM_SUCCESS;
339}