blob: e5e030b41f3a26416cbd8abdb049a907dc2ebd9f [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
Hemant Gupta94c15ec2013-11-11 12:33:44 +05303 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
4 * Not a Contribution.
The Android Open Source Project5738f832012-12-12 16:00:35 -08005 * Copyright (C) 2009-2012 Broadcom Corporation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at:
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ******************************************************************************/
20
21/************************************************************************************
22 *
23 * Filename: btif_dm.c
24 *
25 * Description: Contains Device Management (DM) related functionality
26 *
27 *
28 ***********************************************************************************/
Sharvil Nanavati44802762014-12-23 23:08:58 -080029
Chris Mantonf8027002015-03-12 09:22:48 -070030#define LOG_TAG "bt_btif_dm"
Sharvil Nanavati44802762014-12-23 23:08:58 -080031
Andre Eisenbach8a057242015-04-29 22:27:15 -070032#include <assert.h>
Scott James Remnant933926c2015-04-02 15:22:14 -070033#include <signal.h>
The Android Open Source Project5738f832012-12-12 16:00:35 -080034#include <stdio.h>
35#include <stdlib.h>
Ian Coolidgec7503db2015-01-24 02:01:26 -080036#include <string.h>
Scott James Remnant933926c2015-04-02 15:22:14 -070037#include <sys/types.h>
The Android Open Source Project5738f832012-12-12 16:00:35 -080038#include <unistd.h>
39
40#include <hardware/bluetooth.h>
41
The Android Open Source Project5738f832012-12-12 16:00:35 -080042#include <cutils/properties.h>
43#include "gki.h"
44#include "btu.h"
Sharvil Nanavati95b74f22015-03-12 15:55:21 -070045#include "btcore/include/bdaddr.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080046#include "bta_api.h"
47#include "btif_api.h"
48#include "btif_util.h"
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080049#include "btif_dm.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080050#include "btif_storage.h"
51#include "btif_hh.h"
Hemant Gupta94c15ec2013-11-11 12:33:44 +053052#include "btif_hd.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080053#include "btif_config.h"
Kim Schulz8372aa52015-03-25 10:39:40 +010054#include "btif_sdp.h"
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080055#include "bta_gatt_api.h"
Andre Eisenbach27c4e632015-07-06 15:43:15 -070056#include "device/include/interop.h"
Sharvil Nanavati44802762014-12-23 23:08:58 -080057#include "include/stack_config.h"
58#include "osi/include/log.h"
Andre Eisenbach8a057242015-04-29 22:27:15 -070059#include "osi/include/allocator.h"
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -070060#include "stack/btm/btm_int.h"
Andre Eisenbach31a64002014-10-14 14:29:19 -070061
62/******************************************************************************
The Android Open Source Project5738f832012-12-12 16:00:35 -080063** Constants & Macros
64******************************************************************************/
65
66#define COD_UNCLASSIFIED ((0x1F) << 8)
Priti Agheraebb1d752012-11-27 18:03:22 -080067#define COD_HID_KEYBOARD 0x0540
68#define COD_HID_POINTING 0x0580
69#define COD_HID_COMBO 0x05C0
70#define COD_HID_MAJOR 0x0500
71#define COD_AV_HEADSETS 0x0404
72#define COD_AV_HANDSFREE 0x0408
73#define COD_AV_HEADPHONES 0x0418
74#define COD_AV_PORTABLE_AUDIO 0x041C
75#define COD_AV_HIFI_AUDIO 0x0428
The Android Open Source Project5738f832012-12-12 16:00:35 -080076
77
78#define BTIF_DM_DEFAULT_INQ_MAX_RESULTS 0
79#define BTIF_DM_DEFAULT_INQ_MAX_DURATION 10
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -070080#define BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING 2
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080081
Andre Eisenbach31a64002014-10-14 14:29:19 -070082#define NUM_TIMEOUT_RETRIES 5
83
Matthew Xie1e5109b2012-11-09 18:26:26 -080084#define PROPERTY_PRODUCT_MODEL "ro.product.model"
Matthew Xiea30d95a2013-09-18 12:30:36 -070085#define DEFAULT_LOCAL_NAME_MAX 31
Matthew Xie1e5109b2012-11-09 18:26:26 -080086#if (DEFAULT_LOCAL_NAME_MAX > BTM_MAX_LOC_BD_NAME_LEN)
87 #error "default btif local name size exceeds stack supported length"
88#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080089
Matthew Xie7f3e4292013-09-30 12:44:10 -070090#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
91#define BTIF_DM_INTERLEAVE_DURATION_BR_ONE 2
92#define BTIF_DM_INTERLEAVE_DURATION_LE_ONE 2
93#define BTIF_DM_INTERLEAVE_DURATION_BR_TWO 3
94#define BTIF_DM_INTERLEAVE_DURATION_LE_TWO 4
95#endif
96
Priti Agherac0edf9f2014-06-26 11:23:51 -070097#define MAX_SDP_BL_ENTRIES 3
98
Andre Eisenbachdfb3b2f2015-02-05 20:00:45 -080099#define ENCRYPTED_BREDR 2
100#define ENCRYPTED_LE 4
101
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800102typedef struct
103{
The Android Open Source Project5738f832012-12-12 16:00:35 -0800104 bt_bond_state_t state;
Andre Eisenbach12871662015-05-08 17:42:10 -0700105 bt_bdaddr_t static_bdaddr;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800106 BD_ADDR bd_addr;
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -0700107 tBTM_BOND_TYPE bond_type;
Chaojing Sune2805532015-04-22 13:40:21 -0700108 UINT8 pin_code_len;
109 UINT8 is_ssp;
110 UINT8 auth_req;
111 UINT8 io_cap;
112 UINT8 autopair_attempts;
113 UINT8 timeout_retries;
114 UINT8 is_local_initiated;
115 UINT8 sdp_attempts;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800116#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Chaojing Sune2805532015-04-22 13:40:21 -0700117 BOOLEAN is_le_only;
118 BOOLEAN is_le_nc; /* LE Numeric comparison */
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800119 btif_dm_ble_cb_t ble;
120#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800121} btif_dm_pairing_cb_t;
122
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800123
124typedef struct
125{
126 UINT8 ir[BT_OCTET16_LEN];
127 UINT8 irk[BT_OCTET16_LEN];
128 UINT8 dhk[BT_OCTET16_LEN];
129}btif_dm_local_key_id_t;
130
131typedef struct
132{
133 BOOLEAN is_er_rcvd;
134 UINT8 er[BT_OCTET16_LEN];
135 BOOLEAN is_id_keys_rcvd;
136 btif_dm_local_key_id_t id_keys; /* ID kyes */
137
138}btif_dm_local_key_cb_t;
139
140typedef struct
141{
The Android Open Source Project5738f832012-12-12 16:00:35 -0800142 BD_ADDR bd_addr;
143 BD_NAME bd_name;
144} btif_dm_remote_name_t;
145
146typedef struct
147{
148 BT_OCTET16 sp_c;
149 BT_OCTET16 sp_r;
150 BD_ADDR oob_bdaddr; /* peer bdaddr*/
151} btif_dm_oob_cb_t;
Satya Callojie5ba8842014-07-03 17:18:02 -0700152
153typedef struct
154{
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -0700155 bt_bdaddr_t bdaddr;
156 UINT8 transport; /* 0=Unknown, 1=BR/EDR, 2=LE */
157} btif_dm_create_bond_cb_t;
158
159typedef struct
160{
Satya Callojie5ba8842014-07-03 17:18:02 -0700161 uint8_t status;
162 uint8_t ctrl_state;
163 uint64_t tx_time;
164 uint64_t rx_time;
165 uint64_t idle_time;
166 uint64_t energy_used;
167} btif_activity_energy_info_cb_t;
168
The Android Open Source Project5738f832012-12-12 16:00:35 -0800169#define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id))
170
Priti Agherac0edf9f2014-06-26 11:23:51 -0700171#define UUID_HUMAN_INTERFACE_DEVICE "00001124-0000-1000-8000-00805f9b34fb"
172
The Android Open Source Project5738f832012-12-12 16:00:35 -0800173/* This flag will be true if HCI_Inquiry is in progress */
174static BOOLEAN btif_dm_inquiry_in_progress = FALSE;
175
Matthew Xie1e5109b2012-11-09 18:26:26 -0800176/************************************************************************************
177** Static variables
178************************************************************************************/
179static char btif_default_local_name[DEFAULT_LOCAL_NAME_MAX+1] = {'\0'};
180
The Android Open Source Project5738f832012-12-12 16:00:35 -0800181/******************************************************************************
182** Static functions
183******************************************************************************/
184static btif_dm_pairing_cb_t pairing_cb;
185static btif_dm_oob_cb_t oob_cb;
186static void btif_dm_generic_evt(UINT16 event, char* p_param);
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -0700187static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr, tBTA_TRANSPORT transport);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800188static void btif_dm_cb_hid_remote_name(tBTM_REMOTE_DEV_NAME *p_remote_name);
189static void btif_update_remote_properties(BD_ADDR bd_addr, BD_NAME bd_name,
190 DEV_CLASS dev_class, tBT_DEVICE_TYPE dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800191#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
192static btif_dm_local_key_cb_t ble_local_key_cb;
193static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif);
194static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl);
195static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ *p_pin_req);
Satya Calloji444a8da2015-03-06 10:38:22 -0800196static void btif_dm_ble_key_nc_req_evt(tBTA_DM_SP_KEY_NOTIF *p_notif_req) ;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800197#endif
Satya Calloji6e2d9db2014-07-08 16:18:58 -0700198
199static void bte_scan_filt_param_cfg_evt(UINT8 action_type,
200 tBTA_DM_BLE_PF_AVBL_SPACE avbl_space,
201 tBTA_DM_BLE_REF_VALUE ref_value, tBTA_STATUS status);
202
Matthew Xie1e5109b2012-11-09 18:26:26 -0800203static char* btif_get_default_local_name();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800204/******************************************************************************
205** Externs
206******************************************************************************/
207extern UINT16 bta_service_id_to_uuid_lkup_tbl [BTA_MAX_SERVICE_ID];
208extern bt_status_t btif_hf_execute_service(BOOLEAN b_enable);
209extern bt_status_t btif_av_execute_service(BOOLEAN b_enable);
Rakesh Iyer9c8dfac2015-04-08 12:25:37 -0700210extern bt_status_t btif_av_sink_execute_service(BOOLEAN b_enable);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800211extern bt_status_t btif_hh_execute_service(BOOLEAN b_enable);
Hemant Gupta10256872013-08-19 18:33:01 +0530212extern bt_status_t btif_hf_client_execute_service(BOOLEAN b_enable);
Kim Schulz8372aa52015-03-25 10:39:40 +0100213extern bt_status_t btif_sdp_execute_service(BOOLEAN b_enable);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800214extern int btif_hh_connect(bt_bdaddr_t *bd_addr);
Hemant Gupta94c15ec2013-11-11 12:33:44 +0530215extern bt_status_t btif_hd_execute_service(BOOLEAN b_enable);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700216extern void bta_gatt_convert_uuid16_to_uuid128(UINT8 uuid_128[LEN_UUID_128], UINT16 uuid_16);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800217
218
219/******************************************************************************
220** Functions
221******************************************************************************/
222
Andre Eisenbach8a057242015-04-29 22:27:15 -0700223static void btif_dm_data_copy(uint16_t event, char *dst, char *src)
224{
225 tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC*)dst;
226 tBTA_DM_SEC *src_dm_sec = (tBTA_DM_SEC*)src;
227
228 if (!src_dm_sec)
229 return;
230
231 assert(dst_dm_sec);
232 memcpy(dst_dm_sec, src_dm_sec, sizeof(tBTA_DM_SEC));
233
234 if (event == BTA_DM_BLE_KEY_EVT)
235 {
236 dst_dm_sec->ble_key.p_key_value = osi_malloc(sizeof(tBTM_LE_KEY_VALUE));
237 assert(src_dm_sec->ble_key.p_key_value);
238 assert(dst_dm_sec->ble_key.p_key_value);
239 memcpy(dst_dm_sec->ble_key.p_key_value, src_dm_sec->ble_key.p_key_value, sizeof(tBTM_LE_KEY_VALUE));
240 }
241}
242
243static void btif_dm_data_free(uint16_t event, tBTA_DM_SEC *dm_sec)
244{
245 if (event == BTA_DM_BLE_KEY_EVT)
246 osi_free(dm_sec->ble_key.p_key_value);
247}
248
The Android Open Source Project5738f832012-12-12 16:00:35 -0800249bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id,
250 BOOLEAN b_enable)
251{
Kim Schulz8372aa52015-03-25 10:39:40 +0100252 BTIF_TRACE_DEBUG("%s service_id: %d", __FUNCTION__, service_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800253 /* Check the service_ID and invoke the profile's BT state changed API */
254 switch (service_id)
255 {
256 case BTA_HFP_SERVICE_ID:
257 case BTA_HSP_SERVICE_ID:
258 {
259 btif_hf_execute_service(b_enable);
260 }break;
Sharvil Nanavati9609cee2014-10-15 18:30:49 -0700261 case BTA_A2DP_SOURCE_SERVICE_ID:
The Android Open Source Project5738f832012-12-12 16:00:35 -0800262 {
263 btif_av_execute_service(b_enable);
264 }break;
Rakesh Iyer9c8dfac2015-04-08 12:25:37 -0700265 case BTA_A2DP_SINK_SERVICE_ID:
266 {
267 btif_av_sink_execute_service(b_enable);
268 }break;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800269 case BTA_HID_SERVICE_ID:
270 {
271 btif_hh_execute_service(b_enable);
272 }break;
Hemant Gupta10256872013-08-19 18:33:01 +0530273 case BTA_HFP_HS_SERVICE_ID:
274 {
275 btif_hf_client_execute_service(b_enable);
276 }break;
Kim Schulz8372aa52015-03-25 10:39:40 +0100277 case BTA_SDP_SERVICE_ID:
Hemant Gupta2dc99992014-04-18 12:54:08 +0530278 {
Kim Schulz8372aa52015-03-25 10:39:40 +0100279 btif_sdp_execute_service(b_enable);
Hemant Gupta2dc99992014-04-18 12:54:08 +0530280 }break;
Hemant Gupta94c15ec2013-11-11 12:33:44 +0530281 case BTA_HIDD_SERVICE_ID:
282 {
283 btif_hd_execute_service(b_enable);
284 }break;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800285 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700286 BTIF_TRACE_ERROR("%s: Unknown service being enabled", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800287 return BT_STATUS_FAIL;
288 }
289 return BT_STATUS_SUCCESS;
290}
291
292/*******************************************************************************
293**
294** Function check_eir_remote_name
295**
296** Description Check if remote name is in the EIR data
297**
298** Returns TRUE if remote name found
299** Populate p_remote_name, if provided and remote name found
300**
301*******************************************************************************/
302static BOOLEAN check_eir_remote_name(tBTA_DM_SEARCH *p_search_data,
303 UINT8 *p_remote_name, UINT8 *p_remote_name_len)
304{
305 UINT8 *p_eir_remote_name = NULL;
306 UINT8 remote_name_len = 0;
307
308 /* Check EIR for remote name and services */
309 if (p_search_data->inq_res.p_eir)
310 {
Zach Johnsona50fc882014-10-30 21:02:58 -0700311 p_eir_remote_name = BTM_CheckEirData(p_search_data->inq_res.p_eir,
The Android Open Source Project5738f832012-12-12 16:00:35 -0800312 BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, &remote_name_len);
313 if (!p_eir_remote_name)
314 {
Zach Johnsona50fc882014-10-30 21:02:58 -0700315 p_eir_remote_name = BTM_CheckEirData(p_search_data->inq_res.p_eir,
The Android Open Source Project5738f832012-12-12 16:00:35 -0800316 BTM_EIR_SHORTENED_LOCAL_NAME_TYPE, &remote_name_len);
317 }
318
319 if (p_eir_remote_name)
320 {
321 if (remote_name_len > BD_NAME_LEN)
322 remote_name_len = BD_NAME_LEN;
323
324 if (p_remote_name && p_remote_name_len)
325 {
326 memcpy(p_remote_name, p_eir_remote_name, remote_name_len);
327 *(p_remote_name + remote_name_len) = 0;
328 *p_remote_name_len = remote_name_len;
329 }
330
331 return TRUE;
332 }
333 }
334
335 return FALSE;
336
337}
338
339/*******************************************************************************
340**
341** Function check_cached_remote_name
342**
343** Description Check if remote name is in the NVRAM cache
344**
345** Returns TRUE if remote name found
346** Populate p_remote_name, if provided and remote name found
347**
348*******************************************************************************/
349static BOOLEAN check_cached_remote_name(tBTA_DM_SEARCH *p_search_data,
350 UINT8 *p_remote_name, UINT8 *p_remote_name_len)
351{
352 bt_bdname_t bdname;
353 bt_bdaddr_t remote_bdaddr;
354 bt_property_t prop_name;
355
356 /* check if we already have it in our btif_storage cache */
357 bdcpy(remote_bdaddr.address, p_search_data->inq_res.bd_addr);
358 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_BDNAME,
359 sizeof(bt_bdname_t), &bdname);
360 if (btif_storage_get_remote_device_property(
361 &remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS)
362 {
363 if (p_remote_name && p_remote_name_len)
364 {
365 strcpy((char *)p_remote_name, (char *)bdname.name);
366 *p_remote_name_len = strlen((char *)p_remote_name);
367 }
368 return TRUE;
369 }
370
371 return FALSE;
372}
373
374BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod)
375{
376 uint32_t remote_cod;
377 bt_property_t prop_name;
378
379 /* check if we already have it in our btif_storage cache */
380 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE,
381 sizeof(uint32_t), &remote_cod);
382 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS)
383 {
Chris Mantonf8027002015-03-12 09:22:48 -0700384 LOG_INFO("%s remote_cod = 0x%08x cod = 0x%08x", __func__, remote_cod, cod);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800385 if ((remote_cod & 0x7ff) == cod)
386 return TRUE;
387 }
388
389 return FALSE;
390}
391
Priti Agheraebb1d752012-11-27 18:03:22 -0800392BOOLEAN check_cod_hid(const bt_bdaddr_t *remote_bdaddr, uint32_t cod)
393{
394 uint32_t remote_cod;
395 bt_property_t prop_name;
396
397 /* check if we already have it in our btif_storage cache */
398 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE,
399 sizeof(uint32_t), &remote_cod);
400 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
401 &prop_name) == BT_STATUS_SUCCESS)
402 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700403 BTIF_TRACE_DEBUG("%s: remote_cod = 0x%06x", __FUNCTION__, remote_cod);
Hemant Guptae4def912014-09-18 14:19:57 +0530404 if ((remote_cod & 0x700) == cod) {
405 BTIF_TRACE_DEBUG("%s: returning TRUE", __FUNCTION__);
Priti Agheraebb1d752012-11-27 18:03:22 -0800406 return TRUE;
Hemant Guptae4def912014-09-18 14:19:57 +0530407 }
Priti Agheraebb1d752012-11-27 18:03:22 -0800408 }
Hemant Guptae4def912014-09-18 14:19:57 +0530409 BTIF_TRACE_DEBUG("%s: returning FALSE", __FUNCTION__);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700410 return FALSE;
411}
Priti Agheraebb1d752012-11-27 18:03:22 -0800412
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700413BOOLEAN check_hid_le(const bt_bdaddr_t *remote_bdaddr)
414{
415 uint32_t remote_dev_type;
416 bt_property_t prop_name;
417
418 /* check if we already have it in our btif_storage cache */
419 BTIF_STORAGE_FILL_PROPERTY(&prop_name,BT_PROPERTY_TYPE_OF_DEVICE,
420 sizeof(uint32_t), &remote_dev_type);
421 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
422 &prop_name) == BT_STATUS_SUCCESS)
423 {
424 if (remote_dev_type == BT_DEVICE_DEVTYPE_BLE)
425 {
426 bdstr_t bdstr;
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -0700427 bdaddr_to_string(remote_bdaddr, bdstr, sizeof(bdstr));
Sharvil Nanavati9d52f882014-08-19 09:50:18 -0700428 if(btif_config_exist(bdstr, "HidAppId"))
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700429 return TRUE;
430 }
431 }
Priti Agheraebb1d752012-11-27 18:03:22 -0800432 return FALSE;
433}
434
Priti Agherac0edf9f2014-06-26 11:23:51 -0700435/*****************************************************************************
436**
Hemant Guptada33b462015-04-26 10:32:57 +0530437** Function check_if_auth_bl
438**
439** Description Checks if a given device is blacklisted to skip authentication
440**
441** Parameters remote_bdaddr
442**
443** Returns TRUE if the device is present in blacklist, else FALSE
444**
445*******************************************************************************/
446static bool check_if_auth_bl(bt_bdaddr_t * remote_bdaddr)
447{
448 if (remote_bdaddr == NULL) {
449 LOG_WARN("%s: remote_bdaddr = NULL, returning false", __func__);
450 return FALSE;
451 }
452
453 bt_property_t prop_name;
454 bt_bdname_t bdname;
455
456 if (interop_addr_match(INTEROP_DISABLE_AUTH_FOR_HID_POINTING, remote_bdaddr))
457 return TRUE;
458
459 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_BDNAME,
460 sizeof(bt_bdname_t), &bdname);
461 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
462 &prop_name) != BT_STATUS_SUCCESS)
463 {
464 LOG_WARN("%s: BT_PROPERTY_BDNAME failed, returning false", __func__);
465 return FALSE;
466 }
467
468 if (bdname.name != NULL &&
469 interop_name_match(INTEROP_DISABLE_SDP_AFTER_PAIRING, (const char *)bdname.name))
470 return TRUE;
471
472 char bdstr[20] = {0};
473 LOG_DEBUG("%s: %s is not in blacklist for skipping auth", __func__,
474 bdaddr_to_string(remote_bdaddr, bdstr, sizeof(bdstr)));
475 return FALSE;
476}
477
478/*****************************************************************************
479**
Priti Agherac0edf9f2014-06-26 11:23:51 -0700480** Function check_sdp_bl
481**
482** Description Checks if a given device is blacklisted to skip sdp
483**
Hemant Guptada33b462015-04-26 10:32:57 +0530484** Parameters remote_bdaddr
Priti Agherac0edf9f2014-06-26 11:23:51 -0700485**
486** Returns TRUE if the device is present in blacklist, else FALSE
487**
488*******************************************************************************/
489BOOLEAN check_sdp_bl(const bt_bdaddr_t *remote_bdaddr)
490{
Hemant Guptada33b462015-04-26 10:32:57 +0530491 if (remote_bdaddr == NULL) {
492 LOG_WARN("%s: remote_bdaddr = NULL, returning false", __func__);
493 return FALSE;
494 }
495
496 if (interop_addr_match(INTEROP_DISABLE_SDP_AFTER_PAIRING, remote_bdaddr)) {
497 LOG_WARN("%s: device is in blacklist for skipping sdp", __func__);
498 return TRUE;
499 }
500
501 bt_property_t prop_name;
502 bt_bdname_t bdname;
503 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_BDNAME,
504 sizeof(bt_bdname_t), &bdname);
505 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
506 &prop_name) != BT_STATUS_SUCCESS)
507 {
508 LOG_WARN("%s: BT_PROPERTY_BDNAME failed, returning false", __func__);
509 return FALSE;
510 }
511
512 if (bdname.name != NULL &&
513 interop_name_match(INTEROP_DISABLE_SDP_AFTER_PAIRING, (const char *)bdname.name))
514 return TRUE;
515
Priti Agherac0edf9f2014-06-26 11:23:51 -0700516 UINT16 manufacturer = 0;
517 UINT8 lmp_ver = 0;
518 UINT16 lmp_subver = 0;
Priti Agherac0edf9f2014-06-26 11:23:51 -0700519 bt_remote_version_t info;
Priti Agherac0edf9f2014-06-26 11:23:51 -0700520
Hemant Guptada33b462015-04-26 10:32:57 +0530521 /* fetch additional info about remote device used in iop query */
Sharvil Nanavatif1c764f2015-02-23 17:31:48 -0800522 BTM_ReadRemoteVersion(*(BD_ADDR*)remote_bdaddr, &lmp_ver,
Priti Agherac0edf9f2014-06-26 11:23:51 -0700523 &manufacturer, &lmp_subver);
524
Hemant Guptada33b462015-04-26 10:32:57 +0530525 /* if not available yet, try fetching from config database */
Priti Agherac0edf9f2014-06-26 11:23:51 -0700526 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_REMOTE_VERSION_INFO,
527 sizeof(bt_remote_version_t), &info);
528
529 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
530 &prop_name) != BT_STATUS_SUCCESS)
531 {
532
Hemant Guptada33b462015-04-26 10:32:57 +0530533 APPL_TRACE_WARNING("%s: BT_PROPERTY_REMOTE_VERSION_INFO failed, returning false", __func__);
Priti Agherac0edf9f2014-06-26 11:23:51 -0700534 return FALSE;
535 }
536 manufacturer = info.manufacturer;
537
Hemant Guptada33b462015-04-26 10:32:57 +0530538 if (manufacturer != 0 &&
539 interop_manufacturer_match(INTEROP_DISABLE_SDP_AFTER_PAIRING, manufacturer))
540 return TRUE;
541
542 char bdstr[20] = {0};
543 LOG_DEBUG("%s: %s is not in blacklist for skipping sdp", __func__,
544 bdaddr_to_string(remote_bdaddr, bdstr, sizeof(bdstr)));
Priti Agherac0edf9f2014-06-26 11:23:51 -0700545 return FALSE;
546}
547
The Android Open Source Project5738f832012-12-12 16:00:35 -0800548static void bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr, bt_bond_state_t state)
549{
Chaojing Sune2805532015-04-22 13:40:21 -0700550 // Send bonding state only once - based on outgoing/incoming we may receive duplicates
551 if ((pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING))
552 {
553 // Cross key pairing so send callback for static address
Andre Eisenbache87ef6d2015-05-01 13:14:59 -0700554 if (!bdaddr_is_empty(&pairing_cb.static_bdaddr))
555 {
Chaojing Sune2805532015-04-22 13:40:21 -0700556 HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state);
Andre Eisenbache87ef6d2015-05-01 13:14:59 -0700557 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800558 return;
Chaojing Sune2805532015-04-22 13:40:21 -0700559 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800560
Andre Eisenbach89363762015-01-26 13:49:36 -0800561 if (pairing_cb.bond_type == BOND_TYPE_TEMPORARY)
Chaojing Sune2805532015-04-22 13:40:21 -0700562 state = BT_BOND_STATE_NONE;
563
564 BTIF_TRACE_DEBUG("%s: state=%d, prev_state=%d, sdp_attempts = %d", __func__,
565 state, pairing_cb.state, pairing_cb.sdp_attempts);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800566
567 HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state);
568
569 if (state == BT_BOND_STATE_BONDING)
570 {
571 pairing_cb.state = state;
572 bdcpy(pairing_cb.bd_addr, bd_addr->address);
Chaojing Sune2805532015-04-22 13:40:21 -0700573 } else {
574 if (!pairing_cb.sdp_attempts)
575 memset(&pairing_cb, 0, sizeof(pairing_cb));
576 else
577 BTIF_TRACE_DEBUG("%s: BR-EDR service discovery active", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800578 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800579}
580
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800581/* store remote version in bt config to always have access
582 to it post pairing*/
583static void btif_update_remote_version_property(bt_bdaddr_t *p_bd)
584{
585 bt_property_t property;
586 UINT8 lmp_ver = 0;
587 UINT16 lmp_subver = 0;
588 UINT16 mfct_set = 0;
589 tBTM_STATUS btm_status;
590 bt_remote_version_t info;
591 bt_status_t status;
592 bdstr_t bdstr;
593
594 btm_status = BTM_ReadRemoteVersion(*(BD_ADDR*)p_bd, &lmp_ver,
595 &mfct_set, &lmp_subver);
596
Sharvil Nanavati44802762014-12-23 23:08:58 -0800597 LOG_DEBUG("remote version info [%s]: %x, %x, %x", bdaddr_to_string(p_bd, bdstr, sizeof(bdstr)),
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800598 lmp_ver, mfct_set, lmp_subver);
599
600 if (btm_status == BTM_SUCCESS)
601 {
Chaojing Sune2805532015-04-22 13:40:21 -0700602 // Always update cache to ensure we have availability whenever BTM API is not populated
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800603 info.manufacturer = mfct_set;
604 info.sub_ver = lmp_subver;
605 info.version = lmp_ver;
606 BTIF_STORAGE_FILL_PROPERTY(&property,
607 BT_PROPERTY_REMOTE_VERSION_INFO, sizeof(bt_remote_version_t),
608 &info);
609 status = btif_storage_set_remote_device_property(p_bd, &property);
610 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote version", status);
611 }
612}
613
The Android Open Source Project5738f832012-12-12 16:00:35 -0800614
615static void btif_update_remote_properties(BD_ADDR bd_addr, BD_NAME bd_name,
616 DEV_CLASS dev_class, tBT_DEVICE_TYPE device_type)
617{
618 int num_properties = 0;
619 bt_property_t properties[3];
620 bt_bdaddr_t bdaddr;
621 bt_status_t status;
622 UINT32 cod;
623 bt_device_type_t dev_type;
624
625 memset(properties, 0, sizeof(properties));
626 bdcpy(bdaddr.address, bd_addr);
627
628 /* remote name */
629 if (strlen((const char *) bd_name))
630 {
631 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
632 BT_PROPERTY_BDNAME, strlen((char *)bd_name), bd_name);
633 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
634 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device name", status);
635 num_properties++;
636 }
637
638 /* class of device */
639 cod = devclass2uint(dev_class);
Chris Mantonf8027002015-03-12 09:22:48 -0700640 BTIF_TRACE_DEBUG("%s cod is 0x%06x", __func__, cod);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800641 if ( cod == 0) {
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530642 /* Try to retrieve cod from storage */
Chris Mantonf8027002015-03-12 09:22:48 -0700643 BTIF_TRACE_DEBUG("%s cod is 0, checking cod from storage", __func__);
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530644 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
645 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
646 status = btif_storage_get_remote_device_property(&bdaddr, &properties[num_properties]);
Chris Mantonf8027002015-03-12 09:22:48 -0700647 BTIF_TRACE_DEBUG("%s cod retrieved from storage is 0x%06x", __func__, cod);
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530648 if ( cod == 0) {
Chris Mantonf8027002015-03-12 09:22:48 -0700649 BTIF_TRACE_DEBUG("%s cod is again 0, set as unclassified", __func__);
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530650 cod = COD_UNCLASSIFIED;
651 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800652 }
653
654 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
655 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
656 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
657 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device class", status);
658 num_properties++;
659
660 /* device type */
Chaojing Sune2805532015-04-22 13:40:21 -0700661 bt_property_t prop_name;
662 uint8_t remote_dev_type;
663 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_TYPE_OF_DEVICE,
664 sizeof(uint8_t), &remote_dev_type);
665 if (btif_storage_get_remote_device_property(&bdaddr, &prop_name) == BT_STATUS_SUCCESS)
666 dev_type = remote_dev_type | device_type;
667 else
668 dev_type = device_type;
669
The Android Open Source Project5738f832012-12-12 16:00:35 -0800670 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
671 BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
672 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
673 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device type", status);
674 num_properties++;
675
676 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
677 status, &bdaddr, num_properties, properties);
678}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800679
680/*******************************************************************************
681**
682** Function btif_dm_cb_hid_remote_name
683**
684** Description Remote name callback for HID device. Called in btif context
685** Special handling for HID devices
686**
687** Returns void
688**
689*******************************************************************************/
690static void btif_dm_cb_hid_remote_name(tBTM_REMOTE_DEV_NAME *p_remote_name)
691{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700692 BTIF_TRACE_DEBUG("%s: status=%d pairing_cb.state=%d", __FUNCTION__, p_remote_name->status, pairing_cb.state);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800693 if (pairing_cb.state == BT_BOND_STATE_BONDING)
694 {
695 bt_bdaddr_t remote_bd;
696
697 bdcpy(remote_bd.address, pairing_cb.bd_addr);
698
699 if (p_remote_name->status == BTM_SUCCESS)
700 {
701 bond_state_changed(BT_STATUS_SUCCESS, &remote_bd, BT_BOND_STATE_BONDED);
702 }
703 else
704 bond_state_changed(BT_STATUS_FAIL, &remote_bd, BT_BOND_STATE_NONE);
705 }
706}
707
The Android Open Source Project5738f832012-12-12 16:00:35 -0800708/*******************************************************************************
709**
710** Function btif_dm_cb_create_bond
711**
712** Description Create bond initiated from the BTIF thread context
713** Special handling for HID devices
714**
715** Returns void
716**
717*******************************************************************************/
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -0700718static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr, tBTA_TRANSPORT transport)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800719{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800720 BOOLEAN is_hid = check_cod(bd_addr, COD_HID_POINTING);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800721 bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800722
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800723#if BLE_INCLUDED == TRUE
724 int device_type;
725 int addr_type;
726 bdstr_t bdstr;
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -0700727 bdaddr_to_string(bd_addr, bdstr, sizeof(bdstr));
Matthew Xie64c54792014-09-16 00:55:03 -0700728 if (transport == BT_TRANSPORT_LE)
729 {
Sharvil Nanavati9d52f882014-08-19 09:50:18 -0700730 if (!btif_config_get_int((char const *)&bdstr,"DevType", &device_type))
Matthew Xie64c54792014-09-16 00:55:03 -0700731 {
Sharvil Nanavati9d52f882014-08-19 09:50:18 -0700732 btif_config_set_int(bdstr, "DevType", BT_DEVICE_TYPE_BLE);
Matthew Xie64c54792014-09-16 00:55:03 -0700733 }
734 if (btif_storage_get_remote_addr_type(bd_addr, &addr_type) != BT_STATUS_SUCCESS)
735 {
736 btif_storage_set_remote_addr_type(bd_addr, BLE_ADDR_PUBLIC);
737 }
738 }
Sharvil Nanavati9d52f882014-08-19 09:50:18 -0700739 if((btif_config_get_int((char const *)&bdstr,"DevType", &device_type) &&
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800740 (btif_storage_get_remote_addr_type(bd_addr, &addr_type) == BT_STATUS_SUCCESS) &&
Chaojing Sune2805532015-04-22 13:40:21 -0700741 (device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE) || (transport == BT_TRANSPORT_LE))
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800742 {
Chaojing Sune2805532015-04-22 13:40:21 -0700743 BTA_DmAddBleDevice(bd_addr->address, addr_type, device_type);
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800744 }
745#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800746
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800747#if BLE_INCLUDED == TRUE
Chaojing Sune2805532015-04-22 13:40:21 -0700748 if(is_hid && (device_type & BT_DEVICE_TYPE_BLE) == 0)
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800749#else
750 if(is_hid)
751#endif
752 {
753 int status;
754 status = btif_hh_connect(bd_addr);
755 if(status != BT_STATUS_SUCCESS)
756 bond_state_changed(status, bd_addr, BT_BOND_STATE_NONE);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800757 }
758 else
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800759 {
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -0700760 BTA_DmBondByTransport((UINT8 *)bd_addr->address, transport);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800761 }
762 /* Track originator of bond creation */
763 pairing_cb.is_local_initiated = TRUE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800764
765}
766
767/*******************************************************************************
768**
769** Function btif_dm_cb_remove_bond
770**
771** Description remove bond initiated from the BTIF thread context
772** Special handling for HID devices
773**
774** Returns void
775**
776*******************************************************************************/
777void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr)
778{
The Android Open Source Project5738f832012-12-12 16:00:35 -0800779 /*special handling for HID devices */
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -0700780 /* VUP needs to be sent if its a HID Device. The HID HOST module will check if there
781 is a valid hid connection with this bd_addr. If yes VUP will be issued.*/
782#if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
783 if (btif_hh_virtual_unplug(bd_addr) != BT_STATUS_SUCCESS)
784#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800785 {
Chaojing Sune2805532015-04-22 13:40:21 -0700786 BTIF_TRACE_DEBUG("%s: Removing HH device", __func__);
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -0700787 BTA_DmRemoveDevice((UINT8 *)bd_addr->address);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800788 }
789}
790
791/*******************************************************************************
792**
Andre Eisenbach249f6002014-06-18 12:20:37 -0700793** Function btif_dm_get_connection_state
794**
795** Description Returns whether the remote device is currently connected
Andre Eisenbachdfb3b2f2015-02-05 20:00:45 -0800796** and whether encryption is active for the connection
Andre Eisenbach249f6002014-06-18 12:20:37 -0700797**
Andre Eisenbachdfb3b2f2015-02-05 20:00:45 -0800798** Returns 0 if not connected; 1 if connected and > 1 if connection is
799** encrypted
Andre Eisenbach249f6002014-06-18 12:20:37 -0700800**
801*******************************************************************************/
802uint16_t btif_dm_get_connection_state(const bt_bdaddr_t *bd_addr)
803{
Andre Eisenbachdfb3b2f2015-02-05 20:00:45 -0800804 uint8_t *bda = (uint8_t*)bd_addr->address;
805 uint16_t rc = BTA_DmGetConnectionState(bda);
806
807 if (rc != 0)
808 {
809 uint8_t flags = 0;
810
811 BTM_GetSecurityFlagsByTransport(bda, &flags, BT_TRANSPORT_BR_EDR);
812 BTIF_TRACE_DEBUG("%s: security flags (BR/EDR)=0x%02x", __FUNCTION__, flags);
813 if (flags & BTM_SEC_FLAG_ENCRYPTED)
814 rc |= ENCRYPTED_BREDR;
815
816 BTM_GetSecurityFlagsByTransport(bda, &flags, BT_TRANSPORT_LE);
817 BTIF_TRACE_DEBUG("%s: security flags (LE)=0x%02x", __FUNCTION__, flags);
818 if (flags & BTM_SEC_FLAG_ENCRYPTED)
819 rc |= ENCRYPTED_LE;
820 }
821
822 return rc;
Andre Eisenbach249f6002014-06-18 12:20:37 -0700823}
824
825/*******************************************************************************
826**
The Android Open Source Project5738f832012-12-12 16:00:35 -0800827** Function search_devices_copy_cb
828**
829** Description Deep copy callback for search devices event
830**
831** Returns void
832**
833*******************************************************************************/
834static void search_devices_copy_cb(UINT16 event, char *p_dest, char *p_src)
835{
836 tBTA_DM_SEARCH *p_dest_data = (tBTA_DM_SEARCH *) p_dest;
837 tBTA_DM_SEARCH *p_src_data = (tBTA_DM_SEARCH *) p_src;
838
839 if (!p_src)
840 return;
841
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700842 BTIF_TRACE_DEBUG("%s: event=%s", __FUNCTION__, dump_dm_search_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800843 memcpy(p_dest_data, p_src_data, sizeof(tBTA_DM_SEARCH));
844 switch (event)
845 {
846 case BTA_DM_INQ_RES_EVT:
847 {
848 if (p_src_data->inq_res.p_eir)
849 {
850 p_dest_data->inq_res.p_eir = (UINT8 *)(p_dest + sizeof(tBTA_DM_SEARCH));
851 memcpy(p_dest_data->inq_res.p_eir, p_src_data->inq_res.p_eir, HCI_EXT_INQ_RESPONSE_LEN);
852 }
853 }
854 break;
855
856 case BTA_DM_DISC_RES_EVT:
857 {
858 if (p_src_data->disc_res.raw_data_size && p_src_data->disc_res.p_raw_data)
859 {
860 p_dest_data->disc_res.p_raw_data = (UINT8 *)(p_dest + sizeof(tBTA_DM_SEARCH));
861 memcpy(p_dest_data->disc_res.p_raw_data,
862 p_src_data->disc_res.p_raw_data, p_src_data->disc_res.raw_data_size);
863 }
864 }
865 break;
866 }
867}
868
869static void search_services_copy_cb(UINT16 event, char *p_dest, char *p_src)
870{
871 tBTA_DM_SEARCH *p_dest_data = (tBTA_DM_SEARCH *) p_dest;
872 tBTA_DM_SEARCH *p_src_data = (tBTA_DM_SEARCH *) p_src;
873
874 if (!p_src)
875 return;
876 memcpy(p_dest_data, p_src_data, sizeof(tBTA_DM_SEARCH));
877 switch (event)
878 {
879 case BTA_DM_DISC_RES_EVT:
880 {
Kausik Sinnaswamy95664a92013-05-03 15:02:50 +0530881 if (p_src_data->disc_res.result == BTA_SUCCESS)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800882 {
Kausik Sinnaswamy95664a92013-05-03 15:02:50 +0530883 if (p_src_data->disc_res.num_uuids > 0)
884 {
885 p_dest_data->disc_res.p_uuid_list =
886 (UINT8*)(p_dest + sizeof(tBTA_DM_SEARCH));
887 memcpy(p_dest_data->disc_res.p_uuid_list, p_src_data->disc_res.p_uuid_list,
888 p_src_data->disc_res.num_uuids*MAX_UUID_SIZE);
889 GKI_freebuf(p_src_data->disc_res.p_uuid_list);
890 }
891 if (p_src_data->disc_res.p_raw_data != NULL)
892 {
893 GKI_freebuf(p_src_data->disc_res.p_raw_data);
894 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800895 }
896 } break;
897 }
898}
899/******************************************************************************
900**
901** BTIF DM callback events
902**
903*****************************************************************************/
904
905/*******************************************************************************
906**
907** Function btif_dm_pin_req_evt
908**
909** Description Executes pin request event in btif context
910**
911** Returns void
912**
913*******************************************************************************/
914static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
915{
916 bt_bdaddr_t bd_addr;
917 bt_bdname_t bd_name;
918 UINT32 cod;
919 bt_pin_code_t pin_code;
Matthew Xie86f97ed2014-11-10 10:24:46 -0800920 int dev_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800921
922 /* Remote properties update */
Matthew Xie86f97ed2014-11-10 10:24:46 -0800923 if (!btif_get_device_type(p_pin_req->bd_addr, &dev_type))
924 {
925 dev_type = BT_DEVICE_TYPE_BREDR;
926 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800927 btif_update_remote_properties(p_pin_req->bd_addr, p_pin_req->bd_name,
Matthew Xie86f97ed2014-11-10 10:24:46 -0800928 p_pin_req->dev_class, (tBT_DEVICE_TYPE) dev_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800929
930 bdcpy(bd_addr.address, p_pin_req->bd_addr);
931 memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN);
932
933 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
934
935 cod = devclass2uint(p_pin_req->dev_class);
936
Chris Mantonf8027002015-03-12 09:22:48 -0700937 if (cod == 0) {
938 BTIF_TRACE_DEBUG("%s cod is 0, set as unclassified", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800939 cod = COD_UNCLASSIFIED;
940 }
941
942 /* check for auto pair possiblity only if bond was initiated by local device */
Casper Bonde818d0f22015-05-21 11:08:45 +0200943 if (pairing_cb.is_local_initiated && (p_pin_req->min_16_digit == FALSE))
The Android Open Source Project5738f832012-12-12 16:00:35 -0800944 {
945 if (check_cod(&bd_addr, COD_AV_HEADSETS) ||
946 check_cod(&bd_addr, COD_AV_HANDSFREE) ||
947 check_cod(&bd_addr, COD_AV_HEADPHONES) ||
948 check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) ||
949 check_cod(&bd_addr, COD_AV_HIFI_AUDIO) ||
950 check_cod(&bd_addr, COD_HID_POINTING))
951 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700952 BTIF_TRACE_DEBUG("%s()cod matches for auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800953 /* Check if this device can be auto paired */
954 if ((btif_storage_is_device_autopair_blacklisted(&bd_addr) == FALSE) &&
955 (pairing_cb.autopair_attempts == 0))
956 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700957 BTIF_TRACE_DEBUG("%s() Attempting auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800958 pin_code.pin[0] = 0x30;
959 pin_code.pin[1] = 0x30;
960 pin_code.pin[2] = 0x30;
961 pin_code.pin[3] = 0x30;
962
963 pairing_cb.autopair_attempts++;
964 BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin);
965 return;
966 }
967 }
968 else if (check_cod(&bd_addr, COD_HID_KEYBOARD) ||
969 check_cod(&bd_addr, COD_HID_COMBO))
970 {
971 if(( btif_storage_is_fixed_pin_zeros_keyboard (&bd_addr) == TRUE) &&
972 (pairing_cb.autopair_attempts == 0))
973 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700974 BTIF_TRACE_DEBUG("%s() Attempting auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800975 pin_code.pin[0] = 0x30;
976 pin_code.pin[1] = 0x30;
977 pin_code.pin[2] = 0x30;
978 pin_code.pin[3] = 0x30;
979
980 pairing_cb.autopair_attempts++;
981 BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin);
982 return;
983 }
984 }
985 }
986 HAL_CBACK(bt_hal_cbacks, pin_request_cb,
Casper Bonde818d0f22015-05-21 11:08:45 +0200987 &bd_addr, &bd_name, cod, p_pin_req->min_16_digit);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800988}
989
990/*******************************************************************************
991**
992** Function btif_dm_ssp_cfm_req_evt
993**
994** Description Executes SSP confirm request event in btif context
995**
996** Returns void
997**
998*******************************************************************************/
999static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ *p_ssp_cfm_req)
1000{
1001 bt_bdaddr_t bd_addr;
1002 bt_bdname_t bd_name;
1003 UINT32 cod;
1004 BOOLEAN is_incoming = !(pairing_cb.state == BT_BOND_STATE_BONDING);
Matthew Xie86f97ed2014-11-10 10:24:46 -08001005 int dev_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001006
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001007 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001008
1009 /* Remote properties update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08001010 if (!btif_get_device_type(p_ssp_cfm_req->bd_addr, &dev_type))
1011 {
1012 dev_type = BT_DEVICE_TYPE_BREDR;
1013 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001014 btif_update_remote_properties(p_ssp_cfm_req->bd_addr, p_ssp_cfm_req->bd_name,
Matthew Xie86f97ed2014-11-10 10:24:46 -08001015 p_ssp_cfm_req->dev_class, (tBT_DEVICE_TYPE) dev_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001016
1017 bdcpy(bd_addr.address, p_ssp_cfm_req->bd_addr);
1018 memcpy(bd_name.name, p_ssp_cfm_req->bd_name, BD_NAME_LEN);
1019
1020 /* Set the pairing_cb based on the local & remote authentication requirements */
1021 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
1022
1023 /* if just_works and bonding bit is not set treat this as temporary */
1024 if (p_ssp_cfm_req->just_works && !(p_ssp_cfm_req->loc_auth_req & BTM_AUTH_BONDS) &&
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001025 !(p_ssp_cfm_req->rmt_auth_req & BTM_AUTH_BONDS) &&
1026 !(check_cod((bt_bdaddr_t*)&p_ssp_cfm_req->bd_addr, COD_HID_POINTING)))
Andre Eisenbach89363762015-01-26 13:49:36 -08001027 pairing_cb.bond_type = BOND_TYPE_TEMPORARY;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001028 else
Andre Eisenbach89363762015-01-26 13:49:36 -08001029 pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001030
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001031 btm_set_bond_type_dev(p_ssp_cfm_req->bd_addr, pairing_cb.bond_type);
1032
The Android Open Source Project5738f832012-12-12 16:00:35 -08001033 pairing_cb.is_ssp = TRUE;
1034
1035 /* If JustWorks auto-accept */
1036 if (p_ssp_cfm_req->just_works)
1037 {
1038 /* Pairing consent for JustWorks needed if:
Andre Eisenbachaf753a22015-06-08 20:43:00 -07001039 * 1. Incoming (non-temporary) pairing is detected AND
The Android Open Source Project5738f832012-12-12 16:00:35 -08001040 * 2. local IO capabilities are DisplayYesNo AND
1041 * 3. remote IO capabiltiies are DisplayOnly or NoInputNoOutput;
1042 */
Andre Eisenbachaf753a22015-06-08 20:43:00 -07001043 if (is_incoming && pairing_cb.bond_type != BOND_TYPE_TEMPORARY &&
1044 ((p_ssp_cfm_req->loc_io_caps == HCI_IO_CAP_DISPLAY_YESNO) &&
1045 (p_ssp_cfm_req->rmt_io_caps == HCI_IO_CAP_DISPLAY_ONLY ||
1046 p_ssp_cfm_req->rmt_io_caps == HCI_IO_CAP_NO_IO)))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001047 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001048 BTIF_TRACE_EVENT("%s: User consent needed for incoming pairing request. loc_io_caps: %d, rmt_io_caps: %d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001049 __FUNCTION__, p_ssp_cfm_req->loc_io_caps, p_ssp_cfm_req->rmt_io_caps);
1050 }
1051 else
1052 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001053 BTIF_TRACE_EVENT("%s: Auto-accept JustWorks pairing", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001054 btif_dm_ssp_reply(&bd_addr, BT_SSP_VARIANT_CONSENT, TRUE, 0);
1055 return;
1056 }
1057 }
1058
1059 cod = devclass2uint(p_ssp_cfm_req->dev_class);
1060
Chris Mantonf8027002015-03-12 09:22:48 -07001061 if (cod == 0) {
1062 LOG_DEBUG("%s cod is 0, set as unclassified", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001063 cod = COD_UNCLASSIFIED;
1064 }
1065
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001066 pairing_cb.sdp_attempts = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001067 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod,
1068 (p_ssp_cfm_req->just_works ? BT_SSP_VARIANT_CONSENT : BT_SSP_VARIANT_PASSKEY_CONFIRMATION),
1069 p_ssp_cfm_req->num_val);
1070}
1071
1072static void btif_dm_ssp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif)
1073{
1074 bt_bdaddr_t bd_addr;
1075 bt_bdname_t bd_name;
1076 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08001077 int dev_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001078
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001079 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001080
1081 /* Remote properties update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08001082 if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type))
1083 {
1084 dev_type = BT_DEVICE_TYPE_BREDR;
1085 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001086 btif_update_remote_properties(p_ssp_key_notif->bd_addr, p_ssp_key_notif->bd_name,
Matthew Xie86f97ed2014-11-10 10:24:46 -08001087 p_ssp_key_notif->dev_class, (tBT_DEVICE_TYPE) dev_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001088
1089 bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
1090 memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
1091
1092 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
1093 pairing_cb.is_ssp = TRUE;
1094 cod = devclass2uint(p_ssp_key_notif->dev_class);
1095
Chris Mantonf8027002015-03-12 09:22:48 -07001096 if (cod == 0) {
1097 LOG_DEBUG("%s cod is 0, set as unclassified", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001098 cod = COD_UNCLASSIFIED;
1099 }
1100
1101 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
1102 cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION,
1103 p_ssp_key_notif->passkey);
1104}
1105/*******************************************************************************
1106**
1107** Function btif_dm_auth_cmpl_evt
1108**
1109** Description Executes authentication complete event in btif context
1110**
1111** Returns void
1112**
1113*******************************************************************************/
1114static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
1115{
1116 /* Save link key, if not temporary */
1117 bt_bdaddr_t bd_addr;
1118 bt_status_t status = BT_STATUS_FAIL;
1119 bt_bond_state_t state = BT_BOND_STATE_NONE;
Priti Agherac0edf9f2014-06-26 11:23:51 -07001120 BOOLEAN skip_sdp = FALSE;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001121
Chaojing Sune2805532015-04-22 13:40:21 -07001122 BTIF_TRACE_DEBUG("%s: bond state=%d", __func__, pairing_cb.state);
1123
The Android Open Source Project5738f832012-12-12 16:00:35 -08001124 bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
1125 if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
1126 {
Srinu Jella21331c62015-06-16 19:38:45 +05301127 if ((p_auth_cmpl->key_type < HCI_LKEY_TYPE_DEBUG_COMB) ||
1128 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB) ||
1129 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_CHANGED_COMB) ||
1130 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB_P_256) ||
1131 pairing_cb.bond_type == BOND_TYPE_PERSISTENT)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001132 {
1133 bt_status_t ret;
Andre Eisenbach89363762015-01-26 13:49:36 -08001134 BTIF_TRACE_DEBUG("%s: Storing link key. key_type=0x%x, bond_type=%d",
1135 __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.bond_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001136 ret = btif_storage_add_bonded_device(&bd_addr,
1137 p_auth_cmpl->key, p_auth_cmpl->key_type,
1138 pairing_cb.pin_code_len);
1139 ASSERTC(ret == BT_STATUS_SUCCESS, "storing link key failed", ret);
1140 }
1141 else
1142 {
Andre Eisenbach89363762015-01-26 13:49:36 -08001143 BTIF_TRACE_DEBUG("%s: Temporary key. Not storing. key_type=0x%x, bond_type=%d",
1144 __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.bond_type);
1145 if(pairing_cb.bond_type == BOND_TYPE_TEMPORARY)
Hemant Guptab820aec2013-12-24 19:59:57 +05301146 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001147 BTIF_TRACE_DEBUG("%s: sending BT_BOND_STATE_NONE for Temp pairing",
Hemant Guptab820aec2013-12-24 19:59:57 +05301148 __FUNCTION__);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001149 btif_storage_remove_bonded_device(&bd_addr);
Hemant Guptab820aec2013-12-24 19:59:57 +05301150 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
1151 return;
1152 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001153 }
1154 }
Priti Agherac0edf9f2014-06-26 11:23:51 -07001155
1156 // Skip SDP for certain HID Devices
The Android Open Source Project5738f832012-12-12 16:00:35 -08001157 if (p_auth_cmpl->success)
1158 {
Andre Eisenbach12871662015-05-08 17:42:10 -07001159#if BLE_INCLUDED == TRUE
Chaojing Sune2805532015-04-22 13:40:21 -07001160 btif_storage_set_remote_addr_type(&bd_addr, p_auth_cmpl->addr_type);
Andre Eisenbach12871662015-05-08 17:42:10 -07001161#endif
Chaojing Sune2805532015-04-22 13:40:21 -07001162 btif_update_remote_properties(p_auth_cmpl->bd_addr,
1163 p_auth_cmpl->bd_name, NULL, p_auth_cmpl->dev_type);
Andre Eisenbach31a64002014-10-14 14:29:19 -07001164 pairing_cb.timeout_retries = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001165
Priti Agherac0edf9f2014-06-26 11:23:51 -07001166 if (check_sdp_bl(&bd_addr) && check_cod_hid(&bd_addr, COD_HID_MAJOR))
1167 {
Hemant Guptada33b462015-04-26 10:32:57 +05301168 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED);
Ganesh Ganapathi Battae17bf002013-02-15 17:52:29 -08001169
Hemant Guptada33b462015-04-26 10:32:57 +05301170 BTIF_TRACE_DEBUG("%s: HID Connection from "
1171 "blacklisted device, skipping sdp",__FUNCTION__);
Priti Agherac0edf9f2014-06-26 11:23:51 -07001172 bt_property_t prop;
Priti Agherac0edf9f2014-06-26 11:23:51 -07001173 bt_uuid_t uuid;
1174 char uuid_str[128] = UUID_HUMAN_INTERFACE_DEVICE;
Ganesh Ganapathi Battae17bf002013-02-15 17:52:29 -08001175
Priti Agherac0edf9f2014-06-26 11:23:51 -07001176 string_to_uuid(uuid_str, &uuid);
1177
1178 prop.type = BT_PROPERTY_UUIDS;
1179 prop.val = uuid.uu;
1180 prop.len = MAX_UUID_SIZE;
1181
Hemant Guptada33b462015-04-26 10:32:57 +05301182 /* Also write this to the NVRAM */
1183 status = btif_storage_set_remote_device_property(&bd_addr, &prop);
1184 ASSERTC(status == BT_STATUS_SUCCESS, "storing remote services failed", status);
Priti Agherac0edf9f2014-06-26 11:23:51 -07001185 /* Send the event to the BTIF */
1186 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1187 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1188 }
1189 else
1190 {
Hemant Guptada33b462015-04-26 10:32:57 +05301191 status = BT_STATUS_SUCCESS;
1192 state = BT_BOND_STATE_BONDED;
1193
Priti Agherac0edf9f2014-06-26 11:23:51 -07001194 /* Trigger SDP on the device */
1195 pairing_cb.sdp_attempts = 1;;
Andre Eisenbach12871662015-05-08 17:42:10 -07001196
1197#if BLE_INCLUDED == TRUE
Chaojing Sune2805532015-04-22 13:40:21 -07001198 /* If bonded due to cross-key, save the static address too*/
1199 if(pairing_cb.state == BT_BOND_STATE_BONDING &&
1200 (bdcmp(p_auth_cmpl->bd_addr, pairing_cb.bd_addr) != 0))
1201 {
1202 BTIF_TRACE_DEBUG("%s: bonding initiated due to cross key, adding static address",
1203 __func__);
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001204 bdcpy(pairing_cb.static_bdaddr.address, p_auth_cmpl->bd_addr);
Chaojing Sune2805532015-04-22 13:40:21 -07001205 }
Andre Eisenbach12871662015-05-08 17:42:10 -07001206#endif
Priti Agherac0edf9f2014-06-26 11:23:51 -07001207
1208 if(btif_dm_inquiry_in_progress)
1209 btif_dm_cancel_discovery();
1210
1211 btif_dm_get_remote_services(&bd_addr);
Chaojing Sune2805532015-04-22 13:40:21 -07001212 }
1213 // Do not call bond_state_changed_cb yet. Wait until remote service discovery is complete
The Android Open Source Project5738f832012-12-12 16:00:35 -08001214 }
1215 else
1216 {
Chaojing Sune2805532015-04-22 13:40:21 -07001217 // Map the HCI fail reason to bt status
The Android Open Source Project5738f832012-12-12 16:00:35 -08001218 switch(p_auth_cmpl->fail_reason)
1219 {
1220 case HCI_ERR_PAGE_TIMEOUT:
Hemant Guptada33b462015-04-26 10:32:57 +05301221 if (interop_addr_match(INTEROP_AUTO_RETRY_PAIRING, &bd_addr)
Andre Eisenbach27c4e632015-07-06 15:43:15 -07001222 && pairing_cb.timeout_retries)
Andre Eisenbach31a64002014-10-14 14:29:19 -07001223 {
1224 BTIF_TRACE_WARNING("%s() - Pairing timeout; retrying (%d) ...", __FUNCTION__, pairing_cb.timeout_retries);
1225 --pairing_cb.timeout_retries;
1226 btif_dm_cb_create_bond (&bd_addr, BTA_TRANSPORT_UNKNOWN);
1227 return;
1228 }
1229 /* Fall-through */
The Android Open Source Project5738f832012-12-12 16:00:35 -08001230 case HCI_ERR_CONNECTION_TOUT:
1231 status = BT_STATUS_RMT_DEV_DOWN;
1232 break;
1233
Hemant Guptaaef7a672013-07-31 19:00:12 +05301234 case HCI_ERR_PAIRING_NOT_ALLOWED:
1235 status = BT_STATUS_AUTH_REJECTED;
1236 break;
1237
Hemant Guptab4801442014-01-07 18:11:15 +05301238 case HCI_ERR_LMP_RESPONSE_TIMEOUT:
1239 status = BT_STATUS_AUTH_FAILURE;
1240 break;
1241
The Android Open Source Project5738f832012-12-12 16:00:35 -08001242 /* map the auth failure codes, so we can retry pairing if necessary */
1243 case HCI_ERR_AUTH_FAILURE:
Hemant Gupta59a88ec2014-03-19 19:01:35 +05301244 case HCI_ERR_KEY_MISSING:
Zhihai Xua7ea8092013-11-27 14:10:53 +05301245 btif_storage_remove_bonded_device(&bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001246 case HCI_ERR_HOST_REJECT_SECURITY:
1247 case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE:
1248 case HCI_ERR_UNIT_KEY_USED:
1249 case HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED:
1250 case HCI_ERR_INSUFFCIENT_SECURITY:
Hemant Gupta87b7cce2013-11-28 13:07:10 +05301251 case HCI_ERR_PEER_USER:
1252 case HCI_ERR_UNSPECIFIED:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001253 BTIF_TRACE_DEBUG(" %s() Authentication fail reason %d",
Hemant Gupta87b7cce2013-11-28 13:07:10 +05301254 __FUNCTION__, p_auth_cmpl->fail_reason);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001255 if (pairing_cb.autopair_attempts == 1)
1256 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001257 BTIF_TRACE_DEBUG("%s(): Adding device to blacklist ", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001258
1259 /* Add the device to dynamic black list only if this device belongs to Audio/pointing dev class */
1260 if (check_cod(&bd_addr, COD_AV_HEADSETS) ||
1261 check_cod(&bd_addr, COD_AV_HANDSFREE) ||
1262 check_cod(&bd_addr, COD_AV_HEADPHONES) ||
1263 check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) ||
1264 check_cod(&bd_addr, COD_AV_HIFI_AUDIO) ||
1265 check_cod(&bd_addr, COD_HID_POINTING))
1266 {
1267 btif_storage_add_device_to_autopair_blacklist (&bd_addr);
1268 }
1269 pairing_cb.autopair_attempts++;
1270
1271 /* Create the Bond once again */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001272 BTIF_TRACE_DEBUG("%s() auto pair failed. Reinitiate Bond", __FUNCTION__);
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07001273 btif_dm_cb_create_bond (&bd_addr, BTA_TRANSPORT_UNKNOWN);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001274 return;
1275 }
1276 else
1277 {
1278 /* if autopair attempts are more than 1, or not attempted */
1279 status = BT_STATUS_AUTH_FAILURE;
1280 }
1281 break;
1282
1283 default:
1284 status = BT_STATUS_FAIL;
1285 }
Zhihai Xu8d2128d2013-12-13 16:09:21 +05301286 /* Special Handling for HID Devices */
1287 if (check_cod(&bd_addr, COD_HID_POINTING)) {
1288 /* Remove Device as bonded in nvram as authentication failed */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001289 BTIF_TRACE_DEBUG("%s(): removing hid pointing device from nvram", __FUNCTION__);
Zhihai Xu8d2128d2013-12-13 16:09:21 +05301290 btif_storage_remove_bonded_device(&bd_addr);
1291 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001292 bond_state_changed(status, &bd_addr, state);
1293 }
1294}
1295
1296/******************************************************************************
1297**
1298** Function btif_dm_search_devices_evt
1299**
1300** Description Executes search devices callback events in btif context
1301**
1302** Returns void
1303**
1304******************************************************************************/
1305static void btif_dm_search_devices_evt (UINT16 event, char *p_param)
1306{
1307 tBTA_DM_SEARCH *p_search_data;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001308 BTIF_TRACE_EVENT("%s event=%s", __FUNCTION__, dump_dm_search_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001309
1310 switch (event)
1311 {
1312 case BTA_DM_DISC_RES_EVT:
1313 {
1314 p_search_data = (tBTA_DM_SEARCH *)p_param;
1315 /* Remote name update */
1316 if (strlen((const char *) p_search_data->disc_res.bd_name))
1317 {
1318 bt_property_t properties[1];
1319 bt_bdaddr_t bdaddr;
1320 bt_status_t status;
1321
1322 properties[0].type = BT_PROPERTY_BDNAME;
1323 properties[0].val = p_search_data->disc_res.bd_name;
1324 properties[0].len = strlen((char *)p_search_data->disc_res.bd_name);
1325 bdcpy(bdaddr.address, p_search_data->disc_res.bd_addr);
1326
1327 status = btif_storage_set_remote_device_property(&bdaddr, &properties[0]);
1328 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device property", status);
1329 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1330 status, &bdaddr, 1, properties);
1331 }
1332 /* TODO: Services? */
1333 }
1334 break;
1335
1336 case BTA_DM_INQ_RES_EVT:
1337 {
1338 /* inquiry result */
1339 UINT32 cod;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001340 bt_bdname_t bdname;
1341 bt_bdaddr_t bdaddr;
1342 UINT8 remote_name_len;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001343 tBTA_SERVICE_MASK services = 0;
1344 bdstr_t bdstr;
1345
1346 p_search_data = (tBTA_DM_SEARCH *)p_param;
1347 bdcpy(bdaddr.address, p_search_data->inq_res.bd_addr);
1348
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07001349 BTIF_TRACE_DEBUG("%s() %s device_type = 0x%x\n", __FUNCTION__, bdaddr_to_string(&bdaddr, bdstr, sizeof(bdstr)),
The Android Open Source Project5738f832012-12-12 16:00:35 -08001350#if (BLE_INCLUDED == TRUE)
1351 p_search_data->inq_res.device_type);
1352#else
1353 BT_DEVICE_TYPE_BREDR);
1354#endif
1355 bdname.name[0] = 0;
1356
1357 cod = devclass2uint (p_search_data->inq_res.dev_class);
1358
Chris Mantonf8027002015-03-12 09:22:48 -07001359 if (cod == 0) {
1360 LOG_DEBUG("%s cod is 0, set as unclassified", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001361 cod = COD_UNCLASSIFIED;
1362 }
1363
1364 if (!check_eir_remote_name(p_search_data, bdname.name, &remote_name_len))
1365 check_cached_remote_name(p_search_data, bdname.name, &remote_name_len);
1366
1367 /* Check EIR for remote name and services */
1368 if (p_search_data->inq_res.p_eir)
1369 {
1370 BTA_GetEirService(p_search_data->inq_res.p_eir, &services);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001371 BTIF_TRACE_DEBUG("%s()EIR BTA services = %08X", __FUNCTION__, (UINT32)services);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001372 /* TODO: Get the service list and check to see which uuids we got and send it back to the client. */
1373 }
1374
1375
1376 {
1377 bt_property_t properties[5];
1378 bt_device_type_t dev_type;
1379 uint32_t num_properties = 0;
1380 bt_status_t status;
Nitin Aroraac728402015-06-26 18:09:37 -07001381 int addr_type = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001382
1383 memset(properties, 0, sizeof(properties));
1384 /* BD_ADDR */
1385 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1386 BT_PROPERTY_BDADDR, sizeof(bdaddr), &bdaddr);
1387 num_properties++;
1388 /* BD_NAME */
1389 /* Don't send BDNAME if it is empty */
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001390 if (bdname.name[0])
1391 {
The Android Open Source Project5738f832012-12-12 16:00:35 -08001392 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1393 BT_PROPERTY_BDNAME,
1394 strlen((char *)bdname.name), &bdname);
1395 num_properties++;
1396 }
1397
1398 /* DEV_CLASS */
1399 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1400 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
1401 num_properties++;
1402 /* DEV_TYPE */
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001403#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001404 /* FixMe: Assumption is that bluetooth.h and BTE enums match */
Nitin Aroraac728402015-06-26 18:09:37 -07001405
1406 /* Verify if the device is dual mode in NVRAM */
1407 int stored_device_type = 0;
1408 if (btif_get_device_type(bdaddr.address, &stored_device_type) &&
1409 ((stored_device_type == BT_DEVICE_TYPE_BLE &&
1410 p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BREDR) ||
1411 (stored_device_type == BT_DEVICE_TYPE_BREDR &&
1412 p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BLE))) {
1413 dev_type = BT_DEVICE_TYPE_DUMO;
1414 } else {
1415 dev_type = p_search_data->inq_res.device_type;
1416 }
1417
1418 if (p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BLE)
1419 addr_type = p_search_data->inq_res.ble_addr_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001420#else
1421 dev_type = BT_DEVICE_TYPE_BREDR;
1422#endif
1423 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1424 BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
1425 num_properties++;
1426 /* RSSI */
1427 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1428 BT_PROPERTY_REMOTE_RSSI, sizeof(int8_t),
1429 &(p_search_data->inq_res.rssi));
1430 num_properties++;
1431
1432 status = btif_storage_add_remote_device(&bdaddr, num_properties, properties);
1433 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device (inquiry)", status);
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001434#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1435 status = btif_storage_set_remote_addr_type(&bdaddr, addr_type);
1436 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote addr type (inquiry)", status);
1437#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001438 /* Callback to notify upper layer of device */
1439 HAL_CBACK(bt_hal_cbacks, device_found_cb,
1440 num_properties, properties);
1441 }
1442 }
1443 break;
1444
1445 case BTA_DM_INQ_CMPL_EVT:
1446 {
Satya Calloji6e2d9db2014-07-08 16:18:58 -07001447#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1448 tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param;
1449 memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
1450 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL,
1451 bte_scan_filt_param_cfg_evt, 0);
1452#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001453 }
1454 break;
1455 case BTA_DM_DISC_CMPL_EVT:
1456 {
1457 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED);
1458 }
1459 break;
1460 case BTA_DM_SEARCH_CANCEL_CMPL_EVT:
1461 {
1462 /* if inquiry is not in progress and we get a cancel event, then
1463 * it means we are done with inquiry, but remote_name fetches are in
1464 * progress
1465 *
1466 * if inquiry is in progress, then we don't want to act on this cancel_cmpl_evt
1467 * but instead wait for the cancel_cmpl_evt via the Busy Level
1468 *
1469 */
1470 if (btif_dm_inquiry_in_progress == FALSE)
1471 {
Nitin Arora7b85efa2014-09-26 14:05:24 -07001472#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1473 tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param;
1474 memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
1475 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL,
1476 bte_scan_filt_param_cfg_evt, 0);
1477#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001478 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED);
1479 }
1480 }
1481 break;
1482 }
1483}
1484
1485/*******************************************************************************
1486**
1487** Function btif_dm_search_services_evt
1488**
1489** Description Executes search services event in btif context
1490**
1491** Returns void
1492**
1493*******************************************************************************/
1494static void btif_dm_search_services_evt(UINT16 event, char *p_param)
1495{
1496 tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param;
1497
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001498 BTIF_TRACE_EVENT("%s: event = %d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001499 switch (event)
1500 {
1501 case BTA_DM_DISC_RES_EVT:
1502 {
The Android Open Source Project5738f832012-12-12 16:00:35 -08001503 bt_property_t prop;
Bernhard Rosenkränzer104e3f22014-11-12 21:53:08 +01001504 uint32_t i = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001505 bt_bdaddr_t bd_addr;
1506 bt_status_t ret;
1507
1508 bdcpy(bd_addr.address, p_data->disc_res.bd_addr);
1509
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001510 BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001511 p_data->disc_res.result, p_data->disc_res.services);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001512 if ((p_data->disc_res.result != BTA_SUCCESS) &&
1513 (pairing_cb.state == BT_BOND_STATE_BONDING ) &&
1514 (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING))
1515 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001516 BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", __FUNCTION__);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001517 pairing_cb.sdp_attempts++;
1518 btif_dm_get_remote_services(&bd_addr);
1519 return;
1520 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001521 prop.type = BT_PROPERTY_UUIDS;
1522 prop.len = 0;
1523 if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0))
1524 {
1525 prop.val = p_data->disc_res.p_uuid_list;
1526 prop.len = p_data->disc_res.num_uuids * MAX_UUID_SIZE;
1527 for (i=0; i < p_data->disc_res.num_uuids; i++)
1528 {
1529 char temp[256];
Chris Manton8ff3fea2015-01-07 13:59:14 -08001530 uuid_to_string_legacy((bt_uuid_t*)(p_data->disc_res.p_uuid_list + (i*MAX_UUID_SIZE)), temp);
Chris Mantonf8027002015-03-12 09:22:48 -07001531 LOG_INFO("%s index:%d uuid:%s", __func__, i, temp);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001532 }
1533 }
1534
1535 /* onUuidChanged requires getBondedDevices to be populated.
1536 ** bond_state_changed needs to be sent prior to remote_device_property
1537 */
1538 if ((pairing_cb.state == BT_BOND_STATE_BONDING) &&
Chaojing Sune2805532015-04-22 13:40:21 -07001539 ((bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0) ||
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001540 (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0)) &&
Chaojing Sune2805532015-04-22 13:40:21 -07001541 pairing_cb.sdp_attempts > 0)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001542 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001543 BTIF_TRACE_DEBUG("%s Remote Service SDP done. Call bond_state_changed_cb BONDED",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001544 __FUNCTION__);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001545 pairing_cb.sdp_attempts = 0;
Chaojing Sune2805532015-04-22 13:40:21 -07001546
1547 // If bonding occured due to cross-key pairing, send bonding callback
1548 // for static address now
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001549 if (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0)
Chaojing Sune2805532015-04-22 13:40:21 -07001550 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
1551
The Android Open Source Project5738f832012-12-12 16:00:35 -08001552 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED);
1553 }
1554
Chaojing Sune2805532015-04-22 13:40:21 -07001555 if (p_data->disc_res.num_uuids != 0)
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001556 {
1557 /* Also write this to the NVRAM */
1558 ret = btif_storage_set_remote_device_property(&bd_addr, &prop);
1559 ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);
1560 /* Send the event to the BTIF */
1561 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1562 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1563 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001564 }
1565 break;
1566
1567 case BTA_DM_DISC_CMPL_EVT:
1568 /* fixme */
1569 break;
1570
Matthew Xie607e3b72013-08-15 19:30:48 -07001571#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001572 case BTA_DM_DISC_BLE_RES_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001573 BTIF_TRACE_DEBUG("%s:, services 0x%x)", __FUNCTION__,
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001574 p_data->disc_ble_res.service.uu.uuid16);
1575 bt_uuid_t uuid;
1576 int i = 0;
1577 int j = 15;
1578 if (p_data->disc_ble_res.service.uu.uuid16 == UUID_SERVCLASS_LE_HID)
1579 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001580 BTIF_TRACE_DEBUG("%s: Found HOGP UUID",__FUNCTION__);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001581 bt_property_t prop;
1582 bt_bdaddr_t bd_addr;
1583 char temp[256];
Zhihai Xud7ee77b2013-11-05 18:06:54 -08001584 bt_status_t ret;
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001585
1586 bta_gatt_convert_uuid16_to_uuid128(uuid.uu,p_data->disc_ble_res.service.uu.uuid16);
1587
1588 while(i < j )
1589 {
1590 unsigned char c = uuid.uu[j];
1591 uuid.uu[j] = uuid.uu[i];
1592 uuid.uu[i] = c;
1593 i++;
1594 j--;
1595 }
1596
Chris Manton8ff3fea2015-01-07 13:59:14 -08001597 uuid_to_string_legacy(&uuid, temp);
Chris Mantonf8027002015-03-12 09:22:48 -07001598 LOG_INFO("%s uuid:%s", __func__, temp);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001599
1600 bdcpy(bd_addr.address, p_data->disc_ble_res.bd_addr);
1601 prop.type = BT_PROPERTY_UUIDS;
1602 prop.val = uuid.uu;
1603 prop.len = MAX_UUID_SIZE;
1604
Zhihai Xud7ee77b2013-11-05 18:06:54 -08001605 /* Also write this to the NVRAM */
1606 ret = btif_storage_set_remote_device_property(&bd_addr, &prop);
1607 ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);
1608
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001609 /* Send the event to the BTIF */
1610 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1611 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1612
1613 }
1614 break;
Matthew Xie607e3b72013-08-15 19:30:48 -07001615#endif /* BLE_INCLUDED */
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001616
The Android Open Source Project5738f832012-12-12 16:00:35 -08001617 default:
1618 {
1619 ASSERTC(0, "unhandled search services event", event);
1620 }
1621 break;
1622 }
1623}
1624
1625/*******************************************************************************
1626**
1627** Function btif_dm_remote_service_record_evt
1628**
1629** Description Executes search service record event in btif context
1630**
1631** Returns void
1632**
1633*******************************************************************************/
1634static void btif_dm_remote_service_record_evt(UINT16 event, char *p_param)
1635{
1636 tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param;
1637
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001638 BTIF_TRACE_EVENT("%s: event = %d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001639 switch (event)
1640 {
1641 case BTA_DM_DISC_RES_EVT:
1642 {
1643 bt_service_record_t rec;
1644 bt_property_t prop;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001645 bt_bdaddr_t bd_addr;
1646
1647 memset(&rec, 0, sizeof(bt_service_record_t));
1648 bdcpy(bd_addr.address, p_data->disc_res.bd_addr);
1649
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001650 BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001651 p_data->disc_res.result, p_data->disc_res.services);
1652 prop.type = BT_PROPERTY_SERVICE_RECORD;
1653 prop.val = (void*)&rec;
1654 prop.len = sizeof(rec);
1655
1656 /* disc_res.result is overloaded with SCN. Cannot check result */
1657 p_data->disc_res.services &= ~BTA_USER_SERVICE_MASK;
1658 /* TODO: Get the UUID as well */
1659 rec.channel = p_data->disc_res.result - 3;
1660 /* TODO: Need to get the service name using p_raw_data */
1661 rec.name[0] = 0;
1662
1663 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1664 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1665 }
1666 break;
1667
1668 default:
1669 {
1670 ASSERTC(0, "unhandled remote service record event", event);
1671 }
1672 break;
1673 }
1674}
1675
1676/*******************************************************************************
1677**
1678** Function btif_dm_upstreams_cback
1679**
1680** Description Executes UPSTREAMS events in btif context
1681**
1682** Returns void
1683**
1684*******************************************************************************/
1685static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
1686{
The Android Open Source Project5738f832012-12-12 16:00:35 -08001687 tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)p_param;
1688 tBTA_SERVICE_MASK service_mask;
1689 uint32_t i;
1690 bt_bdaddr_t bd_addr;
1691
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001692 BTIF_TRACE_EVENT("btif_dm_upstreams_cback ev: %s", dump_dm_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001693
1694 switch (event)
1695 {
1696 case BTA_DM_ENABLE_EVT:
1697 {
1698 BD_NAME bdname;
1699 bt_status_t status;
1700 bt_property_t prop;
1701 prop.type = BT_PROPERTY_BDNAME;
1702 prop.len = BD_NAME_LEN;
1703 prop.val = (void*)bdname;
1704
1705 status = btif_storage_get_adapter_property(&prop);
Matthew Xie1e5109b2012-11-09 18:26:26 -08001706 if (status == BT_STATUS_SUCCESS)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001707 {
1708 /* A name exists in the storage. Make this the device name */
1709 BTA_DmSetDeviceName((char*)prop.val);
1710 }
Matthew Xie1e5109b2012-11-09 18:26:26 -08001711 else
1712 {
1713 /* Storage does not have a name yet.
1714 * Use the default name and write it to the chip
1715 */
1716 BTA_DmSetDeviceName(btif_get_default_local_name());
1717 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001718
Andre Eisenbacha015a832014-09-11 14:09:40 -07001719#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1720 /* Enable local privacy */
Andre Eisenbach3e0dc732014-10-24 09:55:34 -07001721 BTA_DmBleConfigLocalPrivacy(BLE_LOCAL_PRIVACY_ENABLED);
Andre Eisenbacha015a832014-09-11 14:09:40 -07001722#endif
1723
The Android Open Source Project5738f832012-12-12 16:00:35 -08001724 /* for each of the enabled services in the mask, trigger the profile
1725 * enable */
1726 service_mask = btif_get_enabled_services_mask();
1727 for (i=0; i <= BTA_MAX_SERVICE_ID; i++)
1728 {
1729 if (service_mask &
1730 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i)))
1731 {
1732 btif_in_execute_service_request(i, TRUE);
1733 }
1734 }
1735 /* clear control blocks */
1736 memset(&pairing_cb, 0, sizeof(btif_dm_pairing_cb_t));
Satya Calloji877123f2015-04-23 23:39:49 -07001737 pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001738
1739 /* This function will also trigger the adapter_properties_cb
1740 ** and bonded_devices_info_cb
1741 */
1742 btif_storage_load_bonded_devices();
1743
1744 btif_storage_load_autopair_device_list();
1745
Zach Johnson39110ec2014-10-06 13:15:00 -07001746 btif_enable_bluetooth_evt(p_data->enable.status);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001747 }
1748 break;
1749
1750 case BTA_DM_DISABLE_EVT:
1751 /* for each of the enabled services in the mask, trigger the profile
1752 * disable */
1753 service_mask = btif_get_enabled_services_mask();
1754 for (i=0; i <= BTA_MAX_SERVICE_ID; i++)
1755 {
1756 if (service_mask &
1757 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i)))
1758 {
1759 btif_in_execute_service_request(i, FALSE);
1760 }
1761 }
1762 btif_disable_bluetooth_evt();
1763 break;
1764
1765 case BTA_DM_PIN_REQ_EVT:
1766 btif_dm_pin_req_evt(&p_data->pin_req);
1767 break;
1768
1769 case BTA_DM_AUTH_CMPL_EVT:
1770 btif_dm_auth_cmpl_evt(&p_data->auth_cmpl);
1771 break;
1772
1773 case BTA_DM_BOND_CANCEL_CMPL_EVT:
1774 if (pairing_cb.state == BT_BOND_STATE_BONDING)
1775 {
1776 bdcpy(bd_addr.address, pairing_cb.bd_addr);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001777 btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001778 bond_state_changed(p_data->bond_cancel_cmpl.result, &bd_addr, BT_BOND_STATE_NONE);
1779 }
1780 break;
1781
1782 case BTA_DM_SP_CFM_REQ_EVT:
1783 btif_dm_ssp_cfm_req_evt(&p_data->cfm_req);
1784 break;
1785 case BTA_DM_SP_KEY_NOTIF_EVT:
1786 btif_dm_ssp_key_notif_evt(&p_data->key_notif);
1787 break;
1788
1789 case BTA_DM_DEV_UNPAIRED_EVT:
1790 bdcpy(bd_addr.address, p_data->link_down.bd_addr);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001791 btm_set_bond_type_dev(p_data->link_down.bd_addr, BOND_TYPE_UNKNOWN);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001792
1793 /*special handling for HID devices */
1794 #if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -07001795 btif_hh_remove_device(bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001796 #endif
Hemant Gupta94c15ec2013-11-11 12:33:44 +05301797 #if (defined(BTA_HD_INCLUDED) && (BTA_HD_INCLUDED == TRUE))
1798 btif_hd_remove_device(bd_addr);
1799 #endif
1800 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1801 btif_storage_remove_ble_bonding_keys(&bd_addr);
1802 #endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001803 btif_storage_remove_bonded_device(&bd_addr);
1804 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
1805 break;
1806
1807 case BTA_DM_BUSY_LEVEL_EVT:
1808 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001809
1810 if (p_data->busy_level.level_flags & BTM_BL_INQUIRY_PAGING_MASK)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001811 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001812 if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_STARTED)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001813 {
1814 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb,
1815 BT_DISCOVERY_STARTED);
1816 btif_dm_inquiry_in_progress = TRUE;
1817 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001818 else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_CANCELLED)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001819 {
1820 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb,
1821 BT_DISCOVERY_STOPPED);
1822 btif_dm_inquiry_in_progress = FALSE;
1823 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001824 else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_COMPLETE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001825 {
1826 btif_dm_inquiry_in_progress = FALSE;
1827 }
1828 }
1829 }break;
1830
1831 case BTA_DM_LINK_UP_EVT:
1832 bdcpy(bd_addr.address, p_data->link_up.bd_addr);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001833 BTIF_TRACE_DEBUG("BTA_DM_LINK_UP_EVT. Sending BT_ACL_STATE_CONNECTED");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001834
1835 btif_update_remote_version_property(&bd_addr);
1836
The Android Open Source Project5738f832012-12-12 16:00:35 -08001837 HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS,
1838 &bd_addr, BT_ACL_STATE_CONNECTED);
1839 break;
1840
1841 case BTA_DM_LINK_DOWN_EVT:
1842 bdcpy(bd_addr.address, p_data->link_down.bd_addr);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001843 btm_set_bond_type_dev(p_data->link_down.bd_addr, BOND_TYPE_UNKNOWN);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001844 BTIF_TRACE_DEBUG("BTA_DM_LINK_DOWN_EVT. Sending BT_ACL_STATE_DISCONNECTED");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001845 HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS,
1846 &bd_addr, BT_ACL_STATE_DISCONNECTED);
1847 break;
1848
1849 case BTA_DM_HW_ERROR_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001850 BTIF_TRACE_ERROR("Received H/W Error. ");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001851 /* Flush storage data */
1852 btif_config_flush();
1853 usleep(100000); /* 100milliseconds */
1854 /* Killing the process to force a restart as part of fault tolerance */
1855 kill(getpid(), SIGKILL);
1856 break;
1857
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001858#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1859 case BTA_DM_BLE_KEY_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001860 BTIF_TRACE_DEBUG("BTA_DM_BLE_KEY_EVT key_type=0x%02x ", p_data->ble_key.key_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001861
1862 /* If this pairing is by-product of local initiated GATT client Read or Write,
1863 BTA would not have sent BTA_DM_BLE_SEC_REQ_EVT event and Bond state would not
1864 have setup properly. Setup pairing_cb and notify App about Bonding state now*/
1865 if (pairing_cb.state != BT_BOND_STATE_BONDING)
1866 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001867 BTIF_TRACE_DEBUG("Bond state not sent to App so far.Notify the app now");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001868 bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t*)p_data->ble_key.bd_addr,
1869 BT_BOND_STATE_BONDING);
1870 }
1871 else if (memcmp (pairing_cb.bd_addr, p_data->ble_key.bd_addr, BD_ADDR_LEN)!=0)
1872 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001873 BTIF_TRACE_ERROR("BD mismatch discard BLE key_type=%d ",p_data->ble_key.key_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001874 break;
1875 }
1876
1877 switch (p_data->ble_key.key_type)
1878 {
1879 case BTA_LE_KEY_PENC:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001880 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PENC");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001881 pairing_cb.ble.is_penc_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001882 pairing_cb.ble.penc_key = p_data->ble_key.p_key_value->penc_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001883 break;
1884
1885 case BTA_LE_KEY_PID:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001886 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PID");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001887 pairing_cb.ble.is_pid_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001888 pairing_cb.ble.pid_key = p_data->ble_key.p_key_value->pid_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001889 break;
1890
1891 case BTA_LE_KEY_PCSRK:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001892 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PCSRK");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001893 pairing_cb.ble.is_pcsrk_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001894 pairing_cb.ble.pcsrk_key = p_data->ble_key.p_key_value->pcsrk_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001895 break;
1896
1897 case BTA_LE_KEY_LENC:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001898 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LENC");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001899 pairing_cb.ble.is_lenc_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001900 pairing_cb.ble.lenc_key = p_data->ble_key.p_key_value->lenc_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001901 break;
1902
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001903 case BTA_LE_KEY_LCSRK:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001904 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LCSRK");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001905 pairing_cb.ble.is_lcsrk_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001906 pairing_cb.ble.lcsrk_key = p_data->ble_key.p_key_value->lcsrk_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001907 break;
1908
Satya Calloji444a8da2015-03-06 10:38:22 -08001909 case BTA_LE_KEY_LID:
1910 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LID");
1911 pairing_cb.ble.is_lidk_key_rcvd = TRUE;
1912 break;
1913
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001914 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001915 BTIF_TRACE_ERROR("unknown BLE key type (0x%02x)", p_data->ble_key.key_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001916 break;
1917 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001918 break;
1919 case BTA_DM_BLE_SEC_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001920 BTIF_TRACE_DEBUG("BTA_DM_BLE_SEC_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001921 btif_dm_ble_sec_req_evt(&p_data->ble_req);
1922 break;
1923 case BTA_DM_BLE_PASSKEY_NOTIF_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001924 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_NOTIF_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001925 btif_dm_ble_key_notif_evt(&p_data->key_notif);
1926 break;
1927 case BTA_DM_BLE_PASSKEY_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001928 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001929 btif_dm_ble_passkey_req_evt(&p_data->pin_req);
1930 break;
Satya Calloji444a8da2015-03-06 10:38:22 -08001931 case BTA_DM_BLE_NC_REQ_EVT:
1932 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_REQ_EVT. ");
1933 btif_dm_ble_key_nc_req_evt(&p_data->key_notif);
1934 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001935 case BTA_DM_BLE_OOB_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001936 BTIF_TRACE_DEBUG("BTA_DM_BLE_OOB_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001937 break;
1938 case BTA_DM_BLE_LOCAL_IR_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001939 BTIF_TRACE_DEBUG("BTA_DM_BLE_LOCAL_IR_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001940 ble_local_key_cb.is_id_keys_rcvd = TRUE;
Satya Calloji444a8da2015-03-06 10:38:22 -08001941 memcpy(&ble_local_key_cb.id_keys.irk[0],
1942 &p_data->ble_id_keys.irk[0], sizeof(BT_OCTET16));
1943 memcpy(&ble_local_key_cb.id_keys.ir[0],
1944 &p_data->ble_id_keys.ir[0], sizeof(BT_OCTET16));
1945 memcpy(&ble_local_key_cb.id_keys.dhk[0],
1946 &p_data->ble_id_keys.dhk[0], sizeof(BT_OCTET16));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001947 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.irk[0],
Satya Calloji7bd40382015-05-19 14:42:32 -07001948 BTIF_DM_LE_LOCAL_KEY_IRK,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001949 BT_OCTET16_LEN);
1950 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.ir[0],
Satya Calloji7bd40382015-05-19 14:42:32 -07001951 BTIF_DM_LE_LOCAL_KEY_IR,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001952 BT_OCTET16_LEN);
1953 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.dhk[0],
1954 BTIF_DM_LE_LOCAL_KEY_DHK,
1955 BT_OCTET16_LEN);
1956 break;
1957 case BTA_DM_BLE_LOCAL_ER_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001958 BTIF_TRACE_DEBUG("BTA_DM_BLE_LOCAL_ER_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001959 ble_local_key_cb.is_er_rcvd = TRUE;
1960 memcpy(&ble_local_key_cb.er[0], &p_data->ble_er[0], sizeof(BT_OCTET16));
1961 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.er[0],
1962 BTIF_DM_LE_LOCAL_KEY_ER,
1963 BT_OCTET16_LEN);
1964 break;
1965
1966 case BTA_DM_BLE_AUTH_CMPL_EVT:
Satya Calloji444a8da2015-03-06 10:38:22 -08001967 BTIF_TRACE_DEBUG("BTA_DM_BLE_AUTH_CMPL_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001968 btif_dm_ble_auth_cmpl_evt(&p_data->auth_cmpl);
1969 break;
Ganesh Ganapathi Batta9546abf2014-05-30 16:28:00 -07001970
1971 case BTA_DM_LE_FEATURES_READ:
1972 {
1973 tBTM_BLE_VSC_CB cmn_vsc_cb;
1974 bt_local_le_features_t local_le_features;
1975 char buf[512];
1976 bt_property_t prop;
1977 prop.type = BT_PROPERTY_LOCAL_LE_FEATURES;
1978 prop.val = (void*)buf;
1979 prop.len = sizeof(buf);
1980
1981 /* LE features are not stored in storage. Should be retrived from stack */
1982 BTM_BleGetVendorCapabilities(&cmn_vsc_cb);
1983 local_le_features.local_privacy_enabled = BTM_BleLocalPrivacyEnabled();
1984
1985 prop.len = sizeof (bt_local_le_features_t);
1986 if (cmn_vsc_cb.filter_support == 1)
1987 local_le_features.max_adv_filter_supported = cmn_vsc_cb.max_filter;
1988 else
1989 local_le_features.max_adv_filter_supported = 0;
1990 local_le_features.max_adv_instance = cmn_vsc_cb.adv_inst_max;
1991 local_le_features.max_irk_list_size = cmn_vsc_cb.max_irk_list_sz;
1992 local_le_features.rpa_offload_supported = cmn_vsc_cb.rpa_offloading;
Satya Callojiefaddcb2014-07-28 23:22:05 -07001993 local_le_features.activity_energy_info_supported = cmn_vsc_cb.energy_support;
Satya Callojif5387072015-02-09 17:40:52 -08001994 local_le_features.scan_result_storage_size = cmn_vsc_cb.tot_scan_results_strg;
1995 local_le_features.version_supported = cmn_vsc_cb.version_supported;
1996 local_le_features.total_trackable_advertisers =
1997 cmn_vsc_cb.total_trackable_advertisers;
Satya Calloji5725fc62015-03-31 13:24:32 -07001998
1999 local_le_features.extended_scan_support = cmn_vsc_cb.extended_scan_support > 0;
2000 local_le_features.debug_logging_supported = cmn_vsc_cb.debug_logging_supported > 0;
2001
Ganesh Ganapathi Batta9546abf2014-05-30 16:28:00 -07002002 memcpy(prop.val, &local_le_features, prop.len);
2003 HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, BT_STATUS_SUCCESS, 1, &prop);
2004 break;
2005 }
Satya Callojie5ba8842014-07-03 17:18:02 -07002006
2007 case BTA_DM_ENER_INFO_READ:
2008 {
2009 btif_activity_energy_info_cb_t *p_ener_data = (btif_activity_energy_info_cb_t*) p_param;
2010 bt_activity_energy_info energy_info;
2011 energy_info.status = p_ener_data->status;
2012 energy_info.ctrl_state = p_ener_data->ctrl_state;
2013 energy_info.rx_time = p_ener_data->rx_time;
2014 energy_info.tx_time = p_ener_data->tx_time;
2015 energy_info.idle_time = p_ener_data->idle_time;
2016 energy_info.energy_used = p_ener_data->energy_used;
2017 HAL_CBACK(bt_hal_cbacks, energy_info_cb, &energy_info);
2018 break;
2019 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002020#endif
2021
The Android Open Source Project5738f832012-12-12 16:00:35 -08002022 case BTA_DM_AUTHORIZE_EVT:
2023 case BTA_DM_SIG_STRENGTH_EVT:
2024 case BTA_DM_SP_RMT_OOB_EVT:
2025 case BTA_DM_SP_KEYPRESS_EVT:
2026 case BTA_DM_ROLE_CHG_EVT:
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002027
The Android Open Source Project5738f832012-12-12 16:00:35 -08002028 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002029 BTIF_TRACE_WARNING( "btif_dm_cback : unhandled event (%d)", event );
The Android Open Source Project5738f832012-12-12 16:00:35 -08002030 break;
2031 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002032
Andre Eisenbach8a057242015-04-29 22:27:15 -07002033 btif_dm_data_free(event, p_data);
2034}
The Android Open Source Project5738f832012-12-12 16:00:35 -08002035
2036/*******************************************************************************
2037**
2038** Function btif_dm_generic_evt
2039**
2040** Description Executes non-BTA upstream events in BTIF context
2041**
2042** Returns void
2043**
2044*******************************************************************************/
2045static void btif_dm_generic_evt(UINT16 event, char* p_param)
2046{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002047 BTIF_TRACE_EVENT("%s: event=%d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002048 switch(event)
2049 {
2050 case BTIF_DM_CB_DISCOVERY_STARTED:
2051 {
2052 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STARTED);
2053 }
2054 break;
2055
2056 case BTIF_DM_CB_CREATE_BOND:
2057 {
Andre Eisenbach31a64002014-10-14 14:29:19 -07002058 pairing_cb.timeout_retries = NUM_TIMEOUT_RETRIES;
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002059 btif_dm_create_bond_cb_t *create_bond_cb = (btif_dm_create_bond_cb_t*)p_param;
2060 btif_dm_cb_create_bond(&create_bond_cb->bdaddr, create_bond_cb->transport);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002061 }
2062 break;
2063
2064 case BTIF_DM_CB_REMOVE_BOND:
2065 {
2066 btif_dm_cb_remove_bond((bt_bdaddr_t *)p_param);
2067 }
2068 break;
2069
2070 case BTIF_DM_CB_HID_REMOTE_NAME:
2071 {
2072 btif_dm_cb_hid_remote_name((tBTM_REMOTE_DEV_NAME *)p_param);
2073 }
2074 break;
2075
2076 case BTIF_DM_CB_BOND_STATE_BONDING:
2077 {
2078 bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t *)p_param, BT_BOND_STATE_BONDING);
2079 }
2080 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002081 case BTIF_DM_CB_LE_TX_TEST:
2082 case BTIF_DM_CB_LE_RX_TEST:
2083 {
2084 uint8_t status;
2085 STREAM_TO_UINT8(status, p_param);
2086 HAL_CBACK(bt_hal_cbacks, le_test_mode_cb,
2087 (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, 0);
2088 }
2089 break;
2090 case BTIF_DM_CB_LE_TEST_END:
2091 {
2092 uint8_t status;
2093 uint16_t count = 0;
2094 STREAM_TO_UINT8(status, p_param);
2095 if (status == 0)
2096 STREAM_TO_UINT16(count, p_param);
2097 HAL_CBACK(bt_hal_cbacks, le_test_mode_cb,
2098 (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, count);
2099 }
2100 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002101 default:
2102 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002103 BTIF_TRACE_WARNING("%s : Unknown event 0x%x", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002104 }
2105 break;
2106 }
2107}
2108
2109/*******************************************************************************
2110**
2111** Function bte_dm_evt
2112**
2113** Description Switches context from BTE to BTIF for all DM events
2114**
2115** Returns void
2116**
2117*******************************************************************************/
2118
2119void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data)
2120{
The Android Open Source Project5738f832012-12-12 16:00:35 -08002121 /* switch context to btif task context (copy full union size for convenience) */
Andre Eisenbach8a057242015-04-29 22:27:15 -07002122 bt_status_t status = btif_transfer_context(btif_dm_upstreams_evt, (uint16_t)event,
2123 (void*)p_data, sizeof(tBTA_DM_SEC), btif_dm_data_copy);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002124
2125 /* catch any failed context transfers */
2126 ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status);
2127}
2128
2129/*******************************************************************************
2130**
2131** Function bte_search_devices_evt
2132**
2133** Description Switches context from BTE to BTIF for DM search events
2134**
2135** Returns void
2136**
2137*******************************************************************************/
2138static void bte_search_devices_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
2139{
2140 UINT16 param_len = 0;
2141
2142 if (p_data)
2143 param_len += sizeof(tBTA_DM_SEARCH);
2144 /* Allocate buffer to hold the pointers (deep copy). The pointers will point to the end of the tBTA_DM_SEARCH */
2145 switch (event)
2146 {
2147 case BTA_DM_INQ_RES_EVT:
2148 {
2149 if (p_data->inq_res.p_eir)
2150 param_len += HCI_EXT_INQ_RESPONSE_LEN;
2151 }
2152 break;
2153
2154 case BTA_DM_DISC_RES_EVT:
2155 {
2156 if (p_data->disc_res.raw_data_size && p_data->disc_res.p_raw_data)
2157 param_len += p_data->disc_res.raw_data_size;
2158 }
2159 break;
2160 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002161 BTIF_TRACE_DEBUG("%s event=%s param_len=%d", __FUNCTION__, dump_dm_search_event(event), param_len);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002162
2163 /* if remote name is available in EIR, set teh flag so that stack doesnt trigger RNR */
2164 if (event == BTA_DM_INQ_RES_EVT)
2165 p_data->inq_res.remt_name_not_required = check_eir_remote_name(p_data, NULL, NULL);
2166
2167 btif_transfer_context (btif_dm_search_devices_evt , (UINT16) event, (void *)p_data, param_len,
2168 (param_len > sizeof(tBTA_DM_SEARCH)) ? search_devices_copy_cb : NULL);
2169}
2170
2171/*******************************************************************************
2172**
2173** Function bte_dm_search_services_evt
2174**
2175** Description Switches context from BTE to BTIF for DM search services
2176** event
2177**
2178** Returns void
2179**
2180*******************************************************************************/
2181static void bte_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
2182{
2183 UINT16 param_len = 0;
2184 if (p_data)
2185 param_len += sizeof(tBTA_DM_SEARCH);
2186 switch (event)
2187 {
2188 case BTA_DM_DISC_RES_EVT:
2189 {
2190 if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0)) {
2191 param_len += (p_data->disc_res.num_uuids * MAX_UUID_SIZE);
2192 }
2193 } break;
2194 }
2195 /* TODO: The only other member that needs a deep copy is the p_raw_data. But not sure
2196 * if raw_data is needed. */
2197 btif_transfer_context(btif_dm_search_services_evt, event, (char*)p_data, param_len,
2198 (param_len > sizeof(tBTA_DM_SEARCH)) ? search_services_copy_cb : NULL);
2199}
2200
2201/*******************************************************************************
2202**
2203** Function bte_dm_remote_service_record_evt
2204**
2205** Description Switches context from BTE to BTIF for DM search service
2206** record event
2207**
2208** Returns void
2209**
2210*******************************************************************************/
2211static void bte_dm_remote_service_record_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
2212{
2213 /* TODO: The only member that needs a deep copy is the p_raw_data. But not sure yet if this is needed. */
2214 btif_transfer_context(btif_dm_remote_service_record_evt, event, (char*)p_data, sizeof(tBTA_DM_SEARCH), NULL);
2215}
2216
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07002217#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Satya Callojie5ba8842014-07-03 17:18:02 -07002218/*******************************************************************************
2219**
2220** Function bta_energy_info_cb
2221**
2222** Description Switches context from BTE to BTIF for DM energy info event
2223**
2224** Returns void
2225**
2226*******************************************************************************/
2227static void bta_energy_info_cb(tBTA_DM_BLE_TX_TIME_MS tx_time, tBTA_DM_BLE_RX_TIME_MS rx_time,
2228 tBTA_DM_BLE_IDLE_TIME_MS idle_time,
2229 tBTA_DM_BLE_ENERGY_USED energy_used,
2230 tBTA_DM_CONTRL_STATE ctrl_state, tBTA_STATUS status)
2231{
2232 BTIF_TRACE_DEBUG("energy_info_cb-Status:%d,state=%d,tx_t=%ld, rx_t=%ld, idle_time=%ld,used=%ld",
2233 status, ctrl_state, tx_time, rx_time, idle_time, energy_used);
2234
2235 btif_activity_energy_info_cb_t btif_cb;
2236 btif_cb.status = status;
2237 btif_cb.ctrl_state = ctrl_state;
2238 btif_cb.tx_time = (uint64_t) tx_time;
2239 btif_cb.rx_time = (uint64_t) rx_time;
2240 btif_cb.idle_time =(uint64_t) idle_time;
2241 btif_cb.energy_used =(uint64_t) energy_used;
2242 btif_transfer_context(btif_dm_upstreams_evt, BTA_DM_ENER_INFO_READ,
2243 (char*) &btif_cb, sizeof(btif_activity_energy_info_cb_t), NULL);
2244}
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07002245#endif
Satya Callojie5ba8842014-07-03 17:18:02 -07002246
Satya Calloji6e2d9db2014-07-08 16:18:58 -07002247/*******************************************************************************
2248**
2249** Function bte_scan_filt_param_cfg_evt
2250**
2251** Description Scan filter param config event
2252**
2253** Returns void
2254**
2255*******************************************************************************/
2256static void bte_scan_filt_param_cfg_evt(UINT8 action_type,
2257 tBTA_DM_BLE_PF_AVBL_SPACE avbl_space,
2258 tBTA_DM_BLE_REF_VALUE ref_value, tBTA_STATUS status)
2259{
2260 /* This event occurs on calling BTA_DmBleCfgFilterCondition internally,
2261 ** and that is why there is no HAL callback
2262 */
2263 if(BTA_SUCCESS != status)
2264 {
2265 BTIF_TRACE_ERROR("%s, %d", __FUNCTION__, status);
2266 }
2267 else
2268 {
2269 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
2270 }
2271}
2272
The Android Open Source Project5738f832012-12-12 16:00:35 -08002273/*****************************************************************************
2274**
2275** btif api functions (no context switch)
2276**
2277*****************************************************************************/
2278
2279/*******************************************************************************
2280**
2281** Function btif_dm_start_discovery
2282**
2283** Description Start device discovery/inquiry
2284**
2285** Returns bt_status_t
2286**
2287*******************************************************************************/
2288bt_status_t btif_dm_start_discovery(void)
2289{
2290 tBTA_DM_INQ inq_params;
2291 tBTA_SERVICE_MASK services = 0;
Satya Calloji6e2d9db2014-07-08 16:18:58 -07002292 tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002293
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002294 BTIF_TRACE_EVENT("%s", __FUNCTION__);
Satya Calloji6e2d9db2014-07-08 16:18:58 -07002295
2296#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2297 memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
2298 /* Cleanup anything remaining on index 0 */
2299 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL,
2300 bte_scan_filt_param_cfg_evt, 0);
2301
2302 /* Add an allow-all filter on index 0*/
2303 adv_filt_param.dely_mode = IMMEDIATE_DELY_MODE;
2304 adv_filt_param.feat_seln = ALLOW_ALL_FILTER;
2305 adv_filt_param.filt_logic_type = BTA_DM_BLE_PF_FILT_LOGIC_OR;
2306 adv_filt_param.list_logic_type = BTA_DM_BLE_PF_LIST_LOGIC_OR;
2307 adv_filt_param.rssi_low_thres = LOWEST_RSSI_VALUE;
2308 adv_filt_param.rssi_high_thres = LOWEST_RSSI_VALUE;
2309 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_ADD, 0, &adv_filt_param, NULL,
2310 bte_scan_filt_param_cfg_evt, 0);
2311
The Android Open Source Project5738f832012-12-12 16:00:35 -08002312 /* TODO: Do we need to handle multiple inquiries at the same time? */
2313
2314 /* Set inquiry params and call API */
The Android Open Source Project5738f832012-12-12 16:00:35 -08002315 inq_params.mode = BTA_DM_GENERAL_INQUIRY|BTA_BLE_GENERAL_INQUIRY;
Matthew Xie7f3e4292013-09-30 12:44:10 -07002316#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
2317 inq_params.intl_duration[0]= BTIF_DM_INTERLEAVE_DURATION_BR_ONE;
2318 inq_params.intl_duration[1]= BTIF_DM_INTERLEAVE_DURATION_LE_ONE;
2319 inq_params.intl_duration[2]= BTIF_DM_INTERLEAVE_DURATION_BR_TWO;
2320 inq_params.intl_duration[3]= BTIF_DM_INTERLEAVE_DURATION_LE_TWO;
2321#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002322#else
2323 inq_params.mode = BTA_DM_GENERAL_INQUIRY;
2324#endif
2325 inq_params.duration = BTIF_DM_DEFAULT_INQ_MAX_DURATION;
2326
2327 inq_params.max_resps = BTIF_DM_DEFAULT_INQ_MAX_RESULTS;
2328 inq_params.report_dup = TRUE;
2329
2330 inq_params.filter_type = BTA_DM_INQ_CLR;
2331 /* TODO: Filter device by BDA needs to be implemented here */
2332
2333 /* Will be enabled to TRUE once inquiry busy level has been received */
2334 btif_dm_inquiry_in_progress = FALSE;
2335 /* find nearby devices */
2336 BTA_DmSearch(&inq_params, services, bte_search_devices_evt);
2337
2338 return BT_STATUS_SUCCESS;
2339}
2340
2341/*******************************************************************************
2342**
2343** Function btif_dm_cancel_discovery
2344**
2345** Description Cancels search
2346**
2347** Returns bt_status_t
2348**
2349*******************************************************************************/
2350bt_status_t btif_dm_cancel_discovery(void)
2351{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002352 BTIF_TRACE_EVENT("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002353 BTA_DmSearchCancel();
2354 return BT_STATUS_SUCCESS;
2355}
2356
2357/*******************************************************************************
2358**
2359** Function btif_dm_create_bond
2360**
2361** Description Initiate bonding with the specified device
2362**
2363** Returns bt_status_t
2364**
2365*******************************************************************************/
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002366bt_status_t btif_dm_create_bond(const bt_bdaddr_t *bd_addr, int transport)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002367{
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002368 btif_dm_create_bond_cb_t create_bond_cb;
2369 create_bond_cb.transport = transport;
2370 bdcpy(create_bond_cb.bdaddr.address, bd_addr->address);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002371
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002372 bdstr_t bdstr;
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002373 BTIF_TRACE_EVENT("%s: bd_addr=%s, transport=%d", __FUNCTION__, bdaddr_to_string(bd_addr, bdstr, sizeof(bdstr)), transport);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002374 if (pairing_cb.state != BT_BOND_STATE_NONE)
2375 return BT_STATUS_BUSY;
2376
2377 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_CREATE_BOND,
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002378 (char *)&create_bond_cb, sizeof(btif_dm_create_bond_cb_t), NULL);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002379
2380 return BT_STATUS_SUCCESS;
2381}
2382
2383/*******************************************************************************
2384**
2385** Function btif_dm_cancel_bond
2386**
2387** Description Initiate bonding with the specified device
2388**
2389** Returns bt_status_t
2390**
2391*******************************************************************************/
2392
2393bt_status_t btif_dm_cancel_bond(const bt_bdaddr_t *bd_addr)
2394{
2395 bdstr_t bdstr;
2396
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002397 BTIF_TRACE_EVENT("%s: bd_addr=%s", __FUNCTION__, bdaddr_to_string(bd_addr, bdstr, sizeof(bdstr)));
The Android Open Source Project5738f832012-12-12 16:00:35 -08002398
2399 /* TODO:
2400 ** 1. Restore scan modes
2401 ** 2. special handling for HID devices
2402 */
2403 if (pairing_cb.state == BT_BOND_STATE_BONDING)
2404 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002405
2406#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2407
2408 if (pairing_cb.is_ssp)
2409 {
2410 if (pairing_cb.is_le_only)
2411 {
2412 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT);
2413 }
2414 else
Hemant Guptae1468692013-11-14 16:21:29 +05302415 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002416 BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE);
Hemant Guptae1468692013-11-14 16:21:29 +05302417 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2418 btif_storage_remove_bonded_device((bt_bdaddr_t *)bd_addr);
2419 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002420 }
2421 else
2422 {
2423 if (pairing_cb.is_le_only)
2424 {
2425 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2426 }
2427 else
2428 {
2429 BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL);
2430 }
2431 /* Cancel bonding, in case it is in ACL connection setup state */
2432 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2433 }
2434
2435#else
The Android Open Source Project5738f832012-12-12 16:00:35 -08002436 if (pairing_cb.is_ssp)
2437 {
2438 BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE);
2439 }
2440 else
2441 {
2442 BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL);
2443 }
2444 /* Cancel bonding, in case it is in ACL connection setup state */
2445 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2446 btif_storage_remove_bonded_device((bt_bdaddr_t *)bd_addr);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002447#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002448 }
2449
2450 return BT_STATUS_SUCCESS;
2451}
2452
2453/*******************************************************************************
2454**
Hemant Guptada33b462015-04-26 10:32:57 +05302455** Function btif_dm_hh_open_success
2456**
2457** Description Checks if device is blacklisted, if yes takes appropriate action
2458**
2459** Returns none
2460**
2461*******************************************************************************/
2462
2463void btif_dm_hh_open_success(bt_bdaddr_t *bdaddr)
2464{
2465 if (pairing_cb.state == BT_BOND_STATE_BONDING &&
2466 bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0)
2467 {
2468 if (check_if_auth_bl(bdaddr)
2469 && check_cod_hid(bdaddr, COD_HID_MAJOR))
2470 {
2471 bt_status_t status;
2472 LINK_KEY link_key = {0};
2473 bond_state_changed(BT_STATUS_SUCCESS, bdaddr, BT_BOND_STATE_BONDED);
2474 BTIF_TRACE_DEBUG("%s: Device is blacklisted for authentication", __func__);
2475 bt_property_t prop;
2476 bt_uuid_t uuid;
2477 char uuid_str[128] = UUID_HUMAN_INTERFACE_DEVICE;
2478 string_to_uuid(uuid_str, &uuid);
2479 prop.type = BT_PROPERTY_UUIDS;
2480 prop.val = uuid.uu;
2481 prop.len = MAX_UUID_SIZE;
2482 // Also write this to the NVRAM
2483 status = btif_storage_set_remote_device_property(bdaddr, &prop);
2484 ASSERTC(status == BT_STATUS_SUCCESS, "storing remote services failed", status);
2485 // Store fake link for device as bonded in nvram,
2486 // otherwise on device reboot/bt off-on device will not be shown in paired list.
2487 btif_storage_add_bonded_device(bdaddr, link_key, HCI_LKEY_TYPE_UNAUTH_COMB, 0);
2488 // Send the event to the BTIF
2489 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
2490 BT_STATUS_SUCCESS, bdaddr, 1, &prop);
2491 }
2492 }
2493}
2494
2495/*******************************************************************************
2496**
Kim Schulza9eb25c2013-09-30 10:55:52 +02002497** Function btif_dm_hh_open_failed
2498**
2499** Description informs the upper layers if the HH have failed during bonding
2500**
2501** Returns none
2502**
2503*******************************************************************************/
2504
2505void btif_dm_hh_open_failed(bt_bdaddr_t *bdaddr)
2506{
2507 if (pairing_cb.state == BT_BOND_STATE_BONDING &&
2508 bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0)
2509 {
2510 bond_state_changed(BT_STATUS_FAIL, bdaddr, BT_BOND_STATE_NONE);
2511 }
2512}
2513
2514/*******************************************************************************
2515**
The Android Open Source Project5738f832012-12-12 16:00:35 -08002516** Function btif_dm_remove_bond
2517**
2518** Description Removes bonding with the specified device
2519**
2520** Returns bt_status_t
2521**
2522*******************************************************************************/
2523
2524bt_status_t btif_dm_remove_bond(const bt_bdaddr_t *bd_addr)
2525{
2526 bdstr_t bdstr;
2527
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002528 BTIF_TRACE_EVENT("%s: bd_addr=%s", __FUNCTION__, bdaddr_to_string(bd_addr, bdstr, sizeof(bdstr)));
The Android Open Source Project5738f832012-12-12 16:00:35 -08002529 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_REMOVE_BOND,
2530 (char *)bd_addr, sizeof(bt_bdaddr_t), NULL);
2531
2532 return BT_STATUS_SUCCESS;
2533}
2534
2535/*******************************************************************************
2536**
2537** Function btif_dm_pin_reply
2538**
2539** Description BT legacy pairing - PIN code reply
2540**
2541** Returns bt_status_t
2542**
2543*******************************************************************************/
2544
2545bt_status_t btif_dm_pin_reply( const bt_bdaddr_t *bd_addr, uint8_t accept,
2546 uint8_t pin_len, bt_pin_code_t *pin_code)
2547{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002548 BTIF_TRACE_EVENT("%s: accept=%d", __FUNCTION__, accept);
Hemant Gupta831423e2014-01-08 12:42:13 +05302549 if (pin_code == NULL)
2550 return BT_STATUS_FAIL;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002551#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002552
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002553 if (pairing_cb.is_le_only)
2554 {
2555 int i;
2556 UINT32 passkey = 0;
2557 int multi[] = {100000, 10000, 1000, 100, 10,1};
2558 BD_ADDR remote_bd_addr;
2559 bdcpy(remote_bd_addr, bd_addr->address);
2560 for (i = 0; i < 6; i++)
2561 {
2562 passkey += (multi[i] * (pin_code->pin[i] - '0'));
2563 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002564 BTIF_TRACE_DEBUG("btif_dm_pin_reply: passkey: %d", passkey);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002565 BTA_DmBlePasskeyReply(remote_bd_addr, accept, passkey);
2566
2567 }
2568 else
2569 {
2570 BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin);
2571 if (accept)
2572 pairing_cb.pin_code_len = pin_len;
2573 }
2574#else
The Android Open Source Project5738f832012-12-12 16:00:35 -08002575 BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin);
2576
2577 if (accept)
2578 pairing_cb.pin_code_len = pin_len;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002579#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002580 return BT_STATUS_SUCCESS;
2581}
2582
2583/*******************************************************************************
2584**
2585** Function btif_dm_ssp_reply
2586**
2587** Description BT SSP Reply - Just Works, Numeric Comparison & Passkey Entry
2588**
2589** Returns bt_status_t
2590**
2591*******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -08002592bt_status_t btif_dm_ssp_reply(const bt_bdaddr_t *bd_addr,
2593 bt_ssp_variant_t variant, uint8_t accept,
2594 uint32_t passkey)
2595{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002596 UNUSED(passkey);
2597
The Android Open Source Project5738f832012-12-12 16:00:35 -08002598 if (variant == BT_SSP_VARIANT_PASSKEY_ENTRY)
2599 {
2600 /* This is not implemented in the stack.
2601 * For devices with display, this is not needed
2602 */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002603 BTIF_TRACE_WARNING("%s: Not implemented", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002604 return BT_STATUS_FAIL;
2605 }
2606 /* BT_SSP_VARIANT_CONSENT & BT_SSP_VARIANT_PASSKEY_CONFIRMATION supported */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002607 BTIF_TRACE_EVENT("%s: accept=%d", __FUNCTION__, accept);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002608#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2609 if (pairing_cb.is_le_only)
2610 {
Satya Calloji7fb0da62015-01-29 20:40:17 -08002611 if(pairing_cb.is_le_nc)
2612 {
2613 BTA_DmBleConfirmReply((UINT8 *)bd_addr->address,accept);
2614 } else {
2615 if (accept)
2616 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_GRANTED);
2617 else
2618 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT);
2619 }
2620 } else {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002621 BTA_DmConfirm( (UINT8 *)bd_addr->address, accept);
Satya Calloji7fb0da62015-01-29 20:40:17 -08002622 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002623#else
2624 BTA_DmConfirm( (UINT8 *)bd_addr->address, accept);
2625#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002626 return BT_STATUS_SUCCESS;
2627}
2628
2629/*******************************************************************************
2630**
2631** Function btif_dm_get_adapter_property
2632**
2633** Description Queries the BTA for the adapter property
2634**
2635** Returns bt_status_t
2636**
2637*******************************************************************************/
2638bt_status_t btif_dm_get_adapter_property(bt_property_t *prop)
2639{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002640 BTIF_TRACE_EVENT("%s: type=0x%x", __FUNCTION__, prop->type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002641 switch (prop->type)
2642 {
2643 case BT_PROPERTY_BDNAME:
2644 {
2645 bt_bdname_t *bd_name = (bt_bdname_t*)prop->val;
VenkatRaghavan VijayaRaghavan4540f592015-02-05 04:40:47 -08002646 strncpy((char *)bd_name->name, (char *)btif_get_default_local_name(),
VenkatRaghavan VijayaRaghavan1d8e6b82015-02-05 22:20:39 -08002647 sizeof(bd_name->name) - 1);
2648 bd_name->name[sizeof(bd_name->name) - 1] = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002649 prop->len = strlen((char *)bd_name->name);
2650 }
2651 break;
2652
2653 case BT_PROPERTY_ADAPTER_SCAN_MODE:
2654 {
2655 /* if the storage does not have it. Most likely app never set it. Default is NONE */
2656 bt_scan_mode_t *mode = (bt_scan_mode_t*)prop->val;
2657 *mode = BT_SCAN_MODE_NONE;
2658 prop->len = sizeof(bt_scan_mode_t);
2659 }
2660 break;
2661
2662 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
2663 {
2664 uint32_t *tmt = (uint32_t*)prop->val;
2665 *tmt = 120; /* default to 120s, if not found in NV */
2666 prop->len = sizeof(uint32_t);
2667 }
2668 break;
2669
2670 default:
2671 prop->len = 0;
2672 return BT_STATUS_FAIL;
2673 }
2674 return BT_STATUS_SUCCESS;
2675}
2676
2677/*******************************************************************************
2678**
2679** Function btif_dm_get_remote_services
2680**
2681** Description Start SDP to get remote services
2682**
2683** Returns bt_status_t
2684**
2685*******************************************************************************/
2686bt_status_t btif_dm_get_remote_services(bt_bdaddr_t *remote_addr)
2687{
2688 bdstr_t bdstr;
2689
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002690 BTIF_TRACE_EVENT("%s: remote_addr=%s", __FUNCTION__, bdaddr_to_string(remote_addr, bdstr, sizeof(bdstr)));
The Android Open Source Project5738f832012-12-12 16:00:35 -08002691
2692 BTA_DmDiscover(remote_addr->address, BTA_ALL_SERVICE_MASK,
2693 bte_dm_search_services_evt, TRUE);
2694
2695 return BT_STATUS_SUCCESS;
2696}
2697
2698/*******************************************************************************
2699**
Nitin Arorab4365c52015-06-25 18:30:09 -07002700** Function btif_dm_get_remote_services_transport
2701**
2702** Description Start SDP to get remote services by transport
2703**
2704** Returns bt_status_t
2705**
2706*******************************************************************************/
2707bt_status_t btif_dm_get_remote_services_by_transport(bt_bdaddr_t *remote_addr, const int transport)
2708{
2709 BTIF_TRACE_EVENT("%s", __func__);
2710
2711 /* Set the mask extension */
2712 tBTA_SERVICE_MASK_EXT mask_ext;
2713 mask_ext.num_uuid = 0;
2714 mask_ext.p_uuid = NULL;
2715 mask_ext.srvc_mask = BTA_ALL_SERVICE_MASK;
2716
2717 BTA_DmDiscoverByTransport(remote_addr->address, &mask_ext,
2718 bte_dm_search_services_evt, TRUE, transport);
2719
2720 return BT_STATUS_SUCCESS;
2721}
2722
2723/*******************************************************************************
2724**
The Android Open Source Project5738f832012-12-12 16:00:35 -08002725** Function btif_dm_get_remote_service_record
2726**
2727** Description Start SDP to get remote service record
2728**
2729**
2730** Returns bt_status_t
2731*******************************************************************************/
2732bt_status_t btif_dm_get_remote_service_record(bt_bdaddr_t *remote_addr,
2733 bt_uuid_t *uuid)
2734{
2735 tSDP_UUID sdp_uuid;
2736 bdstr_t bdstr;
2737
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002738 BTIF_TRACE_EVENT("%s: remote_addr=%s", __FUNCTION__, bdaddr_to_string(remote_addr, bdstr, sizeof(bdstr)));
The Android Open Source Project5738f832012-12-12 16:00:35 -08002739
2740 sdp_uuid.len = MAX_UUID_SIZE;
2741 memcpy(sdp_uuid.uu.uuid128, uuid->uu, MAX_UUID_SIZE);
2742
2743 BTA_DmDiscoverUUID(remote_addr->address, &sdp_uuid,
2744 bte_dm_remote_service_record_evt, TRUE);
2745
2746 return BT_STATUS_SUCCESS;
2747}
2748
2749void btif_dm_execute_service_request(UINT16 event, char *p_param)
2750{
2751 BOOLEAN b_enable = FALSE;
2752 bt_status_t status;
2753 if (event == BTIF_DM_ENABLE_SERVICE)
2754 {
2755 b_enable = TRUE;
2756 }
2757 status = btif_in_execute_service_request(*((tBTA_SERVICE_ID*)p_param), b_enable);
2758 if (status == BT_STATUS_SUCCESS)
2759 {
2760 bt_property_t property;
2761 bt_uuid_t local_uuids[BT_MAX_NUM_UUIDS];
2762
2763 /* Now send the UUID_PROPERTY_CHANGED event to the upper layer */
2764 BTIF_STORAGE_FILL_PROPERTY(&property, BT_PROPERTY_UUIDS,
2765 sizeof(local_uuids), local_uuids);
2766 btif_storage_get_adapter_property(&property);
2767 HAL_CBACK(bt_hal_cbacks, adapter_properties_cb,
2768 BT_STATUS_SUCCESS, 1, &property);
2769 }
2770 return;
2771}
2772
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002773void btif_dm_proc_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, tBTA_OOB_DATA *p_oob_data,
2774 tBTA_AUTH_REQ *p_auth_req, BOOLEAN is_orig)
2775{
2776 UINT8 yes_no_bit = BTA_AUTH_SP_YES & *p_auth_req;
2777 /* if local initiated:
2778 ** 1. set DD + MITM
2779 ** if remote initiated:
2780 ** 1. Copy over the auth_req from peer's io_rsp
2781 ** 2. Set the MITM if peer has it set or if peer has DisplayYesNo (iPhone)
2782 ** as a fallback set MITM+GB if peer had MITM set
2783 */
2784 UNUSED (bd_addr);
2785 UNUSED (p_io_cap);
2786 UNUSED (p_oob_data);
2787
2788
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002789 BTIF_TRACE_DEBUG("+%s: p_auth_req=%d", __FUNCTION__, *p_auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002790 if(pairing_cb.is_local_initiated)
2791 {
2792 /* if initing/responding to a dedicated bonding, use dedicate bonding bit */
2793 *p_auth_req = BTA_AUTH_DD_BOND | BTA_AUTH_SP_YES;
2794 }
2795 else if (!is_orig)
2796 {
2797 /* peer initiated paring. They probably know what they want.
2798 ** Copy the mitm from peer device.
2799 */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002800 BTIF_TRACE_DEBUG("%s: setting p_auth_req to peer's: %d",
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002801 __FUNCTION__, pairing_cb.auth_req);
2802 *p_auth_req = (pairing_cb.auth_req & BTA_AUTH_BONDS);
2803
2804 /* copy over the MITM bit as well. In addition if the peer has DisplayYesNo, force MITM */
2805 if ((yes_no_bit) || (pairing_cb.io_cap & BTM_IO_CAP_IO) )
2806 *p_auth_req |= BTA_AUTH_SP_YES;
2807 }
2808 else if (yes_no_bit)
2809 {
2810 /* set the general bonding bit for stored device */
2811 *p_auth_req = BTA_AUTH_GEN_BOND | yes_no_bit;
2812 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002813 BTIF_TRACE_DEBUG("-%s: p_auth_req=%d", __FUNCTION__, *p_auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002814}
2815
2816void btif_dm_proc_io_rsp(BD_ADDR bd_addr, tBTA_IO_CAP io_cap,
2817 tBTA_OOB_DATA oob_data, tBTA_AUTH_REQ auth_req)
2818{
2819 UNUSED (bd_addr);
2820 UNUSED (oob_data);
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002821
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002822 if(auth_req & BTA_AUTH_BONDS)
2823 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002824 BTIF_TRACE_DEBUG("%s auth_req:%d", __FUNCTION__, auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002825 pairing_cb.auth_req = auth_req;
2826 pairing_cb.io_cap = io_cap;
2827 }
2828}
2829
The Android Open Source Project5738f832012-12-12 16:00:35 -08002830#if (BTM_OOB_INCLUDED == TRUE)
2831void btif_dm_set_oob_for_io_req(tBTA_OOB_DATA *p_oob_data)
2832{
2833 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2834 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
2835 {
2836 *p_oob_data = FALSE;
2837 }
2838 else
2839 {
2840 *p_oob_data = TRUE;
2841 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002842 BTIF_TRACE_DEBUG("btif_dm_set_oob_for_io_req *p_oob_data=%d", *p_oob_data);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002843}
2844#endif /* BTM_OOB_INCLUDED */
2845
2846#ifdef BTIF_DM_OOB_TEST
2847void btif_dm_load_local_oob(void)
2848{
Nick Kralevichd70b7a82013-01-31 14:40:15 -08002849 char prop_oob[PROPERTY_VALUE_MAX];
The Android Open Source Project5738f832012-12-12 16:00:35 -08002850 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002851 BTIF_TRACE_DEBUG("btif_dm_load_local_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002852 if (prop_oob[0] != '3')
2853 {
2854#if (BTM_OOB_INCLUDED == TRUE)
2855 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2856 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
2857 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002858 BTIF_TRACE_DEBUG("btif_dm_load_local_oob: read OOB, call BTA_DmLocalOob()");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002859 BTA_DmLocalOob();
2860 }
2861#else
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002862 BTIF_TRACE_ERROR("BTM_OOB_INCLUDED is FALSE!!(btif_dm_load_local_oob)");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002863#endif
2864 }
2865}
2866
2867void btif_dm_proc_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r)
2868{
2869 FILE *fp;
2870 char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
2871 char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
2872 char *path = NULL;
Nick Kralevichd70b7a82013-01-31 14:40:15 -08002873 char prop_oob[PROPERTY_VALUE_MAX];
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002874 BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob: valid=%d", valid);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002875 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2876 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 &&
2877 valid)
2878 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002879 BTIF_TRACE_DEBUG("save local OOB data in memory");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002880 memcpy(oob_cb.sp_c, c, BT_OCTET16_LEN);
2881 memcpy(oob_cb.sp_r, r, BT_OCTET16_LEN);
2882 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002883 BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002884 if (prop_oob[0] == '1')
2885 path = path_a;
2886 else if (prop_oob[0] == '2')
2887 path = path_b;
2888 if (path)
2889 {
2890 fp = fopen(path, "wb+");
2891 if (fp == NULL)
2892 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002893 BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob: failed to save local OOB data to %s", path);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002894 }
2895 else
2896 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002897 BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob: save local OOB data into file %s",path);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002898 fwrite (c , 1 , BT_OCTET16_LEN , fp );
2899 fwrite (r , 1 , BT_OCTET16_LEN , fp );
2900 fclose(fp);
2901 }
2902 }
2903 }
2904}
2905BOOLEAN btif_dm_proc_rmt_oob(BD_ADDR bd_addr, BT_OCTET16 p_c, BT_OCTET16 p_r)
2906{
2907 char t[128];
2908 FILE *fp;
2909 char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
2910 char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
2911 char *path = NULL;
Nick Kralevichd70b7a82013-01-31 14:40:15 -08002912 char prop_oob[PROPERTY_VALUE_MAX];
The Android Open Source Project5738f832012-12-12 16:00:35 -08002913 BOOLEAN result = FALSE;
2914 bt_bdaddr_t bt_bd_addr;
2915 bdcpy(oob_cb.oob_bdaddr, bd_addr);
2916 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002917 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002918 if (prop_oob[0] == '1')
2919 path = path_b;
2920 else if (prop_oob[0] == '2')
2921 path = path_a;
2922 if (path)
2923 {
2924 fp = fopen(path, "rb");
2925 if (fp == NULL)
2926 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002927 BTIF_TRACE_DEBUG("btapp_dm_rmt_oob_reply: failed to read OOB keys from %s",path);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002928 return FALSE;
2929 }
2930 else
2931 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002932 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob: read OOB data from %s",path);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002933 fread (p_c , 1 , BT_OCTET16_LEN , fp );
2934 fread (p_r , 1 , BT_OCTET16_LEN , fp );
2935 fclose(fp);
2936 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002937 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: TRUE");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002938 sprintf(t, "%02x:%02x:%02x:%02x:%02x:%02x",
2939 oob_cb.oob_bdaddr[0], oob_cb.oob_bdaddr[1], oob_cb.oob_bdaddr[2],
2940 oob_cb.oob_bdaddr[3], oob_cb.oob_bdaddr[4], oob_cb.oob_bdaddr[5]);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002941 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: peer_bdaddr = %s", t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002942 sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
2943 p_c[0], p_c[1], p_c[2], p_c[3], p_c[4], p_c[5], p_c[6], p_c[7],
2944 p_c[8], p_c[9], p_c[10], p_c[11], p_c[12], p_c[13], p_c[14], p_c[15]);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002945 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: c = %s",t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002946 sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
2947 p_r[0], p_r[1], p_r[2], p_r[3], p_r[4], p_r[5], p_r[6], p_r[7],
2948 p_r[8], p_r[9], p_r[10], p_r[11], p_r[12], p_r[13], p_r[14], p_r[15]);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002949 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: r = %s",t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002950 bdcpy(bt_bd_addr.address, bd_addr);
2951 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_BOND_STATE_BONDING,
2952 (char *)&bt_bd_addr, sizeof(bt_bdaddr_t), NULL);
2953 result = TRUE;
2954 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002955 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob result=%d",result);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002956 return result;
2957}
2958#endif /* BTIF_DM_OOB_TEST */
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002959#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2960
2961static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif)
2962{
2963 bt_bdaddr_t bd_addr;
2964 bt_bdname_t bd_name;
2965 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08002966 int dev_type;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002967
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002968 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002969
2970 /* Remote name update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08002971 if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type))
2972 {
2973 dev_type = BT_DEVICE_TYPE_BLE;
2974 }
2975 btif_dm_update_ble_remote_properties(p_ssp_key_notif->bd_addr , p_ssp_key_notif->bd_name,
2976 (tBT_DEVICE_TYPE) dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002977 bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
2978 memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
2979
2980 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
2981 pairing_cb.is_ssp = FALSE;
2982 cod = COD_UNCLASSIFIED;
2983
2984 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
2985 cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION,
2986 p_ssp_key_notif->passkey);
2987}
2988
2989/*******************************************************************************
2990**
2991** Function btif_dm_ble_auth_cmpl_evt
2992**
2993** Description Executes authentication complete event in btif context
2994**
2995** Returns void
2996**
2997*******************************************************************************/
2998static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
2999{
3000 /* Save link key, if not temporary */
3001 bt_bdaddr_t bd_addr;
3002 bt_status_t status = BT_STATUS_FAIL;
3003 bt_bond_state_t state = BT_BOND_STATE_NONE;
3004
3005 bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
3006 if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
3007 {
3008 /* store keys */
3009 }
3010 if (p_auth_cmpl->success)
3011 {
3012 status = BT_STATUS_SUCCESS;
3013 state = BT_BOND_STATE_BONDED;
Satya Calloji7cb76b42015-05-07 09:45:00 -07003014 int addr_type;
3015 bt_bdaddr_t bdaddr;
3016 bdcpy(bdaddr.address, p_auth_cmpl->bd_addr);
3017 if (btif_storage_get_remote_addr_type(&bdaddr, &addr_type) != BT_STATUS_SUCCESS)
3018 btif_storage_set_remote_addr_type(&bdaddr, p_auth_cmpl->addr_type);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07003019
3020 /* Test for temporary bonding */
3021 if (btm_get_bond_type_dev(p_auth_cmpl->bd_addr) == BOND_TYPE_TEMPORARY) {
3022 BTIF_TRACE_DEBUG("%s: sending BT_BOND_STATE_NONE for Temp pairing",
3023 __func__);
3024 btif_storage_remove_bonded_device(&bdaddr);
3025 state = BT_BOND_STATE_NONE;
3026 } else {
3027 btif_dm_save_ble_bonding_keys();
3028 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003029 BTA_GATTC_Refresh(bd_addr.address);
Nitin Arorab4365c52015-06-25 18:30:09 -07003030 btif_dm_get_remote_services_by_transport(&bd_addr, BTA_GATT_TRANSPORT_LE);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003031 }
3032 else
3033 {
3034 /*Map the HCI fail reason to bt status */
3035 switch (p_auth_cmpl->fail_reason)
3036 {
Priti Aghera156c52b2014-07-09 14:58:19 -07003037 case BTA_DM_AUTH_SMP_PAIR_AUTH_FAIL:
3038 case BTA_DM_AUTH_SMP_CONFIRM_VALUE_FAIL:
3039 btif_dm_remove_ble_bonding_keys();
3040 status = BT_STATUS_AUTH_FAILURE;
3041 break;
3042 case BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT:
3043 status = BT_STATUS_AUTH_REJECTED;
3044 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003045 default:
Andre Eisenbachca22ac42013-02-13 17:02:11 +09003046 btif_dm_remove_ble_bonding_keys();
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003047 status = BT_STATUS_FAIL;
3048 break;
3049 }
3050 }
3051 bond_state_changed(status, &bd_addr, state);
3052}
3053
3054
3055
3056void btif_dm_load_ble_local_keys(void)
3057{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003058 memset(&ble_local_key_cb, 0, sizeof(btif_dm_local_key_cb_t));
3059
3060 if (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_ER,(char*)&ble_local_key_cb.er[0],
3061 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)
3062 {
3063 ble_local_key_cb.is_er_rcvd = TRUE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003064 BTIF_TRACE_DEBUG("%s BLE ER key loaded",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003065 }
3066
3067 if ((btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IR,(char*)&ble_local_key_cb.id_keys.ir[0],
3068 BT_OCTET16_LEN)== BT_STATUS_SUCCESS )&&
3069 (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IRK, (char*)&ble_local_key_cb.id_keys.irk[0],
3070 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)&&
3071 (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_DHK,(char*)&ble_local_key_cb.id_keys.dhk[0],
3072 BT_OCTET16_LEN)== BT_STATUS_SUCCESS))
3073 {
3074 ble_local_key_cb.is_id_keys_rcvd = TRUE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003075 BTIF_TRACE_DEBUG("%s BLE ID keys loaded",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003076 }
3077
3078}
3079void btif_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
3080 tBTA_BLE_LOCAL_ID_KEYS *p_id_keys)
3081{
3082 if (ble_local_key_cb.is_er_rcvd )
3083 {
3084 memcpy(&er[0], &ble_local_key_cb.er[0], sizeof(BT_OCTET16));
3085 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ER;
3086 }
3087
3088 if (ble_local_key_cb.is_id_keys_rcvd)
3089 {
3090 memcpy(&p_id_keys->ir[0], &ble_local_key_cb.id_keys.ir[0], sizeof(BT_OCTET16));
3091 memcpy(&p_id_keys->irk[0], &ble_local_key_cb.id_keys.irk[0], sizeof(BT_OCTET16));
3092 memcpy(&p_id_keys->dhk[0], &ble_local_key_cb.id_keys.dhk[0], sizeof(BT_OCTET16));
3093 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID;
3094 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003095 BTIF_TRACE_DEBUG("%s *p_key_mask=0x%02x",__FUNCTION__, *p_key_mask);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003096}
3097
3098void btif_dm_save_ble_bonding_keys(void)
3099{
3100
3101 bt_bdaddr_t bd_addr;
3102
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003103 BTIF_TRACE_DEBUG("%s",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003104
3105 bdcpy(bd_addr.address, pairing_cb.bd_addr);
3106
3107 if (pairing_cb.ble.is_penc_key_rcvd)
3108 {
3109 btif_storage_add_ble_bonding_key(&bd_addr,
3110 (char *) &pairing_cb.ble.penc_key,
3111 BTIF_DM_LE_KEY_PENC,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003112 sizeof(tBTM_LE_PENC_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003113 }
3114
3115 if (pairing_cb.ble.is_pid_key_rcvd)
3116 {
3117 btif_storage_add_ble_bonding_key(&bd_addr,
Andre Eisenbach5e808462014-10-21 12:37:53 -07003118 (char *) &pairing_cb.ble.pid_key,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003119 BTIF_DM_LE_KEY_PID,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003120 sizeof(tBTM_LE_PID_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003121 }
3122
3123
3124 if (pairing_cb.ble.is_pcsrk_key_rcvd)
3125 {
3126 btif_storage_add_ble_bonding_key(&bd_addr,
3127 (char *) &pairing_cb.ble.pcsrk_key,
3128 BTIF_DM_LE_KEY_PCSRK,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003129 sizeof(tBTM_LE_PCSRK_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003130 }
3131
3132
3133 if (pairing_cb.ble.is_lenc_key_rcvd)
3134 {
3135 btif_storage_add_ble_bonding_key(&bd_addr,
3136 (char *) &pairing_cb.ble.lenc_key,
3137 BTIF_DM_LE_KEY_LENC,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003138 sizeof(tBTM_LE_LENC_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003139 }
3140
3141 if (pairing_cb.ble.is_lcsrk_key_rcvd)
3142 {
3143 btif_storage_add_ble_bonding_key(&bd_addr,
3144 (char *) &pairing_cb.ble.lcsrk_key,
3145 BTIF_DM_LE_KEY_LCSRK,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003146 sizeof(tBTM_LE_LCSRK_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003147 }
3148
Satya Calloji444a8da2015-03-06 10:38:22 -08003149 if (pairing_cb.ble.is_lidk_key_rcvd)
3150 {
3151 btif_storage_add_ble_bonding_key(&bd_addr,
3152 NULL,
3153 BTIF_DM_LE_KEY_LID,
3154 0);
3155 }
3156
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003157}
3158
3159
3160void btif_dm_remove_ble_bonding_keys(void)
3161{
3162 bt_bdaddr_t bd_addr;
3163
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003164 BTIF_TRACE_DEBUG("%s",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003165
3166 bdcpy(bd_addr.address, pairing_cb.bd_addr);
3167 btif_storage_remove_ble_bonding_keys(&bd_addr);
3168}
3169
3170
3171/*******************************************************************************
3172**
3173** Function btif_dm_ble_sec_req_evt
3174**
3175** Description Eprocess security request event in btif context
3176**
3177** Returns void
3178**
3179*******************************************************************************/
3180void btif_dm_ble_sec_req_evt(tBTA_DM_BLE_SEC_REQ *p_ble_req)
3181{
3182 bt_bdaddr_t bd_addr;
3183 bt_bdname_t bd_name;
3184 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08003185 int dev_type;
3186
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003187 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003188
3189 if (pairing_cb.state == BT_BOND_STATE_BONDING)
3190 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003191 BTIF_TRACE_DEBUG("%s Discard security request", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003192 return;
3193 }
3194
3195 /* Remote name update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08003196 if (!btif_get_device_type(p_ble_req->bd_addr, &dev_type))
3197 {
3198 dev_type = BT_DEVICE_TYPE_BLE;
3199 }
3200 btif_dm_update_ble_remote_properties(p_ble_req->bd_addr, p_ble_req->bd_name,
3201 (tBT_DEVICE_TYPE) dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003202
3203 bdcpy(bd_addr.address, p_ble_req->bd_addr);
3204 memcpy(bd_name.name, p_ble_req->bd_name, BD_NAME_LEN);
3205
3206 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
3207
Andre Eisenbach89363762015-01-26 13:49:36 -08003208 pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003209 pairing_cb.is_le_only = TRUE;
Satya Calloji7fb0da62015-01-29 20:40:17 -08003210 pairing_cb.is_le_nc = FALSE;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003211 pairing_cb.is_ssp = TRUE;
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07003212 btm_set_bond_type_dev(p_ble_req->bd_addr, pairing_cb.bond_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003213
3214 cod = COD_UNCLASSIFIED;
3215
3216 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod,
3217 BT_SSP_VARIANT_CONSENT, 0);
3218}
3219
3220
3221
3222/*******************************************************************************
3223**
3224** Function btif_dm_ble_passkey_req_evt
3225**
3226** Description Executes pin request event in btif context
3227**
3228** Returns void
3229**
3230*******************************************************************************/
3231static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
3232{
3233 bt_bdaddr_t bd_addr;
3234 bt_bdname_t bd_name;
3235 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08003236 int dev_type;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003237
3238 /* Remote name update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08003239 if (!btif_get_device_type(p_pin_req->bd_addr, &dev_type))
3240 {
3241 dev_type = BT_DEVICE_TYPE_BLE;
3242 }
3243 btif_dm_update_ble_remote_properties(p_pin_req->bd_addr,p_pin_req->bd_name,
3244 (tBT_DEVICE_TYPE) dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003245
3246 bdcpy(bd_addr.address, p_pin_req->bd_addr);
3247 memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN);
3248
3249 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
3250 pairing_cb.is_le_only = TRUE;
3251
3252 cod = COD_UNCLASSIFIED;
3253
3254 HAL_CBACK(bt_hal_cbacks, pin_request_cb,
Casper Bonde818d0f22015-05-21 11:08:45 +02003255 &bd_addr, &bd_name, cod, FALSE);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003256}
Satya Calloji444a8da2015-03-06 10:38:22 -08003257static void btif_dm_ble_key_nc_req_evt(tBTA_DM_SP_KEY_NOTIF *p_notif_req)
3258{
3259 /* TODO implement key notification for numeric comparison */
3260 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003261
Satya Calloji444a8da2015-03-06 10:38:22 -08003262 /* Remote name update */
3263 btif_update_remote_properties(p_notif_req->bd_addr , p_notif_req->bd_name,
3264 NULL, BT_DEVICE_TYPE_BLE);
3265
3266 bt_bdaddr_t bd_addr;
3267 bdcpy(bd_addr.address, p_notif_req->bd_addr);
3268
3269 bt_bdname_t bd_name;
3270 memcpy(bd_name.name, p_notif_req->bd_name, BD_NAME_LEN);
3271
3272 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
3273 pairing_cb.is_ssp = FALSE;
Satya Calloji7fb0da62015-01-29 20:40:17 -08003274 pairing_cb.is_le_only = TRUE;
3275 pairing_cb.is_le_nc = TRUE;
Satya Calloji444a8da2015-03-06 10:38:22 -08003276
3277 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
3278 COD_UNCLASSIFIED, BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
3279 p_notif_req->passkey);
3280}
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003281
3282void btif_dm_update_ble_remote_properties( BD_ADDR bd_addr, BD_NAME bd_name,
3283 tBT_DEVICE_TYPE dev_type)
3284{
3285 btif_update_remote_properties(bd_addr,bd_name,NULL,dev_type);
3286}
3287
3288static void btif_dm_ble_tx_test_cback(void *p)
3289{
3290 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TX_TEST,
3291 (char *)p, 1, NULL);
3292}
3293
3294static void btif_dm_ble_rx_test_cback(void *p)
3295{
3296 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_RX_TEST,
3297 (char *)p, 1, NULL);
3298}
3299
3300static void btif_dm_ble_test_end_cback(void *p)
3301{
3302 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TEST_END,
3303 (char *)p, 3, NULL);
3304}
3305/*******************************************************************************
3306**
3307** Function btif_le_test_mode
3308**
3309** Description Sends a HCI BLE Test command to the Controller
3310**
3311** Returns BT_STATUS_SUCCESS on success
3312**
3313*******************************************************************************/
3314bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t len)
3315{
3316 switch (opcode) {
3317 case HCI_BLE_TRANSMITTER_TEST:
3318 if (len != 3) return BT_STATUS_PARM_INVALID;
3319 BTM_BleTransmitterTest(buf[0],buf[1],buf[2], btif_dm_ble_tx_test_cback);
3320 break;
3321 case HCI_BLE_RECEIVER_TEST:
3322 if (len != 1) return BT_STATUS_PARM_INVALID;
3323 BTM_BleReceiverTest(buf[0], btif_dm_ble_rx_test_cback);
3324 break;
3325 case HCI_BLE_TEST_END:
3326 BTM_BleTestEnd((tBTM_CMPL_CB*) btif_dm_ble_test_end_cback);
3327 break;
3328 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003329 BTIF_TRACE_ERROR("%s: Unknown LE Test Mode Command 0x%x", __FUNCTION__, opcode);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003330 return BT_STATUS_UNSUPPORTED;
3331 }
3332 return BT_STATUS_SUCCESS;
3333}
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003334#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08003335
3336void btif_dm_on_disable()
3337{
3338 /* cancel any pending pairing requests */
3339 if (pairing_cb.state == BT_BOND_STATE_BONDING)
3340 {
3341 bt_bdaddr_t bd_addr;
3342
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003343 BTIF_TRACE_DEBUG("%s: Cancel pending pairing request", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003344 bdcpy(bd_addr.address, pairing_cb.bd_addr);
3345 btif_dm_cancel_bond(&bd_addr);
3346 }
3347}
Matthew Xie1e5109b2012-11-09 18:26:26 -08003348
Satya Callojie5ba8842014-07-03 17:18:02 -07003349/*******************************************************************************
3350**
3351** Function btif_dm_read_energy_info
3352**
3353** Description Reads the energy info from controller
3354**
3355** Returns void
3356**
3357*******************************************************************************/
3358void btif_dm_read_energy_info()
3359{
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07003360#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Satya Callojie5ba8842014-07-03 17:18:02 -07003361 BTA_DmBleGetEnergyInfo(bta_energy_info_cb);
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07003362#endif
Satya Callojie5ba8842014-07-03 17:18:02 -07003363}
3364
Matthew Xie1e5109b2012-11-09 18:26:26 -08003365static char* btif_get_default_local_name() {
3366 if (btif_default_local_name[0] == '\0')
3367 {
3368 int max_len = sizeof(btif_default_local_name) - 1;
3369 if (BTM_DEF_LOCAL_NAME[0] != '\0')
3370 {
3371 strncpy(btif_default_local_name, BTM_DEF_LOCAL_NAME, max_len);
3372 }
3373 else
3374 {
3375 char prop_model[PROPERTY_VALUE_MAX];
3376 property_get(PROPERTY_PRODUCT_MODEL, prop_model, "");
3377 strncpy(btif_default_local_name, prop_model, max_len);
3378 }
3379 btif_default_local_name[max_len] = '\0';
3380 }
3381 return btif_default_local_name;
3382}