blob: 02dca1a51d7e5c766dfafc87b9c57a617e2a3a55 [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 Jeffery9d2a1c62023-06-05 13:02:16 +093068LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093069int encode_get_types_req(uint8_t instance_id, struct pldm_msg *msg)
70{
71 if (msg == NULL) {
72 return PLDM_ERROR_INVALID_DATA;
73 }
74
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093075 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093076 header.instance = instance_id;
77 header.msg_type = PLDM_REQUEST;
78 header.command = PLDM_GET_PLDM_TYPES;
79
80 return pack_pldm_header(&header, &(msg->hdr));
81}
82
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +093083LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +093084int encode_get_commands_req(uint8_t instance_id, uint8_t type, ver32_t version,
85 struct pldm_msg *msg)
86{
87 if (msg == NULL) {
88 return PLDM_ERROR_INVALID_DATA;
89 }
90
Andrew Jeffery37dd6a32023-05-12 16:04:06 +093091 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +093092 header.instance = instance_id;
93 header.msg_type = PLDM_REQUEST;
94 header.command = PLDM_GET_PLDM_COMMANDS;
95
96 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
97 if (rc != PLDM_SUCCESS) {
98 return rc;
99 }
100
101 struct pldm_get_commands_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930102 (struct pldm_get_commands_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930103
104 request->type = type;
105 request->version = version;
106
107 return PLDM_SUCCESS;
108}
109
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930110LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930111int encode_get_types_resp(uint8_t instance_id, uint8_t completion_code,
112 const bitfield8_t *types, struct pldm_msg *msg)
113{
114 if (msg == NULL) {
115 return PLDM_ERROR_INVALID_DATA;
116 }
117
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930118 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930119 header.instance = instance_id;
120 header.msg_type = PLDM_RESPONSE;
121 header.command = PLDM_GET_PLDM_TYPES;
122
123 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
124 if (rc != PLDM_SUCCESS) {
125 return rc;
126 }
127
128 struct pldm_get_types_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930129 (struct pldm_get_types_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930130 response->completion_code = completion_code;
131 if (response->completion_code == PLDM_SUCCESS) {
132 if (types == NULL) {
133 return PLDM_ERROR_INVALID_DATA;
134 }
135 memcpy(response->types, &(types->byte), PLDM_MAX_TYPES / 8);
136 }
137
138 return PLDM_SUCCESS;
139}
140
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930141LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930142int decode_get_commands_req(const struct pldm_msg *msg, size_t payload_length,
143 uint8_t *type, ver32_t *version)
144{
145 if (msg == NULL || type == NULL || version == NULL) {
146 return PLDM_ERROR_INVALID_DATA;
147 }
148
149 if (payload_length != PLDM_GET_COMMANDS_REQ_BYTES) {
150 return PLDM_ERROR_INVALID_LENGTH;
151 }
152
153 struct pldm_get_commands_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930154 (struct pldm_get_commands_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930155 *type = request->type;
156 *version = request->version;
157 return PLDM_SUCCESS;
158}
159
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930160LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930161int encode_get_commands_resp(uint8_t instance_id, uint8_t completion_code,
162 const bitfield8_t *commands, struct pldm_msg *msg)
163{
164 if (msg == NULL) {
165 return PLDM_ERROR_INVALID_DATA;
166 }
167
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930168 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930169 header.instance = instance_id;
170 header.msg_type = PLDM_RESPONSE;
171 header.command = PLDM_GET_PLDM_COMMANDS;
172 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
173 if (rc != PLDM_SUCCESS) {
174 return rc;
175 }
176
177 struct pldm_get_commands_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930178 (struct pldm_get_commands_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930179 response->completion_code = completion_code;
180 if (response->completion_code == PLDM_SUCCESS) {
181 if (commands == NULL) {
182 return PLDM_ERROR_INVALID_DATA;
183 }
184 memcpy(response->commands, &(commands->byte),
185 PLDM_MAX_CMDS_PER_TYPE / 8);
186 }
187
188 return PLDM_SUCCESS;
189}
190
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930191LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930192int decode_get_types_resp(const struct pldm_msg *msg, size_t payload_length,
193 uint8_t *completion_code, bitfield8_t *types)
194{
195 if (msg == NULL || types == NULL || completion_code == NULL) {
196 return PLDM_ERROR_INVALID_DATA;
197 }
198
199 *completion_code = msg->payload[0];
200 if (PLDM_SUCCESS != *completion_code) {
201 return PLDM_SUCCESS;
202 }
203
204 if (payload_length != PLDM_GET_TYPES_RESP_BYTES) {
205 return PLDM_ERROR_INVALID_LENGTH;
206 }
207
208 struct pldm_get_types_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930209 (struct pldm_get_types_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930210
211 memcpy(&(types->byte), response->types, PLDM_MAX_TYPES / 8);
212
213 return PLDM_SUCCESS;
214}
215
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930216LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930217int decode_get_commands_resp(const struct pldm_msg *msg, size_t payload_length,
218 uint8_t *completion_code, bitfield8_t *commands)
219{
220 if (msg == NULL || commands == NULL || completion_code == NULL) {
221 return PLDM_ERROR_INVALID_DATA;
222 }
223
224 *completion_code = msg->payload[0];
225 if (PLDM_SUCCESS != *completion_code) {
226 return PLDM_SUCCESS;
227 }
228
229 if (payload_length != PLDM_GET_COMMANDS_RESP_BYTES) {
230 return PLDM_ERROR_INVALID_LENGTH;
231 }
232
233 struct pldm_get_commands_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930234 (struct pldm_get_commands_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930235
236 memcpy(&(commands->byte), response->commands,
237 PLDM_MAX_CMDS_PER_TYPE / 8);
238
239 return PLDM_SUCCESS;
240}
241
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930242LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930243int encode_get_version_req(uint8_t instance_id, uint32_t transfer_handle,
244 uint8_t transfer_opflag, uint8_t type,
245 struct pldm_msg *msg)
246{
247 if (NULL == msg) {
248 return PLDM_ERROR_INVALID_DATA;
249 }
250
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930251 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930252 header.msg_type = PLDM_REQUEST;
253 header.instance = instance_id;
254 header.pldm_type = PLDM_BASE;
255 header.command = PLDM_GET_PLDM_VERSION;
256
257 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
258 if (rc != PLDM_SUCCESS) {
259 return rc;
260 }
261
262 struct pldm_get_version_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930263 (struct pldm_get_version_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930264 transfer_handle = htole32(transfer_handle);
265 request->transfer_handle = transfer_handle;
266 request->transfer_opflag = transfer_opflag;
267 request->type = type;
268
269 return PLDM_SUCCESS;
270}
271
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930272LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930273int encode_get_version_resp(uint8_t instance_id, uint8_t completion_code,
274 uint32_t next_transfer_handle,
275 uint8_t transfer_flag, const ver32_t *version_data,
276 size_t version_size, struct pldm_msg *msg)
277{
278 if (NULL == msg) {
279 return PLDM_ERROR_INVALID_DATA;
280 }
281
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930282 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930283 header.msg_type = PLDM_RESPONSE;
284 header.instance = instance_id;
285 header.pldm_type = PLDM_BASE;
286 header.command = PLDM_GET_PLDM_VERSION;
287
288 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
289 if (rc != PLDM_SUCCESS) {
290 return rc;
291 }
292
293 struct pldm_get_version_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930294 (struct pldm_get_version_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930295 response->completion_code = completion_code;
296 if (response->completion_code == PLDM_SUCCESS) {
297 response->next_transfer_handle = htole32(next_transfer_handle);
298 response->transfer_flag = transfer_flag;
299 memcpy(response->version_data, (uint8_t *)version_data,
300 version_size);
301 }
302 return PLDM_SUCCESS;
303}
304
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930305LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930306int decode_get_version_req(const struct pldm_msg *msg, size_t payload_length,
307 uint32_t *transfer_handle, uint8_t *transfer_opflag,
308 uint8_t *type)
309{
Andrew Jeffery9c766792022-08-10 23:12:49 +0930310 if (payload_length != PLDM_GET_VERSION_REQ_BYTES) {
311 return PLDM_ERROR_INVALID_LENGTH;
312 }
313
314 struct pldm_get_version_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930315 (struct pldm_get_version_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930316 *transfer_handle = le32toh(request->transfer_handle);
317 *transfer_opflag = request->transfer_opflag;
318 *type = request->type;
319 return PLDM_SUCCESS;
320}
321
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930322LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930323int decode_get_version_resp(const struct pldm_msg *msg, size_t payload_length,
324 uint8_t *completion_code,
325 uint32_t *next_transfer_handle,
326 uint8_t *transfer_flag, ver32_t *version)
327{
328 if (msg == NULL || next_transfer_handle == NULL ||
329 transfer_flag == NULL || completion_code == NULL) {
330 return PLDM_ERROR_INVALID_DATA;
331 }
332
333 *completion_code = msg->payload[0];
334 if (PLDM_SUCCESS != *completion_code) {
335 return PLDM_SUCCESS;
336 }
337
338 if (payload_length < PLDM_GET_VERSION_RESP_BYTES) {
339 return PLDM_ERROR_INVALID_LENGTH;
340 }
341
342 struct pldm_get_version_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930343 (struct pldm_get_version_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930344
345 *next_transfer_handle = le32toh(response->next_transfer_handle);
346 *transfer_flag = response->transfer_flag;
347 memcpy(version, (uint8_t *)response->version_data, sizeof(ver32_t));
348
349 return PLDM_SUCCESS;
350}
351
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930352LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930353int encode_get_tid_req(uint8_t instance_id, struct pldm_msg *msg)
354{
355 if (msg == NULL) {
356 return PLDM_ERROR_INVALID_DATA;
357 }
358
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930359 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930360 header.instance = instance_id;
361 header.msg_type = PLDM_REQUEST;
362 header.command = PLDM_GET_TID;
363
364 return pack_pldm_header(&header, &(msg->hdr));
365}
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930366
367LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930368int encode_get_tid_resp(uint8_t instance_id, uint8_t completion_code,
369 uint8_t tid, struct pldm_msg *msg)
370{
371 if (msg == NULL) {
372 return PLDM_ERROR_INVALID_DATA;
373 }
374
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930375 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930376 header.instance = instance_id;
377 header.msg_type = PLDM_RESPONSE;
378 header.command = PLDM_GET_TID;
379
380 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
381 if (rc != PLDM_SUCCESS) {
382 return rc;
383 }
384
385 struct pldm_get_tid_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930386 (struct pldm_get_tid_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930387 response->completion_code = completion_code;
388 response->tid = tid;
389
390 return PLDM_SUCCESS;
391}
392
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930393LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930394int decode_get_tid_resp(const struct pldm_msg *msg, size_t payload_length,
395 uint8_t *completion_code, uint8_t *tid)
396{
397 if (msg == NULL || tid == NULL || completion_code == NULL) {
398 return PLDM_ERROR_INVALID_DATA;
399 }
400
401 *completion_code = msg->payload[0];
402 if (PLDM_SUCCESS != *completion_code) {
403 return PLDM_SUCCESS;
404 }
405
406 if (payload_length != PLDM_GET_TID_RESP_BYTES) {
407 return PLDM_ERROR_INVALID_LENGTH;
408 }
409
410 struct pldm_get_tid_resp *response =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930411 (struct pldm_get_tid_resp *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930412
413 *tid = response->tid;
414
415 return PLDM_SUCCESS;
416}
417
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930418LIBPLDM_ABI_STABLE
Gilbert Chen6c9c9172022-10-18 17:07:29 +0800419int encode_set_tid_req(uint8_t instance_id, uint8_t tid, struct pldm_msg *msg)
420{
421 if (msg == NULL) {
422 return PLDM_ERROR_INVALID_DATA;
423 }
424
425 if (tid == 0x0 || tid == 0xff) {
426 return PLDM_ERROR_INVALID_DATA;
427 }
428
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930429 struct pldm_header_info header = { 0 };
Gilbert Chen6c9c9172022-10-18 17:07:29 +0800430 header.instance = instance_id;
431 header.msg_type = PLDM_REQUEST;
432 header.command = PLDM_SET_TID;
433
434 uint8_t rc = pack_pldm_header(&header, &(msg->hdr));
435 if (rc != PLDM_SUCCESS) {
436 return rc;
437 }
438
439 struct pldm_set_tid_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930440 (struct pldm_set_tid_req *)msg->payload;
Gilbert Chen6c9c9172022-10-18 17:07:29 +0800441 request->tid = tid;
442
443 return PLDM_SUCCESS;
444}
445
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930446LIBPLDM_ABI_STABLE
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930447int decode_multipart_receive_req(const struct pldm_msg *msg,
448 size_t payload_length, uint8_t *pldm_type,
449 uint8_t *transfer_opflag,
450 uint32_t *transfer_ctx,
451 uint32_t *transfer_handle,
452 uint32_t *section_offset,
453 uint32_t *section_length)
Andrew Jeffery9c766792022-08-10 23:12:49 +0930454{
455 if (msg == NULL || pldm_type == NULL || transfer_opflag == NULL ||
456 transfer_ctx == NULL || transfer_handle == NULL ||
457 section_offset == NULL || section_length == NULL) {
458 return PLDM_ERROR_INVALID_DATA;
459 }
460
461 if (payload_length != PLDM_MULTIPART_RECEIVE_REQ_BYTES) {
462 return PLDM_ERROR_INVALID_LENGTH;
463 }
464
465 struct pldm_multipart_receive_req *request =
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930466 (struct pldm_multipart_receive_req *)msg->payload;
Andrew Jeffery9c766792022-08-10 23:12:49 +0930467
468 if (request->pldm_type != PLDM_BASE) {
469 return PLDM_ERROR_INVALID_PLDM_TYPE;
470 }
471
472 // Any enum value above PLDM_XFER_CURRENT_PART is invalid.
473 if (request->transfer_opflag > PLDM_XFER_CURRENT_PART) {
474 return PLDM_INVALID_TRANSFER_OPERATION_FLAG;
475 }
476
477 // A section offset of 0 is only valid on FIRST_PART or COMPLETE Xfers.
478 uint32_t sec_offset = le32toh(request->section_offset);
479 if (sec_offset == 0 &&
480 (request->transfer_opflag != PLDM_XFER_FIRST_PART &&
481 request->transfer_opflag != PLDM_XFER_COMPLETE)) {
482 return PLDM_ERROR_INVALID_DATA;
483 }
484
485 uint32_t handle = le32toh(request->transfer_handle);
486 if (handle == 0 && request->transfer_opflag != PLDM_XFER_COMPLETE) {
487 return PLDM_ERROR_INVALID_DATA;
488 }
489
490 *pldm_type = request->pldm_type;
491 *transfer_opflag = request->transfer_opflag;
492 *transfer_ctx = request->transfer_ctx;
493 *transfer_handle = handle;
494 *section_offset = sec_offset;
495 *section_length = le32toh(request->section_length);
496
497 return PLDM_SUCCESS;
498}
499
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930500LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930501int encode_cc_only_resp(uint8_t instance_id, uint8_t type, uint8_t command,
502 uint8_t cc, struct pldm_msg *msg)
503{
504 if (msg == NULL) {
505 return PLDM_ERROR_INVALID_DATA;
506 }
507
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930508 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930509 header.instance = instance_id;
510 header.msg_type = PLDM_RESPONSE;
511 header.pldm_type = type;
512 header.command = command;
513
514 uint8_t rc = pack_pldm_header(&header, &msg->hdr);
515 if (rc != PLDM_SUCCESS) {
516 return rc;
517 }
518
519 msg->payload[0] = cc;
520
521 return PLDM_SUCCESS;
522}
523
Andrew Jeffery9d2a1c62023-06-05 13:02:16 +0930524LIBPLDM_ABI_STABLE
Andrew Jeffery9c766792022-08-10 23:12:49 +0930525int encode_pldm_header_only(uint8_t msg_type, uint8_t instance_id,
526 uint8_t pldm_type, uint8_t command,
527 struct pldm_msg *msg)
528{
529 if (msg == NULL) {
530 return PLDM_ERROR_INVALID_DATA;
531 }
532
Andrew Jeffery37dd6a32023-05-12 16:04:06 +0930533 struct pldm_header_info header = { 0 };
Andrew Jeffery9c766792022-08-10 23:12:49 +0930534 header.msg_type = msg_type;
535 header.instance = instance_id;
536 header.pldm_type = pldm_type;
537 header.command = command;
538 return pack_pldm_header(&header, &(msg->hdr));
539}