Skip to content

Commit 03dd5e3

Browse files
committed
Merge branch 'feat/channel_sounding_nimble' into 'master'
feat(nimble): Add initial support for CS HCI See merge request espressif/esp-idf!41865
2 parents f4e999f + 38364c0 commit 03dd5e3

31 files changed

+2729
-1
lines changed

components/bt/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ if(CONFIG_BT_ENABLED)
754754
host/nimble/nimble/nimble/host/util/include
755755
host/nimble/nimble/nimble/host/store/ram/include
756756
host/nimble/nimble/nimble/host/store/config/include
757+
host/nimble/nimble/nimble/host/services/ras/include
757758
)
758759

759760
list(APPEND srcs "host/nimble/nimble/nimble/transport/src/transport.c"
@@ -774,6 +775,8 @@ if(CONFIG_BT_ENABLED)
774775
"host/nimble/nimble/nimble/host/services/hid/src/ble_svc_hid.c"
775776
"host/nimble/nimble/nimble/host/services/sps/src/ble_svc_sps.c"
776777
"host/nimble/nimble/nimble/host/services/cte/src/ble_svc_cte.c"
778+
"host/nimble/nimble/nimble/host/services/ras/src/ble_svc_ras.c"
779+
"host/nimble/nimble/nimble/host/src/ble_cs.c"
777780
"host/nimble/nimble/nimble/host/src/ble_hs_conn.c"
778781
"host/nimble/nimble/nimble/host/src/ble_store_util.c"
779782
"host/nimble/nimble/nimble/host/src/ble_sm.c"

components/bt/host/nimble/Kconfig.in

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,27 @@ menu "BLE 5.x Features"
708708
endif
709709
endmenu #BLE5.x
710710

711+
menu "BLE 6.x Features"
712+
depends on (SOC_BLE_60_SUPPORTED || BT_CONTROLLER_DISABLED)
713+
714+
menuconfig BT_NIMBLE_60_FEATURE_SUPPORT
715+
bool "Enable BLE 6 feature"
716+
depends on BT_NIMBLE_ENABLED && (SOC_BLE_60_SUPPORTED || BT_CONTROLLER_DISABLED)
717+
default n
718+
help
719+
Enable BLE 6 feature
720+
721+
if BT_NIMBLE_60_FEATURE_SUPPORT
722+
config BT_NIMBLE_CHANNEL_SOUNDING
723+
bool "ble channel souding feature"
724+
depends on BT_NIMBLE_ENABLED
725+
default n
726+
help
727+
Used to enable/disable the channel sounding feature
728+
729+
endif
730+
endmenu #BLE6.x
731+
711732
menu "Services"
712733
depends on BT_NIMBLE_GATT_SERVER
713734

@@ -955,6 +976,7 @@ menu "Services"
955976
default 0 if BT_NIMBLE_SVC_GAP_CAR_NOT_SUPP
956977
default 1 if BT_NIMBLE_SVC_GAP_CAR_SUPP
957978

979+
958980
menu "GAP Appearance write permissions"
959981
depends on BT_NIMBLE_GAP_SERVICE
960982

components/bt/host/nimble/port/include/esp_nimble_cfg.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,4 +2192,12 @@
21922192
#define MYNEWT_VAL_BLE_USED_IN_IDF (1)
21932193
#endif
21942194

2195+
#ifndef MYNEWT_VAL_BLE_CHANNEL_SOUNDING
2196+
#ifdef CONFIG_BT_NIMBLE_CHANNEL_SOUNDING
2197+
#define MYNEWT_VAL_BLE_CHANNEL_SOUNDING (CONFIG_BT_NIMBLE_CHANNEL_SOUNDING)
2198+
#else
2199+
#define MYNEWT_VAL_BLE_CHANNEL_SOUNDING (0)
2200+
#endif
2201+
#endif
2202+
21952203
#endif

examples/bluetooth/.build-test-rules.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,25 @@ examples/bluetooth/nimble/ble_ancs:
187187
depends_filepatterns:
188188
- examples/bluetooth/nimble/common/**/*
189189

190+
examples/bluetooth/nimble/ble_chan_sound_initiator:
191+
<<: *bt_default_depends
192+
enable:
193+
- if: SOC_BLE_SUPPORTED == 1 and IDF_TARGET == "esp32c6"
194+
temporary: true
195+
reason: Channel Sounding example only supported on ESP32-C6
196+
depends_filepatterns:
197+
- examples/bluetooth/nimble/ble_chan_sound_initiator/**/*
198+
- examples/bluetooth/nimble/common/**/*
199+
200+
examples/bluetooth/nimble/ble_chan_sound_reflector:
201+
<<: *bt_default_depends
202+
enable:
203+
- if: SOC_BLE_SUPPORTED == 1 and IDF_TARGET == "esp32c6"
204+
temporary: true
205+
reason: Channel Sounding example only supported on ESP32-C6
206+
depends_filepatterns:
207+
- examples/bluetooth/nimble/ble_chan_sound_reflector/**/*
208+
- examples/bluetooth/nimble/common/**/*
190209
examples/bluetooth/nimble/ble_cte:
191210
<<: *bt_default_depends
192211
enable:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# The following lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.16)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
7+
idf_build_set_property(MINIMAL_BUILD ON)
8+
project(ble_chan_sound_initiator)
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
| Supported Targets | ESP32-C6 |
2+
| ----------------- | -------- |
3+
4+
# BLE Channel sounding example
5+
(See the README.md file in the upper-level 'examples' directory for more information about examples.)
6+
* This example demonstrates the capability of the CS procedure to be executed on the ESP host + external controller.
7+
* It is important to note that the current example does not provide support for distance calculation, and it is currently under development.
8+
9+
## Example output
10+
11+
I (372) hal_uart: set baud_rate:115200.
12+
13+
I (382) NimBLE_RAS_INITIATOR: BLE Host Task Started
14+
I (382) main_task: Returned from app_main()
15+
16+
I (432) NimBLE: GAP procedure initiated: extended discovery;
17+
18+
I (157332) NimBLE: GAP procedure initiated: extended connect;
19+
I (157552) NimBLE: Connection established
20+
I (157562) NimBLE: Connection secured
21+
I (162222) NimBLE: encryption change event; status=0
22+
23+
I (162372) NimBLE: CS capabilities exchanged
24+
I (162372) NimBLE: Set default CS settings
25+
I (162392) NimBLE: create CS config
26+
I (162392) NimBLE: Setup phase completed
27+
28+
## Note:
29+
* This example currently requires an external Bluetooth controller supporting BLE Channel sounding functionality,as the ESP chips listed above do not have native controller support for BLE channel sounding feature and is under development phase
30+
31+
* To install the dependency packages needed, please refer to the top level [README file](../../../README.md#running-test-python-script-pytest).
32+
33+
## How to Use Example
34+
35+
Before project configuration and build, be sure to set the correct chip target using:
36+
37+
```bash
38+
idf.py set-target <chip_name>
39+
```
40+
41+
### Hardware Required
42+
43+
* A development board with ESP32/ESP32-C2/ESP32-C3/ESP32-S3/ESP32-C6 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
44+
* A USB cable for Power supply and programming
45+
46+
See [Development Boards](https://www.espressif.com/en/products/devkits) for more information about it.
47+
48+
### Configure the Project
49+
50+
Open the project configuration menu:
51+
52+
```bash
53+
idf.py menuconfig
54+
```
55+
56+
In the `Example Configuration` menu:
57+
58+
* Change the `Peer Address` option if needed.
59+
60+
### Build and Flash
61+
62+
Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.
63+
64+
(To exit the serial monitor, type ``Ctrl-]``.)
65+
66+
See the [Getting Started Guide](https://idf.espressif.com/) for full steps to configure and use ESP-IDF to build projects.
67+
68+
## Troubleshooting
69+
70+
For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you soon.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
set(srcs "main.c")
2+
3+
idf_component_register(SRCS "gatt_svr.c" "${srcs}"
4+
INCLUDE_DIRS ".")
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
menu "Example Configuration"
2+
3+
4+
config EXAMPLE_EXTENDED_ADV
5+
bool
6+
depends on SOC_BLE_50_SUPPORTED && BT_NIMBLE_50_FEATURE_SUPPORT
7+
default y
8+
select BT_NIMBLE_EXT_ADV
9+
prompt "Enable Extended Adv"
10+
help
11+
Use this option to enable extended advertising in the example.
12+
If this option is disabled, ensure config BT_NIMBLE_EXT_ADV is
13+
also disabled from Nimble stack menuconfig
14+
endmenu
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
3+
* SPDX-License-Identifier: Unlicense OR CC0-1.0
4+
*/
5+
6+
#ifndef H_BLE_CHAN_INITIATOR_
7+
#define H_BLE_CHAN_INITIATOR_
8+
9+
#include "modlog/modlog.h"
10+
#include "esp_central.h"
11+
#ifdef __cplusplus
12+
extern "C" {
13+
#endif
14+
15+
struct ble_hs_adv_fields;
16+
struct ble_gap_conn_desc;
17+
struct ble_hs_cfg;
18+
union ble_store_value;
19+
union ble_store_key;
20+
21+
22+
#define BLE_HCI_LE_CS_SUBEVENT_DONE_STATUS_COMPLETE 0x0
23+
#define BLE_HCI_LE_CS_SUBEVENT_DONE_STATUS_PARTIAL 0x1
24+
#define BLE_HCI_LE_CS_SUBEVENT_DONE_STATUS_ABORTED 0xF
25+
26+
#define LOCAL_PROCEDURE_MEM 1024 // Replace with an appropriate constant value
27+
struct ble_hs_cfg;
28+
struct ble_gatt_register_ctxt;
29+
30+
/** GATT server. */
31+
32+
#define BLE_UUID_RANGING_SERVICE_VAL (0x185B)
33+
34+
/** @brief UUID of the RAS Features Characteristic. **/
35+
#define BLE_UUID_RAS_FEATURES_VAL (0x2C14)
36+
37+
/** @brief UUID of the Real-time Ranging Data Characteristic. **/
38+
#define BLE_UUID_RAS_REALTIME_RD_VAL (0x2C15)
39+
40+
/** @brief UUID of the On-demand Ranging Data Characteristic. **/
41+
#define BLE_UUID_RAS_ONDEMAND_RD_VAL (0x2C16)
42+
43+
/** @brief UUID of the RAS Control Point Characteristic. **/
44+
#define BLE_UUID_RAS_CP_VAL (0x2C17)
45+
46+
/** @brief UUID of the Ranging Data Ready Characteristic. **/
47+
#define BLE_UUID_RAS_RD_READY_VAL (0x2C18)
48+
49+
/** @brief UUID of the Ranging Data Overwritten Characteristic. **/
50+
#define BLE_UUID_RAS_RD_OVERWRITTEN_VAL (0x2C19)
51+
52+
void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
53+
int gatt_svr_init(void);
54+
55+
#ifdef __cplusplus
56+
}
57+
#endif
58+
59+
#endif

0 commit comments

Comments
 (0)