feat(ble/bluedroid): Support BLE vendor event reporting with params

This commit is contained in:
chenjianhua
2025-03-06 14:28:51 +08:00
parent 412c535f98
commit 2844ec6049
6 changed files with 99 additions and 17 deletions

View File

@ -1741,7 +1741,7 @@ esp_err_t esp_ble_gap_vendor_command_send(esp_ble_vendor_cmd_params_t *vendor_cm
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gap_set_vendor_event_mask(uint32_t event_mask)
esp_err_t esp_ble_gap_set_vendor_event_mask(esp_ble_vendor_evt_mask_t event_mask)
{
btc_msg_t msg = {0};
btc_ble_gap_args_t arg;

View File

@ -1102,11 +1102,58 @@ typedef struct {
} esp_ble_gap_past_params_t;
#endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
typedef enum{
typedef enum {
ESP_BLE_NETWORK_PRIVACY_MODE = 0X00, /*!< Network Privacy Mode for peer device (default) */
ESP_BLE_DEVICE_PRIVACY_MODE = 0X01, /*!< Device Privacy Mode for peer device */
} esp_ble_privacy_mode_t;
#define ESP_BLE_VENDOR_SCAN_REQ_RECV_EVT_MASK BIT(0) /*!< Vendor BLE legacy SCAN_REQ received event mask */
#define ESP_BLE_VENDOR_CHMAP_UPDATE_EVT_MASK BIT(1) /*!< Vendor BLE channel map update event mask */
#define ESP_BLE_VENDOR_SLEEP_WAKEUP_EVT_MASK BIT(3) /*!< Vendor BLE sleep wakeup event mask */
#define ESP_BLE_VENDOR_CONN_REQ_RECV_EVT_MASK BIT(4) /*!< Vendor BLE CONNECT_IND and AUX_CONNECT_REQ received event mask */
#define ESP_BLE_VENDOR_CONN_RSP_RECV_EVT_MASK BIT(5) /*!< Vendor BLE AUX_CONNECT_RSP received event mask */
typedef uint32_t esp_ble_vendor_evt_mask_t;
#define ESP_BLE_VENDOR_PDU_RECV_EVT (0) /*!< Vendor BLE specify PDU received event */
#define ESP_BLE_VENDOR_CHAN_MAP_UPDATE_EVT (1) /*!< Vendor BLE channel map update complete event */
#define ESP_BLE_VENDOR_SLEEP_WAKEUP_EVT (2) /*!< Vendor BLE sleep wakeup event */
typedef uint8_t esp_ble_vendor_evt_t;
typedef enum {
ESP_BLE_VENDOR_PDU_SCAN_REQ = 0, /*!< SCAN_REQ PDU type */
ESP_BLE_VENDOR_PDU_CONN_REQ, /*!< CONNECT_IND and AUX_CONNECT_REQ PDU type */
ESP_BLE_VENDOR_PDU_CONN_RSP, /*!< AUX_CONNECT_RSP PDU type */
} esp_ble_vendor_pdu_t;
/**
* @brief BLE vendor event parameters union
*/
typedef union {
/**
* @brief ESP_BLE_VENDOR_PDU_RECV_EVT
*/
struct ble_pdu_recv_evt_param {
esp_ble_vendor_pdu_t type; /*!< The type of LE PDU */
uint8_t handle; /*!< The handle of advertising set */
esp_ble_addr_type_t addr_type; /*!< The address type of peer device */
esp_bd_addr_t peer_addr; /*!< The address of peer device */
} pdu_recv; /*!< Event parameter of ESP_BLE_VENDOR_PDU_RECV_EVT */
/**
* @brief ESP_BLE_VENDOR_CHAN_MAP_UPDATE_EVT
*/
struct ble_chan_map_update_evt_param {
uint8_t status; /*!< Indicate the channel map update status (HCI error code) */
uint16_t conn_handle; /*!< The connection handle */
esp_gap_ble_channels ch_map; /*!< The channel map after updated */
} chan_map_update; /*!< Event parameter of ESP_BLE_VENDOR_CHAN_MAP_UPDATE_EVT */
/**
* @brief ESP_BLE_VENDOR_SLEEP_WAKEUP_EVT
*/
struct ble_sleep_wakeup_evt_param {
// No parameters
} sleep_wakeup; /*!< Event parameter of ESP_BLE_VENDOR_SLEEP_WAKEUP_EVT */
} esp_ble_vendor_evt_param_t;
/**
* @brief path loss report parameters
*/
@ -1695,10 +1742,11 @@ typedef union {
* @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_vendor_evt_t subevt_code; /*!< Subevent code for BLE vendor HCI event */
esp_ble_vendor_evt_param_t param; /*!< Event parameter of BLE vendor HCI subevent */
uint8_t param_len; /*!< The length of the event parameter buffer (for internal use only) */
uint8_t *param_buf; /*!< The pointer of the event parameter buffer (for internal use only) */
} vendor_hci_evt; /*!< Event parameter of ESP_GAP_BLE_VENDOR_HCI_EVT */
#if (BLE_FEAT_POWER_CONTROL_EN == TRUE)
/**
* @brief ESP_GAP_BLE_ENH_READ_TRANS_PWR_LEVEL_EVT
@ -3032,14 +3080,13 @@ esp_err_t esp_ble_gap_set_csa_support(uint8_t csa_select);
/**
* @brief This function is used to control which vendor events are generated by the HCI for the Host.
*
* @param[in] event_mask: Bit0: Legacy scan request received event
* Bit1: Vendor channel map update complete event
* @param[in] event_mask: The BLE vendor HCI event mask
*
* @return
* - ESP_OK : success
* - other : failed
*/
esp_err_t esp_ble_gap_set_vendor_event_mask(uint32_t event_mask);
esp_err_t esp_ble_gap_set_vendor_event_mask(esp_ble_vendor_evt_mask_t event_mask);
/**
* @brief This function is used to read the current and maximum transmit power levels of the local Controller.

View File

@ -1490,7 +1490,7 @@ static void btc_ble_set_vendor_evt_mask_callback(UINT8 status)
msg.pid = BTC_PID_GAP_BLE;
msg.act = ESP_GAP_BLE_SET_VENDOR_EVT_MASK_COMPLETE_EVT;
param.set_csa_support_cmpl.status = btc_btm_status_to_esp_status(status);
param.set_vendor_evt_mask_cmpl.status = btc_btm_status_to_esp_status(status);
ret = btc_transfer_context(&msg, &param, sizeof(esp_ble_gap_cb_param_t), NULL, NULL);
@ -1504,15 +1504,46 @@ static void btc_ble_vendor_hci_event_callback(UINT8 subevt_code, UINT8 param_len
esp_ble_gap_cb_param_t param = {0};
bt_status_t ret;
btc_msg_t msg = {0};
esp_ble_vendor_evt_param_t *evt_param = &param.vendor_hci_evt.param;
bool copy_param = false;
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);
param.vendor_hci_evt.param_len = 0;
param.vendor_hci_evt.param_buf = NULL;
switch (subevt_code) {
case BLE_VENDOR_PDU_RECV_EVT:
param.vendor_hci_evt.subevt_code = ESP_BLE_VENDOR_PDU_RECV_EVT;
STREAM_TO_UINT8(evt_param->pdu_recv.type, params);
STREAM_TO_UINT8(evt_param->pdu_recv.handle, params);
STREAM_TO_UINT8(evt_param->pdu_recv.addr_type, params);
STREAM_TO_BDADDR(evt_param->pdu_recv.peer_addr, params);
break;
case BLE_VENDOR_CHMAP_UPDATE_EVT:
param.vendor_hci_evt.subevt_code = ESP_BLE_VENDOR_CHAN_MAP_UPDATE_EVT;
STREAM_TO_UINT8(evt_param->chan_map_update.status, params);
STREAM_TO_UINT16(evt_param->chan_map_update.conn_handle, params);
REVERSE_STREAM_TO_ARRAY(evt_param->chan_map_update.ch_map, params, ESP_GAP_BLE_CHANNELS_LEN);
break;
case BLE_VENDOR_SLEEP_WAKEUP_EVT:
param.vendor_hci_evt.subevt_code = ESP_BLE_VENDOR_SLEEP_WAKEUP_EVT;
// No parameters
break;
default:
copy_param = true;
break;
}
if (copy_param) {
param.vendor_hci_evt.param_len = param_len;
param.vendor_hci_evt.param_buf = (param_len) ? params : NULL;
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);
} else {
ret = btc_transfer_context(&msg, &param, sizeof(esp_ble_gap_cb_param_t), NULL, NULL);
}
if (ret != BT_STATUS_SUCCESS) {
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);

View File

@ -24,6 +24,10 @@ extern tBTA_BLE_ADV_DATA *gl_bta_scan_rsp_data_ptr;
#define BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)))
#define BLE_VENDOR_PDU_RECV_EVT (0xC0)
#define BLE_VENDOR_CHMAP_UPDATE_EVT (0xC1)
#define BLE_VENDOR_SLEEP_WAKEUP_EVT (0xC3)
typedef enum {
#if (BLE_42_FEATURE_SUPPORT == TRUE)
BTC_GAP_BLE_ACT_CFG_ADV_DATA = 0,

View File

@ -4559,7 +4559,7 @@ static void btm_ble_vs_evt_callback(UINT8 len, UINT8 *p)
STREAM_TO_UINT8(sub_event, p);
len--;
if (sub_event < HCI_VSE_LE_LEGACY_SCAN_REQ_RECEIVED_EVT) {
if (sub_event < HCI_VSE_LE_SUBEVT_BASE) {
return;
}

View File

@ -926,9 +926,9 @@
#define HCI_VENDOR_CH_CLASSIFICATION_EVT_SUBCODE 0x06
#define HCI_VENDOR_CH_CLASSIFICATION_REPORTING_MODE_EVT_SUBCODE 0x07
#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_VENDOR_SPECIFIC_EVT 0xFF /* Vendor specific events */
#define HCI_VSE_LE_SUBEVT_BASE 0xC0 /* BLE vendor event code base */
#define HCI_VSE_LE_EVT_MAX 0xFF /* BLE vendor event code max */
#define HCI_NAP_TRACE_EVT 0xFF /* was define 0xFE, 0xFD, change to 0xFF
because conflict w/ TCI_EVT and per
specification compliant */