1 /* 2 * Copyright 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <functional> 18 19 #include "osi/include/log.h" 20 #include "stack/btm/btm_ble_int.h" 21 #include "stack/btm/security_device_record.h" 22 #include "stack/include/acl_api.h" 23 #include "stack/include/bt_octets.h" 24 #include "types/raw_address.h" 25 26 void wipe_secrets_and_remove(tBTM_SEC_DEV_REC* p_dev_rec); 27 28 /** Free resources associated with the device associated with |bd_addr| address. 29 * 30 * *** WARNING *** 31 * tBTM_SEC_DEV_REC associated with bd_addr becomes invalid after this function 32 * is called, also any of it's fields. i.e. if you use p_dev_rec->bd_addr, it is 33 * no longer valid! 34 * *** WARNING *** 35 * 36 * Returns true if removed OK, false if not found or ACL link is active. 37 */ 38 bool BTM_SecDeleteDevice(const RawAddress& bd_addr); 39 40 /******************************************************************************* 41 * 42 * Function BTM_SecClearSecurityFlags 43 * 44 * Description Reset the security flags (mark as not-paired) for a given 45 * remove device. 46 * 47 ******************************************************************************/ 48 void BTM_SecClearSecurityFlags(const RawAddress& bd_addr); 49 50 /******************************************************************************* 51 * 52 * Function BTM_SecReadDevName 53 * 54 * Description Looks for the device name in the security database for the 55 * specified BD address. 56 * 57 * Returns Pointer to the name or NULL 58 * 59 ******************************************************************************/ 60 char* BTM_SecReadDevName(const RawAddress& bd_addr); 61 62 /******************************************************************************* 63 * 64 * Function btm_sec_alloc_dev 65 * 66 * Description Look for the record in the device database for the record 67 * with specified address 68 * 69 * Returns Pointer to the record or NULL 70 * 71 ******************************************************************************/ 72 tBTM_SEC_DEV_REC* btm_sec_alloc_dev(const RawAddress& bd_addr); 73 74 /******************************************************************************* 75 * 76 * Function btm_dev_support_role_switch 77 * 78 * Description This function is called by the L2CAP to check if remote 79 * device supports role switch 80 * 81 * Parameters: bd_addr - Address of the peer device 82 * 83 * Returns true if device is known and role switch is supported 84 * 85 ******************************************************************************/ 86 bool btm_dev_support_role_switch(const RawAddress& bd_addr); 87 88 /******************************************************************************* 89 * 90 * Function btm_find_dev_by_handle 91 * 92 * Description Look for the record in the device database for the record 93 * with specified handle 94 * 95 * Returns Pointer to the record or NULL 96 * 97 ******************************************************************************/ 98 tBTM_SEC_DEV_REC* btm_find_dev_by_handle(uint16_t handle); 99 100 bool is_address_equal(void* data, void* context); 101 102 /******************************************************************************* 103 * 104 * Function btm_find_dev 105 * 106 * Description Look for the record in the device database for the record 107 * with specified BD address 108 * 109 * Returns Pointer to the record or NULL 110 * 111 ******************************************************************************/ 112 tBTM_SEC_DEV_REC* btm_find_dev(const RawAddress& bd_addr); 113 114 /******************************************************************************* 115 * 116 * Function btm_find_dev_with_lenc 117 * 118 * Description Look for the record in the device database with LTK and 119 * specified BD address 120 * 121 * Returns Pointer to the record or NULL 122 * 123 ******************************************************************************/ 124 tBTM_SEC_DEV_REC* btm_find_dev_with_lenc(const RawAddress& bd_addr); 125 126 /******************************************************************************* 127 * 128 * Function btm_consolidate_dev 129 * 130 * Description combine security records if identified as same peer 131 * 132 * Returns none 133 * 134 ******************************************************************************/ 135 void btm_consolidate_dev(tBTM_SEC_DEV_REC* p_target_rec); 136 137 /******************************************************************************* 138 * 139 * Function btm_consolidate_dev 140 * 141 * Description When pairing is finished (i.e. on BR/EDR), this function 142 * checks if there are existing LE connections to same device 143 * that can now be encrypted and used for profiles requiring 144 * encryption. 145 * 146 * Returns none 147 * 148 ******************************************************************************/ 149 void btm_dev_consolidate_existing_connections(const RawAddress& bd_addr); 150 151 /******************************************************************************* 152 * 153 * Function btm_find_or_alloc_dev 154 * 155 * Description Look for the record in the device database for the record 156 * with specified BD address 157 * 158 * Returns Pointer to the record or NULL 159 * 160 ******************************************************************************/ 161 tBTM_SEC_DEV_REC* btm_find_or_alloc_dev(const RawAddress& bd_addr); 162 163 /******************************************************************************* 164 * 165 * Function btm_sec_allocate_dev_rec 166 * 167 * Description Attempts to allocate a new device record. If we have 168 * exceeded the maximum number of allowable records to 169 * allocate, the oldest record will be deleted to make room 170 * for the new record. 171 * 172 * Returns Pointer to the newly allocated record 173 * 174 ******************************************************************************/ 175 tBTM_SEC_DEV_REC* btm_sec_allocate_dev_rec(void); 176 177 /******************************************************************************* 178 * 179 * Function btm_get_bond_type_dev 180 * 181 * Description Get the bond type for a device in the device database 182 * with specified BD address 183 * 184 * Returns The device bond type if known, otherwise BOND_TYPE_UNKNOWN 185 * 186 ******************************************************************************/ 187 tBTM_SEC_DEV_REC::tBTM_BOND_TYPE btm_get_bond_type_dev( 188 const RawAddress& bd_addr); 189 190 /******************************************************************************* 191 * 192 * Function btm_set_bond_type_dev 193 * 194 * Description Set the bond type for a device in the device database 195 * with specified BD address 196 * 197 * Returns true on success, otherwise false 198 * 199 ******************************************************************************/ 200 bool btm_set_bond_type_dev(const RawAddress& bd_addr, 201 tBTM_SEC_DEV_REC::tBTM_BOND_TYPE bond_type); 202 203 /******************************************************************************* 204 * 205 * Function btm_get_sec_dev_rec 206 * 207 * Description Get security device records satisfying given filter 208 * 209 * Returns A vector containing pointers of security device records 210 * 211 ******************************************************************************/ 212 std::vector<tBTM_SEC_DEV_REC*> btm_get_sec_dev_rec(); 213