The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Satya Calloji | 1a9247a | 2014-06-05 13:15:15 -0700 | [diff] [blame] | 3 | * Copyright (C) 2003-2014 Broadcom Corporation |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 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 | * This file contains the action functions for device manager state |
| 22 | * machine. |
| 23 | * |
| 24 | ******************************************************************************/ |
| 25 | |
Marie Janssen | 49120dc | 2015-07-07 16:47:20 -0700 | [diff] [blame] | 26 | #define LOG_TAG "bt_bta_dm" |
| 27 | |
Jakub Pawlowski | 221e9bf | 2016-12-15 14:35:15 -0800 | [diff] [blame] | 28 | #include <base/bind.h> |
| 29 | #include <base/callback.h> |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 30 | #include <base/logging.h> |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 31 | #include <string.h> |
| 32 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 33 | #include "bt_common.h" |
Mike J. Chen | 597c577 | 2014-02-11 16:23:31 -0800 | [diff] [blame] | 34 | #include "bt_target.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 35 | #include "bt_types.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 36 | #include "bta_api.h" |
Pavlin Radoslavov | b2a292b | 2016-10-14 19:34:48 -0700 | [diff] [blame] | 37 | #include "bta_dm_api.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 38 | #include "bta_dm_co.h" |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 39 | #include "bta_dm_int.h" |
| 40 | #include "bta_sys.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 41 | #include "btm_api.h" |
| 42 | #include "btm_int.h" |
| 43 | #include "btu.h" |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 44 | #include "gap_api.h" /* For GAP_BleReadPeerPrefConnParams */ |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 45 | #include "l2c_api.h" |
Chris Manton | f802700 | 2015-03-12 09:22:48 -0700 | [diff] [blame] | 46 | #include "osi/include/log.h" |
Arman Uguray | bb95452 | 2015-06-02 21:11:07 -0700 | [diff] [blame] | 47 | #include "osi/include/osi.h" |
Marie Janssen | db55458 | 2015-06-26 14:53:46 -0700 | [diff] [blame] | 48 | #include "sdp_api.h" |
| 49 | #include "utl.h" |
Chris Manton | f802700 | 2015-03-12 09:22:48 -0700 | [diff] [blame] | 50 | |
Mike J. Chen | a02a48c | 2014-01-31 17:49:43 -0800 | [diff] [blame] | 51 | #if (GAP_INCLUDED == TRUE) |
| 52 | #include "gap_api.h" |
| 53 | #endif |
| 54 | |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 55 | static void bta_dm_inq_results_cb(tBTM_INQ_RESULTS* p_inq, uint8_t* p_eir, |
Jakub Pawlowski | f7100bb | 2017-02-13 14:31:52 -0800 | [diff] [blame] | 56 | uint16_t eir_len); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 57 | static void bta_dm_inq_cmpl_cb(void* p_result); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 58 | static void bta_dm_service_search_remname_cback(const bt_bdaddr_t& bd_addr, |
| 59 | DEV_CLASS dc, BD_NAME bd_name); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 60 | static void bta_dm_remname_cback(tBTM_REMOTE_DEV_NAME* p_remote_name); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 61 | static void bta_dm_find_services(const bt_bdaddr_t& bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 62 | static void bta_dm_discover_next_device(void); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 63 | static void bta_dm_sdp_callback(uint16_t sdp_status); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 64 | static uint8_t bta_dm_authorize_cback(const bt_bdaddr_t& bd_addr, |
| 65 | DEV_CLASS dev_class, BD_NAME bd_name, |
| 66 | uint8_t* service_name, uint8_t service_id, |
| 67 | bool is_originator); |
| 68 | static uint8_t bta_dm_pin_cback(const bt_bdaddr_t& bd_addr, DEV_CLASS dev_class, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 69 | BD_NAME bd_name, bool min_16_digit); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 70 | static uint8_t bta_dm_new_link_key_cback(const bt_bdaddr_t& bd_addr, |
| 71 | DEV_CLASS dev_class, BD_NAME bd_name, |
| 72 | LINK_KEY key, uint8_t key_type); |
| 73 | static uint8_t bta_dm_authentication_complete_cback(const bt_bdaddr_t& bd_addr, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 74 | DEV_CLASS dev_class, |
| 75 | BD_NAME bd_name, |
| 76 | int result); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 77 | static void bta_dm_local_name_cback(const bt_bdaddr_t& bd_addr); |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 78 | static bool bta_dm_check_av(uint16_t event); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 79 | static void bta_dm_bl_change_cback(tBTM_BL_EVENT_DATA* p_data); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 80 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 81 | static void bta_dm_policy_cback(tBTA_SYS_CONN_STATUS status, uint8_t id, |
| 82 | uint8_t app_id, BD_ADDR peer_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 83 | |
| 84 | /* Extended Inquiry Response */ |
Pulkit Bhuwalka | eb1ad1d | 2017-02-28 16:11:34 -0800 | [diff] [blame] | 85 | #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 86 | static uint8_t bta_dm_sp_cback(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data); |
Pulkit Bhuwalka | eb1ad1d | 2017-02-28 16:11:34 -0800 | [diff] [blame] | 87 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 88 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 89 | static void bta_dm_set_eir(char* local_name); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 90 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 91 | static void bta_dm_eir_search_services(tBTM_INQ_RESULTS* p_result, |
| 92 | tBTA_SERVICE_MASK* p_services_to_search, |
| 93 | tBTA_SERVICE_MASK* p_services_found); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 94 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 95 | static void bta_dm_search_timer_cback(void* data); |
| 96 | static void bta_dm_disable_conn_down_timer_cback(void* data); |
| 97 | static void bta_dm_rm_cback(tBTA_SYS_CONN_STATUS status, uint8_t id, |
| 98 | uint8_t app_id, BD_ADDR peer_addr); |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 99 | static void bta_dm_adjust_roles(bool delay_role_switch); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 100 | static char* bta_dm_get_remname(void); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 101 | static void bta_dm_bond_cancel_complete_cback(tBTM_STATUS result); |
| 102 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 103 | static bool bta_dm_read_remote_device_name(const bt_bdaddr_t& bd_addr, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 104 | tBT_TRANSPORT transport); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 105 | static void bta_dm_discover_device(const bt_bdaddr_t& remote_bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 106 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 107 | static void bta_dm_sys_hw_cback(tBTA_SYS_HW_EVT status); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 108 | static void bta_dm_disable_search_and_disc(void); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 109 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 110 | static uint8_t bta_dm_ble_smp_cback(tBTM_LE_EVT event, const bt_bdaddr_t& bda, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 111 | tBTM_LE_EVT_DATA* p_data); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 112 | static void bta_dm_ble_id_key_cback(uint8_t key_type, |
| 113 | tBTM_BLE_LOCAL_KEYS* p_key); |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 114 | static void bta_dm_gattc_register(void); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 115 | static void btm_dm_start_gatt_discovery(const bt_bdaddr_t& bd_addr); |
| 116 | static void bta_dm_cancel_gatt_discovery(const bt_bdaddr_t& bd_addr); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 117 | static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data); |
Prerepa Viswanadham | 81b0319 | 2014-07-23 17:49:48 -0700 | [diff] [blame] | 118 | extern tBTA_DM_CONTRL_STATE bta_dm_pm_obtain_controller_state(void); |
Bernhard Rosenkränzer | 104e3f2 | 2014-11-12 21:53:08 +0100 | [diff] [blame] | 119 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 120 | #if (BLE_VND_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 121 | static void bta_dm_ctrl_features_rd_cmpl_cback(tBTM_STATUS result); |
Bernhard Rosenkränzer | 104e3f2 | 2014-11-12 21:53:08 +0100 | [diff] [blame] | 122 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 123 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 124 | #ifndef BTA_DM_BLE_ADV_CHNL_MAP |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 125 | #define BTA_DM_BLE_ADV_CHNL_MAP \ |
| 126 | (BTM_BLE_ADV_CHNL_37 | BTM_BLE_ADV_CHNL_38 | BTM_BLE_ADV_CHNL_39) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 127 | #endif |
Matthew Xie | f751b01 | 2013-08-13 20:05:34 -0700 | [diff] [blame] | 128 | |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 129 | /* Disable timer interval (in milliseconds) */ |
| 130 | #ifndef BTA_DM_DISABLE_TIMER_MS |
| 131 | #define BTA_DM_DISABLE_TIMER_MS 5000 |
| 132 | #endif |
| 133 | |
| 134 | /* Disable timer retrial interval (in milliseconds) */ |
| 135 | #ifndef BTA_DM_DISABLE_TIMER_RETRIAL_MS |
| 136 | #define BTA_DM_DISABLE_TIMER_RETRIAL_MS 1500 |
| 137 | #endif |
| 138 | |
| 139 | /* Disable connection down timer (in milliseconds) */ |
| 140 | #ifndef BTA_DM_DISABLE_CONN_DOWN_TIMER_MS |
| 141 | #define BTA_DM_DISABLE_CONN_DOWN_TIMER_MS 1000 |
| 142 | #endif |
| 143 | |
| 144 | /* Switch delay timer (in milliseconds) */ |
| 145 | #ifndef BTA_DM_SWITCH_DELAY_TIMER_MS |
| 146 | #define BTA_DM_SWITCH_DELAY_TIMER_MS 500 |
| 147 | #endif |
| 148 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 149 | static void bta_dm_reset_sec_dev_pending(const bt_bdaddr_t& remote_bd_addr); |
| 150 | static void bta_dm_remove_sec_dev_entry(const bt_bdaddr_t& remote_bd_addr); |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 151 | static void bta_dm_observe_results_cb(tBTM_INQ_RESULTS* p_inq, uint8_t* p_eir, |
Jakub Pawlowski | f7100bb | 2017-02-13 14:31:52 -0800 | [diff] [blame] | 152 | uint16_t eir_len); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 153 | static void bta_dm_observe_cmpl_cb(void* p_result); |
| 154 | static void bta_dm_delay_role_switch_cback(void* data); |
| 155 | static void bta_dm_disable_timer_cback(void* data); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 156 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 157 | const uint16_t bta_service_id_to_uuid_lkup_tbl[BTA_MAX_SERVICE_ID] = { |
| 158 | UUID_SERVCLASS_PNP_INFORMATION, /* Reserved */ |
| 159 | UUID_SERVCLASS_SERIAL_PORT, /* BTA_SPP_SERVICE_ID */ |
| 160 | UUID_SERVCLASS_DIALUP_NETWORKING, /* BTA_DUN_SERVICE_ID */ |
| 161 | UUID_SERVCLASS_AUDIO_SOURCE, /* BTA_A2DP_SOURCE_SERVICE_ID */ |
| 162 | UUID_SERVCLASS_LAN_ACCESS_USING_PPP, /* BTA_LAP_SERVICE_ID */ |
| 163 | UUID_SERVCLASS_HEADSET, /* BTA_HSP_HS_SERVICE_ID */ |
| 164 | UUID_SERVCLASS_HF_HANDSFREE, /* BTA_HFP_HS_SERVICE_ID */ |
| 165 | UUID_SERVCLASS_OBEX_OBJECT_PUSH, /* BTA_OPP_SERVICE_ID */ |
| 166 | UUID_SERVCLASS_OBEX_FILE_TRANSFER, /* BTA_FTP_SERVICE_ID */ |
| 167 | UUID_SERVCLASS_CORDLESS_TELEPHONY, /* BTA_CTP_SERVICE_ID */ |
| 168 | UUID_SERVCLASS_INTERCOM, /* BTA_ICP_SERVICE_ID */ |
| 169 | UUID_SERVCLASS_IRMC_SYNC, /* BTA_SYNC_SERVICE_ID */ |
| 170 | UUID_SERVCLASS_DIRECT_PRINTING, /* BTA_BPP_SERVICE_ID */ |
| 171 | UUID_SERVCLASS_IMAGING_RESPONDER, /* BTA_BIP_SERVICE_ID */ |
| 172 | UUID_SERVCLASS_PANU, /* BTA_PANU_SERVICE_ID */ |
| 173 | UUID_SERVCLASS_NAP, /* BTA_NAP_SERVICE_ID */ |
| 174 | UUID_SERVCLASS_GN, /* BTA_GN_SERVICE_ID */ |
| 175 | UUID_SERVCLASS_SAP, /* BTA_SAP_SERVICE_ID */ |
| 176 | UUID_SERVCLASS_AUDIO_SINK, /* BTA_A2DP_SERVICE_ID */ |
| 177 | UUID_SERVCLASS_AV_REMOTE_CONTROL, /* BTA_AVRCP_SERVICE_ID */ |
| 178 | UUID_SERVCLASS_HUMAN_INTERFACE, /* BTA_HID_SERVICE_ID */ |
| 179 | UUID_SERVCLASS_VIDEO_SINK, /* BTA_VDP_SERVICE_ID */ |
| 180 | UUID_SERVCLASS_PBAP_PSE, /* BTA_PBAP_SERVICE_ID */ |
| 181 | UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY, /* BTA_HSP_SERVICE_ID */ |
| 182 | UUID_SERVCLASS_AG_HANDSFREE, /* BTA_HFP_SERVICE_ID */ |
| 183 | UUID_SERVCLASS_MESSAGE_ACCESS, /* BTA_MAP_SERVICE_ID */ |
| 184 | UUID_SERVCLASS_MESSAGE_NOTIFICATION, /* BTA_MN_SERVICE_ID */ |
| 185 | UUID_SERVCLASS_HDP_PROFILE, /* BTA_HDP_SERVICE_ID */ |
Myles Watson | 9979121 | 2016-11-18 08:42:23 -0800 | [diff] [blame] | 186 | UUID_SERVCLASS_PBAP_PCE, /* BTA_PCE_SERVICE_ID */ |
| 187 | UUID_PROTOCOL_ATT /* BTA_GATT_SERVICE_ID */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | /* |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 191 | * NOTE : The number of element in bta_service_id_to_btm_srv_id_lkup_tbl should |
| 192 | * be matching with |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 193 | * the value BTA_MAX_SERVICE_ID in bta_api.h |
| 194 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 195 | * i.e., If you add new Service ID for BTA, the correct security ID of |
| 196 | * the new service |
| 197 | * from Security service definitions (btm_api.h) should be added to |
| 198 | * this lookup table. |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 199 | */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 200 | const uint32_t bta_service_id_to_btm_srv_id_lkup_tbl[BTA_MAX_SERVICE_ID] = { |
| 201 | 0, /* Reserved */ |
| 202 | BTM_SEC_SERVICE_SERIAL_PORT, /* BTA_SPP_SERVICE_ID */ |
| 203 | BTM_SEC_SERVICE_DUN, /* BTA_DUN_SERVICE_ID */ |
| 204 | BTM_SEC_SERVICE_AVDTP, /* BTA_AUDIO_SOURCE_SERVICE_ID */ |
| 205 | BTM_SEC_SERVICE_LAN_ACCESS, /* BTA_LAP_SERVICE_ID */ |
| 206 | BTM_SEC_SERVICE_HEADSET_AG, /* BTA_HSP_SERVICE_ID */ |
| 207 | BTM_SEC_SERVICE_AG_HANDSFREE, /* BTA_HFP_SERVICE_ID */ |
| 208 | BTM_SEC_SERVICE_OBEX, /* BTA_OPP_SERVICE_ID */ |
| 209 | BTM_SEC_SERVICE_OBEX_FTP, /* BTA_FTP_SERVICE_ID */ |
| 210 | BTM_SEC_SERVICE_CORDLESS, /* BTA_CTP_SERVICE_ID */ |
| 211 | BTM_SEC_SERVICE_INTERCOM, /* BTA_ICP_SERVICE_ID */ |
| 212 | BTM_SEC_SERVICE_IRMC_SYNC, /* BTA_SYNC_SERVICE_ID */ |
| 213 | BTM_SEC_SERVICE_BPP_JOB, /* BTA_BPP_SERVICE_ID */ |
| 214 | BTM_SEC_SERVICE_BIP, /* BTA_BIP_SERVICE_ID */ |
| 215 | BTM_SEC_SERVICE_BNEP_PANU, /* BTA_PANU_SERVICE_ID */ |
| 216 | BTM_SEC_SERVICE_BNEP_NAP, /* BTA_NAP_SERVICE_ID */ |
| 217 | BTM_SEC_SERVICE_BNEP_GN, /* BTA_GN_SERVICE_ID */ |
| 218 | BTM_SEC_SERVICE_SAP, /* BTA_SAP_SERVICE_ID */ |
| 219 | BTM_SEC_SERVICE_AVDTP, /* BTA_A2DP_SERVICE_ID */ |
| 220 | BTM_SEC_SERVICE_AVCTP, /* BTA_AVRCP_SERVICE_ID */ |
| 221 | BTM_SEC_SERVICE_HIDH_SEC_CTRL, /* BTA_HID_SERVICE_ID */ |
| 222 | BTM_SEC_SERVICE_AVDTP, /* BTA_VDP_SERVICE_ID */ |
| 223 | BTM_SEC_SERVICE_PBAP, /* BTA_PBAP_SERVICE_ID */ |
| 224 | BTM_SEC_SERVICE_HEADSET, /* BTA_HSP_HS_SERVICE_ID */ |
| 225 | BTM_SEC_SERVICE_HF_HANDSFREE, /* BTA_HFP_HS_SERVICE_ID */ |
| 226 | BTM_SEC_SERVICE_MAP, /* BTA_MAP_SERVICE_ID */ |
| 227 | BTM_SEC_SERVICE_MAP, /* BTA_MN_SERVICE_ID */ |
| 228 | BTM_SEC_SERVICE_HDP_SNK, /* BTA_HDP_SERVICE_ID */ |
Myles Watson | 9979121 | 2016-11-18 08:42:23 -0800 | [diff] [blame] | 229 | BTM_SEC_SERVICE_PBAP, /* BTA_PCE_SERVICE_ID */ |
| 230 | BTM_SEC_SERVICE_ATT /* BTA_GATT_SERVICE_ID */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | /* bta security callback */ |
Myles Watson | 2e8e9f4 | 2016-11-14 16:45:15 -0800 | [diff] [blame] | 234 | const tBTM_APPL_INFO bta_security = {&bta_dm_authorize_cback, |
| 235 | &bta_dm_pin_cback, |
| 236 | &bta_dm_new_link_key_cback, |
| 237 | &bta_dm_authentication_complete_cback, |
| 238 | &bta_dm_bond_cancel_complete_cback, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 239 | #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) |
Myles Watson | 2e8e9f4 | 2016-11-14 16:45:15 -0800 | [diff] [blame] | 240 | &bta_dm_sp_cback, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 241 | #else |
Alex Deymo | 7651cfb | 2017-03-15 00:16:58 -0700 | [diff] [blame] | 242 | NULL, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 243 | #endif |
Myles Watson | 2e8e9f4 | 2016-11-14 16:45:15 -0800 | [diff] [blame] | 244 | &bta_dm_ble_smp_cback, |
| 245 | &bta_dm_ble_id_key_cback}; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 246 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 247 | #define MAX_DISC_RAW_DATA_BUF (4096) |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 248 | uint8_t g_disc_raw_data_buf[MAX_DISC_RAW_DATA_BUF]; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 249 | |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 250 | extern DEV_CLASS local_device_default_class; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 251 | extern fixed_queue_t* btu_bta_alarm_queue; |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 252 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 253 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 254 | * |
| 255 | * Function bta_dm_enable |
| 256 | * |
| 257 | * Description Initialises the BT device manager |
| 258 | * |
| 259 | * |
| 260 | * Returns void |
| 261 | * |
| 262 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 263 | void bta_dm_enable(tBTA_DM_MSG* p_data) { |
| 264 | tBTA_DM_ENABLE enable_event; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 265 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 266 | /* if already in use, return an error */ |
| 267 | if (bta_dm_cb.is_bta_dm_active == true) { |
| 268 | APPL_TRACE_WARNING("%s Device already started by another application", |
| 269 | __func__); |
| 270 | memset(&enable_event, 0, sizeof(tBTA_DM_ENABLE)); |
| 271 | enable_event.status = BTA_FAILURE; |
| 272 | if (p_data->enable.p_sec_cback != NULL) |
| 273 | p_data->enable.p_sec_cback(BTA_DM_ENABLE_EVT, |
| 274 | (tBTA_DM_SEC*)&enable_event); |
| 275 | return; |
| 276 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 277 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 278 | /* first, register our callback to SYS HW manager */ |
| 279 | bta_sys_hw_register(BTA_SYS_HW_BLUETOOTH, bta_dm_sys_hw_cback); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 280 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 281 | /* make sure security callback is saved - if no callback, do not erase the |
| 282 | previous one, |
| 283 | it could be an error recovery mechanism */ |
| 284 | if (p_data->enable.p_sec_cback != NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 285 | bta_dm_cb.p_sec_cback = p_data->enable.p_sec_cback; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 286 | /* notify BTA DM is now active */ |
| 287 | bta_dm_cb.is_bta_dm_active = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 288 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 289 | /* send a message to BTA SYS */ |
| 290 | tBTA_SYS_HW_MSG* sys_enable_event = |
| 291 | (tBTA_SYS_HW_MSG*)osi_malloc(sizeof(tBTA_SYS_HW_MSG)); |
| 292 | sys_enable_event->hdr.event = BTA_SYS_API_ENABLE_EVT; |
| 293 | sys_enable_event->hw_module = BTA_SYS_HW_BLUETOOTH; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 294 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 295 | bta_sys_sendmsg(sys_enable_event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 296 | } |
| 297 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 298 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 299 | * |
| 300 | * Function bta_dm_init_cb |
| 301 | * |
| 302 | * Description Initializes the bta_dm_cb control block |
| 303 | * |
| 304 | * |
| 305 | * Returns void |
| 306 | * |
| 307 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 308 | void bta_dm_init_cb(void) { |
| 309 | memset(&bta_dm_cb, 0, sizeof(bta_dm_cb)); |
| 310 | bta_dm_cb.disable_timer = alarm_new("bta_dm.disable_timer"); |
| 311 | bta_dm_cb.switch_delay_timer = alarm_new("bta_dm.switch_delay_timer"); |
| 312 | for (size_t i = 0; i < BTA_DM_NUM_PM_TIMER; i++) { |
| 313 | for (size_t j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++) { |
| 314 | bta_dm_cb.pm_timer[i].timer[j] = alarm_new("bta_dm.pm_timer"); |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 315 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 316 | } |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 320 | * |
| 321 | * Function bta_dm_deinit_cb |
| 322 | * |
| 323 | * Description De-initializes the bta_dm_cb control block |
| 324 | * |
| 325 | * |
| 326 | * Returns void |
| 327 | * |
| 328 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 329 | void bta_dm_deinit_cb(void) { |
| 330 | /* |
| 331 | * TODO: Should alarm_free() the bta_dm_cb timers during graceful |
| 332 | * shutdown. |
| 333 | */ |
| 334 | alarm_free(bta_dm_cb.disable_timer); |
| 335 | alarm_free(bta_dm_cb.switch_delay_timer); |
| 336 | for (size_t i = 0; i < BTA_DM_NUM_PM_TIMER; i++) { |
| 337 | for (size_t j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++) { |
| 338 | alarm_free(bta_dm_cb.pm_timer[i].timer[j]); |
Srinu Jella | 5ba7922 | 2016-06-08 17:31:41 +0530 | [diff] [blame] | 339 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 340 | } |
| 341 | memset(&bta_dm_cb, 0, sizeof(bta_dm_cb)); |
Srinu Jella | 5ba7922 | 2016-06-08 17:31:41 +0530 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 345 | * |
| 346 | * Function bta_dm_sys_hw_cback |
| 347 | * |
| 348 | * Description callback register to SYS to get HW status updates |
| 349 | * |
| 350 | * |
| 351 | * Returns void |
| 352 | * |
| 353 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 354 | static void bta_dm_sys_hw_cback(tBTA_SYS_HW_EVT status) { |
| 355 | DEV_CLASS dev_class; |
| 356 | tBTA_DM_SEC_CBACK* temp_cback; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 357 | uint8_t key_mask = 0; |
| 358 | BT_OCTET16 er; |
| 359 | tBTA_BLE_LOCAL_ID_KEYS id_key; |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 360 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 361 | APPL_TRACE_DEBUG("%s with event: %i", __func__, status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 362 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 363 | /* On H/W error evt, report to the registered DM application callback */ |
| 364 | if (status == BTA_SYS_HW_ERROR_EVT) { |
| 365 | if (bta_dm_cb.p_sec_cback != NULL) |
| 366 | bta_dm_cb.p_sec_cback(BTA_DM_HW_ERROR_EVT, NULL); |
| 367 | return; |
| 368 | } |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 369 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 370 | if (status == BTA_SYS_HW_OFF_EVT) { |
| 371 | if (bta_dm_cb.p_sec_cback != NULL) |
| 372 | bta_dm_cb.p_sec_cback(BTA_DM_DISABLE_EVT, NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 373 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 374 | /* reinitialize the control block */ |
| 375 | bta_dm_deinit_cb(); |
Srinu Jella | 5ba7922 | 2016-06-08 17:31:41 +0530 | [diff] [blame] | 376 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 377 | /* hw is ready, go on with BTA DM initialization */ |
| 378 | alarm_free(bta_dm_search_cb.search_timer); |
| 379 | alarm_free(bta_dm_search_cb.gatt_close_timer); |
| 380 | memset(&bta_dm_search_cb, 0, sizeof(bta_dm_search_cb)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 381 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 382 | /* unregister from SYS */ |
| 383 | bta_sys_hw_unregister(BTA_SYS_HW_BLUETOOTH); |
| 384 | /* notify BTA DM is now unactive */ |
| 385 | bta_dm_cb.is_bta_dm_active = false; |
| 386 | } else if (status == BTA_SYS_HW_ON_EVT) { |
| 387 | /* FIXME: We should not unregister as the SYS shall invoke this callback on |
Andre Eisenbach | 1f5ec73 | 2017-04-13 14:49:36 -0700 | [diff] [blame] | 388 | * a H/W error. |
| 389 | * We need to revisit when this platform has more than one BLuetooth H/W |
| 390 | * chip |
| 391 | */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 392 | // bta_sys_hw_unregister( BTA_SYS_HW_BLUETOOTH); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 393 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 394 | /* save security callback */ |
| 395 | temp_cback = bta_dm_cb.p_sec_cback; |
| 396 | /* make sure the control block is properly initialized */ |
| 397 | bta_dm_init_cb(); |
| 398 | /* and retrieve the callback */ |
| 399 | bta_dm_cb.p_sec_cback = temp_cback; |
| 400 | bta_dm_cb.is_bta_dm_active = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 401 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 402 | /* hw is ready, go on with BTA DM initialization */ |
| 403 | alarm_free(bta_dm_search_cb.search_timer); |
| 404 | alarm_free(bta_dm_search_cb.gatt_close_timer); |
| 405 | memset(&bta_dm_search_cb, 0, sizeof(bta_dm_search_cb)); |
| 406 | /* |
| 407 | * TODO: Should alarm_free() the bta_dm_search_cb timers during |
| 408 | * graceful shutdown. |
| 409 | */ |
| 410 | bta_dm_search_cb.search_timer = alarm_new("bta_dm_search.search_timer"); |
| 411 | bta_dm_search_cb.gatt_close_timer = |
| 412 | alarm_new("bta_dm_search.gatt_close_timer"); |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 413 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 414 | memset(&bta_dm_conn_srvcs, 0, sizeof(bta_dm_conn_srvcs)); |
| 415 | memset(&bta_dm_di_cb, 0, sizeof(tBTA_DM_DI_CB)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 416 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 417 | memcpy(dev_class, p_bta_dm_cfg->dev_class, sizeof(dev_class)); |
| 418 | BTM_SetDeviceClass(dev_class); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 419 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 420 | /* load BLE local information: ID keys, ER if available */ |
| 421 | bta_dm_co_ble_load_local_keys(&key_mask, er, &id_key); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 422 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 423 | if (key_mask & BTA_BLE_LOCAL_KEY_TYPE_ER) { |
| 424 | BTM_BleLoadLocalKeys(BTA_BLE_LOCAL_KEY_TYPE_ER, |
| 425 | (tBTM_BLE_LOCAL_KEYS*)&er); |
| 426 | } |
| 427 | if (key_mask & BTA_BLE_LOCAL_KEY_TYPE_ID) { |
| 428 | BTM_BleLoadLocalKeys(BTA_BLE_LOCAL_KEY_TYPE_ID, |
| 429 | (tBTM_BLE_LOCAL_KEYS*)&id_key); |
| 430 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 431 | bta_dm_search_cb.conn_id = BTA_GATT_INVALID_CONN_ID; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 432 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 433 | BTM_SecRegister((tBTM_APPL_INFO*)&bta_security); |
| 434 | BTM_SetDefaultLinkSuperTout(p_bta_dm_cfg->link_timeout); |
| 435 | BTM_WritePageTimeout(p_bta_dm_cfg->page_timeout); |
| 436 | bta_dm_cb.cur_policy = p_bta_dm_cfg->policy_settings; |
| 437 | BTM_SetDefaultLinkPolicy(bta_dm_cb.cur_policy); |
| 438 | BTM_RegBusyLevelNotif(bta_dm_bl_change_cback, NULL, |
| 439 | BTM_BL_UPDATE_MASK | BTM_BL_ROLE_CHG_MASK); |
Satya Calloji | 3f24f46 | 2014-09-16 22:44:43 -0700 | [diff] [blame] | 440 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 441 | #if (BLE_VND_INCLUDED == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 442 | BTM_BleReadControllerFeatures(bta_dm_ctrl_features_rd_cmpl_cback); |
Jakub Pawlowski | 2255250 | 2016-12-22 03:13:00 -0800 | [diff] [blame] | 443 | #else |
| 444 | /* If VSC multi adv commands are available, advertising will be initialized |
| 445 | * when capabilities are read. If they are not avaliable, initialize |
| 446 | * advertising here */ |
| 447 | btm_ble_adv_init(); |
Satya Calloji | 3f24f46 | 2014-09-16 22:44:43 -0700 | [diff] [blame] | 448 | #endif |
| 449 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 450 | /* Earlier, we used to invoke BTM_ReadLocalAddr which was just copying the |
| 451 | bd_addr |
| 452 | from the control block and invoking the callback which was sending the |
| 453 | DM_ENABLE_EVT. |
| 454 | But then we have a few HCI commands being invoked above which were still |
| 455 | in progress |
| 456 | when the ENABLE_EVT was sent. So modified this to fetch the local name |
| 457 | which forces |
| 458 | the DM_ENABLE_EVT to be sent only after all the init steps are complete |
| 459 | */ |
| 460 | BTM_ReadLocalDeviceNameFromController( |
| 461 | (tBTM_CMPL_CB*)bta_dm_local_name_cback); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 462 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 463 | bta_sys_rm_register((tBTA_SYS_CONN_CBACK*)bta_dm_rm_cback); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 464 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 465 | /* initialize bluetooth low power manager */ |
| 466 | bta_dm_init_pm(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 467 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 468 | bta_sys_policy_register((tBTA_SYS_CONN_CBACK*)bta_dm_policy_cback); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 469 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 470 | bta_dm_gattc_register(); |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 471 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 472 | } else |
| 473 | APPL_TRACE_DEBUG(" --- ignored event"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 474 | } |
| 475 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 476 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 477 | * |
| 478 | * Function bta_dm_disable |
| 479 | * |
| 480 | * Description Disables the BT device manager |
| 481 | * |
| 482 | * |
| 483 | * Returns void |
| 484 | * |
| 485 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 486 | void bta_dm_disable(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 487 | /* Set l2cap idle timeout to 0 (so BTE immediately disconnects ACL link after |
| 488 | * last channel is closed) */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 489 | L2CA_SetIdleTimeoutByBdAddr(BT_BD_ANY, 0, BT_TRANSPORT_BR_EDR); |
| 490 | L2CA_SetIdleTimeoutByBdAddr(BT_BD_ANY, 0, BT_TRANSPORT_LE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 491 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 492 | /* disable all active subsystems */ |
| 493 | bta_sys_disable(BTA_SYS_HW_BLUETOOTH); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 494 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 495 | BTM_SetDiscoverability(BTM_NON_DISCOVERABLE, 0, 0); |
| 496 | BTM_SetConnectability(BTM_NON_CONNECTABLE, 0, 0); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 497 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 498 | bta_dm_disable_pm(); |
| 499 | bta_dm_disable_search_and_disc(); |
| 500 | bta_dm_cb.disabling = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 501 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 502 | BTM_BleClearBgConnDev(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 503 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 504 | if (BTM_GetNumAclLinks() == 0) { |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 505 | #if (BTA_DISABLE_DELAY > 0) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 506 | /* If BTA_DISABLE_DELAY is defined and greater than zero, then delay the |
| 507 | * shutdown by |
| 508 | * BTA_DISABLE_DELAY milliseconds |
| 509 | */ |
| 510 | APPL_TRACE_WARNING("%s BTA_DISABLE_DELAY set to %d ms", __func__, |
| 511 | BTA_DISABLE_DELAY); |
| 512 | alarm_set_on_queue(bta_dm_cb.disable_timer, BTA_DISABLE_DELAY, |
| 513 | bta_dm_disable_conn_down_timer_cback, NULL, |
| 514 | btu_bta_alarm_queue); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 515 | #else |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 516 | bta_dm_disable_conn_down_timer_cback(NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 517 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 518 | } else { |
| 519 | alarm_set_on_queue(bta_dm_cb.disable_timer, BTA_DM_DISABLE_TIMER_MS, |
| 520 | bta_dm_disable_timer_cback, UINT_TO_PTR(0), |
| 521 | btu_bta_alarm_queue); |
| 522 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 526 | * |
| 527 | * Function bta_dm_disable_timer_cback |
| 528 | * |
| 529 | * Description Called if the disable timer expires |
| 530 | * Used to close ACL connections which are still active |
| 531 | * |
| 532 | * |
| 533 | * |
| 534 | * Returns void |
| 535 | * |
| 536 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 537 | static void bta_dm_disable_timer_cback(void* data) { |
| 538 | uint8_t i; |
| 539 | tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; |
| 540 | bool trigger_disc = false; |
| 541 | uint32_t param = PTR_TO_UINT(data); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 542 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 543 | APPL_TRACE_EVENT("%s trial %u", __func__, param); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 544 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 545 | if (BTM_GetNumAclLinks() && (param == 0)) { |
| 546 | for (i = 0; i < bta_dm_cb.device_list.count; i++) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 547 | transport = bta_dm_cb.device_list.peer_device[i].transport; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 548 | btm_remove_acl(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, |
| 549 | transport); |
| 550 | trigger_disc = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 551 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 552 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 553 | /* Retrigger disable timer in case ACL disconnect failed, DISABLE_EVT still |
| 554 | need |
| 555 | to be sent out to avoid jave layer disable timeout */ |
| 556 | if (trigger_disc) { |
| 557 | alarm_set_on_queue( |
| 558 | bta_dm_cb.disable_timer, BTA_DM_DISABLE_TIMER_RETRIAL_MS, |
| 559 | bta_dm_disable_timer_cback, UINT_TO_PTR(1), btu_bta_alarm_queue); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 560 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 561 | } else { |
| 562 | bta_dm_cb.disabling = false; |
| 563 | |
| 564 | bta_sys_remove_uuid(UUID_SERVCLASS_PNP_INFORMATION); |
| 565 | bta_dm_cb.p_sec_cback(BTA_DM_DISABLE_EVT, NULL); |
| 566 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 567 | } |
| 568 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 569 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 570 | * |
| 571 | * Function bta_dm_set_dev_name |
| 572 | * |
| 573 | * Description Sets local device name |
| 574 | * |
| 575 | * |
| 576 | * Returns void |
| 577 | * |
| 578 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 579 | void bta_dm_set_dev_name(tBTA_DM_MSG* p_data) { |
| 580 | BTM_SetLocalDeviceName((char*)p_data->set_name.name); |
| 581 | bta_dm_set_eir((char*)p_data->set_name.name); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 585 | * |
| 586 | * Function bta_dm_set_visibility |
| 587 | * |
| 588 | * Description Sets discoverability, connectability and pairability |
| 589 | * |
| 590 | * |
| 591 | * Returns void |
| 592 | * |
| 593 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 594 | void bta_dm_set_visibility(tBTA_DM_MSG* p_data) { |
| 595 | uint16_t window, interval; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 596 | uint16_t le_disc_mode = BTM_BleReadDiscoverability(); |
| 597 | uint16_t le_conn_mode = BTM_BleReadConnectability(); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 598 | uint16_t disc_mode = BTM_ReadDiscoverability(&window, &interval); |
| 599 | uint16_t conn_mode = BTM_ReadConnectability(&window, &interval); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 600 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 601 | /* set modes for Discoverability and connectability if not ignore */ |
| 602 | if (p_data->set_visibility.disc_mode != (BTA_DM_IGNORE | BTA_DM_LE_IGNORE)) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 603 | if ((p_data->set_visibility.disc_mode & BTA_DM_LE_IGNORE) == |
| 604 | BTA_DM_LE_IGNORE) |
| 605 | p_data->set_visibility.disc_mode = |
| 606 | ((p_data->set_visibility.disc_mode & ~BTA_DM_LE_IGNORE) | |
| 607 | le_disc_mode); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 608 | if ((p_data->set_visibility.disc_mode & BTA_DM_IGNORE) == BTA_DM_IGNORE) |
| 609 | p_data->set_visibility.disc_mode = |
| 610 | ((p_data->set_visibility.disc_mode & ~BTA_DM_IGNORE) | disc_mode); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 611 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 612 | BTM_SetDiscoverability(p_data->set_visibility.disc_mode, |
| 613 | bta_dm_cb.inquiry_scan_window, |
| 614 | bta_dm_cb.inquiry_scan_interval); |
| 615 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 616 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 617 | if (p_data->set_visibility.conn_mode != (BTA_DM_IGNORE | BTA_DM_LE_IGNORE)) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 618 | if ((p_data->set_visibility.conn_mode & BTA_DM_LE_IGNORE) == |
| 619 | BTA_DM_LE_IGNORE) |
| 620 | p_data->set_visibility.conn_mode = |
| 621 | ((p_data->set_visibility.conn_mode & ~BTA_DM_LE_IGNORE) | |
| 622 | le_conn_mode); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 623 | if ((p_data->set_visibility.conn_mode & BTA_DM_IGNORE) == BTA_DM_IGNORE) |
| 624 | p_data->set_visibility.conn_mode = |
| 625 | ((p_data->set_visibility.conn_mode & ~BTA_DM_IGNORE) | conn_mode); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 626 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 627 | BTM_SetConnectability(p_data->set_visibility.conn_mode, |
| 628 | bta_dm_cb.page_scan_window, |
| 629 | bta_dm_cb.page_scan_interval); |
| 630 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 631 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 632 | /* Send False or True if not ignore */ |
| 633 | if (p_data->set_visibility.pair_mode != BTA_DM_IGNORE) { |
| 634 | if (p_data->set_visibility.pair_mode == BTA_DM_NON_PAIRABLE) |
| 635 | bta_dm_cb.disable_pair_mode = true; |
| 636 | else |
| 637 | bta_dm_cb.disable_pair_mode = false; |
| 638 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 639 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 640 | /* Send False or True if not ignore */ |
| 641 | if (p_data->set_visibility.conn_paired_only != BTA_DM_IGNORE) { |
| 642 | if (p_data->set_visibility.conn_paired_only == BTA_DM_CONN_ALL) |
| 643 | bta_dm_cb.conn_paired_only = false; |
| 644 | else |
| 645 | bta_dm_cb.conn_paired_only = true; |
| 646 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 647 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 648 | /* Change mode if either mode is not ignore */ |
| 649 | if (p_data->set_visibility.pair_mode != BTA_DM_IGNORE || |
| 650 | p_data->set_visibility.conn_paired_only != BTA_DM_IGNORE) |
| 651 | BTM_SetPairableMode((bool)(!(bta_dm_cb.disable_pair_mode)), |
| 652 | bta_dm_cb.conn_paired_only); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 653 | } |
| 654 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 655 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 656 | * |
| 657 | * Function bta_dm_process_remove_device |
| 658 | * |
| 659 | * Description Removes device, Disconnects ACL link if required. |
| 660 | *** |
| 661 | ******************************************************************************/ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 662 | void bta_dm_process_remove_device(const bt_bdaddr_t& bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 663 | /* need to remove all pending background connection before unpair */ |
| 664 | BTA_GATTC_CancelOpen(0, bd_addr, false); |
Zhihai Xu | bd68d68 | 2013-11-15 17:55:46 -0800 | [diff] [blame] | 665 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 666 | BTM_SecDeleteDevice(bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 667 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 668 | /* remove all cached GATT information */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 669 | BTA_GATTC_Refresh(bd_addr); |
Satya Calloji | 6fc9526 | 2015-04-21 16:34:54 -0700 | [diff] [blame] | 670 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 671 | if (bta_dm_cb.p_sec_cback) { |
| 672 | tBTA_DM_SEC sec_event; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 673 | sec_event.link_down.bd_addr = bd_addr; |
| 674 | ; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 675 | /* No connection, set status to success (acl disc code not valid) */ |
| 676 | sec_event.link_down.status = HCI_SUCCESS; |
| 677 | bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &sec_event); |
| 678 | } |
Satya Calloji | 6fc9526 | 2015-04-21 16:34:54 -0700 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 682 | * |
| 683 | * Function bta_dm_remove_device |
| 684 | * |
| 685 | * Description Removes device, disconnects ACL link if required. |
| 686 | *** |
| 687 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 688 | void bta_dm_remove_device(tBTA_DM_MSG* p_data) { |
| 689 | tBTA_DM_API_REMOVE_DEVICE* p_dev = &p_data->remove_dev; |
| 690 | bool continue_delete_other_dev = false; |
| 691 | if (p_dev == NULL) return; |
Satya Calloji | 6fc9526 | 2015-04-21 16:34:54 -0700 | [diff] [blame] | 692 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 693 | bt_bdaddr_t other_address = p_dev->bd_addr; |
Satya Calloji | 6fc9526 | 2015-04-21 16:34:54 -0700 | [diff] [blame] | 694 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 695 | /* If ACL exists for the device in the remove_bond message*/ |
| 696 | bool continue_delete_dev = false; |
| 697 | uint8_t other_transport = BT_TRANSPORT_INVALID; |
Satya Calloji | 6fc9526 | 2015-04-21 16:34:54 -0700 | [diff] [blame] | 698 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 699 | if (BTM_IsAclConnectionUp(p_dev->bd_addr, BT_TRANSPORT_LE) || |
| 700 | BTM_IsAclConnectionUp(p_dev->bd_addr, BT_TRANSPORT_BR_EDR)) { |
| 701 | APPL_TRACE_DEBUG("%s: ACL Up count %d", __func__, |
| 702 | bta_dm_cb.device_list.count); |
| 703 | continue_delete_dev = false; |
Satya Calloji | 6fc9526 | 2015-04-21 16:34:54 -0700 | [diff] [blame] | 704 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 705 | /* Take the link down first, and mark the device for removal when |
| 706 | * disconnected */ |
| 707 | for (int i = 0; i < bta_dm_cb.device_list.count; i++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 708 | if (bta_dm_cb.device_list.peer_device[i].peer_bdaddr == p_dev->bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 709 | uint8_t transport = BT_TRANSPORT_BR_EDR; |
Scott James Remnant | dd339ab | 2015-11-19 15:27:41 -0800 | [diff] [blame] | 710 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 711 | transport = bta_dm_cb.device_list.peer_device[i].transport; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 712 | bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_UNPAIRING; |
| 713 | btm_remove_acl(p_dev->bd_addr, transport); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 714 | APPL_TRACE_DEBUG("%s:transport = %d", __func__, |
| 715 | bta_dm_cb.device_list.peer_device[i].transport); |
Satya Calloji | 6fc9526 | 2015-04-21 16:34:54 -0700 | [diff] [blame] | 716 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 717 | /* save the other transport to check if device is connected on |
| 718 | * other_transport */ |
| 719 | if (bta_dm_cb.device_list.peer_device[i].transport == BT_TRANSPORT_LE) |
| 720 | other_transport = BT_TRANSPORT_BR_EDR; |
| 721 | else |
| 722 | other_transport = BT_TRANSPORT_LE; |
Scott James Remnant | dd339ab | 2015-11-19 15:27:41 -0800 | [diff] [blame] | 723 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 724 | break; |
| 725 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 726 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 727 | } else { |
| 728 | continue_delete_dev = true; |
| 729 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 730 | // If it is DUMO device and device is paired as different address, unpair that |
| 731 | // device |
| 732 | // if different address |
| 733 | if ((other_transport && |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 734 | (BTM_ReadConnectedTransportAddress(&other_address, other_transport))) || |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 735 | (!other_transport && |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 736 | (BTM_ReadConnectedTransportAddress(&other_address, |
| 737 | BT_TRANSPORT_BR_EDR) || |
| 738 | BTM_ReadConnectedTransportAddress(&other_address, BT_TRANSPORT_LE)))) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 739 | continue_delete_other_dev = false; |
| 740 | /* Take the link down first, and mark the device for removal when |
| 741 | * disconnected */ |
| 742 | for (int i = 0; i < bta_dm_cb.device_list.count; i++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 743 | if (bta_dm_cb.device_list.peer_device[i].peer_bdaddr == other_address) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 744 | bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_UNPAIRING; |
| 745 | btm_remove_acl(other_address, |
| 746 | bta_dm_cb.device_list.peer_device[i].transport); |
| 747 | break; |
| 748 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 749 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 750 | } else { |
| 751 | APPL_TRACE_DEBUG("%s: continue to delete the other dev ", __func__); |
| 752 | continue_delete_other_dev = true; |
| 753 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 754 | /* Delete the device mentioned in the msg */ |
| 755 | if (continue_delete_dev) bta_dm_process_remove_device(p_dev->bd_addr); |
Satya Calloji | 6fc9526 | 2015-04-21 16:34:54 -0700 | [diff] [blame] | 756 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 757 | /* Delete the other paired device too */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 758 | bt_bdaddr_t dummy_bda = {.address = {0}}; |
| 759 | if (continue_delete_other_dev && other_address != dummy_bda) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 760 | bta_dm_process_remove_device(other_address); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 764 | * |
| 765 | * Function bta_dm_add_device |
| 766 | * |
| 767 | * Description This function adds a Link Key to an security database entry. |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 768 | * It is normally called during host startup to restore all |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 769 | * required information stored in the NVRAM. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 770 | *** |
| 771 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 772 | void bta_dm_add_device(tBTA_DM_MSG* p_data) { |
| 773 | tBTA_DM_API_ADD_DEVICE* p_dev = &p_data->add_dev; |
| 774 | uint8_t* p_dc = NULL; |
| 775 | uint8_t* p_lc = NULL; |
| 776 | uint32_t trusted_services_mask[BTM_SEC_SERVICE_ARRAY_SIZE]; |
| 777 | uint8_t index = 0; |
| 778 | uint8_t btm_mask_index = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 779 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 780 | memset(trusted_services_mask, 0, sizeof(trusted_services_mask)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 781 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 782 | /* If not all zeros, the device class has been specified */ |
| 783 | if (p_dev->dc_known) p_dc = (uint8_t*)p_dev->dc; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 784 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 785 | if (p_dev->link_key_known) p_lc = (uint8_t*)p_dev->link_key; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 786 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 787 | if (p_dev->is_trusted) { |
| 788 | /* covert BTA service mask to BTM mask */ |
| 789 | while (p_dev->tm && (index < BTA_MAX_SERVICE_ID)) { |
| 790 | if (p_dev->tm & (uint32_t)(1 << index)) { |
| 791 | btm_mask_index = |
| 792 | bta_service_id_to_btm_srv_id_lkup_tbl[index] / BTM_SEC_ARRAY_BITS; |
| 793 | trusted_services_mask[btm_mask_index] |= |
| 794 | (uint32_t)(1 << (bta_service_id_to_btm_srv_id_lkup_tbl[index] - |
| 795 | (uint32_t)(btm_mask_index * 32))); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 796 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 797 | p_dev->tm &= (uint32_t)(~(1 << index)); |
| 798 | } |
| 799 | index++; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 800 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 801 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 802 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 803 | if (!BTM_SecAddDevice(p_dev->bd_addr, p_dc, p_dev->bd_name, p_dev->features, |
| 804 | trusted_services_mask, p_lc, p_dev->key_type, |
| 805 | p_dev->io_cap, p_dev->pin_length)) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 806 | LOG(ERROR) << "BTA_DM: Error adding device " << p_dev->bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 807 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 811 | * |
| 812 | * Function bta_dm_close_acl |
| 813 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 814 | * Description This function forces to close the connection to a remote |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 815 | * device and optionaly remove the device from security |
| 816 | * database if required. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 817 | *** |
| 818 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 819 | void bta_dm_close_acl(tBTA_DM_MSG* p_data) { |
| 820 | tBTA_DM_API_REMOVE_ACL* p_remove_acl = &p_data->remove_acl; |
| 821 | uint8_t index; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 822 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 823 | APPL_TRACE_DEBUG("bta_dm_close_acl"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 824 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 825 | if (BTM_IsAclConnectionUp(p_remove_acl->bd_addr, p_remove_acl->transport)) { |
| 826 | for (index = 0; index < bta_dm_cb.device_list.count; index++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 827 | if (bta_dm_cb.device_list.peer_device[index].peer_bdaddr == |
| 828 | p_remove_acl->bd_addr) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 829 | break; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 830 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 831 | if (index != bta_dm_cb.device_list.count) { |
| 832 | if (p_remove_acl->remove_dev) |
| 833 | bta_dm_cb.device_list.peer_device[index].remove_dev_pending = true; |
| 834 | } else { |
| 835 | APPL_TRACE_ERROR("unknown device, remove ACL failed"); |
| 836 | } |
| 837 | /* Disconnect the ACL link */ |
| 838 | btm_remove_acl(p_remove_acl->bd_addr, p_remove_acl->transport); |
| 839 | } |
| 840 | /* if to remove the device from security database ? do it now */ |
| 841 | else if (p_remove_acl->remove_dev) { |
| 842 | if (!BTM_SecDeleteDevice(p_remove_acl->bd_addr)) { |
| 843 | APPL_TRACE_ERROR("delete device from security database failed."); |
| 844 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 845 | /* need to remove all pending background connection if any */ |
| 846 | BTA_GATTC_CancelOpen(0, p_remove_acl->bd_addr, false); |
| 847 | /* remove all cached GATT information */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 848 | BTA_GATTC_Refresh(p_remove_acl->bd_addr); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 849 | } |
| 850 | /* otherwise, no action needed */ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 851 | } |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 852 | |
| 853 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 854 | * |
| 855 | * Function bta_dm_remove_all_acl |
| 856 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 857 | * Description This function forces to close all the ACL links specified by |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 858 | * link type |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 859 | *** |
| 860 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 861 | void bta_dm_remove_all_acl(tBTA_DM_MSG* p_data) { |
| 862 | const tBTA_DM_LINK_TYPE link_type = p_data->remove_all_acl.link_type; |
| 863 | tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 864 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 865 | APPL_TRACE_DEBUG("%s link type = %d", __func__, link_type); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 866 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 867 | for (uint8_t i = 0; i < bta_dm_cb.device_list.count; i++) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 868 | transport = bta_dm_cb.device_list.peer_device[i].transport; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 869 | if ((link_type == BTA_DM_LINK_TYPE_ALL) || |
| 870 | ((link_type == BTA_DM_LINK_TYPE_LE) && |
| 871 | (transport == BT_TRANSPORT_LE)) || |
| 872 | ((link_type == BTA_DM_LINK_TYPE_BR_EDR) && |
| 873 | (transport == BT_TRANSPORT_BR_EDR))) { |
| 874 | /* Disconnect the ACL link */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 875 | btm_remove_acl(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, |
| 876 | transport); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 877 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 878 | } |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 881 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 882 | * |
| 883 | * Function bta_dm_bond |
| 884 | * |
| 885 | * Description Bonds with peer device |
| 886 | * |
| 887 | * |
| 888 | * Returns void |
| 889 | * |
| 890 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 891 | void bta_dm_bond(tBTA_DM_MSG* p_data) { |
| 892 | tBTM_STATUS status; |
| 893 | tBTA_DM_SEC sec_event; |
| 894 | char* p_name; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 895 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 896 | if (p_data->bond.transport == BTA_TRANSPORT_UNKNOWN) |
| 897 | status = BTM_SecBond(p_data->bond.bd_addr, 0, NULL, 0); |
| 898 | else |
| 899 | status = BTM_SecBondByTransport(p_data->bond.bd_addr, |
| 900 | p_data->bond.transport, 0, NULL, 0); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 901 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 902 | if (bta_dm_cb.p_sec_cback && (status != BTM_CMD_STARTED)) { |
| 903 | memset(&sec_event, 0, sizeof(tBTA_DM_SEC)); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 904 | sec_event.auth_cmpl.bd_addr = p_data->bond.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 905 | p_name = BTM_SecReadDevName(p_data->bond.bd_addr); |
| 906 | if (p_name != NULL) { |
| 907 | memcpy(sec_event.auth_cmpl.bd_name, p_name, (BD_NAME_LEN - 1)); |
| 908 | sec_event.auth_cmpl.bd_name[BD_NAME_LEN - 1] = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 909 | } |
| 910 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 911 | /* taken care of by memset [above] |
| 912 | sec_event.auth_cmpl.key_present = false; |
| 913 | sec_event.auth_cmpl.success = false; |
| 914 | */ |
| 915 | sec_event.auth_cmpl.fail_reason = HCI_ERR_ILLEGAL_COMMAND; |
| 916 | if (status == BTM_SUCCESS) { |
| 917 | sec_event.auth_cmpl.success = true; |
| 918 | } else { |
| 919 | /* delete this device entry from Sec Dev DB */ |
| 920 | bta_dm_remove_sec_dev_entry(p_data->bond.bd_addr); |
| 921 | } |
| 922 | bta_dm_cb.p_sec_cback(BTA_DM_AUTH_CMPL_EVT, &sec_event); |
| 923 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 927 | * |
| 928 | * Function bta_dm_bond_cancel |
| 929 | * |
| 930 | * Description Cancels bonding with a peer device |
| 931 | * |
| 932 | * |
| 933 | * Returns void |
| 934 | * |
| 935 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 936 | void bta_dm_bond_cancel(tBTA_DM_MSG* p_data) { |
| 937 | tBTM_STATUS status; |
| 938 | tBTA_DM_SEC sec_event; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 939 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 940 | APPL_TRACE_EVENT(" bta_dm_bond_cancel "); |
| 941 | status = BTM_SecBondCancel(p_data->bond_cancel.bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 942 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 943 | if (bta_dm_cb.p_sec_cback && |
| 944 | (status != BTM_CMD_STARTED && status != BTM_SUCCESS)) { |
| 945 | sec_event.bond_cancel_cmpl.result = BTA_FAILURE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 946 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 947 | bta_dm_cb.p_sec_cback(BTA_DM_BOND_CANCEL_CMPL_EVT, &sec_event); |
| 948 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 952 | * |
| 953 | * Function bta_dm_pin_reply |
| 954 | * |
| 955 | * Description Send the pin_reply to a request from BTM |
| 956 | * |
| 957 | * |
| 958 | * Returns void |
| 959 | * |
| 960 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 961 | void bta_dm_pin_reply(tBTA_DM_MSG* p_data) { |
| 962 | uint32_t trusted_mask[BTM_SEC_SERVICE_ARRAY_SIZE]; |
| 963 | uint32_t* current_trusted_mask; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 964 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 965 | current_trusted_mask = BTM_ReadTrustedMask(p_data->pin_reply.bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 966 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 967 | if (current_trusted_mask) { |
| 968 | memcpy(trusted_mask, current_trusted_mask, sizeof(trusted_mask)); |
| 969 | } else { |
| 970 | memset(trusted_mask, 0, sizeof(trusted_mask)); |
| 971 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 972 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 973 | if (p_data->pin_reply.accept) { |
| 974 | BTM_PINCodeReply(p_data->pin_reply.bd_addr, BTM_SUCCESS, |
| 975 | p_data->pin_reply.pin_len, p_data->pin_reply.p_pin, |
| 976 | trusted_mask); |
| 977 | } else { |
| 978 | BTM_PINCodeReply(p_data->pin_reply.bd_addr, BTM_NOT_AUTHORIZED, 0, NULL, |
| 979 | trusted_mask); |
| 980 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 981 | } |
| 982 | |
| 983 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 984 | * |
| 985 | * Function bta_dm_policy_cback |
| 986 | * |
| 987 | * Description process the link policy changes |
| 988 | * |
| 989 | * Returns void |
| 990 | * |
| 991 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 992 | static void bta_dm_policy_cback(tBTA_SYS_CONN_STATUS status, uint8_t id, |
| 993 | uint8_t app_id, BD_ADDR peer_addr) { |
| 994 | tBTA_DM_PEER_DEVICE* p_dev = NULL; |
| 995 | uint16_t policy = app_id; |
| 996 | uint32_t mask = (uint32_t)(1 << id); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 997 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 998 | if (peer_addr) p_dev = bta_dm_find_peer_device(from_BD_ADDR(peer_addr)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 999 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1000 | APPL_TRACE_DEBUG(" bta_dm_policy_cback cmd:%d, policy:0x%x", status, policy); |
| 1001 | switch (status) { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1002 | case BTA_SYS_PLCY_SET: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1003 | if (!p_dev) return; |
| 1004 | /* restore the default link policy */ |
| 1005 | p_dev->link_policy |= policy; |
| 1006 | BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy)); |
| 1007 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1008 | |
| 1009 | case BTA_SYS_PLCY_CLR: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1010 | if (!p_dev) return; |
| 1011 | /* clear the policy from the default link policy */ |
| 1012 | p_dev->link_policy &= (~policy); |
| 1013 | BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1014 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1015 | if (policy & (HCI_ENABLE_SNIFF_MODE | HCI_ENABLE_PARK_MODE)) { |
| 1016 | /* if clearing sniff/park, wake the link */ |
| 1017 | bta_dm_pm_active(p_dev->peer_bdaddr); |
| 1018 | } |
| 1019 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1020 | |
| 1021 | case BTA_SYS_PLCY_DEF_SET: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1022 | /* want to restore/set the role switch policy */ |
| 1023 | bta_dm_cb.role_policy_mask &= ~mask; |
| 1024 | if (0 == bta_dm_cb.role_policy_mask) { |
| 1025 | /* if nobody wants to insist on the role */ |
| 1026 | bta_dm_cb.cur_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH; |
| 1027 | BTM_SetDefaultLinkPolicy(bta_dm_cb.cur_policy); |
| 1028 | } |
| 1029 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1030 | |
| 1031 | case BTA_SYS_PLCY_DEF_CLR: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1032 | /* want to remove the role switch policy */ |
| 1033 | bta_dm_cb.role_policy_mask |= mask; |
| 1034 | bta_dm_cb.cur_policy &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH; |
| 1035 | BTM_SetDefaultLinkPolicy(bta_dm_cb.cur_policy); |
| 1036 | break; |
| 1037 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1038 | } |
| 1039 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1040 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1041 | * |
| 1042 | * Function bta_dm_confirm |
| 1043 | * |
| 1044 | * Description Send the user confirm request reply in response to a |
| 1045 | * request from BTM |
| 1046 | * |
| 1047 | * Returns void |
| 1048 | * |
| 1049 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1050 | void bta_dm_confirm(tBTA_DM_MSG* p_data) { |
| 1051 | tBTM_STATUS res = BTM_NOT_AUTHORIZED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1052 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1053 | if (p_data->confirm.accept == true) res = BTM_SUCCESS; |
| 1054 | BTM_ConfirmReqReply(res, p_data->confirm.bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1058 | * |
| 1059 | * Function bta_dm_loc_oob |
| 1060 | * |
| 1061 | * Description Retrieve the OOB data from the local LM |
| 1062 | * |
| 1063 | * Returns void |
| 1064 | * |
| 1065 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1066 | void bta_dm_loc_oob(UNUSED_ATTR tBTA_DM_MSG* p_data) { BTM_ReadLocalOobData(); } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1067 | |
| 1068 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1069 | * |
| 1070 | * Function bta_dm_ci_io_req_act |
| 1071 | * |
| 1072 | * Description respond to the IO capabilities request from BTM |
| 1073 | * |
| 1074 | * Returns void |
| 1075 | * |
| 1076 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1077 | void bta_dm_ci_io_req_act(tBTA_DM_MSG* p_data) { |
| 1078 | tBTM_AUTH_REQ auth_req = BTM_AUTH_AP_NO; |
| 1079 | if (p_data->ci_io_req.auth_req) auth_req = BTM_AUTH_AP_YES; |
| 1080 | BTM_IoCapRsp(p_data->ci_io_req.bd_addr, p_data->ci_io_req.io_cap, |
| 1081 | p_data->ci_io_req.oob_data, auth_req); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1085 | * |
| 1086 | * Function bta_dm_ci_rmt_oob_act |
| 1087 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1088 | * Description respond to the OOB data request for the remote device from |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 1089 | * BTM |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1090 | * |
| 1091 | * |
| 1092 | * Returns void |
| 1093 | * |
| 1094 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1095 | void bta_dm_ci_rmt_oob_act(tBTA_DM_MSG* p_data) { |
| 1096 | tBTM_STATUS res = BTM_NOT_AUTHORIZED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1097 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1098 | if (p_data->ci_rmt_oob.accept == true) res = BTM_SUCCESS; |
| 1099 | BTM_RemoteOobDataReply(res, p_data->ci_rmt_oob.bd_addr, p_data->ci_rmt_oob.c, |
| 1100 | p_data->ci_rmt_oob.r); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1101 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1102 | |
| 1103 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1104 | * |
| 1105 | * Function bta_dm_search_start |
| 1106 | * |
| 1107 | * Description Starts an inquiry |
| 1108 | * |
| 1109 | * |
| 1110 | * Returns void |
| 1111 | * |
| 1112 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1113 | void bta_dm_search_start(tBTA_DM_MSG* p_data) { |
| 1114 | tBTM_INQUIRY_CMPL result; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1115 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1116 | size_t len = sizeof(tBT_UUID) * p_data->search.num_uuid; |
| 1117 | bta_dm_gattc_register(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1118 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1119 | APPL_TRACE_DEBUG("%s avoid_scatter=%d", __func__, |
| 1120 | p_bta_dm_cfg->avoid_scatter); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 1121 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1122 | if (p_bta_dm_cfg->avoid_scatter && |
| 1123 | (p_data->search.rs_res == BTA_DM_RS_NONE) && |
| 1124 | bta_dm_check_av(BTA_DM_API_SEARCH_EVT)) { |
| 1125 | memcpy(&bta_dm_cb.search_msg, &p_data->search, sizeof(tBTA_DM_API_SEARCH)); |
| 1126 | return; |
| 1127 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1128 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1129 | BTM_ClearInqDb(NULL); |
| 1130 | /* save search params */ |
| 1131 | bta_dm_search_cb.p_search_cback = p_data->search.p_cback; |
| 1132 | bta_dm_search_cb.services = p_data->search.services; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1133 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1134 | osi_free_and_reset((void**)&bta_dm_search_cb.p_srvc_uuid); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1135 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1136 | if ((bta_dm_search_cb.num_uuid = p_data->search.num_uuid) != 0 && |
| 1137 | p_data->search.p_uuid != NULL) { |
| 1138 | bta_dm_search_cb.p_srvc_uuid = (tBT_UUID*)osi_malloc(len); |
| 1139 | memcpy(bta_dm_search_cb.p_srvc_uuid, p_data->search.p_uuid, len); |
| 1140 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1141 | result.status = BTM_StartInquiry((tBTM_INQ_PARMS*)&p_data->search.inq_params, |
| 1142 | bta_dm_inq_results_cb, |
| 1143 | (tBTM_CMPL_CB*)bta_dm_inq_cmpl_cb); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1144 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1145 | APPL_TRACE_EVENT("%s status=%d", __func__, result.status); |
| 1146 | if (result.status != BTM_CMD_STARTED) { |
| 1147 | result.num_resp = 0; |
| 1148 | bta_dm_inq_cmpl_cb((void*)&result); |
| 1149 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1153 | * |
| 1154 | * Function bta_dm_search_cancel |
| 1155 | * |
| 1156 | * Description Cancels an ongoing search for devices |
| 1157 | * |
| 1158 | * |
| 1159 | * Returns void |
| 1160 | * |
| 1161 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1162 | void bta_dm_search_cancel(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 1163 | tBTA_DM_MSG* p_msg; |
Jack He | db76fa4 | 2016-11-01 11:30:51 -0700 | [diff] [blame] | 1164 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1165 | if (BTM_IsInquiryActive()) { |
| 1166 | if (BTM_CancelInquiry() == BTM_SUCCESS) { |
| 1167 | bta_dm_search_cancel_notify(NULL); |
| 1168 | p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
| 1169 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1170 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 1171 | bta_sys_sendmsg(p_msg); |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 1172 | } else { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1173 | /* flag a search cancel is pending */ |
| 1174 | bta_dm_search_cb.cancel_pending = true; |
Matthew Xie | c358eed | 2015-01-28 17:30:13 -0800 | [diff] [blame] | 1175 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1176 | } |
| 1177 | /* If no Service Search going on then issue cancel remote name in case it is |
| 1178 | active */ |
| 1179 | else if (!bta_dm_search_cb.name_discover_done) { |
| 1180 | BTM_CancelRemoteDeviceName(); |
| 1181 | |
| 1182 | p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
| 1183 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1184 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 1185 | bta_sys_sendmsg(p_msg); |
| 1186 | } else { |
| 1187 | p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
| 1188 | p_msg->hdr.event = BTA_DM_INQUIRY_CMPL_EVT; |
| 1189 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 1190 | bta_sys_sendmsg(p_msg); |
| 1191 | } |
Matthew Xie | c358eed | 2015-01-28 17:30:13 -0800 | [diff] [blame] | 1192 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1193 | if (bta_dm_search_cb.gatt_disc_active) { |
| 1194 | bta_dm_cancel_gatt_discovery(bta_dm_search_cb.peer_bdaddr); |
| 1195 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1199 | * |
| 1200 | * Function bta_dm_discover |
| 1201 | * |
| 1202 | * Description Discovers services on a remote device |
| 1203 | * |
| 1204 | * |
| 1205 | * Returns void |
| 1206 | * |
| 1207 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1208 | void bta_dm_discover(tBTA_DM_MSG* p_data) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1209 | size_t len = sizeof(tBT_UUID) * p_data->discover.num_uuid; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1210 | APPL_TRACE_EVENT("%s services_to_search=0x%04X, sdp_search=%d", __func__, |
| 1211 | p_data->discover.services, p_data->discover.sdp_search); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1212 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1213 | /* save the search condition */ |
| 1214 | bta_dm_search_cb.services = p_data->discover.services; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1215 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1216 | bta_dm_gattc_register(); |
| 1217 | osi_free_and_reset((void**)&bta_dm_search_cb.p_srvc_uuid); |
| 1218 | if ((bta_dm_search_cb.num_uuid = p_data->discover.num_uuid) != 0 && |
| 1219 | p_data->discover.p_uuid != NULL) { |
| 1220 | bta_dm_search_cb.p_srvc_uuid = (tBT_UUID*)osi_malloc(len); |
| 1221 | memcpy(bta_dm_search_cb.p_srvc_uuid, p_data->discover.p_uuid, len); |
| 1222 | } |
| 1223 | bta_dm_search_cb.uuid_to_search = bta_dm_search_cb.num_uuid; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1224 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1225 | bta_dm_search_cb.p_search_cback = p_data->discover.p_cback; |
| 1226 | bta_dm_search_cb.sdp_search = p_data->discover.sdp_search; |
| 1227 | bta_dm_search_cb.services_to_search = bta_dm_search_cb.services; |
| 1228 | bta_dm_search_cb.service_index = 0; |
| 1229 | bta_dm_search_cb.services_found = 0; |
| 1230 | bta_dm_search_cb.peer_name[0] = 0; |
| 1231 | bta_dm_search_cb.sdp_search = p_data->discover.sdp_search; |
| 1232 | bta_dm_search_cb.p_btm_inq_info = BTM_InqDbRead(p_data->discover.bd_addr); |
| 1233 | bta_dm_search_cb.transport = p_data->discover.transport; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1234 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1235 | bta_dm_search_cb.name_discover_done = false; |
| 1236 | memcpy(&bta_dm_search_cb.uuid, &p_data->discover.uuid, sizeof(tSDP_UUID)); |
| 1237 | bta_dm_discover_device(p_data->discover.bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1241 | * |
| 1242 | * Function bta_dm_di_disc_cmpl |
| 1243 | * |
| 1244 | * Description Sends event to application when DI discovery complete |
| 1245 | * |
| 1246 | * Returns void |
| 1247 | * |
| 1248 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1249 | void bta_dm_di_disc_cmpl(tBTA_DM_MSG* p_data) { |
| 1250 | tBTA_DM_DI_DISC_CMPL di_disc; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1251 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1252 | memset(&di_disc, 0, sizeof(tBTA_DM_DI_DISC_CMPL)); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1253 | di_disc.bd_addr = bta_dm_search_cb.peer_bdaddr; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1254 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1255 | if ((p_data->hdr.offset == SDP_SUCCESS) || |
| 1256 | (p_data->hdr.offset == SDP_DB_FULL)) { |
| 1257 | di_disc.num_record = SDP_GetNumDiRecords(bta_dm_di_cb.p_di_db); |
| 1258 | } else |
| 1259 | di_disc.result = BTA_FAILURE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1260 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1261 | bta_dm_di_cb.p_di_db = NULL; |
| 1262 | bta_dm_search_cb.p_search_cback(BTA_DM_DI_DISC_CMPL_EVT, |
| 1263 | (tBTA_DM_SEARCH*)&di_disc); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1267 | * |
| 1268 | * Function bta_dm_di_disc_callback |
| 1269 | * |
| 1270 | * Description This function queries a remote device for DI information. |
| 1271 | * |
| 1272 | * |
| 1273 | * Returns void |
| 1274 | * |
| 1275 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1276 | static void bta_dm_di_disc_callback(uint16_t result) { |
| 1277 | tBTA_DM_MSG* p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1278 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1279 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1280 | p_msg->hdr.layer_specific = BTA_DM_API_DI_DISCOVER_EVT; |
| 1281 | p_msg->hdr.offset = result; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 1282 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1283 | bta_sys_sendmsg(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1287 | * |
| 1288 | * Function bta_dm_disable_search_and_disc |
| 1289 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1290 | * Description Cancels an ongoing search or discovery for devices in case |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 1291 | * of a Bluetooth disable |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1292 | * |
| 1293 | * |
| 1294 | * Returns void |
| 1295 | * |
| 1296 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1297 | static void bta_dm_disable_search_and_disc(void) { |
| 1298 | tBTA_DM_DI_DISC_CMPL di_disc; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1299 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1300 | if (bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE) bta_dm_search_cancel(NULL); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1301 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1302 | if (bta_dm_di_cb.p_di_db != NULL) { |
| 1303 | memset(&di_disc, 0, sizeof(tBTA_DM_DI_DISC_CMPL)); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1304 | di_disc.bd_addr = bta_dm_search_cb.peer_bdaddr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1305 | di_disc.result = BTA_FAILURE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1306 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1307 | bta_dm_di_cb.p_di_db = NULL; |
| 1308 | bta_dm_search_cb.p_search_cback(BTA_DM_DI_DISC_CMPL_EVT, NULL); |
| 1309 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1313 | * |
| 1314 | * Function bta_dm_di_disc |
| 1315 | * |
| 1316 | * Description This function queries a remote device for DI information. |
| 1317 | * |
| 1318 | * |
| 1319 | * Returns void |
| 1320 | * |
| 1321 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1322 | void bta_dm_di_disc(tBTA_DM_MSG* p_data) { |
| 1323 | uint16_t result = BTA_FAILURE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1324 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1325 | bta_dm_search_cb.p_search_cback = p_data->di_disc.p_cback; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1326 | bta_dm_search_cb.peer_bdaddr = p_data->di_disc.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1327 | bta_dm_di_cb.p_di_db = p_data->di_disc.p_sdp_db; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1328 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1329 | bta_dm_search_cb.p_sdp_db = |
| 1330 | (tSDP_DISCOVERY_DB*)osi_malloc(BTA_DM_SDP_DB_SIZE); |
Jakub Pawlowski | 135b7f6 | 2017-06-16 10:00:46 -0700 | [diff] [blame^] | 1331 | if (SDP_DiDiscover(bta_dm_search_cb.peer_bdaddr, p_data->di_disc.p_sdp_db, |
| 1332 | p_data->di_disc.len, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1333 | bta_dm_di_disc_callback) == SDP_SUCCESS) { |
| 1334 | result = BTA_SUCCESS; |
| 1335 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1336 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1337 | if (result == BTA_FAILURE) { |
| 1338 | tBTA_DM_MSG* p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 1339 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1340 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1341 | p_msg->hdr.layer_specific = BTA_DM_API_DI_DISCOVER_EVT; |
| 1342 | p_data->hdr.offset = result; |
| 1343 | bta_sys_sendmsg(p_msg); |
| 1344 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1348 | * |
| 1349 | * Function bta_dm_read_remote_device_name |
| 1350 | * |
| 1351 | * Description Initiate to get remote device name |
| 1352 | * |
| 1353 | * Returns true if started to get remote name |
| 1354 | * |
| 1355 | ******************************************************************************/ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1356 | static bool bta_dm_read_remote_device_name(const bt_bdaddr_t& bd_addr, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1357 | tBT_TRANSPORT transport) { |
| 1358 | tBTM_STATUS btm_status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1359 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1360 | APPL_TRACE_DEBUG("%s", __func__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1361 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1362 | bta_dm_search_cb.peer_bdaddr = bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1363 | bta_dm_search_cb.peer_name[0] = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1364 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1365 | btm_status = |
| 1366 | BTM_ReadRemoteDeviceName(bta_dm_search_cb.peer_bdaddr, |
| 1367 | (tBTM_CMPL_CB*)bta_dm_remname_cback, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1368 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1369 | if (btm_status == BTM_CMD_STARTED) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1370 | APPL_TRACE_DEBUG("%s: BTM_ReadRemoteDeviceName is started", __func__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1371 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1372 | return (true); |
| 1373 | } else if (btm_status == BTM_BUSY) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1374 | APPL_TRACE_DEBUG("%s: BTM_ReadRemoteDeviceName is busy", __func__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1375 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1376 | /* Remote name discovery is on going now so BTM cannot notify through |
| 1377 | * "bta_dm_remname_cback" */ |
| 1378 | /* adding callback to get notified that current reading remore name done */ |
| 1379 | BTM_SecAddRmtNameNotifyCallback(&bta_dm_service_search_remname_cback); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1380 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1381 | return (true); |
| 1382 | } else { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1383 | APPL_TRACE_WARNING("%s: BTM_ReadRemoteDeviceName returns 0x%02X", __func__, |
| 1384 | btm_status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1385 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1386 | return (false); |
| 1387 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1388 | } |
| 1389 | |
| 1390 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1391 | * |
| 1392 | * Function bta_dm_inq_cmpl |
| 1393 | * |
| 1394 | * Description Process the inquiry complete event from BTM |
| 1395 | * |
| 1396 | * Returns void |
| 1397 | * |
| 1398 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1399 | void bta_dm_inq_cmpl(tBTA_DM_MSG* p_data) { |
| 1400 | tBTA_DM_SEARCH data; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1401 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1402 | APPL_TRACE_DEBUG("bta_dm_inq_cmpl"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1403 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1404 | data.inq_cmpl.num_resps = p_data->inq_cmpl.num; |
| 1405 | bta_dm_search_cb.p_search_cback(BTA_DM_INQ_CMPL_EVT, &data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1406 | |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame] | 1407 | bta_dm_search_cb.p_btm_inq_info = BTM_InqDbFirst(); |
| 1408 | if (bta_dm_search_cb.p_btm_inq_info != NULL) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1409 | /* start name and service discovery from the first device on inquiry result |
| 1410 | */ |
| 1411 | bta_dm_search_cb.name_discover_done = false; |
| 1412 | bta_dm_search_cb.peer_name[0] = 0; |
| 1413 | bta_dm_discover_device( |
| 1414 | bta_dm_search_cb.p_btm_inq_info->results.remote_bd_addr); |
| 1415 | } else { |
| 1416 | tBTA_DM_MSG* p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 1417 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1418 | /* no devices, search complete */ |
| 1419 | bta_dm_search_cb.services = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1420 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1421 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1422 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 1423 | bta_sys_sendmsg(p_msg); |
| 1424 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 1425 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1426 | |
| 1427 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1428 | * |
| 1429 | * Function bta_dm_rmt_name |
| 1430 | * |
| 1431 | * Description Process the remote name result from BTM |
| 1432 | * |
| 1433 | * Returns void |
| 1434 | * |
| 1435 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1436 | void bta_dm_rmt_name(tBTA_DM_MSG* p_data) { |
| 1437 | APPL_TRACE_DEBUG("bta_dm_rmt_name"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1438 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1439 | if (p_data->rem_name.result.disc_res.bd_name[0] && |
| 1440 | bta_dm_search_cb.p_btm_inq_info) { |
| 1441 | bta_dm_search_cb.p_btm_inq_info->appl_knows_rem_name = true; |
| 1442 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1443 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1444 | bta_dm_discover_device(bta_dm_search_cb.peer_bdaddr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1448 | * |
| 1449 | * Function bta_dm_disc_rmt_name |
| 1450 | * |
| 1451 | * Description Process the remote name result from BTM when application |
| 1452 | * wants to find the name for a bdaddr |
| 1453 | * |
| 1454 | * Returns void |
| 1455 | * |
| 1456 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1457 | void bta_dm_disc_rmt_name(tBTA_DM_MSG* p_data) { |
| 1458 | tBTM_INQ_INFO* p_btm_inq_info; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1459 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1460 | APPL_TRACE_DEBUG("bta_dm_disc_rmt_name"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1461 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1462 | p_btm_inq_info = BTM_InqDbRead(p_data->rem_name.result.disc_res.bd_addr); |
| 1463 | if (p_btm_inq_info) { |
| 1464 | if (p_data->rem_name.result.disc_res.bd_name[0]) { |
| 1465 | p_btm_inq_info->appl_knows_rem_name = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1466 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1467 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1468 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1469 | bta_dm_discover_device(p_data->rem_name.result.disc_res.bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1470 | } |
| 1471 | |
| 1472 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1473 | * |
| 1474 | * Function bta_dm_sdp_result |
| 1475 | * |
| 1476 | * Description Process the discovery result from sdp |
| 1477 | * |
| 1478 | * Returns void |
| 1479 | * |
| 1480 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1481 | void bta_dm_sdp_result(tBTA_DM_MSG* p_data) { |
| 1482 | tSDP_DISC_REC* p_sdp_rec = NULL; |
| 1483 | tBTA_DM_MSG* p_msg; |
| 1484 | bool scn_found = false; |
| 1485 | uint16_t service = 0xFFFF; |
| 1486 | tSDP_PROTOCOL_ELEM pe; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1487 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1488 | tBT_UUID* p_uuid = bta_dm_search_cb.p_srvc_uuid; |
| 1489 | tBTA_DM_SEARCH result; |
| 1490 | tBT_UUID service_uuid; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1491 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1492 | uint32_t num_uuids = 0; |
| 1493 | uint8_t uuid_list[32][MAX_UUID_SIZE]; // assuming a max of 32 services |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1494 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1495 | if ((p_data->sdp_event.sdp_result == SDP_SUCCESS) || |
| 1496 | (p_data->sdp_event.sdp_result == SDP_NO_RECS_MATCH) || |
| 1497 | (p_data->sdp_event.sdp_result == SDP_DB_FULL)) { |
| 1498 | APPL_TRACE_DEBUG("sdp_result::0x%x", p_data->sdp_event.sdp_result); |
| 1499 | do { |
| 1500 | p_sdp_rec = NULL; |
| 1501 | if (bta_dm_search_cb.service_index == (BTA_USER_SERVICE_ID + 1)) { |
| 1502 | p_sdp_rec = SDP_FindServiceUUIDInDb(bta_dm_search_cb.p_sdp_db, |
| 1503 | &bta_dm_search_cb.uuid, p_sdp_rec); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1504 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1505 | if (p_sdp_rec && SDP_FindProtocolListElemInRec( |
| 1506 | p_sdp_rec, UUID_PROTOCOL_RFCOMM, &pe)) { |
| 1507 | bta_dm_search_cb.peer_scn = (uint8_t)pe.params[0]; |
| 1508 | scn_found = true; |
| 1509 | } |
| 1510 | } else { |
| 1511 | service = |
| 1512 | bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index - 1]; |
| 1513 | p_sdp_rec = |
| 1514 | SDP_FindServiceInDb(bta_dm_search_cb.p_sdp_db, service, p_sdp_rec); |
| 1515 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1516 | /* finished with BR/EDR services, now we check the result for GATT based |
| 1517 | * service UUID */ |
| 1518 | if (bta_dm_search_cb.service_index == BTA_MAX_SERVICE_ID) { |
| 1519 | if (bta_dm_search_cb.uuid_to_search != 0 && p_uuid != NULL) { |
| 1520 | p_uuid += |
| 1521 | (bta_dm_search_cb.num_uuid - bta_dm_search_cb.uuid_to_search); |
| 1522 | /* only support 16 bits UUID for now */ |
| 1523 | service = p_uuid->uu.uuid16; |
| 1524 | } |
| 1525 | /* all GATT based services */ |
| 1526 | do { |
| 1527 | /* find a service record, report it */ |
| 1528 | p_sdp_rec = |
| 1529 | SDP_FindServiceInDb(bta_dm_search_cb.p_sdp_db, 0, p_sdp_rec); |
| 1530 | if (p_sdp_rec) { |
| 1531 | if (SDP_FindServiceUUIDInRec(p_sdp_rec, &service_uuid)) { |
| 1532 | /* send result back to app now, one by one */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1533 | result.disc_ble_res.bd_addr = bta_dm_search_cb.peer_bdaddr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1534 | strlcpy((char*)result.disc_ble_res.bd_name, bta_dm_get_remname(), |
| 1535 | BD_NAME_LEN); |
| 1536 | result.disc_ble_res.service.len = service_uuid.len; |
| 1537 | result.disc_ble_res.service.uu.uuid16 = service_uuid.uu.uuid16; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1538 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1539 | bta_dm_search_cb.p_search_cback(BTA_DM_DISC_BLE_RES_EVT, &result); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1540 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | if (bta_dm_search_cb.uuid_to_search > 0) break; |
| 1544 | |
| 1545 | } while (p_sdp_rec); |
Myles Watson | 9979121 | 2016-11-18 08:42:23 -0800 | [diff] [blame] | 1546 | } else { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1547 | /* SDP_DB_FULL means some records with the |
| 1548 | required attributes were received */ |
| 1549 | if (((p_data->sdp_event.sdp_result == SDP_DB_FULL) && |
| 1550 | bta_dm_search_cb.services != BTA_ALL_SERVICE_MASK) || |
| 1551 | (p_sdp_rec != NULL)) { |
| 1552 | if (service != UUID_SERVCLASS_PNP_INFORMATION) { |
| 1553 | uint16_t tmp_svc = 0xFFFF; |
| 1554 | bta_dm_search_cb.services_found |= |
| 1555 | (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK( |
| 1556 | bta_dm_search_cb.service_index - 1)); |
| 1557 | tmp_svc = |
| 1558 | bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index - |
| 1559 | 1]; |
| 1560 | /* Add to the list of UUIDs */ |
| 1561 | sdpu_uuid16_to_uuid128(tmp_svc, uuid_list[num_uuids]); |
| 1562 | num_uuids++; |
| 1563 | } |
| 1564 | } |
| 1565 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1566 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1567 | if (bta_dm_search_cb.services == BTA_ALL_SERVICE_MASK && |
| 1568 | bta_dm_search_cb.services_to_search == 0) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1569 | if (bta_dm_search_cb.service_index == BTA_BLE_SERVICE_ID && |
| 1570 | bta_dm_search_cb.uuid_to_search > 0) |
| 1571 | bta_dm_search_cb.uuid_to_search--; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1572 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1573 | if (bta_dm_search_cb.uuid_to_search == 0 || |
| 1574 | bta_dm_search_cb.service_index != BTA_BLE_SERVICE_ID) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1575 | bta_dm_search_cb.service_index++; |
| 1576 | } else /* regular one service per search or PNP search */ |
| 1577 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1578 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1579 | } while (bta_dm_search_cb.service_index <= BTA_MAX_SERVICE_ID); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1580 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1581 | APPL_TRACE_DEBUG("%s services_found = %04x", __func__, |
| 1582 | bta_dm_search_cb.services_found); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1583 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1584 | /* Collect the 128-bit services here and put them into the list */ |
| 1585 | if (bta_dm_search_cb.services == BTA_ALL_SERVICE_MASK) { |
| 1586 | p_sdp_rec = NULL; |
| 1587 | do { |
| 1588 | tBT_UUID temp_uuid; |
| 1589 | /* find a service record, report it */ |
| 1590 | p_sdp_rec = |
| 1591 | SDP_FindServiceInDb_128bit(bta_dm_search_cb.p_sdp_db, p_sdp_rec); |
| 1592 | if (p_sdp_rec) { |
| 1593 | if (SDP_FindServiceUUIDInRec_128bit(p_sdp_rec, &temp_uuid)) { |
| 1594 | memcpy(uuid_list[num_uuids], temp_uuid.uu.uuid128, MAX_UUID_SIZE); |
| 1595 | num_uuids++; |
| 1596 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1597 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1598 | } while (p_sdp_rec); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1599 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1600 | /* if there are more services to search for */ |
| 1601 | if (bta_dm_search_cb.services_to_search) { |
| 1602 | /* Free up the p_sdp_db before checking the next one */ |
| 1603 | bta_dm_free_sdp_db(NULL); |
| 1604 | bta_dm_find_services(bta_dm_search_cb.peer_bdaddr); |
| 1605 | } else { |
| 1606 | /* callbacks */ |
| 1607 | /* start next bd_addr if necessary */ |
| 1608 | |
| 1609 | BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback); |
| 1610 | |
| 1611 | p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
| 1612 | p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT; |
| 1613 | p_msg->disc_result.result.disc_res.result = BTA_SUCCESS; |
| 1614 | p_msg->disc_result.result.disc_res.p_raw_data = NULL; |
| 1615 | p_msg->disc_result.result.disc_res.raw_data_size = 0; |
| 1616 | p_msg->disc_result.result.disc_res.num_uuids = num_uuids; |
| 1617 | p_msg->disc_result.result.disc_res.p_uuid_list = NULL; |
| 1618 | if (num_uuids > 0) { |
| 1619 | p_msg->disc_result.result.disc_res.p_uuid_list = |
| 1620 | (uint8_t*)osi_malloc(num_uuids * MAX_UUID_SIZE); |
| 1621 | memcpy(p_msg->disc_result.result.disc_res.p_uuid_list, uuid_list, |
| 1622 | num_uuids * MAX_UUID_SIZE); |
| 1623 | } |
| 1624 | // Copy the raw_data to the discovery result structure |
| 1625 | if (bta_dm_search_cb.p_sdp_db != NULL && |
| 1626 | bta_dm_search_cb.p_sdp_db->raw_used != 0 && |
| 1627 | bta_dm_search_cb.p_sdp_db->raw_data != NULL) { |
| 1628 | APPL_TRACE_DEBUG("%s raw_data used = 0x%x raw_data_ptr = 0x%x", |
| 1629 | __func__, bta_dm_search_cb.p_sdp_db->raw_used, |
| 1630 | bta_dm_search_cb.p_sdp_db->raw_data); |
| 1631 | |
| 1632 | p_msg->disc_result.result.disc_res.p_raw_data = |
| 1633 | (uint8_t*)osi_malloc(bta_dm_search_cb.p_sdp_db->raw_used); |
| 1634 | memcpy(p_msg->disc_result.result.disc_res.p_raw_data, |
| 1635 | bta_dm_search_cb.p_sdp_db->raw_data, |
| 1636 | bta_dm_search_cb.p_sdp_db->raw_used); |
| 1637 | |
| 1638 | p_msg->disc_result.result.disc_res.raw_data_size = |
| 1639 | bta_dm_search_cb.p_sdp_db->raw_used; |
| 1640 | |
| 1641 | bta_dm_search_cb.p_sdp_db->raw_data = |
| 1642 | NULL; // no need to free this - it is a global assigned. |
| 1643 | bta_dm_search_cb.p_sdp_db->raw_used = 0; |
| 1644 | bta_dm_search_cb.p_sdp_db->raw_size = 0; |
| 1645 | } else { |
| 1646 | APPL_TRACE_DEBUG("%s raw data size is 0 or raw_data is null!!", |
| 1647 | __func__); |
| 1648 | } |
| 1649 | /* Done with p_sdp_db. Free it */ |
| 1650 | bta_dm_free_sdp_db(NULL); |
| 1651 | p_msg->disc_result.result.disc_res.services = |
| 1652 | bta_dm_search_cb.services_found; |
| 1653 | |
| 1654 | // Piggy back the SCN over result field |
| 1655 | if (scn_found) { |
| 1656 | p_msg->disc_result.result.disc_res.result = |
| 1657 | (3 + bta_dm_search_cb.peer_scn); |
| 1658 | p_msg->disc_result.result.disc_res.services |= BTA_USER_SERVICE_MASK; |
| 1659 | |
| 1660 | APPL_TRACE_EVENT(" Piggy back the SCN over result field SCN=%d", |
| 1661 | bta_dm_search_cb.peer_scn); |
| 1662 | } |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1663 | p_msg->disc_result.result.disc_res.bd_addr = bta_dm_search_cb.peer_bdaddr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1664 | strlcpy((char*)p_msg->disc_result.result.disc_res.bd_name, |
| 1665 | bta_dm_get_remname(), BD_NAME_LEN); |
| 1666 | |
| 1667 | bta_sys_sendmsg(p_msg); |
| 1668 | } |
| 1669 | } else { |
| 1670 | /* conn failed. No need for timer */ |
| 1671 | if (p_data->sdp_event.sdp_result == SDP_CONN_FAILED || |
| 1672 | p_data->sdp_event.sdp_result == SDP_CONN_REJECTED || |
| 1673 | p_data->sdp_event.sdp_result == SDP_SECURITY_ERR) |
| 1674 | bta_dm_search_cb.wait_disc = false; |
| 1675 | |
| 1676 | /* not able to connect go to next device */ |
| 1677 | if (bta_dm_search_cb.p_sdp_db) |
| 1678 | osi_free_and_reset((void**)&bta_dm_search_cb.p_sdp_db); |
| 1679 | |
| 1680 | BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback); |
| 1681 | |
| 1682 | p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
| 1683 | p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT; |
| 1684 | p_msg->disc_result.result.disc_res.result = BTA_FAILURE; |
| 1685 | p_msg->disc_result.result.disc_res.services = |
| 1686 | bta_dm_search_cb.services_found; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1687 | p_msg->disc_result.result.disc_res.bd_addr = bta_dm_search_cb.peer_bdaddr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1688 | strlcpy((char*)p_msg->disc_result.result.disc_res.bd_name, |
| 1689 | bta_dm_get_remname(), BD_NAME_LEN); |
| 1690 | |
| 1691 | bta_sys_sendmsg(p_msg); |
| 1692 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1696 | * |
| 1697 | * Function bta_dm_search_cmpl |
| 1698 | * |
| 1699 | * Description Sends event to application |
| 1700 | * |
| 1701 | * Returns void |
| 1702 | * |
| 1703 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1704 | void bta_dm_search_cmpl(tBTA_DM_MSG* p_data) { |
| 1705 | APPL_TRACE_EVENT("%s", __func__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1706 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1707 | osi_free_and_reset((void**)&bta_dm_search_cb.p_srvc_uuid); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1708 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1709 | if (p_data->hdr.layer_specific == BTA_DM_API_DI_DISCOVER_EVT) |
| 1710 | bta_dm_di_disc_cmpl(p_data); |
| 1711 | else |
| 1712 | bta_dm_search_cb.p_search_cback(BTA_DM_DISC_CMPL_EVT, NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1716 | * |
| 1717 | * Function bta_dm_disc_result |
| 1718 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1719 | * Description Service discovery result when discovering services on a |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 1720 | * device |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1721 | * |
| 1722 | * Returns void |
| 1723 | * |
| 1724 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1725 | void bta_dm_disc_result(tBTA_DM_MSG* p_data) { |
| 1726 | APPL_TRACE_EVENT("%s", __func__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1727 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1728 | /* if any BR/EDR service discovery has been done, report the event */ |
| 1729 | if ((bta_dm_search_cb.services & |
| 1730 | ((BTA_ALL_SERVICE_MASK | BTA_USER_SERVICE_MASK) & |
| 1731 | ~BTA_BLE_SERVICE_MASK))) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1732 | bta_dm_search_cb.p_search_cback(BTA_DM_DISC_RES_EVT, |
| 1733 | &p_data->disc_result.result); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1734 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1735 | tBTA_DM_MSG* p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 1736 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1737 | /* send a message to change state */ |
| 1738 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1739 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 1740 | bta_sys_sendmsg(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1741 | } |
| 1742 | |
| 1743 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1744 | * |
| 1745 | * Function bta_dm_search_result |
| 1746 | * |
| 1747 | * Description Service discovery result while searching for devices |
| 1748 | * |
| 1749 | * Returns void |
| 1750 | * |
| 1751 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1752 | void bta_dm_search_result(tBTA_DM_MSG* p_data) { |
| 1753 | APPL_TRACE_DEBUG("%s searching:0x%04x, result:0x%04x", __func__, |
| 1754 | bta_dm_search_cb.services, |
| 1755 | p_data->disc_result.result.disc_res.services); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1756 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1757 | /* call back if application wants name discovery or found services that |
| 1758 | * application is searching */ |
| 1759 | if ((!bta_dm_search_cb.services) || |
| 1760 | ((bta_dm_search_cb.services) && |
| 1761 | (p_data->disc_result.result.disc_res.services))) { |
| 1762 | bta_dm_search_cb.p_search_cback(BTA_DM_DISC_RES_EVT, |
| 1763 | &p_data->disc_result.result); |
| 1764 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1765 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1766 | /* if searching did not initiate to create link */ |
| 1767 | if (!bta_dm_search_cb.wait_disc) { |
| 1768 | /* if service searching is done with EIR, don't search next device */ |
| 1769 | if (bta_dm_search_cb.p_btm_inq_info) bta_dm_discover_next_device(); |
| 1770 | } else { |
| 1771 | /* wait until link is disconnected or timeout */ |
| 1772 | bta_dm_search_cb.sdp_results = true; |
| 1773 | alarm_set_on_queue(bta_dm_search_cb.search_timer, |
| 1774 | 1000 * (L2CAP_LINK_INACTIVITY_TOUT + 1), |
| 1775 | bta_dm_search_timer_cback, NULL, btu_bta_alarm_queue); |
| 1776 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1780 | * |
| 1781 | * Function bta_dm_search_timer_cback |
| 1782 | * |
| 1783 | * Description Called when ACL disconnect time is over |
| 1784 | * |
| 1785 | * |
| 1786 | * Returns void |
| 1787 | * |
| 1788 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1789 | static void bta_dm_search_timer_cback(UNUSED_ATTR void* data) { |
| 1790 | APPL_TRACE_EVENT("%s", __func__); |
| 1791 | bta_dm_search_cb.wait_disc = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1792 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1793 | /* proceed with next device */ |
| 1794 | bta_dm_discover_next_device(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1795 | } |
| 1796 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1797 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1798 | * |
| 1799 | * Function bta_dm_free_sdp_db |
| 1800 | * |
| 1801 | * Description Frees SDP data base |
| 1802 | * |
| 1803 | * Returns void |
| 1804 | * |
| 1805 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1806 | void bta_dm_free_sdp_db(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 1807 | osi_free_and_reset((void**)&bta_dm_search_cb.p_sdp_db); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1811 | * |
| 1812 | * Function bta_dm_queue_search |
| 1813 | * |
| 1814 | * Description Queues search command while search is being cancelled |
| 1815 | * |
| 1816 | * Returns void |
| 1817 | * |
| 1818 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1819 | void bta_dm_queue_search(tBTA_DM_MSG* p_data) { |
| 1820 | osi_free(bta_dm_search_cb.p_search_queue); |
| 1821 | bta_dm_search_cb.p_search_queue = |
| 1822 | (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_API_SEARCH)); |
| 1823 | memcpy(bta_dm_search_cb.p_search_queue, p_data, sizeof(tBTA_DM_API_SEARCH)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1827 | * |
| 1828 | * Function bta_dm_queue_disc |
| 1829 | * |
| 1830 | * Description Queues discovery command while search is being cancelled |
| 1831 | * |
| 1832 | * Returns void |
| 1833 | * |
| 1834 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1835 | void bta_dm_queue_disc(tBTA_DM_MSG* p_data) { |
| 1836 | osi_free(bta_dm_search_cb.p_search_queue); |
| 1837 | bta_dm_search_cb.p_search_queue = |
| 1838 | (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_API_DISCOVER)); |
| 1839 | memcpy(bta_dm_search_cb.p_search_queue, p_data, sizeof(tBTA_DM_API_DISCOVER)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1843 | * |
| 1844 | * Function bta_dm_search_clear_queue |
| 1845 | * |
| 1846 | * Description Clears the queue if API search cancel is called |
| 1847 | * |
| 1848 | * Returns void |
| 1849 | * |
| 1850 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1851 | void bta_dm_search_clear_queue(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 1852 | osi_free_and_reset((void**)&bta_dm_search_cb.p_search_queue); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1856 | * |
| 1857 | * Function bta_dm_search_cancel_cmpl |
| 1858 | * |
| 1859 | * Description Search cancel is complete |
| 1860 | * |
| 1861 | * Returns void |
| 1862 | * |
| 1863 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1864 | void bta_dm_search_cancel_cmpl(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 1865 | if (bta_dm_search_cb.p_search_queue) { |
| 1866 | bta_sys_sendmsg(bta_dm_search_cb.p_search_queue); |
| 1867 | bta_dm_search_cb.p_search_queue = NULL; |
| 1868 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1869 | } |
| 1870 | |
| 1871 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1872 | * |
| 1873 | * Function bta_dm_search_cancel_transac_cmpl |
| 1874 | * |
| 1875 | * Description Current Service Discovery or remote name procedure is |
| 1876 | * completed after search cancellation |
| 1877 | * |
| 1878 | * Returns void |
| 1879 | * |
| 1880 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1881 | void bta_dm_search_cancel_transac_cmpl(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 1882 | osi_free_and_reset((void**)&bta_dm_search_cb.p_sdp_db); |
| 1883 | bta_dm_search_cancel_notify(NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1884 | } |
| 1885 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1886 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1887 | * |
| 1888 | * Function bta_dm_search_cancel_notify |
| 1889 | * |
| 1890 | * Description Notify application that search has been cancelled |
| 1891 | * |
| 1892 | * Returns void |
| 1893 | * |
| 1894 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1895 | void bta_dm_search_cancel_notify(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 1896 | if (bta_dm_search_cb.p_search_cback) { |
| 1897 | bta_dm_search_cb.p_search_cback(BTA_DM_SEARCH_CANCEL_CMPL_EVT, NULL); |
| 1898 | } |
| 1899 | if (!bta_dm_search_cb.name_discover_done) { |
| 1900 | BTM_CancelRemoteDeviceName(); |
| 1901 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1902 | if (bta_dm_search_cb.gatt_disc_active) { |
| 1903 | bta_dm_cancel_gatt_discovery(bta_dm_search_cb.peer_bdaddr); |
| 1904 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1905 | } |
| 1906 | |
| 1907 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1908 | * |
| 1909 | * Function bta_dm_find_services |
| 1910 | * |
| 1911 | * Description Starts discovery on a device |
| 1912 | * |
| 1913 | * Returns void |
| 1914 | * |
| 1915 | ******************************************************************************/ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1916 | static void bta_dm_find_services(const bt_bdaddr_t& bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1917 | tSDP_UUID uuid; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1918 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1919 | memset(&uuid, 0, sizeof(tSDP_UUID)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1920 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1921 | while (bta_dm_search_cb.service_index < BTA_MAX_SERVICE_ID) { |
| 1922 | if (bta_dm_search_cb.services_to_search & |
| 1923 | (tBTA_SERVICE_MASK)( |
| 1924 | BTA_SERVICE_ID_TO_SERVICE_MASK(bta_dm_search_cb.service_index))) { |
| 1925 | bta_dm_search_cb.p_sdp_db = |
| 1926 | (tSDP_DISCOVERY_DB*)osi_malloc(BTA_DM_SDP_DB_SIZE); |
| 1927 | APPL_TRACE_DEBUG("bta_dm_search_cb.services = %04x***********", |
| 1928 | bta_dm_search_cb.services); |
| 1929 | /* try to search all services by search based on L2CAP UUID */ |
| 1930 | if (bta_dm_search_cb.services == BTA_ALL_SERVICE_MASK) { |
| 1931 | LOG_INFO(LOG_TAG, "%s services_to_search=%08x", __func__, |
| 1932 | bta_dm_search_cb.services_to_search); |
| 1933 | if (bta_dm_search_cb.services_to_search & BTA_RES_SERVICE_MASK) { |
| 1934 | uuid.uu.uuid16 = bta_service_id_to_uuid_lkup_tbl[0]; |
| 1935 | bta_dm_search_cb.services_to_search &= ~BTA_RES_SERVICE_MASK; |
| 1936 | } else { |
| 1937 | uuid.uu.uuid16 = UUID_PROTOCOL_L2CAP; |
| 1938 | bta_dm_search_cb.services_to_search = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1939 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1940 | } else { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1941 | /* for LE only profile */ |
| 1942 | if (bta_dm_search_cb.service_index == BTA_BLE_SERVICE_ID) { |
| 1943 | if (bta_dm_search_cb.uuid_to_search > 0 && |
| 1944 | bta_dm_search_cb.p_srvc_uuid) { |
| 1945 | memcpy(&uuid, (const void*)(bta_dm_search_cb.p_srvc_uuid + |
| 1946 | bta_dm_search_cb.num_uuid - |
| 1947 | bta_dm_search_cb.uuid_to_search), |
| 1948 | sizeof(tBT_UUID)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1949 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1950 | bta_dm_search_cb.uuid_to_search--; |
| 1951 | } else { |
| 1952 | uuid.uu.uuid16 = |
| 1953 | bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index]; |
| 1954 | } |
| 1955 | |
| 1956 | /* last one? clear the BLE service bit if all discovery has been done |
| 1957 | */ |
| 1958 | if (bta_dm_search_cb.uuid_to_search == 0) |
| 1959 | bta_dm_search_cb.services_to_search &= |
| 1960 | (tBTA_SERVICE_MASK)(~(BTA_SERVICE_ID_TO_SERVICE_MASK( |
| 1961 | bta_dm_search_cb.service_index))); |
| 1962 | |
Myles Watson | 9979121 | 2016-11-18 08:42:23 -0800 | [diff] [blame] | 1963 | } else { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1964 | /* remove the service from services to be searched */ |
| 1965 | bta_dm_search_cb.services_to_search &= (tBTA_SERVICE_MASK)(~( |
| 1966 | BTA_SERVICE_ID_TO_SERVICE_MASK(bta_dm_search_cb.service_index))); |
| 1967 | uuid.uu.uuid16 = |
| 1968 | bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index]; |
| 1969 | } |
| 1970 | } |
| 1971 | |
| 1972 | if (uuid.len == 0) uuid.len = LEN_UUID_16; |
| 1973 | |
| 1974 | if (bta_dm_search_cb.service_index == BTA_USER_SERVICE_ID) { |
| 1975 | memcpy(&uuid, &bta_dm_search_cb.uuid, sizeof(tSDP_UUID)); |
| 1976 | } |
| 1977 | |
| 1978 | LOG_INFO(LOG_TAG, "%s search UUID = %04x", __func__, uuid.uu.uuid16); |
| 1979 | SDP_InitDiscoveryDb(bta_dm_search_cb.p_sdp_db, BTA_DM_SDP_DB_SIZE, 1, |
| 1980 | &uuid, 0, NULL); |
| 1981 | |
| 1982 | memset(g_disc_raw_data_buf, 0, sizeof(g_disc_raw_data_buf)); |
| 1983 | bta_dm_search_cb.p_sdp_db->raw_data = g_disc_raw_data_buf; |
| 1984 | |
| 1985 | bta_dm_search_cb.p_sdp_db->raw_size = MAX_DISC_RAW_DATA_BUF; |
| 1986 | |
Jakub Pawlowski | 135b7f6 | 2017-06-16 10:00:46 -0700 | [diff] [blame^] | 1987 | if (!SDP_ServiceSearchAttributeRequest(bd_addr, bta_dm_search_cb.p_sdp_db, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1988 | &bta_dm_sdp_callback)) { |
| 1989 | /* |
| 1990 | * If discovery is not successful with this device, then |
| 1991 | * proceed with the next one. |
| 1992 | */ |
| 1993 | osi_free_and_reset((void**)&bta_dm_search_cb.p_sdp_db); |
| 1994 | bta_dm_search_cb.service_index = BTA_MAX_SERVICE_ID; |
| 1995 | |
| 1996 | } else { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1997 | if ((bta_dm_search_cb.service_index == BTA_BLE_SERVICE_ID && |
| 1998 | bta_dm_search_cb.uuid_to_search == 0) || |
| 1999 | bta_dm_search_cb.service_index != BTA_BLE_SERVICE_ID) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2000 | bta_dm_search_cb.service_index++; |
| 2001 | return; |
| 2002 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2003 | } |
| 2004 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2005 | bta_dm_search_cb.service_index++; |
| 2006 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2007 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2008 | /* no more services to be discovered */ |
| 2009 | if (bta_dm_search_cb.service_index >= BTA_MAX_SERVICE_ID) { |
| 2010 | tBTA_DM_MSG* p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
Manu Viswanadhan | 65cca8f | 2016-06-07 16:21:18 +0530 | [diff] [blame] | 2011 | /* initialize the data structure - includes p_raw_data and raw_data_size */ |
| 2012 | memset(&(p_msg->disc_result.result), 0, sizeof(tBTA_DM_DISC_RES)); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2013 | p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT; |
| 2014 | p_msg->disc_result.result.disc_res.services = |
| 2015 | bta_dm_search_cb.services_found; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2016 | p_msg->disc_result.result.disc_res.bd_addr = bta_dm_search_cb.peer_bdaddr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2017 | strlcpy((char*)p_msg->disc_result.result.disc_res.bd_name, |
| 2018 | bta_dm_get_remname(), BD_NAME_LEN); |
| 2019 | |
| 2020 | bta_sys_sendmsg(p_msg); |
| 2021 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2025 | * |
| 2026 | * Function bta_dm_discover_next_device |
| 2027 | * |
| 2028 | * Description Starts discovery on the next device in Inquiry data base |
| 2029 | * |
| 2030 | * Returns void |
| 2031 | * |
| 2032 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2033 | static void bta_dm_discover_next_device(void) { |
| 2034 | APPL_TRACE_DEBUG("bta_dm_discover_next_device"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2035 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2036 | /* searching next device on inquiry result */ |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame] | 2037 | bta_dm_search_cb.p_btm_inq_info = |
| 2038 | BTM_InqDbNext(bta_dm_search_cb.p_btm_inq_info); |
| 2039 | if (bta_dm_search_cb.p_btm_inq_info != NULL) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2040 | bta_dm_search_cb.name_discover_done = false; |
| 2041 | bta_dm_search_cb.peer_name[0] = 0; |
| 2042 | bta_dm_discover_device( |
| 2043 | bta_dm_search_cb.p_btm_inq_info->results.remote_bd_addr); |
| 2044 | } else { |
| 2045 | tBTA_DM_MSG* p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2046 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2047 | /* no devices, search complete */ |
| 2048 | bta_dm_search_cb.services = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2049 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2050 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 2051 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2052 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2053 | bta_sys_sendmsg(p_msg); |
| 2054 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2058 | * |
| 2059 | * Function bta_dm_discover_device |
| 2060 | * |
| 2061 | * Description Starts name and service discovery on the device |
| 2062 | * |
| 2063 | * Returns void |
| 2064 | * |
| 2065 | ******************************************************************************/ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2066 | static void bta_dm_discover_device(const bt_bdaddr_t& remote_bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2067 | tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2068 | if (bta_dm_search_cb.transport == BTA_TRANSPORT_UNKNOWN) { |
| 2069 | tBT_DEVICE_TYPE dev_type; |
| 2070 | tBLE_ADDR_TYPE addr_type; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2071 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2072 | BTM_ReadDevInfo(remote_bd_addr, &dev_type, &addr_type); |
| 2073 | if (dev_type == BT_DEVICE_TYPE_BLE || addr_type == BLE_ADDR_RANDOM) |
| 2074 | transport = BT_TRANSPORT_LE; |
| 2075 | } else { |
| 2076 | transport = bta_dm_search_cb.transport; |
| 2077 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2078 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2079 | /* Reset transport state for next discovery */ |
| 2080 | bta_dm_search_cb.transport = BTA_TRANSPORT_UNKNOWN; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2081 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2082 | VLOG(1) << __func__ << " BDA: " << remote_bd_addr; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2083 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2084 | bta_dm_search_cb.peer_bdaddr = remote_bd_addr; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2085 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2086 | APPL_TRACE_DEBUG( |
| 2087 | "%s name_discover_done = %d p_btm_inq_info 0x%x state = %d, transport=%d", |
| 2088 | __func__, bta_dm_search_cb.name_discover_done, |
| 2089 | bta_dm_search_cb.p_btm_inq_info, bta_dm_search_cb.state, transport); |
Nitin Arora | b4365c5 | 2015-06-25 18:30:09 -0700 | [diff] [blame] | 2090 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2091 | if (bta_dm_search_cb.p_btm_inq_info) { |
| 2092 | APPL_TRACE_DEBUG("%s appl_knows_rem_name %d", __func__, |
| 2093 | bta_dm_search_cb.p_btm_inq_info->appl_knows_rem_name); |
| 2094 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2095 | if ((bta_dm_search_cb.p_btm_inq_info) && |
| 2096 | (bta_dm_search_cb.p_btm_inq_info->results.device_type == |
| 2097 | BT_DEVICE_TYPE_BLE) && |
| 2098 | (bta_dm_search_cb.state == BTA_DM_SEARCH_ACTIVE)) { |
| 2099 | /* Do not perform RNR for LE devices at inquiry complete*/ |
| 2100 | bta_dm_search_cb.name_discover_done = true; |
| 2101 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2102 | /* if name discovery is not done and application needs remote name */ |
| 2103 | if ((!bta_dm_search_cb.name_discover_done) && |
| 2104 | ((bta_dm_search_cb.p_btm_inq_info == NULL) || |
| 2105 | (bta_dm_search_cb.p_btm_inq_info && |
| 2106 | (!bta_dm_search_cb.p_btm_inq_info->appl_knows_rem_name)))) { |
| 2107 | if (bta_dm_read_remote_device_name(bta_dm_search_cb.peer_bdaddr, |
| 2108 | transport) == true) |
| 2109 | return; |
Nitin Arora | b4365c5 | 2015-06-25 18:30:09 -0700 | [diff] [blame] | 2110 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2111 | /* starting name discovery failed */ |
| 2112 | bta_dm_search_cb.name_discover_done = true; |
| 2113 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2114 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2115 | /* if application wants to discover service */ |
| 2116 | if (bta_dm_search_cb.services) { |
| 2117 | /* initialize variables */ |
| 2118 | bta_dm_search_cb.service_index = 0; |
| 2119 | bta_dm_search_cb.services_found = 0; |
| 2120 | bta_dm_search_cb.services_to_search = bta_dm_search_cb.services; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2121 | bta_dm_search_cb.uuid_to_search = bta_dm_search_cb.num_uuid; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2122 | if ((bta_dm_search_cb.p_btm_inq_info != NULL) && |
| 2123 | bta_dm_search_cb.services != BTA_USER_SERVICE_MASK && |
| 2124 | (bta_dm_search_cb.sdp_search == false)) { |
| 2125 | /* check if EIR provides the information of supported services */ |
| 2126 | bta_dm_eir_search_services(&bta_dm_search_cb.p_btm_inq_info->results, |
| 2127 | &bta_dm_search_cb.services_to_search, |
| 2128 | &bta_dm_search_cb.services_found); |
| 2129 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2130 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2131 | /* if seaching with EIR is not completed */ |
| 2132 | if (bta_dm_search_cb.services_to_search) { |
| 2133 | /* check whether connection already exists to the device |
| 2134 | if connection exists, we don't have to wait for ACL |
| 2135 | link to go down to start search on next device */ |
| 2136 | if (BTM_IsAclConnectionUp(bta_dm_search_cb.peer_bdaddr, |
| 2137 | BT_TRANSPORT_BR_EDR)) |
| 2138 | bta_dm_search_cb.wait_disc = false; |
| 2139 | else |
| 2140 | bta_dm_search_cb.wait_disc = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2141 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2142 | if (bta_dm_search_cb.p_btm_inq_info) { |
| 2143 | APPL_TRACE_DEBUG( |
| 2144 | "%s p_btm_inq_info 0x%x results.device_type 0x%x " |
| 2145 | "services_to_search 0x%x", |
| 2146 | __func__, bta_dm_search_cb.p_btm_inq_info, |
| 2147 | bta_dm_search_cb.p_btm_inq_info->results.device_type, |
| 2148 | bta_dm_search_cb.services_to_search); |
| 2149 | } |
Chaojing Sun | e280553 | 2015-04-22 13:40:21 -0700 | [diff] [blame] | 2150 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2151 | if (transport == BT_TRANSPORT_LE) { |
| 2152 | if (bta_dm_search_cb.services_to_search & BTA_BLE_SERVICE_MASK) { |
| 2153 | // set the raw data buffer here |
| 2154 | memset(g_disc_raw_data_buf, 0, sizeof(g_disc_raw_data_buf)); |
| 2155 | bta_dm_search_cb.p_ble_rawdata = g_disc_raw_data_buf; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2156 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2157 | bta_dm_search_cb.ble_raw_size = MAX_DISC_RAW_DATA_BUF; |
| 2158 | bta_dm_search_cb.ble_raw_used = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2159 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2160 | /* start GATT for service discovery */ |
| 2161 | btm_dm_start_gatt_discovery(bta_dm_search_cb.peer_bdaddr); |
| 2162 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2163 | } |
Myles Watson | 9979121 | 2016-11-18 08:42:23 -0800 | [diff] [blame] | 2164 | } else { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2165 | bta_dm_search_cb.sdp_results = false; |
| 2166 | bta_dm_find_services(bta_dm_search_cb.peer_bdaddr); |
| 2167 | return; |
| 2168 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2169 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2170 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2171 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2172 | /* name discovery and service discovery are done for this device */ |
| 2173 | tBTA_DM_MSG* p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
| 2174 | p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT; |
| 2175 | /* initialize the data structure - includes p_raw_data and raw_data_size */ |
| 2176 | memset(&(p_msg->disc_result.result), 0, sizeof(tBTA_DM_DISC_RES)); |
| 2177 | p_msg->disc_result.result.disc_res.result = BTA_SUCCESS; |
| 2178 | p_msg->disc_result.result.disc_res.services = bta_dm_search_cb.services_found; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2179 | p_msg->disc_result.result.disc_res.bd_addr = bta_dm_search_cb.peer_bdaddr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2180 | strlcpy((char*)p_msg->disc_result.result.disc_res.bd_name, |
| 2181 | (char*)bta_dm_search_cb.peer_name, BD_NAME_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2182 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2183 | bta_sys_sendmsg(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2184 | } |
| 2185 | |
| 2186 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2187 | * |
| 2188 | * Function bta_dm_sdp_callback |
| 2189 | * |
| 2190 | * Description Callback from sdp with discovery status |
| 2191 | * |
| 2192 | * Returns void |
| 2193 | * |
| 2194 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2195 | static void bta_dm_sdp_callback(uint16_t sdp_status) { |
| 2196 | tBTA_DM_SDP_RESULT* p_msg = |
| 2197 | (tBTA_DM_SDP_RESULT*)osi_malloc(sizeof(tBTA_DM_SDP_RESULT)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2198 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2199 | p_msg->hdr.event = BTA_DM_SDP_RESULT_EVT; |
| 2200 | p_msg->sdp_result = sdp_status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2201 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2202 | bta_sys_sendmsg(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2206 | * |
| 2207 | * Function bta_dm_inq_results_cb |
| 2208 | * |
| 2209 | * Description Inquiry results callback from BTM |
| 2210 | * |
| 2211 | * Returns void |
| 2212 | * |
| 2213 | ******************************************************************************/ |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 2214 | static void bta_dm_inq_results_cb(tBTM_INQ_RESULTS* p_inq, uint8_t* p_eir, |
Jakub Pawlowski | f7100bb | 2017-02-13 14:31:52 -0800 | [diff] [blame] | 2215 | uint16_t eir_len) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2216 | tBTA_DM_SEARCH result; |
| 2217 | tBTM_INQ_INFO* p_inq_info; |
| 2218 | uint16_t service_class; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2219 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2220 | result.inq_res.bd_addr = p_inq->remote_bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2221 | memcpy(result.inq_res.dev_class, p_inq->dev_class, DEV_CLASS_LEN); |
| 2222 | BTM_COD_SERVICE_CLASS(service_class, p_inq->dev_class); |
| 2223 | result.inq_res.is_limited = |
| 2224 | (service_class & BTM_COD_SERVICE_LMTD_DISCOVER) ? true : false; |
| 2225 | result.inq_res.rssi = p_inq->rssi; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2226 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2227 | result.inq_res.ble_addr_type = p_inq->ble_addr_type; |
| 2228 | result.inq_res.inq_result_type = p_inq->inq_result_type; |
| 2229 | result.inq_res.device_type = p_inq->device_type; |
| 2230 | result.inq_res.flag = p_inq->flag; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2231 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2232 | /* application will parse EIR to find out remote device name */ |
| 2233 | result.inq_res.p_eir = p_eir; |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 2234 | result.inq_res.eir_len = eir_len; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2235 | |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame] | 2236 | p_inq_info = BTM_InqDbRead(p_inq->remote_bd_addr); |
| 2237 | if (p_inq_info != NULL) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2238 | /* initialize remt_name_not_required to false so that we get the name by |
| 2239 | * default */ |
| 2240 | result.inq_res.remt_name_not_required = false; |
| 2241 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2242 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2243 | if (bta_dm_search_cb.p_search_cback) |
| 2244 | bta_dm_search_cb.p_search_cback(BTA_DM_INQ_RES_EVT, &result); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2245 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2246 | if (p_inq_info) { |
| 2247 | /* application indicates if it knows the remote name, inside the callback |
| 2248 | copy that to the inquiry data base*/ |
| 2249 | if (result.inq_res.remt_name_not_required) |
| 2250 | p_inq_info->appl_knows_rem_name = true; |
| 2251 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2252 | } |
| 2253 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2254 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2255 | * |
| 2256 | * Function bta_dm_inq_cmpl_cb |
| 2257 | * |
| 2258 | * Description Inquiry complete callback from BTM |
| 2259 | * |
| 2260 | * Returns void |
| 2261 | * |
| 2262 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2263 | static void bta_dm_inq_cmpl_cb(void* p_result) { |
| 2264 | tBTA_DM_MSG* p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2265 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2266 | APPL_TRACE_DEBUG("%s", __func__); |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2267 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2268 | if (bta_dm_search_cb.cancel_pending == false) { |
| 2269 | p_msg->inq_cmpl.hdr.event = BTA_DM_INQUIRY_CMPL_EVT; |
| 2270 | p_msg->inq_cmpl.num = ((tBTM_INQUIRY_CMPL*)p_result)->num_resp; |
| 2271 | } else { |
| 2272 | bta_dm_search_cb.cancel_pending = false; |
| 2273 | bta_dm_search_cancel_notify(NULL); |
| 2274 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 2275 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 2276 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2277 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2278 | bta_sys_sendmsg(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2282 | * |
| 2283 | * Function bta_dm_service_search_remname_cback |
| 2284 | * |
| 2285 | * Description Remote name call back from BTM during service discovery |
| 2286 | * |
| 2287 | * Returns void |
| 2288 | * |
| 2289 | ******************************************************************************/ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2290 | static void bta_dm_service_search_remname_cback(const bt_bdaddr_t& bd_addr, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2291 | UNUSED_ATTR DEV_CLASS dc, |
| 2292 | BD_NAME bd_name) { |
| 2293 | tBTM_REMOTE_DEV_NAME rem_name; |
| 2294 | tBTM_STATUS btm_status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2295 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2296 | APPL_TRACE_DEBUG("%s name=<%s>", __func__, bd_name); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2297 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2298 | /* if this is what we are looking for */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2299 | if (bta_dm_search_cb.peer_bdaddr == bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2300 | rem_name.length = strlen((char*)bd_name); |
| 2301 | if (rem_name.length > (BD_NAME_LEN - 1)) { |
| 2302 | rem_name.length = (BD_NAME_LEN - 1); |
| 2303 | rem_name.remote_bd_name[(BD_NAME_LEN - 1)] = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2304 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2305 | strlcpy((char*)rem_name.remote_bd_name, (char*)bd_name, BD_NAME_LEN); |
| 2306 | rem_name.status = BTM_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2307 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2308 | bta_dm_remname_cback(&rem_name); |
| 2309 | } else { |
| 2310 | /* get name of device */ |
| 2311 | btm_status = BTM_ReadRemoteDeviceName(bta_dm_search_cb.peer_bdaddr, |
| 2312 | (tBTM_CMPL_CB*)bta_dm_remname_cback, |
| 2313 | BT_TRANSPORT_BR_EDR); |
| 2314 | if (btm_status == BTM_BUSY) { |
| 2315 | /* wait for next chance(notification of remote name discovery done) */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2316 | APPL_TRACE_DEBUG("%s: BTM_ReadRemoteDeviceName is busy", __func__); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2317 | } else if (btm_status != BTM_CMD_STARTED) { |
| 2318 | /* if failed to start getting remote name then continue */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2319 | APPL_TRACE_WARNING("%s: BTM_ReadRemoteDeviceName returns 0x%02X", |
| 2320 | __func__, btm_status); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2321 | |
| 2322 | rem_name.length = 0; |
| 2323 | rem_name.remote_bd_name[0] = 0; |
| 2324 | rem_name.status = btm_status; |
| 2325 | bta_dm_remname_cback(&rem_name); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2326 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2327 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2328 | } |
| 2329 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2330 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2331 | * |
| 2332 | * Function bta_dm_remname_cback |
| 2333 | * |
| 2334 | * Description Remote name complete call back from BTM |
| 2335 | * |
| 2336 | * Returns void |
| 2337 | * |
| 2338 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2339 | static void bta_dm_remname_cback(tBTM_REMOTE_DEV_NAME* p_remote_name) { |
| 2340 | APPL_TRACE_DEBUG("bta_dm_remname_cback len = %d name=<%s>", |
| 2341 | p_remote_name->length, p_remote_name->remote_bd_name); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2342 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2343 | /* remote name discovery is done but it could be failed */ |
| 2344 | bta_dm_search_cb.name_discover_done = true; |
| 2345 | strlcpy((char*)bta_dm_search_cb.peer_name, |
| 2346 | (char*)p_remote_name->remote_bd_name, BD_NAME_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2347 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2348 | BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2349 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2350 | if (bta_dm_search_cb.transport == BT_TRANSPORT_LE) { |
| 2351 | GAP_BleReadPeerPrefConnParams(bta_dm_search_cb.peer_bdaddr); |
| 2352 | } |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 2353 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2354 | tBTA_DM_REM_NAME* p_msg = |
| 2355 | (tBTA_DM_REM_NAME*)osi_malloc(sizeof(tBTA_DM_REM_NAME)); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2356 | p_msg->result.disc_res.bd_addr = bta_dm_search_cb.peer_bdaddr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2357 | strlcpy((char*)p_msg->result.disc_res.bd_name, |
| 2358 | (char*)p_remote_name->remote_bd_name, BD_NAME_LEN); |
| 2359 | p_msg->hdr.event = BTA_DM_REMT_NAME_EVT; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2360 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2361 | bta_sys_sendmsg(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2365 | * |
| 2366 | * Function bta_dm_authorize_cback |
| 2367 | * |
| 2368 | * Description cback requesting authorization |
| 2369 | * |
| 2370 | * Returns void |
| 2371 | * |
| 2372 | ******************************************************************************/ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2373 | static uint8_t bta_dm_authorize_cback(const bt_bdaddr_t& bd_addr, |
| 2374 | DEV_CLASS dev_class, BD_NAME bd_name, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2375 | UNUSED_ATTR uint8_t* service_name, |
| 2376 | uint8_t service_id, |
| 2377 | UNUSED_ATTR bool is_originator) { |
| 2378 | tBTA_DM_SEC sec_event; |
| 2379 | uint8_t index = 1; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2380 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2381 | sec_event.authorize.bd_addr = bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2382 | memcpy(sec_event.authorize.dev_class, dev_class, DEV_CLASS_LEN); |
| 2383 | strlcpy((char*)sec_event.authorize.bd_name, (char*)bd_name, BD_NAME_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2384 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 2385 | #if (BTA_JV_INCLUDED == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2386 | sec_event.authorize.service = service_id; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2387 | #endif |
| 2388 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2389 | while (index < BTA_MAX_SERVICE_ID) { |
| 2390 | /* get the BTA service id corresponding to BTM id */ |
| 2391 | if (bta_service_id_to_btm_srv_id_lkup_tbl[index] == service_id) { |
| 2392 | sec_event.authorize.service = index; |
| 2393 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2394 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2395 | index++; |
| 2396 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2397 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2398 | /* if supported service callback otherwise not authorized */ |
| 2399 | if (bta_dm_cb.p_sec_cback && (index < BTA_MAX_SERVICE_ID |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 2400 | #if (BTA_JV_INCLUDED == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2401 | /* pass through JV service ID */ |
| 2402 | || (service_id >= BTA_FIRST_JV_SERVICE_ID && |
| 2403 | service_id <= BTA_LAST_JV_SERVICE_ID) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2404 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2405 | )) { |
| 2406 | bta_dm_cb.p_sec_cback(BTA_DM_AUTHORIZE_EVT, &sec_event); |
| 2407 | return BTM_CMD_STARTED; |
| 2408 | } else { |
| 2409 | return BTM_NOT_AUTHORIZED; |
| 2410 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2411 | } |
| 2412 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2413 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2414 | * |
| 2415 | * Function bta_dm_pinname_cback |
| 2416 | * |
| 2417 | * Description Callback requesting pin_key |
| 2418 | * |
| 2419 | * Returns void |
| 2420 | * |
| 2421 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2422 | static void bta_dm_pinname_cback(void* p_data) { |
| 2423 | tBTM_REMOTE_DEV_NAME* p_result = (tBTM_REMOTE_DEV_NAME*)p_data; |
| 2424 | tBTA_DM_SEC sec_event; |
| 2425 | uint32_t bytes_to_copy; |
| 2426 | tBTA_DM_SEC_EVT event = bta_dm_cb.pin_evt; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2427 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2428 | if (BTA_DM_SP_CFM_REQ_EVT == event) { |
| 2429 | /* Retrieved saved device class and bd_addr */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2430 | sec_event.cfm_req.bd_addr = bta_dm_cb.pin_bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2431 | BTA_COPY_DEVICE_CLASS(sec_event.cfm_req.dev_class, bta_dm_cb.pin_dev_class); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2432 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2433 | if (p_result && p_result->status == BTM_SUCCESS) { |
| 2434 | bytes_to_copy = (p_result->length < (BD_NAME_LEN - 1)) |
| 2435 | ? p_result->length |
| 2436 | : (BD_NAME_LEN - 1); |
| 2437 | memcpy(sec_event.cfm_req.bd_name, p_result->remote_bd_name, |
| 2438 | bytes_to_copy); |
| 2439 | sec_event.pin_req.bd_name[BD_NAME_LEN - 1] = 0; |
| 2440 | } else /* No name found */ |
| 2441 | sec_event.cfm_req.bd_name[0] = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2442 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2443 | sec_event.key_notif.passkey = |
| 2444 | bta_dm_cb.num_val; /* get PIN code numeric number */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2445 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2446 | /* 1 additional event data fields for this event */ |
| 2447 | sec_event.cfm_req.just_works = bta_dm_cb.just_works; |
| 2448 | } else { |
| 2449 | /* Retrieved saved device class and bd_addr */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2450 | sec_event.pin_req.bd_addr = bta_dm_cb.pin_bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2451 | BTA_COPY_DEVICE_CLASS(sec_event.pin_req.dev_class, bta_dm_cb.pin_dev_class); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2452 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2453 | if (p_result && p_result->status == BTM_SUCCESS) { |
| 2454 | bytes_to_copy = (p_result->length < (BD_NAME_LEN - 1)) |
| 2455 | ? p_result->length |
| 2456 | : (BD_NAME_LEN - 1); |
| 2457 | memcpy(sec_event.pin_req.bd_name, p_result->remote_bd_name, |
| 2458 | bytes_to_copy); |
| 2459 | sec_event.pin_req.bd_name[BD_NAME_LEN - 1] = 0; |
| 2460 | } else /* No name found */ |
| 2461 | sec_event.pin_req.bd_name[0] = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2462 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2463 | event = bta_dm_cb.pin_evt; |
| 2464 | sec_event.key_notif.passkey = |
| 2465 | bta_dm_cb.num_val; /* get PIN code numeric number */ |
| 2466 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2467 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2468 | if (bta_dm_cb.p_sec_cback) bta_dm_cb.p_sec_cback(event, &sec_event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2469 | } |
| 2470 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2471 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2472 | * |
| 2473 | * Function bta_dm_pin_cback |
| 2474 | * |
| 2475 | * Description Callback requesting pin_key |
| 2476 | * |
| 2477 | * Returns void |
| 2478 | * |
| 2479 | ******************************************************************************/ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2480 | static uint8_t bta_dm_pin_cback(const bt_bdaddr_t& bd_addr, DEV_CLASS dev_class, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2481 | BD_NAME bd_name, bool min_16_digit) { |
| 2482 | tBTA_DM_SEC sec_event; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2483 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2484 | if (!bta_dm_cb.p_sec_cback) return BTM_NOT_AUTHORIZED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2485 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2486 | /* If the device name is not known, save bdaddr and devclass and initiate a |
| 2487 | * name request */ |
| 2488 | if (bd_name[0] == 0) { |
| 2489 | bta_dm_cb.pin_evt = BTA_DM_PIN_REQ_EVT; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2490 | bta_dm_cb.pin_bd_addr = bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2491 | BTA_COPY_DEVICE_CLASS(bta_dm_cb.pin_dev_class, dev_class); |
| 2492 | if ((BTM_ReadRemoteDeviceName(bd_addr, bta_dm_pinname_cback, |
| 2493 | BT_TRANSPORT_BR_EDR)) == BTM_CMD_STARTED) |
| 2494 | return BTM_CMD_STARTED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2495 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2496 | APPL_TRACE_WARNING( |
| 2497 | " bta_dm_pin_cback() -> Failed to start Remote Name Request "); |
| 2498 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2499 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2500 | sec_event.pin_req.bd_addr = bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2501 | BTA_COPY_DEVICE_CLASS(sec_event.pin_req.dev_class, dev_class); |
| 2502 | strlcpy((char*)sec_event.pin_req.bd_name, (char*)bd_name, BD_NAME_LEN); |
| 2503 | sec_event.pin_req.min_16_digit = min_16_digit; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2504 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2505 | bta_dm_cb.p_sec_cback(BTA_DM_PIN_REQ_EVT, &sec_event); |
| 2506 | return BTM_CMD_STARTED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2507 | } |
| 2508 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2509 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2510 | * |
| 2511 | * Function bta_dm_new_link_key_cback |
| 2512 | * |
| 2513 | * Description Callback from BTM to notify new link key |
| 2514 | * |
| 2515 | * Returns void |
| 2516 | * |
| 2517 | ******************************************************************************/ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2518 | static uint8_t bta_dm_new_link_key_cback(const bt_bdaddr_t& bd_addr, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2519 | UNUSED_ATTR DEV_CLASS dev_class, |
| 2520 | BD_NAME bd_name, LINK_KEY key, |
| 2521 | uint8_t key_type) { |
| 2522 | tBTA_DM_SEC sec_event; |
| 2523 | tBTA_DM_AUTH_CMPL* p_auth_cmpl; |
| 2524 | uint8_t event; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2525 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2526 | memset(&sec_event, 0, sizeof(tBTA_DM_SEC)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2527 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2528 | /* Not AMP Key type */ |
| 2529 | if (key_type != HCI_LKEY_TYPE_AMP_WIFI && key_type != HCI_LKEY_TYPE_AMP_UWB) { |
| 2530 | event = BTA_DM_AUTH_CMPL_EVT; |
| 2531 | p_auth_cmpl = &sec_event.auth_cmpl; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2532 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2533 | p_auth_cmpl->bd_addr = bd_addr; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2534 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2535 | memcpy(p_auth_cmpl->bd_name, bd_name, (BD_NAME_LEN - 1)); |
| 2536 | p_auth_cmpl->bd_name[BD_NAME_LEN - 1] = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2537 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2538 | p_auth_cmpl->key_present = true; |
| 2539 | p_auth_cmpl->key_type = key_type; |
| 2540 | p_auth_cmpl->success = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2541 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2542 | memcpy(p_auth_cmpl->key, key, LINK_KEY_LEN); |
| 2543 | sec_event.auth_cmpl.fail_reason = HCI_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2544 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2545 | // Report the BR link key based on the BR/EDR address and type |
| 2546 | BTM_ReadDevInfo(bd_addr, &sec_event.auth_cmpl.dev_type, |
| 2547 | &sec_event.auth_cmpl.addr_type); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2548 | if (bta_dm_cb.p_sec_cback) bta_dm_cb.p_sec_cback(event, &sec_event); |
Balraj Selvaraj | 9412bba | 2016-02-11 13:46:02 +0530 | [diff] [blame] | 2549 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2550 | // Setting remove_dev_pending flag to false, where it will avoid deleting |
| 2551 | // the |
| 2552 | // security device record when the ACL connection link goes down in case of |
| 2553 | // reconnection. |
| 2554 | if (bta_dm_cb.device_list.count) |
| 2555 | bta_dm_reset_sec_dev_pending(p_auth_cmpl->bd_addr); |
| 2556 | } else { |
| 2557 | APPL_TRACE_WARNING("%s() Received AMP Key", __func__); |
| 2558 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2559 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2560 | return BTM_CMD_STARTED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2561 | } |
| 2562 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2563 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2564 | * |
| 2565 | * Function bta_dm_authentication_complete_cback |
| 2566 | * |
| 2567 | * Description Authentication complete callback from BTM |
| 2568 | * |
| 2569 | * Returns void |
| 2570 | * |
| 2571 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2572 | static uint8_t bta_dm_authentication_complete_cback( |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2573 | const bt_bdaddr_t& bd_addr, UNUSED_ATTR DEV_CLASS dev_class, |
| 2574 | BD_NAME bd_name, int result) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2575 | tBTA_DM_SEC sec_event; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2576 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2577 | if (result != BTM_SUCCESS) { |
| 2578 | memset(&sec_event, 0, sizeof(tBTA_DM_SEC)); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2579 | sec_event.auth_cmpl.bd_addr = bd_addr; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2580 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2581 | memcpy(sec_event.auth_cmpl.bd_name, bd_name, (BD_NAME_LEN - 1)); |
| 2582 | sec_event.auth_cmpl.bd_name[BD_NAME_LEN - 1] = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2583 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2584 | // Report the BR link key based on the BR/EDR address and type |
| 2585 | BTM_ReadDevInfo(bd_addr, &sec_event.auth_cmpl.dev_type, |
| 2586 | &sec_event.auth_cmpl.addr_type); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2587 | sec_event.auth_cmpl.fail_reason = (uint8_t)result; |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 2588 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2589 | if (bta_dm_cb.p_sec_cback) |
| 2590 | bta_dm_cb.p_sec_cback(BTA_DM_AUTH_CMPL_EVT, &sec_event); |
Chaojing Sun | e280553 | 2015-04-22 13:40:21 -0700 | [diff] [blame] | 2591 | |
Andre Eisenbach | 1f5ec73 | 2017-04-13 14:49:36 -0700 | [diff] [blame] | 2592 | if (result != HCI_ERR_LMP_RESPONSE_TIMEOUT && |
| 2593 | result != HCI_ERR_PAGE_TIMEOUT && |
| 2594 | result != HCI_ERR_CONN_FAILED_ESTABLISHMENT) { |
| 2595 | bta_dm_remove_sec_dev_entry(bd_addr); |
| 2596 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2597 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2598 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2599 | return BTM_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2600 | } |
| 2601 | |
Pulkit Bhuwalka | eb1ad1d | 2017-02-28 16:11:34 -0800 | [diff] [blame] | 2602 | #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2603 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2604 | * |
| 2605 | * Function bta_dm_sp_cback |
| 2606 | * |
| 2607 | * Description simple pairing callback from BTM |
| 2608 | * |
| 2609 | * Returns void |
| 2610 | * |
| 2611 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2612 | static uint8_t bta_dm_sp_cback(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data) { |
| 2613 | tBTM_STATUS status = BTM_CMD_STARTED; |
| 2614 | tBTA_DM_SEC sec_event; |
| 2615 | tBTA_DM_SEC_EVT pin_evt = BTA_DM_SP_KEY_NOTIF_EVT; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2616 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2617 | APPL_TRACE_EVENT("bta_dm_sp_cback: %d", event); |
| 2618 | if (!bta_dm_cb.p_sec_cback) return BTM_NOT_AUTHORIZED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2619 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2620 | /* TODO_SP */ |
| 2621 | switch (event) { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2622 | case BTM_SP_IO_REQ_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2623 | /* translate auth_req */ |
| 2624 | bta_dm_co_io_req(p_data->io_req.bd_addr, &p_data->io_req.io_cap, |
| 2625 | &p_data->io_req.oob_data, &p_data->io_req.auth_req, |
| 2626 | p_data->io_req.is_orig); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2627 | APPL_TRACE_EVENT("io mitm: %d oob_data:%d", p_data->io_req.auth_req, |
| 2628 | p_data->io_req.oob_data); |
| 2629 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2630 | case BTM_SP_IO_RSP_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2631 | bta_dm_co_io_rsp(p_data->io_rsp.bd_addr, p_data->io_rsp.io_cap, |
| 2632 | p_data->io_rsp.oob_data, p_data->io_rsp.auth_req); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2633 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2634 | |
| 2635 | case BTM_SP_CFM_REQ_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2636 | pin_evt = BTA_DM_SP_CFM_REQ_EVT; |
| 2637 | bta_dm_cb.just_works = sec_event.cfm_req.just_works = |
| 2638 | p_data->cfm_req.just_works; |
| 2639 | sec_event.cfm_req.loc_auth_req = p_data->cfm_req.loc_auth_req; |
| 2640 | sec_event.cfm_req.rmt_auth_req = p_data->cfm_req.rmt_auth_req; |
| 2641 | sec_event.cfm_req.loc_io_caps = p_data->cfm_req.loc_io_caps; |
| 2642 | sec_event.cfm_req.rmt_io_caps = p_data->cfm_req.rmt_io_caps; |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 2643 | |
Andre Eisenbach | 1f5ec73 | 2017-04-13 14:49:36 -0700 | [diff] [blame] | 2644 | /* continue to next case */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2645 | /* Passkey entry mode, mobile device with output capability is very |
| 2646 | unlikely to receive key request, so skip this event */ |
| 2647 | /*case BTM_SP_KEY_REQ_EVT: */ |
| 2648 | case BTM_SP_KEY_NOTIF_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2649 | bta_dm_cb.num_val = sec_event.key_notif.passkey = |
| 2650 | p_data->key_notif.passkey; |
Jack He | db76fa4 | 2016-11-01 11:30:51 -0700 | [diff] [blame] | 2651 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2652 | if (BTM_SP_CFM_REQ_EVT == event) { |
| 2653 | /* Due to the switch case falling through below to BTM_SP_KEY_NOTIF_EVT, |
| 2654 | call remote name request using values from cfm_req */ |
| 2655 | if (p_data->cfm_req.bd_name[0] == 0) { |
| 2656 | bta_dm_cb.pin_evt = pin_evt; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2657 | bta_dm_cb.pin_bd_addr = p_data->cfm_req.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2658 | BTA_COPY_DEVICE_CLASS(bta_dm_cb.pin_dev_class, |
| 2659 | p_data->cfm_req.dev_class); |
| 2660 | if ((BTM_ReadRemoteDeviceName( |
| 2661 | p_data->cfm_req.bd_addr, bta_dm_pinname_cback, |
| 2662 | BT_TRANSPORT_BR_EDR)) == BTM_CMD_STARTED) |
| 2663 | return BTM_CMD_STARTED; |
| 2664 | APPL_TRACE_WARNING( |
| 2665 | " bta_dm_sp_cback() -> Failed to start Remote Name Request "); |
| 2666 | } else { |
| 2667 | /* Due to the switch case falling through below to |
| 2668 | BTM_SP_KEY_NOTIF_EVT, |
| 2669 | copy these values into key_notif from cfm_req */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2670 | sec_event.key_notif.bd_addr = p_data->cfm_req.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2671 | BTA_COPY_DEVICE_CLASS(sec_event.key_notif.dev_class, |
| 2672 | p_data->cfm_req.dev_class); |
| 2673 | strlcpy((char*)sec_event.key_notif.bd_name, |
| 2674 | (char*)p_data->cfm_req.bd_name, BD_NAME_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2675 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2676 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2677 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2678 | if (BTM_SP_KEY_NOTIF_EVT == event) { |
| 2679 | /* If the device name is not known, save bdaddr and devclass |
| 2680 | and initiate a name request with values from key_notif */ |
| 2681 | if (p_data->key_notif.bd_name[0] == 0) { |
| 2682 | bta_dm_cb.pin_evt = pin_evt; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2683 | bta_dm_cb.pin_bd_addr = p_data->key_notif.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2684 | BTA_COPY_DEVICE_CLASS(bta_dm_cb.pin_dev_class, |
| 2685 | p_data->key_notif.dev_class); |
| 2686 | if ((BTM_ReadRemoteDeviceName( |
| 2687 | p_data->key_notif.bd_addr, bta_dm_pinname_cback, |
| 2688 | BT_TRANSPORT_BR_EDR)) == BTM_CMD_STARTED) |
| 2689 | return BTM_CMD_STARTED; |
| 2690 | APPL_TRACE_WARNING( |
| 2691 | " bta_dm_sp_cback() -> Failed to start Remote Name Request "); |
| 2692 | } else { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2693 | sec_event.key_notif.bd_addr = p_data->key_notif.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2694 | BTA_COPY_DEVICE_CLASS(sec_event.key_notif.dev_class, |
| 2695 | p_data->key_notif.dev_class); |
| 2696 | strlcpy((char*)sec_event.key_notif.bd_name, |
| 2697 | (char*)p_data->key_notif.bd_name, BD_NAME_LEN); |
| 2698 | sec_event.key_notif.bd_name[BD_NAME_LEN - 1] = 0; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2699 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2700 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2701 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2702 | bta_dm_cb.p_sec_cback(pin_evt, &sec_event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2703 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2704 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2705 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2706 | case BTM_SP_LOC_OOB_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2707 | bta_dm_co_loc_oob((bool)(p_data->loc_oob.status == BTM_SUCCESS), |
| 2708 | p_data->loc_oob.c, p_data->loc_oob.r); |
| 2709 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2710 | |
| 2711 | case BTM_SP_RMT_OOB_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2712 | /* If the device name is not known, save bdaddr and devclass and initiate |
| 2713 | * a name request */ |
| 2714 | if (p_data->rmt_oob.bd_name[0] == 0) { |
| 2715 | bta_dm_cb.pin_evt = BTA_DM_SP_RMT_OOB_EVT; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2716 | bta_dm_cb.pin_bd_addr = p_data->rmt_oob.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2717 | BTA_COPY_DEVICE_CLASS(bta_dm_cb.pin_dev_class, |
| 2718 | p_data->rmt_oob.dev_class); |
| 2719 | if ((BTM_ReadRemoteDeviceName(p_data->rmt_oob.bd_addr, |
| 2720 | bta_dm_pinname_cback, |
| 2721 | BT_TRANSPORT_BR_EDR)) == BTM_CMD_STARTED) |
| 2722 | return BTM_CMD_STARTED; |
| 2723 | APPL_TRACE_WARNING( |
| 2724 | " bta_dm_sp_cback() -> Failed to start Remote Name Request "); |
| 2725 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2726 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2727 | sec_event.rmt_oob.bd_addr = p_data->rmt_oob.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2728 | BTA_COPY_DEVICE_CLASS(sec_event.rmt_oob.dev_class, |
| 2729 | p_data->rmt_oob.dev_class); |
| 2730 | strlcpy((char*)sec_event.rmt_oob.bd_name, (char*)p_data->rmt_oob.bd_name, |
| 2731 | BD_NAME_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2732 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2733 | bta_dm_cb.p_sec_cback(BTA_DM_SP_RMT_OOB_EVT, &sec_event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2734 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2735 | bta_dm_co_rmt_oob(p_data->rmt_oob.bd_addr); |
| 2736 | break; |
Jakub Pawlowski | 175da70 | 2015-11-12 15:00:58 -0800 | [diff] [blame] | 2737 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2738 | case BTM_SP_COMPLT_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2739 | /* do not report this event - handled by link_key_callback or |
| 2740 | * auth_complete_callback */ |
| 2741 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2742 | |
| 2743 | case BTM_SP_KEYPRESS_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2744 | memcpy(&sec_event.key_press, &p_data->key_press, |
| 2745 | sizeof(tBTM_SP_KEYPRESS)); |
| 2746 | bta_dm_cb.p_sec_cback(BTA_DM_SP_KEYPRESS_EVT, &sec_event); |
| 2747 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2748 | |
| 2749 | case BTM_SP_UPGRADE_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2750 | bta_dm_co_lk_upgrade(p_data->upgrade.bd_addr, &p_data->upgrade.upgrade); |
| 2751 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2752 | |
| 2753 | default: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2754 | status = BTM_NOT_AUTHORIZED; |
| 2755 | break; |
| 2756 | } |
| 2757 | APPL_TRACE_EVENT("dm status: %d", status); |
| 2758 | return status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2759 | } |
Pulkit Bhuwalka | eb1ad1d | 2017-02-28 16:11:34 -0800 | [diff] [blame] | 2760 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2761 | |
| 2762 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2763 | * |
| 2764 | * Function bta_dm_local_name_cback |
| 2765 | * |
| 2766 | * Description Callback from btm after local name is read |
| 2767 | * |
| 2768 | * |
| 2769 | * Returns void |
| 2770 | * |
| 2771 | ******************************************************************************/ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2772 | static void bta_dm_local_name_cback(UNUSED_ATTR const bt_bdaddr_t& p_name) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2773 | tBTA_DM_SEC sec_event; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2774 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2775 | sec_event.enable.status = BTA_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2776 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2777 | if (bta_dm_cb.p_sec_cback) |
| 2778 | bta_dm_cb.p_sec_cback(BTA_DM_ENABLE_EVT, &sec_event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2779 | } |
| 2780 | |
| 2781 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2782 | * |
| 2783 | * Function bta_dm_bl_change_cback |
| 2784 | * |
| 2785 | * Description Callback from btm when acl connection goes up or down |
| 2786 | * |
| 2787 | * |
| 2788 | * Returns void |
| 2789 | * |
| 2790 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2791 | static void bta_dm_bl_change_cback(tBTM_BL_EVENT_DATA* p_data) { |
| 2792 | tBTA_DM_ACL_CHANGE* p_msg = |
| 2793 | (tBTA_DM_ACL_CHANGE*)osi_malloc(sizeof(tBTA_DM_ACL_CHANGE)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2794 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2795 | p_msg->event = p_data->event; |
| 2796 | p_msg->is_new = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2797 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2798 | switch (p_msg->event) { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2799 | case BTM_BL_CONN_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2800 | p_msg->is_new = true; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2801 | p_msg->bd_addr = *p_data->conn.p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2802 | p_msg->transport = p_data->conn.transport; |
| 2803 | p_msg->handle = p_data->conn.handle; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2804 | break; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2805 | case BTM_BL_DISCN_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2806 | p_msg->bd_addr = *p_data->discn.p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2807 | p_msg->transport = p_data->discn.transport; |
| 2808 | p_msg->handle = p_data->discn.handle; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2809 | break; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2810 | case BTM_BL_UPDATE_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2811 | p_msg->busy_level = p_data->update.busy_level; |
| 2812 | p_msg->busy_level_flags = p_data->update.busy_level_flags; |
| 2813 | break; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2814 | case BTM_BL_ROLE_CHG_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2815 | p_msg->new_role = p_data->role_chg.new_role; |
| 2816 | p_msg->hci_status = p_data->role_chg.hci_status; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2817 | p_msg->bd_addr = *p_data->role_chg.p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2818 | break; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2819 | case BTM_BL_COLLISION_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2820 | p_msg->bd_addr = *p_data->conn.p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2821 | break; |
| 2822 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2823 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2824 | p_msg->hdr.event = BTA_DM_ACL_CHANGE_EVT; |
| 2825 | bta_sys_sendmsg(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2826 | } |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 2827 | |
| 2828 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2829 | * |
| 2830 | * Function bta_dm_rs_cback |
| 2831 | * |
| 2832 | * Description Receives the role switch complete event |
| 2833 | * |
| 2834 | * Returns |
| 2835 | * |
| 2836 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2837 | static void bta_dm_rs_cback(UNUSED_ATTR tBTM_ROLE_SWITCH_CMPL* p1) { |
| 2838 | APPL_TRACE_WARNING("bta_dm_rs_cback:%d", bta_dm_cb.rs_event); |
| 2839 | if (bta_dm_cb.rs_event == BTA_DM_API_SEARCH_EVT) { |
| 2840 | bta_dm_cb.search_msg.rs_res = |
| 2841 | BTA_DM_RS_OK; /* do not care about the result for now */ |
| 2842 | bta_dm_cb.rs_event = 0; |
| 2843 | bta_dm_search_start((tBTA_DM_MSG*)&bta_dm_cb.search_msg); |
| 2844 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2848 | * |
| 2849 | * Function bta_dm_check_av |
| 2850 | * |
| 2851 | * Description This function checks if AV is active |
| 2852 | * if yes, make sure the AV link is master |
| 2853 | * |
| 2854 | * Returns bool - true, if switch is in progress |
| 2855 | * |
| 2856 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2857 | static bool bta_dm_check_av(uint16_t event) { |
| 2858 | bool avoid_roleswitch = false; |
| 2859 | bool switching = false; |
| 2860 | uint8_t i; |
| 2861 | tBTA_DM_PEER_DEVICE* p_dev; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2862 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 2863 | #if (BTA_DM_AVOID_A2DP_ROLESWITCH_ON_INQUIRY == TRUE) |
Mattias Agren | 9647e91 | 2013-04-08 12:23:42 +0200 | [diff] [blame] | 2864 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2865 | /* avoid role switch upon inquiry if a2dp is actively streaming as it |
| 2866 | introduces an audioglitch due to FW scheduling delays (unavoidable) */ |
| 2867 | if (event == BTA_DM_API_SEARCH_EVT) { |
| 2868 | avoid_roleswitch = true; |
| 2869 | } |
Mattias Agren | 9647e91 | 2013-04-08 12:23:42 +0200 | [diff] [blame] | 2870 | #endif |
| 2871 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2872 | APPL_TRACE_WARNING("bta_dm_check_av:%d", bta_dm_cb.cur_av_count); |
| 2873 | if (bta_dm_cb.cur_av_count) { |
| 2874 | for (i = 0; i < bta_dm_cb.device_list.count; i++) { |
| 2875 | p_dev = &bta_dm_cb.device_list.peer_device[i]; |
| 2876 | APPL_TRACE_WARNING("[%d]: state:%d, info:x%x, avoid_rs %d", i, |
| 2877 | p_dev->conn_state, p_dev->info, avoid_roleswitch); |
| 2878 | if ((p_dev->conn_state == BTA_DM_CONNECTED) && |
| 2879 | (p_dev->info & BTA_DM_DI_AV_ACTIVE) && (avoid_roleswitch == false)) { |
| 2880 | /* make master and take away the role switch policy */ |
| 2881 | if (BTM_CMD_STARTED == BTM_SwitchRole(p_dev->peer_bdaddr, |
| 2882 | HCI_ROLE_MASTER, |
| 2883 | (tBTM_CMPL_CB*)bta_dm_rs_cback)) { |
| 2884 | /* the role switch command is actually sent */ |
| 2885 | bta_dm_cb.rs_event = event; |
| 2886 | switching = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2887 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2888 | /* else either already master or can not switch for some reasons */ |
| 2889 | bta_dm_policy_cback(BTA_SYS_PLCY_CLR, 0, HCI_ENABLE_MASTER_SLAVE_SWITCH, |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2890 | to_BD_ADDR(p_dev->peer_bdaddr)); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2891 | break; |
| 2892 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2893 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2894 | } |
| 2895 | return switching; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2896 | } |
| 2897 | |
| 2898 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2899 | * |
| 2900 | * Function bta_dm_acl_change |
| 2901 | * |
| 2902 | * Description Process BTA_DM_ACL_CHANGE_EVT |
| 2903 | * |
| 2904 | * |
| 2905 | * Returns void |
| 2906 | * |
| 2907 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2908 | void bta_dm_acl_change(tBTA_DM_MSG* p_data) { |
| 2909 | uint8_t i; |
| 2910 | uint8_t* p; |
| 2911 | tBTA_DM_SEC conn; |
| 2912 | bool is_new = p_data->acl_change.is_new; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2913 | const bt_bdaddr_t& p_bda = p_data->acl_change.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2914 | bool need_policy_change = false; |
| 2915 | bool issue_unpair_cb = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2916 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2917 | tBTA_DM_PEER_DEVICE* p_dev; |
| 2918 | memset(&conn, 0, sizeof(tBTA_DM_SEC)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2919 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2920 | switch (p_data->acl_change.event) { |
| 2921 | case BTM_BL_UPDATE_EVT: /* busy level update */ |
| 2922 | if (bta_dm_cb.p_sec_cback) { |
| 2923 | conn.busy_level.level = p_data->acl_change.busy_level; |
| 2924 | conn.busy_level.level_flags = p_data->acl_change.busy_level_flags; |
| 2925 | bta_dm_cb.p_sec_cback(BTA_DM_BUSY_LEVEL_EVT, &conn); |
| 2926 | } |
| 2927 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2928 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2929 | case BTM_BL_ROLE_CHG_EVT: /* role change event */ |
| 2930 | p_dev = bta_dm_find_peer_device(p_bda); |
| 2931 | if (p_dev) { |
| 2932 | APPL_TRACE_DEBUG( |
| 2933 | "bta_dm_acl_change role chg info:x%x new_role:%d dev count:%d", |
| 2934 | p_dev->info, p_data->acl_change.new_role, |
| 2935 | bta_dm_cb.device_list.count); |
| 2936 | if (p_dev->info & BTA_DM_DI_AV_ACTIVE) { |
| 2937 | /* there's AV activity on this link */ |
| 2938 | if (p_data->acl_change.new_role == HCI_ROLE_SLAVE && |
| 2939 | bta_dm_cb.device_list.count > 1 && |
| 2940 | p_data->acl_change.hci_status == HCI_SUCCESS) { |
| 2941 | /* more than one connections and the AV connection is role switched |
| 2942 | * to slave |
| 2943 | * switch it back to master and remove the switch policy */ |
| 2944 | BTM_SwitchRole(p_bda, BTM_ROLE_MASTER, NULL); |
| 2945 | need_policy_change = true; |
| 2946 | } else if (p_bta_dm_cfg->avoid_scatter && |
| 2947 | (p_data->acl_change.new_role == HCI_ROLE_MASTER)) { |
| 2948 | /* if the link updated to be master include AV activities, remove |
| 2949 | * the switch policy */ |
| 2950 | need_policy_change = true; |
| 2951 | } |
| 2952 | |
| 2953 | if (need_policy_change) { |
| 2954 | bta_dm_policy_cback(BTA_SYS_PLCY_CLR, 0, |
| 2955 | HCI_ENABLE_MASTER_SLAVE_SWITCH, |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2956 | to_BD_ADDR(p_dev->peer_bdaddr)); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2957 | } |
| 2958 | } else { |
| 2959 | /* there's AV no activity on this link and role switch happened |
| 2960 | * check if AV is active |
| 2961 | * if so, make sure the AV link is master */ |
| 2962 | bta_dm_check_av(0); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2963 | } |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2964 | bta_sys_notify_role_chg(to_BD_ADDR(p_data->acl_change.bd_addr), |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2965 | p_data->acl_change.new_role, |
| 2966 | p_data->acl_change.hci_status); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2967 | conn.role_chg.bd_addr = p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2968 | conn.role_chg.new_role = (uint8_t)p_data->acl_change.new_role; |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 2969 | if (bta_dm_cb.p_sec_cback) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2970 | bta_dm_cb.p_sec_cback(BTA_DM_ROLE_CHG_EVT, (tBTA_DM_SEC*)&conn); |
| 2971 | } |
| 2972 | return; |
| 2973 | } |
| 2974 | |
| 2975 | /* Collision report from Stack: Notify profiles */ |
| 2976 | if (p_data->acl_change.event == BTM_BL_COLLISION_EVT) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2977 | bta_sys_notify_collision(to_BD_ADDR(p_bda)); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2978 | return; |
| 2979 | } |
| 2980 | |
| 2981 | if (is_new) { |
| 2982 | for (i = 0; i < bta_dm_cb.device_list.count; i++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2983 | if (bta_dm_cb.device_list.peer_device[i].peer_bdaddr == p_bda && |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2984 | bta_dm_cb.device_list.peer_device[i].conn_handle == |
Myles Watson | 84baa7f | 2016-11-14 12:05:37 -0800 | [diff] [blame] | 2985 | p_data->acl_change.handle) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2986 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2987 | } |
| 2988 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2989 | if (i == bta_dm_cb.device_list.count) { |
| 2990 | if (bta_dm_cb.device_list.count < BTA_DM_NUM_PEER_DEVICE) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2991 | bta_dm_cb.device_list.peer_device[bta_dm_cb.device_list.count] |
| 2992 | .peer_bdaddr = p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2993 | bta_dm_cb.device_list.peer_device[bta_dm_cb.device_list.count] |
| 2994 | .link_policy = bta_dm_cb.cur_policy; |
| 2995 | bta_dm_cb.device_list.count++; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2996 | bta_dm_cb.device_list.peer_device[i].conn_handle = |
| 2997 | p_data->acl_change.handle; |
| 2998 | if (p_data->acl_change.transport == BT_TRANSPORT_LE) |
| 2999 | bta_dm_cb.device_list.le_count++; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3000 | } else { |
| 3001 | APPL_TRACE_ERROR("%s max active connection reached, no resources", |
| 3002 | __func__); |
| 3003 | return; |
| 3004 | } |
| 3005 | } |
| 3006 | |
| 3007 | bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_CONNECTED; |
| 3008 | bta_dm_cb.device_list.peer_device[i].pref_role = BTA_ANY_ROLE; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3009 | conn.link_up.bd_addr = p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3010 | bta_dm_cb.device_list.peer_device[i].info = BTA_DM_DI_NONE; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3011 | conn.link_up.link_type = p_data->acl_change.transport; |
| 3012 | bta_dm_cb.device_list.peer_device[i].transport = |
| 3013 | p_data->acl_change.transport; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3014 | |
| 3015 | if (((NULL != (p = BTM_ReadLocalFeatures())) && |
| 3016 | HCI_SNIFF_SUB_RATE_SUPPORTED(p)) && |
| 3017 | ((NULL != (p = BTM_ReadRemoteFeatures(p_bda))) && |
| 3018 | HCI_SNIFF_SUB_RATE_SUPPORTED(p))) { |
| 3019 | /* both local and remote devices support SSR */ |
| 3020 | bta_dm_cb.device_list.peer_device[i].info = BTA_DM_DI_USE_SSR; |
| 3021 | } |
| 3022 | APPL_TRACE_WARNING("%s info: 0x%x", __func__, |
| 3023 | bta_dm_cb.device_list.peer_device[i].info); |
| 3024 | |
| 3025 | if (bta_dm_cb.p_sec_cback) |
| 3026 | bta_dm_cb.p_sec_cback(BTA_DM_LINK_UP_EVT, (tBTA_DM_SEC*)&conn); |
| 3027 | } else { |
| 3028 | for (i = 0; i < bta_dm_cb.device_list.count; i++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3029 | if (bta_dm_cb.device_list.peer_device[i].peer_bdaddr != p_bda || |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3030 | bta_dm_cb.device_list.peer_device[i].transport != |
Myles Watson | 84baa7f | 2016-11-14 12:05:37 -0800 | [diff] [blame] | 3031 | p_data->acl_change.transport) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3032 | continue; |
| 3033 | |
| 3034 | if (bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_UNPAIRING) { |
| 3035 | if (BTM_SecDeleteDevice( |
| 3036 | bta_dm_cb.device_list.peer_device[i].peer_bdaddr)) |
| 3037 | issue_unpair_cb = true; |
| 3038 | |
| 3039 | APPL_TRACE_DEBUG("%s: Unpairing: issue unpair CB = %d ", __func__, |
| 3040 | issue_unpair_cb); |
| 3041 | } |
| 3042 | |
| 3043 | conn.link_down.is_removed = |
| 3044 | bta_dm_cb.device_list.peer_device[i].remove_dev_pending; |
| 3045 | |
Martin Brabham | 36d19de | 2017-05-01 16:30:40 -0700 | [diff] [blame] | 3046 | // Iterate to the one before the last when shrinking the list, |
| 3047 | // otherwise we memcpy garbage data into the record. |
| 3048 | // Then clear out the last item in the list since we are shrinking. |
| 3049 | for (; i < bta_dm_cb.device_list.count - 1; i++) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3050 | memcpy(&bta_dm_cb.device_list.peer_device[i], |
| 3051 | &bta_dm_cb.device_list.peer_device[i + 1], |
| 3052 | sizeof(bta_dm_cb.device_list.peer_device[i])); |
| 3053 | } |
Martin Brabham | 36d19de | 2017-05-01 16:30:40 -0700 | [diff] [blame] | 3054 | if (bta_dm_cb.device_list.count > 0) { |
| 3055 | int clear_index = bta_dm_cb.device_list.count - 1; |
| 3056 | memset(&bta_dm_cb.device_list.peer_device[clear_index], 0, |
| 3057 | sizeof(bta_dm_cb.device_list.peer_device[clear_index])); |
| 3058 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3059 | break; |
| 3060 | } |
| 3061 | if (bta_dm_cb.device_list.count) bta_dm_cb.device_list.count--; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3062 | if ((p_data->acl_change.transport == BT_TRANSPORT_LE) && |
| 3063 | (bta_dm_cb.device_list.le_count)) |
| 3064 | bta_dm_cb.device_list.le_count--; |
| 3065 | conn.link_down.link_type = p_data->acl_change.transport; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3066 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3067 | if (bta_dm_search_cb.wait_disc && bta_dm_search_cb.peer_bdaddr == p_bda) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3068 | bta_dm_search_cb.wait_disc = false; |
| 3069 | |
| 3070 | if (bta_dm_search_cb.sdp_results) { |
| 3071 | APPL_TRACE_EVENT(" timer stopped "); |
| 3072 | alarm_cancel(bta_dm_search_cb.search_timer); |
| 3073 | bta_dm_discover_next_device(); |
| 3074 | } |
| 3075 | } |
| 3076 | |
| 3077 | if (bta_dm_cb.disabling) { |
| 3078 | if (!BTM_GetNumAclLinks()) { |
| 3079 | /* |
| 3080 | * Start a timer to make sure that the profiles |
| 3081 | * get the disconnect event. |
| 3082 | */ |
| 3083 | alarm_set_on_queue( |
| 3084 | bta_dm_cb.disable_timer, BTA_DM_DISABLE_CONN_DOWN_TIMER_MS, |
| 3085 | bta_dm_disable_conn_down_timer_cback, NULL, btu_bta_alarm_queue); |
| 3086 | } |
| 3087 | } |
| 3088 | if (conn.link_down.is_removed) { |
| 3089 | BTM_SecDeleteDevice(p_bda); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3090 | /* need to remove all pending background connection */ |
| 3091 | BTA_GATTC_CancelOpen(0, p_bda, false); |
| 3092 | /* remove all cached GATT information */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3093 | BTA_GATTC_Refresh(p_bda); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3094 | } |
| 3095 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3096 | conn.link_down.bd_addr = p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3097 | conn.link_down.status = (uint8_t)btm_get_acl_disc_reason_code(); |
| 3098 | if (bta_dm_cb.p_sec_cback) { |
| 3099 | bta_dm_cb.p_sec_cback(BTA_DM_LINK_DOWN_EVT, &conn); |
| 3100 | if (issue_unpair_cb) |
| 3101 | bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &conn); |
| 3102 | } |
| 3103 | } |
| 3104 | |
| 3105 | bta_dm_adjust_roles(true); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3109 | * |
| 3110 | * Function bta_dm_disable_conn_down_timer_cback |
| 3111 | * |
| 3112 | * Description Sends disable event to application |
| 3113 | * |
| 3114 | * |
| 3115 | * Returns void |
| 3116 | * |
| 3117 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3118 | static void bta_dm_disable_conn_down_timer_cback(UNUSED_ATTR void* data) { |
| 3119 | tBTA_SYS_HW_MSG* sys_enable_event = |
| 3120 | (tBTA_SYS_HW_MSG*)osi_malloc(sizeof(tBTA_SYS_HW_MSG)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3121 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3122 | /* disable the power managment module */ |
| 3123 | bta_dm_disable_pm(); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3124 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3125 | /* register our callback to SYS HW manager */ |
| 3126 | bta_sys_hw_register(BTA_SYS_HW_BLUETOOTH, bta_dm_sys_hw_cback); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3127 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3128 | /* send a message to BTA SYS */ |
| 3129 | sys_enable_event->hdr.event = BTA_SYS_API_DISABLE_EVT; |
| 3130 | sys_enable_event->hw_module = BTA_SYS_HW_BLUETOOTH; |
| 3131 | bta_sys_sendmsg(sys_enable_event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3132 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3133 | bta_dm_cb.disabling = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3134 | } |
| 3135 | |
| 3136 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3137 | * |
| 3138 | * Function bta_dm_rm_cback |
| 3139 | * |
| 3140 | * Description Role management callback from sys |
| 3141 | * |
| 3142 | * |
| 3143 | * Returns void |
| 3144 | * |
| 3145 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3146 | static void bta_dm_rm_cback(tBTA_SYS_CONN_STATUS status, uint8_t id, |
| 3147 | uint8_t app_id, BD_ADDR peer_addr) { |
| 3148 | uint8_t j; |
| 3149 | tBTA_PREF_ROLES role; |
| 3150 | tBTA_DM_PEER_DEVICE* p_dev; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3151 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3152 | p_dev = bta_dm_find_peer_device(from_BD_ADDR(peer_addr)); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3153 | if (status == BTA_SYS_CONN_OPEN) { |
| 3154 | if (p_dev) { |
| 3155 | /* Do not set to connected if we are in the middle of unpairing. When AV |
| 3156 | * stream is |
| 3157 | * started it fakes out a SYS_CONN_OPEN to potentially trigger a role |
| 3158 | * switch command. |
| 3159 | * But this should not be done if we are in the middle of unpairing. |
| 3160 | */ |
| 3161 | if (p_dev->conn_state != BTA_DM_UNPAIRING) |
| 3162 | p_dev->conn_state = BTA_DM_CONNECTED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3163 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3164 | for (j = 1; j <= p_bta_dm_rm_cfg[0].app_id; j++) { |
| 3165 | if (((p_bta_dm_rm_cfg[j].app_id == app_id) || |
| 3166 | (p_bta_dm_rm_cfg[j].app_id == BTA_ALL_APP_ID)) && |
| 3167 | (p_bta_dm_rm_cfg[j].id == id)) { |
| 3168 | role = p_bta_dm_rm_cfg[j].cfg; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3169 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3170 | if (role > p_dev->pref_role) p_dev->pref_role = role; |
| 3171 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3172 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3173 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3174 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3175 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3176 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3177 | if ((BTA_ID_AV == id) || (BTA_ID_AVK == id)) { |
| 3178 | if (status == BTA_SYS_CONN_BUSY) { |
| 3179 | if (p_dev) p_dev->info |= BTA_DM_DI_AV_ACTIVE; |
| 3180 | /* AV calls bta_sys_conn_open with the A2DP stream count as app_id */ |
| 3181 | if (BTA_ID_AV == id) bta_dm_cb.cur_av_count = bta_dm_get_av_count(); |
| 3182 | } else if (status == BTA_SYS_CONN_IDLE) { |
| 3183 | if (p_dev) p_dev->info &= ~BTA_DM_DI_AV_ACTIVE; |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 3184 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3185 | /* get cur_av_count from connected services */ |
| 3186 | if (BTA_ID_AV == id) bta_dm_cb.cur_av_count = bta_dm_get_av_count(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3187 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3188 | APPL_TRACE_WARNING("bta_dm_rm_cback:%d, status:%d", bta_dm_cb.cur_av_count, |
| 3189 | status); |
| 3190 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3191 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3192 | /* Don't adjust roles for each busy/idle state transition to avoid |
| 3193 | excessive switch requests when individual profile busy/idle status |
| 3194 | changes */ |
| 3195 | if ((status != BTA_SYS_CONN_BUSY) && (status != BTA_SYS_CONN_IDLE)) |
| 3196 | bta_dm_adjust_roles(false); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3200 | * |
| 3201 | * Function bta_dm_delay_role_switch_cback |
| 3202 | * |
| 3203 | * Description Callback from btm to delay a role switch |
| 3204 | * |
| 3205 | * Returns void |
| 3206 | * |
| 3207 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3208 | static void bta_dm_delay_role_switch_cback(UNUSED_ATTR void* data) { |
| 3209 | APPL_TRACE_EVENT("%s: initiating Delayed RS", __func__); |
| 3210 | bta_dm_adjust_roles(false); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3211 | } |
| 3212 | |
| 3213 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3214 | * |
| 3215 | * Function bta_dm_reset_sec_dev_pending |
| 3216 | * |
| 3217 | * Description Setting the remove device pending status to false from |
| 3218 | * security device DB, when the link key notification |
| 3219 | * event comes. |
| 3220 | * |
| 3221 | * Returns void |
| 3222 | * |
| 3223 | ******************************************************************************/ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3224 | static void bta_dm_reset_sec_dev_pending(const bt_bdaddr_t& remote_bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3225 | for (size_t i = 0; i < bta_dm_cb.device_list.count; i++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3226 | if (bta_dm_cb.device_list.peer_device[i].peer_bdaddr == remote_bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3227 | bta_dm_cb.device_list.peer_device[i].remove_dev_pending = false; |
| 3228 | return; |
Balraj Selvaraj | 9412bba | 2016-02-11 13:46:02 +0530 | [diff] [blame] | 3229 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3230 | } |
Balraj Selvaraj | 9412bba | 2016-02-11 13:46:02 +0530 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3234 | * |
| 3235 | * Function bta_dm_remove_sec_dev_entry |
| 3236 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3237 | * Description Removes device entry from Security device DB if ACL |
| 3238 | connection with |
| 3239 | * remtoe device does not exist, else schedule for dev entry |
| 3240 | removal upon |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3241 | ACL close |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3242 | * |
| 3243 | * Returns void |
| 3244 | * |
| 3245 | ******************************************************************************/ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3246 | static void bta_dm_remove_sec_dev_entry(const bt_bdaddr_t& remote_bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3247 | if (BTM_IsAclConnectionUp(remote_bd_addr, BT_TRANSPORT_LE) || |
| 3248 | BTM_IsAclConnectionUp(remote_bd_addr, BT_TRANSPORT_BR_EDR)) { |
| 3249 | APPL_TRACE_DEBUG( |
| 3250 | "%s ACL is not down. Schedule for Dev Removal when ACL closes", |
| 3251 | __func__); |
| 3252 | BTM_SecClearSecurityFlags(remote_bd_addr); |
| 3253 | for (int i = 0; i < bta_dm_cb.device_list.count; i++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3254 | if (bta_dm_cb.device_list.peer_device[i].peer_bdaddr == remote_bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3255 | bta_dm_cb.device_list.peer_device[i].remove_dev_pending = TRUE; |
| 3256 | break; |
| 3257 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3258 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3259 | } else { |
| 3260 | BTM_SecDeleteDevice(remote_bd_addr); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3261 | /* need to remove all pending background connection */ |
| 3262 | BTA_GATTC_CancelOpen(0, remote_bd_addr, false); |
| 3263 | /* remove all cached GATT information */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3264 | BTA_GATTC_Refresh(remote_bd_addr); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3265 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3266 | } |
| 3267 | |
| 3268 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3269 | * |
| 3270 | * Function bta_dm_adjust_roles |
| 3271 | * |
| 3272 | * Description Adjust roles |
| 3273 | * |
| 3274 | * |
| 3275 | * Returns void |
| 3276 | * |
| 3277 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3278 | static void bta_dm_adjust_roles(bool delay_role_switch) { |
| 3279 | uint8_t i; |
| 3280 | bool set_master_role = false; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3281 | uint8_t br_count = |
| 3282 | bta_dm_cb.device_list.count - bta_dm_cb.device_list.le_count; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3283 | if (br_count) { |
| 3284 | /* the configuration is no scatternet |
| 3285 | * or AV connection exists and there are more than one ACL link */ |
| 3286 | if ((p_bta_dm_rm_cfg[0].cfg == BTA_DM_NO_SCATTERNET) || |
| 3287 | (bta_dm_cb.cur_av_count && br_count > 1)) { |
| 3288 | L2CA_SetDesireRole(HCI_ROLE_MASTER); |
| 3289 | set_master_role = true; |
| 3290 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3291 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3292 | for (i = 0; i < bta_dm_cb.device_list.count; i++) { |
Myles Watson | 84baa7f | 2016-11-14 12:05:37 -0800 | [diff] [blame] | 3293 | if (bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_CONNECTED && |
| 3294 | bta_dm_cb.device_list.peer_device[i].transport == |
| 3295 | BT_TRANSPORT_BR_EDR) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3296 | if (!set_master_role && |
| 3297 | (bta_dm_cb.device_list.peer_device[i].pref_role != BTA_ANY_ROLE) && |
| 3298 | (p_bta_dm_rm_cfg[0].cfg == BTA_DM_PARTIAL_SCATTERNET)) { |
| 3299 | L2CA_SetDesireRole(HCI_ROLE_MASTER); |
| 3300 | set_master_role = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3301 | } |
| 3302 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3303 | if ((bta_dm_cb.device_list.peer_device[i].pref_role == |
| 3304 | BTA_MASTER_ROLE_ONLY) || |
| 3305 | (br_count > 1)) { |
| 3306 | /* Initiating immediate role switch with certain remote devices |
| 3307 | has caused issues due to role switch colliding with link encryption |
| 3308 | setup and |
| 3309 | causing encryption (and in turn the link) to fail . These device . |
| 3310 | Firmware |
| 3311 | versions are stored in a blacklist and role switch with these |
| 3312 | devices are |
| 3313 | delayed to avoid the collision with link encryption setup */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3314 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3315 | if (bta_dm_cb.device_list.peer_device[i].pref_role != |
| 3316 | BTA_SLAVE_ROLE_ONLY && |
| 3317 | delay_role_switch == false) { |
| 3318 | BTM_SwitchRole(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, |
| 3319 | HCI_ROLE_MASTER, NULL); |
| 3320 | } else { |
| 3321 | alarm_set_on_queue( |
| 3322 | bta_dm_cb.switch_delay_timer, BTA_DM_SWITCH_DELAY_TIMER_MS, |
| 3323 | bta_dm_delay_role_switch_cback, NULL, btu_bta_alarm_queue); |
| 3324 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3325 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3326 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3327 | } |
| 3328 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3329 | if (!set_master_role) { |
| 3330 | L2CA_SetDesireRole(L2CAP_DESIRED_LINK_ROLE); |
| 3331 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3332 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3333 | } else { |
| 3334 | L2CA_SetDesireRole(L2CAP_DESIRED_LINK_ROLE); |
| 3335 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3339 | * |
| 3340 | * Function bta_dm_get_remname |
| 3341 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3342 | * Description Returns a pointer to the remote name stored in the DM |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 3343 | * control block if it exists, or from the BTM memory. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3344 | * |
| 3345 | * Returns char * - Pointer to the remote device name |
| 3346 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3347 | static char* bta_dm_get_remname(void) { |
| 3348 | char* p_name = (char*)bta_dm_search_cb.peer_name; |
| 3349 | char* p_temp; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3350 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3351 | /* If the name isn't already stored, try retrieving from BTM */ |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame] | 3352 | if (*p_name == '\0') { |
| 3353 | p_temp = BTM_SecReadDevName(bta_dm_search_cb.peer_bdaddr); |
| 3354 | if (p_temp != NULL) p_name = p_temp; |
| 3355 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3356 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3357 | return p_name; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3361 | * |
| 3362 | * Function bta_dm_bond_cancel_complete_cback |
| 3363 | * |
| 3364 | * Description Authentication complete callback from BTM |
| 3365 | * |
| 3366 | * Returns void |
| 3367 | * |
| 3368 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3369 | static void bta_dm_bond_cancel_complete_cback(tBTM_STATUS result) { |
| 3370 | tBTA_DM_SEC sec_event; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3371 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3372 | if (result == BTM_SUCCESS) |
| 3373 | sec_event.bond_cancel_cmpl.result = BTA_SUCCESS; |
| 3374 | else |
| 3375 | sec_event.bond_cancel_cmpl.result = BTA_FAILURE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3376 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3377 | if (bta_dm_cb.p_sec_cback) { |
| 3378 | bta_dm_cb.p_sec_cback(BTA_DM_BOND_CANCEL_CMPL_EVT, &sec_event); |
| 3379 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3380 | } |
| 3381 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3382 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3383 | * |
| 3384 | * Function find_utf8_char_boundary |
| 3385 | * |
| 3386 | * Description This function checks a UTF8 string |utf8str| starting at |
| 3387 | * |offset|, moving backwards and returns the offset of the |
| 3388 | * next valid UTF8 character boundary found. |
| 3389 | * |
| 3390 | * Returns Offset of UTF8 character boundary |
| 3391 | * |
| 3392 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3393 | static size_t find_utf8_char_boundary(const char* utf8str, size_t offset) { |
Jack He | f2af1c4 | 2016-12-13 01:59:12 -0800 | [diff] [blame] | 3394 | CHECK(utf8str); |
| 3395 | CHECK(offset > 0); |
Matadeen Mishra | c5734d7 | 2016-02-03 20:50:31 +0530 | [diff] [blame] | 3396 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3397 | while (--offset) { |
| 3398 | uint8_t ch = (uint8_t)utf8str[offset]; |
| 3399 | if ((ch & 0x80) == 0x00) // ASCII |
| 3400 | return offset + 1; |
| 3401 | if ((ch & 0xC0) == 0xC0) // Multi-byte sequence start |
| 3402 | return offset; |
| 3403 | } |
Matadeen Mishra | c5734d7 | 2016-02-03 20:50:31 +0530 | [diff] [blame] | 3404 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3405 | return 0; |
Matadeen Mishra | c5734d7 | 2016-02-03 20:50:31 +0530 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3409 | * |
| 3410 | * Function bta_dm_set_eir |
| 3411 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3412 | * Description This function creates EIR tagged data and writes it to |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 3413 | * controller. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3414 | * |
| 3415 | * Returns None |
| 3416 | * |
| 3417 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3418 | static void bta_dm_set_eir(char* local_name) { |
| 3419 | uint8_t* p; |
| 3420 | uint8_t* p_length; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3421 | #if (BTA_EIR_CANNED_UUID_LIST != TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3422 | uint8_t* p_type; |
| 3423 | uint8_t max_num_uuid; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3424 | #if (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3425 | uint8_t custom_uuid_idx; |
Chris Manton | 1e61ce1 | 2014-10-24 09:12:41 -0700 | [diff] [blame] | 3426 | #endif // BTA_EIR_SERVER_NUM_CUSTOM_UUID |
| 3427 | #endif // BTA_EIR_CANNED_UUID_LIST |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3428 | #if (BTM_EIR_DEFAULT_FEC_REQUIRED == FALSE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3429 | uint8_t free_eir_length = HCI_EXT_INQ_RESPONSE_LEN; |
Chris Manton | 1e61ce1 | 2014-10-24 09:12:41 -0700 | [diff] [blame] | 3430 | #else // BTM_EIR_DEFAULT_FEC_REQUIRED |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3431 | uint8_t free_eir_length = HCI_DM5_PACKET_SIZE; |
Casper Bonde | 818d0f2 | 2015-05-21 11:08:45 +0200 | [diff] [blame] | 3432 | #endif // BTM_EIR_DEFAULT_FEC_REQUIRED |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3433 | uint8_t num_uuid; |
| 3434 | uint8_t data_type; |
| 3435 | uint8_t local_name_len; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3436 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3437 | /* wait until complete to disable */ |
| 3438 | if (alarm_is_scheduled(bta_dm_cb.disable_timer)) return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3439 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 3440 | #if (BTA_EIR_CANNED_UUID_LIST != TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3441 | /* if local name is not provided, get it from controller */ |
| 3442 | if (local_name == NULL) { |
| 3443 | if (BTM_ReadLocalDeviceName(&local_name) != BTM_SUCCESS) { |
| 3444 | APPL_TRACE_ERROR("Fail to read local device name for EIR"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3445 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3446 | } |
Chris Manton | 1e61ce1 | 2014-10-24 09:12:41 -0700 | [diff] [blame] | 3447 | #endif // BTA_EIR_CANNED_UUID_LIST |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3448 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3449 | /* Allocate a buffer to hold HCI command */ |
| 3450 | BT_HDR* p_buf = (BT_HDR*)osi_malloc(BTM_CMD_BUF_SIZE); |
| 3451 | p = (uint8_t*)p_buf + BTM_HCI_EIR_OFFSET; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3452 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3453 | memset(p, 0x00, HCI_EXT_INQ_RESPONSE_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3454 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3455 | APPL_TRACE_DEBUG("BTA is generating EIR"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3456 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3457 | if (local_name) |
| 3458 | local_name_len = strlen(local_name); |
| 3459 | else |
| 3460 | local_name_len = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3461 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3462 | data_type = BTM_EIR_COMPLETE_LOCAL_NAME_TYPE; |
| 3463 | /* if local name is longer than minimum length of shortened name */ |
| 3464 | /* check whether it needs to be shortened or not */ |
| 3465 | if (local_name_len > p_bta_dm_eir_cfg->bta_dm_eir_min_name_len) { |
| 3466 | /* get number of UUID 16-bit list */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3467 | #if (BTA_EIR_CANNED_UUID_LIST == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3468 | num_uuid = p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len / LEN_UUID_16; |
| 3469 | #else // BTA_EIR_CANNED_UUID_LIST |
| 3470 | max_num_uuid = (free_eir_length - 2) / LEN_UUID_16; |
| 3471 | data_type = BTM_GetEirSupportedServices(bta_dm_cb.eir_uuid, &p, |
| 3472 | max_num_uuid, &num_uuid); |
| 3473 | p = (uint8_t*)p_buf + BTM_HCI_EIR_OFFSET; /* reset p */ |
Chris Manton | 1e61ce1 | 2014-10-24 09:12:41 -0700 | [diff] [blame] | 3474 | #endif // BTA_EIR_CANNED_UUID_LIST |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3475 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3476 | /* if UUID doesn't fit remaing space, shorten local name */ |
| 3477 | if (local_name_len > (free_eir_length - 4 - num_uuid * LEN_UUID_16)) { |
| 3478 | local_name_len = find_utf8_char_boundary( |
| 3479 | local_name, p_bta_dm_eir_cfg->bta_dm_eir_min_name_len); |
| 3480 | APPL_TRACE_WARNING("%s local name is shortened (%d)", __func__, |
| 3481 | local_name_len); |
| 3482 | data_type = BTM_EIR_SHORTENED_LOCAL_NAME_TYPE; |
| 3483 | } else { |
| 3484 | data_type = BTM_EIR_COMPLETE_LOCAL_NAME_TYPE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3485 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3486 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3487 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3488 | UINT8_TO_STREAM(p, local_name_len + 1); |
| 3489 | UINT8_TO_STREAM(p, data_type); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3490 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3491 | if (local_name != NULL) { |
| 3492 | memcpy(p, local_name, local_name_len); |
| 3493 | p += local_name_len; |
| 3494 | } |
| 3495 | free_eir_length -= local_name_len + 2; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3496 | |
| 3497 | #if (BTA_EIR_CANNED_UUID_LIST == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3498 | /* if UUID list is provided as static data in configuration */ |
| 3499 | if ((p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len > 0) && |
| 3500 | (p_bta_dm_eir_cfg->bta_dm_eir_uuid16)) { |
| 3501 | if (free_eir_length > LEN_UUID_16 + 2) { |
| 3502 | free_eir_length -= 2; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3503 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3504 | if (free_eir_length >= p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len) { |
| 3505 | num_uuid = p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len / LEN_UUID_16; |
| 3506 | data_type = BTM_EIR_COMPLETE_16BITS_UUID_TYPE; |
| 3507 | } else /* not enough room for all UUIDs */ |
| 3508 | { |
| 3509 | APPL_TRACE_WARNING("BTA EIR: UUID 16-bit list is truncated"); |
| 3510 | num_uuid = free_eir_length / LEN_UUID_16; |
| 3511 | data_type = BTM_EIR_MORE_16BITS_UUID_TYPE; |
| 3512 | } |
| 3513 | UINT8_TO_STREAM(p, num_uuid * LEN_UUID_16 + 1); |
| 3514 | UINT8_TO_STREAM(p, data_type); |
| 3515 | memcpy(p, p_bta_dm_eir_cfg->bta_dm_eir_uuid16, num_uuid * LEN_UUID_16); |
| 3516 | p += num_uuid * LEN_UUID_16; |
| 3517 | free_eir_length -= num_uuid * LEN_UUID_16; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3518 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3519 | } |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 3520 | #else /* (BTA_EIR_CANNED_UUID_LIST == TRUE) */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3521 | /* if UUID list is dynamic */ |
| 3522 | if (free_eir_length >= 2) { |
| 3523 | p_length = p++; |
| 3524 | p_type = p++; |
| 3525 | num_uuid = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3526 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3527 | max_num_uuid = (free_eir_length - 2) / LEN_UUID_16; |
| 3528 | data_type = BTM_GetEirSupportedServices(bta_dm_cb.eir_uuid, &p, |
| 3529 | max_num_uuid, &num_uuid); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3530 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3531 | if (data_type == BTM_EIR_MORE_16BITS_UUID_TYPE) { |
| 3532 | APPL_TRACE_WARNING("BTA EIR: UUID 16-bit list is truncated"); |
| 3533 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3534 | #if (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3535 | else { |
| 3536 | for (custom_uuid_idx = 0; |
| 3537 | custom_uuid_idx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; |
| 3538 | custom_uuid_idx++) { |
| 3539 | if (bta_dm_cb.custom_uuid[custom_uuid_idx].len == LEN_UUID_16) { |
| 3540 | if (num_uuid < max_num_uuid) { |
| 3541 | UINT16_TO_STREAM(p, |
| 3542 | bta_dm_cb.custom_uuid[custom_uuid_idx].uu.uuid16); |
| 3543 | num_uuid++; |
| 3544 | } else { |
| 3545 | data_type = BTM_EIR_MORE_16BITS_UUID_TYPE; |
| 3546 | APPL_TRACE_WARNING("BTA EIR: UUID 16-bit list is truncated"); |
| 3547 | break; |
| 3548 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3549 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3550 | } |
| 3551 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3552 | #endif /* (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) */ |
| 3553 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3554 | UINT8_TO_STREAM(p_length, num_uuid * LEN_UUID_16 + 1); |
| 3555 | UINT8_TO_STREAM(p_type, data_type); |
| 3556 | free_eir_length -= num_uuid * LEN_UUID_16 + 2; |
| 3557 | } |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 3558 | #endif /* (BTA_EIR_CANNED_UUID_LIST == TRUE) */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3559 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 3560 | #if (BTA_EIR_CANNED_UUID_LIST != TRUE && BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3561 | /* Adding 32-bit UUID list */ |
| 3562 | if (free_eir_length >= 2) { |
| 3563 | p_length = p++; |
| 3564 | p_type = p++; |
| 3565 | num_uuid = 0; |
| 3566 | data_type = BTM_EIR_COMPLETE_32BITS_UUID_TYPE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3567 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3568 | max_num_uuid = (free_eir_length - 2) / LEN_UUID_32; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3569 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3570 | for (custom_uuid_idx = 0; custom_uuid_idx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; |
| 3571 | custom_uuid_idx++) { |
| 3572 | if (bta_dm_cb.custom_uuid[custom_uuid_idx].len == LEN_UUID_32) { |
| 3573 | if (num_uuid < max_num_uuid) { |
| 3574 | UINT32_TO_STREAM(p, bta_dm_cb.custom_uuid[custom_uuid_idx].uu.uuid32); |
| 3575 | num_uuid++; |
| 3576 | } else { |
| 3577 | data_type = BTM_EIR_MORE_32BITS_UUID_TYPE; |
| 3578 | APPL_TRACE_WARNING("BTA EIR: UUID 32-bit list is truncated"); |
| 3579 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3580 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3581 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3582 | } |
| 3583 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3584 | UINT8_TO_STREAM(p_length, num_uuid * LEN_UUID_32 + 1); |
| 3585 | UINT8_TO_STREAM(p_type, data_type); |
| 3586 | free_eir_length -= num_uuid * LEN_UUID_32 + 2; |
| 3587 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3588 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3589 | /* Adding 128-bit UUID list */ |
| 3590 | if (free_eir_length >= 2) { |
| 3591 | p_length = p++; |
| 3592 | p_type = p++; |
| 3593 | num_uuid = 0; |
| 3594 | data_type = BTM_EIR_COMPLETE_128BITS_UUID_TYPE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3595 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3596 | max_num_uuid = (free_eir_length - 2) / LEN_UUID_128; |
| 3597 | |
| 3598 | for (custom_uuid_idx = 0; custom_uuid_idx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; |
| 3599 | custom_uuid_idx++) { |
| 3600 | if (bta_dm_cb.custom_uuid[custom_uuid_idx].len == LEN_UUID_128) { |
| 3601 | if (num_uuid < max_num_uuid) { |
| 3602 | ARRAY16_TO_STREAM(p, |
| 3603 | bta_dm_cb.custom_uuid[custom_uuid_idx].uu.uuid128); |
| 3604 | num_uuid++; |
| 3605 | } else { |
| 3606 | data_type = BTM_EIR_MORE_128BITS_UUID_TYPE; |
| 3607 | APPL_TRACE_WARNING("BTA EIR: UUID 128-bit list is truncated"); |
| 3608 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3609 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3610 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3611 | } |
| 3612 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3613 | UINT8_TO_STREAM(p_length, num_uuid * LEN_UUID_128 + 1); |
| 3614 | UINT8_TO_STREAM(p_type, data_type); |
| 3615 | free_eir_length -= num_uuid * LEN_UUID_128 + 2; |
| 3616 | } |
| 3617 | #endif /* ( BTA_EIR_CANNED_UUID_LIST != TRUE \ |
| 3618 | )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3619 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3620 | /* if Flags are provided in configuration */ |
| 3621 | if ((p_bta_dm_eir_cfg->bta_dm_eir_flag_len > 0) && |
| 3622 | (p_bta_dm_eir_cfg->bta_dm_eir_flags) && |
| 3623 | (free_eir_length >= p_bta_dm_eir_cfg->bta_dm_eir_flag_len + 2)) { |
| 3624 | UINT8_TO_STREAM(p, p_bta_dm_eir_cfg->bta_dm_eir_flag_len + 1); |
| 3625 | UINT8_TO_STREAM(p, BTM_EIR_FLAGS_TYPE); |
| 3626 | memcpy(p, p_bta_dm_eir_cfg->bta_dm_eir_flags, |
| 3627 | p_bta_dm_eir_cfg->bta_dm_eir_flag_len); |
| 3628 | p += p_bta_dm_eir_cfg->bta_dm_eir_flag_len; |
| 3629 | free_eir_length -= p_bta_dm_eir_cfg->bta_dm_eir_flag_len + 2; |
| 3630 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3631 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3632 | /* if Manufacturer Specific are provided in configuration */ |
| 3633 | if ((p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len > 0) && |
| 3634 | (p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec) && |
| 3635 | (free_eir_length >= p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len + 2)) { |
| 3636 | p_length = p; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3637 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3638 | UINT8_TO_STREAM(p, p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len + 1); |
| 3639 | UINT8_TO_STREAM(p, BTM_EIR_MANUFACTURER_SPECIFIC_TYPE); |
| 3640 | memcpy(p, p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec, |
| 3641 | p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len); |
| 3642 | p += p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len; |
| 3643 | free_eir_length -= p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len + 2; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3644 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3645 | } else { |
| 3646 | p_length = NULL; |
| 3647 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3648 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3649 | /* if Inquiry Tx Resp Power compiled */ |
| 3650 | if ((p_bta_dm_eir_cfg->bta_dm_eir_inq_tx_power) && (free_eir_length >= 3)) { |
| 3651 | UINT8_TO_STREAM(p, 2); /* Length field */ |
| 3652 | UINT8_TO_STREAM(p, BTM_EIR_TX_POWER_LEVEL_TYPE); |
| 3653 | UINT8_TO_STREAM(p, *(p_bta_dm_eir_cfg->bta_dm_eir_inq_tx_power)); |
| 3654 | free_eir_length -= 3; |
| 3655 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3656 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3657 | if (free_eir_length) |
| 3658 | UINT8_TO_STREAM(p, 0); /* terminator of significant part */ |
| 3659 | |
| 3660 | BTM_WriteEIR(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3661 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3662 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3663 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3664 | * |
| 3665 | * Function bta_dm_eir_search_services |
| 3666 | * |
| 3667 | * Description This function searches services in received EIR |
| 3668 | * |
| 3669 | * Returns None |
| 3670 | * |
| 3671 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3672 | static void bta_dm_eir_search_services(tBTM_INQ_RESULTS* p_result, |
| 3673 | tBTA_SERVICE_MASK* p_services_to_search, |
| 3674 | tBTA_SERVICE_MASK* p_services_found) { |
| 3675 | tBTA_SERVICE_MASK service_index = 0; |
| 3676 | tBTM_EIR_SEARCH_RESULT result; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3677 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3678 | VLOG(1) << "BTA searching services in EIR of BDA:" |
| 3679 | << p_result->remote_bd_addr; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3680 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3681 | APPL_TRACE_DEBUG(" with services_to_search=0x%08X", *p_services_to_search); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3682 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3683 | /* always do GATT based service discovery by SDP instead of from EIR */ |
| 3684 | /* if GATT based service is also to be put in EIR, need to modify this */ |
Myles Watson | 9979121 | 2016-11-18 08:42:23 -0800 | [diff] [blame] | 3685 | while (service_index < (BTA_MAX_SERVICE_ID - 1)) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3686 | if (*p_services_to_search & |
| 3687 | (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(service_index))) { |
| 3688 | result = BTM_HasInquiryEirService( |
| 3689 | p_result, bta_service_id_to_uuid_lkup_tbl[service_index]); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3690 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3691 | /* Searching for HSP v1.2 only device */ |
| 3692 | if ((result != BTM_EIR_FOUND) && |
| 3693 | (bta_service_id_to_uuid_lkup_tbl[service_index] == |
| 3694 | UUID_SERVCLASS_HEADSET)) { |
| 3695 | result = BTM_HasInquiryEirService(p_result, UUID_SERVCLASS_HEADSET_HS); |
| 3696 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3697 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3698 | if (result == BTM_EIR_FOUND) { |
| 3699 | /* If Plug and Play service record, need to check to see if Broadcom |
| 3700 | * stack */ |
| 3701 | /* However, EIR data doesn't have EXT_BRCM_VERSION so just skip it */ |
| 3702 | if (bta_service_id_to_uuid_lkup_tbl[service_index] != |
| 3703 | UUID_SERVCLASS_PNP_INFORMATION) { |
| 3704 | *p_services_found |= (tBTA_SERVICE_MASK)( |
| 3705 | BTA_SERVICE_ID_TO_SERVICE_MASK(service_index)); |
| 3706 | /* remove the service from services to be searched */ |
| 3707 | *p_services_to_search &= (tBTA_SERVICE_MASK)( |
| 3708 | ~(BTA_SERVICE_ID_TO_SERVICE_MASK(service_index))); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3709 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3710 | } else if (result == BTM_EIR_NOT_FOUND) { |
| 3711 | /* remove the service from services to be searched */ |
| 3712 | *p_services_to_search &= (tBTA_SERVICE_MASK)( |
| 3713 | ~(BTA_SERVICE_ID_TO_SERVICE_MASK(service_index))); |
| 3714 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3715 | } |
| 3716 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3717 | service_index++; |
| 3718 | } |
| 3719 | |
| 3720 | APPL_TRACE_ERROR( |
| 3721 | "BTA EIR search result, services_to_search=0x%08X, services_found=0x%08X", |
| 3722 | *p_services_to_search, *p_services_found); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3723 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3724 | |
Chris Manton | 1e61ce1 | 2014-10-24 09:12:41 -0700 | [diff] [blame] | 3725 | #if (BTA_EIR_CANNED_UUID_LIST != TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3726 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3727 | * |
| 3728 | * Function bta_dm_eir_update_uuid |
| 3729 | * |
| 3730 | * Description This function adds or removes service UUID in EIR database. |
| 3731 | * |
| 3732 | * Returns None |
| 3733 | * |
| 3734 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3735 | void bta_dm_eir_update_uuid(uint16_t uuid16, bool adding) { |
| 3736 | /* if this UUID is not advertised in EIR */ |
| 3737 | if (!BTM_HasEirService(p_bta_dm_eir_cfg->uuid_mask, uuid16)) return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3738 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3739 | if (adding) { |
| 3740 | APPL_TRACE_EVENT("Adding UUID=0x%04X into EIR", uuid16); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3741 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3742 | BTM_AddEirService(bta_dm_cb.eir_uuid, uuid16); |
| 3743 | } else { |
| 3744 | APPL_TRACE_EVENT("Removing UUID=0x%04X from EIR", uuid16); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3745 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3746 | BTM_RemoveEirService(bta_dm_cb.eir_uuid, uuid16); |
| 3747 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3748 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3749 | bta_dm_set_eir(NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3750 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3751 | APPL_TRACE_EVENT("bta_dm_eir_update_uuid UUID bit mask=0x%08X %08X", |
| 3752 | bta_dm_cb.eir_uuid[1], bta_dm_cb.eir_uuid[0]); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3753 | } |
| 3754 | #endif |
| 3755 | |
| 3756 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3757 | * |
| 3758 | * Function bta_dm_enable_test_mode |
| 3759 | * |
| 3760 | * Description enable test mode |
| 3761 | * |
| 3762 | * |
| 3763 | * Returns void |
| 3764 | * |
| 3765 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3766 | void bta_dm_enable_test_mode(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 3767 | BTM_EnableTestMode(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3768 | } |
| 3769 | |
| 3770 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3771 | * |
| 3772 | * Function bta_dm_disable_test_mode |
| 3773 | * |
| 3774 | * Description disable test mode |
| 3775 | * |
| 3776 | * |
| 3777 | * Returns void |
| 3778 | * |
| 3779 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3780 | void bta_dm_disable_test_mode(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 3781 | BTM_DeviceReset(NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3782 | } |
| 3783 | |
| 3784 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3785 | * |
| 3786 | * Function bta_dm_execute_callback |
| 3787 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3788 | * Description Just execute a generic call back in the context of the |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 3789 | * BTU/BTA tack |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3790 | * |
| 3791 | * |
| 3792 | * Returns void |
| 3793 | * |
| 3794 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3795 | void bta_dm_execute_callback(tBTA_DM_MSG* p_data) { |
| 3796 | /* sanity check */ |
| 3797 | if (p_data->exec_cback.p_exec_cback == NULL) { |
| 3798 | return; |
| 3799 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3800 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3801 | p_data->exec_cback.p_exec_cback(p_data->exec_cback.p_param); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3802 | } |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 3803 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3804 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3805 | * |
| 3806 | * Function bta_dm_encrypt_cback |
| 3807 | * |
| 3808 | * Description link encryption complete callback. |
| 3809 | * |
| 3810 | * Returns None |
| 3811 | * |
| 3812 | ******************************************************************************/ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3813 | void bta_dm_encrypt_cback(const bt_bdaddr_t* bd_addr, tBT_TRANSPORT transport, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3814 | UNUSED_ATTR void* p_ref_data, tBTM_STATUS result) { |
| 3815 | tBTA_STATUS bta_status = BTA_SUCCESS; |
| 3816 | tBTA_DM_ENCRYPT_CBACK* p_callback = NULL; |
| 3817 | uint8_t i; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3818 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3819 | for (i = 0; i < bta_dm_cb.device_list.count; i++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3820 | if (bta_dm_cb.device_list.peer_device[i].peer_bdaddr == *bd_addr && |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3821 | bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_CONNECTED) |
| 3822 | break; |
| 3823 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3824 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3825 | if (i < bta_dm_cb.device_list.count) { |
| 3826 | p_callback = bta_dm_cb.device_list.peer_device[i].p_encrypt_cback; |
| 3827 | bta_dm_cb.device_list.peer_device[i].p_encrypt_cback = NULL; |
| 3828 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3829 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3830 | switch (result) { |
| 3831 | case BTM_SUCCESS: |
| 3832 | break; |
| 3833 | case BTM_WRONG_MODE: |
| 3834 | bta_status = BTA_WRONG_MODE; |
| 3835 | break; |
| 3836 | case BTM_NO_RESOURCES: |
| 3837 | bta_status = BTA_NO_RESOURCES; |
| 3838 | break; |
| 3839 | case BTM_BUSY: |
| 3840 | bta_status = BTA_BUSY; |
| 3841 | break; |
| 3842 | default: |
| 3843 | bta_status = BTA_FAILURE; |
| 3844 | break; |
| 3845 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3846 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3847 | APPL_TRACE_DEBUG("bta_dm_encrypt_cback status =%d p_callback=0x%x", |
| 3848 | bta_status, p_callback); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3849 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3850 | if (p_callback) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3851 | (*p_callback)(*bd_addr, transport, bta_status); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3852 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3853 | } |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 3854 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3855 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3856 | * |
| 3857 | * Function bta_dm_set_encryption |
| 3858 | * |
| 3859 | * Description This function to encrypt the link |
| 3860 | * |
| 3861 | * Returns None |
| 3862 | * |
| 3863 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3864 | void bta_dm_set_encryption(tBTA_DM_MSG* p_data) { |
| 3865 | uint8_t i; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3866 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3867 | APPL_TRACE_DEBUG("bta_dm_set_encryption"); // todo |
| 3868 | if (!p_data->set_encryption.p_callback) { |
| 3869 | APPL_TRACE_ERROR("bta_dm_set_encryption callback is not provided"); |
| 3870 | return; |
| 3871 | } |
| 3872 | for (i = 0; i < bta_dm_cb.device_list.count; i++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3873 | if (bta_dm_cb.device_list.peer_device[i].peer_bdaddr == |
| 3874 | p_data->set_encryption.bd_addr && |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3875 | bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_CONNECTED) |
| 3876 | break; |
| 3877 | } |
| 3878 | if (i < bta_dm_cb.device_list.count) { |
| 3879 | if (bta_dm_cb.device_list.peer_device[i].p_encrypt_cback) { |
| 3880 | APPL_TRACE_ERROR("earlier enc was not done for same device"); |
| 3881 | (*p_data->set_encryption.p_callback)(p_data->set_encryption.bd_addr, |
| 3882 | p_data->set_encryption.transport, |
| 3883 | BTA_BUSY); |
| 3884 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3885 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3886 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3887 | if (BTM_SetEncryption(p_data->set_encryption.bd_addr, |
| 3888 | p_data->set_encryption.transport, |
| 3889 | bta_dm_encrypt_cback, NULL, |
| 3890 | p_data->set_encryption.sec_act) == BTM_CMD_STARTED) { |
| 3891 | bta_dm_cb.device_list.peer_device[i].p_encrypt_cback = |
| 3892 | p_data->set_encryption.p_callback; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3893 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3894 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3895 | } |
| 3896 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3897 | bool bta_dm_check_if_only_hd_connected(const bt_bdaddr_t& peer_addr) { |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 3898 | APPL_TRACE_DEBUG("%s: count(%d)", __func__, bta_dm_conn_srvcs.count); |
| 3899 | |
| 3900 | for (uint8_t j = 0; j < bta_dm_conn_srvcs.count; j++) { |
| 3901 | // Check if profiles other than hid are connected |
| 3902 | if ((bta_dm_conn_srvcs.conn_srvc[j].id != BTA_ID_HD) && |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3903 | bta_dm_conn_srvcs.conn_srvc[j].peer_bdaddr == peer_addr) { |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 3904 | APPL_TRACE_DEBUG("%s: Another profile (id=%d) is connected", __func__, |
| 3905 | bta_dm_conn_srvcs.conn_srvc[j].id); |
Jack He | fe695a5 | 2017-05-07 17:27:47 -0700 | [diff] [blame] | 3906 | return false; |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 3907 | } |
| 3908 | } |
| 3909 | |
Jack He | fe695a5 | 2017-05-07 17:27:47 -0700 | [diff] [blame] | 3910 | return true; |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 3911 | } |
| 3912 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3913 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3914 | * |
| 3915 | * Function bta_dm_observe_results_cb |
| 3916 | * |
| 3917 | * Description Callback for BLE Observe result |
| 3918 | * |
| 3919 | * |
| 3920 | * Returns void |
| 3921 | * |
| 3922 | ******************************************************************************/ |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 3923 | static void bta_dm_observe_results_cb(tBTM_INQ_RESULTS* p_inq, uint8_t* p_eir, |
Jakub Pawlowski | f7100bb | 2017-02-13 14:31:52 -0800 | [diff] [blame] | 3924 | uint16_t eir_len) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3925 | tBTA_DM_SEARCH result; |
| 3926 | tBTM_INQ_INFO* p_inq_info; |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 3927 | APPL_TRACE_DEBUG("bta_dm_observe_results_cb"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3928 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3929 | result.inq_res.bd_addr = p_inq->remote_bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3930 | result.inq_res.rssi = p_inq->rssi; |
| 3931 | result.inq_res.ble_addr_type = p_inq->ble_addr_type; |
| 3932 | result.inq_res.inq_result_type = p_inq->inq_result_type; |
| 3933 | result.inq_res.device_type = p_inq->device_type; |
| 3934 | result.inq_res.flag = p_inq->flag; |
Jakub Pawlowski | 7de0f9b | 2017-01-27 08:06:20 -0800 | [diff] [blame] | 3935 | result.inq_res.ble_evt_type = p_inq->ble_evt_type; |
| 3936 | result.inq_res.ble_primary_phy = p_inq->ble_primary_phy; |
| 3937 | result.inq_res.ble_secondary_phy = p_inq->ble_secondary_phy; |
| 3938 | result.inq_res.ble_advertising_sid = p_inq->ble_advertising_sid; |
| 3939 | result.inq_res.ble_tx_power = p_inq->ble_tx_power; |
| 3940 | result.inq_res.ble_periodic_adv_int = p_inq->ble_periodic_adv_int; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3941 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3942 | /* application will parse EIR to find out remote device name */ |
| 3943 | result.inq_res.p_eir = p_eir; |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 3944 | result.inq_res.eir_len = eir_len; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3945 | |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame] | 3946 | p_inq_info = BTM_InqDbRead(p_inq->remote_bd_addr); |
| 3947 | if (p_inq_info != NULL) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3948 | /* initialize remt_name_not_required to false so that we get the name by |
| 3949 | * default */ |
| 3950 | result.inq_res.remt_name_not_required = false; |
| 3951 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3952 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3953 | if (bta_dm_search_cb.p_scan_cback) |
| 3954 | bta_dm_search_cb.p_scan_cback(BTA_DM_INQ_RES_EVT, &result); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3955 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3956 | if (p_inq_info) { |
| 3957 | /* application indicates if it knows the remote name, inside the callback |
| 3958 | copy that to the inquiry data base*/ |
| 3959 | if (result.inq_res.remt_name_not_required) |
| 3960 | p_inq_info->appl_knows_rem_name = true; |
| 3961 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3962 | } |
| 3963 | |
| 3964 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3965 | * |
| 3966 | * Function bta_dm_observe_cmpl_cb |
| 3967 | * |
| 3968 | * Description Callback for BLE Observe complete |
| 3969 | * |
| 3970 | * |
| 3971 | * Returns void |
| 3972 | * |
| 3973 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3974 | static void bta_dm_observe_cmpl_cb(void* p_result) { |
| 3975 | tBTA_DM_SEARCH data; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3976 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3977 | APPL_TRACE_DEBUG("bta_dm_observe_cmpl_cb"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3978 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3979 | data.inq_cmpl.num_resps = ((tBTM_INQUIRY_CMPL*)p_result)->num_resp; |
| 3980 | if (bta_dm_search_cb.p_scan_cback) { |
| 3981 | bta_dm_search_cb.p_scan_cback(BTA_DM_INQ_CMPL_EVT, &data); |
| 3982 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3983 | } |
| 3984 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3985 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3986 | * |
| 3987 | * Function bta_dm_ble_smp_cback |
| 3988 | * |
| 3989 | * Description Callback for BLE SMP |
| 3990 | * |
| 3991 | * |
| 3992 | * Returns void |
| 3993 | * |
| 3994 | ******************************************************************************/ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3995 | static uint8_t bta_dm_ble_smp_cback(tBTM_LE_EVT event, const bt_bdaddr_t& bda, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3996 | tBTM_LE_EVT_DATA* p_data) { |
| 3997 | tBTM_STATUS status = BTM_SUCCESS; |
| 3998 | tBTA_DM_SEC sec_event; |
| 3999 | char* p_name = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4000 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4001 | if (!bta_dm_cb.p_sec_cback) return BTM_NOT_AUTHORIZED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4002 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4003 | memset(&sec_event, 0, sizeof(tBTA_DM_SEC)); |
| 4004 | switch (event) { |
| 4005 | case BTM_LE_IO_REQ_EVT: |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4006 | #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) |
| 4007 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4008 | bta_dm_co_ble_io_req( |
| 4009 | bda, &p_data->io_req.io_cap, &p_data->io_req.oob_data, |
| 4010 | &p_data->io_req.auth_req, &p_data->io_req.max_key_size, |
| 4011 | &p_data->io_req.init_keys, &p_data->io_req.resp_keys); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4012 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4013 | APPL_TRACE_EVENT("io mitm: %d oob_data:%d", p_data->io_req.auth_req, |
| 4014 | p_data->io_req.oob_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4015 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4016 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4017 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4018 | case BTM_LE_SEC_REQUEST_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4019 | sec_event.ble_req.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4020 | p_name = BTM_SecReadDevName(bda); |
| 4021 | if (p_name != NULL) |
| 4022 | strlcpy((char*)sec_event.ble_req.bd_name, p_name, BD_NAME_LEN); |
| 4023 | else |
| 4024 | sec_event.ble_req.bd_name[0] = 0; |
| 4025 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_SEC_REQ_EVT, &sec_event); |
| 4026 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4027 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4028 | case BTM_LE_KEY_NOTIF_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4029 | sec_event.key_notif.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4030 | p_name = BTM_SecReadDevName(bda); |
| 4031 | if (p_name != NULL) |
| 4032 | strlcpy((char*)sec_event.key_notif.bd_name, p_name, BD_NAME_LEN); |
| 4033 | else |
| 4034 | sec_event.key_notif.bd_name[0] = 0; |
| 4035 | sec_event.key_notif.passkey = p_data->key_notif; |
| 4036 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_PASSKEY_NOTIF_EVT, &sec_event); |
| 4037 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4038 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4039 | case BTM_LE_KEY_REQ_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4040 | sec_event.ble_req.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4041 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_PASSKEY_REQ_EVT, &sec_event); |
| 4042 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4043 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4044 | case BTM_LE_OOB_REQ_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4045 | sec_event.ble_req.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4046 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_OOB_REQ_EVT, &sec_event); |
| 4047 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4048 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4049 | case BTM_LE_NC_REQ_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4050 | sec_event.key_notif.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4051 | strlcpy((char*)sec_event.key_notif.bd_name, bta_dm_get_remname(), |
| 4052 | (BD_NAME_LEN)); |
| 4053 | sec_event.key_notif.passkey = p_data->key_notif; |
| 4054 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_NC_REQ_EVT, &sec_event); |
| 4055 | break; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 4056 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4057 | case BTM_LE_SC_OOB_REQ_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4058 | sec_event.ble_req.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4059 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_SC_OOB_REQ_EVT, &sec_event); |
| 4060 | break; |
Jakub Pawlowski | bd60854 | 2016-07-28 05:58:35 -0700 | [diff] [blame] | 4061 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4062 | case BTM_LE_KEY_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4063 | sec_event.ble_key.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4064 | sec_event.ble_key.key_type = p_data->key.key_type; |
| 4065 | sec_event.ble_key.p_key_value = p_data->key.p_key_value; |
| 4066 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_KEY_EVT, &sec_event); |
| 4067 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4068 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4069 | case BTM_LE_COMPLT_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4070 | sec_event.auth_cmpl.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4071 | BTM_ReadDevInfo(bda, &sec_event.auth_cmpl.dev_type, |
| 4072 | &sec_event.auth_cmpl.addr_type); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4073 | p_name = BTM_SecReadDevName(bda); |
| 4074 | if (p_name != NULL) |
| 4075 | strlcpy((char*)sec_event.auth_cmpl.bd_name, p_name, (BD_NAME_LEN)); |
| 4076 | else |
| 4077 | sec_event.auth_cmpl.bd_name[0] = 0; |
Andre Eisenbach | 5b9462d | 2016-02-08 11:34:00 -0800 | [diff] [blame] | 4078 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4079 | if (p_data->complt.reason != 0) { |
| 4080 | sec_event.auth_cmpl.fail_reason = |
| 4081 | BTA_DM_AUTH_CONVERT_SMP_CODE(((uint8_t)p_data->complt.reason)); |
| 4082 | /* delete this device entry from Sec Dev DB */ |
| 4083 | bta_dm_remove_sec_dev_entry(bda); |
| 4084 | } else { |
| 4085 | sec_event.auth_cmpl.success = true; |
| 4086 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 4087 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4088 | if (bta_dm_cb.p_sec_cback) { |
| 4089 | // bta_dm_cb.p_sec_cback(BTA_DM_AUTH_CMPL_EVT, &sec_event); |
| 4090 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_AUTH_CMPL_EVT, &sec_event); |
| 4091 | } |
| 4092 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4093 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4094 | default: |
| 4095 | status = BTM_NOT_AUTHORIZED; |
| 4096 | break; |
| 4097 | } |
| 4098 | return status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4099 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4100 | |
| 4101 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4102 | * |
| 4103 | * Function bta_dm_ble_id_key_cback |
| 4104 | * |
| 4105 | * Description Callback for BLE local ID keys |
| 4106 | * |
| 4107 | * |
| 4108 | * Returns void |
| 4109 | * |
| 4110 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4111 | static void bta_dm_ble_id_key_cback(uint8_t key_type, |
| 4112 | tBTM_BLE_LOCAL_KEYS* p_key) { |
| 4113 | uint8_t evt; |
| 4114 | tBTA_DM_SEC dm_key; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4115 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4116 | switch (key_type) { |
| 4117 | case BTM_BLE_KEY_TYPE_ID: |
| 4118 | case BTM_BLE_KEY_TYPE_ER: |
| 4119 | if (bta_dm_cb.p_sec_cback) { |
| 4120 | memcpy(&dm_key.ble_id_keys, p_key, sizeof(tBTM_BLE_LOCAL_KEYS)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4121 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4122 | evt = (key_type == BTM_BLE_KEY_TYPE_ID) ? BTA_DM_BLE_LOCAL_IR_EVT |
| 4123 | : BTA_DM_BLE_LOCAL_ER_EVT; |
| 4124 | bta_dm_cb.p_sec_cback(evt, &dm_key); |
| 4125 | } |
| 4126 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4127 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4128 | default: |
| 4129 | APPL_TRACE_DEBUG("Unknown key type %d", key_type); |
| 4130 | break; |
| 4131 | } |
| 4132 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4133 | } |
| 4134 | |
| 4135 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4136 | * |
| 4137 | * Function bta_dm_add_blekey |
| 4138 | * |
| 4139 | * Description This function adds an BLE Key to an security database entry. |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4140 | * This function shall only be called AFTER BTA_DmAddBleDevice |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 4141 | * has been called. |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4142 | * It is normally called during host startup to restore all |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 4143 | * required information stored in the NVRAM. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4144 | * |
| 4145 | * Parameters: |
| 4146 | * |
| 4147 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4148 | void bta_dm_add_blekey(tBTA_DM_MSG* p_data) { |
| 4149 | if (!BTM_SecAddBleKey(p_data->add_ble_key.bd_addr, |
| 4150 | (tBTM_LE_KEY_VALUE*)&p_data->add_ble_key.blekey, |
| 4151 | p_data->add_ble_key.key_type)) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4152 | LOG(ERROR) << "BTA_DM: Error adding BLE Key for device " |
| 4153 | << p_data->add_ble_key.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4154 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4155 | } |
| 4156 | |
| 4157 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4158 | * |
| 4159 | * Function bta_dm_add_ble_device |
| 4160 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4161 | * Description This function adds an BLE device to an security database |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 4162 | * entry. |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4163 | * It is normally called during host startup to restore all |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 4164 | * required information stored in the NVRAM. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4165 | * |
| 4166 | * Parameters: |
| 4167 | * |
| 4168 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4169 | void bta_dm_add_ble_device(tBTA_DM_MSG* p_data) { |
| 4170 | if (!BTM_SecAddBleDevice(p_data->add_ble_device.bd_addr, NULL, |
| 4171 | p_data->add_ble_device.dev_type, |
| 4172 | p_data->add_ble_device.addr_type)) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4173 | LOG(ERROR) << "BTA_DM: Error adding BLE Device for device " |
| 4174 | << p_data->add_ble_device.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4175 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4176 | } |
| 4177 | |
| 4178 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4179 | * |
| 4180 | * Function bta_dm_add_ble_device |
| 4181 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4182 | * Description This function adds an BLE device to an security database |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 4183 | * entry. |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4184 | * It is normally called during host startup to restore all |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 4185 | * required information stored in the NVRAM. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4186 | * |
| 4187 | * Parameters: |
| 4188 | * |
| 4189 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4190 | void bta_dm_ble_passkey_reply(tBTA_DM_MSG* p_data) { |
| 4191 | if (p_data->pin_reply.accept) { |
| 4192 | BTM_BlePasskeyReply(p_data->ble_passkey_reply.bd_addr, BTM_SUCCESS, |
| 4193 | p_data->ble_passkey_reply.passkey); |
| 4194 | } else { |
| 4195 | BTM_BlePasskeyReply(p_data->ble_passkey_reply.bd_addr, BTM_NOT_AUTHORIZED, |
| 4196 | p_data->ble_passkey_reply.passkey); |
| 4197 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4198 | } |
| 4199 | |
| 4200 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4201 | * |
| 4202 | * Function bta_dm_ble_confirm_reply |
| 4203 | * |
| 4204 | * Description This is response to SM numeric comparison request submitted |
| 4205 | * to application. |
| 4206 | * |
| 4207 | * Parameters: |
| 4208 | * |
| 4209 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4210 | void bta_dm_ble_confirm_reply(tBTA_DM_MSG* p_data) { |
| 4211 | if (p_data->confirm.accept) { |
| 4212 | BTM_BleConfirmReply(p_data->confirm.bd_addr, BTM_SUCCESS); |
| 4213 | } else { |
| 4214 | BTM_BleConfirmReply(p_data->ble_passkey_reply.bd_addr, BTM_NOT_AUTHORIZED); |
| 4215 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4219 | * |
| 4220 | * Function bta_dm_security_grant |
| 4221 | * |
| 4222 | * Description This function grant SMP security request access. |
| 4223 | * |
| 4224 | * Parameters: |
| 4225 | * |
| 4226 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4227 | void bta_dm_security_grant(tBTA_DM_MSG* p_data) { |
| 4228 | BTM_SecurityGrant(p_data->ble_sec_grant.bd_addr, p_data->ble_sec_grant.res); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4229 | } |
| 4230 | |
| 4231 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4232 | * |
| 4233 | * Function bta_dm_ble_set_bg_conn_type |
| 4234 | * |
| 4235 | * Description This function set the BLE background connection type |
| 4236 | * |
| 4237 | * Parameters: |
| 4238 | * |
| 4239 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4240 | void bta_dm_ble_set_bg_conn_type(tBTA_DM_MSG* p_data) { |
Jakub Pawlowski | 83211b0 | 2016-12-07 11:25:15 -0800 | [diff] [blame] | 4241 | BTM_BleStartAutoConn(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4242 | } |
| 4243 | |
| 4244 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4245 | * |
| 4246 | * Function bta_dm_ble_set_conn_params |
| 4247 | * |
| 4248 | * Description This function set the preferred connection parameters. |
| 4249 | * |
| 4250 | * Parameters: |
| 4251 | * |
| 4252 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4253 | void bta_dm_ble_set_conn_params(tBTA_DM_MSG* p_data) { |
| 4254 | BTM_BleSetPrefConnParams(p_data->ble_set_conn_params.peer_bda, |
| 4255 | p_data->ble_set_conn_params.conn_int_min, |
| 4256 | p_data->ble_set_conn_params.conn_int_max, |
| 4257 | p_data->ble_set_conn_params.slave_latency, |
| 4258 | p_data->ble_set_conn_params.supervision_tout); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4262 | * |
| 4263 | * Function bta_dm_ble_set_conn_scan_params |
| 4264 | * |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4265 | * Description This function set the preferred connection scan parameters. |
| 4266 | * |
| 4267 | * Parameters: |
| 4268 | * |
| 4269 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4270 | void bta_dm_ble_set_conn_scan_params(tBTA_DM_MSG* p_data) { |
| 4271 | BTM_BleSetConnScanParams(p_data->ble_set_conn_scan_params.scan_int, |
| 4272 | p_data->ble_set_conn_scan_params.scan_window); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4273 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4274 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4275 | * |
| 4276 | * Function bta_dm_ble_update_conn_params |
| 4277 | * |
| 4278 | * Description This function update LE connection parameters. |
| 4279 | * |
| 4280 | * Parameters: |
| 4281 | * |
| 4282 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4283 | void bta_dm_ble_update_conn_params(tBTA_DM_MSG* p_data) { |
| 4284 | if (!L2CA_UpdateBleConnParams(p_data->ble_update_conn_params.bd_addr, |
| 4285 | p_data->ble_update_conn_params.min_int, |
| 4286 | p_data->ble_update_conn_params.max_int, |
| 4287 | p_data->ble_update_conn_params.latency, |
| 4288 | p_data->ble_update_conn_params.timeout)) { |
| 4289 | APPL_TRACE_ERROR("Update connection parameters failed!"); |
| 4290 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4291 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4292 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 4293 | #if (BLE_PRIVACY_SPT == TRUE) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4294 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4295 | * |
| 4296 | * Function bta_dm_ble_config_local_privacy |
| 4297 | * |
| 4298 | * Description This function set the local device LE privacy settings. |
| 4299 | * |
| 4300 | * Parameters: |
| 4301 | * |
| 4302 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4303 | void bta_dm_ble_config_local_privacy(tBTA_DM_MSG* p_data) { |
| 4304 | BTM_BleConfigPrivacy(p_data->ble_local_privacy.privacy_enable); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4305 | } |
| 4306 | #endif |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 4307 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 4308 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4309 | * |
| 4310 | * Function bta_dm_ble_observe |
| 4311 | * |
| 4312 | * Description This function set the preferred connection scan parameters. |
| 4313 | * |
| 4314 | * Parameters: |
| 4315 | * |
| 4316 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4317 | void bta_dm_ble_observe(tBTA_DM_MSG* p_data) { |
| 4318 | tBTM_STATUS status; |
| 4319 | if (p_data->ble_observe.start) { |
| 4320 | /*Save the callback to be called when a scan results are available */ |
| 4321 | bta_dm_search_cb.p_scan_cback = p_data->ble_observe.p_cback; |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame] | 4322 | status = BTM_BleObserve(true, p_data->ble_observe.duration, |
| 4323 | bta_dm_observe_results_cb, bta_dm_observe_cmpl_cb); |
| 4324 | if (status != BTM_CMD_STARTED) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4325 | tBTA_DM_SEARCH data; |
| 4326 | APPL_TRACE_WARNING(" %s BTM_BleObserve failed. status %d", __func__, |
| 4327 | status); |
| 4328 | data.inq_cmpl.num_resps = 0; |
| 4329 | if (bta_dm_search_cb.p_scan_cback) { |
| 4330 | bta_dm_search_cb.p_scan_cback(BTA_DM_INQ_CMPL_EVT, &data); |
| 4331 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 4332 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4333 | } else { |
| 4334 | bta_dm_search_cb.p_scan_cback = NULL; |
| 4335 | BTM_BleObserve(false, 0, NULL, NULL); |
| 4336 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 4337 | } |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 4338 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4339 | * |
| 4340 | * Function bta_dm_ble_set_adv_params |
| 4341 | * |
| 4342 | * Description This function set the adv parameters. |
| 4343 | * |
| 4344 | * Parameters: |
| 4345 | * |
| 4346 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4347 | void bta_dm_ble_set_adv_params(uint16_t adv_int_min, uint16_t adv_int_max, |
| 4348 | tBLE_BD_ADDR* p_dir_bda) { |
| 4349 | BTM_BleSetAdvParams(adv_int_min, adv_int_max, p_dir_bda, |
| 4350 | BTA_DM_BLE_ADV_CHNL_MAP); |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 4351 | } |
Andre Eisenbach | eeeac99 | 2013-11-08 10:23:52 -0800 | [diff] [blame] | 4352 | |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 4353 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4354 | * |
| 4355 | * Function bta_dm_ble_set_data_length |
| 4356 | * |
| 4357 | * Description This function set the maximum transmission packet size |
| 4358 | * |
| 4359 | * Parameters |
| 4360 | * |
| 4361 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4362 | void bta_dm_ble_set_data_length(tBTA_DM_MSG* p_data) { |
| 4363 | if (BTM_SetBleDataLength(p_data->ble_set_data_length.remote_bda, |
| 4364 | p_data->ble_set_data_length.tx_data_length) != |
| 4365 | BTM_SUCCESS) { |
| 4366 | APPL_TRACE_ERROR("%s failed", __func__); |
| 4367 | } |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 4368 | } |
| 4369 | |
| 4370 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4371 | * |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4372 | * Function bta_ble_enable_scan_cmpl |
| 4373 | * |
| 4374 | * Description ADV payload filtering enable / disable complete callback |
| 4375 | * |
| 4376 | * |
| 4377 | * Returns None |
| 4378 | * |
| 4379 | ******************************************************************************/ |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 4380 | static void bta_ble_energy_info_cmpl(tBTM_BLE_TX_TIME_MS tx_time, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4381 | tBTM_BLE_RX_TIME_MS rx_time, |
| 4382 | tBTM_BLE_IDLE_TIME_MS idle_time, |
| 4383 | tBTM_BLE_ENERGY_USED energy_used, |
| 4384 | tBTM_STATUS status) { |
| 4385 | tBTA_STATUS st = (status == BTM_SUCCESS) ? BTA_SUCCESS : BTA_FAILURE; |
| 4386 | tBTA_DM_CONTRL_STATE ctrl_state = 0; |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 4387 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4388 | if (BTA_SUCCESS == st) ctrl_state = bta_dm_pm_obtain_controller_state(); |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 4389 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4390 | if (bta_dm_cb.p_energy_info_cback) |
| 4391 | bta_dm_cb.p_energy_info_cback(tx_time, rx_time, idle_time, energy_used, |
| 4392 | ctrl_state, st); |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 4393 | } |
| 4394 | |
| 4395 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4396 | * |
| 4397 | * Function bta_dm_ble_get_energy_info |
| 4398 | * |
| 4399 | * Description This function obtains the energy info |
| 4400 | * |
| 4401 | * Parameters: |
| 4402 | * |
| 4403 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4404 | void bta_dm_ble_get_energy_info(tBTA_DM_MSG* p_data) { |
| 4405 | tBTM_STATUS btm_status = 0; |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 4406 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4407 | bta_dm_cb.p_energy_info_cback = p_data->ble_energy_info.p_energy_info_cback; |
| 4408 | btm_status = BTM_BleGetEnergyInfo(bta_ble_energy_info_cmpl); |
| 4409 | if (BTM_CMD_STARTED != btm_status) |
| 4410 | bta_ble_energy_info_cmpl(0, 0, 0, 0, btm_status); |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 4411 | } |
| 4412 | |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 4413 | #ifndef BTA_DM_GATT_CLOSE_DELAY_TOUT |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4414 | #define BTA_DM_GATT_CLOSE_DELAY_TOUT 1000 |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 4415 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4416 | |
| 4417 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4418 | * |
| 4419 | * Function bta_dm_gattc_register |
| 4420 | * |
| 4421 | * Description Register with GATTC in DM if BLE is needed. |
| 4422 | * |
| 4423 | * |
| 4424 | * Returns void |
| 4425 | * |
| 4426 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4427 | static void bta_dm_gattc_register(void) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4428 | if (bta_dm_search_cb.client_if == BTA_GATTS_INVALID_IF) { |
Jakub Pawlowski | 221e9bf | 2016-12-15 14:35:15 -0800 | [diff] [blame] | 4429 | BTA_GATTC_AppRegister(bta_dm_gattc_callback, |
| 4430 | base::Bind([](uint8_t client_id, uint8_t status) { |
| 4431 | if (status == BTA_GATT_OK) |
| 4432 | bta_dm_search_cb.client_if = client_id; |
| 4433 | else |
| 4434 | bta_dm_search_cb.client_if = BTA_GATTS_INVALID_IF; |
| 4435 | |
| 4436 | })); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4437 | } |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 4438 | } |
| 4439 | |
| 4440 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4441 | * |
| 4442 | * Function btm_dm_start_disc_gatt_services |
| 4443 | * |
| 4444 | * Description This function starts a GATT service search request. |
| 4445 | * |
| 4446 | * Parameters: |
| 4447 | * |
| 4448 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4449 | static void btm_dm_start_disc_gatt_services(uint16_t conn_id) { |
| 4450 | tBT_UUID* p_uuid = bta_dm_search_cb.p_srvc_uuid + bta_dm_search_cb.num_uuid - |
| 4451 | bta_dm_search_cb.uuid_to_search; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4452 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4453 | p_uuid = bta_dm_search_cb.p_srvc_uuid + bta_dm_search_cb.num_uuid - |
| 4454 | bta_dm_search_cb.uuid_to_search; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4455 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4456 | /* always search for all services */ |
| 4457 | BTA_GATTC_ServiceSearchRequest(conn_id, p_uuid); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4458 | } |
| 4459 | |
| 4460 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4461 | * |
| 4462 | * Function bta_dm_gatt_disc_result |
| 4463 | * |
| 4464 | * Description This function process the GATT service search result. |
| 4465 | * |
| 4466 | * Parameters: |
| 4467 | * |
| 4468 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4469 | static void bta_dm_gatt_disc_result(tBTA_GATT_ID service_id) { |
| 4470 | tBTA_DM_SEARCH result; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4471 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4472 | /* |
Andre Eisenbach | 1f5ec73 | 2017-04-13 14:49:36 -0700 | [diff] [blame] | 4473 | * This logic will not work for gatt case. We are checking against the |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4474 | * bluetooth profiles here |
Andre Eisenbach | 1f5ec73 | 2017-04-13 14:49:36 -0700 | [diff] [blame] | 4475 | * just copy the GATTID in raw data field and send it across. |
| 4476 | */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4477 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4478 | if (bta_dm_search_cb.ble_raw_used + sizeof(tBTA_GATT_ID) < |
| 4479 | bta_dm_search_cb.ble_raw_size) { |
| 4480 | APPL_TRACE_DEBUG( |
| 4481 | "ADDING BLE SERVICE uuid=0x%x, ble_ptr = 0x%x, ble_raw_used = 0x%x", |
| 4482 | service_id.uuid.uu.uuid16, bta_dm_search_cb.p_ble_rawdata, |
| 4483 | bta_dm_search_cb.ble_raw_used); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4484 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4485 | if (bta_dm_search_cb.p_ble_rawdata) { |
| 4486 | memcpy((bta_dm_search_cb.p_ble_rawdata + bta_dm_search_cb.ble_raw_used), |
| 4487 | &service_id, sizeof(service_id)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4488 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4489 | bta_dm_search_cb.ble_raw_used += sizeof(service_id); |
| 4490 | } else { |
| 4491 | APPL_TRACE_ERROR("p_ble_rawdata is NULL"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4492 | } |
| 4493 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4494 | } else { |
| 4495 | APPL_TRACE_ERROR( |
| 4496 | "%s out of room to accomodate more service ids ble_raw_size = %d " |
| 4497 | "ble_raw_used = %d", |
| 4498 | __func__, bta_dm_search_cb.ble_raw_size, bta_dm_search_cb.ble_raw_used); |
| 4499 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4500 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4501 | LOG_INFO(LOG_TAG, "%s service_id_uuid_len=%d ", __func__, |
| 4502 | service_id.uuid.len); |
| 4503 | if (bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE) { |
| 4504 | /* send result back to app now, one by one */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4505 | result.disc_ble_res.bd_addr = bta_dm_search_cb.peer_bdaddr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4506 | strlcpy((char*)result.disc_ble_res.bd_name, bta_dm_get_remname(), |
| 4507 | BD_NAME_LEN); |
| 4508 | memcpy(&result.disc_ble_res.service, &service_id.uuid, sizeof(tBT_UUID)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4509 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4510 | bta_dm_search_cb.p_search_cback(BTA_DM_DISC_BLE_RES_EVT, &result); |
| 4511 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4512 | } |
| 4513 | |
| 4514 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4515 | * |
| 4516 | * Function bta_dm_gatt_disc_complete |
| 4517 | * |
| 4518 | * Description This function process the GATT service search complete. |
| 4519 | * |
| 4520 | * Parameters: |
| 4521 | * |
| 4522 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4523 | static void bta_dm_gatt_disc_complete(uint16_t conn_id, |
| 4524 | tBTA_GATT_STATUS status) { |
| 4525 | APPL_TRACE_DEBUG("%s conn_id = %d", __func__, conn_id); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4526 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4527 | if (bta_dm_search_cb.uuid_to_search > 0) bta_dm_search_cb.uuid_to_search--; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4528 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4529 | if (status == BTA_GATT_OK && bta_dm_search_cb.uuid_to_search > 0) { |
| 4530 | btm_dm_start_disc_gatt_services(conn_id); |
| 4531 | } else { |
| 4532 | tBTA_DM_MSG* p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
| 4533 | |
| 4534 | bta_dm_search_cb.uuid_to_search = 0; |
| 4535 | |
| 4536 | /* no more services to be discovered */ |
| 4537 | p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT; |
| 4538 | p_msg->disc_result.result.disc_res.result = |
| 4539 | (status == BTA_GATT_OK) ? BTA_SUCCESS : BTA_FAILURE; |
| 4540 | APPL_TRACE_DEBUG("%s service found: 0x%08x", __func__, |
| 4541 | bta_dm_search_cb.services_found); |
| 4542 | p_msg->disc_result.result.disc_res.services = |
| 4543 | bta_dm_search_cb.services_found; |
| 4544 | p_msg->disc_result.result.disc_res.num_uuids = 0; |
| 4545 | p_msg->disc_result.result.disc_res.p_uuid_list = NULL; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4546 | p_msg->disc_result.result.disc_res.bd_addr = bta_dm_search_cb.peer_bdaddr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4547 | strlcpy((char*)p_msg->disc_result.result.disc_res.bd_name, |
| 4548 | bta_dm_get_remname(), BD_NAME_LEN); |
| 4549 | |
| 4550 | p_msg->disc_result.result.disc_res.device_type |= BT_DEVICE_TYPE_BLE; |
| 4551 | if (bta_dm_search_cb.ble_raw_used > 0) { |
| 4552 | p_msg->disc_result.result.disc_res.p_raw_data = |
| 4553 | (uint8_t*)osi_malloc(bta_dm_search_cb.ble_raw_used); |
| 4554 | |
| 4555 | memcpy(p_msg->disc_result.result.disc_res.p_raw_data, |
| 4556 | bta_dm_search_cb.p_ble_rawdata, bta_dm_search_cb.ble_raw_used); |
| 4557 | |
| 4558 | p_msg->disc_result.result.disc_res.raw_data_size = |
| 4559 | bta_dm_search_cb.ble_raw_used; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 4560 | } else { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4561 | p_msg->disc_result.result.disc_res.p_raw_data = NULL; |
| 4562 | bta_dm_search_cb.p_ble_rawdata = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4563 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4564 | |
| 4565 | bta_sys_sendmsg(p_msg); |
| 4566 | |
| 4567 | if (conn_id != BTA_GATT_INVALID_CONN_ID) { |
| 4568 | /* start a GATT channel close delay timer */ |
| 4569 | bta_sys_start_timer(bta_dm_search_cb.gatt_close_timer, |
| 4570 | BTA_DM_GATT_CLOSE_DELAY_TOUT, |
| 4571 | BTA_DM_DISC_CLOSE_TOUT_EVT, 0); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4572 | bta_dm_search_cb.pending_close_bda = bta_dm_search_cb.peer_bdaddr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4573 | } |
| 4574 | bta_dm_search_cb.gatt_disc_active = false; |
| 4575 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4576 | } |
| 4577 | |
| 4578 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4579 | * |
| 4580 | * Function bta_dm_close_gatt_conn |
| 4581 | * |
Jakub Pawlowski | 221e9bf | 2016-12-15 14:35:15 -0800 | [diff] [blame] | 4582 | * Description This function close the GATT connection after delay |
| 4583 | *timeout. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4584 | * |
| 4585 | * Parameters: |
| 4586 | * |
| 4587 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4588 | void bta_dm_close_gatt_conn(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 4589 | if (bta_dm_search_cb.conn_id != BTA_GATT_INVALID_CONN_ID) |
| 4590 | BTA_GATTC_Close(bta_dm_search_cb.conn_id); |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 4591 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4592 | bta_dm_search_cb.pending_close_bda = {.address = {0}}; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4593 | bta_dm_search_cb.conn_id = BTA_GATT_INVALID_CONN_ID; |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 4594 | } |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 4595 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4596 | * |
| 4597 | * Function btm_dm_start_gatt_discovery |
| 4598 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4599 | * Description This is GATT initiate the service search by open a GATT |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 4600 | * connection first. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4601 | * |
| 4602 | * Parameters: |
| 4603 | * |
| 4604 | ******************************************************************************/ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4605 | void btm_dm_start_gatt_discovery(const bt_bdaddr_t& bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4606 | bta_dm_search_cb.gatt_disc_active = true; |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 4607 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4608 | /* connection is already open */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4609 | if (bta_dm_search_cb.pending_close_bda == bd_addr && |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4610 | bta_dm_search_cb.conn_id != BTA_GATT_INVALID_CONN_ID) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4611 | bta_dm_search_cb.pending_close_bda = {.address = {0}}; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4612 | alarm_cancel(bta_dm_search_cb.gatt_close_timer); |
| 4613 | btm_dm_start_disc_gatt_services(bta_dm_search_cb.conn_id); |
Jakub Pawlowski | 16bb48b | 2017-05-25 09:09:12 -0700 | [diff] [blame] | 4614 | } else { |
| 4615 | if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE)) { |
| 4616 | BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, true, |
| 4617 | BTA_GATT_TRANSPORT_LE, true); |
| 4618 | } else { |
| 4619 | BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, true, |
| 4620 | BTA_GATT_TRANSPORT_LE, false); |
| 4621 | } |
| 4622 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4623 | } |
| 4624 | |
| 4625 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4626 | * |
| 4627 | * Function bta_dm_cancel_gatt_discovery |
| 4628 | * |
| 4629 | * Description This is GATT cancel the GATT service search. |
| 4630 | * |
| 4631 | * Parameters: |
| 4632 | * |
| 4633 | ******************************************************************************/ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4634 | static void bta_dm_cancel_gatt_discovery(const bt_bdaddr_t& bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4635 | if (bta_dm_search_cb.conn_id == BTA_GATT_INVALID_CONN_ID) { |
| 4636 | BTA_GATTC_CancelOpen(bta_dm_search_cb.client_if, bd_addr, true); |
| 4637 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4638 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4639 | bta_dm_gatt_disc_complete(bta_dm_search_cb.conn_id, |
| 4640 | (tBTA_GATT_STATUS)BTA_GATT_ERROR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4641 | } |
| 4642 | |
| 4643 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4644 | * |
| 4645 | * Function bta_dm_proc_open_evt |
| 4646 | * |
| 4647 | * Description process BTA_GATTC_OPEN_EVT in DM. |
| 4648 | * |
| 4649 | * Parameters: |
| 4650 | * |
| 4651 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4652 | void bta_dm_proc_open_evt(tBTA_GATTC_OPEN* p_data) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4653 | VLOG(1) << "DM Search state= " << bta_dm_search_cb.state |
| 4654 | << " search_cb.peer_dbaddr:" << bta_dm_search_cb.peer_bdaddr |
| 4655 | << " connected_bda=" << p_data->remote_bda.address; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4656 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4657 | APPL_TRACE_DEBUG("BTA_GATTC_OPEN_EVT conn_id = %d client_if=%d status = %d", |
| 4658 | p_data->conn_id, p_data->client_if, p_data->status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4659 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4660 | bta_dm_search_cb.conn_id = p_data->conn_id; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4661 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4662 | if (p_data->status == BTA_GATT_OK) { |
| 4663 | btm_dm_start_disc_gatt_services(p_data->conn_id); |
| 4664 | } else { |
| 4665 | bta_dm_gatt_disc_complete(BTA_GATT_INVALID_CONN_ID, p_data->status); |
| 4666 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4667 | } |
| 4668 | |
| 4669 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4670 | * |
| 4671 | * Function bta_dm_gattc_callback |
| 4672 | * |
| 4673 | * Description This is GATT client callback function used in DM. |
| 4674 | * |
| 4675 | * Parameters: |
| 4676 | * |
| 4677 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4678 | static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) { |
| 4679 | APPL_TRACE_DEBUG("bta_dm_gattc_callback event = %d", event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4680 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4681 | switch (event) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4682 | case BTA_GATTC_OPEN_EVT: |
| 4683 | bta_dm_proc_open_evt(&p_data->open); |
| 4684 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4685 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4686 | case BTA_GATTC_SEARCH_RES_EVT: |
| 4687 | bta_dm_gatt_disc_result(p_data->srvc_res.service_uuid); |
| 4688 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4689 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4690 | case BTA_GATTC_SEARCH_CMPL_EVT: |
| 4691 | if (bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE) |
| 4692 | bta_dm_gatt_disc_complete(p_data->search_cmpl.conn_id, |
| 4693 | p_data->search_cmpl.status); |
| 4694 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4695 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4696 | case BTA_GATTC_CLOSE_EVT: |
| 4697 | APPL_TRACE_DEBUG("BTA_GATTC_CLOSE_EVT reason = %d", p_data->close.reason); |
| 4698 | /* in case of disconnect before search is completed */ |
| 4699 | if ((bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE) && |
| 4700 | (bta_dm_search_cb.state != BTA_DM_SEARCH_ACTIVE) && |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4701 | p_data->close.remote_bda == bta_dm_search_cb.peer_bdaddr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4702 | bta_dm_gatt_disc_complete((uint16_t)BTA_GATT_INVALID_CONN_ID, |
| 4703 | (tBTA_GATT_STATUS)BTA_GATT_ERROR); |
| 4704 | } |
| 4705 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4706 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4707 | default: |
| 4708 | break; |
| 4709 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4710 | } |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 4711 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 4712 | #if (BLE_VND_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 4713 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4714 | * |
| 4715 | * Function bta_dm_ctrl_features_rd_cmpl_cback |
| 4716 | * |
| 4717 | * Description callback to handle controller feature read complete |
| 4718 | * |
| 4719 | * Parameters: |
| 4720 | * |
| 4721 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4722 | static void bta_dm_ctrl_features_rd_cmpl_cback(tBTM_STATUS result) { |
| 4723 | APPL_TRACE_DEBUG("%s status = %d ", __func__, result); |
| 4724 | if (result == BTM_SUCCESS) { |
| 4725 | if (bta_dm_cb.p_sec_cback) |
| 4726 | bta_dm_cb.p_sec_cback(BTA_DM_LE_FEATURES_READ, NULL); |
| 4727 | } else { |
| 4728 | APPL_TRACE_ERROR("%s Ctrl BLE feature read failed: status :%d", __func__, |
| 4729 | result); |
| 4730 | } |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 4731 | } |
Bernhard Rosenkränzer | 104e3f2 | 2014-11-12 21:53:08 +0100 | [diff] [blame] | 4732 | #endif /* BLE_VND_INCLUDED */ |