Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 1 | #ifndef BASE_H |
| 2 | #define BASE_H |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
| 8 | #include <asm/byteorder.h> |
| 9 | #include <stddef.h> |
| 10 | #include <stdint.h> |
| 11 | |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 12 | #include "pldm_types.h" |
| 13 | |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 14 | /** @brief PLDM Types |
| 15 | */ |
| 16 | enum pldm_supported_types { |
| 17 | PLDM_BASE = 0x00, |
Sampa Misra | 0db1dfa | 2019-03-19 00:15:31 -0500 | [diff] [blame] | 18 | PLDM_PLATFORM = 0x02, |
Sampa Misra | 032bd50 | 2019-03-06 05:03:22 -0600 | [diff] [blame] | 19 | PLDM_BIOS = 0x03, |
Jinu Joy Thomas | 8e92c6c | 2019-08-06 12:22:34 +0530 | [diff] [blame] | 20 | PLDM_FRU = 0x04, |
gokulsanker | 138ceba | 2021-04-05 13:25:25 +0530 | [diff] [blame] | 21 | PLDM_FWUP = 0x05, |
Jinu Joy Thomas | f666db1 | 2019-05-29 05:22:31 -0500 | [diff] [blame] | 22 | PLDM_OEM = 0x3F, |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 23 | }; |
| 24 | |
| 25 | /** @brief PLDM Commands |
| 26 | */ |
| 27 | enum pldm_supported_commands { |
John Wang | 5c4f80d | 2019-07-29 11:12:18 +0800 | [diff] [blame] | 28 | PLDM_GET_TID = 0x2, |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 29 | PLDM_GET_PLDM_VERSION = 0x3, |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 30 | PLDM_GET_PLDM_TYPES = 0x4, |
| 31 | PLDM_GET_PLDM_COMMANDS = 0x5 |
| 32 | }; |
| 33 | |
| 34 | /** @brief PLDM base codes |
| 35 | */ |
| 36 | enum pldm_completion_codes { |
| 37 | PLDM_SUCCESS = 0x00, |
| 38 | PLDM_ERROR = 0x01, |
| 39 | PLDM_ERROR_INVALID_DATA = 0x02, |
| 40 | PLDM_ERROR_INVALID_LENGTH = 0x03, |
| 41 | PLDM_ERROR_NOT_READY = 0x04, |
| 42 | PLDM_ERROR_UNSUPPORTED_PLDM_CMD = 0x05, |
| 43 | PLDM_ERROR_INVALID_PLDM_TYPE = 0x20 |
| 44 | }; |
| 45 | |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 46 | enum transfer_op_flag { |
| 47 | PLDM_GET_NEXTPART = 0, |
| 48 | PLDM_GET_FIRSTPART = 1, |
| 49 | }; |
| 50 | |
| 51 | enum transfer_resp_flag { |
| 52 | PLDM_START = 0x01, |
| 53 | PLDM_MIDDLE = 0x02, |
| 54 | PLDM_END = 0x04, |
| 55 | PLDM_START_AND_END = 0x05, |
| 56 | }; |
| 57 | |
Sagar Srinivas | 535bccd | 2021-03-24 12:18:26 -0500 | [diff] [blame] | 58 | /** @brief PLDM transport protocol type |
| 59 | */ |
| 60 | enum pldm_transport_protocol_type { |
| 61 | PLDM_TRANSPORT_PROTOCOL_TYPE_MCTP = 0x00, |
| 62 | PLDM_TRANSPORT_PROTOCOL_TYPE_OEM = 0xFF, |
| 63 | }; |
| 64 | |
Tom Joseph | 4125104 | 2019-02-07 16:17:07 +0530 | [diff] [blame] | 65 | /** @enum MessageType |
| 66 | * |
| 67 | * The different message types supported by the PLDM specification. |
| 68 | */ |
| 69 | typedef enum { |
| 70 | PLDM_RESPONSE, //!< PLDM response |
| 71 | PLDM_REQUEST, //!< PLDM request |
| 72 | PLDM_RESERVED, //!< Reserved |
| 73 | PLDM_ASYNC_REQUEST_NOTIFY, //!< Unacknowledged PLDM request messages |
| 74 | } MessageType; |
| 75 | |
| 76 | #define PLDM_INSTANCE_MAX 31 |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 77 | #define PLDM_MAX_TYPES 64 |
| 78 | #define PLDM_MAX_CMDS_PER_TYPE 256 |
| 79 | |
| 80 | /* Message payload lengths */ |
| 81 | #define PLDM_GET_COMMANDS_REQ_BYTES 5 |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 82 | #define PLDM_GET_VERSION_REQ_BYTES 6 |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 83 | |
| 84 | /* Response lengths are inclusive of completion code */ |
| 85 | #define PLDM_GET_TYPES_RESP_BYTES 9 |
John Wang | 5c4f80d | 2019-07-29 11:12:18 +0800 | [diff] [blame] | 86 | #define PLDM_GET_TID_RESP_BYTES 2 |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 87 | #define PLDM_GET_COMMANDS_RESP_BYTES 33 |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 88 | /* Response data has only one version and does not contain the checksum */ |
| 89 | #define PLDM_GET_VERSION_RESP_BYTES 10 |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 90 | |
Christian Geddes | 6c146f1 | 2020-05-01 14:48:23 -0500 | [diff] [blame] | 91 | #define PLDM_VERSION_0 0 |
| 92 | #define PLDM_CURRENT_VERSION PLDM_VERSION_0 |
| 93 | |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 94 | /** @struct pldm_msg_hdr |
| 95 | * |
| 96 | * Structure representing PLDM message header fields |
| 97 | */ |
| 98 | struct pldm_msg_hdr { |
| 99 | #if defined(__LITTLE_ENDIAN_BITFIELD) |
| 100 | uint8_t instance_id : 5; //!< Instance ID |
Deepak Kodihalli | 826c9d4 | 2020-05-26 01:58:06 -0500 | [diff] [blame] | 101 | uint8_t reserved : 1; //!< Reserved |
| 102 | uint8_t datagram : 1; //!< Datagram bit |
| 103 | uint8_t request : 1; //!< Request bit |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 104 | #elif defined(__BIG_ENDIAN_BITFIELD) |
Deepak Kodihalli | 826c9d4 | 2020-05-26 01:58:06 -0500 | [diff] [blame] | 105 | uint8_t request : 1; //!< Request bit |
| 106 | uint8_t datagram : 1; //!< Datagram bit |
| 107 | uint8_t reserved : 1; //!< Reserved |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 108 | uint8_t instance_id : 5; //!< Instance ID |
| 109 | #endif |
| 110 | |
| 111 | #if defined(__LITTLE_ENDIAN_BITFIELD) |
Deepak Kodihalli | 826c9d4 | 2020-05-26 01:58:06 -0500 | [diff] [blame] | 112 | uint8_t type : 6; //!< PLDM type |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 113 | uint8_t header_ver : 2; //!< Header version |
| 114 | #elif defined(__BIG_ENDIAN_BITFIELD) |
Deepak Kodihalli | 826c9d4 | 2020-05-26 01:58:06 -0500 | [diff] [blame] | 115 | uint8_t header_ver : 2; //!< Header version |
| 116 | uint8_t type : 6; //!< PLDM type |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 117 | #endif |
| 118 | uint8_t command; //!< PLDM command code |
| 119 | } __attribute__((packed)); |
| 120 | |
Zach Clark | b728eee | 2020-06-18 10:01:31 -0500 | [diff] [blame] | 121 | // Macros for byte-swapping variables in-place |
| 122 | #define HTOLE32(X) (X = htole32(X)) |
| 123 | #define HTOLE16(X) (X = htole16(X)) |
George Liu | cae1866 | 2020-05-15 09:32:57 +0800 | [diff] [blame] | 124 | #define LE32TOH(X) (X = le32toh(X)) |
| 125 | #define LE16TOH(X) (X = le16toh(X)) |
Zach Clark | b728eee | 2020-06-18 10:01:31 -0500 | [diff] [blame] | 126 | |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 127 | /** @struct pldm_msg |
| 128 | * |
| 129 | * Structure representing PLDM message |
| 130 | */ |
| 131 | struct pldm_msg { |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 132 | struct pldm_msg_hdr hdr; //!< PLDM message header |
| 133 | uint8_t payload[1]; //!< &payload[0] is the beginning of the payload |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 134 | } __attribute__((packed)); |
| 135 | |
Tom Joseph | 4125104 | 2019-02-07 16:17:07 +0530 | [diff] [blame] | 136 | /** @struct pldm_header_info |
| 137 | * |
| 138 | * The information needed to prepare PLDM header and this is passed to the |
| 139 | * pack_pldm_header and unpack_pldm_header API. |
| 140 | */ |
| 141 | struct pldm_header_info { |
Deepak Kodihalli | 826c9d4 | 2020-05-26 01:58:06 -0500 | [diff] [blame] | 142 | MessageType msg_type; //!< PLDM message type |
| 143 | uint8_t instance; //!< PLDM instance id |
| 144 | uint8_t pldm_type; //!< PLDM type |
Tom Joseph | 4125104 | 2019-02-07 16:17:07 +0530 | [diff] [blame] | 145 | uint8_t command; //!< PLDM command code |
| 146 | uint8_t completion_code; //!< PLDM completion code, applies for response |
| 147 | }; |
| 148 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 149 | /** @struct pldm_get_types_resp |
| 150 | * |
| 151 | * Structure representing PLDM get types response. |
| 152 | */ |
| 153 | struct pldm_get_types_resp { |
| 154 | uint8_t completion_code; //!< completion code |
| 155 | bitfield8_t types[8]; //!< each bit represents whether a given PLDM Type |
| 156 | //!< is supported |
| 157 | } __attribute__((packed)); |
| 158 | |
| 159 | /** @struct pldm_get_commands_req |
| 160 | * |
| 161 | * Structure representing PLDM get commands request. |
| 162 | */ |
| 163 | struct pldm_get_commands_req { |
Deepak Kodihalli | 826c9d4 | 2020-05-26 01:58:06 -0500 | [diff] [blame] | 164 | uint8_t type; //!< PLDM Type for which command support information is |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 165 | //!< being requested |
| 166 | ver32_t version; //!< version for the specified PLDM Type |
| 167 | } __attribute__((packed)); |
| 168 | |
| 169 | /** @struct pldm_get_commands_resp |
| 170 | * |
| 171 | * Structure representing PLDM get commands response. |
| 172 | */ |
| 173 | struct pldm_get_commands_resp { |
| 174 | uint8_t completion_code; //!< completion code |
| 175 | bitfield8_t commands[32]; //!< each bit represents whether a given PLDM |
| 176 | //!< command is supported |
| 177 | } __attribute__((packed)); |
| 178 | |
| 179 | /** @struct pldm_get_version_req |
| 180 | * |
| 181 | * Structure representing PLDM get version request. |
| 182 | */ |
| 183 | struct pldm_get_version_req { |
| 184 | uint32_t |
| 185 | transfer_handle; //!< handle to identify PLDM version data transfer |
| 186 | uint8_t transfer_opflag; //!< PLDM GetVersion operation flag |
| 187 | uint8_t type; //!< PLDM Type for which version information is being |
| 188 | //!< requested |
| 189 | } __attribute__((packed)); |
| 190 | |
| 191 | /** @struct pldm_get_version_resp |
| 192 | * |
| 193 | * Structure representing PLDM get version response. |
| 194 | */ |
| 195 | |
| 196 | struct pldm_get_version_resp { |
| 197 | uint8_t completion_code; //!< completion code |
| 198 | uint32_t next_transfer_handle; //!< next portion of PLDM version data |
| 199 | //!< transfer |
Deepak Kodihalli | 826c9d4 | 2020-05-26 01:58:06 -0500 | [diff] [blame] | 200 | uint8_t transfer_flag; //!< PLDM GetVersion transfer flag |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 201 | uint8_t version_data[1]; //!< PLDM GetVersion version field |
| 202 | } __attribute__((packed)); |
| 203 | |
John Wang | 5c4f80d | 2019-07-29 11:12:18 +0800 | [diff] [blame] | 204 | /** @struct pldm_get_tid_resp |
| 205 | * |
| 206 | * Structure representing PLDM get tid response. |
| 207 | */ |
| 208 | |
| 209 | struct pldm_get_tid_resp { |
| 210 | uint8_t completion_code; //!< completion code |
| 211 | uint8_t tid; //!< PLDM GetTID TID field |
| 212 | } __attribute__((packed)); |
| 213 | |
Tom Joseph | 4125104 | 2019-02-07 16:17:07 +0530 | [diff] [blame] | 214 | /** |
| 215 | * @brief Populate the PLDM message with the PLDM header.The caller of this API |
| 216 | * allocates buffer for the PLDM header when forming the PLDM message. |
| 217 | * The buffer is passed to this API to pack the PLDM header. |
| 218 | * |
| 219 | * @param[in] hdr - Pointer to the PLDM header information |
| 220 | * @param[out] msg - Pointer to PLDM message header |
| 221 | * |
| 222 | * @return 0 on success, otherwise PLDM error codes. |
Christian Geddes | 6c146f1 | 2020-05-01 14:48:23 -0500 | [diff] [blame] | 223 | * @note Caller is responsible for alloc and dealloc of msg |
| 224 | * and hdr params |
Tom Joseph | 4125104 | 2019-02-07 16:17:07 +0530 | [diff] [blame] | 225 | */ |
| 226 | int pack_pldm_header(const struct pldm_header_info *hdr, |
| 227 | struct pldm_msg_hdr *msg); |
| 228 | |
| 229 | /** |
| 230 | * @brief Unpack the PLDM header from the PLDM message. |
| 231 | * |
| 232 | * @param[in] msg - Pointer to the PLDM message header |
| 233 | * @param[out] hdr - Pointer to the PLDM header information |
| 234 | * |
| 235 | * @return 0 on success, otherwise PLDM error codes. |
Christian Geddes | 6c146f1 | 2020-05-01 14:48:23 -0500 | [diff] [blame] | 236 | * @note Caller is responsible for alloc and dealloc of msg |
| 237 | * and hdr params |
Tom Joseph | 4125104 | 2019-02-07 16:17:07 +0530 | [diff] [blame] | 238 | */ |
| 239 | int unpack_pldm_header(const struct pldm_msg_hdr *msg, |
| 240 | struct pldm_header_info *hdr); |
| 241 | |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 242 | /* Requester */ |
| 243 | |
| 244 | /* GetPLDMTypes */ |
| 245 | |
| 246 | /** @brief Create a PLDM request message for GetPLDMTypes |
| 247 | * |
| 248 | * @param[in] instance_id - Message's instance id |
| 249 | * @param[in,out] msg - Message will be written to this |
| 250 | * @return pldm_completion_codes |
| 251 | * @note Caller is responsible for memory alloc and dealloc of param |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 252 | * 'msg.payload' |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 253 | */ |
| 254 | int encode_get_types_req(uint8_t instance_id, struct pldm_msg *msg); |
| 255 | |
| 256 | /** @brief Decode a GetPLDMTypes response message |
| 257 | * |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 258 | * Note: |
| 259 | * * If the return value is not PLDM_SUCCESS, it represents a |
| 260 | * transport layer error. |
| 261 | * * If the completion_code value is not PLDM_SUCCESS, it represents a |
| 262 | * protocol layer error and all the out-parameters are invalid. |
| 263 | * |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 264 | * @param[in] msg - Response message |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 265 | * @param[in] payload_length - Length of response message payload |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 266 | * @param[out] completion_code - Pointer to response msg's PLDM completion code |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 267 | * @param[out] types - pointer to array bitfield8_t[8] containing supported |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 268 | * types (MAX_TYPES/8) = 8), as per DSP0240 |
| 269 | * @return pldm_completion_codes |
| 270 | */ |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 271 | int decode_get_types_resp(const struct pldm_msg *msg, size_t payload_length, |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 272 | uint8_t *completion_code, bitfield8_t *types); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 273 | |
| 274 | /* GetPLDMCommands */ |
| 275 | |
| 276 | /** @brief Create a PLDM request message for GetPLDMCommands |
| 277 | * |
| 278 | * @param[in] instance_id - Message's instance id |
| 279 | * @param[in] type - PLDM Type |
| 280 | * @param[in] version - Version for PLDM Type |
| 281 | * @param[in,out] msg - Message will be written to this |
| 282 | * @return pldm_completion_codes |
| 283 | * @note Caller is responsible for memory alloc and dealloc of param |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 284 | * 'msg.payload' |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 285 | */ |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 286 | int encode_get_commands_req(uint8_t instance_id, uint8_t type, ver32_t version, |
| 287 | struct pldm_msg *msg); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 288 | |
| 289 | /** @brief Decode a GetPLDMCommands response message |
| 290 | * |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 291 | * Note: |
| 292 | * * If the return value is not PLDM_SUCCESS, it represents a |
| 293 | * transport layer error. |
| 294 | * * If the completion_code value is not PLDM_SUCCESS, it represents a |
| 295 | * protocol layer error and all the out-parameters are invalid. |
| 296 | * |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 297 | * @param[in] msg - Response message |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 298 | * @param[in] payload_length - Length of reponse message payload |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 299 | * @param[out] completion_code - Pointer to response msg's PLDM completion code |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 300 | * @param[in] commands - pointer to array bitfield8_t[32] containing supported |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 301 | * commands (PLDM_MAX_CMDS_PER_TYPE/8) = 32), as per DSP0240 |
| 302 | * @return pldm_completion_codes |
| 303 | */ |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 304 | int decode_get_commands_resp(const struct pldm_msg *msg, size_t payload_length, |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 305 | uint8_t *completion_code, bitfield8_t *commands); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 306 | |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 307 | /* GetPLDMVersion */ |
| 308 | |
| 309 | /** @brief Create a PLDM request for GetPLDMVersion |
| 310 | * |
| 311 | * @param[in] instance_id - Message's instance id |
| 312 | * @param[in] transfer_handle - Handle to identify PLDM version data transfer. |
| 313 | * This handle is ignored by the responder when the |
| 314 | * transferop_flag is set to getFirstPart. |
| 315 | * @param[in] transfer_opflag - flag to indicate whether it is start of |
| 316 | * transfer |
| 317 | * @param[in] type - PLDM Type for which version is requested |
| 318 | * @param[in,out] msg - Message will be written to this |
| 319 | * @return pldm_completion_codes |
| 320 | * @note Caller is responsible for memory alloc and dealloc of param |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 321 | * 'msg.payload' |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 322 | */ |
| 323 | int encode_get_version_req(uint8_t instance_id, uint32_t transfer_handle, |
| 324 | uint8_t transfer_opflag, uint8_t type, |
| 325 | struct pldm_msg *msg); |
| 326 | |
| 327 | /** @brief Decode a GetPLDMVersion response message |
| 328 | * |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 329 | * Note: |
| 330 | * * If the return value is not PLDM_SUCCESS, it represents a |
| 331 | * transport layer error. |
| 332 | * * If the completion_code value is not PLDM_SUCCESS, it represents a |
| 333 | * protocol layer error and all the out-parameters are invalid. |
| 334 | * |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 335 | * @param[in] msg - Response message |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 336 | * @param[in] payload_length - Length of reponse message payload |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 337 | * @param[out] completion_code - Pointer to response msg's PLDM completion code |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 338 | * @param[out] next_transfer_handle - the next handle for the next part of data |
| 339 | * @param[out] transfer_flag - flag to indicate the part of data |
| 340 | * @return pldm_completion_codes |
| 341 | */ |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 342 | int decode_get_version_resp(const struct pldm_msg *msg, size_t payload_length, |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 343 | uint8_t *completion_code, |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 344 | uint32_t *next_transfer_handle, |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 345 | uint8_t *transfer_flag, ver32_t *version); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 346 | |
John Wang | 5c4f80d | 2019-07-29 11:12:18 +0800 | [diff] [blame] | 347 | /* GetTID */ |
| 348 | |
| 349 | /** @brief Decode a GetTID response message |
| 350 | * |
George Liu | 684a716 | 2019-12-06 15:10:52 +0800 | [diff] [blame] | 351 | * Note: |
| 352 | * * If the return value is not PLDM_SUCCESS, it represents a |
| 353 | * transport layer error. |
| 354 | * * If the completion_code value is not PLDM_SUCCESS, it represents a |
| 355 | * protocol layer error and all the out-parameters are invalid. |
| 356 | * |
John Wang | 5c4f80d | 2019-07-29 11:12:18 +0800 | [diff] [blame] | 357 | * @param[in] msg - Response message |
| 358 | * @param[in] payload_length - Length of response message payload |
| 359 | * @param[out] completion_code - Pointer to response msg's PLDM completion code |
| 360 | * @param[out] tid - Pointer to the terminus id |
| 361 | * @return pldm_completion_codes |
| 362 | */ |
| 363 | int decode_get_tid_resp(const struct pldm_msg *msg, size_t payload_length, |
| 364 | uint8_t *completion_code, uint8_t *tid); |
| 365 | |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 366 | /* Responder */ |
| 367 | |
| 368 | /* GetPLDMTypes */ |
| 369 | |
| 370 | /** @brief Create a PLDM response message for GetPLDMTypes |
| 371 | * |
| 372 | * @param[in] instance_id - Message's instance id |
| 373 | * @param[in] completion_code - PLDM completion code |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 374 | * @param[in] types - pointer to array bitfield8_t[8] containing supported |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 375 | * types (MAX_TYPES/8) = 8), as per DSP0240 |
| 376 | * @param[in,out] msg - Message will be written to this |
| 377 | * @return pldm_completion_codes |
| 378 | * @note Caller is responsible for memory alloc and dealloc of param |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 379 | * 'msg.payload' |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 380 | */ |
| 381 | int encode_get_types_resp(uint8_t instance_id, uint8_t completion_code, |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 382 | const bitfield8_t *types, struct pldm_msg *msg); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 383 | |
| 384 | /* GetPLDMCommands */ |
| 385 | |
| 386 | /** @brief Decode GetPLDMCommands' request data |
| 387 | * |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 388 | * @param[in] msg - Request message |
| 389 | * @param[in] payload_length - Length of request message payload |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 390 | * @param[out] type - PLDM Type |
| 391 | * @param[out] version - Version for PLDM Type |
| 392 | * @return pldm_completion_codes |
| 393 | */ |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 394 | int decode_get_commands_req(const struct pldm_msg *msg, size_t payload_length, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 395 | uint8_t *type, ver32_t *version); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 396 | |
| 397 | /** @brief Create a PLDM response message for GetPLDMCommands |
| 398 | * |
| 399 | * @param[in] instance_id - Message's instance id |
| 400 | * @param[in] completion_code - PLDM completion code |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 401 | * @param[in] commands - pointer to array bitfield8_t[32] containing supported |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 402 | * commands (PLDM_MAX_CMDS_PER_TYPE/8) = 32), as per DSP0240 |
| 403 | * @param[in,out] msg - Message will be written to this |
| 404 | * @return pldm_completion_codes |
| 405 | * @note Caller is responsible for memory alloc and dealloc of param |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 406 | * 'msg.payload' |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 407 | */ |
| 408 | int encode_get_commands_resp(uint8_t instance_id, uint8_t completion_code, |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 409 | const bitfield8_t *commands, struct pldm_msg *msg); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 410 | |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 411 | /* GetPLDMVersion */ |
| 412 | |
| 413 | /** @brief Create a PLDM response for GetPLDMVersion |
| 414 | * |
| 415 | * @param[in] instance_id - Message's instance id |
| 416 | * @param[in] completion_code - PLDM completion code |
| 417 | * @param[in] next_transfer_handle - Handle to identify next portion of |
| 418 | * data transfer |
| 419 | * @param[in] transfer_flag - Represents the part of transfer |
| 420 | * @param[in] version_data - the version data |
| 421 | * @param[in] version_size - size of version data |
| 422 | * @param[in,out] msg - Message will be written to this |
| 423 | * @return pldm_completion_codes |
| 424 | * @note Caller is responsible for memory alloc and dealloc of param |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 425 | * 'msg.payload' |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 426 | */ |
| 427 | int encode_get_version_resp(uint8_t instance_id, uint8_t completion_code, |
| 428 | uint32_t next_transfer_handle, |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 429 | uint8_t transfer_flag, const ver32_t *version_data, |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 430 | size_t version_size, struct pldm_msg *msg); |
| 431 | |
| 432 | /** @brief Decode a GetPLDMVersion request message |
| 433 | * |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 434 | * @param[in] msg - Request message |
| 435 | * @param[in] payload_length - length of request message payload |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 436 | * @param[out] transfer_handle - the handle of data |
| 437 | * @param[out] transfer_opflag - Transfer Flag |
| 438 | * @param[out] type - PLDM type for which version is requested |
| 439 | * @return pldm_completion_codes |
| 440 | */ |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 441 | int decode_get_version_req(const struct pldm_msg *msg, size_t payload_length, |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 442 | uint32_t *transfer_handle, uint8_t *transfer_opflag, |
| 443 | uint8_t *type); |
| 444 | |
Sridevi Ramesh | bc6ff26 | 2019-12-12 04:58:35 -0600 | [diff] [blame] | 445 | /* Requester */ |
| 446 | |
John Wang | 5c4f80d | 2019-07-29 11:12:18 +0800 | [diff] [blame] | 447 | /* GetTID */ |
| 448 | |
Sridevi Ramesh | bc6ff26 | 2019-12-12 04:58:35 -0600 | [diff] [blame] | 449 | /** @brief Create a PLDM request message for GetTID |
| 450 | * |
| 451 | * @param[in] instance_id - Message's instance id |
| 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 |
| 455 | * 'msg.payload' |
| 456 | */ |
| 457 | int encode_get_tid_req(uint8_t instance_id, struct pldm_msg *msg); |
| 458 | |
John Wang | 5c4f80d | 2019-07-29 11:12:18 +0800 | [diff] [blame] | 459 | /** @brief Create a PLDM response message for GetTID |
| 460 | * |
| 461 | * @param[in] instance_id - Message's instance id |
| 462 | * @param[in] completion_code - PLDM completion code |
| 463 | * @param[in] tid - Terminus ID |
| 464 | * @param[in,out] msg - Message will be written to this |
| 465 | * @return pldm_completion_codes |
| 466 | * @note Caller is responsible for memory alloc and dealloc of param |
| 467 | * 'msg.payload' |
| 468 | */ |
| 469 | int encode_get_tid_resp(uint8_t instance_id, uint8_t completion_code, |
| 470 | uint8_t tid, struct pldm_msg *msg); |
| 471 | |
John Wang | 7f02d70 | 2019-12-03 13:38:14 +0800 | [diff] [blame] | 472 | /** @brief Create a PLDM response message containing only cc |
| 473 | * |
| 474 | * @param[in] instance_id - Message's instance id |
| 475 | * @param[in] type - PLDM Type |
| 476 | * @param[in] command - PLDM Command |
| 477 | * @param[in] cc - PLDM Completion Code |
| 478 | * @param[out] msg - Message will be written to this |
| 479 | * @return pldm_completion_codes |
| 480 | */ |
| 481 | int encode_cc_only_resp(uint8_t instance_id, uint8_t type, uint8_t command, |
| 482 | uint8_t cc, struct pldm_msg *msg); |
| 483 | |
gokulsanker | 138ceba | 2021-04-05 13:25:25 +0530 | [diff] [blame] | 484 | /** @brief Create a PLDM message only with the header |
| 485 | * |
| 486 | * @param[in] msg_type - PLDM message type |
| 487 | * @param[in] instance_id - Message's instance id |
| 488 | * @param[in] pldm_type - PLDM Type |
| 489 | * @param[in] command - PLDM Command |
| 490 | * @param[out] msg - Message will be written to this |
| 491 | * |
| 492 | * @return pldm_completion_codes |
| 493 | */ |
| 494 | int encode_pldm_header_only(uint8_t msg_type, uint8_t instance_id, |
| 495 | uint8_t pldm_type, uint8_t command, |
| 496 | struct pldm_msg *msg); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 497 | #ifdef __cplusplus |
| 498 | } |
| 499 | #endif |
| 500 | |
| 501 | #endif /* BASE_H */ |