Skip to content

Commit 38364c0

Browse files
committed
fix(nimble): Added CS service support
1 parent 300bf85 commit 38364c0

29 files changed

+1083
-4805
lines changed

components/bt/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ if(CONFIG_BT_ENABLED)
775775
"host/nimble/nimble/nimble/host/services/hid/src/ble_svc_hid.c"
776776
"host/nimble/nimble/nimble/host/services/sps/src/ble_svc_sps.c"
777777
"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"
778779
"host/nimble/nimble/nimble/host/src/ble_cs.c"
779780
"host/nimble/nimble/nimble/host/src/ble_hs_conn.c"
780781
"host/nimble/nimble/nimble/host/src/ble_store_util.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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,7 @@
21962196
#ifdef CONFIG_BT_NIMBLE_CHANNEL_SOUNDING
21972197
#define MYNEWT_VAL_BLE_CHANNEL_SOUNDING (CONFIG_BT_NIMBLE_CHANNEL_SOUNDING)
21982198
#else
2199-
#define MYNEWT_VAL_BLE_CHANNEL_SOUNDING (1)
2199+
#define MYNEWT_VAL_BLE_CHANNEL_SOUNDING (0)
22002200
#endif
22012201
#endif
22022202

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:

examples/bluetooth/nimble/ble_chan_sound_initiator/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ cmake_minimum_required(VERSION 3.16)
55
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
66
# "Trim" the build. Include the minimal set of components, main, and anything it depends on.
77
idf_build_set_property(MINIMAL_BUILD ON)
8-
project(blecent)
8+
project(ble_chan_sound_initiator)
Lines changed: 22 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,32 @@
1-
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-S3 |
2-
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- |
1+
| Supported Targets | ESP32-C6 |
2+
| ----------------- | -------- |
33

4-
# BLE Central Example
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.
58

6-
(See the README.md file in the upper level 'examples' directory for more information about examples.)
9+
## Example output
710

8-
This example creates GATT client and performs passive scan, it then connects to peripheral device if the device advertises connectability and the device advertises support for the Alert Notification service (0x1811) as primary service UUID.
11+
I (372) hal_uart: set baud_rate:115200.
912

10-
After connection it enables bonding and link encryprion if the `Enable Link Encryption` flag is set in the example config.
13+
I (382) NimBLE_RAS_INITIATOR: BLE Host Task Started
14+
I (382) main_task: Returned from app_main()
1115

12-
It performs six GATT operations against the specified peer:
16+
I (432) NimBLE: GAP procedure initiated: extended discovery;
1317

14-
* Reads the ANS Supported New Alert Category characteristic.
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
1522

16-
* After the read operation is completed, writes the ANS Alert Notification Control Point characteristic.
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
1727

18-
* After the write operation is completed, subscribes to notifications for the ANS Unread Alert Status characteristic.
19-
20-
* After the subscribe operation is completed, it subscribes to notifications for a user defined characteristic.
21-
22-
* After this subscribe operation is completed, it writes to the user defined characteristic.
23-
24-
* After the write operation is completed, it reads from the user defined characteristic.
25-
26-
If the peer does not support a required service, characteristic, or descriptor, then the peer lied when it claimed support for the alert notification service! When this happens, or if a GATT procedure fails, this function immediately terminates the connection.
27-
28-
It uses ESP32's Bluetooth controller and NimBLE stack based BLE host.
29-
30-
This example aims at understanding BLE service discovery, connection, encryption and characteristic operations.
31-
32-
To test this demo, use any BLE GATT server app that advertises support for the Alert Notification service (0x1811) and includes it in the GATT database.
33-
34-
Note :
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
3530

3631
* To install the dependency packages needed, please refer to the top level [README file](../../../README.md#running-test-python-script-pytest).
3732

@@ -45,7 +40,7 @@ idf.py set-target <chip_name>
4540

4641
### Hardware Required
4742

48-
* A development board with ESP32/ESP32-C2/ESP32-C3/ESP32-S3 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
43+
* A development board with ESP32/ESP32-C2/ESP32-C3/ESP32-S3/ESP32-C6 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
4944
* A USB cable for Power supply and programming
5045

5146
See [Development Boards](https://www.espressif.com/en/products/devkits) for more information about it.
@@ -70,68 +65,6 @@ Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.
7065

7166
See the [Getting Started Guide](https://idf.espressif.com/) for full steps to configure and use ESP-IDF to build projects.
7267

73-
## Example Output
74-
75-
This is the console output on successful connection:
76-
77-
```
78-
I (202) BTDM_INIT: BT controller compile version [0b60040]
79-
I (202) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
80-
W (212) phy_init: failed to load RF calibration data (0xffffffff), falling back to full calibration
81-
I (422) phy: phy_version: 4007, 9c6b43b, Jan 11 2019, 16:45:07, 0, 2
82-
I (722) NimBLE_BLE_CENT: BLE Host Task Started
83-
GAP procedure initiated: stop advertising.
84-
GAP procedure initiated: discovery; own_addr_type=0 filter_policy=0 passive=1 limited=0 filter_duplicates=1 duration=forever
85-
GAP procedure initiated: connect; peer_addr_type=1 peer_addr=xx:xx:xx:xx:xx:xx scan_itvl=16 scan_window=16 itvl_min=24 itvl_max=40 latency=0 supervision_timeout=256 min_ce_len=16 max_ce_len=768 own_addr_type=0
86-
Connection established
87-
Connection secured
88-
encryption change event; status=0
89-
GATT procedure initiated: discover all services
90-
GATT procedure initiated: discover all characteristics; start_handle=1 end_handle=3
91-
GATT procedure initiated: discover all characteristics; start_handle=20 end_handle=26
92-
GATT procedure initiated: discover all characteristics; start_handle=40 end_handle=65535
93-
GATT procedure initiated: discover all descriptors; chr_val_handle=42 end_handle=43
94-
GATT procedure initiated: discover all descriptors; chr_val_handle=49 end_handle=65535
95-
Service discovery complete; status=0 conn_handle=0
96-
GATT procedure initiated: read; att_handle=45
97-
GATT procedure initiated: write; att_handle=47 len=2
98-
GATT procedure initiated: write; att_handle=43 len=2
99-
Read complete; status=0 conn_handle=0 attr_handle=45 value=0x02
100-
Write complete; status=0 conn_handle=0 attr_handle=47
101-
Subscribe complete; status=0 conn_handle=0 attr_handle=43
102-
GATT procedure initiated: write; att_handle=26 len=2
103-
GATT procedure initiated: write; att_handle=25 len=1
104-
GATT procedure initiated: read; att_handle=25
105-
Subscribe to the custom subscribable characteristic complete; status=0 conn_handle=1 attr_handle=26 value=
106-
Write to the custom subscribable characteristic complete; status=0 conn_handle=1 attr_handle=25
107-
received notification; conn_handle=1 attr_handle=25 attr_len=4
108-
Read complete for the subscribable characteristic; status=0 conn_handle=1 attr_handle=25 value=0x19
109-
```
110-
111-
This is the console output on failure (or peripheral does not support New Alert Service category):
112-
113-
```
114-
I (180) BTDM_INIT: BT controller compile version [8e87ec7]
115-
I (180) system_api: Base MAC address is not set, read default base MAC address from BLK0 of EFUSE
116-
I (250) phy: phy_version: 4000, b6198fa, Sep 3 2018, 15:11:06, 0, 0
117-
I (480) NimBLE_BLE_CENT: BLE Host Task Started
118-
GAP procedure initiated: stop advertising.
119-
GAP procedure initiated: discovery; own_addr_type=0 filter_policy=0 passive=1 limited=0 filter_duplicates=1 duration=forever
120-
GAP procedure initiated: connect; peer_addr_type=1 peer_addr=xx:xx:xx:xx:xx:xx scan_itvl=16 scan_window=16 itvl_min=24 itvl_max=40 latency=0 supervision_timeout=256 min_ce_len=16 max_ce_len=768 own_addr_type=0
121-
Connection established
122-
GATT procedure initiated: discover all services
123-
GATT procedure initiated: discover all characteristics; start_handle=1 end_handle=3
124-
GATT procedure initiated: discover all characteristics; start_handle=20 end_handle=26
125-
GATT procedure initiated: discover all characteristics; start_handle=40 end_handle=65535
126-
GATT procedure initiated: discover all descriptors; chr_val_handle=42 end_handle=43
127-
GATT procedure initiated: discover all descriptors; chr_val_handle=47 end_handle=65535
128-
Service discovery complete; status=0 conn_handle=0
129-
Error: Peer doesn't support the Supported New Alert Category characteristic
130-
GAP procedure initiated: terminate connection; conn_handle=0 hci_reason=19
131-
disconnect; reason=534
132-
```
133-
134-
13568
## Troubleshooting
13669

13770
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: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,14 @@
11
menu "Example Configuration"
22

3-
config EXAMPLE_PEER_ADDR
4-
string "Peer Address"
5-
default "ADDR_ANY"
6-
help
7-
Enter the peer address in aa:bb:cc:dd:ee:ff form to connect to a specific peripheral
83

94
config EXAMPLE_EXTENDED_ADV
105
bool
116
depends on SOC_BLE_50_SUPPORTED && BT_NIMBLE_50_FEATURE_SUPPORT
12-
default y if SOC_ESP_NIMBLE_CONTROLLER
7+
default y
138
select BT_NIMBLE_EXT_ADV
149
prompt "Enable Extended Adv"
1510
help
1611
Use this option to enable extended advertising in the example.
1712
If this option is disabled, ensure config BT_NIMBLE_EXT_ADV is
1813
also disabled from Nimble stack menuconfig
19-
20-
config EXAMPLE_INIT_DEINIT_LOOP
21-
bool
22-
prompt "Perform init deinit of nimble stack in a loop"
23-
help
24-
Enable this flag, to perform only stack Init and Deinit in a loop.
25-
26-
config EXAMPLE_ENCRYPTION
27-
bool
28-
prompt "Enable Link Encryption"
29-
help
30-
This enables bonding and encryption after connection has been established.
31-
32-
config EXAMPLE_USE_CI_ADDRESS
33-
bool
34-
default n
35-
prompt "Advertise using Test address(Internal Test ONLY)"
36-
help
37-
Used for internal test ONLY.
38-
Use this option to advertise in a specific random address.
3914
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

examples/bluetooth/nimble/ble_chan_sound_initiator/main/blecent.h

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)