• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef BTM_BLE_SCAN_PARAM_TOUT
34 #define BTM_BLE_SCAN_PARAM_TOUT      50    /* 50 seconds */
35 #endif
36 
37 #if (BLE_INCLUDED == TRUE)
38 /*******************************************************************************
39 **
40 ** Function         btm_update_scanner_filter_policy
41 **
42 ** Description      This function update the filter policy of scnner or advertiser.
43 *******************************************************************************/
btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy)44 void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy)
45 {
46     tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var;
47     BTM_TRACE_EVENT0 ("btm_update_scanner_filter_policy");
48     btm_cb.ble_ctr_cb.inq_var.sfp = scan_policy;
49 
50     btsnd_hcic_ble_set_scan_params ((UINT8)((p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE) ? BTM_BLE_SCAN_MODE_ACTI: p_inq->scan_type),
51                                     (UINT16)(!p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval),
52                                     (UINT16)(!p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window),
53                                      BLE_ADDR_PUBLIC,
54                                      scan_policy);
55 }
56 /*******************************************************************************
57 **
58 ** Function         btm_update_adv_filter_policy
59 **
60 ** Description      This function update the filter policy of scnner or advertiser.
61 *******************************************************************************/
btm_update_adv_filter_policy(tBTM_BLE_AFP adv_policy)62 void btm_update_adv_filter_policy(tBTM_BLE_AFP adv_policy)
63 {
64     tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var;
65     BTM_TRACE_EVENT0 ("btm_update_adv_filter_policy");
66     p_cb->afp = adv_policy;
67 }
68 /*******************************************************************************
69 **
70 ** Function         btm_update_dev_to_white_list
71 **
72 ** Description      This function adds a device into white list.
73 *******************************************************************************/
btm_update_dev_to_white_list(BOOLEAN to_add,BD_ADDR bd_addr,tBLE_ADDR_TYPE addr_type)74 BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type)
75 {
76     /* look up the sec device record, and find the address */
77     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
78     tBTM_SEC_DEV_REC    *p_dev_rec;
79     BD_ADDR             dummy_bda = {0};
80     BOOLEAN             started = FALSE, suspend = FALSE;
81 
82     if (btm_cb.btm_inq_vars.inq_active)
83     {
84         suspend = TRUE;
85         btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE);
86     }
87 
88     if ((p_dev_rec = btm_find_dev (bd_addr)) != NULL &&
89         p_dev_rec->device_type == BT_DEVICE_TYPE_BLE)
90     {
91         BTM_TRACE_DEBUG0("btm_update_dev_to_white_list 1");
92 
93         if ((to_add && p_cb->num_empty_filter == 0) ||
94             (!to_add && p_cb->num_empty_filter == p_cb->max_filter_entries))
95         {
96             BTM_TRACE_ERROR1("num_entry available in controller: %d", p_cb->num_empty_filter);
97             return started;
98         }
99 
100 
101         if ( p_dev_rec->ble.ble_addr_type == BLE_ADDR_PUBLIC)
102         {
103             if (to_add)
104                 started = btsnd_hcic_ble_add_white_list (BLE_ADDR_PUBLIC, bd_addr);
105             else
106                 started = btsnd_hcic_ble_remove_from_white_list (BLE_ADDR_PUBLIC, bd_addr);
107         }
108         else
109         {
110             if (BLE_ADDR_IS_STATIC(bd_addr))
111             {
112                 if (to_add)
113                     started = btsnd_hcic_ble_add_white_list (BLE_ADDR_RANDOM, bd_addr);
114                 else
115                     started = btsnd_hcic_ble_remove_from_white_list (BLE_ADDR_RANDOM, bd_addr);
116 
117             }
118             if (memcmp(p_dev_rec->ble.reconn_addr, dummy_bda, BD_ADDR_LEN) != 0)
119             {
120                 if (to_add)
121                     started = btsnd_hcic_ble_add_white_list (BLE_ADDR_RANDOM, p_dev_rec->ble.reconn_addr);
122                 else
123                     started = btsnd_hcic_ble_remove_from_white_list (BLE_ADDR_RANDOM, p_dev_rec->ble.reconn_addr);
124             }
125         }
126     }
127     /* if not a known device, shall we add it? */
128     else
129     {
130         if (to_add)
131             started = btsnd_hcic_ble_add_white_list (addr_type, bd_addr);
132         else
133             started = btsnd_hcic_ble_remove_from_white_list (addr_type, bd_addr);
134     }
135 
136     if (suspend)
137     {
138         btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, BTM_BLE_DUPLICATE_DISABLE);
139     }
140 
141     return started;
142 }
143 /*******************************************************************************
144 **
145 ** Function         btm_ble_clear_white_list
146 **
147 ** Description      This function clears the white list.
148 *******************************************************************************/
btm_ble_clear_white_list(void)149 void btm_ble_clear_white_list (void)
150 {
151     BTM_TRACE_EVENT0 ("btm_ble_clear_white_list");
152     btsnd_hcic_ble_clear_white_list();
153 }
154 
155 /*******************************************************************************
156 **
157 ** Function         btm_ble_clear_white_list_complete
158 **
159 ** Description      This function clears the white list complete.
160 *******************************************************************************/
btm_ble_clear_white_list_complete(UINT8 * p_data,UINT16 evt_len)161 void btm_ble_clear_white_list_complete(UINT8 *p_data, UINT16 evt_len)
162 {
163     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
164     UINT8       status;
165     BTM_TRACE_EVENT0 ("btm_ble_clear_white_list_complete");
166     STREAM_TO_UINT8  (status, p_data);
167 
168     if (status == HCI_SUCCESS)
169         p_cb->num_empty_filter = p_cb->max_filter_entries;
170 
171 }
172 /*******************************************************************************
173 **
174 ** Function         btm_ble_add_2_white_list_complete
175 **
176 ** Description      This function read the current white list size.
177 *******************************************************************************/
btm_ble_add_2_white_list_complete(UINT8 * p,UINT16 evt_len)178 void btm_ble_add_2_white_list_complete(UINT8 *p, UINT16 evt_len)
179 {
180     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
181     BTM_TRACE_EVENT0 ("btm_ble_add_2_white_list_complete");
182 
183     if (*p == HCI_SUCCESS)
184     {
185         p_cb->num_empty_filter --;
186     }
187 }
188 /*******************************************************************************
189 **
190 ** Function         btm_ble_add_2_white_list_complete
191 **
192 ** Description      This function read the current white list size.
193 *******************************************************************************/
btm_ble_remove_from_white_list_complete(UINT8 * p,UINT16 evt_len)194 void btm_ble_remove_from_white_list_complete(UINT8 *p, UINT16 evt_len)
195 {
196     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
197     BTM_TRACE_EVENT0 ("btm_ble_remove_from_white_list_complete");
198     if (*p == HCI_SUCCESS)
199     {
200         p_cb->num_empty_filter ++;
201     }
202 }
203 /*******************************************************************************
204 **
205 ** Function         btm_ble_find_dev_in_whitelist
206 **
207 ** Description      This function check if the device is in the white list
208 *******************************************************************************/
btm_ble_find_dev_in_whitelist(BD_ADDR bd_addr)209 BOOLEAN btm_ble_find_dev_in_whitelist(BD_ADDR bd_addr)
210 {
211     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
212     UINT8 i;
213 
214     BTM_TRACE_EVENT0 ("btm_ble_find_dev_in_whitelist");
215 
216     /* empty wl */
217     if (p_cb->num_empty_filter == p_cb->max_filter_entries)
218     {
219         BTM_TRACE_DEBUG0("white list empty");
220         return FALSE;
221     }
222 
223     for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM && i < p_cb->max_filter_entries; i ++)
224     {
225         if (memcmp(p_cb->bg_conn_dev_list[i], bd_addr, BD_ADDR_LEN) == 0)
226             return TRUE;
227     }
228     return FALSE;
229 }
230 /*******************************************************************************
231 **
232 ** Function         btm_ble_count_unconn_dev_in_whitelist
233 **
234 ** Description      This function check the number of unconnected device in white list.
235 *******************************************************************************/
btm_ble_count_unconn_dev_in_whitelist(void)236 UINT8 btm_ble_count_unconn_dev_in_whitelist(void)
237 {
238     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
239     UINT8 count = 0, i;
240     BD_ADDR dummy_bda ={0};
241 
242     BTM_TRACE_EVENT0 ("btm_ble_find_dev_in_whitelist");
243 
244     for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM && i < p_cb->max_filter_entries; i ++)
245     {
246         if (memcmp(p_cb->bg_conn_dev_list[i], dummy_bda, BD_ADDR_LEN) != 0 &&
247             !BTM_IsAclConnectionUp(p_cb->bg_conn_dev_list[i]))
248         {
249             count ++;
250         }
251     }
252     return count;
253 }
254 /*******************************************************************************
255 **
256 ** Function         btm_update_bg_conn_list
257 **
258 ** Description      This function update the local background connection device list.
259 *******************************************************************************/
btm_update_bg_conn_list(BOOLEAN to_add,BD_ADDR bd_addr)260 BOOLEAN btm_update_bg_conn_list(BOOLEAN to_add, BD_ADDR bd_addr)
261 {
262     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
263     UINT8 i;
264     BD_ADDR dummy_bda = {0};
265     BTM_TRACE_EVENT0 ("btm_update_bg_conn_list");
266     if ((to_add && (p_cb->bg_conn_dev_num == BTM_BLE_MAX_BG_CONN_DEV_NUM || p_cb->num_empty_filter == 0)) ||
267         (!to_add && p_cb->num_empty_filter == p_cb->max_filter_entries))
268     {
269         BTM_TRACE_DEBUG1("num_empty_filter = %d", p_cb->num_empty_filter);
270         return FALSE;
271     }
272 
273     for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM && i < p_cb->max_filter_entries; i ++)
274     {
275         /* to add */
276         if (memcmp(p_cb->bg_conn_dev_list[i], dummy_bda, BD_ADDR_LEN) == 0 && to_add)
277         {
278             memcpy(p_cb->bg_conn_dev_list[i], bd_addr, BD_ADDR_LEN);
279             p_cb->bg_conn_dev_num ++;
280             return TRUE;
281         }
282         /* to remove */
283         if (!to_add && memcmp(p_cb->bg_conn_dev_list[i], bd_addr, BD_ADDR_LEN) == 0)
284         {
285             memset(p_cb->bg_conn_dev_list[i], 0, BD_ADDR_LEN);
286             p_cb->bg_conn_dev_num --;
287             return TRUE;
288         }
289     }
290     return FALSE;
291 }
292 /*******************************************************************************
293 **
294 ** Function         btm_write_bg_conn_wl
295 **
296 ** Description      This function write background connection device list into
297 **                  controller.
298 *******************************************************************************/
btm_write_bg_conn_wl(void)299 void btm_write_bg_conn_wl(void)
300 {
301     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
302     UINT8       i;
303     BTM_TRACE_EVENT0 ("btm_write_bg_conn_wl");
304     btm_ble_clear_white_list();
305 
306     for (i = 0; i < p_cb->bg_conn_dev_num; i ++)
307     {
308         if (!btm_update_dev_to_white_list(TRUE, p_cb->bg_conn_dev_list[i], BLE_ADDR_PUBLIC))
309             break;
310     }
311     return;
312 }
313 /*******************************************************************************
314 **
315 ** Function         btm_ble_start_auto_conn
316 **
317 ** Description      This function is to start/stop auto connection procedure.
318 **
319 ** Parameters       start: TRUE to start; FALSE to stop.
320 **
321 ** Returns          void
322 **
323 *******************************************************************************/
btm_ble_start_auto_conn(BOOLEAN start)324 BOOLEAN btm_ble_start_auto_conn(BOOLEAN start)
325 {
326     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
327     BD_ADDR dummy_bda = {0};
328     BOOLEAN exec = TRUE;
329     UINT16 scan_int, scan_win;
330 
331     scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_CONN_EST_SCAN_INT : p_cb->scan_int;
332     scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_CONN_EST_SCAN_WIND : p_cb->scan_win;
333 
334     if (start)
335     {
336         if (!l2cb.is_ble_connecting &&
337             btm_ble_count_unconn_dev_in_whitelist() > 0)
338         {
339             if (p_cb->bg_conn_state != BLE_BG_CONN_ACTIVE && p_cb->bg_conn_dev_num > 0)
340             {
341                 if (!btsnd_hcic_ble_create_ll_conn (scan_int,  /* UINT16 scan_int      */
342                                                     scan_win,    /* UINT16 scan_win      */
343                                                     0x01,                   /* UINT8 white_list     */
344                                                     BLE_ADDR_PUBLIC,        /* UINT8 addr_type_peer */
345                                                     dummy_bda,              /* BD_ADDR bda_peer     */
346                                                     BLE_ADDR_PUBLIC,         /* UINT8 addr_type_own  */
347                                                     BTM_BLE_CONN_INT_MIN_DEF,   /* UINT16 conn_int_min  */
348                                                     BTM_BLE_CONN_INT_MAX_DEF,   /* UINT16 conn_int_max  */
349                                                     BTM_BLE_CONN_SLAVE_LATENCY_DEF,  /* UINT16 conn_latency  */
350                                                     BTM_BLE_CONN_TIMEOUT_DEF,        /* UINT16 conn_timeout  */
351                                                     0,                       /* UINT16 min_len       */
352                                                     0))                      /* UINT16 max_len       */
353                 {
354                     /* start auto connection failed */
355                     exec =  FALSE;
356                 }
357                 else
358                 {
359                     p_cb->bg_conn_state = BLE_BG_CONN_ACTIVE;
360                 }
361             }
362         }
363         else
364             exec = FALSE;
365     }
366     else
367     {
368         if (p_cb->bg_conn_state == BLE_BG_CONN_ACTIVE)
369         {
370             if (!btsnd_hcic_ble_create_conn_cancel())
371                 exec = FALSE;
372             else
373                 p_cb->bg_conn_state = BLE_BG_CONN_IDLE;
374         }
375     }
376     return exec;
377 }
378 
379 /*******************************************************************************
380 **
381 ** Function         btm_ble_start_select_conn
382 **
383 ** Description      This function is to start/stop selective connection procedure.
384 **
385 ** Parameters       start: TRUE to start; FALSE to stop.
386 **                  p_select_cback: callback function to return application
387 **                                  selection.
388 **
389 ** Returns          BOOLEAN: selective connectino procedure is started.
390 **
391 *******************************************************************************/
btm_ble_start_select_conn(BOOLEAN start,tBTM_BLE_SEL_CBACK * p_select_cback)392 BOOLEAN btm_ble_start_select_conn(BOOLEAN start,tBTM_BLE_SEL_CBACK   *p_select_cback)
393 {
394     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
395     UINT16 scan_int, scan_win;
396 
397     BTM_TRACE_EVENT0 ("btm_ble_start_select_conn");
398 
399     scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_CONN_EST_SCAN_INT : p_cb->scan_int;
400     scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_CONN_EST_SCAN_WIND : p_cb->scan_win;
401 
402     if (start)
403     {
404         if (!btm_cb.btm_inq_vars.inq_active)
405         {
406             btm_cb.ble_ctr_cb.p_select_cback = p_select_cback;
407 
408             btm_update_scanner_filter_policy(SP_ADV_WL);
409 
410             if (!btsnd_hcic_ble_set_scan_params(BTM_BLE_SCAN_MODE_PASS,  /* use passive scan by default */
411                                                 scan_int, /* scan interval */
412                                                 scan_win,    /* scan window */
413                                                 BLE_ADDR_PUBLIC,         /* own device, DUMO always use public */
414                                                 SP_ADV_WL)              /* process advertising packets only from devices in the White List */
415                 )
416                 return FALSE;
417 
418             if (p_cb->inq_var.adv_mode == BTM_BLE_ADV_ENABLE)
419             {
420                 BTM_TRACE_ERROR0("peripheral device cannot initiate a selective connection");
421                 return FALSE;
422             }
423             else if (p_cb->bg_conn_dev_num > 0 && btm_ble_count_unconn_dev_in_whitelist() > 0 )
424             {
425 
426                 if (!btsnd_hcic_ble_set_scan_enable(TRUE, TRUE)) /* duplicate filtering enabled */
427                     return FALSE;
428 
429                 /* mark up inquiry status flag */
430                 btm_cb.btm_inq_vars.inq_active = TRUE;
431                 btm_cb.ble_ctr_cb.inq_var.proc_mode = BTM_BLE_SELECT_SCAN;
432 
433                 p_cb->bg_conn_state = BLE_BG_CONN_ACTIVE;
434 
435             }
436         }
437         else
438         {
439             BTM_TRACE_ERROR0("scan active, can not start selective connection procedure");
440             return FALSE;
441         }
442     }
443     else /* disable selective connection mode */
444     {
445         p_cb->p_select_cback = NULL;
446         btm_cb.btm_inq_vars.inq_active = FALSE;
447         btm_cb.ble_ctr_cb.inq_var.proc_mode = BTM_BLE_INQUIRY_NONE;
448 
449         btm_update_scanner_filter_policy(SP_ADV_ALL);
450 
451         /* stop scanning */
452         if (p_cb->bg_conn_dev_num > 0)
453         {
454             if (!btsnd_hcic_ble_set_scan_enable(FALSE, TRUE)) /* duplicate filtering enabled */
455                 return FALSE;
456         }
457     }
458     return TRUE;
459 }
460 /*******************************************************************************
461 **
462 ** Function         btm_ble_initiate_select_conn
463 **
464 ** Description      This function is to start/stop selective connection procedure.
465 **
466 ** Parameters       start: TRUE to start; FALSE to stop.
467 **                  p_select_cback: callback function to return application
468 **                                  selection.
469 **
470 ** Returns          BOOLEAN: selective connectino procedure is started.
471 **
472 *******************************************************************************/
btm_ble_initiate_select_conn(BD_ADDR bda)473 void btm_ble_initiate_select_conn(BD_ADDR bda)
474 {
475     UINT8   addr_type;
476     BTM_TRACE_EVENT0 ("btm_ble_initiate_select_conn");
477     addr_type = btm_ble_map_bda_to_conn_bda(bda);
478 
479     /* use direct connection procedure to initiate connection */
480     if (!L2CA_ConnectFixedChnl(L2CAP_ATT_CID, bda))
481     {
482         BTM_TRACE_ERROR0("btm_ble_initiate_select_conn failed");
483     }
484 }
485 /*******************************************************************************
486 **
487 ** Function         btm_ble_suspend_bg_sele_conn
488 **
489 ** Description      This function is to suspend an active background connection
490 **                  procedure.
491 **
492 ** Parameters       none.
493 **
494 ** Returns          none.
495 **
496 *******************************************************************************/
btm_ble_suspend_bg_sele_conn(void)497 void btm_ble_suspend_bg_sele_conn(void)
498 {
499     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
500     BTM_TRACE_EVENT0 ("btm_ble_suspend_bg_sele_conn");
501 
502     if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE)
503     {
504         p_cb->bg_conn_state = BLE_BG_CONN_SUSPEND;
505         btm_ble_start_select_conn(FALSE, NULL);
506     }
507 }
508 /*******************************************************************************
509 **
510 ** Function         btm_ble_suspend_bg_conn
511 **
512 ** Description      This function is to suspend an active background connection
513 **                  procedure.
514 **
515 ** Parameters       none.
516 **
517 ** Returns          none.
518 **
519 *******************************************************************************/
btm_ble_suspend_bg_conn(void)520 void btm_ble_suspend_bg_conn(void)
521 {
522     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
523     BTM_TRACE_EVENT0 ("btm_ble_suspend_bg_conn");
524 
525     if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO)
526     {
527         if (btm_ble_start_auto_conn(FALSE))
528             p_cb->bg_conn_state = BLE_BG_CONN_SUSPEND;
529     }
530 }
531 /*******************************************************************************
532 **
533 ** Function         btm_ble_scan_param_idle
534 **
535 ** Description      This function is to process the scan parameter idle timeout
536 **                  timeout.
537 ********************************************************************************/
btm_ble_scan_param_idle(void)538 void btm_ble_scan_param_idle(void)
539 {
540     BTM_BleSetConnScanParams(BTM_BLE_CONN_EST_SCAN_INT_LO, BTM_BLE_CONN_EST_SCAN_WIND_LO);
541 }
542 /*******************************************************************************
543 **
544 ** Function         btm_ble_resume_bg_conn
545 **
546 ** Description      This function is to resume a background auto connection
547 **                  procedure.
548 **
549 ** Parameters       none.
550 **
551 ** Returns          none.
552 **
553 *******************************************************************************/
btm_ble_resume_bg_conn(tBTM_BLE_SEL_CBACK * p_sele_callback,BOOLEAN def_param)554 BOOLEAN btm_ble_resume_bg_conn(tBTM_BLE_SEL_CBACK *p_sele_callback, BOOLEAN def_param)
555 {
556     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
557     BOOLEAN ret = FALSE;
558 
559     if (p_cb->bg_conn_state != BLE_BG_CONN_ACTIVE )
560     {
561         if (def_param)
562         {
563             p_cb->scan_int = BTM_BLE_CONN_PARAM_UNDEF;
564             p_cb->scan_win = BTM_BLE_CONN_PARAM_UNDEF;
565 
566             /* start scan param idle timer */
567             btu_start_timer(&p_cb->scan_param_idle_timer,
568                             BTU_TTYPE_BLE_SCAN_PARAM_IDLE,
569                             BTM_BLE_SCAN_PARAM_TOUT);
570         }
571 
572         if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO)
573             ret = btm_ble_start_auto_conn(TRUE);
574 
575         if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE)
576         {
577             /* terminate selective connection mode if all devices are connected */
578             if (btm_ble_count_unconn_dev_in_whitelist() == 0)
579             {
580                 btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_DISABLE);
581                 btm_cb.ble_ctr_cb.inq_var.proc_mode = BTM_BLE_INQUIRY_NONE;
582                 btm_cb.btm_inq_vars.inq_active = FALSE;
583             }
584             else if (!btm_cb.btm_inq_vars.inq_active)
585                 btm_ble_start_select_conn(TRUE, btm_cb.ble_ctr_cb.p_select_cback);
586         }
587 
588         if (ret)
589             p_cb->bg_conn_state = BLE_BG_CONN_ACTIVE;
590 
591     }
592 
593     return ret;
594 }
595 /*******************************************************************************
596 **
597 ** Function         btm_ble_update_bg_state
598 **
599 ** Description      This function is to update the bg connection status.
600 **
601 ** Parameters       none.
602 **
603 ** Returns          none.
604 **
605 *******************************************************************************/
btm_ble_update_bg_state(void)606 void btm_ble_update_bg_state(void)
607 {
608     tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
609 
610     if (!l2cb.is_ble_connecting && (p_cb->bg_conn_state != BLE_BG_CONN_SUSPEND))
611         p_cb->bg_conn_state = BLE_BG_CONN_IDLE;
612 
613 }
614 
615 #endif
616 
617