nrf_dfu_ble.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * Copyright (c) 2016 - 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_ble DFU BLE Service
  43. * @{
  44. * @ingroup nrf_dfu
  45. * @brief Device Firmware Update (DFU) transport layer for <em>Bluetooth</em> low energy.
  46. *
  47. * @details The Device Firmware Update (DFU) Service is a GATT-based service that can be used for
  48. * performing firmware updates over BLE. Note that this implementation uses
  49. * vendor-specific UUIDs for the service and characteristics, and is intended to demonstrate
  50. * firmware updates over BLE. See @ref lib_dfu_transport_ble "DFU Transport: BLE" for more information on the service and the profile.
  51. */
  52. #ifndef NRF_DFU_BLE_H__
  53. #define NRF_DFU_BLE_H__
  54. #include <stdint.h>
  55. #include "ble_gatts.h"
  56. #include "ble.h"
  57. #include "nrf_dfu_transport.h"
  58. #ifdef __cplusplus
  59. extern "C" {
  60. #endif
  61. // This is a 16-bit UUID.
  62. #define BLE_DFU_SERVICE_UUID 0xFE59 //!< UUID of the DFU Service.
  63. // These UUIDs are used with the Nordic base address to create a 128-bit UUID (0x8EC9XXXXF3154F609FB8838830DAEA50).
  64. #define BLE_DFU_CTRL_PT_UUID 0x0001 //!< UUID of the DFU Control Point.
  65. #define BLE_DFU_PKT_CHAR_UUID 0x0002 //!< UUID of the DFU Packet Characteristic.
  66. /**@brief DFU Service.
  67. *
  68. * @details This structure contains status information related to the service.
  69. */
  70. typedef struct
  71. {
  72. uint16_t service_handle; /**< Handle of the DFU Service (as provided by the SoftDevice). */
  73. uint8_t uuid_type; /**< UUID type assigned to the DFU Service by the SoftDevice. */
  74. ble_gatts_char_handles_t dfu_pkt_handles; /**< Handles related to the DFU Packet Characteristic. */
  75. ble_gatts_char_handles_t dfu_ctrl_pt_handles; /**< Handles related to the DFU Control Point Characteristic. */
  76. } ble_dfu_t;
  77. /**@brief Function for initializing the BLE transport.
  78. *
  79. * @param[in] observer Callback function for receiving notifications from the BLE transport.
  80. *
  81. * @retval NRF_SUCCESS If successful.
  82. * @return Error code from sub-call on error.
  83. */
  84. uint32_t ble_dfu_transport_init(nrf_dfu_observer_t observer);
  85. /**@brief Function for closing the BLE transport.
  86. *
  87. * This function disconnects and disables the SoftDevice.
  88. *
  89. * @param[in] p_exception Optional exception. If the exception refers to this transport,
  90. * this function will do nothing. Can be NULL to signify no exception.
  91. *
  92. * @retval NRF_SUCCESS If successful.
  93. * @return Error code from sub-call on error.
  94. */
  95. uint32_t ble_dfu_transport_close(nrf_dfu_transport_t const * p_exception);
  96. /**@brief Function for disconnecting from the BLE peer and starting advertising.
  97. *
  98. * @retval NRF_SUCCESS If successful.
  99. * @return Error code from sub-call on error.
  100. */
  101. uint32_t ble_dfu_transport_disconnect(void);
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif // NRF_DFU_BLE_H__
  106. /** @} */