blob: 1f35395c2c47aac3b02336391115c4dc71733b8e [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
Hemant Gupta87ebae02013-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 ***********************************************************************************/
29#include <stdio.h>
30#include <stdlib.h>
31#include <unistd.h>
32
33#include <hardware/bluetooth.h>
34
35#include <utils/Log.h>
36#include <cutils/properties.h>
37#include "gki.h"
38#include "btu.h"
39#include "bd.h"
40#include "bta_api.h"
41#include "btif_api.h"
42#include "btif_util.h"
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080043#include "btif_dm.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080044#include "btif_storage.h"
45#include "btif_hh.h"
Hemant Gupta87ebae02013-11-11 12:33:44 +053046#include "btif_hd.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080047#include "btif_config.h"
48
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080049#include "bta_gatt_api.h"
Andre Eisenbach31a64002014-10-14 14:29:19 -070050
51/******************************************************************************
52** Device specific workarounds
53******************************************************************************/
54
55/**
56 * The devices below have proven problematic during the pairing process, often
57 * requiring multiple retries to complete pairing. To avoid degrading the user
58 * experience for other devices, explicitely blacklist troubled devices here.
59 */
60static const UINT8 blacklist_pairing_retries[][3] = {
61 {0x9C, 0xDF, 0x03} // BMW car kits (Harman/Becker)
62};
63
64BOOLEAN blacklistPairingRetries(BD_ADDR bd_addr)
65{
66 const unsigned blacklist_size = sizeof(blacklist_pairing_retries)
67 / sizeof(blacklist_pairing_retries[0]);
68 for (unsigned i = 0; i != blacklist_size; ++i)
69 {
70 if (blacklist_pairing_retries[i][0] == bd_addr[0] &&
71 blacklist_pairing_retries[i][1] == bd_addr[1] &&
72 blacklist_pairing_retries[i][2] == bd_addr[2])
73 return TRUE;
74 }
75 return FALSE;
76}
77
The Android Open Source Project5738f832012-12-12 16:00:35 -080078/******************************************************************************
79** Constants & Macros
80******************************************************************************/
Ajay Kumarc2dffa22014-06-11 22:09:20 +053081#define BTIF_DM_GET_REMOTE_PROP(b,t,v,l,p) \
82 {p.type=t;p.val=v;p.len=l;btif_storage_get_remote_device_property(b,&p);}
The Android Open Source Project5738f832012-12-12 16:00:35 -080083
84#define COD_UNCLASSIFIED ((0x1F) << 8)
Priti Agheraebb1d752012-11-27 18:03:22 -080085#define COD_HID_KEYBOARD 0x0540
86#define COD_HID_POINTING 0x0580
87#define COD_HID_COMBO 0x05C0
88#define COD_HID_MAJOR 0x0500
89#define COD_AV_HEADSETS 0x0404
90#define COD_AV_HANDSFREE 0x0408
91#define COD_AV_HEADPHONES 0x0418
92#define COD_AV_PORTABLE_AUDIO 0x041C
93#define COD_AV_HIFI_AUDIO 0x0428
The Android Open Source Project5738f832012-12-12 16:00:35 -080094
95
96#define BTIF_DM_DEFAULT_INQ_MAX_RESULTS 0
97#define BTIF_DM_DEFAULT_INQ_MAX_DURATION 10
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -070098#define BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING 2
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080099
Andre Eisenbach31a64002014-10-14 14:29:19 -0700100#define NUM_TIMEOUT_RETRIES 5
101
Matthew Xie1e5109b2012-11-09 18:26:26 -0800102#define PROPERTY_PRODUCT_MODEL "ro.product.model"
Matthew Xiea30d95a2013-09-18 12:30:36 -0700103#define DEFAULT_LOCAL_NAME_MAX 31
Matthew Xie1e5109b2012-11-09 18:26:26 -0800104#if (DEFAULT_LOCAL_NAME_MAX > BTM_MAX_LOC_BD_NAME_LEN)
105 #error "default btif local name size exceeds stack supported length"
106#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800107
Matthew Xie7f3e4292013-09-30 12:44:10 -0700108#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
109#define BTIF_DM_INTERLEAVE_DURATION_BR_ONE 2
110#define BTIF_DM_INTERLEAVE_DURATION_LE_ONE 2
111#define BTIF_DM_INTERLEAVE_DURATION_BR_TWO 3
112#define BTIF_DM_INTERLEAVE_DURATION_LE_TWO 4
113#endif
114
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800115typedef struct
116{
The Android Open Source Project5738f832012-12-12 16:00:35 -0800117 bt_bond_state_t state;
118 BD_ADDR bd_addr;
119 UINT8 is_temp;
120 UINT8 pin_code_len;
121 UINT8 is_ssp;
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -0700122 UINT8 auth_req;
123 UINT8 io_cap;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800124 UINT8 autopair_attempts;
Andre Eisenbach31a64002014-10-14 14:29:19 -0700125 UINT8 timeout_retries;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800126 UINT8 is_local_initiated;
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -0700127 UINT8 sdp_attempts;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800128#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
129 BOOLEAN is_le_only;
130 btif_dm_ble_cb_t ble;
131#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800132} btif_dm_pairing_cb_t;
133
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800134
135typedef struct
136{
137 UINT8 ir[BT_OCTET16_LEN];
138 UINT8 irk[BT_OCTET16_LEN];
139 UINT8 dhk[BT_OCTET16_LEN];
140}btif_dm_local_key_id_t;
141
142typedef struct
143{
144 BOOLEAN is_er_rcvd;
145 UINT8 er[BT_OCTET16_LEN];
146 BOOLEAN is_id_keys_rcvd;
147 btif_dm_local_key_id_t id_keys; /* ID kyes */
148
149}btif_dm_local_key_cb_t;
150
151typedef struct
152{
The Android Open Source Project5738f832012-12-12 16:00:35 -0800153 BD_ADDR bd_addr;
154 BD_NAME bd_name;
155} btif_dm_remote_name_t;
156
157typedef struct
158{
159 BT_OCTET16 sp_c;
160 BT_OCTET16 sp_r;
161 BD_ADDR oob_bdaddr; /* peer bdaddr*/
162} btif_dm_oob_cb_t;
Satya Callojie5ba8842014-07-03 17:18:02 -0700163
164typedef struct
165{
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -0700166 bt_bdaddr_t bdaddr;
167 UINT8 transport; /* 0=Unknown, 1=BR/EDR, 2=LE */
168} btif_dm_create_bond_cb_t;
169
170typedef struct
171{
Satya Callojie5ba8842014-07-03 17:18:02 -0700172 uint8_t status;
173 uint8_t ctrl_state;
174 uint64_t tx_time;
175 uint64_t rx_time;
176 uint64_t idle_time;
177 uint64_t energy_used;
178} btif_activity_energy_info_cb_t;
179
Priti Agherac0edf9f2014-06-26 11:23:51 -0700180typedef struct
181{
182 unsigned int manufact_id;
183}skip_sdp_entry_t;
184
The Android Open Source Project5738f832012-12-12 16:00:35 -0800185#define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id))
186
Priti Agherac0edf9f2014-06-26 11:23:51 -0700187#define MAX_SDP_BL_ENTRIES 3
188#define UUID_HUMAN_INTERFACE_DEVICE "00001124-0000-1000-8000-00805f9b34fb"
189
190static skip_sdp_entry_t sdp_blacklist[] = {{76}}; //Apple Mouse and Keyboard
191
Hemant Gupta29ccbb02014-07-15 23:33:32 +0530192/* hid_auth_blacklist to FIX IOP issues with hid devices
193 * that dont want to have authentication during hid connection */
194static const UINT8 hid_auth_blacklist[][3] = {
195 {0x00, 0x12, 0xa1} // Targus
196};
197
Priti Agherac0edf9f2014-06-26 11:23:51 -0700198
The Android Open Source Project5738f832012-12-12 16:00:35 -0800199/* This flag will be true if HCI_Inquiry is in progress */
200static BOOLEAN btif_dm_inquiry_in_progress = FALSE;
201
Priti Agherac0edf9f2014-06-26 11:23:51 -0700202
203
Matthew Xie1e5109b2012-11-09 18:26:26 -0800204/************************************************************************************
205** Static variables
206************************************************************************************/
207static char btif_default_local_name[DEFAULT_LOCAL_NAME_MAX+1] = {'\0'};
208
The Android Open Source Project5738f832012-12-12 16:00:35 -0800209/******************************************************************************
210** Static functions
211******************************************************************************/
212static btif_dm_pairing_cb_t pairing_cb;
213static btif_dm_oob_cb_t oob_cb;
214static void btif_dm_generic_evt(UINT16 event, char* p_param);
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -0700215static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr, tBTA_TRANSPORT transport);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800216static void btif_dm_cb_hid_remote_name(tBTM_REMOTE_DEV_NAME *p_remote_name);
217static void btif_update_remote_properties(BD_ADDR bd_addr, BD_NAME bd_name,
218 DEV_CLASS dev_class, tBT_DEVICE_TYPE dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800219#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
220static btif_dm_local_key_cb_t ble_local_key_cb;
221static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif);
222static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl);
223static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ *p_pin_req);
224#endif
Satya Calloji6e2d9db2014-07-08 16:18:58 -0700225
226static void bte_scan_filt_param_cfg_evt(UINT8 action_type,
227 tBTA_DM_BLE_PF_AVBL_SPACE avbl_space,
228 tBTA_DM_BLE_REF_VALUE ref_value, tBTA_STATUS status);
229
Matthew Xie1e5109b2012-11-09 18:26:26 -0800230static char* btif_get_default_local_name();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800231/******************************************************************************
232** Externs
233******************************************************************************/
234extern UINT16 bta_service_id_to_uuid_lkup_tbl [BTA_MAX_SERVICE_ID];
235extern bt_status_t btif_hf_execute_service(BOOLEAN b_enable);
236extern bt_status_t btif_av_execute_service(BOOLEAN b_enable);
AnubhavGuptaed0a8b12014-08-13 14:26:14 +0530237extern bt_status_t btif_avk_execute_service(BOOLEAN b_enable);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800238extern bt_status_t btif_hh_execute_service(BOOLEAN b_enable);
Hemant Gupta10256872013-08-19 18:33:01 +0530239extern bt_status_t btif_hf_client_execute_service(BOOLEAN b_enable);
Hemant Gupta2dc99992014-04-18 12:54:08 +0530240extern bt_status_t btif_mce_execute_service(BOOLEAN b_enable);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800241extern int btif_hh_connect(bt_bdaddr_t *bd_addr);
Hemant Gupta87ebae02013-11-11 12:33:44 +0530242extern bt_status_t btif_hd_execute_service(BOOLEAN b_enable);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700243extern void bta_gatt_convert_uuid16_to_uuid128(UINT8 uuid_128[LEN_UUID_128], UINT16 uuid_16);
Nitin Shivpure85495682013-09-12 21:45:59 +0530244extern void btif_av_move_idle(bt_bdaddr_t bd_addr);
Nitin Arora60ea0ed2014-08-05 11:06:23 -0700245extern BOOLEAN btif_hh_find_added_dev_by_bda(bt_bdaddr_t *bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800246
247/******************************************************************************
248** Functions
249******************************************************************************/
250
251bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id,
252 BOOLEAN b_enable)
253{
254 /* 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;
AnubhavGuptaed0a8b12014-08-13 14:26:14 +0530262 case BTA_A2DP_SRC_SERVICE_ID:
The Android Open Source Project5738f832012-12-12 16:00:35 -0800263 {
264 btif_av_execute_service(b_enable);
265 }break;
AnubhavGuptaed0a8b12014-08-13 14:26:14 +0530266 case BTA_A2DP_SINK_SERVICE_ID:
267 {
268 btif_avk_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;
Hemant Gupta2dc99992014-04-18 12:54:08 +0530278 case BTA_MAP_SERVICE_ID:
279 {
280 btif_mce_execute_service(b_enable);
281 }break;
Hemant Gupta87ebae02013-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**
Nitin Shivpure81ae1012013-06-25 16:34:00 +0530295** Function check_eir_is_remote_name_short
296**
297** Description Check if remote name is shortened
298**
299** Returns TRUE if remote name found
300** else FALSE
301**
302*******************************************************************************/
303static BOOLEAN check_eir_is_remote_name_short(tBTA_DM_SEARCH *p_search_data)
304{
305 UINT8 *p_eir_remote_name = NULL;
306 UINT8 remote_name_len = 0;
307
308 /* Check EIR for remote name and services */
309 if (p_search_data->inq_res.p_eir)
310 {
311 p_eir_remote_name = BTA_CheckEirData(p_search_data->inq_res.p_eir,
312 BTM_EIR_SHORTENED_LOCAL_NAME_TYPE, &remote_name_len);
313
314 if (p_eir_remote_name)
315 {
316 return TRUE;
317 }
318 }
319 return FALSE;
320}
321
322/*******************************************************************************
323**
The Android Open Source Project5738f832012-12-12 16:00:35 -0800324** Function check_eir_remote_name
325**
326** Description Check if remote name is in the EIR data
327**
328** Returns TRUE if remote name found
329** Populate p_remote_name, if provided and remote name found
330**
331*******************************************************************************/
332static BOOLEAN check_eir_remote_name(tBTA_DM_SEARCH *p_search_data,
333 UINT8 *p_remote_name, UINT8 *p_remote_name_len)
334{
335 UINT8 *p_eir_remote_name = NULL;
336 UINT8 remote_name_len = 0;
337
338 /* Check EIR for remote name and services */
339 if (p_search_data->inq_res.p_eir)
340 {
341 p_eir_remote_name = BTA_CheckEirData(p_search_data->inq_res.p_eir,
342 BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, &remote_name_len);
343 if (!p_eir_remote_name)
344 {
345 p_eir_remote_name = BTA_CheckEirData(p_search_data->inq_res.p_eir,
346 BTM_EIR_SHORTENED_LOCAL_NAME_TYPE, &remote_name_len);
347 }
348
349 if (p_eir_remote_name)
350 {
351 if (remote_name_len > BD_NAME_LEN)
352 remote_name_len = BD_NAME_LEN;
353
354 if (p_remote_name && p_remote_name_len)
355 {
356 memcpy(p_remote_name, p_eir_remote_name, remote_name_len);
357 *(p_remote_name + remote_name_len) = 0;
358 *p_remote_name_len = remote_name_len;
359 }
360
361 return TRUE;
362 }
363 }
364
365 return FALSE;
366
367}
368
369/*******************************************************************************
370**
371** Function check_cached_remote_name
372**
373** Description Check if remote name is in the NVRAM cache
374**
375** Returns TRUE if remote name found
376** Populate p_remote_name, if provided and remote name found
377**
378*******************************************************************************/
379static BOOLEAN check_cached_remote_name(tBTA_DM_SEARCH *p_search_data,
380 UINT8 *p_remote_name, UINT8 *p_remote_name_len)
381{
382 bt_bdname_t bdname;
383 bt_bdaddr_t remote_bdaddr;
384 bt_property_t prop_name;
385
386 /* check if we already have it in our btif_storage cache */
387 bdcpy(remote_bdaddr.address, p_search_data->inq_res.bd_addr);
388 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_BDNAME,
389 sizeof(bt_bdname_t), &bdname);
390 if (btif_storage_get_remote_device_property(
391 &remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS)
392 {
393 if (p_remote_name && p_remote_name_len)
394 {
395 strcpy((char *)p_remote_name, (char *)bdname.name);
396 *p_remote_name_len = strlen((char *)p_remote_name);
397 }
398 return TRUE;
399 }
400
401 return FALSE;
402}
403
404BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod)
405{
406 uint32_t remote_cod;
407 bt_property_t prop_name;
408
409 /* check if we already have it in our btif_storage cache */
410 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE,
411 sizeof(uint32_t), &remote_cod);
412 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS)
413 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700414 BTIF_TRACE_ERROR("%s: remote_cod = 0x%06x", __FUNCTION__, remote_cod);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800415 if ((remote_cod & 0x7ff) == cod)
416 return TRUE;
417 }
418
419 return FALSE;
420}
421
Priti Agheraebb1d752012-11-27 18:03:22 -0800422BOOLEAN check_cod_hid(const bt_bdaddr_t *remote_bdaddr, uint32_t cod)
423{
424 uint32_t remote_cod;
425 bt_property_t prop_name;
426
427 /* check if we already have it in our btif_storage cache */
428 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE,
429 sizeof(uint32_t), &remote_cod);
430 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
431 &prop_name) == BT_STATUS_SUCCESS)
432 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700433 BTIF_TRACE_DEBUG("%s: remote_cod = 0x%06x", __FUNCTION__, remote_cod);
Priti Agheraebb1d752012-11-27 18:03:22 -0800434 if ((remote_cod & 0x700) == cod)
435 return TRUE;
436 }
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700437 return FALSE;
438}
Priti Agheraebb1d752012-11-27 18:03:22 -0800439
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700440BOOLEAN check_hid_le(const bt_bdaddr_t *remote_bdaddr)
441{
442 uint32_t remote_dev_type;
443 bt_property_t prop_name;
444
445 /* check if we already have it in our btif_storage cache */
446 BTIF_STORAGE_FILL_PROPERTY(&prop_name,BT_PROPERTY_TYPE_OF_DEVICE,
447 sizeof(uint32_t), &remote_dev_type);
448 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
449 &prop_name) == BT_STATUS_SUCCESS)
450 {
451 if (remote_dev_type == BT_DEVICE_DEVTYPE_BLE)
452 {
453 bdstr_t bdstr;
454 bd2str(remote_bdaddr, &bdstr);
455 if(btif_config_exist("Remote", bdstr, "HidAppId"))
456 return TRUE;
457 }
458 }
Priti Agheraebb1d752012-11-27 18:03:22 -0800459 return FALSE;
460}
461
Priti Agherac0edf9f2014-06-26 11:23:51 -0700462/*****************************************************************************
463**
Hemant Gupta29ccbb02014-07-15 23:33:32 +0530464** Function check_if_auth_bl
465**
466** Description Checks if a given device is blacklisted to skip authentication
467**
468** Parameters remote_bdaddr
469**
470** Returns TRUE if the device is present in blacklist, else FALSE
471**
472*******************************************************************************/
473static bool check_if_auth_bl(BD_ADDR peer_dev)
474{
475 int i;
476 int blacklist_size =
477 sizeof(hid_auth_blacklist)/sizeof(hid_auth_blacklist[0]);
478 for (i = 0; i < blacklist_size; i++) {
479 if (hid_auth_blacklist[i][0] == peer_dev[0] &&
480 hid_auth_blacklist[i][1] == peer_dev[1] &&
481 hid_auth_blacklist[i][2] == peer_dev[2]) {
482 APPL_TRACE_WARNING("%02x:%02x:%02x:%02x:%02x:%02x is in blacklist for "
483 "skipping authentication", peer_dev[0], peer_dev[1], peer_dev[2],
484 peer_dev[3], peer_dev[4], peer_dev[5]);
485
486 return TRUE;
487 }
488 }
489 APPL_TRACE_DEBUG("%02x:%02x:%02x:%02x:%02x:%02x is not in blacklist for "
490 "skipping authentication", peer_dev[0], peer_dev[1], peer_dev[2],
491 peer_dev[3], peer_dev[4], peer_dev[5]);
492 return FALSE;
493}
494
495/*****************************************************************************
496**
Priti Agherac0edf9f2014-06-26 11:23:51 -0700497** Function check_sdp_bl
498**
499** Description Checks if a given device is blacklisted to skip sdp
500**
Hemant Gupta29ccbb02014-07-15 23:33:32 +0530501** Parameters remote_bdaddr
Priti Agherac0edf9f2014-06-26 11:23:51 -0700502**
503** Returns TRUE if the device is present in blacklist, else FALSE
504**
505*******************************************************************************/
506BOOLEAN check_sdp_bl(const bt_bdaddr_t *remote_bdaddr)
507{
508 UINT8 i = 0;
509 UINT16 manufacturer = 0;
510 UINT8 lmp_ver = 0;
511 UINT16 lmp_subver = 0;
512 tBTM_STATUS btm_status;
513 bt_property_t prop_name;
514 bt_remote_version_t info;
515 bt_status_t status;
516
517
518 if (remote_bdaddr == NULL)
519 return FALSE;
520
Hemant Gupta29ccbb02014-07-15 23:33:32 +0530521 /* fetch additional info about remote device used in iop query */
Priti Agherac0edf9f2014-06-26 11:23:51 -0700522 btm_status = BTM_ReadRemoteVersion(*(BD_ADDR*)remote_bdaddr, &lmp_ver,
523 &manufacturer, &lmp_subver);
524
525
526
Hemant Gupta29ccbb02014-07-15 23:33:32 +0530527 /* if not available yet, try fetching from config database */
Priti Agherac0edf9f2014-06-26 11:23:51 -0700528 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_REMOTE_VERSION_INFO,
529 sizeof(bt_remote_version_t), &info);
530
531 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
532 &prop_name) != BT_STATUS_SUCCESS)
533 {
534
535 return FALSE;
536 }
537 manufacturer = info.manufacturer;
538
539 for (int i = 0; i < MAX_SDP_BL_ENTRIES; i++)
540 {
541 if (manufacturer == sdp_blacklist[i].manufact_id)
Hemant Gupta29ccbb02014-07-15 23:33:32 +0530542 {
543 APPL_TRACE_WARNING("device is in blacklist for skipping sdp");
Priti Agherac0edf9f2014-06-26 11:23:51 -0700544 return TRUE;
Hemant Gupta29ccbb02014-07-15 23:33:32 +0530545 }
Priti Agherac0edf9f2014-06-26 11:23:51 -0700546 }
547 return FALSE;
548}
549
The Android Open Source Project5738f832012-12-12 16:00:35 -0800550static void bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr, bt_bond_state_t state)
551{
552 /* Send bonding state only once - based on outgoing/incoming we may receive duplicates */
553 if ( (pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING) )
554 return;
555
Srinu Jellacacdcdd2014-11-01 13:12:10 +0530556 /* Ignore the invalid state transition for othere device */
557 if ( (state == BT_BOND_STATE_NONE) && (pairing_cb.state == BT_BOND_STATE_BONDING) &&
558 bdcmp(pairing_cb.bd_addr, bd_addr->address))
559 {
560 BTIF_TRACE_ERROR("%s:Ignore invalid bond state transition of other device", __FUNCTION__);
561 return;
562 }
563
The Android Open Source Project5738f832012-12-12 16:00:35 -0800564 if (pairing_cb.is_temp)
565 {
566 state = BT_BOND_STATE_NONE;
567 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700568 BTIF_TRACE_DEBUG("%s: state=%d prev_state=%d", __FUNCTION__, state, pairing_cb.state);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800569
570 HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state);
571
572 if (state == BT_BOND_STATE_BONDING)
573 {
574 pairing_cb.state = state;
575 bdcpy(pairing_cb.bd_addr, bd_addr->address);
576 }
Hemant Guptac23a7322013-11-26 18:02:40 +0530577 else if (bdcmp(pairing_cb.bd_addr, bd_addr->address) == 0)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800578 {
579 memset(&pairing_cb, 0, sizeof(pairing_cb));
580 }
581
582}
583
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800584/* store remote version in bt config to always have access
585 to it post pairing*/
586static void btif_update_remote_version_property(bt_bdaddr_t *p_bd)
587{
588 bt_property_t property;
589 UINT8 lmp_ver = 0;
590 UINT16 lmp_subver = 0;
591 UINT16 mfct_set = 0;
592 tBTM_STATUS btm_status;
593 bt_remote_version_t info;
594 bt_status_t status;
595 bdstr_t bdstr;
596
597 btm_status = BTM_ReadRemoteVersion(*(BD_ADDR*)p_bd, &lmp_ver,
598 &mfct_set, &lmp_subver);
599
600 ALOGD("remote version info [%s]: %x, %x, %x", bd2str(p_bd, &bdstr),
601 lmp_ver, mfct_set, lmp_subver);
602
603 if (btm_status == BTM_SUCCESS)
604 {
605 /* always update cache to ensure we have availability whenever BTM API
606 is not populated */
607 info.manufacturer = mfct_set;
608 info.sub_ver = lmp_subver;
609 info.version = lmp_ver;
610 BTIF_STORAGE_FILL_PROPERTY(&property,
611 BT_PROPERTY_REMOTE_VERSION_INFO, sizeof(bt_remote_version_t),
612 &info);
613 status = btif_storage_set_remote_device_property(p_bd, &property);
614 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote version", status);
615 }
616}
617
The Android Open Source Project5738f832012-12-12 16:00:35 -0800618
619static void btif_update_remote_properties(BD_ADDR bd_addr, BD_NAME bd_name,
620 DEV_CLASS dev_class, tBT_DEVICE_TYPE device_type)
621{
622 int num_properties = 0;
623 bt_property_t properties[3];
624 bt_bdaddr_t bdaddr;
625 bt_status_t status;
626 UINT32 cod;
627 bt_device_type_t dev_type;
628
629 memset(properties, 0, sizeof(properties));
630 bdcpy(bdaddr.address, bd_addr);
631
632 /* remote name */
633 if (strlen((const char *) bd_name))
634 {
635 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
636 BT_PROPERTY_BDNAME, strlen((char *)bd_name), bd_name);
637 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
638 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device name", status);
639 num_properties++;
640 }
641
642 /* class of device */
643 cod = devclass2uint(dev_class);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700644 BTIF_TRACE_DEBUG("%s():cod is 0x%06x", __FUNCTION__, cod);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800645 if ( cod == 0) {
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530646 /* Try to retrieve cod from storage */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700647 BTIF_TRACE_DEBUG("%s():cod is 0, checking cod from storage", __FUNCTION__);
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530648 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
649 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
650 status = btif_storage_get_remote_device_property(&bdaddr, &properties[num_properties]);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700651 BTIF_TRACE_DEBUG("%s():cod retreived from storage is 0x%06x", __FUNCTION__, cod);
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530652 if ( cod == 0) {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700653 BTIF_TRACE_DEBUG("%s():cod is again 0, set as unclassified", __FUNCTION__);
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530654 cod = COD_UNCLASSIFIED;
655 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800656 }
657
658 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
659 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
660 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
661 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device class", status);
662 num_properties++;
663
664 /* device type */
665 dev_type = device_type;
666 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
667 BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
668 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
669 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device type", status);
670 num_properties++;
671
672 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
673 status, &bdaddr, num_properties, properties);
674}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800675
Subramanian Srinivasan4aae63d2014-09-26 18:38:47 -0700676void btif_update_remote_device_type(BD_ADDR bd_addr, tBT_DEVICE_TYPE device_type)
677{
678 int num_properties = 0;
679 bt_property_t properties[2];
680 bt_bdaddr_t bdaddr;
681 bt_status_t status;
682 UINT32 cod;
683 bt_device_type_t dev_type;
684
685 memset(properties, 0, sizeof(properties));
686 bdcpy(bdaddr.address, bd_addr);
687 BTIF_TRACE_DEBUG("%s():", __FUNCTION__);
688
689 /* device addr */
690 dev_type = device_type;
691 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
692 BT_PROPERTY_BDADDR, sizeof(bdaddr), &bdaddr);
693 num_properties++;
694 /* device type */
695 dev_type = device_type;
696 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
697 BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
698 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
699 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device type", status);
700 num_properties++;
701
702 btif_storage_add_remote_device(&bdaddr, num_properties, properties);
703}
704
The Android Open Source Project5738f832012-12-12 16:00:35 -0800705/*******************************************************************************
706**
707** Function btif_dm_cb_hid_remote_name
708**
709** Description Remote name callback for HID device. Called in btif context
710** Special handling for HID devices
711**
712** Returns void
713**
714*******************************************************************************/
715static void btif_dm_cb_hid_remote_name(tBTM_REMOTE_DEV_NAME *p_remote_name)
716{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700717 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 -0800718 if (pairing_cb.state == BT_BOND_STATE_BONDING)
719 {
720 bt_bdaddr_t remote_bd;
721
722 bdcpy(remote_bd.address, pairing_cb.bd_addr);
723
724 if (p_remote_name->status == BTM_SUCCESS)
725 {
726 bond_state_changed(BT_STATUS_SUCCESS, &remote_bd, BT_BOND_STATE_BONDED);
727 }
728 else
729 bond_state_changed(BT_STATUS_FAIL, &remote_bd, BT_BOND_STATE_NONE);
730 }
731}
732
The Android Open Source Project5738f832012-12-12 16:00:35 -0800733/*******************************************************************************
734**
735** Function btif_dm_cb_create_bond
736**
737** Description Create bond initiated from the BTIF thread context
738** Special handling for HID devices
739**
740** Returns void
741**
742*******************************************************************************/
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -0700743static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr, tBTA_TRANSPORT transport)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800744{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800745 BOOLEAN is_hid = check_cod(bd_addr, COD_HID_POINTING);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800746 bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800747
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800748#if BLE_INCLUDED == TRUE
749 int device_type;
750 int addr_type;
751 bdstr_t bdstr;
752 bd2str(bd_addr, &bdstr);
Matthew Xie64c54792014-09-16 00:55:03 -0700753 if (transport == BT_TRANSPORT_LE)
754 {
755 if (!btif_config_get_int("Remote", (char const *)&bdstr,"DevType", &device_type))
756 {
757 btif_config_set_int("Remote", bdstr, "DevType", BT_DEVICE_TYPE_BLE);
758 }
759 if (btif_storage_get_remote_addr_type(bd_addr, &addr_type) != BT_STATUS_SUCCESS)
760 {
761 btif_storage_set_remote_addr_type(bd_addr, BLE_ADDR_PUBLIC);
762 }
763 }
lungtsai_lin3baff792014-08-29 13:47:47 +0800764 if((btif_config_get_int("Remote", (char const *)&bdstr,"DevType", &device_type) &&
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800765 (btif_storage_get_remote_addr_type(bd_addr, &addr_type) == BT_STATUS_SUCCESS) &&
lungtsai_lin3baff792014-08-29 13:47:47 +0800766 (device_type == BT_DEVICE_TYPE_BLE)) || (transport == BT_TRANSPORT_LE))
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800767 {
768 BTA_DmAddBleDevice(bd_addr->address, addr_type, BT_DEVICE_TYPE_BLE);
769 }
770#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800771
Thomas.TT_Lin2772dac2014-07-18 12:10:59 +0800772#if BLE_INCLUDED == TRUE
773 if(is_hid && device_type != BT_DEVICE_TYPE_BLE)
774#else
775 if(is_hid)
776#endif
777 {
778 int status;
779 status = btif_hh_connect(bd_addr);
780 if(status != BT_STATUS_SUCCESS)
781 bond_state_changed(status, bd_addr, BT_BOND_STATE_NONE);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800782 }
783 else
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800784 {
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -0700785 BTA_DmBondByTransport((UINT8 *)bd_addr->address, transport);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800786 }
787 /* Track originator of bond creation */
788 pairing_cb.is_local_initiated = TRUE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800789
790}
791
792/*******************************************************************************
793**
794** Function btif_dm_cb_remove_bond
795**
796** Description remove bond initiated from the BTIF thread context
797** Special handling for HID devices
798**
799** Returns void
800**
801*******************************************************************************/
802void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr)
803{
804 bdstr_t bdstr;
Ajay Kumarc2dffa22014-06-11 22:09:20 +0530805 bt_bdname_t alias;
806 bt_property_t properties[1];
807 uint32_t num_properties = 0;
Hemant Guptad20e4092014-10-08 11:59:12 +0530808 bt_status_t status = BT_STATUS_FAIL;
Rohit Singha82ea7c2014-10-30 11:59:13 +0530809 int property_value = 0;
810
Ajay Kumarc2dffa22014-06-11 22:09:20 +0530811 memset(&alias, 0, sizeof(alias));
812 BTIF_DM_GET_REMOTE_PROP(bd_addr, BT_PROPERTY_REMOTE_FRIENDLY_NAME,
813 &alias, sizeof(alias), properties[num_properties]);
814
815 if(alias.name[0] != '\0') {
816 properties[0].type = BT_PROPERTY_REMOTE_FRIENDLY_NAME;
817 properties[0].val = (void *) "";
818 properties[0].len = 1;
819
820 btif_storage_set_remote_device_property(bd_addr, &properties[0]);
821 }
822
Hemant Guptad20e4092014-10-08 11:59:12 +0530823 /* Reset the remoteTrustvalue*/
824 properties[0].type = BT_PROPERTY_REMOTE_TRUST_VALUE;
Rohit Singha82ea7c2014-10-30 11:59:13 +0530825 properties[0].val = (void *)&property_value;
Hemant Guptad20e4092014-10-08 11:59:12 +0530826 properties[0].len = sizeof(int);
827 /* Also write this to the NVRAM */
828 status = btif_storage_set_remote_device_property(bd_addr, &properties[0]);
829 ASSERTC(status == BT_STATUS_SUCCESS, "resetting trust failed", status);
830 /* Callback to notify upper layer of remote device property change */
831 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
832 BT_STATUS_SUCCESS, bd_addr, 1, properties);
833
The Android Open Source Project5738f832012-12-12 16:00:35 -0800834 /*special handling for HID devices */
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -0700835 /* VUP needs to be sent if its a HID Device. The HID HOST module will check if there
836 is a valid hid connection with this bd_addr. If yes VUP will be issued.*/
837#if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
838 if (btif_hh_virtual_unplug(bd_addr) != BT_STATUS_SUCCESS)
839#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800840 {
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -0700841 BTA_DmRemoveDevice((UINT8 *)bd_addr->address);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800842 }
843}
844
845/*******************************************************************************
846**
Andre Eisenbach249f6002014-06-18 12:20:37 -0700847** Function btif_dm_get_connection_state
848**
849** Description Returns whether the remote device is currently connected
850**
851** Returns 0 if not connected
852**
853*******************************************************************************/
854uint16_t btif_dm_get_connection_state(const bt_bdaddr_t *bd_addr)
855{
856 return BTA_DmGetConnectionState((UINT8 *)bd_addr->address);
857}
858
859/*******************************************************************************
860**
The Android Open Source Project5738f832012-12-12 16:00:35 -0800861** Function search_devices_copy_cb
862**
863** Description Deep copy callback for search devices event
864**
865** Returns void
866**
867*******************************************************************************/
868static void search_devices_copy_cb(UINT16 event, char *p_dest, char *p_src)
869{
870 tBTA_DM_SEARCH *p_dest_data = (tBTA_DM_SEARCH *) p_dest;
871 tBTA_DM_SEARCH *p_src_data = (tBTA_DM_SEARCH *) p_src;
872
873 if (!p_src)
874 return;
875
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700876 BTIF_TRACE_DEBUG("%s: event=%s", __FUNCTION__, dump_dm_search_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800877 memcpy(p_dest_data, p_src_data, sizeof(tBTA_DM_SEARCH));
878 switch (event)
879 {
880 case BTA_DM_INQ_RES_EVT:
881 {
882 if (p_src_data->inq_res.p_eir)
883 {
884 p_dest_data->inq_res.p_eir = (UINT8 *)(p_dest + sizeof(tBTA_DM_SEARCH));
885 memcpy(p_dest_data->inq_res.p_eir, p_src_data->inq_res.p_eir, HCI_EXT_INQ_RESPONSE_LEN);
886 }
887 }
888 break;
889
890 case BTA_DM_DISC_RES_EVT:
891 {
892 if (p_src_data->disc_res.raw_data_size && p_src_data->disc_res.p_raw_data)
893 {
894 p_dest_data->disc_res.p_raw_data = (UINT8 *)(p_dest + sizeof(tBTA_DM_SEARCH));
895 memcpy(p_dest_data->disc_res.p_raw_data,
896 p_src_data->disc_res.p_raw_data, p_src_data->disc_res.raw_data_size);
897 }
898 }
899 break;
900 }
901}
902
903static void search_services_copy_cb(UINT16 event, char *p_dest, char *p_src)
904{
905 tBTA_DM_SEARCH *p_dest_data = (tBTA_DM_SEARCH *) p_dest;
906 tBTA_DM_SEARCH *p_src_data = (tBTA_DM_SEARCH *) p_src;
907
908 if (!p_src)
909 return;
910 memcpy(p_dest_data, p_src_data, sizeof(tBTA_DM_SEARCH));
911 switch (event)
912 {
913 case BTA_DM_DISC_RES_EVT:
914 {
Kausik Sinnaswamy95664a92013-05-03 15:02:50 +0530915 if (p_src_data->disc_res.result == BTA_SUCCESS)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800916 {
Kausik Sinnaswamy95664a92013-05-03 15:02:50 +0530917 if (p_src_data->disc_res.num_uuids > 0)
918 {
919 p_dest_data->disc_res.p_uuid_list =
920 (UINT8*)(p_dest + sizeof(tBTA_DM_SEARCH));
921 memcpy(p_dest_data->disc_res.p_uuid_list, p_src_data->disc_res.p_uuid_list,
922 p_src_data->disc_res.num_uuids*MAX_UUID_SIZE);
923 GKI_freebuf(p_src_data->disc_res.p_uuid_list);
924 }
925 if (p_src_data->disc_res.p_raw_data != NULL)
926 {
927 GKI_freebuf(p_src_data->disc_res.p_raw_data);
928 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800929 }
930 } break;
931 }
932}
933/******************************************************************************
934**
935** BTIF DM callback events
936**
937*****************************************************************************/
938
939/*******************************************************************************
940**
941** Function btif_dm_pin_req_evt
942**
943** Description Executes pin request event in btif context
944**
945** Returns void
946**
947*******************************************************************************/
948static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
949{
950 bt_bdaddr_t bd_addr;
951 bt_bdname_t bd_name;
952 UINT32 cod;
953 bt_pin_code_t pin_code;
Srinu Jellaedadca02013-07-05 18:20:40 +0530954 BOOLEAN secure;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800955
956 /* Remote properties update */
957 btif_update_remote_properties(p_pin_req->bd_addr, p_pin_req->bd_name,
958 p_pin_req->dev_class, BT_DEVICE_TYPE_BREDR);
959
960 bdcpy(bd_addr.address, p_pin_req->bd_addr);
961 memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN);
962
Srinu Jella9f4cfa72014-11-04 13:09:13 +0530963 /* Respond with neg pin reply, if pin req comes with high security for the
964 same device which is already in pairing */
965 if ( (p_pin_req->secure) && (pairing_cb.state == BT_BOND_STATE_BONDING) &&
966 !bdcmp(pairing_cb.bd_addr, bd_addr.address))
967 {
968 BTIF_TRACE_ERROR("%s():bonding is already in progress", __FUNCTION__);
969 BTA_DmPinReply( (UINT8 *)bd_addr.address, FALSE, 0, NULL);
970 return;
971 }
972
The Android Open Source Project5738f832012-12-12 16:00:35 -0800973 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
974
975 cod = devclass2uint(p_pin_req->dev_class);
976
Srinu Jellaedadca02013-07-05 18:20:40 +0530977 secure = p_pin_req->secure;
978
The Android Open Source Project5738f832012-12-12 16:00:35 -0800979 if ( cod == 0) {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700980 BTIF_TRACE_DEBUG("%s():cod is 0, set as unclassified", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800981 cod = COD_UNCLASSIFIED;
982 }
983
Smriti Guptacd3a3f22014-10-08 15:23:47 +0530984 BTIF_TRACE_DEBUG("%s()pairing_cb.is_local_initiated = %d, secure = %d", __FUNCTION__,
985 pairing_cb.is_local_initiated, secure);
986
The Android Open Source Project5738f832012-12-12 16:00:35 -0800987 /* check for auto pair possiblity only if bond was initiated by local device */
988 if (pairing_cb.is_local_initiated)
989 {
990 if (check_cod(&bd_addr, COD_AV_HEADSETS) ||
991 check_cod(&bd_addr, COD_AV_HANDSFREE) ||
992 check_cod(&bd_addr, COD_AV_HEADPHONES) ||
993 check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) ||
994 check_cod(&bd_addr, COD_AV_HIFI_AUDIO) ||
995 check_cod(&bd_addr, COD_HID_POINTING))
996 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700997 BTIF_TRACE_DEBUG("%s()cod matches for auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800998 /* Check if this device can be auto paired */
999 if ((btif_storage_is_device_autopair_blacklisted(&bd_addr) == FALSE) &&
1000 (pairing_cb.autopair_attempts == 0))
1001 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001002 BTIF_TRACE_DEBUG("%s() Attempting auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001003 pin_code.pin[0] = 0x30;
1004 pin_code.pin[1] = 0x30;
1005 pin_code.pin[2] = 0x30;
1006 pin_code.pin[3] = 0x30;
1007
1008 pairing_cb.autopair_attempts++;
1009 BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin);
1010 return;
1011 }
1012 }
1013 else if (check_cod(&bd_addr, COD_HID_KEYBOARD) ||
1014 check_cod(&bd_addr, COD_HID_COMBO))
1015 {
1016 if(( btif_storage_is_fixed_pin_zeros_keyboard (&bd_addr) == TRUE) &&
1017 (pairing_cb.autopair_attempts == 0))
1018 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001019 BTIF_TRACE_DEBUG("%s() Attempting auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001020 pin_code.pin[0] = 0x30;
1021 pin_code.pin[1] = 0x30;
1022 pin_code.pin[2] = 0x30;
1023 pin_code.pin[3] = 0x30;
1024
1025 pairing_cb.autopair_attempts++;
1026 BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin);
1027 return;
1028 }
1029 }
1030 }
1031 HAL_CBACK(bt_hal_cbacks, pin_request_cb,
Srinu Jellaedadca02013-07-05 18:20:40 +05301032 &bd_addr, &bd_name, cod, secure);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001033}
1034
1035/*******************************************************************************
1036**
1037** Function btif_dm_ssp_cfm_req_evt
1038**
1039** Description Executes SSP confirm request event in btif context
1040**
1041** Returns void
1042**
1043*******************************************************************************/
1044static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ *p_ssp_cfm_req)
1045{
1046 bt_bdaddr_t bd_addr;
1047 bt_bdname_t bd_name;
1048 UINT32 cod;
1049 BOOLEAN is_incoming = !(pairing_cb.state == BT_BOND_STATE_BONDING);
1050
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001051 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001052
1053 /* Remote properties update */
1054 btif_update_remote_properties(p_ssp_cfm_req->bd_addr, p_ssp_cfm_req->bd_name,
1055 p_ssp_cfm_req->dev_class, BT_DEVICE_TYPE_BREDR);
1056
1057 bdcpy(bd_addr.address, p_ssp_cfm_req->bd_addr);
1058 memcpy(bd_name.name, p_ssp_cfm_req->bd_name, BD_NAME_LEN);
1059
1060 /* Set the pairing_cb based on the local & remote authentication requirements */
1061 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
1062
1063 /* if just_works and bonding bit is not set treat this as temporary */
1064 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 -08001065 !(p_ssp_cfm_req->rmt_auth_req & BTM_AUTH_BONDS) &&
1066 !(check_cod((bt_bdaddr_t*)&p_ssp_cfm_req->bd_addr, COD_HID_POINTING)))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001067 pairing_cb.is_temp = TRUE;
1068 else
1069 pairing_cb.is_temp = FALSE;
1070
1071 pairing_cb.is_ssp = TRUE;
1072
1073 /* If JustWorks auto-accept */
1074 if (p_ssp_cfm_req->just_works)
1075 {
1076 /* Pairing consent for JustWorks needed if:
1077 * 1. Incoming pairing is detected AND
1078 * 2. local IO capabilities are DisplayYesNo AND
1079 * 3. remote IO capabiltiies are DisplayOnly or NoInputNoOutput;
1080 */
1081 if ((is_incoming) && ((p_ssp_cfm_req->loc_io_caps == 0x01) &&
1082 (p_ssp_cfm_req->rmt_io_caps == 0x00 || p_ssp_cfm_req->rmt_io_caps == 0x03)))
1083 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001084 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 -08001085 __FUNCTION__, p_ssp_cfm_req->loc_io_caps, p_ssp_cfm_req->rmt_io_caps);
1086 }
1087 else
1088 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001089 BTIF_TRACE_EVENT("%s: Auto-accept JustWorks pairing", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001090 btif_dm_ssp_reply(&bd_addr, BT_SSP_VARIANT_CONSENT, TRUE, 0);
1091 return;
1092 }
1093 }
1094
1095 cod = devclass2uint(p_ssp_cfm_req->dev_class);
1096
1097 if ( cod == 0) {
1098 ALOGD("cod is 0, set as unclassified");
1099 cod = COD_UNCLASSIFIED;
1100 }
1101
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001102 pairing_cb.sdp_attempts = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001103 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod,
1104 (p_ssp_cfm_req->just_works ? BT_SSP_VARIANT_CONSENT : BT_SSP_VARIANT_PASSKEY_CONFIRMATION),
1105 p_ssp_cfm_req->num_val);
1106}
1107
1108static void btif_dm_ssp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif)
1109{
1110 bt_bdaddr_t bd_addr;
1111 bt_bdname_t bd_name;
1112 UINT32 cod;
1113
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001114 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001115
1116 /* Remote properties update */
1117 btif_update_remote_properties(p_ssp_key_notif->bd_addr, p_ssp_key_notif->bd_name,
1118 p_ssp_key_notif->dev_class, BT_DEVICE_TYPE_BREDR);
1119
1120 bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
1121 memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
1122
1123 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
1124 pairing_cb.is_ssp = TRUE;
1125 cod = devclass2uint(p_ssp_key_notif->dev_class);
1126
1127 if ( cod == 0) {
1128 ALOGD("cod is 0, set as unclassified");
1129 cod = COD_UNCLASSIFIED;
1130 }
1131
1132 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
1133 cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION,
1134 p_ssp_key_notif->passkey);
1135}
1136/*******************************************************************************
1137**
1138** Function btif_dm_auth_cmpl_evt
1139**
1140** Description Executes authentication complete event in btif context
1141**
1142** Returns void
1143**
1144*******************************************************************************/
1145static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
1146{
1147 /* Save link key, if not temporary */
1148 bt_bdaddr_t bd_addr;
1149 bt_status_t status = BT_STATUS_FAIL;
1150 bt_bond_state_t state = BT_BOND_STATE_NONE;
Priti Agherac0edf9f2014-06-26 11:23:51 -07001151 BOOLEAN skip_sdp = FALSE;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001152
1153 bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
1154 if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
1155 {
1156 if ((p_auth_cmpl->key_type < HCI_LKEY_TYPE_DEBUG_COMB) || (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB) ||
Srinu Jellac8372bb2014-06-30 16:52:48 +05301157 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_CHANGED_COMB) ||
1158#if (defined(BTM_SECURE_CONN_HOST_INCLUDED) && BTM_SECURE_CONN_HOST_INCLUDED == TRUE)
1159 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB_P256) ||
1160#endif
1161 (!pairing_cb.is_temp))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001162 {
1163 bt_status_t ret;
Srinu Jellac8372bb2014-06-30 16:52:48 +05301164 BTIF_TRACE_WARNING("%s: Storing link key. key_type=0x%x, is_temp=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001165 __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.is_temp);
1166 ret = btif_storage_add_bonded_device(&bd_addr,
1167 p_auth_cmpl->key, p_auth_cmpl->key_type,
1168 pairing_cb.pin_code_len);
1169 ASSERTC(ret == BT_STATUS_SUCCESS, "storing link key failed", ret);
1170 }
1171 else
1172 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001173 BTIF_TRACE_DEBUG("%s: Temporary key. Not storing. key_type=0x%x, is_temp=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001174 __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.is_temp);
Hemant Guptab820aec2013-12-24 19:59:57 +05301175 if(pairing_cb.is_temp)
1176 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001177 BTIF_TRACE_DEBUG("%s: sending BT_BOND_STATE_NONE for Temp pairing",
Hemant Guptab820aec2013-12-24 19:59:57 +05301178 __FUNCTION__);
venkata Jagadeeshcc72e342014-09-02 15:42:11 +05301179 if (btif_storage_is_device_bonded(&bd_addr) == TRUE) {
1180 btif_storage_remove_bonded_device(&bd_addr);
1181 }
Hemant Guptab820aec2013-12-24 19:59:57 +05301182 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
1183 return;
1184 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001185 }
1186 }
Priti Agherac0edf9f2014-06-26 11:23:51 -07001187
1188 // Skip SDP for certain HID Devices
The Android Open Source Project5738f832012-12-12 16:00:35 -08001189 if (p_auth_cmpl->success)
1190 {
Andre Eisenbach31a64002014-10-14 14:29:19 -07001191 pairing_cb.timeout_retries = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001192
Priti Agherac0edf9f2014-06-26 11:23:51 -07001193 if (check_sdp_bl(&bd_addr) && check_cod_hid(&bd_addr, COD_HID_MAJOR))
1194 {
Hemant Gupta29ccbb02014-07-15 23:33:32 +05301195 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED);
Ganesh Ganapathi Battae17bf002013-02-15 17:52:29 -08001196
Hemant Gupta29ccbb02014-07-15 23:33:32 +05301197 BTIF_TRACE_DEBUG("%s: HID Connection from "
1198 "blacklisted device, skipping sdp",__FUNCTION__);
Priti Agherac0edf9f2014-06-26 11:23:51 -07001199 bt_property_t prop;
Priti Agherac0edf9f2014-06-26 11:23:51 -07001200 bt_uuid_t uuid;
1201 char uuid_str[128] = UUID_HUMAN_INTERFACE_DEVICE;
Ganesh Ganapathi Battae17bf002013-02-15 17:52:29 -08001202
Priti Agherac0edf9f2014-06-26 11:23:51 -07001203 string_to_uuid(uuid_str, &uuid);
1204
1205 prop.type = BT_PROPERTY_UUIDS;
1206 prop.val = uuid.uu;
1207 prop.len = MAX_UUID_SIZE;
1208
Hemant Gupta29ccbb02014-07-15 23:33:32 +05301209 /* Also write this to the NVRAM */
1210 status = btif_storage_set_remote_device_property(&bd_addr, &prop);
1211 ASSERTC(status == BT_STATUS_SUCCESS, "storing remote services failed", status);
Hemant Guptad20e4092014-10-08 11:59:12 +05301212 /* Send the event from BTIF */
Priti Agherac0edf9f2014-06-26 11:23:51 -07001213 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1214 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1215 }
1216 else
1217 {
Hemant Gupta29ccbb02014-07-15 23:33:32 +05301218 status = BT_STATUS_SUCCESS;
1219 state = BT_BOND_STATE_BONDED;
1220
Priti Agherac0edf9f2014-06-26 11:23:51 -07001221 /* Trigger SDP on the device */
1222 pairing_cb.sdp_attempts = 1;;
1223
1224 if(btif_dm_inquiry_in_progress)
1225 btif_dm_cancel_discovery();
1226
1227 btif_dm_get_remote_services(&bd_addr);
Priti Agherac0edf9f2014-06-26 11:23:51 -07001228 /* Do not call bond_state_changed_cb yet. Wait till fetch remote service is complete */
Hemant Gupta29ccbb02014-07-15 23:33:32 +05301229 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001230 }
1231 else
1232 {
1233 /*Map the HCI fail reason to bt status */
1234 switch(p_auth_cmpl->fail_reason)
1235 {
1236 case HCI_ERR_PAGE_TIMEOUT:
Andre Eisenbach31a64002014-10-14 14:29:19 -07001237 if (blacklistPairingRetries(bd_addr.address) && pairing_cb.timeout_retries)
1238 {
1239 BTIF_TRACE_WARNING("%s() - Pairing timeout; retrying (%d) ...", __FUNCTION__, pairing_cb.timeout_retries);
1240 --pairing_cb.timeout_retries;
1241 btif_dm_cb_create_bond (&bd_addr, BTA_TRANSPORT_UNKNOWN);
1242 return;
1243 }
1244 /* Fall-through */
The Android Open Source Project5738f832012-12-12 16:00:35 -08001245 case HCI_ERR_CONNECTION_TOUT:
1246 status = BT_STATUS_RMT_DEV_DOWN;
1247 break;
1248
Hemant Guptaaef7a672013-07-31 19:00:12 +05301249 case HCI_ERR_PAIRING_NOT_ALLOWED:
Pramod Sivaraman35159ed2014-01-16 16:54:47 +05301250 btif_storage_remove_bonded_device(&bd_addr);
Hemant Guptaaef7a672013-07-31 19:00:12 +05301251 status = BT_STATUS_AUTH_REJECTED;
1252 break;
1253
Hemant Guptab4801442014-01-07 18:11:15 +05301254
The Android Open Source Project5738f832012-12-12 16:00:35 -08001255 /* map the auth failure codes, so we can retry pairing if necessary */
1256 case HCI_ERR_AUTH_FAILURE:
Hemant Gupta59a88ec2014-03-19 19:01:35 +05301257 case HCI_ERR_KEY_MISSING:
Nitin Shivpure81ae1012013-06-25 16:34:00 +05301258 case HCI_ERR_LMP_RESPONSE_TIMEOUT:
Zhihai Xua7ea8092013-11-27 14:10:53 +05301259 btif_storage_remove_bonded_device(&bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001260 case HCI_ERR_HOST_REJECT_SECURITY:
1261 case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE:
1262 case HCI_ERR_UNIT_KEY_USED:
1263 case HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED:
1264 case HCI_ERR_INSUFFCIENT_SECURITY:
Hemant Gupta87b7cce2013-11-28 13:07:10 +05301265 case HCI_ERR_PEER_USER:
1266 case HCI_ERR_UNSPECIFIED:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001267 BTIF_TRACE_DEBUG(" %s() Authentication fail reason %d",
Hemant Gupta87b7cce2013-11-28 13:07:10 +05301268 __FUNCTION__, p_auth_cmpl->fail_reason);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001269 if (pairing_cb.autopair_attempts == 1)
1270 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001271 BTIF_TRACE_DEBUG("%s(): Adding device to blacklist ", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001272
1273 /* Add the device to dynamic black list only if this device belongs to Audio/pointing dev class */
1274 if (check_cod(&bd_addr, COD_AV_HEADSETS) ||
1275 check_cod(&bd_addr, COD_AV_HANDSFREE) ||
1276 check_cod(&bd_addr, COD_AV_HEADPHONES) ||
1277 check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) ||
1278 check_cod(&bd_addr, COD_AV_HIFI_AUDIO) ||
1279 check_cod(&bd_addr, COD_HID_POINTING))
1280 {
1281 btif_storage_add_device_to_autopair_blacklist (&bd_addr);
1282 }
1283 pairing_cb.autopair_attempts++;
1284
1285 /* Create the Bond once again */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001286 BTIF_TRACE_DEBUG("%s() auto pair failed. Reinitiate Bond", __FUNCTION__);
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07001287 btif_dm_cb_create_bond (&bd_addr, BTA_TRANSPORT_UNKNOWN);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001288 return;
1289 }
1290 else
1291 {
1292 /* if autopair attempts are more than 1, or not attempted */
1293 status = BT_STATUS_AUTH_FAILURE;
1294 }
1295 break;
1296
1297 default:
1298 status = BT_STATUS_FAIL;
1299 }
Zhihai Xu8d2128d2013-12-13 16:09:21 +05301300 /* Special Handling for HID Devices */
1301 if (check_cod(&bd_addr, COD_HID_POINTING)) {
1302 /* Remove Device as bonded in nvram as authentication failed */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001303 BTIF_TRACE_DEBUG("%s(): removing hid pointing device from nvram", __FUNCTION__);
Zhihai Xu8d2128d2013-12-13 16:09:21 +05301304 btif_storage_remove_bonded_device(&bd_addr);
1305 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001306 bond_state_changed(status, &bd_addr, state);
1307 }
1308}
1309
1310/******************************************************************************
1311**
1312** Function btif_dm_search_devices_evt
1313**
1314** Description Executes search devices callback events in btif context
1315**
1316** Returns void
1317**
1318******************************************************************************/
1319static void btif_dm_search_devices_evt (UINT16 event, char *p_param)
1320{
1321 tBTA_DM_SEARCH *p_search_data;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001322 BTIF_TRACE_EVENT("%s event=%s", __FUNCTION__, dump_dm_search_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001323
1324 switch (event)
1325 {
1326 case BTA_DM_DISC_RES_EVT:
1327 {
1328 p_search_data = (tBTA_DM_SEARCH *)p_param;
1329 /* Remote name update */
1330 if (strlen((const char *) p_search_data->disc_res.bd_name))
1331 {
1332 bt_property_t properties[1];
1333 bt_bdaddr_t bdaddr;
1334 bt_status_t status;
1335
1336 properties[0].type = BT_PROPERTY_BDNAME;
1337 properties[0].val = p_search_data->disc_res.bd_name;
1338 properties[0].len = strlen((char *)p_search_data->disc_res.bd_name);
1339 bdcpy(bdaddr.address, p_search_data->disc_res.bd_addr);
1340
1341 status = btif_storage_set_remote_device_property(&bdaddr, &properties[0]);
1342 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device property", status);
1343 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1344 status, &bdaddr, 1, properties);
1345 }
1346 /* TODO: Services? */
1347 }
1348 break;
1349
1350 case BTA_DM_INQ_RES_EVT:
1351 {
1352 /* inquiry result */
1353 UINT32 cod;
1354 UINT8 *p_eir_remote_name = NULL;
1355 bt_bdname_t bdname;
1356 bt_bdaddr_t bdaddr;
1357 UINT8 remote_name_len;
1358 UINT8 *p_cached_name = NULL;
1359 tBTA_SERVICE_MASK services = 0;
1360 bdstr_t bdstr;
1361
1362 p_search_data = (tBTA_DM_SEARCH *)p_param;
1363 bdcpy(bdaddr.address, p_search_data->inq_res.bd_addr);
1364
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001365 BTIF_TRACE_DEBUG("%s() %s device_type = 0x%x\n", __FUNCTION__, bd2str(&bdaddr, &bdstr),
The Android Open Source Project5738f832012-12-12 16:00:35 -08001366#if (BLE_INCLUDED == TRUE)
1367 p_search_data->inq_res.device_type);
1368#else
1369 BT_DEVICE_TYPE_BREDR);
1370#endif
1371 bdname.name[0] = 0;
1372
1373 cod = devclass2uint (p_search_data->inq_res.dev_class);
1374
1375 if ( cod == 0) {
1376 ALOGD("cod is 0, set as unclassified");
1377 cod = COD_UNCLASSIFIED;
1378 }
1379
1380 if (!check_eir_remote_name(p_search_data, bdname.name, &remote_name_len))
1381 check_cached_remote_name(p_search_data, bdname.name, &remote_name_len);
1382
1383 /* Check EIR for remote name and services */
1384 if (p_search_data->inq_res.p_eir)
1385 {
1386 BTA_GetEirService(p_search_data->inq_res.p_eir, &services);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001387 BTIF_TRACE_DEBUG("%s()EIR BTA services = %08X", __FUNCTION__, (UINT32)services);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001388 /* TODO: Get the service list and check to see which uuids we got and send it back to the client. */
1389 }
1390
1391
1392 {
1393 bt_property_t properties[5];
1394 bt_device_type_t dev_type;
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001395 UINT8 addr_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001396 uint32_t num_properties = 0;
1397 bt_status_t status;
Ajay Kumarc2dffa22014-06-11 22:09:20 +05301398 bt_bdname_t alias;
1399 memset(&alias, 0, sizeof(alias));
1400 BTIF_DM_GET_REMOTE_PROP(&bdaddr, BT_PROPERTY_REMOTE_FRIENDLY_NAME,
1401 &alias, sizeof(alias), properties[num_properties]);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001402
1403 memset(properties, 0, sizeof(properties));
1404 /* BD_ADDR */
1405 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1406 BT_PROPERTY_BDADDR, sizeof(bdaddr), &bdaddr);
1407 num_properties++;
1408 /* BD_NAME */
1409 /* Don't send BDNAME if it is empty */
Ajay Kumarc2dffa22014-06-11 22:09:20 +05301410 /* send alias name as the name if alias name present */
1411 if(alias.name[0] != '\0') {
1412 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1413 BT_PROPERTY_BDNAME,
1414 strlen((char *)alias.name), &alias);
1415 num_properties++;
1416 }
1417 else if (bdname.name[0])
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001418 {
Nitin Shivpure81ae1012013-06-25 16:34:00 +05301419 if( (check_eir_is_remote_name_short(p_search_data) == TRUE) &&
1420 (btif_storage_is_device_bonded(&bdaddr) == TRUE) )
1421 {
1422 BTIF_TRACE_DEBUG("%s Don't update about the device name ", __FUNCTION__);
1423 }
1424 else
1425 {
1426 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1427 BT_PROPERTY_BDNAME,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001428 strlen((char *)bdname.name), &bdname);
Nitin Shivpure81ae1012013-06-25 16:34:00 +05301429 num_properties++;
1430 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001431 }
1432
1433 /* DEV_CLASS */
1434 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1435 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
1436 num_properties++;
1437 /* DEV_TYPE */
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001438#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001439 /* FixMe: Assumption is that bluetooth.h and BTE enums match */
1440 dev_type = p_search_data->inq_res.device_type;
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001441 addr_type = p_search_data->inq_res.ble_addr_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001442#else
1443 dev_type = BT_DEVICE_TYPE_BREDR;
1444#endif
1445 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1446 BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
1447 num_properties++;
1448 /* RSSI */
1449 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1450 BT_PROPERTY_REMOTE_RSSI, sizeof(int8_t),
1451 &(p_search_data->inq_res.rssi));
1452 num_properties++;
1453
1454 status = btif_storage_add_remote_device(&bdaddr, num_properties, properties);
1455 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device (inquiry)", status);
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001456#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1457 status = btif_storage_set_remote_addr_type(&bdaddr, addr_type);
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001458 if (( dev_type == BT_DEVICE_TYPE_DUMO)&&
1459 (p_search_data->inq_res.flag & BTA_BLE_DMT_CONTROLLER_SPT) &&
1460 (p_search_data->inq_res.flag & BTA_BLE_DMT_HOST_SPT))
1461 {
1462 btif_storage_set_dmt_support_type (&bdaddr, TRUE);
1463 }
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001464 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote addr type (inquiry)", status);
1465#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001466 /* Callback to notify upper layer of device */
1467 HAL_CBACK(bt_hal_cbacks, device_found_cb,
1468 num_properties, properties);
1469 }
1470 }
1471 break;
1472
1473 case BTA_DM_INQ_CMPL_EVT:
1474 {
Satya Calloji6e2d9db2014-07-08 16:18:58 -07001475#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1476 tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param;
1477 memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
1478 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL,
1479 bte_scan_filt_param_cfg_evt, 0);
1480#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001481 }
1482 break;
1483 case BTA_DM_DISC_CMPL_EVT:
1484 {
1485 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED);
1486 }
1487 break;
1488 case BTA_DM_SEARCH_CANCEL_CMPL_EVT:
1489 {
1490 /* if inquiry is not in progress and we get a cancel event, then
1491 * it means we are done with inquiry, but remote_name fetches are in
1492 * progress
1493 *
1494 * if inquiry is in progress, then we don't want to act on this cancel_cmpl_evt
1495 * but instead wait for the cancel_cmpl_evt via the Busy Level
1496 *
1497 */
1498 if (btif_dm_inquiry_in_progress == FALSE)
1499 {
Nitin Arora417790c2014-09-26 14:05:24 -07001500#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1501 tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param;
1502 memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
1503 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL,
1504 bte_scan_filt_param_cfg_evt, 0);
1505#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001506 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED);
1507 }
1508 }
1509 break;
1510 }
1511}
1512
1513/*******************************************************************************
1514**
1515** Function btif_dm_search_services_evt
1516**
1517** Description Executes search services event in btif context
1518**
1519** Returns void
1520**
1521*******************************************************************************/
1522static void btif_dm_search_services_evt(UINT16 event, char *p_param)
1523{
1524 tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param;
1525
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001526 BTIF_TRACE_EVENT("%s: event = %d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001527 switch (event)
1528 {
1529 case BTA_DM_DISC_RES_EVT:
1530 {
1531 bt_uuid_t uuid_arr[BT_MAX_NUM_UUIDS]; /* Max 32 services */
Nitin Shivpure81ae1012013-06-25 16:34:00 +05301532 bt_property_t prop[2];
1533 int num_properties = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001534 uint32_t i = 0, j = 0;
1535 bt_bdaddr_t bd_addr;
1536 bt_status_t ret;
1537
1538 bdcpy(bd_addr.address, p_data->disc_res.bd_addr);
1539
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001540 BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001541 p_data->disc_res.result, p_data->disc_res.services);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001542 if ((p_data->disc_res.result != BTA_SUCCESS) &&
1543 (pairing_cb.state == BT_BOND_STATE_BONDING ) &&
1544 (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING))
1545 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001546 BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", __FUNCTION__);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001547 pairing_cb.sdp_attempts++;
1548 btif_dm_get_remote_services(&bd_addr);
1549 return;
1550 }
Nitin Shivpure81ae1012013-06-25 16:34:00 +05301551 prop[0].type = BT_PROPERTY_UUIDS;
1552 prop[0].len = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001553 if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0))
1554 {
Nitin Shivpure81ae1012013-06-25 16:34:00 +05301555 prop[0].val = p_data->disc_res.p_uuid_list;
1556 prop[0].len = p_data->disc_res.num_uuids * MAX_UUID_SIZE;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001557 for (i=0; i < p_data->disc_res.num_uuids; i++)
1558 {
1559 char temp[256];
1560 uuid_to_string((bt_uuid_t*)(p_data->disc_res.p_uuid_list + (i*MAX_UUID_SIZE)), temp);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001561 BTIF_TRACE_ERROR("Index: %d uuid:%s", i, temp);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001562 }
1563 }
1564
1565 /* onUuidChanged requires getBondedDevices to be populated.
1566 ** bond_state_changed needs to be sent prior to remote_device_property
1567 */
1568 if ((pairing_cb.state == BT_BOND_STATE_BONDING) &&
1569 (bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0)&&
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001570 pairing_cb.sdp_attempts > 0)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001571 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001572 BTIF_TRACE_DEBUG("%s Remote Service SDP done. Call bond_state_changed_cb BONDED",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001573 __FUNCTION__);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001574 pairing_cb.sdp_attempts = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001575 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED);
1576 }
1577
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001578 if(p_data->disc_res.num_uuids != 0)
1579 {
1580 /* Also write this to the NVRAM */
Nitin Shivpure81ae1012013-06-25 16:34:00 +05301581 ret = btif_storage_set_remote_device_property(&bd_addr, &prop[0]);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001582 ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);
Nitin Shivpure81ae1012013-06-25 16:34:00 +05301583 num_properties++;
1584 }
1585
Liang Yingc7fc2072014-11-06 18:43:23 -08001586 /* check if the alias is set for the bt device */
1587 bt_bdname_t alias;
1588 bt_property_t properties;
1589 memset(&alias, 0, sizeof(alias));
1590 BTIF_DM_GET_REMOTE_PROP(&bd_addr, BT_PROPERTY_REMOTE_FRIENDLY_NAME,
1591 &alias, sizeof(alias), properties);
1592
Nitin Shivpure81ae1012013-06-25 16:34:00 +05301593 /* Remote name update */
Liang Yingc7fc2072014-11-06 18:43:23 -08001594 if (alias.name[0] == '\0' && strlen((const char *) p_data->disc_res.bd_name))
1595 { // update BDNAME only if no alias and BD name is present
Nitin Shivpure81ae1012013-06-25 16:34:00 +05301596 prop[1].type = BT_PROPERTY_BDNAME;
1597 prop[1].val = p_data->disc_res.bd_name;
1598 prop[1].len = strlen((char *)p_data->disc_res.bd_name);
1599
1600 ret = btif_storage_set_remote_device_property(&bd_addr, &prop[1]);
1601 ASSERTC(ret == BT_STATUS_SUCCESS, "failed to save remote device property", ret);
1602 num_properties++;
1603 }
1604
1605 if(num_properties > 0)
1606 {
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001607 /* Send the event to the BTIF */
1608 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
Nitin Shivpure81ae1012013-06-25 16:34:00 +05301609 BT_STATUS_SUCCESS, &bd_addr, num_properties, prop);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001610 }
Nitin Shivpure81ae1012013-06-25 16:34:00 +05301611
The Android Open Source Project5738f832012-12-12 16:00:35 -08001612 }
1613 break;
1614
1615 case BTA_DM_DISC_CMPL_EVT:
Ajay Kumarade6ea82014-09-23 16:07:10 +05301616 {
1617 int device_type;
1618 bt_bdaddr_t bd_addr;
1619 bdstr_t bdstr;
1620 bdcpy(bd_addr.address, p_data->disc_res.bd_addr);
1621 bd2str(&bd_addr, &bdstr);
1622 if(!btif_config_get_int("Remote", (char const *)&bdstr,"DevType", &device_type) || device_type != BT_DEVICE_TYPE_BLE)
1623 {
1624 if ((pairing_cb.state == BT_BOND_STATE_BONDING) &&
1625 (pairing_cb.bd_addr[0] != '\0') &&
1626 pairing_cb.sdp_attempts > 0)
1627 {
1628 pairing_cb.sdp_attempts = 0;
1629
1630 BTIF_TRACE_DEBUG("%s Remote Service SDP not done. Call "
1631 "bond_state_changed_cb BONDED", __FUNCTION__);
1632 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED);
1633 }
1634
1635 }
1636 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001637 break;
1638
Matthew Xie607e3b72013-08-15 19:30:48 -07001639#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001640 case BTA_DM_DISC_BLE_RES_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001641 BTIF_TRACE_DEBUG("%s:, services 0x%x)", __FUNCTION__,
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001642 p_data->disc_ble_res.service.uu.uuid16);
1643 bt_uuid_t uuid;
1644 int i = 0;
1645 int j = 15;
1646 if (p_data->disc_ble_res.service.uu.uuid16 == UUID_SERVCLASS_LE_HID)
1647 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001648 BTIF_TRACE_DEBUG("%s: Found HOGP UUID",__FUNCTION__);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001649 bt_property_t prop;
1650 bt_bdaddr_t bd_addr;
1651 char temp[256];
Zhihai Xud7ee77b2013-11-05 18:06:54 -08001652 bt_status_t ret;
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001653
1654 bta_gatt_convert_uuid16_to_uuid128(uuid.uu,p_data->disc_ble_res.service.uu.uuid16);
1655
1656 while(i < j )
1657 {
1658 unsigned char c = uuid.uu[j];
1659 uuid.uu[j] = uuid.uu[i];
1660 uuid.uu[i] = c;
1661 i++;
1662 j--;
1663 }
1664
1665 uuid_to_string(&uuid, temp);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001666 BTIF_TRACE_ERROR(" uuid:%s", temp);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001667
1668 bdcpy(bd_addr.address, p_data->disc_ble_res.bd_addr);
1669 prop.type = BT_PROPERTY_UUIDS;
1670 prop.val = uuid.uu;
1671 prop.len = MAX_UUID_SIZE;
1672
Zhihai Xud7ee77b2013-11-05 18:06:54 -08001673 /* Also write this to the NVRAM */
1674 ret = btif_storage_set_remote_device_property(&bd_addr, &prop);
1675 ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);
1676
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001677 /* Send the event to the BTIF */
1678 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1679 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1680
1681 }
1682 break;
Matthew Xie607e3b72013-08-15 19:30:48 -07001683#endif /* BLE_INCLUDED */
Nitin Shivpure0663c942014-05-20 17:54:48 +05301684#if (defined(RMT_DI_TO_APP_INCLUDED) && (RMT_DI_TO_APP_INCLUDED == TRUE))
1685 case BTA_DM_DI_DISC_CMPL_EVT:
1686 {
1687 if(NULL != p_data)
1688 {
1689 bt_property_t properties[1];
1690 bt_bdaddr_t bd_addr;
1691 int status;
1692 BTIF_TRACE_DEBUG("%s: num of DI records:%d, result: %d, vendorID: 0x%x",
1693 __FUNCTION__, p_data->di_disc.num_record, p_data->di_disc.result,
1694 p_data->di_disc.p_device_info.rec.vendor);
1695 if (p_data->di_disc.result == BTA_SUCCESS && p_data->di_disc.num_record > 0)
1696 {
1697 bt_remote_di_record_t di_rec;
1698
1699 di_rec.spec_id = p_data->di_disc.p_device_info.spec_id;
1700 di_rec.product = p_data->di_disc.p_device_info.rec.product;
1701 di_rec.vendor = p_data->di_disc.p_device_info.rec.vendor;
1702 di_rec.vendor_id_source = p_data->di_disc.p_device_info.rec.vendor_id_source;
1703 di_rec.version = p_data->di_disc.p_device_info.rec.version;
1704
1705 bdcpy(bd_addr.address, p_data->di_disc.bd_addr);
1706 properties[0].type = BT_PROPERTY_REMOTE_DI_RECORD;
1707 properties[0].val = &di_rec;
1708 properties[0].len = sizeof(bt_remote_di_record_t);
1709 status=btif_storage_set_remote_device_property(&bd_addr, &properties[0]);
1710 ASSERTC(status == BT_STATUS_SUCCESS, "saving DI record", status);
1711
1712 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1713 status, &bd_addr, 1, properties);
1714 }
1715 }
1716 }
1717 break;
1718#endif
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001719
The Android Open Source Project5738f832012-12-12 16:00:35 -08001720 default:
1721 {
1722 ASSERTC(0, "unhandled search services event", event);
1723 }
1724 break;
1725 }
1726}
1727
1728/*******************************************************************************
1729**
1730** Function btif_dm_remote_service_record_evt
1731**
1732** Description Executes search service record event in btif context
1733**
1734** Returns void
1735**
1736*******************************************************************************/
1737static void btif_dm_remote_service_record_evt(UINT16 event, char *p_param)
1738{
1739 tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param;
1740
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001741 BTIF_TRACE_EVENT("%s: event = %d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001742 switch (event)
1743 {
1744 case BTA_DM_DISC_RES_EVT:
1745 {
1746 bt_service_record_t rec;
1747 bt_property_t prop;
1748 uint32_t i = 0;
1749 bt_bdaddr_t bd_addr;
1750
1751 memset(&rec, 0, sizeof(bt_service_record_t));
1752 bdcpy(bd_addr.address, p_data->disc_res.bd_addr);
1753
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001754 BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001755 p_data->disc_res.result, p_data->disc_res.services);
1756 prop.type = BT_PROPERTY_SERVICE_RECORD;
1757 prop.val = (void*)&rec;
1758 prop.len = sizeof(rec);
1759
1760 /* disc_res.result is overloaded with SCN. Cannot check result */
1761 p_data->disc_res.services &= ~BTA_USER_SERVICE_MASK;
1762 /* TODO: Get the UUID as well */
1763 rec.channel = p_data->disc_res.result - 3;
1764 /* TODO: Need to get the service name using p_raw_data */
1765 rec.name[0] = 0;
1766
1767 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1768 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1769 }
1770 break;
1771
1772 default:
1773 {
1774 ASSERTC(0, "unhandled remote service record event", event);
1775 }
1776 break;
1777 }
1778}
1779
1780/*******************************************************************************
1781**
1782** Function btif_dm_upstreams_cback
1783**
1784** Description Executes UPSTREAMS events in btif context
1785**
1786** Returns void
1787**
1788*******************************************************************************/
1789static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
1790{
1791 tBTA_DM_SEC_EVT dm_event = (tBTA_DM_SEC_EVT)event;
1792 tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)p_param;
1793 tBTA_SERVICE_MASK service_mask;
1794 uint32_t i;
1795 bt_bdaddr_t bd_addr;
Subramanian Srinivasan4aae63d2014-09-26 18:38:47 -07001796 int dev_type = 0;
1797 bdstr_t bdstr;
1798
The Android Open Source Project5738f832012-12-12 16:00:35 -08001799
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001800 BTIF_TRACE_EVENT("btif_dm_upstreams_cback ev: %s", dump_dm_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001801
1802 switch (event)
1803 {
1804 case BTA_DM_ENABLE_EVT:
1805 {
1806 BD_NAME bdname;
1807 bt_status_t status;
1808 bt_property_t prop;
1809 prop.type = BT_PROPERTY_BDNAME;
Pramod Sivaraman0c4a3482014-06-23 22:11:33 +05301810 prop.len = BD_NAME_LEN + 1;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001811 prop.val = (void*)bdname;
1812
1813 status = btif_storage_get_adapter_property(&prop);
Matthew Xie1e5109b2012-11-09 18:26:26 -08001814 if (status == BT_STATUS_SUCCESS)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001815 {
1816 /* A name exists in the storage. Make this the device name */
1817 BTA_DmSetDeviceName((char*)prop.val);
1818 }
Matthew Xie1e5109b2012-11-09 18:26:26 -08001819 else
1820 {
1821 /* Storage does not have a name yet.
1822 * Use the default name and write it to the chip
1823 */
1824 BTA_DmSetDeviceName(btif_get_default_local_name());
1825 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001826
Andre Eisenbacha015a832014-09-11 14:09:40 -07001827#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1828 /* Enable local privacy */
1829 BTA_DmBleConfigLocalPrivacy(TRUE);
1830#endif
1831
The Android Open Source Project5738f832012-12-12 16:00:35 -08001832 /* for each of the enabled services in the mask, trigger the profile
1833 * enable */
1834 service_mask = btif_get_enabled_services_mask();
1835 for (i=0; i <= BTA_MAX_SERVICE_ID; i++)
1836 {
1837 if (service_mask &
1838 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i)))
1839 {
1840 btif_in_execute_service_request(i, TRUE);
1841 }
1842 }
1843 /* clear control blocks */
1844 memset(&pairing_cb, 0, sizeof(btif_dm_pairing_cb_t));
1845
1846 /* This function will also trigger the adapter_properties_cb
1847 ** and bonded_devices_info_cb
1848 */
1849 btif_storage_load_bonded_devices();
1850
1851 btif_storage_load_autopair_device_list();
1852
1853 btif_enable_bluetooth_evt(p_data->enable.status, p_data->enable.bd_addr);
1854 }
1855 break;
1856
1857 case BTA_DM_DISABLE_EVT:
1858 /* for each of the enabled services in the mask, trigger the profile
1859 * disable */
1860 service_mask = btif_get_enabled_services_mask();
1861 for (i=0; i <= BTA_MAX_SERVICE_ID; i++)
1862 {
1863 if (service_mask &
1864 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i)))
1865 {
1866 btif_in_execute_service_request(i, FALSE);
1867 }
1868 }
1869 btif_disable_bluetooth_evt();
1870 break;
1871
1872 case BTA_DM_PIN_REQ_EVT:
1873 btif_dm_pin_req_evt(&p_data->pin_req);
1874 break;
1875
1876 case BTA_DM_AUTH_CMPL_EVT:
1877 btif_dm_auth_cmpl_evt(&p_data->auth_cmpl);
1878 break;
1879
1880 case BTA_DM_BOND_CANCEL_CMPL_EVT:
1881 if (pairing_cb.state == BT_BOND_STATE_BONDING)
1882 {
1883 bdcpy(bd_addr.address, pairing_cb.bd_addr);
1884 bond_state_changed(p_data->bond_cancel_cmpl.result, &bd_addr, BT_BOND_STATE_NONE);
Subramanian Srinivasanc2a4ed72014-03-13 12:44:03 -07001885 btif_dm_remove_bond(&bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001886 }
1887 break;
1888
1889 case BTA_DM_SP_CFM_REQ_EVT:
1890 btif_dm_ssp_cfm_req_evt(&p_data->cfm_req);
1891 break;
1892 case BTA_DM_SP_KEY_NOTIF_EVT:
1893 btif_dm_ssp_key_notif_evt(&p_data->key_notif);
1894 break;
1895
1896 case BTA_DM_DEV_UNPAIRED_EVT:
1897 bdcpy(bd_addr.address, p_data->link_down.bd_addr);
1898
1899 /*special handling for HID devices */
1900 #if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -07001901 btif_hh_remove_device(bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001902 #endif
Hemant Gupta87ebae02013-11-11 12:33:44 +05301903 #if (defined(BTA_HD_INCLUDED) && (BTA_HD_INCLUDED == TRUE))
1904 btif_hd_remove_device(bd_addr);
1905 #endif
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001906 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1907 btif_storage_remove_ble_bonding_keys(&bd_addr);
1908 #endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001909 btif_storage_remove_bonded_device(&bd_addr);
1910 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
1911 break;
1912
1913 case BTA_DM_BUSY_LEVEL_EVT:
1914 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001915
1916 if (p_data->busy_level.level_flags & BTM_BL_INQUIRY_PAGING_MASK)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001917 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001918 if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_STARTED)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001919 {
1920 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb,
1921 BT_DISCOVERY_STARTED);
1922 btif_dm_inquiry_in_progress = TRUE;
1923 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001924 else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_CANCELLED)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001925 {
1926 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb,
1927 BT_DISCOVERY_STOPPED);
1928 btif_dm_inquiry_in_progress = FALSE;
1929 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001930 else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_COMPLETE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001931 {
1932 btif_dm_inquiry_in_progress = FALSE;
1933 }
1934 }
1935 }break;
1936
1937 case BTA_DM_LINK_UP_EVT:
1938 bdcpy(bd_addr.address, p_data->link_up.bd_addr);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001939 BTIF_TRACE_DEBUG("BTA_DM_LINK_UP_EVT. Sending BT_ACL_STATE_CONNECTED");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001940
Subramanian Srinivasan4aae63d2014-09-26 18:38:47 -07001941 bd2str(&bd_addr, &bdstr);
1942 if(btif_config_get_int("Remote", (char const *)&bdstr,"DevType", &dev_type) &&
1943 p_data->link_up.link_type == BT_TRANSPORT_LE && dev_type == BT_DEVICE_TYPE_BREDR)
1944 {
Nitin Aroraa4079d62014-10-14 14:10:09 -07001945 btif_update_remote_properties(bd_addr.address, (UINT8 *)"", NULL, dev_type | p_data->link_up.link_type);
Subramanian Srinivasan4aae63d2014-09-26 18:38:47 -07001946 }
1947 if(p_data->link_up.link_type == BT_TRANSPORT_LE)
1948 {
1949 if(dev_type == 0)
1950 {
1951 btif_update_remote_device_type(p_data->link_up.bd_addr, BT_TRANSPORT_LE);
1952 }
1953 btif_storage_set_remote_addr_type(&bd_addr, p_data->link_up.remote_addr_type);
1954 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001955 btif_update_remote_version_property(&bd_addr);
1956
The Android Open Source Project5738f832012-12-12 16:00:35 -08001957 HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS,
1958 &bd_addr, BT_ACL_STATE_CONNECTED);
1959 break;
1960
1961 case BTA_DM_LINK_DOWN_EVT:
1962 bdcpy(bd_addr.address, p_data->link_down.bd_addr);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001963 BTIF_TRACE_DEBUG("BTA_DM_LINK_DOWN_EVT. Sending BT_ACL_STATE_DISCONNECTED");
Nitin Shivpure85495682013-09-12 21:45:59 +05301964 btif_av_move_idle(bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001965 HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS,
1966 &bd_addr, BT_ACL_STATE_DISCONNECTED);
1967 break;
1968
1969 case BTA_DM_HW_ERROR_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001970 BTIF_TRACE_ERROR("Received H/W Error. ");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001971 /* Flush storage data */
1972 btif_config_flush();
1973 usleep(100000); /* 100milliseconds */
1974 /* Killing the process to force a restart as part of fault tolerance */
1975 kill(getpid(), SIGKILL);
1976 break;
1977
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001978#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1979 case BTA_DM_BLE_KEY_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001980 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 -08001981
1982 /* If this pairing is by-product of local initiated GATT client Read or Write,
1983 BTA would not have sent BTA_DM_BLE_SEC_REQ_EVT event and Bond state would not
1984 have setup properly. Setup pairing_cb and notify App about Bonding state now*/
1985 if (pairing_cb.state != BT_BOND_STATE_BONDING)
1986 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001987 BTIF_TRACE_DEBUG("Bond state not sent to App so far.Notify the app now");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001988 bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t*)p_data->ble_key.bd_addr,
1989 BT_BOND_STATE_BONDING);
1990 }
1991 else if (memcmp (pairing_cb.bd_addr, p_data->ble_key.bd_addr, BD_ADDR_LEN)!=0)
1992 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001993 BTIF_TRACE_ERROR("BD mismatch discard BLE key_type=%d ",p_data->ble_key.key_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001994 break;
1995 }
1996
1997 switch (p_data->ble_key.key_type)
1998 {
1999 case BTA_LE_KEY_PENC:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002000 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PENC");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002001 pairing_cb.ble.is_penc_key_rcvd = TRUE;
2002 memcpy(pairing_cb.ble.penc_key.ltk,p_data->ble_key.key_value.penc_key.ltk, 16);
2003 memcpy(pairing_cb.ble.penc_key.rand, p_data->ble_key.key_value.penc_key.rand,8);
2004 pairing_cb.ble.penc_key.ediv = p_data->ble_key.key_value.penc_key.ediv;
2005 pairing_cb.ble.penc_key.sec_level = p_data->ble_key.key_value.penc_key.sec_level;
2006
2007 for (i=0; i<16; i++)
2008 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002009 BTIF_TRACE_DEBUG("pairing_cb.ble.penc_key.ltk[%d]=0x%02x",i,pairing_cb.ble.penc_key.ltk[i]);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002010 }
2011 for (i=0; i<8; i++)
2012 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002013 BTIF_TRACE_DEBUG("pairing_cb.ble.penc_key.rand[%d]=0x%02x",i,pairing_cb.ble.penc_key.rand[i]);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002014 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002015 BTIF_TRACE_DEBUG("pairing_cb.ble.penc_key.ediv=0x%04x",pairing_cb.ble.penc_key.ediv);
2016 BTIF_TRACE_DEBUG("pairing_cb.ble.penc_key.sec_level=0x%02x",pairing_cb.ble.penc_key.sec_level);
2017 BTIF_TRACE_DEBUG("pairing_cb.ble.penc_key.key_size=0x%02x",pairing_cb.ble.penc_key.key_size);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002018 break;
2019
2020 case BTA_LE_KEY_PID:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002021 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PID");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002022 pairing_cb.ble.is_pid_key_rcvd = TRUE;
Andre Eisenbachda9b0f82014-10-21 12:37:53 -07002023 pairing_cb.ble.pid_key.addr_type = p_data->ble_key.key_value.pid_key.addr_type;
2024 memcpy(pairing_cb.ble.pid_key.irk, p_data->ble_key.key_value.pid_key.irk, 16);
2025 memcpy(pairing_cb.ble.pid_key.static_addr,
2026 p_data->ble_key.key_value.pid_key.static_addr,BD_ADDR_LEN);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002027 for (i=0; i<16; i++)
2028 {
Andre Eisenbachda9b0f82014-10-21 12:37:53 -07002029 BTIF_TRACE_DEBUG("pairing_cb.ble.pid_key.irk[%d]=0x%02x"
2030 ,i,pairing_cb.ble.pid_key.irk[i]);
2031 }
2032 for (i=0; i<BD_ADDR_LEN; i++)
2033 {
2034 BTIF_TRACE_DEBUG("piaring_cb.ble.pid_address[%d] = %x"
2035 ,i, pairing_cb.ble.pid_key.static_addr[i]);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002036 }
2037 break;
2038
2039 case BTA_LE_KEY_PCSRK:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002040 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PCSRK");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002041 pairing_cb.ble.is_pcsrk_key_rcvd = TRUE;
2042 pairing_cb.ble.pcsrk_key.counter = p_data->ble_key.key_value.pcsrk_key.counter;
2043 pairing_cb.ble.pcsrk_key.sec_level = p_data->ble_key.key_value.pcsrk_key.sec_level;
2044 memcpy(pairing_cb.ble.pcsrk_key.csrk,p_data->ble_key.key_value.pcsrk_key.csrk,16);
2045
2046 for (i=0; i<16; i++)
2047 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002048 BTIF_TRACE_DEBUG("pairing_cb.ble.pcsrk_key.csrk[%d]=0x%02x",i,pairing_cb.ble.pcsrk_key.csrk[i]);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002049 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002050 BTIF_TRACE_DEBUG("pairing_cb.ble.pcsrk_key.counter=0x%08x",pairing_cb.ble.pcsrk_key.counter);
2051 BTIF_TRACE_DEBUG("pairing_cb.ble.pcsrk_key.sec_level=0x%02x",pairing_cb.ble.pcsrk_key.sec_level);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002052 break;
2053
2054 case BTA_LE_KEY_LENC:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002055 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LENC");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002056 pairing_cb.ble.is_lenc_key_rcvd = TRUE;
2057 pairing_cb.ble.lenc_key.div = p_data->ble_key.key_value.lenc_key.div;
2058 pairing_cb.ble.lenc_key.key_size = p_data->ble_key.key_value.lenc_key.key_size;
2059 pairing_cb.ble.lenc_key.sec_level = p_data->ble_key.key_value.lenc_key.sec_level;
2060
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002061 BTIF_TRACE_DEBUG("pairing_cb.ble.lenc_key.div=0x%04x",pairing_cb.ble.lenc_key.div);
2062 BTIF_TRACE_DEBUG("pairing_cb.ble.lenc_key.key_size=0x%02x",pairing_cb.ble.lenc_key.key_size);
2063 BTIF_TRACE_DEBUG("pairing_cb.ble.lenc_key.sec_level=0x%02x",pairing_cb.ble.lenc_key.sec_level);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002064 break;
2065
2066
2067
2068 case BTA_LE_KEY_LCSRK:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002069 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LCSRK");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002070 pairing_cb.ble.is_lcsrk_key_rcvd = TRUE;
2071 pairing_cb.ble.lcsrk_key.counter = p_data->ble_key.key_value.lcsrk_key.counter;
2072 pairing_cb.ble.lcsrk_key.div = p_data->ble_key.key_value.lcsrk_key.div;
2073 pairing_cb.ble.lcsrk_key.sec_level = p_data->ble_key.key_value.lcsrk_key.sec_level;
2074
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002075 BTIF_TRACE_DEBUG("pairing_cb.ble.lcsrk_key.div=0x%04x",pairing_cb.ble.lcsrk_key.div);
2076 BTIF_TRACE_DEBUG("pairing_cb.ble.lcsrk_key.counter=0x%08x",pairing_cb.ble.lcsrk_key.counter);
2077 BTIF_TRACE_DEBUG("pairing_cb.ble.lcsrk_key.sec_level=0x%02x",pairing_cb.ble.lcsrk_key.sec_level);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002078
2079 break;
2080
2081 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002082 BTIF_TRACE_ERROR("unknown BLE key type (0x%02x)", p_data->ble_key.key_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002083 break;
2084 }
2085
2086 break;
2087 case BTA_DM_BLE_SEC_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002088 BTIF_TRACE_DEBUG("BTA_DM_BLE_SEC_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002089 btif_dm_ble_sec_req_evt(&p_data->ble_req);
2090 break;
2091 case BTA_DM_BLE_PASSKEY_NOTIF_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002092 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_NOTIF_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002093 btif_dm_ble_key_notif_evt(&p_data->key_notif);
2094 break;
2095 case BTA_DM_BLE_PASSKEY_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002096 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002097 btif_dm_ble_passkey_req_evt(&p_data->pin_req);
2098 break;
2099 case BTA_DM_BLE_OOB_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002100 BTIF_TRACE_DEBUG("BTA_DM_BLE_OOB_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002101 break;
2102 case BTA_DM_BLE_LOCAL_IR_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002103 BTIF_TRACE_DEBUG("BTA_DM_BLE_LOCAL_IR_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002104 ble_local_key_cb.is_id_keys_rcvd = TRUE;
2105 memcpy(&ble_local_key_cb.id_keys.irk[0], &p_data->ble_id_keys.irk[0], sizeof(BT_OCTET16));
2106 memcpy(&ble_local_key_cb.id_keys.ir[0], &p_data->ble_id_keys.ir[0], sizeof(BT_OCTET16));
2107 memcpy(&ble_local_key_cb.id_keys.dhk[0], &p_data->ble_id_keys.dhk[0], sizeof(BT_OCTET16));
2108 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.irk[0],
2109 BTIF_DM_LE_LOCAL_KEY_IR,
2110 BT_OCTET16_LEN);
2111 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.ir[0],
2112 BTIF_DM_LE_LOCAL_KEY_IRK,
2113 BT_OCTET16_LEN);
2114 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.dhk[0],
2115 BTIF_DM_LE_LOCAL_KEY_DHK,
2116 BT_OCTET16_LEN);
2117 break;
2118 case BTA_DM_BLE_LOCAL_ER_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002119 BTIF_TRACE_DEBUG("BTA_DM_BLE_LOCAL_ER_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002120 ble_local_key_cb.is_er_rcvd = TRUE;
2121 memcpy(&ble_local_key_cb.er[0], &p_data->ble_er[0], sizeof(BT_OCTET16));
2122 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.er[0],
2123 BTIF_DM_LE_LOCAL_KEY_ER,
2124 BT_OCTET16_LEN);
2125 break;
2126
2127 case BTA_DM_BLE_AUTH_CMPL_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002128 BTIF_TRACE_DEBUG("BTA_DM_BLE_KEY_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002129 btif_dm_ble_auth_cmpl_evt(&p_data->auth_cmpl);
2130 break;
Ganesh Ganapathi Batta9546abf2014-05-30 16:28:00 -07002131
2132 case BTA_DM_LE_FEATURES_READ:
2133 {
2134 tBTM_BLE_VSC_CB cmn_vsc_cb;
2135 bt_local_le_features_t local_le_features;
2136 char buf[512];
2137 bt_property_t prop;
2138 prop.type = BT_PROPERTY_LOCAL_LE_FEATURES;
2139 prop.val = (void*)buf;
2140 prop.len = sizeof(buf);
2141
2142 /* LE features are not stored in storage. Should be retrived from stack */
2143 BTM_BleGetVendorCapabilities(&cmn_vsc_cb);
2144 local_le_features.local_privacy_enabled = BTM_BleLocalPrivacyEnabled();
2145
2146 prop.len = sizeof (bt_local_le_features_t);
2147 if (cmn_vsc_cb.filter_support == 1)
2148 local_le_features.max_adv_filter_supported = cmn_vsc_cb.max_filter;
2149 else
2150 local_le_features.max_adv_filter_supported = 0;
2151 local_le_features.max_adv_instance = cmn_vsc_cb.adv_inst_max;
2152 local_le_features.max_irk_list_size = cmn_vsc_cb.max_irk_list_sz;
2153 local_le_features.rpa_offload_supported = cmn_vsc_cb.rpa_offloading;
Satya Callojid773c2c2014-07-29 22:08:55 -07002154 local_le_features.scan_result_storage_size_hibyte =
2155 (cmn_vsc_cb.tot_scan_results_strg >> 8) & (0xFF);
2156 local_le_features.scan_result_storage_size_lobyte =
2157 (cmn_vsc_cb.tot_scan_results_strg) & (0xFF);
Satya Callojiefaddcb2014-07-28 23:22:05 -07002158 local_le_features.activity_energy_info_supported = cmn_vsc_cb.energy_support;
Ganesh Ganapathi Batta9546abf2014-05-30 16:28:00 -07002159 memcpy(prop.val, &local_le_features, prop.len);
2160 HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, BT_STATUS_SUCCESS, 1, &prop);
2161 break;
2162 }
Satya Callojie5ba8842014-07-03 17:18:02 -07002163
2164 case BTA_DM_ENER_INFO_READ:
2165 {
2166 btif_activity_energy_info_cb_t *p_ener_data = (btif_activity_energy_info_cb_t*) p_param;
2167 bt_activity_energy_info energy_info;
2168 energy_info.status = p_ener_data->status;
2169 energy_info.ctrl_state = p_ener_data->ctrl_state;
2170 energy_info.rx_time = p_ener_data->rx_time;
2171 energy_info.tx_time = p_ener_data->tx_time;
2172 energy_info.idle_time = p_ener_data->idle_time;
2173 energy_info.energy_used = p_ener_data->energy_used;
2174 HAL_CBACK(bt_hal_cbacks, energy_info_cb, &energy_info);
2175 break;
2176 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002177#endif
2178
Hemant Gupta32127bb2013-12-31 16:30:58 +05302179 case BTA_DM_REM_NAME_EVT:
2180 BTIF_TRACE_DEBUG("BTA_DM_REM_NAME_EVT");
2181
Srinu Jella25bf9592014-02-28 17:52:03 +05302182 bt_bdname_t alias;
2183 bt_property_t prop[1];
2184 uint32_t num_properties = 0;
2185 memset(&alias, 0, sizeof(alias));
2186 bdcpy(bd_addr.address, p_data->rem_name_evt.bd_addr);
2187 BTIF_DM_GET_REMOTE_PROP(&bd_addr, BT_PROPERTY_REMOTE_FRIENDLY_NAME,
2188 &alias, sizeof(alias), prop[num_properties]);
2189
2190 /* Update Remote device name only when the Alias name is not present */
2191 if ((alias.name[0] == '\0') && (strlen((char *)p_data->rem_name_evt.bd_name) > 0))
Hemant Gupta32127bb2013-12-31 16:30:58 +05302192 {
2193 bt_property_t properties[1];
2194 bt_status_t status;
2195
2196 BTIF_TRACE_DEBUG("name of device = %s", p_data->rem_name_evt.bd_name);
2197 properties[0].type = BT_PROPERTY_BDNAME;
2198 properties[0].val = p_data->rem_name_evt.bd_name;
2199 properties[0].len = strlen((char *)p_data->rem_name_evt.bd_name);
2200 bdcpy(bd_addr.address, p_data->rem_name_evt.bd_addr);
2201
2202 status = btif_storage_set_remote_device_property(&bd_addr, &properties[0]);
2203 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device property",
2204 status);
2205 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
2206 status, &bd_addr, 1, properties);
2207 }
2208
2209 break;
2210
The Android Open Source Project5738f832012-12-12 16:00:35 -08002211 case BTA_DM_AUTHORIZE_EVT:
2212 case BTA_DM_SIG_STRENGTH_EVT:
2213 case BTA_DM_SP_RMT_OOB_EVT:
2214 case BTA_DM_SP_KEYPRESS_EVT:
2215 case BTA_DM_ROLE_CHG_EVT:
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002216
The Android Open Source Project5738f832012-12-12 16:00:35 -08002217 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002218 BTIF_TRACE_WARNING( "btif_dm_cback : unhandled event (%d)", event );
The Android Open Source Project5738f832012-12-12 16:00:35 -08002219 break;
2220 }
2221} /* btui_security_cback() */
2222
2223
2224/*******************************************************************************
2225**
2226** Function btif_dm_generic_evt
2227**
2228** Description Executes non-BTA upstream events in BTIF context
2229**
2230** Returns void
2231**
2232*******************************************************************************/
2233static void btif_dm_generic_evt(UINT16 event, char* p_param)
2234{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002235 BTIF_TRACE_EVENT("%s: event=%d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002236 switch(event)
2237 {
2238 case BTIF_DM_CB_DISCOVERY_STARTED:
2239 {
2240 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STARTED);
2241 }
2242 break;
2243
2244 case BTIF_DM_CB_CREATE_BOND:
2245 {
Andre Eisenbach31a64002014-10-14 14:29:19 -07002246 pairing_cb.timeout_retries = NUM_TIMEOUT_RETRIES;
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002247 btif_dm_create_bond_cb_t *create_bond_cb = (btif_dm_create_bond_cb_t*)p_param;
2248 btif_dm_cb_create_bond(&create_bond_cb->bdaddr, create_bond_cb->transport);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002249 }
2250 break;
2251
2252 case BTIF_DM_CB_REMOVE_BOND:
2253 {
2254 btif_dm_cb_remove_bond((bt_bdaddr_t *)p_param);
2255 }
2256 break;
2257
2258 case BTIF_DM_CB_HID_REMOTE_NAME:
2259 {
2260 btif_dm_cb_hid_remote_name((tBTM_REMOTE_DEV_NAME *)p_param);
2261 }
2262 break;
2263
2264 case BTIF_DM_CB_BOND_STATE_BONDING:
2265 {
2266 bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t *)p_param, BT_BOND_STATE_BONDING);
2267 }
2268 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002269 case BTIF_DM_CB_LE_TX_TEST:
2270 case BTIF_DM_CB_LE_RX_TEST:
2271 {
2272 uint8_t status;
2273 STREAM_TO_UINT8(status, p_param);
2274 HAL_CBACK(bt_hal_cbacks, le_test_mode_cb,
2275 (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, 0);
2276 }
2277 break;
2278 case BTIF_DM_CB_LE_TEST_END:
2279 {
2280 uint8_t status;
2281 uint16_t count = 0;
2282 STREAM_TO_UINT8(status, p_param);
2283 if (status == 0)
2284 STREAM_TO_UINT16(count, p_param);
2285 HAL_CBACK(bt_hal_cbacks, le_test_mode_cb,
2286 (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, count);
2287 }
2288 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002289 default:
2290 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002291 BTIF_TRACE_WARNING("%s : Unknown event 0x%x", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002292 }
2293 break;
2294 }
2295}
2296
2297/*******************************************************************************
2298**
2299** Function bte_dm_evt
2300**
2301** Description Switches context from BTE to BTIF for all DM events
2302**
2303** Returns void
2304**
2305*******************************************************************************/
2306
2307void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data)
2308{
2309 bt_status_t status;
2310
2311 /* switch context to btif task context (copy full union size for convenience) */
2312 status = btif_transfer_context(btif_dm_upstreams_evt, (uint16_t)event, (void*)p_data, sizeof(tBTA_DM_SEC), NULL);
2313
2314 /* catch any failed context transfers */
2315 ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status);
2316}
2317
2318/*******************************************************************************
2319**
2320** Function bte_search_devices_evt
2321**
2322** Description Switches context from BTE to BTIF for DM search events
2323**
2324** Returns void
2325**
2326*******************************************************************************/
2327static void bte_search_devices_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
2328{
2329 UINT16 param_len = 0;
2330
2331 if (p_data)
2332 param_len += sizeof(tBTA_DM_SEARCH);
2333 /* Allocate buffer to hold the pointers (deep copy). The pointers will point to the end of the tBTA_DM_SEARCH */
2334 switch (event)
2335 {
2336 case BTA_DM_INQ_RES_EVT:
2337 {
Sai Aitharaju312401d2014-10-28 15:18:06 +05302338 if (p_data && p_data->inq_res.p_eir)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002339 param_len += HCI_EXT_INQ_RESPONSE_LEN;
2340 }
2341 break;
2342
2343 case BTA_DM_DISC_RES_EVT:
2344 {
Sai Aitharaju312401d2014-10-28 15:18:06 +05302345 if (p_data && p_data->disc_res.raw_data_size && p_data->disc_res.p_raw_data)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002346 param_len += p_data->disc_res.raw_data_size;
2347 }
2348 break;
2349 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002350 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 -08002351
2352 /* if remote name is available in EIR, set teh flag so that stack doesnt trigger RNR */
Sai Aitharaju312401d2014-10-28 15:18:06 +05302353 if (p_data && event == BTA_DM_INQ_RES_EVT)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002354 p_data->inq_res.remt_name_not_required = check_eir_remote_name(p_data, NULL, NULL);
2355
2356 btif_transfer_context (btif_dm_search_devices_evt , (UINT16) event, (void *)p_data, param_len,
2357 (param_len > sizeof(tBTA_DM_SEARCH)) ? search_devices_copy_cb : NULL);
2358}
2359
2360/*******************************************************************************
2361**
2362** Function bte_dm_search_services_evt
2363**
2364** Description Switches context from BTE to BTIF for DM search services
2365** event
2366**
2367** Returns void
2368**
2369*******************************************************************************/
2370static void bte_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
2371{
2372 UINT16 param_len = 0;
2373 if (p_data)
2374 param_len += sizeof(tBTA_DM_SEARCH);
2375 switch (event)
2376 {
2377 case BTA_DM_DISC_RES_EVT:
2378 {
Sai Aitharaju312401d2014-10-28 15:18:06 +05302379 if (p_data && (p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0)) {
The Android Open Source Project5738f832012-12-12 16:00:35 -08002380 param_len += (p_data->disc_res.num_uuids * MAX_UUID_SIZE);
2381 }
2382 } break;
2383 }
2384 /* TODO: The only other member that needs a deep copy is the p_raw_data. But not sure
Sai Aitharaju312401d2014-10-28 15:18:06 +05302385 * if raw_data is needed. */
The Android Open Source Project5738f832012-12-12 16:00:35 -08002386 btif_transfer_context(btif_dm_search_services_evt, event, (char*)p_data, param_len,
2387 (param_len > sizeof(tBTA_DM_SEARCH)) ? search_services_copy_cb : NULL);
2388}
2389
2390/*******************************************************************************
2391**
2392** Function bte_dm_remote_service_record_evt
2393**
2394** Description Switches context from BTE to BTIF for DM search service
2395** record event
2396**
2397** Returns void
2398**
2399*******************************************************************************/
2400static void bte_dm_remote_service_record_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
2401{
2402 /* TODO: The only member that needs a deep copy is the p_raw_data. But not sure yet if this is needed. */
2403 btif_transfer_context(btif_dm_remote_service_record_evt, event, (char*)p_data, sizeof(tBTA_DM_SEARCH), NULL);
2404}
2405
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07002406#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Satya Callojie5ba8842014-07-03 17:18:02 -07002407/*******************************************************************************
2408**
2409** Function bta_energy_info_cb
2410**
2411** Description Switches context from BTE to BTIF for DM energy info event
2412**
2413** Returns void
2414**
2415*******************************************************************************/
2416static void bta_energy_info_cb(tBTA_DM_BLE_TX_TIME_MS tx_time, tBTA_DM_BLE_RX_TIME_MS rx_time,
2417 tBTA_DM_BLE_IDLE_TIME_MS idle_time,
2418 tBTA_DM_BLE_ENERGY_USED energy_used,
2419 tBTA_DM_CONTRL_STATE ctrl_state, tBTA_STATUS status)
2420{
2421 BTIF_TRACE_DEBUG("energy_info_cb-Status:%d,state=%d,tx_t=%ld, rx_t=%ld, idle_time=%ld,used=%ld",
2422 status, ctrl_state, tx_time, rx_time, idle_time, energy_used);
2423
2424 btif_activity_energy_info_cb_t btif_cb;
2425 btif_cb.status = status;
2426 btif_cb.ctrl_state = ctrl_state;
2427 btif_cb.tx_time = (uint64_t) tx_time;
2428 btif_cb.rx_time = (uint64_t) rx_time;
2429 btif_cb.idle_time =(uint64_t) idle_time;
2430 btif_cb.energy_used =(uint64_t) energy_used;
2431 btif_transfer_context(btif_dm_upstreams_evt, BTA_DM_ENER_INFO_READ,
2432 (char*) &btif_cb, sizeof(btif_activity_energy_info_cb_t), NULL);
2433}
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07002434#endif
Satya Callojie5ba8842014-07-03 17:18:02 -07002435
Satya Calloji6e2d9db2014-07-08 16:18:58 -07002436/*******************************************************************************
2437**
2438** Function bte_scan_filt_param_cfg_evt
2439**
2440** Description Scan filter param config event
2441**
2442** Returns void
2443**
2444*******************************************************************************/
2445static void bte_scan_filt_param_cfg_evt(UINT8 action_type,
2446 tBTA_DM_BLE_PF_AVBL_SPACE avbl_space,
2447 tBTA_DM_BLE_REF_VALUE ref_value, tBTA_STATUS status)
2448{
2449 /* This event occurs on calling BTA_DmBleCfgFilterCondition internally,
2450 ** and that is why there is no HAL callback
2451 */
2452 if(BTA_SUCCESS != status)
2453 {
2454 BTIF_TRACE_ERROR("%s, %d", __FUNCTION__, status);
2455 }
2456 else
2457 {
2458 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
2459 }
2460}
2461
The Android Open Source Project5738f832012-12-12 16:00:35 -08002462/*****************************************************************************
2463**
2464** btif api functions (no context switch)
2465**
2466*****************************************************************************/
2467
2468/*******************************************************************************
2469**
2470** Function btif_dm_start_discovery
2471**
2472** Description Start device discovery/inquiry
2473**
2474** Returns bt_status_t
2475**
2476*******************************************************************************/
2477bt_status_t btif_dm_start_discovery(void)
2478{
2479 tBTA_DM_INQ inq_params;
2480 tBTA_SERVICE_MASK services = 0;
Satya Calloji6e2d9db2014-07-08 16:18:58 -07002481 tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002482
Nitin Shivpure81ae1012013-06-25 16:34:00 +05302483 BTIF_TRACE_EVENT("%s : pairing_cb.state: 0x%x", __FUNCTION__, pairing_cb.state);
2484
2485 /* We should not go for inquiry in BONDING STATE. */
2486 if (pairing_cb.state == BT_BOND_STATE_BONDING)
2487 return BT_STATUS_BUSY;
Satya Calloji6e2d9db2014-07-08 16:18:58 -07002488
2489#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2490 memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
2491 /* Cleanup anything remaining on index 0 */
2492 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL,
2493 bte_scan_filt_param_cfg_evt, 0);
2494
2495 /* Add an allow-all filter on index 0*/
2496 adv_filt_param.dely_mode = IMMEDIATE_DELY_MODE;
2497 adv_filt_param.feat_seln = ALLOW_ALL_FILTER;
2498 adv_filt_param.filt_logic_type = BTA_DM_BLE_PF_FILT_LOGIC_OR;
2499 adv_filt_param.list_logic_type = BTA_DM_BLE_PF_LIST_LOGIC_OR;
2500 adv_filt_param.rssi_low_thres = LOWEST_RSSI_VALUE;
2501 adv_filt_param.rssi_high_thres = LOWEST_RSSI_VALUE;
2502 BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_ADD, 0, &adv_filt_param, NULL,
2503 bte_scan_filt_param_cfg_evt, 0);
2504
The Android Open Source Project5738f832012-12-12 16:00:35 -08002505 /* TODO: Do we need to handle multiple inquiries at the same time? */
2506
2507 /* Set inquiry params and call API */
The Android Open Source Project5738f832012-12-12 16:00:35 -08002508 inq_params.mode = BTA_DM_GENERAL_INQUIRY|BTA_BLE_GENERAL_INQUIRY;
Matthew Xie7f3e4292013-09-30 12:44:10 -07002509#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
2510 inq_params.intl_duration[0]= BTIF_DM_INTERLEAVE_DURATION_BR_ONE;
2511 inq_params.intl_duration[1]= BTIF_DM_INTERLEAVE_DURATION_LE_ONE;
2512 inq_params.intl_duration[2]= BTIF_DM_INTERLEAVE_DURATION_BR_TWO;
2513 inq_params.intl_duration[3]= BTIF_DM_INTERLEAVE_DURATION_LE_TWO;
2514#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002515#else
2516 inq_params.mode = BTA_DM_GENERAL_INQUIRY;
2517#endif
2518 inq_params.duration = BTIF_DM_DEFAULT_INQ_MAX_DURATION;
2519
2520 inq_params.max_resps = BTIF_DM_DEFAULT_INQ_MAX_RESULTS;
2521 inq_params.report_dup = TRUE;
2522
2523 inq_params.filter_type = BTA_DM_INQ_CLR;
2524 /* TODO: Filter device by BDA needs to be implemented here */
2525
2526 /* Will be enabled to TRUE once inquiry busy level has been received */
2527 btif_dm_inquiry_in_progress = FALSE;
2528 /* find nearby devices */
2529 BTA_DmSearch(&inq_params, services, bte_search_devices_evt);
2530
2531 return BT_STATUS_SUCCESS;
2532}
2533
2534/*******************************************************************************
2535**
2536** Function btif_dm_cancel_discovery
2537**
2538** Description Cancels search
2539**
2540** Returns bt_status_t
2541**
2542*******************************************************************************/
2543bt_status_t btif_dm_cancel_discovery(void)
2544{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002545 BTIF_TRACE_EVENT("%s", __FUNCTION__);
Srinu Jellaaec80382013-12-14 20:04:41 +05302546
2547 if(BTM_IsInquiryActive() || (TRUE == BTM_IsRnrActive()) ||
2548 (btif_dm_inquiry_in_progress == TRUE)) {
2549 BTIF_TRACE_EVENT("%s : Inquiry is in progress", __FUNCTION__)
2550 BTA_DmSearchCancel();
2551 return BT_STATUS_SUCCESS;
2552 }
2553 else {
2554 BTIF_TRACE_EVENT("%s : Inquiry not started", __FUNCTION__);
2555 return BT_STATUS_FAIL;
2556 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002557}
2558
2559/*******************************************************************************
2560**
2561** Function btif_dm_create_bond
2562**
2563** Description Initiate bonding with the specified device
2564**
2565** Returns bt_status_t
2566**
2567*******************************************************************************/
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002568bt_status_t btif_dm_create_bond(const bt_bdaddr_t *bd_addr, int transport)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002569{
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002570 btif_dm_create_bond_cb_t create_bond_cb;
2571 create_bond_cb.transport = transport;
2572 bdcpy(create_bond_cb.bdaddr.address, bd_addr->address);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002573
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002574 bdstr_t bdstr;
2575 BTIF_TRACE_EVENT("%s: bd_addr=%s, transport=%d", __FUNCTION__,
2576 bd2str((bt_bdaddr_t *) bd_addr, &bdstr), transport);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002577 if (pairing_cb.state != BT_BOND_STATE_NONE)
2578 return BT_STATUS_BUSY;
2579
Srinu Jellaaec80382013-12-14 20:04:41 +05302580 BTIF_TRACE_EVENT("%s : Cancel Inquiry", __FUNCTION__);
2581 BTA_DmSearchCancel();
2582
The Android Open Source Project5738f832012-12-12 16:00:35 -08002583 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_CREATE_BOND,
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07002584 (char *)&create_bond_cb, sizeof(btif_dm_create_bond_cb_t), NULL);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002585
2586 return BT_STATUS_SUCCESS;
2587}
2588
2589/*******************************************************************************
2590**
2591** Function btif_dm_cancel_bond
2592**
2593** Description Initiate bonding with the specified device
2594**
2595** Returns bt_status_t
2596**
2597*******************************************************************************/
2598
2599bt_status_t btif_dm_cancel_bond(const bt_bdaddr_t *bd_addr)
2600{
2601 bdstr_t bdstr;
2602
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002603 BTIF_TRACE_EVENT("%s: bd_addr=%s", __FUNCTION__, bd2str((bt_bdaddr_t *)bd_addr, &bdstr));
The Android Open Source Project5738f832012-12-12 16:00:35 -08002604
2605 /* TODO:
2606 ** 1. Restore scan modes
2607 ** 2. special handling for HID devices
2608 */
2609 if (pairing_cb.state == BT_BOND_STATE_BONDING)
2610 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002611
2612#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2613
2614 if (pairing_cb.is_ssp)
2615 {
2616 if (pairing_cb.is_le_only)
2617 {
2618 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT);
2619 }
2620 else
Hemant Guptae1468692013-11-14 16:21:29 +05302621 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002622 BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE);
Hemant Guptae1468692013-11-14 16:21:29 +05302623 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2624 btif_storage_remove_bonded_device((bt_bdaddr_t *)bd_addr);
2625 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002626 }
2627 else
2628 {
2629 if (pairing_cb.is_le_only)
2630 {
2631 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2632 }
2633 else
2634 {
2635 BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL);
2636 }
2637 /* Cancel bonding, in case it is in ACL connection setup state */
2638 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2639 }
2640
2641#else
The Android Open Source Project5738f832012-12-12 16:00:35 -08002642 if (pairing_cb.is_ssp)
2643 {
2644 BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE);
2645 }
2646 else
2647 {
2648 BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL);
2649 }
2650 /* Cancel bonding, in case it is in ACL connection setup state */
2651 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2652 btif_storage_remove_bonded_device((bt_bdaddr_t *)bd_addr);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002653#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002654 }
2655
2656 return BT_STATUS_SUCCESS;
2657}
2658
2659/*******************************************************************************
2660**
Hemant Gupta29ccbb02014-07-15 23:33:32 +05302661** Function btif_dm_hh_open_success
2662**
2663** Description Checks if device is blacklisted, if yes takes appropriate action
2664**
2665** Returns none
2666**
2667*******************************************************************************/
2668
2669void btif_dm_hh_open_success(bt_bdaddr_t *bdaddr)
2670{
2671 if (pairing_cb.state == BT_BOND_STATE_BONDING &&
2672 bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0)
2673 {
2674 if (check_if_auth_bl(bdaddr->address)
2675 && check_cod_hid(bdaddr, COD_HID_MAJOR))
2676 {
2677 bt_status_t status;
2678 bond_state_changed(BT_STATUS_SUCCESS, bdaddr, BT_BOND_STATE_BONDED);
2679 BTIF_TRACE_DEBUG("%s: Device is blacklisted for authentication",__FUNCTION__);
2680 bt_property_t prop;
2681 bt_uuid_t uuid;
2682 char uuid_str[128] = UUID_HUMAN_INTERFACE_DEVICE;
2683 string_to_uuid(uuid_str, &uuid);
2684 prop.type = BT_PROPERTY_UUIDS;
2685 prop.val = uuid.uu;
2686 prop.len = MAX_UUID_SIZE;
2687 /* Also write this to the NVRAM */
2688 status = btif_storage_set_remote_device_property(bdaddr, &prop);
2689 ASSERTC(status == BT_STATUS_SUCCESS, "storing remote services failed", status);
2690 /* Store Device as bonded in nvram */
2691 btif_storage_add_bonded_device(bdaddr, NULL, 0, 0);
2692 /* Send the event to the BTIF */
2693 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
2694 BT_STATUS_SUCCESS, bdaddr, 1, &prop);
2695 }
2696 }
2697}
2698
2699/*******************************************************************************
2700**
Kim Schulza9eb25c2013-09-30 10:55:52 +02002701** Function btif_dm_hh_open_failed
2702**
2703** Description informs the upper layers if the HH have failed during bonding
2704**
2705** Returns none
2706**
2707*******************************************************************************/
2708
2709void btif_dm_hh_open_failed(bt_bdaddr_t *bdaddr)
2710{
2711 if (pairing_cb.state == BT_BOND_STATE_BONDING &&
2712 bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0)
2713 {
2714 bond_state_changed(BT_STATUS_FAIL, bdaddr, BT_BOND_STATE_NONE);
2715 }
2716}
2717
2718/*******************************************************************************
2719**
The Android Open Source Project5738f832012-12-12 16:00:35 -08002720** Function btif_dm_remove_bond
2721**
2722** Description Removes bonding with the specified device
2723**
2724** Returns bt_status_t
2725**
2726*******************************************************************************/
2727
2728bt_status_t btif_dm_remove_bond(const bt_bdaddr_t *bd_addr)
2729{
2730 bdstr_t bdstr;
2731
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002732 BTIF_TRACE_EVENT("%s: bd_addr=%s", __FUNCTION__, bd2str((bt_bdaddr_t *)bd_addr, &bdstr));
The Android Open Source Project5738f832012-12-12 16:00:35 -08002733 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_REMOVE_BOND,
2734 (char *)bd_addr, sizeof(bt_bdaddr_t), NULL);
2735
2736 return BT_STATUS_SUCCESS;
2737}
2738
2739/*******************************************************************************
2740**
2741** Function btif_dm_pin_reply
2742**
2743** Description BT legacy pairing - PIN code reply
2744**
2745** Returns bt_status_t
2746**
2747*******************************************************************************/
2748
2749bt_status_t btif_dm_pin_reply( const bt_bdaddr_t *bd_addr, uint8_t accept,
2750 uint8_t pin_len, bt_pin_code_t *pin_code)
2751{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002752 BTIF_TRACE_EVENT("%s: accept=%d", __FUNCTION__, accept);
Hemant Gupta831423e2014-01-08 12:42:13 +05302753 if (pin_code == NULL)
2754 return BT_STATUS_FAIL;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002755#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002756
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002757 if (pairing_cb.is_le_only)
2758 {
2759 int i;
2760 UINT32 passkey = 0;
2761 int multi[] = {100000, 10000, 1000, 100, 10,1};
2762 BD_ADDR remote_bd_addr;
2763 bdcpy(remote_bd_addr, bd_addr->address);
2764 for (i = 0; i < 6; i++)
2765 {
2766 passkey += (multi[i] * (pin_code->pin[i] - '0'));
2767 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002768 BTIF_TRACE_DEBUG("btif_dm_pin_reply: passkey: %d", passkey);
Nitin Arora080087a2014-08-29 10:50:00 -07002769 if(pin_len > BTIF_DM_LE_PIN_LEN_MAX)/*incorrect key len*/
2770 {
2771 accept = FALSE;
2772 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002773 BTA_DmBlePasskeyReply(remote_bd_addr, accept, passkey);
2774
2775 }
2776 else
2777 {
2778 BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin);
2779 if (accept)
2780 pairing_cb.pin_code_len = pin_len;
2781 }
2782#else
The Android Open Source Project5738f832012-12-12 16:00:35 -08002783 BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin);
2784
2785 if (accept)
2786 pairing_cb.pin_code_len = pin_len;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002787#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002788 return BT_STATUS_SUCCESS;
2789}
2790
2791/*******************************************************************************
2792**
2793** Function btif_dm_ssp_reply
2794**
2795** Description BT SSP Reply - Just Works, Numeric Comparison & Passkey Entry
2796**
2797** Returns bt_status_t
2798**
2799*******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -08002800bt_status_t btif_dm_ssp_reply(const bt_bdaddr_t *bd_addr,
2801 bt_ssp_variant_t variant, uint8_t accept,
2802 uint32_t passkey)
2803{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002804 UNUSED(passkey);
2805
The Android Open Source Project5738f832012-12-12 16:00:35 -08002806 if (variant == BT_SSP_VARIANT_PASSKEY_ENTRY)
2807 {
2808 /* This is not implemented in the stack.
2809 * For devices with display, this is not needed
2810 */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002811 BTIF_TRACE_WARNING("%s: Not implemented", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002812 return BT_STATUS_FAIL;
2813 }
2814 /* BT_SSP_VARIANT_CONSENT & BT_SSP_VARIANT_PASSKEY_CONFIRMATION supported */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002815 BTIF_TRACE_EVENT("%s: accept=%d", __FUNCTION__, accept);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002816#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2817 if (pairing_cb.is_le_only)
2818 {
2819 if (accept)
2820 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_GRANTED);
2821 else
2822 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT);
2823 }
2824 else
2825 BTA_DmConfirm( (UINT8 *)bd_addr->address, accept);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002826
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002827#else
2828 BTA_DmConfirm( (UINT8 *)bd_addr->address, accept);
2829#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002830 return BT_STATUS_SUCCESS;
2831}
2832
2833/*******************************************************************************
2834**
2835** Function btif_dm_get_adapter_property
2836**
2837** Description Queries the BTA for the adapter property
2838**
2839** Returns bt_status_t
2840**
2841*******************************************************************************/
2842bt_status_t btif_dm_get_adapter_property(bt_property_t *prop)
2843{
2844 bt_status_t status;
2845
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002846 BTIF_TRACE_EVENT("%s: type=0x%x", __FUNCTION__, prop->type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002847 switch (prop->type)
2848 {
2849 case BT_PROPERTY_BDNAME:
2850 {
2851 bt_bdname_t *bd_name = (bt_bdname_t*)prop->val;
Matthew Xie1e5109b2012-11-09 18:26:26 -08002852 strcpy((char *)bd_name->name, btif_get_default_local_name());
The Android Open Source Project5738f832012-12-12 16:00:35 -08002853 prop->len = strlen((char *)bd_name->name);
2854 }
2855 break;
2856
2857 case BT_PROPERTY_ADAPTER_SCAN_MODE:
2858 {
Juffin Alex Varghese2eb4c6b2013-08-16 19:40:35 +05302859 /* get scan mode state from storage */
The Android Open Source Project5738f832012-12-12 16:00:35 -08002860 bt_scan_mode_t *mode = (bt_scan_mode_t*)prop->val;
Juffin Alex Varghese2eb4c6b2013-08-16 19:40:35 +05302861 switch (*mode)
2862 {
2863 case BT_SCAN_MODE_NONE:
2864 case BT_SCAN_MODE_CONNECTABLE:
2865 case BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE:
2866 break;
2867
2868 default:
2869 *mode = BT_SCAN_MODE_NONE;
2870 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08002871 prop->len = sizeof(bt_scan_mode_t);
2872 }
2873 break;
2874
2875 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
2876 {
2877 uint32_t *tmt = (uint32_t*)prop->val;
2878 *tmt = 120; /* default to 120s, if not found in NV */
2879 prop->len = sizeof(uint32_t);
2880 }
2881 break;
2882
2883 default:
2884 prop->len = 0;
2885 return BT_STATUS_FAIL;
2886 }
2887 return BT_STATUS_SUCCESS;
2888}
2889
2890/*******************************************************************************
2891**
2892** Function btif_dm_get_remote_services
2893**
2894** Description Start SDP to get remote services
2895**
2896** Returns bt_status_t
2897**
2898*******************************************************************************/
2899bt_status_t btif_dm_get_remote_services(bt_bdaddr_t *remote_addr)
2900{
2901 bdstr_t bdstr;
2902
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002903 BTIF_TRACE_EVENT("%s: remote_addr=%s", __FUNCTION__, bd2str(remote_addr, &bdstr));
The Android Open Source Project5738f832012-12-12 16:00:35 -08002904
2905 BTA_DmDiscover(remote_addr->address, BTA_ALL_SERVICE_MASK,
2906 bte_dm_search_services_evt, TRUE);
2907
2908 return BT_STATUS_SUCCESS;
2909}
2910
2911/*******************************************************************************
2912**
2913** Function btif_dm_get_remote_service_record
2914**
2915** Description Start SDP to get remote service record
2916**
2917**
2918** Returns bt_status_t
2919*******************************************************************************/
2920bt_status_t btif_dm_get_remote_service_record(bt_bdaddr_t *remote_addr,
2921 bt_uuid_t *uuid)
2922{
2923 tSDP_UUID sdp_uuid;
2924 bdstr_t bdstr;
2925
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002926 BTIF_TRACE_EVENT("%s: remote_addr=%s", __FUNCTION__, bd2str(remote_addr, &bdstr));
The Android Open Source Project5738f832012-12-12 16:00:35 -08002927
2928 sdp_uuid.len = MAX_UUID_SIZE;
2929 memcpy(sdp_uuid.uu.uuid128, uuid->uu, MAX_UUID_SIZE);
2930
2931 BTA_DmDiscoverUUID(remote_addr->address, &sdp_uuid,
2932 bte_dm_remote_service_record_evt, TRUE);
2933
2934 return BT_STATUS_SUCCESS;
2935}
2936
2937void btif_dm_execute_service_request(UINT16 event, char *p_param)
2938{
2939 BOOLEAN b_enable = FALSE;
2940 bt_status_t status;
2941 if (event == BTIF_DM_ENABLE_SERVICE)
2942 {
2943 b_enable = TRUE;
2944 }
2945 status = btif_in_execute_service_request(*((tBTA_SERVICE_ID*)p_param), b_enable);
2946 if (status == BT_STATUS_SUCCESS)
2947 {
2948 bt_property_t property;
2949 bt_uuid_t local_uuids[BT_MAX_NUM_UUIDS];
2950
2951 /* Now send the UUID_PROPERTY_CHANGED event to the upper layer */
2952 BTIF_STORAGE_FILL_PROPERTY(&property, BT_PROPERTY_UUIDS,
2953 sizeof(local_uuids), local_uuids);
2954 btif_storage_get_adapter_property(&property);
2955 HAL_CBACK(bt_hal_cbacks, adapter_properties_cb,
2956 BT_STATUS_SUCCESS, 1, &property);
2957 }
2958 return;
2959}
2960
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002961void btif_dm_proc_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, tBTA_OOB_DATA *p_oob_data,
2962 tBTA_AUTH_REQ *p_auth_req, BOOLEAN is_orig)
2963{
2964 UINT8 yes_no_bit = BTA_AUTH_SP_YES & *p_auth_req;
2965 /* if local initiated:
2966 ** 1. set DD + MITM
2967 ** if remote initiated:
2968 ** 1. Copy over the auth_req from peer's io_rsp
2969 ** 2. Set the MITM if peer has it set or if peer has DisplayYesNo (iPhone)
2970 ** as a fallback set MITM+GB if peer had MITM set
2971 */
2972 UNUSED (bd_addr);
2973 UNUSED (p_io_cap);
2974 UNUSED (p_oob_data);
2975
2976
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002977 BTIF_TRACE_DEBUG("+%s: p_auth_req=%d", __FUNCTION__, *p_auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002978 if(pairing_cb.is_local_initiated)
2979 {
2980 /* if initing/responding to a dedicated bonding, use dedicate bonding bit */
2981 *p_auth_req = BTA_AUTH_DD_BOND | BTA_AUTH_SP_YES;
2982 }
2983 else if (!is_orig)
2984 {
2985 /* peer initiated paring. They probably know what they want.
2986 ** Copy the mitm from peer device.
2987 */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002988 BTIF_TRACE_DEBUG("%s: setting p_auth_req to peer's: %d",
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002989 __FUNCTION__, pairing_cb.auth_req);
2990 *p_auth_req = (pairing_cb.auth_req & BTA_AUTH_BONDS);
2991
2992 /* copy over the MITM bit as well. In addition if the peer has DisplayYesNo, force MITM */
2993 if ((yes_no_bit) || (pairing_cb.io_cap & BTM_IO_CAP_IO) )
2994 *p_auth_req |= BTA_AUTH_SP_YES;
2995 }
2996 else if (yes_no_bit)
2997 {
2998 /* set the general bonding bit for stored device */
2999 *p_auth_req = BTA_AUTH_GEN_BOND | yes_no_bit;
3000 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003001 BTIF_TRACE_DEBUG("-%s: p_auth_req=%d", __FUNCTION__, *p_auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07003002}
3003
3004void btif_dm_proc_io_rsp(BD_ADDR bd_addr, tBTA_IO_CAP io_cap,
3005 tBTA_OOB_DATA oob_data, tBTA_AUTH_REQ auth_req)
3006{
3007 UNUSED (bd_addr);
3008 UNUSED (oob_data);
Andre Eisenbachb0daa5d2014-08-04 17:50:10 -07003009
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07003010 if(auth_req & BTA_AUTH_BONDS)
3011 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003012 BTIF_TRACE_DEBUG("%s auth_req:%d", __FUNCTION__, auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07003013 pairing_cb.auth_req = auth_req;
3014 pairing_cb.io_cap = io_cap;
3015 }
3016}
3017
The Android Open Source Project5738f832012-12-12 16:00:35 -08003018#if (BTM_OOB_INCLUDED == TRUE)
3019void btif_dm_set_oob_for_io_req(tBTA_OOB_DATA *p_oob_data)
3020{
3021 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
3022 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
3023 {
3024 *p_oob_data = FALSE;
3025 }
3026 else
3027 {
3028 *p_oob_data = TRUE;
3029 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003030 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 -08003031}
3032#endif /* BTM_OOB_INCLUDED */
3033
3034#ifdef BTIF_DM_OOB_TEST
3035void btif_dm_load_local_oob(void)
3036{
Nick Kralevichd70b7a82013-01-31 14:40:15 -08003037 char prop_oob[PROPERTY_VALUE_MAX];
The Android Open Source Project5738f832012-12-12 16:00:35 -08003038 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003039 BTIF_TRACE_DEBUG("btif_dm_load_local_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003040 if (prop_oob[0] != '3')
3041 {
3042#if (BTM_OOB_INCLUDED == TRUE)
3043 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
3044 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
3045 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003046 BTIF_TRACE_DEBUG("btif_dm_load_local_oob: read OOB, call BTA_DmLocalOob()");
The Android Open Source Project5738f832012-12-12 16:00:35 -08003047 BTA_DmLocalOob();
3048 }
3049#else
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003050 BTIF_TRACE_ERROR("BTM_OOB_INCLUDED is FALSE!!(btif_dm_load_local_oob)");
The Android Open Source Project5738f832012-12-12 16:00:35 -08003051#endif
3052 }
3053}
3054
3055void btif_dm_proc_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r)
3056{
3057 FILE *fp;
3058 char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
3059 char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
3060 char *path = NULL;
Nick Kralevichd70b7a82013-01-31 14:40:15 -08003061 char prop_oob[PROPERTY_VALUE_MAX];
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003062 BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob: valid=%d", valid);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003063 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
3064 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 &&
3065 valid)
3066 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003067 BTIF_TRACE_DEBUG("save local OOB data in memory");
The Android Open Source Project5738f832012-12-12 16:00:35 -08003068 memcpy(oob_cb.sp_c, c, BT_OCTET16_LEN);
3069 memcpy(oob_cb.sp_r, r, BT_OCTET16_LEN);
3070 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003071 BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003072 if (prop_oob[0] == '1')
3073 path = path_a;
3074 else if (prop_oob[0] == '2')
3075 path = path_b;
3076 if (path)
3077 {
3078 fp = fopen(path, "wb+");
3079 if (fp == NULL)
3080 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003081 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 -08003082 }
3083 else
3084 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003085 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 -08003086 fwrite (c , 1 , BT_OCTET16_LEN , fp );
3087 fwrite (r , 1 , BT_OCTET16_LEN , fp );
3088 fclose(fp);
3089 }
3090 }
3091 }
3092}
3093BOOLEAN btif_dm_proc_rmt_oob(BD_ADDR bd_addr, BT_OCTET16 p_c, BT_OCTET16 p_r)
3094{
3095 char t[128];
3096 FILE *fp;
3097 char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
3098 char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
3099 char *path = NULL;
Nick Kralevichd70b7a82013-01-31 14:40:15 -08003100 char prop_oob[PROPERTY_VALUE_MAX];
The Android Open Source Project5738f832012-12-12 16:00:35 -08003101 BOOLEAN result = FALSE;
3102 bt_bdaddr_t bt_bd_addr;
3103 bdcpy(oob_cb.oob_bdaddr, bd_addr);
3104 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003105 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003106 if (prop_oob[0] == '1')
3107 path = path_b;
3108 else if (prop_oob[0] == '2')
3109 path = path_a;
3110 if (path)
3111 {
3112 fp = fopen(path, "rb");
3113 if (fp == NULL)
3114 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003115 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 -08003116 return FALSE;
3117 }
3118 else
3119 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003120 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob: read OOB data from %s",path);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003121 fread (p_c , 1 , BT_OCTET16_LEN , fp );
3122 fread (p_r , 1 , BT_OCTET16_LEN , fp );
3123 fclose(fp);
3124 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003125 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: TRUE");
The Android Open Source Project5738f832012-12-12 16:00:35 -08003126 sprintf(t, "%02x:%02x:%02x:%02x:%02x:%02x",
3127 oob_cb.oob_bdaddr[0], oob_cb.oob_bdaddr[1], oob_cb.oob_bdaddr[2],
3128 oob_cb.oob_bdaddr[3], oob_cb.oob_bdaddr[4], oob_cb.oob_bdaddr[5]);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003129 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: peer_bdaddr = %s", t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003130 sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
3131 p_c[0], p_c[1], p_c[2], p_c[3], p_c[4], p_c[5], p_c[6], p_c[7],
3132 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 -07003133 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: c = %s",t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003134 sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
3135 p_r[0], p_r[1], p_r[2], p_r[3], p_r[4], p_r[5], p_r[6], p_r[7],
3136 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 -07003137 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: r = %s",t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003138 bdcpy(bt_bd_addr.address, bd_addr);
3139 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_BOND_STATE_BONDING,
3140 (char *)&bt_bd_addr, sizeof(bt_bdaddr_t), NULL);
3141 result = TRUE;
3142 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003143 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob result=%d",result);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003144 return result;
3145}
3146#endif /* BTIF_DM_OOB_TEST */
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003147#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
3148
3149static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif)
3150{
3151 bt_bdaddr_t bd_addr;
3152 bt_bdname_t bd_name;
3153 UINT32 cod;
3154
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003155 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003156
3157 /* Remote name update */
3158 btif_update_remote_properties(p_ssp_key_notif->bd_addr , p_ssp_key_notif->bd_name,
3159 NULL, BT_DEVICE_TYPE_BLE);
3160 bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
3161 memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
3162
3163 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
3164 pairing_cb.is_ssp = FALSE;
3165 cod = COD_UNCLASSIFIED;
3166
3167 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
3168 cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION,
3169 p_ssp_key_notif->passkey);
3170}
3171
3172/*******************************************************************************
3173**
3174** Function btif_dm_ble_auth_cmpl_evt
3175**
3176** Description Executes authentication complete event in btif context
3177**
3178** Returns void
3179**
3180*******************************************************************************/
3181static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
3182{
3183 /* Save link key, if not temporary */
3184 bt_bdaddr_t bd_addr;
3185 bt_status_t status = BT_STATUS_FAIL;
3186 bt_bond_state_t state = BT_BOND_STATE_NONE;
3187
3188 bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
3189 if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
3190 {
3191 /* store keys */
3192 }
3193 if (p_auth_cmpl->success)
3194 {
3195 status = BT_STATUS_SUCCESS;
3196 state = BT_BOND_STATE_BONDED;
3197
Nitin Arora60ea0ed2014-08-05 11:06:23 -07003198 if(btif_hh_find_added_dev_by_bda(&bd_addr))
3199 {
3200 BTIF_TRACE_DEBUG("%s, device already paired, skipping discovery",__FUNCTION__ );
3201 }
3202 else
3203 {
3204 btif_dm_save_ble_bonding_keys();
Amit Goel19cedbb2014-05-21 15:58:04 -07003205 BTA_GATTC_Refresh_No_Discovery(bd_addr.address);
Nitin Arora60ea0ed2014-08-05 11:06:23 -07003206 btif_dm_get_remote_services(&bd_addr);
3207 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003208 }
3209 else
3210 {
3211 /*Map the HCI fail reason to bt status */
3212 switch (p_auth_cmpl->fail_reason)
3213 {
Priti Aghera156c52b2014-07-09 14:58:19 -07003214 case BTA_DM_AUTH_SMP_PAIR_AUTH_FAIL:
3215 case BTA_DM_AUTH_SMP_CONFIRM_VALUE_FAIL:
3216 btif_dm_remove_ble_bonding_keys();
3217 status = BT_STATUS_AUTH_FAILURE;
3218 break;
3219 case BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT:
3220 status = BT_STATUS_AUTH_REJECTED;
3221 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003222 default:
Andre Eisenbachca22ac42013-02-13 17:02:11 +09003223 btif_dm_remove_ble_bonding_keys();
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003224 status = BT_STATUS_FAIL;
3225 break;
3226 }
3227 }
3228 bond_state_changed(status, &bd_addr, state);
Nitin Arora60ea0ed2014-08-05 11:06:23 -07003229 if(state==BT_BOND_STATE_BONDED)
3230 {
3231 BTIF_TRACE_DEBUG("%s, save keys immidiately",__FUNCTION__ );
3232 btif_config_flush();
3233 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003234}
3235
3236
3237
3238void btif_dm_load_ble_local_keys(void)
3239{
3240 bt_status_t bt_status;
3241
3242 memset(&ble_local_key_cb, 0, sizeof(btif_dm_local_key_cb_t));
3243
3244 if (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_ER,(char*)&ble_local_key_cb.er[0],
3245 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)
3246 {
3247 ble_local_key_cb.is_er_rcvd = TRUE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003248 BTIF_TRACE_DEBUG("%s BLE ER key loaded",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003249 }
3250
3251 if ((btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IR,(char*)&ble_local_key_cb.id_keys.ir[0],
3252 BT_OCTET16_LEN)== BT_STATUS_SUCCESS )&&
3253 (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IRK, (char*)&ble_local_key_cb.id_keys.irk[0],
3254 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)&&
3255 (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_DHK,(char*)&ble_local_key_cb.id_keys.dhk[0],
3256 BT_OCTET16_LEN)== BT_STATUS_SUCCESS))
3257 {
3258 ble_local_key_cb.is_id_keys_rcvd = TRUE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003259 BTIF_TRACE_DEBUG("%s BLE ID keys loaded",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003260 }
3261
3262}
3263void btif_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
3264 tBTA_BLE_LOCAL_ID_KEYS *p_id_keys)
3265{
3266 if (ble_local_key_cb.is_er_rcvd )
3267 {
3268 memcpy(&er[0], &ble_local_key_cb.er[0], sizeof(BT_OCTET16));
3269 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ER;
3270 }
3271
3272 if (ble_local_key_cb.is_id_keys_rcvd)
3273 {
3274 memcpy(&p_id_keys->ir[0], &ble_local_key_cb.id_keys.ir[0], sizeof(BT_OCTET16));
3275 memcpy(&p_id_keys->irk[0], &ble_local_key_cb.id_keys.irk[0], sizeof(BT_OCTET16));
3276 memcpy(&p_id_keys->dhk[0], &ble_local_key_cb.id_keys.dhk[0], sizeof(BT_OCTET16));
3277 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID;
3278 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003279 BTIF_TRACE_DEBUG("%s *p_key_mask=0x%02x",__FUNCTION__, *p_key_mask);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003280}
3281
3282void btif_dm_save_ble_bonding_keys(void)
3283{
3284
3285 bt_bdaddr_t bd_addr;
3286
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003287 BTIF_TRACE_DEBUG("%s",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003288
3289 bdcpy(bd_addr.address, pairing_cb.bd_addr);
3290
3291 if (pairing_cb.ble.is_penc_key_rcvd)
3292 {
3293 btif_storage_add_ble_bonding_key(&bd_addr,
3294 (char *) &pairing_cb.ble.penc_key,
3295 BTIF_DM_LE_KEY_PENC,
3296 sizeof(btif_dm_ble_penc_keys_t));
3297 }
3298
3299 if (pairing_cb.ble.is_pid_key_rcvd)
3300 {
3301 btif_storage_add_ble_bonding_key(&bd_addr,
Andre Eisenbachda9b0f82014-10-21 12:37:53 -07003302 (char *) &pairing_cb.ble.pid_key,
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003303 BTIF_DM_LE_KEY_PID,
Andre Eisenbachda9b0f82014-10-21 12:37:53 -07003304 sizeof(btif_dm_ble_pid_keys_t));
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003305 }
3306
3307
3308 if (pairing_cb.ble.is_pcsrk_key_rcvd)
3309 {
3310 btif_storage_add_ble_bonding_key(&bd_addr,
3311 (char *) &pairing_cb.ble.pcsrk_key,
3312 BTIF_DM_LE_KEY_PCSRK,
3313 sizeof(btif_dm_ble_pcsrk_keys_t));
3314 }
3315
3316
3317 if (pairing_cb.ble.is_lenc_key_rcvd)
3318 {
3319 btif_storage_add_ble_bonding_key(&bd_addr,
3320 (char *) &pairing_cb.ble.lenc_key,
3321 BTIF_DM_LE_KEY_LENC,
3322 sizeof(btif_dm_ble_lenc_keys_t));
3323 }
3324
3325 if (pairing_cb.ble.is_lcsrk_key_rcvd)
3326 {
3327 btif_storage_add_ble_bonding_key(&bd_addr,
3328 (char *) &pairing_cb.ble.lcsrk_key,
3329 BTIF_DM_LE_KEY_LCSRK,
3330 sizeof(btif_dm_ble_lcsrk_keys_t));
3331 }
3332
3333}
3334
3335
3336void btif_dm_remove_ble_bonding_keys(void)
3337{
3338 bt_bdaddr_t bd_addr;
3339
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003340 BTIF_TRACE_DEBUG("%s",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003341
3342 bdcpy(bd_addr.address, pairing_cb.bd_addr);
3343 btif_storage_remove_ble_bonding_keys(&bd_addr);
3344}
3345
3346
3347/*******************************************************************************
3348**
3349** Function btif_dm_ble_sec_req_evt
3350**
3351** Description Eprocess security request event in btif context
3352**
3353** Returns void
3354**
3355*******************************************************************************/
3356void btif_dm_ble_sec_req_evt(tBTA_DM_BLE_SEC_REQ *p_ble_req)
3357{
3358 bt_bdaddr_t bd_addr;
3359 bt_bdname_t bd_name;
3360 UINT32 cod;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003361 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003362
3363 if (pairing_cb.state == BT_BOND_STATE_BONDING)
3364 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003365 BTIF_TRACE_DEBUG("%s Discard security request", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003366 return;
3367 }
3368
3369 /* Remote name update */
3370 btif_update_remote_properties(p_ble_req->bd_addr,p_ble_req->bd_name,NULL,BT_DEVICE_TYPE_BLE);
3371
3372 bdcpy(bd_addr.address, p_ble_req->bd_addr);
3373 memcpy(bd_name.name, p_ble_req->bd_name, BD_NAME_LEN);
3374
3375 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
3376
3377 pairing_cb.is_temp = FALSE;
3378 pairing_cb.is_le_only = TRUE;
3379 pairing_cb.is_ssp = TRUE;
3380
3381 cod = COD_UNCLASSIFIED;
3382
3383 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod,
3384 BT_SSP_VARIANT_CONSENT, 0);
3385}
3386
3387
3388
3389/*******************************************************************************
3390**
3391** Function btif_dm_ble_passkey_req_evt
3392**
3393** Description Executes pin request event in btif context
3394**
3395** Returns void
3396**
3397*******************************************************************************/
3398static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
3399{
3400 bt_bdaddr_t bd_addr;
3401 bt_bdname_t bd_name;
3402 UINT32 cod;
3403
3404 /* Remote name update */
3405 btif_update_remote_properties(p_pin_req->bd_addr,p_pin_req->bd_name,NULL,BT_DEVICE_TYPE_BLE);
3406
3407 bdcpy(bd_addr.address, p_pin_req->bd_addr);
3408 memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN);
3409
3410 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
3411 pairing_cb.is_le_only = TRUE;
3412
3413 cod = COD_UNCLASSIFIED;
3414
3415 HAL_CBACK(bt_hal_cbacks, pin_request_cb,
Srinu Jellaedadca02013-07-05 18:20:40 +05303416 &bd_addr, &bd_name, cod, FALSE);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003417}
3418
3419
3420void btif_dm_update_ble_remote_properties( BD_ADDR bd_addr, BD_NAME bd_name,
3421 tBT_DEVICE_TYPE dev_type)
3422{
3423 btif_update_remote_properties(bd_addr,bd_name,NULL,dev_type);
3424}
3425
3426static void btif_dm_ble_tx_test_cback(void *p)
3427{
3428 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TX_TEST,
3429 (char *)p, 1, NULL);
3430}
3431
3432static void btif_dm_ble_rx_test_cback(void *p)
3433{
3434 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_RX_TEST,
3435 (char *)p, 1, NULL);
3436}
3437
3438static void btif_dm_ble_test_end_cback(void *p)
3439{
3440 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TEST_END,
3441 (char *)p, 3, NULL);
3442}
3443/*******************************************************************************
3444**
3445** Function btif_le_test_mode
3446**
3447** Description Sends a HCI BLE Test command to the Controller
3448**
3449** Returns BT_STATUS_SUCCESS on success
3450**
3451*******************************************************************************/
3452bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t len)
3453{
3454 switch (opcode) {
3455 case HCI_BLE_TRANSMITTER_TEST:
3456 if (len != 3) return BT_STATUS_PARM_INVALID;
3457 BTM_BleTransmitterTest(buf[0],buf[1],buf[2], btif_dm_ble_tx_test_cback);
3458 break;
3459 case HCI_BLE_RECEIVER_TEST:
3460 if (len != 1) return BT_STATUS_PARM_INVALID;
3461 BTM_BleReceiverTest(buf[0], btif_dm_ble_rx_test_cback);
3462 break;
3463 case HCI_BLE_TEST_END:
3464 BTM_BleTestEnd((tBTM_CMPL_CB*) btif_dm_ble_test_end_cback);
3465 break;
3466 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003467 BTIF_TRACE_ERROR("%s: Unknown LE Test Mode Command 0x%x", __FUNCTION__, opcode);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08003468 return BT_STATUS_UNSUPPORTED;
3469 }
3470 return BT_STATUS_SUCCESS;
3471}
3472
3473#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08003474
3475void btif_dm_on_disable()
3476{
3477 /* cancel any pending pairing requests */
3478 if (pairing_cb.state == BT_BOND_STATE_BONDING)
3479 {
3480 bt_bdaddr_t bd_addr;
3481
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07003482 BTIF_TRACE_DEBUG("%s: Cancel pending pairing request", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08003483 bdcpy(bd_addr.address, pairing_cb.bd_addr);
3484 btif_dm_cancel_bond(&bd_addr);
3485 }
3486}
Matthew Xie1e5109b2012-11-09 18:26:26 -08003487
Satya Callojie5ba8842014-07-03 17:18:02 -07003488/*******************************************************************************
3489**
3490** Function btif_dm_read_energy_info
3491**
3492** Description Reads the energy info from controller
3493**
3494** Returns void
3495**
3496*******************************************************************************/
3497void btif_dm_read_energy_info()
3498{
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07003499#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Satya Callojie5ba8842014-07-03 17:18:02 -07003500 BTA_DmBleGetEnergyInfo(bta_energy_info_cb);
Prerepa Viswanadham81b03192014-07-23 17:49:48 -07003501#endif
Satya Callojie5ba8842014-07-03 17:18:02 -07003502}
3503
Matthew Xie1e5109b2012-11-09 18:26:26 -08003504static char* btif_get_default_local_name() {
3505 if (btif_default_local_name[0] == '\0')
3506 {
3507 int max_len = sizeof(btif_default_local_name) - 1;
3508 if (BTM_DEF_LOCAL_NAME[0] != '\0')
3509 {
3510 strncpy(btif_default_local_name, BTM_DEF_LOCAL_NAME, max_len);
3511 }
3512 else
3513 {
3514 char prop_model[PROPERTY_VALUE_MAX];
3515 property_get(PROPERTY_PRODUCT_MODEL, prop_model, "");
3516 strncpy(btif_default_local_name, prop_model, max_len);
3517 }
3518 btif_default_local_name[max_len] = '\0';
3519 }
3520 return btif_default_local_name;
3521}