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