The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2003-2012 Broadcom Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
| 19 | /****************************************************************************** |
| 20 | * |
| 21 | * This file contains the action functions for device manager state |
| 22 | * machine. |
| 23 | * |
| 24 | ******************************************************************************/ |
| 25 | |
Mike J. Chen | 597c577 | 2014-02-11 16:23:31 -0800 | [diff] [blame] | 26 | #include "bt_target.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 27 | #include "bt_types.h" |
| 28 | #include "gki.h" |
| 29 | #include "bd.h" |
| 30 | #include "bta_sys.h" |
| 31 | #include "bta_api.h" |
| 32 | #include "bta_dm_int.h" |
| 33 | #include "bta_dm_co.h" |
| 34 | #include "btm_api.h" |
| 35 | #include "btm_int.h" |
| 36 | #include "btu.h" |
| 37 | #include "sdp_api.h" |
| 38 | #include "l2c_api.h" |
| 39 | #include "wbt_api.h" |
| 40 | #include "utl.h" |
Kévin PETIT | 22c6e50 | 2014-02-12 17:24:01 +0000 | [diff] [blame] | 41 | #include "gap_api.h" /* For GAP_BleReadPeerPrefConnParams */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 42 | #include <string.h> |
| 43 | |
Mike J. Chen | a02a48c | 2014-01-31 17:49:43 -0800 | [diff] [blame] | 44 | #if (GAP_INCLUDED == TRUE) |
| 45 | #include "gap_api.h" |
| 46 | #endif |
| 47 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 48 | static void bta_dm_inq_results_cb (tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir); |
| 49 | static void bta_dm_inq_cmpl_cb (void * p_result); |
| 50 | static void bta_dm_service_search_remname_cback (BD_ADDR bd_addr, DEV_CLASS dc, BD_NAME bd_name); |
| 51 | static void bta_dm_remname_cback (tBTM_REMOTE_DEV_NAME *p_remote_name); |
| 52 | static void bta_dm_find_services ( BD_ADDR bd_addr); |
| 53 | static void bta_dm_discover_next_device(void); |
| 54 | static void bta_dm_sdp_callback (UINT16 sdp_status); |
| 55 | static UINT8 bta_dm_authorize_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, UINT8 *service_name, UINT8 service_id, BOOLEAN is_originator); |
| 56 | static UINT8 bta_dm_pin_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name); |
| 57 | static UINT8 bta_dm_link_key_request_cback (BD_ADDR bd_addr, LINK_KEY key); |
| 58 | static UINT8 bta_dm_new_link_key_cback(BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, LINK_KEY key, UINT8 key_type); |
| 59 | static UINT8 bta_dm_authentication_complete_cback(BD_ADDR bd_addr, DEV_CLASS dev_class,BD_NAME bd_name, int result); |
| 60 | static void bta_dm_local_name_cback(BD_ADDR bd_addr); |
| 61 | static BOOLEAN bta_dm_check_av(UINT16 event); |
| 62 | #if (BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
| 63 | static void bta_dm_bl_change_cback (tBTM_BL_EVENT_DATA *p_data); |
| 64 | #else |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 65 | static void bta_dm_acl_change_cback (BD_ADDR p_bda, DEV_CLASS p_dc, BD_NAME p_bdn, UINT8 *features, BOOLEAN is_new); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 66 | #endif |
| 67 | static void bta_dm_policy_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr); |
| 68 | |
| 69 | /* Extended Inquiry Response */ |
| 70 | static UINT8 bta_dm_sp_cback (tBTM_SP_EVT event, tBTM_SP_EVT_DATA *p_data); |
| 71 | |
| 72 | #if (BTM_EIR_SERVER_INCLUDED == TRUE) |
| 73 | static void bta_dm_set_eir (char *local_name); |
| 74 | #endif /* BTM_EIR_SERVER_INCLUDED */ |
| 75 | |
| 76 | #if (BTM_EIR_CLIENT_INCLUDED == TRUE) |
| 77 | static void bta_dm_eir_search_services( tBTM_INQ_RESULTS *p_result, |
| 78 | tBTA_SERVICE_MASK *p_services_to_search, |
| 79 | tBTA_SERVICE_MASK *p_services_found); |
| 80 | #endif /* BTM_EIR_CLIENT_INCLUDED */ |
| 81 | |
| 82 | static void bta_dm_rssi_cback (tBTM_RSSI_RESULTS *p_result); |
| 83 | static void bta_dm_signal_strength_timer_cback (TIMER_LIST_ENT *p_tle); |
| 84 | static void bta_dm_link_quality_cback (tBTM_LINK_QUALITY_RESULTS *p_result); |
| 85 | static void bta_dm_search_timer_cback (TIMER_LIST_ENT *p_tle); |
| 86 | static void bta_dm_disable_timer_cback (TIMER_LIST_ENT *p_tle); |
| 87 | static void bta_dm_disable_conn_down_timer_cback (TIMER_LIST_ENT *p_tle); |
| 88 | static void bta_dm_rm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr); |
| 89 | static void bta_dm_adjust_roles(BOOLEAN delay_role_switch); |
| 90 | static char *bta_dm_get_remname(void); |
| 91 | static void bta_dm_bond_cancel_complete_cback(tBTM_STATUS result); |
| 92 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 93 | static BOOLEAN bta_dm_read_remote_device_name (BD_ADDR bd_addr,tBT_TRANSPORT transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 94 | static void bta_dm_discover_device(BD_ADDR remote_bd_addr); |
| 95 | |
| 96 | static void bta_dm_sys_hw_cback( tBTA_SYS_HW_EVT status ); |
| 97 | |
| 98 | static BOOLEAN bta_dm_dev_blacklisted_for_switch (BD_ADDR remote_bd_addr); |
| 99 | static void bta_dm_delay_role_switch_cback (TIMER_LIST_ENT *p_tle); |
| 100 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 101 | static void bta_dm_disable_search_and_disc(void); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 102 | #if ((defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
| 103 | #if ((defined SMP_INCLUDED) && (SMP_INCLUDED == TRUE)) |
| 104 | static UINT8 bta_dm_ble_smp_cback (tBTM_LE_EVT event, BD_ADDR bda, tBTM_LE_EVT_DATA *p_data); |
| 105 | #endif |
| 106 | static void bta_dm_ble_id_key_cback (UINT8 key_type, tBTM_BLE_LOCAL_KEYS *p_key); |
| 107 | #if ((defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE)) |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 108 | static void bta_dm_gattc_register(void); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 109 | static void btm_dm_start_gatt_discovery ( BD_ADDR bd_addr); |
| 110 | static void bta_dm_cancel_gatt_discovery(BD_ADDR bd_addr); |
| 111 | static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC *p_data); |
| 112 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 113 | static void bta_dm_observe_results_cb (tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir); |
| 114 | static void bta_dm_observe_cmpl_cb (void * p_result); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 115 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 116 | #ifndef BTA_DM_BLE_ADV_CHNL_MAP |
| 117 | #define BTA_DM_BLE_ADV_CHNL_MAP (BTM_BLE_ADV_CHNL_37|BTM_BLE_ADV_CHNL_38|BTM_BLE_ADV_CHNL_39) |
| 118 | #endif |
| 119 | #endif |
Matthew Xie | f751b01 | 2013-08-13 20:05:34 -0700 | [diff] [blame] | 120 | static void bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr); |
| 121 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 122 | extern void sdpu_uuid16_to_uuid128(UINT16 uuid16, UINT8* p_uuid128); |
| 123 | |
| 124 | const UINT16 bta_service_id_to_uuid_lkup_tbl [BTA_MAX_SERVICE_ID] = |
| 125 | { |
| 126 | UUID_SERVCLASS_PNP_INFORMATION, /* Reserved */ |
| 127 | UUID_SERVCLASS_SERIAL_PORT, /* BTA_SPP_SERVICE_ID */ |
| 128 | UUID_SERVCLASS_DIALUP_NETWORKING, /* BTA_DUN_SERVICE_ID */ |
| 129 | UUID_SERVCLASS_AUDIO_SOURCE, /* BTA_A2DP_SOURCE_SERVICE_ID */ |
| 130 | UUID_SERVCLASS_LAN_ACCESS_USING_PPP, /* BTA_LAP_SERVICE_ID */ |
| 131 | UUID_SERVCLASS_HEADSET, /* BTA_HSP_HS_SERVICE_ID */ |
| 132 | UUID_SERVCLASS_HF_HANDSFREE, /* BTA_HFP_HS_SERVICE_ID */ |
| 133 | UUID_SERVCLASS_OBEX_OBJECT_PUSH, /* BTA_OPP_SERVICE_ID */ |
| 134 | UUID_SERVCLASS_OBEX_FILE_TRANSFER, /* BTA_FTP_SERVICE_ID */ |
| 135 | UUID_SERVCLASS_CORDLESS_TELEPHONY, /* BTA_CTP_SERVICE_ID */ |
| 136 | UUID_SERVCLASS_INTERCOM, /* BTA_ICP_SERVICE_ID */ |
| 137 | UUID_SERVCLASS_IRMC_SYNC, /* BTA_SYNC_SERVICE_ID */ |
| 138 | UUID_SERVCLASS_DIRECT_PRINTING, /* BTA_BPP_SERVICE_ID */ |
| 139 | UUID_SERVCLASS_IMAGING_RESPONDER, /* BTA_BIP_SERVICE_ID */ |
| 140 | UUID_SERVCLASS_PANU, /* BTA_PANU_SERVICE_ID */ |
| 141 | UUID_SERVCLASS_NAP, /* BTA_NAP_SERVICE_ID */ |
| 142 | UUID_SERVCLASS_GN, /* BTA_GN_SERVICE_ID */ |
| 143 | UUID_SERVCLASS_SAP, /* BTA_SAP_SERVICE_ID */ |
| 144 | UUID_SERVCLASS_AUDIO_SINK, /* BTA_A2DP_SERVICE_ID */ |
| 145 | UUID_SERVCLASS_AV_REMOTE_CONTROL, /* BTA_AVRCP_SERVICE_ID */ |
| 146 | UUID_SERVCLASS_HUMAN_INTERFACE, /* BTA_HID_SERVICE_ID */ |
| 147 | UUID_SERVCLASS_VIDEO_SINK, /* BTA_VDP_SERVICE_ID */ |
| 148 | UUID_SERVCLASS_PBAP_PSE, /* BTA_PBAP_SERVICE_ID */ |
| 149 | UUID_SERVCLASS_HEADSET_AUDIO_GATEWAY, /* BTA_HSP_SERVICE_ID */ |
| 150 | UUID_SERVCLASS_AG_HANDSFREE, /* BTA_HFP_SERVICE_ID */ |
| 151 | UUID_SERVCLASS_MESSAGE_ACCESS, /* BTA_MAP_SERVICE_ID */ |
| 152 | UUID_SERVCLASS_MESSAGE_NOTIFICATION, /* BTA_MN_SERVICE_ID */ |
| 153 | UUID_SERVCLASS_HDP_PROFILE, /* BTA_HDP_SERVICE_ID */ |
| 154 | UUID_SERVCLASS_PBAP_PCE /* BTA_PCE_SERVICE_ID */ |
| 155 | #if BLE_INCLUDED && BTA_GATT_INCLUDED |
| 156 | ,UUID_PROTOCOL_ATT /* BTA_GATT_SERVICE_ID */ |
| 157 | #endif |
| 158 | }; |
| 159 | |
| 160 | /* |
| 161 | * NOTE : The number of element in bta_service_id_to_btm_srv_id_lkup_tbl should be matching with |
| 162 | * the value BTA_MAX_SERVICE_ID in bta_api.h |
| 163 | * |
| 164 | * i.e., If you add new Service ID for BTA, the correct security ID of the new service |
| 165 | * from Security service definitions (btm_api.h) should be added to this lookup table. |
| 166 | */ |
| 167 | const UINT32 bta_service_id_to_btm_srv_id_lkup_tbl [BTA_MAX_SERVICE_ID] = |
| 168 | { |
| 169 | 0, /* Reserved */ |
| 170 | BTM_SEC_SERVICE_SERIAL_PORT, /* BTA_SPP_SERVICE_ID */ |
| 171 | BTM_SEC_SERVICE_DUN, /* BTA_DUN_SERVICE_ID */ |
| 172 | BTM_SEC_SERVICE_AVDTP, /* BTA_AUDIO_SOURCE_SERVICE_ID */ |
| 173 | BTM_SEC_SERVICE_LAN_ACCESS, /* BTA_LAP_SERVICE_ID */ |
| 174 | BTM_SEC_SERVICE_HEADSET_AG, /* BTA_HSP_SERVICE_ID */ |
| 175 | BTM_SEC_SERVICE_AG_HANDSFREE, /* BTA_HFP_SERVICE_ID */ |
| 176 | BTM_SEC_SERVICE_OBEX, /* BTA_OPP_SERVICE_ID */ |
| 177 | BTM_SEC_SERVICE_OBEX_FTP, /* BTA_FTP_SERVICE_ID */ |
| 178 | BTM_SEC_SERVICE_CORDLESS, /* BTA_CTP_SERVICE_ID */ |
| 179 | BTM_SEC_SERVICE_INTERCOM, /* BTA_ICP_SERVICE_ID */ |
| 180 | BTM_SEC_SERVICE_IRMC_SYNC, /* BTA_SYNC_SERVICE_ID */ |
| 181 | BTM_SEC_SERVICE_BPP_JOB, /* BTA_BPP_SERVICE_ID */ |
| 182 | BTM_SEC_SERVICE_BIP, /* BTA_BIP_SERVICE_ID */ |
| 183 | BTM_SEC_SERVICE_BNEP_PANU, /* BTA_PANU_SERVICE_ID */ |
| 184 | BTM_SEC_SERVICE_BNEP_NAP, /* BTA_NAP_SERVICE_ID */ |
| 185 | BTM_SEC_SERVICE_BNEP_GN, /* BTA_GN_SERVICE_ID */ |
| 186 | BTM_SEC_SERVICE_SAP, /* BTA_SAP_SERVICE_ID */ |
| 187 | BTM_SEC_SERVICE_AVDTP, /* BTA_A2DP_SERVICE_ID */ |
| 188 | BTM_SEC_SERVICE_AVCTP, /* BTA_AVRCP_SERVICE_ID */ |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 189 | BTM_SEC_SERVICE_HIDH_SEC_CTRL, /* BTA_HID_SERVICE_ID */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 190 | BTM_SEC_SERVICE_AVDTP, /* BTA_VDP_SERVICE_ID */ |
| 191 | BTM_SEC_SERVICE_PBAP, /* BTA_PBAP_SERVICE_ID */ |
| 192 | BTM_SEC_SERVICE_HEADSET, /* BTA_HSP_HS_SERVICE_ID */ |
| 193 | BTM_SEC_SERVICE_HF_HANDSFREE, /* BTA_HFP_HS_SERVICE_ID */ |
| 194 | BTM_SEC_SERVICE_MAP, /* BTA_MAP_SERVICE_ID */ |
| 195 | BTM_SEC_SERVICE_MAP, /* BTA_MN_SERVICE_ID */ |
| 196 | BTM_SEC_SERVICE_HDP_SNK, /* BTA_HDP_SERVICE_ID */ |
| 197 | BTM_SEC_SERVICE_PBAP /* BTA_PCE_SERVICE_ID */ |
| 198 | #if BLE_INCLUDED && BTA_GATT_INCLUDED |
| 199 | ,BTM_SEC_SERVICE_ATT /* BTA_GATT_SERVICE_ID */ |
| 200 | #endif |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 201 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | /* bta security callback */ |
| 205 | const tBTM_APPL_INFO bta_security = |
| 206 | { |
| 207 | &bta_dm_authorize_cback, |
| 208 | &bta_dm_pin_cback, |
| 209 | &bta_dm_new_link_key_cback, |
| 210 | &bta_dm_link_key_request_cback, |
| 211 | &bta_dm_authentication_complete_cback, |
| 212 | NULL, |
| 213 | &bta_dm_bond_cancel_complete_cback, |
| 214 | #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) |
| 215 | &bta_dm_sp_cback |
| 216 | #else |
| 217 | NULL |
| 218 | #endif |
| 219 | #if BLE_INCLUDED == TRUE |
| 220 | #if SMP_INCLUDED == TRUE |
| 221 | ,&bta_dm_ble_smp_cback |
| 222 | #endif |
| 223 | ,&bta_dm_ble_id_key_cback |
| 224 | #endif |
| 225 | |
| 226 | }; |
| 227 | |
| 228 | /* TBD... To be moved to some conf file..? */ |
| 229 | #define BTA_DM_MAX_ROLE_SWITCH_BLACKLIST_COUNT 5 |
| 230 | const tBTA_DM_LMP_VER_INFO bta_role_switch_blacklist[BTA_DM_MAX_ROLE_SWITCH_BLACKLIST_COUNT] = |
| 231 | { |
| 232 | {0x000F,0x2000,0x04}, |
| 233 | {0x00,0x00,0x00}, |
| 234 | {0x00,0x00,0x00}, |
| 235 | {0x00,0x00,0x00}, |
| 236 | {0x00,0x00,0x00} |
| 237 | }; |
| 238 | |
| 239 | #define MAX_DISC_RAW_DATA_BUF (4096) |
| 240 | UINT8 g_disc_raw_data_buf[MAX_DISC_RAW_DATA_BUF]; |
| 241 | |
| 242 | /******************************************************************************* |
| 243 | ** |
| 244 | ** Function bta_dm_app_ready_timer_cback |
| 245 | ** |
| 246 | ** Description allow sending EIR to controller |
| 247 | ** |
| 248 | ** |
| 249 | ** Returns void |
| 250 | ** |
| 251 | *******************************************************************************/ |
| 252 | #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&(BTA_EIR_CANNED_UUID_LIST != TRUE) |
| 253 | static void bta_dm_app_ready_timer_cback (TIMER_LIST_ENT *p_tle) |
| 254 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 255 | UNUSED(p_tle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 256 | bta_dm_set_eir (NULL); |
| 257 | } |
| 258 | #else |
| 259 | #define bta_dm_app_ready_timer_cback (x) |
| 260 | #endif |
| 261 | |
| 262 | /******************************************************************************* |
| 263 | ** |
| 264 | ** Function bta_dm_enable |
| 265 | ** |
| 266 | ** Description Initialises the BT device manager |
| 267 | ** |
| 268 | ** |
| 269 | ** Returns void |
| 270 | ** |
| 271 | *******************************************************************************/ |
| 272 | void bta_dm_enable(tBTA_DM_MSG *p_data) |
| 273 | { |
| 274 | tBTA_SYS_HW_MSG *sys_enable_event; |
| 275 | tBTA_DM_SEC sec_event; |
| 276 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 277 | /* if already in use, return an error */ |
| 278 | if( bta_dm_cb.is_bta_dm_active == TRUE ) |
| 279 | { |
| 280 | APPL_TRACE_WARNING0("bta_dm_enable - device already started by another application"); |
| 281 | memset(&sec_event.enable, 0, sizeof ( tBTA_DM_ENABLE )); |
| 282 | sec_event.enable.status = BTA_FAILURE; |
| 283 | if( p_data->enable.p_sec_cback != NULL ) |
| 284 | p_data->enable.p_sec_cback (BTA_DM_ENABLE_EVT, &sec_event); |
| 285 | return; |
| 286 | } |
| 287 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 288 | /* first, register our callback to SYS HW manager */ |
| 289 | bta_sys_hw_register( BTA_SYS_HW_BLUETOOTH, bta_dm_sys_hw_cback ); |
| 290 | |
| 291 | /* make sure security callback is saved - if no callback, do not erase the previous one, |
| 292 | it could be an error recovery mechanism */ |
| 293 | if( p_data->enable.p_sec_cback != NULL ) |
| 294 | bta_dm_cb.p_sec_cback = p_data->enable.p_sec_cback; |
| 295 | /* notify BTA DM is now active */ |
| 296 | bta_dm_cb.is_bta_dm_active = TRUE; |
| 297 | |
| 298 | /* send a message to BTA SYS */ |
| 299 | if ((sys_enable_event = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL) |
| 300 | { |
| 301 | sys_enable_event->hdr.event = BTA_SYS_API_ENABLE_EVT; |
| 302 | sys_enable_event->hw_module = BTA_SYS_HW_BLUETOOTH; |
| 303 | |
| 304 | bta_sys_sendmsg(sys_enable_event); |
| 305 | |
| 306 | } |
| 307 | |
| 308 | |
| 309 | |
| 310 | } |
| 311 | |
| 312 | |
| 313 | |
| 314 | /******************************************************************************* |
| 315 | ** |
| 316 | ** Function bta_dm_sys_hw_cback |
| 317 | ** |
| 318 | ** Description callback register to SYS to get HW status updates |
| 319 | ** |
| 320 | ** |
| 321 | ** Returns void |
| 322 | ** |
| 323 | *******************************************************************************/ |
| 324 | static void bta_dm_sys_hw_cback( tBTA_SYS_HW_EVT status ) |
| 325 | { |
| 326 | DEV_CLASS dev_class; |
| 327 | tBTA_DM_SEC_CBACK *temp_cback; |
| 328 | #if BLE_INCLUDED == TRUE |
| 329 | UINT8 key_mask = 0; |
| 330 | BT_OCTET16 er; |
| 331 | tBTA_BLE_LOCAL_ID_KEYS id_key; |
| 332 | tBT_UUID app_uuid = {LEN_UUID_128,{0}}; |
| 333 | #endif |
| 334 | APPL_TRACE_DEBUG1(" bta_dm_sys_hw_cback with event: %i" , status ); |
| 335 | |
| 336 | /* On H/W error evt, report to the registered DM application callback */ |
| 337 | if (status == BTA_SYS_HW_ERROR_EVT) { |
| 338 | if( bta_dm_cb.p_sec_cback != NULL ) |
| 339 | bta_dm_cb.p_sec_cback(BTA_DM_HW_ERROR_EVT, NULL); |
| 340 | return; |
| 341 | } |
| 342 | if( status == BTA_SYS_HW_OFF_EVT ) |
| 343 | { |
| 344 | if( bta_dm_cb.p_sec_cback != NULL ) |
| 345 | bta_dm_cb.p_sec_cback(BTA_DM_DISABLE_EVT, NULL); |
| 346 | |
| 347 | /* reinitialize the control block */ |
| 348 | memset(&bta_dm_cb, 0, sizeof(bta_dm_cb)); |
| 349 | |
| 350 | /* unregister from SYS */ |
| 351 | bta_sys_hw_unregister( BTA_SYS_HW_BLUETOOTH ); |
| 352 | /* notify BTA DM is now unactive */ |
| 353 | bta_dm_cb.is_bta_dm_active = FALSE; |
| 354 | } |
| 355 | else |
| 356 | if( status == BTA_SYS_HW_ON_EVT ) |
| 357 | { |
| 358 | /* FIXME: We should not unregister as the SYS shall invoke this callback on a H/W error. |
| 359 | * We need to revisit when this platform has more than one BLuetooth H/W chip */ |
| 360 | //bta_sys_hw_unregister( BTA_SYS_HW_BLUETOOTH); |
| 361 | |
| 362 | /* save security callback */ |
| 363 | temp_cback = bta_dm_cb.p_sec_cback; |
| 364 | /* make sure the control block is properly initialized */ |
| 365 | memset(&bta_dm_cb, 0, sizeof(bta_dm_cb)); |
| 366 | /* and retrieve the callback */ |
| 367 | bta_dm_cb.p_sec_cback=temp_cback; |
| 368 | bta_dm_cb.is_bta_dm_active = TRUE; |
| 369 | |
| 370 | /* hw is ready, go on with BTA DM initialization */ |
| 371 | memset(&bta_dm_search_cb, 0x00, sizeof(bta_dm_search_cb)); |
| 372 | memset(&bta_dm_conn_srvcs, 0x00, sizeof(bta_dm_conn_srvcs)); |
| 373 | memset(&bta_dm_di_cb, 0, sizeof(tBTA_DM_DI_CB)); |
| 374 | |
| 375 | memcpy(dev_class, bta_dm_cfg.dev_class, sizeof(dev_class)); |
| 376 | BTM_SetDeviceClass (dev_class); |
| 377 | |
| 378 | #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE) |
| 379 | /* load BLE local information: ID keys, ER if available */ |
| 380 | bta_dm_co_ble_load_local_keys(&key_mask, er, &id_key); |
| 381 | |
| 382 | if (key_mask & BTA_BLE_LOCAL_KEY_TYPE_ER) |
| 383 | { |
| 384 | BTM_BleLoadLocalKeys(BTA_BLE_LOCAL_KEY_TYPE_ER, (tBTM_BLE_LOCAL_KEYS *)&er); |
| 385 | } |
| 386 | if (key_mask & BTA_BLE_LOCAL_KEY_TYPE_ID) |
| 387 | { |
| 388 | BTM_BleLoadLocalKeys(BTA_BLE_LOCAL_KEY_TYPE_ID, (tBTM_BLE_LOCAL_KEYS *)&id_key); |
| 389 | } |
Mike J. Chen | 597c577 | 2014-02-11 16:23:31 -0800 | [diff] [blame] | 390 | #if ((defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE)) |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 391 | bta_dm_search_cb.conn_id = BTA_GATT_INVALID_CONN_ID; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 392 | #endif |
Mike J. Chen | 597c577 | 2014-02-11 16:23:31 -0800 | [diff] [blame] | 393 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 394 | |
| 395 | BTM_SecRegister((tBTM_APPL_INFO*)&bta_security); |
| 396 | BTM_SetDefaultLinkSuperTout(bta_dm_cfg.link_timeout); |
| 397 | BTM_WritePageTimeout(bta_dm_cfg.page_timeout); |
| 398 | bta_dm_cb.cur_policy = bta_dm_cfg.policy_settings; |
| 399 | BTM_SetDefaultLinkPolicy(bta_dm_cb.cur_policy); |
| 400 | #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
| 401 | BTM_RegBusyLevelNotif (bta_dm_bl_change_cback, NULL, BTM_BL_UPDATE_MASK|BTM_BL_ROLE_CHG_MASK); |
| 402 | #else |
| 403 | BTM_AclRegisterForChanges(bta_dm_acl_change_cback); |
| 404 | #endif |
| 405 | /* Earlier, we used to invoke BTM_ReadLocalAddr which was just copying the bd_addr |
| 406 | from the control block and invoking the callback which was sending the DM_ENABLE_EVT. |
| 407 | But then we have a few HCI commands being invoked above which were still in progress |
| 408 | when the ENABLE_EVT was sent. So modified this to fetch the local name which forces |
| 409 | the DM_ENABLE_EVT to be sent only after all the init steps are complete */ |
| 410 | BTM_ReadLocalDeviceNameFromController((tBTM_CMPL_CB *)bta_dm_local_name_cback); |
| 411 | |
| 412 | bta_sys_rm_register((tBTA_SYS_CONN_CBACK*)bta_dm_rm_cback); |
| 413 | |
| 414 | /* initialize bluetooth low power manager */ |
| 415 | bta_dm_init_pm(); |
| 416 | |
| 417 | bta_sys_policy_register((tBTA_SYS_CONN_CBACK*)bta_dm_policy_cback); |
| 418 | |
| 419 | |
| 420 | // BLUEDROID REMOVE ?? |
| 421 | #if 0 |
| 422 | #if 1 |
| 423 | /* Create broadcom primary DI record */ |
| 424 | if(WBT_ExtCreateRecord()) |
| 425 | { |
| 426 | #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&( BTA_EIR_CANNED_UUID_LIST != TRUE ) |
| 427 | /* while app_ready_timer is running, BTA DM doesn't send EIR to controller */ |
| 428 | bta_dm_cb.app_ready_timer.p_cback = (TIMER_CBACK*)&bta_dm_app_ready_timer_cback; |
| 429 | bta_sys_start_timer(&bta_dm_cb.app_ready_timer, 0, 100); |
| 430 | |
| 431 | bta_sys_add_uuid(UUID_SERVCLASS_PNP_INFORMATION); |
| 432 | #endif |
| 433 | bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = 0; /* primary DI record */ |
| 434 | bta_dm_di_cb.di_num ++; |
| 435 | } |
| 436 | #else /* Eventually implement pin code */ |
| 437 | if (WBT_ExtCreateRecord()) |
| 438 | WBT_ExtAddPinCode(); |
| 439 | #endif |
| 440 | #endif |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 441 | #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) |
| 442 | memset (&app_uuid.uu.uuid128, 0x87, LEN_UUID_128); |
| 443 | bta_dm_gattc_register(); |
| 444 | #endif |
| 445 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 446 | } |
| 447 | else |
| 448 | APPL_TRACE_DEBUG0(" --- ignored event"); |
| 449 | |
| 450 | } |
| 451 | |
| 452 | |
| 453 | /******************************************************************************* |
| 454 | ** |
| 455 | ** Function bta_dm_disable |
| 456 | ** |
| 457 | ** Description Disables the BT device manager |
| 458 | ** |
| 459 | ** |
| 460 | ** Returns void |
| 461 | ** |
| 462 | *******************************************************************************/ |
| 463 | void bta_dm_disable (tBTA_DM_MSG *p_data) |
| 464 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 465 | UNUSED(p_data); |
| 466 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 467 | /* Set l2cap idle timeout to 0 (so BTE immediately disconnects ACL link after last channel is closed) */ |
| 468 | L2CA_SetIdleTimeoutByBdAddr((UINT8 *)BT_BD_ANY, 0); |
| 469 | |
| 470 | /* disable all active subsystems */ |
| 471 | bta_sys_disable(BTA_SYS_HW_BLUETOOTH); |
| 472 | |
| 473 | BTM_SetDiscoverability(BTM_NON_DISCOVERABLE, 0, 0); |
| 474 | BTM_SetConnectability(BTM_NON_CONNECTABLE, 0, 0); |
| 475 | |
| 476 | bta_dm_disable_pm(); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 477 | bta_dm_disable_search_and_disc(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 478 | bta_dm_cb.disabling = TRUE; |
| 479 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 480 | |
| 481 | if(BTM_GetNumAclLinks()==0) |
| 482 | { |
| 483 | #if (defined(BTA_DISABLE_DELAY) && BTA_DISABLE_DELAY > 0) |
| 484 | /* If BTA_DISABLE_DELAY is defined and greater than zero, then delay the shutdown by |
| 485 | * BTA_DISABLE_DELAY milliseconds |
| 486 | */ |
| 487 | APPL_TRACE_WARNING2("%s BTA_DISABLE_DELAY set to %d ms", |
| 488 | __FUNCTION__, BTA_DISABLE_DELAY); |
| 489 | bta_sys_stop_timer(&bta_dm_cb.disable_timer); |
| 490 | bta_dm_cb.disable_timer.p_cback = (TIMER_CBACK*)&bta_dm_disable_conn_down_timer_cback; |
| 491 | bta_sys_start_timer(&bta_dm_cb.disable_timer, 0, BTA_DISABLE_DELAY); |
| 492 | #else |
| 493 | bta_dm_disable_conn_down_timer_cback(NULL); |
| 494 | #endif |
| 495 | } |
| 496 | else |
| 497 | { |
| 498 | bta_dm_cb.disable_timer.p_cback = (TIMER_CBACK*)&bta_dm_disable_timer_cback; |
| 499 | bta_sys_start_timer(&bta_dm_cb.disable_timer, 0, 5000); |
| 500 | } |
| 501 | |
| 502 | } |
| 503 | |
| 504 | /******************************************************************************* |
| 505 | ** |
| 506 | ** Function bta_dm_disable_timer_cback |
| 507 | ** |
| 508 | ** Description Called if the disable timer expires |
| 509 | ** Used to close ACL connections which are still active |
| 510 | ** |
| 511 | ** |
| 512 | ** |
| 513 | ** Returns void |
| 514 | ** |
| 515 | *******************************************************************************/ |
| 516 | static void bta_dm_disable_timer_cback (TIMER_LIST_ENT *p_tle) |
| 517 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 518 | UNUSED(p_tle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 519 | UINT8 i; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 520 | tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; |
| 521 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 522 | |
| 523 | APPL_TRACE_EVENT0(" bta_dm_disable_timer_cback "); |
| 524 | |
| 525 | if(BTM_GetNumAclLinks()) |
| 526 | { |
| 527 | for(i=0; i<bta_dm_cb.device_list.count; i++) |
| 528 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 529 | #if (BLE_INCLUDED == TRUE) |
| 530 | transport = bta_dm_cb.device_list.peer_device[i].transport; |
| 531 | #endif |
| 532 | btm_remove_acl(bta_dm_cb.device_list.peer_device[i].peer_bdaddr, transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | } |
| 536 | else |
| 537 | { |
| 538 | bta_dm_cb.disabling = FALSE; |
| 539 | |
| 540 | bta_sys_remove_uuid(UUID_SERVCLASS_PNP_INFORMATION); |
| 541 | bta_dm_cb.p_sec_cback(BTA_DM_DISABLE_EVT, NULL); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | /******************************************************************************* |
| 549 | ** |
| 550 | ** Function bta_dm_set_dev_name |
| 551 | ** |
| 552 | ** Description Sets local device name |
| 553 | ** |
| 554 | ** |
| 555 | ** Returns void |
| 556 | ** |
| 557 | *******************************************************************************/ |
| 558 | void bta_dm_set_dev_name (tBTA_DM_MSG *p_data) |
| 559 | { |
| 560 | |
| 561 | BTM_SetLocalDeviceName((char*)p_data->set_name.name); |
| 562 | #if (BTM_EIR_SERVER_INCLUDED == TRUE) |
| 563 | bta_dm_set_eir ((char*)p_data->set_name.name); |
| 564 | #endif |
| 565 | } |
| 566 | |
| 567 | /******************************************************************************* |
| 568 | ** |
| 569 | ** Function bta_dm_set_visibility |
| 570 | ** |
| 571 | ** Description Sets discoverability, connectability and pairability |
| 572 | ** |
| 573 | ** |
| 574 | ** Returns void |
| 575 | ** |
| 576 | *******************************************************************************/ |
| 577 | void bta_dm_set_visibility (tBTA_DM_MSG *p_data) |
| 578 | { |
| 579 | |
| 580 | |
| 581 | /* set modes for Discoverability and connectability if not ignore */ |
| 582 | if (p_data->set_visibility.disc_mode != BTA_DM_IGNORE) |
| 583 | BTM_SetDiscoverability((UINT8)p_data->set_visibility.disc_mode, |
| 584 | bta_dm_cb.inquiry_scan_window, |
| 585 | bta_dm_cb.inquiry_scan_interval); |
| 586 | |
| 587 | if (p_data->set_visibility.conn_mode != BTA_DM_IGNORE) |
| 588 | BTM_SetConnectability((UINT8)p_data->set_visibility.conn_mode, |
| 589 | bta_dm_cb.page_scan_window, |
| 590 | bta_dm_cb.page_scan_interval); |
| 591 | |
| 592 | /* Send False or True if not ignore */ |
| 593 | if (p_data->set_visibility.pair_mode != BTA_DM_IGNORE ) |
| 594 | { |
| 595 | |
| 596 | if (p_data->set_visibility.pair_mode == BTA_DM_NON_PAIRABLE) |
| 597 | bta_dm_cb.disable_pair_mode = TRUE; |
| 598 | else |
| 599 | bta_dm_cb.disable_pair_mode = FALSE; |
| 600 | |
| 601 | } |
| 602 | |
| 603 | /* Send False or True if not ignore */ |
| 604 | if (p_data->set_visibility.conn_paired_only != BTA_DM_IGNORE) |
| 605 | { |
| 606 | |
| 607 | if (p_data->set_visibility.conn_paired_only == BTA_DM_CONN_ALL) |
| 608 | bta_dm_cb.conn_paired_only = FALSE; |
| 609 | else |
| 610 | bta_dm_cb.conn_paired_only = TRUE; |
| 611 | |
| 612 | } |
| 613 | |
| 614 | /* Change mode if either mode is not ignore */ |
| 615 | if (p_data->set_visibility.pair_mode != BTA_DM_IGNORE || p_data->set_visibility.conn_paired_only != BTA_DM_IGNORE) |
| 616 | BTM_SetPairableMode((BOOLEAN)(!(bta_dm_cb.disable_pair_mode)),bta_dm_cb.conn_paired_only); |
| 617 | |
| 618 | } |
| 619 | |
| 620 | |
| 621 | /******************************************************************************* |
| 622 | ** |
| 623 | ** Function bta_dm_set_afhchannels |
| 624 | ** |
| 625 | ** Description This function sets the AFH first and |
| 626 | ** last disable channel, so channels within |
| 627 | ** that range are disabled. |
| 628 | ** |
| 629 | ** |
| 630 | ** Returns void |
| 631 | ** |
| 632 | *******************************************************************************/ |
| 633 | void bta_dm_set_afhchannels (tBTA_DM_MSG *p_data) |
| 634 | { |
| 635 | BTM_SetAfhChannels(p_data->set_afhchannels.first,p_data->set_afhchannels.last); |
| 636 | |
| 637 | } |
| 638 | |
| 639 | |
| 640 | /******************************************************************************* |
| 641 | ** |
| 642 | ** Function bta_dm_vendor_spec_command |
| 643 | ** |
| 644 | ** Description Send a vendor specific command to the controller |
| 645 | ** |
| 646 | ** |
| 647 | ** Returns void |
| 648 | ** |
| 649 | *******************************************************************************/ |
| 650 | void bta_dm_vendor_spec_command (tBTA_DM_MSG *p_data) |
| 651 | { |
| 652 | tBTM_STATUS status; |
| 653 | |
| 654 | status = BTM_VendorSpecificCommand(p_data->vendor_command.opcode,p_data->vendor_command.param_len,p_data->vendor_command.p_param_buf, p_data->vendor_command.p_cback); |
| 655 | |
| 656 | } |
| 657 | |
| 658 | |
| 659 | /******************************************************************************* |
| 660 | ** |
| 661 | ** Function bta_dm_tx_inqpower |
| 662 | ** |
| 663 | ** Description write inquiry tx power. |
| 664 | ** |
| 665 | ** |
| 666 | ** Returns void |
| 667 | ** |
| 668 | *******************************************************************************/ |
| 669 | void bta_dm_tx_inqpower(tBTA_DM_MSG *p_data) |
| 670 | { |
| 671 | if (BTM_WriteInquiryTxPower (p_data->tx_inq_pwr.tx_power) == BTM_ILLEGAL_VALUE) |
| 672 | { |
| 673 | APPL_TRACE_ERROR1("Invalid Inquiry Tx Power: %d", p_data->tx_inq_pwr.tx_power); |
| 674 | } |
| 675 | return; |
| 676 | } |
| 677 | |
| 678 | /******************************************************************************* |
| 679 | ** |
| 680 | ** Function bta_dm_remove_device |
| 681 | ** |
| 682 | ** Description Removes device, Disconnects ACL link if required. |
| 683 | **** |
| 684 | *******************************************************************************/ |
| 685 | void bta_dm_remove_device (tBTA_DM_MSG *p_data) |
| 686 | { |
| 687 | tBTA_DM_API_REMOVE_DEVICE *p_dev = &p_data->remove_dev; |
| 688 | int i; |
| 689 | tBTA_DM_SEC sec_event; |
| 690 | |
Zhihai Xu | bd68d68 | 2013-11-15 17:55:46 -0800 | [diff] [blame] | 691 | #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) |
| 692 | /* need to remove all pending background connection before unpair */ |
| 693 | BTA_GATTC_CancelOpen(0, p_dev->bd_addr, FALSE); |
| 694 | #endif |
| 695 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 696 | if ( BTM_IsAclConnectionUp(p_dev->bd_addr, BT_TRANSPORT_LE) || |
| 697 | BTM_IsAclConnectionUp(p_dev->bd_addr, BT_TRANSPORT_BR_EDR)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 698 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 699 | APPL_TRACE_DEBUG2("%s: ACL Up count %d", __FUNCTION__,bta_dm_cb.device_list.count); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 700 | /* Take the link down first, and mark the device for removal when disconnected */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 701 | |
| 702 | for(i=0; i<bta_dm_cb.device_list.count; i++) |
| 703 | { |
| 704 | if(!bdcmp( bta_dm_cb.device_list.peer_device[i].peer_bdaddr, p_dev->bd_addr)) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 705 | { |
| 706 | bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_UNPAIRING; |
| 707 | btm_remove_acl( p_dev->bd_addr,bta_dm_cb.device_list.peer_device[i].transport); |
| 708 | APPL_TRACE_DEBUG2("%s:transport = %d", __FUNCTION__, |
| 709 | bta_dm_cb.device_list.peer_device[i].transport); |
| 710 | break; |
| 711 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 712 | } |
| 713 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 714 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 715 | else /* Ok to remove the device in application layer */ |
| 716 | { |
| 717 | BTM_SecDeleteDevice(p_dev->bd_addr); |
Zhihai Xu | bd68d68 | 2013-11-15 17:55:46 -0800 | [diff] [blame] | 718 | #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) |
| 719 | /* remove all cached GATT information */ |
| 720 | BTA_GATTC_Refresh(p_dev->bd_addr); |
| 721 | #endif |
| 722 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 723 | if( bta_dm_cb.p_sec_cback ) |
| 724 | { |
| 725 | bdcpy(sec_event.link_down.bd_addr, p_dev->bd_addr); |
| 726 | /* No connection, set status to success (acl disc code not valid) */ |
| 727 | sec_event.link_down.status = HCI_SUCCESS; |
| 728 | bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &sec_event); |
| 729 | } |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | /******************************************************************************* |
| 734 | ** |
| 735 | ** Function bta_dm_add_device |
| 736 | ** |
| 737 | ** Description This function adds a Link Key to an security database entry. |
| 738 | ** It is normally called during host startup to restore all required information |
| 739 | ** stored in the NVRAM. |
| 740 | **** |
| 741 | *******************************************************************************/ |
| 742 | void bta_dm_add_device (tBTA_DM_MSG *p_data) |
| 743 | { |
| 744 | tBTA_DM_API_ADD_DEVICE *p_dev = &p_data->add_dev; |
| 745 | UINT8 *p_dc = NULL; |
| 746 | UINT8 *p_lc = NULL; |
| 747 | UINT32 trusted_services_mask[BTM_SEC_SERVICE_ARRAY_SIZE]; |
| 748 | UINT8 index = 0; |
| 749 | UINT8 btm_mask_index = 0; |
| 750 | |
| 751 | memset (trusted_services_mask, 0, sizeof(trusted_services_mask)); |
| 752 | |
| 753 | /* If not all zeros, the device class has been specified */ |
| 754 | if (p_dev->dc_known) |
| 755 | p_dc = (UINT8 *)p_dev->dc; |
| 756 | |
| 757 | if (p_dev->link_key_known) |
| 758 | p_lc = (UINT8 *)p_dev->link_key; |
| 759 | |
| 760 | if (p_dev->is_trusted) |
| 761 | { |
| 762 | /* covert BTA service mask to BTM mask */ |
| 763 | while (p_dev->tm && (index < BTA_MAX_SERVICE_ID)) |
| 764 | { |
| 765 | if (p_dev->tm & (UINT32)(1<<index)) |
| 766 | { |
| 767 | |
| 768 | btm_mask_index = bta_service_id_to_btm_srv_id_lkup_tbl[index] / BTM_SEC_ARRAY_BITS; |
| 769 | trusted_services_mask[btm_mask_index] |= (UINT32)(1 << (bta_service_id_to_btm_srv_id_lkup_tbl[index] - (UINT32)(btm_mask_index * 32))); |
| 770 | |
| 771 | p_dev->tm &= (UINT32)(~(1<<index)); |
| 772 | |
| 773 | } |
| 774 | index++; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | if (!BTM_SecAddDevice (p_dev->bd_addr, p_dc, p_dev->bd_name, p_dev->features, |
| 779 | trusted_services_mask, p_lc, p_dev->key_type, p_dev->io_cap)) |
| 780 | { |
| 781 | APPL_TRACE_ERROR2 ("BTA_DM: Error adding device %08x%04x", |
| 782 | (p_dev->bd_addr[0]<<24)+(p_dev->bd_addr[1]<<16)+(p_dev->bd_addr[2]<<8)+p_dev->bd_addr[3], |
| 783 | (p_dev->bd_addr[4]<<8)+p_dev->bd_addr[5]); |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | /******************************************************************************* |
| 788 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 789 | ** Function bta_dm_close_acl |
| 790 | ** |
| 791 | ** Description This function forces to close the connection to a remote device |
| 792 | ** and optionaly remove the device from security database if |
| 793 | ** required. |
| 794 | **** |
| 795 | *******************************************************************************/ |
| 796 | void bta_dm_close_acl(tBTA_DM_MSG *p_data) |
| 797 | { |
| 798 | tBTA_DM_API_REMOVE_ACL *p_remove_acl = &p_data->remove_acl; |
| 799 | UINT8 index; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 800 | tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 801 | |
| 802 | APPL_TRACE_DEBUG0("bta_dm_close_acl"); |
| 803 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 804 | if ( BTM_IsAclConnectionUp(p_remove_acl->bd_addr, BT_TRANSPORT_LE) || |
| 805 | BTM_IsAclConnectionUp(p_remove_acl->bd_addr, BT_TRANSPORT_BR_EDR)) |
| 806 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 807 | { |
| 808 | for (index = 0; index < bta_dm_cb.device_list.count; index ++) |
| 809 | { |
| 810 | if (!bdcmp( bta_dm_cb.device_list.peer_device[index].peer_bdaddr, p_remove_acl->bd_addr)) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 811 | { |
| 812 | #if defined (BLE_INCLUDED) && (BLE_INCLUDED == TRUE) |
| 813 | transport = bta_dm_cb.device_list.peer_device[index].transport; |
| 814 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 815 | break; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 816 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 817 | } |
| 818 | if (index != bta_dm_cb.device_list.count) |
| 819 | { |
| 820 | if (p_remove_acl->remove_dev) |
| 821 | bta_dm_cb.device_list.peer_device[index].remove_dev_pending = TRUE; |
| 822 | } |
| 823 | else |
| 824 | { |
| 825 | APPL_TRACE_ERROR0("unknown device, remove ACL failed"); |
| 826 | } |
| 827 | /* Disconnect the ACL link */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 828 | btm_remove_acl(p_remove_acl->bd_addr, transport); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 829 | } |
| 830 | /* if to remove the device from security database ? do it now */ |
| 831 | else if (p_remove_acl->remove_dev) |
| 832 | { |
| 833 | if (!BTM_SecDeleteDevice(p_remove_acl->bd_addr)) |
| 834 | { |
| 835 | APPL_TRACE_ERROR0("delete device from security database failed."); |
| 836 | } |
| 837 | #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) |
| 838 | /* need to remove all pending background connection if any */ |
| 839 | BTA_GATTC_CancelOpen(0, p_remove_acl->bd_addr, FALSE); |
| 840 | /* remove all cached GATT information */ |
| 841 | BTA_GATTC_Refresh(p_remove_acl->bd_addr); |
| 842 | #endif |
| 843 | } |
| 844 | /* otherwise, no action needed */ |
| 845 | |
| 846 | } |
| 847 | /******************************************************************************* |
| 848 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 849 | ** Function bta_dm_bond |
| 850 | ** |
| 851 | ** Description Bonds with peer device |
| 852 | ** |
| 853 | ** |
| 854 | ** Returns void |
| 855 | ** |
| 856 | *******************************************************************************/ |
| 857 | void bta_dm_bond (tBTA_DM_MSG *p_data) |
| 858 | { |
| 859 | tBTM_STATUS status; |
| 860 | tBTA_DM_SEC sec_event; |
| 861 | char *p_name; |
| 862 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 863 | if (p_data->bond.transport == BTA_TRANSPORT_UNKNOWN) |
| 864 | status = BTM_SecBond ( p_data->bond.bd_addr, 0, NULL, 0 ); |
| 865 | else |
| 866 | status = BTM_SecBondByTransport ( p_data->bond.bd_addr, p_data->bond.transport, 0, NULL, 0 ); |
| 867 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 868 | |
| 869 | if (bta_dm_cb.p_sec_cback && (status != BTM_CMD_STARTED)) |
| 870 | { |
| 871 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 872 | memset(&sec_event, 0, sizeof(tBTA_DM_SEC)); |
| 873 | bdcpy(sec_event.auth_cmpl.bd_addr, p_data->bond.bd_addr); |
Kim Schulz | 2a2701c | 2013-09-16 15:59:33 +0200 | [diff] [blame] | 874 | p_name = BTM_SecReadDevName(p_data->bond.bd_addr); |
| 875 | if (p_name != NULL) |
| 876 | { |
| 877 | memcpy(sec_event.auth_cmpl.bd_name, p_name, (BD_NAME_LEN-1)); |
| 878 | sec_event.auth_cmpl.bd_name[BD_NAME_LEN-1] = 0; |
| 879 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 880 | |
| 881 | /* taken care of by memset [above] |
| 882 | sec_event.auth_cmpl.key_present = FALSE; |
| 883 | sec_event.auth_cmpl.success = FALSE; |
| 884 | */ |
| 885 | sec_event.auth_cmpl.fail_reason = HCI_ERR_ILLEGAL_COMMAND; |
| 886 | if (status == BTM_SUCCESS) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 887 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 888 | sec_event.auth_cmpl.success = TRUE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 889 | } |
| 890 | else |
| 891 | { |
| 892 | /* delete this device entry from Sec Dev DB */ |
| 893 | bta_dm_remove_sec_dev_entry(p_data->bond.bd_addr); |
| 894 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 895 | bta_dm_cb.p_sec_cback(BTA_DM_AUTH_CMPL_EVT, &sec_event); |
| 896 | } |
| 897 | |
| 898 | } |
| 899 | |
| 900 | /******************************************************************************* |
| 901 | ** |
| 902 | ** Function bta_dm_bond_cancel |
| 903 | ** |
| 904 | ** Description Cancels bonding with a peer device |
| 905 | ** |
| 906 | ** |
| 907 | ** Returns void |
| 908 | ** |
| 909 | *******************************************************************************/ |
| 910 | void bta_dm_bond_cancel (tBTA_DM_MSG *p_data) |
| 911 | { |
| 912 | tBTM_STATUS status; |
| 913 | tBTA_DM_SEC sec_event; |
| 914 | |
| 915 | APPL_TRACE_EVENT0(" bta_dm_bond_cancel "); |
| 916 | status = BTM_SecBondCancel ( p_data->bond_cancel.bd_addr ); |
| 917 | |
| 918 | if (bta_dm_cb.p_sec_cback && (status != BTM_CMD_STARTED && status != BTM_SUCCESS)) |
| 919 | { |
| 920 | sec_event.bond_cancel_cmpl.result = BTA_FAILURE; |
| 921 | |
| 922 | bta_dm_cb.p_sec_cback(BTA_DM_BOND_CANCEL_CMPL_EVT, &sec_event); |
| 923 | } |
| 924 | |
| 925 | } |
| 926 | |
| 927 | /******************************************************************************* |
| 928 | ** |
| 929 | ** Function bta_dm_pin_reply |
| 930 | ** |
| 931 | ** Description Send the pin_reply to a request from BTM |
| 932 | ** |
| 933 | ** |
| 934 | ** Returns void |
| 935 | ** |
| 936 | *******************************************************************************/ |
| 937 | void bta_dm_pin_reply (tBTA_DM_MSG *p_data) |
| 938 | { |
| 939 | UINT32 trusted_mask[BTM_SEC_SERVICE_ARRAY_SIZE]; |
| 940 | UINT32 * current_trusted_mask; |
| 941 | |
| 942 | current_trusted_mask = BTM_ReadTrustedMask(p_data->pin_reply.bd_addr); |
| 943 | |
| 944 | if(current_trusted_mask) |
| 945 | { |
| 946 | memcpy(trusted_mask, current_trusted_mask, sizeof(trusted_mask)); |
| 947 | } |
| 948 | else |
| 949 | { |
| 950 | memset(trusted_mask, 0, sizeof(trusted_mask)); |
| 951 | } |
| 952 | |
| 953 | if(p_data->pin_reply.accept) |
| 954 | { |
| 955 | |
| 956 | BTM_PINCodeReply(p_data->pin_reply.bd_addr, BTM_SUCCESS, p_data->pin_reply.pin_len, p_data->pin_reply.p_pin, trusted_mask ); |
| 957 | } |
| 958 | else |
| 959 | { |
| 960 | BTM_PINCodeReply(p_data->pin_reply.bd_addr, BTM_NOT_AUTHORIZED, 0, NULL, trusted_mask ); |
| 961 | } |
| 962 | |
| 963 | } |
| 964 | |
| 965 | /******************************************************************************* |
| 966 | ** |
| 967 | ** Function bta_dm_link_policy |
| 968 | ** |
| 969 | ** Description remove/set link policy mask. |
| 970 | ** wake the link, is sniff/park is removed |
| 971 | ** |
| 972 | ** Returns void |
| 973 | ** |
| 974 | *******************************************************************************/ |
| 975 | void bta_dm_link_policy (tBTA_DM_MSG *p_data) |
| 976 | { |
| 977 | tBTA_DM_PEER_DEVICE *p_dev; |
| 978 | |
| 979 | p_dev = bta_dm_find_peer_device(p_data->link_policy.bd_addr); |
| 980 | if(!p_dev) |
| 981 | return; |
| 982 | |
| 983 | APPL_TRACE_DEBUG2(" bta_dm_link_policy set:%d, policy:0x%x", |
| 984 | p_data->link_policy.set, p_data->link_policy.policy_mask); |
| 985 | if(p_data->link_policy.set) |
| 986 | { |
| 987 | /* restore the default link policy */ |
| 988 | p_dev->link_policy |= p_data->link_policy.policy_mask; |
| 989 | BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy)); |
| 990 | } |
| 991 | else |
| 992 | { |
| 993 | /* clear the policy from the default link policy */ |
| 994 | p_dev->link_policy &= (~p_data->link_policy.policy_mask); |
| 995 | BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy)); |
| 996 | |
| 997 | if(p_data->link_policy.policy_mask & (HCI_ENABLE_SNIFF_MODE | HCI_ENABLE_PARK_MODE)) |
| 998 | { |
| 999 | /* if clearing sniff/park, wake the link */ |
| 1000 | bta_dm_pm_active(p_dev->peer_bdaddr); |
| 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | /******************************************************************************* |
| 1006 | ** |
| 1007 | ** Function bta_dm_policy_cback |
| 1008 | ** |
| 1009 | ** Description process the link policy changes |
| 1010 | ** |
| 1011 | ** Returns void |
| 1012 | ** |
| 1013 | *******************************************************************************/ |
| 1014 | static void bta_dm_policy_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr) |
| 1015 | { |
| 1016 | tBTA_DM_PEER_DEVICE *p_dev = NULL; |
| 1017 | UINT16 policy = app_id; |
| 1018 | UINT32 mask = (UINT32)(1 << id); |
| 1019 | |
| 1020 | if(peer_addr) |
| 1021 | p_dev = bta_dm_find_peer_device(peer_addr); |
| 1022 | |
| 1023 | APPL_TRACE_DEBUG2(" bta_dm_policy_cback cmd:%d, policy:0x%x", |
| 1024 | status, policy); |
| 1025 | switch(status) |
| 1026 | { |
| 1027 | case BTA_SYS_PLCY_SET: |
| 1028 | if(!p_dev) |
| 1029 | return; |
| 1030 | /* restore the default link policy */ |
| 1031 | p_dev->link_policy |= policy; |
| 1032 | BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy)); |
| 1033 | break; |
| 1034 | |
| 1035 | case BTA_SYS_PLCY_CLR: |
| 1036 | if(!p_dev) |
| 1037 | return; |
| 1038 | /* clear the policy from the default link policy */ |
| 1039 | p_dev->link_policy &= (~policy); |
| 1040 | BTM_SetLinkPolicy(p_dev->peer_bdaddr, &(p_dev->link_policy)); |
| 1041 | |
| 1042 | if(policy & (HCI_ENABLE_SNIFF_MODE | HCI_ENABLE_PARK_MODE)) |
| 1043 | { |
| 1044 | /* if clearing sniff/park, wake the link */ |
| 1045 | bta_dm_pm_active(p_dev->peer_bdaddr); |
| 1046 | } |
| 1047 | break; |
| 1048 | |
| 1049 | case BTA_SYS_PLCY_DEF_SET: |
| 1050 | /* want to restore/set the role switch policy */ |
| 1051 | bta_dm_cb.role_policy_mask &= ~mask; |
| 1052 | if(0 == bta_dm_cb.role_policy_mask) |
| 1053 | { |
| 1054 | /* if nobody wants to insist on the role */ |
| 1055 | bta_dm_cb.cur_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH; |
| 1056 | BTM_SetDefaultLinkPolicy(bta_dm_cb.cur_policy); |
| 1057 | } |
| 1058 | break; |
| 1059 | |
| 1060 | case BTA_SYS_PLCY_DEF_CLR: |
| 1061 | /* want to remove the role switch policy */ |
| 1062 | bta_dm_cb.role_policy_mask |= mask; |
| 1063 | bta_dm_cb.cur_policy &= ~HCI_ENABLE_MASTER_SLAVE_SWITCH; |
| 1064 | BTM_SetDefaultLinkPolicy(bta_dm_cb.cur_policy); |
| 1065 | break; |
| 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | |
| 1070 | /******************************************************************************* |
| 1071 | ** |
| 1072 | ** Function bta_dm_auth_reply |
| 1073 | ** |
| 1074 | ** Description Send the authorization reply to a request from BTM |
| 1075 | ** |
| 1076 | ** |
| 1077 | ** Returns void |
| 1078 | ** |
| 1079 | *******************************************************************************/ |
| 1080 | void bta_dm_auth_reply (tBTA_DM_MSG *p_data) |
| 1081 | { |
| 1082 | |
| 1083 | UINT32 trusted_mask[BTM_SEC_SERVICE_ARRAY_SIZE]; |
| 1084 | UINT8 btm_mask_index = 0; |
| 1085 | UINT32 * current_trusted_mask; |
| 1086 | |
| 1087 | current_trusted_mask = BTM_ReadTrustedMask(p_data->auth_reply.bd_addr); |
| 1088 | |
| 1089 | if(current_trusted_mask) |
| 1090 | { |
| 1091 | memcpy(trusted_mask, current_trusted_mask, sizeof(trusted_mask)); |
| 1092 | } |
| 1093 | else |
| 1094 | { |
| 1095 | memset(trusted_mask, 0, sizeof(trusted_mask)); |
| 1096 | } |
| 1097 | |
| 1098 | if(p_data->auth_reply.response != BTA_DM_NOT_AUTH) |
| 1099 | { |
| 1100 | if(p_data->auth_reply.response == BTA_DM_AUTH_PERM) |
| 1101 | { |
| 1102 | if(p_data->auth_reply.service < BTA_MAX_SERVICE_ID) |
| 1103 | { |
| 1104 | /* convert BTA service id to BTM mask */ |
| 1105 | btm_mask_index = bta_service_id_to_btm_srv_id_lkup_tbl[p_data->auth_reply.service] / 32; |
| 1106 | trusted_mask[btm_mask_index] |= (UINT32)(1 << (bta_service_id_to_btm_srv_id_lkup_tbl[p_data->auth_reply.service] - (UINT32)(btm_mask_index * 32))); |
| 1107 | |
| 1108 | } |
| 1109 | } |
| 1110 | BTM_DeviceAuthorized (p_data->auth_reply.bd_addr, BTM_SUCCESS,trusted_mask); |
| 1111 | } |
| 1112 | else |
| 1113 | { |
| 1114 | BTM_DeviceAuthorized (p_data->auth_reply.bd_addr, BTM_NOT_AUTHORIZED,trusted_mask); |
| 1115 | } |
| 1116 | |
| 1117 | } |
| 1118 | |
| 1119 | /******************************************************************************* |
| 1120 | ** |
| 1121 | ** Function bta_dm_confirm |
| 1122 | ** |
| 1123 | ** Description Send the user confirm request reply in response to a |
| 1124 | ** request from BTM |
| 1125 | ** |
| 1126 | ** Returns void |
| 1127 | ** |
| 1128 | *******************************************************************************/ |
| 1129 | void bta_dm_confirm(tBTA_DM_MSG *p_data) |
| 1130 | { |
| 1131 | tBTM_STATUS res = BTM_NOT_AUTHORIZED; |
| 1132 | |
| 1133 | if(p_data->confirm.accept == TRUE) |
| 1134 | res = BTM_SUCCESS; |
| 1135 | BTM_ConfirmReqReply(res, p_data->confirm.bd_addr); |
| 1136 | } |
| 1137 | |
| 1138 | /******************************************************************************* |
| 1139 | ** |
| 1140 | ** Function bta_dm_passkey_cancel |
| 1141 | ** |
| 1142 | ** Description Send the passkey cancel from SP initiator by sending a negative |
| 1143 | ** passkey request replyreply. |
| 1144 | ** Returns void |
| 1145 | ** |
| 1146 | *******************************************************************************/ |
| 1147 | #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) |
| 1148 | void bta_dm_passkey_cancel(tBTA_DM_MSG *p_data) |
| 1149 | { |
| 1150 | BTM_PasskeyReqReply(BTM_NOT_AUTHORIZED, p_data->passkey_cancel.bd_addr, 0); |
| 1151 | } |
| 1152 | #endif |
| 1153 | |
| 1154 | /******************************************************************************* |
| 1155 | ** |
| 1156 | ** Function bta_dm_loc_oob |
| 1157 | ** |
| 1158 | ** Description Retrieve the OOB data from the local LM |
| 1159 | ** |
| 1160 | ** Returns void |
| 1161 | ** |
| 1162 | *******************************************************************************/ |
| 1163 | #if (BTM_OOB_INCLUDED == TRUE) |
| 1164 | void bta_dm_loc_oob(tBTA_DM_MSG *p_data) |
| 1165 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 1166 | UNUSED(p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1167 | BTM_ReadLocalOobData(); |
| 1168 | } |
| 1169 | |
| 1170 | /******************************************************************************* |
| 1171 | ** |
| 1172 | ** Function bta_dm_ci_io_req_act |
| 1173 | ** |
| 1174 | ** Description respond to the IO capabilities request from BTM |
| 1175 | ** |
| 1176 | ** Returns void |
| 1177 | ** |
| 1178 | *******************************************************************************/ |
| 1179 | void bta_dm_ci_io_req_act(tBTA_DM_MSG *p_data) |
| 1180 | { |
| 1181 | tBTM_AUTH_REQ auth_req = BTM_AUTH_AP_NO; |
| 1182 | if(p_data->ci_io_req.auth_req) |
| 1183 | auth_req = BTM_AUTH_AP_YES; |
| 1184 | BTM_IoCapRsp(p_data->ci_io_req.bd_addr, p_data->ci_io_req.io_cap, |
| 1185 | p_data->ci_io_req.oob_data, auth_req); |
| 1186 | } |
| 1187 | |
| 1188 | /******************************************************************************* |
| 1189 | ** |
| 1190 | ** Function bta_dm_ci_rmt_oob_act |
| 1191 | ** |
| 1192 | ** Description respond to the OOB data request for the remote device from BTM |
| 1193 | ** |
| 1194 | ** |
| 1195 | ** Returns void |
| 1196 | ** |
| 1197 | *******************************************************************************/ |
| 1198 | void bta_dm_ci_rmt_oob_act(tBTA_DM_MSG *p_data) |
| 1199 | { |
| 1200 | tBTM_STATUS res = BTM_NOT_AUTHORIZED; |
| 1201 | |
| 1202 | if(p_data->ci_rmt_oob.accept == TRUE) |
| 1203 | res = BTM_SUCCESS; |
| 1204 | BTM_RemoteOobDataReply(res, p_data->ci_rmt_oob.bd_addr, |
| 1205 | p_data->ci_rmt_oob.c, p_data->ci_rmt_oob.r ); |
| 1206 | } |
| 1207 | #endif /* BTM_OOB_INCLUDED */ |
| 1208 | |
| 1209 | /******************************************************************************* |
| 1210 | ** |
| 1211 | ** Function bta_dm_search_start |
| 1212 | ** |
| 1213 | ** Description Starts an inquiry |
| 1214 | ** |
| 1215 | ** |
| 1216 | ** Returns void |
| 1217 | ** |
| 1218 | *******************************************************************************/ |
| 1219 | void bta_dm_search_start (tBTA_DM_MSG *p_data) |
| 1220 | { |
| 1221 | tBTM_INQUIRY_CMPL result; |
| 1222 | |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 1223 | #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1224 | UINT16 len = (UINT16)(sizeof(tBT_UUID) * p_data->search.num_uuid); |
| 1225 | #endif |
| 1226 | |
| 1227 | APPL_TRACE_DEBUG1("bta_dm_search_start avoid_scatter=%d", bta_dm_cfg.avoid_scatter); |
| 1228 | if (bta_dm_cfg.avoid_scatter && |
| 1229 | (p_data->search.rs_res == BTA_DM_RS_NONE) && bta_dm_check_av(BTA_DM_API_SEARCH_EVT)) |
| 1230 | { |
| 1231 | memcpy(&bta_dm_cb.search_msg, &p_data->search, sizeof(tBTA_DM_API_SEARCH)); |
| 1232 | return; |
| 1233 | } |
| 1234 | |
| 1235 | BTM_ClearInqDb(NULL); |
| 1236 | /* save search params */ |
| 1237 | bta_dm_search_cb.p_search_cback = p_data->search.p_cback; |
| 1238 | bta_dm_search_cb.services = p_data->search.services; |
| 1239 | |
| 1240 | #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) |
| 1241 | utl_freebuf((void **)&bta_dm_search_cb.p_srvc_uuid); |
| 1242 | |
| 1243 | if ((bta_dm_search_cb.num_uuid = p_data->search.num_uuid) != 0 && |
| 1244 | p_data->search.p_uuid != NULL) |
| 1245 | { |
| 1246 | if ((bta_dm_search_cb.p_srvc_uuid = (tBT_UUID *)GKI_getbuf(len)) == NULL) |
| 1247 | { |
| 1248 | APPL_TRACE_ERROR0("bta_dm_search_start no resources"); |
| 1249 | |
| 1250 | result.status = BTA_FAILURE; |
| 1251 | result.num_resp = 0; |
| 1252 | bta_dm_inq_cmpl_cb ((void *)&result); |
| 1253 | return; |
| 1254 | } |
| 1255 | // bta_dm_search_cb.p_srvc_uuid = (tBT_UUID *)GKI_getbuf(len); |
| 1256 | memcpy(bta_dm_search_cb.p_srvc_uuid, p_data->search.p_uuid, len); |
| 1257 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1258 | #endif |
| 1259 | result.status = BTM_StartInquiry( (tBTM_INQ_PARMS*)&p_data->search.inq_params, |
| 1260 | bta_dm_inq_results_cb, |
| 1261 | (tBTM_CMPL_CB*) bta_dm_inq_cmpl_cb); |
| 1262 | |
| 1263 | APPL_TRACE_EVENT1("bta_dm_search_start status=%d", result.status); |
| 1264 | if (result.status != BTM_CMD_STARTED) |
| 1265 | { |
| 1266 | result.num_resp = 0; |
| 1267 | bta_dm_inq_cmpl_cb ((void *)&result); |
| 1268 | } |
| 1269 | |
| 1270 | } |
| 1271 | |
| 1272 | /******************************************************************************* |
| 1273 | ** |
| 1274 | ** Function bta_dm_search_cancel |
| 1275 | ** |
| 1276 | ** Description Cancels an ongoing search for devices |
| 1277 | ** |
| 1278 | ** |
| 1279 | ** Returns void |
| 1280 | ** |
| 1281 | *******************************************************************************/ |
| 1282 | void bta_dm_search_cancel (tBTA_DM_MSG *p_data) |
| 1283 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 1284 | UNUSED(p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1285 | tBTA_DM_MSG * p_msg; |
| 1286 | |
| 1287 | if(BTM_IsInquiryActive()) |
| 1288 | { |
| 1289 | BTM_CancelInquiry(); |
| 1290 | bta_dm_search_cancel_notify(NULL); |
| 1291 | |
| 1292 | if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) |
| 1293 | { |
| 1294 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1295 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 1296 | bta_sys_sendmsg(p_msg); |
| 1297 | |
| 1298 | } |
| 1299 | } |
| 1300 | /* If no Service Search going on then issue cancel remote name in case it is active */ |
| 1301 | else if (!bta_dm_search_cb.name_discover_done) |
| 1302 | { |
| 1303 | BTM_CancelRemoteDeviceName(); |
| 1304 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1305 | #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1306 | if (bta_dm_search_cb.gatt_disc_active) |
| 1307 | { |
| 1308 | bta_dm_cancel_gatt_discovery(bta_dm_search_cb.peer_bdaddr); |
| 1309 | } |
| 1310 | #endif |
| 1311 | } |
| 1312 | |
| 1313 | /******************************************************************************* |
| 1314 | ** |
| 1315 | ** Function bta_dm_discover |
| 1316 | ** |
| 1317 | ** Description Discovers services on a remote device |
| 1318 | ** |
| 1319 | ** |
| 1320 | ** Returns void |
| 1321 | ** |
| 1322 | *******************************************************************************/ |
| 1323 | void bta_dm_discover (tBTA_DM_MSG *p_data) |
| 1324 | { |
| 1325 | #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE |
| 1326 | UINT16 len = (UINT16)(sizeof(tBT_UUID) * p_data->discover.num_uuid); |
| 1327 | #endif |
| 1328 | APPL_TRACE_EVENT2("bta_dm_discover services_to_search=0x%04X, sdp_search=%d", |
| 1329 | p_data->discover.services, p_data->discover.sdp_search); |
| 1330 | |
| 1331 | /* save the search condition */ |
| 1332 | bta_dm_search_cb.services = p_data->discover.services; |
| 1333 | |
| 1334 | #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE |
| 1335 | utl_freebuf((void **)&bta_dm_search_cb.p_srvc_uuid); |
| 1336 | if ((bta_dm_search_cb.num_uuid = p_data->discover.num_uuid) != 0 && |
| 1337 | p_data->discover.p_uuid != NULL) |
| 1338 | { |
| 1339 | if ((bta_dm_search_cb.p_srvc_uuid = (tBT_UUID *)GKI_getbuf(len)) == NULL) |
| 1340 | { |
| 1341 | p_data->discover.p_cback(BTA_DM_DISC_CMPL_EVT, NULL); |
| 1342 | return; |
| 1343 | } |
| 1344 | memcpy(bta_dm_search_cb.p_srvc_uuid, p_data->discover.p_uuid, len); |
| 1345 | } |
| 1346 | bta_dm_search_cb.uuid_to_search = bta_dm_search_cb.num_uuid; |
| 1347 | #endif |
| 1348 | |
| 1349 | bta_dm_search_cb.p_search_cback = p_data->discover.p_cback; |
| 1350 | bta_dm_search_cb.sdp_search = p_data->discover.sdp_search; |
| 1351 | bta_dm_search_cb.services_to_search = bta_dm_search_cb.services; |
| 1352 | bta_dm_search_cb.service_index = 0; |
| 1353 | bta_dm_search_cb.services_found = 0; |
| 1354 | bta_dm_search_cb.peer_name[0] = 0; |
| 1355 | bta_dm_search_cb.sdp_search = p_data->discover.sdp_search; |
| 1356 | bta_dm_search_cb.p_btm_inq_info = BTM_InqDbRead (p_data->discover.bd_addr); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1357 | bta_dm_search_cb.transport = p_data->discover.transport; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1358 | |
| 1359 | bta_dm_search_cb.name_discover_done = FALSE; |
| 1360 | memcpy(&bta_dm_search_cb.uuid, &p_data->discover.uuid, sizeof(tSDP_UUID)); |
| 1361 | bta_dm_discover_device(p_data->discover.bd_addr); |
| 1362 | } |
| 1363 | |
| 1364 | /******************************************************************************* |
| 1365 | ** |
| 1366 | ** Function bta_dm_di_disc_cmpl |
| 1367 | ** |
| 1368 | ** Description Sends event to application when DI discovery complete |
| 1369 | ** |
| 1370 | ** Returns void |
| 1371 | ** |
| 1372 | *******************************************************************************/ |
| 1373 | void bta_dm_di_disc_cmpl(tBTA_DM_MSG *p_data) |
| 1374 | { |
| 1375 | tBTA_DM_DI_DISC_CMPL di_disc; |
| 1376 | |
| 1377 | memset(&di_disc, 0, sizeof(tBTA_DM_DI_DISC_CMPL)); |
| 1378 | bdcpy(di_disc.bd_addr, bta_dm_search_cb.peer_bdaddr); |
| 1379 | |
| 1380 | if((p_data->hdr.offset == SDP_SUCCESS) |
| 1381 | || (p_data->hdr.offset == SDP_DB_FULL)) |
| 1382 | { |
| 1383 | di_disc.num_record = SDP_GetNumDiRecords(bta_dm_di_cb.p_di_db); |
| 1384 | } |
| 1385 | else |
| 1386 | di_disc.result = BTA_FAILURE; |
| 1387 | |
| 1388 | bta_dm_di_cb.p_di_db = NULL; |
| 1389 | bta_dm_search_cb.p_search_cback(BTA_DM_DI_DISC_CMPL_EVT, (tBTA_DM_SEARCH *) &di_disc); |
| 1390 | } |
| 1391 | |
| 1392 | /******************************************************************************* |
| 1393 | ** |
| 1394 | ** Function bta_dm_di_disc_callback |
| 1395 | ** |
| 1396 | ** Description This function queries a remote device for DI information. |
| 1397 | ** |
| 1398 | ** |
| 1399 | ** Returns void |
| 1400 | ** |
| 1401 | *******************************************************************************/ |
| 1402 | static void bta_dm_di_disc_callback(UINT16 result) |
| 1403 | { |
| 1404 | tBTA_DM_MSG * p_msg; |
| 1405 | |
| 1406 | if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) |
| 1407 | { |
| 1408 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1409 | p_msg->hdr.layer_specific = BTA_DM_API_DI_DISCOVER_EVT; |
| 1410 | p_msg->hdr.offset = result; |
| 1411 | bta_sys_sendmsg(p_msg); |
| 1412 | } |
| 1413 | } |
| 1414 | |
| 1415 | /******************************************************************************* |
| 1416 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1417 | ** Function bta_dm_disable_search_and_disc |
| 1418 | ** |
| 1419 | ** Description Cancels an ongoing search or discovery for devices in case of |
| 1420 | ** a Bluetooth disable |
| 1421 | ** |
| 1422 | ** |
| 1423 | ** Returns void |
| 1424 | ** |
| 1425 | *******************************************************************************/ |
| 1426 | static void bta_dm_disable_search_and_disc (void) |
| 1427 | { |
| 1428 | tBTA_DM_DI_DISC_CMPL di_disc; |
| 1429 | tBTA_DM_MSG * p_msg; |
| 1430 | |
| 1431 | if(BTM_IsInquiryActive()||(bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE)) |
| 1432 | { |
| 1433 | BTM_CancelInquiry(); |
| 1434 | bta_dm_search_cancel_notify(NULL); |
| 1435 | |
| 1436 | if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) |
| 1437 | { |
| 1438 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1439 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 1440 | bta_sys_sendmsg(p_msg); |
| 1441 | |
| 1442 | } |
| 1443 | } |
| 1444 | /* If no Service Search going on then issue cancel remote name in case it is active */ |
| 1445 | else if (!bta_dm_search_cb.name_discover_done) |
| 1446 | { |
| 1447 | BTM_CancelRemoteDeviceName(); |
| 1448 | |
| 1449 | if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) |
| 1450 | { |
| 1451 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1452 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 1453 | bta_sys_sendmsg(p_msg); |
| 1454 | } |
| 1455 | } |
| 1456 | else if(bta_dm_di_cb.p_di_db != NULL) |
| 1457 | { |
| 1458 | memset(&di_disc, 0, sizeof(tBTA_DM_DI_DISC_CMPL)); |
| 1459 | bdcpy(di_disc.bd_addr, bta_dm_search_cb.peer_bdaddr); |
| 1460 | di_disc.result = BTA_FAILURE; |
| 1461 | |
| 1462 | bta_dm_di_cb.p_di_db = NULL; |
| 1463 | bta_dm_search_cb.p_search_cback(BTA_DM_DI_DISC_CMPL_EVT, NULL); |
| 1464 | } |
| 1465 | |
| 1466 | #if (BLE_INCLUDED == TRUE) && (BTA_GATT_INCLUDED == TRUE) |
| 1467 | if (bta_dm_search_cb.gatt_disc_active) |
| 1468 | { |
| 1469 | bta_dm_cancel_gatt_discovery(bta_dm_search_cb.peer_bdaddr); |
| 1470 | } |
| 1471 | #endif |
| 1472 | } |
| 1473 | |
| 1474 | /******************************************************************************* |
| 1475 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1476 | ** Function bta_dm_di_disc |
| 1477 | ** |
| 1478 | ** Description This function queries a remote device for DI information. |
| 1479 | ** |
| 1480 | ** |
| 1481 | ** Returns void |
| 1482 | ** |
| 1483 | *******************************************************************************/ |
| 1484 | void bta_dm_di_disc (tBTA_DM_MSG *p_data) |
| 1485 | { |
| 1486 | UINT16 result = BTA_FAILURE; |
| 1487 | tBTA_DM_MSG *p_msg; |
| 1488 | |
| 1489 | bta_dm_search_cb.p_search_cback = p_data->di_disc.p_cback; |
| 1490 | bdcpy(bta_dm_search_cb.peer_bdaddr, p_data->di_disc.bd_addr); |
| 1491 | bta_dm_di_cb.p_di_db = p_data->di_disc.p_sdp_db; |
| 1492 | |
| 1493 | if((bta_dm_search_cb.p_sdp_db = (tSDP_DISCOVERY_DB *)GKI_getbuf(BTA_DM_SDP_DB_SIZE)) != NULL) |
| 1494 | { |
| 1495 | if ( SDP_DiDiscover(bta_dm_search_cb.peer_bdaddr, p_data->di_disc.p_sdp_db, |
| 1496 | p_data->di_disc.len, bta_dm_di_disc_callback) == SDP_SUCCESS) |
| 1497 | { |
| 1498 | result = BTA_SUCCESS; |
| 1499 | } |
| 1500 | } |
| 1501 | else |
| 1502 | { |
| 1503 | APPL_TRACE_ERROR0("No buffer to start DI discovery"); |
| 1504 | } |
| 1505 | |
| 1506 | if ( result == BTA_FAILURE && |
| 1507 | (p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) |
| 1508 | { |
| 1509 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1510 | p_msg->hdr.layer_specific = BTA_DM_API_DI_DISCOVER_EVT; |
| 1511 | p_data->hdr.offset = result; |
| 1512 | bta_sys_sendmsg(p_msg); |
| 1513 | } |
| 1514 | } |
| 1515 | |
| 1516 | /******************************************************************************* |
| 1517 | ** |
| 1518 | ** Function bta_dm_read_remote_device_name |
| 1519 | ** |
| 1520 | ** Description Initiate to get remote device name |
| 1521 | ** |
| 1522 | ** Returns TRUE if started to get remote name |
| 1523 | ** |
| 1524 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1525 | static BOOLEAN bta_dm_read_remote_device_name (BD_ADDR bd_addr,tBT_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1526 | { |
| 1527 | tBTM_STATUS btm_status; |
| 1528 | |
| 1529 | APPL_TRACE_DEBUG0("bta_dm_read_remote_device_name"); |
| 1530 | |
| 1531 | bdcpy(bta_dm_search_cb.peer_bdaddr, bd_addr); |
| 1532 | bta_dm_search_cb.peer_name[0] = 0; |
| 1533 | |
| 1534 | btm_status = BTM_ReadRemoteDeviceName (bta_dm_search_cb.peer_bdaddr, |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1535 | (tBTM_CMPL_CB *) bta_dm_remname_cback, |
| 1536 | transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1537 | |
| 1538 | if ( btm_status == BTM_CMD_STARTED ) |
| 1539 | { |
| 1540 | APPL_TRACE_DEBUG0("bta_dm_read_remote_device_name: BTM_ReadRemoteDeviceName is started"); |
| 1541 | |
| 1542 | return (TRUE); |
| 1543 | } |
| 1544 | else if ( btm_status == BTM_BUSY ) |
| 1545 | { |
| 1546 | APPL_TRACE_DEBUG0("bta_dm_read_remote_device_name: BTM_ReadRemoteDeviceName is busy"); |
| 1547 | |
| 1548 | /* Remote name discovery is on going now so BTM cannot notify through "bta_dm_remname_cback" */ |
| 1549 | /* adding callback to get notified that current reading remore name done */ |
| 1550 | BTM_SecAddRmtNameNotifyCallback(&bta_dm_service_search_remname_cback); |
| 1551 | |
| 1552 | return (TRUE); |
| 1553 | } |
| 1554 | else |
| 1555 | { |
| 1556 | APPL_TRACE_WARNING1("bta_dm_read_remote_device_name: BTM_ReadRemoteDeviceName returns 0x%02X", btm_status); |
| 1557 | |
| 1558 | return (FALSE); |
| 1559 | } |
| 1560 | } |
| 1561 | |
| 1562 | /******************************************************************************* |
| 1563 | ** |
| 1564 | ** Function bta_dm_inq_cmpl |
| 1565 | ** |
| 1566 | ** Description Process the inquiry complete event from BTM |
| 1567 | ** |
| 1568 | ** Returns void |
| 1569 | ** |
| 1570 | *******************************************************************************/ |
| 1571 | void bta_dm_inq_cmpl (tBTA_DM_MSG *p_data) |
| 1572 | { |
| 1573 | tBTA_DM_MSG * p_msg; |
| 1574 | tBTA_DM_SEARCH data; |
| 1575 | |
| 1576 | APPL_TRACE_DEBUG0("bta_dm_inq_cmpl"); |
| 1577 | |
| 1578 | data.inq_cmpl.num_resps = p_data->inq_cmpl.num; |
| 1579 | bta_dm_search_cb.p_search_cback(BTA_DM_INQ_CMPL_EVT, &data); |
| 1580 | |
| 1581 | if((bta_dm_search_cb.p_btm_inq_info = BTM_InqDbFirst()) != NULL) |
| 1582 | { |
| 1583 | /* start name and service discovery from the first device on inquiry result */ |
| 1584 | bta_dm_search_cb.name_discover_done = FALSE; |
| 1585 | bta_dm_search_cb.peer_name[0] = 0; |
| 1586 | bta_dm_discover_device(bta_dm_search_cb.p_btm_inq_info->results.remote_bd_addr); |
| 1587 | } |
| 1588 | else |
| 1589 | { |
| 1590 | /* no devices, search complete */ |
| 1591 | bta_dm_search_cb.services = 0; |
| 1592 | |
| 1593 | if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) |
| 1594 | { |
| 1595 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1596 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 1597 | bta_sys_sendmsg(p_msg); |
| 1598 | } |
| 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | /******************************************************************************* |
| 1603 | ** |
| 1604 | ** Function bta_dm_rmt_name |
| 1605 | ** |
| 1606 | ** Description Process the remote name result from BTM |
| 1607 | ** |
| 1608 | ** Returns void |
| 1609 | ** |
| 1610 | *******************************************************************************/ |
| 1611 | void bta_dm_rmt_name (tBTA_DM_MSG *p_data) |
| 1612 | { |
| 1613 | APPL_TRACE_DEBUG0("bta_dm_rmt_name"); |
| 1614 | |
| 1615 | if( p_data->rem_name.result.disc_res.bd_name[0] && bta_dm_search_cb.p_btm_inq_info) |
| 1616 | { |
| 1617 | bta_dm_search_cb.p_btm_inq_info->appl_knows_rem_name = TRUE; |
| 1618 | } |
| 1619 | |
| 1620 | bta_dm_discover_device(bta_dm_search_cb.peer_bdaddr); |
| 1621 | } |
| 1622 | |
| 1623 | /******************************************************************************* |
| 1624 | ** |
| 1625 | ** Function bta_dm_disc_rmt_name |
| 1626 | ** |
| 1627 | ** Description Process the remote name result from BTM when application |
| 1628 | ** wants to find the name for a bdaddr |
| 1629 | ** |
| 1630 | ** Returns void |
| 1631 | ** |
| 1632 | *******************************************************************************/ |
| 1633 | void bta_dm_disc_rmt_name (tBTA_DM_MSG *p_data) |
| 1634 | { |
| 1635 | tBTM_INQ_INFO *p_btm_inq_info; |
| 1636 | |
| 1637 | APPL_TRACE_DEBUG0("bta_dm_disc_rmt_name"); |
| 1638 | |
| 1639 | p_btm_inq_info = BTM_InqDbRead (p_data->rem_name.result.disc_res.bd_addr); |
| 1640 | if( p_btm_inq_info ) |
| 1641 | { |
| 1642 | if( p_data->rem_name.result.disc_res.bd_name[0] ) |
| 1643 | { |
| 1644 | p_btm_inq_info->appl_knows_rem_name = TRUE; |
| 1645 | } |
| 1646 | } |
| 1647 | |
| 1648 | bta_dm_discover_device(p_data->rem_name.result.disc_res.bd_addr); |
| 1649 | } |
| 1650 | |
| 1651 | /******************************************************************************* |
| 1652 | ** |
| 1653 | ** Function bta_dm_sdp_result |
| 1654 | ** |
| 1655 | ** Description Process the discovery result from sdp |
| 1656 | ** |
| 1657 | ** Returns void |
| 1658 | ** |
| 1659 | *******************************************************************************/ |
| 1660 | void bta_dm_sdp_result (tBTA_DM_MSG *p_data) |
| 1661 | { |
| 1662 | |
| 1663 | tSDP_DISC_REC *p_sdp_rec = NULL; |
| 1664 | tBTA_DM_MSG *p_msg; |
| 1665 | BOOLEAN service_found = FALSE; |
| 1666 | BOOLEAN scn_found = FALSE; |
| 1667 | UINT16 service = 0xFFFF; |
| 1668 | tSDP_PROTOCOL_ELEM pe; |
| 1669 | |
| 1670 | #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE |
| 1671 | tBT_UUID *p_uuid = bta_dm_search_cb.p_srvc_uuid; |
| 1672 | tBTA_DM_SEARCH result; |
| 1673 | tBT_UUID service_uuid; |
| 1674 | #endif |
| 1675 | |
| 1676 | UINT32 num_uuids = 0; |
| 1677 | UINT8 uuid_list[32][MAX_UUID_SIZE]; // assuming a max of 32 services |
| 1678 | |
| 1679 | if((p_data->sdp_event.sdp_result == SDP_SUCCESS) |
| 1680 | || (p_data->sdp_event.sdp_result == SDP_NO_RECS_MATCH) |
| 1681 | || (p_data->sdp_event.sdp_result == SDP_DB_FULL)) |
| 1682 | { |
| 1683 | APPL_TRACE_DEBUG1("sdp_result::0x%x", p_data->sdp_event.sdp_result); |
| 1684 | do |
| 1685 | { |
| 1686 | |
| 1687 | service_found = FALSE; |
| 1688 | p_sdp_rec = NULL; |
| 1689 | if( bta_dm_search_cb.service_index == (BTA_USER_SERVICE_ID+1) ) |
| 1690 | { |
| 1691 | p_sdp_rec = SDP_FindServiceUUIDInDb(bta_dm_search_cb.p_sdp_db, &bta_dm_search_cb.uuid, p_sdp_rec); |
| 1692 | |
| 1693 | if (p_sdp_rec && SDP_FindProtocolListElemInRec(p_sdp_rec, UUID_PROTOCOL_RFCOMM, &pe)) |
| 1694 | { |
| 1695 | bta_dm_search_cb.peer_scn = (UINT8) pe.params[0]; |
| 1696 | scn_found = TRUE; |
| 1697 | } |
| 1698 | } |
| 1699 | else |
| 1700 | { |
| 1701 | service = bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index-1]; |
| 1702 | p_sdp_rec = SDP_FindServiceInDb(bta_dm_search_cb.p_sdp_db, service, p_sdp_rec); |
| 1703 | } |
| 1704 | #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE |
| 1705 | /* finished with BR/EDR services, now we check the result for GATT based service UUID */ |
| 1706 | if (bta_dm_search_cb.service_index == BTA_MAX_SERVICE_ID) |
| 1707 | { |
| 1708 | if (bta_dm_search_cb.uuid_to_search != 0 && p_uuid != NULL) |
| 1709 | { |
| 1710 | p_uuid += (bta_dm_search_cb.num_uuid - bta_dm_search_cb.uuid_to_search); |
| 1711 | /* only support 16 bits UUID for now */ |
| 1712 | service = p_uuid->uu.uuid16; |
| 1713 | |
| 1714 | } |
| 1715 | /* all GATT based services */ |
| 1716 | do |
| 1717 | { |
| 1718 | /* find a service record, report it */ |
| 1719 | p_sdp_rec = SDP_FindServiceInDb(bta_dm_search_cb.p_sdp_db, |
| 1720 | 0, p_sdp_rec); |
| 1721 | if (p_sdp_rec) |
| 1722 | { |
| 1723 | if (SDP_FindServiceUUIDInRec(p_sdp_rec, &service_uuid)) |
| 1724 | { |
| 1725 | /* send result back to app now, one by one */ |
| 1726 | bdcpy (result.disc_ble_res.bd_addr, bta_dm_search_cb.peer_bdaddr); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1727 | BCM_STRNCPY_S((char*)result.disc_ble_res.bd_name, sizeof(BD_NAME), bta_dm_get_remname(), (BD_NAME_LEN)); |
| 1728 | result.disc_ble_res.bd_name[BD_NAME_LEN] = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1729 | result.disc_ble_res.service.len = service_uuid.len; |
| 1730 | result.disc_ble_res.service.uu.uuid16 = service_uuid.uu.uuid16; |
| 1731 | |
| 1732 | bta_dm_search_cb.p_search_cback(BTA_DM_DISC_BLE_RES_EVT, &result); |
| 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | if (bta_dm_search_cb.uuid_to_search > 0) |
| 1737 | break; |
| 1738 | |
| 1739 | } while (p_sdp_rec); |
| 1740 | } |
| 1741 | else |
| 1742 | #endif |
| 1743 | { |
| 1744 | /* SDP_DB_FULL means some records with the |
| 1745 | required attributes were received */ |
| 1746 | if(((p_data->sdp_event.sdp_result == SDP_DB_FULL) && |
| 1747 | bta_dm_search_cb.services != BTA_ALL_SERVICE_MASK) || |
| 1748 | (p_sdp_rec != NULL)) |
| 1749 | { |
| 1750 | /* If Plug and Play service record, check to see if Broadcom stack */ |
| 1751 | if (service == UUID_SERVCLASS_PNP_INFORMATION) |
| 1752 | { |
| 1753 | if (p_sdp_rec) |
| 1754 | { |
| 1755 | if (SDP_FindAttributeInRec (p_sdp_rec, ATTR_ID_EXT_BRCM_VERSION)) |
| 1756 | { |
| 1757 | service_found = TRUE; |
| 1758 | } |
| 1759 | } |
| 1760 | } |
| 1761 | else |
| 1762 | { |
| 1763 | service_found = TRUE; |
| 1764 | } |
| 1765 | |
| 1766 | if (service_found) |
| 1767 | { |
| 1768 | UINT16 tmp_svc = 0xFFFF; |
| 1769 | bta_dm_search_cb.services_found |= |
| 1770 | (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(bta_dm_search_cb.service_index-1)); |
| 1771 | tmp_svc = bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index-1]; |
| 1772 | /* Add to the list of UUIDs */ |
| 1773 | sdpu_uuid16_to_uuid128(tmp_svc, uuid_list[num_uuids]); |
| 1774 | num_uuids++; |
| 1775 | } |
| 1776 | } |
| 1777 | } |
| 1778 | |
| 1779 | if(bta_dm_search_cb.services == BTA_ALL_SERVICE_MASK && |
| 1780 | bta_dm_search_cb.services_to_search == 0) |
| 1781 | { |
| 1782 | #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE |
| 1783 | if ( bta_dm_search_cb.service_index == BTA_BLE_SERVICE_ID && |
| 1784 | bta_dm_search_cb.uuid_to_search > 0) |
| 1785 | bta_dm_search_cb.uuid_to_search --; |
| 1786 | |
| 1787 | if (bta_dm_search_cb.uuid_to_search == 0 || |
| 1788 | bta_dm_search_cb.service_index != BTA_BLE_SERVICE_ID) |
| 1789 | #endif |
| 1790 | bta_dm_search_cb.service_index++; |
| 1791 | } |
| 1792 | else /* regular one service per search or PNP search */ |
| 1793 | break; |
| 1794 | |
| 1795 | } |
| 1796 | while(bta_dm_search_cb.service_index <= BTA_MAX_SERVICE_ID); |
| 1797 | |
| 1798 | // GKI_freebuf(bta_dm_search_cb.p_sdp_db); |
| 1799 | // bta_dm_search_cb.p_sdp_db = NULL; |
| 1800 | APPL_TRACE_DEBUG1("bta_dm_sdp_result services_found = %04x", bta_dm_search_cb.services_found); |
| 1801 | |
| 1802 | /* Collect the 128-bit services here and put them into the list */ |
| 1803 | if(bta_dm_search_cb.services == BTA_ALL_SERVICE_MASK) |
| 1804 | { |
| 1805 | p_sdp_rec = NULL; |
| 1806 | do |
| 1807 | { |
| 1808 | tBT_UUID temp_uuid; |
| 1809 | /* find a service record, report it */ |
| 1810 | p_sdp_rec = SDP_FindServiceInDb_128bit(bta_dm_search_cb.p_sdp_db, p_sdp_rec); |
| 1811 | if (p_sdp_rec) |
| 1812 | { |
| 1813 | if (SDP_FindServiceUUIDInRec_128bit(p_sdp_rec, &temp_uuid)) |
| 1814 | { |
| 1815 | memcpy(uuid_list[num_uuids], temp_uuid.uu.uuid128, MAX_UUID_SIZE); |
| 1816 | num_uuids++; |
| 1817 | } |
| 1818 | } |
| 1819 | } while (p_sdp_rec); |
| 1820 | } |
| 1821 | /* if there are more services to search for */ |
| 1822 | if(bta_dm_search_cb.services_to_search) |
| 1823 | { |
| 1824 | /* Free up the p_sdp_db before checking the next one */ |
| 1825 | bta_dm_free_sdp_db(NULL); |
| 1826 | bta_dm_find_services(bta_dm_search_cb.peer_bdaddr); |
| 1827 | } |
| 1828 | else |
| 1829 | { |
| 1830 | /* callbacks */ |
| 1831 | /* start next bd_addr if necessary */ |
| 1832 | |
| 1833 | BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback); |
| 1834 | |
| 1835 | |
| 1836 | if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) |
| 1837 | { |
| 1838 | p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT; |
| 1839 | p_msg->disc_result.result.disc_res.result = BTA_SUCCESS; |
| 1840 | p_msg->disc_result.result.disc_res.p_raw_data = NULL; |
| 1841 | p_msg->disc_result.result.disc_res.raw_data_size = 0; |
| 1842 | p_msg->disc_result.result.disc_res.num_uuids = num_uuids; |
| 1843 | p_msg->disc_result.result.disc_res.p_uuid_list = NULL; |
| 1844 | if (num_uuids > 0) { |
| 1845 | p_msg->disc_result.result.disc_res.p_uuid_list = (UINT8*)GKI_getbuf(num_uuids*MAX_UUID_SIZE); |
| 1846 | if (p_msg->disc_result.result.disc_res.p_uuid_list) { |
| 1847 | memcpy(p_msg->disc_result.result.disc_res.p_uuid_list, uuid_list, |
| 1848 | num_uuids*MAX_UUID_SIZE); |
| 1849 | } else { |
| 1850 | p_msg->disc_result.result.disc_res.num_uuids = 0; |
| 1851 | APPL_TRACE_ERROR1("%s: Unable to allocate memory for uuid_list", __FUNCTION__); |
| 1852 | } |
| 1853 | } |
| 1854 | //copy the raw_data to the discovery result structure |
| 1855 | // |
| 1856 | APPL_TRACE_DEBUG2("bta_dm_sdp_result (raw_data used = 0x%x raw_data_ptr = 0x%x)\r\n",bta_dm_search_cb.p_sdp_db->raw_used, bta_dm_search_cb.p_sdp_db->raw_data); |
| 1857 | |
| 1858 | if ( bta_dm_search_cb.p_sdp_db != NULL && bta_dm_search_cb.p_sdp_db->raw_used != 0 && |
| 1859 | bta_dm_search_cb.p_sdp_db->raw_data != NULL) { |
| 1860 | |
| 1861 | p_msg->disc_result.result.disc_res.p_raw_data = GKI_getbuf(bta_dm_search_cb.p_sdp_db->raw_used); |
| 1862 | if ( NULL != p_msg->disc_result.result.disc_res.p_raw_data ) { |
| 1863 | memcpy( p_msg->disc_result.result.disc_res.p_raw_data, |
| 1864 | bta_dm_search_cb.p_sdp_db->raw_data, |
| 1865 | bta_dm_search_cb.p_sdp_db->raw_used ); |
| 1866 | |
| 1867 | p_msg->disc_result.result.disc_res.raw_data_size = |
| 1868 | bta_dm_search_cb.p_sdp_db->raw_used; |
| 1869 | |
| 1870 | } else { |
| 1871 | APPL_TRACE_DEBUG1("bta_dm_sdp_result GKI Alloc failed to allocate %d bytes !!\r\n",bta_dm_search_cb.p_sdp_db->raw_used); |
| 1872 | } |
| 1873 | |
| 1874 | bta_dm_search_cb.p_sdp_db->raw_data = NULL; //no need to free this - it is a global assigned. |
| 1875 | bta_dm_search_cb.p_sdp_db->raw_used = 0; |
| 1876 | bta_dm_search_cb.p_sdp_db->raw_size = 0; |
| 1877 | } |
| 1878 | else { |
| 1879 | APPL_TRACE_DEBUG0("bta_dm_sdp_result raw data size is 0 or raw_data is null!!\r\n"); |
| 1880 | } |
| 1881 | /* Done with p_sdp_db. Free it */ |
| 1882 | bta_dm_free_sdp_db(NULL); |
| 1883 | p_msg->disc_result.result.disc_res.services = bta_dm_search_cb.services_found; |
| 1884 | |
| 1885 | //Piggy back the SCN over result field |
| 1886 | if( scn_found ) |
| 1887 | { |
| 1888 | p_msg->disc_result.result.disc_res.result = (3 + bta_dm_search_cb.peer_scn); |
| 1889 | p_msg->disc_result.result.disc_res.services |= BTA_USER_SERVICE_MASK; |
| 1890 | |
| 1891 | APPL_TRACE_EVENT1(" Piggy back the SCN over result field SCN=%d", bta_dm_search_cb.peer_scn); |
| 1892 | |
| 1893 | } |
| 1894 | bdcpy (p_msg->disc_result.result.disc_res.bd_addr, bta_dm_search_cb.peer_bdaddr); |
| 1895 | BCM_STRNCPY_S((char*)p_msg->disc_result.result.disc_res.bd_name, sizeof(BD_NAME), |
| 1896 | bta_dm_get_remname(), (BD_NAME_LEN-1)); |
| 1897 | |
| 1898 | /* make sure the string is null terminated */ |
| 1899 | p_msg->disc_result.result.disc_res.bd_name[BD_NAME_LEN-1] = 0; |
| 1900 | |
| 1901 | bta_sys_sendmsg(p_msg); |
| 1902 | } |
| 1903 | |
| 1904 | } |
| 1905 | |
| 1906 | } |
| 1907 | else |
| 1908 | { |
| 1909 | /* conn failed. No need for timer */ |
| 1910 | if(p_data->sdp_event.sdp_result == SDP_CONN_FAILED || p_data->sdp_event.sdp_result == SDP_CONN_REJECTED |
| 1911 | || p_data->sdp_event.sdp_result == SDP_SECURITY_ERR) |
| 1912 | bta_dm_search_cb.wait_disc = FALSE; |
| 1913 | |
| 1914 | /* not able to connect go to next device */ |
| 1915 | GKI_freebuf(bta_dm_search_cb.p_sdp_db); |
| 1916 | bta_dm_search_cb.p_sdp_db = NULL; |
| 1917 | |
| 1918 | BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback); |
| 1919 | |
| 1920 | if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) |
| 1921 | { |
| 1922 | p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT; |
| 1923 | p_msg->disc_result.result.disc_res.result = BTA_FAILURE; |
| 1924 | p_msg->disc_result.result.disc_res.services = bta_dm_search_cb.services_found; |
| 1925 | bdcpy (p_msg->disc_result.result.disc_res.bd_addr, bta_dm_search_cb.peer_bdaddr); |
| 1926 | BCM_STRNCPY_S((char*)p_msg->disc_result.result.disc_res.bd_name, sizeof(BD_NAME), |
| 1927 | bta_dm_get_remname(), (BD_NAME_LEN-1)); |
| 1928 | |
| 1929 | /* make sure the string is null terminated */ |
| 1930 | p_msg->disc_result.result.disc_res.bd_name[BD_NAME_LEN-1] = 0; |
| 1931 | |
| 1932 | bta_sys_sendmsg(p_msg); |
| 1933 | } |
| 1934 | } |
| 1935 | } |
| 1936 | |
| 1937 | /******************************************************************************* |
| 1938 | ** |
| 1939 | ** Function bta_dm_search_cmpl |
| 1940 | ** |
| 1941 | ** Description Sends event to application |
| 1942 | ** |
| 1943 | ** Returns void |
| 1944 | ** |
| 1945 | *******************************************************************************/ |
| 1946 | void bta_dm_search_cmpl (tBTA_DM_MSG *p_data) |
| 1947 | { |
| 1948 | APPL_TRACE_DEBUG0("bta_dm_search_cmpl"); |
| 1949 | |
| 1950 | #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) |
| 1951 | utl_freebuf((void **)&bta_dm_search_cb.p_srvc_uuid); |
| 1952 | #endif |
| 1953 | |
| 1954 | if (p_data->hdr.layer_specific == BTA_DM_API_DI_DISCOVER_EVT) |
| 1955 | bta_dm_di_disc_cmpl(p_data); |
| 1956 | else |
| 1957 | bta_dm_search_cb.p_search_cback(BTA_DM_DISC_CMPL_EVT, NULL); |
| 1958 | } |
| 1959 | |
| 1960 | /******************************************************************************* |
| 1961 | ** |
| 1962 | ** Function bta_dm_disc_result |
| 1963 | ** |
| 1964 | ** Description Service discovery result when discovering services on a device |
| 1965 | ** |
| 1966 | ** Returns void |
| 1967 | ** |
| 1968 | *******************************************************************************/ |
| 1969 | void bta_dm_disc_result (tBTA_DM_MSG *p_data) |
| 1970 | { |
| 1971 | tBTA_DM_MSG * p_msg; |
| 1972 | |
| 1973 | APPL_TRACE_DEBUG0("bta_dm_disc_result"); |
| 1974 | |
| 1975 | #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE |
| 1976 | /* if any BR/EDR service discovery has been done, report the event */ |
| 1977 | if ((bta_dm_search_cb.services & ((BTA_ALL_SERVICE_MASK | BTA_USER_SERVICE_MASK ) & ~BTA_BLE_SERVICE_MASK))) |
| 1978 | #endif |
| 1979 | bta_dm_search_cb.p_search_cback(BTA_DM_DISC_RES_EVT, &p_data->disc_result.result); |
| 1980 | |
| 1981 | /* send a message to change state */ |
| 1982 | if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) |
| 1983 | { |
| 1984 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 1985 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 1986 | bta_sys_sendmsg(p_msg); |
| 1987 | } |
| 1988 | } |
| 1989 | |
| 1990 | /******************************************************************************* |
| 1991 | ** |
| 1992 | ** Function bta_dm_search_result |
| 1993 | ** |
| 1994 | ** Description Service discovery result while searching for devices |
| 1995 | ** |
| 1996 | ** Returns void |
| 1997 | ** |
| 1998 | *******************************************************************************/ |
| 1999 | void bta_dm_search_result (tBTA_DM_MSG *p_data) |
| 2000 | { |
| 2001 | APPL_TRACE_DEBUG2("bta_dm_search_result searching:0x%04x, result:0x%04x", |
| 2002 | bta_dm_search_cb.services, |
| 2003 | p_data->disc_result.result.disc_res.services); |
| 2004 | |
| 2005 | /* call back if application wants name discovery or found services that application is searching */ |
| 2006 | if (( !bta_dm_search_cb.services ) |
| 2007 | ||(( bta_dm_search_cb.services ) && ( p_data->disc_result.result.disc_res.services ))) |
| 2008 | { |
| 2009 | bta_dm_search_cb.p_search_cback(BTA_DM_DISC_RES_EVT, &p_data->disc_result.result); |
| 2010 | } |
| 2011 | |
| 2012 | /* if searching did not initiate to create link */ |
| 2013 | if(!bta_dm_search_cb.wait_disc ) |
| 2014 | { |
| 2015 | #if ( BTM_EIR_CLIENT_INCLUDED == TRUE ) |
| 2016 | /* if service searching is done with EIR, don't search next device */ |
| 2017 | if( bta_dm_search_cb.p_btm_inq_info ) |
| 2018 | #endif |
| 2019 | bta_dm_discover_next_device(); |
| 2020 | } |
| 2021 | else |
| 2022 | { |
| 2023 | /* wait until link is disconnected or timeout */ |
| 2024 | bta_dm_search_cb.sdp_results = TRUE; |
| 2025 | bta_dm_search_cb.search_timer.p_cback = (TIMER_CBACK*)&bta_dm_search_timer_cback; |
| 2026 | bta_sys_start_timer(&bta_dm_search_cb.search_timer, 0, 1000*(L2CAP_LINK_INACTIVITY_TOUT+1) ); |
| 2027 | } |
| 2028 | |
| 2029 | } |
| 2030 | |
| 2031 | /******************************************************************************* |
| 2032 | ** |
| 2033 | ** Function bta_dm_search_timer_cback |
| 2034 | ** |
| 2035 | ** Description Called when ACL disconnect time is over |
| 2036 | ** |
| 2037 | ** |
| 2038 | ** Returns void |
| 2039 | ** |
| 2040 | *******************************************************************************/ |
| 2041 | static void bta_dm_search_timer_cback (TIMER_LIST_ENT *p_tle) |
| 2042 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 2043 | UNUSED(p_tle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2044 | |
| 2045 | APPL_TRACE_EVENT0(" bta_dm_search_timer_cback "); |
| 2046 | bta_dm_search_cb.wait_disc = FALSE; |
| 2047 | |
| 2048 | /* proceed with next device */ |
| 2049 | bta_dm_discover_next_device(); |
| 2050 | |
| 2051 | } |
| 2052 | |
| 2053 | |
| 2054 | /******************************************************************************* |
| 2055 | ** |
| 2056 | ** Function bta_dm_free_sdp_db |
| 2057 | ** |
| 2058 | ** Description Frees SDP data base |
| 2059 | ** |
| 2060 | ** Returns void |
| 2061 | ** |
| 2062 | *******************************************************************************/ |
| 2063 | void bta_dm_free_sdp_db (tBTA_DM_MSG *p_data) |
| 2064 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 2065 | UNUSED(p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2066 | if(bta_dm_search_cb.p_sdp_db) |
| 2067 | { |
| 2068 | GKI_freebuf(bta_dm_search_cb.p_sdp_db); |
| 2069 | bta_dm_search_cb.p_sdp_db = NULL; |
| 2070 | } |
| 2071 | |
| 2072 | } |
| 2073 | |
| 2074 | /******************************************************************************* |
| 2075 | ** |
| 2076 | ** Function bta_dm_queue_search |
| 2077 | ** |
| 2078 | ** Description Queues search command while search is being cancelled |
| 2079 | ** |
| 2080 | ** Returns void |
| 2081 | ** |
| 2082 | *******************************************************************************/ |
| 2083 | void bta_dm_queue_search (tBTA_DM_MSG *p_data) |
| 2084 | { |
Zhihai Xu | b69a175 | 2013-11-06 19:23:13 -0800 | [diff] [blame] | 2085 | if(bta_dm_search_cb.p_search_queue) |
| 2086 | { |
| 2087 | GKI_freebuf(bta_dm_search_cb.p_search_queue); |
| 2088 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2089 | |
| 2090 | bta_dm_search_cb.p_search_queue = (tBTA_DM_MSG *)GKI_getbuf(sizeof(tBTA_DM_API_SEARCH)); |
| 2091 | memcpy(bta_dm_search_cb.p_search_queue, p_data, sizeof(tBTA_DM_API_SEARCH)); |
| 2092 | |
| 2093 | } |
| 2094 | |
| 2095 | /******************************************************************************* |
| 2096 | ** |
| 2097 | ** Function bta_dm_queue_disc |
| 2098 | ** |
| 2099 | ** Description Queues discovery command while search is being cancelled |
| 2100 | ** |
| 2101 | ** Returns void |
| 2102 | ** |
| 2103 | *******************************************************************************/ |
| 2104 | void bta_dm_queue_disc (tBTA_DM_MSG *p_data) |
| 2105 | { |
Zhihai Xu | b69a175 | 2013-11-06 19:23:13 -0800 | [diff] [blame] | 2106 | if(bta_dm_search_cb.p_search_queue) |
| 2107 | { |
| 2108 | GKI_freebuf(bta_dm_search_cb.p_search_queue); |
| 2109 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2110 | |
| 2111 | bta_dm_search_cb.p_search_queue = (tBTA_DM_MSG *)GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER)); |
| 2112 | memcpy(bta_dm_search_cb.p_search_queue, p_data, sizeof(tBTA_DM_API_DISCOVER)); |
| 2113 | |
| 2114 | } |
| 2115 | |
| 2116 | /******************************************************************************* |
| 2117 | ** |
| 2118 | ** Function bta_dm_search_clear_queue |
| 2119 | ** |
| 2120 | ** Description Clears the queue if API search cancel is called |
| 2121 | ** |
| 2122 | ** Returns void |
| 2123 | ** |
| 2124 | *******************************************************************************/ |
| 2125 | void bta_dm_search_clear_queue (tBTA_DM_MSG *p_data) |
| 2126 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 2127 | UNUSED(p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2128 | if(bta_dm_search_cb.p_search_queue) |
| 2129 | { |
| 2130 | GKI_freebuf(bta_dm_search_cb.p_search_queue); |
| 2131 | bta_dm_search_cb.p_search_queue = NULL; |
| 2132 | } |
| 2133 | |
| 2134 | |
| 2135 | } |
| 2136 | |
| 2137 | /******************************************************************************* |
| 2138 | ** |
| 2139 | ** Function bta_dm_search_cancel_cmpl |
| 2140 | ** |
| 2141 | ** Description Search cancel is complete |
| 2142 | ** |
| 2143 | ** Returns void |
| 2144 | ** |
| 2145 | *******************************************************************************/ |
| 2146 | void bta_dm_search_cancel_cmpl (tBTA_DM_MSG *p_data) |
| 2147 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 2148 | UNUSED(p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2149 | if(bta_dm_search_cb.p_search_queue) |
| 2150 | { |
| 2151 | bta_sys_sendmsg(bta_dm_search_cb.p_search_queue); |
| 2152 | bta_dm_search_cb.p_search_queue = NULL; |
| 2153 | } |
| 2154 | |
| 2155 | } |
| 2156 | |
| 2157 | /******************************************************************************* |
| 2158 | ** |
| 2159 | ** Function bta_dm_search_cancel_transac_cmpl |
| 2160 | ** |
| 2161 | ** Description Current Service Discovery or remote name procedure is |
| 2162 | ** completed after search cancellation |
| 2163 | ** |
| 2164 | ** Returns void |
| 2165 | ** |
| 2166 | *******************************************************************************/ |
| 2167 | void bta_dm_search_cancel_transac_cmpl(tBTA_DM_MSG *p_data) |
| 2168 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 2169 | UNUSED(p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2170 | if(bta_dm_search_cb.p_sdp_db) |
| 2171 | { |
| 2172 | GKI_freebuf(bta_dm_search_cb.p_sdp_db); |
| 2173 | bta_dm_search_cb.p_sdp_db = NULL; |
| 2174 | } |
| 2175 | |
| 2176 | bta_dm_search_cancel_notify(NULL); |
| 2177 | } |
| 2178 | |
| 2179 | |
| 2180 | /******************************************************************************* |
| 2181 | ** |
| 2182 | ** Function bta_dm_search_cancel_notify |
| 2183 | ** |
| 2184 | ** Description Notify application that search has been cancelled |
| 2185 | ** |
| 2186 | ** Returns void |
| 2187 | ** |
| 2188 | *******************************************************************************/ |
| 2189 | void bta_dm_search_cancel_notify (tBTA_DM_MSG *p_data) |
| 2190 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 2191 | UNUSED(p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2192 | if (bta_dm_search_cb.p_search_cback) |
| 2193 | { |
| 2194 | bta_dm_search_cb.p_search_cback(BTA_DM_SEARCH_CANCEL_CMPL_EVT, NULL); |
| 2195 | } |
| 2196 | if (!bta_dm_search_cb.name_discover_done) |
| 2197 | { |
| 2198 | BTM_CancelRemoteDeviceName(); |
| 2199 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2200 | #if (BLE_INCLUDED == TRUE) && (BTA_GATT_INCLUDED == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2201 | if (bta_dm_search_cb.gatt_disc_active) |
| 2202 | { |
| 2203 | bta_dm_cancel_gatt_discovery(bta_dm_search_cb.peer_bdaddr); |
| 2204 | } |
| 2205 | #endif |
| 2206 | |
| 2207 | } |
| 2208 | |
| 2209 | /******************************************************************************* |
| 2210 | ** |
| 2211 | ** Function bta_dm_find_services |
| 2212 | ** |
| 2213 | ** Description Starts discovery on a device |
| 2214 | ** |
| 2215 | ** Returns void |
| 2216 | ** |
| 2217 | *******************************************************************************/ |
| 2218 | static void bta_dm_find_services ( BD_ADDR bd_addr) |
| 2219 | { |
| 2220 | |
| 2221 | tSDP_UUID uuid; |
| 2222 | UINT16 attr_list[] = {ATTR_ID_SERVICE_CLASS_ID_LIST, ATTR_ID_EXT_BRCM_VERSION}; |
| 2223 | UINT16 num_attrs = 1; |
| 2224 | tBTA_DM_MSG *p_msg; |
| 2225 | |
| 2226 | memset (&uuid, 0, sizeof(tSDP_UUID)); |
| 2227 | |
| 2228 | while(bta_dm_search_cb.service_index < BTA_MAX_SERVICE_ID) |
| 2229 | { |
| 2230 | if( bta_dm_search_cb.services_to_search |
| 2231 | & (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(bta_dm_search_cb.service_index))) |
| 2232 | { |
| 2233 | if((bta_dm_search_cb.p_sdp_db = (tSDP_DISCOVERY_DB *)GKI_getbuf(BTA_DM_SDP_DB_SIZE)) != NULL) |
| 2234 | { |
| 2235 | APPL_TRACE_DEBUG1("bta_dm_search_cb.services = %04x***********", bta_dm_search_cb.services); |
| 2236 | /* try to search all services by search based on L2CAP UUID */ |
| 2237 | if(bta_dm_search_cb.services == BTA_ALL_SERVICE_MASK ) |
| 2238 | { |
| 2239 | APPL_TRACE_ERROR1("services_to_search = %08x",bta_dm_search_cb.services_to_search); |
| 2240 | if (bta_dm_search_cb.services_to_search & BTA_RES_SERVICE_MASK) |
| 2241 | { |
| 2242 | uuid.uu.uuid16 = bta_service_id_to_uuid_lkup_tbl[0]; |
| 2243 | bta_dm_search_cb.services_to_search &= ~BTA_RES_SERVICE_MASK; |
| 2244 | } |
| 2245 | else |
| 2246 | { |
| 2247 | uuid.uu.uuid16 = UUID_PROTOCOL_L2CAP; |
| 2248 | bta_dm_search_cb.services_to_search = 0; |
| 2249 | } |
| 2250 | } |
| 2251 | else |
| 2252 | { |
| 2253 | #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE |
| 2254 | /* for LE only profile */ |
| 2255 | if (bta_dm_search_cb.service_index == BTA_BLE_SERVICE_ID) |
| 2256 | { |
| 2257 | if (bta_dm_search_cb.uuid_to_search > 0 && bta_dm_search_cb.p_srvc_uuid) |
| 2258 | { |
| 2259 | memcpy(&uuid, |
| 2260 | (const void *)(bta_dm_search_cb.p_srvc_uuid + \ |
| 2261 | bta_dm_search_cb.num_uuid - bta_dm_search_cb.uuid_to_search), |
| 2262 | sizeof(tBT_UUID)); |
| 2263 | |
| 2264 | bta_dm_search_cb.uuid_to_search -- ; |
| 2265 | } |
| 2266 | else |
| 2267 | uuid.uu.uuid16 = bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index]; |
| 2268 | |
| 2269 | /* last one? clear the BLE service bit if all discovery has been done */ |
| 2270 | if (bta_dm_search_cb.uuid_to_search == 0) |
| 2271 | bta_dm_search_cb.services_to_search &= |
| 2272 | (tBTA_SERVICE_MASK)(~(BTA_SERVICE_ID_TO_SERVICE_MASK(bta_dm_search_cb.service_index))); |
| 2273 | |
| 2274 | } |
| 2275 | else |
| 2276 | #endif |
| 2277 | { |
| 2278 | /* remove the service from services to be searched */ |
| 2279 | bta_dm_search_cb.services_to_search &= |
| 2280 | (tBTA_SERVICE_MASK)(~(BTA_SERVICE_ID_TO_SERVICE_MASK(bta_dm_search_cb.service_index))); |
| 2281 | uuid.uu.uuid16 = bta_service_id_to_uuid_lkup_tbl[bta_dm_search_cb.service_index]; |
| 2282 | } |
| 2283 | } |
| 2284 | |
| 2285 | if (uuid.len == 0) |
| 2286 | uuid.len = LEN_UUID_16; |
| 2287 | |
| 2288 | #if 0 |
| 2289 | if (uuid.uu.uuid16 == UUID_SERVCLASS_PNP_INFORMATION) |
| 2290 | { |
| 2291 | num_attrs = 2; |
| 2292 | } |
| 2293 | #endif |
| 2294 | |
| 2295 | if (bta_dm_search_cb.service_index == BTA_USER_SERVICE_ID) |
| 2296 | { |
| 2297 | memcpy(&uuid, &bta_dm_search_cb.uuid, sizeof(tSDP_UUID)); |
| 2298 | } |
| 2299 | |
| 2300 | |
| 2301 | APPL_TRACE_ERROR1("****************search UUID = %04x***********", uuid.uu.uuid16); |
| 2302 | //SDP_InitDiscoveryDb (bta_dm_search_cb.p_sdp_db, BTA_DM_SDP_DB_SIZE, 1, &uuid, num_attrs, attr_list); |
| 2303 | SDP_InitDiscoveryDb (bta_dm_search_cb.p_sdp_db, BTA_DM_SDP_DB_SIZE, 1, &uuid, 0, NULL); |
| 2304 | |
| 2305 | |
| 2306 | memset(g_disc_raw_data_buf, 0, sizeof(g_disc_raw_data_buf)); |
| 2307 | bta_dm_search_cb.p_sdp_db->raw_data = g_disc_raw_data_buf; |
| 2308 | |
| 2309 | bta_dm_search_cb.p_sdp_db->raw_size = MAX_DISC_RAW_DATA_BUF; |
| 2310 | |
| 2311 | if (!SDP_ServiceSearchAttributeRequest (bd_addr, bta_dm_search_cb.p_sdp_db, &bta_dm_sdp_callback)) |
| 2312 | { |
| 2313 | /* if discovery not successful with this device |
| 2314 | proceed to next one */ |
| 2315 | GKI_freebuf(bta_dm_search_cb.p_sdp_db); |
| 2316 | bta_dm_search_cb.p_sdp_db = NULL; |
| 2317 | bta_dm_search_cb.service_index = BTA_MAX_SERVICE_ID; |
| 2318 | |
| 2319 | } |
| 2320 | else |
| 2321 | { |
| 2322 | #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE |
| 2323 | if ((bta_dm_search_cb.service_index == BTA_BLE_SERVICE_ID && |
| 2324 | bta_dm_search_cb.uuid_to_search == 0) || |
| 2325 | bta_dm_search_cb.service_index != BTA_BLE_SERVICE_ID) |
| 2326 | #endif |
| 2327 | bta_dm_search_cb.service_index++; |
| 2328 | return; |
| 2329 | } |
| 2330 | } |
| 2331 | else |
| 2332 | { |
| 2333 | APPL_TRACE_ERROR0("#### Failed to allocate SDP DB buffer! ####"); |
| 2334 | } |
| 2335 | } |
| 2336 | |
| 2337 | bta_dm_search_cb.service_index++; |
| 2338 | } |
| 2339 | |
| 2340 | /* no more services to be discovered */ |
| 2341 | if(bta_dm_search_cb.service_index >= BTA_MAX_SERVICE_ID) |
| 2342 | { |
| 2343 | if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) |
| 2344 | { |
| 2345 | p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT; |
| 2346 | p_msg->disc_result.result.disc_res.services = bta_dm_search_cb.services_found; |
| 2347 | bdcpy (p_msg->disc_result.result.disc_res.bd_addr, bta_dm_search_cb.peer_bdaddr); |
| 2348 | BCM_STRNCPY_S((char*)p_msg->disc_result.result.disc_res.bd_name, sizeof(BD_NAME), |
| 2349 | bta_dm_get_remname(), (BD_NAME_LEN-1)); |
| 2350 | |
| 2351 | /* make sure the string is terminated */ |
| 2352 | p_msg->disc_result.result.disc_res.bd_name[BD_NAME_LEN-1] = 0; |
| 2353 | |
| 2354 | bta_sys_sendmsg(p_msg); |
| 2355 | } |
| 2356 | } |
| 2357 | } |
| 2358 | |
| 2359 | /******************************************************************************* |
| 2360 | ** |
| 2361 | ** Function bta_dm_discover_next_device |
| 2362 | ** |
| 2363 | ** Description Starts discovery on the next device in Inquiry data base |
| 2364 | ** |
| 2365 | ** Returns void |
| 2366 | ** |
| 2367 | *******************************************************************************/ |
| 2368 | static void bta_dm_discover_next_device(void) |
| 2369 | { |
| 2370 | |
| 2371 | tBTA_DM_MSG * p_msg; |
| 2372 | |
| 2373 | APPL_TRACE_DEBUG0("bta_dm_discover_next_device"); |
| 2374 | |
| 2375 | /* searching next device on inquiry result */ |
| 2376 | if((bta_dm_search_cb.p_btm_inq_info = BTM_InqDbNext(bta_dm_search_cb.p_btm_inq_info)) != NULL) |
| 2377 | { |
| 2378 | bta_dm_search_cb.name_discover_done = FALSE; |
| 2379 | bta_dm_search_cb.peer_name[0] = 0; |
| 2380 | bta_dm_discover_device(bta_dm_search_cb.p_btm_inq_info->results.remote_bd_addr); |
| 2381 | } |
| 2382 | else |
| 2383 | { |
| 2384 | /* no devices, search complete */ |
| 2385 | bta_dm_search_cb.services = 0; |
| 2386 | |
| 2387 | if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) |
| 2388 | { |
| 2389 | p_msg->hdr.event = BTA_DM_SEARCH_CMPL_EVT; |
| 2390 | p_msg->hdr.layer_specific = BTA_DM_API_DISCOVER_EVT; |
| 2391 | bta_sys_sendmsg(p_msg); |
| 2392 | } |
| 2393 | } |
| 2394 | } |
| 2395 | |
| 2396 | /******************************************************************************* |
| 2397 | ** |
| 2398 | ** Function bta_dm_discover_device |
| 2399 | ** |
| 2400 | ** Description Starts name and service discovery on the device |
| 2401 | ** |
| 2402 | ** Returns void |
| 2403 | ** |
| 2404 | *******************************************************************************/ |
| 2405 | static void bta_dm_discover_device(BD_ADDR remote_bd_addr) |
| 2406 | { |
| 2407 | tBTA_DM_MSG * p_msg; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2408 | tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR; |
| 2409 | #if BLE_INCLUDED == TRUE |
| 2410 | tBT_DEVICE_TYPE dev_type; |
| 2411 | tBLE_ADDR_TYPE addr_type; |
| 2412 | |
| 2413 | if (bta_dm_search_cb.transport == BTA_TRANSPORT_UNKNOWN) |
| 2414 | { |
| 2415 | BTM_ReadDevInfo(remote_bd_addr, &dev_type, &addr_type); |
| 2416 | if (dev_type == BT_DEVICE_TYPE_BLE || addr_type == BLE_ADDR_RANDOM ) |
| 2417 | transport = BT_TRANSPORT_LE; |
| 2418 | } |
| 2419 | else |
| 2420 | transport = bta_dm_search_cb.transport; |
| 2421 | #endif |
| 2422 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2423 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2424 | APPL_TRACE_DEBUG6("bta_dm_discover_device, BDA:0x%02X%02X%02X%02X%02X%02X", |
| 2425 | remote_bd_addr[0],remote_bd_addr[1], |
| 2426 | remote_bd_addr[2],remote_bd_addr[3], |
| 2427 | remote_bd_addr[4],remote_bd_addr[5]); |
| 2428 | |
| 2429 | bdcpy(bta_dm_search_cb.peer_bdaddr, remote_bd_addr); |
| 2430 | |
| 2431 | APPL_TRACE_DEBUG2("bta_dm_discover_device name_discover_done = %d p_btm_inq_info 0x%x ", |
| 2432 | bta_dm_search_cb.name_discover_done, |
| 2433 | bta_dm_search_cb.p_btm_inq_info |
| 2434 | ); |
| 2435 | if ( bta_dm_search_cb.p_btm_inq_info ) { |
| 2436 | |
| 2437 | APPL_TRACE_DEBUG1("bta_dm_discover_device appl_knows_rem_name %d", |
| 2438 | bta_dm_search_cb.p_btm_inq_info->appl_knows_rem_name |
| 2439 | ); |
| 2440 | } |
| 2441 | |
| 2442 | /* if name discovery is not done and application needs remote name */ |
| 2443 | if ((!bta_dm_search_cb.name_discover_done) |
| 2444 | && (( bta_dm_search_cb.p_btm_inq_info == NULL ) |
| 2445 | ||(bta_dm_search_cb.p_btm_inq_info && (!bta_dm_search_cb.p_btm_inq_info->appl_knows_rem_name)))) |
| 2446 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2447 | if(bta_dm_read_remote_device_name(bta_dm_search_cb.peer_bdaddr, transport) == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2448 | { |
| 2449 | return; |
| 2450 | } |
| 2451 | else |
| 2452 | { |
| 2453 | /* starting name discovery failed */ |
| 2454 | bta_dm_search_cb.name_discover_done = TRUE; |
| 2455 | } |
| 2456 | } |
| 2457 | |
| 2458 | /* if application wants to discover service */ |
| 2459 | if ( bta_dm_search_cb.services ) |
| 2460 | { |
| 2461 | /* initialize variables */ |
| 2462 | bta_dm_search_cb.service_index = 0; |
| 2463 | bta_dm_search_cb.services_found = 0; |
| 2464 | bta_dm_search_cb.services_to_search = bta_dm_search_cb.services; |
| 2465 | #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE |
| 2466 | bta_dm_search_cb.uuid_to_search = bta_dm_search_cb.num_uuid; |
| 2467 | #endif |
| 2468 | #if ( BTM_EIR_CLIENT_INCLUDED == TRUE ) |
| 2469 | if ((bta_dm_search_cb.p_btm_inq_info != NULL) && |
| 2470 | bta_dm_search_cb.services != BTA_USER_SERVICE_MASK |
| 2471 | &&(bta_dm_search_cb.sdp_search == FALSE)) |
| 2472 | { |
| 2473 | /* check if EIR provides the information of supported services */ |
| 2474 | bta_dm_eir_search_services( &bta_dm_search_cb.p_btm_inq_info->results, |
| 2475 | &bta_dm_search_cb.services_to_search, |
| 2476 | &bta_dm_search_cb.services_found ); |
| 2477 | } |
| 2478 | |
| 2479 | /* if seaching with EIR is not completed */ |
| 2480 | if(bta_dm_search_cb.services_to_search) |
| 2481 | #endif |
| 2482 | { |
| 2483 | /* check whether connection already exists to the device |
| 2484 | if connection exists, we don't have to wait for ACL |
| 2485 | link to go down to start search on next device */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2486 | if (BTM_IsAclConnectionUp(bta_dm_search_cb.peer_bdaddr, BT_TRANSPORT_BR_EDR)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2487 | bta_dm_search_cb.wait_disc = FALSE; |
| 2488 | else |
| 2489 | bta_dm_search_cb.wait_disc = TRUE; |
| 2490 | |
| 2491 | #if (BLE_INCLUDED == TRUE && (defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE)) |
| 2492 | if ( bta_dm_search_cb.p_btm_inq_info ) |
| 2493 | { |
| 2494 | APPL_TRACE_DEBUG3("bta_dm_discover_device p_btm_inq_info 0x%x results.device_type 0x%x services_to_search 0x%x", |
| 2495 | bta_dm_search_cb.p_btm_inq_info, |
| 2496 | bta_dm_search_cb.p_btm_inq_info->results.device_type, |
| 2497 | bta_dm_search_cb.services_to_search |
| 2498 | ); |
| 2499 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2500 | if (transport == BT_TRANSPORT_LE) /* |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2501 | if ( bta_dm_search_cb.p_btm_inq_info != NULL && |
| 2502 | bta_dm_search_cb.p_btm_inq_info->results.device_type == BT_DEVICE_TYPE_BLE && |
| 2503 | (bta_dm_search_cb.services_to_search & BTA_BLE_SERVICE_MASK))*/ |
| 2504 | { |
| 2505 | if (bta_dm_search_cb.services_to_search & BTA_BLE_SERVICE_MASK) |
| 2506 | { |
| 2507 | //set the raw data buffer here |
| 2508 | memset(g_disc_raw_data_buf, 0, sizeof(g_disc_raw_data_buf)); |
| 2509 | bta_dm_search_cb.p_ble_rawdata = g_disc_raw_data_buf; |
| 2510 | |
| 2511 | bta_dm_search_cb.ble_raw_size = MAX_DISC_RAW_DATA_BUF; |
| 2512 | bta_dm_search_cb.ble_raw_used = 0; |
| 2513 | |
| 2514 | /* start GATT for service discovery */ |
| 2515 | btm_dm_start_gatt_discovery(bta_dm_search_cb.peer_bdaddr); |
| 2516 | return; |
| 2517 | } |
| 2518 | } |
| 2519 | else |
| 2520 | #endif |
| 2521 | { |
| 2522 | bta_dm_search_cb.sdp_results = FALSE; |
| 2523 | bta_dm_find_services(bta_dm_search_cb.peer_bdaddr); |
| 2524 | |
| 2525 | return; |
| 2526 | } |
| 2527 | } |
| 2528 | } |
| 2529 | |
| 2530 | /* name discovery and service discovery are done for this device */ |
| 2531 | if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) |
| 2532 | { |
| 2533 | p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT; |
| 2534 | /* initialize the data structure - includes p_raw_data and raw_data_size */ |
| 2535 | memset(&(p_msg->disc_result.result), 0, sizeof(tBTA_DM_DISC_RES)); |
| 2536 | p_msg->disc_result.result.disc_res.result = BTA_SUCCESS; |
| 2537 | p_msg->disc_result.result.disc_res.services = bta_dm_search_cb.services_found; |
| 2538 | bdcpy (p_msg->disc_result.result.disc_res.bd_addr, bta_dm_search_cb.peer_bdaddr); |
| 2539 | BCM_STRNCPY_S((char*)p_msg->disc_result.result.disc_res.bd_name, sizeof(BD_NAME), |
| 2540 | (char*)bta_dm_search_cb.peer_name, (BD_NAME_LEN-1)); |
| 2541 | |
| 2542 | /* make sure the string is terminated */ |
| 2543 | p_msg->disc_result.result.disc_res.bd_name[BD_NAME_LEN-1] = 0; |
| 2544 | |
| 2545 | bta_sys_sendmsg(p_msg); |
| 2546 | } |
| 2547 | } |
| 2548 | |
| 2549 | /******************************************************************************* |
| 2550 | ** |
| 2551 | ** Function bta_dm_sdp_callback |
| 2552 | ** |
| 2553 | ** Description Callback from sdp with discovery status |
| 2554 | ** |
| 2555 | ** Returns void |
| 2556 | ** |
| 2557 | *******************************************************************************/ |
| 2558 | static void bta_dm_sdp_callback (UINT16 sdp_status) |
| 2559 | { |
| 2560 | |
| 2561 | tBTA_DM_SDP_RESULT * p_msg; |
| 2562 | |
| 2563 | if ((p_msg = (tBTA_DM_SDP_RESULT *) GKI_getbuf(sizeof(tBTA_DM_SDP_RESULT))) != NULL) |
| 2564 | { |
| 2565 | p_msg->hdr.event = BTA_DM_SDP_RESULT_EVT; |
| 2566 | p_msg->sdp_result = sdp_status; |
| 2567 | bta_sys_sendmsg(p_msg); |
| 2568 | |
| 2569 | } |
| 2570 | } |
| 2571 | |
| 2572 | /******************************************************************************* |
| 2573 | ** |
| 2574 | ** Function bta_dm_inq_results_cb |
| 2575 | ** |
| 2576 | ** Description Inquiry results callback from BTM |
| 2577 | ** |
| 2578 | ** Returns void |
| 2579 | ** |
| 2580 | *******************************************************************************/ |
| 2581 | static void bta_dm_inq_results_cb (tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir) |
| 2582 | { |
| 2583 | |
| 2584 | tBTA_DM_SEARCH result; |
| 2585 | tBTM_INQ_INFO *p_inq_info; |
| 2586 | UINT16 service_class; |
| 2587 | |
| 2588 | bdcpy(result.inq_res.bd_addr, p_inq->remote_bd_addr); |
| 2589 | memcpy(result.inq_res.dev_class, p_inq->dev_class, DEV_CLASS_LEN); |
| 2590 | BTM_COD_SERVICE_CLASS(service_class, p_inq->dev_class); |
| 2591 | result.inq_res.is_limited = (service_class & BTM_COD_SERVICE_LMTD_DISCOVER)?TRUE:FALSE; |
| 2592 | result.inq_res.rssi = p_inq->rssi; |
| 2593 | |
| 2594 | #if (BLE_INCLUDED == TRUE) |
| 2595 | result.inq_res.ble_addr_type = p_inq->ble_addr_type; |
| 2596 | result.inq_res.inq_result_type = p_inq->inq_result_type; |
| 2597 | result.inq_res.device_type = p_inq->device_type; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2598 | result.inq_res.flag = p_inq->flag; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2599 | #endif |
| 2600 | |
| 2601 | /* application will parse EIR to find out remote device name */ |
| 2602 | result.inq_res.p_eir = p_eir; |
| 2603 | |
| 2604 | if((p_inq_info = BTM_InqDbRead(p_inq->remote_bd_addr)) != NULL) |
| 2605 | { |
| 2606 | /* initialize remt_name_not_required to FALSE so that we get the name by default */ |
| 2607 | result.inq_res.remt_name_not_required = FALSE; |
| 2608 | |
| 2609 | } |
| 2610 | |
| 2611 | if(bta_dm_search_cb.p_search_cback) |
| 2612 | bta_dm_search_cb.p_search_cback(BTA_DM_INQ_RES_EVT, &result); |
| 2613 | |
| 2614 | if(p_inq_info) |
| 2615 | { |
| 2616 | /* application indicates if it knows the remote name, inside the callback |
| 2617 | copy that to the inquiry data base*/ |
| 2618 | if(result.inq_res.remt_name_not_required) |
| 2619 | p_inq_info->appl_knows_rem_name = TRUE; |
| 2620 | |
| 2621 | } |
| 2622 | |
| 2623 | |
| 2624 | } |
| 2625 | |
| 2626 | |
| 2627 | /******************************************************************************* |
| 2628 | ** |
| 2629 | ** Function bta_dm_inq_cmpl_cb |
| 2630 | ** |
| 2631 | ** Description Inquiry complete callback from BTM |
| 2632 | ** |
| 2633 | ** Returns void |
| 2634 | ** |
| 2635 | *******************************************************************************/ |
| 2636 | static void bta_dm_inq_cmpl_cb (void * p_result) |
| 2637 | { |
| 2638 | |
| 2639 | tBTA_DM_MSG * p_msg; |
| 2640 | |
| 2641 | APPL_TRACE_DEBUG0("bta_dm_inq_cmpl_cb"); |
| 2642 | if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) |
| 2643 | { |
| 2644 | p_msg->inq_cmpl.hdr.event = BTA_DM_INQUIRY_CMPL_EVT; |
| 2645 | p_msg->inq_cmpl.num = ((tBTM_INQUIRY_CMPL *)p_result)->num_resp; |
| 2646 | bta_sys_sendmsg(p_msg); |
| 2647 | |
| 2648 | } |
| 2649 | |
| 2650 | |
| 2651 | } |
| 2652 | |
| 2653 | /******************************************************************************* |
| 2654 | ** |
| 2655 | ** Function bta_dm_service_search_remname_cback |
| 2656 | ** |
| 2657 | ** Description Remote name call back from BTM during service discovery |
| 2658 | ** |
| 2659 | ** Returns void |
| 2660 | ** |
| 2661 | *******************************************************************************/ |
| 2662 | static void bta_dm_service_search_remname_cback (BD_ADDR bd_addr, DEV_CLASS dc, BD_NAME bd_name) |
| 2663 | { |
| 2664 | tBTM_REMOTE_DEV_NAME rem_name; |
| 2665 | tBTM_STATUS btm_status; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 2666 | UNUSED(dc); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2667 | |
| 2668 | APPL_TRACE_DEBUG1("bta_dm_service_search_remname_cback name=<%s>", bd_name); |
| 2669 | |
| 2670 | /* if this is what we are looking for */ |
| 2671 | if (!bdcmp( bta_dm_search_cb.peer_bdaddr, bd_addr)) |
| 2672 | { |
| 2673 | rem_name.length = strlen((char*)bd_name); |
| 2674 | if (rem_name.length > (BD_NAME_LEN-1)) |
| 2675 | { |
| 2676 | rem_name.length = (BD_NAME_LEN-1); |
| 2677 | rem_name.remote_bd_name[(BD_NAME_LEN-1)] = 0; |
| 2678 | } |
| 2679 | BCM_STRNCPY_S((char*)rem_name.remote_bd_name, sizeof(BD_NAME), (char*)bd_name, (BD_NAME_LEN-1)); |
| 2680 | rem_name.status = BTM_SUCCESS; |
| 2681 | |
| 2682 | bta_dm_remname_cback(&rem_name); |
| 2683 | } |
| 2684 | else |
| 2685 | { |
| 2686 | /* get name of device */ |
| 2687 | btm_status = BTM_ReadRemoteDeviceName (bta_dm_search_cb.peer_bdaddr, |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2688 | (tBTM_CMPL_CB *) bta_dm_remname_cback, |
| 2689 | BT_TRANSPORT_BR_EDR); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2690 | if ( btm_status == BTM_BUSY ) |
| 2691 | { |
| 2692 | /* wait for next chance(notification of remote name discovery done) */ |
| 2693 | APPL_TRACE_DEBUG0("bta_dm_service_search_remname_cback: BTM_ReadRemoteDeviceName is busy"); |
| 2694 | } |
| 2695 | else if ( btm_status != BTM_CMD_STARTED ) |
| 2696 | { |
| 2697 | /* if failed to start getting remote name then continue */ |
| 2698 | APPL_TRACE_WARNING1("bta_dm_service_search_remname_cback: BTM_ReadRemoteDeviceName returns 0x%02X", btm_status); |
| 2699 | |
| 2700 | rem_name.length = 0; |
| 2701 | rem_name.remote_bd_name[0] = 0; |
| 2702 | rem_name.status = btm_status; |
| 2703 | bta_dm_remname_cback(&rem_name); |
| 2704 | } |
| 2705 | } |
| 2706 | } |
| 2707 | |
| 2708 | |
| 2709 | /******************************************************************************* |
| 2710 | ** |
| 2711 | ** Function bta_dm_remname_cback |
| 2712 | ** |
| 2713 | ** Description Remote name complete call back from BTM |
| 2714 | ** |
| 2715 | ** Returns void |
| 2716 | ** |
| 2717 | *******************************************************************************/ |
| 2718 | static void bta_dm_remname_cback (tBTM_REMOTE_DEV_NAME *p_remote_name) |
| 2719 | { |
| 2720 | tBTA_DM_REM_NAME * p_msg; |
| 2721 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2722 | APPL_TRACE_DEBUG2("bta_dm_remname_cback len = %d name=<%s>", p_remote_name->length, |
| 2723 | p_remote_name->remote_bd_name); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2724 | |
| 2725 | /* remote name discovery is done but it could be failed */ |
| 2726 | bta_dm_search_cb.name_discover_done = TRUE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2727 | BCM_STRNCPY_S((char*)bta_dm_search_cb.peer_name, sizeof(BD_NAME), (char*)p_remote_name->remote_bd_name, (BD_NAME_LEN)); |
| 2728 | bta_dm_search_cb.peer_name[BD_NAME_LEN]=0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2729 | |
| 2730 | BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2731 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2732 | #if BLE_INCLUDED == TRUE |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2733 | if (bta_dm_search_cb.transport == BT_TRANSPORT_LE ) |
| 2734 | { |
| 2735 | GAP_BleReadPeerPrefConnParams (bta_dm_search_cb.peer_bdaddr); |
| 2736 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2737 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2738 | if ((p_msg = (tBTA_DM_REM_NAME *) GKI_getbuf(sizeof(tBTA_DM_REM_NAME))) != NULL) |
| 2739 | { |
| 2740 | bdcpy (p_msg->result.disc_res.bd_addr, bta_dm_search_cb.peer_bdaddr); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2741 | BCM_STRNCPY_S((char*)p_msg->result.disc_res.bd_name, sizeof(BD_NAME), (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] | 2742 | |
| 2743 | /* make sure the string is null terminated */ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2744 | p_msg->result.disc_res.bd_name[BD_NAME_LEN] = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2745 | |
| 2746 | p_msg->hdr.event = BTA_DM_REMT_NAME_EVT; |
| 2747 | bta_sys_sendmsg(p_msg); |
| 2748 | |
| 2749 | } |
| 2750 | } |
| 2751 | |
| 2752 | /******************************************************************************* |
| 2753 | ** |
| 2754 | ** Function bta_dm_authorize_cback |
| 2755 | ** |
| 2756 | ** Description cback requesting authorization |
| 2757 | ** |
| 2758 | ** Returns void |
| 2759 | ** |
| 2760 | *******************************************************************************/ |
| 2761 | static UINT8 bta_dm_authorize_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name, |
| 2762 | UINT8 *service_name, UINT8 service_id, BOOLEAN is_originator) |
| 2763 | { |
| 2764 | tBTA_DM_SEC sec_event; |
| 2765 | UINT8 index = 1; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 2766 | UNUSED(service_name); |
| 2767 | UNUSED(is_originator); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2768 | |
| 2769 | bdcpy(sec_event.authorize.bd_addr, bd_addr); |
| 2770 | memcpy(sec_event.authorize.dev_class, dev_class, DEV_CLASS_LEN); |
| 2771 | |
| 2772 | BCM_STRNCPY_S((char*)sec_event.authorize.bd_name, sizeof(BD_NAME), (char*)bd_name, (BD_NAME_LEN-1)); |
| 2773 | |
| 2774 | /* make sure the string is null terminated */ |
| 2775 | sec_event.authorize.bd_name[BD_NAME_LEN-1] = 0; |
| 2776 | |
| 2777 | #if ( defined(BTA_JV_INCLUDED) && BTA_JV_INCLUDED == TRUE ) |
| 2778 | sec_event.authorize.service = service_id; |
| 2779 | #endif |
| 2780 | |
| 2781 | while(index < BTA_MAX_SERVICE_ID) |
| 2782 | { |
| 2783 | /* get the BTA service id corresponding to BTM id */ |
| 2784 | if(bta_service_id_to_btm_srv_id_lkup_tbl[index] == service_id) |
| 2785 | { |
| 2786 | sec_event.authorize.service = index; |
| 2787 | break; |
| 2788 | } |
| 2789 | index++; |
| 2790 | } |
| 2791 | |
| 2792 | |
| 2793 | /* if supported service callback otherwise not authorized */ |
| 2794 | if(bta_dm_cb.p_sec_cback && (index < BTA_MAX_SERVICE_ID |
| 2795 | #if ( defined(BTA_JV_INCLUDED) && BTA_JV_INCLUDED == TRUE ) |
| 2796 | /* pass through JV service ID */ |
| 2797 | || (service_id >= BTA_FIRST_JV_SERVICE_ID && service_id <= BTA_LAST_JV_SERVICE_ID) |
| 2798 | #endif |
| 2799 | )) |
| 2800 | { |
| 2801 | bta_dm_cb.p_sec_cback(BTA_DM_AUTHORIZE_EVT, &sec_event); |
| 2802 | return BTM_CMD_STARTED; |
| 2803 | } |
| 2804 | else |
| 2805 | { |
| 2806 | return BTM_NOT_AUTHORIZED; |
| 2807 | } |
| 2808 | } |
| 2809 | |
| 2810 | |
| 2811 | |
| 2812 | |
| 2813 | |
| 2814 | /******************************************************************************* |
| 2815 | ** |
| 2816 | ** Function bta_dm_pinname_cback |
| 2817 | ** |
| 2818 | ** Description Callback requesting pin_key |
| 2819 | ** |
| 2820 | ** Returns void |
| 2821 | ** |
| 2822 | *******************************************************************************/ |
| 2823 | static void bta_dm_pinname_cback (void *p_data) |
| 2824 | { |
| 2825 | tBTM_REMOTE_DEV_NAME *p_result = (tBTM_REMOTE_DEV_NAME *)p_data; |
| 2826 | tBTA_DM_SEC sec_event; |
| 2827 | UINT32 bytes_to_copy; |
| 2828 | tBTA_DM_SEC_EVT event = bta_dm_cb.pin_evt; |
| 2829 | |
| 2830 | if (BTA_DM_SP_CFM_REQ_EVT == event) |
| 2831 | { |
Andre Eisenbach | 181d075 | 2013-06-11 14:18:21 -0700 | [diff] [blame] | 2832 | /* Retrieved saved device class and bd_addr */ |
| 2833 | bdcpy(sec_event.cfm_req.bd_addr, bta_dm_cb.pin_bd_addr); |
| 2834 | 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] | 2835 | |
Andre Eisenbach | 181d075 | 2013-06-11 14:18:21 -0700 | [diff] [blame] | 2836 | if (p_result && p_result->status == BTM_SUCCESS) |
| 2837 | { |
| 2838 | bytes_to_copy = (p_result->length < (BD_NAME_LEN-1)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2839 | ? p_result->length : (BD_NAME_LEN-1); |
Andre Eisenbach | 181d075 | 2013-06-11 14:18:21 -0700 | [diff] [blame] | 2840 | memcpy(sec_event.cfm_req.bd_name, p_result->remote_bd_name, bytes_to_copy); |
| 2841 | sec_event.pin_req.bd_name[BD_NAME_LEN-1] = 0; |
| 2842 | } |
| 2843 | else /* No name found */ |
| 2844 | sec_event.cfm_req.bd_name[0] = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2845 | |
Andre Eisenbach | 181d075 | 2013-06-11 14:18:21 -0700 | [diff] [blame] | 2846 | sec_event.key_notif.passkey = 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] | 2847 | |
| 2848 | /* 1 additional event data fields for this event */ |
| 2849 | sec_event.cfm_req.just_works = bta_dm_cb.just_works; |
| 2850 | } |
| 2851 | else |
| 2852 | { |
Andre Eisenbach | 181d075 | 2013-06-11 14:18:21 -0700 | [diff] [blame] | 2853 | /* Retrieved saved device class and bd_addr */ |
| 2854 | bdcpy(sec_event.pin_req.bd_addr, bta_dm_cb.pin_bd_addr); |
| 2855 | 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] | 2856 | |
Andre Eisenbach | 181d075 | 2013-06-11 14:18:21 -0700 | [diff] [blame] | 2857 | if (p_result && p_result->status == BTM_SUCCESS) |
| 2858 | { |
| 2859 | bytes_to_copy = (p_result->length < (BD_NAME_LEN-1)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2860 | ? p_result->length : (BD_NAME_LEN-1); |
Andre Eisenbach | 181d075 | 2013-06-11 14:18:21 -0700 | [diff] [blame] | 2861 | memcpy(sec_event.pin_req.bd_name, p_result->remote_bd_name, bytes_to_copy); |
| 2862 | sec_event.pin_req.bd_name[BD_NAME_LEN-1] = 0; |
| 2863 | } |
| 2864 | else /* No name found */ |
| 2865 | sec_event.pin_req.bd_name[0] = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2866 | |
Andre Eisenbach | 181d075 | 2013-06-11 14:18:21 -0700 | [diff] [blame] | 2867 | event = bta_dm_cb.pin_evt; |
| 2868 | sec_event.key_notif.passkey = 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] | 2869 | } |
| 2870 | |
| 2871 | if( bta_dm_cb.p_sec_cback ) |
| 2872 | bta_dm_cb.p_sec_cback(event, &sec_event); |
| 2873 | } |
| 2874 | |
| 2875 | |
| 2876 | |
| 2877 | /******************************************************************************* |
| 2878 | ** |
| 2879 | ** Function bta_dm_pin_cback |
| 2880 | ** |
| 2881 | ** Description Callback requesting pin_key |
| 2882 | ** |
| 2883 | ** Returns void |
| 2884 | ** |
| 2885 | *******************************************************************************/ |
| 2886 | static UINT8 bta_dm_pin_cback (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name) |
| 2887 | { |
| 2888 | tBTA_DM_SEC sec_event; |
| 2889 | |
| 2890 | if (!bta_dm_cb.p_sec_cback) |
| 2891 | return BTM_NOT_AUTHORIZED; |
| 2892 | |
| 2893 | /* If the device name is not known, save bdaddr and devclass and initiate a name request */ |
| 2894 | if (bd_name[0] == 0) |
| 2895 | { |
| 2896 | bta_dm_cb.pin_evt = BTA_DM_PIN_REQ_EVT; |
| 2897 | bdcpy(bta_dm_cb.pin_bd_addr, bd_addr); |
| 2898 | BTA_COPY_DEVICE_CLASS(bta_dm_cb.pin_dev_class, dev_class); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 2899 | if ((BTM_ReadRemoteDeviceName(bd_addr, bta_dm_pinname_cback, BT_TRANSPORT_BR_EDR)) == BTM_CMD_STARTED) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2900 | return BTM_CMD_STARTED; |
| 2901 | |
| 2902 | APPL_TRACE_WARNING0(" bta_dm_pin_cback() -> Failed to start Remote Name Request "); |
| 2903 | } |
| 2904 | |
| 2905 | bdcpy(sec_event.pin_req.bd_addr, bd_addr); |
| 2906 | BTA_COPY_DEVICE_CLASS(sec_event.pin_req.dev_class, dev_class); |
| 2907 | BCM_STRNCPY_S((char*)sec_event.pin_req.bd_name, sizeof(BD_NAME), (char*)bd_name, (BD_NAME_LEN-1)); |
| 2908 | sec_event.pin_req.bd_name[BD_NAME_LEN-1] = 0; |
| 2909 | |
| 2910 | bta_dm_cb.p_sec_cback(BTA_DM_PIN_REQ_EVT, &sec_event); |
| 2911 | return BTM_CMD_STARTED; |
| 2912 | } |
| 2913 | |
| 2914 | |
| 2915 | |
| 2916 | /******************************************************************************* |
| 2917 | ** |
| 2918 | ** Function bta_dm_link_key_request_cback |
| 2919 | ** |
| 2920 | ** Description Callback requesting linkkey |
| 2921 | ** |
| 2922 | ** Returns void |
| 2923 | ** |
| 2924 | *******************************************************************************/ |
| 2925 | static UINT8 bta_dm_link_key_request_cback (BD_ADDR bd_addr, LINK_KEY key) |
| 2926 | { |
| 2927 | /* Application passes all link key to |
| 2928 | BTM during initialization using add_device |
| 2929 | API. If BTM doesn't have the link key in it's |
| 2930 | data base, that's because application doesn't |
| 2931 | it */ |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 2932 | UNUSED(bd_addr); |
| 2933 | UNUSED(key); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2934 | |
| 2935 | return BTM_NOT_AUTHORIZED; |
| 2936 | } |
| 2937 | |
| 2938 | |
| 2939 | |
| 2940 | |
| 2941 | |
| 2942 | /******************************************************************************* |
| 2943 | ** |
| 2944 | ** Function bta_dm_new_link_key_cback |
| 2945 | ** |
| 2946 | ** Description Callback from BTM to notify new link key |
| 2947 | ** |
| 2948 | ** Returns void |
| 2949 | ** |
| 2950 | *******************************************************************************/ |
| 2951 | static UINT8 bta_dm_new_link_key_cback(BD_ADDR bd_addr, DEV_CLASS dev_class, |
| 2952 | BD_NAME bd_name, LINK_KEY key, UINT8 key_type) |
| 2953 | { |
| 2954 | tBTA_DM_SEC sec_event; |
| 2955 | tBTA_DM_AUTH_CMPL *p_auth_cmpl; |
| 2956 | UINT8 event; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 2957 | UNUSED(dev_class); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2958 | |
| 2959 | memset (&sec_event, 0, sizeof(tBTA_DM_SEC)); |
| 2960 | |
| 2961 | /* Not AMP Key type */ |
| 2962 | if (key_type != HCI_LKEY_TYPE_AMP_WIFI && key_type != HCI_LKEY_TYPE_AMP_UWB) |
| 2963 | { |
| 2964 | event = BTA_DM_AUTH_CMPL_EVT; |
| 2965 | p_auth_cmpl = &sec_event.auth_cmpl; |
| 2966 | |
| 2967 | bdcpy(p_auth_cmpl->bd_addr, bd_addr); |
| 2968 | |
| 2969 | memcpy(p_auth_cmpl->bd_name, bd_name, (BD_NAME_LEN-1)); |
| 2970 | p_auth_cmpl->bd_name[BD_NAME_LEN-1] = 0; |
| 2971 | |
| 2972 | p_auth_cmpl->key_present = TRUE; |
| 2973 | p_auth_cmpl->key_type = key_type; |
| 2974 | p_auth_cmpl->success = TRUE; |
| 2975 | |
| 2976 | memcpy(p_auth_cmpl->key, key, LINK_KEY_LEN); |
| 2977 | sec_event.auth_cmpl.fail_reason = HCI_SUCCESS; |
| 2978 | |
| 2979 | if(bta_dm_cb.p_sec_cback) |
| 2980 | { |
| 2981 | bta_dm_cb.p_sec_cback(event, &sec_event); |
| 2982 | } |
| 2983 | } |
| 2984 | else |
| 2985 | { |
| 2986 | APPL_TRACE_WARNING0(" bta_dm_new_link_key_cback() Received AMP Key?? "); |
| 2987 | } |
| 2988 | |
| 2989 | return BTM_CMD_STARTED; |
| 2990 | } |
| 2991 | |
| 2992 | |
| 2993 | /******************************************************************************* |
| 2994 | ** |
| 2995 | ** Function bta_dm_authentication_complete_cback |
| 2996 | ** |
| 2997 | ** Description Authentication complete callback from BTM |
| 2998 | ** |
| 2999 | ** Returns void |
| 3000 | ** |
| 3001 | *******************************************************************************/ |
| 3002 | static UINT8 bta_dm_authentication_complete_cback(BD_ADDR bd_addr, DEV_CLASS dev_class,BD_NAME bd_name, int result) |
| 3003 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3004 | tBTA_DM_SEC sec_event; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 3005 | UNUSED(dev_class); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3006 | |
| 3007 | if(result != BTM_SUCCESS) |
| 3008 | { |
| 3009 | memset(&sec_event, 0, sizeof(tBTA_DM_SEC)); |
| 3010 | bdcpy(sec_event.auth_cmpl.bd_addr, bd_addr); |
| 3011 | |
| 3012 | memcpy(sec_event.auth_cmpl.bd_name, bd_name, (BD_NAME_LEN-1)); |
| 3013 | sec_event.auth_cmpl.bd_name[BD_NAME_LEN-1] = 0; |
| 3014 | |
| 3015 | /* taken care of by memset [above] |
| 3016 | sec_event.auth_cmpl.key_present = FALSE; |
| 3017 | sec_event.auth_cmpl.success = FALSE; |
| 3018 | */ |
| 3019 | sec_event.auth_cmpl.fail_reason = (UINT8)result; |
| 3020 | if(bta_dm_cb.p_sec_cback) |
| 3021 | { |
| 3022 | bta_dm_cb.p_sec_cback(BTA_DM_AUTH_CMPL_EVT, &sec_event); |
| 3023 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3024 | /* delete this device entry from Sec Dev DB */ |
| 3025 | bta_dm_remove_sec_dev_entry(bd_addr); |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 3026 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3027 | } |
| 3028 | |
| 3029 | return BTM_SUCCESS; |
| 3030 | } |
| 3031 | |
| 3032 | /******************************************************************************* |
| 3033 | ** |
| 3034 | ** Function bta_dm_sp_cback |
| 3035 | ** |
| 3036 | ** Description simple pairing callback from BTM |
| 3037 | ** |
| 3038 | ** Returns void |
| 3039 | ** |
| 3040 | *******************************************************************************/ |
| 3041 | static UINT8 bta_dm_sp_cback (tBTM_SP_EVT event, tBTM_SP_EVT_DATA *p_data) |
| 3042 | { |
| 3043 | tBTM_STATUS status = BTM_CMD_STARTED; |
| 3044 | tBTA_DM_SEC sec_event; |
| 3045 | tBTA_DM_SEC_EVT pin_evt = BTA_DM_SP_KEY_NOTIF_EVT; |
| 3046 | |
| 3047 | APPL_TRACE_EVENT1("bta_dm_sp_cback: %d", event); |
| 3048 | if (!bta_dm_cb.p_sec_cback) |
| 3049 | return BTM_NOT_AUTHORIZED; |
| 3050 | |
| 3051 | /* TODO_SP */ |
| 3052 | switch(event) |
| 3053 | { |
| 3054 | case BTM_SP_IO_REQ_EVT: |
| 3055 | #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) |
| 3056 | /* translate auth_req */ |
| 3057 | bta_dm_co_io_req(p_data->io_req.bd_addr, &p_data->io_req.io_cap, |
| 3058 | &p_data->io_req.oob_data, &p_data->io_req.auth_req, p_data->io_req.is_orig); |
| 3059 | #endif |
| 3060 | #if BTM_OOB_INCLUDED == FALSE |
| 3061 | status = BTM_SUCCESS; |
| 3062 | #endif |
| 3063 | |
| 3064 | APPL_TRACE_EVENT2("io mitm: %d oob_data:%d", p_data->io_req.auth_req, p_data->io_req.oob_data); |
| 3065 | break; |
| 3066 | case BTM_SP_IO_RSP_EVT: |
| 3067 | #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) |
| 3068 | bta_dm_co_io_rsp(p_data->io_rsp.bd_addr, p_data->io_rsp.io_cap, |
| 3069 | p_data->io_rsp.oob_data, p_data->io_rsp.auth_req ); |
| 3070 | #endif |
| 3071 | break; |
| 3072 | |
| 3073 | case BTM_SP_CFM_REQ_EVT: |
| 3074 | pin_evt = BTA_DM_SP_CFM_REQ_EVT; |
| 3075 | bta_dm_cb.just_works = sec_event.cfm_req.just_works = p_data->cfm_req.just_works; |
| 3076 | sec_event.cfm_req.loc_auth_req = p_data->cfm_req.loc_auth_req; |
| 3077 | sec_event.cfm_req.rmt_auth_req = p_data->cfm_req.rmt_auth_req; |
| 3078 | sec_event.cfm_req.loc_io_caps = p_data->cfm_req.loc_io_caps; |
| 3079 | sec_event.cfm_req.rmt_io_caps = p_data->cfm_req.rmt_io_caps; |
| 3080 | /* continue to next case */ |
| 3081 | #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) |
| 3082 | /* Passkey entry mode, mobile device with output capability is very |
| 3083 | unlikely to receive key request, so skip this event */ |
| 3084 | /*case BTM_SP_KEY_REQ_EVT: */ |
| 3085 | case BTM_SP_KEY_NOTIF_EVT: |
| 3086 | #endif |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3087 | if(BTM_SP_CFM_REQ_EVT == event) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3088 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3089 | /* Due to the switch case falling through below to BTM_SP_KEY_NOTIF_EVT, |
| 3090 | call remote name request using values from cfm_req */ |
| 3091 | if(p_data->cfm_req.bd_name[0] == 0) |
| 3092 | { |
| 3093 | bta_dm_cb.pin_evt = pin_evt; |
| 3094 | bdcpy(bta_dm_cb.pin_bd_addr, p_data->cfm_req.bd_addr); |
| 3095 | BTA_COPY_DEVICE_CLASS(bta_dm_cb.pin_dev_class, p_data->cfm_req.dev_class); |
| 3096 | if ((BTM_ReadRemoteDeviceName(p_data->cfm_req.bd_addr, bta_dm_pinname_cback, |
| 3097 | BT_TRANSPORT_BR_EDR)) == BTM_CMD_STARTED) |
| 3098 | return BTM_CMD_STARTED; |
| 3099 | APPL_TRACE_WARNING0(" bta_dm_sp_cback() -> Failed to start Remote Name Request "); |
| 3100 | } |
| 3101 | else |
| 3102 | { |
| 3103 | /* Due to the switch case falling through below to BTM_SP_KEY_NOTIF_EVT, |
| 3104 | copy these values into key_notif from cfm_req */ |
| 3105 | bdcpy(sec_event.key_notif.bd_addr, p_data->cfm_req.bd_addr); |
| 3106 | BTA_COPY_DEVICE_CLASS(sec_event.key_notif.dev_class, p_data->cfm_req.dev_class); |
| 3107 | BCM_STRNCPY_S((char*)sec_event.key_notif.bd_name, sizeof(BD_NAME), |
| 3108 | (char*)p_data->cfm_req.bd_name, (BD_NAME_LEN-1)); |
| 3109 | sec_event.key_notif.bd_name[BD_NAME_LEN-1] = 0; |
| 3110 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3111 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3112 | |
| 3113 | bta_dm_cb.num_val = sec_event.key_notif.passkey = p_data->key_notif.passkey; |
| 3114 | if (BTM_SP_KEY_NOTIF_EVT == event) |
| 3115 | { |
| 3116 | /* If the device name is not known, save bdaddr and devclass |
| 3117 | and initiate a name request with values from key_notif */ |
| 3118 | if(p_data->key_notif.bd_name[0] == 0) |
| 3119 | { |
| 3120 | bta_dm_cb.pin_evt = pin_evt; |
| 3121 | bdcpy(bta_dm_cb.pin_bd_addr, p_data->key_notif.bd_addr); |
| 3122 | BTA_COPY_DEVICE_CLASS(bta_dm_cb.pin_dev_class, p_data->key_notif.dev_class); |
| 3123 | if ((BTM_ReadRemoteDeviceName(p_data->key_notif.bd_addr, bta_dm_pinname_cback, |
| 3124 | BT_TRANSPORT_BR_EDR)) == BTM_CMD_STARTED) |
| 3125 | return BTM_CMD_STARTED; |
| 3126 | APPL_TRACE_WARNING0(" bta_dm_sp_cback() -> Failed to start Remote Name Request "); |
| 3127 | } |
| 3128 | else |
| 3129 | { |
| 3130 | bdcpy(sec_event.key_notif.bd_addr, p_data->key_notif.bd_addr); |
| 3131 | BTA_COPY_DEVICE_CLASS(sec_event.key_notif.dev_class, p_data->key_notif.dev_class); |
| 3132 | BCM_STRNCPY_S((char*)sec_event.key_notif.bd_name, sizeof(BD_NAME), |
| 3133 | (char*)p_data->key_notif.bd_name, (BD_NAME_LEN-1)); |
| 3134 | sec_event.key_notif.bd_name[BD_NAME_LEN-1] = 0; |
| 3135 | } |
| 3136 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3137 | |
| 3138 | bta_dm_cb.p_sec_cback(pin_evt, &sec_event); |
| 3139 | |
| 3140 | break; |
| 3141 | |
| 3142 | #if BTM_OOB_INCLUDED == TRUE |
| 3143 | case BTM_SP_LOC_OOB_EVT: |
| 3144 | bta_dm_co_loc_oob((BOOLEAN)(p_data->loc_oob.status == BTM_SUCCESS), |
| 3145 | p_data->loc_oob.c, p_data->loc_oob.r); |
| 3146 | break; |
| 3147 | |
| 3148 | case BTM_SP_RMT_OOB_EVT: |
| 3149 | /* If the device name is not known, save bdaddr and devclass and initiate a name request */ |
| 3150 | if (p_data->rmt_oob.bd_name[0] == 0) |
| 3151 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3152 | bta_dm_cb.pin_evt = BTA_DM_SP_RMT_OOB_EVT; |
| 3153 | bdcpy(bta_dm_cb.pin_bd_addr, p_data->rmt_oob.bd_addr); |
| 3154 | BTA_COPY_DEVICE_CLASS(bta_dm_cb.pin_dev_class, p_data->rmt_oob.dev_class); |
| 3155 | if ((BTM_ReadRemoteDeviceName(p_data->rmt_oob.bd_addr, bta_dm_pinname_cback, |
| 3156 | BT_TRANSPORT_BR_EDR)) == BTM_CMD_STARTED) |
| 3157 | return BTM_CMD_STARTED; |
| 3158 | APPL_TRACE_WARNING0(" bta_dm_sp_cback() -> Failed to start Remote Name Request "); |
| 3159 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3160 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3161 | bdcpy(sec_event.rmt_oob.bd_addr, p_data->rmt_oob.bd_addr); |
| 3162 | BTA_COPY_DEVICE_CLASS(sec_event.rmt_oob.dev_class, p_data->rmt_oob.dev_class); |
| 3163 | BCM_STRNCPY_S((char*)sec_event.rmt_oob.bd_name, sizeof(BD_NAME), (char*)p_data->rmt_oob.bd_name, (BD_NAME_LEN-1)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3164 | sec_event.rmt_oob.bd_name[BD_NAME_LEN-1] = 0; |
| 3165 | |
| 3166 | bta_dm_cb.p_sec_cback(BTA_DM_SP_RMT_OOB_EVT, &sec_event); |
| 3167 | |
| 3168 | bta_dm_co_rmt_oob(p_data->rmt_oob.bd_addr); |
| 3169 | break; |
| 3170 | #endif |
| 3171 | case BTM_SP_COMPLT_EVT: |
| 3172 | /* do not report this event - handled by link_key_callback or auth_complete_callback */ |
| 3173 | break; |
| 3174 | |
| 3175 | case BTM_SP_KEYPRESS_EVT: |
| 3176 | memcpy(&sec_event.key_press, &p_data->key_press, sizeof(tBTM_SP_KEYPRESS)); |
| 3177 | bta_dm_cb.p_sec_cback(BTA_DM_SP_KEYPRESS_EVT, &sec_event); |
| 3178 | break; |
| 3179 | |
| 3180 | case BTM_SP_UPGRADE_EVT: |
| 3181 | bta_dm_co_lk_upgrade(p_data->upgrade.bd_addr, &p_data->upgrade.upgrade ); |
| 3182 | break; |
| 3183 | |
| 3184 | default: |
| 3185 | status = BTM_NOT_AUTHORIZED; |
| 3186 | break; |
| 3187 | } |
| 3188 | APPL_TRACE_EVENT1("dm status: %d", status); |
| 3189 | return status; |
| 3190 | } |
| 3191 | |
| 3192 | /******************************************************************************* |
| 3193 | ** |
| 3194 | ** Function bta_dm_local_name_cback |
| 3195 | ** |
| 3196 | ** Description Callback from btm after local name is read |
| 3197 | ** |
| 3198 | ** |
| 3199 | ** Returns void |
| 3200 | ** |
| 3201 | *******************************************************************************/ |
| 3202 | static void bta_dm_local_name_cback(UINT8 *p_name) |
| 3203 | { |
| 3204 | tBTA_DM_SEC sec_event; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 3205 | UNUSED(p_name); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3206 | |
| 3207 | BTM_GetLocalDeviceAddr(sec_event.enable.bd_addr); |
| 3208 | sec_event.enable.status = BTA_SUCCESS; |
| 3209 | |
| 3210 | if(bta_dm_cb.p_sec_cback) |
| 3211 | bta_dm_cb.p_sec_cback(BTA_DM_ENABLE_EVT, &sec_event); |
| 3212 | } |
| 3213 | |
| 3214 | /******************************************************************************* |
| 3215 | ** |
| 3216 | ** Function bta_dm_signal_strength |
| 3217 | ** |
| 3218 | ** Description Callback from btm after local bdaddr is read |
| 3219 | ** |
| 3220 | ** |
| 3221 | ** Returns void |
| 3222 | ** |
| 3223 | *******************************************************************************/ |
| 3224 | void bta_dm_signal_strength(tBTA_DM_MSG *p_data) |
| 3225 | { |
| 3226 | |
| 3227 | if(p_data->sig_strength.start) |
| 3228 | { |
| 3229 | bta_dm_cb.signal_strength_mask = p_data->sig_strength.mask; |
| 3230 | bta_dm_cb.signal_strength_period = p_data->sig_strength.period; |
| 3231 | bta_dm_signal_strength_timer_cback(NULL); |
| 3232 | } |
| 3233 | else |
| 3234 | { |
| 3235 | bta_sys_stop_timer(&bta_dm_cb.signal_strength_timer); |
| 3236 | } |
| 3237 | |
| 3238 | } |
| 3239 | /******************************************************************************* |
| 3240 | ** |
| 3241 | ** Function bta_dm_signal_strength_timer_cback |
| 3242 | ** |
| 3243 | ** Description Periodic timer callback to read signal strength |
| 3244 | ** |
| 3245 | ** |
| 3246 | ** Returns void |
| 3247 | ** |
| 3248 | *******************************************************************************/ |
| 3249 | static void bta_dm_signal_strength_timer_cback (TIMER_LIST_ENT *p_tle) |
| 3250 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 3251 | UNUSED(p_tle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3252 | UINT8 i; |
| 3253 | |
| 3254 | if(bta_dm_cb.signal_strength_mask & BTA_SIG_STRENGTH_RSSI_MASK) |
| 3255 | { |
| 3256 | for(i=0; i<bta_dm_cb.device_list.count; i++) |
| 3257 | { |
| 3258 | BTM_ReadRSSI (bta_dm_cb.device_list.peer_device[i].peer_bdaddr, (tBTM_CMPL_CB *)bta_dm_rssi_cback); |
| 3259 | |
| 3260 | } |
| 3261 | } |
| 3262 | if(bta_dm_cb.signal_strength_mask & BTA_SIG_STRENGTH_LINK_QUALITY_MASK) |
| 3263 | { |
| 3264 | |
| 3265 | for(i=0; i<bta_dm_cb.device_list.count; i++) |
| 3266 | { |
| 3267 | BTM_ReadLinkQuality (bta_dm_cb.device_list.peer_device[i].peer_bdaddr, (tBTM_CMPL_CB *)bta_dm_link_quality_cback); |
| 3268 | } |
| 3269 | |
| 3270 | } |
| 3271 | |
| 3272 | if(bta_dm_cb.signal_strength_period) |
| 3273 | { |
| 3274 | bta_dm_cb.signal_strength_timer.p_cback = (TIMER_CBACK*)&bta_dm_signal_strength_timer_cback; |
| 3275 | bta_sys_start_timer(&bta_dm_cb.signal_strength_timer, 0, (UINT32)1000*bta_dm_cb.signal_strength_period); |
| 3276 | } |
| 3277 | } |
| 3278 | |
| 3279 | |
| 3280 | #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
| 3281 | /******************************************************************************* |
| 3282 | ** |
| 3283 | ** Function bta_dm_bl_change_cback |
| 3284 | ** |
| 3285 | ** Description Callback from btm when acl connection goes up or down |
| 3286 | ** |
| 3287 | ** |
| 3288 | ** Returns void |
| 3289 | ** |
| 3290 | *******************************************************************************/ |
| 3291 | static void bta_dm_bl_change_cback (tBTM_BL_EVENT_DATA *p_data) |
| 3292 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3293 | tBTA_DM_ACL_CHANGE * p_msg; |
| 3294 | |
| 3295 | if ((p_msg = (tBTA_DM_ACL_CHANGE *) GKI_getbuf(sizeof(tBTA_DM_ACL_CHANGE))) != NULL) |
| 3296 | { |
| 3297 | p_msg->event = p_data->event; |
| 3298 | p_msg->is_new = FALSE; |
| 3299 | |
| 3300 | switch(p_msg->event) |
| 3301 | { |
| 3302 | case BTM_BL_CONN_EVT: |
| 3303 | p_msg->is_new = TRUE; |
| 3304 | bdcpy(p_msg->bd_addr, p_data->conn.p_bda); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3305 | #if BLE_INCLUDED == TRUE |
| 3306 | p_msg->transport = p_data->conn.transport; |
| 3307 | p_msg->handle = p_data->conn.handle; |
| 3308 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3309 | break; |
| 3310 | case BTM_BL_DISCN_EVT: |
| 3311 | bdcpy(p_msg->bd_addr, p_data->discn.p_bda); |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3312 | #if BLE_INCLUDED == TRUE |
| 3313 | p_msg->transport = p_data->discn.transport; |
| 3314 | p_msg->handle = p_data->discn.handle; |
| 3315 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3316 | break; |
| 3317 | case BTM_BL_UPDATE_EVT: |
| 3318 | p_msg->busy_level = p_data->update.busy_level; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3319 | p_msg->busy_level_flags = p_data->update.busy_level_flags; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3320 | break; |
| 3321 | case BTM_BL_ROLE_CHG_EVT: |
| 3322 | p_msg->new_role = p_data->role_chg.new_role; |
| 3323 | p_msg->hci_status = p_data->role_chg.hci_status; |
| 3324 | bdcpy(p_msg->bd_addr, p_data->role_chg.p_bda); |
| 3325 | break; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3326 | case BTM_BL_COLLISION_EVT: |
| 3327 | bdcpy(p_msg->bd_addr, p_data->conn.p_bda); |
| 3328 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | p_msg->hdr.event = BTA_DM_ACL_CHANGE_EVT; |
| 3332 | bta_sys_sendmsg(p_msg); |
| 3333 | |
| 3334 | } |
| 3335 | |
| 3336 | } |
| 3337 | #else |
| 3338 | |
| 3339 | /******************************************************************************* |
| 3340 | ** |
| 3341 | ** Function bta_dm_acl_change_cback |
| 3342 | ** |
| 3343 | ** Description Callback from btm when acl connection goes up or down |
| 3344 | ** |
| 3345 | ** |
| 3346 | ** Returns void |
| 3347 | ** |
| 3348 | *******************************************************************************/ |
| 3349 | static void bta_dm_acl_change_cback (BD_ADDR p_bda, DEV_CLASS p_dc, BD_NAME p_bdn, |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3350 | UINT8 *features, BOOLEAN is_new,UINT16 handle, |
| 3351 | tBT_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3352 | { |
| 3353 | |
| 3354 | tBTA_DM_ACL_CHANGE * p_msg; |
| 3355 | |
| 3356 | if ((p_msg = (tBTA_DM_ACL_CHANGE *) GKI_getbuf(sizeof(tBTA_DM_ACL_CHANGE))) != NULL) |
| 3357 | { |
| 3358 | bdcpy (p_msg->bd_addr, p_bda); |
| 3359 | p_msg->is_new = is_new; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3360 | #if BLE_INCLUDED == TRUE |
| 3361 | p_msg->handle = handle; |
| 3362 | p_msg->transport = transport; |
| 3363 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3364 | /* This is collision case */ |
| 3365 | if (features != NULL) |
| 3366 | { |
| 3367 | if ((features[0] == 0xFF) && !is_new) |
| 3368 | p_msg->event = BTM_BL_COLLISION_EVT; |
| 3369 | } |
| 3370 | |
| 3371 | p_msg->hdr.event = BTA_DM_ACL_CHANGE_EVT; |
| 3372 | bta_sys_sendmsg(p_msg); |
| 3373 | |
| 3374 | } |
| 3375 | |
| 3376 | } |
| 3377 | #endif |
| 3378 | /******************************************************************************* |
| 3379 | ** |
| 3380 | ** Function bta_dm_rs_cback |
| 3381 | ** |
| 3382 | ** Description Receives the role switch complete event |
| 3383 | ** |
| 3384 | ** Returns |
| 3385 | ** |
| 3386 | *******************************************************************************/ |
| 3387 | static void bta_dm_rs_cback (tBTM_ROLE_SWITCH_CMPL *p1) |
| 3388 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 3389 | UNUSED(p1); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3390 | APPL_TRACE_WARNING1("bta_dm_rs_cback:%d", bta_dm_cb.rs_event); |
| 3391 | if(bta_dm_cb.rs_event == BTA_DM_API_SEARCH_EVT) |
| 3392 | { |
| 3393 | bta_dm_cb.search_msg.rs_res = BTA_DM_RS_OK; /* do not care about the result for now */ |
| 3394 | bta_dm_cb.rs_event = 0; |
| 3395 | bta_dm_search_start((tBTA_DM_MSG *)&bta_dm_cb.search_msg); |
| 3396 | } |
| 3397 | } |
| 3398 | |
| 3399 | /******************************************************************************* |
| 3400 | ** |
| 3401 | ** Function bta_dm_check_av |
| 3402 | ** |
| 3403 | ** Description This function checks if AV is active |
| 3404 | ** if yes, make sure the AV link is master |
| 3405 | ** |
| 3406 | ** Returns BOOLEAN - TRUE, if switch is in progress |
| 3407 | ** |
| 3408 | *******************************************************************************/ |
| 3409 | static BOOLEAN bta_dm_check_av(UINT16 event) |
| 3410 | { |
Mattias Agren | 9647e91 | 2013-04-08 12:23:42 +0200 | [diff] [blame] | 3411 | BOOLEAN avoid_roleswitch = FALSE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3412 | BOOLEAN switching = FALSE; |
| 3413 | UINT8 i; |
| 3414 | tBTA_DM_PEER_DEVICE *p_dev; |
| 3415 | |
Mattias Agren | 9647e91 | 2013-04-08 12:23:42 +0200 | [diff] [blame] | 3416 | #if defined(BTA_DM_AVOID_A2DP_ROLESWITCH_ON_INQUIRY) && (BTA_DM_AVOID_A2DP_ROLESWITCH_ON_INQUIRY == TRUE) |
| 3417 | |
| 3418 | /* avoid role switch upon inquiry if a2dp is actively streaming as it |
| 3419 | introduces an audioglitch due to FW scheduling delays (unavoidable) */ |
| 3420 | if (event == BTA_DM_API_SEARCH_EVT) |
| 3421 | { |
| 3422 | avoid_roleswitch = TRUE; |
| 3423 | } |
| 3424 | #endif |
| 3425 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3426 | APPL_TRACE_WARNING1("bta_dm_check_av:%d", bta_dm_cb.cur_av_count); |
| 3427 | if(bta_dm_cb.cur_av_count) |
| 3428 | { |
| 3429 | for(i=0; i<bta_dm_cb.device_list.count; i++) |
| 3430 | { |
| 3431 | p_dev = &bta_dm_cb.device_list.peer_device[i]; |
Mattias Agren | 9647e91 | 2013-04-08 12:23:42 +0200 | [diff] [blame] | 3432 | APPL_TRACE_WARNING4("[%d]: state:%d, info:x%x, avoid_rs %d", |
| 3433 | i, p_dev->conn_state, p_dev->info, avoid_roleswitch); |
| 3434 | if((p_dev->conn_state == BTA_DM_CONNECTED) && (p_dev->info & BTA_DM_DI_AV_ACTIVE) && |
| 3435 | (avoid_roleswitch == FALSE)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3436 | { |
| 3437 | /* make master and take away the role switch policy */ |
| 3438 | if(BTM_CMD_STARTED == BTM_SwitchRole (p_dev->peer_bdaddr, HCI_ROLE_MASTER, (tBTM_CMPL_CB *)bta_dm_rs_cback)) |
| 3439 | { |
| 3440 | /* the role switch command is actually sent */ |
| 3441 | bta_dm_cb.rs_event = event; |
| 3442 | switching = TRUE; |
| 3443 | } |
| 3444 | /* else either already master or can not switch for some reasons */ |
| 3445 | bta_dm_policy_cback(BTA_SYS_PLCY_CLR, 0, HCI_ENABLE_MASTER_SLAVE_SWITCH, p_dev->peer_bdaddr); |
| 3446 | break; |
| 3447 | } |
| 3448 | } |
| 3449 | } |
| 3450 | return switching; |
| 3451 | } |
| 3452 | |
| 3453 | /******************************************************************************* |
| 3454 | ** |
| 3455 | ** Function bta_dm_acl_change |
| 3456 | ** |
| 3457 | ** Description Process BTA_DM_ACL_CHANGE_EVT |
| 3458 | ** |
| 3459 | ** |
| 3460 | ** Returns void |
| 3461 | ** |
| 3462 | *******************************************************************************/ |
| 3463 | void bta_dm_acl_change(tBTA_DM_MSG *p_data) |
| 3464 | { |
| 3465 | |
| 3466 | UINT8 i; |
| 3467 | UINT8 *p; |
| 3468 | tBTA_DM_SEC conn; |
| 3469 | BOOLEAN is_new = p_data->acl_change.is_new; |
| 3470 | BD_ADDR_PTR p_bda = p_data->acl_change.bd_addr; |
| 3471 | BOOLEAN need_policy_change = FALSE; |
| 3472 | BOOLEAN issue_unpair_cb = FALSE; |
| 3473 | |
| 3474 | #if (defined(BTM_BUSY_LEVEL_CHANGE_INCLUDED) && BTM_BUSY_LEVEL_CHANGE_INCLUDED == TRUE) |
| 3475 | tBTA_DM_PEER_DEVICE *p_dev; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3476 | memset(&conn, 0, sizeof(tBTA_DM_SEC)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3477 | |
| 3478 | switch(p_data->acl_change.event) |
| 3479 | { |
| 3480 | case BTM_BL_UPDATE_EVT: /* busy level update */ |
| 3481 | if( bta_dm_cb.p_sec_cback ) |
| 3482 | { |
| 3483 | conn.busy_level.level = p_data->acl_change.busy_level; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3484 | conn.busy_level.level_flags = p_data->acl_change.busy_level_flags; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3485 | bta_dm_cb.p_sec_cback(BTA_DM_BUSY_LEVEL_EVT, &conn); |
| 3486 | } |
| 3487 | return; |
| 3488 | |
| 3489 | case BTM_BL_ROLE_CHG_EVT: /* role change event */ |
| 3490 | p_dev = bta_dm_find_peer_device(p_bda); |
| 3491 | if(p_dev) |
| 3492 | { |
| 3493 | APPL_TRACE_DEBUG3("bta_dm_acl_change role chg info:x%x new_role:%d dev count:%d", |
| 3494 | p_dev->info, p_data->acl_change.new_role, bta_dm_cb.device_list.count); |
| 3495 | if(p_dev->info & BTA_DM_DI_AV_ACTIVE) |
| 3496 | { |
| 3497 | /* there's AV activity on this link */ |
| 3498 | if(p_data->acl_change.new_role == HCI_ROLE_SLAVE && bta_dm_cb.device_list.count > 1 |
| 3499 | && p_data->acl_change.hci_status == HCI_SUCCESS) |
| 3500 | { |
| 3501 | /* more than one connections and the AV connection is role switched to slave |
| 3502 | * switch it back to master and remove the switch policy */ |
| 3503 | BTM_SwitchRole(p_bda, BTM_ROLE_MASTER, NULL); |
| 3504 | need_policy_change = TRUE; |
| 3505 | } |
| 3506 | else if (bta_dm_cfg.avoid_scatter && (p_data->acl_change.new_role == HCI_ROLE_MASTER)) |
| 3507 | { |
| 3508 | /* if the link updated to be master include AV activities, remove the switch policy */ |
| 3509 | need_policy_change = TRUE; |
| 3510 | } |
| 3511 | |
| 3512 | if(need_policy_change) |
| 3513 | { |
| 3514 | bta_dm_policy_cback(BTA_SYS_PLCY_CLR, 0, HCI_ENABLE_MASTER_SLAVE_SWITCH, p_dev->peer_bdaddr); |
| 3515 | } |
| 3516 | } |
| 3517 | else |
| 3518 | { |
| 3519 | /* there's AV no activity on this link and role switch happened |
| 3520 | * check if AV is active |
| 3521 | * if so, make sure the AV link is master */ |
| 3522 | bta_dm_check_av(0); |
| 3523 | } |
| 3524 | bta_sys_notify_role_chg(p_data->acl_change.bd_addr, p_data->acl_change.new_role, p_data->acl_change.hci_status); |
| 3525 | bdcpy(conn.role_chg.bd_addr, p_bda); |
| 3526 | conn.role_chg.new_role = (UINT8) p_data->acl_change.new_role; |
| 3527 | if( bta_dm_cb.p_sec_cback ) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3528 | bta_dm_cb.p_sec_cback(BTA_DM_ROLE_CHG_EVT, (tBTA_DM_SEC *)&conn); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3529 | } |
| 3530 | return; |
| 3531 | } |
| 3532 | #endif |
| 3533 | |
| 3534 | /* Collision report from Stack: Notify profiles */ |
| 3535 | if (p_data->acl_change.event == BTM_BL_COLLISION_EVT) |
| 3536 | { |
| 3537 | bta_sys_notify_collision (p_bda); |
| 3538 | return; |
| 3539 | } |
| 3540 | |
| 3541 | if(is_new) |
| 3542 | { |
| 3543 | for(i=0; i<bta_dm_cb.device_list.count; i++) |
| 3544 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3545 | if (!bdcmp( bta_dm_cb.device_list.peer_device[i].peer_bdaddr, p_bda) |
| 3546 | #if BLE_INCLUDED == TRUE |
| 3547 | && bta_dm_cb.device_list.peer_device[i].conn_handle == p_data->acl_change.handle |
| 3548 | #endif |
| 3549 | ) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3550 | break; |
| 3551 | |
| 3552 | } |
| 3553 | |
| 3554 | if(i == bta_dm_cb.device_list.count) |
| 3555 | { |
| 3556 | bdcpy(bta_dm_cb.device_list.peer_device[bta_dm_cb.device_list.count].peer_bdaddr, p_bda); |
| 3557 | bta_dm_cb.device_list.peer_device[bta_dm_cb.device_list.count].link_policy = bta_dm_cb.cur_policy; |
| 3558 | bta_dm_cb.device_list.count++; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3559 | #if BLE_INCLUDED == TRUE |
| 3560 | bta_dm_cb.device_list.peer_device[i].conn_handle = p_data->acl_change.handle; |
| 3561 | if (p_data->acl_change.transport == BT_TRANSPORT_LE) |
| 3562 | bta_dm_cb.device_list.le_count++; |
| 3563 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | bta_dm_cb.device_list.peer_device[i].conn_state = BTA_DM_CONNECTED; |
| 3567 | bta_dm_cb.device_list.peer_device[i].pref_role = BTA_ANY_ROLE; |
| 3568 | bdcpy(conn.link_up.bd_addr, p_bda); |
| 3569 | bta_dm_cb.device_list.peer_device[i].info = BTA_DM_DI_NONE; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3570 | #if BLE_INCLUDED == TRUE |
| 3571 | conn.link_up.link_type = p_data->acl_change.transport; |
| 3572 | bta_dm_cb.device_list.peer_device[i].transport = p_data->acl_change.transport; |
| 3573 | #endif |
| 3574 | |
| 3575 | if (((NULL != (p = BTM_ReadLocalFeatures ())) && HCI_SNIFF_SUB_RATE_SUPPORTED(p)) && |
| 3576 | ((NULL != (p = BTM_ReadRemoteFeatures (p_bda))) && HCI_SNIFF_SUB_RATE_SUPPORTED(p))) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3577 | { |
| 3578 | /* both local and remote devices support SSR */ |
| 3579 | bta_dm_cb.device_list.peer_device[i].info = BTA_DM_DI_USE_SSR; |
| 3580 | } |
| 3581 | APPL_TRACE_WARNING1("info:x%x", bta_dm_cb.device_list.peer_device[i].info); |
| 3582 | if( bta_dm_cb.p_sec_cback ) |
| 3583 | bta_dm_cb.p_sec_cback(BTA_DM_LINK_UP_EVT, &conn); |
| 3584 | |
| 3585 | } |
| 3586 | else |
| 3587 | { |
| 3588 | for(i=0; i<bta_dm_cb.device_list.count; i++) |
| 3589 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3590 | if (bdcmp( bta_dm_cb.device_list.peer_device[i].peer_bdaddr, p_bda) |
| 3591 | #if BLE_INCLUDED == TRUE |
| 3592 | ||bta_dm_cb.device_list.peer_device[i].transport != p_data->acl_change.transport |
| 3593 | #endif |
| 3594 | ) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3595 | continue; |
| 3596 | |
| 3597 | if( bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_UNPAIRING ) |
| 3598 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3599 | if (BTM_SecDeleteDevice(bta_dm_cb.device_list.peer_device[i].peer_bdaddr)) |
| 3600 | { |
Zhihai Xu | bd68d68 | 2013-11-15 17:55:46 -0800 | [diff] [blame] | 3601 | #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3602 | /* remove all cached GATT information */ |
| 3603 | BTA_GATTC_Refresh(p_bda); |
Zhihai Xu | bd68d68 | 2013-11-15 17:55:46 -0800 | [diff] [blame] | 3604 | #endif |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3605 | issue_unpair_cb = TRUE; |
| 3606 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3607 | } |
| 3608 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3609 | conn.link_down.is_removed = bta_dm_cb.device_list.peer_device[i].remove_dev_pending; |
| 3610 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3611 | for(; i<bta_dm_cb.device_list.count ; i++) |
| 3612 | { |
| 3613 | memcpy(&bta_dm_cb.device_list.peer_device[i], &bta_dm_cb.device_list.peer_device[i+1], sizeof(bta_dm_cb.device_list.peer_device[i])); |
| 3614 | } |
| 3615 | break; |
| 3616 | } |
| 3617 | if(bta_dm_cb.device_list.count) |
| 3618 | bta_dm_cb.device_list.count--; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3619 | #if BLE_INCLUDED == TRUE |
| 3620 | if ((p_data->acl_change.transport == BT_TRANSPORT_LE) && |
| 3621 | (bta_dm_cb.device_list.le_count)) |
| 3622 | bta_dm_cb.device_list.le_count--; |
| 3623 | conn.link_down.link_type = p_data->acl_change.transport; |
| 3624 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3625 | |
| 3626 | if(bta_dm_search_cb.wait_disc && !bdcmp(bta_dm_search_cb.peer_bdaddr, p_bda)) |
| 3627 | { |
| 3628 | bta_dm_search_cb.wait_disc = FALSE; |
| 3629 | |
| 3630 | if(bta_dm_search_cb.sdp_results) |
| 3631 | { |
| 3632 | APPL_TRACE_EVENT0(" timer stopped "); |
| 3633 | bta_sys_stop_timer(&bta_dm_search_cb.search_timer); |
| 3634 | bta_dm_discover_next_device(); |
| 3635 | } |
| 3636 | |
| 3637 | } |
| 3638 | |
| 3639 | if(bta_dm_cb.disabling) |
| 3640 | { |
| 3641 | if(!BTM_GetNumAclLinks()) |
| 3642 | { |
| 3643 | bta_sys_stop_timer(&bta_dm_cb.disable_timer); |
| 3644 | bta_dm_cb.disable_timer.p_cback = (TIMER_CBACK*)&bta_dm_disable_conn_down_timer_cback; |
| 3645 | /* start a timer to make sure that the profiles get the disconnect event */ |
| 3646 | bta_sys_start_timer(&bta_dm_cb.disable_timer, 0, 1000); |
| 3647 | } |
| 3648 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3649 | if (conn.link_down.is_removed) |
| 3650 | { |
| 3651 | BTM_SecDeleteDevice(p_bda); |
| 3652 | #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) |
| 3653 | /* need to remove all pending background connection */ |
| 3654 | BTA_GATTC_CancelOpen(0, p_bda, FALSE); |
| 3655 | /* remove all cached GATT information */ |
| 3656 | BTA_GATTC_Refresh(p_bda); |
| 3657 | #endif |
| 3658 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3659 | |
| 3660 | bdcpy(conn.link_down.bd_addr, p_bda); |
| 3661 | conn.link_down.status = (UINT8) btm_get_acl_disc_reason_code(); |
| 3662 | if( bta_dm_cb.p_sec_cback ) |
| 3663 | { |
| 3664 | bta_dm_cb.p_sec_cback(BTA_DM_LINK_DOWN_EVT, &conn); |
| 3665 | if( issue_unpair_cb ) |
| 3666 | bta_dm_cb.p_sec_cback(BTA_DM_DEV_UNPAIRED_EVT, &conn); |
| 3667 | } |
| 3668 | } |
| 3669 | |
| 3670 | bta_dm_adjust_roles(TRUE); |
| 3671 | } |
| 3672 | |
| 3673 | /******************************************************************************* |
| 3674 | ** |
| 3675 | ** Function bta_dm_disable_conn_down_timer_cback |
| 3676 | ** |
| 3677 | ** Description Sends disable event to application |
| 3678 | ** |
| 3679 | ** |
| 3680 | ** Returns void |
| 3681 | ** |
| 3682 | *******************************************************************************/ |
| 3683 | static void bta_dm_disable_conn_down_timer_cback (TIMER_LIST_ENT *p_tle) |
| 3684 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 3685 | UNUSED(p_tle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3686 | tBTA_SYS_HW_MSG *sys_enable_event; |
| 3687 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3688 | /* disable the power managment module */ |
| 3689 | bta_dm_disable_pm(); |
| 3690 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3691 | /* register our callback to SYS HW manager */ |
| 3692 | bta_sys_hw_register( BTA_SYS_HW_BLUETOOTH, bta_dm_sys_hw_cback ); |
| 3693 | |
| 3694 | /* send a message to BTA SYS */ |
| 3695 | if ((sys_enable_event = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL) |
| 3696 | { |
| 3697 | sys_enable_event->hdr.event = BTA_SYS_API_DISABLE_EVT; |
| 3698 | sys_enable_event->hw_module = BTA_SYS_HW_BLUETOOTH; |
| 3699 | bta_sys_sendmsg(sys_enable_event); |
| 3700 | } |
| 3701 | |
| 3702 | bta_dm_cb.disabling = FALSE; |
| 3703 | |
| 3704 | } |
| 3705 | |
| 3706 | /******************************************************************************* |
| 3707 | ** |
| 3708 | ** Function bta_dm_rssi_cback |
| 3709 | ** |
| 3710 | ** Description Callback from btm with rssi values |
| 3711 | ** |
| 3712 | ** |
| 3713 | ** Returns void |
| 3714 | ** |
| 3715 | *******************************************************************************/ |
| 3716 | static void bta_dm_rssi_cback (tBTM_RSSI_RESULTS *p_result) |
| 3717 | { |
| 3718 | tBTA_DM_SEC sec_event; |
| 3719 | |
| 3720 | if(p_result->status == BTM_SUCCESS) |
| 3721 | { |
| 3722 | |
| 3723 | bdcpy(sec_event.sig_strength.bd_addr, p_result->rem_bda); |
| 3724 | sec_event.sig_strength.mask = BTA_SIG_STRENGTH_RSSI_MASK; |
| 3725 | sec_event.sig_strength.rssi_value = p_result->rssi; |
| 3726 | if( bta_dm_cb.p_sec_cback!= NULL ) |
| 3727 | bta_dm_cb.p_sec_cback(BTA_DM_SIG_STRENGTH_EVT, &sec_event); |
| 3728 | |
| 3729 | } |
| 3730 | } |
| 3731 | |
| 3732 | /******************************************************************************* |
| 3733 | ** |
| 3734 | ** Function bta_dm_link_quality_cback |
| 3735 | ** |
| 3736 | ** Description Callback from btm with link quality value |
| 3737 | ** |
| 3738 | ** |
| 3739 | ** Returns void |
| 3740 | ** |
| 3741 | *******************************************************************************/ |
| 3742 | static void bta_dm_link_quality_cback (tBTM_LINK_QUALITY_RESULTS *p_result) |
| 3743 | { |
| 3744 | |
| 3745 | tBTA_DM_SEC sec_event; |
| 3746 | |
| 3747 | if(p_result->status == BTM_SUCCESS) |
| 3748 | { |
| 3749 | |
| 3750 | bdcpy(sec_event.sig_strength.bd_addr, p_result->rem_bda); |
| 3751 | sec_event.sig_strength.mask = BTA_SIG_STRENGTH_LINK_QUALITY_MASK; |
| 3752 | sec_event.sig_strength.link_quality_value = p_result->link_quality; |
| 3753 | if( bta_dm_cb.p_sec_cback!= NULL ) |
| 3754 | bta_dm_cb.p_sec_cback(BTA_DM_SIG_STRENGTH_EVT, &sec_event); |
| 3755 | |
| 3756 | } |
| 3757 | } |
| 3758 | |
| 3759 | /******************************************************************************* |
| 3760 | ** |
| 3761 | ** Function bta_dm_rm_cback |
| 3762 | ** |
| 3763 | ** Description Role management callback from sys |
| 3764 | ** |
| 3765 | ** |
| 3766 | ** Returns void |
| 3767 | ** |
| 3768 | *******************************************************************************/ |
| 3769 | static void bta_dm_rm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr) |
| 3770 | { |
| 3771 | |
| 3772 | UINT8 j; |
| 3773 | tBTA_PREF_ROLES role; |
| 3774 | tBTA_DM_PEER_DEVICE *p_dev; |
| 3775 | |
| 3776 | p_dev = bta_dm_find_peer_device(peer_addr); |
| 3777 | if( status == BTA_SYS_CONN_OPEN) |
| 3778 | { |
| 3779 | if(p_dev) |
| 3780 | { |
| 3781 | /* Do not set to connected if we are in the middle of unpairing. When AV stream is |
| 3782 | * started it fakes out a SYS_CONN_OPEN to potentially trigger a role switch command. |
| 3783 | * But this should not be done if we are in the middle of unpairing. |
| 3784 | */ |
| 3785 | if (p_dev->conn_state != BTA_DM_UNPAIRING) |
| 3786 | p_dev->conn_state = BTA_DM_CONNECTED; |
| 3787 | |
| 3788 | for(j=1; j<= p_bta_dm_rm_cfg[0].app_id; j++) |
| 3789 | { |
| 3790 | if(((p_bta_dm_rm_cfg[j].app_id == app_id) || (p_bta_dm_rm_cfg[j].app_id == BTA_ALL_APP_ID)) |
| 3791 | && (p_bta_dm_rm_cfg[j].id == id)) |
| 3792 | { |
| 3793 | role = p_bta_dm_rm_cfg[j].cfg; |
| 3794 | |
| 3795 | if(role > p_dev->pref_role ) |
| 3796 | p_dev->pref_role = role; |
| 3797 | break; |
| 3798 | } |
| 3799 | } |
| 3800 | |
| 3801 | } |
| 3802 | |
| 3803 | } |
| 3804 | |
| 3805 | if((BTA_ID_AV == id)||(BTA_ID_AVK ==id)) |
| 3806 | { |
| 3807 | if( status == BTA_SYS_CONN_BUSY) |
| 3808 | { |
| 3809 | if(p_dev) |
| 3810 | p_dev->info |= BTA_DM_DI_AV_ACTIVE; |
| 3811 | /* AV calls bta_sys_conn_open with the A2DP stream count as app_id */ |
| 3812 | if(BTA_ID_AV == id) |
| 3813 | bta_dm_cb.cur_av_count = app_id; |
| 3814 | } |
| 3815 | else if( status == BTA_SYS_CONN_IDLE) |
| 3816 | { |
| 3817 | if(p_dev) |
| 3818 | p_dev->info &= ~BTA_DM_DI_AV_ACTIVE; |
| 3819 | /* AV calls bta_sys_conn_open with the A2DP stream count as app_id */ |
| 3820 | if(BTA_ID_AV == id) |
| 3821 | bta_dm_cb.cur_av_count = app_id; |
| 3822 | } |
| 3823 | APPL_TRACE_WARNING2("bta_dm_rm_cback:%d, status:%d", bta_dm_cb.cur_av_count, status); |
| 3824 | } |
Ganesh Ganapathi Batta | ed049d7 | 2013-04-12 11:57:50 -0700 | [diff] [blame] | 3825 | else if ((status == BTA_SYS_CONN_BUSY) || (status == BTA_SYS_CONN_IDLE)) |
| 3826 | { |
| 3827 | /* Do not do role switch management for non-AV profiles when data flow starts/stops */ |
| 3828 | return; |
| 3829 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3830 | |
| 3831 | bta_dm_adjust_roles(FALSE); |
| 3832 | |
| 3833 | } |
| 3834 | |
| 3835 | /******************************************************************************* |
| 3836 | ** |
| 3837 | ** Function bta_dm_dev_blacklisted_for_switch |
| 3838 | ** |
| 3839 | ** Description Checks if the device is blacklisted for immediate role switch after connection. |
| 3840 | ** |
| 3841 | ** Returns TRUE if dev is blacklisted else FALSE |
| 3842 | ** |
| 3843 | *******************************************************************************/ |
| 3844 | static BOOLEAN bta_dm_dev_blacklisted_for_switch (BD_ADDR remote_bd_addr) |
| 3845 | { |
| 3846 | UINT16 manufacturer = 0; |
| 3847 | UINT16 lmp_sub_version = 0; |
| 3848 | UINT8 lmp_version = 0; |
| 3849 | UINT8 i = 0; |
| 3850 | |
| 3851 | if (BTM_ReadRemoteVersion(remote_bd_addr, &lmp_version, |
| 3852 | &manufacturer, &lmp_sub_version) == BTM_SUCCESS) |
| 3853 | { |
| 3854 | /* Check if this device version info matches with is |
| 3855 | blacklisted versions for role switch */ |
| 3856 | for (i = 0; i < BTA_DM_MAX_ROLE_SWITCH_BLACKLIST_COUNT; i++) |
| 3857 | { |
| 3858 | if ((bta_role_switch_blacklist[i].lmp_version == lmp_version) && |
| 3859 | (bta_role_switch_blacklist[i].manufacturer == manufacturer)&& |
| 3860 | ((bta_role_switch_blacklist[i].lmp_sub_version & lmp_sub_version) == |
| 3861 | bta_role_switch_blacklist[i].lmp_sub_version)) |
| 3862 | { |
| 3863 | APPL_TRACE_EVENT0("Black list F/W version matches.. Delay Role Switch..."); |
| 3864 | return TRUE; |
| 3865 | } |
| 3866 | |
| 3867 | } |
| 3868 | } |
| 3869 | return FALSE; |
| 3870 | } |
| 3871 | |
| 3872 | /******************************************************************************* |
| 3873 | ** |
| 3874 | ** Function bta_dm_delay_role_switch_cback |
| 3875 | ** |
| 3876 | ** Description Callback from btm to delay a role switch |
| 3877 | ** |
| 3878 | ** Returns void |
| 3879 | ** |
| 3880 | *******************************************************************************/ |
| 3881 | static void bta_dm_delay_role_switch_cback(TIMER_LIST_ENT *p_tle) |
| 3882 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 3883 | UNUSED(p_tle); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3884 | APPL_TRACE_EVENT0("bta_dm_delay_role_switch_cback: initiating Delayed RS"); |
| 3885 | bta_dm_adjust_roles (FALSE); |
| 3886 | } |
| 3887 | |
| 3888 | /******************************************************************************* |
| 3889 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3890 | ** Function bta_dm_remove_sec_dev_entry |
| 3891 | ** |
| 3892 | ** Description Removes device entry from Security device DB if ACL connection with |
| 3893 | ** remtoe device does not exist, else schedule for dev entry removal upon |
| 3894 | ACL close |
| 3895 | ** |
| 3896 | ** Returns void |
| 3897 | ** |
| 3898 | *******************************************************************************/ |
| 3899 | static void bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr) |
| 3900 | { |
| 3901 | UINT16 index = 0; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3902 | if ( BTM_IsAclConnectionUp(remote_bd_addr, BT_TRANSPORT_LE) || |
| 3903 | BTM_IsAclConnectionUp(remote_bd_addr, BT_TRANSPORT_BR_EDR)) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3904 | { |
| 3905 | APPL_TRACE_DEBUG1("%s ACL is not down. Schedule for Dev Removal when ACL closes", |
| 3906 | __FUNCTION__); |
| 3907 | for (index = 0; index < bta_dm_cb.device_list.count; index ++) |
| 3908 | { |
| 3909 | if (!bdcmp( bta_dm_cb.device_list.peer_device[index].peer_bdaddr, remote_bd_addr)) |
| 3910 | break; |
| 3911 | } |
| 3912 | if (index != bta_dm_cb.device_list.count) |
| 3913 | { |
| 3914 | bta_dm_cb.device_list.peer_device[index].remove_dev_pending = TRUE; |
| 3915 | } |
| 3916 | else |
| 3917 | { |
| 3918 | APPL_TRACE_ERROR1(" %s Device does not exist in DB", __FUNCTION__); |
| 3919 | } |
| 3920 | } |
| 3921 | else |
| 3922 | { |
| 3923 | BTM_SecDeleteDevice (remote_bd_addr); |
Zhihai Xu | bd68d68 | 2013-11-15 17:55:46 -0800 | [diff] [blame] | 3924 | #if (BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE) |
| 3925 | /* need to remove all pending background connection */ |
| 3926 | BTA_GATTC_CancelOpen(0, remote_bd_addr, FALSE); |
| 3927 | /* remove all cached GATT information */ |
| 3928 | BTA_GATTC_Refresh(remote_bd_addr); |
| 3929 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3930 | } |
| 3931 | } |
| 3932 | |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 3933 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3934 | /******************************************************************************* |
| 3935 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3936 | ** Function bta_dm_adjust_roles |
| 3937 | ** |
| 3938 | ** Description Adjust roles |
| 3939 | ** |
| 3940 | ** |
| 3941 | ** Returns void |
| 3942 | ** |
| 3943 | *******************************************************************************/ |
| 3944 | static void bta_dm_adjust_roles(BOOLEAN delay_role_switch) |
| 3945 | { |
| 3946 | |
| 3947 | UINT8 i; |
| 3948 | BOOLEAN set_master_role = FALSE; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3949 | #if BLE_INCLUDED == TRUE |
| 3950 | UINT8 br_count = bta_dm_cb.device_list.count - bta_dm_cb.device_list.le_count; |
| 3951 | #else |
| 3952 | UINT8 br_count = bta_dm_cb.device_list.count; |
| 3953 | #endif |
| 3954 | if (br_count) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3955 | { |
| 3956 | |
| 3957 | /* the configuration is no scatternet |
| 3958 | * or AV connection exists and there are more than one ACL link */ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3959 | if ( (p_bta_dm_rm_cfg[0].cfg == BTA_DM_NO_SCATTERNET) || |
| 3960 | (bta_dm_cb.cur_av_count && br_count > 1) ) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3961 | { |
| 3962 | |
| 3963 | L2CA_SetDesireRole (HCI_ROLE_MASTER); |
| 3964 | set_master_role = TRUE; |
| 3965 | |
| 3966 | } |
| 3967 | |
| 3968 | for(i=0; i<bta_dm_cb.device_list.count; i++) |
| 3969 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3970 | if (bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_CONNECTED |
| 3971 | #if BLE_INCLUDED == TRUE |
| 3972 | && bta_dm_cb.device_list.peer_device[i].transport == BT_TRANSPORT_BR_EDR |
| 3973 | #endif |
| 3974 | ) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3975 | { |
| 3976 | if(!set_master_role && (bta_dm_cb.device_list.peer_device[i].pref_role != BTA_ANY_ROLE) |
| 3977 | && (p_bta_dm_rm_cfg[0].cfg == BTA_DM_PARTIAL_SCATTERNET)) |
| 3978 | { |
| 3979 | L2CA_SetDesireRole (HCI_ROLE_MASTER); |
| 3980 | set_master_role = TRUE; |
| 3981 | } |
| 3982 | |
| 3983 | if((bta_dm_cb.device_list.peer_device[i].pref_role == BTA_MASTER_ROLE_ONLY) |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 3984 | || (br_count > 1)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3985 | { |
| 3986 | |
| 3987 | /* Initiating immediate role switch with certain remote devices |
| 3988 | has caused issues due to role switch colliding with link encryption setup and |
| 3989 | causing encryption (and in turn the link) to fail . These device . Firmware |
| 3990 | versions are stored in a blacklist and role switch with these devices are |
| 3991 | delayed to avoid the collision with link encryption setup */ |
| 3992 | |
| 3993 | if ((delay_role_switch == FALSE) || |
| 3994 | (bta_dm_dev_blacklisted_for_switch( |
| 3995 | bta_dm_cb.device_list.peer_device[i].peer_bdaddr) == FALSE)) |
| 3996 | { |
| 3997 | BTM_SwitchRole (bta_dm_cb.device_list.peer_device[i].peer_bdaddr, |
| 3998 | HCI_ROLE_MASTER, NULL); |
| 3999 | } |
| 4000 | else |
| 4001 | { |
| 4002 | bta_dm_cb.switch_delay_timer.p_cback = |
| 4003 | (TIMER_CBACK*)&bta_dm_delay_role_switch_cback; |
| 4004 | bta_sys_start_timer(&bta_dm_cb.switch_delay_timer, 0, 500); |
| 4005 | } |
| 4006 | } |
| 4007 | |
| 4008 | } |
| 4009 | } |
| 4010 | |
| 4011 | |
| 4012 | if(!set_master_role) |
| 4013 | { |
| 4014 | |
| 4015 | L2CA_SetDesireRole (L2CAP_DESIRED_LINK_ROLE); |
| 4016 | |
| 4017 | } |
| 4018 | |
| 4019 | } |
| 4020 | else |
| 4021 | { |
| 4022 | L2CA_SetDesireRole (L2CAP_DESIRED_LINK_ROLE); |
| 4023 | } |
| 4024 | |
| 4025 | |
| 4026 | } |
| 4027 | |
| 4028 | /******************************************************************************* |
| 4029 | ** |
| 4030 | ** Function bta_dm_get_remname |
| 4031 | ** |
| 4032 | ** Description Returns a pointer to the remote name stored in the DM control |
| 4033 | ** block if it exists, or from the BTM memory. |
| 4034 | ** |
| 4035 | ** Returns char * - Pointer to the remote device name |
| 4036 | *******************************************************************************/ |
| 4037 | static char *bta_dm_get_remname(void) |
| 4038 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 4039 | char *p_name = (char *)bta_dm_search_cb.peer_name; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4040 | char *p_temp; |
| 4041 | |
| 4042 | /* If the name isn't already stored, try retrieving from BTM */ |
| 4043 | if (*p_name == '\0') |
| 4044 | if ((p_temp = BTM_SecReadDevName(bta_dm_search_cb.peer_bdaddr)) != NULL) |
| 4045 | p_name = p_temp; |
| 4046 | |
| 4047 | return p_name; |
| 4048 | } |
| 4049 | |
| 4050 | /******************************************************************************* |
| 4051 | ** |
| 4052 | ** Function bta_dm_bond_cancel_complete_cback |
| 4053 | ** |
| 4054 | ** Description Authentication complete callback from BTM |
| 4055 | ** |
| 4056 | ** Returns void |
| 4057 | ** |
| 4058 | *******************************************************************************/ |
| 4059 | static void bta_dm_bond_cancel_complete_cback(tBTM_STATUS result) |
| 4060 | { |
| 4061 | |
| 4062 | tBTA_DM_SEC sec_event; |
| 4063 | |
| 4064 | if (result == BTM_SUCCESS) |
| 4065 | sec_event.bond_cancel_cmpl.result = BTA_SUCCESS; |
| 4066 | else |
| 4067 | sec_event.bond_cancel_cmpl.result = BTA_FAILURE; |
| 4068 | |
| 4069 | if(bta_dm_cb.p_sec_cback) |
| 4070 | { |
| 4071 | bta_dm_cb.p_sec_cback(BTA_DM_BOND_CANCEL_CMPL_EVT, &sec_event); |
| 4072 | } |
| 4073 | } |
| 4074 | |
| 4075 | #if ( BTM_EIR_SERVER_INCLUDED == TRUE ) |
| 4076 | #if ( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) |
| 4077 | /******************************************************************************* |
| 4078 | ** |
| 4079 | ** Function bta_dm_update_eir_uuid |
| 4080 | ** |
| 4081 | ** Description |
| 4082 | ** |
| 4083 | ** |
| 4084 | *******************************************************************************/ |
| 4085 | void bta_dm_update_eir_uuid (tBTA_DM_MSG *p_data) |
| 4086 | { |
| 4087 | tBTA_DM_API_UPDATE_EIR_UUID *p_msg = (tBTA_DM_API_UPDATE_EIR_UUID *)p_data; |
| 4088 | UINT8 xx; |
| 4089 | UINT8 empty_slot = BTA_EIR_SERVER_NUM_CUSTOM_UUID; |
| 4090 | UINT8 match_slot = BTA_EIR_SERVER_NUM_CUSTOM_UUID; |
| 4091 | |
| 4092 | for (xx = 0; xx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; xx++) |
| 4093 | { |
| 4094 | if (bta_dm_cb.custom_uuid[xx].len == 0) |
| 4095 | { |
| 4096 | if (empty_slot == BTA_EIR_SERVER_NUM_CUSTOM_UUID) |
| 4097 | empty_slot = xx; |
| 4098 | } |
| 4099 | else if (match_slot == BTA_EIR_SERVER_NUM_CUSTOM_UUID) |
| 4100 | { |
| 4101 | if (!memcmp (bta_dm_cb.custom_uuid[xx].uu.uuid128, p_msg->uuid.uu.uuid128, p_msg->uuid.len)) |
| 4102 | { |
| 4103 | match_slot = xx;; |
| 4104 | } |
| 4105 | } |
| 4106 | } |
| 4107 | |
| 4108 | if (p_msg->is_add) |
| 4109 | { |
| 4110 | if (match_slot == BTA_EIR_SERVER_NUM_CUSTOM_UUID) |
| 4111 | { |
| 4112 | if (empty_slot == BTA_EIR_SERVER_NUM_CUSTOM_UUID) |
| 4113 | { |
| 4114 | APPL_TRACE_ERROR0("No space to add UUID for EIR"); |
| 4115 | return; |
| 4116 | } |
| 4117 | else |
| 4118 | { |
| 4119 | memcpy (&(bta_dm_cb.custom_uuid[empty_slot]), &(p_msg->uuid), sizeof(tBT_UUID)); |
| 4120 | } |
| 4121 | } |
| 4122 | else |
| 4123 | { |
| 4124 | APPL_TRACE_ERROR0("UUID is already added for EIR"); |
| 4125 | return; |
| 4126 | } |
| 4127 | } |
| 4128 | else |
| 4129 | { |
| 4130 | if (match_slot == BTA_EIR_SERVER_NUM_CUSTOM_UUID) |
| 4131 | { |
| 4132 | APPL_TRACE_ERROR0("UUID is not found for EIR"); |
| 4133 | return; |
| 4134 | } |
| 4135 | else |
| 4136 | { |
| 4137 | memset (&(bta_dm_cb.custom_uuid[match_slot]), 0, sizeof(tBT_UUID)); |
| 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | bta_dm_set_eir (NULL); |
| 4142 | } |
| 4143 | #endif |
| 4144 | |
| 4145 | /******************************************************************************* |
| 4146 | ** |
| 4147 | ** Function bta_dm_set_eir_config |
| 4148 | ** |
| 4149 | ** Description |
| 4150 | ** |
| 4151 | ** |
| 4152 | *******************************************************************************/ |
| 4153 | void bta_dm_set_eir_config (tBTA_DM_MSG *p_data) |
| 4154 | { |
| 4155 | if (p_data->set_eir_cfg.p_eir_cfg) |
| 4156 | { |
| 4157 | /* User defined config */ |
| 4158 | p_bta_dm_eir_cfg = p_data->set_eir_cfg.p_eir_cfg; |
| 4159 | } |
| 4160 | else |
| 4161 | { |
| 4162 | /* Back to default config */ |
| 4163 | p_bta_dm_eir_cfg = (tBTA_DM_EIR_CONF*)&bta_dm_eir_cfg; |
| 4164 | } |
| 4165 | |
| 4166 | bta_dm_set_eir (NULL); |
| 4167 | } |
| 4168 | |
| 4169 | /******************************************************************************* |
| 4170 | ** |
| 4171 | ** Function bta_dm_set_eir |
| 4172 | ** |
| 4173 | ** Description This function creates EIR tagged data and writes it to controller. |
| 4174 | ** |
| 4175 | ** Returns None |
| 4176 | ** |
| 4177 | *******************************************************************************/ |
| 4178 | static void bta_dm_set_eir (char *local_name) |
| 4179 | { |
| 4180 | BT_HDR *p_buf; |
| 4181 | UINT8 *p; |
| 4182 | UINT8 *p_length; |
| 4183 | #if (BTA_EIR_CANNED_UUID_LIST != TRUE) |
| 4184 | UINT8 *p_type; |
| 4185 | UINT8 max_num_uuid; |
| 4186 | #if (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) |
| 4187 | UINT8 custom_uuid_idx; |
| 4188 | #endif |
| 4189 | #endif |
| 4190 | #if (BTM_EIR_DEFAULT_FEC_REQUIRED == FALSE) |
| 4191 | UINT8 free_eir_length = HCI_EXT_INQ_RESPONSE_LEN; |
| 4192 | #else |
| 4193 | UINT8 free_eir_length = HCI_DM5_PACKET_SIZE; |
| 4194 | #endif |
| 4195 | UINT8 num_uuid; |
| 4196 | UINT8 data_type; |
| 4197 | UINT8 local_name_len; |
| 4198 | |
| 4199 | /* wait until complete to disable */ |
| 4200 | if (bta_dm_cb.disable_timer.in_use) |
| 4201 | return; |
| 4202 | |
| 4203 | #if ( BTA_EIR_CANNED_UUID_LIST != TRUE ) |
| 4204 | /* wait until App is ready */ |
| 4205 | if (bta_dm_cb.app_ready_timer.in_use) |
| 4206 | return; |
| 4207 | |
| 4208 | /* if local name is not provided, get it from controller */ |
| 4209 | if( local_name == NULL ) |
| 4210 | { |
| 4211 | if( BTM_ReadLocalDeviceName( &local_name ) != BTM_SUCCESS ) |
| 4212 | { |
| 4213 | APPL_TRACE_ERROR0("Fail to read local device name for EIR"); |
| 4214 | } |
| 4215 | } |
| 4216 | #endif |
| 4217 | |
| 4218 | /* Allocate a buffer to hold HCI command */ |
| 4219 | if ((p_buf = (BT_HDR *)GKI_getpoolbuf(BTM_CMD_POOL_ID)) == NULL) |
| 4220 | { |
| 4221 | APPL_TRACE_ERROR0("bta_dm_set_eir couldn't allocate buffer"); |
| 4222 | return; |
| 4223 | } |
| 4224 | p = (UINT8 *)p_buf + BTM_HCI_EIR_OFFSET; |
| 4225 | |
| 4226 | memset(p, 0x00, HCI_EXT_INQ_RESPONSE_LEN ); |
| 4227 | |
| 4228 | APPL_TRACE_DEBUG0("BTA is generating EIR"); |
| 4229 | |
| 4230 | if( local_name ) |
| 4231 | local_name_len = strlen( local_name ); |
| 4232 | else |
| 4233 | local_name_len = 0; |
| 4234 | |
| 4235 | data_type = BTM_EIR_COMPLETE_LOCAL_NAME_TYPE; |
| 4236 | /* if local name is longer than minimum length of shortened name */ |
| 4237 | /* check whether it needs to be shortened or not */ |
| 4238 | if( local_name_len > p_bta_dm_eir_cfg->bta_dm_eir_min_name_len ) |
| 4239 | { |
| 4240 | /* get number of UUID 16-bit list */ |
| 4241 | #if (BTA_EIR_CANNED_UUID_LIST == TRUE) |
| 4242 | num_uuid = p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len/LEN_UUID_16; |
| 4243 | #else |
| 4244 | max_num_uuid = (free_eir_length - 2)/LEN_UUID_16; |
| 4245 | data_type = BTM_GetEirSupportedServices( bta_dm_cb.eir_uuid, &p, |
| 4246 | max_num_uuid, &num_uuid ); |
| 4247 | p = (UINT8 *)p_buf + BTM_HCI_EIR_OFFSET; /* reset p */ |
| 4248 | #endif |
| 4249 | |
| 4250 | /* if UUID doesn't fit remaing space, shorten local name */ |
| 4251 | if ( local_name_len > (free_eir_length - 4 - num_uuid*LEN_UUID_16)) |
| 4252 | { |
| 4253 | APPL_TRACE_WARNING0("BTA EIR: local name is shortened"); |
| 4254 | local_name_len = p_bta_dm_eir_cfg->bta_dm_eir_min_name_len; |
| 4255 | data_type = BTM_EIR_SHORTENED_LOCAL_NAME_TYPE; |
| 4256 | } |
| 4257 | else |
| 4258 | data_type = BTM_EIR_COMPLETE_LOCAL_NAME_TYPE; |
| 4259 | } |
| 4260 | |
| 4261 | UINT8_TO_STREAM(p, local_name_len + 1); |
| 4262 | UINT8_TO_STREAM(p, data_type); |
Andre Eisenbach | 3aa6054 | 2013-03-22 18:00:51 -0700 | [diff] [blame] | 4263 | |
| 4264 | if (local_name != NULL) |
| 4265 | { |
| 4266 | memcpy(p, local_name, local_name_len); |
| 4267 | p += local_name_len; |
| 4268 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4269 | free_eir_length -= local_name_len + 2; |
| 4270 | |
| 4271 | #if (BTA_EIR_CANNED_UUID_LIST == TRUE) |
| 4272 | /* if UUID list is provided as static data in configuration */ |
| 4273 | if(( p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len > 0 ) |
| 4274 | &&(p_bta_dm_eir_cfg->bta_dm_eir_uuid16)) |
| 4275 | { |
| 4276 | if( free_eir_length > LEN_UUID_16 + 2) |
| 4277 | { |
| 4278 | free_eir_length -= 2; |
| 4279 | |
| 4280 | if( free_eir_length >= p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len) |
| 4281 | { |
| 4282 | num_uuid = p_bta_dm_eir_cfg->bta_dm_eir_uuid16_len / LEN_UUID_16; |
| 4283 | data_type = BTM_EIR_COMPLETE_16BITS_UUID_TYPE; |
| 4284 | } |
| 4285 | else /* not enough room for all UUIDs */ |
| 4286 | { |
| 4287 | APPL_TRACE_WARNING0("BTA EIR: UUID 16-bit list is truncated"); |
| 4288 | num_uuid = free_eir_length / LEN_UUID_16; |
| 4289 | data_type = BTM_EIR_MORE_16BITS_UUID_TYPE; |
| 4290 | } |
| 4291 | UINT8_TO_STREAM(p, num_uuid * LEN_UUID_16 + 1); |
| 4292 | UINT8_TO_STREAM(p, data_type); |
| 4293 | memcpy(p, p_bta_dm_eir_cfg->bta_dm_eir_uuid16, num_uuid * LEN_UUID_16 ); |
| 4294 | p += num_uuid * LEN_UUID_16; |
| 4295 | free_eir_length -= num_uuid * LEN_UUID_16; |
| 4296 | } |
| 4297 | } |
| 4298 | #else /* (BTA_EIR_CANNED_UUID_LIST == TRUE) */ |
| 4299 | /* if UUID list is dynamic */ |
| 4300 | if ( free_eir_length >= 2) |
| 4301 | { |
| 4302 | p_length = p++; |
| 4303 | p_type = p++; |
| 4304 | num_uuid = 0; |
| 4305 | |
| 4306 | max_num_uuid = (free_eir_length - 2)/LEN_UUID_16; |
| 4307 | data_type = BTM_GetEirSupportedServices( bta_dm_cb.eir_uuid, &p, max_num_uuid, &num_uuid ); |
| 4308 | |
| 4309 | if( data_type == BTM_EIR_MORE_16BITS_UUID_TYPE ) |
| 4310 | { |
| 4311 | APPL_TRACE_WARNING0("BTA EIR: UUID 16-bit list is truncated"); |
| 4312 | } |
| 4313 | #if (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) |
| 4314 | else |
| 4315 | { |
| 4316 | for (custom_uuid_idx = 0; custom_uuid_idx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; custom_uuid_idx++) |
| 4317 | { |
| 4318 | if (bta_dm_cb.custom_uuid[custom_uuid_idx].len == LEN_UUID_16) |
| 4319 | { |
| 4320 | if ( num_uuid < max_num_uuid ) |
| 4321 | { |
| 4322 | UINT16_TO_STREAM(p, bta_dm_cb.custom_uuid[custom_uuid_idx].uu.uuid16); |
| 4323 | num_uuid++; |
| 4324 | } |
| 4325 | else |
| 4326 | { |
| 4327 | data_type = BTM_EIR_MORE_16BITS_UUID_TYPE; |
| 4328 | APPL_TRACE_WARNING0("BTA EIR: UUID 16-bit list is truncated"); |
| 4329 | break; |
| 4330 | } |
| 4331 | } |
| 4332 | } |
| 4333 | } |
| 4334 | #endif /* (BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) */ |
| 4335 | |
| 4336 | UINT8_TO_STREAM(p_length, num_uuid * LEN_UUID_16 + 1); |
| 4337 | UINT8_TO_STREAM(p_type, data_type); |
| 4338 | free_eir_length -= num_uuid * LEN_UUID_16 + 2; |
| 4339 | } |
| 4340 | #endif /* (BTA_EIR_CANNED_UUID_LIST == TRUE) */ |
| 4341 | |
| 4342 | #if ( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) |
| 4343 | /* Adding 32-bit UUID list */ |
| 4344 | if ( free_eir_length >= 2) |
| 4345 | { |
| 4346 | p_length = p++; |
| 4347 | p_type = p++; |
| 4348 | num_uuid = 0; |
| 4349 | data_type = BTM_EIR_COMPLETE_32BITS_UUID_TYPE; |
| 4350 | |
| 4351 | max_num_uuid = (free_eir_length - 2)/LEN_UUID_32; |
| 4352 | |
| 4353 | for (custom_uuid_idx = 0; custom_uuid_idx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; custom_uuid_idx++) |
| 4354 | { |
| 4355 | if (bta_dm_cb.custom_uuid[custom_uuid_idx].len == LEN_UUID_32) |
| 4356 | { |
| 4357 | if ( num_uuid < max_num_uuid ) |
| 4358 | { |
| 4359 | UINT32_TO_STREAM(p, bta_dm_cb.custom_uuid[custom_uuid_idx].uu.uuid32); |
| 4360 | num_uuid++; |
| 4361 | } |
| 4362 | else |
| 4363 | { |
| 4364 | data_type = BTM_EIR_MORE_32BITS_UUID_TYPE; |
| 4365 | APPL_TRACE_WARNING0("BTA EIR: UUID 32-bit list is truncated"); |
| 4366 | break; |
| 4367 | } |
| 4368 | } |
| 4369 | } |
| 4370 | |
| 4371 | UINT8_TO_STREAM(p_length, num_uuid * LEN_UUID_32 + 1); |
| 4372 | UINT8_TO_STREAM(p_type, data_type); |
| 4373 | free_eir_length -= num_uuid * LEN_UUID_32 + 2; |
| 4374 | } |
| 4375 | |
| 4376 | /* Adding 128-bit UUID list */ |
| 4377 | if ( free_eir_length >= 2) |
| 4378 | { |
| 4379 | p_length = p++; |
| 4380 | p_type = p++; |
| 4381 | num_uuid = 0; |
| 4382 | data_type = BTM_EIR_COMPLETE_128BITS_UUID_TYPE; |
| 4383 | |
| 4384 | max_num_uuid = (free_eir_length - 2)/LEN_UUID_128; |
| 4385 | |
| 4386 | for (custom_uuid_idx = 0; custom_uuid_idx < BTA_EIR_SERVER_NUM_CUSTOM_UUID; custom_uuid_idx++) |
| 4387 | { |
| 4388 | if (bta_dm_cb.custom_uuid[custom_uuid_idx].len == LEN_UUID_128) |
| 4389 | { |
| 4390 | if ( num_uuid < max_num_uuid ) |
| 4391 | { |
| 4392 | ARRAY16_TO_STREAM(p, bta_dm_cb.custom_uuid[custom_uuid_idx].uu.uuid128); |
| 4393 | num_uuid++; |
| 4394 | } |
| 4395 | else |
| 4396 | { |
| 4397 | data_type = BTM_EIR_MORE_128BITS_UUID_TYPE; |
| 4398 | APPL_TRACE_WARNING0("BTA EIR: UUID 128-bit list is truncated"); |
| 4399 | break; |
| 4400 | } |
| 4401 | } |
| 4402 | } |
| 4403 | |
| 4404 | UINT8_TO_STREAM(p_length, num_uuid * LEN_UUID_128 + 1); |
| 4405 | UINT8_TO_STREAM(p_type, data_type); |
| 4406 | free_eir_length -= num_uuid * LEN_UUID_128 + 2; |
| 4407 | } |
| 4408 | #endif /* ( BTA_EIR_CANNED_UUID_LIST != TRUE )&&(BTA_EIR_SERVER_NUM_CUSTOM_UUID > 0) */ |
| 4409 | |
| 4410 | /* if Flags are provided in configuration */ |
| 4411 | if(( p_bta_dm_eir_cfg->bta_dm_eir_flag_len > 0 ) |
| 4412 | &&( p_bta_dm_eir_cfg->bta_dm_eir_flags ) |
| 4413 | &&( free_eir_length >= p_bta_dm_eir_cfg->bta_dm_eir_flag_len + 2 )) |
| 4414 | { |
| 4415 | UINT8_TO_STREAM(p, p_bta_dm_eir_cfg->bta_dm_eir_flag_len + 1); |
| 4416 | UINT8_TO_STREAM(p, BTM_EIR_FLAGS_TYPE); |
| 4417 | memcpy(p, p_bta_dm_eir_cfg->bta_dm_eir_flags, |
| 4418 | p_bta_dm_eir_cfg->bta_dm_eir_flag_len); |
| 4419 | p += p_bta_dm_eir_cfg->bta_dm_eir_flag_len; |
| 4420 | free_eir_length -= p_bta_dm_eir_cfg->bta_dm_eir_flag_len + 2; |
| 4421 | } |
| 4422 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4423 | /* if Manufacturer Specific are provided in configuration */ |
| 4424 | if(( p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len > 0 ) |
| 4425 | &&( p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec ) |
| 4426 | &&( free_eir_length >= p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len + 2 )) |
| 4427 | { |
| 4428 | p_length = p; |
| 4429 | |
| 4430 | UINT8_TO_STREAM(p, p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len + 1); |
| 4431 | UINT8_TO_STREAM(p, BTM_EIR_MANUFACTURER_SPECIFIC_TYPE); |
| 4432 | memcpy(p, p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec, |
| 4433 | p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len); |
| 4434 | p += p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len; |
| 4435 | free_eir_length -= p_bta_dm_eir_cfg->bta_dm_eir_manufac_spec_len + 2; |
| 4436 | |
| 4437 | } |
| 4438 | else |
| 4439 | { |
| 4440 | p_length = NULL; |
| 4441 | } |
| 4442 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 4443 | /* if Inquiry Tx Resp Power compiled */ |
| 4444 | if ((p_bta_dm_eir_cfg->bta_dm_eir_inq_tx_power) && |
| 4445 | (free_eir_length >= 3)) |
| 4446 | { |
| 4447 | UINT8_TO_STREAM(p, 2); /* Length field */ |
| 4448 | UINT8_TO_STREAM(p, BTM_EIR_TX_POWER_LEVEL_TYPE); |
| 4449 | UINT8_TO_STREAM(p, *(p_bta_dm_eir_cfg->bta_dm_eir_inq_tx_power)); |
| 4450 | free_eir_length -= 3; |
| 4451 | } |
| 4452 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4453 | if( free_eir_length ) |
| 4454 | UINT8_TO_STREAM(p, 0); /* terminator of significant part */ |
| 4455 | |
| 4456 | BTM_WriteEIR( p_buf ); |
| 4457 | |
| 4458 | } |
| 4459 | #endif |
| 4460 | |
| 4461 | #if ( BTM_EIR_CLIENT_INCLUDED == TRUE ) |
| 4462 | /******************************************************************************* |
| 4463 | ** |
| 4464 | ** Function bta_dm_eir_search_services |
| 4465 | ** |
| 4466 | ** Description This function searches services in received EIR |
| 4467 | ** |
| 4468 | ** Returns None |
| 4469 | ** |
| 4470 | *******************************************************************************/ |
| 4471 | static void bta_dm_eir_search_services( tBTM_INQ_RESULTS *p_result, |
| 4472 | tBTA_SERVICE_MASK *p_services_to_search, |
| 4473 | tBTA_SERVICE_MASK *p_services_found) |
| 4474 | { |
| 4475 | tBTA_SERVICE_MASK service_index = 0; |
| 4476 | tBTM_EIR_SEARCH_RESULT result; |
| 4477 | |
| 4478 | APPL_TRACE_DEBUG6("BTA searching services in EIR of BDA:0x%02X%02X%02X%02X%02X%02X", |
| 4479 | p_result->remote_bd_addr[0],p_result->remote_bd_addr[1], |
| 4480 | p_result->remote_bd_addr[2],p_result->remote_bd_addr[3], |
| 4481 | p_result->remote_bd_addr[4],p_result->remote_bd_addr[5]); |
| 4482 | |
| 4483 | APPL_TRACE_DEBUG1(" with services_to_search=0x%08X", *p_services_to_search); |
| 4484 | |
| 4485 | #if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE |
| 4486 | /* always do GATT based service discovery by SDP instead of from EIR */ |
| 4487 | /* if GATT based service is also to be put in EIR, need to modify this */ |
| 4488 | while (service_index < (BTA_MAX_SERVICE_ID - 1)) |
| 4489 | #else |
| 4490 | while(service_index < BTA_MAX_SERVICE_ID) |
| 4491 | #endif |
| 4492 | { |
| 4493 | if( *p_services_to_search |
| 4494 | & (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(service_index))) |
| 4495 | { |
| 4496 | result = BTM_HasInquiryEirService( p_result, |
| 4497 | bta_service_id_to_uuid_lkup_tbl[service_index] ); |
| 4498 | |
| 4499 | /* Searching for HSP v1.2 only device */ |
| 4500 | if ((result != BTM_EIR_FOUND) && |
| 4501 | (bta_service_id_to_uuid_lkup_tbl[service_index] == UUID_SERVCLASS_HEADSET)) |
| 4502 | { |
| 4503 | result = BTM_HasInquiryEirService (p_result, UUID_SERVCLASS_HEADSET_HS); |
| 4504 | } |
| 4505 | |
| 4506 | if( result == BTM_EIR_FOUND ) |
| 4507 | { |
| 4508 | /* If Plug and Play service record, need to check to see if Broadcom stack */ |
| 4509 | /* However, EIR data doesn't have EXT_BRCM_VERSION so just skip it */ |
| 4510 | if( bta_service_id_to_uuid_lkup_tbl[service_index] |
| 4511 | != UUID_SERVCLASS_PNP_INFORMATION ) |
| 4512 | { |
| 4513 | |
| 4514 | *p_services_found |= |
| 4515 | (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(service_index)); |
| 4516 | /* remove the service from services to be searched */ |
| 4517 | *p_services_to_search &= |
| 4518 | (tBTA_SERVICE_MASK)(~(BTA_SERVICE_ID_TO_SERVICE_MASK(service_index))); |
| 4519 | } |
| 4520 | } |
| 4521 | else if( result == BTM_EIR_NOT_FOUND ) |
| 4522 | { |
| 4523 | /* remove the service from services to be searched */ |
| 4524 | *p_services_to_search &= |
| 4525 | (tBTA_SERVICE_MASK)(~(BTA_SERVICE_ID_TO_SERVICE_MASK(service_index))); |
| 4526 | } |
| 4527 | } |
| 4528 | |
| 4529 | service_index++; |
| 4530 | } |
| 4531 | |
| 4532 | APPL_TRACE_ERROR2("BTA EIR search result, services_to_search=0x%08X, services_found=0x%08X", |
| 4533 | *p_services_to_search, *p_services_found); |
| 4534 | } |
| 4535 | #endif |
| 4536 | |
| 4537 | #if ( BTM_EIR_SERVER_INCLUDED == TRUE )&&(BTA_EIR_CANNED_UUID_LIST != TRUE) |
| 4538 | /******************************************************************************* |
| 4539 | ** |
| 4540 | ** Function bta_dm_eir_update_uuid |
| 4541 | ** |
| 4542 | ** Description This function adds or removes service UUID in EIR database. |
| 4543 | ** |
| 4544 | ** Returns None |
| 4545 | ** |
| 4546 | *******************************************************************************/ |
| 4547 | void bta_dm_eir_update_uuid(UINT16 uuid16, BOOLEAN adding) |
| 4548 | { |
| 4549 | /* if this UUID is not advertised in EIR */ |
| 4550 | if( !BTM_HasEirService( p_bta_dm_eir_cfg->uuid_mask, uuid16 )) |
| 4551 | return; |
| 4552 | |
| 4553 | if( adding ) |
| 4554 | { |
| 4555 | APPL_TRACE_EVENT1("Adding UUID=0x%04X into EIR", uuid16); |
| 4556 | |
| 4557 | BTM_AddEirService( bta_dm_cb.eir_uuid, uuid16 ); |
| 4558 | } |
| 4559 | else |
| 4560 | { |
| 4561 | APPL_TRACE_EVENT1("Removing UUID=0x%04X from EIR", uuid16); |
| 4562 | |
| 4563 | BTM_RemoveEirService( bta_dm_cb.eir_uuid, uuid16 ); |
| 4564 | } |
| 4565 | |
| 4566 | bta_dm_set_eir (NULL); |
| 4567 | |
| 4568 | APPL_TRACE_EVENT2("bta_dm_eir_update_uuid UUID bit mask=0x%08X %08X", |
| 4569 | bta_dm_cb.eir_uuid[1], bta_dm_cb.eir_uuid[0] ); |
| 4570 | } |
| 4571 | #endif |
| 4572 | |
| 4573 | /******************************************************************************* |
| 4574 | ** |
| 4575 | ** Function bta_dm_enable_test_mode |
| 4576 | ** |
| 4577 | ** Description enable test mode |
| 4578 | ** |
| 4579 | ** |
| 4580 | ** Returns void |
| 4581 | ** |
| 4582 | *******************************************************************************/ |
| 4583 | void bta_dm_enable_test_mode(tBTA_DM_MSG *p_data) |
| 4584 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 4585 | UNUSED(p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4586 | BTM_EnableTestMode(); |
| 4587 | } |
| 4588 | |
| 4589 | /******************************************************************************* |
| 4590 | ** |
| 4591 | ** Function bta_dm_disable_test_mode |
| 4592 | ** |
| 4593 | ** Description disable test mode |
| 4594 | ** |
| 4595 | ** |
| 4596 | ** Returns void |
| 4597 | ** |
| 4598 | *******************************************************************************/ |
| 4599 | void bta_dm_disable_test_mode(tBTA_DM_MSG *p_data) |
| 4600 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 4601 | UNUSED(p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4602 | BTM_DeviceReset(NULL); |
| 4603 | } |
| 4604 | |
| 4605 | /******************************************************************************* |
| 4606 | ** |
| 4607 | ** Function bta_dm_execute_callback |
| 4608 | ** |
| 4609 | ** Description Just execute a generic call back in the context of the BTU/BTA tack |
| 4610 | ** |
| 4611 | ** |
| 4612 | ** Returns void |
| 4613 | ** |
| 4614 | *******************************************************************************/ |
| 4615 | void bta_dm_execute_callback(tBTA_DM_MSG *p_data) |
| 4616 | { |
| 4617 | /* sanity check */ |
| 4618 | if(p_data->exec_cback.p_exec_cback == NULL) |
| 4619 | { |
| 4620 | return; |
| 4621 | } |
| 4622 | |
| 4623 | p_data->exec_cback.p_exec_cback(p_data->exec_cback.p_param); |
| 4624 | } |
| 4625 | /******************************************************************************* |
| 4626 | ** |
| 4627 | ** Function bta_dm_encrypt_cback |
| 4628 | ** |
| 4629 | ** Description link encryption complete callback. |
| 4630 | ** |
| 4631 | ** Returns None |
| 4632 | ** |
| 4633 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4634 | void bta_dm_encrypt_cback(BD_ADDR bd_addr, tBT_TRANSPORT transport, void *p_ref_data, tBTM_STATUS result) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4635 | { |
| 4636 | tBTA_STATUS bta_status = BTA_SUCCESS; |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4637 | tBTA_DM_ENCRYPT_CBACK *p_callback = NULL; |
| 4638 | UINT8 i ; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 4639 | UNUSED(p_ref_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4640 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4641 | for (i=0; i<bta_dm_cb.device_list.count; i++) |
| 4642 | { |
| 4643 | if (bdcmp( bta_dm_cb.device_list.peer_device[i].peer_bdaddr, bd_addr) == 0 && |
| 4644 | bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_CONNECTED) |
| 4645 | break; |
| 4646 | } |
| 4647 | |
| 4648 | if (i < bta_dm_cb.device_list.count) |
| 4649 | { |
| 4650 | p_callback = bta_dm_cb.device_list.peer_device[i].p_encrypt_cback; |
| 4651 | bta_dm_cb.device_list.peer_device[i].p_encrypt_cback = NULL; |
| 4652 | } |
| 4653 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4654 | switch (result) |
| 4655 | { |
| 4656 | case BTM_SUCCESS: |
| 4657 | break; |
| 4658 | case BTM_WRONG_MODE: |
| 4659 | bta_status = BTA_WRONG_MODE; |
| 4660 | break; |
| 4661 | case BTM_NO_RESOURCES: |
| 4662 | bta_status = BTA_NO_RESOURCES; |
| 4663 | break; |
| 4664 | case BTM_BUSY: |
| 4665 | bta_status = BTA_BUSY; |
| 4666 | break; |
| 4667 | default: |
| 4668 | bta_status = BTA_FAILURE; |
| 4669 | break; |
| 4670 | } |
| 4671 | |
| 4672 | APPL_TRACE_DEBUG2("bta_dm_encrypt_cback status =%d p_callback=0x%x", bta_status, p_callback); |
| 4673 | |
| 4674 | if (p_callback) |
| 4675 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4676 | (*p_callback)(bd_addr, transport, bta_status); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4677 | } |
| 4678 | } |
| 4679 | /******************************************************************************* |
| 4680 | ** |
| 4681 | ** Function bta_dm_set_encryption |
| 4682 | ** |
| 4683 | ** Description This function to encrypt the link |
| 4684 | ** |
| 4685 | ** Returns None |
| 4686 | ** |
| 4687 | *******************************************************************************/ |
| 4688 | void bta_dm_set_encryption (tBTA_DM_MSG *p_data) |
| 4689 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4690 | UINT8 i ; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4691 | |
| 4692 | APPL_TRACE_DEBUG0("bta_dm_set_encryption"); //todo |
| 4693 | if (!p_data->set_encryption.p_callback) |
| 4694 | { |
| 4695 | APPL_TRACE_ERROR0("bta_dm_set_encryption callback is not provided"); |
| 4696 | return; |
| 4697 | } |
| 4698 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4699 | for (i=0; i<bta_dm_cb.device_list.count; i++) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4700 | { |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4701 | if (bdcmp( bta_dm_cb.device_list.peer_device[i].peer_bdaddr, p_data->set_encryption.bd_addr) == 0 && |
| 4702 | bta_dm_cb.device_list.peer_device[i].conn_state == BTA_DM_CONNECTED) |
| 4703 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4704 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4705 | if (i < bta_dm_cb.device_list.count) |
| 4706 | { |
| 4707 | if (bta_dm_cb.device_list.peer_device[i].p_encrypt_cback) |
| 4708 | { |
| 4709 | APPL_TRACE_ERROR0("earlier enc was not done for same device"); |
| 4710 | (*p_data->set_encryption.p_callback)(p_data->set_encryption.bd_addr, |
| 4711 | p_data->set_encryption.transport, BTA_BUSY); |
| 4712 | return; |
| 4713 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4714 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 4715 | if (BTM_SetEncryption(p_data->set_encryption.bd_addr, |
| 4716 | p_data->set_encryption.transport, |
| 4717 | bta_dm_encrypt_cback, |
| 4718 | &p_data->set_encryption.sec_act) |
| 4719 | == BTM_CMD_STARTED) |
| 4720 | { |
| 4721 | bta_dm_cb.device_list.peer_device[i].p_encrypt_cback = p_data->set_encryption.p_callback; |
| 4722 | } |
| 4723 | } |
| 4724 | else |
| 4725 | { |
| 4726 | APPL_TRACE_ERROR1(" %s Device not found/not connected", __FUNCTION__); |
| 4727 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4728 | } |
| 4729 | |
| 4730 | /******************************************************************************* |
| 4731 | ** |
| 4732 | ** Function bta_dm_set_afh_channels |
| 4733 | ** |
| 4734 | ** Description set afh channels |
| 4735 | ** |
| 4736 | ** |
| 4737 | ** Returns void |
| 4738 | ** |
| 4739 | *******************************************************************************/ |
| 4740 | void bta_dm_set_afh_channels(tBTA_DM_MSG * p_data) |
| 4741 | { |
| 4742 | |
| 4743 | BTM_SetAfhChannels(p_data->set_afhchannels.first,p_data->set_afhchannels.last); |
| 4744 | } |
| 4745 | |
| 4746 | /******************************************************************************* |
| 4747 | ** |
| 4748 | ** Function bta_dm_set_afh_channel_assesment |
| 4749 | ** |
| 4750 | ** Description set afh channel assesment |
| 4751 | ** |
| 4752 | ** |
| 4753 | ** Returns void |
| 4754 | ** |
| 4755 | *******************************************************************************/ |
| 4756 | |
| 4757 | void bta_dm_set_afh_channel_assesment (tBTA_DM_MSG * p_data) |
| 4758 | { |
| 4759 | BTM_SetAfhChannelAssessment(p_data->set_afh_channel_assessment.enable_or_disable); |
| 4760 | } |
| 4761 | |
| 4762 | #if (BLE_INCLUDED == TRUE) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 4763 | /******************************************************************************* |
| 4764 | ** |
| 4765 | ** Function bta_dm_observe_results_cb |
| 4766 | ** |
| 4767 | ** Description Callback for BLE Observe result |
| 4768 | ** |
| 4769 | ** |
| 4770 | ** Returns void |
| 4771 | ** |
| 4772 | *******************************************************************************/ |
| 4773 | static void bta_dm_observe_results_cb (tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir) |
| 4774 | { |
| 4775 | ; |
| 4776 | tBTA_DM_SEARCH result; |
| 4777 | tBTM_INQ_INFO *p_inq_info; |
| 4778 | UINT16 service_class; |
| 4779 | APPL_TRACE_DEBUG0("bta_dm_observe_results_cb") |
| 4780 | |
| 4781 | bdcpy(result.inq_res.bd_addr, p_inq->remote_bd_addr); |
| 4782 | result.inq_res.rssi = p_inq->rssi; |
| 4783 | result.inq_res.ble_addr_type = p_inq->ble_addr_type; |
| 4784 | result.inq_res.inq_result_type = p_inq->inq_result_type; |
| 4785 | result.inq_res.device_type = p_inq->device_type; |
| 4786 | |
| 4787 | /* application will parse EIR to find out remote device name */ |
| 4788 | result.inq_res.p_eir = p_eir; |
| 4789 | |
| 4790 | if((p_inq_info = BTM_InqDbRead(p_inq->remote_bd_addr)) != NULL) |
| 4791 | { |
| 4792 | /* initialize remt_name_not_required to FALSE so that we get the name by default */ |
| 4793 | result.inq_res.remt_name_not_required = FALSE; |
| 4794 | } |
| 4795 | |
| 4796 | if(bta_dm_search_cb.p_scan_cback) |
| 4797 | bta_dm_search_cb.p_scan_cback(BTA_DM_INQ_RES_EVT, &result); |
| 4798 | |
| 4799 | if(p_inq_info) |
| 4800 | { |
| 4801 | /* application indicates if it knows the remote name, inside the callback |
| 4802 | copy that to the inquiry data base*/ |
| 4803 | if(result.inq_res.remt_name_not_required) |
| 4804 | p_inq_info->appl_knows_rem_name = TRUE; |
| 4805 | } |
| 4806 | } |
| 4807 | |
| 4808 | /******************************************************************************* |
| 4809 | ** |
| 4810 | ** Function bta_dm_observe_cmpl_cb |
| 4811 | ** |
| 4812 | ** Description Callback for BLE Observe complete |
| 4813 | ** |
| 4814 | ** |
| 4815 | ** Returns void |
| 4816 | ** |
| 4817 | *******************************************************************************/ |
| 4818 | static void bta_dm_observe_cmpl_cb (void * p_result) |
| 4819 | { |
| 4820 | tBTA_DM_SEARCH data; |
| 4821 | |
| 4822 | APPL_TRACE_DEBUG0("bta_dm_observe_cmpl_cb"); |
| 4823 | |
| 4824 | data.inq_cmpl.num_resps = ((tBTM_INQUIRY_CMPL *)p_result)->num_resp; |
| 4825 | if (bta_dm_search_cb.p_scan_cback) |
| 4826 | { |
| 4827 | bta_dm_search_cb.p_scan_cback(BTA_DM_INQ_CMPL_EVT, &data); |
| 4828 | } |
| 4829 | } |
| 4830 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4831 | #if (SMP_INCLUDED == TRUE) |
| 4832 | /******************************************************************************* |
| 4833 | ** |
| 4834 | ** Function bta_dm_ble_smp_cback |
| 4835 | ** |
| 4836 | ** Description Callback for BLE SMP |
| 4837 | ** |
| 4838 | ** |
| 4839 | ** Returns void |
| 4840 | ** |
| 4841 | *******************************************************************************/ |
| 4842 | static UINT8 bta_dm_ble_smp_cback (tBTM_LE_EVT event, BD_ADDR bda, tBTM_LE_EVT_DATA *p_data) |
| 4843 | { |
| 4844 | tBTM_STATUS status = BTM_SUCCESS; |
| 4845 | tBTA_DM_SEC sec_event; |
Andre Eisenbach | 181d075 | 2013-06-11 14:18:21 -0700 | [diff] [blame] | 4846 | char* p_name = NULL; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 4847 | UINT8 i; |
| 4848 | |
| 4849 | APPL_TRACE_DEBUG0("bta_dm_ble_smp_cback"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4850 | |
| 4851 | if (!bta_dm_cb.p_sec_cback) |
| 4852 | return BTM_NOT_AUTHORIZED; |
| 4853 | |
| 4854 | memset(&sec_event, 0, sizeof(tBTA_DM_SEC)); |
| 4855 | switch (event) |
| 4856 | { |
| 4857 | case BTM_LE_IO_REQ_EVT: |
| 4858 | #if (BTM_LOCAL_IO_CAPS != BTM_IO_CAP_NONE) |
| 4859 | |
| 4860 | bta_dm_co_ble_io_req(bda, |
| 4861 | &p_data->io_req.io_cap, |
| 4862 | &p_data->io_req.oob_data, |
| 4863 | &p_data->io_req.auth_req, |
| 4864 | &p_data->io_req.max_key_size, |
| 4865 | &p_data->io_req.init_keys, |
| 4866 | &p_data->io_req.resp_keys); |
| 4867 | #endif |
| 4868 | #if BTM_OOB_INCLUDED == FALSE |
| 4869 | status = BTM_SUCCESS; |
| 4870 | #endif |
| 4871 | APPL_TRACE_EVENT2("io mitm: %d oob_data:%d", p_data->io_req.auth_req, p_data->io_req.oob_data); |
| 4872 | |
| 4873 | break; |
| 4874 | |
| 4875 | case BTM_LE_SEC_REQUEST_EVT: |
| 4876 | bdcpy(sec_event.ble_req.bd_addr, bda); |
Andre Eisenbach | 181d075 | 2013-06-11 14:18:21 -0700 | [diff] [blame] | 4877 | p_name = BTM_SecReadDevName(bda); |
| 4878 | if (p_name != NULL) |
| 4879 | { |
| 4880 | BCM_STRNCPY_S((char*)sec_event.ble_req.bd_name, |
| 4881 | sizeof(BD_NAME), p_name, (BD_NAME_LEN)); |
| 4882 | } |
| 4883 | else |
| 4884 | { |
| 4885 | sec_event.ble_req.bd_name[0] = 0; |
| 4886 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4887 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_SEC_REQ_EVT, &sec_event); |
| 4888 | break; |
| 4889 | |
| 4890 | case BTM_LE_KEY_NOTIF_EVT: |
| 4891 | bdcpy(sec_event.key_notif.bd_addr, bda); |
Andre Eisenbach | 181d075 | 2013-06-11 14:18:21 -0700 | [diff] [blame] | 4892 | p_name = BTM_SecReadDevName(bda); |
| 4893 | if (p_name != NULL) |
| 4894 | { |
| 4895 | BCM_STRNCPY_S((char*)sec_event.key_notif.bd_name, |
| 4896 | sizeof(BD_NAME), p_name, (BD_NAME_LEN)); |
| 4897 | } |
| 4898 | else |
| 4899 | { |
| 4900 | sec_event.key_notif.bd_name[0] = 0; |
| 4901 | } |
| 4902 | sec_event.key_notif.passkey = p_data->key_notif; |
| 4903 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_PASSKEY_NOTIF_EVT, &sec_event); |
| 4904 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4905 | |
| 4906 | case BTM_LE_KEY_REQ_EVT: |
| 4907 | bdcpy(sec_event.ble_req.bd_addr, bda); |
| 4908 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_PASSKEY_REQ_EVT, &sec_event); |
| 4909 | break; |
| 4910 | |
| 4911 | case BTM_LE_OOB_REQ_EVT: |
| 4912 | bdcpy(sec_event.ble_req.bd_addr, bda); |
| 4913 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_OOB_REQ_EVT, &sec_event); |
| 4914 | break; |
| 4915 | |
| 4916 | case BTM_LE_KEY_EVT: |
| 4917 | bdcpy(sec_event.ble_key.bd_addr, bda); |
| 4918 | sec_event.ble_key.key_type = p_data->key.key_type; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 4919 | |
| 4920 | if (p_data->key.key_type == BTM_LE_KEY_PID) |
| 4921 | { |
| 4922 | for (i=0; i<BT_OCTET16_LEN; i++ ) |
| 4923 | { |
| 4924 | sec_event.ble_key.key_value.pid_key.irk[i] = p_data->key.p_key_value->pid_key.irk[i]; |
| 4925 | } |
| 4926 | sec_event.ble_key.key_value.pid_key.addr_type = p_data->key.p_key_value->pid_key.addr_type; |
| 4927 | memcpy( &(sec_event.ble_key.key_value.pid_key.static_addr), |
| 4928 | &(p_data->key.p_key_value->pid_key.static_addr), |
| 4929 | sizeof (BD_ADDR)); |
| 4930 | } |
| 4931 | else |
| 4932 | { |
| 4933 | memcpy(&sec_event.ble_key.key_value, p_data->key.p_key_value, sizeof(tBTM_LE_KEY_VALUE)); |
| 4934 | } |
| 4935 | // memcpy(&sec_event.ble_key.key_value, p_data->key.p_key_value, sizeof(tBTM_LE_KEY_VALUE)); todo will crash |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4936 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_KEY_EVT, &sec_event); |
| 4937 | break; |
| 4938 | |
| 4939 | case BTM_LE_COMPLT_EVT: |
| 4940 | bdcpy(sec_event.auth_cmpl.bd_addr, bda); |
Andre Eisenbach | 181d075 | 2013-06-11 14:18:21 -0700 | [diff] [blame] | 4941 | p_name = BTM_SecReadDevName(bda); |
| 4942 | if (p_name != NULL) |
| 4943 | { |
| 4944 | BCM_STRNCPY_S((char*)sec_event.auth_cmpl.bd_name, |
| 4945 | sizeof(BD_NAME), p_name, (BD_NAME_LEN)); |
| 4946 | } |
| 4947 | else |
| 4948 | { |
| 4949 | sec_event.auth_cmpl.bd_name[0] = 0; |
| 4950 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 4951 | if (p_data->complt.reason != 0) |
| 4952 | { |
| 4953 | sec_event.auth_cmpl.fail_reason = BTA_DM_AUTH_CONVERT_SMP_CODE(((UINT8)p_data->complt.reason)); |
| 4954 | /* delete this device entry from Sec Dev DB */ |
| 4955 | bta_dm_remove_sec_dev_entry (bda); |
| 4956 | } |
| 4957 | else |
| 4958 | { |
| 4959 | sec_event.auth_cmpl.success = TRUE; |
| 4960 | } |
| 4961 | sec_event.auth_cmpl.privacy_enabled = p_data->complt.privacy_supported; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 4962 | if (bta_dm_cb.p_sec_cback) |
| 4963 | { |
| 4964 | //bta_dm_cb.p_sec_cback(BTA_DM_AUTH_CMPL_EVT, &sec_event); |
| 4965 | bta_dm_cb.p_sec_cback(BTA_DM_BLE_AUTH_CMPL_EVT, &sec_event); |
| 4966 | } |
| 4967 | |
| 4968 | break; |
| 4969 | |
| 4970 | default: |
| 4971 | status = BTM_NOT_AUTHORIZED; |
| 4972 | break; |
| 4973 | } |
| 4974 | return status; |
| 4975 | } |
| 4976 | #endif /* SMP_INCLUDED == TRUE */ |
| 4977 | |
| 4978 | /******************************************************************************* |
| 4979 | ** |
| 4980 | ** Function bta_dm_ble_id_key_cback |
| 4981 | ** |
| 4982 | ** Description Callback for BLE local ID keys |
| 4983 | ** |
| 4984 | ** |
| 4985 | ** Returns void |
| 4986 | ** |
| 4987 | *******************************************************************************/ |
| 4988 | static void bta_dm_ble_id_key_cback (UINT8 key_type, tBTM_BLE_LOCAL_KEYS *p_key) |
| 4989 | { |
| 4990 | UINT8 evt; |
| 4991 | tBTA_DM_SEC dm_key; |
| 4992 | |
| 4993 | switch (key_type) |
| 4994 | { |
| 4995 | case BTM_BLE_KEY_TYPE_ID: |
| 4996 | case BTM_BLE_KEY_TYPE_ER: |
| 4997 | if (bta_dm_cb.p_sec_cback) |
| 4998 | { |
| 4999 | memcpy(&dm_key.ble_id_keys, p_key, sizeof(tBTM_BLE_LOCAL_KEYS)); |
| 5000 | |
| 5001 | evt = (key_type == BTM_BLE_KEY_TYPE_ID) ? BTA_DM_BLE_LOCAL_IR_EVT :\ |
| 5002 | BTA_DM_BLE_LOCAL_ER_EVT; |
| 5003 | bta_dm_cb.p_sec_cback(evt, &dm_key); |
| 5004 | } |
| 5005 | break; |
| 5006 | |
| 5007 | default: |
| 5008 | APPL_TRACE_DEBUG1("Unknown key type %d", key_type); |
| 5009 | break; |
| 5010 | } |
| 5011 | return; |
| 5012 | |
| 5013 | } |
| 5014 | |
| 5015 | /******************************************************************************* |
| 5016 | ** |
| 5017 | ** Function bta_dm_add_blekey |
| 5018 | ** |
| 5019 | ** Description This function adds an BLE Key to an security database entry. |
| 5020 | ** This function shall only be called AFTER BTA_DmAddBleDevice has been called. |
| 5021 | ** It is normally called during host startup to restore all required information |
| 5022 | ** stored in the NVRAM. |
| 5023 | ** |
| 5024 | ** Parameters: |
| 5025 | ** |
| 5026 | *******************************************************************************/ |
| 5027 | void bta_dm_add_blekey (tBTA_DM_MSG *p_data) |
| 5028 | { |
| 5029 | if (!BTM_SecAddBleKey (p_data->add_ble_key.bd_addr, |
| 5030 | (tBTM_LE_KEY_VALUE *)&p_data->add_ble_key.blekey, |
| 5031 | p_data->add_ble_key.key_type)) |
| 5032 | { |
| 5033 | APPL_TRACE_ERROR2 ("BTA_DM: Error adding BLE Key for device %08x%04x", |
| 5034 | (p_data->add_ble_key.bd_addr[0]<<24)+(p_data->add_ble_key.bd_addr[1]<<16)+\ |
| 5035 | (p_data->add_ble_key.bd_addr[2]<<8)+p_data->add_ble_key.bd_addr[3], |
| 5036 | (p_data->add_ble_key.bd_addr[4]<<8)+p_data->add_ble_key.bd_addr[5]); |
| 5037 | } |
| 5038 | } |
| 5039 | |
| 5040 | /******************************************************************************* |
| 5041 | ** |
| 5042 | ** Function bta_dm_add_ble_device |
| 5043 | ** |
| 5044 | ** Description This function adds an BLE device to an security database entry. |
| 5045 | ** It is normally called during host startup to restore all required information |
| 5046 | ** stored in the NVRAM. |
| 5047 | ** |
| 5048 | ** Parameters: |
| 5049 | ** |
| 5050 | *******************************************************************************/ |
| 5051 | void bta_dm_add_ble_device (tBTA_DM_MSG *p_data) |
| 5052 | { |
| 5053 | if (!BTM_SecAddBleDevice (p_data->add_ble_device.bd_addr, NULL, |
| 5054 | p_data->add_ble_device.dev_type , |
| 5055 | p_data->add_ble_device.addr_type)) |
| 5056 | { |
| 5057 | APPL_TRACE_ERROR2 ("BTA_DM: Error adding BLE Device for device %08x%04x", |
| 5058 | (p_data->add_ble_device.bd_addr[0]<<24)+(p_data->add_ble_device.bd_addr[1]<<16)+ \ |
| 5059 | (p_data->add_ble_device.bd_addr[2]<<8)+p_data->add_ble_device.bd_addr[3], |
| 5060 | (p_data->add_ble_device.bd_addr[4]<<8)+p_data->add_ble_device.bd_addr[5]); |
| 5061 | } |
| 5062 | } |
| 5063 | |
| 5064 | /******************************************************************************* |
| 5065 | ** |
| 5066 | ** Function bta_dm_add_ble_device |
| 5067 | ** |
| 5068 | ** Description This function adds an BLE device to an security database entry. |
| 5069 | ** It is normally called during host startup to restore all required information |
| 5070 | ** stored in the NVRAM. |
| 5071 | ** |
| 5072 | ** Parameters: |
| 5073 | ** |
| 5074 | *******************************************************************************/ |
| 5075 | void bta_dm_ble_passkey_reply (tBTA_DM_MSG *p_data) |
| 5076 | { |
| 5077 | if (p_data->pin_reply.accept) |
| 5078 | { |
| 5079 | |
| 5080 | BTM_BlePasskeyReply(p_data->ble_passkey_reply.bd_addr, BTM_SUCCESS, p_data->ble_passkey_reply.passkey); |
| 5081 | } |
| 5082 | else |
| 5083 | { |
| 5084 | BTM_BlePasskeyReply(p_data->ble_passkey_reply.bd_addr, BTM_NOT_AUTHORIZED, p_data->ble_passkey_reply.passkey); |
| 5085 | } |
| 5086 | |
| 5087 | } |
| 5088 | |
| 5089 | /******************************************************************************* |
| 5090 | ** |
| 5091 | ** Function bta_dm_security_grant |
| 5092 | ** |
| 5093 | ** Description This function grant SMP security request access. |
| 5094 | ** |
| 5095 | ** Parameters: |
| 5096 | ** |
| 5097 | *******************************************************************************/ |
| 5098 | void bta_dm_security_grant (tBTA_DM_MSG *p_data) |
| 5099 | { |
| 5100 | BTM_SecurityGrant(p_data->ble_sec_grant.bd_addr, p_data->ble_sec_grant.res); |
| 5101 | } |
| 5102 | |
| 5103 | /******************************************************************************* |
| 5104 | ** |
| 5105 | ** Function bta_dm_ble_set_bg_conn_type |
| 5106 | ** |
| 5107 | ** Description This function set the BLE background connection type |
| 5108 | ** |
| 5109 | ** Parameters: |
| 5110 | ** |
| 5111 | *******************************************************************************/ |
| 5112 | void bta_dm_ble_set_bg_conn_type (tBTA_DM_MSG *p_data) |
| 5113 | { |
| 5114 | BTM_BleSetBgConnType(p_data->ble_set_bd_conn_type.bg_conn_type, |
| 5115 | p_data->ble_set_bd_conn_type.p_select_cback); |
| 5116 | } |
| 5117 | |
| 5118 | /******************************************************************************* |
| 5119 | ** |
| 5120 | ** Function bta_dm_ble_set_conn_params |
| 5121 | ** |
| 5122 | ** Description This function set the preferred connection parameters. |
| 5123 | ** |
| 5124 | ** Parameters: |
| 5125 | ** |
| 5126 | *******************************************************************************/ |
| 5127 | void bta_dm_ble_set_conn_params (tBTA_DM_MSG *p_data) |
| 5128 | { |
| 5129 | BTM_BleSetPrefConnParams(p_data->ble_set_conn_params.peer_bda, |
| 5130 | p_data->ble_set_conn_params.conn_int_min, |
| 5131 | p_data->ble_set_conn_params.conn_int_max, |
| 5132 | p_data->ble_set_conn_params.slave_latency, |
| 5133 | p_data->ble_set_conn_params.supervision_tout); |
| 5134 | } |
| 5135 | |
| 5136 | /******************************************************************************* |
| 5137 | ** |
| 5138 | ** Function bta_dm_ble_set_scan_params |
| 5139 | ** |
| 5140 | ** Description This function set the preferred connection scan parameters. |
| 5141 | ** |
| 5142 | ** Parameters: |
| 5143 | ** |
| 5144 | *******************************************************************************/ |
| 5145 | void bta_dm_ble_set_scan_params (tBTA_DM_MSG *p_data) |
| 5146 | { |
| 5147 | BTM_BleSetConnScanParams(p_data->ble_set_scan_params.scan_int, |
| 5148 | p_data->ble_set_scan_params.scan_window); |
| 5149 | } |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 5150 | /******************************************************************************* |
| 5151 | ** |
| 5152 | ** Function bta_dm_ble_update_conn_params |
| 5153 | ** |
| 5154 | ** Description This function update LE connection parameters. |
| 5155 | ** |
| 5156 | ** Parameters: |
| 5157 | ** |
| 5158 | *******************************************************************************/ |
| 5159 | void bta_dm_ble_update_conn_params (tBTA_DM_MSG *p_data) |
| 5160 | { |
| 5161 | if (!L2CA_UpdateBleConnParams(p_data->ble_update_conn_params.bd_addr, |
| 5162 | p_data->ble_update_conn_params.min_int, |
| 5163 | p_data-> ble_update_conn_params.max_int, |
| 5164 | p_data->ble_update_conn_params.latency, |
| 5165 | p_data->ble_update_conn_params.timeout)) |
| 5166 | { |
| 5167 | APPL_TRACE_ERROR0("Update connection parameters failed!"); |
| 5168 | } |
| 5169 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 5170 | |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 5171 | #if BLE_PRIVACY_SPT == TRUE |
| 5172 | /******************************************************************************* |
| 5173 | ** |
| 5174 | ** Function bta_dm_ble_config_local_privacy |
| 5175 | ** |
| 5176 | ** Description This function set the local device LE privacy settings. |
| 5177 | ** |
| 5178 | ** Parameters: |
| 5179 | ** |
| 5180 | *******************************************************************************/ |
| 5181 | void bta_dm_ble_config_local_privacy (tBTA_DM_MSG *p_data) |
| 5182 | { |
| 5183 | BTM_BleConfigPrivacy (p_data->ble_local_privacy.privacy_enable); |
| 5184 | } |
| 5185 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 5186 | |
| 5187 | /******************************************************************************* |
| 5188 | ** |
| 5189 | ** Function bta_dm_ble_observe |
| 5190 | ** |
| 5191 | ** Description This function set the preferred connection scan parameters. |
| 5192 | ** |
| 5193 | ** Parameters: |
| 5194 | ** |
| 5195 | *******************************************************************************/ |
| 5196 | void bta_dm_ble_observe (tBTA_DM_MSG *p_data) |
| 5197 | { |
| 5198 | |
| 5199 | tBTM_STATUS status; |
| 5200 | if (p_data->ble_observe.start) |
| 5201 | { |
| 5202 | /*Save the callback to be called when a scan results are available */ |
| 5203 | bta_dm_search_cb.p_scan_cback = p_data->ble_observe.p_cback; |
| 5204 | if ((status = BTM_BleObserve(TRUE, p_data->ble_observe.duration, |
| 5205 | bta_dm_observe_results_cb, bta_dm_observe_cmpl_cb))!= BTM_SUCCESS) |
| 5206 | { |
| 5207 | tBTA_DM_SEARCH data; |
| 5208 | APPL_TRACE_WARNING2(" %s BTM_BleObserve failed. status %d",__FUNCTION__,status); |
| 5209 | data.inq_cmpl.num_resps = 0; |
| 5210 | if (bta_dm_search_cb.p_scan_cback) |
| 5211 | { |
| 5212 | bta_dm_search_cb.p_scan_cback(BTA_DM_INQ_CMPL_EVT, &data); |
| 5213 | } |
| 5214 | } |
| 5215 | } |
| 5216 | else |
| 5217 | { |
| 5218 | bta_dm_search_cb.p_scan_cback = NULL; |
| 5219 | BTM_BleObserve(FALSE, 0, NULL,NULL ); |
| 5220 | } |
| 5221 | } |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 5222 | /******************************************************************************* |
| 5223 | ** |
| 5224 | ** Function bta_dm_ble_set_scan_params |
| 5225 | ** |
| 5226 | ** Description This function set the adv parameters. |
| 5227 | ** |
| 5228 | ** Parameters: |
| 5229 | ** |
| 5230 | *******************************************************************************/ |
| 5231 | void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data) |
| 5232 | { |
| 5233 | BTM_BleSetAdvParams(p_data->ble_set_adv_params.adv_int_min, |
| 5234 | p_data->ble_set_adv_params.adv_int_max, |
| 5235 | p_data->ble_set_adv_params.p_dir_bda, |
| 5236 | BTA_DM_BLE_ADV_CHNL_MAP); |
| 5237 | } |
Andre Eisenbach | eeeac99 | 2013-11-08 10:23:52 -0800 | [diff] [blame] | 5238 | |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 5239 | /******************************************************************************* |
| 5240 | ** |
| 5241 | ** Function bta_dm_ble_set_adv_config |
| 5242 | ** |
| 5243 | ** Description This function set the customized ADV data configuration |
| 5244 | ** |
| 5245 | ** Parameters: |
| 5246 | ** |
| 5247 | *******************************************************************************/ |
| 5248 | void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data) |
| 5249 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 5250 | tBTA_STATUS status = BTA_FAILURE; |
| 5251 | |
| 5252 | if (BTM_BleWriteAdvData(p_data->ble_set_adv_data.data_mask, |
| 5253 | (tBTM_BLE_ADV_DATA *)p_data->ble_set_adv_data.p_adv_cfg) == BTM_SUCCESS) |
| 5254 | { |
| 5255 | status = BTA_SUCCESS; |
| 5256 | } |
| 5257 | |
| 5258 | if (p_data->ble_set_adv_data.p_adv_data_cback) |
| 5259 | (*p_data->ble_set_adv_data.p_adv_data_cback)(status); |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 5260 | } |
| 5261 | |
Andre Eisenbach | eeeac99 | 2013-11-08 10:23:52 -0800 | [diff] [blame] | 5262 | /******************************************************************************* |
| 5263 | ** |
| 5264 | ** Function bta_dm_ble_set_scan_rsp |
| 5265 | ** |
| 5266 | ** Description This function set the customized ADV scan resp. configuration |
| 5267 | ** |
| 5268 | ** Parameters: |
| 5269 | ** |
| 5270 | *******************************************************************************/ |
| 5271 | void bta_dm_ble_set_scan_rsp (tBTA_DM_MSG *p_data) |
| 5272 | { |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 5273 | tBTA_STATUS status = BTA_FAILURE; |
| 5274 | |
| 5275 | if(BTM_BleWriteScanRsp(p_data->ble_set_adv_data.data_mask, |
| 5276 | (tBTM_BLE_ADV_DATA *)p_data->ble_set_adv_data.p_adv_cfg) == BTM_SUCCESS) |
| 5277 | { |
| 5278 | status = BTA_SUCCESS; |
| 5279 | } |
| 5280 | |
| 5281 | if (p_data->ble_set_adv_data.p_adv_data_cback) |
| 5282 | (*p_data->ble_set_adv_data.p_adv_data_cback)(status); |
Andre Eisenbach | eeeac99 | 2013-11-08 10:23:52 -0800 | [diff] [blame] | 5283 | } |
| 5284 | |
| 5285 | /******************************************************************************* |
| 5286 | ** |
| 5287 | ** Function bta_dm_ble_broadcast |
| 5288 | ** |
| 5289 | ** Description Starts or stops LE broadcasts |
| 5290 | ** |
| 5291 | ** Parameters: |
| 5292 | ** |
| 5293 | *******************************************************************************/ |
| 5294 | void bta_dm_ble_broadcast (tBTA_DM_MSG *p_data) |
| 5295 | { |
| 5296 | BTM_BleBroadcast(p_data->ble_observe.start); |
| 5297 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 5298 | |
Wei Wang | a6ce775 | 2014-05-20 06:30:32 +0000 | [diff] [blame] | 5299 | /******************************************************************************* |
| 5300 | ** |
| 5301 | ** Function bta_dm_ble_multi_adv_enb |
| 5302 | ** |
| 5303 | ** Description This function enables a single advertising instance |
| 5304 | ** |
| 5305 | ** Parameters: |
| 5306 | ** |
| 5307 | *******************************************************************************/ |
| 5308 | void bta_dm_ble_multi_adv_enb(tBTA_DM_MSG *p_data) |
| 5309 | { |
| 5310 | #if BLE_MULTI_ADV_INCLUDED == TRUE |
| 5311 | BTM_BleEnableAdvInstance((tBTM_BLE_ADV_PARAMS*)p_data->ble_multi_adv_enb.p_params, |
| 5312 | p_data->ble_multi_adv_enb.p_cback,p_data->ble_multi_adv_enb.p_ref); |
| 5313 | #endif |
| 5314 | } |
| 5315 | /******************************************************************************* |
| 5316 | ** |
| 5317 | ** Function bta_dm_ble_multi_adv_param_upd |
| 5318 | ** |
| 5319 | ** Description This function updates multiple advertising instance parameters |
| 5320 | ** |
| 5321 | ** Parameters: |
| 5322 | ** |
| 5323 | *******************************************************************************/ |
| 5324 | void bta_dm_ble_multi_adv_upd_param(tBTA_DM_MSG *p_data) |
| 5325 | { |
| 5326 | #if BLE_MULTI_ADV_INCLUDED == TRUE |
| 5327 | BTM_BleUpdateAdvInstParam(p_data->ble_multi_adv_param.inst_id, |
| 5328 | (tBTM_BLE_ADV_PARAMS*)p_data->ble_multi_adv_param.p_params); |
| 5329 | #endif |
| 5330 | } |
| 5331 | /******************************************************************************* |
| 5332 | ** |
| 5333 | ** Function bta_dm_ble_multi_adv_data |
| 5334 | ** |
| 5335 | ** Description This function write multiple advertising instance adv data |
| 5336 | ** or scan response data |
| 5337 | ** |
| 5338 | ** Parameters: |
| 5339 | ** |
| 5340 | *******************************************************************************/ |
| 5341 | void bta_dm_ble_multi_adv_data(tBTA_DM_MSG *p_data) |
| 5342 | { |
| 5343 | #if BLE_MULTI_ADV_INCLUDED == TRUE |
| 5344 | BTM_BleCfgAdvInstData(p_data->ble_multi_adv_data.inst_id,p_data->ble_multi_adv_data.is_scan_rsp, |
| 5345 | p_data->ble_multi_adv_data.data_mask,(tBTM_BLE_ADV_DATA*)p_data->ble_multi_adv_data.p_data); |
| 5346 | #endif |
| 5347 | } |
| 5348 | /******************************************************************************* |
| 5349 | ** |
| 5350 | ** Function btm_dm_ble_multi_adv_disable |
| 5351 | ** |
| 5352 | ** Description This function disable a single adv instance |
| 5353 | ** |
| 5354 | ** Parameters: |
| 5355 | ** |
| 5356 | *******************************************************************************/ |
| 5357 | void btm_dm_ble_multi_adv_disable(tBTA_DM_MSG *p_data) |
| 5358 | { |
| 5359 | #if BLE_MULTI_ADV_INCLUDED == TRUE |
| 5360 | BTM_BleDisableAdvInstance(p_data->ble_multi_adv_disable.inst_id); |
| 5361 | #endif |
| 5362 | } |
| 5363 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 5364 | #if ((defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE)) |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 5365 | #ifndef BTA_DM_GATT_CLOSE_DELAY_TOUT |
| 5366 | #define BTA_DM_GATT_CLOSE_DELAY_TOUT 1000 |
| 5367 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 5368 | |
| 5369 | /******************************************************************************* |
| 5370 | ** |
Andre Eisenbach | e1202ca | 2013-05-15 04:55:08 -0700 | [diff] [blame] | 5371 | ** Function bta_dm_gattc_register |
| 5372 | ** |
| 5373 | ** Description Register with GATTC in DM if BLE is needed. |
| 5374 | ** |
| 5375 | ** |
| 5376 | ** Returns void |
| 5377 | ** |
| 5378 | *******************************************************************************/ |
| 5379 | static void bta_dm_gattc_register(void) |
| 5380 | { |
| 5381 | tBT_UUID app_uuid = {LEN_UUID_128,{0}}; |
| 5382 | |
| 5383 | if (bta_dm_search_cb.client_if == BTA_GATTS_INVALID_IF) |
| 5384 | { |
| 5385 | memset (&app_uuid.uu.uuid128, 0x87, LEN_UUID_128); |
| 5386 | BTA_GATTC_AppRegister(&app_uuid, bta_dm_gattc_callback); |
| 5387 | } |
| 5388 | } |
| 5389 | |
| 5390 | /******************************************************************************* |
| 5391 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 5392 | ** Function btm_dm_start_disc_gatt_services |
| 5393 | ** |
| 5394 | ** Description This function starts a GATT service search request. |
| 5395 | ** |
| 5396 | ** Parameters: |
| 5397 | ** |
| 5398 | *******************************************************************************/ |
| 5399 | static void btm_dm_start_disc_gatt_services (UINT16 conn_id) |
| 5400 | { |
| 5401 | tBT_UUID *p_uuid = bta_dm_search_cb.p_srvc_uuid + |
| 5402 | bta_dm_search_cb.num_uuid - bta_dm_search_cb.uuid_to_search; |
| 5403 | |
| 5404 | p_uuid = bta_dm_search_cb.p_srvc_uuid + |
| 5405 | bta_dm_search_cb.num_uuid - bta_dm_search_cb.uuid_to_search; |
| 5406 | |
| 5407 | /* always search for all services */ |
| 5408 | BTA_GATTC_ServiceSearchRequest(conn_id, p_uuid); |
| 5409 | } |
| 5410 | |
| 5411 | /******************************************************************************* |
| 5412 | ** |
| 5413 | ** Function bta_dm_gatt_disc_result |
| 5414 | ** |
| 5415 | ** Description This function process the GATT service search result. |
| 5416 | ** |
| 5417 | ** Parameters: |
| 5418 | ** |
| 5419 | *******************************************************************************/ |
| 5420 | static void bta_dm_gatt_disc_result(tBTA_GATT_ID service_id) |
| 5421 | { |
| 5422 | tBTA_DM_SEARCH result; |
| 5423 | |
| 5424 | /* |
| 5425 | * This logic will not work for gatt case. We are checking against the bluetooth profiles here |
| 5426 | * just copy the GATTID in raw data field and send it across. |
| 5427 | */ |
| 5428 | |
| 5429 | |
| 5430 | if ( bta_dm_search_cb.ble_raw_used + sizeof(tBTA_GATT_ID) < bta_dm_search_cb.ble_raw_size ) |
| 5431 | { |
| 5432 | APPL_TRACE_DEBUG3("ADDING BLE SERVICE uuid=0x%x, ble_ptr = 0x%x, ble_raw_used = 0x%x", service_id.uuid.uu.uuid16,bta_dm_search_cb.p_ble_rawdata,bta_dm_search_cb.ble_raw_used); |
| 5433 | |
Andre Eisenbach | ca22ac4 | 2013-02-13 17:02:11 +0900 | [diff] [blame] | 5434 | if(bta_dm_search_cb.p_ble_rawdata) |
| 5435 | { |
| 5436 | memcpy((bta_dm_search_cb.p_ble_rawdata + bta_dm_search_cb.ble_raw_used), &service_id, |
| 5437 | sizeof(service_id) ); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 5438 | |
Andre Eisenbach | ca22ac4 | 2013-02-13 17:02:11 +0900 | [diff] [blame] | 5439 | bta_dm_search_cb.ble_raw_used += sizeof(service_id); |
| 5440 | } |
| 5441 | else |
| 5442 | { |
| 5443 | APPL_TRACE_ERROR0("p_ble_rawdata is NULL"); |
| 5444 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 5445 | |
| 5446 | } |
| 5447 | else |
| 5448 | { |
| 5449 | APPL_TRACE_ERROR3("%s out of room to accomodate more service ids ble_raw_size = %d ble_raw_used = %d", __FUNCTION__,bta_dm_search_cb.ble_raw_size, bta_dm_search_cb.ble_raw_used ); |
| 5450 | } |
| 5451 | |
| 5452 | APPL_TRACE_ERROR1("bta_dm_gatt_disc_result serivce_id len=%d ", service_id.uuid.len); |
| 5453 | if ( bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE) |
| 5454 | { |
| 5455 | |
| 5456 | /* send result back to app now, one by one */ |
| 5457 | bdcpy (result.disc_ble_res.bd_addr, bta_dm_search_cb.peer_bdaddr); |
| 5458 | BCM_STRNCPY_S((char*)result.disc_ble_res.bd_name, sizeof(BD_NAME), bta_dm_get_remname(), (BD_NAME_LEN-1)); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 5459 | result.disc_ble_res.bd_name[BD_NAME_LEN] = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 5460 | memcpy(&result.disc_ble_res.service, &service_id.uuid, sizeof(tBT_UUID)); |
| 5461 | |
| 5462 | bta_dm_search_cb.p_search_cback(BTA_DM_DISC_BLE_RES_EVT, &result); |
| 5463 | } |
| 5464 | } |
| 5465 | |
| 5466 | /******************************************************************************* |
| 5467 | ** |
| 5468 | ** Function bta_dm_gatt_disc_complete |
| 5469 | ** |
| 5470 | ** Description This function process the GATT service search complete. |
| 5471 | ** |
| 5472 | ** Parameters: |
| 5473 | ** |
| 5474 | *******************************************************************************/ |
| 5475 | static void bta_dm_gatt_disc_complete(UINT16 conn_id, tBTA_GATT_STATUS status) |
| 5476 | { |
| 5477 | tBTA_DM_MSG *p_msg; |
| 5478 | |
| 5479 | APPL_TRACE_DEBUG1("bta_dm_gatt_disc_complete conn_id = %d",conn_id); |
| 5480 | |
| 5481 | if (bta_dm_search_cb.uuid_to_search > 0) bta_dm_search_cb.uuid_to_search --; |
| 5482 | |
| 5483 | if (status == BTA_GATT_OK && bta_dm_search_cb.uuid_to_search > 0) |
| 5484 | { |
| 5485 | btm_dm_start_disc_gatt_services(conn_id); |
| 5486 | } |
| 5487 | else |
| 5488 | { |
| 5489 | bta_dm_search_cb.uuid_to_search = 0; |
| 5490 | |
| 5491 | /* no more services to be discovered */ |
| 5492 | if ((p_msg = (tBTA_DM_MSG *) GKI_getbuf(sizeof(tBTA_DM_MSG))) != NULL) |
| 5493 | { |
| 5494 | p_msg->hdr.event = BTA_DM_DISCOVERY_RESULT_EVT; |
| 5495 | p_msg->disc_result.result.disc_res.result = (status == BTA_GATT_OK) ? BTA_SUCCESS :BTA_FAILURE; |
| 5496 | p_msg->disc_result.result.disc_res.services = bta_dm_search_cb.services_found; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 5497 | p_msg->disc_result.result.disc_res.num_uuids = 0; |
| 5498 | p_msg->disc_result.result.disc_res.p_uuid_list = NULL; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 5499 | bdcpy (p_msg->disc_result.result.disc_res.bd_addr, bta_dm_search_cb.peer_bdaddr); |
| 5500 | BCM_STRNCPY_S((char*)p_msg->disc_result.result.disc_res.bd_name, sizeof(BD_NAME), |
| 5501 | bta_dm_get_remname(), (BD_NAME_LEN-1)); |
| 5502 | |
| 5503 | /* make sure the string is terminated */ |
| 5504 | p_msg->disc_result.result.disc_res.bd_name[BD_NAME_LEN-1] = 0; |
| 5505 | |
| 5506 | p_msg->disc_result.result.disc_res.device_type = BT_DEVICE_TYPE_BLE; |
| 5507 | if ( bta_dm_search_cb.ble_raw_used > 0 ) |
| 5508 | { |
| 5509 | p_msg->disc_result.result.disc_res.p_raw_data = GKI_getbuf(bta_dm_search_cb.ble_raw_used); |
| 5510 | |
| 5511 | memcpy( p_msg->disc_result.result.disc_res.p_raw_data, |
| 5512 | bta_dm_search_cb.p_ble_rawdata, |
| 5513 | bta_dm_search_cb.ble_raw_used ); |
| 5514 | |
| 5515 | p_msg->disc_result.result.disc_res.raw_data_size = bta_dm_search_cb.ble_raw_used; |
| 5516 | } |
| 5517 | else |
| 5518 | { |
| 5519 | p_msg->disc_result.result.disc_res.p_raw_data = NULL; |
| 5520 | bta_dm_search_cb.p_ble_rawdata = 0; |
| 5521 | } |
| 5522 | |
| 5523 | bta_sys_sendmsg(p_msg); |
| 5524 | } |
| 5525 | if (conn_id != BTA_GATT_INVALID_CONN_ID) |
| 5526 | { |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 5527 | if (BTA_DM_GATT_CLOSE_DELAY_TOUT != 0) |
| 5528 | { |
| 5529 | bta_sys_start_timer(&bta_dm_search_cb.gatt_close_timer, BTA_DM_DISC_CLOSE_TOUT_EVT, |
| 5530 | BTA_DM_GATT_CLOSE_DELAY_TOUT); |
| 5531 | } |
| 5532 | else |
| 5533 | { |
| 5534 | BTA_GATTC_Close(conn_id); |
| 5535 | bta_dm_search_cb.conn_id = BTA_GATT_INVALID_CONN_ID; |
| 5536 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 5537 | } |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 5538 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 5539 | bta_dm_search_cb.gatt_disc_active = FALSE; |
| 5540 | } |
| 5541 | } |
| 5542 | |
| 5543 | /******************************************************************************* |
| 5544 | ** |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 5545 | ** Function bta_dm_close_gatt_conn |
| 5546 | ** |
| 5547 | ** Description This function close the GATT connection after delay timeout. |
| 5548 | ** |
| 5549 | ** Parameters: |
| 5550 | ** |
| 5551 | *******************************************************************************/ |
| 5552 | void bta_dm_close_gatt_conn(tBTA_DM_MSG *p_data) |
| 5553 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 5554 | UNUSED(p_data); |
| 5555 | |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 5556 | if (bta_dm_search_cb.conn_id != BTA_GATT_INVALID_CONN_ID) |
| 5557 | BTA_GATTC_Close(bta_dm_search_cb.conn_id); |
| 5558 | |
| 5559 | bta_dm_search_cb.conn_id = BTA_GATT_INVALID_CONN_ID; |
| 5560 | } |
| 5561 | |
| 5562 | /******************************************************************************* |
| 5563 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 5564 | ** Function btm_dm_start_gatt_discovery |
| 5565 | ** |
| 5566 | ** Description This is GATT initiate the service search by open a GATT connection |
| 5567 | ** first. |
| 5568 | ** |
| 5569 | ** Parameters: |
| 5570 | ** |
| 5571 | *******************************************************************************/ |
| 5572 | void btm_dm_start_gatt_discovery (BD_ADDR bd_addr) |
| 5573 | { |
| 5574 | bta_dm_search_cb.gatt_disc_active = TRUE; |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 5575 | |
| 5576 | /* connection is already open */ |
| 5577 | if (bdcmp(bta_dm_search_cb.pending_close_bda, bd_addr) == 0 && |
| 5578 | bta_dm_search_cb.conn_id != BTA_GATT_INVALID_CONN_ID) |
| 5579 | { |
| 5580 | memset(bta_dm_search_cb.pending_close_bda, 0, BD_ADDR_LEN); |
| 5581 | bta_sys_stop_timer(&bta_dm_search_cb.gatt_close_timer); |
| 5582 | btm_dm_start_disc_gatt_services(bta_dm_search_cb.conn_id); |
| 5583 | } |
| 5584 | else |
Ganesh Ganapathi Batta | 7fa4fba | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 5585 | BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, TRUE, BTA_GATT_TRANSPORT_LE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 5586 | } |
| 5587 | |
| 5588 | /******************************************************************************* |
| 5589 | ** |
| 5590 | ** Function bta_dm_cancel_gatt_discovery |
| 5591 | ** |
| 5592 | ** Description This is GATT cancel the GATT service search. |
| 5593 | ** |
| 5594 | ** Parameters: |
| 5595 | ** |
| 5596 | *******************************************************************************/ |
| 5597 | static void bta_dm_cancel_gatt_discovery(BD_ADDR bd_addr) |
| 5598 | { |
| 5599 | if (bta_dm_search_cb.conn_id == BTA_GATT_INVALID_CONN_ID) |
| 5600 | { |
| 5601 | BTA_GATTC_CancelOpen(bta_dm_search_cb.client_if, bd_addr, TRUE); |
| 5602 | } |
| 5603 | |
| 5604 | bta_dm_gatt_disc_complete(bta_dm_search_cb.conn_id, (tBTA_GATT_STATUS) BTA_GATT_ERROR); |
| 5605 | } |
| 5606 | |
| 5607 | /******************************************************************************* |
| 5608 | ** |
| 5609 | ** Function bta_dm_proc_open_evt |
| 5610 | ** |
| 5611 | ** Description process BTA_GATTC_OPEN_EVT in DM. |
| 5612 | ** |
| 5613 | ** Parameters: |
| 5614 | ** |
| 5615 | *******************************************************************************/ |
| 5616 | void bta_dm_proc_open_evt(tBTA_GATTC_OPEN *p_data) |
| 5617 | { |
| 5618 | UINT8 *p1; |
| 5619 | UINT8 *p2; |
| 5620 | |
| 5621 | p1 = bta_dm_search_cb.peer_bdaddr; |
| 5622 | p2 = p_data->remote_bda; |
| 5623 | |
| 5624 | APPL_TRACE_DEBUG5("DM Search state= %d search_cb.peer_dbaddr: [%08x%04x] connected_bda= [%08x%04x] ", |
| 5625 | bta_dm_search_cb.state, |
| 5626 | ((p1[0])<<24)+((p1[1])<<16)+((p1[2])<<8)+(p1[3]), |
| 5627 | ((p1[4])<<8)+ p1[5], |
| 5628 | ((p2[0])<<24)+((p2[1])<<16)+((p2[2])<<8)+(p2[3]), |
| 5629 | ((p2[4])<<8)+ p2[5]); |
| 5630 | |
| 5631 | APPL_TRACE_DEBUG3("BTA_GATTC_OPEN_EVT conn_id = %d client_if=%d status = %d" , |
| 5632 | p_data->conn_id, |
| 5633 | p_data->client_if, |
| 5634 | p_data->status); |
| 5635 | |
| 5636 | bta_dm_search_cb.conn_id = p_data->conn_id; |
| 5637 | |
| 5638 | if (p_data->status == BTA_GATT_OK) |
| 5639 | { |
| 5640 | btm_dm_start_disc_gatt_services(p_data->conn_id); |
| 5641 | } |
| 5642 | else |
| 5643 | { |
| 5644 | bta_dm_gatt_disc_complete(BTA_GATT_INVALID_CONN_ID, p_data->status); |
| 5645 | } |
| 5646 | } |
| 5647 | |
| 5648 | /******************************************************************************* |
| 5649 | ** |
| 5650 | ** Function bta_dm_gattc_callback |
| 5651 | ** |
| 5652 | ** Description This is GATT client callback function used in DM. |
| 5653 | ** |
| 5654 | ** Parameters: |
| 5655 | ** |
| 5656 | *******************************************************************************/ |
| 5657 | static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) |
| 5658 | { |
| 5659 | APPL_TRACE_DEBUG1("bta_dm_gattc_callback event = %d", event); |
| 5660 | |
| 5661 | switch (event) |
| 5662 | { |
| 5663 | case BTA_GATTC_REG_EVT: |
| 5664 | APPL_TRACE_DEBUG1("BTA_GATTC_REG_EVT client_if = %d", p_data->reg_oper.client_if); |
| 5665 | if (p_data->reg_oper.status == BTA_GATT_OK) |
| 5666 | bta_dm_search_cb.client_if = p_data->reg_oper.client_if; |
| 5667 | else |
| 5668 | bta_dm_search_cb.client_if = BTA_GATTS_INVALID_IF; |
| 5669 | break; |
| 5670 | |
| 5671 | case BTA_GATTC_OPEN_EVT: |
| 5672 | bta_dm_proc_open_evt(&p_data->open); |
| 5673 | break; |
| 5674 | |
| 5675 | case BTA_GATTC_SEARCH_RES_EVT: |
| 5676 | bta_dm_gatt_disc_result(p_data->srvc_res.service_uuid.id); |
| 5677 | break; |
| 5678 | |
| 5679 | case BTA_GATTC_SEARCH_CMPL_EVT: |
| 5680 | if ( bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE) |
| 5681 | bta_dm_gatt_disc_complete(p_data->search_cmpl.conn_id, p_data->search_cmpl.status); |
| 5682 | break; |
| 5683 | |
| 5684 | case BTA_GATTC_CLOSE_EVT: |
| 5685 | APPL_TRACE_DEBUG1("BTA_GATTC_CLOSE_EVT reason = %d", p_data->close.reason); |
| 5686 | /* in case of disconnect before search is completed */ |
| 5687 | if ( (bta_dm_search_cb.state != BTA_DM_SEARCH_IDLE) && |
| 5688 | !memcmp(p_data->close.remote_bda, bta_dm_search_cb.peer_bdaddr, BD_ADDR_LEN)) |
| 5689 | { |
| 5690 | bta_dm_gatt_disc_complete((UINT16)BTA_GATT_INVALID_CONN_ID, (tBTA_GATT_STATUS) BTA_GATT_ERROR); |
| 5691 | } |
| 5692 | break; |
| 5693 | |
| 5694 | default: |
| 5695 | break; |
| 5696 | } |
| 5697 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 5698 | #endif /* BTA_GATT_INCLUDED */ |
Andre Eisenbach | b203d47 | 2013-11-20 17:23:06 -0800 | [diff] [blame] | 5699 | |
| 5700 | #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE |
| 5701 | /******************************************************************************* |
| 5702 | ** |
| 5703 | ** Function bta_dm_enable_scan_filter |
| 5704 | ** |
| 5705 | ** Description This function enable/disable adv payload filtering condition |
| 5706 | ** |
| 5707 | ** Parameters: |
| 5708 | ** |
| 5709 | *******************************************************************************/ |
| 5710 | void bta_dm_enable_scan_filter (tBTA_DM_MSG *p_data) |
| 5711 | { |
| 5712 | tBTA_SYS_VS_BLE_SCAN_PF_ENABLE param; |
| 5713 | |
| 5714 | param.enable = p_data->ble_enable_scan_filter.enable; |
| 5715 | param.p_target = p_data->ble_enable_scan_filter.p_target; |
| 5716 | param.p_cmpl_cback = p_data->ble_enable_scan_filter.p_cmpl_cback; |
| 5717 | |
| 5718 | bta_sys_vs_hdl(BTA_VS_BLE_SCAN_PF_ENABLE_EVT, (void *)¶m); |
| 5719 | } |
| 5720 | |
| 5721 | /******************************************************************************* |
| 5722 | ** |
| 5723 | ** Function bta_dm_cfg_filter_cond |
| 5724 | ** |
| 5725 | ** Description This function configure adv payload filtering condition |
| 5726 | ** |
| 5727 | ** Parameters: |
| 5728 | ** |
| 5729 | *******************************************************************************/ |
| 5730 | void bta_dm_cfg_filter_cond (tBTA_DM_MSG *p_data) |
| 5731 | { |
| 5732 | tBTA_SYS_VS_BLE_SCAN_PF_COND param; |
| 5733 | |
| 5734 | param.action = p_data->ble_cfg_filter_cond.action; |
| 5735 | param.cond_type = p_data->ble_cfg_filter_cond.cond_type; |
| 5736 | param.p_cond = (void *)p_data->ble_cfg_filter_cond.p_cond_param; |
| 5737 | param.p_cmpl_cback = p_data->ble_cfg_filter_cond.p_cmpl_cback; |
| 5738 | |
| 5739 | bta_sys_vs_hdl(BTA_VS_BLE_SCAN_PF_COND_EVT, (void *)¶m); |
| 5740 | } |
| 5741 | #endif /* BLE_ANDROID_CONTROLLER_SCAN_FILTER */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 5742 | #endif /* BLE_INCLUDED */ |