blob: 35627af86101725058c6bbeda342f3b1691f82dc [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);
Anubhav Gupta791692a2013-12-06 17:11:11 +0530217extern void btif_av_move_idle(bt_bdaddr_t bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800218
219
220/******************************************************************************
221** Functions
222******************************************************************************/
223
Andre Eisenbach8a057242015-04-29 22:27:15 -0700224static void btif_dm_data_copy(uint16_t event, char *dst, char *src)
225{
226 tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC*)dst;
227 tBTA_DM_SEC *src_dm_sec = (tBTA_DM_SEC*)src;
228
229 if (!src_dm_sec)
230 return;
231
232 assert(dst_dm_sec);
233 memcpy(dst_dm_sec, src_dm_sec, sizeof(tBTA_DM_SEC));
234
235 if (event == BTA_DM_BLE_KEY_EVT)
236 {
237 dst_dm_sec->ble_key.p_key_value = osi_malloc(sizeof(tBTM_LE_KEY_VALUE));
238 assert(src_dm_sec->ble_key.p_key_value);
239 assert(dst_dm_sec->ble_key.p_key_value);
240 memcpy(dst_dm_sec->ble_key.p_key_value, src_dm_sec->ble_key.p_key_value, sizeof(tBTM_LE_KEY_VALUE));
241 }
242}
243
244static void btif_dm_data_free(uint16_t event, tBTA_DM_SEC *dm_sec)
245{
246 if (event == BTA_DM_BLE_KEY_EVT)
247 osi_free(dm_sec->ble_key.p_key_value);
248}
249
The Android Open Source Project5738f832012-12-12 16:00:35 -0800250bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id,
251 BOOLEAN b_enable)
252{
Kim Schulz8372aa52015-03-25 10:39:40 +0100253 BTIF_TRACE_DEBUG("%s service_id: %d", __FUNCTION__, service_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800254 /* Check the service_ID and invoke the profile's BT state changed API */
255 switch (service_id)
256 {
257 case BTA_HFP_SERVICE_ID:
258 case BTA_HSP_SERVICE_ID:
259 {
260 btif_hf_execute_service(b_enable);
261 }break;
Sharvil Nanavati9609cee2014-10-15 18:30:49 -0700262 case BTA_A2DP_SOURCE_SERVICE_ID:
The Android Open Source Project5738f832012-12-12 16:00:35 -0800263 {
264 btif_av_execute_service(b_enable);
265 }break;
Rakesh Iyer9c8dfac2015-04-08 12:25:37 -0700266 case BTA_A2DP_SINK_SERVICE_ID:
267 {
268 btif_av_sink_execute_service(b_enable);
269 }break;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800270 case BTA_HID_SERVICE_ID:
271 {
272 btif_hh_execute_service(b_enable);
273 }break;
Hemant Gupta10256872013-08-19 18:33:01 +0530274 case BTA_HFP_HS_SERVICE_ID:
275 {
276 btif_hf_client_execute_service(b_enable);
277 }break;
Kim Schulz8372aa52015-03-25 10:39:40 +0100278 case BTA_SDP_SERVICE_ID:
Hemant Gupta2dc99992014-04-18 12:54:08 +0530279 {
Kim Schulz8372aa52015-03-25 10:39:40 +0100280 btif_sdp_execute_service(b_enable);
Hemant Gupta2dc99992014-04-18 12:54:08 +0530281 }break;
Hemant Gupta94c15ec2013-11-11 12:33:44 +0530282 case BTA_HIDD_SERVICE_ID:
283 {
284 btif_hd_execute_service(b_enable);
285 }break;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800286 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700287 BTIF_TRACE_ERROR("%s: Unknown service being enabled", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800288 return BT_STATUS_FAIL;
289 }
290 return BT_STATUS_SUCCESS;
291}
292
293/*******************************************************************************
294**
295** Function check_eir_remote_name
296**
297** Description Check if remote name is in the EIR data
298**
299** Returns TRUE if remote name found
300** Populate p_remote_name, if provided and remote name found
301**
302*******************************************************************************/
303static BOOLEAN check_eir_remote_name(tBTA_DM_SEARCH *p_search_data,
304 UINT8 *p_remote_name, UINT8 *p_remote_name_len)
305{
306 UINT8 *p_eir_remote_name = NULL;
307 UINT8 remote_name_len = 0;
308
309 /* Check EIR for remote name and services */
310 if (p_search_data->inq_res.p_eir)
311 {
Zach Johnsona50fc882014-10-30 21:02:58 -0700312 p_eir_remote_name = BTM_CheckEirData(p_search_data->inq_res.p_eir,
The Android Open Source Project5738f832012-12-12 16:00:35 -0800313 BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, &remote_name_len);
314 if (!p_eir_remote_name)
315 {
Zach Johnsona50fc882014-10-30 21:02:58 -0700316 p_eir_remote_name = BTM_CheckEirData(p_search_data->inq_res.p_eir,
The Android Open Source Project5738f832012-12-12 16:00:35 -0800317 BTM_EIR_SHORTENED_LOCAL_NAME_TYPE, &remote_name_len);
318 }
319
320 if (p_eir_remote_name)
321 {
322 if (remote_name_len > BD_NAME_LEN)
323 remote_name_len = BD_NAME_LEN;
324
325 if (p_remote_name && p_remote_name_len)
326 {
327 memcpy(p_remote_name, p_eir_remote_name, remote_name_len);
328 *(p_remote_name + remote_name_len) = 0;
329 *p_remote_name_len = remote_name_len;
330 }
331
332 return TRUE;
333 }
334 }
335
336 return FALSE;
337
338}
339
340/*******************************************************************************
341**
342** Function check_cached_remote_name
343**
344** Description Check if remote name is in the NVRAM cache
345**
346** Returns TRUE if remote name found
347** Populate p_remote_name, if provided and remote name found
348**
349*******************************************************************************/
350static BOOLEAN check_cached_remote_name(tBTA_DM_SEARCH *p_search_data,
351 UINT8 *p_remote_name, UINT8 *p_remote_name_len)
352{
353 bt_bdname_t bdname;
354 bt_bdaddr_t remote_bdaddr;
355 bt_property_t prop_name;
356
357 /* check if we already have it in our btif_storage cache */
358 bdcpy(remote_bdaddr.address, p_search_data->inq_res.bd_addr);
359 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_BDNAME,
360 sizeof(bt_bdname_t), &bdname);
361 if (btif_storage_get_remote_device_property(
362 &remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS)
363 {
364 if (p_remote_name && p_remote_name_len)
365 {
366 strcpy((char *)p_remote_name, (char *)bdname.name);
367 *p_remote_name_len = strlen((char *)p_remote_name);
368 }
369 return TRUE;
370 }
371
372 return FALSE;
373}
374
375BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod)
376{
377 uint32_t remote_cod;
378 bt_property_t prop_name;
379
380 /* check if we already have it in our btif_storage cache */
381 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE,
382 sizeof(uint32_t), &remote_cod);
383 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS)
384 {
Chris Mantonf8027002015-03-12 09:22:48 -0700385 LOG_INFO("%s remote_cod = 0x%08x cod = 0x%08x", __func__, remote_cod, cod);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800386 if ((remote_cod & 0x7ff) == cod)
387 return TRUE;
388 }
389
390 return FALSE;
391}
392
Priti Agheraebb1d752012-11-27 18:03:22 -0800393BOOLEAN check_cod_hid(const bt_bdaddr_t *remote_bdaddr, uint32_t cod)
394{
395 uint32_t remote_cod;
396 bt_property_t prop_name;
397
398 /* check if we already have it in our btif_storage cache */
399 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE,
400 sizeof(uint32_t), &remote_cod);
401 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
402 &prop_name) == BT_STATUS_SUCCESS)
403 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700404 BTIF_TRACE_DEBUG("%s: remote_cod = 0x%06x", __FUNCTION__, remote_cod);
Hemant Guptae4def912014-09-18 14:19:57 +0530405 if ((remote_cod & 0x700) == cod) {
406 BTIF_TRACE_DEBUG("%s: returning TRUE", __FUNCTION__);
Priti Agheraebb1d752012-11-27 18:03:22 -0800407 return TRUE;
Hemant Guptae4def912014-09-18 14:19:57 +0530408 }
Priti Agheraebb1d752012-11-27 18:03:22 -0800409 }
Hemant Guptae4def912014-09-18 14:19:57 +0530410 BTIF_TRACE_DEBUG("%s: returning FALSE", __FUNCTION__);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700411 return FALSE;
412}
Priti Agheraebb1d752012-11-27 18:03:22 -0800413
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700414BOOLEAN check_hid_le(const bt_bdaddr_t *remote_bdaddr)
415{
416 uint32_t remote_dev_type;
417 bt_property_t prop_name;
418
419 /* check if we already have it in our btif_storage cache */
420 BTIF_STORAGE_FILL_PROPERTY(&prop_name,BT_PROPERTY_TYPE_OF_DEVICE,
421 sizeof(uint32_t), &remote_dev_type);
422 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
423 &prop_name) == BT_STATUS_SUCCESS)
424 {
425 if (remote_dev_type == BT_DEVICE_DEVTYPE_BLE)
426 {
427 bdstr_t bdstr;
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -0700428 bdaddr_to_string(remote_bdaddr, bdstr, sizeof(bdstr));
Sharvil Nanavati9d52f882014-08-19 09:50:18 -0700429 if(btif_config_exist(bdstr, "HidAppId"))
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700430 return TRUE;
431 }
432 }
Priti Agheraebb1d752012-11-27 18:03:22 -0800433 return FALSE;
434}
435
Priti Agherac0edf9f2014-06-26 11:23:51 -0700436/*****************************************************************************
437**
Hemant Guptada33b462015-04-26 10:32:57 +0530438** Function check_if_auth_bl
439**
440** Description Checks if a given device is blacklisted to skip authentication
441**
442** Parameters remote_bdaddr
443**
444** Returns TRUE if the device is present in blacklist, else FALSE
445**
446*******************************************************************************/
447static bool check_if_auth_bl(bt_bdaddr_t * remote_bdaddr)
448{
449 if (remote_bdaddr == NULL) {
450 LOG_WARN("%s: remote_bdaddr = NULL, returning false", __func__);
451 return FALSE;
452 }
453
454 bt_property_t prop_name;
455 bt_bdname_t bdname;
456
457 if (interop_addr_match(INTEROP_DISABLE_AUTH_FOR_HID_POINTING, remote_bdaddr))
458 return TRUE;
459
460 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_BDNAME,
461 sizeof(bt_bdname_t), &bdname);
462 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
463 &prop_name) != BT_STATUS_SUCCESS)
464 {
465 LOG_WARN("%s: BT_PROPERTY_BDNAME failed, returning false", __func__);
466 return FALSE;
467 }
468
469 if (bdname.name != NULL &&
470 interop_name_match(INTEROP_DISABLE_SDP_AFTER_PAIRING, (const char *)bdname.name))
471 return TRUE;
472
473 char bdstr[20] = {0};
474 LOG_DEBUG("%s: %s is not in blacklist for skipping auth", __func__,
475 bdaddr_to_string(remote_bdaddr, bdstr, sizeof(bdstr)));
476 return FALSE;
477}
478
479/*****************************************************************************
480**
Priti Agherac0edf9f2014-06-26 11:23:51 -0700481** Function check_sdp_bl
482**
483** Description Checks if a given device is blacklisted to skip sdp
484**
Hemant Guptada33b462015-04-26 10:32:57 +0530485** Parameters remote_bdaddr
Priti Agherac0edf9f2014-06-26 11:23:51 -0700486**
487** Returns TRUE if the device is present in blacklist, else FALSE
488**
489*******************************************************************************/
490BOOLEAN check_sdp_bl(const bt_bdaddr_t *remote_bdaddr)
491{
Hemant Guptada33b462015-04-26 10:32:57 +0530492 if (remote_bdaddr == NULL) {
493 LOG_WARN("%s: remote_bdaddr = NULL, returning false", __func__);
494 return FALSE;
495 }
496
497 if (interop_addr_match(INTEROP_DISABLE_SDP_AFTER_PAIRING, remote_bdaddr)) {
498 LOG_WARN("%s: device is in blacklist for skipping sdp", __func__);
499 return TRUE;
500 }
501
502 bt_property_t prop_name;
503 bt_bdname_t bdname;
504 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_BDNAME,
505 sizeof(bt_bdname_t), &bdname);
506 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
507 &prop_name) != BT_STATUS_SUCCESS)
508 {
509 LOG_WARN("%s: BT_PROPERTY_BDNAME failed, returning false", __func__);
510 return FALSE;
511 }
512
513 if (bdname.name != NULL &&
514 interop_name_match(INTEROP_DISABLE_SDP_AFTER_PAIRING, (const char *)bdname.name))
515 return TRUE;
516
Priti Agherac0edf9f2014-06-26 11:23:51 -0700517 UINT16 manufacturer = 0;
518 UINT8 lmp_ver = 0;
519 UINT16 lmp_subver = 0;
Priti Agherac0edf9f2014-06-26 11:23:51 -0700520 bt_remote_version_t info;
Priti Agherac0edf9f2014-06-26 11:23:51 -0700521
Hemant Guptada33b462015-04-26 10:32:57 +0530522 /* fetch additional info about remote device used in iop query */
Sharvil Nanavatif1c764f2015-02-23 17:31:48 -0800523 BTM_ReadRemoteVersion(*(BD_ADDR*)remote_bdaddr, &lmp_ver,
Priti Agherac0edf9f2014-06-26 11:23:51 -0700524 &manufacturer, &lmp_subver);
525
Hemant Guptada33b462015-04-26 10:32:57 +0530526 /* if not available yet, try fetching from config database */
Priti Agherac0edf9f2014-06-26 11:23:51 -0700527 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_REMOTE_VERSION_INFO,
528 sizeof(bt_remote_version_t), &info);
529
530 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
531 &prop_name) != BT_STATUS_SUCCESS)
532 {
533
Hemant Guptada33b462015-04-26 10:32:57 +0530534 APPL_TRACE_WARNING("%s: BT_PROPERTY_REMOTE_VERSION_INFO failed, returning false", __func__);
Priti Agherac0edf9f2014-06-26 11:23:51 -0700535 return FALSE;
536 }
537 manufacturer = info.manufacturer;
538
Hemant Guptada33b462015-04-26 10:32:57 +0530539 if (manufacturer != 0 &&
540 interop_manufacturer_match(INTEROP_DISABLE_SDP_AFTER_PAIRING, manufacturer))
541 return TRUE;
542
543 char bdstr[20] = {0};
544 LOG_DEBUG("%s: %s is not in blacklist for skipping sdp", __func__,
545 bdaddr_to_string(remote_bdaddr, bdstr, sizeof(bdstr)));
Priti Agherac0edf9f2014-06-26 11:23:51 -0700546 return FALSE;
547}
548
The Android Open Source Project5738f832012-12-12 16:00:35 -0800549static void bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr, bt_bond_state_t state)
550{
Chaojing Sune2805532015-04-22 13:40:21 -0700551 // Send bonding state only once - based on outgoing/incoming we may receive duplicates
552 if ((pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING))
553 {
554 // Cross key pairing so send callback for static address
Andre Eisenbache87ef6d2015-05-01 13:14:59 -0700555 if (!bdaddr_is_empty(&pairing_cb.static_bdaddr))
556 {
Chaojing Sune2805532015-04-22 13:40:21 -0700557 HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state);
Andre Eisenbache87ef6d2015-05-01 13:14:59 -0700558 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800559 return;
Chaojing Sune2805532015-04-22 13:40:21 -0700560 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800561
Andre Eisenbach89363762015-01-26 13:49:36 -0800562 if (pairing_cb.bond_type == BOND_TYPE_TEMPORARY)
Chaojing Sune2805532015-04-22 13:40:21 -0700563 state = BT_BOND_STATE_NONE;
564
565 BTIF_TRACE_DEBUG("%s: state=%d, prev_state=%d, sdp_attempts = %d", __func__,
566 state, pairing_cb.state, pairing_cb.sdp_attempts);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800567
568 HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state);
569
570 if (state == BT_BOND_STATE_BONDING)
571 {
572 pairing_cb.state = state;
573 bdcpy(pairing_cb.bd_addr, bd_addr->address);
Chaojing Sune2805532015-04-22 13:40:21 -0700574 } else {
575 if (!pairing_cb.sdp_attempts)
576 memset(&pairing_cb, 0, sizeof(pairing_cb));
577 else
578 BTIF_TRACE_DEBUG("%s: BR-EDR service discovery active", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800579 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800580}
581
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800582/* store remote version in bt config to always have access
583 to it post pairing*/
584static void btif_update_remote_version_property(bt_bdaddr_t *p_bd)
585{
586 bt_property_t property;
587 UINT8 lmp_ver = 0;
588 UINT16 lmp_subver = 0;
589 UINT16 mfct_set = 0;
590 tBTM_STATUS btm_status;
591 bt_remote_version_t info;
592 bt_status_t status;
593 bdstr_t bdstr;
594
595 btm_status = BTM_ReadRemoteVersion(*(BD_ADDR*)p_bd, &lmp_ver,
596 &mfct_set, &lmp_subver);
597
Sharvil Nanavati44802762014-12-23 23:08:58 -0800598 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 -0800599 lmp_ver, mfct_set, lmp_subver);
600
601 if (btm_status == BTM_SUCCESS)
602 {
Chaojing Sune2805532015-04-22 13:40:21 -0700603 // Always update cache to ensure we have availability whenever BTM API is not populated
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800604 info.manufacturer = mfct_set;
605 info.sub_ver = lmp_subver;
606 info.version = lmp_ver;
607 BTIF_STORAGE_FILL_PROPERTY(&property,
608 BT_PROPERTY_REMOTE_VERSION_INFO, sizeof(bt_remote_version_t),
609 &info);
610 status = btif_storage_set_remote_device_property(p_bd, &property);
611 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote version", status);
612 }
613}
614
The Android Open Source Project5738f832012-12-12 16:00:35 -0800615
616static void btif_update_remote_properties(BD_ADDR bd_addr, BD_NAME bd_name,
617 DEV_CLASS dev_class, tBT_DEVICE_TYPE device_type)
618{
619 int num_properties = 0;
620 bt_property_t properties[3];
621 bt_bdaddr_t bdaddr;
622 bt_status_t status;
623 UINT32 cod;
624 bt_device_type_t dev_type;
625
626 memset(properties, 0, sizeof(properties));
627 bdcpy(bdaddr.address, bd_addr);
628
629 /* remote name */
630 if (strlen((const char *) bd_name))
631 {
632 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
633 BT_PROPERTY_BDNAME, strlen((char *)bd_name), bd_name);
634 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
635 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device name", status);
636 num_properties++;
637 }
638
639 /* class of device */
640 cod = devclass2uint(dev_class);
Chris Mantonf8027002015-03-12 09:22:48 -0700641 BTIF_TRACE_DEBUG("%s cod is 0x%06x", __func__, cod);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800642 if ( cod == 0) {
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530643 /* Try to retrieve cod from storage */
Chris Mantonf8027002015-03-12 09:22:48 -0700644 BTIF_TRACE_DEBUG("%s cod is 0, checking cod from storage", __func__);
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530645 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
646 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
647 status = btif_storage_get_remote_device_property(&bdaddr, &properties[num_properties]);
Chris Mantonf8027002015-03-12 09:22:48 -0700648 BTIF_TRACE_DEBUG("%s cod retrieved from storage is 0x%06x", __func__, cod);
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530649 if ( cod == 0) {
Chris Mantonf8027002015-03-12 09:22:48 -0700650 BTIF_TRACE_DEBUG("%s cod is again 0, set as unclassified", __func__);
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530651 cod = COD_UNCLASSIFIED;
652 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800653 }
654
655 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
656 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
657 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
658 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device class", status);
659 num_properties++;
660
661 /* device type */
Chaojing Sune2805532015-04-22 13:40:21 -0700662 bt_property_t prop_name;
663 uint8_t remote_dev_type;
664 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_TYPE_OF_DEVICE,
665 sizeof(uint8_t), &remote_dev_type);
666 if (btif_storage_get_remote_device_property(&bdaddr, &prop_name) == BT_STATUS_SUCCESS)
667 dev_type = remote_dev_type | device_type;
668 else
669 dev_type = device_type;
670
The Android Open Source Project5738f832012-12-12 16:00:35 -0800671 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
672 BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
673 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
674 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device type", status);
675 num_properties++;
676
677 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
678 status, &bdaddr, num_properties, properties);
679}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800680
681/*******************************************************************************
682**
683** Function btif_dm_cb_hid_remote_name
684**
685** Description Remote name callback for HID device. Called in btif context
686** Special handling for HID devices
687**
688** Returns void
689**
690*******************************************************************************/
691static void btif_dm_cb_hid_remote_name(tBTM_REMOTE_DEV_NAME *p_remote_name)
692{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700693 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 -0800694 if (pairing_cb.state == BT_BOND_STATE_BONDING)
695 {
696 bt_bdaddr_t remote_bd;
697
698 bdcpy(remote_bd.address, pairing_cb.bd_addr);
699
700 if (p_remote_name->status == BTM_SUCCESS)
701 {
702 bond_state_changed(BT_STATUS_SUCCESS, &remote_bd, BT_BOND_STATE_BONDED);
703 }
704 else
705 bond_state_changed(BT_STATUS_FAIL, &remote_bd, BT_BOND_STATE_NONE);
706 }
707}
708
The Android Open Source Project5738f832012-12-12 16:00:35 -0800709/*******************************************************************************
710**
711** Function btif_dm_cb_create_bond
712**
713** Description Create bond initiated from the BTIF thread context
714** Special handling for HID devices
715**
716** Returns void
717**
718*******************************************************************************/
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -0700719static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr, tBTA_TRANSPORT transport)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800720{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800721 BOOLEAN is_hid = check_cod(bd_addr, COD_HID_POINTING);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800722 bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800723
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800724#if BLE_INCLUDED == TRUE
725 int device_type;
726 int addr_type;
727 bdstr_t bdstr;
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -0700728 bdaddr_to_string(bd_addr, bdstr, sizeof(bdstr));
Matthew Xie64c54792014-09-16 00:55:03 -0700729 if (transport == BT_TRANSPORT_LE)
730 {
Sharvil Nanavati9d52f882014-08-19 09:50:18 -0700731 if (!btif_config_get_int((char const *)&bdstr,"DevType", &device_type))
Matthew Xie64c54792014-09-16 00:55:03 -0700732 {
Sharvil Nanavati9d52f882014-08-19 09:50:18 -0700733 btif_config_set_int(bdstr, "DevType", BT_DEVICE_TYPE_BLE);
Matthew Xie64c54792014-09-16 00:55:03 -0700734 }
735 if (btif_storage_get_remote_addr_type(bd_addr, &addr_type) != BT_STATUS_SUCCESS)
736 {
737 btif_storage_set_remote_addr_type(bd_addr, BLE_ADDR_PUBLIC);
738 }
739 }
Sharvil Nanavati9d52f882014-08-19 09:50:18 -0700740 if((btif_config_get_int((char const *)&bdstr,"DevType", &device_type) &&
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800741 (btif_storage_get_remote_addr_type(bd_addr, &addr_type) == BT_STATUS_SUCCESS) &&
Chaojing Sune2805532015-04-22 13:40:21 -0700742 (device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE) || (transport == BT_TRANSPORT_LE))
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800743 {
Chaojing Sune2805532015-04-22 13:40:21 -0700744 BTA_DmAddBleDevice(bd_addr->address, addr_type, device_type);
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800745 }
746#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800747
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800748#if BLE_INCLUDED == TRUE
Chaojing Sune2805532015-04-22 13:40:21 -0700749 if(is_hid && (device_type & BT_DEVICE_TYPE_BLE) == 0)
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800750#else
751 if(is_hid)
752#endif
753 {
754 int status;
755 status = btif_hh_connect(bd_addr);
756 if(status != BT_STATUS_SUCCESS)
757 bond_state_changed(status, bd_addr, BT_BOND_STATE_NONE);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800758 }
759 else
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800760 {
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -0700761 BTA_DmBondByTransport((UINT8 *)bd_addr->address, transport);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800762 }
763 /* Track originator of bond creation */
764 pairing_cb.is_local_initiated = TRUE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800765
766}
767
768/*******************************************************************************
769**
770** Function btif_dm_cb_remove_bond
771**
772** Description remove bond initiated from the BTIF thread context
773** Special handling for HID devices
774**
775** Returns void
776**
777*******************************************************************************/
778void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr)
779{
The Android Open Source Project5738f832012-12-12 16:00:35 -0800780 /*special handling for HID devices */
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -0700781 /* VUP needs to be sent if its a HID Device. The HID HOST module will check if there
782 is a valid hid connection with this bd_addr. If yes VUP will be issued.*/
783#if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
784 if (btif_hh_virtual_unplug(bd_addr) != BT_STATUS_SUCCESS)
785#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800786 {
Chaojing Sune2805532015-04-22 13:40:21 -0700787 BTIF_TRACE_DEBUG("%s: Removing HH device", __func__);
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -0700788 BTA_DmRemoveDevice((UINT8 *)bd_addr->address);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800789 }
790}
791
792/*******************************************************************************
793**
Andre Eisenbach249f6002014-06-18 12:20:37 -0700794** Function btif_dm_get_connection_state
795**
796** Description Returns whether the remote device is currently connected
Andre Eisenbachdfb3b2f2015-02-05 20:00:45 -0800797** and whether encryption is active for the connection
Andre Eisenbach249f6002014-06-18 12:20:37 -0700798**
Andre Eisenbachdfb3b2f2015-02-05 20:00:45 -0800799** Returns 0 if not connected; 1 if connected and > 1 if connection is
800** encrypted
Andre Eisenbach249f6002014-06-18 12:20:37 -0700801**
802*******************************************************************************/
803uint16_t btif_dm_get_connection_state(const bt_bdaddr_t *bd_addr)
804{
Andre Eisenbachdfb3b2f2015-02-05 20:00:45 -0800805 uint8_t *bda = (uint8_t*)bd_addr->address;
806 uint16_t rc = BTA_DmGetConnectionState(bda);
807
808 if (rc != 0)
809 {
810 uint8_t flags = 0;
811
812 BTM_GetSecurityFlagsByTransport(bda, &flags, BT_TRANSPORT_BR_EDR);
813 BTIF_TRACE_DEBUG("%s: security flags (BR/EDR)=0x%02x", __FUNCTION__, flags);
814 if (flags & BTM_SEC_FLAG_ENCRYPTED)
815 rc |= ENCRYPTED_BREDR;
816
817 BTM_GetSecurityFlagsByTransport(bda, &flags, BT_TRANSPORT_LE);
818 BTIF_TRACE_DEBUG("%s: security flags (LE)=0x%02x", __FUNCTION__, flags);
819 if (flags & BTM_SEC_FLAG_ENCRYPTED)
820 rc |= ENCRYPTED_LE;
821 }
822
823 return rc;
Andre Eisenbach249f6002014-06-18 12:20:37 -0700824}
825
826/*******************************************************************************
827**
The Android Open Source Project5738f832012-12-12 16:00:35 -0800828** Function search_devices_copy_cb
829**
830** Description Deep copy callback for search devices event
831**
832** Returns void
833**
834*******************************************************************************/
835static void search_devices_copy_cb(UINT16 event, char *p_dest, char *p_src)
836{
837 tBTA_DM_SEARCH *p_dest_data = (tBTA_DM_SEARCH *) p_dest;
838 tBTA_DM_SEARCH *p_src_data = (tBTA_DM_SEARCH *) p_src;
839
840 if (!p_src)
841 return;
842
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700843 BTIF_TRACE_DEBUG("%s: event=%s", __FUNCTION__, dump_dm_search_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800844 memcpy(p_dest_data, p_src_data, sizeof(tBTA_DM_SEARCH));
845 switch (event)
846 {
847 case BTA_DM_INQ_RES_EVT:
848 {
849 if (p_src_data->inq_res.p_eir)
850 {
851 p_dest_data->inq_res.p_eir = (UINT8 *)(p_dest + sizeof(tBTA_DM_SEARCH));
852 memcpy(p_dest_data->inq_res.p_eir, p_src_data->inq_res.p_eir, HCI_EXT_INQ_RESPONSE_LEN);
853 }
854 }
855 break;
856
857 case BTA_DM_DISC_RES_EVT:
858 {
859 if (p_src_data->disc_res.raw_data_size && p_src_data->disc_res.p_raw_data)
860 {
861 p_dest_data->disc_res.p_raw_data = (UINT8 *)(p_dest + sizeof(tBTA_DM_SEARCH));
862 memcpy(p_dest_data->disc_res.p_raw_data,
863 p_src_data->disc_res.p_raw_data, p_src_data->disc_res.raw_data_size);
864 }
865 }
866 break;
867 }
868}
869
870static void search_services_copy_cb(UINT16 event, char *p_dest, char *p_src)
871{
872 tBTA_DM_SEARCH *p_dest_data = (tBTA_DM_SEARCH *) p_dest;
873 tBTA_DM_SEARCH *p_src_data = (tBTA_DM_SEARCH *) p_src;
874
875 if (!p_src)
876 return;
877 memcpy(p_dest_data, p_src_data, sizeof(tBTA_DM_SEARCH));
878 switch (event)
879 {
880 case BTA_DM_DISC_RES_EVT:
881 {
Kausik Sinnaswamy95664a92013-05-03 15:02:50 +0530882 if (p_src_data->disc_res.result == BTA_SUCCESS)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800883 {
Kausik Sinnaswamy95664a92013-05-03 15:02:50 +0530884 if (p_src_data->disc_res.num_uuids > 0)
885 {
886 p_dest_data->disc_res.p_uuid_list =
887 (UINT8*)(p_dest + sizeof(tBTA_DM_SEARCH));
888 memcpy(p_dest_data->disc_res.p_uuid_list, p_src_data->disc_res.p_uuid_list,
889 p_src_data->disc_res.num_uuids*MAX_UUID_SIZE);
890 GKI_freebuf(p_src_data->disc_res.p_uuid_list);
891 }
892 if (p_src_data->disc_res.p_raw_data != NULL)
893 {
894 GKI_freebuf(p_src_data->disc_res.p_raw_data);
895 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800896 }
897 } break;
898 }
899}
900/******************************************************************************
901**
902** BTIF DM callback events
903**
904*****************************************************************************/
905
906/*******************************************************************************
907**
908** Function btif_dm_pin_req_evt
909**
910** Description Executes pin request event in btif context
911**
912** Returns void
913**
914*******************************************************************************/
915static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
916{
917 bt_bdaddr_t bd_addr;
918 bt_bdname_t bd_name;
919 UINT32 cod;
920 bt_pin_code_t pin_code;
Matthew Xie86f97ed2014-11-10 10:24:46 -0800921 int dev_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800922
923 /* Remote properties update */
Matthew Xie86f97ed2014-11-10 10:24:46 -0800924 if (!btif_get_device_type(p_pin_req->bd_addr, &dev_type))
925 {
926 dev_type = BT_DEVICE_TYPE_BREDR;
927 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800928 btif_update_remote_properties(p_pin_req->bd_addr, p_pin_req->bd_name,
Matthew Xie86f97ed2014-11-10 10:24:46 -0800929 p_pin_req->dev_class, (tBT_DEVICE_TYPE) dev_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800930
931 bdcpy(bd_addr.address, p_pin_req->bd_addr);
932 memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN);
933
934 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
935
936 cod = devclass2uint(p_pin_req->dev_class);
937
Chris Mantonf8027002015-03-12 09:22:48 -0700938 if (cod == 0) {
939 BTIF_TRACE_DEBUG("%s cod is 0, set as unclassified", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800940 cod = COD_UNCLASSIFIED;
941 }
942
943 /* check for auto pair possiblity only if bond was initiated by local device */
Casper Bonde818d0f22015-05-21 11:08:45 +0200944 if (pairing_cb.is_local_initiated && (p_pin_req->min_16_digit == FALSE))
The Android Open Source Project5738f832012-12-12 16:00:35 -0800945 {
946 if (check_cod(&bd_addr, COD_AV_HEADSETS) ||
947 check_cod(&bd_addr, COD_AV_HANDSFREE) ||
948 check_cod(&bd_addr, COD_AV_HEADPHONES) ||
949 check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) ||
950 check_cod(&bd_addr, COD_AV_HIFI_AUDIO) ||
951 check_cod(&bd_addr, COD_HID_POINTING))
952 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700953 BTIF_TRACE_DEBUG("%s()cod matches for auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800954 /* Check if this device can be auto paired */
955 if ((btif_storage_is_device_autopair_blacklisted(&bd_addr) == FALSE) &&
956 (pairing_cb.autopair_attempts == 0))
957 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700958 BTIF_TRACE_DEBUG("%s() Attempting auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800959 pin_code.pin[0] = 0x30;
960 pin_code.pin[1] = 0x30;
961 pin_code.pin[2] = 0x30;
962 pin_code.pin[3] = 0x30;
963
964 pairing_cb.autopair_attempts++;
965 BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin);
966 return;
967 }
968 }
969 else if (check_cod(&bd_addr, COD_HID_KEYBOARD) ||
970 check_cod(&bd_addr, COD_HID_COMBO))
971 {
972 if(( btif_storage_is_fixed_pin_zeros_keyboard (&bd_addr) == TRUE) &&
973 (pairing_cb.autopair_attempts == 0))
974 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700975 BTIF_TRACE_DEBUG("%s() Attempting auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800976 pin_code.pin[0] = 0x30;
977 pin_code.pin[1] = 0x30;
978 pin_code.pin[2] = 0x30;
979 pin_code.pin[3] = 0x30;
980
981 pairing_cb.autopair_attempts++;
982 BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin);
983 return;
984 }
985 }
986 }
987 HAL_CBACK(bt_hal_cbacks, pin_request_cb,
Casper Bonde818d0f22015-05-21 11:08:45 +0200988 &bd_addr, &bd_name, cod, p_pin_req->min_16_digit);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800989}
990
991/*******************************************************************************
992**
993** Function btif_dm_ssp_cfm_req_evt
994**
995** Description Executes SSP confirm request event in btif context
996**
997** Returns void
998**
999*******************************************************************************/
1000static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ *p_ssp_cfm_req)
1001{
1002 bt_bdaddr_t bd_addr;
1003 bt_bdname_t bd_name;
1004 UINT32 cod;
1005 BOOLEAN is_incoming = !(pairing_cb.state == BT_BOND_STATE_BONDING);
Matthew Xie86f97ed2014-11-10 10:24:46 -08001006 int dev_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001007
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001008 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001009
1010 /* Remote properties update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08001011 if (!btif_get_device_type(p_ssp_cfm_req->bd_addr, &dev_type))
1012 {
1013 dev_type = BT_DEVICE_TYPE_BREDR;
1014 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001015 btif_update_remote_properties(p_ssp_cfm_req->bd_addr, p_ssp_cfm_req->bd_name,
Matthew Xie86f97ed2014-11-10 10:24:46 -08001016 p_ssp_cfm_req->dev_class, (tBT_DEVICE_TYPE) dev_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001017
1018 bdcpy(bd_addr.address, p_ssp_cfm_req->bd_addr);
1019 memcpy(bd_name.name, p_ssp_cfm_req->bd_name, BD_NAME_LEN);
1020
1021 /* Set the pairing_cb based on the local & remote authentication requirements */
1022 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
1023
1024 /* if just_works and bonding bit is not set treat this as temporary */
1025 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 -08001026 !(p_ssp_cfm_req->rmt_auth_req & BTM_AUTH_BONDS) &&
1027 !(check_cod((bt_bdaddr_t*)&p_ssp_cfm_req->bd_addr, COD_HID_POINTING)))
Andre Eisenbach89363762015-01-26 13:49:36 -08001028 pairing_cb.bond_type = BOND_TYPE_TEMPORARY;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001029 else
Andre Eisenbach89363762015-01-26 13:49:36 -08001030 pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001031
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001032 btm_set_bond_type_dev(p_ssp_cfm_req->bd_addr, pairing_cb.bond_type);
1033
The Android Open Source Project5738f832012-12-12 16:00:35 -08001034 pairing_cb.is_ssp = TRUE;
1035
1036 /* If JustWorks auto-accept */
1037 if (p_ssp_cfm_req->just_works)
1038 {
1039 /* Pairing consent for JustWorks needed if:
Andre Eisenbachaf753a22015-06-08 20:43:00 -07001040 * 1. Incoming (non-temporary) pairing is detected AND
The Android Open Source Project5738f832012-12-12 16:00:35 -08001041 * 2. local IO capabilities are DisplayYesNo AND
1042 * 3. remote IO capabiltiies are DisplayOnly or NoInputNoOutput;
1043 */
Andre Eisenbachaf753a22015-06-08 20:43:00 -07001044 if (is_incoming && pairing_cb.bond_type != BOND_TYPE_TEMPORARY &&
1045 ((p_ssp_cfm_req->loc_io_caps == HCI_IO_CAP_DISPLAY_YESNO) &&
1046 (p_ssp_cfm_req->rmt_io_caps == HCI_IO_CAP_DISPLAY_ONLY ||
1047 p_ssp_cfm_req->rmt_io_caps == HCI_IO_CAP_NO_IO)))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001048 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001049 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 -08001050 __FUNCTION__, p_ssp_cfm_req->loc_io_caps, p_ssp_cfm_req->rmt_io_caps);
1051 }
1052 else
1053 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001054 BTIF_TRACE_EVENT("%s: Auto-accept JustWorks pairing", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001055 btif_dm_ssp_reply(&bd_addr, BT_SSP_VARIANT_CONSENT, TRUE, 0);
1056 return;
1057 }
1058 }
1059
1060 cod = devclass2uint(p_ssp_cfm_req->dev_class);
1061
Chris Mantonf8027002015-03-12 09:22:48 -07001062 if (cod == 0) {
1063 LOG_DEBUG("%s cod is 0, set as unclassified", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001064 cod = COD_UNCLASSIFIED;
1065 }
1066
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001067 pairing_cb.sdp_attempts = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001068 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod,
1069 (p_ssp_cfm_req->just_works ? BT_SSP_VARIANT_CONSENT : BT_SSP_VARIANT_PASSKEY_CONFIRMATION),
1070 p_ssp_cfm_req->num_val);
1071}
1072
1073static void btif_dm_ssp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif)
1074{
1075 bt_bdaddr_t bd_addr;
1076 bt_bdname_t bd_name;
1077 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08001078 int dev_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001079
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001080 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001081
1082 /* Remote properties update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08001083 if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type))
1084 {
1085 dev_type = BT_DEVICE_TYPE_BREDR;
1086 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001087 btif_update_remote_properties(p_ssp_key_notif->bd_addr, p_ssp_key_notif->bd_name,
Matthew Xie86f97ed2014-11-10 10:24:46 -08001088 p_ssp_key_notif->dev_class, (tBT_DEVICE_TYPE) dev_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001089
1090 bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
1091 memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
1092
1093 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
1094 pairing_cb.is_ssp = TRUE;
1095 cod = devclass2uint(p_ssp_key_notif->dev_class);
1096
Chris Mantonf8027002015-03-12 09:22:48 -07001097 if (cod == 0) {
1098 LOG_DEBUG("%s cod is 0, set as unclassified", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001099 cod = COD_UNCLASSIFIED;
1100 }
1101
1102 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
1103 cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION,
1104 p_ssp_key_notif->passkey);
1105}
1106/*******************************************************************************
1107**
1108** Function btif_dm_auth_cmpl_evt
1109**
1110** Description Executes authentication complete event in btif context
1111**
1112** Returns void
1113**
1114*******************************************************************************/
1115static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
1116{
1117 /* Save link key, if not temporary */
1118 bt_bdaddr_t bd_addr;
1119 bt_status_t status = BT_STATUS_FAIL;
1120 bt_bond_state_t state = BT_BOND_STATE_NONE;
Priti Agherac0edf9f2014-06-26 11:23:51 -07001121 BOOLEAN skip_sdp = FALSE;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001122
Chaojing Sune2805532015-04-22 13:40:21 -07001123 BTIF_TRACE_DEBUG("%s: bond state=%d", __func__, pairing_cb.state);
1124
The Android Open Source Project5738f832012-12-12 16:00:35 -08001125 bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
1126 if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
1127 {
Srinu Jella21331c62015-06-16 19:38:45 +05301128 if ((p_auth_cmpl->key_type < HCI_LKEY_TYPE_DEBUG_COMB) ||
1129 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB) ||
1130 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_CHANGED_COMB) ||
1131 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB_P_256) ||
1132 pairing_cb.bond_type == BOND_TYPE_PERSISTENT)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001133 {
1134 bt_status_t ret;
Andre Eisenbach89363762015-01-26 13:49:36 -08001135 BTIF_TRACE_DEBUG("%s: Storing link key. key_type=0x%x, bond_type=%d",
1136 __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.bond_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001137 ret = btif_storage_add_bonded_device(&bd_addr,
1138 p_auth_cmpl->key, p_auth_cmpl->key_type,
1139 pairing_cb.pin_code_len);
1140 ASSERTC(ret == BT_STATUS_SUCCESS, "storing link key failed", ret);
1141 }
1142 else
1143 {
Andre Eisenbach89363762015-01-26 13:49:36 -08001144 BTIF_TRACE_DEBUG("%s: Temporary key. Not storing. key_type=0x%x, bond_type=%d",
1145 __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.bond_type);
1146 if(pairing_cb.bond_type == BOND_TYPE_TEMPORARY)
Hemant Guptab820aec2013-12-24 19:59:57 +05301147 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001148 BTIF_TRACE_DEBUG("%s: sending BT_BOND_STATE_NONE for Temp pairing",
Hemant Guptab820aec2013-12-24 19:59:57 +05301149 __FUNCTION__);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001150 btif_storage_remove_bonded_device(&bd_addr);
Hemant Guptab820aec2013-12-24 19:59:57 +05301151 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
1152 return;
1153 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001154 }
1155 }
Priti Agherac0edf9f2014-06-26 11:23:51 -07001156
1157 // Skip SDP for certain HID Devices
The Android Open Source Project5738f832012-12-12 16:00:35 -08001158 if (p_auth_cmpl->success)
1159 {
Andre Eisenbach12871662015-05-08 17:42:10 -07001160#if BLE_INCLUDED == TRUE
Chaojing Sune2805532015-04-22 13:40:21 -07001161 btif_storage_set_remote_addr_type(&bd_addr, p_auth_cmpl->addr_type);
Andre Eisenbach12871662015-05-08 17:42:10 -07001162#endif
Chaojing Sune2805532015-04-22 13:40:21 -07001163 btif_update_remote_properties(p_auth_cmpl->bd_addr,
1164 p_auth_cmpl->bd_name, NULL, p_auth_cmpl->dev_type);
Andre Eisenbach31a64002014-10-14 14:29:19 -07001165 pairing_cb.timeout_retries = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001166
Priti Agherac0edf9f2014-06-26 11:23:51 -07001167 if (check_sdp_bl(&bd_addr) && check_cod_hid(&bd_addr, COD_HID_MAJOR))
1168 {
Hemant Guptada33b462015-04-26 10:32:57 +05301169 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED);
Ganesh Ganapathi Battae17bf002013-02-15 17:52:29 -08001170
Hemant Guptada33b462015-04-26 10:32:57 +05301171 BTIF_TRACE_DEBUG("%s: HID Connection from "
1172 "blacklisted device, skipping sdp",__FUNCTION__);
Priti Agherac0edf9f2014-06-26 11:23:51 -07001173 bt_property_t prop;
Priti Agherac0edf9f2014-06-26 11:23:51 -07001174 bt_uuid_t uuid;
1175 char uuid_str[128] = UUID_HUMAN_INTERFACE_DEVICE;
Ganesh Ganapathi Battae17bf002013-02-15 17:52:29 -08001176
Priti Agherac0edf9f2014-06-26 11:23:51 -07001177 string_to_uuid(uuid_str, &uuid);
1178
1179 prop.type = BT_PROPERTY_UUIDS;
1180 prop.val = uuid.uu;
1181 prop.len = MAX_UUID_SIZE;
1182
Hemant Guptada33b462015-04-26 10:32:57 +05301183 /* Also write this to the NVRAM */
1184 status = btif_storage_set_remote_device_property(&bd_addr, &prop);
1185 ASSERTC(status == BT_STATUS_SUCCESS, "storing remote services failed", status);
Priti Agherac0edf9f2014-06-26 11:23:51 -07001186 /* Send the event to the BTIF */
1187 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1188 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1189 }
1190 else
1191 {
Hemant Guptada33b462015-04-26 10:32:57 +05301192 status = BT_STATUS_SUCCESS;
1193 state = BT_BOND_STATE_BONDED;
1194
Priti Agherac0edf9f2014-06-26 11:23:51 -07001195 /* Trigger SDP on the device */
1196 pairing_cb.sdp_attempts = 1;;
Andre Eisenbach12871662015-05-08 17:42:10 -07001197
1198#if BLE_INCLUDED == TRUE
Chaojing Sune2805532015-04-22 13:40:21 -07001199 /* If bonded due to cross-key, save the static address too*/
1200 if(pairing_cb.state == BT_BOND_STATE_BONDING &&
1201 (bdcmp(p_auth_cmpl->bd_addr, pairing_cb.bd_addr) != 0))
1202 {
1203 BTIF_TRACE_DEBUG("%s: bonding initiated due to cross key, adding static address",
1204 __func__);
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001205 bdcpy(pairing_cb.static_bdaddr.address, p_auth_cmpl->bd_addr);
Chaojing Sune2805532015-04-22 13:40:21 -07001206 }
Andre Eisenbach12871662015-05-08 17:42:10 -07001207#endif
Priti Agherac0edf9f2014-06-26 11:23:51 -07001208
1209 if(btif_dm_inquiry_in_progress)
1210 btif_dm_cancel_discovery();
1211
1212 btif_dm_get_remote_services(&bd_addr);
Chaojing Sune2805532015-04-22 13:40:21 -07001213 }
1214 // 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 -08001215 }
1216 else
1217 {
Chaojing Sune2805532015-04-22 13:40:21 -07001218 // Map the HCI fail reason to bt status
The Android Open Source Project5738f832012-12-12 16:00:35 -08001219 switch(p_auth_cmpl->fail_reason)
1220 {
1221 case HCI_ERR_PAGE_TIMEOUT:
Hemant Guptada33b462015-04-26 10:32:57 +05301222 if (interop_addr_match(INTEROP_AUTO_RETRY_PAIRING, &bd_addr)
Andre Eisenbach27c4e632015-07-06 15:43:15 -07001223 && pairing_cb.timeout_retries)
Andre Eisenbach31a64002014-10-14 14:29:19 -07001224 {
1225 BTIF_TRACE_WARNING("%s() - Pairing timeout; retrying (%d) ...", __FUNCTION__, pairing_cb.timeout_retries);
1226 --pairing_cb.timeout_retries;
1227 btif_dm_cb_create_bond (&bd_addr, BTA_TRANSPORT_UNKNOWN);
1228 return;
1229 }
1230 /* Fall-through */
The Android Open Source Project5738f832012-12-12 16:00:35 -08001231 case HCI_ERR_CONNECTION_TOUT:
1232 status = BT_STATUS_RMT_DEV_DOWN;
1233 break;
1234
Hemant Guptaaef7a672013-07-31 19:00:12 +05301235 case HCI_ERR_PAIRING_NOT_ALLOWED:
1236 status = BT_STATUS_AUTH_REJECTED;
1237 break;
1238
Hemant Guptab4801442014-01-07 18:11:15 +05301239 case HCI_ERR_LMP_RESPONSE_TIMEOUT:
1240 status = BT_STATUS_AUTH_FAILURE;
1241 break;
1242
The Android Open Source Project5738f832012-12-12 16:00:35 -08001243 /* map the auth failure codes, so we can retry pairing if necessary */
1244 case HCI_ERR_AUTH_FAILURE:
Hemant Gupta59a88ec2014-03-19 19:01:35 +05301245 case HCI_ERR_KEY_MISSING:
Zhihai Xua7ea8092013-11-27 14:10:53 +05301246 btif_storage_remove_bonded_device(&bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001247 case HCI_ERR_HOST_REJECT_SECURITY:
1248 case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE:
1249 case HCI_ERR_UNIT_KEY_USED:
1250 case HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED:
1251 case HCI_ERR_INSUFFCIENT_SECURITY:
Hemant Gupta87b7cce2013-11-28 13:07:10 +05301252 case HCI_ERR_PEER_USER:
1253 case HCI_ERR_UNSPECIFIED:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001254 BTIF_TRACE_DEBUG(" %s() Authentication fail reason %d",
Hemant Gupta87b7cce2013-11-28 13:07:10 +05301255 __FUNCTION__, p_auth_cmpl->fail_reason);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001256 if (pairing_cb.autopair_attempts == 1)
1257 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001258 BTIF_TRACE_DEBUG("%s(): Adding device to blacklist ", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001259
1260 /* Add the device to dynamic black list only if this device belongs to Audio/pointing dev class */
1261 if (check_cod(&bd_addr, COD_AV_HEADSETS) ||
1262 check_cod(&bd_addr, COD_AV_HANDSFREE) ||
1263 check_cod(&bd_addr, COD_AV_HEADPHONES) ||
1264 check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) ||
1265 check_cod(&bd_addr, COD_AV_HIFI_AUDIO) ||
1266 check_cod(&bd_addr, COD_HID_POINTING))
1267 {
1268 btif_storage_add_device_to_autopair_blacklist (&bd_addr);
1269 }
1270 pairing_cb.autopair_attempts++;
1271
1272 /* Create the Bond once again */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001273 BTIF_TRACE_DEBUG("%s() auto pair failed. Reinitiate Bond", __FUNCTION__);
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07001274 btif_dm_cb_create_bond (&bd_addr, BTA_TRANSPORT_UNKNOWN);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001275 return;
1276 }
1277 else
1278 {
1279 /* if autopair attempts are more than 1, or not attempted */
1280 status = BT_STATUS_AUTH_FAILURE;
1281 }
1282 break;
1283
1284 default:
1285 status = BT_STATUS_FAIL;
1286 }
Zhihai Xu8d2128d2013-12-13 16:09:21 +05301287 /* Special Handling for HID Devices */
1288 if (check_cod(&bd_addr, COD_HID_POINTING)) {
1289 /* Remove Device as bonded in nvram as authentication failed */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001290 BTIF_TRACE_DEBUG("%s(): removing hid pointing device from nvram", __FUNCTION__);
Zhihai Xu8d2128d2013-12-13 16:09:21 +05301291 btif_storage_remove_bonded_device(&bd_addr);
1292 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001293 bond_state_changed(status, &bd_addr, state);
1294 }
1295}
1296
1297/******************************************************************************
1298**
1299** Function btif_dm_search_devices_evt
1300**
1301** Description Executes search devices callback events in btif context
1302**
1303** Returns void
1304**
1305******************************************************************************/
1306static void btif_dm_search_devices_evt (UINT16 event, char *p_param)
1307{
1308 tBTA_DM_SEARCH *p_search_data;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001309 BTIF_TRACE_EVENT("%s event=%s", __FUNCTION__, dump_dm_search_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001310
1311 switch (event)
1312 {
1313 case BTA_DM_DISC_RES_EVT:
1314 {
1315 p_search_data = (tBTA_DM_SEARCH *)p_param;
1316 /* Remote name update */
1317 if (strlen((const char *) p_search_data->disc_res.bd_name))
1318 {
1319 bt_property_t properties[1];
1320 bt_bdaddr_t bdaddr;
1321 bt_status_t status;
1322
1323 properties[0].type = BT_PROPERTY_BDNAME;
1324 properties[0].val = p_search_data->disc_res.bd_name;
1325 properties[0].len = strlen((char *)p_search_data->disc_res.bd_name);
1326 bdcpy(bdaddr.address, p_search_data->disc_res.bd_addr);
1327
1328 status = btif_storage_set_remote_device_property(&bdaddr, &properties[0]);
1329 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device property", status);
1330 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1331 status, &bdaddr, 1, properties);
1332 }
1333 /* TODO: Services? */
1334 }
1335 break;
1336
1337 case BTA_DM_INQ_RES_EVT:
1338 {
1339 /* inquiry result */
1340 UINT32 cod;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001341 bt_bdname_t bdname;
1342 bt_bdaddr_t bdaddr;
1343 UINT8 remote_name_len;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001344 tBTA_SERVICE_MASK services = 0;
1345 bdstr_t bdstr;
1346
1347 p_search_data = (tBTA_DM_SEARCH *)p_param;
1348 bdcpy(bdaddr.address, p_search_data->inq_res.bd_addr);
1349
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07001350 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 -08001351#if (BLE_INCLUDED == TRUE)
1352 p_search_data->inq_res.device_type);
1353#else
1354 BT_DEVICE_TYPE_BREDR);
1355#endif
1356 bdname.name[0] = 0;
1357
1358 cod = devclass2uint (p_search_data->inq_res.dev_class);
1359
Chris Mantonf8027002015-03-12 09:22:48 -07001360 if (cod == 0) {
1361 LOG_DEBUG("%s cod is 0, set as unclassified", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001362 cod = COD_UNCLASSIFIED;
1363 }
1364
1365 if (!check_eir_remote_name(p_search_data, bdname.name, &remote_name_len))
1366 check_cached_remote_name(p_search_data, bdname.name, &remote_name_len);
1367
1368 /* Check EIR for remote name and services */
1369 if (p_search_data->inq_res.p_eir)
1370 {
1371 BTA_GetEirService(p_search_data->inq_res.p_eir, &services);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001372 BTIF_TRACE_DEBUG("%s()EIR BTA services = %08X", __FUNCTION__, (UINT32)services);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001373 /* TODO: Get the service list and check to see which uuids we got and send it back to the client. */
1374 }
1375
1376
1377 {
1378 bt_property_t properties[5];
1379 bt_device_type_t dev_type;
1380 uint32_t num_properties = 0;
1381 bt_status_t status;
Nitin Aroraac728402015-06-26 18:09:37 -07001382 int addr_type = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001383
1384 memset(properties, 0, sizeof(properties));
1385 /* BD_ADDR */
1386 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1387 BT_PROPERTY_BDADDR, sizeof(bdaddr), &bdaddr);
1388 num_properties++;
1389 /* BD_NAME */
1390 /* Don't send BDNAME if it is empty */
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001391 if (bdname.name[0])
1392 {
The Android Open Source Project5738f832012-12-12 16:00:35 -08001393 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1394 BT_PROPERTY_BDNAME,
1395 strlen((char *)bdname.name), &bdname);
1396 num_properties++;
1397 }
1398
1399 /* DEV_CLASS */
1400 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1401 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
1402 num_properties++;
1403 /* DEV_TYPE */
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001404#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001405 /* FixMe: Assumption is that bluetooth.h and BTE enums match */
Nitin Aroraac728402015-06-26 18:09:37 -07001406
1407 /* Verify if the device is dual mode in NVRAM */
1408 int stored_device_type = 0;
1409 if (btif_get_device_type(bdaddr.address, &stored_device_type) &&
1410 ((stored_device_type == BT_DEVICE_TYPE_BLE &&
1411 p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BREDR) ||
1412 (stored_device_type == BT_DEVICE_TYPE_BREDR &&
1413 p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BLE))) {
1414 dev_type = BT_DEVICE_TYPE_DUMO;
1415 } else {
1416 dev_type = p_search_data->inq_res.device_type;
1417 }
1418
1419 if (p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BLE)
1420 addr_type = p_search_data->inq_res.ble_addr_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001421#else
1422 dev_type = BT_DEVICE_TYPE_BREDR;
1423#endif
1424 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1425 BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
1426 num_properties++;
1427 /* RSSI */
1428 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1429 BT_PROPERTY_REMOTE_RSSI, sizeof(int8_t),
1430 &(p_search_data->inq_res.rssi));
1431 num_properties++;
1432
1433 status = btif_storage_add_remote_device(&bdaddr, num_properties, properties);
1434 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device (inquiry)", status);
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001435#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1436 status = btif_storage_set_remote_addr_type(&bdaddr, addr_type);
1437 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote addr type (inquiry)", status);
1438#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001439 /* Callback to notify upper layer of device */
1440 HAL_CBACK(bt_hal_cbacks, device_found_cb,
1441 num_properties, properties);
1442 }
1443 }
1444 break;
1445
1446 case BTA_DM_INQ_CMPL_EVT:
1447 {
Satya Calloji6e2d9db2014-07-08 16:18:58 -07001448#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1449 tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param;
1450 memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
1451 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL,
1452 bte_scan_filt_param_cfg_evt, 0);
1453#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001454 }
1455 break;
1456 case BTA_DM_DISC_CMPL_EVT:
1457 {
1458 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED);
1459 }
1460 break;
1461 case BTA_DM_SEARCH_CANCEL_CMPL_EVT:
1462 {
1463 /* if inquiry is not in progress and we get a cancel event, then
1464 * it means we are done with inquiry, but remote_name fetches are in
1465 * progress
1466 *
1467 * if inquiry is in progress, then we don't want to act on this cancel_cmpl_evt
1468 * but instead wait for the cancel_cmpl_evt via the Busy Level
1469 *
1470 */
1471 if (btif_dm_inquiry_in_progress == FALSE)
1472 {
Nitin Arora7b85efa2014-09-26 14:05:24 -07001473#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1474 tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param;
1475 memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
1476 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL,
1477 bte_scan_filt_param_cfg_evt, 0);
1478#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001479 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED);
1480 }
1481 }
1482 break;
1483 }
1484}
1485
1486/*******************************************************************************
1487**
1488** Function btif_dm_search_services_evt
1489**
1490** Description Executes search services event in btif context
1491**
1492** Returns void
1493**
1494*******************************************************************************/
1495static void btif_dm_search_services_evt(UINT16 event, char *p_param)
1496{
1497 tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param;
1498
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001499 BTIF_TRACE_EVENT("%s: event = %d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001500 switch (event)
1501 {
1502 case BTA_DM_DISC_RES_EVT:
1503 {
The Android Open Source Project5738f832012-12-12 16:00:35 -08001504 bt_property_t prop;
Bernhard Rosenkränzer104e3f22014-11-12 21:53:08 +01001505 uint32_t i = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001506 bt_bdaddr_t bd_addr;
1507 bt_status_t ret;
1508
1509 bdcpy(bd_addr.address, p_data->disc_res.bd_addr);
1510
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001511 BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001512 p_data->disc_res.result, p_data->disc_res.services);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001513 if ((p_data->disc_res.result != BTA_SUCCESS) &&
1514 (pairing_cb.state == BT_BOND_STATE_BONDING ) &&
1515 (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING))
1516 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001517 BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", __FUNCTION__);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001518 pairing_cb.sdp_attempts++;
1519 btif_dm_get_remote_services(&bd_addr);
1520 return;
1521 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001522 prop.type = BT_PROPERTY_UUIDS;
1523 prop.len = 0;
1524 if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0))
1525 {
1526 prop.val = p_data->disc_res.p_uuid_list;
1527 prop.len = p_data->disc_res.num_uuids * MAX_UUID_SIZE;
1528 for (i=0; i < p_data->disc_res.num_uuids; i++)
1529 {
1530 char temp[256];
Chris Manton8ff3fea2015-01-07 13:59:14 -08001531 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 -07001532 LOG_INFO("%s index:%d uuid:%s", __func__, i, temp);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001533 }
1534 }
1535
1536 /* onUuidChanged requires getBondedDevices to be populated.
1537 ** bond_state_changed needs to be sent prior to remote_device_property
1538 */
1539 if ((pairing_cb.state == BT_BOND_STATE_BONDING) &&
Chaojing Sune2805532015-04-22 13:40:21 -07001540 ((bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0) ||
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001541 (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0)) &&
Chaojing Sune2805532015-04-22 13:40:21 -07001542 pairing_cb.sdp_attempts > 0)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001543 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001544 BTIF_TRACE_DEBUG("%s Remote Service SDP done. Call bond_state_changed_cb BONDED",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001545 __FUNCTION__);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001546 pairing_cb.sdp_attempts = 0;
Chaojing Sune2805532015-04-22 13:40:21 -07001547
1548 // If bonding occured due to cross-key pairing, send bonding callback
1549 // for static address now
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001550 if (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0)
Chaojing Sune2805532015-04-22 13:40:21 -07001551 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
1552
The Android Open Source Project5738f832012-12-12 16:00:35 -08001553 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED);
1554 }
1555
Chaojing Sune2805532015-04-22 13:40:21 -07001556 if (p_data->disc_res.num_uuids != 0)
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001557 {
1558 /* Also write this to the NVRAM */
1559 ret = btif_storage_set_remote_device_property(&bd_addr, &prop);
1560 ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);
1561 /* Send the event to the BTIF */
1562 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1563 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1564 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001565 }
1566 break;
1567
1568 case BTA_DM_DISC_CMPL_EVT:
1569 /* fixme */
1570 break;
1571
Matthew Xie607e3b72013-08-15 19:30:48 -07001572#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001573 case BTA_DM_DISC_BLE_RES_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001574 BTIF_TRACE_DEBUG("%s:, services 0x%x)", __FUNCTION__,
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001575 p_data->disc_ble_res.service.uu.uuid16);
1576 bt_uuid_t uuid;
1577 int i = 0;
1578 int j = 15;
1579 if (p_data->disc_ble_res.service.uu.uuid16 == UUID_SERVCLASS_LE_HID)
1580 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001581 BTIF_TRACE_DEBUG("%s: Found HOGP UUID",__FUNCTION__);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001582 bt_property_t prop;
1583 bt_bdaddr_t bd_addr;
1584 char temp[256];
Zhihai Xud7ee77b2013-11-05 18:06:54 -08001585 bt_status_t ret;
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001586
1587 bta_gatt_convert_uuid16_to_uuid128(uuid.uu,p_data->disc_ble_res.service.uu.uuid16);
1588
1589 while(i < j )
1590 {
1591 unsigned char c = uuid.uu[j];
1592 uuid.uu[j] = uuid.uu[i];
1593 uuid.uu[i] = c;
1594 i++;
1595 j--;
1596 }
1597
Chris Manton8ff3fea2015-01-07 13:59:14 -08001598 uuid_to_string_legacy(&uuid, temp);
Chris Mantonf8027002015-03-12 09:22:48 -07001599 LOG_INFO("%s uuid:%s", __func__, temp);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001600
1601 bdcpy(bd_addr.address, p_data->disc_ble_res.bd_addr);
1602 prop.type = BT_PROPERTY_UUIDS;
1603 prop.val = uuid.uu;
1604 prop.len = MAX_UUID_SIZE;
1605
Zhihai Xud7ee77b2013-11-05 18:06:54 -08001606 /* Also write this to the NVRAM */
1607 ret = btif_storage_set_remote_device_property(&bd_addr, &prop);
1608 ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);
1609
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001610 /* Send the event to the BTIF */
1611 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1612 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1613
1614 }
1615 break;
Matthew Xie607e3b72013-08-15 19:30:48 -07001616#endif /* BLE_INCLUDED */
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001617
The Android Open Source Project5738f832012-12-12 16:00:35 -08001618 default:
1619 {
1620 ASSERTC(0, "unhandled search services event", event);
1621 }
1622 break;
1623 }
1624}
1625
1626/*******************************************************************************
1627**
1628** Function btif_dm_remote_service_record_evt
1629**
1630** Description Executes search service record event in btif context
1631**
1632** Returns void
1633**
1634*******************************************************************************/
1635static void btif_dm_remote_service_record_evt(UINT16 event, char *p_param)
1636{
1637 tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param;
1638
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001639 BTIF_TRACE_EVENT("%s: event = %d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001640 switch (event)
1641 {
1642 case BTA_DM_DISC_RES_EVT:
1643 {
1644 bt_service_record_t rec;
1645 bt_property_t prop;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001646 bt_bdaddr_t bd_addr;
1647
1648 memset(&rec, 0, sizeof(bt_service_record_t));
1649 bdcpy(bd_addr.address, p_data->disc_res.bd_addr);
1650
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001651 BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001652 p_data->disc_res.result, p_data->disc_res.services);
1653 prop.type = BT_PROPERTY_SERVICE_RECORD;
1654 prop.val = (void*)&rec;
1655 prop.len = sizeof(rec);
1656
1657 /* disc_res.result is overloaded with SCN. Cannot check result */
1658 p_data->disc_res.services &= ~BTA_USER_SERVICE_MASK;
1659 /* TODO: Get the UUID as well */
1660 rec.channel = p_data->disc_res.result - 3;
1661 /* TODO: Need to get the service name using p_raw_data */
1662 rec.name[0] = 0;
1663
1664 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1665 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1666 }
1667 break;
1668
1669 default:
1670 {
1671 ASSERTC(0, "unhandled remote service record event", event);
1672 }
1673 break;
1674 }
1675}
1676
1677/*******************************************************************************
1678**
1679** Function btif_dm_upstreams_cback
1680**
1681** Description Executes UPSTREAMS events in btif context
1682**
1683** Returns void
1684**
1685*******************************************************************************/
1686static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
1687{
The Android Open Source Project5738f832012-12-12 16:00:35 -08001688 tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)p_param;
1689 tBTA_SERVICE_MASK service_mask;
1690 uint32_t i;
1691 bt_bdaddr_t bd_addr;
1692
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001693 BTIF_TRACE_EVENT("btif_dm_upstreams_cback ev: %s", dump_dm_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001694
1695 switch (event)
1696 {
1697 case BTA_DM_ENABLE_EVT:
1698 {
1699 BD_NAME bdname;
1700 bt_status_t status;
1701 bt_property_t prop;
1702 prop.type = BT_PROPERTY_BDNAME;
1703 prop.len = BD_NAME_LEN;
1704 prop.val = (void*)bdname;
1705
1706 status = btif_storage_get_adapter_property(&prop);
Matthew Xie1e5109b2012-11-09 18:26:26 -08001707 if (status == BT_STATUS_SUCCESS)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001708 {
1709 /* A name exists in the storage. Make this the device name */
1710 BTA_DmSetDeviceName((char*)prop.val);
1711 }
Matthew Xie1e5109b2012-11-09 18:26:26 -08001712 else
1713 {
1714 /* Storage does not have a name yet.
1715 * Use the default name and write it to the chip
1716 */
1717 BTA_DmSetDeviceName(btif_get_default_local_name());
1718 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001719
Andre Eisenbacha015a832014-09-11 14:09:40 -07001720#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1721 /* Enable local privacy */
Andre Eisenbach3e0dc732014-10-24 09:55:34 -07001722 BTA_DmBleConfigLocalPrivacy(BLE_LOCAL_PRIVACY_ENABLED);
Andre Eisenbacha015a832014-09-11 14:09:40 -07001723#endif
1724
The Android Open Source Project5738f832012-12-12 16:00:35 -08001725 /* for each of the enabled services in the mask, trigger the profile
1726 * enable */
1727 service_mask = btif_get_enabled_services_mask();
1728 for (i=0; i <= BTA_MAX_SERVICE_ID; i++)
1729 {
1730 if (service_mask &
1731 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i)))
1732 {
1733 btif_in_execute_service_request(i, TRUE);
1734 }
1735 }
1736 /* clear control blocks */
1737 memset(&pairing_cb, 0, sizeof(btif_dm_pairing_cb_t));
Satya Calloji877123f2015-04-23 23:39:49 -07001738 pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001739
1740 /* This function will also trigger the adapter_properties_cb
1741 ** and bonded_devices_info_cb
1742 */
1743 btif_storage_load_bonded_devices();
1744
1745 btif_storage_load_autopair_device_list();
1746
Zach Johnson39110ec2014-10-06 13:15:00 -07001747 btif_enable_bluetooth_evt(p_data->enable.status);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001748 }
1749 break;
1750
1751 case BTA_DM_DISABLE_EVT:
1752 /* for each of the enabled services in the mask, trigger the profile
1753 * disable */
1754 service_mask = btif_get_enabled_services_mask();
1755 for (i=0; i <= BTA_MAX_SERVICE_ID; i++)
1756 {
1757 if (service_mask &
1758 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i)))
1759 {
1760 btif_in_execute_service_request(i, FALSE);
1761 }
1762 }
1763 btif_disable_bluetooth_evt();
1764 break;
1765
1766 case BTA_DM_PIN_REQ_EVT:
1767 btif_dm_pin_req_evt(&p_data->pin_req);
1768 break;
1769
1770 case BTA_DM_AUTH_CMPL_EVT:
1771 btif_dm_auth_cmpl_evt(&p_data->auth_cmpl);
1772 break;
1773
1774 case BTA_DM_BOND_CANCEL_CMPL_EVT:
1775 if (pairing_cb.state == BT_BOND_STATE_BONDING)
1776 {
1777 bdcpy(bd_addr.address, pairing_cb.bd_addr);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001778 btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001779 bond_state_changed(p_data->bond_cancel_cmpl.result, &bd_addr, BT_BOND_STATE_NONE);
Subramanian Srinivasan19bc89c2014-03-13 12:44:03 -07001780 btif_dm_remove_bond(&bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001781 }
1782 break;
1783
1784 case BTA_DM_SP_CFM_REQ_EVT:
1785 btif_dm_ssp_cfm_req_evt(&p_data->cfm_req);
1786 break;
1787 case BTA_DM_SP_KEY_NOTIF_EVT:
1788 btif_dm_ssp_key_notif_evt(&p_data->key_notif);
1789 break;
1790
1791 case BTA_DM_DEV_UNPAIRED_EVT:
1792 bdcpy(bd_addr.address, p_data->link_down.bd_addr);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001793 btm_set_bond_type_dev(p_data->link_down.bd_addr, BOND_TYPE_UNKNOWN);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001794
1795 /*special handling for HID devices */
1796 #if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -07001797 btif_hh_remove_device(bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001798 #endif
Hemant Gupta94c15ec2013-11-11 12:33:44 +05301799 #if (defined(BTA_HD_INCLUDED) && (BTA_HD_INCLUDED == TRUE))
1800 btif_hd_remove_device(bd_addr);
1801 #endif
1802 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1803 btif_storage_remove_ble_bonding_keys(&bd_addr);
1804 #endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001805 btif_storage_remove_bonded_device(&bd_addr);
1806 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
1807 break;
1808
1809 case BTA_DM_BUSY_LEVEL_EVT:
1810 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001811
1812 if (p_data->busy_level.level_flags & BTM_BL_INQUIRY_PAGING_MASK)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001813 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001814 if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_STARTED)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001815 {
1816 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb,
1817 BT_DISCOVERY_STARTED);
1818 btif_dm_inquiry_in_progress = TRUE;
1819 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001820 else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_CANCELLED)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001821 {
1822 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb,
1823 BT_DISCOVERY_STOPPED);
1824 btif_dm_inquiry_in_progress = FALSE;
1825 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001826 else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_COMPLETE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001827 {
1828 btif_dm_inquiry_in_progress = FALSE;
1829 }
1830 }
1831 }break;
1832
1833 case BTA_DM_LINK_UP_EVT:
1834 bdcpy(bd_addr.address, p_data->link_up.bd_addr);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001835 BTIF_TRACE_DEBUG("BTA_DM_LINK_UP_EVT. Sending BT_ACL_STATE_CONNECTED");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001836
1837 btif_update_remote_version_property(&bd_addr);
1838
The Android Open Source Project5738f832012-12-12 16:00:35 -08001839 HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS,
1840 &bd_addr, BT_ACL_STATE_CONNECTED);
1841 break;
1842
1843 case BTA_DM_LINK_DOWN_EVT:
1844 bdcpy(bd_addr.address, p_data->link_down.bd_addr);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001845 btm_set_bond_type_dev(p_data->link_down.bd_addr, BOND_TYPE_UNKNOWN);
Anubhav Gupta791692a2013-12-06 17:11:11 +05301846 btif_av_move_idle(bd_addr);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001847 BTIF_TRACE_DEBUG("BTA_DM_LINK_DOWN_EVT. Sending BT_ACL_STATE_DISCONNECTED");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001848 HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS,
1849 &bd_addr, BT_ACL_STATE_DISCONNECTED);
1850 break;
1851
1852 case BTA_DM_HW_ERROR_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001853 BTIF_TRACE_ERROR("Received H/W Error. ");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001854 /* Flush storage data */
1855 btif_config_flush();
1856 usleep(100000); /* 100milliseconds */
1857 /* Killing the process to force a restart as part of fault tolerance */
1858 kill(getpid(), SIGKILL);
1859 break;
1860
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001861#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1862 case BTA_DM_BLE_KEY_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001863 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 -08001864
1865 /* If this pairing is by-product of local initiated GATT client Read or Write,
1866 BTA would not have sent BTA_DM_BLE_SEC_REQ_EVT event and Bond state would not
1867 have setup properly. Setup pairing_cb and notify App about Bonding state now*/
1868 if (pairing_cb.state != BT_BOND_STATE_BONDING)
1869 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001870 BTIF_TRACE_DEBUG("Bond state not sent to App so far.Notify the app now");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001871 bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t*)p_data->ble_key.bd_addr,
1872 BT_BOND_STATE_BONDING);
1873 }
1874 else if (memcmp (pairing_cb.bd_addr, p_data->ble_key.bd_addr, BD_ADDR_LEN)!=0)
1875 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001876 BTIF_TRACE_ERROR("BD mismatch discard BLE key_type=%d ",p_data->ble_key.key_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001877 break;
1878 }
1879
1880 switch (p_data->ble_key.key_type)
1881 {
1882 case BTA_LE_KEY_PENC:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001883 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PENC");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001884 pairing_cb.ble.is_penc_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001885 pairing_cb.ble.penc_key = p_data->ble_key.p_key_value->penc_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001886 break;
1887
1888 case BTA_LE_KEY_PID:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001889 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PID");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001890 pairing_cb.ble.is_pid_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001891 pairing_cb.ble.pid_key = p_data->ble_key.p_key_value->pid_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001892 break;
1893
1894 case BTA_LE_KEY_PCSRK:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001895 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PCSRK");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001896 pairing_cb.ble.is_pcsrk_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001897 pairing_cb.ble.pcsrk_key = p_data->ble_key.p_key_value->pcsrk_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001898 break;
1899
1900 case BTA_LE_KEY_LENC:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001901 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LENC");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001902 pairing_cb.ble.is_lenc_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001903 pairing_cb.ble.lenc_key = p_data->ble_key.p_key_value->lenc_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001904 break;
1905
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001906 case BTA_LE_KEY_LCSRK:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001907 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LCSRK");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001908 pairing_cb.ble.is_lcsrk_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001909 pairing_cb.ble.lcsrk_key = p_data->ble_key.p_key_value->lcsrk_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001910 break;
1911
Satya Calloji444a8da2015-03-06 10:38:22 -08001912 case BTA_LE_KEY_LID:
1913 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LID");
1914 pairing_cb.ble.is_lidk_key_rcvd = TRUE;
1915 break;
1916
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001917 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001918 BTIF_TRACE_ERROR("unknown BLE key type (0x%02x)", p_data->ble_key.key_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001919 break;
1920 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001921 break;
1922 case BTA_DM_BLE_SEC_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001923 BTIF_TRACE_DEBUG("BTA_DM_BLE_SEC_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001924 btif_dm_ble_sec_req_evt(&p_data->ble_req);
1925 break;
1926 case BTA_DM_BLE_PASSKEY_NOTIF_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001927 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_NOTIF_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001928 btif_dm_ble_key_notif_evt(&p_data->key_notif);
1929 break;
1930 case BTA_DM_BLE_PASSKEY_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001931 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001932 btif_dm_ble_passkey_req_evt(&p_data->pin_req);
1933 break;
Satya Calloji444a8da2015-03-06 10:38:22 -08001934 case BTA_DM_BLE_NC_REQ_EVT:
1935 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_REQ_EVT. ");
1936 btif_dm_ble_key_nc_req_evt(&p_data->key_notif);
1937 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001938 case BTA_DM_BLE_OOB_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001939 BTIF_TRACE_DEBUG("BTA_DM_BLE_OOB_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001940 break;
1941 case BTA_DM_BLE_LOCAL_IR_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001942 BTIF_TRACE_DEBUG("BTA_DM_BLE_LOCAL_IR_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001943 ble_local_key_cb.is_id_keys_rcvd = TRUE;
Satya Calloji444a8da2015-03-06 10:38:22 -08001944 memcpy(&ble_local_key_cb.id_keys.irk[0],
1945 &p_data->ble_id_keys.irk[0], sizeof(BT_OCTET16));
1946 memcpy(&ble_local_key_cb.id_keys.ir[0],
1947 &p_data->ble_id_keys.ir[0], sizeof(BT_OCTET16));
1948 memcpy(&ble_local_key_cb.id_keys.dhk[0],
1949 &p_data->ble_id_keys.dhk[0], sizeof(BT_OCTET16));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001950 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.irk[0],
Satya Calloji7bd40382015-05-19 14:42:32 -07001951 BTIF_DM_LE_LOCAL_KEY_IRK,
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.ir[0],
Satya Calloji7bd40382015-05-19 14:42:32 -07001954 BTIF_DM_LE_LOCAL_KEY_IR,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001955 BT_OCTET16_LEN);
1956 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.dhk[0],
1957 BTIF_DM_LE_LOCAL_KEY_DHK,
1958 BT_OCTET16_LEN);
1959 break;
1960 case BTA_DM_BLE_LOCAL_ER_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001961 BTIF_TRACE_DEBUG("BTA_DM_BLE_LOCAL_ER_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001962 ble_local_key_cb.is_er_rcvd = TRUE;
1963 memcpy(&ble_local_key_cb.er[0], &p_data->ble_er[0], sizeof(BT_OCTET16));
1964 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.er[0],
1965 BTIF_DM_LE_LOCAL_KEY_ER,
1966 BT_OCTET16_LEN);
1967 break;
1968
1969 case BTA_DM_BLE_AUTH_CMPL_EVT:
Satya Calloji444a8da2015-03-06 10:38:22 -08001970 BTIF_TRACE_DEBUG("BTA_DM_BLE_AUTH_CMPL_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001971 btif_dm_ble_auth_cmpl_evt(&p_data->auth_cmpl);
1972 break;
Ganesh Ganapathi Batta9546abf2014-05-30 16:28:00 -07001973
1974 case BTA_DM_LE_FEATURES_READ:
1975 {
1976 tBTM_BLE_VSC_CB cmn_vsc_cb;
1977 bt_local_le_features_t local_le_features;
1978 char buf[512];
1979 bt_property_t prop;
1980 prop.type = BT_PROPERTY_LOCAL_LE_FEATURES;
1981 prop.val = (void*)buf;
1982 prop.len = sizeof(buf);
1983
1984 /* LE features are not stored in storage. Should be retrived from stack */
1985 BTM_BleGetVendorCapabilities(&cmn_vsc_cb);
1986 local_le_features.local_privacy_enabled = BTM_BleLocalPrivacyEnabled();
1987
1988 prop.len = sizeof (bt_local_le_features_t);
1989 if (cmn_vsc_cb.filter_support == 1)
1990 local_le_features.max_adv_filter_supported = cmn_vsc_cb.max_filter;
1991 else
1992 local_le_features.max_adv_filter_supported = 0;
1993 local_le_features.max_adv_instance = cmn_vsc_cb.adv_inst_max;
1994 local_le_features.max_irk_list_size = cmn_vsc_cb.max_irk_list_sz;
1995 local_le_features.rpa_offload_supported = cmn_vsc_cb.rpa_offloading;
Satya Callojiefaddcb2014-07-28 23:22:05 -07001996 local_le_features.activity_energy_info_supported = cmn_vsc_cb.energy_support;
Satya Callojif5387072015-02-09 17:40:52 -08001997 local_le_features.scan_result_storage_size = cmn_vsc_cb.tot_scan_results_strg;
1998 local_le_features.version_supported = cmn_vsc_cb.version_supported;
1999 local_le_features.total_trackable_advertisers =
2000 cmn_vsc_cb.total_trackable_advertisers;
Satya Calloji5725fc62015-03-31 13:24:32 -07002001
2002 local_le_features.extended_scan_support = cmn_vsc_cb.extended_scan_support > 0;
2003 local_le_features.debug_logging_supported = cmn_vsc_cb.debug_logging_supported > 0;
2004
Ganesh Ganapathi Batta9546abf2014-05-30 16:28:00 -07002005 memcpy(prop.val, &local_le_features, prop.len);
2006 HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, BT_STATUS_SUCCESS, 1, &prop);
2007 break;
2008 }
Satya Callojie5ba8842014-07-03 17:18:02 -07002009
2010 case BTA_DM_ENER_INFO_READ:
2011 {
2012 btif_activity_energy_info_cb_t *p_ener_data = (btif_activity_energy_info_cb_t*) p_param;
2013 bt_activity_energy_info energy_info;
2014 energy_info.status = p_ener_data->status;
2015 energy_info.ctrl_state = p_ener_data->ctrl_state;
2016 energy_info.rx_time = p_ener_data->rx_time;
2017 energy_info.tx_time = p_ener_data->tx_time;
2018 energy_info.idle_time = p_ener_data->idle_time;
2019 energy_info.energy_used = p_ener_data->energy_used;
2020 HAL_CBACK(bt_hal_cbacks, energy_info_cb, &energy_info);
2021 break;
2022 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002023#endif
2024
The Android Open Source Project5738f832012-12-12 16:00:35 -08002025 case BTA_DM_AUTHORIZE_EVT:
2026 case BTA_DM_SIG_STRENGTH_EVT:
2027 case BTA_DM_SP_RMT_OOB_EVT:
2028 case BTA_DM_SP_KEYPRESS_EVT:
2029 case BTA_DM_ROLE_CHG_EVT:
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002030
The Android Open Source Project5738f832012-12-12 16:00:35 -08002031 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002032 BTIF_TRACE_WARNING( "btif_dm_cback : unhandled event (%d)", event );
The Android Open Source Project5738f832012-12-12 16:00:35 -08002033 break;
2034 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002035
Andre Eisenbach8a057242015-04-29 22:27:15 -07002036 btif_dm_data_free(event, p_data);
2037}
The Android Open Source Project5738f832012-12-12 16:00:35 -08002038
2039/*******************************************************************************
2040**
2041** Function btif_dm_generic_evt
2042**
2043** Description Executes non-BTA upstream events in BTIF context
2044**
2045** Returns void
2046**
2047*******************************************************************************/
2048static void btif_dm_generic_evt(UINT16 event, char* p_param)
2049{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002050 BTIF_TRACE_EVENT("%s: event=%d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002051 switch(event)
2052 {
2053 case BTIF_DM_CB_DISCOVERY_STARTED:
2054 {
2055 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STARTED);
2056 }
2057 break;
2058
2059 case BTIF_DM_CB_CREATE_BOND:
2060 {
Andre Eisenbach31a64002014-10-14 14:29:19 -07002061 pairing_cb.timeout_retries = NUM_TIMEOUT_RETRIES;
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002062 btif_dm_create_bond_cb_t *create_bond_cb = (btif_dm_create_bond_cb_t*)p_param;
2063 btif_dm_cb_create_bond(&create_bond_cb->bdaddr, create_bond_cb->transport);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002064 }
2065 break;
2066
2067 case BTIF_DM_CB_REMOVE_BOND:
2068 {
2069 btif_dm_cb_remove_bond((bt_bdaddr_t *)p_param);
2070 }
2071 break;
2072
2073 case BTIF_DM_CB_HID_REMOTE_NAME:
2074 {
2075 btif_dm_cb_hid_remote_name((tBTM_REMOTE_DEV_NAME *)p_param);
2076 }
2077 break;
2078
2079 case BTIF_DM_CB_BOND_STATE_BONDING:
2080 {
2081 bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t *)p_param, BT_BOND_STATE_BONDING);
2082 }
2083 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002084 case BTIF_DM_CB_LE_TX_TEST:
2085 case BTIF_DM_CB_LE_RX_TEST:
2086 {
2087 uint8_t status;
2088 STREAM_TO_UINT8(status, p_param);
2089 HAL_CBACK(bt_hal_cbacks, le_test_mode_cb,
2090 (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, 0);
2091 }
2092 break;
2093 case BTIF_DM_CB_LE_TEST_END:
2094 {
2095 uint8_t status;
2096 uint16_t count = 0;
2097 STREAM_TO_UINT8(status, p_param);
2098 if (status == 0)
2099 STREAM_TO_UINT16(count, p_param);
2100 HAL_CBACK(bt_hal_cbacks, le_test_mode_cb,
2101 (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, count);
2102 }
2103 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002104 default:
2105 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002106 BTIF_TRACE_WARNING("%s : Unknown event 0x%x", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002107 }
2108 break;
2109 }
2110}
2111
2112/*******************************************************************************
2113**
2114** Function bte_dm_evt
2115**
2116** Description Switches context from BTE to BTIF for all DM events
2117**
2118** Returns void
2119**
2120*******************************************************************************/
2121
2122void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data)
2123{
The Android Open Source Project5738f832012-12-12 16:00:35 -08002124 /* switch context to btif task context (copy full union size for convenience) */
Andre Eisenbach8a057242015-04-29 22:27:15 -07002125 bt_status_t status = btif_transfer_context(btif_dm_upstreams_evt, (uint16_t)event,
2126 (void*)p_data, sizeof(tBTA_DM_SEC), btif_dm_data_copy);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002127
2128 /* catch any failed context transfers */
2129 ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status);
2130}
2131
2132/*******************************************************************************
2133**
2134** Function bte_search_devices_evt
2135**
2136** Description Switches context from BTE to BTIF for DM search events
2137**
2138** Returns void
2139**
2140*******************************************************************************/
2141static void bte_search_devices_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
2142{
2143 UINT16 param_len = 0;
2144
2145 if (p_data)
2146 param_len += sizeof(tBTA_DM_SEARCH);
2147 /* Allocate buffer to hold the pointers (deep copy). The pointers will point to the end of the tBTA_DM_SEARCH */
2148 switch (event)
2149 {
2150 case BTA_DM_INQ_RES_EVT:
2151 {
2152 if (p_data->inq_res.p_eir)
2153 param_len += HCI_EXT_INQ_RESPONSE_LEN;
2154 }
2155 break;
2156
2157 case BTA_DM_DISC_RES_EVT:
2158 {
2159 if (p_data->disc_res.raw_data_size && p_data->disc_res.p_raw_data)
2160 param_len += p_data->disc_res.raw_data_size;
2161 }
2162 break;
2163 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002164 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 -08002165
2166 /* if remote name is available in EIR, set teh flag so that stack doesnt trigger RNR */
2167 if (event == BTA_DM_INQ_RES_EVT)
2168 p_data->inq_res.remt_name_not_required = check_eir_remote_name(p_data, NULL, NULL);
2169
2170 btif_transfer_context (btif_dm_search_devices_evt , (UINT16) event, (void *)p_data, param_len,
2171 (param_len > sizeof(tBTA_DM_SEARCH)) ? search_devices_copy_cb : NULL);
2172}
2173
2174/*******************************************************************************
2175**
2176** Function bte_dm_search_services_evt
2177**
2178** Description Switches context from BTE to BTIF for DM search services
2179** event
2180**
2181** Returns void
2182**
2183*******************************************************************************/
2184static void bte_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
2185{
2186 UINT16 param_len = 0;
2187 if (p_data)
2188 param_len += sizeof(tBTA_DM_SEARCH);
2189 switch (event)
2190 {
2191 case BTA_DM_DISC_RES_EVT:
2192 {
2193 if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0)) {
2194 param_len += (p_data->disc_res.num_uuids * MAX_UUID_SIZE);
2195 }
2196 } break;
2197 }
2198 /* TODO: The only other member that needs a deep copy is the p_raw_data. But not sure
2199 * if raw_data is needed. */
2200 btif_transfer_context(btif_dm_search_services_evt, event, (char*)p_data, param_len,
2201 (param_len > sizeof(tBTA_DM_SEARCH)) ? search_services_copy_cb : NULL);
2202}
2203
2204/*******************************************************************************
2205**
2206** Function bte_dm_remote_service_record_evt
2207**
2208** Description Switches context from BTE to BTIF for DM search service
2209** record event
2210**
2211** Returns void
2212**
2213*******************************************************************************/
2214static void bte_dm_remote_service_record_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
2215{
2216 /* TODO: The only member that needs a deep copy is the p_raw_data. But not sure yet if this is needed. */
2217 btif_transfer_context(btif_dm_remote_service_record_evt, event, (char*)p_data, sizeof(tBTA_DM_SEARCH), NULL);
2218}
2219
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07002220#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Satya Callojie5ba8842014-07-03 17:18:02 -07002221/*******************************************************************************
2222**
2223** Function bta_energy_info_cb
2224**
2225** Description Switches context from BTE to BTIF for DM energy info event
2226**
2227** Returns void
2228**
2229*******************************************************************************/
2230static void bta_energy_info_cb(tBTA_DM_BLE_TX_TIME_MS tx_time, tBTA_DM_BLE_RX_TIME_MS rx_time,
2231 tBTA_DM_BLE_IDLE_TIME_MS idle_time,
2232 tBTA_DM_BLE_ENERGY_USED energy_used,
2233 tBTA_DM_CONTRL_STATE ctrl_state, tBTA_STATUS status)
2234{
2235 BTIF_TRACE_DEBUG("energy_info_cb-Status:%d,state=%d,tx_t=%ld, rx_t=%ld, idle_time=%ld,used=%ld",
2236 status, ctrl_state, tx_time, rx_time, idle_time, energy_used);
2237
2238 btif_activity_energy_info_cb_t btif_cb;
2239 btif_cb.status = status;
2240 btif_cb.ctrl_state = ctrl_state;
2241 btif_cb.tx_time = (uint64_t) tx_time;
2242 btif_cb.rx_time = (uint64_t) rx_time;
2243 btif_cb.idle_time =(uint64_t) idle_time;
2244 btif_cb.energy_used =(uint64_t) energy_used;
2245 btif_transfer_context(btif_dm_upstreams_evt, BTA_DM_ENER_INFO_READ,
2246 (char*) &btif_cb, sizeof(btif_activity_energy_info_cb_t), NULL);
2247}
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07002248#endif
Satya Callojie5ba8842014-07-03 17:18:02 -07002249
Satya Calloji6e2d9db2014-07-08 16:18:58 -07002250/*******************************************************************************
2251**
2252** Function bte_scan_filt_param_cfg_evt
2253**
2254** Description Scan filter param config event
2255**
2256** Returns void
2257**
2258*******************************************************************************/
2259static void bte_scan_filt_param_cfg_evt(UINT8 action_type,
2260 tBTA_DM_BLE_PF_AVBL_SPACE avbl_space,
2261 tBTA_DM_BLE_REF_VALUE ref_value, tBTA_STATUS status)
2262{
2263 /* This event occurs on calling BTA_DmBleCfgFilterCondition internally,
2264 ** and that is why there is no HAL callback
2265 */
2266 if(BTA_SUCCESS != status)
2267 {
2268 BTIF_TRACE_ERROR("%s, %d", __FUNCTION__, status);
2269 }
2270 else
2271 {
2272 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
2273 }
2274}
2275
The Android Open Source Project5738f832012-12-12 16:00:35 -08002276/*****************************************************************************
2277**
2278** btif api functions (no context switch)
2279**
2280*****************************************************************************/
2281
2282/*******************************************************************************
2283**
2284** Function btif_dm_start_discovery
2285**
2286** Description Start device discovery/inquiry
2287**
2288** Returns bt_status_t
2289**
2290*******************************************************************************/
2291bt_status_t btif_dm_start_discovery(void)
2292{
2293 tBTA_DM_INQ inq_params;
2294 tBTA_SERVICE_MASK services = 0;
Satya Calloji6e2d9db2014-07-08 16:18:58 -07002295 tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002296
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002297 BTIF_TRACE_EVENT("%s", __FUNCTION__);
Satya Calloji6e2d9db2014-07-08 16:18:58 -07002298
2299#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2300 memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
2301 /* Cleanup anything remaining on index 0 */
2302 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL,
2303 bte_scan_filt_param_cfg_evt, 0);
2304
2305 /* Add an allow-all filter on index 0*/
2306 adv_filt_param.dely_mode = IMMEDIATE_DELY_MODE;
2307 adv_filt_param.feat_seln = ALLOW_ALL_FILTER;
2308 adv_filt_param.filt_logic_type = BTA_DM_BLE_PF_FILT_LOGIC_OR;
2309 adv_filt_param.list_logic_type = BTA_DM_BLE_PF_LIST_LOGIC_OR;
2310 adv_filt_param.rssi_low_thres = LOWEST_RSSI_VALUE;
2311 adv_filt_param.rssi_high_thres = LOWEST_RSSI_VALUE;
2312 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_ADD, 0, &adv_filt_param, NULL,
2313 bte_scan_filt_param_cfg_evt, 0);
2314
The Android Open Source Project5738f832012-12-12 16:00:35 -08002315 /* TODO: Do we need to handle multiple inquiries at the same time? */
2316
2317 /* Set inquiry params and call API */
The Android Open Source Project5738f832012-12-12 16:00:35 -08002318 inq_params.mode = BTA_DM_GENERAL_INQUIRY|BTA_BLE_GENERAL_INQUIRY;
Matthew Xie7f3e4292013-09-30 12:44:10 -07002319#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
2320 inq_params.intl_duration[0]= BTIF_DM_INTERLEAVE_DURATION_BR_ONE;
2321 inq_params.intl_duration[1]= BTIF_DM_INTERLEAVE_DURATION_LE_ONE;
2322 inq_params.intl_duration[2]= BTIF_DM_INTERLEAVE_DURATION_BR_TWO;
2323 inq_params.intl_duration[3]= BTIF_DM_INTERLEAVE_DURATION_LE_TWO;
2324#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002325#else
2326 inq_params.mode = BTA_DM_GENERAL_INQUIRY;
2327#endif
2328 inq_params.duration = BTIF_DM_DEFAULT_INQ_MAX_DURATION;
2329
2330 inq_params.max_resps = BTIF_DM_DEFAULT_INQ_MAX_RESULTS;
2331 inq_params.report_dup = TRUE;
2332
2333 inq_params.filter_type = BTA_DM_INQ_CLR;
2334 /* TODO: Filter device by BDA needs to be implemented here */
2335
2336 /* Will be enabled to TRUE once inquiry busy level has been received */
2337 btif_dm_inquiry_in_progress = FALSE;
2338 /* find nearby devices */
2339 BTA_DmSearch(&inq_params, services, bte_search_devices_evt);
2340
2341 return BT_STATUS_SUCCESS;
2342}
2343
2344/*******************************************************************************
2345**
2346** Function btif_dm_cancel_discovery
2347**
2348** Description Cancels search
2349**
2350** Returns bt_status_t
2351**
2352*******************************************************************************/
2353bt_status_t btif_dm_cancel_discovery(void)
2354{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002355 BTIF_TRACE_EVENT("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002356 BTA_DmSearchCancel();
2357 return BT_STATUS_SUCCESS;
2358}
2359
2360/*******************************************************************************
2361**
2362** Function btif_dm_create_bond
2363**
2364** Description Initiate bonding with the specified device
2365**
2366** Returns bt_status_t
2367**
2368*******************************************************************************/
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002369bt_status_t btif_dm_create_bond(const bt_bdaddr_t *bd_addr, int transport)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002370{
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002371 btif_dm_create_bond_cb_t create_bond_cb;
2372 create_bond_cb.transport = transport;
2373 bdcpy(create_bond_cb.bdaddr.address, bd_addr->address);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002374
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002375 bdstr_t bdstr;
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002376 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 -08002377 if (pairing_cb.state != BT_BOND_STATE_NONE)
2378 return BT_STATUS_BUSY;
2379
2380 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_CREATE_BOND,
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002381 (char *)&create_bond_cb, sizeof(btif_dm_create_bond_cb_t), NULL);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002382
2383 return BT_STATUS_SUCCESS;
2384}
2385
2386/*******************************************************************************
2387**
2388** Function btif_dm_cancel_bond
2389**
2390** Description Initiate bonding with the specified device
2391**
2392** Returns bt_status_t
2393**
2394*******************************************************************************/
2395
2396bt_status_t btif_dm_cancel_bond(const bt_bdaddr_t *bd_addr)
2397{
2398 bdstr_t bdstr;
2399
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002400 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 -08002401
2402 /* TODO:
2403 ** 1. Restore scan modes
2404 ** 2. special handling for HID devices
2405 */
2406 if (pairing_cb.state == BT_BOND_STATE_BONDING)
2407 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002408
2409#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2410
2411 if (pairing_cb.is_ssp)
2412 {
2413 if (pairing_cb.is_le_only)
2414 {
2415 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT);
2416 }
2417 else
Hemant Guptae1468692013-11-14 16:21:29 +05302418 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002419 BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE);
Hemant Guptae1468692013-11-14 16:21:29 +05302420 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2421 btif_storage_remove_bonded_device((bt_bdaddr_t *)bd_addr);
2422 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002423 }
2424 else
2425 {
2426 if (pairing_cb.is_le_only)
2427 {
2428 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2429 }
2430 else
2431 {
2432 BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL);
2433 }
2434 /* Cancel bonding, in case it is in ACL connection setup state */
2435 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2436 }
2437
2438#else
The Android Open Source Project5738f832012-12-12 16:00:35 -08002439 if (pairing_cb.is_ssp)
2440 {
2441 BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE);
2442 }
2443 else
2444 {
2445 BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL);
2446 }
2447 /* Cancel bonding, in case it is in ACL connection setup state */
2448 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2449 btif_storage_remove_bonded_device((bt_bdaddr_t *)bd_addr);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002450#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002451 }
2452
2453 return BT_STATUS_SUCCESS;
2454}
2455
2456/*******************************************************************************
2457**
Hemant Guptada33b462015-04-26 10:32:57 +05302458** Function btif_dm_hh_open_success
2459**
2460** Description Checks if device is blacklisted, if yes takes appropriate action
2461**
2462** Returns none
2463**
2464*******************************************************************************/
2465
2466void btif_dm_hh_open_success(bt_bdaddr_t *bdaddr)
2467{
2468 if (pairing_cb.state == BT_BOND_STATE_BONDING &&
2469 bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0)
2470 {
2471 if (check_if_auth_bl(bdaddr)
2472 && check_cod_hid(bdaddr, COD_HID_MAJOR))
2473 {
2474 bt_status_t status;
2475 LINK_KEY link_key = {0};
2476 bond_state_changed(BT_STATUS_SUCCESS, bdaddr, BT_BOND_STATE_BONDED);
2477 BTIF_TRACE_DEBUG("%s: Device is blacklisted for authentication", __func__);
2478 bt_property_t prop;
2479 bt_uuid_t uuid;
2480 char uuid_str[128] = UUID_HUMAN_INTERFACE_DEVICE;
2481 string_to_uuid(uuid_str, &uuid);
2482 prop.type = BT_PROPERTY_UUIDS;
2483 prop.val = uuid.uu;
2484 prop.len = MAX_UUID_SIZE;
2485 // Also write this to the NVRAM
2486 status = btif_storage_set_remote_device_property(bdaddr, &prop);
2487 ASSERTC(status == BT_STATUS_SUCCESS, "storing remote services failed", status);
2488 // Store fake link for device as bonded in nvram,
2489 // otherwise on device reboot/bt off-on device will not be shown in paired list.
2490 btif_storage_add_bonded_device(bdaddr, link_key, HCI_LKEY_TYPE_UNAUTH_COMB, 0);
2491 // Send the event to the BTIF
2492 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
2493 BT_STATUS_SUCCESS, bdaddr, 1, &prop);
2494 }
2495 }
2496}
2497
2498/*******************************************************************************
2499**
Kim Schulza9eb25c2013-09-30 10:55:52 +02002500** Function btif_dm_hh_open_failed
2501**
2502** Description informs the upper layers if the HH have failed during bonding
2503**
2504** Returns none
2505**
2506*******************************************************************************/
2507
2508void btif_dm_hh_open_failed(bt_bdaddr_t *bdaddr)
2509{
2510 if (pairing_cb.state == BT_BOND_STATE_BONDING &&
2511 bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0)
2512 {
2513 bond_state_changed(BT_STATUS_FAIL, bdaddr, BT_BOND_STATE_NONE);
2514 }
2515}
2516
2517/*******************************************************************************
2518**
The Android Open Source Project5738f832012-12-12 16:00:35 -08002519** Function btif_dm_remove_bond
2520**
2521** Description Removes bonding with the specified device
2522**
2523** Returns bt_status_t
2524**
2525*******************************************************************************/
2526
2527bt_status_t btif_dm_remove_bond(const bt_bdaddr_t *bd_addr)
2528{
2529 bdstr_t bdstr;
2530
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002531 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 -08002532 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_REMOVE_BOND,
2533 (char *)bd_addr, sizeof(bt_bdaddr_t), NULL);
2534
2535 return BT_STATUS_SUCCESS;
2536}
2537
2538/*******************************************************************************
2539**
2540** Function btif_dm_pin_reply
2541**
2542** Description BT legacy pairing - PIN code reply
2543**
2544** Returns bt_status_t
2545**
2546*******************************************************************************/
2547
2548bt_status_t btif_dm_pin_reply( const bt_bdaddr_t *bd_addr, uint8_t accept,
2549 uint8_t pin_len, bt_pin_code_t *pin_code)
2550{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002551 BTIF_TRACE_EVENT("%s: accept=%d", __FUNCTION__, accept);
Hemant Gupta831423e2014-01-08 12:42:13 +05302552 if (pin_code == NULL)
2553 return BT_STATUS_FAIL;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002554#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002555
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002556 if (pairing_cb.is_le_only)
2557 {
2558 int i;
2559 UINT32 passkey = 0;
2560 int multi[] = {100000, 10000, 1000, 100, 10,1};
2561 BD_ADDR remote_bd_addr;
2562 bdcpy(remote_bd_addr, bd_addr->address);
2563 for (i = 0; i < 6; i++)
2564 {
2565 passkey += (multi[i] * (pin_code->pin[i] - '0'));
2566 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002567 BTIF_TRACE_DEBUG("btif_dm_pin_reply: passkey: %d", passkey);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002568 BTA_DmBlePasskeyReply(remote_bd_addr, accept, passkey);
2569
2570 }
2571 else
2572 {
2573 BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin);
2574 if (accept)
2575 pairing_cb.pin_code_len = pin_len;
2576 }
2577#else
The Android Open Source Project5738f832012-12-12 16:00:35 -08002578 BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin);
2579
2580 if (accept)
2581 pairing_cb.pin_code_len = pin_len;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002582#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002583 return BT_STATUS_SUCCESS;
2584}
2585
2586/*******************************************************************************
2587**
2588** Function btif_dm_ssp_reply
2589**
2590** Description BT SSP Reply - Just Works, Numeric Comparison & Passkey Entry
2591**
2592** Returns bt_status_t
2593**
2594*******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -08002595bt_status_t btif_dm_ssp_reply(const bt_bdaddr_t *bd_addr,
2596 bt_ssp_variant_t variant, uint8_t accept,
2597 uint32_t passkey)
2598{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002599 UNUSED(passkey);
2600
The Android Open Source Project5738f832012-12-12 16:00:35 -08002601 if (variant == BT_SSP_VARIANT_PASSKEY_ENTRY)
2602 {
2603 /* This is not implemented in the stack.
2604 * For devices with display, this is not needed
2605 */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002606 BTIF_TRACE_WARNING("%s: Not implemented", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002607 return BT_STATUS_FAIL;
2608 }
2609 /* BT_SSP_VARIANT_CONSENT & BT_SSP_VARIANT_PASSKEY_CONFIRMATION supported */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002610 BTIF_TRACE_EVENT("%s: accept=%d", __FUNCTION__, accept);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002611#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2612 if (pairing_cb.is_le_only)
2613 {
Satya Calloji7fb0da62015-01-29 20:40:17 -08002614 if(pairing_cb.is_le_nc)
2615 {
2616 BTA_DmBleConfirmReply((UINT8 *)bd_addr->address,accept);
2617 } else {
2618 if (accept)
2619 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_GRANTED);
2620 else
2621 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT);
2622 }
2623 } else {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002624 BTA_DmConfirm( (UINT8 *)bd_addr->address, accept);
Satya Calloji7fb0da62015-01-29 20:40:17 -08002625 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002626#else
2627 BTA_DmConfirm( (UINT8 *)bd_addr->address, accept);
2628#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002629 return BT_STATUS_SUCCESS;
2630}
2631
2632/*******************************************************************************
2633**
2634** Function btif_dm_get_adapter_property
2635**
2636** Description Queries the BTA for the adapter property
2637**
2638** Returns bt_status_t
2639**
2640*******************************************************************************/
2641bt_status_t btif_dm_get_adapter_property(bt_property_t *prop)
2642{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002643 BTIF_TRACE_EVENT("%s: type=0x%x", __FUNCTION__, prop->type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002644 switch (prop->type)
2645 {
2646 case BT_PROPERTY_BDNAME:
2647 {
2648 bt_bdname_t *bd_name = (bt_bdname_t*)prop->val;
VenkatRaghavan VijayaRaghavan4540f592015-02-05 04:40:47 -08002649 strncpy((char *)bd_name->name, (char *)btif_get_default_local_name(),
VenkatRaghavan VijayaRaghavan1d8e6b82015-02-05 22:20:39 -08002650 sizeof(bd_name->name) - 1);
2651 bd_name->name[sizeof(bd_name->name) - 1] = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002652 prop->len = strlen((char *)bd_name->name);
2653 }
2654 break;
2655
2656 case BT_PROPERTY_ADAPTER_SCAN_MODE:
2657 {
2658 /* if the storage does not have it. Most likely app never set it. Default is NONE */
2659 bt_scan_mode_t *mode = (bt_scan_mode_t*)prop->val;
2660 *mode = BT_SCAN_MODE_NONE;
2661 prop->len = sizeof(bt_scan_mode_t);
2662 }
2663 break;
2664
2665 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
2666 {
2667 uint32_t *tmt = (uint32_t*)prop->val;
2668 *tmt = 120; /* default to 120s, if not found in NV */
2669 prop->len = sizeof(uint32_t);
2670 }
2671 break;
2672
2673 default:
2674 prop->len = 0;
2675 return BT_STATUS_FAIL;
2676 }
2677 return BT_STATUS_SUCCESS;
2678}
2679
2680/*******************************************************************************
2681**
2682** Function btif_dm_get_remote_services
2683**
2684** Description Start SDP to get remote services
2685**
2686** Returns bt_status_t
2687**
2688*******************************************************************************/
2689bt_status_t btif_dm_get_remote_services(bt_bdaddr_t *remote_addr)
2690{
2691 bdstr_t bdstr;
2692
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002693 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 -08002694
2695 BTA_DmDiscover(remote_addr->address, BTA_ALL_SERVICE_MASK,
2696 bte_dm_search_services_evt, TRUE);
2697
2698 return BT_STATUS_SUCCESS;
2699}
2700
2701/*******************************************************************************
2702**
Nitin Arorab4365c52015-06-25 18:30:09 -07002703** Function btif_dm_get_remote_services_transport
2704**
2705** Description Start SDP to get remote services by transport
2706**
2707** Returns bt_status_t
2708**
2709*******************************************************************************/
2710bt_status_t btif_dm_get_remote_services_by_transport(bt_bdaddr_t *remote_addr, const int transport)
2711{
2712 BTIF_TRACE_EVENT("%s", __func__);
2713
2714 /* Set the mask extension */
2715 tBTA_SERVICE_MASK_EXT mask_ext;
2716 mask_ext.num_uuid = 0;
2717 mask_ext.p_uuid = NULL;
2718 mask_ext.srvc_mask = BTA_ALL_SERVICE_MASK;
2719
2720 BTA_DmDiscoverByTransport(remote_addr->address, &mask_ext,
2721 bte_dm_search_services_evt, TRUE, transport);
2722
2723 return BT_STATUS_SUCCESS;
2724}
2725
2726/*******************************************************************************
2727**
The Android Open Source Project5738f832012-12-12 16:00:35 -08002728** Function btif_dm_get_remote_service_record
2729**
2730** Description Start SDP to get remote service record
2731**
2732**
2733** Returns bt_status_t
2734*******************************************************************************/
2735bt_status_t btif_dm_get_remote_service_record(bt_bdaddr_t *remote_addr,
2736 bt_uuid_t *uuid)
2737{
2738 tSDP_UUID sdp_uuid;
2739 bdstr_t bdstr;
2740
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002741 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 -08002742
2743 sdp_uuid.len = MAX_UUID_SIZE;
2744 memcpy(sdp_uuid.uu.uuid128, uuid->uu, MAX_UUID_SIZE);
2745
2746 BTA_DmDiscoverUUID(remote_addr->address, &sdp_uuid,
2747 bte_dm_remote_service_record_evt, TRUE);
2748
2749 return BT_STATUS_SUCCESS;
2750}
2751
2752void btif_dm_execute_service_request(UINT16 event, char *p_param)
2753{
2754 BOOLEAN b_enable = FALSE;
2755 bt_status_t status;
2756 if (event == BTIF_DM_ENABLE_SERVICE)
2757 {
2758 b_enable = TRUE;
2759 }
2760 status = btif_in_execute_service_request(*((tBTA_SERVICE_ID*)p_param), b_enable);
2761 if (status == BT_STATUS_SUCCESS)
2762 {
2763 bt_property_t property;
2764 bt_uuid_t local_uuids[BT_MAX_NUM_UUIDS];
2765
2766 /* Now send the UUID_PROPERTY_CHANGED event to the upper layer */
2767 BTIF_STORAGE_FILL_PROPERTY(&property, BT_PROPERTY_UUIDS,
2768 sizeof(local_uuids), local_uuids);
2769 btif_storage_get_adapter_property(&property);
2770 HAL_CBACK(bt_hal_cbacks, adapter_properties_cb,
2771 BT_STATUS_SUCCESS, 1, &property);
2772 }
2773 return;
2774}
2775
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002776void btif_dm_proc_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, tBTA_OOB_DATA *p_oob_data,
2777 tBTA_AUTH_REQ *p_auth_req, BOOLEAN is_orig)
2778{
2779 UINT8 yes_no_bit = BTA_AUTH_SP_YES & *p_auth_req;
2780 /* if local initiated:
2781 ** 1. set DD + MITM
2782 ** if remote initiated:
2783 ** 1. Copy over the auth_req from peer's io_rsp
2784 ** 2. Set the MITM if peer has it set or if peer has DisplayYesNo (iPhone)
2785 ** as a fallback set MITM+GB if peer had MITM set
2786 */
2787 UNUSED (bd_addr);
2788 UNUSED (p_io_cap);
2789 UNUSED (p_oob_data);
2790
2791
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002792 BTIF_TRACE_DEBUG("+%s: p_auth_req=%d", __FUNCTION__, *p_auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002793 if(pairing_cb.is_local_initiated)
2794 {
2795 /* if initing/responding to a dedicated bonding, use dedicate bonding bit */
2796 *p_auth_req = BTA_AUTH_DD_BOND | BTA_AUTH_SP_YES;
2797 }
2798 else if (!is_orig)
2799 {
2800 /* peer initiated paring. They probably know what they want.
2801 ** Copy the mitm from peer device.
2802 */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002803 BTIF_TRACE_DEBUG("%s: setting p_auth_req to peer's: %d",
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002804 __FUNCTION__, pairing_cb.auth_req);
2805 *p_auth_req = (pairing_cb.auth_req & BTA_AUTH_BONDS);
2806
2807 /* copy over the MITM bit as well. In addition if the peer has DisplayYesNo, force MITM */
2808 if ((yes_no_bit) || (pairing_cb.io_cap & BTM_IO_CAP_IO) )
2809 *p_auth_req |= BTA_AUTH_SP_YES;
2810 }
2811 else if (yes_no_bit)
2812 {
2813 /* set the general bonding bit for stored device */
2814 *p_auth_req = BTA_AUTH_GEN_BOND | yes_no_bit;
2815 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002816 BTIF_TRACE_DEBUG("-%s: p_auth_req=%d", __FUNCTION__, *p_auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002817}
2818
2819void btif_dm_proc_io_rsp(BD_ADDR bd_addr, tBTA_IO_CAP io_cap,
2820 tBTA_OOB_DATA oob_data, tBTA_AUTH_REQ auth_req)
2821{
2822 UNUSED (bd_addr);
2823 UNUSED (oob_data);
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002824
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002825 if(auth_req & BTA_AUTH_BONDS)
2826 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002827 BTIF_TRACE_DEBUG("%s auth_req:%d", __FUNCTION__, auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002828 pairing_cb.auth_req = auth_req;
2829 pairing_cb.io_cap = io_cap;
2830 }
2831}
2832
The Android Open Source Project5738f832012-12-12 16:00:35 -08002833#if (BTM_OOB_INCLUDED == TRUE)
2834void btif_dm_set_oob_for_io_req(tBTA_OOB_DATA *p_oob_data)
2835{
2836 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2837 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
2838 {
2839 *p_oob_data = FALSE;
2840 }
2841 else
2842 {
2843 *p_oob_data = TRUE;
2844 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002845 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 -08002846}
2847#endif /* BTM_OOB_INCLUDED */
2848
2849#ifdef BTIF_DM_OOB_TEST
2850void btif_dm_load_local_oob(void)
2851{
Nick Kralevichd70b7a82013-01-31 14:40:15 -08002852 char prop_oob[PROPERTY_VALUE_MAX];
The Android Open Source Project5738f832012-12-12 16:00:35 -08002853 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002854 BTIF_TRACE_DEBUG("btif_dm_load_local_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002855 if (prop_oob[0] != '3')
2856 {
2857#if (BTM_OOB_INCLUDED == TRUE)
2858 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2859 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
2860 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002861 BTIF_TRACE_DEBUG("btif_dm_load_local_oob: read OOB, call BTA_DmLocalOob()");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002862 BTA_DmLocalOob();
2863 }
2864#else
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002865 BTIF_TRACE_ERROR("BTM_OOB_INCLUDED is FALSE!!(btif_dm_load_local_oob)");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002866#endif
2867 }
2868}
2869
2870void btif_dm_proc_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r)
2871{
2872 FILE *fp;
2873 char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
2874 char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
2875 char *path = NULL;
Nick Kralevichd70b7a82013-01-31 14:40:15 -08002876 char prop_oob[PROPERTY_VALUE_MAX];
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002877 BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob: valid=%d", valid);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002878 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2879 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 &&
2880 valid)
2881 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002882 BTIF_TRACE_DEBUG("save local OOB data in memory");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002883 memcpy(oob_cb.sp_c, c, BT_OCTET16_LEN);
2884 memcpy(oob_cb.sp_r, r, BT_OCTET16_LEN);
2885 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002886 BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002887 if (prop_oob[0] == '1')
2888 path = path_a;
2889 else if (prop_oob[0] == '2')
2890 path = path_b;
2891 if (path)
2892 {
2893 fp = fopen(path, "wb+");
2894 if (fp == NULL)
2895 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002896 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 -08002897 }
2898 else
2899 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002900 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 -08002901 fwrite (c , 1 , BT_OCTET16_LEN , fp );
2902 fwrite (r , 1 , BT_OCTET16_LEN , fp );
2903 fclose(fp);
2904 }
2905 }
2906 }
2907}
2908BOOLEAN btif_dm_proc_rmt_oob(BD_ADDR bd_addr, BT_OCTET16 p_c, BT_OCTET16 p_r)
2909{
2910 char t[128];
2911 FILE *fp;
2912 char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
2913 char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
2914 char *path = NULL;
Nick Kralevichd70b7a82013-01-31 14:40:15 -08002915 char prop_oob[PROPERTY_VALUE_MAX];
The Android Open Source Project5738f832012-12-12 16:00:35 -08002916 BOOLEAN result = FALSE;
2917 bt_bdaddr_t bt_bd_addr;
2918 bdcpy(oob_cb.oob_bdaddr, bd_addr);
2919 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002920 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002921 if (prop_oob[0] == '1')
2922 path = path_b;
2923 else if (prop_oob[0] == '2')
2924 path = path_a;
2925 if (path)
2926 {
2927 fp = fopen(path, "rb");
2928 if (fp == NULL)
2929 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002930 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 -08002931 return FALSE;
2932 }
2933 else
2934 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002935 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob: read OOB data from %s",path);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002936 fread (p_c , 1 , BT_OCTET16_LEN , fp );
2937 fread (p_r , 1 , BT_OCTET16_LEN , fp );
2938 fclose(fp);
2939 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002940 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: TRUE");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002941 sprintf(t, "%02x:%02x:%02x:%02x:%02x:%02x",
2942 oob_cb.oob_bdaddr[0], oob_cb.oob_bdaddr[1], oob_cb.oob_bdaddr[2],
2943 oob_cb.oob_bdaddr[3], oob_cb.oob_bdaddr[4], oob_cb.oob_bdaddr[5]);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002944 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: peer_bdaddr = %s", t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002945 sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
2946 p_c[0], p_c[1], p_c[2], p_c[3], p_c[4], p_c[5], p_c[6], p_c[7],
2947 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 -07002948 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: c = %s",t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002949 sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
2950 p_r[0], p_r[1], p_r[2], p_r[3], p_r[4], p_r[5], p_r[6], p_r[7],
2951 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 -07002952 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: r = %s",t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002953 bdcpy(bt_bd_addr.address, bd_addr);
2954 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_BOND_STATE_BONDING,
2955 (char *)&bt_bd_addr, sizeof(bt_bdaddr_t), NULL);
2956 result = TRUE;
2957 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002958 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob result=%d",result);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002959 return result;
2960}
2961#endif /* BTIF_DM_OOB_TEST */
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002962#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2963
2964static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif)
2965{
2966 bt_bdaddr_t bd_addr;
2967 bt_bdname_t bd_name;
2968 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08002969 int dev_type;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002970
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002971 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002972
2973 /* Remote name update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08002974 if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type))
2975 {
2976 dev_type = BT_DEVICE_TYPE_BLE;
2977 }
2978 btif_dm_update_ble_remote_properties(p_ssp_key_notif->bd_addr , p_ssp_key_notif->bd_name,
2979 (tBT_DEVICE_TYPE) dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002980 bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
2981 memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
2982
2983 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
2984 pairing_cb.is_ssp = FALSE;
2985 cod = COD_UNCLASSIFIED;
2986
2987 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
2988 cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION,
2989 p_ssp_key_notif->passkey);
2990}
2991
2992/*******************************************************************************
2993**
2994** Function btif_dm_ble_auth_cmpl_evt
2995**
2996** Description Executes authentication complete event in btif context
2997**
2998** Returns void
2999**
3000*******************************************************************************/
3001static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
3002{
3003 /* Save link key, if not temporary */
3004 bt_bdaddr_t bd_addr;
3005 bt_status_t status = BT_STATUS_FAIL;
3006 bt_bond_state_t state = BT_BOND_STATE_NONE;
3007
3008 bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
3009 if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
3010 {
3011 /* store keys */
3012 }
3013 if (p_auth_cmpl->success)
3014 {
3015 status = BT_STATUS_SUCCESS;
3016 state = BT_BOND_STATE_BONDED;
Satya Calloji7cb76b42015-05-07 09:45:00 -07003017 int addr_type;
3018 bt_bdaddr_t bdaddr;
3019 bdcpy(bdaddr.address, p_auth_cmpl->bd_addr);
3020 if (btif_storage_get_remote_addr_type(&bdaddr, &addr_type) != BT_STATUS_SUCCESS)
3021 btif_storage_set_remote_addr_type(&bdaddr, p_auth_cmpl->addr_type);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07003022
3023 /* Test for temporary bonding */
3024 if (btm_get_bond_type_dev(p_auth_cmpl->bd_addr) == BOND_TYPE_TEMPORARY) {
3025 BTIF_TRACE_DEBUG("%s: sending BT_BOND_STATE_NONE for Temp pairing",
3026 __func__);
3027 btif_storage_remove_bonded_device(&bdaddr);
3028 state = BT_BOND_STATE_NONE;
3029 } else {
3030 btif_dm_save_ble_bonding_keys();
3031 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003032 BTA_GATTC_Refresh(bd_addr.address);
Nitin Arorab4365c52015-06-25 18:30:09 -07003033 btif_dm_get_remote_services_by_transport(&bd_addr, BTA_GATT_TRANSPORT_LE);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003034 }
3035 else
3036 {
3037 /*Map the HCI fail reason to bt status */
3038 switch (p_auth_cmpl->fail_reason)
3039 {
Priti Aghera156c52b2014-07-09 14:58:19 -07003040 case BTA_DM_AUTH_SMP_PAIR_AUTH_FAIL:
3041 case BTA_DM_AUTH_SMP_CONFIRM_VALUE_FAIL:
3042 btif_dm_remove_ble_bonding_keys();
3043 status = BT_STATUS_AUTH_FAILURE;
3044 break;
3045 case BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT:
3046 status = BT_STATUS_AUTH_REJECTED;
3047 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003048 default:
Andre Eisenbachca22ac42013-02-13 17:02:11 +09003049 btif_dm_remove_ble_bonding_keys();
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003050 status = BT_STATUS_FAIL;
3051 break;
3052 }
3053 }
3054 bond_state_changed(status, &bd_addr, state);
3055}
3056
3057
3058
3059void btif_dm_load_ble_local_keys(void)
3060{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003061 memset(&ble_local_key_cb, 0, sizeof(btif_dm_local_key_cb_t));
3062
3063 if (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_ER,(char*)&ble_local_key_cb.er[0],
3064 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)
3065 {
3066 ble_local_key_cb.is_er_rcvd = TRUE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003067 BTIF_TRACE_DEBUG("%s BLE ER key loaded",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003068 }
3069
3070 if ((btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IR,(char*)&ble_local_key_cb.id_keys.ir[0],
3071 BT_OCTET16_LEN)== BT_STATUS_SUCCESS )&&
3072 (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IRK, (char*)&ble_local_key_cb.id_keys.irk[0],
3073 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)&&
3074 (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_DHK,(char*)&ble_local_key_cb.id_keys.dhk[0],
3075 BT_OCTET16_LEN)== BT_STATUS_SUCCESS))
3076 {
3077 ble_local_key_cb.is_id_keys_rcvd = TRUE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003078 BTIF_TRACE_DEBUG("%s BLE ID keys loaded",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003079 }
3080
3081}
3082void btif_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
3083 tBTA_BLE_LOCAL_ID_KEYS *p_id_keys)
3084{
3085 if (ble_local_key_cb.is_er_rcvd )
3086 {
3087 memcpy(&er[0], &ble_local_key_cb.er[0], sizeof(BT_OCTET16));
3088 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ER;
3089 }
3090
3091 if (ble_local_key_cb.is_id_keys_rcvd)
3092 {
3093 memcpy(&p_id_keys->ir[0], &ble_local_key_cb.id_keys.ir[0], sizeof(BT_OCTET16));
3094 memcpy(&p_id_keys->irk[0], &ble_local_key_cb.id_keys.irk[0], sizeof(BT_OCTET16));
3095 memcpy(&p_id_keys->dhk[0], &ble_local_key_cb.id_keys.dhk[0], sizeof(BT_OCTET16));
3096 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID;
3097 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003098 BTIF_TRACE_DEBUG("%s *p_key_mask=0x%02x",__FUNCTION__, *p_key_mask);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003099}
3100
3101void btif_dm_save_ble_bonding_keys(void)
3102{
3103
3104 bt_bdaddr_t bd_addr;
3105
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003106 BTIF_TRACE_DEBUG("%s",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003107
3108 bdcpy(bd_addr.address, pairing_cb.bd_addr);
3109
3110 if (pairing_cb.ble.is_penc_key_rcvd)
3111 {
3112 btif_storage_add_ble_bonding_key(&bd_addr,
3113 (char *) &pairing_cb.ble.penc_key,
3114 BTIF_DM_LE_KEY_PENC,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003115 sizeof(tBTM_LE_PENC_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003116 }
3117
3118 if (pairing_cb.ble.is_pid_key_rcvd)
3119 {
3120 btif_storage_add_ble_bonding_key(&bd_addr,
Andre Eisenbach5e808462014-10-21 12:37:53 -07003121 (char *) &pairing_cb.ble.pid_key,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003122 BTIF_DM_LE_KEY_PID,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003123 sizeof(tBTM_LE_PID_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003124 }
3125
3126
3127 if (pairing_cb.ble.is_pcsrk_key_rcvd)
3128 {
3129 btif_storage_add_ble_bonding_key(&bd_addr,
3130 (char *) &pairing_cb.ble.pcsrk_key,
3131 BTIF_DM_LE_KEY_PCSRK,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003132 sizeof(tBTM_LE_PCSRK_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003133 }
3134
3135
3136 if (pairing_cb.ble.is_lenc_key_rcvd)
3137 {
3138 btif_storage_add_ble_bonding_key(&bd_addr,
3139 (char *) &pairing_cb.ble.lenc_key,
3140 BTIF_DM_LE_KEY_LENC,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003141 sizeof(tBTM_LE_LENC_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003142 }
3143
3144 if (pairing_cb.ble.is_lcsrk_key_rcvd)
3145 {
3146 btif_storage_add_ble_bonding_key(&bd_addr,
3147 (char *) &pairing_cb.ble.lcsrk_key,
3148 BTIF_DM_LE_KEY_LCSRK,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003149 sizeof(tBTM_LE_LCSRK_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003150 }
3151
Satya Calloji444a8da2015-03-06 10:38:22 -08003152 if (pairing_cb.ble.is_lidk_key_rcvd)
3153 {
3154 btif_storage_add_ble_bonding_key(&bd_addr,
3155 NULL,
3156 BTIF_DM_LE_KEY_LID,
3157 0);
3158 }
3159
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003160}
3161
3162
3163void btif_dm_remove_ble_bonding_keys(void)
3164{
3165 bt_bdaddr_t bd_addr;
3166
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003167 BTIF_TRACE_DEBUG("%s",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003168
3169 bdcpy(bd_addr.address, pairing_cb.bd_addr);
3170 btif_storage_remove_ble_bonding_keys(&bd_addr);
3171}
3172
3173
3174/*******************************************************************************
3175**
3176** Function btif_dm_ble_sec_req_evt
3177**
3178** Description Eprocess security request event in btif context
3179**
3180** Returns void
3181**
3182*******************************************************************************/
3183void btif_dm_ble_sec_req_evt(tBTA_DM_BLE_SEC_REQ *p_ble_req)
3184{
3185 bt_bdaddr_t bd_addr;
3186 bt_bdname_t bd_name;
3187 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08003188 int dev_type;
3189
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003190 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003191
3192 if (pairing_cb.state == BT_BOND_STATE_BONDING)
3193 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003194 BTIF_TRACE_DEBUG("%s Discard security request", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003195 return;
3196 }
3197
3198 /* Remote name update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08003199 if (!btif_get_device_type(p_ble_req->bd_addr, &dev_type))
3200 {
3201 dev_type = BT_DEVICE_TYPE_BLE;
3202 }
3203 btif_dm_update_ble_remote_properties(p_ble_req->bd_addr, p_ble_req->bd_name,
3204 (tBT_DEVICE_TYPE) dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003205
3206 bdcpy(bd_addr.address, p_ble_req->bd_addr);
3207 memcpy(bd_name.name, p_ble_req->bd_name, BD_NAME_LEN);
3208
3209 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
3210
Andre Eisenbach89363762015-01-26 13:49:36 -08003211 pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003212 pairing_cb.is_le_only = TRUE;
Satya Calloji7fb0da62015-01-29 20:40:17 -08003213 pairing_cb.is_le_nc = FALSE;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003214 pairing_cb.is_ssp = TRUE;
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07003215 btm_set_bond_type_dev(p_ble_req->bd_addr, pairing_cb.bond_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003216
3217 cod = COD_UNCLASSIFIED;
3218
3219 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod,
3220 BT_SSP_VARIANT_CONSENT, 0);
3221}
3222
3223
3224
3225/*******************************************************************************
3226**
3227** Function btif_dm_ble_passkey_req_evt
3228**
3229** Description Executes pin request event in btif context
3230**
3231** Returns void
3232**
3233*******************************************************************************/
3234static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
3235{
3236 bt_bdaddr_t bd_addr;
3237 bt_bdname_t bd_name;
3238 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08003239 int dev_type;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003240
3241 /* Remote name update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08003242 if (!btif_get_device_type(p_pin_req->bd_addr, &dev_type))
3243 {
3244 dev_type = BT_DEVICE_TYPE_BLE;
3245 }
3246 btif_dm_update_ble_remote_properties(p_pin_req->bd_addr,p_pin_req->bd_name,
3247 (tBT_DEVICE_TYPE) dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003248
3249 bdcpy(bd_addr.address, p_pin_req->bd_addr);
3250 memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN);
3251
3252 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
3253 pairing_cb.is_le_only = TRUE;
3254
3255 cod = COD_UNCLASSIFIED;
3256
3257 HAL_CBACK(bt_hal_cbacks, pin_request_cb,
Casper Bonde818d0f22015-05-21 11:08:45 +02003258 &bd_addr, &bd_name, cod, FALSE);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003259}
Satya Calloji444a8da2015-03-06 10:38:22 -08003260static void btif_dm_ble_key_nc_req_evt(tBTA_DM_SP_KEY_NOTIF *p_notif_req)
3261{
3262 /* TODO implement key notification for numeric comparison */
3263 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003264
Satya Calloji444a8da2015-03-06 10:38:22 -08003265 /* Remote name update */
3266 btif_update_remote_properties(p_notif_req->bd_addr , p_notif_req->bd_name,
3267 NULL, BT_DEVICE_TYPE_BLE);
3268
3269 bt_bdaddr_t bd_addr;
3270 bdcpy(bd_addr.address, p_notif_req->bd_addr);
3271
3272 bt_bdname_t bd_name;
3273 memcpy(bd_name.name, p_notif_req->bd_name, BD_NAME_LEN);
3274
3275 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
3276 pairing_cb.is_ssp = FALSE;
Satya Calloji7fb0da62015-01-29 20:40:17 -08003277 pairing_cb.is_le_only = TRUE;
3278 pairing_cb.is_le_nc = TRUE;
Satya Calloji444a8da2015-03-06 10:38:22 -08003279
3280 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
3281 COD_UNCLASSIFIED, BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
3282 p_notif_req->passkey);
3283}
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003284
3285void btif_dm_update_ble_remote_properties( BD_ADDR bd_addr, BD_NAME bd_name,
3286 tBT_DEVICE_TYPE dev_type)
3287{
3288 btif_update_remote_properties(bd_addr,bd_name,NULL,dev_type);
3289}
3290
3291static void btif_dm_ble_tx_test_cback(void *p)
3292{
3293 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TX_TEST,
3294 (char *)p, 1, NULL);
3295}
3296
3297static void btif_dm_ble_rx_test_cback(void *p)
3298{
3299 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_RX_TEST,
3300 (char *)p, 1, NULL);
3301}
3302
3303static void btif_dm_ble_test_end_cback(void *p)
3304{
3305 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TEST_END,
3306 (char *)p, 3, NULL);
3307}
3308/*******************************************************************************
3309**
3310** Function btif_le_test_mode
3311**
3312** Description Sends a HCI BLE Test command to the Controller
3313**
3314** Returns BT_STATUS_SUCCESS on success
3315**
3316*******************************************************************************/
3317bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t len)
3318{
3319 switch (opcode) {
3320 case HCI_BLE_TRANSMITTER_TEST:
3321 if (len != 3) return BT_STATUS_PARM_INVALID;
3322 BTM_BleTransmitterTest(buf[0],buf[1],buf[2], btif_dm_ble_tx_test_cback);
3323 break;
3324 case HCI_BLE_RECEIVER_TEST:
3325 if (len != 1) return BT_STATUS_PARM_INVALID;
3326 BTM_BleReceiverTest(buf[0], btif_dm_ble_rx_test_cback);
3327 break;
3328 case HCI_BLE_TEST_END:
3329 BTM_BleTestEnd((tBTM_CMPL_CB*) btif_dm_ble_test_end_cback);
3330 break;
3331 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003332 BTIF_TRACE_ERROR("%s: Unknown LE Test Mode Command 0x%x", __FUNCTION__, opcode);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003333 return BT_STATUS_UNSUPPORTED;
3334 }
3335 return BT_STATUS_SUCCESS;
3336}
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003337#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08003338
3339void btif_dm_on_disable()
3340{
3341 /* cancel any pending pairing requests */
3342 if (pairing_cb.state == BT_BOND_STATE_BONDING)
3343 {
3344 bt_bdaddr_t bd_addr;
3345
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003346 BTIF_TRACE_DEBUG("%s: Cancel pending pairing request", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003347 bdcpy(bd_addr.address, pairing_cb.bd_addr);
3348 btif_dm_cancel_bond(&bd_addr);
3349 }
3350}
Matthew Xie1e5109b2012-11-09 18:26:26 -08003351
Satya Callojie5ba8842014-07-03 17:18:02 -07003352/*******************************************************************************
3353**
3354** Function btif_dm_read_energy_info
3355**
3356** Description Reads the energy info from controller
3357**
3358** Returns void
3359**
3360*******************************************************************************/
3361void btif_dm_read_energy_info()
3362{
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07003363#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Satya Callojie5ba8842014-07-03 17:18:02 -07003364 BTA_DmBleGetEnergyInfo(bta_energy_info_cb);
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07003365#endif
Satya Callojie5ba8842014-07-03 17:18:02 -07003366}
3367
Matthew Xie1e5109b2012-11-09 18:26:26 -08003368static char* btif_get_default_local_name() {
3369 if (btif_default_local_name[0] == '\0')
3370 {
3371 int max_len = sizeof(btif_default_local_name) - 1;
3372 if (BTM_DEF_LOCAL_NAME[0] != '\0')
3373 {
3374 strncpy(btif_default_local_name, BTM_DEF_LOCAL_NAME, max_len);
3375 }
3376 else
3377 {
3378 char prop_model[PROPERTY_VALUE_MAX];
3379 property_get(PROPERTY_PRODUCT_MODEL, prop_model, "");
3380 strncpy(btif_default_local_name, prop_model, max_len);
3381 }
3382 btif_default_local_name[max_len] = '\0';
3383 }
3384 return btif_default_local_name;
3385}