blob: 4fb94fb77b920c2e5f0b1b494019966581f3eeca [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,
18};
19
20/** @brief PLDM Commands
21 */
22enum pldm_supported_commands {
Sampa Misra432e1872019-02-13 03:49:43 -060023 PLDM_GET_PLDM_VERSION = 0x3,
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060024 PLDM_GET_PLDM_TYPES = 0x4,
25 PLDM_GET_PLDM_COMMANDS = 0x5
26};
27
28/** @brief PLDM base codes
29 */
30enum pldm_completion_codes {
31 PLDM_SUCCESS = 0x00,
32 PLDM_ERROR = 0x01,
33 PLDM_ERROR_INVALID_DATA = 0x02,
34 PLDM_ERROR_INVALID_LENGTH = 0x03,
35 PLDM_ERROR_NOT_READY = 0x04,
36 PLDM_ERROR_UNSUPPORTED_PLDM_CMD = 0x05,
37 PLDM_ERROR_INVALID_PLDM_TYPE = 0x20
38};
39
Sampa Misra432e1872019-02-13 03:49:43 -060040enum transfer_op_flag {
41 PLDM_GET_NEXTPART = 0,
42 PLDM_GET_FIRSTPART = 1,
43};
44
45enum transfer_resp_flag {
46 PLDM_START = 0x01,
47 PLDM_MIDDLE = 0x02,
48 PLDM_END = 0x04,
49 PLDM_START_AND_END = 0x05,
50};
51
Tom Joseph41251042019-02-07 16:17:07 +053052/** @enum MessageType
53 *
54 * The different message types supported by the PLDM specification.
55 */
56typedef enum {
57 PLDM_RESPONSE, //!< PLDM response
58 PLDM_REQUEST, //!< PLDM request
59 PLDM_RESERVED, //!< Reserved
60 PLDM_ASYNC_REQUEST_NOTIFY, //!< Unacknowledged PLDM request messages
61} MessageType;
62
63#define PLDM_INSTANCE_MAX 31
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060064#define PLDM_MAX_TYPES 64
65#define PLDM_MAX_CMDS_PER_TYPE 256
66
67/* Message payload lengths */
68#define PLDM_GET_COMMANDS_REQ_BYTES 5
Sampa Misra432e1872019-02-13 03:49:43 -060069#define PLDM_GET_VERSION_REQ_BYTES 6
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060070
71/* Response lengths are inclusive of completion code */
72#define PLDM_GET_TYPES_RESP_BYTES 9
73#define PLDM_GET_COMMANDS_RESP_BYTES 33
Sampa Misra432e1872019-02-13 03:49:43 -060074/* Response data has only one version and does not contain the checksum */
75#define PLDM_GET_VERSION_RESP_BYTES 10
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060076
77/** @struct pldm_msg_hdr
78 *
79 * Structure representing PLDM message header fields
80 */
81struct pldm_msg_hdr {
82#if defined(__LITTLE_ENDIAN_BITFIELD)
83 uint8_t instance_id : 5; //!< Instance ID
84 uint8_t reserved : 1; //!< Reserved
85 uint8_t datagram : 1; //!< Datagram bit
86 uint8_t request : 1; //!< Request bit
87#elif defined(__BIG_ENDIAN_BITFIELD)
88 uint8_t request : 1; //!< Request bit
89 uint8_t datagram : 1; //!< Datagram bit
90 uint8_t reserved : 1; //!< Reserved
91 uint8_t instance_id : 5; //!< Instance ID
92#endif
93
94#if defined(__LITTLE_ENDIAN_BITFIELD)
95 uint8_t type : 6; //!< PLDM type
96 uint8_t header_ver : 2; //!< Header version
97#elif defined(__BIG_ENDIAN_BITFIELD)
98 uint8_t header_ver : 2; //!< Header version
99 uint8_t type : 6; //!< PLDM type
100#endif
101 uint8_t command; //!< PLDM command code
102} __attribute__((packed));
103
104/** @struct pldm_msg_payload
105 *
106 * Structure representing PLDM message payload
107 */
108struct pldm_msg_payload {
109 uint8_t *payload; //!< Pointer to PLDM message payload
110 size_t payload_length; //!< PLDM message payload's length in bytes
111} __attribute__((packed));
112
113/** @struct pldm_msg
114 *
115 * Structure representing PLDM message
116 */
117struct pldm_msg {
118 struct pldm_msg_hdr hdr; //!< PLDM message header
119 struct pldm_msg_payload body; //!< PLDM message payload
120} __attribute__((packed));
121
Tom Joseph41251042019-02-07 16:17:07 +0530122/** @struct pldm_header_info
123 *
124 * The information needed to prepare PLDM header and this is passed to the
125 * pack_pldm_header and unpack_pldm_header API.
126 */
127struct pldm_header_info {
128 MessageType msg_type; //!< PLDM message type
129 uint8_t instance; //!< PLDM instance id
130 uint8_t pldm_type; //!< PLDM type
131 uint8_t command; //!< PLDM command code
132 uint8_t completion_code; //!< PLDM completion code, applies for response
133};
134
135/**
136 * @brief Populate the PLDM message with the PLDM header.The caller of this API
137 * allocates buffer for the PLDM header when forming the PLDM message.
138 * The buffer is passed to this API to pack the PLDM header.
139 *
140 * @param[in] hdr - Pointer to the PLDM header information
141 * @param[out] msg - Pointer to PLDM message header
142 *
143 * @return 0 on success, otherwise PLDM error codes.
144 */
145int pack_pldm_header(const struct pldm_header_info *hdr,
146 struct pldm_msg_hdr *msg);
147
148/**
149 * @brief Unpack the PLDM header from the PLDM message.
150 *
151 * @param[in] msg - Pointer to the PLDM message header
152 * @param[out] hdr - Pointer to the PLDM header information
153 *
154 * @return 0 on success, otherwise PLDM error codes.
155 */
156int unpack_pldm_header(const struct pldm_msg_hdr *msg,
157 struct pldm_header_info *hdr);
158
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600159/* Requester */
160
161/* GetPLDMTypes */
162
163/** @brief Create a PLDM request message for GetPLDMTypes
164 *
165 * @param[in] instance_id - Message's instance id
166 * @param[in,out] msg - Message will be written to this
167 * @return pldm_completion_codes
168 * @note Caller is responsible for memory alloc and dealloc of param
169 * 'msg.body.payload'
170 */
171int encode_get_types_req(uint8_t instance_id, struct pldm_msg *msg);
172
173/** @brief Decode a GetPLDMTypes response message
174 *
175 * @param[in] msg - Response message payload
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600176 * @param[out] completion_code - Pointer to response msg's PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600177 * @param[out] types - pointer to array bitfield8_t[8] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600178 * types (MAX_TYPES/8) = 8), as per DSP0240
179 * @return pldm_completion_codes
180 */
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600181int decode_get_types_resp(const struct pldm_msg_payload *msg,
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600182 uint8_t *completion_code, bitfield8_t *types);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600183
184/* GetPLDMCommands */
185
186/** @brief Create a PLDM request message for GetPLDMCommands
187 *
188 * @param[in] instance_id - Message's instance id
189 * @param[in] type - PLDM Type
190 * @param[in] version - Version for PLDM Type
191 * @param[in,out] msg - Message will be written to this
192 * @return pldm_completion_codes
193 * @note Caller is responsible for memory alloc and dealloc of param
194 * 'msg.body.payload'
195 */
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600196int encode_get_commands_req(uint8_t instance_id, uint8_t type, ver32_t version,
197 struct pldm_msg *msg);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600198
199/** @brief Decode a GetPLDMCommands response message
200 *
201 * @param[in] msg - Response message payload
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600202 * @param[out] completion_code - Pointer to response msg's PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600203 * @param[in] commands - pointer to array bitfield8_t[32] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600204 * commands (PLDM_MAX_CMDS_PER_TYPE/8) = 32), as per DSP0240
205 * @return pldm_completion_codes
206 */
207int decode_get_commands_resp(const struct pldm_msg_payload *msg,
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600208 uint8_t *completion_code, bitfield8_t *commands);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600209
Sampa Misra432e1872019-02-13 03:49:43 -0600210/* GetPLDMVersion */
211
212/** @brief Create a PLDM request for GetPLDMVersion
213 *
214 * @param[in] instance_id - Message's instance id
215 * @param[in] transfer_handle - Handle to identify PLDM version data transfer.
216 * This handle is ignored by the responder when the
217 * transferop_flag is set to getFirstPart.
218 * @param[in] transfer_opflag - flag to indicate whether it is start of
219 * transfer
220 * @param[in] type - PLDM Type for which version is requested
221 * @param[in,out] msg - Message will be written to this
222 * @return pldm_completion_codes
223 * @note Caller is responsible for memory alloc and dealloc of param
224 * 'msg.body.payload'
225 */
226int encode_get_version_req(uint8_t instance_id, uint32_t transfer_handle,
227 uint8_t transfer_opflag, uint8_t type,
228 struct pldm_msg *msg);
229
230/** @brief Decode a GetPLDMVersion response message
231 *
232 * @param[in] msg - Response message payload
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600233 * @param[out] completion_code - Pointer to response msg's PLDM completion code
Sampa Misra432e1872019-02-13 03:49:43 -0600234 * @param[out] next_transfer_handle - the next handle for the next part of data
235 * @param[out] transfer_flag - flag to indicate the part of data
236 * @return pldm_completion_codes
237 */
238int decode_get_version_resp(const struct pldm_msg_payload *msg,
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600239 uint8_t *completion_code,
Sampa Misra432e1872019-02-13 03:49:43 -0600240 uint32_t *next_transfer_handle,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600241 uint8_t *transfer_flag, ver32_t *version);
Sampa Misra432e1872019-02-13 03:49:43 -0600242
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600243/* Responder */
244
245/* GetPLDMTypes */
246
247/** @brief Create a PLDM response message for GetPLDMTypes
248 *
249 * @param[in] instance_id - Message's instance id
250 * @param[in] completion_code - PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600251 * @param[in] types - pointer to array bitfield8_t[8] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600252 * types (MAX_TYPES/8) = 8), as per DSP0240
253 * @param[in,out] msg - Message will be written to this
254 * @return pldm_completion_codes
255 * @note Caller is responsible for memory alloc and dealloc of param
256 * 'msg.body.payload'
257 */
258int encode_get_types_resp(uint8_t instance_id, uint8_t completion_code,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600259 const bitfield8_t *types, struct pldm_msg *msg);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600260
261/* GetPLDMCommands */
262
263/** @brief Decode GetPLDMCommands' request data
264 *
265 * @param[in] msg - Request message payload
266 * @param[out] type - PLDM Type
267 * @param[out] version - Version for PLDM Type
268 * @return pldm_completion_codes
269 */
270int decode_get_commands_req(const struct pldm_msg_payload *msg, uint8_t *type,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600271 ver32_t *version);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600272
273/** @brief Create a PLDM response message for GetPLDMCommands
274 *
275 * @param[in] instance_id - Message's instance id
276 * @param[in] completion_code - PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600277 * @param[in] commands - pointer to array bitfield8_t[32] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600278 * commands (PLDM_MAX_CMDS_PER_TYPE/8) = 32), as per DSP0240
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
282 * 'msg.body.payload'
283 */
284int encode_get_commands_resp(uint8_t instance_id, uint8_t completion_code,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600285 const bitfield8_t *commands, struct pldm_msg *msg);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600286
Sampa Misra432e1872019-02-13 03:49:43 -0600287/* GetPLDMVersion */
288
289/** @brief Create a PLDM response for GetPLDMVersion
290 *
291 * @param[in] instance_id - Message's instance id
292 * @param[in] completion_code - PLDM completion code
293 * @param[in] next_transfer_handle - Handle to identify next portion of
294 * data transfer
295 * @param[in] transfer_flag - Represents the part of transfer
296 * @param[in] version_data - the version data
297 * @param[in] version_size - size of version data
298 * @param[in,out] msg - Message will be written to this
299 * @return pldm_completion_codes
300 * @note Caller is responsible for memory alloc and dealloc of param
301 * 'msg.body.payload'
302 */
303int encode_get_version_resp(uint8_t instance_id, uint8_t completion_code,
304 uint32_t next_transfer_handle,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600305 uint8_t transfer_flag, const ver32_t *version_data,
Sampa Misra432e1872019-02-13 03:49:43 -0600306 size_t version_size, struct pldm_msg *msg);
307
308/** @brief Decode a GetPLDMVersion request message
309 *
310 * @param[in] msg - Request message payload
311 * @param[out] transfer_handle - the handle of data
312 * @param[out] transfer_opflag - Transfer Flag
313 * @param[out] type - PLDM type for which version is requested
314 * @return pldm_completion_codes
315 */
316int decode_get_version_req(const struct pldm_msg_payload *msg,
317 uint32_t *transfer_handle, uint8_t *transfer_opflag,
318 uint8_t *type);
319
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600320#ifdef __cplusplus
321}
322#endif
323
324#endif /* BASE_H */