feat(bt/bluedroid): Support BLE vendor hci event reporting

This commit is contained in:
chenjianhua 2025-02-08 09:54:17 +08:00
parent 70c7675b45
commit 2e2e44d680
6 changed files with 84 additions and 0 deletions

View File

@ -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;
@ -1586,6 +1587,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;
/**

View File

@ -1394,6 +1394,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, &param, 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);
@ -1793,6 +1813,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;
@ -1921,6 +1953,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;
@ -2434,6 +2473,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)

View File

@ -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
*******************************************************************************/
@ -326,6 +328,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
@ -4529,6 +4536,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
@ -4585,6 +4612,8 @@ void btm_ble_init (void)
#if BLE_VND_INCLUDED == FALSE
btm_ble_adv_filter_init();
#endif
BTM_RegisterForVSEvents(btm_ble_vs_evt_callback, TRUE);
}
/*******************************************************************************

View File

@ -202,6 +202,8 @@ 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 DISCOVERY - Inquiry, Remote Name, Discovery, Class of Device
*****************************************************************************/

View File

@ -1384,6 +1384,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);
/*******************************************************************************
**

View File

@ -827,6 +827,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 */