Skip to content

Commit fd4094e

Browse files
committed
feat(bt/bluedroid): Support BLE setting vendor event mask
1 parent 7d751dc commit fd4094e

File tree

16 files changed

+160
-2
lines changed

16 files changed

+160
-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: 21 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,7 @@ 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 */
233234
ESP_GAP_BLE_EVT_MAX, /*!< when maximum advertising event complete, the event comes */
234235
} esp_gap_ble_cb_event_t;
235236

@@ -1580,7 +1581,13 @@ typedef union {
15801581
*/
15811582
struct ble_set_csa_support_cmpl_evt_param {
15821583
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 */
1584+
} set_csa_support_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_CSA_SUPPORT_COMPLETE_EVT */
1585+
/**
1586+
* @brief ESP_GAP_BLE_SET_VENDOR_EVT_MASK_COMPLETE_EVT
1587+
*/
1588+
struct ble_set_vendor_evt_mask_cmpl_evt_param {
1589+
esp_bt_status_t status; /*!< Indicate set vendor event mask operation success status */
1590+
} set_vendor_evt_mask_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_VENDOR_EVT_MASK_COMPLETE_EVT */
15841591
} esp_ble_gap_cb_param_t;
15851592

15861593
/**
@@ -2772,6 +2779,18 @@ esp_err_t esp_ble_gap_set_privacy_mode(esp_ble_addr_type_t addr_type, esp_bd_add
27722779
*/
27732780
esp_err_t esp_ble_gap_set_csa_support(uint8_t csa_select);
27742781

2782+
/**
2783+
* @brief This function is used to control which vendor events are generated by the HCI for the Host.
2784+
*
2785+
* @param[in] event_mask: Bit0: Legacy scan request received event
2786+
* Bit1: Vendor channel map update complete event
2787+
*
2788+
* @return
2789+
* - ESP_OK : success
2790+
* - other : failed
2791+
*/
2792+
esp_err_t esp_ble_gap_set_vendor_event_mask(uint32_t event_mask);
2793+
27752794
#ifdef __cplusplus
27762795
}
27772796
#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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,25 @@ 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+
13841403
void btc_get_whitelist_size(uint16_t *length)
13851404
{
13861405
BTM_BleGetWhiteListSize(length);
@@ -2461,6 +2480,9 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
24612480
case BTC_GAP_BLE_SET_CSA_SUPPORT:
24622481
BTA_DmBleGapSetCsaSupport(arg->set_csa_support.csa_select, btc_ble_set_csa_support_callback);
24632482
break;
2483+
case BTC_GAP_BLE_ACT_SET_VENDOR_EVT_MASK:
2484+
BTA_DmBleGapSetVendorEventMask(arg->set_vendor_evt_mask.evt_mask, btc_ble_set_vendor_evt_mask_callback);
2485+
break;
24642486
default:
24652487
break;
24662488
}

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4793,6 +4793,17 @@ BOOLEAN BTM_BleSetCsaSupport(UINT8 csa_select, tBTM_SET_CSA_SUPPORT_CMPL_CBACK *
47934793
return TRUE;
47944794
}
47954795

4796+
BOOLEAN BTM_BleSetVendorEventMask(UINT32 evt_mask, tBTM_SET_VENDOR_EVT_MASK_CBACK *p_callback)
4797+
{
4798+
if (btsnd_hcic_ble_set_vendor_evt_mask(evt_mask) != TRUE) {
4799+
BTM_TRACE_ERROR("LE SetVendorEventMask evt_mask=%x: error", evt_mask);
4800+
return FALSE;
4801+
}
4802+
4803+
btm_cb.ble_ctr_cb.set_vendor_evt_mask_cmpl_cb = p_callback;
4804+
return TRUE;
4805+
}
4806+
47964807
#if (BLE_42_SCAN_EN == TRUE)
47974808
bool btm_ble_adv_pkt_ready(void)
47984809
{

0 commit comments

Comments
 (0)