Skip to content

Commit 300bf85

Browse files
committed
feat(nimble): Base support for Channel sounding HCI command and events
1 parent 79cc42a commit 300bf85

33 files changed

+6641
-191
lines changed

components/bt/CMakeLists.txt

Lines changed: 2 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,7 @@ 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/src/ble_cs.c"
777779
"host/nimble/nimble/nimble/host/src/ble_hs_conn.c"
778780
"host/nimble/nimble/nimble/host/src/ble_store_util.c"
779781
"host/nimble/nimble/nimble/host/src/ble_sm.c"

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 (1)
2200+
#endif
2201+
#endif
2202+
21952203
#endif
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(blecent)
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C5 | ESP32-C6 | ESP32-C61 | ESP32-H2 | ESP32-S3 |
2+
| ----------------- | ----- | -------- | -------- | -------- | -------- | --------- | -------- | -------- |
3+
4+
# BLE Central Example
5+
6+
(See the README.md file in the upper level 'examples' directory for more information about examples.)
7+
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.
9+
10+
After connection it enables bonding and link encryprion if the `Enable Link Encryption` flag is set in the example config.
11+
12+
It performs six GATT operations against the specified peer:
13+
14+
* Reads the ANS Supported New Alert Category characteristic.
15+
16+
* After the read operation is completed, writes the ANS Alert Notification Control Point characteristic.
17+
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 :
35+
36+
* To install the dependency packages needed, please refer to the top level [README file](../../../README.md#running-test-python-script-pytest).
37+
38+
## How to Use Example
39+
40+
Before project configuration and build, be sure to set the correct chip target using:
41+
42+
```bash
43+
idf.py set-target <chip_name>
44+
```
45+
46+
### Hardware Required
47+
48+
* A development board with ESP32/ESP32-C2/ESP32-C3/ESP32-S3 SoC (e.g., ESP32-DevKitC, ESP-WROVER-KIT, etc.)
49+
* A USB cable for Power supply and programming
50+
51+
See [Development Boards](https://www.espressif.com/en/products/devkits) for more information about it.
52+
53+
### Configure the Project
54+
55+
Open the project configuration menu:
56+
57+
```bash
58+
idf.py menuconfig
59+
```
60+
61+
In the `Example Configuration` menu:
62+
63+
* Change the `Peer Address` option if needed.
64+
65+
### Build and Flash
66+
67+
Run `idf.py -p PORT flash monitor` to build, flash and monitor the project.
68+
69+
(To exit the serial monitor, type ``Ctrl-]``.)
70+
71+
See the [Getting Started Guide](https://idf.espressif.com/) for full steps to configure and use ESP-IDF to build projects.
72+
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+
135+
## Troubleshooting
136+
137+
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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
menu "Example Configuration"
2+
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
8+
9+
config EXAMPLE_EXTENDED_ADV
10+
bool
11+
depends on SOC_BLE_50_SUPPORTED && BT_NIMBLE_50_FEATURE_SUPPORT
12+
default y if SOC_ESP_NIMBLE_CONTROLLER
13+
select BT_NIMBLE_EXT_ADV
14+
prompt "Enable Extended Adv"
15+
help
16+
Use this option to enable extended advertising in the example.
17+
If this option is disabled, ensure config BT_NIMBLE_EXT_ADV is
18+
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.
39+
endmenu
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#ifndef H_BLECENT_
21+
#define H_BLECENT_
22+
23+
#include "modlog/modlog.h"
24+
#include "esp_central.h"
25+
#ifdef __cplusplus
26+
extern "C" {
27+
#endif
28+
29+
struct ble_hs_adv_fields;
30+
struct ble_gap_conn_desc;
31+
struct ble_hs_cfg;
32+
union ble_store_value;
33+
union ble_store_key;
34+
35+
#define BLECENT_SVC_ALERT_UUID 0x1811
36+
#define BLECENT_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47
37+
#define BLECENT_CHR_NEW_ALERT 0x2A46
38+
#define BLECENT_CHR_SUP_UNR_ALERT_CAT_UUID 0x2A48
39+
#define BLECENT_CHR_UNR_ALERT_STAT_UUID 0x2A45
40+
#define BLECENT_CHR_ALERT_NOT_CTRL_PT 0x2A44
41+
42+
#ifdef __cplusplus
43+
}
44+
#endif
45+
46+
#endif
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#ifndef H_BLEHR_SENSOR_
21+
#define H_BLEHR_SENSOR_
22+
23+
#include "nimble/ble.h"
24+
#include "modlog/modlog.h"
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
/* Heart-rate configuration */
31+
#define GATT_HRS_UUID 0x180D
32+
#define GATT_HRS_MEASUREMENT_UUID 0x2A37
33+
#define GATT_HRS_BODY_SENSOR_LOC_UUID 0x2A38
34+
#define GATT_DEVICE_INFO_UUID 0x180A
35+
#define GATT_MANUFACTURER_NAME_UUID 0x2A29
36+
#define GATT_MODEL_NUMBER_UUID 0x2A24
37+
38+
39+
#define BLE_UUID_RANGING_SERVICE_VAL (0x185B)
40+
41+
/** @brief UUID of the RAS Features Characteristic. **/
42+
#define BLE_UUID_RAS_FEATURES_VAL (0x2C14)
43+
44+
/** @brief UUID of the Real-time Ranging Data Characteristic. **/
45+
#define BLE_UUID_RAS_REALTIME_RD_VAL (0x2C15)
46+
47+
/** @brief UUID of the On-demand Ranging Data Characteristic. **/
48+
#define BLE_UUID_RAS_ONDEMAND_RD_VAL (0x2C16)
49+
50+
/** @brief UUID of the RAS Control Point Characteristic. **/
51+
#define BLE_UUID_RAS_CP_VAL (0x2C17)
52+
53+
/** @brief UUID of the Ranging Data Ready Characteristic. **/
54+
#define BLE_UUID_RAS_RD_READY_VAL (0x2C18)
55+
56+
/** @brief UUID of the Ranging Data Overwritten Characteristic. **/
57+
#define BLE_UUID_RAS_RD_OVERWRITTEN_VAL (0x2C19)
58+
59+
60+
extern uint16_t hrs_hrm_handle;
61+
62+
struct ble_hs_cfg;
63+
struct ble_gatt_register_ctxt;
64+
65+
void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg);
66+
int gatt_svr_init(void);
67+
68+
#ifdef __cplusplus
69+
}
70+
#endif
71+
72+
#endif

0 commit comments

Comments
 (0)