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 #pragma once 18 19 #include <vector> 20 21 #include "stack/btm/security_device_record.h" 22 #include "types/ble_address_with_type.h" 23 #include "types/raw_address.h" 24 25 /** Free resources associated with the device associated with |bd_addr| address. 26 * 27 * *** WARNING *** 28 * tBTM_SEC_DEV_REC associated with bd_addr becomes invalid after this function 29 * is called, also any of it's fields. i.e. if you use p_dev_rec->bd_addr, it is 30 * no longer valid! 31 * *** WARNING *** 32 * 33 * Returns true if removed OK, false if not found or ACL link is active. 34 */ 35 bool BTM_SecDeleteDevice(const RawAddress& bd_addr); 36 37 /******************************************************************************* 38 * 39 * Function BTM_SecClearSecurityFlags 40 * 41 * Description Reset the security flags (mark as not-paired) for a given 42 * remove device. 43 * 44 ******************************************************************************/ 45 void BTM_SecClearSecurityFlags(const RawAddress& bd_addr); 46 47 /******************************************************************************* 48 * 49 * Function BTM_SecReadDevName 50 * 51 * Description Looks for the device name in the security database for the 52 * specified BD address. 53 * 54 * Returns Pointer to the name or NULL 55 * 56 ******************************************************************************/ 57 const char* BTM_SecReadDevName(const RawAddress& bd_addr); 58 59 /******************************************************************************* 60 * 61 * Function BTM_SecReadDevName 62 * 63 * Description Looks for the device name in the security database for the 64 * specified BD address. 65 * 66 * Returns Pointer to the name or NULL 67 * 68 ******************************************************************************/ 69 DEV_CLASS BTM_SecReadDevClass(const RawAddress& bd_addr); 70 71 /******************************************************************************* 72 * 73 * Function btm_sec_alloc_dev 74 * 75 * Description Allocate a record in the device database 76 * with specified address 77 * 78 * Returns Pointer to the record or NULL 79 * 80 ******************************************************************************/ 81 tBTM_SEC_DEV_REC* btm_sec_alloc_dev(const RawAddress& bd_addr); 82 83 /******************************************************************************* 84 * 85 * Function btm_find_dev_by_handle 86 * 87 * Description Look for the record in the device database for the record 88 * with specified handle 89 * 90 * Returns Pointer to the record or NULL 91 * 92 ******************************************************************************/ 93 tBTM_SEC_DEV_REC* btm_find_dev_by_handle(uint16_t handle); 94 95 /******************************************************************************* 96 * 97 * Function btm_find_dev 98 * 99 * Description Look for the record in the device database for the record 100 * with specified BD address 101 * 102 * Returns Pointer to the record or NULL 103 * 104 ******************************************************************************/ 105 tBTM_SEC_DEV_REC* btm_find_dev(const RawAddress& bd_addr); 106 107 /******************************************************************************* 108 * 109 * Function btm_find_dev_with_lenc 110 * 111 * Description Look for the record in the device database with LTK and 112 * specified BD address 113 * 114 * Returns Pointer to the record or NULL 115 * 116 ******************************************************************************/ 117 tBTM_SEC_DEV_REC* btm_find_dev_with_lenc(const RawAddress& bd_addr); 118 119 /******************************************************************************* 120 * 121 * Function btm_consolidate_dev 122 * 123 * Description combine security records if identified as same peer 124 * 125 * Returns none 126 * 127 ******************************************************************************/ 128 void btm_consolidate_dev(tBTM_SEC_DEV_REC* p_target_rec); 129 130 /******************************************************************************* 131 * 132 * Function btm_consolidate_dev 133 * 134 * Description When pairing is finished (i.e. on BR/EDR), this function 135 * checks if there are existing LE connections to same device 136 * that can now be encrypted and used for profiles requiring 137 * encryption. 138 * 139 * Returns none 140 * 141 ******************************************************************************/ 142 void btm_dev_consolidate_existing_connections(const RawAddress& bd_addr); 143 144 /******************************************************************************* 145 * 146 * Function btm_find_or_alloc_dev 147 * 148 * Description Look for the record in the device database for the record 149 * with specified BD address 150 * 151 * Returns Pointer to the record or NULL 152 * 153 ******************************************************************************/ 154 tBTM_SEC_DEV_REC* btm_find_or_alloc_dev(const RawAddress& bd_addr); 155 156 /******************************************************************************* 157 * 158 * Function btm_sec_allocate_dev_rec 159 * 160 * Description Attempts to allocate a new device record. If we have 161 * exceeded the maximum number of allowable records to 162 * allocate, the oldest record will be deleted to make room 163 * for the new record. 164 * 165 * Returns Pointer to the newly allocated record 166 * 167 ******************************************************************************/ 168 tBTM_SEC_DEV_REC* btm_sec_allocate_dev_rec(void); 169 170 /******************************************************************************* 171 * 172 * Function btm_get_bond_type_dev 173 * 174 * Description Get the bond type for a device in the device database 175 * with specified BD address 176 * 177 * Returns The device bond type if known, otherwise BOND_TYPE_UNKNOWN 178 * 179 ******************************************************************************/ 180 tBTM_BOND_TYPE btm_get_bond_type_dev(const RawAddress& bd_addr); 181 182 /******************************************************************************* 183 * 184 * Function btm_set_bond_type_dev 185 * 186 * Description Set the bond type for a device in the device database 187 * with specified BD address 188 * 189 * Returns true on success, otherwise false 190 * 191 ******************************************************************************/ 192 bool btm_set_bond_type_dev(const RawAddress& bd_addr, tBTM_BOND_TYPE bond_type); 193 194 /******************************************************************************* 195 * 196 * Function btm_get_sec_dev_rec 197 * 198 * Description Get security device records satisfying given filter 199 * 200 * Returns A vector containing pointers of security device records 201 * 202 ******************************************************************************/ 203 std::vector<tBTM_SEC_DEV_REC*> btm_get_sec_dev_rec(); 204 205 bool BTM_Sec_AddressKnown(const RawAddress& address); 206 const tBLE_BD_ADDR BTM_Sec_GetAddressWithType(const RawAddress& bd_addr); 207 208 /******************************************************************************* 209 * 210 * Function DumpsysRecord 211 * 212 * Description Provides dumpsys access to device records. 213 * 214 * Returns void 215 * 216 ******************************************************************************/ 217 void DumpsysRecord(int fd); 218