• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 bool btif_dm_is_pairing(const RawAddress& bdaddr);
226 
227 /*******************************************************************************
228  *
229  * Function         btif_dm_create_bond
230  *
231  * Description      Initiate bonding with the specified device
232  *
233  ******************************************************************************/
234 void btif_dm_create_bond(const RawAddress bd_addr, tBT_TRANSPORT transport);
235 
236 /*******************************************************************************
237  *
238  * Function         btif_dm_create_bond_le
239  *
240  * Description      Initiate bonding with the specified device over le transport
241  *
242  ******************************************************************************/
243 void btif_dm_create_bond_le(const RawAddress bd_addr, uint8_t addr_type);
244 
245 /*******************************************************************************
246  *
247  * Function         btif_dm_create_bond_out_of_band
248  *
249  * Description      Initiate bonding with the specified device using OOB data.
250  *
251  ******************************************************************************/
252 void btif_dm_create_bond_out_of_band(const RawAddress bd_addr, tBT_TRANSPORT transport,
253                                      const bt_oob_data_t p192_data, const bt_oob_data_t p256_data);
254 
255 /*******************************************************************************
256  *
257  * Function         btif_dm_cancel_bond
258  *
259  * Description      Initiate bonding with the specified device
260  *
261  ******************************************************************************/
262 void btif_dm_cancel_bond(const RawAddress bd_addr);
263 
264 /*******************************************************************************
265  *
266  * Function         btif_dm_remove_bond
267  *
268  * Description      Removes bonding with the specified device
269  *
270  ******************************************************************************/
271 void btif_dm_remove_bond(const RawAddress bd_addr);
272 
273 /*******************************************************************************
274  *
275  * Function         btif_dm_get_connection_state
276  *                  btif_dm_get_connection_state_sync
277  *
278  * Description      Returns bitmask on remote device connection state indicating
279  *                  connection and encryption.  The `_sync` version properly
280  *                  synchronizes the state and is the preferred mechanism.
281  *                  NOTE: Currently no address resolution is attempted upon
282  *                  LE random addresses.
283  *
284  * Returns          '000 (0x0000) if not connected
285  *                  '001 (0x0001) Connected with no encryption to remote
286  *                                device on BR/EDR or LE ACL
287  *                  '011 (0x0003) Connected with encryption to remote
288  *                                device on BR/EDR ACL
289  *                  '101 (0x0005) Connected with encruption to remote
290  *                                device on LE ACL
291  *                  '111 (0x0007) Connected with encruption to remote
292  *                                device on both BR/EDR and LE ACLs
293  *                  All other values are reserved
294  *
295  ******************************************************************************/
296 uint16_t btif_dm_get_connection_state(const RawAddress& bd_addr);
297 uint16_t btif_dm_get_connection_state_sync(const RawAddress& bd_addr);
298 
299 /*******************************************************************************
300  *
301  * Function         btif_dm_pin_reply
302  *
303  * Description      BT legacy pairing - PIN code reply
304  *
305  ******************************************************************************/
306 void btif_dm_pin_reply(const RawAddress bd_addr, uint8_t accept, uint8_t pin_len,
307                        bt_pin_code_t pin_code);
308 
309 /*******************************************************************************
310  *
311  * Function         btif_dm_ssp_reply
312  *
313  * Description      BT SSP Reply - Just Works, Numeric Comparison & Passkey
314  *                  Entry
315  *
316  ******************************************************************************/
317 void btif_dm_ssp_reply(const RawAddress bd_addr, bt_ssp_variant_t variant, uint8_t accept);
318 
319 /*******************************************************************************
320  *
321  * Function         btif_dm_get_adapter_property
322  *
323  * Description      Queries the BTA for the adapter property
324  *
325  * Returns          bt_status_t
326  *
327  ******************************************************************************/
328 bt_status_t btif_dm_get_adapter_property(bt_property_t* prop);
329 
330 /*******************************************************************************
331  *
332  * Function         btif_dm_get_remote_services
333  *
334  * Description      Start SDP to get remote services
335  *
336  * Returns          bt_status_t
337  *
338  ******************************************************************************/
339 void btif_dm_get_remote_services(const RawAddress remote_addr, tBT_TRANSPORT transport);
340 
341 /*******************************************************************************
342  *
343  * Function         btif_dut_mode_configure
344  *
345  * Description      Configure Test Mode - 'enable' to 1 puts the device in test
346  *                  mode and 0 exits test mode
347  *
348  ******************************************************************************/
349 void btif_dut_mode_configure(uint8_t enable);
350 
351 bool btif_is_dut_mode();
352 
353 /*******************************************************************************
354  *
355  * Function         btif_dut_mode_send
356  *
357  * Description     Sends a HCI Vendor specific command to the controller
358  *
359  ******************************************************************************/
360 void btif_dut_mode_send(uint16_t opcode, uint8_t* buf, uint8_t len);
361 
362 void btif_ble_transmitter_test(uint8_t tx_freq, uint8_t test_data_len, uint8_t packet_payload);
363 
364 void btif_ble_receiver_test(uint8_t rx_freq);
365 void btif_ble_test_end();
366 
367 /*******************************************************************************
368  *
369  * Function         btif_dm_read_energy_info
370  *
371  * Description     Reads the energy info from controller
372  *
373  * Returns          void
374  *
375  ******************************************************************************/
376 void btif_dm_read_energy_info();
377 
378 /*******************************************************************************
379  *
380  * Function         btif_config_hci_snoop_log
381  *
382  * Description     enable or disable HCI snoop log
383  *
384  * Returns          BT_STATUS_SUCCESS on success
385  *
386  ******************************************************************************/
387 bt_status_t btif_config_hci_snoop_log(uint8_t enable);
388 
389 /*******************************************************************************
390  *
391  * Function         btif_debug_bond_event_dump
392  *
393  * Description     Dump bond event information
394  *
395  * Returns          void
396  *
397  ******************************************************************************/
398 void btif_debug_bond_event_dump(int fd);
399 
400 /*******************************************************************************
401  *
402  * Function         btif_set_dynamic_audio_buffer_size
403  *
404  * Description     Set dynamic audio buffer size
405  *
406  * Returns          BT_STATUS_SUCCESS on success
407  *
408  ******************************************************************************/
409 bt_status_t btif_set_dynamic_audio_buffer_size(int codec, int size);
410 
411 /*******************************************************************************
412  *
413  * Function         btif_debug_linkkey_type_dump
414  *
415  * Description     Dump exchanged linkkey types information
416  *
417  * Returns          void
418  *
419  ******************************************************************************/
420 void btif_debug_linkkey_type_dump(int fd);
421 
422 #endif /* BTIF_API_H */
423