Merge branch 'fix/adding_missing_apis_nimble_v5.2' into 'release/v5.2'

fix(nimble): Added helper APIs in NimBLE (v5.2)

See merge request espressif/esp-idf!40931
This commit is contained in:
Jiang Jiang Jian
2025-08-22 15:46:49 +08:00
7 changed files with 150 additions and 4 deletions

View File

@@ -781,6 +781,12 @@ config BT_NIMBLE_GATT_CACHING_DISABLE_AUTO
help
When client receives ATT out-of-sync error message, it will not automatically start the discovery procedure
to correct the invalid cache.
config BT_NIMBLE_GATT_CACHING_ASSOC_ENABLE
bool "Enable association-based GATT caching"
depends on BT_NIMBLE_GATT_CACHING
default n
help
Enable this option to use associated address caching instead of performing service discovery.
config BT_NIMBLE_WHITELIST_SIZE
int "BLE white list size"

View File

@@ -188,6 +188,14 @@
#define MYNEWT_VAL_BLE_GATT_CACHING_DISABLE_AUTO (0)
#endif
#ifndef MYNEWT_VAL_BLE_GATT_CACHING_ASSOC_ENABLE
#ifdef CONFIG_BT_NIMBLE_GATT_CACHING_ASSOC_ENABLE
#define MYNEWT_VAL_BLE_GATT_CACHING_ASSOC_ENABLE (CONFIG_BT_NIMBLE_GATT_CACHING_ASSOC_ENABLE)
#else
#define MYNEWT_VAL_BLE_GATT_CACHING_ASSOC_ENABLE (0)
#endif
#endif
#endif
#ifndef MYNEWT_VAL_BLE_GATT_CSFC_SIZE

View File

@@ -426,6 +426,13 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg)
} else {
MODLOG_DFLT(INFO, "Connection secured\n");
}
#else
#if MYNEWT_VAL(BLE_GATT_CACHING_ASSOC_ENABLE)
rc = ble_gattc_cache_assoc(desc.peer_id_addr);
if (rc != 0) {
MODLOG_DFLT(ERROR, "Cache Association Failed; rc=%d\n", rc);
return 0;
}
#else
/* Perform service discovery */
rc = peer_disc_all(event->connect.conn_handle,
@@ -434,6 +441,7 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif // BLE_GATT_CACHING_ASSOC_ENABLE
#endif
} else {
/* Connection attempt failed; resume scanning. */
@@ -470,6 +478,13 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg)
assert(rc == 0);
print_conn_desc(&desc);
#if CONFIG_EXAMPLE_ENCRYPTION
#if MYNEWT_VAL(BLE_GATT_CACHING_ASSOC_ENABLE)
rc = ble_gattc_cache_assoc(desc.peer_id_addr);
if (rc != 0) {
MODLOG_DFLT(ERROR, "Cache Association Failed; rc=%d\n", rc);
return 0;
}
#else
/*** Go for service discovery after encryption has been successfully enabled ***/
rc = peer_disc_all(event->connect.conn_handle,
ble_cts_cent_on_disc_complete, NULL);
@@ -477,9 +492,27 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif // BLE_GATT_CACHING_ASSOC_ENABLE
#endif
return 0;
case BLE_GAP_EVENT_CACHE_ASSOC:
#if MYNEWT_VAL(BLE_GATT_CACHING_ASSOC_ENABLE)
/* Cache association result for this connection */
MODLOG_DFLT(INFO, "cache association; conn_handle=%d status=%d cache_state=%s\n",
event->cache_assoc.conn_handle,
event->cache_assoc.status,
(event->cache_assoc.cache_state == 0) ? "INVALID" : "LOADED");
/* Perform service discovery */
rc = peer_disc_all(event->connect.conn_handle,
blecent_on_disc_complete, NULL);
if(rc != 0) {
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
return 0;
case BLE_GAP_EVENT_NOTIFY_RX:
/* Peer sent us a notification or indication. */
MODLOG_DFLT(INFO, "received %s; conn_handle=%d attr_handle=%d "

View File

@@ -540,6 +540,13 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg)
} else {
MODLOG_DFLT(INFO, "Connection secured\n");
}
#else
#if MYNEWT_VAL(BLE_GATT_CACHING_ASSOC_ENABLE)
rc = ble_gattc_cache_assoc(desc.peer_id_addr);
if (rc != 0) {
MODLOG_DFLT(ERROR, "Cache Association Failed; rc=%d\n", rc);
return 0;
}
#else
/* Perform service discovery */
rc = peer_disc_all(event->connect.conn_handle,
@@ -548,6 +555,7 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif // BLE_GATT_CACHING_ASSOC_ENABLE
#endif
} else {
/* Connection attempt failed; resume scanning. */
@@ -584,6 +592,13 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg)
assert(rc == 0);
print_conn_desc(&desc);
#if CONFIG_EXAMPLE_ENCRYPTION
#if MYNEWT_VAL(BLE_GATT_CACHING_ASSOC_ENABLE)
rc = ble_gattc_cache_assoc(desc.peer_id_addr);
if (rc != 0) {
MODLOG_DFLT(ERROR, "Cache Association Failed; rc=%d\n", rc);
return 0;
}
#else
/*** Go for service discovery after encryption has been successfully enabled ***/
rc = peer_disc_all(event->connect.conn_handle,
ble_htp_cent_on_disc_complete, NULL);
@@ -591,9 +606,27 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif // BLE_GATT_CACHING_ASSOC_ENABLE
#endif
return 0;
case BLE_GAP_EVENT_CACHE_ASSOC:
#if MYNEWT_VAL(BLE_GATT_CACHING_ASSOC_ENABLE)
/* Cache association result for this connection */
MODLOG_DFLT(INFO, "cache association; conn_handle=%d status=%d cache_state=%s\n",
event->cache_assoc.conn_handle,
event->cache_assoc.status,
(event->cache_assoc.cache_state == 0) ? "INVALID" : "LOADED");
/* Perform service discovery */
rc = peer_disc_all(event->connect.conn_handle,
blecent_on_disc_complete, NULL);
if(rc != 0) {
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
return 0;
case BLE_GAP_EVENT_NOTIFY_RX:
/* Peer sent us a notification or indication. */
MODLOG_DFLT(INFO, "received %s; conn_handle=%d attr_handle=%d "

View File

@@ -472,6 +472,13 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg)
} else {
MODLOG_DFLT(INFO, "Connection secured\n");
}
#else
#if MYNEWT_VAL(BLE_GATT_CACHING_ASSOC_ENABLE)
rc = ble_gattc_cache_assoc(desc.peer_id_addr);
if (rc != 0) {
MODLOG_DFLT(ERROR, "Cache Association Failed; rc=%d\n", rc);
return 0;
}
#else
/* Perform service discovery */
rc = peer_disc_all(event->connect.conn_handle,
@@ -480,6 +487,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif // BLE_GATT_CACHING_ASSOC_ENABLE
#endif
} else {
/* Connection attempt failed; resume scanning. */
@@ -532,6 +540,13 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg)
assert(rc == 0);
print_conn_desc(&desc);
#if CONFIG_EXAMPLE_ENCRYPTION
#if MYNEWT_VAL(BLE_GATT_CACHING_ASSOC_ENABLE)
rc = ble_gattc_cache_assoc(desc.peer_id_addr);
if (rc != 0) {
MODLOG_DFLT(ERROR, "Cache Association Failed; rc=%d\n", rc);
return 0;
}
#else
/*** Go for service discovery after encryption has been successfully enabled ***/
rc = peer_disc_all(event->connect.conn_handle,
ble_prox_cent_on_disc_complete, NULL);
@@ -539,9 +554,27 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif // BLE_GATT_CACHING_ASSOC_ENABLE
#endif
return 0;
case BLE_GAP_EVENT_CACHE_ASSOC:
#if MYNEWT_VAL(BLE_GATT_CACHING_ASSOC_ENABLE)
/* Cache association result for this connection */
MODLOG_DFLT(INFO, "cache association; conn_handle=%d status=%d cache_state=%s\n",
event->cache_assoc.conn_handle,
event->cache_assoc.status,
(event->cache_assoc.cache_state == 0) ? "INVALID" : "LOADED");
/* Perform service discovery */
rc = peer_disc_all(event->connect.conn_handle,
blecent_on_disc_complete, NULL);
if(rc != 0) {
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
return 0;
case BLE_GAP_EVENT_NOTIFY_RX:
/* Peer sent us a notification or indication. */
MODLOG_DFLT(INFO, "received %s; conn_handle=%d attr_handle=%d "

View File

@@ -787,6 +787,13 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
}
#else
#if MYNEWT_VAL(BLE_GATTC)
#if MYNEWT_VAL(BLE_GATT_CACHING_ASSOC_ENABLE)
rc = ble_gattc_cache_assoc(desc.peer_id_addr);
if (rc != 0) {
MODLOG_DFLT(ERROR, "Cache Association Failed; rc=%d\n", rc);
return 0;
}
#else
/* Perform service discovery */
rc = peer_disc_all(event->connect.conn_handle,
blecent_on_disc_complete, NULL);
@@ -794,8 +801,9 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
#endif
#endif // BLE_GATT_CACHING_ASSOC_ENABLE
#endif // BLE_GATTC
#endif // EXAMPLE_ENCRYPTION
} else {
/* Connection attempt failed; resume scanning. */
MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n",
@@ -840,6 +848,13 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
print_conn_desc(&desc);
#if !MYNEWT_VAL(BLE_EATT_CHAN_NUM)
#if CONFIG_EXAMPLE_ENCRYPTION && MYNEWT_VAL(BLE_GATTC)
#if MYNEWT_VAL(BLE_GATT_CACHING_ASSOC_ENABLE)
rc = ble_gattc_cache_assoc(desc.peer_id_addr);
if (rc != 0) {
MODLOG_DFLT(ERROR, "Cache Association Failed; rc=%d\n", rc);
return 0;
}
#else
/*** Go for service discovery after encryption has been successfully enabled ***/
rc = peer_disc_all(event->enc_change.conn_handle,
blecent_on_disc_complete, NULL);
@@ -847,10 +862,28 @@ blecent_gap_event(struct ble_gap_event *event, void *arg)
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
#endif // BLE_GATT_CACHING_ASSOC_ENABLE
#endif // EXAMPLE_ENCRYPTION
#endif
return 0;
case BLE_GAP_EVENT_CACHE_ASSOC:
#if MYNEWT_VAL(BLE_GATT_CACHING_ASSOC_ENABLE)
/* Cache association result for this connection */
MODLOG_DFLT(INFO, "cache association; conn_handle=%d status=%d cache_state=%s\n",
event->cache_assoc.conn_handle,
event->cache_assoc.status,
(event->cache_assoc.cache_state == 0) ? "INVALID" : "LOADED");
/* Perform service discovery */
rc = peer_disc_all(event->connect.conn_handle,
blecent_on_disc_complete, NULL);
if(rc != 0) {
MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc);
return 0;
}
#endif
return 0;
case BLE_GAP_EVENT_NOTIFY_RX:
/* Peer sent us a notification or indication. */
MODLOG_DFLT(INFO, "received %s; conn_handle=%d attr_handle=%d "