From 022ce314c3bd8ef23e64219271a945de51d194de Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Mon, 12 Jun 2023 16:24:34 +0530 Subject: [PATCH 1/2] Nimble: Add APIs to handle vs HCI commands and events --- components/bt/host/nimble/Kconfig.in | 6 ++++++ components/bt/host/nimble/nimble | 2 +- components/bt/host/nimble/port/include/esp_nimble_cfg.h | 9 ++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/components/bt/host/nimble/Kconfig.in b/components/bt/host/nimble/Kconfig.in index bccac21385..869ccad1f1 100644 --- a/components/bt/host/nimble/Kconfig.in +++ b/components/bt/host/nimble/Kconfig.in @@ -661,3 +661,9 @@ config BT_NIMBLE_BLE_GATT_BLOB_TRANSFER help This option is used when data to be sent is more than 512 bytes. For peripheral role, BT_NIMBLE_MSYS_1_BLOCK_COUNT needs to be increased according to the need. + +config BT_NIMBLE_VS_SUPPORT + bool "Enable support for VSC and VSE" + help + This option is used to enable support for sending Vendor Specific HCI commands and handling + Vendor Specific HCI Events. diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 326292d478..46268fd9c0 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 326292d47806594994f4b98fbeb20619a67132bd +Subproject commit 46268fd9c058fde006427b62b2198ace049b4e5f 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 aa69f6579f..66d85102c4 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-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -1681,4 +1681,11 @@ #endif #endif +#ifndef MYNEWT_VAL_BLE_HCI_VS +#define MYNEWT_VAL_BLE_HCI_VS CONFIG_BT_NIMBLE_VS_SUPPORT +#define MYNEWT_VAL_BLE_HCI_VS_OCF_OFFSET (0) +#else +#define MYNEWT_VAL_BLE_HCI_VS (0) +#endif + #endif From 7c6ab05f5083e1ac27465d74ef59addf1315fe63 Mon Sep 17 00:00:00 2001 From: Rahul Tank Date: Mon, 12 Jun 2023 16:55:52 +0530 Subject: [PATCH 2/2] feat(nimble): Add support for PCL Set RSSI VSC and example code for its usage This commit adds support for sending Vendor Specific HCI commands and handling Vendor Specific HCI Events in the Nimble stack. It also includes the necessary configuration options and APIs to handle these commands and events. The following changes were made: - Added configuration option to enable support for VSC and VSE - Added API to send Vendor Specific HCI commands - Added example code for using the Set RSSI VSC for Power Control This commit also includes some minor code improvements and bug fixes --- components/bt/host/nimble/nimble | 2 +- .../porting/nimble/include/nimble/hci_common.h | 5 +++++ examples/bluetooth/nimble/blecent/main/main.c | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index 46268fd9c0..abc80c36ca 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit 46268fd9c058fde006427b62b2198ace049b4e5f +Subproject commit abc80c36cab77cc47c62b0cdbbcedf53346460c4 diff --git a/components/bt/porting/nimble/include/nimble/hci_common.h b/components/bt/porting/nimble/include/nimble/hci_common.h index 7d350b9ef8..70eb982d4a 100644 --- a/components/bt/porting/nimble/include/nimble/hci_common.h +++ b/components/bt/porting/nimble/include/nimble/hci_common.h @@ -1136,6 +1136,11 @@ struct ble_hci_vs_rd_static_addr_rp { uint8_t addr[6]; } __attribute__((packed)); + +#if SOC_BLE_POWER_CONTROL_SUPPORTED && MYNEWT_VAL(BLE_HCI_VS) +#define BLE_HCI_OCF_VS_PCL_SET_RSSI (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x0111)) +#endif + /* Command Specific Definitions */ /* --- Set controller to host flow control (OGF 0x03, OCF 0x0031) --- */ #define BLE_HCI_CTLR_TO_HOST_FC_OFF (0) diff --git a/examples/bluetooth/nimble/blecent/main/main.c b/examples/bluetooth/nimble/blecent/main/main.c index 81a849a370..8d377b6dfe 100644 --- a/examples/bluetooth/nimble/blecent/main/main.c +++ b/examples/bluetooth/nimble/blecent/main/main.c @@ -671,6 +671,24 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) blecent_power_control(event->connect.conn_handle); #endif +#if MYNEWT_VAL(BLE_HCI_VS) +#if MYNEWT_VAL(BLE_POWER_CONTROL) + int8_t vs_cmd[10]= {0, 0,-70,-60,-68,-58,-75,-65,-80,-70}; + + vs_cmd[0] = ((uint8_t)(event->connect.conn_handle & 0xFF)); + vs_cmd[1] = ((uint8_t)(event->connect.conn_handle >> 8) & 0xFF); + + rc = ble_hs_hci_send_vs_cmd(BLE_HCI_OCF_VS_PCL_SET_RSSI , + &vs_cmd, sizeof(vs_cmd), NULL, 0); + if (rc != 0) { + MODLOG_DFLT(INFO, "Failed to send VSC %x \n", rc); + return 0; + } + else + MODLOG_DFLT(INFO, "Successfully issued VSC , rc = %d \n", rc); +#endif +#endif + #if CONFIG_EXAMPLE_ENCRYPTION /** Initiate security - It will perform * Pairing (Exchange keys)