feat(ble/bluedroid): support adv monitor feature

(cherry picked from commit 1566a50929)

Co-authored-by: zhiweijian <zhiweijian@espressif.com>
This commit is contained in:
Zhi Wei Jian
2026-03-26 17:23:44 +08:00
parent befa3a2c2f
commit f6e48dd5d7
19 changed files with 800 additions and 2 deletions
@@ -1344,6 +1344,125 @@ void btm_ble_ext_adv_report_evt(tBTM_BLE_EXT_ADV_REPORT *params)
}
#endif // #if (BLE_50_EXTEND_SCAN_EN == TRUE)
#if (BLE_FEAT_ADV_MONITOR == TRUE)
void btm_ble_monitor_adv_report_evt(tBTM_BLE_MONITOR_ADV_REPORT *params)
{
tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0};
if (!params) {
BTM_TRACE_ERROR("%s, Invalid params.", __func__);
return;
}
memcpy(&cb_params.monitor_adv_report, params, sizeof(tBTM_BLE_MONITOR_ADV_REPORT));
BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_MONITOR_ADV_REPORT_EVT, &cb_params);
}
void btm_ble_read_monitor_adv_list_size_complete(UINT8 *p)
{
tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0};
UINT8 status;
if (!p) {
BTM_TRACE_ERROR("%s, Invalid params.", __func__);
return;
}
STREAM_TO_UINT8(status, p);
cb_params.monitor_adv_list_size.status = (status == HCI_SUCCESS) ? BTM_SUCCESS : (BTM_HCI_ERROR | status);
if (status == HCI_SUCCESS) {
STREAM_TO_UINT8(cb_params.monitor_adv_list_size.list_size, p);
}
BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_READ_MONITOR_ADV_LIST_SIZE_COMPLETE_EVT, &cb_params);
}
tBTM_STATUS BTM_BleAddMonitorAdvList(UINT8 addr_type, BD_ADDR addr, INT8 rssi_low, INT8 rssi_high, UINT8 timeout)
{
tHCI_STATUS err = HCI_SUCCESS;
tBTM_STATUS status = BTM_SUCCESS;
tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0};
if (addr_type > BLE_ADDR_TYPE_MAX) {
status = BTM_ILLEGAL_VALUE;
BTM_TRACE_ERROR("%s invalid addr_type %d", __func__, addr_type);
goto end;
}
if ((err = btsnd_hcic_ble_add_monitor_adv_list(addr_type, addr, rssi_low, rssi_high, timeout)) != HCI_SUCCESS) {
BTM_TRACE_ERROR("LE AddMonitorAdvList: cmd err=0x%x", err);
status = BTM_HCI_ERROR | err;
}
end:
cb_params.status = status;
BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_ADD_MONITOR_ADV_COMPLETE_EVT, &cb_params);
return status;
}
tBTM_STATUS BTM_BleRemoveMonitorAdvList(UINT8 addr_type, BD_ADDR addr)
{
tHCI_STATUS err = HCI_SUCCESS;
tBTM_STATUS status = BTM_SUCCESS;
tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0};
if (addr_type > BLE_ADDR_TYPE_MAX) {
status = BTM_ILLEGAL_VALUE;
BTM_TRACE_ERROR("%s invalid addr_type %d", __func__, addr_type);
goto end;
}
if ((err = btsnd_hcic_ble_rmv_monitor_adv_list(addr_type, addr)) != HCI_SUCCESS) {
BTM_TRACE_ERROR("LE RmvMonitorAdvList: cmd err=0x%x", err);
status = BTM_HCI_ERROR | err;
}
end:
cb_params.status = status;
BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_REMOVE_MONITOR_ADV_COMPLETE_EVT, &cb_params);
return status;
}
tBTM_STATUS BTM_BleClearMonitorAdvList(void)
{
tHCI_STATUS err = HCI_SUCCESS;
tBTM_STATUS status = BTM_SUCCESS;
tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0};
if ((err = btsnd_hcic_ble_clear_monitor_adv_list()) != HCI_SUCCESS) {
BTM_TRACE_ERROR("LE ClearMonitorAdvList: cmd err=0x%x", err);
status = BTM_HCI_ERROR | err;
}
cb_params.status = status;
BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_CLEAR_MONITOR_ADV_COMPLETE_EVT, &cb_params);
return status;
}
tBTM_STATUS BTM_BleReadMonitorAdvListSize(void)
{
if (!btsnd_hcic_ble_read_monitor_adv_list_size()) {
return BTM_NO_RESOURCES;
}
return BTM_CMD_STARTED;
}
tBTM_STATUS BTM_BleEnableMonitorAdv(UINT8 enable)
{
tHCI_STATUS err = HCI_SUCCESS;
tBTM_STATUS status = BTM_SUCCESS;
tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0};
if ((err = btsnd_hcic_ble_enable_monitor_adv(enable)) != HCI_SUCCESS) {
BTM_TRACE_ERROR("LE EnableMonitorAdv: cmd err=0x%x", err);
status = BTM_HCI_ERROR | err;
}
cb_params.status = status;
BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_ENABLE_MONITOR_ADV_COMPLETE_EVT, &cb_params);
return status;
}
#endif // #if (BLE_FEAT_ADV_MONITOR == TRUE)
#if (BLE_50_EXTEND_ADV_EN == TRUE)
void btm_ble_scan_req_received_evt(tBTM_BLE_SCAN_REQ_RECEIVED *params)
{
@@ -554,6 +554,10 @@ void btm_ble_periodic_adv_sync_establish_evt(tBTM_BLE_PERIOD_ADV_SYNC_ESTAB *par
void btm_ble_periodic_adv_list_init(UINT8 periodic_adv_size);
#endif //#if (BLE_50_EXTEND_SYNC_EN == TRUE)
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_ADV_MONITOR == TRUE)
void btm_ble_monitor_adv_report_evt(tBTM_BLE_MONITOR_ADV_REPORT *params);
void btm_ble_read_monitor_adv_list_size_complete(UINT8 *p);
#endif // #if (BLE_FEAT_ADV_MONITOR == TRUE)
#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
void btm_ble_periodic_adv_sync_trans_recv_evt(tBTM_BLE_PERIOD_ADV_SYNC_TRANS_RECV *params);
@@ -171,6 +171,9 @@ static void btu_ble_phy_update_complete_evt(UINT8 *p);
#if (BLE_50_EXTEND_SCAN_EN == TRUE)
static void btu_ble_ext_adv_report_evt(UINT8 *p, UINT16 evt_len);
#endif // #if (BLE_50_EXTEND_SCAN_EN == TRUE)
#if (BLE_FEAT_ADV_MONITOR == TRUE)
static void btu_ble_monitor_adv_report_evt(UINT8 *p);
#endif // #if (BLE_FEAT_ADV_MONITOR == TRUE)
#if (BLE_50_EXTEND_SYNC_EN == TRUE)
static void btu_ble_periodic_adv_sync_establish_evt(UINT8 *p, bool v2_evt);
static void btu_ble_periodic_adv_report_evt(UINT8 *p, UINT8 evt_len, bool v2_evt);
@@ -551,6 +554,11 @@ void btu_hcif_process_event (UNUSED_ATTR UINT8 controller_id, BT_HDR *p_msg)
btu_ble_channel_select_alg_evt(p);
break;
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_ADV_MONITOR == TRUE)
case HCI_BLE_MONITOR_ADV_REPORT_EVT:
btu_ble_monitor_adv_report_evt(p);
break;
#endif // #if (BLE_FEAT_ADV_MONITOR == TRUE)
#if (BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER == TRUE)
case HCI_BLE_PERIOD_ADV_SYNC_TRANS_RECV_EVT:
btu_ble_periodic_adv_sync_trans_recv(p);
@@ -1464,6 +1472,11 @@ static void btu_hcif_hdl_command_complete (UINT16 opcode, UINT8 *p, UINT16 evt_l
btm_ble_cs_read_local_supp_caps_cmpl_evt(p);
break;
#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE)
#if (BLE_FEAT_ADV_MONITOR == TRUE)
case HCI_BLE_READ_MONITOR_ADV_LIST_SIZE:
btm_ble_read_monitor_adv_list_size_complete(p);
break;
#endif // #if (BLE_FEAT_ADV_MONITOR == TRUE)
#endif /* (BLE_INCLUDED == TRUE) */
default: {
@@ -2633,6 +2646,23 @@ static void btu_ble_ext_adv_report_evt(UINT8 *p, UINT16 evt_len)
}
#endif // #if (BLE_50_EXTEND_SCAN_EN == TRUE)
#if (BLE_FEAT_ADV_MONITOR == TRUE)
static void btu_ble_monitor_adv_report_evt(UINT8 *p)
{
tBTM_BLE_MONITOR_ADV_REPORT report = {0};
if (!p) {
HCI_TRACE_ERROR("%s, Invalid params.", __func__);
return;
}
/* HCI LE Monitor Adv Report: Addr_Type(1) + Address(6) + Condition(1) */
STREAM_TO_UINT8(report.addr_type, p);
STREAM_TO_BDADDR(report.address, p);
STREAM_TO_UINT8(report.condition, p);
btm_ble_monitor_adv_report_evt(&report);
}
#endif // #if (BLE_FEAT_ADV_MONITOR == TRUE)
#if (BLE_50_EXTEND_SYNC_EN == TRUE)
static void btu_ble_periodic_adv_sync_establish_evt(UINT8 *p, bool v2_evt)
{
@@ -2969,6 +2969,87 @@ UINT8 btsnd_hcic_ble_set_host_feature(uint16_t bit_num, uint8_t bit_val)
}
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_ADV_MONITOR == TRUE)
UINT8 btsnd_hcic_ble_add_monitor_adv_list(UINT8 addr_type, BD_ADDR addr, INT8 rssi_low, INT8 rssi_high, UINT8 timeout)
{
BT_HDR *p;
UINT8 *pp;
HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_ADD_MONITOR_ADV_LIST);
UINT16_TO_STREAM(pp, HCI_BLE_ADD_MONITOR_ADV_LIST);
UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ADD_MONITOR_ADV_LIST);
UINT8_TO_STREAM(pp, addr_type);
BDADDR_TO_STREAM(pp, addr);
UINT8_TO_STREAM(pp, (UINT8)rssi_low);
UINT8_TO_STREAM(pp, (UINT8)rssi_high);
UINT8_TO_STREAM(pp, timeout);
return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
}
UINT8 btsnd_hcic_ble_rmv_monitor_adv_list(UINT8 addr_type, BD_ADDR addr)
{
BT_HDR *p;
UINT8 *pp;
HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_RMV_MONITOR_ADV_LIST);
UINT16_TO_STREAM(pp, HCI_BLE_RMV_MONITOR_ADV_LIST);
UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_RMV_MONITOR_ADV_LIST);
UINT8_TO_STREAM(pp, addr_type);
BDADDR_TO_STREAM(pp, addr);
return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
}
UINT8 btsnd_hcic_ble_clear_monitor_adv_list(void)
{
BT_HDR *p;
UINT8 *pp;
HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_CLEAR_MONITOR_ADV_LIST);
UINT16_TO_STREAM(pp, HCI_BLE_CLEAR_MONITOR_ADV_LIST);
UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CLEAR_MONITOR_ADV_LIST);
return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
}
BOOLEAN btsnd_hcic_ble_read_monitor_adv_list_size(void)
{
BT_HDR *p;
UINT8 *pp;
if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_MONITOR_ADV_LIST_SIZE)) == NULL) {
return FALSE;
}
pp = (UINT8 *)(p + 1);
p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_MONITOR_ADV_LIST_SIZE;
p->offset = 0;
UINT16_TO_STREAM(pp, HCI_BLE_READ_MONITOR_ADV_LIST_SIZE);
UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_MONITOR_ADV_LIST_SIZE);
btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
return TRUE;
}
UINT8 btsnd_hcic_ble_enable_monitor_adv(UINT8 enable)
{
BT_HDR *p;
UINT8 *pp;
HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_ENABLE_MONITOR_ADV);
UINT16_TO_STREAM(pp, HCI_BLE_ENABLE_MONITOR_ADV);
UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ENABLE_MONITOR_ADV);
UINT8_TO_STREAM(pp, enable);
return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p);
}
#endif // #if (BLE_FEAT_ADV_MONITOR == TRUE)
#if (BT_BLE_FEAT_PAWR_EN == TRUE)
UINT8 btsnd_hcic_ble_set_periodic_adv_subevt_data(UINT8 adv_handle, UINT8 num_subevents_with_data, ble_subevent_params *subevent_params)
{
@@ -974,7 +974,15 @@ typedef void (tBTM_SET_VENDOR_EVT_MASK_CBACK) (tBTM_STATUS status);
#define BTM_BLE_GAP_CS_SUBEVENT_RESULT_EVT 68
#define BTM_BLE_GAP_CS_SUBEVENT_RESULT_CONTINUE_EVT 69
#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE)
#define BTM_BLE_5_GAP_UNKNOWN_EVT 70
#if (BLE_FEAT_ADV_MONITOR == TRUE)
#define BTM_BLE_5_GAP_MONITOR_ADV_REPORT_EVT 70
#define BTM_BLE_5_GAP_ADD_MONITOR_ADV_COMPLETE_EVT 71
#define BTM_BLE_5_GAP_REMOVE_MONITOR_ADV_COMPLETE_EVT 72
#define BTM_BLE_5_GAP_CLEAR_MONITOR_ADV_COMPLETE_EVT 73
#define BTM_BLE_5_GAP_READ_MONITOR_ADV_LIST_SIZE_COMPLETE_EVT 74
#define BTM_BLE_5_GAP_ENABLE_MONITOR_ADV_COMPLETE_EVT 75
#endif // #if (BLE_FEAT_ADV_MONITOR == TRUE)
#define BTM_BLE_5_GAP_UNKNOWN_EVT 76
typedef UINT8 tBTM_BLE_5_GAP_EVENT;
#if (BLE_FEAT_ISO_EN == TRUE)
@@ -1211,6 +1219,19 @@ typedef struct {
UINT8 channel_sel_alg;
} tBTM_BLE_CHANNEL_SEL_ALG;
#if (BLE_FEAT_ADV_MONITOR == TRUE)
typedef struct {
UINT8 addr_type;
BD_ADDR address;
UINT8 condition;
} tBTM_BLE_MONITOR_ADV_REPORT;
typedef struct {
tBTM_STATUS status;
UINT8 list_size;
} tBTM_BLE_MONITOR_ADV_LIST_SIZE;
#endif // #if (BLE_FEAT_ADV_MONITOR == TRUE)
typedef struct {
UINT16 sync_handle;
UINT8 tx_power;
@@ -1917,6 +1938,10 @@ typedef union {
tBTM_BLE_CS_SUBEVT_RESULT_CMPL_EVT cs_subevt_result;
tBTM_BLE_CS_SUBEVT_RESULT_CONTINUE_EVT cs_subevt_result_continue;
#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE)
#if (BLE_FEAT_ADV_MONITOR == TRUE)
tBTM_BLE_MONITOR_ADV_REPORT monitor_adv_report;
tBTM_BLE_MONITOR_ADV_LIST_SIZE monitor_adv_list_size;
#endif // #if (BLE_FEAT_ADV_MONITOR == TRUE)
} tBTM_BLE_5_GAP_CB_PARAMS;
typedef struct {
@@ -3087,6 +3112,14 @@ tBTM_STATUS BTM_BleSetExtendedScanParams(tBTM_BLE_EXT_SCAN_PARAMS *params);
tBTM_STATUS BTM_BleExtendedScan(BOOLEAN enable, UINT16 duration, UINT16 period);
void BTM_BleSetPreferExtenedConnParams(BD_ADDR bd_addr, tBTM_EXT_CONN_PARAMS *params);
#if (BLE_FEAT_ADV_MONITOR == TRUE)
tBTM_STATUS BTM_BleAddMonitorAdvList(UINT8 addr_type, BD_ADDR addr, INT8 rssi_low, INT8 rssi_high, UINT8 timeout);
tBTM_STATUS BTM_BleRemoveMonitorAdvList(UINT8 addr_type, BD_ADDR addr);
tBTM_STATUS BTM_BleClearMonitorAdvList(void);
tBTM_STATUS BTM_BleReadMonitorAdvListSize(void);
tBTM_STATUS BTM_BleEnableMonitorAdv(UINT8 enable);
#endif // #if (BLE_FEAT_ADV_MONITOR == TRUE)
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_50_DTM_TEST_EN == TRUE)
@@ -430,6 +430,15 @@
#define HCI_BLE_ISO_READ_ISO_LINK_QUALITY (0x0075 | HCI_GRP_BLE_CMDS)
#define HCI_BLE_SET_HOST_FEATURE_V2 (0x0097 | HCI_GRP_BLE_CMDS)
#if (BLE_FEAT_ADV_MONITOR == TRUE)
/* LE Monitor Advertisement (Bluetooth Core 6.0) */
#define HCI_BLE_ADD_MONITOR_ADV_LIST (0x0098 | HCI_GRP_BLE_CMDS)
#define HCI_BLE_RMV_MONITOR_ADV_LIST (0x0099 | HCI_GRP_BLE_CMDS)
#define HCI_BLE_CLEAR_MONITOR_ADV_LIST (0x009A | HCI_GRP_BLE_CMDS)
#define HCI_BLE_READ_MONITOR_ADV_LIST_SIZE (0x009B | HCI_GRP_BLE_CMDS)
#define HCI_BLE_ENABLE_MONITOR_ADV (0x009C | HCI_GRP_BLE_CMDS)
#endif // #if (BLE_FEAT_ADV_MONITOR == TRUE)
#if (BLE_FEAT_POWER_CONTROL_EN == TRUE)
#define HCI_BLE_ENH_READ_TRANS_POWER_LEVEL (0x0076 | HCI_GRP_BLE_CMDS)
#define HCI_BLE_READ_REMOTE_TRANS_POWER_LEVEL (0x0077 | HCI_GRP_BLE_CMDS)
@@ -961,6 +970,10 @@
#define HCI_BLE_PA_RESPONSE_REPORT_EVT 0x28
#endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE)
#if (BLE_FEAT_ADV_MONITOR == TRUE)
#define HCI_BLE_MONITOR_ADV_REPORT_EVT 0x34
#endif // #if (BLE_FEAT_ADV_MONITOR == TRUE)
#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE)
#define HCI_BLE_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT 0x2C
#define HCI_BLE_CS_READ_REMOTE_FAE_TAB_CMPL_EVT 0x2D
@@ -809,6 +809,20 @@ uint8_t btsnd_hcic_ble_get_status(void);
void btsnd_hci_ble_set_status(UINT8 hci_status);
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
#if (BLE_FEAT_ADV_MONITOR == TRUE)
#define HCIC_PARAM_SIZE_ADD_MONITOR_ADV_LIST 10
#define HCIC_PARAM_SIZE_RMV_MONITOR_ADV_LIST 7
#define HCIC_PARAM_SIZE_CLEAR_MONITOR_ADV_LIST 0
#define HCIC_PARAM_SIZE_READ_MONITOR_ADV_LIST_SIZE 0
#define HCIC_PARAM_SIZE_ENABLE_MONITOR_ADV 1
UINT8 btsnd_hcic_ble_add_monitor_adv_list(UINT8 addr_type, BD_ADDR addr, INT8 rssi_low, INT8 rssi_high, UINT8 timeout);
UINT8 btsnd_hcic_ble_rmv_monitor_adv_list(UINT8 addr_type, BD_ADDR addr);
UINT8 btsnd_hcic_ble_clear_monitor_adv_list(void);
BOOLEAN btsnd_hcic_ble_read_monitor_adv_list_size(void);
UINT8 btsnd_hcic_ble_enable_monitor_adv(UINT8 enable);
#endif // #if (BLE_FEAT_ADV_MONITOR == TRUE)
/* ULP HCI command */
BOOLEAN btsnd_hcic_ble_set_evt_mask (BT_EVENT_MASK event_mask);