From ae6d5f8c297df61d38938f9312e547a9830a94d4 Mon Sep 17 00:00:00 2001 From: Zhang Hai Peng Date: Mon, 17 Feb 2025 11:14:37 +0800 Subject: [PATCH 1/5] fix(ble/bluedroid): Allow 0 length indications (cherry picked from commit 9b5a52e2f784a50c0e4c1a422a2b3d22ce5e9998) Co-authored-by: Nebojsa Cvetkovic --- components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c b/components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c index 6795c00939..a5c2fc1f64 100644 --- a/components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c +++ b/components/bt/host/bluedroid/bta/gatt/bta_gatts_act.c @@ -723,10 +723,6 @@ void bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg) } else { APPL_TRACE_ERROR("%s, malloc failed", __func__); } - } else { - if (p_msg->api_indicate.value) { - APPL_TRACE_ERROR("%s, incorrect length", __func__); - } } (*p_rcb->p_cback)(BTA_GATTS_CONF_EVT, &cb_data); if (cb_data.req_data.value != NULL) { From 358020ad8f3f79e8a08ed5fd885b0159b9cf81a7 Mon Sep 17 00:00:00 2001 From: Zhang Hai Peng Date: Mon, 17 Feb 2025 11:14:42 +0800 Subject: [PATCH 2/5] fix(ble/bluedroid): Don't log error on 16/128-bit UUID mixed descriptors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit fed1d41aa7170d8418dd126dd8e3b47a977b4aca) Co-authored-by: Nebojša Cvetković --- components/bt/host/bluedroid/stack/gatt/gatt_sr.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/components/bt/host/bluedroid/stack/gatt/gatt_sr.c b/components/bt/host/bluedroid/stack/gatt/gatt_sr.c index 79e161c1e3..a8a1531f87 100644 --- a/components/bt/host/bluedroid/stack/gatt/gatt_sr.c +++ b/components/bt/host/bluedroid/stack/gatt/gatt_sr.c @@ -788,7 +788,7 @@ static tGATT_STATUS gatt_build_primary_service_rsp (BT_HDR *p_msg, tGATT_TCB *p_ ** buffer. ** ** Returns TRUE: if data filled successfully. -** FALSE: packet full, or format mismatch. +** FALSE: packet full. ** *******************************************************************************/ static tGATT_STATUS gatt_build_find_info_rsp(tGATT_SR_REG *p_rcb, BT_HDR *p_msg, UINT16 *p_len, @@ -831,10 +831,9 @@ static tGATT_STATUS gatt_build_find_info_rsp(tGATT_SR_REG *p_rcb, BT_HDR *p_msg, gatt_convert_uuid32_to_uuid128(p, ((tGATT_ATTR32 *) p_attr)->uuid); p += LEN_UUID_128; } else { - GATT_TRACE_ERROR("format mismatch"); - status = GATT_NO_RESOURCES; + // UUID format mismatch in sequential attributes + // A new request will be sent with the starting handle of the next attribute break; - /* format mismatch */ } p_msg->len += info_pair_len[p_msg->offset - 1]; len -= info_pair_len[p_msg->offset - 1]; From fe57c1bfb956e87857bf8133f05c7ab2ff956932 Mon Sep 17 00:00:00 2001 From: Zhang Hai Peng Date: Mon, 17 Feb 2025 11:14:45 +0800 Subject: [PATCH 3/5] docs(ble/bluedroid): Optimize doc for implementation of a characteristic with 128 bit UUID MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit fa40d971a52e9eb66686ac3ae645fca2589f0807) Co-authored-by: Erast  <78802792+MatoiDev@users.noreply.github.com> --- ...erver_Service_Table_Example_Walkthrough.md | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) 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 a61f01661a..8327334e64 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 @@ -440,6 +440,46 @@ static const esp_gatts_attr_db_t heart_rate_gatt_db[HRS_IDX_NB] = }; ``` +### 128-bit UUID + +To add characteristics with 128-bit UUIDs, a similar approach is used, but with minor differences. + +Let's suppose we have the following UUID: `12345678-a1b2-c3d4-e5f6-9fafd205e457` and we want to assign it to +the `HRS_IDX_128_BIT_LEN_UUID_CHAR` characteristic we also have. + +Here is an example of how this can be done: + +- First, let's declare our UUID + +```c +static const uint8_t our_128_bit_uuid_characteristic_uuid[ESP_UUID_LEN_128] = { // ESP_UUID_LEN_128 defined as 16 + 0x57, 0xe4, 0x05, 0xd2, 0xaf, 0x9f, 0xf6, 0xe5, 0xd4, 0xc3, 0xb2, 0xa1, 0x78, 0x56, 0x34, 0x12 +}; +``` + +> ##### `0x57 0xe4 0x05 0xd2 0xaf 0x9f 0xf6 0xe5 0xd4 0xc3 0xb2 0xa1 0x78 0x56 0x34 0x12` - reversed version of the original UUID represented by uuid_byte_array. + +- Now, all we need is to set `uuid_length` to `ESP_UUID_LEN_128` in the *Characteristic Value* setup. + +> ##### Not to be confused with the *Characteristic Declaration*! + +```c +static const esp_gatts_attr_db_t heart_rate_gatt_db[HRS_IDX_NB] = +{ +<...> + // 128-bit UUID Characteristic Declaration + [HRS_IDX_128_BIT_LEN_UUID_CHAR] = + {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&character_declaration_uuid, ESP_GATT_PERM_READ, + CHAR_DECLARATION_SIZE,CHAR_DECLARATION_SIZE, (uint8_t *)&char_prop_notify}}, + + // 128-bit UUID Characteristic Value + [HRS_IDX_128_BIT_LEN_UUID_VAL] = + {{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_128, (uint8_t *)&our_128_bit_uuid_characteristic_uuid, ESP_GATT_PERM_READ, + THIS_CHAR_VAL_MAX_LEN,0, NULL}}, +<...> +}; +``` + ## Starting the Service When the attribute table is created, an ``ESP_GATTS_CREAT_ATTR_TAB_EVT`` event is triggered. This event has the following parameters: @@ -494,4 +534,3 @@ struct gatts_profile_inst { This document explains the work flow of the GATT Server Service Table example code that implements a Heart Rate Profile. This example begins by defining a table of attributes which include all the services and characteristics of the server, then it registers the Application Profile which triggers events that are used to configure GAP parameters and to create the service table. A service table is initialized with all the parameters required for each attribute and the service is started. This example shows a practical way of defining the server attributes by using a table instead of adding characteristic one by one. - From 2f9c756d745aff4431f8ddcd0b041b3d532f9d6a Mon Sep 17 00:00:00 2001 From: Zhang Hai Peng Date: Mon, 17 Feb 2025 11:15:46 +0800 Subject: [PATCH 4/5] feat(ble/bluedroid): Support change HID task size by Kconfig in HID example (cherry picked from commit d4b3a7e99d29150d9718415384db7ac5ae7673d5) Co-authored-by: Mitch Cairns --- components/esp_hid/Kconfig | 17 ++++++++++ components/esp_hid/include/esp_hid_common.h | 35 ++++++++++++--------- components/esp_hid/src/ble_hidd.c | 2 +- components/esp_hid/src/bt_hidd.c | 2 +- tools/ci/check_copyright_ignore.txt | 1 - 5 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 components/esp_hid/Kconfig diff --git a/components/esp_hid/Kconfig b/components/esp_hid/Kconfig new file mode 100644 index 0000000000..619042645c --- /dev/null +++ b/components/esp_hid/Kconfig @@ -0,0 +1,17 @@ +menu "ESP HID" + config ESPHID_TASK_SIZE_BT + int "Task stack size for ESP HID BR/EDR" + range 2048 10240 + default 2048 + help + This is the stack size for the BT HID task. + Default is 2048 bytes. + + config ESPHID_TASK_SIZE_BLE + int "Task stack size for ESP HID BLE" + range 2048 10240 + default 4096 + help + This is the stack size for the BLE HID task. + Default is 4096 bytes. +endmenu diff --git a/components/esp_hid/include/esp_hid_common.h b/components/esp_hid/include/esp_hid_common.h index d7582cbc84..d2ddb7dee2 100644 --- a/components/esp_hid/include/esp_hid_common.h +++ b/components/esp_hid/include/esp_hid_common.h @@ -1,16 +1,8 @@ -// Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #pragma once @@ -94,6 +86,19 @@ extern "C" { #define ESP_HID_CCC_NOTIFICATIONS_ENABLED 0x01 // Notifications enabled #define ESP_HID_CCC_INDICATIONS_ENABLED 0x02 // Indications enabled +/* HID Task Size configuration */ +#ifdef CONFIG_ESPHID_TASK_SIZE_BT +#define BT_HID_DEVICE_TASK_SIZE_BT CONFIG_ESPHID_TASK_SIZE_BT +#else +#define BT_HID_DEVICE_TASK_SIZE_BT 2048 +#endif + +#ifdef CONFIG_ESPHID_TASK_SIZE_BLE +#define BT_HID_DEVICE_TASK_SIZE_BLE CONFIG_ESPHID_TASK_SIZE_BLE +#else +#define BT_HID_DEVICE_TASK_SIZE_BLE 4096 +#endif + /* HID Transports */ typedef enum { ESP_HID_TRANSPORT_BT, @@ -203,8 +208,8 @@ esp_hid_report_map_t *esp_hid_parse_report_map(const uint8_t *hid_rm, size_t hid void esp_hid_free_report_map(esp_hid_report_map_t *map); /** - * @brief Calculate the HID Device usage type from the BLE Apperance - * @param appearance : BLE Apperance value + * @brief Calculate the HID Device usage type from the BLE Appearance + * @param appearance : BLE Appearance value * * @return: the hid usage type */ diff --git a/components/esp_hid/src/ble_hidd.c b/components/esp_hid/src/ble_hidd.c index e0c22adb85..36d21f29d6 100644 --- a/components/esp_hid/src/ble_hidd.c +++ b/components/esp_hid/src/ble_hidd.c @@ -977,7 +977,7 @@ esp_err_t esp_ble_hidd_dev_init(esp_hidd_dev_t *dev_p, const esp_hid_device_conf .queue_size = 5, .task_name = "ble_hidd_events", .task_priority = uxTaskPriorityGet(NULL), - .task_stack_size = 4096, + .task_stack_size = BT_HID_DEVICE_TASK_SIZE_BLE, .task_core_id = tskNO_AFFINITY }; ret = esp_event_loop_create(&event_task_args, &s_dev->event_loop_handle); diff --git a/components/esp_hid/src/bt_hidd.c b/components/esp_hid/src/bt_hidd.c index 0800613e0f..861c8c1dc6 100644 --- a/components/esp_hid/src/bt_hidd.c +++ b/components/esp_hid/src/bt_hidd.c @@ -811,7 +811,7 @@ esp_err_t esp_bt_hidd_dev_init(esp_hidd_dev_t *dev_p, const esp_hid_device_confi .queue_size = 5, .task_name = "bt_hidd_events", .task_priority = uxTaskPriorityGet(NULL), - .task_stack_size = 2048, + .task_stack_size = BT_HID_DEVICE_TASK_SIZE_BT, .task_core_id = tskNO_AFFINITY }; ret = esp_event_loop_create(&event_task_args, &s_hidd_param.dev->event_loop_handle); diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index eea8adac3f..e07889cda8 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -431,7 +431,6 @@ components/esp_event/include/esp_event_loop.h components/esp_event/private_include/esp_event_internal.h components/esp_event/private_include/esp_event_private.h components/esp_event/test/test_event.c -components/esp_hid/include/esp_hid_common.h components/esp_hid/include/esp_hidd.h components/esp_hid/include/esp_hidd_gatts.h components/esp_hid/include/esp_hidd_transport.h From 162331877c3843879a689535f56548f49dcfbf5b Mon Sep 17 00:00:00 2001 From: zhanghaipeng Date: Fri, 24 Jan 2025 20:12:08 +0800 Subject: [PATCH 5/5] fix(ble): Update bt lib for ESP32(2a2631f) - Support ESP32 BLE GPIO DEBUG --- components/bt/controller/esp32/Kconfig.in | 9 +++++++++ components/bt/controller/lib_esp32 | 2 +- components/bt/include/esp32/include/esp_bt.h | 12 +++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/components/bt/controller/esp32/Kconfig.in b/components/bt/controller/esp32/Kconfig.in index b93200209a..f8033b2f6a 100644 --- a/components/bt/controller/esp32/Kconfig.in +++ b/components/bt/controller/esp32/Kconfig.in @@ -490,6 +490,15 @@ config BTDM_BLE_VS_QA_SUPPORT help This enables BLE vendor HCI command and event for QA. +config BTDM_CTRL_CONTROLLER_DEBUG_MODE_1 + bool "Enable Bluetooth controller debugging mode 1 (for internal use only)" if n + default n + depends on BT_ENABLED + help + Enables specific debugging features for the Bluetooth controller. + This option is strictly for internal debugging purposes and should not be enabled in production environments, + as it may impact performance and stability. + config BTDM_RESERVE_DRAM hex default 0xdb5c if BT_ENABLED diff --git a/components/bt/controller/lib_esp32 b/components/bt/controller/lib_esp32 index e847faba2d..6093909e01 160000 --- a/components/bt/controller/lib_esp32 +++ b/components/bt/controller/lib_esp32 @@ -1 +1 @@ -Subproject commit e847faba2d86e90b5f21d6310bb4723c4e32ba1c +Subproject commit 6093909e01930f8cda6f60510f8a412c6d1814e8 diff --git a/components/bt/include/esp32/include/esp_bt.h b/components/bt/include/esp32/include/esp_bt.h index 684866f9e2..3b67d008d8 100644 --- a/components/bt/include/esp32/include/esp_bt.h +++ b/components/bt/include/esp32/include/esp_bt.h @@ -205,6 +205,16 @@ the adv packet will be discarded until the memory is restored. */ #define BTDM_BLE_CHAN_ASS_EN (0) #endif +#if CONFIG_BTDM_CTRL_CONTROLLER_DEBUG_MODE_1 +#define BTDM_CTRL_CONTROLLER_DEBUG_MODE_1 (1 << 1) +#else +#define BTDM_CTRL_CONTROLLER_DEBUG_MODE_1 0 +#endif + +#ifndef BTDM_CTRL_CONTROLLER_DEBUG_FLAG +#define BTDM_CTRL_CONTROLLER_DEBUG_FLAG (BTDM_CTRL_CONTROLLER_DEBUG_MODE_1 | CONTROLLER_ADV_LOST_DEBUG_BIT) +#endif + #if defined(CONFIG_BTDM_BLE_PING_EN) #define BTDM_BLE_PING_EN (CONFIG_BTDM_BLE_PING_EN) #else @@ -224,7 +234,7 @@ the adv packet will be discarded until the memory is restored. */ .normal_adv_size = NORMAL_SCAN_DUPLICATE_CACHE_SIZE, \ .mesh_adv_size = MESH_DUPLICATE_SCAN_CACHE_SIZE, \ .send_adv_reserved_size = SCAN_SEND_ADV_RESERVED_SIZE, \ - .controller_debug_flag = CONTROLLER_ADV_LOST_DEBUG_BIT, \ + .controller_debug_flag = BTDM_CTRL_CONTROLLER_DEBUG_FLAG, \ .mode = BTDM_CONTROLLER_MODE_EFF, \ .ble_max_conn = CONFIG_BTDM_CTRL_BLE_MAX_CONN_EFF, \ .bt_max_acl_conn = CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN_EFF, \