From 886039b39b9b3605f7a07ca0fb344d3df99f96b4 Mon Sep 17 00:00:00 2001 From: cjin Date: Thu, 11 Dec 2025 20:27:49 +0800 Subject: [PATCH] feat: add vs cmd support for adv constant did and scan adi filter --- nimble/host/include/host/ble_esp_gap.h | 34 +++++++++++++++++++++++++ nimble/host/include/host/ble_gap.h | 8 ++++++ nimble/host/src/ble_gap.c | 35 ++++++++++++++++++++++++++ nimble/include/nimble/hci_common.h | 2 ++ 4 files changed, 79 insertions(+) diff --git a/nimble/host/include/host/ble_esp_gap.h b/nimble/host/include/host/ble_esp_gap.h index 7a108200b..2c22a8aec 100644 --- a/nimble/host/include/host/ble_esp_gap.h +++ b/nimble/host/include/host/ble_esp_gap.h @@ -279,6 +279,40 @@ int ble_gap_set_chan_select(uint8_t select); */ int ble_gap_set_scan_chan(uint8_t state, uint8_t *bitmap); +#if MYNEWT_VAL(BLE_ADV_SEND_CONSTANT_DID) +/** + * This API is used to make extended adv send with specific DID + * + * @param handle + * @param enable + * @param did + * @return int + */ +int ble_gap_set_adv_constant_did(uint16_t handle, uint8_t enable, uint16_t did); +#endif // MYNEWT_VAL(BLE_ADV_SEND_CONSTANT_DID) + +#if MYNEWT_VAL(BLE_SCAN_ALLOW_ENH_ADI_FILTER) +struct ble_gap_adi_filter_entry { + uint8_t sid; + uint16_t did_cnt; + uint16_t did[0]; +}; + +/** + * This API is used to configure the ADI filter options for the extended scan. + * + * @param enable 0: Disable ADI filtering + * 1: Enable ADI filter + * @param did_filter 0: Enable filter of SID only + * 1: Enable filter of both DID and SID + * @param sid_cnt Number of SID to allow receiving + * @param filter_list Array of filter list pointers to store the SID + * and DID combinations allowed for reception + * @return int + */ +int ble_gap_config_ext_scan_adi_filter(uint8_t enable, uint8_t did_filter, uint8_t sid_cnt, struct ble_gap_adi_filter_entry *filter_list[]); +#endif // MYNEWT_VAL(BLE_SCAN_ALLOW_ENH_ADI_FILTER) + #endif /** diff --git a/nimble/host/include/host/ble_gap.h b/nimble/host/include/host/ble_gap.h index 453f0161b..1dec2d559 100644 --- a/nimble/host/include/host/ble_gap.h +++ b/nimble/host/include/host/ble_gap.h @@ -2686,6 +2686,14 @@ struct ble_gap_set_periodic_adv_subev_data_params { }; #endif +#if MYNEWT_VAL(BLE_ADV_SEND_CONSTANT_DID) +struct ble_gap_adv_const_did_cmd_params { + uint16_t handle; + uint8_t enable; + uint16_t did; +}; +#endif // MYNEWT_VAL(BLE_ADV_SEND_CONSTANT_DID) + /** * Configure periodic advertising for specified advertising instance * diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c index 7eb39cab5..a6dab0a92 100644 --- a/nimble/host/src/ble_gap.c +++ b/nimble/host/src/ble_gap.c @@ -10338,6 +10338,41 @@ int ble_gap_set_scan_chan(uint8_t state, uint8_t *bitmap) return ble_hs_hci_send_vs_cmd(BLE_HCI_OCF_VS_SET_SCAN_CHAN, &vs_cmd, sizeof(vs_cmd), NULL, 0); } + +#if MYNEWT_VAL(BLE_ADV_SEND_CONSTANT_DID) +int ble_gap_set_adv_constant_did(uint16_t handle, uint8_t enable, uint16_t did) +{ + struct ble_gap_adv_const_did_cmd_params vs_cmd; + + vs_cmd.handle = handle; + vs_cmd.enable = enable; + vs_cmd.did = did; + return ble_hs_hci_send_vs_cmd(BLE_HCI_OCF_VS_SET_ADV_DID, + &vs_cmd, sizeof(vs_cmd), NULL, 0); +} +#endif // MYNEWT_VAL(BLE_ADV_SEND_CONSTANT_DID) + +#if MYNEWT_VAL(BLE_SCAN_ALLOW_ENH_ADI_FILTER) +/* filter list in format struct ble_gap_adi_filter_entry */ +int ble_gap_config_ext_scan_adi_filter(uint8_t enable, uint8_t did_filter, uint8_t sid_cnt, + struct ble_gap_adi_filter_entry *filter_list[]) +{ + uint8_t vs_cmd[64]; + + memset(vs_cmd, 0x0, sizeof(vs_cmd)); + if (sid_cnt > 15) { + return BLE_HS_EINVAL; + } + + vs_cmd[0] = enable; + vs_cmd[1] = did_filter; + vs_cmd[2] = sid_cnt; + memcpy(&vs_cmd[3], filter_list, sid_cnt * sizeof(struct ble_gap_adi_filter_entry *)); + + return ble_hs_hci_send_vs_cmd(BLE_HCI_OCF_VS_SET_SCAN_SID, + &vs_cmd, sid_cnt * sizeof(struct ble_gap_adi_filter_entry *) + 3, NULL, 0); +} +#endif // MYNEWT_VAL(BLE_SCAN_ALLOW_ENH_ADI_FILTER) #endif #if MYNEWT_VAL(BLE_UTIL_API) diff --git a/nimble/include/nimble/hci_common.h b/nimble/include/nimble/hci_common.h index 8ed533718..56d86479e 100644 --- a/nimble/include/nimble/hci_common.h +++ b/nimble/include/nimble/hci_common.h @@ -1663,6 +1663,8 @@ struct ble_hci_vs_duplicate_exception_list_cp { #define BLE_HCI_OCF_VS_SET_EVT_MASK (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x0116)) #define BLE_HCI_OCF_VS_SET_SCAN_CHAN (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x0119)) +#define BLE_HCI_OCF_VS_SET_ADV_DID (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x012A)) +#define BLE_HCI_OCF_VS_SET_SCAN_SID (MYNEWT_VAL(BLE_HCI_VS_OCF_OFFSET) + (0x012B)) struct ble_hci_vs_set_event_mask_cp { uint32_t event_mask;