From bc29f45224ddb06551bd72a974f96108ff0b7c11 Mon Sep 17 00:00:00 2001 From: Astha Verma Date: Mon, 28 Oct 2024 12:53:36 +0530 Subject: [PATCH 01/14] fix(nimble): added a function for printing HCI error definition --- components/bt/host/nimble/nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 275e6820cd..46f1139a05 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 275e6820cda2862e636c35b1acecfe67978684c7 +Subproject commit 46f1139a055246d05c0744c2195c5f82155b5e6d From 03a4e243940203cb611413e6d6ff09b6b715e549 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Fri, 6 Dec 2024 10:54:11 +0530 Subject: [PATCH 02/14] fix(nimble): Fixes for security vulnerabilities reported in NimBLE --- components/bt/host/nimble/nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 46f1139a05..c58a8e7edf 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 46f1139a055246d05c0744c2195c5f82155b5e6d +Subproject commit c58a8e7edfdad6e6b4e7742ef2aa3a07488b815e From fc3ecc25274520691a77987730ccfb9280bf7a94 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Wed, 18 Dec 2024 17:41:56 +0530 Subject: [PATCH 03/14] fix(nimble): Corrected link_estab event handling parameters --- components/bt/host/nimble/nimble | 2 +- .../nimble/ble_cts/cts_cent/main/main.c | 16 ++++++++-------- .../nimble/ble_cts/cts_prph/main/main.c | 8 ++++---- .../nimble/ble_dynamic_service/main/main.c | 12 ++++++------ .../enc_adv_data_cent/main/main.c | 18 +++++++++--------- .../enc_adv_data_prph/main/main.c | 12 ++++++------ .../nimble/ble_htp/htp_cent/main/main.c | 18 +++++++++--------- .../nimble/ble_htp/htp_prph/main/main.c | 10 +++++----- .../ble_l2cap_coc/coc_blecent/main/main.c | 14 +++++++------- .../ble_l2cap_coc/coc_bleprph/main/main.c | 14 +++++++------- .../bluetooth/nimble/ble_multi_adv/main/main.c | 10 +++++----- .../ble_multi_conn_cent/main/main.c | 18 +++++++++--------- .../ble_multi_conn_prph/main/main.c | 4 ++-- .../nimble/ble_phy/phy_cent/main/main.c | 12 ++++++------ .../nimble/ble_phy/phy_prph/main/main.c | 12 ++++++------ .../proximity_sensor_cent/main/main.c | 18 +++++++++--------- .../proximity_sensor_prph/main/main.c | 8 ++++---- .../nimble/ble_spp/spp_client/main/main.c | 14 +++++++------- .../nimble/ble_spp/spp_server/main/main.c | 12 ++++++------ examples/bluetooth/nimble/blecent/main/main.c | 18 +++++++++--------- examples/bluetooth/nimble/blecsc/main/main.c | 8 ++++---- examples/bluetooth/nimble/blehr/main/main.c | 8 ++++---- examples/bluetooth/nimble/bleprph/main/main.c | 12 ++++++------ .../nimble/bleprph_host_only/main/main.c | 14 +++++++------- .../nimble/bleprph_wifi_coex/main/main.c | 10 +++++----- .../bluetooth/nimble/power_save/main/main.c | 14 +++++++------- .../blecent_throughput/main/main.c | 18 +++++++++--------- .../bleprph_throughput/main/main.c | 12 ++++++------ 28 files changed, 173 insertions(+), 173 deletions(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index c58a8e7edf..bac3aa9d4e 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit c58a8e7edfdad6e6b4e7742ef2aa3a07488b815e +Subproject commit bac3aa9d4e261b57aa49819fe72bb8e842b9f93f diff --git a/examples/bluetooth/nimble/ble_cts/cts_cent/main/main.c b/examples/bluetooth/nimble/ble_cts/cts_cent/main/main.c index 41bc0899c6..dfacbcd9cf 100644 --- a/examples/bluetooth/nimble/ble_cts/cts_cent/main/main.c +++ b/examples/bluetooth/nimble/ble_cts/cts_cent/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -375,17 +375,17 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ - if (event->connect.status == 0) { + if (event->link_estab.status == 0) { /* Connection successfully established. */ MODLOG_DFLT(INFO, "Connection established "); - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); MODLOG_DFLT(INFO, "\n"); /* Remember peer. */ - rc = peer_add(event->connect.conn_handle); + rc = peer_add(event->link_estab.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; @@ -398,17 +398,17 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg) * Encryption (Enable encryption) * Will invoke event BLE_GAP_EVENT_ENC_CHANGE **/ - rc = ble_gap_security_initiate(event->connect.conn_handle); + rc = ble_gap_security_initiate(event->link_estab.conn_handle); if (rc != 0) { MODLOG_DFLT(INFO, "Security could not be initiated, rc = %d\n", rc); - return ble_gap_terminate(event->connect.conn_handle, + return ble_gap_terminate(event->link_estab.conn_handle, BLE_ERR_REM_USER_CONN_TERM); } else { MODLOG_DFLT(INFO, "Connection secured\n"); } #else /* Perform service discovery */ - rc = peer_disc_all(event->connect.conn_handle, + rc = peer_disc_all(event->link_estab.conn_handle, ble_cts_cent_on_disc_complete, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); @@ -418,7 +418,7 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->connect.status); + event->link_estab.status); ble_cts_cent_scan(); } diff --git a/examples/bluetooth/nimble/ble_cts/cts_prph/main/main.c b/examples/bluetooth/nimble/ble_cts/cts_prph/main/main.c index 53f81200ce..24b643cb19 100644 --- a/examples/bluetooth/nimble/ble_cts/cts_prph/main/main.c +++ b/examples/bluetooth/nimble/ble_cts/cts_prph/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -181,10 +181,10 @@ ble_cts_prph_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed */ MODLOG_DFLT(INFO, "connection %s; status=%d\n", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); - if (event->connect.status != 0) { + if (event->link_estab.status != 0) { /* Connection failed; resume advertising */ #if CONFIG_EXAMPLE_EXTENDED_ADV ext_ble_cts_prph_advertise(); diff --git a/examples/bluetooth/nimble/ble_dynamic_service/main/main.c b/examples/bluetooth/nimble/ble_dynamic_service/main/main.c index d4a7365698..3000624f4f 100644 --- a/examples/bluetooth/nimble/ble_dynamic_service/main/main.c +++ b/examples/bluetooth/nimble/ble_dynamic_service/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -139,16 +139,16 @@ dynamic_service_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); - if (event->connect.status == 0) { - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); + if (event->link_estab.status == 0) { + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); dynamic_service_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->connect.status != 0) { + if (event->link_estab.status != 0) { /* Connection failed; resume advertising. */ dynamic_service_advertise(); } diff --git a/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_cent/main/main.c b/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_cent/main/main.c index d0a4a86bf0..98a95dd893 100644 --- a/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_cent/main/main.c +++ b/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_cent/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -426,11 +426,11 @@ enc_adv_data_cent_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ - if (event->connect.status == 0) { + if (event->link_estab.status == 0) { /* Connection successfully established. */ MODLOG_DFLT(INFO, "Connection established "); - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); MODLOG_DFLT(INFO, ""); @@ -440,29 +440,29 @@ enc_adv_data_cent_gap_event(struct ble_gap_event *event, void *arg) ESP_LOGE(tag, "Failed to set preferred MTU; rc = %d", rc); } - rc = ble_gattc_exchange_mtu(event->connect.conn_handle, NULL, NULL); + rc = ble_gattc_exchange_mtu(event->link_estab.conn_handle, NULL, NULL); if (rc != 0) { ESP_LOGE(tag, "Failed to negotiate MTU; rc = %d", rc); } /* Remember peer. */ - rc = peer_add(event->connect.conn_handle); + rc = peer_add(event->link_estab.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; } - rc = peer_set_addr(event->connect.conn_handle, desc.peer_id_addr.val); + rc = peer_set_addr(event->link_estab.conn_handle, desc.peer_id_addr.val); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to set peer addr; rc=%d\n", rc); return 0; } /** Authorization is required for this characterisitc */ - rc = ble_gap_security_initiate(event->connect.conn_handle); + rc = ble_gap_security_initiate(event->link_estab.conn_handle); if (rc != 0) { MODLOG_DFLT(INFO, "Security could not be initiated, rc = %d\n", rc); - return ble_gap_terminate(event->connect.conn_handle, + return ble_gap_terminate(event->link_estab.conn_handle, BLE_ERR_REM_USER_CONN_TERM); } else { MODLOG_DFLT(INFO, "Connection secured\n"); @@ -471,7 +471,7 @@ enc_adv_data_cent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->connect.status); + event->link_estab.status); enc_adv_data_cent_scan(); } diff --git a/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_prph/main/main.c b/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_prph/main/main.c index ff2536c3a2..cd09b6521a 100644 --- a/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_prph/main/main.c +++ b/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_prph/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -188,16 +188,16 @@ enc_adv_data_prph_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); - if (event->connect.status == 0) { - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); + if (event->link_estab.status == 0) { + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); enc_adv_data_prph_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->connect.status != 0) { + if (event->link_estab.status != 0) { /* Connection failed; resume advertising. */ enc_adv_data_prph_advertise(); } diff --git a/examples/bluetooth/nimble/ble_htp/htp_cent/main/main.c b/examples/bluetooth/nimble/ble_htp/htp_cent/main/main.c index 798455f230..ad8ab5e980 100644 --- a/examples/bluetooth/nimble/ble_htp/htp_cent/main/main.c +++ b/examples/bluetooth/nimble/ble_htp/htp_cent/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -490,17 +490,17 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ - if (event->connect.status == 0) { + if (event->link_estab.status == 0) { /* Connection successfully established. */ MODLOG_DFLT(INFO, "Connection established "); - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); MODLOG_DFLT(INFO, "\n"); /* Remember peer. */ - rc = peer_add(event->connect.conn_handle); + rc = peer_add(event->link_estab.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; @@ -513,17 +513,17 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg) * Encryption (Enable encryption) * Will invoke event BLE_GAP_EVENT_ENC_CHANGE **/ - rc = ble_gap_security_initiate(event->connect.conn_handle); + rc = ble_gap_security_initiate(event->link_estab.conn_handle); if (rc != 0) { MODLOG_DFLT(INFO, "Security could not be initiated, rc = %d\n", rc); - return ble_gap_terminate(event->connect.conn_handle, + return ble_gap_terminate(event->link_estab.conn_handle, BLE_ERR_REM_USER_CONN_TERM); } else { MODLOG_DFLT(INFO, "Connection secured\n"); } #else /* Perform service discovery */ - rc = peer_disc_all(event->connect.conn_handle, + rc = peer_disc_all(event->link_estab.conn_handle, ble_htp_cent_on_disc_complete, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); @@ -533,7 +533,7 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->connect.status); + event->link_estab.status); ble_htp_cent_scan(); } @@ -566,7 +566,7 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg) print_conn_desc(&desc); #if CONFIG_EXAMPLE_ENCRYPTION /*** Go for service discovery after encryption has been successfully enabled ***/ - rc = peer_disc_all(event->connect.conn_handle, + rc = peer_disc_all(event->link_estab.conn_handle, ble_htp_cent_on_disc_complete, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); diff --git a/examples/bluetooth/nimble/ble_htp/htp_prph/main/main.c b/examples/bluetooth/nimble/ble_htp/htp_prph/main/main.c index df4e8f28d9..f9b48b9c01 100644 --- a/examples/bluetooth/nimble/ble_htp/htp_prph/main/main.c +++ b/examples/bluetooth/nimble/ble_htp/htp_prph/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -233,10 +233,10 @@ ble_htp_prph_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed */ MODLOG_DFLT(INFO, "connection %s; status=%d\n", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); - if (event->connect.status != 0) { + if (event->link_estab.status != 0) { /* Connection failed; resume advertising */ #if CONFIG_EXAMPLE_EXTENDED_ADV ext_ble_htp_prph_advertise(); @@ -245,7 +245,7 @@ ble_htp_prph_gap_event(struct ble_gap_event *event, void *arg) #endif } - conn_handle = event->connect.conn_handle; + conn_handle = event->link_estab.conn_handle; break; case BLE_GAP_EVENT_DISCONNECT: diff --git a/examples/bluetooth/nimble/ble_l2cap_coc/coc_blecent/main/main.c b/examples/bluetooth/nimble/ble_l2cap_coc/coc_blecent/main/main.c index 5b5cba1422..eef5030a9b 100644 --- a/examples/bluetooth/nimble/ble_l2cap_coc/coc_blecent/main/main.c +++ b/examples/bluetooth/nimble/ble_l2cap_coc/coc_blecent/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -414,30 +414,30 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ - if (event->connect.status == 0) { + if (event->link_estab.status == 0) { /* Connection successfully established. */ MODLOG_DFLT(INFO, "Connection established "); - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); MODLOG_DFLT(INFO, "\n"); #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) >= 1 - conn_handle_coc = event->connect.conn_handle; + conn_handle_coc = event->link_estab.conn_handle; disc_cb = blecent_l2cap_coc_on_disc_complete; #else disc_cb = blecent_on_disc_complete; #endif /* Remember peer. */ - rc = peer_add(event->connect.conn_handle); + rc = peer_add(event->link_estab.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; } /* Perform service discovery. */ - rc = peer_disc_all(event->connect.conn_handle, + rc = peer_disc_all(event->link_estab.conn_handle, disc_cb, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); @@ -446,7 +446,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->connect.status); + event->link_estab.status); blecent_scan(); } diff --git a/examples/bluetooth/nimble/ble_l2cap_coc/coc_bleprph/main/main.c b/examples/bluetooth/nimble/ble_l2cap_coc/coc_bleprph/main/main.c index 6432c67c6c..8e90bfc021 100644 --- a/examples/bluetooth/nimble/ble_l2cap_coc/coc_bleprph/main/main.c +++ b/examples/bluetooth/nimble/ble_l2cap_coc/coc_bleprph/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -318,16 +318,16 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); - if (event->connect.status == 0) { - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); + if (event->link_estab.status == 0) { + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); bleprph_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->connect.status != 0) { + if (event->link_estab.status != 0) { /* Connection failed; resume advertising. */ #if CONFIG_EXAMPLE_EXTENDED_ADV ext_bleprph_advertise(); @@ -335,7 +335,7 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) bleprph_advertise(); #endif } else { - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); bleprph_print_conn_desc(&desc); #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) >= 1 diff --git a/examples/bluetooth/nimble/ble_multi_adv/main/main.c b/examples/bluetooth/nimble/ble_multi_adv/main/main.c index 10e279864e..495ba7a083 100644 --- a/examples/bluetooth/nimble/ble_multi_adv/main/main.c +++ b/examples/bluetooth/nimble/ble_multi_adv/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -340,10 +340,10 @@ ble_multi_adv_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); - if (event->connect.status == 0) { - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); + if (event->link_estab.status == 0) { + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); ble_multi_adv_print_conn_desc(&desc); diff --git a/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_cent/main/main.c b/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_cent/main/main.c index eb7bf718e7..85c382a0a8 100644 --- a/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_cent/main/main.c +++ b/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_cent/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -94,16 +94,16 @@ ble_cent_client_gap_event(struct ble_gap_event *event, void *arg) return 0; case BLE_GAP_EVENT_LINK_ESTAB: - if (event->connect.status == 0) { - ESP_LOGI(TAG, "Connection established. Handle:%d, Total:%d", event->connect.conn_handle, + if (event->link_estab.status == 0) { + ESP_LOGI(TAG, "Connection established. Handle:%d, Total:%d", event->link_estab.conn_handle, ++s_ble_multi_conn_num); /* Remember peer. */ - rc = peer_add(event->connect.conn_handle); + rc = peer_add(event->link_estab.conn_handle); if (rc != 0) { ESP_LOGE(TAG, "Failed to add peer; rc=%d\n", rc); } else { /* Perform service discovery */ - rc = peer_disc_svc_by_uuid(event->connect.conn_handle, remote_svc_uuid, + rc = peer_disc_svc_by_uuid(event->link_estab.conn_handle, remote_svc_uuid, ble_cent_on_disc_complete, NULL); if(rc != 0) { ESP_LOGE(TAG, "Failed to discover services; rc=%d\n", rc); @@ -111,7 +111,7 @@ ble_cent_client_gap_event(struct ble_gap_event *event, void *arg) } } else { /* Connection attempt failed; resume scanning. */ - ESP_LOGE(TAG, "Central: Connection failed; status=0x%x\n", event->connect.status); + ESP_LOGE(TAG, "Central: Connection failed; status=0x%x\n", event->link_estab.status); } ble_cent_scan(); return 0; @@ -176,10 +176,10 @@ ble_cent_server_gap_event(struct ble_gap_event *event, void *arg) switch (event->type) { case BLE_GAP_EVENT_LINK_ESTAB: /* The connectable adv has been established. We will act as the peripheral. */ - if (event->connect.status == 0) { - ESP_LOGI(TAG, "Peripheral connected to central. Handle:%d", event->connect.conn_handle); + if (event->link_estab.status == 0) { + ESP_LOGI(TAG, "Peripheral connected to central. Handle:%d", event->link_estab.conn_handle); } else { - ESP_LOGE(TAG, "Peripheral: Connection failed; status=0x%x\n", event->connect.status); + ESP_LOGE(TAG, "Peripheral: Connection failed; status=0x%x\n", event->link_estab.status); ble_cent_advertise(); } return 0; diff --git a/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_prph/main/main.c b/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_prph/main/main.c index e32cd6355f..dfdc5edcff 100644 --- a/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_prph/main/main.c +++ b/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_prph/main/main.c @@ -190,9 +190,9 @@ ble_prph_gap_event(struct ble_gap_event *event, void *arg) { switch (event->type) { case BLE_GAP_EVENT_LINK_ESTAB: - if (event->connect.status == 0) { + if (event->link_estab.status == 0) { /* A new connection was established. */ - ESP_LOGI(TAG, "Connection established. Handle:%d. Total:%d", event->connect.conn_handle, + ESP_LOGI(TAG, "Connection established. Handle:%d. Total:%d", event->link_estab.conn_handle, ++s_ble_prph_conn_num); #if CONFIG_EXAMPLE_RESTART_ADV_AFTER_CONNECTED ble_prph_restart_adv(); diff --git a/examples/bluetooth/nimble/ble_phy/phy_cent/main/main.c b/examples/bluetooth/nimble/ble_phy/phy_cent/main/main.c index 772c0d25bf..d04eb194e4 100644 --- a/examples/bluetooth/nimble/ble_phy/phy_cent/main/main.c +++ b/examples/bluetooth/nimble/ble_phy/phy_cent/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -349,7 +349,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) switch (event->type) { case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ - if (event->connect.status == 0) { + if (event->link_estab.status == 0) { /* Connection successfully established. */ switch (s_current_phy) { @@ -367,20 +367,20 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) break; } - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); MODLOG_DFLT(INFO, "\n"); /* Remember peer. */ - rc = peer_add(event->connect.conn_handle); + rc = peer_add(event->link_estab.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; } /* Perform service discovery. */ - rc = peer_disc_all(event->connect.conn_handle, + rc = peer_disc_all(event->link_estab.conn_handle, blecent_on_disc_complete, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); @@ -389,7 +389,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->connect.status); + event->link_estab.status); blecent_scan(); } diff --git a/examples/bluetooth/nimble/ble_phy/phy_prph/main/main.c b/examples/bluetooth/nimble/ble_phy/phy_prph/main/main.c index f1308fd708..4a953c70f3 100644 --- a/examples/bluetooth/nimble/ble_phy/phy_prph/main/main.c +++ b/examples/bluetooth/nimble/ble_phy/phy_prph/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -186,16 +186,16 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); - if (event->connect.status == 0) { - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); + if (event->link_estab.status == 0) { + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); bleprph_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->connect.status != 0) { + if (event->link_estab.status != 0) { /* Connection failed; resume advertising. */ ext_bleprph_advertise(); } diff --git a/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_cent/main/main.c b/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_cent/main/main.c index b57c17bb74..3fdb0405c3 100644 --- a/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_cent/main/main.c +++ b/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_cent/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -407,11 +407,11 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ - if (event->connect.status == 0) { + if (event->link_estab.status == 0) { /* Connection successfully established. */ MODLOG_DFLT(INFO, "Connection established "); - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); MODLOG_DFLT(INFO, "\n"); @@ -419,7 +419,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg) link_supervision_timeout = 8 * desc.conn_itvl; /* Remember peer. */ - rc = peer_add(event->connect.conn_handle); + rc = peer_add(event->link_estab.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; @@ -445,17 +445,17 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg) * Encryption (Enable encryption) * Will invoke event BLE_GAP_EVENT_ENC_CHANGE **/ - rc = ble_gap_security_initiate(event->connect.conn_handle); + rc = ble_gap_security_initiate(event->link_estab.conn_handle); if (rc != 0) { MODLOG_DFLT(INFO, "Security could not be initiated, rc = %d\n", rc); - return ble_gap_terminate(event->connect.conn_handle, + return ble_gap_terminate(event->link_estab.conn_handle, BLE_ERR_REM_USER_CONN_TERM); } else { MODLOG_DFLT(INFO, "Connection secured\n"); } #else /* Perform service discovery */ - rc = peer_disc_all(event->connect.conn_handle, + rc = peer_disc_all(event->link_estab.conn_handle, ble_prox_cent_on_disc_complete, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); @@ -465,7 +465,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->connect.status); + event->link_estab.status); } ble_prox_cent_scan(); return 0; @@ -514,7 +514,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg) print_conn_desc(&desc); #if CONFIG_EXAMPLE_ENCRYPTION /*** Go for service discovery after encryption has been successfully enabled ***/ - rc = peer_disc_all(event->connect.conn_handle, + rc = peer_disc_all(event->link_estab.conn_handle, ble_prox_cent_on_disc_complete, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); diff --git a/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_prph/main/main.c b/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_prph/main/main.c index 47634029c3..21220948eb 100644 --- a/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_prph/main/main.c +++ b/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_prph/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -180,10 +180,10 @@ ble_prox_prph_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed */ MODLOG_DFLT(INFO, "connection %s; status=%d\n", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); - if (event->connect.status != 0) { + if (event->link_estab.status != 0) { /* Connection failed, resume advertising */ #if CONFIG_EXAMPLE_EXTENDED_ADV ext_ble_prox_prph_advertise(); diff --git a/examples/bluetooth/nimble/ble_spp/spp_client/main/main.c b/examples/bluetooth/nimble/ble_spp/spp_client/main/main.c index 1b4f11284a..7fd5f7ff0a 100644 --- a/examples/bluetooth/nimble/ble_spp/spp_client/main/main.c +++ b/examples/bluetooth/nimble/ble_spp/spp_client/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -273,25 +273,25 @@ ble_spp_client_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ - if (event->connect.status == 0) { + if (event->link_estab.status == 0) { /* Connection successfully established. */ MODLOG_DFLT(INFO, "Connection established "); - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); - memcpy(&connected_addr[event->connect.conn_handle].val, desc.peer_id_addr.val, + memcpy(&connected_addr[event->link_estab.conn_handle].val, desc.peer_id_addr.val, PEER_ADDR_VAL_SIZE); print_conn_desc(&desc); MODLOG_DFLT(INFO, "\n"); /* Remember peer. */ - rc = peer_add(event->connect.conn_handle); + rc = peer_add(event->link_estab.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; } /* Perform service discovery. */ - rc = peer_disc_all(event->connect.conn_handle, + rc = peer_disc_all(event->link_estab.conn_handle, ble_spp_client_on_disc_complete, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); @@ -300,7 +300,7 @@ ble_spp_client_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->connect.status); + event->link_estab.status); ble_spp_client_scan(); } diff --git a/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c b/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c index f2569d2301..18eeb93b07 100644 --- a/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c +++ b/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -144,15 +144,15 @@ ble_spp_server_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); - if (event->connect.status == 0) { - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); + if (event->link_estab.status == 0) { + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); ble_spp_server_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->connect.status != 0 || CONFIG_BT_NIMBLE_MAX_CONNECTIONS > 1) { + if (event->link_estab.status != 0 || CONFIG_BT_NIMBLE_MAX_CONNECTIONS > 1) { /* Connection failed or if multiple connection allowed; resume advertising. */ ble_spp_server_advertise(); } diff --git a/examples/bluetooth/nimble/blecent/main/main.c b/examples/bluetooth/nimble/blecent/main/main.c index 46f4ba9bcb..6b05b9aef2 100644 --- a/examples/bluetooth/nimble/blecent/main/main.c +++ b/examples/bluetooth/nimble/blecent/main/main.c @@ -705,30 +705,30 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ - if (event->connect.status == 0) { + if (event->link_estab.status == 0) { /* Connection successfully established. */ MODLOG_DFLT(INFO, "Connection established "); - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); MODLOG_DFLT(INFO, "\n"); /* Remember peer. */ - rc = peer_add(event->connect.conn_handle); + rc = peer_add(event->link_estab.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; } #if MYNEWT_VAL(BLE_POWER_CONTROL) - blecent_power_control(event->connect.conn_handle); + blecent_power_control(event->link_estab.conn_handle); #endif #if MYNEWT_VAL(BLE_HCI_VS) #if MYNEWT_VAL(BLE_POWER_CONTROL) memset(¶ms, 0x0, sizeof(struct ble_gap_set_auto_pcl_params)); - params.conn_handle = event->connect.conn_handle; + params.conn_handle = event->link_estab.conn_handle; rc = ble_gap_set_auto_pcl_param(¶ms); if (rc != 0) { MODLOG_DFLT(INFO, "Failed to send VSC %x \n", rc); @@ -747,17 +747,17 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) * Encryption (Enable encryption) * Will invoke event BLE_GAP_EVENT_ENC_CHANGE **/ - rc = ble_gap_security_initiate(event->connect.conn_handle); + rc = ble_gap_security_initiate(event->link_estab.conn_handle); if (rc != 0) { MODLOG_DFLT(INFO, "Security could not be initiated, rc = %d\n", rc); - return ble_gap_terminate(event->connect.conn_handle, + return ble_gap_terminate(event->link_estab.conn_handle, BLE_ERR_REM_USER_CONN_TERM); } else { MODLOG_DFLT(INFO, "Connection secured\n"); } #else /* Perform service discovery */ - rc = peer_disc_all(event->connect.conn_handle, + rc = peer_disc_all(event->link_estab.conn_handle, blecent_on_disc_complete, NULL); if(rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); @@ -767,7 +767,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->connect.status); + event->link_estab.status); blecent_scan(); } diff --git a/examples/bluetooth/nimble/blecsc/main/main.c b/examples/bluetooth/nimble/blecsc/main/main.c index 4e159c922c..a813c03781 100644 --- a/examples/bluetooth/nimble/blecsc/main/main.c +++ b/examples/bluetooth/nimble/blecsc/main/main.c @@ -216,16 +216,16 @@ blecsc_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed */ MODLOG_DFLT(INFO, "connection %s; status=%d\n", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); - if (event->connect.status != 0) { + if (event->link_estab.status != 0) { /* Connection failed; resume advertising */ blecsc_advertise(); conn_handle = 0; } else { - conn_handle = event->connect.conn_handle; + conn_handle = event->link_estab.conn_handle; } break; diff --git a/examples/bluetooth/nimble/blehr/main/main.c b/examples/bluetooth/nimble/blehr/main/main.c index 9c9a917334..49e2d53a07 100644 --- a/examples/bluetooth/nimble/blehr/main/main.c +++ b/examples/bluetooth/nimble/blehr/main/main.c @@ -187,14 +187,14 @@ blehr_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed */ MODLOG_DFLT(INFO, "connection %s; status=%d\n", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); - if (event->connect.status != 0) { + if (event->link_estab.status != 0) { /* Connection failed; resume advertising */ blehr_advertise(); } - conn_handle = event->connect.conn_handle; + conn_handle = event->link_estab.conn_handle; break; case BLE_GAP_EVENT_DISCONNECT: diff --git a/examples/bluetooth/nimble/bleprph/main/main.c b/examples/bluetooth/nimble/bleprph/main/main.c index a34dd3e741..2726a4bdb0 100644 --- a/examples/bluetooth/nimble/bleprph/main/main.c +++ b/examples/bluetooth/nimble/bleprph/main/main.c @@ -243,16 +243,16 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); - if (event->connect.status == 0) { - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); + if (event->link_estab.status == 0) { + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); bleprph_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->connect.status != 0) { + if (event->link_estab.status != 0) { /* Connection failed; resume advertising. */ #if CONFIG_EXAMPLE_EXTENDED_ADV ext_bleprph_advertise(); @@ -262,7 +262,7 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) } #if MYNEWT_VAL(BLE_POWER_CONTROL) - bleprph_power_control(event->connect.conn_handle); + bleprph_power_control(event->link_estab.conn_handle); #endif return 0; diff --git a/examples/bluetooth/nimble/bleprph_host_only/main/main.c b/examples/bluetooth/nimble/bleprph_host_only/main/main.c index 43a4d14bff..277c03537e 100644 --- a/examples/bluetooth/nimble/bleprph_host_only/main/main.c +++ b/examples/bluetooth/nimble/bleprph_host_only/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -226,16 +226,16 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); - if (event->connect.status == 0) { - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); + if (event->link_estab.status == 0) { + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); bleprph_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->connect.status != 0) { + if (event->link_estab.status != 0) { /* Connection failed; resume advertising. */ #if CONFIG_EXAMPLE_EXTENDED_ADV ext_bleprph_advertise(); @@ -245,7 +245,7 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) } #if MYNEWT_VAL(BLE_POWER_CONTROL) - bleprph_power_control(event->connect.conn_handle); + bleprph_power_control(event->link_estab.conn_handle); #endif return 0; diff --git a/examples/bluetooth/nimble/bleprph_wifi_coex/main/main.c b/examples/bluetooth/nimble/bleprph_wifi_coex/main/main.c index 670bc983b0..af7c7b16d8 100644 --- a/examples/bluetooth/nimble/bleprph_wifi_coex/main/main.c +++ b/examples/bluetooth/nimble/bleprph_wifi_coex/main/main.c @@ -392,15 +392,15 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ ESP_LOGI(TAG, "connection %s; status=%d ", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); - if (event->connect.status == 0) { - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); + if (event->link_estab.status == 0) { + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); bleprph_print_conn_desc(&desc); } - if (event->connect.status != 0) { + if (event->link_estab.status != 0) { /* Connection failed; resume advertising. */ bleprph_advertise(); } diff --git a/examples/bluetooth/nimble/power_save/main/main.c b/examples/bluetooth/nimble/power_save/main/main.c index 39276934ea..b194608f6c 100644 --- a/examples/bluetooth/nimble/power_save/main/main.c +++ b/examples/bluetooth/nimble/power_save/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -287,16 +287,16 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); - if (event->connect.status == 0) { - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); + if (event->link_estab.status == 0) { + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); bleprph_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->connect.status != 0) { + if (event->link_estab.status != 0) { /* Connection failed; resume advertising. */ #if CONFIG_EXAMPLE_EXTENDED_ADV ext_bleprph_advertise(); @@ -306,7 +306,7 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) } #if MYNEWT_VAL(BLE_POWER_CONTROL) - bleprph_power_control(event->connect.conn_handle); + bleprph_power_control(event->link_estab.conn_handle); ble_gap_event_listener_register(&power_control_event_listener, bleprph_gap_power_event, NULL); diff --git a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c index c1087307e5..3dfe261c74 100644 --- a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c +++ b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -540,11 +540,11 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed. */ - if (event->connect.status == 0) { + if (event->link_estab.status == 0) { /* Connection successfully established. */ /* XXX Set packet length in controller for better throughput */ ESP_LOGI(tag, "Connection established "); - rc = ble_hs_hci_util_set_data_len(event->connect.conn_handle, + rc = ble_hs_hci_util_set_data_len(event->link_estab.conn_handle, LL_PACKET_LENGTH, LL_PACKET_TIME); if (rc != 0) { ESP_LOGE(tag, "Set packet length failed; rc = %d", rc); @@ -555,29 +555,29 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) ESP_LOGE(tag, "Failed to set preferred MTU; rc = %d", rc); } - rc = ble_gattc_exchange_mtu(event->connect.conn_handle, NULL, NULL); + rc = ble_gattc_exchange_mtu(event->link_estab.conn_handle, NULL, NULL); if (rc != 0) { ESP_LOGE(tag, "Failed to negotiate MTU; rc = %d", rc); } - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); - rc = ble_gap_update_params(event->connect.conn_handle, &conn_params); + rc = ble_gap_update_params(event->link_estab.conn_handle, &conn_params); if (rc != 0) { ESP_LOGE(tag, "Failed to update params; rc = %d", rc); } /* Remember peer. */ - rc = peer_add(event->connect.conn_handle); + rc = peer_add(event->link_estab.conn_handle); if (rc != 0) { ESP_LOGE(tag, "Failed to add peer; rc = %d", rc); return 0; } /* Perform service discovery. */ - rc = peer_disc_all(event->connect.conn_handle, + rc = peer_disc_all(event->link_estab.conn_handle, blecent_on_disc_complete, NULL); if (rc != 0) { ESP_LOGE(tag, "Failed to discover services; rc = %d", rc); @@ -586,7 +586,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ ESP_LOGE(tag, "Error: Connection failed; status = %d", - event->connect.status); + event->link_estab.status); blecent_scan(); } diff --git a/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c b/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c index 0a66ea0b60..da0d7916ce 100644 --- a/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c +++ b/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -242,26 +242,26 @@ gatts_gap_event(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_LINK_ESTAB: /* A new connection was established or a connection attempt failed */ ESP_LOGI(tag, "connection %s; status = %d ", - event->connect.status == 0 ? "established" : "failed", - event->connect.status); + event->link_estab.status == 0 ? "established" : "failed", + event->link_estab.status); rc = ble_att_set_preferred_mtu(PREFERRED_MTU_VALUE); if (rc != 0) { ESP_LOGE(tag, "Failed to set preferred MTU; rc = %d", rc); } - if (event->connect.status != 0) { + if (event->link_estab.status != 0) { /* Connection failed; resume advertising */ gatts_advertise(); } - rc = ble_hs_hci_util_set_data_len(event->connect.conn_handle, + rc = ble_hs_hci_util_set_data_len(event->link_estab.conn_handle, LL_PACKET_LENGTH, LL_PACKET_TIME); if (rc != 0) { ESP_LOGE(tag, "Set packet length failed"); } - conn_handle = event->connect.conn_handle; + conn_handle = event->link_estab.conn_handle; break; case BLE_GAP_EVENT_DISCONNECT: From 408d841dfeb47e76d1e57d49929168b595b3bf6d Mon Sep 17 00:00:00 2001 From: Abhinav Kudnar Date: Mon, 9 Dec 2024 18:14:46 +0800 Subject: [PATCH 04/14] fix(nimble): Changing esp_rom_printf to ESP_LOGI when memory allocation fails --- components/bt/host/nimble/nimble | 2 +- components/bt/porting/mem/bt_osi_mem.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index bac3aa9d4e..7d350d5ed1 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit bac3aa9d4e261b57aa49819fe72bb8e842b9f93f +Subproject commit 7d350d5ed15b2cba936e2a4dc903e3c745a6fd7d diff --git a/components/bt/porting/mem/bt_osi_mem.c b/components/bt/porting/mem/bt_osi_mem.c index d6bb800a49..612099d277 100644 --- a/components/bt/porting/mem/bt_osi_mem.c +++ b/components/bt/porting/mem/bt_osi_mem.c @@ -25,8 +25,8 @@ IRAM_ATTR void *bt_osi_mem_malloc(size_t size) #endif if (!mem) { log_count ++; - if ((log_count % 40) == 0) { - esp_rom_printf("malloc failed (size %zu)",size); + if ((log_count % 100) == 0) { + ESP_EARLY_LOGI("ESP_LOG_INFO","malloc failed (size %zu)",size); log_count = 0; } assert(mem != NULL); From f84739cce0d697f66855d52d466f9e949d28d816 Mon Sep 17 00:00:00 2001 From: Astha Verma Date: Mon, 16 Dec 2024 19:02:01 +0530 Subject: [PATCH 05/14] fix(nimble): Added a function for printing HCI error definition --- components/bt/host/nimble/nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 7d350d5ed1..2b25c70cae 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 7d350d5ed15b2cba936e2a4dc903e3c745a6fd7d +Subproject commit 2b25c70caef314bc9222b63f1c5935bc19616630 From 53744fe62c25bcbf7ab2e07b13eaea57032194c2 Mon Sep 17 00:00:00 2001 From: Astha Verma Date: Wed, 27 Nov 2024 15:13:49 +0530 Subject: [PATCH 06/14] fix(nimble): fix memory leak issue in Blufi example --- .../btc/profile/esp/blufi/include/esp_blufi.h | 1 + .../profile/esp/blufi/nimble_host/esp_blufi.c | 40 ++++++++++++++++++- components/bt/host/nimble/nimble | 2 +- examples/bluetooth/blufi/main/blufi_init.c | 9 +++-- 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/components/bt/common/btc/profile/esp/blufi/include/esp_blufi.h b/components/bt/common/btc/profile/esp/blufi/include/esp_blufi.h index db2203b1e6..862f7bf02f 100644 --- a/components/bt/common/btc/profile/esp/blufi/include/esp_blufi.h +++ b/components/bt/common/btc/profile/esp/blufi/include/esp_blufi.h @@ -44,6 +44,7 @@ void esp_blufi_gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *a /* Initialise gatt server */ int esp_blufi_gatt_svr_init(void); +int esp_blufi_gatt_svr_deinit(void); void esp_blufi_btc_init(void); void esp_blufi_btc_deinit(void); #endif diff --git a/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c b/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c index bd24eb8ba9..184cbe77da 100644 --- a/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c +++ b/components/bt/common/btc/profile/esp/blufi/nimble_host/esp_blufi.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -240,6 +240,32 @@ static void init_gatt_values(void) } +static void deinit_gatt_values(void) +{ + int i = 0; + const struct ble_gatt_svc_def *svc; + const struct ble_gatt_chr_def *chr; + const struct ble_gatt_dsc_def *dsc; + + for (svc = gatt_svr_svcs; svc && svc->uuid; svc++) { + for (chr = svc->characteristics; chr && chr->uuid; chr++) { + if (i < SERVER_MAX_VALUES && gatt_values[i].buf != NULL) { + os_mbuf_free(gatt_values[i].buf); /* Free the buffer */ + gatt_values[i].buf = NULL; /* Nullify the pointer to avoid dangling references */ + } + ++i; + + for (dsc = chr->descriptors; dsc && dsc->uuid; dsc++) { + if (i < SERVER_MAX_VALUES && gatt_values[i].buf != NULL) { + os_mbuf_free(gatt_values[i].buf); /* Free the buffer */ + gatt_values[i].buf = NULL; /* Nullify the pointer to avoid dangling references */ + } + ++i; + } + } + } +} + int esp_blufi_gatt_svr_init(void) { int rc; @@ -260,6 +286,18 @@ int esp_blufi_gatt_svr_init(void) return 0; } +int esp_blufi_gatt_svr_deinit(void) +{ + deinit_gatt_values(); + + ble_gatts_free_svcs(); + /* Deinitialize BLE GATT and GAP services */ + ble_svc_gatt_deinit(); + ble_svc_gap_deinit(); + + return 0; +} + static int esp_blufi_gap_event(struct ble_gap_event *event, void *arg) { diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 2b25c70cae..41df5f2e69 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 2b25c70caef314bc9222b63f1c5935bc19616630 +Subproject commit 41df5f2e69508de5fc67891ee53583c1021423f5 diff --git a/examples/bluetooth/blufi/main/blufi_init.c b/examples/bluetooth/blufi/main/blufi_init.c index 8361a4d168..fcea8c468d 100644 --- a/examples/bluetooth/blufi/main/blufi_init.c +++ b/examples/bluetooth/blufi/main/blufi_init.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -233,14 +233,17 @@ esp_err_t esp_blufi_host_deinit(void) { esp_err_t ret = ESP_OK; + esp_blufi_gatt_svr_deinit(); ret = nimble_port_stop(); - + if (ret != ESP_OK) { + return ret; + } if (ret == 0) { esp_nimble_deinit(); } ret = esp_blufi_profile_deinit(); - if(ret != ESP_OK) { + if (ret != ESP_OK) { return ret; } From 0aab10f023c5bc6efe237a483c3f73bdb2876819 Mon Sep 17 00:00:00 2001 From: shreeyash Date: Wed, 30 Oct 2024 17:03:49 +0530 Subject: [PATCH 07/14] fix(nimble): Updated peer OTA address type --- components/bt/host/nimble/nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 41df5f2e69..307f7b9c83 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 41df5f2e69508de5fc67891ee53583c1021423f5 +Subproject commit 307f7b9c83d7cb6c2e3e853bcc7671cd15e8b999 From b5dd19e613d3657eb92fde319ada1d6cccdf0f0b Mon Sep 17 00:00:00 2001 From: Shreeyash Date: Tue, 17 Dec 2024 16:32:47 +0530 Subject: [PATCH 08/14] fix(nimble): Added a check for invalid offset --- components/bt/host/nimble/nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 307f7b9c83..fc8d244eae 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 307f7b9c83d7cb6c2e3e853bcc7671cd15e8b999 +Subproject commit fc8d244eaeea78615f956c4d7433d9d2faf2c5b5 From 0dc38beb8156b70e520998a64b8e7052a9b3e6c4 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Mon, 14 Oct 2024 14:58:33 +0530 Subject: [PATCH 09/14] fix(nimble): Fix compilation issues when BLE_MAX_STORE_BOND is set to 0 --- components/bt/host/nimble/nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index fc8d244eae..3c8aa5456e 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit fc8d244eaeea78615f956c4d7433d9d2faf2c5b5 +Subproject commit 3c8aa5456efefabe0f7343fae6512a0ee51b48dd From 8108f35850a460768b542e565df1ca48ceda6257 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Tue, 24 Dec 2024 21:08:18 +0530 Subject: [PATCH 10/14] fix(nimble): Add ATT Tx queue cleanup during link disconnection --- components/bt/host/nimble/nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 3c8aa5456e..fc1eac6774 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 3c8aa5456efefabe0f7343fae6512a0ee51b48dd +Subproject commit fc1eac6774dc62834471ecf62d11cefd34c5ae40 From 594137b0e34d0918087055ddbb4417ee9fe978df Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Fri, 13 Dec 2024 10:38:06 +0530 Subject: [PATCH 11/14] fix(nimble): Fix compilation issue for combination of Ext Adv and Reattempt conn flag --- components/bt/host/nimble/nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index fc1eac6774..ff017e5b74 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit fc1eac6774dc62834471ecf62d11cefd34c5ae40 +Subproject commit ff017e5b749b666e5cade6f69acd930cb95a06a9 From c28509987c7196db25c3dad73b2abcb6e4941444 Mon Sep 17 00:00:00 2001 From: Abhinav Kudnar Date: Wed, 3 Jul 2024 16:13:33 +0530 Subject: [PATCH 12/14] fix(nimble): Save the gatt context in case of preemption --- components/bt/host/nimble/Kconfig.in | 9 +++++++++ components/bt/host/nimble/nimble | 2 +- .../bt/host/nimble/port/include/esp_nimble_cfg.h | 10 +++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/components/bt/host/nimble/Kconfig.in b/components/bt/host/nimble/Kconfig.in index 48bb902e2e..73536c0cf4 100644 --- a/components/bt/host/nimble/Kconfig.in +++ b/components/bt/host/nimble/Kconfig.in @@ -1072,6 +1072,15 @@ config BT_NIMBLE_HOST_QUEUE_CONG_CHECK 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. +config BT_NIMBLE_GATTC_PROC_PREEMPTION_PROTECT + bool "Gatt-proc preemption protect check" + depends on BT_NIMBLE_ENABLED + default n + help + When BLE and Wireless protocol/IEEE 802.15.4 operate in coexistence, BLE preemption + can disrupt the GATT context,causing the service discovery callback to not be invoked. + A temporary list is maintained to preserve the GATT context and use it in case of preemption. + menu "Host-controller Transport" config BT_NIMBLE_TRANSPORT_UART bool "Enable Uart Transport" diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index ff017e5b74..4cf7d046d3 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit ff017e5b749b666e5cade6f69acd930cb95a06a9 +Subproject commit 4cf7d046d3b8e3a572224abe25b8d93a40658ca2 diff --git a/components/bt/host/nimble/port/include/esp_nimble_cfg.h b/components/bt/host/nimble/port/include/esp_nimble_cfg.h index 6db93500be..4be2da745c 100644 --- a/components/bt/host/nimble/port/include/esp_nimble_cfg.h +++ b/components/bt/host/nimble/port/include/esp_nimble_cfg.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -1953,6 +1953,14 @@ #endif #endif +#ifndef MYNEWT_VAL_BLE_GATTC_PROC_PREEMPTION_PROTECT +#ifdef CONFIG_BT_NIMBLE_GATTC_PROC_PREEMPTION_PROTECT +#define MYNEWT_VAL_BLE_GATTC_PROC_PREEMPTION_PROTECT CONFIG_BT_NIMBLE_GATTC_PROC_PREEMPTION_PROTECT +#else +#define MYNEWT_VAL_BLE_GATTC_PROC_PREEMPTION_PROTECT (0) +#endif +#endif + #ifndef MYNEWT_VAL_BLE_HOST_ALLOW_CONNECT_WITH_SCAN #ifdef CONFIG_BT_NIMBLE_HOST_ALLOW_CONNECT_WITH_SCAN #define MYNEWT_VAL_BLE_HOST_ALLOW_CONNECT_WITH_SCAN CONFIG_BT_NIMBLE_HOST_ALLOW_CONNECT_WITH_SCAN From 8163aa849612ae6067755ba84b9744271fc88daf Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Mon, 2 Dec 2024 11:17:46 +0530 Subject: [PATCH 13/14] fix(nimble): Address few coverity reported issues 1. Overflowed constant (INTEGER_OVERFLOW): Added change to typecast value 2. Structurally dead code: Removed dead code 3. Resource leak: Added a free for allocated memory, in case of failure 4. too_few_printf_args: Corrected print statement to pass arguments 5. Fixed nesting levels 6. Fixed unused value warnings 7. Illegal memory access fix --- components/bt/common/osi/pkt_queue.c | 1 + components/bt/host/nimble/nimble | 2 +- components/wifi_provisioning/src/scheme_ble.c | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/components/bt/common/osi/pkt_queue.c b/components/bt/common/osi/pkt_queue.c index 81abd1f043..4c149be2c6 100644 --- a/components/bt/common/osi/pkt_queue.c +++ b/components/bt/common/osi/pkt_queue.c @@ -25,6 +25,7 @@ struct pkt_queue *pkt_queue_create(void) } if (osi_mutex_new(&queue->lock) != 0) { osi_free(queue); + return NULL; } struct pkt_queue_header *p = &queue->header; STAILQ_INIT(p); diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 4cf7d046d3..16d59c062d 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 4cf7d046d3b8e3a572224abe25b8d93a40658ca2 +Subproject commit 16d59c062d498b7db210d9dc57255ac5d1d945ad diff --git a/components/wifi_provisioning/src/scheme_ble.c b/components/wifi_provisioning/src/scheme_ble.c index 0ab935c018..0ede4934c0 100644 --- a/components/wifi_provisioning/src/scheme_ble.c +++ b/components/wifi_provisioning/src/scheme_ble.c @@ -227,6 +227,7 @@ static esp_err_t set_config_endpoint(void *config, const char *endpoint_name, ui realloc(ble_config->nu_lookup, (ble_config->nu_lookup_count + 1) * sizeof(protocomm_ble_name_uuid_t))); if (!lookup_table) { ESP_LOGE(TAG, "Error allocating memory for EP-UUID lookup table"); + free(copy_ep_name); return ESP_ERR_NO_MEM; } From 71b0d14b21f6b5281b5c4ed9a5568b5f2e7c9cd1 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Fri, 29 Nov 2024 14:41:14 +0530 Subject: [PATCH 14/14] fix(nimble): Fix compilation issue in esp_hid_host example --- .../esp_hid_host/main/esp_hid_host_main.c | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/examples/bluetooth/esp_hid_host/main/esp_hid_host_main.c b/examples/bluetooth/esp_hid_host/main/esp_hid_host_main.c index 5b71af00f7..03e255d3ab 100644 --- a/examples/bluetooth/esp_hid_host/main/esp_hid_host_main.c +++ b/examples/bluetooth/esp_hid_host/main/esp_hid_host_main.c @@ -55,7 +55,8 @@ static const char *TAG = "ESP_HIDH_DEMO"; static const char * remote_device_name = CONFIG_EXAMPLE_PEER_DEVICE_NAME; #endif // CONFIG_BT_HID_HOST_ENABLED -static char *bda2str(esp_bd_addr_t bda, char *str, size_t size) +#if !CONFIG_BT_NIMBLE_ENABLED +static char *bda2str(uint8_t *bda, char *str, size_t size) { if (bda == NULL || str == NULL || size < 18) { return NULL; @@ -66,6 +67,7 @@ static char *bda2str(esp_bd_addr_t bda, char *str, size_t size) p[0], p[1], p[2], p[3], p[4], p[5]); return str; } +#endif void hidh_callback(void *handler_args, esp_event_base_t base, int32_t id, void *event_data) { @@ -201,7 +203,6 @@ void ble_store_config_init(void); #endif void app_main(void) { - char bda_str[18] = {0}; esp_err_t ret; #if HID_HOST_MODE == HIDH_IDLE_MODE ESP_LOGE(TAG, "Please turn on BT HID host or BLE!"); @@ -225,7 +226,12 @@ void app_main(void) }; ESP_ERROR_CHECK( esp_hidh_init(&config) ); +#if !CONFIG_BT_NIMBLE_ENABLED + char bda_str[18] = {0}; ESP_LOGI(TAG, "Own address:[%s]", bda2str((uint8_t *)esp_bt_dev_get_address(), bda_str, sizeof(bda_str))); +#endif + + #if CONFIG_BT_NIMBLE_ENABLED /* XXX Need to have template for store */ ble_store_config_init(); @@ -236,6 +242,28 @@ void app_main(void) if (ret) { ESP_LOGE(TAG, "esp_nimble_enable failed: %d", ret); } + + vTaskDelay(200); + + uint8_t own_addr_type = 0; + int rc; + uint8_t addr_val[6] = {0}; + + rc = ble_hs_id_copy_addr(BLE_ADDR_PUBLIC, NULL, NULL); + + rc = ble_hs_id_infer_auto(0, &own_addr_type); + + if (rc != 0) { + ESP_LOGI(TAG, "error determining address type; rc=%d\n", rc); + return; + } + + rc = ble_hs_id_copy_addr(own_addr_type, addr_val, NULL); + + ESP_LOGI(TAG, "Device Address: "); + ESP_LOGI(TAG, "%02x:%02x:%02x:%02x:%02x:%02x \n", addr_val[5], addr_val[4], addr_val[3], + addr_val[2], addr_val[1], addr_val[0]); + #endif xTaskCreate(&hid_demo_task, "hid_task", 6 * 1024, NULL, 2, NULL); }