1 /******************************************************************************
2  *
3  *  Copyright 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 the main Bluetooth Manager (BTM) internal
22  *  definitions.
23  *
24  ******************************************************************************/
25 
26 #ifndef BTM_BLE_INT_H
27 #define BTM_BLE_INT_H
28 
29 #include "bt_common.h"
30 #include "bt_target.h"
31 #include "btm_ble_api.h"
32 #include "btm_ble_int_types.h"
33 #include "btm_int.h"
34 #include "btm_int_types.h"
35 #include "hcidefs.h"
36 #include "smp_api.h"
37 
38 extern bool ble_evt_type_is_connectable(uint16_t evt_type);
39 extern void btm_ble_refresh_raddr_timer_timeout(void* data);
40 extern void btm_ble_process_adv_pkt(uint8_t len, uint8_t* p);
41 extern void btm_ble_process_phy_update_pkt(uint8_t len, uint8_t* p);
42 extern void btm_ble_process_ext_adv_pkt(uint8_t len, uint8_t* p);
43 extern tBTM_STATUS btm_ble_read_remote_name(const RawAddress& remote_bda,
44                                             tBTM_CMPL_CB* p_cb);
45 extern bool btm_ble_cancel_remote_name(const RawAddress& remote_bda);
46 
47 extern tBTM_STATUS btm_ble_set_discoverability(uint16_t combined_mode);
48 extern tBTM_STATUS btm_ble_set_connectability(uint16_t combined_mode);
49 extern void btm_send_hci_scan_enable(uint8_t enable, uint8_t filter_duplicates);
50 extern void btm_send_hci_set_scan_params(uint8_t scan_type, uint16_t scan_int,
51                                          uint16_t scan_win,
52                                          uint8_t addr_type_own,
53                                          uint8_t scan_filter_policy);
54 extern tBTM_STATUS btm_ble_start_inquiry(uint8_t mode, uint8_t duration);
55 extern void btm_ble_stop_scan(void);
56 extern void btm_clear_all_pending_le_entry(void);
57 
58 extern void btm_ble_stop_scan();
59 extern void btm_ble_stop_inquiry(void);
60 extern void btm_ble_init(void);
61 extern void btm_ble_connected(const RawAddress& bda, uint16_t handle,
62                               uint8_t enc_mode, uint8_t role,
63                               tBLE_ADDR_TYPE addr_type, bool addr_matched);
64 extern void btm_ble_read_remote_features_complete(uint8_t* p);
65 extern void btm_ble_write_adv_enable_complete(uint8_t* p);
66 extern void btm_ble_conn_complete(uint8_t* p, uint16_t evt_len, bool enhanced);
67 extern tBTM_BLE_CONN_ST btm_ble_get_conn_st(void);
68 extern tBTM_STATUS btm_ble_start_adv(void);
69 extern tBTM_STATUS btm_ble_stop_adv(void);
70 extern void btm_le_on_advertising_set_terminated(uint8_t* p, uint16_t length);
71 extern tBTM_STATUS btm_ble_start_scan(void);
72 extern void btm_ble_create_ll_conn_complete(uint8_t status);
73 
74 /* LE security function from btm_sec.cc */
75 extern void btm_ble_link_sec_check(const RawAddress& bd_addr,
76                                    tBTM_LE_AUTH_REQ auth_req,
77                                    tBTM_BLE_SEC_REQ_ACT* p_sec_req_act);
78 extern void btm_ble_ltk_request_reply(const RawAddress& bda, bool use_stk,
79                                       const Octet16& stk);
80 extern uint8_t btm_proc_smp_cback(tSMP_EVT event, const RawAddress& bd_addr,
81                                   tSMP_EVT_DATA* p_data);
82 extern tBTM_STATUS btm_ble_set_encryption(const RawAddress& bd_addr,
83                                           tBTM_BLE_SEC_ACT sec_act,
84                                           uint8_t link_role);
85 extern void btm_ble_ltk_request(uint16_t handle, uint8_t rand[8],
86                                 uint16_t ediv);
87 extern tBTM_STATUS btm_ble_start_encrypt(const RawAddress& bda, bool use_stk,
88                                          Octet16* p_stk);
89 extern void btm_ble_link_encrypted(const RawAddress& bd_addr,
90                                    uint8_t encr_enable);
91 
92 /* LE device management functions */
93 extern void btm_ble_reset_id(void);
94 
95 /* security related functions */
96 extern void btm_ble_increment_sign_ctr(const RawAddress& bd_addr,
97                                        bool is_local);
98 extern bool btm_get_local_div(const RawAddress& bd_addr, uint16_t* p_div);
99 extern bool btm_ble_get_enc_key_type(const RawAddress& bd_addr,
100                                      uint8_t* p_key_types);
101 
102 extern void btm_ble_test_command_complete(uint8_t* p);
103 extern void btm_ble_rand_enc_complete(uint8_t* p, uint16_t op_code,
104                                       tBTM_RAND_ENC_CB* p_enc_cplt_cback);
105 
106 extern void btm_sec_save_le_key(const RawAddress& bd_addr,
107                                 tBTM_LE_KEY_TYPE key_type,
108                                 tBTM_LE_KEY_VALUE* p_keys,
109                                 bool pass_to_application);
110 extern void btm_ble_update_sec_key_size(const RawAddress& bd_addr,
111                                         uint8_t enc_key_size);
112 extern uint8_t btm_ble_read_sec_key_size(const RawAddress& bd_addr);
113 
114 /* white list function */
115 extern void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy);
116 extern void btm_ble_white_list_init(uint8_t white_list_size);
117 
118 /* background connection function */
119 extern bool btm_ble_suspend_bg_conn(void);
120 extern bool btm_ble_resume_bg_conn(void);
121 extern bool btm_ble_start_auto_conn();
122 extern bool btm_ble_stop_auto_conn();
123 extern void btm_ble_update_mode_operation(uint8_t link_role,
124                                           const RawAddress* bda,
125                                           uint8_t status);
126 extern bool btm_execute_wl_dev_operation(void);
127 extern void btm_ble_update_link_topology_mask(uint8_t role, bool increase);
128 extern void btm_ble_bgconn_cancel_if_disconnected(const RawAddress& bd_addr);
129 
130 /* BLE address management */
131 extern void btm_gen_resolvable_private_addr(
132     base::Callback<void(const RawAddress& rpa)> cb);
133 
134 extern tBTM_SEC_DEV_REC* btm_ble_resolve_random_addr(
135     const RawAddress& random_bda);
136 extern void btm_gen_resolve_paddr_low(const RawAddress& address);
137 extern uint64_t btm_get_next_private_addrress_interval_ms();
138 
139 /*  privacy function */
140 #if (BLE_PRIVACY_SPT == TRUE)
141 /* BLE address mapping with CS feature */
142 extern bool btm_identity_addr_to_random_pseudo(RawAddress* bd_addr,
143                                                uint8_t* p_addr_type,
144                                                bool refresh);
145 extern bool btm_random_pseudo_to_identity_addr(RawAddress* random_pseudo,
146                                                uint8_t* p_identity_addr_type);
147 extern void btm_ble_refresh_peer_resolvable_private_addr(
148     const RawAddress& pseudo_bda, const RawAddress& rra, uint8_t rra_type);
149 extern void btm_ble_refresh_local_resolvable_private_addr(
150     const RawAddress& pseudo_addr, const RawAddress& local_rpa);
151 extern void btm_ble_read_resolving_list_entry_complete(uint8_t* p,
152                                                        uint16_t evt_len);
153 extern void btm_ble_remove_resolving_list_entry_complete(uint8_t* p,
154                                                          uint16_t evt_len);
155 extern void btm_ble_add_resolving_list_entry_complete(uint8_t* p,
156                                                       uint16_t evt_len);
157 extern void btm_ble_clear_resolving_list_complete(uint8_t* p, uint16_t evt_len);
158 extern void btm_ble_enable_resolving_list(uint8_t);
159 extern bool btm_ble_disable_resolving_list(uint8_t rl_mask, bool to_resume);
160 extern void btm_ble_enable_resolving_list_for_platform(uint8_t rl_mask);
161 extern void btm_ble_resolving_list_init(uint8_t max_irk_list_sz);
162 extern void btm_ble_resolving_list_cleanup(void);
163 #endif
164 
165 extern void btm_ble_adv_init(void);
166 extern void btm_ble_multi_adv_cleanup(void);
167 extern void btm_ble_batchscan_init(void);
168 extern void btm_ble_batchscan_cleanup(void);
169 extern void btm_ble_adv_filter_init(void);
170 extern void btm_ble_adv_filter_cleanup(void);
171 extern bool btm_ble_topology_check(tBTM_BLE_STATE_MASK request);
172 extern bool btm_ble_clear_topology_mask(tBTM_BLE_STATE_MASK request_state);
173 extern bool btm_ble_set_topology_mask(tBTM_BLE_STATE_MASK request_state);
174 extern void btm_ble_set_random_address(const RawAddress& random_bda);
175 
176 #if (BTM_BLE_CONFORMANCE_TESTING == TRUE)
177 extern void btm_ble_set_no_disc_if_pair_fail(bool disble_disc);
178 extern void btm_ble_set_test_mac_value(bool enable, uint8_t* p_test_mac_val);
179 extern void btm_ble_set_test_local_sign_cntr_value(
180     bool enable, uint32_t test_local_sign_cntr);
181 extern void btm_ble_set_keep_rfu_in_auth_req(bool keep_rfu);
182 #endif
183 
184 #endif
185