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