From 1bbc6fb9b810b1afb9f19051dbd5c26bc30f8757 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Mon, 6 Jan 2025 12:02:40 +0530 Subject: [PATCH 1/4] fix(nimble): Clear our and peer security records during unpair --- 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 d7a585dcf0..24333a9dce 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit d7a585dcf0bff149d92e77ab356d091bdfa45982 +Subproject commit 24333a9dcefe8c2ebe6c4683a3605187cd3d4753 From d9de2b7ddeb6f368e5bc562b2932544264dff80c Mon Sep 17 00:00:00 2001 From: Astha Verma Date: Fri, 3 Jan 2025 10:36:01 +0530 Subject: [PATCH 2/4] fix(nimble): Added HCI_Read_Remote_Version_Information command --- 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 24333a9dce..5d7de020d3 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 24333a9dcefe8c2ebe6c4683a3605187cd3d4753 +Subproject commit 5d7de020d3d214f9432ece0147c853c65f342f3c From 99af3abadf36a4846bf16b80f4fd452e06dc8089 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Wed, 8 Jan 2025 20:28:37 +0530 Subject: [PATCH 3/4] fix(nimble): Fixed a typo in Kconfig file --- components/bt/host/nimble/Kconfig.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/host/nimble/Kconfig.in b/components/bt/host/nimble/Kconfig.in index 73536c0cf4..2c04d87d6d 100644 --- a/components/bt/host/nimble/Kconfig.in +++ b/components/bt/host/nimble/Kconfig.in @@ -177,7 +177,7 @@ config BT_NIMBLE_SMP_ID_RESET default n help There are tracking risks associated with using a fixed or static IRK. - If enabled this option, Bluedroid will assign a new randomly-generated IRK + If enabled this option, NimBLE will assign a new randomly-generated IRK when all pairing and bonding records are deleted. This would decrease the ability of a previously paired peer to be used to determine whether a device with which it previously shared an IRK is within range. From 3f4dd2bf35abc14d0ad381fb33d337a7785b8828 Mon Sep 17 00:00:00 2001 From: Abhinav Kudnar Date: Thu, 19 Dec 2024 15:13:19 +0800 Subject: [PATCH 4/4] feat(nimble): Additional changes in PAWR IDF Examples/support for ESP IP --- components/bt/host/nimble/nimble | 2 +- .../ble_pawr_adv/ble_pawr_adv/main/main.c | 56 +++++------ .../ble_pawr_adv/sdkconfig.defaults | 21 +---- .../ble_pawr_adv/ble_pawr_sync/main/main.c | 28 +++--- .../ble_pawr_sync/sdkconfig.defaults | 21 +---- .../ble_pawr_adv_conn/main/main.c | 93 ++++++++++--------- .../ble_pawr_adv_conn/sdkconfig.defaults | 23 +---- .../ble_pawr_sync_conn/main/main.c | 67 +++++++------ .../ble_pawr_sync_conn/sdkconfig.defaults | 21 +---- 9 files changed, 135 insertions(+), 197 deletions(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 5d7de020d3..6c53703528 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 5d7de020d3d214f9432ece0147c853c65f342f3c +Subproject commit 6c53703528c6d55d6d7752952c1532610bf8a124 diff --git a/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_adv/main/main.c b/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_adv/main/main.c index 3695bb366c..a9539b5432 100644 --- a/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_adv/main/main.c +++ b/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_adv/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -10,12 +10,13 @@ #include "nimble/nimble_port_freertos.h" #include "host/ble_hs.h" -#define BLE_PAWR_NUM_SUBEVTS (5) -#define BLE_PAWR_SUB_INTERVAL (12) /*!< Interval between subevents (N * 1.25 ms) */ -#define BLE_PAWR_RSP_SLOT_DELAY (1) /*!< The first response slot delay (N * 1.25 ms)*/ +#define BLE_PAWR_EVENT_INTERVAL (600) +#define BLE_PAWR_NUM_SUBEVTS (10) +#define BLE_PAWR_SUB_INTERVAL (44) /*!< Interval between subevents (N * 1.25 ms) */ +#define BLE_PAWR_RSP_SLOT_DELAY (20) /*!< The first response slot delay (N * 1.25 ms)*/ #define BLE_PAWR_RSP_SLOT_SPACING (32) /*!< Time between response slots (N * 0.125 ms) */ -#define BLE_PAWR_NUM_RSP_SLOTS (3) /*!< Number of subevent response slots */ -#define BLE_PAWR_SUB_DATA_LEN (10) +#define BLE_PAWR_NUM_RSP_SLOTS (5) /*!< Number of subevent response slots */ +#define BLE_PAWR_SUB_DATA_LEN (20) #define TAG "NimBLE_BLE_PAwR" @@ -63,29 +64,20 @@ gap_event_cb(struct ble_gap_event *event, void *arg) return 0; case BLE_GAP_EVENT_PER_SUBEV_RESP: - - if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_INCOMPLETE) { - // ESP_LOGI(TAG,"Incomplete response report received, discarding \n"); + if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_COMPLETE) { + ESP_LOGI(TAG, "[Response] subevent:%d, response_slot:%d, data_length:%d", + event->periodic_adv_response.subevent, + event->periodic_adv_response.response_slot, + event->periodic_adv_response.data_length); + const uint8_t *data = event->periodic_adv_response.data; + ESP_LOGI(TAG, "data: 0x%0x, 0x%0x", data[0], data[1]); + } else { + ESP_LOGE(TAG, "[Response] subevent:%d, response_slot:%d, rsp_data status:%d", + event->periodic_adv_response.subevent, + event->periodic_adv_response.response_slot, + event->periodic_adv_response.data_status); } - else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_RX_FAILED) { - // ESP_LOGI(TAG,"Controller failed to received the AUX_SYNC_SUBEVENT_RSP\n"); - } - else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_COMPLETE) { - ESP_LOGI(TAG, "[Response] subevent:%d, response_slot:%d, data_length:%d, data:%x", - event->periodic_adv_response.subevent, - event->periodic_adv_response.response_slot, - event->periodic_adv_response.data_length, - event->periodic_adv_response.data[0]); - } - else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_TRUNCATED) { - // ESP_LOGI(TAG,"Truncated response report received, discarding\n"); - } - else { - ESP_LOGE(TAG,"Invalid data status\n"); - } - return 0; - default: return 0; } @@ -120,8 +112,8 @@ start_periodic_adv(void) params.primary_phy = BLE_HCI_LE_PHY_CODED; params.secondary_phy = BLE_HCI_LE_PHY_1M; params.sid = 0; - params.itvl_min = BLE_GAP_ADV_ITVL_MS(100); - params.itvl_max = BLE_GAP_ADV_ITVL_MS(100); + params.itvl_min = BLE_PAWR_EVENT_INTERVAL; + params.itvl_max = BLE_PAWR_EVENT_INTERVAL; rc = ble_gap_ext_adv_configure(instance, ¶ms, NULL, gap_event_cb, NULL); assert (rc == 0); @@ -147,9 +139,9 @@ start_periodic_adv(void) pparams.itvl_max = BLE_GAP_PERIODIC_ITVL_MS(3000); /* Configure the parameters of PAwR. */ pparams.num_subevents = BLE_PAWR_NUM_SUBEVTS; - pparams.subevent_interval = BLE_GAP_PERIODIC_ITVL_MS(300); - pparams.response_slot_delay = BLE_GAP_PERIODIC_ITVL_MS(80); - pparams.response_slot_spacing = 0xFF; + pparams.subevent_interval = BLE_PAWR_SUB_INTERVAL; + pparams.response_slot_delay = BLE_PAWR_RSP_SLOT_DELAY; + pparams.response_slot_spacing = BLE_PAWR_RSP_SLOT_SPACING; pparams.num_response_slots = BLE_PAWR_NUM_RSP_SLOTS; rc = ble_gap_periodic_adv_configure(instance, &pparams); diff --git a/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_adv/sdkconfig.defaults b/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_adv/sdkconfig.defaults index cfb85a1c81..f243bb3674 100644 --- a/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_adv/sdkconfig.defaults +++ b/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_adv/sdkconfig.defaults @@ -13,23 +13,4 @@ CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS=1 CONFIG_BT_NIMBLE_ROLE_CENTRAL=y CONFIG_BT_NIMBLE_ROLE_OBSERVER=n -CONFIG_BT_CONTROLLER_DISABLED=y - -# -# Host-controller Transport -# -CONFIG_BT_NIMBLE_TRANSPORT_UART_PORT=1 -CONFIG_UART_BAUDRATE_115200=y -CONFIG_BT_NIMBLE_UART_TX_PIN=20 -CONFIG_BT_NIMBLE_UART_RX_PIN=21 -CONFIG_UART_HW_FLOWCTRL_CTS_RTS=n -# CONFIG_BT_NIMBLE_HCI_UART_RTS_PIN=22 -# CONFIG_BT_NIMBLE_HCI_UART_CTS_PIN=23 -# end of Host-controller Transport -# end of NimBLE Options - -# C6 Nordic -# TX: 20 ---- RX -# RX: 21 ---- TX -# RTS: 22 ---- CTS -# CTS: 23 ---- RTS +CONFIG_BT_CONTROLLER_ENABLED=y diff --git a/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_sync/main/main.c b/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_sync/main/main.c index 11ba92ad04..c0a8ef0b60 100644 --- a/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_sync/main/main.c +++ b/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_sync/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -13,7 +13,7 @@ #define TAG "NimBLE_BLE_PAwR" #define TARGET_NAME "Nimble_PAwR" -#define BLE_PAWR_RSP_DATA_LEN (20) +#define BLE_PAWR_RSP_DATA_LEN (16) static uint8_t sub_data_pattern[BLE_PAWR_RSP_DATA_LEN] = {0}; static int create_periodic_sync(struct ble_gap_ext_disc_desc *disc); @@ -22,6 +22,7 @@ static void start_scan(void); static struct ble_hs_adv_fields fields; static bool synced = false; +uint8_t rsp_slot_idx = 0; static int gap_event_cb(struct ble_gap_event *event, void *arg) { @@ -51,20 +52,17 @@ gap_event_cb(struct ble_gap_event *event, void *arg) return 0; case BLE_GAP_EVENT_PERIODIC_REPORT: - if (event->periodic_report.event_counter % 10 == 0) { - // print every 10th event - ESP_LOGI(TAG, "[Periodic Adv Report] handle:%d, rssi:%d, data status:0x%x", - event->periodic_report.sync_handle, event->periodic_report.rssi, - event->periodic_report.data_status); - ESP_LOGI(TAG, "[Periodic Adv Report] event_counter(%d), subevent(%d)", - event->periodic_report.event_counter, event->periodic_report.subevent); - } + ESP_LOGI(TAG, "[Periodic Adv Report] handle:%d, event_counter(%d), subevent(%d)", + event->periodic_report.sync_handle, + event->periodic_report.event_counter, + event->periodic_report.subevent); + rsp_slot_idx += 1; struct ble_gap_periodic_adv_response_params param = { .request_event = event->periodic_report.event_counter, .request_subevent = event->periodic_report.subevent, .response_subevent = event->periodic_report.subevent, - .response_slot = 0 + .response_slot = rsp_slot_idx, }; struct os_mbuf *data = os_msys_get_pkthdr(BLE_PAWR_RSP_DATA_LEN, 0); @@ -79,8 +77,12 @@ gap_event_cb(struct ble_gap_event *event, void *arg) rc = ble_gap_periodic_adv_set_response_data(event->periodic_report.sync_handle, ¶m, data); if (rc) { - ESP_LOGE(TAG, "Set response data failed, subev(%x), rsp_slot(%d), rc(0x%x)", - sub_data_pattern[0], event->periodic_report.subevent, rc); + ESP_LOGE(TAG, "Set response data failed, sync handle: %d, subev(%x), rsp_slot(%d), rc(0x%x)", + event->periodic_report.sync_handle, param.response_subevent, param.response_slot, rc); + } + else{ + ESP_LOGI(TAG, "[RSP Data Set] sync handle: %d, subev(%x), rsp_slot(%d), rc(0x%x)", + event->periodic_report.sync_handle, param.response_subevent, param.response_slot, rc); } os_mbuf_free_chain(data); diff --git a/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_sync/sdkconfig.defaults b/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_sync/sdkconfig.defaults index 83db34e62f..ae461582df 100644 --- a/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_sync/sdkconfig.defaults +++ b/examples/bluetooth/nimble/ble_pawr_adv/ble_pawr_sync/sdkconfig.defaults @@ -13,23 +13,4 @@ CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS=1 CONFIG_BT_NIMBLE_ROLE_CENTRAL=n CONFIG_BT_NIMBLE_ROLE_OBSERVER=y -CONFIG_BT_CONTROLLER_DISABLED=y - -# -# Host-controller Transport -# -CONFIG_BT_NIMBLE_TRANSPORT_UART_PORT=1 -CONFIG_UART_BAUDRATE_115200=y -CONFIG_BT_NIMBLE_UART_TX_PIN=20 -CONFIG_BT_NIMBLE_UART_RX_PIN=21 -CONFIG_UART_HW_FLOWCTRL_CTS_RTS=n -# CONFIG_BT_NIMBLE_HCI_UART_RTS_PIN=22 -# CONFIG_BT_NIMBLE_HCI_UART_CTS_PIN=23 -# end of Host-controller Transport -# end of NimBLE Options - -# C6 Nordic -# TX: 20 ---- RX -# RX: 21 ---- TX -# RTS: 22 ---- CTS -# CTS: 23 ---- RTS +CONFIG_BT_CONTROLLER_ENABLED=y diff --git a/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_adv_conn/main/main.c b/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_adv_conn/main/main.c index 8d428352b1..425de7e90a 100644 --- a/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_adv_conn/main/main.c +++ b/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_adv_conn/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -10,14 +10,15 @@ #include "nimble/nimble_port_freertos.h" #include "host/ble_hs.h" -#define BLE_PAWR_NUM_SUBEVTS (5) -#define BLE_PAWR_SUB_INTERVAL (12) /*!< Interval between subevents (N * 1.25 ms) */ -#define BLE_PAWR_RSP_SLOT_DELAY (1) /*!< The first response slot delay (N * 1.25 ms)*/ -#define BLE_PAWR_RSP_SLOT_SPACING (32) /*!< Time between response slots (N * 0.125 ms) */ -#define BLE_PAWR_NUM_RSP_SLOTS (3) /*!< Number of subevent response slots */ -#define BLE_PAWR_SUB_DATA_LEN (10) +#define BLE_PAWR_EVENT_INTERVAL (520) +#define BLE_PAWR_NUM_SUBEVTS (10) +#define BLE_PAWR_SUB_INTERVAL (52) /*!< Interval between subevents (N * 1.25 ms) */ +#define BLE_PAWR_RSP_SLOT_DELAY (5) /*!< The first response slot delay (N * 1.25 ms)*/ +#define BLE_PAWR_RSP_SLOT_SPACING (10) /*!< Time between response slots (N * 0.125 ms) */ +#define BLE_PAWR_NUM_RSP_SLOTS (25) /*!< Number of subevent response slots */ +#define BLE_PAWR_SUB_DATA_LEN (20) -#define TAG "NimBLE_BLE_PAwR" +#define TAG "NimBLE_BLE_PAwR_CONN" static struct ble_gap_set_periodic_adv_subev_data_params sub_data_params[BLE_PAWR_NUM_SUBEVTS]; static uint8_t sub_data_pattern[BLE_PAWR_SUB_DATA_LEN] = {0}; @@ -71,18 +72,28 @@ gap_event_cb(struct ble_gap_event *event, void *arg) uint8_t phy_mask; switch (event->type) { - case BLE_GAP_EVENT_CONNECT: - printf("\n"); - ESP_LOGI(TAG, "Connection established, conn_handle = 0x%02x, Adv handle = 0x%0x, status = 0x%0x\n",event->connect.conn_handle,event->connect.adv_handle, event->connect.status); - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); - if(rc == 0){ - print_conn_desc(&desc); - } - else{ - ESP_LOGE(TAG,"Failed to find Conn Information"); - } - return 0; + case BLE_GAP_EVENT_LINK_ESTAB: + if (event->link_estab.status == 0) { + ESP_LOGI(TAG, "[Connection established], conn_handle = 0x%02x, Adv handle = 0x%0x, status = 0x%0x\n",event->link_estab.conn_handle, event->link_estab.adv_handle, event->link_estab.status); + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + if (rc == 0) { + print_conn_desc(&desc); + } + else{ + ESP_LOGE(TAG,"Failed to find Conn Information"); + } + } else { + ESP_LOGW(TAG, "[Connection Failed], conn_handle = 0x%02x, Adv handle = 0x%0x, status = 0x%0x\n",event->link_estab.conn_handle, event->link_estab.adv_handle, event->link_estab.status); + conn = 0; + } + + return 0; + case BLE_GAP_EVENT_DISCONNECT: + ESP_LOGI(TAG, "[Disconnected], conn_handle = 0x%02x, status = 0x%0x\n",event->disconnect.conn.conn_handle,event->disconnect.reason); + conn = 0; + return 0; + case BLE_GAP_EVENT_PER_SUBEV_DATA_REQ: ESP_LOGI(TAG, "[Request] data: %x, subevt start:%d, subevt count:%d", sub_data_pattern[0], @@ -115,20 +126,17 @@ gap_event_cb(struct ble_gap_event *event, void *arg) case BLE_GAP_EVENT_PER_SUBEV_RESP: - if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_INCOMPLETE) { - // ESP_LOGI(TAG,"Incomplete response report received, discarding \n"); - } - else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_RX_FAILED) { - // ESP_LOGI(TAG,"Controller failed to received the AUX_SYNC_SUBEVENT_RSP\n"); - } - else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_COMPLETE) { - ESP_LOGI(TAG, "[Response] subevent:%d, response_slot:%d, data_length:%d, data:%x", + if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_COMPLETE) { + ESP_LOGI(TAG, "[Response] subevent:%d, response_slot:%d, data_length:%d", event->periodic_adv_response.subevent, event->periodic_adv_response.response_slot, - event->periodic_adv_response.data_length, - event->periodic_adv_response.data[0]); + event->periodic_adv_response.data_length); + const uint8_t *data = event->periodic_adv_response.data; + ESP_LOGI(TAG, "data: 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x", + data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9]); + peer_addr.type=0; - memcpy(peer_addr.val,&event->periodic_adv_response.data[1],6); + memcpy(peer_addr.val,&event->periodic_adv_response.data[2],6); adv_handle = event->periodic_adv_response.adv_handle; subevent = event->periodic_adv_response.subevent; @@ -138,15 +146,16 @@ gap_event_cb(struct ble_gap_event *event, void *arg) rc = ble_gap_connect_with_synced(0,adv_handle,subevent,&peer_addr,30000,phy_mask,NULL,NULL,NULL,gap_event_cb,NULL); if (rc != 0 ) { ESP_LOGI(TAG,"Error: Failed to connect to device , rc = %d\n",rc); + }else { + ESP_LOGI(TAG,"Connection create sent, adv handle = %d, subevent = %d", adv_handle, subevent); } conn = 1; } - } - else if (event->periodic_adv_response.data_status == BLE_GAP_PER_ADV_DATA_STATUS_TRUNCATED) { - // ESP_LOGI(TAG,"Truncated response report received, discarding\n"); - } - else { - ESP_LOGE(TAG,"Invalid data status\n"); + } else { + ESP_LOGE(TAG, "[Response] subevent:%d, response_slot:%d, rsp_data status:%d", + event->periodic_adv_response.subevent, + event->periodic_adv_response.response_slot, + event->periodic_adv_response.data_status); } return 0; @@ -185,14 +194,14 @@ start_periodic_adv(void) params.primary_phy = BLE_HCI_LE_PHY_CODED; params.secondary_phy = BLE_HCI_LE_PHY_1M; params.sid = 0; - params.itvl_min = BLE_GAP_ADV_ITVL_MS(100); - params.itvl_max = BLE_GAP_ADV_ITVL_MS(100); + params.itvl_min = BLE_GAP_ADV_ITVL_MS(50); + params.itvl_max = BLE_GAP_ADV_ITVL_MS(50); rc = ble_gap_ext_adv_configure(instance, ¶ms, NULL, gap_event_cb, NULL); assert (rc == 0); memset(&adv_fields, 0, sizeof(adv_fields)); - adv_fields.name = (const uint8_t *)"Nimble_PAwR"; + adv_fields.name = (const uint8_t *)"Nimble_PAwR_CONN"; adv_fields.name_len = strlen((char *)adv_fields.name); /* mbuf chain will be increased if needed */ @@ -212,9 +221,9 @@ start_periodic_adv(void) pparams.itvl_max = BLE_GAP_PERIODIC_ITVL_MS(3000); /* Configure the parameters of PAwR. */ pparams.num_subevents = BLE_PAWR_NUM_SUBEVTS; - pparams.subevent_interval = BLE_GAP_PERIODIC_ITVL_MS(300); - pparams.response_slot_delay = BLE_GAP_PERIODIC_ITVL_MS(80); - pparams.response_slot_spacing = 0xFF; + pparams.subevent_interval = BLE_PAWR_SUB_INTERVAL; + pparams.response_slot_delay = BLE_PAWR_RSP_SLOT_DELAY; + pparams.response_slot_spacing = BLE_PAWR_RSP_SLOT_SPACING; pparams.num_response_slots = BLE_PAWR_NUM_RSP_SLOTS; rc = ble_gap_periodic_adv_configure(instance, &pparams); diff --git a/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_adv_conn/sdkconfig.defaults b/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_adv_conn/sdkconfig.defaults index 20b00aad69..f243bb3674 100644 --- a/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_adv_conn/sdkconfig.defaults +++ b/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_adv_conn/sdkconfig.defaults @@ -10,26 +10,7 @@ CONFIG_BT_NIMBLE_ENABLED=y CONFIG_BT_NIMBLE_EXT_ADV=y CONFIG_BT_NIMBLE_PERIODIC_ADV_WITH_RESPONSES=y CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS=1 -CONFIG_BT_NIMBLE_ROLE_CENTRAL=n +CONFIG_BT_NIMBLE_ROLE_CENTRAL=y CONFIG_BT_NIMBLE_ROLE_OBSERVER=n -CONFIG_BT_CONTROLLER_DISABLED=y - -# -# Host-controller Transport -# -CONFIG_BT_NIMBLE_TRANSPORT_UART_PORT=1 -CONFIG_UART_BAUDRATE_115200=y -CONFIG_BT_NIMBLE_UART_TX_PIN=20 -CONFIG_BT_NIMBLE_UART_RX_PIN=21 -CONFIG_UART_HW_FLOWCTRL_CTS_RTS=n -# CONFIG_BT_NIMBLE_HCI_UART_RTS_PIN=22 -# CONFIG_BT_NIMBLE_HCI_UART_CTS_PIN=23 -# end of Host-controller Transport -# end of NimBLE Options - -# C6 Nordic -# TX: 20 ---- RX -# RX: 21 ---- TX -# RTS: 22 ---- CTS -# CTS: 23 ---- RTS +CONFIG_BT_CONTROLLER_ENABLED=y diff --git a/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_sync_conn/main/main.c b/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_sync_conn/main/main.c index badce40af7..a67d24a765 100644 --- a/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_sync_conn/main/main.c +++ b/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_sync_conn/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -11,9 +11,9 @@ #include "host/ble_hs.h" #include "host/util/util.h" -#define TAG "NimBLE_BLE_PAwR" -#define TARGET_NAME "Nimble_PAwR" -#define BLE_PAWR_RSP_DATA_LEN (20) +#define TAG "NimBLE_BLE_PAwR_CONN" +#define TARGET_NAME "Nimble_PAwR_CONN" +#define BLE_PAWR_RSP_DATA_LEN (10) static uint8_t sub_data_pattern[BLE_PAWR_RSP_DATA_LEN] = {0}; static int create_periodic_sync(struct ble_gap_ext_disc_desc *disc); @@ -65,16 +65,25 @@ gap_event_cb(struct ble_gap_event *event, void *arg) struct ble_gap_ext_disc_desc *disc; switch (event->type) { - case BLE_GAP_EVENT_CONNECT: - ESP_LOGI(TAG, "Connection established, conn_handle = 0x%0x, sync handle= 0x%02x, status = 0x%0x\n",event->connect.conn_handle, event->connect.sync_handle, event->connect.status); - rc = ble_gap_conn_find(event->connect.conn_handle, &desc); - if(rc == 0){ + case BLE_GAP_EVENT_LINK_ESTAB: + if (event->link_estab.status == 0) { + ESP_LOGI(TAG, "Connection established, conn_handle = 0x%0x, sync handle= 0x%02x, status = 0x%0x\n",event->link_estab.conn_handle, event->link_estab.sync_handle, event->link_estab.status); + rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + if (rc == 0) { print_conn_desc(&desc); - } - else{ + } + else{ ESP_LOGE(TAG,"Failed to find Conn Information"); - } - return 0; + } + } else{ + ESP_LOGW(TAG, "[Connection Failed], conn_handle = 0x%02x, sync handle = 0x%0x, status = 0x%0x\n",event->link_estab.conn_handle, event->link_estab.sync_handle, event->link_estab.status); + } + return 0; + + case BLE_GAP_EVENT_DISCONNECT: + ESP_LOGW(TAG, "[Disconnected], conn_handle = 0x%02x, status = 0x%0x\n",event->disconnect.conn.conn_handle,event->disconnect.reason); + return 0; + case BLE_GAP_EVENT_EXT_DISC: disc = &event->ext_disc; addr = disc->addr.val; @@ -90,26 +99,22 @@ gap_event_cb(struct ble_gap_event *event, void *arg) return 0; } - if (disc->periodic_adv_itvl && fields.name_len && !memcmp(fields.name, TARGET_NAME, strlen(TARGET_NAME))) { + if (fields.name_len && !memcmp(fields.name, TARGET_NAME, strlen(TARGET_NAME))) { create_periodic_sync(disc); } return 0; case BLE_GAP_EVENT_PERIODIC_REPORT: - if (event->periodic_report.event_counter % 10 == 0) { - // print every 10th event - ESP_LOGI(TAG, "[Periodic Adv Report] handle:%d, rssi:%d, data status:0x%x", - event->periodic_report.sync_handle, event->periodic_report.rssi, - event->periodic_report.data_status); - ESP_LOGI(TAG, "[Periodic Adv Report] event_counter(%d), subevent(%d)", - event->periodic_report.event_counter, event->periodic_report.subevent); - } + ESP_LOGI(TAG, "[Periodic Adv Report] handle:%d, event_counter(%d), subevent(%d)", + event->periodic_report.sync_handle, + event->periodic_report.event_counter, + event->periodic_report.subevent); struct ble_gap_periodic_adv_response_params param = { .request_event = event->periodic_report.event_counter, .request_subevent = event->periodic_report.subevent, .response_subevent = event->periodic_report.subevent, - .response_slot = 0 + .response_slot = 2, }; struct os_mbuf *data = os_msys_get_pkthdr(BLE_PAWR_RSP_DATA_LEN, 0); @@ -118,16 +123,22 @@ gap_event_cb(struct ble_gap_event *event, void *arg) return 0; } // create a special data for checking manually in ADV side - sub_data_pattern[0] = event->periodic_report.data[0]; + + sub_data_pattern[0] = event->periodic_report.subevent; rc = ble_hs_id_copy_addr(BLE_ADDR_PUBLIC, device_addr, NULL); - memset(sub_data_pattern + 1, event->periodic_report.subevent, BLE_PAWR_RSP_DATA_LEN - 1); - memcpy(sub_data_pattern + 1,device_addr,BLE_DEV_ADDR_LEN); + sub_data_pattern[1] = param.response_slot; + memcpy(&sub_data_pattern[2],device_addr,BLE_DEV_ADDR_LEN); + os_mbuf_append(data, sub_data_pattern, BLE_PAWR_RSP_DATA_LEN); rc = ble_gap_periodic_adv_set_response_data(event->periodic_report.sync_handle, ¶m, data); if (rc) { - ESP_LOGE(TAG, "Set response data failed, subev(%x), rsp_slot(%d), rc(0x%x)", - sub_data_pattern[0], event->periodic_report.subevent, rc); + ESP_LOGE(TAG, "Set response data failed, sync handle: %d, subev(%x), rsp_slot(%d), rc(0x%x)", + event->periodic_report.sync_handle, param.response_subevent, param.response_slot, rc); + } else { + ESP_LOGW(TAG, "[RSP Data Set] sync handle: %d, subev(%x), rsp_slot(%d), rc(0x%x)", + event->periodic_report.sync_handle, param.response_subevent, param.response_slot, rc); + } os_mbuf_free_chain(data); @@ -151,7 +162,7 @@ gap_event_cb(struct ble_gap_event *event, void *arg) ble_gap_disc_cancel(); // choose subevents in range 0 to (num_subevents - 1) - uint8_t subevents[] = {0, 1, 2, 3, 4}; + uint8_t subevents[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int result = ble_gap_periodic_adv_sync_subev(event->periodic_sync.sync_handle, 0, sizeof(subevents), subevents); if (result == ESP_OK) { ESP_LOGI(TAG, "[Subevent Sync OK] sync handle:%d, sync_subevents:%d\n", event->periodic_sync.sync_handle, sizeof(subevents)); diff --git a/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_sync_conn/sdkconfig.defaults b/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_sync_conn/sdkconfig.defaults index 83db34e62f..ae461582df 100644 --- a/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_sync_conn/sdkconfig.defaults +++ b/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_sync_conn/sdkconfig.defaults @@ -13,23 +13,4 @@ CONFIG_BT_NIMBLE_MAX_PERIODIC_SYNCS=1 CONFIG_BT_NIMBLE_ROLE_CENTRAL=n CONFIG_BT_NIMBLE_ROLE_OBSERVER=y -CONFIG_BT_CONTROLLER_DISABLED=y - -# -# Host-controller Transport -# -CONFIG_BT_NIMBLE_TRANSPORT_UART_PORT=1 -CONFIG_UART_BAUDRATE_115200=y -CONFIG_BT_NIMBLE_UART_TX_PIN=20 -CONFIG_BT_NIMBLE_UART_RX_PIN=21 -CONFIG_UART_HW_FLOWCTRL_CTS_RTS=n -# CONFIG_BT_NIMBLE_HCI_UART_RTS_PIN=22 -# CONFIG_BT_NIMBLE_HCI_UART_CTS_PIN=23 -# end of Host-controller Transport -# end of NimBLE Options - -# C6 Nordic -# TX: 20 ---- RX -# RX: 21 ---- TX -# RTS: 22 ---- CTS -# CTS: 23 ---- RTS +CONFIG_BT_CONTROLLER_ENABLED=y