The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright (C) 1999-2012 Broadcom Corporation |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | * you may not use this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at: |
| 8 | * |
| 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | * |
| 17 | ******************************************************************************/ |
| 18 | |
| 19 | /****************************************************************************** |
| 20 | * |
| 21 | * This file contains functions for BLE device control utilities, and LE |
| 22 | * security functions. |
| 23 | * |
| 24 | ******************************************************************************/ |
Mike J. Chen | bf9a8aa | 2014-02-11 13:51:29 -0800 | [diff] [blame] | 25 | #include "bt_target.h" |
| 26 | |
| 27 | #if BLE_INCLUDED == TRUE |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 28 | |
| 29 | #include <string.h> |
| 30 | |
| 31 | #include "bt_types.h" |
| 32 | #include "hcimsgs.h" |
| 33 | #include "btu.h" |
| 34 | #include "btm_int.h" |
| 35 | #include "btm_ble_api.h" |
| 36 | #include "smp_api.h" |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 37 | #include "l2c_int.h" |
| 38 | #include "gap_api.h" |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 39 | #include "bt_utils.h" |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 40 | |
Satya Calloji | 0943c10 | 2014-05-12 09:13:02 -0700 | [diff] [blame] | 41 | #if (defined BLE_VND_INCLUDED && BLE_VND_INCLUDED == TRUE) |
| 42 | #include "vendor_ble.h" |
| 43 | #endif |
| 44 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 45 | #if SMP_INCLUDED == TRUE |
| 46 | extern BOOLEAN AES_CMAC ( BT_OCTET16 key, UINT8 *input, UINT16 length, UINT16 tlen, UINT8 *p_signature); |
| 47 | extern void smp_link_encrypted(BD_ADDR bda, UINT8 encr_enable); |
| 48 | extern BOOLEAN smp_proc_ltk_request(BD_ADDR bda); |
| 49 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 50 | extern void gatt_notify_enc_cmpl(BD_ADDR bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 51 | |
| 52 | /*******************************************************************************/ |
| 53 | /* External Function to be called by other modules */ |
| 54 | /*******************************************************************************/ |
| 55 | /******************************************************** |
| 56 | ** |
| 57 | ** Function BTM_SecAddBleDevice |
| 58 | ** |
| 59 | ** Description Add/modify device. This function will be normally called |
| 60 | ** during host startup to restore all required information |
| 61 | ** for a LE device stored in the NVRAM. |
| 62 | ** |
| 63 | ** Parameters: bd_addr - BD address of the peer |
| 64 | ** bd_name - Name of the peer device. NULL if unknown. |
| 65 | ** dev_type - Remote device's device type. |
| 66 | ** addr_type - LE device address type. |
| 67 | ** |
| 68 | ** Returns TRUE if added OK, else FALSE |
| 69 | ** |
| 70 | *******************************************************************************/ |
| 71 | BOOLEAN BTM_SecAddBleDevice (BD_ADDR bd_addr, BD_NAME bd_name, tBT_DEVICE_TYPE dev_type, |
| 72 | tBLE_ADDR_TYPE addr_type) |
| 73 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 74 | tBTM_SEC_DEV_REC *p_dev_rec; |
| 75 | UINT8 i = 0; |
| 76 | tBTM_INQ_INFO *p_info=NULL; |
| 77 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 78 | BTM_TRACE_DEBUG ("BTM_SecAddBleDevice dev_type=0x%x", dev_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 79 | p_dev_rec = btm_find_dev (bd_addr); |
| 80 | |
| 81 | if (!p_dev_rec) |
| 82 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 83 | BTM_TRACE_DEBUG("Add a new device"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 84 | |
| 85 | /* There is no device record, allocate one. |
| 86 | * If we can not find an empty spot for this one, let it fail. */ |
| 87 | for (i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i++) |
| 88 | { |
| 89 | if (!(btm_cb.sec_dev_rec[i].sec_flags & BTM_SEC_IN_USE)) |
| 90 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 91 | BTM_TRACE_DEBUG ("allocate a new dev rec idx=0x%x ", i ); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 92 | p_dev_rec = &btm_cb.sec_dev_rec[i]; |
| 93 | |
| 94 | /* Mark this record as in use and initialize */ |
| 95 | memset (p_dev_rec, 0, sizeof (tBTM_SEC_DEV_REC)); |
| 96 | p_dev_rec->sec_flags = BTM_SEC_IN_USE; |
| 97 | memcpy (p_dev_rec->bd_addr, bd_addr, BD_ADDR_LEN); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 98 | p_dev_rec->hci_handle = BTM_GetHCIConnHandle (bd_addr, BT_TRANSPORT_BR_EDR); |
| 99 | p_dev_rec->ble_hci_handle = BTM_GetHCIConnHandle (bd_addr, BT_TRANSPORT_LE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 100 | |
| 101 | /* update conn params, use default value for background connection params */ |
| 102 | p_dev_rec->conn_params.min_conn_int = |
| 103 | p_dev_rec->conn_params.max_conn_int = |
| 104 | p_dev_rec->conn_params.supervision_tout = |
| 105 | p_dev_rec->conn_params.slave_latency = BTM_BLE_CONN_PARAM_UNDEF; |
| 106 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 107 | BTM_TRACE_DEBUG ("hci_handl=0x%x ", p_dev_rec->ble_hci_handle ); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 108 | break; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | if (!p_dev_rec) |
| 113 | return(FALSE); |
| 114 | } |
| 115 | else |
| 116 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 117 | BTM_TRACE_DEBUG("Device already exist"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | memset(p_dev_rec->sec_bd_name, 0, sizeof(tBTM_BD_NAME)); |
| 121 | |
| 122 | if (bd_name && bd_name[0]) |
| 123 | { |
| 124 | p_dev_rec->sec_flags |= BTM_SEC_NAME_KNOWN; |
| 125 | BCM_STRNCPY_S ((char *)p_dev_rec->sec_bd_name, sizeof (p_dev_rec->sec_bd_name), |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 126 | (char *)bd_name, BTM_MAX_REM_BD_NAME_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 127 | } |
| 128 | p_dev_rec->device_type = dev_type; |
| 129 | p_dev_rec->ble.ble_addr_type = addr_type; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 130 | BTM_TRACE_DEBUG ("p_dev_rec->device_type =0x%x addr_type=0x%x sec_flags=0x%x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 131 | dev_type, addr_type, p_dev_rec->sec_flags); |
| 132 | |
| 133 | /* sync up with the Inq Data base*/ |
| 134 | p_info = BTM_InqDbRead(bd_addr); |
| 135 | if (p_info) |
| 136 | { |
| 137 | p_info->results.ble_addr_type = p_dev_rec->ble.ble_addr_type ; |
| 138 | p_info->results.device_type = p_dev_rec->device_type; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 139 | BTM_TRACE_DEBUG ("InqDb device_type =0x%x addr_type=0x%x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 140 | p_info->results.device_type, p_info->results.ble_addr_type); |
| 141 | } |
| 142 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 143 | return(TRUE); |
| 144 | } |
| 145 | |
| 146 | /******************************************************************************* |
| 147 | ** |
| 148 | ** Function BTM_SecAddBleKey |
| 149 | ** |
| 150 | ** Description Add/modify LE device information. This function will be |
| 151 | ** normally called during host startup to restore all required |
| 152 | ** information stored in the NVRAM. |
| 153 | ** |
| 154 | ** Parameters: bd_addr - BD address of the peer |
| 155 | ** p_le_key - LE key values. |
| 156 | ** key_type - LE SMP key type. |
| 157 | * |
| 158 | ** Returns TRUE if added OK, else FALSE |
| 159 | ** |
| 160 | *******************************************************************************/ |
| 161 | BOOLEAN BTM_SecAddBleKey (BD_ADDR bd_addr, tBTM_LE_KEY_VALUE *p_le_key, tBTM_LE_KEY_TYPE key_type) |
| 162 | { |
Mike J. Chen | bf9a8aa | 2014-02-11 13:51:29 -0800 | [diff] [blame] | 163 | #if SMP_INCLUDED == TRUE |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 164 | tBTM_SEC_DEV_REC *p_dev_rec; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 165 | BTM_TRACE_DEBUG ("BTM_SecAddBleKey"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 166 | p_dev_rec = btm_find_dev (bd_addr); |
| 167 | if (!p_dev_rec || !p_le_key || |
| 168 | (key_type != BTM_LE_KEY_PENC && key_type != BTM_LE_KEY_PID && |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 169 | key_type != BTM_LE_KEY_PCSRK && key_type != BTM_LE_KEY_LENC && |
| 170 | key_type != BTM_LE_KEY_LCSRK)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 171 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 172 | BTM_TRACE_WARNING ("BTM_SecAddBleKey() Wrong Type, or No Device record \ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 173 | for bdaddr: %08x%04x, Type: %d", |
| 174 | (bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8)+bd_addr[3], |
| 175 | (bd_addr[4]<<8)+bd_addr[5], key_type); |
| 176 | return(FALSE); |
| 177 | } |
| 178 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 179 | BTM_TRACE_DEBUG ("BTM_SecAddLeKey() BDA: %08x%04x, Type: 0x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 180 | (bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8)+bd_addr[3], |
| 181 | (bd_addr[4]<<8)+bd_addr[5], key_type); |
| 182 | |
| 183 | if (key_type == BTM_LE_KEY_PENC || key_type == BTM_LE_KEY_PID || |
| 184 | key_type == BTM_LE_KEY_PCSRK || key_type == BTM_LE_KEY_LENC || |
| 185 | key_type == BTM_LE_KEY_LCSRK) |
| 186 | { |
| 187 | btm_sec_save_le_key (bd_addr, key_type, p_le_key, FALSE); |
| 188 | } |
| 189 | |
| 190 | #endif |
| 191 | |
| 192 | return(TRUE); |
| 193 | } |
| 194 | |
| 195 | /******************************************************************************* |
| 196 | ** |
| 197 | ** Function BTM_BleLoadLocalKeys |
| 198 | ** |
| 199 | ** Description Local local identity key, encryption root or sign counter. |
| 200 | ** |
| 201 | ** Parameters: key_type: type of key, can be BTM_BLE_KEY_TYPE_ID, BTM_BLE_KEY_TYPE_ER |
| 202 | ** or BTM_BLE_KEY_TYPE_COUNTER. |
| 203 | ** p_key: pointer to the key. |
| 204 | * |
| 205 | ** Returns non2. |
| 206 | ** |
| 207 | *******************************************************************************/ |
| 208 | void BTM_BleLoadLocalKeys(UINT8 key_type, tBTM_BLE_LOCAL_KEYS *p_key) |
| 209 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 210 | tBTM_DEVCB *p_devcb = &btm_cb.devcb; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 211 | BTM_TRACE_DEBUG ("BTM_BleLoadLocalKeys"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 212 | if (p_key != NULL) |
| 213 | { |
| 214 | switch (key_type) |
| 215 | { |
| 216 | case BTM_BLE_KEY_TYPE_ID: |
| 217 | memcpy(&p_devcb->id_keys, &p_key->id_keys, sizeof(tBTM_BLE_LOCAL_ID_KEYS)); |
| 218 | break; |
| 219 | |
| 220 | case BTM_BLE_KEY_TYPE_ER: |
| 221 | memcpy(p_devcb->er, p_key->er, sizeof(BT_OCTET16)); |
| 222 | break; |
| 223 | |
| 224 | default: |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 225 | BTM_TRACE_ERROR("unknow local key type: %d", key_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 226 | break; |
| 227 | } |
| 228 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | /******************************************************************************* |
| 232 | ** |
| 233 | ** Function BTM_GetDeviceEncRoot |
| 234 | ** |
| 235 | ** Description This function is called to read the local device encryption |
| 236 | ** root. |
| 237 | ** |
| 238 | ** Returns void |
| 239 | ** the local device ER is copied into er |
| 240 | ** |
| 241 | *******************************************************************************/ |
| 242 | void BTM_GetDeviceEncRoot (BT_OCTET16 er) |
| 243 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 244 | BTM_TRACE_DEBUG ("BTM_GetDeviceEncRoot"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 245 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 246 | memcpy (er, btm_cb.devcb.er, BT_OCTET16_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /******************************************************************************* |
| 250 | ** |
| 251 | ** Function BTM_GetDeviceIDRoot |
| 252 | ** |
| 253 | ** Description This function is called to read the local device identity |
| 254 | ** root. |
| 255 | ** |
| 256 | ** Returns void |
| 257 | ** the local device IR is copied into irk |
| 258 | ** |
| 259 | *******************************************************************************/ |
| 260 | void BTM_GetDeviceIDRoot (BT_OCTET16 irk) |
| 261 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 262 | BTM_TRACE_DEBUG ("BTM_GetDeviceIDRoot "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 263 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 264 | memcpy (irk, btm_cb.devcb.id_keys.irk, BT_OCTET16_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /******************************************************************************* |
| 268 | ** |
| 269 | ** Function BTM_GetDeviceDHK |
| 270 | ** |
| 271 | ** Description This function is called to read the local device DHK. |
| 272 | ** |
| 273 | ** Returns void |
| 274 | ** the local device DHK is copied into dhk |
| 275 | ** |
| 276 | *******************************************************************************/ |
| 277 | void BTM_GetDeviceDHK (BT_OCTET16 dhk) |
| 278 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 279 | BTM_TRACE_DEBUG ("BTM_GetDeviceDHK"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 280 | memcpy (dhk, btm_cb.devcb.id_keys.dhk, BT_OCTET16_LEN); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /******************************************************************************* |
| 284 | ** |
| 285 | ** Function BTM_ReadConnectionAddr |
| 286 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 287 | ** Description This function is called to get the local device address information |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 288 | ** . |
| 289 | ** |
| 290 | ** Returns void |
| 291 | ** |
| 292 | *******************************************************************************/ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 293 | void BTM_ReadConnectionAddr (BD_ADDR remote_bda, BD_ADDR local_conn_addr, tBLE_ADDR_TYPE *p_addr_type) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 294 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 295 | tACL_CONN *p_acl = btm_bda_to_acl(remote_bda, BT_TRANSPORT_LE); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 296 | |
| 297 | if (p_acl == NULL) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 298 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 299 | BTM_TRACE_ERROR("No connection exist!"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 300 | return; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 301 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 302 | memcpy(local_conn_addr, p_acl->conn_addr, BD_ADDR_LEN); |
| 303 | * p_addr_type = p_acl->conn_addr_type; |
| 304 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 305 | BTM_TRACE_DEBUG ("BTM_ReadConnectionAddr address type: %d addr: 0x%02x", |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 306 | p_acl->conn_addr_type, p_acl->conn_addr[0]); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 307 | } |
Mike J. Chen | bf9a8aa | 2014-02-11 13:51:29 -0800 | [diff] [blame] | 308 | |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 309 | /******************************************************************************* |
| 310 | ** |
| 311 | ** Function BTM_IsBleConnection |
| 312 | ** |
| 313 | ** Description This function is called to check if the connection handle |
| 314 | ** for an LE link |
| 315 | ** |
| 316 | ** Returns TRUE if connection is LE link, otherwise FALSE. |
| 317 | ** |
| 318 | *******************************************************************************/ |
| 319 | BOOLEAN BTM_IsBleConnection (UINT16 conn_handle) |
| 320 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 321 | #if (BLE_INCLUDED == TRUE) |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 322 | UINT8 xx; |
| 323 | tACL_CONN *p; |
| 324 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 325 | BTM_TRACE_API ("BTM_IsBleConnection: conn_handle: %d", conn_handle); |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 326 | |
| 327 | xx = btm_handle_to_acl_index (conn_handle); |
| 328 | if (xx >= MAX_L2CAP_LINKS) |
| 329 | return FALSE; |
| 330 | |
| 331 | p = &btm_cb.acl_db[xx]; |
| 332 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 333 | return (p->transport == BT_TRANSPORT_LE); |
| 334 | #else |
| 335 | return FALSE; |
| 336 | #endif |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 337 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 338 | |
| 339 | /******************************************************************************* |
| 340 | ** |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 341 | ** Function BTM_ReadRemoteConnectionAddr |
| 342 | ** |
| 343 | ** Description This function is read the remote device address currently used |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 344 | ** |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 345 | ** Parameters pseudo_addr: pseudo random address available |
| 346 | ** conn_addr:connection address used |
| 347 | ** p_addr_type : BD Address type, Public or Random of the address used |
| 348 | ** |
| 349 | ** Returns BOOLEAN , TRUE if connection to remote device exists, else FALSE |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 350 | ** |
| 351 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 352 | BOOLEAN BTM_ReadRemoteConnectionAddr(BD_ADDR pseudo_addr, BD_ADDR conn_addr, |
| 353 | tBLE_ADDR_TYPE *p_addr_type) |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 354 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 355 | BOOLEAN st = TRUE; |
| 356 | #if (BLE_PRIVACY_SPT == TRUE) |
| 357 | tACL_CONN *p = btm_bda_to_acl (pseudo_addr, BT_TRANSPORT_LE); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 358 | |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 359 | if (p == NULL) |
| 360 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 361 | BTM_TRACE_ERROR("BTM_ReadRemoteConnectionAddr can not find connection" |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 362 | " with matching address"); |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 363 | return FALSE; |
| 364 | } |
| 365 | |
| 366 | memcpy(conn_addr, p->active_remote_addr, BD_ADDR_LEN); |
| 367 | *p_addr_type = p->active_remote_addr_type; |
| 368 | #else |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 369 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(pseudo_addr); |
| 370 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 371 | memcpy(conn_addr, pseudo_addr, BD_ADDR_LEN); |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 372 | if (p_dev_rec != NULL) |
| 373 | { |
| 374 | *p_addr_type = p_dev_rec->ble.ble_addr_type; |
| 375 | } |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 376 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 377 | return st; |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 378 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 379 | } |
| 380 | /******************************************************************************* |
| 381 | ** |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 382 | ** Function BTM_SecurityGrant |
| 383 | ** |
| 384 | ** Description This function is called to grant security process. |
| 385 | ** |
| 386 | ** Parameters bd_addr - peer device bd address. |
| 387 | ** res - result of the operation BTM_SUCCESS if success. |
| 388 | ** Otherwise, BTM_REPEATED_ATTEMPTS is too many attempts. |
| 389 | ** |
| 390 | ** Returns None |
| 391 | ** |
| 392 | *******************************************************************************/ |
| 393 | void BTM_SecurityGrant(BD_ADDR bd_addr, UINT8 res) |
| 394 | { |
Mike J. Chen | bf9a8aa | 2014-02-11 13:51:29 -0800 | [diff] [blame] | 395 | #if SMP_INCLUDED == TRUE |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 396 | tSMP_STATUS res_smp = (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_REPEATED_ATTEMPTS; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 397 | BTM_TRACE_DEBUG ("BTM_SecurityGrant"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 398 | SMP_SecurityGrant(bd_addr, res_smp); |
| 399 | #endif |
| 400 | } |
| 401 | |
| 402 | /******************************************************************************* |
| 403 | ** |
| 404 | ** Function BTM_BlePasskeyReply |
| 405 | ** |
| 406 | ** Description This function is called after Security Manager submitted |
| 407 | ** passkey request to the application. |
| 408 | ** |
| 409 | ** Parameters: bd_addr - Address of the device for which passkey was requested |
| 410 | ** res - result of the operation BTM_SUCCESS if success |
| 411 | ** key_len - length in bytes of the Passkey |
| 412 | ** p_passkey - pointer to array with the passkey |
| 413 | ** trusted_mask - bitwise OR of trusted services (array of UINT32) |
| 414 | ** |
| 415 | *******************************************************************************/ |
| 416 | void BTM_BlePasskeyReply (BD_ADDR bd_addr, UINT8 res, UINT32 passkey) |
| 417 | { |
Mike J. Chen | bf9a8aa | 2014-02-11 13:51:29 -0800 | [diff] [blame] | 418 | #if SMP_INCLUDED == TRUE |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 419 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); |
| 420 | tSMP_STATUS res_smp = (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_PASSKEY_ENTRY_FAIL; |
| 421 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 422 | if (p_dev_rec == NULL) |
| 423 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 424 | BTM_TRACE_ERROR("Passkey reply to Unknown device"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 425 | return; |
| 426 | } |
| 427 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 428 | p_dev_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_AUTHED; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 429 | BTM_TRACE_DEBUG ("BTM_BlePasskeyReply"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 430 | SMP_PasskeyReply(bd_addr, res_smp, passkey); |
| 431 | #endif |
| 432 | } |
| 433 | |
| 434 | /******************************************************************************* |
| 435 | ** |
| 436 | ** Function BTM_BleOobDataReply |
| 437 | ** |
| 438 | ** Description This function is called to provide the OOB data for |
| 439 | ** SMP in response to BTM_LE_OOB_REQ_EVT |
| 440 | ** |
| 441 | ** Parameters: bd_addr - Address of the peer device |
| 442 | ** res - result of the operation SMP_SUCCESS if success |
| 443 | ** p_data - simple pairing Randomizer C. |
| 444 | ** |
| 445 | *******************************************************************************/ |
| 446 | void BTM_BleOobDataReply(BD_ADDR bd_addr, UINT8 res, UINT8 len, UINT8 *p_data) |
| 447 | { |
Mike J. Chen | bf9a8aa | 2014-02-11 13:51:29 -0800 | [diff] [blame] | 448 | #if SMP_INCLUDED == TRUE |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 449 | tSMP_STATUS res_smp = (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_OOB_FAIL; |
| 450 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); |
| 451 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 452 | BTM_TRACE_DEBUG ("BTM_BleOobDataReply"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 453 | |
| 454 | if (p_dev_rec == NULL) |
| 455 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 456 | BTM_TRACE_ERROR("BTM_BleOobDataReply() to Unknown device"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 457 | return; |
| 458 | } |
| 459 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 460 | p_dev_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_AUTHED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 461 | SMP_OobDataReply(bd_addr, res_smp, len, p_data); |
| 462 | #endif |
| 463 | } |
| 464 | |
| 465 | /****************************************************************************** |
| 466 | ** |
| 467 | ** Function BTM_BleSetConnScanParams |
| 468 | ** |
| 469 | ** Description Set scan parameter used in BLE connection request |
| 470 | ** |
| 471 | ** Parameters: scan_interval: scan interval |
| 472 | ** scan_window: scan window |
| 473 | ** |
| 474 | ** Returns void |
| 475 | ** |
| 476 | *******************************************************************************/ |
| 477 | void BTM_BleSetConnScanParams (UINT16 scan_interval, UINT16 scan_window) |
| 478 | { |
Mike J. Chen | bf9a8aa | 2014-02-11 13:51:29 -0800 | [diff] [blame] | 479 | #if SMP_INCLUDED == TRUE |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 480 | tBTM_BLE_CB *p_ble_cb = &btm_cb.ble_ctr_cb; |
| 481 | BOOLEAN new_param = FALSE; |
| 482 | |
| 483 | if (BTM_BLE_VALID_PRAM(scan_interval, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) && |
| 484 | BTM_BLE_VALID_PRAM(scan_window, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX)) |
| 485 | { |
| 486 | btu_stop_timer(&p_ble_cb->scan_param_idle_timer); |
| 487 | |
| 488 | if (p_ble_cb->scan_int != scan_interval) |
| 489 | { |
| 490 | p_ble_cb->scan_int = scan_interval; |
| 491 | new_param = TRUE; |
| 492 | } |
| 493 | |
| 494 | if (p_ble_cb->scan_win != scan_window) |
| 495 | { |
| 496 | p_ble_cb->scan_win = scan_window; |
| 497 | new_param = TRUE; |
| 498 | } |
| 499 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 500 | if (new_param && p_ble_cb->conn_state == BLE_BG_CONN) |
| 501 | { |
| 502 | btm_ble_suspend_bg_conn(); |
| 503 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 504 | } |
| 505 | else |
| 506 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 507 | BTM_TRACE_ERROR("Illegal Connection Scan Parameters"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 508 | } |
| 509 | #endif |
| 510 | } |
| 511 | |
| 512 | /******************************************************** |
| 513 | ** |
| 514 | ** Function BTM_BleSetPrefConnParams |
| 515 | ** |
| 516 | ** Description Set a peripheral's preferred connection parameters |
| 517 | ** |
| 518 | ** Parameters: bd_addr - BD address of the peripheral |
| 519 | ** scan_interval: scan interval |
| 520 | ** scan_window: scan window |
| 521 | ** min_conn_int - minimum preferred connection interval |
| 522 | ** max_conn_int - maximum preferred connection interval |
| 523 | ** slave_latency - preferred slave latency |
| 524 | ** supervision_tout - preferred supervision timeout |
| 525 | ** |
| 526 | ** Returns void |
| 527 | ** |
| 528 | *******************************************************************************/ |
| 529 | void BTM_BleSetPrefConnParams (BD_ADDR bd_addr, |
| 530 | UINT16 min_conn_int, UINT16 max_conn_int, |
| 531 | UINT16 slave_latency, UINT16 supervision_tout) |
| 532 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 533 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); |
| 534 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 535 | BTM_TRACE_API ("BTM_BleSetPrefConnParams min: %u max: %u latency: %u \ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 536 | tout: %u", |
| 537 | min_conn_int, max_conn_int, slave_latency, supervision_tout); |
| 538 | |
| 539 | if (BTM_BLE_VALID_PRAM(min_conn_int, BTM_BLE_CONN_INT_MIN, BTM_BLE_CONN_INT_MAX) && |
| 540 | BTM_BLE_VALID_PRAM(max_conn_int, BTM_BLE_CONN_INT_MIN, BTM_BLE_CONN_INT_MAX) && |
| 541 | BTM_BLE_VALID_PRAM(supervision_tout, BTM_BLE_CONN_SUP_TOUT_MIN, BTM_BLE_CONN_SUP_TOUT_MAX) && |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 542 | (slave_latency <= BTM_BLE_CONN_LATENCY_MAX || slave_latency == BTM_BLE_CONN_PARAM_UNDEF)) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 543 | { |
| 544 | if (p_dev_rec) |
| 545 | { |
| 546 | /* expect conn int and stout and slave latency to be updated all together */ |
| 547 | if (min_conn_int != BTM_BLE_CONN_PARAM_UNDEF || max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) |
| 548 | { |
| 549 | if (min_conn_int != BTM_BLE_CONN_PARAM_UNDEF) |
| 550 | p_dev_rec->conn_params.min_conn_int = min_conn_int; |
| 551 | else |
| 552 | p_dev_rec->conn_params.min_conn_int = max_conn_int; |
| 553 | |
| 554 | if (max_conn_int != BTM_BLE_CONN_PARAM_UNDEF) |
| 555 | p_dev_rec->conn_params.max_conn_int = max_conn_int; |
| 556 | else |
| 557 | p_dev_rec->conn_params.max_conn_int = min_conn_int; |
| 558 | |
| 559 | if (slave_latency != BTM_BLE_CONN_PARAM_UNDEF) |
| 560 | p_dev_rec->conn_params.slave_latency = slave_latency; |
| 561 | else |
| 562 | p_dev_rec->conn_params.slave_latency = BTM_BLE_CONN_SLAVE_LATENCY_DEF; |
| 563 | |
| 564 | if (supervision_tout != BTM_BLE_CONN_PARAM_UNDEF) |
| 565 | p_dev_rec->conn_params.supervision_tout = supervision_tout; |
| 566 | else |
| 567 | p_dev_rec->conn_params.slave_latency = BTM_BLE_CONN_TIMEOUT_DEF; |
| 568 | |
| 569 | } |
| 570 | |
| 571 | } |
| 572 | else |
| 573 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 574 | BTM_TRACE_ERROR("Unknown Device, setting rejected"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 575 | } |
| 576 | } |
| 577 | else |
| 578 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 579 | BTM_TRACE_ERROR("Illegal Connection Parameters"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 580 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | /******************************************************************************* |
| 584 | ** |
| 585 | ** Function BTM_ReadDevInfo |
| 586 | ** |
| 587 | ** Description This function is called to read the device/address type |
| 588 | ** of BD address. |
| 589 | ** |
| 590 | ** Parameter remote_bda: remote device address |
| 591 | ** p_dev_type: output parameter to read the device type. |
| 592 | ** p_addr_type: output parameter to read the address type. |
| 593 | ** |
| 594 | *******************************************************************************/ |
| 595 | void BTM_ReadDevInfo (BD_ADDR remote_bda, tBT_DEVICE_TYPE *p_dev_type, tBLE_ADDR_TYPE *p_addr_type) |
| 596 | { |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 597 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (remote_bda); |
| 598 | tBTM_INQ_INFO *p_inq_info = BTM_InqDbRead(remote_bda); |
| 599 | |
| 600 | *p_dev_type = BT_DEVICE_TYPE_BREDR; |
| 601 | *p_addr_type = BLE_ADDR_PUBLIC; |
| 602 | |
| 603 | if (!p_dev_rec) |
| 604 | { |
| 605 | /* Check with the BT manager if details about remote device are known */ |
| 606 | if (p_inq_info != NULL) |
| 607 | { |
| 608 | *p_dev_type = p_inq_info->results.device_type ; |
| 609 | *p_addr_type = p_inq_info->results.ble_addr_type; |
Andre Eisenbach | 306bdda | 2013-11-06 23:35:48 -0800 | [diff] [blame] | 610 | } else { |
| 611 | /* unknown device, assume BR/EDR */ |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 612 | BTM_TRACE_DEBUG ("btm_find_dev_type - unknown device, BR/EDR assumed"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 613 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 614 | } |
| 615 | else /* there is a security device record exisitng */ |
| 616 | { |
| 617 | /* new inquiry result, overwrite device type in security device record */ |
| 618 | if (p_inq_info) |
| 619 | { |
| 620 | p_dev_rec->device_type = p_inq_info->results.device_type; |
| 621 | p_dev_rec->ble.ble_addr_type = p_inq_info->results.ble_addr_type; |
| 622 | } |
| 623 | *p_dev_type = p_dev_rec->device_type; |
| 624 | *p_addr_type = p_dev_rec->ble.ble_addr_type; |
| 625 | |
| 626 | } |
| 627 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 628 | BTM_TRACE_DEBUG ("btm_find_dev_type - device_type = %d addr_type = %d", *p_dev_type , *p_addr_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 629 | } |
| 630 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 631 | /******************************************************************************* |
| 632 | ** |
| 633 | ** Function BTM_BleReceiverTest |
| 634 | ** |
| 635 | ** Description This function is called to start the LE Receiver test |
| 636 | ** |
| 637 | ** Parameter rx_freq - Frequency Range |
| 638 | ** p_cmd_cmpl_cback - Command Complete callback |
| 639 | ** |
| 640 | *******************************************************************************/ |
| 641 | void BTM_BleReceiverTest(UINT8 rx_freq, tBTM_CMPL_CB *p_cmd_cmpl_cback) |
| 642 | { |
| 643 | btm_cb.devcb.p_le_test_cmd_cmpl_cb = p_cmd_cmpl_cback; |
| 644 | |
| 645 | if (btsnd_hcic_ble_receiver_test(rx_freq) == FALSE) |
| 646 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 647 | BTM_TRACE_ERROR("%s: Unable to Trigger LE receiver test", __FUNCTION__); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 648 | } |
| 649 | } |
| 650 | |
| 651 | /******************************************************************************* |
| 652 | ** |
| 653 | ** Function BTM_BleTransmitterTest |
| 654 | ** |
| 655 | ** Description This function is called to start the LE Transmitter test |
| 656 | ** |
| 657 | ** Parameter tx_freq - Frequency Range |
| 658 | ** test_data_len - Length in bytes of payload data in each packet |
| 659 | ** packet_payload - Pattern to use in the payload |
| 660 | ** p_cmd_cmpl_cback - Command Complete callback |
| 661 | ** |
| 662 | *******************************************************************************/ |
| 663 | void BTM_BleTransmitterTest(UINT8 tx_freq, UINT8 test_data_len, |
| 664 | UINT8 packet_payload, tBTM_CMPL_CB *p_cmd_cmpl_cback) |
| 665 | { |
| 666 | btm_cb.devcb.p_le_test_cmd_cmpl_cb = p_cmd_cmpl_cback; |
| 667 | if (btsnd_hcic_ble_transmitter_test(tx_freq, test_data_len, packet_payload) == FALSE) |
| 668 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 669 | BTM_TRACE_ERROR("%s: Unable to Trigger LE transmitter test", __FUNCTION__); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | |
| 673 | /******************************************************************************* |
| 674 | ** |
| 675 | ** Function BTM_BleTestEnd |
| 676 | ** |
| 677 | ** Description This function is called to stop the in-progress TX or RX test |
| 678 | ** |
| 679 | ** Parameter p_cmd_cmpl_cback - Command complete callback |
| 680 | ** |
| 681 | *******************************************************************************/ |
| 682 | void BTM_BleTestEnd(tBTM_CMPL_CB *p_cmd_cmpl_cback) |
| 683 | { |
| 684 | btm_cb.devcb.p_le_test_cmd_cmpl_cb = p_cmd_cmpl_cback; |
| 685 | |
| 686 | if (btsnd_hcic_ble_test_end() == FALSE) |
| 687 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 688 | BTM_TRACE_ERROR("%s: Unable to End the LE TX/RX test", __FUNCTION__); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 689 | } |
| 690 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 691 | |
| 692 | /******************************************************************************* |
| 693 | ** Internal Functions |
| 694 | *******************************************************************************/ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 695 | void btm_ble_test_command_complete(UINT8 *p) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 696 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 697 | tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_le_test_cmd_cmpl_cb; |
| 698 | UINT8 status; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 699 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 700 | btm_cb.devcb.p_le_test_cmd_cmpl_cb = NULL; |
| 701 | |
| 702 | if (p_cb) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 703 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 704 | (*p_cb)(p); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 705 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | /******************************************************************************* |
| 709 | ** |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 710 | ** Function BTM_UseLeLink |
| 711 | ** |
| 712 | ** Description This function is to select the underneath physical link to use. |
| 713 | ** |
| 714 | ** Returns TRUE to use LE, FALSE use BR/EDR. |
| 715 | ** |
| 716 | *******************************************************************************/ |
| 717 | BOOLEAN BTM_UseLeLink (BD_ADDR bd_addr) |
| 718 | { |
| 719 | tACL_CONN *p; |
| 720 | tBT_DEVICE_TYPE dev_type; |
| 721 | tBLE_ADDR_TYPE addr_type; |
| 722 | BOOLEAN use_le = FALSE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 723 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 724 | if ((p = btm_bda_to_acl(bd_addr, BT_TRANSPORT_BR_EDR)) != NULL) |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 725 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 726 | return use_le; |
| 727 | } |
| 728 | else if ((p = btm_bda_to_acl(bd_addr, BT_TRANSPORT_LE)) != NULL) |
| 729 | { |
| 730 | use_le = TRUE; |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 731 | } |
| 732 | else |
| 733 | { |
| 734 | BTM_ReadDevInfo(bd_addr, &dev_type, &addr_type); |
| 735 | use_le = (dev_type == BT_DEVICE_TYPE_BLE); |
| 736 | } |
| 737 | return use_le; |
| 738 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 739 | /******************************************************************************* |
| 740 | ** |
| 741 | ** Function btm_ble_rand_enc_complete |
| 742 | ** |
| 743 | ** Description This function is the callback functions for HCI_Rand command |
| 744 | ** and HCI_Encrypt command is completed. |
| 745 | ** This message is received from the HCI. |
| 746 | ** |
| 747 | ** Returns void |
| 748 | ** |
| 749 | *******************************************************************************/ |
| 750 | void btm_ble_rand_enc_complete (UINT8 *p, UINT16 op_code, tBTM_RAND_ENC_CB *p_enc_cplt_cback) |
| 751 | { |
| 752 | tBTM_RAND_ENC params; |
| 753 | UINT8 *p_dest = params.param_buf; |
| 754 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 755 | BTM_TRACE_DEBUG ("btm_ble_rand_enc_complete"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 756 | |
| 757 | memset(¶ms, 0, sizeof(tBTM_RAND_ENC)); |
| 758 | |
| 759 | /* If there was a callback address for vcs complete, call it */ |
| 760 | if (p_enc_cplt_cback && p) |
| 761 | { |
| 762 | /* Pass paramters to the callback function */ |
| 763 | STREAM_TO_UINT8(params.status, p); /* command status */ |
| 764 | |
| 765 | if (params.status == HCI_SUCCESS) |
| 766 | { |
| 767 | params.opcode = op_code; |
| 768 | |
| 769 | if (op_code == HCI_BLE_RAND) |
| 770 | params.param_len = BT_OCTET8_LEN; |
| 771 | else |
| 772 | params.param_len = BT_OCTET16_LEN; |
| 773 | |
| 774 | memcpy(p_dest, p, params.param_len); /* Fetch return info from HCI event message */ |
| 775 | } |
| 776 | if (p_enc_cplt_cback) |
| 777 | (*p_enc_cplt_cback)(¶ms); /* Call the Encryption complete callback function */ |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 782 | #if (SMP_INCLUDED == TRUE) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 783 | |
| 784 | /******************************************************************************* |
| 785 | ** |
| 786 | ** Function btm_ble_get_enc_key_type |
| 787 | ** |
| 788 | ** Description This function is to increment local sign counter |
| 789 | ** Returns None |
| 790 | ** |
| 791 | *******************************************************************************/ |
| 792 | void btm_ble_increment_sign_ctr(BD_ADDR bd_addr, BOOLEAN is_local ) |
| 793 | { |
| 794 | tBTM_SEC_DEV_REC *p_dev_rec; |
| 795 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 796 | BTM_TRACE_DEBUG ("btm_ble_increment_sign_ctr is_local=%d", is_local); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 797 | |
| 798 | if ((p_dev_rec = btm_find_dev (bd_addr)) != NULL) |
| 799 | { |
| 800 | if (is_local) |
| 801 | p_dev_rec->ble.keys.local_counter++; |
| 802 | else |
| 803 | p_dev_rec->ble.keys.counter++; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 804 | BTM_TRACE_DEBUG ("is_local=%d local sign counter=%d peer sign counter=%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 805 | is_local, |
| 806 | p_dev_rec->ble.keys.local_counter, |
| 807 | p_dev_rec->ble.keys.counter); |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | /******************************************************************************* |
| 812 | ** |
| 813 | ** Function btm_ble_get_enc_key_type |
| 814 | ** |
| 815 | ** Description This function is to get the BLE key type that has been exchanged |
| 816 | ** in betweem local device and peer device. |
| 817 | ** |
| 818 | ** Returns p_key_type: output parameter to carry the key type value. |
| 819 | ** |
| 820 | *******************************************************************************/ |
| 821 | BOOLEAN btm_ble_get_enc_key_type(BD_ADDR bd_addr, UINT8 *p_key_types) |
| 822 | { |
| 823 | tBTM_SEC_DEV_REC *p_dev_rec; |
| 824 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 825 | BTM_TRACE_DEBUG ("btm_ble_get_enc_key_type"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 826 | |
| 827 | if ((p_dev_rec = btm_find_dev (bd_addr)) != NULL) |
| 828 | { |
| 829 | *p_key_types = p_dev_rec->ble.key_type; |
| 830 | return TRUE; |
| 831 | } |
| 832 | return FALSE; |
| 833 | } |
| 834 | |
| 835 | /******************************************************************************* |
| 836 | ** |
| 837 | ** Function btm_get_local_div |
| 838 | ** |
| 839 | ** Description This function is called to read the local DIV |
| 840 | ** |
| 841 | ** Returns TURE - if a valid DIV is availavle |
| 842 | *******************************************************************************/ |
| 843 | BOOLEAN btm_get_local_div (BD_ADDR bd_addr, UINT16 *p_div) |
| 844 | { |
| 845 | tBTM_SEC_DEV_REC *p_dev_rec; |
| 846 | BOOLEAN status = FALSE; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 847 | BTM_TRACE_DEBUG ("btm_get_local_div"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 848 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 849 | BTM_TRACE_DEBUG("bd_addr:%02x-%02x-%02x-%02x-%02x-%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 850 | bd_addr[0],bd_addr[1], |
| 851 | bd_addr[2],bd_addr[3], |
| 852 | bd_addr[4],bd_addr[5]); |
| 853 | |
| 854 | p_dev_rec = btm_find_dev (bd_addr); |
| 855 | |
| 856 | if (p_dev_rec && p_dev_rec->ble.keys.div) |
| 857 | { |
| 858 | status = TRUE; |
| 859 | *p_div = p_dev_rec->ble.keys.div; |
| 860 | } |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 861 | BTM_TRACE_DEBUG ("btm_get_local_div status=%d (1-OK) DIV=0x%x", status, *p_div); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 862 | return status; |
| 863 | } |
| 864 | |
| 865 | /******************************************************************************* |
| 866 | ** |
| 867 | ** Function btm_sec_save_le_key |
| 868 | ** |
| 869 | ** Description This function is called by the SMP to update |
| 870 | ** an BLE key. SMP is internal, whereas all the keys shall |
| 871 | ** be sent to the application. The function is also called |
| 872 | ** when application passes ble key stored in NVRAM to the btm_sec. |
| 873 | ** pass_to_application parameter is false in this case. |
| 874 | ** |
| 875 | ** Returns void |
| 876 | ** |
| 877 | *******************************************************************************/ |
| 878 | void btm_sec_save_le_key(BD_ADDR bd_addr, tBTM_LE_KEY_TYPE key_type, tBTM_LE_KEY_VALUE *p_keys, |
| 879 | BOOLEAN pass_to_application) |
| 880 | { |
| 881 | tBTM_SEC_DEV_REC *p_rec; |
| 882 | tBTM_LE_EVT_DATA cb_data; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 883 | UINT8 i; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 884 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 885 | BTM_TRACE_DEBUG ("btm_sec_save_le_key key_type=0x%x pass_to_application=%d",key_type, pass_to_application); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 886 | /* Store the updated key in the device database */ |
| 887 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 888 | BTM_TRACE_DEBUG("bd_addr:%02x-%02x-%02x-%02x-%02x-%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 889 | bd_addr[0],bd_addr[1], |
| 890 | bd_addr[2],bd_addr[3], |
| 891 | bd_addr[4],bd_addr[5]); |
| 892 | |
| 893 | if ((p_rec = btm_find_dev (bd_addr)) != NULL && p_keys) |
| 894 | { |
| 895 | switch (key_type) |
| 896 | { |
| 897 | case BTM_LE_KEY_PENC: |
| 898 | memcpy(p_rec->ble.keys.ltk, p_keys->penc_key.ltk, BT_OCTET16_LEN); |
| 899 | memcpy(p_rec->ble.keys.rand, p_keys->penc_key.rand, BT_OCTET8_LEN); |
| 900 | p_rec->ble.keys.sec_level = p_keys->penc_key.sec_level; |
| 901 | p_rec->ble.keys.ediv = p_keys->penc_key.ediv; |
| 902 | p_rec->ble.keys.key_size = p_keys->penc_key.key_size; |
| 903 | p_rec->ble.key_type |= BTM_LE_KEY_PENC; |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 904 | p_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_KNOWN; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 905 | if (p_keys->penc_key.sec_level == SMP_SEC_AUTHENTICATED) |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 906 | p_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_AUTHED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 907 | else |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 908 | p_rec->sec_flags &= ~BTM_SEC_LE_LINK_KEY_AUTHED; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 909 | BTM_TRACE_DEBUG("BTM_LE_KEY_PENC key_type=0x%x sec_flags=0x%x sec_leve=0x%x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 910 | p_rec->ble.key_type, |
| 911 | p_rec->sec_flags, |
| 912 | p_rec->ble.keys.sec_level); |
| 913 | break; |
| 914 | |
| 915 | case BTM_LE_KEY_PID: |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 916 | for (i=0; i<BT_OCTET16_LEN; i++) |
| 917 | { |
| 918 | p_rec->ble.keys.irk[i] = p_keys->pid_key.irk[i]; |
| 919 | } |
| 920 | |
| 921 | //memcpy( p_rec->ble.keys.irk, p_keys->pid_key, BT_OCTET16_LEN); todo will crash the system |
| 922 | memcpy(p_rec->ble.static_addr, p_keys->pid_key.static_addr, BD_ADDR_LEN); |
| 923 | p_rec->ble.static_addr_type = p_keys->pid_key.addr_type; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 924 | p_rec->ble.key_type |= BTM_LE_KEY_PID; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 925 | BTM_TRACE_DEBUG("BTM_LE_KEY_PID key_type=0x%x save peer IRK", p_rec->ble.key_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 926 | break; |
| 927 | |
| 928 | case BTM_LE_KEY_PCSRK: |
| 929 | memcpy(p_rec->ble.keys.csrk, p_keys->pcsrk_key.csrk, BT_OCTET16_LEN); |
| 930 | p_rec->ble.keys.srk_sec_level = p_keys->pcsrk_key.sec_level; |
| 931 | p_rec->ble.keys.counter = p_keys->pcsrk_key.counter; |
| 932 | p_rec->ble.key_type |= BTM_LE_KEY_PCSRK; |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 933 | p_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_KNOWN; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 934 | if ( p_keys->pcsrk_key.sec_level== SMP_SEC_AUTHENTICATED) |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 935 | p_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_AUTHED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 936 | else |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 937 | p_rec->sec_flags &= ~BTM_SEC_LE_LINK_KEY_AUTHED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 938 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 939 | BTM_TRACE_DEBUG("BTM_LE_KEY_PCSRK key_type=0x%x sec_flags=0x%x sec_level=0x%x peer_counter=%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 940 | p_rec->ble.key_type, |
| 941 | p_rec->sec_flags, |
| 942 | p_rec->ble.keys.srk_sec_level, |
| 943 | p_rec->ble.keys.counter ); |
| 944 | break; |
| 945 | |
| 946 | case BTM_LE_KEY_LENC: |
| 947 | p_rec->ble.keys.div = p_keys->lenc_key.div; /* update DIV */ |
| 948 | p_rec->ble.keys.sec_level = p_keys->lenc_key.sec_level; |
| 949 | p_rec->ble.keys.key_size = p_keys->lenc_key.key_size; |
| 950 | p_rec->ble.key_type |= BTM_LE_KEY_LENC; |
| 951 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 952 | BTM_TRACE_DEBUG("BTM_LE_KEY_LENC key_type=0x%x DIV=0x%x key_size=0x%x sec_level=0x%x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 953 | p_rec->ble.key_type, |
| 954 | p_rec->ble.keys.div, |
| 955 | p_rec->ble.keys.key_size, |
| 956 | p_rec->ble.keys.sec_level ); |
| 957 | break; |
| 958 | |
| 959 | case BTM_LE_KEY_LCSRK:/* local CSRK has been delivered */ |
| 960 | p_rec->ble.keys.div = p_keys->lcsrk_key.div; /* update DIV */ |
| 961 | p_rec->ble.keys.local_csrk_sec_level = p_keys->lcsrk_key.sec_level; |
| 962 | p_rec->ble.keys.local_counter = p_keys->lcsrk_key.counter; |
| 963 | p_rec->ble.key_type |= BTM_LE_KEY_LCSRK; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 964 | BTM_TRACE_DEBUG("BTM_LE_KEY_LCSRK key_type=0x%x DIV=0x%x scrk_sec_level=0x%x local_counter=%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 965 | p_rec->ble.key_type, |
| 966 | p_rec->ble.keys.div, |
| 967 | p_rec->ble.keys.local_csrk_sec_level, |
| 968 | p_rec->ble.keys.local_counter ); |
| 969 | break; |
| 970 | |
| 971 | default: |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 972 | BTM_TRACE_WARNING("btm_sec_save_le_key (Bad key_type 0x%02x)", key_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 973 | return; |
| 974 | } |
| 975 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 976 | BTM_TRACE_DEBUG ("BLE key type 0x%02x updated for BDA: %08x%04x (btm_sec_save_le_key)", key_type, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 977 | (bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8)+bd_addr[3], |
| 978 | (bd_addr[4]<<8)+bd_addr[5]); |
| 979 | |
| 980 | /* Notify the application that one of the BLE keys has been updated |
| 981 | If link key is in progress, it will get sent later.*/ |
| 982 | if (pass_to_application && btm_cb.api.p_le_callback) |
| 983 | { |
| 984 | cb_data.key.p_key_value = p_keys; |
| 985 | cb_data.key.key_type = key_type; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 986 | (*btm_cb.api.p_le_callback) (BTM_LE_KEY_EVT, bd_addr, &cb_data); |
| 987 | } |
| 988 | return; |
| 989 | } |
| 990 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 991 | BTM_TRACE_WARNING ("BLE key type 0x%02x called for Unknown BDA or type: %08x%04x !! (btm_sec_save_le_key)", key_type, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 992 | (bd_addr[0]<<24)+(bd_addr[1]<<16)+(bd_addr[2]<<8)+bd_addr[3], |
| 993 | (bd_addr[4]<<8)+bd_addr[5]); |
| 994 | |
| 995 | if (p_rec) |
| 996 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 997 | BTM_TRACE_DEBUG ("sec_flags=0x%x", p_rec->sec_flags); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 998 | } |
| 999 | } |
| 1000 | |
| 1001 | /******************************************************************************* |
| 1002 | ** |
| 1003 | ** Function btm_ble_update_sec_key_size |
| 1004 | ** |
| 1005 | ** Description update the current lin kencryption key size |
| 1006 | ** |
| 1007 | ** Returns void |
| 1008 | ** |
| 1009 | *******************************************************************************/ |
| 1010 | void btm_ble_update_sec_key_size(BD_ADDR bd_addr, UINT8 enc_key_size) |
| 1011 | { |
| 1012 | tBTM_SEC_DEV_REC *p_rec; |
| 1013 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1014 | BTM_TRACE_DEBUG("btm_ble_update_sec_key_size enc_key_size = %d", enc_key_size); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1015 | |
| 1016 | if ((p_rec = btm_find_dev (bd_addr)) != NULL ) |
| 1017 | { |
| 1018 | p_rec->enc_key_size = enc_key_size; |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | /******************************************************************************* |
| 1023 | ** |
| 1024 | ** Function btm_ble_read_sec_key_size |
| 1025 | ** |
| 1026 | ** Description update the current lin kencryption key size |
| 1027 | ** |
| 1028 | ** Returns void |
| 1029 | ** |
| 1030 | *******************************************************************************/ |
| 1031 | UINT8 btm_ble_read_sec_key_size(BD_ADDR bd_addr) |
| 1032 | { |
| 1033 | tBTM_SEC_DEV_REC *p_rec; |
| 1034 | |
| 1035 | if ((p_rec = btm_find_dev (bd_addr)) != NULL ) |
| 1036 | { |
| 1037 | return p_rec->enc_key_size; |
| 1038 | } |
| 1039 | else |
| 1040 | return 0; |
| 1041 | } |
| 1042 | |
| 1043 | /******************************************************************************* |
| 1044 | ** |
| 1045 | ** Function btm_ble_link_sec_check |
| 1046 | ** |
| 1047 | ** Description Check BLE link security level match. |
| 1048 | ** |
| 1049 | ** Returns TRUE: check is OK and the *p_sec_req_act contain the action |
| 1050 | ** |
| 1051 | *******************************************************************************/ |
| 1052 | void btm_ble_link_sec_check(BD_ADDR bd_addr, tBTM_LE_AUTH_REQ auth_req, tBTM_BLE_SEC_REQ_ACT *p_sec_req_act) |
| 1053 | { |
| 1054 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 1055 | UINT8 req_sec_level = BTM_LE_SEC_NONE, cur_sec_level = BTM_LE_SEC_NONE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1056 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1057 | BTM_TRACE_DEBUG ("btm_ble_link_sec_check auth_req =0x%x", auth_req); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1058 | |
| 1059 | if (p_dev_rec == NULL) |
| 1060 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1061 | BTM_TRACE_ERROR ("btm_ble_link_sec_check received for unknown device"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1062 | return; |
| 1063 | } |
| 1064 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1065 | if (p_dev_rec->sec_state == BTM_SEC_STATE_ENCRYPTING || |
| 1066 | p_dev_rec->sec_state == BTM_SEC_STATE_AUTHENTICATING) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1067 | { |
| 1068 | /* race condition: discard the security request while master is encrypting the link */ |
| 1069 | *p_sec_req_act = BTM_BLE_SEC_REQ_ACT_DISCARD; |
| 1070 | } |
| 1071 | else |
| 1072 | { |
| 1073 | req_sec_level = BTM_LE_SEC_UNAUTHENTICATE; |
| 1074 | if ((auth_req == (BTM_LE_AUTH_REQ_BOND|BTM_LE_AUTH_REQ_MITM)) || |
| 1075 | (auth_req == (BTM_LE_AUTH_REQ_MITM)) ) |
| 1076 | { |
| 1077 | req_sec_level = BTM_LE_SEC_AUTHENTICATED; |
| 1078 | } |
| 1079 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1080 | BTM_TRACE_DEBUG ("dev_rec sec_flags=0x%x", p_dev_rec->sec_flags); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1081 | |
| 1082 | /* currently encrpted */ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1083 | if (p_dev_rec->sec_flags & BTM_SEC_LE_ENCRYPTED) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1084 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1085 | if (p_dev_rec->sec_flags & BTM_SEC_LE_LINK_KEY_AUTHED) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1086 | cur_sec_level = BTM_LE_SEC_AUTHENTICATED; |
| 1087 | else |
| 1088 | cur_sec_level = BTM_LE_SEC_UNAUTHENTICATE; |
| 1089 | } |
| 1090 | else /* unencrypted link */ |
| 1091 | { |
| 1092 | /* if bonded, get the key security level */ |
| 1093 | if (p_dev_rec->ble.key_type & BTM_LE_KEY_PENC) |
| 1094 | cur_sec_level = p_dev_rec->ble.keys.sec_level; |
| 1095 | else |
| 1096 | cur_sec_level = BTM_LE_SEC_NONE; |
| 1097 | } |
| 1098 | |
| 1099 | if (cur_sec_level >= req_sec_level) |
| 1100 | { |
| 1101 | if (cur_sec_level == BTM_LE_SEC_NONE) |
| 1102 | { |
| 1103 | *p_sec_req_act = BTM_BLE_SEC_REQ_ACT_NONE; |
| 1104 | } |
| 1105 | else |
| 1106 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1107 | /* To avoid re-encryption on an encrypted link for an equal condition encryption */ |
| 1108 | /* if link has been encrypted, do nothing, go straight to furhter action |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1109 | if (p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) |
| 1110 | *p_sec_req_act = BTM_BLE_SEC_REQ_ACT_DISCARD; |
| 1111 | else |
| 1112 | */ |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1113 | *p_sec_req_act = BTM_BLE_SEC_REQ_ACT_ENCRYPT; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1114 | } |
| 1115 | } |
| 1116 | else |
| 1117 | { |
| 1118 | *p_sec_req_act = BTM_BLE_SEC_REQ_ACT_PAIR; /* start the pariring process to upgrade the keys*/ |
| 1119 | } |
| 1120 | } |
| 1121 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1122 | BTM_TRACE_DEBUG("cur_sec_level=%d req_sec_level=%d sec_req_act=%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1123 | cur_sec_level, |
| 1124 | req_sec_level, |
| 1125 | *p_sec_req_act); |
| 1126 | |
| 1127 | } |
| 1128 | |
| 1129 | /******************************************************************************* |
| 1130 | ** |
| 1131 | ** Function btm_ble_set_encryption |
| 1132 | ** |
| 1133 | ** Description This function is called to ensure that LE connection is |
| 1134 | ** encrypted. Should be called only on an open connection. |
| 1135 | ** Typically only needed for connections that first want to |
| 1136 | ** bring up unencrypted links, then later encrypt them. |
| 1137 | ** |
| 1138 | ** Returns void |
| 1139 | ** the local device ER is copied into er |
| 1140 | ** |
| 1141 | *******************************************************************************/ |
| 1142 | tBTM_STATUS btm_ble_set_encryption (BD_ADDR bd_addr, void *p_ref_data, UINT8 link_role) |
| 1143 | { |
| 1144 | tBTM_STATUS cmd = BTM_NO_RESOURCES; |
| 1145 | tBTM_BLE_SEC_ACT sec_act = *(tBTM_BLE_SEC_ACT *)p_ref_data ; |
| 1146 | tBTM_SEC_DEV_REC *p_rec = btm_find_dev (bd_addr); |
| 1147 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1148 | if (p_rec == NULL) |
| 1149 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1150 | BTM_TRACE_WARNING ("btm_ble_set_encryption (NULL device record!! sec_act=0x%x", sec_act); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1151 | return(BTM_WRONG_MODE); |
| 1152 | } |
| 1153 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1154 | BTM_TRACE_DEBUG ("btm_ble_set_encryption sec_act=0x%x role_master=%d", sec_act, p_rec->role_master); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1155 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1156 | if (sec_act == BTM_BLE_SEC_ENCRYPT_MITM) |
| 1157 | { |
| 1158 | p_rec->security_required |= BTM_SEC_IN_MITM; |
| 1159 | } |
| 1160 | |
| 1161 | switch (sec_act) |
| 1162 | { |
| 1163 | case BTM_BLE_SEC_ENCRYPT: |
| 1164 | if (link_role == BTM_ROLE_MASTER) |
| 1165 | { |
Sunny Kapdi | 51822b4 | 2013-08-07 12:30:20 -0700 | [diff] [blame] | 1166 | if(p_rec->sec_state == BTM_SEC_STATE_ENCRYPTING) { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1167 | BTM_TRACE_DEBUG ("State is already encrypting::"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1168 | cmd = BTM_CMD_STARTED; |
| 1169 | } |
Sunny Kapdi | 51822b4 | 2013-08-07 12:30:20 -0700 | [diff] [blame] | 1170 | else { |
| 1171 | /* start link layer encryption using the security info stored */ |
| 1172 | if (btm_ble_start_encrypt(bd_addr, FALSE, NULL)) |
| 1173 | { |
| 1174 | p_rec->sec_state = BTM_SEC_STATE_ENCRYPTING; |
| 1175 | cmd = BTM_CMD_STARTED; |
| 1176 | } |
| 1177 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1178 | break; |
| 1179 | } |
| 1180 | /* if salve role then fall through to call SMP_Pair below which will send a |
| 1181 | sec_request to request the master to encrypt the link */ |
| 1182 | case BTM_BLE_SEC_ENCRYPT_NO_MITM: |
| 1183 | case BTM_BLE_SEC_ENCRYPT_MITM: |
| 1184 | |
| 1185 | if (SMP_Pair(bd_addr) == SMP_STARTED) |
| 1186 | { |
| 1187 | cmd = BTM_CMD_STARTED; |
| 1188 | p_rec->sec_state = BTM_SEC_STATE_AUTHENTICATING; |
| 1189 | } |
| 1190 | break; |
| 1191 | |
| 1192 | default: |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1193 | cmd = BTM_WRONG_MODE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1194 | break; |
| 1195 | } |
| 1196 | return cmd; |
| 1197 | } |
| 1198 | |
| 1199 | /******************************************************************************* |
| 1200 | ** |
| 1201 | ** Function btm_ble_ltk_request |
| 1202 | ** |
| 1203 | ** Description This function is called when encryption request is received |
| 1204 | ** on a slave device. |
| 1205 | ** |
| 1206 | ** |
| 1207 | ** Returns void |
| 1208 | ** |
| 1209 | *******************************************************************************/ |
| 1210 | void btm_ble_ltk_request(UINT16 handle, UINT8 rand[8], UINT16 ediv) |
| 1211 | { |
| 1212 | tBTM_CB *p_cb = &btm_cb; |
| 1213 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev_by_handle (handle); |
| 1214 | BT_OCTET8 dummy_stk = {0}; |
| 1215 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1216 | BTM_TRACE_DEBUG ("btm_ble_ltk_request"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1217 | |
| 1218 | p_cb->ediv = ediv; |
| 1219 | |
| 1220 | memcpy(p_cb->enc_rand, rand, BT_OCTET8_LEN); |
| 1221 | |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 1222 | if (p_dev_rec != NULL) |
| 1223 | { |
| 1224 | if (!smp_proc_ltk_request(p_dev_rec->bd_addr)) |
| 1225 | btm_ble_ltk_request_reply(p_dev_rec->bd_addr, FALSE, dummy_stk); |
| 1226 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1227 | |
| 1228 | } |
| 1229 | |
| 1230 | /******************************************************************************* |
| 1231 | ** |
| 1232 | ** Function btm_ble_start_encrypt |
| 1233 | ** |
| 1234 | ** Description This function is called to start LE encryption. |
| 1235 | ** |
| 1236 | ** |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1237 | ** Returns BTM_SUCCESS if encryption was started successfully |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1238 | ** |
| 1239 | *******************************************************************************/ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1240 | tBTM_STATUS btm_ble_start_encrypt(BD_ADDR bda, BOOLEAN use_stk, BT_OCTET16 stk) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1241 | { |
| 1242 | tBTM_CB *p_cb = &btm_cb; |
| 1243 | tBTM_SEC_DEV_REC *p_rec = btm_find_dev (bda); |
| 1244 | BT_OCTET8 dummy_rand = {0}; |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1245 | tBTM_STATUS rt = BTM_NO_RESOURCES; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1246 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1247 | BTM_TRACE_DEBUG ("btm_ble_start_encrypt"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1248 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1249 | if (!p_rec ) |
| 1250 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1251 | BTM_TRACE_ERROR("Link is not active, can not encrypt!"); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1252 | return BTM_WRONG_MODE; |
| 1253 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1254 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1255 | if (p_rec->sec_state == BTM_SEC_STATE_ENCRYPTING) |
| 1256 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1257 | BTM_TRACE_WARNING("Link Encryption is active, Busy!"); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1258 | return BTM_BUSY; |
| 1259 | } |
| 1260 | |
| 1261 | p_cb->enc_handle = p_rec->ble_hci_handle; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1262 | |
| 1263 | if (use_stk) |
| 1264 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1265 | if (btsnd_hcic_ble_start_enc(p_rec->ble_hci_handle, dummy_rand, 0, stk)) |
| 1266 | rt = BTM_CMD_STARTED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1267 | } |
Andre Eisenbach | ca22ac4 | 2013-02-13 17:02:11 +0900 | [diff] [blame] | 1268 | else if (p_rec->ble.key_type & BTM_LE_KEY_PENC) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1269 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1270 | if (btsnd_hcic_ble_start_enc(p_rec->ble_hci_handle, p_rec->ble.keys.rand, |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1271 | p_rec->ble.keys.ediv, p_rec->ble.keys.ltk)) |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1272 | rt = BTM_CMD_STARTED; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1273 | } |
Andre Eisenbach | ca22ac4 | 2013-02-13 17:02:11 +0900 | [diff] [blame] | 1274 | else |
| 1275 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1276 | BTM_TRACE_ERROR("No key available to encrypt the link"); |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 1277 | } |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1278 | if (rt == BTM_CMD_STARTED) |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 1279 | { |
| 1280 | if (p_rec->sec_state == BTM_SEC_STATE_IDLE) |
| 1281 | p_rec->sec_state = BTM_SEC_STATE_ENCRYPTING; |
Andre Eisenbach | ca22ac4 | 2013-02-13 17:02:11 +0900 | [diff] [blame] | 1282 | } |
| 1283 | |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 1284 | return rt; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | /******************************************************************************* |
| 1288 | ** |
| 1289 | ** Function btm_ble_link_encrypted |
| 1290 | ** |
| 1291 | ** Description This function is called when LE link encrption status is changed. |
| 1292 | ** |
| 1293 | ** Returns void |
| 1294 | ** |
| 1295 | *******************************************************************************/ |
| 1296 | void btm_ble_link_encrypted(BD_ADDR bd_addr, UINT8 encr_enable) |
| 1297 | { |
| 1298 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1299 | BOOLEAN enc_cback; |
| 1300 | |
| 1301 | if (!p_dev_rec) |
| 1302 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1303 | BTM_TRACE_WARNING ("btm_ble_link_encrypted (No Device Found!) encr_enable=%d", encr_enable); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1304 | return; |
| 1305 | } |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1306 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1307 | BTM_TRACE_DEBUG ("btm_ble_link_encrypted encr_enable=%d", encr_enable); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1308 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1309 | enc_cback = (p_dev_rec->sec_state == BTM_SEC_STATE_ENCRYPTING); |
| 1310 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1311 | smp_link_encrypted(bd_addr, encr_enable); |
| 1312 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1313 | BTM_TRACE_DEBUG(" p_dev_rec->sec_flags=0x%x", p_dev_rec->sec_flags); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1314 | |
| 1315 | if (encr_enable && p_dev_rec->enc_key_size == 0) |
| 1316 | p_dev_rec->enc_key_size = p_dev_rec->ble.keys.key_size; |
| 1317 | |
| 1318 | p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; |
| 1319 | if (p_dev_rec->p_callback && enc_cback) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1320 | { |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1321 | if (encr_enable) |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1322 | btm_sec_dev_rec_cback_event(p_dev_rec, BTM_SUCCESS, TRUE); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1323 | else if (p_dev_rec->role_master) |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1324 | btm_sec_dev_rec_cback_event(p_dev_rec, BTM_ERR_PROCESSING, TRUE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1325 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1326 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1327 | /* to notify GATT to send data if any request is pending */ |
| 1328 | gatt_notify_enc_cmpl(p_dev_rec->bd_addr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | /******************************************************************************* |
| 1332 | ** Function btm_enc_proc_ltk |
| 1333 | ** Description send LTK reply when it's ready. |
| 1334 | *******************************************************************************/ |
| 1335 | static void btm_enc_proc_ltk(tSMP_ENC *p) |
| 1336 | { |
| 1337 | UINT8 i; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1338 | BTM_TRACE_DEBUG ("btm_enc_proc_ltk"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1339 | if (p && p->param_len == BT_OCTET16_LEN) |
| 1340 | { |
| 1341 | for (i = 0; i < (BT_OCTET16_LEN - btm_cb.key_size); i ++) |
| 1342 | p->param_buf[BT_OCTET16_LEN - i - 1] = 0; |
| 1343 | btsnd_hcic_ble_ltk_req_reply(btm_cb.enc_handle, p->param_buf); |
| 1344 | } |
| 1345 | } |
| 1346 | |
| 1347 | /******************************************************************************* |
| 1348 | ** Function btm_enc_proc_slave_y |
| 1349 | ** Description calculate LTK when Y is ready |
| 1350 | *******************************************************************************/ |
| 1351 | static void btm_enc_proc_slave_y(tSMP_ENC *p) |
| 1352 | { |
| 1353 | UINT16 div, y; |
| 1354 | UINT8 *pp = p->param_buf; |
| 1355 | tBTM_CB *p_cb = &btm_cb; |
| 1356 | tSMP_ENC output; |
| 1357 | tBTM_SEC_DEV_REC *p_dev_rec; |
| 1358 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1359 | BTM_TRACE_DEBUG ("btm_enc_proc_slave_y"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1360 | if (p != NULL) |
| 1361 | { |
| 1362 | STREAM_TO_UINT16(y, pp); |
| 1363 | |
| 1364 | div = p_cb->ediv ^ y; |
| 1365 | p_dev_rec = btm_find_dev_by_handle (p_cb->enc_handle); |
| 1366 | |
| 1367 | if ( p_dev_rec && |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1368 | p_dev_rec->ble.keys.div == div ) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1369 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1370 | BTM_TRACE_DEBUG ("LTK request OK"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1371 | /* calculating LTK , LTK = E er(div) */ |
| 1372 | SMP_Encrypt(p_cb->devcb.er, BT_OCTET16_LEN, (UINT8 *)&div, 2, &output); |
| 1373 | btm_enc_proc_ltk(&output); |
| 1374 | } |
| 1375 | else |
| 1376 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1377 | BTM_TRACE_DEBUG ("LTK request failed - send negative reply"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1378 | btsnd_hcic_ble_ltk_req_neg_reply(p_cb->enc_handle); |
| 1379 | if (p_dev_rec) |
| 1380 | btm_ble_link_encrypted(p_dev_rec->bd_addr, 0); |
| 1381 | |
| 1382 | } |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | /******************************************************************************* |
| 1387 | ** |
| 1388 | ** Function btm_ble_ltk_request_reply |
| 1389 | ** |
| 1390 | ** Description This function is called to send a LTK request reply on a slave |
| 1391 | ** device. |
| 1392 | ** |
| 1393 | ** Returns void |
| 1394 | ** |
| 1395 | *******************************************************************************/ |
| 1396 | void btm_ble_ltk_request_reply(BD_ADDR bda, BOOLEAN use_stk, BT_OCTET16 stk) |
| 1397 | { |
| 1398 | tBTM_SEC_DEV_REC *p_rec = btm_find_dev (bda); |
| 1399 | tBTM_CB *p_cb = &btm_cb; |
| 1400 | tSMP_ENC output; |
| 1401 | |
| 1402 | if (p_rec == NULL) |
| 1403 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1404 | BTM_TRACE_ERROR("btm_ble_ltk_request_reply received for unknown device"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1405 | return; |
| 1406 | } |
| 1407 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1408 | BTM_TRACE_DEBUG ("btm_ble_ltk_request_reply"); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1409 | p_cb->enc_handle = p_rec->ble_hci_handle; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1410 | p_cb->key_size = p_rec->ble.keys.key_size; |
| 1411 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1412 | BTM_TRACE_ERROR("key size = %d", p_rec->ble.keys.key_size); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1413 | if (use_stk) |
| 1414 | { |
| 1415 | btsnd_hcic_ble_ltk_req_reply(btm_cb.enc_handle, stk); |
| 1416 | } |
| 1417 | else /* calculate LTK using peer device */ |
| 1418 | { |
| 1419 | /* generate Y= Encrypt(DHK, Rand) received from encrypt request */ |
| 1420 | SMP_Encrypt(p_cb->devcb.id_keys.dhk, BT_OCTET16_LEN, p_cb->enc_rand, |
| 1421 | BT_OCTET8_LEN, &output); |
| 1422 | btm_enc_proc_slave_y(&output); |
| 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | /******************************************************************************* |
| 1427 | ** |
| 1428 | ** Function btm_ble_io_capabilities_req |
| 1429 | ** |
| 1430 | ** Description This function is called to handle SMP get IO capability request. |
| 1431 | ** |
| 1432 | ** Returns void |
| 1433 | ** |
| 1434 | *******************************************************************************/ |
| 1435 | UINT8 btm_ble_io_capabilities_req(tBTM_SEC_DEV_REC *p_dev_rec, tBTM_LE_IO_REQ *p_data) |
| 1436 | { |
| 1437 | UINT8 callback_rc = BTM_SUCCESS; |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1438 | BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1439 | if (btm_cb.api.p_le_callback) |
| 1440 | { |
| 1441 | /* the callback function implementation may change the IO capability... */ |
| 1442 | callback_rc = (*btm_cb.api.p_le_callback) (BTM_LE_IO_REQ_EVT, p_dev_rec->bd_addr, (tBTM_LE_EVT_DATA *)p_data); |
| 1443 | } |
| 1444 | #if BTM_OOB_INCLUDED == TRUE |
| 1445 | if ((callback_rc == BTM_SUCCESS) || (BTM_OOB_UNKNOWN != p_data->oob_data)) |
| 1446 | #else |
| 1447 | if (callback_rc == BTM_SUCCESS) |
| 1448 | #endif |
| 1449 | { |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 1450 | #if BTM_BLE_CONFORMANCE_TESTING == TRUE |
| 1451 | if (btm_cb.devcb.keep_rfu_in_auth_req) |
| 1452 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1453 | BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req keep_rfu_in_auth_req = %u", |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 1454 | btm_cb.devcb.keep_rfu_in_auth_req); |
| 1455 | p_data->auth_req &= BTM_LE_AUTH_REQ_MASK_KEEP_RFU; |
| 1456 | btm_cb.devcb.keep_rfu_in_auth_req = FALSE; |
| 1457 | } |
| 1458 | else |
| 1459 | { /* default */ |
| 1460 | p_data->auth_req &= BTM_LE_AUTH_REQ_MASK; |
| 1461 | } |
| 1462 | #else |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1463 | p_data->auth_req &= BTM_LE_AUTH_REQ_MASK; |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 1464 | #endif |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1465 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1466 | BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 1: p_dev_rec->security_required = %d auth_req:%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1467 | p_dev_rec->security_required, p_data->auth_req); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1468 | BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 2: i_keys=0x%x r_keys=0x%x (bit 0-LTK 1-IRK 2-CSRK)", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1469 | p_data->init_keys, |
| 1470 | p_data->resp_keys); |
| 1471 | |
| 1472 | /* if authentication requires MITM protection, put on the mask */ |
| 1473 | if (p_dev_rec->security_required & BTM_SEC_IN_MITM) |
| 1474 | p_data->auth_req |= BTM_LE_AUTH_REQ_MITM; |
| 1475 | |
| 1476 | if (!(p_data->auth_req & SMP_AUTH_BOND)) |
| 1477 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1478 | BTM_TRACE_DEBUG("Non bonding: No keys should be exchanged"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1479 | p_data->init_keys = 0; |
| 1480 | p_data->resp_keys = 0; |
| 1481 | } |
| 1482 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1483 | BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 3: auth_req:%d", p_data->auth_req); |
| 1484 | BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 4: i_keys=0x%x r_keys=0x%x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1485 | p_data->init_keys, |
| 1486 | p_data->resp_keys); |
| 1487 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1488 | BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 5: p_data->io_cap = %d auth_req:%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1489 | p_data->io_cap, p_data->auth_req); |
| 1490 | |
| 1491 | /* remove MITM protection requirement if IO cap does not allow it */ |
| 1492 | if ((p_data->io_cap == BTM_IO_CAP_NONE) && p_data->oob_data == SMP_OOB_NONE) |
| 1493 | p_data->auth_req &= ~BTM_LE_AUTH_REQ_MITM; |
| 1494 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1495 | BTM_TRACE_DEBUG ("btm_ble_io_capabilities_req 6: IO_CAP:%d oob_data:%d auth_req:%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1496 | p_data->io_cap, p_data->oob_data, p_data->auth_req); |
| 1497 | } |
| 1498 | return callback_rc; |
| 1499 | } |
| 1500 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1501 | #if (BLE_PRIVACY_SPT == TRUE ) |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 1502 | /******************************************************************************* |
| 1503 | ** |
| 1504 | ** Function btm_ble_resolve_random_addr_on_conn_cmpl |
| 1505 | ** |
| 1506 | ** Description resolve random address complete on connection complete event. |
| 1507 | ** |
| 1508 | ** Returns void |
| 1509 | ** |
| 1510 | *******************************************************************************/ |
| 1511 | static void btm_ble_resolve_random_addr_on_conn_cmpl(void * p_rec, void *p_data) |
| 1512 | { |
| 1513 | UINT8 *p = (UINT8 *)p_data; |
| 1514 | tBTM_SEC_DEV_REC *match_rec = (tBTM_SEC_DEV_REC *) p_rec; |
| 1515 | UINT8 role, status, bda_type; |
| 1516 | UINT16 handle; |
| 1517 | BD_ADDR bda; |
| 1518 | UINT16 conn_interval, conn_latency, conn_timeout; |
| 1519 | BOOLEAN match = FALSE; |
| 1520 | |
| 1521 | STREAM_TO_UINT8 (status, p); |
| 1522 | STREAM_TO_UINT16 (handle, p); |
| 1523 | STREAM_TO_UINT8 (role, p); |
| 1524 | STREAM_TO_UINT8 (bda_type, p); |
| 1525 | STREAM_TO_BDADDR (bda, p); |
| 1526 | STREAM_TO_UINT16 (conn_interval, p); |
| 1527 | STREAM_TO_UINT16 (conn_latency, p); |
| 1528 | STREAM_TO_UINT16 (conn_timeout, p); |
| 1529 | |
| 1530 | handle = HCID_GET_HANDLE (handle); |
| 1531 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1532 | BTM_TRACE_EVENT ("btm_ble_resolve_random_addr_master_cmpl"); |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 1533 | |
| 1534 | if (match_rec) |
| 1535 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1536 | BTM_TRACE_ERROR("Random match"); |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 1537 | match = TRUE; |
| 1538 | match_rec->ble.active_addr_type = BTM_BLE_ADDR_RRA; |
| 1539 | memcpy(match_rec->ble.cur_rand_addr, bda, BD_ADDR_LEN); |
| 1540 | memcpy(bda, match_rec->bd_addr, BD_ADDR_LEN); |
| 1541 | } |
| 1542 | else |
| 1543 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1544 | BTM_TRACE_ERROR("Random unmatch"); |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | btm_ble_connected(bda, handle, HCI_ENCRYPT_MODE_DISABLED, role, bda_type, match); |
| 1548 | |
| 1549 | l2cble_conn_comp (handle, role, bda, bda_type, conn_interval, |
| 1550 | conn_latency, conn_timeout); |
| 1551 | |
| 1552 | return; |
| 1553 | } |
| 1554 | #endif |
| 1555 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1556 | /******************************************************************************* |
| 1557 | ** |
| 1558 | ** Function btm_ble_connected |
| 1559 | ** |
| 1560 | ** Description This function is when a LE connection to the peer device is |
| 1561 | ** establsihed |
| 1562 | ** |
| 1563 | ** Returns void |
| 1564 | ** |
| 1565 | *******************************************************************************/ |
| 1566 | void btm_ble_connected (UINT8 *bda, UINT16 handle, UINT8 enc_mode, UINT8 role, |
| 1567 | tBLE_ADDR_TYPE addr_type, BOOLEAN addr_matched) |
| 1568 | { |
| 1569 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bda); |
| 1570 | tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 1571 | UNUSED(addr_matched); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1572 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1573 | BTM_TRACE_EVENT ("btm_ble_connected"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1574 | |
| 1575 | /* Commenting out trace due to obf/compilation problems. |
| 1576 | */ |
| 1577 | #if (BT_USE_TRACES == TRUE) |
| 1578 | if (p_dev_rec) |
| 1579 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1580 | BTM_TRACE_EVENT ("Security Manager: btm_ble_connected : handle:%d enc_mode:%d bda:%x RName:%s", |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1581 | handle, enc_mode, |
| 1582 | (bda[2]<<24)+(bda[3]<<16)+(bda[4]<<8)+bda[5], |
| 1583 | p_dev_rec->sec_bd_name); |
| 1584 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1585 | BTM_TRACE_DEBUG ("btm_ble_connected sec_flags=0x%x",p_dev_rec->sec_flags); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1586 | } |
| 1587 | else |
| 1588 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1589 | BTM_TRACE_EVENT ("Security Manager: btm_ble_connected: handle:%d enc_mode:%d bda:%x ", |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1590 | handle, enc_mode, |
| 1591 | (bda[2]<<24)+(bda[3]<<16)+(bda[4]<<8)+bda[5]); |
| 1592 | } |
| 1593 | #endif |
| 1594 | |
| 1595 | if (!p_dev_rec) |
| 1596 | { |
| 1597 | /* There is no device record for new connection. Allocate one */ |
| 1598 | p_dev_rec = btm_sec_alloc_dev (bda); |
| 1599 | } |
| 1600 | else /* Update the timestamp for this device */ |
| 1601 | { |
| 1602 | p_dev_rec->timestamp = btm_cb.dev_rec_count++; |
| 1603 | } |
| 1604 | |
| 1605 | /* update device information */ |
| 1606 | p_dev_rec->device_type |= BT_DEVICE_TYPE_BLE; |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1607 | p_dev_rec->ble_hci_handle = handle; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1608 | p_dev_rec->ble.ble_addr_type = addr_type; |
| 1609 | |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 1610 | p_dev_rec->role_master = FALSE; |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1611 | if (role == HCI_ROLE_MASTER) |
| 1612 | p_dev_rec->role_master = TRUE; |
| 1613 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1614 | #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 1615 | if (!addr_matched) |
| 1616 | p_dev_rec->ble.active_addr_type = BTM_BLE_ADDR_PSEUDO; |
| 1617 | |
| 1618 | if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_RANDOM && !addr_matched) |
| 1619 | memcpy(p_dev_rec->ble.cur_rand_addr, bda, BD_ADDR_LEN); |
Satya Calloji | 0943c10 | 2014-05-12 09:13:02 -0700 | [diff] [blame] | 1620 | |
| 1621 | #if (defined BLE_VND_INCLUDED && BLE_VND_INCLUDED == TRUE) |
| 1622 | btm_ble_vendor_disable_irk_list(); |
| 1623 | #endif |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 1624 | #endif |
| 1625 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1626 | if (role == HCI_ROLE_SLAVE) |
| 1627 | p_cb->inq_var.adv_mode = BTM_BLE_ADV_DISABLE; |
| 1628 | p_cb->inq_var.directed_conn = FALSE; |
| 1629 | |
| 1630 | return; |
| 1631 | } |
| 1632 | |
| 1633 | /***************************************************************************** |
| 1634 | ** Function btm_ble_conn_complete |
| 1635 | ** |
| 1636 | ** Description LE connection complete. |
| 1637 | ** |
| 1638 | ******************************************************************************/ |
| 1639 | void btm_ble_conn_complete(UINT8 *p, UINT16 evt_len) |
| 1640 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1641 | #if (BLE_PRIVACY_SPT == TRUE ) |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 1642 | UINT8 *p_data = p; |
| 1643 | #endif |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1644 | UINT8 role, status, bda_type; |
| 1645 | UINT16 handle; |
| 1646 | BD_ADDR bda; |
| 1647 | UINT16 conn_interval, conn_latency, conn_timeout; |
| 1648 | BOOLEAN match = FALSE; |
Mike J. Chen | 5cd8bff | 2014-01-31 18:16:59 -0800 | [diff] [blame] | 1649 | UNUSED(evt_len); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1650 | |
| 1651 | STREAM_TO_UINT8 (status, p); |
| 1652 | STREAM_TO_UINT16 (handle, p); |
| 1653 | STREAM_TO_UINT8 (role, p); |
| 1654 | STREAM_TO_UINT8 (bda_type, p); |
| 1655 | STREAM_TO_BDADDR (bda, p); |
| 1656 | |
| 1657 | if (status == 0) |
| 1658 | { |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1659 | #if (BLE_PRIVACY_SPT == TRUE ) |
Satya Calloji | 0943c10 | 2014-05-12 09:13:02 -0700 | [diff] [blame] | 1660 | #if (BLE_VND_INCLUDED == TRUE) |
| 1661 | match = btm_public_addr_to_random_pseudo (bda, &bda_type); |
| 1662 | #endif |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 1663 | /* possiblly receive connection complete with resolvable random on |
| 1664 | slave role while the device has been paired */ |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1665 | if (!match && role == HCI_ROLE_SLAVE && BTM_BLE_IS_RESOLVE_BDA(bda)) |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 1666 | { |
| 1667 | btm_ble_resolve_random_addr(bda, btm_ble_resolve_random_addr_on_conn_cmpl, p_data); |
| 1668 | } |
| 1669 | else |
| 1670 | #endif |
| 1671 | { |
| 1672 | STREAM_TO_UINT16 (conn_interval, p); |
| 1673 | STREAM_TO_UINT16 (conn_latency, p); |
| 1674 | STREAM_TO_UINT16 (conn_timeout, p); |
| 1675 | handle = HCID_GET_HANDLE (handle); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1676 | |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 1677 | btm_ble_connected(bda, handle, HCI_ENCRYPT_MODE_DISABLED, role, bda_type, match); |
| 1678 | l2cble_conn_comp (handle, role, bda, bda_type, conn_interval, |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1679 | conn_latency, conn_timeout); |
Zhihai Xu | 6f908b2 | 2014-03-11 15:01:45 -0700 | [diff] [blame] | 1680 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1681 | } |
| 1682 | else |
| 1683 | { |
| 1684 | role = HCI_ROLE_UNKNOWN; |
| 1685 | |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 1686 | if (status != HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT) |
Zhihai Xu | 83d709a | 2014-01-14 17:46:26 -0800 | [diff] [blame] | 1687 | { |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 1688 | btm_ble_set_conn_st(BLE_CONN_IDLE); |
Zhihai Xu | 83d709a | 2014-01-14 17:46:26 -0800 | [diff] [blame] | 1689 | } |
| 1690 | /* this is to work around broadcom firmware problem to handle |
| 1691 | * unsolicited command complete event for HCI_LE_Create_Connection_Cancel |
| 1692 | * and LE connection complete event with status error code (0x2) |
| 1693 | * unknown connection identifier from bluetooth controller |
| 1694 | * the workaround is to release the HCI connection to avoid out of sync |
| 1695 | * with bluetooth controller, which cause BT can't be turned off. |
| 1696 | */ |
| 1697 | else if ((status == HCI_ERR_NO_CONNECTION) && |
| 1698 | (btm_ble_get_conn_st() != BLE_CONN_CANCEL)) |
| 1699 | { |
| 1700 | tL2C_LCB *p_lcb; |
| 1701 | handle = HCID_GET_HANDLE (handle); |
| 1702 | p_lcb = l2cu_find_lcb_by_handle (handle); |
| 1703 | if (p_lcb != NULL) |
| 1704 | { |
| 1705 | l2c_link_hci_disc_comp (handle, HCI_ERR_PEER_USER); |
| 1706 | btm_sec_disconnected (handle, HCI_ERR_PEER_USER); |
| 1707 | } |
| 1708 | } |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1709 | } |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 1710 | btm_ble_set_conn_st(BLE_CONN_IDLE); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1711 | btm_ble_update_mode_operation(role, bda, TRUE); |
| 1712 | } |
| 1713 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1714 | /***************************************************************************** |
| 1715 | ** Function btm_proc_smp_cback |
| 1716 | ** |
| 1717 | ** Description This function is the SMP callback handler. |
| 1718 | ** |
| 1719 | ******************************************************************************/ |
| 1720 | UINT8 btm_proc_smp_cback(tSMP_EVT event, BD_ADDR bd_addr, tSMP_EVT_DATA *p_data) |
| 1721 | { |
| 1722 | tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1723 | UINT8 res = 0; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1724 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1725 | BTM_TRACE_DEBUG ("btm_proc_smp_cback event = %d", event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1726 | |
| 1727 | if (p_dev_rec != NULL) |
| 1728 | { |
| 1729 | switch (event) |
| 1730 | { |
| 1731 | case SMP_IO_CAP_REQ_EVT: |
| 1732 | btm_ble_io_capabilities_req(p_dev_rec, (tBTM_LE_IO_REQ *)&p_data->io_req); |
| 1733 | break; |
| 1734 | |
| 1735 | case SMP_PASSKEY_REQ_EVT: |
| 1736 | case SMP_PASSKEY_NOTIF_EVT: |
| 1737 | case SMP_OOB_REQ_EVT: |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1738 | p_dev_rec->sec_flags |= BTM_SEC_LE_AUTHENTICATED; |
| 1739 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1740 | case SMP_SEC_REQUEST_EVT: |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 1741 | memcpy (btm_cb.pairing_bda, bd_addr, BD_ADDR_LEN); |
| 1742 | p_dev_rec->sec_state = BTM_SEC_STATE_AUTHENTICATING; |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1743 | btm_cb.pairing_flags |= BTM_PAIR_FLAGS_LE_ACTIVE; |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 1744 | /* fall through */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1745 | case SMP_COMPLT_EVT: |
| 1746 | if (btm_cb.api.p_le_callback) |
| 1747 | { |
| 1748 | /* the callback function implementation may change the IO capability... */ |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1749 | BTM_TRACE_DEBUG ("btm_cb.api.p_le_callback=0x%x", btm_cb.api.p_le_callback ); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1750 | (*btm_cb.api.p_le_callback) (event, bd_addr, (tBTM_LE_EVT_DATA *)p_data); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | if (event == SMP_COMPLT_EVT) |
| 1754 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1755 | BTM_TRACE_DEBUG ("evt=SMP_COMPLT_EVT before update sec_level=0x%x sec_flags=0x%x", p_data->cmplt.sec_level , p_dev_rec->sec_flags ); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1756 | |
| 1757 | res = (p_data->cmplt.reason == SMP_SUCCESS) ? BTM_SUCCESS : BTM_ERR_PROCESSING; |
| 1758 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1759 | BTM_TRACE_DEBUG ("after update result=%d sec_level=0x%x sec_flags=0x%x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1760 | res, p_data->cmplt.sec_level , p_dev_rec->sec_flags ); |
| 1761 | |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1762 | btm_sec_dev_rec_cback_event(p_dev_rec, res, TRUE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1763 | |
| 1764 | if (p_data->cmplt.is_pair_cancel && btm_cb.api.p_bond_cancel_cmpl_callback ) |
| 1765 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1766 | BTM_TRACE_DEBUG ("Pairing Cancel completed"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1767 | (*btm_cb.api.p_bond_cancel_cmpl_callback)(BTM_SUCCESS); |
| 1768 | } |
| 1769 | #if BTM_BLE_CONFORMANCE_TESTING == TRUE |
| 1770 | if (res != BTM_SUCCESS) |
| 1771 | { |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 1772 | if (!btm_cb.devcb.no_disc_if_pair_fail && p_data->cmplt.reason != SMP_CONN_TOUT) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1773 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1774 | BTM_TRACE_DEBUG ("Pairing failed - Remove ACL"); |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1775 | btm_remove_acl(bd_addr, BT_TRANSPORT_LE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1776 | } |
| 1777 | else |
| 1778 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1779 | BTM_TRACE_DEBUG ("Pairing failed - Not Removing ACL"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1780 | p_dev_rec->sec_state = BTM_SEC_STATE_IDLE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1781 | } |
| 1782 | } |
| 1783 | #else |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 1784 | if (res != BTM_SUCCESS && p_data->cmplt.reason != SMP_CONN_TOUT) |
Ganesh Ganapathi Batta | 8fe5887 | 2014-04-16 16:50:09 -0700 | [diff] [blame] | 1785 | btm_remove_acl(bd_addr, BT_TRANSPORT_LE); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1786 | #endif |
| 1787 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1788 | BTM_TRACE_DEBUG ("btm_cb pairing_state=%x pairing_flags=%x pin_code_len=%x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1789 | btm_cb.pairing_state, |
| 1790 | btm_cb.pairing_flags, |
| 1791 | btm_cb.pin_code_len ); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1792 | BTM_TRACE_DEBUG ("btm_cb.pairing_bda %02x:%02x:%02x:%02x:%02x:%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1793 | btm_cb.pairing_bda[0], btm_cb.pairing_bda[1], btm_cb.pairing_bda[2], |
| 1794 | btm_cb.pairing_bda[3], btm_cb.pairing_bda[4], btm_cb.pairing_bda[5]); |
| 1795 | |
| 1796 | memset (btm_cb.pairing_bda, 0xff, BD_ADDR_LEN); |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 1797 | btm_cb.pairing_state = BTM_PAIR_STATE_IDLE; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1798 | btm_cb.pairing_flags = 0; |
| 1799 | } |
| 1800 | break; |
| 1801 | |
| 1802 | default: |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1803 | BTM_TRACE_DEBUG ("unknown event = %d", event); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1804 | break; |
| 1805 | |
| 1806 | |
| 1807 | } |
| 1808 | } |
| 1809 | else |
| 1810 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1811 | BTM_TRACE_ERROR("btm_proc_smp_cback received for unknown device"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | return 0; |
| 1815 | } |
| 1816 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1817 | #endif /* SMP_INCLUDED */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1818 | |
| 1819 | /******************************************************************************* |
| 1820 | ** |
| 1821 | ** Function BTM_BleDataSignature |
| 1822 | ** |
| 1823 | ** Description This function is called to sign the data using AES128 CMAC |
| 1824 | ** algorith. |
| 1825 | ** |
| 1826 | ** Parameter bd_addr: target device the data to be signed for. |
| 1827 | ** p_text: singing data |
| 1828 | ** len: length of the data to be signed. |
| 1829 | ** signature: output parameter where data signature is going to |
| 1830 | ** be stored. |
| 1831 | ** |
| 1832 | ** Returns TRUE if signing sucessul, otherwise FALSE. |
| 1833 | ** |
| 1834 | *******************************************************************************/ |
| 1835 | BOOLEAN BTM_BleDataSignature (BD_ADDR bd_addr, UINT8 *p_text, UINT16 len, |
| 1836 | BLE_SIGNATURE signature) |
| 1837 | { |
| 1838 | BOOLEAN ret = FALSE; |
Mike J. Chen | bf9a8aa | 2014-02-11 13:51:29 -0800 | [diff] [blame] | 1839 | #if SMP_INCLUDED == TRUE |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1840 | tBTM_SEC_DEV_REC *p_rec = btm_find_dev (bd_addr); |
| 1841 | UINT8 *p_buf, *pp; |
| 1842 | |
| 1843 | BT_OCTET16 er; |
| 1844 | UINT16 div; |
| 1845 | UINT8 temp[4]; /* for (r || DIV) r=1*/ |
| 1846 | UINT16 r=1; |
| 1847 | UINT8 *p=temp, *p_mac = (UINT8 *)signature; |
| 1848 | tSMP_ENC output; |
| 1849 | BT_OCTET16 local_csrk; |
| 1850 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1851 | BTM_TRACE_DEBUG ("BTM_BleDataSignature"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1852 | if (p_rec == NULL) |
| 1853 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1854 | BTM_TRACE_ERROR("data signing can not be done from unknow device"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1855 | } |
| 1856 | else |
| 1857 | { |
| 1858 | if ((p_buf = (UINT8 *)GKI_getbuf((UINT16)(len + 4))) != NULL) |
| 1859 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1860 | BTM_TRACE_DEBUG("Start to generate Local CSRK"); |
Andre Eisenbach | 6975b4d | 2013-08-05 16:55:38 -0700 | [diff] [blame] | 1861 | pp = p_buf; |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1862 | /* prepare plain text */ |
| 1863 | if (p_text) |
| 1864 | { |
| 1865 | memcpy(p_buf, p_text, len); |
| 1866 | pp = (p_buf + len); |
| 1867 | } |
| 1868 | |
| 1869 | #if BTM_BLE_CONFORMANCE_TESTING == TRUE |
| 1870 | if ( btm_cb.devcb.enable_test_local_sign_cntr) |
| 1871 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1872 | BTM_TRACE_DEBUG ("Use Test local counter value from script counter_val=%d", btm_cb.devcb.test_local_sign_cntr); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1873 | UINT32_TO_STREAM(pp, btm_cb.devcb.test_local_sign_cntr); |
| 1874 | } |
| 1875 | else |
| 1876 | { |
| 1877 | UINT32_TO_STREAM(pp, p_rec->ble.keys.local_counter); |
| 1878 | } |
| 1879 | #else |
| 1880 | UINT32_TO_STREAM(pp, p_rec->ble.keys.local_counter); |
| 1881 | #endif |
| 1882 | /* compute local csrk */ |
| 1883 | if (btm_get_local_div(bd_addr, &div)) |
| 1884 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1885 | BTM_TRACE_DEBUG ("compute_csrk div=%x", div); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1886 | BTM_GetDeviceEncRoot(er); |
| 1887 | |
| 1888 | /* CSRK = d1(ER, DIV, 1) */ |
| 1889 | UINT16_TO_STREAM(p, div); |
| 1890 | UINT16_TO_STREAM(p, r); |
| 1891 | |
| 1892 | if (!SMP_Encrypt(er, BT_OCTET16_LEN, temp, 4, &output)) |
| 1893 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1894 | BTM_TRACE_ERROR("Local CSRK generation failed "); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1895 | } |
| 1896 | else |
| 1897 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1898 | BTM_TRACE_DEBUG("local CSRK generation success"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1899 | memcpy((void *)local_csrk, output.param_buf, BT_OCTET16_LEN); |
| 1900 | |
| 1901 | |
| 1902 | #if BTM_BLE_CONFORMANCE_TESTING == TRUE |
| 1903 | if (btm_cb.devcb.enable_test_local_sign_cntr) |
| 1904 | { |
| 1905 | UINT32_TO_STREAM(p_mac, btm_cb.devcb.test_local_sign_cntr); |
| 1906 | } |
| 1907 | else |
| 1908 | { |
| 1909 | UINT32_TO_STREAM(p_mac, p_rec->ble.keys.local_counter); |
| 1910 | } |
| 1911 | #else |
| 1912 | UINT32_TO_STREAM(p_mac, p_rec->ble.keys.local_counter); |
| 1913 | #endif |
| 1914 | |
| 1915 | if ((ret = AES_CMAC(local_csrk, p_buf, (UINT16)(len + 4), BTM_CMAC_TLEN_SIZE, p_mac)) == TRUE) |
| 1916 | { |
| 1917 | btm_ble_increment_sign_ctr(bd_addr, TRUE); |
| 1918 | |
| 1919 | #if BTM_BLE_CONFORMANCE_TESTING == TRUE |
| 1920 | if ( btm_cb.devcb.enable_test_mac_val) |
| 1921 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1922 | BTM_TRACE_DEBUG ("Use MAC value from script"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1923 | memcpy(p_mac, btm_cb.devcb.test_mac, BTM_CMAC_TLEN_SIZE); |
| 1924 | } |
| 1925 | #endif |
| 1926 | } |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1927 | BTM_TRACE_DEBUG("BTM_BleDataSignature p_mac = %d", p_mac); |
| 1928 | BTM_TRACE_DEBUG("p_mac[0] = 0x%02x p_mac[1] = 0x%02x p_mac[2] = 0x%02x p_mac[3] = 0x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1929 | *p_mac, *(p_mac + 1), *(p_mac + 2), *(p_mac + 3)); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1930 | BTM_TRACE_DEBUG("p_mac[4] = 0x%02x p_mac[5] = 0x%02x p_mac[6] = 0x%02x p_mac[7] = 0x%02x", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1931 | *(p_mac + 4), *(p_mac + 5), *(p_mac + 6), *(p_mac + 7)); |
| 1932 | |
| 1933 | GKI_freebuf(p_buf); |
| 1934 | } |
| 1935 | } |
| 1936 | } |
| 1937 | } |
Mike J. Chen | bf9a8aa | 2014-02-11 13:51:29 -0800 | [diff] [blame] | 1938 | #endif /* SMP_INCLUDED */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1939 | return ret; |
| 1940 | } |
| 1941 | |
| 1942 | /******************************************************************************* |
| 1943 | ** |
| 1944 | ** Function BTM_BleVerifySignature |
| 1945 | ** |
| 1946 | ** Description This function is called to verify the data signature |
| 1947 | ** |
| 1948 | ** Parameter bd_addr: target device the data to be signed for. |
| 1949 | ** p_orig: original data before signature. |
| 1950 | ** len: length of the signing data |
| 1951 | ** counter: counter used when doing data signing |
| 1952 | ** p_comp: signature to be compared against. |
| 1953 | |
| 1954 | ** Returns TRUE if signature verified correctly; otherwise FALSE. |
| 1955 | ** |
| 1956 | *******************************************************************************/ |
| 1957 | BOOLEAN BTM_BleVerifySignature (BD_ADDR bd_addr, UINT8 *p_orig, UINT16 len, UINT32 counter, |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 1958 | UINT8 *p_comp) |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1959 | { |
| 1960 | BOOLEAN verified = FALSE; |
Mike J. Chen | bf9a8aa | 2014-02-11 13:51:29 -0800 | [diff] [blame] | 1961 | #if SMP_INCLUDED == TRUE |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1962 | tBTM_SEC_DEV_REC *p_rec = btm_find_dev (bd_addr); |
| 1963 | UINT8 p_mac[BTM_CMAC_TLEN_SIZE]; |
| 1964 | |
| 1965 | if (p_rec == NULL || (p_rec && !(p_rec->ble.key_type & BTM_LE_KEY_PCSRK))) |
| 1966 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1967 | BTM_TRACE_ERROR("can not verify signature for unknown device"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1968 | } |
| 1969 | else if (counter < p_rec->ble.keys.counter) |
| 1970 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1971 | BTM_TRACE_ERROR("signature received with out dated sign counter"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1972 | } |
| 1973 | else if (p_orig == NULL) |
| 1974 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1975 | BTM_TRACE_ERROR("No signature to verify"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1976 | } |
| 1977 | else |
| 1978 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 1979 | BTM_TRACE_DEBUG ("BTM_BleVerifySignature rcv_cnt=%d >= expected_cnt=%d", counter, p_rec->ble.keys.counter); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1980 | |
| 1981 | if (AES_CMAC(p_rec->ble.keys.csrk, p_orig, len, BTM_CMAC_TLEN_SIZE, p_mac)) |
| 1982 | { |
| 1983 | if (memcmp(p_mac, p_comp, BTM_CMAC_TLEN_SIZE) == 0) |
| 1984 | { |
| 1985 | btm_ble_increment_sign_ctr(bd_addr, FALSE); |
| 1986 | verified = TRUE; |
| 1987 | } |
| 1988 | } |
| 1989 | } |
Mike J. Chen | bf9a8aa | 2014-02-11 13:51:29 -0800 | [diff] [blame] | 1990 | #endif /* SMP_INCLUDED */ |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1991 | return verified; |
| 1992 | } |
| 1993 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 1994 | /******************************************************************************* |
| 1995 | ** Utility functions for LE device IR/ER generation |
| 1996 | *******************************************************************************/ |
| 1997 | /******************************************************************************* |
| 1998 | ** |
| 1999 | ** Function btm_notify_new_key |
| 2000 | ** |
| 2001 | ** Description This function is to notify application new keys have been |
| 2002 | ** generated. |
| 2003 | ** |
| 2004 | ** Returns void |
| 2005 | ** |
| 2006 | *******************************************************************************/ |
| 2007 | static void btm_notify_new_key(UINT8 key_type) |
| 2008 | { |
| 2009 | tBTM_BLE_LOCAL_KEYS *p_locak_keys = NULL; |
| 2010 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2011 | BTM_TRACE_DEBUG ("btm_notify_new_key key_type=%d", key_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2012 | |
| 2013 | if (btm_cb.api.p_le_key_callback) |
| 2014 | { |
| 2015 | switch (key_type) |
| 2016 | { |
| 2017 | case BTM_BLE_KEY_TYPE_ID: |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2018 | BTM_TRACE_DEBUG ("BTM_BLE_KEY_TYPE_ID"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2019 | p_locak_keys = (tBTM_BLE_LOCAL_KEYS *)&btm_cb.devcb.id_keys; |
| 2020 | break; |
| 2021 | |
| 2022 | case BTM_BLE_KEY_TYPE_ER: |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2023 | BTM_TRACE_DEBUG ("BTM_BLE_KEY_TYPE_ER"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2024 | p_locak_keys = (tBTM_BLE_LOCAL_KEYS *)&btm_cb.devcb.er; |
| 2025 | break; |
| 2026 | |
| 2027 | default: |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2028 | BTM_TRACE_ERROR("unknown key type: %d", key_type); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2029 | break; |
| 2030 | } |
| 2031 | if (p_locak_keys != NULL) |
| 2032 | (*btm_cb.api.p_le_key_callback) (key_type, p_locak_keys); |
| 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | /******************************************************************************* |
| 2037 | ** |
| 2038 | ** Function btm_ble_process_er2 |
| 2039 | ** |
| 2040 | ** Description This function is called when ER is generated, store it in |
| 2041 | ** local control block. |
| 2042 | ** |
| 2043 | ** Returns void |
| 2044 | ** |
| 2045 | *******************************************************************************/ |
| 2046 | static void btm_ble_process_er2(tBTM_RAND_ENC *p) |
| 2047 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2048 | BTM_TRACE_DEBUG ("btm_ble_process_er2"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2049 | |
| 2050 | if (p &&p->opcode == HCI_BLE_RAND) |
| 2051 | { |
| 2052 | memcpy(&btm_cb.devcb.er[8], p->param_buf, BT_OCTET8_LEN); |
| 2053 | btm_notify_new_key(BTM_BLE_KEY_TYPE_ER); |
| 2054 | } |
| 2055 | else |
| 2056 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2057 | BTM_TRACE_ERROR("Generating ER2 exception."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2058 | memset(&btm_cb.devcb.er, 0, sizeof(BT_OCTET16)); |
| 2059 | } |
| 2060 | } |
| 2061 | |
| 2062 | /******************************************************************************* |
| 2063 | ** |
| 2064 | ** Function btm_ble_process_er |
| 2065 | ** |
| 2066 | ** Description This function is called when ER is generated, store it in |
| 2067 | ** local control block. |
| 2068 | ** |
| 2069 | ** Returns void |
| 2070 | ** |
| 2071 | *******************************************************************************/ |
| 2072 | static void btm_ble_process_er(tBTM_RAND_ENC *p) |
| 2073 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2074 | BTM_TRACE_DEBUG ("btm_ble_process_er"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2075 | |
| 2076 | if (p &&p->opcode == HCI_BLE_RAND) |
| 2077 | { |
| 2078 | memcpy(&btm_cb.devcb.er[0], p->param_buf, BT_OCTET8_LEN); |
| 2079 | |
| 2080 | if (!btsnd_hcic_ble_rand((void *)btm_ble_process_er2)) |
| 2081 | { |
| 2082 | memset(&btm_cb.devcb.er, 0, sizeof(BT_OCTET16)); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2083 | BTM_TRACE_ERROR("Generating ER2 failed."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2084 | } |
| 2085 | } |
| 2086 | else |
| 2087 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2088 | BTM_TRACE_ERROR("Generating ER1 exception."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | /******************************************************************************* |
| 2093 | ** |
| 2094 | ** Function btm_ble_process_irk |
| 2095 | ** |
| 2096 | ** Description This function is called when IRK is generated, store it in |
| 2097 | ** local control block. |
| 2098 | ** |
| 2099 | ** Returns void |
| 2100 | ** |
| 2101 | *******************************************************************************/ |
| 2102 | static void btm_ble_process_irk(tSMP_ENC *p) |
| 2103 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2104 | BTM_TRACE_DEBUG ("btm_ble_process_irk"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2105 | if (p &&p->opcode == HCI_BLE_ENCRYPT) |
| 2106 | { |
| 2107 | memcpy(btm_cb.devcb.id_keys.irk, p->param_buf, BT_OCTET16_LEN); |
| 2108 | btm_notify_new_key(BTM_BLE_KEY_TYPE_ID); |
| 2109 | } |
| 2110 | else |
| 2111 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2112 | BTM_TRACE_ERROR("Generating IRK exception."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | /* proceed generate ER */ |
| 2116 | if (!btsnd_hcic_ble_rand((void *)btm_ble_process_er)) |
| 2117 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2118 | BTM_TRACE_ERROR("Generating ER failed."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2119 | } |
| 2120 | } |
| 2121 | |
| 2122 | /******************************************************************************* |
| 2123 | ** |
| 2124 | ** Function btm_ble_process_dhk |
| 2125 | ** |
| 2126 | ** Description This function is called when DHK is calculated, store it in |
| 2127 | ** local control block, and proceed to generate ER, a 128-bits |
| 2128 | ** random number. |
| 2129 | ** |
| 2130 | ** Returns void |
| 2131 | ** |
| 2132 | *******************************************************************************/ |
| 2133 | static void btm_ble_process_dhk(tSMP_ENC *p) |
| 2134 | { |
| 2135 | #if SMP_INCLUDED == TRUE |
| 2136 | UINT8 btm_ble_irk_pt = 0x01; |
| 2137 | tSMP_ENC output; |
| 2138 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2139 | BTM_TRACE_DEBUG ("btm_ble_process_dhk"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2140 | |
| 2141 | if (p && p->opcode == HCI_BLE_ENCRYPT) |
| 2142 | { |
| 2143 | memcpy(btm_cb.devcb.id_keys.dhk, p->param_buf, BT_OCTET16_LEN); |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2144 | BTM_TRACE_DEBUG("BLE DHK generated."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2145 | |
| 2146 | /* IRK = D1(IR, 1) */ |
| 2147 | if (!SMP_Encrypt(btm_cb.devcb.id_keys.ir, BT_OCTET16_LEN, &btm_ble_irk_pt, |
| 2148 | 1, &output)) |
| 2149 | { |
| 2150 | /* reset all identity root related key */ |
| 2151 | memset(&btm_cb.devcb.id_keys, 0, sizeof(tBTM_BLE_LOCAL_ID_KEYS)); |
| 2152 | } |
| 2153 | else |
| 2154 | { |
| 2155 | btm_ble_process_irk(&output); |
| 2156 | } |
| 2157 | } |
| 2158 | else |
| 2159 | { |
| 2160 | /* reset all identity root related key */ |
| 2161 | memset(&btm_cb.devcb.id_keys, 0, sizeof(tBTM_BLE_LOCAL_ID_KEYS)); |
| 2162 | } |
| 2163 | #endif |
| 2164 | } |
| 2165 | |
| 2166 | /******************************************************************************* |
| 2167 | ** |
| 2168 | ** Function btm_ble_process_ir2 |
| 2169 | ** |
| 2170 | ** Description This function is called when IR is generated, proceed to calculate |
| 2171 | ** DHK = Eir({0x03, 0, 0 ...}) |
| 2172 | ** |
| 2173 | ** |
| 2174 | ** Returns void |
| 2175 | ** |
| 2176 | *******************************************************************************/ |
| 2177 | static void btm_ble_process_ir2(tBTM_RAND_ENC *p) |
| 2178 | { |
| 2179 | #if SMP_INCLUDED == TRUE |
| 2180 | UINT8 btm_ble_dhk_pt = 0x03; |
| 2181 | tSMP_ENC output; |
| 2182 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2183 | BTM_TRACE_DEBUG ("btm_ble_process_ir2"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2184 | |
| 2185 | if (p && p->opcode == HCI_BLE_RAND) |
| 2186 | { |
| 2187 | /* remembering in control block */ |
| 2188 | memcpy(&btm_cb.devcb.id_keys.ir[8], p->param_buf, BT_OCTET8_LEN); |
| 2189 | /* generate DHK= Eir({0x03, 0x00, 0x00 ...}) */ |
| 2190 | |
| 2191 | |
| 2192 | SMP_Encrypt(btm_cb.devcb.id_keys.ir, BT_OCTET16_LEN, &btm_ble_dhk_pt, |
| 2193 | 1, &output); |
| 2194 | btm_ble_process_dhk(&output); |
| 2195 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2196 | BTM_TRACE_DEBUG("BLE IR generated."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2197 | } |
| 2198 | else |
| 2199 | { |
| 2200 | memset(&btm_cb.devcb.id_keys, 0, sizeof(tBTM_BLE_LOCAL_ID_KEYS)); |
| 2201 | } |
| 2202 | #endif |
| 2203 | } |
| 2204 | |
| 2205 | /******************************************************************************* |
| 2206 | ** |
| 2207 | ** Function btm_ble_process_ir |
| 2208 | ** |
| 2209 | ** Description This function is called when IR is generated, proceed to calculate |
| 2210 | ** DHK = Eir({0x02, 0, 0 ...}) |
| 2211 | ** |
| 2212 | ** |
| 2213 | ** Returns void |
| 2214 | ** |
| 2215 | *******************************************************************************/ |
| 2216 | static void btm_ble_process_ir(tBTM_RAND_ENC *p) |
| 2217 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2218 | BTM_TRACE_DEBUG ("btm_ble_process_ir"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2219 | |
| 2220 | if (p && p->opcode == HCI_BLE_RAND) |
| 2221 | { |
| 2222 | /* remembering in control block */ |
| 2223 | memcpy(btm_cb.devcb.id_keys.ir, p->param_buf, BT_OCTET8_LEN); |
| 2224 | |
| 2225 | if (!btsnd_hcic_ble_rand((void *)btm_ble_process_ir2)) |
| 2226 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2227 | BTM_TRACE_ERROR("Generating IR2 failed."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2228 | memset(&btm_cb.devcb.id_keys, 0, sizeof(tBTM_BLE_LOCAL_ID_KEYS)); |
| 2229 | } |
| 2230 | } |
| 2231 | } |
| 2232 | |
| 2233 | /******************************************************************************* |
| 2234 | ** |
| 2235 | ** Function btm_ble_reset_id |
| 2236 | ** |
| 2237 | ** Description This function is called to reset LE device identity. |
| 2238 | ** |
| 2239 | ** Returns void |
| 2240 | ** |
| 2241 | *******************************************************************************/ |
| 2242 | void btm_ble_reset_id( void ) |
| 2243 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2244 | BTM_TRACE_DEBUG ("btm_ble_reset_id"); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2245 | |
| 2246 | /* regenrate Identity Root*/ |
| 2247 | if (!btsnd_hcic_ble_rand((void *)btm_ble_process_ir)) |
| 2248 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2249 | BTM_TRACE_DEBUG("Generating IR failed."); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2250 | } |
| 2251 | } |
| 2252 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2253 | #if BTM_BLE_CONFORMANCE_TESTING == TRUE |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2254 | /******************************************************************************* |
| 2255 | ** |
| 2256 | ** Function btm_ble_set_no_disc_if_pair_fail |
| 2257 | ** |
| 2258 | ** Description This function indicates that whether no disconnect of the ACL |
| 2259 | ** should be used if pairing failed |
| 2260 | ** |
| 2261 | ** Returns void |
| 2262 | ** |
| 2263 | *******************************************************************************/ |
| 2264 | void btm_ble_set_no_disc_if_pair_fail(BOOLEAN disable_disc ) |
| 2265 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2266 | BTM_TRACE_DEBUG ("btm_ble_set_disc_enable_if_pair_fail disable_disc=%d", disable_disc); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2267 | btm_cb.devcb.no_disc_if_pair_fail = disable_disc; |
| 2268 | } |
| 2269 | |
| 2270 | /******************************************************************************* |
| 2271 | ** |
| 2272 | ** Function btm_ble_set_test_mac_value |
| 2273 | ** |
| 2274 | ** Description This function set test MAC value |
| 2275 | ** |
| 2276 | ** Returns void |
| 2277 | ** |
| 2278 | *******************************************************************************/ |
| 2279 | void btm_ble_set_test_mac_value(BOOLEAN enable, UINT8 *p_test_mac_val ) |
| 2280 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2281 | BTM_TRACE_DEBUG ("btm_ble_set_test_mac_value enable=%d", enable); |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2282 | btm_cb.devcb.enable_test_mac_val = enable; |
| 2283 | memcpy(btm_cb.devcb.test_mac, p_test_mac_val, BT_OCTET8_LEN); |
| 2284 | } |
| 2285 | |
| 2286 | /******************************************************************************* |
| 2287 | ** |
| 2288 | ** Function btm_ble_set_test_local_sign_cntr_value |
| 2289 | ** |
| 2290 | ** Description This function set test local sign counter value |
| 2291 | ** |
| 2292 | ** Returns void |
| 2293 | ** |
| 2294 | *******************************************************************************/ |
| 2295 | void btm_ble_set_test_local_sign_cntr_value(BOOLEAN enable, UINT32 test_local_sign_cntr ) |
| 2296 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2297 | BTM_TRACE_DEBUG ("btm_ble_set_test_local_sign_cntr_value enable=%d local_sign_cntr=%d", |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2298 | enable, test_local_sign_cntr); |
| 2299 | btm_cb.devcb.enable_test_local_sign_cntr = enable; |
| 2300 | btm_cb.devcb.test_local_sign_cntr = test_local_sign_cntr; |
| 2301 | } |
| 2302 | |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2303 | /******************************************************************************* |
| 2304 | ** |
| 2305 | ** Function btm_set_random_address |
| 2306 | ** |
| 2307 | ** Description This function set a random address to local controller. |
| 2308 | ** |
| 2309 | ** Returns void |
| 2310 | ** |
| 2311 | *******************************************************************************/ |
| 2312 | void btm_set_random_address(BD_ADDR random_bda) |
| 2313 | { |
| 2314 | tBTM_LE_RANDOM_CB *p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; |
| 2315 | BOOLEAN adv_mode = btm_cb.ble_ctr_cb.inq_var.adv_mode ; |
| 2316 | |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2317 | BTM_TRACE_DEBUG ("btm_set_random_address"); |
Ganesh Ganapathi Batta | ead3cde | 2013-02-05 15:22:31 -0800 | [diff] [blame] | 2318 | |
| 2319 | if (adv_mode == BTM_BLE_ADV_ENABLE) |
| 2320 | btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_DISABLE); |
| 2321 | |
| 2322 | memcpy(p_cb->private_addr, random_bda, BD_ADDR_LEN); |
| 2323 | btsnd_hcic_ble_set_random_addr(p_cb->private_addr); |
| 2324 | |
| 2325 | if (adv_mode == BTM_BLE_ADV_ENABLE) |
| 2326 | btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE); |
| 2327 | |
| 2328 | |
| 2329 | } |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 2330 | |
| 2331 | /******************************************************************************* |
| 2332 | ** |
| 2333 | ** Function btm_ble_set_keep_rfu_in_auth_req |
| 2334 | ** |
| 2335 | ** Description This function indicates if RFU bits have to be kept as is |
| 2336 | ** (by default they have to be set to 0 by the sender). |
| 2337 | ** |
| 2338 | ** Returns void |
| 2339 | ** |
| 2340 | *******************************************************************************/ |
| 2341 | void btm_ble_set_keep_rfu_in_auth_req(BOOLEAN keep_rfu) |
| 2342 | { |
Sharvil Nanavati | 83c5256 | 2014-05-04 00:46:57 -0700 | [diff] [blame] | 2343 | BTM_TRACE_DEBUG ("btm_ble_set_keep_rfu_in_auth_req keep_rfus=%d", keep_rfu); |
Satya Calloji | ffb3960 | 2014-04-30 15:55:39 -0700 | [diff] [blame] | 2344 | btm_cb.devcb.keep_rfu_in_auth_req = keep_rfu; |
| 2345 | } |
| 2346 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2347 | #endif /* BTM_BLE_CONFORMANCE_TESTING */ |
| 2348 | |
The Android Open Source Project | 5738f83 | 2012-12-12 16:00:35 -0800 | [diff] [blame] | 2349 | #endif /* BLE_INCLUDED */ |