Skip to content

Commit 1003ced

Browse files
committed
feat(bt/bluedroid): Support BLE vendor hci event reporting
1 parent fd4094e commit 1003ced

File tree

6 files changed

+84
-0
lines changed

6 files changed

+84
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ typedef enum {
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 */
233233
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 */
234235
ESP_GAP_BLE_EVT_MAX, /*!< when maximum advertising event complete, the event comes */
235236
} esp_gap_ble_cb_event_t;
236237

@@ -1588,6 +1589,14 @@ typedef union {
15881589
struct ble_set_vendor_evt_mask_cmpl_evt_param {
15891590
esp_bt_status_t status; /*!< Indicate set vendor event mask operation success status */
15901591
} 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 */
15911600
} esp_ble_gap_cb_param_t;
15921601

15931602
/**

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,26 @@ static void btc_ble_set_vendor_evt_mask_callback(UINT8 status)
14001400
}
14011401
}
14021402

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+
14031423
void btc_get_whitelist_size(uint16_t *length)
14041424
{
14051425
BTM_BleGetWhiteListSize(length);
@@ -1822,6 +1842,18 @@ void btc_gap_ble_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
18221842
}
18231843
break;
18241844
}
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+
}
18251857
default:
18261858
BTC_TRACE_ERROR("%s, Unhandled deep copy %d\n", __func__, msg->act);
18271859
break;
@@ -1966,6 +1998,13 @@ void btc_gap_ble_cb_deep_free(btc_msg_t *msg)
19661998
}
19671999
break;
19682000
}
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+
}
19692008
default:
19702009
BTC_TRACE_DEBUG("Unhandled deep free %d", msg->act);
19712010
break;
@@ -2498,6 +2537,7 @@ void btc_gap_callback_init(void)
24982537
#if (BLE_50_FEATURE_SUPPORT == TRUE)
24992538
BTM_BleGapRegisterCallback(btc_ble_5_gap_callback);
25002539
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
2540+
BTM_BleRegisterVendorHciEventCallback(btc_ble_vendor_hci_event_callback);
25012541
}
25022542

25032543
bool btc_gap_ble_init(void)

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

Lines changed: 29 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
/*******************************************************************************

components/bt/host/bluedroid/stack/include/stack/btm_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ typedef void (tBTM_SET_LOCAL_PRIVACY_CBACK) (UINT8 status);
201201
typedef void (tBTM_SET_RPA_TIMEOUT_CMPL_CBACK) (UINT8 status);
202202

203203
typedef void (tBTM_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK) (UINT8 status);
204+
205+
typedef void (tBTM_BLE_VENDOR_HCI_EVT_CBACK) (UINT8 subevt_code, UINT8 param_len, UINT8 *params);
204206
/*******************************
205207
** Device Coexist status
206208
********************************/

components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,7 @@ extern "C" {
14171417
*******************************************************************************/
14181418
void BTM_BleRegiseterConnParamCallback(tBTM_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb);
14191419
void BTM_BleRegiseterPktLengthChangeCallback(tBTM_SET_PKT_DATA_LENGTH_CBACK *ptk_len_chane_cb);
1420+
void BTM_BleRegisterVendorHciEventCallback(tBTM_BLE_VENDOR_HCI_EVT_CBACK *vendor_hci_evt_cb);
14201421

14211422
/*******************************************************************************
14221423
**

components/bt/host/bluedroid/stack/include/stack/hcidefs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,9 @@
832832
#define HCI_BLE_CHNL_MAP_SIZE 5
833833

834834
#define HCI_VENDOR_SPECIFIC_EVT 0xFF /* Vendor specific events */
835+
#define HCI_VSE_LE_LEGACY_SCAN_REQ_RECEIVED_EVT 0xC0
836+
#define HCI_VSE_LE_CHAN_MAP_UPDATE_CMPL_EVT 0xC1
837+
#define HCI_VSE_LE_EVT_MAX 0xFF
835838
#define HCI_NAP_TRACE_EVT 0xFF /* was define 0xFE, 0xFD, change to 0xFF
836839
because conflict w/ TCI_EVT and per
837840
specification compliant */

0 commit comments

Comments
 (0)