From 540b0131c2fea7ab86d353a764caa3274a4898d4 Mon Sep 17 00:00:00 2001 From: linruihao Date: Mon, 17 Feb 2025 11:42:33 +0800 Subject: [PATCH] feat(bt/bluedroid): Add Kconfig option to keep device bonding info when HID unplugging --- components/bt/host/bluedroid/Kconfig.in | 8 ++++++++ .../bt/host/bluedroid/btc/profile/std/hid/btc_hd.c | 12 ++++-------- .../bt/host/bluedroid/btc/profile/std/hid/btc_hh.c | 6 +++++- .../common/include/common/bluedroid_user_config.h | 7 +++++++ .../host/bluedroid/common/include/common/bt_target.h | 8 ++++++++ 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/components/bt/host/bluedroid/Kconfig.in b/components/bt/host/bluedroid/Kconfig.in index d9fa589123..80a4cf5dd0 100644 --- a/components/bt/host/bluedroid/Kconfig.in +++ b/components/bt/host/bluedroid/Kconfig.in @@ -192,6 +192,14 @@ config BT_HID_DEVICE_ENABLED help This enables the BT HID Device +config BT_HID_REMOVE_DEVICE_BONDING_ENABLED + bool "Remove Device Bonding Information when HID Virtual Cable Unplugging" + depends on BT_HID_ENABLED + default y + help + This enables the BT HID to remove device bonding information when virtual cable unplugging, + removing device bonding information is optional in HID 1.0 but mandatory in HID 1.1 + menuconfig BT_PBAC_ENABLED bool "PBAP Client" depends on BT_CLASSIC_ENABLED diff --git a/components/bt/host/bluedroid/btc/profile/std/hid/btc_hd.c b/components/bt/host/bluedroid/btc/profile/std/hid/btc_hd.c index 0d99c030b6..3bb4ff5c83 100644 --- a/components/bt/host/bluedroid/btc/profile/std/hid/btc_hd.c +++ b/components/bt/host/bluedroid/btc/profile/std/hid/btc_hd.c @@ -903,14 +903,10 @@ void btc_hd_cb_handler(btc_msg_t *msg) btc_hd_cb_to_app(ESP_HIDD_INTR_DATA_EVT, ¶m); break; case BTA_HD_VC_UNPLUG_EVT: { - bt_bdaddr_t *bd_addr = (bt_bdaddr_t *)&p_data->conn.bda; - if (bta_dm_check_if_only_hd_connected(p_data->conn.bda)) { - BTC_TRACE_DEBUG("%s: Removing bonding as only HID profile connected", __func__); - BTA_DmRemoveDevice((uint8_t *)&p_data->conn.bda, BT_TRANSPORT_BR_EDR); - } else { - BTC_TRACE_DEBUG("%s: Only removing HID data as some other profiles connected", __func__); - btc_hd_remove_device(*bd_addr); - } +#if BTC_HID_REMOVE_DEVICE_BONDING + BTC_TRACE_DEBUG("%s: Removing bonding information", __func__); + BTA_DmRemoveDevice((uint8_t *)&p_data->conn.bda, BT_TRANSPORT_BR_EDR); +#endif if (btc_hd_cb.status == BTC_HD_DISCONNECTING || btc_hd_cb.status == BTC_HD_CONNECTING || btc_hd_cb.status == BTC_HD_CONNECTED) { diff --git a/components/bt/host/bluedroid/btc/profile/std/hid/btc_hh.c b/components/bt/host/bluedroid/btc/profile/std/hid/btc_hh.c index 1d6f20201e..1b02b33286 100644 --- a/components/bt/host/bluedroid/btc/profile/std/hid/btc_hh.c +++ b/components/bt/host/bluedroid/btc/profile/std/hid/btc_hh.c @@ -1372,7 +1372,10 @@ void btc_hh_cb_handler(btc_msg_t *msg) */ if (p_dev->local_vup) { p_dev->local_vup = false; +#if BTC_HID_REMOVE_DEVICE_BONDING BTA_DmRemoveDevice(p_dev->bd_addr, BT_TRANSPORT_BR_EDR); +#endif + btc_hh_remove_device(p_dev->bd_addr); } btc_hh_cb.status = (BTC_HH_STATUS)BTC_HH_DEV_DISCONNECTED; @@ -1406,8 +1409,9 @@ void btc_hh_cb_handler(btc_msg_t *msg) // [boblane] if (p_dev->local_vup) { p_dev->local_vup = false; +#if BTC_HID_REMOVE_DEVICE_BONDING BTA_DmRemoveDevice(p_dev->bd_addr, BT_TRANSPORT_BR_EDR); - } else { +#endif btc_hh_remove_device(p_dev->bd_addr); } param.unplug.status = p_data->dev_status.status; diff --git a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h index 2f109219d5..e3d824000f 100644 --- a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h +++ b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h @@ -108,6 +108,13 @@ #define UC_BT_HID_DEVICE_ENABLED FALSE #endif +//HID remove device bonding option +#ifdef CONFIG_BT_HID_REMOVE_DEVICE_BONDING_ENABLED +#define UC_BT_HID_REMOVE_DEVICE_BONDING_ENABLED CONFIG_BT_HID_REMOVE_DEVICE_BONDING_ENABLED +#else +#define UC_BT_HID_REMOVE_DEVICE_BONDING_ENABLED FALSE +#endif + //BQB(BT) #ifdef CONFIG_BT_CLASSIC_BQB_ENABLED #define UC_BT_CLASSIC_BQB_ENABLED CONFIG_BT_CLASSIC_BQB_ENABLED diff --git a/components/bt/host/bluedroid/common/include/common/bt_target.h b/components/bt/host/bluedroid/common/include/common/bt_target.h index c7dff7606d..efc5f3e92d 100644 --- a/components/bt/host/bluedroid/common/include/common/bt_target.h +++ b/components/bt/host/bluedroid/common/include/common/bt_target.h @@ -176,6 +176,10 @@ #define BTC_HD_INCLUDED TRUE #endif /* UC_BT_HID_DEVICE_ENABLED */ +#if UC_BT_HID_REMOVE_DEVICE_BONDING_ENABLED +#define BTC_HID_REMOVE_DEVICE_BONDING TRUE +#endif + #if UC_BT_GOEPC_ENABLED #ifndef RFCOMM_INCLUDED #define RFCOMM_INCLUDED TRUE @@ -433,6 +437,10 @@ #define BTC_HD_INCLUDED FALSE #endif +#ifndef BTC_HID_REMOVE_DEVICE_BONDING +#define BTC_HID_REMOVE_DEVICE_BONDING FALSE +#endif + #ifndef SBC_DEC_INCLUDED #define SBC_DEC_INCLUDED FALSE #endif