blob: fd561f46c5e6cae65deed48894750d37baa72a64 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
2 *
3 * Copyright (C) 2009-2012 Broadcom Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19/************************************************************************************
20 *
21 * Filename: btif_dm.c
22 *
23 * Description: Contains Device Management (DM) related functionality
24 *
25 *
26 ***********************************************************************************/
27#include <stdio.h>
28#include <stdlib.h>
29#include <unistd.h>
30
31#include <hardware/bluetooth.h>
32
33#include <utils/Log.h>
34#include <cutils/properties.h>
35#include "gki.h"
36#include "btu.h"
37#include "bd.h"
38#include "bta_api.h"
39#include "btif_api.h"
40#include "btif_util.h"
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080041#include "btif_dm.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080042#include "btif_storage.h"
43#include "btif_hh.h"
44#include "btif_config.h"
45
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080046#include "bta_gatt_api.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080047/******************************************************************************
48** Constants & Macros
49******************************************************************************/
50
51#define COD_UNCLASSIFIED ((0x1F) << 8)
Priti Agheraebb1d752012-11-27 18:03:22 -080052#define COD_HID_KEYBOARD 0x0540
53#define COD_HID_POINTING 0x0580
54#define COD_HID_COMBO 0x05C0
55#define COD_HID_MAJOR 0x0500
56#define COD_AV_HEADSETS 0x0404
57#define COD_AV_HANDSFREE 0x0408
58#define COD_AV_HEADPHONES 0x0418
59#define COD_AV_PORTABLE_AUDIO 0x041C
60#define COD_AV_HIFI_AUDIO 0x0428
The Android Open Source Project5738f832012-12-12 16:00:35 -080061
62
63#define BTIF_DM_DEFAULT_INQ_MAX_RESULTS 0
64#define BTIF_DM_DEFAULT_INQ_MAX_DURATION 10
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -070065#define BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING 2
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080066
Matthew Xie1e5109b2012-11-09 18:26:26 -080067#define PROPERTY_PRODUCT_MODEL "ro.product.model"
Matthew Xiea30d95a2013-09-18 12:30:36 -070068#define DEFAULT_LOCAL_NAME_MAX 31
Matthew Xie1e5109b2012-11-09 18:26:26 -080069#if (DEFAULT_LOCAL_NAME_MAX > BTM_MAX_LOC_BD_NAME_LEN)
70 #error "default btif local name size exceeds stack supported length"
71#endif
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080072
Matthew Xie7f3e4292013-09-30 12:44:10 -070073#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
74#define BTIF_DM_INTERLEAVE_DURATION_BR_ONE 2
75#define BTIF_DM_INTERLEAVE_DURATION_LE_ONE 2
76#define BTIF_DM_INTERLEAVE_DURATION_BR_TWO 3
77#define BTIF_DM_INTERLEAVE_DURATION_LE_TWO 4
78#endif
79
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080080typedef struct
81{
The Android Open Source Project5738f832012-12-12 16:00:35 -080082 bt_bond_state_t state;
83 BD_ADDR bd_addr;
84 UINT8 is_temp;
85 UINT8 pin_code_len;
86 UINT8 is_ssp;
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -070087 UINT8 auth_req;
88 UINT8 io_cap;
The Android Open Source Project5738f832012-12-12 16:00:35 -080089 UINT8 autopair_attempts;
90 UINT8 is_local_initiated;
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -070091 UINT8 sdp_attempts;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080092#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
93 BOOLEAN is_le_only;
94 btif_dm_ble_cb_t ble;
95#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -080096} btif_dm_pairing_cb_t;
97
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -080098
99typedef struct
100{
101 UINT8 ir[BT_OCTET16_LEN];
102 UINT8 irk[BT_OCTET16_LEN];
103 UINT8 dhk[BT_OCTET16_LEN];
104}btif_dm_local_key_id_t;
105
106typedef struct
107{
108 BOOLEAN is_er_rcvd;
109 UINT8 er[BT_OCTET16_LEN];
110 BOOLEAN is_id_keys_rcvd;
111 btif_dm_local_key_id_t id_keys; /* ID kyes */
112
113}btif_dm_local_key_cb_t;
114
115typedef struct
116{
The Android Open Source Project5738f832012-12-12 16:00:35 -0800117 BD_ADDR bd_addr;
118 BD_NAME bd_name;
119} btif_dm_remote_name_t;
120
121typedef struct
122{
123 BT_OCTET16 sp_c;
124 BT_OCTET16 sp_r;
125 BD_ADDR oob_bdaddr; /* peer bdaddr*/
126} btif_dm_oob_cb_t;
127#define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id))
128
129/* This flag will be true if HCI_Inquiry is in progress */
130static BOOLEAN btif_dm_inquiry_in_progress = FALSE;
131
Matthew Xie1e5109b2012-11-09 18:26:26 -0800132/************************************************************************************
133** Static variables
134************************************************************************************/
135static char btif_default_local_name[DEFAULT_LOCAL_NAME_MAX+1] = {'\0'};
136
The Android Open Source Project5738f832012-12-12 16:00:35 -0800137/******************************************************************************
138** Static functions
139******************************************************************************/
140static btif_dm_pairing_cb_t pairing_cb;
141static btif_dm_oob_cb_t oob_cb;
142static void btif_dm_generic_evt(UINT16 event, char* p_param);
143static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr);
144static void btif_dm_cb_hid_remote_name(tBTM_REMOTE_DEV_NAME *p_remote_name);
145static void btif_update_remote_properties(BD_ADDR bd_addr, BD_NAME bd_name,
146 DEV_CLASS dev_class, tBT_DEVICE_TYPE dev_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800147#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
148static btif_dm_local_key_cb_t ble_local_key_cb;
149static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif);
150static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl);
151static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ *p_pin_req);
152#endif
Matthew Xie1e5109b2012-11-09 18:26:26 -0800153static char* btif_get_default_local_name();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800154/******************************************************************************
155** Externs
156******************************************************************************/
157extern UINT16 bta_service_id_to_uuid_lkup_tbl [BTA_MAX_SERVICE_ID];
158extern bt_status_t btif_hf_execute_service(BOOLEAN b_enable);
159extern bt_status_t btif_av_execute_service(BOOLEAN b_enable);
160extern bt_status_t btif_hh_execute_service(BOOLEAN b_enable);
Hemant Gupta10256872013-08-19 18:33:01 +0530161extern bt_status_t btif_hf_client_execute_service(BOOLEAN b_enable);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800162extern int btif_hh_connect(bt_bdaddr_t *bd_addr);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700163extern void bta_gatt_convert_uuid16_to_uuid128(UINT8 uuid_128[LEN_UUID_128], UINT16 uuid_16);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800164
165
166/******************************************************************************
167** Functions
168******************************************************************************/
169
170bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id,
171 BOOLEAN b_enable)
172{
173 /* Check the service_ID and invoke the profile's BT state changed API */
174 switch (service_id)
175 {
176 case BTA_HFP_SERVICE_ID:
177 case BTA_HSP_SERVICE_ID:
178 {
179 btif_hf_execute_service(b_enable);
180 }break;
181 case BTA_A2DP_SERVICE_ID:
182 {
183 btif_av_execute_service(b_enable);
184 }break;
185 case BTA_HID_SERVICE_ID:
186 {
187 btif_hh_execute_service(b_enable);
188 }break;
Hemant Gupta10256872013-08-19 18:33:01 +0530189 case BTA_HFP_HS_SERVICE_ID:
190 {
191 btif_hf_client_execute_service(b_enable);
192 }break;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800193 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700194 BTIF_TRACE_ERROR("%s: Unknown service being enabled", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800195 return BT_STATUS_FAIL;
196 }
197 return BT_STATUS_SUCCESS;
198}
199
200/*******************************************************************************
201**
202** Function check_eir_remote_name
203**
204** Description Check if remote name is in the EIR data
205**
206** Returns TRUE if remote name found
207** Populate p_remote_name, if provided and remote name found
208**
209*******************************************************************************/
210static BOOLEAN check_eir_remote_name(tBTA_DM_SEARCH *p_search_data,
211 UINT8 *p_remote_name, UINT8 *p_remote_name_len)
212{
213 UINT8 *p_eir_remote_name = NULL;
214 UINT8 remote_name_len = 0;
215
216 /* Check EIR for remote name and services */
217 if (p_search_data->inq_res.p_eir)
218 {
219 p_eir_remote_name = BTA_CheckEirData(p_search_data->inq_res.p_eir,
220 BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, &remote_name_len);
221 if (!p_eir_remote_name)
222 {
223 p_eir_remote_name = BTA_CheckEirData(p_search_data->inq_res.p_eir,
224 BTM_EIR_SHORTENED_LOCAL_NAME_TYPE, &remote_name_len);
225 }
226
227 if (p_eir_remote_name)
228 {
229 if (remote_name_len > BD_NAME_LEN)
230 remote_name_len = BD_NAME_LEN;
231
232 if (p_remote_name && p_remote_name_len)
233 {
234 memcpy(p_remote_name, p_eir_remote_name, remote_name_len);
235 *(p_remote_name + remote_name_len) = 0;
236 *p_remote_name_len = remote_name_len;
237 }
238
239 return TRUE;
240 }
241 }
242
243 return FALSE;
244
245}
246
247/*******************************************************************************
248**
249** Function check_cached_remote_name
250**
251** Description Check if remote name is in the NVRAM cache
252**
253** Returns TRUE if remote name found
254** Populate p_remote_name, if provided and remote name found
255**
256*******************************************************************************/
257static BOOLEAN check_cached_remote_name(tBTA_DM_SEARCH *p_search_data,
258 UINT8 *p_remote_name, UINT8 *p_remote_name_len)
259{
260 bt_bdname_t bdname;
261 bt_bdaddr_t remote_bdaddr;
262 bt_property_t prop_name;
263
264 /* check if we already have it in our btif_storage cache */
265 bdcpy(remote_bdaddr.address, p_search_data->inq_res.bd_addr);
266 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_BDNAME,
267 sizeof(bt_bdname_t), &bdname);
268 if (btif_storage_get_remote_device_property(
269 &remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS)
270 {
271 if (p_remote_name && p_remote_name_len)
272 {
273 strcpy((char *)p_remote_name, (char *)bdname.name);
274 *p_remote_name_len = strlen((char *)p_remote_name);
275 }
276 return TRUE;
277 }
278
279 return FALSE;
280}
281
282BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod)
283{
284 uint32_t remote_cod;
285 bt_property_t prop_name;
286
287 /* check if we already have it in our btif_storage cache */
288 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE,
289 sizeof(uint32_t), &remote_cod);
290 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS)
291 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700292 BTIF_TRACE_ERROR("%s: remote_cod = 0x%06x", __FUNCTION__, remote_cod);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800293 if ((remote_cod & 0x7ff) == cod)
294 return TRUE;
295 }
296
297 return FALSE;
298}
299
Priti Agheraebb1d752012-11-27 18:03:22 -0800300BOOLEAN check_cod_hid(const bt_bdaddr_t *remote_bdaddr, uint32_t cod)
301{
302 uint32_t remote_cod;
303 bt_property_t prop_name;
304
305 /* check if we already have it in our btif_storage cache */
306 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE,
307 sizeof(uint32_t), &remote_cod);
308 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
309 &prop_name) == BT_STATUS_SUCCESS)
310 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700311 BTIF_TRACE_DEBUG("%s: remote_cod = 0x%06x", __FUNCTION__, remote_cod);
Priti Agheraebb1d752012-11-27 18:03:22 -0800312 if ((remote_cod & 0x700) == cod)
313 return TRUE;
314 }
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700315 return FALSE;
316}
Priti Agheraebb1d752012-11-27 18:03:22 -0800317
Andre Eisenbach2e7fa682013-08-08 15:42:48 -0700318BOOLEAN check_hid_le(const bt_bdaddr_t *remote_bdaddr)
319{
320 uint32_t remote_dev_type;
321 bt_property_t prop_name;
322
323 /* check if we already have it in our btif_storage cache */
324 BTIF_STORAGE_FILL_PROPERTY(&prop_name,BT_PROPERTY_TYPE_OF_DEVICE,
325 sizeof(uint32_t), &remote_dev_type);
326 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
327 &prop_name) == BT_STATUS_SUCCESS)
328 {
329 if (remote_dev_type == BT_DEVICE_DEVTYPE_BLE)
330 {
331 bdstr_t bdstr;
332 bd2str(remote_bdaddr, &bdstr);
333 if(btif_config_exist("Remote", bdstr, "HidAppId"))
334 return TRUE;
335 }
336 }
Priti Agheraebb1d752012-11-27 18:03:22 -0800337 return FALSE;
338}
339
The Android Open Source Project5738f832012-12-12 16:00:35 -0800340static void bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr, bt_bond_state_t state)
341{
342 /* Send bonding state only once - based on outgoing/incoming we may receive duplicates */
343 if ( (pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING) )
344 return;
345
346 if (pairing_cb.is_temp)
347 {
348 state = BT_BOND_STATE_NONE;
349 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700350 BTIF_TRACE_DEBUG("%s: state=%d prev_state=%d", __FUNCTION__, state, pairing_cb.state);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800351
352 HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state);
353
354 if (state == BT_BOND_STATE_BONDING)
355 {
356 pairing_cb.state = state;
357 bdcpy(pairing_cb.bd_addr, bd_addr->address);
358 }
359 else
360 {
361 memset(&pairing_cb, 0, sizeof(pairing_cb));
362 }
363
364}
365
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800366/* store remote version in bt config to always have access
367 to it post pairing*/
368static void btif_update_remote_version_property(bt_bdaddr_t *p_bd)
369{
370 bt_property_t property;
371 UINT8 lmp_ver = 0;
372 UINT16 lmp_subver = 0;
373 UINT16 mfct_set = 0;
374 tBTM_STATUS btm_status;
375 bt_remote_version_t info;
376 bt_status_t status;
377 bdstr_t bdstr;
378
379 btm_status = BTM_ReadRemoteVersion(*(BD_ADDR*)p_bd, &lmp_ver,
380 &mfct_set, &lmp_subver);
381
382 ALOGD("remote version info [%s]: %x, %x, %x", bd2str(p_bd, &bdstr),
383 lmp_ver, mfct_set, lmp_subver);
384
385 if (btm_status == BTM_SUCCESS)
386 {
387 /* always update cache to ensure we have availability whenever BTM API
388 is not populated */
389 info.manufacturer = mfct_set;
390 info.sub_ver = lmp_subver;
391 info.version = lmp_ver;
392 BTIF_STORAGE_FILL_PROPERTY(&property,
393 BT_PROPERTY_REMOTE_VERSION_INFO, sizeof(bt_remote_version_t),
394 &info);
395 status = btif_storage_set_remote_device_property(p_bd, &property);
396 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote version", status);
397 }
398}
399
The Android Open Source Project5738f832012-12-12 16:00:35 -0800400
401static void btif_update_remote_properties(BD_ADDR bd_addr, BD_NAME bd_name,
402 DEV_CLASS dev_class, tBT_DEVICE_TYPE device_type)
403{
404 int num_properties = 0;
405 bt_property_t properties[3];
406 bt_bdaddr_t bdaddr;
407 bt_status_t status;
408 UINT32 cod;
409 bt_device_type_t dev_type;
410
411 memset(properties, 0, sizeof(properties));
412 bdcpy(bdaddr.address, bd_addr);
413
414 /* remote name */
415 if (strlen((const char *) bd_name))
416 {
417 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
418 BT_PROPERTY_BDNAME, strlen((char *)bd_name), bd_name);
419 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
420 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device name", status);
421 num_properties++;
422 }
423
424 /* class of device */
425 cod = devclass2uint(dev_class);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700426 BTIF_TRACE_DEBUG("%s():cod is 0x%06x", __FUNCTION__, cod);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800427 if ( cod == 0) {
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530428 /* Try to retrieve cod from storage */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700429 BTIF_TRACE_DEBUG("%s():cod is 0, checking cod from storage", __FUNCTION__);
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530430 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
431 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
432 status = btif_storage_get_remote_device_property(&bdaddr, &properties[num_properties]);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700433 BTIF_TRACE_DEBUG("%s():cod retreived from storage is 0x%06x", __FUNCTION__, cod);
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530434 if ( cod == 0) {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700435 BTIF_TRACE_DEBUG("%s():cod is again 0, set as unclassified", __FUNCTION__);
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530436 cod = COD_UNCLASSIFIED;
437 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800438 }
439
440 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
441 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
442 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
443 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device class", status);
444 num_properties++;
445
446 /* device type */
447 dev_type = device_type;
448 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
449 BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
450 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
451 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device type", status);
452 num_properties++;
453
454 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
455 status, &bdaddr, num_properties, properties);
456}
The Android Open Source Project5738f832012-12-12 16:00:35 -0800457
458/*******************************************************************************
459**
460** Function btif_dm_cb_hid_remote_name
461**
462** Description Remote name callback for HID device. Called in btif context
463** Special handling for HID devices
464**
465** Returns void
466**
467*******************************************************************************/
468static void btif_dm_cb_hid_remote_name(tBTM_REMOTE_DEV_NAME *p_remote_name)
469{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700470 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 -0800471 if (pairing_cb.state == BT_BOND_STATE_BONDING)
472 {
473 bt_bdaddr_t remote_bd;
474
475 bdcpy(remote_bd.address, pairing_cb.bd_addr);
476
477 if (p_remote_name->status == BTM_SUCCESS)
478 {
479 bond_state_changed(BT_STATUS_SUCCESS, &remote_bd, BT_BOND_STATE_BONDED);
480 }
481 else
482 bond_state_changed(BT_STATUS_FAIL, &remote_bd, BT_BOND_STATE_NONE);
483 }
484}
485
The Android Open Source Project5738f832012-12-12 16:00:35 -0800486/*******************************************************************************
487**
488** Function btif_dm_cb_create_bond
489**
490** Description Create bond initiated from the BTIF thread context
491** Special handling for HID devices
492**
493** Returns void
494**
495*******************************************************************************/
496static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr)
497{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800498 BOOLEAN is_hid = check_cod(bd_addr, COD_HID_POINTING);
499
500
The Android Open Source Project5738f832012-12-12 16:00:35 -0800501 bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800502
503 if (is_hid){
504
The Android Open Source Project5738f832012-12-12 16:00:35 -0800505 int status;
506 status = btif_hh_connect(bd_addr);
507 if(status != BT_STATUS_SUCCESS)
508 bond_state_changed(status, bd_addr, BT_BOND_STATE_NONE);
509 }
510 else
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800511 {
Matthew Xiefc4b2f12013-05-06 20:51:02 -0700512#if BLE_INCLUDED == TRUE
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800513 int device_type;
514 int addr_type;
515 bdstr_t bdstr;
516 bd2str(bd_addr, &bdstr);
517 if(btif_config_get_int("Remote", (char const *)&bdstr,"DevType", &device_type) &&
518 (btif_storage_get_remote_addr_type(bd_addr, &addr_type) == BT_STATUS_SUCCESS) &&
519 (device_type == BT_DEVICE_TYPE_BLE))
520 {
521 BTA_DmAddBleDevice(bd_addr->address, addr_type, BT_DEVICE_TYPE_BLE);
522 }
Matthew Xiefc4b2f12013-05-06 20:51:02 -0700523#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800524 BTA_DmBond ((UINT8 *)bd_addr->address);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800525 }
526 /* Track originator of bond creation */
527 pairing_cb.is_local_initiated = TRUE;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800528
529}
530
531/*******************************************************************************
532**
533** Function btif_dm_cb_remove_bond
534**
535** Description remove bond initiated from the BTIF thread context
536** Special handling for HID devices
537**
538** Returns void
539**
540*******************************************************************************/
541void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr)
542{
543 bdstr_t bdstr;
544 /*special handling for HID devices */
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -0700545 /* VUP needs to be sent if its a HID Device. The HID HOST module will check if there
546 is a valid hid connection with this bd_addr. If yes VUP will be issued.*/
547#if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
548 if (btif_hh_virtual_unplug(bd_addr) != BT_STATUS_SUCCESS)
549#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800550 {
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -0700551 BTA_DmRemoveDevice((UINT8 *)bd_addr->address);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800552 }
553}
554
555/*******************************************************************************
556**
Andre Eisenbach249f6002014-06-18 12:20:37 -0700557** Function btif_dm_get_connection_state
558**
559** Description Returns whether the remote device is currently connected
560**
561** Returns 0 if not connected
562**
563*******************************************************************************/
564uint16_t btif_dm_get_connection_state(const bt_bdaddr_t *bd_addr)
565{
566 return BTA_DmGetConnectionState((UINT8 *)bd_addr->address);
567}
568
569/*******************************************************************************
570**
The Android Open Source Project5738f832012-12-12 16:00:35 -0800571** Function search_devices_copy_cb
572**
573** Description Deep copy callback for search devices event
574**
575** Returns void
576**
577*******************************************************************************/
578static void search_devices_copy_cb(UINT16 event, char *p_dest, char *p_src)
579{
580 tBTA_DM_SEARCH *p_dest_data = (tBTA_DM_SEARCH *) p_dest;
581 tBTA_DM_SEARCH *p_src_data = (tBTA_DM_SEARCH *) p_src;
582
583 if (!p_src)
584 return;
585
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700586 BTIF_TRACE_DEBUG("%s: event=%s", __FUNCTION__, dump_dm_search_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800587 memcpy(p_dest_data, p_src_data, sizeof(tBTA_DM_SEARCH));
588 switch (event)
589 {
590 case BTA_DM_INQ_RES_EVT:
591 {
592 if (p_src_data->inq_res.p_eir)
593 {
594 p_dest_data->inq_res.p_eir = (UINT8 *)(p_dest + sizeof(tBTA_DM_SEARCH));
595 memcpy(p_dest_data->inq_res.p_eir, p_src_data->inq_res.p_eir, HCI_EXT_INQ_RESPONSE_LEN);
596 }
597 }
598 break;
599
600 case BTA_DM_DISC_RES_EVT:
601 {
602 if (p_src_data->disc_res.raw_data_size && p_src_data->disc_res.p_raw_data)
603 {
604 p_dest_data->disc_res.p_raw_data = (UINT8 *)(p_dest + sizeof(tBTA_DM_SEARCH));
605 memcpy(p_dest_data->disc_res.p_raw_data,
606 p_src_data->disc_res.p_raw_data, p_src_data->disc_res.raw_data_size);
607 }
608 }
609 break;
610 }
611}
612
613static void search_services_copy_cb(UINT16 event, char *p_dest, char *p_src)
614{
615 tBTA_DM_SEARCH *p_dest_data = (tBTA_DM_SEARCH *) p_dest;
616 tBTA_DM_SEARCH *p_src_data = (tBTA_DM_SEARCH *) p_src;
617
618 if (!p_src)
619 return;
620 memcpy(p_dest_data, p_src_data, sizeof(tBTA_DM_SEARCH));
621 switch (event)
622 {
623 case BTA_DM_DISC_RES_EVT:
624 {
Kausik Sinnaswamy95664a92013-05-03 15:02:50 +0530625 if (p_src_data->disc_res.result == BTA_SUCCESS)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800626 {
Kausik Sinnaswamy95664a92013-05-03 15:02:50 +0530627 if (p_src_data->disc_res.num_uuids > 0)
628 {
629 p_dest_data->disc_res.p_uuid_list =
630 (UINT8*)(p_dest + sizeof(tBTA_DM_SEARCH));
631 memcpy(p_dest_data->disc_res.p_uuid_list, p_src_data->disc_res.p_uuid_list,
632 p_src_data->disc_res.num_uuids*MAX_UUID_SIZE);
633 GKI_freebuf(p_src_data->disc_res.p_uuid_list);
634 }
635 if (p_src_data->disc_res.p_raw_data != NULL)
636 {
637 GKI_freebuf(p_src_data->disc_res.p_raw_data);
638 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800639 }
640 } break;
641 }
642}
643/******************************************************************************
644**
645** BTIF DM callback events
646**
647*****************************************************************************/
648
649/*******************************************************************************
650**
651** Function btif_dm_pin_req_evt
652**
653** Description Executes pin request event in btif context
654**
655** Returns void
656**
657*******************************************************************************/
658static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
659{
660 bt_bdaddr_t bd_addr;
661 bt_bdname_t bd_name;
662 UINT32 cod;
663 bt_pin_code_t pin_code;
664
665 /* Remote properties update */
666 btif_update_remote_properties(p_pin_req->bd_addr, p_pin_req->bd_name,
667 p_pin_req->dev_class, BT_DEVICE_TYPE_BREDR);
668
669 bdcpy(bd_addr.address, p_pin_req->bd_addr);
670 memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN);
671
672 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
673
674 cod = devclass2uint(p_pin_req->dev_class);
675
676 if ( cod == 0) {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700677 BTIF_TRACE_DEBUG("%s():cod is 0, set as unclassified", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800678 cod = COD_UNCLASSIFIED;
679 }
680
681 /* check for auto pair possiblity only if bond was initiated by local device */
682 if (pairing_cb.is_local_initiated)
683 {
684 if (check_cod(&bd_addr, COD_AV_HEADSETS) ||
685 check_cod(&bd_addr, COD_AV_HANDSFREE) ||
686 check_cod(&bd_addr, COD_AV_HEADPHONES) ||
687 check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) ||
688 check_cod(&bd_addr, COD_AV_HIFI_AUDIO) ||
689 check_cod(&bd_addr, COD_HID_POINTING))
690 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700691 BTIF_TRACE_DEBUG("%s()cod matches for auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800692 /* Check if this device can be auto paired */
693 if ((btif_storage_is_device_autopair_blacklisted(&bd_addr) == FALSE) &&
694 (pairing_cb.autopair_attempts == 0))
695 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700696 BTIF_TRACE_DEBUG("%s() Attempting auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800697 pin_code.pin[0] = 0x30;
698 pin_code.pin[1] = 0x30;
699 pin_code.pin[2] = 0x30;
700 pin_code.pin[3] = 0x30;
701
702 pairing_cb.autopair_attempts++;
703 BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin);
704 return;
705 }
706 }
707 else if (check_cod(&bd_addr, COD_HID_KEYBOARD) ||
708 check_cod(&bd_addr, COD_HID_COMBO))
709 {
710 if(( btif_storage_is_fixed_pin_zeros_keyboard (&bd_addr) == TRUE) &&
711 (pairing_cb.autopair_attempts == 0))
712 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700713 BTIF_TRACE_DEBUG("%s() Attempting auto pair", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800714 pin_code.pin[0] = 0x30;
715 pin_code.pin[1] = 0x30;
716 pin_code.pin[2] = 0x30;
717 pin_code.pin[3] = 0x30;
718
719 pairing_cb.autopair_attempts++;
720 BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin);
721 return;
722 }
723 }
724 }
725 HAL_CBACK(bt_hal_cbacks, pin_request_cb,
726 &bd_addr, &bd_name, cod);
727}
728
729/*******************************************************************************
730**
731** Function btif_dm_ssp_cfm_req_evt
732**
733** Description Executes SSP confirm request event in btif context
734**
735** Returns void
736**
737*******************************************************************************/
738static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ *p_ssp_cfm_req)
739{
740 bt_bdaddr_t bd_addr;
741 bt_bdname_t bd_name;
742 UINT32 cod;
743 BOOLEAN is_incoming = !(pairing_cb.state == BT_BOND_STATE_BONDING);
744
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700745 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800746
747 /* Remote properties update */
748 btif_update_remote_properties(p_ssp_cfm_req->bd_addr, p_ssp_cfm_req->bd_name,
749 p_ssp_cfm_req->dev_class, BT_DEVICE_TYPE_BREDR);
750
751 bdcpy(bd_addr.address, p_ssp_cfm_req->bd_addr);
752 memcpy(bd_name.name, p_ssp_cfm_req->bd_name, BD_NAME_LEN);
753
754 /* Set the pairing_cb based on the local & remote authentication requirements */
755 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
756
757 /* if just_works and bonding bit is not set treat this as temporary */
758 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 -0800759 !(p_ssp_cfm_req->rmt_auth_req & BTM_AUTH_BONDS) &&
760 !(check_cod((bt_bdaddr_t*)&p_ssp_cfm_req->bd_addr, COD_HID_POINTING)))
The Android Open Source Project5738f832012-12-12 16:00:35 -0800761 pairing_cb.is_temp = TRUE;
762 else
763 pairing_cb.is_temp = FALSE;
764
765 pairing_cb.is_ssp = TRUE;
766
767 /* If JustWorks auto-accept */
768 if (p_ssp_cfm_req->just_works)
769 {
770 /* Pairing consent for JustWorks needed if:
771 * 1. Incoming pairing is detected AND
772 * 2. local IO capabilities are DisplayYesNo AND
773 * 3. remote IO capabiltiies are DisplayOnly or NoInputNoOutput;
774 */
775 if ((is_incoming) && ((p_ssp_cfm_req->loc_io_caps == 0x01) &&
776 (p_ssp_cfm_req->rmt_io_caps == 0x00 || p_ssp_cfm_req->rmt_io_caps == 0x03)))
777 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700778 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 -0800779 __FUNCTION__, p_ssp_cfm_req->loc_io_caps, p_ssp_cfm_req->rmt_io_caps);
780 }
781 else
782 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700783 BTIF_TRACE_EVENT("%s: Auto-accept JustWorks pairing", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800784 btif_dm_ssp_reply(&bd_addr, BT_SSP_VARIANT_CONSENT, TRUE, 0);
785 return;
786 }
787 }
788
789 cod = devclass2uint(p_ssp_cfm_req->dev_class);
790
791 if ( cod == 0) {
792 ALOGD("cod is 0, set as unclassified");
793 cod = COD_UNCLASSIFIED;
794 }
795
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -0700796 pairing_cb.sdp_attempts = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800797 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod,
798 (p_ssp_cfm_req->just_works ? BT_SSP_VARIANT_CONSENT : BT_SSP_VARIANT_PASSKEY_CONFIRMATION),
799 p_ssp_cfm_req->num_val);
800}
801
802static void btif_dm_ssp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif)
803{
804 bt_bdaddr_t bd_addr;
805 bt_bdname_t bd_name;
806 UINT32 cod;
807
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700808 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800809
810 /* Remote properties update */
811 btif_update_remote_properties(p_ssp_key_notif->bd_addr, p_ssp_key_notif->bd_name,
812 p_ssp_key_notif->dev_class, BT_DEVICE_TYPE_BREDR);
813
814 bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
815 memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
816
817 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
818 pairing_cb.is_ssp = TRUE;
819 cod = devclass2uint(p_ssp_key_notif->dev_class);
820
821 if ( cod == 0) {
822 ALOGD("cod is 0, set as unclassified");
823 cod = COD_UNCLASSIFIED;
824 }
825
826 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
827 cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION,
828 p_ssp_key_notif->passkey);
829}
830/*******************************************************************************
831**
832** Function btif_dm_auth_cmpl_evt
833**
834** Description Executes authentication complete event in btif context
835**
836** Returns void
837**
838*******************************************************************************/
839static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
840{
841 /* Save link key, if not temporary */
842 bt_bdaddr_t bd_addr;
843 bt_status_t status = BT_STATUS_FAIL;
844 bt_bond_state_t state = BT_BOND_STATE_NONE;
845
846 bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
847 if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
848 {
849 if ((p_auth_cmpl->key_type < HCI_LKEY_TYPE_DEBUG_COMB) || (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB) ||
850 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_CHANGED_COMB) || (!pairing_cb.is_temp))
851 {
852 bt_status_t ret;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700853 BTIF_TRACE_DEBUG("%s: Storing link key. key_type=0x%x, is_temp=%d",
The Android Open Source Project5738f832012-12-12 16:00:35 -0800854 __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.is_temp);
855 ret = btif_storage_add_bonded_device(&bd_addr,
856 p_auth_cmpl->key, p_auth_cmpl->key_type,
857 pairing_cb.pin_code_len);
858 ASSERTC(ret == BT_STATUS_SUCCESS, "storing link key failed", ret);
859 }
860 else
861 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700862 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 -0800863 __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.is_temp);
Hemant Guptab820aec2013-12-24 19:59:57 +0530864 if(pairing_cb.is_temp)
865 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700866 BTIF_TRACE_DEBUG("%s: sending BT_BOND_STATE_NONE for Temp pairing",
Hemant Guptab820aec2013-12-24 19:59:57 +0530867 __FUNCTION__);
868 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
869 return;
870 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800871 }
872 }
873 if (p_auth_cmpl->success)
874 {
875 status = BT_STATUS_SUCCESS;
876 state = BT_BOND_STATE_BONDED;
877
878 /* Trigger SDP on the device */
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -0700879 pairing_cb.sdp_attempts = 1;;
Ganesh Ganapathi Battae17bf002013-02-15 17:52:29 -0800880
881 if(btif_dm_inquiry_in_progress)
882 btif_dm_cancel_discovery();
883
The Android Open Source Project5738f832012-12-12 16:00:35 -0800884 btif_dm_get_remote_services(&bd_addr);
885 /* Do not call bond_state_changed_cb yet. Wait till fetch remote service is complete */
886 }
887 else
888 {
889 /*Map the HCI fail reason to bt status */
890 switch(p_auth_cmpl->fail_reason)
891 {
892 case HCI_ERR_PAGE_TIMEOUT:
893 case HCI_ERR_CONNECTION_TOUT:
894 status = BT_STATUS_RMT_DEV_DOWN;
895 break;
896
Hemant Guptaaef7a672013-07-31 19:00:12 +0530897 case HCI_ERR_PAIRING_NOT_ALLOWED:
898 status = BT_STATUS_AUTH_REJECTED;
899 break;
900
Hemant Guptab4801442014-01-07 18:11:15 +0530901 case HCI_ERR_LMP_RESPONSE_TIMEOUT:
902 status = BT_STATUS_AUTH_FAILURE;
903 break;
904
The Android Open Source Project5738f832012-12-12 16:00:35 -0800905 /* map the auth failure codes, so we can retry pairing if necessary */
906 case HCI_ERR_AUTH_FAILURE:
Hemant Gupta59a88ec2014-03-19 19:01:35 +0530907 case HCI_ERR_KEY_MISSING:
Zhihai Xua7ea8092013-11-27 14:10:53 +0530908 btif_storage_remove_bonded_device(&bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800909 case HCI_ERR_HOST_REJECT_SECURITY:
910 case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE:
911 case HCI_ERR_UNIT_KEY_USED:
912 case HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED:
913 case HCI_ERR_INSUFFCIENT_SECURITY:
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530914 case HCI_ERR_PEER_USER:
915 case HCI_ERR_UNSPECIFIED:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700916 BTIF_TRACE_DEBUG(" %s() Authentication fail reason %d",
Hemant Gupta87b7cce2013-11-28 13:07:10 +0530917 __FUNCTION__, p_auth_cmpl->fail_reason);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800918 if (pairing_cb.autopair_attempts == 1)
919 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700920 BTIF_TRACE_DEBUG("%s(): Adding device to blacklist ", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800921
922 /* Add the device to dynamic black list only if this device belongs to Audio/pointing dev class */
923 if (check_cod(&bd_addr, COD_AV_HEADSETS) ||
924 check_cod(&bd_addr, COD_AV_HANDSFREE) ||
925 check_cod(&bd_addr, COD_AV_HEADPHONES) ||
926 check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) ||
927 check_cod(&bd_addr, COD_AV_HIFI_AUDIO) ||
928 check_cod(&bd_addr, COD_HID_POINTING))
929 {
930 btif_storage_add_device_to_autopair_blacklist (&bd_addr);
931 }
932 pairing_cb.autopair_attempts++;
933
934 /* Create the Bond once again */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700935 BTIF_TRACE_DEBUG("%s() auto pair failed. Reinitiate Bond", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800936 btif_dm_cb_create_bond (&bd_addr);
937 return;
938 }
939 else
940 {
941 /* if autopair attempts are more than 1, or not attempted */
942 status = BT_STATUS_AUTH_FAILURE;
943 }
944 break;
945
946 default:
947 status = BT_STATUS_FAIL;
948 }
Zhihai Xu8d2128d2013-12-13 16:09:21 +0530949 /* Special Handling for HID Devices */
950 if (check_cod(&bd_addr, COD_HID_POINTING)) {
951 /* Remove Device as bonded in nvram as authentication failed */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700952 BTIF_TRACE_DEBUG("%s(): removing hid pointing device from nvram", __FUNCTION__);
Zhihai Xu8d2128d2013-12-13 16:09:21 +0530953 btif_storage_remove_bonded_device(&bd_addr);
954 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800955 bond_state_changed(status, &bd_addr, state);
956 }
957}
958
959/******************************************************************************
960**
961** Function btif_dm_search_devices_evt
962**
963** Description Executes search devices callback events in btif context
964**
965** Returns void
966**
967******************************************************************************/
968static void btif_dm_search_devices_evt (UINT16 event, char *p_param)
969{
970 tBTA_DM_SEARCH *p_search_data;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -0700971 BTIF_TRACE_EVENT("%s event=%s", __FUNCTION__, dump_dm_search_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -0800972
973 switch (event)
974 {
975 case BTA_DM_DISC_RES_EVT:
976 {
977 p_search_data = (tBTA_DM_SEARCH *)p_param;
978 /* Remote name update */
979 if (strlen((const char *) p_search_data->disc_res.bd_name))
980 {
981 bt_property_t properties[1];
982 bt_bdaddr_t bdaddr;
983 bt_status_t status;
984
985 properties[0].type = BT_PROPERTY_BDNAME;
986 properties[0].val = p_search_data->disc_res.bd_name;
987 properties[0].len = strlen((char *)p_search_data->disc_res.bd_name);
988 bdcpy(bdaddr.address, p_search_data->disc_res.bd_addr);
989
990 status = btif_storage_set_remote_device_property(&bdaddr, &properties[0]);
991 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device property", status);
992 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
993 status, &bdaddr, 1, properties);
994 }
995 /* TODO: Services? */
996 }
997 break;
998
999 case BTA_DM_INQ_RES_EVT:
1000 {
1001 /* inquiry result */
1002 UINT32 cod;
1003 UINT8 *p_eir_remote_name = NULL;
1004 bt_bdname_t bdname;
1005 bt_bdaddr_t bdaddr;
1006 UINT8 remote_name_len;
1007 UINT8 *p_cached_name = NULL;
1008 tBTA_SERVICE_MASK services = 0;
1009 bdstr_t bdstr;
1010
1011 p_search_data = (tBTA_DM_SEARCH *)p_param;
1012 bdcpy(bdaddr.address, p_search_data->inq_res.bd_addr);
1013
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001014 BTIF_TRACE_DEBUG("%s() %s device_type = 0x%x\n", __FUNCTION__, bd2str(&bdaddr, &bdstr),
The Android Open Source Project5738f832012-12-12 16:00:35 -08001015#if (BLE_INCLUDED == TRUE)
1016 p_search_data->inq_res.device_type);
1017#else
1018 BT_DEVICE_TYPE_BREDR);
1019#endif
1020 bdname.name[0] = 0;
1021
1022 cod = devclass2uint (p_search_data->inq_res.dev_class);
1023
1024 if ( cod == 0) {
1025 ALOGD("cod is 0, set as unclassified");
1026 cod = COD_UNCLASSIFIED;
1027 }
1028
1029 if (!check_eir_remote_name(p_search_data, bdname.name, &remote_name_len))
1030 check_cached_remote_name(p_search_data, bdname.name, &remote_name_len);
1031
1032 /* Check EIR for remote name and services */
1033 if (p_search_data->inq_res.p_eir)
1034 {
1035 BTA_GetEirService(p_search_data->inq_res.p_eir, &services);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001036 BTIF_TRACE_DEBUG("%s()EIR BTA services = %08X", __FUNCTION__, (UINT32)services);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001037 /* TODO: Get the service list and check to see which uuids we got and send it back to the client. */
1038 }
1039
1040
1041 {
1042 bt_property_t properties[5];
1043 bt_device_type_t dev_type;
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001044 UINT8 addr_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001045 uint32_t num_properties = 0;
1046 bt_status_t status;
1047
1048 memset(properties, 0, sizeof(properties));
1049 /* BD_ADDR */
1050 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1051 BT_PROPERTY_BDADDR, sizeof(bdaddr), &bdaddr);
1052 num_properties++;
1053 /* BD_NAME */
1054 /* Don't send BDNAME if it is empty */
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001055 if (bdname.name[0])
1056 {
The Android Open Source Project5738f832012-12-12 16:00:35 -08001057 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1058 BT_PROPERTY_BDNAME,
1059 strlen((char *)bdname.name), &bdname);
1060 num_properties++;
1061 }
1062
1063 /* DEV_CLASS */
1064 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1065 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
1066 num_properties++;
1067 /* DEV_TYPE */
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001068#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001069 /* FixMe: Assumption is that bluetooth.h and BTE enums match */
1070 dev_type = p_search_data->inq_res.device_type;
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001071 addr_type = p_search_data->inq_res.ble_addr_type;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001072#else
1073 dev_type = BT_DEVICE_TYPE_BREDR;
1074#endif
1075 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1076 BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
1077 num_properties++;
1078 /* RSSI */
1079 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1080 BT_PROPERTY_REMOTE_RSSI, sizeof(int8_t),
1081 &(p_search_data->inq_res.rssi));
1082 num_properties++;
1083
1084 status = btif_storage_add_remote_device(&bdaddr, num_properties, properties);
1085 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device (inquiry)", status);
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001086#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1087 status = btif_storage_set_remote_addr_type(&bdaddr, addr_type);
Ganesh Ganapathi Batta8fe58872014-04-16 16:50:09 -07001088 if (( dev_type == BT_DEVICE_TYPE_DUMO)&&
1089 (p_search_data->inq_res.flag & BTA_BLE_DMT_CONTROLLER_SPT) &&
1090 (p_search_data->inq_res.flag & BTA_BLE_DMT_HOST_SPT))
1091 {
1092 btif_storage_set_dmt_support_type (&bdaddr, TRUE);
1093 }
Andre Eisenbach5c44e452013-08-06 18:19:37 -07001094 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote addr type (inquiry)", status);
1095#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001096 /* Callback to notify upper layer of device */
1097 HAL_CBACK(bt_hal_cbacks, device_found_cb,
1098 num_properties, properties);
1099 }
1100 }
1101 break;
1102
1103 case BTA_DM_INQ_CMPL_EVT:
1104 {
1105 }
1106 break;
1107 case BTA_DM_DISC_CMPL_EVT:
1108 {
1109 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED);
1110 }
1111 break;
1112 case BTA_DM_SEARCH_CANCEL_CMPL_EVT:
1113 {
1114 /* if inquiry is not in progress and we get a cancel event, then
1115 * it means we are done with inquiry, but remote_name fetches are in
1116 * progress
1117 *
1118 * if inquiry is in progress, then we don't want to act on this cancel_cmpl_evt
1119 * but instead wait for the cancel_cmpl_evt via the Busy Level
1120 *
1121 */
1122 if (btif_dm_inquiry_in_progress == FALSE)
1123 {
1124 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED);
1125 }
1126 }
1127 break;
1128 }
1129}
1130
1131/*******************************************************************************
1132**
1133** Function btif_dm_search_services_evt
1134**
1135** Description Executes search services event in btif context
1136**
1137** Returns void
1138**
1139*******************************************************************************/
1140static void btif_dm_search_services_evt(UINT16 event, char *p_param)
1141{
1142 tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param;
1143
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001144 BTIF_TRACE_EVENT("%s: event = %d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001145 switch (event)
1146 {
1147 case BTA_DM_DISC_RES_EVT:
1148 {
1149 bt_uuid_t uuid_arr[BT_MAX_NUM_UUIDS]; /* Max 32 services */
1150 bt_property_t prop;
1151 uint32_t i = 0, j = 0;
1152 bt_bdaddr_t bd_addr;
1153 bt_status_t ret;
1154
1155 bdcpy(bd_addr.address, p_data->disc_res.bd_addr);
1156
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001157 BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001158 p_data->disc_res.result, p_data->disc_res.services);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001159 if ((p_data->disc_res.result != BTA_SUCCESS) &&
1160 (pairing_cb.state == BT_BOND_STATE_BONDING ) &&
1161 (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING))
1162 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001163 BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", __FUNCTION__);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001164 pairing_cb.sdp_attempts++;
1165 btif_dm_get_remote_services(&bd_addr);
1166 return;
1167 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001168 prop.type = BT_PROPERTY_UUIDS;
1169 prop.len = 0;
1170 if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0))
1171 {
1172 prop.val = p_data->disc_res.p_uuid_list;
1173 prop.len = p_data->disc_res.num_uuids * MAX_UUID_SIZE;
1174 for (i=0; i < p_data->disc_res.num_uuids; i++)
1175 {
1176 char temp[256];
1177 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 -07001178 BTIF_TRACE_ERROR("Index: %d uuid:%s", i, temp);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001179 }
1180 }
1181
1182 /* onUuidChanged requires getBondedDevices to be populated.
1183 ** bond_state_changed needs to be sent prior to remote_device_property
1184 */
1185 if ((pairing_cb.state == BT_BOND_STATE_BONDING) &&
1186 (bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0)&&
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001187 pairing_cb.sdp_attempts > 0)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001188 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001189 BTIF_TRACE_DEBUG("%s Remote Service SDP done. Call bond_state_changed_cb BONDED",
The Android Open Source Project5738f832012-12-12 16:00:35 -08001190 __FUNCTION__);
Ganesh Ganapathi Battaec7e2c82013-06-20 11:00:28 -07001191 pairing_cb.sdp_attempts = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001192 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED);
1193 }
1194
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001195 if(p_data->disc_res.num_uuids != 0)
1196 {
1197 /* Also write this to the NVRAM */
1198 ret = btif_storage_set_remote_device_property(&bd_addr, &prop);
1199 ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);
1200 /* Send the event to the BTIF */
1201 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1202 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1203 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001204 }
1205 break;
1206
1207 case BTA_DM_DISC_CMPL_EVT:
1208 /* fixme */
1209 break;
1210
Matthew Xie607e3b72013-08-15 19:30:48 -07001211#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001212 case BTA_DM_DISC_BLE_RES_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001213 BTIF_TRACE_DEBUG("%s:, services 0x%x)", __FUNCTION__,
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001214 p_data->disc_ble_res.service.uu.uuid16);
1215 bt_uuid_t uuid;
1216 int i = 0;
1217 int j = 15;
1218 if (p_data->disc_ble_res.service.uu.uuid16 == UUID_SERVCLASS_LE_HID)
1219 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001220 BTIF_TRACE_DEBUG("%s: Found HOGP UUID",__FUNCTION__);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001221 bt_property_t prop;
1222 bt_bdaddr_t bd_addr;
1223 char temp[256];
Zhihai Xud7ee77b2013-11-05 18:06:54 -08001224 bt_status_t ret;
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001225
1226 bta_gatt_convert_uuid16_to_uuid128(uuid.uu,p_data->disc_ble_res.service.uu.uuid16);
1227
1228 while(i < j )
1229 {
1230 unsigned char c = uuid.uu[j];
1231 uuid.uu[j] = uuid.uu[i];
1232 uuid.uu[i] = c;
1233 i++;
1234 j--;
1235 }
1236
1237 uuid_to_string(&uuid, temp);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001238 BTIF_TRACE_ERROR(" uuid:%s", temp);
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001239
1240 bdcpy(bd_addr.address, p_data->disc_ble_res.bd_addr);
1241 prop.type = BT_PROPERTY_UUIDS;
1242 prop.val = uuid.uu;
1243 prop.len = MAX_UUID_SIZE;
1244
Zhihai Xud7ee77b2013-11-05 18:06:54 -08001245 /* Also write this to the NVRAM */
1246 ret = btif_storage_set_remote_device_property(&bd_addr, &prop);
1247 ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);
1248
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001249 /* Send the event to the BTIF */
1250 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1251 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1252
1253 }
1254 break;
Matthew Xie607e3b72013-08-15 19:30:48 -07001255#endif /* BLE_INCLUDED */
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001256
The Android Open Source Project5738f832012-12-12 16:00:35 -08001257 default:
1258 {
1259 ASSERTC(0, "unhandled search services event", event);
1260 }
1261 break;
1262 }
1263}
1264
1265/*******************************************************************************
1266**
1267** Function btif_dm_remote_service_record_evt
1268**
1269** Description Executes search service record event in btif context
1270**
1271** Returns void
1272**
1273*******************************************************************************/
1274static void btif_dm_remote_service_record_evt(UINT16 event, char *p_param)
1275{
1276 tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param;
1277
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001278 BTIF_TRACE_EVENT("%s: event = %d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001279 switch (event)
1280 {
1281 case BTA_DM_DISC_RES_EVT:
1282 {
1283 bt_service_record_t rec;
1284 bt_property_t prop;
1285 uint32_t i = 0;
1286 bt_bdaddr_t bd_addr;
1287
1288 memset(&rec, 0, sizeof(bt_service_record_t));
1289 bdcpy(bd_addr.address, p_data->disc_res.bd_addr);
1290
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001291 BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__,
The Android Open Source Project5738f832012-12-12 16:00:35 -08001292 p_data->disc_res.result, p_data->disc_res.services);
1293 prop.type = BT_PROPERTY_SERVICE_RECORD;
1294 prop.val = (void*)&rec;
1295 prop.len = sizeof(rec);
1296
1297 /* disc_res.result is overloaded with SCN. Cannot check result */
1298 p_data->disc_res.services &= ~BTA_USER_SERVICE_MASK;
1299 /* TODO: Get the UUID as well */
1300 rec.channel = p_data->disc_res.result - 3;
1301 /* TODO: Need to get the service name using p_raw_data */
1302 rec.name[0] = 0;
1303
1304 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1305 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1306 }
1307 break;
1308
1309 default:
1310 {
1311 ASSERTC(0, "unhandled remote service record event", event);
1312 }
1313 break;
1314 }
1315}
1316
1317/*******************************************************************************
1318**
1319** Function btif_dm_upstreams_cback
1320**
1321** Description Executes UPSTREAMS events in btif context
1322**
1323** Returns void
1324**
1325*******************************************************************************/
1326static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
1327{
1328 tBTA_DM_SEC_EVT dm_event = (tBTA_DM_SEC_EVT)event;
1329 tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)p_param;
1330 tBTA_SERVICE_MASK service_mask;
1331 uint32_t i;
1332 bt_bdaddr_t bd_addr;
1333
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001334 BTIF_TRACE_EVENT("btif_dm_upstreams_cback ev: %s", dump_dm_event(event));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001335
1336 switch (event)
1337 {
1338 case BTA_DM_ENABLE_EVT:
1339 {
1340 BD_NAME bdname;
1341 bt_status_t status;
1342 bt_property_t prop;
1343 prop.type = BT_PROPERTY_BDNAME;
1344 prop.len = BD_NAME_LEN;
1345 prop.val = (void*)bdname;
1346
1347 status = btif_storage_get_adapter_property(&prop);
Matthew Xie1e5109b2012-11-09 18:26:26 -08001348 if (status == BT_STATUS_SUCCESS)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001349 {
1350 /* A name exists in the storage. Make this the device name */
1351 BTA_DmSetDeviceName((char*)prop.val);
1352 }
Matthew Xie1e5109b2012-11-09 18:26:26 -08001353 else
1354 {
1355 /* Storage does not have a name yet.
1356 * Use the default name and write it to the chip
1357 */
1358 BTA_DmSetDeviceName(btif_get_default_local_name());
1359 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001360
1361 /* for each of the enabled services in the mask, trigger the profile
1362 * enable */
1363 service_mask = btif_get_enabled_services_mask();
1364 for (i=0; i <= BTA_MAX_SERVICE_ID; i++)
1365 {
1366 if (service_mask &
1367 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i)))
1368 {
1369 btif_in_execute_service_request(i, TRUE);
1370 }
1371 }
1372 /* clear control blocks */
1373 memset(&pairing_cb, 0, sizeof(btif_dm_pairing_cb_t));
1374
1375 /* This function will also trigger the adapter_properties_cb
1376 ** and bonded_devices_info_cb
1377 */
1378 btif_storage_load_bonded_devices();
1379
1380 btif_storage_load_autopair_device_list();
1381
1382 btif_enable_bluetooth_evt(p_data->enable.status, p_data->enable.bd_addr);
Satya Calloji0943c102014-05-12 09:13:02 -07001383
Wei Wangbf0e4b22014-05-19 23:23:35 -07001384 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
Satya Calloji0943c102014-05-12 09:13:02 -07001385 /* Enable local privacy */
Ganesh Ganapathi Batta9546abf2014-05-30 16:28:00 -07001386 /*TODO Should this call be exposed to JAVA...? */
Satya Calloji0943c102014-05-12 09:13:02 -07001387 BTA_DmBleConfigLocalPrivacy(TRUE);
Wei Wangbf0e4b22014-05-19 23:23:35 -07001388 #endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001389 }
1390 break;
1391
1392 case BTA_DM_DISABLE_EVT:
1393 /* for each of the enabled services in the mask, trigger the profile
1394 * disable */
1395 service_mask = btif_get_enabled_services_mask();
1396 for (i=0; i <= BTA_MAX_SERVICE_ID; i++)
1397 {
1398 if (service_mask &
1399 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i)))
1400 {
1401 btif_in_execute_service_request(i, FALSE);
1402 }
1403 }
1404 btif_disable_bluetooth_evt();
1405 break;
1406
1407 case BTA_DM_PIN_REQ_EVT:
1408 btif_dm_pin_req_evt(&p_data->pin_req);
1409 break;
1410
1411 case BTA_DM_AUTH_CMPL_EVT:
1412 btif_dm_auth_cmpl_evt(&p_data->auth_cmpl);
1413 break;
1414
1415 case BTA_DM_BOND_CANCEL_CMPL_EVT:
1416 if (pairing_cb.state == BT_BOND_STATE_BONDING)
1417 {
1418 bdcpy(bd_addr.address, pairing_cb.bd_addr);
1419 bond_state_changed(p_data->bond_cancel_cmpl.result, &bd_addr, BT_BOND_STATE_NONE);
1420 }
1421 break;
1422
1423 case BTA_DM_SP_CFM_REQ_EVT:
1424 btif_dm_ssp_cfm_req_evt(&p_data->cfm_req);
1425 break;
1426 case BTA_DM_SP_KEY_NOTIF_EVT:
1427 btif_dm_ssp_key_notif_evt(&p_data->key_notif);
1428 break;
1429
1430 case BTA_DM_DEV_UNPAIRED_EVT:
1431 bdcpy(bd_addr.address, p_data->link_down.bd_addr);
1432
1433 /*special handling for HID devices */
1434 #if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
Ganesh Ganapathi Batta390c94d2013-05-15 17:58:35 -07001435 btif_hh_remove_device(bd_addr);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001436 #endif
Andre Eisenbach2e7fa682013-08-08 15:42:48 -07001437 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1438 btif_storage_remove_ble_bonding_keys(&bd_addr);
1439 #endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001440 btif_storage_remove_bonded_device(&bd_addr);
1441 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
1442 break;
1443
1444 case BTA_DM_BUSY_LEVEL_EVT:
1445 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001446
1447 if (p_data->busy_level.level_flags & BTM_BL_INQUIRY_PAGING_MASK)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001448 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001449 if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_STARTED)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001450 {
1451 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb,
1452 BT_DISCOVERY_STARTED);
1453 btif_dm_inquiry_in_progress = TRUE;
1454 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001455 else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_CANCELLED)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001456 {
1457 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb,
1458 BT_DISCOVERY_STOPPED);
1459 btif_dm_inquiry_in_progress = FALSE;
1460 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001461 else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_COMPLETE)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001462 {
1463 btif_dm_inquiry_in_progress = FALSE;
1464 }
1465 }
1466 }break;
1467
1468 case BTA_DM_LINK_UP_EVT:
1469 bdcpy(bd_addr.address, p_data->link_up.bd_addr);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001470 BTIF_TRACE_DEBUG("BTA_DM_LINK_UP_EVT. Sending BT_ACL_STATE_CONNECTED");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001471
1472 btif_update_remote_version_property(&bd_addr);
1473
The Android Open Source Project5738f832012-12-12 16:00:35 -08001474 HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS,
1475 &bd_addr, BT_ACL_STATE_CONNECTED);
1476 break;
1477
1478 case BTA_DM_LINK_DOWN_EVT:
1479 bdcpy(bd_addr.address, p_data->link_down.bd_addr);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001480 BTIF_TRACE_DEBUG("BTA_DM_LINK_DOWN_EVT. Sending BT_ACL_STATE_DISCONNECTED");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001481 HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS,
1482 &bd_addr, BT_ACL_STATE_DISCONNECTED);
1483 break;
1484
1485 case BTA_DM_HW_ERROR_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001486 BTIF_TRACE_ERROR("Received H/W Error. ");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001487 /* Flush storage data */
1488 btif_config_flush();
1489 usleep(100000); /* 100milliseconds */
1490 /* Killing the process to force a restart as part of fault tolerance */
1491 kill(getpid(), SIGKILL);
1492 break;
1493
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001494#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1495 case BTA_DM_BLE_KEY_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001496 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 -08001497
1498 /* If this pairing is by-product of local initiated GATT client Read or Write,
1499 BTA would not have sent BTA_DM_BLE_SEC_REQ_EVT event and Bond state would not
1500 have setup properly. Setup pairing_cb and notify App about Bonding state now*/
1501 if (pairing_cb.state != BT_BOND_STATE_BONDING)
1502 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001503 BTIF_TRACE_DEBUG("Bond state not sent to App so far.Notify the app now");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001504 bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t*)p_data->ble_key.bd_addr,
1505 BT_BOND_STATE_BONDING);
1506 }
1507 else if (memcmp (pairing_cb.bd_addr, p_data->ble_key.bd_addr, BD_ADDR_LEN)!=0)
1508 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001509 BTIF_TRACE_ERROR("BD mismatch discard BLE key_type=%d ",p_data->ble_key.key_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001510 break;
1511 }
1512
1513 switch (p_data->ble_key.key_type)
1514 {
1515 case BTA_LE_KEY_PENC:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001516 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PENC");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001517 pairing_cb.ble.is_penc_key_rcvd = TRUE;
1518 memcpy(pairing_cb.ble.penc_key.ltk,p_data->ble_key.key_value.penc_key.ltk, 16);
1519 memcpy(pairing_cb.ble.penc_key.rand, p_data->ble_key.key_value.penc_key.rand,8);
1520 pairing_cb.ble.penc_key.ediv = p_data->ble_key.key_value.penc_key.ediv;
1521 pairing_cb.ble.penc_key.sec_level = p_data->ble_key.key_value.penc_key.sec_level;
1522
1523 for (i=0; i<16; i++)
1524 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001525 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 -08001526 }
1527 for (i=0; i<8; i++)
1528 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001529 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 -08001530 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001531 BTIF_TRACE_DEBUG("pairing_cb.ble.penc_key.ediv=0x%04x",pairing_cb.ble.penc_key.ediv);
1532 BTIF_TRACE_DEBUG("pairing_cb.ble.penc_key.sec_level=0x%02x",pairing_cb.ble.penc_key.sec_level);
1533 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 -08001534 break;
1535
1536 case BTA_LE_KEY_PID:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001537 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PID");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001538 pairing_cb.ble.is_pid_key_rcvd = TRUE;
1539 memcpy(pairing_cb.ble.pid_key, p_data->ble_key.key_value.pid_key.irk, 16);
1540 for (i=0; i<16; i++)
1541 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001542 BTIF_TRACE_DEBUG("pairing_cb.ble.pid_key[%d]=0x%02x",i,pairing_cb.ble.pid_key[i]);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001543 }
1544 break;
1545
1546 case BTA_LE_KEY_PCSRK:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001547 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PCSRK");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001548 pairing_cb.ble.is_pcsrk_key_rcvd = TRUE;
1549 pairing_cb.ble.pcsrk_key.counter = p_data->ble_key.key_value.pcsrk_key.counter;
1550 pairing_cb.ble.pcsrk_key.sec_level = p_data->ble_key.key_value.pcsrk_key.sec_level;
1551 memcpy(pairing_cb.ble.pcsrk_key.csrk,p_data->ble_key.key_value.pcsrk_key.csrk,16);
1552
1553 for (i=0; i<16; i++)
1554 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001555 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 -08001556 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001557 BTIF_TRACE_DEBUG("pairing_cb.ble.pcsrk_key.counter=0x%08x",pairing_cb.ble.pcsrk_key.counter);
1558 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 -08001559 break;
1560
1561 case BTA_LE_KEY_LENC:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001562 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LENC");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001563 pairing_cb.ble.is_lenc_key_rcvd = TRUE;
1564 pairing_cb.ble.lenc_key.div = p_data->ble_key.key_value.lenc_key.div;
1565 pairing_cb.ble.lenc_key.key_size = p_data->ble_key.key_value.lenc_key.key_size;
1566 pairing_cb.ble.lenc_key.sec_level = p_data->ble_key.key_value.lenc_key.sec_level;
1567
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001568 BTIF_TRACE_DEBUG("pairing_cb.ble.lenc_key.div=0x%04x",pairing_cb.ble.lenc_key.div);
1569 BTIF_TRACE_DEBUG("pairing_cb.ble.lenc_key.key_size=0x%02x",pairing_cb.ble.lenc_key.key_size);
1570 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 -08001571 break;
1572
1573
1574
1575 case BTA_LE_KEY_LCSRK:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001576 BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LCSRK");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001577 pairing_cb.ble.is_lcsrk_key_rcvd = TRUE;
1578 pairing_cb.ble.lcsrk_key.counter = p_data->ble_key.key_value.lcsrk_key.counter;
1579 pairing_cb.ble.lcsrk_key.div = p_data->ble_key.key_value.lcsrk_key.div;
1580 pairing_cb.ble.lcsrk_key.sec_level = p_data->ble_key.key_value.lcsrk_key.sec_level;
1581
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001582 BTIF_TRACE_DEBUG("pairing_cb.ble.lcsrk_key.div=0x%04x",pairing_cb.ble.lcsrk_key.div);
1583 BTIF_TRACE_DEBUG("pairing_cb.ble.lcsrk_key.counter=0x%08x",pairing_cb.ble.lcsrk_key.counter);
1584 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 -08001585
1586 break;
1587
1588 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001589 BTIF_TRACE_ERROR("unknown BLE key type (0x%02x)", p_data->ble_key.key_type);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001590 break;
1591 }
1592
1593 break;
1594 case BTA_DM_BLE_SEC_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001595 BTIF_TRACE_DEBUG("BTA_DM_BLE_SEC_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001596 btif_dm_ble_sec_req_evt(&p_data->ble_req);
1597 break;
1598 case BTA_DM_BLE_PASSKEY_NOTIF_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001599 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_NOTIF_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001600 btif_dm_ble_key_notif_evt(&p_data->key_notif);
1601 break;
1602 case BTA_DM_BLE_PASSKEY_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001603 BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001604 btif_dm_ble_passkey_req_evt(&p_data->pin_req);
1605 break;
1606 case BTA_DM_BLE_OOB_REQ_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001607 BTIF_TRACE_DEBUG("BTA_DM_BLE_OOB_REQ_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001608 break;
1609 case BTA_DM_BLE_LOCAL_IR_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001610 BTIF_TRACE_DEBUG("BTA_DM_BLE_LOCAL_IR_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001611 ble_local_key_cb.is_id_keys_rcvd = TRUE;
1612 memcpy(&ble_local_key_cb.id_keys.irk[0], &p_data->ble_id_keys.irk[0], sizeof(BT_OCTET16));
1613 memcpy(&ble_local_key_cb.id_keys.ir[0], &p_data->ble_id_keys.ir[0], sizeof(BT_OCTET16));
1614 memcpy(&ble_local_key_cb.id_keys.dhk[0], &p_data->ble_id_keys.dhk[0], sizeof(BT_OCTET16));
1615 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.irk[0],
1616 BTIF_DM_LE_LOCAL_KEY_IR,
1617 BT_OCTET16_LEN);
1618 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.ir[0],
1619 BTIF_DM_LE_LOCAL_KEY_IRK,
1620 BT_OCTET16_LEN);
1621 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.dhk[0],
1622 BTIF_DM_LE_LOCAL_KEY_DHK,
1623 BT_OCTET16_LEN);
1624 break;
1625 case BTA_DM_BLE_LOCAL_ER_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001626 BTIF_TRACE_DEBUG("BTA_DM_BLE_LOCAL_ER_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001627 ble_local_key_cb.is_er_rcvd = TRUE;
1628 memcpy(&ble_local_key_cb.er[0], &p_data->ble_er[0], sizeof(BT_OCTET16));
1629 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.er[0],
1630 BTIF_DM_LE_LOCAL_KEY_ER,
1631 BT_OCTET16_LEN);
1632 break;
1633
1634 case BTA_DM_BLE_AUTH_CMPL_EVT:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001635 BTIF_TRACE_DEBUG("BTA_DM_BLE_KEY_EVT. ");
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001636 btif_dm_ble_auth_cmpl_evt(&p_data->auth_cmpl);
1637 break;
Ganesh Ganapathi Batta9546abf2014-05-30 16:28:00 -07001638
1639 case BTA_DM_LE_FEATURES_READ:
1640 {
1641 tBTM_BLE_VSC_CB cmn_vsc_cb;
1642 bt_local_le_features_t local_le_features;
1643 char buf[512];
1644 bt_property_t prop;
1645 prop.type = BT_PROPERTY_LOCAL_LE_FEATURES;
1646 prop.val = (void*)buf;
1647 prop.len = sizeof(buf);
1648
1649 /* LE features are not stored in storage. Should be retrived from stack */
1650 BTM_BleGetVendorCapabilities(&cmn_vsc_cb);
1651 local_le_features.local_privacy_enabled = BTM_BleLocalPrivacyEnabled();
1652
1653 prop.len = sizeof (bt_local_le_features_t);
1654 if (cmn_vsc_cb.filter_support == 1)
1655 local_le_features.max_adv_filter_supported = cmn_vsc_cb.max_filter;
1656 else
1657 local_le_features.max_adv_filter_supported = 0;
1658 local_le_features.max_adv_instance = cmn_vsc_cb.adv_inst_max;
1659 local_le_features.max_irk_list_size = cmn_vsc_cb.max_irk_list_sz;
1660 local_le_features.rpa_offload_supported = cmn_vsc_cb.rpa_offloading;
1661 local_le_features.scan_result_storage_size = cmn_vsc_cb.tot_scan_results_strg;
1662 memcpy(prop.val, &local_le_features, prop.len);
1663 HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, BT_STATUS_SUCCESS, 1, &prop);
1664 break;
1665 }
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001666#endif
1667
The Android Open Source Project5738f832012-12-12 16:00:35 -08001668 case BTA_DM_AUTHORIZE_EVT:
1669 case BTA_DM_SIG_STRENGTH_EVT:
1670 case BTA_DM_SP_RMT_OOB_EVT:
1671 case BTA_DM_SP_KEYPRESS_EVT:
1672 case BTA_DM_ROLE_CHG_EVT:
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001673
The Android Open Source Project5738f832012-12-12 16:00:35 -08001674 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001675 BTIF_TRACE_WARNING( "btif_dm_cback : unhandled event (%d)", event );
The Android Open Source Project5738f832012-12-12 16:00:35 -08001676 break;
1677 }
1678} /* btui_security_cback() */
1679
1680
1681/*******************************************************************************
1682**
1683** Function btif_dm_generic_evt
1684**
1685** Description Executes non-BTA upstream events in BTIF context
1686**
1687** Returns void
1688**
1689*******************************************************************************/
1690static void btif_dm_generic_evt(UINT16 event, char* p_param)
1691{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001692 BTIF_TRACE_EVENT("%s: event=%d", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001693 switch(event)
1694 {
1695 case BTIF_DM_CB_DISCOVERY_STARTED:
1696 {
1697 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STARTED);
1698 }
1699 break;
1700
1701 case BTIF_DM_CB_CREATE_BOND:
1702 {
1703 btif_dm_cb_create_bond((bt_bdaddr_t *)p_param);
1704 }
1705 break;
1706
1707 case BTIF_DM_CB_REMOVE_BOND:
1708 {
1709 btif_dm_cb_remove_bond((bt_bdaddr_t *)p_param);
1710 }
1711 break;
1712
1713 case BTIF_DM_CB_HID_REMOTE_NAME:
1714 {
1715 btif_dm_cb_hid_remote_name((tBTM_REMOTE_DEV_NAME *)p_param);
1716 }
1717 break;
1718
1719 case BTIF_DM_CB_BOND_STATE_BONDING:
1720 {
1721 bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t *)p_param, BT_BOND_STATE_BONDING);
1722 }
1723 break;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001724 case BTIF_DM_CB_LE_TX_TEST:
1725 case BTIF_DM_CB_LE_RX_TEST:
1726 {
1727 uint8_t status;
1728 STREAM_TO_UINT8(status, p_param);
1729 HAL_CBACK(bt_hal_cbacks, le_test_mode_cb,
1730 (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, 0);
1731 }
1732 break;
1733 case BTIF_DM_CB_LE_TEST_END:
1734 {
1735 uint8_t status;
1736 uint16_t count = 0;
1737 STREAM_TO_UINT8(status, p_param);
1738 if (status == 0)
1739 STREAM_TO_UINT16(count, p_param);
1740 HAL_CBACK(bt_hal_cbacks, le_test_mode_cb,
1741 (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, count);
1742 }
1743 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001744 default:
1745 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001746 BTIF_TRACE_WARNING("%s : Unknown event 0x%x", __FUNCTION__, event);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001747 }
1748 break;
1749 }
1750}
1751
1752/*******************************************************************************
1753**
1754** Function bte_dm_evt
1755**
1756** Description Switches context from BTE to BTIF for all DM events
1757**
1758** Returns void
1759**
1760*******************************************************************************/
1761
1762void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data)
1763{
1764 bt_status_t status;
1765
1766 /* switch context to btif task context (copy full union size for convenience) */
1767 status = btif_transfer_context(btif_dm_upstreams_evt, (uint16_t)event, (void*)p_data, sizeof(tBTA_DM_SEC), NULL);
1768
1769 /* catch any failed context transfers */
1770 ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status);
1771}
1772
1773/*******************************************************************************
1774**
1775** Function bte_search_devices_evt
1776**
1777** Description Switches context from BTE to BTIF for DM search events
1778**
1779** Returns void
1780**
1781*******************************************************************************/
1782static void bte_search_devices_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
1783{
1784 UINT16 param_len = 0;
1785
1786 if (p_data)
1787 param_len += sizeof(tBTA_DM_SEARCH);
1788 /* Allocate buffer to hold the pointers (deep copy). The pointers will point to the end of the tBTA_DM_SEARCH */
1789 switch (event)
1790 {
1791 case BTA_DM_INQ_RES_EVT:
1792 {
1793 if (p_data->inq_res.p_eir)
1794 param_len += HCI_EXT_INQ_RESPONSE_LEN;
1795 }
1796 break;
1797
1798 case BTA_DM_DISC_RES_EVT:
1799 {
1800 if (p_data->disc_res.raw_data_size && p_data->disc_res.p_raw_data)
1801 param_len += p_data->disc_res.raw_data_size;
1802 }
1803 break;
1804 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001805 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 -08001806
1807 /* if remote name is available in EIR, set teh flag so that stack doesnt trigger RNR */
1808 if (event == BTA_DM_INQ_RES_EVT)
1809 p_data->inq_res.remt_name_not_required = check_eir_remote_name(p_data, NULL, NULL);
1810
1811 btif_transfer_context (btif_dm_search_devices_evt , (UINT16) event, (void *)p_data, param_len,
1812 (param_len > sizeof(tBTA_DM_SEARCH)) ? search_devices_copy_cb : NULL);
1813}
1814
1815/*******************************************************************************
1816**
1817** Function bte_dm_search_services_evt
1818**
1819** Description Switches context from BTE to BTIF for DM search services
1820** event
1821**
1822** Returns void
1823**
1824*******************************************************************************/
1825static void bte_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
1826{
1827 UINT16 param_len = 0;
1828 if (p_data)
1829 param_len += sizeof(tBTA_DM_SEARCH);
1830 switch (event)
1831 {
1832 case BTA_DM_DISC_RES_EVT:
1833 {
1834 if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0)) {
1835 param_len += (p_data->disc_res.num_uuids * MAX_UUID_SIZE);
1836 }
1837 } break;
1838 }
1839 /* TODO: The only other member that needs a deep copy is the p_raw_data. But not sure
1840 * if raw_data is needed. */
1841 btif_transfer_context(btif_dm_search_services_evt, event, (char*)p_data, param_len,
1842 (param_len > sizeof(tBTA_DM_SEARCH)) ? search_services_copy_cb : NULL);
1843}
1844
1845/*******************************************************************************
1846**
1847** Function bte_dm_remote_service_record_evt
1848**
1849** Description Switches context from BTE to BTIF for DM search service
1850** record event
1851**
1852** Returns void
1853**
1854*******************************************************************************/
1855static void bte_dm_remote_service_record_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
1856{
1857 /* TODO: The only member that needs a deep copy is the p_raw_data. But not sure yet if this is needed. */
1858 btif_transfer_context(btif_dm_remote_service_record_evt, event, (char*)p_data, sizeof(tBTA_DM_SEARCH), NULL);
1859}
1860
1861/*****************************************************************************
1862**
1863** btif api functions (no context switch)
1864**
1865*****************************************************************************/
1866
1867/*******************************************************************************
1868**
1869** Function btif_dm_start_discovery
1870**
1871** Description Start device discovery/inquiry
1872**
1873** Returns bt_status_t
1874**
1875*******************************************************************************/
1876bt_status_t btif_dm_start_discovery(void)
1877{
1878 tBTA_DM_INQ inq_params;
1879 tBTA_SERVICE_MASK services = 0;
1880
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001881 BTIF_TRACE_EVENT("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001882 /* TODO: Do we need to handle multiple inquiries at the same time? */
1883
1884 /* Set inquiry params and call API */
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001885#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
The Android Open Source Project5738f832012-12-12 16:00:35 -08001886 inq_params.mode = BTA_DM_GENERAL_INQUIRY|BTA_BLE_GENERAL_INQUIRY;
Matthew Xie7f3e4292013-09-30 12:44:10 -07001887#if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
1888 inq_params.intl_duration[0]= BTIF_DM_INTERLEAVE_DURATION_BR_ONE;
1889 inq_params.intl_duration[1]= BTIF_DM_INTERLEAVE_DURATION_LE_ONE;
1890 inq_params.intl_duration[2]= BTIF_DM_INTERLEAVE_DURATION_BR_TWO;
1891 inq_params.intl_duration[3]= BTIF_DM_INTERLEAVE_DURATION_LE_TWO;
1892#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08001893#else
1894 inq_params.mode = BTA_DM_GENERAL_INQUIRY;
1895#endif
1896 inq_params.duration = BTIF_DM_DEFAULT_INQ_MAX_DURATION;
1897
1898 inq_params.max_resps = BTIF_DM_DEFAULT_INQ_MAX_RESULTS;
1899 inq_params.report_dup = TRUE;
1900
1901 inq_params.filter_type = BTA_DM_INQ_CLR;
1902 /* TODO: Filter device by BDA needs to be implemented here */
1903
1904 /* Will be enabled to TRUE once inquiry busy level has been received */
1905 btif_dm_inquiry_in_progress = FALSE;
1906 /* find nearby devices */
1907 BTA_DmSearch(&inq_params, services, bte_search_devices_evt);
1908
1909 return BT_STATUS_SUCCESS;
1910}
1911
1912/*******************************************************************************
1913**
1914** Function btif_dm_cancel_discovery
1915**
1916** Description Cancels search
1917**
1918** Returns bt_status_t
1919**
1920*******************************************************************************/
1921bt_status_t btif_dm_cancel_discovery(void)
1922{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001923 BTIF_TRACE_EVENT("%s", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001924 BTA_DmSearchCancel();
1925 return BT_STATUS_SUCCESS;
1926}
1927
1928/*******************************************************************************
1929**
1930** Function btif_dm_create_bond
1931**
1932** Description Initiate bonding with the specified device
1933**
1934** Returns bt_status_t
1935**
1936*******************************************************************************/
1937bt_status_t btif_dm_create_bond(const bt_bdaddr_t *bd_addr)
1938{
1939 bdstr_t bdstr;
1940
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001941 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 -08001942 if (pairing_cb.state != BT_BOND_STATE_NONE)
1943 return BT_STATUS_BUSY;
1944
1945 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_CREATE_BOND,
1946 (char *)bd_addr, sizeof(bt_bdaddr_t), NULL);
1947
1948 return BT_STATUS_SUCCESS;
1949}
1950
1951/*******************************************************************************
1952**
1953** Function btif_dm_cancel_bond
1954**
1955** Description Initiate bonding with the specified device
1956**
1957** Returns bt_status_t
1958**
1959*******************************************************************************/
1960
1961bt_status_t btif_dm_cancel_bond(const bt_bdaddr_t *bd_addr)
1962{
1963 bdstr_t bdstr;
1964
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07001965 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 -08001966
1967 /* TODO:
1968 ** 1. Restore scan modes
1969 ** 2. special handling for HID devices
1970 */
1971 if (pairing_cb.state == BT_BOND_STATE_BONDING)
1972 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001973
1974#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1975
1976 if (pairing_cb.is_ssp)
1977 {
1978 if (pairing_cb.is_le_only)
1979 {
1980 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT);
1981 }
1982 else
1983 BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE);
1984 }
1985 else
1986 {
1987 if (pairing_cb.is_le_only)
1988 {
1989 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
1990 }
1991 else
1992 {
1993 BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL);
1994 }
1995 /* Cancel bonding, in case it is in ACL connection setup state */
1996 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
1997 }
1998
1999#else
The Android Open Source Project5738f832012-12-12 16:00:35 -08002000 if (pairing_cb.is_ssp)
2001 {
2002 BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE);
2003 }
2004 else
2005 {
2006 BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL);
2007 }
2008 /* Cancel bonding, in case it is in ACL connection setup state */
2009 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
2010 btif_storage_remove_bonded_device((bt_bdaddr_t *)bd_addr);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002011#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002012 }
2013
2014 return BT_STATUS_SUCCESS;
2015}
2016
2017/*******************************************************************************
2018**
Kim Schulza9eb25c2013-09-30 10:55:52 +02002019** Function btif_dm_hh_open_failed
2020**
2021** Description informs the upper layers if the HH have failed during bonding
2022**
2023** Returns none
2024**
2025*******************************************************************************/
2026
2027void btif_dm_hh_open_failed(bt_bdaddr_t *bdaddr)
2028{
2029 if (pairing_cb.state == BT_BOND_STATE_BONDING &&
2030 bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0)
2031 {
2032 bond_state_changed(BT_STATUS_FAIL, bdaddr, BT_BOND_STATE_NONE);
2033 }
2034}
2035
2036/*******************************************************************************
2037**
The Android Open Source Project5738f832012-12-12 16:00:35 -08002038** Function btif_dm_remove_bond
2039**
2040** Description Removes bonding with the specified device
2041**
2042** Returns bt_status_t
2043**
2044*******************************************************************************/
2045
2046bt_status_t btif_dm_remove_bond(const bt_bdaddr_t *bd_addr)
2047{
2048 bdstr_t bdstr;
2049
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002050 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 -08002051 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_REMOVE_BOND,
2052 (char *)bd_addr, sizeof(bt_bdaddr_t), NULL);
2053
2054 return BT_STATUS_SUCCESS;
2055}
2056
2057/*******************************************************************************
2058**
2059** Function btif_dm_pin_reply
2060**
2061** Description BT legacy pairing - PIN code reply
2062**
2063** Returns bt_status_t
2064**
2065*******************************************************************************/
2066
2067bt_status_t btif_dm_pin_reply( const bt_bdaddr_t *bd_addr, uint8_t accept,
2068 uint8_t pin_len, bt_pin_code_t *pin_code)
2069{
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002070 BTIF_TRACE_EVENT("%s: accept=%d", __FUNCTION__, accept);
Hemant Gupta831423e2014-01-08 12:42:13 +05302071 if (pin_code == NULL)
2072 return BT_STATUS_FAIL;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002073#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
The Android Open Source Project5738f832012-12-12 16:00:35 -08002074
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002075 if (pairing_cb.is_le_only)
2076 {
2077 int i;
2078 UINT32 passkey = 0;
2079 int multi[] = {100000, 10000, 1000, 100, 10,1};
2080 BD_ADDR remote_bd_addr;
2081 bdcpy(remote_bd_addr, bd_addr->address);
2082 for (i = 0; i < 6; i++)
2083 {
2084 passkey += (multi[i] * (pin_code->pin[i] - '0'));
2085 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002086 BTIF_TRACE_DEBUG("btif_dm_pin_reply: passkey: %d", passkey);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002087 BTA_DmBlePasskeyReply(remote_bd_addr, accept, passkey);
2088
2089 }
2090 else
2091 {
2092 BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin);
2093 if (accept)
2094 pairing_cb.pin_code_len = pin_len;
2095 }
2096#else
The Android Open Source Project5738f832012-12-12 16:00:35 -08002097 BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin);
2098
2099 if (accept)
2100 pairing_cb.pin_code_len = pin_len;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002101#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002102 return BT_STATUS_SUCCESS;
2103}
2104
2105/*******************************************************************************
2106**
2107** Function btif_dm_ssp_reply
2108**
2109** Description BT SSP Reply - Just Works, Numeric Comparison & Passkey Entry
2110**
2111** Returns bt_status_t
2112**
2113*******************************************************************************/
The Android Open Source Project5738f832012-12-12 16:00:35 -08002114bt_status_t btif_dm_ssp_reply(const bt_bdaddr_t *bd_addr,
2115 bt_ssp_variant_t variant, uint8_t accept,
2116 uint32_t passkey)
2117{
Mike J. Chen5cd8bff2014-01-31 18:16:59 -08002118 UNUSED(passkey);
2119
The Android Open Source Project5738f832012-12-12 16:00:35 -08002120 if (variant == BT_SSP_VARIANT_PASSKEY_ENTRY)
2121 {
2122 /* This is not implemented in the stack.
2123 * For devices with display, this is not needed
2124 */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002125 BTIF_TRACE_WARNING("%s: Not implemented", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002126 return BT_STATUS_FAIL;
2127 }
2128 /* BT_SSP_VARIANT_CONSENT & BT_SSP_VARIANT_PASSKEY_CONFIRMATION supported */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002129 BTIF_TRACE_EVENT("%s: accept=%d", __FUNCTION__, accept);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002130#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2131 if (pairing_cb.is_le_only)
2132 {
2133 if (accept)
2134 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_GRANTED);
2135 else
2136 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT);
2137 }
2138 else
2139 BTA_DmConfirm( (UINT8 *)bd_addr->address, accept);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002140
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002141#else
2142 BTA_DmConfirm( (UINT8 *)bd_addr->address, accept);
2143#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002144 return BT_STATUS_SUCCESS;
2145}
2146
2147/*******************************************************************************
2148**
2149** Function btif_dm_get_adapter_property
2150**
2151** Description Queries the BTA for the adapter property
2152**
2153** Returns bt_status_t
2154**
2155*******************************************************************************/
2156bt_status_t btif_dm_get_adapter_property(bt_property_t *prop)
2157{
2158 bt_status_t status;
2159
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002160 BTIF_TRACE_EVENT("%s: type=0x%x", __FUNCTION__, prop->type);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002161 switch (prop->type)
2162 {
2163 case BT_PROPERTY_BDNAME:
2164 {
2165 bt_bdname_t *bd_name = (bt_bdname_t*)prop->val;
Matthew Xie1e5109b2012-11-09 18:26:26 -08002166 strcpy((char *)bd_name->name, btif_get_default_local_name());
The Android Open Source Project5738f832012-12-12 16:00:35 -08002167 prop->len = strlen((char *)bd_name->name);
2168 }
2169 break;
2170
2171 case BT_PROPERTY_ADAPTER_SCAN_MODE:
2172 {
2173 /* if the storage does not have it. Most likely app never set it. Default is NONE */
2174 bt_scan_mode_t *mode = (bt_scan_mode_t*)prop->val;
2175 *mode = BT_SCAN_MODE_NONE;
2176 prop->len = sizeof(bt_scan_mode_t);
2177 }
2178 break;
2179
2180 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
2181 {
2182 uint32_t *tmt = (uint32_t*)prop->val;
2183 *tmt = 120; /* default to 120s, if not found in NV */
2184 prop->len = sizeof(uint32_t);
2185 }
2186 break;
2187
2188 default:
2189 prop->len = 0;
2190 return BT_STATUS_FAIL;
2191 }
2192 return BT_STATUS_SUCCESS;
2193}
2194
2195/*******************************************************************************
2196**
2197** Function btif_dm_get_remote_services
2198**
2199** Description Start SDP to get remote services
2200**
2201** Returns bt_status_t
2202**
2203*******************************************************************************/
2204bt_status_t btif_dm_get_remote_services(bt_bdaddr_t *remote_addr)
2205{
2206 bdstr_t bdstr;
2207
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002208 BTIF_TRACE_EVENT("%s: remote_addr=%s", __FUNCTION__, bd2str(remote_addr, &bdstr));
The Android Open Source Project5738f832012-12-12 16:00:35 -08002209
2210 BTA_DmDiscover(remote_addr->address, BTA_ALL_SERVICE_MASK,
2211 bte_dm_search_services_evt, TRUE);
2212
2213 return BT_STATUS_SUCCESS;
2214}
2215
2216/*******************************************************************************
2217**
2218** Function btif_dm_get_remote_service_record
2219**
2220** Description Start SDP to get remote service record
2221**
2222**
2223** Returns bt_status_t
2224*******************************************************************************/
2225bt_status_t btif_dm_get_remote_service_record(bt_bdaddr_t *remote_addr,
2226 bt_uuid_t *uuid)
2227{
2228 tSDP_UUID sdp_uuid;
2229 bdstr_t bdstr;
2230
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002231 BTIF_TRACE_EVENT("%s: remote_addr=%s", __FUNCTION__, bd2str(remote_addr, &bdstr));
The Android Open Source Project5738f832012-12-12 16:00:35 -08002232
2233 sdp_uuid.len = MAX_UUID_SIZE;
2234 memcpy(sdp_uuid.uu.uuid128, uuid->uu, MAX_UUID_SIZE);
2235
2236 BTA_DmDiscoverUUID(remote_addr->address, &sdp_uuid,
2237 bte_dm_remote_service_record_evt, TRUE);
2238
2239 return BT_STATUS_SUCCESS;
2240}
2241
2242void btif_dm_execute_service_request(UINT16 event, char *p_param)
2243{
2244 BOOLEAN b_enable = FALSE;
2245 bt_status_t status;
2246 if (event == BTIF_DM_ENABLE_SERVICE)
2247 {
2248 b_enable = TRUE;
2249 }
2250 status = btif_in_execute_service_request(*((tBTA_SERVICE_ID*)p_param), b_enable);
2251 if (status == BT_STATUS_SUCCESS)
2252 {
2253 bt_property_t property;
2254 bt_uuid_t local_uuids[BT_MAX_NUM_UUIDS];
2255
2256 /* Now send the UUID_PROPERTY_CHANGED event to the upper layer */
2257 BTIF_STORAGE_FILL_PROPERTY(&property, BT_PROPERTY_UUIDS,
2258 sizeof(local_uuids), local_uuids);
2259 btif_storage_get_adapter_property(&property);
2260 HAL_CBACK(bt_hal_cbacks, adapter_properties_cb,
2261 BT_STATUS_SUCCESS, 1, &property);
2262 }
2263 return;
2264}
2265
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002266void btif_dm_proc_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, tBTA_OOB_DATA *p_oob_data,
2267 tBTA_AUTH_REQ *p_auth_req, BOOLEAN is_orig)
2268{
2269 UINT8 yes_no_bit = BTA_AUTH_SP_YES & *p_auth_req;
2270 /* if local initiated:
2271 ** 1. set DD + MITM
2272 ** if remote initiated:
2273 ** 1. Copy over the auth_req from peer's io_rsp
2274 ** 2. Set the MITM if peer has it set or if peer has DisplayYesNo (iPhone)
2275 ** as a fallback set MITM+GB if peer had MITM set
2276 */
2277 UNUSED (bd_addr);
2278 UNUSED (p_io_cap);
2279 UNUSED (p_oob_data);
2280
2281
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002282 BTIF_TRACE_DEBUG("+%s: p_auth_req=%d", __FUNCTION__, *p_auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002283 if(pairing_cb.is_local_initiated)
2284 {
2285 /* if initing/responding to a dedicated bonding, use dedicate bonding bit */
2286 *p_auth_req = BTA_AUTH_DD_BOND | BTA_AUTH_SP_YES;
2287 }
2288 else if (!is_orig)
2289 {
2290 /* peer initiated paring. They probably know what they want.
2291 ** Copy the mitm from peer device.
2292 */
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002293 BTIF_TRACE_DEBUG("%s: setting p_auth_req to peer's: %d",
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002294 __FUNCTION__, pairing_cb.auth_req);
2295 *p_auth_req = (pairing_cb.auth_req & BTA_AUTH_BONDS);
2296
2297 /* copy over the MITM bit as well. In addition if the peer has DisplayYesNo, force MITM */
2298 if ((yes_no_bit) || (pairing_cb.io_cap & BTM_IO_CAP_IO) )
2299 *p_auth_req |= BTA_AUTH_SP_YES;
2300 }
2301 else if (yes_no_bit)
2302 {
2303 /* set the general bonding bit for stored device */
2304 *p_auth_req = BTA_AUTH_GEN_BOND | yes_no_bit;
2305 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002306 BTIF_TRACE_DEBUG("-%s: p_auth_req=%d", __FUNCTION__, *p_auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002307}
2308
2309void btif_dm_proc_io_rsp(BD_ADDR bd_addr, tBTA_IO_CAP io_cap,
2310 tBTA_OOB_DATA oob_data, tBTA_AUTH_REQ auth_req)
2311{
2312 UNUSED (bd_addr);
2313 UNUSED (oob_data);
2314
2315 if(auth_req & BTA_AUTH_BONDS)
2316 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002317 BTIF_TRACE_DEBUG("%s auth_req:%d", __FUNCTION__, auth_req);
Ganesh Ganapathi Battaa217ab92014-04-28 16:30:55 -07002318 pairing_cb.auth_req = auth_req;
2319 pairing_cb.io_cap = io_cap;
2320 }
2321}
2322
The Android Open Source Project5738f832012-12-12 16:00:35 -08002323#if (BTM_OOB_INCLUDED == TRUE)
2324void btif_dm_set_oob_for_io_req(tBTA_OOB_DATA *p_oob_data)
2325{
2326 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2327 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
2328 {
2329 *p_oob_data = FALSE;
2330 }
2331 else
2332 {
2333 *p_oob_data = TRUE;
2334 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002335 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 -08002336}
2337#endif /* BTM_OOB_INCLUDED */
2338
2339#ifdef BTIF_DM_OOB_TEST
2340void btif_dm_load_local_oob(void)
2341{
Nick Kralevichd70b7a82013-01-31 14:40:15 -08002342 char prop_oob[PROPERTY_VALUE_MAX];
The Android Open Source Project5738f832012-12-12 16:00:35 -08002343 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002344 BTIF_TRACE_DEBUG("btif_dm_load_local_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002345 if (prop_oob[0] != '3')
2346 {
2347#if (BTM_OOB_INCLUDED == TRUE)
2348 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2349 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
2350 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002351 BTIF_TRACE_DEBUG("btif_dm_load_local_oob: read OOB, call BTA_DmLocalOob()");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002352 BTA_DmLocalOob();
2353 }
2354#else
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002355 BTIF_TRACE_ERROR("BTM_OOB_INCLUDED is FALSE!!(btif_dm_load_local_oob)");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002356#endif
2357 }
2358}
2359
2360void btif_dm_proc_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r)
2361{
2362 FILE *fp;
2363 char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
2364 char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
2365 char *path = NULL;
Nick Kralevichd70b7a82013-01-31 14:40:15 -08002366 char prop_oob[PROPERTY_VALUE_MAX];
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002367 BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob: valid=%d", valid);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002368 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2369 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 &&
2370 valid)
2371 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002372 BTIF_TRACE_DEBUG("save local OOB data in memory");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002373 memcpy(oob_cb.sp_c, c, BT_OCTET16_LEN);
2374 memcpy(oob_cb.sp_r, r, BT_OCTET16_LEN);
2375 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002376 BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002377 if (prop_oob[0] == '1')
2378 path = path_a;
2379 else if (prop_oob[0] == '2')
2380 path = path_b;
2381 if (path)
2382 {
2383 fp = fopen(path, "wb+");
2384 if (fp == NULL)
2385 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002386 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 -08002387 }
2388 else
2389 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002390 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 -08002391 fwrite (c , 1 , BT_OCTET16_LEN , fp );
2392 fwrite (r , 1 , BT_OCTET16_LEN , fp );
2393 fclose(fp);
2394 }
2395 }
2396 }
2397}
2398BOOLEAN btif_dm_proc_rmt_oob(BD_ADDR bd_addr, BT_OCTET16 p_c, BT_OCTET16 p_r)
2399{
2400 char t[128];
2401 FILE *fp;
2402 char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
2403 char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
2404 char *path = NULL;
Nick Kralevichd70b7a82013-01-31 14:40:15 -08002405 char prop_oob[PROPERTY_VALUE_MAX];
The Android Open Source Project5738f832012-12-12 16:00:35 -08002406 BOOLEAN result = FALSE;
2407 bt_bdaddr_t bt_bd_addr;
2408 bdcpy(oob_cb.oob_bdaddr, bd_addr);
2409 property_get("service.brcm.bt.oob", prop_oob, "3");
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002410 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob prop_oob = %s",prop_oob);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002411 if (prop_oob[0] == '1')
2412 path = path_b;
2413 else if (prop_oob[0] == '2')
2414 path = path_a;
2415 if (path)
2416 {
2417 fp = fopen(path, "rb");
2418 if (fp == NULL)
2419 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002420 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 -08002421 return FALSE;
2422 }
2423 else
2424 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002425 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob: read OOB data from %s",path);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002426 fread (p_c , 1 , BT_OCTET16_LEN , fp );
2427 fread (p_r , 1 , BT_OCTET16_LEN , fp );
2428 fclose(fp);
2429 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002430 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: TRUE");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002431 sprintf(t, "%02x:%02x:%02x:%02x:%02x:%02x",
2432 oob_cb.oob_bdaddr[0], oob_cb.oob_bdaddr[1], oob_cb.oob_bdaddr[2],
2433 oob_cb.oob_bdaddr[3], oob_cb.oob_bdaddr[4], oob_cb.oob_bdaddr[5]);
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002434 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: peer_bdaddr = %s", t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002435 sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
2436 p_c[0], p_c[1], p_c[2], p_c[3], p_c[4], p_c[5], p_c[6], p_c[7],
2437 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 -07002438 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: c = %s",t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002439 sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
2440 p_r[0], p_r[1], p_r[2], p_r[3], p_r[4], p_r[5], p_r[6], p_r[7],
2441 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 -07002442 BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: r = %s",t);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002443 bdcpy(bt_bd_addr.address, bd_addr);
2444 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_BOND_STATE_BONDING,
2445 (char *)&bt_bd_addr, sizeof(bt_bdaddr_t), NULL);
2446 result = TRUE;
2447 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002448 BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob result=%d",result);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002449 return result;
2450}
2451#endif /* BTIF_DM_OOB_TEST */
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002452#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2453
2454static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif)
2455{
2456 bt_bdaddr_t bd_addr;
2457 bt_bdname_t bd_name;
2458 UINT32 cod;
2459
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002460 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002461
2462 /* Remote name update */
2463 btif_update_remote_properties(p_ssp_key_notif->bd_addr , p_ssp_key_notif->bd_name,
2464 NULL, BT_DEVICE_TYPE_BLE);
2465 bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
2466 memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
2467
2468 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
2469 pairing_cb.is_ssp = FALSE;
2470 cod = COD_UNCLASSIFIED;
2471
2472 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
2473 cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION,
2474 p_ssp_key_notif->passkey);
2475}
2476
2477/*******************************************************************************
2478**
2479** Function btif_dm_ble_auth_cmpl_evt
2480**
2481** Description Executes authentication complete event in btif context
2482**
2483** Returns void
2484**
2485*******************************************************************************/
2486static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
2487{
2488 /* Save link key, if not temporary */
2489 bt_bdaddr_t bd_addr;
2490 bt_status_t status = BT_STATUS_FAIL;
2491 bt_bond_state_t state = BT_BOND_STATE_NONE;
2492
2493 bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
2494 if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
2495 {
2496 /* store keys */
2497 }
2498 if (p_auth_cmpl->success)
2499 {
2500 status = BT_STATUS_SUCCESS;
2501 state = BT_BOND_STATE_BONDED;
2502
2503 btif_dm_save_ble_bonding_keys();
2504 BTA_GATTC_Refresh(bd_addr.address);
2505 btif_dm_get_remote_services(&bd_addr);
2506 }
2507 else
2508 {
2509 /*Map the HCI fail reason to bt status */
2510 switch (p_auth_cmpl->fail_reason)
2511 {
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002512 default:
Andre Eisenbachca22ac42013-02-13 17:02:11 +09002513 btif_dm_remove_ble_bonding_keys();
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002514 status = BT_STATUS_FAIL;
2515 break;
2516 }
2517 }
2518 bond_state_changed(status, &bd_addr, state);
2519}
2520
2521
2522
2523void btif_dm_load_ble_local_keys(void)
2524{
2525 bt_status_t bt_status;
2526
2527 memset(&ble_local_key_cb, 0, sizeof(btif_dm_local_key_cb_t));
2528
2529 if (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_ER,(char*)&ble_local_key_cb.er[0],
2530 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)
2531 {
2532 ble_local_key_cb.is_er_rcvd = TRUE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002533 BTIF_TRACE_DEBUG("%s BLE ER key loaded",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002534 }
2535
2536 if ((btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IR,(char*)&ble_local_key_cb.id_keys.ir[0],
2537 BT_OCTET16_LEN)== BT_STATUS_SUCCESS )&&
2538 (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IRK, (char*)&ble_local_key_cb.id_keys.irk[0],
2539 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)&&
2540 (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_DHK,(char*)&ble_local_key_cb.id_keys.dhk[0],
2541 BT_OCTET16_LEN)== BT_STATUS_SUCCESS))
2542 {
2543 ble_local_key_cb.is_id_keys_rcvd = TRUE;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002544 BTIF_TRACE_DEBUG("%s BLE ID keys loaded",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002545 }
2546
2547}
2548void btif_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
2549 tBTA_BLE_LOCAL_ID_KEYS *p_id_keys)
2550{
2551 if (ble_local_key_cb.is_er_rcvd )
2552 {
2553 memcpy(&er[0], &ble_local_key_cb.er[0], sizeof(BT_OCTET16));
2554 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ER;
2555 }
2556
2557 if (ble_local_key_cb.is_id_keys_rcvd)
2558 {
2559 memcpy(&p_id_keys->ir[0], &ble_local_key_cb.id_keys.ir[0], sizeof(BT_OCTET16));
2560 memcpy(&p_id_keys->irk[0], &ble_local_key_cb.id_keys.irk[0], sizeof(BT_OCTET16));
2561 memcpy(&p_id_keys->dhk[0], &ble_local_key_cb.id_keys.dhk[0], sizeof(BT_OCTET16));
2562 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID;
2563 }
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002564 BTIF_TRACE_DEBUG("%s *p_key_mask=0x%02x",__FUNCTION__, *p_key_mask);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002565}
2566
2567void btif_dm_save_ble_bonding_keys(void)
2568{
2569
2570 bt_bdaddr_t bd_addr;
2571
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002572 BTIF_TRACE_DEBUG("%s",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002573
2574 bdcpy(bd_addr.address, pairing_cb.bd_addr);
2575
2576 if (pairing_cb.ble.is_penc_key_rcvd)
2577 {
2578 btif_storage_add_ble_bonding_key(&bd_addr,
2579 (char *) &pairing_cb.ble.penc_key,
2580 BTIF_DM_LE_KEY_PENC,
2581 sizeof(btif_dm_ble_penc_keys_t));
2582 }
2583
2584 if (pairing_cb.ble.is_pid_key_rcvd)
2585 {
2586 btif_storage_add_ble_bonding_key(&bd_addr,
2587 (char *) &pairing_cb.ble.pid_key[0],
2588 BTIF_DM_LE_KEY_PID,
2589 BT_OCTET16_LEN);
2590 }
2591
2592
2593 if (pairing_cb.ble.is_pcsrk_key_rcvd)
2594 {
2595 btif_storage_add_ble_bonding_key(&bd_addr,
2596 (char *) &pairing_cb.ble.pcsrk_key,
2597 BTIF_DM_LE_KEY_PCSRK,
2598 sizeof(btif_dm_ble_pcsrk_keys_t));
2599 }
2600
2601
2602 if (pairing_cb.ble.is_lenc_key_rcvd)
2603 {
2604 btif_storage_add_ble_bonding_key(&bd_addr,
2605 (char *) &pairing_cb.ble.lenc_key,
2606 BTIF_DM_LE_KEY_LENC,
2607 sizeof(btif_dm_ble_lenc_keys_t));
2608 }
2609
2610 if (pairing_cb.ble.is_lcsrk_key_rcvd)
2611 {
2612 btif_storage_add_ble_bonding_key(&bd_addr,
2613 (char *) &pairing_cb.ble.lcsrk_key,
2614 BTIF_DM_LE_KEY_LCSRK,
2615 sizeof(btif_dm_ble_lcsrk_keys_t));
2616 }
2617
2618}
2619
2620
2621void btif_dm_remove_ble_bonding_keys(void)
2622{
2623 bt_bdaddr_t bd_addr;
2624
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002625 BTIF_TRACE_DEBUG("%s",__FUNCTION__ );
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002626
2627 bdcpy(bd_addr.address, pairing_cb.bd_addr);
2628 btif_storage_remove_ble_bonding_keys(&bd_addr);
2629}
2630
2631
2632/*******************************************************************************
2633**
2634** Function btif_dm_ble_sec_req_evt
2635**
2636** Description Eprocess security request event in btif context
2637**
2638** Returns void
2639**
2640*******************************************************************************/
2641void btif_dm_ble_sec_req_evt(tBTA_DM_BLE_SEC_REQ *p_ble_req)
2642{
2643 bt_bdaddr_t bd_addr;
2644 bt_bdname_t bd_name;
2645 UINT32 cod;
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002646 BTIF_TRACE_DEBUG("%s", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002647
2648 if (pairing_cb.state == BT_BOND_STATE_BONDING)
2649 {
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002650 BTIF_TRACE_DEBUG("%s Discard security request", __FUNCTION__);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002651 return;
2652 }
2653
2654 /* Remote name update */
2655 btif_update_remote_properties(p_ble_req->bd_addr,p_ble_req->bd_name,NULL,BT_DEVICE_TYPE_BLE);
2656
2657 bdcpy(bd_addr.address, p_ble_req->bd_addr);
2658 memcpy(bd_name.name, p_ble_req->bd_name, BD_NAME_LEN);
2659
2660 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
2661
2662 pairing_cb.is_temp = FALSE;
2663 pairing_cb.is_le_only = TRUE;
2664 pairing_cb.is_ssp = TRUE;
2665
2666 cod = COD_UNCLASSIFIED;
2667
2668 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod,
2669 BT_SSP_VARIANT_CONSENT, 0);
2670}
2671
2672
2673
2674/*******************************************************************************
2675**
2676** Function btif_dm_ble_passkey_req_evt
2677**
2678** Description Executes pin request event in btif context
2679**
2680** Returns void
2681**
2682*******************************************************************************/
2683static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
2684{
2685 bt_bdaddr_t bd_addr;
2686 bt_bdname_t bd_name;
2687 UINT32 cod;
2688
2689 /* Remote name update */
2690 btif_update_remote_properties(p_pin_req->bd_addr,p_pin_req->bd_name,NULL,BT_DEVICE_TYPE_BLE);
2691
2692 bdcpy(bd_addr.address, p_pin_req->bd_addr);
2693 memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN);
2694
2695 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
2696 pairing_cb.is_le_only = TRUE;
2697
2698 cod = COD_UNCLASSIFIED;
2699
2700 HAL_CBACK(bt_hal_cbacks, pin_request_cb,
2701 &bd_addr, &bd_name, cod);
2702}
2703
2704
2705void btif_dm_update_ble_remote_properties( BD_ADDR bd_addr, BD_NAME bd_name,
2706 tBT_DEVICE_TYPE dev_type)
2707{
2708 btif_update_remote_properties(bd_addr,bd_name,NULL,dev_type);
2709}
2710
2711static void btif_dm_ble_tx_test_cback(void *p)
2712{
2713 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TX_TEST,
2714 (char *)p, 1, NULL);
2715}
2716
2717static void btif_dm_ble_rx_test_cback(void *p)
2718{
2719 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_RX_TEST,
2720 (char *)p, 1, NULL);
2721}
2722
2723static void btif_dm_ble_test_end_cback(void *p)
2724{
2725 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TEST_END,
2726 (char *)p, 3, NULL);
2727}
2728/*******************************************************************************
2729**
2730** Function btif_le_test_mode
2731**
2732** Description Sends a HCI BLE Test command to the Controller
2733**
2734** Returns BT_STATUS_SUCCESS on success
2735**
2736*******************************************************************************/
2737bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t len)
2738{
2739 switch (opcode) {
2740 case HCI_BLE_TRANSMITTER_TEST:
2741 if (len != 3) return BT_STATUS_PARM_INVALID;
2742 BTM_BleTransmitterTest(buf[0],buf[1],buf[2], btif_dm_ble_tx_test_cback);
2743 break;
2744 case HCI_BLE_RECEIVER_TEST:
2745 if (len != 1) return BT_STATUS_PARM_INVALID;
2746 BTM_BleReceiverTest(buf[0], btif_dm_ble_rx_test_cback);
2747 break;
2748 case HCI_BLE_TEST_END:
2749 BTM_BleTestEnd((tBTM_CMPL_CB*) btif_dm_ble_test_end_cback);
2750 break;
2751 default:
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002752 BTIF_TRACE_ERROR("%s: Unknown LE Test Mode Command 0x%x", __FUNCTION__, opcode);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002753 return BT_STATUS_UNSUPPORTED;
2754 }
2755 return BT_STATUS_SUCCESS;
2756}
2757
2758#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -08002759
2760void btif_dm_on_disable()
2761{
2762 /* cancel any pending pairing requests */
2763 if (pairing_cb.state == BT_BOND_STATE_BONDING)
2764 {
2765 bt_bdaddr_t bd_addr;
2766
Sharvil Nanavatie8c3d752014-05-04 10:12:26 -07002767 BTIF_TRACE_DEBUG("%s: Cancel pending pairing request", __FUNCTION__);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002768 bdcpy(bd_addr.address, pairing_cb.bd_addr);
2769 btif_dm_cancel_bond(&bd_addr);
2770 }
2771}
Matthew Xie1e5109b2012-11-09 18:26:26 -08002772
2773static char* btif_get_default_local_name() {
2774 if (btif_default_local_name[0] == '\0')
2775 {
2776 int max_len = sizeof(btif_default_local_name) - 1;
2777 if (BTM_DEF_LOCAL_NAME[0] != '\0')
2778 {
2779 strncpy(btif_default_local_name, BTM_DEF_LOCAL_NAME, max_len);
2780 }
2781 else
2782 {
2783 char prop_model[PROPERTY_VALUE_MAX];
2784 property_get(PROPERTY_PRODUCT_MODEL, prop_model, "");
2785 strncpy(btif_default_local_name, prop_model, max_len);
2786 }
2787 btif_default_local_name[max_len] = '\0';
2788 }
2789 return btif_default_local_name;
2790}