Patrick Williams | 691668f | 2023-11-01 08:19:10 -0500 | [diff] [blame] | 1 | /* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */ |
Chris Wang | 4c1f2c7 | 2024-03-21 17:09:44 +0800 | [diff] [blame] | 2 | #include "msgbuf.h" |
Andrew Jeffery | b0c1d20 | 2023-11-07 22:08:44 +1030 | [diff] [blame] | 3 | #include <libpldm/firmware_update.h> |
| 4 | #include <libpldm/utils.h> |
| 5 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 6 | #include <endian.h> |
Manojkiran Eda | 9a8e497 | 2022-11-28 16:38:21 +0530 | [diff] [blame] | 7 | #include <stdbool.h> |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 8 | #include <string.h> |
| 9 | |
| 10 | /** @brief Check whether string type value is valid |
| 11 | * |
| 12 | * @return true if string type value is valid, false if not |
| 13 | */ |
| 14 | static bool is_string_type_valid(uint8_t string_type) |
| 15 | { |
| 16 | switch (string_type) { |
| 17 | case PLDM_STR_TYPE_UNKNOWN: |
| 18 | return false; |
| 19 | case PLDM_STR_TYPE_ASCII: |
| 20 | case PLDM_STR_TYPE_UTF_8: |
| 21 | case PLDM_STR_TYPE_UTF_16: |
| 22 | case PLDM_STR_TYPE_UTF_16LE: |
| 23 | case PLDM_STR_TYPE_UTF_16BE: |
| 24 | return true; |
| 25 | default: |
| 26 | return false; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | /** @brief Return the length of the descriptor type described in firmware update |
| 31 | * specification |
| 32 | * |
| 33 | * @return length of the descriptor type if descriptor type is valid else |
| 34 | * return 0 |
| 35 | */ |
| 36 | static uint16_t get_descriptor_type_length(uint16_t descriptor_type) |
| 37 | { |
| 38 | switch (descriptor_type) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 39 | case PLDM_FWUP_PCI_VENDOR_ID: |
| 40 | return PLDM_FWUP_PCI_VENDOR_ID_LENGTH; |
| 41 | case PLDM_FWUP_IANA_ENTERPRISE_ID: |
| 42 | return PLDM_FWUP_IANA_ENTERPRISE_ID_LENGTH; |
| 43 | case PLDM_FWUP_UUID: |
| 44 | return PLDM_FWUP_UUID_LENGTH; |
| 45 | case PLDM_FWUP_PNP_VENDOR_ID: |
| 46 | return PLDM_FWUP_PNP_VENDOR_ID_LENGTH; |
| 47 | case PLDM_FWUP_ACPI_VENDOR_ID: |
| 48 | return PLDM_FWUP_ACPI_VENDOR_ID_LENGTH; |
| 49 | case PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID: |
| 50 | return PLDM_FWUP_IEEE_ASSIGNED_COMPANY_ID_LENGTH; |
| 51 | case PLDM_FWUP_SCSI_VENDOR_ID: |
| 52 | return PLDM_FWUP_SCSI_VENDOR_ID_LENGTH; |
| 53 | case PLDM_FWUP_PCI_DEVICE_ID: |
| 54 | return PLDM_FWUP_PCI_DEVICE_ID_LENGTH; |
| 55 | case PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID: |
| 56 | return PLDM_FWUP_PCI_SUBSYSTEM_VENDOR_ID_LENGTH; |
| 57 | case PLDM_FWUP_PCI_SUBSYSTEM_ID: |
| 58 | return PLDM_FWUP_PCI_SUBSYSTEM_ID_LENGTH; |
| 59 | case PLDM_FWUP_PCI_REVISION_ID: |
| 60 | return PLDM_FWUP_PCI_REVISION_ID_LENGTH; |
| 61 | case PLDM_FWUP_PNP_PRODUCT_IDENTIFIER: |
| 62 | return PLDM_FWUP_PNP_PRODUCT_IDENTIFIER_LENGTH; |
| 63 | case PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER: |
| 64 | return PLDM_FWUP_ACPI_PRODUCT_IDENTIFIER_LENGTH; |
| 65 | case PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING: |
| 66 | return PLDM_FWUP_ASCII_MODEL_NUMBER_LONG_STRING_LENGTH; |
| 67 | case PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING: |
| 68 | return PLDM_FWUP_ASCII_MODEL_NUMBER_SHORT_STRING_LENGTH; |
| 69 | case PLDM_FWUP_SCSI_PRODUCT_ID: |
| 70 | return PLDM_FWUP_SCSI_PRODUCT_ID_LENGTH; |
| 71 | case PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE: |
| 72 | return PLDM_FWUP_UBM_CONTROLLER_DEVICE_CODE_LENGTH; |
| 73 | default: |
| 74 | return 0; |
| 75 | } |
| 76 | } |
| 77 | |
Chris Wang | 4c1f2c7 | 2024-03-21 17:09:44 +0800 | [diff] [blame] | 78 | static bool is_downstream_device_update_support_valid(uint8_t resp) |
| 79 | { |
| 80 | switch (resp) { |
| 81 | case PLDM_FWUP_DOWNSTREAM_DEVICE_UPDATE_NOT_SUPPORTED: |
| 82 | case PLDM_FWUP_DOWNSTREAM_DEVICE_UPDATE_SUPPORTED: |
| 83 | return true; |
| 84 | default: |
| 85 | return false; |
| 86 | } |
| 87 | } |
| 88 | |
Chris Wang | 458475a | 2024-03-26 17:59:19 +0800 | [diff] [blame] | 89 | static bool |
| 90 | is_transfer_operation_flag_valid(enum transfer_op_flag transfer_op_flag) |
| 91 | { |
| 92 | switch (transfer_op_flag) { |
| 93 | case PLDM_GET_NEXTPART: |
| 94 | case PLDM_GET_FIRSTPART: |
| 95 | return true; |
| 96 | default: |
| 97 | return false; |
| 98 | } |
| 99 | } |
| 100 | |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 101 | /** @brief Check whether ComponentResponse is valid |
| 102 | * |
| 103 | * @return true if ComponentResponse is valid, false if not |
| 104 | */ |
| 105 | static bool is_comp_resp_valid(uint8_t comp_resp) |
| 106 | { |
| 107 | switch (comp_resp) { |
| 108 | case PLDM_CR_COMP_CAN_BE_UPDATED: |
| 109 | case PLDM_CR_COMP_MAY_BE_UPDATEABLE: |
| 110 | return true; |
| 111 | |
| 112 | default: |
| 113 | return false; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /** @brief Check whether ComponentResponseCode is valid |
| 118 | * |
| 119 | * @return true if ComponentResponseCode is valid, false if not |
| 120 | */ |
| 121 | static bool is_comp_resp_code_valid(uint8_t comp_resp_code) |
| 122 | { |
| 123 | switch (comp_resp_code) { |
| 124 | case PLDM_CRC_COMP_CAN_BE_UPDATED: |
| 125 | case PLDM_CRC_COMP_COMPARISON_STAMP_IDENTICAL: |
| 126 | case PLDM_CRC_COMP_COMPARISON_STAMP_LOWER: |
| 127 | case PLDM_CRC_INVALID_COMP_COMPARISON_STAMP: |
| 128 | case PLDM_CRC_COMP_CONFLICT: |
| 129 | case PLDM_CRC_COMP_PREREQUISITES_NOT_MET: |
| 130 | case PLDM_CRC_COMP_NOT_SUPPORTED: |
| 131 | case PLDM_CRC_COMP_SECURITY_RESTRICTIONS: |
| 132 | case PLDM_CRC_INCOMPLETE_COMP_IMAGE_SET: |
| 133 | case PLDM_CRC_ACTIVE_IMAGE_NOT_UPDATEABLE_SUBSEQUENTLY: |
| 134 | case PLDM_CRC_COMP_VER_STR_IDENTICAL: |
| 135 | case PLDM_CRC_COMP_VER_STR_LOWER: |
| 136 | return true; |
| 137 | |
| 138 | default: |
| 139 | if (comp_resp_code >= |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 140 | PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MIN && |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 141 | comp_resp_code <= |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 142 | PLDM_CRC_VENDOR_COMP_RESP_CODE_RANGE_MAX) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 143 | return true; |
| 144 | } |
| 145 | return false; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /** @brief Check whether ComponentCompatibilityResponse is valid |
| 150 | * |
| 151 | * @return true if ComponentCompatibilityResponse is valid, false if not |
| 152 | */ |
| 153 | static bool is_comp_compatibility_resp_valid(uint8_t comp_compatibility_resp) |
| 154 | { |
| 155 | switch (comp_compatibility_resp) { |
| 156 | case PLDM_CCR_COMP_CAN_BE_UPDATED: |
| 157 | case PLDM_CCR_COMP_CANNOT_BE_UPDATED: |
| 158 | return true; |
| 159 | |
| 160 | default: |
| 161 | return false; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | /** @brief Check whether ComponentCompatibilityResponse Code is valid |
| 166 | * |
| 167 | * @return true if ComponentCompatibilityResponse Code is valid, false if not |
| 168 | */ |
| 169 | static bool |
| 170 | is_comp_compatibility_resp_code_valid(uint8_t comp_compatibility_resp_code) |
| 171 | { |
| 172 | switch (comp_compatibility_resp_code) { |
| 173 | case PLDM_CCRC_NO_RESPONSE_CODE: |
| 174 | case PLDM_CCRC_COMP_COMPARISON_STAMP_IDENTICAL: |
| 175 | case PLDM_CCRC_COMP_COMPARISON_STAMP_LOWER: |
| 176 | case PLDM_CCRC_INVALID_COMP_COMPARISON_STAMP: |
| 177 | case PLDM_CCRC_COMP_CONFLICT: |
| 178 | case PLDM_CCRC_COMP_PREREQUISITES_NOT_MET: |
| 179 | case PLDM_CCRC_COMP_NOT_SUPPORTED: |
| 180 | case PLDM_CCRC_COMP_SECURITY_RESTRICTIONS: |
| 181 | case PLDM_CRC_INCOMPLETE_COMP_IMAGE_SET: |
| 182 | case PLDM_CCRC_COMP_INFO_NO_MATCH: |
| 183 | case PLDM_CCRC_COMP_VER_STR_IDENTICAL: |
| 184 | case PLDM_CCRC_COMP_VER_STR_LOWER: |
| 185 | return true; |
| 186 | |
| 187 | default: |
| 188 | if (comp_compatibility_resp_code >= |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 189 | PLDM_CCRC_VENDOR_COMP_RESP_CODE_RANGE_MIN && |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 190 | comp_compatibility_resp_code <= |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 191 | PLDM_CCRC_VENDOR_COMP_RESP_CODE_RANGE_MAX) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 192 | return true; |
| 193 | } |
| 194 | return false; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | /** @brief Check whether SelfContainedActivationRequest is valid |
| 199 | * |
| 200 | * @return true if SelfContainedActivationRequest is valid, false if not |
| 201 | */ |
| 202 | static bool |
| 203 | is_self_contained_activation_req_valid(bool8_t self_contained_activation_req) |
| 204 | { |
| 205 | switch (self_contained_activation_req) { |
| 206 | case PLDM_NOT_ACTIVATE_SELF_CONTAINED_COMPONENTS: |
| 207 | case PLDM_ACTIVATE_SELF_CONTAINED_COMPONENTS: |
| 208 | return true; |
| 209 | |
| 210 | default: |
| 211 | return false; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | /** @brief Check if current or previous status in GetStatus command response is |
| 216 | * valid |
| 217 | * |
| 218 | * @param[in] state - current or previous different state machine state of |
| 219 | * the FD |
| 220 | * @return true if state is valid, false if not |
| 221 | */ |
| 222 | static bool is_state_valid(uint8_t state) |
| 223 | { |
| 224 | switch (state) { |
| 225 | case PLDM_FD_STATE_IDLE: |
| 226 | case PLDM_FD_STATE_LEARN_COMPONENTS: |
| 227 | case PLDM_FD_STATE_READY_XFER: |
| 228 | case PLDM_FD_STATE_DOWNLOAD: |
| 229 | case PLDM_FD_STATE_VERIFY: |
| 230 | case PLDM_FD_STATE_APPLY: |
| 231 | case PLDM_FD_STATE_ACTIVATE: |
| 232 | return true; |
| 233 | |
| 234 | default: |
| 235 | return false; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | /** @brief Check if aux state in GetStatus command response is valid |
| 240 | * |
| 241 | * @param[in] aux_state - provides additional information to the UA to describe |
| 242 | * the current operation state of the FD/FDP |
| 243 | * |
| 244 | * @return true if aux state is valid, false if not |
| 245 | */ |
| 246 | static bool is_aux_state_valid(uint8_t aux_state) |
| 247 | { |
| 248 | switch (aux_state) { |
| 249 | case PLDM_FD_OPERATION_IN_PROGRESS: |
| 250 | case PLDM_FD_OPERATION_SUCCESSFUL: |
| 251 | case PLDM_FD_OPERATION_FAILED: |
| 252 | case PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER: |
| 253 | return true; |
| 254 | |
| 255 | default: |
| 256 | return false; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | /** @brief Check if aux state status in GetStatus command response is valid |
| 261 | * |
| 262 | * @param[in] aux_state_status - aux state status |
| 263 | * |
| 264 | * @return true if aux state status is valid, false if not |
| 265 | */ |
| 266 | static bool is_aux_state_status_valid(uint8_t aux_state_status) |
| 267 | { |
| 268 | if (aux_state_status == PLDM_FD_AUX_STATE_IN_PROGRESS_OR_SUCCESS || |
| 269 | aux_state_status == PLDM_FD_TIMEOUT || |
Andrew Jeffery | 67f7ed9 | 2023-04-05 14:00:00 +0930 | [diff] [blame] | 270 | aux_state_status == PLDM_FD_GENERIC_ERROR || |
| 271 | (aux_state_status >= PLDM_FD_VENDOR_DEFINED_STATUS_CODE_START && |
| 272 | aux_state_status <= PLDM_FD_VENDOR_DEFINED_STATUS_CODE_END)) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 273 | return true; |
| 274 | } |
| 275 | |
| 276 | return false; |
| 277 | } |
| 278 | |
| 279 | /** @brief Check if reason code in GetStatus command response is valid |
| 280 | * |
| 281 | * @param[in] reason_code - provides the reason for why the current state |
| 282 | * entered the IDLE state |
| 283 | * |
| 284 | * @return true if reason code is valid, false if not |
| 285 | */ |
| 286 | static bool is_reason_code_valid(uint8_t reason_code) |
| 287 | { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 288 | switch (reason_code) { |
| 289 | case PLDM_FD_INITIALIZATION: |
| 290 | case PLDM_FD_ACTIVATE_FW: |
| 291 | case PLDM_FD_CANCEL_UPDATE: |
| 292 | case PLDM_FD_TIMEOUT_LEARN_COMPONENT: |
| 293 | case PLDM_FD_TIMEOUT_READY_XFER: |
| 294 | case PLDM_FD_TIMEOUT_DOWNLOAD: |
| 295 | case PLDM_FD_TIMEOUT_VERIFY: |
| 296 | case PLDM_FD_TIMEOUT_APPLY: |
| 297 | return true; |
| 298 | |
| 299 | default: |
| 300 | if (reason_code >= PLDM_FD_STATUS_VENDOR_DEFINED_MIN) { |
| 301 | return true; |
| 302 | } |
| 303 | return false; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | /** @brief Check if non functioning component indication in CancelUpdate |
| 308 | * response is valid |
| 309 | * |
| 310 | * @return true if non functioning component indication is valid, false if not |
| 311 | */ |
| 312 | static bool is_non_functioning_component_indication_valid( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 313 | bool8_t non_functioning_component_indication) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 314 | { |
| 315 | switch (non_functioning_component_indication) { |
| 316 | case PLDM_FWUP_COMPONENTS_FUNCTIONING: |
| 317 | case PLDM_FWUP_COMPONENTS_NOT_FUNCTIONING: |
| 318 | return true; |
| 319 | |
| 320 | default: |
| 321 | return false; |
| 322 | } |
| 323 | } |
| 324 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 325 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 326 | int decode_pldm_package_header_info( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 327 | const uint8_t *data, size_t length, |
| 328 | struct pldm_package_header_information *package_header_info, |
| 329 | struct variable_field *package_version_str) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 330 | { |
| 331 | if (data == NULL || package_header_info == NULL || |
| 332 | package_version_str == NULL) { |
| 333 | return PLDM_ERROR_INVALID_DATA; |
| 334 | } |
| 335 | |
| 336 | if (length < sizeof(struct pldm_package_header_information)) { |
| 337 | return PLDM_ERROR_INVALID_LENGTH; |
| 338 | } |
| 339 | |
| 340 | struct pldm_package_header_information *data_header = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 341 | (struct pldm_package_header_information *)(data); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 342 | |
| 343 | if (!is_string_type_valid(data_header->package_version_string_type) || |
| 344 | (data_header->package_version_string_length == 0)) { |
| 345 | return PLDM_ERROR_INVALID_DATA; |
| 346 | } |
| 347 | |
| 348 | if (length < sizeof(struct pldm_package_header_information) + |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 349 | data_header->package_version_string_length) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 350 | return PLDM_ERROR_INVALID_LENGTH; |
| 351 | } |
| 352 | |
| 353 | if ((data_header->component_bitmap_bit_length % |
| 354 | PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE) != 0) { |
| 355 | return PLDM_ERROR_INVALID_DATA; |
| 356 | } |
| 357 | |
| 358 | memcpy(package_header_info->uuid, data_header->uuid, |
| 359 | sizeof(data_header->uuid)); |
| 360 | package_header_info->package_header_format_version = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 361 | data_header->package_header_format_version; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 362 | package_header_info->package_header_size = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 363 | le16toh(data_header->package_header_size); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 364 | memcpy(package_header_info->package_release_date_time, |
| 365 | data_header->package_release_date_time, |
| 366 | sizeof(data_header->package_release_date_time)); |
| 367 | package_header_info->component_bitmap_bit_length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 368 | le16toh(data_header->component_bitmap_bit_length); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 369 | package_header_info->package_version_string_type = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 370 | data_header->package_version_string_type; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 371 | package_header_info->package_version_string_length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 372 | data_header->package_version_string_length; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 373 | package_version_str->ptr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 374 | data + sizeof(struct pldm_package_header_information); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 375 | package_version_str->length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 376 | package_header_info->package_version_string_length; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 377 | |
| 378 | return PLDM_SUCCESS; |
| 379 | } |
| 380 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 381 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 382 | int decode_firmware_device_id_record( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 383 | const uint8_t *data, size_t length, |
| 384 | uint16_t component_bitmap_bit_length, |
| 385 | struct pldm_firmware_device_id_record *fw_device_id_record, |
| 386 | struct variable_field *applicable_components, |
| 387 | struct variable_field *comp_image_set_version_str, |
| 388 | struct variable_field *record_descriptors, |
| 389 | struct variable_field *fw_device_pkg_data) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 390 | { |
| 391 | if (data == NULL || fw_device_id_record == NULL || |
| 392 | applicable_components == NULL || |
| 393 | comp_image_set_version_str == NULL || record_descriptors == NULL || |
| 394 | fw_device_pkg_data == NULL) { |
| 395 | return PLDM_ERROR_INVALID_DATA; |
| 396 | } |
| 397 | |
| 398 | if (length < sizeof(struct pldm_firmware_device_id_record)) { |
| 399 | return PLDM_ERROR_INVALID_LENGTH; |
| 400 | } |
| 401 | |
| 402 | if ((component_bitmap_bit_length % |
| 403 | PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE) != 0) { |
| 404 | return PLDM_ERROR_INVALID_DATA; |
| 405 | } |
| 406 | |
| 407 | struct pldm_firmware_device_id_record *data_record = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 408 | (struct pldm_firmware_device_id_record *)(data); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 409 | |
| 410 | if (!is_string_type_valid( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 411 | data_record->comp_image_set_version_string_type) || |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 412 | (data_record->comp_image_set_version_string_length == 0)) { |
| 413 | return PLDM_ERROR_INVALID_DATA; |
| 414 | } |
| 415 | |
| 416 | fw_device_id_record->record_length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 417 | le16toh(data_record->record_length); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 418 | fw_device_id_record->descriptor_count = data_record->descriptor_count; |
| 419 | fw_device_id_record->device_update_option_flags.value = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 420 | le32toh(data_record->device_update_option_flags.value); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 421 | fw_device_id_record->comp_image_set_version_string_type = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 422 | data_record->comp_image_set_version_string_type; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 423 | fw_device_id_record->comp_image_set_version_string_length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 424 | data_record->comp_image_set_version_string_length; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 425 | fw_device_id_record->fw_device_pkg_data_length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 426 | le16toh(data_record->fw_device_pkg_data_length); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 427 | |
| 428 | if (length < fw_device_id_record->record_length) { |
| 429 | return PLDM_ERROR_INVALID_LENGTH; |
| 430 | } |
| 431 | |
| 432 | uint16_t applicable_components_length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 433 | component_bitmap_bit_length / |
| 434 | PLDM_FWUP_COMPONENT_BITMAP_MULTIPLE; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 435 | uint16_t calc_min_record_length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 436 | sizeof(struct pldm_firmware_device_id_record) + |
| 437 | applicable_components_length + |
| 438 | data_record->comp_image_set_version_string_length + |
| 439 | PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN + |
| 440 | fw_device_id_record->fw_device_pkg_data_length; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 441 | |
| 442 | if (fw_device_id_record->record_length < calc_min_record_length) { |
| 443 | return PLDM_ERROR_INVALID_LENGTH; |
| 444 | } |
| 445 | |
| 446 | applicable_components->ptr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 447 | data + sizeof(struct pldm_firmware_device_id_record); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 448 | applicable_components->length = applicable_components_length; |
| 449 | |
| 450 | comp_image_set_version_str->ptr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 451 | applicable_components->ptr + applicable_components->length; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 452 | comp_image_set_version_str->length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 453 | fw_device_id_record->comp_image_set_version_string_length; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 454 | |
| 455 | record_descriptors->ptr = comp_image_set_version_str->ptr + |
| 456 | comp_image_set_version_str->length; |
| 457 | record_descriptors->length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 458 | fw_device_id_record->record_length - |
| 459 | sizeof(struct pldm_firmware_device_id_record) - |
| 460 | applicable_components_length - |
| 461 | fw_device_id_record->comp_image_set_version_string_length - |
| 462 | fw_device_id_record->fw_device_pkg_data_length; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 463 | |
| 464 | if (fw_device_id_record->fw_device_pkg_data_length) { |
| 465 | fw_device_pkg_data->ptr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 466 | record_descriptors->ptr + record_descriptors->length; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 467 | fw_device_pkg_data->length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 468 | fw_device_id_record->fw_device_pkg_data_length; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | return PLDM_SUCCESS; |
| 472 | } |
| 473 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 474 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 475 | int decode_descriptor_type_length_value(const uint8_t *data, size_t length, |
| 476 | uint16_t *descriptor_type, |
| 477 | struct variable_field *descriptor_data) |
| 478 | { |
| 479 | uint16_t descriptor_length = 0; |
| 480 | |
| 481 | if (data == NULL || descriptor_type == NULL || |
| 482 | descriptor_data == NULL) { |
| 483 | return PLDM_ERROR_INVALID_DATA; |
| 484 | } |
| 485 | |
| 486 | if (length < PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN) { |
| 487 | return PLDM_ERROR_INVALID_LENGTH; |
| 488 | } |
| 489 | |
| 490 | struct pldm_descriptor_tlv *entry = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 491 | (struct pldm_descriptor_tlv *)(data); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 492 | |
| 493 | *descriptor_type = le16toh(entry->descriptor_type); |
| 494 | descriptor_length = le16toh(entry->descriptor_length); |
| 495 | if (*descriptor_type != PLDM_FWUP_VENDOR_DEFINED) { |
| 496 | if (descriptor_length != |
| 497 | get_descriptor_type_length(*descriptor_type)) { |
| 498 | return PLDM_ERROR_INVALID_LENGTH; |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | if (length < (sizeof(*descriptor_type) + sizeof(descriptor_length) + |
| 503 | descriptor_length)) { |
| 504 | return PLDM_ERROR_INVALID_LENGTH; |
| 505 | } |
| 506 | |
| 507 | descriptor_data->ptr = entry->descriptor_data; |
| 508 | descriptor_data->length = descriptor_length; |
| 509 | |
| 510 | return PLDM_SUCCESS; |
| 511 | } |
| 512 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 513 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 514 | int decode_vendor_defined_descriptor_value( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 515 | const uint8_t *data, size_t length, uint8_t *descriptor_title_str_type, |
| 516 | struct variable_field *descriptor_title_str, |
| 517 | struct variable_field *descriptor_data) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 518 | { |
| 519 | if (data == NULL || descriptor_title_str_type == NULL || |
| 520 | descriptor_title_str == NULL || descriptor_data == NULL) { |
| 521 | return PLDM_ERROR_INVALID_DATA; |
| 522 | } |
| 523 | |
| 524 | if (length < sizeof(struct pldm_vendor_defined_descriptor_title_data)) { |
| 525 | return PLDM_ERROR_INVALID_LENGTH; |
| 526 | } |
| 527 | |
| 528 | struct pldm_vendor_defined_descriptor_title_data *entry = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 529 | (struct pldm_vendor_defined_descriptor_title_data *)(data); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 530 | if (!is_string_type_valid( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 531 | entry->vendor_defined_descriptor_title_str_type) || |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 532 | (entry->vendor_defined_descriptor_title_str_len == 0)) { |
| 533 | return PLDM_ERROR_INVALID_DATA; |
| 534 | } |
| 535 | |
| 536 | // Assuming atleast 1 byte of VendorDefinedDescriptorData |
| 537 | if (length < (sizeof(struct pldm_vendor_defined_descriptor_title_data) + |
| 538 | entry->vendor_defined_descriptor_title_str_len)) { |
| 539 | return PLDM_ERROR_INVALID_LENGTH; |
| 540 | } |
| 541 | |
| 542 | *descriptor_title_str_type = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 543 | entry->vendor_defined_descriptor_title_str_type; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 544 | descriptor_title_str->ptr = entry->vendor_defined_descriptor_title_str; |
| 545 | descriptor_title_str->length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 546 | entry->vendor_defined_descriptor_title_str_len; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 547 | |
| 548 | descriptor_data->ptr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 549 | descriptor_title_str->ptr + descriptor_title_str->length; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 550 | descriptor_data->length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 551 | length - |
| 552 | sizeof(entry->vendor_defined_descriptor_title_str_type) - |
| 553 | sizeof(entry->vendor_defined_descriptor_title_str_len) - |
| 554 | descriptor_title_str->length; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 555 | |
| 556 | return PLDM_SUCCESS; |
| 557 | } |
| 558 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 559 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 560 | int decode_pldm_comp_image_info( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 561 | const uint8_t *data, size_t length, |
| 562 | struct pldm_component_image_information *pldm_comp_image_info, |
| 563 | struct variable_field *comp_version_str) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 564 | { |
| 565 | if (data == NULL || pldm_comp_image_info == NULL || |
| 566 | comp_version_str == NULL) { |
| 567 | return PLDM_ERROR_INVALID_DATA; |
| 568 | } |
| 569 | |
| 570 | if (length < sizeof(struct pldm_component_image_information)) { |
| 571 | return PLDM_ERROR_INVALID_LENGTH; |
| 572 | } |
| 573 | |
| 574 | struct pldm_component_image_information *data_header = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 575 | (struct pldm_component_image_information *)(data); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 576 | |
| 577 | if (!is_string_type_valid(data_header->comp_version_string_type) || |
| 578 | (data_header->comp_version_string_length == 0)) { |
| 579 | return PLDM_ERROR_INVALID_DATA; |
| 580 | } |
| 581 | |
| 582 | if (length < sizeof(struct pldm_component_image_information) + |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 583 | data_header->comp_version_string_length) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 584 | return PLDM_ERROR_INVALID_LENGTH; |
| 585 | } |
| 586 | |
| 587 | pldm_comp_image_info->comp_classification = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 588 | le16toh(data_header->comp_classification); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 589 | pldm_comp_image_info->comp_identifier = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 590 | le16toh(data_header->comp_identifier); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 591 | pldm_comp_image_info->comp_comparison_stamp = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 592 | le32toh(data_header->comp_comparison_stamp); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 593 | pldm_comp_image_info->comp_options.value = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 594 | le16toh(data_header->comp_options.value); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 595 | pldm_comp_image_info->requested_comp_activation_method.value = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 596 | le16toh(data_header->requested_comp_activation_method.value); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 597 | pldm_comp_image_info->comp_location_offset = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 598 | le32toh(data_header->comp_location_offset); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 599 | pldm_comp_image_info->comp_size = le32toh(data_header->comp_size); |
| 600 | pldm_comp_image_info->comp_version_string_type = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 601 | data_header->comp_version_string_type; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 602 | pldm_comp_image_info->comp_version_string_length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 603 | data_header->comp_version_string_length; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 604 | |
| 605 | if ((pldm_comp_image_info->comp_options.bits.bit1 == false && |
| 606 | pldm_comp_image_info->comp_comparison_stamp != |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 607 | PLDM_FWUP_INVALID_COMPONENT_COMPARISON_TIMESTAMP)) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 608 | return PLDM_ERROR_INVALID_DATA; |
| 609 | } |
| 610 | |
| 611 | if (pldm_comp_image_info->comp_location_offset == 0 || |
| 612 | pldm_comp_image_info->comp_size == 0) { |
| 613 | return PLDM_ERROR_INVALID_DATA; |
| 614 | } |
| 615 | |
| 616 | comp_version_str->ptr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 617 | data + sizeof(struct pldm_component_image_information); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 618 | comp_version_str->length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 619 | pldm_comp_image_info->comp_version_string_length; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 620 | |
| 621 | return PLDM_SUCCESS; |
| 622 | } |
| 623 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 624 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 625 | int encode_query_device_identifiers_req(uint8_t instance_id, |
| 626 | size_t payload_length, |
| 627 | struct pldm_msg *msg) |
| 628 | { |
| 629 | if (msg == NULL) { |
| 630 | return PLDM_ERROR_INVALID_DATA; |
| 631 | } |
| 632 | |
| 633 | if (payload_length != PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES) { |
| 634 | return PLDM_ERROR_INVALID_LENGTH; |
| 635 | } |
| 636 | |
| 637 | return encode_pldm_header_only(PLDM_REQUEST, instance_id, PLDM_FWUP, |
| 638 | PLDM_QUERY_DEVICE_IDENTIFIERS, msg); |
| 639 | } |
| 640 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 641 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 642 | int decode_query_device_identifiers_resp(const struct pldm_msg *msg, |
| 643 | size_t payload_length, |
| 644 | uint8_t *completion_code, |
| 645 | uint32_t *device_identifiers_len, |
| 646 | uint8_t *descriptor_count, |
| 647 | uint8_t **descriptor_data) |
| 648 | { |
| 649 | if (msg == NULL || completion_code == NULL || |
| 650 | device_identifiers_len == NULL || descriptor_count == NULL || |
| 651 | descriptor_data == NULL) { |
| 652 | return PLDM_ERROR_INVALID_DATA; |
| 653 | } |
| 654 | |
| 655 | *completion_code = msg->payload[0]; |
| 656 | if (PLDM_SUCCESS != *completion_code) { |
| 657 | return PLDM_SUCCESS; |
| 658 | } |
| 659 | |
| 660 | if (payload_length < |
| 661 | sizeof(struct pldm_query_device_identifiers_resp)) { |
| 662 | return PLDM_ERROR_INVALID_LENGTH; |
| 663 | } |
| 664 | |
| 665 | struct pldm_query_device_identifiers_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 666 | (struct pldm_query_device_identifiers_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 667 | *device_identifiers_len = le32toh(response->device_identifiers_len); |
| 668 | |
| 669 | if (*device_identifiers_len < PLDM_FWUP_DEVICE_DESCRIPTOR_MIN_LEN) { |
| 670 | return PLDM_ERROR_INVALID_LENGTH; |
| 671 | } |
| 672 | |
| 673 | if (payload_length != |
| 674 | sizeof(struct pldm_query_device_identifiers_resp) + |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 675 | *device_identifiers_len) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 676 | return PLDM_ERROR_INVALID_LENGTH; |
| 677 | } |
| 678 | *descriptor_count = response->descriptor_count; |
| 679 | |
| 680 | if (*descriptor_count == 0) { |
| 681 | return PLDM_ERROR_INVALID_DATA; |
| 682 | } |
| 683 | *descriptor_data = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 684 | (uint8_t *)(msg->payload + |
| 685 | sizeof(struct pldm_query_device_identifiers_resp)); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 686 | return PLDM_SUCCESS; |
| 687 | } |
| 688 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 689 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 690 | int encode_get_firmware_parameters_req(uint8_t instance_id, |
| 691 | size_t payload_length, |
| 692 | struct pldm_msg *msg) |
| 693 | { |
| 694 | if (msg == NULL) { |
| 695 | return PLDM_ERROR_INVALID_DATA; |
| 696 | } |
| 697 | |
| 698 | if (payload_length != PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES) { |
| 699 | return PLDM_ERROR_INVALID_LENGTH; |
| 700 | } |
| 701 | |
| 702 | return encode_pldm_header_only(PLDM_REQUEST, instance_id, PLDM_FWUP, |
| 703 | PLDM_GET_FIRMWARE_PARAMETERS, msg); |
| 704 | } |
| 705 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 706 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 707 | int decode_get_firmware_parameters_resp( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 708 | const struct pldm_msg *msg, size_t payload_length, |
| 709 | struct pldm_get_firmware_parameters_resp *resp_data, |
| 710 | struct variable_field *active_comp_image_set_ver_str, |
| 711 | struct variable_field *pending_comp_image_set_ver_str, |
| 712 | struct variable_field *comp_parameter_table) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 713 | { |
| 714 | if (msg == NULL || resp_data == NULL || |
| 715 | active_comp_image_set_ver_str == NULL || |
| 716 | pending_comp_image_set_ver_str == NULL || |
| 717 | comp_parameter_table == NULL || !payload_length) { |
| 718 | return PLDM_ERROR_INVALID_DATA; |
| 719 | } |
| 720 | |
| 721 | resp_data->completion_code = msg->payload[0]; |
| 722 | if (PLDM_SUCCESS != resp_data->completion_code) { |
| 723 | return PLDM_SUCCESS; |
| 724 | } |
| 725 | |
| 726 | if (payload_length < sizeof(struct pldm_get_firmware_parameters_resp)) { |
| 727 | return PLDM_ERROR_INVALID_LENGTH; |
| 728 | } |
| 729 | |
| 730 | struct pldm_get_firmware_parameters_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 731 | (struct pldm_get_firmware_parameters_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 732 | |
| 733 | if (!is_string_type_valid( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 734 | response->active_comp_image_set_ver_str_type) || |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 735 | (response->active_comp_image_set_ver_str_len == 0)) { |
| 736 | return PLDM_ERROR_INVALID_DATA; |
| 737 | } |
| 738 | |
| 739 | if (response->pending_comp_image_set_ver_str_len == 0) { |
| 740 | if (response->pending_comp_image_set_ver_str_type != |
| 741 | PLDM_STR_TYPE_UNKNOWN) { |
| 742 | return PLDM_ERROR_INVALID_DATA; |
| 743 | } |
| 744 | } else { |
| 745 | if (!is_string_type_valid( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 746 | response->pending_comp_image_set_ver_str_type)) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 747 | return PLDM_ERROR_INVALID_DATA; |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | size_t partial_response_length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 752 | sizeof(struct pldm_get_firmware_parameters_resp) + |
| 753 | response->active_comp_image_set_ver_str_len + |
| 754 | response->pending_comp_image_set_ver_str_len; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 755 | |
| 756 | if (payload_length < partial_response_length) { |
| 757 | return PLDM_ERROR_INVALID_LENGTH; |
| 758 | } |
| 759 | |
| 760 | resp_data->capabilities_during_update.value = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 761 | le32toh(response->capabilities_during_update.value); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 762 | resp_data->comp_count = le16toh(response->comp_count); |
| 763 | resp_data->active_comp_image_set_ver_str_type = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 764 | response->active_comp_image_set_ver_str_type; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 765 | resp_data->active_comp_image_set_ver_str_len = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 766 | response->active_comp_image_set_ver_str_len; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 767 | resp_data->pending_comp_image_set_ver_str_type = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 768 | response->pending_comp_image_set_ver_str_type; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 769 | resp_data->pending_comp_image_set_ver_str_len = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 770 | response->pending_comp_image_set_ver_str_len; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 771 | |
| 772 | active_comp_image_set_ver_str->ptr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 773 | msg->payload + sizeof(struct pldm_get_firmware_parameters_resp); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 774 | active_comp_image_set_ver_str->length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 775 | resp_data->active_comp_image_set_ver_str_len; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 776 | |
| 777 | if (resp_data->pending_comp_image_set_ver_str_len != 0) { |
| 778 | pending_comp_image_set_ver_str->ptr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 779 | msg->payload + |
| 780 | sizeof(struct pldm_get_firmware_parameters_resp) + |
| 781 | resp_data->active_comp_image_set_ver_str_len; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 782 | pending_comp_image_set_ver_str->length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 783 | resp_data->pending_comp_image_set_ver_str_len; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 784 | } else { |
| 785 | pending_comp_image_set_ver_str->ptr = NULL; |
| 786 | pending_comp_image_set_ver_str->length = 0; |
| 787 | } |
| 788 | |
| 789 | if (payload_length > partial_response_length && resp_data->comp_count) { |
| 790 | comp_parameter_table->ptr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 791 | msg->payload + |
| 792 | sizeof(struct pldm_get_firmware_parameters_resp) + |
| 793 | resp_data->active_comp_image_set_ver_str_len + |
| 794 | resp_data->pending_comp_image_set_ver_str_len; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 795 | comp_parameter_table->length = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 796 | payload_length - partial_response_length; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 797 | } else { |
| 798 | comp_parameter_table->ptr = NULL; |
| 799 | comp_parameter_table->length = 0; |
| 800 | } |
| 801 | |
| 802 | return PLDM_SUCCESS; |
| 803 | } |
| 804 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 805 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 806 | int decode_get_firmware_parameters_resp_comp_entry( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 807 | const uint8_t *data, size_t length, |
| 808 | struct pldm_component_parameter_entry *component_data, |
| 809 | struct variable_field *active_comp_ver_str, |
| 810 | struct variable_field *pending_comp_ver_str) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 811 | { |
| 812 | if (data == NULL || component_data == NULL || |
| 813 | active_comp_ver_str == NULL || pending_comp_ver_str == NULL) { |
| 814 | return PLDM_ERROR_INVALID_DATA; |
| 815 | } |
| 816 | |
| 817 | if (length < sizeof(struct pldm_component_parameter_entry)) { |
| 818 | return PLDM_ERROR_INVALID_LENGTH; |
| 819 | } |
| 820 | |
| 821 | struct pldm_component_parameter_entry *entry = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 822 | (struct pldm_component_parameter_entry *)(data); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 823 | |
| 824 | size_t entry_length = sizeof(struct pldm_component_parameter_entry) + |
| 825 | entry->active_comp_ver_str_len + |
| 826 | entry->pending_comp_ver_str_len; |
| 827 | |
| 828 | if (length < entry_length) { |
| 829 | return PLDM_ERROR_INVALID_LENGTH; |
| 830 | } |
| 831 | |
| 832 | component_data->comp_classification = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 833 | le16toh(entry->comp_classification); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 834 | component_data->comp_identifier = le16toh(entry->comp_identifier); |
| 835 | component_data->comp_classification_index = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 836 | entry->comp_classification_index; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 837 | component_data->active_comp_comparison_stamp = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 838 | le32toh(entry->active_comp_comparison_stamp); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 839 | component_data->active_comp_ver_str_type = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 840 | entry->active_comp_ver_str_type; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 841 | component_data->active_comp_ver_str_len = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 842 | entry->active_comp_ver_str_len; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 843 | memcpy(component_data->active_comp_release_date, |
| 844 | entry->active_comp_release_date, |
| 845 | sizeof(entry->active_comp_release_date)); |
| 846 | component_data->pending_comp_comparison_stamp = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 847 | le32toh(entry->pending_comp_comparison_stamp); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 848 | component_data->pending_comp_ver_str_type = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 849 | entry->pending_comp_ver_str_type; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 850 | component_data->pending_comp_ver_str_len = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 851 | entry->pending_comp_ver_str_len; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 852 | memcpy(component_data->pending_comp_release_date, |
| 853 | entry->pending_comp_release_date, |
| 854 | sizeof(entry->pending_comp_release_date)); |
| 855 | component_data->comp_activation_methods.value = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 856 | le16toh(entry->comp_activation_methods.value); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 857 | component_data->capabilities_during_update.value = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 858 | le32toh(entry->capabilities_during_update.value); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 859 | |
| 860 | if (entry->active_comp_ver_str_len != 0) { |
| 861 | active_comp_ver_str->ptr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 862 | data + sizeof(struct pldm_component_parameter_entry); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 863 | active_comp_ver_str->length = entry->active_comp_ver_str_len; |
| 864 | } else { |
| 865 | active_comp_ver_str->ptr = NULL; |
| 866 | active_comp_ver_str->length = 0; |
| 867 | } |
| 868 | |
| 869 | if (entry->pending_comp_ver_str_len != 0) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 870 | pending_comp_ver_str->ptr = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 871 | data + sizeof(struct pldm_component_parameter_entry) + |
| 872 | entry->active_comp_ver_str_len; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 873 | pending_comp_ver_str->length = entry->pending_comp_ver_str_len; |
| 874 | } else { |
| 875 | pending_comp_ver_str->ptr = NULL; |
| 876 | pending_comp_ver_str->length = 0; |
| 877 | } |
| 878 | return PLDM_SUCCESS; |
| 879 | } |
| 880 | |
Chris Wang | 4c1f2c7 | 2024-03-21 17:09:44 +0800 | [diff] [blame] | 881 | LIBPLDM_ABI_TESTING |
| 882 | int encode_query_downstream_devices_req(uint8_t instance_id, |
| 883 | struct pldm_msg *msg) |
| 884 | { |
| 885 | if (msg == NULL) { |
| 886 | return PLDM_ERROR_INVALID_DATA; |
| 887 | } |
| 888 | |
| 889 | return encode_pldm_header_only(PLDM_REQUEST, instance_id, PLDM_FWUP, |
| 890 | PLDM_QUERY_DOWNSTREAM_DEVICES, msg); |
| 891 | } |
| 892 | |
| 893 | LIBPLDM_ABI_TESTING |
| 894 | int decode_query_downstream_devices_resp( |
| 895 | const struct pldm_msg *msg, size_t payload_length, |
| 896 | struct pldm_query_downstream_devices_resp *resp_data) |
| 897 | { |
| 898 | struct pldm_msgbuf _buf; |
| 899 | struct pldm_msgbuf *buf = &_buf; |
| 900 | int rc; |
| 901 | |
| 902 | if (msg == NULL || resp_data == NULL || !payload_length) { |
| 903 | return PLDM_ERROR_INVALID_DATA; |
| 904 | } |
| 905 | |
| 906 | rc = pldm_msgbuf_init(buf, PLDM_OPTIONAL_COMMAND_RESP_MIN_LEN, |
| 907 | msg->payload, payload_length); |
| 908 | if (rc) { |
| 909 | return rc; |
| 910 | } |
| 911 | |
| 912 | rc = pldm_msgbuf_extract(buf, resp_data->completion_code); |
| 913 | if (rc) { |
| 914 | return rc; |
| 915 | } |
| 916 | if (PLDM_SUCCESS != resp_data->completion_code) { |
| 917 | // Return the CC directly without decoding the rest of the payload |
| 918 | return PLDM_SUCCESS; |
| 919 | } |
| 920 | |
| 921 | if (payload_length < PLDM_QUERY_DOWNSTREAM_DEVICES_RESP_BYTES) { |
| 922 | return PLDM_ERROR_INVALID_LENGTH; |
| 923 | } |
| 924 | |
| 925 | rc = pldm_msgbuf_extract(buf, |
| 926 | resp_data->downstream_device_update_supported); |
| 927 | if (rc) { |
| 928 | return rc; |
| 929 | } |
| 930 | |
| 931 | if (!is_downstream_device_update_support_valid( |
| 932 | resp_data->downstream_device_update_supported)) { |
| 933 | return PLDM_ERROR_INVALID_DATA; |
| 934 | } |
| 935 | |
| 936 | pldm_msgbuf_extract(buf, resp_data->number_of_downstream_devices); |
| 937 | pldm_msgbuf_extract(buf, resp_data->max_number_of_downstream_devices); |
| 938 | pldm_msgbuf_extract(buf, resp_data->capabilities.value); |
| 939 | |
| 940 | return pldm_msgbuf_destroy_consumed(buf); |
| 941 | } |
| 942 | |
Chris Wang | 458475a | 2024-03-26 17:59:19 +0800 | [diff] [blame] | 943 | LIBPLDM_ABI_TESTING |
| 944 | int encode_query_downstream_identifiers_req( |
| 945 | uint8_t instance_id, uint32_t data_transfer_handle, |
| 946 | enum transfer_op_flag transfer_operation_flag, struct pldm_msg *msg, |
| 947 | size_t payload_length) |
| 948 | { |
| 949 | struct pldm_msgbuf _buf; |
| 950 | struct pldm_msgbuf *buf = &_buf; |
| 951 | int rc; |
| 952 | |
| 953 | if (msg == NULL) { |
| 954 | return PLDM_ERROR_INVALID_DATA; |
| 955 | } |
| 956 | |
| 957 | if (!is_transfer_operation_flag_valid(transfer_operation_flag)) { |
| 958 | return PLDM_INVALID_TRANSFER_OPERATION_FLAG; |
| 959 | } |
| 960 | |
| 961 | struct pldm_header_info header = { 0 }; |
| 962 | header.instance = instance_id; |
| 963 | header.msg_type = PLDM_REQUEST; |
| 964 | header.pldm_type = PLDM_FWUP; |
| 965 | header.command = PLDM_QUERY_DOWNSTREAM_IDENTIFIERS; |
| 966 | rc = pack_pldm_header(&header, &(msg->hdr)); |
| 967 | if (rc) { |
| 968 | return rc; |
| 969 | } |
| 970 | |
| 971 | rc = pldm_msgbuf_init(buf, PLDM_QUERY_DOWNSTREAM_IDENTIFIERS_REQ_BYTES, |
| 972 | msg->payload, payload_length); |
| 973 | if (rc) { |
| 974 | return rc; |
| 975 | } |
| 976 | |
| 977 | pldm_msgbuf_insert(buf, data_transfer_handle); |
| 978 | // Data correctness has been verified, cast it to 1-byte data directly. |
| 979 | pldm_msgbuf_insert(buf, (uint8_t)transfer_operation_flag); |
| 980 | |
| 981 | return pldm_msgbuf_destroy(buf); |
| 982 | } |
| 983 | |
| 984 | LIBPLDM_ABI_TESTING |
| 985 | int decode_query_downstream_identifiers_resp( |
| 986 | const struct pldm_msg *msg, size_t payload_length, |
| 987 | struct pldm_query_downstream_identifiers_resp *resp_data, |
| 988 | struct variable_field *downstream_devices) |
| 989 | { |
| 990 | struct pldm_msgbuf _buf; |
| 991 | struct pldm_msgbuf *buf = &_buf; |
| 992 | int rc = PLDM_ERROR; |
| 993 | |
| 994 | if (msg == NULL || resp_data == NULL || downstream_devices == NULL || |
| 995 | !payload_length) { |
| 996 | return PLDM_ERROR_INVALID_DATA; |
| 997 | } |
| 998 | |
| 999 | rc = pldm_msgbuf_init(buf, PLDM_OPTIONAL_COMMAND_RESP_MIN_LEN, |
| 1000 | msg->payload, payload_length); |
| 1001 | if (rc) { |
| 1002 | return rc; |
| 1003 | } |
| 1004 | |
| 1005 | rc = pldm_msgbuf_extract(buf, resp_data->completion_code); |
| 1006 | if (rc) { |
| 1007 | return rc; |
| 1008 | } |
| 1009 | if (PLDM_SUCCESS != resp_data->completion_code) { |
| 1010 | return PLDM_SUCCESS; |
| 1011 | } |
| 1012 | |
| 1013 | if (payload_length < PLDM_QUERY_DOWNSTREAM_IDENTIFIERS_RESP_MIN_LEN) { |
| 1014 | return PLDM_ERROR_INVALID_LENGTH; |
| 1015 | } |
| 1016 | |
| 1017 | pldm_msgbuf_extract(buf, resp_data->next_data_transfer_handle); |
| 1018 | pldm_msgbuf_extract(buf, resp_data->transfer_flag); |
| 1019 | |
| 1020 | rc = pldm_msgbuf_extract(buf, resp_data->downstream_devices_length); |
| 1021 | if (rc) { |
| 1022 | return rc; |
| 1023 | } |
| 1024 | |
| 1025 | pldm_msgbuf_extract(buf, resp_data->number_of_downstream_devices); |
| 1026 | rc = pldm_msgbuf_span_required(buf, |
| 1027 | resp_data->downstream_devices_length, |
| 1028 | (void **)&downstream_devices->ptr); |
| 1029 | if (rc) { |
| 1030 | return rc; |
| 1031 | } |
| 1032 | downstream_devices->length = resp_data->downstream_devices_length; |
| 1033 | |
| 1034 | return pldm_msgbuf_destroy(buf); |
| 1035 | } |
| 1036 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1037 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1038 | int encode_request_update_req(uint8_t instance_id, uint32_t max_transfer_size, |
| 1039 | uint16_t num_of_comp, |
| 1040 | uint8_t max_outstanding_transfer_req, |
| 1041 | uint16_t pkg_data_len, |
| 1042 | uint8_t comp_image_set_ver_str_type, |
| 1043 | uint8_t comp_image_set_ver_str_len, |
| 1044 | const struct variable_field *comp_img_set_ver_str, |
| 1045 | struct pldm_msg *msg, size_t payload_length) |
| 1046 | { |
| 1047 | if (comp_img_set_ver_str == NULL || comp_img_set_ver_str->ptr == NULL || |
| 1048 | msg == NULL) { |
| 1049 | return PLDM_ERROR_INVALID_DATA; |
| 1050 | } |
| 1051 | |
| 1052 | if (payload_length != sizeof(struct pldm_request_update_req) + |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1053 | comp_img_set_ver_str->length) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1054 | return PLDM_ERROR_INVALID_LENGTH; |
| 1055 | } |
| 1056 | |
| 1057 | if ((comp_image_set_ver_str_len == 0) || |
| 1058 | (comp_image_set_ver_str_len != comp_img_set_ver_str->length)) { |
| 1059 | return PLDM_ERROR_INVALID_DATA; |
| 1060 | } |
| 1061 | |
| 1062 | if ((max_transfer_size < PLDM_FWUP_BASELINE_TRANSFER_SIZE) || |
| 1063 | (max_outstanding_transfer_req < PLDM_FWUP_MIN_OUTSTANDING_REQ)) { |
| 1064 | return PLDM_ERROR_INVALID_DATA; |
| 1065 | } |
| 1066 | |
| 1067 | if (!is_string_type_valid(comp_image_set_ver_str_type)) { |
| 1068 | return PLDM_ERROR_INVALID_DATA; |
| 1069 | } |
| 1070 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1071 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1072 | header.instance = instance_id; |
| 1073 | header.msg_type = PLDM_REQUEST; |
| 1074 | header.pldm_type = PLDM_FWUP; |
| 1075 | header.command = PLDM_REQUEST_UPDATE; |
| 1076 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1077 | if (rc) { |
| 1078 | return rc; |
| 1079 | } |
| 1080 | |
| 1081 | struct pldm_request_update_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1082 | (struct pldm_request_update_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1083 | |
| 1084 | request->max_transfer_size = htole32(max_transfer_size); |
| 1085 | request->num_of_comp = htole16(num_of_comp); |
| 1086 | request->max_outstanding_transfer_req = max_outstanding_transfer_req; |
| 1087 | request->pkg_data_len = htole16(pkg_data_len); |
| 1088 | request->comp_image_set_ver_str_type = comp_image_set_ver_str_type; |
| 1089 | request->comp_image_set_ver_str_len = comp_image_set_ver_str_len; |
| 1090 | |
| 1091 | memcpy(msg->payload + sizeof(struct pldm_request_update_req), |
| 1092 | comp_img_set_ver_str->ptr, comp_img_set_ver_str->length); |
| 1093 | |
| 1094 | return PLDM_SUCCESS; |
| 1095 | } |
| 1096 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1097 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1098 | int decode_request_update_resp(const struct pldm_msg *msg, |
| 1099 | size_t payload_length, uint8_t *completion_code, |
| 1100 | uint16_t *fd_meta_data_len, |
| 1101 | uint8_t *fd_will_send_pkg_data) |
| 1102 | { |
| 1103 | if (msg == NULL || completion_code == NULL || |
| 1104 | fd_meta_data_len == NULL || fd_will_send_pkg_data == NULL || |
| 1105 | !payload_length) { |
| 1106 | return PLDM_ERROR_INVALID_DATA; |
| 1107 | } |
| 1108 | |
| 1109 | *completion_code = msg->payload[0]; |
| 1110 | if (*completion_code != PLDM_SUCCESS) { |
| 1111 | return PLDM_SUCCESS; |
| 1112 | } |
| 1113 | |
| 1114 | if (payload_length != sizeof(struct pldm_request_update_resp)) { |
| 1115 | return PLDM_ERROR_INVALID_LENGTH; |
| 1116 | } |
| 1117 | |
| 1118 | struct pldm_request_update_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1119 | (struct pldm_request_update_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1120 | |
| 1121 | *fd_meta_data_len = le16toh(response->fd_meta_data_len); |
| 1122 | *fd_will_send_pkg_data = response->fd_will_send_pkg_data; |
| 1123 | |
| 1124 | return PLDM_SUCCESS; |
| 1125 | } |
| 1126 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1127 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1128 | int encode_pass_component_table_req(uint8_t instance_id, uint8_t transfer_flag, |
| 1129 | uint16_t comp_classification, |
| 1130 | uint16_t comp_identifier, |
| 1131 | uint8_t comp_classification_index, |
| 1132 | uint32_t comp_comparison_stamp, |
| 1133 | uint8_t comp_ver_str_type, |
| 1134 | uint8_t comp_ver_str_len, |
| 1135 | const struct variable_field *comp_ver_str, |
| 1136 | struct pldm_msg *msg, size_t payload_length) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1137 | { |
| 1138 | if (comp_ver_str == NULL || comp_ver_str->ptr == NULL || msg == NULL) { |
| 1139 | return PLDM_ERROR_INVALID_DATA; |
| 1140 | } |
| 1141 | |
| 1142 | if (payload_length != sizeof(struct pldm_pass_component_table_req) + |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1143 | comp_ver_str->length) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1144 | return PLDM_ERROR_INVALID_LENGTH; |
| 1145 | } |
| 1146 | |
| 1147 | if ((comp_ver_str_len == 0) || |
| 1148 | (comp_ver_str_len != comp_ver_str->length)) { |
| 1149 | return PLDM_ERROR_INVALID_DATA; |
| 1150 | } |
| 1151 | |
| 1152 | if (!is_transfer_flag_valid(transfer_flag)) { |
| 1153 | return PLDM_INVALID_TRANSFER_OPERATION_FLAG; |
| 1154 | } |
| 1155 | |
| 1156 | if (!is_string_type_valid(comp_ver_str_type)) { |
| 1157 | return PLDM_ERROR_INVALID_DATA; |
| 1158 | } |
| 1159 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1160 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1161 | header.instance = instance_id; |
| 1162 | header.msg_type = PLDM_REQUEST; |
| 1163 | header.pldm_type = PLDM_FWUP; |
| 1164 | header.command = PLDM_PASS_COMPONENT_TABLE; |
| 1165 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1166 | if (rc) { |
| 1167 | return rc; |
| 1168 | } |
| 1169 | |
| 1170 | struct pldm_pass_component_table_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1171 | (struct pldm_pass_component_table_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1172 | |
| 1173 | request->transfer_flag = transfer_flag; |
| 1174 | request->comp_classification = htole16(comp_classification); |
| 1175 | request->comp_identifier = htole16(comp_identifier); |
| 1176 | request->comp_classification_index = comp_classification_index; |
| 1177 | request->comp_comparison_stamp = htole32(comp_comparison_stamp); |
| 1178 | request->comp_ver_str_type = comp_ver_str_type; |
| 1179 | request->comp_ver_str_len = comp_ver_str_len; |
| 1180 | |
| 1181 | memcpy(msg->payload + sizeof(struct pldm_pass_component_table_req), |
| 1182 | comp_ver_str->ptr, comp_ver_str->length); |
| 1183 | |
| 1184 | return PLDM_SUCCESS; |
| 1185 | } |
| 1186 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1187 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1188 | int decode_pass_component_table_resp(const struct pldm_msg *msg, |
| 1189 | const size_t payload_length, |
| 1190 | uint8_t *completion_code, |
| 1191 | uint8_t *comp_resp, |
| 1192 | uint8_t *comp_resp_code) |
| 1193 | { |
| 1194 | if (msg == NULL || completion_code == NULL || comp_resp == NULL || |
| 1195 | comp_resp_code == NULL || !payload_length) { |
| 1196 | return PLDM_ERROR_INVALID_DATA; |
| 1197 | } |
| 1198 | |
| 1199 | *completion_code = msg->payload[0]; |
| 1200 | if (*completion_code != PLDM_SUCCESS) { |
| 1201 | return PLDM_SUCCESS; |
| 1202 | } |
| 1203 | |
| 1204 | if (payload_length != sizeof(struct pldm_pass_component_table_resp)) { |
| 1205 | return PLDM_ERROR_INVALID_LENGTH; |
| 1206 | } |
| 1207 | |
| 1208 | struct pldm_pass_component_table_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1209 | (struct pldm_pass_component_table_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1210 | |
| 1211 | if (!is_comp_resp_valid(response->comp_resp)) { |
| 1212 | return PLDM_ERROR_INVALID_DATA; |
| 1213 | } |
| 1214 | |
| 1215 | if (!is_comp_resp_code_valid(response->comp_resp_code)) { |
| 1216 | return PLDM_ERROR_INVALID_DATA; |
| 1217 | } |
| 1218 | |
| 1219 | *comp_resp = response->comp_resp; |
| 1220 | *comp_resp_code = response->comp_resp_code; |
| 1221 | |
| 1222 | return PLDM_SUCCESS; |
| 1223 | } |
| 1224 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1225 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1226 | int encode_update_component_req( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1227 | uint8_t instance_id, uint16_t comp_classification, |
| 1228 | uint16_t comp_identifier, uint8_t comp_classification_index, |
| 1229 | uint32_t comp_comparison_stamp, uint32_t comp_image_size, |
| 1230 | bitfield32_t update_option_flags, uint8_t comp_ver_str_type, |
| 1231 | uint8_t comp_ver_str_len, const struct variable_field *comp_ver_str, |
| 1232 | struct pldm_msg *msg, size_t payload_length) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1233 | { |
| 1234 | if (comp_ver_str == NULL || comp_ver_str->ptr == NULL || msg == NULL) { |
| 1235 | return PLDM_ERROR_INVALID_DATA; |
| 1236 | } |
| 1237 | |
| 1238 | if (payload_length != |
| 1239 | sizeof(struct pldm_update_component_req) + comp_ver_str->length) { |
| 1240 | return PLDM_ERROR_INVALID_LENGTH; |
| 1241 | } |
| 1242 | |
| 1243 | if (!comp_image_size) { |
| 1244 | return PLDM_ERROR_INVALID_DATA; |
| 1245 | } |
| 1246 | |
| 1247 | if ((comp_ver_str_len == 0) || |
| 1248 | (comp_ver_str_len != comp_ver_str->length)) { |
| 1249 | return PLDM_ERROR_INVALID_DATA; |
| 1250 | } |
| 1251 | |
| 1252 | if (!is_string_type_valid(comp_ver_str_type)) { |
| 1253 | return PLDM_ERROR_INVALID_DATA; |
| 1254 | } |
| 1255 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1256 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1257 | header.instance = instance_id; |
| 1258 | header.msg_type = PLDM_REQUEST; |
| 1259 | header.pldm_type = PLDM_FWUP; |
| 1260 | header.command = PLDM_UPDATE_COMPONENT; |
| 1261 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1262 | if (rc) { |
| 1263 | return rc; |
| 1264 | } |
| 1265 | |
| 1266 | struct pldm_update_component_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1267 | (struct pldm_update_component_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1268 | |
| 1269 | request->comp_classification = htole16(comp_classification); |
| 1270 | request->comp_identifier = htole16(comp_identifier); |
| 1271 | request->comp_classification_index = comp_classification_index; |
| 1272 | request->comp_comparison_stamp = htole32(comp_comparison_stamp); |
| 1273 | request->comp_image_size = htole32(comp_image_size); |
| 1274 | request->update_option_flags.value = htole32(update_option_flags.value); |
| 1275 | request->comp_ver_str_type = comp_ver_str_type; |
| 1276 | request->comp_ver_str_len = comp_ver_str_len; |
| 1277 | |
| 1278 | memcpy(msg->payload + sizeof(struct pldm_update_component_req), |
| 1279 | comp_ver_str->ptr, comp_ver_str->length); |
| 1280 | |
| 1281 | return PLDM_SUCCESS; |
| 1282 | } |
| 1283 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1284 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1285 | int decode_update_component_resp(const struct pldm_msg *msg, |
| 1286 | size_t payload_length, |
| 1287 | uint8_t *completion_code, |
| 1288 | uint8_t *comp_compatibility_resp, |
| 1289 | uint8_t *comp_compatibility_resp_code, |
| 1290 | bitfield32_t *update_option_flags_enabled, |
| 1291 | uint16_t *time_before_req_fw_data) |
| 1292 | { |
| 1293 | if (msg == NULL || completion_code == NULL || |
| 1294 | comp_compatibility_resp == NULL || |
| 1295 | comp_compatibility_resp_code == NULL || |
| 1296 | update_option_flags_enabled == NULL || |
| 1297 | time_before_req_fw_data == NULL || !payload_length) { |
| 1298 | return PLDM_ERROR_INVALID_DATA; |
| 1299 | } |
| 1300 | |
| 1301 | *completion_code = msg->payload[0]; |
| 1302 | if (*completion_code != PLDM_SUCCESS) { |
| 1303 | return PLDM_SUCCESS; |
| 1304 | } |
| 1305 | |
| 1306 | if (payload_length != sizeof(struct pldm_update_component_resp)) { |
| 1307 | return PLDM_ERROR_INVALID_LENGTH; |
| 1308 | } |
| 1309 | |
| 1310 | struct pldm_update_component_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1311 | (struct pldm_update_component_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1312 | |
| 1313 | if (!is_comp_compatibility_resp_valid( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1314 | response->comp_compatibility_resp)) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1315 | return PLDM_ERROR_INVALID_DATA; |
| 1316 | } |
| 1317 | |
| 1318 | if (!is_comp_compatibility_resp_code_valid( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1319 | response->comp_compatibility_resp_code)) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1320 | return PLDM_ERROR_INVALID_DATA; |
| 1321 | } |
| 1322 | |
| 1323 | *comp_compatibility_resp = response->comp_compatibility_resp; |
| 1324 | *comp_compatibility_resp_code = response->comp_compatibility_resp_code; |
| 1325 | update_option_flags_enabled->value = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1326 | le32toh(response->update_option_flags_enabled.value); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1327 | *time_before_req_fw_data = le16toh(response->time_before_req_fw_data); |
| 1328 | |
| 1329 | return PLDM_SUCCESS; |
| 1330 | } |
| 1331 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1332 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1333 | int decode_request_firmware_data_req(const struct pldm_msg *msg, |
| 1334 | size_t payload_length, uint32_t *offset, |
| 1335 | uint32_t *length) |
| 1336 | { |
| 1337 | if (msg == NULL || offset == NULL || length == NULL) { |
| 1338 | return PLDM_ERROR_INVALID_DATA; |
| 1339 | } |
| 1340 | if (payload_length != sizeof(struct pldm_request_firmware_data_req)) { |
| 1341 | return PLDM_ERROR_INVALID_LENGTH; |
| 1342 | } |
| 1343 | struct pldm_request_firmware_data_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1344 | (struct pldm_request_firmware_data_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1345 | *offset = le32toh(request->offset); |
| 1346 | *length = le32toh(request->length); |
| 1347 | |
| 1348 | if (*length < PLDM_FWUP_BASELINE_TRANSFER_SIZE) { |
| 1349 | return PLDM_FWUP_INVALID_TRANSFER_LENGTH; |
| 1350 | } |
| 1351 | |
| 1352 | return PLDM_SUCCESS; |
| 1353 | } |
| 1354 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1355 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1356 | int encode_request_firmware_data_resp(uint8_t instance_id, |
| 1357 | uint8_t completion_code, |
| 1358 | struct pldm_msg *msg, |
| 1359 | size_t payload_length) |
| 1360 | { |
| 1361 | if (msg == NULL || !payload_length) { |
| 1362 | return PLDM_ERROR_INVALID_DATA; |
| 1363 | } |
| 1364 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1365 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1366 | header.instance = instance_id; |
| 1367 | header.msg_type = PLDM_RESPONSE; |
| 1368 | header.pldm_type = PLDM_FWUP; |
| 1369 | header.command = PLDM_REQUEST_FIRMWARE_DATA; |
| 1370 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1371 | if (rc) { |
| 1372 | return rc; |
| 1373 | } |
| 1374 | |
| 1375 | msg->payload[0] = completion_code; |
| 1376 | |
| 1377 | return PLDM_SUCCESS; |
| 1378 | } |
| 1379 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1380 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1381 | int decode_transfer_complete_req(const struct pldm_msg *msg, |
| 1382 | size_t payload_length, |
| 1383 | uint8_t *transfer_result) |
| 1384 | { |
| 1385 | if (msg == NULL || transfer_result == NULL) { |
| 1386 | return PLDM_ERROR_INVALID_DATA; |
| 1387 | } |
| 1388 | |
| 1389 | if (payload_length != sizeof(*transfer_result)) { |
| 1390 | return PLDM_ERROR_INVALID_LENGTH; |
| 1391 | } |
| 1392 | |
| 1393 | *transfer_result = msg->payload[0]; |
| 1394 | return PLDM_SUCCESS; |
| 1395 | } |
| 1396 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1397 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1398 | int encode_transfer_complete_resp(uint8_t instance_id, uint8_t completion_code, |
| 1399 | struct pldm_msg *msg, size_t payload_length) |
| 1400 | { |
| 1401 | if (msg == NULL) { |
| 1402 | return PLDM_ERROR_INVALID_DATA; |
| 1403 | } |
| 1404 | |
| 1405 | if (payload_length != sizeof(completion_code)) { |
| 1406 | return PLDM_ERROR_INVALID_LENGTH; |
| 1407 | } |
| 1408 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1409 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1410 | header.instance = instance_id; |
| 1411 | header.msg_type = PLDM_RESPONSE; |
| 1412 | header.pldm_type = PLDM_FWUP; |
| 1413 | header.command = PLDM_TRANSFER_COMPLETE; |
| 1414 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1415 | if (rc) { |
| 1416 | return rc; |
| 1417 | } |
| 1418 | |
| 1419 | msg->payload[0] = completion_code; |
| 1420 | |
| 1421 | return PLDM_SUCCESS; |
| 1422 | } |
| 1423 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1424 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1425 | int decode_verify_complete_req(const struct pldm_msg *msg, |
| 1426 | size_t payload_length, uint8_t *verify_result) |
| 1427 | { |
| 1428 | if (msg == NULL || verify_result == NULL) { |
| 1429 | return PLDM_ERROR_INVALID_DATA; |
| 1430 | } |
| 1431 | |
| 1432 | if (payload_length != sizeof(*verify_result)) { |
| 1433 | return PLDM_ERROR_INVALID_LENGTH; |
| 1434 | } |
| 1435 | |
| 1436 | *verify_result = msg->payload[0]; |
| 1437 | return PLDM_SUCCESS; |
| 1438 | } |
| 1439 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1440 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1441 | int encode_verify_complete_resp(uint8_t instance_id, uint8_t completion_code, |
| 1442 | struct pldm_msg *msg, size_t payload_length) |
| 1443 | { |
| 1444 | if (msg == NULL) { |
| 1445 | return PLDM_ERROR_INVALID_DATA; |
| 1446 | } |
| 1447 | |
| 1448 | if (payload_length != sizeof(completion_code)) { |
| 1449 | return PLDM_ERROR_INVALID_LENGTH; |
| 1450 | } |
| 1451 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1452 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1453 | header.instance = instance_id; |
| 1454 | header.msg_type = PLDM_RESPONSE; |
| 1455 | header.pldm_type = PLDM_FWUP; |
| 1456 | header.command = PLDM_VERIFY_COMPLETE; |
| 1457 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1458 | if (rc) { |
| 1459 | return rc; |
| 1460 | } |
| 1461 | |
| 1462 | msg->payload[0] = completion_code; |
| 1463 | |
| 1464 | return PLDM_SUCCESS; |
| 1465 | } |
| 1466 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1467 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1468 | int decode_apply_complete_req(const struct pldm_msg *msg, size_t payload_length, |
| 1469 | uint8_t *apply_result, |
| 1470 | bitfield16_t *comp_activation_methods_modification) |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1471 | { |
| 1472 | if (msg == NULL || apply_result == NULL || |
| 1473 | comp_activation_methods_modification == NULL) { |
| 1474 | return PLDM_ERROR_INVALID_DATA; |
| 1475 | } |
| 1476 | |
| 1477 | if (payload_length != sizeof(struct pldm_apply_complete_req)) { |
| 1478 | return PLDM_ERROR_INVALID_LENGTH; |
| 1479 | } |
| 1480 | |
| 1481 | struct pldm_apply_complete_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1482 | (struct pldm_apply_complete_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1483 | |
| 1484 | *apply_result = request->apply_result; |
| 1485 | comp_activation_methods_modification->value = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1486 | le16toh(request->comp_activation_methods_modification.value); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1487 | |
| 1488 | if ((*apply_result != PLDM_FWUP_APPLY_SUCCESS_WITH_ACTIVATION_METHOD) && |
| 1489 | comp_activation_methods_modification->value) { |
| 1490 | return PLDM_ERROR_INVALID_DATA; |
| 1491 | } |
| 1492 | |
| 1493 | return PLDM_SUCCESS; |
| 1494 | } |
| 1495 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1496 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1497 | int encode_apply_complete_resp(uint8_t instance_id, uint8_t completion_code, |
| 1498 | struct pldm_msg *msg, size_t payload_length) |
| 1499 | { |
| 1500 | if (msg == NULL) { |
| 1501 | return PLDM_ERROR_INVALID_DATA; |
| 1502 | } |
| 1503 | |
| 1504 | if (payload_length != sizeof(completion_code)) { |
| 1505 | return PLDM_ERROR_INVALID_LENGTH; |
| 1506 | } |
| 1507 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1508 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1509 | header.instance = instance_id; |
| 1510 | header.msg_type = PLDM_RESPONSE; |
| 1511 | header.pldm_type = PLDM_FWUP; |
| 1512 | header.command = PLDM_APPLY_COMPLETE; |
| 1513 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1514 | if (rc) { |
| 1515 | return rc; |
| 1516 | } |
| 1517 | |
| 1518 | msg->payload[0] = completion_code; |
| 1519 | |
| 1520 | return PLDM_SUCCESS; |
| 1521 | } |
| 1522 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1523 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1524 | int encode_activate_firmware_req(uint8_t instance_id, |
| 1525 | bool8_t self_contained_activation_req, |
| 1526 | struct pldm_msg *msg, size_t payload_length) |
| 1527 | { |
| 1528 | if (msg == NULL) { |
| 1529 | return PLDM_ERROR_INVALID_DATA; |
| 1530 | } |
| 1531 | |
| 1532 | if (payload_length != sizeof(struct pldm_activate_firmware_req)) { |
| 1533 | return PLDM_ERROR_INVALID_LENGTH; |
| 1534 | } |
| 1535 | |
| 1536 | if (!is_self_contained_activation_req_valid( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1537 | self_contained_activation_req)) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1538 | return PLDM_ERROR_INVALID_DATA; |
| 1539 | } |
| 1540 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1541 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1542 | header.instance = instance_id; |
| 1543 | header.msg_type = PLDM_REQUEST; |
| 1544 | header.pldm_type = PLDM_FWUP; |
| 1545 | header.command = PLDM_ACTIVATE_FIRMWARE; |
| 1546 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1547 | if (rc) { |
| 1548 | return rc; |
| 1549 | } |
| 1550 | |
| 1551 | struct pldm_activate_firmware_req *request = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1552 | (struct pldm_activate_firmware_req *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1553 | |
| 1554 | request->self_contained_activation_req = self_contained_activation_req; |
| 1555 | |
| 1556 | return PLDM_SUCCESS; |
| 1557 | } |
| 1558 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1559 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1560 | int decode_activate_firmware_resp(const struct pldm_msg *msg, |
| 1561 | size_t payload_length, |
| 1562 | uint8_t *completion_code, |
| 1563 | uint16_t *estimated_time_activation) |
| 1564 | { |
| 1565 | if (msg == NULL || completion_code == NULL || |
| 1566 | estimated_time_activation == NULL || !payload_length) { |
| 1567 | return PLDM_ERROR_INVALID_DATA; |
| 1568 | } |
| 1569 | |
| 1570 | *completion_code = msg->payload[0]; |
| 1571 | if (*completion_code != PLDM_SUCCESS) { |
| 1572 | return PLDM_SUCCESS; |
| 1573 | } |
| 1574 | |
| 1575 | if (payload_length != sizeof(struct pldm_activate_firmware_resp)) { |
| 1576 | return PLDM_ERROR_INVALID_LENGTH; |
| 1577 | } |
| 1578 | |
| 1579 | struct pldm_activate_firmware_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1580 | (struct pldm_activate_firmware_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1581 | |
| 1582 | *estimated_time_activation = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1583 | le16toh(response->estimated_time_activation); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1584 | |
| 1585 | return PLDM_SUCCESS; |
| 1586 | } |
| 1587 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1588 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1589 | int encode_get_status_req(uint8_t instance_id, struct pldm_msg *msg, |
| 1590 | size_t payload_length) |
| 1591 | { |
| 1592 | if (msg == NULL) { |
| 1593 | return PLDM_ERROR_INVALID_DATA; |
| 1594 | } |
| 1595 | |
| 1596 | if (payload_length != PLDM_GET_STATUS_REQ_BYTES) { |
| 1597 | return PLDM_ERROR_INVALID_LENGTH; |
| 1598 | } |
| 1599 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1600 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1601 | header.instance = instance_id; |
| 1602 | header.msg_type = PLDM_REQUEST; |
| 1603 | header.pldm_type = PLDM_FWUP; |
| 1604 | header.command = PLDM_GET_STATUS; |
| 1605 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1606 | if (rc) { |
| 1607 | return rc; |
| 1608 | } |
| 1609 | |
| 1610 | return PLDM_SUCCESS; |
| 1611 | } |
| 1612 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1613 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1614 | int decode_get_status_resp(const struct pldm_msg *msg, size_t payload_length, |
| 1615 | uint8_t *completion_code, uint8_t *current_state, |
| 1616 | uint8_t *previous_state, uint8_t *aux_state, |
| 1617 | uint8_t *aux_state_status, uint8_t *progress_percent, |
| 1618 | uint8_t *reason_code, |
| 1619 | bitfield32_t *update_option_flags_enabled) |
| 1620 | { |
| 1621 | if (msg == NULL || completion_code == NULL || current_state == NULL || |
| 1622 | previous_state == NULL || aux_state == NULL || |
| 1623 | aux_state_status == NULL || progress_percent == NULL || |
| 1624 | reason_code == NULL || update_option_flags_enabled == NULL || |
| 1625 | !payload_length) { |
| 1626 | return PLDM_ERROR_INVALID_DATA; |
| 1627 | } |
| 1628 | |
| 1629 | *completion_code = msg->payload[0]; |
| 1630 | if (*completion_code != PLDM_SUCCESS) { |
| 1631 | return PLDM_SUCCESS; |
| 1632 | } |
| 1633 | |
| 1634 | if (payload_length != sizeof(struct pldm_get_status_resp)) { |
| 1635 | return PLDM_ERROR_INVALID_LENGTH; |
| 1636 | } |
| 1637 | struct pldm_get_status_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1638 | (struct pldm_get_status_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1639 | |
| 1640 | if (!is_state_valid(response->current_state)) { |
| 1641 | return PLDM_ERROR_INVALID_DATA; |
| 1642 | } |
| 1643 | if (!is_state_valid(response->previous_state)) { |
| 1644 | return PLDM_ERROR_INVALID_DATA; |
| 1645 | } |
| 1646 | if (!is_aux_state_valid(response->aux_state)) { |
| 1647 | return PLDM_ERROR_INVALID_DATA; |
| 1648 | } |
| 1649 | if (!is_aux_state_status_valid(response->aux_state_status)) { |
| 1650 | return PLDM_ERROR_INVALID_DATA; |
| 1651 | } |
| 1652 | if (response->progress_percent > PLDM_FWUP_MAX_PROGRESS_PERCENT) { |
| 1653 | return PLDM_ERROR_INVALID_DATA; |
| 1654 | } |
| 1655 | if (!is_reason_code_valid(response->reason_code)) { |
| 1656 | return PLDM_ERROR_INVALID_DATA; |
| 1657 | } |
| 1658 | |
| 1659 | if ((response->current_state == PLDM_FD_STATE_IDLE) || |
| 1660 | (response->current_state == PLDM_FD_STATE_LEARN_COMPONENTS) || |
| 1661 | (response->current_state == PLDM_FD_STATE_READY_XFER)) { |
| 1662 | if (response->aux_state != |
| 1663 | PLDM_FD_IDLE_LEARN_COMPONENTS_READ_XFER) { |
| 1664 | return PLDM_ERROR_INVALID_DATA; |
| 1665 | } |
| 1666 | } |
| 1667 | |
| 1668 | *current_state = response->current_state; |
| 1669 | *previous_state = response->previous_state; |
| 1670 | *aux_state = response->aux_state; |
| 1671 | *aux_state_status = response->aux_state_status; |
| 1672 | *progress_percent = response->progress_percent; |
| 1673 | *reason_code = response->reason_code; |
| 1674 | update_option_flags_enabled->value = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1675 | le32toh(response->update_option_flags_enabled.value); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1676 | |
| 1677 | return PLDM_SUCCESS; |
| 1678 | } |
| 1679 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1680 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1681 | int encode_cancel_update_component_req(uint8_t instance_id, |
| 1682 | struct pldm_msg *msg, |
| 1683 | size_t payload_length) |
| 1684 | { |
| 1685 | if (msg == NULL) { |
| 1686 | return PLDM_ERROR_INVALID_DATA; |
| 1687 | } |
| 1688 | |
| 1689 | if (payload_length != PLDM_CANCEL_UPDATE_COMPONENT_REQ_BYTES) { |
| 1690 | return PLDM_ERROR_INVALID_LENGTH; |
| 1691 | } |
| 1692 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1693 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1694 | header.instance = instance_id; |
| 1695 | header.msg_type = PLDM_REQUEST; |
| 1696 | header.pldm_type = PLDM_FWUP; |
| 1697 | header.command = PLDM_CANCEL_UPDATE_COMPONENT; |
| 1698 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1699 | if (rc) { |
| 1700 | return rc; |
| 1701 | } |
| 1702 | |
| 1703 | return PLDM_SUCCESS; |
| 1704 | } |
| 1705 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1706 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1707 | int decode_cancel_update_component_resp(const struct pldm_msg *msg, |
| 1708 | size_t payload_length, |
| 1709 | uint8_t *completion_code) |
| 1710 | { |
| 1711 | if (msg == NULL || completion_code == NULL) { |
| 1712 | return PLDM_ERROR_INVALID_DATA; |
| 1713 | } |
| 1714 | |
| 1715 | if (payload_length != sizeof(*completion_code)) { |
| 1716 | return PLDM_ERROR_INVALID_LENGTH; |
| 1717 | } |
| 1718 | |
| 1719 | *completion_code = msg->payload[0]; |
| 1720 | return PLDM_SUCCESS; |
| 1721 | } |
| 1722 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1723 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1724 | int encode_cancel_update_req(uint8_t instance_id, struct pldm_msg *msg, |
| 1725 | size_t payload_length) |
| 1726 | { |
| 1727 | if (msg == NULL) { |
| 1728 | return PLDM_ERROR_INVALID_DATA; |
| 1729 | } |
| 1730 | |
| 1731 | if (payload_length != PLDM_CANCEL_UPDATE_REQ_BYTES) { |
| 1732 | return PLDM_ERROR_INVALID_LENGTH; |
| 1733 | } |
| 1734 | |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1735 | struct pldm_header_info header = { 0 }; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1736 | header.instance = instance_id; |
| 1737 | header.msg_type = PLDM_REQUEST; |
| 1738 | header.pldm_type = PLDM_FWUP; |
| 1739 | header.command = PLDM_CANCEL_UPDATE; |
| 1740 | uint8_t rc = pack_pldm_header(&header, &(msg->hdr)); |
| 1741 | if (rc) { |
| 1742 | return rc; |
| 1743 | } |
| 1744 | |
| 1745 | return PLDM_SUCCESS; |
| 1746 | } |
| 1747 | |
Andrew Jeffery | 9d2a1c6 | 2023-06-05 13:02:16 +0930 | [diff] [blame] | 1748 | LIBPLDM_ABI_STABLE |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1749 | int decode_cancel_update_resp(const struct pldm_msg *msg, size_t payload_length, |
| 1750 | uint8_t *completion_code, |
| 1751 | bool8_t *non_functioning_component_indication, |
| 1752 | bitfield64_t *non_functioning_component_bitmap) |
| 1753 | { |
| 1754 | if (msg == NULL || completion_code == NULL || |
| 1755 | non_functioning_component_indication == NULL || |
| 1756 | non_functioning_component_bitmap == NULL || !payload_length) { |
| 1757 | return PLDM_ERROR_INVALID_DATA; |
| 1758 | } |
| 1759 | |
| 1760 | *completion_code = msg->payload[0]; |
| 1761 | if (*completion_code != PLDM_SUCCESS) { |
| 1762 | return PLDM_SUCCESS; |
| 1763 | } |
| 1764 | |
| 1765 | if (payload_length != sizeof(struct pldm_cancel_update_resp)) { |
| 1766 | return PLDM_ERROR_INVALID_LENGTH; |
| 1767 | } |
| 1768 | struct pldm_cancel_update_resp *response = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1769 | (struct pldm_cancel_update_resp *)msg->payload; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1770 | |
| 1771 | if (!is_non_functioning_component_indication_valid( |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1772 | response->non_functioning_component_indication)) { |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1773 | return PLDM_ERROR_INVALID_DATA; |
| 1774 | } |
| 1775 | |
| 1776 | *non_functioning_component_indication = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1777 | response->non_functioning_component_indication; |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1778 | |
| 1779 | if (*non_functioning_component_indication) { |
| 1780 | non_functioning_component_bitmap->value = |
Andrew Jeffery | 37dd6a3 | 2023-05-12 16:04:06 +0930 | [diff] [blame] | 1781 | le64toh(response->non_functioning_component_bitmap); |
Andrew Jeffery | 9c76679 | 2022-08-10 23:12:49 +0930 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | return PLDM_SUCCESS; |
| 1785 | } |