]> granicus.if.org Git - esp-idf/commitdiff
component/bt: Fix the bug that sometimes received a ble connection & the adv will...
authorYulong <huangyulong@espressif.com>
Tue, 16 May 2017 07:10:16 +0000 (03:10 -0400)
committerYulong <huangyulong@espressif.com>
Tue, 16 May 2017 07:10:16 +0000 (03:10 -0400)
components/bt/bluedroid/stack/btm/btm_ble_gap.c
components/bt/bluedroid/stack/gatt/gatt_utils.c
components/bt/bluedroid/stack/include/btm_ble_api.h
components/bt/bluedroid/stack/include/btm_ble_int.h
components/bt/bluedroid/stack/l2cap/l2c_link.c

index dfa3b068d47c70b61ad8b3f388b01c1ba4558f5f..36778ed89720f5d97146216b7c74c30467c46b34 100644 (file)
@@ -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 */
index 6ece5e88f8768c17e9dcffa4dbc08aee944019a0..ac51e19662478b3d2926359cb25d54456be40aac 100644 (file)
@@ -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 ");
 }
 /*******************************************************************************
 **
index 4d3f5f889afa51de8d9f4999bc80c3030ed0d140..3a9d23a2a5c6a6cfed1f6d81778bd7aeee15c04d 100644 (file)
@@ -1532,6 +1532,8 @@ UINT16 BTM_BleReadDiscoverability();
 //extern
 UINT16 BTM_BleReadConnectability ();
 
+void BTM_Recovery_Pre_State(void);
+
 /*******************************************************************************
 **
 ** Function         BTM_ReadDevInfo
index 8345777c1a8ca5448be848846bfb9f4caa1cde77..055591d77456ad4f250c04500f6cfdf92c26effb 100644 (file)
@@ -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;
 
index 14c56c56ecd83e827451534fc29a52f597f29699..72dc20774022e4203803343292804667e048de0a 100644 (file)
@@ -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);
-        }\r
+        }
 #endif  ///SMP_INCLUDED == TRUE
     }
 }