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 functions for BLE whitelist operation.
22 *
23 ******************************************************************************/
24
25 #include <string.h>
26
27 #include "bt_types.h"
28 #include "btu.h"
29 #include "btm_int.h"
30 #include "l2c_int.h"
31 #include "hcimsgs.h"
32
33
34 #ifndef BTM_BLE_SCAN_PARAM_TOUT
35 #define BTM_BLE_SCAN_PARAM_TOUT 50 /* 50 seconds */
36 #endif
37
38 #if (BLE_INCLUDED == TRUE)
39
40 static void btm_suspend_wl_activity(tBTM_BLE_WL_STATE wl_state);
41 static void btm_resume_wl_activity(tBTM_BLE_WL_STATE wl_state);
42
43 /*******************************************************************************
44 **
45 ** Function btm_update_scanner_filter_policy
46 **
47 ** Description This function update the filter policy of scnner or advertiser.
48 *******************************************************************************/
btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy)49 void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy)
50 {
51 tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var;
52 BTM_TRACE_EVENT0 ("btm_update_scanner_filter_policy");
53
54 p_inq->sfp = scan_policy;
55 p_inq->scan_type = (p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE) ? BTM_BLE_SCAN_MODE_ACTI: p_inq->scan_type;
56
57 btsnd_hcic_ble_set_scan_params (p_inq->scan_type,
58 (UINT16)(!p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval),
59 (UINT16)(!p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window),
60 BLE_ADDR_PUBLIC,
61 scan_policy);
62 }
63 /*******************************************************************************
64 **
65 ** Function btm_add_dev_to_controller
66 **
67 ** Description This function load the device into controller white list
68 *******************************************************************************/
btm_add_dev_to_controller(BOOLEAN to_add,BD_ADDR bd_addr,UINT8 attr)69 BOOLEAN btm_add_dev_to_controller (BOOLEAN to_add, BD_ADDR bd_addr, UINT8 attr)
70 {
71 tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (bd_addr);
72 tBLE_ADDR_TYPE addr_type = BLE_ADDR_PUBLIC;
73 BOOLEAN started = FALSE;
74 BD_ADDR dummy_bda = {0};
75 tBT_DEVICE_TYPE dev_type;
76
77 if (p_dev_rec != NULL &&
78 p_dev_rec->device_type == BT_DEVICE_TYPE_BLE)
79 {
80
81 if (to_add)
82 {
83 if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_PUBLIC || !BTM_BLE_IS_RESOLVE_BDA(bd_addr))
84 {
85 started = btsnd_hcic_ble_add_white_list (p_dev_rec->ble.ble_addr_type, bd_addr);
86 }
87 if (memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) != 0 &&
88 memcmp(p_dev_rec->ble.static_addr, dummy_bda, BD_ADDR_LEN) != 0)
89 {
90 started = btsnd_hcic_ble_add_white_list (p_dev_rec->ble.static_addr_type, p_dev_rec->ble.static_addr);
91 }
92 }
93 else
94 {
95 if (!BTM_BLE_IS_RESOLVE_BDA(bd_addr))
96 {
97 started = btsnd_hcic_ble_remove_from_white_list (p_dev_rec->ble.ble_addr_type, bd_addr);
98 }
99 if (memcmp(p_dev_rec->ble.static_addr, dummy_bda, BD_ADDR_LEN) != 0 &&
100 memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) != 0)
101 {
102 started = btsnd_hcic_ble_remove_from_white_list (p_dev_rec->ble.static_addr_type, p_dev_rec->ble.static_addr);
103 }
104 }
105 } /* if not a known device, shall we add it? */
106 else
107 {
108 BTM_ReadDevInfo(bd_addr, &dev_type, &addr_type);
109
110 if (to_add)
111 started = btsnd_hcic_ble_add_white_list (addr_type, bd_addr);
112 else
113 started = btsnd_hcic_ble_remove_from_white_list (addr_type, bd_addr);
114 }
115
116 return started;
117
118 }
119 /*******************************************************************************
120 **
121 ** Function btm_execute_wl_dev_operation
122 **
123 ** Description execute the pending whitelist device operation(loading or removing)
124 *******************************************************************************/
btm_execute_wl_dev_operation(void)125 BOOLEAN btm_execute_wl_dev_operation(void)
126 {
127 tBTM_BLE_WL_OP *p_dev_op = btm_cb.ble_ctr_cb.wl_op_q;
128 UINT8 i = 0;
129 BOOLEAN rt = TRUE;
130
131 for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM && rt; i ++, p_dev_op ++)
132 {
133 if (p_dev_op->in_use)
134 {
135 rt = btm_add_dev_to_controller(p_dev_op->to_add, p_dev_op->bd_addr, p_dev_op->attr);
136 memset(p_dev_op, 0, sizeof(tBTM_BLE_WL_OP));
137 }
138 else
139 break;
140 }
141 return rt;
142 }
143 /*******************************************************************************
144 **
145 ** Function btm_enq_wl_dev_operation
146 **
147 ** Description enqueue the pending whitelist device operation(loading or removing).
148 *******************************************************************************/
btm_enq_wl_dev_operation(BOOLEAN to_add,BD_ADDR bd_addr,UINT8 attr)149 void btm_enq_wl_dev_operation(BOOLEAN to_add, BD_ADDR bd_addr, UINT8 attr)
150 {
151 tBTM_BLE_WL_OP *p_dev_op = btm_cb.ble_ctr_cb.wl_op_q;
152 UINT8 i = 0;
153
154 for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM; i ++, p_dev_op ++)
155 {
156 if (p_dev_op->in_use && !memcmp(p_dev_op->bd_addr, bd_addr, BD_ADDR_LEN))
157 {
158 p_dev_op->to_add = to_add;
159 p_dev_op->attr = attr;
160 return;
161 }
162 else if (!p_dev_op->in_use)
163 break;
164 }
165 if (i != BTM_BLE_MAX_BG_CONN_DEV_NUM)
166 {
167 p_dev_op->in_use = TRUE;
168 p_dev_op->to_add = to_add;
169 p_dev_op->attr = attr;
170 memcpy(p_dev_op->bd_addr, bd_addr, BD_ADDR_LEN);
171 }
172 else
173 {
174 BTM_TRACE_ERROR0("max pending WL operation reached, discard");
175 }
176 return;
177 }
178 /*******************************************************************************
179 **
180 ** Function btm_update_dev_to_white_list
181 **
182 ** Description This function adds a device into white list.
183 *******************************************************************************/
btm_update_dev_to_white_list(BOOLEAN to_add,BD_ADDR bd_addr,UINT8 attr)184 BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, UINT8 attr)
185 {
186 /* look up the sec device record, and find the address */
187 tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
188 BOOLEAN started = FALSE;
189 UINT8 wl_state = p_cb->wl_state;
190
191 if ((to_add && p_cb->num_empty_filter == 0) ||
192 (!to_add && p_cb->num_empty_filter == p_cb->max_filter_entries))
193 {
194 BTM_TRACE_ERROR1("WL full or empty, unable to update to WL. num_entry available: %d",
195 p_cb->num_empty_filter);
196 return started;
197 }
198
199 btm_suspend_wl_activity(wl_state);
200
201 /* enq pending WL device operation */
202 btm_enq_wl_dev_operation(to_add, bd_addr, attr);
203
204 btm_resume_wl_activity(wl_state);
205
206 return started;
207 }
208 /*******************************************************************************
209 **
210 ** Function btm_ble_clear_white_list
211 **
212 ** Description This function clears the white list.
213 *******************************************************************************/
btm_ble_clear_white_list(void)214 void btm_ble_clear_white_list (void)
215 {
216 BTM_TRACE_EVENT0 ("btm_ble_clear_white_list");
217 btsnd_hcic_ble_clear_white_list();
218 }
219
220 /*******************************************************************************
221 **
222 ** Function btm_ble_clear_white_list_complete
223 **
224 ** Description This function clears the white list complete.
225 *******************************************************************************/
btm_ble_clear_white_list_complete(UINT8 * p_data,UINT16 evt_len)226 void btm_ble_clear_white_list_complete(UINT8 *p_data, UINT16 evt_len)
227 {
228 tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
229 UINT8 status;
230 BTM_TRACE_EVENT0 ("btm_ble_clear_white_list_complete");
231 STREAM_TO_UINT8 (status, p_data);
232
233 if (status == HCI_SUCCESS)
234 p_cb->num_empty_filter = p_cb->max_filter_entries;
235
236 }
237 /*******************************************************************************
238 **
239 ** Function btm_ble_add_2_white_list_complete
240 **
241 ** Description This function read the current white list size.
242 *******************************************************************************/
btm_ble_add_2_white_list_complete(UINT8 status)243 void btm_ble_add_2_white_list_complete(UINT8 status)
244 {
245 tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
246 BTM_TRACE_EVENT0 ("btm_ble_add_2_white_list_complete");
247
248 if (status == HCI_SUCCESS)
249 {
250 p_cb->num_empty_filter --;
251 }
252 }
253 /*******************************************************************************
254 **
255 ** Function btm_ble_add_2_white_list_complete
256 **
257 ** Description This function read the current white list size.
258 *******************************************************************************/
btm_ble_remove_from_white_list_complete(UINT8 * p,UINT16 evt_len)259 void btm_ble_remove_from_white_list_complete(UINT8 *p, UINT16 evt_len)
260 {
261 tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
262 BTM_TRACE_EVENT0 ("btm_ble_remove_from_white_list_complete");
263 if (*p == HCI_SUCCESS)
264 {
265 p_cb->num_empty_filter ++;
266 }
267 }
268 /*******************************************************************************
269 **
270 ** Function btm_ble_count_unconn_dev_in_whitelist
271 **
272 ** Description This function find the number of un-connected background device
273 *******************************************************************************/
btm_ble_count_unconn_dev_in_whitelist(void)274 UINT8 btm_ble_count_unconn_dev_in_whitelist(void)
275 {
276 tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
277 UINT8 i, count = 0;
278
279 for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM; i ++)
280 {
281 if (p_cb->bg_dev_list[i].in_use &&
282 !BTM_IsAclConnectionUp(p_cb->bg_dev_list[i].bd_addr))
283 {
284 count ++;
285 }
286 }
287 return count;
288
289 }
290 /*******************************************************************************
291 **
292 ** Function btm_update_bg_conn_list
293 **
294 ** Description This function update the local background connection device list.
295 *******************************************************************************/
btm_update_bg_conn_list(BOOLEAN to_add,BD_ADDR bd_addr,UINT8 * p_attr_tag)296 BOOLEAN btm_update_bg_conn_list(BOOLEAN to_add, BD_ADDR bd_addr, UINT8 *p_attr_tag)
297 {
298 tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
299 tBTM_LE_BG_CONN_DEV *p_bg_dev = &p_cb->bg_dev_list[0], *p_next, *p_cur;
300 UINT8 i, j;
301 BOOLEAN ret = FALSE;
302
303 BTM_TRACE_EVENT0 ("btm_update_bg_conn_list");
304
305 if ((to_add && (p_cb->bg_dev_num == BTM_BLE_MAX_BG_CONN_DEV_NUM || p_cb->num_empty_filter == 0)))
306 {
307 BTM_TRACE_DEBUG1("num_empty_filter = %d", p_cb->num_empty_filter);
308 return ret;
309 }
310
311 for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM; i ++, p_bg_dev ++)
312 {
313 if (p_bg_dev->in_use && memcmp(p_bg_dev->bd_addr, bd_addr, BD_ADDR_LEN) == 0)
314 {
315 if (!to_add)
316 {
317 memset(p_bg_dev, 0, sizeof(tBTM_LE_BG_CONN_DEV));
318 p_cb->bg_dev_num --;
319 p_cur = p_bg_dev;
320 p_next = p_bg_dev + 1;
321 for (j = i + 1 ;j < BTM_BLE_MAX_BG_CONN_DEV_NUM && p_next->in_use ; j ++, p_cur ++, p_next ++ )
322 memcpy(p_cur, p_next, sizeof(tBTM_LE_BG_CONN_DEV));
323 }
324 ret = TRUE;
325 break;
326 }
327 else if (!p_bg_dev->in_use && to_add)
328 {
329 BTM_TRACE_DEBUG0("add new WL entry in bg_dev_list");
330
331 memcpy(p_bg_dev->bd_addr, bd_addr, BD_ADDR_LEN);
332 p_bg_dev->in_use = TRUE;
333 p_cb->bg_dev_num ++;
334
335 ret = TRUE;
336 break;
337 }
338 }
339
340
341 return ret;
342 }
343
344 /*******************************************************************************
345 **
346 ** Function btm_ble_start_auto_conn
347 **
348 ** Description This function is to start/stop auto connection procedure.
349 **
350 ** Parameters start: TRUE to start; FALSE to stop.
351 **
352 ** Returns void
353 **
354 *******************************************************************************/
btm_ble_start_auto_conn(BOOLEAN start)355 BOOLEAN btm_ble_start_auto_conn(BOOLEAN start)
356 {
357 tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
358 BD_ADDR dummy_bda = {0};
359 BOOLEAN exec = TRUE;
360 UINT8 own_addr_type = BLE_ADDR_PUBLIC;
361 UINT16 scan_int, scan_win;
362
363 if (start)
364 {
365 if (p_cb->conn_state == BLE_CONN_IDLE && btm_ble_count_unconn_dev_in_whitelist() > 0)
366 {
367 btm_execute_wl_dev_operation();
368
369 scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_SLOW_INT_1 : p_cb->scan_int;
370 scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_SLOW_WIN_1 : p_cb->scan_win;
371
372 if (!btsnd_hcic_ble_create_ll_conn (scan_int, /* UINT16 scan_int */
373 scan_win, /* UINT16 scan_win */
374 0x01, /* UINT8 white_list */
375 BLE_ADDR_PUBLIC, /* UINT8 addr_type_peer */
376 dummy_bda, /* BD_ADDR bda_peer */
377 own_addr_type, /* UINT8 addr_type_own, not allow random address for central */
378 BTM_BLE_CONN_INT_MIN_DEF, /* UINT16 conn_int_min */
379 BTM_BLE_CONN_INT_MAX_DEF, /* UINT16 conn_int_max */
380 BTM_BLE_CONN_SLAVE_LATENCY_DEF, /* UINT16 conn_latency */
381 BTM_BLE_CONN_TIMEOUT_DEF, /* UINT16 conn_timeout */
382 0, /* UINT16 min_len */
383 0)) /* UINT16 max_len */
384 {
385 /* start auto connection failed */
386 exec = FALSE;
387 }
388 else
389 {
390 btm_ble_set_conn_st (BLE_BG_CONN);
391
392 }
393 }
394 else
395 {
396 exec = FALSE;
397 }
398 }
399 else
400 {
401 if (p_cb->conn_state == BLE_BG_CONN)
402 {
403 btsnd_hcic_ble_create_conn_cancel();
404 btm_ble_set_conn_st (BLE_CONN_CANCEL);
405
406 }
407 else
408 {
409 #if 0
410 BTM_TRACE_ERROR1("conn_st = %d, not in auto conn state, can not stop.", p_cb->conn_state);
411 exec = FALSE;
412 #endif
413 }
414 }
415 return exec;
416 }
417
418 /*******************************************************************************
419 **
420 ** Function btm_ble_start_select_conn
421 **
422 ** Description This function is to start/stop selective connection procedure.
423 **
424 ** Parameters start: TRUE to start; FALSE to stop.
425 ** p_select_cback: callback function to return application
426 ** selection.
427 **
428 ** Returns BOOLEAN: selective connectino procedure is started.
429 **
430 *******************************************************************************/
btm_ble_start_select_conn(BOOLEAN start,tBTM_BLE_SEL_CBACK * p_select_cback)431 BOOLEAN btm_ble_start_select_conn(BOOLEAN start,tBTM_BLE_SEL_CBACK *p_select_cback)
432 {
433 tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
434 UINT16 scan_int, scan_win;
435
436 BTM_TRACE_EVENT0 ("btm_ble_start_select_conn");
437
438 scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_INT : p_cb->scan_int;
439 scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_SCAN_FAST_WIN : p_cb->scan_win;
440
441 if (start)
442 {
443 if (btm_cb.btm_inq_vars.inq_active == BTM_INQUIRY_INACTIVE)
444 {
445 if (p_select_cback != NULL)
446 btm_cb.ble_ctr_cb.p_select_cback = p_select_cback;
447
448 btm_update_scanner_filter_policy(SP_ADV_WL);
449 btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_PASS;
450
451 if (!btsnd_hcic_ble_set_scan_params(BTM_BLE_SCAN_MODE_PASS, /* use passive scan by default */
452 scan_int, /* scan interval */
453 scan_win, /* scan window */
454 BLE_ADDR_PUBLIC, /* own device, DUMO always use public */
455 SP_ADV_WL) /* process advertising packets only from devices in the White List */
456 )
457 return FALSE;
458
459 if (p_cb->inq_var.adv_mode == BTM_BLE_ADV_ENABLE
460 )
461 {
462 BTM_TRACE_ERROR0("peripheral device cannot initiate a selective connection");
463 return FALSE;
464 }
465 else if (p_cb->bg_dev_num > 0 && btm_ble_count_unconn_dev_in_whitelist() > 0 )
466 {
467
468 if (!btsnd_hcic_ble_set_scan_enable(TRUE, TRUE)) /* duplicate filtering enabled */
469 return FALSE;
470
471 /* mark up inquiry status flag */
472 btm_cb.btm_inq_vars.inq_active |= BTM_LE_SELECT_CONN_ACTIVE;
473 p_cb->inq_var.proc_mode = BTM_BLE_SELECT_SCAN;
474 p_cb->conn_state = BLE_BG_CONN;
475 }
476 }
477 else
478 {
479 BTM_TRACE_ERROR0("scan active, can not start selective connection procedure");
480 return FALSE;
481 }
482 }
483 else /* disable selective connection mode */
484 {
485 btm_cb.btm_inq_vars.inq_active &= ~BTM_LE_SELECT_CONN_ACTIVE;
486 btm_cb.ble_ctr_cb.inq_var.proc_mode = BTM_BLE_INQUIRY_NONE;
487
488 btm_update_scanner_filter_policy(SP_ADV_ALL);
489 /* stop scanning */
490 if (!btsnd_hcic_ble_set_scan_enable(FALSE, TRUE)) /* duplicate filtering enabled */
491 return FALSE;
492 btm_update_scanner_filter_policy(SP_ADV_ALL);
493 }
494 return TRUE;
495 }
496 /*******************************************************************************
497 **
498 ** Function btm_ble_initiate_select_conn
499 **
500 ** Description This function is to start/stop selective connection procedure.
501 **
502 ** Parameters start: TRUE to start; FALSE to stop.
503 ** p_select_cback: callback function to return application
504 ** selection.
505 **
506 ** Returns BOOLEAN: selective connectino procedure is started.
507 **
508 *******************************************************************************/
btm_ble_initiate_select_conn(BD_ADDR bda)509 void btm_ble_initiate_select_conn(BD_ADDR bda)
510 {
511 BTM_TRACE_EVENT0 ("btm_ble_initiate_select_conn");
512
513 /* use direct connection procedure to initiate connection */
514 if (!L2CA_ConnectFixedChnl(L2CAP_ATT_CID, bda))
515 {
516 BTM_TRACE_ERROR0("btm_ble_initiate_select_conn failed");
517 }
518 }
519 /*******************************************************************************
520 **
521 ** Function btm_ble_suspend_bg_conn
522 **
523 ** Description This function is to suspend an active background connection
524 ** procedure.
525 **
526 ** Parameters none.
527 **
528 ** Returns none.
529 **
530 *******************************************************************************/
btm_ble_suspend_bg_conn(void)531 void btm_ble_suspend_bg_conn(void)
532 {
533 tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
534 BTM_TRACE_EVENT0 ("btm_ble_suspend_bg_conn");
535
536 if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO)
537 {
538 btm_ble_start_auto_conn(FALSE);
539 }
540 else if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE)
541 {
542 btm_ble_start_select_conn(FALSE, NULL);
543 }
544 }
545 /*******************************************************************************
546 **
547 ** Function btm_suspend_wl_activity
548 **
549 ** Description This function is to suspend white list related activity
550 **
551 ** Returns none.
552 **
553 *******************************************************************************/
btm_suspend_wl_activity(tBTM_BLE_WL_STATE wl_state)554 static void btm_suspend_wl_activity(tBTM_BLE_WL_STATE wl_state)
555 {
556 if (wl_state & BTM_BLE_WL_INIT)
557 {
558 btm_ble_start_auto_conn(FALSE);
559 }
560 if (wl_state & BTM_BLE_WL_SCAN)
561 {
562 btm_ble_start_select_conn(FALSE, NULL);
563 }
564 if (wl_state & BTM_BLE_WL_ADV)
565 {
566 btsnd_hcic_ble_set_adv_enable(BTM_BLE_ADV_DISABLE);
567 }
568
569 }
570 /*******************************************************************************
571 **
572 ** Function btm_resume_wl_activity
573 **
574 ** Description This function is to resume white list related activity
575 **
576 ** Returns none.
577 **
578 *******************************************************************************/
btm_resume_wl_activity(tBTM_BLE_WL_STATE wl_state)579 static void btm_resume_wl_activity(tBTM_BLE_WL_STATE wl_state)
580 {
581 btm_ble_resume_bg_conn();
582
583 if (wl_state & BTM_BLE_WL_ADV)
584 {
585 btsnd_hcic_ble_set_adv_enable(BTM_BLE_ADV_ENABLE);
586 }
587
588 }
589 /*******************************************************************************
590 **
591 ** Function btm_ble_resume_bg_conn
592 **
593 ** Description This function is to resume a background auto connection
594 ** procedure.
595 **
596 ** Parameters none.
597 **
598 ** Returns none.
599 **
600 *******************************************************************************/
btm_ble_resume_bg_conn(void)601 BOOLEAN btm_ble_resume_bg_conn(void)
602 {
603 tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
604 BOOLEAN ret = FALSE;
605
606 if (p_cb->bg_conn_type != BTM_BLE_CONN_NONE)
607 {
608 if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO)
609 ret = btm_ble_start_auto_conn(TRUE);
610
611 if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE)
612 ret = btm_ble_start_select_conn(TRUE, btm_cb.ble_ctr_cb.p_select_cback);
613 }
614
615 return ret;
616 }
617 /*******************************************************************************
618 **
619 ** Function btm_ble_get_conn_st
620 **
621 ** Description This function get BLE connection state
622 **
623 ** Returns connection state
624 **
625 *******************************************************************************/
btm_ble_get_conn_st(void)626 tBTM_BLE_CONN_ST btm_ble_get_conn_st(void)
627 {
628 return btm_cb.ble_ctr_cb.conn_state;
629 }
630 /*******************************************************************************
631 **
632 ** Function btm_ble_set_conn_st
633 **
634 ** Description This function set BLE connection state
635 **
636 ** Returns None.
637 **
638 *******************************************************************************/
btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st)639 void btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st)
640 {
641 btm_cb.ble_ctr_cb.conn_state = new_st;
642 }
643
644 /*******************************************************************************
645 **
646 ** Function btm_ble_enqueue_direct_conn_req
647 **
648 ** Description This function enqueue the direct connection request
649 **
650 ** Returns None.
651 **
652 *******************************************************************************/
btm_ble_enqueue_direct_conn_req(void * p_param)653 void btm_ble_enqueue_direct_conn_req(void *p_param)
654 {
655 tBTM_BLE_CONN_REQ *p = (tBTM_BLE_CONN_REQ *)GKI_getbuf(sizeof(tBTM_BLE_CONN_REQ));
656
657 p->p_param = p_param;
658
659 GKI_enqueue (&btm_cb.ble_ctr_cb.conn_pending_q, p);
660 }
661 /*******************************************************************************
662 **
663 ** Function btm_send_pending_direct_conn
664 **
665 ** Description This function send the pending direct connection request in queue
666 **
667 ** Returns TRUE if started, FALSE otherwise
668 **
669 *******************************************************************************/
btm_send_pending_direct_conn(void)670 BOOLEAN btm_send_pending_direct_conn(void )
671 {
672 tBTM_BLE_CONN_REQ *p_req;
673 BOOLEAN rt = FALSE;
674
675 if ( btm_cb.ble_ctr_cb.conn_pending_q.count )
676 {
677 p_req = (tBTM_BLE_CONN_REQ*)GKI_dequeue (&btm_cb.ble_ctr_cb.conn_pending_q);
678
679 rt = l2cble_init_direct_conn((tL2C_LCB *)(p_req->p_param));
680
681 GKI_freebuf((void *)p_req);
682 }
683
684 return rt;
685 }
686 #endif
687
688
689