From fd4094e5025aefc21e63d59427b7d62c08e79cd8 Mon Sep 17 00:00:00 2001 From: chenjianhua Date: Sat, 8 Feb 2025 10:16:34 +0800 Subject: [PATCH 1/2] feat(bt/bluedroid): Support BLE setting vendor event mask --- .../bt/host/bluedroid/api/esp_gap_ble_api.c | 18 +++++++++++++++ .../api/include/api/esp_gap_ble_api.h | 23 +++++++++++++++++-- .../bt/host/bluedroid/bta/dm/bta_dm_act.c | 5 ++++ .../bt/host/bluedroid/bta/dm/bta_dm_api.c | 13 +++++++++++ .../bt/host/bluedroid/bta/dm/bta_dm_main.c | 1 + .../bluedroid/bta/dm/include/bta_dm_int.h | 9 ++++++++ .../host/bluedroid/bta/include/bta/bta_api.h | 4 ++++ .../btc/profile/std/gap/btc_gap_ble.c | 22 ++++++++++++++++++ .../btc/profile/std/include/btc_gap_ble.h | 5 ++++ .../bt/host/bluedroid/stack/btm/btm_ble_gap.c | 11 +++++++++ .../bt/host/bluedroid/stack/btm/btm_devctl.c | 8 +++++++ .../bluedroid/stack/btm/include/btm_ble_int.h | 1 + .../bt/host/bluedroid/stack/hcic/hciblecmds.c | 22 ++++++++++++++++++ .../stack/include/stack/btm_ble_api.h | 14 +++++++++++ .../bluedroid/stack/include/stack/hcidefs.h | 3 +++ .../bluedroid/stack/include/stack/hcimsgs.h | 3 +++ 16 files changed, 160 insertions(+), 2 deletions(-) diff --git a/components/bt/host/bluedroid/api/esp_gap_ble_api.c b/components/bt/host/bluedroid/api/esp_gap_ble_api.c index 6cef5e32da..9f5a1f5853 100644 --- a/components/bt/host/bluedroid/api/esp_gap_ble_api.c +++ b/components/bt/host/bluedroid/api/esp_gap_ble_api.c @@ -1774,3 +1774,21 @@ esp_err_t esp_ble_gap_vendor_command_send(esp_ble_vendor_cmd_params_t *vendor_cm return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy, btc_gap_ble_arg_deep_free) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } + +esp_err_t esp_ble_gap_set_vendor_event_mask(uint32_t event_mask) +{ + btc_msg_t msg = {0}; + btc_ble_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_ACT_SET_VENDOR_EVT_MASK; + arg.set_vendor_evt_mask.evt_mask = event_mask; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} diff --git a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h index 9e328bfde6..a28abfa41b 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -230,6 +230,7 @@ typedef enum { ESP_GAP_BLE_VENDOR_CMD_COMPLETE_EVT, /*!< When vendor hci command complete, the event comes */ ESP_GAP_BLE_SET_PRIVACY_MODE_COMPLETE_EVT, /*!< When set privacy mode complete, the event comes */ ESP_GAP_BLE_SET_CSA_SUPPORT_COMPLETE_EVT, /*!< When set CSA support complete, the event comes */ + ESP_GAP_BLE_SET_VENDOR_EVT_MASK_COMPLETE_EVT, /*!< When set vendor event mask complete, the event comes */ ESP_GAP_BLE_EVT_MAX, /*!< when maximum advertising event complete, the event comes */ } esp_gap_ble_cb_event_t; @@ -1580,7 +1581,13 @@ typedef union { */ struct ble_set_csa_support_cmpl_evt_param { esp_bt_status_t status; /*!< Indicate CSA support set operation success status */ - } set_csa_support_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_CSA_SUPPORT_COMPLETE_EVT */ + } set_csa_support_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_CSA_SUPPORT_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_SET_VENDOR_EVT_MASK_COMPLETE_EVT + */ + struct ble_set_vendor_evt_mask_cmpl_evt_param { + esp_bt_status_t status; /*!< Indicate set vendor event mask operation success status */ + } set_vendor_evt_mask_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_VENDOR_EVT_MASK_COMPLETE_EVT */ } esp_ble_gap_cb_param_t; /** @@ -2772,6 +2779,18 @@ esp_err_t esp_ble_gap_set_privacy_mode(esp_ble_addr_type_t addr_type, esp_bd_add */ esp_err_t esp_ble_gap_set_csa_support(uint8_t csa_select); +/** + * @brief This function is used to control which vendor events are generated by the HCI for the Host. + * + * @param[in] event_mask: Bit0: Legacy scan request received event + * Bit1: Vendor channel map update complete event + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_gap_set_vendor_event_mask(uint32_t event_mask); + #ifdef __cplusplus } #endif diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c index da55bf3578..122831f5e3 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c @@ -5859,6 +5859,11 @@ void bta_dm_ble_gap_set_csa_support(tBTA_DM_MSG *p_data) BTM_BleSetCsaSupport(p_data->ble_set_csa_support.csa_select, p_data->ble_set_csa_support.p_cback); } +void bta_dm_ble_gap_set_vendor_evt_mask(tBTA_DM_MSG *p_data) +{ + APPL_TRACE_API("%s, evt_mask = %d", __func__, p_data->ble_set_vendor_evt_mask.evt_mask); + BTM_BleSetVendorEventMask(p_data->ble_set_vendor_evt_mask.evt_mask, p_data->ble_set_vendor_evt_mask.p_cback); +} #if (BLE_50_DTM_TEST_EN == TRUE) void bta_dm_ble_gap_dtm_enhance_tx_start(tBTA_DM_MSG *p_data) diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c index cc474ef332..009c53bd1f 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c @@ -3013,6 +3013,19 @@ void BTA_DmBleGapSetCsaSupport(uint8_t csa_select, tBTA_SET_CSA_SUPPORT_CMPL_CBA } } +void BTA_DmBleGapSetVendorEventMask(uint32_t evt_mask, tBTA_SET_VENDOR_EVT_MASK_CBACK *p_callback) +{ + tBTA_DM_API_BLE_SET_VENDOR_EVT_MASK *p_msg; + + if ((p_msg = (tBTA_DM_API_BLE_SET_VENDOR_EVT_MASK *)osi_malloc(sizeof(tBTA_DM_API_BLE_SET_VENDOR_EVT_MASK))) + != NULL) { + p_msg->hdr.event = BTA_DM_API_BLE_SET_VENDOR_EVT_MASK_EVT; + p_msg->evt_mask = evt_mask; + p_msg->p_cback = p_callback; + bta_sys_sendmsg(p_msg); + } +} + /******************************************************************************* ** ** Function BTA_VendorInit diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_main.c b/components/bt/host/bluedroid/bta/dm/bta_dm_main.c index 00f51af69b..5460e2a44a 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_main.c @@ -285,6 +285,7 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = { bta_dm_ble_gap_add_dev_to_resolving_list, /* BTA_DM_API_ADD_DEV_TO_RESOLVING_LIST_EVT */ bta_dm_ble_gap_set_privacy_mode, /* BTA_DM_API_SET_PRIVACY_MODE_EVT */ bta_dm_ble_gap_set_csa_support, /* BTA_DM_API_BLE_SET_CSA_SUPPORT_EVT */ + bta_dm_ble_gap_set_vendor_evt_mask, /* BTA_DM_API_BLE_SET_VENDOR_EVT_MASK_EVT */ #endif }; diff --git a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h index 6b64e3caaf..2a195ee79c 100644 --- a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h +++ b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h @@ -276,6 +276,7 @@ enum { BTA_DM_API_ADD_DEV_TO_RESOLVING_LIST_EVT, BTA_DM_API_SET_PRIVACY_MODE_EVT, BTA_DM_API_BLE_SET_CSA_SUPPORT_EVT, + BTA_DM_API_BLE_SET_VENDOR_EVT_MASK_EVT, #endif BTA_DM_MAX_EVT }; @@ -1020,6 +1021,12 @@ typedef struct { tBTA_SET_CSA_SUPPORT_CMPL_CBACK *p_cback; } tBTA_DM_API_BLE_SET_CSA_SUPPORT; +typedef struct { + BT_HDR hdr; + UINT32 evt_mask; + tBTA_SET_VENDOR_EVT_MASK_CBACK *p_cback; +} tBTA_DM_API_BLE_SET_VENDOR_EVT_MASK; + #endif /* BLE_INCLUDED */ #if (BLE_HOST_REMOVE_AN_ACL_EN == TRUE) @@ -1463,6 +1470,7 @@ typedef union { tBTA_DM_API_CLEAR_ADV ble_clear_adv; tBTA_DM_API_SET_PRIVACY_MODE ble_set_privacy_mode; tBTA_DM_API_BLE_SET_CSA_SUPPORT ble_set_csa_support; + tBTA_DM_API_BLE_SET_VENDOR_EVT_MASK ble_set_vendor_evt_mask; #endif #if (BLE_HOST_REMOVE_AN_ACL_EN == TRUE) tBTA_DM_API_REMOVE_ACL remove_acl; @@ -1929,6 +1937,7 @@ extern void bta_dm_ble_gap_set_rpa_timeout(tBTA_DM_MSG *p_data); extern void bta_dm_ble_gap_add_dev_to_resolving_list(tBTA_DM_MSG *p_data); extern void bta_dm_ble_gap_set_privacy_mode(tBTA_DM_MSG *p_data); extern void bta_dm_ble_gap_set_csa_support(tBTA_DM_MSG *p_data); +extern void bta_dm_ble_gap_set_vendor_evt_mask(tBTA_DM_MSG *p_data); #if (BLE_50_DTM_TEST_EN == TRUE) extern void bta_dm_ble_gap_dtm_enhance_tx_start(tBTA_DM_MSG *p_data); extern void bta_dm_ble_gap_dtm_enhance_rx_start(tBTA_DM_MSG *p_data); diff --git a/components/bt/host/bluedroid/bta/include/bta/bta_api.h b/components/bt/host/bluedroid/bta/include/bta/bta_api.h index 05f413e9c3..acd49962b3 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_api.h @@ -441,6 +441,8 @@ typedef tBTM_SET_PRIVACY_MODE_CMPL_CBACK tBTA_SET_PRIVACY_MODE_CMPL_CBACK; typedef tBTM_SET_CSA_SUPPORT_CMPL_CBACK tBTA_SET_CSA_SUPPORT_CMPL_CBACK; +typedef tBTM_SET_VENDOR_EVT_MASK_CBACK tBTA_SET_VENDOR_EVT_MASK_CBACK; + typedef tBTM_CMPL_CB tBTA_CMPL_CB; typedef tBTM_VSC_CMPL tBTA_VSC_CMPL; @@ -2921,6 +2923,8 @@ extern void BTA_DmBleSetPrivacyMode(uint8_t addr_type, BD_ADDR addr, uint8_t pri extern void BTA_DmBleGapSetCsaSupport(uint8_t csa_select, tBTM_SET_CSA_SUPPORT_CMPL_CBACK *p_callback); +extern void BTA_DmBleGapSetVendorEventMask(uint32_t evt_mask, tBTA_SET_VENDOR_EVT_MASK_CBACK *p_callback); + /******************************************************************************* ** ** Function BTA_DmBleSetStorageParams diff --git a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c index 3158672855..d291648850 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -1381,6 +1381,25 @@ static void btc_ble_set_csa_support_callback(UINT8 status) } } +static void btc_ble_set_vendor_evt_mask_callback(UINT8 status) +{ + esp_ble_gap_cb_param_t param; + bt_status_t ret; + btc_msg_t msg = {0}; + + msg.sig = BTC_SIG_API_CB; + msg.pid = BTC_PID_GAP_BLE; + msg.act = ESP_GAP_BLE_SET_VENDOR_EVT_MASK_COMPLETE_EVT; + + param.set_csa_support_cmpl.status = btc_btm_status_to_esp_status(status); + + ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL, NULL); + + if (ret != BT_STATUS_SUCCESS) { + BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__); + } +} + void btc_get_whitelist_size(uint16_t *length) { BTM_BleGetWhiteListSize(length); @@ -2461,6 +2480,9 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) case BTC_GAP_BLE_SET_CSA_SUPPORT: BTA_DmBleGapSetCsaSupport(arg->set_csa_support.csa_select, btc_ble_set_csa_support_callback); break; + case BTC_GAP_BLE_ACT_SET_VENDOR_EVT_MASK: + BTA_DmBleGapSetVendorEventMask(arg->set_vendor_evt_mask.evt_mask, btc_ble_set_vendor_evt_mask_callback); + break; default: break; } diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h index df6a2c8212..d3829aa2e0 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h @@ -121,6 +121,7 @@ typedef enum { BTC_GAP_BLE_ACT_VENDOR_HCI_CMD_EVT, BTC_GAP_BLE_SET_PRIVACY_MODE, BTC_GAP_BLE_SET_CSA_SUPPORT, + BTC_GAP_BLE_ACT_SET_VENDOR_EVT_MASK, } btc_gap_ble_act_t; /* btc_ble_gap_args_t */ @@ -295,6 +296,10 @@ typedef union { struct set_csa_support_args { uint8_t csa_select; } set_csa_support; + // BTC_GAP_BLE_ACT_SET_VENDOR_EVT_MASK + struct set_vendor_evt_mask_args { + uint32_t evt_mask; + } set_vendor_evt_mask; } btc_ble_gap_args_t; #if (BLE_50_FEATURE_SUPPORT == TRUE) diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c index 2b0fdd1337..1e70ecd4f6 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c @@ -4793,6 +4793,17 @@ BOOLEAN BTM_BleSetCsaSupport(UINT8 csa_select, tBTM_SET_CSA_SUPPORT_CMPL_CBACK * return TRUE; } +BOOLEAN BTM_BleSetVendorEventMask(UINT32 evt_mask, tBTM_SET_VENDOR_EVT_MASK_CBACK *p_callback) +{ + if (btsnd_hcic_ble_set_vendor_evt_mask(evt_mask) != TRUE) { + BTM_TRACE_ERROR("LE SetVendorEventMask evt_mask=%x: error", evt_mask); + return FALSE; + } + + btm_cb.ble_ctr_cb.set_vendor_evt_mask_cmpl_cb = p_callback; + return TRUE; +} + #if (BLE_42_SCAN_EN == TRUE) bool btm_ble_adv_pkt_ready(void) { diff --git a/components/bt/host/bluedroid/stack/btm/btm_devctl.c b/components/bt/host/bluedroid/stack/btm/btm_devctl.c index cde694a886..3125ee775e 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_devctl.c +++ b/components/bt/host/bluedroid/stack/btm/btm_devctl.c @@ -786,6 +786,14 @@ void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len, } break; } + case HCI_VENDOR_BLE_SET_EVT_MASK: { + uint8_t status; + STREAM_TO_UINT8(status, p); + if (ble_cb && ble_cb->set_vendor_evt_mask_cmpl_cb) { + ble_cb->set_vendor_evt_mask_cmpl_cb(status); + } + break; + } default: break; } diff --git a/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h b/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h index 6411440048..49f9ff8353 100644 --- a/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h +++ b/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h @@ -381,6 +381,7 @@ typedef struct { UINT8 link_count[2]; /* total link count master and slave*/ tBTM_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK *update_exceptional_list_cmp_cb; tBTM_SET_CSA_SUPPORT_CMPL_CBACK *set_csa_support_cmpl_cb; + tBTM_SET_VENDOR_EVT_MASK_CBACK *set_vendor_evt_mask_cmpl_cb; } tBTM_BLE_CB; #ifdef __cplusplus diff --git a/components/bt/host/bluedroid/stack/hcic/hciblecmds.c b/components/bt/host/bluedroid/stack/hcic/hciblecmds.c index 3d28c5718e..4b2eae32c8 100644 --- a/components/bt/host/bluedroid/stack/hcic/hciblecmds.c +++ b/components/bt/host/bluedroid/stack/hcic/hciblecmds.c @@ -1969,4 +1969,26 @@ BOOLEAN btsnd_hcic_ble_set_csa_support (UINT8 csa_select) btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); return TRUE; } + +BOOLEAN btsnd_hcic_ble_set_vendor_evt_mask (UINT32 evt_mask) +{ + BT_HDR *p; + UINT8 *pp; + + if ((p = HCI_GET_CMD_BUF (HCIC_PARAM_SIZE_BLE_SET_VENDOR_EVT_MASK)) == NULL) { + return (FALSE); + } + + pp = (UINT8 *)(p + 1); + + p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_BLE_SET_VENDOR_EVT_MASK; + p->offset = 0; + + UINT16_TO_STREAM (pp, HCI_VENDOR_BLE_SET_EVT_MASK); + UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_BLE_SET_VENDOR_EVT_MASK); + UINT32_TO_STREAM (pp, evt_mask); + + btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); + return TRUE; +} #endif diff --git a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h index 1bc54b04c6..38f907bdcf 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h @@ -1013,6 +1013,7 @@ typedef void (tBTM_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK) (tBTM_STATUS st typedef void (tBTM_CLEAR_ADV_CMPL_CBACK) (UINT8 status); typedef void (tBTM_SET_PRIVACY_MODE_CMPL_CBACK) (tBTM_STATUS status); typedef void (tBTM_SET_CSA_SUPPORT_CMPL_CBACK) (tBTM_STATUS status); +typedef void (tBTM_SET_VENDOR_EVT_MASK_CBACK) (tBTM_STATUS status); #if (BLE_50_FEATURE_SUPPORT == TRUE) #define BTM_BLE_5_GAP_READ_PHY_COMPLETE_EVT 1 @@ -2751,6 +2752,19 @@ BOOLEAN BTM_BleSetPrivacyMode(UINT8 addr_type, *******************************************************************************/ BOOLEAN BTM_BleSetCsaSupport (UINT8 csa_select, tBTM_SET_CSA_SUPPORT_CMPL_CBACK *p_callback); +/******************************************************************************* +** +** Function BTM_BleSetVendorEventMask +** +** Description This function is called to set the vendor HCI event mask +** +** Parameters evt_mask - vendor HCI event mask. +** p_callback - Callback function to be called when the operation is completed. +** +** Returns TRUE if the operation was successful, otherwise FALSE. +** +*******************************************************************************/ +BOOLEAN BTM_BleSetVendorEventMask(UINT32 evt_mask, tBTM_SET_VENDOR_EVT_MASK_CBACK *p_callback); /* #ifdef __cplusplus } diff --git a/components/bt/host/bluedroid/stack/include/stack/hcidefs.h b/components/bt/host/bluedroid/stack/include/stack/hcidefs.h index 054b616993..42773f0c8b 100644 --- a/components/bt/host/bluedroid/stack/include/stack/hcidefs.h +++ b/components/bt/host/bluedroid/stack/include/stack/hcidefs.h @@ -427,6 +427,7 @@ #define HCI_SUBCODE_BLE_RD_STATIC_ADDR 0x0B #define HCI_SUBCODE_BLE_CLEAR_ADV 0x0C #define HCI_SUBCODE_BLE_SET_CSA_SUPPORT 0x12 +#define HCI_SUBCODE_BLE_SET_VENDOR_EVT_MASK 0x16 #define HCI_SUBCODE_BLE_MAX 0x7F //ESP BT subcode define @@ -473,6 +474,8 @@ #define HCI_VENDOR_BLE_CLEAR_ADV HCI_ESP_VENDOR_OPCODE_BUILD(HCI_VENDOR_OGF, HCI_ESP_GROUP_BLE, HCI_SUBCODE_BLE_CLEAR_ADV) /* BLE set CSA support */ #define HCI_VENDOR_BLE_SET_CSA_SUPPORT HCI_ESP_VENDOR_OPCODE_BUILD(HCI_VENDOR_OGF, HCI_ESP_GROUP_BLE, HCI_SUBCODE_BLE_SET_CSA_SUPPORT) +/* BLE set vendor event mask */ +#define HCI_VENDOR_BLE_SET_EVT_MASK HCI_ESP_VENDOR_OPCODE_BUILD(HCI_VENDOR_OGF, HCI_ESP_GROUP_BLE, HCI_SUBCODE_BLE_SET_VENDOR_EVT_MASK) //ESP BT HCI CMD #define HCI_VENDOR_BT_SET_MIN_ENC_KEY_SIZE HCI_ESP_VENDOR_OPCODE_BUILD(HCI_VENDOR_OGF, HCI_ESP_GROUP_BT, HCI_SUBCODE_BT_SET_MIN_ENC_KEY_SIZE) diff --git a/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h b/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h index 6d21f06f23..dff7633f34 100644 --- a/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h +++ b/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h @@ -760,6 +760,7 @@ void btsnd_hcic_vendor_spec_cmd (BT_HDR *buffer, UINT16 opcode, #define HCIC_PARAM_SIZE_BLE_CLEAR_ADV 0 #define HCIC_PARAM_SIZE_SET_PRIVACY_MODE 8 #define HCIC_PARAM_SIZE_BLE_SET_CSA_SUPPORT 1 +#define HCIC_PARAM_SIZE_BLE_SET_VENDOR_EVT_MASK 4 #if (BLE_50_FEATURE_SUPPORT == TRUE) #define HCIC_PARAM_SIZE_BLE_READ_PHY 2 #define HCIC_PARAM_SIZE_BLE_SET_DEF_PHY 3 @@ -923,6 +924,8 @@ BOOLEAN btsnd_hcic_ble_set_privacy_mode(UINT8 addr_type, BD_ADDR addr, UINT8 pri BOOLEAN btsnd_hcic_ble_set_csa_support (UINT8 csa_select); +BOOLEAN btsnd_hcic_ble_set_vendor_evt_mask (UINT32 evt_mask); + #endif /* BLE_INCLUDED */ #if (BLE_50_FEATURE_SUPPORT == TRUE) From 1003ced6e95f4c0831646e46120b68a80f4bddac Mon Sep 17 00:00:00 2001 From: chenjianhua Date: Sat, 8 Feb 2025 09:54:17 +0800 Subject: [PATCH 2/2] feat(bt/bluedroid): Support BLE vendor hci event reporting --- .../api/include/api/esp_gap_ble_api.h | 9 +++++ .../btc/profile/std/gap/btc_gap_ble.c | 40 +++++++++++++++++++ .../bt/host/bluedroid/stack/btm/btm_ble_gap.c | 29 ++++++++++++++ .../bluedroid/stack/include/stack/btm_api.h | 2 + .../stack/include/stack/btm_ble_api.h | 1 + .../bluedroid/stack/include/stack/hcidefs.h | 3 ++ 6 files changed, 84 insertions(+) diff --git a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h index a28abfa41b..748c34c2ca 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h @@ -231,6 +231,7 @@ typedef enum { ESP_GAP_BLE_SET_PRIVACY_MODE_COMPLETE_EVT, /*!< When set privacy mode complete, the event comes */ ESP_GAP_BLE_SET_CSA_SUPPORT_COMPLETE_EVT, /*!< When set CSA support complete, the event comes */ ESP_GAP_BLE_SET_VENDOR_EVT_MASK_COMPLETE_EVT, /*!< When set vendor event mask complete, the event comes */ + ESP_GAP_BLE_VENDOR_HCI_EVT, /*!< When BLE vendor HCI event received, the event comes */ ESP_GAP_BLE_EVT_MAX, /*!< when maximum advertising event complete, the event comes */ } esp_gap_ble_cb_event_t; @@ -1588,6 +1589,14 @@ typedef union { struct ble_set_vendor_evt_mask_cmpl_evt_param { esp_bt_status_t status; /*!< Indicate set vendor event mask operation success status */ } set_vendor_evt_mask_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_VENDOR_EVT_MASK_COMPLETE_EVT */ + /** + * @brief ESP_GAP_BLE_VENDOR_HCI_EVT + */ + struct ble_vendor_hci_event_evt_param { + uint8_t subevt_code; /*!< Subevent code for vendor HCI event, the range is 0xC0 to 0xFF */ + uint8_t param_len; /*!< The length of the event parameter buffer */ + uint8_t *param_buf; /*!< The pointer of the event parameter buffer */ + } vendor_hci_evt; /*!< Event parameter buffer of ESP_GAP_BLE_VENDOR_HCI_EVT */ } esp_ble_gap_cb_param_t; /** diff --git a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c index d291648850..c4cbdc0a1d 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -1400,6 +1400,26 @@ static void btc_ble_set_vendor_evt_mask_callback(UINT8 status) } } +static void btc_ble_vendor_hci_event_callback(UINT8 subevt_code, UINT8 param_len, UINT8 *params) +{ + esp_ble_gap_cb_param_t param = {0}; + bt_status_t ret; + btc_msg_t msg = {0}; + + msg.sig = BTC_SIG_API_CB; + msg.pid = BTC_PID_GAP_BLE; + msg.act = ESP_GAP_BLE_VENDOR_HCI_EVT; + + param.vendor_hci_evt.subevt_code = subevt_code; + param.vendor_hci_evt.param_len = param_len; + param.vendor_hci_evt.param_buf = params; + ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), btc_gap_ble_cb_deep_copy, btc_gap_ble_cb_deep_free); + + if (ret != BT_STATUS_SUCCESS) { + BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__); + } +} + void btc_get_whitelist_size(uint16_t *length) { BTM_BleGetWhiteListSize(length); @@ -1822,6 +1842,18 @@ void btc_gap_ble_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) } break; } + case ESP_GAP_BLE_VENDOR_HCI_EVT: { + if (src->vendor_hci_evt.param_len) { + dst->vendor_hci_evt.param_buf = osi_malloc(src->vendor_hci_evt.param_len); + if (dst->vendor_hci_evt.param_buf) { + memcpy(dst->vendor_hci_evt.param_buf, src->vendor_hci_evt.param_buf, + src->vendor_hci_evt.param_len); + } else { + BTC_TRACE_ERROR("%s, malloc failed\n", __func__); + } + } + break; + } default: BTC_TRACE_ERROR("%s, Unhandled deep copy %d\n", __func__, msg->act); break; @@ -1966,6 +1998,13 @@ void btc_gap_ble_cb_deep_free(btc_msg_t *msg) } break; } + case ESP_GAP_BLE_VENDOR_HCI_EVT: { + void *value = ((esp_ble_gap_cb_param_t *)msg->arg)->vendor_hci_evt.param_buf; + if (value) { + osi_free(value); + } + break; + } default: BTC_TRACE_DEBUG("Unhandled deep free %d", msg->act); break; @@ -2498,6 +2537,7 @@ void btc_gap_callback_init(void) #if (BLE_50_FEATURE_SUPPORT == TRUE) BTM_BleGapRegisterCallback(btc_ble_5_gap_callback); #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) + BTM_BleRegisterVendorHciEventCallback(btc_ble_vendor_hci_event_callback); } bool btc_gap_ble_init(void) diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c index 1e70ecd4f6..185e57d172 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c @@ -71,6 +71,8 @@ static tBTM_BLE_CTRL_FEATURES_CBACK *p_ctrl_le_feature_rd_cmpl_cback = NULL; #endif tBTM_CallbackFunc conn_callback_func; +// BLE vendor HCI event callback +static tBTM_BLE_VENDOR_HCI_EVT_CBACK *ble_vs_evt_callback = NULL; /******************************************************************************* ** Local functions *******************************************************************************/ @@ -351,6 +353,11 @@ void BTM_BleRegiseterPktLengthChangeCallback(tBTM_SET_PKT_DATA_LENGTH_CBACK *ptk conn_callback_func.set_pkt_data_length_cb = ptk_len_chane_cb; } +void BTM_BleRegisterVendorHciEventCallback(tBTM_BLE_VENDOR_HCI_EVT_CBACK *vendor_hci_evt_cb) +{ + ble_vs_evt_callback = vendor_hci_evt_cb; +} + /******************************************************************************* ** ** Function BTM_BleUpdateAdvWhitelist @@ -4542,6 +4549,26 @@ BOOLEAN btm_ble_update_mode_operation(UINT8 link_role, BD_ADDR bd_addr, UINT8 st return bg_con; } +static void btm_ble_vs_evt_callback(UINT8 len, UINT8 *p) +{ + UINT8 sub_event; + + if (!len || !p) { + return; + } + + STREAM_TO_UINT8(sub_event, p); + len--; + + if (sub_event < HCI_VSE_LE_LEGACY_SCAN_REQ_RECEIVED_EVT) { + return; + } + + if (ble_vs_evt_callback) { + ble_vs_evt_callback(sub_event, len, p); + } +} + /******************************************************************************* ** ** Function btm_ble_init @@ -4600,6 +4627,8 @@ void btm_ble_init (void) btm_ble_adv_filter_init(); #endif // #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE #endif + + BTM_RegisterForVSEvents(btm_ble_vs_evt_callback, TRUE); } /******************************************************************************* diff --git a/components/bt/host/bluedroid/stack/include/stack/btm_api.h b/components/bt/host/bluedroid/stack/include/stack/btm_api.h index 596b024f92..8e51118f58 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_api.h @@ -201,6 +201,8 @@ typedef void (tBTM_SET_LOCAL_PRIVACY_CBACK) (UINT8 status); typedef void (tBTM_SET_RPA_TIMEOUT_CMPL_CBACK) (UINT8 status); typedef void (tBTM_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK) (UINT8 status); + +typedef void (tBTM_BLE_VENDOR_HCI_EVT_CBACK) (UINT8 subevt_code, UINT8 param_len, UINT8 *params); /******************************* ** Device Coexist status ********************************/ diff --git a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h index 38f907bdcf..d10c02279e 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h @@ -1417,6 +1417,7 @@ extern "C" { *******************************************************************************/ void BTM_BleRegiseterConnParamCallback(tBTM_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb); void BTM_BleRegiseterPktLengthChangeCallback(tBTM_SET_PKT_DATA_LENGTH_CBACK *ptk_len_chane_cb); +void BTM_BleRegisterVendorHciEventCallback(tBTM_BLE_VENDOR_HCI_EVT_CBACK *vendor_hci_evt_cb); /******************************************************************************* ** diff --git a/components/bt/host/bluedroid/stack/include/stack/hcidefs.h b/components/bt/host/bluedroid/stack/include/stack/hcidefs.h index 42773f0c8b..b9b2206979 100644 --- a/components/bt/host/bluedroid/stack/include/stack/hcidefs.h +++ b/components/bt/host/bluedroid/stack/include/stack/hcidefs.h @@ -832,6 +832,9 @@ #define HCI_BLE_CHNL_MAP_SIZE 5 #define HCI_VENDOR_SPECIFIC_EVT 0xFF /* Vendor specific events */ +#define HCI_VSE_LE_LEGACY_SCAN_REQ_RECEIVED_EVT 0xC0 +#define HCI_VSE_LE_CHAN_MAP_UPDATE_CMPL_EVT 0xC1 +#define HCI_VSE_LE_EVT_MAX 0xFF #define HCI_NAP_TRACE_EVT 0xFF /* was define 0xFE, 0xFD, change to 0xFF because conflict w/ TCI_EVT and per specification compliant */