From 7143d13f7a953bbbf8eb9f6a7216bfc2c05fec9d Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Tue, 14 Jan 2020 17:41:45 +0800 Subject: [PATCH 1/2] Component/bt: Fix GATTC trigger open event multiple times --- .../bt/bluedroid/bta/gatt/bta_gattc_act.c | 2 ++ .../bt/bluedroid/bta/gatt/bta_gattc_utils.c | 24 +++++++++++++++++++ .../bta/gatt/include/bta_gattc_int.h | 1 + 3 files changed, 27 insertions(+) diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c index 6001c8e9b..1a20e5d44 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c @@ -745,6 +745,8 @@ void bta_gattc_conncback(tBTA_GATTC_RCB *p_rcb, tBTA_GATTC_DATA *p_data) void bta_gattc_disconncback(tBTA_GATTC_RCB *p_rcb, tBTA_GATTC_DATA *p_data) { if (p_rcb) { + // Clear up the notification registration information by BD_ADDR + bta_gattc_clear_notif_registration_by_bda(p_rcb, p_data->int_conn.remote_bda); bta_gattc_send_disconnect_cback(p_rcb, p_data->int_conn.reason, p_data->int_conn.remote_bda, diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c b/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c index 001f78247..d2eaba0d6 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_utils.c @@ -596,6 +596,30 @@ void bta_gattc_clear_notif_registration(tBTA_GATTC_SERV *p_srcb, UINT16 conn_id, return; } +/******************************************************************************* +** +** Function bta_gattc_clear_notif_registration_by_bda +** +** Description Clear up the notification registration information by BD_ADDR. +** +** +** Returns None. +** +*******************************************************************************/ +void bta_gattc_clear_notif_registration_by_bda(tBTA_GATTC_RCB *p_clrcb, BD_ADDR remote_bda) +{ + if(p_clrcb == NULL) { + return; + } + for (uint8_t i = 0 ; i < BTA_GATTC_NOTIF_REG_MAX; i ++) { + if (p_clrcb->notif_reg[i].in_use && + !bdcmp(p_clrcb->notif_reg[i].remote_bda, remote_bda)) + { + memset(&p_clrcb->notif_reg[i], 0, sizeof(tBTA_GATTC_NOTIF_REG)); + } + } +} + /******************************************************************************* ** ** Function bta_gattc_mark_bg_conn diff --git a/components/bt/bluedroid/bta/gatt/include/bta_gattc_int.h b/components/bt/bluedroid/bta/gatt/include/bta_gattc_int.h index 68887f089..8cc8c402e 100644 --- a/components/bt/bluedroid/bta/gatt/include/bta_gattc_int.h +++ b/components/bt/bluedroid/bta/gatt/include/bta_gattc_int.h @@ -491,6 +491,7 @@ extern BOOLEAN bta_gattc_mark_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR_PTR rem extern BOOLEAN bta_gattc_check_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, UINT8 role); extern UINT8 bta_gattc_num_reg_app(void); extern void bta_gattc_clear_notif_registration(tBTA_GATTC_SERV *p_srcb, UINT16 conn_id, UINT16 start_handle, UINT16 end_handle); +extern void bta_gattc_clear_notif_registration_by_bda(tBTA_GATTC_RCB *p_clrcb, BD_ADDR remote_bda); extern tBTA_GATTC_SERV * bta_gattc_find_srvr_cache(BD_ADDR bda); /* discovery functions */ From 0a84fe593d9999e281d1a3cf4a886b809e04459c Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Tue, 14 Jan 2020 17:45:40 +0800 Subject: [PATCH 2/2] component/bt: fix blufi prepare write buf len invalid --- components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c b/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c index 45c220b3b..d9c0375cd 100644 --- a/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c +++ b/components/bt/bluedroid/btc/profile/esp/blufi/blufi_prf.c @@ -147,6 +147,7 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) if (blufi_env.prepare_buf == NULL) { blufi_env.prepare_buf = osi_malloc(BLUFI_PREPAIR_BUF_MAX_SIZE); + blufi_env.prepare_len = 0; if (blufi_env.prepare_buf == NULL) { BLUFI_TRACE_ERROR("Blufi prep no mem\n"); status = GATT_NO_RESOURCES; @@ -174,6 +175,7 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) if (blufi_env.prepare_buf) { osi_free(blufi_env.prepare_buf); blufi_env.prepare_buf = NULL; + blufi_env.prepare_len = 0; } BLUFI_TRACE_ERROR("write data error , error code 0x%x\n", status); return; @@ -209,6 +211,7 @@ static void blufi_profile_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) if (blufi_env.prepare_buf) { osi_free(blufi_env.prepare_buf); blufi_env.prepare_buf = NULL; + blufi_env.prepare_len = 0; } break;