blob: 71acf721f19f8fedb801fea3baac1c98f13be955 [file] [log] [blame]
Patrick Williams691668f2023-11-01 08:19:10 -05001/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
Andrew Jefferyb0c1d202023-11-07 22:08:44 +10302#include <libpldm/base.h>
Pavithra Barithayaa7989cd2023-10-30 08:52:28 -05003#include <libpldm/oem/ibm/file_io.h>
Andrew Jefferyb0c1d202023-11-07 22:08:44 +10304
Andrew Jeffery9c766792022-08-10 23:12:49 +09305#include <endian.h>
6#include <string.h>
7
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09308LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +09309int decode_rw_file_memory_req(const struct pldm_msg *msg, size_t payload_length,
10 uint32_t *file_handle, uint32_t *offset,
11 uint32_t *length, uint64_t *address)
12{
13 if (msg == NULL || file_handle == NULL || offset == NULL ||
14 length == NULL || address == NULL) {
15 return PLDM_ERROR_INVALID_DATA;
16 }
17
18 if (payload_length != PLDM_RW_FILE_MEM_REQ_BYTES) {
19 return PLDM_ERROR_INVALID_LENGTH;
20 }
21
22 struct pldm_read_write_file_memory_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093023 (struct pldm_read_write_file_memory_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093024
25 *file_handle = le32toh(request->file_handle);
26 *offset = le32toh(request->offset);
27 *length = le32toh(request->length);
28 *address = le64toh(request->address);
29
30 return PLDM_SUCCESS;
31}
32
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093033LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093034int encode_rw_file_memory_resp(uint8_t instance_id, uint8_t command,
35 uint8_t completion_code, uint32_t length,
36 struct pldm_msg *msg)
37{
38 if (msg == NULL) {
39 return PLDM_ERROR_INVALID_LENGTH;
40 }
41
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093042 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093043 header.msg_type = PLDM_RESPONSE;
44 header.instance = instance_id;
45 header.pldm_type = PLDM_OEM;
46 header.command = command;
47 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
48 if (rc != PLDM_SUCCESS) {
49 return rc;
50 }
51
52 struct pldm_read_write_file_memory_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093053 (struct pldm_read_write_file_memory_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093054 response->completion_code = completion_code;
55 if (response->completion_code == PLDM_SUCCESS) {
56 response->length = htole32(length);
57 }
58
59 return PLDM_SUCCESS;
60}
61
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093062LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093063int encode_rw_file_memory_req(uint8_t instance_id, uint8_t command,
64 uint32_t file_handle, uint32_t offset,
65 uint32_t length, uint64_t address,
66 struct pldm_msg *msg)
67{
68 if (msg == NULL) {
69 return PLDM_ERROR_INVALID_DATA;
70 }
71
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093072 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093073 header.msg_type = PLDM_REQUEST;
74 header.instance = instance_id;
75 header.pldm_type = PLDM_OEM;
76 header.command = command;
77 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
78 if (rc != PLDM_SUCCESS) {
79 return rc;
80 }
81
82 struct pldm_read_write_file_memory_req *req =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093083 (struct pldm_read_write_file_memory_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +093084 req->file_handle = htole32(file_handle);
85 req->offset = htole32(offset);
86 req->length = htole32(length);
87 req->address = htole64(address);
88 return PLDM_SUCCESS;
89}
90
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093091LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093092int decode_rw_file_memory_resp(const struct pldm_msg *msg,
93 size_t payload_length, uint8_t *completion_code,
94 uint32_t *length)
95{
96 if (msg == NULL || length == NULL || completion_code == NULL) {
97 return PLDM_ERROR_INVALID_DATA;
98 }
99
100 if (payload_length != PLDM_RW_FILE_MEM_RESP_BYTES) {
101 return PLDM_ERROR_INVALID_LENGTH;
102 }
103
104 struct pldm_read_write_file_memory_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930105 (struct pldm_read_write_file_memory_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930106 *completion_code = response->completion_code;
107 if (*completion_code == PLDM_SUCCESS) {
108 *length = le32toh(response->length);
109 }
110
111 return PLDM_SUCCESS;
112}
113
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930114LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930115int decode_get_file_table_req(const struct pldm_msg *msg, size_t payload_length,
116 uint32_t *transfer_handle,
117 uint8_t *transfer_opflag, uint8_t *table_type)
118{
119 if (msg == NULL || transfer_handle == NULL || transfer_opflag == NULL ||
120 table_type == NULL) {
121 return PLDM_ERROR_INVALID_DATA;
122 }
123
124 if (payload_length != PLDM_GET_FILE_TABLE_REQ_BYTES) {
125 return PLDM_ERROR_INVALID_LENGTH;
126 }
127
128 struct pldm_get_file_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930129 (struct pldm_get_file_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930130
131 *transfer_handle = le32toh(request->transfer_handle);
132 *transfer_opflag = request->operation_flag;
133 *table_type = request->table_type;
134
135 return PLDM_SUCCESS;
136}
137
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930138LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930139int encode_get_file_table_resp(uint8_t instance_id, uint8_t completion_code,
140 uint32_t next_transfer_handle,
141 uint8_t transfer_flag, const uint8_t *table_data,
142 size_t table_size, struct pldm_msg *msg)
143{
144 if (msg == NULL) {
145 return PLDM_ERROR_INVALID_LENGTH;
146 }
147
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930148 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930149 header.msg_type = PLDM_RESPONSE;
150 header.instance = instance_id;
151 header.pldm_type = PLDM_OEM;
152 header.command = PLDM_GET_FILE_TABLE;
153 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
154 if (rc != PLDM_SUCCESS) {
155 return rc;
156 }
157
158 struct pldm_get_file_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930159 (struct pldm_get_file_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930160 response->completion_code = completion_code;
161
162 if (completion_code == PLDM_SUCCESS) {
163 response->next_transfer_handle = htole32(next_transfer_handle);
164 response->transfer_flag = transfer_flag;
165 memcpy(response->table_data, table_data, table_size);
166 }
167
168 return PLDM_SUCCESS;
169}
170
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930171LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930172int encode_get_file_table_req(uint8_t instance_id, uint32_t transfer_handle,
173 uint8_t transfer_opflag, uint8_t table_type,
174 struct pldm_msg *msg)
175{
176 if (msg == NULL) {
177 return PLDM_ERROR_INVALID_DATA;
178 }
179
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930180 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930181 header.msg_type = PLDM_REQUEST;
182 header.instance = instance_id;
183 header.pldm_type = PLDM_OEM;
184 header.command = PLDM_GET_FILE_TABLE;
185 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
186 if (rc != PLDM_SUCCESS) {
187 return rc;
188 }
189
190 struct pldm_get_file_table_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930191 (struct pldm_get_file_table_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930192
193 request->transfer_handle = htole32(transfer_handle);
194 request->operation_flag = transfer_opflag;
195 request->table_type = table_type;
196 return PLDM_SUCCESS;
197}
198
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930199LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930200int decode_get_file_table_resp(const struct pldm_msg *msg,
201 size_t payload_length, uint8_t *completion_code,
202 uint32_t *next_transfer_handle,
203 uint8_t *transfer_flag,
204 uint8_t *file_table_data_start_offset,
205 size_t *file_table_length)
206{
207 if (msg == NULL || transfer_flag == NULL ||
208 next_transfer_handle == NULL || completion_code == NULL ||
209 file_table_data_start_offset == NULL || file_table_length == NULL) {
210 return PLDM_ERROR_INVALID_DATA;
211 }
212
213 if (payload_length <= PLDM_GET_FILE_TABLE_MIN_RESP_BYTES) {
214 return PLDM_ERROR_INVALID_LENGTH;
215 }
216
217 *completion_code = msg->payload[0];
218
219 if (PLDM_SUCCESS != *completion_code) {
220 return PLDM_SUCCESS;
221 }
222
223 struct pldm_get_file_table_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930224 (struct pldm_get_file_table_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930225
226 *next_transfer_handle = le32toh(response->next_transfer_handle);
227 *transfer_flag = response->transfer_flag;
228 *file_table_data_start_offset = sizeof(*completion_code) +
229 sizeof(*next_transfer_handle) +
230 sizeof(*transfer_flag);
231 *file_table_length =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930232 payload_length - PLDM_GET_FILE_TABLE_MIN_RESP_BYTES;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930233
234 return PLDM_SUCCESS;
235}
236
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930237LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930238int decode_read_file_req(const struct pldm_msg *msg, size_t payload_length,
239 uint32_t *file_handle, uint32_t *offset,
240 uint32_t *length)
241{
242 if (msg == NULL || file_handle == NULL || offset == NULL ||
243 length == NULL) {
244 return PLDM_ERROR_INVALID_DATA;
245 }
246
247 if (payload_length != PLDM_READ_FILE_REQ_BYTES) {
248 return PLDM_ERROR_INVALID_LENGTH;
249 }
250
251 struct pldm_read_file_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930252 (struct pldm_read_file_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930253
254 *file_handle = le32toh(request->file_handle);
255 *offset = le32toh(request->offset);
256 *length = le32toh(request->length);
257
258 return PLDM_SUCCESS;
259}
260
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930261LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930262int encode_read_file_req(uint8_t instance_id, uint32_t file_handle,
263 uint32_t offset, uint32_t length, struct pldm_msg *msg)
264{
265 if (msg == NULL) {
266 return PLDM_ERROR_INVALID_DATA;
267 }
268
269 if (length == 0) {
270 return PLDM_ERROR_INVALID_LENGTH;
271 }
272
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930273 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930274 header.msg_type = PLDM_REQUEST;
275 header.instance = instance_id;
276 header.pldm_type = PLDM_OEM;
277 header.command = PLDM_READ_FILE;
278 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
279 if (rc != PLDM_SUCCESS) {
280 return rc;
281 }
282
283 struct pldm_read_file_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930284 (struct pldm_read_file_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930285
286 request->file_handle = htole32(file_handle);
287 request->offset = htole32(offset);
288 request->length = htole32(length);
289
290 return PLDM_SUCCESS;
291}
292
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930293LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930294int decode_read_file_resp(const struct pldm_msg *msg, size_t payload_length,
295 uint8_t *completion_code, uint32_t *length,
296 size_t *file_data_offset)
297{
298 if (msg == NULL || completion_code == NULL || length == NULL) {
299 return PLDM_ERROR_INVALID_DATA;
300 }
301
302 if (payload_length < PLDM_READ_FILE_RESP_BYTES) {
303 return PLDM_ERROR_INVALID_LENGTH;
304 }
305
306 struct pldm_read_file_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930307 (struct pldm_read_file_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930308
309 *completion_code = response->completion_code;
310 if (*completion_code == PLDM_SUCCESS) {
311 *length = le32toh(response->length);
312 if (payload_length != PLDM_READ_FILE_RESP_BYTES + *length) {
313 return PLDM_ERROR_INVALID_LENGTH;
314 }
315 *file_data_offset = sizeof(*completion_code) + sizeof(*length);
316 }
317
318 return PLDM_SUCCESS;
319}
320
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930321LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930322int encode_read_file_resp(uint8_t instance_id, uint8_t completion_code,
323 uint32_t length, struct pldm_msg *msg)
324{
325 if (msg == NULL) {
326 return PLDM_ERROR_INVALID_DATA;
327 }
328
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930329 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930330 header.msg_type = PLDM_RESPONSE;
331 header.instance = instance_id;
332 header.pldm_type = PLDM_OEM;
333 header.command = PLDM_READ_FILE;
334 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
335 if (rc != PLDM_SUCCESS) {
336 return rc;
337 }
338
339 struct pldm_read_file_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930340 (struct pldm_read_file_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930341 response->completion_code = completion_code;
342
343 if (response->completion_code == PLDM_SUCCESS) {
344 response->length = htole32(length);
345 }
346
347 return PLDM_SUCCESS;
348}
349
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930350LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930351int decode_write_file_req(const struct pldm_msg *msg, size_t payload_length,
352 uint32_t *file_handle, uint32_t *offset,
353 uint32_t *length, size_t *file_data_offset)
354{
355 if (msg == NULL || file_handle == NULL || length == NULL) {
356 return PLDM_ERROR_INVALID_DATA;
357 }
358
359 if (payload_length < PLDM_WRITE_FILE_REQ_BYTES) {
360 return PLDM_ERROR_INVALID_LENGTH;
361 }
362
363 struct pldm_write_file_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930364 (struct pldm_write_file_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930365
366 *file_handle = le32toh(request->file_handle);
367 *offset = le32toh(request->offset);
368 *length = le32toh(request->length);
369 if (payload_length != PLDM_WRITE_FILE_REQ_BYTES + *length) {
370 return PLDM_ERROR_INVALID_LENGTH;
371 }
372 *file_data_offset =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930373 sizeof(*file_handle) + sizeof(*offset) + sizeof(*length);
Andrew Jeffery9c766792022-08-10 23:12:49 +0930374
375 return PLDM_SUCCESS;
376}
377
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930378LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930379int encode_write_file_req(uint8_t instance_id, uint32_t file_handle,
380 uint32_t offset, uint32_t length,
381 struct pldm_msg *msg)
382{
383 if (msg == NULL) {
384 return PLDM_ERROR_INVALID_DATA;
385 }
386
387 if (length == 0) {
388 return PLDM_ERROR_INVALID_LENGTH;
389 }
390
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930391 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930392 header.msg_type = PLDM_REQUEST;
393 header.instance = instance_id;
394 header.pldm_type = PLDM_OEM;
395 header.command = PLDM_WRITE_FILE;
396 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
397 if (rc != PLDM_SUCCESS) {
398 return rc;
399 }
400
401 struct pldm_write_file_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930402 (struct pldm_write_file_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930403
404 request->file_handle = htole32(file_handle);
405 request->offset = htole32(offset);
406 request->length = htole32(length);
407
408 return PLDM_SUCCESS;
409}
410
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930411LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930412int decode_write_file_resp(const struct pldm_msg *msg, size_t payload_length,
413 uint8_t *completion_code, uint32_t *length)
414{
415 if (msg == NULL || completion_code == NULL || length == NULL) {
416 return PLDM_ERROR_INVALID_DATA;
417 }
418
419 if (payload_length != PLDM_WRITE_FILE_RESP_BYTES) {
420 return PLDM_ERROR_INVALID_LENGTH;
421 }
422
423 struct pldm_write_file_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930424 (struct pldm_write_file_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930425
426 *completion_code = le32toh(response->completion_code);
427 if (response->completion_code == PLDM_SUCCESS) {
428 *length = le32toh(response->length);
429 }
430
431 return PLDM_SUCCESS;
432}
433
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930434LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930435int encode_write_file_resp(uint8_t instance_id, uint8_t completion_code,
436 uint32_t length, struct pldm_msg *msg)
437{
438 if (msg == NULL) {
439 return PLDM_ERROR_INVALID_DATA;
440 }
441
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930442 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930443 header.msg_type = PLDM_RESPONSE;
444 header.instance = instance_id;
445 header.pldm_type = PLDM_OEM;
446 header.command = PLDM_WRITE_FILE;
447 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
448 if (rc != PLDM_SUCCESS) {
449 return rc;
450 }
451
452 struct pldm_write_file_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930453 (struct pldm_write_file_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930454 response->completion_code = completion_code;
455
456 if (response->completion_code == PLDM_SUCCESS) {
457 response->length = htole32(length);
458 }
459
460 return PLDM_SUCCESS;
461}
462
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930463LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930464int decode_rw_file_by_type_memory_req(const struct pldm_msg *msg,
465 size_t payload_length,
466 uint16_t *file_type,
467 uint32_t *file_handle, uint32_t *offset,
468 uint32_t *length, uint64_t *address)
469{
470 if (msg == NULL || file_type == NULL || file_handle == NULL ||
471 offset == NULL || length == NULL || address == NULL) {
472 return PLDM_ERROR_INVALID_DATA;
473 }
474
475 if (payload_length != PLDM_RW_FILE_BY_TYPE_MEM_REQ_BYTES) {
476 return PLDM_ERROR_INVALID_LENGTH;
477 }
478
479 struct pldm_read_write_file_by_type_memory_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930480 (struct pldm_read_write_file_by_type_memory_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930481 *file_type = le16toh(request->file_type);
482 *file_handle = le32toh(request->file_handle);
483 *offset = le32toh(request->offset);
484 *length = le32toh(request->length);
485 *address = le64toh(request->address);
486
487 return PLDM_SUCCESS;
488}
489
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930490LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930491int encode_rw_file_by_type_memory_resp(uint8_t instance_id, uint8_t command,
492 uint8_t completion_code, uint32_t length,
493 struct pldm_msg *msg)
494{
495 if (msg == NULL) {
496 return PLDM_ERROR_INVALID_DATA;
497 }
498
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930499 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930500 header.msg_type = PLDM_RESPONSE;
501 header.instance = instance_id;
502 header.pldm_type = PLDM_OEM;
503 header.command = command;
504 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
505 if (rc != PLDM_SUCCESS) {
506 return rc;
507 }
508
509 struct pldm_read_write_file_by_type_memory_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930510 (struct pldm_read_write_file_by_type_memory_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930511 response->completion_code = completion_code;
512 if (response->completion_code == PLDM_SUCCESS) {
513 response->length = htole32(length);
514 }
515
516 return PLDM_SUCCESS;
517}
518
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930519LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930520int encode_rw_file_by_type_memory_req(uint8_t instance_id, uint8_t command,
521 uint16_t file_type, uint32_t file_handle,
522 uint32_t offset, uint32_t length,
523 uint64_t address, struct pldm_msg *msg)
524{
525 if (msg == NULL) {
526 return PLDM_ERROR_INVALID_DATA;
527 }
528
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930529 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930530 header.msg_type = PLDM_REQUEST;
531 header.instance = instance_id;
532 header.pldm_type = PLDM_OEM;
533 header.command = command;
534 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
535 if (rc != PLDM_SUCCESS) {
536 return rc;
537 }
538
539 struct pldm_read_write_file_by_type_memory_req *req =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930540 (struct pldm_read_write_file_by_type_memory_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930541 req->file_type = htole16(file_type);
542 req->file_handle = htole32(file_handle);
543 req->offset = htole32(offset);
544 req->length = htole32(length);
545 req->address = htole64(address);
546
547 return PLDM_SUCCESS;
548}
549
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930550LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930551int decode_rw_file_by_type_memory_resp(const struct pldm_msg *msg,
552 size_t payload_length,
553 uint8_t *completion_code,
554 uint32_t *length)
555{
556 if (msg == NULL || length == NULL || completion_code == NULL) {
557 return PLDM_ERROR_INVALID_DATA;
558 }
559
560 if (payload_length != PLDM_RW_FILE_BY_TYPE_MEM_RESP_BYTES) {
561 return PLDM_ERROR_INVALID_LENGTH;
562 }
563
564 struct pldm_read_write_file_by_type_memory_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930565 (struct pldm_read_write_file_by_type_memory_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930566 *completion_code = response->completion_code;
567 if (*completion_code == PLDM_SUCCESS) {
568 *length = le32toh(response->length);
569 }
570
571 return PLDM_SUCCESS;
572}
573
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930574LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930575int decode_new_file_req(const struct pldm_msg *msg, size_t payload_length,
576 uint16_t *file_type, uint32_t *file_handle,
577 uint64_t *length)
578{
579 if (msg == NULL || file_type == NULL || file_handle == NULL ||
580 length == NULL) {
581 return PLDM_ERROR_INVALID_DATA;
582 }
583
584 if (payload_length != PLDM_NEW_FILE_REQ_BYTES) {
585 return PLDM_ERROR_INVALID_LENGTH;
586 }
587
588 struct pldm_new_file_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930589 (struct pldm_new_file_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930590 *file_type = le16toh(request->file_type);
591 *file_handle = le32toh(request->file_handle);
592 *length = le64toh(request->length);
593
594 return PLDM_SUCCESS;
595}
596
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930597LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930598int encode_new_file_resp(uint8_t instance_id, uint8_t completion_code,
599 struct pldm_msg *msg)
600{
601 if (msg == NULL) {
602 return PLDM_ERROR_INVALID_DATA;
603 }
604
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930605 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930606 header.msg_type = PLDM_RESPONSE;
607 header.instance = instance_id;
608 header.pldm_type = PLDM_OEM;
609 header.command = PLDM_NEW_FILE_AVAILABLE;
610 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
611 if (rc != PLDM_SUCCESS) {
612 return rc;
613 }
614
615 struct pldm_new_file_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930616 (struct pldm_new_file_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930617 response->completion_code = completion_code;
618
619 return PLDM_SUCCESS;
620}
621
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930622LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930623int encode_new_file_req(uint8_t instance_id, uint16_t file_type,
624 uint32_t file_handle, uint64_t length,
625 struct pldm_msg *msg)
626{
627 if (msg == NULL) {
628 return PLDM_ERROR_INVALID_DATA;
629 }
630
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930631 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930632 header.msg_type = PLDM_REQUEST;
633 header.instance = instance_id;
634 header.pldm_type = PLDM_OEM;
635 header.command = PLDM_NEW_FILE_AVAILABLE;
636 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
637 if (rc != PLDM_SUCCESS) {
638 return rc;
639 }
640
641 struct pldm_new_file_req *req =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930642 (struct pldm_new_file_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930643 req->file_type = htole16(file_type);
644 req->file_handle = htole32(file_handle);
645 req->length = htole64(length);
646
647 return PLDM_SUCCESS;
648}
649
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930650LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930651int decode_new_file_resp(const struct pldm_msg *msg, size_t payload_length,
652 uint8_t *completion_code)
653{
654 if (msg == NULL || completion_code == NULL) {
655 return PLDM_ERROR_INVALID_DATA;
656 }
657
658 if (payload_length != PLDM_NEW_FILE_RESP_BYTES) {
659 return PLDM_ERROR_INVALID_LENGTH;
660 }
661
662 struct pldm_new_file_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930663 (struct pldm_new_file_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930664 *completion_code = response->completion_code;
665
666 return PLDM_SUCCESS;
667}
668
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930669LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930670int decode_rw_file_by_type_req(const struct pldm_msg *msg,
671 size_t payload_length, uint16_t *file_type,
672 uint32_t *file_handle, uint32_t *offset,
673 uint32_t *length)
674{
675 if (msg == NULL || file_type == NULL || file_handle == NULL ||
676 offset == NULL || length == NULL) {
677 return PLDM_ERROR_INVALID_DATA;
678 }
679
680 if (payload_length < PLDM_RW_FILE_BY_TYPE_REQ_BYTES) {
681 return PLDM_ERROR_INVALID_LENGTH;
682 }
683
684 struct pldm_read_write_file_by_type_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930685 (struct pldm_read_write_file_by_type_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930686 *file_type = le16toh(request->file_type);
687 *file_handle = le32toh(request->file_handle);
688 *offset = le32toh(request->offset);
689 *length = le32toh(request->length);
690
691 return PLDM_SUCCESS;
692}
693
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930694LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930695int encode_rw_file_by_type_resp(uint8_t instance_id, uint8_t command,
696 uint8_t completion_code, uint32_t length,
697 struct pldm_msg *msg)
698{
699 if (msg == NULL) {
700 return PLDM_ERROR_INVALID_DATA;
701 }
702 if (command != PLDM_READ_FILE_BY_TYPE &&
703 command != PLDM_WRITE_FILE_BY_TYPE) {
704 return PLDM_ERROR_INVALID_DATA;
705 }
706
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930707 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930708 header.msg_type = PLDM_RESPONSE;
709 header.instance = instance_id;
710 header.pldm_type = PLDM_OEM;
711 header.command = command;
712 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
713 if (rc != PLDM_SUCCESS) {
714 return rc;
715 }
716
717 struct pldm_read_write_file_by_type_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930718 (struct pldm_read_write_file_by_type_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930719 response->completion_code = completion_code;
720 if (response->completion_code == PLDM_SUCCESS) {
721 response->length = htole32(length);
722 }
723
724 return PLDM_SUCCESS;
725}
726
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930727LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930728int encode_rw_file_by_type_req(uint8_t instance_id, uint8_t command,
729 uint16_t file_type, uint32_t file_handle,
730 uint32_t offset, uint32_t length,
731 struct pldm_msg *msg)
732{
733 if (msg == NULL) {
734 return PLDM_ERROR_INVALID_DATA;
735 }
736 if (command != PLDM_READ_FILE_BY_TYPE &&
737 command != PLDM_WRITE_FILE_BY_TYPE) {
738 return PLDM_ERROR_INVALID_DATA;
739 }
740
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930741 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930742 header.msg_type = PLDM_REQUEST;
743 header.instance = instance_id;
744 header.pldm_type = PLDM_OEM;
745 header.command = command;
746 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
747 if (rc != PLDM_SUCCESS) {
748 return rc;
749 }
750
751 struct pldm_read_write_file_by_type_req *req =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930752 (struct pldm_read_write_file_by_type_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930753 req->file_type = htole16(file_type);
754 req->file_handle = htole32(file_handle);
755 req->offset = htole32(offset);
756 req->length = htole32(length);
757
758 return PLDM_SUCCESS;
759}
760
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930761LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930762int decode_rw_file_by_type_resp(const struct pldm_msg *msg,
763 size_t payload_length, uint8_t *completion_code,
764 uint32_t *length)
765{
766 if (msg == NULL || length == NULL || completion_code == NULL) {
767 return PLDM_ERROR_INVALID_DATA;
768 }
769
770 if (payload_length != PLDM_RW_FILE_BY_TYPE_RESP_BYTES) {
771 return PLDM_ERROR_INVALID_LENGTH;
772 }
773
774 struct pldm_read_write_file_by_type_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930775 (struct pldm_read_write_file_by_type_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930776 *completion_code = response->completion_code;
777 if (*completion_code == PLDM_SUCCESS) {
778 *length = le32toh(response->length);
779 }
780
781 return PLDM_SUCCESS;
782}
783
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930784LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930785int decode_file_ack_req(const struct pldm_msg *msg, size_t payload_length,
786 uint16_t *file_type, uint32_t *file_handle,
787 uint8_t *file_status)
788{
789 if (msg == NULL || file_type == NULL || file_handle == NULL) {
790 return PLDM_ERROR_INVALID_DATA;
791 }
792
793 if (payload_length != PLDM_FILE_ACK_REQ_BYTES) {
794 return PLDM_ERROR_INVALID_LENGTH;
795 }
796
797 struct pldm_file_ack_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930798 (struct pldm_file_ack_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930799 *file_type = le16toh(request->file_type);
800 *file_handle = le32toh(request->file_handle);
801 *file_status = request->file_status;
802
803 return PLDM_SUCCESS;
804}
805
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930806LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930807int encode_file_ack_resp(uint8_t instance_id, uint8_t completion_code,
808 struct pldm_msg *msg)
809{
810 if (msg == NULL) {
811 return PLDM_ERROR_INVALID_DATA;
812 }
813
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930814 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930815 header.msg_type = PLDM_RESPONSE;
816 header.instance = instance_id;
817 header.pldm_type = PLDM_OEM;
818 header.command = PLDM_FILE_ACK;
819 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
820 if (rc != PLDM_SUCCESS) {
821 return rc;
822 }
823
824 struct pldm_file_ack_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930825 (struct pldm_file_ack_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930826 response->completion_code = completion_code;
827
828 return PLDM_SUCCESS;
829}
830
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930831LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930832int encode_file_ack_req(uint8_t instance_id, uint16_t file_type,
833 uint32_t file_handle, uint8_t file_status,
834 struct pldm_msg *msg)
835{
836 if (msg == NULL) {
837 return PLDM_ERROR_INVALID_DATA;
838 }
839
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930840 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930841 header.msg_type = PLDM_REQUEST;
842 header.instance = instance_id;
843 header.pldm_type = PLDM_OEM;
844 header.command = PLDM_FILE_ACK;
845 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
846 if (rc != PLDM_SUCCESS) {
847 return rc;
848 }
849
850 struct pldm_file_ack_req *req =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930851 (struct pldm_file_ack_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930852 req->file_type = htole16(file_type);
853 req->file_handle = htole32(file_handle);
854 req->file_status = file_status;
855
856 return PLDM_SUCCESS;
857}
858
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930859LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930860int decode_file_ack_resp(const struct pldm_msg *msg, size_t payload_length,
861 uint8_t *completion_code)
862{
863 if (msg == NULL || completion_code == NULL) {
864 return PLDM_ERROR_INVALID_DATA;
865 }
866
867 if (payload_length != PLDM_FILE_ACK_RESP_BYTES) {
868 return PLDM_ERROR_INVALID_LENGTH;
869 }
870
871 struct pldm_file_ack_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930872 (struct pldm_file_ack_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930873 *completion_code = response->completion_code;
874
875 return PLDM_SUCCESS;
876}
877
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930878LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930879int encode_file_ack_with_meta_data_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930880 uint8_t instance_id, uint16_t file_type, uint32_t file_handle,
881 uint8_t file_status, uint32_t file_meta_data_1,
882 uint32_t file_meta_data_2, uint32_t file_meta_data_3,
883 uint32_t file_meta_data_4, struct pldm_msg *msg)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930884{
885 if (msg == NULL) {
886 return PLDM_ERROR_INVALID_DATA;
887 }
888
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930889 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930890 header.msg_type = PLDM_REQUEST;
891 header.instance = instance_id;
892 header.pldm_type = PLDM_OEM;
893 header.command = PLDM_FILE_ACK_WITH_META_DATA;
894 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
895 if (rc != PLDM_SUCCESS) {
896 return rc;
897 }
898
899 struct pldm_file_ack_with_meta_data_req *req =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930900 (struct pldm_file_ack_with_meta_data_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930901 req->file_type = htole16(file_type);
902 req->file_handle = htole32(file_handle);
903 req->file_status = file_status;
904 req->file_meta_data_1 = htole32(file_meta_data_1);
905 req->file_meta_data_2 = htole32(file_meta_data_2);
906 req->file_meta_data_3 = htole32(file_meta_data_3);
907 req->file_meta_data_4 = htole32(file_meta_data_4);
908
909 return PLDM_SUCCESS;
910}
911
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930912LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930913int decode_file_ack_with_meta_data_resp(const struct pldm_msg *msg,
914 size_t payload_length,
915 uint8_t *completion_code)
916{
917 if (msg == NULL || completion_code == NULL) {
918 return PLDM_ERROR_INVALID_DATA;
919 }
920
921 if (payload_length != PLDM_FILE_ACK_WITH_META_DATA_RESP_BYTES) {
922 return PLDM_ERROR_INVALID_LENGTH;
923 }
924
925 struct pldm_file_ack_with_meta_data_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930926 (struct pldm_file_ack_with_meta_data_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930927 *completion_code = response->completion_code;
928
929 return PLDM_SUCCESS;
930}
931
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930932LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930933int decode_file_ack_with_meta_data_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930934 const struct pldm_msg *msg, size_t payload_length, uint16_t *file_type,
935 uint32_t *file_handle, uint8_t *file_status, uint32_t *file_meta_data_1,
936 uint32_t *file_meta_data_2, uint32_t *file_meta_data_3,
937 uint32_t *file_meta_data_4)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930938{
939 if (msg == NULL || file_type == NULL || file_handle == NULL) {
940 return PLDM_ERROR_INVALID_DATA;
941 }
942
943 if (payload_length != PLDM_FILE_ACK_WITH_META_DATA_REQ_BYTES) {
944 return PLDM_ERROR_INVALID_LENGTH;
945 }
946
947 struct pldm_file_ack_with_meta_data_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930948 (struct pldm_file_ack_with_meta_data_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930949 *file_type = le16toh(request->file_type);
950 *file_handle = le32toh(request->file_handle);
951 *file_status = request->file_status;
952 *file_meta_data_1 = le32toh(request->file_meta_data_1);
953 *file_meta_data_2 = le32toh(request->file_meta_data_2);
954 *file_meta_data_3 = le32toh(request->file_meta_data_3);
955 *file_meta_data_4 = le32toh(request->file_meta_data_4);
956
957 return PLDM_SUCCESS;
958}
959
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930960LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930961int encode_file_ack_with_meta_data_resp(uint8_t instance_id,
962 uint8_t completion_code,
963 struct pldm_msg *msg)
964{
965 if (msg == NULL) {
966 return PLDM_ERROR_INVALID_DATA;
967 }
968
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930969 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930970 header.msg_type = PLDM_RESPONSE;
971 header.instance = instance_id;
972 header.pldm_type = PLDM_OEM;
973 header.command = PLDM_FILE_ACK_WITH_META_DATA;
974 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
975 if (rc != PLDM_SUCCESS) {
976 return rc;
977 }
978
979 struct pldm_file_ack_with_meta_data_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930980 (struct pldm_file_ack_with_meta_data_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930981 response->completion_code = completion_code;
982
983 return PLDM_SUCCESS;
984}
985
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930986LIBPLDM_ABI_STABLE
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930987int encode_new_file_with_metadata_req(uint8_t instance_id, uint16_t file_type,
988 uint32_t file_handle, uint64_t length,
989 uint32_t file_meta_data_1,
990 uint32_t file_meta_data_2,
991 uint32_t file_meta_data_3,
992 uint32_t file_meta_data_4,
993 struct pldm_msg *msg)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930994{
995 if (msg == NULL) {
996 return PLDM_ERROR_INVALID_DATA;
997 }
998
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930999 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +09301000 header.msg_type = PLDM_REQUEST;
1001 header.instance = instance_id;
1002 header.pldm_type = PLDM_OEM;
1003 header.command = PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA;
1004 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
1005 if (rc != PLDM_SUCCESS) {
1006 return rc;
1007 }
1008
1009 struct pldm_new_file_with_metadata_req *req =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +09301010 (struct pldm_new_file_with_metadata_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +09301011 req->file_type = htole16(file_type);
1012 req->file_handle = htole32(file_handle);
1013 req->length = htole64(length);
1014 req->file_meta_data_1 = htole32(file_meta_data_1);
1015 req->file_meta_data_2 = htole32(file_meta_data_2);
1016 req->file_meta_data_3 = htole32(file_meta_data_3);
1017 req->file_meta_data_4 = htole32(file_meta_data_4);
1018
1019 return PLDM_SUCCESS;
1020}
1021
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09301022LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +09301023int decode_new_file_with_metadata_resp(const struct pldm_msg *msg,
1024 size_t payload_length,
1025 uint8_t *completion_code)
1026{
1027 if (msg == NULL || completion_code == NULL) {
1028 return PLDM_ERROR_INVALID_DATA;
1029 }
1030
1031 if (payload_length !=
1032 PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_RESP_BYTES) {
1033 return PLDM_ERROR_INVALID_LENGTH;
1034 }
1035
1036 struct pldm_new_file_with_metadata_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +09301037 (struct pldm_new_file_with_metadata_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +09301038
1039 *completion_code = msg->payload[0];
1040 if (*completion_code == PLDM_SUCCESS) {
1041 *completion_code = response->completion_code;
1042 }
1043 return PLDM_SUCCESS;
1044}
1045
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09301046LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +09301047int decode_new_file_with_metadata_req(
Andrew Jeffery37dd6a32023-05-12 16:04:06 +09301048 const struct pldm_msg *msg, size_t payload_length, uint16_t *file_type,
1049 uint32_t *file_handle, uint64_t *length, uint32_t *file_meta_data_1,
1050 uint32_t *file_meta_data_2, uint32_t *file_meta_data_3,
1051 uint32_t *file_meta_data_4)
Andrew Jeffery9c766792022-08-10 23:12:49 +09301052{
1053 if (msg == NULL || file_type == NULL || file_handle == NULL ||
1054 length == NULL) {
1055 return PLDM_ERROR_INVALID_DATA;
1056 }
1057
1058 if (payload_length !=
1059 PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA_REQ_BYTES) {
1060 return PLDM_ERROR_INVALID_LENGTH;
1061 }
1062
1063 struct pldm_new_file_with_metadata_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +09301064 (struct pldm_new_file_with_metadata_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +09301065 *file_type = le16toh(request->file_type);
1066 *file_handle = le32toh(request->file_handle);
1067 *length = le64toh(request->length);
1068 *file_meta_data_1 = le32toh(request->file_meta_data_1);
1069 *file_meta_data_2 = le32toh(request->file_meta_data_2);
1070 *file_meta_data_3 = le32toh(request->file_meta_data_3);
1071 *file_meta_data_4 = le32toh(request->file_meta_data_4);
1072
1073 return PLDM_SUCCESS;
1074}
1075
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09301076LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +09301077int encode_new_file_with_metadata_resp(uint8_t instance_id,
1078 uint8_t completion_code,
1079 struct pldm_msg *msg)
1080{
1081 if (msg == NULL) {
1082 return PLDM_ERROR_INVALID_DATA;
1083 }
1084
Andrew Jeffery37dd6a32023-05-12 16:04:06 +09301085 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +09301086 header.msg_type = PLDM_RESPONSE;
1087 header.instance = instance_id;
1088 header.pldm_type = PLDM_OEM;
1089 header.command = PLDM_NEW_FILE_AVAILABLE_WITH_META_DATA;
1090 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
1091 if (rc != PLDM_SUCCESS) {
1092 return rc;
1093 }
1094
1095 struct pldm_new_file_with_metadata_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +09301096 (struct pldm_new_file_with_metadata_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +09301097
1098 if (response->completion_code == PLDM_SUCCESS) {
1099 response->completion_code = completion_code;
1100 }
1101
1102 return PLDM_SUCCESS;
1103}