Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 1 | #include <endian.h> |
| 2 | #include <string.h> |
| 3 | |
| 4 | #include "base.h" |
| 5 | |
Tom Joseph | 4125104 | 2019-02-07 16:17:07 +0530 | [diff] [blame] | 6 | int pack_pldm_header(const struct pldm_header_info *hdr, |
| 7 | struct pldm_msg_hdr *msg) |
| 8 | { |
| 9 | if (msg == NULL || hdr == NULL) { |
| 10 | return PLDM_ERROR_INVALID_DATA; |
| 11 | } |
| 12 | |
| 13 | if (hdr->msg_type != PLDM_RESPONSE && hdr->msg_type != PLDM_REQUEST && |
| 14 | hdr->msg_type != PLDM_ASYNC_REQUEST_NOTIFY) { |
| 15 | return PLDM_ERROR_INVALID_DATA; |
| 16 | } |
| 17 | |
| 18 | if (hdr->instance > PLDM_INSTANCE_MAX) { |
| 19 | return PLDM_ERROR_INVALID_DATA; |
| 20 | } |
| 21 | |
| 22 | if (hdr->pldm_type > (PLDM_MAX_TYPES - 1)) { |
| 23 | return PLDM_ERROR_INVALID_PLDM_TYPE; |
| 24 | } |
| 25 | |
| 26 | uint8_t datagram = (hdr->msg_type == PLDM_ASYNC_REQUEST_NOTIFY) ? 1 : 0; |
| 27 | |
| 28 | if (hdr->msg_type == PLDM_RESPONSE) { |
| 29 | msg->request = PLDM_RESPONSE; |
| 30 | } else if (hdr->msg_type == PLDM_REQUEST || |
| 31 | hdr->msg_type == PLDM_ASYNC_REQUEST_NOTIFY) { |
| 32 | msg->request = PLDM_REQUEST; |
| 33 | } |
| 34 | msg->datagram = datagram; |
| 35 | msg->reserved = 0; |
| 36 | msg->instance_id = hdr->instance; |
| 37 | msg->header_ver = 0; |
| 38 | msg->type = hdr->pldm_type; |
| 39 | msg->command = hdr->command; |
| 40 | |
| 41 | return PLDM_SUCCESS; |
| 42 | } |
| 43 | |
| 44 | int unpack_pldm_header(const struct pldm_msg_hdr *msg, |
| 45 | struct pldm_header_info *hdr) |
| 46 | { |
| 47 | if (msg == NULL) { |
| 48 | return PLDM_ERROR_INVALID_DATA; |
| 49 | } |
| 50 | |
| 51 | if (msg->request == PLDM_RESPONSE) { |
| 52 | hdr->msg_type = PLDM_RESPONSE; |
| 53 | } else { |
| 54 | hdr->msg_type = |
| 55 | msg->datagram ? PLDM_ASYNC_REQUEST_NOTIFY : PLDM_REQUEST; |
| 56 | } |
| 57 | |
| 58 | hdr->instance = msg->instance_id; |
| 59 | hdr->pldm_type = msg->type; |
| 60 | hdr->command = msg->command; |
| 61 | |
| 62 | return PLDM_SUCCESS; |
| 63 | } |
| 64 | |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 65 | int encode_get_types_req(uint8_t instance_id, struct pldm_msg *msg) |
| 66 | { |
| 67 | if (msg == NULL) { |
| 68 | return PLDM_ERROR_INVALID_DATA; |
| 69 | } |
| 70 | |
Deepak Kodihalli | 67ec465 | 2019-02-16 07:00:48 -0600 | [diff] [blame] | 71 | struct pldm_header_info header = {0}; |
| 72 | header.instance = instance_id; |
| 73 | header.msg_type = PLDM_REQUEST; |
| 74 | header.command = PLDM_GET_PLDM_TYPES; |
| 75 | pack_pldm_header(&header, &(msg->hdr)); |
| 76 | |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 77 | return PLDM_SUCCESS; |
| 78 | } |
| 79 | |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 80 | int encode_get_commands_req(uint8_t instance_id, uint8_t type, ver32_t version, |
| 81 | struct pldm_msg *msg) |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 82 | { |
| 83 | if (msg == NULL) { |
| 84 | return PLDM_ERROR_INVALID_DATA; |
| 85 | } |
| 86 | |
Deepak Kodihalli | 67ec465 | 2019-02-16 07:00:48 -0600 | [diff] [blame] | 87 | struct pldm_header_info header = {0}; |
| 88 | header.instance = instance_id; |
| 89 | header.msg_type = PLDM_REQUEST; |
| 90 | header.command = PLDM_GET_PLDM_COMMANDS; |
| 91 | pack_pldm_header(&header, &(msg->hdr)); |
| 92 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 93 | struct pldm_get_commands_req *request = |
| 94 | (struct pldm_get_commands_req *)msg->payload; |
| 95 | |
| 96 | request->type = type; |
| 97 | request->version = version; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 98 | |
| 99 | return PLDM_SUCCESS; |
| 100 | } |
| 101 | |
| 102 | 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] | 103 | const bitfield8_t *types, struct pldm_msg *msg) |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 104 | { |
| 105 | if (msg == NULL) { |
| 106 | return PLDM_ERROR_INVALID_DATA; |
| 107 | } |
| 108 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 109 | struct pldm_get_types_resp *response = |
| 110 | (struct pldm_get_types_resp *)msg->payload; |
Deepak Kodihalli | 67ec465 | 2019-02-16 07:00:48 -0600 | [diff] [blame] | 111 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 112 | response->completion_code = completion_code; |
Deepak Kodihalli | 67ec465 | 2019-02-16 07:00:48 -0600 | [diff] [blame] | 113 | struct pldm_header_info header = {0}; |
| 114 | header.instance = instance_id; |
| 115 | header.msg_type = PLDM_RESPONSE; |
| 116 | header.command = PLDM_GET_PLDM_TYPES; |
| 117 | pack_pldm_header(&header, &(msg->hdr)); |
| 118 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 119 | if (response->completion_code == PLDM_SUCCESS) { |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 120 | if (types == NULL) { |
| 121 | return PLDM_ERROR_INVALID_DATA; |
| 122 | } |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 123 | memcpy(response->types, &(types->byte), PLDM_MAX_TYPES / 8); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | return PLDM_SUCCESS; |
| 127 | } |
| 128 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 129 | 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] | 130 | uint8_t *type, ver32_t *version) |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 131 | { |
| 132 | if (msg == NULL || type == NULL || version == NULL) { |
| 133 | return PLDM_ERROR_INVALID_DATA; |
| 134 | } |
| 135 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 136 | if (payload_length != PLDM_GET_COMMANDS_REQ_BYTES) { |
| 137 | return PLDM_ERROR_INVALID_LENGTH; |
| 138 | } |
| 139 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 140 | struct pldm_get_commands_req *request = |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 141 | (struct pldm_get_commands_req *)msg->payload; |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 142 | *type = request->type; |
| 143 | *version = request->version; |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 144 | return PLDM_SUCCESS; |
| 145 | } |
| 146 | |
| 147 | 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] | 148 | const bitfield8_t *commands, struct pldm_msg *msg) |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 149 | { |
| 150 | if (msg == NULL) { |
| 151 | return PLDM_ERROR_INVALID_DATA; |
| 152 | } |
| 153 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 154 | struct pldm_get_commands_resp *response = |
| 155 | (struct pldm_get_commands_resp *)msg->payload; |
| 156 | response->completion_code = completion_code; |
Deepak Kodihalli | 67ec465 | 2019-02-16 07:00:48 -0600 | [diff] [blame] | 157 | |
| 158 | struct pldm_header_info header = {0}; |
| 159 | header.instance = instance_id; |
| 160 | header.msg_type = PLDM_RESPONSE; |
| 161 | header.command = PLDM_GET_PLDM_COMMANDS; |
| 162 | pack_pldm_header(&header, &(msg->hdr)); |
| 163 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 164 | if (response->completion_code == PLDM_SUCCESS) { |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 165 | if (commands == NULL) { |
| 166 | return PLDM_ERROR_INVALID_DATA; |
| 167 | } |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 168 | memcpy(response->commands, &(commands->byte), |
| 169 | PLDM_MAX_CMDS_PER_TYPE / 8); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | return PLDM_SUCCESS; |
| 173 | } |
| 174 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 175 | 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] | 176 | uint8_t *completion_code, bitfield8_t *types) |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 177 | { |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 178 | if (msg == NULL || types == NULL || completion_code == NULL) { |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 179 | return PLDM_ERROR_INVALID_DATA; |
| 180 | } |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 181 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 182 | if (payload_length != PLDM_GET_TYPES_RESP_BYTES) { |
| 183 | return PLDM_ERROR_INVALID_LENGTH; |
| 184 | } |
| 185 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 186 | struct pldm_get_types_resp *response = |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 187 | (struct pldm_get_types_resp *)msg->payload; |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 188 | *completion_code = response->completion_code; |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 189 | if (PLDM_SUCCESS != *completion_code) { |
| 190 | return PLDM_SUCCESS; |
| 191 | }; |
| 192 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 193 | memcpy(&(types->byte), response->types, PLDM_MAX_TYPES / 8); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 194 | |
| 195 | return PLDM_SUCCESS; |
| 196 | } |
| 197 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 198 | 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] | 199 | uint8_t *completion_code, bitfield8_t *commands) |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 200 | { |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 201 | if (msg == NULL || commands == NULL || completion_code == NULL) { |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 202 | return PLDM_ERROR_INVALID_DATA; |
| 203 | } |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 204 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 205 | if (payload_length != PLDM_GET_COMMANDS_RESP_BYTES) { |
| 206 | return PLDM_ERROR_INVALID_LENGTH; |
| 207 | } |
| 208 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 209 | struct pldm_get_commands_resp *response = |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 210 | (struct pldm_get_commands_resp *)msg->payload; |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 211 | *completion_code = response->completion_code; |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 212 | if (PLDM_SUCCESS != *completion_code) { |
| 213 | return PLDM_SUCCESS; |
| 214 | }; |
| 215 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 216 | memcpy(&(commands->byte), response->commands, |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 217 | PLDM_MAX_CMDS_PER_TYPE / 8); |
Deepak Kodihalli | 1b24f97 | 2019-02-01 04:09:13 -0600 | [diff] [blame] | 218 | |
| 219 | return PLDM_SUCCESS; |
| 220 | } |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 221 | |
| 222 | int encode_get_version_req(uint8_t instance_id, uint32_t transfer_handle, |
| 223 | uint8_t transfer_opflag, uint8_t type, |
| 224 | struct pldm_msg *msg) |
| 225 | { |
| 226 | struct pldm_header_info header = {0}; |
| 227 | int rc = PLDM_SUCCESS; |
| 228 | |
| 229 | if (NULL == msg) { |
| 230 | return PLDM_ERROR_INVALID_DATA; |
| 231 | } |
| 232 | |
| 233 | header.msg_type = PLDM_REQUEST; |
| 234 | header.instance = instance_id; |
| 235 | header.pldm_type = PLDM_BASE; |
| 236 | header.command = PLDM_GET_PLDM_VERSION; |
| 237 | |
| 238 | if ((rc = pack_pldm_header(&header, &(msg->hdr))) > PLDM_SUCCESS) { |
| 239 | return rc; |
| 240 | } |
| 241 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 242 | struct pldm_get_version_req *request = |
| 243 | (struct pldm_get_version_req *)msg->payload; |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 244 | transfer_handle = htole32(transfer_handle); |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 245 | request->transfer_handle = transfer_handle; |
| 246 | request->transfer_opflag = transfer_opflag; |
| 247 | request->type = type; |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 248 | |
| 249 | return PLDM_SUCCESS; |
| 250 | } |
| 251 | |
| 252 | int encode_get_version_resp(uint8_t instance_id, uint8_t completion_code, |
| 253 | uint32_t next_transfer_handle, |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 254 | uint8_t transfer_flag, const ver32_t *version_data, |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 255 | size_t version_size, struct pldm_msg *msg) |
| 256 | { |
| 257 | struct pldm_header_info header = {0}; |
| 258 | int rc = PLDM_SUCCESS; |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 259 | struct pldm_get_version_resp *response = |
| 260 | (struct pldm_get_version_resp *)msg->payload; |
| 261 | response->completion_code = completion_code; |
| 262 | if (response->completion_code == PLDM_SUCCESS) { |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 263 | |
| 264 | header.msg_type = PLDM_RESPONSE; |
| 265 | header.instance = instance_id; |
| 266 | header.pldm_type = PLDM_BASE; |
| 267 | header.command = PLDM_GET_PLDM_VERSION; |
| 268 | |
| 269 | if ((rc = pack_pldm_header(&header, &(msg->hdr))) > |
| 270 | PLDM_SUCCESS) { |
| 271 | return rc; |
| 272 | } |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 273 | response->next_transfer_handle = htole32(next_transfer_handle); |
| 274 | response->transfer_flag = transfer_flag; |
| 275 | memcpy(response->version_data, (uint8_t *)version_data, |
| 276 | version_size); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 277 | } |
| 278 | return PLDM_SUCCESS; |
| 279 | } |
| 280 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 281 | 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] | 282 | uint32_t *transfer_handle, uint8_t *transfer_opflag, |
| 283 | uint8_t *type) |
| 284 | { |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 285 | |
| 286 | if (payload_length != PLDM_GET_VERSION_REQ_BYTES) { |
| 287 | return PLDM_ERROR_INVALID_LENGTH; |
| 288 | } |
| 289 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 290 | struct pldm_get_version_req *request = |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 291 | (struct pldm_get_version_req *)msg->payload; |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 292 | *transfer_handle = le32toh(request->transfer_handle); |
| 293 | *transfer_opflag = request->transfer_opflag; |
| 294 | *type = request->type; |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 295 | return PLDM_SUCCESS; |
| 296 | } |
| 297 | |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 298 | 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] | 299 | uint8_t *completion_code, |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 300 | uint32_t *next_transfer_handle, |
Deepak Kodihalli | 97e0bd5 | 2019-02-21 03:54:22 -0600 | [diff] [blame] | 301 | uint8_t *transfer_flag, ver32_t *version) |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 302 | { |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 303 | if (msg == NULL || next_transfer_handle == NULL || |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 304 | transfer_flag == NULL || completion_code == NULL) { |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 305 | return PLDM_ERROR_INVALID_DATA; |
| 306 | } |
| 307 | |
vkaverap | a6575b8 | 2019-04-03 05:33:52 -0500 | [diff] [blame] | 308 | if (payload_length < PLDM_GET_VERSION_RESP_BYTES) { |
| 309 | return PLDM_ERROR_INVALID_LENGTH; |
| 310 | } |
| 311 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 312 | struct pldm_get_version_resp *response = |
Zahed Hossain | 223a73d | 2019-07-04 12:46:18 -0500 | [diff] [blame] | 313 | (struct pldm_get_version_resp *)msg->payload; |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 314 | *completion_code = response->completion_code; |
Deepak Kodihalli | 8c64346 | 2019-02-21 10:43:36 -0600 | [diff] [blame] | 315 | if (PLDM_SUCCESS != *completion_code) { |
| 316 | return PLDM_SUCCESS; |
| 317 | }; |
| 318 | |
Priyanga | 4b790ce | 2019-06-10 01:30:09 -0500 | [diff] [blame] | 319 | *next_transfer_handle = le32toh(response->next_transfer_handle); |
| 320 | *transfer_flag = response->transfer_flag; |
| 321 | memcpy(version, (uint8_t *)response->version_data, sizeof(ver32_t)); |
Sampa Misra | 432e187 | 2019-02-13 03:49:43 -0600 | [diff] [blame] | 322 | |
| 323 | return PLDM_SUCCESS; |
| 324 | } |
John Wang | 5c4f80d | 2019-07-29 11:12:18 +0800 | [diff] [blame] | 325 | |
| 326 | int encode_get_tid_resp(uint8_t instance_id, uint8_t completion_code, |
| 327 | uint8_t tid, struct pldm_msg *msg) |
| 328 | { |
| 329 | if (msg == NULL) { |
| 330 | return PLDM_ERROR_INVALID_DATA; |
| 331 | } |
| 332 | |
| 333 | struct pldm_get_tid_resp *response = |
| 334 | (struct pldm_get_tid_resp *)msg->payload; |
| 335 | |
| 336 | response->completion_code = completion_code; |
| 337 | struct pldm_header_info header = {0}; |
| 338 | header.instance = instance_id; |
| 339 | header.msg_type = PLDM_RESPONSE; |
| 340 | header.command = PLDM_GET_TID; |
| 341 | pack_pldm_header(&header, &(msg->hdr)); |
| 342 | |
| 343 | response->tid = tid; |
| 344 | |
| 345 | return PLDM_SUCCESS; |
| 346 | } |
| 347 | |
| 348 | int decode_get_tid_resp(const struct pldm_msg *msg, size_t payload_length, |
| 349 | uint8_t *completion_code, uint8_t *tid) |
| 350 | { |
| 351 | if (msg == NULL || tid == NULL || completion_code == NULL) { |
| 352 | return PLDM_ERROR_INVALID_DATA; |
| 353 | } |
| 354 | |
| 355 | if (payload_length != PLDM_GET_TID_RESP_BYTES) { |
| 356 | return PLDM_ERROR_INVALID_LENGTH; |
| 357 | } |
| 358 | |
| 359 | struct pldm_get_tid_resp *response = |
| 360 | (struct pldm_get_tid_resp *)msg->payload; |
| 361 | *completion_code = response->completion_code; |
| 362 | if (PLDM_SUCCESS != *completion_code) { |
| 363 | return PLDM_SUCCESS; |
| 364 | }; |
| 365 | |
| 366 | *tid = response->tid; |
| 367 | |
| 368 | return PLDM_SUCCESS; |
| 369 | } |