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

This commit is contained in:
chenjianhua 2025-02-08 09:54:17 +08:00
parent fd4094e502
commit 1003ced6e9
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_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_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_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_EVT_MAX, /*!< when maximum advertising event complete, the event comes */
} esp_gap_ble_cb_event_t; } esp_gap_ble_cb_event_t;
@ -1588,6 +1589,14 @@ typedef union {
struct ble_set_vendor_evt_mask_cmpl_evt_param { struct ble_set_vendor_evt_mask_cmpl_evt_param {
esp_bt_status_t status; /*!< Indicate set vendor event mask operation success status */ 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 */ } 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; } esp_ble_gap_cb_param_t;
/** /**

View File

@ -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, &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) void btc_get_whitelist_size(uint16_t *length)
{ {
BTM_BleGetWhiteListSize(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; 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: default:
BTC_TRACE_ERROR("%s, Unhandled deep copy %d\n", __func__, msg->act); BTC_TRACE_ERROR("%s, Unhandled deep copy %d\n", __func__, msg->act);
break; break;
@ -1966,6 +1998,13 @@ void btc_gap_ble_cb_deep_free(btc_msg_t *msg)
} }
break; 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: default:
BTC_TRACE_DEBUG("Unhandled deep free %d", msg->act); BTC_TRACE_DEBUG("Unhandled deep free %d", msg->act);
break; break;
@ -2498,6 +2537,7 @@ void btc_gap_callback_init(void)
#if (BLE_50_FEATURE_SUPPORT == TRUE) #if (BLE_50_FEATURE_SUPPORT == TRUE)
BTM_BleGapRegisterCallback(btc_ble_5_gap_callback); BTM_BleGapRegisterCallback(btc_ble_5_gap_callback);
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
BTM_BleRegisterVendorHciEventCallback(btc_ble_vendor_hci_event_callback);
} }
bool btc_gap_ble_init(void) 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 #endif
tBTM_CallbackFunc conn_callback_func; tBTM_CallbackFunc conn_callback_func;
// BLE vendor HCI event callback
static tBTM_BLE_VENDOR_HCI_EVT_CBACK *ble_vs_evt_callback = NULL;
/******************************************************************************* /*******************************************************************************
** Local functions ** 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; 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 ** 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; 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 ** Function btm_ble_init
@ -4600,6 +4627,8 @@ void btm_ble_init (void)
btm_ble_adv_filter_init(); btm_ble_adv_filter_init();
#endif // #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE #endif // #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
#endif #endif
BTM_RegisterForVSEvents(btm_ble_vs_evt_callback, TRUE);
} }
/******************************************************************************* /*******************************************************************************

View File

@ -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_SET_RPA_TIMEOUT_CMPL_CBACK) (UINT8 status);
typedef void (tBTM_ADD_DEV_TO_RESOLVING_LIST_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 ** Device Coexist status
********************************/ ********************************/

View File

@ -1417,6 +1417,7 @@ extern "C" {
*******************************************************************************/ *******************************************************************************/
void BTM_BleRegiseterConnParamCallback(tBTM_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb); 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_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

@ -832,6 +832,9 @@
#define HCI_BLE_CHNL_MAP_SIZE 5 #define HCI_BLE_CHNL_MAP_SIZE 5
#define HCI_VENDOR_SPECIFIC_EVT 0xFF /* Vendor specific events */ #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 #define HCI_NAP_TRACE_EVT 0xFF /* was define 0xFE, 0xFD, change to 0xFF
because conflict w/ TCI_EVT and per because conflict w/ TCI_EVT and per
specification compliant */ specification compliant */