From 0a221c0693af1c67622d0d10a9a96c0bd976b83a 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 8742373be..c94d81eb5 100644 --- a/nimble/host/include/host/ble_esp_gap.h +++ b/nimble/host/include/host/ble_esp_gap.h @@ -30,6 +30,13 @@ typedef enum gap_status gap_status_t; #define BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_PROV_SRV_ADV 3 #define BLE_DUPLICATE_SCAN_EXCEPTIONAL_INFO_MESH_PROXY_SRV_ADV 4 +#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 @@ -274,6 +281,20 @@ int ble_gap_set_chan_select(uint8_t select); 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 0f7afdd53..a5cb10436 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -8663,6 +8663,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 bf86bc560..62ac9e8e7 100644 --- a/nimble/include/nimble/hci_common.h +++ b/nimble/include/nimble/hci_common.h @@ -1383,6 +1383,11 @@ struct ble_hci_vs_duplicate_exception_list_cp { #define BLE_HCI_OCF_VS_SET_CHAN_SELECT (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x0112)) +#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) @@ -1807,6 +1812,8 @@ struct ble_hci_ev_vs_css_slot_changed { #define BLE_HCI_VS_SUBEV_ID_LLCP_TRACE (0x17) +#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 {