From e797cd03f0abf19308fbbf768be23cb7022ae2d3 Mon Sep 17 00:00:00 2001 From: Yulong Date: Tue, 16 May 2017 03:10:16 -0400 Subject: [PATCH] component/bt: Fix the bug that sometimes received a ble connection & the adv will stop, can not send adv again. --- .../bt/bluedroid/stack/btm/btm_ble_gap.c | 19 ++++++++++++++++++- .../bt/bluedroid/stack/gatt/gatt_utils.c | 4 +++- .../bt/bluedroid/stack/include/btm_ble_api.h | 2 ++ .../bt/bluedroid/stack/include/btm_ble_int.h | 11 ++++++++++- .../bt/bluedroid/stack/l2cap/l2c_link.c | 4 ++-- 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index dfa3b068d..36778ed89 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -1484,6 +1484,20 @@ UINT16 BTM_BleReadConnectability() return (btm_cb.ble_ctr_cb.inq_var.connectable_mode); } +void BTM_Recovery_Pre_State(void) +{ + tBTM_BLE_INQ_CB *ble_inq_cb = &btm_cb.ble_ctr_cb.inq_var; + + if (ble_inq_cb->state == BTM_BLE_ADVERTISING) { + btm_ble_stop_adv(); + btm_ble_start_adv(); + } else if (ble_inq_cb->state == BTM_BLE_SCANNING) { + btm_ble_start_scan(); + } + + return; +} + /******************************************************************************* ** ** Function btm_ble_build_adv_data @@ -2954,6 +2968,7 @@ tBTM_STATUS btm_ble_start_scan(void) if (!btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, p_inq->scan_duplicate_filter)) { status = BTM_NO_RESOURCES; } else { + btm_cb.ble_ctr_cb.inq_var.state = BTM_BLE_SCANNING; if (p_inq->scan_type == BTM_BLE_SCAN_MODE_ACTI) { btm_ble_set_topology_mask(BTM_BLE_STATE_ACTIVE_SCAN_BIT); } else { @@ -2980,7 +2995,7 @@ void btm_ble_stop_scan(void) if (btm_cb.ble_ctr_cb.inq_var.adv_mode == BTM_BLE_ADV_DISABLE) { /* Clear the inquiry callback if set */ btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE; - + 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); @@ -3136,6 +3151,7 @@ tBTM_STATUS btm_ble_start_adv(void) if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE)) { p_cb->adv_mode = BTM_BLE_ADV_ENABLE; + p_cb->state = BTM_BLE_ADVERTISING; btm_ble_adv_states_operation(btm_ble_set_topology_mask, p_cb->evt_type); rt = BTM_SUCCESS; BTM_TRACE_EVENT ("BTM_SUCCESS\n"); @@ -3166,6 +3182,7 @@ tBTM_STATUS btm_ble_stop_adv(void) if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_DISABLE)) { p_cb->fast_adv_on = FALSE; p_cb->adv_mode = BTM_BLE_ADV_DISABLE; + p_cb->state = BTM_BLE_STOP_ADV; btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_ADV; /* clear all adv states */ diff --git a/components/bt/bluedroid/stack/gatt/gatt_utils.c b/components/bt/bluedroid/stack/gatt/gatt_utils.c index 6ece5e88f..ac51e1966 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_utils.c +++ b/components/bt/bluedroid/stack/gatt/gatt_utils.c @@ -2184,8 +2184,10 @@ void gatt_cleanup_upon_disc(BD_ADDR bda, UINT16 reason, tBT_TRANSPORT transport) } memset(p_tcb, 0, sizeof(tGATT_TCB)); + } else { + GATT_TRACE_DEBUG ("exit gatt_cleanup_upon_disc "); + BTM_Recovery_Pre_State(); } - GATT_TRACE_DEBUG ("exit gatt_cleanup_upon_disc "); } /******************************************************************************* ** diff --git a/components/bt/bluedroid/stack/include/btm_ble_api.h b/components/bt/bluedroid/stack/include/btm_ble_api.h index 4d3f5f889..3a9d23a2a 100644 --- a/components/bt/bluedroid/stack/include/btm_ble_api.h +++ b/components/bt/bluedroid/stack/include/btm_ble_api.h @@ -1532,6 +1532,8 @@ UINT16 BTM_BleReadDiscoverability(); //extern UINT16 BTM_BleReadConnectability (); +void BTM_Recovery_Pre_State(void); + /******************************************************************************* ** ** Function BTM_ReadDevInfo diff --git a/components/bt/bluedroid/stack/include/btm_ble_int.h b/components/bt/bluedroid/stack/include/btm_ble_int.h index 8345777c1..055591d77 100644 --- a/components/bt/bluedroid/stack/include/btm_ble_int.h +++ b/components/bt/bluedroid/stack/include/btm_ble_int.h @@ -101,6 +101,15 @@ typedef UINT8 tBTM_BLE_SEC_REQ_ACT; #define BTM_VSC_CHIP_CAPABILITY_L_VERSION 55 #define BTM_VSC_CHIP_CAPABILITY_M_VERSION 95 +typedef enum { + BTM_BLE_SCANNING, + BTM_BLE_SCAN_PENDING, + BTM_BLE_STOP_SCAN, + BTM_BLE_ADVERTISING, + BTM_BLE_ADV_PENDING, + BTM_BLE_STOP_ADV, +}tBTM_BLE_GAP_STATE; + typedef struct { UINT16 data_mask; UINT8 *p_flags; @@ -155,7 +164,7 @@ typedef struct { TIMER_LIST_ENT inq_timer_ent; BOOLEAN scan_rsp; - UINT8 state; /* Current state that the inquiry process is in */ + tBTM_BLE_GAP_STATE state; /* Current state that the inquiry process is in */ INT8 tx_power; } tBTM_BLE_INQ_CB; diff --git a/components/bt/bluedroid/stack/l2cap/l2c_link.c b/components/bt/bluedroid/stack/l2cap/l2c_link.c index 14c56c56e..72dc20774 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_link.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_link.c @@ -356,9 +356,9 @@ BOOLEAN l2c_link_hci_disc_comp (UINT16 handle, UINT8 reason) /* See if we have a link control block for the connection */ p_lcb = l2cu_find_lcb_by_handle (handle); - /* If we don't have one, maybe an SCO link. Send to MM */ if (!p_lcb) { + BTM_Recovery_Pre_State(); status = FALSE; } else { /* There can be a case when we rejected PIN code authentication */ @@ -613,7 +613,7 @@ void l2c_link_timeout (tL2C_LCB *p_lcb) } else { /* Check in case we were flow controlled */ l2c_link_check_send_pkts (p_lcb, NULL, NULL); - } + } #endif ///SMP_INCLUDED == TRUE } }