blob: 6a044ad841c7ddb3b39bb2df6913d6817eaac2cc [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 Thomasf666db12019-05-29 05:22:31 -050020 PLDM_OEM = 0x3F,
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060021};
22
23/** @brief PLDM Commands
24 */
25enum pldm_supported_commands {
Sampa Misra432e1872019-02-13 03:49:43 -060026 PLDM_GET_PLDM_VERSION = 0x3,
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060027 PLDM_GET_PLDM_TYPES = 0x4,
28 PLDM_GET_PLDM_COMMANDS = 0x5
29};
30
31/** @brief PLDM base codes
32 */
33enum pldm_completion_codes {
34 PLDM_SUCCESS = 0x00,
35 PLDM_ERROR = 0x01,
36 PLDM_ERROR_INVALID_DATA = 0x02,
37 PLDM_ERROR_INVALID_LENGTH = 0x03,
38 PLDM_ERROR_NOT_READY = 0x04,
39 PLDM_ERROR_UNSUPPORTED_PLDM_CMD = 0x05,
40 PLDM_ERROR_INVALID_PLDM_TYPE = 0x20
41};
42
Sampa Misra432e1872019-02-13 03:49:43 -060043enum transfer_op_flag {
44 PLDM_GET_NEXTPART = 0,
45 PLDM_GET_FIRSTPART = 1,
46};
47
48enum transfer_resp_flag {
49 PLDM_START = 0x01,
50 PLDM_MIDDLE = 0x02,
51 PLDM_END = 0x04,
52 PLDM_START_AND_END = 0x05,
53};
54
Tom Joseph41251042019-02-07 16:17:07 +053055/** @enum MessageType
56 *
57 * The different message types supported by the PLDM specification.
58 */
59typedef enum {
60 PLDM_RESPONSE, //!< PLDM response
61 PLDM_REQUEST, //!< PLDM request
62 PLDM_RESERVED, //!< Reserved
63 PLDM_ASYNC_REQUEST_NOTIFY, //!< Unacknowledged PLDM request messages
64} MessageType;
65
66#define PLDM_INSTANCE_MAX 31
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060067#define PLDM_MAX_TYPES 64
68#define PLDM_MAX_CMDS_PER_TYPE 256
69
70/* Message payload lengths */
71#define PLDM_GET_COMMANDS_REQ_BYTES 5
Sampa Misra432e1872019-02-13 03:49:43 -060072#define PLDM_GET_VERSION_REQ_BYTES 6
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060073
74/* Response lengths are inclusive of completion code */
75#define PLDM_GET_TYPES_RESP_BYTES 9
76#define PLDM_GET_COMMANDS_RESP_BYTES 33
Sampa Misra432e1872019-02-13 03:49:43 -060077/* Response data has only one version and does not contain the checksum */
78#define PLDM_GET_VERSION_RESP_BYTES 10
Deepak Kodihalli1b24f972019-02-01 04:09:13 -060079
80/** @struct pldm_msg_hdr
81 *
82 * Structure representing PLDM message header fields
83 */
84struct pldm_msg_hdr {
85#if defined(__LITTLE_ENDIAN_BITFIELD)
86 uint8_t instance_id : 5; //!< Instance ID
87 uint8_t reserved : 1; //!< Reserved
88 uint8_t datagram : 1; //!< Datagram bit
89 uint8_t request : 1; //!< Request bit
90#elif defined(__BIG_ENDIAN_BITFIELD)
91 uint8_t request : 1; //!< Request bit
92 uint8_t datagram : 1; //!< Datagram bit
93 uint8_t reserved : 1; //!< Reserved
94 uint8_t instance_id : 5; //!< Instance ID
95#endif
96
97#if defined(__LITTLE_ENDIAN_BITFIELD)
98 uint8_t type : 6; //!< PLDM type
99 uint8_t header_ver : 2; //!< Header version
100#elif defined(__BIG_ENDIAN_BITFIELD)
101 uint8_t header_ver : 2; //!< Header version
102 uint8_t type : 6; //!< PLDM type
103#endif
104 uint8_t command; //!< PLDM command code
105} __attribute__((packed));
106
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600107/** @struct pldm_msg
108 *
109 * Structure representing PLDM message
110 */
111struct pldm_msg {
vkaverapa6575b82019-04-03 05:33:52 -0500112 struct pldm_msg_hdr hdr; //!< PLDM message header
113 uint8_t payload[1]; //!< &payload[0] is the beginning of the payload
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600114} __attribute__((packed));
115
Tom Joseph41251042019-02-07 16:17:07 +0530116/** @struct pldm_header_info
117 *
118 * The information needed to prepare PLDM header and this is passed to the
119 * pack_pldm_header and unpack_pldm_header API.
120 */
121struct pldm_header_info {
122 MessageType msg_type; //!< PLDM message type
123 uint8_t instance; //!< PLDM instance id
124 uint8_t pldm_type; //!< PLDM type
125 uint8_t command; //!< PLDM command code
126 uint8_t completion_code; //!< PLDM completion code, applies for response
127};
128
Priyanga4b790ce2019-06-10 01:30:09 -0500129/** @struct pldm_get_types_resp
130 *
131 * Structure representing PLDM get types response.
132 */
133struct pldm_get_types_resp {
134 uint8_t completion_code; //!< completion code
135 bitfield8_t types[8]; //!< each bit represents whether a given PLDM Type
136 //!< is supported
137} __attribute__((packed));
138
139/** @struct pldm_get_commands_req
140 *
141 * Structure representing PLDM get commands request.
142 */
143struct pldm_get_commands_req {
144 uint8_t type; //!< PLDM Type for which command support information is
145 //!< being requested
146 ver32_t version; //!< version for the specified PLDM Type
147} __attribute__((packed));
148
149/** @struct pldm_get_commands_resp
150 *
151 * Structure representing PLDM get commands response.
152 */
153struct pldm_get_commands_resp {
154 uint8_t completion_code; //!< completion code
155 bitfield8_t commands[32]; //!< each bit represents whether a given PLDM
156 //!< command is supported
157} __attribute__((packed));
158
159/** @struct pldm_get_version_req
160 *
161 * Structure representing PLDM get version request.
162 */
163struct pldm_get_version_req {
164 uint32_t
165 transfer_handle; //!< handle to identify PLDM version data transfer
166 uint8_t transfer_opflag; //!< PLDM GetVersion operation flag
167 uint8_t type; //!< PLDM Type for which version information is being
168 //!< requested
169} __attribute__((packed));
170
171/** @struct pldm_get_version_resp
172 *
173 * Structure representing PLDM get version response.
174 */
175
176struct pldm_get_version_resp {
177 uint8_t completion_code; //!< completion code
178 uint32_t next_transfer_handle; //!< next portion of PLDM version data
179 //!< transfer
180 uint8_t transfer_flag; //!< PLDM GetVersion transfer flag
181 uint8_t version_data[1]; //!< PLDM GetVersion version field
182} __attribute__((packed));
183
Tom Joseph41251042019-02-07 16:17:07 +0530184/**
185 * @brief Populate the PLDM message with the PLDM header.The caller of this API
186 * allocates buffer for the PLDM header when forming the PLDM message.
187 * The buffer is passed to this API to pack the PLDM header.
188 *
189 * @param[in] hdr - Pointer to the PLDM header information
190 * @param[out] msg - Pointer to PLDM message header
191 *
192 * @return 0 on success, otherwise PLDM error codes.
193 */
194int pack_pldm_header(const struct pldm_header_info *hdr,
195 struct pldm_msg_hdr *msg);
196
197/**
198 * @brief Unpack the PLDM header from the PLDM message.
199 *
200 * @param[in] msg - Pointer to the PLDM message header
201 * @param[out] hdr - Pointer to the PLDM header information
202 *
203 * @return 0 on success, otherwise PLDM error codes.
204 */
205int unpack_pldm_header(const struct pldm_msg_hdr *msg,
206 struct pldm_header_info *hdr);
207
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600208/* Requester */
209
210/* GetPLDMTypes */
211
212/** @brief Create a PLDM request message for GetPLDMTypes
213 *
214 * @param[in] instance_id - Message's instance id
215 * @param[in,out] msg - Message will be written to this
216 * @return pldm_completion_codes
217 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500218 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600219 */
220int encode_get_types_req(uint8_t instance_id, struct pldm_msg *msg);
221
222/** @brief Decode a GetPLDMTypes response message
223 *
224 * @param[in] msg - Response message payload
vkaverapa6575b82019-04-03 05:33:52 -0500225 * @param[in] payload_length - Length of response message payload
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600226 * @param[out] completion_code - Pointer to response msg's PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600227 * @param[out] types - pointer to array bitfield8_t[8] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600228 * types (MAX_TYPES/8) = 8), as per DSP0240
229 * @return pldm_completion_codes
230 */
vkaverapa6575b82019-04-03 05:33:52 -0500231int decode_get_types_resp(const uint8_t *msg, size_t payload_length,
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600232 uint8_t *completion_code, bitfield8_t *types);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600233
234/* GetPLDMCommands */
235
236/** @brief Create a PLDM request message for GetPLDMCommands
237 *
238 * @param[in] instance_id - Message's instance id
239 * @param[in] type - PLDM Type
240 * @param[in] version - Version for PLDM Type
241 * @param[in,out] msg - Message will be written to this
242 * @return pldm_completion_codes
243 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500244 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600245 */
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600246int encode_get_commands_req(uint8_t instance_id, uint8_t type, ver32_t version,
247 struct pldm_msg *msg);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600248
249/** @brief Decode a GetPLDMCommands response message
250 *
251 * @param[in] msg - Response message payload
vkaverapa6575b82019-04-03 05:33:52 -0500252 * @param[in] payload_length - Length of reponse message payload
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600253 * @param[out] completion_code - Pointer to response msg's PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600254 * @param[in] commands - pointer to array bitfield8_t[32] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600255 * commands (PLDM_MAX_CMDS_PER_TYPE/8) = 32), as per DSP0240
256 * @return pldm_completion_codes
257 */
vkaverapa6575b82019-04-03 05:33:52 -0500258int decode_get_commands_resp(const uint8_t *msg, size_t payload_length,
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600259 uint8_t *completion_code, bitfield8_t *commands);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600260
Sampa Misra432e1872019-02-13 03:49:43 -0600261/* GetPLDMVersion */
262
263/** @brief Create a PLDM request for GetPLDMVersion
264 *
265 * @param[in] instance_id - Message's instance id
266 * @param[in] transfer_handle - Handle to identify PLDM version data transfer.
267 * This handle is ignored by the responder when the
268 * transferop_flag is set to getFirstPart.
269 * @param[in] transfer_opflag - flag to indicate whether it is start of
270 * transfer
271 * @param[in] type - PLDM Type for which version is requested
272 * @param[in,out] msg - Message will be written to this
273 * @return pldm_completion_codes
274 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500275 * 'msg.payload'
Sampa Misra432e1872019-02-13 03:49:43 -0600276 */
277int encode_get_version_req(uint8_t instance_id, uint32_t transfer_handle,
278 uint8_t transfer_opflag, uint8_t type,
279 struct pldm_msg *msg);
280
281/** @brief Decode a GetPLDMVersion response message
282 *
283 * @param[in] msg - Response message payload
vkaverapa6575b82019-04-03 05:33:52 -0500284 * @param[in] payload_length - Length of reponse message payload
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600285 * @param[out] completion_code - Pointer to response msg's PLDM completion code
Sampa Misra432e1872019-02-13 03:49:43 -0600286 * @param[out] next_transfer_handle - the next handle for the next part of data
287 * @param[out] transfer_flag - flag to indicate the part of data
288 * @return pldm_completion_codes
289 */
vkaverapa6575b82019-04-03 05:33:52 -0500290int decode_get_version_resp(const uint8_t *msg, size_t payload_length,
Deepak Kodihalli8c643462019-02-21 10:43:36 -0600291 uint8_t *completion_code,
Sampa Misra432e1872019-02-13 03:49:43 -0600292 uint32_t *next_transfer_handle,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600293 uint8_t *transfer_flag, ver32_t *version);
Sampa Misra432e1872019-02-13 03:49:43 -0600294
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600295/* Responder */
296
297/* GetPLDMTypes */
298
299/** @brief Create a PLDM response message for GetPLDMTypes
300 *
301 * @param[in] instance_id - Message's instance id
302 * @param[in] completion_code - PLDM completion code
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600303 * @param[in] types - pointer to array bitfield8_t[8] containing supported
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600304 * types (MAX_TYPES/8) = 8), as per DSP0240
305 * @param[in,out] msg - Message will be written to this
306 * @return pldm_completion_codes
307 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500308 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600309 */
310int encode_get_types_resp(uint8_t instance_id, uint8_t completion_code,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600311 const bitfield8_t *types, struct pldm_msg *msg);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600312
313/* GetPLDMCommands */
314
315/** @brief Decode GetPLDMCommands' request data
316 *
vkaverapa6575b82019-04-03 05:33:52 -0500317 * @param[in] msg - Request message
318 * @param[in] payload_length - Length of request message payload
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600319 * @param[out] type - PLDM Type
320 * @param[out] version - Version for PLDM Type
321 * @return pldm_completion_codes
322 */
vkaverapa6575b82019-04-03 05:33:52 -0500323int decode_get_commands_req(const uint8_t *msg, size_t payload_length,
324 uint8_t *type, ver32_t *version);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600325
326/** @brief Create a PLDM response message for GetPLDMCommands
327 *
328 * @param[in] instance_id - Message's instance id
329 * @param[in] completion_code - 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 * @param[in,out] msg - Message will be written to this
333 * @return pldm_completion_codes
334 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500335 * 'msg.payload'
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600336 */
337int encode_get_commands_resp(uint8_t instance_id, uint8_t completion_code,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600338 const bitfield8_t *commands, struct pldm_msg *msg);
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600339
Sampa Misra432e1872019-02-13 03:49:43 -0600340/* GetPLDMVersion */
341
342/** @brief Create a PLDM response for GetPLDMVersion
343 *
344 * @param[in] instance_id - Message's instance id
345 * @param[in] completion_code - PLDM completion code
346 * @param[in] next_transfer_handle - Handle to identify next portion of
347 * data transfer
348 * @param[in] transfer_flag - Represents the part of transfer
349 * @param[in] version_data - the version data
350 * @param[in] version_size - size of version data
351 * @param[in,out] msg - Message will be written to this
352 * @return pldm_completion_codes
353 * @note Caller is responsible for memory alloc and dealloc of param
vkaverapa6575b82019-04-03 05:33:52 -0500354 * 'msg.payload'
Sampa Misra432e1872019-02-13 03:49:43 -0600355 */
356int encode_get_version_resp(uint8_t instance_id, uint8_t completion_code,
357 uint32_t next_transfer_handle,
Deepak Kodihalli97e0bd52019-02-21 03:54:22 -0600358 uint8_t transfer_flag, const ver32_t *version_data,
Sampa Misra432e1872019-02-13 03:49:43 -0600359 size_t version_size, struct pldm_msg *msg);
360
361/** @brief Decode a GetPLDMVersion request message
362 *
vkaverapa6575b82019-04-03 05:33:52 -0500363 * @param[in] msg - Request message
364 * @param[in] payload_length - length of request message payload
Sampa Misra432e1872019-02-13 03:49:43 -0600365 * @param[out] transfer_handle - the handle of data
366 * @param[out] transfer_opflag - Transfer Flag
367 * @param[out] type - PLDM type for which version is requested
368 * @return pldm_completion_codes
369 */
vkaverapa6575b82019-04-03 05:33:52 -0500370int decode_get_version_req(const uint8_t *msg, size_t payload_length,
Sampa Misra432e1872019-02-13 03:49:43 -0600371 uint32_t *transfer_handle, uint8_t *transfer_opflag,
372 uint8_t *type);
373
Deepak Kodihalli1b24f972019-02-01 04:09:13 -0600374#ifdef __cplusplus
375}
376#endif
377
378#endif /* BASE_H */