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