From d6fbbc7d555f00cc55d3cc2455c151d9cff5380a Mon Sep 17 00:00:00 2001 From: Shreeyash Date: Fri, 7 Mar 2025 12:19:24 +0530 Subject: [PATCH] feat(nimble): support vendor event mask set and vendor HCI event on nimble host --- nimble/host/include/host/ble_esp_gap.h | 21 +++++++++++++++++++++ nimble/host/src/ble_gap.c | 13 +++++++++++++ nimble/include/nimble/hci_common.h | 7 +++++++ 3 files changed, 41 insertions(+) diff --git a/nimble/host/include/host/ble_esp_gap.h b/nimble/host/include/host/ble_esp_gap.h index cc0fda3b9..f5c076963 100644 --- a/nimble/host/include/host/ble_esp_gap.h +++ b/nimble/host/include/host/ble_esp_gap.h @@ -24,6 +24,13 @@ enum gap_status { typedef enum gap_status gap_status_t; +#define ESP_BLE_VENDOR_LEGACY_SCAN_REQ_EVT_MASK BIT(0) +#define ESP_BLE_VENDOR_CHAN_MAP_UPDATE_CMPL_EVT_MASK BIT(1) +#define ESP_BLE_VENDOR_TL_RUNNING_STATUS_EVT_MASK BIT(2) +#define ESP_BLE_VENDOR_SLEEP_WAKEUP_EVT_MASK BIT(3) +#define ESP_BLE_VENDOR_CONNECT_IND_REQ_EVT_MASK BIT(4) +#define ESP_BLE_VENDOR_AUX_CONNECT_RSP_EVT_MASK BIT(5) + #if MYNEWT_VAL(BLE_ENABLE_CONN_REATTEMPT) #ifdef CONFIG_BT_NIMBLE_MAX_CONN_REATTEMPT #define MAX_REATTEMPT_ALLOWED CONFIG_BT_NIMBLE_MAX_CONN_REATTEMPT @@ -110,6 +117,20 @@ int ble_gap_duplicate_exception_list(uint8_t subcode, uint8_t type, uint8_t *val int ble_gap_dev_authorization(uint16_t conn_handle, bool authorized); +/** + * Sets the vendor-specific event mask for BLE host. + * + * This function configures the vendor-specific event mask, enabling or disabling + * specific vendor-defined events from being reported by the controller. + * + * @param event_mask Bitmask representing the events to enable. + * + * @return 0 on success; + * A nonzero value indicating an error if the command fails. + */ +int +ble_hs_send_vs_event_mask(uint32_t event_mask); + void ble_gap_rx_test_evt(const void *buf, uint8_t len); void ble_gap_tx_test_evt(const void *buf, uint8_t len); void ble_gap_end_test_evt(const void *buf, uint8_t len); diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index a200480c8..ebfacc797 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -7987,6 +7987,19 @@ ble_gap_vs_hci_event(const void *buf, uint8_t len) ble_gap_event_listener_call(&event); } + +int +ble_hs_send_vs_event_mask(uint32_t event_mask) +{ + struct ble_hci_vs_set_event_mask_cp cmd; + + /* Populate command */ + cmd.event_mask = htole32(event_mask); + + /* Send command via HCI */ + return ble_hs_hci_send_vs_cmd(BLE_HCI_OCF_VS_SET_EVT_MASK, + &cmd, sizeof(cmd), NULL, 0); +} #endif int diff --git a/nimble/include/nimble/hci_common.h b/nimble/include/nimble/hci_common.h index 239d16480..1b116e339 100644 --- a/nimble/include/nimble/hci_common.h +++ b/nimble/include/nimble/hci_common.h @@ -1199,6 +1199,11 @@ struct ble_hci_vs_duplicate_exception_list_cp { #define BLE_HCI_OCF_VS_LEGACY_ADV_CLEAR (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x010C)) +#define BLE_HCI_OCF_VS_SET_EVT_MASK (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x0116)) +struct ble_hci_vs_set_event_mask_cp { + uint32_t event_mask; +} __attribute__((packed)); + /* Command Specific Definitions */ /* --- Set controller to host flow control (OGF 0x03, OCF 0x0031) --- */ #define BLE_HCI_CTLR_TO_HOST_FC_OFF (0) @@ -1604,6 +1609,8 @@ struct ble_hci_ev_vendor_debug { uint8_t data[0]; } __attribute__((packed)); +#define BLE_HCI_VS_SUBEV_LE_SLEEP_WAKE_UP (0xC3) + /* LE sub-event codes */ #define BLE_HCI_LE_SUBEV_CONN_COMPLETE (0x01) struct ble_hci_ev_le_subev_conn_complete {