blob: 908621bceeeeede22efec57fe7dc72f8449a74a1 [file] [log] [blame]
Andrew Jeffery9c766792022-08-10 23:12:49 +09301#include "base.h"
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05302#include "pldm_types.h"
3#include <endian.h>
4#include <stdint.h>
5#include <string.h>
Andrew Jeffery9c766792022-08-10 23:12:49 +09306
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09307LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +09308uint8_t pack_pldm_header(const struct pldm_header_info *hdr,
9 struct pldm_msg_hdr *msg)
10{
11 if (msg == NULL || hdr == NULL) {
12 return PLDM_ERROR_INVALID_DATA;
13 }
14
15 if (hdr->msg_type != PLDM_RESPONSE && hdr->msg_type != PLDM_REQUEST &&
16 hdr->msg_type != PLDM_ASYNC_REQUEST_NOTIFY) {
17 return PLDM_ERROR_INVALID_DATA;
18 }
19
20 if (hdr->instance > PLDM_INSTANCE_MAX) {
21 return PLDM_ERROR_INVALID_DATA;
22 }
23
24 if (hdr->pldm_type > (PLDM_MAX_TYPES - 1)) {
25 return PLDM_ERROR_INVALID_PLDM_TYPE;
26 }
27
28 uint8_t datagram = (hdr->msg_type == PLDM_ASYNC_REQUEST_NOTIFY) ? 1 : 0;
29
30 if (hdr->msg_type == PLDM_RESPONSE) {
31 msg->request = PLDM_RESPONSE;
32 } else if (hdr->msg_type == PLDM_REQUEST ||
33 hdr->msg_type == PLDM_ASYNC_REQUEST_NOTIFY) {
34 msg->request = PLDM_REQUEST;
35 }
36 msg->datagram = datagram;
37 msg->reserved = 0;
38 msg->instance_id = hdr->instance;
39 msg->header_ver = PLDM_CURRENT_VERSION;
40 msg->type = hdr->pldm_type;
41 msg->command = hdr->command;
42
43 return PLDM_SUCCESS;
44}
45
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093046LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093047uint8_t unpack_pldm_header(const struct pldm_msg_hdr *msg,
48 struct pldm_header_info *hdr)
49{
50 if (msg == NULL) {
51 return PLDM_ERROR_INVALID_DATA;
52 }
53
54 if (msg->request == PLDM_RESPONSE) {
55 hdr->msg_type = PLDM_RESPONSE;
56 } else {
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093057 hdr->msg_type = msg->datagram ? PLDM_ASYNC_REQUEST_NOTIFY :
58 PLDM_REQUEST;
Andrew Jeffery9c766792022-08-10 23:12:49 +093059 }
60
61 hdr->instance = msg->instance_id;
62 hdr->pldm_type = msg->type;
63 hdr->command = msg->command;
64
65 return PLDM_SUCCESS;
66}
67
Andrew Jeffery5239d9a2023-10-16 10:51:53 +103068LIBPLDM_ABI_STABLE
Andrew Jeffery91c06e92023-09-22 15:22:54 +093069bool pldm_msg_hdr_correlate_response(const struct pldm_msg_hdr *req,
70 const struct pldm_msg_hdr *resp)
71{
72 return req->instance_id == resp->instance_id && req->request &&
73 !resp->request && req->type == resp->type &&
74 req->command == resp->command;
75}
76
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093077LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093078int encode_get_types_req(uint8_t instance_id, struct pldm_msg *msg)
79{
80 if (msg == NULL) {
81 return PLDM_ERROR_INVALID_DATA;
82 }
83
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093084 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093085 header.instance = instance_id;
86 header.msg_type = PLDM_REQUEST;
87 header.command = PLDM_GET_PLDM_TYPES;
88
89 return pack_pldm_header(&header, &(msg->hdr));
90}
91
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093092LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093093int encode_get_commands_req(uint8_t instance_id, uint8_t type, ver32_t version,
94 struct pldm_msg *msg)
95{
96 if (msg == NULL) {
97 return PLDM_ERROR_INVALID_DATA;
98 }
99
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930100 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930101 header.instance = instance_id;
102 header.msg_type = PLDM_REQUEST;
103 header.command = PLDM_GET_PLDM_COMMANDS;
104
105 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
106 if (rc != PLDM_SUCCESS) {
107 return rc;
108 }
109
110 struct pldm_get_commands_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930111 (struct pldm_get_commands_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930112
113 request->type = type;
114 request->version = version;
115
116 return PLDM_SUCCESS;
117}
118
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930119LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930120int encode_get_types_resp(uint8_t instance_id, uint8_t completion_code,
121 const bitfield8_t *types, struct pldm_msg *msg)
122{
123 if (msg == NULL) {
124 return PLDM_ERROR_INVALID_DATA;
125 }
126
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930127 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930128 header.instance = instance_id;
129 header.msg_type = PLDM_RESPONSE;
130 header.command = PLDM_GET_PLDM_TYPES;
131
132 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
133 if (rc != PLDM_SUCCESS) {
134 return rc;
135 }
136
137 struct pldm_get_types_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930138 (struct pldm_get_types_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930139 response->completion_code = completion_code;
140 if (response->completion_code == PLDM_SUCCESS) {
141 if (types == NULL) {
142 return PLDM_ERROR_INVALID_DATA;
143 }
144 memcpy(response->types, &(types->byte), PLDM_MAX_TYPES / 8);
145 }
146
147 return PLDM_SUCCESS;
148}
149
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930150LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930151int decode_get_commands_req(const struct pldm_msg *msg, size_t payload_length,
152 uint8_t *type, ver32_t *version)
153{
154 if (msg == NULL || type == NULL || version == NULL) {
155 return PLDM_ERROR_INVALID_DATA;
156 }
157
158 if (payload_length != PLDM_GET_COMMANDS_REQ_BYTES) {
159 return PLDM_ERROR_INVALID_LENGTH;
160 }
161
162 struct pldm_get_commands_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930163 (struct pldm_get_commands_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930164 *type = request->type;
165 *version = request->version;
166 return PLDM_SUCCESS;
167}
168
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930169LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930170int encode_get_commands_resp(uint8_t instance_id, uint8_t completion_code,
171 const bitfield8_t *commands, struct pldm_msg *msg)
172{
173 if (msg == NULL) {
174 return PLDM_ERROR_INVALID_DATA;
175 }
176
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930177 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930178 header.instance = instance_id;
179 header.msg_type = PLDM_RESPONSE;
180 header.command = PLDM_GET_PLDM_COMMANDS;
181 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
182 if (rc != PLDM_SUCCESS) {
183 return rc;
184 }
185
186 struct pldm_get_commands_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930187 (struct pldm_get_commands_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930188 response->completion_code = completion_code;
189 if (response->completion_code == PLDM_SUCCESS) {
190 if (commands == NULL) {
191 return PLDM_ERROR_INVALID_DATA;
192 }
193 memcpy(response->commands, &(commands->byte),
194 PLDM_MAX_CMDS_PER_TYPE / 8);
195 }
196
197 return PLDM_SUCCESS;
198}
199
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930200LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930201int decode_get_types_resp(const struct pldm_msg *msg, size_t payload_length,
202 uint8_t *completion_code, bitfield8_t *types)
203{
204 if (msg == NULL || types == NULL || completion_code == NULL) {
205 return PLDM_ERROR_INVALID_DATA;
206 }
207
208 *completion_code = msg->payload[0];
209 if (PLDM_SUCCESS != *completion_code) {
210 return PLDM_SUCCESS;
211 }
212
213 if (payload_length != PLDM_GET_TYPES_RESP_BYTES) {
214 return PLDM_ERROR_INVALID_LENGTH;
215 }
216
217 struct pldm_get_types_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930218 (struct pldm_get_types_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930219
220 memcpy(&(types->byte), response->types, PLDM_MAX_TYPES / 8);
221
222 return PLDM_SUCCESS;
223}
224
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930225LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930226int decode_get_commands_resp(const struct pldm_msg *msg, size_t payload_length,
227 uint8_t *completion_code, bitfield8_t *commands)
228{
229 if (msg == NULL || commands == NULL || completion_code == NULL) {
230 return PLDM_ERROR_INVALID_DATA;
231 }
232
233 *completion_code = msg->payload[0];
234 if (PLDM_SUCCESS != *completion_code) {
235 return PLDM_SUCCESS;
236 }
237
238 if (payload_length != PLDM_GET_COMMANDS_RESP_BYTES) {
239 return PLDM_ERROR_INVALID_LENGTH;
240 }
241
242 struct pldm_get_commands_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930243 (struct pldm_get_commands_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930244
245 memcpy(&(commands->byte), response->commands,
246 PLDM_MAX_CMDS_PER_TYPE / 8);
247
248 return PLDM_SUCCESS;
249}
250
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930251LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930252int encode_get_version_req(uint8_t instance_id, uint32_t transfer_handle,
253 uint8_t transfer_opflag, uint8_t type,
254 struct pldm_msg *msg)
255{
256 if (NULL == msg) {
257 return PLDM_ERROR_INVALID_DATA;
258 }
259
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930260 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930261 header.msg_type = PLDM_REQUEST;
262 header.instance = instance_id;
263 header.pldm_type = PLDM_BASE;
264 header.command = PLDM_GET_PLDM_VERSION;
265
266 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
267 if (rc != PLDM_SUCCESS) {
268 return rc;
269 }
270
271 struct pldm_get_version_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930272 (struct pldm_get_version_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930273 transfer_handle = htole32(transfer_handle);
274 request->transfer_handle = transfer_handle;
275 request->transfer_opflag = transfer_opflag;
276 request->type = type;
277
278 return PLDM_SUCCESS;
279}
280
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930281LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930282int encode_get_version_resp(uint8_t instance_id, uint8_t completion_code,
283 uint32_t next_transfer_handle,
284 uint8_t transfer_flag, const ver32_t *version_data,
285 size_t version_size, struct pldm_msg *msg)
286{
287 if (NULL == msg) {
288 return PLDM_ERROR_INVALID_DATA;
289 }
290
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930291 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930292 header.msg_type = PLDM_RESPONSE;
293 header.instance = instance_id;
294 header.pldm_type = PLDM_BASE;
295 header.command = PLDM_GET_PLDM_VERSION;
296
297 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
298 if (rc != PLDM_SUCCESS) {
299 return rc;
300 }
301
302 struct pldm_get_version_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930303 (struct pldm_get_version_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930304 response->completion_code = completion_code;
305 if (response->completion_code == PLDM_SUCCESS) {
306 response->next_transfer_handle = htole32(next_transfer_handle);
307 response->transfer_flag = transfer_flag;
308 memcpy(response->version_data, (uint8_t *)version_data,
309 version_size);
310 }
311 return PLDM_SUCCESS;
312}
313
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930314LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930315int decode_get_version_req(const struct pldm_msg *msg, size_t payload_length,
316 uint32_t *transfer_handle, uint8_t *transfer_opflag,
317 uint8_t *type)
318{
Andrew Jeffery9c766792022-08-10 23:12:49 +0930319 if (payload_length != PLDM_GET_VERSION_REQ_BYTES) {
320 return PLDM_ERROR_INVALID_LENGTH;
321 }
322
323 struct pldm_get_version_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930324 (struct pldm_get_version_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930325 *transfer_handle = le32toh(request->transfer_handle);
326 *transfer_opflag = request->transfer_opflag;
327 *type = request->type;
328 return PLDM_SUCCESS;
329}
330
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930331LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930332int decode_get_version_resp(const struct pldm_msg *msg, size_t payload_length,
333 uint8_t *completion_code,
334 uint32_t *next_transfer_handle,
335 uint8_t *transfer_flag, ver32_t *version)
336{
337 if (msg == NULL || next_transfer_handle == NULL ||
338 transfer_flag == NULL || completion_code == NULL) {
339 return PLDM_ERROR_INVALID_DATA;
340 }
341
342 *completion_code = msg->payload[0];
343 if (PLDM_SUCCESS != *completion_code) {
344 return PLDM_SUCCESS;
345 }
346
347 if (payload_length < PLDM_GET_VERSION_RESP_BYTES) {
348 return PLDM_ERROR_INVALID_LENGTH;
349 }
350
351 struct pldm_get_version_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930352 (struct pldm_get_version_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930353
354 *next_transfer_handle = le32toh(response->next_transfer_handle);
355 *transfer_flag = response->transfer_flag;
356 memcpy(version, (uint8_t *)response->version_data, sizeof(ver32_t));
357
358 return PLDM_SUCCESS;
359}
360
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930361LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930362int encode_get_tid_req(uint8_t instance_id, struct pldm_msg *msg)
363{
364 if (msg == NULL) {
365 return PLDM_ERROR_INVALID_DATA;
366 }
367
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930368 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930369 header.instance = instance_id;
370 header.msg_type = PLDM_REQUEST;
371 header.command = PLDM_GET_TID;
372
373 return pack_pldm_header(&header, &(msg->hdr));
374}
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930375
376LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930377int encode_get_tid_resp(uint8_t instance_id, uint8_t completion_code,
378 uint8_t tid, struct pldm_msg *msg)
379{
380 if (msg == NULL) {
381 return PLDM_ERROR_INVALID_DATA;
382 }
383
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930384 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930385 header.instance = instance_id;
386 header.msg_type = PLDM_RESPONSE;
387 header.command = PLDM_GET_TID;
388
389 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
390 if (rc != PLDM_SUCCESS) {
391 return rc;
392 }
393
394 struct pldm_get_tid_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930395 (struct pldm_get_tid_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930396 response->completion_code = completion_code;
397 response->tid = tid;
398
399 return PLDM_SUCCESS;
400}
401
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930402LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930403int decode_get_tid_resp(const struct pldm_msg *msg, size_t payload_length,
404 uint8_t *completion_code, uint8_t *tid)
405{
406 if (msg == NULL || tid == NULL || completion_code == NULL) {
407 return PLDM_ERROR_INVALID_DATA;
408 }
409
410 *completion_code = msg->payload[0];
411 if (PLDM_SUCCESS != *completion_code) {
412 return PLDM_SUCCESS;
413 }
414
415 if (payload_length != PLDM_GET_TID_RESP_BYTES) {
416 return PLDM_ERROR_INVALID_LENGTH;
417 }
418
419 struct pldm_get_tid_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930420 (struct pldm_get_tid_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930421
422 *tid = response->tid;
423
424 return PLDM_SUCCESS;
425}
426
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930427LIBPLDM_ABI_STABLE
Gilbert Chen6c9c9172022-10-18 17:07:29 +0800428int encode_set_tid_req(uint8_t instance_id, uint8_t tid, struct pldm_msg *msg)
429{
430 if (msg == NULL) {
431 return PLDM_ERROR_INVALID_DATA;
432 }
433
434 if (tid == 0x0 || tid == 0xff) {
435 return PLDM_ERROR_INVALID_DATA;
436 }
437
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930438 struct pldm_header_info header = { 0 };
Gilbert Chen6c9c9172022-10-18 17:07:29 +0800439 header.instance = instance_id;
440 header.msg_type = PLDM_REQUEST;
441 header.command = PLDM_SET_TID;
442
443 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
444 if (rc != PLDM_SUCCESS) {
445 return rc;
446 }
447
448 struct pldm_set_tid_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930449 (struct pldm_set_tid_req *)msg->payload;
Gilbert Chen6c9c9172022-10-18 17:07:29 +0800450 request->tid = tid;
451
452 return PLDM_SUCCESS;
453}
454
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930455LIBPLDM_ABI_STABLE
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930456int decode_multipart_receive_req(const struct pldm_msg *msg,
457 size_t payload_length, uint8_t *pldm_type,
458 uint8_t *transfer_opflag,
459 uint32_t *transfer_ctx,
460 uint32_t *transfer_handle,
461 uint32_t *section_offset,
462 uint32_t *section_length)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930463{
464 if (msg == NULL || pldm_type == NULL || transfer_opflag == NULL ||
465 transfer_ctx == NULL || transfer_handle == NULL ||
466 section_offset == NULL || section_length == NULL) {
467 return PLDM_ERROR_INVALID_DATA;
468 }
469
470 if (payload_length != PLDM_MULTIPART_RECEIVE_REQ_BYTES) {
471 return PLDM_ERROR_INVALID_LENGTH;
472 }
473
474 struct pldm_multipart_receive_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930475 (struct pldm_multipart_receive_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930476
477 if (request->pldm_type != PLDM_BASE) {
478 return PLDM_ERROR_INVALID_PLDM_TYPE;
479 }
480
481 // Any enum value above PLDM_XFER_CURRENT_PART is invalid.
482 if (request->transfer_opflag > PLDM_XFER_CURRENT_PART) {
483 return PLDM_INVALID_TRANSFER_OPERATION_FLAG;
484 }
485
486 // A section offset of 0 is only valid on FIRST_PART or COMPLETE Xfers.
487 uint32_t sec_offset = le32toh(request->section_offset);
488 if (sec_offset == 0 &&
489 (request->transfer_opflag != PLDM_XFER_FIRST_PART &&
490 request->transfer_opflag != PLDM_XFER_COMPLETE)) {
491 return PLDM_ERROR_INVALID_DATA;
492 }
493
494 uint32_t handle = le32toh(request->transfer_handle);
495 if (handle == 0 && request->transfer_opflag != PLDM_XFER_COMPLETE) {
496 return PLDM_ERROR_INVALID_DATA;
497 }
498
499 *pldm_type = request->pldm_type;
500 *transfer_opflag = request->transfer_opflag;
501 *transfer_ctx = request->transfer_ctx;
502 *transfer_handle = handle;
503 *section_offset = sec_offset;
504 *section_length = le32toh(request->section_length);
505
506 return PLDM_SUCCESS;
507}
508
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930509LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930510int encode_cc_only_resp(uint8_t instance_id, uint8_t type, uint8_t command,
511 uint8_t cc, struct pldm_msg *msg)
512{
513 if (msg == NULL) {
514 return PLDM_ERROR_INVALID_DATA;
515 }
516
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930517 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930518 header.instance = instance_id;
519 header.msg_type = PLDM_RESPONSE;
520 header.pldm_type = type;
521 header.command = command;
522
523 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
524 if (rc != PLDM_SUCCESS) {
525 return rc;
526 }
527
528 msg->payload[0] = cc;
529
530 return PLDM_SUCCESS;
531}
532
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930533LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930534int encode_pldm_header_only(uint8_t msg_type, uint8_t instance_id,
535 uint8_t pldm_type, uint8_t command,
536 struct pldm_msg *msg)
537{
538 if (msg == NULL) {
539 return PLDM_ERROR_INVALID_DATA;
540 }
541
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930542 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930543 header.msg_type = msg_type;
544 header.instance = instance_id;
545 header.pldm_type = pldm_type;
546 header.command = command;
547 return pack_pldm_header(&header, &(msg->hdr));
548}