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 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 "common/bt_target.h"
30 #include "osi/fixed_queue.h"
31 #include "osi/pkt_queue.h"
32 #include "osi/thread.h"
33 #include "stack/hcidefs.h"
34 #include "stack/btm_ble_api.h"
35 #include "btm_int.h"
36 
37 #if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE
38 #include "stack/smp_api.h"
39 #endif
40 
41 
42 /* scanning enable status */
43 #define BTM_BLE_SCAN_ENABLE      0x01
44 #define BTM_BLE_SCAN_DISABLE     0x00
45 
46 /* advertising enable status */
47 #define BTM_BLE_ADV_ENABLE     0x01
48 #define BTM_BLE_ADV_DISABLE    0x00
49 
50 /* use the high 4 bits unused by inquiry mode */
51 #define BTM_BLE_SELECT_SCAN     0x20
52 #define BTM_BLE_NAME_REQUEST    0x40
53 #define BTM_BLE_OBSERVE         0x80
54 
55 #define BTM_BLE_MAX_WL_ENTRY        1
56 #define BTM_BLE_AD_DATA_LEN         31
57 
58 #define BTM_BLE_ENC_MASK    0x03
59 
60 #define BTM_BLE_DUPLICATE_DISABLE       0
61 #define BTM_BLE_DUPLICATE_ENABLE        1
62 #define BTM_BLE_DUPLICATE_MAX           BTM_BLE_DUPLICATE_ENABLE
63 
64 #define BTM_BLE_GAP_DISC_SCAN_INT      18         /* Interval(scan_int) = 11.25 ms= 0x0010 * 0.625 ms */
65 #define BTM_BLE_GAP_DISC_SCAN_WIN      18         /* scan_window = 11.25 ms= 0x0010 * 0.625 ms */
66 #define BTM_BLE_GAP_ADV_INT            512        /* Tgap(gen_disc) = 1.28 s= 512 * 0.625 ms */
67 #define BTM_BLE_GAP_LIM_TOUT           180        /* Tgap(lim_timeout) = 180s max */
68 #define BTM_BLE_LOW_LATENCY_SCAN_INT   8000       /* Interval(scan_int) = 5s= 8000 * 0.625 ms */
69 #define BTM_BLE_LOW_LATENCY_SCAN_WIN   8000       /* scan_window = 5s= 8000 * 0.625 ms */
70 
71 
72 #define BTM_BLE_GAP_ADV_FAST_INT_1         48         /* TGAP(adv_fast_interval1) = 30(used) ~ 60 ms  = 48 *0.625 */
73 #define BTM_BLE_GAP_ADV_FAST_INT_2         160         /* TGAP(adv_fast_interval2) = 100(used) ~ 150 ms = 160 * 0.625 ms */
74 #define BTM_BLE_GAP_ADV_SLOW_INT           2048         /* Tgap(adv_slow_interval) = 1.28 s= 512 * 0.625 ms */
75 #define BTM_BLE_GAP_ADV_DIR_MAX_INT        800         /* Tgap(dir_conn_adv_int_max) = 500 ms = 800 * 0.625 ms */
76 #define BTM_BLE_GAP_ADV_DIR_MIN_INT        400         /* Tgap(dir_conn_adv_int_min) = 250 ms = 400 * 0.625 ms */
77 
78 #define BTM_BLE_GAP_FAST_ADV_TOUT          30
79 
80 #define BTM_BLE_SEC_REQ_ACT_NONE           0
81 #define BTM_BLE_SEC_REQ_ACT_ENCRYPT        1 /* encrypt the link using current key or key refresh */
82 #define BTM_BLE_SEC_REQ_ACT_PAIR           2
83 #define BTM_BLE_SEC_REQ_ACT_DISCARD        3 /* discard the sec request while encryption is started but not completed */
84 typedef UINT8   tBTM_BLE_SEC_REQ_ACT;
85 
86 #define BLE_STATIC_PRIVATE_MSB_MASK          0x3f
87 #define BLE_RESOLVE_ADDR_MSB                 0x40   /*  most significant bit, bit7, bit6 is 01 to be resolvable random */
88 #define BLE_RESOLVE_ADDR_MASK                0xc0   /* bit 6, and bit7 */
89 #define BTM_BLE_IS_RESOLVE_BDA(x)           ((x[0] & BLE_RESOLVE_ADDR_MASK) == BLE_RESOLVE_ADDR_MSB)
90 
91 /* LE scan activity bit mask, continue with LE inquiry bits */
92 #define BTM_LE_SELECT_CONN_ACTIVE      0x0040     /* selection connection is in progress */
93 #define BTM_LE_OBSERVE_ACTIVE          0x0080     /* observe is in progress */
94 #define BTM_LE_DISCOVER_ACTIVE         0x0100     /* scan is in progress */
95 
96 /* BLE scan activity mask checking */
97 #define BTM_BLE_IS_SCAN_ACTIVE(x)   ((x) & BTM_BLE_SCAN_ACTIVE_MASK)
98 #define BTM_BLE_IS_INQ_ACTIVE(x)   ((x) & BTM_BLE_INQUIRY_MASK)
99 #define BTM_BLE_IS_OBS_ACTIVE(x)   ((x) & BTM_LE_OBSERVE_ACTIVE)
100 #define BTM_BLE_IS_DISCO_ACTIVE(x)   ((x) & BTM_LE_DISCOVER_ACTIVE)
101 #define BTM_BLE_IS_SEL_CONN_ACTIVE(x)   ((x) & BTM_LE_SELECT_CONN_ACTIVE)
102 
103 /* BLE ADDR type ID bit */
104 #define BLE_ADDR_TYPE_ID_BIT 0x02
105 
106 #define BTM_VSC_CHIP_CAPABILITY_L_VERSION 55
107 #define BTM_VSC_CHIP_CAPABILITY_M_VERSION 95
108 
109 typedef enum {
110     BTM_BLE_IDLE = 0,
111     BTM_BLE_SCANNING = 1,
112     BTM_BLE_ADVERTISING = 2,
113 }tBTM_BLE_GAP_STATE;
114 
115 typedef struct {
116     UINT16              data_mask;
117     UINT8               *p_flags;
118     UINT8               ad_data[BTM_BLE_AD_DATA_LEN];
119     UINT8               *p_pad;
120 } tBTM_BLE_LOCAL_ADV_DATA;
121 
122 typedef struct {
123     UINT32          inq_count;          /* Used for determining if a response has already been      */
124     /* received for the current inquiry operation. (We do not   */
125     /* want to flood the caller with multiple responses from    */
126     /* the same device.                                         */
127     BOOLEAN         scan_rsp;
128     tBLE_BD_ADDR    le_bda;
129 } tINQ_LE_BDADDR;
130 
131 #define BTM_BLE_ADV_DATA_LEN_MAX        31
132 #define BTM_BLE_CACHE_ADV_DATA_MAX      62
133 #if (BLE_50_FEATURE_SUPPORT == TRUE)
134 #define BTM_BLE_EXT_ADV_DATA_LEN_MAX    251
135 #define BTM_BLE_PERIODIC_ADV_DATA_LEN_MAX 252
136 
137 #define BTM_BLE_ADV_DATA_OP_INTERMEDIATE_FRAG    0
138 #define BTM_BLE_ADV_DATA_OP_FIRST_FRAG           1
139 #define BTM_BLE_ADV_DATA_OP_LAST_FRAG            2
140 #define BTM_BLE_ADV_DATA_OP_COMPLETE             3
141 #define BTM_BLE_ADV_DATA_OP_UNCHANGED_DATA       4
142 #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
143 
144 #define BTM_BLE_ISVALID_PARAM(x, min, max)  (((x) >= (min) && (x) <= (max)) || ((x) == BTM_BLE_CONN_PARAM_UNDEF))
145 
146 typedef struct {
147     UINT16 discoverable_mode;
148     UINT16 connectable_mode;
149     BOOLEAN scan_params_set;
150     UINT32 scan_window;
151     UINT32 scan_interval;
152     UINT8 scan_type; /* current scan type: active or passive */
153     UINT8 scan_duplicate_filter; /* duplicate filter enabled for scan */
154     UINT16 adv_interval_min;
155     UINT16 adv_interval_max;
156     tBTM_BLE_AFP afp; /* advertising filter policy */
157     tBTM_BLE_SFP sfp; /* scanning filter policy */
158     tBTM_START_ADV_CMPL_CBACK *p_adv_cb;
159     tBTM_START_STOP_ADV_CMPL_CBACK *p_stop_adv_cb;
160     tBLE_ADDR_TYPE adv_addr_type;
161     UINT8 evt_type;
162     UINT8 adv_mode;
163     tBLE_BD_ADDR direct_bda;
164     tBTM_BLE_EVT directed_conn;
165     BOOLEAN fast_adv_on;
166     TIMER_LIST_ENT fast_adv_timer;
167 
168     UINT8 adv_len;
169     UINT8 adv_data_cache[BTM_BLE_CACHE_ADV_DATA_MAX];
170     BD_ADDR adv_addr;
171     /* inquiry BD addr database */
172     UINT8 num_bd_entries;
173     UINT8 max_bd_entries;
174     tBTM_BLE_LOCAL_ADV_DATA adv_data;
175     tBTM_BLE_ADV_CHNL_MAP adv_chnl_map;
176 
177     TIMER_LIST_ENT inq_timer_ent;
178     BOOLEAN scan_rsp;
179     tBTM_BLE_GAP_STATE state; /* Current state that the adv or scan process is in */
180     INT8 tx_power;
181 } tBTM_BLE_INQ_CB;
182 
183 
184 /* random address resolving complete callback */
185 typedef void (tBTM_BLE_RESOLVE_CBACK) (void *match_rec, void *p);
186 
187 typedef void (tBTM_BLE_ADDR_CBACK) (BD_ADDR_PTR static_random, void *p);
188 
189 #define BTM_BLE_GAP_ADDR_BIT_RANDOM      (1<<0)
190 #define BTM_BLE_GAP_ADDR_BIT_RESOLVABLE  (1<<1)
191 
192 /* random address management control block */
193 typedef struct {
194     tBLE_ADDR_TYPE              own_addr_type;         /* local device LE address type */
195     UINT8                       exist_addr_bit;
196     BD_ADDR                     static_rand_addr;
197     BD_ADDR                     resolvale_addr;
198     BD_ADDR                     private_addr;
199     BD_ADDR                     random_bda;
200     BOOLEAN                     busy;
201     tBTM_SEC_DEV_REC            *p_dev_rec;
202     tBTM_BLE_RESOLVE_CBACK      *p_resolve_cback;
203     tBTM_BLE_ADDR_CBACK         *p_generate_cback;
204     void                        *p;
205     TIMER_LIST_ENT              raddr_timer_ent;
206     tBTM_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback;
207 } tBTM_LE_RANDOM_CB;
208 
209 #define BTM_BLE_MAX_BG_CONN_DEV_NUM    10
210 
211 typedef struct {
212     UINT16              min_conn_int;
213     UINT16              max_conn_int;
214     UINT16              slave_latency;
215     UINT16              supervision_tout;
216 
217 } tBTM_LE_CONN_PRAMS;
218 
219 
220 typedef struct {
221     BD_ADDR     bd_addr;
222     UINT8       attr;
223     BOOLEAN     is_connected;
224     BOOLEAN     in_use;
225 } tBTM_LE_BG_CONN_DEV;
226 
227 /* white list using state as a bit mask */
228 #define BTM_BLE_WL_IDLE         0
229 #define BTM_BLE_WL_INIT         1
230 #define BTM_BLE_WL_SCAN         2
231 #define BTM_BLE_WL_ADV          4
232 typedef UINT8 tBTM_BLE_WL_STATE;
233 
234 /* resolving list using state as a bit mask */
235 #define BTM_BLE_RL_IDLE         0
236 #define BTM_BLE_RL_INIT         1
237 #define BTM_BLE_RL_SCAN         2
238 #define BTM_BLE_RL_ADV          4
239 typedef UINT8 tBTM_BLE_RL_STATE;
240 
241 /* BLE connection state */
242 #define BLE_CONN_IDLE    0
243 #define BLE_DIR_CONN     1
244 #define BLE_BG_CONN      2
245 #define BLE_CONN_CANCEL  3
246 typedef UINT8 tBTM_BLE_CONN_ST;
247 
248 typedef struct {
249     void    *p_param;
250 } tBTM_BLE_CONN_REQ;
251 
252 /* LE state request */
253 #define BTM_BLE_STATE_INVALID               0
254 #define BTM_BLE_STATE_CONN_ADV              1
255 #define BTM_BLE_STATE_INIT                  2
256 #define BTM_BLE_STATE_MASTER                3
257 #define BTM_BLE_STATE_SLAVE                 4
258 #define BTM_BLE_STATE_LO_DUTY_DIR_ADV       5
259 #define BTM_BLE_STATE_HI_DUTY_DIR_ADV       6
260 #define BTM_BLE_STATE_NON_CONN_ADV          7
261 #define BTM_BLE_STATE_PASSIVE_SCAN          8
262 #define BTM_BLE_STATE_ACTIVE_SCAN           9
263 #define BTM_BLE_STATE_SCAN_ADV              10
264 #define BTM_BLE_STATE_MAX                   11
265 typedef UINT8 tBTM_BLE_STATE;
266 
267 #define BTM_BLE_STATE_CONN_ADV_BIT          0x0001
268 #define BTM_BLE_STATE_INIT_BIT              0x0002
269 #define BTM_BLE_STATE_MASTER_BIT            0x0004
270 #define BTM_BLE_STATE_SLAVE_BIT             0x0008
271 #define BTM_BLE_STATE_LO_DUTY_DIR_ADV_BIT   0x0010
272 #define BTM_BLE_STATE_HI_DUTY_DIR_ADV_BIT   0x0020
273 #define BTM_BLE_STATE_NON_CONN_ADV_BIT      0x0040
274 #define BTM_BLE_STATE_PASSIVE_SCAN_BIT      0x0080
275 #define BTM_BLE_STATE_ACTIVE_SCAN_BIT       0x0100
276 #define BTM_BLE_STATE_SCAN_ADV_BIT          0x0200
277 typedef UINT16 tBTM_BLE_STATE_MASK;
278 
279 #define BTM_BLE_STATE_ALL_MASK              0x03ff
280 #define BTM_BLE_STATE_ALL_ADV_MASK          (BTM_BLE_STATE_CONN_ADV_BIT|BTM_BLE_STATE_LO_DUTY_DIR_ADV_BIT|BTM_BLE_STATE_HI_DUTY_DIR_ADV_BIT|BTM_BLE_STATE_SCAN_ADV_BIT)
281 #define BTM_BLE_STATE_ALL_SCAN_MASK         (BTM_BLE_STATE_PASSIVE_SCAN_BIT|BTM_BLE_STATE_ACTIVE_SCAN_BIT)
282 #define BTM_BLE_STATE_ALL_CONN_MASK         (BTM_BLE_STATE_MASTER_BIT|BTM_BLE_STATE_SLAVE_BIT)
283 
284 #ifndef BTM_LE_RESOLVING_LIST_MAX
285 #define BTM_LE_RESOLVING_LIST_MAX     0x20
286 #endif
287 
288 #define BTM_DUPLICATE_SCAN_EXCEPTIONAL_INFO_ADV_ADDR             0
289 #define BTM_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_LINK_ID         1
290 #define BTM_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_BEACON_TYPE     2
291 #define BTM_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_PROV_SRV_ADV    3
292 #define BTM_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_PROXY_SRV_ADV   4
293 
294 typedef struct {
295     BD_ADDR         *resolve_q_random_pseudo;
296     UINT8           *resolve_q_action;
297     UINT8           q_next;
298     UINT8           q_pending;
299 } tBTM_BLE_RESOLVE_Q;
300 
301 typedef struct {
302     BOOLEAN     in_use;
303     BOOLEAN     to_add;
304     BD_ADDR     bd_addr;
305     tBLE_ADDR_TYPE addr_type;
306     UINT8       attr;
307 } tBTM_BLE_WL_OP;
308 
309 /* BLE privacy mode */
310 #define BTM_PRIVACY_NONE    0              /* BLE no privacy */
311 #define BTM_PRIVACY_1_1     1              /* BLE privacy 1.1, do not support privacy 1.0 */
312 #define BTM_PRIVACY_1_2     2              /* BLE privacy 1.2 */
313 #define BTM_PRIVACY_MIXED   3              /* BLE privacy mixed mode, broadcom propietary mode */
314 typedef UINT8 tBTM_PRIVACY_MODE;
315 
316 /* data length change event callback */
317 typedef void (tBTM_DATA_LENGTH_CHANGE_CBACK) (UINT16 max_tx_length, UINT16 max_rx_length);
318 
319 /* Define BLE Device Management control structure
320 */
321 typedef struct {
322     UINT16 scan_activity;         /* LE scan activity mask */
323 
324     /*****************************************************
325     **      BLE Inquiry
326     *****************************************************/
327     tBTM_BLE_INQ_CB inq_var;
328 
329     /* observer callback and timer */
330     tBTM_INQ_RESULTS_CB *p_obs_results_cb;
331     tBTM_CMPL_CB *p_obs_cmpl_cb;
332     tBTM_INQ_DIS_CB *p_obs_discard_cb;
333     TIMER_LIST_ENT obs_timer_ent;
334 
335     /* scan callback and timer */
336     tBTM_INQ_RESULTS_CB *p_scan_results_cb;
337     tBTM_CMPL_CB *p_scan_cmpl_cb;
338     TIMER_LIST_ENT scan_timer_ent;
339 
340     struct pkt_queue *adv_rpt_queue;
341     struct osi_event *adv_rpt_ready;
342 
343     /* background connection procedure cb value */
344     tBTM_BLE_CONN_TYPE bg_conn_type;
345     UINT32 scan_int;
346     UINT32 scan_win;
347     tBTM_BLE_SEL_CBACK *p_select_cback;
348     /* white list information */
349     UINT8 white_list_avail_size;
350     tBTM_UPDATE_WHITELIST_CBACK *update_wl_cb;
351     tBTM_BLE_WL_STATE wl_state;
352 
353     fixed_queue_t *conn_pending_q;
354     tBTM_BLE_CONN_ST conn_state;
355 
356     /* random address management control block */
357     tBTM_LE_RANDOM_CB addr_mgnt_cb;
358 
359     BOOLEAN enabled;
360 
361 #if BLE_PRIVACY_SPT == TRUE
362     BOOLEAN mixed_mode; /* privacy 1.2 mixed mode is on or not */
363     tBTM_PRIVACY_MODE privacy_mode; /* privacy mode */
364     UINT8 resolving_list_avail_size; /* resolving list available size */
365     tBTM_BLE_RESOLVE_Q resolving_list_pend_q; /* Resolving list queue */
366     tBTM_BLE_RL_STATE suspended_rl_state; /* Suspended resolving list state */
367     UINT8 *irk_list_mask; /* IRK list availability mask, up to max entry bits */
368     tBTM_BLE_RL_STATE rl_state; /* Resolving list state */
369 #endif
370 
371     tBTM_BLE_WL_OP wl_op_q[BTM_BLE_MAX_BG_CONN_DEV_NUM];
372 
373     /* current BLE link state */
374     tBTM_BLE_STATE_MASK cur_states; /* bit mask of tBTM_BLE_STATE */
375     UINT8 link_count[2]; /* total link count master and slave*/
376     tBTM_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK *update_exceptional_list_cmp_cb;
377 } tBTM_BLE_CB;
378 
379 #ifdef __cplusplus
380 extern "C" {
381 #endif
382 
383 void btm_ble_timeout(TIMER_LIST_ENT *p_tle);
384 void btm_ble_process_adv_pkt (UINT8 *p);
385 void btm_ble_process_adv_discard_evt(UINT8 *p);
386 void btm_ble_process_direct_adv_pkt (UINT8 *p);
387 bool btm_ble_adv_pkt_ready(void);
388 bool btm_ble_adv_pkt_post(pkt_linked_item_t *pkt);
389 void btm_ble_proc_scan_rsp_rpt (UINT8 *p);
390 tBTM_STATUS btm_ble_read_remote_name(BD_ADDR remote_bda, tBTM_INQ_INFO *p_cur, tBTM_CMPL_CB *p_cb);
391 BOOLEAN btm_ble_cancel_remote_name(BD_ADDR remote_bda);
392 
393 tBTM_STATUS btm_ble_set_discoverability(UINT16 combined_mode);
394 tBTM_STATUS btm_ble_set_connectability(UINT16 combined_mode);
395 tBTM_STATUS btm_ble_start_inquiry (UINT8 mode, UINT8   duration);
396 void btm_ble_stop_scan(void);
397 void btm_clear_all_pending_le_entry(void);
398 
399 BOOLEAN btm_ble_send_extended_scan_params(UINT8 scan_type, UINT32 scan_int, UINT32 scan_win, UINT8 addr_type_own, UINT8 scan_filter_policy);
400 void btm_ble_stop_inquiry(void);
401 void btm_ble_init (void);
402 void btm_ble_free (void);
403 void btm_ble_connected (UINT8 *bda, UINT16 handle, UINT8 enc_mode, UINT8 role, tBLE_ADDR_TYPE addr_type, BOOLEAN addr_matched);
404 void btm_ble_read_remote_features_complete(UINT8 *p);
405 void btm_ble_write_adv_enable_complete(UINT8 *p);
406 void btm_ble_conn_complete(UINT8 *p, UINT16 evt_len, BOOLEAN enhanced);
407 void btm_read_ble_local_supported_states_complete(UINT8 *p, UINT16 evt_len);
408 tBTM_BLE_CONN_ST btm_ble_get_conn_st(void);
409 void btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st);
410 UINT8 *btm_ble_build_adv_data(tBTM_BLE_AD_MASK *p_data_mask, UINT8 **p_dst, tBTM_BLE_ADV_DATA *p_data);
411 tBTM_STATUS btm_ble_start_adv(void);
412 tBTM_STATUS btm_ble_stop_adv(void);
413 tBTM_STATUS btm_ble_start_scan(void);
414 void btm_ble_create_ll_conn_complete (UINT8 status);
415 void btm_ble_create_conn_cancel_complete (UINT8 *p);
416 tBTM_STATUS btm_ble_set_random_addr(BD_ADDR random_bda);
417 
418 /* LE security function from btm_sec.c */
419 #if SMP_INCLUDED == TRUE
420 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);
421 void btm_ble_ltk_request_reply(BD_ADDR bda,  BOOLEAN use_stk, BT_OCTET16 stk);
422 UINT8 btm_proc_smp_cback(tSMP_EVT event, BD_ADDR bd_addr, tSMP_EVT_DATA *p_data);
423 tBTM_STATUS btm_ble_set_encryption (BD_ADDR bd_addr, void *p_ref_data, UINT8 link_role);
424 void btm_ble_ltk_request(UINT16 handle, UINT8 rand[8], UINT16 ediv);
425 tBTM_STATUS btm_ble_start_encrypt(BD_ADDR bda, BOOLEAN use_stk, BT_OCTET16 stk);
426 void btm_ble_link_encrypted(BD_ADDR bd_addr, UINT8 encr_enable);
427 #endif
428 
429 /* LE device management functions */
430 void btm_ble_reset_id( void );
431 
432 /* security related functions */
433 void btm_ble_increment_sign_ctr(BD_ADDR bd_addr, BOOLEAN is_local );
434 BOOLEAN btm_get_local_div (BD_ADDR bd_addr, UINT16 *p_div);
435 BOOLEAN btm_ble_get_enc_key_type(BD_ADDR bd_addr, UINT8 *p_key_types);
436 
437 void btm_ble_test_command_complete(UINT8 *p);
438 void btm_ble_rand_enc_complete (UINT8 *p, UINT16 op_code, tBTM_RAND_ENC_CB *p_enc_cplt_cback);
439 
440 void btm_sec_save_le_key(BD_ADDR bd_addr, tBTM_LE_KEY_TYPE key_type, tBTM_LE_KEY_VALUE *p_keys, BOOLEAN pass_to_application);
441 void btm_ble_update_sec_key_size(BD_ADDR bd_addr, UINT8 enc_key_size);
442 UINT8 btm_ble_read_sec_key_size(BD_ADDR bd_addr);
443 
444 /* white list function */
445 BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBTM_UPDATE_WHITELIST_CBACK *update_wl_cb);
446 void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy);
447 void btm_update_adv_filter_policy(tBTM_BLE_AFP adv_policy);
448 void btm_ble_clear_white_list (tBTM_UPDATE_WHITELIST_CBACK *update_wl_cb);
449 void btm_read_white_list_size_complete(UINT8 *p, UINT16 evt_len);
450 void btm_ble_add_2_white_list_complete(UINT8 status);
451 void btm_ble_remove_from_white_list_complete(UINT8 *p, UINT16 evt_len);
452 void btm_ble_clear_white_list_complete(UINT8 *p, UINT16 evt_len);
453 void btm_ble_white_list_init(UINT8 white_list_size);
454 
455 /* background connection function */
456 BOOLEAN btm_ble_suspend_bg_conn(void);
457 BOOLEAN btm_ble_resume_bg_conn(void);
458 void btm_ble_initiate_select_conn(BD_ADDR bda);
459 BOOLEAN btm_ble_start_auto_conn(BOOLEAN start);
460 BOOLEAN btm_ble_start_select_conn(BOOLEAN start, tBTM_BLE_SEL_CBACK   *p_select_cback);
461 BOOLEAN btm_ble_renew_bg_conn_params(BOOLEAN add, BD_ADDR bd_addr);
462 void btm_write_dir_conn_wl(BD_ADDR target_addr);
463 BOOLEAN btm_ble_update_mode_operation(UINT8 link_role, BD_ADDR bda, UINT8 status);
464 BOOLEAN btm_execute_wl_dev_operation(void);
465 void btm_ble_update_link_topology_mask(UINT8 role, BOOLEAN increase);
466 
467 /* direct connection utility */
468 BOOLEAN btm_send_pending_direct_conn(void);
469 void btm_ble_enqueue_direct_conn_req(void *p_param);
470 
471 /* BLE address management */
472 void btm_gen_resolvable_private_addr (void *p_cmd_cplt_cback);
473 void btm_gen_non_resolvable_private_addr (tBTM_BLE_ADDR_CBACK *p_cback, void *p);
474 void btm_ble_resolve_random_addr(BD_ADDR random_bda, tBTM_BLE_RESOLVE_CBACK *p_cback, void *p);
475 void btm_gen_resolve_paddr_low(tBTM_RAND_ENC *p);
476 
477 /*  privacy function */
478 #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
479 /* BLE address mapping with CS feature */
480 BOOLEAN btm_identity_addr_to_random_pseudo(BD_ADDR bd_addr, UINT8 *p_addr_type, BOOLEAN refresh);
481 BOOLEAN btm_random_pseudo_to_identity_addr(BD_ADDR random_pseudo, UINT8 *p_static_addr_type);
482 void btm_ble_refresh_peer_resolvable_private_addr(BD_ADDR pseudo_bda, BD_ADDR rra, UINT8 rra_type);
483 void btm_ble_refresh_local_resolvable_private_addr(BD_ADDR pseudo_addr, BD_ADDR local_rpa);
484 void btm_ble_read_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len) ;
485 void btm_ble_remove_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len);
486 void btm_ble_add_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len);
487 void btm_ble_clear_resolving_list_complete(UINT8 *p, UINT16 evt_len);
488 void btm_read_ble_resolving_list_size_complete (UINT8 *p, UINT16 evt_len);
489 void btm_ble_enable_resolving_list(UINT8);
490 BOOLEAN btm_ble_disable_resolving_list(UINT8 rl_mask, BOOLEAN to_resume);
491 void btm_ble_enable_resolving_list_for_platform (UINT8 rl_mask);
492 void btm_ble_resolving_list_init(UINT8 max_irk_list_sz);
493 void btm_ble_resolving_list_cleanup(void);
494 void btm_ble_add_default_entry_to_resolving_list(void);
495 #endif
496 
497 void btm_ble_multi_adv_configure_rpa (tBTM_BLE_MULTI_ADV_INST *p_inst);
498 void btm_ble_multi_adv_init(void);
499 void *btm_ble_multi_adv_get_ref(UINT8 inst_id);
500 void btm_ble_multi_adv_cleanup(void);
501 void btm_ble_multi_adv_reenable(UINT8 inst_id);
502 void btm_ble_multi_adv_enb_privacy(BOOLEAN enable);
503 char btm_ble_map_adv_tx_power(int tx_power_index);
504 void btm_ble_batchscan_init(void);
505 void btm_ble_batchscan_cleanup(void);
506 void btm_ble_adv_filter_init(void);
507 void btm_ble_adv_filter_cleanup(void);
508 BOOLEAN btm_ble_topology_check(tBTM_BLE_STATE_MASK request);
509 BOOLEAN btm_ble_clear_topology_mask(tBTM_BLE_STATE_MASK request_state);
510 BOOLEAN btm_ble_set_topology_mask(tBTM_BLE_STATE_MASK request_state);
511 tBTM_BLE_STATE_MASK btm_ble_get_topology_mask(void);
512 
513 #if BTM_BLE_CONFORMANCE_TESTING == TRUE
514 void btm_ble_set_no_disc_if_pair_fail (BOOLEAN disble_disc);
515 void btm_ble_set_test_mac_value (BOOLEAN enable, UINT8 *p_test_mac_val);
516 void btm_ble_set_test_local_sign_cntr_value(BOOLEAN enable, UINT32 test_local_sign_cntr);
517 void btm_set_random_address(BD_ADDR random_bda);
518 void btm_ble_set_keep_rfu_in_auth_req(BOOLEAN keep_rfu);
519 #endif
520 
521 BOOLEAN btm_get_current_conn_params(BD_ADDR bda, UINT16 *interval, UINT16 *latency, UINT16 *timeout);
522 
523 #if (BLE_50_FEATURE_SUPPORT == TRUE)
524 void btm_ble_update_phy_evt(tBTM_BLE_UPDATE_PHY *params);
525 void btm_ble_scan_timeout_evt(void);
526 void btm_ble_adv_set_terminated_evt(tBTM_BLE_ADV_TERMINAT *params);
527 void btm_ble_ext_adv_report_evt(tBTM_BLE_EXT_ADV_REPORT *params);
528 void btm_ble_scan_req_received_evt(tBTM_BLE_SCAN_REQ_RECEIVED *params);
529 void btm_ble_channel_select_algorithm_evt(tBTM_BLE_CHANNEL_SEL_ALG *params);
530 void btm_ble_periodic_adv_report_evt(tBTM_PERIOD_ADV_REPORT *params);
531 void btm_ble_periodic_adv_sync_lost_evt(tBTM_BLE_PERIOD_ADV_SYNC_LOST *params);
532 void btm_ble_periodic_adv_sync_establish_evt(tBTM_BLE_PERIOD_ADV_SYNC_ESTAB *params);
533 #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
534 
535 /*
536 #ifdef __cplusplus
537 }
538 #endif
539 */
540 #endif
541