esp_bluedroid_hci.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <string.h>
  7. #include "esp_log.h"
  8. #include "esp_bluedroid_hci.h"
  9. #include "common/bt_target.h"
  10. #include "hci/hci_trans_int.h"
  11. #if (BT_CONTROLLER_INCLUDED == TRUE)
  12. #include "esp_bt.h"
  13. #endif
  14. #define LOG_TAG "HCI_API"
  15. static esp_bluedroid_hci_driver_operations_t s_hci_driver_ops = { 0 };
  16. esp_err_t esp_bluedroid_attach_hci_driver(const esp_bluedroid_hci_driver_operations_t *p_ops)
  17. {
  18. if (!p_ops) {
  19. ESP_LOGE(LOG_TAG, "%s invalid function parameter", __func__);
  20. return ESP_FAIL;
  21. }
  22. s_hci_driver_ops.send = p_ops->send;
  23. s_hci_driver_ops.check_send_available = p_ops->check_send_available;
  24. s_hci_driver_ops.register_host_callback = p_ops->register_host_callback;
  25. return ESP_OK;
  26. }
  27. esp_err_t esp_bluedroid_detach_hci_driver(void)
  28. {
  29. s_hci_driver_ops.send = NULL;
  30. s_hci_driver_ops.check_send_available = NULL;
  31. s_hci_driver_ops.register_host_callback = NULL;
  32. return ESP_OK;
  33. }
  34. /****************************************************************
  35. * INTERNAL USE *
  36. ****************************************************************/
  37. bool hci_host_check_send_available(void)
  38. {
  39. bool can_send = false;
  40. #if (BT_CONTROLLER_INCLUDED == TRUE)
  41. can_send = esp_vhci_host_check_send_available();
  42. #else /* BT_CONTROLLER_INCLUDED == TRUE */
  43. if (s_hci_driver_ops.check_send_available) {
  44. can_send = s_hci_driver_ops.check_send_available();
  45. }
  46. #endif /* BT_CONTROLLER_INCLUDED == TRUE */
  47. return can_send;
  48. }
  49. void hci_host_send_packet(uint8_t *data, uint16_t len)
  50. {
  51. #if (BT_CONTROLLER_INCLUDED == TRUE)
  52. esp_vhci_host_send_packet(data, len);
  53. #else /* BT_CONTROLLER_INCLUDED == TRUE */
  54. if (s_hci_driver_ops.send) {
  55. s_hci_driver_ops.send(data, len);
  56. }
  57. #endif /* BT_CONTROLLER_INCLUDED == TRUE */
  58. }
  59. esp_err_t hci_host_register_callback(const esp_bluedroid_hci_driver_callbacks_t *callback)
  60. {
  61. esp_err_t ret = ESP_FAIL;
  62. if (!callback) {
  63. ESP_LOGE(LOG_TAG, "%s invalid function parameter", __func__);
  64. return ESP_FAIL;
  65. }
  66. #if (BT_CONTROLLER_INCLUDED == TRUE)
  67. ret = esp_vhci_host_register_callback((esp_vhci_host_callback_t *)callback);
  68. #else /* BT_CONTROLLER_INCLUDED == TRUE */
  69. if (s_hci_driver_ops.register_host_callback) {
  70. ret = s_hci_driver_ops.register_host_callback(callback);
  71. }
  72. #endif /* BT_CONTROLLER_INCLUDED == TRUE */
  73. return ret;
  74. }