The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Jakub Pawlowski | 5b790fe | 2017-09-18 09:00:20 -0700 | [diff] [blame] | 3 | * Copyright 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 | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 55 | using bluetooth::Uuid; |
| 56 | |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 57 | 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] | 58 | uint16_t eir_len); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 59 | static void bta_dm_inq_cmpl_cb(void* p_result); |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 60 | static void bta_dm_service_search_remname_cback(const RawAddress& bd_addr, |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 61 | DEV_CLASS dc, BD_NAME bd_name); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 62 | static void bta_dm_remname_cback(tBTM_REMOTE_DEV_NAME* p_remote_name); |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 63 | static void bta_dm_find_services(const RawAddress& bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 64 | static void bta_dm_discover_next_device(void); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 65 | static void bta_dm_sdp_callback(uint16_t sdp_status); |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 66 | static uint8_t bta_dm_authorize_cback(const RawAddress& bd_addr, |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 67 | DEV_CLASS dev_class, BD_NAME bd_name, |
| 68 | uint8_t* service_name, uint8_t service_id, |
| 69 | bool is_originator); |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 70 | static uint8_t bta_dm_pin_cback(const RawAddress& bd_addr, DEV_CLASS dev_class, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 71 | BD_NAME bd_name, bool min_16_digit); |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 72 | static uint8_t bta_dm_new_link_key_cback(const RawAddress& bd_addr, |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 73 | DEV_CLASS dev_class, BD_NAME bd_name, |
| 74 | LINK_KEY key, uint8_t key_type); |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 75 | static uint8_t bta_dm_authentication_complete_cback(const RawAddress& bd_addr, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 76 | DEV_CLASS dev_class, |
| 77 | BD_NAME bd_name, |
| 78 | int result); |
Vishwath Mohan | 325abcf | 2017-11-08 22:45:47 -0800 | [diff] [blame^] | 79 | static void bta_dm_local_name_cback(void* p_name); |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 80 | static bool bta_dm_check_av(uint16_t event); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 81 | 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] | 82 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 83 | static void bta_dm_policy_cback(tBTA_SYS_CONN_STATUS status, uint8_t id, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 84 | uint8_t app_id, const RawAddress* peer_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 85 | |
| 86 | /* Extended Inquiry Response */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 87 | static uint8_t bta_dm_sp_cback(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data); |
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, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 98 | uint8_t app_id, const RawAddress* 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 | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 103 | static bool bta_dm_read_remote_device_name(const RawAddress& bd_addr, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 104 | tBT_TRANSPORT transport); |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 105 | static void bta_dm_discover_device(const RawAddress& 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 | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 110 | static uint8_t bta_dm_ble_smp_cback(tBTM_LE_EVT event, const RawAddress& 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 | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 115 | static void btm_dm_start_gatt_discovery(const RawAddress& bd_addr); |
| 116 | static void bta_dm_cancel_gatt_discovery(const RawAddress& 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 | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 149 | static void bta_dm_reset_sec_dev_pending(const RawAddress& remote_bd_addr); |
| 150 | static void bta_dm_remove_sec_dev_entry(const RawAddress& 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, |
Myles Watson | 2e8e9f4 | 2016-11-14 16:45:15 -0800 | [diff] [blame] | 239 | &bta_dm_sp_cback, |
Myles Watson | 2e8e9f4 | 2016-11-14 16:45:15 -0800 | [diff] [blame] | 240 | &bta_dm_ble_smp_cback, |
| 241 | &bta_dm_ble_id_key_cback}; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 242 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 243 | #define MAX_DISC_RAW_DATA_BUF (4096) |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 244 | 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] | 245 | |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 246 | extern DEV_CLASS local_device_default_class; |
| 247 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 248 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 249 | * |
| 250 | * Function bta_dm_enable |
| 251 | * |
| 252 | * Description Initialises the BT device manager |
| 253 | * |
| 254 | * |
| 255 | * Returns void |
| 256 | * |
| 257 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 258 | void bta_dm_enable(tBTA_DM_MSG* p_data) { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 259 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 260 | /* if already in use, return an error */ |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 261 | if (bta_dm_cb.is_bta_dm_active) { |
Myles Watson | 6ef9190 | 2017-10-03 12:35:59 -0700 | [diff] [blame] | 262 | tBTA_DM_SEC enable_event; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 263 | APPL_TRACE_WARNING("%s Device already started by another application", |
| 264 | __func__); |
Myles Watson | 6ef9190 | 2017-10-03 12:35:59 -0700 | [diff] [blame] | 265 | memset(&enable_event, 0, sizeof(tBTA_DM_SEC)); |
| 266 | enable_event.enable.status = BTA_FAILURE; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 267 | if (p_data->enable.p_sec_cback != NULL) |
Myles Watson | 6ef9190 | 2017-10-03 12:35:59 -0700 | [diff] [blame] | 268 | p_data->enable.p_sec_cback(BTA_DM_ENABLE_EVT, &enable_event); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 269 | return; |
| 270 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 271 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 272 | /* first, register our callback to SYS HW manager */ |
| 273 | 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] | 274 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 275 | /* make sure security callback is saved - if no callback, do not erase the |
| 276 | previous one, |
| 277 | it could be an error recovery mechanism */ |
| 278 | if (p_data->enable.p_sec_cback != NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 279 | bta_dm_cb.p_sec_cback = p_data->enable.p_sec_cback; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 280 | /* notify BTA DM is now active */ |
| 281 | bta_dm_cb.is_bta_dm_active = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 282 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 283 | /* send a message to BTA SYS */ |
| 284 | tBTA_SYS_HW_MSG* sys_enable_event = |
| 285 | (tBTA_SYS_HW_MSG*)osi_malloc(sizeof(tBTA_SYS_HW_MSG)); |
| 286 | sys_enable_event->hdr.event = BTA_SYS_API_ENABLE_EVT; |
| 287 | sys_enable_event->hw_module = BTA_SYS_HW_BLUETOOTH; |
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 | bta_sys_sendmsg(sys_enable_event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 290 | } |
| 291 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 292 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 293 | * |
| 294 | * Function bta_dm_init_cb |
| 295 | * |
| 296 | * Description Initializes the bta_dm_cb control block |
| 297 | * |
| 298 | * |
| 299 | * Returns void |
| 300 | * |
| 301 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 302 | void bta_dm_init_cb(void) { |
| 303 | memset(&bta_dm_cb, 0, sizeof(bta_dm_cb)); |
| 304 | bta_dm_cb.disable_timer = alarm_new("bta_dm.disable_timer"); |
| 305 | bta_dm_cb.switch_delay_timer = alarm_new("bta_dm.switch_delay_timer"); |
| 306 | for (size_t i = 0; i < BTA_DM_NUM_PM_TIMER; i++) { |
| 307 | for (size_t j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++) { |
| 308 | 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] | 309 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 310 | } |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 314 | * |
| 315 | * Function bta_dm_deinit_cb |
| 316 | * |
| 317 | * Description De-initializes the bta_dm_cb control block |
| 318 | * |
| 319 | * |
| 320 | * Returns void |
| 321 | * |
| 322 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 323 | void bta_dm_deinit_cb(void) { |
| 324 | /* |
| 325 | * TODO: Should alarm_free() the bta_dm_cb timers during graceful |
| 326 | * shutdown. |
| 327 | */ |
| 328 | alarm_free(bta_dm_cb.disable_timer); |
| 329 | alarm_free(bta_dm_cb.switch_delay_timer); |
| 330 | for (size_t i = 0; i < BTA_DM_NUM_PM_TIMER; i++) { |
| 331 | for (size_t j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++) { |
| 332 | alarm_free(bta_dm_cb.pm_timer[i].timer[j]); |
Srinu Jella | 5ba7922 | 2016-06-08 17:31:41 +0530 | [diff] [blame] | 333 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 334 | } |
| 335 | memset(&bta_dm_cb, 0, sizeof(bta_dm_cb)); |
Srinu Jella | 5ba7922 | 2016-06-08 17:31:41 +0530 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 339 | * |
| 340 | * Function bta_dm_sys_hw_cback |
| 341 | * |
| 342 | * Description callback register to SYS to get HW status updates |
| 343 | * |
| 344 | * |
| 345 | * Returns void |
| 346 | * |
| 347 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 348 | static void bta_dm_sys_hw_cback(tBTA_SYS_HW_EVT status) { |
| 349 | DEV_CLASS dev_class; |
| 350 | tBTA_DM_SEC_CBACK* temp_cback; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 351 | uint8_t key_mask = 0; |
| 352 | BT_OCTET16 er; |
| 353 | tBTA_BLE_LOCAL_ID_KEYS id_key; |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 354 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 355 | APPL_TRACE_DEBUG("%s with event: %i", __func__, status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 356 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 357 | /* On H/W error evt, report to the registered DM application callback */ |
| 358 | if (status == BTA_SYS_HW_ERROR_EVT) { |
| 359 | if (bta_dm_cb.p_sec_cback != NULL) |
| 360 | bta_dm_cb.p_sec_cback(BTA_DM_HW_ERROR_EVT, NULL); |
| 361 | return; |
| 362 | } |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 363 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 364 | if (status == BTA_SYS_HW_OFF_EVT) { |
| 365 | if (bta_dm_cb.p_sec_cback != NULL) |
| 366 | 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] | 367 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 368 | /* reinitialize the control block */ |
| 369 | bta_dm_deinit_cb(); |
Srinu Jella | 5ba7922 | 2016-06-08 17:31:41 +0530 | [diff] [blame] | 370 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 371 | /* hw is ready, go on with BTA DM initialization */ |
| 372 | alarm_free(bta_dm_search_cb.search_timer); |
| 373 | alarm_free(bta_dm_search_cb.gatt_close_timer); |
| 374 | 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] | 375 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 376 | /* unregister from SYS */ |
| 377 | bta_sys_hw_unregister(BTA_SYS_HW_BLUETOOTH); |
| 378 | /* notify BTA DM is now unactive */ |
| 379 | bta_dm_cb.is_bta_dm_active = false; |
| 380 | } else if (status == BTA_SYS_HW_ON_EVT) { |
| 381 | /* 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] | 382 | * a H/W error. |
| 383 | * We need to revisit when this platform has more than one BLuetooth H/W |
| 384 | * chip |
| 385 | */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 386 | // bta_sys_hw_unregister( BTA_SYS_HW_BLUETOOTH); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 387 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 388 | /* save security callback */ |
| 389 | temp_cback = bta_dm_cb.p_sec_cback; |
| 390 | /* make sure the control block is properly initialized */ |
| 391 | bta_dm_init_cb(); |
| 392 | /* and retrieve the callback */ |
| 393 | bta_dm_cb.p_sec_cback = temp_cback; |
| 394 | bta_dm_cb.is_bta_dm_active = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 395 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 396 | /* hw is ready, go on with BTA DM initialization */ |
| 397 | alarm_free(bta_dm_search_cb.search_timer); |
| 398 | alarm_free(bta_dm_search_cb.gatt_close_timer); |
| 399 | memset(&bta_dm_search_cb, 0, sizeof(bta_dm_search_cb)); |
| 400 | /* |
| 401 | * TODO: Should alarm_free() the bta_dm_search_cb timers during |
| 402 | * graceful shutdown. |
| 403 | */ |
| 404 | bta_dm_search_cb.search_timer = alarm_new("bta_dm_search.search_timer"); |
| 405 | bta_dm_search_cb.gatt_close_timer = |
| 406 | alarm_new("bta_dm_search.gatt_close_timer"); |
Pavlin Radoslavov | 78bcff7 | 2015-12-04 17:36:34 -0800 | [diff] [blame] | 407 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 408 | memset(&bta_dm_conn_srvcs, 0, sizeof(bta_dm_conn_srvcs)); |
| 409 | 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] | 410 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 411 | memcpy(dev_class, p_bta_dm_cfg->dev_class, sizeof(dev_class)); |
| 412 | BTM_SetDeviceClass(dev_class); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 413 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 414 | /* load BLE local information: ID keys, ER if available */ |
| 415 | 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] | 416 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 417 | if (key_mask & BTA_BLE_LOCAL_KEY_TYPE_ER) { |
| 418 | BTM_BleLoadLocalKeys(BTA_BLE_LOCAL_KEY_TYPE_ER, |
| 419 | (tBTM_BLE_LOCAL_KEYS*)&er); |
| 420 | } |
| 421 | if (key_mask & BTA_BLE_LOCAL_KEY_TYPE_ID) { |
| 422 | BTM_BleLoadLocalKeys(BTA_BLE_LOCAL_KEY_TYPE_ID, |
| 423 | (tBTM_BLE_LOCAL_KEYS*)&id_key); |
| 424 | } |
Jakub Pawlowski | e9ef00c | 2017-09-25 17:41:21 -0700 | [diff] [blame] | 425 | bta_dm_search_cb.conn_id = GATT_INVALID_CONN_ID; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 426 | |
Myles Watson | 6ef9190 | 2017-10-03 12:35:59 -0700 | [diff] [blame] | 427 | BTM_SecRegister(&bta_security); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 428 | BTM_SetDefaultLinkSuperTout(p_bta_dm_cfg->link_timeout); |
| 429 | BTM_WritePageTimeout(p_bta_dm_cfg->page_timeout); |
| 430 | bta_dm_cb.cur_policy = p_bta_dm_cfg->policy_settings; |
| 431 | BTM_SetDefaultLinkPolicy(bta_dm_cb.cur_policy); |
| 432 | BTM_RegBusyLevelNotif(bta_dm_bl_change_cback, NULL, |
| 433 | BTM_BL_UPDATE_MASK | BTM_BL_ROLE_CHG_MASK); |
Satya Calloji | 3f24f46 | 2014-09-16 22:44:43 -0700 | [diff] [blame] | 434 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 435 | #if (BLE_VND_INCLUDED == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 436 | BTM_BleReadControllerFeatures(bta_dm_ctrl_features_rd_cmpl_cback); |
Jakub Pawlowski | 2255250 | 2016-12-22 03:13:00 -0800 | [diff] [blame] | 437 | #else |
| 438 | /* If VSC multi adv commands are available, advertising will be initialized |
| 439 | * when capabilities are read. If they are not avaliable, initialize |
| 440 | * advertising here */ |
| 441 | btm_ble_adv_init(); |
Satya Calloji | 3f24f46 | 2014-09-16 22:44:43 -0700 | [diff] [blame] | 442 | #endif |
| 443 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 444 | /* Earlier, we used to invoke BTM_ReadLocalAddr which was just copying the |
| 445 | bd_addr |
| 446 | from the control block and invoking the callback which was sending the |
| 447 | DM_ENABLE_EVT. |
| 448 | But then we have a few HCI commands being invoked above which were still |
| 449 | in progress |
| 450 | when the ENABLE_EVT was sent. So modified this to fetch the local name |
| 451 | which forces |
| 452 | the DM_ENABLE_EVT to be sent only after all the init steps are complete |
| 453 | */ |
| 454 | BTM_ReadLocalDeviceNameFromController( |
| 455 | (tBTM_CMPL_CB*)bta_dm_local_name_cback); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 456 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 457 | 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] | 458 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 459 | /* initialize bluetooth low power manager */ |
| 460 | bta_dm_init_pm(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 461 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 462 | 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] | 463 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 464 | bta_dm_gattc_register(); |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 465 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 466 | } else |
| 467 | APPL_TRACE_DEBUG(" --- ignored event"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 468 | } |
| 469 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 470 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 471 | * |
| 472 | * Function bta_dm_disable |
| 473 | * |
| 474 | * Description Disables the BT device manager |
| 475 | * |
| 476 | * |
| 477 | * Returns void |
| 478 | * |
| 479 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 480 | void bta_dm_disable(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 481 | /* Set l2cap idle timeout to 0 (so BTE immediately disconnects ACL link after |
| 482 | * last channel is closed) */ |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame] | 483 | L2CA_SetIdleTimeoutByBdAddr(RawAddress::kAny, 0, BT_TRANSPORT_BR_EDR); |
| 484 | L2CA_SetIdleTimeoutByBdAddr(RawAddress::kAny, 0, BT_TRANSPORT_LE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 485 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 486 | /* disable all active subsystems */ |
| 487 | bta_sys_disable(BTA_SYS_HW_BLUETOOTH); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 488 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 489 | BTM_SetDiscoverability(BTM_NON_DISCOVERABLE, 0, 0); |
| 490 | BTM_SetConnectability(BTM_NON_CONNECTABLE, 0, 0); |
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 | bta_dm_disable_pm(); |
| 493 | bta_dm_disable_search_and_disc(); |
| 494 | bta_dm_cb.disabling = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 495 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 496 | BTM_BleClearBgConnDev(); |
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 | if (BTM_GetNumAclLinks() == 0) { |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 499 | #if (BTA_DISABLE_DELAY > 0) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 500 | /* If BTA_DISABLE_DELAY is defined and greater than zero, then delay the |
| 501 | * shutdown by |
| 502 | * BTA_DISABLE_DELAY milliseconds |
| 503 | */ |
| 504 | APPL_TRACE_WARNING("%s BTA_DISABLE_DELAY set to %d ms", __func__, |
| 505 | BTA_DISABLE_DELAY); |
Jakub Pawlowski | be8bbd7 | 2017-09-08 11:26:25 -0700 | [diff] [blame] | 506 | alarm_set_on_mloop(bta_dm_cb.disable_timer, BTA_DISABLE_DELAY, |
| 507 | bta_dm_disable_conn_down_timer_cback, NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 508 | #else |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 509 | bta_dm_disable_conn_down_timer_cback(NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 510 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 511 | } else { |
Jakub Pawlowski | be8bbd7 | 2017-09-08 11:26:25 -0700 | [diff] [blame] | 512 | alarm_set_on_mloop(bta_dm_cb.disable_timer, BTA_DM_DISABLE_TIMER_MS, |
| 513 | bta_dm_disable_timer_cback, UINT_TO_PTR(0)); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 514 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 518 | * |
| 519 | * Function bta_dm_disable_timer_cback |
| 520 | * |
| 521 | * Description Called if the disable timer expires |
| 522 | * Used to close ACL connections which are still active |
| 523 | * |
| 524 | * |
| 525 | * |
| 526 | * Returns void |
| 527 | * |
| 528 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 529 | static void bta_dm_disable_timer_cback(void* data) { |
| 530 | uint8_t i; |
| 531 | tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; |
| 532 | bool trigger_disc = false; |
| 533 | uint32_t param = PTR_TO_UINT(data); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 534 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 535 | APPL_TRACE_EVENT("%s trial %u", __func__, param); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 536 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 537 | if (BTM_GetNumAclLinks() && (param == 0)) { |
| 538 | for (i = 0; i < bta_dm_cb.device_list.count; i++) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 539 | transport = bta_dm_cb.device_list.peer_device[i].transport; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 540 | btm_remove_acl(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, |
| 541 | transport); |
| 542 | trigger_disc = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 543 | } |
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 | /* Retrigger disable timer in case ACL disconnect failed, DISABLE_EVT still |
| 546 | need |
| 547 | to be sent out to avoid jave layer disable timeout */ |
| 548 | if (trigger_disc) { |
Jakub Pawlowski | be8bbd7 | 2017-09-08 11:26:25 -0700 | [diff] [blame] | 549 | alarm_set_on_mloop(bta_dm_cb.disable_timer, |
| 550 | BTA_DM_DISABLE_TIMER_RETRIAL_MS, |
| 551 | bta_dm_disable_timer_cback, UINT_TO_PTR(1)); |
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 | } else { |
| 554 | bta_dm_cb.disabling = false; |
| 555 | |
| 556 | bta_sys_remove_uuid(UUID_SERVCLASS_PNP_INFORMATION); |
| 557 | bta_dm_cb.p_sec_cback(BTA_DM_DISABLE_EVT, NULL); |
| 558 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 559 | } |
| 560 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 561 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 562 | * |
| 563 | * Function bta_dm_set_dev_name |
| 564 | * |
| 565 | * Description Sets local device name |
| 566 | * |
| 567 | * |
| 568 | * Returns void |
| 569 | * |
| 570 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 571 | void bta_dm_set_dev_name(tBTA_DM_MSG* p_data) { |
| 572 | BTM_SetLocalDeviceName((char*)p_data->set_name.name); |
| 573 | 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] | 574 | } |
| 575 | |
| 576 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 577 | * |
| 578 | * Function bta_dm_set_visibility |
| 579 | * |
| 580 | * Description Sets discoverability, connectability and pairability |
| 581 | * |
| 582 | * |
| 583 | * Returns void |
| 584 | * |
| 585 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 586 | void bta_dm_set_visibility(tBTA_DM_MSG* p_data) { |
| 587 | uint16_t window, interval; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 588 | uint16_t le_disc_mode = BTM_BleReadDiscoverability(); |
| 589 | uint16_t le_conn_mode = BTM_BleReadConnectability(); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 590 | uint16_t disc_mode = BTM_ReadDiscoverability(&window, &interval); |
| 591 | uint16_t conn_mode = BTM_ReadConnectability(&window, &interval); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 592 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 593 | /* set modes for Discoverability and connectability if not ignore */ |
| 594 | 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] | 595 | if ((p_data->set_visibility.disc_mode & BTA_DM_LE_IGNORE) == |
| 596 | BTA_DM_LE_IGNORE) |
| 597 | p_data->set_visibility.disc_mode = |
| 598 | ((p_data->set_visibility.disc_mode & ~BTA_DM_LE_IGNORE) | |
| 599 | le_disc_mode); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 600 | if ((p_data->set_visibility.disc_mode & BTA_DM_IGNORE) == BTA_DM_IGNORE) |
| 601 | p_data->set_visibility.disc_mode = |
| 602 | ((p_data->set_visibility.disc_mode & ~BTA_DM_IGNORE) | disc_mode); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 603 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 604 | BTM_SetDiscoverability(p_data->set_visibility.disc_mode, |
| 605 | bta_dm_cb.inquiry_scan_window, |
| 606 | bta_dm_cb.inquiry_scan_interval); |
| 607 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 608 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 609 | 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] | 610 | if ((p_data->set_visibility.conn_mode & BTA_DM_LE_IGNORE) == |
| 611 | BTA_DM_LE_IGNORE) |
| 612 | p_data->set_visibility.conn_mode = |
| 613 | ((p_data->set_visibility.conn_mode & ~BTA_DM_LE_IGNORE) | |
| 614 | le_conn_mode); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 615 | if ((p_data->set_visibility.conn_mode & BTA_DM_IGNORE) == BTA_DM_IGNORE) |
| 616 | p_data->set_visibility.conn_mode = |
| 617 | ((p_data->set_visibility.conn_mode & ~BTA_DM_IGNORE) | conn_mode); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 618 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 619 | BTM_SetConnectability(p_data->set_visibility.conn_mode, |
| 620 | bta_dm_cb.page_scan_window, |
| 621 | bta_dm_cb.page_scan_interval); |
| 622 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 623 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 624 | /* Send False or True if not ignore */ |
| 625 | if (p_data->set_visibility.pair_mode != BTA_DM_IGNORE) { |
| 626 | if (p_data->set_visibility.pair_mode == BTA_DM_NON_PAIRABLE) |
| 627 | bta_dm_cb.disable_pair_mode = true; |
| 628 | else |
| 629 | bta_dm_cb.disable_pair_mode = false; |
| 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.conn_paired_only != BTA_DM_IGNORE) { |
| 634 | if (p_data->set_visibility.conn_paired_only == BTA_DM_CONN_ALL) |
| 635 | bta_dm_cb.conn_paired_only = false; |
| 636 | else |
| 637 | bta_dm_cb.conn_paired_only = true; |
| 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 | /* Change mode if either mode is not ignore */ |
| 641 | if (p_data->set_visibility.pair_mode != BTA_DM_IGNORE || |
| 642 | p_data->set_visibility.conn_paired_only != BTA_DM_IGNORE) |
| 643 | BTM_SetPairableMode((bool)(!(bta_dm_cb.disable_pair_mode)), |
| 644 | bta_dm_cb.conn_paired_only); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 645 | } |
| 646 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 647 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 648 | * |
| 649 | * Function bta_dm_process_remove_device |
| 650 | * |
| 651 | * Description Removes device, Disconnects ACL link if required. |
| 652 | *** |
| 653 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 654 | void bta_dm_process_remove_device(const RawAddress& bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 655 | /* need to remove all pending background connection before unpair */ |
| 656 | BTA_GATTC_CancelOpen(0, bd_addr, false); |
Zhihai Xu | bd68d68 | 2013-11-15 17:55:46 -0800 | [diff] [blame] | 657 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 658 | BTM_SecDeleteDevice(bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 659 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 660 | /* remove all cached GATT information */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 661 | BTA_GATTC_Refresh(bd_addr); |
Satya Calloji | 6fc9526 | 2015-04-21 16:34:54 -0700 | [diff] [blame] | 662 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 663 | if (bta_dm_cb.p_sec_cback) { |
| 664 | tBTA_DM_SEC sec_event; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 665 | sec_event.link_down.bd_addr = bd_addr; |
| 666 | ; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 667 | /* No connection, set status to success (acl disc code not valid) */ |
| 668 | sec_event.link_down.status = HCI_SUCCESS; |
| 669 | bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &sec_event); |
| 670 | } |
Satya Calloji | 6fc9526 | 2015-04-21 16:34:54 -0700 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 674 | * |
| 675 | * Function bta_dm_remove_device |
| 676 | * |
| 677 | * Description Removes device, disconnects ACL link if required. |
| 678 | *** |
| 679 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 680 | void bta_dm_remove_device(tBTA_DM_MSG* p_data) { |
| 681 | tBTA_DM_API_REMOVE_DEVICE* p_dev = &p_data->remove_dev; |
| 682 | bool continue_delete_other_dev = false; |
| 683 | if (p_dev == NULL) return; |
Satya Calloji | 6fc9526 | 2015-04-21 16:34:54 -0700 | [diff] [blame] | 684 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 685 | RawAddress other_address = p_dev->bd_addr; |
Satya Calloji | 6fc9526 | 2015-04-21 16:34:54 -0700 | [diff] [blame] | 686 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 687 | /* If ACL exists for the device in the remove_bond message*/ |
| 688 | bool continue_delete_dev = false; |
| 689 | uint8_t other_transport = BT_TRANSPORT_INVALID; |
Satya Calloji | 6fc9526 | 2015-04-21 16:34:54 -0700 | [diff] [blame] | 690 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 691 | if (BTM_IsAclConnectionUp(p_dev->bd_addr, BT_TRANSPORT_LE) || |
| 692 | BTM_IsAclConnectionUp(p_dev->bd_addr, BT_TRANSPORT_BR_EDR)) { |
| 693 | APPL_TRACE_DEBUG("%s: ACL Up count %d", __func__, |
| 694 | bta_dm_cb.device_list.count); |
| 695 | continue_delete_dev = false; |
Satya Calloji | 6fc9526 | 2015-04-21 16:34:54 -0700 | [diff] [blame] | 696 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 697 | /* Take the link down first, and mark the device for removal when |
| 698 | * disconnected */ |
| 699 | for (int i = 0; i < bta_dm_cb.device_list.count; i++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 700 | 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] | 701 | uint8_t transport = BT_TRANSPORT_BR_EDR; |
Scott James Remnant | dd339ab | 2015-11-19 15:27:41 -0800 | [diff] [blame] | 702 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 703 | transport = bta_dm_cb.device_list.peer_device[i].transport; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 704 | bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_UNPAIRING; |
| 705 | btm_remove_acl(p_dev->bd_addr, transport); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 706 | APPL_TRACE_DEBUG("%s:transport = %d", __func__, |
| 707 | bta_dm_cb.device_list.peer_device[i].transport); |
Satya Calloji | 6fc9526 | 2015-04-21 16:34:54 -0700 | [diff] [blame] | 708 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 709 | /* save the other transport to check if device is connected on |
| 710 | * other_transport */ |
| 711 | if (bta_dm_cb.device_list.peer_device[i].transport == BT_TRANSPORT_LE) |
| 712 | other_transport = BT_TRANSPORT_BR_EDR; |
| 713 | else |
| 714 | other_transport = BT_TRANSPORT_LE; |
Scott James Remnant | dd339ab | 2015-11-19 15:27:41 -0800 | [diff] [blame] | 715 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 716 | break; |
| 717 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 718 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 719 | } else { |
| 720 | continue_delete_dev = true; |
| 721 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 722 | // If it is DUMO device and device is paired as different address, unpair that |
| 723 | // device |
| 724 | // if different address |
| 725 | if ((other_transport && |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 726 | (BTM_ReadConnectedTransportAddress(&other_address, other_transport))) || |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 727 | (!other_transport && |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 728 | (BTM_ReadConnectedTransportAddress(&other_address, |
| 729 | BT_TRANSPORT_BR_EDR) || |
| 730 | BTM_ReadConnectedTransportAddress(&other_address, BT_TRANSPORT_LE)))) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 731 | continue_delete_other_dev = false; |
| 732 | /* Take the link down first, and mark the device for removal when |
| 733 | * disconnected */ |
| 734 | for (int i = 0; i < bta_dm_cb.device_list.count; i++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 735 | 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] | 736 | bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_UNPAIRING; |
| 737 | btm_remove_acl(other_address, |
| 738 | bta_dm_cb.device_list.peer_device[i].transport); |
| 739 | break; |
| 740 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 741 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 742 | } else { |
| 743 | APPL_TRACE_DEBUG("%s: continue to delete the other dev ", __func__); |
| 744 | continue_delete_other_dev = true; |
| 745 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 746 | /* Delete the device mentioned in the msg */ |
| 747 | 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] | 748 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 749 | /* Delete the other paired device too */ |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame] | 750 | if (continue_delete_other_dev && !other_address.IsEmpty()) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 751 | bta_dm_process_remove_device(other_address); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 755 | * |
| 756 | * Function bta_dm_add_device |
| 757 | * |
| 758 | * Description This function adds a Link Key to an security database entry. |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 759 | * It is normally called during host startup to restore all |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 760 | * required information stored in the NVRAM. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 761 | *** |
| 762 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 763 | void bta_dm_add_device(tBTA_DM_MSG* p_data) { |
| 764 | tBTA_DM_API_ADD_DEVICE* p_dev = &p_data->add_dev; |
| 765 | uint8_t* p_dc = NULL; |
| 766 | uint8_t* p_lc = NULL; |
| 767 | uint32_t trusted_services_mask[BTM_SEC_SERVICE_ARRAY_SIZE]; |
| 768 | uint8_t index = 0; |
| 769 | uint8_t btm_mask_index = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 770 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 771 | memset(trusted_services_mask, 0, sizeof(trusted_services_mask)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 772 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 773 | /* If not all zeros, the device class has been specified */ |
| 774 | 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] | 775 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 776 | 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] | 777 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 778 | if (p_dev->is_trusted) { |
| 779 | /* covert BTA service mask to BTM mask */ |
| 780 | while (p_dev->tm && (index < BTA_MAX_SERVICE_ID)) { |
| 781 | if (p_dev->tm & (uint32_t)(1 << index)) { |
| 782 | btm_mask_index = |
| 783 | bta_service_id_to_btm_srv_id_lkup_tbl[index] / BTM_SEC_ARRAY_BITS; |
| 784 | trusted_services_mask[btm_mask_index] |= |
| 785 | (uint32_t)(1 << (bta_service_id_to_btm_srv_id_lkup_tbl[index] - |
| 786 | (uint32_t)(btm_mask_index * 32))); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 787 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 788 | p_dev->tm &= (uint32_t)(~(1 << index)); |
| 789 | } |
| 790 | index++; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 791 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 792 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 793 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 794 | if (!BTM_SecAddDevice(p_dev->bd_addr, p_dc, p_dev->bd_name, p_dev->features, |
| 795 | trusted_services_mask, p_lc, p_dev->key_type, |
| 796 | p_dev->io_cap, p_dev->pin_length)) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 797 | LOG(ERROR) << "BTA_DM: Error adding device " << p_dev->bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 798 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 802 | * |
| 803 | * Function bta_dm_close_acl |
| 804 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 805 | * Description This function forces to close the connection to a remote |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 806 | * device and optionaly remove the device from security |
| 807 | * database if required. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 808 | *** |
| 809 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 810 | void bta_dm_close_acl(tBTA_DM_MSG* p_data) { |
| 811 | tBTA_DM_API_REMOVE_ACL* p_remove_acl = &p_data->remove_acl; |
| 812 | uint8_t index; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 813 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 814 | APPL_TRACE_DEBUG("bta_dm_close_acl"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 815 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 816 | if (BTM_IsAclConnectionUp(p_remove_acl->bd_addr, p_remove_acl->transport)) { |
| 817 | for (index = 0; index < bta_dm_cb.device_list.count; index++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 818 | if (bta_dm_cb.device_list.peer_device[index].peer_bdaddr == |
| 819 | p_remove_acl->bd_addr) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 820 | break; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 821 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 822 | if (index != bta_dm_cb.device_list.count) { |
| 823 | if (p_remove_acl->remove_dev) |
| 824 | bta_dm_cb.device_list.peer_device[index].remove_dev_pending = true; |
| 825 | } else { |
| 826 | APPL_TRACE_ERROR("unknown device, remove ACL failed"); |
| 827 | } |
| 828 | /* Disconnect the ACL link */ |
| 829 | btm_remove_acl(p_remove_acl->bd_addr, p_remove_acl->transport); |
| 830 | } |
| 831 | /* if to remove the device from security database ? do it now */ |
| 832 | else if (p_remove_acl->remove_dev) { |
| 833 | if (!BTM_SecDeleteDevice(p_remove_acl->bd_addr)) { |
| 834 | APPL_TRACE_ERROR("delete device from security database failed."); |
| 835 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 836 | /* need to remove all pending background connection if any */ |
| 837 | BTA_GATTC_CancelOpen(0, p_remove_acl->bd_addr, false); |
| 838 | /* remove all cached GATT information */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 839 | BTA_GATTC_Refresh(p_remove_acl->bd_addr); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 840 | } |
| 841 | /* otherwise, no action needed */ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 842 | } |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 843 | |
| 844 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 845 | * |
| 846 | * Function bta_dm_remove_all_acl |
| 847 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 848 | * Description This function forces to close all the ACL links specified by |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 849 | * link type |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 850 | *** |
| 851 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 852 | void bta_dm_remove_all_acl(tBTA_DM_MSG* p_data) { |
| 853 | const tBTA_DM_LINK_TYPE link_type = p_data->remove_all_acl.link_type; |
| 854 | tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 855 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 856 | APPL_TRACE_DEBUG("%s link type = %d", __func__, link_type); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 857 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 858 | 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] | 859 | transport = bta_dm_cb.device_list.peer_device[i].transport; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 860 | if ((link_type == BTA_DM_LINK_TYPE_ALL) || |
| 861 | ((link_type == BTA_DM_LINK_TYPE_LE) && |
| 862 | (transport == BT_TRANSPORT_LE)) || |
| 863 | ((link_type == BTA_DM_LINK_TYPE_BR_EDR) && |
| 864 | (transport == BT_TRANSPORT_BR_EDR))) { |
| 865 | /* Disconnect the ACL link */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 866 | btm_remove_acl(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, |
| 867 | transport); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 868 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 869 | } |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 872 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 873 | * |
| 874 | * Function bta_dm_bond |
| 875 | * |
| 876 | * Description Bonds with peer device |
| 877 | * |
| 878 | * |
| 879 | * Returns void |
| 880 | * |
| 881 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 882 | void bta_dm_bond(tBTA_DM_MSG* p_data) { |
| 883 | tBTM_STATUS status; |
| 884 | tBTA_DM_SEC sec_event; |
| 885 | char* p_name; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 886 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 887 | if (p_data->bond.transport == BTA_TRANSPORT_UNKNOWN) |
| 888 | status = BTM_SecBond(p_data->bond.bd_addr, 0, NULL, 0); |
| 889 | else |
| 890 | status = BTM_SecBondByTransport(p_data->bond.bd_addr, |
| 891 | p_data->bond.transport, 0, NULL, 0); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 892 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 893 | if (bta_dm_cb.p_sec_cback && (status != BTM_CMD_STARTED)) { |
| 894 | memset(&sec_event, 0, sizeof(tBTA_DM_SEC)); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 895 | sec_event.auth_cmpl.bd_addr = p_data->bond.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 896 | p_name = BTM_SecReadDevName(p_data->bond.bd_addr); |
| 897 | if (p_name != NULL) { |
| 898 | memcpy(sec_event.auth_cmpl.bd_name, p_name, (BD_NAME_LEN - 1)); |
| 899 | 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] | 900 | } |
| 901 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 902 | /* taken care of by memset [above] |
| 903 | sec_event.auth_cmpl.key_present = false; |
| 904 | sec_event.auth_cmpl.success = false; |
| 905 | */ |
| 906 | sec_event.auth_cmpl.fail_reason = HCI_ERR_ILLEGAL_COMMAND; |
| 907 | if (status == BTM_SUCCESS) { |
| 908 | sec_event.auth_cmpl.success = true; |
| 909 | } else { |
| 910 | /* delete this device entry from Sec Dev DB */ |
| 911 | bta_dm_remove_sec_dev_entry(p_data->bond.bd_addr); |
| 912 | } |
| 913 | bta_dm_cb.p_sec_cback(BTA_DM_AUTH_CMPL_EVT, &sec_event); |
| 914 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 918 | * |
| 919 | * Function bta_dm_bond_cancel |
| 920 | * |
| 921 | * Description Cancels bonding with a peer device |
| 922 | * |
| 923 | * |
| 924 | * Returns void |
| 925 | * |
| 926 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 927 | void bta_dm_bond_cancel(tBTA_DM_MSG* p_data) { |
| 928 | tBTM_STATUS status; |
| 929 | tBTA_DM_SEC sec_event; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 930 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 931 | APPL_TRACE_EVENT(" bta_dm_bond_cancel "); |
| 932 | status = BTM_SecBondCancel(p_data->bond_cancel.bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 933 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 934 | if (bta_dm_cb.p_sec_cback && |
| 935 | (status != BTM_CMD_STARTED && status != BTM_SUCCESS)) { |
| 936 | sec_event.bond_cancel_cmpl.result = BTA_FAILURE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 937 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 938 | bta_dm_cb.p_sec_cback(BTA_DM_BOND_CANCEL_CMPL_EVT, &sec_event); |
| 939 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 943 | * |
| 944 | * Function bta_dm_pin_reply |
| 945 | * |
| 946 | * Description Send the pin_reply to a request from BTM |
| 947 | * |
| 948 | * |
| 949 | * Returns void |
| 950 | * |
| 951 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 952 | void bta_dm_pin_reply(tBTA_DM_MSG* p_data) { |
| 953 | uint32_t trusted_mask[BTM_SEC_SERVICE_ARRAY_SIZE]; |
| 954 | uint32_t* current_trusted_mask; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 955 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 956 | 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] | 957 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 958 | if (current_trusted_mask) { |
| 959 | memcpy(trusted_mask, current_trusted_mask, sizeof(trusted_mask)); |
| 960 | } else { |
| 961 | memset(trusted_mask, 0, sizeof(trusted_mask)); |
| 962 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 963 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 964 | if (p_data->pin_reply.accept) { |
| 965 | BTM_PINCodeReply(p_data->pin_reply.bd_addr, BTM_SUCCESS, |
| 966 | p_data->pin_reply.pin_len, p_data->pin_reply.p_pin, |
| 967 | trusted_mask); |
| 968 | } else { |
| 969 | BTM_PINCodeReply(p_data->pin_reply.bd_addr, BTM_NOT_AUTHORIZED, 0, NULL, |
| 970 | trusted_mask); |
| 971 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 975 | * |
| 976 | * Function bta_dm_policy_cback |
| 977 | * |
| 978 | * Description process the link policy changes |
| 979 | * |
| 980 | * Returns void |
| 981 | * |
| 982 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 983 | static void bta_dm_policy_cback(tBTA_SYS_CONN_STATUS status, uint8_t id, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 984 | uint8_t app_id, const RawAddress* peer_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 985 | tBTA_DM_PEER_DEVICE* p_dev = NULL; |
| 986 | uint16_t policy = app_id; |
| 987 | uint32_t mask = (uint32_t)(1 << id); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 988 | |
Jakub Pawlowski | 78b81c6 | 2017-06-16 13:55:52 -0700 | [diff] [blame] | 989 | if (peer_addr) p_dev = bta_dm_find_peer_device(*peer_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 990 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 991 | APPL_TRACE_DEBUG(" bta_dm_policy_cback cmd:%d, policy:0x%x", status, policy); |
| 992 | switch (status) { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 993 | case BTA_SYS_PLCY_SET: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 994 | if (!p_dev) return; |
| 995 | /* restore the default link policy */ |
| 996 | p_dev->link_policy |= policy; |
| 997 | BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy)); |
| 998 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 999 | |
| 1000 | case BTA_SYS_PLCY_CLR: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1001 | if (!p_dev) return; |
| 1002 | /* clear the policy from the default link policy */ |
| 1003 | p_dev->link_policy &= (~policy); |
| 1004 | 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] | 1005 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1006 | if (policy & (HCI_ENABLE_SNIFF_MODE | HCI_ENABLE_PARK_MODE)) { |
| 1007 | /* if clearing sniff/park, wake the link */ |
| 1008 | bta_dm_pm_active(p_dev->peer_bdaddr); |
| 1009 | } |
| 1010 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1011 | |
| 1012 | case BTA_SYS_PLCY_DEF_SET: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1013 | /* want to restore/set the role switch policy */ |
| 1014 | bta_dm_cb.role_policy_mask &= ~mask; |
| 1015 | if (0 == bta_dm_cb.role_policy_mask) { |
| 1016 | /* if nobody wants to insist on the role */ |
| 1017 | bta_dm_cb.cur_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH; |
| 1018 | BTM_SetDefaultLinkPolicy(bta_dm_cb.cur_policy); |
| 1019 | } |
| 1020 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1021 | |
| 1022 | case BTA_SYS_PLCY_DEF_CLR: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1023 | /* want to remove the role switch policy */ |
| 1024 | bta_dm_cb.role_policy_mask |= mask; |
| 1025 | bta_dm_cb.cur_policy &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH; |
| 1026 | BTM_SetDefaultLinkPolicy(bta_dm_cb.cur_policy); |
| 1027 | break; |
| 1028 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1029 | } |
| 1030 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1031 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1032 | * |
| 1033 | * Function bta_dm_confirm |
| 1034 | * |
| 1035 | * Description Send the user confirm request reply in response to a |
| 1036 | * request from BTM |
| 1037 | * |
| 1038 | * Returns void |
| 1039 | * |
| 1040 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1041 | void bta_dm_confirm(tBTA_DM_MSG* p_data) { |
| 1042 | tBTM_STATUS res = BTM_NOT_AUTHORIZED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1043 | |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 1044 | if (p_data->confirm.accept) res = BTM_SUCCESS; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1045 | BTM_ConfirmReqReply(res, p_data->confirm.bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1049 | * |
| 1050 | * Function bta_dm_loc_oob |
| 1051 | * |
| 1052 | * Description Retrieve the OOB data from the local LM |
| 1053 | * |
| 1054 | * Returns void |
| 1055 | * |
| 1056 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1057 | 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] | 1058 | |
| 1059 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1060 | * |
| 1061 | * Function bta_dm_ci_io_req_act |
| 1062 | * |
| 1063 | * Description respond to the IO capabilities request from BTM |
| 1064 | * |
| 1065 | * Returns void |
| 1066 | * |
| 1067 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1068 | void bta_dm_ci_io_req_act(tBTA_DM_MSG* p_data) { |
| 1069 | tBTM_AUTH_REQ auth_req = BTM_AUTH_AP_NO; |
| 1070 | if (p_data->ci_io_req.auth_req) auth_req = BTM_AUTH_AP_YES; |
| 1071 | BTM_IoCapRsp(p_data->ci_io_req.bd_addr, p_data->ci_io_req.io_cap, |
| 1072 | p_data->ci_io_req.oob_data, auth_req); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1076 | * |
| 1077 | * Function bta_dm_ci_rmt_oob_act |
| 1078 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1079 | * Description respond to the OOB data request for the remote device from |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 1080 | * BTM |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1081 | * |
| 1082 | * |
| 1083 | * Returns void |
| 1084 | * |
| 1085 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1086 | void bta_dm_ci_rmt_oob_act(tBTA_DM_MSG* p_data) { |
| 1087 | tBTM_STATUS res = BTM_NOT_AUTHORIZED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1088 | |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 1089 | if (p_data->ci_rmt_oob.accept) res = BTM_SUCCESS; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1090 | BTM_RemoteOobDataReply(res, p_data->ci_rmt_oob.bd_addr, p_data->ci_rmt_oob.c, |
| 1091 | p_data->ci_rmt_oob.r); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1092 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1093 | |
| 1094 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1095 | * |
| 1096 | * Function bta_dm_search_start |
| 1097 | * |
| 1098 | * Description Starts an inquiry |
| 1099 | * |
| 1100 | * |
| 1101 | * Returns void |
| 1102 | * |
| 1103 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1104 | void bta_dm_search_start(tBTA_DM_MSG* p_data) { |
| 1105 | tBTM_INQUIRY_CMPL result; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1106 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1107 | size_t len = sizeof(Uuid) * p_data->search.num_uuid; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1108 | bta_dm_gattc_register(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1109 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1110 | APPL_TRACE_DEBUG("%s avoid_scatter=%d", __func__, |
| 1111 | p_bta_dm_cfg->avoid_scatter); |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 1112 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1113 | if (p_bta_dm_cfg->avoid_scatter && |
| 1114 | (p_data->search.rs_res == BTA_DM_RS_NONE) && |
| 1115 | bta_dm_check_av(BTA_DM_API_SEARCH_EVT)) { |
| 1116 | memcpy(&bta_dm_cb.search_msg, &p_data->search, sizeof(tBTA_DM_API_SEARCH)); |
| 1117 | return; |
| 1118 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1119 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1120 | BTM_ClearInqDb(NULL); |
| 1121 | /* save search params */ |
| 1122 | bta_dm_search_cb.p_search_cback = p_data->search.p_cback; |
| 1123 | bta_dm_search_cb.services = p_data->search.services; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1124 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1125 | 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] | 1126 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1127 | if ((bta_dm_search_cb.num_uuid = p_data->search.num_uuid) != 0 && |
| 1128 | p_data->search.p_uuid != NULL) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1129 | bta_dm_search_cb.p_srvc_uuid = (Uuid*)osi_malloc(len); |
| 1130 | *bta_dm_search_cb.p_srvc_uuid = *p_data->search.p_uuid; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1131 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1132 | result.status = BTM_StartInquiry((tBTM_INQ_PARMS*)&p_data->search.inq_params, |
| 1133 | bta_dm_inq_results_cb, |
| 1134 | (tBTM_CMPL_CB*)bta_dm_inq_cmpl_cb); |
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 | APPL_TRACE_EVENT("%s status=%d", __func__, result.status); |
| 1137 | if (result.status != BTM_CMD_STARTED) { |
| 1138 | result.num_resp = 0; |
| 1139 | bta_dm_inq_cmpl_cb((void*)&result); |
| 1140 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1144 | * |
| 1145 | * Function bta_dm_search_cancel |
| 1146 | * |
| 1147 | * Description Cancels an ongoing search for devices |
| 1148 | * |
| 1149 | * |
| 1150 | * Returns void |
| 1151 | * |
| 1152 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1153 | void bta_dm_search_cancel(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 1154 | tBTA_DM_MSG* p_msg; |
Jack He | db76fa4 | 2016-11-01 11:30:51 -0700 | [diff] [blame] | 1155 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1156 | if (BTM_IsInquiryActive()) { |
| 1157 | if (BTM_CancelInquiry() == BTM_SUCCESS) { |
| 1158 | bta_dm_search_cancel_notify(NULL); |
| 1159 | p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
| 1160 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1161 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 1162 | bta_sys_sendmsg(p_msg); |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 1163 | } else { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1164 | /* flag a search cancel is pending */ |
| 1165 | bta_dm_search_cb.cancel_pending = true; |
Matthew Xie | c358eed | 2015-01-28 17:30:13 -0800 | [diff] [blame] | 1166 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1167 | } |
| 1168 | /* If no Service Search going on then issue cancel remote name in case it is |
| 1169 | active */ |
| 1170 | else if (!bta_dm_search_cb.name_discover_done) { |
| 1171 | BTM_CancelRemoteDeviceName(); |
| 1172 | |
| 1173 | p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
| 1174 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1175 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 1176 | bta_sys_sendmsg(p_msg); |
| 1177 | } else { |
| 1178 | p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
| 1179 | p_msg->hdr.event = BTA_DM_INQUIRY_CMPL_EVT; |
| 1180 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 1181 | bta_sys_sendmsg(p_msg); |
| 1182 | } |
Matthew Xie | c358eed | 2015-01-28 17:30:13 -0800 | [diff] [blame] | 1183 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1184 | if (bta_dm_search_cb.gatt_disc_active) { |
| 1185 | bta_dm_cancel_gatt_discovery(bta_dm_search_cb.peer_bdaddr); |
| 1186 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1190 | * |
| 1191 | * Function bta_dm_discover |
| 1192 | * |
| 1193 | * Description Discovers services on a remote device |
| 1194 | * |
| 1195 | * |
| 1196 | * Returns void |
| 1197 | * |
| 1198 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1199 | void bta_dm_discover(tBTA_DM_MSG* p_data) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1200 | size_t len = sizeof(Uuid) * p_data->discover.num_uuid; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1201 | APPL_TRACE_EVENT("%s services_to_search=0x%04X, sdp_search=%d", __func__, |
| 1202 | p_data->discover.services, p_data->discover.sdp_search); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1203 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1204 | /* save the search condition */ |
| 1205 | bta_dm_search_cb.services = p_data->discover.services; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1206 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1207 | bta_dm_gattc_register(); |
| 1208 | osi_free_and_reset((void**)&bta_dm_search_cb.p_srvc_uuid); |
| 1209 | if ((bta_dm_search_cb.num_uuid = p_data->discover.num_uuid) != 0 && |
| 1210 | p_data->discover.p_uuid != NULL) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1211 | bta_dm_search_cb.p_srvc_uuid = (Uuid*)osi_malloc(len); |
| 1212 | *bta_dm_search_cb.p_srvc_uuid = *p_data->discover.p_uuid; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1213 | } |
| 1214 | 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] | 1215 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1216 | bta_dm_search_cb.p_search_cback = p_data->discover.p_cback; |
| 1217 | bta_dm_search_cb.sdp_search = p_data->discover.sdp_search; |
| 1218 | bta_dm_search_cb.services_to_search = bta_dm_search_cb.services; |
| 1219 | bta_dm_search_cb.service_index = 0; |
| 1220 | bta_dm_search_cb.services_found = 0; |
| 1221 | bta_dm_search_cb.peer_name[0] = 0; |
| 1222 | bta_dm_search_cb.sdp_search = p_data->discover.sdp_search; |
| 1223 | bta_dm_search_cb.p_btm_inq_info = BTM_InqDbRead(p_data->discover.bd_addr); |
| 1224 | bta_dm_search_cb.transport = p_data->discover.transport; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1225 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1226 | bta_dm_search_cb.name_discover_done = false; |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1227 | bta_dm_search_cb.uuid = p_data->discover.uuid; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1228 | bta_dm_discover_device(p_data->discover.bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1232 | * |
| 1233 | * Function bta_dm_di_disc_cmpl |
| 1234 | * |
| 1235 | * Description Sends event to application when DI discovery complete |
| 1236 | * |
| 1237 | * Returns void |
| 1238 | * |
| 1239 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1240 | void bta_dm_di_disc_cmpl(tBTA_DM_MSG* p_data) { |
| 1241 | tBTA_DM_DI_DISC_CMPL di_disc; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1242 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1243 | memset(&di_disc, 0, sizeof(tBTA_DM_DI_DISC_CMPL)); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1244 | 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] | 1245 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1246 | if ((p_data->hdr.offset == SDP_SUCCESS) || |
| 1247 | (p_data->hdr.offset == SDP_DB_FULL)) { |
| 1248 | di_disc.num_record = SDP_GetNumDiRecords(bta_dm_di_cb.p_di_db); |
| 1249 | } else |
| 1250 | di_disc.result = BTA_FAILURE; |
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 | bta_dm_di_cb.p_di_db = NULL; |
| 1253 | bta_dm_search_cb.p_search_cback(BTA_DM_DI_DISC_CMPL_EVT, |
| 1254 | (tBTA_DM_SEARCH*)&di_disc); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1258 | * |
| 1259 | * Function bta_dm_di_disc_callback |
| 1260 | * |
| 1261 | * Description This function queries a remote device for DI information. |
| 1262 | * |
| 1263 | * |
| 1264 | * Returns void |
| 1265 | * |
| 1266 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1267 | static void bta_dm_di_disc_callback(uint16_t result) { |
| 1268 | 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] | 1269 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1270 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1271 | p_msg->hdr.layer_specific = BTA_DM_API_DI_DISCOVER_EVT; |
| 1272 | p_msg->hdr.offset = result; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 1273 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1274 | bta_sys_sendmsg(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1278 | * |
| 1279 | * Function bta_dm_disable_search_and_disc |
| 1280 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1281 | * Description Cancels an ongoing search or discovery for devices in case |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 1282 | * of a Bluetooth disable |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1283 | * |
| 1284 | * |
| 1285 | * Returns void |
| 1286 | * |
| 1287 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1288 | static void bta_dm_disable_search_and_disc(void) { |
| 1289 | tBTA_DM_DI_DISC_CMPL di_disc; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1290 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1291 | 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] | 1292 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1293 | if (bta_dm_di_cb.p_di_db != NULL) { |
| 1294 | memset(&di_disc, 0, sizeof(tBTA_DM_DI_DISC_CMPL)); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1295 | di_disc.bd_addr = bta_dm_search_cb.peer_bdaddr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1296 | di_disc.result = BTA_FAILURE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1297 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1298 | bta_dm_di_cb.p_di_db = NULL; |
| 1299 | bta_dm_search_cb.p_search_cback(BTA_DM_DI_DISC_CMPL_EVT, NULL); |
| 1300 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1301 | } |
| 1302 | |
| 1303 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1304 | * |
| 1305 | * Function bta_dm_di_disc |
| 1306 | * |
| 1307 | * Description This function queries a remote device for DI information. |
| 1308 | * |
| 1309 | * |
| 1310 | * Returns void |
| 1311 | * |
| 1312 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1313 | void bta_dm_di_disc(tBTA_DM_MSG* p_data) { |
| 1314 | uint16_t result = BTA_FAILURE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1315 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1316 | 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] | 1317 | bta_dm_search_cb.peer_bdaddr = p_data->di_disc.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1318 | 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] | 1319 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1320 | bta_dm_search_cb.p_sdp_db = |
| 1321 | (tSDP_DISCOVERY_DB*)osi_malloc(BTA_DM_SDP_DB_SIZE); |
Jakub Pawlowski | 135b7f6 | 2017-06-16 10:00:46 -0700 | [diff] [blame] | 1322 | if (SDP_DiDiscover(bta_dm_search_cb.peer_bdaddr, p_data->di_disc.p_sdp_db, |
| 1323 | p_data->di_disc.len, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1324 | bta_dm_di_disc_callback) == SDP_SUCCESS) { |
| 1325 | result = BTA_SUCCESS; |
| 1326 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1327 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1328 | if (result == BTA_FAILURE) { |
| 1329 | 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] | 1330 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1331 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1332 | p_msg->hdr.layer_specific = BTA_DM_API_DI_DISCOVER_EVT; |
| 1333 | p_data->hdr.offset = result; |
| 1334 | bta_sys_sendmsg(p_msg); |
| 1335 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1336 | } |
| 1337 | |
| 1338 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1339 | * |
| 1340 | * Function bta_dm_read_remote_device_name |
| 1341 | * |
| 1342 | * Description Initiate to get remote device name |
| 1343 | * |
| 1344 | * Returns true if started to get remote name |
| 1345 | * |
| 1346 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 1347 | static bool bta_dm_read_remote_device_name(const RawAddress& bd_addr, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1348 | tBT_TRANSPORT transport) { |
| 1349 | tBTM_STATUS btm_status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1350 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1351 | APPL_TRACE_DEBUG("%s", __func__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1352 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1353 | bta_dm_search_cb.peer_bdaddr = bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1354 | bta_dm_search_cb.peer_name[0] = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1355 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1356 | btm_status = |
| 1357 | BTM_ReadRemoteDeviceName(bta_dm_search_cb.peer_bdaddr, |
| 1358 | (tBTM_CMPL_CB*)bta_dm_remname_cback, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1359 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1360 | if (btm_status == BTM_CMD_STARTED) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1361 | APPL_TRACE_DEBUG("%s: BTM_ReadRemoteDeviceName is started", __func__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1362 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1363 | return (true); |
| 1364 | } else if (btm_status == BTM_BUSY) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1365 | APPL_TRACE_DEBUG("%s: BTM_ReadRemoteDeviceName is busy", __func__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1366 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1367 | /* Remote name discovery is on going now so BTM cannot notify through |
| 1368 | * "bta_dm_remname_cback" */ |
| 1369 | /* adding callback to get notified that current reading remore name done */ |
| 1370 | BTM_SecAddRmtNameNotifyCallback(&bta_dm_service_search_remname_cback); |
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 { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1374 | APPL_TRACE_WARNING("%s: BTM_ReadRemoteDeviceName returns 0x%02X", __func__, |
| 1375 | btm_status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1376 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1377 | return (false); |
| 1378 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1382 | * |
| 1383 | * Function bta_dm_inq_cmpl |
| 1384 | * |
| 1385 | * Description Process the inquiry complete event from BTM |
| 1386 | * |
| 1387 | * Returns void |
| 1388 | * |
| 1389 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1390 | void bta_dm_inq_cmpl(tBTA_DM_MSG* p_data) { |
| 1391 | tBTA_DM_SEARCH data; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1392 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1393 | APPL_TRACE_DEBUG("bta_dm_inq_cmpl"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1394 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1395 | data.inq_cmpl.num_resps = p_data->inq_cmpl.num; |
| 1396 | 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] | 1397 | |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame] | 1398 | bta_dm_search_cb.p_btm_inq_info = BTM_InqDbFirst(); |
| 1399 | if (bta_dm_search_cb.p_btm_inq_info != NULL) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1400 | /* start name and service discovery from the first device on inquiry result |
| 1401 | */ |
| 1402 | bta_dm_search_cb.name_discover_done = false; |
| 1403 | bta_dm_search_cb.peer_name[0] = 0; |
| 1404 | bta_dm_discover_device( |
| 1405 | bta_dm_search_cb.p_btm_inq_info->results.remote_bd_addr); |
| 1406 | } else { |
| 1407 | 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] | 1408 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1409 | /* no devices, search complete */ |
| 1410 | bta_dm_search_cb.services = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1411 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1412 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1413 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 1414 | bta_sys_sendmsg(p_msg); |
| 1415 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 1416 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1417 | |
| 1418 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1419 | * |
| 1420 | * Function bta_dm_rmt_name |
| 1421 | * |
| 1422 | * Description Process the remote name result from BTM |
| 1423 | * |
| 1424 | * Returns void |
| 1425 | * |
| 1426 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1427 | void bta_dm_rmt_name(tBTA_DM_MSG* p_data) { |
| 1428 | APPL_TRACE_DEBUG("bta_dm_rmt_name"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1429 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1430 | if (p_data->rem_name.result.disc_res.bd_name[0] && |
| 1431 | bta_dm_search_cb.p_btm_inq_info) { |
| 1432 | bta_dm_search_cb.p_btm_inq_info->appl_knows_rem_name = true; |
| 1433 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1434 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1435 | 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] | 1436 | } |
| 1437 | |
| 1438 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1439 | * |
| 1440 | * Function bta_dm_disc_rmt_name |
| 1441 | * |
| 1442 | * Description Process the remote name result from BTM when application |
| 1443 | * wants to find the name for a bdaddr |
| 1444 | * |
| 1445 | * Returns void |
| 1446 | * |
| 1447 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1448 | void bta_dm_disc_rmt_name(tBTA_DM_MSG* p_data) { |
| 1449 | tBTM_INQ_INFO* p_btm_inq_info; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1450 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1451 | APPL_TRACE_DEBUG("bta_dm_disc_rmt_name"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1452 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1453 | p_btm_inq_info = BTM_InqDbRead(p_data->rem_name.result.disc_res.bd_addr); |
| 1454 | if (p_btm_inq_info) { |
| 1455 | if (p_data->rem_name.result.disc_res.bd_name[0]) { |
| 1456 | p_btm_inq_info->appl_knows_rem_name = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1457 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1458 | } |
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 | 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] | 1461 | } |
| 1462 | |
| 1463 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1464 | * |
| 1465 | * Function bta_dm_sdp_result |
| 1466 | * |
| 1467 | * Description Process the discovery result from sdp |
| 1468 | * |
| 1469 | * Returns void |
| 1470 | * |
| 1471 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1472 | void bta_dm_sdp_result(tBTA_DM_MSG* p_data) { |
| 1473 | tSDP_DISC_REC* p_sdp_rec = NULL; |
| 1474 | tBTA_DM_MSG* p_msg; |
| 1475 | bool scn_found = false; |
| 1476 | uint16_t service = 0xFFFF; |
| 1477 | tSDP_PROTOCOL_ELEM pe; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1478 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1479 | Uuid* p_uuid = bta_dm_search_cb.p_srvc_uuid; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1480 | tBTA_DM_SEARCH result; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1481 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1482 | std::vector<Uuid> uuid_list; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1483 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1484 | if ((p_data->sdp_event.sdp_result == SDP_SUCCESS) || |
| 1485 | (p_data->sdp_event.sdp_result == SDP_NO_RECS_MATCH) || |
| 1486 | (p_data->sdp_event.sdp_result == SDP_DB_FULL)) { |
| 1487 | APPL_TRACE_DEBUG("sdp_result::0x%x", p_data->sdp_event.sdp_result); |
| 1488 | do { |
| 1489 | p_sdp_rec = NULL; |
| 1490 | if (bta_dm_search_cb.service_index == (BTA_USER_SERVICE_ID + 1)) { |
| 1491 | p_sdp_rec = SDP_FindServiceUUIDInDb(bta_dm_search_cb.p_sdp_db, |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1492 | bta_dm_search_cb.uuid, p_sdp_rec); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1493 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1494 | if (p_sdp_rec && SDP_FindProtocolListElemInRec( |
| 1495 | p_sdp_rec, UUID_PROTOCOL_RFCOMM, &pe)) { |
| 1496 | bta_dm_search_cb.peer_scn = (uint8_t)pe.params[0]; |
| 1497 | scn_found = true; |
| 1498 | } |
| 1499 | } else { |
| 1500 | service = |
| 1501 | bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index - 1]; |
| 1502 | p_sdp_rec = |
| 1503 | SDP_FindServiceInDb(bta_dm_search_cb.p_sdp_db, service, p_sdp_rec); |
| 1504 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1505 | /* finished with BR/EDR services, now we check the result for GATT based |
| 1506 | * service UUID */ |
| 1507 | if (bta_dm_search_cb.service_index == BTA_MAX_SERVICE_ID) { |
| 1508 | if (bta_dm_search_cb.uuid_to_search != 0 && p_uuid != NULL) { |
| 1509 | p_uuid += |
| 1510 | (bta_dm_search_cb.num_uuid - bta_dm_search_cb.uuid_to_search); |
| 1511 | /* only support 16 bits UUID for now */ |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1512 | service = p_uuid->As16Bit(); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1513 | } |
| 1514 | /* all GATT based services */ |
| 1515 | do { |
| 1516 | /* find a service record, report it */ |
| 1517 | p_sdp_rec = |
| 1518 | SDP_FindServiceInDb(bta_dm_search_cb.p_sdp_db, 0, p_sdp_rec); |
| 1519 | if (p_sdp_rec) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1520 | Uuid service_uuid; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1521 | if (SDP_FindServiceUUIDInRec(p_sdp_rec, &service_uuid)) { |
| 1522 | /* send result back to app now, one by one */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1523 | result.disc_ble_res.bd_addr = bta_dm_search_cb.peer_bdaddr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1524 | strlcpy((char*)result.disc_ble_res.bd_name, bta_dm_get_remname(), |
| 1525 | BD_NAME_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1526 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1527 | result.disc_ble_res.service = service_uuid; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1528 | 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] | 1529 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1530 | } |
| 1531 | |
| 1532 | if (bta_dm_search_cb.uuid_to_search > 0) break; |
| 1533 | |
| 1534 | } while (p_sdp_rec); |
Myles Watson | 9979121 | 2016-11-18 08:42:23 -0800 | [diff] [blame] | 1535 | } else { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1536 | /* SDP_DB_FULL means some records with the |
| 1537 | required attributes were received */ |
| 1538 | if (((p_data->sdp_event.sdp_result == SDP_DB_FULL) && |
| 1539 | bta_dm_search_cb.services != BTA_ALL_SERVICE_MASK) || |
| 1540 | (p_sdp_rec != NULL)) { |
| 1541 | if (service != UUID_SERVCLASS_PNP_INFORMATION) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1542 | bta_dm_search_cb.services_found |= |
| 1543 | (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK( |
| 1544 | bta_dm_search_cb.service_index - 1)); |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1545 | uint16_t tmp_svc = |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1546 | bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index - |
| 1547 | 1]; |
| 1548 | /* Add to the list of UUIDs */ |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1549 | uuid_list.push_back(Uuid::From16Bit(tmp_svc)); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1550 | } |
| 1551 | } |
| 1552 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1553 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1554 | if (bta_dm_search_cb.services == BTA_ALL_SERVICE_MASK && |
| 1555 | bta_dm_search_cb.services_to_search == 0) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1556 | if (bta_dm_search_cb.service_index == BTA_BLE_SERVICE_ID && |
| 1557 | bta_dm_search_cb.uuid_to_search > 0) |
| 1558 | bta_dm_search_cb.uuid_to_search--; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1559 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1560 | if (bta_dm_search_cb.uuid_to_search == 0 || |
| 1561 | bta_dm_search_cb.service_index != BTA_BLE_SERVICE_ID) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1562 | bta_dm_search_cb.service_index++; |
| 1563 | } else /* regular one service per search or PNP search */ |
| 1564 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1565 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1566 | } 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] | 1567 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1568 | APPL_TRACE_DEBUG("%s services_found = %04x", __func__, |
| 1569 | bta_dm_search_cb.services_found); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1570 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1571 | /* Collect the 128-bit services here and put them into the list */ |
| 1572 | if (bta_dm_search_cb.services == BTA_ALL_SERVICE_MASK) { |
| 1573 | p_sdp_rec = NULL; |
| 1574 | do { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1575 | /* find a service record, report it */ |
| 1576 | p_sdp_rec = |
| 1577 | SDP_FindServiceInDb_128bit(bta_dm_search_cb.p_sdp_db, p_sdp_rec); |
| 1578 | if (p_sdp_rec) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1579 | // SDP_FindServiceUUIDInRec_128bit is used only once, refactor? |
| 1580 | Uuid temp_uuid; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1581 | if (SDP_FindServiceUUIDInRec_128bit(p_sdp_rec, &temp_uuid)) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1582 | uuid_list.push_back(temp_uuid); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1583 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1584 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1585 | } while (p_sdp_rec); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1586 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1587 | /* if there are more services to search for */ |
| 1588 | if (bta_dm_search_cb.services_to_search) { |
| 1589 | /* Free up the p_sdp_db before checking the next one */ |
| 1590 | bta_dm_free_sdp_db(NULL); |
| 1591 | bta_dm_find_services(bta_dm_search_cb.peer_bdaddr); |
| 1592 | } else { |
| 1593 | /* callbacks */ |
| 1594 | /* start next bd_addr if necessary */ |
| 1595 | |
| 1596 | BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback); |
| 1597 | |
| 1598 | p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
| 1599 | p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT; |
| 1600 | p_msg->disc_result.result.disc_res.result = BTA_SUCCESS; |
| 1601 | p_msg->disc_result.result.disc_res.p_raw_data = NULL; |
| 1602 | p_msg->disc_result.result.disc_res.raw_data_size = 0; |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1603 | p_msg->disc_result.result.disc_res.num_uuids = uuid_list.size(); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1604 | p_msg->disc_result.result.disc_res.p_uuid_list = NULL; |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1605 | if (uuid_list.size() > 0) { |
| 1606 | // TODO(jpawlowski): make p_uuid_list into vector, and just copy |
| 1607 | // vectors, but first get rid of bta_sys_sendmsg below. |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1608 | p_msg->disc_result.result.disc_res.p_uuid_list = |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1609 | (Uuid*)osi_malloc(uuid_list.size() * sizeof(Uuid)); |
| 1610 | memcpy(p_msg->disc_result.result.disc_res.p_uuid_list, uuid_list.data(), |
| 1611 | uuid_list.size() * sizeof(Uuid)); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1612 | } |
| 1613 | // Copy the raw_data to the discovery result structure |
| 1614 | if (bta_dm_search_cb.p_sdp_db != NULL && |
| 1615 | bta_dm_search_cb.p_sdp_db->raw_used != 0 && |
| 1616 | bta_dm_search_cb.p_sdp_db->raw_data != NULL) { |
| 1617 | APPL_TRACE_DEBUG("%s raw_data used = 0x%x raw_data_ptr = 0x%x", |
| 1618 | __func__, bta_dm_search_cb.p_sdp_db->raw_used, |
| 1619 | bta_dm_search_cb.p_sdp_db->raw_data); |
| 1620 | |
| 1621 | p_msg->disc_result.result.disc_res.p_raw_data = |
| 1622 | (uint8_t*)osi_malloc(bta_dm_search_cb.p_sdp_db->raw_used); |
| 1623 | memcpy(p_msg->disc_result.result.disc_res.p_raw_data, |
| 1624 | bta_dm_search_cb.p_sdp_db->raw_data, |
| 1625 | bta_dm_search_cb.p_sdp_db->raw_used); |
| 1626 | |
| 1627 | p_msg->disc_result.result.disc_res.raw_data_size = |
| 1628 | bta_dm_search_cb.p_sdp_db->raw_used; |
| 1629 | |
| 1630 | bta_dm_search_cb.p_sdp_db->raw_data = |
| 1631 | NULL; // no need to free this - it is a global assigned. |
| 1632 | bta_dm_search_cb.p_sdp_db->raw_used = 0; |
| 1633 | bta_dm_search_cb.p_sdp_db->raw_size = 0; |
| 1634 | } else { |
| 1635 | APPL_TRACE_DEBUG("%s raw data size is 0 or raw_data is null!!", |
| 1636 | __func__); |
| 1637 | } |
| 1638 | /* Done with p_sdp_db. Free it */ |
| 1639 | bta_dm_free_sdp_db(NULL); |
| 1640 | p_msg->disc_result.result.disc_res.services = |
| 1641 | bta_dm_search_cb.services_found; |
| 1642 | |
| 1643 | // Piggy back the SCN over result field |
| 1644 | if (scn_found) { |
| 1645 | p_msg->disc_result.result.disc_res.result = |
| 1646 | (3 + bta_dm_search_cb.peer_scn); |
| 1647 | p_msg->disc_result.result.disc_res.services |= BTA_USER_SERVICE_MASK; |
| 1648 | |
| 1649 | APPL_TRACE_EVENT(" Piggy back the SCN over result field SCN=%d", |
| 1650 | bta_dm_search_cb.peer_scn); |
| 1651 | } |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1652 | 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] | 1653 | strlcpy((char*)p_msg->disc_result.result.disc_res.bd_name, |
| 1654 | bta_dm_get_remname(), BD_NAME_LEN); |
| 1655 | |
| 1656 | bta_sys_sendmsg(p_msg); |
| 1657 | } |
| 1658 | } else { |
| 1659 | /* conn failed. No need for timer */ |
| 1660 | if (p_data->sdp_event.sdp_result == SDP_CONN_FAILED || |
| 1661 | p_data->sdp_event.sdp_result == SDP_CONN_REJECTED || |
| 1662 | p_data->sdp_event.sdp_result == SDP_SECURITY_ERR) |
| 1663 | bta_dm_search_cb.wait_disc = false; |
| 1664 | |
| 1665 | /* not able to connect go to next device */ |
| 1666 | if (bta_dm_search_cb.p_sdp_db) |
| 1667 | osi_free_and_reset((void**)&bta_dm_search_cb.p_sdp_db); |
| 1668 | |
| 1669 | BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback); |
| 1670 | |
| 1671 | p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
| 1672 | p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT; |
| 1673 | p_msg->disc_result.result.disc_res.result = BTA_FAILURE; |
| 1674 | p_msg->disc_result.result.disc_res.services = |
| 1675 | bta_dm_search_cb.services_found; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 1676 | 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] | 1677 | strlcpy((char*)p_msg->disc_result.result.disc_res.bd_name, |
| 1678 | bta_dm_get_remname(), BD_NAME_LEN); |
| 1679 | |
| 1680 | bta_sys_sendmsg(p_msg); |
| 1681 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1682 | } |
| 1683 | |
| 1684 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1685 | * |
| 1686 | * Function bta_dm_search_cmpl |
| 1687 | * |
| 1688 | * Description Sends event to application |
| 1689 | * |
| 1690 | * Returns void |
| 1691 | * |
| 1692 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1693 | void bta_dm_search_cmpl(tBTA_DM_MSG* p_data) { |
| 1694 | APPL_TRACE_EVENT("%s", __func__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1695 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1696 | 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] | 1697 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1698 | if (p_data->hdr.layer_specific == BTA_DM_API_DI_DISCOVER_EVT) |
| 1699 | bta_dm_di_disc_cmpl(p_data); |
| 1700 | else |
| 1701 | 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] | 1702 | } |
| 1703 | |
| 1704 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1705 | * |
| 1706 | * Function bta_dm_disc_result |
| 1707 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1708 | * Description Service discovery result when discovering services on a |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 1709 | * device |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1710 | * |
| 1711 | * Returns void |
| 1712 | * |
| 1713 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1714 | void bta_dm_disc_result(tBTA_DM_MSG* p_data) { |
| 1715 | APPL_TRACE_EVENT("%s", __func__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1716 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1717 | /* if any BR/EDR service discovery has been done, report the event */ |
| 1718 | if ((bta_dm_search_cb.services & |
| 1719 | ((BTA_ALL_SERVICE_MASK | BTA_USER_SERVICE_MASK) & |
| 1720 | ~BTA_BLE_SERVICE_MASK))) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1721 | bta_dm_search_cb.p_search_cback(BTA_DM_DISC_RES_EVT, |
| 1722 | &p_data->disc_result.result); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1723 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1724 | 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] | 1725 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1726 | /* send a message to change state */ |
| 1727 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1728 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 1729 | bta_sys_sendmsg(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1733 | * |
| 1734 | * Function bta_dm_search_result |
| 1735 | * |
| 1736 | * Description Service discovery result while searching for devices |
| 1737 | * |
| 1738 | * Returns void |
| 1739 | * |
| 1740 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1741 | void bta_dm_search_result(tBTA_DM_MSG* p_data) { |
| 1742 | APPL_TRACE_DEBUG("%s searching:0x%04x, result:0x%04x", __func__, |
| 1743 | bta_dm_search_cb.services, |
| 1744 | p_data->disc_result.result.disc_res.services); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1745 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1746 | /* call back if application wants name discovery or found services that |
| 1747 | * application is searching */ |
| 1748 | if ((!bta_dm_search_cb.services) || |
| 1749 | ((bta_dm_search_cb.services) && |
| 1750 | (p_data->disc_result.result.disc_res.services))) { |
| 1751 | bta_dm_search_cb.p_search_cback(BTA_DM_DISC_RES_EVT, |
| 1752 | &p_data->disc_result.result); |
| 1753 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1754 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1755 | /* if searching did not initiate to create link */ |
| 1756 | if (!bta_dm_search_cb.wait_disc) { |
| 1757 | /* if service searching is done with EIR, don't search next device */ |
| 1758 | if (bta_dm_search_cb.p_btm_inq_info) bta_dm_discover_next_device(); |
| 1759 | } else { |
| 1760 | /* wait until link is disconnected or timeout */ |
| 1761 | bta_dm_search_cb.sdp_results = true; |
Jakub Pawlowski | be8bbd7 | 2017-09-08 11:26:25 -0700 | [diff] [blame] | 1762 | alarm_set_on_mloop(bta_dm_search_cb.search_timer, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1763 | 1000 * (L2CAP_LINK_INACTIVITY_TOUT + 1), |
Jakub Pawlowski | be8bbd7 | 2017-09-08 11:26:25 -0700 | [diff] [blame] | 1764 | bta_dm_search_timer_cback, NULL); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1765 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1769 | * |
| 1770 | * Function bta_dm_search_timer_cback |
| 1771 | * |
| 1772 | * Description Called when ACL disconnect time is over |
| 1773 | * |
| 1774 | * |
| 1775 | * Returns void |
| 1776 | * |
| 1777 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1778 | static void bta_dm_search_timer_cback(UNUSED_ATTR void* data) { |
| 1779 | APPL_TRACE_EVENT("%s", __func__); |
| 1780 | bta_dm_search_cb.wait_disc = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1781 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1782 | /* proceed with next device */ |
| 1783 | bta_dm_discover_next_device(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1784 | } |
| 1785 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1786 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1787 | * |
| 1788 | * Function bta_dm_free_sdp_db |
| 1789 | * |
| 1790 | * Description Frees SDP data base |
| 1791 | * |
| 1792 | * Returns void |
| 1793 | * |
| 1794 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1795 | void bta_dm_free_sdp_db(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 1796 | 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] | 1797 | } |
| 1798 | |
| 1799 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1800 | * |
| 1801 | * Function bta_dm_queue_search |
| 1802 | * |
| 1803 | * Description Queues search command while search is being cancelled |
| 1804 | * |
| 1805 | * Returns void |
| 1806 | * |
| 1807 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1808 | void bta_dm_queue_search(tBTA_DM_MSG* p_data) { |
| 1809 | osi_free(bta_dm_search_cb.p_search_queue); |
| 1810 | bta_dm_search_cb.p_search_queue = |
| 1811 | (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_API_SEARCH)); |
| 1812 | 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] | 1813 | } |
| 1814 | |
| 1815 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1816 | * |
| 1817 | * Function bta_dm_queue_disc |
| 1818 | * |
| 1819 | * Description Queues discovery command while search is being cancelled |
| 1820 | * |
| 1821 | * Returns void |
| 1822 | * |
| 1823 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1824 | void bta_dm_queue_disc(tBTA_DM_MSG* p_data) { |
| 1825 | osi_free(bta_dm_search_cb.p_search_queue); |
| 1826 | bta_dm_search_cb.p_search_queue = |
| 1827 | (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_API_DISCOVER)); |
| 1828 | 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] | 1829 | } |
| 1830 | |
| 1831 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1832 | * |
| 1833 | * Function bta_dm_search_clear_queue |
| 1834 | * |
| 1835 | * Description Clears the queue if API search cancel is called |
| 1836 | * |
| 1837 | * Returns void |
| 1838 | * |
| 1839 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1840 | void bta_dm_search_clear_queue(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 1841 | 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] | 1842 | } |
| 1843 | |
| 1844 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1845 | * |
| 1846 | * Function bta_dm_search_cancel_cmpl |
| 1847 | * |
| 1848 | * Description Search cancel is complete |
| 1849 | * |
| 1850 | * Returns void |
| 1851 | * |
| 1852 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1853 | void bta_dm_search_cancel_cmpl(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 1854 | if (bta_dm_search_cb.p_search_queue) { |
| 1855 | bta_sys_sendmsg(bta_dm_search_cb.p_search_queue); |
| 1856 | bta_dm_search_cb.p_search_queue = NULL; |
| 1857 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1861 | * |
| 1862 | * Function bta_dm_search_cancel_transac_cmpl |
| 1863 | * |
| 1864 | * Description Current Service Discovery or remote name procedure is |
| 1865 | * completed after search cancellation |
| 1866 | * |
| 1867 | * Returns void |
| 1868 | * |
| 1869 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1870 | void bta_dm_search_cancel_transac_cmpl(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 1871 | osi_free_and_reset((void**)&bta_dm_search_cb.p_sdp_db); |
| 1872 | bta_dm_search_cancel_notify(NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1873 | } |
| 1874 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1875 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1876 | * |
| 1877 | * Function bta_dm_search_cancel_notify |
| 1878 | * |
| 1879 | * Description Notify application that search has been cancelled |
| 1880 | * |
| 1881 | * Returns void |
| 1882 | * |
| 1883 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1884 | void bta_dm_search_cancel_notify(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 1885 | if (bta_dm_search_cb.p_search_cback) { |
| 1886 | bta_dm_search_cb.p_search_cback(BTA_DM_SEARCH_CANCEL_CMPL_EVT, NULL); |
| 1887 | } |
| 1888 | if (!bta_dm_search_cb.name_discover_done) { |
| 1889 | BTM_CancelRemoteDeviceName(); |
| 1890 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1891 | if (bta_dm_search_cb.gatt_disc_active) { |
| 1892 | bta_dm_cancel_gatt_discovery(bta_dm_search_cb.peer_bdaddr); |
| 1893 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 1897 | * |
| 1898 | * Function bta_dm_find_services |
| 1899 | * |
| 1900 | * Description Starts discovery on a device |
| 1901 | * |
| 1902 | * Returns void |
| 1903 | * |
| 1904 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 1905 | static void bta_dm_find_services(const RawAddress& bd_addr) { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1906 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1907 | while (bta_dm_search_cb.service_index < BTA_MAX_SERVICE_ID) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1908 | Uuid uuid = Uuid::kEmpty; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1909 | if (bta_dm_search_cb.services_to_search & |
| 1910 | (tBTA_SERVICE_MASK)( |
| 1911 | BTA_SERVICE_ID_TO_SERVICE_MASK(bta_dm_search_cb.service_index))) { |
| 1912 | bta_dm_search_cb.p_sdp_db = |
| 1913 | (tSDP_DISCOVERY_DB*)osi_malloc(BTA_DM_SDP_DB_SIZE); |
| 1914 | APPL_TRACE_DEBUG("bta_dm_search_cb.services = %04x***********", |
| 1915 | bta_dm_search_cb.services); |
| 1916 | /* try to search all services by search based on L2CAP UUID */ |
| 1917 | if (bta_dm_search_cb.services == BTA_ALL_SERVICE_MASK) { |
| 1918 | LOG_INFO(LOG_TAG, "%s services_to_search=%08x", __func__, |
| 1919 | bta_dm_search_cb.services_to_search); |
| 1920 | if (bta_dm_search_cb.services_to_search & BTA_RES_SERVICE_MASK) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1921 | uuid = Uuid::From16Bit(bta_service_id_to_uuid_lkup_tbl[0]); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1922 | bta_dm_search_cb.services_to_search &= ~BTA_RES_SERVICE_MASK; |
| 1923 | } else { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1924 | uuid = Uuid::From16Bit(UUID_PROTOCOL_L2CAP); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1925 | bta_dm_search_cb.services_to_search = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1926 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1927 | } else { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1928 | /* for LE only profile */ |
| 1929 | if (bta_dm_search_cb.service_index == BTA_BLE_SERVICE_ID) { |
| 1930 | if (bta_dm_search_cb.uuid_to_search > 0 && |
| 1931 | bta_dm_search_cb.p_srvc_uuid) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1932 | uuid = *(bta_dm_search_cb.p_srvc_uuid + bta_dm_search_cb.num_uuid - |
| 1933 | bta_dm_search_cb.uuid_to_search); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1934 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1935 | bta_dm_search_cb.uuid_to_search--; |
| 1936 | } else { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1937 | uuid = Uuid::From16Bit( |
| 1938 | bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb |
| 1939 | .service_index]); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | /* last one? clear the BLE service bit if all discovery has been done |
| 1943 | */ |
| 1944 | if (bta_dm_search_cb.uuid_to_search == 0) |
| 1945 | bta_dm_search_cb.services_to_search &= |
| 1946 | (tBTA_SERVICE_MASK)(~(BTA_SERVICE_ID_TO_SERVICE_MASK( |
| 1947 | bta_dm_search_cb.service_index))); |
| 1948 | |
Myles Watson | 9979121 | 2016-11-18 08:42:23 -0800 | [diff] [blame] | 1949 | } else { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1950 | /* remove the service from services to be searched */ |
| 1951 | bta_dm_search_cb.services_to_search &= (tBTA_SERVICE_MASK)(~( |
| 1952 | BTA_SERVICE_ID_TO_SERVICE_MASK(bta_dm_search_cb.service_index))); |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1953 | uuid = Uuid::From16Bit( |
| 1954 | bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index]); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1955 | } |
| 1956 | } |
| 1957 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1958 | if (bta_dm_search_cb.service_index == BTA_USER_SERVICE_ID) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1959 | uuid = bta_dm_search_cb.uuid; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1960 | } |
| 1961 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 1962 | LOG_INFO(LOG_TAG, "%s search UUID = %s", __func__, |
| 1963 | uuid.ToString().c_str()); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1964 | SDP_InitDiscoveryDb(bta_dm_search_cb.p_sdp_db, BTA_DM_SDP_DB_SIZE, 1, |
| 1965 | &uuid, 0, NULL); |
| 1966 | |
| 1967 | memset(g_disc_raw_data_buf, 0, sizeof(g_disc_raw_data_buf)); |
| 1968 | bta_dm_search_cb.p_sdp_db->raw_data = g_disc_raw_data_buf; |
| 1969 | |
| 1970 | bta_dm_search_cb.p_sdp_db->raw_size = MAX_DISC_RAW_DATA_BUF; |
| 1971 | |
Jakub Pawlowski | 135b7f6 | 2017-06-16 10:00:46 -0700 | [diff] [blame] | 1972 | if (!SDP_ServiceSearchAttributeRequest(bd_addr, bta_dm_search_cb.p_sdp_db, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1973 | &bta_dm_sdp_callback)) { |
| 1974 | /* |
| 1975 | * If discovery is not successful with this device, then |
| 1976 | * proceed with the next one. |
| 1977 | */ |
| 1978 | osi_free_and_reset((void**)&bta_dm_search_cb.p_sdp_db); |
| 1979 | bta_dm_search_cb.service_index = BTA_MAX_SERVICE_ID; |
| 1980 | |
| 1981 | } else { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1982 | if ((bta_dm_search_cb.service_index == BTA_BLE_SERVICE_ID && |
| 1983 | bta_dm_search_cb.uuid_to_search == 0) || |
| 1984 | bta_dm_search_cb.service_index != BTA_BLE_SERVICE_ID) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1985 | bta_dm_search_cb.service_index++; |
| 1986 | return; |
| 1987 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1988 | } |
| 1989 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1990 | bta_dm_search_cb.service_index++; |
| 1991 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1992 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1993 | /* no more services to be discovered */ |
| 1994 | if (bta_dm_search_cb.service_index >= BTA_MAX_SERVICE_ID) { |
| 1995 | 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] | 1996 | /* initialize the data structure - includes p_raw_data and raw_data_size */ |
| 1997 | memset(&(p_msg->disc_result.result), 0, sizeof(tBTA_DM_DISC_RES)); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 1998 | p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT; |
| 1999 | p_msg->disc_result.result.disc_res.services = |
| 2000 | bta_dm_search_cb.services_found; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2001 | 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] | 2002 | strlcpy((char*)p_msg->disc_result.result.disc_res.bd_name, |
| 2003 | bta_dm_get_remname(), BD_NAME_LEN); |
| 2004 | |
| 2005 | bta_sys_sendmsg(p_msg); |
| 2006 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2007 | } |
| 2008 | |
| 2009 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2010 | * |
| 2011 | * Function bta_dm_discover_next_device |
| 2012 | * |
| 2013 | * Description Starts discovery on the next device in Inquiry data base |
| 2014 | * |
| 2015 | * Returns void |
| 2016 | * |
| 2017 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2018 | static void bta_dm_discover_next_device(void) { |
| 2019 | APPL_TRACE_DEBUG("bta_dm_discover_next_device"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2020 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2021 | /* searching next device on inquiry result */ |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame] | 2022 | bta_dm_search_cb.p_btm_inq_info = |
| 2023 | BTM_InqDbNext(bta_dm_search_cb.p_btm_inq_info); |
| 2024 | if (bta_dm_search_cb.p_btm_inq_info != NULL) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2025 | bta_dm_search_cb.name_discover_done = false; |
| 2026 | bta_dm_search_cb.peer_name[0] = 0; |
| 2027 | bta_dm_discover_device( |
| 2028 | bta_dm_search_cb.p_btm_inq_info->results.remote_bd_addr); |
| 2029 | } else { |
| 2030 | 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] | 2031 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2032 | /* no devices, search complete */ |
| 2033 | bta_dm_search_cb.services = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2034 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2035 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 2036 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2037 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2038 | bta_sys_sendmsg(p_msg); |
| 2039 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2043 | * |
| 2044 | * Function bta_dm_discover_device |
| 2045 | * |
| 2046 | * Description Starts name and service discovery on the device |
| 2047 | * |
| 2048 | * Returns void |
| 2049 | * |
| 2050 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 2051 | static void bta_dm_discover_device(const RawAddress& remote_bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2052 | tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2053 | if (bta_dm_search_cb.transport == BTA_TRANSPORT_UNKNOWN) { |
| 2054 | tBT_DEVICE_TYPE dev_type; |
| 2055 | tBLE_ADDR_TYPE addr_type; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2056 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2057 | BTM_ReadDevInfo(remote_bd_addr, &dev_type, &addr_type); |
| 2058 | if (dev_type == BT_DEVICE_TYPE_BLE || addr_type == BLE_ADDR_RANDOM) |
| 2059 | transport = BT_TRANSPORT_LE; |
| 2060 | } else { |
| 2061 | transport = bta_dm_search_cb.transport; |
| 2062 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2063 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2064 | /* Reset transport state for next discovery */ |
| 2065 | bta_dm_search_cb.transport = BTA_TRANSPORT_UNKNOWN; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2066 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2067 | VLOG(1) << __func__ << " BDA: " << remote_bd_addr; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2068 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2069 | bta_dm_search_cb.peer_bdaddr = remote_bd_addr; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2070 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2071 | APPL_TRACE_DEBUG( |
| 2072 | "%s name_discover_done = %d p_btm_inq_info 0x%x state = %d, transport=%d", |
| 2073 | __func__, bta_dm_search_cb.name_discover_done, |
| 2074 | 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] | 2075 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2076 | if (bta_dm_search_cb.p_btm_inq_info) { |
| 2077 | APPL_TRACE_DEBUG("%s appl_knows_rem_name %d", __func__, |
| 2078 | bta_dm_search_cb.p_btm_inq_info->appl_knows_rem_name); |
| 2079 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2080 | if ((bta_dm_search_cb.p_btm_inq_info) && |
| 2081 | (bta_dm_search_cb.p_btm_inq_info->results.device_type == |
| 2082 | BT_DEVICE_TYPE_BLE) && |
| 2083 | (bta_dm_search_cb.state == BTA_DM_SEARCH_ACTIVE)) { |
| 2084 | /* Do not perform RNR for LE devices at inquiry complete*/ |
| 2085 | bta_dm_search_cb.name_discover_done = true; |
| 2086 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2087 | /* if name discovery is not done and application needs remote name */ |
| 2088 | if ((!bta_dm_search_cb.name_discover_done) && |
| 2089 | ((bta_dm_search_cb.p_btm_inq_info == NULL) || |
| 2090 | (bta_dm_search_cb.p_btm_inq_info && |
| 2091 | (!bta_dm_search_cb.p_btm_inq_info->appl_knows_rem_name)))) { |
Myles Watson | 5d5fcf2 | 2017-10-06 16:51:21 -0700 | [diff] [blame] | 2092 | if (bta_dm_read_remote_device_name(bta_dm_search_cb.peer_bdaddr, transport)) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2093 | return; |
Nitin Arora | b4365c5 | 2015-06-25 18:30:09 -0700 | [diff] [blame] | 2094 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2095 | /* starting name discovery failed */ |
| 2096 | bta_dm_search_cb.name_discover_done = true; |
| 2097 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2098 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2099 | /* if application wants to discover service */ |
| 2100 | if (bta_dm_search_cb.services) { |
| 2101 | /* initialize variables */ |
| 2102 | bta_dm_search_cb.service_index = 0; |
| 2103 | bta_dm_search_cb.services_found = 0; |
| 2104 | bta_dm_search_cb.services_to_search = bta_dm_search_cb.services; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2105 | 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] | 2106 | if ((bta_dm_search_cb.p_btm_inq_info != NULL) && |
| 2107 | bta_dm_search_cb.services != BTA_USER_SERVICE_MASK && |
Myles Watson | 5d5fcf2 | 2017-10-06 16:51:21 -0700 | [diff] [blame] | 2108 | (!bta_dm_search_cb.sdp_search)) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2109 | /* check if EIR provides the information of supported services */ |
| 2110 | bta_dm_eir_search_services(&bta_dm_search_cb.p_btm_inq_info->results, |
| 2111 | &bta_dm_search_cb.services_to_search, |
| 2112 | &bta_dm_search_cb.services_found); |
| 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 seaching with EIR is not completed */ |
| 2116 | if (bta_dm_search_cb.services_to_search) { |
| 2117 | /* check whether connection already exists to the device |
| 2118 | if connection exists, we don't have to wait for ACL |
| 2119 | link to go down to start search on next device */ |
| 2120 | if (BTM_IsAclConnectionUp(bta_dm_search_cb.peer_bdaddr, |
| 2121 | BT_TRANSPORT_BR_EDR)) |
| 2122 | bta_dm_search_cb.wait_disc = false; |
| 2123 | else |
| 2124 | bta_dm_search_cb.wait_disc = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2125 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2126 | if (bta_dm_search_cb.p_btm_inq_info) { |
| 2127 | APPL_TRACE_DEBUG( |
| 2128 | "%s p_btm_inq_info 0x%x results.device_type 0x%x " |
| 2129 | "services_to_search 0x%x", |
| 2130 | __func__, bta_dm_search_cb.p_btm_inq_info, |
| 2131 | bta_dm_search_cb.p_btm_inq_info->results.device_type, |
| 2132 | bta_dm_search_cb.services_to_search); |
| 2133 | } |
Chaojing Sun | e280553 | 2015-04-22 13:40:21 -0700 | [diff] [blame] | 2134 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2135 | if (transport == BT_TRANSPORT_LE) { |
| 2136 | if (bta_dm_search_cb.services_to_search & BTA_BLE_SERVICE_MASK) { |
| 2137 | // set the raw data buffer here |
| 2138 | memset(g_disc_raw_data_buf, 0, sizeof(g_disc_raw_data_buf)); |
| 2139 | 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] | 2140 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2141 | bta_dm_search_cb.ble_raw_size = MAX_DISC_RAW_DATA_BUF; |
| 2142 | bta_dm_search_cb.ble_raw_used = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2143 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2144 | /* start GATT for service discovery */ |
| 2145 | btm_dm_start_gatt_discovery(bta_dm_search_cb.peer_bdaddr); |
| 2146 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2147 | } |
Myles Watson | 9979121 | 2016-11-18 08:42:23 -0800 | [diff] [blame] | 2148 | } else { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2149 | bta_dm_search_cb.sdp_results = false; |
| 2150 | bta_dm_find_services(bta_dm_search_cb.peer_bdaddr); |
| 2151 | return; |
| 2152 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2153 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2154 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2155 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2156 | /* name discovery and service discovery are done for this device */ |
| 2157 | tBTA_DM_MSG* p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
| 2158 | p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT; |
| 2159 | /* initialize the data structure - includes p_raw_data and raw_data_size */ |
| 2160 | memset(&(p_msg->disc_result.result), 0, sizeof(tBTA_DM_DISC_RES)); |
| 2161 | p_msg->disc_result.result.disc_res.result = BTA_SUCCESS; |
| 2162 | 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] | 2163 | 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] | 2164 | strlcpy((char*)p_msg->disc_result.result.disc_res.bd_name, |
| 2165 | (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] | 2166 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2167 | bta_sys_sendmsg(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2171 | * |
| 2172 | * Function bta_dm_sdp_callback |
| 2173 | * |
| 2174 | * Description Callback from sdp with discovery status |
| 2175 | * |
| 2176 | * Returns void |
| 2177 | * |
| 2178 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2179 | static void bta_dm_sdp_callback(uint16_t sdp_status) { |
| 2180 | tBTA_DM_SDP_RESULT* p_msg = |
| 2181 | (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] | 2182 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2183 | p_msg->hdr.event = BTA_DM_SDP_RESULT_EVT; |
| 2184 | p_msg->sdp_result = sdp_status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2185 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2186 | bta_sys_sendmsg(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2190 | * |
| 2191 | * Function bta_dm_inq_results_cb |
| 2192 | * |
| 2193 | * Description Inquiry results callback from BTM |
| 2194 | * |
| 2195 | * Returns void |
| 2196 | * |
| 2197 | ******************************************************************************/ |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 2198 | 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] | 2199 | uint16_t eir_len) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2200 | tBTA_DM_SEARCH result; |
| 2201 | tBTM_INQ_INFO* p_inq_info; |
| 2202 | uint16_t service_class; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2203 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2204 | result.inq_res.bd_addr = p_inq->remote_bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2205 | memcpy(result.inq_res.dev_class, p_inq->dev_class, DEV_CLASS_LEN); |
| 2206 | BTM_COD_SERVICE_CLASS(service_class, p_inq->dev_class); |
| 2207 | result.inq_res.is_limited = |
| 2208 | (service_class & BTM_COD_SERVICE_LMTD_DISCOVER) ? true : false; |
| 2209 | result.inq_res.rssi = p_inq->rssi; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2210 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2211 | result.inq_res.ble_addr_type = p_inq->ble_addr_type; |
| 2212 | result.inq_res.inq_result_type = p_inq->inq_result_type; |
| 2213 | result.inq_res.device_type = p_inq->device_type; |
| 2214 | result.inq_res.flag = p_inq->flag; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2215 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2216 | /* application will parse EIR to find out remote device name */ |
| 2217 | result.inq_res.p_eir = p_eir; |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 2218 | result.inq_res.eir_len = eir_len; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2219 | |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame] | 2220 | p_inq_info = BTM_InqDbRead(p_inq->remote_bd_addr); |
| 2221 | if (p_inq_info != NULL) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2222 | /* initialize remt_name_not_required to false so that we get the name by |
| 2223 | * default */ |
| 2224 | result.inq_res.remt_name_not_required = false; |
| 2225 | } |
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 | if (bta_dm_search_cb.p_search_cback) |
| 2228 | 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] | 2229 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2230 | if (p_inq_info) { |
| 2231 | /* application indicates if it knows the remote name, inside the callback |
| 2232 | copy that to the inquiry data base*/ |
| 2233 | if (result.inq_res.remt_name_not_required) |
| 2234 | p_inq_info->appl_knows_rem_name = true; |
| 2235 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2236 | } |
| 2237 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2238 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2239 | * |
| 2240 | * Function bta_dm_inq_cmpl_cb |
| 2241 | * |
| 2242 | * Description Inquiry complete callback from BTM |
| 2243 | * |
| 2244 | * Returns void |
| 2245 | * |
| 2246 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2247 | static void bta_dm_inq_cmpl_cb(void* p_result) { |
| 2248 | 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] | 2249 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2250 | APPL_TRACE_DEBUG("%s", __func__); |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2251 | |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 2252 | if (!bta_dm_search_cb.cancel_pending) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2253 | p_msg->inq_cmpl.hdr.event = BTA_DM_INQUIRY_CMPL_EVT; |
| 2254 | p_msg->inq_cmpl.num = ((tBTM_INQUIRY_CMPL*)p_result)->num_resp; |
| 2255 | } else { |
| 2256 | bta_dm_search_cb.cancel_pending = false; |
| 2257 | bta_dm_search_cancel_notify(NULL); |
| 2258 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 2259 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 2260 | } |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2261 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2262 | bta_sys_sendmsg(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2266 | * |
| 2267 | * Function bta_dm_service_search_remname_cback |
| 2268 | * |
| 2269 | * Description Remote name call back from BTM during service discovery |
| 2270 | * |
| 2271 | * Returns void |
| 2272 | * |
| 2273 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 2274 | static void bta_dm_service_search_remname_cback(const RawAddress& bd_addr, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2275 | UNUSED_ATTR DEV_CLASS dc, |
| 2276 | BD_NAME bd_name) { |
| 2277 | tBTM_REMOTE_DEV_NAME rem_name; |
| 2278 | tBTM_STATUS btm_status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2279 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2280 | APPL_TRACE_DEBUG("%s name=<%s>", __func__, bd_name); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2281 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2282 | /* if this is what we are looking for */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2283 | if (bta_dm_search_cb.peer_bdaddr == bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2284 | rem_name.length = strlen((char*)bd_name); |
| 2285 | if (rem_name.length > (BD_NAME_LEN - 1)) { |
| 2286 | rem_name.length = (BD_NAME_LEN - 1); |
| 2287 | 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] | 2288 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2289 | strlcpy((char*)rem_name.remote_bd_name, (char*)bd_name, BD_NAME_LEN); |
| 2290 | rem_name.status = BTM_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2291 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2292 | bta_dm_remname_cback(&rem_name); |
| 2293 | } else { |
| 2294 | /* get name of device */ |
| 2295 | btm_status = BTM_ReadRemoteDeviceName(bta_dm_search_cb.peer_bdaddr, |
| 2296 | (tBTM_CMPL_CB*)bta_dm_remname_cback, |
| 2297 | BT_TRANSPORT_BR_EDR); |
| 2298 | if (btm_status == BTM_BUSY) { |
| 2299 | /* wait for next chance(notification of remote name discovery done) */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2300 | APPL_TRACE_DEBUG("%s: BTM_ReadRemoteDeviceName is busy", __func__); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2301 | } else if (btm_status != BTM_CMD_STARTED) { |
| 2302 | /* if failed to start getting remote name then continue */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2303 | APPL_TRACE_WARNING("%s: BTM_ReadRemoteDeviceName returns 0x%02X", |
| 2304 | __func__, btm_status); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2305 | |
| 2306 | rem_name.length = 0; |
| 2307 | rem_name.remote_bd_name[0] = 0; |
| 2308 | rem_name.status = btm_status; |
| 2309 | bta_dm_remname_cback(&rem_name); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2310 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2311 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2312 | } |
| 2313 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2314 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2315 | * |
| 2316 | * Function bta_dm_remname_cback |
| 2317 | * |
| 2318 | * Description Remote name complete call back from BTM |
| 2319 | * |
| 2320 | * Returns void |
| 2321 | * |
| 2322 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2323 | static void bta_dm_remname_cback(tBTM_REMOTE_DEV_NAME* p_remote_name) { |
| 2324 | APPL_TRACE_DEBUG("bta_dm_remname_cback len = %d name=<%s>", |
| 2325 | 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] | 2326 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2327 | /* remote name discovery is done but it could be failed */ |
| 2328 | bta_dm_search_cb.name_discover_done = true; |
| 2329 | strlcpy((char*)bta_dm_search_cb.peer_name, |
| 2330 | (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] | 2331 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2332 | BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2333 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2334 | if (bta_dm_search_cb.transport == BT_TRANSPORT_LE) { |
| 2335 | GAP_BleReadPeerPrefConnParams(bta_dm_search_cb.peer_bdaddr); |
| 2336 | } |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 2337 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2338 | tBTA_DM_REM_NAME* p_msg = |
| 2339 | (tBTA_DM_REM_NAME*)osi_malloc(sizeof(tBTA_DM_REM_NAME)); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2340 | 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] | 2341 | strlcpy((char*)p_msg->result.disc_res.bd_name, |
| 2342 | (char*)p_remote_name->remote_bd_name, BD_NAME_LEN); |
| 2343 | p_msg->hdr.event = BTA_DM_REMT_NAME_EVT; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2344 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2345 | bta_sys_sendmsg(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2346 | } |
| 2347 | |
| 2348 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2349 | * |
| 2350 | * Function bta_dm_authorize_cback |
| 2351 | * |
| 2352 | * Description cback requesting authorization |
| 2353 | * |
| 2354 | * Returns void |
| 2355 | * |
| 2356 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 2357 | static uint8_t bta_dm_authorize_cback(const RawAddress& bd_addr, |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2358 | DEV_CLASS dev_class, BD_NAME bd_name, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2359 | UNUSED_ATTR uint8_t* service_name, |
| 2360 | uint8_t service_id, |
| 2361 | UNUSED_ATTR bool is_originator) { |
| 2362 | tBTA_DM_SEC sec_event; |
| 2363 | uint8_t index = 1; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2364 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2365 | sec_event.authorize.bd_addr = bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2366 | memcpy(sec_event.authorize.dev_class, dev_class, DEV_CLASS_LEN); |
| 2367 | 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] | 2368 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 2369 | #if (BTA_JV_INCLUDED == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2370 | sec_event.authorize.service = service_id; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2371 | #endif |
| 2372 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2373 | while (index < BTA_MAX_SERVICE_ID) { |
| 2374 | /* get the BTA service id corresponding to BTM id */ |
| 2375 | if (bta_service_id_to_btm_srv_id_lkup_tbl[index] == service_id) { |
| 2376 | sec_event.authorize.service = index; |
| 2377 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2378 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2379 | index++; |
| 2380 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2381 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2382 | /* if supported service callback otherwise not authorized */ |
| 2383 | if (bta_dm_cb.p_sec_cback && (index < BTA_MAX_SERVICE_ID |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 2384 | #if (BTA_JV_INCLUDED == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2385 | /* pass through JV service ID */ |
| 2386 | || (service_id >= BTA_FIRST_JV_SERVICE_ID && |
| 2387 | service_id <= BTA_LAST_JV_SERVICE_ID) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2388 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2389 | )) { |
| 2390 | bta_dm_cb.p_sec_cback(BTA_DM_AUTHORIZE_EVT, &sec_event); |
| 2391 | return BTM_CMD_STARTED; |
| 2392 | } else { |
| 2393 | return BTM_NOT_AUTHORIZED; |
| 2394 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2395 | } |
| 2396 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2397 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2398 | * |
| 2399 | * Function bta_dm_pinname_cback |
| 2400 | * |
| 2401 | * Description Callback requesting pin_key |
| 2402 | * |
| 2403 | * Returns void |
| 2404 | * |
| 2405 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2406 | static void bta_dm_pinname_cback(void* p_data) { |
| 2407 | tBTM_REMOTE_DEV_NAME* p_result = (tBTM_REMOTE_DEV_NAME*)p_data; |
| 2408 | tBTA_DM_SEC sec_event; |
| 2409 | uint32_t bytes_to_copy; |
| 2410 | 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] | 2411 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2412 | if (BTA_DM_SP_CFM_REQ_EVT == event) { |
| 2413 | /* Retrieved saved device class and bd_addr */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2414 | sec_event.cfm_req.bd_addr = bta_dm_cb.pin_bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2415 | 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] | 2416 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2417 | if (p_result && p_result->status == BTM_SUCCESS) { |
| 2418 | bytes_to_copy = (p_result->length < (BD_NAME_LEN - 1)) |
| 2419 | ? p_result->length |
| 2420 | : (BD_NAME_LEN - 1); |
| 2421 | memcpy(sec_event.cfm_req.bd_name, p_result->remote_bd_name, |
| 2422 | bytes_to_copy); |
| 2423 | sec_event.pin_req.bd_name[BD_NAME_LEN - 1] = 0; |
| 2424 | } else /* No name found */ |
| 2425 | sec_event.cfm_req.bd_name[0] = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2426 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2427 | sec_event.key_notif.passkey = |
| 2428 | 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] | 2429 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2430 | /* 1 additional event data fields for this event */ |
| 2431 | sec_event.cfm_req.just_works = bta_dm_cb.just_works; |
| 2432 | } else { |
| 2433 | /* Retrieved saved device class and bd_addr */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2434 | sec_event.pin_req.bd_addr = bta_dm_cb.pin_bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2435 | 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] | 2436 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2437 | if (p_result && p_result->status == BTM_SUCCESS) { |
| 2438 | bytes_to_copy = (p_result->length < (BD_NAME_LEN - 1)) |
| 2439 | ? p_result->length |
| 2440 | : (BD_NAME_LEN - 1); |
| 2441 | memcpy(sec_event.pin_req.bd_name, p_result->remote_bd_name, |
| 2442 | bytes_to_copy); |
| 2443 | sec_event.pin_req.bd_name[BD_NAME_LEN - 1] = 0; |
| 2444 | } else /* No name found */ |
| 2445 | sec_event.pin_req.bd_name[0] = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2446 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2447 | event = bta_dm_cb.pin_evt; |
| 2448 | sec_event.key_notif.passkey = |
| 2449 | bta_dm_cb.num_val; /* get PIN code numeric number */ |
| 2450 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2451 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2452 | 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] | 2453 | } |
| 2454 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2455 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2456 | * |
| 2457 | * Function bta_dm_pin_cback |
| 2458 | * |
| 2459 | * Description Callback requesting pin_key |
| 2460 | * |
| 2461 | * Returns void |
| 2462 | * |
| 2463 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 2464 | static uint8_t bta_dm_pin_cback(const RawAddress& bd_addr, DEV_CLASS dev_class, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2465 | BD_NAME bd_name, bool min_16_digit) { |
| 2466 | tBTA_DM_SEC sec_event; |
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) return BTM_NOT_AUTHORIZED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2469 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2470 | /* If the device name is not known, save bdaddr and devclass and initiate a |
| 2471 | * name request */ |
| 2472 | if (bd_name[0] == 0) { |
| 2473 | bta_dm_cb.pin_evt = BTA_DM_PIN_REQ_EVT; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2474 | bta_dm_cb.pin_bd_addr = bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2475 | BTA_COPY_DEVICE_CLASS(bta_dm_cb.pin_dev_class, dev_class); |
| 2476 | if ((BTM_ReadRemoteDeviceName(bd_addr, bta_dm_pinname_cback, |
| 2477 | BT_TRANSPORT_BR_EDR)) == BTM_CMD_STARTED) |
| 2478 | return BTM_CMD_STARTED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2479 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2480 | APPL_TRACE_WARNING( |
| 2481 | " bta_dm_pin_cback() -> Failed to start Remote Name Request "); |
| 2482 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2483 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2484 | sec_event.pin_req.bd_addr = bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2485 | BTA_COPY_DEVICE_CLASS(sec_event.pin_req.dev_class, dev_class); |
| 2486 | strlcpy((char*)sec_event.pin_req.bd_name, (char*)bd_name, BD_NAME_LEN); |
| 2487 | 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] | 2488 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2489 | bta_dm_cb.p_sec_cback(BTA_DM_PIN_REQ_EVT, &sec_event); |
| 2490 | return BTM_CMD_STARTED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2491 | } |
| 2492 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2493 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2494 | * |
| 2495 | * Function bta_dm_new_link_key_cback |
| 2496 | * |
| 2497 | * Description Callback from BTM to notify new link key |
| 2498 | * |
| 2499 | * Returns void |
| 2500 | * |
| 2501 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 2502 | static uint8_t bta_dm_new_link_key_cback(const RawAddress& bd_addr, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2503 | UNUSED_ATTR DEV_CLASS dev_class, |
| 2504 | BD_NAME bd_name, LINK_KEY key, |
| 2505 | uint8_t key_type) { |
| 2506 | tBTA_DM_SEC sec_event; |
| 2507 | tBTA_DM_AUTH_CMPL* p_auth_cmpl; |
| 2508 | uint8_t event; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2509 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2510 | memset(&sec_event, 0, sizeof(tBTA_DM_SEC)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2511 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2512 | /* Not AMP Key type */ |
| 2513 | if (key_type != HCI_LKEY_TYPE_AMP_WIFI && key_type != HCI_LKEY_TYPE_AMP_UWB) { |
| 2514 | event = BTA_DM_AUTH_CMPL_EVT; |
| 2515 | p_auth_cmpl = &sec_event.auth_cmpl; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2516 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2517 | p_auth_cmpl->bd_addr = bd_addr; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2518 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2519 | memcpy(p_auth_cmpl->bd_name, bd_name, (BD_NAME_LEN - 1)); |
| 2520 | 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] | 2521 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2522 | p_auth_cmpl->key_present = true; |
| 2523 | p_auth_cmpl->key_type = key_type; |
| 2524 | p_auth_cmpl->success = true; |
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 | memcpy(p_auth_cmpl->key, key, LINK_KEY_LEN); |
| 2527 | sec_event.auth_cmpl.fail_reason = HCI_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2528 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2529 | // Report the BR link key based on the BR/EDR address and type |
| 2530 | BTM_ReadDevInfo(bd_addr, &sec_event.auth_cmpl.dev_type, |
| 2531 | &sec_event.auth_cmpl.addr_type); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2532 | 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] | 2533 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2534 | // Setting remove_dev_pending flag to false, where it will avoid deleting |
| 2535 | // the |
| 2536 | // security device record when the ACL connection link goes down in case of |
| 2537 | // reconnection. |
| 2538 | if (bta_dm_cb.device_list.count) |
| 2539 | bta_dm_reset_sec_dev_pending(p_auth_cmpl->bd_addr); |
| 2540 | } else { |
| 2541 | APPL_TRACE_WARNING("%s() Received AMP Key", __func__); |
| 2542 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2543 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2544 | return BTM_CMD_STARTED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2545 | } |
| 2546 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2547 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2548 | * |
| 2549 | * Function bta_dm_authentication_complete_cback |
| 2550 | * |
| 2551 | * Description Authentication complete callback from BTM |
| 2552 | * |
| 2553 | * Returns void |
| 2554 | * |
| 2555 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2556 | static uint8_t bta_dm_authentication_complete_cback( |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 2557 | const RawAddress& bd_addr, UNUSED_ATTR DEV_CLASS dev_class, BD_NAME bd_name, |
| 2558 | int result) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2559 | tBTA_DM_SEC sec_event; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2560 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2561 | if (result != BTM_SUCCESS) { |
| 2562 | memset(&sec_event, 0, sizeof(tBTA_DM_SEC)); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2563 | sec_event.auth_cmpl.bd_addr = bd_addr; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2564 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2565 | memcpy(sec_event.auth_cmpl.bd_name, bd_name, (BD_NAME_LEN - 1)); |
| 2566 | 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] | 2567 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2568 | // Report the BR link key based on the BR/EDR address and type |
| 2569 | BTM_ReadDevInfo(bd_addr, &sec_event.auth_cmpl.dev_type, |
| 2570 | &sec_event.auth_cmpl.addr_type); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2571 | sec_event.auth_cmpl.fail_reason = (uint8_t)result; |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 2572 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2573 | if (bta_dm_cb.p_sec_cback) |
| 2574 | 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] | 2575 | |
Andre Eisenbach | 51fb9c0 | 2017-07-19 15:33:07 -0700 | [diff] [blame] | 2576 | if (result == HCI_ERR_AUTH_FAILURE || result == HCI_ERR_KEY_MISSING || |
| 2577 | result == HCI_ERR_HOST_REJECT_SECURITY || |
| 2578 | result == HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE) { |
Andre Eisenbach | f54d7e2 | 2017-07-18 15:13:55 -0700 | [diff] [blame] | 2579 | APPL_TRACE_WARNING("%s deleting %s - result: 0x%02x", __func__, |
| 2580 | bd_addr.ToString().c_str(), result); |
Andre Eisenbach | 1f5ec73 | 2017-04-13 14:49:36 -0700 | [diff] [blame] | 2581 | bta_dm_remove_sec_dev_entry(bd_addr); |
| 2582 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2583 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2584 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2585 | return BTM_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2589 | * |
| 2590 | * Function bta_dm_sp_cback |
| 2591 | * |
| 2592 | * Description simple pairing callback from BTM |
| 2593 | * |
| 2594 | * Returns void |
| 2595 | * |
| 2596 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2597 | static uint8_t bta_dm_sp_cback(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data) { |
| 2598 | tBTM_STATUS status = BTM_CMD_STARTED; |
| 2599 | tBTA_DM_SEC sec_event; |
| 2600 | 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] | 2601 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2602 | APPL_TRACE_EVENT("bta_dm_sp_cback: %d", event); |
| 2603 | 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] | 2604 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2605 | /* TODO_SP */ |
| 2606 | switch (event) { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2607 | case BTM_SP_IO_REQ_EVT: |
Bailey Forrest | 4f77842 | 2017-07-25 19:50:39 -0700 | [diff] [blame] | 2608 | #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2609 | /* translate auth_req */ |
| 2610 | bta_dm_co_io_req(p_data->io_req.bd_addr, &p_data->io_req.io_cap, |
| 2611 | &p_data->io_req.oob_data, &p_data->io_req.auth_req, |
| 2612 | p_data->io_req.is_orig); |
Bailey Forrest | 4f77842 | 2017-07-25 19:50:39 -0700 | [diff] [blame] | 2613 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2614 | APPL_TRACE_EVENT("io mitm: %d oob_data:%d", p_data->io_req.auth_req, |
| 2615 | p_data->io_req.oob_data); |
| 2616 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2617 | case BTM_SP_IO_RSP_EVT: |
Bailey Forrest | 4f77842 | 2017-07-25 19:50:39 -0700 | [diff] [blame] | 2618 | #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2619 | bta_dm_co_io_rsp(p_data->io_rsp.bd_addr, p_data->io_rsp.io_cap, |
| 2620 | p_data->io_rsp.oob_data, p_data->io_rsp.auth_req); |
Bailey Forrest | 4f77842 | 2017-07-25 19:50:39 -0700 | [diff] [blame] | 2621 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2622 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2623 | |
| 2624 | case BTM_SP_CFM_REQ_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2625 | pin_evt = BTA_DM_SP_CFM_REQ_EVT; |
| 2626 | bta_dm_cb.just_works = sec_event.cfm_req.just_works = |
| 2627 | p_data->cfm_req.just_works; |
| 2628 | sec_event.cfm_req.loc_auth_req = p_data->cfm_req.loc_auth_req; |
| 2629 | sec_event.cfm_req.rmt_auth_req = p_data->cfm_req.rmt_auth_req; |
| 2630 | sec_event.cfm_req.loc_io_caps = p_data->cfm_req.loc_io_caps; |
| 2631 | 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] | 2632 | |
Andre Eisenbach | 1f5ec73 | 2017-04-13 14:49:36 -0700 | [diff] [blame] | 2633 | /* continue to next case */ |
Bailey Forrest | 4f77842 | 2017-07-25 19:50:39 -0700 | [diff] [blame] | 2634 | #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2635 | /* Passkey entry mode, mobile device with output capability is very |
| 2636 | unlikely to receive key request, so skip this event */ |
| 2637 | /*case BTM_SP_KEY_REQ_EVT: */ |
| 2638 | case BTM_SP_KEY_NOTIF_EVT: |
Bailey Forrest | 4f77842 | 2017-07-25 19:50:39 -0700 | [diff] [blame] | 2639 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2640 | bta_dm_cb.num_val = sec_event.key_notif.passkey = |
| 2641 | p_data->key_notif.passkey; |
Jack He | db76fa4 | 2016-11-01 11:30:51 -0700 | [diff] [blame] | 2642 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2643 | if (BTM_SP_CFM_REQ_EVT == event) { |
| 2644 | /* Due to the switch case falling through below to BTM_SP_KEY_NOTIF_EVT, |
| 2645 | call remote name request using values from cfm_req */ |
| 2646 | if (p_data->cfm_req.bd_name[0] == 0) { |
| 2647 | bta_dm_cb.pin_evt = pin_evt; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2648 | bta_dm_cb.pin_bd_addr = p_data->cfm_req.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2649 | BTA_COPY_DEVICE_CLASS(bta_dm_cb.pin_dev_class, |
| 2650 | p_data->cfm_req.dev_class); |
| 2651 | if ((BTM_ReadRemoteDeviceName( |
| 2652 | p_data->cfm_req.bd_addr, bta_dm_pinname_cback, |
| 2653 | BT_TRANSPORT_BR_EDR)) == BTM_CMD_STARTED) |
| 2654 | return BTM_CMD_STARTED; |
| 2655 | APPL_TRACE_WARNING( |
| 2656 | " bta_dm_sp_cback() -> Failed to start Remote Name Request "); |
| 2657 | } else { |
| 2658 | /* Due to the switch case falling through below to |
| 2659 | BTM_SP_KEY_NOTIF_EVT, |
| 2660 | copy these values into key_notif from cfm_req */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2661 | sec_event.key_notif.bd_addr = p_data->cfm_req.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2662 | BTA_COPY_DEVICE_CLASS(sec_event.key_notif.dev_class, |
| 2663 | p_data->cfm_req.dev_class); |
| 2664 | strlcpy((char*)sec_event.key_notif.bd_name, |
| 2665 | (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] | 2666 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2667 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2668 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2669 | if (BTM_SP_KEY_NOTIF_EVT == event) { |
| 2670 | /* If the device name is not known, save bdaddr and devclass |
| 2671 | and initiate a name request with values from key_notif */ |
| 2672 | if (p_data->key_notif.bd_name[0] == 0) { |
| 2673 | bta_dm_cb.pin_evt = pin_evt; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2674 | bta_dm_cb.pin_bd_addr = p_data->key_notif.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2675 | BTA_COPY_DEVICE_CLASS(bta_dm_cb.pin_dev_class, |
| 2676 | p_data->key_notif.dev_class); |
| 2677 | if ((BTM_ReadRemoteDeviceName( |
| 2678 | p_data->key_notif.bd_addr, bta_dm_pinname_cback, |
| 2679 | BT_TRANSPORT_BR_EDR)) == BTM_CMD_STARTED) |
| 2680 | return BTM_CMD_STARTED; |
| 2681 | APPL_TRACE_WARNING( |
| 2682 | " bta_dm_sp_cback() -> Failed to start Remote Name Request "); |
| 2683 | } else { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2684 | sec_event.key_notif.bd_addr = p_data->key_notif.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2685 | BTA_COPY_DEVICE_CLASS(sec_event.key_notif.dev_class, |
| 2686 | p_data->key_notif.dev_class); |
| 2687 | strlcpy((char*)sec_event.key_notif.bd_name, |
| 2688 | (char*)p_data->key_notif.bd_name, BD_NAME_LEN); |
| 2689 | sec_event.key_notif.bd_name[BD_NAME_LEN - 1] = 0; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2690 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2691 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2692 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2693 | 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] | 2694 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2695 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2696 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2697 | case BTM_SP_LOC_OOB_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2698 | bta_dm_co_loc_oob((bool)(p_data->loc_oob.status == BTM_SUCCESS), |
| 2699 | p_data->loc_oob.c, p_data->loc_oob.r); |
| 2700 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2701 | |
| 2702 | case BTM_SP_RMT_OOB_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2703 | /* If the device name is not known, save bdaddr and devclass and initiate |
| 2704 | * a name request */ |
| 2705 | if (p_data->rmt_oob.bd_name[0] == 0) { |
| 2706 | bta_dm_cb.pin_evt = BTA_DM_SP_RMT_OOB_EVT; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2707 | bta_dm_cb.pin_bd_addr = p_data->rmt_oob.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2708 | BTA_COPY_DEVICE_CLASS(bta_dm_cb.pin_dev_class, |
| 2709 | p_data->rmt_oob.dev_class); |
| 2710 | if ((BTM_ReadRemoteDeviceName(p_data->rmt_oob.bd_addr, |
| 2711 | bta_dm_pinname_cback, |
| 2712 | BT_TRANSPORT_BR_EDR)) == BTM_CMD_STARTED) |
| 2713 | return BTM_CMD_STARTED; |
| 2714 | APPL_TRACE_WARNING( |
| 2715 | " bta_dm_sp_cback() -> Failed to start Remote Name Request "); |
| 2716 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2717 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2718 | sec_event.rmt_oob.bd_addr = p_data->rmt_oob.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2719 | BTA_COPY_DEVICE_CLASS(sec_event.rmt_oob.dev_class, |
| 2720 | p_data->rmt_oob.dev_class); |
| 2721 | strlcpy((char*)sec_event.rmt_oob.bd_name, (char*)p_data->rmt_oob.bd_name, |
| 2722 | BD_NAME_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2723 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2724 | 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] | 2725 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2726 | bta_dm_co_rmt_oob(p_data->rmt_oob.bd_addr); |
| 2727 | break; |
Jakub Pawlowski | 175da70 | 2015-11-12 15:00:58 -0800 | [diff] [blame] | 2728 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2729 | case BTM_SP_COMPLT_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2730 | /* do not report this event - handled by link_key_callback or |
| 2731 | * auth_complete_callback */ |
| 2732 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2733 | |
| 2734 | case BTM_SP_KEYPRESS_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2735 | memcpy(&sec_event.key_press, &p_data->key_press, |
| 2736 | sizeof(tBTM_SP_KEYPRESS)); |
| 2737 | bta_dm_cb.p_sec_cback(BTA_DM_SP_KEYPRESS_EVT, &sec_event); |
| 2738 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2739 | |
| 2740 | case BTM_SP_UPGRADE_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2741 | bta_dm_co_lk_upgrade(p_data->upgrade.bd_addr, &p_data->upgrade.upgrade); |
| 2742 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2743 | |
| 2744 | default: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2745 | status = BTM_NOT_AUTHORIZED; |
| 2746 | break; |
| 2747 | } |
| 2748 | APPL_TRACE_EVENT("dm status: %d", status); |
| 2749 | return status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2753 | * |
| 2754 | * Function bta_dm_local_name_cback |
| 2755 | * |
| 2756 | * Description Callback from btm after local name is read |
| 2757 | * |
| 2758 | * |
| 2759 | * Returns void |
| 2760 | * |
| 2761 | ******************************************************************************/ |
Vishwath Mohan | 325abcf | 2017-11-08 22:45:47 -0800 | [diff] [blame^] | 2762 | static void bta_dm_local_name_cback(UNUSED_ATTR void* p_name) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2763 | tBTA_DM_SEC sec_event; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2764 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2765 | sec_event.enable.status = BTA_SUCCESS; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2766 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2767 | if (bta_dm_cb.p_sec_cback) |
| 2768 | 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] | 2769 | } |
| 2770 | |
| 2771 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2772 | * |
| 2773 | * Function bta_dm_bl_change_cback |
| 2774 | * |
| 2775 | * Description Callback from btm when acl connection goes up or down |
| 2776 | * |
| 2777 | * |
| 2778 | * Returns void |
| 2779 | * |
| 2780 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2781 | static void bta_dm_bl_change_cback(tBTM_BL_EVENT_DATA* p_data) { |
| 2782 | tBTA_DM_ACL_CHANGE* p_msg = |
| 2783 | (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] | 2784 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2785 | p_msg->event = p_data->event; |
| 2786 | p_msg->is_new = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2787 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2788 | switch (p_msg->event) { |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2789 | case BTM_BL_CONN_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2790 | p_msg->is_new = true; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2791 | p_msg->bd_addr = *p_data->conn.p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2792 | p_msg->transport = p_data->conn.transport; |
| 2793 | p_msg->handle = p_data->conn.handle; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2794 | break; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2795 | case BTM_BL_DISCN_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2796 | p_msg->bd_addr = *p_data->discn.p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2797 | p_msg->transport = p_data->discn.transport; |
| 2798 | p_msg->handle = p_data->discn.handle; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2799 | break; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2800 | case BTM_BL_UPDATE_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2801 | p_msg->busy_level = p_data->update.busy_level; |
| 2802 | p_msg->busy_level_flags = p_data->update.busy_level_flags; |
| 2803 | break; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2804 | case BTM_BL_ROLE_CHG_EVT: |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2805 | p_msg->new_role = p_data->role_chg.new_role; |
| 2806 | p_msg->hci_status = p_data->role_chg.hci_status; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2807 | p_msg->bd_addr = *p_data->role_chg.p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2808 | break; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 2809 | case BTM_BL_COLLISION_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2810 | p_msg->bd_addr = *p_data->conn.p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2811 | break; |
| 2812 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2813 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2814 | p_msg->hdr.event = BTA_DM_ACL_CHANGE_EVT; |
| 2815 | bta_sys_sendmsg(p_msg); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2816 | } |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 2817 | |
| 2818 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2819 | * |
| 2820 | * Function bta_dm_rs_cback |
| 2821 | * |
| 2822 | * Description Receives the role switch complete event |
| 2823 | * |
| 2824 | * Returns |
| 2825 | * |
| 2826 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2827 | static void bta_dm_rs_cback(UNUSED_ATTR tBTM_ROLE_SWITCH_CMPL* p1) { |
| 2828 | APPL_TRACE_WARNING("bta_dm_rs_cback:%d", bta_dm_cb.rs_event); |
| 2829 | if (bta_dm_cb.rs_event == BTA_DM_API_SEARCH_EVT) { |
| 2830 | bta_dm_cb.search_msg.rs_res = |
| 2831 | BTA_DM_RS_OK; /* do not care about the result for now */ |
| 2832 | bta_dm_cb.rs_event = 0; |
| 2833 | bta_dm_search_start((tBTA_DM_MSG*)&bta_dm_cb.search_msg); |
| 2834 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2838 | * |
| 2839 | * Function bta_dm_check_av |
| 2840 | * |
| 2841 | * Description This function checks if AV is active |
| 2842 | * if yes, make sure the AV link is master |
| 2843 | * |
| 2844 | * Returns bool - true, if switch is in progress |
| 2845 | * |
| 2846 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2847 | static bool bta_dm_check_av(uint16_t event) { |
| 2848 | bool avoid_roleswitch = false; |
| 2849 | bool switching = false; |
| 2850 | uint8_t i; |
| 2851 | tBTA_DM_PEER_DEVICE* p_dev; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2852 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 2853 | #if (BTA_DM_AVOID_A2DP_ROLESWITCH_ON_INQUIRY == TRUE) |
Mattias Agren | 9647e91 | 2013-04-08 12:23:42 +0200 | [diff] [blame] | 2854 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2855 | /* avoid role switch upon inquiry if a2dp is actively streaming as it |
| 2856 | introduces an audioglitch due to FW scheduling delays (unavoidable) */ |
| 2857 | if (event == BTA_DM_API_SEARCH_EVT) { |
| 2858 | avoid_roleswitch = true; |
| 2859 | } |
Mattias Agren | 9647e91 | 2013-04-08 12:23:42 +0200 | [diff] [blame] | 2860 | #endif |
| 2861 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2862 | APPL_TRACE_WARNING("bta_dm_check_av:%d", bta_dm_cb.cur_av_count); |
| 2863 | if (bta_dm_cb.cur_av_count) { |
| 2864 | for (i = 0; i < bta_dm_cb.device_list.count; i++) { |
| 2865 | p_dev = &bta_dm_cb.device_list.peer_device[i]; |
| 2866 | APPL_TRACE_WARNING("[%d]: state:%d, info:x%x, avoid_rs %d", i, |
| 2867 | p_dev->conn_state, p_dev->info, avoid_roleswitch); |
| 2868 | if ((p_dev->conn_state == BTA_DM_CONNECTED) && |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 2869 | (p_dev->info & BTA_DM_DI_AV_ACTIVE) && (!avoid_roleswitch)) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2870 | /* make master and take away the role switch policy */ |
| 2871 | if (BTM_CMD_STARTED == BTM_SwitchRole(p_dev->peer_bdaddr, |
| 2872 | HCI_ROLE_MASTER, |
| 2873 | (tBTM_CMPL_CB*)bta_dm_rs_cback)) { |
| 2874 | /* the role switch command is actually sent */ |
| 2875 | bta_dm_cb.rs_event = event; |
| 2876 | switching = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2877 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2878 | /* else either already master or can not switch for some reasons */ |
| 2879 | bta_dm_policy_cback(BTA_SYS_PLCY_CLR, 0, HCI_ENABLE_MASTER_SLAVE_SWITCH, |
Jakub Pawlowski | 78b81c6 | 2017-06-16 13:55:52 -0700 | [diff] [blame] | 2880 | &p_dev->peer_bdaddr); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2881 | break; |
| 2882 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2883 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2884 | } |
| 2885 | return switching; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 2889 | * |
| 2890 | * Function bta_dm_acl_change |
| 2891 | * |
| 2892 | * Description Process BTA_DM_ACL_CHANGE_EVT |
| 2893 | * |
| 2894 | * |
| 2895 | * Returns void |
| 2896 | * |
| 2897 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2898 | void bta_dm_acl_change(tBTA_DM_MSG* p_data) { |
| 2899 | uint8_t i; |
| 2900 | uint8_t* p; |
| 2901 | tBTA_DM_SEC conn; |
| 2902 | bool is_new = p_data->acl_change.is_new; |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 2903 | const RawAddress& p_bda = p_data->acl_change.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2904 | bool need_policy_change = false; |
| 2905 | bool issue_unpair_cb = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2906 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2907 | tBTA_DM_PEER_DEVICE* p_dev; |
| 2908 | memset(&conn, 0, sizeof(tBTA_DM_SEC)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2909 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2910 | switch (p_data->acl_change.event) { |
| 2911 | case BTM_BL_UPDATE_EVT: /* busy level update */ |
| 2912 | if (bta_dm_cb.p_sec_cback) { |
| 2913 | conn.busy_level.level = p_data->acl_change.busy_level; |
| 2914 | conn.busy_level.level_flags = p_data->acl_change.busy_level_flags; |
| 2915 | bta_dm_cb.p_sec_cback(BTA_DM_BUSY_LEVEL_EVT, &conn); |
| 2916 | } |
| 2917 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2918 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2919 | case BTM_BL_ROLE_CHG_EVT: /* role change event */ |
| 2920 | p_dev = bta_dm_find_peer_device(p_bda); |
| 2921 | if (p_dev) { |
| 2922 | APPL_TRACE_DEBUG( |
| 2923 | "bta_dm_acl_change role chg info:x%x new_role:%d dev count:%d", |
| 2924 | p_dev->info, p_data->acl_change.new_role, |
| 2925 | bta_dm_cb.device_list.count); |
| 2926 | if (p_dev->info & BTA_DM_DI_AV_ACTIVE) { |
| 2927 | /* there's AV activity on this link */ |
| 2928 | if (p_data->acl_change.new_role == HCI_ROLE_SLAVE && |
| 2929 | bta_dm_cb.device_list.count > 1 && |
| 2930 | p_data->acl_change.hci_status == HCI_SUCCESS) { |
| 2931 | /* more than one connections and the AV connection is role switched |
| 2932 | * to slave |
| 2933 | * switch it back to master and remove the switch policy */ |
| 2934 | BTM_SwitchRole(p_bda, BTM_ROLE_MASTER, NULL); |
| 2935 | need_policy_change = true; |
| 2936 | } else if (p_bta_dm_cfg->avoid_scatter && |
| 2937 | (p_data->acl_change.new_role == HCI_ROLE_MASTER)) { |
| 2938 | /* if the link updated to be master include AV activities, remove |
| 2939 | * the switch policy */ |
| 2940 | need_policy_change = true; |
| 2941 | } |
| 2942 | |
| 2943 | if (need_policy_change) { |
| 2944 | bta_dm_policy_cback(BTA_SYS_PLCY_CLR, 0, |
| 2945 | HCI_ENABLE_MASTER_SLAVE_SWITCH, |
Jakub Pawlowski | 78b81c6 | 2017-06-16 13:55:52 -0700 | [diff] [blame] | 2946 | &p_dev->peer_bdaddr); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2947 | } |
| 2948 | } else { |
| 2949 | /* there's AV no activity on this link and role switch happened |
| 2950 | * check if AV is active |
| 2951 | * if so, make sure the AV link is master */ |
| 2952 | bta_dm_check_av(0); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2953 | } |
Jakub Pawlowski | c752e13 | 2017-06-16 12:52:23 -0700 | [diff] [blame] | 2954 | bta_sys_notify_role_chg(p_data->acl_change.bd_addr, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2955 | p_data->acl_change.new_role, |
| 2956 | p_data->acl_change.hci_status); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2957 | conn.role_chg.bd_addr = p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2958 | 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] | 2959 | if (bta_dm_cb.p_sec_cback) |
Myles Watson | 6ef9190 | 2017-10-03 12:35:59 -0700 | [diff] [blame] | 2960 | bta_dm_cb.p_sec_cback(BTA_DM_ROLE_CHG_EVT, &conn); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2961 | } |
| 2962 | return; |
| 2963 | } |
| 2964 | |
| 2965 | /* Collision report from Stack: Notify profiles */ |
| 2966 | if (p_data->acl_change.event == BTM_BL_COLLISION_EVT) { |
Jakub Pawlowski | c752e13 | 2017-06-16 12:52:23 -0700 | [diff] [blame] | 2967 | bta_sys_notify_collision(p_bda); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2968 | return; |
| 2969 | } |
| 2970 | |
| 2971 | if (is_new) { |
| 2972 | for (i = 0; i < bta_dm_cb.device_list.count; i++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2973 | 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] | 2974 | bta_dm_cb.device_list.peer_device[i].conn_handle == |
Myles Watson | 84baa7f | 2016-11-14 12:05:37 -0800 | [diff] [blame] | 2975 | p_data->acl_change.handle) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2976 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2977 | } |
| 2978 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2979 | if (i == bta_dm_cb.device_list.count) { |
| 2980 | if (bta_dm_cb.device_list.count < BTA_DM_NUM_PEER_DEVICE) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 2981 | bta_dm_cb.device_list.peer_device[bta_dm_cb.device_list.count] |
| 2982 | .peer_bdaddr = p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2983 | bta_dm_cb.device_list.peer_device[bta_dm_cb.device_list.count] |
| 2984 | .link_policy = bta_dm_cb.cur_policy; |
| 2985 | bta_dm_cb.device_list.count++; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2986 | bta_dm_cb.device_list.peer_device[i].conn_handle = |
| 2987 | p_data->acl_change.handle; |
| 2988 | if (p_data->acl_change.transport == BT_TRANSPORT_LE) |
| 2989 | bta_dm_cb.device_list.le_count++; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 2990 | } else { |
| 2991 | APPL_TRACE_ERROR("%s max active connection reached, no resources", |
| 2992 | __func__); |
| 2993 | return; |
| 2994 | } |
| 2995 | } |
| 2996 | |
| 2997 | bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_CONNECTED; |
| 2998 | 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] | 2999 | conn.link_up.bd_addr = p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3000 | 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] | 3001 | conn.link_up.link_type = p_data->acl_change.transport; |
| 3002 | bta_dm_cb.device_list.peer_device[i].transport = |
| 3003 | p_data->acl_change.transport; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3004 | |
| 3005 | if (((NULL != (p = BTM_ReadLocalFeatures())) && |
| 3006 | HCI_SNIFF_SUB_RATE_SUPPORTED(p)) && |
| 3007 | ((NULL != (p = BTM_ReadRemoteFeatures(p_bda))) && |
| 3008 | HCI_SNIFF_SUB_RATE_SUPPORTED(p))) { |
| 3009 | /* both local and remote devices support SSR */ |
| 3010 | bta_dm_cb.device_list.peer_device[i].info = BTA_DM_DI_USE_SSR; |
| 3011 | } |
| 3012 | APPL_TRACE_WARNING("%s info: 0x%x", __func__, |
| 3013 | bta_dm_cb.device_list.peer_device[i].info); |
| 3014 | |
Myles Watson | 6ef9190 | 2017-10-03 12:35:59 -0700 | [diff] [blame] | 3015 | if (bta_dm_cb.p_sec_cback) bta_dm_cb.p_sec_cback(BTA_DM_LINK_UP_EVT, &conn); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3016 | } else { |
| 3017 | for (i = 0; i < bta_dm_cb.device_list.count; i++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3018 | 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] | 3019 | bta_dm_cb.device_list.peer_device[i].transport != |
Myles Watson | 84baa7f | 2016-11-14 12:05:37 -0800 | [diff] [blame] | 3020 | p_data->acl_change.transport) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3021 | continue; |
| 3022 | |
| 3023 | if (bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_UNPAIRING) { |
| 3024 | if (BTM_SecDeleteDevice( |
| 3025 | bta_dm_cb.device_list.peer_device[i].peer_bdaddr)) |
| 3026 | issue_unpair_cb = true; |
| 3027 | |
| 3028 | APPL_TRACE_DEBUG("%s: Unpairing: issue unpair CB = %d ", __func__, |
| 3029 | issue_unpair_cb); |
| 3030 | } |
| 3031 | |
| 3032 | conn.link_down.is_removed = |
| 3033 | bta_dm_cb.device_list.peer_device[i].remove_dev_pending; |
| 3034 | |
Martin Brabham | 36d19de | 2017-05-01 16:30:40 -0700 | [diff] [blame] | 3035 | // Iterate to the one before the last when shrinking the list, |
| 3036 | // otherwise we memcpy garbage data into the record. |
| 3037 | // Then clear out the last item in the list since we are shrinking. |
| 3038 | for (; i < bta_dm_cb.device_list.count - 1; i++) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3039 | memcpy(&bta_dm_cb.device_list.peer_device[i], |
| 3040 | &bta_dm_cb.device_list.peer_device[i + 1], |
| 3041 | sizeof(bta_dm_cb.device_list.peer_device[i])); |
| 3042 | } |
Martin Brabham | 36d19de | 2017-05-01 16:30:40 -0700 | [diff] [blame] | 3043 | if (bta_dm_cb.device_list.count > 0) { |
| 3044 | int clear_index = bta_dm_cb.device_list.count - 1; |
| 3045 | memset(&bta_dm_cb.device_list.peer_device[clear_index], 0, |
| 3046 | sizeof(bta_dm_cb.device_list.peer_device[clear_index])); |
| 3047 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3048 | break; |
| 3049 | } |
| 3050 | 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] | 3051 | if ((p_data->acl_change.transport == BT_TRANSPORT_LE) && |
| 3052 | (bta_dm_cb.device_list.le_count)) |
| 3053 | bta_dm_cb.device_list.le_count--; |
| 3054 | conn.link_down.link_type = p_data->acl_change.transport; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3055 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3056 | 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] | 3057 | bta_dm_search_cb.wait_disc = false; |
| 3058 | |
| 3059 | if (bta_dm_search_cb.sdp_results) { |
| 3060 | APPL_TRACE_EVENT(" timer stopped "); |
| 3061 | alarm_cancel(bta_dm_search_cb.search_timer); |
| 3062 | bta_dm_discover_next_device(); |
| 3063 | } |
| 3064 | } |
| 3065 | |
| 3066 | if (bta_dm_cb.disabling) { |
| 3067 | if (!BTM_GetNumAclLinks()) { |
| 3068 | /* |
| 3069 | * Start a timer to make sure that the profiles |
| 3070 | * get the disconnect event. |
| 3071 | */ |
Jakub Pawlowski | be8bbd7 | 2017-09-08 11:26:25 -0700 | [diff] [blame] | 3072 | alarm_set_on_mloop(bta_dm_cb.disable_timer, |
| 3073 | BTA_DM_DISABLE_CONN_DOWN_TIMER_MS, |
| 3074 | bta_dm_disable_conn_down_timer_cback, NULL); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3075 | } |
| 3076 | } |
| 3077 | if (conn.link_down.is_removed) { |
| 3078 | BTM_SecDeleteDevice(p_bda); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3079 | /* need to remove all pending background connection */ |
| 3080 | BTA_GATTC_CancelOpen(0, p_bda, false); |
| 3081 | /* remove all cached GATT information */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3082 | BTA_GATTC_Refresh(p_bda); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3083 | } |
| 3084 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3085 | conn.link_down.bd_addr = p_bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3086 | conn.link_down.status = (uint8_t)btm_get_acl_disc_reason_code(); |
| 3087 | if (bta_dm_cb.p_sec_cback) { |
| 3088 | bta_dm_cb.p_sec_cback(BTA_DM_LINK_DOWN_EVT, &conn); |
| 3089 | if (issue_unpair_cb) |
| 3090 | bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &conn); |
| 3091 | } |
| 3092 | } |
| 3093 | |
| 3094 | bta_dm_adjust_roles(true); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3095 | } |
| 3096 | |
| 3097 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3098 | * |
| 3099 | * Function bta_dm_disable_conn_down_timer_cback |
| 3100 | * |
| 3101 | * Description Sends disable event to application |
| 3102 | * |
| 3103 | * |
| 3104 | * Returns void |
| 3105 | * |
| 3106 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3107 | static void bta_dm_disable_conn_down_timer_cback(UNUSED_ATTR void* data) { |
| 3108 | tBTA_SYS_HW_MSG* sys_enable_event = |
| 3109 | (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] | 3110 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3111 | /* disable the power managment module */ |
| 3112 | bta_dm_disable_pm(); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3113 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3114 | /* register our callback to SYS HW manager */ |
| 3115 | 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] | 3116 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3117 | /* send a message to BTA SYS */ |
| 3118 | sys_enable_event->hdr.event = BTA_SYS_API_DISABLE_EVT; |
| 3119 | sys_enable_event->hw_module = BTA_SYS_HW_BLUETOOTH; |
| 3120 | bta_sys_sendmsg(sys_enable_event); |
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 | bta_dm_cb.disabling = false; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3126 | * |
| 3127 | * Function bta_dm_rm_cback |
| 3128 | * |
| 3129 | * Description Role management callback from sys |
| 3130 | * |
| 3131 | * |
| 3132 | * Returns void |
| 3133 | * |
| 3134 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3135 | static void bta_dm_rm_cback(tBTA_SYS_CONN_STATUS status, uint8_t id, |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 3136 | uint8_t app_id, const RawAddress* peer_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3137 | uint8_t j; |
| 3138 | tBTA_PREF_ROLES role; |
| 3139 | tBTA_DM_PEER_DEVICE* p_dev; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3140 | |
Jakub Pawlowski | 78b81c6 | 2017-06-16 13:55:52 -0700 | [diff] [blame] | 3141 | p_dev = bta_dm_find_peer_device(*peer_addr); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3142 | if (status == BTA_SYS_CONN_OPEN) { |
| 3143 | if (p_dev) { |
| 3144 | /* Do not set to connected if we are in the middle of unpairing. When AV |
| 3145 | * stream is |
| 3146 | * started it fakes out a SYS_CONN_OPEN to potentially trigger a role |
| 3147 | * switch command. |
| 3148 | * But this should not be done if we are in the middle of unpairing. |
| 3149 | */ |
| 3150 | if (p_dev->conn_state != BTA_DM_UNPAIRING) |
| 3151 | p_dev->conn_state = BTA_DM_CONNECTED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3152 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3153 | for (j = 1; j <= p_bta_dm_rm_cfg[0].app_id; j++) { |
| 3154 | if (((p_bta_dm_rm_cfg[j].app_id == app_id) || |
| 3155 | (p_bta_dm_rm_cfg[j].app_id == BTA_ALL_APP_ID)) && |
| 3156 | (p_bta_dm_rm_cfg[j].id == id)) { |
| 3157 | role = p_bta_dm_rm_cfg[j].cfg; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3158 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3159 | if (role > p_dev->pref_role) p_dev->pref_role = role; |
| 3160 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3161 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3162 | } |
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 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3165 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3166 | if ((BTA_ID_AV == id) || (BTA_ID_AVK == id)) { |
| 3167 | if (status == BTA_SYS_CONN_BUSY) { |
| 3168 | if (p_dev) p_dev->info |= BTA_DM_DI_AV_ACTIVE; |
| 3169 | /* AV calls bta_sys_conn_open with the A2DP stream count as app_id */ |
| 3170 | if (BTA_ID_AV == id) bta_dm_cb.cur_av_count = bta_dm_get_av_count(); |
| 3171 | } else if (status == BTA_SYS_CONN_IDLE) { |
| 3172 | if (p_dev) p_dev->info &= ~BTA_DM_DI_AV_ACTIVE; |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 3173 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3174 | /* get cur_av_count from connected services */ |
| 3175 | 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] | 3176 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3177 | APPL_TRACE_WARNING("bta_dm_rm_cback:%d, status:%d", bta_dm_cb.cur_av_count, |
| 3178 | status); |
| 3179 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3180 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3181 | /* Don't adjust roles for each busy/idle state transition to avoid |
| 3182 | excessive switch requests when individual profile busy/idle status |
| 3183 | changes */ |
| 3184 | if ((status != BTA_SYS_CONN_BUSY) && (status != BTA_SYS_CONN_IDLE)) |
| 3185 | bta_dm_adjust_roles(false); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3189 | * |
| 3190 | * Function bta_dm_delay_role_switch_cback |
| 3191 | * |
| 3192 | * Description Callback from btm to delay a role switch |
| 3193 | * |
| 3194 | * Returns void |
| 3195 | * |
| 3196 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3197 | static void bta_dm_delay_role_switch_cback(UNUSED_ATTR void* data) { |
| 3198 | APPL_TRACE_EVENT("%s: initiating Delayed RS", __func__); |
| 3199 | bta_dm_adjust_roles(false); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3200 | } |
| 3201 | |
| 3202 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3203 | * |
| 3204 | * Function bta_dm_reset_sec_dev_pending |
| 3205 | * |
| 3206 | * Description Setting the remove device pending status to false from |
| 3207 | * security device DB, when the link key notification |
| 3208 | * event comes. |
| 3209 | * |
| 3210 | * Returns void |
| 3211 | * |
| 3212 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 3213 | static void bta_dm_reset_sec_dev_pending(const RawAddress& remote_bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3214 | 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] | 3215 | 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] | 3216 | bta_dm_cb.device_list.peer_device[i].remove_dev_pending = false; |
| 3217 | return; |
Balraj Selvaraj | 9412bba | 2016-02-11 13:46:02 +0530 | [diff] [blame] | 3218 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3219 | } |
Balraj Selvaraj | 9412bba | 2016-02-11 13:46:02 +0530 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3223 | * |
| 3224 | * Function bta_dm_remove_sec_dev_entry |
| 3225 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3226 | * Description Removes device entry from Security device DB if ACL |
| 3227 | connection with |
| 3228 | * remtoe device does not exist, else schedule for dev entry |
| 3229 | removal upon |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3230 | ACL close |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3231 | * |
| 3232 | * Returns void |
| 3233 | * |
| 3234 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 3235 | static void bta_dm_remove_sec_dev_entry(const RawAddress& remote_bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3236 | if (BTM_IsAclConnectionUp(remote_bd_addr, BT_TRANSPORT_LE) || |
| 3237 | BTM_IsAclConnectionUp(remote_bd_addr, BT_TRANSPORT_BR_EDR)) { |
| 3238 | APPL_TRACE_DEBUG( |
| 3239 | "%s ACL is not down. Schedule for Dev Removal when ACL closes", |
| 3240 | __func__); |
| 3241 | BTM_SecClearSecurityFlags(remote_bd_addr); |
| 3242 | for (int i = 0; i < bta_dm_cb.device_list.count; i++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3243 | 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] | 3244 | bta_dm_cb.device_list.peer_device[i].remove_dev_pending = TRUE; |
| 3245 | break; |
| 3246 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3247 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3248 | } else { |
| 3249 | BTM_SecDeleteDevice(remote_bd_addr); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3250 | /* need to remove all pending background connection */ |
| 3251 | BTA_GATTC_CancelOpen(0, remote_bd_addr, false); |
| 3252 | /* remove all cached GATT information */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3253 | BTA_GATTC_Refresh(remote_bd_addr); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3254 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3258 | * |
| 3259 | * Function bta_dm_adjust_roles |
| 3260 | * |
| 3261 | * Description Adjust roles |
| 3262 | * |
| 3263 | * |
| 3264 | * Returns void |
| 3265 | * |
| 3266 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3267 | static void bta_dm_adjust_roles(bool delay_role_switch) { |
| 3268 | uint8_t i; |
| 3269 | bool set_master_role = false; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3270 | uint8_t br_count = |
| 3271 | 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] | 3272 | if (br_count) { |
| 3273 | /* the configuration is no scatternet |
| 3274 | * or AV connection exists and there are more than one ACL link */ |
| 3275 | if ((p_bta_dm_rm_cfg[0].cfg == BTA_DM_NO_SCATTERNET) || |
| 3276 | (bta_dm_cb.cur_av_count && br_count > 1)) { |
| 3277 | L2CA_SetDesireRole(HCI_ROLE_MASTER); |
| 3278 | set_master_role = true; |
| 3279 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3280 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3281 | for (i = 0; i < bta_dm_cb.device_list.count; i++) { |
Myles Watson | 84baa7f | 2016-11-14 12:05:37 -0800 | [diff] [blame] | 3282 | if (bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_CONNECTED && |
| 3283 | bta_dm_cb.device_list.peer_device[i].transport == |
| 3284 | BT_TRANSPORT_BR_EDR) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3285 | if (!set_master_role && |
| 3286 | (bta_dm_cb.device_list.peer_device[i].pref_role != BTA_ANY_ROLE) && |
| 3287 | (p_bta_dm_rm_cfg[0].cfg == BTA_DM_PARTIAL_SCATTERNET)) { |
| 3288 | L2CA_SetDesireRole(HCI_ROLE_MASTER); |
| 3289 | set_master_role = true; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3290 | } |
| 3291 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3292 | if ((bta_dm_cb.device_list.peer_device[i].pref_role == |
| 3293 | BTA_MASTER_ROLE_ONLY) || |
| 3294 | (br_count > 1)) { |
| 3295 | /* Initiating immediate role switch with certain remote devices |
| 3296 | has caused issues due to role switch colliding with link encryption |
| 3297 | setup and |
| 3298 | causing encryption (and in turn the link) to fail . These device . |
| 3299 | Firmware |
| 3300 | versions are stored in a blacklist and role switch with these |
| 3301 | devices are |
| 3302 | delayed to avoid the collision with link encryption setup */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3303 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3304 | if (bta_dm_cb.device_list.peer_device[i].pref_role != |
| 3305 | BTA_SLAVE_ROLE_ONLY && |
Myles Watson | b749ebd | 2017-10-06 16:39:05 -0700 | [diff] [blame] | 3306 | !delay_role_switch) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3307 | BTM_SwitchRole(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, |
| 3308 | HCI_ROLE_MASTER, NULL); |
| 3309 | } else { |
Jakub Pawlowski | be8bbd7 | 2017-09-08 11:26:25 -0700 | [diff] [blame] | 3310 | alarm_set_on_mloop(bta_dm_cb.switch_delay_timer, |
| 3311 | BTA_DM_SWITCH_DELAY_TIMER_MS, |
| 3312 | bta_dm_delay_role_switch_cback, NULL); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3313 | } |
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 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3316 | } |
| 3317 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3318 | if (!set_master_role) { |
| 3319 | L2CA_SetDesireRole(L2CAP_DESIRED_LINK_ROLE); |
| 3320 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3321 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3322 | } else { |
| 3323 | L2CA_SetDesireRole(L2CAP_DESIRED_LINK_ROLE); |
| 3324 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3328 | * |
| 3329 | * Function bta_dm_get_remname |
| 3330 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3331 | * Description Returns a pointer to the remote name stored in the DM |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 3332 | * control block if it exists, or from the BTM memory. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3333 | * |
| 3334 | * Returns char * - Pointer to the remote device name |
| 3335 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3336 | static char* bta_dm_get_remname(void) { |
| 3337 | char* p_name = (char*)bta_dm_search_cb.peer_name; |
| 3338 | char* p_temp; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3339 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3340 | /* If the name isn't already stored, try retrieving from BTM */ |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame] | 3341 | if (*p_name == '\0') { |
| 3342 | p_temp = BTM_SecReadDevName(bta_dm_search_cb.peer_bdaddr); |
| 3343 | if (p_temp != NULL) p_name = p_temp; |
| 3344 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3345 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3346 | return p_name; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3350 | * |
| 3351 | * Function bta_dm_bond_cancel_complete_cback |
| 3352 | * |
| 3353 | * Description Authentication complete callback from BTM |
| 3354 | * |
| 3355 | * Returns void |
| 3356 | * |
| 3357 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3358 | static void bta_dm_bond_cancel_complete_cback(tBTM_STATUS result) { |
| 3359 | tBTA_DM_SEC sec_event; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3360 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3361 | if (result == BTM_SUCCESS) |
| 3362 | sec_event.bond_cancel_cmpl.result = BTA_SUCCESS; |
| 3363 | else |
| 3364 | sec_event.bond_cancel_cmpl.result = BTA_FAILURE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3365 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3366 | if (bta_dm_cb.p_sec_cback) { |
| 3367 | bta_dm_cb.p_sec_cback(BTA_DM_BOND_CANCEL_CMPL_EVT, &sec_event); |
| 3368 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3369 | } |
| 3370 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3371 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3372 | * |
| 3373 | * Function find_utf8_char_boundary |
| 3374 | * |
| 3375 | * Description This function checks a UTF8 string |utf8str| starting at |
| 3376 | * |offset|, moving backwards and returns the offset of the |
| 3377 | * next valid UTF8 character boundary found. |
| 3378 | * |
| 3379 | * Returns Offset of UTF8 character boundary |
| 3380 | * |
| 3381 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3382 | 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] | 3383 | CHECK(utf8str); |
| 3384 | CHECK(offset > 0); |
Matadeen Mishra | c5734d7 | 2016-02-03 20:50:31 +0530 | [diff] [blame] | 3385 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3386 | while (--offset) { |
| 3387 | uint8_t ch = (uint8_t)utf8str[offset]; |
| 3388 | if ((ch & 0x80) == 0x00) // ASCII |
| 3389 | return offset + 1; |
| 3390 | if ((ch & 0xC0) == 0xC0) // Multi-byte sequence start |
| 3391 | return offset; |
| 3392 | } |
Matadeen Mishra | c5734d7 | 2016-02-03 20:50:31 +0530 | [diff] [blame] | 3393 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3394 | return 0; |
Matadeen Mishra | c5734d7 | 2016-02-03 20:50:31 +0530 | [diff] [blame] | 3395 | } |
| 3396 | |
| 3397 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3398 | * |
| 3399 | * Function bta_dm_set_eir |
| 3400 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3401 | * Description This function creates EIR tagged data and writes it to |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 3402 | * controller. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3403 | * |
| 3404 | * Returns None |
| 3405 | * |
| 3406 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3407 | static void bta_dm_set_eir(char* local_name) { |
| 3408 | uint8_t* p; |
| 3409 | uint8_t* p_length; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3410 | #if (BTA_EIR_CANNED_UUID_LIST != TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3411 | uint8_t* p_type; |
| 3412 | uint8_t max_num_uuid; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3413 | #if (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3414 | uint8_t custom_uuid_idx; |
Chris Manton | 1e61ce1 | 2014-10-24 09:12:41 -0700 | [diff] [blame] | 3415 | #endif // BTA_EIR_SERVER_NUM_CUSTOM_UUID |
| 3416 | #endif // BTA_EIR_CANNED_UUID_LIST |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3417 | #if (BTM_EIR_DEFAULT_FEC_REQUIRED == FALSE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3418 | uint8_t free_eir_length = HCI_EXT_INQ_RESPONSE_LEN; |
Chris Manton | 1e61ce1 | 2014-10-24 09:12:41 -0700 | [diff] [blame] | 3419 | #else // BTM_EIR_DEFAULT_FEC_REQUIRED |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3420 | uint8_t free_eir_length = HCI_DM5_PACKET_SIZE; |
Casper Bonde | 818d0f2 | 2015-05-21 11:08:45 +0200 | [diff] [blame] | 3421 | #endif // BTM_EIR_DEFAULT_FEC_REQUIRED |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3422 | uint8_t num_uuid; |
| 3423 | uint8_t data_type; |
| 3424 | uint8_t local_name_len; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3425 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3426 | /* wait until complete to disable */ |
| 3427 | 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] | 3428 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 3429 | #if (BTA_EIR_CANNED_UUID_LIST != TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3430 | /* if local name is not provided, get it from controller */ |
| 3431 | if (local_name == NULL) { |
| 3432 | if (BTM_ReadLocalDeviceName(&local_name) != BTM_SUCCESS) { |
| 3433 | 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] | 3434 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3435 | } |
Chris Manton | 1e61ce1 | 2014-10-24 09:12:41 -0700 | [diff] [blame] | 3436 | #endif // BTA_EIR_CANNED_UUID_LIST |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3437 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3438 | /* Allocate a buffer to hold HCI command */ |
| 3439 | BT_HDR* p_buf = (BT_HDR*)osi_malloc(BTM_CMD_BUF_SIZE); |
| 3440 | p = (uint8_t*)p_buf + BTM_HCI_EIR_OFFSET; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3441 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3442 | memset(p, 0x00, HCI_EXT_INQ_RESPONSE_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3443 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3444 | APPL_TRACE_DEBUG("BTA is generating 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 | if (local_name) |
| 3447 | local_name_len = strlen(local_name); |
| 3448 | else |
| 3449 | local_name_len = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3450 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3451 | data_type = BTM_EIR_COMPLETE_LOCAL_NAME_TYPE; |
| 3452 | /* if local name is longer than minimum length of shortened name */ |
| 3453 | /* check whether it needs to be shortened or not */ |
| 3454 | if (local_name_len > p_bta_dm_eir_cfg->bta_dm_eir_min_name_len) { |
| 3455 | /* get number of UUID 16-bit list */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3456 | #if (BTA_EIR_CANNED_UUID_LIST == TRUE) |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3457 | num_uuid = p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len / Uuid::kNumBytes16; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3458 | #else // BTA_EIR_CANNED_UUID_LIST |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3459 | max_num_uuid = (free_eir_length - 2) / Uuid::kNumBytes16; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3460 | data_type = BTM_GetEirSupportedServices(bta_dm_cb.eir_uuid, &p, |
| 3461 | max_num_uuid, &num_uuid); |
| 3462 | p = (uint8_t*)p_buf + BTM_HCI_EIR_OFFSET; /* reset p */ |
Chris Manton | 1e61ce1 | 2014-10-24 09:12:41 -0700 | [diff] [blame] | 3463 | #endif // BTA_EIR_CANNED_UUID_LIST |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3464 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3465 | /* if UUID doesn't fit remaing space, shorten local name */ |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3466 | if (local_name_len > (free_eir_length - 4 - num_uuid * Uuid::kNumBytes16)) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3467 | local_name_len = find_utf8_char_boundary( |
| 3468 | local_name, p_bta_dm_eir_cfg->bta_dm_eir_min_name_len); |
| 3469 | APPL_TRACE_WARNING("%s local name is shortened (%d)", __func__, |
| 3470 | local_name_len); |
| 3471 | data_type = BTM_EIR_SHORTENED_LOCAL_NAME_TYPE; |
| 3472 | } else { |
| 3473 | data_type = BTM_EIR_COMPLETE_LOCAL_NAME_TYPE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3474 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3475 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3476 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3477 | UINT8_TO_STREAM(p, local_name_len + 1); |
| 3478 | UINT8_TO_STREAM(p, data_type); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 3479 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3480 | if (local_name != NULL) { |
| 3481 | memcpy(p, local_name, local_name_len); |
| 3482 | p += local_name_len; |
| 3483 | } |
| 3484 | free_eir_length -= local_name_len + 2; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3485 | |
| 3486 | #if (BTA_EIR_CANNED_UUID_LIST == TRUE) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3487 | /* if UUID list is provided as static data in configuration */ |
| 3488 | if ((p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len > 0) && |
| 3489 | (p_bta_dm_eir_cfg->bta_dm_eir_uuid16)) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3490 | if (free_eir_length > Uuid::kNumBytes16 + 2) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3491 | free_eir_length -= 2; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3492 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3493 | if (free_eir_length >= p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3494 | num_uuid = p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len / Uuid::kNumBytes16; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3495 | data_type = BTM_EIR_COMPLETE_16BITS_UUID_TYPE; |
| 3496 | } else /* not enough room for all UUIDs */ |
| 3497 | { |
| 3498 | APPL_TRACE_WARNING("BTA EIR: UUID 16-bit list is truncated"); |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3499 | num_uuid = free_eir_length / Uuid::kNumBytes16; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3500 | data_type = BTM_EIR_MORE_16BITS_UUID_TYPE; |
| 3501 | } |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3502 | UINT8_TO_STREAM(p, num_uuid * Uuid::kNumBytes16 + 1); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3503 | UINT8_TO_STREAM(p, data_type); |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3504 | memcpy(p, p_bta_dm_eir_cfg->bta_dm_eir_uuid16, |
| 3505 | num_uuid * Uuid::kNumBytes16); |
| 3506 | p += num_uuid * Uuid::kNumBytes16; |
| 3507 | free_eir_length -= num_uuid * Uuid::kNumBytes16; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3508 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3509 | } |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 3510 | #else /* (BTA_EIR_CANNED_UUID_LIST == TRUE) */ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3511 | /* if UUID list is dynamic */ |
| 3512 | if (free_eir_length >= 2) { |
| 3513 | p_length = p++; |
| 3514 | p_type = p++; |
| 3515 | num_uuid = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3516 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3517 | max_num_uuid = (free_eir_length - 2) / Uuid::kNumBytes16; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3518 | data_type = BTM_GetEirSupportedServices(bta_dm_cb.eir_uuid, &p, |
| 3519 | max_num_uuid, &num_uuid); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3520 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3521 | if (data_type == BTM_EIR_MORE_16BITS_UUID_TYPE) { |
| 3522 | APPL_TRACE_WARNING("BTA EIR: UUID 16-bit list is truncated"); |
| 3523 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3524 | #if (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3525 | else { |
| 3526 | for (custom_uuid_idx = 0; |
| 3527 | custom_uuid_idx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; |
| 3528 | custom_uuid_idx++) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3529 | const Uuid& curr = bta_dm_cb.custom_uuid[custom_uuid_idx]; |
| 3530 | if (curr.GetShortestRepresentationSize() == Uuid::kNumBytes16) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3531 | if (num_uuid < max_num_uuid) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3532 | UINT16_TO_STREAM(p, curr.As16Bit()); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3533 | num_uuid++; |
| 3534 | } else { |
| 3535 | data_type = BTM_EIR_MORE_16BITS_UUID_TYPE; |
| 3536 | APPL_TRACE_WARNING("BTA EIR: UUID 16-bit list is truncated"); |
| 3537 | break; |
| 3538 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3539 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3540 | } |
| 3541 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3542 | #endif /* (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) */ |
| 3543 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3544 | UINT8_TO_STREAM(p_length, num_uuid * Uuid::kNumBytes16 + 1); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3545 | UINT8_TO_STREAM(p_type, data_type); |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3546 | free_eir_length -= num_uuid * Uuid::kNumBytes16 + 2; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3547 | } |
Marie Janssen | d19e078 | 2016-07-15 12:48:27 -0700 | [diff] [blame] | 3548 | #endif /* (BTA_EIR_CANNED_UUID_LIST == TRUE) */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3549 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 3550 | #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] | 3551 | /* Adding 32-bit UUID list */ |
| 3552 | if (free_eir_length >= 2) { |
| 3553 | p_length = p++; |
| 3554 | p_type = p++; |
| 3555 | num_uuid = 0; |
| 3556 | data_type = BTM_EIR_COMPLETE_32BITS_UUID_TYPE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3557 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3558 | max_num_uuid = (free_eir_length - 2) / Uuid::kNumBytes32; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3559 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3560 | for (custom_uuid_idx = 0; custom_uuid_idx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; |
| 3561 | custom_uuid_idx++) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3562 | const Uuid& curr = bta_dm_cb.custom_uuid[custom_uuid_idx]; |
| 3563 | if (curr.GetShortestRepresentationSize() == Uuid::kNumBytes32) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3564 | if (num_uuid < max_num_uuid) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3565 | UINT32_TO_STREAM(p, curr.As32Bit()); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3566 | num_uuid++; |
| 3567 | } else { |
| 3568 | data_type = BTM_EIR_MORE_32BITS_UUID_TYPE; |
| 3569 | APPL_TRACE_WARNING("BTA EIR: UUID 32-bit list is truncated"); |
| 3570 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3571 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3572 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3573 | } |
| 3574 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3575 | UINT8_TO_STREAM(p_length, num_uuid * Uuid::kNumBytes32 + 1); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3576 | UINT8_TO_STREAM(p_type, data_type); |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3577 | free_eir_length -= num_uuid * Uuid::kNumBytes32 + 2; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3578 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3579 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3580 | /* Adding 128-bit UUID list */ |
| 3581 | if (free_eir_length >= 2) { |
| 3582 | p_length = p++; |
| 3583 | p_type = p++; |
| 3584 | num_uuid = 0; |
| 3585 | data_type = BTM_EIR_COMPLETE_128BITS_UUID_TYPE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3586 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3587 | max_num_uuid = (free_eir_length - 2) / Uuid::kNumBytes128; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3588 | |
| 3589 | for (custom_uuid_idx = 0; custom_uuid_idx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; |
| 3590 | custom_uuid_idx++) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3591 | const Uuid& curr = bta_dm_cb.custom_uuid[custom_uuid_idx]; |
| 3592 | if (curr.GetShortestRepresentationSize() == Uuid::kNumBytes128) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3593 | if (num_uuid < max_num_uuid) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3594 | ARRAY16_TO_STREAM(p, curr.To128BitBE().data()); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3595 | num_uuid++; |
| 3596 | } else { |
| 3597 | data_type = BTM_EIR_MORE_128BITS_UUID_TYPE; |
| 3598 | APPL_TRACE_WARNING("BTA EIR: UUID 128-bit list is truncated"); |
| 3599 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3600 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3601 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3602 | } |
| 3603 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3604 | UINT8_TO_STREAM(p_length, num_uuid * Uuid::kNumBytes128 + 1); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3605 | UINT8_TO_STREAM(p_type, data_type); |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 3606 | free_eir_length -= num_uuid * Uuid::kNumBytes128 + 2; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3607 | } |
| 3608 | #endif /* ( BTA_EIR_CANNED_UUID_LIST != TRUE \ |
| 3609 | )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3610 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3611 | /* if Flags are provided in configuration */ |
| 3612 | if ((p_bta_dm_eir_cfg->bta_dm_eir_flag_len > 0) && |
| 3613 | (p_bta_dm_eir_cfg->bta_dm_eir_flags) && |
| 3614 | (free_eir_length >= p_bta_dm_eir_cfg->bta_dm_eir_flag_len + 2)) { |
| 3615 | UINT8_TO_STREAM(p, p_bta_dm_eir_cfg->bta_dm_eir_flag_len + 1); |
| 3616 | UINT8_TO_STREAM(p, BTM_EIR_FLAGS_TYPE); |
| 3617 | memcpy(p, p_bta_dm_eir_cfg->bta_dm_eir_flags, |
| 3618 | p_bta_dm_eir_cfg->bta_dm_eir_flag_len); |
| 3619 | p += p_bta_dm_eir_cfg->bta_dm_eir_flag_len; |
| 3620 | free_eir_length -= p_bta_dm_eir_cfg->bta_dm_eir_flag_len + 2; |
| 3621 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3622 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3623 | /* if Manufacturer Specific are provided in configuration */ |
| 3624 | if ((p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len > 0) && |
| 3625 | (p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec) && |
| 3626 | (free_eir_length >= p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len + 2)) { |
| 3627 | p_length = p; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3628 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3629 | UINT8_TO_STREAM(p, p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len + 1); |
| 3630 | UINT8_TO_STREAM(p, BTM_EIR_MANUFACTURER_SPECIFIC_TYPE); |
| 3631 | memcpy(p, p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec, |
| 3632 | p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len); |
| 3633 | p += p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len; |
| 3634 | 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] | 3635 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3636 | } else { |
| 3637 | p_length = NULL; |
| 3638 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3639 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3640 | /* if Inquiry Tx Resp Power compiled */ |
| 3641 | if ((p_bta_dm_eir_cfg->bta_dm_eir_inq_tx_power) && (free_eir_length >= 3)) { |
| 3642 | UINT8_TO_STREAM(p, 2); /* Length field */ |
| 3643 | UINT8_TO_STREAM(p, BTM_EIR_TX_POWER_LEVEL_TYPE); |
| 3644 | UINT8_TO_STREAM(p, *(p_bta_dm_eir_cfg->bta_dm_eir_inq_tx_power)); |
| 3645 | free_eir_length -= 3; |
| 3646 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3647 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3648 | if (free_eir_length) |
| 3649 | UINT8_TO_STREAM(p, 0); /* terminator of significant part */ |
| 3650 | |
| 3651 | BTM_WriteEIR(p_buf); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3652 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3653 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3654 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3655 | * |
| 3656 | * Function bta_dm_eir_search_services |
| 3657 | * |
| 3658 | * Description This function searches services in received EIR |
| 3659 | * |
| 3660 | * Returns None |
| 3661 | * |
| 3662 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3663 | static void bta_dm_eir_search_services(tBTM_INQ_RESULTS* p_result, |
| 3664 | tBTA_SERVICE_MASK* p_services_to_search, |
| 3665 | tBTA_SERVICE_MASK* p_services_found) { |
| 3666 | tBTA_SERVICE_MASK service_index = 0; |
| 3667 | tBTM_EIR_SEARCH_RESULT result; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3668 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3669 | VLOG(1) << "BTA searching services in EIR of BDA:" |
| 3670 | << p_result->remote_bd_addr; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3671 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3672 | 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] | 3673 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3674 | /* always do GATT based service discovery by SDP instead of from EIR */ |
| 3675 | /* 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] | 3676 | while (service_index < (BTA_MAX_SERVICE_ID - 1)) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3677 | if (*p_services_to_search & |
| 3678 | (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(service_index))) { |
| 3679 | result = BTM_HasInquiryEirService( |
| 3680 | 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] | 3681 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3682 | /* Searching for HSP v1.2 only device */ |
| 3683 | if ((result != BTM_EIR_FOUND) && |
| 3684 | (bta_service_id_to_uuid_lkup_tbl[service_index] == |
| 3685 | UUID_SERVCLASS_HEADSET)) { |
| 3686 | result = BTM_HasInquiryEirService(p_result, UUID_SERVCLASS_HEADSET_HS); |
| 3687 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3688 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3689 | if (result == BTM_EIR_FOUND) { |
| 3690 | /* If Plug and Play service record, need to check to see if Broadcom |
| 3691 | * stack */ |
| 3692 | /* However, EIR data doesn't have EXT_BRCM_VERSION so just skip it */ |
| 3693 | if (bta_service_id_to_uuid_lkup_tbl[service_index] != |
| 3694 | UUID_SERVCLASS_PNP_INFORMATION) { |
| 3695 | *p_services_found |= (tBTA_SERVICE_MASK)( |
| 3696 | BTA_SERVICE_ID_TO_SERVICE_MASK(service_index)); |
| 3697 | /* remove the service from services to be searched */ |
| 3698 | *p_services_to_search &= (tBTA_SERVICE_MASK)( |
| 3699 | ~(BTA_SERVICE_ID_TO_SERVICE_MASK(service_index))); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3700 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3701 | } else if (result == BTM_EIR_NOT_FOUND) { |
| 3702 | /* remove the service from services to be searched */ |
| 3703 | *p_services_to_search &= (tBTA_SERVICE_MASK)( |
| 3704 | ~(BTA_SERVICE_ID_TO_SERVICE_MASK(service_index))); |
| 3705 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3706 | } |
| 3707 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3708 | service_index++; |
| 3709 | } |
| 3710 | |
| 3711 | APPL_TRACE_ERROR( |
| 3712 | "BTA EIR search result, services_to_search=0x%08X, services_found=0x%08X", |
| 3713 | *p_services_to_search, *p_services_found); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3714 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3715 | |
Chris Manton | 1e61ce1 | 2014-10-24 09:12:41 -0700 | [diff] [blame] | 3716 | #if (BTA_EIR_CANNED_UUID_LIST != TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3717 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3718 | * |
| 3719 | * Function bta_dm_eir_update_uuid |
| 3720 | * |
| 3721 | * Description This function adds or removes service UUID in EIR database. |
| 3722 | * |
| 3723 | * Returns None |
| 3724 | * |
| 3725 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3726 | void bta_dm_eir_update_uuid(uint16_t uuid16, bool adding) { |
| 3727 | /* if this UUID is not advertised in EIR */ |
| 3728 | 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] | 3729 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3730 | if (adding) { |
| 3731 | 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] | 3732 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3733 | BTM_AddEirService(bta_dm_cb.eir_uuid, uuid16); |
| 3734 | } else { |
| 3735 | 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] | 3736 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3737 | BTM_RemoveEirService(bta_dm_cb.eir_uuid, uuid16); |
| 3738 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3739 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3740 | bta_dm_set_eir(NULL); |
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 | APPL_TRACE_EVENT("bta_dm_eir_update_uuid UUID bit mask=0x%08X %08X", |
| 3743 | 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] | 3744 | } |
| 3745 | #endif |
| 3746 | |
| 3747 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3748 | * |
| 3749 | * Function bta_dm_enable_test_mode |
| 3750 | * |
| 3751 | * Description enable test mode |
| 3752 | * |
| 3753 | * |
| 3754 | * Returns void |
| 3755 | * |
| 3756 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3757 | void bta_dm_enable_test_mode(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 3758 | BTM_EnableTestMode(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3759 | } |
| 3760 | |
| 3761 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3762 | * |
| 3763 | * Function bta_dm_disable_test_mode |
| 3764 | * |
| 3765 | * Description disable test mode |
| 3766 | * |
| 3767 | * |
| 3768 | * Returns void |
| 3769 | * |
| 3770 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3771 | void bta_dm_disable_test_mode(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
| 3772 | BTM_DeviceReset(NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3773 | } |
| 3774 | |
| 3775 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3776 | * |
| 3777 | * Function bta_dm_execute_callback |
| 3778 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3779 | * Description Just execute a generic call back in the context of the |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 3780 | * BTU/BTA tack |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3781 | * |
| 3782 | * |
| 3783 | * Returns void |
| 3784 | * |
| 3785 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3786 | void bta_dm_execute_callback(tBTA_DM_MSG* p_data) { |
| 3787 | /* sanity check */ |
| 3788 | if (p_data->exec_cback.p_exec_cback == NULL) { |
| 3789 | return; |
| 3790 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3791 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3792 | 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] | 3793 | } |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 3794 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3795 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3796 | * |
| 3797 | * Function bta_dm_encrypt_cback |
| 3798 | * |
| 3799 | * Description link encryption complete callback. |
| 3800 | * |
| 3801 | * Returns None |
| 3802 | * |
| 3803 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 3804 | void bta_dm_encrypt_cback(const RawAddress* bd_addr, tBT_TRANSPORT transport, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3805 | UNUSED_ATTR void* p_ref_data, tBTM_STATUS result) { |
| 3806 | tBTA_STATUS bta_status = BTA_SUCCESS; |
| 3807 | tBTA_DM_ENCRYPT_CBACK* p_callback = NULL; |
| 3808 | uint8_t i; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3809 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3810 | for (i = 0; i < bta_dm_cb.device_list.count; i++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3811 | 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] | 3812 | bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_CONNECTED) |
| 3813 | break; |
| 3814 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3815 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3816 | if (i < bta_dm_cb.device_list.count) { |
| 3817 | p_callback = bta_dm_cb.device_list.peer_device[i].p_encrypt_cback; |
| 3818 | bta_dm_cb.device_list.peer_device[i].p_encrypt_cback = NULL; |
| 3819 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3820 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3821 | switch (result) { |
| 3822 | case BTM_SUCCESS: |
| 3823 | break; |
| 3824 | case BTM_WRONG_MODE: |
| 3825 | bta_status = BTA_WRONG_MODE; |
| 3826 | break; |
| 3827 | case BTM_NO_RESOURCES: |
| 3828 | bta_status = BTA_NO_RESOURCES; |
| 3829 | break; |
| 3830 | case BTM_BUSY: |
| 3831 | bta_status = BTA_BUSY; |
| 3832 | break; |
| 3833 | default: |
| 3834 | bta_status = BTA_FAILURE; |
| 3835 | break; |
| 3836 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3837 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3838 | APPL_TRACE_DEBUG("bta_dm_encrypt_cback status =%d p_callback=0x%x", |
| 3839 | bta_status, p_callback); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3840 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3841 | if (p_callback) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3842 | (*p_callback)(*bd_addr, transport, bta_status); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3843 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3844 | } |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 3845 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3846 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3847 | * |
| 3848 | * Function bta_dm_set_encryption |
| 3849 | * |
| 3850 | * Description This function to encrypt the link |
| 3851 | * |
| 3852 | * Returns None |
| 3853 | * |
| 3854 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3855 | void bta_dm_set_encryption(tBTA_DM_MSG* p_data) { |
| 3856 | uint8_t i; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3857 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3858 | APPL_TRACE_DEBUG("bta_dm_set_encryption"); // todo |
| 3859 | if (!p_data->set_encryption.p_callback) { |
| 3860 | APPL_TRACE_ERROR("bta_dm_set_encryption callback is not provided"); |
| 3861 | return; |
| 3862 | } |
| 3863 | for (i = 0; i < bta_dm_cb.device_list.count; i++) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3864 | if (bta_dm_cb.device_list.peer_device[i].peer_bdaddr == |
| 3865 | p_data->set_encryption.bd_addr && |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3866 | bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_CONNECTED) |
| 3867 | break; |
| 3868 | } |
| 3869 | if (i < bta_dm_cb.device_list.count) { |
| 3870 | if (bta_dm_cb.device_list.peer_device[i].p_encrypt_cback) { |
| 3871 | APPL_TRACE_ERROR("earlier enc was not done for same device"); |
| 3872 | (*p_data->set_encryption.p_callback)(p_data->set_encryption.bd_addr, |
| 3873 | p_data->set_encryption.transport, |
| 3874 | BTA_BUSY); |
| 3875 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3876 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3877 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3878 | if (BTM_SetEncryption(p_data->set_encryption.bd_addr, |
| 3879 | p_data->set_encryption.transport, |
| 3880 | bta_dm_encrypt_cback, NULL, |
| 3881 | p_data->set_encryption.sec_act) == BTM_CMD_STARTED) { |
| 3882 | bta_dm_cb.device_list.peer_device[i].p_encrypt_cback = |
| 3883 | p_data->set_encryption.p_callback; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3884 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3885 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3886 | } |
| 3887 | |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 3888 | bool bta_dm_check_if_only_hd_connected(const RawAddress& peer_addr) { |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 3889 | APPL_TRACE_DEBUG("%s: count(%d)", __func__, bta_dm_conn_srvcs.count); |
| 3890 | |
| 3891 | for (uint8_t j = 0; j < bta_dm_conn_srvcs.count; j++) { |
| 3892 | // Check if profiles other than hid are connected |
| 3893 | if ((bta_dm_conn_srvcs.conn_srvc[j].id != BTA_ID_HD) && |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3894 | bta_dm_conn_srvcs.conn_srvc[j].peer_bdaddr == peer_addr) { |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 3895 | APPL_TRACE_DEBUG("%s: Another profile (id=%d) is connected", __func__, |
| 3896 | bta_dm_conn_srvcs.conn_srvc[j].id); |
Jack He | fe695a5 | 2017-05-07 17:27:47 -0700 | [diff] [blame] | 3897 | return false; |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 3898 | } |
| 3899 | } |
| 3900 | |
Jack He | fe695a5 | 2017-05-07 17:27:47 -0700 | [diff] [blame] | 3901 | return true; |
Hemant Gupta | 8843cc8 | 2014-04-18 12:34:55 +0530 | [diff] [blame] | 3902 | } |
| 3903 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3904 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3905 | * |
| 3906 | * Function bta_dm_observe_results_cb |
| 3907 | * |
| 3908 | * Description Callback for BLE Observe result |
| 3909 | * |
| 3910 | * |
| 3911 | * Returns void |
| 3912 | * |
| 3913 | ******************************************************************************/ |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 3914 | 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] | 3915 | uint16_t eir_len) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3916 | tBTA_DM_SEARCH result; |
| 3917 | tBTM_INQ_INFO* p_inq_info; |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 3918 | APPL_TRACE_DEBUG("bta_dm_observe_results_cb"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3919 | |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 3920 | result.inq_res.bd_addr = p_inq->remote_bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3921 | result.inq_res.rssi = p_inq->rssi; |
| 3922 | result.inq_res.ble_addr_type = p_inq->ble_addr_type; |
| 3923 | result.inq_res.inq_result_type = p_inq->inq_result_type; |
| 3924 | result.inq_res.device_type = p_inq->device_type; |
| 3925 | result.inq_res.flag = p_inq->flag; |
Jakub Pawlowski | 7de0f9b | 2017-01-27 08:06:20 -0800 | [diff] [blame] | 3926 | result.inq_res.ble_evt_type = p_inq->ble_evt_type; |
| 3927 | result.inq_res.ble_primary_phy = p_inq->ble_primary_phy; |
| 3928 | result.inq_res.ble_secondary_phy = p_inq->ble_secondary_phy; |
| 3929 | result.inq_res.ble_advertising_sid = p_inq->ble_advertising_sid; |
| 3930 | result.inq_res.ble_tx_power = p_inq->ble_tx_power; |
| 3931 | 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] | 3932 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3933 | /* application will parse EIR to find out remote device name */ |
| 3934 | result.inq_res.p_eir = p_eir; |
Jakub Pawlowski | 0595ca0 | 2017-02-07 12:15:06 -0800 | [diff] [blame] | 3935 | result.inq_res.eir_len = eir_len; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3936 | |
Marie Janssen | f33b6f4 | 2016-11-22 15:01:42 -0800 | [diff] [blame] | 3937 | p_inq_info = BTM_InqDbRead(p_inq->remote_bd_addr); |
| 3938 | if (p_inq_info != NULL) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3939 | /* initialize remt_name_not_required to false so that we get the name by |
| 3940 | * default */ |
| 3941 | result.inq_res.remt_name_not_required = false; |
| 3942 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3943 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3944 | if (bta_dm_search_cb.p_scan_cback) |
| 3945 | 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] | 3946 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3947 | if (p_inq_info) { |
| 3948 | /* application indicates if it knows the remote name, inside the callback |
| 3949 | copy that to the inquiry data base*/ |
| 3950 | if (result.inq_res.remt_name_not_required) |
| 3951 | p_inq_info->appl_knows_rem_name = true; |
| 3952 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3956 | * |
| 3957 | * Function bta_dm_observe_cmpl_cb |
| 3958 | * |
| 3959 | * Description Callback for BLE Observe complete |
| 3960 | * |
| 3961 | * |
| 3962 | * Returns void |
| 3963 | * |
| 3964 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3965 | static void bta_dm_observe_cmpl_cb(void* p_result) { |
| 3966 | tBTA_DM_SEARCH data; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3967 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3968 | APPL_TRACE_DEBUG("bta_dm_observe_cmpl_cb"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3969 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3970 | data.inq_cmpl.num_resps = ((tBTM_INQUIRY_CMPL*)p_result)->num_resp; |
| 3971 | if (bta_dm_search_cb.p_scan_cback) { |
| 3972 | bta_dm_search_cb.p_scan_cback(BTA_DM_INQ_CMPL_EVT, &data); |
| 3973 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3974 | } |
| 3975 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3976 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 3977 | * |
| 3978 | * Function bta_dm_ble_smp_cback |
| 3979 | * |
| 3980 | * Description Callback for BLE SMP |
| 3981 | * |
| 3982 | * |
| 3983 | * Returns void |
| 3984 | * |
| 3985 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 3986 | static uint8_t bta_dm_ble_smp_cback(tBTM_LE_EVT event, const RawAddress& bda, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3987 | tBTM_LE_EVT_DATA* p_data) { |
| 3988 | tBTM_STATUS status = BTM_SUCCESS; |
| 3989 | tBTA_DM_SEC sec_event; |
| 3990 | char* p_name = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3991 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3992 | 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] | 3993 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3994 | memset(&sec_event, 0, sizeof(tBTA_DM_SEC)); |
| 3995 | switch (event) { |
| 3996 | case BTM_LE_IO_REQ_EVT: |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3997 | #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) |
| 3998 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 3999 | bta_dm_co_ble_io_req( |
| 4000 | bda, &p_data->io_req.io_cap, &p_data->io_req.oob_data, |
| 4001 | &p_data->io_req.auth_req, &p_data->io_req.max_key_size, |
| 4002 | &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] | 4003 | #endif |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4004 | APPL_TRACE_EVENT("io mitm: %d oob_data:%d", p_data->io_req.auth_req, |
| 4005 | p_data->io_req.oob_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4006 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4007 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4008 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4009 | case BTM_LE_SEC_REQUEST_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4010 | sec_event.ble_req.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4011 | p_name = BTM_SecReadDevName(bda); |
| 4012 | if (p_name != NULL) |
| 4013 | strlcpy((char*)sec_event.ble_req.bd_name, p_name, BD_NAME_LEN); |
| 4014 | else |
| 4015 | sec_event.ble_req.bd_name[0] = 0; |
| 4016 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_SEC_REQ_EVT, &sec_event); |
| 4017 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4018 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4019 | case BTM_LE_KEY_NOTIF_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4020 | sec_event.key_notif.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4021 | p_name = BTM_SecReadDevName(bda); |
| 4022 | if (p_name != NULL) |
| 4023 | strlcpy((char*)sec_event.key_notif.bd_name, p_name, BD_NAME_LEN); |
| 4024 | else |
| 4025 | sec_event.key_notif.bd_name[0] = 0; |
| 4026 | sec_event.key_notif.passkey = p_data->key_notif; |
| 4027 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_PASSKEY_NOTIF_EVT, &sec_event); |
| 4028 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4029 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4030 | case BTM_LE_KEY_REQ_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4031 | sec_event.ble_req.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4032 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_PASSKEY_REQ_EVT, &sec_event); |
| 4033 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4034 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4035 | case BTM_LE_OOB_REQ_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4036 | sec_event.ble_req.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4037 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_OOB_REQ_EVT, &sec_event); |
| 4038 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4039 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4040 | case BTM_LE_NC_REQ_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4041 | sec_event.key_notif.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4042 | strlcpy((char*)sec_event.key_notif.bd_name, bta_dm_get_remname(), |
| 4043 | (BD_NAME_LEN)); |
| 4044 | sec_event.key_notif.passkey = p_data->key_notif; |
| 4045 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_NC_REQ_EVT, &sec_event); |
| 4046 | break; |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 4047 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4048 | case BTM_LE_SC_OOB_REQ_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4049 | sec_event.ble_req.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4050 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_SC_OOB_REQ_EVT, &sec_event); |
| 4051 | break; |
Jakub Pawlowski | bd60854 | 2016-07-28 05:58:35 -0700 | [diff] [blame] | 4052 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4053 | case BTM_LE_KEY_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4054 | sec_event.ble_key.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4055 | sec_event.ble_key.key_type = p_data->key.key_type; |
| 4056 | sec_event.ble_key.p_key_value = p_data->key.p_key_value; |
| 4057 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_KEY_EVT, &sec_event); |
| 4058 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4059 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4060 | case BTM_LE_COMPLT_EVT: |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4061 | sec_event.auth_cmpl.bd_addr = bda; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4062 | BTM_ReadDevInfo(bda, &sec_event.auth_cmpl.dev_type, |
| 4063 | &sec_event.auth_cmpl.addr_type); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4064 | p_name = BTM_SecReadDevName(bda); |
| 4065 | if (p_name != NULL) |
| 4066 | strlcpy((char*)sec_event.auth_cmpl.bd_name, p_name, (BD_NAME_LEN)); |
| 4067 | else |
| 4068 | sec_event.auth_cmpl.bd_name[0] = 0; |
Andre Eisenbach | 5b9462d | 2016-02-08 11:34:00 -0800 | [diff] [blame] | 4069 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4070 | if (p_data->complt.reason != 0) { |
| 4071 | sec_event.auth_cmpl.fail_reason = |
| 4072 | BTA_DM_AUTH_CONVERT_SMP_CODE(((uint8_t)p_data->complt.reason)); |
| 4073 | /* delete this device entry from Sec Dev DB */ |
| 4074 | bta_dm_remove_sec_dev_entry(bda); |
| 4075 | } else { |
| 4076 | sec_event.auth_cmpl.success = true; |
| 4077 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 4078 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4079 | if (bta_dm_cb.p_sec_cback) { |
| 4080 | // bta_dm_cb.p_sec_cback(BTA_DM_AUTH_CMPL_EVT, &sec_event); |
| 4081 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_AUTH_CMPL_EVT, &sec_event); |
| 4082 | } |
| 4083 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4084 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4085 | default: |
| 4086 | status = BTM_NOT_AUTHORIZED; |
| 4087 | break; |
| 4088 | } |
| 4089 | return status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4090 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4091 | |
| 4092 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4093 | * |
| 4094 | * Function bta_dm_ble_id_key_cback |
| 4095 | * |
| 4096 | * Description Callback for BLE local ID keys |
| 4097 | * |
| 4098 | * |
| 4099 | * Returns void |
| 4100 | * |
| 4101 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4102 | static void bta_dm_ble_id_key_cback(uint8_t key_type, |
| 4103 | tBTM_BLE_LOCAL_KEYS* p_key) { |
| 4104 | uint8_t evt; |
| 4105 | tBTA_DM_SEC dm_key; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4106 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4107 | switch (key_type) { |
| 4108 | case BTM_BLE_KEY_TYPE_ID: |
| 4109 | case BTM_BLE_KEY_TYPE_ER: |
| 4110 | if (bta_dm_cb.p_sec_cback) { |
| 4111 | 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] | 4112 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4113 | evt = (key_type == BTM_BLE_KEY_TYPE_ID) ? BTA_DM_BLE_LOCAL_IR_EVT |
| 4114 | : BTA_DM_BLE_LOCAL_ER_EVT; |
| 4115 | bta_dm_cb.p_sec_cback(evt, &dm_key); |
| 4116 | } |
| 4117 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4118 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4119 | default: |
| 4120 | APPL_TRACE_DEBUG("Unknown key type %d", key_type); |
| 4121 | break; |
| 4122 | } |
| 4123 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4124 | } |
| 4125 | |
| 4126 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4127 | * |
| 4128 | * Function bta_dm_add_blekey |
| 4129 | * |
| 4130 | * Description This function adds an BLE Key to an security database entry. |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4131 | * This function shall only be called AFTER BTA_DmAddBleDevice |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 4132 | * has been called. |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4133 | * It is normally called during host startup to restore all |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 4134 | * required information stored in the NVRAM. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4135 | * |
| 4136 | * Parameters: |
| 4137 | * |
| 4138 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4139 | void bta_dm_add_blekey(tBTA_DM_MSG* p_data) { |
| 4140 | if (!BTM_SecAddBleKey(p_data->add_ble_key.bd_addr, |
| 4141 | (tBTM_LE_KEY_VALUE*)&p_data->add_ble_key.blekey, |
| 4142 | p_data->add_ble_key.key_type)) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4143 | LOG(ERROR) << "BTA_DM: Error adding BLE Key for device " |
| 4144 | << p_data->add_ble_key.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4145 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4146 | } |
| 4147 | |
| 4148 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4149 | * |
| 4150 | * Function bta_dm_add_ble_device |
| 4151 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4152 | * Description This function adds an BLE device to an security database |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 4153 | * entry. |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4154 | * It is normally called during host startup to restore all |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 4155 | * required information stored in the NVRAM. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4156 | * |
| 4157 | * Parameters: |
| 4158 | * |
| 4159 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4160 | void bta_dm_add_ble_device(tBTA_DM_MSG* p_data) { |
| 4161 | if (!BTM_SecAddBleDevice(p_data->add_ble_device.bd_addr, NULL, |
| 4162 | p_data->add_ble_device.dev_type, |
| 4163 | p_data->add_ble_device.addr_type)) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4164 | LOG(ERROR) << "BTA_DM: Error adding BLE Device for device " |
| 4165 | << p_data->add_ble_device.bd_addr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4166 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4167 | } |
| 4168 | |
| 4169 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4170 | * |
| 4171 | * Function bta_dm_add_ble_device |
| 4172 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4173 | * Description This function adds an BLE device to an security database |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 4174 | * entry. |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4175 | * It is normally called during host startup to restore all |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 4176 | * required information stored in the NVRAM. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4177 | * |
| 4178 | * Parameters: |
| 4179 | * |
| 4180 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4181 | void bta_dm_ble_passkey_reply(tBTA_DM_MSG* p_data) { |
| 4182 | if (p_data->pin_reply.accept) { |
| 4183 | BTM_BlePasskeyReply(p_data->ble_passkey_reply.bd_addr, BTM_SUCCESS, |
| 4184 | p_data->ble_passkey_reply.passkey); |
| 4185 | } else { |
| 4186 | BTM_BlePasskeyReply(p_data->ble_passkey_reply.bd_addr, BTM_NOT_AUTHORIZED, |
| 4187 | p_data->ble_passkey_reply.passkey); |
| 4188 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4189 | } |
| 4190 | |
| 4191 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4192 | * |
| 4193 | * Function bta_dm_ble_confirm_reply |
| 4194 | * |
| 4195 | * Description This is response to SM numeric comparison request submitted |
| 4196 | * to application. |
| 4197 | * |
| 4198 | * Parameters: |
| 4199 | * |
| 4200 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4201 | void bta_dm_ble_confirm_reply(tBTA_DM_MSG* p_data) { |
| 4202 | if (p_data->confirm.accept) { |
| 4203 | BTM_BleConfirmReply(p_data->confirm.bd_addr, BTM_SUCCESS); |
| 4204 | } else { |
| 4205 | BTM_BleConfirmReply(p_data->ble_passkey_reply.bd_addr, BTM_NOT_AUTHORIZED); |
| 4206 | } |
Satya Calloji | 444a8da | 2015-03-06 10:38:22 -0800 | [diff] [blame] | 4207 | } |
| 4208 | |
| 4209 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4210 | * |
| 4211 | * Function bta_dm_security_grant |
| 4212 | * |
| 4213 | * Description This function grant SMP security request access. |
| 4214 | * |
| 4215 | * Parameters: |
| 4216 | * |
| 4217 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4218 | void bta_dm_security_grant(tBTA_DM_MSG* p_data) { |
| 4219 | 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] | 4220 | } |
| 4221 | |
| 4222 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4223 | * |
| 4224 | * Function bta_dm_ble_set_bg_conn_type |
| 4225 | * |
| 4226 | * Description This function set the BLE background connection type |
| 4227 | * |
| 4228 | * Parameters: |
| 4229 | * |
| 4230 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4231 | 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] | 4232 | BTM_BleStartAutoConn(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4233 | } |
| 4234 | |
| 4235 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4236 | * |
| 4237 | * Function bta_dm_ble_set_conn_params |
| 4238 | * |
| 4239 | * Description This function set the preferred connection parameters. |
| 4240 | * |
| 4241 | * Parameters: |
| 4242 | * |
| 4243 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4244 | void bta_dm_ble_set_conn_params(tBTA_DM_MSG* p_data) { |
| 4245 | BTM_BleSetPrefConnParams(p_data->ble_set_conn_params.peer_bda, |
| 4246 | p_data->ble_set_conn_params.conn_int_min, |
| 4247 | p_data->ble_set_conn_params.conn_int_max, |
| 4248 | p_data->ble_set_conn_params.slave_latency, |
| 4249 | p_data->ble_set_conn_params.supervision_tout); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4250 | } |
| 4251 | |
| 4252 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4253 | * |
| 4254 | * Function bta_dm_ble_set_conn_scan_params |
| 4255 | * |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4256 | * Description This function set the preferred connection scan parameters. |
| 4257 | * |
| 4258 | * Parameters: |
| 4259 | * |
| 4260 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4261 | void bta_dm_ble_set_conn_scan_params(tBTA_DM_MSG* p_data) { |
| 4262 | BTM_BleSetConnScanParams(p_data->ble_set_conn_scan_params.scan_int, |
| 4263 | p_data->ble_set_conn_scan_params.scan_window); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4264 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4265 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4266 | * |
| 4267 | * Function bta_dm_ble_update_conn_params |
| 4268 | * |
| 4269 | * Description This function update LE connection parameters. |
| 4270 | * |
| 4271 | * Parameters: |
| 4272 | * |
| 4273 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4274 | void bta_dm_ble_update_conn_params(tBTA_DM_MSG* p_data) { |
| 4275 | if (!L2CA_UpdateBleConnParams(p_data->ble_update_conn_params.bd_addr, |
| 4276 | p_data->ble_update_conn_params.min_int, |
| 4277 | p_data->ble_update_conn_params.max_int, |
| 4278 | p_data->ble_update_conn_params.latency, |
| 4279 | p_data->ble_update_conn_params.timeout)) { |
| 4280 | APPL_TRACE_ERROR("Update connection parameters failed!"); |
| 4281 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4282 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4283 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 4284 | #if (BLE_PRIVACY_SPT == TRUE) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4285 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4286 | * |
| 4287 | * Function bta_dm_ble_config_local_privacy |
| 4288 | * |
| 4289 | * Description This function set the local device LE privacy settings. |
| 4290 | * |
| 4291 | * Parameters: |
| 4292 | * |
| 4293 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4294 | void bta_dm_ble_config_local_privacy(tBTA_DM_MSG* p_data) { |
| 4295 | BTM_BleConfigPrivacy(p_data->ble_local_privacy.privacy_enable); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4296 | } |
| 4297 | #endif |
VenkatRaghavan VijayaRaghavan | 76356ae | 2015-04-21 11:32:29 -0700 | [diff] [blame] | 4298 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 4299 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4300 | * |
| 4301 | * Function bta_dm_ble_observe |
| 4302 | * |
| 4303 | * Description This function set the preferred connection scan parameters. |
| 4304 | * |
| 4305 | * Parameters: |
| 4306 | * |
| 4307 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4308 | void bta_dm_ble_observe(tBTA_DM_MSG* p_data) { |
| 4309 | tBTM_STATUS status; |
| 4310 | if (p_data->ble_observe.start) { |
| 4311 | /*Save the callback to be called when a scan results are available */ |
| 4312 | 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] | 4313 | status = BTM_BleObserve(true, p_data->ble_observe.duration, |
| 4314 | bta_dm_observe_results_cb, bta_dm_observe_cmpl_cb); |
| 4315 | if (status != BTM_CMD_STARTED) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4316 | tBTA_DM_SEARCH data; |
| 4317 | APPL_TRACE_WARNING(" %s BTM_BleObserve failed. status %d", __func__, |
| 4318 | status); |
| 4319 | data.inq_cmpl.num_resps = 0; |
| 4320 | if (bta_dm_search_cb.p_scan_cback) { |
| 4321 | bta_dm_search_cb.p_scan_cback(BTA_DM_INQ_CMPL_EVT, &data); |
| 4322 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 4323 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4324 | } else { |
| 4325 | bta_dm_search_cb.p_scan_cback = NULL; |
| 4326 | BTM_BleObserve(false, 0, NULL, NULL); |
| 4327 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 4328 | } |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 4329 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4330 | * |
| 4331 | * Function bta_dm_ble_set_adv_params |
| 4332 | * |
| 4333 | * Description This function set the adv parameters. |
| 4334 | * |
| 4335 | * Parameters: |
| 4336 | * |
| 4337 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4338 | void bta_dm_ble_set_adv_params(uint16_t adv_int_min, uint16_t adv_int_max, |
| 4339 | tBLE_BD_ADDR* p_dir_bda) { |
| 4340 | BTM_BleSetAdvParams(adv_int_min, adv_int_max, p_dir_bda, |
| 4341 | BTA_DM_BLE_ADV_CHNL_MAP); |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 4342 | } |
Andre Eisenbach | eeeac99 | 2013-11-08 10:23:52 -0800 | [diff] [blame] | 4343 | |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 4344 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4345 | * |
| 4346 | * Function bta_dm_ble_set_data_length |
| 4347 | * |
| 4348 | * Description This function set the maximum transmission packet size |
| 4349 | * |
| 4350 | * Parameters |
| 4351 | * |
| 4352 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4353 | void bta_dm_ble_set_data_length(tBTA_DM_MSG* p_data) { |
| 4354 | if (BTM_SetBleDataLength(p_data->ble_set_data_length.remote_bda, |
| 4355 | p_data->ble_set_data_length.tx_data_length) != |
| 4356 | BTM_SUCCESS) { |
| 4357 | APPL_TRACE_ERROR("%s failed", __func__); |
| 4358 | } |
Priti Aghera | 636d671 | 2014-12-18 13:55:48 -0800 | [diff] [blame] | 4359 | } |
| 4360 | |
| 4361 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4362 | * |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4363 | * Function bta_ble_enable_scan_cmpl |
| 4364 | * |
| 4365 | * Description ADV payload filtering enable / disable complete callback |
| 4366 | * |
| 4367 | * |
| 4368 | * Returns None |
| 4369 | * |
| 4370 | ******************************************************************************/ |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 4371 | 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] | 4372 | tBTM_BLE_RX_TIME_MS rx_time, |
| 4373 | tBTM_BLE_IDLE_TIME_MS idle_time, |
| 4374 | tBTM_BLE_ENERGY_USED energy_used, |
| 4375 | tBTM_STATUS status) { |
| 4376 | tBTA_STATUS st = (status == BTM_SUCCESS) ? BTA_SUCCESS : BTA_FAILURE; |
| 4377 | tBTA_DM_CONTRL_STATE ctrl_state = 0; |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 4378 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4379 | if (BTA_SUCCESS == st) ctrl_state = bta_dm_pm_obtain_controller_state(); |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 4380 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4381 | if (bta_dm_cb.p_energy_info_cback) |
| 4382 | bta_dm_cb.p_energy_info_cback(tx_time, rx_time, idle_time, energy_used, |
| 4383 | ctrl_state, st); |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 4384 | } |
| 4385 | |
| 4386 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4387 | * |
| 4388 | * Function bta_dm_ble_get_energy_info |
| 4389 | * |
| 4390 | * Description This function obtains the energy info |
| 4391 | * |
| 4392 | * Parameters: |
| 4393 | * |
| 4394 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4395 | void bta_dm_ble_get_energy_info(tBTA_DM_MSG* p_data) { |
| 4396 | tBTM_STATUS btm_status = 0; |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 4397 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4398 | bta_dm_cb.p_energy_info_cback = p_data->ble_energy_info.p_energy_info_cback; |
| 4399 | btm_status = BTM_BleGetEnergyInfo(bta_ble_energy_info_cmpl); |
| 4400 | if (BTM_CMD_STARTED != btm_status) |
| 4401 | bta_ble_energy_info_cmpl(0, 0, 0, 0, btm_status); |
Prerepa Viswanadham | 16fe082 | 2014-08-07 11:38:06 -0700 | [diff] [blame] | 4402 | } |
| 4403 | |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 4404 | #ifndef BTA_DM_GATT_CLOSE_DELAY_TOUT |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4405 | #define BTA_DM_GATT_CLOSE_DELAY_TOUT 1000 |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 4406 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4407 | |
| 4408 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4409 | * |
| 4410 | * Function bta_dm_gattc_register |
| 4411 | * |
| 4412 | * Description Register with GATTC in DM if BLE is needed. |
| 4413 | * |
| 4414 | * |
| 4415 | * Returns void |
| 4416 | * |
| 4417 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4418 | static void bta_dm_gattc_register(void) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4419 | if (bta_dm_search_cb.client_if == BTA_GATTS_INVALID_IF) { |
Jakub Pawlowski | 221e9bf | 2016-12-15 14:35:15 -0800 | [diff] [blame] | 4420 | BTA_GATTC_AppRegister(bta_dm_gattc_callback, |
| 4421 | base::Bind([](uint8_t client_id, uint8_t status) { |
Jakub Pawlowski | e9ef00c | 2017-09-25 17:41:21 -0700 | [diff] [blame] | 4422 | if (status == GATT_SUCCESS) |
Jakub Pawlowski | 221e9bf | 2016-12-15 14:35:15 -0800 | [diff] [blame] | 4423 | bta_dm_search_cb.client_if = client_id; |
| 4424 | else |
| 4425 | bta_dm_search_cb.client_if = BTA_GATTS_INVALID_IF; |
| 4426 | |
| 4427 | })); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4428 | } |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 4429 | } |
| 4430 | |
| 4431 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4432 | * |
| 4433 | * Function btm_dm_start_disc_gatt_services |
| 4434 | * |
| 4435 | * Description This function starts a GATT service search request. |
| 4436 | * |
| 4437 | * Parameters: |
| 4438 | * |
| 4439 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4440 | static void btm_dm_start_disc_gatt_services(uint16_t conn_id) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 4441 | Uuid* p_uuid = bta_dm_search_cb.p_srvc_uuid + bta_dm_search_cb.num_uuid - |
| 4442 | bta_dm_search_cb.uuid_to_search; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4443 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4444 | /* always search for all services */ |
| 4445 | BTA_GATTC_ServiceSearchRequest(conn_id, p_uuid); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4446 | } |
| 4447 | |
| 4448 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4449 | * |
| 4450 | * Function bta_dm_gatt_disc_result |
| 4451 | * |
| 4452 | * Description This function process the GATT service search result. |
| 4453 | * |
| 4454 | * Parameters: |
| 4455 | * |
| 4456 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4457 | static void bta_dm_gatt_disc_result(tBTA_GATT_ID service_id) { |
| 4458 | tBTA_DM_SEARCH result; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4459 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4460 | /* |
Andre Eisenbach | 1f5ec73 | 2017-04-13 14:49:36 -0700 | [diff] [blame] | 4461 | * 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] | 4462 | * bluetooth profiles here |
Andre Eisenbach | 1f5ec73 | 2017-04-13 14:49:36 -0700 | [diff] [blame] | 4463 | * just copy the GATTID in raw data field and send it across. |
| 4464 | */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4465 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4466 | if (bta_dm_search_cb.ble_raw_used + sizeof(tBTA_GATT_ID) < |
| 4467 | bta_dm_search_cb.ble_raw_size) { |
| 4468 | APPL_TRACE_DEBUG( |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 4469 | "ADDING BLE SERVICE uuid=%s, ble_ptr = 0x%x, ble_raw_used = 0x%x", |
| 4470 | service_id.uuid.ToString().c_str(), bta_dm_search_cb.p_ble_rawdata, |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4471 | bta_dm_search_cb.ble_raw_used); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4472 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4473 | if (bta_dm_search_cb.p_ble_rawdata) { |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 4474 | // TODO(jpawlowski): the p_ble_raw data is only sent to btif_dm.cc, but is |
| 4475 | // never used there. Get rid of this code completly, or implement the |
| 4476 | // TODOs from btif_dm.cc |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4477 | memcpy((bta_dm_search_cb.p_ble_rawdata + bta_dm_search_cb.ble_raw_used), |
| 4478 | &service_id, sizeof(service_id)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4479 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4480 | bta_dm_search_cb.ble_raw_used += sizeof(service_id); |
| 4481 | } else { |
| 4482 | APPL_TRACE_ERROR("p_ble_rawdata is NULL"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4483 | } |
| 4484 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4485 | } else { |
| 4486 | APPL_TRACE_ERROR( |
| 4487 | "%s out of room to accomodate more service ids ble_raw_size = %d " |
| 4488 | "ble_raw_used = %d", |
| 4489 | __func__, bta_dm_search_cb.ble_raw_size, bta_dm_search_cb.ble_raw_used); |
| 4490 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4491 | |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 4492 | LOG_INFO(LOG_TAG, "%s service_id_uuid_len=%zu", __func__, |
| 4493 | service_id.uuid.GetShortestRepresentationSize()); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4494 | if (bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE) { |
| 4495 | /* send result back to app now, one by one */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4496 | result.disc_ble_res.bd_addr = bta_dm_search_cb.peer_bdaddr; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4497 | strlcpy((char*)result.disc_ble_res.bd_name, bta_dm_get_remname(), |
| 4498 | BD_NAME_LEN); |
Jakub Pawlowski | 819e2ec | 2017-07-10 09:56:09 -0700 | [diff] [blame] | 4499 | result.disc_ble_res.service = service_id.uuid; |
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 | bta_dm_search_cb.p_search_cback(BTA_DM_DISC_BLE_RES_EVT, &result); |
| 4502 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4503 | } |
| 4504 | |
| 4505 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4506 | * |
| 4507 | * Function bta_dm_gatt_disc_complete |
| 4508 | * |
| 4509 | * Description This function process the GATT service search complete. |
| 4510 | * |
| 4511 | * Parameters: |
| 4512 | * |
| 4513 | ******************************************************************************/ |
Jakub Pawlowski | e9ef00c | 2017-09-25 17:41:21 -0700 | [diff] [blame] | 4514 | static void bta_dm_gatt_disc_complete(uint16_t conn_id, tGATT_STATUS status) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4515 | 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] | 4516 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4517 | 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] | 4518 | |
Jakub Pawlowski | e9ef00c | 2017-09-25 17:41:21 -0700 | [diff] [blame] | 4519 | if (status == GATT_SUCCESS && bta_dm_search_cb.uuid_to_search > 0) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4520 | btm_dm_start_disc_gatt_services(conn_id); |
| 4521 | } else { |
| 4522 | tBTA_DM_MSG* p_msg = (tBTA_DM_MSG*)osi_malloc(sizeof(tBTA_DM_MSG)); |
| 4523 | |
| 4524 | bta_dm_search_cb.uuid_to_search = 0; |
| 4525 | |
| 4526 | /* no more services to be discovered */ |
| 4527 | p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT; |
| 4528 | p_msg->disc_result.result.disc_res.result = |
Jakub Pawlowski | e9ef00c | 2017-09-25 17:41:21 -0700 | [diff] [blame] | 4529 | (status == GATT_SUCCESS) ? BTA_SUCCESS : BTA_FAILURE; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4530 | APPL_TRACE_DEBUG("%s service found: 0x%08x", __func__, |
| 4531 | bta_dm_search_cb.services_found); |
| 4532 | p_msg->disc_result.result.disc_res.services = |
| 4533 | bta_dm_search_cb.services_found; |
| 4534 | p_msg->disc_result.result.disc_res.num_uuids = 0; |
| 4535 | p_msg->disc_result.result.disc_res.p_uuid_list = NULL; |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4536 | 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] | 4537 | strlcpy((char*)p_msg->disc_result.result.disc_res.bd_name, |
| 4538 | bta_dm_get_remname(), BD_NAME_LEN); |
| 4539 | |
| 4540 | p_msg->disc_result.result.disc_res.device_type |= BT_DEVICE_TYPE_BLE; |
| 4541 | if (bta_dm_search_cb.ble_raw_used > 0) { |
| 4542 | p_msg->disc_result.result.disc_res.p_raw_data = |
| 4543 | (uint8_t*)osi_malloc(bta_dm_search_cb.ble_raw_used); |
| 4544 | |
| 4545 | memcpy(p_msg->disc_result.result.disc_res.p_raw_data, |
| 4546 | bta_dm_search_cb.p_ble_rawdata, bta_dm_search_cb.ble_raw_used); |
| 4547 | |
| 4548 | p_msg->disc_result.result.disc_res.raw_data_size = |
| 4549 | bta_dm_search_cb.ble_raw_used; |
Pavlin Radoslavov | 717a4a9 | 2016-02-06 08:36:06 -0800 | [diff] [blame] | 4550 | } else { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4551 | p_msg->disc_result.result.disc_res.p_raw_data = NULL; |
| 4552 | bta_dm_search_cb.p_ble_rawdata = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4553 | } |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4554 | |
| 4555 | bta_sys_sendmsg(p_msg); |
| 4556 | |
Jakub Pawlowski | e9ef00c | 2017-09-25 17:41:21 -0700 | [diff] [blame] | 4557 | if (conn_id != GATT_INVALID_CONN_ID) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4558 | /* start a GATT channel close delay timer */ |
| 4559 | bta_sys_start_timer(bta_dm_search_cb.gatt_close_timer, |
| 4560 | BTA_DM_GATT_CLOSE_DELAY_TOUT, |
| 4561 | BTA_DM_DISC_CLOSE_TOUT_EVT, 0); |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4562 | 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] | 4563 | } |
| 4564 | bta_dm_search_cb.gatt_disc_active = false; |
| 4565 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4566 | } |
| 4567 | |
| 4568 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4569 | * |
| 4570 | * Function bta_dm_close_gatt_conn |
| 4571 | * |
Jakub Pawlowski | 221e9bf | 2016-12-15 14:35:15 -0800 | [diff] [blame] | 4572 | * Description This function close the GATT connection after delay |
| 4573 | *timeout. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4574 | * |
| 4575 | * Parameters: |
| 4576 | * |
| 4577 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4578 | void bta_dm_close_gatt_conn(UNUSED_ATTR tBTA_DM_MSG* p_data) { |
Jakub Pawlowski | e9ef00c | 2017-09-25 17:41:21 -0700 | [diff] [blame] | 4579 | if (bta_dm_search_cb.conn_id != GATT_INVALID_CONN_ID) |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4580 | BTA_GATTC_Close(bta_dm_search_cb.conn_id); |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 4581 | |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame] | 4582 | bta_dm_search_cb.pending_close_bda = RawAddress::kEmpty; |
Jakub Pawlowski | e9ef00c | 2017-09-25 17:41:21 -0700 | [diff] [blame] | 4583 | bta_dm_search_cb.conn_id = GATT_INVALID_CONN_ID; |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 4584 | } |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 4585 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4586 | * |
| 4587 | * Function btm_dm_start_gatt_discovery |
| 4588 | * |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4589 | * Description This is GATT initiate the service search by open a GATT |
Myles Watson | 1baaae3 | 2016-11-09 14:25:23 -0800 | [diff] [blame] | 4590 | * connection first. |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4591 | * |
| 4592 | * Parameters: |
| 4593 | * |
| 4594 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 4595 | void btm_dm_start_gatt_discovery(const RawAddress& bd_addr) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4596 | bta_dm_search_cb.gatt_disc_active = true; |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 4597 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4598 | /* connection is already open */ |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4599 | if (bta_dm_search_cb.pending_close_bda == bd_addr && |
Jakub Pawlowski | e9ef00c | 2017-09-25 17:41:21 -0700 | [diff] [blame] | 4600 | bta_dm_search_cb.conn_id != GATT_INVALID_CONN_ID) { |
Jakub Pawlowski | b707f44 | 2017-07-03 15:39:36 -0700 | [diff] [blame] | 4601 | bta_dm_search_cb.pending_close_bda = RawAddress::kEmpty; |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4602 | alarm_cancel(bta_dm_search_cb.gatt_close_timer); |
| 4603 | btm_dm_start_disc_gatt_services(bta_dm_search_cb.conn_id); |
Jakub Pawlowski | 16bb48b | 2017-05-25 09:09:12 -0700 | [diff] [blame] | 4604 | } else { |
| 4605 | if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE)) { |
| 4606 | BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, true, |
Jakub Pawlowski | 50ba903 | 2017-09-26 08:45:20 -0700 | [diff] [blame] | 4607 | GATT_TRANSPORT_LE, true); |
Jakub Pawlowski | 16bb48b | 2017-05-25 09:09:12 -0700 | [diff] [blame] | 4608 | } else { |
| 4609 | BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, true, |
Jakub Pawlowski | 50ba903 | 2017-09-26 08:45:20 -0700 | [diff] [blame] | 4610 | GATT_TRANSPORT_LE, false); |
Jakub Pawlowski | 16bb48b | 2017-05-25 09:09:12 -0700 | [diff] [blame] | 4611 | } |
| 4612 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4613 | } |
| 4614 | |
| 4615 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4616 | * |
| 4617 | * Function bta_dm_cancel_gatt_discovery |
| 4618 | * |
| 4619 | * Description This is GATT cancel the GATT service search. |
| 4620 | * |
| 4621 | * Parameters: |
| 4622 | * |
| 4623 | ******************************************************************************/ |
Jakub Pawlowski | a484a88 | 2017-06-24 17:30:18 -0700 | [diff] [blame] | 4624 | static void bta_dm_cancel_gatt_discovery(const RawAddress& bd_addr) { |
Jakub Pawlowski | e9ef00c | 2017-09-25 17:41:21 -0700 | [diff] [blame] | 4625 | if (bta_dm_search_cb.conn_id == GATT_INVALID_CONN_ID) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4626 | BTA_GATTC_CancelOpen(bta_dm_search_cb.client_if, bd_addr, true); |
| 4627 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4628 | |
Jakub Pawlowski | e9ef00c | 2017-09-25 17:41:21 -0700 | [diff] [blame] | 4629 | bta_dm_gatt_disc_complete(bta_dm_search_cb.conn_id, (tGATT_STATUS)GATT_ERROR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4630 | } |
| 4631 | |
| 4632 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4633 | * |
| 4634 | * Function bta_dm_proc_open_evt |
| 4635 | * |
| 4636 | * Description process BTA_GATTC_OPEN_EVT in DM. |
| 4637 | * |
| 4638 | * Parameters: |
| 4639 | * |
| 4640 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4641 | void bta_dm_proc_open_evt(tBTA_GATTC_OPEN* p_data) { |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4642 | VLOG(1) << "DM Search state= " << bta_dm_search_cb.state |
| 4643 | << " search_cb.peer_dbaddr:" << bta_dm_search_cb.peer_bdaddr |
| 4644 | << " connected_bda=" << p_data->remote_bda.address; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4645 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4646 | APPL_TRACE_DEBUG("BTA_GATTC_OPEN_EVT conn_id = %d client_if=%d status = %d", |
| 4647 | 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] | 4648 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4649 | 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] | 4650 | |
Jakub Pawlowski | e9ef00c | 2017-09-25 17:41:21 -0700 | [diff] [blame] | 4651 | if (p_data->status == GATT_SUCCESS) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4652 | btm_dm_start_disc_gatt_services(p_data->conn_id); |
| 4653 | } else { |
Jakub Pawlowski | e9ef00c | 2017-09-25 17:41:21 -0700 | [diff] [blame] | 4654 | bta_dm_gatt_disc_complete(GATT_INVALID_CONN_ID, p_data->status); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4655 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4659 | * |
| 4660 | * Function bta_dm_gattc_callback |
| 4661 | * |
| 4662 | * Description This is GATT client callback function used in DM. |
| 4663 | * |
| 4664 | * Parameters: |
| 4665 | * |
| 4666 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4667 | static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data) { |
| 4668 | 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] | 4669 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4670 | switch (event) { |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4671 | case BTA_GATTC_OPEN_EVT: |
| 4672 | bta_dm_proc_open_evt(&p_data->open); |
| 4673 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4674 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4675 | case BTA_GATTC_SEARCH_RES_EVT: |
| 4676 | bta_dm_gatt_disc_result(p_data->srvc_res.service_uuid); |
| 4677 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4678 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4679 | case BTA_GATTC_SEARCH_CMPL_EVT: |
| 4680 | if (bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE) |
| 4681 | bta_dm_gatt_disc_complete(p_data->search_cmpl.conn_id, |
| 4682 | p_data->search_cmpl.status); |
| 4683 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4684 | |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4685 | case BTA_GATTC_CLOSE_EVT: |
| 4686 | APPL_TRACE_DEBUG("BTA_GATTC_CLOSE_EVT reason = %d", p_data->close.reason); |
| 4687 | /* in case of disconnect before search is completed */ |
| 4688 | if ((bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE) && |
| 4689 | (bta_dm_search_cb.state != BTA_DM_SEARCH_ACTIVE) && |
Jakub Pawlowski | c2276b0 | 2017-06-09 16:00:25 -0700 | [diff] [blame] | 4690 | p_data->close.remote_bda == bta_dm_search_cb.peer_bdaddr) { |
Jakub Pawlowski | e9ef00c | 2017-09-25 17:41:21 -0700 | [diff] [blame] | 4691 | bta_dm_gatt_disc_complete((uint16_t)GATT_INVALID_CONN_ID, |
| 4692 | (tGATT_STATUS)GATT_ERROR); |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4693 | } |
| 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 | default: |
| 4697 | break; |
| 4698 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4699 | } |
Satya Calloji | c4e2596 | 2014-05-10 23:46:24 -0700 | [diff] [blame] | 4700 | |
Marie Janssen | e9e58ce | 2016-06-17 14:12:17 -0700 | [diff] [blame] | 4701 | #if (BLE_VND_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 4702 | /******************************************************************************* |
Myles Watson | 8af480e | 2016-11-09 10:40:23 -0800 | [diff] [blame] | 4703 | * |
| 4704 | * Function bta_dm_ctrl_features_rd_cmpl_cback |
| 4705 | * |
| 4706 | * Description callback to handle controller feature read complete |
| 4707 | * |
| 4708 | * Parameters: |
| 4709 | * |
| 4710 | ******************************************************************************/ |
Myles Watson | cd1fd07 | 2016-11-09 13:17:43 -0800 | [diff] [blame] | 4711 | static void bta_dm_ctrl_features_rd_cmpl_cback(tBTM_STATUS result) { |
| 4712 | APPL_TRACE_DEBUG("%s status = %d ", __func__, result); |
| 4713 | if (result == BTM_SUCCESS) { |
| 4714 | if (bta_dm_cb.p_sec_cback) |
| 4715 | bta_dm_cb.p_sec_cback(BTA_DM_LE_FEATURES_READ, NULL); |
| 4716 | } else { |
| 4717 | APPL_TRACE_ERROR("%s Ctrl BLE feature read failed: status :%d", __func__, |
| 4718 | result); |
| 4719 | } |
Ganesh Ganapathi Batta | 8d41691 | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 4720 | } |
Bernhard Rosenkränzer | 104e3f2 | 2014-11-12 21:53:08 +0100 | [diff] [blame] | 4721 | #endif /* BLE_VND_INCLUDED */ |