Skip to content

Commit 0fe1586

Browse files
committed
feat(ble/bluedroid): Support BLE vendor event reporting with params
1 parent 48b37dd commit 0fe1586

File tree

6 files changed

+99
-17
lines changed

6 files changed

+99
-17
lines changed

components/bt/host/bluedroid/api/esp_gap_ble_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ esp_err_t esp_ble_gap_vendor_command_send(esp_ble_vendor_cmd_params_t *vendor_cm
17411741
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
17421742
}
17431743

1744-
esp_err_t esp_ble_gap_set_vendor_event_mask(uint32_t event_mask)
1744+
esp_err_t esp_ble_gap_set_vendor_event_mask(esp_ble_vendor_evt_mask_t event_mask)
17451745
{
17461746
btc_msg_t msg = {0};
17471747
btc_ble_gap_args_t arg;

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

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,11 +1102,58 @@ typedef struct {
11021102
} esp_ble_gap_past_params_t;
11031103
#endif // #if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
11041104

1105-
typedef enum{
1105+
typedef enum {
11061106
ESP_BLE_NETWORK_PRIVACY_MODE = 0X00, /*!< Network Privacy Mode for peer device (default) */
11071107
ESP_BLE_DEVICE_PRIVACY_MODE = 0X01, /*!< Device Privacy Mode for peer device */
11081108
} esp_ble_privacy_mode_t;
11091109

1110+
#define ESP_BLE_VENDOR_SCAN_REQ_RECV_EVT_MASK BIT(0) /*!< Vendor BLE legacy SCAN_REQ received event mask */
1111+
#define ESP_BLE_VENDOR_CHMAP_UPDATE_EVT_MASK BIT(1) /*!< Vendor BLE channel map update event mask */
1112+
#define ESP_BLE_VENDOR_SLEEP_WAKEUP_EVT_MASK BIT(3) /*!< Vendor BLE sleep wakeup event mask */
1113+
#define ESP_BLE_VENDOR_CONN_REQ_RECV_EVT_MASK BIT(4) /*!< Vendor BLE CONNECT_IND and AUX_CONNECT_REQ received event mask */
1114+
#define ESP_BLE_VENDOR_CONN_RSP_RECV_EVT_MASK BIT(5) /*!< Vendor BLE AUX_CONNECT_RSP received event mask */
1115+
typedef uint32_t esp_ble_vendor_evt_mask_t;
1116+
1117+
#define ESP_BLE_VENDOR_PDU_RECV_EVT (0) /*!< Vendor BLE specify PDU received event */
1118+
#define ESP_BLE_VENDOR_CHAN_MAP_UPDATE_EVT (1) /*!< Vendor BLE channel map update complete event */
1119+
#define ESP_BLE_VENDOR_SLEEP_WAKEUP_EVT (2) /*!< Vendor BLE sleep wakeup event */
1120+
typedef uint8_t esp_ble_vendor_evt_t;
1121+
1122+
typedef enum {
1123+
ESP_BLE_VENDOR_PDU_SCAN_REQ = 0, /*!< SCAN_REQ PDU type */
1124+
ESP_BLE_VENDOR_PDU_CONN_REQ, /*!< CONNECT_IND and AUX_CONNECT_REQ PDU type */
1125+
ESP_BLE_VENDOR_PDU_CONN_RSP, /*!< AUX_CONNECT_RSP PDU type */
1126+
} esp_ble_vendor_pdu_t;
1127+
1128+
/**
1129+
* @brief BLE vendor event parameters union
1130+
*/
1131+
typedef union {
1132+
/**
1133+
* @brief ESP_BLE_VENDOR_PDU_RECV_EVT
1134+
*/
1135+
struct ble_pdu_recv_evt_param {
1136+
esp_ble_vendor_pdu_t type; /*!< The type of LE PDU */
1137+
uint8_t handle; /*!< The handle of advertising set */
1138+
esp_ble_addr_type_t addr_type; /*!< The address type of peer device */
1139+
esp_bd_addr_t peer_addr; /*!< The address of peer device */
1140+
} pdu_recv; /*!< Event parameter of ESP_BLE_VENDOR_PDU_RECV_EVT */
1141+
/**
1142+
* @brief ESP_BLE_VENDOR_CHAN_MAP_UPDATE_EVT
1143+
*/
1144+
struct ble_chan_map_update_evt_param {
1145+
uint8_t status; /*!< Indicate the channel map update status (HCI error code) */
1146+
uint16_t conn_handle; /*!< The connection handle */
1147+
esp_gap_ble_channels ch_map; /*!< The channel map after updated */
1148+
} chan_map_update; /*!< Event parameter of ESP_BLE_VENDOR_CHAN_MAP_UPDATE_EVT */
1149+
/**
1150+
* @brief ESP_BLE_VENDOR_SLEEP_WAKEUP_EVT
1151+
*/
1152+
struct ble_sleep_wakeup_evt_param {
1153+
// No parameters
1154+
} sleep_wakeup; /*!< Event parameter of ESP_BLE_VENDOR_SLEEP_WAKEUP_EVT */
1155+
} esp_ble_vendor_evt_param_t;
1156+
11101157
/**
11111158
* @brief path loss report parameters
11121159
*/
@@ -1695,10 +1742,11 @@ typedef union {
16951742
* @brief ESP_GAP_BLE_VENDOR_HCI_EVT
16961743
*/
16971744
struct ble_vendor_hci_event_evt_param {
1698-
uint8_t subevt_code; /*!< Subevent code for vendor HCI event, the range is 0xC0 to 0xFF */
1699-
uint8_t param_len; /*!< The length of the event parameter buffer */
1700-
uint8_t *param_buf; /*!< The pointer of the event parameter buffer */
1701-
} vendor_hci_evt; /*!< Event parameter buffer of ESP_GAP_BLE_VENDOR_HCI_EVT */
1745+
esp_ble_vendor_evt_t subevt_code; /*!< Subevent code for BLE vendor HCI event */
1746+
esp_ble_vendor_evt_param_t param; /*!< Event parameter of BLE vendor HCI subevent */
1747+
uint8_t param_len; /*!< The length of the event parameter buffer (for internal use only) */
1748+
uint8_t *param_buf; /*!< The pointer of the event parameter buffer (for internal use only) */
1749+
} vendor_hci_evt; /*!< Event parameter of ESP_GAP_BLE_VENDOR_HCI_EVT */
17021750
#if (BLE_FEAT_POWER_CONTROL_EN == TRUE)
17031751
/**
17041752
* @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);
30323080
/**
30333081
* @brief This function is used to control which vendor events are generated by the HCI for the Host.
30343082
*
3035-
* @param[in] event_mask: Bit0: Legacy scan request received event
3036-
* Bit1: Vendor channel map update complete event
3083+
* @param[in] event_mask: The BLE vendor HCI event mask
30373084
*
30383085
* @return
30393086
* - ESP_OK : success
30403087
* - other : failed
30413088
*/
3042-
esp_err_t esp_ble_gap_set_vendor_event_mask(uint32_t event_mask);
3089+
esp_err_t esp_ble_gap_set_vendor_event_mask(esp_ble_vendor_evt_mask_t event_mask);
30433090

30443091
/**
30453092
* @brief This function is used to read the current and maximum transmit power levels of the local Controller.

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

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ static void btc_ble_set_vendor_evt_mask_callback(UINT8 status)
14901490
msg.pid = BTC_PID_GAP_BLE;
14911491
msg.act = ESP_GAP_BLE_SET_VENDOR_EVT_MASK_COMPLETE_EVT;
14921492

1493-
param.set_csa_support_cmpl.status = btc_btm_status_to_esp_status(status);
1493+
param.set_vendor_evt_mask_cmpl.status = btc_btm_status_to_esp_status(status);
14941494

14951495
ret = btc_transfer_context(&msg, &param, sizeof(esp_ble_gap_cb_param_t), NULL, NULL);
14961496

@@ -1504,15 +1504,46 @@ static void btc_ble_vendor_hci_event_callback(UINT8 subevt_code, UINT8 param_len
15041504
esp_ble_gap_cb_param_t param = {0};
15051505
bt_status_t ret;
15061506
btc_msg_t msg = {0};
1507+
esp_ble_vendor_evt_param_t *evt_param = &param.vendor_hci_evt.param;
1508+
bool copy_param = false;
15071509

15081510
msg.sig = BTC_SIG_API_CB;
15091511
msg.pid = BTC_PID_GAP_BLE;
15101512
msg.act = ESP_GAP_BLE_VENDOR_HCI_EVT;
15111513

15121514
param.vendor_hci_evt.subevt_code = subevt_code;
1513-
param.vendor_hci_evt.param_len = param_len;
1514-
param.vendor_hci_evt.param_buf = params;
1515-
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);
1515+
param.vendor_hci_evt.param_len = 0;
1516+
param.vendor_hci_evt.param_buf = NULL;
1517+
switch (subevt_code) {
1518+
case BLE_VENDOR_PDU_RECV_EVT:
1519+
param.vendor_hci_evt.subevt_code = ESP_BLE_VENDOR_PDU_RECV_EVT;
1520+
STREAM_TO_UINT8(evt_param->pdu_recv.type, params);
1521+
STREAM_TO_UINT8(evt_param->pdu_recv.handle, params);
1522+
STREAM_TO_UINT8(evt_param->pdu_recv.addr_type, params);
1523+
STREAM_TO_BDADDR(evt_param->pdu_recv.peer_addr, params);
1524+
break;
1525+
case BLE_VENDOR_CHMAP_UPDATE_EVT:
1526+
param.vendor_hci_evt.subevt_code = ESP_BLE_VENDOR_CHAN_MAP_UPDATE_EVT;
1527+
STREAM_TO_UINT8(evt_param->chan_map_update.status, params);
1528+
STREAM_TO_UINT16(evt_param->chan_map_update.conn_handle, params);
1529+
REVERSE_STREAM_TO_ARRAY(evt_param->chan_map_update.ch_map, params, ESP_GAP_BLE_CHANNELS_LEN);
1530+
break;
1531+
case BLE_VENDOR_SLEEP_WAKEUP_EVT:
1532+
param.vendor_hci_evt.subevt_code = ESP_BLE_VENDOR_SLEEP_WAKEUP_EVT;
1533+
// No parameters
1534+
break;
1535+
default:
1536+
copy_param = true;
1537+
break;
1538+
}
1539+
1540+
if (copy_param) {
1541+
param.vendor_hci_evt.param_len = param_len;
1542+
param.vendor_hci_evt.param_buf = (param_len) ? params : NULL;
1543+
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);
1544+
} else {
1545+
ret = btc_transfer_context(&msg, &param, sizeof(esp_ble_gap_cb_param_t), NULL, NULL);
1546+
}
15161547

15171548
if (ret != BT_STATUS_SUCCESS) {
15181549
BTC_TRACE_ERROR("%s btc_transfer_context failed\n", __func__);

components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ extern tBTA_BLE_ADV_DATA *gl_bta_scan_rsp_data_ptr;
2424

2525
#define BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)))
2626

27+
#define BLE_VENDOR_PDU_RECV_EVT (0xC0)
28+
#define BLE_VENDOR_CHMAP_UPDATE_EVT (0xC1)
29+
#define BLE_VENDOR_SLEEP_WAKEUP_EVT (0xC3)
30+
2731
typedef enum {
2832
#if (BLE_42_FEATURE_SUPPORT == TRUE)
2933
BTC_GAP_BLE_ACT_CFG_ADV_DATA = 0,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4559,7 +4559,7 @@ static void btm_ble_vs_evt_callback(UINT8 len, UINT8 *p)
45594559
STREAM_TO_UINT8(sub_event, p);
45604560
len--;
45614561

4562-
if (sub_event < HCI_VSE_LE_LEGACY_SCAN_REQ_RECEIVED_EVT) {
4562+
if (sub_event < HCI_VSE_LE_SUBEVT_BASE) {
45634563
return;
45644564
}
45654565

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -927,9 +927,9 @@
927927
#define HCI_VENDOR_CH_CLASSIFICATION_EVT_SUBCODE 0x06
928928
#define HCI_VENDOR_CH_CLASSIFICATION_REPORTING_MODE_EVT_SUBCODE 0x07
929929

930-
#define HCI_VSE_LE_LEGACY_SCAN_REQ_RECEIVED_EVT 0xC0
931-
#define HCI_VSE_LE_CHAN_MAP_UPDATE_CMPL_EVT 0xC1
932-
#define HCI_VSE_LE_EVT_MAX 0xFF
930+
#define HCI_VENDOR_SPECIFIC_EVT 0xFF /* Vendor specific events */
931+
#define HCI_VSE_LE_SUBEVT_BASE 0xC0 /* BLE vendor event code base */
932+
#define HCI_VSE_LE_EVT_MAX 0xFF /* BLE vendor event code max */
933933
#define HCI_NAP_TRACE_EVT 0xFF /* was define 0xFE, 0xFD, change to 0xFF
934934
because conflict w/ TCI_EVT and per
935935
specification compliant */

0 commit comments

Comments
 (0)