From 804f939ed03671925e80417424e9eb8f06a712fc Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Thu, 30 Nov 2023 10:41:48 +0800 Subject: [PATCH 1/4] docs(bt/bluedroid): Update ble example document --- .../gatt_server_service_table/main/gatts_table_creat_demo.c | 5 +++++ .../Gatt_Server_Service_Table_Example_Walkthrough.md | 1 + 2 files changed, 6 insertions(+) diff --git a/examples/bluetooth/bluedroid/ble/gatt_server_service_table/main/gatts_table_creat_demo.c b/examples/bluetooth/bluedroid/ble/gatt_server_service_table/main/gatts_table_creat_demo.c index 982927ef3bd8..cc43d728cc03 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_server_service_table/main/gatts_table_creat_demo.c +++ b/examples/bluetooth/bluedroid/ble/gatt_server_service_table/main/gatts_table_creat_demo.c @@ -403,6 +403,11 @@ static void gatts_profile_event_handler(esp_gatts_cb_event_t event, esp_gatt_if_ { indicate_data[i] = i % 0xff; } + + // if want to change the value in server database, call: + // esp_ble_gatts_set_attr_value(heart_rate_handle_table[IDX_CHAR_VAL_A], sizeof(indicate_data), indicate_data); + + //the size of indicate_data[] need less than MTU size esp_ble_gatts_send_indicate(gatts_if, param->write.conn_id, heart_rate_handle_table[IDX_CHAR_VAL_A], sizeof(indicate_data), indicate_data, true); diff --git a/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md b/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md index 7db332db2a09..623043e71325 100644 --- a/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md +++ b/examples/bluetooth/bluedroid/ble/gatt_server_service_table/tutorial/Gatt_Server_Service_Table_Example_Walkthrough.md @@ -159,6 +159,7 @@ The application registration takes place inside ``app_main()`` using the ``esp_b ```c esp_ble_gatts_app_register(ESP_HEART_RATE_APP_ID); ``` +The ``ESP_HEART_RATE_APP_ID`` serves as an application ID, distinguishing between various application layer callbacks. This identifier corresponds to the ``app_id`` found within the ``gatts_reg_evt_param`` in ESP_GATTS_REG_EVT. ## Setting GAP Parameters From 3d2daa08cc0814379cacd22fa446db008f826ac1 Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Thu, 30 Nov 2023 10:42:04 +0800 Subject: [PATCH 2/4] fix(bt/bluedroid): Fix bluedroid menuconfig --- components/bt/host/bluedroid/Kconfig.in | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/components/bt/host/bluedroid/Kconfig.in b/components/bt/host/bluedroid/Kconfig.in index 479d0d689750..78e94111c5f1 100644 --- a/components/bt/host/bluedroid/Kconfig.in +++ b/components/bt/host/bluedroid/Kconfig.in @@ -1051,7 +1051,7 @@ config BT_ACL_CONNECTIONS config BT_MULTI_CONNECTION_ENBALE bool "Enable BLE multi-conections" - depends on BT_BLUEDROID_ENABLED + depends on BT_BLE_ENABLED default y help Enable this option if there are multiple connections @@ -1072,7 +1072,7 @@ config BT_BLE_DYNAMIC_ENV_MEMORY config BT_BLE_HOST_QUEUE_CONG_CHECK bool "BLE queue congestion check" - depends on BT_BLUEDROID_ENABLED + depends on BT_BLE_ENABLED default n help When scanning and scan duplicate is not enabled, if there are a lot of adv packets around @@ -1097,7 +1097,7 @@ config BT_BLE_ACT_SCAN_REP_ADV_SCAN config BT_BLE_ESTAB_LINK_CONN_TOUT int "Timeout of BLE connection establishment" - depends on BT_BLUEDROID_ENABLED + depends on BT_BLE_ENABLED range 1 60 default 30 help @@ -1133,7 +1133,7 @@ config BT_BLE_RPA_SUPPORTED config BT_BLE_RPA_TIMEOUT int "Timeout of resolvable private address" - depends on BT_BLUEDROID_ENABLED + depends on BT_BLE_ENABLED range 1 3600 default 900 help @@ -1142,35 +1142,36 @@ config BT_BLE_RPA_TIMEOUT config BT_BLE_50_FEATURES_SUPPORTED bool "Enable BLE 5.0 features" - depends on (BT_BLUEDROID_ENABLED && ((BT_CONTROLLER_ENABLED && SOC_BLE_50_SUPPORTED) || BT_CONTROLLER_DISABLED)) + depends on (BT_BLE_ENABLED && ((BT_CONTROLLER_ENABLED && SOC_BLE_50_SUPPORTED) || BT_CONTROLLER_DISABLED)) default y help - This enables BLE 5.0 features, this option only support esp32c3/esp32s3 chip + Enabling this option activates BLE 5.0 features. + This option is universally supported in chips that support BLE, except for ESP32. config BT_BLE_42_FEATURES_SUPPORTED bool "Enable BLE 4.2 features" - depends on (BT_BLUEDROID_ENABLED && ((BT_CONTROLLER_ENABLED && SOC_BLE_SUPPORTED) || BT_CONTROLLER_DISABLED)) + depends on (BT_BLE_ENABLED && ((BT_CONTROLLER_ENABLED && SOC_BLE_SUPPORTED) || BT_CONTROLLER_DISABLED)) default n help This enables BLE 4.2 features. config BT_BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER bool "Enable BLE periodic advertising sync transfer feature" - depends on (BT_BLUEDROID_ENABLED && BT_BLE_50_FEATURES_SUPPORTED && ((BT_CONTROLLER_ENABLED && SOC_ESP_NIMBLE_CONTROLLER) || BT_CONTROLLER_DISABLED)) + depends on (BT_BLE_50_FEATURES_SUPPORTED && ((BT_CONTROLLER_ENABLED && SOC_ESP_NIMBLE_CONTROLLER) || BT_CONTROLLER_DISABLED)) default n help This enables BLE periodic advertising sync transfer feature config BT_BLE_FEAT_PERIODIC_ADV_ENH bool "Enable periodic adv enhancements(adi support)" - depends on (BT_BLUEDROID_ENABLED && BT_BLE_50_FEATURES_SUPPORTED && ((BT_CONTROLLER_ENABLED && SOC_ESP_NIMBLE_CONTROLLER) || BT_CONTROLLER_DISABLED)) + depends on (BT_BLE_50_FEATURES_SUPPORTED && ((BT_CONTROLLER_ENABLED && SOC_ESP_NIMBLE_CONTROLLER) || BT_CONTROLLER_DISABLED)) default n help Enable the periodic advertising enhancements config BT_BLE_HIGH_DUTY_ADV_INTERVAL bool "Enable BLE high duty advertising interval feature" - depends on BT_BLUEDROID_ENABLED + depends on BT_BLE_ENABLED default n help This enable BLE high duty advertising interval feature From 068a364a6b77dafeaa4e5e6a815465bce08cde41 Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Fri, 1 Dec 2023 16:55:40 +0800 Subject: [PATCH 3/4] fix(bt/bluedroid): Fix BLE SMP register log level --- components/bt/host/bluedroid/stack/smp/smp_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/bluedroid/stack/smp/smp_api.c b/components/bt/host/bluedroid/stack/smp/smp_api.c index df8f4cea213b..78e295f4f1f6 100644 --- a/components/bt/host/bluedroid/stack/smp/smp_api.c +++ b/components/bt/host/bluedroid/stack/smp/smp_api.c @@ -125,7 +125,7 @@ BOOLEAN SMP_Register (tSMP_CALLBACK *p_cback) SMP_TRACE_EVENT ("SMP_Register state=%d", smp_cb.state); if (smp_cb.p_callback != NULL) { - SMP_TRACE_ERROR ("SMP_Register: duplicate registration, overwrite it"); + SMP_TRACE_WARNING ("SMP_Register: duplicate registration, overwrite it"); } smp_cb.p_callback = p_cback; From 633dd89d4a2c71d2d4c873e07ef30fa2973a9f6a Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Fri, 3 Nov 2023 19:39:25 +0800 Subject: [PATCH 4/4] feat(bt/bluedroid): Support ble create sync report disable and filter duplicate --- components/bt/host/bluedroid/Kconfig.in | 7 ++++++ .../api/include/api/esp_gap_ble_api.h | 22 +++++++++++++----- .../host/bluedroid/bta/include/bta/bta_api.h | 4 ++++ .../btc/profile/std/gap/btc_gap_ble.c | 4 ++++ .../include/common/bluedroid_user_config.h | 6 +++++ .../common/include/common/bt_target.h | 6 +++++ .../host/bluedroid/stack/btm/btm_ble_5_gap.c | 23 +++++++++++++++++-- .../bt/host/bluedroid/stack/hcic/hciblecmds.c | 8 +++---- .../stack/include/stack/btm_ble_api.h | 4 ++++ .../Periodic_Sync_Example_Walkthrough.md | 23 +++++++++++++------ 10 files changed, 88 insertions(+), 19 deletions(-) diff --git a/components/bt/host/bluedroid/Kconfig.in b/components/bt/host/bluedroid/Kconfig.in index 78e94111c5f1..73f8a9cd7a80 100644 --- a/components/bt/host/bluedroid/Kconfig.in +++ b/components/bt/host/bluedroid/Kconfig.in @@ -1169,6 +1169,13 @@ config BT_BLE_FEAT_PERIODIC_ADV_ENH help Enable the periodic advertising enhancements +config BT_BLE_FEAT_CREATE_SYNC_ENH + bool "Enable create sync enhancements(reporting disable and duplicate filtering enable support)" + depends on (BT_BLE_50_FEATURES_SUPPORTED && ((BT_CONTROLLER_ENABLED && SOC_ESP_NIMBLE_CONTROLLER) || BT_CONTROLLER_DISABLED)) + default n + help + Enable the create sync enhancements + config BT_BLE_HIGH_DUTY_ADV_INTERVAL bool "Enable BLE high duty advertising interval feature" depends on BT_BLE_ENABLED diff --git a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h index faee853fd9fa..db995a078b13 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h @@ -904,12 +904,22 @@ typedef struct { * @brief periodic adv sync parameters */ typedef struct { - esp_ble_gap_sync_t filter_policy; /*!< periodic advertising sync filter policy */ - uint8_t sid; /*!< periodic advertising sid */ - esp_ble_addr_type_t addr_type; /*!< periodic advertising address type */ - esp_bd_addr_t addr; /*!< periodic advertising address */ - uint16_t skip; /*!< the maximum number of periodic advertising events that can be skipped */ - uint16_t sync_timeout; /*!< synchronization timeout */ + esp_ble_gap_sync_t filter_policy; /*!< Configures the filter policy for periodic advertising sync: + 0: Use Advertising SID, Advertiser Address Type, and Advertiser Address parameters to determine the advertiser to listen to. + 1: Use the Periodic Advertiser List to determine the advertiser to listen to. */ + #if (CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH) + esp_ble_gap_sync_t reports_disabled; /*!< Supported only by esp32c2, esp32c6, and esp32h2; can be set by menuconfig: + 0: Reporting initially enabled. + 1: Reporting initially disabled. */ + esp_ble_gap_sync_t filter_duplicates; /*!< Supported only by esp32c2, esp32c6, and esp32h2; can be set by menuconfig: + 0: Duplicate filtering initially disabled. + 1: Duplicate filtering initially enabled. */ + #endif + uint8_t sid; /*!< SID of the periodic advertising */ + esp_ble_addr_type_t addr_type; /*!< Address type of the periodic advertising */ + esp_bd_addr_t addr; /*!< Address of the periodic advertising */ + uint16_t skip; /*!< Maximum number of periodic advertising events that can be skipped */ + uint16_t sync_timeout; /*!< Synchronization timeout */ } esp_ble_gap_periodic_adv_sync_params_t; /** diff --git a/components/bt/host/bluedroid/bta/include/bta/bta_api.h b/components/bt/host/bluedroid/bta/include/bta/bta_api.h index 5ed4e9481615..f362176ed0dc 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_api.h @@ -1539,6 +1539,10 @@ typedef struct { typedef struct { UINT8 filter_policy; + #if (CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH) + UINT8 reports_disabled; + UINT8 filter_duplicates; + #endif UINT8 sid; tBLE_ADDR_TYPE addr_type; BD_ADDR addr; diff --git a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c index 99ef66ef7240..2e6c7b8d2507 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -2076,6 +2076,10 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) params.addr_type = arg_5->periodic_adv_create_sync.params.addr_type; params.skip = arg_5->periodic_adv_create_sync.params.skip; params.sync_timeout = arg_5->periodic_adv_create_sync.params.sync_timeout; + #if (CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH) + params.reports_disabled = arg_5->periodic_adv_create_sync.params.reports_disabled; + params.filter_duplicates = arg_5->periodic_adv_create_sync.params.filter_duplicates; + #endif memcpy(params.addr, arg_5->periodic_adv_create_sync.params.addr, sizeof(BD_ADDR)); BTC_TRACE_DEBUG("BTC_GAP_BLE_PERIODIC_ADV_CREATE_SYNC"); 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 101ae8006674..898978f6218c 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 @@ -136,6 +136,12 @@ #define UC_BT_BLE_FEAT_PERIODIC_ADV_ENH FALSE #endif +#ifdef CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH +#define UC_BT_BLE_FEAT_CREATE_SYNC_ENH CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH +#else +#define UC_BT_BLE_FEAT_CREATE_SYNC_ENH FALSE +#endif + #ifdef CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL #define UC_BT_BLE_HIGH_DUTY_ADV_INTERVAL CONFIG_BT_BLE_HIGH_DUTY_ADV_INTERVAL #else 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 21a728e247f6..cb87f02f22e1 100644 --- a/components/bt/host/bluedroid/common/include/common/bt_target.h +++ b/components/bt/host/bluedroid/common/include/common/bt_target.h @@ -213,6 +213,12 @@ #define BLE_FEAT_PERIODIC_ADV_ENH FALSE #endif +#if (UC_BT_BLE_FEAT_CREATE_SYNC_ENH == TRUE) +#define BLE_FEAT_CREATE_SYNC_ENH TRUE +#else +#define BLE_FEAT_CREATE_SYNC_ENH FALSE +#endif + #if (UC_BT_BLE_HIGH_DUTY_ADV_INTERVAL == TRUE) #define BLE_HIGH_DUTY_ADV_INTERVAL TRUE #else diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c index 2a4c9ce85e32..e5dc3b42ac1c 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c @@ -11,6 +11,7 @@ #include #include "l2c_int.h" #if (BLE_50_FEATURE_SUPPORT == TRUE) +#define SET_BIT(t, n) (t |= 1UL << (n)) tBTM_BLE_EXTENDED_CB extend_adv_cb; tBTM_BLE_5_HCI_CBACK ble_5_hci_cb; @@ -788,14 +789,32 @@ tBTM_STATUS BTM_BlePeriodicAdvCreateSync(tBTM_BLE_Periodic_Sync_Params *params) } if ((params->sync_timeout < 0x0a || params->sync_timeout > 0x4000) - || (params->filter_policy > 0x01) || (params->addr_type > 0x01) || + || (params->filter_policy > 0x01) + #if (CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH) + || (params->reports_disabled > 0x01) + || (params->filter_duplicates > 0x01) + #endif + || (params->addr_type > 0x01) || (params->sid > 0xf) || (params->skip > 0x01F3)) { status = BTM_ILLEGAL_VALUE; BTM_TRACE_ERROR("%s, The sync parameters is invalid.", __func__); goto end; } + uint8_t option = 0x00; + if (params->filter_policy) { + SET_BIT(option, 0); + } + + #if (CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH) + if (params->reports_disabled) { + SET_BIT(option, 1); + } + if (params->filter_duplicates) { + SET_BIT(option, 2); + } + #endif - if (!btsnd_hcic_ble_periodic_adv_create_sync(params->filter_policy, params->sid, params->addr_type, + if (!btsnd_hcic_ble_periodic_adv_create_sync(option, params->sid, params->addr_type, params->addr, params->sync_timeout, 0)) { BTM_TRACE_ERROR("LE PA CreateSync cmd failed"); status = BTM_ILLEGAL_VALUE; diff --git a/components/bt/host/bluedroid/stack/hcic/hciblecmds.c b/components/bt/host/bluedroid/stack/hcic/hciblecmds.c index 0324002792c6..0f6408f0826e 100644 --- a/components/bt/host/bluedroid/stack/hcic/hciblecmds.c +++ b/components/bt/host/bluedroid/stack/hcic/hciblecmds.c @@ -1627,14 +1627,14 @@ BOOLEAN btsnd_hcic_ble_create_ext_conn(tHCI_CreatExtConn *p_conn) } -BOOLEAN btsnd_hcic_ble_periodic_adv_create_sync(UINT8 filter_policy, UINT8 adv_sid, +BOOLEAN btsnd_hcic_ble_periodic_adv_create_sync(UINT8 option, UINT8 adv_sid, UINT8 adv_addr_type, BD_ADDR adv_addr, UINT16 sync_timeout, UINT8 unused) { BT_HDR *p; UINT8 *pp; - HCI_TRACE_EVENT("%s, filter_policy = %d, adv_sid = %d, adv_addr_type = %d, sync_timeout = %d, unused = %d", - __func__, filter_policy, adv_sid, adv_addr_type, sync_timeout, unused); + HCI_TRACE_EVENT("%s, option = %d, adv_sid = %d, adv_addr_type = %d, sync_timeout = %d, unused = %d", + __func__, option, adv_sid, adv_addr_type, sync_timeout, unused); HCI_TRACE_EVENT("addr %02x %02x %02x %02x %02x %02x", adv_addr[0], adv_addr[1], adv_addr[2], adv_addr[3], adv_addr[4], adv_addr[5]); uint16_t skip = 0; @@ -1642,7 +1642,7 @@ BOOLEAN btsnd_hcic_ble_periodic_adv_create_sync(UINT8 filter_policy, UINT8 adv_s UINT16_TO_STREAM(pp, HCI_BLE_PERIOD_ADV_CREATE_SYNC); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PERIODIC_ADV_CREATE_SYNC + 2); - UINT8_TO_STREAM(pp, filter_policy); + UINT8_TO_STREAM(pp, option); UINT8_TO_STREAM(pp, adv_sid); UINT8_TO_STREAM(pp, adv_addr_type); BDADDR_TO_STREAM(pp, adv_addr); diff --git a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h index f64500656bef..a3085361da1f 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h @@ -809,6 +809,10 @@ typedef struct { typedef struct { UINT8 filter_policy; + #if (CONFIG_BT_BLE_FEAT_CREATE_SYNC_ENH) + UINT8 reports_disabled; + UINT8 filter_duplicates; + #endif UINT8 sid; tBLE_ADDR_TYPE addr_type; BD_ADDR addr; diff --git a/examples/bluetooth/bluedroid/ble_50/peroidic_sync/tutorial/Periodic_Sync_Example_Walkthrough.md b/examples/bluetooth/bluedroid/ble_50/peroidic_sync/tutorial/Periodic_Sync_Example_Walkthrough.md index bba00bb45a9d..ab9e37407888 100644 --- a/examples/bluetooth/bluedroid/ble_50/peroidic_sync/tutorial/Periodic_Sync_Example_Walkthrough.md +++ b/examples/bluetooth/bluedroid/ble_50/peroidic_sync/tutorial/Periodic_Sync_Example_Walkthrough.md @@ -241,13 +241,22 @@ same for the periodic sync: * @brief periodic adv sync parameters */ typedef struct { - esp_ble_gap_sync_t filter_policy; /*!< periodic advertising sync filter policy */ - uint8_t sid; /*!< periodic advertising sid */ - esp_ble_addr_type_t addr_type; /*!< periodic advertising address type */ - esp_bd_addr_t addr; /*!< periodic advertising address */ - uint16_t skip; /*!< the maximum number of periodic advertising events t -hat can be skipped */ - uint16_t sync_timeout; /*!< synchronization timeout */ + esp_ble_gap_sync_t filter_policy; /*!< Configures the filter policy for periodic advertising sync: + 0: Use Advertising SID, Advertiser Address Type, and Advertiser Address parameters to determine the advertiser to listen to. + 1: Use the Periodic Advertiser List to determine the advertiser to listen to. */ + #if (BLE_FEAT_CREATE_SYNC_ENH) + esp_ble_gap_sync_t reports_disabled; /*!< Supported only by esp32c2, esp32c6, and esp32h2; can be set by menuconfig: + 0: Reporting initially enabled. + 1: Reporting initially disabled. */ + esp_ble_gap_sync_t filter_duplicates; /*!< Supported only by esp32c2, esp32c6, and esp32h2; can be set by menuconfig: + 0: Duplicate filtering initially disabled. + 1: Duplicate filtering initially enabled. */ + #endif + uint8_t sid; /*!< SID of the periodic advertising */ + esp_ble_addr_type_t addr_type; /*!< Address type of the periodic advertising */ + esp_bd_addr_t addr; /*!< Address of the periodic advertising */ + uint16_t skip; /*!< Maximum number of periodic advertising events that can be skipped */ + uint16_t sync_timeout; /*!< Synchronization timeout */ } esp_ble_gap_periodic_adv_sync_params_t; ```