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