Skip to content

Commit 85d74cd

Browse files
committed
Merge branch 'feat/support_ble_vendor_evt_report_with_param' into 'master'
feat(bt/bluedroid): Support BLE vendor event reporting with params Closes BLERP-1624 See merge request espressif/esp-idf!37539
2 parents a4fcd06 + 71e15a1 commit 85d74cd

File tree

14 files changed

+365
-239
lines changed

14 files changed

+365
-239
lines changed

components/bt/host/bluedroid/Kconfig.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,13 @@ config BT_BLE_FEAT_CONN_SUBRATING
14931493
help
14941494
Enable BLE connection subrating feature
14951495

1496+
config BT_BLE_VENDOR_HCI_EN
1497+
bool "Enable BLE Vendor HCI command and event"
1498+
depends on BT_BLE_ENABLED
1499+
default y
1500+
help
1501+
This enables BLE vendor HCI command and event
1502+
14961503
config BT_BLE_HIGH_DUTY_ADV_INTERVAL
14971504
bool "Enable BLE high duty advertising interval feature"
14981505
depends on BT_BLE_ENABLED

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

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,6 @@ esp_err_t esp_ble_gap_stop_advertising(void)
131131

132132
return (btc_transfer_context(&msg, NULL, 0, NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
133133
}
134-
135-
esp_err_t esp_ble_gap_clear_advertising(void)
136-
{
137-
btc_msg_t msg;
138-
139-
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
140-
141-
msg.sig = BTC_SIG_API_CALL;
142-
msg.pid = BTC_PID_GAP_BLE;
143-
msg.act = BTC_GAP_BLE_ACT_CLEAR_ADV;
144-
145-
return (btc_transfer_context(&msg, NULL, 0, NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
146-
}
147134
#endif // #if (BLE_42_ADV_EN == TRUE)
148135
#endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
149136

@@ -1013,23 +1000,6 @@ esp_err_t esp_ble_gap_set_privacy_mode(esp_ble_addr_type_t addr_type, esp_bd_add
10131000
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
10141001
}
10151002

1016-
esp_err_t esp_ble_gap_set_csa_support(uint8_t csa_select)
1017-
{
1018-
btc_msg_t msg;
1019-
btc_ble_gap_args_t arg;
1020-
1021-
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1022-
1023-
msg.sig = BTC_SIG_API_CALL;
1024-
msg.pid = BTC_PID_GAP_BLE;
1025-
msg.act = BTC_GAP_BLE_SET_CSA_SUPPORT;
1026-
1027-
arg.set_csa_support.csa_select = csa_select;
1028-
1029-
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL)
1030-
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1031-
}
1032-
10331003
#if (BLE_50_FEATURE_SUPPORT == TRUE)
10341004

10351005
esp_err_t esp_ble_gap_read_phy(esp_bd_addr_t bd_addr)
@@ -1713,6 +1683,7 @@ esp_err_t esp_ble_gap_set_periodic_adv_sync_trans_params(esp_bd_addr_t addr, con
17131683
}
17141684
#endif //#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
17151685

1686+
#if (BLE_VENDOR_HCI_EN == TRUE)
17161687
esp_err_t esp_ble_gap_vendor_command_send(esp_ble_vendor_cmd_params_t *vendor_cmd_param)
17171688
{
17181689
btc_msg_t msg = {0};
@@ -1741,7 +1712,7 @@ esp_err_t esp_ble_gap_vendor_command_send(esp_ble_vendor_cmd_params_t *vendor_cm
17411712
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
17421713
}
17431714

1744-
esp_err_t esp_ble_gap_set_vendor_event_mask(uint32_t event_mask)
1715+
esp_err_t esp_ble_gap_set_vendor_event_mask(esp_ble_vendor_evt_mask_t event_mask)
17451716
{
17461717
btc_msg_t msg = {0};
17471718
btc_ble_gap_args_t arg;
@@ -1759,6 +1730,37 @@ esp_err_t esp_ble_gap_set_vendor_event_mask(uint32_t event_mask)
17591730
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
17601731
}
17611732

1733+
esp_err_t esp_ble_gap_clear_advertising(void)
1734+
{
1735+
btc_msg_t msg;
1736+
1737+
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1738+
1739+
msg.sig = BTC_SIG_API_CALL;
1740+
msg.pid = BTC_PID_GAP_BLE;
1741+
msg.act = BTC_GAP_BLE_ACT_CLEAR_ADV;
1742+
1743+
return (btc_transfer_context(&msg, NULL, 0, NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1744+
}
1745+
1746+
esp_err_t esp_ble_gap_set_csa_support(uint8_t csa_select)
1747+
{
1748+
btc_msg_t msg;
1749+
btc_ble_gap_args_t arg;
1750+
1751+
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
1752+
1753+
msg.sig = BTC_SIG_API_CALL;
1754+
msg.pid = BTC_PID_GAP_BLE;
1755+
msg.act = BTC_GAP_BLE_SET_CSA_SUPPORT;
1756+
1757+
arg.set_csa_support.csa_select = csa_select;
1758+
1759+
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL, NULL)
1760+
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
1761+
}
1762+
#endif // (BLE_VENDOR_HCI_EN == TRUE)
1763+
17621764
#if (BLE_FEAT_POWER_CONTROL_EN == TRUE)
17631765
esp_err_t esp_ble_gap_enhanced_read_transmit_power_level(uint16_t conn_handle, esp_ble_tx_power_phy_t phy)
17641766
{

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

Lines changed: 69 additions & 20 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
*/
@@ -1258,12 +1305,6 @@ typedef union {
12581305
struct ble_adv_stop_cmpl_evt_param {
12591306
esp_bt_status_t status; /*!< Indicate adv stop operation success status */
12601307
} adv_stop_cmpl; /*!< Event parameter of ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT */
1261-
/**
1262-
* @brief ESP_GAP_BLE_ADV_CLEAR_COMPLETE_EVT
1263-
*/
1264-
struct ble_adv_clear_cmpl_evt_param {
1265-
esp_bt_status_t status; /*!< Indicate adv clear operation success status */
1266-
} adv_clear_cmpl; /*!< Event parameter of ESP_GAP_BLE_ADV_CLEAR_COMPLETE_EVT */
12671308
#endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
12681309
/**
12691310
* @brief ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT
@@ -1665,6 +1706,19 @@ typedef union {
16651706
esp_ble_dtm_update_evt_t update_evt; /*!< DTM state change event, 0x00: DTM TX start, 0x01: DTM RX start, 0x02:DTM end */
16661707
uint16_t num_of_pkt; /*!< number of packets received, only valid if update_evt is DTM_TEST_STOP_EVT and shall be reported as 0 for a transmitter */
16671708
} dtm_state_update; /*!< Event parameter of ESP_GAP_BLE_DTM_TEST_UPDATE_EVT */
1709+
/**
1710+
* @brief ESP_GAP_BLE_SET_PRIVACY_MODE_COMPLETE_EVT
1711+
*/
1712+
struct ble_set_privacy_mode_cmpl_evt_param {
1713+
esp_bt_status_t status; /*!< Indicate privacy mode set operation success status */
1714+
} set_privacy_mode_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_PRIVACY_MODE_COMPLETE_EVT */
1715+
#if (BLE_VENDOR_HCI_EN == TRUE)
1716+
/**
1717+
* @brief ESP_GAP_BLE_ADV_CLEAR_COMPLETE_EVT
1718+
*/
1719+
struct ble_adv_clear_cmpl_evt_param {
1720+
esp_bt_status_t status; /*!< Indicate adv clear operation success status */
1721+
} adv_clear_cmpl; /*!< Event parameter of ESP_GAP_BLE_ADV_CLEAR_COMPLETE_EVT */
16681722
/**
16691723
* @brief ESP_GAP_BLE_VENDOR_CMD_COMPLETE_EVT
16701724
*/
@@ -1673,12 +1727,6 @@ typedef union {
16731727
uint16_t param_len; /*!< The length of parameter buffer */
16741728
uint8_t *p_param_buf; /*!< The point of parameter buffer */
16751729
} vendor_cmd_cmpl; /*!< Event parameter of ESP_GAP_BLE_VENDOR_CMD_COMPLETE_EVT */
1676-
/**
1677-
* @brief ESP_GAP_BLE_SET_PRIVACY_MODE_COMPLETE_EVT
1678-
*/
1679-
struct ble_set_privacy_mode_cmpl_evt_param {
1680-
esp_bt_status_t status; /*!< Indicate privacy mode set operation success status */
1681-
} set_privacy_mode_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_PRIVACY_MODE_COMPLETE_EVT */
16821730
/**
16831731
* @brief ESP_GAP_BLE_SET_CSA_SUPPORT_COMPLETE_EVT
16841732
*/
@@ -1695,10 +1743,12 @@ typedef union {
16951743
* @brief ESP_GAP_BLE_VENDOR_HCI_EVT
16961744
*/
16971745
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 */
1746+
esp_ble_vendor_evt_t subevt_code; /*!< Subevent code for BLE vendor HCI event */
1747+
esp_ble_vendor_evt_param_t param; /*!< Event parameter of BLE vendor HCI subevent */
1748+
uint8_t param_len; /*!< The length of the event parameter buffer (for internal use only) */
1749+
uint8_t *param_buf; /*!< The pointer of the event parameter buffer (for internal use only) */
1750+
} vendor_hci_evt; /*!< Event parameter of ESP_GAP_BLE_VENDOR_HCI_EVT */
1751+
#endif // #if (BLE_VENDOR_HCI_EN == TRUE)
17021752
#if (BLE_FEAT_POWER_CONTROL_EN == TRUE)
17031753
/**
17041754
* @brief ESP_GAP_BLE_ENH_READ_TRANS_PWR_LEVEL_EVT
@@ -3032,14 +3082,13 @@ esp_err_t esp_ble_gap_set_csa_support(uint8_t csa_select);
30323082
/**
30333083
* @brief This function is used to control which vendor events are generated by the HCI for the Host.
30343084
*
3035-
* @param[in] event_mask: Bit0: Legacy scan request received event
3036-
* Bit1: Vendor channel map update complete event
3085+
* @param[in] event_mask: The BLE vendor HCI event mask
30373086
*
30383087
* @return
30393088
* - ESP_OK : success
30403089
* - other : failed
30413090
*/
3042-
esp_err_t esp_ble_gap_set_vendor_event_mask(uint32_t event_mask);
3091+
esp_err_t esp_ble_gap_set_vendor_event_mask(esp_ble_vendor_evt_mask_t event_mask);
30433092

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

components/bt/host/bluedroid/bta/dm/bta_dm_act.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ void bta_dm_cfg_coex_status (tBTA_DM_MSG *p_data)
733733
}
734734
#endif
735735

736+
#if (BLE_VENDOR_HCI_EN == TRUE)
736737
void bta_dm_send_vendor_hci(tBTA_DM_MSG *p_data)
737738
{
738739
BTM_VendorSpecificCommand(p_data->vendor_hci_cmd.opcode,
@@ -741,6 +742,28 @@ void bta_dm_send_vendor_hci(tBTA_DM_MSG *p_data)
741742
p_data->vendor_hci_cmd.vendor_hci_cb);
742743
}
743744

745+
void bta_dm_ble_gap_clear_adv(tBTA_DM_MSG *p_data)
746+
{
747+
if (BTM_BleClearAdv(p_data->ble_clear_adv.p_clear_adv_cback) == FALSE) {
748+
if (p_data->ble_clear_adv.p_clear_adv_cback) {
749+
(*p_data->ble_clear_adv.p_clear_adv_cback)(BTA_FAILURE);
750+
}
751+
}
752+
}
753+
754+
void bta_dm_ble_gap_set_csa_support(tBTA_DM_MSG *p_data)
755+
{
756+
APPL_TRACE_API("%s, csa_select = %d", __func__, p_data->ble_set_csa_support.csa_select);
757+
BTM_BleSetCsaSupport(p_data->ble_set_csa_support.csa_select, p_data->ble_set_csa_support.p_cback);
758+
}
759+
760+
void bta_dm_ble_gap_set_vendor_evt_mask(tBTA_DM_MSG *p_data)
761+
{
762+
APPL_TRACE_API("%s, evt_mask = %d", __func__, p_data->ble_set_vendor_evt_mask.evt_mask);
763+
BTM_BleSetVendorEventMask(p_data->ble_set_vendor_evt_mask.evt_mask, p_data->ble_set_vendor_evt_mask.p_cback);
764+
}
765+
#endif // #if (BLE_VENDOR_HCI_EN == TRUE)
766+
744767
/*******************************************************************************
745768
**
746769
** Function bta_dm_set_afh_channels
@@ -5822,15 +5845,6 @@ void bta_dm_ble_gap_dtm_stop(tBTA_DM_MSG *p_data)
58225845
}
58235846
#endif // #if ((BLE_42_DTM_TEST_EN == TRUE) || (BLE_50_DTM_TEST_EN == TRUE))
58245847

5825-
void bta_dm_ble_gap_clear_adv(tBTA_DM_MSG *p_data)
5826-
{
5827-
if (BTM_BleClearAdv(p_data->ble_clear_adv.p_clear_adv_cback) == FALSE) {
5828-
if (p_data->ble_clear_adv.p_clear_adv_cback) {
5829-
(*p_data->ble_clear_adv.p_clear_adv_cback)(BTA_FAILURE);
5830-
}
5831-
}
5832-
}
5833-
58345848
void bta_dm_ble_gap_set_rpa_timeout(tBTA_DM_MSG *p_data)
58355849
{
58365850
APPL_TRACE_API("%s, rpa_timeout = %d", __func__, p_data->set_rpa_timeout.rpa_timeout);
@@ -5853,18 +5867,6 @@ void bta_dm_ble_gap_set_privacy_mode(tBTA_DM_MSG *p_data)
58535867
p_data->ble_set_privacy_mode.privacy_mode, p_data->ble_set_privacy_mode.p_cback);
58545868
}
58555869

5856-
void bta_dm_ble_gap_set_csa_support(tBTA_DM_MSG *p_data)
5857-
{
5858-
APPL_TRACE_API("%s, csa_select = %d", __func__, p_data->ble_set_csa_support.csa_select);
5859-
BTM_BleSetCsaSupport(p_data->ble_set_csa_support.csa_select, p_data->ble_set_csa_support.p_cback);
5860-
}
5861-
5862-
void bta_dm_ble_gap_set_vendor_evt_mask(tBTA_DM_MSG *p_data)
5863-
{
5864-
APPL_TRACE_API("%s, evt_mask = %d", __func__, p_data->ble_set_vendor_evt_mask.evt_mask);
5865-
BTM_BleSetVendorEventMask(p_data->ble_set_vendor_evt_mask.evt_mask, p_data->ble_set_vendor_evt_mask.p_cback);
5866-
}
5867-
58685870
void bta_dm_read_ble_channel_map(tBTA_DM_MSG *p_data)
58695871
{
58705872
if (p_data && p_data->ch_map.read_ch_map_cb) {

0 commit comments

Comments
 (0)