1 /******************************************************************************
2  *
3  *  Copyright 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 /*******************************************************************************
20  *
21  *  Filename:      btif_api.h
22  *
23  *  Description:   Main API header file for all BTIF functions accessed
24  *                 from main bluetooth HAL. All HAL extensions will not
25  *                 require headerfiles as they would be accessed through
26  *                 callout/callins.
27  *
28  ******************************************************************************/
29 
30 #ifndef BTIF_API_H
31 #define BTIF_API_H
32 
33 #include <hardware/bluetooth.h>
34 
35 #include "btif_common.h"
36 #include "btif_dm.h"
37 #include "types/raw_address.h"
38 
39 /*******************************************************************************
40  *  BTIF CORE API
41  ******************************************************************************/
42 
43 /*******************************************************************************
44  *
45  * Function         btif_init_bluetooth
46  *
47  * Description      Creates BTIF task and prepares BT scheduler for startup
48  *
49  * Returns          bt_status_t
50  *
51  ******************************************************************************/
52 bt_status_t btif_init_bluetooth(void);
53 
54 /*******************************************************************************
55  *
56  * Function         btif_enable_bluetooth
57  *
58  * Description      Performs chip power on and kickstarts OS scheduler
59  *
60  * Returns          bt_status_t
61  *
62  ******************************************************************************/
63 bt_status_t btif_enable_bluetooth(void);
64 
65 /*******************************************************************************
66  *
67  * Function         btif_cleanup_bluetooth
68  *
69  * Description      Cleanup BTIF state.
70  *
71  *
72  * Returns          void
73  *
74  ******************************************************************************/
75 bt_status_t btif_cleanup_bluetooth(void);
76 
77 /*******************************************************************************
78  *
79  * Function         is_restricted_mode
80  *
81  * Description      Checks if BT was enabled in restriced mode. In restricted
82  *                  mode, bonds that are created are marked as temporary.
83  *                  These bonds persist until we leave restricted mode, at
84  *                  which point they will be deleted from the config. Also
85  *                  while in restricted mode, the user can access devices
86  *                  that are already paired before entering restricted mode,
87  *                  but they cannot remove any of these devices.
88  *
89  * Returns          bool
90  *
91  ******************************************************************************/
92 bool is_restricted_mode(void);
93 
94 /*******************************************************************************
95  *
96  * Function         is_common_criteria_mode
97  *
98  * Description      Check if BT is enabled in common criteria mode. In this
99  *                  mode, will use the LTK from the keystore to authenticate.
100  *
101  * Returns          bool
102  *
103  ******************************************************************************/
104 bool is_common_criteria_mode(void);
105 
106 /*******************************************************************************
107  *
108  * Function         get_common_criteria_config_compare_result
109  *
110  * Description      Get the common criteria config compare result for confirming
111  *                  the config checksum compare result. When the common criteria
112  *                  mode doesn't enable, it should be all pass (0b11).
113  *                  Bit define:
114  *                    CONFIG_FILE_COMPARE_PASS = 0b01
115  *                    CONFIG_BACKUP_COMPARE_PASS = 0b10
116  *
117  * Returns          int
118  *
119  ******************************************************************************/
120 int get_common_criteria_config_compare_result(void);
121 
122 /*******************************************************************************
123  *
124  * Function         is_atv_device
125  *
126  * Description      Returns true if the local device is an Android TV
127  *                  device, false if it is not.
128  *
129  * Returns          bool
130  *
131  ******************************************************************************/
132 bool is_atv_device(void);
133 
134 /*******************************************************************************
135  *
136  * Function         btif_get_adapter_properties
137  *
138  * Description      Fetches all local adapter properties
139  *
140  ******************************************************************************/
141 void btif_get_adapter_properties(void);
142 
143 bt_property_t* property_deep_copy(const bt_property_t* prop);
144 
145 /*******************************************************************************
146  *
147  * Function         btif_get_adapter_property
148  *
149  * Description      Fetches property value from local cache
150  *
151  ******************************************************************************/
152 void btif_get_adapter_property(bt_property_type_t type);
153 
154 /*******************************************************************************
155  *
156  * Function         btif_set_scan_mode
157  *
158  * Description      Updates core stack scan mode
159  *
160  ******************************************************************************/
161 void btif_set_scan_mode(bt_scan_mode_t mode);
162 
163 /*******************************************************************************
164  *
165  * Function         btif_set_adapter_property
166  *
167  * Description      Updates core stack with property value and stores it in
168  *                  local cache
169  *
170  ******************************************************************************/
171 void btif_set_adapter_property(bt_property_t* property);
172 
173 /*******************************************************************************
174  *
175  * Function         btif_get_remote_device_property
176  *
177  * Description      Fetches the remote device property from the NVRAM
178  *
179  ******************************************************************************/
180 void btif_get_remote_device_property(RawAddress remote_addr, bt_property_type_t type);
181 
182 /*******************************************************************************
183  *
184  * Function         btif_get_remote_device_properties
185  *
186  * Description      Fetches all the remote device properties from NVRAM
187  *
188  ******************************************************************************/
189 void btif_get_remote_device_properties(RawAddress remote_addr);
190 
191 /*******************************************************************************
192  *
193  * Function         btif_set_remote_device_property
194  *
195  * Description      Writes the remote device property to NVRAM.
196  *                  Currently, BT_PROPERTY_REMOTE_FRIENDLY_NAME is the only
197  *                  remote device property that can be set
198  *
199  ******************************************************************************/
200 void btif_set_remote_device_property(RawAddress* remote_addr, bt_property_t* property);
201 
202 /*******************************************************************************
203  *  BTIF DM API
204  ******************************************************************************/
205 
206 /*******************************************************************************
207  *
208  * Function         btif_dm_start_discovery
209  *
210  * Description      Start device discovery/inquiry
211  *
212  ******************************************************************************/
213 void btif_dm_start_discovery(void);
214 
215 /*******************************************************************************
216  *
217  * Function         btif_dm_cancel_discovery
218  *
219  * Description      Cancels search
220  *
221  ******************************************************************************/
222 void btif_dm_cancel_discovery(void);
223 
224 bool btif_dm_pairing_is_busy();
225 /*******************************************************************************
226  *
227  * Function         btif_dm_create_bond
228  *
229  * Description      Initiate bonding with the specified device
230  *
231  ******************************************************************************/
232 void btif_dm_create_bond(const RawAddress bd_addr, tBT_TRANSPORT transport);
233 
234 /*******************************************************************************
235  *
236  * Function         btif_dm_create_bond_le
237  *
238  * Description      Initiate bonding with the specified device over le transport
239  *
240  ******************************************************************************/
241 void btif_dm_create_bond_le(const RawAddress bd_addr, uint8_t addr_type);
242 
243 /*******************************************************************************
244  *
245  * Function         btif_dm_create_bond_out_of_band
246  *
247  * Description      Initiate bonding with the specified device using OOB data.
248  *
249  ******************************************************************************/
250 void btif_dm_create_bond_out_of_band(const RawAddress bd_addr, tBT_TRANSPORT transport,
251                                      const bt_oob_data_t p192_data, const bt_oob_data_t p256_data);
252 
253 /*******************************************************************************
254  *
255  * Function         btif_dm_cancel_bond
256  *
257  * Description      Initiate bonding with the specified device
258  *
259  ******************************************************************************/
260 void btif_dm_cancel_bond(const RawAddress bd_addr);
261 
262 /*******************************************************************************
263  *
264  * Function         btif_dm_remove_bond
265  *
266  * Description      Removes bonding with the specified device
267  *
268  ******************************************************************************/
269 void btif_dm_remove_bond(const RawAddress bd_addr);
270 
271 /*******************************************************************************
272  *
273  * Function         btif_dm_get_connection_state
274  *                  btif_dm_get_connection_state_sync
275  *
276  * Description      Returns bitmask on remote device connection state indicating
277  *                  connection and encryption.  The `_sync` version properly
278  *                  synchronizes the state and is the preferred mechanism.
279  *                  NOTE: Currently no address resolution is attempted upon
280  *                  LE random addresses.
281  *
282  * Returns          '000 (0x0000) if not connected
283  *                  '001 (0x0001) Connected with no encryption to remote
284  *                                device on BR/EDR or LE ACL
285  *                  '011 (0x0003) Connected with encryption to remote
286  *                                device on BR/EDR ACL
287  *                  '101 (0x0005) Connected with encruption to remote
288  *                                device on LE ACL
289  *                  '111 (0x0007) Connected with encruption to remote
290  *                                device on both BR/EDR and LE ACLs
291  *                  All other values are reserved
292  *
293  ******************************************************************************/
294 uint16_t btif_dm_get_connection_state(const RawAddress& bd_addr);
295 uint16_t btif_dm_get_connection_state_sync(const RawAddress& bd_addr);
296 
297 /*******************************************************************************
298  *
299  * Function         btif_dm_pin_reply
300  *
301  * Description      BT legacy pairing - PIN code reply
302  *
303  ******************************************************************************/
304 void btif_dm_pin_reply(const RawAddress bd_addr, uint8_t accept, uint8_t pin_len,
305                        bt_pin_code_t pin_code);
306 
307 /*******************************************************************************
308  *
309  * Function         btif_dm_passkey_reply
310  *
311  * Description      BT SSP passkey reply
312  *
313  * Returns          bt_status_t
314  *
315  ******************************************************************************/
316 bt_status_t btif_dm_passkey_reply(const RawAddress* bd_addr, uint8_t accept, uint32_t passkey);
317 
318 /*******************************************************************************
319  *
320  * Function         btif_dm_ssp_reply
321  *
322  * Description      BT SSP Reply - Just Works, Numeric Comparison & Passkey
323  *                  Entry
324  *
325  ******************************************************************************/
326 void btif_dm_ssp_reply(const RawAddress bd_addr, bt_ssp_variant_t variant, uint8_t accept);
327 
328 /*******************************************************************************
329  *
330  * Function         btif_dm_get_adapter_property
331  *
332  * Description      Queries the BTA for the adapter property
333  *
334  * Returns          bt_status_t
335  *
336  ******************************************************************************/
337 bt_status_t btif_dm_get_adapter_property(bt_property_t* prop);
338 
339 /*******************************************************************************
340  *
341  * Function         btif_dm_get_remote_services
342  *
343  * Description      Start SDP to get remote services
344  *
345  * Returns          bt_status_t
346  *
347  ******************************************************************************/
348 void btif_dm_get_remote_services(const RawAddress remote_addr, tBT_TRANSPORT transport);
349 
350 /*******************************************************************************
351  *
352  * Function         btif_dut_mode_configure
353  *
354  * Description      Configure Test Mode - 'enable' to 1 puts the device in test
355  *                  mode and 0 exits test mode
356  *
357  ******************************************************************************/
358 void btif_dut_mode_configure(uint8_t enable);
359 
360 bool btif_is_dut_mode();
361 
362 /*******************************************************************************
363  *
364  * Function         btif_dut_mode_send
365  *
366  * Description     Sends a HCI Vendor specific command to the controller
367  *
368  ******************************************************************************/
369 void btif_dut_mode_send(uint16_t opcode, uint8_t* buf, uint8_t len);
370 
371 void btif_ble_transmitter_test(uint8_t tx_freq, uint8_t test_data_len, uint8_t packet_payload);
372 
373 void btif_ble_receiver_test(uint8_t rx_freq);
374 void btif_ble_test_end();
375 
376 /*******************************************************************************
377  *
378  * Function         btif_dm_read_energy_info
379  *
380  * Description     Reads the energy info from controller
381  *
382  * Returns          void
383  *
384  ******************************************************************************/
385 void btif_dm_read_energy_info();
386 
387 /*******************************************************************************
388  *
389  * Function         btif_config_hci_snoop_log
390  *
391  * Description     enable or disable HCI snoop log
392  *
393  * Returns          BT_STATUS_SUCCESS on success
394  *
395  ******************************************************************************/
396 bt_status_t btif_config_hci_snoop_log(uint8_t enable);
397 
398 /*******************************************************************************
399  *
400  * Function         btif_debug_bond_event_dump
401  *
402  * Description     Dump bond event information
403  *
404  * Returns          void
405  *
406  ******************************************************************************/
407 void btif_debug_bond_event_dump(int fd);
408 
409 /*******************************************************************************
410  *
411  * Function         btif_set_dynamic_audio_buffer_size
412  *
413  * Description     Set dynamic audio buffer size
414  *
415  * Returns          BT_STATUS_SUCCESS on success
416  *
417  ******************************************************************************/
418 bt_status_t btif_set_dynamic_audio_buffer_size(int codec, int size);
419 
420 /*******************************************************************************
421  *
422  * Function         btif_debug_linkkey_type_dump
423  *
424  * Description     Dump exchanged linkkey types information
425  *
426  * Returns          void
427  *
428  ******************************************************************************/
429 void btif_debug_linkkey_type_dump(int fd);
430 
431 #endif /* BTIF_API_H */
432