nrf_dfu_handling_error.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. * Copyright (c) 2017 - 2020, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. /**@file
  41. *
  42. * @defgroup nrf_dfu_rescodes DFU result codes
  43. * @{
  44. * @ingroup sdk_nrf_dfu_transport
  45. * @brief When the DFU controller sends requests to the DFU bootloader on
  46. * the DFU target, the DFU bootloader answers with any of these result codes.
  47. */
  48. #ifndef DFU_HANDLING_ERROR_H__
  49. #define DFU_HANDLING_ERROR_H__
  50. #include "nrf_dfu_types.h"
  51. #include "nrf_dfu_req_handler.h"
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55. /**@brief DFU request extended result codes.
  56. *
  57. * @details When an event returns @ref NRF_DFU_RES_CODE_EXT_ERROR, it also stores an extended error code.
  58. * The transport layer can then send the extended error code together with the error code to give
  59. * the controller additional information about the cause of the error.
  60. */
  61. typedef enum
  62. {
  63. NRF_DFU_EXT_ERROR_NO_ERROR = 0x00, /**< No extended error code has been set. This error indicates an implementation problem. */
  64. NRF_DFU_EXT_ERROR_INVALID_ERROR_CODE = 0x01, /**< Invalid error code. This error code should never be used outside of development. */
  65. NRF_DFU_EXT_ERROR_WRONG_COMMAND_FORMAT = 0x02, /**< The format of the command was incorrect. This error code is not used in the
  66. current implementation, because @ref NRF_DFU_RES_CODE_OP_CODE_NOT_SUPPORTED
  67. and @ref NRF_DFU_RES_CODE_INVALID_PARAMETER cover all
  68. possible format errors. */
  69. NRF_DFU_EXT_ERROR_UNKNOWN_COMMAND = 0x03, /**< The command was successfully parsed, but it is not supported or unknown. */
  70. NRF_DFU_EXT_ERROR_INIT_COMMAND_INVALID = 0x04, /**< The init command is invalid. The init packet either has
  71. an invalid update type or it is missing required fields for the update type
  72. (for example, the init packet for a SoftDevice update is missing the SoftDevice size field). */
  73. NRF_DFU_EXT_ERROR_FW_VERSION_FAILURE = 0x05, /**< The firmware version is too low. For an application or SoftDevice, the version must be greater than
  74. or equal to the current version. For a bootloader, it must be greater than the current version.
  75. to the current version. This requirement prevents downgrade attacks.*/
  76. NRF_DFU_EXT_ERROR_HW_VERSION_FAILURE = 0x06, /**< The hardware version of the device does not match the required
  77. hardware version for the update. */
  78. NRF_DFU_EXT_ERROR_SD_VERSION_FAILURE = 0x07, /**< The array of supported SoftDevices for the update does not contain
  79. the FWID of the current SoftDevice or the first FWID is '0' on a
  80. bootloader which requires the SoftDevice to be present. */
  81. NRF_DFU_EXT_ERROR_SIGNATURE_MISSING = 0x08, /**< The init packet does not contain a signature. This error code is not used in the
  82. current implementation, because init packets without a signature
  83. are regarded as invalid. */
  84. NRF_DFU_EXT_ERROR_WRONG_HASH_TYPE = 0x09, /**< The hash type that is specified by the init packet is not supported by the DFU bootloader. */
  85. NRF_DFU_EXT_ERROR_HASH_FAILED = 0x0A, /**< The hash of the firmware image cannot be calculated. */
  86. NRF_DFU_EXT_ERROR_WRONG_SIGNATURE_TYPE = 0x0B, /**< The type of the signature is unknown or not supported by the DFU bootloader. */
  87. NRF_DFU_EXT_ERROR_VERIFICATION_FAILED = 0x0C, /**< The hash of the received firmware image does not match the hash in the init packet. */
  88. NRF_DFU_EXT_ERROR_INSUFFICIENT_SPACE = 0x0D, /**< The available space on the device is insufficient to hold the firmware. */
  89. } nrf_dfu_ext_error_code_t;
  90. /**@brief Function for setting an extended error code that can be retrieved later.
  91. *
  92. * @details When an extended error occurs in the DFU process, this function can be used to store the error.
  93. *
  94. * @param error_code The error code to store.
  95. *
  96. * @retval NRF_DFU_RES_CODE_EXT_ERROR
  97. */
  98. nrf_dfu_result_t ext_error_set(nrf_dfu_ext_error_code_t error_code);
  99. /**@brief Function for getting the most recent extended error code.
  100. *
  101. * @details This function is used by the transport layer to fetch the most recent extended error code.
  102. *
  103. * @return The most recent error code. If the function is called again before a new error occurs, @ref NRF_DFU_EXT_ERROR_NO_ERROR is returned.
  104. */
  105. nrf_dfu_ext_error_code_t ext_error_get( void );
  106. #ifdef __cplusplus
  107. }
  108. #endif
  109. #endif // DFU_HANDLING_ERROR_H__
  110. /** @} */