• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "osi/include/log.h"
18 #include "stack/btm/btm_ble_int.h"
19 #include "stack/btm/security_device_record.h"
20 #include "stack/include/acl_api.h"
21 #include "stack/include/hcimsgs.h"
22 #include "types/raw_address.h"
23 
24 /*******************************************************************************
25  *
26  * Function         BTM_SecAddDevice
27  *
28  * Description      Add/modify device.  This function will be normally called
29  *                  during host startup to restore all required information
30  *                  stored in the NVRAM.
31  *
32  * Parameters:      bd_addr          - BD address of the peer
33  *                  dev_class        - Device Class
34  *                  bd_name          - Name of the peer device. NULL if unknown.
35  *                  features         - Remote device's features (up to 3 pages).
36  *                                     NULL if not known
37  *                  link_key         - Connection link key. NULL if unknown.
38  *
39  * Returns          true if added OK, else false
40  *
41  ******************************************************************************/
42 bool BTM_SecAddDevice(const RawAddress& bd_addr, DEV_CLASS dev_class,
43                       BD_NAME bd_name, uint8_t* features, LinkKey* p_link_key,
44                       uint8_t key_type, uint8_t pin_length);
45 void wipe_secrets_and_remove(tBTM_SEC_DEV_REC* p_dev_rec);
46 
47 /** Free resources associated with the device associated with |bd_addr| address.
48  *
49  * *** WARNING ***
50  * tBTM_SEC_DEV_REC associated with bd_addr becomes invalid after this function
51  * is called, also any of it's fields. i.e. if you use p_dev_rec->bd_addr, it is
52  * no longer valid!
53  * *** WARNING ***
54  *
55  * Returns true if removed OK, false if not found or ACL link is active.
56  */
57 bool BTM_SecDeleteDevice(const RawAddress& bd_addr);
58 
59 /*******************************************************************************
60  *
61  * Function         BTM_SecClearSecurityFlags
62  *
63  * Description      Reset the security flags (mark as not-paired) for a given
64  *                  remove device.
65  *
66  ******************************************************************************/
67 void BTM_SecClearSecurityFlags(const RawAddress& bd_addr);
68 
69 /*******************************************************************************
70  *
71  * Function         BTM_SecReadDevName
72  *
73  * Description      Looks for the device name in the security database for the
74  *                  specified BD address.
75  *
76  * Returns          Pointer to the name or NULL
77  *
78  ******************************************************************************/
79 char* BTM_SecReadDevName(const RawAddress& bd_addr);
80 
81 /*******************************************************************************
82  *
83  * Function         btm_sec_alloc_dev
84  *
85  * Description      Look for the record in the device database for the record
86  *                  with specified address
87  *
88  * Returns          Pointer to the record or NULL
89  *
90  ******************************************************************************/
91 tBTM_SEC_DEV_REC* btm_sec_alloc_dev(const RawAddress& bd_addr);
92 
93 /*******************************************************************************
94  *
95  * Function         btm_dev_support_role_switch
96  *
97  * Description      This function is called by the L2CAP to check if remote
98  *                  device supports role switch
99  *
100  * Parameters:      bd_addr       - Address of the peer device
101  *
102  * Returns          true if device is known and role switch is supported
103  *
104  ******************************************************************************/
105 bool btm_dev_support_role_switch(const RawAddress& bd_addr);
106 
107 /*******************************************************************************
108  *
109  * Function         btm_find_dev_by_handle
110  *
111  * Description      Look for the record in the device database for the record
112  *                  with specified handle
113  *
114  * Returns          Pointer to the record or NULL
115  *
116  ******************************************************************************/
117 tBTM_SEC_DEV_REC* btm_find_dev_by_handle(uint16_t handle);
118 
119 bool is_address_equal(void* data, void* context);
120 
121 /*******************************************************************************
122  *
123  * Function         btm_find_dev
124  *
125  * Description      Look for the record in the device database for the record
126  *                  with specified BD address
127  *
128  * Returns          Pointer to the record or NULL
129  *
130  ******************************************************************************/
131 tBTM_SEC_DEV_REC* btm_find_dev(const RawAddress& bd_addr);
132 
133 /*******************************************************************************
134  *
135  * Function         btm_consolidate_dev
136 5**
137  * Description      combine security records if identified as same peer
138  *
139  * Returns          none
140  *
141  ******************************************************************************/
142 void btm_consolidate_dev(tBTM_SEC_DEV_REC* p_target_rec);
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_SEC_DEV_REC::tBTM_BOND_TYPE btm_get_bond_type_dev(
181     const RawAddress& bd_addr);
182 
183 /*******************************************************************************
184  *
185  * Function         btm_set_bond_type_dev
186  *
187  * Description      Set the bond type for a device in the device database
188  *                  with specified BD address
189  *
190  * Returns          true on success, otherwise false
191  *
192  ******************************************************************************/
193 bool btm_set_bond_type_dev(const RawAddress& bd_addr,
194                            tBTM_SEC_DEV_REC::tBTM_BOND_TYPE bond_type);
195