The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 2009-2012 Broadcom Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
| 19 | /************************************************************************************ |
| 20 | * |
| 21 | * Filename: btif_dm.c |
| 22 | * |
| 23 | * Description: Contains Device Management (DM) related functionality |
| 24 | * |
| 25 | * |
| 26 | ***********************************************************************************/ |
| 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <unistd.h> |
| 30 | |
| 31 | #include <hardware/bluetooth.h> |
| 32 | |
| 33 | #include <utils/Log.h> |
| 34 | #include <cutils/properties.h> |
| 35 | #include "gki.h" |
| 36 | #include "btu.h" |
| 37 | #include "bd.h" |
| 38 | #include "bta_api.h" |
| 39 | #include "btif_api.h" |
| 40 | #include "btif_util.h" |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 41 | #include "btif_dm.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 42 | #include "btif_storage.h" |
| 43 | #include "btif_hh.h" |
| 44 | #include "btif_config.h" |
| 45 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 46 | #include "bta_gatt_api.h" |
Andre Eisenbach | 31a6400 | 2014-10-14 14:29:19 -0700 | [diff] [blame] | 47 | |
| 48 | /****************************************************************************** |
| 49 | ** Device specific workarounds |
| 50 | ******************************************************************************/ |
| 51 | |
| 52 | /** |
| 53 | * The devices below have proven problematic during the pairing process, often |
| 54 | * requiring multiple retries to complete pairing. To avoid degrading the user |
| 55 | * experience for other devices, explicitely blacklist troubled devices here. |
| 56 | */ |
| 57 | static const UINT8 blacklist_pairing_retries[][3] = { |
| 58 | {0x9C, 0xDF, 0x03} // BMW car kits (Harman/Becker) |
| 59 | }; |
| 60 | |
| 61 | BOOLEAN blacklistPairingRetries(BD_ADDR bd_addr) |
| 62 | { |
| 63 | const unsigned blacklist_size = sizeof(blacklist_pairing_retries) |
| 64 | / sizeof(blacklist_pairing_retries[0]); |
| 65 | for (unsigned i = 0; i != blacklist_size; ++i) |
| 66 | { |
| 67 | if (blacklist_pairing_retries[i][0] == bd_addr[0] && |
| 68 | blacklist_pairing_retries[i][1] == bd_addr[1] && |
| 69 | blacklist_pairing_retries[i][2] == bd_addr[2]) |
| 70 | return TRUE; |
| 71 | } |
| 72 | return FALSE; |
| 73 | } |
| 74 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 75 | /****************************************************************************** |
| 76 | ** Constants & Macros |
| 77 | ******************************************************************************/ |
| 78 | |
| 79 | #define COD_UNCLASSIFIED ((0x1F) << 8) |
Priti Aghera | ebb1d75 | 2012-11-27 18:03:22 -0800 | [diff] [blame] | 80 | #define COD_HID_KEYBOARD 0x0540 |
| 81 | #define COD_HID_POINTING 0x0580 |
| 82 | #define COD_HID_COMBO 0x05C0 |
| 83 | #define COD_HID_MAJOR 0x0500 |
| 84 | #define COD_AV_HEADSETS 0x0404 |
| 85 | #define COD_AV_HANDSFREE 0x0408 |
| 86 | #define COD_AV_HEADPHONES 0x0418 |
| 87 | #define COD_AV_PORTABLE_AUDIO 0x041C |
| 88 | #define COD_AV_HIFI_AUDIO 0x0428 |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 89 | |
| 90 | |
| 91 | #define BTIF_DM_DEFAULT_INQ_MAX_RESULTS 0 |
| 92 | #define BTIF_DM_DEFAULT_INQ_MAX_DURATION 10 |
Ganesh Ganapathi Batta | ec7e2c8 | 2013-06-20 11:00:28 -0700 | [diff] [blame] | 93 | #define BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING 2 |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 94 | |
Andre Eisenbach | 31a6400 | 2014-10-14 14:29:19 -0700 | [diff] [blame] | 95 | #define NUM_TIMEOUT_RETRIES 5 |
| 96 | |
Matthew Xie | 1e5109b | 2012-11-09 18:26:26 -0800 | [diff] [blame] | 97 | #define PROPERTY_PRODUCT_MODEL "ro.product.model" |
Matthew Xie | a30d95a | 2013-09-18 12:30:36 -0700 | [diff] [blame] | 98 | #define DEFAULT_LOCAL_NAME_MAX 31 |
Matthew Xie | 1e5109b | 2012-11-09 18:26:26 -0800 | [diff] [blame] | 99 | #if (DEFAULT_LOCAL_NAME_MAX > BTM_MAX_LOC_BD_NAME_LEN) |
| 100 | #error "default btif local name size exceeds stack supported length" |
| 101 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 102 | |
Matthew Xie | 7f3e429 | 2013-09-30 12:44:10 -0700 | [diff] [blame] | 103 | #if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE) |
| 104 | #define BTIF_DM_INTERLEAVE_DURATION_BR_ONE 2 |
| 105 | #define BTIF_DM_INTERLEAVE_DURATION_LE_ONE 2 |
| 106 | #define BTIF_DM_INTERLEAVE_DURATION_BR_TWO 3 |
| 107 | #define BTIF_DM_INTERLEAVE_DURATION_LE_TWO 4 |
| 108 | #endif |
| 109 | |
Priti Aghera | c0edf9f | 2014-06-26 11:23:51 -0700 | [diff] [blame] | 110 | #define MAX_SDP_BL_ENTRIES 3 |
| 111 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 112 | typedef struct |
| 113 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 114 | bt_bond_state_t state; |
| 115 | BD_ADDR bd_addr; |
| 116 | UINT8 is_temp; |
| 117 | UINT8 pin_code_len; |
| 118 | UINT8 is_ssp; |
Ganesh Ganapathi Batta | a217ab9 | 2014-04-28 16:30:55 -0700 | [diff] [blame] | 119 | UINT8 auth_req; |
| 120 | UINT8 io_cap; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 121 | UINT8 autopair_attempts; |
Andre Eisenbach | 31a6400 | 2014-10-14 14:29:19 -0700 | [diff] [blame] | 122 | UINT8 timeout_retries; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 123 | UINT8 is_local_initiated; |
Ganesh Ganapathi Batta | ec7e2c8 | 2013-06-20 11:00:28 -0700 | [diff] [blame] | 124 | UINT8 sdp_attempts; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 125 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
| 126 | BOOLEAN is_le_only; |
| 127 | btif_dm_ble_cb_t ble; |
| 128 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 129 | } btif_dm_pairing_cb_t; |
| 130 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 131 | |
| 132 | typedef struct |
| 133 | { |
| 134 | UINT8 ir[BT_OCTET16_LEN]; |
| 135 | UINT8 irk[BT_OCTET16_LEN]; |
| 136 | UINT8 dhk[BT_OCTET16_LEN]; |
| 137 | }btif_dm_local_key_id_t; |
| 138 | |
| 139 | typedef struct |
| 140 | { |
| 141 | BOOLEAN is_er_rcvd; |
| 142 | UINT8 er[BT_OCTET16_LEN]; |
| 143 | BOOLEAN is_id_keys_rcvd; |
| 144 | btif_dm_local_key_id_t id_keys; /* ID kyes */ |
| 145 | |
| 146 | }btif_dm_local_key_cb_t; |
| 147 | |
| 148 | typedef struct |
| 149 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 150 | BD_ADDR bd_addr; |
| 151 | BD_NAME bd_name; |
| 152 | } btif_dm_remote_name_t; |
| 153 | |
| 154 | typedef struct |
| 155 | { |
| 156 | BT_OCTET16 sp_c; |
| 157 | BT_OCTET16 sp_r; |
| 158 | BD_ADDR oob_bdaddr; /* peer bdaddr*/ |
| 159 | } btif_dm_oob_cb_t; |
Satya Calloji | e5ba884 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 160 | |
| 161 | typedef struct |
| 162 | { |
Andre Eisenbach | b0daa5d | 2014-08-04 17:50:10 -0700 | [diff] [blame] | 163 | bt_bdaddr_t bdaddr; |
| 164 | UINT8 transport; /* 0=Unknown, 1=BR/EDR, 2=LE */ |
| 165 | } btif_dm_create_bond_cb_t; |
| 166 | |
| 167 | typedef struct |
| 168 | { |
Satya Calloji | e5ba884 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 169 | uint8_t status; |
| 170 | uint8_t ctrl_state; |
| 171 | uint64_t tx_time; |
| 172 | uint64_t rx_time; |
| 173 | uint64_t idle_time; |
| 174 | uint64_t energy_used; |
| 175 | } btif_activity_energy_info_cb_t; |
| 176 | |
Priti Aghera | c0edf9f | 2014-06-26 11:23:51 -0700 | [diff] [blame] | 177 | typedef struct |
| 178 | { |
| 179 | unsigned int manufact_id; |
| 180 | }skip_sdp_entry_t; |
| 181 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 182 | #define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id)) |
| 183 | |
Priti Aghera | c0edf9f | 2014-06-26 11:23:51 -0700 | [diff] [blame] | 184 | #define MAX_SDP_BL_ENTRIES 3 |
| 185 | #define UUID_HUMAN_INTERFACE_DEVICE "00001124-0000-1000-8000-00805f9b34fb" |
| 186 | |
| 187 | static skip_sdp_entry_t sdp_blacklist[] = {{76}}; //Apple Mouse and Keyboard |
| 188 | |
| 189 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 190 | /* This flag will be true if HCI_Inquiry is in progress */ |
| 191 | static BOOLEAN btif_dm_inquiry_in_progress = FALSE; |
| 192 | |
Priti Aghera | c0edf9f | 2014-06-26 11:23:51 -0700 | [diff] [blame] | 193 | |
| 194 | |
Matthew Xie | 1e5109b | 2012-11-09 18:26:26 -0800 | [diff] [blame] | 195 | /************************************************************************************ |
| 196 | ** Static variables |
| 197 | ************************************************************************************/ |
| 198 | static char btif_default_local_name[DEFAULT_LOCAL_NAME_MAX+1] = {'\0'}; |
| 199 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 200 | /****************************************************************************** |
| 201 | ** Static functions |
| 202 | ******************************************************************************/ |
| 203 | static btif_dm_pairing_cb_t pairing_cb; |
| 204 | static btif_dm_oob_cb_t oob_cb; |
| 205 | static void btif_dm_generic_evt(UINT16 event, char* p_param); |
Andre Eisenbach | b0daa5d | 2014-08-04 17:50:10 -0700 | [diff] [blame] | 206 | static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr, tBTA_TRANSPORT transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 207 | static void btif_dm_cb_hid_remote_name(tBTM_REMOTE_DEV_NAME *p_remote_name); |
| 208 | static void btif_update_remote_properties(BD_ADDR bd_addr, BD_NAME bd_name, |
| 209 | DEV_CLASS dev_class, tBT_DEVICE_TYPE dev_type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 210 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
| 211 | static btif_dm_local_key_cb_t ble_local_key_cb; |
| 212 | static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif); |
| 213 | static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl); |
| 214 | static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ *p_pin_req); |
| 215 | #endif |
Satya Calloji | 6e2d9db | 2014-07-08 16:18:58 -0700 | [diff] [blame] | 216 | |
| 217 | static void bte_scan_filt_param_cfg_evt(UINT8 action_type, |
| 218 | tBTA_DM_BLE_PF_AVBL_SPACE avbl_space, |
| 219 | tBTA_DM_BLE_REF_VALUE ref_value, tBTA_STATUS status); |
| 220 | |
Matthew Xie | 1e5109b | 2012-11-09 18:26:26 -0800 | [diff] [blame] | 221 | static char* btif_get_default_local_name(); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 222 | /****************************************************************************** |
| 223 | ** Externs |
| 224 | ******************************************************************************/ |
| 225 | extern UINT16 bta_service_id_to_uuid_lkup_tbl [BTA_MAX_SERVICE_ID]; |
| 226 | extern bt_status_t btif_hf_execute_service(BOOLEAN b_enable); |
| 227 | extern bt_status_t btif_av_execute_service(BOOLEAN b_enable); |
| 228 | extern bt_status_t btif_hh_execute_service(BOOLEAN b_enable); |
Hemant Gupta | 1025687 | 2013-08-19 18:33:01 +0530 | [diff] [blame] | 229 | extern bt_status_t btif_hf_client_execute_service(BOOLEAN b_enable); |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 230 | extern bt_status_t btif_mce_execute_service(BOOLEAN b_enable); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 231 | extern int btif_hh_connect(bt_bdaddr_t *bd_addr); |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 232 | extern void bta_gatt_convert_uuid16_to_uuid128(UINT8 uuid_128[LEN_UUID_128], UINT16 uuid_16); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 233 | |
| 234 | |
| 235 | /****************************************************************************** |
| 236 | ** Functions |
| 237 | ******************************************************************************/ |
| 238 | |
| 239 | bt_status_t btif_in_execute_service_request(tBTA_SERVICE_ID service_id, |
| 240 | BOOLEAN b_enable) |
| 241 | { |
| 242 | /* Check the service_ID and invoke the profile's BT state changed API */ |
| 243 | switch (service_id) |
| 244 | { |
| 245 | case BTA_HFP_SERVICE_ID: |
| 246 | case BTA_HSP_SERVICE_ID: |
| 247 | { |
| 248 | btif_hf_execute_service(b_enable); |
| 249 | }break; |
| 250 | case BTA_A2DP_SERVICE_ID: |
| 251 | { |
| 252 | btif_av_execute_service(b_enable); |
| 253 | }break; |
| 254 | case BTA_HID_SERVICE_ID: |
| 255 | { |
| 256 | btif_hh_execute_service(b_enable); |
| 257 | }break; |
Hemant Gupta | 1025687 | 2013-08-19 18:33:01 +0530 | [diff] [blame] | 258 | case BTA_HFP_HS_SERVICE_ID: |
| 259 | { |
| 260 | btif_hf_client_execute_service(b_enable); |
| 261 | }break; |
Hemant Gupta | 2dc9999 | 2014-04-18 12:54:08 +0530 | [diff] [blame] | 262 | case BTA_MAP_SERVICE_ID: |
| 263 | { |
| 264 | btif_mce_execute_service(b_enable); |
| 265 | }break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 266 | default: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 267 | BTIF_TRACE_ERROR("%s: Unknown service being enabled", __FUNCTION__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 268 | return BT_STATUS_FAIL; |
| 269 | } |
| 270 | return BT_STATUS_SUCCESS; |
| 271 | } |
| 272 | |
| 273 | /******************************************************************************* |
| 274 | ** |
| 275 | ** Function check_eir_remote_name |
| 276 | ** |
| 277 | ** Description Check if remote name is in the EIR data |
| 278 | ** |
| 279 | ** Returns TRUE if remote name found |
| 280 | ** Populate p_remote_name, if provided and remote name found |
| 281 | ** |
| 282 | *******************************************************************************/ |
| 283 | static BOOLEAN check_eir_remote_name(tBTA_DM_SEARCH *p_search_data, |
| 284 | UINT8 *p_remote_name, UINT8 *p_remote_name_len) |
| 285 | { |
| 286 | UINT8 *p_eir_remote_name = NULL; |
| 287 | UINT8 remote_name_len = 0; |
| 288 | |
| 289 | /* Check EIR for remote name and services */ |
| 290 | if (p_search_data->inq_res.p_eir) |
| 291 | { |
| 292 | p_eir_remote_name = BTA_CheckEirData(p_search_data->inq_res.p_eir, |
| 293 | BTM_EIR_COMPLETE_LOCAL_NAME_TYPE, &remote_name_len); |
| 294 | if (!p_eir_remote_name) |
| 295 | { |
| 296 | p_eir_remote_name = BTA_CheckEirData(p_search_data->inq_res.p_eir, |
| 297 | BTM_EIR_SHORTENED_LOCAL_NAME_TYPE, &remote_name_len); |
| 298 | } |
| 299 | |
| 300 | if (p_eir_remote_name) |
| 301 | { |
| 302 | if (remote_name_len > BD_NAME_LEN) |
| 303 | remote_name_len = BD_NAME_LEN; |
| 304 | |
| 305 | if (p_remote_name && p_remote_name_len) |
| 306 | { |
| 307 | memcpy(p_remote_name, p_eir_remote_name, remote_name_len); |
| 308 | *(p_remote_name + remote_name_len) = 0; |
| 309 | *p_remote_name_len = remote_name_len; |
| 310 | } |
| 311 | |
| 312 | return TRUE; |
| 313 | } |
| 314 | } |
| 315 | |
| 316 | return FALSE; |
| 317 | |
| 318 | } |
| 319 | |
| 320 | /******************************************************************************* |
| 321 | ** |
| 322 | ** Function check_cached_remote_name |
| 323 | ** |
| 324 | ** Description Check if remote name is in the NVRAM cache |
| 325 | ** |
| 326 | ** Returns TRUE if remote name found |
| 327 | ** Populate p_remote_name, if provided and remote name found |
| 328 | ** |
| 329 | *******************************************************************************/ |
| 330 | static BOOLEAN check_cached_remote_name(tBTA_DM_SEARCH *p_search_data, |
| 331 | UINT8 *p_remote_name, UINT8 *p_remote_name_len) |
| 332 | { |
| 333 | bt_bdname_t bdname; |
| 334 | bt_bdaddr_t remote_bdaddr; |
| 335 | bt_property_t prop_name; |
| 336 | |
| 337 | /* check if we already have it in our btif_storage cache */ |
| 338 | bdcpy(remote_bdaddr.address, p_search_data->inq_res.bd_addr); |
| 339 | BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_BDNAME, |
| 340 | sizeof(bt_bdname_t), &bdname); |
| 341 | if (btif_storage_get_remote_device_property( |
| 342 | &remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS) |
| 343 | { |
| 344 | if (p_remote_name && p_remote_name_len) |
| 345 | { |
| 346 | strcpy((char *)p_remote_name, (char *)bdname.name); |
| 347 | *p_remote_name_len = strlen((char *)p_remote_name); |
| 348 | } |
| 349 | return TRUE; |
| 350 | } |
| 351 | |
| 352 | return FALSE; |
| 353 | } |
| 354 | |
| 355 | BOOLEAN check_cod(const bt_bdaddr_t *remote_bdaddr, uint32_t cod) |
| 356 | { |
| 357 | uint32_t remote_cod; |
| 358 | bt_property_t prop_name; |
| 359 | |
| 360 | /* check if we already have it in our btif_storage cache */ |
| 361 | BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE, |
| 362 | sizeof(uint32_t), &remote_cod); |
| 363 | if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr, &prop_name) == BT_STATUS_SUCCESS) |
| 364 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 365 | BTIF_TRACE_ERROR("%s: remote_cod = 0x%06x", __FUNCTION__, remote_cod); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 366 | if ((remote_cod & 0x7ff) == cod) |
| 367 | return TRUE; |
| 368 | } |
| 369 | |
| 370 | return FALSE; |
| 371 | } |
| 372 | |
Priti Aghera | ebb1d75 | 2012-11-27 18:03:22 -0800 | [diff] [blame] | 373 | BOOLEAN check_cod_hid(const bt_bdaddr_t *remote_bdaddr, uint32_t cod) |
| 374 | { |
| 375 | uint32_t remote_cod; |
| 376 | bt_property_t prop_name; |
| 377 | |
| 378 | /* check if we already have it in our btif_storage cache */ |
| 379 | BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE, |
| 380 | sizeof(uint32_t), &remote_cod); |
| 381 | if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr, |
| 382 | &prop_name) == BT_STATUS_SUCCESS) |
| 383 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 384 | BTIF_TRACE_DEBUG("%s: remote_cod = 0x%06x", __FUNCTION__, remote_cod); |
Priti Aghera | ebb1d75 | 2012-11-27 18:03:22 -0800 | [diff] [blame] | 385 | if ((remote_cod & 0x700) == cod) |
| 386 | return TRUE; |
| 387 | } |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 388 | return FALSE; |
| 389 | } |
Priti Aghera | ebb1d75 | 2012-11-27 18:03:22 -0800 | [diff] [blame] | 390 | |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 391 | BOOLEAN check_hid_le(const bt_bdaddr_t *remote_bdaddr) |
| 392 | { |
| 393 | uint32_t remote_dev_type; |
| 394 | bt_property_t prop_name; |
| 395 | |
| 396 | /* check if we already have it in our btif_storage cache */ |
| 397 | BTIF_STORAGE_FILL_PROPERTY(&prop_name,BT_PROPERTY_TYPE_OF_DEVICE, |
| 398 | sizeof(uint32_t), &remote_dev_type); |
| 399 | if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr, |
| 400 | &prop_name) == BT_STATUS_SUCCESS) |
| 401 | { |
| 402 | if (remote_dev_type == BT_DEVICE_DEVTYPE_BLE) |
| 403 | { |
| 404 | bdstr_t bdstr; |
| 405 | bd2str(remote_bdaddr, &bdstr); |
| 406 | if(btif_config_exist("Remote", bdstr, "HidAppId")) |
| 407 | return TRUE; |
| 408 | } |
| 409 | } |
Priti Aghera | ebb1d75 | 2012-11-27 18:03:22 -0800 | [diff] [blame] | 410 | return FALSE; |
| 411 | } |
| 412 | |
Priti Aghera | c0edf9f | 2014-06-26 11:23:51 -0700 | [diff] [blame] | 413 | /***************************************************************************** |
| 414 | ** |
| 415 | ** Function check_sdp_bl |
| 416 | ** |
| 417 | ** Description Checks if a given device is blacklisted to skip sdp |
| 418 | ** |
| 419 | ** Parameters skip_sdp_entry |
| 420 | ** |
| 421 | ** Returns TRUE if the device is present in blacklist, else FALSE |
| 422 | ** |
| 423 | *******************************************************************************/ |
| 424 | BOOLEAN check_sdp_bl(const bt_bdaddr_t *remote_bdaddr) |
| 425 | { |
| 426 | UINT8 i = 0; |
| 427 | UINT16 manufacturer = 0; |
| 428 | UINT8 lmp_ver = 0; |
| 429 | UINT16 lmp_subver = 0; |
| 430 | tBTM_STATUS btm_status; |
| 431 | bt_property_t prop_name; |
| 432 | bt_remote_version_t info; |
| 433 | bt_status_t status; |
| 434 | |
| 435 | |
| 436 | if (remote_bdaddr == NULL) |
| 437 | return FALSE; |
| 438 | |
| 439 | /* fetch additional info about remote device used in iop query */ |
| 440 | btm_status = BTM_ReadRemoteVersion(*(BD_ADDR*)remote_bdaddr, &lmp_ver, |
| 441 | &manufacturer, &lmp_subver); |
| 442 | |
| 443 | |
| 444 | |
| 445 | /* if not available yet, try fetching from config database */ |
| 446 | BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_REMOTE_VERSION_INFO, |
| 447 | sizeof(bt_remote_version_t), &info); |
| 448 | |
| 449 | if (btif_storage_get_remote_device_property((bt_bdaddr_t *)remote_bdaddr, |
| 450 | &prop_name) != BT_STATUS_SUCCESS) |
| 451 | { |
| 452 | |
| 453 | return FALSE; |
| 454 | } |
| 455 | manufacturer = info.manufacturer; |
| 456 | |
| 457 | for (int i = 0; i < MAX_SDP_BL_ENTRIES; i++) |
| 458 | { |
| 459 | if (manufacturer == sdp_blacklist[i].manufact_id) |
| 460 | return TRUE; |
| 461 | } |
| 462 | return FALSE; |
| 463 | } |
| 464 | |
| 465 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 466 | static void bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr, bt_bond_state_t state) |
| 467 | { |
| 468 | /* Send bonding state only once - based on outgoing/incoming we may receive duplicates */ |
| 469 | if ( (pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING) ) |
| 470 | return; |
| 471 | |
| 472 | if (pairing_cb.is_temp) |
| 473 | { |
| 474 | state = BT_BOND_STATE_NONE; |
| 475 | } |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 476 | BTIF_TRACE_DEBUG("%s: state=%d prev_state=%d", __FUNCTION__, state, pairing_cb.state); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 477 | |
| 478 | HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state); |
| 479 | |
| 480 | if (state == BT_BOND_STATE_BONDING) |
| 481 | { |
| 482 | pairing_cb.state = state; |
| 483 | bdcpy(pairing_cb.bd_addr, bd_addr->address); |
| 484 | } |
| 485 | else |
| 486 | { |
| 487 | memset(&pairing_cb, 0, sizeof(pairing_cb)); |
| 488 | } |
| 489 | |
| 490 | } |
| 491 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 492 | /* store remote version in bt config to always have access |
| 493 | to it post pairing*/ |
| 494 | static void btif_update_remote_version_property(bt_bdaddr_t *p_bd) |
| 495 | { |
| 496 | bt_property_t property; |
| 497 | UINT8 lmp_ver = 0; |
| 498 | UINT16 lmp_subver = 0; |
| 499 | UINT16 mfct_set = 0; |
| 500 | tBTM_STATUS btm_status; |
| 501 | bt_remote_version_t info; |
| 502 | bt_status_t status; |
| 503 | bdstr_t bdstr; |
| 504 | |
| 505 | btm_status = BTM_ReadRemoteVersion(*(BD_ADDR*)p_bd, &lmp_ver, |
| 506 | &mfct_set, &lmp_subver); |
| 507 | |
| 508 | ALOGD("remote version info [%s]: %x, %x, %x", bd2str(p_bd, &bdstr), |
| 509 | lmp_ver, mfct_set, lmp_subver); |
| 510 | |
| 511 | if (btm_status == BTM_SUCCESS) |
| 512 | { |
| 513 | /* always update cache to ensure we have availability whenever BTM API |
| 514 | is not populated */ |
| 515 | info.manufacturer = mfct_set; |
| 516 | info.sub_ver = lmp_subver; |
| 517 | info.version = lmp_ver; |
| 518 | BTIF_STORAGE_FILL_PROPERTY(&property, |
| 519 | BT_PROPERTY_REMOTE_VERSION_INFO, sizeof(bt_remote_version_t), |
| 520 | &info); |
| 521 | status = btif_storage_set_remote_device_property(p_bd, &property); |
| 522 | ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote version", status); |
| 523 | } |
| 524 | } |
| 525 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 526 | |
| 527 | static void btif_update_remote_properties(BD_ADDR bd_addr, BD_NAME bd_name, |
| 528 | DEV_CLASS dev_class, tBT_DEVICE_TYPE device_type) |
| 529 | { |
| 530 | int num_properties = 0; |
| 531 | bt_property_t properties[3]; |
| 532 | bt_bdaddr_t bdaddr; |
| 533 | bt_status_t status; |
| 534 | UINT32 cod; |
| 535 | bt_device_type_t dev_type; |
| 536 | |
| 537 | memset(properties, 0, sizeof(properties)); |
| 538 | bdcpy(bdaddr.address, bd_addr); |
| 539 | |
| 540 | /* remote name */ |
| 541 | if (strlen((const char *) bd_name)) |
| 542 | { |
| 543 | BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], |
| 544 | BT_PROPERTY_BDNAME, strlen((char *)bd_name), bd_name); |
| 545 | status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]); |
| 546 | ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device name", status); |
| 547 | num_properties++; |
| 548 | } |
| 549 | |
| 550 | /* class of device */ |
| 551 | cod = devclass2uint(dev_class); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 552 | BTIF_TRACE_DEBUG("%s():cod is 0x%06x", __FUNCTION__, cod); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 553 | if ( cod == 0) { |
Hemant Gupta | 87b7cce | 2013-11-28 13:07:10 +0530 | [diff] [blame] | 554 | /* Try to retrieve cod from storage */ |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 555 | BTIF_TRACE_DEBUG("%s():cod is 0, checking cod from storage", __FUNCTION__); |
Hemant Gupta | 87b7cce | 2013-11-28 13:07:10 +0530 | [diff] [blame] | 556 | BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], |
| 557 | BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod); |
| 558 | status = btif_storage_get_remote_device_property(&bdaddr, &properties[num_properties]); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 559 | BTIF_TRACE_DEBUG("%s():cod retreived from storage is 0x%06x", __FUNCTION__, cod); |
Hemant Gupta | 87b7cce | 2013-11-28 13:07:10 +0530 | [diff] [blame] | 560 | if ( cod == 0) { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 561 | BTIF_TRACE_DEBUG("%s():cod is again 0, set as unclassified", __FUNCTION__); |
Hemant Gupta | 87b7cce | 2013-11-28 13:07:10 +0530 | [diff] [blame] | 562 | cod = COD_UNCLASSIFIED; |
| 563 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], |
| 567 | BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod); |
| 568 | status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]); |
| 569 | ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device class", status); |
| 570 | num_properties++; |
| 571 | |
| 572 | /* device type */ |
| 573 | dev_type = device_type; |
| 574 | BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], |
| 575 | BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type); |
| 576 | status = btif_storage_set_remote_device_property(&bdaddr, &properties[num_properties]); |
| 577 | ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device type", status); |
| 578 | num_properties++; |
| 579 | |
| 580 | HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, |
| 581 | status, &bdaddr, num_properties, properties); |
| 582 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 583 | |
| 584 | /******************************************************************************* |
| 585 | ** |
| 586 | ** Function btif_dm_cb_hid_remote_name |
| 587 | ** |
| 588 | ** Description Remote name callback for HID device. Called in btif context |
| 589 | ** Special handling for HID devices |
| 590 | ** |
| 591 | ** Returns void |
| 592 | ** |
| 593 | *******************************************************************************/ |
| 594 | static void btif_dm_cb_hid_remote_name(tBTM_REMOTE_DEV_NAME *p_remote_name) |
| 595 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 596 | BTIF_TRACE_DEBUG("%s: status=%d pairing_cb.state=%d", __FUNCTION__, p_remote_name->status, pairing_cb.state); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 597 | if (pairing_cb.state == BT_BOND_STATE_BONDING) |
| 598 | { |
| 599 | bt_bdaddr_t remote_bd; |
| 600 | |
| 601 | bdcpy(remote_bd.address, pairing_cb.bd_addr); |
| 602 | |
| 603 | if (p_remote_name->status == BTM_SUCCESS) |
| 604 | { |
| 605 | bond_state_changed(BT_STATUS_SUCCESS, &remote_bd, BT_BOND_STATE_BONDED); |
| 606 | } |
| 607 | else |
| 608 | bond_state_changed(BT_STATUS_FAIL, &remote_bd, BT_BOND_STATE_NONE); |
| 609 | } |
| 610 | } |
| 611 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 612 | /******************************************************************************* |
| 613 | ** |
| 614 | ** Function btif_dm_cb_create_bond |
| 615 | ** |
| 616 | ** Description Create bond initiated from the BTIF thread context |
| 617 | ** Special handling for HID devices |
| 618 | ** |
| 619 | ** Returns void |
| 620 | ** |
| 621 | *******************************************************************************/ |
Andre Eisenbach | b0daa5d | 2014-08-04 17:50:10 -0700 | [diff] [blame] | 622 | static void btif_dm_cb_create_bond(bt_bdaddr_t *bd_addr, tBTA_TRANSPORT transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 623 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 624 | BOOLEAN is_hid = check_cod(bd_addr, COD_HID_POINTING); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 625 | bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 626 | |
Thomas.TT_Lin | 2772dac | 2014-07-18 12:10:59 +0800 | [diff] [blame] | 627 | #if BLE_INCLUDED == TRUE |
| 628 | int device_type; |
| 629 | int addr_type; |
| 630 | bdstr_t bdstr; |
| 631 | bd2str(bd_addr, &bdstr); |
Matthew Xie | 64c5479 | 2014-09-16 00:55:03 -0700 | [diff] [blame] | 632 | if (transport == BT_TRANSPORT_LE) |
| 633 | { |
| 634 | if (!btif_config_get_int("Remote", (char const *)&bdstr,"DevType", &device_type)) |
| 635 | { |
| 636 | btif_config_set_int("Remote", bdstr, "DevType", BT_DEVICE_TYPE_BLE); |
| 637 | } |
| 638 | if (btif_storage_get_remote_addr_type(bd_addr, &addr_type) != BT_STATUS_SUCCESS) |
| 639 | { |
| 640 | btif_storage_set_remote_addr_type(bd_addr, BLE_ADDR_PUBLIC); |
| 641 | } |
| 642 | } |
lungtsai_lin | 3baff79 | 2014-08-29 13:47:47 +0800 | [diff] [blame] | 643 | if((btif_config_get_int("Remote", (char const *)&bdstr,"DevType", &device_type) && |
Thomas.TT_Lin | 2772dac | 2014-07-18 12:10:59 +0800 | [diff] [blame] | 644 | (btif_storage_get_remote_addr_type(bd_addr, &addr_type) == BT_STATUS_SUCCESS) && |
lungtsai_lin | 3baff79 | 2014-08-29 13:47:47 +0800 | [diff] [blame] | 645 | (device_type == BT_DEVICE_TYPE_BLE)) || (transport == BT_TRANSPORT_LE)) |
Thomas.TT_Lin | 2772dac | 2014-07-18 12:10:59 +0800 | [diff] [blame] | 646 | { |
| 647 | BTA_DmAddBleDevice(bd_addr->address, addr_type, BT_DEVICE_TYPE_BLE); |
| 648 | } |
| 649 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 650 | |
Thomas.TT_Lin | 2772dac | 2014-07-18 12:10:59 +0800 | [diff] [blame] | 651 | #if BLE_INCLUDED == TRUE |
| 652 | if(is_hid && device_type != BT_DEVICE_TYPE_BLE) |
| 653 | #else |
| 654 | if(is_hid) |
| 655 | #endif |
| 656 | { |
| 657 | int status; |
| 658 | status = btif_hh_connect(bd_addr); |
| 659 | if(status != BT_STATUS_SUCCESS) |
| 660 | bond_state_changed(status, bd_addr, BT_BOND_STATE_NONE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 661 | } |
| 662 | else |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 663 | { |
Andre Eisenbach | b0daa5d | 2014-08-04 17:50:10 -0700 | [diff] [blame] | 664 | BTA_DmBondByTransport((UINT8 *)bd_addr->address, transport); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 665 | } |
| 666 | /* Track originator of bond creation */ |
| 667 | pairing_cb.is_local_initiated = TRUE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 668 | |
| 669 | } |
| 670 | |
| 671 | /******************************************************************************* |
| 672 | ** |
| 673 | ** Function btif_dm_cb_remove_bond |
| 674 | ** |
| 675 | ** Description remove bond initiated from the BTIF thread context |
| 676 | ** Special handling for HID devices |
| 677 | ** |
| 678 | ** Returns void |
| 679 | ** |
| 680 | *******************************************************************************/ |
| 681 | void btif_dm_cb_remove_bond(bt_bdaddr_t *bd_addr) |
| 682 | { |
| 683 | bdstr_t bdstr; |
| 684 | /*special handling for HID devices */ |
Ganesh Ganapathi Batta | 390c94d | 2013-05-15 17:58:35 -0700 | [diff] [blame] | 685 | /* VUP needs to be sent if its a HID Device. The HID HOST module will check if there |
| 686 | is a valid hid connection with this bd_addr. If yes VUP will be issued.*/ |
| 687 | #if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE)) |
| 688 | if (btif_hh_virtual_unplug(bd_addr) != BT_STATUS_SUCCESS) |
| 689 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 690 | { |
Ganesh Ganapathi Batta | 390c94d | 2013-05-15 17:58:35 -0700 | [diff] [blame] | 691 | BTA_DmRemoveDevice((UINT8 *)bd_addr->address); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | |
| 695 | /******************************************************************************* |
| 696 | ** |
Andre Eisenbach | 249f600 | 2014-06-18 12:20:37 -0700 | [diff] [blame] | 697 | ** Function btif_dm_get_connection_state |
| 698 | ** |
| 699 | ** Description Returns whether the remote device is currently connected |
| 700 | ** |
| 701 | ** Returns 0 if not connected |
| 702 | ** |
| 703 | *******************************************************************************/ |
| 704 | uint16_t btif_dm_get_connection_state(const bt_bdaddr_t *bd_addr) |
| 705 | { |
| 706 | return BTA_DmGetConnectionState((UINT8 *)bd_addr->address); |
| 707 | } |
| 708 | |
| 709 | /******************************************************************************* |
| 710 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 711 | ** Function search_devices_copy_cb |
| 712 | ** |
| 713 | ** Description Deep copy callback for search devices event |
| 714 | ** |
| 715 | ** Returns void |
| 716 | ** |
| 717 | *******************************************************************************/ |
| 718 | static void search_devices_copy_cb(UINT16 event, char *p_dest, char *p_src) |
| 719 | { |
| 720 | tBTA_DM_SEARCH *p_dest_data = (tBTA_DM_SEARCH *) p_dest; |
| 721 | tBTA_DM_SEARCH *p_src_data = (tBTA_DM_SEARCH *) p_src; |
| 722 | |
| 723 | if (!p_src) |
| 724 | return; |
| 725 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 726 | BTIF_TRACE_DEBUG("%s: event=%s", __FUNCTION__, dump_dm_search_event(event)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 727 | memcpy(p_dest_data, p_src_data, sizeof(tBTA_DM_SEARCH)); |
| 728 | switch (event) |
| 729 | { |
| 730 | case BTA_DM_INQ_RES_EVT: |
| 731 | { |
| 732 | if (p_src_data->inq_res.p_eir) |
| 733 | { |
| 734 | p_dest_data->inq_res.p_eir = (UINT8 *)(p_dest + sizeof(tBTA_DM_SEARCH)); |
| 735 | memcpy(p_dest_data->inq_res.p_eir, p_src_data->inq_res.p_eir, HCI_EXT_INQ_RESPONSE_LEN); |
| 736 | } |
| 737 | } |
| 738 | break; |
| 739 | |
| 740 | case BTA_DM_DISC_RES_EVT: |
| 741 | { |
| 742 | if (p_src_data->disc_res.raw_data_size && p_src_data->disc_res.p_raw_data) |
| 743 | { |
| 744 | p_dest_data->disc_res.p_raw_data = (UINT8 *)(p_dest + sizeof(tBTA_DM_SEARCH)); |
| 745 | memcpy(p_dest_data->disc_res.p_raw_data, |
| 746 | p_src_data->disc_res.p_raw_data, p_src_data->disc_res.raw_data_size); |
| 747 | } |
| 748 | } |
| 749 | break; |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | static void search_services_copy_cb(UINT16 event, char *p_dest, char *p_src) |
| 754 | { |
| 755 | tBTA_DM_SEARCH *p_dest_data = (tBTA_DM_SEARCH *) p_dest; |
| 756 | tBTA_DM_SEARCH *p_src_data = (tBTA_DM_SEARCH *) p_src; |
| 757 | |
| 758 | if (!p_src) |
| 759 | return; |
| 760 | memcpy(p_dest_data, p_src_data, sizeof(tBTA_DM_SEARCH)); |
| 761 | switch (event) |
| 762 | { |
| 763 | case BTA_DM_DISC_RES_EVT: |
| 764 | { |
Kausik Sinnaswamy | 95664a9 | 2013-05-03 15:02:50 +0530 | [diff] [blame] | 765 | if (p_src_data->disc_res.result == BTA_SUCCESS) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 766 | { |
Kausik Sinnaswamy | 95664a9 | 2013-05-03 15:02:50 +0530 | [diff] [blame] | 767 | if (p_src_data->disc_res.num_uuids > 0) |
| 768 | { |
| 769 | p_dest_data->disc_res.p_uuid_list = |
| 770 | (UINT8*)(p_dest + sizeof(tBTA_DM_SEARCH)); |
| 771 | memcpy(p_dest_data->disc_res.p_uuid_list, p_src_data->disc_res.p_uuid_list, |
| 772 | p_src_data->disc_res.num_uuids*MAX_UUID_SIZE); |
| 773 | GKI_freebuf(p_src_data->disc_res.p_uuid_list); |
| 774 | } |
| 775 | if (p_src_data->disc_res.p_raw_data != NULL) |
| 776 | { |
| 777 | GKI_freebuf(p_src_data->disc_res.p_raw_data); |
| 778 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 779 | } |
| 780 | } break; |
| 781 | } |
| 782 | } |
| 783 | /****************************************************************************** |
| 784 | ** |
| 785 | ** BTIF DM callback events |
| 786 | ** |
| 787 | *****************************************************************************/ |
| 788 | |
| 789 | /******************************************************************************* |
| 790 | ** |
| 791 | ** Function btif_dm_pin_req_evt |
| 792 | ** |
| 793 | ** Description Executes pin request event in btif context |
| 794 | ** |
| 795 | ** Returns void |
| 796 | ** |
| 797 | *******************************************************************************/ |
| 798 | static void btif_dm_pin_req_evt(tBTA_DM_PIN_REQ *p_pin_req) |
| 799 | { |
| 800 | bt_bdaddr_t bd_addr; |
| 801 | bt_bdname_t bd_name; |
| 802 | UINT32 cod; |
| 803 | bt_pin_code_t pin_code; |
Matthew Xie | 86f97ed | 2014-11-10 10:24:46 -0800 | [diff] [blame] | 804 | int dev_type; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 805 | |
| 806 | /* Remote properties update */ |
Matthew Xie | 86f97ed | 2014-11-10 10:24:46 -0800 | [diff] [blame] | 807 | if (!btif_get_device_type(p_pin_req->bd_addr, &dev_type)) |
| 808 | { |
| 809 | dev_type = BT_DEVICE_TYPE_BREDR; |
| 810 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 811 | btif_update_remote_properties(p_pin_req->bd_addr, p_pin_req->bd_name, |
Matthew Xie | 86f97ed | 2014-11-10 10:24:46 -0800 | [diff] [blame] | 812 | p_pin_req->dev_class, (tBT_DEVICE_TYPE) dev_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 813 | |
| 814 | bdcpy(bd_addr.address, p_pin_req->bd_addr); |
| 815 | memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN); |
| 816 | |
| 817 | bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING); |
| 818 | |
| 819 | cod = devclass2uint(p_pin_req->dev_class); |
| 820 | |
| 821 | if ( cod == 0) { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 822 | BTIF_TRACE_DEBUG("%s():cod is 0, set as unclassified", __FUNCTION__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 823 | cod = COD_UNCLASSIFIED; |
| 824 | } |
| 825 | |
| 826 | /* check for auto pair possiblity only if bond was initiated by local device */ |
| 827 | if (pairing_cb.is_local_initiated) |
| 828 | { |
| 829 | if (check_cod(&bd_addr, COD_AV_HEADSETS) || |
| 830 | check_cod(&bd_addr, COD_AV_HANDSFREE) || |
| 831 | check_cod(&bd_addr, COD_AV_HEADPHONES) || |
| 832 | check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) || |
| 833 | check_cod(&bd_addr, COD_AV_HIFI_AUDIO) || |
| 834 | check_cod(&bd_addr, COD_HID_POINTING)) |
| 835 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 836 | BTIF_TRACE_DEBUG("%s()cod matches for auto pair", __FUNCTION__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 837 | /* Check if this device can be auto paired */ |
| 838 | if ((btif_storage_is_device_autopair_blacklisted(&bd_addr) == FALSE) && |
| 839 | (pairing_cb.autopair_attempts == 0)) |
| 840 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 841 | BTIF_TRACE_DEBUG("%s() Attempting auto pair", __FUNCTION__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 842 | pin_code.pin[0] = 0x30; |
| 843 | pin_code.pin[1] = 0x30; |
| 844 | pin_code.pin[2] = 0x30; |
| 845 | pin_code.pin[3] = 0x30; |
| 846 | |
| 847 | pairing_cb.autopair_attempts++; |
| 848 | BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin); |
| 849 | return; |
| 850 | } |
| 851 | } |
| 852 | else if (check_cod(&bd_addr, COD_HID_KEYBOARD) || |
| 853 | check_cod(&bd_addr, COD_HID_COMBO)) |
| 854 | { |
| 855 | if(( btif_storage_is_fixed_pin_zeros_keyboard (&bd_addr) == TRUE) && |
| 856 | (pairing_cb.autopair_attempts == 0)) |
| 857 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 858 | BTIF_TRACE_DEBUG("%s() Attempting auto pair", __FUNCTION__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 859 | pin_code.pin[0] = 0x30; |
| 860 | pin_code.pin[1] = 0x30; |
| 861 | pin_code.pin[2] = 0x30; |
| 862 | pin_code.pin[3] = 0x30; |
| 863 | |
| 864 | pairing_cb.autopair_attempts++; |
| 865 | BTA_DmPinReply( (UINT8*)bd_addr.address, TRUE, 4, pin_code.pin); |
| 866 | return; |
| 867 | } |
| 868 | } |
| 869 | } |
| 870 | HAL_CBACK(bt_hal_cbacks, pin_request_cb, |
| 871 | &bd_addr, &bd_name, cod); |
| 872 | } |
| 873 | |
| 874 | /******************************************************************************* |
| 875 | ** |
| 876 | ** Function btif_dm_ssp_cfm_req_evt |
| 877 | ** |
| 878 | ** Description Executes SSP confirm request event in btif context |
| 879 | ** |
| 880 | ** Returns void |
| 881 | ** |
| 882 | *******************************************************************************/ |
| 883 | static void btif_dm_ssp_cfm_req_evt(tBTA_DM_SP_CFM_REQ *p_ssp_cfm_req) |
| 884 | { |
| 885 | bt_bdaddr_t bd_addr; |
| 886 | bt_bdname_t bd_name; |
| 887 | UINT32 cod; |
| 888 | BOOLEAN is_incoming = !(pairing_cb.state == BT_BOND_STATE_BONDING); |
Matthew Xie | 86f97ed | 2014-11-10 10:24:46 -0800 | [diff] [blame] | 889 | int dev_type; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 890 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 891 | BTIF_TRACE_DEBUG("%s", __FUNCTION__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 892 | |
| 893 | /* Remote properties update */ |
Matthew Xie | 86f97ed | 2014-11-10 10:24:46 -0800 | [diff] [blame] | 894 | if (!btif_get_device_type(p_ssp_cfm_req->bd_addr, &dev_type)) |
| 895 | { |
| 896 | dev_type = BT_DEVICE_TYPE_BREDR; |
| 897 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 898 | btif_update_remote_properties(p_ssp_cfm_req->bd_addr, p_ssp_cfm_req->bd_name, |
Matthew Xie | 86f97ed | 2014-11-10 10:24:46 -0800 | [diff] [blame] | 899 | p_ssp_cfm_req->dev_class, (tBT_DEVICE_TYPE) dev_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 900 | |
| 901 | bdcpy(bd_addr.address, p_ssp_cfm_req->bd_addr); |
| 902 | memcpy(bd_name.name, p_ssp_cfm_req->bd_name, BD_NAME_LEN); |
| 903 | |
| 904 | /* Set the pairing_cb based on the local & remote authentication requirements */ |
| 905 | bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING); |
| 906 | |
| 907 | /* if just_works and bonding bit is not set treat this as temporary */ |
| 908 | if (p_ssp_cfm_req->just_works && !(p_ssp_cfm_req->loc_auth_req & BTM_AUTH_BONDS) && |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 909 | !(p_ssp_cfm_req->rmt_auth_req & BTM_AUTH_BONDS) && |
| 910 | !(check_cod((bt_bdaddr_t*)&p_ssp_cfm_req->bd_addr, COD_HID_POINTING))) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 911 | pairing_cb.is_temp = TRUE; |
| 912 | else |
| 913 | pairing_cb.is_temp = FALSE; |
| 914 | |
| 915 | pairing_cb.is_ssp = TRUE; |
| 916 | |
| 917 | /* If JustWorks auto-accept */ |
| 918 | if (p_ssp_cfm_req->just_works) |
| 919 | { |
| 920 | /* Pairing consent for JustWorks needed if: |
| 921 | * 1. Incoming pairing is detected AND |
| 922 | * 2. local IO capabilities are DisplayYesNo AND |
| 923 | * 3. remote IO capabiltiies are DisplayOnly or NoInputNoOutput; |
| 924 | */ |
| 925 | if ((is_incoming) && ((p_ssp_cfm_req->loc_io_caps == 0x01) && |
| 926 | (p_ssp_cfm_req->rmt_io_caps == 0x00 || p_ssp_cfm_req->rmt_io_caps == 0x03))) |
| 927 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 928 | BTIF_TRACE_EVENT("%s: User consent needed for incoming pairing request. loc_io_caps: %d, rmt_io_caps: %d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 929 | __FUNCTION__, p_ssp_cfm_req->loc_io_caps, p_ssp_cfm_req->rmt_io_caps); |
| 930 | } |
| 931 | else |
| 932 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 933 | BTIF_TRACE_EVENT("%s: Auto-accept JustWorks pairing", __FUNCTION__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 934 | btif_dm_ssp_reply(&bd_addr, BT_SSP_VARIANT_CONSENT, TRUE, 0); |
| 935 | return; |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | cod = devclass2uint(p_ssp_cfm_req->dev_class); |
| 940 | |
| 941 | if ( cod == 0) { |
| 942 | ALOGD("cod is 0, set as unclassified"); |
| 943 | cod = COD_UNCLASSIFIED; |
| 944 | } |
| 945 | |
Ganesh Ganapathi Batta | ec7e2c8 | 2013-06-20 11:00:28 -0700 | [diff] [blame] | 946 | pairing_cb.sdp_attempts = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 947 | HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod, |
| 948 | (p_ssp_cfm_req->just_works ? BT_SSP_VARIANT_CONSENT : BT_SSP_VARIANT_PASSKEY_CONFIRMATION), |
| 949 | p_ssp_cfm_req->num_val); |
| 950 | } |
| 951 | |
| 952 | static void btif_dm_ssp_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif) |
| 953 | { |
| 954 | bt_bdaddr_t bd_addr; |
| 955 | bt_bdname_t bd_name; |
| 956 | UINT32 cod; |
Matthew Xie | 86f97ed | 2014-11-10 10:24:46 -0800 | [diff] [blame] | 957 | int dev_type; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 958 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 959 | BTIF_TRACE_DEBUG("%s", __FUNCTION__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 960 | |
| 961 | /* Remote properties update */ |
Matthew Xie | 86f97ed | 2014-11-10 10:24:46 -0800 | [diff] [blame] | 962 | if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type)) |
| 963 | { |
| 964 | dev_type = BT_DEVICE_TYPE_BREDR; |
| 965 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 966 | btif_update_remote_properties(p_ssp_key_notif->bd_addr, p_ssp_key_notif->bd_name, |
Matthew Xie | 86f97ed | 2014-11-10 10:24:46 -0800 | [diff] [blame] | 967 | p_ssp_key_notif->dev_class, (tBT_DEVICE_TYPE) dev_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 968 | |
| 969 | bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr); |
| 970 | memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN); |
| 971 | |
| 972 | bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING); |
| 973 | pairing_cb.is_ssp = TRUE; |
| 974 | cod = devclass2uint(p_ssp_key_notif->dev_class); |
| 975 | |
| 976 | if ( cod == 0) { |
| 977 | ALOGD("cod is 0, set as unclassified"); |
| 978 | cod = COD_UNCLASSIFIED; |
| 979 | } |
| 980 | |
| 981 | HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, |
| 982 | cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION, |
| 983 | p_ssp_key_notif->passkey); |
| 984 | } |
| 985 | /******************************************************************************* |
| 986 | ** |
| 987 | ** Function btif_dm_auth_cmpl_evt |
| 988 | ** |
| 989 | ** Description Executes authentication complete event in btif context |
| 990 | ** |
| 991 | ** Returns void |
| 992 | ** |
| 993 | *******************************************************************************/ |
| 994 | static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl) |
| 995 | { |
| 996 | /* Save link key, if not temporary */ |
| 997 | bt_bdaddr_t bd_addr; |
| 998 | bt_status_t status = BT_STATUS_FAIL; |
| 999 | bt_bond_state_t state = BT_BOND_STATE_NONE; |
Priti Aghera | c0edf9f | 2014-06-26 11:23:51 -0700 | [diff] [blame] | 1000 | BOOLEAN skip_sdp = FALSE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1001 | |
| 1002 | bdcpy(bd_addr.address, p_auth_cmpl->bd_addr); |
| 1003 | if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) ) |
| 1004 | { |
| 1005 | if ((p_auth_cmpl->key_type < HCI_LKEY_TYPE_DEBUG_COMB) || (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB) || |
| 1006 | (p_auth_cmpl->key_type == HCI_LKEY_TYPE_CHANGED_COMB) || (!pairing_cb.is_temp)) |
| 1007 | { |
| 1008 | bt_status_t ret; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1009 | BTIF_TRACE_DEBUG("%s: Storing link key. key_type=0x%x, is_temp=%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1010 | __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.is_temp); |
| 1011 | ret = btif_storage_add_bonded_device(&bd_addr, |
| 1012 | p_auth_cmpl->key, p_auth_cmpl->key_type, |
| 1013 | pairing_cb.pin_code_len); |
| 1014 | ASSERTC(ret == BT_STATUS_SUCCESS, "storing link key failed", ret); |
| 1015 | } |
| 1016 | else |
| 1017 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1018 | BTIF_TRACE_DEBUG("%s: Temporary key. Not storing. key_type=0x%x, is_temp=%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1019 | __FUNCTION__, p_auth_cmpl->key_type, pairing_cb.is_temp); |
Hemant Gupta | b820aec | 2013-12-24 19:59:57 +0530 | [diff] [blame] | 1020 | if(pairing_cb.is_temp) |
| 1021 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1022 | BTIF_TRACE_DEBUG("%s: sending BT_BOND_STATE_NONE for Temp pairing", |
Hemant Gupta | b820aec | 2013-12-24 19:59:57 +0530 | [diff] [blame] | 1023 | __FUNCTION__); |
| 1024 | bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE); |
| 1025 | return; |
| 1026 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1027 | } |
| 1028 | } |
Priti Aghera | c0edf9f | 2014-06-26 11:23:51 -0700 | [diff] [blame] | 1029 | |
| 1030 | // Skip SDP for certain HID Devices |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1031 | if (p_auth_cmpl->success) |
| 1032 | { |
Andre Eisenbach | 31a6400 | 2014-10-14 14:29:19 -0700 | [diff] [blame] | 1033 | pairing_cb.timeout_retries = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1034 | status = BT_STATUS_SUCCESS; |
| 1035 | state = BT_BOND_STATE_BONDED; |
Priti Aghera | c0edf9f | 2014-06-26 11:23:51 -0700 | [diff] [blame] | 1036 | bdcpy(bd_addr.address, p_auth_cmpl->bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1037 | |
Priti Aghera | c0edf9f | 2014-06-26 11:23:51 -0700 | [diff] [blame] | 1038 | if (check_sdp_bl(&bd_addr) && check_cod_hid(&bd_addr, COD_HID_MAJOR)) |
| 1039 | { |
| 1040 | ALOGW("%s:skip SDP", |
| 1041 | __FUNCTION__); |
| 1042 | skip_sdp = TRUE; |
| 1043 | } |
| 1044 | if(!pairing_cb.is_local_initiated && skip_sdp) |
| 1045 | { |
| 1046 | bond_state_changed(status, &bd_addr, state); |
Ganesh Ganapathi Batta | e17bf00 | 2013-02-15 17:52:29 -0800 | [diff] [blame] | 1047 | |
Priti Aghera | c0edf9f | 2014-06-26 11:23:51 -0700 | [diff] [blame] | 1048 | ALOGW("%s: Incoming HID Connection",__FUNCTION__); |
| 1049 | bt_property_t prop; |
| 1050 | bt_bdaddr_t bd_addr; |
| 1051 | bt_uuid_t uuid; |
| 1052 | char uuid_str[128] = UUID_HUMAN_INTERFACE_DEVICE; |
Ganesh Ganapathi Batta | e17bf00 | 2013-02-15 17:52:29 -0800 | [diff] [blame] | 1053 | |
Priti Aghera | c0edf9f | 2014-06-26 11:23:51 -0700 | [diff] [blame] | 1054 | string_to_uuid(uuid_str, &uuid); |
| 1055 | |
| 1056 | prop.type = BT_PROPERTY_UUIDS; |
| 1057 | prop.val = uuid.uu; |
| 1058 | prop.len = MAX_UUID_SIZE; |
| 1059 | |
| 1060 | /* Send the event to the BTIF */ |
| 1061 | HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, |
| 1062 | BT_STATUS_SUCCESS, &bd_addr, 1, &prop); |
| 1063 | } |
| 1064 | else |
| 1065 | { |
| 1066 | /* Trigger SDP on the device */ |
| 1067 | pairing_cb.sdp_attempts = 1;; |
| 1068 | |
| 1069 | if(btif_dm_inquiry_in_progress) |
| 1070 | btif_dm_cancel_discovery(); |
| 1071 | |
| 1072 | btif_dm_get_remote_services(&bd_addr); |
| 1073 | } |
| 1074 | /* Do not call bond_state_changed_cb yet. Wait till fetch remote service is complete */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1075 | } |
| 1076 | else |
| 1077 | { |
| 1078 | /*Map the HCI fail reason to bt status */ |
| 1079 | switch(p_auth_cmpl->fail_reason) |
| 1080 | { |
| 1081 | case HCI_ERR_PAGE_TIMEOUT: |
Andre Eisenbach | 31a6400 | 2014-10-14 14:29:19 -0700 | [diff] [blame] | 1082 | if (blacklistPairingRetries(bd_addr.address) && pairing_cb.timeout_retries) |
| 1083 | { |
| 1084 | BTIF_TRACE_WARNING("%s() - Pairing timeout; retrying (%d) ...", __FUNCTION__, pairing_cb.timeout_retries); |
| 1085 | --pairing_cb.timeout_retries; |
| 1086 | btif_dm_cb_create_bond (&bd_addr, BTA_TRANSPORT_UNKNOWN); |
| 1087 | return; |
| 1088 | } |
| 1089 | /* Fall-through */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1090 | case HCI_ERR_CONNECTION_TOUT: |
| 1091 | status = BT_STATUS_RMT_DEV_DOWN; |
| 1092 | break; |
| 1093 | |
Hemant Gupta | aef7a67 | 2013-07-31 19:00:12 +0530 | [diff] [blame] | 1094 | case HCI_ERR_PAIRING_NOT_ALLOWED: |
| 1095 | status = BT_STATUS_AUTH_REJECTED; |
| 1096 | break; |
| 1097 | |
Hemant Gupta | b480144 | 2014-01-07 18:11:15 +0530 | [diff] [blame] | 1098 | case HCI_ERR_LMP_RESPONSE_TIMEOUT: |
| 1099 | status = BT_STATUS_AUTH_FAILURE; |
| 1100 | break; |
| 1101 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1102 | /* map the auth failure codes, so we can retry pairing if necessary */ |
| 1103 | case HCI_ERR_AUTH_FAILURE: |
Hemant Gupta | 59a88ec | 2014-03-19 19:01:35 +0530 | [diff] [blame] | 1104 | case HCI_ERR_KEY_MISSING: |
Zhihai Xu | a7ea809 | 2013-11-27 14:10:53 +0530 | [diff] [blame] | 1105 | btif_storage_remove_bonded_device(&bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1106 | case HCI_ERR_HOST_REJECT_SECURITY: |
| 1107 | case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE: |
| 1108 | case HCI_ERR_UNIT_KEY_USED: |
| 1109 | case HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED: |
| 1110 | case HCI_ERR_INSUFFCIENT_SECURITY: |
Hemant Gupta | 87b7cce | 2013-11-28 13:07:10 +0530 | [diff] [blame] | 1111 | case HCI_ERR_PEER_USER: |
| 1112 | case HCI_ERR_UNSPECIFIED: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1113 | BTIF_TRACE_DEBUG(" %s() Authentication fail reason %d", |
Hemant Gupta | 87b7cce | 2013-11-28 13:07:10 +0530 | [diff] [blame] | 1114 | __FUNCTION__, p_auth_cmpl->fail_reason); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1115 | if (pairing_cb.autopair_attempts == 1) |
| 1116 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1117 | BTIF_TRACE_DEBUG("%s(): Adding device to blacklist ", __FUNCTION__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1118 | |
| 1119 | /* Add the device to dynamic black list only if this device belongs to Audio/pointing dev class */ |
| 1120 | if (check_cod(&bd_addr, COD_AV_HEADSETS) || |
| 1121 | check_cod(&bd_addr, COD_AV_HANDSFREE) || |
| 1122 | check_cod(&bd_addr, COD_AV_HEADPHONES) || |
| 1123 | check_cod(&bd_addr, COD_AV_PORTABLE_AUDIO) || |
| 1124 | check_cod(&bd_addr, COD_AV_HIFI_AUDIO) || |
| 1125 | check_cod(&bd_addr, COD_HID_POINTING)) |
| 1126 | { |
| 1127 | btif_storage_add_device_to_autopair_blacklist (&bd_addr); |
| 1128 | } |
| 1129 | pairing_cb.autopair_attempts++; |
| 1130 | |
| 1131 | /* Create the Bond once again */ |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1132 | BTIF_TRACE_DEBUG("%s() auto pair failed. Reinitiate Bond", __FUNCTION__); |
Andre Eisenbach | b0daa5d | 2014-08-04 17:50:10 -0700 | [diff] [blame] | 1133 | btif_dm_cb_create_bond (&bd_addr, BTA_TRANSPORT_UNKNOWN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1134 | return; |
| 1135 | } |
| 1136 | else |
| 1137 | { |
| 1138 | /* if autopair attempts are more than 1, or not attempted */ |
| 1139 | status = BT_STATUS_AUTH_FAILURE; |
| 1140 | } |
| 1141 | break; |
| 1142 | |
| 1143 | default: |
| 1144 | status = BT_STATUS_FAIL; |
| 1145 | } |
Zhihai Xu | 8d2128d | 2013-12-13 16:09:21 +0530 | [diff] [blame] | 1146 | /* Special Handling for HID Devices */ |
| 1147 | if (check_cod(&bd_addr, COD_HID_POINTING)) { |
| 1148 | /* Remove Device as bonded in nvram as authentication failed */ |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1149 | BTIF_TRACE_DEBUG("%s(): removing hid pointing device from nvram", __FUNCTION__); |
Zhihai Xu | 8d2128d | 2013-12-13 16:09:21 +0530 | [diff] [blame] | 1150 | btif_storage_remove_bonded_device(&bd_addr); |
| 1151 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1152 | bond_state_changed(status, &bd_addr, state); |
| 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | /****************************************************************************** |
| 1157 | ** |
| 1158 | ** Function btif_dm_search_devices_evt |
| 1159 | ** |
| 1160 | ** Description Executes search devices callback events in btif context |
| 1161 | ** |
| 1162 | ** Returns void |
| 1163 | ** |
| 1164 | ******************************************************************************/ |
| 1165 | static void btif_dm_search_devices_evt (UINT16 event, char *p_param) |
| 1166 | { |
| 1167 | tBTA_DM_SEARCH *p_search_data; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1168 | BTIF_TRACE_EVENT("%s event=%s", __FUNCTION__, dump_dm_search_event(event)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1169 | |
| 1170 | switch (event) |
| 1171 | { |
| 1172 | case BTA_DM_DISC_RES_EVT: |
| 1173 | { |
| 1174 | p_search_data = (tBTA_DM_SEARCH *)p_param; |
| 1175 | /* Remote name update */ |
| 1176 | if (strlen((const char *) p_search_data->disc_res.bd_name)) |
| 1177 | { |
| 1178 | bt_property_t properties[1]; |
| 1179 | bt_bdaddr_t bdaddr; |
| 1180 | bt_status_t status; |
| 1181 | |
| 1182 | properties[0].type = BT_PROPERTY_BDNAME; |
| 1183 | properties[0].val = p_search_data->disc_res.bd_name; |
| 1184 | properties[0].len = strlen((char *)p_search_data->disc_res.bd_name); |
| 1185 | bdcpy(bdaddr.address, p_search_data->disc_res.bd_addr); |
| 1186 | |
| 1187 | status = btif_storage_set_remote_device_property(&bdaddr, &properties[0]); |
| 1188 | ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device property", status); |
| 1189 | HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, |
| 1190 | status, &bdaddr, 1, properties); |
| 1191 | } |
| 1192 | /* TODO: Services? */ |
| 1193 | } |
| 1194 | break; |
| 1195 | |
| 1196 | case BTA_DM_INQ_RES_EVT: |
| 1197 | { |
| 1198 | /* inquiry result */ |
| 1199 | UINT32 cod; |
| 1200 | UINT8 *p_eir_remote_name = NULL; |
| 1201 | bt_bdname_t bdname; |
| 1202 | bt_bdaddr_t bdaddr; |
| 1203 | UINT8 remote_name_len; |
| 1204 | UINT8 *p_cached_name = NULL; |
| 1205 | tBTA_SERVICE_MASK services = 0; |
| 1206 | bdstr_t bdstr; |
| 1207 | |
| 1208 | p_search_data = (tBTA_DM_SEARCH *)p_param; |
| 1209 | bdcpy(bdaddr.address, p_search_data->inq_res.bd_addr); |
| 1210 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1211 | BTIF_TRACE_DEBUG("%s() %s device_type = 0x%x\n", __FUNCTION__, bd2str(&bdaddr, &bdstr), |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1212 | #if (BLE_INCLUDED == TRUE) |
| 1213 | p_search_data->inq_res.device_type); |
| 1214 | #else |
| 1215 | BT_DEVICE_TYPE_BREDR); |
| 1216 | #endif |
| 1217 | bdname.name[0] = 0; |
| 1218 | |
| 1219 | cod = devclass2uint (p_search_data->inq_res.dev_class); |
| 1220 | |
| 1221 | if ( cod == 0) { |
| 1222 | ALOGD("cod is 0, set as unclassified"); |
| 1223 | cod = COD_UNCLASSIFIED; |
| 1224 | } |
| 1225 | |
| 1226 | if (!check_eir_remote_name(p_search_data, bdname.name, &remote_name_len)) |
| 1227 | check_cached_remote_name(p_search_data, bdname.name, &remote_name_len); |
| 1228 | |
| 1229 | /* Check EIR for remote name and services */ |
| 1230 | if (p_search_data->inq_res.p_eir) |
| 1231 | { |
| 1232 | BTA_GetEirService(p_search_data->inq_res.p_eir, &services); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1233 | BTIF_TRACE_DEBUG("%s()EIR BTA services = %08X", __FUNCTION__, (UINT32)services); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1234 | /* TODO: Get the service list and check to see which uuids we got and send it back to the client. */ |
| 1235 | } |
| 1236 | |
| 1237 | |
| 1238 | { |
| 1239 | bt_property_t properties[5]; |
| 1240 | bt_device_type_t dev_type; |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 1241 | UINT8 addr_type; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1242 | uint32_t num_properties = 0; |
| 1243 | bt_status_t status; |
| 1244 | |
| 1245 | memset(properties, 0, sizeof(properties)); |
| 1246 | /* BD_ADDR */ |
| 1247 | BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], |
| 1248 | BT_PROPERTY_BDADDR, sizeof(bdaddr), &bdaddr); |
| 1249 | num_properties++; |
| 1250 | /* BD_NAME */ |
| 1251 | /* Don't send BDNAME if it is empty */ |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 1252 | if (bdname.name[0]) |
| 1253 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1254 | BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], |
| 1255 | BT_PROPERTY_BDNAME, |
| 1256 | strlen((char *)bdname.name), &bdname); |
| 1257 | num_properties++; |
| 1258 | } |
| 1259 | |
| 1260 | /* DEV_CLASS */ |
| 1261 | BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], |
| 1262 | BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod); |
| 1263 | num_properties++; |
| 1264 | /* DEV_TYPE */ |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 1265 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1266 | /* FixMe: Assumption is that bluetooth.h and BTE enums match */ |
| 1267 | dev_type = p_search_data->inq_res.device_type; |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 1268 | addr_type = p_search_data->inq_res.ble_addr_type; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1269 | #else |
| 1270 | dev_type = BT_DEVICE_TYPE_BREDR; |
| 1271 | #endif |
| 1272 | BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], |
| 1273 | BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type), &dev_type); |
| 1274 | num_properties++; |
| 1275 | /* RSSI */ |
| 1276 | BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], |
| 1277 | BT_PROPERTY_REMOTE_RSSI, sizeof(int8_t), |
| 1278 | &(p_search_data->inq_res.rssi)); |
| 1279 | num_properties++; |
| 1280 | |
| 1281 | status = btif_storage_add_remote_device(&bdaddr, num_properties, properties); |
| 1282 | ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device (inquiry)", status); |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 1283 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
| 1284 | status = btif_storage_set_remote_addr_type(&bdaddr, addr_type); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1285 | if (( dev_type == BT_DEVICE_TYPE_DUMO)&& |
| 1286 | (p_search_data->inq_res.flag & BTA_BLE_DMT_CONTROLLER_SPT) && |
| 1287 | (p_search_data->inq_res.flag & BTA_BLE_DMT_HOST_SPT)) |
| 1288 | { |
| 1289 | btif_storage_set_dmt_support_type (&bdaddr, TRUE); |
| 1290 | } |
Andre Eisenbach | 5c44e45 | 2013-08-06 18:19:37 -0700 | [diff] [blame] | 1291 | ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote addr type (inquiry)", status); |
| 1292 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1293 | /* Callback to notify upper layer of device */ |
| 1294 | HAL_CBACK(bt_hal_cbacks, device_found_cb, |
| 1295 | num_properties, properties); |
| 1296 | } |
| 1297 | } |
| 1298 | break; |
| 1299 | |
| 1300 | case BTA_DM_INQ_CMPL_EVT: |
| 1301 | { |
Satya Calloji | 6e2d9db | 2014-07-08 16:18:58 -0700 | [diff] [blame] | 1302 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
| 1303 | tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param; |
| 1304 | memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS)); |
| 1305 | BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL, |
| 1306 | bte_scan_filt_param_cfg_evt, 0); |
| 1307 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1308 | } |
| 1309 | break; |
| 1310 | case BTA_DM_DISC_CMPL_EVT: |
| 1311 | { |
| 1312 | HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED); |
| 1313 | } |
| 1314 | break; |
| 1315 | case BTA_DM_SEARCH_CANCEL_CMPL_EVT: |
| 1316 | { |
| 1317 | /* if inquiry is not in progress and we get a cancel event, then |
| 1318 | * it means we are done with inquiry, but remote_name fetches are in |
| 1319 | * progress |
| 1320 | * |
| 1321 | * if inquiry is in progress, then we don't want to act on this cancel_cmpl_evt |
| 1322 | * but instead wait for the cancel_cmpl_evt via the Busy Level |
| 1323 | * |
| 1324 | */ |
| 1325 | if (btif_dm_inquiry_in_progress == FALSE) |
| 1326 | { |
| 1327 | HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STOPPED); |
| 1328 | } |
| 1329 | } |
| 1330 | break; |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | /******************************************************************************* |
| 1335 | ** |
| 1336 | ** Function btif_dm_search_services_evt |
| 1337 | ** |
| 1338 | ** Description Executes search services event in btif context |
| 1339 | ** |
| 1340 | ** Returns void |
| 1341 | ** |
| 1342 | *******************************************************************************/ |
| 1343 | static void btif_dm_search_services_evt(UINT16 event, char *p_param) |
| 1344 | { |
| 1345 | tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param; |
| 1346 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1347 | BTIF_TRACE_EVENT("%s: event = %d", __FUNCTION__, event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1348 | switch (event) |
| 1349 | { |
| 1350 | case BTA_DM_DISC_RES_EVT: |
| 1351 | { |
| 1352 | bt_uuid_t uuid_arr[BT_MAX_NUM_UUIDS]; /* Max 32 services */ |
| 1353 | bt_property_t prop; |
| 1354 | uint32_t i = 0, j = 0; |
| 1355 | bt_bdaddr_t bd_addr; |
| 1356 | bt_status_t ret; |
| 1357 | |
| 1358 | bdcpy(bd_addr.address, p_data->disc_res.bd_addr); |
| 1359 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1360 | BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1361 | p_data->disc_res.result, p_data->disc_res.services); |
Ganesh Ganapathi Batta | ec7e2c8 | 2013-06-20 11:00:28 -0700 | [diff] [blame] | 1362 | if ((p_data->disc_res.result != BTA_SUCCESS) && |
| 1363 | (pairing_cb.state == BT_BOND_STATE_BONDING ) && |
| 1364 | (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING)) |
| 1365 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1366 | BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", __FUNCTION__); |
Ganesh Ganapathi Batta | ec7e2c8 | 2013-06-20 11:00:28 -0700 | [diff] [blame] | 1367 | pairing_cb.sdp_attempts++; |
| 1368 | btif_dm_get_remote_services(&bd_addr); |
| 1369 | return; |
| 1370 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1371 | prop.type = BT_PROPERTY_UUIDS; |
| 1372 | prop.len = 0; |
| 1373 | if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0)) |
| 1374 | { |
| 1375 | prop.val = p_data->disc_res.p_uuid_list; |
| 1376 | prop.len = p_data->disc_res.num_uuids * MAX_UUID_SIZE; |
| 1377 | for (i=0; i < p_data->disc_res.num_uuids; i++) |
| 1378 | { |
| 1379 | char temp[256]; |
| 1380 | uuid_to_string((bt_uuid_t*)(p_data->disc_res.p_uuid_list + (i*MAX_UUID_SIZE)), temp); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1381 | BTIF_TRACE_ERROR("Index: %d uuid:%s", i, temp); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | /* onUuidChanged requires getBondedDevices to be populated. |
| 1386 | ** bond_state_changed needs to be sent prior to remote_device_property |
| 1387 | */ |
| 1388 | if ((pairing_cb.state == BT_BOND_STATE_BONDING) && |
| 1389 | (bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0)&& |
Ganesh Ganapathi Batta | ec7e2c8 | 2013-06-20 11:00:28 -0700 | [diff] [blame] | 1390 | pairing_cb.sdp_attempts > 0) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1391 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1392 | BTIF_TRACE_DEBUG("%s Remote Service SDP done. Call bond_state_changed_cb BONDED", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1393 | __FUNCTION__); |
Ganesh Ganapathi Batta | ec7e2c8 | 2013-06-20 11:00:28 -0700 | [diff] [blame] | 1394 | pairing_cb.sdp_attempts = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1395 | bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED); |
| 1396 | } |
| 1397 | |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 1398 | if(p_data->disc_res.num_uuids != 0) |
| 1399 | { |
| 1400 | /* Also write this to the NVRAM */ |
| 1401 | ret = btif_storage_set_remote_device_property(&bd_addr, &prop); |
| 1402 | ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret); |
| 1403 | /* Send the event to the BTIF */ |
| 1404 | HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, |
| 1405 | BT_STATUS_SUCCESS, &bd_addr, 1, &prop); |
| 1406 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1407 | } |
| 1408 | break; |
| 1409 | |
| 1410 | case BTA_DM_DISC_CMPL_EVT: |
| 1411 | /* fixme */ |
| 1412 | break; |
| 1413 | |
Matthew Xie | 607e3b7 | 2013-08-15 19:30:48 -0700 | [diff] [blame] | 1414 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 1415 | case BTA_DM_DISC_BLE_RES_EVT: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1416 | BTIF_TRACE_DEBUG("%s:, services 0x%x)", __FUNCTION__, |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 1417 | p_data->disc_ble_res.service.uu.uuid16); |
| 1418 | bt_uuid_t uuid; |
| 1419 | int i = 0; |
| 1420 | int j = 15; |
| 1421 | if (p_data->disc_ble_res.service.uu.uuid16 == UUID_SERVCLASS_LE_HID) |
| 1422 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1423 | BTIF_TRACE_DEBUG("%s: Found HOGP UUID",__FUNCTION__); |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 1424 | bt_property_t prop; |
| 1425 | bt_bdaddr_t bd_addr; |
| 1426 | char temp[256]; |
Zhihai Xu | d7ee77b | 2013-11-05 18:06:54 -0800 | [diff] [blame] | 1427 | bt_status_t ret; |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 1428 | |
| 1429 | bta_gatt_convert_uuid16_to_uuid128(uuid.uu,p_data->disc_ble_res.service.uu.uuid16); |
| 1430 | |
| 1431 | while(i < j ) |
| 1432 | { |
| 1433 | unsigned char c = uuid.uu[j]; |
| 1434 | uuid.uu[j] = uuid.uu[i]; |
| 1435 | uuid.uu[i] = c; |
| 1436 | i++; |
| 1437 | j--; |
| 1438 | } |
| 1439 | |
| 1440 | uuid_to_string(&uuid, temp); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1441 | BTIF_TRACE_ERROR(" uuid:%s", temp); |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 1442 | |
| 1443 | bdcpy(bd_addr.address, p_data->disc_ble_res.bd_addr); |
| 1444 | prop.type = BT_PROPERTY_UUIDS; |
| 1445 | prop.val = uuid.uu; |
| 1446 | prop.len = MAX_UUID_SIZE; |
| 1447 | |
Zhihai Xu | d7ee77b | 2013-11-05 18:06:54 -0800 | [diff] [blame] | 1448 | /* Also write this to the NVRAM */ |
| 1449 | ret = btif_storage_set_remote_device_property(&bd_addr, &prop); |
| 1450 | ASSERTC(ret == BT_STATUS_SUCCESS, "storing remote services failed", ret); |
| 1451 | |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 1452 | /* Send the event to the BTIF */ |
| 1453 | HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, |
| 1454 | BT_STATUS_SUCCESS, &bd_addr, 1, &prop); |
| 1455 | |
| 1456 | } |
| 1457 | break; |
Matthew Xie | 607e3b7 | 2013-08-15 19:30:48 -0700 | [diff] [blame] | 1458 | #endif /* BLE_INCLUDED */ |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 1459 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1460 | default: |
| 1461 | { |
| 1462 | ASSERTC(0, "unhandled search services event", event); |
| 1463 | } |
| 1464 | break; |
| 1465 | } |
| 1466 | } |
| 1467 | |
| 1468 | /******************************************************************************* |
| 1469 | ** |
| 1470 | ** Function btif_dm_remote_service_record_evt |
| 1471 | ** |
| 1472 | ** Description Executes search service record event in btif context |
| 1473 | ** |
| 1474 | ** Returns void |
| 1475 | ** |
| 1476 | *******************************************************************************/ |
| 1477 | static void btif_dm_remote_service_record_evt(UINT16 event, char *p_param) |
| 1478 | { |
| 1479 | tBTA_DM_SEARCH *p_data = (tBTA_DM_SEARCH*)p_param; |
| 1480 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1481 | BTIF_TRACE_EVENT("%s: event = %d", __FUNCTION__, event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1482 | switch (event) |
| 1483 | { |
| 1484 | case BTA_DM_DISC_RES_EVT: |
| 1485 | { |
| 1486 | bt_service_record_t rec; |
| 1487 | bt_property_t prop; |
| 1488 | uint32_t i = 0; |
| 1489 | bt_bdaddr_t bd_addr; |
| 1490 | |
| 1491 | memset(&rec, 0, sizeof(bt_service_record_t)); |
| 1492 | bdcpy(bd_addr.address, p_data->disc_res.bd_addr); |
| 1493 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1494 | BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1495 | p_data->disc_res.result, p_data->disc_res.services); |
| 1496 | prop.type = BT_PROPERTY_SERVICE_RECORD; |
| 1497 | prop.val = (void*)&rec; |
| 1498 | prop.len = sizeof(rec); |
| 1499 | |
| 1500 | /* disc_res.result is overloaded with SCN. Cannot check result */ |
| 1501 | p_data->disc_res.services &= ~BTA_USER_SERVICE_MASK; |
| 1502 | /* TODO: Get the UUID as well */ |
| 1503 | rec.channel = p_data->disc_res.result - 3; |
| 1504 | /* TODO: Need to get the service name using p_raw_data */ |
| 1505 | rec.name[0] = 0; |
| 1506 | |
| 1507 | HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, |
| 1508 | BT_STATUS_SUCCESS, &bd_addr, 1, &prop); |
| 1509 | } |
| 1510 | break; |
| 1511 | |
| 1512 | default: |
| 1513 | { |
| 1514 | ASSERTC(0, "unhandled remote service record event", event); |
| 1515 | } |
| 1516 | break; |
| 1517 | } |
| 1518 | } |
| 1519 | |
| 1520 | /******************************************************************************* |
| 1521 | ** |
| 1522 | ** Function btif_dm_upstreams_cback |
| 1523 | ** |
| 1524 | ** Description Executes UPSTREAMS events in btif context |
| 1525 | ** |
| 1526 | ** Returns void |
| 1527 | ** |
| 1528 | *******************************************************************************/ |
| 1529 | static void btif_dm_upstreams_evt(UINT16 event, char* p_param) |
| 1530 | { |
| 1531 | tBTA_DM_SEC_EVT dm_event = (tBTA_DM_SEC_EVT)event; |
| 1532 | tBTA_DM_SEC *p_data = (tBTA_DM_SEC*)p_param; |
| 1533 | tBTA_SERVICE_MASK service_mask; |
| 1534 | uint32_t i; |
| 1535 | bt_bdaddr_t bd_addr; |
| 1536 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1537 | BTIF_TRACE_EVENT("btif_dm_upstreams_cback ev: %s", dump_dm_event(event)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1538 | |
| 1539 | switch (event) |
| 1540 | { |
| 1541 | case BTA_DM_ENABLE_EVT: |
| 1542 | { |
| 1543 | BD_NAME bdname; |
| 1544 | bt_status_t status; |
| 1545 | bt_property_t prop; |
| 1546 | prop.type = BT_PROPERTY_BDNAME; |
| 1547 | prop.len = BD_NAME_LEN; |
| 1548 | prop.val = (void*)bdname; |
| 1549 | |
| 1550 | status = btif_storage_get_adapter_property(&prop); |
Matthew Xie | 1e5109b | 2012-11-09 18:26:26 -0800 | [diff] [blame] | 1551 | if (status == BT_STATUS_SUCCESS) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1552 | { |
| 1553 | /* A name exists in the storage. Make this the device name */ |
| 1554 | BTA_DmSetDeviceName((char*)prop.val); |
| 1555 | } |
Matthew Xie | 1e5109b | 2012-11-09 18:26:26 -0800 | [diff] [blame] | 1556 | else |
| 1557 | { |
| 1558 | /* Storage does not have a name yet. |
| 1559 | * Use the default name and write it to the chip |
| 1560 | */ |
| 1561 | BTA_DmSetDeviceName(btif_get_default_local_name()); |
| 1562 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1563 | |
Andre Eisenbach | a015a83 | 2014-09-11 14:09:40 -0700 | [diff] [blame] | 1564 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
| 1565 | /* Enable local privacy */ |
Andre Eisenbach | 3e0dc73 | 2014-10-24 09:55:34 -0700 | [diff] [blame] | 1566 | BTA_DmBleConfigLocalPrivacy(BLE_LOCAL_PRIVACY_ENABLED); |
Andre Eisenbach | a015a83 | 2014-09-11 14:09:40 -0700 | [diff] [blame] | 1567 | #endif |
| 1568 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1569 | /* for each of the enabled services in the mask, trigger the profile |
| 1570 | * enable */ |
| 1571 | service_mask = btif_get_enabled_services_mask(); |
| 1572 | for (i=0; i <= BTA_MAX_SERVICE_ID; i++) |
| 1573 | { |
| 1574 | if (service_mask & |
| 1575 | (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) |
| 1576 | { |
| 1577 | btif_in_execute_service_request(i, TRUE); |
| 1578 | } |
| 1579 | } |
| 1580 | /* clear control blocks */ |
| 1581 | memset(&pairing_cb, 0, sizeof(btif_dm_pairing_cb_t)); |
| 1582 | |
| 1583 | /* This function will also trigger the adapter_properties_cb |
| 1584 | ** and bonded_devices_info_cb |
| 1585 | */ |
| 1586 | btif_storage_load_bonded_devices(); |
| 1587 | |
| 1588 | btif_storage_load_autopair_device_list(); |
| 1589 | |
| 1590 | btif_enable_bluetooth_evt(p_data->enable.status, p_data->enable.bd_addr); |
| 1591 | } |
| 1592 | break; |
| 1593 | |
| 1594 | case BTA_DM_DISABLE_EVT: |
| 1595 | /* for each of the enabled services in the mask, trigger the profile |
| 1596 | * disable */ |
| 1597 | service_mask = btif_get_enabled_services_mask(); |
| 1598 | for (i=0; i <= BTA_MAX_SERVICE_ID; i++) |
| 1599 | { |
| 1600 | if (service_mask & |
| 1601 | (tBTA_SERVICE_MASK)(BTA_SERVICE_ID_TO_SERVICE_MASK(i))) |
| 1602 | { |
| 1603 | btif_in_execute_service_request(i, FALSE); |
| 1604 | } |
| 1605 | } |
| 1606 | btif_disable_bluetooth_evt(); |
| 1607 | break; |
| 1608 | |
| 1609 | case BTA_DM_PIN_REQ_EVT: |
| 1610 | btif_dm_pin_req_evt(&p_data->pin_req); |
| 1611 | break; |
| 1612 | |
| 1613 | case BTA_DM_AUTH_CMPL_EVT: |
| 1614 | btif_dm_auth_cmpl_evt(&p_data->auth_cmpl); |
| 1615 | break; |
| 1616 | |
| 1617 | case BTA_DM_BOND_CANCEL_CMPL_EVT: |
| 1618 | if (pairing_cb.state == BT_BOND_STATE_BONDING) |
| 1619 | { |
| 1620 | bdcpy(bd_addr.address, pairing_cb.bd_addr); |
| 1621 | bond_state_changed(p_data->bond_cancel_cmpl.result, &bd_addr, BT_BOND_STATE_NONE); |
| 1622 | } |
| 1623 | break; |
| 1624 | |
| 1625 | case BTA_DM_SP_CFM_REQ_EVT: |
| 1626 | btif_dm_ssp_cfm_req_evt(&p_data->cfm_req); |
| 1627 | break; |
| 1628 | case BTA_DM_SP_KEY_NOTIF_EVT: |
| 1629 | btif_dm_ssp_key_notif_evt(&p_data->key_notif); |
| 1630 | break; |
| 1631 | |
| 1632 | case BTA_DM_DEV_UNPAIRED_EVT: |
| 1633 | bdcpy(bd_addr.address, p_data->link_down.bd_addr); |
| 1634 | |
| 1635 | /*special handling for HID devices */ |
| 1636 | #if (defined(BTA_HH_INCLUDED) && (BTA_HH_INCLUDED == TRUE)) |
Ganesh Ganapathi Batta | 390c94d | 2013-05-15 17:58:35 -0700 | [diff] [blame] | 1637 | btif_hh_remove_device(bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1638 | #endif |
Andre Eisenbach | 2e7fa68 | 2013-08-08 15:42:48 -0700 | [diff] [blame] | 1639 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
| 1640 | btif_storage_remove_ble_bonding_keys(&bd_addr); |
| 1641 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1642 | btif_storage_remove_bonded_device(&bd_addr); |
| 1643 | bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_NONE); |
| 1644 | break; |
| 1645 | |
| 1646 | case BTA_DM_BUSY_LEVEL_EVT: |
| 1647 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1648 | |
| 1649 | if (p_data->busy_level.level_flags & BTM_BL_INQUIRY_PAGING_MASK) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1650 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1651 | if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_STARTED) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1652 | { |
| 1653 | HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, |
| 1654 | BT_DISCOVERY_STARTED); |
| 1655 | btif_dm_inquiry_in_progress = TRUE; |
| 1656 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1657 | else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_CANCELLED) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1658 | { |
| 1659 | HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, |
| 1660 | BT_DISCOVERY_STOPPED); |
| 1661 | btif_dm_inquiry_in_progress = FALSE; |
| 1662 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1663 | else if (p_data->busy_level.level_flags == BTM_BL_INQUIRY_COMPLETE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1664 | { |
| 1665 | btif_dm_inquiry_in_progress = FALSE; |
| 1666 | } |
| 1667 | } |
| 1668 | }break; |
| 1669 | |
| 1670 | case BTA_DM_LINK_UP_EVT: |
| 1671 | bdcpy(bd_addr.address, p_data->link_up.bd_addr); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1672 | BTIF_TRACE_DEBUG("BTA_DM_LINK_UP_EVT. Sending BT_ACL_STATE_CONNECTED"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1673 | |
| 1674 | btif_update_remote_version_property(&bd_addr); |
| 1675 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1676 | HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS, |
| 1677 | &bd_addr, BT_ACL_STATE_CONNECTED); |
| 1678 | break; |
| 1679 | |
| 1680 | case BTA_DM_LINK_DOWN_EVT: |
| 1681 | bdcpy(bd_addr.address, p_data->link_down.bd_addr); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1682 | BTIF_TRACE_DEBUG("BTA_DM_LINK_DOWN_EVT. Sending BT_ACL_STATE_DISCONNECTED"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1683 | HAL_CBACK(bt_hal_cbacks, acl_state_changed_cb, BT_STATUS_SUCCESS, |
| 1684 | &bd_addr, BT_ACL_STATE_DISCONNECTED); |
| 1685 | break; |
| 1686 | |
| 1687 | case BTA_DM_HW_ERROR_EVT: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1688 | BTIF_TRACE_ERROR("Received H/W Error. "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1689 | /* Flush storage data */ |
| 1690 | btif_config_flush(); |
| 1691 | usleep(100000); /* 100milliseconds */ |
| 1692 | /* Killing the process to force a restart as part of fault tolerance */ |
| 1693 | kill(getpid(), SIGKILL); |
| 1694 | break; |
| 1695 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1696 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
| 1697 | case BTA_DM_BLE_KEY_EVT: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1698 | BTIF_TRACE_DEBUG("BTA_DM_BLE_KEY_EVT key_type=0x%02x ", p_data->ble_key.key_type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1699 | |
| 1700 | /* If this pairing is by-product of local initiated GATT client Read or Write, |
| 1701 | BTA would not have sent BTA_DM_BLE_SEC_REQ_EVT event and Bond state would not |
| 1702 | have setup properly. Setup pairing_cb and notify App about Bonding state now*/ |
| 1703 | if (pairing_cb.state != BT_BOND_STATE_BONDING) |
| 1704 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1705 | BTIF_TRACE_DEBUG("Bond state not sent to App so far.Notify the app now"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1706 | bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t*)p_data->ble_key.bd_addr, |
| 1707 | BT_BOND_STATE_BONDING); |
| 1708 | } |
| 1709 | else if (memcmp (pairing_cb.bd_addr, p_data->ble_key.bd_addr, BD_ADDR_LEN)!=0) |
| 1710 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1711 | BTIF_TRACE_ERROR("BD mismatch discard BLE key_type=%d ",p_data->ble_key.key_type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1712 | break; |
| 1713 | } |
| 1714 | |
| 1715 | switch (p_data->ble_key.key_type) |
| 1716 | { |
| 1717 | case BTA_LE_KEY_PENC: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1718 | BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PENC"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1719 | pairing_cb.ble.is_penc_key_rcvd = TRUE; |
| 1720 | memcpy(pairing_cb.ble.penc_key.ltk,p_data->ble_key.key_value.penc_key.ltk, 16); |
| 1721 | memcpy(pairing_cb.ble.penc_key.rand, p_data->ble_key.key_value.penc_key.rand,8); |
| 1722 | pairing_cb.ble.penc_key.ediv = p_data->ble_key.key_value.penc_key.ediv; |
| 1723 | pairing_cb.ble.penc_key.sec_level = p_data->ble_key.key_value.penc_key.sec_level; |
| 1724 | |
| 1725 | for (i=0; i<16; i++) |
| 1726 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1727 | BTIF_TRACE_DEBUG("pairing_cb.ble.penc_key.ltk[%d]=0x%02x",i,pairing_cb.ble.penc_key.ltk[i]); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1728 | } |
| 1729 | for (i=0; i<8; i++) |
| 1730 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1731 | BTIF_TRACE_DEBUG("pairing_cb.ble.penc_key.rand[%d]=0x%02x",i,pairing_cb.ble.penc_key.rand[i]); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1732 | } |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1733 | BTIF_TRACE_DEBUG("pairing_cb.ble.penc_key.ediv=0x%04x",pairing_cb.ble.penc_key.ediv); |
| 1734 | BTIF_TRACE_DEBUG("pairing_cb.ble.penc_key.sec_level=0x%02x",pairing_cb.ble.penc_key.sec_level); |
| 1735 | BTIF_TRACE_DEBUG("pairing_cb.ble.penc_key.key_size=0x%02x",pairing_cb.ble.penc_key.key_size); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1736 | break; |
| 1737 | |
| 1738 | case BTA_LE_KEY_PID: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1739 | BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PID"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1740 | pairing_cb.ble.is_pid_key_rcvd = TRUE; |
Andre Eisenbach | 5e80846 | 2014-10-21 12:37:53 -0700 | [diff] [blame] | 1741 | pairing_cb.ble.pid_key.addr_type = p_data->ble_key.key_value.pid_key.addr_type; |
| 1742 | memcpy(pairing_cb.ble.pid_key.irk, p_data->ble_key.key_value.pid_key.irk, 16); |
| 1743 | memcpy(pairing_cb.ble.pid_key.static_addr, |
| 1744 | p_data->ble_key.key_value.pid_key.static_addr,BD_ADDR_LEN); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1745 | for (i=0; i<16; i++) |
| 1746 | { |
Andre Eisenbach | 5e80846 | 2014-10-21 12:37:53 -0700 | [diff] [blame] | 1747 | BTIF_TRACE_DEBUG("pairing_cb.ble.pid_key.irk[%d]=0x%02x" |
| 1748 | ,i,pairing_cb.ble.pid_key.irk[i]); |
| 1749 | } |
| 1750 | for (i=0; i<BD_ADDR_LEN; i++) |
| 1751 | { |
| 1752 | BTIF_TRACE_DEBUG("piaring_cb.ble.pid_address[%d] = %x" |
| 1753 | ,i, pairing_cb.ble.pid_key.static_addr[i]); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1754 | } |
| 1755 | break; |
| 1756 | |
| 1757 | case BTA_LE_KEY_PCSRK: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1758 | BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_PCSRK"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1759 | pairing_cb.ble.is_pcsrk_key_rcvd = TRUE; |
| 1760 | pairing_cb.ble.pcsrk_key.counter = p_data->ble_key.key_value.pcsrk_key.counter; |
| 1761 | pairing_cb.ble.pcsrk_key.sec_level = p_data->ble_key.key_value.pcsrk_key.sec_level; |
| 1762 | memcpy(pairing_cb.ble.pcsrk_key.csrk,p_data->ble_key.key_value.pcsrk_key.csrk,16); |
| 1763 | |
| 1764 | for (i=0; i<16; i++) |
| 1765 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1766 | BTIF_TRACE_DEBUG("pairing_cb.ble.pcsrk_key.csrk[%d]=0x%02x",i,pairing_cb.ble.pcsrk_key.csrk[i]); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1767 | } |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1768 | BTIF_TRACE_DEBUG("pairing_cb.ble.pcsrk_key.counter=0x%08x",pairing_cb.ble.pcsrk_key.counter); |
| 1769 | BTIF_TRACE_DEBUG("pairing_cb.ble.pcsrk_key.sec_level=0x%02x",pairing_cb.ble.pcsrk_key.sec_level); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1770 | break; |
| 1771 | |
| 1772 | case BTA_LE_KEY_LENC: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1773 | BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LENC"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1774 | pairing_cb.ble.is_lenc_key_rcvd = TRUE; |
| 1775 | pairing_cb.ble.lenc_key.div = p_data->ble_key.key_value.lenc_key.div; |
| 1776 | pairing_cb.ble.lenc_key.key_size = p_data->ble_key.key_value.lenc_key.key_size; |
| 1777 | pairing_cb.ble.lenc_key.sec_level = p_data->ble_key.key_value.lenc_key.sec_level; |
| 1778 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1779 | BTIF_TRACE_DEBUG("pairing_cb.ble.lenc_key.div=0x%04x",pairing_cb.ble.lenc_key.div); |
| 1780 | BTIF_TRACE_DEBUG("pairing_cb.ble.lenc_key.key_size=0x%02x",pairing_cb.ble.lenc_key.key_size); |
| 1781 | BTIF_TRACE_DEBUG("pairing_cb.ble.lenc_key.sec_level=0x%02x",pairing_cb.ble.lenc_key.sec_level); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1782 | break; |
| 1783 | |
| 1784 | |
| 1785 | |
| 1786 | case BTA_LE_KEY_LCSRK: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1787 | BTIF_TRACE_DEBUG("Rcv BTA_LE_KEY_LCSRK"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1788 | pairing_cb.ble.is_lcsrk_key_rcvd = TRUE; |
| 1789 | pairing_cb.ble.lcsrk_key.counter = p_data->ble_key.key_value.lcsrk_key.counter; |
| 1790 | pairing_cb.ble.lcsrk_key.div = p_data->ble_key.key_value.lcsrk_key.div; |
| 1791 | pairing_cb.ble.lcsrk_key.sec_level = p_data->ble_key.key_value.lcsrk_key.sec_level; |
| 1792 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1793 | BTIF_TRACE_DEBUG("pairing_cb.ble.lcsrk_key.div=0x%04x",pairing_cb.ble.lcsrk_key.div); |
| 1794 | BTIF_TRACE_DEBUG("pairing_cb.ble.lcsrk_key.counter=0x%08x",pairing_cb.ble.lcsrk_key.counter); |
| 1795 | BTIF_TRACE_DEBUG("pairing_cb.ble.lcsrk_key.sec_level=0x%02x",pairing_cb.ble.lcsrk_key.sec_level); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1796 | |
| 1797 | break; |
| 1798 | |
| 1799 | default: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1800 | BTIF_TRACE_ERROR("unknown BLE key type (0x%02x)", p_data->ble_key.key_type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1801 | break; |
| 1802 | } |
| 1803 | |
| 1804 | break; |
| 1805 | case BTA_DM_BLE_SEC_REQ_EVT: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1806 | BTIF_TRACE_DEBUG("BTA_DM_BLE_SEC_REQ_EVT. "); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1807 | btif_dm_ble_sec_req_evt(&p_data->ble_req); |
| 1808 | break; |
| 1809 | case BTA_DM_BLE_PASSKEY_NOTIF_EVT: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1810 | BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_NOTIF_EVT. "); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1811 | btif_dm_ble_key_notif_evt(&p_data->key_notif); |
| 1812 | break; |
| 1813 | case BTA_DM_BLE_PASSKEY_REQ_EVT: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1814 | BTIF_TRACE_DEBUG("BTA_DM_BLE_PASSKEY_REQ_EVT. "); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1815 | btif_dm_ble_passkey_req_evt(&p_data->pin_req); |
| 1816 | break; |
| 1817 | case BTA_DM_BLE_OOB_REQ_EVT: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1818 | BTIF_TRACE_DEBUG("BTA_DM_BLE_OOB_REQ_EVT. "); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1819 | break; |
| 1820 | case BTA_DM_BLE_LOCAL_IR_EVT: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1821 | BTIF_TRACE_DEBUG("BTA_DM_BLE_LOCAL_IR_EVT. "); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1822 | ble_local_key_cb.is_id_keys_rcvd = TRUE; |
| 1823 | memcpy(&ble_local_key_cb.id_keys.irk[0], &p_data->ble_id_keys.irk[0], sizeof(BT_OCTET16)); |
| 1824 | memcpy(&ble_local_key_cb.id_keys.ir[0], &p_data->ble_id_keys.ir[0], sizeof(BT_OCTET16)); |
| 1825 | memcpy(&ble_local_key_cb.id_keys.dhk[0], &p_data->ble_id_keys.dhk[0], sizeof(BT_OCTET16)); |
| 1826 | btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.irk[0], |
| 1827 | BTIF_DM_LE_LOCAL_KEY_IR, |
| 1828 | BT_OCTET16_LEN); |
| 1829 | btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.ir[0], |
| 1830 | BTIF_DM_LE_LOCAL_KEY_IRK, |
| 1831 | BT_OCTET16_LEN); |
| 1832 | btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.id_keys.dhk[0], |
| 1833 | BTIF_DM_LE_LOCAL_KEY_DHK, |
| 1834 | BT_OCTET16_LEN); |
| 1835 | break; |
| 1836 | case BTA_DM_BLE_LOCAL_ER_EVT: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1837 | BTIF_TRACE_DEBUG("BTA_DM_BLE_LOCAL_ER_EVT. "); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1838 | ble_local_key_cb.is_er_rcvd = TRUE; |
| 1839 | memcpy(&ble_local_key_cb.er[0], &p_data->ble_er[0], sizeof(BT_OCTET16)); |
| 1840 | btif_storage_add_ble_local_key( (char *)&ble_local_key_cb.er[0], |
| 1841 | BTIF_DM_LE_LOCAL_KEY_ER, |
| 1842 | BT_OCTET16_LEN); |
| 1843 | break; |
| 1844 | |
| 1845 | case BTA_DM_BLE_AUTH_CMPL_EVT: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1846 | BTIF_TRACE_DEBUG("BTA_DM_BLE_KEY_EVT. "); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1847 | btif_dm_ble_auth_cmpl_evt(&p_data->auth_cmpl); |
| 1848 | break; |
Ganesh Ganapathi Batta | 9546abf | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 1849 | |
| 1850 | case BTA_DM_LE_FEATURES_READ: |
| 1851 | { |
| 1852 | tBTM_BLE_VSC_CB cmn_vsc_cb; |
| 1853 | bt_local_le_features_t local_le_features; |
| 1854 | char buf[512]; |
| 1855 | bt_property_t prop; |
| 1856 | prop.type = BT_PROPERTY_LOCAL_LE_FEATURES; |
| 1857 | prop.val = (void*)buf; |
| 1858 | prop.len = sizeof(buf); |
| 1859 | |
| 1860 | /* LE features are not stored in storage. Should be retrived from stack */ |
| 1861 | BTM_BleGetVendorCapabilities(&cmn_vsc_cb); |
| 1862 | local_le_features.local_privacy_enabled = BTM_BleLocalPrivacyEnabled(); |
| 1863 | |
| 1864 | prop.len = sizeof (bt_local_le_features_t); |
| 1865 | if (cmn_vsc_cb.filter_support == 1) |
| 1866 | local_le_features.max_adv_filter_supported = cmn_vsc_cb.max_filter; |
| 1867 | else |
| 1868 | local_le_features.max_adv_filter_supported = 0; |
| 1869 | local_le_features.max_adv_instance = cmn_vsc_cb.adv_inst_max; |
| 1870 | local_le_features.max_irk_list_size = cmn_vsc_cb.max_irk_list_sz; |
| 1871 | local_le_features.rpa_offload_supported = cmn_vsc_cb.rpa_offloading; |
Satya Calloji | d773c2c | 2014-07-29 22:08:55 -0700 | [diff] [blame] | 1872 | local_le_features.scan_result_storage_size_hibyte = |
| 1873 | (cmn_vsc_cb.tot_scan_results_strg >> 8) & (0xFF); |
| 1874 | local_le_features.scan_result_storage_size_lobyte = |
| 1875 | (cmn_vsc_cb.tot_scan_results_strg) & (0xFF); |
Satya Calloji | efaddcb | 2014-07-28 23:22:05 -0700 | [diff] [blame] | 1876 | local_le_features.activity_energy_info_supported = cmn_vsc_cb.energy_support; |
Ganesh Ganapathi Batta | 9546abf | 2014-05-30 16:28:00 -0700 | [diff] [blame] | 1877 | memcpy(prop.val, &local_le_features, prop.len); |
| 1878 | HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, BT_STATUS_SUCCESS, 1, &prop); |
| 1879 | break; |
| 1880 | } |
Satya Calloji | e5ba884 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 1881 | |
| 1882 | case BTA_DM_ENER_INFO_READ: |
| 1883 | { |
| 1884 | btif_activity_energy_info_cb_t *p_ener_data = (btif_activity_energy_info_cb_t*) p_param; |
| 1885 | bt_activity_energy_info energy_info; |
| 1886 | energy_info.status = p_ener_data->status; |
| 1887 | energy_info.ctrl_state = p_ener_data->ctrl_state; |
| 1888 | energy_info.rx_time = p_ener_data->rx_time; |
| 1889 | energy_info.tx_time = p_ener_data->tx_time; |
| 1890 | energy_info.idle_time = p_ener_data->idle_time; |
| 1891 | energy_info.energy_used = p_ener_data->energy_used; |
| 1892 | HAL_CBACK(bt_hal_cbacks, energy_info_cb, &energy_info); |
| 1893 | break; |
| 1894 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1895 | #endif |
| 1896 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1897 | case BTA_DM_AUTHORIZE_EVT: |
| 1898 | case BTA_DM_SIG_STRENGTH_EVT: |
| 1899 | case BTA_DM_SP_RMT_OOB_EVT: |
| 1900 | case BTA_DM_SP_KEYPRESS_EVT: |
| 1901 | case BTA_DM_ROLE_CHG_EVT: |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1902 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1903 | default: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1904 | BTIF_TRACE_WARNING( "btif_dm_cback : unhandled event (%d)", event ); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1905 | break; |
| 1906 | } |
| 1907 | } /* btui_security_cback() */ |
| 1908 | |
| 1909 | |
| 1910 | /******************************************************************************* |
| 1911 | ** |
| 1912 | ** Function btif_dm_generic_evt |
| 1913 | ** |
| 1914 | ** Description Executes non-BTA upstream events in BTIF context |
| 1915 | ** |
| 1916 | ** Returns void |
| 1917 | ** |
| 1918 | *******************************************************************************/ |
| 1919 | static void btif_dm_generic_evt(UINT16 event, char* p_param) |
| 1920 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1921 | BTIF_TRACE_EVENT("%s: event=%d", __FUNCTION__, event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1922 | switch(event) |
| 1923 | { |
| 1924 | case BTIF_DM_CB_DISCOVERY_STARTED: |
| 1925 | { |
| 1926 | HAL_CBACK(bt_hal_cbacks, discovery_state_changed_cb, BT_DISCOVERY_STARTED); |
| 1927 | } |
| 1928 | break; |
| 1929 | |
| 1930 | case BTIF_DM_CB_CREATE_BOND: |
| 1931 | { |
Andre Eisenbach | 31a6400 | 2014-10-14 14:29:19 -0700 | [diff] [blame] | 1932 | pairing_cb.timeout_retries = NUM_TIMEOUT_RETRIES; |
Andre Eisenbach | b0daa5d | 2014-08-04 17:50:10 -0700 | [diff] [blame] | 1933 | btif_dm_create_bond_cb_t *create_bond_cb = (btif_dm_create_bond_cb_t*)p_param; |
| 1934 | btif_dm_cb_create_bond(&create_bond_cb->bdaddr, create_bond_cb->transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1935 | } |
| 1936 | break; |
| 1937 | |
| 1938 | case BTIF_DM_CB_REMOVE_BOND: |
| 1939 | { |
| 1940 | btif_dm_cb_remove_bond((bt_bdaddr_t *)p_param); |
| 1941 | } |
| 1942 | break; |
| 1943 | |
| 1944 | case BTIF_DM_CB_HID_REMOTE_NAME: |
| 1945 | { |
| 1946 | btif_dm_cb_hid_remote_name((tBTM_REMOTE_DEV_NAME *)p_param); |
| 1947 | } |
| 1948 | break; |
| 1949 | |
| 1950 | case BTIF_DM_CB_BOND_STATE_BONDING: |
| 1951 | { |
| 1952 | bond_state_changed(BT_STATUS_SUCCESS, (bt_bdaddr_t *)p_param, BT_BOND_STATE_BONDING); |
| 1953 | } |
| 1954 | break; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1955 | case BTIF_DM_CB_LE_TX_TEST: |
| 1956 | case BTIF_DM_CB_LE_RX_TEST: |
| 1957 | { |
| 1958 | uint8_t status; |
| 1959 | STREAM_TO_UINT8(status, p_param); |
| 1960 | HAL_CBACK(bt_hal_cbacks, le_test_mode_cb, |
| 1961 | (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, 0); |
| 1962 | } |
| 1963 | break; |
| 1964 | case BTIF_DM_CB_LE_TEST_END: |
| 1965 | { |
| 1966 | uint8_t status; |
| 1967 | uint16_t count = 0; |
| 1968 | STREAM_TO_UINT8(status, p_param); |
| 1969 | if (status == 0) |
| 1970 | STREAM_TO_UINT16(count, p_param); |
| 1971 | HAL_CBACK(bt_hal_cbacks, le_test_mode_cb, |
| 1972 | (status == 0) ? BT_STATUS_SUCCESS : BT_STATUS_FAIL, count); |
| 1973 | } |
| 1974 | break; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1975 | default: |
| 1976 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 1977 | BTIF_TRACE_WARNING("%s : Unknown event 0x%x", __FUNCTION__, event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1978 | } |
| 1979 | break; |
| 1980 | } |
| 1981 | } |
| 1982 | |
| 1983 | /******************************************************************************* |
| 1984 | ** |
| 1985 | ** Function bte_dm_evt |
| 1986 | ** |
| 1987 | ** Description Switches context from BTE to BTIF for all DM events |
| 1988 | ** |
| 1989 | ** Returns void |
| 1990 | ** |
| 1991 | *******************************************************************************/ |
| 1992 | |
| 1993 | void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data) |
| 1994 | { |
| 1995 | bt_status_t status; |
| 1996 | |
| 1997 | /* switch context to btif task context (copy full union size for convenience) */ |
| 1998 | status = btif_transfer_context(btif_dm_upstreams_evt, (uint16_t)event, (void*)p_data, sizeof(tBTA_DM_SEC), NULL); |
| 1999 | |
| 2000 | /* catch any failed context transfers */ |
| 2001 | ASSERTC(status == BT_STATUS_SUCCESS, "context transfer failed", status); |
| 2002 | } |
| 2003 | |
| 2004 | /******************************************************************************* |
| 2005 | ** |
| 2006 | ** Function bte_search_devices_evt |
| 2007 | ** |
| 2008 | ** Description Switches context from BTE to BTIF for DM search events |
| 2009 | ** |
| 2010 | ** Returns void |
| 2011 | ** |
| 2012 | *******************************************************************************/ |
| 2013 | static void bte_search_devices_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data) |
| 2014 | { |
| 2015 | UINT16 param_len = 0; |
| 2016 | |
| 2017 | if (p_data) |
| 2018 | param_len += sizeof(tBTA_DM_SEARCH); |
| 2019 | /* Allocate buffer to hold the pointers (deep copy). The pointers will point to the end of the tBTA_DM_SEARCH */ |
| 2020 | switch (event) |
| 2021 | { |
| 2022 | case BTA_DM_INQ_RES_EVT: |
| 2023 | { |
| 2024 | if (p_data->inq_res.p_eir) |
| 2025 | param_len += HCI_EXT_INQ_RESPONSE_LEN; |
| 2026 | } |
| 2027 | break; |
| 2028 | |
| 2029 | case BTA_DM_DISC_RES_EVT: |
| 2030 | { |
| 2031 | if (p_data->disc_res.raw_data_size && p_data->disc_res.p_raw_data) |
| 2032 | param_len += p_data->disc_res.raw_data_size; |
| 2033 | } |
| 2034 | break; |
| 2035 | } |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2036 | BTIF_TRACE_DEBUG("%s event=%s param_len=%d", __FUNCTION__, dump_dm_search_event(event), param_len); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2037 | |
| 2038 | /* if remote name is available in EIR, set teh flag so that stack doesnt trigger RNR */ |
| 2039 | if (event == BTA_DM_INQ_RES_EVT) |
| 2040 | p_data->inq_res.remt_name_not_required = check_eir_remote_name(p_data, NULL, NULL); |
| 2041 | |
| 2042 | btif_transfer_context (btif_dm_search_devices_evt , (UINT16) event, (void *)p_data, param_len, |
| 2043 | (param_len > sizeof(tBTA_DM_SEARCH)) ? search_devices_copy_cb : NULL); |
| 2044 | } |
| 2045 | |
| 2046 | /******************************************************************************* |
| 2047 | ** |
| 2048 | ** Function bte_dm_search_services_evt |
| 2049 | ** |
| 2050 | ** Description Switches context from BTE to BTIF for DM search services |
| 2051 | ** event |
| 2052 | ** |
| 2053 | ** Returns void |
| 2054 | ** |
| 2055 | *******************************************************************************/ |
| 2056 | static void bte_dm_search_services_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data) |
| 2057 | { |
| 2058 | UINT16 param_len = 0; |
| 2059 | if (p_data) |
| 2060 | param_len += sizeof(tBTA_DM_SEARCH); |
| 2061 | switch (event) |
| 2062 | { |
| 2063 | case BTA_DM_DISC_RES_EVT: |
| 2064 | { |
| 2065 | if ((p_data->disc_res.result == BTA_SUCCESS) && (p_data->disc_res.num_uuids > 0)) { |
| 2066 | param_len += (p_data->disc_res.num_uuids * MAX_UUID_SIZE); |
| 2067 | } |
| 2068 | } break; |
| 2069 | } |
| 2070 | /* TODO: The only other member that needs a deep copy is the p_raw_data. But not sure |
| 2071 | * if raw_data is needed. */ |
| 2072 | btif_transfer_context(btif_dm_search_services_evt, event, (char*)p_data, param_len, |
| 2073 | (param_len > sizeof(tBTA_DM_SEARCH)) ? search_services_copy_cb : NULL); |
| 2074 | } |
| 2075 | |
| 2076 | /******************************************************************************* |
| 2077 | ** |
| 2078 | ** Function bte_dm_remote_service_record_evt |
| 2079 | ** |
| 2080 | ** Description Switches context from BTE to BTIF for DM search service |
| 2081 | ** record event |
| 2082 | ** |
| 2083 | ** Returns void |
| 2084 | ** |
| 2085 | *******************************************************************************/ |
| 2086 | static void bte_dm_remote_service_record_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data) |
| 2087 | { |
| 2088 | /* TODO: The only member that needs a deep copy is the p_raw_data. But not sure yet if this is needed. */ |
| 2089 | btif_transfer_context(btif_dm_remote_service_record_evt, event, (char*)p_data, sizeof(tBTA_DM_SEARCH), NULL); |
| 2090 | } |
| 2091 | |
Prerepa Viswanadham | 81b0319 | 2014-07-23 17:49:48 -0700 | [diff] [blame] | 2092 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
Satya Calloji | e5ba884 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 2093 | /******************************************************************************* |
| 2094 | ** |
| 2095 | ** Function bta_energy_info_cb |
| 2096 | ** |
| 2097 | ** Description Switches context from BTE to BTIF for DM energy info event |
| 2098 | ** |
| 2099 | ** Returns void |
| 2100 | ** |
| 2101 | *******************************************************************************/ |
| 2102 | static void bta_energy_info_cb(tBTA_DM_BLE_TX_TIME_MS tx_time, tBTA_DM_BLE_RX_TIME_MS rx_time, |
| 2103 | tBTA_DM_BLE_IDLE_TIME_MS idle_time, |
| 2104 | tBTA_DM_BLE_ENERGY_USED energy_used, |
| 2105 | tBTA_DM_CONTRL_STATE ctrl_state, tBTA_STATUS status) |
| 2106 | { |
| 2107 | BTIF_TRACE_DEBUG("energy_info_cb-Status:%d,state=%d,tx_t=%ld, rx_t=%ld, idle_time=%ld,used=%ld", |
| 2108 | status, ctrl_state, tx_time, rx_time, idle_time, energy_used); |
| 2109 | |
| 2110 | btif_activity_energy_info_cb_t btif_cb; |
| 2111 | btif_cb.status = status; |
| 2112 | btif_cb.ctrl_state = ctrl_state; |
| 2113 | btif_cb.tx_time = (uint64_t) tx_time; |
| 2114 | btif_cb.rx_time = (uint64_t) rx_time; |
| 2115 | btif_cb.idle_time =(uint64_t) idle_time; |
| 2116 | btif_cb.energy_used =(uint64_t) energy_used; |
| 2117 | btif_transfer_context(btif_dm_upstreams_evt, BTA_DM_ENER_INFO_READ, |
| 2118 | (char*) &btif_cb, sizeof(btif_activity_energy_info_cb_t), NULL); |
| 2119 | } |
Prerepa Viswanadham | 81b0319 | 2014-07-23 17:49:48 -0700 | [diff] [blame] | 2120 | #endif |
Satya Calloji | e5ba884 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 2121 | |
Satya Calloji | 6e2d9db | 2014-07-08 16:18:58 -0700 | [diff] [blame] | 2122 | /******************************************************************************* |
| 2123 | ** |
| 2124 | ** Function bte_scan_filt_param_cfg_evt |
| 2125 | ** |
| 2126 | ** Description Scan filter param config event |
| 2127 | ** |
| 2128 | ** Returns void |
| 2129 | ** |
| 2130 | *******************************************************************************/ |
| 2131 | static void bte_scan_filt_param_cfg_evt(UINT8 action_type, |
| 2132 | tBTA_DM_BLE_PF_AVBL_SPACE avbl_space, |
| 2133 | tBTA_DM_BLE_REF_VALUE ref_value, tBTA_STATUS status) |
| 2134 | { |
| 2135 | /* This event occurs on calling BTA_DmBleCfgFilterCondition internally, |
| 2136 | ** and that is why there is no HAL callback |
| 2137 | */ |
| 2138 | if(BTA_SUCCESS != status) |
| 2139 | { |
| 2140 | BTIF_TRACE_ERROR("%s, %d", __FUNCTION__, status); |
| 2141 | } |
| 2142 | else |
| 2143 | { |
| 2144 | BTIF_TRACE_DEBUG("%s", __FUNCTION__); |
| 2145 | } |
| 2146 | } |
| 2147 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2148 | /***************************************************************************** |
| 2149 | ** |
| 2150 | ** btif api functions (no context switch) |
| 2151 | ** |
| 2152 | *****************************************************************************/ |
| 2153 | |
| 2154 | /******************************************************************************* |
| 2155 | ** |
| 2156 | ** Function btif_dm_start_discovery |
| 2157 | ** |
| 2158 | ** Description Start device discovery/inquiry |
| 2159 | ** |
| 2160 | ** Returns bt_status_t |
| 2161 | ** |
| 2162 | *******************************************************************************/ |
| 2163 | bt_status_t btif_dm_start_discovery(void) |
| 2164 | { |
| 2165 | tBTA_DM_INQ inq_params; |
| 2166 | tBTA_SERVICE_MASK services = 0; |
Satya Calloji | 6e2d9db | 2014-07-08 16:18:58 -0700 | [diff] [blame] | 2167 | tBTA_DM_BLE_PF_FILT_PARAMS adv_filt_param; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2168 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2169 | BTIF_TRACE_EVENT("%s", __FUNCTION__); |
Satya Calloji | 6e2d9db | 2014-07-08 16:18:58 -0700 | [diff] [blame] | 2170 | |
| 2171 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
| 2172 | memset(&adv_filt_param, 0, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS)); |
| 2173 | /* Cleanup anything remaining on index 0 */ |
| 2174 | BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_DELETE, 0, &adv_filt_param, NULL, |
| 2175 | bte_scan_filt_param_cfg_evt, 0); |
| 2176 | |
| 2177 | /* Add an allow-all filter on index 0*/ |
| 2178 | adv_filt_param.dely_mode = IMMEDIATE_DELY_MODE; |
| 2179 | adv_filt_param.feat_seln = ALLOW_ALL_FILTER; |
| 2180 | adv_filt_param.filt_logic_type = BTA_DM_BLE_PF_FILT_LOGIC_OR; |
| 2181 | adv_filt_param.list_logic_type = BTA_DM_BLE_PF_LIST_LOGIC_OR; |
| 2182 | adv_filt_param.rssi_low_thres = LOWEST_RSSI_VALUE; |
| 2183 | adv_filt_param.rssi_high_thres = LOWEST_RSSI_VALUE; |
| 2184 | BTA_DmBleScanFilterSetup(BTA_DM_BLE_SCAN_COND_ADD, 0, &adv_filt_param, NULL, |
| 2185 | bte_scan_filt_param_cfg_evt, 0); |
| 2186 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2187 | /* TODO: Do we need to handle multiple inquiries at the same time? */ |
| 2188 | |
| 2189 | /* Set inquiry params and call API */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2190 | inq_params.mode = BTA_DM_GENERAL_INQUIRY|BTA_BLE_GENERAL_INQUIRY; |
Matthew Xie | 7f3e429 | 2013-09-30 12:44:10 -0700 | [diff] [blame] | 2191 | #if (defined(BTA_HOST_INTERLEAVE_SEARCH) && BTA_HOST_INTERLEAVE_SEARCH == TRUE) |
| 2192 | inq_params.intl_duration[0]= BTIF_DM_INTERLEAVE_DURATION_BR_ONE; |
| 2193 | inq_params.intl_duration[1]= BTIF_DM_INTERLEAVE_DURATION_LE_ONE; |
| 2194 | inq_params.intl_duration[2]= BTIF_DM_INTERLEAVE_DURATION_BR_TWO; |
| 2195 | inq_params.intl_duration[3]= BTIF_DM_INTERLEAVE_DURATION_LE_TWO; |
| 2196 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2197 | #else |
| 2198 | inq_params.mode = BTA_DM_GENERAL_INQUIRY; |
| 2199 | #endif |
| 2200 | inq_params.duration = BTIF_DM_DEFAULT_INQ_MAX_DURATION; |
| 2201 | |
| 2202 | inq_params.max_resps = BTIF_DM_DEFAULT_INQ_MAX_RESULTS; |
| 2203 | inq_params.report_dup = TRUE; |
| 2204 | |
| 2205 | inq_params.filter_type = BTA_DM_INQ_CLR; |
| 2206 | /* TODO: Filter device by BDA needs to be implemented here */ |
| 2207 | |
| 2208 | /* Will be enabled to TRUE once inquiry busy level has been received */ |
| 2209 | btif_dm_inquiry_in_progress = FALSE; |
| 2210 | /* find nearby devices */ |
| 2211 | BTA_DmSearch(&inq_params, services, bte_search_devices_evt); |
| 2212 | |
| 2213 | return BT_STATUS_SUCCESS; |
| 2214 | } |
| 2215 | |
| 2216 | /******************************************************************************* |
| 2217 | ** |
| 2218 | ** Function btif_dm_cancel_discovery |
| 2219 | ** |
| 2220 | ** Description Cancels search |
| 2221 | ** |
| 2222 | ** Returns bt_status_t |
| 2223 | ** |
| 2224 | *******************************************************************************/ |
| 2225 | bt_status_t btif_dm_cancel_discovery(void) |
| 2226 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2227 | BTIF_TRACE_EVENT("%s", __FUNCTION__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2228 | BTA_DmSearchCancel(); |
| 2229 | return BT_STATUS_SUCCESS; |
| 2230 | } |
| 2231 | |
| 2232 | /******************************************************************************* |
| 2233 | ** |
| 2234 | ** Function btif_dm_create_bond |
| 2235 | ** |
| 2236 | ** Description Initiate bonding with the specified device |
| 2237 | ** |
| 2238 | ** Returns bt_status_t |
| 2239 | ** |
| 2240 | *******************************************************************************/ |
Andre Eisenbach | b0daa5d | 2014-08-04 17:50:10 -0700 | [diff] [blame] | 2241 | bt_status_t btif_dm_create_bond(const bt_bdaddr_t *bd_addr, int transport) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2242 | { |
Andre Eisenbach | b0daa5d | 2014-08-04 17:50:10 -0700 | [diff] [blame] | 2243 | btif_dm_create_bond_cb_t create_bond_cb; |
| 2244 | create_bond_cb.transport = transport; |
| 2245 | bdcpy(create_bond_cb.bdaddr.address, bd_addr->address); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2246 | |
Andre Eisenbach | b0daa5d | 2014-08-04 17:50:10 -0700 | [diff] [blame] | 2247 | bdstr_t bdstr; |
| 2248 | BTIF_TRACE_EVENT("%s: bd_addr=%s, transport=%d", __FUNCTION__, |
| 2249 | bd2str((bt_bdaddr_t *) bd_addr, &bdstr), transport); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2250 | if (pairing_cb.state != BT_BOND_STATE_NONE) |
| 2251 | return BT_STATUS_BUSY; |
| 2252 | |
| 2253 | btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_CREATE_BOND, |
Andre Eisenbach | b0daa5d | 2014-08-04 17:50:10 -0700 | [diff] [blame] | 2254 | (char *)&create_bond_cb, sizeof(btif_dm_create_bond_cb_t), NULL); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2255 | |
| 2256 | return BT_STATUS_SUCCESS; |
| 2257 | } |
| 2258 | |
| 2259 | /******************************************************************************* |
| 2260 | ** |
| 2261 | ** Function btif_dm_cancel_bond |
| 2262 | ** |
| 2263 | ** Description Initiate bonding with the specified device |
| 2264 | ** |
| 2265 | ** Returns bt_status_t |
| 2266 | ** |
| 2267 | *******************************************************************************/ |
| 2268 | |
| 2269 | bt_status_t btif_dm_cancel_bond(const bt_bdaddr_t *bd_addr) |
| 2270 | { |
| 2271 | bdstr_t bdstr; |
| 2272 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2273 | BTIF_TRACE_EVENT("%s: bd_addr=%s", __FUNCTION__, bd2str((bt_bdaddr_t *)bd_addr, &bdstr)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2274 | |
| 2275 | /* TODO: |
| 2276 | ** 1. Restore scan modes |
| 2277 | ** 2. special handling for HID devices |
| 2278 | */ |
| 2279 | if (pairing_cb.state == BT_BOND_STATE_BONDING) |
| 2280 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2281 | |
| 2282 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
| 2283 | |
| 2284 | if (pairing_cb.is_ssp) |
| 2285 | { |
| 2286 | if (pairing_cb.is_le_only) |
| 2287 | { |
| 2288 | BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT); |
| 2289 | } |
| 2290 | else |
Hemant Gupta | e146869 | 2013-11-14 16:21:29 +0530 | [diff] [blame] | 2291 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2292 | BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE); |
Hemant Gupta | e146869 | 2013-11-14 16:21:29 +0530 | [diff] [blame] | 2293 | BTA_DmBondCancel ((UINT8 *)bd_addr->address); |
| 2294 | btif_storage_remove_bonded_device((bt_bdaddr_t *)bd_addr); |
| 2295 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2296 | } |
| 2297 | else |
| 2298 | { |
| 2299 | if (pairing_cb.is_le_only) |
| 2300 | { |
| 2301 | BTA_DmBondCancel ((UINT8 *)bd_addr->address); |
| 2302 | } |
| 2303 | else |
| 2304 | { |
| 2305 | BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL); |
| 2306 | } |
| 2307 | /* Cancel bonding, in case it is in ACL connection setup state */ |
| 2308 | BTA_DmBondCancel ((UINT8 *)bd_addr->address); |
| 2309 | } |
| 2310 | |
| 2311 | #else |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2312 | if (pairing_cb.is_ssp) |
| 2313 | { |
| 2314 | BTA_DmConfirm( (UINT8 *)bd_addr->address, FALSE); |
| 2315 | } |
| 2316 | else |
| 2317 | { |
| 2318 | BTA_DmPinReply( (UINT8 *)bd_addr->address, FALSE, 0, NULL); |
| 2319 | } |
| 2320 | /* Cancel bonding, in case it is in ACL connection setup state */ |
| 2321 | BTA_DmBondCancel ((UINT8 *)bd_addr->address); |
| 2322 | btif_storage_remove_bonded_device((bt_bdaddr_t *)bd_addr); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2323 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2324 | } |
| 2325 | |
| 2326 | return BT_STATUS_SUCCESS; |
| 2327 | } |
| 2328 | |
| 2329 | /******************************************************************************* |
| 2330 | ** |
Kim Schulz | a9eb25c | 2013-09-30 10:55:52 +0200 | [diff] [blame] | 2331 | ** Function btif_dm_hh_open_failed |
| 2332 | ** |
| 2333 | ** Description informs the upper layers if the HH have failed during bonding |
| 2334 | ** |
| 2335 | ** Returns none |
| 2336 | ** |
| 2337 | *******************************************************************************/ |
| 2338 | |
| 2339 | void btif_dm_hh_open_failed(bt_bdaddr_t *bdaddr) |
| 2340 | { |
| 2341 | if (pairing_cb.state == BT_BOND_STATE_BONDING && |
| 2342 | bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0) |
| 2343 | { |
| 2344 | bond_state_changed(BT_STATUS_FAIL, bdaddr, BT_BOND_STATE_NONE); |
| 2345 | } |
| 2346 | } |
| 2347 | |
| 2348 | /******************************************************************************* |
| 2349 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2350 | ** Function btif_dm_remove_bond |
| 2351 | ** |
| 2352 | ** Description Removes bonding with the specified device |
| 2353 | ** |
| 2354 | ** Returns bt_status_t |
| 2355 | ** |
| 2356 | *******************************************************************************/ |
| 2357 | |
| 2358 | bt_status_t btif_dm_remove_bond(const bt_bdaddr_t *bd_addr) |
| 2359 | { |
| 2360 | bdstr_t bdstr; |
| 2361 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2362 | BTIF_TRACE_EVENT("%s: bd_addr=%s", __FUNCTION__, bd2str((bt_bdaddr_t *)bd_addr, &bdstr)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2363 | btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_REMOVE_BOND, |
| 2364 | (char *)bd_addr, sizeof(bt_bdaddr_t), NULL); |
| 2365 | |
| 2366 | return BT_STATUS_SUCCESS; |
| 2367 | } |
| 2368 | |
| 2369 | /******************************************************************************* |
| 2370 | ** |
| 2371 | ** Function btif_dm_pin_reply |
| 2372 | ** |
| 2373 | ** Description BT legacy pairing - PIN code reply |
| 2374 | ** |
| 2375 | ** Returns bt_status_t |
| 2376 | ** |
| 2377 | *******************************************************************************/ |
| 2378 | |
| 2379 | bt_status_t btif_dm_pin_reply( const bt_bdaddr_t *bd_addr, uint8_t accept, |
| 2380 | uint8_t pin_len, bt_pin_code_t *pin_code) |
| 2381 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2382 | BTIF_TRACE_EVENT("%s: accept=%d", __FUNCTION__, accept); |
Hemant Gupta | 831423e | 2014-01-08 12:42:13 +0530 | [diff] [blame] | 2383 | if (pin_code == NULL) |
| 2384 | return BT_STATUS_FAIL; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2385 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2386 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2387 | if (pairing_cb.is_le_only) |
| 2388 | { |
| 2389 | int i; |
| 2390 | UINT32 passkey = 0; |
| 2391 | int multi[] = {100000, 10000, 1000, 100, 10,1}; |
| 2392 | BD_ADDR remote_bd_addr; |
| 2393 | bdcpy(remote_bd_addr, bd_addr->address); |
| 2394 | for (i = 0; i < 6; i++) |
| 2395 | { |
| 2396 | passkey += (multi[i] * (pin_code->pin[i] - '0')); |
| 2397 | } |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2398 | BTIF_TRACE_DEBUG("btif_dm_pin_reply: passkey: %d", passkey); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2399 | BTA_DmBlePasskeyReply(remote_bd_addr, accept, passkey); |
| 2400 | |
| 2401 | } |
| 2402 | else |
| 2403 | { |
| 2404 | BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin); |
| 2405 | if (accept) |
| 2406 | pairing_cb.pin_code_len = pin_len; |
| 2407 | } |
| 2408 | #else |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2409 | BTA_DmPinReply( (UINT8 *)bd_addr->address, accept, pin_len, pin_code->pin); |
| 2410 | |
| 2411 | if (accept) |
| 2412 | pairing_cb.pin_code_len = pin_len; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2413 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2414 | return BT_STATUS_SUCCESS; |
| 2415 | } |
| 2416 | |
| 2417 | /******************************************************************************* |
| 2418 | ** |
| 2419 | ** Function btif_dm_ssp_reply |
| 2420 | ** |
| 2421 | ** Description BT SSP Reply - Just Works, Numeric Comparison & Passkey Entry |
| 2422 | ** |
| 2423 | ** Returns bt_status_t |
| 2424 | ** |
| 2425 | *******************************************************************************/ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2426 | bt_status_t btif_dm_ssp_reply(const bt_bdaddr_t *bd_addr, |
| 2427 | bt_ssp_variant_t variant, uint8_t accept, |
| 2428 | uint32_t passkey) |
| 2429 | { |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 2430 | UNUSED(passkey); |
| 2431 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2432 | if (variant == BT_SSP_VARIANT_PASSKEY_ENTRY) |
| 2433 | { |
| 2434 | /* This is not implemented in the stack. |
| 2435 | * For devices with display, this is not needed |
| 2436 | */ |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2437 | BTIF_TRACE_WARNING("%s: Not implemented", __FUNCTION__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2438 | return BT_STATUS_FAIL; |
| 2439 | } |
| 2440 | /* BT_SSP_VARIANT_CONSENT & BT_SSP_VARIANT_PASSKEY_CONFIRMATION supported */ |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2441 | BTIF_TRACE_EVENT("%s: accept=%d", __FUNCTION__, accept); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2442 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
| 2443 | if (pairing_cb.is_le_only) |
| 2444 | { |
| 2445 | if (accept) |
| 2446 | BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_GRANTED); |
| 2447 | else |
| 2448 | BTA_DmBleSecurityGrant((UINT8 *)bd_addr->address,BTA_DM_SEC_PAIR_NOT_SPT); |
| 2449 | } |
| 2450 | else |
| 2451 | BTA_DmConfirm( (UINT8 *)bd_addr->address, accept); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2452 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2453 | #else |
| 2454 | BTA_DmConfirm( (UINT8 *)bd_addr->address, accept); |
| 2455 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2456 | return BT_STATUS_SUCCESS; |
| 2457 | } |
| 2458 | |
| 2459 | /******************************************************************************* |
| 2460 | ** |
| 2461 | ** Function btif_dm_get_adapter_property |
| 2462 | ** |
| 2463 | ** Description Queries the BTA for the adapter property |
| 2464 | ** |
| 2465 | ** Returns bt_status_t |
| 2466 | ** |
| 2467 | *******************************************************************************/ |
| 2468 | bt_status_t btif_dm_get_adapter_property(bt_property_t *prop) |
| 2469 | { |
| 2470 | bt_status_t status; |
| 2471 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2472 | BTIF_TRACE_EVENT("%s: type=0x%x", __FUNCTION__, prop->type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2473 | switch (prop->type) |
| 2474 | { |
| 2475 | case BT_PROPERTY_BDNAME: |
| 2476 | { |
| 2477 | bt_bdname_t *bd_name = (bt_bdname_t*)prop->val; |
Matthew Xie | 1e5109b | 2012-11-09 18:26:26 -0800 | [diff] [blame] | 2478 | strcpy((char *)bd_name->name, btif_get_default_local_name()); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2479 | prop->len = strlen((char *)bd_name->name); |
| 2480 | } |
| 2481 | break; |
| 2482 | |
| 2483 | case BT_PROPERTY_ADAPTER_SCAN_MODE: |
| 2484 | { |
| 2485 | /* if the storage does not have it. Most likely app never set it. Default is NONE */ |
| 2486 | bt_scan_mode_t *mode = (bt_scan_mode_t*)prop->val; |
| 2487 | *mode = BT_SCAN_MODE_NONE; |
| 2488 | prop->len = sizeof(bt_scan_mode_t); |
| 2489 | } |
| 2490 | break; |
| 2491 | |
| 2492 | case BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT: |
| 2493 | { |
| 2494 | uint32_t *tmt = (uint32_t*)prop->val; |
| 2495 | *tmt = 120; /* default to 120s, if not found in NV */ |
| 2496 | prop->len = sizeof(uint32_t); |
| 2497 | } |
| 2498 | break; |
| 2499 | |
| 2500 | default: |
| 2501 | prop->len = 0; |
| 2502 | return BT_STATUS_FAIL; |
| 2503 | } |
| 2504 | return BT_STATUS_SUCCESS; |
| 2505 | } |
| 2506 | |
| 2507 | /******************************************************************************* |
| 2508 | ** |
| 2509 | ** Function btif_dm_get_remote_services |
| 2510 | ** |
| 2511 | ** Description Start SDP to get remote services |
| 2512 | ** |
| 2513 | ** Returns bt_status_t |
| 2514 | ** |
| 2515 | *******************************************************************************/ |
| 2516 | bt_status_t btif_dm_get_remote_services(bt_bdaddr_t *remote_addr) |
| 2517 | { |
| 2518 | bdstr_t bdstr; |
| 2519 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2520 | BTIF_TRACE_EVENT("%s: remote_addr=%s", __FUNCTION__, bd2str(remote_addr, &bdstr)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2521 | |
| 2522 | BTA_DmDiscover(remote_addr->address, BTA_ALL_SERVICE_MASK, |
| 2523 | bte_dm_search_services_evt, TRUE); |
| 2524 | |
| 2525 | return BT_STATUS_SUCCESS; |
| 2526 | } |
| 2527 | |
| 2528 | /******************************************************************************* |
| 2529 | ** |
| 2530 | ** Function btif_dm_get_remote_service_record |
| 2531 | ** |
| 2532 | ** Description Start SDP to get remote service record |
| 2533 | ** |
| 2534 | ** |
| 2535 | ** Returns bt_status_t |
| 2536 | *******************************************************************************/ |
| 2537 | bt_status_t btif_dm_get_remote_service_record(bt_bdaddr_t *remote_addr, |
| 2538 | bt_uuid_t *uuid) |
| 2539 | { |
| 2540 | tSDP_UUID sdp_uuid; |
| 2541 | bdstr_t bdstr; |
| 2542 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2543 | BTIF_TRACE_EVENT("%s: remote_addr=%s", __FUNCTION__, bd2str(remote_addr, &bdstr)); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2544 | |
| 2545 | sdp_uuid.len = MAX_UUID_SIZE; |
| 2546 | memcpy(sdp_uuid.uu.uuid128, uuid->uu, MAX_UUID_SIZE); |
| 2547 | |
| 2548 | BTA_DmDiscoverUUID(remote_addr->address, &sdp_uuid, |
| 2549 | bte_dm_remote_service_record_evt, TRUE); |
| 2550 | |
| 2551 | return BT_STATUS_SUCCESS; |
| 2552 | } |
| 2553 | |
| 2554 | void btif_dm_execute_service_request(UINT16 event, char *p_param) |
| 2555 | { |
| 2556 | BOOLEAN b_enable = FALSE; |
| 2557 | bt_status_t status; |
| 2558 | if (event == BTIF_DM_ENABLE_SERVICE) |
| 2559 | { |
| 2560 | b_enable = TRUE; |
| 2561 | } |
| 2562 | status = btif_in_execute_service_request(*((tBTA_SERVICE_ID*)p_param), b_enable); |
| 2563 | if (status == BT_STATUS_SUCCESS) |
| 2564 | { |
| 2565 | bt_property_t property; |
| 2566 | bt_uuid_t local_uuids[BT_MAX_NUM_UUIDS]; |
| 2567 | |
| 2568 | /* Now send the UUID_PROPERTY_CHANGED event to the upper layer */ |
| 2569 | BTIF_STORAGE_FILL_PROPERTY(&property, BT_PROPERTY_UUIDS, |
| 2570 | sizeof(local_uuids), local_uuids); |
| 2571 | btif_storage_get_adapter_property(&property); |
| 2572 | HAL_CBACK(bt_hal_cbacks, adapter_properties_cb, |
| 2573 | BT_STATUS_SUCCESS, 1, &property); |
| 2574 | } |
| 2575 | return; |
| 2576 | } |
| 2577 | |
Ganesh Ganapathi Batta | a217ab9 | 2014-04-28 16:30:55 -0700 | [diff] [blame] | 2578 | void btif_dm_proc_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, tBTA_OOB_DATA *p_oob_data, |
| 2579 | tBTA_AUTH_REQ *p_auth_req, BOOLEAN is_orig) |
| 2580 | { |
| 2581 | UINT8 yes_no_bit = BTA_AUTH_SP_YES & *p_auth_req; |
| 2582 | /* if local initiated: |
| 2583 | ** 1. set DD + MITM |
| 2584 | ** if remote initiated: |
| 2585 | ** 1. Copy over the auth_req from peer's io_rsp |
| 2586 | ** 2. Set the MITM if peer has it set or if peer has DisplayYesNo (iPhone) |
| 2587 | ** as a fallback set MITM+GB if peer had MITM set |
| 2588 | */ |
| 2589 | UNUSED (bd_addr); |
| 2590 | UNUSED (p_io_cap); |
| 2591 | UNUSED (p_oob_data); |
| 2592 | |
| 2593 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2594 | BTIF_TRACE_DEBUG("+%s: p_auth_req=%d", __FUNCTION__, *p_auth_req); |
Ganesh Ganapathi Batta | a217ab9 | 2014-04-28 16:30:55 -0700 | [diff] [blame] | 2595 | if(pairing_cb.is_local_initiated) |
| 2596 | { |
| 2597 | /* if initing/responding to a dedicated bonding, use dedicate bonding bit */ |
| 2598 | *p_auth_req = BTA_AUTH_DD_BOND | BTA_AUTH_SP_YES; |
| 2599 | } |
| 2600 | else if (!is_orig) |
| 2601 | { |
| 2602 | /* peer initiated paring. They probably know what they want. |
| 2603 | ** Copy the mitm from peer device. |
| 2604 | */ |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2605 | BTIF_TRACE_DEBUG("%s: setting p_auth_req to peer's: %d", |
Ganesh Ganapathi Batta | a217ab9 | 2014-04-28 16:30:55 -0700 | [diff] [blame] | 2606 | __FUNCTION__, pairing_cb.auth_req); |
| 2607 | *p_auth_req = (pairing_cb.auth_req & BTA_AUTH_BONDS); |
| 2608 | |
| 2609 | /* copy over the MITM bit as well. In addition if the peer has DisplayYesNo, force MITM */ |
| 2610 | if ((yes_no_bit) || (pairing_cb.io_cap & BTM_IO_CAP_IO) ) |
| 2611 | *p_auth_req |= BTA_AUTH_SP_YES; |
| 2612 | } |
| 2613 | else if (yes_no_bit) |
| 2614 | { |
| 2615 | /* set the general bonding bit for stored device */ |
| 2616 | *p_auth_req = BTA_AUTH_GEN_BOND | yes_no_bit; |
| 2617 | } |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2618 | BTIF_TRACE_DEBUG("-%s: p_auth_req=%d", __FUNCTION__, *p_auth_req); |
Ganesh Ganapathi Batta | a217ab9 | 2014-04-28 16:30:55 -0700 | [diff] [blame] | 2619 | } |
| 2620 | |
| 2621 | void btif_dm_proc_io_rsp(BD_ADDR bd_addr, tBTA_IO_CAP io_cap, |
| 2622 | tBTA_OOB_DATA oob_data, tBTA_AUTH_REQ auth_req) |
| 2623 | { |
| 2624 | UNUSED (bd_addr); |
| 2625 | UNUSED (oob_data); |
Andre Eisenbach | b0daa5d | 2014-08-04 17:50:10 -0700 | [diff] [blame] | 2626 | |
Ganesh Ganapathi Batta | a217ab9 | 2014-04-28 16:30:55 -0700 | [diff] [blame] | 2627 | if(auth_req & BTA_AUTH_BONDS) |
| 2628 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2629 | BTIF_TRACE_DEBUG("%s auth_req:%d", __FUNCTION__, auth_req); |
Ganesh Ganapathi Batta | a217ab9 | 2014-04-28 16:30:55 -0700 | [diff] [blame] | 2630 | pairing_cb.auth_req = auth_req; |
| 2631 | pairing_cb.io_cap = io_cap; |
| 2632 | } |
| 2633 | } |
| 2634 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2635 | #if (BTM_OOB_INCLUDED == TRUE) |
| 2636 | void btif_dm_set_oob_for_io_req(tBTA_OOB_DATA *p_oob_data) |
| 2637 | { |
| 2638 | if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 && |
| 2639 | oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 ) |
| 2640 | { |
| 2641 | *p_oob_data = FALSE; |
| 2642 | } |
| 2643 | else |
| 2644 | { |
| 2645 | *p_oob_data = TRUE; |
| 2646 | } |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2647 | BTIF_TRACE_DEBUG("btif_dm_set_oob_for_io_req *p_oob_data=%d", *p_oob_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2648 | } |
| 2649 | #endif /* BTM_OOB_INCLUDED */ |
| 2650 | |
| 2651 | #ifdef BTIF_DM_OOB_TEST |
| 2652 | void btif_dm_load_local_oob(void) |
| 2653 | { |
Nick Kralevich | d70b7a8 | 2013-01-31 14:40:15 -0800 | [diff] [blame] | 2654 | char prop_oob[PROPERTY_VALUE_MAX]; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2655 | property_get("service.brcm.bt.oob", prop_oob, "3"); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2656 | BTIF_TRACE_DEBUG("btif_dm_load_local_oob prop_oob = %s",prop_oob); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2657 | if (prop_oob[0] != '3') |
| 2658 | { |
| 2659 | #if (BTM_OOB_INCLUDED == TRUE) |
| 2660 | if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 && |
| 2661 | oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 ) |
| 2662 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2663 | BTIF_TRACE_DEBUG("btif_dm_load_local_oob: read OOB, call BTA_DmLocalOob()"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2664 | BTA_DmLocalOob(); |
| 2665 | } |
| 2666 | #else |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2667 | BTIF_TRACE_ERROR("BTM_OOB_INCLUDED is FALSE!!(btif_dm_load_local_oob)"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2668 | #endif |
| 2669 | } |
| 2670 | } |
| 2671 | |
| 2672 | void btif_dm_proc_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r) |
| 2673 | { |
| 2674 | FILE *fp; |
| 2675 | char *path_a = "/data/misc/bluedroid/LOCAL/a.key"; |
| 2676 | char *path_b = "/data/misc/bluedroid/LOCAL/b.key"; |
| 2677 | char *path = NULL; |
Nick Kralevich | d70b7a8 | 2013-01-31 14:40:15 -0800 | [diff] [blame] | 2678 | char prop_oob[PROPERTY_VALUE_MAX]; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2679 | BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob: valid=%d", valid); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2680 | if (oob_cb.sp_c[0] == 0 && oob_cb.sp_c[1] == 0 && |
| 2681 | oob_cb.sp_c[2] == 0 && oob_cb.sp_c[3] == 0 && |
| 2682 | valid) |
| 2683 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2684 | BTIF_TRACE_DEBUG("save local OOB data in memory"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2685 | memcpy(oob_cb.sp_c, c, BT_OCTET16_LEN); |
| 2686 | memcpy(oob_cb.sp_r, r, BT_OCTET16_LEN); |
| 2687 | property_get("service.brcm.bt.oob", prop_oob, "3"); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2688 | BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob prop_oob = %s",prop_oob); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2689 | if (prop_oob[0] == '1') |
| 2690 | path = path_a; |
| 2691 | else if (prop_oob[0] == '2') |
| 2692 | path = path_b; |
| 2693 | if (path) |
| 2694 | { |
| 2695 | fp = fopen(path, "wb+"); |
| 2696 | if (fp == NULL) |
| 2697 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2698 | BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob: failed to save local OOB data to %s", path); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2699 | } |
| 2700 | else |
| 2701 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2702 | BTIF_TRACE_DEBUG("btif_dm_proc_loc_oob: save local OOB data into file %s",path); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2703 | fwrite (c , 1 , BT_OCTET16_LEN , fp ); |
| 2704 | fwrite (r , 1 , BT_OCTET16_LEN , fp ); |
| 2705 | fclose(fp); |
| 2706 | } |
| 2707 | } |
| 2708 | } |
| 2709 | } |
| 2710 | BOOLEAN btif_dm_proc_rmt_oob(BD_ADDR bd_addr, BT_OCTET16 p_c, BT_OCTET16 p_r) |
| 2711 | { |
| 2712 | char t[128]; |
| 2713 | FILE *fp; |
| 2714 | char *path_a = "/data/misc/bluedroid/LOCAL/a.key"; |
| 2715 | char *path_b = "/data/misc/bluedroid/LOCAL/b.key"; |
| 2716 | char *path = NULL; |
Nick Kralevich | d70b7a8 | 2013-01-31 14:40:15 -0800 | [diff] [blame] | 2717 | char prop_oob[PROPERTY_VALUE_MAX]; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2718 | BOOLEAN result = FALSE; |
| 2719 | bt_bdaddr_t bt_bd_addr; |
| 2720 | bdcpy(oob_cb.oob_bdaddr, bd_addr); |
| 2721 | property_get("service.brcm.bt.oob", prop_oob, "3"); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2722 | BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob prop_oob = %s",prop_oob); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2723 | if (prop_oob[0] == '1') |
| 2724 | path = path_b; |
| 2725 | else if (prop_oob[0] == '2') |
| 2726 | path = path_a; |
| 2727 | if (path) |
| 2728 | { |
| 2729 | fp = fopen(path, "rb"); |
| 2730 | if (fp == NULL) |
| 2731 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2732 | BTIF_TRACE_DEBUG("btapp_dm_rmt_oob_reply: failed to read OOB keys from %s",path); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2733 | return FALSE; |
| 2734 | } |
| 2735 | else |
| 2736 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2737 | BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob: read OOB data from %s",path); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2738 | fread (p_c , 1 , BT_OCTET16_LEN , fp ); |
| 2739 | fread (p_r , 1 , BT_OCTET16_LEN , fp ); |
| 2740 | fclose(fp); |
| 2741 | } |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2742 | BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: TRUE"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2743 | sprintf(t, "%02x:%02x:%02x:%02x:%02x:%02x", |
| 2744 | oob_cb.oob_bdaddr[0], oob_cb.oob_bdaddr[1], oob_cb.oob_bdaddr[2], |
| 2745 | oob_cb.oob_bdaddr[3], oob_cb.oob_bdaddr[4], oob_cb.oob_bdaddr[5]); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2746 | BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: peer_bdaddr = %s", t); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2747 | sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", |
| 2748 | p_c[0], p_c[1], p_c[2], p_c[3], p_c[4], p_c[5], p_c[6], p_c[7], |
| 2749 | p_c[8], p_c[9], p_c[10], p_c[11], p_c[12], p_c[13], p_c[14], p_c[15]); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2750 | BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: c = %s",t); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2751 | sprintf(t, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", |
| 2752 | p_r[0], p_r[1], p_r[2], p_r[3], p_r[4], p_r[5], p_r[6], p_r[7], |
| 2753 | p_r[8], p_r[9], p_r[10], p_r[11], p_r[12], p_r[13], p_r[14], p_r[15]); |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2754 | BTIF_TRACE_DEBUG("----btif_dm_proc_rmt_oob: r = %s",t); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2755 | bdcpy(bt_bd_addr.address, bd_addr); |
| 2756 | btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_BOND_STATE_BONDING, |
| 2757 | (char *)&bt_bd_addr, sizeof(bt_bdaddr_t), NULL); |
| 2758 | result = TRUE; |
| 2759 | } |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2760 | BTIF_TRACE_DEBUG("btif_dm_proc_rmt_oob result=%d",result); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2761 | return result; |
| 2762 | } |
| 2763 | #endif /* BTIF_DM_OOB_TEST */ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2764 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
| 2765 | |
| 2766 | static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF *p_ssp_key_notif) |
| 2767 | { |
| 2768 | bt_bdaddr_t bd_addr; |
| 2769 | bt_bdname_t bd_name; |
| 2770 | UINT32 cod; |
Matthew Xie | 86f97ed | 2014-11-10 10:24:46 -0800 | [diff] [blame] | 2771 | int dev_type; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2772 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2773 | BTIF_TRACE_DEBUG("%s", __FUNCTION__); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2774 | |
| 2775 | /* Remote name update */ |
Matthew Xie | 86f97ed | 2014-11-10 10:24:46 -0800 | [diff] [blame] | 2776 | if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type)) |
| 2777 | { |
| 2778 | dev_type = BT_DEVICE_TYPE_BLE; |
| 2779 | } |
| 2780 | btif_dm_update_ble_remote_properties(p_ssp_key_notif->bd_addr , p_ssp_key_notif->bd_name, |
| 2781 | (tBT_DEVICE_TYPE) dev_type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2782 | bdcpy(bd_addr.address, p_ssp_key_notif->bd_addr); |
| 2783 | memcpy(bd_name.name, p_ssp_key_notif->bd_name, BD_NAME_LEN); |
| 2784 | |
| 2785 | bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING); |
| 2786 | pairing_cb.is_ssp = FALSE; |
| 2787 | cod = COD_UNCLASSIFIED; |
| 2788 | |
| 2789 | HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, |
| 2790 | cod, BT_SSP_VARIANT_PASSKEY_NOTIFICATION, |
| 2791 | p_ssp_key_notif->passkey); |
| 2792 | } |
| 2793 | |
| 2794 | /******************************************************************************* |
| 2795 | ** |
| 2796 | ** Function btif_dm_ble_auth_cmpl_evt |
| 2797 | ** |
| 2798 | ** Description Executes authentication complete event in btif context |
| 2799 | ** |
| 2800 | ** Returns void |
| 2801 | ** |
| 2802 | *******************************************************************************/ |
| 2803 | static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl) |
| 2804 | { |
| 2805 | /* Save link key, if not temporary */ |
| 2806 | bt_bdaddr_t bd_addr; |
| 2807 | bt_status_t status = BT_STATUS_FAIL; |
| 2808 | bt_bond_state_t state = BT_BOND_STATE_NONE; |
| 2809 | |
| 2810 | bdcpy(bd_addr.address, p_auth_cmpl->bd_addr); |
| 2811 | if ( (p_auth_cmpl->success == TRUE) && (p_auth_cmpl->key_present) ) |
| 2812 | { |
| 2813 | /* store keys */ |
| 2814 | } |
| 2815 | if (p_auth_cmpl->success) |
| 2816 | { |
| 2817 | status = BT_STATUS_SUCCESS; |
| 2818 | state = BT_BOND_STATE_BONDED; |
| 2819 | |
| 2820 | btif_dm_save_ble_bonding_keys(); |
| 2821 | BTA_GATTC_Refresh(bd_addr.address); |
| 2822 | btif_dm_get_remote_services(&bd_addr); |
| 2823 | } |
| 2824 | else |
| 2825 | { |
| 2826 | /*Map the HCI fail reason to bt status */ |
| 2827 | switch (p_auth_cmpl->fail_reason) |
| 2828 | { |
Priti Aghera | 156c52b | 2014-07-09 14:58:19 -0700 | [diff] [blame] | 2829 | case BTA_DM_AUTH_SMP_PAIR_AUTH_FAIL: |
| 2830 | case BTA_DM_AUTH_SMP_CONFIRM_VALUE_FAIL: |
| 2831 | btif_dm_remove_ble_bonding_keys(); |
| 2832 | status = BT_STATUS_AUTH_FAILURE; |
| 2833 | break; |
| 2834 | case BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT: |
| 2835 | status = BT_STATUS_AUTH_REJECTED; |
| 2836 | break; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2837 | default: |
Andre Eisenbach | ca22ac4 | 2013-02-13 17:02:11 +0900 | [diff] [blame] | 2838 | btif_dm_remove_ble_bonding_keys(); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2839 | status = BT_STATUS_FAIL; |
| 2840 | break; |
| 2841 | } |
| 2842 | } |
| 2843 | bond_state_changed(status, &bd_addr, state); |
| 2844 | } |
| 2845 | |
| 2846 | |
| 2847 | |
| 2848 | void btif_dm_load_ble_local_keys(void) |
| 2849 | { |
| 2850 | bt_status_t bt_status; |
| 2851 | |
| 2852 | memset(&ble_local_key_cb, 0, sizeof(btif_dm_local_key_cb_t)); |
| 2853 | |
| 2854 | if (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_ER,(char*)&ble_local_key_cb.er[0], |
| 2855 | BT_OCTET16_LEN)== BT_STATUS_SUCCESS) |
| 2856 | { |
| 2857 | ble_local_key_cb.is_er_rcvd = TRUE; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2858 | BTIF_TRACE_DEBUG("%s BLE ER key loaded",__FUNCTION__ ); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2859 | } |
| 2860 | |
| 2861 | if ((btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IR,(char*)&ble_local_key_cb.id_keys.ir[0], |
| 2862 | BT_OCTET16_LEN)== BT_STATUS_SUCCESS )&& |
| 2863 | (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_IRK, (char*)&ble_local_key_cb.id_keys.irk[0], |
| 2864 | BT_OCTET16_LEN)== BT_STATUS_SUCCESS)&& |
| 2865 | (btif_storage_get_ble_local_key(BTIF_DM_LE_LOCAL_KEY_DHK,(char*)&ble_local_key_cb.id_keys.dhk[0], |
| 2866 | BT_OCTET16_LEN)== BT_STATUS_SUCCESS)) |
| 2867 | { |
| 2868 | ble_local_key_cb.is_id_keys_rcvd = TRUE; |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2869 | BTIF_TRACE_DEBUG("%s BLE ID keys loaded",__FUNCTION__ ); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2870 | } |
| 2871 | |
| 2872 | } |
| 2873 | void btif_dm_get_ble_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er, |
| 2874 | tBTA_BLE_LOCAL_ID_KEYS *p_id_keys) |
| 2875 | { |
| 2876 | if (ble_local_key_cb.is_er_rcvd ) |
| 2877 | { |
| 2878 | memcpy(&er[0], &ble_local_key_cb.er[0], sizeof(BT_OCTET16)); |
| 2879 | *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ER; |
| 2880 | } |
| 2881 | |
| 2882 | if (ble_local_key_cb.is_id_keys_rcvd) |
| 2883 | { |
| 2884 | memcpy(&p_id_keys->ir[0], &ble_local_key_cb.id_keys.ir[0], sizeof(BT_OCTET16)); |
| 2885 | memcpy(&p_id_keys->irk[0], &ble_local_key_cb.id_keys.irk[0], sizeof(BT_OCTET16)); |
| 2886 | memcpy(&p_id_keys->dhk[0], &ble_local_key_cb.id_keys.dhk[0], sizeof(BT_OCTET16)); |
| 2887 | *p_key_mask |= BTA_BLE_LOCAL_KEY_TYPE_ID; |
| 2888 | } |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2889 | BTIF_TRACE_DEBUG("%s *p_key_mask=0x%02x",__FUNCTION__, *p_key_mask); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2890 | } |
| 2891 | |
| 2892 | void btif_dm_save_ble_bonding_keys(void) |
| 2893 | { |
| 2894 | |
| 2895 | bt_bdaddr_t bd_addr; |
| 2896 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2897 | BTIF_TRACE_DEBUG("%s",__FUNCTION__ ); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2898 | |
| 2899 | bdcpy(bd_addr.address, pairing_cb.bd_addr); |
| 2900 | |
| 2901 | if (pairing_cb.ble.is_penc_key_rcvd) |
| 2902 | { |
| 2903 | btif_storage_add_ble_bonding_key(&bd_addr, |
| 2904 | (char *) &pairing_cb.ble.penc_key, |
| 2905 | BTIF_DM_LE_KEY_PENC, |
| 2906 | sizeof(btif_dm_ble_penc_keys_t)); |
| 2907 | } |
| 2908 | |
| 2909 | if (pairing_cb.ble.is_pid_key_rcvd) |
| 2910 | { |
| 2911 | btif_storage_add_ble_bonding_key(&bd_addr, |
Andre Eisenbach | 5e80846 | 2014-10-21 12:37:53 -0700 | [diff] [blame] | 2912 | (char *) &pairing_cb.ble.pid_key, |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2913 | BTIF_DM_LE_KEY_PID, |
Andre Eisenbach | 5e80846 | 2014-10-21 12:37:53 -0700 | [diff] [blame] | 2914 | sizeof(btif_dm_ble_pid_keys_t)); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2915 | } |
| 2916 | |
| 2917 | |
| 2918 | if (pairing_cb.ble.is_pcsrk_key_rcvd) |
| 2919 | { |
| 2920 | btif_storage_add_ble_bonding_key(&bd_addr, |
| 2921 | (char *) &pairing_cb.ble.pcsrk_key, |
| 2922 | BTIF_DM_LE_KEY_PCSRK, |
| 2923 | sizeof(btif_dm_ble_pcsrk_keys_t)); |
| 2924 | } |
| 2925 | |
| 2926 | |
| 2927 | if (pairing_cb.ble.is_lenc_key_rcvd) |
| 2928 | { |
| 2929 | btif_storage_add_ble_bonding_key(&bd_addr, |
| 2930 | (char *) &pairing_cb.ble.lenc_key, |
| 2931 | BTIF_DM_LE_KEY_LENC, |
| 2932 | sizeof(btif_dm_ble_lenc_keys_t)); |
| 2933 | } |
| 2934 | |
| 2935 | if (pairing_cb.ble.is_lcsrk_key_rcvd) |
| 2936 | { |
| 2937 | btif_storage_add_ble_bonding_key(&bd_addr, |
| 2938 | (char *) &pairing_cb.ble.lcsrk_key, |
| 2939 | BTIF_DM_LE_KEY_LCSRK, |
| 2940 | sizeof(btif_dm_ble_lcsrk_keys_t)); |
| 2941 | } |
| 2942 | |
| 2943 | } |
| 2944 | |
| 2945 | |
| 2946 | void btif_dm_remove_ble_bonding_keys(void) |
| 2947 | { |
| 2948 | bt_bdaddr_t bd_addr; |
| 2949 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2950 | BTIF_TRACE_DEBUG("%s",__FUNCTION__ ); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2951 | |
| 2952 | bdcpy(bd_addr.address, pairing_cb.bd_addr); |
| 2953 | btif_storage_remove_ble_bonding_keys(&bd_addr); |
| 2954 | } |
| 2955 | |
| 2956 | |
| 2957 | /******************************************************************************* |
| 2958 | ** |
| 2959 | ** Function btif_dm_ble_sec_req_evt |
| 2960 | ** |
| 2961 | ** Description Eprocess security request event in btif context |
| 2962 | ** |
| 2963 | ** Returns void |
| 2964 | ** |
| 2965 | *******************************************************************************/ |
| 2966 | void btif_dm_ble_sec_req_evt(tBTA_DM_BLE_SEC_REQ *p_ble_req) |
| 2967 | { |
| 2968 | bt_bdaddr_t bd_addr; |
| 2969 | bt_bdname_t bd_name; |
| 2970 | UINT32 cod; |
Matthew Xie | 86f97ed | 2014-11-10 10:24:46 -0800 | [diff] [blame] | 2971 | int dev_type; |
| 2972 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2973 | BTIF_TRACE_DEBUG("%s", __FUNCTION__); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2974 | |
| 2975 | if (pairing_cb.state == BT_BOND_STATE_BONDING) |
| 2976 | { |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 2977 | BTIF_TRACE_DEBUG("%s Discard security request", __FUNCTION__); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2978 | return; |
| 2979 | } |
| 2980 | |
| 2981 | /* Remote name update */ |
Matthew Xie | 86f97ed | 2014-11-10 10:24:46 -0800 | [diff] [blame] | 2982 | if (!btif_get_device_type(p_ble_req->bd_addr, &dev_type)) |
| 2983 | { |
| 2984 | dev_type = BT_DEVICE_TYPE_BLE; |
| 2985 | } |
| 2986 | btif_dm_update_ble_remote_properties(p_ble_req->bd_addr, p_ble_req->bd_name, |
| 2987 | (tBT_DEVICE_TYPE) dev_type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2988 | |
| 2989 | bdcpy(bd_addr.address, p_ble_req->bd_addr); |
| 2990 | memcpy(bd_name.name, p_ble_req->bd_name, BD_NAME_LEN); |
| 2991 | |
| 2992 | bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING); |
| 2993 | |
| 2994 | pairing_cb.is_temp = FALSE; |
| 2995 | pairing_cb.is_le_only = TRUE; |
| 2996 | pairing_cb.is_ssp = TRUE; |
| 2997 | |
| 2998 | cod = COD_UNCLASSIFIED; |
| 2999 | |
| 3000 | HAL_CBACK(bt_hal_cbacks, ssp_request_cb, &bd_addr, &bd_name, cod, |
| 3001 | BT_SSP_VARIANT_CONSENT, 0); |
| 3002 | } |
| 3003 | |
| 3004 | |
| 3005 | |
| 3006 | /******************************************************************************* |
| 3007 | ** |
| 3008 | ** Function btif_dm_ble_passkey_req_evt |
| 3009 | ** |
| 3010 | ** Description Executes pin request event in btif context |
| 3011 | ** |
| 3012 | ** Returns void |
| 3013 | ** |
| 3014 | *******************************************************************************/ |
| 3015 | static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ *p_pin_req) |
| 3016 | { |
| 3017 | bt_bdaddr_t bd_addr; |
| 3018 | bt_bdname_t bd_name; |
| 3019 | UINT32 cod; |
Matthew Xie | 86f97ed | 2014-11-10 10:24:46 -0800 | [diff] [blame] | 3020 | int dev_type; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3021 | |
| 3022 | /* Remote name update */ |
Matthew Xie | 86f97ed | 2014-11-10 10:24:46 -0800 | [diff] [blame] | 3023 | if (!btif_get_device_type(p_pin_req->bd_addr, &dev_type)) |
| 3024 | { |
| 3025 | dev_type = BT_DEVICE_TYPE_BLE; |
| 3026 | } |
| 3027 | btif_dm_update_ble_remote_properties(p_pin_req->bd_addr,p_pin_req->bd_name, |
| 3028 | (tBT_DEVICE_TYPE) dev_type); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3029 | |
| 3030 | bdcpy(bd_addr.address, p_pin_req->bd_addr); |
| 3031 | memcpy(bd_name.name, p_pin_req->bd_name, BD_NAME_LEN); |
| 3032 | |
| 3033 | bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING); |
| 3034 | pairing_cb.is_le_only = TRUE; |
| 3035 | |
| 3036 | cod = COD_UNCLASSIFIED; |
| 3037 | |
| 3038 | HAL_CBACK(bt_hal_cbacks, pin_request_cb, |
| 3039 | &bd_addr, &bd_name, cod); |
| 3040 | } |
| 3041 | |
| 3042 | |
| 3043 | void btif_dm_update_ble_remote_properties( BD_ADDR bd_addr, BD_NAME bd_name, |
| 3044 | tBT_DEVICE_TYPE dev_type) |
| 3045 | { |
| 3046 | btif_update_remote_properties(bd_addr,bd_name,NULL,dev_type); |
| 3047 | } |
| 3048 | |
| 3049 | static void btif_dm_ble_tx_test_cback(void *p) |
| 3050 | { |
| 3051 | btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TX_TEST, |
| 3052 | (char *)p, 1, NULL); |
| 3053 | } |
| 3054 | |
| 3055 | static void btif_dm_ble_rx_test_cback(void *p) |
| 3056 | { |
| 3057 | btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_RX_TEST, |
| 3058 | (char *)p, 1, NULL); |
| 3059 | } |
| 3060 | |
| 3061 | static void btif_dm_ble_test_end_cback(void *p) |
| 3062 | { |
| 3063 | btif_transfer_context(btif_dm_generic_evt, BTIF_DM_CB_LE_TEST_END, |
| 3064 | (char *)p, 3, NULL); |
| 3065 | } |
| 3066 | /******************************************************************************* |
| 3067 | ** |
| 3068 | ** Function btif_le_test_mode |
| 3069 | ** |
| 3070 | ** Description Sends a HCI BLE Test command to the Controller |
| 3071 | ** |
| 3072 | ** Returns BT_STATUS_SUCCESS on success |
| 3073 | ** |
| 3074 | *******************************************************************************/ |
| 3075 | bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t len) |
| 3076 | { |
| 3077 | switch (opcode) { |
| 3078 | case HCI_BLE_TRANSMITTER_TEST: |
| 3079 | if (len != 3) return BT_STATUS_PARM_INVALID; |
| 3080 | BTM_BleTransmitterTest(buf[0],buf[1],buf[2], btif_dm_ble_tx_test_cback); |
| 3081 | break; |
| 3082 | case HCI_BLE_RECEIVER_TEST: |
| 3083 | if (len != 1) return BT_STATUS_PARM_INVALID; |
| 3084 | BTM_BleReceiverTest(buf[0], btif_dm_ble_rx_test_cback); |
| 3085 | break; |
| 3086 | case HCI_BLE_TEST_END: |
| 3087 | BTM_BleTestEnd((tBTM_CMPL_CB*) btif_dm_ble_test_end_cback); |
| 3088 | break; |
| 3089 | default: |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 3090 | BTIF_TRACE_ERROR("%s: Unknown LE Test Mode Command 0x%x", __FUNCTION__, opcode); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 3091 | return BT_STATUS_UNSUPPORTED; |
| 3092 | } |
| 3093 | return BT_STATUS_SUCCESS; |
| 3094 | } |
| 3095 | |
| 3096 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3097 | |
| 3098 | void btif_dm_on_disable() |
| 3099 | { |
| 3100 | /* cancel any pending pairing requests */ |
| 3101 | if (pairing_cb.state == BT_BOND_STATE_BONDING) |
| 3102 | { |
| 3103 | bt_bdaddr_t bd_addr; |
| 3104 | |
Sharvil Nanavati | e8c3d75 | 2014-05-04 10:12:26 -0700 | [diff] [blame] | 3105 | BTIF_TRACE_DEBUG("%s: Cancel pending pairing request", __FUNCTION__); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 3106 | bdcpy(bd_addr.address, pairing_cb.bd_addr); |
| 3107 | btif_dm_cancel_bond(&bd_addr); |
| 3108 | } |
| 3109 | } |
Matthew Xie | 1e5109b | 2012-11-09 18:26:26 -0800 | [diff] [blame] | 3110 | |
Satya Calloji | e5ba884 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 3111 | /******************************************************************************* |
| 3112 | ** |
| 3113 | ** Function btif_dm_read_energy_info |
| 3114 | ** |
| 3115 | ** Description Reads the energy info from controller |
| 3116 | ** |
| 3117 | ** Returns void |
| 3118 | ** |
| 3119 | *******************************************************************************/ |
| 3120 | void btif_dm_read_energy_info() |
| 3121 | { |
Prerepa Viswanadham | 81b0319 | 2014-07-23 17:49:48 -0700 | [diff] [blame] | 3122 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
Satya Calloji | e5ba884 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 3123 | BTA_DmBleGetEnergyInfo(bta_energy_info_cb); |
Prerepa Viswanadham | 81b0319 | 2014-07-23 17:49:48 -0700 | [diff] [blame] | 3124 | #endif |
Satya Calloji | e5ba884 | 2014-07-03 17:18:02 -0700 | [diff] [blame] | 3125 | } |
| 3126 | |
Matthew Xie | 1e5109b | 2012-11-09 18:26:26 -0800 | [diff] [blame] | 3127 | static char* btif_get_default_local_name() { |
| 3128 | if (btif_default_local_name[0] == '\0') |
| 3129 | { |
| 3130 | int max_len = sizeof(btif_default_local_name) - 1; |
| 3131 | if (BTM_DEF_LOCAL_NAME[0] != '\0') |
| 3132 | { |
| 3133 | strncpy(btif_default_local_name, BTM_DEF_LOCAL_NAME, max_len); |
| 3134 | } |
| 3135 | else |
| 3136 | { |
| 3137 | char prop_model[PROPERTY_VALUE_MAX]; |
| 3138 | property_get(PROPERTY_PRODUCT_MODEL, prop_model, ""); |
| 3139 | strncpy(btif_default_local_name, prop_model, max_len); |
| 3140 | } |
| 3141 | btif_default_local_name[max_len] = '\0'; |
| 3142 | } |
| 3143 | return btif_default_local_name; |
| 3144 | } |