blob: ca367efa8c3e8938ad142eb766ac810945484ba9 [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,
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060020};
21
22/** @brief PLDM Commands
23 */
24enum pldm_supported_commands {
Sampa Misra432e1872019-02-13 03:49:43 -060025 PLDM_GET_PLDM_VERSION = 0x3,
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060026 PLDM_GET_PLDM_TYPES = 0x4,
27 PLDM_GET_PLDM_COMMANDS = 0x5
28};
29
30/** @brief PLDM base codes
31 */
32enum pldm_completion_codes {
33 PLDM_SUCCESS = 0x00,
34 PLDM_ERROR = 0x01,
35 PLDM_ERROR_INVALID_DATA = 0x02,
36 PLDM_ERROR_INVALID_LENGTH = 0x03,
37 PLDM_ERROR_NOT_READY = 0x04,
38 PLDM_ERROR_UNSUPPORTED_PLDM_CMD = 0x05,
39 PLDM_ERROR_INVALID_PLDM_TYPE = 0x20
40};
41
Sampa Misra432e1872019-02-13 03:49:43 -060042enum transfer_op_flag {
43 PLDM_GET_NEXTPART = 0,
44 PLDM_GET_FIRSTPART = 1,
45};
46
47enum transfer_resp_flag {
48 PLDM_START = 0x01,
49 PLDM_MIDDLE = 0x02,
50 PLDM_END = 0x04,
51 PLDM_START_AND_END = 0x05,
52};
53
Tom Joseph41251042019-02-07 16:17:07 +053054/** @enum MessageType
55 *
56 * The different message types supported by the PLDM specification.
57 */
58typedef enum {
59 PLDM_RESPONSE, //!< PLDM response
60 PLDM_REQUEST, //!< PLDM request
61 PLDM_RESERVED, //!< Reserved
62 PLDM_ASYNC_REQUEST_NOTIFY, //!< Unacknowledged PLDM request messages
63} MessageType;
64
65#define PLDM_INSTANCE_MAX 31
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060066#define PLDM_MAX_TYPES 64
67#define PLDM_MAX_CMDS_PER_TYPE 256
68
69/* Message payload lengths */
70#define PLDM_GET_COMMANDS_REQ_BYTES 5
Sampa Misra432e1872019-02-13 03:49:43 -060071#define PLDM_GET_VERSION_REQ_BYTES 6
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060072
73/* Response lengths are inclusive of completion code */
74#define PLDM_GET_TYPES_RESP_BYTES 9
75#define PLDM_GET_COMMANDS_RESP_BYTES 33
Sampa Misra432e1872019-02-13 03:49:43 -060076/* Response data has only one version and does not contain the checksum */
77#define PLDM_GET_VERSION_RESP_BYTES 10
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060078
79/** @struct pldm_msg_hdr
80 *
81 * Structure representing PLDM message header fields
82 */
83struct pldm_msg_hdr {
84#if defined(__LITTLE_ENDIAN_BITFIELD)
85 uint8_t instance_id : 5; //!< Instance ID
86 uint8_t reserved : 1; //!< Reserved
87 uint8_t datagram : 1; //!< Datagram bit
88 uint8_t request : 1; //!< Request bit
89#elif defined(__BIG_ENDIAN_BITFIELD)
90 uint8_t request : 1; //!< Request bit
91 uint8_t datagram : 1; //!< Datagram bit
92 uint8_t reserved : 1; //!< Reserved
93 uint8_t instance_id : 5; //!< Instance ID
94#endif
95
96#if defined(__LITTLE_ENDIAN_BITFIELD)
97 uint8_t type : 6; //!< PLDM type
98 uint8_t header_ver : 2; //!< Header version
99#elif defined(__BIG_ENDIAN_BITFIELD)
100 uint8_t header_ver : 2; //!< Header version
101 uint8_t type : 6; //!< PLDM type
102#endif
103 uint8_t command; //!< PLDM command code
104} __attribute__((packed));
105
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600106/** @struct pldm_msg
107 *
108 * Structure representing PLDM message
109 */
110struct pldm_msg {
vkaverapa6575b82019-04-03 05:33:52 -0500111 struct pldm_msg_hdr hdr; //!< PLDM message header
112 uint8_t payload[1]; //!< &payload[0] is the beginning of the payload
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600113} __attribute__((packed));
114
Tom Joseph41251042019-02-07 16:17:07 +0530115/** @struct pldm_header_info
116 *
117 * The information needed to prepare PLDM header and this is passed to the
118 * pack_pldm_header and unpack_pldm_header API.
119 */
120struct pldm_header_info {
121 MessageType msg_type; //!< PLDM message type
122 uint8_t instance; //!< PLDM instance id
123 uint8_t pldm_type; //!< PLDM type
124 uint8_t command; //!< PLDM command code
125 uint8_t completion_code; //!< PLDM completion code, applies for response
126};
127
Priyanga4b790ce2019-06-10 01:30:09 -0500128/** @struct pldm_get_types_resp
129 *
130 * Structure representing PLDM get types response.
131 */
132struct pldm_get_types_resp {
133 uint8_t completion_code; //!< completion code
134 bitfield8_t types[8]; //!< each bit represents whether a given PLDM Type
135 //!< is supported
136} __attribute__((packed));
137
138/** @struct pldm_get_commands_req
139 *
140 * Structure representing PLDM get commands request.
141 */
142struct pldm_get_commands_req {
143 uint8_t type; //!< PLDM Type for which command support information is
144 //!< being requested
145 ver32_t version; //!< version for the specified PLDM Type
146} __attribute__((packed));
147
148/** @struct pldm_get_commands_resp
149 *
150 * Structure representing PLDM get commands response.
151 */
152struct pldm_get_commands_resp {
153 uint8_t completion_code; //!< completion code
154 bitfield8_t commands[32]; //!< each bit represents whether a given PLDM
155 //!< command is supported
156} __attribute__((packed));
157
158/** @struct pldm_get_version_req
159 *
160 * Structure representing PLDM get version request.
161 */
162struct pldm_get_version_req {
163 uint32_t
164 transfer_handle; //!< handle to identify PLDM version data transfer
165 uint8_t transfer_opflag; //!< PLDM GetVersion operation flag
166 uint8_t type; //!< PLDM Type for which version information is being
167 //!< requested
168} __attribute__((packed));
169
170/** @struct pldm_get_version_resp
171 *
172 * Structure representing PLDM get version response.
173 */
174
175struct pldm_get_version_resp {
176 uint8_t completion_code; //!< completion code
177 uint32_t next_transfer_handle; //!< next portion of PLDM version data
178 //!< transfer
179 uint8_t transfer_flag; //!< PLDM GetVersion transfer flag
180 uint8_t version_data[1]; //!< PLDM GetVersion version field
181} __attribute__((packed));
182
Tom Joseph41251042019-02-07 16:17:07 +0530183/**
184 * @brief Populate the PLDM message with the PLDM header.The caller of this API
185 * allocates buffer for the PLDM header when forming the PLDM message.
186 * The buffer is passed to this API to pack the PLDM header.
187 *
188 * @param[in] hdr - Pointer to the PLDM header information
189 * @param[out] msg - Pointer to PLDM message header
190 *
191 * @return 0 on success, otherwise PLDM error codes.
192 */
193int pack_pldm_header(const struct pldm_header_info *hdr,
194 struct pldm_msg_hdr *msg);
195
196/**
197 * @brief Unpack the PLDM header from the PLDM message.
198 *
199 * @param[in] msg - Pointer to the PLDM message header
200 * @param[out] hdr - Pointer to the PLDM header information
201 *
202 * @return 0 on success, otherwise PLDM error codes.
203 */
204int unpack_pldm_header(const struct pldm_msg_hdr *msg,
205 struct pldm_header_info *hdr);
206
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600207/* Requester */
208
209/* GetPLDMTypes */
210
211/** @brief Create a PLDM request message for GetPLDMTypes
212 *
213 * @param[in] instance_id - Message's instance id
214 * @param[in,out] msg - Message will be written to this
215 * @return pldm_completion_codes
216 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500217 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600218 */
219int encode_get_types_req(uint8_t instance_id, struct pldm_msg *msg);
220
221/** @brief Decode a GetPLDMTypes response message
222 *
223 * @param[in] msg - Response message payload
vkaverapa6575b82019-04-03 05:33:52 -0500224 * @param[in] payload_length - Length of response message payload
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600225 * @param[out] completion_code - Pointer to response msg's PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600226 * @param[out] types - pointer to array bitfield8_t[8] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600227 * types (MAX_TYPES/8) = 8), as per DSP0240
228 * @return pldm_completion_codes
229 */
vkaverapa6575b82019-04-03 05:33:52 -0500230int decode_get_types_resp(const uint8_t *msg, size_t payload_length,
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600231 uint8_t *completion_code, bitfield8_t *types);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600232
233/* GetPLDMCommands */
234
235/** @brief Create a PLDM request message for GetPLDMCommands
236 *
237 * @param[in] instance_id - Message's instance id
238 * @param[in] type - PLDM Type
239 * @param[in] version - Version for PLDM Type
240 * @param[in,out] msg - Message will be written to this
241 * @return pldm_completion_codes
242 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500243 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600244 */
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600245int encode_get_commands_req(uint8_t instance_id, uint8_t type, ver32_t version,
246 struct pldm_msg *msg);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600247
248/** @brief Decode a GetPLDMCommands response message
249 *
250 * @param[in] msg - Response message payload
vkaverapa6575b82019-04-03 05:33:52 -0500251 * @param[in] payload_length - Length of reponse message payload
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600252 * @param[out] completion_code - Pointer to response msg's PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600253 * @param[in] commands - pointer to array bitfield8_t[32] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600254 * commands (PLDM_MAX_CMDS_PER_TYPE/8) = 32), as per DSP0240
255 * @return pldm_completion_codes
256 */
vkaverapa6575b82019-04-03 05:33:52 -0500257int decode_get_commands_resp(const uint8_t *msg, size_t payload_length,
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600258 uint8_t *completion_code, bitfield8_t *commands);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600259
Sampa Misra432e1872019-02-13 03:49:43 -0600260/* GetPLDMVersion */
261
262/** @brief Create a PLDM request for GetPLDMVersion
263 *
264 * @param[in] instance_id - Message's instance id
265 * @param[in] transfer_handle - Handle to identify PLDM version data transfer.
266 * This handle is ignored by the responder when the
267 * transferop_flag is set to getFirstPart.
268 * @param[in] transfer_opflag - flag to indicate whether it is start of
269 * transfer
270 * @param[in] type - PLDM Type for which version is requested
271 * @param[in,out] msg - Message will be written to this
272 * @return pldm_completion_codes
273 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500274 * 'msg.payload'
Sampa Misra432e1872019-02-13 03:49:43 -0600275 */
276int encode_get_version_req(uint8_t instance_id, uint32_t transfer_handle,
277 uint8_t transfer_opflag, uint8_t type,
278 struct pldm_msg *msg);
279
280/** @brief Decode a GetPLDMVersion response message
281 *
282 * @param[in] msg - Response message payload
vkaverapa6575b82019-04-03 05:33:52 -0500283 * @param[in] payload_length - Length of reponse message payload
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600284 * @param[out] completion_code - Pointer to response msg's PLDM completion code
Sampa Misra432e1872019-02-13 03:49:43 -0600285 * @param[out] next_transfer_handle - the next handle for the next part of data
286 * @param[out] transfer_flag - flag to indicate the part of data
287 * @return pldm_completion_codes
288 */
vkaverapa6575b82019-04-03 05:33:52 -0500289int decode_get_version_resp(const uint8_t *msg, size_t payload_length,
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600290 uint8_t *completion_code,
Sampa Misra432e1872019-02-13 03:49:43 -0600291 uint32_t *next_transfer_handle,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600292 uint8_t *transfer_flag, ver32_t *version);
Sampa Misra432e1872019-02-13 03:49:43 -0600293
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600294/* Responder */
295
296/* GetPLDMTypes */
297
298/** @brief Create a PLDM response message for GetPLDMTypes
299 *
300 * @param[in] instance_id - Message's instance id
301 * @param[in] completion_code - PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600302 * @param[in] types - pointer to array bitfield8_t[8] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600303 * types (MAX_TYPES/8) = 8), as per DSP0240
304 * @param[in,out] msg - Message will be written to this
305 * @return pldm_completion_codes
306 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500307 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600308 */
309int encode_get_types_resp(uint8_t instance_id, uint8_t completion_code,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600310 const bitfield8_t *types, struct pldm_msg *msg);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600311
312/* GetPLDMCommands */
313
314/** @brief Decode GetPLDMCommands' request data
315 *
vkaverapa6575b82019-04-03 05:33:52 -0500316 * @param[in] msg - Request message
317 * @param[in] payload_length - Length of request message payload
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600318 * @param[out] type - PLDM Type
319 * @param[out] version - Version for PLDM Type
320 * @return pldm_completion_codes
321 */
vkaverapa6575b82019-04-03 05:33:52 -0500322int decode_get_commands_req(const uint8_t *msg, size_t payload_length,
323 uint8_t *type, ver32_t *version);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600324
325/** @brief Create a PLDM response message for GetPLDMCommands
326 *
327 * @param[in] instance_id - Message's instance id
328 * @param[in] completion_code - PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600329 * @param[in] commands - pointer to array bitfield8_t[32] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600330 * commands (PLDM_MAX_CMDS_PER_TYPE/8) = 32), as per DSP0240
331 * @param[in,out] msg - Message will be written to this
332 * @return pldm_completion_codes
333 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500334 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600335 */
336int encode_get_commands_resp(uint8_t instance_id, uint8_t completion_code,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600337 const bitfield8_t *commands, struct pldm_msg *msg);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600338
Sampa Misra432e1872019-02-13 03:49:43 -0600339/* GetPLDMVersion */
340
341/** @brief Create a PLDM response for GetPLDMVersion
342 *
343 * @param[in] instance_id - Message's instance id
344 * @param[in] completion_code - PLDM completion code
345 * @param[in] next_transfer_handle - Handle to identify next portion of
346 * data transfer
347 * @param[in] transfer_flag - Represents the part of transfer
348 * @param[in] version_data - the version data
349 * @param[in] version_size - size of version data
350 * @param[in,out] msg - Message will be written to this
351 * @return pldm_completion_codes
352 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500353 * 'msg.payload'
Sampa Misra432e1872019-02-13 03:49:43 -0600354 */
355int encode_get_version_resp(uint8_t instance_id, uint8_t completion_code,
356 uint32_t next_transfer_handle,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600357 uint8_t transfer_flag, const ver32_t *version_data,
Sampa Misra432e1872019-02-13 03:49:43 -0600358 size_t version_size, struct pldm_msg *msg);
359
360/** @brief Decode a GetPLDMVersion request message
361 *
vkaverapa6575b82019-04-03 05:33:52 -0500362 * @param[in] msg - Request message
363 * @param[in] payload_length - length of request message payload
Sampa Misra432e1872019-02-13 03:49:43 -0600364 * @param[out] transfer_handle - the handle of data
365 * @param[out] transfer_opflag - Transfer Flag
366 * @param[out] type - PLDM type for which version is requested
367 * @return pldm_completion_codes
368 */
vkaverapa6575b82019-04-03 05:33:52 -0500369int decode_get_version_req(const uint8_t *msg, size_t payload_length,
Sampa Misra432e1872019-02-13 03:49:43 -0600370 uint32_t *transfer_handle, uint8_t *transfer_opflag,
371 uint8_t *type);
372
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600373#ifdef __cplusplus
374}
375#endif
376
377#endif /* BASE_H */