blob: f0bbe82a68e240536a4715456e481decfcb5c0b9 [file] [log] [blame]
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09301#include "config.h"
Andrew Jeffery9c766792022-08-10 23:12:49 +09302#include "base.h"
Manojkiran Eda9a8e4972022-11-28 16:38:21 +05303#include "pldm_types.h"
4#include <endian.h>
5#include <stdint.h>
6#include <string.h>
Andrew Jeffery9c766792022-08-10 23:12:49 +09307
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +09308LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +09309uint8_t pack_pldm_header(const struct pldm_header_info *hdr,
10 struct pldm_msg_hdr *msg)
11{
12 if (msg == NULL || hdr == NULL) {
13 return PLDM_ERROR_INVALID_DATA;
14 }
15
16 if (hdr->msg_type != PLDM_RESPONSE && hdr->msg_type != PLDM_REQUEST &&
17 hdr->msg_type != PLDM_ASYNC_REQUEST_NOTIFY) {
18 return PLDM_ERROR_INVALID_DATA;
19 }
20
21 if (hdr->instance > PLDM_INSTANCE_MAX) {
22 return PLDM_ERROR_INVALID_DATA;
23 }
24
25 if (hdr->pldm_type > (PLDM_MAX_TYPES - 1)) {
26 return PLDM_ERROR_INVALID_PLDM_TYPE;
27 }
28
29 uint8_t datagram = (hdr->msg_type == PLDM_ASYNC_REQUEST_NOTIFY) ? 1 : 0;
30
31 if (hdr->msg_type == PLDM_RESPONSE) {
32 msg->request = PLDM_RESPONSE;
33 } else if (hdr->msg_type == PLDM_REQUEST ||
34 hdr->msg_type == PLDM_ASYNC_REQUEST_NOTIFY) {
35 msg->request = PLDM_REQUEST;
36 }
37 msg->datagram = datagram;
38 msg->reserved = 0;
39 msg->instance_id = hdr->instance;
40 msg->header_ver = PLDM_CURRENT_VERSION;
41 msg->type = hdr->pldm_type;
42 msg->command = hdr->command;
43
44 return PLDM_SUCCESS;
45}
46
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093047LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093048uint8_t unpack_pldm_header(const struct pldm_msg_hdr *msg,
49 struct pldm_header_info *hdr)
50{
51 if (msg == NULL) {
52 return PLDM_ERROR_INVALID_DATA;
53 }
54
55 if (msg->request == PLDM_RESPONSE) {
56 hdr->msg_type = PLDM_RESPONSE;
57 } else {
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093058 hdr->msg_type = msg->datagram ? PLDM_ASYNC_REQUEST_NOTIFY :
59 PLDM_REQUEST;
Andrew Jeffery9c766792022-08-10 23:12:49 +093060 }
61
62 hdr->instance = msg->instance_id;
63 hdr->pldm_type = msg->type;
64 hdr->command = msg->command;
65
66 return PLDM_SUCCESS;
67}
68
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093069LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093070int encode_get_types_req(uint8_t instance_id, struct pldm_msg *msg)
71{
72 if (msg == NULL) {
73 return PLDM_ERROR_INVALID_DATA;
74 }
75
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093076 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093077 header.instance = instance_id;
78 header.msg_type = PLDM_REQUEST;
79 header.command = PLDM_GET_PLDM_TYPES;
80
81 return pack_pldm_header(&header, &(msg->hdr));
82}
83
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093084LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093085int encode_get_commands_req(uint8_t instance_id, uint8_t type, ver32_t version,
86 struct pldm_msg *msg)
87{
88 if (msg == NULL) {
89 return PLDM_ERROR_INVALID_DATA;
90 }
91
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093092 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093093 header.instance = instance_id;
94 header.msg_type = PLDM_REQUEST;
95 header.command = PLDM_GET_PLDM_COMMANDS;
96
97 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
98 if (rc != PLDM_SUCCESS) {
99 return rc;
100 }
101
102 struct pldm_get_commands_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930103 (struct pldm_get_commands_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930104
105 request->type = type;
106 request->version = version;
107
108 return PLDM_SUCCESS;
109}
110
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930111LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930112int encode_get_types_resp(uint8_t instance_id, uint8_t completion_code,
113 const bitfield8_t *types, struct pldm_msg *msg)
114{
115 if (msg == NULL) {
116 return PLDM_ERROR_INVALID_DATA;
117 }
118
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930119 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930120 header.instance = instance_id;
121 header.msg_type = PLDM_RESPONSE;
122 header.command = PLDM_GET_PLDM_TYPES;
123
124 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
125 if (rc != PLDM_SUCCESS) {
126 return rc;
127 }
128
129 struct pldm_get_types_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930130 (struct pldm_get_types_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930131 response->completion_code = completion_code;
132 if (response->completion_code == PLDM_SUCCESS) {
133 if (types == NULL) {
134 return PLDM_ERROR_INVALID_DATA;
135 }
136 memcpy(response->types, &(types->byte), PLDM_MAX_TYPES / 8);
137 }
138
139 return PLDM_SUCCESS;
140}
141
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930142LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930143int decode_get_commands_req(const struct pldm_msg *msg, size_t payload_length,
144 uint8_t *type, ver32_t *version)
145{
146 if (msg == NULL || type == NULL || version == NULL) {
147 return PLDM_ERROR_INVALID_DATA;
148 }
149
150 if (payload_length != PLDM_GET_COMMANDS_REQ_BYTES) {
151 return PLDM_ERROR_INVALID_LENGTH;
152 }
153
154 struct pldm_get_commands_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930155 (struct pldm_get_commands_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930156 *type = request->type;
157 *version = request->version;
158 return PLDM_SUCCESS;
159}
160
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930161LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930162int encode_get_commands_resp(uint8_t instance_id, uint8_t completion_code,
163 const bitfield8_t *commands, struct pldm_msg *msg)
164{
165 if (msg == NULL) {
166 return PLDM_ERROR_INVALID_DATA;
167 }
168
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930169 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930170 header.instance = instance_id;
171 header.msg_type = PLDM_RESPONSE;
172 header.command = PLDM_GET_PLDM_COMMANDS;
173 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
174 if (rc != PLDM_SUCCESS) {
175 return rc;
176 }
177
178 struct pldm_get_commands_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930179 (struct pldm_get_commands_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930180 response->completion_code = completion_code;
181 if (response->completion_code == PLDM_SUCCESS) {
182 if (commands == NULL) {
183 return PLDM_ERROR_INVALID_DATA;
184 }
185 memcpy(response->commands, &(commands->byte),
186 PLDM_MAX_CMDS_PER_TYPE / 8);
187 }
188
189 return PLDM_SUCCESS;
190}
191
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930192LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930193int decode_get_types_resp(const struct pldm_msg *msg, size_t payload_length,
194 uint8_t *completion_code, bitfield8_t *types)
195{
196 if (msg == NULL || types == NULL || completion_code == NULL) {
197 return PLDM_ERROR_INVALID_DATA;
198 }
199
200 *completion_code = msg->payload[0];
201 if (PLDM_SUCCESS != *completion_code) {
202 return PLDM_SUCCESS;
203 }
204
205 if (payload_length != PLDM_GET_TYPES_RESP_BYTES) {
206 return PLDM_ERROR_INVALID_LENGTH;
207 }
208
209 struct pldm_get_types_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930210 (struct pldm_get_types_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930211
212 memcpy(&(types->byte), response->types, PLDM_MAX_TYPES / 8);
213
214 return PLDM_SUCCESS;
215}
216
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930217LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930218int decode_get_commands_resp(const struct pldm_msg *msg, size_t payload_length,
219 uint8_t *completion_code, bitfield8_t *commands)
220{
221 if (msg == NULL || commands == NULL || completion_code == NULL) {
222 return PLDM_ERROR_INVALID_DATA;
223 }
224
225 *completion_code = msg->payload[0];
226 if (PLDM_SUCCESS != *completion_code) {
227 return PLDM_SUCCESS;
228 }
229
230 if (payload_length != PLDM_GET_COMMANDS_RESP_BYTES) {
231 return PLDM_ERROR_INVALID_LENGTH;
232 }
233
234 struct pldm_get_commands_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930235 (struct pldm_get_commands_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930236
237 memcpy(&(commands->byte), response->commands,
238 PLDM_MAX_CMDS_PER_TYPE / 8);
239
240 return PLDM_SUCCESS;
241}
242
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930243LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930244int encode_get_version_req(uint8_t instance_id, uint32_t transfer_handle,
245 uint8_t transfer_opflag, uint8_t type,
246 struct pldm_msg *msg)
247{
248 if (NULL == msg) {
249 return PLDM_ERROR_INVALID_DATA;
250 }
251
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930252 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930253 header.msg_type = PLDM_REQUEST;
254 header.instance = instance_id;
255 header.pldm_type = PLDM_BASE;
256 header.command = PLDM_GET_PLDM_VERSION;
257
258 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
259 if (rc != PLDM_SUCCESS) {
260 return rc;
261 }
262
263 struct pldm_get_version_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930264 (struct pldm_get_version_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930265 transfer_handle = htole32(transfer_handle);
266 request->transfer_handle = transfer_handle;
267 request->transfer_opflag = transfer_opflag;
268 request->type = type;
269
270 return PLDM_SUCCESS;
271}
272
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930273LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930274int encode_get_version_resp(uint8_t instance_id, uint8_t completion_code,
275 uint32_t next_transfer_handle,
276 uint8_t transfer_flag, const ver32_t *version_data,
277 size_t version_size, struct pldm_msg *msg)
278{
279 if (NULL == msg) {
280 return PLDM_ERROR_INVALID_DATA;
281 }
282
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930283 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930284 header.msg_type = PLDM_RESPONSE;
285 header.instance = instance_id;
286 header.pldm_type = PLDM_BASE;
287 header.command = PLDM_GET_PLDM_VERSION;
288
289 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
290 if (rc != PLDM_SUCCESS) {
291 return rc;
292 }
293
294 struct pldm_get_version_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930295 (struct pldm_get_version_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930296 response->completion_code = completion_code;
297 if (response->completion_code == PLDM_SUCCESS) {
298 response->next_transfer_handle = htole32(next_transfer_handle);
299 response->transfer_flag = transfer_flag;
300 memcpy(response->version_data, (uint8_t *)version_data,
301 version_size);
302 }
303 return PLDM_SUCCESS;
304}
305
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930306LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930307int decode_get_version_req(const struct pldm_msg *msg, size_t payload_length,
308 uint32_t *transfer_handle, uint8_t *transfer_opflag,
309 uint8_t *type)
310{
Andrew Jeffery9c766792022-08-10 23:12:49 +0930311 if (payload_length != PLDM_GET_VERSION_REQ_BYTES) {
312 return PLDM_ERROR_INVALID_LENGTH;
313 }
314
315 struct pldm_get_version_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930316 (struct pldm_get_version_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930317 *transfer_handle = le32toh(request->transfer_handle);
318 *transfer_opflag = request->transfer_opflag;
319 *type = request->type;
320 return PLDM_SUCCESS;
321}
322
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930323LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930324int decode_get_version_resp(const struct pldm_msg *msg, size_t payload_length,
325 uint8_t *completion_code,
326 uint32_t *next_transfer_handle,
327 uint8_t *transfer_flag, ver32_t *version)
328{
329 if (msg == NULL || next_transfer_handle == NULL ||
330 transfer_flag == NULL || completion_code == NULL) {
331 return PLDM_ERROR_INVALID_DATA;
332 }
333
334 *completion_code = msg->payload[0];
335 if (PLDM_SUCCESS != *completion_code) {
336 return PLDM_SUCCESS;
337 }
338
339 if (payload_length < PLDM_GET_VERSION_RESP_BYTES) {
340 return PLDM_ERROR_INVALID_LENGTH;
341 }
342
343 struct pldm_get_version_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930344 (struct pldm_get_version_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930345
346 *next_transfer_handle = le32toh(response->next_transfer_handle);
347 *transfer_flag = response->transfer_flag;
348 memcpy(version, (uint8_t *)response->version_data, sizeof(ver32_t));
349
350 return PLDM_SUCCESS;
351}
352
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930353LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930354int encode_get_tid_req(uint8_t instance_id, struct pldm_msg *msg)
355{
356 if (msg == NULL) {
357 return PLDM_ERROR_INVALID_DATA;
358 }
359
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930360 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930361 header.instance = instance_id;
362 header.msg_type = PLDM_REQUEST;
363 header.command = PLDM_GET_TID;
364
365 return pack_pldm_header(&header, &(msg->hdr));
366}
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930367
368LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930369int encode_get_tid_resp(uint8_t instance_id, uint8_t completion_code,
370 uint8_t tid, struct pldm_msg *msg)
371{
372 if (msg == NULL) {
373 return PLDM_ERROR_INVALID_DATA;
374 }
375
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930376 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930377 header.instance = instance_id;
378 header.msg_type = PLDM_RESPONSE;
379 header.command = PLDM_GET_TID;
380
381 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
382 if (rc != PLDM_SUCCESS) {
383 return rc;
384 }
385
386 struct pldm_get_tid_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930387 (struct pldm_get_tid_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930388 response->completion_code = completion_code;
389 response->tid = tid;
390
391 return PLDM_SUCCESS;
392}
393
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930394LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930395int decode_get_tid_resp(const struct pldm_msg *msg, size_t payload_length,
396 uint8_t *completion_code, uint8_t *tid)
397{
398 if (msg == NULL || tid == NULL || completion_code == NULL) {
399 return PLDM_ERROR_INVALID_DATA;
400 }
401
402 *completion_code = msg->payload[0];
403 if (PLDM_SUCCESS != *completion_code) {
404 return PLDM_SUCCESS;
405 }
406
407 if (payload_length != PLDM_GET_TID_RESP_BYTES) {
408 return PLDM_ERROR_INVALID_LENGTH;
409 }
410
411 struct pldm_get_tid_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930412 (struct pldm_get_tid_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930413
414 *tid = response->tid;
415
416 return PLDM_SUCCESS;
417}
418
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930419LIBPLDM_ABI_STABLE
Gilbert Chen6c9c9172022-10-18 17:07:29 +0800420int encode_set_tid_req(uint8_t instance_id, uint8_t tid, struct pldm_msg *msg)
421{
422 if (msg == NULL) {
423 return PLDM_ERROR_INVALID_DATA;
424 }
425
426 if (tid == 0x0 || tid == 0xff) {
427 return PLDM_ERROR_INVALID_DATA;
428 }
429
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930430 struct pldm_header_info header = { 0 };
Gilbert Chen6c9c9172022-10-18 17:07:29 +0800431 header.instance = instance_id;
432 header.msg_type = PLDM_REQUEST;
433 header.command = PLDM_SET_TID;
434
435 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
436 if (rc != PLDM_SUCCESS) {
437 return rc;
438 }
439
440 struct pldm_set_tid_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930441 (struct pldm_set_tid_req *)msg->payload;
Gilbert Chen6c9c9172022-10-18 17:07:29 +0800442 request->tid = tid;
443
444 return PLDM_SUCCESS;
445}
446
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930447LIBPLDM_ABI_STABLE
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930448int decode_multipart_receive_req(const struct pldm_msg *msg,
449 size_t payload_length, uint8_t *pldm_type,
450 uint8_t *transfer_opflag,
451 uint32_t *transfer_ctx,
452 uint32_t *transfer_handle,
453 uint32_t *section_offset,
454 uint32_t *section_length)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930455{
456 if (msg == NULL || pldm_type == NULL || transfer_opflag == NULL ||
457 transfer_ctx == NULL || transfer_handle == NULL ||
458 section_offset == NULL || section_length == NULL) {
459 return PLDM_ERROR_INVALID_DATA;
460 }
461
462 if (payload_length != PLDM_MULTIPART_RECEIVE_REQ_BYTES) {
463 return PLDM_ERROR_INVALID_LENGTH;
464 }
465
466 struct pldm_multipart_receive_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930467 (struct pldm_multipart_receive_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930468
469 if (request->pldm_type != PLDM_BASE) {
470 return PLDM_ERROR_INVALID_PLDM_TYPE;
471 }
472
473 // Any enum value above PLDM_XFER_CURRENT_PART is invalid.
474 if (request->transfer_opflag > PLDM_XFER_CURRENT_PART) {
475 return PLDM_INVALID_TRANSFER_OPERATION_FLAG;
476 }
477
478 // A section offset of 0 is only valid on FIRST_PART or COMPLETE Xfers.
479 uint32_t sec_offset = le32toh(request->section_offset);
480 if (sec_offset == 0 &&
481 (request->transfer_opflag != PLDM_XFER_FIRST_PART &&
482 request->transfer_opflag != PLDM_XFER_COMPLETE)) {
483 return PLDM_ERROR_INVALID_DATA;
484 }
485
486 uint32_t handle = le32toh(request->transfer_handle);
487 if (handle == 0 && request->transfer_opflag != PLDM_XFER_COMPLETE) {
488 return PLDM_ERROR_INVALID_DATA;
489 }
490
491 *pldm_type = request->pldm_type;
492 *transfer_opflag = request->transfer_opflag;
493 *transfer_ctx = request->transfer_ctx;
494 *transfer_handle = handle;
495 *section_offset = sec_offset;
496 *section_length = le32toh(request->section_length);
497
498 return PLDM_SUCCESS;
499}
500
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930501LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930502int encode_cc_only_resp(uint8_t instance_id, uint8_t type, uint8_t command,
503 uint8_t cc, struct pldm_msg *msg)
504{
505 if (msg == NULL) {
506 return PLDM_ERROR_INVALID_DATA;
507 }
508
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930509 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930510 header.instance = instance_id;
511 header.msg_type = PLDM_RESPONSE;
512 header.pldm_type = type;
513 header.command = command;
514
515 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
516 if (rc != PLDM_SUCCESS) {
517 return rc;
518 }
519
520 msg->payload[0] = cc;
521
522 return PLDM_SUCCESS;
523}
524
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930525LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930526int encode_pldm_header_only(uint8_t msg_type, uint8_t instance_id,
527 uint8_t pldm_type, uint8_t command,
528 struct pldm_msg *msg)
529{
530 if (msg == NULL) {
531 return PLDM_ERROR_INVALID_DATA;
532 }
533
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930534 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930535 header.msg_type = msg_type;
536 header.instance = instance_id;
537 header.pldm_type = pldm_type;
538 header.command = command;
539 return pack_pldm_header(&header, &(msg->hdr));
540}