From c05421bd88c52049bc48118214967ba757af673e Mon Sep 17 00:00:00 2001 From: Shreeyash Date: Wed, 5 Mar 2025 19:42:56 +0530 Subject: [PATCH] feat(nimble): support vendor event mask set and vendor HCI event on nimble host --- components/bt/host/nimble/nimble | 2 +- .../nimble/power_save/main/Kconfig.projbuild | 11 ++++++++ .../bluetooth/nimble/power_save/main/main.c | 25 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index c67396bad6..d6fbbc7d55 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit c67396bad6bd4ea23334874b6a9733caee3c7a80 +Subproject commit d6fbbc7d555f00cc55d3cc2455c151d9cff5380a diff --git a/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild b/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild index 654baec1d5..028ddfc561 100644 --- a/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild +++ b/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild @@ -160,4 +160,15 @@ menu "Example Configuration" help Used for internal test ONLY. Use this option to advertise in a specific random address. + + config EXAMPLE_SLEEP_WAKEUP + bool "Enable Vendor-Specific Sleep Wake-Up Event" + depends on BT_NIMBLE_VS_SUPPORT + default n + help + When enabled, the Nimble Host allows setting a Vendor-Specific + Event Mask for processing sleep wake-up events from the controller. + The controller sends a wake-up event (HCI_LE_SLEEP_WAKE_UP 0xFF 0xC3) + when it resumes from sleep. + endmenu diff --git a/examples/bluetooth/nimble/power_save/main/main.c b/examples/bluetooth/nimble/power_save/main/main.c index c7c385874c..361070a3cd 100644 --- a/examples/bluetooth/nimble/power_save/main/main.c +++ b/examples/bluetooth/nimble/power_save/main/main.c @@ -56,6 +56,10 @@ static uint8_t own_addr_type; void ble_store_config_init(void); +#if MYNEWT_VAL(BLE_HCI_VS) +static struct ble_gap_event_listener vs_event_listener; +#endif + #if MYNEWT_VAL(BLE_POWER_CONTROL) static struct ble_gap_event_listener power_control_event_listener; #endif @@ -144,6 +148,13 @@ ext_bleprph_advertise(void) /* start advertising */ rc = ble_gap_ext_adv_start(instance, 0, 0); assert (rc == 0); + +#if CONFIG_EXAMPLE_SLEEP_WAKEUP + rc = ble_hs_send_vs_event_mask(ESP_BLE_VENDOR_SLEEP_WAKEUP_EVT_MASK); + + rc = ble_gap_event_listener_register(&vs_event_listener, + bleprph_gap_event,NULL); +#endif } #else /** @@ -443,6 +454,20 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) } return 0; +#if CONFIG_EXAMPLE_SLEEP_WAKEUP + case BLE_GAP_EVENT_VS_HCI: + const struct ble_hci_ev_vs *ev = event->vs_hci.ev; + + switch(ev->id) { + case BLE_HCI_VS_SUBEV_LE_SLEEP_WAKE_UP: + MODLOG_DFLT(INFO, "Got Sleep wake up "); + break; + + default: + break; + } +#endif + } return 0;