summaryrefslogtreecommitdiffstats
path: root/stack/btm/btm_ble_bgconn.c
blob: aa002e8ef1e04a10f3a6db84c3227aee071de53f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
/******************************************************************************
 *
 *  Copyright (C) 1999-2012 Broadcom Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

/******************************************************************************
 *
 *  This file contains functions for BLE whitelist operation.
 *
 ******************************************************************************/

#include <string.h>

#include "bt_types.h"
#include "btu.h"
#include "btm_int.h"
#include "l2c_int.h"
#include "hcimsgs.h"

#ifndef BTM_BLE_SCAN_PARAM_TOUT
#define BTM_BLE_SCAN_PARAM_TOUT      50    /* 50 seconds */
#endif

#if (BLE_INCLUDED == TRUE)
/*******************************************************************************
**
** Function         btm_update_scanner_filter_policy
**
** Description      This function update the filter policy of scnner or advertiser.
*******************************************************************************/
void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy)
{
    tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var;
    BTM_TRACE_EVENT0 ("btm_update_scanner_filter_policy");
    btm_cb.ble_ctr_cb.inq_var.sfp = scan_policy;

    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),
                                    (UINT16)(!p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval),
                                    (UINT16)(!p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window),
                                     BLE_ADDR_PUBLIC,
                                     scan_policy);
}
/*******************************************************************************
**
** Function         btm_update_adv_filter_policy
**
** Description      This function update the filter policy of scnner or advertiser.
*******************************************************************************/
void btm_update_adv_filter_policy(tBTM_BLE_AFP adv_policy)
{
    tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var;
    BTM_TRACE_EVENT0 ("btm_update_adv_filter_policy");
    p_cb->afp = adv_policy;
}
/*******************************************************************************
**
** Function         btm_update_dev_to_white_list
**
** Description      This function adds a device into white list.
*******************************************************************************/
BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type)
{
    /* look up the sec device record, and find the address */
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    tBTM_SEC_DEV_REC    *p_dev_rec;
    BD_ADDR             dummy_bda = {0};
    BOOLEAN             started = FALSE, suspend = FALSE;

    if (btm_cb.btm_inq_vars.inq_active)
    {
        suspend = TRUE;
        btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE);
    }

    if ((p_dev_rec = btm_find_dev (bd_addr)) != NULL &&
        p_dev_rec->device_type == BT_DEVICE_TYPE_BLE)
    {
        BTM_TRACE_DEBUG0("btm_update_dev_to_white_list 1");

        if ((to_add && p_cb->num_empty_filter == 0) ||
            (!to_add && p_cb->num_empty_filter == p_cb->max_filter_entries))
        {
            BTM_TRACE_ERROR1("num_entry available in controller: %d", p_cb->num_empty_filter);
            return started;
        }


        if ( p_dev_rec->ble.ble_addr_type == BLE_ADDR_PUBLIC)
        {
            if (to_add)
                started = btsnd_hcic_ble_add_white_list (BLE_ADDR_PUBLIC, bd_addr);
            else
                started = btsnd_hcic_ble_remove_from_white_list (BLE_ADDR_PUBLIC, bd_addr);
        }
        else
        {
            if (BLE_ADDR_IS_STATIC(bd_addr))
            {
                if (to_add)
                    started = btsnd_hcic_ble_add_white_list (BLE_ADDR_RANDOM, bd_addr);
                else
                    started = btsnd_hcic_ble_remove_from_white_list (BLE_ADDR_RANDOM, bd_addr);

            }
            if (memcmp(p_dev_rec->ble.reconn_addr, dummy_bda, BD_ADDR_LEN) != 0)
            {
                if (to_add)
                    started = btsnd_hcic_ble_add_white_list (BLE_ADDR_RANDOM, p_dev_rec->ble.reconn_addr);
                else
                    started = btsnd_hcic_ble_remove_from_white_list (BLE_ADDR_RANDOM, p_dev_rec->ble.reconn_addr);
            }
        }
    }
    /* if not a known device, shall we add it? */
    else
    {
        if (to_add)
            started = btsnd_hcic_ble_add_white_list (addr_type, bd_addr);
        else
            started = btsnd_hcic_ble_remove_from_white_list (addr_type, bd_addr);
    }

    if (suspend)
    {
        btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, BTM_BLE_DUPLICATE_DISABLE);
    }

    return started;
}
/*******************************************************************************
**
** Function         btm_ble_clear_white_list
**
** Description      This function clears the white list.
*******************************************************************************/
void btm_ble_clear_white_list (void)
{
    BTM_TRACE_EVENT0 ("btm_ble_clear_white_list");
    btsnd_hcic_ble_clear_white_list();
}

/*******************************************************************************
**
** Function         btm_ble_clear_white_list_complete
**
** Description      This function clears the white list complete.
*******************************************************************************/
void btm_ble_clear_white_list_complete(UINT8 *p_data, UINT16 evt_len)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    UINT8       status;
    BTM_TRACE_EVENT0 ("btm_ble_clear_white_list_complete");
    STREAM_TO_UINT8  (status, p_data);

    if (status == HCI_SUCCESS)
        p_cb->num_empty_filter = p_cb->max_filter_entries;

}
/*******************************************************************************
**
** Function         btm_ble_add_2_white_list_complete
**
** Description      This function read the current white list size.
*******************************************************************************/
void btm_ble_add_2_white_list_complete(UINT8 *p, UINT16 evt_len)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    BTM_TRACE_EVENT0 ("btm_ble_add_2_white_list_complete");

    if (*p == HCI_SUCCESS)
    {
        p_cb->num_empty_filter --;
    }
}
/*******************************************************************************
**
** Function         btm_ble_add_2_white_list_complete
**
** Description      This function read the current white list size.
*******************************************************************************/
void btm_ble_remove_from_white_list_complete(UINT8 *p, UINT16 evt_len)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    BTM_TRACE_EVENT0 ("btm_ble_remove_from_white_list_complete");
    if (*p == HCI_SUCCESS)
    {
        p_cb->num_empty_filter ++;
    }
}
/*******************************************************************************
**
** Function         btm_ble_find_dev_in_whitelist
**
** Description      This function check if the device is in the white list
*******************************************************************************/
BOOLEAN btm_ble_find_dev_in_whitelist(BD_ADDR bd_addr)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    UINT8 i;

    BTM_TRACE_EVENT0 ("btm_ble_find_dev_in_whitelist");

    /* empty wl */
    if (p_cb->num_empty_filter == p_cb->max_filter_entries)
    {
        BTM_TRACE_DEBUG0("white list empty");
        return FALSE;
    }

    for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM && i < p_cb->max_filter_entries; i ++)
    {
        if (memcmp(p_cb->bg_conn_dev_list[i], bd_addr, BD_ADDR_LEN) == 0)
            return TRUE;
    }
    return FALSE;
}
/*******************************************************************************
**
** Function         btm_ble_count_unconn_dev_in_whitelist
**
** Description      This function check the number of unconnected device in white list.
*******************************************************************************/
UINT8 btm_ble_count_unconn_dev_in_whitelist(void)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    UINT8 count = 0, i;
    BD_ADDR dummy_bda ={0};

    BTM_TRACE_EVENT0 ("btm_ble_find_dev_in_whitelist");

    for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM && i < p_cb->max_filter_entries; i ++)
    {
        if (memcmp(p_cb->bg_conn_dev_list[i], dummy_bda, BD_ADDR_LEN) != 0 &&
            !BTM_IsAclConnectionUp(p_cb->bg_conn_dev_list[i]))
        {
            count ++;
        }
    }
    return count;
}
/*******************************************************************************
**
** Function         btm_update_bg_conn_list
**
** Description      This function update the local background connection device list.
*******************************************************************************/
BOOLEAN btm_update_bg_conn_list(BOOLEAN to_add, BD_ADDR bd_addr)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    UINT8 i;
    BD_ADDR dummy_bda = {0};
    BTM_TRACE_EVENT0 ("btm_update_bg_conn_list");
    if ((to_add && (p_cb->bg_conn_dev_num == BTM_BLE_MAX_BG_CONN_DEV_NUM || p_cb->num_empty_filter == 0)) ||
        (!to_add && p_cb->num_empty_filter == p_cb->max_filter_entries))
    {
        BTM_TRACE_DEBUG1("num_empty_filter = %d", p_cb->num_empty_filter);
        return FALSE;
    }

    for (i = 0; i < BTM_BLE_MAX_BG_CONN_DEV_NUM && i < p_cb->max_filter_entries; i ++)
    {
        /* to add */
        if (memcmp(p_cb->bg_conn_dev_list[i], dummy_bda, BD_ADDR_LEN) == 0 && to_add)
        {
            memcpy(p_cb->bg_conn_dev_list[i], bd_addr, BD_ADDR_LEN);
            p_cb->bg_conn_dev_num ++;
            return TRUE;
        }
        /* to remove */
        if (!to_add && memcmp(p_cb->bg_conn_dev_list[i], bd_addr, BD_ADDR_LEN) == 0)
        {
            memset(p_cb->bg_conn_dev_list[i], 0, BD_ADDR_LEN);
            p_cb->bg_conn_dev_num --;
            return TRUE;
        }
    }
    return FALSE;
}
/*******************************************************************************
**
** Function         btm_write_bg_conn_wl
**
** Description      This function write background connection device list into
**                  controller.
*******************************************************************************/
void btm_write_bg_conn_wl(void)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    UINT8       i;
    BTM_TRACE_EVENT0 ("btm_write_bg_conn_wl");
    btm_ble_clear_white_list();

    for (i = 0; i < p_cb->bg_conn_dev_num; i ++)
    {
        if (!btm_update_dev_to_white_list(TRUE, p_cb->bg_conn_dev_list[i], BLE_ADDR_PUBLIC))
            break;
    }
    return;
}
/*******************************************************************************
**
** Function         btm_ble_start_auto_conn
**
** Description      This function is to start/stop auto connection procedure.
**
** Parameters       start: TRUE to start; FALSE to stop.
**
** Returns          void
**
*******************************************************************************/
BOOLEAN btm_ble_start_auto_conn(BOOLEAN start)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    BD_ADDR dummy_bda = {0};
    BOOLEAN exec = TRUE;
    UINT16 scan_int, scan_win;

    scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_CONN_EST_SCAN_INT : p_cb->scan_int;
    scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_CONN_EST_SCAN_WIND : p_cb->scan_win;

    if (start)
    {
        if (!l2cb.is_ble_connecting &&
            btm_ble_count_unconn_dev_in_whitelist() > 0)
        {
            if (p_cb->bg_conn_state != BLE_BG_CONN_ACTIVE && p_cb->bg_conn_dev_num > 0)
            {
                if (!btsnd_hcic_ble_create_ll_conn (scan_int,  /* UINT16 scan_int      */
                                                    scan_win,    /* UINT16 scan_win      */
                                                    0x01,                   /* UINT8 white_list     */
                                                    BLE_ADDR_PUBLIC,        /* UINT8 addr_type_peer */
                                                    dummy_bda,              /* BD_ADDR bda_peer     */
                                                    BLE_ADDR_PUBLIC,         /* UINT8 addr_type_own  */
                                                    BTM_BLE_CONN_INT_MIN_DEF,   /* UINT16 conn_int_min  */
                                                    BTM_BLE_CONN_INT_MAX_DEF,   /* UINT16 conn_int_max  */
                                                    BTM_BLE_CONN_SLAVE_LATENCY_DEF,  /* UINT16 conn_latency  */
                                                    BTM_BLE_CONN_TIMEOUT_DEF,        /* UINT16 conn_timeout  */
                                                    0,                       /* UINT16 min_len       */
                                                    0))                      /* UINT16 max_len       */
                {
                    /* start auto connection failed */
                    exec =  FALSE;
                }
                else
                {
                    p_cb->bg_conn_state = BLE_BG_CONN_ACTIVE;
                }
            }
        }
        else
            exec = FALSE;
    }
    else
    {
        if (p_cb->bg_conn_state == BLE_BG_CONN_ACTIVE)
        {
            if (!btsnd_hcic_ble_create_conn_cancel())
                exec = FALSE;
            else
                p_cb->bg_conn_state = BLE_BG_CONN_IDLE;
        }
    }
    return exec;
}

/*******************************************************************************
**
** Function         btm_ble_start_select_conn
**
** Description      This function is to start/stop selective connection procedure.
**
** Parameters       start: TRUE to start; FALSE to stop.
**                  p_select_cback: callback function to return application
**                                  selection.
**
** Returns          BOOLEAN: selective connectino procedure is started.
**
*******************************************************************************/
BOOLEAN btm_ble_start_select_conn(BOOLEAN start,tBTM_BLE_SEL_CBACK   *p_select_cback)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    UINT16 scan_int, scan_win;

    BTM_TRACE_EVENT0 ("btm_ble_start_select_conn");

    scan_int = (p_cb->scan_int == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_CONN_EST_SCAN_INT : p_cb->scan_int;
    scan_win = (p_cb->scan_win == BTM_BLE_CONN_PARAM_UNDEF) ? BTM_BLE_CONN_EST_SCAN_WIND : p_cb->scan_win;

    if (start)
    {
        if (!btm_cb.btm_inq_vars.inq_active)
        {
            btm_cb.ble_ctr_cb.p_select_cback = p_select_cback;

            btm_update_scanner_filter_policy(SP_ADV_WL);

            if (!btsnd_hcic_ble_set_scan_params(BTM_BLE_SCAN_MODE_PASS,  /* use passive scan by default */
                                                scan_int, /* scan interval */
                                                scan_win,    /* scan window */
                                                BLE_ADDR_PUBLIC,         /* own device, DUMO always use public */
                                                SP_ADV_WL)              /* process advertising packets only from devices in the White List */
                )
                return FALSE;

            if (p_cb->inq_var.adv_mode == BTM_BLE_ADV_ENABLE)
            {
                BTM_TRACE_ERROR0("peripheral device cannot initiate a selective connection");
                return FALSE;
            }
            else if (p_cb->bg_conn_dev_num > 0 && btm_ble_count_unconn_dev_in_whitelist() > 0 )
            {

                if (!btsnd_hcic_ble_set_scan_enable(TRUE, TRUE)) /* duplicate filtering enabled */
                    return FALSE;

                /* mark up inquiry status flag */
                btm_cb.btm_inq_vars.inq_active = TRUE;
                btm_cb.ble_ctr_cb.inq_var.proc_mode = BTM_BLE_SELECT_SCAN;

                p_cb->bg_conn_state = BLE_BG_CONN_ACTIVE;

            }
        }
        else
        {
            BTM_TRACE_ERROR0("scan active, can not start selective connection procedure");
            return FALSE;
        }
    }
    else /* disable selective connection mode */
    {
        p_cb->p_select_cback = NULL;
        btm_cb.btm_inq_vars.inq_active = FALSE;
        btm_cb.ble_ctr_cb.inq_var.proc_mode = BTM_BLE_INQUIRY_NONE;

        btm_update_scanner_filter_policy(SP_ADV_ALL);

        /* stop scanning */
        if (p_cb->bg_conn_dev_num > 0)
        {
            if (!btsnd_hcic_ble_set_scan_enable(FALSE, TRUE)) /* duplicate filtering enabled */
                return FALSE;
        }
    }
    return TRUE;
}
/*******************************************************************************
**
** Function         btm_ble_initiate_select_conn
**
** Description      This function is to start/stop selective connection procedure.
**
** Parameters       start: TRUE to start; FALSE to stop.
**                  p_select_cback: callback function to return application
**                                  selection.
**
** Returns          BOOLEAN: selective connectino procedure is started.
**
*******************************************************************************/
void btm_ble_initiate_select_conn(BD_ADDR bda)
{
    UINT8   addr_type;
    BTM_TRACE_EVENT0 ("btm_ble_initiate_select_conn");
    addr_type = btm_ble_map_bda_to_conn_bda(bda);

    /* use direct connection procedure to initiate connection */
    if (!L2CA_ConnectFixedChnl(L2CAP_ATT_CID, bda))
    {
        BTM_TRACE_ERROR0("btm_ble_initiate_select_conn failed");
    }
}
/*******************************************************************************
**
** Function         btm_ble_suspend_bg_sele_conn
**
** Description      This function is to suspend an active background connection
**                  procedure.
**
** Parameters       none.
**
** Returns          none.
**
*******************************************************************************/
void btm_ble_suspend_bg_sele_conn(void)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    BTM_TRACE_EVENT0 ("btm_ble_suspend_bg_sele_conn");

    if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE)
    {
        p_cb->bg_conn_state = BLE_BG_CONN_SUSPEND;
        btm_ble_start_select_conn(FALSE, NULL);
    }
}
/*******************************************************************************
**
** Function         btm_ble_suspend_bg_conn
**
** Description      This function is to suspend an active background connection
**                  procedure.
**
** Parameters       none.
**
** Returns          none.
**
*******************************************************************************/
void btm_ble_suspend_bg_conn(void)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    BTM_TRACE_EVENT0 ("btm_ble_suspend_bg_conn");

    if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO)
    {
        if (btm_ble_start_auto_conn(FALSE))
            p_cb->bg_conn_state = BLE_BG_CONN_SUSPEND;
    }
}
/*******************************************************************************
**
** Function         btm_ble_scan_param_idle
**
** Description      This function is to process the scan parameter idle timeout
**                  timeout.
********************************************************************************/
void btm_ble_scan_param_idle(void)
{
    BTM_BleSetConnScanParams(BTM_BLE_CONN_EST_SCAN_INT_LO, BTM_BLE_CONN_EST_SCAN_WIND_LO);
}
/*******************************************************************************
**
** Function         btm_ble_resume_bg_conn
**
** Description      This function is to resume a background auto connection
**                  procedure.
**
** Parameters       none.
**
** Returns          none.
**
*******************************************************************************/
BOOLEAN btm_ble_resume_bg_conn(tBTM_BLE_SEL_CBACK *p_sele_callback, BOOLEAN def_param)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
    BOOLEAN ret = FALSE;

    if (p_cb->bg_conn_state != BLE_BG_CONN_ACTIVE )
    {
        if (def_param)
        {
            p_cb->scan_int = BTM_BLE_CONN_PARAM_UNDEF;
            p_cb->scan_win = BTM_BLE_CONN_PARAM_UNDEF;

            /* start scan param idle timer */
            btu_start_timer(&p_cb->scan_param_idle_timer,
                            BTU_TTYPE_BLE_SCAN_PARAM_IDLE,
                            BTM_BLE_SCAN_PARAM_TOUT);
        }

        if (p_cb->bg_conn_type == BTM_BLE_CONN_AUTO)
            ret = btm_ble_start_auto_conn(TRUE);

        if (p_cb->bg_conn_type == BTM_BLE_CONN_SELECTIVE)
        {
            /* terminate selective connection mode if all devices are connected */
            if (btm_ble_count_unconn_dev_in_whitelist() == 0)
            {
                btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_DISABLE);
                btm_cb.ble_ctr_cb.inq_var.proc_mode = BTM_BLE_INQUIRY_NONE;
                btm_cb.btm_inq_vars.inq_active = FALSE;
            }
            else if (!btm_cb.btm_inq_vars.inq_active)
                btm_ble_start_select_conn(TRUE, btm_cb.ble_ctr_cb.p_select_cback);
        }

        if (ret)
            p_cb->bg_conn_state = BLE_BG_CONN_ACTIVE;

    }

    return ret;
}
/*******************************************************************************
**
** Function         btm_ble_update_bg_state
**
** Description      This function is to update the bg connection status.
**
** Parameters       none.
**
** Returns          none.
**
*******************************************************************************/
void btm_ble_update_bg_state(void)
{
    tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;

    if (!l2cb.is_ble_connecting && (p_cb->bg_conn_state != BLE_BG_CONN_SUSPEND))
        p_cb->bg_conn_state = BLE_BG_CONN_IDLE;

}

#endif