ble_ota.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #ifndef _BLE_OTA_H_
  8. #define _BLE_OTA_H_
  9. #ifdef CONFIG_PRE_ENC_OTA
  10. #include "esp_encrypted_img.h"
  11. #endif
  12. #ifdef __cplusplus
  13. extern "C"
  14. {
  15. #endif
  16. /**
  17. * @brief BLE OAT receive data callback function type
  18. * @param buf : The pointer to the receive data buffer.
  19. * @param length : The length of receive data buffer.
  20. */
  21. typedef void (* esp_ble_ota_recv_fw_cb_t)(uint8_t *buf, uint32_t length);
  22. /**
  23. * @brief BLE OTA callback functions struct
  24. */
  25. typedef struct esp_ble_ota_callback_funs {
  26. esp_ble_ota_recv_fw_cb_t recv_fw_cb; /*!< BLE OTA data receive callback function */
  27. } esp_ble_ota_callback_funs_t;
  28. /**
  29. * @brief BLE OTA notification flags struct
  30. */
  31. typedef struct esp_ble_ota_notification_check {
  32. bool recv_fw_ntf_enable; /*!< BLE OTA receive firmware characteristic */
  33. bool process_bar_ntf_enable; /*!< BLE OTA notify process bar characteristic */
  34. bool command_ntf_enable; /*!< BLE OTA command characteristic */
  35. bool customer_ntf_enable; /*!< BLE OTA customer data characteristic */
  36. } esp_ble_ota_notification_check_t;
  37. #if CONFIG_BT_BLUEDROID_ENABLED
  38. /// BLE OTA characteristics
  39. typedef enum {
  40. RECV_FW_CHAR,
  41. RECV_FW_CHAR_CCC,
  42. OTA_STATUS_CHAR,
  43. OTA_STATUS_CHAR_CCC,
  44. CMD_CHAR,
  45. CMD_CHAR_CCC,
  46. CUS_CHAR,
  47. CUS_CHAR_CCC,
  48. INVALID_CHAR,
  49. } esp_ble_ota_char_t;
  50. /// BLE DIS characteristics
  51. typedef enum {
  52. DIS_SVC_IDX,
  53. DIS_MODEL_CHAR_IDX,
  54. DIS_MODEL_CHAR_VAL_IDX,
  55. DIS_SN_CHAR_IDX,
  56. DIS_SN_CHAR_VAL_IDX,
  57. DIS_FW_CHAR_IDX,
  58. DIS_FW_CHAR_VAL_IDX,
  59. DIS_IDX_NB,
  60. } esp_ble_dis_service_index_t;
  61. /// BLE OTA characteristics Index
  62. typedef enum {
  63. OTA_SVC_IDX,
  64. RECV_FW_CHAR_IDX,
  65. RECV_FW_CHAR_VAL_IDX,
  66. RECV_FW_CHAR_NTF_CFG,
  67. OTA_STATUS_CHAR_IDX,
  68. OTA_STATUS_CHAR_VAL_IDX,
  69. OTA_STATUS_NTF_CFG,
  70. CMD_CHAR_IDX,
  71. CMD_CHAR_VAL_IDX,
  72. CMD_CHAR_NTF_CFG,
  73. CUS_CHAR_IDX,
  74. CUS_CHAR_VAL_IDX,
  75. CUS_CHAR_NTF_CFG,
  76. OTA_IDX_NB,
  77. } esp_ble_ota_service_index_t;
  78. #else
  79. typedef enum {
  80. RECV_FW_CHAR,
  81. OTA_STATUS_CHAR,
  82. CMD_CHAR,
  83. CUS_CHAR,
  84. INVALID_CHAR,
  85. } esp_ble_ota_char_t;
  86. typedef enum {
  87. RECV_FW_CHAR_VAL_IDX,
  88. OTA_STATUS_CHAR_VAL_IDX,
  89. CMD_CHAR_VAL_IDX,
  90. CUS_CHAR_VAL_IDX,
  91. } esp_ble_ota_service_index_t;
  92. /**
  93. * @brief This function is called to process write event on characteristics
  94. *
  95. * @return void
  96. *
  97. */
  98. void esp_ble_ota_write(uint8_t *file, size_t length);
  99. /**
  100. * @brief This function is used to set total file size and each block size
  101. *
  102. * @return void
  103. *
  104. */
  105. void esp_ble_ota_set_sizes(size_t file_size, size_t block_size);
  106. #endif
  107. /**
  108. * @brief This function is called to Initialization ble ota host
  109. *
  110. * @return
  111. * - ESP_OK: success
  112. * - other: failed
  113. *
  114. */
  115. esp_err_t esp_ble_ota_host_init(void);
  116. /**
  117. * @brief This function is called to register ble ota receive firmware data callback function
  118. *
  119. * @param[in] callback : pointer to the application callback function.
  120. *
  121. * @return
  122. * - ESP_OK: success
  123. * - other: failed
  124. *
  125. */
  126. #ifdef CONFIG_PRE_ENC_OTA
  127. esp_err_t esp_ble_ota_recv_fw_data_callback(esp_ble_ota_recv_fw_cb_t callback,
  128. esp_decrypt_handle_t esp_decrypt_handle);
  129. #else
  130. esp_err_t esp_ble_ota_recv_fw_data_callback(esp_ble_ota_recv_fw_cb_t callback);
  131. #endif
  132. /**
  133. * @brief This function is called to Initialization ble ota process
  134. *
  135. * @return
  136. * - length of ota firmware
  137. *
  138. */
  139. unsigned int esp_ble_ota_get_fw_length(void);
  140. /**
  141. * @brief This function is called to indicate OTA end
  142. *
  143. */
  144. void esp_ble_ota_finish(void);
  145. #ifdef __cplusplus
  146. }
  147. #endif
  148. #endif