From f14699068d2c2b4f61bc7ff24dd127de84995ae4 Mon Sep 17 00:00:00 2001 From: Yulong Date: Thu, 23 Nov 2017 03:54:29 -0500 Subject: [PATCH 1/3] component/bt: Fixed the bug when stop scan if not set back the scan params will lead to connection request sent the empty packet to the peer device. --- components/bt/bluedroid/stack/btm/btm_ble_gap.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index e5b50e0e2..c75971085 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -3192,7 +3192,7 @@ static void btm_ble_stop_discover(void) { tBTM_BLE_CB *p_ble_cb = & btm_cb.ble_ctr_cb; tBTM_CMPL_CB *p_scan_cb = p_ble_cb->p_scan_cmpl_cb; - + tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var; btu_stop_timer (&p_ble_cb->scan_timer_ent); p_ble_cb->scan_activity &= ~BTM_LE_DISCOVER_ACTIVE; @@ -3206,6 +3206,19 @@ static void btm_ble_stop_discover(void) btm_cb.ble_ctr_cb.inq_var.state = BTM_BLE_STOP_SCAN; /* stop discovery now */ btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE); + + if (p_inq->scan_params_set) { + /// set back the scan params to the controller after stop the scan + btsnd_hcic_ble_set_scan_params(p_inq->scan_type, p_inq->scan_interval, + p_inq->scan_window, + btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, + p_inq->sfp); + } else { + /// set the default value if the scan params not set yet + btm_update_scanner_filter_policy(SP_ADV_ALL); + + btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_SCAN; + } } if (p_scan_cb) { From 2458d15d2dfff298a2e80942aad084b4644af7f9 Mon Sep 17 00:00:00 2001 From: Yulong Date: Thu, 23 Nov 2017 06:36:00 -0500 Subject: [PATCH 2/3] component/bt: recovery the scan parameter to the controller before start scan. --- .../bt/bluedroid/stack/btm/btm_ble_gap.c | 52 ++++++++----------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index c75971085..292c92ef0 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -467,20 +467,6 @@ tBTM_STATUS BTM_BleScan(BOOLEAN start, UINT32 duration, /* enable resolving list */ btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); #endif - // if not set scan params, set defalult scan params - if (!p_inq->scan_params_set) - { - /* allow config of scan type */ - p_inq->scan_type = BTM_BLE_SCAN_MODE_ACTI; - p_inq->scan_interval = BTM_BLE_GAP_DISC_SCAN_INT; - p_inq->scan_window = BTM_BLE_GAP_DISC_SCAN_WIN; - p_inq->sfp = BTM_BLE_DEFAULT_SFP; - p_inq->scan_params_set = TRUE; - btsnd_hcic_ble_set_scan_params(p_inq->scan_type, p_inq->scan_interval, - p_inq->scan_window, - btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, - p_inq->sfp); - } p_inq->scan_duplicate_filter = BTM_BLE_DUPLICATE_DISABLE; status = btm_ble_start_scan(); } @@ -3061,6 +3047,25 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, UINT8 addr_type, UINT8 evt } } +static void btm_ble_recover_scan_params(void) +{ + tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var; + + if (p_inq->scan_params_set) { + /// set back the scan params to the controller after stop the scan + btsnd_hcic_ble_set_scan_params(p_inq->scan_type, p_inq->scan_interval, + p_inq->scan_window, + btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, + p_inq->sfp); + } else { + /// set the default value if the scan params not set yet + btm_update_scanner_filter_policy(SP_ADV_ALL); + + btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_SCAN; + } + +} + /******************************************************************************* ** ** Function btm_ble_start_scan @@ -3074,7 +3079,8 @@ tBTM_STATUS btm_ble_start_scan(void) { tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var; tBTM_STATUS status = BTM_CMD_STARTED; - + // recoverly the scan parameters to the controller before start scan + btm_ble_recover_scan_params(); /* start scan, disable duplicate filtering */ if (!btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, p_inq->scan_duplicate_filter)) { status = BTM_NO_RESOURCES; @@ -3192,7 +3198,6 @@ static void btm_ble_stop_discover(void) { tBTM_BLE_CB *p_ble_cb = & btm_cb.ble_ctr_cb; tBTM_CMPL_CB *p_scan_cb = p_ble_cb->p_scan_cmpl_cb; - tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var; btu_stop_timer (&p_ble_cb->scan_timer_ent); p_ble_cb->scan_activity &= ~BTM_LE_DISCOVER_ACTIVE; @@ -3206,19 +3211,8 @@ static void btm_ble_stop_discover(void) btm_cb.ble_ctr_cb.inq_var.state = BTM_BLE_STOP_SCAN; /* stop discovery now */ btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE); - - if (p_inq->scan_params_set) { - /// set back the scan params to the controller after stop the scan - btsnd_hcic_ble_set_scan_params(p_inq->scan_type, p_inq->scan_interval, - p_inq->scan_window, - btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, - p_inq->sfp); - } else { - /// set the default value if the scan params not set yet - btm_update_scanner_filter_policy(SP_ADV_ALL); - - btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_SCAN; - } + // recoverly the scan parameters to the controller after stop scan + btm_ble_recover_scan_params(); } if (p_scan_cb) { From 177c92f15e797a2a0fa8edac702bc03ee1ac5da8 Mon Sep 17 00:00:00 2001 From: Yulong Date: Thu, 23 Nov 2017 06:42:04 -0500 Subject: [PATCH 3/3] component/bt: Change the code format. --- components/bt/bluedroid/stack/btm/btm_ble_gap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index 292c92ef0..f8be10940 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -3054,9 +3054,9 @@ static void btm_ble_recover_scan_params(void) if (p_inq->scan_params_set) { /// set back the scan params to the controller after stop the scan btsnd_hcic_ble_set_scan_params(p_inq->scan_type, p_inq->scan_interval, - p_inq->scan_window, - btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, - p_inq->sfp); + p_inq->scan_window, + btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, + p_inq->sfp); } else { /// set the default value if the scan params not set yet btm_update_scanner_filter_policy(SP_ADV_ALL);