1 /* 2 * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef H_ESP_HCI_INTERNAL_ 8 #define H_ESP_HCI_INTERNAL_ 9 10 #ifdef __cplusplus 11 extern "C" { 12 #endif 13 #include <stdint.h> 14 #include "os/os_mbuf.h" 15 16 17 /* The leadingspace in user info header for ACL data */ 18 #define ESP_HCI_INTERNAL_ACL_MBUF_LEADINGSPCAE (4) 19 20 #define ESP_HCI_INTERNAL_BUF_CMD (3) 21 22 /** 23 * @brief Define the HCI hardware error code for synchronization loss. 24 * This error code is used to indicate a loss of synchronization between the controller and the host. 25 */ 26 #define ESP_HCI_SYNC_LOSS_ERR (0x1) 27 /** Callback function types; executed when HCI packets are received. */ 28 typedef int esp_hci_internal_rx_cmd_fn(uint8_t *cmd, void *arg); 29 typedef int esp_hci_internal_rx_acl_fn(struct os_mbuf *om, void *arg); 30 31 /** 32 * Configures the HCI transport to operate with a host. The transport will 33 * execute specified callbacks upon receiving HCI packets from the controller. 34 * 35 * @param evt_cb The callback to execute upon receiving an HCI 36 * event. 37 * @param evt_arg Optional argument to pass to the event 38 * callback. 39 * @param acl_cb The callback to execute upon receiving ACL 40 * data. 41 * @param acl_arg Optional argument to pass to the ACL 42 * callback. 43 */ 44 void r_ble_hci_trans_cfg_hs(esp_hci_internal_rx_cmd_fn *evt_cb, void *evt_arg, 45 esp_hci_internal_rx_acl_fn *acl_cb, void *acl_arg); 46 /** 47 * Sends ACL data from host to controller. 48 * 49 * @param om The ACL data packet to send. 50 * 51 * @return 0 on success; 52 * A BLE_ERR_[...] error code on failure. 53 */ 54 int r_ble_hci_trans_hs_acl_tx(struct os_mbuf *om); 55 56 /** 57 * Sends an HCI command from the host to the controller. 58 * 59 * @param cmd The HCI command to send. This buffer must be 60 * allocated via ble_hci_trans_buf_alloc(). 61 * 62 * @return 0 on success; 63 * A BLE_ERR_[...] error code on failure. 64 */ 65 int r_ble_hci_trans_hs_cmd_tx(uint8_t *cmd); 66 67 /** 68 * Allocates a flat buffer of the specified type. 69 * 70 * @param type The type of buffer to allocate; one of the 71 * BLE_HCI_TRANS_BUF_[...] constants. 72 * 73 * @return The allocated buffer on success; 74 * NULL on buffer exhaustion. 75 */ 76 uint8_t * r_ble_hci_trans_buf_alloc(int type); 77 78 /** 79 * Frees the specified flat buffer. The buffer must have been allocated via 80 * ble_hci_trans_buf_alloc(). 81 * 82 * @param buf The buffer to free. 83 */ 84 void r_ble_hci_trans_buf_free(uint8_t *buf); 85 86 /** 87 * Configures a callback to get executed whenever an ACL data packet is freed. 88 * The function is called immediately before the free occurs. 89 * 90 * @param cb The callback to configure. 91 * @param arg An optional argument to pass to the callback. 92 * 93 * @return 0 on success; 94 * BLE_ERR_UNSUPPORTED if the transport does not 95 * support this operation. 96 */ 97 int r_ble_hci_trans_set_acl_free_cb(os_mempool_put_fn *cb, void *arg); 98 99 /** 100 * @brief Handle an HCI hardware error event. 101 * This function processes a hardware error code and generates the appropriate HCI hardware error event. 102 * 103 * @param hw_err The hardware error code that needs to be processed. The specific meaning of the error code 104 * depends on the implementation and the hardware. 105 * 106 * @return int Returns 0 on success, or a non-zero error code on failure. 107 * 108 * @note This function should be called whenever a hardware error is detected in the HCI Layer. 109 */ 110 int r_ble_ll_hci_ev_hw_err(uint8_t hw_err); 111 112 //!TODO: Check what this API is used for 113 int r_ble_hci_trans_reset(void); 114 115 //!TODO: Should we initialize the hci layer in IDF ? 116 void esp_ble_hci_trans_init(uint8_t); 117 118 #ifdef __cplusplus 119 } 120 #endif 121 #endif /* H_ESP_HCI_INTERNAL_ */ 122