1 /****************************************************************************** 2 * 3 * Copyright (C) 2009-2012 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 #ifndef BT_HCI_LIB_H 20 #define BT_HCI_LIB_H 21 22 #include <stdint.h> 23 #include <stdbool.h> 24 #include <sys/cdefs.h> 25 #include <sys/types.h> 26 27 /** Struct types */ 28 29 30 /** Typedefs and defines */ 31 32 /* Generic purpose transac returned upon request complete */ 33 typedef void* TRANSAC; 34 35 /** Bluetooth Power Control States */ 36 typedef enum { 37 BT_HC_CHIP_PWR_OFF, 38 BT_HC_CHIP_PWR_ON, 39 } bt_hc_chip_power_state_t; 40 41 /** Bluetooth Low Power Mode */ 42 typedef enum { 43 BT_HC_LPM_DISABLE, 44 BT_HC_LPM_ENABLE, 45 BT_HC_LPM_WAKE_ASSERT, 46 BT_HC_LPM_WAKE_DEASSERT, 47 } bt_hc_low_power_event_t; 48 49 /** Receive flow control */ 50 typedef enum { 51 BT_RXFLOW_OFF, /* add transport device fd to select set */ 52 BT_RXFLOW_ON, /* remove transport device to from select set */ 53 } bt_rx_flow_state_t; 54 55 /** HCI logging control */ 56 typedef enum { 57 BT_HC_LOGGING_OFF, 58 BT_HC_LOGGING_ON, 59 } bt_hc_logging_state_t; 60 61 /* commands to be used in LSB with MSG_CTRL_TO_HC_CMD */ 62 typedef enum { 63 BT_HC_AUDIO_STATE = 0, 64 BT_HC_CMD_MAX 65 } bt_hc_tx_cmd_t; 66 /** Result of write request */ 67 typedef enum { 68 BT_HC_TX_SUCCESS, /* a buffer is fully processed and can be released */ 69 BT_HC_TX_FAIL, /* transmit fail */ 70 BT_HC_TX_FRAGMENT, /* send split ACL pkt back to stack to reprocess */ 71 } bt_hc_transmit_result_t; 72 73 /** Result of preload initialization */ 74 typedef enum { 75 BT_HC_PRELOAD_SUCCESS, 76 BT_HC_PRELOAD_FAIL, 77 } bt_hc_preload_result_t; 78 79 /** Result of postload initialization */ 80 typedef enum { 81 BT_HC_POSTLOAD_SUCCESS, 82 BT_HC_POSTLOAD_FAIL, 83 } bt_hc_postload_result_t; 84 85 /** Result of low power enable/disable request */ 86 typedef enum { 87 BT_HC_LPM_DISABLED, 88 BT_HC_LPM_ENABLED, 89 } bt_hc_lpm_request_result_t; 90 91 /** Host/Controller Library Return Status */ 92 typedef enum { 93 BT_HC_STATUS_SUCCESS, 94 BT_HC_STATUS_FAIL, 95 BT_HC_STATUS_NOT_READY, 96 BT_HC_STATUS_NOMEM, 97 BT_HC_STATUS_BUSY, 98 BT_HC_STATUS_CORRUPTED_BUFFER 99 } bt_hc_status_t; 100 101 102 /* Section comment */ 103 104 /* 105 * Bluetooth Host/Controller callback structure. 106 */ 107 108 /* called upon bt host wake signal */ 109 typedef void (*hostwake_ind_cb)(bt_hc_low_power_event_t event); 110 111 /* preload initialization callback */ 112 typedef void (*preload_result_cb)(TRANSAC transac, bt_hc_preload_result_t result); 113 114 /* postload initialization callback */ 115 typedef void (*postload_result_cb)(TRANSAC transac, bt_hc_postload_result_t result); 116 117 /* lpm enable/disable callback */ 118 typedef void (*lpm_result_cb)(bt_hc_lpm_request_result_t result); 119 120 /* datapath buffer allocation callback (callout) */ 121 typedef char* (*alloc_mem_cb)(int size); 122 123 /* datapath buffer deallocation callback (callout) */ 124 typedef void (*dealloc_mem_cb)(TRANSAC transac); 125 126 /* transmit result callback */ 127 typedef int (*tx_result_cb)(TRANSAC transac, char *p_buf, bt_hc_transmit_result_t result); 128 129 /* a previously setup buffer is read and available for processing 130 buffer is deallocated in stack when processed */ 131 typedef int (*data_ind_cb)(TRANSAC transac, char *p_buf, int len); 132 133 typedef struct { 134 /** set to sizeof(bt_hc_callbacks_t) */ 135 size_t size; 136 137 /* notifies caller result of preload request */ 138 preload_result_cb preload_cb; 139 140 /* notifies caller result of postload request */ 141 postload_result_cb postload_cb; 142 143 /* notifies caller result of lpm enable/disable */ 144 lpm_result_cb lpm_cb; 145 146 /* notifies hardware on host wake state */ 147 hostwake_ind_cb hostwake_ind; 148 149 /* buffer allocation request */ 150 alloc_mem_cb alloc; 151 152 /* buffer deallocation request */ 153 dealloc_mem_cb dealloc; 154 155 /* notifies stack data is available */ 156 data_ind_cb data_ind; 157 158 /* notifies caller when a buffer is transmitted (or failed) */ 159 tx_result_cb tx_result; 160 } bt_hc_callbacks_t; 161 162 /* 163 * Bluetooth Host/Controller Interface 164 */ 165 typedef struct { 166 /** Set to sizeof(bt_hc_interface_t) */ 167 size_t size; 168 169 /** 170 * Opens the interface and provides the callback routines 171 * to the implemenation of this interface. 172 */ 173 int (*init)(const bt_hc_callbacks_t* p_cb, unsigned char *local_bdaddr); 174 175 /** Chip power control */ 176 void (*set_power)(bt_hc_chip_power_state_t state); 177 178 /** Set low power mode wake */ 179 int (*lpm)(bt_hc_low_power_event_t event); 180 181 /** Called prior to stack initialization */ 182 void (*preload)(TRANSAC transac); 183 184 /** Called post stack initialization */ 185 void (*postload)(TRANSAC transac); 186 187 /** Transmit buffer */ 188 int (*transmit_buf)(TRANSAC transac, char *p_buf, int len); 189 190 /** Controls HCI logging on/off */ 191 int (*logging)(bt_hc_logging_state_t state, char *p_path, bool save_existing); 192 193 /** Closes the interface */ 194 void (*cleanup)( void ); 195 196 /** sends commands to hc layer (e.g. SCO state) */ 197 int (*tx_cmd)(TRANSAC transac, char *p_buf, int len); 198 } bt_hc_interface_t; 199 200 201 /* 202 * External shared lib functions 203 */ 204 205 extern const bt_hc_interface_t* bt_hc_get_interface(void); 206 207 #endif /* BT_HCI_LIB_H */ 208 209