blob: 01d3e431c054fdd86cb3b4f164a1c9b5e5cece9b [file] [log] [blame]
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09301#include "config.h"
Andrew Jeffery9c766792022-08-10 23:12:49 +09302#include "libpldm/file_io.h"
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05303#include "base.h"
Andrew Jeffery9c766792022-08-10 23:12:49 +09304#include <endian.h>
5#include <string.h>
6
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09307LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +09308int decode_rw_file_memory_req(const struct pldm_msg *msg, size_t payload_length,
9 uint32_t *file_handle, uint32_t *offset,
10 uint32_t *length, uint64_t *address)
11{
12 if (msg == NULL || file_handle == NULL || offset == NULL ||
13 length == NULL || address == NULL) {
14 return PLDM_ERROR_INVALID_DATA;
15 }
16
17 if (payload_length != PLDM_RW_FILE_MEM_REQ_BYTES) {
18 return PLDM_ERROR_INVALID_LENGTH;
19 }
20
21 struct pldm_read_write_file_memory_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093022 (struct pldm_read_write_file_memory_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093023
24 *file_handle = le32toh(request->file_handle);
25 *offset = le32toh(request->offset);
26 *length = le32toh(request->length);
27 *address = le64toh(request->address);
28
29 return PLDM_SUCCESS;
30}
31
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093032LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093033int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command,
34 uint8_t completion_code, uint32_t length,
35 struct pldm_msg *msg)
36{
37 if (msg == NULL) {
38 return PLDM_ERROR_INVALID_LENGTH;
39 }
40
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093041 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093042 header.msg_type = PLDM_RESPONSE;
43 header.instance = instance_id;
44 header.pldm_type = PLDM_OEM;
45 header.command = command;
46 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
47 if (rc != PLDM_SUCCESS) {
48 return rc;
49 }
50
51 struct pldm_read_write_file_memory_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093052 (struct pldm_read_write_file_memory_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093053 response->completion_code = completion_code;
54 if (response->completion_code == PLDM_SUCCESS) {
55 response->length = htole32(length);
56 }
57
58 return PLDM_SUCCESS;
59}
60
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093061LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093062int encode_rw_file_memory_req(uint8_t instance_id, uint8_t command,
63 uint32_t file_handle, uint32_t offset,
64 uint32_t length, uint64_t address,
65 struct pldm_msg *msg)
66{
67 if (msg == NULL) {
68 return PLDM_ERROR_INVALID_DATA;
69 }
70
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093071 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093072 header.msg_type = PLDM_REQUEST;
73 header.instance = instance_id;
74 header.pldm_type = PLDM_OEM;
75 header.command = command;
76 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
77 if (rc != PLDM_SUCCESS) {
78 return rc;
79 }
80
81 struct pldm_read_write_file_memory_req *req =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093082 (struct pldm_read_write_file_memory_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093083 req->file_handle = htole32(file_handle);
84 req->offset = htole32(offset);
85 req->length = htole32(length);
86 req->address = htole64(address);
87 return PLDM_SUCCESS;
88}
89
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093090LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093091int decode_rw_file_memory_resp(const struct pldm_msg *msg,
92 size_t payload_length, uint8_t *completion_code,
93 uint32_t *length)
94{
95 if (msg == NULL || length == NULL || completion_code == NULL) {
96 return PLDM_ERROR_INVALID_DATA;
97 }
98
99 if (payload_length != PLDM_RW_FILE_MEM_RESP_BYTES) {
100 return PLDM_ERROR_INVALID_LENGTH;
101 }
102
103 struct pldm_read_write_file_memory_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930104 (struct pldm_read_write_file_memory_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930105 *completion_code = response->completion_code;
106 if (*completion_code == PLDM_SUCCESS) {
107 *length = le32toh(response->length);
108 }
109
110 return PLDM_SUCCESS;
111}
112
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930113LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930114int decode_get_file_table_req(const struct pldm_msg *msg, size_t payload_length,
115 uint32_t *transfer_handle,
116 uint8_t *transfer_opflag, uint8_t *table_type)
117{
118 if (msg == NULL || transfer_handle == NULL || transfer_opflag == NULL ||
119 table_type == NULL) {
120 return PLDM_ERROR_INVALID_DATA;
121 }
122
123 if (payload_length != PLDM_GET_FILE_TABLE_REQ_BYTES) {
124 return PLDM_ERROR_INVALID_LENGTH;
125 }
126
127 struct pldm_get_file_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930128 (struct pldm_get_file_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930129
130 *transfer_handle = le32toh(request->transfer_handle);
131 *transfer_opflag = request->operation_flag;
132 *table_type = request->table_type;
133
134 return PLDM_SUCCESS;
135}
136
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930137LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930138int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code,
139 uint32_t next_transfer_handle,
140 uint8_t transfer_flag, const uint8_t *table_data,
141 size_t table_size, struct pldm_msg *msg)
142{
143 if (msg == NULL) {
144 return PLDM_ERROR_INVALID_LENGTH;
145 }
146
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930147 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930148 header.msg_type = PLDM_RESPONSE;
149 header.instance = instance_id;
150 header.pldm_type = PLDM_OEM;
151 header.command = PLDM_GET_FILE_TABLE;
152 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
153 if (rc != PLDM_SUCCESS) {
154 return rc;
155 }
156
157 struct pldm_get_file_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930158 (struct pldm_get_file_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930159 response->completion_code = completion_code;
160
161 if (completion_code == PLDM_SUCCESS) {
162 response->next_transfer_handle = htole32(next_transfer_handle);
163 response->transfer_flag = transfer_flag;
164 memcpy(response->table_data, table_data, table_size);
165 }
166
167 return PLDM_SUCCESS;
168}
169
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930170LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930171int encode_get_file_table_req(uint8_t instance_id, uint32_t transfer_handle,
172 uint8_t transfer_opflag, uint8_t table_type,
173 struct pldm_msg *msg)
174{
175 if (msg == NULL) {
176 return PLDM_ERROR_INVALID_DATA;
177 }
178
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930179 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930180 header.msg_type = PLDM_REQUEST;
181 header.instance = instance_id;
182 header.pldm_type = PLDM_OEM;
183 header.command = PLDM_GET_FILE_TABLE;
184 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
185 if (rc != PLDM_SUCCESS) {
186 return rc;
187 }
188
189 struct pldm_get_file_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930190 (struct pldm_get_file_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930191
192 request->transfer_handle = htole32(transfer_handle);
193 request->operation_flag = transfer_opflag;
194 request->table_type = table_type;
195 return PLDM_SUCCESS;
196}
197
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930198LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930199int decode_get_file_table_resp(const struct pldm_msg *msg,
200 size_t payload_length, uint8_t *completion_code,
201 uint32_t *next_transfer_handle,
202 uint8_t *transfer_flag,
203 uint8_t *file_table_data_start_offset,
204 size_t *file_table_length)
205{
206 if (msg == NULL || transfer_flag == NULL ||
207 next_transfer_handle == NULL || completion_code == NULL ||
208 file_table_data_start_offset == NULL || file_table_length == NULL) {
209 return PLDM_ERROR_INVALID_DATA;
210 }
211
212 if (payload_length <= PLDM_GET_FILE_TABLE_MIN_RESP_BYTES) {
213 return PLDM_ERROR_INVALID_LENGTH;
214 }
215
216 *completion_code = msg->payload[0];
217
218 if (PLDM_SUCCESS != *completion_code) {
219 return PLDM_SUCCESS;
220 }
221
222 struct pldm_get_file_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930223 (struct pldm_get_file_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930224
225 *next_transfer_handle = le32toh(response->next_transfer_handle);
226 *transfer_flag = response->transfer_flag;
227 *file_table_data_start_offset = sizeof(*completion_code) +
228 sizeof(*next_transfer_handle) +
229 sizeof(*transfer_flag);
230 *file_table_length =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930231 payload_length - PLDM_GET_FILE_TABLE_MIN_RESP_BYTES;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930232
233 return PLDM_SUCCESS;
234}
235
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930236LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930237int decode_read_file_req(const struct pldm_msg *msg, size_t payload_length,
238 uint32_t *file_handle, uint32_t *offset,
239 uint32_t *length)
240{
241 if (msg == NULL || file_handle == NULL || offset == NULL ||
242 length == NULL) {
243 return PLDM_ERROR_INVALID_DATA;
244 }
245
246 if (payload_length != PLDM_READ_FILE_REQ_BYTES) {
247 return PLDM_ERROR_INVALID_LENGTH;
248 }
249
250 struct pldm_read_file_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930251 (struct pldm_read_file_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930252
253 *file_handle = le32toh(request->file_handle);
254 *offset = le32toh(request->offset);
255 *length = le32toh(request->length);
256
257 return PLDM_SUCCESS;
258}
259
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930260LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930261int encode_read_file_req(uint8_t instance_id, uint32_t file_handle,
262 uint32_t offset, uint32_t length, struct pldm_msg *msg)
263{
264 if (msg == NULL) {
265 return PLDM_ERROR_INVALID_DATA;
266 }
267
268 if (length == 0) {
269 return PLDM_ERROR_INVALID_LENGTH;
270 }
271
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930272 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930273 header.msg_type = PLDM_REQUEST;
274 header.instance = instance_id;
275 header.pldm_type = PLDM_OEM;
276 header.command = PLDM_READ_FILE;
277 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
278 if (rc != PLDM_SUCCESS) {
279 return rc;
280 }
281
282 struct pldm_read_file_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930283 (struct pldm_read_file_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930284
285 request->file_handle = htole32(file_handle);
286 request->offset = htole32(offset);
287 request->length = htole32(length);
288
289 return PLDM_SUCCESS;
290}
291
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930292LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930293int decode_read_file_resp(const struct pldm_msg *msg, size_t payload_length,
294 uint8_t *completion_code, uint32_t *length,
295 size_t *file_data_offset)
296{
297 if (msg == NULL || completion_code == NULL || length == NULL) {
298 return PLDM_ERROR_INVALID_DATA;
299 }
300
301 if (payload_length < PLDM_READ_FILE_RESP_BYTES) {
302 return PLDM_ERROR_INVALID_LENGTH;
303 }
304
305 struct pldm_read_file_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930306 (struct pldm_read_file_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930307
308 *completion_code = response->completion_code;
309 if (*completion_code == PLDM_SUCCESS) {
310 *length = le32toh(response->length);
311 if (payload_length != PLDM_READ_FILE_RESP_BYTES + *length) {
312 return PLDM_ERROR_INVALID_LENGTH;
313 }
314 *file_data_offset = sizeof(*completion_code) + sizeof(*length);
315 }
316
317 return PLDM_SUCCESS;
318}
319
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930320LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930321int encode_read_file_resp(uint8_t instance_id, uint8_t completion_code,
322 uint32_t length, struct pldm_msg *msg)
323{
324 if (msg == NULL) {
325 return PLDM_ERROR_INVALID_DATA;
326 }
327
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930328 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930329 header.msg_type = PLDM_RESPONSE;
330 header.instance = instance_id;
331 header.pldm_type = PLDM_OEM;
332 header.command = PLDM_READ_FILE;
333 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
334 if (rc != PLDM_SUCCESS) {
335 return rc;
336 }
337
338 struct pldm_read_file_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930339 (struct pldm_read_file_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930340 response->completion_code = completion_code;
341
342 if (response->completion_code == PLDM_SUCCESS) {
343 response->length = htole32(length);
344 }
345
346 return PLDM_SUCCESS;
347}
348
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930349LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930350int decode_write_file_req(const struct pldm_msg *msg, size_t payload_length,
351 uint32_t *file_handle, uint32_t *offset,
352 uint32_t *length, size_t *file_data_offset)
353{
354 if (msg == NULL || file_handle == NULL || length == NULL) {
355 return PLDM_ERROR_INVALID_DATA;
356 }
357
358 if (payload_length < PLDM_WRITE_FILE_REQ_BYTES) {
359 return PLDM_ERROR_INVALID_LENGTH;
360 }
361
362 struct pldm_write_file_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930363 (struct pldm_write_file_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930364
365 *file_handle = le32toh(request->file_handle);
366 *offset = le32toh(request->offset);
367 *length = le32toh(request->length);
368 if (payload_length != PLDM_WRITE_FILE_REQ_BYTES + *length) {
369 return PLDM_ERROR_INVALID_LENGTH;
370 }
371 *file_data_offset =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930372 sizeof(*file_handle) + sizeof(*offset) + sizeof(*length);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930373
374 return PLDM_SUCCESS;
375}
376
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930377LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930378int encode_write_file_req(uint8_t instance_id, uint32_t file_handle,
379 uint32_t offset, uint32_t length,
380 struct pldm_msg *msg)
381{
382 if (msg == NULL) {
383 return PLDM_ERROR_INVALID_DATA;
384 }
385
386 if (length == 0) {
387 return PLDM_ERROR_INVALID_LENGTH;
388 }
389
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930390 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930391 header.msg_type = PLDM_REQUEST;
392 header.instance = instance_id;
393 header.pldm_type = PLDM_OEM;
394 header.command = PLDM_WRITE_FILE;
395 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
396 if (rc != PLDM_SUCCESS) {
397 return rc;
398 }
399
400 struct pldm_write_file_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930401 (struct pldm_write_file_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930402
403 request->file_handle = htole32(file_handle);
404 request->offset = htole32(offset);
405 request->length = htole32(length);
406
407 return PLDM_SUCCESS;
408}
409
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930410LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930411int decode_write_file_resp(const struct pldm_msg *msg, size_t payload_length,
412 uint8_t *completion_code, uint32_t *length)
413{
414 if (msg == NULL || completion_code == NULL || length == NULL) {
415 return PLDM_ERROR_INVALID_DATA;
416 }
417
418 if (payload_length != PLDM_WRITE_FILE_RESP_BYTES) {
419 return PLDM_ERROR_INVALID_LENGTH;
420 }
421
422 struct pldm_write_file_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930423 (struct pldm_write_file_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930424
425 *completion_code = le32toh(response->completion_code);
426 if (response->completion_code == PLDM_SUCCESS) {
427 *length = le32toh(response->length);
428 }
429
430 return PLDM_SUCCESS;
431}
432
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930433LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930434int encode_write_file_resp(uint8_t instance_id, uint8_t completion_code,
435 uint32_t length, struct pldm_msg *msg)
436{
437 if (msg == NULL) {
438 return PLDM_ERROR_INVALID_DATA;
439 }
440
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930441 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930442 header.msg_type = PLDM_RESPONSE;
443 header.instance = instance_id;
444 header.pldm_type = PLDM_OEM;
445 header.command = PLDM_WRITE_FILE;
446 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
447 if (rc != PLDM_SUCCESS) {
448 return rc;
449 }
450
451 struct pldm_write_file_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930452 (struct pldm_write_file_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930453 response->completion_code = completion_code;
454
455 if (response->completion_code == PLDM_SUCCESS) {
456 response->length = htole32(length);
457 }
458
459 return PLDM_SUCCESS;
460}
461
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930462LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930463int decode_rw_file_by_type_memory_req(const struct pldm_msg *msg,
464 size_t payload_length,
465 uint16_t *file_type,
466 uint32_t *file_handle, uint32_t *offset,
467 uint32_t *length, uint64_t *address)
468{
469 if (msg == NULL || file_type == NULL || file_handle == NULL ||
470 offset == NULL || length == NULL || address == NULL) {
471 return PLDM_ERROR_INVALID_DATA;
472 }
473
474 if (payload_length != PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES) {
475 return PLDM_ERROR_INVALID_LENGTH;
476 }
477
478 struct pldm_read_write_file_by_type_memory_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930479 (struct pldm_read_write_file_by_type_memory_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930480 *file_type = le16toh(request->file_type);
481 *file_handle = le32toh(request->file_handle);
482 *offset = le32toh(request->offset);
483 *length = le32toh(request->length);
484 *address = le64toh(request->address);
485
486 return PLDM_SUCCESS;
487}
488
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930489LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930490int encode_rw_file_by_type_memory_resp(uint8_t instance_id, uint8_t command,
491 uint8_t completion_code, uint32_t length,
492 struct pldm_msg *msg)
493{
494 if (msg == NULL) {
495 return PLDM_ERROR_INVALID_DATA;
496 }
497
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930498 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930499 header.msg_type = PLDM_RESPONSE;
500 header.instance = instance_id;
501 header.pldm_type = PLDM_OEM;
502 header.command = command;
503 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
504 if (rc != PLDM_SUCCESS) {
505 return rc;
506 }
507
508 struct pldm_read_write_file_by_type_memory_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930509 (struct pldm_read_write_file_by_type_memory_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930510 response->completion_code = completion_code;
511 if (response->completion_code == PLDM_SUCCESS) {
512 response->length = htole32(length);
513 }
514
515 return PLDM_SUCCESS;
516}
517
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930518LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930519int encode_rw_file_by_type_memory_req(uint8_t instance_id, uint8_t command,
520 uint16_t file_type, uint32_t file_handle,
521 uint32_t offset, uint32_t length,
522 uint64_t address, struct pldm_msg *msg)
523{
524 if (msg == NULL) {
525 return PLDM_ERROR_INVALID_DATA;
526 }
527
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930528 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930529 header.msg_type = PLDM_REQUEST;
530 header.instance = instance_id;
531 header.pldm_type = PLDM_OEM;
532 header.command = command;
533 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
534 if (rc != PLDM_SUCCESS) {
535 return rc;
536 }
537
538 struct pldm_read_write_file_by_type_memory_req *req =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930539 (struct pldm_read_write_file_by_type_memory_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930540 req->file_type = htole16(file_type);
541 req->file_handle = htole32(file_handle);
542 req->offset = htole32(offset);
543 req->length = htole32(length);
544 req->address = htole64(address);
545
546 return PLDM_SUCCESS;
547}
548
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930549LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930550int decode_rw_file_by_type_memory_resp(const struct pldm_msg *msg,
551 size_t payload_length,
552 uint8_t *completion_code,
553 uint32_t *length)
554{
555 if (msg == NULL || length == NULL || completion_code == NULL) {
556 return PLDM_ERROR_INVALID_DATA;
557 }
558
559 if (payload_length != PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES) {
560 return PLDM_ERROR_INVALID_LENGTH;
561 }
562
563 struct pldm_read_write_file_by_type_memory_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930564 (struct pldm_read_write_file_by_type_memory_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930565 *completion_code = response->completion_code;
566 if (*completion_code == PLDM_SUCCESS) {
567 *length = le32toh(response->length);
568 }
569
570 return PLDM_SUCCESS;
571}
572
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930573LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930574int decode_new_file_req(const struct pldm_msg *msg, size_t payload_length,
575 uint16_t *file_type, uint32_t *file_handle,
576 uint64_t *length)
577{
578 if (msg == NULL || file_type == NULL || file_handle == NULL ||
579 length == NULL) {
580 return PLDM_ERROR_INVALID_DATA;
581 }
582
583 if (payload_length != PLDM_NEW_FILE_REQ_BYTES) {
584 return PLDM_ERROR_INVALID_LENGTH;
585 }
586
587 struct pldm_new_file_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930588 (struct pldm_new_file_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930589 *file_type = le16toh(request->file_type);
590 *file_handle = le32toh(request->file_handle);
591 *length = le64toh(request->length);
592
593 return PLDM_SUCCESS;
594}
595
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930596LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930597int encode_new_file_resp(uint8_t instance_id, uint8_t completion_code,
598 struct pldm_msg *msg)
599{
600 if (msg == NULL) {
601 return PLDM_ERROR_INVALID_DATA;
602 }
603
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930604 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930605 header.msg_type = PLDM_RESPONSE;
606 header.instance = instance_id;
607 header.pldm_type = PLDM_OEM;
608 header.command = PLDM_NEW_FILE_AVAILABLE;
609 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
610 if (rc != PLDM_SUCCESS) {
611 return rc;
612 }
613
614 struct pldm_new_file_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930615 (struct pldm_new_file_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930616 response->completion_code = completion_code;
617
618 return PLDM_SUCCESS;
619}
620
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930621LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930622int encode_new_file_req(uint8_t instance_id, uint16_t file_type,
623 uint32_t file_handle, uint64_t length,
624 struct pldm_msg *msg)
625{
626 if (msg == NULL) {
627 return PLDM_ERROR_INVALID_DATA;
628 }
629
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930630 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930631 header.msg_type = PLDM_REQUEST;
632 header.instance = instance_id;
633 header.pldm_type = PLDM_OEM;
634 header.command = PLDM_NEW_FILE_AVAILABLE;
635 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
636 if (rc != PLDM_SUCCESS) {
637 return rc;
638 }
639
640 struct pldm_new_file_req *req =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930641 (struct pldm_new_file_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930642 req->file_type = htole16(file_type);
643 req->file_handle = htole32(file_handle);
644 req->length = htole64(length);
645
646 return PLDM_SUCCESS;
647}
648
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930649LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930650int decode_new_file_resp(const struct pldm_msg *msg, size_t payload_length,
651 uint8_t *completion_code)
652{
653 if (msg == NULL || completion_code == NULL) {
654 return PLDM_ERROR_INVALID_DATA;
655 }
656
657 if (payload_length != PLDM_NEW_FILE_RESP_BYTES) {
658 return PLDM_ERROR_INVALID_LENGTH;
659 }
660
661 struct pldm_new_file_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930662 (struct pldm_new_file_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930663 *completion_code = response->completion_code;
664
665 return PLDM_SUCCESS;
666}
667
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930668LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930669int decode_rw_file_by_type_req(const struct pldm_msg *msg,
670 size_t payload_length, uint16_t *file_type,
671 uint32_t *file_handle, uint32_t *offset,
672 uint32_t *length)
673{
674 if (msg == NULL || file_type == NULL || file_handle == NULL ||
675 offset == NULL || length == NULL) {
676 return PLDM_ERROR_INVALID_DATA;
677 }
678
679 if (payload_length < PLDM_RW_FILE_BY_TYPE_REQ_BYTES) {
680 return PLDM_ERROR_INVALID_LENGTH;
681 }
682
683 struct pldm_read_write_file_by_type_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930684 (struct pldm_read_write_file_by_type_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930685 *file_type = le16toh(request->file_type);
686 *file_handle = le32toh(request->file_handle);
687 *offset = le32toh(request->offset);
688 *length = le32toh(request->length);
689
690 return PLDM_SUCCESS;
691}
692
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930693LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930694int encode_rw_file_by_type_resp(uint8_t instance_id, uint8_t command,
695 uint8_t completion_code, uint32_t length,
696 struct pldm_msg *msg)
697{
698 if (msg == NULL) {
699 return PLDM_ERROR_INVALID_DATA;
700 }
701 if (command != PLDM_READ_FILE_BY_TYPE &&
702 command != PLDM_WRITE_FILE_BY_TYPE) {
703 return PLDM_ERROR_INVALID_DATA;
704 }
705
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930706 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930707 header.msg_type = PLDM_RESPONSE;
708 header.instance = instance_id;
709 header.pldm_type = PLDM_OEM;
710 header.command = command;
711 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
712 if (rc != PLDM_SUCCESS) {
713 return rc;
714 }
715
716 struct pldm_read_write_file_by_type_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930717 (struct pldm_read_write_file_by_type_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930718 response->completion_code = completion_code;
719 if (response->completion_code == PLDM_SUCCESS) {
720 response->length = htole32(length);
721 }
722
723 return PLDM_SUCCESS;
724}
725
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930726LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930727int encode_rw_file_by_type_req(uint8_t instance_id, uint8_t command,
728 uint16_t file_type, uint32_t file_handle,
729 uint32_t offset, uint32_t length,
730 struct pldm_msg *msg)
731{
732 if (msg == NULL) {
733 return PLDM_ERROR_INVALID_DATA;
734 }
735 if (command != PLDM_READ_FILE_BY_TYPE &&
736 command != PLDM_WRITE_FILE_BY_TYPE) {
737 return PLDM_ERROR_INVALID_DATA;
738 }
739
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930740 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930741 header.msg_type = PLDM_REQUEST;
742 header.instance = instance_id;
743 header.pldm_type = PLDM_OEM;
744 header.command = command;
745 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
746 if (rc != PLDM_SUCCESS) {
747 return rc;
748 }
749
750 struct pldm_read_write_file_by_type_req *req =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930751 (struct pldm_read_write_file_by_type_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930752 req->file_type = htole16(file_type);
753 req->file_handle = htole32(file_handle);
754 req->offset = htole32(offset);
755 req->length = htole32(length);
756
757 return PLDM_SUCCESS;
758}
759
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930760LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930761int decode_rw_file_by_type_resp(const struct pldm_msg *msg,
762 size_t payload_length, uint8_t *completion_code,
763 uint32_t *length)
764{
765 if (msg == NULL || length == NULL || completion_code == NULL) {
766 return PLDM_ERROR_INVALID_DATA;
767 }
768
769 if (payload_length != PLDM_RW_FILE_BY_TYPE_RESP_BYTES) {
770 return PLDM_ERROR_INVALID_LENGTH;
771 }
772
773 struct pldm_read_write_file_by_type_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930774 (struct pldm_read_write_file_by_type_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930775 *completion_code = response->completion_code;
776 if (*completion_code == PLDM_SUCCESS) {
777 *length = le32toh(response->length);
778 }
779
780 return PLDM_SUCCESS;
781}
782
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930783LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930784int decode_file_ack_req(const struct pldm_msg *msg, size_t payload_length,
785 uint16_t *file_type, uint32_t *file_handle,
786 uint8_t *file_status)
787{
788 if (msg == NULL || file_type == NULL || file_handle == NULL) {
789 return PLDM_ERROR_INVALID_DATA;
790 }
791
792 if (payload_length != PLDM_FILE_ACK_REQ_BYTES) {
793 return PLDM_ERROR_INVALID_LENGTH;
794 }
795
796 struct pldm_file_ack_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930797 (struct pldm_file_ack_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930798 *file_type = le16toh(request->file_type);
799 *file_handle = le32toh(request->file_handle);
800 *file_status = request->file_status;
801
802 return PLDM_SUCCESS;
803}
804
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930805LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930806int encode_file_ack_resp(uint8_t instance_id, uint8_t completion_code,
807 struct pldm_msg *msg)
808{
809 if (msg == NULL) {
810 return PLDM_ERROR_INVALID_DATA;
811 }
812
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930813 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930814 header.msg_type = PLDM_RESPONSE;
815 header.instance = instance_id;
816 header.pldm_type = PLDM_OEM;
817 header.command = PLDM_FILE_ACK;
818 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
819 if (rc != PLDM_SUCCESS) {
820 return rc;
821 }
822
823 struct pldm_file_ack_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930824 (struct pldm_file_ack_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930825 response->completion_code = completion_code;
826
827 return PLDM_SUCCESS;
828}
829
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930830LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930831int encode_file_ack_req(uint8_t instance_id, uint16_t file_type,
832 uint32_t file_handle, uint8_t file_status,
833 struct pldm_msg *msg)
834{
835 if (msg == NULL) {
836 return PLDM_ERROR_INVALID_DATA;
837 }
838
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930839 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930840 header.msg_type = PLDM_REQUEST;
841 header.instance = instance_id;
842 header.pldm_type = PLDM_OEM;
843 header.command = PLDM_FILE_ACK;
844 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
845 if (rc != PLDM_SUCCESS) {
846 return rc;
847 }
848
849 struct pldm_file_ack_req *req =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930850 (struct pldm_file_ack_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930851 req->file_type = htole16(file_type);
852 req->file_handle = htole32(file_handle);
853 req->file_status = file_status;
854
855 return PLDM_SUCCESS;
856}
857
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930858LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930859int decode_file_ack_resp(const struct pldm_msg *msg, size_t payload_length,
860 uint8_t *completion_code)
861{
862 if (msg == NULL || completion_code == NULL) {
863 return PLDM_ERROR_INVALID_DATA;
864 }
865
866 if (payload_length != PLDM_FILE_ACK_RESP_BYTES) {
867 return PLDM_ERROR_INVALID_LENGTH;
868 }
869
870 struct pldm_file_ack_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930871 (struct pldm_file_ack_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930872 *completion_code = response->completion_code;
873
874 return PLDM_SUCCESS;
875}
876
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930877LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930878int encode_file_ack_with_meta_data_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930879 uint8_t instance_id, uint16_t file_type, uint32_t file_handle,
880 uint8_t file_status, uint32_t file_meta_data_1,
881 uint32_t file_meta_data_2, uint32_t file_meta_data_3,
882 uint32_t file_meta_data_4, struct pldm_msg *msg)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930883{
884 if (msg == NULL) {
885 return PLDM_ERROR_INVALID_DATA;
886 }
887
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930888 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930889 header.msg_type = PLDM_REQUEST;
890 header.instance = instance_id;
891 header.pldm_type = PLDM_OEM;
892 header.command = PLDM_FILE_ACK_WITH_META_DATA;
893 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
894 if (rc != PLDM_SUCCESS) {
895 return rc;
896 }
897
898 struct pldm_file_ack_with_meta_data_req *req =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930899 (struct pldm_file_ack_with_meta_data_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930900 req->file_type = htole16(file_type);
901 req->file_handle = htole32(file_handle);
902 req->file_status = file_status;
903 req->file_meta_data_1 = htole32(file_meta_data_1);
904 req->file_meta_data_2 = htole32(file_meta_data_2);
905 req->file_meta_data_3 = htole32(file_meta_data_3);
906 req->file_meta_data_4 = htole32(file_meta_data_4);
907
908 return PLDM_SUCCESS;
909}
910
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930911LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930912int decode_file_ack_with_meta_data_resp(const struct pldm_msg *msg,
913 size_t payload_length,
914 uint8_t *completion_code)
915{
916 if (msg == NULL || completion_code == NULL) {
917 return PLDM_ERROR_INVALID_DATA;
918 }
919
920 if (payload_length != PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES) {
921 return PLDM_ERROR_INVALID_LENGTH;
922 }
923
924 struct pldm_file_ack_with_meta_data_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930925 (struct pldm_file_ack_with_meta_data_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930926 *completion_code = response->completion_code;
927
928 return PLDM_SUCCESS;
929}
930
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930931LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930932int decode_file_ack_with_meta_data_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930933 const struct pldm_msg *msg, size_t payload_length, uint16_t *file_type,
934 uint32_t *file_handle, uint8_t *file_status, uint32_t *file_meta_data_1,
935 uint32_t *file_meta_data_2, uint32_t *file_meta_data_3,
936 uint32_t *file_meta_data_4)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930937{
938 if (msg == NULL || file_type == NULL || file_handle == NULL) {
939 return PLDM_ERROR_INVALID_DATA;
940 }
941
942 if (payload_length != PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES) {
943 return PLDM_ERROR_INVALID_LENGTH;
944 }
945
946 struct pldm_file_ack_with_meta_data_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930947 (struct pldm_file_ack_with_meta_data_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930948 *file_type = le16toh(request->file_type);
949 *file_handle = le32toh(request->file_handle);
950 *file_status = request->file_status;
951 *file_meta_data_1 = le32toh(request->file_meta_data_1);
952 *file_meta_data_2 = le32toh(request->file_meta_data_2);
953 *file_meta_data_3 = le32toh(request->file_meta_data_3);
954 *file_meta_data_4 = le32toh(request->file_meta_data_4);
955
956 return PLDM_SUCCESS;
957}
958
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930959LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930960int encode_file_ack_with_meta_data_resp(uint8_t instance_id,
961 uint8_t completion_code,
962 struct pldm_msg *msg)
963{
964 if (msg == NULL) {
965 return PLDM_ERROR_INVALID_DATA;
966 }
967
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930968 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930969 header.msg_type = PLDM_RESPONSE;
970 header.instance = instance_id;
971 header.pldm_type = PLDM_OEM;
972 header.command = PLDM_FILE_ACK_WITH_META_DATA;
973 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
974 if (rc != PLDM_SUCCESS) {
975 return rc;
976 }
977
978 struct pldm_file_ack_with_meta_data_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930979 (struct pldm_file_ack_with_meta_data_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930980 response->completion_code = completion_code;
981
982 return PLDM_SUCCESS;
983}
984
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930985LIBPLDM_ABI_STABLE
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930986int encode_new_file_with_metadata_req(uint8_t instance_id, uint16_t file_type,
987 uint32_t file_handle, uint64_t length,
988 uint32_t file_meta_data_1,
989 uint32_t file_meta_data_2,
990 uint32_t file_meta_data_3,
991 uint32_t file_meta_data_4,
992 struct pldm_msg *msg)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930993{
994 if (msg == NULL) {
995 return PLDM_ERROR_INVALID_DATA;
996 }
997
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930998 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930999 header.msg_type = PLDM_REQUEST;
1000 header.instance = instance_id;
1001 header.pldm_type = PLDM_OEM;
1002 header.command = PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA;
1003 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
1004 if (rc != PLDM_SUCCESS) {
1005 return rc;
1006 }
1007
1008 struct pldm_new_file_with_metadata_req *req =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +09301009 (struct pldm_new_file_with_metadata_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +09301010 req->file_type = htole16(file_type);
1011 req->file_handle = htole32(file_handle);
1012 req->length = htole64(length);
1013 req->file_meta_data_1 = htole32(file_meta_data_1);
1014 req->file_meta_data_2 = htole32(file_meta_data_2);
1015 req->file_meta_data_3 = htole32(file_meta_data_3);
1016 req->file_meta_data_4 = htole32(file_meta_data_4);
1017
1018 return PLDM_SUCCESS;
1019}
1020
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09301021LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +09301022int decode_new_file_with_metadata_resp(const struct pldm_msg *msg,
1023 size_t payload_length,
1024 uint8_t *completion_code)
1025{
1026 if (msg == NULL || completion_code == NULL) {
1027 return PLDM_ERROR_INVALID_DATA;
1028 }
1029
1030 if (payload_length !=
1031 PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES) {
1032 return PLDM_ERROR_INVALID_LENGTH;
1033 }
1034
1035 struct pldm_new_file_with_metadata_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +09301036 (struct pldm_new_file_with_metadata_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +09301037
1038 *completion_code = msg->payload[0];
1039 if (*completion_code == PLDM_SUCCESS) {
1040 *completion_code = response->completion_code;
1041 }
1042 return PLDM_SUCCESS;
1043}
1044
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09301045LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +09301046int decode_new_file_with_metadata_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +09301047 const struct pldm_msg *msg, size_t payload_length, uint16_t *file_type,
1048 uint32_t *file_handle, uint64_t *length, uint32_t *file_meta_data_1,
1049 uint32_t *file_meta_data_2, uint32_t *file_meta_data_3,
1050 uint32_t *file_meta_data_4)
Andrew Jeffery9c766792022-08-10 23:12:49 +09301051{
1052 if (msg == NULL || file_type == NULL || file_handle == NULL ||
1053 length == NULL) {
1054 return PLDM_ERROR_INVALID_DATA;
1055 }
1056
1057 if (payload_length !=
1058 PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_REQ_BYTES) {
1059 return PLDM_ERROR_INVALID_LENGTH;
1060 }
1061
1062 struct pldm_new_file_with_metadata_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +09301063 (struct pldm_new_file_with_metadata_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +09301064 *file_type = le16toh(request->file_type);
1065 *file_handle = le32toh(request->file_handle);
1066 *length = le64toh(request->length);
1067 *file_meta_data_1 = le32toh(request->file_meta_data_1);
1068 *file_meta_data_2 = le32toh(request->file_meta_data_2);
1069 *file_meta_data_3 = le32toh(request->file_meta_data_3);
1070 *file_meta_data_4 = le32toh(request->file_meta_data_4);
1071
1072 return PLDM_SUCCESS;
1073}
1074
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09301075LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +09301076int encode_new_file_with_metadata_resp(uint8_t instance_id,
1077 uint8_t completion_code,
1078 struct pldm_msg *msg)
1079{
1080 if (msg == NULL) {
1081 return PLDM_ERROR_INVALID_DATA;
1082 }
1083
Andrew Jeffery37dd6a32023-05-12 16:04:06 +09301084 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +09301085 header.msg_type = PLDM_RESPONSE;
1086 header.instance = instance_id;
1087 header.pldm_type = PLDM_OEM;
1088 header.command = PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA;
1089 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
1090 if (rc != PLDM_SUCCESS) {
1091 return rc;
1092 }
1093
1094 struct pldm_new_file_with_metadata_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +09301095 (struct pldm_new_file_with_metadata_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +09301096
1097 if (response->completion_code == PLDM_SUCCESS) {
1098 response->completion_code = completion_code;
1099 }
1100
1101 return PLDM_SUCCESS;
1102}