blob: 649f2ba607a896f8979ad84a44cbfa4448856622 [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 {
Srinu Jellabf691e82014-11-10 18:30:26 +0530946 if (bdcmp(pairing_cb.bd_addr, bd_addr.address))
947 {
948 /* Pin code from different device reject it as we dont support more than 1 pairing */
949 BTIF_TRACE_DEBUG("%s()rejecting pairing request", __FUNCTION__);
950 BTA_DmPinReply( (UINT8*)bd_addr.address, FALSE, 0, NULL);
951 return;
952 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800953 if (check_cod(&bd_addr, COD_AV_HEADSETS) ||
954 check_cod(&bd_addr, COD_AV_HANDSFREE) ||
955 check_cod(&bd_addr, COD_AV_HEADPHONES) ||
956 check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) ||
957 check_cod(&bd_addr, COD_AV_HIFI_AUDIO) ||
958 check_cod(&bd_addr, COD_HID_POINTING))
959 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700960 BTIF_TRACE_DEBUG("%s()cod matches for auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800961 /* Check if this device can be auto paired */
962 if ((btif_storage_is_device_autopair_blacklisted(&bd_addr) == FALSE) &&
963 (pairing_cb.autopair_attempts == 0))
964 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700965 BTIF_TRACE_DEBUG("%s() Attempting auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800966 pin_code.pin[0] = 0x30;
967 pin_code.pin[1] = 0x30;
968 pin_code.pin[2] = 0x30;
969 pin_code.pin[3] = 0x30;
970
971 pairing_cb.autopair_attempts++;
972 BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin);
973 return;
974 }
975 }
976 else if (check_cod(&bd_addr, COD_HID_KEYBOARD) ||
977 check_cod(&bd_addr, COD_HID_COMBO))
978 {
979 if(( btif_storage_is_fixed_pin_zeros_keyboard (&bd_addr) == TRUE) &&
980 (pairing_cb.autopair_attempts == 0))
981 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700982 BTIF_TRACE_DEBUG("%s() Attempting auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800983 pin_code.pin[0] = 0x30;
984 pin_code.pin[1] = 0x30;
985 pin_code.pin[2] = 0x30;
986 pin_code.pin[3] = 0x30;
987
988 pairing_cb.autopair_attempts++;
989 BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin);
990 return;
991 }
992 }
993 }
994 HAL_CBACK(bt_hal_cbacks, pin_request_cb,
Casper Bonde818d0f22015-05-21 11:08:45 +0200995 &bd_addr, &bd_name, cod, p_pin_req->min_16_digit);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800996}
997
998/*******************************************************************************
999**
1000** Function btif_dm_ssp_cfm_req_evt
1001**
1002** Description Executes SSP confirm request event in btif context
1003**
1004** Returns void
1005**
1006*******************************************************************************/
1007static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ *p_ssp_cfm_req)
1008{
1009 bt_bdaddr_t bd_addr;
1010 bt_bdname_t bd_name;
1011 UINT32 cod;
1012 BOOLEAN is_incoming = !(pairing_cb.state == BT_BOND_STATE_BONDING);
Matthew Xie86f97ed2014-11-10 10:24:46 -08001013 int dev_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001014
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001015 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001016
1017 /* Remote properties update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08001018 if (!btif_get_device_type(p_ssp_cfm_req->bd_addr, &dev_type))
1019 {
1020 dev_type = BT_DEVICE_TYPE_BREDR;
1021 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001022 btif_update_remote_properties(p_ssp_cfm_req->bd_addr, p_ssp_cfm_req->bd_name,
Matthew Xie86f97ed2014-11-10 10:24:46 -08001023 p_ssp_cfm_req->dev_class, (tBT_DEVICE_TYPE) dev_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001024
1025 bdcpy(bd_addr.address, p_ssp_cfm_req->bd_addr);
1026 memcpy(bd_name.name, p_ssp_cfm_req->bd_name, BD_NAME_LEN);
1027
1028 /* Set the pairing_cb based on the local & remote authentication requirements */
1029 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
1030
1031 /* if just_works and bonding bit is not set treat this as temporary */
1032 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 -08001033 !(p_ssp_cfm_req->rmt_auth_req & BTM_AUTH_BONDS) &&
1034 !(check_cod((bt_bdaddr_t*)&p_ssp_cfm_req->bd_addr, COD_HID_POINTING)))
Andre Eisenbach89363762015-01-26 13:49:36 -08001035 pairing_cb.bond_type = BOND_TYPE_TEMPORARY;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001036 else
Andre Eisenbach89363762015-01-26 13:49:36 -08001037 pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001038
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001039 btm_set_bond_type_dev(p_ssp_cfm_req->bd_addr, pairing_cb.bond_type);
1040
The Android Open Source Project5738f832012-12-12 16:00:35 -08001041 pairing_cb.is_ssp = TRUE;
1042
1043 /* If JustWorks auto-accept */
1044 if (p_ssp_cfm_req->just_works)
1045 {
1046 /* Pairing consent for JustWorks needed if:
Andre Eisenbachaf753a22015-06-08 20:43:00 -07001047 * 1. Incoming (non-temporary) pairing is detected AND
The Android Open Source Project5738f832012-12-12 16:00:35 -08001048 * 2. local IO capabilities are DisplayYesNo AND
1049 * 3. remote IO capabiltiies are DisplayOnly or NoInputNoOutput;
1050 */
Andre Eisenbachaf753a22015-06-08 20:43:00 -07001051 if (is_incoming && pairing_cb.bond_type != BOND_TYPE_TEMPORARY &&
1052 ((p_ssp_cfm_req->loc_io_caps == HCI_IO_CAP_DISPLAY_YESNO) &&
1053 (p_ssp_cfm_req->rmt_io_caps == HCI_IO_CAP_DISPLAY_ONLY ||
1054 p_ssp_cfm_req->rmt_io_caps == HCI_IO_CAP_NO_IO)))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001055 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001056 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 -08001057 __FUNCTION__, p_ssp_cfm_req->loc_io_caps, p_ssp_cfm_req->rmt_io_caps);
1058 }
1059 else
1060 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001061 BTIF_TRACE_EVENT("%s: Auto-accept JustWorks pairing", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001062 btif_dm_ssp_reply(&bd_addr, BT_SSP_VARIANT_CONSENT, TRUE, 0);
1063 return;
1064 }
1065 }
1066
1067 cod = devclass2uint(p_ssp_cfm_req->dev_class);
1068
Chris Mantonf8027002015-03-12 09:22:48 -07001069 if (cod == 0) {
1070 LOG_DEBUG("%s cod is 0, set as unclassified", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001071 cod = COD_UNCLASSIFIED;
1072 }
1073
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001074 pairing_cb.sdp_attempts = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001075 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod,
1076 (p_ssp_cfm_req->just_works ? BT_SSP_VARIANT_CONSENT : BT_SSP_VARIANT_PASSKEY_CONFIRMATION),
1077 p_ssp_cfm_req->num_val);
1078}
1079
1080static void btif_dm_ssp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif)
1081{
1082 bt_bdaddr_t bd_addr;
1083 bt_bdname_t bd_name;
1084 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08001085 int dev_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001086
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001087 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001088
1089 /* Remote properties update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08001090 if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type))
1091 {
1092 dev_type = BT_DEVICE_TYPE_BREDR;
1093 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001094 btif_update_remote_properties(p_ssp_key_notif->bd_addr, p_ssp_key_notif->bd_name,
Matthew Xie86f97ed2014-11-10 10:24:46 -08001095 p_ssp_key_notif->dev_class, (tBT_DEVICE_TYPE) dev_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001096
1097 bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
1098 memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
1099
1100 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
1101 pairing_cb.is_ssp = TRUE;
1102 cod = devclass2uint(p_ssp_key_notif->dev_class);
1103
Chris Mantonf8027002015-03-12 09:22:48 -07001104 if (cod == 0) {
1105 LOG_DEBUG("%s cod is 0, set as unclassified", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001106 cod = COD_UNCLASSIFIED;
1107 }
1108
1109 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
1110 cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION,
1111 p_ssp_key_notif->passkey);
1112}
1113/*******************************************************************************
1114**
1115** Function btif_dm_auth_cmpl_evt
1116**
1117** Description Executes authentication complete event in btif context
1118**
1119** Returns void
1120**
1121*******************************************************************************/
1122static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
1123{
1124 /* Save link key, if not temporary */
1125 bt_bdaddr_t bd_addr;
1126 bt_status_t status = BT_STATUS_FAIL;
1127 bt_bond_state_t state = BT_BOND_STATE_NONE;
Priti Agherac0edf9f2014-06-26 11:23:51 -07001128 BOOLEAN skip_sdp = FALSE;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001129
Chaojing Sune2805532015-04-22 13:40:21 -07001130 BTIF_TRACE_DEBUG("%s: bond state=%d", __func__, pairing_cb.state);
1131
The Android Open Source Project5738f832012-12-12 16:00:35 -08001132 bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
1133 if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
1134 {
Srinu Jella21331c62015-06-16 19:38:45 +05301135 if ((p_auth_cmpl->key_type < HCI_LKEY_TYPE_DEBUG_COMB) ||
1136 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB) ||
1137 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_CHANGED_COMB) ||
1138 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB_P_256) ||
1139 pairing_cb.bond_type == BOND_TYPE_PERSISTENT)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001140 {
1141 bt_status_t ret;
Andre Eisenbach89363762015-01-26 13:49:36 -08001142 BTIF_TRACE_DEBUG("%s: Storing link key. key_type=0x%x, bond_type=%d",
1143 __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.bond_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001144 ret = btif_storage_add_bonded_device(&bd_addr,
1145 p_auth_cmpl->key, p_auth_cmpl->key_type,
1146 pairing_cb.pin_code_len);
1147 ASSERTC(ret == BT_STATUS_SUCCESS, "storing link key failed", ret);
1148 }
1149 else
1150 {
Andre Eisenbach89363762015-01-26 13:49:36 -08001151 BTIF_TRACE_DEBUG("%s: Temporary key. Not storing. key_type=0x%x, bond_type=%d",
1152 __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.bond_type);
1153 if(pairing_cb.bond_type == BOND_TYPE_TEMPORARY)
Hemant Guptab820aec2013-12-24 19:59:57 +05301154 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001155 BTIF_TRACE_DEBUG("%s: sending BT_BOND_STATE_NONE for Temp pairing",
Hemant Guptab820aec2013-12-24 19:59:57 +05301156 __FUNCTION__);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001157 btif_storage_remove_bonded_device(&bd_addr);
Hemant Guptab820aec2013-12-24 19:59:57 +05301158 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
1159 return;
1160 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001161 }
1162 }
Priti Agherac0edf9f2014-06-26 11:23:51 -07001163
1164 // Skip SDP for certain HID Devices
The Android Open Source Project5738f832012-12-12 16:00:35 -08001165 if (p_auth_cmpl->success)
1166 {
Andre Eisenbach12871662015-05-08 17:42:10 -07001167#if BLE_INCLUDED == TRUE
Chaojing Sune2805532015-04-22 13:40:21 -07001168 btif_storage_set_remote_addr_type(&bd_addr, p_auth_cmpl->addr_type);
Andre Eisenbach12871662015-05-08 17:42:10 -07001169#endif
Chaojing Sune2805532015-04-22 13:40:21 -07001170 btif_update_remote_properties(p_auth_cmpl->bd_addr,
1171 p_auth_cmpl->bd_name, NULL, p_auth_cmpl->dev_type);
Andre Eisenbach31a64002014-10-14 14:29:19 -07001172 pairing_cb.timeout_retries = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001173
Priti Agherac0edf9f2014-06-26 11:23:51 -07001174 if (check_sdp_bl(&bd_addr) && check_cod_hid(&bd_addr, COD_HID_MAJOR))
1175 {
Hemant Guptada33b462015-04-26 10:32:57 +05301176 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED);
Ganesh Ganapathi Battae17bf002013-02-15 17:52:29 -08001177
Hemant Guptada33b462015-04-26 10:32:57 +05301178 BTIF_TRACE_DEBUG("%s: HID Connection from "
1179 "blacklisted device, skipping sdp",__FUNCTION__);
Priti Agherac0edf9f2014-06-26 11:23:51 -07001180 bt_property_t prop;
Priti Agherac0edf9f2014-06-26 11:23:51 -07001181 bt_uuid_t uuid;
1182 char uuid_str[128] = UUID_HUMAN_INTERFACE_DEVICE;
Ganesh Ganapathi Battae17bf002013-02-15 17:52:29 -08001183
Priti Agherac0edf9f2014-06-26 11:23:51 -07001184 string_to_uuid(uuid_str, &uuid);
1185
1186 prop.type = BT_PROPERTY_UUIDS;
1187 prop.val = uuid.uu;
1188 prop.len = MAX_UUID_SIZE;
1189
Hemant Guptada33b462015-04-26 10:32:57 +05301190 /* Also write this to the NVRAM */
1191 status = btif_storage_set_remote_device_property(&bd_addr, &prop);
1192 ASSERTC(status == BT_STATUS_SUCCESS, "storing remote services failed", status);
Priti Agherac0edf9f2014-06-26 11:23:51 -07001193 /* Send the event to the BTIF */
1194 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1195 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1196 }
1197 else
1198 {
Hemant Guptada33b462015-04-26 10:32:57 +05301199 status = BT_STATUS_SUCCESS;
1200 state = BT_BOND_STATE_BONDED;
1201
Priti Agherac0edf9f2014-06-26 11:23:51 -07001202 /* Trigger SDP on the device */
1203 pairing_cb.sdp_attempts = 1;;
Andre Eisenbach12871662015-05-08 17:42:10 -07001204
1205#if BLE_INCLUDED == TRUE
Chaojing Sune2805532015-04-22 13:40:21 -07001206 /* If bonded due to cross-key, save the static address too*/
1207 if(pairing_cb.state == BT_BOND_STATE_BONDING &&
1208 (bdcmp(p_auth_cmpl->bd_addr, pairing_cb.bd_addr) != 0))
1209 {
1210 BTIF_TRACE_DEBUG("%s: bonding initiated due to cross key, adding static address",
1211 __func__);
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001212 bdcpy(pairing_cb.static_bdaddr.address, p_auth_cmpl->bd_addr);
Chaojing Sune2805532015-04-22 13:40:21 -07001213 }
Andre Eisenbach12871662015-05-08 17:42:10 -07001214#endif
Priti Agherac0edf9f2014-06-26 11:23:51 -07001215
1216 if(btif_dm_inquiry_in_progress)
1217 btif_dm_cancel_discovery();
1218
1219 btif_dm_get_remote_services(&bd_addr);
Chaojing Sune2805532015-04-22 13:40:21 -07001220 }
1221 // 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 -08001222 }
1223 else
1224 {
Chaojing Sune2805532015-04-22 13:40:21 -07001225 // Map the HCI fail reason to bt status
The Android Open Source Project5738f832012-12-12 16:00:35 -08001226 switch(p_auth_cmpl->fail_reason)
1227 {
1228 case HCI_ERR_PAGE_TIMEOUT:
Hemant Guptada33b462015-04-26 10:32:57 +05301229 if (interop_addr_match(INTEROP_AUTO_RETRY_PAIRING, &bd_addr)
Andre Eisenbach27c4e632015-07-06 15:43:15 -07001230 && pairing_cb.timeout_retries)
Andre Eisenbach31a64002014-10-14 14:29:19 -07001231 {
1232 BTIF_TRACE_WARNING("%s() - Pairing timeout; retrying (%d) ...", __FUNCTION__, pairing_cb.timeout_retries);
1233 --pairing_cb.timeout_retries;
1234 btif_dm_cb_create_bond (&bd_addr, BTA_TRANSPORT_UNKNOWN);
1235 return;
1236 }
1237 /* Fall-through */
The Android Open Source Project5738f832012-12-12 16:00:35 -08001238 case HCI_ERR_CONNECTION_TOUT:
1239 status = BT_STATUS_RMT_DEV_DOWN;
1240 break;
1241
Hemant Guptaaef7a672013-07-31 19:00:12 +05301242 case HCI_ERR_PAIRING_NOT_ALLOWED:
1243 status = BT_STATUS_AUTH_REJECTED;
1244 break;
1245
Hemant Guptab4801442014-01-07 18:11:15 +05301246 case HCI_ERR_LMP_RESPONSE_TIMEOUT:
1247 status = BT_STATUS_AUTH_FAILURE;
1248 break;
1249
The Android Open Source Project5738f832012-12-12 16:00:35 -08001250 /* map the auth failure codes, so we can retry pairing if necessary */
1251 case HCI_ERR_AUTH_FAILURE:
Hemant Gupta59a88ec2014-03-19 19:01:35 +05301252 case HCI_ERR_KEY_MISSING:
Zhihai Xua7ea8092013-11-27 14:10:53 +05301253 btif_storage_remove_bonded_device(&bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001254 case HCI_ERR_HOST_REJECT_SECURITY:
1255 case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE:
1256 case HCI_ERR_UNIT_KEY_USED:
1257 case HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED:
1258 case HCI_ERR_INSUFFCIENT_SECURITY:
Hemant Gupta87b7cce2013-11-28 13:07:10 +05301259 case HCI_ERR_PEER_USER:
1260 case HCI_ERR_UNSPECIFIED:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001261 BTIF_TRACE_DEBUG(" %s() Authentication fail reason %d",
Hemant Gupta87b7cce2013-11-28 13:07:10 +05301262 __FUNCTION__, p_auth_cmpl->fail_reason);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001263 if (pairing_cb.autopair_attempts == 1)
1264 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001265 BTIF_TRACE_DEBUG("%s(): Adding device to blacklist ", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001266
1267 /* Add the device to dynamic black list only if this device belongs to Audio/pointing dev class */
1268 if (check_cod(&bd_addr, COD_AV_HEADSETS) ||
1269 check_cod(&bd_addr, COD_AV_HANDSFREE) ||
1270 check_cod(&bd_addr, COD_AV_HEADPHONES) ||
1271 check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) ||
1272 check_cod(&bd_addr, COD_AV_HIFI_AUDIO) ||
1273 check_cod(&bd_addr, COD_HID_POINTING))
1274 {
1275 btif_storage_add_device_to_autopair_blacklist (&bd_addr);
1276 }
1277 pairing_cb.autopair_attempts++;
1278
1279 /* Create the Bond once again */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001280 BTIF_TRACE_DEBUG("%s() auto pair failed. Reinitiate Bond", __FUNCTION__);
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07001281 btif_dm_cb_create_bond (&bd_addr, BTA_TRANSPORT_UNKNOWN);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001282 return;
1283 }
1284 else
1285 {
1286 /* if autopair attempts are more than 1, or not attempted */
1287 status = BT_STATUS_AUTH_FAILURE;
1288 }
1289 break;
1290
1291 default:
1292 status = BT_STATUS_FAIL;
1293 }
Zhihai Xu8d2128d2013-12-13 16:09:21 +05301294 /* Special Handling for HID Devices */
1295 if (check_cod(&bd_addr, COD_HID_POINTING)) {
1296 /* Remove Device as bonded in nvram as authentication failed */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001297 BTIF_TRACE_DEBUG("%s(): removing hid pointing device from nvram", __FUNCTION__);
Zhihai Xu8d2128d2013-12-13 16:09:21 +05301298 btif_storage_remove_bonded_device(&bd_addr);
1299 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001300 bond_state_changed(status, &bd_addr, state);
1301 }
1302}
1303
1304/******************************************************************************
1305**
1306** Function btif_dm_search_devices_evt
1307**
1308** Description Executes search devices callback events in btif context
1309**
1310** Returns void
1311**
1312******************************************************************************/
1313static void btif_dm_search_devices_evt (UINT16 event, char *p_param)
1314{
1315 tBTA_DM_SEARCH *p_search_data;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001316 BTIF_TRACE_EVENT("%s event=%s", __FUNCTION__, dump_dm_search_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001317
1318 switch (event)
1319 {
1320 case BTA_DM_DISC_RES_EVT:
1321 {
1322 p_search_data = (tBTA_DM_SEARCH *)p_param;
1323 /* Remote name update */
1324 if (strlen((const char *) p_search_data->disc_res.bd_name))
1325 {
1326 bt_property_t properties[1];
1327 bt_bdaddr_t bdaddr;
1328 bt_status_t status;
1329
1330 properties[0].type = BT_PROPERTY_BDNAME;
1331 properties[0].val = p_search_data->disc_res.bd_name;
1332 properties[0].len = strlen((char *)p_search_data->disc_res.bd_name);
1333 bdcpy(bdaddr.address, p_search_data->disc_res.bd_addr);
1334
1335 status = btif_storage_set_remote_device_property(&bdaddr, &properties[0]);
1336 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device property", status);
1337 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1338 status, &bdaddr, 1, properties);
1339 }
1340 /* TODO: Services? */
1341 }
1342 break;
1343
1344 case BTA_DM_INQ_RES_EVT:
1345 {
1346 /* inquiry result */
1347 UINT32 cod;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001348 bt_bdname_t bdname;
1349 bt_bdaddr_t bdaddr;
1350 UINT8 remote_name_len;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001351 tBTA_SERVICE_MASK services = 0;
1352 bdstr_t bdstr;
1353
1354 p_search_data = (tBTA_DM_SEARCH *)p_param;
1355 bdcpy(bdaddr.address, p_search_data->inq_res.bd_addr);
1356
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07001357 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 -08001358#if (BLE_INCLUDED == TRUE)
1359 p_search_data->inq_res.device_type);
1360#else
1361 BT_DEVICE_TYPE_BREDR);
1362#endif
1363 bdname.name[0] = 0;
1364
1365 cod = devclass2uint (p_search_data->inq_res.dev_class);
1366
Chris Mantonf8027002015-03-12 09:22:48 -07001367 if (cod == 0) {
1368 LOG_DEBUG("%s cod is 0, set as unclassified", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001369 cod = COD_UNCLASSIFIED;
1370 }
1371
1372 if (!check_eir_remote_name(p_search_data, bdname.name, &remote_name_len))
1373 check_cached_remote_name(p_search_data, bdname.name, &remote_name_len);
1374
1375 /* Check EIR for remote name and services */
1376 if (p_search_data->inq_res.p_eir)
1377 {
1378 BTA_GetEirService(p_search_data->inq_res.p_eir, &services);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001379 BTIF_TRACE_DEBUG("%s()EIR BTA services = %08X", __FUNCTION__, (UINT32)services);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001380 /* TODO: Get the service list and check to see which uuids we got and send it back to the client. */
1381 }
1382
1383
1384 {
1385 bt_property_t properties[5];
1386 bt_device_type_t dev_type;
1387 uint32_t num_properties = 0;
1388 bt_status_t status;
Nitin Aroraac728402015-06-26 18:09:37 -07001389 int addr_type = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001390
1391 memset(properties, 0, sizeof(properties));
1392 /* BD_ADDR */
1393 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1394 BT_PROPERTY_BDADDR, sizeof(bdaddr), &bdaddr);
1395 num_properties++;
1396 /* BD_NAME */
1397 /* Don't send BDNAME if it is empty */
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001398 if (bdname.name[0])
1399 {
The Android Open Source Project5738f832012-12-12 16:00:35 -08001400 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1401 BT_PROPERTY_BDNAME,
1402 strlen((char *)bdname.name), &bdname);
1403 num_properties++;
1404 }
1405
1406 /* DEV_CLASS */
1407 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1408 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
1409 num_properties++;
1410 /* DEV_TYPE */
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001411#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001412 /* FixMe: Assumption is that bluetooth.h and BTE enums match */
Nitin Aroraac728402015-06-26 18:09:37 -07001413
1414 /* Verify if the device is dual mode in NVRAM */
1415 int stored_device_type = 0;
1416 if (btif_get_device_type(bdaddr.address, &stored_device_type) &&
1417 ((stored_device_type == BT_DEVICE_TYPE_BLE &&
1418 p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BREDR) ||
1419 (stored_device_type == BT_DEVICE_TYPE_BREDR &&
1420 p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BLE))) {
1421 dev_type = BT_DEVICE_TYPE_DUMO;
1422 } else {
1423 dev_type = p_search_data->inq_res.device_type;
1424 }
1425
1426 if (p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BLE)
1427 addr_type = p_search_data->inq_res.ble_addr_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001428#else
1429 dev_type = BT_DEVICE_TYPE_BREDR;
1430#endif
1431 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1432 BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
1433 num_properties++;
1434 /* RSSI */
1435 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1436 BT_PROPERTY_REMOTE_RSSI, sizeof(int8_t),
1437 &(p_search_data->inq_res.rssi));
1438 num_properties++;
1439
1440 status = btif_storage_add_remote_device(&bdaddr, num_properties, properties);
1441 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device (inquiry)", status);
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001442#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1443 status = btif_storage_set_remote_addr_type(&bdaddr, addr_type);
1444 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote addr type (inquiry)", status);
1445#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001446 /* Callback to notify upper layer of device */
1447 HAL_CBACK(bt_hal_cbacks, device_found_cb,
1448 num_properties, properties);
1449 }
1450 }
1451 break;
1452
1453 case BTA_DM_INQ_CMPL_EVT:
1454 {
Satya Calloji6e2d9db2014-07-08 16:18:58 -07001455#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1456 tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param;
1457 memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
1458 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL,
1459 bte_scan_filt_param_cfg_evt, 0);
1460#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001461 }
1462 break;
1463 case BTA_DM_DISC_CMPL_EVT:
1464 {
1465 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED);
1466 }
1467 break;
1468 case BTA_DM_SEARCH_CANCEL_CMPL_EVT:
1469 {
1470 /* if inquiry is not in progress and we get a cancel event, then
1471 * it means we are done with inquiry, but remote_name fetches are in
1472 * progress
1473 *
1474 * if inquiry is in progress, then we don't want to act on this cancel_cmpl_evt
1475 * but instead wait for the cancel_cmpl_evt via the Busy Level
1476 *
1477 */
1478 if (btif_dm_inquiry_in_progress == FALSE)
1479 {
Nitin Arora7b85efa2014-09-26 14:05:24 -07001480#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1481 tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param;
1482 memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
1483 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL,
1484 bte_scan_filt_param_cfg_evt, 0);
1485#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001486 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED);
1487 }
1488 }
1489 break;
1490 }
1491}
1492
1493/*******************************************************************************
1494**
1495** Function btif_dm_search_services_evt
1496**
1497** Description Executes search services event in btif context
1498**
1499** Returns void
1500**
1501*******************************************************************************/
1502static void btif_dm_search_services_evt(UINT16 event, char *p_param)
1503{
1504 tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param;
1505
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001506 BTIF_TRACE_EVENT("%s: event = %d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001507 switch (event)
1508 {
1509 case BTA_DM_DISC_RES_EVT:
1510 {
The Android Open Source Project5738f832012-12-12 16:00:35 -08001511 bt_property_t prop;
Bernhard Rosenkränzer104e3f22014-11-12 21:53:08 +01001512 uint32_t i = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001513 bt_bdaddr_t bd_addr;
1514 bt_status_t ret;
1515
1516 bdcpy(bd_addr.address, p_data->disc_res.bd_addr);
1517
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001518 BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001519 p_data->disc_res.result, p_data->disc_res.services);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001520 if ((p_data->disc_res.result != BTA_SUCCESS) &&
1521 (pairing_cb.state == BT_BOND_STATE_BONDING ) &&
1522 (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING))
1523 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001524 BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", __FUNCTION__);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001525 pairing_cb.sdp_attempts++;
1526 btif_dm_get_remote_services(&bd_addr);
1527 return;
1528 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001529 prop.type = BT_PROPERTY_UUIDS;
1530 prop.len = 0;
1531 if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0))
1532 {
1533 prop.val = p_data->disc_res.p_uuid_list;
1534 prop.len = p_data->disc_res.num_uuids * MAX_UUID_SIZE;
1535 for (i=0; i < p_data->disc_res.num_uuids; i++)
1536 {
1537 char temp[256];
Chris Manton8ff3fea2015-01-07 13:59:14 -08001538 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 -07001539 LOG_INFO("%s index:%d uuid:%s", __func__, i, temp);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001540 }
1541 }
1542
1543 /* onUuidChanged requires getBondedDevices to be populated.
1544 ** bond_state_changed needs to be sent prior to remote_device_property
1545 */
1546 if ((pairing_cb.state == BT_BOND_STATE_BONDING) &&
Chaojing Sune2805532015-04-22 13:40:21 -07001547 ((bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0) ||
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001548 (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0)) &&
Chaojing Sune2805532015-04-22 13:40:21 -07001549 pairing_cb.sdp_attempts > 0)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001550 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001551 BTIF_TRACE_DEBUG("%s Remote Service SDP done. Call bond_state_changed_cb BONDED",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001552 __FUNCTION__);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001553 pairing_cb.sdp_attempts = 0;
Chaojing Sune2805532015-04-22 13:40:21 -07001554
1555 // If bonding occured due to cross-key pairing, send bonding callback
1556 // for static address now
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001557 if (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0)
Chaojing Sune2805532015-04-22 13:40:21 -07001558 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
1559
The Android Open Source Project5738f832012-12-12 16:00:35 -08001560 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED);
1561 }
1562
Chaojing Sune2805532015-04-22 13:40:21 -07001563 if (p_data->disc_res.num_uuids != 0)
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001564 {
1565 /* Also write this to the NVRAM */
1566 ret = btif_storage_set_remote_device_property(&bd_addr, &prop);
1567 ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);
1568 /* Send the event to the BTIF */
1569 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1570 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1571 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001572 }
1573 break;
1574
1575 case BTA_DM_DISC_CMPL_EVT:
1576 /* fixme */
1577 break;
1578
Matthew Xie607e3b72013-08-15 19:30:48 -07001579#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001580 case BTA_DM_DISC_BLE_RES_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001581 BTIF_TRACE_DEBUG("%s:, services 0x%x)", __FUNCTION__,
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001582 p_data->disc_ble_res.service.uu.uuid16);
1583 bt_uuid_t uuid;
1584 int i = 0;
1585 int j = 15;
1586 if (p_data->disc_ble_res.service.uu.uuid16 == UUID_SERVCLASS_LE_HID)
1587 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001588 BTIF_TRACE_DEBUG("%s: Found HOGP UUID",__FUNCTION__);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001589 bt_property_t prop;
1590 bt_bdaddr_t bd_addr;
1591 char temp[256];
Zhihai Xud7ee77b2013-11-05 18:06:54 -08001592 bt_status_t ret;
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001593
1594 bta_gatt_convert_uuid16_to_uuid128(uuid.uu,p_data->disc_ble_res.service.uu.uuid16);
1595
1596 while(i < j )
1597 {
1598 unsigned char c = uuid.uu[j];
1599 uuid.uu[j] = uuid.uu[i];
1600 uuid.uu[i] = c;
1601 i++;
1602 j--;
1603 }
1604
Chris Manton8ff3fea2015-01-07 13:59:14 -08001605 uuid_to_string_legacy(&uuid, temp);
Chris Mantonf8027002015-03-12 09:22:48 -07001606 LOG_INFO("%s uuid:%s", __func__, temp);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001607
1608 bdcpy(bd_addr.address, p_data->disc_ble_res.bd_addr);
1609 prop.type = BT_PROPERTY_UUIDS;
1610 prop.val = uuid.uu;
1611 prop.len = MAX_UUID_SIZE;
1612
Zhihai Xud7ee77b2013-11-05 18:06:54 -08001613 /* Also write this to the NVRAM */
1614 ret = btif_storage_set_remote_device_property(&bd_addr, &prop);
1615 ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);
1616
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001617 /* Send the event to the BTIF */
1618 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1619 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1620
1621 }
1622 break;
Matthew Xie607e3b72013-08-15 19:30:48 -07001623#endif /* BLE_INCLUDED */
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001624
The Android Open Source Project5738f832012-12-12 16:00:35 -08001625 default:
1626 {
1627 ASSERTC(0, "unhandled search services event", event);
1628 }
1629 break;
1630 }
1631}
1632
1633/*******************************************************************************
1634**
1635** Function btif_dm_remote_service_record_evt
1636**
1637** Description Executes search service record event in btif context
1638**
1639** Returns void
1640**
1641*******************************************************************************/
1642static void btif_dm_remote_service_record_evt(UINT16 event, char *p_param)
1643{
1644 tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param;
1645
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001646 BTIF_TRACE_EVENT("%s: event = %d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001647 switch (event)
1648 {
1649 case BTA_DM_DISC_RES_EVT:
1650 {
1651 bt_service_record_t rec;
1652 bt_property_t prop;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001653 bt_bdaddr_t bd_addr;
1654
1655 memset(&rec, 0, sizeof(bt_service_record_t));
1656 bdcpy(bd_addr.address, p_data->disc_res.bd_addr);
1657
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001658 BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001659 p_data->disc_res.result, p_data->disc_res.services);
1660 prop.type = BT_PROPERTY_SERVICE_RECORD;
1661 prop.val = (void*)&rec;
1662 prop.len = sizeof(rec);
1663
1664 /* disc_res.result is overloaded with SCN. Cannot check result */
1665 p_data->disc_res.services &= ~BTA_USER_SERVICE_MASK;
1666 /* TODO: Get the UUID as well */
1667 rec.channel = p_data->disc_res.result - 3;
1668 /* TODO: Need to get the service name using p_raw_data */
1669 rec.name[0] = 0;
1670
1671 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1672 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1673 }
1674 break;
1675
1676 default:
1677 {
1678 ASSERTC(0, "unhandled remote service record event", event);
1679 }
1680 break;
1681 }
1682}
1683
1684/*******************************************************************************
1685**
1686** Function btif_dm_upstreams_cback
1687**
1688** Description Executes UPSTREAMS events in btif context
1689**
1690** Returns void
1691**
1692*******************************************************************************/
1693static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
1694{
The Android Open Source Project5738f832012-12-12 16:00:35 -08001695 tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)p_param;
1696 tBTA_SERVICE_MASK service_mask;
1697 uint32_t i;
1698 bt_bdaddr_t bd_addr;
1699
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001700 BTIF_TRACE_EVENT("btif_dm_upstreams_cback ev: %s", dump_dm_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001701
1702 switch (event)
1703 {
1704 case BTA_DM_ENABLE_EVT:
1705 {
1706 BD_NAME bdname;
1707 bt_status_t status;
1708 bt_property_t prop;
1709 prop.type = BT_PROPERTY_BDNAME;
1710 prop.len = BD_NAME_LEN;
1711 prop.val = (void*)bdname;
1712
1713 status = btif_storage_get_adapter_property(&prop);
Matthew Xie1e5109b2012-11-09 18:26:26 -08001714 if (status == BT_STATUS_SUCCESS)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001715 {
1716 /* A name exists in the storage. Make this the device name */
1717 BTA_DmSetDeviceName((char*)prop.val);
1718 }
Matthew Xie1e5109b2012-11-09 18:26:26 -08001719 else
1720 {
1721 /* Storage does not have a name yet.
1722 * Use the default name and write it to the chip
1723 */
1724 BTA_DmSetDeviceName(btif_get_default_local_name());
1725 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001726
Andre Eisenbacha015a832014-09-11 14:09:40 -07001727#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1728 /* Enable local privacy */
Andre Eisenbach3e0dc732014-10-24 09:55:34 -07001729 BTA_DmBleConfigLocalPrivacy(BLE_LOCAL_PRIVACY_ENABLED);
Andre Eisenbacha015a832014-09-11 14:09:40 -07001730#endif
1731
The Android Open Source Project5738f832012-12-12 16:00:35 -08001732 /* for each of the enabled services in the mask, trigger the profile
1733 * enable */
1734 service_mask = btif_get_enabled_services_mask();
1735 for (i=0; i <= BTA_MAX_SERVICE_ID; i++)
1736 {
1737 if (service_mask &
1738 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i)))
1739 {
1740 btif_in_execute_service_request(i, TRUE);
1741 }
1742 }
1743 /* clear control blocks */
1744 memset(&pairing_cb, 0, sizeof(btif_dm_pairing_cb_t));
Satya Calloji877123f2015-04-23 23:39:49 -07001745 pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001746
1747 /* This function will also trigger the adapter_properties_cb
1748 ** and bonded_devices_info_cb
1749 */
1750 btif_storage_load_bonded_devices();
1751
1752 btif_storage_load_autopair_device_list();
1753
Zach Johnson39110ec2014-10-06 13:15:00 -07001754 btif_enable_bluetooth_evt(p_data->enable.status);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001755 }
1756 break;
1757
1758 case BTA_DM_DISABLE_EVT:
1759 /* for each of the enabled services in the mask, trigger the profile
1760 * disable */
1761 service_mask = btif_get_enabled_services_mask();
1762 for (i=0; i <= BTA_MAX_SERVICE_ID; i++)
1763 {
1764 if (service_mask &
1765 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i)))
1766 {
1767 btif_in_execute_service_request(i, FALSE);
1768 }
1769 }
1770 btif_disable_bluetooth_evt();
1771 break;
1772
1773 case BTA_DM_PIN_REQ_EVT:
1774 btif_dm_pin_req_evt(&p_data->pin_req);
1775 break;
1776
1777 case BTA_DM_AUTH_CMPL_EVT:
1778 btif_dm_auth_cmpl_evt(&p_data->auth_cmpl);
1779 break;
1780
1781 case BTA_DM_BOND_CANCEL_CMPL_EVT:
1782 if (pairing_cb.state == BT_BOND_STATE_BONDING)
1783 {
1784 bdcpy(bd_addr.address, pairing_cb.bd_addr);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001785 btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001786 bond_state_changed(p_data->bond_cancel_cmpl.result, &bd_addr, BT_BOND_STATE_NONE);
Subramanian Srinivasan19bc89c2014-03-13 12:44:03 -07001787 btif_dm_remove_bond(&bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001788 }
1789 break;
1790
1791 case BTA_DM_SP_CFM_REQ_EVT:
1792 btif_dm_ssp_cfm_req_evt(&p_data->cfm_req);
1793 break;
1794 case BTA_DM_SP_KEY_NOTIF_EVT:
1795 btif_dm_ssp_key_notif_evt(&p_data->key_notif);
1796 break;
1797
1798 case BTA_DM_DEV_UNPAIRED_EVT:
1799 bdcpy(bd_addr.address, p_data->link_down.bd_addr);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001800 btm_set_bond_type_dev(p_data->link_down.bd_addr, BOND_TYPE_UNKNOWN);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001801
1802 /*special handling for HID devices */
1803 #if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -07001804 btif_hh_remove_device(bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001805 #endif
Hemant Gupta94c15ec2013-11-11 12:33:44 +05301806 #if (defined(BTA_HD_INCLUDED) && (BTA_HD_INCLUDED == TRUE))
1807 btif_hd_remove_device(bd_addr);
1808 #endif
1809 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1810 btif_storage_remove_ble_bonding_keys(&bd_addr);
1811 #endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001812 btif_storage_remove_bonded_device(&bd_addr);
1813 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
1814 break;
1815
1816 case BTA_DM_BUSY_LEVEL_EVT:
1817 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001818
1819 if (p_data->busy_level.level_flags & BTM_BL_INQUIRY_PAGING_MASK)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001820 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001821 if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_STARTED)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001822 {
1823 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb,
1824 BT_DISCOVERY_STARTED);
1825 btif_dm_inquiry_in_progress = TRUE;
1826 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001827 else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_CANCELLED)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001828 {
1829 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb,
1830 BT_DISCOVERY_STOPPED);
1831 btif_dm_inquiry_in_progress = FALSE;
1832 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001833 else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_COMPLETE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001834 {
1835 btif_dm_inquiry_in_progress = FALSE;
1836 }
1837 }
1838 }break;
1839
1840 case BTA_DM_LINK_UP_EVT:
1841 bdcpy(bd_addr.address, p_data->link_up.bd_addr);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001842 BTIF_TRACE_DEBUG("BTA_DM_LINK_UP_EVT. Sending BT_ACL_STATE_CONNECTED");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001843
1844 btif_update_remote_version_property(&bd_addr);
1845
The Android Open Source Project5738f832012-12-12 16:00:35 -08001846 HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS,
1847 &bd_addr, BT_ACL_STATE_CONNECTED);
1848 break;
1849
1850 case BTA_DM_LINK_DOWN_EVT:
1851 bdcpy(bd_addr.address, p_data->link_down.bd_addr);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001852 btm_set_bond_type_dev(p_data->link_down.bd_addr, BOND_TYPE_UNKNOWN);
Anubhav Gupta791692a2013-12-06 17:11:11 +05301853 btif_av_move_idle(bd_addr);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001854 BTIF_TRACE_DEBUG("BTA_DM_LINK_DOWN_EVT. Sending BT_ACL_STATE_DISCONNECTED");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001855 HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS,
1856 &bd_addr, BT_ACL_STATE_DISCONNECTED);
1857 break;
1858
1859 case BTA_DM_HW_ERROR_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001860 BTIF_TRACE_ERROR("Received H/W Error. ");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001861 /* Flush storage data */
1862 btif_config_flush();
1863 usleep(100000); /* 100milliseconds */
1864 /* Killing the process to force a restart as part of fault tolerance */
1865 kill(getpid(), SIGKILL);
1866 break;
1867
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001868#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1869 case BTA_DM_BLE_KEY_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001870 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 -08001871
1872 /* If this pairing is by-product of local initiated GATT client Read or Write,
1873 BTA would not have sent BTA_DM_BLE_SEC_REQ_EVT event and Bond state would not
1874 have setup properly. Setup pairing_cb and notify App about Bonding state now*/
1875 if (pairing_cb.state != BT_BOND_STATE_BONDING)
1876 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001877 BTIF_TRACE_DEBUG("Bond state not sent to App so far.Notify the app now");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001878 bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t*)p_data->ble_key.bd_addr,
1879 BT_BOND_STATE_BONDING);
1880 }
1881 else if (memcmp (pairing_cb.bd_addr, p_data->ble_key.bd_addr, BD_ADDR_LEN)!=0)
1882 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001883 BTIF_TRACE_ERROR("BD mismatch discard BLE key_type=%d ",p_data->ble_key.key_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001884 break;
1885 }
1886
1887 switch (p_data->ble_key.key_type)
1888 {
1889 case BTA_LE_KEY_PENC:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001890 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PENC");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001891 pairing_cb.ble.is_penc_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001892 pairing_cb.ble.penc_key = p_data->ble_key.p_key_value->penc_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001893 break;
1894
1895 case BTA_LE_KEY_PID:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001896 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PID");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001897 pairing_cb.ble.is_pid_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001898 pairing_cb.ble.pid_key = p_data->ble_key.p_key_value->pid_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001899 break;
1900
1901 case BTA_LE_KEY_PCSRK:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001902 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PCSRK");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001903 pairing_cb.ble.is_pcsrk_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001904 pairing_cb.ble.pcsrk_key = p_data->ble_key.p_key_value->pcsrk_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001905 break;
1906
1907 case BTA_LE_KEY_LENC:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001908 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LENC");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001909 pairing_cb.ble.is_lenc_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001910 pairing_cb.ble.lenc_key = p_data->ble_key.p_key_value->lenc_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001911 break;
1912
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001913 case BTA_LE_KEY_LCSRK:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001914 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LCSRK");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001915 pairing_cb.ble.is_lcsrk_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001916 pairing_cb.ble.lcsrk_key = p_data->ble_key.p_key_value->lcsrk_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001917 break;
1918
Satya Calloji444a8da2015-03-06 10:38:22 -08001919 case BTA_LE_KEY_LID:
1920 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LID");
1921 pairing_cb.ble.is_lidk_key_rcvd = TRUE;
1922 break;
1923
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001924 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001925 BTIF_TRACE_ERROR("unknown BLE key type (0x%02x)", p_data->ble_key.key_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001926 break;
1927 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001928 break;
1929 case BTA_DM_BLE_SEC_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001930 BTIF_TRACE_DEBUG("BTA_DM_BLE_SEC_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001931 btif_dm_ble_sec_req_evt(&p_data->ble_req);
1932 break;
1933 case BTA_DM_BLE_PASSKEY_NOTIF_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001934 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_NOTIF_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001935 btif_dm_ble_key_notif_evt(&p_data->key_notif);
1936 break;
1937 case BTA_DM_BLE_PASSKEY_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001938 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001939 btif_dm_ble_passkey_req_evt(&p_data->pin_req);
1940 break;
Satya Calloji444a8da2015-03-06 10:38:22 -08001941 case BTA_DM_BLE_NC_REQ_EVT:
1942 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_REQ_EVT. ");
1943 btif_dm_ble_key_nc_req_evt(&p_data->key_notif);
1944 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001945 case BTA_DM_BLE_OOB_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001946 BTIF_TRACE_DEBUG("BTA_DM_BLE_OOB_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001947 break;
1948 case BTA_DM_BLE_LOCAL_IR_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001949 BTIF_TRACE_DEBUG("BTA_DM_BLE_LOCAL_IR_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001950 ble_local_key_cb.is_id_keys_rcvd = TRUE;
Satya Calloji444a8da2015-03-06 10:38:22 -08001951 memcpy(&ble_local_key_cb.id_keys.irk[0],
1952 &p_data->ble_id_keys.irk[0], sizeof(BT_OCTET16));
1953 memcpy(&ble_local_key_cb.id_keys.ir[0],
1954 &p_data->ble_id_keys.ir[0], sizeof(BT_OCTET16));
1955 memcpy(&ble_local_key_cb.id_keys.dhk[0],
1956 &p_data->ble_id_keys.dhk[0], sizeof(BT_OCTET16));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001957 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.irk[0],
Satya Calloji7bd40382015-05-19 14:42:32 -07001958 BTIF_DM_LE_LOCAL_KEY_IRK,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001959 BT_OCTET16_LEN);
1960 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.ir[0],
Satya Calloji7bd40382015-05-19 14:42:32 -07001961 BTIF_DM_LE_LOCAL_KEY_IR,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001962 BT_OCTET16_LEN);
1963 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.dhk[0],
1964 BTIF_DM_LE_LOCAL_KEY_DHK,
1965 BT_OCTET16_LEN);
1966 break;
1967 case BTA_DM_BLE_LOCAL_ER_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001968 BTIF_TRACE_DEBUG("BTA_DM_BLE_LOCAL_ER_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001969 ble_local_key_cb.is_er_rcvd = TRUE;
1970 memcpy(&ble_local_key_cb.er[0], &p_data->ble_er[0], sizeof(BT_OCTET16));
1971 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.er[0],
1972 BTIF_DM_LE_LOCAL_KEY_ER,
1973 BT_OCTET16_LEN);
1974 break;
1975
1976 case BTA_DM_BLE_AUTH_CMPL_EVT:
Satya Calloji444a8da2015-03-06 10:38:22 -08001977 BTIF_TRACE_DEBUG("BTA_DM_BLE_AUTH_CMPL_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001978 btif_dm_ble_auth_cmpl_evt(&p_data->auth_cmpl);
1979 break;
Ganesh Ganapathi Batta9546abf2014-05-30 16:28:00 -07001980
1981 case BTA_DM_LE_FEATURES_READ:
1982 {
1983 tBTM_BLE_VSC_CB cmn_vsc_cb;
1984 bt_local_le_features_t local_le_features;
1985 char buf[512];
1986 bt_property_t prop;
1987 prop.type = BT_PROPERTY_LOCAL_LE_FEATURES;
1988 prop.val = (void*)buf;
1989 prop.len = sizeof(buf);
1990
1991 /* LE features are not stored in storage. Should be retrived from stack */
1992 BTM_BleGetVendorCapabilities(&cmn_vsc_cb);
1993 local_le_features.local_privacy_enabled = BTM_BleLocalPrivacyEnabled();
1994
1995 prop.len = sizeof (bt_local_le_features_t);
1996 if (cmn_vsc_cb.filter_support == 1)
1997 local_le_features.max_adv_filter_supported = cmn_vsc_cb.max_filter;
1998 else
1999 local_le_features.max_adv_filter_supported = 0;
2000 local_le_features.max_adv_instance = cmn_vsc_cb.adv_inst_max;
2001 local_le_features.max_irk_list_size = cmn_vsc_cb.max_irk_list_sz;
2002 local_le_features.rpa_offload_supported = cmn_vsc_cb.rpa_offloading;
Satya Callojiefaddcb2014-07-28 23:22:05 -07002003 local_le_features.activity_energy_info_supported = cmn_vsc_cb.energy_support;
Satya Callojif5387072015-02-09 17:40:52 -08002004 local_le_features.scan_result_storage_size = cmn_vsc_cb.tot_scan_results_strg;
2005 local_le_features.version_supported = cmn_vsc_cb.version_supported;
2006 local_le_features.total_trackable_advertisers =
2007 cmn_vsc_cb.total_trackable_advertisers;
Satya Calloji5725fc62015-03-31 13:24:32 -07002008
2009 local_le_features.extended_scan_support = cmn_vsc_cb.extended_scan_support > 0;
2010 local_le_features.debug_logging_supported = cmn_vsc_cb.debug_logging_supported > 0;
2011
Ganesh Ganapathi Batta9546abf2014-05-30 16:28:00 -07002012 memcpy(prop.val, &local_le_features, prop.len);
2013 HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, BT_STATUS_SUCCESS, 1, &prop);
2014 break;
2015 }
Satya Callojie5ba8842014-07-03 17:18:02 -07002016
2017 case BTA_DM_ENER_INFO_READ:
2018 {
2019 btif_activity_energy_info_cb_t *p_ener_data = (btif_activity_energy_info_cb_t*) p_param;
2020 bt_activity_energy_info energy_info;
2021 energy_info.status = p_ener_data->status;
2022 energy_info.ctrl_state = p_ener_data->ctrl_state;
2023 energy_info.rx_time = p_ener_data->rx_time;
2024 energy_info.tx_time = p_ener_data->tx_time;
2025 energy_info.idle_time = p_ener_data->idle_time;
2026 energy_info.energy_used = p_ener_data->energy_used;
2027 HAL_CBACK(bt_hal_cbacks, energy_info_cb, &energy_info);
2028 break;
2029 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002030#endif
2031
The Android Open Source Project5738f832012-12-12 16:00:35 -08002032 case BTA_DM_AUTHORIZE_EVT:
2033 case BTA_DM_SIG_STRENGTH_EVT:
2034 case BTA_DM_SP_RMT_OOB_EVT:
2035 case BTA_DM_SP_KEYPRESS_EVT:
2036 case BTA_DM_ROLE_CHG_EVT:
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002037
The Android Open Source Project5738f832012-12-12 16:00:35 -08002038 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002039 BTIF_TRACE_WARNING( "btif_dm_cback : unhandled event (%d)", event );
The Android Open Source Project5738f832012-12-12 16:00:35 -08002040 break;
2041 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002042
Andre Eisenbach8a057242015-04-29 22:27:15 -07002043 btif_dm_data_free(event, p_data);
2044}
The Android Open Source Project5738f832012-12-12 16:00:35 -08002045
2046/*******************************************************************************
2047**
2048** Function btif_dm_generic_evt
2049**
2050** Description Executes non-BTA upstream events in BTIF context
2051**
2052** Returns void
2053**
2054*******************************************************************************/
2055static void btif_dm_generic_evt(UINT16 event, char* p_param)
2056{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002057 BTIF_TRACE_EVENT("%s: event=%d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002058 switch(event)
2059 {
2060 case BTIF_DM_CB_DISCOVERY_STARTED:
2061 {
2062 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STARTED);
2063 }
2064 break;
2065
2066 case BTIF_DM_CB_CREATE_BOND:
2067 {
Andre Eisenbach31a64002014-10-14 14:29:19 -07002068 pairing_cb.timeout_retries = NUM_TIMEOUT_RETRIES;
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002069 btif_dm_create_bond_cb_t *create_bond_cb = (btif_dm_create_bond_cb_t*)p_param;
2070 btif_dm_cb_create_bond(&create_bond_cb->bdaddr, create_bond_cb->transport);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002071 }
2072 break;
2073
2074 case BTIF_DM_CB_REMOVE_BOND:
2075 {
2076 btif_dm_cb_remove_bond((bt_bdaddr_t *)p_param);
2077 }
2078 break;
2079
2080 case BTIF_DM_CB_HID_REMOTE_NAME:
2081 {
2082 btif_dm_cb_hid_remote_name((tBTM_REMOTE_DEV_NAME *)p_param);
2083 }
2084 break;
2085
2086 case BTIF_DM_CB_BOND_STATE_BONDING:
2087 {
2088 bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t *)p_param, BT_BOND_STATE_BONDING);
2089 }
2090 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002091 case BTIF_DM_CB_LE_TX_TEST:
2092 case BTIF_DM_CB_LE_RX_TEST:
2093 {
2094 uint8_t status;
2095 STREAM_TO_UINT8(status, p_param);
2096 HAL_CBACK(bt_hal_cbacks, le_test_mode_cb,
2097 (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, 0);
2098 }
2099 break;
2100 case BTIF_DM_CB_LE_TEST_END:
2101 {
2102 uint8_t status;
2103 uint16_t count = 0;
2104 STREAM_TO_UINT8(status, p_param);
2105 if (status == 0)
2106 STREAM_TO_UINT16(count, p_param);
2107 HAL_CBACK(bt_hal_cbacks, le_test_mode_cb,
2108 (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, count);
2109 }
2110 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002111 default:
2112 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002113 BTIF_TRACE_WARNING("%s : Unknown event 0x%x", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002114 }
2115 break;
2116 }
2117}
2118
2119/*******************************************************************************
2120**
2121** Function bte_dm_evt
2122**
2123** Description Switches context from BTE to BTIF for all DM events
2124**
2125** Returns void
2126**
2127*******************************************************************************/
2128
2129void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data)
2130{
The Android Open Source Project5738f832012-12-12 16:00:35 -08002131 /* switch context to btif task context (copy full union size for convenience) */
Andre Eisenbach8a057242015-04-29 22:27:15 -07002132 bt_status_t status = btif_transfer_context(btif_dm_upstreams_evt, (uint16_t)event,
2133 (void*)p_data, sizeof(tBTA_DM_SEC), btif_dm_data_copy);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002134
2135 /* catch any failed context transfers */
2136 ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status);
2137}
2138
2139/*******************************************************************************
2140**
2141** Function bte_search_devices_evt
2142**
2143** Description Switches context from BTE to BTIF for DM search events
2144**
2145** Returns void
2146**
2147*******************************************************************************/
2148static void bte_search_devices_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
2149{
2150 UINT16 param_len = 0;
2151
2152 if (p_data)
2153 param_len += sizeof(tBTA_DM_SEARCH);
2154 /* Allocate buffer to hold the pointers (deep copy). The pointers will point to the end of the tBTA_DM_SEARCH */
2155 switch (event)
2156 {
2157 case BTA_DM_INQ_RES_EVT:
2158 {
2159 if (p_data->inq_res.p_eir)
2160 param_len += HCI_EXT_INQ_RESPONSE_LEN;
2161 }
2162 break;
2163
2164 case BTA_DM_DISC_RES_EVT:
2165 {
2166 if (p_data->disc_res.raw_data_size && p_data->disc_res.p_raw_data)
2167 param_len += p_data->disc_res.raw_data_size;
2168 }
2169 break;
2170 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002171 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 -08002172
2173 /* if remote name is available in EIR, set teh flag so that stack doesnt trigger RNR */
2174 if (event == BTA_DM_INQ_RES_EVT)
2175 p_data->inq_res.remt_name_not_required = check_eir_remote_name(p_data, NULL, NULL);
2176
2177 btif_transfer_context (btif_dm_search_devices_evt , (UINT16) event, (void *)p_data, param_len,
2178 (param_len > sizeof(tBTA_DM_SEARCH)) ? search_devices_copy_cb : NULL);
2179}
2180
2181/*******************************************************************************
2182**
2183** Function bte_dm_search_services_evt
2184**
2185** Description Switches context from BTE to BTIF for DM search services
2186** event
2187**
2188** Returns void
2189**
2190*******************************************************************************/
2191static void bte_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
2192{
2193 UINT16 param_len = 0;
2194 if (p_data)
2195 param_len += sizeof(tBTA_DM_SEARCH);
2196 switch (event)
2197 {
2198 case BTA_DM_DISC_RES_EVT:
2199 {
2200 if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0)) {
2201 param_len += (p_data->disc_res.num_uuids * MAX_UUID_SIZE);
2202 }
2203 } break;
2204 }
2205 /* TODO: The only other member that needs a deep copy is the p_raw_data. But not sure
2206 * if raw_data is needed. */
2207 btif_transfer_context(btif_dm_search_services_evt, event, (char*)p_data, param_len,
2208 (param_len > sizeof(tBTA_DM_SEARCH)) ? search_services_copy_cb : NULL);
2209}
2210
2211/*******************************************************************************
2212**
2213** Function bte_dm_remote_service_record_evt
2214**
2215** Description Switches context from BTE to BTIF for DM search service
2216** record event
2217**
2218** Returns void
2219**
2220*******************************************************************************/
2221static void bte_dm_remote_service_record_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
2222{
2223 /* TODO: The only member that needs a deep copy is the p_raw_data. But not sure yet if this is needed. */
2224 btif_transfer_context(btif_dm_remote_service_record_evt, event, (char*)p_data, sizeof(tBTA_DM_SEARCH), NULL);
2225}
2226
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07002227#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Satya Callojie5ba8842014-07-03 17:18:02 -07002228/*******************************************************************************
2229**
2230** Function bta_energy_info_cb
2231**
2232** Description Switches context from BTE to BTIF for DM energy info event
2233**
2234** Returns void
2235**
2236*******************************************************************************/
2237static void bta_energy_info_cb(tBTA_DM_BLE_TX_TIME_MS tx_time, tBTA_DM_BLE_RX_TIME_MS rx_time,
2238 tBTA_DM_BLE_IDLE_TIME_MS idle_time,
2239 tBTA_DM_BLE_ENERGY_USED energy_used,
2240 tBTA_DM_CONTRL_STATE ctrl_state, tBTA_STATUS status)
2241{
2242 BTIF_TRACE_DEBUG("energy_info_cb-Status:%d,state=%d,tx_t=%ld, rx_t=%ld, idle_time=%ld,used=%ld",
2243 status, ctrl_state, tx_time, rx_time, idle_time, energy_used);
2244
2245 btif_activity_energy_info_cb_t btif_cb;
2246 btif_cb.status = status;
2247 btif_cb.ctrl_state = ctrl_state;
2248 btif_cb.tx_time = (uint64_t) tx_time;
2249 btif_cb.rx_time = (uint64_t) rx_time;
2250 btif_cb.idle_time =(uint64_t) idle_time;
2251 btif_cb.energy_used =(uint64_t) energy_used;
2252 btif_transfer_context(btif_dm_upstreams_evt, BTA_DM_ENER_INFO_READ,
2253 (char*) &btif_cb, sizeof(btif_activity_energy_info_cb_t), NULL);
2254}
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07002255#endif
Satya Callojie5ba8842014-07-03 17:18:02 -07002256
Satya Calloji6e2d9db2014-07-08 16:18:58 -07002257/*******************************************************************************
2258**
2259** Function bte_scan_filt_param_cfg_evt
2260**
2261** Description Scan filter param config event
2262**
2263** Returns void
2264**
2265*******************************************************************************/
2266static void bte_scan_filt_param_cfg_evt(UINT8 action_type,
2267 tBTA_DM_BLE_PF_AVBL_SPACE avbl_space,
2268 tBTA_DM_BLE_REF_VALUE ref_value, tBTA_STATUS status)
2269{
2270 /* This event occurs on calling BTA_DmBleCfgFilterCondition internally,
2271 ** and that is why there is no HAL callback
2272 */
2273 if(BTA_SUCCESS != status)
2274 {
2275 BTIF_TRACE_ERROR("%s, %d", __FUNCTION__, status);
2276 }
2277 else
2278 {
2279 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
2280 }
2281}
2282
The Android Open Source Project5738f832012-12-12 16:00:35 -08002283/*****************************************************************************
2284**
2285** btif api functions (no context switch)
2286**
2287*****************************************************************************/
2288
2289/*******************************************************************************
2290**
2291** Function btif_dm_start_discovery
2292**
2293** Description Start device discovery/inquiry
2294**
2295** Returns bt_status_t
2296**
2297*******************************************************************************/
2298bt_status_t btif_dm_start_discovery(void)
2299{
2300 tBTA_DM_INQ inq_params;
2301 tBTA_SERVICE_MASK services = 0;
Satya Calloji6e2d9db2014-07-08 16:18:58 -07002302 tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002303
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002304 BTIF_TRACE_EVENT("%s", __FUNCTION__);
Satya Calloji6e2d9db2014-07-08 16:18:58 -07002305
2306#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2307 memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
2308 /* Cleanup anything remaining on index 0 */
2309 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL,
2310 bte_scan_filt_param_cfg_evt, 0);
2311
2312 /* Add an allow-all filter on index 0*/
2313 adv_filt_param.dely_mode = IMMEDIATE_DELY_MODE;
2314 adv_filt_param.feat_seln = ALLOW_ALL_FILTER;
2315 adv_filt_param.filt_logic_type = BTA_DM_BLE_PF_FILT_LOGIC_OR;
2316 adv_filt_param.list_logic_type = BTA_DM_BLE_PF_LIST_LOGIC_OR;
2317 adv_filt_param.rssi_low_thres = LOWEST_RSSI_VALUE;
2318 adv_filt_param.rssi_high_thres = LOWEST_RSSI_VALUE;
2319 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_ADD, 0, &adv_filt_param, NULL,
2320 bte_scan_filt_param_cfg_evt, 0);
2321
The Android Open Source Project5738f832012-12-12 16:00:35 -08002322 /* TODO: Do we need to handle multiple inquiries at the same time? */
2323
2324 /* Set inquiry params and call API */
The Android Open Source Project5738f832012-12-12 16:00:35 -08002325 inq_params.mode = BTA_DM_GENERAL_INQUIRY|BTA_BLE_GENERAL_INQUIRY;
Matthew Xie7f3e4292013-09-30 12:44:10 -07002326#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
2327 inq_params.intl_duration[0]= BTIF_DM_INTERLEAVE_DURATION_BR_ONE;
2328 inq_params.intl_duration[1]= BTIF_DM_INTERLEAVE_DURATION_LE_ONE;
2329 inq_params.intl_duration[2]= BTIF_DM_INTERLEAVE_DURATION_BR_TWO;
2330 inq_params.intl_duration[3]= BTIF_DM_INTERLEAVE_DURATION_LE_TWO;
2331#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002332#else
2333 inq_params.mode = BTA_DM_GENERAL_INQUIRY;
2334#endif
2335 inq_params.duration = BTIF_DM_DEFAULT_INQ_MAX_DURATION;
2336
2337 inq_params.max_resps = BTIF_DM_DEFAULT_INQ_MAX_RESULTS;
2338 inq_params.report_dup = TRUE;
2339
2340 inq_params.filter_type = BTA_DM_INQ_CLR;
2341 /* TODO: Filter device by BDA needs to be implemented here */
2342
2343 /* Will be enabled to TRUE once inquiry busy level has been received */
2344 btif_dm_inquiry_in_progress = FALSE;
2345 /* find nearby devices */
2346 BTA_DmSearch(&inq_params, services, bte_search_devices_evt);
2347
2348 return BT_STATUS_SUCCESS;
2349}
2350
2351/*******************************************************************************
2352**
2353** Function btif_dm_cancel_discovery
2354**
2355** Description Cancels search
2356**
2357** Returns bt_status_t
2358**
2359*******************************************************************************/
2360bt_status_t btif_dm_cancel_discovery(void)
2361{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002362 BTIF_TRACE_EVENT("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002363 BTA_DmSearchCancel();
2364 return BT_STATUS_SUCCESS;
2365}
2366
2367/*******************************************************************************
2368**
2369** Function btif_dm_create_bond
2370**
2371** Description Initiate bonding with the specified device
2372**
2373** Returns bt_status_t
2374**
2375*******************************************************************************/
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002376bt_status_t btif_dm_create_bond(const bt_bdaddr_t *bd_addr, int transport)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002377{
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002378 btif_dm_create_bond_cb_t create_bond_cb;
2379 create_bond_cb.transport = transport;
2380 bdcpy(create_bond_cb.bdaddr.address, bd_addr->address);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002381
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002382 bdstr_t bdstr;
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002383 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 -08002384 if (pairing_cb.state != BT_BOND_STATE_NONE)
2385 return BT_STATUS_BUSY;
2386
2387 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_CREATE_BOND,
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002388 (char *)&create_bond_cb, sizeof(btif_dm_create_bond_cb_t), NULL);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002389
2390 return BT_STATUS_SUCCESS;
2391}
2392
2393/*******************************************************************************
2394**
2395** Function btif_dm_cancel_bond
2396**
2397** Description Initiate bonding with the specified device
2398**
2399** Returns bt_status_t
2400**
2401*******************************************************************************/
2402
2403bt_status_t btif_dm_cancel_bond(const bt_bdaddr_t *bd_addr)
2404{
2405 bdstr_t bdstr;
2406
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002407 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 -08002408
2409 /* TODO:
2410 ** 1. Restore scan modes
2411 ** 2. special handling for HID devices
2412 */
2413 if (pairing_cb.state == BT_BOND_STATE_BONDING)
2414 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002415
2416#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2417
2418 if (pairing_cb.is_ssp)
2419 {
2420 if (pairing_cb.is_le_only)
2421 {
2422 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT);
2423 }
2424 else
Hemant Guptae1468692013-11-14 16:21:29 +05302425 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002426 BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE);
Hemant Guptae1468692013-11-14 16:21:29 +05302427 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2428 btif_storage_remove_bonded_device((bt_bdaddr_t *)bd_addr);
2429 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002430 }
2431 else
2432 {
2433 if (pairing_cb.is_le_only)
2434 {
2435 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2436 }
2437 else
2438 {
2439 BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL);
2440 }
2441 /* Cancel bonding, in case it is in ACL connection setup state */
2442 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2443 }
2444
2445#else
The Android Open Source Project5738f832012-12-12 16:00:35 -08002446 if (pairing_cb.is_ssp)
2447 {
2448 BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE);
2449 }
2450 else
2451 {
2452 BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL);
2453 }
2454 /* Cancel bonding, in case it is in ACL connection setup state */
2455 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2456 btif_storage_remove_bonded_device((bt_bdaddr_t *)bd_addr);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002457#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002458 }
2459
2460 return BT_STATUS_SUCCESS;
2461}
2462
2463/*******************************************************************************
2464**
Hemant Guptada33b462015-04-26 10:32:57 +05302465** Function btif_dm_hh_open_success
2466**
2467** Description Checks if device is blacklisted, if yes takes appropriate action
2468**
2469** Returns none
2470**
2471*******************************************************************************/
2472
2473void btif_dm_hh_open_success(bt_bdaddr_t *bdaddr)
2474{
2475 if (pairing_cb.state == BT_BOND_STATE_BONDING &&
2476 bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0)
2477 {
2478 if (check_if_auth_bl(bdaddr)
2479 && check_cod_hid(bdaddr, COD_HID_MAJOR))
2480 {
2481 bt_status_t status;
2482 LINK_KEY link_key = {0};
2483 bond_state_changed(BT_STATUS_SUCCESS, bdaddr, BT_BOND_STATE_BONDED);
2484 BTIF_TRACE_DEBUG("%s: Device is blacklisted for authentication", __func__);
2485 bt_property_t prop;
2486 bt_uuid_t uuid;
2487 char uuid_str[128] = UUID_HUMAN_INTERFACE_DEVICE;
2488 string_to_uuid(uuid_str, &uuid);
2489 prop.type = BT_PROPERTY_UUIDS;
2490 prop.val = uuid.uu;
2491 prop.len = MAX_UUID_SIZE;
2492 // Also write this to the NVRAM
2493 status = btif_storage_set_remote_device_property(bdaddr, &prop);
2494 ASSERTC(status == BT_STATUS_SUCCESS, "storing remote services failed", status);
2495 // Store fake link for device as bonded in nvram,
2496 // otherwise on device reboot/bt off-on device will not be shown in paired list.
2497 btif_storage_add_bonded_device(bdaddr, link_key, HCI_LKEY_TYPE_UNAUTH_COMB, 0);
2498 // Send the event to the BTIF
2499 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
2500 BT_STATUS_SUCCESS, bdaddr, 1, &prop);
2501 }
2502 }
2503}
2504
2505/*******************************************************************************
2506**
Kim Schulza9eb25c2013-09-30 10:55:52 +02002507** Function btif_dm_hh_open_failed
2508**
2509** Description informs the upper layers if the HH have failed during bonding
2510**
2511** Returns none
2512**
2513*******************************************************************************/
2514
2515void btif_dm_hh_open_failed(bt_bdaddr_t *bdaddr)
2516{
2517 if (pairing_cb.state == BT_BOND_STATE_BONDING &&
2518 bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0)
2519 {
2520 bond_state_changed(BT_STATUS_FAIL, bdaddr, BT_BOND_STATE_NONE);
2521 }
2522}
2523
2524/*******************************************************************************
2525**
The Android Open Source Project5738f832012-12-12 16:00:35 -08002526** Function btif_dm_remove_bond
2527**
2528** Description Removes bonding with the specified device
2529**
2530** Returns bt_status_t
2531**
2532*******************************************************************************/
2533
2534bt_status_t btif_dm_remove_bond(const bt_bdaddr_t *bd_addr)
2535{
2536 bdstr_t bdstr;
2537
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002538 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 -08002539 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_REMOVE_BOND,
2540 (char *)bd_addr, sizeof(bt_bdaddr_t), NULL);
2541
2542 return BT_STATUS_SUCCESS;
2543}
2544
2545/*******************************************************************************
2546**
2547** Function btif_dm_pin_reply
2548**
2549** Description BT legacy pairing - PIN code reply
2550**
2551** Returns bt_status_t
2552**
2553*******************************************************************************/
2554
2555bt_status_t btif_dm_pin_reply( const bt_bdaddr_t *bd_addr, uint8_t accept,
2556 uint8_t pin_len, bt_pin_code_t *pin_code)
2557{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002558 BTIF_TRACE_EVENT("%s: accept=%d", __FUNCTION__, accept);
Hemant Gupta831423e2014-01-08 12:42:13 +05302559 if (pin_code == NULL)
2560 return BT_STATUS_FAIL;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002561#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002562
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002563 if (pairing_cb.is_le_only)
2564 {
2565 int i;
2566 UINT32 passkey = 0;
2567 int multi[] = {100000, 10000, 1000, 100, 10,1};
2568 BD_ADDR remote_bd_addr;
2569 bdcpy(remote_bd_addr, bd_addr->address);
2570 for (i = 0; i < 6; i++)
2571 {
2572 passkey += (multi[i] * (pin_code->pin[i] - '0'));
2573 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002574 BTIF_TRACE_DEBUG("btif_dm_pin_reply: passkey: %d", passkey);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002575 BTA_DmBlePasskeyReply(remote_bd_addr, accept, passkey);
2576
2577 }
2578 else
2579 {
2580 BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin);
2581 if (accept)
2582 pairing_cb.pin_code_len = pin_len;
2583 }
2584#else
The Android Open Source Project5738f832012-12-12 16:00:35 -08002585 BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin);
2586
2587 if (accept)
2588 pairing_cb.pin_code_len = pin_len;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002589#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002590 return BT_STATUS_SUCCESS;
2591}
2592
2593/*******************************************************************************
2594**
2595** Function btif_dm_ssp_reply
2596**
2597** Description BT SSP Reply - Just Works, Numeric Comparison & Passkey Entry
2598**
2599** Returns bt_status_t
2600**
2601*******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -08002602bt_status_t btif_dm_ssp_reply(const bt_bdaddr_t *bd_addr,
2603 bt_ssp_variant_t variant, uint8_t accept,
2604 uint32_t passkey)
2605{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002606 UNUSED(passkey);
2607
The Android Open Source Project5738f832012-12-12 16:00:35 -08002608 if (variant == BT_SSP_VARIANT_PASSKEY_ENTRY)
2609 {
2610 /* This is not implemented in the stack.
2611 * For devices with display, this is not needed
2612 */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002613 BTIF_TRACE_WARNING("%s: Not implemented", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002614 return BT_STATUS_FAIL;
2615 }
2616 /* BT_SSP_VARIANT_CONSENT & BT_SSP_VARIANT_PASSKEY_CONFIRMATION supported */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002617 BTIF_TRACE_EVENT("%s: accept=%d", __FUNCTION__, accept);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002618#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2619 if (pairing_cb.is_le_only)
2620 {
Satya Calloji7fb0da62015-01-29 20:40:17 -08002621 if(pairing_cb.is_le_nc)
2622 {
2623 BTA_DmBleConfirmReply((UINT8 *)bd_addr->address,accept);
2624 } else {
2625 if (accept)
2626 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_GRANTED);
2627 else
2628 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT);
2629 }
2630 } else {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002631 BTA_DmConfirm( (UINT8 *)bd_addr->address, accept);
Satya Calloji7fb0da62015-01-29 20:40:17 -08002632 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002633#else
2634 BTA_DmConfirm( (UINT8 *)bd_addr->address, accept);
2635#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002636 return BT_STATUS_SUCCESS;
2637}
2638
2639/*******************************************************************************
2640**
2641** Function btif_dm_get_adapter_property
2642**
2643** Description Queries the BTA for the adapter property
2644**
2645** Returns bt_status_t
2646**
2647*******************************************************************************/
2648bt_status_t btif_dm_get_adapter_property(bt_property_t *prop)
2649{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002650 BTIF_TRACE_EVENT("%s: type=0x%x", __FUNCTION__, prop->type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002651 switch (prop->type)
2652 {
2653 case BT_PROPERTY_BDNAME:
2654 {
2655 bt_bdname_t *bd_name = (bt_bdname_t*)prop->val;
VenkatRaghavan VijayaRaghavan4540f592015-02-05 04:40:47 -08002656 strncpy((char *)bd_name->name, (char *)btif_get_default_local_name(),
VenkatRaghavan VijayaRaghavan1d8e6b82015-02-05 22:20:39 -08002657 sizeof(bd_name->name) - 1);
2658 bd_name->name[sizeof(bd_name->name) - 1] = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002659 prop->len = strlen((char *)bd_name->name);
2660 }
2661 break;
2662
2663 case BT_PROPERTY_ADAPTER_SCAN_MODE:
2664 {
2665 /* if the storage does not have it. Most likely app never set it. Default is NONE */
2666 bt_scan_mode_t *mode = (bt_scan_mode_t*)prop->val;
2667 *mode = BT_SCAN_MODE_NONE;
2668 prop->len = sizeof(bt_scan_mode_t);
2669 }
2670 break;
2671
2672 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
2673 {
2674 uint32_t *tmt = (uint32_t*)prop->val;
2675 *tmt = 120; /* default to 120s, if not found in NV */
2676 prop->len = sizeof(uint32_t);
2677 }
2678 break;
2679
2680 default:
2681 prop->len = 0;
2682 return BT_STATUS_FAIL;
2683 }
2684 return BT_STATUS_SUCCESS;
2685}
2686
2687/*******************************************************************************
2688**
2689** Function btif_dm_get_remote_services
2690**
2691** Description Start SDP to get remote services
2692**
2693** Returns bt_status_t
2694**
2695*******************************************************************************/
2696bt_status_t btif_dm_get_remote_services(bt_bdaddr_t *remote_addr)
2697{
2698 bdstr_t bdstr;
2699
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002700 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 -08002701
2702 BTA_DmDiscover(remote_addr->address, BTA_ALL_SERVICE_MASK,
2703 bte_dm_search_services_evt, TRUE);
2704
2705 return BT_STATUS_SUCCESS;
2706}
2707
2708/*******************************************************************************
2709**
Nitin Arorab4365c52015-06-25 18:30:09 -07002710** Function btif_dm_get_remote_services_transport
2711**
2712** Description Start SDP to get remote services by transport
2713**
2714** Returns bt_status_t
2715**
2716*******************************************************************************/
2717bt_status_t btif_dm_get_remote_services_by_transport(bt_bdaddr_t *remote_addr, const int transport)
2718{
2719 BTIF_TRACE_EVENT("%s", __func__);
2720
2721 /* Set the mask extension */
2722 tBTA_SERVICE_MASK_EXT mask_ext;
2723 mask_ext.num_uuid = 0;
2724 mask_ext.p_uuid = NULL;
2725 mask_ext.srvc_mask = BTA_ALL_SERVICE_MASK;
2726
2727 BTA_DmDiscoverByTransport(remote_addr->address, &mask_ext,
2728 bte_dm_search_services_evt, TRUE, transport);
2729
2730 return BT_STATUS_SUCCESS;
2731}
2732
2733/*******************************************************************************
2734**
The Android Open Source Project5738f832012-12-12 16:00:35 -08002735** Function btif_dm_get_remote_service_record
2736**
2737** Description Start SDP to get remote service record
2738**
2739**
2740** Returns bt_status_t
2741*******************************************************************************/
2742bt_status_t btif_dm_get_remote_service_record(bt_bdaddr_t *remote_addr,
2743 bt_uuid_t *uuid)
2744{
2745 tSDP_UUID sdp_uuid;
2746 bdstr_t bdstr;
2747
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002748 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 -08002749
2750 sdp_uuid.len = MAX_UUID_SIZE;
2751 memcpy(sdp_uuid.uu.uuid128, uuid->uu, MAX_UUID_SIZE);
2752
2753 BTA_DmDiscoverUUID(remote_addr->address, &sdp_uuid,
2754 bte_dm_remote_service_record_evt, TRUE);
2755
2756 return BT_STATUS_SUCCESS;
2757}
2758
2759void btif_dm_execute_service_request(UINT16 event, char *p_param)
2760{
2761 BOOLEAN b_enable = FALSE;
2762 bt_status_t status;
2763 if (event == BTIF_DM_ENABLE_SERVICE)
2764 {
2765 b_enable = TRUE;
2766 }
2767 status = btif_in_execute_service_request(*((tBTA_SERVICE_ID*)p_param), b_enable);
2768 if (status == BT_STATUS_SUCCESS)
2769 {
2770 bt_property_t property;
2771 bt_uuid_t local_uuids[BT_MAX_NUM_UUIDS];
2772
2773 /* Now send the UUID_PROPERTY_CHANGED event to the upper layer */
2774 BTIF_STORAGE_FILL_PROPERTY(&property, BT_PROPERTY_UUIDS,
2775 sizeof(local_uuids), local_uuids);
2776 btif_storage_get_adapter_property(&property);
2777 HAL_CBACK(bt_hal_cbacks, adapter_properties_cb,
2778 BT_STATUS_SUCCESS, 1, &property);
2779 }
2780 return;
2781}
2782
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002783void btif_dm_proc_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, tBTA_OOB_DATA *p_oob_data,
2784 tBTA_AUTH_REQ *p_auth_req, BOOLEAN is_orig)
2785{
2786 UINT8 yes_no_bit = BTA_AUTH_SP_YES & *p_auth_req;
2787 /* if local initiated:
2788 ** 1. set DD + MITM
2789 ** if remote initiated:
2790 ** 1. Copy over the auth_req from peer's io_rsp
2791 ** 2. Set the MITM if peer has it set or if peer has DisplayYesNo (iPhone)
2792 ** as a fallback set MITM+GB if peer had MITM set
2793 */
2794 UNUSED (bd_addr);
2795 UNUSED (p_io_cap);
2796 UNUSED (p_oob_data);
2797
2798
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002799 BTIF_TRACE_DEBUG("+%s: p_auth_req=%d", __FUNCTION__, *p_auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002800 if(pairing_cb.is_local_initiated)
2801 {
2802 /* if initing/responding to a dedicated bonding, use dedicate bonding bit */
2803 *p_auth_req = BTA_AUTH_DD_BOND | BTA_AUTH_SP_YES;
2804 }
2805 else if (!is_orig)
2806 {
2807 /* peer initiated paring. They probably know what they want.
2808 ** Copy the mitm from peer device.
2809 */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002810 BTIF_TRACE_DEBUG("%s: setting p_auth_req to peer's: %d",
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002811 __FUNCTION__, pairing_cb.auth_req);
2812 *p_auth_req = (pairing_cb.auth_req & BTA_AUTH_BONDS);
2813
2814 /* copy over the MITM bit as well. In addition if the peer has DisplayYesNo, force MITM */
2815 if ((yes_no_bit) || (pairing_cb.io_cap & BTM_IO_CAP_IO) )
2816 *p_auth_req |= BTA_AUTH_SP_YES;
2817 }
2818 else if (yes_no_bit)
2819 {
2820 /* set the general bonding bit for stored device */
2821 *p_auth_req = BTA_AUTH_GEN_BOND | yes_no_bit;
2822 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002823 BTIF_TRACE_DEBUG("-%s: p_auth_req=%d", __FUNCTION__, *p_auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002824}
2825
2826void btif_dm_proc_io_rsp(BD_ADDR bd_addr, tBTA_IO_CAP io_cap,
2827 tBTA_OOB_DATA oob_data, tBTA_AUTH_REQ auth_req)
2828{
2829 UNUSED (bd_addr);
2830 UNUSED (oob_data);
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002831
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002832 if(auth_req & BTA_AUTH_BONDS)
2833 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002834 BTIF_TRACE_DEBUG("%s auth_req:%d", __FUNCTION__, auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002835 pairing_cb.auth_req = auth_req;
2836 pairing_cb.io_cap = io_cap;
2837 }
2838}
2839
The Android Open Source Project5738f832012-12-12 16:00:35 -08002840#if (BTM_OOB_INCLUDED == TRUE)
2841void btif_dm_set_oob_for_io_req(tBTA_OOB_DATA *p_oob_data)
2842{
2843 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2844 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
2845 {
2846 *p_oob_data = FALSE;
2847 }
2848 else
2849 {
2850 *p_oob_data = TRUE;
2851 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002852 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 -08002853}
2854#endif /* BTM_OOB_INCLUDED */
2855
2856#ifdef BTIF_DM_OOB_TEST
2857void btif_dm_load_local_oob(void)
2858{
Nick Kralevichd70b7a82013-01-31 14:40:15 -08002859 char prop_oob[PROPERTY_VALUE_MAX];
The Android Open Source Project5738f832012-12-12 16:00:35 -08002860 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002861 BTIF_TRACE_DEBUG("btif_dm_load_local_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002862 if (prop_oob[0] != '3')
2863 {
2864#if (BTM_OOB_INCLUDED == TRUE)
2865 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2866 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
2867 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002868 BTIF_TRACE_DEBUG("btif_dm_load_local_oob: read OOB, call BTA_DmLocalOob()");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002869 BTA_DmLocalOob();
2870 }
2871#else
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002872 BTIF_TRACE_ERROR("BTM_OOB_INCLUDED is FALSE!!(btif_dm_load_local_oob)");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002873#endif
2874 }
2875}
2876
2877void btif_dm_proc_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r)
2878{
2879 FILE *fp;
2880 char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
2881 char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
2882 char *path = NULL;
Nick Kralevichd70b7a82013-01-31 14:40:15 -08002883 char prop_oob[PROPERTY_VALUE_MAX];
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002884 BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob: valid=%d", valid);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002885 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2886 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 &&
2887 valid)
2888 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002889 BTIF_TRACE_DEBUG("save local OOB data in memory");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002890 memcpy(oob_cb.sp_c, c, BT_OCTET16_LEN);
2891 memcpy(oob_cb.sp_r, r, BT_OCTET16_LEN);
2892 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002893 BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002894 if (prop_oob[0] == '1')
2895 path = path_a;
2896 else if (prop_oob[0] == '2')
2897 path = path_b;
2898 if (path)
2899 {
2900 fp = fopen(path, "wb+");
2901 if (fp == NULL)
2902 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002903 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 -08002904 }
2905 else
2906 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002907 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 -08002908 fwrite (c , 1 , BT_OCTET16_LEN , fp );
2909 fwrite (r , 1 , BT_OCTET16_LEN , fp );
2910 fclose(fp);
2911 }
2912 }
2913 }
2914}
2915BOOLEAN btif_dm_proc_rmt_oob(BD_ADDR bd_addr, BT_OCTET16 p_c, BT_OCTET16 p_r)
2916{
2917 char t[128];
2918 FILE *fp;
2919 char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
2920 char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
2921 char *path = NULL;
Nick Kralevichd70b7a82013-01-31 14:40:15 -08002922 char prop_oob[PROPERTY_VALUE_MAX];
The Android Open Source Project5738f832012-12-12 16:00:35 -08002923 BOOLEAN result = FALSE;
2924 bt_bdaddr_t bt_bd_addr;
2925 bdcpy(oob_cb.oob_bdaddr, bd_addr);
2926 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002927 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002928 if (prop_oob[0] == '1')
2929 path = path_b;
2930 else if (prop_oob[0] == '2')
2931 path = path_a;
2932 if (path)
2933 {
2934 fp = fopen(path, "rb");
2935 if (fp == NULL)
2936 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002937 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 -08002938 return FALSE;
2939 }
2940 else
2941 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002942 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob: read OOB data from %s",path);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002943 fread (p_c , 1 , BT_OCTET16_LEN , fp );
2944 fread (p_r , 1 , BT_OCTET16_LEN , fp );
2945 fclose(fp);
2946 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002947 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: TRUE");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002948 sprintf(t, "%02x:%02x:%02x:%02x:%02x:%02x",
2949 oob_cb.oob_bdaddr[0], oob_cb.oob_bdaddr[1], oob_cb.oob_bdaddr[2],
2950 oob_cb.oob_bdaddr[3], oob_cb.oob_bdaddr[4], oob_cb.oob_bdaddr[5]);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002951 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: peer_bdaddr = %s", t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002952 sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
2953 p_c[0], p_c[1], p_c[2], p_c[3], p_c[4], p_c[5], p_c[6], p_c[7],
2954 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 -07002955 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: c = %s",t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002956 sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
2957 p_r[0], p_r[1], p_r[2], p_r[3], p_r[4], p_r[5], p_r[6], p_r[7],
2958 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 -07002959 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: r = %s",t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002960 bdcpy(bt_bd_addr.address, bd_addr);
2961 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_BOND_STATE_BONDING,
2962 (char *)&bt_bd_addr, sizeof(bt_bdaddr_t), NULL);
2963 result = TRUE;
2964 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002965 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob result=%d",result);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002966 return result;
2967}
2968#endif /* BTIF_DM_OOB_TEST */
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002969#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2970
2971static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif)
2972{
2973 bt_bdaddr_t bd_addr;
2974 bt_bdname_t bd_name;
2975 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08002976 int dev_type;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002977
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002978 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002979
2980 /* Remote name update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08002981 if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type))
2982 {
2983 dev_type = BT_DEVICE_TYPE_BLE;
2984 }
2985 btif_dm_update_ble_remote_properties(p_ssp_key_notif->bd_addr , p_ssp_key_notif->bd_name,
2986 (tBT_DEVICE_TYPE) dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002987 bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
2988 memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
2989
2990 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
2991 pairing_cb.is_ssp = FALSE;
2992 cod = COD_UNCLASSIFIED;
2993
2994 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
2995 cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION,
2996 p_ssp_key_notif->passkey);
2997}
2998
2999/*******************************************************************************
3000**
3001** Function btif_dm_ble_auth_cmpl_evt
3002**
3003** Description Executes authentication complete event in btif context
3004**
3005** Returns void
3006**
3007*******************************************************************************/
3008static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
3009{
3010 /* Save link key, if not temporary */
3011 bt_bdaddr_t bd_addr;
3012 bt_status_t status = BT_STATUS_FAIL;
3013 bt_bond_state_t state = BT_BOND_STATE_NONE;
3014
3015 bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
3016 if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
3017 {
3018 /* store keys */
3019 }
3020 if (p_auth_cmpl->success)
3021 {
3022 status = BT_STATUS_SUCCESS;
3023 state = BT_BOND_STATE_BONDED;
Satya Calloji7cb76b42015-05-07 09:45:00 -07003024 int addr_type;
3025 bt_bdaddr_t bdaddr;
3026 bdcpy(bdaddr.address, p_auth_cmpl->bd_addr);
3027 if (btif_storage_get_remote_addr_type(&bdaddr, &addr_type) != BT_STATUS_SUCCESS)
3028 btif_storage_set_remote_addr_type(&bdaddr, p_auth_cmpl->addr_type);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07003029
3030 /* Test for temporary bonding */
3031 if (btm_get_bond_type_dev(p_auth_cmpl->bd_addr) == BOND_TYPE_TEMPORARY) {
3032 BTIF_TRACE_DEBUG("%s: sending BT_BOND_STATE_NONE for Temp pairing",
3033 __func__);
3034 btif_storage_remove_bonded_device(&bdaddr);
3035 state = BT_BOND_STATE_NONE;
3036 } else {
3037 btif_dm_save_ble_bonding_keys();
3038 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003039 BTA_GATTC_Refresh(bd_addr.address);
Nitin Arorab4365c52015-06-25 18:30:09 -07003040 btif_dm_get_remote_services_by_transport(&bd_addr, BTA_GATT_TRANSPORT_LE);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003041 }
3042 else
3043 {
3044 /*Map the HCI fail reason to bt status */
3045 switch (p_auth_cmpl->fail_reason)
3046 {
Priti Aghera156c52b2014-07-09 14:58:19 -07003047 case BTA_DM_AUTH_SMP_PAIR_AUTH_FAIL:
3048 case BTA_DM_AUTH_SMP_CONFIRM_VALUE_FAIL:
3049 btif_dm_remove_ble_bonding_keys();
3050 status = BT_STATUS_AUTH_FAILURE;
3051 break;
3052 case BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT:
3053 status = BT_STATUS_AUTH_REJECTED;
3054 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003055 default:
Andre Eisenbachca22ac42013-02-13 17:02:11 +09003056 btif_dm_remove_ble_bonding_keys();
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003057 status = BT_STATUS_FAIL;
3058 break;
3059 }
3060 }
3061 bond_state_changed(status, &bd_addr, state);
3062}
3063
3064
3065
3066void btif_dm_load_ble_local_keys(void)
3067{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003068 memset(&ble_local_key_cb, 0, sizeof(btif_dm_local_key_cb_t));
3069
3070 if (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_ER,(char*)&ble_local_key_cb.er[0],
3071 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)
3072 {
3073 ble_local_key_cb.is_er_rcvd = TRUE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003074 BTIF_TRACE_DEBUG("%s BLE ER key loaded",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003075 }
3076
3077 if ((btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IR,(char*)&ble_local_key_cb.id_keys.ir[0],
3078 BT_OCTET16_LEN)== BT_STATUS_SUCCESS )&&
3079 (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IRK, (char*)&ble_local_key_cb.id_keys.irk[0],
3080 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)&&
3081 (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_DHK,(char*)&ble_local_key_cb.id_keys.dhk[0],
3082 BT_OCTET16_LEN)== BT_STATUS_SUCCESS))
3083 {
3084 ble_local_key_cb.is_id_keys_rcvd = TRUE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003085 BTIF_TRACE_DEBUG("%s BLE ID keys loaded",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003086 }
3087
3088}
3089void btif_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
3090 tBTA_BLE_LOCAL_ID_KEYS *p_id_keys)
3091{
3092 if (ble_local_key_cb.is_er_rcvd )
3093 {
3094 memcpy(&er[0], &ble_local_key_cb.er[0], sizeof(BT_OCTET16));
3095 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ER;
3096 }
3097
3098 if (ble_local_key_cb.is_id_keys_rcvd)
3099 {
3100 memcpy(&p_id_keys->ir[0], &ble_local_key_cb.id_keys.ir[0], sizeof(BT_OCTET16));
3101 memcpy(&p_id_keys->irk[0], &ble_local_key_cb.id_keys.irk[0], sizeof(BT_OCTET16));
3102 memcpy(&p_id_keys->dhk[0], &ble_local_key_cb.id_keys.dhk[0], sizeof(BT_OCTET16));
3103 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID;
3104 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003105 BTIF_TRACE_DEBUG("%s *p_key_mask=0x%02x",__FUNCTION__, *p_key_mask);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003106}
3107
3108void btif_dm_save_ble_bonding_keys(void)
3109{
3110
3111 bt_bdaddr_t bd_addr;
3112
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003113 BTIF_TRACE_DEBUG("%s",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003114
3115 bdcpy(bd_addr.address, pairing_cb.bd_addr);
3116
3117 if (pairing_cb.ble.is_penc_key_rcvd)
3118 {
3119 btif_storage_add_ble_bonding_key(&bd_addr,
3120 (char *) &pairing_cb.ble.penc_key,
3121 BTIF_DM_LE_KEY_PENC,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003122 sizeof(tBTM_LE_PENC_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003123 }
3124
3125 if (pairing_cb.ble.is_pid_key_rcvd)
3126 {
3127 btif_storage_add_ble_bonding_key(&bd_addr,
Andre Eisenbach5e808462014-10-21 12:37:53 -07003128 (char *) &pairing_cb.ble.pid_key,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003129 BTIF_DM_LE_KEY_PID,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003130 sizeof(tBTM_LE_PID_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003131 }
3132
3133
3134 if (pairing_cb.ble.is_pcsrk_key_rcvd)
3135 {
3136 btif_storage_add_ble_bonding_key(&bd_addr,
3137 (char *) &pairing_cb.ble.pcsrk_key,
3138 BTIF_DM_LE_KEY_PCSRK,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003139 sizeof(tBTM_LE_PCSRK_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003140 }
3141
3142
3143 if (pairing_cb.ble.is_lenc_key_rcvd)
3144 {
3145 btif_storage_add_ble_bonding_key(&bd_addr,
3146 (char *) &pairing_cb.ble.lenc_key,
3147 BTIF_DM_LE_KEY_LENC,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003148 sizeof(tBTM_LE_LENC_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003149 }
3150
3151 if (pairing_cb.ble.is_lcsrk_key_rcvd)
3152 {
3153 btif_storage_add_ble_bonding_key(&bd_addr,
3154 (char *) &pairing_cb.ble.lcsrk_key,
3155 BTIF_DM_LE_KEY_LCSRK,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003156 sizeof(tBTM_LE_LCSRK_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003157 }
3158
Satya Calloji444a8da2015-03-06 10:38:22 -08003159 if (pairing_cb.ble.is_lidk_key_rcvd)
3160 {
3161 btif_storage_add_ble_bonding_key(&bd_addr,
3162 NULL,
3163 BTIF_DM_LE_KEY_LID,
3164 0);
3165 }
3166
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003167}
3168
3169
3170void btif_dm_remove_ble_bonding_keys(void)
3171{
3172 bt_bdaddr_t bd_addr;
3173
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003174 BTIF_TRACE_DEBUG("%s",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003175
3176 bdcpy(bd_addr.address, pairing_cb.bd_addr);
3177 btif_storage_remove_ble_bonding_keys(&bd_addr);
3178}
3179
3180
3181/*******************************************************************************
3182**
3183** Function btif_dm_ble_sec_req_evt
3184**
3185** Description Eprocess security request event in btif context
3186**
3187** Returns void
3188**
3189*******************************************************************************/
3190void btif_dm_ble_sec_req_evt(tBTA_DM_BLE_SEC_REQ *p_ble_req)
3191{
3192 bt_bdaddr_t bd_addr;
3193 bt_bdname_t bd_name;
3194 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08003195 int dev_type;
3196
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003197 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003198
3199 if (pairing_cb.state == BT_BOND_STATE_BONDING)
3200 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003201 BTIF_TRACE_DEBUG("%s Discard security request", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003202 return;
3203 }
3204
3205 /* Remote name update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08003206 if (!btif_get_device_type(p_ble_req->bd_addr, &dev_type))
3207 {
3208 dev_type = BT_DEVICE_TYPE_BLE;
3209 }
3210 btif_dm_update_ble_remote_properties(p_ble_req->bd_addr, p_ble_req->bd_name,
3211 (tBT_DEVICE_TYPE) dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003212
3213 bdcpy(bd_addr.address, p_ble_req->bd_addr);
3214 memcpy(bd_name.name, p_ble_req->bd_name, BD_NAME_LEN);
3215
3216 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
3217
Andre Eisenbach89363762015-01-26 13:49:36 -08003218 pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003219 pairing_cb.is_le_only = TRUE;
Satya Calloji7fb0da62015-01-29 20:40:17 -08003220 pairing_cb.is_le_nc = FALSE;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003221 pairing_cb.is_ssp = TRUE;
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07003222 btm_set_bond_type_dev(p_ble_req->bd_addr, pairing_cb.bond_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003223
3224 cod = COD_UNCLASSIFIED;
3225
3226 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod,
3227 BT_SSP_VARIANT_CONSENT, 0);
3228}
3229
3230
3231
3232/*******************************************************************************
3233**
3234** Function btif_dm_ble_passkey_req_evt
3235**
3236** Description Executes pin request event in btif context
3237**
3238** Returns void
3239**
3240*******************************************************************************/
3241static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
3242{
3243 bt_bdaddr_t bd_addr;
3244 bt_bdname_t bd_name;
3245 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08003246 int dev_type;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003247
3248 /* Remote name update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08003249 if (!btif_get_device_type(p_pin_req->bd_addr, &dev_type))
3250 {
3251 dev_type = BT_DEVICE_TYPE_BLE;
3252 }
3253 btif_dm_update_ble_remote_properties(p_pin_req->bd_addr,p_pin_req->bd_name,
3254 (tBT_DEVICE_TYPE) dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003255
3256 bdcpy(bd_addr.address, p_pin_req->bd_addr);
3257 memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN);
3258
3259 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
3260 pairing_cb.is_le_only = TRUE;
3261
3262 cod = COD_UNCLASSIFIED;
3263
3264 HAL_CBACK(bt_hal_cbacks, pin_request_cb,
Casper Bonde818d0f22015-05-21 11:08:45 +02003265 &bd_addr, &bd_name, cod, FALSE);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003266}
Satya Calloji444a8da2015-03-06 10:38:22 -08003267static void btif_dm_ble_key_nc_req_evt(tBTA_DM_SP_KEY_NOTIF *p_notif_req)
3268{
3269 /* TODO implement key notification for numeric comparison */
3270 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003271
Satya Calloji444a8da2015-03-06 10:38:22 -08003272 /* Remote name update */
3273 btif_update_remote_properties(p_notif_req->bd_addr , p_notif_req->bd_name,
3274 NULL, BT_DEVICE_TYPE_BLE);
3275
3276 bt_bdaddr_t bd_addr;
3277 bdcpy(bd_addr.address, p_notif_req->bd_addr);
3278
3279 bt_bdname_t bd_name;
3280 memcpy(bd_name.name, p_notif_req->bd_name, BD_NAME_LEN);
3281
3282 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
3283 pairing_cb.is_ssp = FALSE;
Satya Calloji7fb0da62015-01-29 20:40:17 -08003284 pairing_cb.is_le_only = TRUE;
3285 pairing_cb.is_le_nc = TRUE;
Satya Calloji444a8da2015-03-06 10:38:22 -08003286
3287 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
3288 COD_UNCLASSIFIED, BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
3289 p_notif_req->passkey);
3290}
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003291
3292void btif_dm_update_ble_remote_properties( BD_ADDR bd_addr, BD_NAME bd_name,
3293 tBT_DEVICE_TYPE dev_type)
3294{
3295 btif_update_remote_properties(bd_addr,bd_name,NULL,dev_type);
3296}
3297
3298static void btif_dm_ble_tx_test_cback(void *p)
3299{
3300 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TX_TEST,
3301 (char *)p, 1, NULL);
3302}
3303
3304static void btif_dm_ble_rx_test_cback(void *p)
3305{
3306 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_RX_TEST,
3307 (char *)p, 1, NULL);
3308}
3309
3310static void btif_dm_ble_test_end_cback(void *p)
3311{
3312 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TEST_END,
3313 (char *)p, 3, NULL);
3314}
3315/*******************************************************************************
3316**
3317** Function btif_le_test_mode
3318**
3319** Description Sends a HCI BLE Test command to the Controller
3320**
3321** Returns BT_STATUS_SUCCESS on success
3322**
3323*******************************************************************************/
3324bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t len)
3325{
3326 switch (opcode) {
3327 case HCI_BLE_TRANSMITTER_TEST:
3328 if (len != 3) return BT_STATUS_PARM_INVALID;
3329 BTM_BleTransmitterTest(buf[0],buf[1],buf[2], btif_dm_ble_tx_test_cback);
3330 break;
3331 case HCI_BLE_RECEIVER_TEST:
3332 if (len != 1) return BT_STATUS_PARM_INVALID;
3333 BTM_BleReceiverTest(buf[0], btif_dm_ble_rx_test_cback);
3334 break;
3335 case HCI_BLE_TEST_END:
3336 BTM_BleTestEnd((tBTM_CMPL_CB*) btif_dm_ble_test_end_cback);
3337 break;
3338 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003339 BTIF_TRACE_ERROR("%s: Unknown LE Test Mode Command 0x%x", __FUNCTION__, opcode);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003340 return BT_STATUS_UNSUPPORTED;
3341 }
3342 return BT_STATUS_SUCCESS;
3343}
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003344#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08003345
3346void btif_dm_on_disable()
3347{
3348 /* cancel any pending pairing requests */
3349 if (pairing_cb.state == BT_BOND_STATE_BONDING)
3350 {
3351 bt_bdaddr_t bd_addr;
3352
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003353 BTIF_TRACE_DEBUG("%s: Cancel pending pairing request", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003354 bdcpy(bd_addr.address, pairing_cb.bd_addr);
3355 btif_dm_cancel_bond(&bd_addr);
3356 }
3357}
Matthew Xie1e5109b2012-11-09 18:26:26 -08003358
Satya Callojie5ba8842014-07-03 17:18:02 -07003359/*******************************************************************************
3360**
3361** Function btif_dm_read_energy_info
3362**
3363** Description Reads the energy info from controller
3364**
3365** Returns void
3366**
3367*******************************************************************************/
3368void btif_dm_read_energy_info()
3369{
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07003370#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Satya Callojie5ba8842014-07-03 17:18:02 -07003371 BTA_DmBleGetEnergyInfo(bta_energy_info_cb);
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07003372#endif
Satya Callojie5ba8842014-07-03 17:18:02 -07003373}
3374
Matthew Xie1e5109b2012-11-09 18:26:26 -08003375static char* btif_get_default_local_name() {
3376 if (btif_default_local_name[0] == '\0')
3377 {
3378 int max_len = sizeof(btif_default_local_name) - 1;
3379 if (BTM_DEF_LOCAL_NAME[0] != '\0')
3380 {
3381 strncpy(btif_default_local_name, BTM_DEF_LOCAL_NAME, max_len);
3382 }
3383 else
3384 {
3385 char prop_model[PROPERTY_VALUE_MAX];
3386 property_get(PROPERTY_PRODUCT_MODEL, prop_model, "");
3387 strncpy(btif_default_local_name, prop_model, max_len);
3388 }
3389 btif_default_local_name[max_len] = '\0';
3390 }
3391 return btif_default_local_name;
3392}