Skip to content

Commit

Permalink
Merge branch 'bugfix/backport_ble_fixes_v5.1' into 'release/v5.1'
Browse files Browse the repository at this point in the history
Bugfix/backport ble fixes v5.1

See merge request espressif/esp-idf!29291
  • Loading branch information
rahult-github committed Mar 1, 2024
2 parents 3962454 + 86aaec4 commit 67c4eac
Show file tree
Hide file tree
Showing 38 changed files with 1,749 additions and 2,054 deletions.
82 changes: 55 additions & 27 deletions components/bt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@ if(CONFIG_BT_ENABLED)
set(srcs "")
set(include_dirs "")
set(ldfragments "linker.lf")
if(CONFIG_BT_CONTROLLER_ENABLED)
if(CONFIG_IDF_TARGET_ESP32)
list(APPEND srcs "controller/esp32/bt.c"
"controller/esp32/hli_api.c"
"controller/esp32/hli_vectors.S")
list(APPEND include_dirs include/esp32/include)

elseif(CONFIG_IDF_TARGET_ESP32C3)
list(APPEND srcs "controller/esp32c3/bt.c")
list(APPEND include_dirs include/esp32c3/include)

elseif(CONFIG_IDF_TARGET_ESP32S3)
list(APPEND srcs "controller/esp32c3/bt.c")
list(APPEND include_dirs include/esp32c3/include)

elseif(CONFIG_IDF_TARGET_ESP32C2)
set(ldfragments "linker.lf.esp32c2")
list(APPEND srcs "controller/esp32c2/bt.c")
list(APPEND include_dirs include/esp32c2/include)

elseif(CONFIG_IDF_TARGET_ESP32C6)
list(APPEND srcs "controller/esp32c6/bt.c")
list(APPEND include_dirs include/esp32c6/include)

elseif(CONFIG_IDF_TARGET_ESP32H2)
list(APPEND srcs "controller/esp32h2/bt.c")
list(APPEND include_dirs include/esp32h2/include)
endif()

if(CONFIG_IDF_TARGET_ESP32)
list(APPEND srcs "controller/esp32/bt.c"
"controller/esp32/hli_api.c"
"controller/esp32/hli_vectors.S")
list(APPEND include_dirs include/esp32/include)

elseif(CONFIG_IDF_TARGET_ESP32C3)
list(APPEND srcs "controller/esp32c3/bt.c")
list(APPEND include_dirs include/esp32c3/include)

elseif(CONFIG_IDF_TARGET_ESP32S3)
list(APPEND srcs "controller/esp32c3/bt.c")
list(APPEND include_dirs include/esp32c3/include)

elseif(CONFIG_IDF_TARGET_ESP32C2)
set(ldfragments "linker.lf.esp32c2")
list(APPEND srcs "controller/esp32c2/bt.c")
list(APPEND include_dirs include/esp32c2/include)

elseif(CONFIG_IDF_TARGET_ESP32C6)
list(APPEND srcs "controller/esp32c6/bt.c")
list(APPEND include_dirs include/esp32c6/include)

elseif(CONFIG_IDF_TARGET_ESP32H2)
list(APPEND srcs "controller/esp32h2/bt.c")
list(APPEND include_dirs include/esp32h2/include)
endif()


Expand Down Expand Up @@ -483,6 +485,11 @@ if(CONFIG_BT_ENABLED)
"porting/nimble/src/os_msys_init.c"
)

if(CONFIG_BT_CONTROLLER_DISABLED)
list(APPEND srcs
"host/nimble/nimble/porting/nimble/src/hal_uart.c"
)
endif()
list(APPEND include_dirs
porting/include
porting/nimble/include
Expand Down Expand Up @@ -524,6 +531,7 @@ if(CONFIG_BT_ENABLED)
list(APPEND include_dirs

host/nimble/nimble/nimble/host/include
host/nimble/nimble/nimble/include
host/nimble/nimble/nimble/host/services/ans/include
host/nimble/nimble/nimble/host/services/bas/include
host/nimble/nimble/nimble/host/services/dis/include
Expand Down Expand Up @@ -613,6 +621,13 @@ if(CONFIG_BT_ENABLED)
"host/nimble/nimble/nimble/host/src/ble_gattc_cache_conn.c"
)

if(CONFIG_BT_CONTROLLER_DISABLED AND CONFIG_BT_NIMBLE_TRANSPORT_UART)
list(APPEND srcs
"host/nimble/nimble/nimble/transport/uart_ll/src/hci_uart.c"
"host/nimble/nimble/nimble/transport/common/hci_h4/src/hci_h4.c"
)
endif()

list(APPEND srcs
"host/nimble/nimble/porting/nimble/src/nimble_port.c"
"host/nimble/nimble/porting/npl/freertos/src/nimble_port_freertos.c"
Expand All @@ -625,6 +640,12 @@ if(CONFIG_BT_ENABLED)
host/nimble/nimble/nimble/transport/include
)

if(CONFIG_BT_CONTROLLER_DISABLED)
list(APPEND include_dirs
host/nimble/nimble/nimble/transport/common/hci_h4/include
)
endif()

if(NOT CONFIG_BT_LE_CONTROLLER_NPL_OS_PORTING_SUPPORT)
list(APPEND srcs
"host/nimble/nimble/porting/nimble/src/endian.c"
Expand All @@ -634,14 +655,21 @@ if(CONFIG_BT_ENABLED)
"host/nimble/nimble/porting/nimble/src/os_msys_init.c"
"host/nimble/nimble/porting/npl/freertos/src/npl_os_freertos.c"
)

if(CONFIG_BT_CONTROLLER_DISABLED AND CONFIG_BT_NIMBLE_TRANSPORT_UART)
list(APPEND srcs
"host/nimble/nimble/porting/nimble/src/hal_uart.c"
)
endif()

list(APPEND include_dirs
host/nimble/nimble/porting/npl/freertos/include
host/nimble/nimble/porting/nimble/include
host/nimble/nimble/nimble/include
)
endif()

if(CONFIG_BT_NIMBLE_LEGACY_VHCI_ENABLE)
if(CONFIG_BT_NIMBLE_LEGACY_VHCI_ENABLE AND CONFIG_BT_CONTROLLER_ENABLED)
list(APPEND srcs
"host/nimble/esp-hci/src/esp_nimble_hci.c"
)
Expand Down
6 changes: 4 additions & 2 deletions components/bt/Kconfig
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
menu "Bluetooth"
visible if SOC_BT_SUPPORTED

config BT_ENABLED
bool "Bluetooth"
depends on SOC_BT_SUPPORTED && !APP_NO_BLOBS
depends on !APP_NO_BLOBS
help
Select this option to enable Bluetooth and show the submenu with Bluetooth configuration choices.

Expand All @@ -15,6 +14,7 @@ menu "Bluetooth"
This helps to choose Bluetooth host stack

config BT_BLUEDROID_ENABLED
depends on BT_CONTROLLER_ENABLED
bool "Bluedroid - Dual-mode"
help
This option is recommended for classic Bluetooth or for dual-mode
Expand All @@ -26,6 +26,7 @@ menu "Bluetooth"
This option is recommended for BLE only usecases to save on memory

config BT_CONTROLLER_ONLY
depends on SOC_BT_SUPPORTED
bool "Disabled"
help
This option is recommended when you want to communicate directly with the
Expand All @@ -42,6 +43,7 @@ menu "Bluetooth"
This helps to choose Bluetooth controller stack

config BT_CONTROLLER_ENABLED
depends on SOC_BT_SUPPORTED
bool "Enabled"
help
This option is recommended for Bluetooth controller usecases
Expand Down
99 changes: 99 additions & 0 deletions components/bt/host/nimble/Kconfig.in
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ config BT_NIMBLE_LL_CFG_FEAT_LE_ENCRYPTION
help
Enable encryption connection

config BT_NIMBLE_SM_SC_LVL
int "Security level"
depends on BT_NIMBLE_SECURITY_ENABLE
default 0
help
LE Security Mode 1 Levels:
1. No Security
2. Unauthenticated pairing with encryption
3. Authenticated pairing with encryption
4. Authenticated LE Secure Connections pairing with encryption using a 128-bit strength encryption key.

config BT_NIMBLE_DEBUG
bool "Enable extra runtime asserts and host debugging"
default n
Expand Down Expand Up @@ -756,3 +767,91 @@ config BT_NIMBLE_HOST_QUEUE_CONG_CHECK
When scanning and scan duplicate is not enabled, if there are a lot of adv packets around
or application layer handling adv packets is slow, it will cause the controller memory
to run out. if enabled, adv packets will be lost when host queue is congested.

menu "Host-controller Transport"
config BT_NIMBLE_TRANSPORT_UART
bool "Enable Uart Transport"
default y
depends on BT_CONTROLLER_DISABLED
help
Use UART transport

config BT_NIMBLE_TRANSPORT_UART_PORT
int "Uart port"
depends on BT_CONTROLLER_DISABLED && BT_NIMBLE_TRANSPORT_UART
default 1
help
Uart port

choice BT_NIMBLE_USE_HCI_UART_PARITY
prompt "Uart PARITY"
default UART_PARITY_NONE
help
Uart Parity

config UART_PARITY_NONE
bool "None"
config UART_PARITY_ODD
bool "Odd"
config UART_PARITY_EVEN
bool "Even"
endchoice

config BT_NIMBLE_TRANSPORT_UART_PARITY_NONE
int
default 0 if !UART_PARITY_NONE
default 1 if UART_PARITY_NONE

config BT_NIMBLE_TRANSPORT_UART_PARITY_ODD
int
default 0 if !UART_PARITY_ODD
default 1 if UART_PARITY_ODD

config BT_NIMBLE_TRANSPORT_UART_PARITY_EVEN
int
default 0 if !UART_PARITY_EVEN
default 1 if UART_PARITY_EVEN

config BT_NIMBLE_UART_RX_PIN
int "UART Rx pin"
depends on BT_CONTROLLER_DISABLED && BT_NIMBLE_TRANSPORT_UART
default 5
help
Rx pin for Nimble Transport

config BT_NIMBLE_UART_TX_PIN
int "UART Tx pin"
depends on BT_CONTROLLER_DISABLED && BT_NIMBLE_TRANSPORT_UART
default 4
help
Tx pin for Nimble Transport

choice BT_NIMBLE_USE_HCI_UART_FLOW_CTRL
prompt "Uart Flow Control"
default UART_HW_FLOWCTRL_DISABLE
help
Uart Flow Control

config UART_HW_FLOWCTRL_DISABLE
bool "Disable"
config UART_HW_FLOWCTRL_CTS_RTS
bool "Enable hardware flow control"
endchoice

config BT_NIMBLE_HCI_UART_FLOW_CTRL
int
default 0 if UART_HW_FLOWCTRL_DISABLE
default 1 if UART_HW_FLOWCTRL_CTS_RTS

config BT_NIMBLE_HCI_UART_RTS_PIN
int "UART Rts Pin"
default 19
help
UART HCI RTS pin

config BT_NIMBLE_HCI_UART_CTS_PIN
int "UART Cts Pin"
default 23
help
UART HCI CTS pin
endmenu
2 changes: 2 additions & 0 deletions components/bt/host/nimble/esp-hci/src/esp_nimble_hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#include "esp_nimble_hci.h"
#include "esp_nimble_mem.h"
#include "bt_osi_mem.h"
#if CONFIG_BT_CONTROLLER_ENABLED
#include "esp_bt.h"
#endif
#include "freertos/semphr.h"
#include "esp_compiler.h"
#include "soc/soc_caps.h"
Expand Down
2 changes: 1 addition & 1 deletion components/bt/host/nimble/nimble
Submodule nimble updated 51 files
+1 −0 nimble/host/include/host/ble_att.h
+42 −0 nimble/host/include/host/ble_esp_gap.h
+129 −0 nimble/host/include/host/ble_gap.h
+258 −0 nimble/host/include/host/ble_gatt.h
+40 −0 nimble/host/include/host/ble_hs_adv.h
+1 −0 nimble/host/include/host/ble_store.h
+1 −0 nimble/host/src/ble_att.c
+100 −0 nimble/host/src/ble_att_clt.c
+14 −0 nimble/host/src/ble_att_cmd_priv.h
+4 −0 nimble/host/src/ble_att_priv.h
+122 −1 nimble/host/src/ble_att_svr.c
+331 −24 nimble/host/src/ble_gap.c
+1 −0 nimble/host/src/ble_gap_priv.h
+14 −0 nimble/host/src/ble_gatt_priv.h
+69 −0 nimble/host/src/ble_gattc.c
+174 −0 nimble/host/src/ble_gatts.c
+2 −2 nimble/host/src/ble_hs.c
+156 −0 nimble/host/src/ble_hs_adv.c
+1 −1 nimble/host/src/ble_hs_flow.c
+16 −2 nimble/host/src/ble_hs_hci.c
+2 −2 nimble/host/src/ble_hs_hci_cmd.c
+41 −1 nimble/host/src/ble_hs_hci_evt.c
+8 −0 nimble/host/src/ble_hs_hci_priv.h
+69 −0 nimble/host/src/ble_hs_hci_util.c
+1 −1 nimble/host/src/ble_hs_resolv.c
+182 −4 nimble/host/src/ble_sm.c
+9 −0 nimble/host/src/ble_sm_priv.h
+10 −0 nimble/host/src/ble_sm_sc.c
+2 −2 nimble/host/store/config/src/ble_store_config.c
+1 −1 nimble/host/store/ram/src/ble_store_ram.c
+2 −2 nimble/host/util/src/addr.c
+12 −1 nimble/include/nimble/hci_common.h
+4 −0 nimble/include/nimble/nimble_opt_auto.h
+4 −0 nimble/transport/common/hci_h4/src/hci_h4.c
+12 −2 nimble/transport/include/nimble/transport.h
+2 −0 nimble/transport/pkg.yml
+1 −1 nimble/transport/src/transport.c
+1 −0 nimble/transport/syscfg.yml
+32 −0 nimble/transport/uart_ll/pkg.yml
+245 −0 nimble/transport/uart_ll/src/hci_uart.c
+39 −0 nimble/transport/uart_ll/syscfg.yml
+1 −1 porting/nimble/include/hal/hal_uart.h
+2 −2 porting/nimble/include/mem/mem.h
+1 −1 porting/nimble/include/nimble/nimble_port.h
+1 −1 porting/nimble/include/os/endian.h
+1 −1 porting/nimble/include/os/os_mbuf.h
+1 −1 porting/nimble/include/os/os_mempool.h
+132 −345 porting/nimble/src/hal_uart.c
+36 −5 porting/nimble/src/nimble_port.c
+2 −0 porting/npl/freertos/src/nimble_port_freertos.c
+4 −4 porting/npl/freertos/src/npl_os_freertos.c
38 changes: 36 additions & 2 deletions components/bt/host/nimble/port/include/esp_nimble_cfg.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -844,7 +844,7 @@


#ifndef MYNEWT_VAL_BLE_SM_SC_LVL
#define MYNEWT_VAL_BLE_SM_SC_LVL (0)
#define MYNEWT_VAL_BLE_SM_SC_LVL CONFIG_BT_NIMBLE_SM_SC_LVL
#endif

#ifndef MYNEWT_VAL_BLE_SM_SC_ONLY
Expand Down Expand Up @@ -1773,4 +1773,38 @@
#endif
#endif

#if CONFIG_BT_CONTROLLER_DISABLED
#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_PORT
#define MYNEWT_VAL_BLE_TRANSPORT_UART_PORT CONFIG_BT_NIMBLE_TRANSPORT_UART_PORT
#endif

#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_PARITY__none
#define MYNEWT_VAL_BLE_TRANSPORT_UART_PARITY__none CONFIG_BT_NIMBLE_TRANSPORT_UART_PARITY_NONE
#endif

#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_PARITY__odd
#define MYNEWT_VAL_BLE_TRANSPORT_UART_PARITY__odd CONFIG_BT_NIMBLE_TRANSPORT_UART_PARITY_ODD
#endif

#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_PARITY__even
#define MYNEWT_VAL_BLE_TRANSPORT_UART_PARITY__even CONFIG_BT_NIMBLE_TRANSPORT_UART_PARITY_EVEN
#endif

#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_FLOW_CONTROL__rtscts
#define MYNEWT_VAL_BLE_TRANSPORT_UART_FLOW_CONTROL__rtscts CONFIG_BT_NIMBLE_HCI_UART_FLOW_CTRL
#endif

#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_BAUDRATE
#define MYNEWT_VAL_BLE_TRANSPORT_UART_BAUDRATE (921600)
#endif

#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_DATA_BITS
#define MYNEWT_VAL_BLE_TRANSPORT_UART_DATA_BITS (3)
#endif

#ifndef MYNEWT_VAL_BLE_TRANSPORT_UART_STOP_BITS
#define MYNEWT_VAL_BLE_TRANSPORT_UART_STOP_BITS (1)
#endif
#endif

#endif
2 changes: 1 addition & 1 deletion components/bt/porting/include/mem_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
extern "C" {
#endif

#if SOC_ESP_NIMBLE_CONTROLLER
#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED

struct os_mempool;
struct os_mbuf_pool;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ extern "C" {
typedef int ble_hci_trans_rx_cmd_fn(uint8_t *cmd, void *arg);
typedef int ble_hci_trans_rx_acl_fn(struct os_mbuf *om, void *arg);

#if SOC_ESP_NIMBLE_CONTROLLER
#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED
#define ble_transport_alloc_cmd() ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD)
#define ble_transport_alloc_event(X) ble_hci_trans_buf_alloc(X ? BLE_HCI_TRANS_BUF_EVT_LO : BLE_HCI_TRANS_BUF_EVT_HI)
#define ble_transport_free ble_hci_trans_buf_free
Expand Down
Loading

0 comments on commit 67c4eac

Please sign in to comment.