From 702292d451dfe403625f1aeee9198a59bcb55181 Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Tue, 18 Nov 2025 19:30:50 +0800 Subject: [PATCH] fix(ble/bluedroid): Delete BLE_ANDROID_CONTROLLER_SCAN_FILTER --- .../bt/host/bluedroid/bta/dm/bta_dm_act.c | 136 -- .../bt/host/bluedroid/bta/dm/bta_dm_api.c | 220 --- .../bt/host/bluedroid/bta/dm/bta_dm_main.c | 5 - .../bluedroid/bta/dm/include/bta_dm_int.h | 44 - .../host/bluedroid/bta/include/bta/bta_api.h | 148 -- .../common/include/common/bt_target.h | 4 - .../bluedroid/stack/btm/btm_ble_adv_filter.c | 1281 ----------------- .../bt/host/bluedroid/stack/btm/btm_ble_gap.c | 4 +- 8 files changed, 1 insertion(+), 1841 deletions(-) diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c index 55f44c0a1c..348da66043 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c @@ -6353,142 +6353,6 @@ void bta_ble_scan_setup_cb(tBTM_BLE_BATCH_SCAN_EVT evt, tBTM_BLE_REF_VALUE ref_v } } - -#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE -/******************************************************************************* -** -** Function bta_ble_scan_pf_cmpl -** -** Description ADV payload filtering operation complete callback -** -** -** Returns TRUE if handled, otherwise FALSE. -** -*******************************************************************************/ -static void bta_ble_scan_cfg_cmpl(tBTM_BLE_PF_ACTION action, tBTM_BLE_SCAN_COND_OP cfg_op, - tBTM_BLE_PF_AVBL_SPACE avbl_space, tBTM_STATUS status, - tBTM_BLE_REF_VALUE ref_value) -{ - tBTA_STATUS st = (status == BTM_SUCCESS) ? BTA_SUCCESS : BTA_FAILURE; - - APPL_TRACE_DEBUG("bta_ble_scan_cfg_cmpl: %d, %d, %d, %d", action, cfg_op, avbl_space, status); - - if (bta_dm_cb.p_scan_filt_cfg_cback) { - bta_dm_cb.p_scan_filt_cfg_cback(action, cfg_op, avbl_space, st, ref_value); - } -} - -/******************************************************************************* -** -** Function bta_dm_cfg_filter_cond -** -** Description This function configure adv payload filtering condition -** -** Parameters: -** -*******************************************************************************/ -void bta_dm_cfg_filter_cond (tBTA_DM_MSG *p_data) -{ - tBTM_STATUS st = BTM_MODE_UNSUPPORTED; - tBTA_STATUS status = BTA_FAILURE; - - tBTM_BLE_VSC_CB cmn_vsc_cb; - - APPL_TRACE_DEBUG("bta_dm_cfg_filter_cond"); - BTM_BleGetVendorCapabilities(&cmn_vsc_cb); - if (0 != cmn_vsc_cb.filter_support) { - if ((st = BTM_BleCfgFilterCondition(p_data->ble_cfg_filter_cond.action, - p_data->ble_cfg_filter_cond.cond_type, - (tBTM_BLE_PF_FILT_INDEX)p_data->ble_cfg_filter_cond.filt_index, - (tBTM_BLE_PF_COND_PARAM *)p_data->ble_cfg_filter_cond.p_cond_param, - bta_ble_scan_cfg_cmpl, p_data->ble_cfg_filter_cond.ref_value)) - == BTM_CMD_STARTED) { - bta_dm_cb.p_scan_filt_cfg_cback = p_data->ble_cfg_filter_cond.p_filt_cfg_cback; - return; - } - } - - if (p_data->ble_cfg_filter_cond.p_filt_cfg_cback) { - p_data->ble_cfg_filter_cond.p_filt_cfg_cback(BTA_DM_BLE_PF_CONFIG_EVT, - p_data->ble_cfg_filter_cond.cond_type, 0, status, - p_data->ble_cfg_filter_cond.ref_value); - } - return; -} - -/******************************************************************************* -** -** Function bta_dm_enable_scan_filter -** -** Description This function enable/disable adv payload filtering condition -** -** Parameters: -** -*******************************************************************************/ -void bta_dm_enable_scan_filter(tBTA_DM_MSG *p_data) -{ - tBTM_STATUS st = BTM_MODE_UNSUPPORTED; - tBTA_STATUS status = BTA_FAILURE; - - tBTM_BLE_VSC_CB cmn_vsc_cb; - APPL_TRACE_DEBUG("bta_dm_enable_scan_filter"); - BTM_BleGetVendorCapabilities(&cmn_vsc_cb); - - if (0 != cmn_vsc_cb.filter_support) { - if ((st = BTM_BleEnableDisableFilterFeature(p_data->ble_enable_scan_filt.action, - p_data->ble_enable_scan_filt.p_filt_status_cback, - (tBTM_BLE_REF_VALUE)p_data->ble_enable_scan_filt.ref_value)) == BTM_CMD_STARTED) { - bta_dm_cb.p_scan_filt_status_cback = p_data->ble_enable_scan_filt.p_filt_status_cback; - } - return; - } - - if (p_data->ble_enable_scan_filt.p_filt_status_cback) { - p_data->ble_enable_scan_filt.p_filt_status_cback (BTA_DM_BLE_PF_ENABLE_EVT, - p_data->ble_enable_scan_filt.ref_value, status); - } - -} - -/******************************************************************************* -** -** Function bta_dm_scan_filter_param_setup -** -** Description This function sets up scan filter params -** -** Parameters: -** -*******************************************************************************/ -void bta_dm_scan_filter_param_setup (tBTA_DM_MSG *p_data) -{ - tBTM_STATUS st = BTM_MODE_UNSUPPORTED; - tBTA_STATUS status = BTA_FAILURE; - - tBTM_BLE_VSC_CB cmn_vsc_cb; - - APPL_TRACE_DEBUG("bta_dm_scan_filter_param_setup"); - BTM_BleGetVendorCapabilities(&cmn_vsc_cb); - if (0 != cmn_vsc_cb.filter_support) { - if ((st = BTM_BleAdvFilterParamSetup(p_data->ble_scan_filt_param_setup.action, - p_data->ble_scan_filt_param_setup.filt_index, - (tBTM_BLE_PF_FILT_PARAMS *)&p_data->ble_scan_filt_param_setup.filt_params, - p_data->ble_scan_filt_param_setup.p_target, - p_data->ble_scan_filt_param_setup.p_filt_param_cback, - p_data->ble_scan_filt_param_setup.ref_value)) == BTM_CMD_STARTED) { - bta_dm_cb.p_scan_filt_param_cback = p_data->ble_scan_filt_param_setup.p_filt_param_cback; - return; - } - } - - if (p_data->ble_scan_filt_param_setup.p_filt_param_cback) { - p_data->ble_scan_filt_param_setup.p_filt_param_cback (BTA_DM_BLE_PF_ENABLE_EVT, 0, - p_data->ble_scan_filt_param_setup.ref_value, status); - } - - return; -} -#endif - #if (BLE_HOST_ENERGY_INFO_EN == TRUE) /******************************************************************************* ** diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c index beba7cacfa..20f1ad773d 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c @@ -2078,187 +2078,6 @@ void BTA_DmBleSetKeyMaterial(const uint8_t *session_key, const uint8_t *iv) } #endif -/******************************************************************************* -** -** Function BTA_DmBleCfgFilterCondition -** -** Description This function is called to configure the adv data payload filter -** condition. -** -** Parameters action: to read/write/clear -** cond_type: filter condition type -** filt_index - Filter index -** p_cond: filter condition parameter -** p_cmpl_back - Command completed callback -** ref_value - Reference value -** -** Returns void -** -*******************************************************************************/ -void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action, - tBTA_DM_BLE_PF_COND_TYPE cond_type, - tBTA_DM_BLE_PF_FILT_INDEX filt_index, - tBTA_DM_BLE_PF_COND_PARAM *p_cond, - tBTA_DM_BLE_PF_CFG_CBACK *p_cmpl_cback, - tBTA_DM_BLE_REF_VALUE ref_value) -{ -#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE - tBTA_DM_API_CFG_FILTER_COND *p_msg; - APPL_TRACE_API ("BTA_DmBleCfgFilterCondition: %d, %d", action, cond_type); - - UINT16 len = sizeof(tBTA_DM_API_CFG_FILTER_COND) + - sizeof(tBTA_DM_BLE_PF_COND_PARAM); - UINT8 *p; - - if (NULL != p_cond) { - switch (cond_type) { - case BTA_DM_BLE_PF_SRVC_DATA_PATTERN: - case BTA_DM_BLE_PF_MANU_DATA: - /* Length of pattern and pattern mask and other elements in */ - /* tBTA_DM_BLE_PF_MANU_COND */ - len += ((p_cond->manu_data.data_len) * 2) + - sizeof(UINT16) + sizeof(UINT16) + sizeof(UINT8); - break; - - case BTA_DM_BLE_PF_LOCAL_NAME: - len += ((p_cond->local_name.data_len) + sizeof(UINT8)); - break; - - case BTM_BLE_PF_SRVC_UUID: - case BTM_BLE_PF_SRVC_SOL_UUID: - len += sizeof(tBLE_BD_ADDR) + sizeof(tBTA_DM_BLE_PF_COND_MASK); - break; - - default: - break; - } - } - - if ((p_msg = (tBTA_DM_API_CFG_FILTER_COND *) osi_malloc(len)) != NULL) { - memset (p_msg, 0, len); - - p_msg->hdr.event = BTA_DM_API_CFG_FILTER_COND_EVT; - p_msg->action = action; - p_msg->cond_type = cond_type; - p_msg->filt_index = filt_index; - p_msg->p_filt_cfg_cback = p_cmpl_cback; - p_msg->ref_value = ref_value; - if (p_cond) { - p_msg->p_cond_param = (tBTA_DM_BLE_PF_COND_PARAM *)(p_msg + 1); - memcpy(p_msg->p_cond_param, p_cond, sizeof(tBTA_DM_BLE_PF_COND_PARAM)); - - p = (UINT8 *)(p_msg->p_cond_param + 1); - - if (cond_type == BTA_DM_BLE_PF_SRVC_DATA_PATTERN || - cond_type == BTA_DM_BLE_PF_MANU_DATA) { - p_msg->p_cond_param->manu_data.p_pattern = p; - p_msg->p_cond_param->manu_data.data_len = p_cond->manu_data.data_len; - memcpy(p_msg->p_cond_param->manu_data.p_pattern, p_cond->manu_data.p_pattern, - p_cond->manu_data.data_len); - p += p_cond->manu_data.data_len; - - if (cond_type == BTA_DM_BLE_PF_MANU_DATA) { - p_msg->p_cond_param->manu_data.company_id_mask = - p_cond->manu_data.company_id_mask; - if ( p_cond->manu_data.p_pattern_mask != NULL) { - p_msg->p_cond_param->manu_data.p_pattern_mask = p; - memcpy(p_msg->p_cond_param->manu_data.p_pattern_mask, - p_cond->manu_data.p_pattern_mask, p_cond->manu_data.data_len); - } - } - } else if (cond_type == BTA_DM_BLE_PF_LOCAL_NAME) { - p_msg->p_cond_param->local_name.p_data = p; - p_msg->p_cond_param->local_name.data_len = - p_cond->local_name.data_len; - memcpy(p_msg->p_cond_param->local_name.p_data, - p_cond->local_name.p_data, p_cond->local_name.data_len); - } else if ((cond_type == BTM_BLE_PF_SRVC_UUID - || cond_type == BTM_BLE_PF_SRVC_SOL_UUID)) { - if (p_cond->srvc_uuid.p_target_addr != NULL) { - p_msg->p_cond_param->srvc_uuid.p_target_addr = (tBLE_BD_ADDR *)(p); - p_msg->p_cond_param->srvc_uuid.p_target_addr->type = - p_cond->srvc_uuid.p_target_addr->type; - memcpy(p_msg->p_cond_param->srvc_uuid.p_target_addr->bda, - p_cond->srvc_uuid.p_target_addr->bda, BD_ADDR_LEN); - p = (UINT8 *)( p_msg->p_cond_param->srvc_uuid.p_target_addr + 1); - } - if (p_cond->srvc_uuid.p_uuid_mask) { - p_msg->p_cond_param->srvc_uuid.p_uuid_mask = (tBTA_DM_BLE_PF_COND_MASK *)p; - memcpy(p_msg->p_cond_param->srvc_uuid.p_uuid_mask, - p_cond->srvc_uuid.p_uuid_mask, sizeof(tBTA_DM_BLE_PF_COND_MASK)); - } - } - } - - bta_sys_sendmsg(p_msg); - } -#else - UNUSED(action); - UNUSED(cond_type); - UNUSED(filt_index); - UNUSED(p_cond); - UNUSED(p_cmpl_cback); - UNUSED(ref_value); -#endif -} - -/******************************************************************************* -** -** Function BTA_DmBleScanFilterSetup -** -** Description This function is called to setup the adv data payload filter param -** -** Parameters p_target: enable the filter condition on a target device; if NULL -** filt_index - Filter index -** p_filt_params -Filter parameters -** ref_value - Reference value -** action - Add, delete or clear -** p_cmpl_back - Command completed callback -** -** Returns void -** -*******************************************************************************/ -void BTA_DmBleScanFilterSetup(UINT8 action, tBTA_DM_BLE_PF_FILT_INDEX filt_index, - tBTA_DM_BLE_PF_FILT_PARAMS *p_filt_params, - tBLE_BD_ADDR *p_target, - tBTA_DM_BLE_PF_PARAM_CBACK *p_cmpl_cback, - tBTA_DM_BLE_REF_VALUE ref_value) -{ -#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE - tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *p_msg; - APPL_TRACE_API ("BTA_DmBleScanFilterSetup: %d", action); - - UINT16 len = sizeof(tBTA_DM_API_SCAN_FILTER_PARAM_SETUP) + sizeof(tBLE_BD_ADDR); - - if ((p_msg = (tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *) osi_malloc(len)) != NULL) { - memset (p_msg, 0, len); - - p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_SETUP_EVT; - p_msg->action = action; - p_msg->filt_index = filt_index; - if (p_filt_params) { - memcpy(&p_msg->filt_params, p_filt_params, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS)); - } - p_msg->p_filt_param_cback = p_cmpl_cback; - p_msg->ref_value = ref_value; - - if (p_target) { - p_msg->p_target = (tBLE_BD_ADDR *)(p_msg + 1); - memcpy(p_msg->p_target, p_target, sizeof(tBLE_BD_ADDR)); - } - - bta_sys_sendmsg(p_msg); - } -#else - UNUSED(action); - UNUSED(filt_index); - UNUSED(p_filt_params); - UNUSED(p_target); - UNUSED(p_cmpl_cback); - UNUSED(ref_value); -#endif -} - #if (BLE_HOST_ENERGY_INFO_EN == TRUE) /******************************************************************************* ** @@ -2287,45 +2106,6 @@ void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK *p_cmpl_cback) } #endif // #if (BLE_HOST_ENERGY_INFO_EN == TRUE) -/******************************************************************************* -** -** Function BTA_DmEnableScanFilter -** -** Description This function is called to enable the adv data payload filter -** -** Parameters action - enable or disable the APCF feature -** p_cmpl_cback - Command completed callback -** ref_value - Reference value -** -** Returns void -** -*******************************************************************************/ -void BTA_DmEnableScanFilter(UINT8 action, tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cback, - tBTA_DM_BLE_REF_VALUE ref_value) -{ -#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE - tBTA_DM_API_ENABLE_SCAN_FILTER *p_msg; - APPL_TRACE_API ("BTA_DmEnableScanFilter: %d\n", action); - - UINT16 len = sizeof(tBTA_DM_API_ENABLE_SCAN_FILTER) + sizeof(tBLE_BD_ADDR); - - if ((p_msg = (tBTA_DM_API_ENABLE_SCAN_FILTER *) osi_malloc(len)) != NULL) { - memset (p_msg, 0, len); - - p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_ENABLE_EVT; - p_msg->action = action; - p_msg->ref_value = ref_value; - p_msg->p_filt_status_cback = p_cmpl_cback; - - bta_sys_sendmsg(p_msg); - } -#else - UNUSED(action); - UNUSED(p_cmpl_cback); - UNUSED(ref_value); -#endif -} - /******************************************************************************* ** ** Function BTA_DmBleUpdateConnectionParams diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_main.c b/components/bt/host/bluedroid/bta/dm/bta_dm_main.c index 6c268432f2..16485d606d 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_main.c @@ -178,11 +178,6 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = { bta_dm_ble_broadcast, /* BTA_DM_API_BLE_BROADCAST_EVT */ #endif // #if (BLE_42_ADV_EN == TRUE) bta_dm_ble_set_data_length, /* BTA_DM_API_SET_DATA_LENGTH_EVT */ -#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE - bta_dm_cfg_filter_cond, /* BTA_DM_API_CFG_FILTER_COND_EVT */ - bta_dm_scan_filter_param_setup, /* BTA_DM_API_SCAN_FILTER_SETUP_EVT */ - bta_dm_enable_scan_filter, /* BTA_DM_API_SCAN_FILTER_ENABLE_EVT */ -#endif #if (BLE_HOST_SETUP_STORAGE_EN == TRUE) bta_dm_ble_setup_storage, /* BTA_DM_API_BLE_SETUP_STORAGE_EVT */ #endif // #if (BLE_HOST_SETUP_STORAGE_EN == TRUE) diff --git a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h index d9ac819965..30659dcd39 100644 --- a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h +++ b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h @@ -162,11 +162,6 @@ enum { BTA_DM_API_BLE_BROADCAST_EVT, #endif // #if (BLE_42_ADV_EN == TRUE) BTA_DM_API_SET_DATA_LENGTH_EVT, -#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE - BTA_DM_API_CFG_FILTER_COND_EVT, - BTA_DM_API_SCAN_FILTER_SETUP_EVT, - BTA_DM_API_SCAN_FILTER_ENABLE_EVT, -#endif #if (BLE_HOST_SETUP_STORAGE_EN == TRUE) BTA_DM_API_BLE_SETUP_STORAGE_EVT, #endif // #if (BLE_HOST_SETUP_STORAGE_EN == TRUE) @@ -1278,35 +1273,6 @@ typedef struct { UINT16 timeout; } tBTA_DM_API_UPDATE_CONN_PARAM; -#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE -typedef struct { - BT_HDR hdr; - tBTA_DM_BLE_SCAN_COND_OP action; - tBTA_DM_BLE_PF_COND_TYPE cond_type; - tBTA_DM_BLE_PF_FILT_INDEX filt_index; - tBTA_DM_BLE_PF_COND_PARAM *p_cond_param; - tBTA_DM_BLE_PF_CFG_CBACK *p_filt_cfg_cback; - tBTA_DM_BLE_REF_VALUE ref_value; -} tBTA_DM_API_CFG_FILTER_COND; - -typedef struct { - BT_HDR hdr; - UINT8 action; - tBTA_DM_BLE_PF_STATUS_CBACK *p_filt_status_cback; - tBTA_DM_BLE_REF_VALUE ref_value; -} tBTA_DM_API_ENABLE_SCAN_FILTER; - -typedef struct { - BT_HDR hdr; - UINT8 action; - tBTA_DM_BLE_PF_FILT_INDEX filt_index; - tBTA_DM_BLE_PF_FILT_PARAMS filt_params; - tBLE_BD_ADDR *p_target; - tBTA_DM_BLE_PF_PARAM_CBACK *p_filt_param_cback; - tBTA_DM_BLE_REF_VALUE ref_value; -} tBTA_DM_API_SCAN_FILTER_PARAM_SETUP; -#endif - #if (BLE_50_DTM_TEST_EN == TRUE) typedef struct { BT_HDR hdr; @@ -1811,11 +1777,6 @@ typedef union { tBTA_DM_API_BLE_ADV_PARAMS_ALL ble_set_adv_params_all; tBTA_DM_API_SET_ADV_CONFIG ble_set_adv_data; tBTA_DM_API_SET_ADV_CONFIG_RAW ble_set_adv_data_raw; -#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE - tBTA_DM_API_SCAN_FILTER_PARAM_SETUP ble_scan_filt_param_setup; - tBTA_DM_API_CFG_FILTER_COND ble_cfg_filter_cond; - tBTA_DM_API_ENABLE_SCAN_FILTER ble_enable_scan_filt; -#endif tBTA_DM_API_UPDATE_CONN_PARAM ble_update_conn_params; tBTA_DM_API_BLE_SET_DATA_LENGTH ble_set_data_length; tBTA_DM_APT_SET_DEV_ADDR set_addr; @@ -2402,11 +2363,6 @@ extern void bta_dm_ble_update_duplicate_exceptional_list(tBTA_DM_MSG *p_data); #if SMP_INCLUDED == TRUE extern void bta_dm_co_security_param_init(void); #endif -#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE -extern void bta_dm_cfg_filter_cond (tBTA_DM_MSG *p_data); -extern void bta_dm_scan_filter_param_setup (tBTA_DM_MSG *p_data); -extern void bta_dm_enable_scan_filter(tBTA_DM_MSG *p_data); -#endif extern void btm_dm_ble_multi_adv_disable(tBTA_DM_MSG *p_data); extern void bta_dm_ble_multi_adv_data(tBTA_DM_MSG *p_data); extern void bta_dm_ble_multi_adv_upd_param(tBTA_DM_MSG *p_data); diff --git a/components/bt/host/bluedroid/bta/include/bta/bta_api.h b/components/bt/host/bluedroid/bta/include/bta/bta_api.h index 7594df6a31..3627a42205 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_api.h @@ -573,7 +573,6 @@ enum { BTA_DM_BLE_SCAN_COND_DELETE, BTA_DM_BLE_SCAN_COND_CLEAR = 2 }; -typedef UINT8 tBTA_DM_BLE_SCAN_COND_OP; /* ADV payload filtering vendor specific call event */ enum { @@ -581,18 +580,6 @@ enum { BTA_BLE_SCAN_PF_COND_EVT }; -/* filter selection bit index */ -#define BTA_DM_BLE_PF_ADDR_FILTER BTM_BLE_PF_ADDR_FILTER -#define BTA_DM_BLE_PF_SRVC_DATA BTM_BLE_PF_SRVC_DATA -#define BTA_DM_BLE_PF_SRVC_UUID BTM_BLE_PF_SRVC_UUID -#define BTA_DM_BLE_PF_SRVC_SOL_UUID BTM_BLE_PF_SRVC_SOL_UUID -#define BTA_DM_BLE_PF_LOCAL_NAME BTM_BLE_PF_LOCAL_NAME -#define BTA_DM_BLE_PF_MANU_DATA BTM_BLE_PF_MANU_DATA -#define BTA_DM_BLE_PF_SRVC_DATA_PATTERN BTM_BLE_PF_SRVC_DATA_PATTERN -#define BTA_DM_BLE_PF_TYPE_ALL BTM_BLE_PF_TYPE_ALL -#define BTA_DM_BLE_PF_TYPE_MAX BTM_BLE_PF_TYPE_MAX -typedef UINT8 tBTA_DM_BLE_PF_COND_TYPE; - typedef union { UINT16 uuid16_mask; UINT32 uuid32_mask; @@ -628,18 +615,6 @@ typedef struct { as data pattern, set to all 0xff, match exact data */ } tBTA_DM_BLE_PF_SRVC_PATTERN_COND; -typedef union { - tBLE_BD_ADDR target_addr; - tBTA_DM_BLE_PF_LOCAL_NAME_COND local_name; /* local name filtering */ - tBTA_DM_BLE_PF_MANU_COND manu_data; /* manufacturer data filtering */ - tBTA_DM_BLE_PF_UUID_COND srvc_uuid; /* service UUID filtering */ - tBTA_DM_BLE_PF_UUID_COND solicitate_uuid; /* solicited service UUID filtering */ - tBTA_DM_BLE_PF_SRVC_PATTERN_COND srvc_data; /* service data pattern */ -} tBTA_DM_BLE_PF_COND_PARAM; - -typedef UINT8 tBTA_DM_BLE_PF_FILT_INDEX; -typedef UINT8 tBTA_DM_BLE_PF_AVBL_SPACE; - typedef INT8 tBTA_DM_RSSI_VALUE; typedef UINT8 tBTA_DM_LINK_QUALITY_VALUE; @@ -1049,64 +1024,6 @@ typedef void (tBTA_DM_SEC_CBACK)(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data); typedef UINT32 tBTA_DM_BLE_REF_VALUE; -#define BTA_DM_BLE_PF_ENABLE_EVT BTM_BLE_PF_ENABLE -#define BTA_DM_BLE_PF_CONFIG_EVT BTM_BLE_PF_CONFIG -typedef UINT8 tBTA_DM_BLE_PF_EVT; - -#define BTA_DM_BLE_PF_ENABLE 1 -#define BTA_DM_BLE_PF_CONFIG 2 -typedef UINT8 tBTA_DM_BLE_PF_ACTION; - -/* Config callback */ -typedef void (tBTA_DM_BLE_PF_CFG_CBACK) (tBTA_DM_BLE_PF_ACTION action, - tBTA_DM_BLE_PF_COND_TYPE cfg_cond, - tBTA_DM_BLE_PF_AVBL_SPACE avbl_space, tBTA_STATUS status, - tBTA_DM_BLE_REF_VALUE ref_value); -/* Param callback */ -typedef void (tBTA_DM_BLE_PF_PARAM_CBACK) (UINT8 action_type, tBTA_DM_BLE_PF_AVBL_SPACE avbl_space, - tBTA_DM_BLE_REF_VALUE ref_value, tBTA_STATUS status); - -/* Status callback */ -typedef void (tBTA_DM_BLE_PF_STATUS_CBACK) (UINT8 action, tBTA_STATUS status, - tBTA_DM_BLE_REF_VALUE ref_value); - - -#define BTA_DM_BLE_PF_BRDCAST_ADDR_FILT 1 -#define BTA_DM_BLE_PF_SERV_DATA_CHG_FILT 2 -#define BTA_DM_BLE_PF_SERV_UUID 4 -#define BTA_DM_BLE_PF_SERV_SOLC_UUID 8 -#define BTA_DM_BLE_PF_LOC_NAME_CHECK 16 -#define BTA_DM_BLE_PF_MANUF_NAME_CHECK 32 -#define BTA_DM_BLE_PF_SERV_DATA_CHECK 64 -typedef UINT16 tBTA_DM_BLE_PF_FEAT_SEL; - -#define BTA_DM_BLE_PF_LIST_LOGIC_OR 1 -#define BTA_DM_BLE_PF_LIST_LOGIC_AND 2 -typedef UINT16 tBTA_DM_BLE_PF_LIST_LOGIC_TYPE; - -#define BTA_DM_BLE_PF_FILT_LOGIC_OR 0 -#define BTA_DM_BLE_PF_FILT_LOGIC_AND 1 -typedef UINT16 tBTA_DM_BLE_PF_FILT_LOGIC_TYPE; - -typedef UINT8 tBTA_DM_BLE_PF_RSSI_THRESHOLD; -typedef UINT8 tBTA_DM_BLE_PF_DELIVERY_MODE; -typedef UINT16 tBTA_DM_BLE_PF_TIMEOUT; -typedef UINT8 tBTA_DM_BLE_PF_TIMEOUT_CNT; -typedef UINT16 tBTA_DM_BLE_PF_ADV_TRACK_ENTRIES; - -typedef struct { - tBTA_DM_BLE_PF_FEAT_SEL feat_seln; - tBTA_DM_BLE_PF_LIST_LOGIC_TYPE list_logic_type; - tBTA_DM_BLE_PF_FILT_LOGIC_TYPE filt_logic_type; - tBTA_DM_BLE_PF_RSSI_THRESHOLD rssi_high_thres; - tBTA_DM_BLE_PF_RSSI_THRESHOLD rssi_low_thres; - tBTA_DM_BLE_PF_DELIVERY_MODE dely_mode; - tBTA_DM_BLE_PF_TIMEOUT found_timeout; - tBTA_DM_BLE_PF_TIMEOUT lost_timeout; - tBTA_DM_BLE_PF_TIMEOUT_CNT found_timeout_cnt; - tBTA_DM_BLE_PF_ADV_TRACK_ENTRIES num_of_tracking_entries; -} tBTA_DM_BLE_PF_FILT_PARAMS; - /* Search callback events */ #define BTA_DM_INQ_RES_EVT 0 /* Inquiry result for a peer device. */ #define BTA_DM_INQ_CMPL_EVT 1 /* Inquiry complete. */ @@ -3211,71 +3128,6 @@ extern void BTA_DmBleReadScanReports(tBTA_BLE_BATCH_SCAN_MODE scan_type, *******************************************************************************/ extern void BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value); -/******************************************************************************* -** -** Function BTA_DmEnableScanFilter -** -** Description This function is called to enable the adv data payload filter -** -** Parameters action - enable or disable the APCF feature -** p_cmpl_cback - Command completed callback -** ref_value - Reference value -** -** Returns void -** -*******************************************************************************/ -extern void BTA_DmEnableScanFilter(UINT8 action, - tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cback, - tBTA_DM_BLE_REF_VALUE ref_value); - -/******************************************************************************* -** -** Function BTA_DmBleScanFilterSetup -** -** Description This function is called to setup the filter params -** -** Parameters p_target: enable the filter condition on a target device; if NULL -** filt_index - Filter index -** p_filt_params -Filter parameters -** ref_value - Reference value -** action - Add, delete or clear -** p_cmpl_back - Command completed callback -** -** Returns void -** -*******************************************************************************/ -extern void BTA_DmBleScanFilterSetup(UINT8 action, - tBTA_DM_BLE_PF_FILT_INDEX filt_index, - tBTA_DM_BLE_PF_FILT_PARAMS *p_filt_params, - tBLE_BD_ADDR *p_target, - tBTA_DM_BLE_PF_PARAM_CBACK *p_cmpl_cback, - tBTA_DM_BLE_REF_VALUE ref_value); - -/******************************************************************************* -** -** Function BTA_DmBleCfgFilterCondition -** -** Description This function is called to configure the adv data payload filter -** condition. -** -** Parameters action: to read/write/clear -** cond_type: filter condition type -** filt_index - Filter index -** p_cond: filter condition parameter -** p_cmpl_back - Command completed callback -** ref_value - Reference value -** -** Returns void -** -*******************************************************************************/ -extern void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action, - tBTA_DM_BLE_PF_COND_TYPE cond_type, - tBTA_DM_BLE_PF_FILT_INDEX filt_index, - tBTA_DM_BLE_PF_COND_PARAM *p_cond, - tBTA_DM_BLE_PF_CFG_CBACK *p_cmpl_cback, - tBTA_DM_BLE_REF_VALUE ref_value); - - #if (BLE_HOST_ENERGY_INFO_EN == TRUE) /******************************************************************************* ** diff --git a/components/bt/host/bluedroid/common/include/common/bt_target.h b/components/bt/host/bluedroid/common/include/common/bt_target.h index ad636b7d67..3294ceeeab 100644 --- a/components/bt/host/bluedroid/common/include/common/bt_target.h +++ b/components/bt/host/bluedroid/common/include/common/bt_target.h @@ -1618,10 +1618,6 @@ #define BLE_INCLUDED FALSE #endif -#ifndef BLE_ANDROID_CONTROLLER_SCAN_FILTER -#define BLE_ANDROID_CONTROLLER_SCAN_FILTER FALSE -#endif - #ifndef BLE_HOST_ENERGY_INFO_EN #define BLE_HOST_ENERGY_INFO_EN FALSE #endif diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_adv_filter.c b/components/bt/host/bluedroid/stack/btm/btm_ble_adv_filter.c index 7eef55e912..8f00b9d690 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_adv_filter.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_adv_filter.c @@ -22,1286 +22,5 @@ #include "common/bt_target.h" #if (BLE_INCLUDED == TRUE) -#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE -#include "stack/bt_types.h" -#include "stack/hcimsgs.h" -#include "stack/btu.h" -#include "btm_int.h" -#include "osi/allocator.h" -#include "stack/hcidefs.h" -#include "stack/btm_ble_api.h" -#include "device/controller.h" -#define BTM_BLE_ADV_FILT_META_HDR_LENGTH 3 -#define BTM_BLE_ADV_FILT_FEAT_SELN_LEN 13 -#define BTM_BLE_ADV_FILT_TRACK_NUM 2 - -#define BTM_BLE_PF_SELECT_NONE 0 - -/* BLE meta vsc header: 1 bytes of sub_code, 1 byte of PCF action */ -#define BTM_BLE_META_HDR_LENGTH 3 -#define BTM_BLE_PF_FEAT_SEL_LEN 18 -#define BTM_BLE_PCF_ENABLE_LEN 2 - -#define BTM_BLE_META_ADDR_LEN 7 -#define BTM_BLE_META_UUID_LEN 40 - -#define BTM_BLE_PF_BIT_TO_MASK(x) (UINT16)(1 << (x)) - - -#if BTM_DYNAMIC_MEMORY == FALSE -tBTM_BLE_ADV_FILTER_CB btm_ble_adv_filt_cb; -tBTM_BLE_VSC_CB cmn_ble_adv_vsc_cb; -#else -tBTM_BLE_ADV_FILTER_CB *btm_ble_adv_filt_cb_ptr; -tBTM_BLE_VSC_CB *cmn_ble_adv_vsc_cb_ptr; -#define btm_ble_adv_filt_cb (*btm_ble_adv_filt_cb_ptr) -#define cmn_ble_adv_vsc_cb (*cmn_ble_adv_vsc_cb_ptr) -#endif - -static const BD_ADDR na_bda = {0}; - -static UINT8 btm_ble_cs_update_pf_counter(tBTM_BLE_SCAN_COND_OP action, - UINT8 cond_type, tBLE_BD_ADDR *p_bd_addr, UINT8 num_available); - -#define BTM_BLE_SET_SCAN_PF_OPCODE(x, y) (((x)<<4)|y) -#define BTM_BLE_GET_SCAN_PF_SUBCODE(x) ((x) >> 4) -#define BTM_BLE_GET_SCAN_PF_ACTION(x) ((x) & 0x0f) -#define BTM_BLE_INVALID_COUNTER 0xff - - -/* length of each multi adv sub command */ -#define BTM_BLE_ADV_FILTER_ENB_LEN 3 - -/* length of each batch scan command */ -#define BTM_BLE_ADV_FILTER_CLEAR_LEN 3 -#define BTM_BLE_ADV_FILTER_LEN 2 - -#define BTM_BLE_ADV_FILT_CB_EVT_MASK 0xF0 -#define BTM_BLE_ADV_FILT_SUBCODE_MASK 0x0F - -/******************************************************************************* -** -** Function btm_ble_obtain_vsc_details -** -** Description This function obtains the VSC details -** -** Parameters -** -** Returns status -** -*******************************************************************************/ -tBTM_STATUS btm_ble_obtain_vsc_details(void) -{ - tBTM_STATUS st = BTM_SUCCESS; - -#if BLE_VND_INCLUDED == TRUE - BTM_BleGetVendorCapabilities(&cmn_ble_adv_vsc_cb); - if (0 == cmn_ble_adv_vsc_cb.max_filter) { - st = BTM_MODE_UNSUPPORTED; - return st; - } -#else - cmn_ble_adv_vsc_cb.max_filter = BTM_BLE_MAX_FILTER_COUNTER; -#endif - return st; -} - -/******************************************************************************* -** -** Function btm_ble_advfilt_enq_op_q -** -** Description enqueue an adv filter operation in q to check command complete -** status -** -** Returns void -** -*******************************************************************************/ -void btm_ble_advfilt_enq_op_q(UINT8 action, UINT8 ocf, tBTM_BLE_FILT_CB_EVT cb_evt, - tBTM_BLE_REF_VALUE ref, tBTM_BLE_PF_CFG_CBACK *p_cmpl_cback, - tBTM_BLE_PF_PARAM_CBACK *p_filt_param_cback) -{ - btm_ble_adv_filt_cb.op_q.action_ocf[btm_ble_adv_filt_cb.op_q.next_idx] = (action | (ocf << 4)); - btm_ble_adv_filt_cb.op_q.ref_value[btm_ble_adv_filt_cb.op_q.next_idx] = ref; - btm_ble_adv_filt_cb.op_q.cb_evt[btm_ble_adv_filt_cb.op_q.next_idx] = cb_evt; - btm_ble_adv_filt_cb.op_q.p_scan_cfg_cback[btm_ble_adv_filt_cb.op_q.next_idx] = p_cmpl_cback; - btm_ble_adv_filt_cb.op_q.p_filt_param_cback[btm_ble_adv_filt_cb.op_q.next_idx] - = p_filt_param_cback; - BTM_TRACE_DEBUG("btm_ble_advfilt_enq_op_q: act_ocf:%d, action:%d, ocf:%d,cb_evt;%d, cback:%p", - btm_ble_adv_filt_cb.op_q.action_ocf[btm_ble_adv_filt_cb.op_q.next_idx], action, - ocf, cb_evt, p_cmpl_cback); - btm_ble_adv_filt_cb.op_q.next_idx = (btm_ble_adv_filt_cb.op_q.next_idx + 1) - % BTM_BLE_PF_TYPE_MAX; -} - -/******************************************************************************* -** -** Function btm_ble_advfilt_deq_op_q -** -** Description dequeue an adv filter operation from q when command complete -** is received -** -** Returns void -** -*******************************************************************************/ -void btm_ble_advfilt_deq_op_q(UINT8 *p_action, UINT8 *p_ocf, tBTM_BLE_FILT_CB_EVT *p_cb_evt, - tBTM_BLE_REF_VALUE *p_ref, tBTM_BLE_PF_CFG_CBACK **p_cmpl_cback, - tBTM_BLE_PF_PARAM_CBACK **p_filt_param_cback) -{ - *p_ocf = (btm_ble_adv_filt_cb.op_q.action_ocf[btm_ble_adv_filt_cb.op_q.pending_idx] >> 4); - *p_action = (btm_ble_adv_filt_cb.op_q.action_ocf[btm_ble_adv_filt_cb.op_q.pending_idx] - & BTM_BLE_ADV_FILT_SUBCODE_MASK); - *p_ref = btm_ble_adv_filt_cb.op_q.ref_value[btm_ble_adv_filt_cb.op_q.pending_idx]; - *p_cb_evt = btm_ble_adv_filt_cb.op_q.cb_evt[btm_ble_adv_filt_cb.op_q.pending_idx]; - *p_cmpl_cback = btm_ble_adv_filt_cb.op_q.p_scan_cfg_cback[btm_ble_adv_filt_cb.op_q.pending_idx]; - *p_filt_param_cback = - btm_ble_adv_filt_cb.op_q.p_filt_param_cback[btm_ble_adv_filt_cb.op_q.pending_idx]; - - btm_ble_adv_filt_cb.op_q.pending_idx = (btm_ble_adv_filt_cb.op_q.pending_idx + 1) - % BTM_BLE_PF_TYPE_MAX; - BTM_TRACE_DEBUG("btm_ble_advfilt_deq_op_q: ocf:%d, action:%d, ref_value:%d, cb_evt:%x", - *p_ocf, *p_action, *p_ref, *p_cb_evt); -} - -/******************************************************************************* -** -** Function btm_ble_condtype_to_ocf -** -** Description Convert cond_type to OCF -** -** Returns Returns ocf value -** -*******************************************************************************/ -UINT8 btm_ble_condtype_to_ocf(UINT8 cond_type) -{ - UINT8 ocf = 0; - - switch (cond_type) { - case BTM_BLE_PF_ADDR_FILTER: - ocf = BTM_BLE_META_PF_ADDR; - break; - case BTM_BLE_PF_SRVC_UUID: - ocf = BTM_BLE_META_PF_UUID; - break; - case BTM_BLE_PF_SRVC_SOL_UUID: - ocf = BTM_BLE_META_PF_SOL_UUID; - break; - case BTM_BLE_PF_LOCAL_NAME: - ocf = BTM_BLE_META_PF_LOCAL_NAME; - break; - case BTM_BLE_PF_MANU_DATA: - ocf = BTM_BLE_META_PF_MANU_DATA; - break; - case BTM_BLE_PF_SRVC_DATA_PATTERN: - ocf = BTM_BLE_META_PF_SRVC_DATA; - break; - case BTM_BLE_PF_TYPE_ALL: - ocf = BTM_BLE_META_PF_ALL; - break; - default: - ocf = BTM_BLE_PF_TYPE_MAX; - break; - } - return ocf; -} - -/******************************************************************************* -** -** Function btm_ble_ocf_to_condtype -** -** Description Convert OCF to cond type -** -** Returns Returns condtype value -** -*******************************************************************************/ -UINT8 btm_ble_ocf_to_condtype(UINT8 ocf) -{ - UINT8 cond_type = 0; - - switch (ocf) { - case BTM_BLE_META_PF_FEAT_SEL: - cond_type = BTM_BLE_META_PF_FEAT_SEL; - break; - case BTM_BLE_META_PF_ADDR: - cond_type = BTM_BLE_PF_ADDR_FILTER; - break; - case BTM_BLE_META_PF_UUID: - cond_type = BTM_BLE_PF_SRVC_UUID; - break; - case BTM_BLE_META_PF_SOL_UUID: - cond_type = BTM_BLE_PF_SRVC_SOL_UUID; - break; - case BTM_BLE_META_PF_LOCAL_NAME: - cond_type = BTM_BLE_PF_LOCAL_NAME; - break; - case BTM_BLE_META_PF_MANU_DATA: - cond_type = BTM_BLE_PF_MANU_DATA; - break; - case BTM_BLE_META_PF_SRVC_DATA: - cond_type = BTM_BLE_PF_SRVC_DATA_PATTERN; - break; - case BTM_BLE_META_PF_ALL: - cond_type = BTM_BLE_PF_TYPE_ALL; - break; - default: - cond_type = BTM_BLE_PF_TYPE_MAX; - break; - } - return cond_type; -} - -/******************************************************************************* -** -** Function btm_ble_scan_pf_cmpl_cback -** -** Description the BTM BLE customer feature VSC complete callback for ADV PF filtering -** -** Returns pointer to the counter if found; NULL otherwise. -** -*******************************************************************************/ -void btm_ble_scan_pf_cmpl_cback(tBTM_VSC_CMPL *p_params) -{ - UINT8 status = 0; - UINT8 *p = p_params->p_param_buf, op_subcode = 0, action = 0xff; - UINT16 evt_len = p_params->param_len; - UINT8 ocf = BTM_BLE_META_PF_ALL, cond_type = 0; - UINT8 num_avail = 0, cb_evt = 0; - tBTM_BLE_REF_VALUE ref_value = 0; - tBTM_BLE_PF_CFG_CBACK *p_scan_cfg_cback = NULL; - tBTM_BLE_PF_PARAM_CBACK *p_filt_param_cback = NULL; - - if (evt_len < 3 || evt_len > 4) { - BTM_TRACE_ERROR("%s cannot interpret APCF callback status = %d, length = %d", - __func__, status, evt_len); - btm_ble_advfilt_deq_op_q(&action, &ocf, &cb_evt, &ref_value, &p_scan_cfg_cback, - &p_filt_param_cback); - return; - } - - btm_ble_advfilt_deq_op_q(&action, &ocf, &cb_evt, &ref_value, &p_scan_cfg_cback, - &p_filt_param_cback); - - STREAM_TO_UINT8(status, p); - STREAM_TO_UINT8(op_subcode, p); - STREAM_TO_UINT8(action, p); - - /* Ignore the event, if it is not the same one expected */ - if (3 == evt_len) { - if (ocf != op_subcode) { - BTM_TRACE_ERROR("btm_ble_scan_pf_cmpl_cback:3-Incorrect opcode :%d, %d, %d, %d, %d, %d", - ocf, op_subcode, action, evt_len, ref_value, status); - return; - } else { - if (NULL != btm_ble_adv_filt_cb.p_filt_stat_cback) { - btm_ble_adv_filt_cb.p_filt_stat_cback(action, status, ref_value); - } - BTM_TRACE_DEBUG("btm_ble_scan_pf_cmpl_cback enabled/disabled, %d, %d, %d, %d", - ocf, action, status, ref_value); - return; - } - } - - if (4 == evt_len && ocf != op_subcode) { - BTM_TRACE_ERROR("btm_ble_scan_pf_cmpl_cback:4-Incorrect opcode: %d, %d, %d, %d, %d", - ocf, op_subcode, action, status, ref_value); - return; - } - - STREAM_TO_UINT8(num_avail, p); - switch (op_subcode) { - case BTM_BLE_META_PF_ADDR: - case BTM_BLE_META_PF_UUID: - case BTM_BLE_META_PF_SOL_UUID: - case BTM_BLE_META_PF_LOCAL_NAME: - case BTM_BLE_META_PF_MANU_DATA: - case BTM_BLE_META_PF_SRVC_DATA: - cond_type = btm_ble_ocf_to_condtype(ocf); - BTM_TRACE_DEBUG("btm_ble_scan_pf_cmpl_cback Recd: %d, %d, %d, %d, %d, %d", op_subcode, - ocf, action, status, ref_value, num_avail); - if (HCI_SUCCESS == status) { - if (memcmp(&btm_ble_adv_filt_cb.cur_filter_target.bda, &na_bda, BD_ADDR_LEN) == 0) { - btm_ble_cs_update_pf_counter(action, cond_type, NULL, num_avail); - } else { - btm_ble_cs_update_pf_counter(action, cond_type, - &btm_ble_adv_filt_cb.cur_filter_target, num_avail); - } - } - - /* send ADV PF operation complete */ - btm_ble_adv_filt_cb.op_type = 0; - break; - - case BTM_BLE_META_PF_FEAT_SEL: - BTM_TRACE_DEBUG("btm_ble_scan_pf_cmpl_cback-Feat sel event: %d, %d, %d, %d", - action, status, ref_value, num_avail); - break; - - default: - BTM_TRACE_ERROR("btm_ble_scan_pf_cmpl_cback: unknown operation: %d", op_subcode); - break; - } - - BTM_TRACE_DEBUG("btm_ble_scan_pf_cmpl_cback: calling the cback: %d", cb_evt); - switch (cb_evt) { - case BTM_BLE_FILT_CFG: - if (NULL != p_scan_cfg_cback) { - p_scan_cfg_cback(action, cond_type, num_avail, status, ref_value); - } - break; - case BTM_BLE_FILT_ADV_PARAM: - if (NULL != p_filt_param_cback) { - p_filt_param_cback(action, num_avail, ref_value, status); - } - break; - default: - break; - } -} - -/******************************************************************************* -** -** Function btm_ble_find_addr_filter_counter -** -** Description find the per bd address ADV payload filter counter by BD_ADDR. -** -** Returns pointer to the counter if found; NULL otherwise. -** -*******************************************************************************/ -tBTM_BLE_PF_COUNT *btm_ble_find_addr_filter_counter(tBLE_BD_ADDR *p_le_bda) -{ - UINT8 i; - tBTM_BLE_PF_COUNT *p_addr_filter = &btm_ble_adv_filt_cb.p_addr_filter_count[1]; - - if (p_le_bda == NULL) { - return &btm_ble_adv_filt_cb.p_addr_filter_count[0]; - } - - for (i = 0; i < cmn_ble_adv_vsc_cb.max_filter; i ++, p_addr_filter ++) { - if (p_addr_filter->in_use && - memcmp(p_le_bda->bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0) { - return p_addr_filter; - } - } - return NULL; -} - -/******************************************************************************* -** -** Function btm_ble_alloc_addr_filter_counter -** -** Description allocate the per device adv payload filter counter. -** -** Returns pointer to the counter if allocation succeed; NULL otherwise. -** -*******************************************************************************/ -tBTM_BLE_PF_COUNT *btm_ble_alloc_addr_filter_counter(BD_ADDR bd_addr) -{ - UINT8 i; - tBTM_BLE_PF_COUNT *p_addr_filter = &btm_ble_adv_filt_cb.p_addr_filter_count[1]; - - for (i = 0; i < cmn_ble_adv_vsc_cb.max_filter; i ++, p_addr_filter ++) { - if (memcmp(na_bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0) { - memcpy(p_addr_filter->bd_addr, bd_addr, BD_ADDR_LEN); - p_addr_filter->in_use = TRUE; - return p_addr_filter; - } - } - return NULL; -} -/******************************************************************************* -** -** Function btm_ble_dealloc_addr_filter_counter -** -** Description de-allocate the per device adv payload filter counter. -** -** Returns TRUE if deallocation succeed; FALSE otherwise. -** -*******************************************************************************/ -BOOLEAN btm_ble_dealloc_addr_filter_counter(tBLE_BD_ADDR *p_bd_addr, UINT8 filter_type) -{ - UINT8 i; - tBTM_BLE_PF_COUNT *p_addr_filter = &btm_ble_adv_filt_cb.p_addr_filter_count[1]; - BOOLEAN found = FALSE; - - if (BTM_BLE_PF_TYPE_ALL == filter_type && NULL == p_bd_addr) { - memset(&btm_ble_adv_filt_cb.p_addr_filter_count[0], 0, sizeof(tBTM_BLE_PF_COUNT)); - } - - for (i = 0; i < cmn_ble_adv_vsc_cb.max_filter; i ++, p_addr_filter ++) { - if ((p_addr_filter->in_use) && (NULL == p_bd_addr || - (memcmp(p_bd_addr->bda, p_addr_filter->bd_addr, BD_ADDR_LEN) == 0)) { - found = TRUE; - memset(p_addr_filter, 0, sizeof(tBTM_BLE_PF_COUNT)); - - if (NULL != p_bd_addr) { - break; - } - } - } - return found; -} - -/******************************************************************************* -** -** Function btm_ble_update_pf_local_name -** -** Description this function update(add,delete or clear) the adv local name filtering condition. -** -** -** Returns BTM_SUCCESS if successful, -** BTM_ILLEGAL_VALUE if parameter is not valid. -** -*******************************************************************************/ -tBTM_STATUS btm_ble_update_pf_local_name(tBTM_BLE_SCAN_COND_OP action, - tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_COND_PARAM *p_cond) -{ - tBTM_BLE_PF_LOCAL_NAME_COND *p_local_name = (p_cond == NULL) ? NULL : &p_cond->local_name; - UINT8 param[BTM_BLE_PF_STR_LEN_MAX + BTM_BLE_ADV_FILT_META_HDR_LENGTH], - *p = param, - len = BTM_BLE_ADV_FILT_META_HDR_LENGTH; - tBTM_STATUS st = BTM_ILLEGAL_VALUE; - - memset(param, 0, BTM_BLE_PF_STR_LEN_MAX + BTM_BLE_ADV_FILT_META_HDR_LENGTH); - - UINT8_TO_STREAM(p, BTM_BLE_META_PF_LOCAL_NAME); - UINT8_TO_STREAM(p, action); - - /* Filter index */ - UINT8_TO_STREAM(p, filt_index); - - if (BTM_BLE_SCAN_COND_ADD == action || - BTM_BLE_SCAN_COND_DELETE == action) { - if (NULL == p_local_name) { - return st; - } - - if (p_local_name->data_len > BTM_BLE_PF_STR_LEN_MAX) { - p_local_name->data_len = BTM_BLE_PF_STR_LEN_MAX; - } - - ARRAY_TO_STREAM(p, p_local_name->p_data, p_local_name->data_len); - len += p_local_name->data_len; - } - - /* send local name filter */ - if ((st = BTM_VendorSpecificCommand (HCI_BLE_ADV_FILTER_OCF, - len, - param, - btm_ble_scan_pf_cmpl_cback)) - != BTM_NO_RESOURCES) { - memset(&btm_ble_adv_filt_cb.cur_filter_target, 0, sizeof(tBLE_BD_ADDR)); - } else { - BTM_TRACE_ERROR("Local Name PF filter update failed"); - } - - return st; -} - - -/******************************************************************************* -** -** Function btm_ble_update_srvc_data_change -** -** Description this function update(add/remove) service data change filter. -** -** -** Returns BTM_SUCCESS if successful, -** BTM_ILLEGAL_VALUE if parameter is not valid. -** -*******************************************************************************/ -tBTM_STATUS btm_ble_update_srvc_data_change(tBTM_BLE_SCAN_COND_OP action, - tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_COND_PARAM *p_cond) -{ - tBTM_STATUS st = BTM_ILLEGAL_VALUE; - tBLE_BD_ADDR *p_bd_addr = p_cond ? &p_cond->target_addr : NULL; - UINT8 num_avail = (action == BTM_BLE_SCAN_COND_ADD) ? 0 : 1; - - if (btm_ble_cs_update_pf_counter (action, BTM_BLE_PF_SRVC_DATA, p_bd_addr, num_avail) - != BTM_BLE_INVALID_COUNTER) { - st = BTM_SUCCESS; - } - - return st; -} - -/******************************************************************************* -** -** Function btm_ble_update_pf_manu_data -** -** Description this function update(add,delete or clear) the adv manufacturer -** data filtering condition. -** -** -** Returns BTM_SUCCESS if successful, -** BTM_ILLEGAL_VALUE if parameter is not valid. -** -*******************************************************************************/ -tBTM_STATUS btm_ble_update_pf_manu_data(tBTM_BLE_SCAN_COND_OP action, - tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_COND_PARAM *p_data, - tBTM_BLE_PF_COND_TYPE cond_type, - tBTM_BLE_FILT_CB_EVT cb_evt, - tBTM_BLE_REF_VALUE ref_value) -{ - tBTM_BLE_PF_MANU_COND *p_manu_data = (p_data == NULL) ? NULL : &p_data->manu_data; - tBTM_BLE_PF_SRVC_PATTERN_COND *p_srvc_data = (p_data == NULL) ? NULL : &p_data->srvc_data; - - UINT8 param[BTM_BLE_PF_STR_LEN_MAX + BTM_BLE_PF_STR_LEN_MAX + BTM_BLE_ADV_FILT_META_HDR_LENGTH], - *p = param, - len = BTM_BLE_ADV_FILT_META_HDR_LENGTH; - tBTM_STATUS st = BTM_ILLEGAL_VALUE; - - if (NULL == p_data) { - return st; - } - - memset(param, 0, BTM_BLE_PF_STR_LEN_MAX + BTM_BLE_PF_STR_LEN_MAX - + BTM_BLE_ADV_FILT_META_HDR_LENGTH); - - if (BTM_BLE_PF_SRVC_DATA_PATTERN == cond_type) { - UINT8_TO_STREAM(p, BTM_BLE_META_PF_SRVC_DATA); - } else { - UINT8_TO_STREAM(p, BTM_BLE_META_PF_MANU_DATA); - } - - UINT8_TO_STREAM(p, action); - - /* Filter index */ - UINT8_TO_STREAM(p, filt_index); - - if (BTM_BLE_SCAN_COND_ADD == action || BTM_BLE_SCAN_COND_DELETE == action) { - if (BTM_BLE_PF_SRVC_DATA_PATTERN == cond_type) { - if (NULL == p_srvc_data) { - return st; - } - if (p_srvc_data->data_len > (BTM_BLE_PF_STR_LEN_MAX - 2)) { - p_srvc_data->data_len = (BTM_BLE_PF_STR_LEN_MAX - 2); - } - - if (p_srvc_data->data_len > 0) { - ARRAY_TO_STREAM(p, p_srvc_data->p_pattern, p_srvc_data->data_len); - len += (p_srvc_data->data_len); - ARRAY_TO_STREAM(p, p_srvc_data->p_pattern_mask, p_srvc_data->data_len); - } - - len += (p_srvc_data->data_len); - BTM_TRACE_DEBUG("Service data length: %d", len); - } else { - if (NULL == p_manu_data) { - BTM_TRACE_ERROR("btm_ble_update_pf_manu_data - No manuf data"); - return st; - } - BTM_TRACE_EVENT("btm_ble_update_pf_manu_data length: %d", - p_manu_data->data_len); - if (p_manu_data->data_len > (BTM_BLE_PF_STR_LEN_MAX - 2)) { - p_manu_data->data_len = (BTM_BLE_PF_STR_LEN_MAX - 2); - } - - UINT16_TO_STREAM(p, p_manu_data->company_id); - if (p_manu_data->data_len > 0 && p_manu_data->p_pattern_mask != NULL) { - ARRAY_TO_STREAM(p, p_manu_data->p_pattern, p_manu_data->data_len); - len += (p_manu_data->data_len + 2); - } else { - len += 2; - } - - if (p_manu_data->company_id_mask != 0) { - UINT16_TO_STREAM (p, p_manu_data->company_id_mask); - } else { - memset(p, 0xff, 2); - p += 2; - } - len += 2; - - if (p_manu_data->data_len > 0 && p_manu_data->p_pattern_mask != NULL) { - ARRAY_TO_STREAM(p, p_manu_data->p_pattern_mask, p_manu_data->data_len); - len += (p_manu_data->data_len); - } - - BTM_TRACE_DEBUG("Manuf data length: %d", len); - } - } - - /* send manufacturer*/ - if ((st = BTM_VendorSpecificCommand (HCI_BLE_ADV_FILTER_OCF, - len, - param, - btm_ble_scan_pf_cmpl_cback)) != BTM_NO_RESOURCES) { - memset(&btm_ble_adv_filt_cb.cur_filter_target, 0, sizeof(tBLE_BD_ADDR)); - } else { - BTM_TRACE_ERROR("manufacturer data PF filter update failed"); - } - - return st; -} - -/******************************************************************************* -** -** Function btm_ble_cs_update_pf_counter -** -** Description this function is to update the adv data payload filter counter -** -** Returns current number of the counter; BTM_BLE_INVALID_COUNTER if -** counter update failed. -** -*******************************************************************************/ -UINT8 btm_ble_cs_update_pf_counter(tBTM_BLE_SCAN_COND_OP action, - UINT8 cond_type, tBLE_BD_ADDR *p_bd_addr, - UINT8 num_available) -{ - tBTM_BLE_PF_COUNT *p_addr_filter = NULL; - UINT8 *p_counter = NULL; - - btm_ble_obtain_vsc_details(); - - if (cond_type > BTM_BLE_PF_TYPE_ALL) { - BTM_TRACE_ERROR("unknown PF filter condition type %d", cond_type); - return BTM_BLE_INVALID_COUNTER; - } - - /* for these three types of filter, always generic */ - if (BTM_BLE_PF_ADDR_FILTER == cond_type || - BTM_BLE_PF_MANU_DATA == cond_type || - BTM_BLE_PF_LOCAL_NAME == cond_type || - BTM_BLE_PF_SRVC_DATA_PATTERN == cond_type) { - p_bd_addr = NULL; - } - - if ((p_addr_filter = btm_ble_find_addr_filter_counter(p_bd_addr)) == NULL && - BTM_BLE_SCAN_COND_ADD == action) { - p_addr_filter = btm_ble_alloc_addr_filter_counter(p_bd_addr->bda); - } - - if (NULL != p_addr_filter) { - /* all filter just cleared */ - if ((BTM_BLE_PF_TYPE_ALL == cond_type && BTM_BLE_SCAN_COND_CLEAR == action) || - /* or bd address filter been deleted */ - (BTM_BLE_PF_ADDR_FILTER == cond_type && - (BTM_BLE_SCAN_COND_DELETE == action || BTM_BLE_SCAN_COND_CLEAR == action))) { - btm_ble_dealloc_addr_filter_counter(p_bd_addr, cond_type); - } - /* if not feature selection, update new addition/reduction of the filter counter */ - else if (cond_type != BTM_BLE_PF_TYPE_ALL) { - p_counter = p_addr_filter->pf_counter; - if (num_available > 0) { - p_counter[cond_type] += 1; - } - - BTM_TRACE_DEBUG("counter = %d, maxfilt = %d, num_avbl=%d", - p_counter[cond_type], cmn_ble_adv_vsc_cb.max_filter, num_available); - return p_counter[cond_type]; - } - } else { - BTM_TRACE_ERROR("no matching filter counter found"); - } - /* no matching filter located and updated */ - return BTM_BLE_INVALID_COUNTER; -} - - -/******************************************************************************* -** -** Function btm_ble_update_addr_filter -** -** Description this function update(add,delete or clear) the address filter of adv. -** -** -** Returns BTM_SUCCESS if successful, -** BTM_ILLEGAL_VALUE if parameter is not valid. -** -*******************************************************************************/ -tBTM_STATUS btm_ble_update_addr_filter(tBTM_BLE_SCAN_COND_OP action, - tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_COND_PARAM *p_cond) -{ - UINT8 param[BTM_BLE_META_ADDR_LEN + BTM_BLE_ADV_FILT_META_HDR_LENGTH], - * p = param; - tBTM_STATUS st = BTM_ILLEGAL_VALUE; - tBLE_BD_ADDR *p_addr = (p_cond == NULL) ? NULL : &p_cond->target_addr; - - memset(param, 0, BTM_BLE_META_ADDR_LEN + BTM_BLE_ADV_FILT_META_HDR_LENGTH); - - UINT8_TO_STREAM(p, BTM_BLE_META_PF_ADDR); - UINT8_TO_STREAM(p, action); - - /* Filter index */ - UINT8_TO_STREAM(p, filt_index); - - if (BTM_BLE_SCAN_COND_ADD == action || - BTM_BLE_SCAN_COND_DELETE == action) { - if (NULL == p_addr) { - return st; - } - - BDADDR_TO_STREAM(p, p_addr->bda); - UINT8_TO_STREAM(p, p_addr->type); - } - /* send address filter */ - if ((st = BTM_VendorSpecificCommand (HCI_BLE_ADV_FILTER_OCF, - (UINT8)(BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_META_ADDR_LEN), - param, - btm_ble_scan_pf_cmpl_cback)) != BTM_NO_RESOURCES) { - memset(&btm_ble_adv_filt_cb.cur_filter_target, 0, sizeof(tBLE_BD_ADDR)); - } else { - BTM_TRACE_ERROR("Broadcaster Address Filter Update failed"); - } - return st; -} - -/******************************************************************************* -** -** Function btm_ble_update_uuid_filter -** -** Description this function update(add,delete or clear) service UUID filter. -** -** -** Returns BTM_SUCCESS if successful, -** BTM_ILLEGAL_VALUE if parameter is not valid. -** -*******************************************************************************/ -tBTM_STATUS btm_ble_update_uuid_filter(tBTM_BLE_SCAN_COND_OP action, - tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_COND_TYPE filter_type, - tBTM_BLE_PF_COND_PARAM *p_cond, - tBTM_BLE_FILT_CB_EVT cb_evt, - tBTM_BLE_REF_VALUE ref_value) -{ - UINT8 param[BTM_BLE_META_UUID_LEN + BTM_BLE_ADV_FILT_META_HDR_LENGTH], - * p = param, - len = BTM_BLE_ADV_FILT_META_HDR_LENGTH; - tBTM_STATUS st = BTM_ILLEGAL_VALUE; - tBTM_BLE_PF_UUID_COND *p_uuid_cond; - UINT8 evt_type; - - memset(param, 0, BTM_BLE_META_UUID_LEN + BTM_BLE_ADV_FILT_META_HDR_LENGTH); - - if (BTM_BLE_PF_SRVC_UUID == filter_type) { - evt_type = BTM_BLE_META_PF_UUID; - p_uuid_cond = p_cond ? &p_cond->srvc_uuid : NULL; - } else { - evt_type = BTM_BLE_META_PF_SOL_UUID; - p_uuid_cond = p_cond ? &p_cond->solicitate_uuid : NULL; - } - - if (NULL == p_uuid_cond && action != BTM_BLE_SCAN_COND_CLEAR) { - BTM_TRACE_ERROR("Illegal param for add/delete UUID filter"); - return st; - } - - /* need to add address filter first, if adding per bda UUID filter without address filter */ - if (BTM_BLE_SCAN_COND_ADD == action && NULL != p_uuid_cond && - p_uuid_cond->p_target_addr && - btm_ble_find_addr_filter_counter(p_uuid_cond->p_target_addr) == NULL) { - UINT8_TO_STREAM(p, BTM_BLE_META_PF_ADDR); - UINT8_TO_STREAM(p, action); - - /* Filter index */ - UINT8_TO_STREAM(p, filt_index); - - BDADDR_TO_STREAM(p, p_uuid_cond->p_target_addr->bda); - UINT8_TO_STREAM(p, p_uuid_cond->p_target_addr->type); - - /* send address filter */ - if ((st = BTM_VendorSpecificCommand (HCI_BLE_ADV_FILTER_OCF, - (UINT8)(BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_META_ADDR_LEN), - param, - btm_ble_scan_pf_cmpl_cback)) == BTM_NO_RESOURCES) { - BTM_TRACE_ERROR("Update Address filter into controller failed."); - return st; - } - - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_ADDR, cb_evt, ref_value, NULL, NULL); - BTM_TRACE_DEBUG("Updated Address filter"); - } - - p = param; - UINT8_TO_STREAM(p, evt_type); - UINT8_TO_STREAM(p, action); - - /* Filter index */ - UINT8_TO_STREAM(p, filt_index); - - if ((BTM_BLE_SCAN_COND_ADD == action || - BTM_BLE_SCAN_COND_DELETE == action) && - NULL != p_uuid_cond) { - if (p_uuid_cond->uuid.len == LEN_UUID_16) { - UINT16_TO_STREAM(p, p_uuid_cond->uuid.uu.uuid16); - len += LEN_UUID_16; - } else if (p_uuid_cond->uuid.len == LEN_UUID_32) { /*4 bytes */ - UINT32_TO_STREAM(p, p_uuid_cond->uuid.uu.uuid32); - len += LEN_UUID_32; - } else if (p_uuid_cond->uuid.len == LEN_UUID_128) { - ARRAY_TO_STREAM (p, p_uuid_cond->uuid.uu.uuid128, LEN_UUID_128); - len += LEN_UUID_128; - } else { - BTM_TRACE_ERROR("illegal UUID length: %d", p_uuid_cond->uuid.len); - return BTM_ILLEGAL_VALUE; - } - - if (NULL != p_uuid_cond->p_uuid_mask) { - if (p_uuid_cond->uuid.len == LEN_UUID_16) { - UINT16_TO_STREAM(p, p_uuid_cond->p_uuid_mask->uuid16_mask); - len += LEN_UUID_16; - } else if (p_uuid_cond->uuid.len == LEN_UUID_32) { /*4 bytes */ - UINT32_TO_STREAM(p, p_uuid_cond->p_uuid_mask->uuid32_mask); - len += LEN_UUID_32; - } else if (p_uuid_cond->uuid.len == LEN_UUID_128) { - ARRAY_TO_STREAM (p, p_uuid_cond->p_uuid_mask->uuid128_mask, LEN_UUID_128); - len += LEN_UUID_128; - } - } else { - memset(p, 0xff, p_uuid_cond->uuid.len); - len += p_uuid_cond->uuid.len; - } - BTM_TRACE_DEBUG("btm_ble_update_uuid_filter : %d, %d, %d, %d", filter_type, evt_type, - p_uuid_cond->uuid.len, len); - } - - /* send UUID filter update */ - if ((st = BTM_VendorSpecificCommand (HCI_BLE_ADV_FILTER_OCF, - len, - param, - btm_ble_scan_pf_cmpl_cback)) != BTM_NO_RESOURCES) { - if (p_uuid_cond && p_uuid_cond->p_target_addr) { - memcpy(&btm_ble_adv_filt_cb.cur_filter_target, p_uuid_cond->p_target_addr, - sizeof(tBLE_BD_ADDR)); - } - else { - memset(&btm_ble_adv_filt_cb.cur_filter_target, 0, sizeof(tBLE_BD_ADDR)); - } - } else { - BTM_TRACE_ERROR("UUID filter updating failed"); - } - - return st; -} - - -/******************************************************************************* -** -** Function btm_ble_clear_scan_pf_filter -** -** Description clear all adv payload filter by de-select all the adv pf feature bits -** -** -** Returns BTM_SUCCESS if successful, -** BTM_ILLEGAL_VALUE if parameter is not valid. -** -*******************************************************************************/ -tBTM_STATUS btm_ble_clear_scan_pf_filter(tBTM_BLE_SCAN_COND_OP action, - tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_COND_PARAM *p_cond, - tBTM_BLE_PF_CFG_CBACK *p_cmpl_cback, - tBTM_BLE_FILT_CB_EVT cb_evt, - tBTM_BLE_REF_VALUE ref_value) -{ - tBLE_BD_ADDR *p_target = (p_cond == NULL) ? NULL : &p_cond->target_addr; - tBTM_BLE_PF_COUNT *p_bda_filter; - tBTM_STATUS st = BTM_WRONG_MODE; - UINT8 param[20], *p; - - if (BTM_BLE_SCAN_COND_CLEAR != action) { - BTM_TRACE_ERROR("unable to perform action:%d for generic adv filter type", action); - return BTM_ILLEGAL_VALUE; - } - - p = param; - memset(param, 0, 20); - - p_bda_filter = btm_ble_find_addr_filter_counter(p_target); - - if (NULL == p_bda_filter || - /* not a generic filter */ - (p_target != NULL)) { - BTM_TRACE_ERROR("Error: Can not clear filter, No PF filter has been configured!"); - return st; - } - - /* clear the general filter entry */ - if (NULL == p_target) { - /* clear manufacturer data filter */ - st = btm_ble_update_pf_manu_data(BTM_BLE_SCAN_COND_CLEAR, filt_index, NULL, - BTM_BLE_PF_MANU_DATA, cb_evt, ref_value); - if (BTM_CMD_STARTED == st) { - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_MANU_DATA, cb_evt, - ref_value, NULL, NULL); - } - - /* clear local name filter */ - st = btm_ble_update_pf_local_name(BTM_BLE_SCAN_COND_CLEAR, filt_index, NULL); - if (BTM_CMD_STARTED == st) { - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_LOCAL_NAME, cb_evt, - ref_value, NULL, NULL); - } - - /* update the counter for service data */ - st = btm_ble_update_srvc_data_change(BTM_BLE_SCAN_COND_CLEAR, filt_index, NULL); - - /* clear UUID filter */ - st = btm_ble_update_uuid_filter(BTM_BLE_SCAN_COND_CLEAR, filt_index, - BTM_BLE_PF_SRVC_UUID, NULL, cb_evt, ref_value); - if (BTM_CMD_STARTED == st) { - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_UUID, cb_evt, ref_value, NULL, NULL); - } - - st = btm_ble_update_uuid_filter(BTM_BLE_SCAN_COND_CLEAR, filt_index, - BTM_BLE_PF_SRVC_SOL_UUID, NULL, cb_evt, ref_value); - if (BTM_CMD_STARTED == st) { - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_SOL_UUID, cb_evt, - ref_value, NULL, NULL); - } - - /* clear service data filter */ - st = btm_ble_update_pf_manu_data(BTM_BLE_SCAN_COND_CLEAR, filt_index, NULL, - BTM_BLE_PF_SRVC_DATA_PATTERN, cb_evt, ref_value); - if (BTM_CMD_STARTED == st) { - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_SRVC_DATA, cb_evt, - ref_value, NULL, NULL); - } - } - - /* select feature based on control block settings */ - UINT8_TO_STREAM(p, BTM_BLE_META_PF_FEAT_SEL); - UINT8_TO_STREAM(p, BTM_BLE_SCAN_COND_CLEAR); - - /* Filter index */ - UINT8_TO_STREAM(p, filt_index); - - /* set PCF selection */ - UINT32_TO_STREAM(p, BTM_BLE_PF_SELECT_NONE); - /* set logic condition as OR as default */ - UINT8_TO_STREAM(p, BTM_BLE_PF_LOGIC_OR); - - if ((st = BTM_VendorSpecificCommand (HCI_BLE_ADV_FILTER_OCF, - (UINT8)(BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_PF_FEAT_SEL_LEN), - param, - btm_ble_scan_pf_cmpl_cback)) - != BTM_NO_RESOURCES) { - if (p_target) { - memcpy(&btm_ble_adv_filt_cb.cur_filter_target, p_target, sizeof(tBLE_BD_ADDR)); - } else { - memset(&btm_ble_adv_filt_cb.cur_filter_target, 0, sizeof(tBLE_BD_ADDR)); - } - } - return st; -} - -/******************************************************************************* -** -** Function BTM_BleAdvFilterParamSetup -** -** Description This function is called to setup the adv data payload filter -** condition. -** -** Parameters action - Type of action to be performed -** filt_index - Filter index -** p_filt_params - Filter parameters -** p_target - Target device -** p_cmpl_back - Callback pointer -** ref_value - reference value -** -** Returns void -** -*******************************************************************************/ -tBTM_STATUS BTM_BleAdvFilterParamSetup(int action, tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_FILT_PARAMS *p_filt_params, - tBLE_BD_ADDR *p_target, tBTM_BLE_PF_PARAM_CBACK *p_cmpl_cback, - tBTM_BLE_REF_VALUE ref_value) -{ - tBTM_STATUS st = BTM_WRONG_MODE; - tBTM_BLE_PF_COUNT *p_bda_filter = NULL; - UINT8 len = BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_ADV_FILT_FEAT_SELN_LEN + - BTM_BLE_ADV_FILT_TRACK_NUM; - UINT8 param[len], *p; - - if (BTM_SUCCESS != btm_ble_obtain_vsc_details()) { - return st; - } - - p = param; - memset(param, 0, len); - BTM_TRACE_EVENT (" BTM_BleAdvFilterParamSetup"); - - if (BTM_BLE_SCAN_COND_ADD == action) { - p_bda_filter = btm_ble_find_addr_filter_counter(p_target); - if (NULL == p_bda_filter) { - BTM_TRACE_ERROR("BD Address not found!"); - return st; - } - - BTM_TRACE_DEBUG("BTM_BleAdvFilterParamSetup : Feat mask:%d", p_filt_params->feat_seln); - /* select feature based on control block settings */ - UINT8_TO_STREAM(p, BTM_BLE_META_PF_FEAT_SEL); - UINT8_TO_STREAM(p, BTM_BLE_SCAN_COND_ADD); - - /* Filter index */ - UINT8_TO_STREAM(p, filt_index); - - /* set PCF selection */ - UINT16_TO_STREAM(p, p_filt_params->feat_seln); - /* set logic type */ - UINT16_TO_STREAM(p, p_filt_params->logic_type); - /* set logic condition */ - UINT8_TO_STREAM(p, p_filt_params->filt_logic_type); - /* set RSSI high threshold */ - UINT8_TO_STREAM(p, p_filt_params->rssi_high_thres); - /* set delivery mode */ - UINT8_TO_STREAM(p, p_filt_params->dely_mode); - - if (0x01 == p_filt_params->dely_mode) { - /* set onfound timeout */ - UINT16_TO_STREAM(p, p_filt_params->found_timeout); - /* set onfound timeout count*/ - UINT8_TO_STREAM(p, p_filt_params->found_timeout_cnt); - /* set RSSI low threshold */ - UINT8_TO_STREAM(p, p_filt_params->rssi_low_thres); - /* set onlost timeout */ - UINT16_TO_STREAM(p, p_filt_params->lost_timeout); - /* set num_of_track_entries for firmware greater than L-release version */ - if (cmn_ble_adv_vsc_cb.version_supported > BTM_VSC_CHIP_CAPABILITY_L_VERSION) { - UINT16_TO_STREAM(p, p_filt_params->num_of_tracking_entries); - } - } - - if (cmn_ble_adv_vsc_cb.version_supported == BTM_VSC_CHIP_CAPABILITY_L_VERSION) { - len = BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_ADV_FILT_FEAT_SELN_LEN; - } else { - len = BTM_BLE_ADV_FILT_META_HDR_LENGTH + BTM_BLE_ADV_FILT_FEAT_SELN_LEN + - BTM_BLE_ADV_FILT_TRACK_NUM; - } - - if ((st = BTM_VendorSpecificCommand (HCI_BLE_ADV_FILTER_OCF, - (UINT8)len, - param, - btm_ble_scan_pf_cmpl_cback)) - == BTM_NO_RESOURCES) { - return st; - } - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_FEAT_SEL, BTM_BLE_FILT_ADV_PARAM, - ref_value, NULL, p_cmpl_cback); - } else if (BTM_BLE_SCAN_COND_DELETE == action) { - /* select feature based on control block settings */ - UINT8_TO_STREAM(p, BTM_BLE_META_PF_FEAT_SEL); - UINT8_TO_STREAM(p, BTM_BLE_SCAN_COND_DELETE); - /* Filter index */ - UINT8_TO_STREAM(p, filt_index); - - if ((st = BTM_VendorSpecificCommand (HCI_BLE_ADV_FILTER_OCF, - (UINT8)(BTM_BLE_ADV_FILT_META_HDR_LENGTH), - param, - btm_ble_scan_pf_cmpl_cback)) - == BTM_NO_RESOURCES) { - return st; - } - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_FEAT_SEL, BTM_BLE_FILT_ADV_PARAM, - ref_value, NULL, p_cmpl_cback); - } else if (BTM_BLE_SCAN_COND_CLEAR == action) { - /* Deallocate all filters here */ - btm_ble_dealloc_addr_filter_counter(NULL, BTM_BLE_PF_TYPE_ALL); - - /* select feature based on control block settings */ - UINT8_TO_STREAM(p, BTM_BLE_META_PF_FEAT_SEL); - UINT8_TO_STREAM(p, BTM_BLE_SCAN_COND_CLEAR); - - if ((st = BTM_VendorSpecificCommand (HCI_BLE_ADV_FILTER_OCF, - (UINT8)(BTM_BLE_ADV_FILT_META_HDR_LENGTH - 1), - param, - btm_ble_scan_pf_cmpl_cback)) - == BTM_NO_RESOURCES) { - return st; - } - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_FEAT_SEL, BTM_BLE_FILT_ADV_PARAM, - ref_value, NULL, p_cmpl_cback); - } - - return st; -} - -/******************************************************************************* -** -** Function BTM_BleEnableDisableFilterFeature -** -** Description This function is called to enable / disable the APCF feature -** -** Parameters enable the generic scan condition. -** enable: enable or disable the filter condition -** p_stat_cback - Status callback pointer -** ref_value - Ref value -** Returns void -** -*******************************************************************************/ -tBTM_STATUS BTM_BleEnableDisableFilterFeature(UINT8 enable, - tBTM_BLE_PF_STATUS_CBACK *p_stat_cback, - tBTM_BLE_REF_VALUE ref_value) -{ - UINT8 param[20], *p; - tBTM_STATUS st = BTM_WRONG_MODE; - - if (BTM_SUCCESS != btm_ble_obtain_vsc_details()) { - return st; - } - - p = param; - memset(param, 0, 20); - - /* enable the content filter in controller */ - p = param; - UINT8_TO_STREAM(p, BTM_BLE_META_PF_ENABLE); - /* enable adv data payload filtering */ - UINT8_TO_STREAM(p, enable); - - if ((st = BTM_VendorSpecificCommand (HCI_BLE_ADV_FILTER_OCF, - BTM_BLE_PCF_ENABLE_LEN, param, - btm_ble_scan_pf_cmpl_cback)) == BTM_CMD_STARTED) { - btm_ble_adv_filt_cb.p_filt_stat_cback = p_stat_cback; - btm_ble_advfilt_enq_op_q(enable, BTM_BLE_META_PF_ENABLE, BTM_BLE_FILT_ENABLE_DISABLE, - ref_value, NULL, NULL); - } - return st; -} - -/******************************************************************************* -** -** Function BTM_BleCfgFilterCondition -** -** Description This function is called to configure the adv data payload filter -** condition. -** -** Parameters action: to read/write/clear -** cond_type: filter condition type. -** filt_index - Filter index -** p_cond: filter condition parameter -** p_cmpl_cback - Config callback pointer -** ref_value - Reference value -** -** Returns void -** -*******************************************************************************/ -tBTM_STATUS BTM_BleCfgFilterCondition(tBTM_BLE_SCAN_COND_OP action, - tBTM_BLE_PF_COND_TYPE cond_type, - tBTM_BLE_PF_FILT_INDEX filt_index, - tBTM_BLE_PF_COND_PARAM *p_cond, - tBTM_BLE_PF_CFG_CBACK *p_cmpl_cback, - tBTM_BLE_REF_VALUE ref_value) -{ - tBTM_STATUS st = BTM_ILLEGAL_VALUE; - UINT8 ocf = 0; - BTM_TRACE_EVENT (" BTM_BleCfgFilterCondition action:%d, cond_type:%d, index:%d", action, - cond_type, filt_index); - - if (BTM_SUCCESS != btm_ble_obtain_vsc_details()) { - return st; - } - - switch (cond_type) { - /* write service data filter */ - case BTM_BLE_PF_SRVC_DATA_PATTERN: - /* write manufacturer data filter */ - case BTM_BLE_PF_MANU_DATA: - st = btm_ble_update_pf_manu_data(action, filt_index, p_cond, cond_type, 0, ref_value); - break; - - /* write local name filter */ - case BTM_BLE_PF_LOCAL_NAME: - st = btm_ble_update_pf_local_name(action, filt_index, p_cond); - break; - - /* filter on advertiser address */ - case BTM_BLE_PF_ADDR_FILTER: - st = btm_ble_update_addr_filter(action, filt_index, p_cond); - break; - - /* filter on service/solicited UUID */ - case BTM_BLE_PF_SRVC_UUID: - case BTM_BLE_PF_SRVC_SOL_UUID: - st = btm_ble_update_uuid_filter(action, filt_index, cond_type, p_cond, 0, ref_value); - break; - - case BTM_BLE_PF_SRVC_DATA: - st = btm_ble_update_srvc_data_change(action, filt_index, p_cond); - break; - - case BTM_BLE_PF_TYPE_ALL: /* only used to clear filter */ - st = btm_ble_clear_scan_pf_filter(action, filt_index, p_cond, p_cmpl_cback, - 0, ref_value); - break; - - default: - BTM_TRACE_WARNING("condition type [%d] not supported currently.", cond_type); - break; - } - - if (BTM_CMD_STARTED == st && cond_type != BTM_BLE_PF_TYPE_ALL) { - ocf = btm_ble_condtype_to_ocf(cond_type); - btm_ble_advfilt_enq_op_q(action, ocf, BTM_BLE_FILT_CFG, ref_value, p_cmpl_cback, NULL); - } else if (BTM_CMD_STARTED == st && BTM_BLE_PF_TYPE_ALL == cond_type) { - btm_ble_advfilt_enq_op_q(action, BTM_BLE_META_PF_FEAT_SEL, BTM_BLE_FILT_CFG, - ref_value, p_cmpl_cback, NULL); - } - return st; -} - -/******************************************************************************* -** -** Function btm_ble_adv_filter_init -** -** Description This function initializes the adv filter control block -** -** Parameters -** -** Returns status -** -*******************************************************************************/ -void btm_ble_adv_filter_init(void) -{ -#if BTM_DYNAMIC_MEMORY == TRUE - btm_ble_adv_filt_cb_ptr = (tBTM_BLE_ADV_FILTER_CB *)osi_malloc(sizeof(tBTM_BLE_ADV_FILTER_CB)); - cmn_ble_adv_vsc_cb_ptr = (tBTM_BLE_VSC_CB *)osi_malloc(sizeof(tBTM_BLE_VSC_CB)); - if (btm_ble_adv_filt_cb_ptr == NULL || cmn_ble_adv_vsc_cb_ptr == NULL) { - BTM_TRACE_ERROR("%s malloc failed", __func__); - return; - } - memset((void *)btm_ble_adv_filt_cb_ptr, 0, sizeof(tBTM_BLE_ADV_FILTER_CB)); - memset((void *)cmn_ble_adv_vsc_cb_ptr, 0, sizeof(tBTM_BLE_VSC_CB)); -#endif - memset(&btm_ble_adv_filt_cb, 0, sizeof(tBTM_BLE_ADV_FILTER_CB)); - if (BTM_SUCCESS != btm_ble_obtain_vsc_details()) { - return; - } - - if (cmn_ble_adv_vsc_cb.max_filter > 0) { - btm_ble_adv_filt_cb.p_addr_filter_count = - (tBTM_BLE_PF_COUNT *) osi_malloc( sizeof(tBTM_BLE_PF_COUNT) * cmn_ble_adv_vsc_cb.max_filter); - } -} - -/******************************************************************************* -** -** Function btm_ble_adv_filter_cleanup -** -** Description This function de-initializes the adv filter control block -** -** Parameters -** -** Returns status -** -*******************************************************************************/ -void btm_ble_adv_filter_cleanup(void) -{ - if (btm_ble_adv_filt_cb.p_addr_filter_count) { - osi_free(btm_ble_adv_filt_cb.p_addr_filter_count); - btm_ble_adv_filt_cb.p_addr_filter_count = NULL; - } - -#if BTM_DYNAMIC_MEMORY == TRUE - osi_free(btm_ble_adv_filt_cb_ptr); - btm_ble_adv_filt_cb_ptr = NULL; - osi_free(cmn_ble_adv_vsc_cb_ptr); - cmn_ble_adv_vsc_cb_ptr = NULL; -#endif -} - -#endif // #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE #endif diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c index e81c86f80a..870d1f1e3c 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c @@ -4579,9 +4579,7 @@ void btm_ble_init (void) osi_event_bind(p_cb->adv_rpt_ready, btu_get_current_thread(), 0); #endif // #if (BLE_42_SCAN_EN == TRUE) #if BLE_VND_INCLUDED == FALSE -#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE - btm_ble_adv_filter_init(); -#endif // #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE + #endif #if (BLE_VENDOR_HCI_EN == TRUE) BTM_RegisterForVSEvents(btm_ble_vs_evt_callback, TRUE);