1 /******************************************************************************
3 * Copyright (C) 2009-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /************************************************************************************
23 * Description: Contains Device Management (DM) related functionality
26 ***********************************************************************************/
31 #include <hardware/bluetooth.h>
33 #include <utils/Log.h>
34 #include <cutils/properties.h>
40 #include "btif_util.h"
42 #include "btif_storage.h"
44 #include "btif_config.h"
46 #include "bta_gatt_api.h"
47 /******************************************************************************
49 ******************************************************************************/
51 #define COD_UNCLASSIFIED ((0x1F) << 8)
52 #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
63 #define BTIF_DM_DEFAULT_INQ_MAX_RESULTS 0
64 #define BTIF_DM_DEFAULT_INQ_MAX_DURATION 10
65 #define BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING 2
67 #define PROPERTY_PRODUCT_MODEL "ro.product.model"
68 #define DEFAULT_LOCAL_NAME_MAX 31
69 #if (DEFAULT_LOCAL_NAME_MAX > BTM_MAX_LOC_BD_NAME_LEN)
70 #error "default btif local name size exceeds stack supported length"
73 #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
80 #define BOND_TYPE_UNKNOWN 0
81 #define BOND_TYPE_PERSISTENT 1
82 #define BOND_TYPE_TEMPORARY 2
86 bt_bond_state_t state;
91 UINT8 autopair_attempts;
92 UINT8 is_local_initiated;
94 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
98 } btif_dm_pairing_cb_t;
103 UINT8 ir[BT_OCTET16_LEN];
104 UINT8 irk[BT_OCTET16_LEN];
105 UINT8 dhk[BT_OCTET16_LEN];
106 }btif_dm_local_key_id_t;
111 UINT8 er[BT_OCTET16_LEN];
112 BOOLEAN is_id_keys_rcvd;
113 btif_dm_local_key_id_t id_keys; /* ID kyes */
115 }btif_dm_local_key_cb_t;
121 } btif_dm_remote_name_t;
127 BD_ADDR oob_bdaddr; /* peer bdaddr*/
129 #define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id))
131 /* This flag will be true if HCI_Inquiry is in progress */
132 static BOOLEAN btif_dm_inquiry_in_progress = FALSE;
134 /************************************************************************************
136 ************************************************************************************/
137 static char btif_default_local_name[DEFAULT_LOCAL_NAME_MAX+1] = {'\0'};
139 /******************************************************************************
141 ******************************************************************************/
142 static btif_dm_pairing_cb_t pairing_cb;
143 static btif_dm_oob_cb_t oob_cb;
144 static void btif_dm_generic_evt(UINT16 event, char* p_param);
145 static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr);
146 static void btif_dm_cb_hid_remote_name(tBTM_REMOTE_DEV_NAME *p_remote_name);
147 static void btif_update_remote_properties(BD_ADDR bd_addr, BD_NAME bd_name,
148 DEV_CLASS dev_class, tBT_DEVICE_TYPE dev_type);
149 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
150 static btif_dm_local_key_cb_t ble_local_key_cb;
151 static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif);
152 static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl);
153 static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ *p_pin_req);
155 static char* btif_get_default_local_name();
156 /******************************************************************************
158 ******************************************************************************/
159 extern UINT16 bta_service_id_to_uuid_lkup_tbl [BTA_MAX_SERVICE_ID];
160 extern bt_status_t btif_hf_execute_service(BOOLEAN b_enable);
161 extern bt_status_t btif_av_execute_service(BOOLEAN b_enable);
162 extern bt_status_t btif_hh_execute_service(BOOLEAN b_enable);
163 extern int btif_hh_connect(bt_bdaddr_t *bd_addr);
164 extern void bta_gatt_convert_uuid16_to_uuid128(UINT8 uuid_128[LEN_UUID_128], UINT16 uuid_16);
167 /******************************************************************************
169 ******************************************************************************/
171 bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id,
174 /* Check the service_ID and invoke the profile's BT state changed API */
177 case BTA_HFP_SERVICE_ID:
178 case BTA_HSP_SERVICE_ID:
180 btif_hf_execute_service(b_enable);
182 case BTA_A2DP_SERVICE_ID:
184 btif_av_execute_service(b_enable);
186 case BTA_HID_SERVICE_ID:
188 btif_hh_execute_service(b_enable);
192 BTIF_TRACE_ERROR1("%s: Unknown service being enabled", __FUNCTION__);
193 return BT_STATUS_FAIL;
195 return BT_STATUS_SUCCESS;
198 /*******************************************************************************
200 ** Function check_eir_remote_name
202 ** Description Check if remote name is in the EIR data
204 ** Returns TRUE if remote name found
205 ** Populate p_remote_name, if provided and remote name found
207 *******************************************************************************/
208 static BOOLEAN check_eir_remote_name(tBTA_DM_SEARCH *p_search_data,
209 UINT8 *p_remote_name, UINT8 *p_remote_name_len)
211 UINT8 *p_eir_remote_name = NULL;
212 UINT8 remote_name_len = 0;
214 /* Check EIR for remote name and services */
215 if (p_search_data->inq_res.p_eir)
217 p_eir_remote_name = BTA_CheckEirData(p_search_data->inq_res.p_eir,
218 BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, &remote_name_len);
219 if (!p_eir_remote_name)
221 p_eir_remote_name = BTA_CheckEirData(p_search_data->inq_res.p_eir,
222 BTM_EIR_SHORTENED_LOCAL_NAME_TYPE, &remote_name_len);
225 if (p_eir_remote_name)
227 if (remote_name_len > BD_NAME_LEN)
228 remote_name_len = BD_NAME_LEN;
230 if (p_remote_name && p_remote_name_len)
232 memcpy(p_remote_name, p_eir_remote_name, remote_name_len);
233 *(p_remote_name + remote_name_len) = 0;
234 *p_remote_name_len = remote_name_len;
245 /*******************************************************************************
247 ** Function check_cached_remote_name
249 ** Description Check if remote name is in the NVRAM cache
251 ** Returns TRUE if remote name found
252 ** Populate p_remote_name, if provided and remote name found
254 *******************************************************************************/
255 static BOOLEAN check_cached_remote_name(tBTA_DM_SEARCH *p_search_data,
256 UINT8 *p_remote_name, UINT8 *p_remote_name_len)
259 bt_bdaddr_t remote_bdaddr;
260 bt_property_t prop_name;
262 /* check if we already have it in our btif_storage cache */
263 bdcpy(remote_bdaddr.address, p_search_data->inq_res.bd_addr);
264 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_BDNAME,
265 sizeof(bt_bdname_t), &bdname);
266 if (btif_storage_get_remote_device_property(
267 &remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS)
269 if (p_remote_name && p_remote_name_len)
271 strcpy((char *)p_remote_name, (char *)bdname.name);
272 *p_remote_name_len = strlen((char *)p_remote_name);
280 BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod)
283 bt_property_t prop_name;
285 /* check if we already have it in our btif_storage cache */
286 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE,
287 sizeof(uint32_t), &remote_cod);
288 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS)
290 if ((remote_cod & 0x7ff) == cod)
297 BOOLEAN check_cod_hid(const bt_bdaddr_t *remote_bdaddr, uint32_t cod)
300 bt_property_t prop_name;
302 /* check if we already have it in our btif_storage cache */
303 BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE,
304 sizeof(uint32_t), &remote_cod);
305 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
306 &prop_name) == BT_STATUS_SUCCESS)
308 if ((remote_cod & 0x700) == cod)
314 BOOLEAN check_hid_le(const bt_bdaddr_t *remote_bdaddr)
316 uint32_t remote_dev_type;
317 bt_property_t prop_name;
319 /* check if we already have it in our btif_storage cache */
320 BTIF_STORAGE_FILL_PROPERTY(&prop_name,BT_PROPERTY_TYPE_OF_DEVICE,
321 sizeof(uint32_t), &remote_dev_type);
322 if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr,
323 &prop_name) == BT_STATUS_SUCCESS)
325 if (remote_dev_type == BT_DEVICE_DEVTYPE_BLE)
328 bd2str(remote_bdaddr, &bdstr);
329 if(btif_config_exist("Remote", bdstr, "HidAppId"))
336 static void bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr, bt_bond_state_t state)
338 /* Send bonding state only once - based on outgoing/incoming we may receive duplicates */
339 if ( (pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING) )
342 if (pairing_cb.bond_type == BOND_TYPE_TEMPORARY)
344 state = BT_BOND_STATE_NONE;
346 BTIF_TRACE_DEBUG3("%s: state=%d prev_state=%d", __FUNCTION__, state, pairing_cb.state);
348 HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state);
350 if (state == BT_BOND_STATE_BONDING)
352 pairing_cb.state = state;
353 bdcpy(pairing_cb.bd_addr, bd_addr->address);
357 memset(&pairing_cb, 0, sizeof(pairing_cb));
362 /* store remote version in bt config to always have access
364 static void btif_update_remote_version_property(bt_bdaddr_t *p_bd)
366 bt_property_t property;
368 UINT16 lmp_subver = 0;
370 tBTM_STATUS btm_status;
371 bt_remote_version_t info;
375 btm_status = BTM_ReadRemoteVersion(*(BD_ADDR*)p_bd, &lmp_ver,
376 &mfct_set, &lmp_subver);
378 ALOGD("remote version info [%s]: %x, %x, %x", bd2str(p_bd, &bdstr),
379 lmp_ver, mfct_set, lmp_subver);
381 if (btm_status == BTM_SUCCESS)
383 /* always update cache to ensure we have availability whenever BTM API
385 info.manufacturer = mfct_set;
386 info.sub_ver = lmp_subver;
387 info.version = lmp_ver;
388 BTIF_STORAGE_FILL_PROPERTY(&property,
389 BT_PROPERTY_REMOTE_VERSION_INFO, sizeof(bt_remote_version_t),
391 status = btif_storage_set_remote_device_property(p_bd, &property);
392 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote version", status);
397 static void btif_update_remote_properties(BD_ADDR bd_addr, BD_NAME bd_name,
398 DEV_CLASS dev_class, tBT_DEVICE_TYPE device_type)
400 int num_properties = 0;
401 bt_property_t properties[3];
405 bt_device_type_t dev_type;
407 memset(properties, 0, sizeof(properties));
408 bdcpy(bdaddr.address, bd_addr);
411 if (strlen((const char *) bd_name))
413 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
414 BT_PROPERTY_BDNAME, strlen((char *)bd_name), bd_name);
415 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
416 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device name", status);
420 /* class of device */
421 cod = devclass2uint(dev_class);
423 BTIF_TRACE_DEBUG1("%s():cod is 0, set as unclassified", __FUNCTION__);
424 cod = COD_UNCLASSIFIED;
427 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
428 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
429 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
430 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device class", status);
434 dev_type = device_type;
435 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
436 BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
437 status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]);
438 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device type", status);
441 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
442 status, &bdaddr, num_properties, properties);
444 /*******************************************************************************
446 ** Function hid_remote_name_cback
448 ** Description Remote name callback for HID device. Called in stack context
449 ** Special handling for HID devices
453 *******************************************************************************/
454 static void hid_remote_name_cback(void *p_param)
456 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
458 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_HID_REMOTE_NAME,
459 (char *)p_param, sizeof(tBTM_REMOTE_DEV_NAME), NULL);
462 /*******************************************************************************
464 ** Function btif_dm_cb_hid_remote_name
466 ** Description Remote name callback for HID device. Called in btif context
467 ** Special handling for HID devices
471 *******************************************************************************/
472 static void btif_dm_cb_hid_remote_name(tBTM_REMOTE_DEV_NAME *p_remote_name)
474 BTIF_TRACE_DEBUG3("%s: status=%d pairing_cb.state=%d", __FUNCTION__, p_remote_name->status, pairing_cb.state);
475 if (pairing_cb.state == BT_BOND_STATE_BONDING)
477 bt_bdaddr_t remote_bd;
479 bdcpy(remote_bd.address, pairing_cb.bd_addr);
481 if (p_remote_name->status == BTM_SUCCESS)
483 bond_state_changed(BT_STATUS_SUCCESS, &remote_bd, BT_BOND_STATE_BONDED);
486 bond_state_changed(BT_STATUS_FAIL, &remote_bd, BT_BOND_STATE_NONE);
490 /*******************************************************************************
492 ** Function btif_dm_cb_create_bond
494 ** Description Create bond initiated from the BTIF thread context
495 ** Special handling for HID devices
499 *******************************************************************************/
500 static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr)
502 BOOLEAN is_hid = check_cod(bd_addr, COD_HID_POINTING);
505 bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
510 status = btif_hh_connect(bd_addr);
511 if(status != BT_STATUS_SUCCESS)
512 bond_state_changed(status, bd_addr, BT_BOND_STATE_NONE);
516 #if BLE_INCLUDED == TRUE
520 bd2str(bd_addr, &bdstr);
521 if(btif_config_get_int("Remote", (char const *)&bdstr,"DevType", &device_type) &&
522 (btif_storage_get_remote_addr_type(bd_addr, &addr_type) == BT_STATUS_SUCCESS) &&
523 (device_type == BT_DEVICE_TYPE_BLE))
525 BTA_DmAddBleDevice(bd_addr->address, addr_type, BT_DEVICE_TYPE_BLE);
528 BTA_DmBond ((UINT8 *)bd_addr->address);
530 /* Track originator of bond creation */
531 pairing_cb.is_local_initiated = TRUE;
535 /*******************************************************************************
537 ** Function btif_dm_cb_remove_bond
539 ** Description remove bond initiated from the BTIF thread context
540 ** Special handling for HID devices
544 *******************************************************************************/
545 void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr)
548 /*special handling for HID devices */
549 /* VUP needs to be sent if its a HID Device. The HID HOST module will check if there
550 is a valid hid connection with this bd_addr. If yes VUP will be issued.*/
551 #if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
552 if (btif_hh_virtual_unplug(bd_addr) != BT_STATUS_SUCCESS)
555 BTA_DmRemoveDevice((UINT8 *)bd_addr->address);
559 /*******************************************************************************
561 ** Function search_devices_copy_cb
563 ** Description Deep copy callback for search devices event
567 *******************************************************************************/
568 static void search_devices_copy_cb(UINT16 event, char *p_dest, char *p_src)
570 tBTA_DM_SEARCH *p_dest_data = (tBTA_DM_SEARCH *) p_dest;
571 tBTA_DM_SEARCH *p_src_data = (tBTA_DM_SEARCH *) p_src;
576 BTIF_TRACE_DEBUG2("%s: event=%s", __FUNCTION__, dump_dm_search_event(event));
577 memcpy(p_dest_data, p_src_data, sizeof(tBTA_DM_SEARCH));
580 case BTA_DM_INQ_RES_EVT:
582 if (p_src_data->inq_res.p_eir)
584 p_dest_data->inq_res.p_eir = (UINT8 *)(p_dest + sizeof(tBTA_DM_SEARCH));
585 memcpy(p_dest_data->inq_res.p_eir, p_src_data->inq_res.p_eir, HCI_EXT_INQ_RESPONSE_LEN);
590 case BTA_DM_DISC_RES_EVT:
592 if (p_src_data->disc_res.raw_data_size && p_src_data->disc_res.p_raw_data)
594 p_dest_data->disc_res.p_raw_data = (UINT8 *)(p_dest + sizeof(tBTA_DM_SEARCH));
595 memcpy(p_dest_data->disc_res.p_raw_data,
596 p_src_data->disc_res.p_raw_data, p_src_data->disc_res.raw_data_size);
603 static void search_services_copy_cb(UINT16 event, char *p_dest, char *p_src)
605 tBTA_DM_SEARCH *p_dest_data = (tBTA_DM_SEARCH *) p_dest;
606 tBTA_DM_SEARCH *p_src_data = (tBTA_DM_SEARCH *) p_src;
610 memcpy(p_dest_data, p_src_data, sizeof(tBTA_DM_SEARCH));
613 case BTA_DM_DISC_RES_EVT:
615 if (p_src_data->disc_res.result == BTA_SUCCESS)
617 if (p_src_data->disc_res.num_uuids > 0)
619 p_dest_data->disc_res.p_uuid_list =
620 (UINT8*)(p_dest + sizeof(tBTA_DM_SEARCH));
621 memcpy(p_dest_data->disc_res.p_uuid_list, p_src_data->disc_res.p_uuid_list,
622 p_src_data->disc_res.num_uuids*MAX_UUID_SIZE);
623 GKI_freebuf(p_src_data->disc_res.p_uuid_list);
625 if (p_src_data->disc_res.p_raw_data != NULL)
627 GKI_freebuf(p_src_data->disc_res.p_raw_data);
633 /******************************************************************************
635 ** BTIF DM callback events
637 *****************************************************************************/
639 /*******************************************************************************
641 ** Function btif_dm_pin_req_evt
643 ** Description Executes pin request event in btif context
647 *******************************************************************************/
648 static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
653 bt_pin_code_t pin_code;
655 /* Remote properties update */
656 btif_update_remote_properties(p_pin_req->bd_addr, p_pin_req->bd_name,
657 p_pin_req->dev_class, BT_DEVICE_TYPE_BREDR);
659 bdcpy(bd_addr.address, p_pin_req->bd_addr);
660 memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN);
662 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
664 cod = devclass2uint(p_pin_req->dev_class);
667 BTIF_TRACE_DEBUG1("%s():cod is 0, set as unclassified", __FUNCTION__);
668 cod = COD_UNCLASSIFIED;
671 /* check for auto pair possiblity only if bond was initiated by local device */
672 if (pairing_cb.is_local_initiated)
674 if (check_cod(&bd_addr, COD_AV_HEADSETS) ||
675 check_cod(&bd_addr, COD_AV_HANDSFREE) ||
676 check_cod(&bd_addr, COD_AV_HEADPHONES) ||
677 check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) ||
678 check_cod(&bd_addr, COD_AV_HIFI_AUDIO) ||
679 check_cod(&bd_addr, COD_HID_POINTING))
681 BTIF_TRACE_DEBUG1("%s()cod matches for auto pair", __FUNCTION__);
682 /* Check if this device can be auto paired */
683 if ((btif_storage_is_device_autopair_blacklisted(&bd_addr) == FALSE) &&
684 (pairing_cb.autopair_attempts == 0))
686 BTIF_TRACE_DEBUG1("%s() Attempting auto pair", __FUNCTION__);
687 pin_code.pin[0] = 0x30;
688 pin_code.pin[1] = 0x30;
689 pin_code.pin[2] = 0x30;
690 pin_code.pin[3] = 0x30;
692 pairing_cb.autopair_attempts++;
693 BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin);
697 else if (check_cod(&bd_addr, COD_HID_KEYBOARD) ||
698 check_cod(&bd_addr, COD_HID_COMBO))
700 if(( btif_storage_is_fixed_pin_zeros_keyboard (&bd_addr) == TRUE) &&
701 (pairing_cb.autopair_attempts == 0))
703 BTIF_TRACE_DEBUG1("%s() Attempting auto pair", __FUNCTION__);
704 pin_code.pin[0] = 0x30;
705 pin_code.pin[1] = 0x30;
706 pin_code.pin[2] = 0x30;
707 pin_code.pin[3] = 0x30;
709 pairing_cb.autopair_attempts++;
710 BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin);
715 HAL_CBACK(bt_hal_cbacks, pin_request_cb,
716 &bd_addr, &bd_name, cod);
719 /*******************************************************************************
721 ** Function btif_dm_ssp_cfm_req_evt
723 ** Description Executes SSP confirm request event in btif context
727 *******************************************************************************/
728 static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ *p_ssp_cfm_req)
733 BOOLEAN is_incoming = !(pairing_cb.state == BT_BOND_STATE_BONDING);
735 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
737 /* Remote properties update */
738 btif_update_remote_properties(p_ssp_cfm_req->bd_addr, p_ssp_cfm_req->bd_name,
739 p_ssp_cfm_req->dev_class, BT_DEVICE_TYPE_BREDR);
741 bdcpy(bd_addr.address, p_ssp_cfm_req->bd_addr);
742 memcpy(bd_name.name, p_ssp_cfm_req->bd_name, BD_NAME_LEN);
744 /* Set the pairing_cb based on the local & remote authentication requirements */
745 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
747 /* if just_works and bonding bit is not set treat this as temporary */
748 if (p_ssp_cfm_req->just_works && !(p_ssp_cfm_req->loc_auth_req & BTM_AUTH_BONDS) &&
749 !(p_ssp_cfm_req->rmt_auth_req & BTM_AUTH_BONDS) &&
750 !(check_cod((bt_bdaddr_t*)&p_ssp_cfm_req->bd_addr, COD_HID_POINTING)))
751 pairing_cb.bond_type = BOND_TYPE_TEMPORARY;
753 pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
755 pairing_cb.is_ssp = TRUE;
757 /* If JustWorks auto-accept */
758 if (p_ssp_cfm_req->just_works)
760 /* Pairing consent for JustWorks needed if:
761 * 1. Incoming pairing is detected AND
762 * 2. local IO capabilities are DisplayYesNo AND
763 * 3. remote IO capabiltiies are DisplayOnly or NoInputNoOutput;
765 if ((is_incoming) && ((p_ssp_cfm_req->loc_io_caps == 0x01) &&
766 (p_ssp_cfm_req->rmt_io_caps == 0x00 || p_ssp_cfm_req->rmt_io_caps == 0x03)))
768 BTIF_TRACE_EVENT3("%s: User consent needed for incoming pairing request. loc_io_caps: %d, rmt_io_caps: %d",
769 __FUNCTION__, p_ssp_cfm_req->loc_io_caps, p_ssp_cfm_req->rmt_io_caps);
773 BTIF_TRACE_EVENT1("%s: Auto-accept JustWorks pairing", __FUNCTION__);
774 btif_dm_ssp_reply(&bd_addr, BT_SSP_VARIANT_CONSENT, TRUE, 0);
779 cod = devclass2uint(p_ssp_cfm_req->dev_class);
782 ALOGD("cod is 0, set as unclassified");
783 cod = COD_UNCLASSIFIED;
786 pairing_cb.sdp_attempts = 0;
787 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod,
788 (p_ssp_cfm_req->just_works ? BT_SSP_VARIANT_CONSENT : BT_SSP_VARIANT_PASSKEY_CONFIRMATION),
789 p_ssp_cfm_req->num_val);
792 static void btif_dm_ssp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif)
798 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
800 /* Remote properties update */
801 btif_update_remote_properties(p_ssp_key_notif->bd_addr, p_ssp_key_notif->bd_name,
802 p_ssp_key_notif->dev_class, BT_DEVICE_TYPE_BREDR);
804 bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
805 memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
807 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
808 pairing_cb.is_ssp = TRUE;
809 cod = devclass2uint(p_ssp_key_notif->dev_class);
812 ALOGD("cod is 0, set as unclassified");
813 cod = COD_UNCLASSIFIED;
816 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
817 cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION,
818 p_ssp_key_notif->passkey);
820 /*******************************************************************************
822 ** Function btif_dm_auth_cmpl_evt
824 ** Description Executes authentication complete event in btif context
828 *******************************************************************************/
829 static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
831 /* Save link key, if not temporary */
833 bt_status_t status = BT_STATUS_FAIL;
834 bt_bond_state_t state = BT_BOND_STATE_NONE;
836 bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
837 if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
839 if ((p_auth_cmpl->key_type < HCI_LKEY_TYPE_DEBUG_COMB) || (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB) ||
840 (p_auth_cmpl->key_type == HCI_LKEY_TYPE_CHANGED_COMB) || pairing_cb.bond_type == BOND_TYPE_PERSISTENT)
843 BTIF_TRACE_DEBUG3("%s: Storing link key. key_type=0x%x, bond_type=%d",
844 __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.bond_type);
845 ret = btif_storage_add_bonded_device(&bd_addr,
846 p_auth_cmpl->key, p_auth_cmpl->key_type,
847 pairing_cb.pin_code_len);
848 ASSERTC(ret == BT_STATUS_SUCCESS, "storing link key failed", ret);
852 BTIF_TRACE_DEBUG3("%s: Temporary key. Not storing. key_type=0x%x, bond_type=%d",
853 __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.bond_type);
854 if(pairing_cb.bond_type == BOND_TYPE_TEMPORARY)
856 BTIF_TRACE_DEBUG1("%s: sending BT_BOND_STATE_NONE for Temp pairing",
858 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
863 if (p_auth_cmpl->success)
865 status = BT_STATUS_SUCCESS;
866 state = BT_BOND_STATE_BONDED;
868 /* Trigger SDP on the device */
869 pairing_cb.sdp_attempts = 1;;
871 if(btif_dm_inquiry_in_progress)
872 btif_dm_cancel_discovery();
874 btif_dm_get_remote_services(&bd_addr);
875 /* Do not call bond_state_changed_cb yet. Wait till fetch remote service is complete */
879 /*Map the HCI fail reason to bt status */
880 switch(p_auth_cmpl->fail_reason)
882 case HCI_ERR_PAGE_TIMEOUT:
883 case HCI_ERR_CONNECTION_TOUT:
884 status = BT_STATUS_RMT_DEV_DOWN;
887 /* map the auth failure codes, so we can retry pairing if necessary */
888 case HCI_ERR_AUTH_FAILURE:
889 case HCI_ERR_HOST_REJECT_SECURITY:
890 case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE:
891 case HCI_ERR_UNIT_KEY_USED:
892 case HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED:
893 case HCI_ERR_INSUFFCIENT_SECURITY:
894 BTIF_TRACE_DEBUG1(" %s() Authentication fail ", __FUNCTION__);
895 if (pairing_cb.autopair_attempts == 1)
897 BTIF_TRACE_DEBUG1("%s(): Adding device to blacklist ", __FUNCTION__);
899 /* Add the device to dynamic black list only if this device belongs to Audio/pointing dev class */
900 if (check_cod(&bd_addr, COD_AV_HEADSETS) ||
901 check_cod(&bd_addr, COD_AV_HANDSFREE) ||
902 check_cod(&bd_addr, COD_AV_HEADPHONES) ||
903 check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) ||
904 check_cod(&bd_addr, COD_AV_HIFI_AUDIO) ||
905 check_cod(&bd_addr, COD_HID_POINTING))
907 btif_storage_add_device_to_autopair_blacklist (&bd_addr);
909 pairing_cb.autopair_attempts++;
911 /* Create the Bond once again */
912 BTIF_TRACE_DEBUG1("%s() auto pair failed. Reinitiate Bond", __FUNCTION__);
913 btif_dm_cb_create_bond (&bd_addr);
918 /* if autopair attempts are more than 1, or not attempted */
919 status = BT_STATUS_AUTH_FAILURE;
924 status = BT_STATUS_FAIL;
926 bond_state_changed(status, &bd_addr, state);
930 /******************************************************************************
932 ** Function btif_dm_search_devices_evt
934 ** Description Executes search devices callback events in btif context
938 ******************************************************************************/
939 static void btif_dm_search_devices_evt (UINT16 event, char *p_param)
941 tBTA_DM_SEARCH *p_search_data;
942 BTIF_TRACE_EVENT2("%s event=%s", __FUNCTION__, dump_dm_search_event(event));
946 case BTA_DM_DISC_RES_EVT:
948 p_search_data = (tBTA_DM_SEARCH *)p_param;
949 /* Remote name update */
950 if (strlen((const char *) p_search_data->disc_res.bd_name))
952 bt_property_t properties[1];
956 properties[0].type = BT_PROPERTY_BDNAME;
957 properties[0].val = p_search_data->disc_res.bd_name;
958 properties[0].len = strlen((char *)p_search_data->disc_res.bd_name);
959 bdcpy(bdaddr.address, p_search_data->disc_res.bd_addr);
961 status = btif_storage_set_remote_device_property(&bdaddr, &properties[0]);
962 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device property", status);
963 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
964 status, &bdaddr, 1, properties);
966 /* TODO: Services? */
970 case BTA_DM_INQ_RES_EVT:
974 UINT8 *p_eir_remote_name = NULL;
977 UINT8 remote_name_len;
978 UINT8 *p_cached_name = NULL;
979 tBTA_SERVICE_MASK services = 0;
982 p_search_data = (tBTA_DM_SEARCH *)p_param;
983 bdcpy(bdaddr.address, p_search_data->inq_res.bd_addr);
985 BTIF_TRACE_DEBUG3("%s() %s device_type = 0x%x\n", __FUNCTION__, bd2str(&bdaddr, &bdstr),
986 #if (BLE_INCLUDED == TRUE)
987 p_search_data->inq_res.device_type);
989 BT_DEVICE_TYPE_BREDR);
993 cod = devclass2uint (p_search_data->inq_res.dev_class);
996 ALOGD("cod is 0, set as unclassified");
997 cod = COD_UNCLASSIFIED;
1000 if (!check_eir_remote_name(p_search_data, bdname.name, &remote_name_len))
1001 check_cached_remote_name(p_search_data, bdname.name, &remote_name_len);
1003 /* Check EIR for remote name and services */
1004 if (p_search_data->inq_res.p_eir)
1006 BTA_GetEirService(p_search_data->inq_res.p_eir, &services);
1007 BTIF_TRACE_DEBUG2("%s()EIR BTA services = %08X", __FUNCTION__, (UINT32)services);
1008 /* TODO: Get the service list and check to see which uuids we got and send it back to the client. */
1013 bt_property_t properties[5];
1014 bt_device_type_t dev_type;
1016 uint32_t num_properties = 0;
1019 memset(properties, 0, sizeof(properties));
1021 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1022 BT_PROPERTY_BDADDR, sizeof(bdaddr), &bdaddr);
1025 /* Don't send BDNAME if it is empty */
1028 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1030 strlen((char *)bdname.name), &bdname);
1035 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1036 BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
1039 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1040 /* FixMe: Assumption is that bluetooth.h and BTE enums match */
1041 dev_type = p_search_data->inq_res.device_type;
1042 addr_type = p_search_data->inq_res.ble_addr_type;
1044 dev_type = BT_DEVICE_TYPE_BREDR;
1046 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1047 BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type);
1050 BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
1051 BT_PROPERTY_REMOTE_RSSI, sizeof(int8_t),
1052 &(p_search_data->inq_res.rssi));
1055 status = btif_storage_add_remote_device(&bdaddr, num_properties, properties);
1056 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device (inquiry)", status);
1057 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1058 status = btif_storage_set_remote_addr_type(&bdaddr, addr_type);
1059 ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote addr type (inquiry)", status);
1061 /* Callback to notify upper layer of device */
1062 HAL_CBACK(bt_hal_cbacks, device_found_cb,
1063 num_properties, properties);
1068 case BTA_DM_INQ_CMPL_EVT:
1072 case BTA_DM_DISC_CMPL_EVT:
1074 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED);
1077 case BTA_DM_SEARCH_CANCEL_CMPL_EVT:
1079 /* if inquiry is not in progress and we get a cancel event, then
1080 * it means we are done with inquiry, but remote_name fetches are in
1083 * if inquiry is in progress, then we don't want to act on this cancel_cmpl_evt
1084 * but instead wait for the cancel_cmpl_evt via the Busy Level
1087 if (btif_dm_inquiry_in_progress == FALSE)
1089 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED);
1096 /*******************************************************************************
1098 ** Function btif_dm_search_services_evt
1100 ** Description Executes search services event in btif context
1104 *******************************************************************************/
1105 static void btif_dm_search_services_evt(UINT16 event, char *p_param)
1107 tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param;
1109 BTIF_TRACE_EVENT2("%s: event = %d", __FUNCTION__, event);
1112 case BTA_DM_DISC_RES_EVT:
1114 bt_uuid_t uuid_arr[BT_MAX_NUM_UUIDS]; /* Max 32 services */
1116 uint32_t i = 0, j = 0;
1117 bt_bdaddr_t bd_addr;
1120 bdcpy(bd_addr.address, p_data->disc_res.bd_addr);
1122 BTIF_TRACE_DEBUG3("%s:(result=0x%x, services 0x%x)", __FUNCTION__,
1123 p_data->disc_res.result, p_data->disc_res.services);
1124 if ((p_data->disc_res.result != BTA_SUCCESS) &&
1125 (pairing_cb.state == BT_BOND_STATE_BONDING ) &&
1126 (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING))
1128 BTIF_TRACE_WARNING1("%s:SDP failed after bonding re-attempting", __FUNCTION__);
1129 pairing_cb.sdp_attempts++;
1130 btif_dm_get_remote_services(&bd_addr);
1133 prop.type = BT_PROPERTY_UUIDS;
1135 if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0))
1137 prop.val = p_data->disc_res.p_uuid_list;
1138 prop.len = p_data->disc_res.num_uuids * MAX_UUID_SIZE;
1139 for (i=0; i < p_data->disc_res.num_uuids; i++)
1142 uuid_to_string((bt_uuid_t*)(p_data->disc_res.p_uuid_list + (i*MAX_UUID_SIZE)), temp);
1143 BTIF_TRACE_ERROR2("Index: %d uuid:%s", i, temp);
1147 /* onUuidChanged requires getBondedDevices to be populated.
1148 ** bond_state_changed needs to be sent prior to remote_device_property
1150 if ((pairing_cb.state == BT_BOND_STATE_BONDING) &&
1151 (bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0)&&
1152 pairing_cb.sdp_attempts > 0)
1154 BTIF_TRACE_DEBUG1("%s Remote Service SDP done. Call bond_state_changed_cb BONDED",
1156 pairing_cb.sdp_attempts = 0;
1157 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED);
1160 if(p_data->disc_res.num_uuids != 0)
1162 /* Also write this to the NVRAM */
1163 ret = btif_storage_set_remote_device_property(&bd_addr, &prop);
1164 ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);
1165 /* Send the event to the BTIF */
1166 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1167 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1172 case BTA_DM_DISC_CMPL_EVT:
1176 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1177 case BTA_DM_DISC_BLE_RES_EVT:
1178 BTIF_TRACE_DEBUG2("%s:, services 0x%x)", __FUNCTION__,
1179 p_data->disc_ble_res.service.uu.uuid16);
1183 if (p_data->disc_ble_res.service.uu.uuid16 == UUID_SERVCLASS_LE_HID)
1185 BTIF_TRACE_DEBUG1("%s: Found HOGP UUID",__FUNCTION__);
1187 bt_bdaddr_t bd_addr;
1191 bta_gatt_convert_uuid16_to_uuid128(uuid.uu,p_data->disc_ble_res.service.uu.uuid16);
1195 unsigned char c = uuid.uu[j];
1196 uuid.uu[j] = uuid.uu[i];
1202 uuid_to_string(&uuid, temp);
1203 BTIF_TRACE_ERROR1(" uuid:%s", temp);
1205 bdcpy(bd_addr.address, p_data->disc_ble_res.bd_addr);
1206 prop.type = BT_PROPERTY_UUIDS;
1208 prop.len = MAX_UUID_SIZE;
1210 /* Also write this to the NVRAM */
1211 ret = btif_storage_set_remote_device_property(&bd_addr, &prop);
1212 ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret);
1214 /* Send the event to the BTIF */
1215 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1216 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1220 #endif /* BLE_INCLUDED */
1224 ASSERTC(0, "unhandled search services event", event);
1230 /*******************************************************************************
1232 ** Function btif_dm_remote_service_record_evt
1234 ** Description Executes search service record event in btif context
1238 *******************************************************************************/
1239 static void btif_dm_remote_service_record_evt(UINT16 event, char *p_param)
1241 tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param;
1243 BTIF_TRACE_EVENT2("%s: event = %d", __FUNCTION__, event);
1246 case BTA_DM_DISC_RES_EVT:
1248 bt_service_record_t rec;
1251 bt_bdaddr_t bd_addr;
1253 memset(&rec, 0, sizeof(bt_service_record_t));
1254 bdcpy(bd_addr.address, p_data->disc_res.bd_addr);
1256 BTIF_TRACE_DEBUG3("%s:(result=0x%x, services 0x%x)", __FUNCTION__,
1257 p_data->disc_res.result, p_data->disc_res.services);
1258 prop.type = BT_PROPERTY_SERVICE_RECORD;
1259 prop.val = (void*)&rec;
1260 prop.len = sizeof(rec);
1262 /* disc_res.result is overloaded with SCN. Cannot check result */
1263 p_data->disc_res.services &= ~BTA_USER_SERVICE_MASK;
1264 /* TODO: Get the UUID as well */
1265 rec.channel = p_data->disc_res.result - 3;
1266 /* TODO: Need to get the service name using p_raw_data */
1269 HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1270 BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1276 ASSERTC(0, "unhandled remote service record event", event);
1282 /*******************************************************************************
1284 ** Function btif_dm_upstreams_cback
1286 ** Description Executes UPSTREAMS events in btif context
1290 *******************************************************************************/
1291 static void btif_dm_upstreams_evt(UINT16 event, char* p_param)
1293 tBTA_DM_SEC_EVT dm_event = (tBTA_DM_SEC_EVT)event;
1294 tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)p_param;
1295 tBTA_SERVICE_MASK service_mask;
1297 bt_bdaddr_t bd_addr;
1299 BTIF_TRACE_EVENT1("btif_dm_upstreams_cback ev: %s", dump_dm_event(event));
1303 case BTA_DM_ENABLE_EVT:
1308 prop.type = BT_PROPERTY_BDNAME;
1309 prop.len = BD_NAME_LEN;
1310 prop.val = (void*)bdname;
1312 status = btif_storage_get_adapter_property(&prop);
1313 if (status == BT_STATUS_SUCCESS)
1315 /* A name exists in the storage. Make this the device name */
1316 BTA_DmSetDeviceName((char*)prop.val);
1320 /* Storage does not have a name yet.
1321 * Use the default name and write it to the chip
1323 BTA_DmSetDeviceName(btif_get_default_local_name());
1326 /* for each of the enabled services in the mask, trigger the profile
1328 service_mask = btif_get_enabled_services_mask();
1329 for (i=0; i <= BTA_MAX_SERVICE_ID; i++)
1332 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i)))
1334 btif_in_execute_service_request(i, TRUE);
1337 /* clear control blocks */
1338 memset(&pairing_cb, 0, sizeof(btif_dm_pairing_cb_t));
1340 /* This function will also trigger the adapter_properties_cb
1341 ** and bonded_devices_info_cb
1343 btif_storage_load_bonded_devices();
1345 btif_storage_load_autopair_device_list();
1347 btif_enable_bluetooth_evt(p_data->enable.status, p_data->enable.bd_addr);
1351 case BTA_DM_DISABLE_EVT:
1352 /* for each of the enabled services in the mask, trigger the profile
1354 service_mask = btif_get_enabled_services_mask();
1355 for (i=0; i <= BTA_MAX_SERVICE_ID; i++)
1358 (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i)))
1360 btif_in_execute_service_request(i, FALSE);
1363 btif_disable_bluetooth_evt();
1366 case BTA_DM_PIN_REQ_EVT:
1367 btif_dm_pin_req_evt(&p_data->pin_req);
1370 case BTA_DM_AUTH_CMPL_EVT:
1371 btif_dm_auth_cmpl_evt(&p_data->auth_cmpl);
1374 case BTA_DM_BOND_CANCEL_CMPL_EVT:
1375 if (pairing_cb.state == BT_BOND_STATE_BONDING)
1377 bdcpy(bd_addr.address, pairing_cb.bd_addr);
1378 bond_state_changed(p_data->bond_cancel_cmpl.result, &bd_addr, BT_BOND_STATE_NONE);
1382 case BTA_DM_SP_CFM_REQ_EVT:
1383 btif_dm_ssp_cfm_req_evt(&p_data->cfm_req);
1385 case BTA_DM_SP_KEY_NOTIF_EVT:
1386 btif_dm_ssp_key_notif_evt(&p_data->key_notif);
1389 case BTA_DM_DEV_UNPAIRED_EVT:
1390 bdcpy(bd_addr.address, p_data->link_down.bd_addr);
1392 /*special handling for HID devices */
1393 #if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE))
1394 btif_hh_remove_device(bd_addr);
1396 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1397 btif_storage_remove_ble_bonding_keys(&bd_addr);
1399 btif_storage_remove_bonded_device(&bd_addr);
1400 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE);
1403 case BTA_DM_BUSY_LEVEL_EVT:
1406 if (p_data->busy_level.level_flags & BTM_BL_INQUIRY_PAGING_MASK)
1408 if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_STARTED)
1410 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb,
1411 BT_DISCOVERY_STARTED);
1412 btif_dm_inquiry_in_progress = TRUE;
1414 else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_CANCELLED)
1416 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb,
1417 BT_DISCOVERY_STOPPED);
1418 btif_dm_inquiry_in_progress = FALSE;
1420 else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_COMPLETE)
1422 btif_dm_inquiry_in_progress = FALSE;
1427 case BTA_DM_LINK_UP_EVT:
1428 bdcpy(bd_addr.address, p_data->link_up.bd_addr);
1429 BTIF_TRACE_DEBUG0("BTA_DM_LINK_UP_EVT. Sending BT_ACL_STATE_CONNECTED");
1431 btif_update_remote_version_property(&bd_addr);
1433 HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS,
1434 &bd_addr, BT_ACL_STATE_CONNECTED);
1437 case BTA_DM_LINK_DOWN_EVT:
1438 bdcpy(bd_addr.address, p_data->link_down.bd_addr);
1439 BTIF_TRACE_DEBUG0("BTA_DM_LINK_DOWN_EVT. Sending BT_ACL_STATE_DISCONNECTED");
1440 HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS,
1441 &bd_addr, BT_ACL_STATE_DISCONNECTED);
1444 case BTA_DM_HW_ERROR_EVT:
1445 BTIF_TRACE_ERROR0("Received H/W Error. ");
1446 /* Flush storage data */
1447 btif_config_flush();
1448 usleep(100000); /* 100milliseconds */
1449 /* Killing the process to force a restart as part of fault tolerance */
1450 kill(getpid(), SIGKILL);
1453 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1454 case BTA_DM_BLE_KEY_EVT:
1455 BTIF_TRACE_DEBUG1("BTA_DM_BLE_KEY_EVT key_type=0x%02x ", p_data->ble_key.key_type);
1457 /* If this pairing is by-product of local initiated GATT client Read or Write,
1458 BTA would not have sent BTA_DM_BLE_SEC_REQ_EVT event and Bond state would not
1459 have setup properly. Setup pairing_cb and notify App about Bonding state now*/
1460 if (pairing_cb.state != BT_BOND_STATE_BONDING)
1462 BTIF_TRACE_DEBUG0("Bond state not sent to App so far.Notify the app now");
1463 bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t*)p_data->ble_key.bd_addr,
1464 BT_BOND_STATE_BONDING);
1466 else if (memcmp (pairing_cb.bd_addr, p_data->ble_key.bd_addr, BD_ADDR_LEN)!=0)
1468 BTIF_TRACE_ERROR1("BD mismatch discard BLE key_type=%d ",p_data->ble_key.key_type);
1472 switch (p_data->ble_key.key_type)
1474 case BTA_LE_KEY_PENC:
1475 BTIF_TRACE_DEBUG0("Rcv BTA_LE_KEY_PENC");
1476 pairing_cb.ble.is_penc_key_rcvd = TRUE;
1477 memcpy(pairing_cb.ble.penc_key.ltk,p_data->ble_key.key_value.penc_key.ltk, 16);
1478 memcpy(pairing_cb.ble.penc_key.rand, p_data->ble_key.key_value.penc_key.rand,8);
1479 pairing_cb.ble.penc_key.ediv = p_data->ble_key.key_value.penc_key.ediv;
1480 pairing_cb.ble.penc_key.sec_level = p_data->ble_key.key_value.penc_key.sec_level;
1482 for (i=0; i<16; i++)
1484 BTIF_TRACE_DEBUG2("pairing_cb.ble.penc_key.ltk[%d]=0x%02x",i,pairing_cb.ble.penc_key.ltk[i]);
1488 BTIF_TRACE_DEBUG2("pairing_cb.ble.penc_key.rand[%d]=0x%02x",i,pairing_cb.ble.penc_key.rand[i]);
1490 BTIF_TRACE_DEBUG1("pairing_cb.ble.penc_key.ediv=0x%04x",pairing_cb.ble.penc_key.ediv);
1491 BTIF_TRACE_DEBUG1("pairing_cb.ble.penc_key.sec_level=0x%02x",pairing_cb.ble.penc_key.sec_level);
1492 BTIF_TRACE_DEBUG1("pairing_cb.ble.penc_key.key_size=0x%02x",pairing_cb.ble.penc_key.key_size);
1495 case BTA_LE_KEY_PID:
1496 BTIF_TRACE_DEBUG0("Rcv BTA_LE_KEY_PID");
1497 pairing_cb.ble.is_pid_key_rcvd = TRUE;
1498 memcpy(pairing_cb.ble.pid_key, p_data->ble_key.key_value.pid_key.irk, 16);
1499 for (i=0; i<16; i++)
1501 BTIF_TRACE_DEBUG2("pairing_cb.ble.pid_key[%d]=0x%02x",i,pairing_cb.ble.pid_key[i]);
1505 case BTA_LE_KEY_PCSRK:
1506 BTIF_TRACE_DEBUG0("Rcv BTA_LE_KEY_PCSRK");
1507 pairing_cb.ble.is_pcsrk_key_rcvd = TRUE;
1508 pairing_cb.ble.pcsrk_key.counter = p_data->ble_key.key_value.pcsrk_key.counter;
1509 pairing_cb.ble.pcsrk_key.sec_level = p_data->ble_key.key_value.pcsrk_key.sec_level;
1510 memcpy(pairing_cb.ble.pcsrk_key.csrk,p_data->ble_key.key_value.pcsrk_key.csrk,16);
1512 for (i=0; i<16; i++)
1514 BTIF_TRACE_DEBUG2("pairing_cb.ble.pcsrk_key.csrk[%d]=0x%02x",i,pairing_cb.ble.pcsrk_key.csrk[i]);
1516 BTIF_TRACE_DEBUG1("pairing_cb.ble.pcsrk_key.counter=0x%08x",pairing_cb.ble.pcsrk_key.counter);
1517 BTIF_TRACE_DEBUG1("pairing_cb.ble.pcsrk_key.sec_level=0x%02x",pairing_cb.ble.pcsrk_key.sec_level);
1520 case BTA_LE_KEY_LENC:
1521 BTIF_TRACE_DEBUG0("Rcv BTA_LE_KEY_LENC");
1522 pairing_cb.ble.is_lenc_key_rcvd = TRUE;
1523 pairing_cb.ble.lenc_key.div = p_data->ble_key.key_value.lenc_key.div;
1524 pairing_cb.ble.lenc_key.key_size = p_data->ble_key.key_value.lenc_key.key_size;
1525 pairing_cb.ble.lenc_key.sec_level = p_data->ble_key.key_value.lenc_key.sec_level;
1527 BTIF_TRACE_DEBUG1("pairing_cb.ble.lenc_key.div=0x%04x",pairing_cb.ble.lenc_key.div);
1528 BTIF_TRACE_DEBUG1("pairing_cb.ble.lenc_key.key_size=0x%02x",pairing_cb.ble.lenc_key.key_size);
1529 BTIF_TRACE_DEBUG1("pairing_cb.ble.lenc_key.sec_level=0x%02x",pairing_cb.ble.lenc_key.sec_level);
1534 case BTA_LE_KEY_LCSRK:
1535 BTIF_TRACE_DEBUG0("Rcv BTA_LE_KEY_LCSRK");
1536 pairing_cb.ble.is_lcsrk_key_rcvd = TRUE;
1537 pairing_cb.ble.lcsrk_key.counter = p_data->ble_key.key_value.lcsrk_key.counter;
1538 pairing_cb.ble.lcsrk_key.div = p_data->ble_key.key_value.lcsrk_key.div;
1539 pairing_cb.ble.lcsrk_key.sec_level = p_data->ble_key.key_value.lcsrk_key.sec_level;
1541 BTIF_TRACE_DEBUG1("pairing_cb.ble.lcsrk_key.div=0x%04x",pairing_cb.ble.lcsrk_key.div);
1542 BTIF_TRACE_DEBUG1("pairing_cb.ble.lcsrk_key.counter=0x%08x",pairing_cb.ble.lcsrk_key.counter);
1543 BTIF_TRACE_DEBUG1("pairing_cb.ble.lcsrk_key.sec_level=0x%02x",pairing_cb.ble.lcsrk_key.sec_level);
1548 BTIF_TRACE_ERROR1("unknown BLE key type (0x%02x)", p_data->ble_key.key_type);
1553 case BTA_DM_BLE_SEC_REQ_EVT:
1554 BTIF_TRACE_DEBUG0("BTA_DM_BLE_SEC_REQ_EVT. ");
1555 btif_dm_ble_sec_req_evt(&p_data->ble_req);
1557 case BTA_DM_BLE_PASSKEY_NOTIF_EVT:
1558 BTIF_TRACE_DEBUG0("BTA_DM_BLE_PASSKEY_NOTIF_EVT. ");
1559 btif_dm_ble_key_notif_evt(&p_data->key_notif);
1561 case BTA_DM_BLE_PASSKEY_REQ_EVT:
1562 BTIF_TRACE_DEBUG0("BTA_DM_BLE_PASSKEY_REQ_EVT. ");
1563 btif_dm_ble_passkey_req_evt(&p_data->pin_req);
1565 case BTA_DM_BLE_OOB_REQ_EVT:
1566 BTIF_TRACE_DEBUG0("BTA_DM_BLE_OOB_REQ_EVT. ");
1568 case BTA_DM_BLE_LOCAL_IR_EVT:
1569 BTIF_TRACE_DEBUG0("BTA_DM_BLE_LOCAL_IR_EVT. ");
1570 ble_local_key_cb.is_id_keys_rcvd = TRUE;
1571 memcpy(&ble_local_key_cb.id_keys.irk[0], &p_data->ble_id_keys.irk[0], sizeof(BT_OCTET16));
1572 memcpy(&ble_local_key_cb.id_keys.ir[0], &p_data->ble_id_keys.ir[0], sizeof(BT_OCTET16));
1573 memcpy(&ble_local_key_cb.id_keys.dhk[0], &p_data->ble_id_keys.dhk[0], sizeof(BT_OCTET16));
1574 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.irk[0],
1575 BTIF_DM_LE_LOCAL_KEY_IR,
1577 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.ir[0],
1578 BTIF_DM_LE_LOCAL_KEY_IRK,
1580 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.dhk[0],
1581 BTIF_DM_LE_LOCAL_KEY_DHK,
1584 case BTA_DM_BLE_LOCAL_ER_EVT:
1585 BTIF_TRACE_DEBUG0("BTA_DM_BLE_LOCAL_ER_EVT. ");
1586 ble_local_key_cb.is_er_rcvd = TRUE;
1587 memcpy(&ble_local_key_cb.er[0], &p_data->ble_er[0], sizeof(BT_OCTET16));
1588 btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.er[0],
1589 BTIF_DM_LE_LOCAL_KEY_ER,
1593 case BTA_DM_BLE_AUTH_CMPL_EVT:
1594 BTIF_TRACE_DEBUG0("BTA_DM_BLE_KEY_EVT. ");
1595 btif_dm_ble_auth_cmpl_evt(&p_data->auth_cmpl);
1599 case BTA_DM_AUTHORIZE_EVT:
1600 case BTA_DM_SIG_STRENGTH_EVT:
1601 case BTA_DM_SP_RMT_OOB_EVT:
1602 case BTA_DM_SP_KEYPRESS_EVT:
1603 case BTA_DM_ROLE_CHG_EVT:
1606 BTIF_TRACE_WARNING1( "btif_dm_cback : unhandled event (%d)", event );
1609 } /* btui_security_cback() */
1612 /*******************************************************************************
1614 ** Function btif_dm_generic_evt
1616 ** Description Executes non-BTA upstream events in BTIF context
1620 *******************************************************************************/
1621 static void btif_dm_generic_evt(UINT16 event, char* p_param)
1623 BTIF_TRACE_EVENT2("%s: event=%d", __FUNCTION__, event);
1626 case BTIF_DM_CB_DISCOVERY_STARTED:
1628 HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STARTED);
1632 case BTIF_DM_CB_CREATE_BOND:
1634 btif_dm_cb_create_bond((bt_bdaddr_t *)p_param);
1638 case BTIF_DM_CB_REMOVE_BOND:
1640 btif_dm_cb_remove_bond((bt_bdaddr_t *)p_param);
1644 case BTIF_DM_CB_HID_REMOTE_NAME:
1646 btif_dm_cb_hid_remote_name((tBTM_REMOTE_DEV_NAME *)p_param);
1650 case BTIF_DM_CB_BOND_STATE_BONDING:
1652 bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t *)p_param, BT_BOND_STATE_BONDING);
1655 case BTIF_DM_CB_LE_TX_TEST:
1656 case BTIF_DM_CB_LE_RX_TEST:
1659 STREAM_TO_UINT8(status, p_param);
1660 HAL_CBACK(bt_hal_cbacks, le_test_mode_cb,
1661 (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, 0);
1664 case BTIF_DM_CB_LE_TEST_END:
1668 STREAM_TO_UINT8(status, p_param);
1670 STREAM_TO_UINT16(count, p_param);
1671 HAL_CBACK(bt_hal_cbacks, le_test_mode_cb,
1672 (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, count);
1677 BTIF_TRACE_WARNING2("%s : Unknown event 0x%x", __FUNCTION__, event);
1683 /*******************************************************************************
1685 ** Function bte_dm_evt
1687 ** Description Switches context from BTE to BTIF for all DM events
1691 *******************************************************************************/
1693 void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data)
1697 /* switch context to btif task context (copy full union size for convenience) */
1698 status = btif_transfer_context(btif_dm_upstreams_evt, (uint16_t)event, (void*)p_data, sizeof(tBTA_DM_SEC), NULL);
1700 /* catch any failed context transfers */
1701 ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status);
1704 /*******************************************************************************
1706 ** Function bte_search_devices_evt
1708 ** Description Switches context from BTE to BTIF for DM search events
1712 *******************************************************************************/
1713 static void bte_search_devices_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
1715 UINT16 param_len = 0;
1718 param_len += sizeof(tBTA_DM_SEARCH);
1719 /* Allocate buffer to hold the pointers (deep copy). The pointers will point to the end of the tBTA_DM_SEARCH */
1722 case BTA_DM_INQ_RES_EVT:
1724 if (p_data->inq_res.p_eir)
1725 param_len += HCI_EXT_INQ_RESPONSE_LEN;
1729 case BTA_DM_DISC_RES_EVT:
1731 if (p_data->disc_res.raw_data_size && p_data->disc_res.p_raw_data)
1732 param_len += p_data->disc_res.raw_data_size;
1736 BTIF_TRACE_DEBUG3("%s event=%s param_len=%d", __FUNCTION__, dump_dm_search_event(event), param_len);
1738 /* if remote name is available in EIR, set teh flag so that stack doesnt trigger RNR */
1739 if (event == BTA_DM_INQ_RES_EVT)
1740 p_data->inq_res.remt_name_not_required = check_eir_remote_name(p_data, NULL, NULL);
1742 btif_transfer_context (btif_dm_search_devices_evt , (UINT16) event, (void *)p_data, param_len,
1743 (param_len > sizeof(tBTA_DM_SEARCH)) ? search_devices_copy_cb : NULL);
1746 /*******************************************************************************
1748 ** Function bte_dm_search_services_evt
1750 ** Description Switches context from BTE to BTIF for DM search services
1755 *******************************************************************************/
1756 static void bte_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
1758 UINT16 param_len = 0;
1760 param_len += sizeof(tBTA_DM_SEARCH);
1763 case BTA_DM_DISC_RES_EVT:
1765 if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0)) {
1766 param_len += (p_data->disc_res.num_uuids * MAX_UUID_SIZE);
1770 /* TODO: The only other member that needs a deep copy is the p_raw_data. But not sure
1771 * if raw_data is needed. */
1772 btif_transfer_context(btif_dm_search_services_evt, event, (char*)p_data, param_len,
1773 (param_len > sizeof(tBTA_DM_SEARCH)) ? search_services_copy_cb : NULL);
1776 /*******************************************************************************
1778 ** Function bte_dm_remote_service_record_evt
1780 ** Description Switches context from BTE to BTIF for DM search service
1785 *******************************************************************************/
1786 static void bte_dm_remote_service_record_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
1788 /* TODO: The only member that needs a deep copy is the p_raw_data. But not sure yet if this is needed. */
1789 btif_transfer_context(btif_dm_remote_service_record_evt, event, (char*)p_data, sizeof(tBTA_DM_SEARCH), NULL);
1792 /*****************************************************************************
1794 ** btif api functions (no context switch)
1796 *****************************************************************************/
1798 /*******************************************************************************
1800 ** Function btif_dm_start_discovery
1802 ** Description Start device discovery/inquiry
1804 ** Returns bt_status_t
1806 *******************************************************************************/
1807 bt_status_t btif_dm_start_discovery(void)
1809 tBTA_DM_INQ inq_params;
1810 tBTA_SERVICE_MASK services = 0;
1812 BTIF_TRACE_EVENT1("%s", __FUNCTION__);
1813 /* TODO: Do we need to handle multiple inquiries at the same time? */
1815 /* Set inquiry params and call API */
1816 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1817 inq_params.mode = BTA_DM_GENERAL_INQUIRY|BTA_BLE_GENERAL_INQUIRY;
1818 #if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE)
1819 inq_params.intl_duration[0]= BTIF_DM_INTERLEAVE_DURATION_BR_ONE;
1820 inq_params.intl_duration[1]= BTIF_DM_INTERLEAVE_DURATION_LE_ONE;
1821 inq_params.intl_duration[2]= BTIF_DM_INTERLEAVE_DURATION_BR_TWO;
1822 inq_params.intl_duration[3]= BTIF_DM_INTERLEAVE_DURATION_LE_TWO;
1825 inq_params.mode = BTA_DM_GENERAL_INQUIRY;
1827 inq_params.duration = BTIF_DM_DEFAULT_INQ_MAX_DURATION;
1829 inq_params.max_resps = BTIF_DM_DEFAULT_INQ_MAX_RESULTS;
1830 inq_params.report_dup = TRUE;
1832 inq_params.filter_type = BTA_DM_INQ_CLR;
1833 /* TODO: Filter device by BDA needs to be implemented here */
1835 /* Will be enabled to TRUE once inquiry busy level has been received */
1836 btif_dm_inquiry_in_progress = FALSE;
1837 /* find nearby devices */
1838 BTA_DmSearch(&inq_params, services, bte_search_devices_evt);
1840 return BT_STATUS_SUCCESS;
1843 /*******************************************************************************
1845 ** Function btif_dm_cancel_discovery
1847 ** Description Cancels search
1849 ** Returns bt_status_t
1851 *******************************************************************************/
1852 bt_status_t btif_dm_cancel_discovery(void)
1854 BTIF_TRACE_EVENT1("%s", __FUNCTION__);
1855 BTA_DmSearchCancel();
1856 return BT_STATUS_SUCCESS;
1859 /*******************************************************************************
1861 ** Function btif_dm_create_bond
1863 ** Description Initiate bonding with the specified device
1865 ** Returns bt_status_t
1867 *******************************************************************************/
1868 bt_status_t btif_dm_create_bond(const bt_bdaddr_t *bd_addr)
1872 BTIF_TRACE_EVENT2("%s: bd_addr=%s", __FUNCTION__, bd2str((bt_bdaddr_t *) bd_addr, &bdstr));
1873 if (pairing_cb.state != BT_BOND_STATE_NONE)
1874 return BT_STATUS_BUSY;
1876 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_CREATE_BOND,
1877 (char *)bd_addr, sizeof(bt_bdaddr_t), NULL);
1879 return BT_STATUS_SUCCESS;
1882 /*******************************************************************************
1884 ** Function btif_dm_cancel_bond
1886 ** Description Initiate bonding with the specified device
1888 ** Returns bt_status_t
1890 *******************************************************************************/
1892 bt_status_t btif_dm_cancel_bond(const bt_bdaddr_t *bd_addr)
1896 BTIF_TRACE_EVENT2("%s: bd_addr=%s", __FUNCTION__, bd2str((bt_bdaddr_t *)bd_addr, &bdstr));
1899 ** 1. Restore scan modes
1900 ** 2. special handling for HID devices
1902 if (pairing_cb.state == BT_BOND_STATE_BONDING)
1905 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
1907 if (pairing_cb.is_ssp)
1909 if (pairing_cb.is_le_only)
1911 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT);
1914 BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE);
1918 if (pairing_cb.is_le_only)
1920 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
1924 BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL);
1926 /* Cancel bonding, in case it is in ACL connection setup state */
1927 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
1931 if (pairing_cb.is_ssp)
1933 BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE);
1937 BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL);
1939 /* Cancel bonding, in case it is in ACL connection setup state */
1940 BTA_DmBondCancel ((UINT8 *)bd_addr->address);
1941 btif_storage_remove_bonded_device((bt_bdaddr_t *)bd_addr);
1945 return BT_STATUS_SUCCESS;
1948 /*******************************************************************************
1950 ** Function btif_dm_hh_open_failed
1952 ** Description informs the upper layers if the HH have failed during bonding
1956 *******************************************************************************/
1958 void btif_dm_hh_open_failed(bt_bdaddr_t *bdaddr)
1960 if (pairing_cb.state == BT_BOND_STATE_BONDING &&
1961 bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0)
1963 bond_state_changed(BT_STATUS_FAIL, bdaddr, BT_BOND_STATE_NONE);
1967 /*******************************************************************************
1969 ** Function btif_dm_remove_bond
1971 ** Description Removes bonding with the specified device
1973 ** Returns bt_status_t
1975 *******************************************************************************/
1977 bt_status_t btif_dm_remove_bond(const bt_bdaddr_t *bd_addr)
1981 BTIF_TRACE_EVENT2("%s: bd_addr=%s", __FUNCTION__, bd2str((bt_bdaddr_t *)bd_addr, &bdstr));
1982 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_REMOVE_BOND,
1983 (char *)bd_addr, sizeof(bt_bdaddr_t), NULL);
1985 return BT_STATUS_SUCCESS;
1988 /*******************************************************************************
1990 ** Function btif_dm_pin_reply
1992 ** Description BT legacy pairing - PIN code reply
1994 ** Returns bt_status_t
1996 *******************************************************************************/
1998 bt_status_t btif_dm_pin_reply( const bt_bdaddr_t *bd_addr, uint8_t accept,
1999 uint8_t pin_len, bt_pin_code_t *pin_code)
2001 BTIF_TRACE_EVENT2("%s: accept=%d", __FUNCTION__, accept);
2002 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2004 if (pairing_cb.is_le_only)
2008 int multi[] = {100000, 10000, 1000, 100, 10,1};
2009 BD_ADDR remote_bd_addr;
2010 bdcpy(remote_bd_addr, bd_addr->address);
2011 for (i = 0; i < 6; i++)
2013 passkey += (multi[i] * (pin_code->pin[i] - '0'));
2015 BTIF_TRACE_DEBUG1("btif_dm_pin_reply: passkey: %d", passkey);
2016 BTA_DmBlePasskeyReply(remote_bd_addr, accept, passkey);
2021 BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin);
2023 pairing_cb.pin_code_len = pin_len;
2026 BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin);
2029 pairing_cb.pin_code_len = pin_len;
2031 return BT_STATUS_SUCCESS;
2034 /*******************************************************************************
2036 ** Function btif_dm_ssp_reply
2038 ** Description BT SSP Reply - Just Works, Numeric Comparison & Passkey Entry
2040 ** Returns bt_status_t
2042 *******************************************************************************/
2043 bt_status_t btif_dm_ssp_reply(const bt_bdaddr_t *bd_addr,
2044 bt_ssp_variant_t variant, uint8_t accept,
2049 if (variant == BT_SSP_VARIANT_PASSKEY_ENTRY)
2051 /* This is not implemented in the stack.
2052 * For devices with display, this is not needed
2054 BTIF_TRACE_WARNING1("%s: Not implemented", __FUNCTION__);
2055 return BT_STATUS_FAIL;
2057 /* BT_SSP_VARIANT_CONSENT & BT_SSP_VARIANT_PASSKEY_CONFIRMATION supported */
2058 BTIF_TRACE_EVENT2("%s: accept=%d", __FUNCTION__, accept);
2059 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2060 if (pairing_cb.is_le_only)
2063 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_GRANTED);
2065 BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT);
2068 BTA_DmConfirm( (UINT8 *)bd_addr->address, accept);
2071 BTA_DmConfirm( (UINT8 *)bd_addr->address, accept);
2073 return BT_STATUS_SUCCESS;
2076 /*******************************************************************************
2078 ** Function btif_dm_get_adapter_property
2080 ** Description Queries the BTA for the adapter property
2082 ** Returns bt_status_t
2084 *******************************************************************************/
2085 bt_status_t btif_dm_get_adapter_property(bt_property_t *prop)
2089 BTIF_TRACE_EVENT2("%s: type=0x%x", __FUNCTION__, prop->type);
2092 case BT_PROPERTY_BDNAME:
2094 bt_bdname_t *bd_name = (bt_bdname_t*)prop->val;
2095 strcpy((char *)bd_name->name, btif_get_default_local_name());
2096 prop->len = strlen((char *)bd_name->name);
2100 case BT_PROPERTY_ADAPTER_SCAN_MODE:
2102 /* if the storage does not have it. Most likely app never set it. Default is NONE */
2103 bt_scan_mode_t *mode = (bt_scan_mode_t*)prop->val;
2104 *mode = BT_SCAN_MODE_NONE;
2105 prop->len = sizeof(bt_scan_mode_t);
2109 case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT:
2111 uint32_t *tmt = (uint32_t*)prop->val;
2112 *tmt = 120; /* default to 120s, if not found in NV */
2113 prop->len = sizeof(uint32_t);
2119 return BT_STATUS_FAIL;
2121 return BT_STATUS_SUCCESS;
2124 /*******************************************************************************
2126 ** Function btif_dm_get_remote_services
2128 ** Description Start SDP to get remote services
2130 ** Returns bt_status_t
2132 *******************************************************************************/
2133 bt_status_t btif_dm_get_remote_services(bt_bdaddr_t *remote_addr)
2137 BTIF_TRACE_EVENT2("%s: remote_addr=%s", __FUNCTION__, bd2str(remote_addr, &bdstr));
2139 BTA_DmDiscover(remote_addr->address, BTA_ALL_SERVICE_MASK,
2140 bte_dm_search_services_evt, TRUE);
2142 return BT_STATUS_SUCCESS;
2145 /*******************************************************************************
2147 ** Function btif_dm_get_remote_service_record
2149 ** Description Start SDP to get remote service record
2152 ** Returns bt_status_t
2153 *******************************************************************************/
2154 bt_status_t btif_dm_get_remote_service_record(bt_bdaddr_t *remote_addr,
2160 BTIF_TRACE_EVENT2("%s: remote_addr=%s", __FUNCTION__, bd2str(remote_addr, &bdstr));
2162 sdp_uuid.len = MAX_UUID_SIZE;
2163 memcpy(sdp_uuid.uu.uuid128, uuid->uu, MAX_UUID_SIZE);
2165 BTA_DmDiscoverUUID(remote_addr->address, &sdp_uuid,
2166 bte_dm_remote_service_record_evt, TRUE);
2168 return BT_STATUS_SUCCESS;
2171 void btif_dm_execute_service_request(UINT16 event, char *p_param)
2173 BOOLEAN b_enable = FALSE;
2175 if (event == BTIF_DM_ENABLE_SERVICE)
2179 status = btif_in_execute_service_request(*((tBTA_SERVICE_ID*)p_param), b_enable);
2180 if (status == BT_STATUS_SUCCESS)
2182 bt_property_t property;
2183 bt_uuid_t local_uuids[BT_MAX_NUM_UUIDS];
2185 /* Now send the UUID_PROPERTY_CHANGED event to the upper layer */
2186 BTIF_STORAGE_FILL_PROPERTY(&property, BT_PROPERTY_UUIDS,
2187 sizeof(local_uuids), local_uuids);
2188 btif_storage_get_adapter_property(&property);
2189 HAL_CBACK(bt_hal_cbacks, adapter_properties_cb,
2190 BT_STATUS_SUCCESS, 1, &property);
2195 #if (BTM_OOB_INCLUDED == TRUE)
2196 void btif_dm_set_oob_for_io_req(tBTA_OOB_DATA *p_oob_data)
2198 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2199 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
2201 *p_oob_data = FALSE;
2207 BTIF_TRACE_DEBUG1("btif_dm_set_oob_for_io_req *p_oob_data=%d", *p_oob_data);
2209 #endif /* BTM_OOB_INCLUDED */
2211 #ifdef BTIF_DM_OOB_TEST
2212 void btif_dm_load_local_oob(void)
2214 char prop_oob[PROPERTY_VALUE_MAX];
2215 property_get("service.brcm.bt.oob", prop_oob, "3");
2216 BTIF_TRACE_DEBUG1("btif_dm_load_local_oob prop_oob = %s",prop_oob);
2217 if (prop_oob[0] != '3')
2219 #if (BTM_OOB_INCLUDED == TRUE)
2220 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2221 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 )
2223 BTIF_TRACE_DEBUG0("btif_dm_load_local_oob: read OOB, call BTA_DmLocalOob()");
2227 BTIF_TRACE_ERROR0("BTM_OOB_INCLUDED is FALSE!!(btif_dm_load_local_oob)");
2232 void btif_dm_proc_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r)
2235 char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
2236 char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
2238 char prop_oob[PROPERTY_VALUE_MAX];
2239 BTIF_TRACE_DEBUG1("btif_dm_proc_loc_oob: valid=%d", valid);
2240 if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 &&
2241 oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 &&
2244 BTIF_TRACE_DEBUG0("save local OOB data in memory");
2245 memcpy(oob_cb.sp_c, c, BT_OCTET16_LEN);
2246 memcpy(oob_cb.sp_r, r, BT_OCTET16_LEN);
2247 property_get("service.brcm.bt.oob", prop_oob, "3");
2248 BTIF_TRACE_DEBUG1("btif_dm_proc_loc_oob prop_oob = %s",prop_oob);
2249 if (prop_oob[0] == '1')
2251 else if (prop_oob[0] == '2')
2255 fp = fopen(path, "wb+");
2258 BTIF_TRACE_DEBUG1("btif_dm_proc_loc_oob: failed to save local OOB data to %s", path);
2262 BTIF_TRACE_DEBUG1("btif_dm_proc_loc_oob: save local OOB data into file %s",path);
2263 fwrite (c , 1 , BT_OCTET16_LEN , fp );
2264 fwrite (r , 1 , BT_OCTET16_LEN , fp );
2270 BOOLEAN btif_dm_proc_rmt_oob(BD_ADDR bd_addr, BT_OCTET16 p_c, BT_OCTET16 p_r)
2274 char *path_a = "/data/misc/bluedroid/LOCAL/a.key";
2275 char *path_b = "/data/misc/bluedroid/LOCAL/b.key";
2277 char prop_oob[PROPERTY_VALUE_MAX];
2278 BOOLEAN result = FALSE;
2279 bt_bdaddr_t bt_bd_addr;
2280 bdcpy(oob_cb.oob_bdaddr, bd_addr);
2281 property_get("service.brcm.bt.oob", prop_oob, "3");
2282 BTIF_TRACE_DEBUG1("btif_dm_proc_rmt_oob prop_oob = %s",prop_oob);
2283 if (prop_oob[0] == '1')
2285 else if (prop_oob[0] == '2')
2289 fp = fopen(path, "rb");
2292 BTIF_TRACE_DEBUG1("btapp_dm_rmt_oob_reply: failed to read OOB keys from %s",path);
2297 BTIF_TRACE_DEBUG1("btif_dm_proc_rmt_oob: read OOB data from %s",path);
2298 fread (p_c , 1 , BT_OCTET16_LEN , fp );
2299 fread (p_r , 1 , BT_OCTET16_LEN , fp );
2302 BTIF_TRACE_DEBUG0("----btif_dm_proc_rmt_oob: TRUE");
2303 sprintf(t, "%02x:%02x:%02x:%02x:%02x:%02x",
2304 oob_cb.oob_bdaddr[0], oob_cb.oob_bdaddr[1], oob_cb.oob_bdaddr[2],
2305 oob_cb.oob_bdaddr[3], oob_cb.oob_bdaddr[4], oob_cb.oob_bdaddr[5]);
2306 BTIF_TRACE_DEBUG1("----btif_dm_proc_rmt_oob: peer_bdaddr = %s", t);
2307 sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
2308 p_c[0], p_c[1], p_c[2], p_c[3], p_c[4], p_c[5], p_c[6], p_c[7],
2309 p_c[8], p_c[9], p_c[10], p_c[11], p_c[12], p_c[13], p_c[14], p_c[15]);
2310 BTIF_TRACE_DEBUG1("----btif_dm_proc_rmt_oob: c = %s",t);
2311 sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
2312 p_r[0], p_r[1], p_r[2], p_r[3], p_r[4], p_r[5], p_r[6], p_r[7],
2313 p_r[8], p_r[9], p_r[10], p_r[11], p_r[12], p_r[13], p_r[14], p_r[15]);
2314 BTIF_TRACE_DEBUG1("----btif_dm_proc_rmt_oob: r = %s",t);
2315 bdcpy(bt_bd_addr.address, bd_addr);
2316 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_BOND_STATE_BONDING,
2317 (char *)&bt_bd_addr, sizeof(bt_bdaddr_t), NULL);
2320 BTIF_TRACE_DEBUG1("btif_dm_proc_rmt_oob result=%d",result);
2323 #endif /* BTIF_DM_OOB_TEST */
2324 #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
2326 static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif)
2328 bt_bdaddr_t bd_addr;
2329 bt_bdname_t bd_name;
2332 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
2334 /* Remote name update */
2335 btif_update_remote_properties(p_ssp_key_notif->bd_addr , p_ssp_key_notif->bd_name,
2336 NULL, BT_DEVICE_TYPE_BLE);
2337 bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr);
2338 memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN);
2340 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
2341 pairing_cb.is_ssp = FALSE;
2342 cod = COD_UNCLASSIFIED;
2344 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name,
2345 cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION,
2346 p_ssp_key_notif->passkey);
2349 /*******************************************************************************
2351 ** Function btif_dm_ble_auth_cmpl_evt
2353 ** Description Executes authentication complete event in btif context
2357 *******************************************************************************/
2358 static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
2360 /* Save link key, if not temporary */
2361 bt_bdaddr_t bd_addr;
2362 bt_status_t status = BT_STATUS_FAIL;
2363 bt_bond_state_t state = BT_BOND_STATE_NONE;
2365 bdcpy(bd_addr.address, p_auth_cmpl->bd_addr);
2366 if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) )
2370 if (p_auth_cmpl->success)
2372 status = BT_STATUS_SUCCESS;
2373 state = BT_BOND_STATE_BONDED;
2375 btif_dm_save_ble_bonding_keys();
2376 BTA_GATTC_Refresh(bd_addr.address);
2377 btif_dm_get_remote_services(&bd_addr);
2381 /*Map the HCI fail reason to bt status */
2382 switch (p_auth_cmpl->fail_reason)
2385 btif_dm_remove_ble_bonding_keys();
2386 status = BT_STATUS_FAIL;
2390 bond_state_changed(status, &bd_addr, state);
2395 void btif_dm_load_ble_local_keys(void)
2397 bt_status_t bt_status;
2399 memset(&ble_local_key_cb, 0, sizeof(btif_dm_local_key_cb_t));
2401 if (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_ER,(char*)&ble_local_key_cb.er[0],
2402 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)
2404 ble_local_key_cb.is_er_rcvd = TRUE;
2405 BTIF_TRACE_DEBUG1("%s BLE ER key loaded",__FUNCTION__ );
2408 if ((btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IR,(char*)&ble_local_key_cb.id_keys.ir[0],
2409 BT_OCTET16_LEN)== BT_STATUS_SUCCESS )&&
2410 (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IRK, (char*)&ble_local_key_cb.id_keys.irk[0],
2411 BT_OCTET16_LEN)== BT_STATUS_SUCCESS)&&
2412 (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_DHK,(char*)&ble_local_key_cb.id_keys.dhk[0],
2413 BT_OCTET16_LEN)== BT_STATUS_SUCCESS))
2415 ble_local_key_cb.is_id_keys_rcvd = TRUE;
2416 BTIF_TRACE_DEBUG1("%s BLE ID keys loaded",__FUNCTION__ );
2420 void btif_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er,
2421 tBTA_BLE_LOCAL_ID_KEYS *p_id_keys)
2423 if (ble_local_key_cb.is_er_rcvd )
2425 memcpy(&er[0], &ble_local_key_cb.er[0], sizeof(BT_OCTET16));
2426 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ER;
2429 if (ble_local_key_cb.is_id_keys_rcvd)
2431 memcpy(&p_id_keys->ir[0], &ble_local_key_cb.id_keys.ir[0], sizeof(BT_OCTET16));
2432 memcpy(&p_id_keys->irk[0], &ble_local_key_cb.id_keys.irk[0], sizeof(BT_OCTET16));
2433 memcpy(&p_id_keys->dhk[0], &ble_local_key_cb.id_keys.dhk[0], sizeof(BT_OCTET16));
2434 *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID;
2436 BTIF_TRACE_DEBUG2("%s *p_key_mask=0x%02x",__FUNCTION__, *p_key_mask);
2439 void btif_dm_save_ble_bonding_keys(void)
2442 bt_bdaddr_t bd_addr;
2444 BTIF_TRACE_DEBUG1("%s",__FUNCTION__ );
2446 bdcpy(bd_addr.address, pairing_cb.bd_addr);
2448 if (pairing_cb.ble.is_penc_key_rcvd)
2450 btif_storage_add_ble_bonding_key(&bd_addr,
2451 (char *) &pairing_cb.ble.penc_key,
2452 BTIF_DM_LE_KEY_PENC,
2453 sizeof(btif_dm_ble_penc_keys_t));
2456 if (pairing_cb.ble.is_pid_key_rcvd)
2458 btif_storage_add_ble_bonding_key(&bd_addr,
2459 (char *) &pairing_cb.ble.pid_key[0],
2465 if (pairing_cb.ble.is_pcsrk_key_rcvd)
2467 btif_storage_add_ble_bonding_key(&bd_addr,
2468 (char *) &pairing_cb.ble.pcsrk_key,
2469 BTIF_DM_LE_KEY_PCSRK,
2470 sizeof(btif_dm_ble_pcsrk_keys_t));
2474 if (pairing_cb.ble.is_lenc_key_rcvd)
2476 btif_storage_add_ble_bonding_key(&bd_addr,
2477 (char *) &pairing_cb.ble.lenc_key,
2478 BTIF_DM_LE_KEY_LENC,
2479 sizeof(btif_dm_ble_lenc_keys_t));
2482 if (pairing_cb.ble.is_lcsrk_key_rcvd)
2484 btif_storage_add_ble_bonding_key(&bd_addr,
2485 (char *) &pairing_cb.ble.lcsrk_key,
2486 BTIF_DM_LE_KEY_LCSRK,
2487 sizeof(btif_dm_ble_lcsrk_keys_t));
2493 void btif_dm_remove_ble_bonding_keys(void)
2495 bt_bdaddr_t bd_addr;
2497 BTIF_TRACE_DEBUG1("%s",__FUNCTION__ );
2499 bdcpy(bd_addr.address, pairing_cb.bd_addr);
2500 btif_storage_remove_ble_bonding_keys(&bd_addr);
2504 /*******************************************************************************
2506 ** Function btif_dm_ble_sec_req_evt
2508 ** Description Eprocess security request event in btif context
2512 *******************************************************************************/
2513 void btif_dm_ble_sec_req_evt(tBTA_DM_BLE_SEC_REQ *p_ble_req)
2515 bt_bdaddr_t bd_addr;
2516 bt_bdname_t bd_name;
2518 BTIF_TRACE_DEBUG1("%s", __FUNCTION__);
2520 if (pairing_cb.state == BT_BOND_STATE_BONDING)
2522 BTIF_TRACE_DEBUG1("%s Discard security request", __FUNCTION__);
2526 /* Remote name update */
2527 btif_update_remote_properties(p_ble_req->bd_addr,p_ble_req->bd_name,NULL,BT_DEVICE_TYPE_BLE);
2529 bdcpy(bd_addr.address, p_ble_req->bd_addr);
2530 memcpy(bd_name.name, p_ble_req->bd_name, BD_NAME_LEN);
2532 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
2534 pairing_cb.bond_type = BOND_TYPE_PERSISTENT;
2535 pairing_cb.is_le_only = TRUE;
2536 pairing_cb.is_ssp = TRUE;
2538 cod = COD_UNCLASSIFIED;
2540 HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod,
2541 BT_SSP_VARIANT_CONSENT, 0);
2546 /*******************************************************************************
2548 ** Function btif_dm_ble_passkey_req_evt
2550 ** Description Executes pin request event in btif context
2554 *******************************************************************************/
2555 static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ *p_pin_req)
2557 bt_bdaddr_t bd_addr;
2558 bt_bdname_t bd_name;
2561 /* Remote name update */
2562 btif_update_remote_properties(p_pin_req->bd_addr,p_pin_req->bd_name,NULL,BT_DEVICE_TYPE_BLE);
2564 bdcpy(bd_addr.address, p_pin_req->bd_addr);
2565 memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN);
2567 bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING);
2568 pairing_cb.is_le_only = TRUE;
2570 cod = COD_UNCLASSIFIED;
2572 HAL_CBACK(bt_hal_cbacks, pin_request_cb,
2573 &bd_addr, &bd_name, cod);
2577 void btif_dm_update_ble_remote_properties( BD_ADDR bd_addr, BD_NAME bd_name,
2578 tBT_DEVICE_TYPE dev_type)
2580 btif_update_remote_properties(bd_addr,bd_name,NULL,dev_type);
2583 static void btif_dm_ble_tx_test_cback(void *p)
2585 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TX_TEST,
2586 (char *)p, 1, NULL);
2589 static void btif_dm_ble_rx_test_cback(void *p)
2591 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_RX_TEST,
2592 (char *)p, 1, NULL);
2595 static void btif_dm_ble_test_end_cback(void *p)
2597 btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TEST_END,
2598 (char *)p, 3, NULL);
2600 /*******************************************************************************
2602 ** Function btif_le_test_mode
2604 ** Description Sends a HCI BLE Test command to the Controller
2606 ** Returns BT_STATUS_SUCCESS on success
2608 *******************************************************************************/
2609 bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t len)
2612 case HCI_BLE_TRANSMITTER_TEST:
2613 if (len != 3) return BT_STATUS_PARM_INVALID;
2614 BTM_BleTransmitterTest(buf[0],buf[1],buf[2], btif_dm_ble_tx_test_cback);
2616 case HCI_BLE_RECEIVER_TEST:
2617 if (len != 1) return BT_STATUS_PARM_INVALID;
2618 BTM_BleReceiverTest(buf[0], btif_dm_ble_rx_test_cback);
2620 case HCI_BLE_TEST_END:
2621 BTM_BleTestEnd((tBTM_CMPL_CB*) btif_dm_ble_test_end_cback);
2624 BTIF_TRACE_ERROR2("%s: Unknown LE Test Mode Command 0x%x", __FUNCTION__, opcode);
2625 return BT_STATUS_UNSUPPORTED;
2627 return BT_STATUS_SUCCESS;
2632 void btif_dm_on_disable()
2634 /* cancel any pending pairing requests */
2635 if (pairing_cb.state == BT_BOND_STATE_BONDING)
2637 bt_bdaddr_t bd_addr;
2639 BTIF_TRACE_DEBUG1("%s: Cancel pending pairing request", __FUNCTION__);
2640 bdcpy(bd_addr.address, pairing_cb.bd_addr);
2641 btif_dm_cancel_bond(&bd_addr);
2645 static char* btif_get_default_local_name() {
2646 if (btif_default_local_name[0] == '\0')
2648 int max_len = sizeof(btif_default_local_name) - 1;
2649 if (BTM_DEF_LOCAL_NAME[0] != '\0')
2651 strncpy(btif_default_local_name, BTM_DEF_LOCAL_NAME, max_len);
2655 char prop_model[PROPERTY_VALUE_MAX];
2656 property_get(PROPERTY_PRODUCT_MODEL, prop_model, "");
2657 strncpy(btif_default_local_name, prop_model, max_len);
2659 btif_default_local_name[max_len] = '\0';
2661 return btif_default_local_name;