bt_hci_lib.h
Go to the documentation of this file.
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 {
40 
41 /** Bluetooth Low Power Mode */
42 typedef enum {
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 */
54 
55 /** HCI logging control */
56 typedef enum {
60 
61 /* commands to be used in LSB with MSG_CTRL_TO_HC_CMD */
62 typedef enum {
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 */
72 
73 /** Result of preload initialization */
74 typedef enum {
78 
79 /** Result of postload initialization */
80 typedef enum {
84 
85 /** Result of low power enable/disable request */
86 typedef enum {
90 
91 /** Host/Controller Library Return Status */
92 typedef enum {
100 
101 
102 /* Section comment */
103 
104 /*
105  * Bluetooth Host/Controller callback structure.
106  */
107 
108 /* called upon bt host wake signal */
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 */
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 */
139 
140  /* notifies caller result of postload request */
142 
143  /* notifies caller result of lpm enable/disable */
145 
146  /* notifies hardware on host wake state */
148 
149  /* buffer allocation request */
151 
152  /* buffer deallocation request */
154 
155  /* notifies stack data is available */
157 
158  /* notifies caller when a buffer is transmitted (or failed) */
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);
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 
bt_hc_low_power_event_t
Definition: bt_hci_lib.h:42
const bt_hc_interface_t * bt_hc_get_interface(void)
bt_hc_tx_cmd_t
Definition: bt_hci_lib.h:62
bt_hc_preload_result_t
Definition: bt_hci_lib.h:74
void(* postload_result_cb)(TRANSAC transac, bt_hc_postload_result_t result)
Definition: bt_hci_lib.h:115
lpm_result_cb lpm_cb
Definition: bt_hci_lib.h:144
bt_hc_status_t
Definition: bt_hci_lib.h:92
bt_hc_postload_result_t
Definition: bt_hci_lib.h:80
bt_hc_lpm_request_result_t
Definition: bt_hci_lib.h:86
void * TRANSAC
Definition: bt_hci_lib.h:33
char *(* alloc_mem_cb)(int size)
Definition: bt_hci_lib.h:121
bt_rx_flow_state_t
Definition: bt_hci_lib.h:50
int(* tx_result_cb)(TRANSAC transac, char *p_buf, bt_hc_transmit_result_t result)
Definition: bt_hci_lib.h:127
void(* hostwake_ind_cb)(bt_hc_low_power_event_t event)
Definition: bt_hci_lib.h:109
bt_hc_logging_state_t
Definition: bt_hci_lib.h:56
bt_hc_transmit_result_t
Definition: bt_hci_lib.h:67
postload_result_cb postload_cb
Definition: bt_hci_lib.h:141
data_ind_cb data_ind
Definition: bt_hci_lib.h:156
void(* preload_result_cb)(TRANSAC transac, bt_hc_preload_result_t result)
Definition: bt_hci_lib.h:112
bt_hc_chip_power_state_t
Definition: bt_hci_lib.h:36
hostwake_ind_cb hostwake_ind
Definition: bt_hci_lib.h:147
void(* dealloc_mem_cb)(TRANSAC transac)
Definition: bt_hci_lib.h:124
int(* data_ind_cb)(TRANSAC transac, char *p_buf, int len)
Definition: bt_hci_lib.h:131
tx_result_cb tx_result
Definition: bt_hci_lib.h:159
alloc_mem_cb alloc
Definition: bt_hci_lib.h:150
preload_result_cb preload_cb
Definition: bt_hci_lib.h:138
void(* lpm_result_cb)(bt_hc_lpm_request_result_t result)
Definition: bt_hci_lib.h:118
dealloc_mem_cb dealloc
Definition: bt_hci_lib.h:153