handlers.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include <esp_err.h>
  9. #include <esp_log.h>
  10. #include "host/ble_hs.h"
  11. #include "manager.h"
  12. #include "esp_ble_ota_priv.h"
  13. #include "ota.h"
  14. #include "ble_ota.h"
  15. #define ENDPOINTS 4
  16. static const char *TAG = "ota_handlers";
  17. static esp_err_t
  18. ota_send_file(uint8_t *file, size_t length)
  19. {
  20. esp_ble_ota_write(file, length);
  21. return ESP_OK;
  22. }
  23. static esp_err_t
  24. ota_start_cmd(size_t file_size, size_t block_size, char *partition_name)
  25. {
  26. /* Currently by default partition is OTA, so not setting it */
  27. ESP_LOGI(TAG, "%s file len = %d block size = %d", __func__, file_size, block_size);
  28. esp_ble_ota_set_sizes(file_size, block_size);
  29. return ESP_OK;
  30. }
  31. static esp_err_t
  32. ota_finish_cmd()
  33. {
  34. esp_ble_ota_finish();
  35. return ESP_OK;
  36. }
  37. esp_err_t
  38. get_ota_handlers(ota_handlers_t *ptr)
  39. {
  40. if (!ptr) {
  41. ESP_LOGE(TAG, "Null ptr");
  42. return ESP_ERR_INVALID_ARG;
  43. }
  44. ptr->ota_send_file = ota_send_file;
  45. ptr->ota_start_cmd = ota_start_cmd;
  46. ptr->ota_finish_cmd = ota_finish_cmd;
  47. return ESP_OK;
  48. }