blob: be1e355a57661d5417cd265bdb06947287480a26 [file] [log] [blame]
Deepak Kodihalli1b24f972019-02-01 04:09:13 -06001#ifndef BASE_H
2#define BASE_H
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <asm/byteorder.h>
9#include <stddef.h>
10#include <stdint.h>
11
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -060012#include "pldm_types.h"
13
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060014/** @brief PLDM Types
15 */
16enum pldm_supported_types {
17 PLDM_BASE = 0x00,
Sampa Misra0db1dfa2019-03-19 00:15:31 -050018 PLDM_PLATFORM = 0x02,
Sampa Misra032bd502019-03-06 05:03:22 -060019 PLDM_BIOS = 0x03,
Jinu Joy Thomas8e92c6c2019-08-06 12:22:34 +053020 PLDM_FRU = 0x04,
gokulsanker138ceba2021-04-05 13:25:25 +053021 PLDM_FWUP = 0x05,
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050022 PLDM_OEM = 0x3F,
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060023};
24
25/** @brief PLDM Commands
26 */
27enum pldm_supported_commands {
John Wang5c4f80d2019-07-29 11:12:18 +080028 PLDM_GET_TID = 0x2,
Sampa Misra432e1872019-02-13 03:49:43 -060029 PLDM_GET_PLDM_VERSION = 0x3,
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060030 PLDM_GET_PLDM_TYPES = 0x4,
Joe Komlodie0b3f3f2022-07-20 22:53:38 +000031 PLDM_GET_PLDM_COMMANDS = 0x5,
32 PLDM_MULTIPART_RECEIVE = 0x9,
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060033};
34
35/** @brief PLDM base codes
36 */
37enum pldm_completion_codes {
38 PLDM_SUCCESS = 0x00,
39 PLDM_ERROR = 0x01,
40 PLDM_ERROR_INVALID_DATA = 0x02,
41 PLDM_ERROR_INVALID_LENGTH = 0x03,
42 PLDM_ERROR_NOT_READY = 0x04,
43 PLDM_ERROR_UNSUPPORTED_PLDM_CMD = 0x05,
gokulsanker1b909d82021-04-05 17:26:02 +053044 PLDM_ERROR_INVALID_PLDM_TYPE = 0x20,
45 PLDM_INVALID_TRANSFER_OPERATION_FLAG = 0x21
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060046};
47
Sampa Misra432e1872019-02-13 03:49:43 -060048enum transfer_op_flag {
49 PLDM_GET_NEXTPART = 0,
50 PLDM_GET_FIRSTPART = 1,
51};
52
Joe Komlodie0b3f3f2022-07-20 22:53:38 +000053enum transfer_multipart_op_flag {
54 PLDM_XFER_FIRST_PART = 0,
55 PLDM_XFER_NEXT_PART = 1,
56 PLDM_XFER_ABORT = 2,
57 PLDM_XFER_COMPLETE = 3,
58 PLDM_XFER_CURRENT_PART = 4,
59};
60
Sampa Misra432e1872019-02-13 03:49:43 -060061enum transfer_resp_flag {
62 PLDM_START = 0x01,
63 PLDM_MIDDLE = 0x02,
64 PLDM_END = 0x04,
65 PLDM_START_AND_END = 0x05,
66};
67
Sagar Srinivas535bccd2021-03-24 12:18:26 -050068/** @brief PLDM transport protocol type
69 */
70enum pldm_transport_protocol_type {
71 PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP = 0x00,
72 PLDM_TRANSPORT_PROTOCOL_TYPE_OEM = 0xFF,
73};
74
Tom Joseph41251042019-02-07 16:17:07 +053075/** @enum MessageType
76 *
77 * The different message types supported by the PLDM specification.
78 */
79typedef enum {
80 PLDM_RESPONSE, //!< PLDM response
81 PLDM_REQUEST, //!< PLDM request
82 PLDM_RESERVED, //!< Reserved
83 PLDM_ASYNC_REQUEST_NOTIFY, //!< Unacknowledged PLDM request messages
84} MessageType;
85
86#define PLDM_INSTANCE_MAX 31
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060087#define PLDM_MAX_TYPES 64
88#define PLDM_MAX_CMDS_PER_TYPE 256
89
90/* Message payload lengths */
91#define PLDM_GET_COMMANDS_REQ_BYTES 5
Sampa Misra432e1872019-02-13 03:49:43 -060092#define PLDM_GET_VERSION_REQ_BYTES 6
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060093
94/* Response lengths are inclusive of completion code */
95#define PLDM_GET_TYPES_RESP_BYTES 9
John Wang5c4f80d2019-07-29 11:12:18 +080096#define PLDM_GET_TID_RESP_BYTES 2
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060097#define PLDM_GET_COMMANDS_RESP_BYTES 33
Sampa Misra432e1872019-02-13 03:49:43 -060098/* Response data has only one version and does not contain the checksum */
99#define PLDM_GET_VERSION_RESP_BYTES 10
Joe Komlodie0b3f3f2022-07-20 22:53:38 +0000100#define PLDM_MULTIPART_RECEIVE_REQ_BYTES 18
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600101
Christian Geddes6c146f12020-05-01 14:48:23 -0500102#define PLDM_VERSION_0 0
103#define PLDM_CURRENT_VERSION PLDM_VERSION_0
104
Tom Joseph568e4702021-06-07 22:15:49 -0700105#define PLDM_TIMESTAMP104_SIZE 13
106
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600107/** @struct pldm_msg_hdr
108 *
109 * Structure representing PLDM message header fields
110 */
111struct pldm_msg_hdr {
112#if defined(__LITTLE_ENDIAN_BITFIELD)
113 uint8_t instance_id : 5; //!< Instance ID
Deepak Kodihalli826c9d42020-05-26 01:58:06 -0500114 uint8_t reserved : 1; //!< Reserved
115 uint8_t datagram : 1; //!< Datagram bit
116 uint8_t request : 1; //!< Request bit
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600117#elif defined(__BIG_ENDIAN_BITFIELD)
Deepak Kodihalli826c9d42020-05-26 01:58:06 -0500118 uint8_t request : 1; //!< Request bit
119 uint8_t datagram : 1; //!< Datagram bit
120 uint8_t reserved : 1; //!< Reserved
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600121 uint8_t instance_id : 5; //!< Instance ID
122#endif
123
124#if defined(__LITTLE_ENDIAN_BITFIELD)
Deepak Kodihalli826c9d42020-05-26 01:58:06 -0500125 uint8_t type : 6; //!< PLDM type
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600126 uint8_t header_ver : 2; //!< Header version
127#elif defined(__BIG_ENDIAN_BITFIELD)
Deepak Kodihalli826c9d42020-05-26 01:58:06 -0500128 uint8_t header_ver : 2; //!< Header version
129 uint8_t type : 6; //!< PLDM type
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600130#endif
131 uint8_t command; //!< PLDM command code
132} __attribute__((packed));
133
Zach Clarkb728eee2020-06-18 10:01:31 -0500134// Macros for byte-swapping variables in-place
135#define HTOLE32(X) (X = htole32(X))
136#define HTOLE16(X) (X = htole16(X))
George Liucae18662020-05-15 09:32:57 +0800137#define LE32TOH(X) (X = le32toh(X))
138#define LE16TOH(X) (X = le16toh(X))
Zach Clarkb728eee2020-06-18 10:01:31 -0500139
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600140/** @struct pldm_msg
141 *
142 * Structure representing PLDM message
143 */
144struct pldm_msg {
vkaverapa6575b82019-04-03 05:33:52 -0500145 struct pldm_msg_hdr hdr; //!< PLDM message header
146 uint8_t payload[1]; //!< &payload[0] is the beginning of the payload
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600147} __attribute__((packed));
148
Tom Joseph41251042019-02-07 16:17:07 +0530149/** @struct pldm_header_info
150 *
151 * The information needed to prepare PLDM header and this is passed to the
152 * pack_pldm_header and unpack_pldm_header API.
153 */
154struct pldm_header_info {
Deepak Kodihalli826c9d42020-05-26 01:58:06 -0500155 MessageType msg_type; //!< PLDM message type
156 uint8_t instance; //!< PLDM instance id
157 uint8_t pldm_type; //!< PLDM type
Tom Joseph41251042019-02-07 16:17:07 +0530158 uint8_t command; //!< PLDM command code
159 uint8_t completion_code; //!< PLDM completion code, applies for response
160};
161
Priyanga4b790ce2019-06-10 01:30:09 -0500162/** @struct pldm_get_types_resp
163 *
164 * Structure representing PLDM get types response.
165 */
166struct pldm_get_types_resp {
167 uint8_t completion_code; //!< completion code
168 bitfield8_t types[8]; //!< each bit represents whether a given PLDM Type
169 //!< is supported
170} __attribute__((packed));
171
172/** @struct pldm_get_commands_req
173 *
174 * Structure representing PLDM get commands request.
175 */
176struct pldm_get_commands_req {
Deepak Kodihalli826c9d42020-05-26 01:58:06 -0500177 uint8_t type; //!< PLDM Type for which command support information is
Priyanga4b790ce2019-06-10 01:30:09 -0500178 //!< being requested
179 ver32_t version; //!< version for the specified PLDM Type
180} __attribute__((packed));
181
182/** @struct pldm_get_commands_resp
183 *
184 * Structure representing PLDM get commands response.
185 */
186struct pldm_get_commands_resp {
187 uint8_t completion_code; //!< completion code
188 bitfield8_t commands[32]; //!< each bit represents whether a given PLDM
189 //!< command is supported
190} __attribute__((packed));
191
192/** @struct pldm_get_version_req
193 *
194 * Structure representing PLDM get version request.
195 */
196struct pldm_get_version_req {
197 uint32_t
198 transfer_handle; //!< handle to identify PLDM version data transfer
199 uint8_t transfer_opflag; //!< PLDM GetVersion operation flag
200 uint8_t type; //!< PLDM Type for which version information is being
201 //!< requested
202} __attribute__((packed));
203
204/** @struct pldm_get_version_resp
205 *
206 * Structure representing PLDM get version response.
207 */
208
209struct pldm_get_version_resp {
210 uint8_t completion_code; //!< completion code
211 uint32_t next_transfer_handle; //!< next portion of PLDM version data
212 //!< transfer
Deepak Kodihalli826c9d42020-05-26 01:58:06 -0500213 uint8_t transfer_flag; //!< PLDM GetVersion transfer flag
Priyanga4b790ce2019-06-10 01:30:09 -0500214 uint8_t version_data[1]; //!< PLDM GetVersion version field
215} __attribute__((packed));
216
John Wang5c4f80d2019-07-29 11:12:18 +0800217/** @struct pldm_get_tid_resp
218 *
219 * Structure representing PLDM get tid response.
220 */
221
222struct pldm_get_tid_resp {
223 uint8_t completion_code; //!< completion code
224 uint8_t tid; //!< PLDM GetTID TID field
225} __attribute__((packed));
226
Joe Komlodie0b3f3f2022-07-20 22:53:38 +0000227/** @struct pldm_multipart_receive_req
228 *
229 * Structure representing PLDM multipart receive request.
230 */
231struct pldm_multipart_receive_req {
232 uint8_t pldm_type; //!< PLDM Type for the MultipartReceive
233 //!< command.
234 uint8_t transfer_opflag; //!< PLDM MultipartReceive operation flag.
235 uint32_t transfer_ctx; //!< Protocol-specifc context for this
236 //!< transfer.
237 uint32_t transfer_handle; //!< handle to identify the part of data to be
238 //!< received.
239 uint32_t section_offset; //!< The start offset for the requested
240 //!< section.
241 uint32_t section_length; //!< The length (in bytes) of the section
242 //!< requested.
243} __attribute__((packed));
Tom Joseph41251042019-02-07 16:17:07 +0530244/**
245 * @brief Populate the PLDM message with the PLDM header.The caller of this API
246 * allocates buffer for the PLDM header when forming the PLDM message.
247 * The buffer is passed to this API to pack the PLDM header.
248 *
249 * @param[in] hdr - Pointer to the PLDM header information
250 * @param[out] msg - Pointer to PLDM message header
251 *
252 * @return 0 on success, otherwise PLDM error codes.
Christian Geddes6c146f12020-05-01 14:48:23 -0500253 * @note Caller is responsible for alloc and dealloc of msg
254 * and hdr params
Tom Joseph41251042019-02-07 16:17:07 +0530255 */
George Liub7095ff2021-06-14 16:01:57 +0800256uint8_t pack_pldm_header(const struct pldm_header_info *hdr,
257 struct pldm_msg_hdr *msg);
Tom Joseph41251042019-02-07 16:17:07 +0530258
259/**
260 * @brief Unpack the PLDM header from the PLDM message.
261 *
262 * @param[in] msg - Pointer to the PLDM message header
263 * @param[out] hdr - Pointer to the PLDM header information
264 *
265 * @return 0 on success, otherwise PLDM error codes.
Christian Geddes6c146f12020-05-01 14:48:23 -0500266 * @note Caller is responsible for alloc and dealloc of msg
267 * and hdr params
Tom Joseph41251042019-02-07 16:17:07 +0530268 */
George Liub7095ff2021-06-14 16:01:57 +0800269uint8_t unpack_pldm_header(const struct pldm_msg_hdr *msg,
270 struct pldm_header_info *hdr);
Tom Joseph41251042019-02-07 16:17:07 +0530271
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600272/* Requester */
273
274/* GetPLDMTypes */
275
276/** @brief Create a PLDM request message for GetPLDMTypes
277 *
278 * @param[in] instance_id - Message's instance id
279 * @param[in,out] msg - Message will be written to this
280 * @return pldm_completion_codes
281 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500282 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600283 */
284int encode_get_types_req(uint8_t instance_id, struct pldm_msg *msg);
285
286/** @brief Decode a GetPLDMTypes response message
287 *
George Liu684a7162019-12-06 15:10:52 +0800288 * Note:
289 * * If the return value is not PLDM_SUCCESS, it represents a
290 * transport layer error.
291 * * If the completion_code value is not PLDM_SUCCESS, it represents a
292 * protocol layer error and all the out-parameters are invalid.
293 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500294 * @param[in] msg - Response message
vkaverapa6575b82019-04-03 05:33:52 -0500295 * @param[in] payload_length - Length of response message payload
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600296 * @param[out] completion_code - Pointer to response msg's PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600297 * @param[out] types - pointer to array bitfield8_t[8] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600298 * types (MAX_TYPES/8) = 8), as per DSP0240
299 * @return pldm_completion_codes
300 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500301int decode_get_types_resp(const struct pldm_msg *msg, size_t payload_length,
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600302 uint8_t *completion_code, bitfield8_t *types);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600303
304/* GetPLDMCommands */
305
306/** @brief Create a PLDM request message for GetPLDMCommands
307 *
308 * @param[in] instance_id - Message's instance id
309 * @param[in] type - PLDM Type
310 * @param[in] version - Version for PLDM Type
311 * @param[in,out] msg - Message will be written to this
312 * @return pldm_completion_codes
313 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500314 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600315 */
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600316int encode_get_commands_req(uint8_t instance_id, uint8_t type, ver32_t version,
317 struct pldm_msg *msg);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600318
319/** @brief Decode a GetPLDMCommands response message
320 *
George Liu684a7162019-12-06 15:10:52 +0800321 * Note:
322 * * If the return value is not PLDM_SUCCESS, it represents a
323 * transport layer error.
324 * * If the completion_code value is not PLDM_SUCCESS, it represents a
325 * protocol layer error and all the out-parameters are invalid.
326 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500327 * @param[in] msg - Response message
vkaverapa6575b82019-04-03 05:33:52 -0500328 * @param[in] payload_length - Length of reponse message payload
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600329 * @param[out] completion_code - Pointer to response msg's PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600330 * @param[in] commands - pointer to array bitfield8_t[32] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600331 * commands (PLDM_MAX_CMDS_PER_TYPE/8) = 32), as per DSP0240
332 * @return pldm_completion_codes
333 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500334int decode_get_commands_resp(const struct pldm_msg *msg, size_t payload_length,
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600335 uint8_t *completion_code, bitfield8_t *commands);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600336
Sampa Misra432e1872019-02-13 03:49:43 -0600337/* GetPLDMVersion */
338
339/** @brief Create a PLDM request for GetPLDMVersion
340 *
341 * @param[in] instance_id - Message's instance id
342 * @param[in] transfer_handle - Handle to identify PLDM version data transfer.
343 * This handle is ignored by the responder when the
344 * transferop_flag is set to getFirstPart.
345 * @param[in] transfer_opflag - flag to indicate whether it is start of
346 * transfer
347 * @param[in] type - PLDM Type for which version is requested
348 * @param[in,out] msg - Message will be written to this
349 * @return pldm_completion_codes
350 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500351 * 'msg.payload'
Sampa Misra432e1872019-02-13 03:49:43 -0600352 */
353int encode_get_version_req(uint8_t instance_id, uint32_t transfer_handle,
354 uint8_t transfer_opflag, uint8_t type,
355 struct pldm_msg *msg);
356
357/** @brief Decode a GetPLDMVersion response message
358 *
George Liu684a7162019-12-06 15:10:52 +0800359 * Note:
360 * * If the return value is not PLDM_SUCCESS, it represents a
361 * transport layer error.
362 * * If the completion_code value is not PLDM_SUCCESS, it represents a
363 * protocol layer error and all the out-parameters are invalid.
364 *
Zahed Hossain223a73d2019-07-04 12:46:18 -0500365 * @param[in] msg - Response message
vkaverapa6575b82019-04-03 05:33:52 -0500366 * @param[in] payload_length - Length of reponse message payload
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600367 * @param[out] completion_code - Pointer to response msg's PLDM completion code
Sampa Misra432e1872019-02-13 03:49:43 -0600368 * @param[out] next_transfer_handle - the next handle for the next part of data
369 * @param[out] transfer_flag - flag to indicate the part of data
370 * @return pldm_completion_codes
371 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500372int decode_get_version_resp(const struct pldm_msg *msg, size_t payload_length,
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600373 uint8_t *completion_code,
Sampa Misra432e1872019-02-13 03:49:43 -0600374 uint32_t *next_transfer_handle,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600375 uint8_t *transfer_flag, ver32_t *version);
Sampa Misra432e1872019-02-13 03:49:43 -0600376
John Wang5c4f80d2019-07-29 11:12:18 +0800377/* GetTID */
378
379/** @brief Decode a GetTID response message
380 *
George Liu684a7162019-12-06 15:10:52 +0800381 * Note:
382 * * If the return value is not PLDM_SUCCESS, it represents a
383 * transport layer error.
384 * * If the completion_code value is not PLDM_SUCCESS, it represents a
385 * protocol layer error and all the out-parameters are invalid.
386 *
John Wang5c4f80d2019-07-29 11:12:18 +0800387 * @param[in] msg - Response message
388 * @param[in] payload_length - Length of response message payload
389 * @param[out] completion_code - Pointer to response msg's PLDM completion code
390 * @param[out] tid - Pointer to the terminus id
391 * @return pldm_completion_codes
392 */
393int decode_get_tid_resp(const struct pldm_msg *msg, size_t payload_length,
394 uint8_t *completion_code, uint8_t *tid);
395
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600396/* Responder */
397
398/* GetPLDMTypes */
399
400/** @brief Create a PLDM response message for GetPLDMTypes
401 *
402 * @param[in] instance_id - Message's instance id
403 * @param[in] completion_code - PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600404 * @param[in] types - pointer to array bitfield8_t[8] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600405 * types (MAX_TYPES/8) = 8), as per DSP0240
406 * @param[in,out] msg - Message will be written to this
407 * @return pldm_completion_codes
408 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500409 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600410 */
411int encode_get_types_resp(uint8_t instance_id, uint8_t completion_code,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600412 const bitfield8_t *types, struct pldm_msg *msg);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600413
414/* GetPLDMCommands */
415
416/** @brief Decode GetPLDMCommands' request data
417 *
vkaverapa6575b82019-04-03 05:33:52 -0500418 * @param[in] msg - Request message
419 * @param[in] payload_length - Length of request message payload
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600420 * @param[out] type - PLDM Type
421 * @param[out] version - Version for PLDM Type
422 * @return pldm_completion_codes
423 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500424int decode_get_commands_req(const struct pldm_msg *msg, size_t payload_length,
vkaverapa6575b82019-04-03 05:33:52 -0500425 uint8_t *type, ver32_t *version);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600426
427/** @brief Create a PLDM response message for GetPLDMCommands
428 *
429 * @param[in] instance_id - Message's instance id
430 * @param[in] completion_code - PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600431 * @param[in] commands - pointer to array bitfield8_t[32] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600432 * commands (PLDM_MAX_CMDS_PER_TYPE/8) = 32), as per DSP0240
433 * @param[in,out] msg - Message will be written to this
434 * @return pldm_completion_codes
435 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500436 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600437 */
438int encode_get_commands_resp(uint8_t instance_id, uint8_t completion_code,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600439 const bitfield8_t *commands, struct pldm_msg *msg);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600440
Sampa Misra432e1872019-02-13 03:49:43 -0600441/* GetPLDMVersion */
442
443/** @brief Create a PLDM response for GetPLDMVersion
444 *
445 * @param[in] instance_id - Message's instance id
446 * @param[in] completion_code - PLDM completion code
447 * @param[in] next_transfer_handle - Handle to identify next portion of
448 * data transfer
449 * @param[in] transfer_flag - Represents the part of transfer
450 * @param[in] version_data - the version data
451 * @param[in] version_size - size of version data
452 * @param[in,out] msg - Message will be written to this
453 * @return pldm_completion_codes
454 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500455 * 'msg.payload'
Sampa Misra432e1872019-02-13 03:49:43 -0600456 */
457int encode_get_version_resp(uint8_t instance_id, uint8_t completion_code,
458 uint32_t next_transfer_handle,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600459 uint8_t transfer_flag, const ver32_t *version_data,
Sampa Misra432e1872019-02-13 03:49:43 -0600460 size_t version_size, struct pldm_msg *msg);
461
462/** @brief Decode a GetPLDMVersion request message
463 *
vkaverapa6575b82019-04-03 05:33:52 -0500464 * @param[in] msg - Request message
465 * @param[in] payload_length - length of request message payload
Sampa Misra432e1872019-02-13 03:49:43 -0600466 * @param[out] transfer_handle - the handle of data
467 * @param[out] transfer_opflag - Transfer Flag
468 * @param[out] type - PLDM type for which version is requested
469 * @return pldm_completion_codes
470 */
Zahed Hossain223a73d2019-07-04 12:46:18 -0500471int decode_get_version_req(const struct pldm_msg *msg, size_t payload_length,
Sampa Misra432e1872019-02-13 03:49:43 -0600472 uint32_t *transfer_handle, uint8_t *transfer_opflag,
473 uint8_t *type);
474
Sridevi Rameshbc6ff262019-12-12 04:58:35 -0600475/* Requester */
476
John Wang5c4f80d2019-07-29 11:12:18 +0800477/* GetTID */
478
Sridevi Rameshbc6ff262019-12-12 04:58:35 -0600479/** @brief Create a PLDM request message for GetTID
480 *
481 * @param[in] instance_id - Message's instance id
482 * @param[in,out] msg - Message will be written to this
483 * @return pldm_completion_codes
484 * @note Caller is responsible for memory alloc and dealloc of param
485 * 'msg.payload'
486 */
487int encode_get_tid_req(uint8_t instance_id, struct pldm_msg *msg);
488
John Wang5c4f80d2019-07-29 11:12:18 +0800489/** @brief Create a PLDM response message for GetTID
490 *
491 * @param[in] instance_id - Message's instance id
492 * @param[in] completion_code - PLDM completion code
493 * @param[in] tid - Terminus ID
494 * @param[in,out] msg - Message will be written to this
495 * @return pldm_completion_codes
496 * @note Caller is responsible for memory alloc and dealloc of param
497 * 'msg.payload'
498 */
499int encode_get_tid_resp(uint8_t instance_id, uint8_t completion_code,
500 uint8_t tid, struct pldm_msg *msg);
501
Joe Komlodie0b3f3f2022-07-20 22:53:38 +0000502/* Responder */
503
504/* MultipartRecieve */
505
506/** @brief Decode a PLDM MultipartReceive request message
507 *
508 * @param[in] msg - Request message
509 * @param[in] payload_length - length of request message payload
510 * @param[out] pldm_type - PLDM type for which version is requested
511 * @param[out] transfer_opflag - Transfer Flag
512 * @param[out] transfer_ctx - The context of the packet
513 * @param[out] transfer_handle - The handle of data
514 * @param[out] section_offset - The start of the requested section
515 * @param[out] section_length - The length of the requested section
516 * @return pldm_completion_codes
517 */
518int decode_multipart_receive_req(
519 const struct pldm_msg *msg, size_t payload_length, uint8_t *pldm_type,
520 uint8_t *transfer_opflag, uint32_t *transfer_ctx, uint32_t *transfer_handle,
521 uint32_t *section_offset, uint32_t *section_length);
522
John Wang7f02d702019-12-03 13:38:14 +0800523/** @brief Create a PLDM response message containing only cc
524 *
525 * @param[in] instance_id - Message's instance id
526 * @param[in] type - PLDM Type
527 * @param[in] command - PLDM Command
528 * @param[in] cc - PLDM Completion Code
529 * @param[out] msg - Message will be written to this
530 * @return pldm_completion_codes
531 */
532int encode_cc_only_resp(uint8_t instance_id, uint8_t type, uint8_t command,
533 uint8_t cc, struct pldm_msg *msg);
534
gokulsanker138ceba2021-04-05 13:25:25 +0530535/** @brief Create a PLDM message only with the header
536 *
537 * @param[in] msg_type - PLDM message type
538 * @param[in] instance_id - Message's instance id
539 * @param[in] pldm_type - PLDM Type
540 * @param[in] command - PLDM Command
541 * @param[out] msg - Message will be written to this
542 *
543 * @return pldm_completion_codes
544 */
545int encode_pldm_header_only(uint8_t msg_type, uint8_t instance_id,
546 uint8_t pldm_type, uint8_t command,
547 struct pldm_msg *msg);
gokulsankerfc370e92021-04-27 12:57:47 +0530548
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600549#ifdef __cplusplus
550}
551#endif
552
553#endif /* BASE_H */