blob: 03e38d7a99747cdf26b1c5dd2978fe194373acd3 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
Hemant Gupta94c15ec2013-11-11 12:33:44 +05303 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
4 * Not a Contribution.
The Android Open Source Project5738f832012-12-12 16:00:35 -08005 * Copyright (C) 2009-2012 Broadcom Corporation
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at:
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ******************************************************************************/
20
21/************************************************************************************
22 *
23 * Filename: btif_dm.c
24 *
25 * Description: Contains Device Management (DM) related functionality
26 *
27 *
28 ***********************************************************************************/
Sharvil Nanavati44802762014-12-23 23:08:58 -080029
Chris Mantonf8027002015-03-12 09:22:48 -070030#define LOG_TAG "bt_btif_dm"
Sharvil Nanavati44802762014-12-23 23:08:58 -080031
Andre Eisenbach8a057242015-04-29 22:27:15 -070032#include <assert.h>
Scott James Remnant933926c2015-04-02 15:22:14 -070033#include <signal.h>
The Android Open Source Project5738f832012-12-12 16:00:35 -080034#include <stdio.h>
35#include <stdlib.h>
Ian Coolidgec7503db2015-01-24 02:01:26 -080036#include <string.h>
Scott James Remnant933926c2015-04-02 15:22:14 -070037#include <sys/types.h>
The Android Open Source Project5738f832012-12-12 16:00:35 -080038#include <unistd.h>
39
40#include <hardware/bluetooth.h>
41
The Android Open Source Project5738f832012-12-12 16:00:35 -080042#include <cutils/properties.h>
43#include "gki.h"
44#include "btu.h"
Sharvil Nanavati95b74f22015-03-12 15:55:21 -070045#include "btcore/include/bdaddr.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080046#include "bta_api.h"
47#include "btif_api.h"
48#include "btif_util.h"
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080049#include "btif_dm.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080050#include "btif_storage.h"
51#include "btif_hh.h"
Hemant Gupta94c15ec2013-11-11 12:33:44 +053052#include "btif_hd.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080053#include "btif_config.h"
Kim Schulz8372aa52015-03-25 10:39:40 +010054#include "btif_sdp.h"
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080055#include "bta_gatt_api.h"
Andre Eisenbach27c4e632015-07-06 15:43:15 -070056#include "device/include/interop.h"
Sharvil Nanavati44802762014-12-23 23:08:58 -080057#include "include/stack_config.h"
58#include "osi/include/log.h"
Andre Eisenbach8a057242015-04-29 22:27:15 -070059#include "osi/include/allocator.h"
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -070060#include "stack/btm/btm_int.h"
Andre Eisenbach31a64002014-10-14 14:29:19 -070061
62/******************************************************************************
The Android Open Source Project5738f832012-12-12 16:00:35 -080063** Constants & Macros
64******************************************************************************/
65
66#define COD_UNCLASSIFIED ((0x1F) << 8)
Priti Agheraebb1d752012-11-27 18:03:22 -080067#define COD_HID_KEYBOARD 0x0540
68#define COD_HID_POINTING 0x0580
69#define COD_HID_COMBO 0x05C0
70#define COD_HID_MAJOR 0x0500
71#define COD_AV_HEADSETS 0x0404
72#define COD_AV_HANDSFREE 0x0408
73#define COD_AV_HEADPHONES 0x0418
74#define COD_AV_PORTABLE_AUDIO 0x041C
75#define COD_AV_HIFI_AUDIO 0x0428
The Android Open Source Project5738f832012-12-12 16:00:35 -080076
77
78#define BTIF_DM_DEFAULT_INQ_MAX_RESULTS 0
79#define BTIF_DM_DEFAULT_INQ_MAX_DURATION 10
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -070080#define BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING 2
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080081
Andre Eisenbach31a64002014-10-14 14:29:19 -070082#define NUM_TIMEOUT_RETRIES 5
83
Matthew Xie1e5109b2012-11-09 18:26:26 -080084#define PROPERTY_PRODUCT_MODEL "ro.product.model"
Matthew Xiea30d95a2013-09-18 12:30:36 -070085#define DEFAULT_LOCAL_NAME_MAX 31
Matthew Xie1e5109b2012-11-09 18:26:26 -080086#if (DEFAULT_LOCAL_NAME_MAX > BTM_MAX_LOC_BD_NAME_LEN)
87 #error "default btif local name size exceeds stack supported length"
88#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080089
Matthew Xie7f3e4292013-09-30 12:44:10 -070090#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
91#define BTIF_DM_INTERLEAVE_DURATION_BR_ONE 2
92#define BTIF_DM_INTERLEAVE_DURATION_LE_ONE 2
93#define BTIF_DM_INTERLEAVE_DURATION_BR_TWO 3
94#define BTIF_DM_INTERLEAVE_DURATION_LE_TWO 4
95#endif
96
Priti Agherac0edf9f2014-06-26 11:23:51 -070097#define MAX_SDP_BL_ENTRIES 3
98
Andre Eisenbachdfb3b2f2015-02-05 20:00:45 -080099#define ENCRYPTED_BREDR 2
100#define ENCRYPTED_LE 4
101
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800102typedef struct
103{
The Android Open Source Project5738f832012-12-12 16:00:35 -0800104 bt_bond_state_t state;
Andre Eisenbach12871662015-05-08 17:42:10 -0700105 bt_bdaddr_t static_bdaddr;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800106 BD_ADDR bd_addr;
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -0700107 tBTM_BOND_TYPE bond_type;
Chaojing Sune2805532015-04-22 13:40:21 -0700108 UINT8 pin_code_len;
109 UINT8 is_ssp;
110 UINT8 auth_req;
111 UINT8 io_cap;
112 UINT8 autopair_attempts;
113 UINT8 timeout_retries;
114 UINT8 is_local_initiated;
115 UINT8 sdp_attempts;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800116#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Chaojing Sune2805532015-04-22 13:40:21 -0700117 BOOLEAN is_le_only;
118 BOOLEAN is_le_nc; /* LE Numeric comparison */
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800119 btif_dm_ble_cb_t ble;
120#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800121} btif_dm_pairing_cb_t;
122
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800123
124typedef struct
125{
126 UINT8 ir[BT_OCTET16_LEN];
127 UINT8 irk[BT_OCTET16_LEN];
128 UINT8 dhk[BT_OCTET16_LEN];
129}btif_dm_local_key_id_t;
130
131typedef struct
132{
133 BOOLEAN is_er_rcvd;
134 UINT8 er[BT_OCTET16_LEN];
135 BOOLEAN is_id_keys_rcvd;
136 btif_dm_local_key_id_t id_keys; /* ID kyes */
137
138}btif_dm_local_key_cb_t;
139
140typedef struct
141{
The Android Open Source Project5738f832012-12-12 16:00:35 -0800142 BD_ADDR bd_addr;
143 BD_NAME bd_name;
144} btif_dm_remote_name_t;
145
146typedef struct
147{
148 BT_OCTET16 sp_c;
149 BT_OCTET16 sp_r;
150 BD_ADDR oob_bdaddr; /* peer bdaddr*/
151} btif_dm_oob_cb_t;
Satya Callojie5ba8842014-07-03 17:18:02 -0700152
153typedef struct
154{
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -0700155 bt_bdaddr_t bdaddr;
156 UINT8 transport; /* 0=Unknown, 1=BR/EDR, 2=LE */
157} btif_dm_create_bond_cb_t;
158
159typedef struct
160{
Satya Callojie5ba8842014-07-03 17:18:02 -0700161 uint8_t status;
162 uint8_t ctrl_state;
163 uint64_t tx_time;
164 uint64_t rx_time;
165 uint64_t idle_time;
166 uint64_t energy_used;
167} btif_activity_energy_info_cb_t;
168
The Android Open Source Project5738f832012-12-12 16:00:35 -0800169#define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id))
170
Priti Agherac0edf9f2014-06-26 11:23:51 -0700171#define UUID_HUMAN_INTERFACE_DEVICE "00001124-0000-1000-8000-00805f9b34fb"
172
The Android Open Source Project5738f832012-12-12 16:00:35 -0800173/* This flag will be true if HCI_Inquiry is in progress */
174static BOOLEAN btif_dm_inquiry_in_progress = FALSE;
175
Matthew Xie1e5109b2012-11-09 18:26:26 -0800176/************************************************************************************
177** Static variables
178************************************************************************************/
179static char btif_default_local_name[DEFAULT_LOCAL_NAME_MAX+1] = {'\0'};
180
The Android Open Source Project5738f832012-12-12 16:00:35 -0800181/******************************************************************************
182** Static functions
183******************************************************************************/
184static btif_dm_pairing_cb_t pairing_cb;
185static btif_dm_oob_cb_t oob_cb;
186static void btif_dm_generic_evt(UINT16 event, char* p_param);
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -0700187static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr, tBTA_TRANSPORT transport);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800188static void btif_dm_cb_hid_remote_name(tBTM_REMOTE_DEV_NAME *p_remote_name);
189static void btif_update_remote_properties(BD_ADDR bd_addr, BD_NAME bd_name,
190 DEV_CLASS dev_class, tBT_DEVICE_TYPE dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800191#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
192static btif_dm_local_key_cb_t ble_local_key_cb;
193static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif);
194static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl);
195static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ *p_pin_req);
Satya Calloji444a8da2015-03-06 10:38:22 -0800196static void btif_dm_ble_key_nc_req_evt(tBTA_DM_SP_KEY_NOTIF *p_notif_req) ;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800197#endif
Satya Calloji6e2d9db2014-07-08 16:18:58 -0700198
199static void bte_scan_filt_param_cfg_evt(UINT8 action_type,
200 tBTA_DM_BLE_PF_AVBL_SPACE avbl_space,
201 tBTA_DM_BLE_REF_VALUE ref_value, tBTA_STATUS status);
202
Matthew Xie1e5109b2012-11-09 18:26:26 -0800203static char* btif_get_default_local_name();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800204/******************************************************************************
205** Externs
206******************************************************************************/
207extern UINT16 bta_service_id_to_uuid_lkup_tbl [BTA_MAX_SERVICE_ID];
208extern bt_status_t btif_hf_execute_service(BOOLEAN b_enable);
209extern bt_status_t btif_av_execute_service(BOOLEAN b_enable);
Rakesh Iyer9c8dfac2015-04-08 12:25:37 -0700210extern bt_status_t btif_av_sink_execute_service(BOOLEAN b_enable);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800211extern bt_status_t btif_hh_execute_service(BOOLEAN b_enable);
Hemant Gupta10256872013-08-19 18:33:01 +0530212extern bt_status_t btif_hf_client_execute_service(BOOLEAN b_enable);
Kim Schulz8372aa52015-03-25 10:39:40 +0100213extern bt_status_t btif_sdp_execute_service(BOOLEAN b_enable);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800214extern int btif_hh_connect(bt_bdaddr_t *bd_addr);
Hemant Gupta94c15ec2013-11-11 12:33:44 +0530215extern bt_status_t btif_hd_execute_service(BOOLEAN b_enable);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700216extern void bta_gatt_convert_uuid16_to_uuid128(UINT8 uuid_128[LEN_UUID_128], UINT16 uuid_16);
Anubhav Gupta791692a2013-12-06 17:11:11 +0530217extern void btif_av_move_idle(bt_bdaddr_t bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800218
219
220/******************************************************************************
221** Functions
222******************************************************************************/
223
Andre Eisenbach8a057242015-04-29 22:27:15 -0700224static void btif_dm_data_copy(uint16_t event, char *dst, char *src)
225{
226 tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC*)dst;
227 tBTA_DM_SEC *src_dm_sec = (tBTA_DM_SEC*)src;
228
229 if (!src_dm_sec)
230 return;
231
232 assert(dst_dm_sec);
233 memcpy(dst_dm_sec, src_dm_sec, sizeof(tBTA_DM_SEC));
234
235 if (event == BTA_DM_BLE_KEY_EVT)
236 {
237 dst_dm_sec->ble_key.p_key_value = osi_malloc(sizeof(tBTM_LE_KEY_VALUE));
238 assert(src_dm_sec->ble_key.p_key_value);
239 assert(dst_dm_sec->ble_key.p_key_value);
240 memcpy(dst_dm_sec->ble_key.p_key_value, src_dm_sec->ble_key.p_key_value, sizeof(tBTM_LE_KEY_VALUE));
241 }
242}
243
244static void btif_dm_data_free(uint16_t event, tBTA_DM_SEC *dm_sec)
245{
246 if (event == BTA_DM_BLE_KEY_EVT)
247 osi_free(dm_sec->ble_key.p_key_value);
248}
249
The Android Open Source Project5738f832012-12-12 16:00:35 -0800250bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id,
251 BOOLEAN b_enable)
252{
Kim Schulz8372aa52015-03-25 10:39:40 +0100253 BTIF_TRACE_DEBUG("%s service_id: %d", __FUNCTION__, service_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800254 /* Check the service_ID and invoke the profile's BT state changed API */
255 switch (service_id)
256 {
257 case BTA_HFP_SERVICE_ID:
258 case BTA_HSP_SERVICE_ID:
259 {
260 btif_hf_execute_service(b_enable);
261 }break;
Sharvil Nanavati9609cee2014-10-15 18:30:49 -0700262 case BTA_A2DP_SOURCE_SERVICE_ID:
The Android Open Source Project5738f832012-12-12 16:00:35 -0800263 {
264 btif_av_execute_service(b_enable);
265 }break;
Rakesh Iyer9c8dfac2015-04-08 12:25:37 -0700266 case BTA_A2DP_SINK_SERVICE_ID:
267 {
268 btif_av_sink_execute_service(b_enable);
269 }break;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800270 case BTA_HID_SERVICE_ID:
271 {
272 btif_hh_execute_service(b_enable);
273 }break;
Hemant Gupta10256872013-08-19 18:33:01 +0530274 case BTA_HFP_HS_SERVICE_ID:
275 {
276 btif_hf_client_execute_service(b_enable);
277 }break;
Kim Schulz8372aa52015-03-25 10:39:40 +0100278 case BTA_SDP_SERVICE_ID:
Hemant Gupta2dc99992014-04-18 12:54:08 +0530279 {
Kim Schulz8372aa52015-03-25 10:39:40 +0100280 btif_sdp_execute_service(b_enable);
Hemant Gupta2dc99992014-04-18 12:54:08 +0530281 }break;
Hemant Gupta94c15ec2013-11-11 12:33:44 +0530282 case BTA_HIDD_SERVICE_ID:
283 {
284 btif_hd_execute_service(b_enable);
285 }break;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800286 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700287 BTIF_TRACE_ERROR("%s: Unknown service being enabled", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800288 return BT_STATUS_FAIL;
289 }
290 return BT_STATUS_SUCCESS;
291}
292
293/*******************************************************************************
294**
295** Function check_eir_remote_name
296**
297** Description Check if remote name is in the EIR data
298**
299** Returns TRUE if remote name found
300** Populate p_remote_name, if provided and remote name found
301**
302*******************************************************************************/
303static BOOLEAN check_eir_remote_name(tBTA_DM_SEARCH *p_search_data,
304 UINT8 *p_remote_name, UINT8 *p_remote_name_len)
305{
306 UINT8 *p_eir_remote_name = NULL;
307 UINT8 remote_name_len = 0;
308
309 /* Check EIR for remote name and services */
310 if (p_search_data->inq_res.p_eir)
311 {
Zach Johnsona50fc882014-10-30 21:02:58 -0700312 p_eir_remote_name = BTM_CheckEirData(p_search_data->inq_res.p_eir,
The Android Open Source Project5738f832012-12-12 16:00:35 -0800313 BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, &remote_name_len);
314 if (!p_eir_remote_name)
315 {
Zach Johnsona50fc882014-10-30 21:02:58 -0700316 p_eir_remote_name = BTM_CheckEirData(p_search_data->inq_res.p_eir,
The Android Open Source Project5738f832012-12-12 16:00:35 -0800317 BTM_EIR_SHORTENED_LOCAL_NAME_TYPE, &remote_name_len);
318 }
319
320 if (p_eir_remote_name)
321 {
322 if (remote_name_len > BD_NAME_LEN)
323 remote_name_len = BD_NAME_LEN;
324
325 if (p_remote_name && p_remote_name_len)
326 {
327 memcpy(p_remote_name, p_eir_remote_name, remote_name_len);
328 *(p_remote_name + remote_name_len) = 0;
329 *p_remote_name_len = remote_name_len;
330 }
331
332 return TRUE;
333 }
334 }
335
336 return FALSE;
337
338}
339
340/*******************************************************************************
341**
342** Function check_cached_remote_name
343**
344** Description Check if remote name is in the NVRAM cache
345**
346** Returns TRUE if remote name found
347** Populate p_remote_name, if provided and remote name found
348**
349*******************************************************************************/
350static BOOLEAN check_cached_remote_name(tBTA_DM_SEARCH *p_search_data,
351 UINT8 *p_remote_name, UINT8 *p_remote_name_len)
352{
353 bt_bdname_t bdname;
354 bt_bdaddr_t remote_bdaddr;
355 bt_property_t prop_name;
356
357 /* check if we already have it in our btif_storage cache */
358 bdcpy(remote_bdaddr.address, p_search_data->inq_res.bd_addr);
359 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_BDNAME,
360 sizeof(bt_bdname_t), &bdname);
361 if (btif_storage_get_remote_device_property(
362 &remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS)
363 {
364 if (p_remote_name && p_remote_name_len)
365 {
366 strcpy((char *)p_remote_name, (char *)bdname.name);
367 *p_remote_name_len = strlen((char *)p_remote_name);
368 }
369 return TRUE;
370 }
371
372 return FALSE;
373}
374
375BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod)
376{
377 uint32_t remote_cod;
378 bt_property_t prop_name;
379
380 /* check if we already have it in our btif_storage cache */
381 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE,
382 sizeof(uint32_t), &remote_cod);
383 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS)
384 {
Chris Mantonf8027002015-03-12 09:22:48 -0700385 LOG_INFO("%s remote_cod = 0x%08x cod = 0x%08x", __func__, remote_cod, cod);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800386 if ((remote_cod & 0x7ff) == cod)
387 return TRUE;
388 }
389
390 return FALSE;
391}
392
Priti Agheraebb1d752012-11-27 18:03:22 -0800393BOOLEAN check_cod_hid(const bt_bdaddr_t *remote_bdaddr, uint32_t cod)
394{
395 uint32_t remote_cod;
396 bt_property_t prop_name;
397
398 /* check if we already have it in our btif_storage cache */
399 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE,
400 sizeof(uint32_t), &remote_cod);
401 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
402 &prop_name) == BT_STATUS_SUCCESS)
403 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700404 BTIF_TRACE_DEBUG("%s: remote_cod = 0x%06x", __FUNCTION__, remote_cod);
Hemant Guptae4def912014-09-18 14:19:57 +0530405 if ((remote_cod & 0x700) == cod) {
406 BTIF_TRACE_DEBUG("%s: returning TRUE", __FUNCTION__);
Priti Agheraebb1d752012-11-27 18:03:22 -0800407 return TRUE;
Hemant Guptae4def912014-09-18 14:19:57 +0530408 }
Priti Agheraebb1d752012-11-27 18:03:22 -0800409 }
Hemant Guptae4def912014-09-18 14:19:57 +0530410 BTIF_TRACE_DEBUG("%s: returning FALSE", __FUNCTION__);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700411 return FALSE;
412}
Priti Agheraebb1d752012-11-27 18:03:22 -0800413
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700414BOOLEAN check_hid_le(const bt_bdaddr_t *remote_bdaddr)
415{
416 uint32_t remote_dev_type;
417 bt_property_t prop_name;
418
419 /* check if we already have it in our btif_storage cache */
420 BTIF_STORAGE_FILL_PROPERTY(&prop_name,BT_PROPERTY_TYPE_OF_DEVICE,
421 sizeof(uint32_t), &remote_dev_type);
422 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
423 &prop_name) == BT_STATUS_SUCCESS)
424 {
425 if (remote_dev_type == BT_DEVICE_DEVTYPE_BLE)
426 {
427 bdstr_t bdstr;
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -0700428 bdaddr_to_string(remote_bdaddr, bdstr, sizeof(bdstr));
Sharvil Nanavati9d52f882014-08-19 09:50:18 -0700429 if(btif_config_exist(bdstr, "HidAppId"))
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700430 return TRUE;
431 }
432 }
Priti Agheraebb1d752012-11-27 18:03:22 -0800433 return FALSE;
434}
435
Priti Agherac0edf9f2014-06-26 11:23:51 -0700436/*****************************************************************************
437**
Hemant Guptada33b462015-04-26 10:32:57 +0530438** Function check_if_auth_bl
439**
440** Description Checks if a given device is blacklisted to skip authentication
441**
442** Parameters remote_bdaddr
443**
444** Returns TRUE if the device is present in blacklist, else FALSE
445**
446*******************************************************************************/
447static bool check_if_auth_bl(bt_bdaddr_t * remote_bdaddr)
448{
449 if (remote_bdaddr == NULL) {
450 LOG_WARN("%s: remote_bdaddr = NULL, returning false", __func__);
451 return FALSE;
452 }
453
454 bt_property_t prop_name;
455 bt_bdname_t bdname;
456
457 if (interop_addr_match(INTEROP_DISABLE_AUTH_FOR_HID_POINTING, remote_bdaddr))
458 return TRUE;
459
460 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_BDNAME,
461 sizeof(bt_bdname_t), &bdname);
462 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
463 &prop_name) != BT_STATUS_SUCCESS)
464 {
465 LOG_WARN("%s: BT_PROPERTY_BDNAME failed, returning false", __func__);
466 return FALSE;
467 }
468
469 if (bdname.name != NULL &&
470 interop_name_match(INTEROP_DISABLE_SDP_AFTER_PAIRING, (const char *)bdname.name))
471 return TRUE;
472
473 char bdstr[20] = {0};
474 LOG_DEBUG("%s: %s is not in blacklist for skipping auth", __func__,
475 bdaddr_to_string(remote_bdaddr, bdstr, sizeof(bdstr)));
476 return FALSE;
477}
478
479/*****************************************************************************
480**
Priti Agherac0edf9f2014-06-26 11:23:51 -0700481** Function check_sdp_bl
482**
483** Description Checks if a given device is blacklisted to skip sdp
484**
Hemant Guptada33b462015-04-26 10:32:57 +0530485** Parameters remote_bdaddr
Priti Agherac0edf9f2014-06-26 11:23:51 -0700486**
487** Returns TRUE if the device is present in blacklist, else FALSE
488**
489*******************************************************************************/
490BOOLEAN check_sdp_bl(const bt_bdaddr_t *remote_bdaddr)
491{
Hemant Guptada33b462015-04-26 10:32:57 +0530492 if (remote_bdaddr == NULL) {
493 LOG_WARN("%s: remote_bdaddr = NULL, returning false", __func__);
494 return FALSE;
495 }
496
497 if (interop_addr_match(INTEROP_DISABLE_SDP_AFTER_PAIRING, remote_bdaddr)) {
498 LOG_WARN("%s: device is in blacklist for skipping sdp", __func__);
499 return TRUE;
500 }
501
502 bt_property_t prop_name;
503 bt_bdname_t bdname;
504 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_BDNAME,
505 sizeof(bt_bdname_t), &bdname);
506 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
507 &prop_name) != BT_STATUS_SUCCESS)
508 {
509 LOG_WARN("%s: BT_PROPERTY_BDNAME failed, returning false", __func__);
510 return FALSE;
511 }
512
513 if (bdname.name != NULL &&
514 interop_name_match(INTEROP_DISABLE_SDP_AFTER_PAIRING, (const char *)bdname.name))
515 return TRUE;
516
Priti Agherac0edf9f2014-06-26 11:23:51 -0700517 UINT16 manufacturer = 0;
518 UINT8 lmp_ver = 0;
519 UINT16 lmp_subver = 0;
Priti Agherac0edf9f2014-06-26 11:23:51 -0700520 bt_remote_version_t info;
Priti Agherac0edf9f2014-06-26 11:23:51 -0700521
Hemant Guptada33b462015-04-26 10:32:57 +0530522 /* fetch additional info about remote device used in iop query */
Sharvil Nanavatif1c764f2015-02-23 17:31:48 -0800523 BTM_ReadRemoteVersion(*(BD_ADDR*)remote_bdaddr, &lmp_ver,
Priti Agherac0edf9f2014-06-26 11:23:51 -0700524 &manufacturer, &lmp_subver);
525
Hemant Guptada33b462015-04-26 10:32:57 +0530526 /* if not available yet, try fetching from config database */
Priti Agherac0edf9f2014-06-26 11:23:51 -0700527 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_REMOTE_VERSION_INFO,
528 sizeof(bt_remote_version_t), &info);
529
530 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
531 &prop_name) != BT_STATUS_SUCCESS)
532 {
533
Hemant Guptada33b462015-04-26 10:32:57 +0530534 APPL_TRACE_WARNING("%s: BT_PROPERTY_REMOTE_VERSION_INFO failed, returning false", __func__);
Priti Agherac0edf9f2014-06-26 11:23:51 -0700535 return FALSE;
536 }
537 manufacturer = info.manufacturer;
538
Hemant Guptada33b462015-04-26 10:32:57 +0530539 if (manufacturer != 0 &&
540 interop_manufacturer_match(INTEROP_DISABLE_SDP_AFTER_PAIRING, manufacturer))
541 return TRUE;
542
543 char bdstr[20] = {0};
544 LOG_DEBUG("%s: %s is not in blacklist for skipping sdp", __func__,
545 bdaddr_to_string(remote_bdaddr, bdstr, sizeof(bdstr)));
Priti Agherac0edf9f2014-06-26 11:23:51 -0700546 return FALSE;
547}
548
The Android Open Source Project5738f832012-12-12 16:00:35 -0800549static void bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr, bt_bond_state_t state)
550{
Chaojing Sune2805532015-04-22 13:40:21 -0700551 // Send bonding state only once - based on outgoing/incoming we may receive duplicates
552 if ((pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING))
553 {
554 // Cross key pairing so send callback for static address
Andre Eisenbache87ef6d2015-05-01 13:14:59 -0700555 if (!bdaddr_is_empty(&pairing_cb.static_bdaddr))
556 {
Chaojing Sune2805532015-04-22 13:40:21 -0700557 HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state);
Andre Eisenbache87ef6d2015-05-01 13:14:59 -0700558 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800559 return;
Chaojing Sune2805532015-04-22 13:40:21 -0700560 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800561
Andre Eisenbach89363762015-01-26 13:49:36 -0800562 if (pairing_cb.bond_type == BOND_TYPE_TEMPORARY)
Chaojing Sune2805532015-04-22 13:40:21 -0700563 state = BT_BOND_STATE_NONE;
564
565 BTIF_TRACE_DEBUG("%s: state=%d, prev_state=%d, sdp_attempts = %d", __func__,
566 state, pairing_cb.state, pairing_cb.sdp_attempts);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800567
568 HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state);
569
570 if (state == BT_BOND_STATE_BONDING)
571 {
572 pairing_cb.state = state;
573 bdcpy(pairing_cb.bd_addr, bd_addr->address);
Chaojing Sune2805532015-04-22 13:40:21 -0700574 } else {
575 if (!pairing_cb.sdp_attempts)
576 memset(&pairing_cb, 0, sizeof(pairing_cb));
577 else
578 BTIF_TRACE_DEBUG("%s: BR-EDR service discovery active", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800579 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800580}
581
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800582/* store remote version in bt config to always have access
583 to it post pairing*/
584static void btif_update_remote_version_property(bt_bdaddr_t *p_bd)
585{
586 bt_property_t property;
587 UINT8 lmp_ver = 0;
588 UINT16 lmp_subver = 0;
589 UINT16 mfct_set = 0;
590 tBTM_STATUS btm_status;
591 bt_remote_version_t info;
592 bt_status_t status;
593 bdstr_t bdstr;
594
595 btm_status = BTM_ReadRemoteVersion(*(BD_ADDR*)p_bd, &lmp_ver,
596 &mfct_set, &lmp_subver);
597
Sharvil Nanavati44802762014-12-23 23:08:58 -0800598 LOG_DEBUG("remote version info [%s]: %x, %x, %x", bdaddr_to_string(p_bd, bdstr, sizeof(bdstr)),
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800599 lmp_ver, mfct_set, lmp_subver);
600
601 if (btm_status == BTM_SUCCESS)
602 {
Chaojing Sune2805532015-04-22 13:40:21 -0700603 // Always update cache to ensure we have availability whenever BTM API is not populated
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800604 info.manufacturer = mfct_set;
605 info.sub_ver = lmp_subver;
606 info.version = lmp_ver;
607 BTIF_STORAGE_FILL_PROPERTY(&property,
608 BT_PROPERTY_REMOTE_VERSION_INFO, sizeof(bt_remote_version_t),
609 &info);
610 status = btif_storage_set_remote_device_property(p_bd, &property);
611 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote version", status);
612 }
613}
614
The Android Open Source Project5738f832012-12-12 16:00:35 -0800615
616static void btif_update_remote_properties(BD_ADDR bd_addr, BD_NAME bd_name,
617 DEV_CLASS dev_class, tBT_DEVICE_TYPE device_type)
618{
619 int num_properties = 0;
620 bt_property_t properties[3];
621 bt_bdaddr_t bdaddr;
622 bt_status_t status;
623 UINT32 cod;
624 bt_device_type_t dev_type;
625
626 memset(properties, 0, sizeof(properties));
627 bdcpy(bdaddr.address, bd_addr);
628
629 /* remote name */
630 if (strlen((const char *) bd_name))
631 {
632 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
633 BT_PROPERTY_BDNAME, strlen((char *)bd_name), bd_name);
634 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
635 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device name", status);
636 num_properties++;
637 }
638
639 /* class of device */
640 cod = devclass2uint(dev_class);
Chris Mantonf8027002015-03-12 09:22:48 -0700641 BTIF_TRACE_DEBUG("%s cod is 0x%06x", __func__, cod);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800642 if ( cod == 0) {
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530643 /* Try to retrieve cod from storage */
Chris Mantonf8027002015-03-12 09:22:48 -0700644 BTIF_TRACE_DEBUG("%s cod is 0, checking cod from storage", __func__);
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530645 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
646 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
647 status = btif_storage_get_remote_device_property(&bdaddr, &properties[num_properties]);
Chris Mantonf8027002015-03-12 09:22:48 -0700648 BTIF_TRACE_DEBUG("%s cod retrieved from storage is 0x%06x", __func__, cod);
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530649 if ( cod == 0) {
Chris Mantonf8027002015-03-12 09:22:48 -0700650 BTIF_TRACE_DEBUG("%s cod is again 0, set as unclassified", __func__);
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530651 cod = COD_UNCLASSIFIED;
652 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800653 }
654
655 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
656 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
657 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
658 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device class", status);
659 num_properties++;
660
661 /* device type */
Chaojing Sune2805532015-04-22 13:40:21 -0700662 bt_property_t prop_name;
663 uint8_t remote_dev_type;
664 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_TYPE_OF_DEVICE,
665 sizeof(uint8_t), &remote_dev_type);
666 if (btif_storage_get_remote_device_property(&bdaddr, &prop_name) == BT_STATUS_SUCCESS)
667 dev_type = remote_dev_type | device_type;
668 else
669 dev_type = device_type;
670
The Android Open Source Project5738f832012-12-12 16:00:35 -0800671 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
672 BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
673 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
674 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device type", status);
675 num_properties++;
676
677 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
678 status, &bdaddr, num_properties, properties);
679}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800680
681/*******************************************************************************
682**
683** Function btif_dm_cb_hid_remote_name
684**
685** Description Remote name callback for HID device. Called in btif context
686** Special handling for HID devices
687**
688** Returns void
689**
690*******************************************************************************/
691static void btif_dm_cb_hid_remote_name(tBTM_REMOTE_DEV_NAME *p_remote_name)
692{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700693 BTIF_TRACE_DEBUG("%s: status=%d pairing_cb.state=%d", __FUNCTION__, p_remote_name->status, pairing_cb.state);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800694 if (pairing_cb.state == BT_BOND_STATE_BONDING)
695 {
696 bt_bdaddr_t remote_bd;
697
698 bdcpy(remote_bd.address, pairing_cb.bd_addr);
699
700 if (p_remote_name->status == BTM_SUCCESS)
701 {
702 bond_state_changed(BT_STATUS_SUCCESS, &remote_bd, BT_BOND_STATE_BONDED);
703 }
704 else
705 bond_state_changed(BT_STATUS_FAIL, &remote_bd, BT_BOND_STATE_NONE);
706 }
707}
708
The Android Open Source Project5738f832012-12-12 16:00:35 -0800709/*******************************************************************************
710**
711** Function btif_dm_cb_create_bond
712**
713** Description Create bond initiated from the BTIF thread context
714** Special handling for HID devices
715**
716** Returns void
717**
718*******************************************************************************/
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -0700719static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr, tBTA_TRANSPORT transport)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800720{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800721 BOOLEAN is_hid = check_cod(bd_addr, COD_HID_POINTING);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800722 bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800723
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800724#if BLE_INCLUDED == TRUE
725 int device_type;
726 int addr_type;
727 bdstr_t bdstr;
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -0700728 bdaddr_to_string(bd_addr, bdstr, sizeof(bdstr));
Matthew Xie64c54792014-09-16 00:55:03 -0700729 if (transport == BT_TRANSPORT_LE)
730 {
Sharvil Nanavati9d52f882014-08-19 09:50:18 -0700731 if (!btif_config_get_int((char const *)&bdstr,"DevType", &device_type))
Matthew Xie64c54792014-09-16 00:55:03 -0700732 {
Sharvil Nanavati9d52f882014-08-19 09:50:18 -0700733 btif_config_set_int(bdstr, "DevType", BT_DEVICE_TYPE_BLE);
Matthew Xie64c54792014-09-16 00:55:03 -0700734 }
735 if (btif_storage_get_remote_addr_type(bd_addr, &addr_type) != BT_STATUS_SUCCESS)
736 {
737 btif_storage_set_remote_addr_type(bd_addr, BLE_ADDR_PUBLIC);
738 }
739 }
Sharvil Nanavati9d52f882014-08-19 09:50:18 -0700740 if((btif_config_get_int((char const *)&bdstr,"DevType", &device_type) &&
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800741 (btif_storage_get_remote_addr_type(bd_addr, &addr_type) == BT_STATUS_SUCCESS) &&
Chaojing Sune2805532015-04-22 13:40:21 -0700742 (device_type & BT_DEVICE_TYPE_BLE) == BT_DEVICE_TYPE_BLE) || (transport == BT_TRANSPORT_LE))
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800743 {
Chaojing Sune2805532015-04-22 13:40:21 -0700744 BTA_DmAddBleDevice(bd_addr->address, addr_type, device_type);
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800745 }
746#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800747
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800748#if BLE_INCLUDED == TRUE
Chaojing Sune2805532015-04-22 13:40:21 -0700749 if(is_hid && (device_type & BT_DEVICE_TYPE_BLE) == 0)
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800750#else
751 if(is_hid)
752#endif
753 {
754 int status;
755 status = btif_hh_connect(bd_addr);
756 if(status != BT_STATUS_SUCCESS)
757 bond_state_changed(status, bd_addr, BT_BOND_STATE_NONE);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800758 }
759 else
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800760 {
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -0700761 BTA_DmBondByTransport((UINT8 *)bd_addr->address, transport);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800762 }
763 /* Track originator of bond creation */
764 pairing_cb.is_local_initiated = TRUE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800765
766}
767
768/*******************************************************************************
769**
770** Function btif_dm_cb_remove_bond
771**
772** Description remove bond initiated from the BTIF thread context
773** Special handling for HID devices
774**
775** Returns void
776**
777*******************************************************************************/
778void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr)
779{
The Android Open Source Project5738f832012-12-12 16:00:35 -0800780 /*special handling for HID devices */
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -0700781 /* VUP needs to be sent if its a HID Device. The HID HOST module will check if there
782 is a valid hid connection with this bd_addr. If yes VUP will be issued.*/
783#if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
784 if (btif_hh_virtual_unplug(bd_addr) != BT_STATUS_SUCCESS)
785#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800786 {
Chaojing Sune2805532015-04-22 13:40:21 -0700787 BTIF_TRACE_DEBUG("%s: Removing HH device", __func__);
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -0700788 BTA_DmRemoveDevice((UINT8 *)bd_addr->address);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800789 }
790}
791
792/*******************************************************************************
793**
Andre Eisenbach249f6002014-06-18 12:20:37 -0700794** Function btif_dm_get_connection_state
795**
796** Description Returns whether the remote device is currently connected
Andre Eisenbachdfb3b2f2015-02-05 20:00:45 -0800797** and whether encryption is active for the connection
Andre Eisenbach249f6002014-06-18 12:20:37 -0700798**
Andre Eisenbachdfb3b2f2015-02-05 20:00:45 -0800799** Returns 0 if not connected; 1 if connected and > 1 if connection is
800** encrypted
Andre Eisenbach249f6002014-06-18 12:20:37 -0700801**
802*******************************************************************************/
803uint16_t btif_dm_get_connection_state(const bt_bdaddr_t *bd_addr)
804{
Andre Eisenbachdfb3b2f2015-02-05 20:00:45 -0800805 uint8_t *bda = (uint8_t*)bd_addr->address;
806 uint16_t rc = BTA_DmGetConnectionState(bda);
807
808 if (rc != 0)
809 {
810 uint8_t flags = 0;
811
812 BTM_GetSecurityFlagsByTransport(bda, &flags, BT_TRANSPORT_BR_EDR);
813 BTIF_TRACE_DEBUG("%s: security flags (BR/EDR)=0x%02x", __FUNCTION__, flags);
814 if (flags & BTM_SEC_FLAG_ENCRYPTED)
815 rc |= ENCRYPTED_BREDR;
816
817 BTM_GetSecurityFlagsByTransport(bda, &flags, BT_TRANSPORT_LE);
818 BTIF_TRACE_DEBUG("%s: security flags (LE)=0x%02x", __FUNCTION__, flags);
819 if (flags & BTM_SEC_FLAG_ENCRYPTED)
820 rc |= ENCRYPTED_LE;
821 }
822
823 return rc;
Andre Eisenbach249f6002014-06-18 12:20:37 -0700824}
825
826/*******************************************************************************
827**
The Android Open Source Project5738f832012-12-12 16:00:35 -0800828** Function search_devices_copy_cb
829**
830** Description Deep copy callback for search devices event
831**
832** Returns void
833**
834*******************************************************************************/
835static void search_devices_copy_cb(UINT16 event, char *p_dest, char *p_src)
836{
837 tBTA_DM_SEARCH *p_dest_data = (tBTA_DM_SEARCH *) p_dest;
838 tBTA_DM_SEARCH *p_src_data = (tBTA_DM_SEARCH *) p_src;
839
840 if (!p_src)
841 return;
842
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700843 BTIF_TRACE_DEBUG("%s: event=%s", __FUNCTION__, dump_dm_search_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800844 memcpy(p_dest_data, p_src_data, sizeof(tBTA_DM_SEARCH));
845 switch (event)
846 {
847 case BTA_DM_INQ_RES_EVT:
848 {
849 if (p_src_data->inq_res.p_eir)
850 {
851 p_dest_data->inq_res.p_eir = (UINT8 *)(p_dest + sizeof(tBTA_DM_SEARCH));
852 memcpy(p_dest_data->inq_res.p_eir, p_src_data->inq_res.p_eir, HCI_EXT_INQ_RESPONSE_LEN);
853 }
854 }
855 break;
856
857 case BTA_DM_DISC_RES_EVT:
858 {
859 if (p_src_data->disc_res.raw_data_size && p_src_data->disc_res.p_raw_data)
860 {
861 p_dest_data->disc_res.p_raw_data = (UINT8 *)(p_dest + sizeof(tBTA_DM_SEARCH));
862 memcpy(p_dest_data->disc_res.p_raw_data,
863 p_src_data->disc_res.p_raw_data, p_src_data->disc_res.raw_data_size);
864 }
865 }
866 break;
867 }
868}
869
870static void search_services_copy_cb(UINT16 event, char *p_dest, char *p_src)
871{
872 tBTA_DM_SEARCH *p_dest_data = (tBTA_DM_SEARCH *) p_dest;
873 tBTA_DM_SEARCH *p_src_data = (tBTA_DM_SEARCH *) p_src;
874
875 if (!p_src)
876 return;
877 memcpy(p_dest_data, p_src_data, sizeof(tBTA_DM_SEARCH));
878 switch (event)
879 {
880 case BTA_DM_DISC_RES_EVT:
881 {
Kausik Sinnaswamy95664a92013-05-03 15:02:50 +0530882 if (p_src_data->disc_res.result == BTA_SUCCESS)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800883 {
Kausik Sinnaswamy95664a92013-05-03 15:02:50 +0530884 if (p_src_data->disc_res.num_uuids > 0)
885 {
886 p_dest_data->disc_res.p_uuid_list =
887 (UINT8*)(p_dest + sizeof(tBTA_DM_SEARCH));
888 memcpy(p_dest_data->disc_res.p_uuid_list, p_src_data->disc_res.p_uuid_list,
889 p_src_data->disc_res.num_uuids*MAX_UUID_SIZE);
890 GKI_freebuf(p_src_data->disc_res.p_uuid_list);
891 }
892 if (p_src_data->disc_res.p_raw_data != NULL)
893 {
894 GKI_freebuf(p_src_data->disc_res.p_raw_data);
895 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800896 }
897 } break;
898 }
899}
900/******************************************************************************
901**
902** BTIF DM callback events
903**
904*****************************************************************************/
905
906/*******************************************************************************
907**
908** Function btif_dm_pin_req_evt
909**
910** Description Executes pin request event in btif context
911**
912** Returns void
913**
914*******************************************************************************/
915static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
916{
917 bt_bdaddr_t bd_addr;
918 bt_bdname_t bd_name;
919 UINT32 cod;
920 bt_pin_code_t pin_code;
Matthew Xie86f97ed2014-11-10 10:24:46 -0800921 int dev_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800922
923 /* Remote properties update */
Matthew Xie86f97ed2014-11-10 10:24:46 -0800924 if (!btif_get_device_type(p_pin_req->bd_addr, &dev_type))
925 {
926 dev_type = BT_DEVICE_TYPE_BREDR;
927 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800928 btif_update_remote_properties(p_pin_req->bd_addr, p_pin_req->bd_name,
Matthew Xie86f97ed2014-11-10 10:24:46 -0800929 p_pin_req->dev_class, (tBT_DEVICE_TYPE) dev_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800930
931 bdcpy(bd_addr.address, p_pin_req->bd_addr);
932 memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN);
933
934 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
935
936 cod = devclass2uint(p_pin_req->dev_class);
937
Chris Mantonf8027002015-03-12 09:22:48 -0700938 if (cod == 0) {
939 BTIF_TRACE_DEBUG("%s cod is 0, set as unclassified", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800940 cod = COD_UNCLASSIFIED;
941 }
942
943 /* check for auto pair possiblity only if bond was initiated by local device */
Casper Bonde818d0f22015-05-21 11:08:45 +0200944 if (pairing_cb.is_local_initiated && (p_pin_req->min_16_digit == FALSE))
The Android Open Source Project5738f832012-12-12 16:00:35 -0800945 {
946 if (check_cod(&bd_addr, COD_AV_HEADSETS) ||
947 check_cod(&bd_addr, COD_AV_HANDSFREE) ||
948 check_cod(&bd_addr, COD_AV_HEADPHONES) ||
949 check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) ||
950 check_cod(&bd_addr, COD_AV_HIFI_AUDIO) ||
951 check_cod(&bd_addr, COD_HID_POINTING))
952 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700953 BTIF_TRACE_DEBUG("%s()cod matches for auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800954 /* Check if this device can be auto paired */
955 if ((btif_storage_is_device_autopair_blacklisted(&bd_addr) == FALSE) &&
956 (pairing_cb.autopair_attempts == 0))
957 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700958 BTIF_TRACE_DEBUG("%s() Attempting auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800959 pin_code.pin[0] = 0x30;
960 pin_code.pin[1] = 0x30;
961 pin_code.pin[2] = 0x30;
962 pin_code.pin[3] = 0x30;
963
964 pairing_cb.autopair_attempts++;
965 BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin);
966 return;
967 }
968 }
969 else if (check_cod(&bd_addr, COD_HID_KEYBOARD) ||
970 check_cod(&bd_addr, COD_HID_COMBO))
971 {
972 if(( btif_storage_is_fixed_pin_zeros_keyboard (&bd_addr) == TRUE) &&
973 (pairing_cb.autopair_attempts == 0))
974 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700975 BTIF_TRACE_DEBUG("%s() Attempting auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800976 pin_code.pin[0] = 0x30;
977 pin_code.pin[1] = 0x30;
978 pin_code.pin[2] = 0x30;
979 pin_code.pin[3] = 0x30;
980
981 pairing_cb.autopair_attempts++;
982 BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin);
983 return;
984 }
985 }
986 }
987 HAL_CBACK(bt_hal_cbacks, pin_request_cb,
Casper Bonde818d0f22015-05-21 11:08:45 +0200988 &bd_addr, &bd_name, cod, p_pin_req->min_16_digit);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800989}
990
991/*******************************************************************************
992**
993** Function btif_dm_ssp_cfm_req_evt
994**
995** Description Executes SSP confirm request event in btif context
996**
997** Returns void
998**
999*******************************************************************************/
1000static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ *p_ssp_cfm_req)
1001{
1002 bt_bdaddr_t bd_addr;
1003 bt_bdname_t bd_name;
1004 UINT32 cod;
1005 BOOLEAN is_incoming = !(pairing_cb.state == BT_BOND_STATE_BONDING);
Matthew Xie86f97ed2014-11-10 10:24:46 -08001006 int dev_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001007
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001008 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001009
1010 /* Remote properties update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08001011 if (!btif_get_device_type(p_ssp_cfm_req->bd_addr, &dev_type))
1012 {
1013 dev_type = BT_DEVICE_TYPE_BREDR;
1014 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001015 btif_update_remote_properties(p_ssp_cfm_req->bd_addr, p_ssp_cfm_req->bd_name,
Matthew Xie86f97ed2014-11-10 10:24:46 -08001016 p_ssp_cfm_req->dev_class, (tBT_DEVICE_TYPE) dev_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001017
1018 bdcpy(bd_addr.address, p_ssp_cfm_req->bd_addr);
1019 memcpy(bd_name.name, p_ssp_cfm_req->bd_name, BD_NAME_LEN);
1020
1021 /* Set the pairing_cb based on the local & remote authentication requirements */
1022 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
1023
1024 /* if just_works and bonding bit is not set treat this as temporary */
1025 if (p_ssp_cfm_req->just_works && !(p_ssp_cfm_req->loc_auth_req & BTM_AUTH_BONDS) &&
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001026 !(p_ssp_cfm_req->rmt_auth_req & BTM_AUTH_BONDS) &&
1027 !(check_cod((bt_bdaddr_t*)&p_ssp_cfm_req->bd_addr, COD_HID_POINTING)))
Andre Eisenbach89363762015-01-26 13:49:36 -08001028 pairing_cb.bond_type = BOND_TYPE_TEMPORARY;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001029 else
Andre Eisenbach89363762015-01-26 13:49:36 -08001030 pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001031
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001032 btm_set_bond_type_dev(p_ssp_cfm_req->bd_addr, pairing_cb.bond_type);
1033
The Android Open Source Project5738f832012-12-12 16:00:35 -08001034 pairing_cb.is_ssp = TRUE;
1035
1036 /* If JustWorks auto-accept */
1037 if (p_ssp_cfm_req->just_works)
1038 {
1039 /* Pairing consent for JustWorks needed if:
Andre Eisenbachaf753a22015-06-08 20:43:00 -07001040 * 1. Incoming (non-temporary) pairing is detected AND
The Android Open Source Project5738f832012-12-12 16:00:35 -08001041 * 2. local IO capabilities are DisplayYesNo AND
1042 * 3. remote IO capabiltiies are DisplayOnly or NoInputNoOutput;
1043 */
Andre Eisenbachaf753a22015-06-08 20:43:00 -07001044 if (is_incoming && pairing_cb.bond_type != BOND_TYPE_TEMPORARY &&
1045 ((p_ssp_cfm_req->loc_io_caps == HCI_IO_CAP_DISPLAY_YESNO) &&
1046 (p_ssp_cfm_req->rmt_io_caps == HCI_IO_CAP_DISPLAY_ONLY ||
1047 p_ssp_cfm_req->rmt_io_caps == HCI_IO_CAP_NO_IO)))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001048 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001049 BTIF_TRACE_EVENT("%s: User consent needed for incoming pairing request. loc_io_caps: %d, rmt_io_caps: %d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001050 __FUNCTION__, p_ssp_cfm_req->loc_io_caps, p_ssp_cfm_req->rmt_io_caps);
1051 }
1052 else
1053 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001054 BTIF_TRACE_EVENT("%s: Auto-accept JustWorks pairing", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001055 btif_dm_ssp_reply(&bd_addr, BT_SSP_VARIANT_CONSENT, TRUE, 0);
1056 return;
1057 }
1058 }
1059
1060 cod = devclass2uint(p_ssp_cfm_req->dev_class);
1061
Chris Mantonf8027002015-03-12 09:22:48 -07001062 if (cod == 0) {
1063 LOG_DEBUG("%s cod is 0, set as unclassified", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001064 cod = COD_UNCLASSIFIED;
1065 }
1066
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001067 pairing_cb.sdp_attempts = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001068 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod,
1069 (p_ssp_cfm_req->just_works ? BT_SSP_VARIANT_CONSENT : BT_SSP_VARIANT_PASSKEY_CONFIRMATION),
1070 p_ssp_cfm_req->num_val);
1071}
1072
1073static void btif_dm_ssp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif)
1074{
1075 bt_bdaddr_t bd_addr;
1076 bt_bdname_t bd_name;
1077 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08001078 int dev_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001079
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001080 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001081
1082 /* Remote properties update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08001083 if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type))
1084 {
1085 dev_type = BT_DEVICE_TYPE_BREDR;
1086 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001087 btif_update_remote_properties(p_ssp_key_notif->bd_addr, p_ssp_key_notif->bd_name,
Matthew Xie86f97ed2014-11-10 10:24:46 -08001088 p_ssp_key_notif->dev_class, (tBT_DEVICE_TYPE) dev_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001089
1090 bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
1091 memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
1092
1093 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
1094 pairing_cb.is_ssp = TRUE;
1095 cod = devclass2uint(p_ssp_key_notif->dev_class);
1096
Chris Mantonf8027002015-03-12 09:22:48 -07001097 if (cod == 0) {
1098 LOG_DEBUG("%s cod is 0, set as unclassified", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001099 cod = COD_UNCLASSIFIED;
1100 }
1101
1102 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
1103 cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION,
1104 p_ssp_key_notif->passkey);
1105}
1106/*******************************************************************************
1107**
1108** Function btif_dm_auth_cmpl_evt
1109**
1110** Description Executes authentication complete event in btif context
1111**
1112** Returns void
1113**
1114*******************************************************************************/
1115static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
1116{
1117 /* Save link key, if not temporary */
1118 bt_bdaddr_t bd_addr;
1119 bt_status_t status = BT_STATUS_FAIL;
1120 bt_bond_state_t state = BT_BOND_STATE_NONE;
Priti Agherac0edf9f2014-06-26 11:23:51 -07001121 BOOLEAN skip_sdp = FALSE;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001122
Chaojing Sune2805532015-04-22 13:40:21 -07001123 BTIF_TRACE_DEBUG("%s: bond state=%d", __func__, pairing_cb.state);
1124
The Android Open Source Project5738f832012-12-12 16:00:35 -08001125 bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
1126 if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
1127 {
Srinu Jella21331c62015-06-16 19:38:45 +05301128 if ((p_auth_cmpl->key_type < HCI_LKEY_TYPE_DEBUG_COMB) ||
1129 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB) ||
1130 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_CHANGED_COMB) ||
1131 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB_P_256) ||
1132 pairing_cb.bond_type == BOND_TYPE_PERSISTENT)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001133 {
1134 bt_status_t ret;
Andre Eisenbach89363762015-01-26 13:49:36 -08001135 BTIF_TRACE_DEBUG("%s: Storing link key. key_type=0x%x, bond_type=%d",
1136 __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.bond_type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001137 ret = btif_storage_add_bonded_device(&bd_addr,
1138 p_auth_cmpl->key, p_auth_cmpl->key_type,
1139 pairing_cb.pin_code_len);
1140 ASSERTC(ret == BT_STATUS_SUCCESS, "storing link key failed", ret);
1141 }
1142 else
1143 {
Andre Eisenbach89363762015-01-26 13:49:36 -08001144 BTIF_TRACE_DEBUG("%s: Temporary key. Not storing. key_type=0x%x, bond_type=%d",
1145 __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.bond_type);
1146 if(pairing_cb.bond_type == BOND_TYPE_TEMPORARY)
Hemant Guptab820aec2013-12-24 19:59:57 +05301147 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001148 BTIF_TRACE_DEBUG("%s: sending BT_BOND_STATE_NONE for Temp pairing",
Hemant Guptab820aec2013-12-24 19:59:57 +05301149 __FUNCTION__);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001150 btif_storage_remove_bonded_device(&bd_addr);
Hemant Guptab820aec2013-12-24 19:59:57 +05301151 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
1152 return;
1153 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001154 }
1155 }
Priti Agherac0edf9f2014-06-26 11:23:51 -07001156
1157 // Skip SDP for certain HID Devices
The Android Open Source Project5738f832012-12-12 16:00:35 -08001158 if (p_auth_cmpl->success)
1159 {
Andre Eisenbach12871662015-05-08 17:42:10 -07001160#if BLE_INCLUDED == TRUE
Chaojing Sune2805532015-04-22 13:40:21 -07001161 btif_storage_set_remote_addr_type(&bd_addr, p_auth_cmpl->addr_type);
Andre Eisenbach12871662015-05-08 17:42:10 -07001162#endif
Chaojing Sune2805532015-04-22 13:40:21 -07001163 btif_update_remote_properties(p_auth_cmpl->bd_addr,
1164 p_auth_cmpl->bd_name, NULL, p_auth_cmpl->dev_type);
Andre Eisenbach31a64002014-10-14 14:29:19 -07001165 pairing_cb.timeout_retries = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001166
Priti Agherac0edf9f2014-06-26 11:23:51 -07001167 if (check_sdp_bl(&bd_addr) && check_cod_hid(&bd_addr, COD_HID_MAJOR))
1168 {
Hemant Guptada33b462015-04-26 10:32:57 +05301169 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED);
Ganesh Ganapathi Battae17bf002013-02-15 17:52:29 -08001170
Hemant Guptada33b462015-04-26 10:32:57 +05301171 BTIF_TRACE_DEBUG("%s: HID Connection from "
1172 "blacklisted device, skipping sdp",__FUNCTION__);
Priti Agherac0edf9f2014-06-26 11:23:51 -07001173 bt_property_t prop;
Priti Agherac0edf9f2014-06-26 11:23:51 -07001174 bt_uuid_t uuid;
1175 char uuid_str[128] = UUID_HUMAN_INTERFACE_DEVICE;
Ganesh Ganapathi Battae17bf002013-02-15 17:52:29 -08001176
Priti Agherac0edf9f2014-06-26 11:23:51 -07001177 string_to_uuid(uuid_str, &uuid);
1178
1179 prop.type = BT_PROPERTY_UUIDS;
1180 prop.val = uuid.uu;
1181 prop.len = MAX_UUID_SIZE;
1182
Hemant Guptada33b462015-04-26 10:32:57 +05301183 /* Also write this to the NVRAM */
1184 status = btif_storage_set_remote_device_property(&bd_addr, &prop);
1185 ASSERTC(status == BT_STATUS_SUCCESS, "storing remote services failed", status);
Priti Agherac0edf9f2014-06-26 11:23:51 -07001186 /* Send the event to the BTIF */
1187 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1188 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1189 }
1190 else
1191 {
Hemant Guptada33b462015-04-26 10:32:57 +05301192 status = BT_STATUS_SUCCESS;
1193 state = BT_BOND_STATE_BONDED;
1194
Priti Agherac0edf9f2014-06-26 11:23:51 -07001195 /* Trigger SDP on the device */
1196 pairing_cb.sdp_attempts = 1;;
Andre Eisenbach12871662015-05-08 17:42:10 -07001197
1198#if BLE_INCLUDED == TRUE
Chaojing Sune2805532015-04-22 13:40:21 -07001199 /* If bonded due to cross-key, save the static address too*/
1200 if(pairing_cb.state == BT_BOND_STATE_BONDING &&
1201 (bdcmp(p_auth_cmpl->bd_addr, pairing_cb.bd_addr) != 0))
1202 {
1203 BTIF_TRACE_DEBUG("%s: bonding initiated due to cross key, adding static address",
1204 __func__);
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001205 bdcpy(pairing_cb.static_bdaddr.address, p_auth_cmpl->bd_addr);
Chaojing Sune2805532015-04-22 13:40:21 -07001206 }
Andre Eisenbach12871662015-05-08 17:42:10 -07001207#endif
Priti Agherac0edf9f2014-06-26 11:23:51 -07001208
1209 if(btif_dm_inquiry_in_progress)
1210 btif_dm_cancel_discovery();
1211
1212 btif_dm_get_remote_services(&bd_addr);
Chaojing Sune2805532015-04-22 13:40:21 -07001213 }
1214 // Do not call bond_state_changed_cb yet. Wait until remote service discovery is complete
The Android Open Source Project5738f832012-12-12 16:00:35 -08001215 }
1216 else
1217 {
Chaojing Sune2805532015-04-22 13:40:21 -07001218 // Map the HCI fail reason to bt status
The Android Open Source Project5738f832012-12-12 16:00:35 -08001219 switch(p_auth_cmpl->fail_reason)
1220 {
1221 case HCI_ERR_PAGE_TIMEOUT:
Hemant Guptada33b462015-04-26 10:32:57 +05301222 if (interop_addr_match(INTEROP_AUTO_RETRY_PAIRING, &bd_addr)
Andre Eisenbach27c4e632015-07-06 15:43:15 -07001223 && pairing_cb.timeout_retries)
Andre Eisenbach31a64002014-10-14 14:29:19 -07001224 {
1225 BTIF_TRACE_WARNING("%s() - Pairing timeout; retrying (%d) ...", __FUNCTION__, pairing_cb.timeout_retries);
1226 --pairing_cb.timeout_retries;
1227 btif_dm_cb_create_bond (&bd_addr, BTA_TRANSPORT_UNKNOWN);
1228 return;
1229 }
1230 /* Fall-through */
The Android Open Source Project5738f832012-12-12 16:00:35 -08001231 case HCI_ERR_CONNECTION_TOUT:
1232 status = BT_STATUS_RMT_DEV_DOWN;
1233 break;
1234
Hemant Guptaaef7a672013-07-31 19:00:12 +05301235 case HCI_ERR_PAIRING_NOT_ALLOWED:
1236 status = BT_STATUS_AUTH_REJECTED;
1237 break;
1238
Hemant Guptab4801442014-01-07 18:11:15 +05301239 case HCI_ERR_LMP_RESPONSE_TIMEOUT:
1240 status = BT_STATUS_AUTH_FAILURE;
1241 break;
1242
The Android Open Source Project5738f832012-12-12 16:00:35 -08001243 /* map the auth failure codes, so we can retry pairing if necessary */
1244 case HCI_ERR_AUTH_FAILURE:
Hemant Gupta59a88ec2014-03-19 19:01:35 +05301245 case HCI_ERR_KEY_MISSING:
Zhihai Xua7ea8092013-11-27 14:10:53 +05301246 btif_storage_remove_bonded_device(&bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001247 case HCI_ERR_HOST_REJECT_SECURITY:
1248 case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE:
1249 case HCI_ERR_UNIT_KEY_USED:
1250 case HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED:
1251 case HCI_ERR_INSUFFCIENT_SECURITY:
Hemant Gupta87b7cce2013-11-28 13:07:10 +05301252 case HCI_ERR_PEER_USER:
1253 case HCI_ERR_UNSPECIFIED:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001254 BTIF_TRACE_DEBUG(" %s() Authentication fail reason %d",
Hemant Gupta87b7cce2013-11-28 13:07:10 +05301255 __FUNCTION__, p_auth_cmpl->fail_reason);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001256 if (pairing_cb.autopair_attempts == 1)
1257 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001258 BTIF_TRACE_DEBUG("%s(): Adding device to blacklist ", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001259
1260 /* Add the device to dynamic black list only if this device belongs to Audio/pointing dev class */
1261 if (check_cod(&bd_addr, COD_AV_HEADSETS) ||
1262 check_cod(&bd_addr, COD_AV_HANDSFREE) ||
1263 check_cod(&bd_addr, COD_AV_HEADPHONES) ||
1264 check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) ||
1265 check_cod(&bd_addr, COD_AV_HIFI_AUDIO) ||
1266 check_cod(&bd_addr, COD_HID_POINTING))
1267 {
1268 btif_storage_add_device_to_autopair_blacklist (&bd_addr);
1269 }
1270 pairing_cb.autopair_attempts++;
1271
1272 /* Create the Bond once again */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001273 BTIF_TRACE_DEBUG("%s() auto pair failed. Reinitiate Bond", __FUNCTION__);
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07001274 btif_dm_cb_create_bond (&bd_addr, BTA_TRANSPORT_UNKNOWN);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001275 return;
1276 }
1277 else
1278 {
1279 /* if autopair attempts are more than 1, or not attempted */
1280 status = BT_STATUS_AUTH_FAILURE;
1281 }
1282 break;
1283
1284 default:
1285 status = BT_STATUS_FAIL;
1286 }
Zhihai Xu8d2128d2013-12-13 16:09:21 +05301287 /* Special Handling for HID Devices */
1288 if (check_cod(&bd_addr, COD_HID_POINTING)) {
1289 /* Remove Device as bonded in nvram as authentication failed */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001290 BTIF_TRACE_DEBUG("%s(): removing hid pointing device from nvram", __FUNCTION__);
Zhihai Xu8d2128d2013-12-13 16:09:21 +05301291 btif_storage_remove_bonded_device(&bd_addr);
1292 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001293 bond_state_changed(status, &bd_addr, state);
1294 }
1295}
1296
1297/******************************************************************************
1298**
1299** Function btif_dm_search_devices_evt
1300**
1301** Description Executes search devices callback events in btif context
1302**
1303** Returns void
1304**
1305******************************************************************************/
1306static void btif_dm_search_devices_evt (UINT16 event, char *p_param)
1307{
1308 tBTA_DM_SEARCH *p_search_data;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001309 BTIF_TRACE_EVENT("%s event=%s", __FUNCTION__, dump_dm_search_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001310
1311 switch (event)
1312 {
1313 case BTA_DM_DISC_RES_EVT:
1314 {
1315 p_search_data = (tBTA_DM_SEARCH *)p_param;
1316 /* Remote name update */
1317 if (strlen((const char *) p_search_data->disc_res.bd_name))
1318 {
1319 bt_property_t properties[1];
1320 bt_bdaddr_t bdaddr;
1321 bt_status_t status;
1322
1323 properties[0].type = BT_PROPERTY_BDNAME;
1324 properties[0].val = p_search_data->disc_res.bd_name;
1325 properties[0].len = strlen((char *)p_search_data->disc_res.bd_name);
1326 bdcpy(bdaddr.address, p_search_data->disc_res.bd_addr);
1327
1328 status = btif_storage_set_remote_device_property(&bdaddr, &properties[0]);
1329 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device property", status);
1330 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1331 status, &bdaddr, 1, properties);
1332 }
1333 /* TODO: Services? */
1334 }
1335 break;
1336
1337 case BTA_DM_INQ_RES_EVT:
1338 {
1339 /* inquiry result */
1340 UINT32 cod;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001341 bt_bdname_t bdname;
1342 bt_bdaddr_t bdaddr;
1343 UINT8 remote_name_len;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001344 tBTA_SERVICE_MASK services = 0;
1345 bdstr_t bdstr;
1346
1347 p_search_data = (tBTA_DM_SEARCH *)p_param;
1348 bdcpy(bdaddr.address, p_search_data->inq_res.bd_addr);
1349
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07001350 BTIF_TRACE_DEBUG("%s() %s device_type = 0x%x\n", __FUNCTION__, bdaddr_to_string(&bdaddr, bdstr, sizeof(bdstr)),
The Android Open Source Project5738f832012-12-12 16:00:35 -08001351#if (BLE_INCLUDED == TRUE)
1352 p_search_data->inq_res.device_type);
1353#else
1354 BT_DEVICE_TYPE_BREDR);
1355#endif
1356 bdname.name[0] = 0;
1357
1358 cod = devclass2uint (p_search_data->inq_res.dev_class);
1359
Chris Mantonf8027002015-03-12 09:22:48 -07001360 if (cod == 0) {
1361 LOG_DEBUG("%s cod is 0, set as unclassified", __func__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001362 cod = COD_UNCLASSIFIED;
1363 }
1364
1365 if (!check_eir_remote_name(p_search_data, bdname.name, &remote_name_len))
1366 check_cached_remote_name(p_search_data, bdname.name, &remote_name_len);
1367
1368 /* Check EIR for remote name and services */
1369 if (p_search_data->inq_res.p_eir)
1370 {
1371 BTA_GetEirService(p_search_data->inq_res.p_eir, &services);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001372 BTIF_TRACE_DEBUG("%s()EIR BTA services = %08X", __FUNCTION__, (UINT32)services);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001373 /* TODO: Get the service list and check to see which uuids we got and send it back to the client. */
1374 }
1375
1376
1377 {
1378 bt_property_t properties[5];
1379 bt_device_type_t dev_type;
1380 uint32_t num_properties = 0;
1381 bt_status_t status;
Nitin Aroraac728402015-06-26 18:09:37 -07001382 int addr_type = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001383
1384 memset(properties, 0, sizeof(properties));
1385 /* BD_ADDR */
1386 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1387 BT_PROPERTY_BDADDR, sizeof(bdaddr), &bdaddr);
1388 num_properties++;
1389 /* BD_NAME */
1390 /* Don't send BDNAME if it is empty */
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001391 if (bdname.name[0])
1392 {
The Android Open Source Project5738f832012-12-12 16:00:35 -08001393 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1394 BT_PROPERTY_BDNAME,
1395 strlen((char *)bdname.name), &bdname);
1396 num_properties++;
1397 }
1398
1399 /* DEV_CLASS */
1400 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1401 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
1402 num_properties++;
1403 /* DEV_TYPE */
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001404#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001405 /* FixMe: Assumption is that bluetooth.h and BTE enums match */
Nitin Aroraac728402015-06-26 18:09:37 -07001406
1407 /* Verify if the device is dual mode in NVRAM */
1408 int stored_device_type = 0;
1409 if (btif_get_device_type(bdaddr.address, &stored_device_type) &&
1410 ((stored_device_type == BT_DEVICE_TYPE_BLE &&
1411 p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BREDR) ||
1412 (stored_device_type == BT_DEVICE_TYPE_BREDR &&
1413 p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BLE))) {
1414 dev_type = BT_DEVICE_TYPE_DUMO;
1415 } else {
1416 dev_type = p_search_data->inq_res.device_type;
1417 }
1418
1419 if (p_search_data->inq_res.device_type == BT_DEVICE_TYPE_BLE)
1420 addr_type = p_search_data->inq_res.ble_addr_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001421#else
1422 dev_type = BT_DEVICE_TYPE_BREDR;
1423#endif
1424 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1425 BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
1426 num_properties++;
1427 /* RSSI */
1428 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1429 BT_PROPERTY_REMOTE_RSSI, sizeof(int8_t),
1430 &(p_search_data->inq_res.rssi));
1431 num_properties++;
1432
1433 status = btif_storage_add_remote_device(&bdaddr, num_properties, properties);
1434 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device (inquiry)", status);
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001435#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1436 status = btif_storage_set_remote_addr_type(&bdaddr, addr_type);
1437 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote addr type (inquiry)", status);
1438#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001439 /* Callback to notify upper layer of device */
1440 HAL_CBACK(bt_hal_cbacks, device_found_cb,
1441 num_properties, properties);
1442 }
1443 }
1444 break;
1445
1446 case BTA_DM_INQ_CMPL_EVT:
1447 {
Satya Calloji6e2d9db2014-07-08 16:18:58 -07001448#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1449 tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param;
1450 memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
1451 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL,
1452 bte_scan_filt_param_cfg_evt, 0);
1453#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001454 }
1455 break;
1456 case BTA_DM_DISC_CMPL_EVT:
1457 {
1458 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED);
1459 }
1460 break;
1461 case BTA_DM_SEARCH_CANCEL_CMPL_EVT:
1462 {
1463 /* if inquiry is not in progress and we get a cancel event, then
1464 * it means we are done with inquiry, but remote_name fetches are in
1465 * progress
1466 *
1467 * if inquiry is in progress, then we don't want to act on this cancel_cmpl_evt
1468 * but instead wait for the cancel_cmpl_evt via the Busy Level
1469 *
1470 */
1471 if (btif_dm_inquiry_in_progress == FALSE)
1472 {
Nitin Arora7b85efa2014-09-26 14:05:24 -07001473#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1474 tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param;
1475 memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
1476 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL,
1477 bte_scan_filt_param_cfg_evt, 0);
1478#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001479 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED);
1480 }
1481 }
1482 break;
1483 }
1484}
1485
1486/*******************************************************************************
1487**
1488** Function btif_dm_search_services_evt
1489**
1490** Description Executes search services event in btif context
1491**
1492** Returns void
1493**
1494*******************************************************************************/
1495static void btif_dm_search_services_evt(UINT16 event, char *p_param)
1496{
1497 tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param;
1498
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001499 BTIF_TRACE_EVENT("%s: event = %d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001500 switch (event)
1501 {
1502 case BTA_DM_DISC_RES_EVT:
1503 {
The Android Open Source Project5738f832012-12-12 16:00:35 -08001504 bt_property_t prop;
Bernhard Rosenkränzer104e3f22014-11-12 21:53:08 +01001505 uint32_t i = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001506 bt_bdaddr_t bd_addr;
1507 bt_status_t ret;
1508
1509 bdcpy(bd_addr.address, p_data->disc_res.bd_addr);
1510
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001511 BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001512 p_data->disc_res.result, p_data->disc_res.services);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001513 if ((p_data->disc_res.result != BTA_SUCCESS) &&
1514 (pairing_cb.state == BT_BOND_STATE_BONDING ) &&
1515 (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING))
1516 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001517 BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", __FUNCTION__);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001518 pairing_cb.sdp_attempts++;
1519 btif_dm_get_remote_services(&bd_addr);
1520 return;
1521 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001522 prop.type = BT_PROPERTY_UUIDS;
1523 prop.len = 0;
1524 if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0))
1525 {
1526 prop.val = p_data->disc_res.p_uuid_list;
1527 prop.len = p_data->disc_res.num_uuids * MAX_UUID_SIZE;
1528 for (i=0; i < p_data->disc_res.num_uuids; i++)
1529 {
1530 char temp[256];
Chris Manton8ff3fea2015-01-07 13:59:14 -08001531 uuid_to_string_legacy((bt_uuid_t*)(p_data->disc_res.p_uuid_list + (i*MAX_UUID_SIZE)), temp);
Chris Mantonf8027002015-03-12 09:22:48 -07001532 LOG_INFO("%s index:%d uuid:%s", __func__, i, temp);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001533 }
1534 }
1535
1536 /* onUuidChanged requires getBondedDevices to be populated.
1537 ** bond_state_changed needs to be sent prior to remote_device_property
1538 */
1539 if ((pairing_cb.state == BT_BOND_STATE_BONDING) &&
Chaojing Sune2805532015-04-22 13:40:21 -07001540 ((bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0) ||
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001541 (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0)) &&
Chaojing Sune2805532015-04-22 13:40:21 -07001542 pairing_cb.sdp_attempts > 0)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001543 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001544 BTIF_TRACE_DEBUG("%s Remote Service SDP done. Call bond_state_changed_cb BONDED",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001545 __FUNCTION__);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001546 pairing_cb.sdp_attempts = 0;
Chaojing Sune2805532015-04-22 13:40:21 -07001547
1548 // If bonding occured due to cross-key pairing, send bonding callback
1549 // for static address now
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001550 if (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0)
Chaojing Sune2805532015-04-22 13:40:21 -07001551 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
1552
The Android Open Source Project5738f832012-12-12 16:00:35 -08001553 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED);
1554 }
1555
Chaojing Sune2805532015-04-22 13:40:21 -07001556 if (p_data->disc_res.num_uuids != 0)
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001557 {
1558 /* Also write this to the NVRAM */
1559 ret = btif_storage_set_remote_device_property(&bd_addr, &prop);
1560 ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);
1561 /* Send the event to the BTIF */
1562 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1563 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1564 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001565 }
1566 break;
1567
1568 case BTA_DM_DISC_CMPL_EVT:
1569 /* fixme */
1570 break;
1571
Matthew Xie607e3b72013-08-15 19:30:48 -07001572#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001573 case BTA_DM_DISC_BLE_RES_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001574 BTIF_TRACE_DEBUG("%s:, services 0x%x)", __FUNCTION__,
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001575 p_data->disc_ble_res.service.uu.uuid16);
1576 bt_uuid_t uuid;
1577 int i = 0;
1578 int j = 15;
1579 if (p_data->disc_ble_res.service.uu.uuid16 == UUID_SERVCLASS_LE_HID)
1580 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001581 BTIF_TRACE_DEBUG("%s: Found HOGP UUID",__FUNCTION__);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001582 bt_property_t prop;
1583 bt_bdaddr_t bd_addr;
1584 char temp[256];
Zhihai Xud7ee77b2013-11-05 18:06:54 -08001585 bt_status_t ret;
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001586
1587 bta_gatt_convert_uuid16_to_uuid128(uuid.uu,p_data->disc_ble_res.service.uu.uuid16);
1588
1589 while(i < j )
1590 {
1591 unsigned char c = uuid.uu[j];
1592 uuid.uu[j] = uuid.uu[i];
1593 uuid.uu[i] = c;
1594 i++;
1595 j--;
1596 }
1597
Chris Manton8ff3fea2015-01-07 13:59:14 -08001598 uuid_to_string_legacy(&uuid, temp);
Chris Mantonf8027002015-03-12 09:22:48 -07001599 LOG_INFO("%s uuid:%s", __func__, temp);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001600
1601 bdcpy(bd_addr.address, p_data->disc_ble_res.bd_addr);
1602 prop.type = BT_PROPERTY_UUIDS;
1603 prop.val = uuid.uu;
1604 prop.len = MAX_UUID_SIZE;
1605
Zhihai Xud7ee77b2013-11-05 18:06:54 -08001606 /* Also write this to the NVRAM */
1607 ret = btif_storage_set_remote_device_property(&bd_addr, &prop);
1608 ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);
1609
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001610 /* Send the event to the BTIF */
1611 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1612 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1613
1614 }
1615 break;
Matthew Xie607e3b72013-08-15 19:30:48 -07001616#endif /* BLE_INCLUDED */
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001617
The Android Open Source Project5738f832012-12-12 16:00:35 -08001618 default:
1619 {
1620 ASSERTC(0, "unhandled search services event", event);
1621 }
1622 break;
1623 }
1624}
1625
1626/*******************************************************************************
1627**
1628** Function btif_dm_remote_service_record_evt
1629**
1630** Description Executes search service record event in btif context
1631**
1632** Returns void
1633**
1634*******************************************************************************/
1635static void btif_dm_remote_service_record_evt(UINT16 event, char *p_param)
1636{
1637 tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param;
1638
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001639 BTIF_TRACE_EVENT("%s: event = %d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001640 switch (event)
1641 {
1642 case BTA_DM_DISC_RES_EVT:
1643 {
1644 bt_service_record_t rec;
1645 bt_property_t prop;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001646 bt_bdaddr_t bd_addr;
1647
1648 memset(&rec, 0, sizeof(bt_service_record_t));
1649 bdcpy(bd_addr.address, p_data->disc_res.bd_addr);
1650
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001651 BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001652 p_data->disc_res.result, p_data->disc_res.services);
1653 prop.type = BT_PROPERTY_SERVICE_RECORD;
1654 prop.val = (void*)&rec;
1655 prop.len = sizeof(rec);
1656
1657 /* disc_res.result is overloaded with SCN. Cannot check result */
1658 p_data->disc_res.services &= ~BTA_USER_SERVICE_MASK;
1659 /* TODO: Get the UUID as well */
1660 rec.channel = p_data->disc_res.result - 3;
1661 /* TODO: Need to get the service name using p_raw_data */
1662 rec.name[0] = 0;
1663
1664 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1665 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1666 }
1667 break;
1668
1669 default:
1670 {
1671 ASSERTC(0, "unhandled remote service record event", event);
1672 }
1673 break;
1674 }
1675}
1676
1677/*******************************************************************************
1678**
1679** Function btif_dm_upstreams_cback
1680**
1681** Description Executes UPSTREAMS events in btif context
1682**
1683** Returns void
1684**
1685*******************************************************************************/
1686static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
1687{
The Android Open Source Project5738f832012-12-12 16:00:35 -08001688 tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)p_param;
1689 tBTA_SERVICE_MASK service_mask;
1690 uint32_t i;
1691 bt_bdaddr_t bd_addr;
1692
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001693 BTIF_TRACE_EVENT("btif_dm_upstreams_cback ev: %s", dump_dm_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001694
1695 switch (event)
1696 {
1697 case BTA_DM_ENABLE_EVT:
1698 {
1699 BD_NAME bdname;
1700 bt_status_t status;
1701 bt_property_t prop;
1702 prop.type = BT_PROPERTY_BDNAME;
1703 prop.len = BD_NAME_LEN;
1704 prop.val = (void*)bdname;
1705
1706 status = btif_storage_get_adapter_property(&prop);
Matthew Xie1e5109b2012-11-09 18:26:26 -08001707 if (status == BT_STATUS_SUCCESS)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001708 {
1709 /* A name exists in the storage. Make this the device name */
1710 BTA_DmSetDeviceName((char*)prop.val);
1711 }
Matthew Xie1e5109b2012-11-09 18:26:26 -08001712 else
1713 {
1714 /* Storage does not have a name yet.
1715 * Use the default name and write it to the chip
1716 */
1717 BTA_DmSetDeviceName(btif_get_default_local_name());
1718 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001719
Andre Eisenbacha015a832014-09-11 14:09:40 -07001720#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1721 /* Enable local privacy */
Andre Eisenbach3e0dc732014-10-24 09:55:34 -07001722 BTA_DmBleConfigLocalPrivacy(BLE_LOCAL_PRIVACY_ENABLED);
Andre Eisenbacha015a832014-09-11 14:09:40 -07001723#endif
1724
The Android Open Source Project5738f832012-12-12 16:00:35 -08001725 /* for each of the enabled services in the mask, trigger the profile
1726 * enable */
1727 service_mask = btif_get_enabled_services_mask();
1728 for (i=0; i <= BTA_MAX_SERVICE_ID; i++)
1729 {
1730 if (service_mask &
1731 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i)))
1732 {
1733 btif_in_execute_service_request(i, TRUE);
1734 }
1735 }
1736 /* clear control blocks */
1737 memset(&pairing_cb, 0, sizeof(btif_dm_pairing_cb_t));
Satya Calloji877123f2015-04-23 23:39:49 -07001738 pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001739
1740 /* This function will also trigger the adapter_properties_cb
1741 ** and bonded_devices_info_cb
1742 */
1743 btif_storage_load_bonded_devices();
1744
1745 btif_storage_load_autopair_device_list();
1746
Zach Johnson39110ec2014-10-06 13:15:00 -07001747 btif_enable_bluetooth_evt(p_data->enable.status);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001748 }
1749 break;
1750
1751 case BTA_DM_DISABLE_EVT:
1752 /* for each of the enabled services in the mask, trigger the profile
1753 * disable */
1754 service_mask = btif_get_enabled_services_mask();
1755 for (i=0; i <= BTA_MAX_SERVICE_ID; i++)
1756 {
1757 if (service_mask &
1758 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i)))
1759 {
1760 btif_in_execute_service_request(i, FALSE);
1761 }
1762 }
1763 btif_disable_bluetooth_evt();
1764 break;
1765
1766 case BTA_DM_PIN_REQ_EVT:
1767 btif_dm_pin_req_evt(&p_data->pin_req);
1768 break;
1769
1770 case BTA_DM_AUTH_CMPL_EVT:
1771 btif_dm_auth_cmpl_evt(&p_data->auth_cmpl);
1772 break;
1773
1774 case BTA_DM_BOND_CANCEL_CMPL_EVT:
1775 if (pairing_cb.state == BT_BOND_STATE_BONDING)
1776 {
1777 bdcpy(bd_addr.address, pairing_cb.bd_addr);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001778 btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001779 bond_state_changed(p_data->bond_cancel_cmpl.result, &bd_addr, BT_BOND_STATE_NONE);
1780 }
1781 break;
1782
1783 case BTA_DM_SP_CFM_REQ_EVT:
1784 btif_dm_ssp_cfm_req_evt(&p_data->cfm_req);
1785 break;
1786 case BTA_DM_SP_KEY_NOTIF_EVT:
1787 btif_dm_ssp_key_notif_evt(&p_data->key_notif);
1788 break;
1789
1790 case BTA_DM_DEV_UNPAIRED_EVT:
1791 bdcpy(bd_addr.address, p_data->link_down.bd_addr);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001792 btm_set_bond_type_dev(p_data->link_down.bd_addr, BOND_TYPE_UNKNOWN);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001793
1794 /*special handling for HID devices */
1795 #if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -07001796 btif_hh_remove_device(bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001797 #endif
Hemant Gupta94c15ec2013-11-11 12:33:44 +05301798 #if (defined(BTA_HD_INCLUDED) && (BTA_HD_INCLUDED == TRUE))
1799 btif_hd_remove_device(bd_addr);
1800 #endif
1801 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1802 btif_storage_remove_ble_bonding_keys(&bd_addr);
1803 #endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001804 btif_storage_remove_bonded_device(&bd_addr);
1805 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
1806 break;
1807
1808 case BTA_DM_BUSY_LEVEL_EVT:
1809 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001810
1811 if (p_data->busy_level.level_flags & BTM_BL_INQUIRY_PAGING_MASK)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001812 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001813 if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_STARTED)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001814 {
1815 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb,
1816 BT_DISCOVERY_STARTED);
1817 btif_dm_inquiry_in_progress = TRUE;
1818 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001819 else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_CANCELLED)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001820 {
1821 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb,
1822 BT_DISCOVERY_STOPPED);
1823 btif_dm_inquiry_in_progress = FALSE;
1824 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001825 else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_COMPLETE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001826 {
1827 btif_dm_inquiry_in_progress = FALSE;
1828 }
1829 }
1830 }break;
1831
1832 case BTA_DM_LINK_UP_EVT:
1833 bdcpy(bd_addr.address, p_data->link_up.bd_addr);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001834 BTIF_TRACE_DEBUG("BTA_DM_LINK_UP_EVT. Sending BT_ACL_STATE_CONNECTED");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001835
1836 btif_update_remote_version_property(&bd_addr);
1837
The Android Open Source Project5738f832012-12-12 16:00:35 -08001838 HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS,
1839 &bd_addr, BT_ACL_STATE_CONNECTED);
1840 break;
1841
1842 case BTA_DM_LINK_DOWN_EVT:
1843 bdcpy(bd_addr.address, p_data->link_down.bd_addr);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07001844 btm_set_bond_type_dev(p_data->link_down.bd_addr, BOND_TYPE_UNKNOWN);
Anubhav Gupta791692a2013-12-06 17:11:11 +05301845 btif_av_move_idle(bd_addr);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001846 BTIF_TRACE_DEBUG("BTA_DM_LINK_DOWN_EVT. Sending BT_ACL_STATE_DISCONNECTED");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001847 HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS,
1848 &bd_addr, BT_ACL_STATE_DISCONNECTED);
1849 break;
1850
1851 case BTA_DM_HW_ERROR_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001852 BTIF_TRACE_ERROR("Received H/W Error. ");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001853 /* Flush storage data */
1854 btif_config_flush();
1855 usleep(100000); /* 100milliseconds */
1856 /* Killing the process to force a restart as part of fault tolerance */
1857 kill(getpid(), SIGKILL);
1858 break;
1859
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001860#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1861 case BTA_DM_BLE_KEY_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001862 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 -08001863
1864 /* If this pairing is by-product of local initiated GATT client Read or Write,
1865 BTA would not have sent BTA_DM_BLE_SEC_REQ_EVT event and Bond state would not
1866 have setup properly. Setup pairing_cb and notify App about Bonding state now*/
1867 if (pairing_cb.state != BT_BOND_STATE_BONDING)
1868 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001869 BTIF_TRACE_DEBUG("Bond state not sent to App so far.Notify the app now");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001870 bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t*)p_data->ble_key.bd_addr,
1871 BT_BOND_STATE_BONDING);
1872 }
1873 else if (memcmp (pairing_cb.bd_addr, p_data->ble_key.bd_addr, BD_ADDR_LEN)!=0)
1874 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001875 BTIF_TRACE_ERROR("BD mismatch discard BLE key_type=%d ",p_data->ble_key.key_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001876 break;
1877 }
1878
1879 switch (p_data->ble_key.key_type)
1880 {
1881 case BTA_LE_KEY_PENC:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001882 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PENC");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001883 pairing_cb.ble.is_penc_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001884 pairing_cb.ble.penc_key = p_data->ble_key.p_key_value->penc_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001885 break;
1886
1887 case BTA_LE_KEY_PID:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001888 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PID");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001889 pairing_cb.ble.is_pid_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001890 pairing_cb.ble.pid_key = p_data->ble_key.p_key_value->pid_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001891 break;
1892
1893 case BTA_LE_KEY_PCSRK:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001894 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PCSRK");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001895 pairing_cb.ble.is_pcsrk_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001896 pairing_cb.ble.pcsrk_key = p_data->ble_key.p_key_value->pcsrk_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001897 break;
1898
1899 case BTA_LE_KEY_LENC:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001900 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LENC");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001901 pairing_cb.ble.is_lenc_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001902 pairing_cb.ble.lenc_key = p_data->ble_key.p_key_value->lenc_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001903 break;
1904
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001905 case BTA_LE_KEY_LCSRK:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001906 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LCSRK");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001907 pairing_cb.ble.is_lcsrk_key_rcvd = TRUE;
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07001908 pairing_cb.ble.lcsrk_key = p_data->ble_key.p_key_value->lcsrk_key;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001909 break;
1910
Satya Calloji444a8da2015-03-06 10:38:22 -08001911 case BTA_LE_KEY_LID:
1912 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LID");
1913 pairing_cb.ble.is_lidk_key_rcvd = TRUE;
1914 break;
1915
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001916 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001917 BTIF_TRACE_ERROR("unknown BLE key type (0x%02x)", p_data->ble_key.key_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001918 break;
1919 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001920 break;
1921 case BTA_DM_BLE_SEC_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001922 BTIF_TRACE_DEBUG("BTA_DM_BLE_SEC_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001923 btif_dm_ble_sec_req_evt(&p_data->ble_req);
1924 break;
1925 case BTA_DM_BLE_PASSKEY_NOTIF_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001926 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_NOTIF_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001927 btif_dm_ble_key_notif_evt(&p_data->key_notif);
1928 break;
1929 case BTA_DM_BLE_PASSKEY_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001930 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001931 btif_dm_ble_passkey_req_evt(&p_data->pin_req);
1932 break;
Satya Calloji444a8da2015-03-06 10:38:22 -08001933 case BTA_DM_BLE_NC_REQ_EVT:
1934 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_REQ_EVT. ");
1935 btif_dm_ble_key_nc_req_evt(&p_data->key_notif);
1936 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001937 case BTA_DM_BLE_OOB_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001938 BTIF_TRACE_DEBUG("BTA_DM_BLE_OOB_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001939 break;
1940 case BTA_DM_BLE_LOCAL_IR_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001941 BTIF_TRACE_DEBUG("BTA_DM_BLE_LOCAL_IR_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001942 ble_local_key_cb.is_id_keys_rcvd = TRUE;
Satya Calloji444a8da2015-03-06 10:38:22 -08001943 memcpy(&ble_local_key_cb.id_keys.irk[0],
1944 &p_data->ble_id_keys.irk[0], sizeof(BT_OCTET16));
1945 memcpy(&ble_local_key_cb.id_keys.ir[0],
1946 &p_data->ble_id_keys.ir[0], sizeof(BT_OCTET16));
1947 memcpy(&ble_local_key_cb.id_keys.dhk[0],
1948 &p_data->ble_id_keys.dhk[0], sizeof(BT_OCTET16));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001949 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.irk[0],
Satya Calloji7bd40382015-05-19 14:42:32 -07001950 BTIF_DM_LE_LOCAL_KEY_IRK,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001951 BT_OCTET16_LEN);
1952 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.ir[0],
Satya Calloji7bd40382015-05-19 14:42:32 -07001953 BTIF_DM_LE_LOCAL_KEY_IR,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001954 BT_OCTET16_LEN);
1955 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.dhk[0],
1956 BTIF_DM_LE_LOCAL_KEY_DHK,
1957 BT_OCTET16_LEN);
1958 break;
1959 case BTA_DM_BLE_LOCAL_ER_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001960 BTIF_TRACE_DEBUG("BTA_DM_BLE_LOCAL_ER_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001961 ble_local_key_cb.is_er_rcvd = TRUE;
1962 memcpy(&ble_local_key_cb.er[0], &p_data->ble_er[0], sizeof(BT_OCTET16));
1963 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.er[0],
1964 BTIF_DM_LE_LOCAL_KEY_ER,
1965 BT_OCTET16_LEN);
1966 break;
1967
1968 case BTA_DM_BLE_AUTH_CMPL_EVT:
Satya Calloji444a8da2015-03-06 10:38:22 -08001969 BTIF_TRACE_DEBUG("BTA_DM_BLE_AUTH_CMPL_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001970 btif_dm_ble_auth_cmpl_evt(&p_data->auth_cmpl);
1971 break;
Ganesh Ganapathi Batta9546abf2014-05-30 16:28:00 -07001972
1973 case BTA_DM_LE_FEATURES_READ:
1974 {
1975 tBTM_BLE_VSC_CB cmn_vsc_cb;
1976 bt_local_le_features_t local_le_features;
1977 char buf[512];
1978 bt_property_t prop;
1979 prop.type = BT_PROPERTY_LOCAL_LE_FEATURES;
1980 prop.val = (void*)buf;
1981 prop.len = sizeof(buf);
1982
1983 /* LE features are not stored in storage. Should be retrived from stack */
1984 BTM_BleGetVendorCapabilities(&cmn_vsc_cb);
1985 local_le_features.local_privacy_enabled = BTM_BleLocalPrivacyEnabled();
1986
1987 prop.len = sizeof (bt_local_le_features_t);
1988 if (cmn_vsc_cb.filter_support == 1)
1989 local_le_features.max_adv_filter_supported = cmn_vsc_cb.max_filter;
1990 else
1991 local_le_features.max_adv_filter_supported = 0;
1992 local_le_features.max_adv_instance = cmn_vsc_cb.adv_inst_max;
1993 local_le_features.max_irk_list_size = cmn_vsc_cb.max_irk_list_sz;
1994 local_le_features.rpa_offload_supported = cmn_vsc_cb.rpa_offloading;
Satya Callojiefaddcb2014-07-28 23:22:05 -07001995 local_le_features.activity_energy_info_supported = cmn_vsc_cb.energy_support;
Satya Callojif5387072015-02-09 17:40:52 -08001996 local_le_features.scan_result_storage_size = cmn_vsc_cb.tot_scan_results_strg;
1997 local_le_features.version_supported = cmn_vsc_cb.version_supported;
1998 local_le_features.total_trackable_advertisers =
1999 cmn_vsc_cb.total_trackable_advertisers;
Satya Calloji5725fc62015-03-31 13:24:32 -07002000
2001 local_le_features.extended_scan_support = cmn_vsc_cb.extended_scan_support > 0;
2002 local_le_features.debug_logging_supported = cmn_vsc_cb.debug_logging_supported > 0;
2003
Ganesh Ganapathi Batta9546abf2014-05-30 16:28:00 -07002004 memcpy(prop.val, &local_le_features, prop.len);
2005 HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, BT_STATUS_SUCCESS, 1, &prop);
2006 break;
2007 }
Satya Callojie5ba8842014-07-03 17:18:02 -07002008
2009 case BTA_DM_ENER_INFO_READ:
2010 {
2011 btif_activity_energy_info_cb_t *p_ener_data = (btif_activity_energy_info_cb_t*) p_param;
2012 bt_activity_energy_info energy_info;
2013 energy_info.status = p_ener_data->status;
2014 energy_info.ctrl_state = p_ener_data->ctrl_state;
2015 energy_info.rx_time = p_ener_data->rx_time;
2016 energy_info.tx_time = p_ener_data->tx_time;
2017 energy_info.idle_time = p_ener_data->idle_time;
2018 energy_info.energy_used = p_ener_data->energy_used;
2019 HAL_CBACK(bt_hal_cbacks, energy_info_cb, &energy_info);
2020 break;
2021 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002022#endif
2023
The Android Open Source Project5738f832012-12-12 16:00:35 -08002024 case BTA_DM_AUTHORIZE_EVT:
2025 case BTA_DM_SIG_STRENGTH_EVT:
2026 case BTA_DM_SP_RMT_OOB_EVT:
2027 case BTA_DM_SP_KEYPRESS_EVT:
2028 case BTA_DM_ROLE_CHG_EVT:
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002029
The Android Open Source Project5738f832012-12-12 16:00:35 -08002030 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002031 BTIF_TRACE_WARNING( "btif_dm_cback : unhandled event (%d)", event );
The Android Open Source Project5738f832012-12-12 16:00:35 -08002032 break;
2033 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002034
Andre Eisenbach8a057242015-04-29 22:27:15 -07002035 btif_dm_data_free(event, p_data);
2036}
The Android Open Source Project5738f832012-12-12 16:00:35 -08002037
2038/*******************************************************************************
2039**
2040** Function btif_dm_generic_evt
2041**
2042** Description Executes non-BTA upstream events in BTIF context
2043**
2044** Returns void
2045**
2046*******************************************************************************/
2047static void btif_dm_generic_evt(UINT16 event, char* p_param)
2048{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002049 BTIF_TRACE_EVENT("%s: event=%d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002050 switch(event)
2051 {
2052 case BTIF_DM_CB_DISCOVERY_STARTED:
2053 {
2054 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STARTED);
2055 }
2056 break;
2057
2058 case BTIF_DM_CB_CREATE_BOND:
2059 {
Andre Eisenbach31a64002014-10-14 14:29:19 -07002060 pairing_cb.timeout_retries = NUM_TIMEOUT_RETRIES;
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002061 btif_dm_create_bond_cb_t *create_bond_cb = (btif_dm_create_bond_cb_t*)p_param;
2062 btif_dm_cb_create_bond(&create_bond_cb->bdaddr, create_bond_cb->transport);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002063 }
2064 break;
2065
2066 case BTIF_DM_CB_REMOVE_BOND:
2067 {
2068 btif_dm_cb_remove_bond((bt_bdaddr_t *)p_param);
2069 }
2070 break;
2071
2072 case BTIF_DM_CB_HID_REMOTE_NAME:
2073 {
2074 btif_dm_cb_hid_remote_name((tBTM_REMOTE_DEV_NAME *)p_param);
2075 }
2076 break;
2077
2078 case BTIF_DM_CB_BOND_STATE_BONDING:
2079 {
2080 bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t *)p_param, BT_BOND_STATE_BONDING);
2081 }
2082 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002083 case BTIF_DM_CB_LE_TX_TEST:
2084 case BTIF_DM_CB_LE_RX_TEST:
2085 {
2086 uint8_t status;
2087 STREAM_TO_UINT8(status, p_param);
2088 HAL_CBACK(bt_hal_cbacks, le_test_mode_cb,
2089 (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, 0);
2090 }
2091 break;
2092 case BTIF_DM_CB_LE_TEST_END:
2093 {
2094 uint8_t status;
2095 uint16_t count = 0;
2096 STREAM_TO_UINT8(status, p_param);
2097 if (status == 0)
2098 STREAM_TO_UINT16(count, p_param);
2099 HAL_CBACK(bt_hal_cbacks, le_test_mode_cb,
2100 (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, count);
2101 }
2102 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002103 default:
2104 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002105 BTIF_TRACE_WARNING("%s : Unknown event 0x%x", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002106 }
2107 break;
2108 }
2109}
2110
2111/*******************************************************************************
2112**
2113** Function bte_dm_evt
2114**
2115** Description Switches context from BTE to BTIF for all DM events
2116**
2117** Returns void
2118**
2119*******************************************************************************/
2120
2121void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data)
2122{
The Android Open Source Project5738f832012-12-12 16:00:35 -08002123 /* switch context to btif task context (copy full union size for convenience) */
Andre Eisenbach8a057242015-04-29 22:27:15 -07002124 bt_status_t status = btif_transfer_context(btif_dm_upstreams_evt, (uint16_t)event,
2125 (void*)p_data, sizeof(tBTA_DM_SEC), btif_dm_data_copy);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002126
2127 /* catch any failed context transfers */
2128 ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status);
2129}
2130
2131/*******************************************************************************
2132**
2133** Function bte_search_devices_evt
2134**
2135** Description Switches context from BTE to BTIF for DM search events
2136**
2137** Returns void
2138**
2139*******************************************************************************/
2140static void bte_search_devices_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
2141{
2142 UINT16 param_len = 0;
2143
2144 if (p_data)
2145 param_len += sizeof(tBTA_DM_SEARCH);
2146 /* Allocate buffer to hold the pointers (deep copy). The pointers will point to the end of the tBTA_DM_SEARCH */
2147 switch (event)
2148 {
2149 case BTA_DM_INQ_RES_EVT:
2150 {
2151 if (p_data->inq_res.p_eir)
2152 param_len += HCI_EXT_INQ_RESPONSE_LEN;
2153 }
2154 break;
2155
2156 case BTA_DM_DISC_RES_EVT:
2157 {
2158 if (p_data->disc_res.raw_data_size && p_data->disc_res.p_raw_data)
2159 param_len += p_data->disc_res.raw_data_size;
2160 }
2161 break;
2162 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002163 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 -08002164
2165 /* if remote name is available in EIR, set teh flag so that stack doesnt trigger RNR */
2166 if (event == BTA_DM_INQ_RES_EVT)
2167 p_data->inq_res.remt_name_not_required = check_eir_remote_name(p_data, NULL, NULL);
2168
2169 btif_transfer_context (btif_dm_search_devices_evt , (UINT16) event, (void *)p_data, param_len,
2170 (param_len > sizeof(tBTA_DM_SEARCH)) ? search_devices_copy_cb : NULL);
2171}
2172
2173/*******************************************************************************
2174**
2175** Function bte_dm_search_services_evt
2176**
2177** Description Switches context from BTE to BTIF for DM search services
2178** event
2179**
2180** Returns void
2181**
2182*******************************************************************************/
2183static void bte_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
2184{
2185 UINT16 param_len = 0;
2186 if (p_data)
2187 param_len += sizeof(tBTA_DM_SEARCH);
2188 switch (event)
2189 {
2190 case BTA_DM_DISC_RES_EVT:
2191 {
2192 if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0)) {
2193 param_len += (p_data->disc_res.num_uuids * MAX_UUID_SIZE);
2194 }
2195 } break;
2196 }
2197 /* TODO: The only other member that needs a deep copy is the p_raw_data. But not sure
2198 * if raw_data is needed. */
2199 btif_transfer_context(btif_dm_search_services_evt, event, (char*)p_data, param_len,
2200 (param_len > sizeof(tBTA_DM_SEARCH)) ? search_services_copy_cb : NULL);
2201}
2202
2203/*******************************************************************************
2204**
2205** Function bte_dm_remote_service_record_evt
2206**
2207** Description Switches context from BTE to BTIF for DM search service
2208** record event
2209**
2210** Returns void
2211**
2212*******************************************************************************/
2213static void bte_dm_remote_service_record_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
2214{
2215 /* TODO: The only member that needs a deep copy is the p_raw_data. But not sure yet if this is needed. */
2216 btif_transfer_context(btif_dm_remote_service_record_evt, event, (char*)p_data, sizeof(tBTA_DM_SEARCH), NULL);
2217}
2218
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07002219#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Satya Callojie5ba8842014-07-03 17:18:02 -07002220/*******************************************************************************
2221**
2222** Function bta_energy_info_cb
2223**
2224** Description Switches context from BTE to BTIF for DM energy info event
2225**
2226** Returns void
2227**
2228*******************************************************************************/
2229static void bta_energy_info_cb(tBTA_DM_BLE_TX_TIME_MS tx_time, tBTA_DM_BLE_RX_TIME_MS rx_time,
2230 tBTA_DM_BLE_IDLE_TIME_MS idle_time,
2231 tBTA_DM_BLE_ENERGY_USED energy_used,
2232 tBTA_DM_CONTRL_STATE ctrl_state, tBTA_STATUS status)
2233{
2234 BTIF_TRACE_DEBUG("energy_info_cb-Status:%d,state=%d,tx_t=%ld, rx_t=%ld, idle_time=%ld,used=%ld",
2235 status, ctrl_state, tx_time, rx_time, idle_time, energy_used);
2236
2237 btif_activity_energy_info_cb_t btif_cb;
2238 btif_cb.status = status;
2239 btif_cb.ctrl_state = ctrl_state;
2240 btif_cb.tx_time = (uint64_t) tx_time;
2241 btif_cb.rx_time = (uint64_t) rx_time;
2242 btif_cb.idle_time =(uint64_t) idle_time;
2243 btif_cb.energy_used =(uint64_t) energy_used;
2244 btif_transfer_context(btif_dm_upstreams_evt, BTA_DM_ENER_INFO_READ,
2245 (char*) &btif_cb, sizeof(btif_activity_energy_info_cb_t), NULL);
2246}
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07002247#endif
Satya Callojie5ba8842014-07-03 17:18:02 -07002248
Satya Calloji6e2d9db2014-07-08 16:18:58 -07002249/*******************************************************************************
2250**
2251** Function bte_scan_filt_param_cfg_evt
2252**
2253** Description Scan filter param config event
2254**
2255** Returns void
2256**
2257*******************************************************************************/
2258static void bte_scan_filt_param_cfg_evt(UINT8 action_type,
2259 tBTA_DM_BLE_PF_AVBL_SPACE avbl_space,
2260 tBTA_DM_BLE_REF_VALUE ref_value, tBTA_STATUS status)
2261{
2262 /* This event occurs on calling BTA_DmBleCfgFilterCondition internally,
2263 ** and that is why there is no HAL callback
2264 */
2265 if(BTA_SUCCESS != status)
2266 {
2267 BTIF_TRACE_ERROR("%s, %d", __FUNCTION__, status);
2268 }
2269 else
2270 {
2271 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
2272 }
2273}
2274
The Android Open Source Project5738f832012-12-12 16:00:35 -08002275/*****************************************************************************
2276**
2277** btif api functions (no context switch)
2278**
2279*****************************************************************************/
2280
2281/*******************************************************************************
2282**
2283** Function btif_dm_start_discovery
2284**
2285** Description Start device discovery/inquiry
2286**
2287** Returns bt_status_t
2288**
2289*******************************************************************************/
2290bt_status_t btif_dm_start_discovery(void)
2291{
2292 tBTA_DM_INQ inq_params;
2293 tBTA_SERVICE_MASK services = 0;
Satya Calloji6e2d9db2014-07-08 16:18:58 -07002294 tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002295
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002296 BTIF_TRACE_EVENT("%s", __FUNCTION__);
Satya Calloji6e2d9db2014-07-08 16:18:58 -07002297
2298#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2299 memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
2300 /* Cleanup anything remaining on index 0 */
2301 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL,
2302 bte_scan_filt_param_cfg_evt, 0);
2303
2304 /* Add an allow-all filter on index 0*/
2305 adv_filt_param.dely_mode = IMMEDIATE_DELY_MODE;
2306 adv_filt_param.feat_seln = ALLOW_ALL_FILTER;
2307 adv_filt_param.filt_logic_type = BTA_DM_BLE_PF_FILT_LOGIC_OR;
2308 adv_filt_param.list_logic_type = BTA_DM_BLE_PF_LIST_LOGIC_OR;
2309 adv_filt_param.rssi_low_thres = LOWEST_RSSI_VALUE;
2310 adv_filt_param.rssi_high_thres = LOWEST_RSSI_VALUE;
2311 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_ADD, 0, &adv_filt_param, NULL,
2312 bte_scan_filt_param_cfg_evt, 0);
2313
The Android Open Source Project5738f832012-12-12 16:00:35 -08002314 /* TODO: Do we need to handle multiple inquiries at the same time? */
2315
2316 /* Set inquiry params and call API */
The Android Open Source Project5738f832012-12-12 16:00:35 -08002317 inq_params.mode = BTA_DM_GENERAL_INQUIRY|BTA_BLE_GENERAL_INQUIRY;
Matthew Xie7f3e4292013-09-30 12:44:10 -07002318#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
2319 inq_params.intl_duration[0]= BTIF_DM_INTERLEAVE_DURATION_BR_ONE;
2320 inq_params.intl_duration[1]= BTIF_DM_INTERLEAVE_DURATION_LE_ONE;
2321 inq_params.intl_duration[2]= BTIF_DM_INTERLEAVE_DURATION_BR_TWO;
2322 inq_params.intl_duration[3]= BTIF_DM_INTERLEAVE_DURATION_LE_TWO;
2323#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002324#else
2325 inq_params.mode = BTA_DM_GENERAL_INQUIRY;
2326#endif
2327 inq_params.duration = BTIF_DM_DEFAULT_INQ_MAX_DURATION;
2328
2329 inq_params.max_resps = BTIF_DM_DEFAULT_INQ_MAX_RESULTS;
2330 inq_params.report_dup = TRUE;
2331
2332 inq_params.filter_type = BTA_DM_INQ_CLR;
2333 /* TODO: Filter device by BDA needs to be implemented here */
2334
2335 /* Will be enabled to TRUE once inquiry busy level has been received */
2336 btif_dm_inquiry_in_progress = FALSE;
2337 /* find nearby devices */
2338 BTA_DmSearch(&inq_params, services, bte_search_devices_evt);
2339
2340 return BT_STATUS_SUCCESS;
2341}
2342
2343/*******************************************************************************
2344**
2345** Function btif_dm_cancel_discovery
2346**
2347** Description Cancels search
2348**
2349** Returns bt_status_t
2350**
2351*******************************************************************************/
2352bt_status_t btif_dm_cancel_discovery(void)
2353{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002354 BTIF_TRACE_EVENT("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002355 BTA_DmSearchCancel();
2356 return BT_STATUS_SUCCESS;
2357}
2358
2359/*******************************************************************************
2360**
2361** Function btif_dm_create_bond
2362**
2363** Description Initiate bonding with the specified device
2364**
2365** Returns bt_status_t
2366**
2367*******************************************************************************/
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002368bt_status_t btif_dm_create_bond(const bt_bdaddr_t *bd_addr, int transport)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002369{
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002370 btif_dm_create_bond_cb_t create_bond_cb;
2371 create_bond_cb.transport = transport;
2372 bdcpy(create_bond_cb.bdaddr.address, bd_addr->address);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002373
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002374 bdstr_t bdstr;
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002375 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 -08002376 if (pairing_cb.state != BT_BOND_STATE_NONE)
2377 return BT_STATUS_BUSY;
2378
2379 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_CREATE_BOND,
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002380 (char *)&create_bond_cb, sizeof(btif_dm_create_bond_cb_t), NULL);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002381
2382 return BT_STATUS_SUCCESS;
2383}
2384
2385/*******************************************************************************
2386**
2387** Function btif_dm_cancel_bond
2388**
2389** Description Initiate bonding with the specified device
2390**
2391** Returns bt_status_t
2392**
2393*******************************************************************************/
2394
2395bt_status_t btif_dm_cancel_bond(const bt_bdaddr_t *bd_addr)
2396{
2397 bdstr_t bdstr;
2398
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002399 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 -08002400
2401 /* TODO:
2402 ** 1. Restore scan modes
2403 ** 2. special handling for HID devices
2404 */
2405 if (pairing_cb.state == BT_BOND_STATE_BONDING)
2406 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002407
2408#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2409
2410 if (pairing_cb.is_ssp)
2411 {
2412 if (pairing_cb.is_le_only)
2413 {
2414 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT);
2415 }
2416 else
Hemant Guptae1468692013-11-14 16:21:29 +05302417 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002418 BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE);
Hemant Guptae1468692013-11-14 16:21:29 +05302419 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2420 btif_storage_remove_bonded_device((bt_bdaddr_t *)bd_addr);
2421 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002422 }
2423 else
2424 {
2425 if (pairing_cb.is_le_only)
2426 {
2427 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2428 }
2429 else
2430 {
2431 BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL);
2432 }
2433 /* Cancel bonding, in case it is in ACL connection setup state */
2434 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2435 }
2436
2437#else
The Android Open Source Project5738f832012-12-12 16:00:35 -08002438 if (pairing_cb.is_ssp)
2439 {
2440 BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE);
2441 }
2442 else
2443 {
2444 BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL);
2445 }
2446 /* Cancel bonding, in case it is in ACL connection setup state */
2447 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2448 btif_storage_remove_bonded_device((bt_bdaddr_t *)bd_addr);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002449#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002450 }
2451
2452 return BT_STATUS_SUCCESS;
2453}
2454
2455/*******************************************************************************
2456**
Hemant Guptada33b462015-04-26 10:32:57 +05302457** Function btif_dm_hh_open_success
2458**
2459** Description Checks if device is blacklisted, if yes takes appropriate action
2460**
2461** Returns none
2462**
2463*******************************************************************************/
2464
2465void btif_dm_hh_open_success(bt_bdaddr_t *bdaddr)
2466{
2467 if (pairing_cb.state == BT_BOND_STATE_BONDING &&
2468 bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0)
2469 {
2470 if (check_if_auth_bl(bdaddr)
2471 && check_cod_hid(bdaddr, COD_HID_MAJOR))
2472 {
2473 bt_status_t status;
2474 LINK_KEY link_key = {0};
2475 bond_state_changed(BT_STATUS_SUCCESS, bdaddr, BT_BOND_STATE_BONDED);
2476 BTIF_TRACE_DEBUG("%s: Device is blacklisted for authentication", __func__);
2477 bt_property_t prop;
2478 bt_uuid_t uuid;
2479 char uuid_str[128] = UUID_HUMAN_INTERFACE_DEVICE;
2480 string_to_uuid(uuid_str, &uuid);
2481 prop.type = BT_PROPERTY_UUIDS;
2482 prop.val = uuid.uu;
2483 prop.len = MAX_UUID_SIZE;
2484 // Also write this to the NVRAM
2485 status = btif_storage_set_remote_device_property(bdaddr, &prop);
2486 ASSERTC(status == BT_STATUS_SUCCESS, "storing remote services failed", status);
2487 // Store fake link for device as bonded in nvram,
2488 // otherwise on device reboot/bt off-on device will not be shown in paired list.
2489 btif_storage_add_bonded_device(bdaddr, link_key, HCI_LKEY_TYPE_UNAUTH_COMB, 0);
2490 // Send the event to the BTIF
2491 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
2492 BT_STATUS_SUCCESS, bdaddr, 1, &prop);
2493 }
2494 }
2495}
2496
2497/*******************************************************************************
2498**
Kim Schulza9eb25c2013-09-30 10:55:52 +02002499** Function btif_dm_hh_open_failed
2500**
2501** Description informs the upper layers if the HH have failed during bonding
2502**
2503** Returns none
2504**
2505*******************************************************************************/
2506
2507void btif_dm_hh_open_failed(bt_bdaddr_t *bdaddr)
2508{
2509 if (pairing_cb.state == BT_BOND_STATE_BONDING &&
2510 bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0)
2511 {
2512 bond_state_changed(BT_STATUS_FAIL, bdaddr, BT_BOND_STATE_NONE);
2513 }
2514}
2515
2516/*******************************************************************************
2517**
The Android Open Source Project5738f832012-12-12 16:00:35 -08002518** Function btif_dm_remove_bond
2519**
2520** Description Removes bonding with the specified device
2521**
2522** Returns bt_status_t
2523**
2524*******************************************************************************/
2525
2526bt_status_t btif_dm_remove_bond(const bt_bdaddr_t *bd_addr)
2527{
2528 bdstr_t bdstr;
2529
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002530 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 -08002531 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_REMOVE_BOND,
2532 (char *)bd_addr, sizeof(bt_bdaddr_t), NULL);
2533
2534 return BT_STATUS_SUCCESS;
2535}
2536
2537/*******************************************************************************
2538**
2539** Function btif_dm_pin_reply
2540**
2541** Description BT legacy pairing - PIN code reply
2542**
2543** Returns bt_status_t
2544**
2545*******************************************************************************/
2546
2547bt_status_t btif_dm_pin_reply( const bt_bdaddr_t *bd_addr, uint8_t accept,
2548 uint8_t pin_len, bt_pin_code_t *pin_code)
2549{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002550 BTIF_TRACE_EVENT("%s: accept=%d", __FUNCTION__, accept);
Hemant Gupta831423e2014-01-08 12:42:13 +05302551 if (pin_code == NULL)
2552 return BT_STATUS_FAIL;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002553#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002554
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002555 if (pairing_cb.is_le_only)
2556 {
2557 int i;
2558 UINT32 passkey = 0;
2559 int multi[] = {100000, 10000, 1000, 100, 10,1};
2560 BD_ADDR remote_bd_addr;
2561 bdcpy(remote_bd_addr, bd_addr->address);
2562 for (i = 0; i < 6; i++)
2563 {
2564 passkey += (multi[i] * (pin_code->pin[i] - '0'));
2565 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002566 BTIF_TRACE_DEBUG("btif_dm_pin_reply: passkey: %d", passkey);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002567 BTA_DmBlePasskeyReply(remote_bd_addr, accept, passkey);
2568
2569 }
2570 else
2571 {
2572 BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin);
2573 if (accept)
2574 pairing_cb.pin_code_len = pin_len;
2575 }
2576#else
The Android Open Source Project5738f832012-12-12 16:00:35 -08002577 BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin);
2578
2579 if (accept)
2580 pairing_cb.pin_code_len = pin_len;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002581#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002582 return BT_STATUS_SUCCESS;
2583}
2584
2585/*******************************************************************************
2586**
2587** Function btif_dm_ssp_reply
2588**
2589** Description BT SSP Reply - Just Works, Numeric Comparison & Passkey Entry
2590**
2591** Returns bt_status_t
2592**
2593*******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -08002594bt_status_t btif_dm_ssp_reply(const bt_bdaddr_t *bd_addr,
2595 bt_ssp_variant_t variant, uint8_t accept,
2596 uint32_t passkey)
2597{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002598 UNUSED(passkey);
2599
The Android Open Source Project5738f832012-12-12 16:00:35 -08002600 if (variant == BT_SSP_VARIANT_PASSKEY_ENTRY)
2601 {
2602 /* This is not implemented in the stack.
2603 * For devices with display, this is not needed
2604 */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002605 BTIF_TRACE_WARNING("%s: Not implemented", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002606 return BT_STATUS_FAIL;
2607 }
2608 /* BT_SSP_VARIANT_CONSENT & BT_SSP_VARIANT_PASSKEY_CONFIRMATION supported */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002609 BTIF_TRACE_EVENT("%s: accept=%d", __FUNCTION__, accept);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002610#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2611 if (pairing_cb.is_le_only)
2612 {
Satya Calloji7fb0da62015-01-29 20:40:17 -08002613 if(pairing_cb.is_le_nc)
2614 {
2615 BTA_DmBleConfirmReply((UINT8 *)bd_addr->address,accept);
2616 } else {
2617 if (accept)
2618 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_GRANTED);
2619 else
2620 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT);
2621 }
2622 } else {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002623 BTA_DmConfirm( (UINT8 *)bd_addr->address, accept);
Satya Calloji7fb0da62015-01-29 20:40:17 -08002624 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002625#else
2626 BTA_DmConfirm( (UINT8 *)bd_addr->address, accept);
2627#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002628 return BT_STATUS_SUCCESS;
2629}
2630
2631/*******************************************************************************
2632**
2633** Function btif_dm_get_adapter_property
2634**
2635** Description Queries the BTA for the adapter property
2636**
2637** Returns bt_status_t
2638**
2639*******************************************************************************/
2640bt_status_t btif_dm_get_adapter_property(bt_property_t *prop)
2641{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002642 BTIF_TRACE_EVENT("%s: type=0x%x", __FUNCTION__, prop->type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002643 switch (prop->type)
2644 {
2645 case BT_PROPERTY_BDNAME:
2646 {
2647 bt_bdname_t *bd_name = (bt_bdname_t*)prop->val;
VenkatRaghavan VijayaRaghavan4540f592015-02-05 04:40:47 -08002648 strncpy((char *)bd_name->name, (char *)btif_get_default_local_name(),
VenkatRaghavan VijayaRaghavan1d8e6b82015-02-05 22:20:39 -08002649 sizeof(bd_name->name) - 1);
2650 bd_name->name[sizeof(bd_name->name) - 1] = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002651 prop->len = strlen((char *)bd_name->name);
2652 }
2653 break;
2654
2655 case BT_PROPERTY_ADAPTER_SCAN_MODE:
2656 {
2657 /* if the storage does not have it. Most likely app never set it. Default is NONE */
2658 bt_scan_mode_t *mode = (bt_scan_mode_t*)prop->val;
2659 *mode = BT_SCAN_MODE_NONE;
2660 prop->len = sizeof(bt_scan_mode_t);
2661 }
2662 break;
2663
2664 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
2665 {
2666 uint32_t *tmt = (uint32_t*)prop->val;
2667 *tmt = 120; /* default to 120s, if not found in NV */
2668 prop->len = sizeof(uint32_t);
2669 }
2670 break;
2671
2672 default:
2673 prop->len = 0;
2674 return BT_STATUS_FAIL;
2675 }
2676 return BT_STATUS_SUCCESS;
2677}
2678
2679/*******************************************************************************
2680**
2681** Function btif_dm_get_remote_services
2682**
2683** Description Start SDP to get remote services
2684**
2685** Returns bt_status_t
2686**
2687*******************************************************************************/
2688bt_status_t btif_dm_get_remote_services(bt_bdaddr_t *remote_addr)
2689{
2690 bdstr_t bdstr;
2691
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002692 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 -08002693
2694 BTA_DmDiscover(remote_addr->address, BTA_ALL_SERVICE_MASK,
2695 bte_dm_search_services_evt, TRUE);
2696
2697 return BT_STATUS_SUCCESS;
2698}
2699
2700/*******************************************************************************
2701**
Nitin Arorab4365c52015-06-25 18:30:09 -07002702** Function btif_dm_get_remote_services_transport
2703**
2704** Description Start SDP to get remote services by transport
2705**
2706** Returns bt_status_t
2707**
2708*******************************************************************************/
2709bt_status_t btif_dm_get_remote_services_by_transport(bt_bdaddr_t *remote_addr, const int transport)
2710{
2711 BTIF_TRACE_EVENT("%s", __func__);
2712
2713 /* Set the mask extension */
2714 tBTA_SERVICE_MASK_EXT mask_ext;
2715 mask_ext.num_uuid = 0;
2716 mask_ext.p_uuid = NULL;
2717 mask_ext.srvc_mask = BTA_ALL_SERVICE_MASK;
2718
2719 BTA_DmDiscoverByTransport(remote_addr->address, &mask_ext,
2720 bte_dm_search_services_evt, TRUE, transport);
2721
2722 return BT_STATUS_SUCCESS;
2723}
2724
2725/*******************************************************************************
2726**
The Android Open Source Project5738f832012-12-12 16:00:35 -08002727** Function btif_dm_get_remote_service_record
2728**
2729** Description Start SDP to get remote service record
2730**
2731**
2732** Returns bt_status_t
2733*******************************************************************************/
2734bt_status_t btif_dm_get_remote_service_record(bt_bdaddr_t *remote_addr,
2735 bt_uuid_t *uuid)
2736{
2737 tSDP_UUID sdp_uuid;
2738 bdstr_t bdstr;
2739
Sharvil Nanavati8a6a89f2014-08-20 09:39:25 -07002740 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 -08002741
2742 sdp_uuid.len = MAX_UUID_SIZE;
2743 memcpy(sdp_uuid.uu.uuid128, uuid->uu, MAX_UUID_SIZE);
2744
2745 BTA_DmDiscoverUUID(remote_addr->address, &sdp_uuid,
2746 bte_dm_remote_service_record_evt, TRUE);
2747
2748 return BT_STATUS_SUCCESS;
2749}
2750
2751void btif_dm_execute_service_request(UINT16 event, char *p_param)
2752{
2753 BOOLEAN b_enable = FALSE;
2754 bt_status_t status;
2755 if (event == BTIF_DM_ENABLE_SERVICE)
2756 {
2757 b_enable = TRUE;
2758 }
2759 status = btif_in_execute_service_request(*((tBTA_SERVICE_ID*)p_param), b_enable);
2760 if (status == BT_STATUS_SUCCESS)
2761 {
2762 bt_property_t property;
2763 bt_uuid_t local_uuids[BT_MAX_NUM_UUIDS];
2764
2765 /* Now send the UUID_PROPERTY_CHANGED event to the upper layer */
2766 BTIF_STORAGE_FILL_PROPERTY(&property, BT_PROPERTY_UUIDS,
2767 sizeof(local_uuids), local_uuids);
2768 btif_storage_get_adapter_property(&property);
2769 HAL_CBACK(bt_hal_cbacks, adapter_properties_cb,
2770 BT_STATUS_SUCCESS, 1, &property);
2771 }
2772 return;
2773}
2774
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002775void btif_dm_proc_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, tBTA_OOB_DATA *p_oob_data,
2776 tBTA_AUTH_REQ *p_auth_req, BOOLEAN is_orig)
2777{
2778 UINT8 yes_no_bit = BTA_AUTH_SP_YES & *p_auth_req;
2779 /* if local initiated:
2780 ** 1. set DD + MITM
2781 ** if remote initiated:
2782 ** 1. Copy over the auth_req from peer's io_rsp
2783 ** 2. Set the MITM if peer has it set or if peer has DisplayYesNo (iPhone)
2784 ** as a fallback set MITM+GB if peer had MITM set
2785 */
2786 UNUSED (bd_addr);
2787 UNUSED (p_io_cap);
2788 UNUSED (p_oob_data);
2789
2790
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002791 BTIF_TRACE_DEBUG("+%s: p_auth_req=%d", __FUNCTION__, *p_auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002792 if(pairing_cb.is_local_initiated)
2793 {
2794 /* if initing/responding to a dedicated bonding, use dedicate bonding bit */
2795 *p_auth_req = BTA_AUTH_DD_BOND | BTA_AUTH_SP_YES;
2796 }
2797 else if (!is_orig)
2798 {
2799 /* peer initiated paring. They probably know what they want.
2800 ** Copy the mitm from peer device.
2801 */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002802 BTIF_TRACE_DEBUG("%s: setting p_auth_req to peer's: %d",
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002803 __FUNCTION__, pairing_cb.auth_req);
2804 *p_auth_req = (pairing_cb.auth_req & BTA_AUTH_BONDS);
2805
2806 /* copy over the MITM bit as well. In addition if the peer has DisplayYesNo, force MITM */
2807 if ((yes_no_bit) || (pairing_cb.io_cap & BTM_IO_CAP_IO) )
2808 *p_auth_req |= BTA_AUTH_SP_YES;
2809 }
2810 else if (yes_no_bit)
2811 {
2812 /* set the general bonding bit for stored device */
2813 *p_auth_req = BTA_AUTH_GEN_BOND | yes_no_bit;
2814 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002815 BTIF_TRACE_DEBUG("-%s: p_auth_req=%d", __FUNCTION__, *p_auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002816}
2817
2818void btif_dm_proc_io_rsp(BD_ADDR bd_addr, tBTA_IO_CAP io_cap,
2819 tBTA_OOB_DATA oob_data, tBTA_AUTH_REQ auth_req)
2820{
2821 UNUSED (bd_addr);
2822 UNUSED (oob_data);
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002823
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002824 if(auth_req & BTA_AUTH_BONDS)
2825 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002826 BTIF_TRACE_DEBUG("%s auth_req:%d", __FUNCTION__, auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002827 pairing_cb.auth_req = auth_req;
2828 pairing_cb.io_cap = io_cap;
2829 }
2830}
2831
The Android Open Source Project5738f832012-12-12 16:00:35 -08002832#if (BTM_OOB_INCLUDED == TRUE)
2833void btif_dm_set_oob_for_io_req(tBTA_OOB_DATA *p_oob_data)
2834{
2835 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2836 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
2837 {
2838 *p_oob_data = FALSE;
2839 }
2840 else
2841 {
2842 *p_oob_data = TRUE;
2843 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002844 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 -08002845}
2846#endif /* BTM_OOB_INCLUDED */
2847
2848#ifdef BTIF_DM_OOB_TEST
2849void btif_dm_load_local_oob(void)
2850{
Nick Kralevichd70b7a82013-01-31 14:40:15 -08002851 char prop_oob[PROPERTY_VALUE_MAX];
The Android Open Source Project5738f832012-12-12 16:00:35 -08002852 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002853 BTIF_TRACE_DEBUG("btif_dm_load_local_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002854 if (prop_oob[0] != '3')
2855 {
2856#if (BTM_OOB_INCLUDED == TRUE)
2857 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2858 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
2859 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002860 BTIF_TRACE_DEBUG("btif_dm_load_local_oob: read OOB, call BTA_DmLocalOob()");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002861 BTA_DmLocalOob();
2862 }
2863#else
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002864 BTIF_TRACE_ERROR("BTM_OOB_INCLUDED is FALSE!!(btif_dm_load_local_oob)");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002865#endif
2866 }
2867}
2868
2869void btif_dm_proc_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r)
2870{
2871 FILE *fp;
2872 char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
2873 char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
2874 char *path = NULL;
Nick Kralevichd70b7a82013-01-31 14:40:15 -08002875 char prop_oob[PROPERTY_VALUE_MAX];
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002876 BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob: valid=%d", valid);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002877 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2878 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 &&
2879 valid)
2880 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002881 BTIF_TRACE_DEBUG("save local OOB data in memory");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002882 memcpy(oob_cb.sp_c, c, BT_OCTET16_LEN);
2883 memcpy(oob_cb.sp_r, r, BT_OCTET16_LEN);
2884 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002885 BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002886 if (prop_oob[0] == '1')
2887 path = path_a;
2888 else if (prop_oob[0] == '2')
2889 path = path_b;
2890 if (path)
2891 {
2892 fp = fopen(path, "wb+");
2893 if (fp == NULL)
2894 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002895 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 -08002896 }
2897 else
2898 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002899 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 -08002900 fwrite (c , 1 , BT_OCTET16_LEN , fp );
2901 fwrite (r , 1 , BT_OCTET16_LEN , fp );
2902 fclose(fp);
2903 }
2904 }
2905 }
2906}
2907BOOLEAN btif_dm_proc_rmt_oob(BD_ADDR bd_addr, BT_OCTET16 p_c, BT_OCTET16 p_r)
2908{
2909 char t[128];
2910 FILE *fp;
2911 char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
2912 char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
2913 char *path = NULL;
Nick Kralevichd70b7a82013-01-31 14:40:15 -08002914 char prop_oob[PROPERTY_VALUE_MAX];
The Android Open Source Project5738f832012-12-12 16:00:35 -08002915 BOOLEAN result = FALSE;
2916 bt_bdaddr_t bt_bd_addr;
2917 bdcpy(oob_cb.oob_bdaddr, bd_addr);
2918 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002919 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002920 if (prop_oob[0] == '1')
2921 path = path_b;
2922 else if (prop_oob[0] == '2')
2923 path = path_a;
2924 if (path)
2925 {
2926 fp = fopen(path, "rb");
2927 if (fp == NULL)
2928 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002929 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 -08002930 return FALSE;
2931 }
2932 else
2933 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002934 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob: read OOB data from %s",path);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002935 fread (p_c , 1 , BT_OCTET16_LEN , fp );
2936 fread (p_r , 1 , BT_OCTET16_LEN , fp );
2937 fclose(fp);
2938 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002939 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: TRUE");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002940 sprintf(t, "%02x:%02x:%02x:%02x:%02x:%02x",
2941 oob_cb.oob_bdaddr[0], oob_cb.oob_bdaddr[1], oob_cb.oob_bdaddr[2],
2942 oob_cb.oob_bdaddr[3], oob_cb.oob_bdaddr[4], oob_cb.oob_bdaddr[5]);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002943 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: peer_bdaddr = %s", t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002944 sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
2945 p_c[0], p_c[1], p_c[2], p_c[3], p_c[4], p_c[5], p_c[6], p_c[7],
2946 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 -07002947 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: c = %s",t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002948 sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
2949 p_r[0], p_r[1], p_r[2], p_r[3], p_r[4], p_r[5], p_r[6], p_r[7],
2950 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 -07002951 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: r = %s",t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002952 bdcpy(bt_bd_addr.address, bd_addr);
2953 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_BOND_STATE_BONDING,
2954 (char *)&bt_bd_addr, sizeof(bt_bdaddr_t), NULL);
2955 result = TRUE;
2956 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002957 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob result=%d",result);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002958 return result;
2959}
2960#endif /* BTIF_DM_OOB_TEST */
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002961#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2962
2963static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif)
2964{
2965 bt_bdaddr_t bd_addr;
2966 bt_bdname_t bd_name;
2967 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08002968 int dev_type;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002969
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002970 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002971
2972 /* Remote name update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08002973 if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type))
2974 {
2975 dev_type = BT_DEVICE_TYPE_BLE;
2976 }
2977 btif_dm_update_ble_remote_properties(p_ssp_key_notif->bd_addr , p_ssp_key_notif->bd_name,
2978 (tBT_DEVICE_TYPE) dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002979 bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
2980 memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
2981
2982 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
2983 pairing_cb.is_ssp = FALSE;
2984 cod = COD_UNCLASSIFIED;
2985
2986 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
2987 cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION,
2988 p_ssp_key_notif->passkey);
2989}
2990
2991/*******************************************************************************
2992**
2993** Function btif_dm_ble_auth_cmpl_evt
2994**
2995** Description Executes authentication complete event in btif context
2996**
2997** Returns void
2998**
2999*******************************************************************************/
3000static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
3001{
3002 /* Save link key, if not temporary */
3003 bt_bdaddr_t bd_addr;
3004 bt_status_t status = BT_STATUS_FAIL;
3005 bt_bond_state_t state = BT_BOND_STATE_NONE;
3006
3007 bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
3008 if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
3009 {
3010 /* store keys */
3011 }
3012 if (p_auth_cmpl->success)
3013 {
3014 status = BT_STATUS_SUCCESS;
3015 state = BT_BOND_STATE_BONDED;
Satya Calloji7cb76b42015-05-07 09:45:00 -07003016 int addr_type;
3017 bt_bdaddr_t bdaddr;
3018 bdcpy(bdaddr.address, p_auth_cmpl->bd_addr);
3019 if (btif_storage_get_remote_addr_type(&bdaddr, &addr_type) != BT_STATUS_SUCCESS)
3020 btif_storage_set_remote_addr_type(&bdaddr, p_auth_cmpl->addr_type);
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07003021
3022 /* Test for temporary bonding */
3023 if (btm_get_bond_type_dev(p_auth_cmpl->bd_addr) == BOND_TYPE_TEMPORARY) {
3024 BTIF_TRACE_DEBUG("%s: sending BT_BOND_STATE_NONE for Temp pairing",
3025 __func__);
3026 btif_storage_remove_bonded_device(&bdaddr);
3027 state = BT_BOND_STATE_NONE;
3028 } else {
3029 btif_dm_save_ble_bonding_keys();
3030 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003031 BTA_GATTC_Refresh(bd_addr.address);
Nitin Arorab4365c52015-06-25 18:30:09 -07003032 btif_dm_get_remote_services_by_transport(&bd_addr, BTA_GATT_TRANSPORT_LE);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003033 }
3034 else
3035 {
3036 /*Map the HCI fail reason to bt status */
3037 switch (p_auth_cmpl->fail_reason)
3038 {
Priti Aghera156c52b2014-07-09 14:58:19 -07003039 case BTA_DM_AUTH_SMP_PAIR_AUTH_FAIL:
3040 case BTA_DM_AUTH_SMP_CONFIRM_VALUE_FAIL:
3041 btif_dm_remove_ble_bonding_keys();
3042 status = BT_STATUS_AUTH_FAILURE;
3043 break;
3044 case BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT:
3045 status = BT_STATUS_AUTH_REJECTED;
3046 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003047 default:
Andre Eisenbachca22ac42013-02-13 17:02:11 +09003048 btif_dm_remove_ble_bonding_keys();
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003049 status = BT_STATUS_FAIL;
3050 break;
3051 }
3052 }
3053 bond_state_changed(status, &bd_addr, state);
3054}
3055
3056
3057
3058void btif_dm_load_ble_local_keys(void)
3059{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003060 memset(&ble_local_key_cb, 0, sizeof(btif_dm_local_key_cb_t));
3061
3062 if (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_ER,(char*)&ble_local_key_cb.er[0],
3063 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)
3064 {
3065 ble_local_key_cb.is_er_rcvd = TRUE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003066 BTIF_TRACE_DEBUG("%s BLE ER key loaded",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003067 }
3068
3069 if ((btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IR,(char*)&ble_local_key_cb.id_keys.ir[0],
3070 BT_OCTET16_LEN)== BT_STATUS_SUCCESS )&&
3071 (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IRK, (char*)&ble_local_key_cb.id_keys.irk[0],
3072 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)&&
3073 (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_DHK,(char*)&ble_local_key_cb.id_keys.dhk[0],
3074 BT_OCTET16_LEN)== BT_STATUS_SUCCESS))
3075 {
3076 ble_local_key_cb.is_id_keys_rcvd = TRUE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003077 BTIF_TRACE_DEBUG("%s BLE ID keys loaded",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003078 }
3079
3080}
3081void btif_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
3082 tBTA_BLE_LOCAL_ID_KEYS *p_id_keys)
3083{
3084 if (ble_local_key_cb.is_er_rcvd )
3085 {
3086 memcpy(&er[0], &ble_local_key_cb.er[0], sizeof(BT_OCTET16));
3087 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ER;
3088 }
3089
3090 if (ble_local_key_cb.is_id_keys_rcvd)
3091 {
3092 memcpy(&p_id_keys->ir[0], &ble_local_key_cb.id_keys.ir[0], sizeof(BT_OCTET16));
3093 memcpy(&p_id_keys->irk[0], &ble_local_key_cb.id_keys.irk[0], sizeof(BT_OCTET16));
3094 memcpy(&p_id_keys->dhk[0], &ble_local_key_cb.id_keys.dhk[0], sizeof(BT_OCTET16));
3095 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID;
3096 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003097 BTIF_TRACE_DEBUG("%s *p_key_mask=0x%02x",__FUNCTION__, *p_key_mask);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003098}
3099
3100void btif_dm_save_ble_bonding_keys(void)
3101{
3102
3103 bt_bdaddr_t bd_addr;
3104
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003105 BTIF_TRACE_DEBUG("%s",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003106
3107 bdcpy(bd_addr.address, pairing_cb.bd_addr);
3108
3109 if (pairing_cb.ble.is_penc_key_rcvd)
3110 {
3111 btif_storage_add_ble_bonding_key(&bd_addr,
3112 (char *) &pairing_cb.ble.penc_key,
3113 BTIF_DM_LE_KEY_PENC,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003114 sizeof(tBTM_LE_PENC_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003115 }
3116
3117 if (pairing_cb.ble.is_pid_key_rcvd)
3118 {
3119 btif_storage_add_ble_bonding_key(&bd_addr,
Andre Eisenbach5e808462014-10-21 12:37:53 -07003120 (char *) &pairing_cb.ble.pid_key,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003121 BTIF_DM_LE_KEY_PID,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003122 sizeof(tBTM_LE_PID_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003123 }
3124
3125
3126 if (pairing_cb.ble.is_pcsrk_key_rcvd)
3127 {
3128 btif_storage_add_ble_bonding_key(&bd_addr,
3129 (char *) &pairing_cb.ble.pcsrk_key,
3130 BTIF_DM_LE_KEY_PCSRK,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003131 sizeof(tBTM_LE_PCSRK_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003132 }
3133
3134
3135 if (pairing_cb.ble.is_lenc_key_rcvd)
3136 {
3137 btif_storage_add_ble_bonding_key(&bd_addr,
3138 (char *) &pairing_cb.ble.lenc_key,
3139 BTIF_DM_LE_KEY_LENC,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003140 sizeof(tBTM_LE_LENC_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003141 }
3142
3143 if (pairing_cb.ble.is_lcsrk_key_rcvd)
3144 {
3145 btif_storage_add_ble_bonding_key(&bd_addr,
3146 (char *) &pairing_cb.ble.lcsrk_key,
3147 BTIF_DM_LE_KEY_LCSRK,
Andre Eisenbache87ef6d2015-05-01 13:14:59 -07003148 sizeof(tBTM_LE_LCSRK_KEYS));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003149 }
3150
Satya Calloji444a8da2015-03-06 10:38:22 -08003151 if (pairing_cb.ble.is_lidk_key_rcvd)
3152 {
3153 btif_storage_add_ble_bonding_key(&bd_addr,
3154 NULL,
3155 BTIF_DM_LE_KEY_LID,
3156 0);
3157 }
3158
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003159}
3160
3161
3162void btif_dm_remove_ble_bonding_keys(void)
3163{
3164 bt_bdaddr_t bd_addr;
3165
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003166 BTIF_TRACE_DEBUG("%s",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003167
3168 bdcpy(bd_addr.address, pairing_cb.bd_addr);
3169 btif_storage_remove_ble_bonding_keys(&bd_addr);
3170}
3171
3172
3173/*******************************************************************************
3174**
3175** Function btif_dm_ble_sec_req_evt
3176**
3177** Description Eprocess security request event in btif context
3178**
3179** Returns void
3180**
3181*******************************************************************************/
3182void btif_dm_ble_sec_req_evt(tBTA_DM_BLE_SEC_REQ *p_ble_req)
3183{
3184 bt_bdaddr_t bd_addr;
3185 bt_bdname_t bd_name;
3186 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08003187 int dev_type;
3188
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003189 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003190
3191 if (pairing_cb.state == BT_BOND_STATE_BONDING)
3192 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003193 BTIF_TRACE_DEBUG("%s Discard security request", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003194 return;
3195 }
3196
3197 /* Remote name update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08003198 if (!btif_get_device_type(p_ble_req->bd_addr, &dev_type))
3199 {
3200 dev_type = BT_DEVICE_TYPE_BLE;
3201 }
3202 btif_dm_update_ble_remote_properties(p_ble_req->bd_addr, p_ble_req->bd_name,
3203 (tBT_DEVICE_TYPE) dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003204
3205 bdcpy(bd_addr.address, p_ble_req->bd_addr);
3206 memcpy(bd_name.name, p_ble_req->bd_name, BD_NAME_LEN);
3207
3208 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
3209
Andre Eisenbach89363762015-01-26 13:49:36 -08003210 pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003211 pairing_cb.is_le_only = TRUE;
Satya Calloji7fb0da62015-01-29 20:40:17 -08003212 pairing_cb.is_le_nc = FALSE;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003213 pairing_cb.is_ssp = TRUE;
Pavlin Radoslavov65f9c042015-07-16 17:40:28 -07003214 btm_set_bond_type_dev(p_ble_req->bd_addr, pairing_cb.bond_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003215
3216 cod = COD_UNCLASSIFIED;
3217
3218 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod,
3219 BT_SSP_VARIANT_CONSENT, 0);
3220}
3221
3222
3223
3224/*******************************************************************************
3225**
3226** Function btif_dm_ble_passkey_req_evt
3227**
3228** Description Executes pin request event in btif context
3229**
3230** Returns void
3231**
3232*******************************************************************************/
3233static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
3234{
3235 bt_bdaddr_t bd_addr;
3236 bt_bdname_t bd_name;
3237 UINT32 cod;
Matthew Xie86f97ed2014-11-10 10:24:46 -08003238 int dev_type;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003239
3240 /* Remote name update */
Matthew Xie86f97ed2014-11-10 10:24:46 -08003241 if (!btif_get_device_type(p_pin_req->bd_addr, &dev_type))
3242 {
3243 dev_type = BT_DEVICE_TYPE_BLE;
3244 }
3245 btif_dm_update_ble_remote_properties(p_pin_req->bd_addr,p_pin_req->bd_name,
3246 (tBT_DEVICE_TYPE) dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003247
3248 bdcpy(bd_addr.address, p_pin_req->bd_addr);
3249 memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN);
3250
3251 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
3252 pairing_cb.is_le_only = TRUE;
3253
3254 cod = COD_UNCLASSIFIED;
3255
3256 HAL_CBACK(bt_hal_cbacks, pin_request_cb,
Casper Bonde818d0f22015-05-21 11:08:45 +02003257 &bd_addr, &bd_name, cod, FALSE);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003258}
Satya Calloji444a8da2015-03-06 10:38:22 -08003259static void btif_dm_ble_key_nc_req_evt(tBTA_DM_SP_KEY_NOTIF *p_notif_req)
3260{
3261 /* TODO implement key notification for numeric comparison */
3262 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003263
Satya Calloji444a8da2015-03-06 10:38:22 -08003264 /* Remote name update */
3265 btif_update_remote_properties(p_notif_req->bd_addr , p_notif_req->bd_name,
3266 NULL, BT_DEVICE_TYPE_BLE);
3267
3268 bt_bdaddr_t bd_addr;
3269 bdcpy(bd_addr.address, p_notif_req->bd_addr);
3270
3271 bt_bdname_t bd_name;
3272 memcpy(bd_name.name, p_notif_req->bd_name, BD_NAME_LEN);
3273
3274 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
3275 pairing_cb.is_ssp = FALSE;
Satya Calloji7fb0da62015-01-29 20:40:17 -08003276 pairing_cb.is_le_only = TRUE;
3277 pairing_cb.is_le_nc = TRUE;
Satya Calloji444a8da2015-03-06 10:38:22 -08003278
3279 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
3280 COD_UNCLASSIFIED, BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
3281 p_notif_req->passkey);
3282}
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003283
3284void btif_dm_update_ble_remote_properties( BD_ADDR bd_addr, BD_NAME bd_name,
3285 tBT_DEVICE_TYPE dev_type)
3286{
3287 btif_update_remote_properties(bd_addr,bd_name,NULL,dev_type);
3288}
3289
3290static void btif_dm_ble_tx_test_cback(void *p)
3291{
3292 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TX_TEST,
3293 (char *)p, 1, NULL);
3294}
3295
3296static void btif_dm_ble_rx_test_cback(void *p)
3297{
3298 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_RX_TEST,
3299 (char *)p, 1, NULL);
3300}
3301
3302static void btif_dm_ble_test_end_cback(void *p)
3303{
3304 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TEST_END,
3305 (char *)p, 3, NULL);
3306}
3307/*******************************************************************************
3308**
3309** Function btif_le_test_mode
3310**
3311** Description Sends a HCI BLE Test command to the Controller
3312**
3313** Returns BT_STATUS_SUCCESS on success
3314**
3315*******************************************************************************/
3316bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t len)
3317{
3318 switch (opcode) {
3319 case HCI_BLE_TRANSMITTER_TEST:
3320 if (len != 3) return BT_STATUS_PARM_INVALID;
3321 BTM_BleTransmitterTest(buf[0],buf[1],buf[2], btif_dm_ble_tx_test_cback);
3322 break;
3323 case HCI_BLE_RECEIVER_TEST:
3324 if (len != 1) return BT_STATUS_PARM_INVALID;
3325 BTM_BleReceiverTest(buf[0], btif_dm_ble_rx_test_cback);
3326 break;
3327 case HCI_BLE_TEST_END:
3328 BTM_BleTestEnd((tBTM_CMPL_CB*) btif_dm_ble_test_end_cback);
3329 break;
3330 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003331 BTIF_TRACE_ERROR("%s: Unknown LE Test Mode Command 0x%x", __FUNCTION__, opcode);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003332 return BT_STATUS_UNSUPPORTED;
3333 }
3334 return BT_STATUS_SUCCESS;
3335}
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003336#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08003337
3338void btif_dm_on_disable()
3339{
3340 /* cancel any pending pairing requests */
3341 if (pairing_cb.state == BT_BOND_STATE_BONDING)
3342 {
3343 bt_bdaddr_t bd_addr;
3344
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003345 BTIF_TRACE_DEBUG("%s: Cancel pending pairing request", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003346 bdcpy(bd_addr.address, pairing_cb.bd_addr);
3347 btif_dm_cancel_bond(&bd_addr);
3348 }
3349}
Matthew Xie1e5109b2012-11-09 18:26:26 -08003350
Satya Callojie5ba8842014-07-03 17:18:02 -07003351/*******************************************************************************
3352**
3353** Function btif_dm_read_energy_info
3354**
3355** Description Reads the energy info from controller
3356**
3357** Returns void
3358**
3359*******************************************************************************/
3360void btif_dm_read_energy_info()
3361{
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07003362#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Satya Callojie5ba8842014-07-03 17:18:02 -07003363 BTA_DmBleGetEnergyInfo(bta_energy_info_cb);
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07003364#endif
Satya Callojie5ba8842014-07-03 17:18:02 -07003365}
3366
Matthew Xie1e5109b2012-11-09 18:26:26 -08003367static char* btif_get_default_local_name() {
3368 if (btif_default_local_name[0] == '\0')
3369 {
3370 int max_len = sizeof(btif_default_local_name) - 1;
3371 if (BTM_DEF_LOCAL_NAME[0] != '\0')
3372 {
3373 strncpy(btif_default_local_name, BTM_DEF_LOCAL_NAME, max_len);
3374 }
3375 else
3376 {
3377 char prop_model[PROPERTY_VALUE_MAX];
3378 property_get(PROPERTY_PRODUCT_MODEL, prop_model, "");
3379 strncpy(btif_default_local_name, prop_model, max_len);
3380 }
3381 btif_default_local_name[max_len] = '\0';
3382 }
3383 return btif_default_local_name;
3384}