]> granicus.if.org Git - esp-idf/commitdiff
Component/bt: fix start adv
authorzhiweijian <zhiweijian@espressif.com>
Tue, 22 May 2018 12:13:53 +0000 (20:13 +0800)
committerzhiweijian <zhiweijian@espressif.com>
Wed, 30 May 2018 09:10:51 +0000 (17:10 +0800)
components/bt/bluedroid/stack/btm/btm_ble_gap.c
components/bt/bluedroid/stack/btm/btm_sec.c
components/bt/include/esp_bt.h

index 109a8168963a67507daf7a3ff7b932d6392833bb..a359b532f243ca45b7eebae9bc06591cf8257100 100644 (file)
@@ -3457,15 +3457,21 @@ tBTM_STATUS btm_ble_start_adv(void)
         btm_execute_wl_dev_operation();
         btm_cb.ble_ctr_cb.wl_state |= BTM_BLE_WL_ADV;
     }
-
+    /* The complete event comes up immediately after the 'btsnd_hcic_ble_set_adv_enable' being called in dual core, 
+    this causes the 'adv_mode' and 'state' not be set yet, so we set the state first */
+    tBTM_BLE_GAP_STATE temp_state = p_cb->state;
+    UINT8 adv_mode = p_cb->adv_mode;
+    p_cb->adv_mode = BTM_BLE_ADV_ENABLE;
+    p_cb->state = BTM_BLE_ADV_PENDING;
+    btm_ble_adv_states_operation(btm_ble_set_topology_mask, p_cb->evt_type);
     if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE)) {
-        p_cb->adv_mode = BTM_BLE_ADV_ENABLE;
-        p_cb->state = BTM_BLE_ADV_PENDING;
-        btm_ble_adv_states_operation(btm_ble_set_topology_mask, p_cb->evt_type);
         rt = BTM_SUCCESS;
         BTM_TRACE_EVENT ("BTM_SUCCESS\n");
     } else {
         p_cb->adv_mode = BTM_BLE_ADV_DISABLE;
+        p_cb->state = temp_state;
+        p_cb->adv_mode = adv_mode;
+        btm_ble_adv_states_operation(btm_ble_clear_topology_mask, p_cb->evt_type);
         btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_ADV;
     }
     return rt;
index 71d888902dc298cbbfdda5fa1cd5429621dd80b1..7b7f28ef441654778d93981f21c36039eb499bf6 100644 (file)
@@ -4046,7 +4046,10 @@ void btm_sec_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable)
                 p_dev_rec->sec_flags |= BTM_SEC_16_DIGIT_PIN_AUTHED;
             }
         } else {
-#if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE
+#if BLE_INCLUDED == TRUE
+            /* Before the application layer has received the connection event, the device has received an 
+            encrypted request from the peer device. The device should wait until the application layer 
+            receives the connection event before updating 'sec_flags'. */
             if ((p_tcb = gatt_find_tcb_by_addr(p_dev_rec->ble.pseudo_addr, BT_TRANSPORT_LE)) == NULL) {
                //do nothing
             } else
index 1fda81dad0b3017a6328afeaa35d97b86713d00e..28aa3cbdfbab37d8518a824551cb2cb780999f4a 100644 (file)
@@ -46,7 +46,7 @@ typedef struct {
 /* While scanning, if the free memory value in controller is less than SCAN_SEND_ADV_RESERVED_SIZE, 
 the adv packet will be discarded until the memory is restored. */
 #define SCAN_SEND_ADV_RESERVED_SIZE        1000
-/* open controller log debug when adv lost */
+/* enable controller log debug when adv lost */
 #define CONTROLLER_ADV_LOST_DEBUG_BIT      (0<<0)
 
 #ifdef CONFIG_BT_HCI_UART_NO