From c8e848b0ff083a3376284705ea1d76c56b37b48a Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Tue, 22 May 2018 20:13:53 +0800 Subject: [PATCH] Component/bt: fix start adv --- components/bt/bluedroid/stack/btm/btm_ble_gap.c | 14 ++++++++++---- components/bt/bluedroid/stack/btm/btm_sec.c | 5 ++++- components/bt/include/esp_bt.h | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index 109a816896..a359b532f2 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -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; diff --git a/components/bt/bluedroid/stack/btm/btm_sec.c b/components/bt/bluedroid/stack/btm/btm_sec.c index 71d888902d..7b7f28ef44 100644 --- a/components/bt/bluedroid/stack/btm/btm_sec.c +++ b/components/bt/bluedroid/stack/btm/btm_sec.c @@ -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 diff --git a/components/bt/include/esp_bt.h b/components/bt/include/esp_bt.h index 1fda81dad0..28aa3cbdfb 100644 --- a/components/bt/include/esp_bt.h +++ b/components/bt/include/esp_bt.h @@ -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 -- 2.50.1