Skip to content

Commit 8ad16fd

Browse files
committed
Merge branch 'feat/support_ble_vendor_hci_event_report' into 'master'
feat(bt/bluedroid): Support BLE vendor hci event reporting Closes BLERP-1542 See merge request espressif/esp-idf!36800
2 parents e01877f + 1003ced commit 8ad16fd

File tree

17 files changed

+244
-2
lines changed

17 files changed

+244
-2
lines changed

components/bt/host/bluedroid/api/esp_gap_ble_api.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,3 +1774,21 @@ esp_err_t esp_ble_gap_vendor_command_send(esp_ble_vendor_cmd_params_t *vendor_cm
17741774
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy, btc_gap_ble_arg_deep_free)
17751775
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
17761776
}
1777+
1778+
esp_err_t esp_ble_gap_set_vendor_event_mask(uint32_t event_mask)
1779+
{
1780+
btc_msg_t msg = {0};
1781+
btc_ble_gap_args_t arg;
1782+
1783+
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
1784+
return ESP_ERR_INVALID_STATE;
1785+
}
1786+
1787+
msg.sig = BTC_SIG_API_CALL;
1788+
msg.pid = BTC_PID_GAP_BLE;
1789+
msg.act = BTC_GAP_BLE_ACT_SET_VENDOR_EVT_MASK;
1790+
arg.set_vendor_evt_mask.evt_mask = event_mask;
1791+
1792+
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL)
1793+
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1794+
}

components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -230,6 +230,8 @@ typedef enum {
230230
ESP_GAP_BLE_VENDOR_CMD_COMPLETE_EVT, /*!< When vendor hci command complete, the event comes */
231231
ESP_GAP_BLE_SET_PRIVACY_MODE_COMPLETE_EVT, /*!< When set privacy mode complete, the event comes */
232232
ESP_GAP_BLE_SET_CSA_SUPPORT_COMPLETE_EVT, /*!< When set CSA support complete, the event comes */
233+
ESP_GAP_BLE_SET_VENDOR_EVT_MASK_COMPLETE_EVT, /*!< When set vendor event mask complete, the event comes */
234+
ESP_GAP_BLE_VENDOR_HCI_EVT, /*!< When BLE vendor HCI event received, the event comes */
233235
ESP_GAP_BLE_EVT_MAX, /*!< when maximum advertising event complete, the event comes */
234236
} esp_gap_ble_cb_event_t;
235237

@@ -1580,7 +1582,21 @@ typedef union {
15801582
*/
15811583
struct ble_set_csa_support_cmpl_evt_param {
15821584
esp_bt_status_t status; /*!< Indicate CSA support set operation success status */
1583-
} set_csa_support_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_CSA_SUPPORT_COMPLETE_EVT */
1585+
} set_csa_support_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_CSA_SUPPORT_COMPLETE_EVT */
1586+
/**
1587+
* @brief ESP_GAP_BLE_SET_VENDOR_EVT_MASK_COMPLETE_EVT
1588+
*/
1589+
struct ble_set_vendor_evt_mask_cmpl_evt_param {
1590+
esp_bt_status_t status; /*!< Indicate set vendor event mask operation success status */
1591+
} set_vendor_evt_mask_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_VENDOR_EVT_MASK_COMPLETE_EVT */
1592+
/**
1593+
* @brief ESP_GAP_BLE_VENDOR_HCI_EVT
1594+
*/
1595+
struct ble_vendor_hci_event_evt_param {
1596+
uint8_t subevt_code; /*!< Subevent code for vendor HCI event, the range is 0xC0 to 0xFF */
1597+
uint8_t param_len; /*!< The length of the event parameter buffer */
1598+
uint8_t *param_buf; /*!< The pointer of the event parameter buffer */
1599+
} vendor_hci_evt; /*!< Event parameter buffer of ESP_GAP_BLE_VENDOR_HCI_EVT */
15841600
} esp_ble_gap_cb_param_t;
15851601

15861602
/**
@@ -2772,6 +2788,18 @@ esp_err_t esp_ble_gap_set_privacy_mode(esp_ble_addr_type_t addr_type, esp_bd_add
27722788
*/
27732789
esp_err_t esp_ble_gap_set_csa_support(uint8_t csa_select);
27742790

2791+
/**
2792+
* @brief This function is used to control which vendor events are generated by the HCI for the Host.
2793+
*
2794+
* @param[in] event_mask: Bit0: Legacy scan request received event
2795+
* Bit1: Vendor channel map update complete event
2796+
*
2797+
* @return
2798+
* - ESP_OK : success
2799+
* - other : failed
2800+
*/
2801+
esp_err_t esp_ble_gap_set_vendor_event_mask(uint32_t event_mask);
2802+
27752803
#ifdef __cplusplus
27762804
}
27772805
#endif

components/bt/host/bluedroid/bta/dm/bta_dm_act.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5859,6 +5859,11 @@ void bta_dm_ble_gap_set_csa_support(tBTA_DM_MSG *p_data)
58595859
BTM_BleSetCsaSupport(p_data->ble_set_csa_support.csa_select, p_data->ble_set_csa_support.p_cback);
58605860
}
58615861

5862+
void bta_dm_ble_gap_set_vendor_evt_mask(tBTA_DM_MSG *p_data)
5863+
{
5864+
APPL_TRACE_API("%s, evt_mask = %d", __func__, p_data->ble_set_vendor_evt_mask.evt_mask);
5865+
BTM_BleSetVendorEventMask(p_data->ble_set_vendor_evt_mask.evt_mask, p_data->ble_set_vendor_evt_mask.p_cback);
5866+
}
58625867

58635868
#if (BLE_50_DTM_TEST_EN == TRUE)
58645869
void bta_dm_ble_gap_dtm_enhance_tx_start(tBTA_DM_MSG *p_data)

components/bt/host/bluedroid/bta/dm/bta_dm_api.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3013,6 +3013,19 @@ void BTA_DmBleGapSetCsaSupport(uint8_t csa_select, tBTA_SET_CSA_SUPPORT_CMPL_CBA
30133013
}
30143014
}
30153015

3016+
void BTA_DmBleGapSetVendorEventMask(uint32_t evt_mask, tBTA_SET_VENDOR_EVT_MASK_CBACK *p_callback)
3017+
{
3018+
tBTA_DM_API_BLE_SET_VENDOR_EVT_MASK *p_msg;
3019+
3020+
if ((p_msg = (tBTA_DM_API_BLE_SET_VENDOR_EVT_MASK *)osi_malloc(sizeof(tBTA_DM_API_BLE_SET_VENDOR_EVT_MASK)))
3021+
!= NULL) {
3022+
p_msg->hdr.event = BTA_DM_API_BLE_SET_VENDOR_EVT_MASK_EVT;
3023+
p_msg->evt_mask = evt_mask;
3024+
p_msg->p_cback = p_callback;
3025+
bta_sys_sendmsg(p_msg);
3026+
}
3027+
}
3028+
30163029
/*******************************************************************************
30173030
**
30183031
** Function BTA_VendorInit

components/bt/host/bluedroid/bta/dm/bta_dm_main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
285285
bta_dm_ble_gap_add_dev_to_resolving_list, /* BTA_DM_API_ADD_DEV_TO_RESOLVING_LIST_EVT */
286286
bta_dm_ble_gap_set_privacy_mode, /* BTA_DM_API_SET_PRIVACY_MODE_EVT */
287287
bta_dm_ble_gap_set_csa_support, /* BTA_DM_API_BLE_SET_CSA_SUPPORT_EVT */
288+
bta_dm_ble_gap_set_vendor_evt_mask, /* BTA_DM_API_BLE_SET_VENDOR_EVT_MASK_EVT */
288289
#endif
289290
};
290291

components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ enum {
276276
BTA_DM_API_ADD_DEV_TO_RESOLVING_LIST_EVT,
277277
BTA_DM_API_SET_PRIVACY_MODE_EVT,
278278
BTA_DM_API_BLE_SET_CSA_SUPPORT_EVT,
279+
BTA_DM_API_BLE_SET_VENDOR_EVT_MASK_EVT,
279280
#endif
280281
BTA_DM_MAX_EVT
281282
};
@@ -1020,6 +1021,12 @@ typedef struct {
10201021
tBTA_SET_CSA_SUPPORT_CMPL_CBACK *p_cback;
10211022
} tBTA_DM_API_BLE_SET_CSA_SUPPORT;
10221023

1024+
typedef struct {
1025+
BT_HDR hdr;
1026+
UINT32 evt_mask;
1027+
tBTA_SET_VENDOR_EVT_MASK_CBACK *p_cback;
1028+
} tBTA_DM_API_BLE_SET_VENDOR_EVT_MASK;
1029+
10231030
#endif /* BLE_INCLUDED */
10241031

10251032
#if (BLE_HOST_REMOVE_AN_ACL_EN == TRUE)
@@ -1463,6 +1470,7 @@ typedef union {
14631470
tBTA_DM_API_CLEAR_ADV ble_clear_adv;
14641471
tBTA_DM_API_SET_PRIVACY_MODE ble_set_privacy_mode;
14651472
tBTA_DM_API_BLE_SET_CSA_SUPPORT ble_set_csa_support;
1473+
tBTA_DM_API_BLE_SET_VENDOR_EVT_MASK ble_set_vendor_evt_mask;
14661474
#endif
14671475
#if (BLE_HOST_REMOVE_AN_ACL_EN == TRUE)
14681476
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);
19291937
extern void bta_dm_ble_gap_add_dev_to_resolving_list(tBTA_DM_MSG *p_data);
19301938
extern void bta_dm_ble_gap_set_privacy_mode(tBTA_DM_MSG *p_data);
19311939
extern void bta_dm_ble_gap_set_csa_support(tBTA_DM_MSG *p_data);
1940+
extern void bta_dm_ble_gap_set_vendor_evt_mask(tBTA_DM_MSG *p_data);
19321941
#if (BLE_50_DTM_TEST_EN == TRUE)
19331942
extern void bta_dm_ble_gap_dtm_enhance_tx_start(tBTA_DM_MSG *p_data);
19341943
extern void bta_dm_ble_gap_dtm_enhance_rx_start(tBTA_DM_MSG *p_data);

components/bt/host/bluedroid/bta/include/bta/bta_api.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ typedef tBTM_SET_PRIVACY_MODE_CMPL_CBACK tBTA_SET_PRIVACY_MODE_CMPL_CBACK;
441441

442442
typedef tBTM_SET_CSA_SUPPORT_CMPL_CBACK tBTA_SET_CSA_SUPPORT_CMPL_CBACK;
443443

444+
typedef tBTM_SET_VENDOR_EVT_MASK_CBACK tBTA_SET_VENDOR_EVT_MASK_CBACK;
445+
444446
typedef tBTM_CMPL_CB tBTA_CMPL_CB;
445447

446448
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
29212923

29222924
extern void BTA_DmBleGapSetCsaSupport(uint8_t csa_select, tBTM_SET_CSA_SUPPORT_CMPL_CBACK *p_callback);
29232925

2926+
extern void BTA_DmBleGapSetVendorEventMask(uint32_t evt_mask, tBTA_SET_VENDOR_EVT_MASK_CBACK *p_callback);
2927+
29242928
/*******************************************************************************
29252929
**
29262930
** Function BTA_DmBleSetStorageParams

components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,45 @@ static void btc_ble_set_csa_support_callback(UINT8 status)
13811381
}
13821382
}
13831383

1384+
static void btc_ble_set_vendor_evt_mask_callback(UINT8 status)
1385+
{
1386+
esp_ble_gap_cb_param_t param;
1387+
bt_status_t ret;
1388+
btc_msg_t msg = {0};
1389+
1390+
msg.sig = BTC_SIG_API_CB;
1391+
msg.pid = BTC_PID_GAP_BLE;
1392+
msg.act = ESP_GAP_BLE_SET_VENDOR_EVT_MASK_COMPLETE_EVT;
1393+
1394+
param.set_csa_support_cmpl.status = btc_btm_status_to_esp_status(status);
1395+
1396+
ret = btc_transfer_context(&msg, &param, sizeof(esp_ble_gap_cb_param_t), NULL, NULL);
1397+
1398+
if (ret != BT_STATUS_SUCCESS) {
1399+
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
1400+
}
1401+
}
1402+
1403+
static void btc_ble_vendor_hci_event_callback(UINT8 subevt_code, UINT8 param_len, UINT8 *params)
1404+
{
1405+
esp_ble_gap_cb_param_t param = {0};
1406+
bt_status_t ret;
1407+
btc_msg_t msg = {0};
1408+
1409+
msg.sig = BTC_SIG_API_CB;
1410+
msg.pid = BTC_PID_GAP_BLE;
1411+
msg.act = ESP_GAP_BLE_VENDOR_HCI_EVT;
1412+
1413+
param.vendor_hci_evt.subevt_code = subevt_code;
1414+
param.vendor_hci_evt.param_len = param_len;
1415+
param.vendor_hci_evt.param_buf = params;
1416+
ret = btc_transfer_context(&msg, &param, sizeof(esp_ble_gap_cb_param_t), btc_gap_ble_cb_deep_copy, btc_gap_ble_cb_deep_free);
1417+
1418+
if (ret != BT_STATUS_SUCCESS) {
1419+
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);
1420+
}
1421+
}
1422+
13841423
void btc_get_whitelist_size(uint16_t *length)
13851424
{
13861425
BTM_BleGetWhiteListSize(length);
@@ -1803,6 +1842,18 @@ void btc_gap_ble_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
18031842
}
18041843
break;
18051844
}
1845+
case ESP_GAP_BLE_VENDOR_HCI_EVT: {
1846+
if (src->vendor_hci_evt.param_len) {
1847+
dst->vendor_hci_evt.param_buf = osi_malloc(src->vendor_hci_evt.param_len);
1848+
if (dst->vendor_hci_evt.param_buf) {
1849+
memcpy(dst->vendor_hci_evt.param_buf, src->vendor_hci_evt.param_buf,
1850+
src->vendor_hci_evt.param_len);
1851+
} else {
1852+
BTC_TRACE_ERROR("%s, malloc failed\n", __func__);
1853+
}
1854+
}
1855+
break;
1856+
}
18061857
default:
18071858
BTC_TRACE_ERROR("%s, Unhandled deep copy %d\n", __func__, msg->act);
18081859
break;
@@ -1947,6 +1998,13 @@ void btc_gap_ble_cb_deep_free(btc_msg_t *msg)
19471998
}
19481999
break;
19492000
}
2001+
case ESP_GAP_BLE_VENDOR_HCI_EVT: {
2002+
void *value = ((esp_ble_gap_cb_param_t *)msg->arg)->vendor_hci_evt.param_buf;
2003+
if (value) {
2004+
osi_free(value);
2005+
}
2006+
break;
2007+
}
19502008
default:
19512009
BTC_TRACE_DEBUG("Unhandled deep free %d", msg->act);
19522010
break;
@@ -2461,6 +2519,9 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
24612519
case BTC_GAP_BLE_SET_CSA_SUPPORT:
24622520
BTA_DmBleGapSetCsaSupport(arg->set_csa_support.csa_select, btc_ble_set_csa_support_callback);
24632521
break;
2522+
case BTC_GAP_BLE_ACT_SET_VENDOR_EVT_MASK:
2523+
BTA_DmBleGapSetVendorEventMask(arg->set_vendor_evt_mask.evt_mask, btc_ble_set_vendor_evt_mask_callback);
2524+
break;
24642525
default:
24652526
break;
24662527
}
@@ -2476,6 +2537,7 @@ void btc_gap_callback_init(void)
24762537
#if (BLE_50_FEATURE_SUPPORT == TRUE)
24772538
BTM_BleGapRegisterCallback(btc_ble_5_gap_callback);
24782539
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
2540+
BTM_BleRegisterVendorHciEventCallback(btc_ble_vendor_hci_event_callback);
24792541
}
24802542

24812543
bool btc_gap_ble_init(void)

components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ typedef enum {
121121
BTC_GAP_BLE_ACT_VENDOR_HCI_CMD_EVT,
122122
BTC_GAP_BLE_SET_PRIVACY_MODE,
123123
BTC_GAP_BLE_SET_CSA_SUPPORT,
124+
BTC_GAP_BLE_ACT_SET_VENDOR_EVT_MASK,
124125
} btc_gap_ble_act_t;
125126

126127
/* btc_ble_gap_args_t */
@@ -295,6 +296,10 @@ typedef union {
295296
struct set_csa_support_args {
296297
uint8_t csa_select;
297298
} set_csa_support;
299+
// BTC_GAP_BLE_ACT_SET_VENDOR_EVT_MASK
300+
struct set_vendor_evt_mask_args {
301+
uint32_t evt_mask;
302+
} set_vendor_evt_mask;
298303
} btc_ble_gap_args_t;
299304

300305
#if (BLE_50_FEATURE_SUPPORT == TRUE)

components/bt/host/bluedroid/stack/btm/btm_ble_gap.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ static tBTM_BLE_CTRL_FEATURES_CBACK *p_ctrl_le_feature_rd_cmpl_cback = NULL;
7171
#endif
7272

7373
tBTM_CallbackFunc conn_callback_func;
74+
// BLE vendor HCI event callback
75+
static tBTM_BLE_VENDOR_HCI_EVT_CBACK *ble_vs_evt_callback = NULL;
7476
/*******************************************************************************
7577
** Local functions
7678
*******************************************************************************/
@@ -351,6 +353,11 @@ void BTM_BleRegiseterPktLengthChangeCallback(tBTM_SET_PKT_DATA_LENGTH_CBACK *ptk
351353
conn_callback_func.set_pkt_data_length_cb = ptk_len_chane_cb;
352354
}
353355

356+
void BTM_BleRegisterVendorHciEventCallback(tBTM_BLE_VENDOR_HCI_EVT_CBACK *vendor_hci_evt_cb)
357+
{
358+
ble_vs_evt_callback = vendor_hci_evt_cb;
359+
}
360+
354361
/*******************************************************************************
355362
**
356363
** Function BTM_BleUpdateAdvWhitelist
@@ -4542,6 +4549,26 @@ BOOLEAN btm_ble_update_mode_operation(UINT8 link_role, BD_ADDR bd_addr, UINT8 st
45424549
return bg_con;
45434550
}
45444551

4552+
static void btm_ble_vs_evt_callback(UINT8 len, UINT8 *p)
4553+
{
4554+
UINT8 sub_event;
4555+
4556+
if (!len || !p) {
4557+
return;
4558+
}
4559+
4560+
STREAM_TO_UINT8(sub_event, p);
4561+
len--;
4562+
4563+
if (sub_event < HCI_VSE_LE_LEGACY_SCAN_REQ_RECEIVED_EVT) {
4564+
return;
4565+
}
4566+
4567+
if (ble_vs_evt_callback) {
4568+
ble_vs_evt_callback(sub_event, len, p);
4569+
}
4570+
}
4571+
45454572
/*******************************************************************************
45464573
**
45474574
** Function btm_ble_init
@@ -4600,6 +4627,8 @@ void btm_ble_init (void)
46004627
btm_ble_adv_filter_init();
46014628
#endif // #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
46024629
#endif
4630+
4631+
BTM_RegisterForVSEvents(btm_ble_vs_evt_callback, TRUE);
46034632
}
46044633

46054634
/*******************************************************************************
@@ -4793,6 +4822,17 @@ BOOLEAN BTM_BleSetCsaSupport(UINT8 csa_select, tBTM_SET_CSA_SUPPORT_CMPL_CBACK *
47934822
return TRUE;
47944823
}
47954824

4825+
BOOLEAN BTM_BleSetVendorEventMask(UINT32 evt_mask, tBTM_SET_VENDOR_EVT_MASK_CBACK *p_callback)
4826+
{
4827+
if (btsnd_hcic_ble_set_vendor_evt_mask(evt_mask) != TRUE) {
4828+
BTM_TRACE_ERROR("LE SetVendorEventMask evt_mask=%x: error", evt_mask);
4829+
return FALSE;
4830+
}
4831+
4832+
btm_cb.ble_ctr_cb.set_vendor_evt_mask_cmpl_cb = p_callback;
4833+
return TRUE;
4834+
}
4835+
47964836
#if (BLE_42_SCAN_EN == TRUE)
47974837
bool btm_ble_adv_pkt_ready(void)
47984838
{

0 commit comments

Comments
 (0)