From 6326d4629bbfac1ce9fc75b1c156eb6b6724b472 Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Mon, 12 Jan 2026 14:39:47 +0800 Subject: [PATCH] fix(ble/bluedroid): optimize bluedroid host and fix GAP, memory, status and BTM API issues - return HCI_ERR_MEMORY_FULL on cmd buffer alloc failure - remove legacy adv/scan semaphores and mutex - Use the same legacy gap callback instead of each independent legacy gap event callback --- .../bt/host/bluedroid/bta/dm/bta_dm_act.c | 252 +++++---- .../bt/host/bluedroid/bta/dm/bta_dm_api.c | 104 ++-- .../bt/host/bluedroid/bta/dm/bta_dm_main.c | 2 +- .../bluedroid/bta/dm/include/bta_dm_gap.h | 112 ++++ .../bluedroid/bta/dm/include/bta_dm_int.h | 35 +- .../host/bluedroid/bta/gatt/bta_gattc_act.c | 4 +- .../host/bluedroid/bta/include/bta/bta_api.h | 127 +---- .../btc/profile/std/gap/btc_gap_ble.c | 305 +++++++---- components/bt/host/bluedroid/hci/hci_layer.c | 10 +- .../bt/host/bluedroid/stack/btm/btm_acl.c | 43 +- .../bt/host/bluedroid/stack/btm/btm_ble.c | 2 +- .../host/bluedroid/stack/btm/btm_ble_5_gap.c | 170 +----- .../host/bluedroid/stack/btm/btm_ble_addr.c | 16 +- .../host/bluedroid/stack/btm/btm_ble_bgconn.c | 97 ++-- .../bt/host/bluedroid/stack/btm/btm_ble_gap.c | 490 ++++++------------ .../bluedroid/stack/btm/btm_ble_privacy.c | 45 +- .../bt/host/bluedroid/stack/btm/btm_devctl.c | 76 ++- .../bt/host/bluedroid/stack/btm/btm_main.c | 2 - .../bluedroid/stack/btm/include/btm_ble_int.h | 17 +- .../bluedroid/stack/btm/include/btm_int.h | 25 +- .../bt/host/bluedroid/stack/btu/btu_hcif.c | 63 +-- .../bt/host/bluedroid/stack/gatt/gatt_utils.c | 6 +- .../bt/host/bluedroid/stack/hcic/hciblecmds.c | 181 +++---- .../bluedroid/stack/include/stack/btm_api.h | 18 +- .../stack/include/stack/btm_ble_api.h | 81 +-- .../host/bluedroid/stack/include/stack/btu.h | 2 - .../bluedroid/stack/include/stack/hcimsgs.h | 17 +- .../bt/host/bluedroid/stack/l2cap/l2c_ble.c | 92 ++-- 28 files changed, 1000 insertions(+), 1394 deletions(-) create mode 100644 components/bt/host/bluedroid/bta/dm/include/bta_dm_gap.h 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 f7cf821980..a73436b2d1 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c @@ -39,6 +39,7 @@ #include "stack/gap_api.h" /* For GAP_BleReadPeerPrefConnParams */ #include #include "device/controller.h" +#include "bta_dm_gap.h" #define LOG_TAG "bt_bta_dm" // #include "osi/include/log.h" @@ -262,6 +263,26 @@ UINT8 *g_disc_raw_data_buf; #endif #endif ///SDP_INCLUDED == TRUE +#if (BLE_INCLUDED == TRUE) +tBTM_BLE_LEGACY_GAP_CBACK ble_legacy_gap_cb; + +void BTM_BleLegacyGapRegisterCallback(tBTM_BLE_LEGACY_GAP_CBACK cb) +{ + if (cb) { + ble_legacy_gap_cb = cb; + } else { + BTM_TRACE_ERROR("%s, register fail, the cb function is NULL.", __func__); + } +} + +void BTM_LegacyBleCallbackTrigger(tBTM_BLE_LEGACY_GAP_EVENT event, tBTM_BLE_LEGACY_GAP_CB_PARAMS *params) +{ + if (ble_legacy_gap_cb) { + ble_legacy_gap_cb(event, params); + } +} +#endif // #if (BLE_INCLUDED == TRUE) + /******************************************************************************* ** ** Function bta_dm_enable @@ -764,23 +785,31 @@ void bta_dm_send_vendor_hci(tBTA_DM_MSG *p_data) void bta_dm_ble_gap_clear_adv(tBTA_DM_MSG *p_data) { - if (BTM_BleClearAdv(p_data->ble_clear_adv.p_clear_adv_cback) == FALSE) { - if (p_data->ble_clear_adv.p_clear_adv_cback) { - (*p_data->ble_clear_adv.p_clear_adv_cback)(BTA_FAILURE); - } + if (BTM_BleClearAdv() == FALSE) { + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = BTA_FAILURE; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_CLEAR_ADV_COMPLETE_EVT, &cb_params); } } void bta_dm_ble_gap_set_csa_support(tBTA_DM_MSG *p_data) { APPL_TRACE_API("%s, csa_select = %d", __func__, p_data->ble_set_csa_support.csa_select); - BTM_BleSetCsaSupport(p_data->ble_set_csa_support.csa_select, p_data->ble_set_csa_support.p_cback); + if (BTM_BleSetCsaSupport(p_data->ble_set_csa_support.csa_select) == FALSE) { + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = BTA_FAILURE; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_SET_CSA_SUPPORT_COMPLETE_EVT, &cb_params); + } } void bta_dm_ble_gap_set_vendor_evt_mask(tBTA_DM_MSG *p_data) { APPL_TRACE_API("%s, evt_mask = %d", __func__, p_data->ble_set_vendor_evt_mask.evt_mask); - BTM_BleSetVendorEventMask(p_data->ble_set_vendor_evt_mask.evt_mask, p_data->ble_set_vendor_evt_mask.p_cback); + if (BTM_BleSetVendorEventMask(p_data->ble_set_vendor_evt_mask.evt_mask) == FALSE) { + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = BTA_FAILURE; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_SET_VENDOR_EVT_MASK_COMPLETE_EVT, &cb_params); + } } #endif // #if (BLE_VENDOR_HCI_EN == TRUE) @@ -998,21 +1027,21 @@ void bta_dm_set_min_enc_key_size (tBTA_DM_MSG *p_data) void bta_dm_ble_set_channels (tBTA_DM_MSG *p_data) { #if (BLE_INCLUDED == TRUE) - BTM_BleSetChannels (p_data->ble_set_channels.channels, p_data->ble_set_channels.set_channels_cb); + BTM_BleSetChannels (p_data->ble_set_channels.channels); #endif /// BLE_INCLUDED == TRUE } void bta_dm_update_white_list(tBTA_DM_MSG *p_data) { #if (BLE_INCLUDED == TRUE) - BTM_BleUpdateAdvWhitelist(p_data->white_list.add_remove, p_data->white_list.remote_addr, p_data->white_list.addr_type, p_data->white_list.update_wl_cb); + BTM_BleUpdateAdvWhitelist(p_data->white_list.add_remove, p_data->white_list.remote_addr, p_data->white_list.addr_type); #endif ///BLE_INCLUDED == TRUE } void bta_dm_clear_white_list(tBTA_DM_MSG *p_data) { #if (BLE_INCLUDED == TRUE) - BTM_BleClearWhitelist(p_data->white_list.update_wl_cb); + BTM_BleClearWhitelist(); #endif } @@ -5186,25 +5215,24 @@ void bta_dm_ble_set_conn_params (tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_ble_set_scan_fil_params(tBTA_DM_MSG *p_data) { - tBTA_STATUS status = BTA_FAILURE; + tBTM_STATUS status; - if (BTM_BleSetScanFilterParams (p_data->ble_set_scan_fil_params.client_if, + + status = BTM_BleSetScanFilterParams (p_data->ble_set_scan_fil_params.client_if, p_data->ble_set_scan_fil_params.scan_int, p_data->ble_set_scan_fil_params.scan_window, p_data->ble_set_scan_fil_params.scan_mode, p_data->ble_set_scan_fil_params.addr_type_own, p_data->ble_set_scan_fil_params.scan_duplicate_filter, - p_data->ble_set_scan_fil_params.scan_filter_policy, - p_data->ble_set_scan_fil_params.scan_param_setup_cback) == BTM_SUCCESS) { - status = BTA_SUCCESS; + p_data->ble_set_scan_fil_params.scan_filter_policy); - } else { + if (status != BTM_SUCCESS) { APPL_TRACE_ERROR("%s(), fail to set scan params.", __func__); } - if (p_data->ble_set_scan_fil_params.scan_param_setup_cback != NULL) { - p_data->ble_set_scan_fil_params.scan_param_setup_cback(p_data->ble_set_scan_fil_params.client_if, status); - } + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_SCAN_PARAMS_SET_COMPLETE_EVT, &cb_params); } #endif // #if (BLE_42_SCAN_EN == TRUE) @@ -5255,16 +5283,15 @@ void bta_dm_ble_set_rand_address(tBTA_DM_MSG *p_data) tBTM_STATUS status = BTM_SET_STATIC_RAND_ADDR_FAIL; if (p_data->set_addr.addr_type != BLE_ADDR_RANDOM) { APPL_TRACE_ERROR("Invalid random address type = %d\n", p_data->set_addr.addr_type); - if(p_data->set_addr.p_set_rand_addr_cback) { - (*p_data->set_addr.p_set_rand_addr_cback)(status); - } - return; + goto _addr_set_end; } //send the setting random address to BTM layer status = BTM_BleSetRandAddress(p_data->set_addr.address); - if(p_data->set_addr.p_set_rand_addr_cback) { - (*p_data->set_addr.p_set_rand_addr_cback)(status); - } + +_addr_set_end: + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_SET_RANDOM_ADDR_EVT, &cb_params); } @@ -5286,7 +5313,7 @@ void bta_dm_ble_clear_rand_address(tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_ble_config_local_privacy (tBTA_DM_MSG *p_data) { - BTM_BleConfigPrivacy (p_data->ble_local_privacy.privacy_enable, p_data->ble_local_privacy.set_local_privacy_cback); + BTM_BleConfigPrivacy (p_data->ble_local_privacy.privacy_enable); } #endif @@ -5341,10 +5368,11 @@ void bta_dm_ble_scan (tBTA_DM_MSG *p_data) APPL_TRACE_WARNING(" %s start scan failed. status=0x%x\n", __FUNCTION__, status); } - if (p_data->ble_scan.p_start_scan_cback) { - status = (status == BTM_CMD_STARTED ? BTA_SUCCESS : BTA_FAILURE); - p_data->ble_scan.p_start_scan_cback(status); - } + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + status = (status == BTM_CMD_STARTED ? BTA_SUCCESS : BTA_FAILURE); + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_SCAN_START_COMPLETE_EVT, &cb_params); + } else { bta_dm_search_cb.p_scan_cback = NULL; status = BTM_BleScan(FALSE, 0, NULL, NULL, NULL); @@ -5353,10 +5381,10 @@ void bta_dm_ble_scan (tBTA_DM_MSG *p_data) APPL_TRACE_WARNING(" %s stop scan failed, status=0x%x\n", __FUNCTION__, status); } - if (p_data->ble_scan.p_stop_scan_cback) { - status = (status == BTM_CMD_STARTED ? BTA_SUCCESS : BTA_FAILURE); - p_data->ble_scan.p_stop_scan_cback(status); - } + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + status = (status == BTM_CMD_STARTED ? BTA_SUCCESS : BTA_FAILURE); + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_SCAN_STOP_COMPLETE_EVT, &cb_params); #if (BLE_TOPOLOGY_CHECK == TRUE) // reset BLE scan link state when stop scan btm_ble_clear_topology_mask(BTM_BLE_STATE_ACTIVE_SCAN_BIT); @@ -5369,7 +5397,7 @@ void bta_dm_ble_scan (tBTA_DM_MSG *p_data) #if (BLE_42_ADV_EN == TRUE) /******************************************************************************* ** -** Function bta_dm_ble_set_adv_params_all +** Function bta_dm_ble_start_adv_with_params ** ** Description This function is called to set all of the advertising parameters. ** @@ -5378,31 +5406,28 @@ void bta_dm_ble_scan (tBTA_DM_MSG *p_data) ** Returns void ** *******************************************************************************/ -void bta_dm_ble_set_adv_params_all (tBTA_DM_MSG *p_data) +void bta_dm_ble_start_adv_with_params (tBTA_DM_MSG *p_data) { - tBTA_STATUS status = BTA_FAILURE; - if (BTM_BleSetAdvParamsAll(p_data->ble_set_adv_params_all.adv_int_min, + tBTM_STATUS status = BTA_FAILURE; + status = BTM_BleStartAdvWithParams(p_data->ble_set_adv_params_all.adv_int_min, p_data->ble_set_adv_params_all.adv_int_max, p_data->ble_set_adv_params_all.adv_type, p_data->ble_set_adv_params_all.addr_type_own, p_data->ble_set_adv_params_all.p_dir_bda, p_data->ble_set_adv_params_all.channel_map, - p_data->ble_set_adv_params_all.adv_filter_policy, - p_data->ble_set_adv_params_all.p_start_adv_cback) == BTM_SUCCESS) { - APPL_TRACE_DEBUG("%s(), success to set ble adv params.", __func__); - } else { - APPL_TRACE_ERROR("%s(), fail to set ble adv params.", __func__); - if(p_data->ble_set_adv_params_all.p_start_adv_cback) { - (*p_data->ble_set_adv_params_all.p_start_adv_cback)(status); - } - return; - } - if(BTM_BleStartAdv() == BTM_SUCCESS) { - status = BTA_SUCCESS; - } - if(p_data->ble_set_adv_params_all.p_start_adv_cback) { - (*p_data->ble_set_adv_params_all.p_start_adv_cback)(status); + p_data->ble_set_adv_params_all.adv_filter_policy); + + if (status != BTM_SUCCESS) { + APPL_TRACE_ERROR("fail to set ble adv params."); + goto _adv_param_error; } + + status = BTM_BleStartAdv(); + +_adv_param_error: + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_ADV_START_COMPLETE_EVT, &cb_params); } #endif // #if (BLE_42_ADV_EN == TRUE) @@ -5419,8 +5444,7 @@ void bta_dm_ble_update_duplicate_exceptional_list(tBTA_DM_MSG *p_data) { BTM_UpdateBleDuplicateExceptionalList(p_data->ble_duplicate_exceptional_list.subcode, p_data->ble_duplicate_exceptional_list.type, - p_data->ble_duplicate_exceptional_list.device_info, - p_data->ble_duplicate_exceptional_list.exceptional_list_cb); + p_data->ble_duplicate_exceptional_list.device_info); } #endif // ((BLE_42_SCAN_EN == TRUE) || (BLE_50_EXTEND_SCAN_EN == TRUE)) @@ -5436,16 +5460,14 @@ void bta_dm_ble_update_duplicate_exceptional_list(tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data) { - tBTA_STATUS status = BTA_FAILURE; + tBTM_STATUS status; - if (BTM_BleWriteAdvData(p_data->ble_set_adv_data.data_mask, - (tBTM_BLE_ADV_DATA *)p_data->ble_set_adv_data.p_adv_cfg) == BTM_SUCCESS) { - status = BTA_SUCCESS; - } + status = BTM_BleWriteAdvData(p_data->ble_set_adv_data.data_mask, + (tBTM_BLE_ADV_DATA *)p_data->ble_set_adv_data.p_adv_cfg); - if (p_data->ble_set_adv_data.p_adv_data_cback) { - (*p_data->ble_set_adv_data.p_adv_data_cback)(status); - } + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_ADV_DATA_SET_COMPLETE_EVT, &cb_params); } /******************************************************************************* @@ -5459,16 +5481,14 @@ void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_ble_set_adv_config_raw (tBTA_DM_MSG *p_data) { - tBTA_STATUS status = BTA_FAILURE; + tBTM_STATUS status; - if (BTM_BleWriteAdvDataRaw(p_data->ble_set_adv_data_raw.p_raw_adv, - p_data->ble_set_adv_data_raw.raw_adv_len) == BTM_SUCCESS) { - status = BTA_SUCCESS; - } + status = BTM_BleWriteAdvDataRaw(p_data->ble_set_adv_data_raw.p_raw_adv, + p_data->ble_set_adv_data_raw.raw_adv_len); - if (p_data->ble_set_adv_data_raw.p_adv_data_cback) { - (*p_data->ble_set_adv_data_raw.p_adv_data_cback)(status); - } + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_ADV_RAW_SET_COMPLETE_EVT, &cb_params); } /******************************************************************************* @@ -5482,16 +5502,14 @@ void bta_dm_ble_set_adv_config_raw (tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_ble_set_scan_rsp (tBTA_DM_MSG *p_data) { - tBTA_STATUS status = BTA_FAILURE; + tBTM_STATUS status; - if (BTM_BleWriteScanRsp(p_data->ble_set_adv_data.data_mask, - (tBTM_BLE_ADV_DATA *)p_data->ble_set_adv_data.p_adv_cfg) == BTM_SUCCESS) { - status = BTA_SUCCESS; - } + status = BTM_BleWriteScanRsp(p_data->ble_set_adv_data.data_mask, + (tBTM_BLE_ADV_DATA *)p_data->ble_set_adv_data.p_adv_cfg); - if (p_data->ble_set_adv_data.p_adv_data_cback) { - (*p_data->ble_set_adv_data.p_adv_data_cback)(status); - } + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_SCAN_RSP_SET_COMPLETE_EVT, &cb_params); } /******************************************************************************* @@ -5505,16 +5523,14 @@ void bta_dm_ble_set_scan_rsp (tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_ble_set_scan_rsp_raw (tBTA_DM_MSG *p_data) { - tBTA_STATUS status = BTA_FAILURE; + tBTM_STATUS status; - if (BTM_BleWriteScanRspRaw(p_data->ble_set_adv_data_raw.p_raw_adv, - p_data->ble_set_adv_data_raw.raw_adv_len) == BTM_SUCCESS) { - status = BTA_SUCCESS; - } + status = BTM_BleWriteScanRspRaw(p_data->ble_set_adv_data_raw.p_raw_adv, + p_data->ble_set_adv_data_raw.raw_adv_len); - if (p_data->ble_set_adv_data_raw.p_adv_data_cback) { - (*p_data->ble_set_adv_data_raw.p_adv_data_cback)(status); - } + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_RSP_RAW_SET_COMPLETE_EVT, &cb_params); } #endif // #if (BLE_42_ADV_EN == TRUE) /******************************************************************************* @@ -5532,16 +5548,19 @@ void bta_dm_ble_set_data_length(tBTA_DM_MSG *p_data) tACL_CONN *p_acl_cb = btm_bda_to_acl(p_data->ble_set_data_length.remote_bda, BT_TRANSPORT_LE); if (p_acl_cb == NULL) { APPL_TRACE_ERROR("%s error: Invalid connection remote_bda.", __func__); + uint16_t length = controller_get_interface()->get_acl_data_size_ble(); + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.data_length_params.status = BTM_UNKNOWN_ADDR; + cb_params.data_length_params.rx_len = length; + cb_params.data_length_params.tx_len = length; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_DATA_LEN_SET_COMPLETE_EVT, &cb_params); return; } - p_acl_cb->p_set_pkt_data_cback = p_data->ble_set_data_length.p_set_pkt_data_cback; // if the value of the data length is same, trigger callback directly if(p_data->ble_set_data_length.tx_data_length == p_acl_cb->data_length_params.tx_len) { - if(p_data->ble_set_data_length.p_set_pkt_data_cback) { - (*p_data->ble_set_data_length.p_set_pkt_data_cback)(status, &p_acl_cb->data_length_params); - } - return; + + goto _data_length_set_complete; } if(p_acl_cb->data_len_updating) { @@ -5550,7 +5569,6 @@ void bta_dm_ble_set_data_length(tBTA_DM_MSG *p_data) status = BTM_ILLEGAL_ACTION; } else { // save the command - p_acl_cb->p_set_data_len_cback_waiting = p_data->ble_set_data_length.p_set_pkt_data_cback; p_acl_cb->tx_len_waiting = p_data->ble_set_data_length.tx_data_length; p_acl_cb->data_len_waiting = true; return; @@ -5559,18 +5577,28 @@ void bta_dm_ble_set_data_length(tBTA_DM_MSG *p_data) status = BTM_SetBleDataLength(p_data->ble_set_data_length.remote_bda, p_data->ble_set_data_length.tx_data_length); } + if (status != BTM_SUCCESS) { APPL_TRACE_ERROR("%s failed\n", __FUNCTION__); - } - if (p_data->ble_set_data_length.p_set_pkt_data_cback && status != BTM_SUCCESS) { if (p_acl_cb->data_length_params.tx_len == 0){ uint16_t length = controller_get_interface()->get_acl_data_size_ble(); p_acl_cb->data_length_params.rx_len = length; p_acl_cb->data_length_params.tx_len = length; } - (*p_data->ble_set_data_length.p_set_pkt_data_cback)(status, &p_acl_cb->data_length_params); + + goto _data_length_set_complete; + } else { + return; } +_data_length_set_complete: + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.data_length_params.status = status; + cb_params.data_length_params.rx_len = p_acl_cb->data_length_params.rx_len; + cb_params.data_length_params.tx_len = p_acl_cb->data_length_params.tx_len; + + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_DATA_LEN_SET_COMPLETE_EVT, &cb_params); + } #if (BLE_42_ADV_EN == TRUE) @@ -5585,19 +5613,16 @@ void bta_dm_ble_set_data_length(tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_ble_advstop (tBTA_DM_MSG *p_data) { - tBTA_STATUS status = BTA_FAILURE; - BOOLEAN start = p_data->ble_adv_action.start; + tBTM_STATUS status; + status = BTM_BleAdvStop(); - tBTM_STATUS btm_status = BTM_BleBroadcast(start, p_data->ble_adv_action.p_stop_adv_cback); - if (btm_status == BTM_SUCCESS) { - status = BTA_SUCCESS; - } else { + if (status != BTM_SUCCESS) { APPL_TRACE_ERROR("%s failed\n", __FUNCTION__); } - if (p_data->ble_adv_action.p_stop_adv_cback){ - (*p_data->ble_adv_action.p_stop_adv_cback)(status); - } + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_ADV_STOP_COMPLETE_EVT, &cb_params); } #endif // #if (BLE_42_ADV_EN == TRUE) @@ -5624,7 +5649,7 @@ void bta_dm_ble_gap_dtm_stop(tBTA_DM_MSG *p_data) void bta_dm_ble_gap_set_rpa_timeout(tBTA_DM_MSG *p_data) { APPL_TRACE_API("%s, rpa_timeout = %d", __func__, p_data->set_rpa_timeout.rpa_timeout); - BTM_BleSetRpaTimeout(p_data->set_rpa_timeout.rpa_timeout,p_data->set_rpa_timeout.p_set_rpa_timeout_cback); + BTM_BleSetRpaTimeout(p_data->set_rpa_timeout.rpa_timeout); } void bta_dm_ble_gap_add_dev_to_resolving_list(tBTA_DM_MSG *p_data) @@ -5632,21 +5657,24 @@ void bta_dm_ble_gap_add_dev_to_resolving_list(tBTA_DM_MSG *p_data) APPL_TRACE_API("%s", __func__); BTM_BleAddDevToResolvingList(p_data->add_dev_to_resolving_list.addr, p_data->add_dev_to_resolving_list.addr_type, - p_data->add_dev_to_resolving_list.irk, - p_data->add_dev_to_resolving_list.p_add_dev_to_resolving_list_callback); + p_data->add_dev_to_resolving_list.irk); } void bta_dm_ble_gap_set_privacy_mode(tBTA_DM_MSG *p_data) { APPL_TRACE_API("%s, privacy_mode = %d", __func__, p_data->ble_set_privacy_mode.privacy_mode); - BTM_BleSetPrivacyMode(p_data->ble_set_privacy_mode.addr_type, p_data->ble_set_privacy_mode.addr, - p_data->ble_set_privacy_mode.privacy_mode, p_data->ble_set_privacy_mode.p_cback); + if (BTM_BleSetPrivacyMode(p_data->ble_set_privacy_mode.addr_type, p_data->ble_set_privacy_mode.addr, + p_data->ble_set_privacy_mode.privacy_mode) == FALSE) { + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = BTA_FAILURE; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_SET_PRIVACY_MODE_COMPLETE_EVT, &cb_params); + } } void bta_dm_read_ble_channel_map(tBTA_DM_MSG *p_data) { - if (p_data && p_data->ch_map.read_ch_map_cb) { - BTM_ReadChannelMap(p_data->ch_map.remote_addr, p_data->ch_map.read_ch_map_cb); + if (p_data) { + BTM_ReadChannelMap(p_data->ch_map.remote_addr); } } 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 2eedb824d9..a1eedd5a5d 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c @@ -213,20 +213,19 @@ void BTA_DmsendVendorHciCmd(UINT16 opcode, UINT8 param_len, UINT8 *p_param_buf, ** Returns None ** *******************************************************************************/ -void BTA_DmBleClearAdv (tBTA_CLEAR_ADV_CMPL_CBACK *p_clear_adv_cback) +void BTA_DmBleClearAdv (void) { tBTA_DM_API_CLEAR_ADV *p_msg; if ((p_msg = (tBTA_DM_API_CLEAR_ADV *) osi_malloc(sizeof(tBTA_DM_API_CLEAR_ADV))) != NULL) { p_msg->hdr.event = BTA_DM_API_BLE_CLEAR_ADV_EVT; - p_msg->p_clear_adv_cback = p_clear_adv_cback; bta_sys_sendmsg(p_msg); } } -void BTA_DmBleGapSetCsaSupport(uint8_t csa_select, tBTA_SET_CSA_SUPPORT_CMPL_CBACK *p_callback) +void BTA_DmBleGapSetCsaSupport(uint8_t csa_select) { tBTA_DM_API_BLE_SET_CSA_SUPPORT *p_msg; @@ -234,12 +233,11 @@ void BTA_DmBleGapSetCsaSupport(uint8_t csa_select, tBTA_SET_CSA_SUPPORT_CMPL_CBA != NULL) { p_msg->hdr.event = BTA_DM_API_BLE_SET_CSA_SUPPORT_EVT; p_msg->csa_select = csa_select; - p_msg->p_cback = p_callback; bta_sys_sendmsg(p_msg); } } -void BTA_DmBleGapSetVendorEventMask(uint32_t evt_mask, tBTA_SET_VENDOR_EVT_MASK_CBACK *p_callback) +void BTA_DmBleGapSetVendorEventMask(uint32_t evt_mask) { tBTA_DM_API_BLE_SET_VENDOR_EVT_MASK *p_msg; @@ -247,7 +245,6 @@ void BTA_DmBleGapSetVendorEventMask(uint32_t evt_mask, tBTA_SET_VENDOR_EVT_MASK_ != NULL) { p_msg->hdr.event = BTA_DM_API_BLE_SET_VENDOR_EVT_MASK_EVT; p_msg->evt_mask = evt_mask; - p_msg->p_cback = p_callback; bta_sys_sendmsg(p_msg); } } @@ -453,51 +450,44 @@ void BTA_DmGetRemoteName(BD_ADDR remote_addr, tBTA_CMPL_CB *rmt_name_cb) ** Returns void ** *******************************************************************************/ -void BTA_DmBleSetChannels(const uint8_t *channels, tBTA_CMPL_CB *set_channels_cb) +void BTA_DmBleSetChannels(const uint8_t *channels) { - tBTA_DM_API_BLE_SET_CHANNELS *p_msg; if ((p_msg = (tBTA_DM_API_BLE_SET_CHANNELS *) osi_malloc(sizeof(tBTA_DM_API_BLE_SET_CHANNELS))) != NULL) { p_msg->hdr.event = BTA_DM_API_BLE_SET_CHANNELS_EVT; - - p_msg->set_channels_cb = set_channels_cb; memcpy(p_msg->channels, channels, BLE_CHANNELS_LEN); bta_sys_sendmsg(p_msg); } - - } -void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr, tBLE_ADDR_TYPE addr_type, tBTA_UPDATE_WHITELIST_CBACK *update_wl_cb) +void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr, tBLE_ADDR_TYPE addr_type) { tBTA_DM_API_UPDATE_WHITE_LIST *p_msg; if ((p_msg = (tBTA_DM_API_UPDATE_WHITE_LIST *)osi_malloc(sizeof(tBTA_DM_API_UPDATE_WHITE_LIST))) != NULL) { p_msg->hdr.event = BTA_DM_API_UPDATE_WHITE_LIST_EVT; p_msg->add_remove = add_remove; p_msg->addr_type = addr_type; - p_msg->update_wl_cb = update_wl_cb; memcpy(p_msg->remote_addr, remote_addr, sizeof(BD_ADDR)); bta_sys_sendmsg(p_msg); } } -void BTA_DmClearWhiteList(tBTA_UPDATE_WHITELIST_CBACK *update_wl_cb) +void BTA_DmClearWhiteList(void) { tBTA_DM_API_UPDATE_WHITE_LIST *p_msg; if ((p_msg = (tBTA_DM_API_UPDATE_WHITE_LIST *)osi_malloc(sizeof(tBTA_DM_API_UPDATE_WHITE_LIST))) != NULL) { p_msg->hdr.event = BTA_DM_API_CLEAR_WHITE_LIST_EVT; - p_msg->update_wl_cb = update_wl_cb; bta_sys_sendmsg(p_msg); } } -void BTA_DmBleReadChannelMap(BD_ADDR remote_device, tBTA_CMPL_CB *p_callback) +void BTA_DmBleReadChannelMap(BD_ADDR remote_device) { - if (!remote_device || !p_callback) { + if (!remote_device) { return; } tBTA_DM_API_READ_CH_MAP *p_msg; @@ -505,7 +495,6 @@ void BTA_DmBleReadChannelMap(BD_ADDR remote_device, tBTA_CMPL_CB *p_callback) if ((p_msg = (tBTA_DM_API_READ_CH_MAP *)osi_malloc(sizeof(tBTA_DM_API_READ_CH_MAP))) != NULL) { p_msg->hdr.event = BTA_DM_API_BLE_READ_CH_MAP_EVT; memcpy(p_msg->remote_addr, remote_device, sizeof(BD_ADDR)); - p_msg->read_ch_map_cb = p_callback; bta_sys_sendmsg(p_msg); } } @@ -1453,7 +1442,7 @@ void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr, *******************************************************************************/ void BTA_DmSetBleScanFilterParams(tGATT_IF client_if, UINT32 scan_interval, UINT32 scan_window, tBLE_SCAN_MODE scan_mode, UINT8 scan_fil_poilcy, - UINT8 addr_type_own, UINT8 scan_duplicate_filter, tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback) + UINT8 addr_type_own, UINT8 scan_duplicate_filter) { tBTA_DM_API_BLE_SCAN_FILTER_PARAMS *p_msg; @@ -1467,7 +1456,6 @@ void BTA_DmSetBleScanFilterParams(tGATT_IF client_if, UINT32 scan_interval, p_msg->addr_type_own = addr_type_own; p_msg->scan_duplicate_filter = scan_duplicate_filter; p_msg->scan_filter_policy = scan_fil_poilcy; - p_msg->scan_param_setup_cback = scan_param_setup_cback; bta_sys_sendmsg(p_msg); } @@ -1477,22 +1465,21 @@ void BTA_DmSetBleScanFilterParams(tGATT_IF client_if, UINT32 scan_interval, #endif // #if (BLE_42_SCAN_EN == TRUE) #if (BLE_42_ADV_EN == TRUE) -void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max, +void BTA_DmAdvStartWithParams (UINT16 adv_int_min, UINT16 adv_int_max, UINT8 adv_type, tBLE_ADDR_TYPE addr_type_own, tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP adv_fil_pol, - tBLE_BD_ADDR *p_dir_bda, tBTA_START_ADV_CMPL_CBACK p_start_adv_cb) + tBLE_BD_ADDR *p_dir_bda) { -#if BLE_INCLUDED == TRUE tBTA_DM_API_BLE_ADV_PARAMS_ALL *p_msg; - APPL_TRACE_API ("BTA_DmSetBleAdvParamsAll: %d, %d\n", adv_int_min, adv_int_max); + APPL_TRACE_API ("BTA_DmAdvStartWithParams: %d, %d\n", adv_int_min, adv_int_max); APPL_TRACE_API ("adv_type = %d, addr_type_own = %d, chnl_map = %d, adv_fil_pol = %d\n", adv_type, addr_type_own, chnl_map, adv_fil_pol); if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS_ALL *) osi_malloc(sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL) + sizeof(tBLE_BD_ADDR))) != NULL) { memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL)); - p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_All_EVT; + p_msg->hdr.event = BTA_DM_API_BLE_ADV_START_WITH_PARAMS_EVT; p_msg->adv_int_min = adv_int_min; p_msg->adv_int_max = adv_int_max; @@ -1500,7 +1487,6 @@ void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max, p_msg->addr_type_own = addr_type_own; p_msg->channel_map = chnl_map; p_msg->adv_filter_policy = adv_fil_pol; - p_msg->p_start_adv_cback = p_start_adv_cb; if (p_dir_bda != NULL) { p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1); memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR)); @@ -1508,7 +1494,6 @@ void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max, bta_sys_sendmsg(p_msg); } -#endif } #endif // #if (BLE_42_ADV_EN == TRUE) @@ -1531,13 +1516,12 @@ void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max, ** p_adv_cfg: Pointer to User defined ADV data structure. This ** memory space can not be freed until p_adv_data_cback ** is received. -** p_adv_data_cback: set adv data complete callback. +** ** ** Returns None ** *******************************************************************************/ -void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback) +void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg) { tBTA_DM_API_SET_ADV_CONFIG *p_msg; @@ -1545,7 +1529,6 @@ void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) { p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_EVT; p_msg->data_mask = data_mask; - p_msg->p_adv_data_cback = p_adv_data_cback; p_msg->p_adv_cfg = p_adv_cfg; bta_sys_sendmsg(p_msg); @@ -1565,15 +1548,13 @@ void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv ** Returns None ** *******************************************************************************/ -void BTA_DmBleSetAdvConfigRaw (UINT8 *p_raw_adv, UINT32 raw_adv_len, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback) +void BTA_DmBleSetAdvConfigRaw (UINT8 *p_raw_adv, UINT32 raw_adv_len) { tBTA_DM_API_SET_ADV_CONFIG_RAW *p_msg; if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG_RAW *) osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW) + raw_adv_len)) != NULL) { p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_RAW_EVT; - p_msg->p_adv_data_cback = p_adv_data_cback; p_msg->p_raw_adv = (UINT8 *)(p_msg + 1); memcpy(p_msg->p_raw_adv, p_raw_adv, raw_adv_len); p_msg->raw_adv_len = raw_adv_len; @@ -1593,8 +1574,7 @@ void BTA_DmBleSetAdvConfigRaw (UINT8 *p_raw_adv, UINT32 raw_adv_len, ** Returns None ** *******************************************************************************/ -extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback) +extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv_cfg) { tBTA_DM_API_SET_ADV_CONFIG *p_msg; @@ -1602,7 +1582,6 @@ extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA * osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) { p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_EVT; p_msg->data_mask = data_mask; - p_msg->p_adv_data_cback = p_adv_data_cback; p_msg->p_adv_cfg = p_adv_cfg; bta_sys_sendmsg(p_msg); @@ -1617,20 +1596,18 @@ extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA * ** ** Parameters p_raw_scan_rsp : raw scan_rspertising data. ** raw_scan_rsp_len : raw scan_rspertising data length. -** p_scan_rsp_data_cback : set scan_rsp data complete callback. +** ** ** Returns None ** *******************************************************************************/ -void BTA_DmBleSetScanRspRaw (UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback) +void BTA_DmBleSetScanRspRaw (UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len) { tBTA_DM_API_SET_ADV_CONFIG_RAW *p_msg; if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG_RAW *) osi_malloc(sizeof(tBTA_DM_API_SET_ADV_CONFIG_RAW) + raw_scan_rsp_len)) != NULL) { p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_RAW_EVT; - p_msg->p_adv_data_cback = p_scan_rsp_data_cback; p_msg->p_raw_adv = (UINT8 *)(p_msg + 1); memcpy(p_msg->p_raw_adv, p_raw_scan_rsp, raw_scan_rsp_len); p_msg->raw_adv_len = raw_scan_rsp_len; @@ -1650,19 +1627,18 @@ void BTA_DmBleSetScanRspRaw (UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len, ** Parameters subcode : add, remove or clean duplicate scan exceptional list. ** type : device info type. ** device_info: device info -** p_update_duplicate_ignore_list_cback : update complete callback. +** ** ** Returns None ** *******************************************************************************/ -void BTA_DmUpdateDuplicateExceptionalList(UINT8 subcode, UINT32 type, BD_ADDR device_info, tBTA_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK p_update_duplicate_exceptional_list_cback) +void BTA_DmUpdateDuplicateExceptionalList(UINT8 subcode, UINT32 type, BD_ADDR device_info) { tBTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST *p_msg; if ((p_msg = (tBTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST *)osi_malloc(sizeof(tBTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST))) != NULL) { p_msg->hdr.event = BTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_EVT; p_msg->subcode = subcode; p_msg->type = type; - p_msg->exceptional_list_cb = p_update_duplicate_exceptional_list_cback; memcpy(p_msg->device_info, device_info, sizeof(BD_ADDR)); bta_sys_sendmsg(p_msg); @@ -1683,25 +1659,21 @@ void BTA_DmUpdateDuplicateExceptionalList(UINT8 subcode, UINT32 type, BD_ADDR de ** ** Description This function starts or stops LE broadcasting. ** -** Parameters start: always be false. +** Parameters void ** ** Returns None ** *******************************************************************************/ -extern void BTA_DmBleAdvStop (BOOLEAN start, tBTA_START_STOP_ADV_CMPL_CBACK *p_start_stop_adv_cb) +extern void BTA_DmBleAdvStop (void) { tBTA_DM_API_BLE_ADVACTION *p_msg; - APPL_TRACE_API("BTA_DmBleAdvStop: start = %d \n", start); + APPL_TRACE_API("BTA_DmBleAdvStop\n"); if ((p_msg = (tBTA_DM_API_BLE_ADVACTION *) osi_malloc(sizeof(tBTA_DM_API_BLE_ADVACTION))) != NULL) { memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADVACTION)); p_msg->hdr.event = BTA_DM_API_BLE_ADVSTOP_EVT; - p_msg->start = start; - if (start == FALSE){ - p_msg->p_stop_adv_cback= p_start_stop_adv_cb; - } bta_sys_sendmsg(p_msg); } @@ -1941,7 +1913,7 @@ void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int, ** Returns void ** *******************************************************************************/ -void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback) +void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable) { ///This function used the irk to generate the resolve address #if BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE @@ -1952,7 +1924,6 @@ void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_ p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT; p_msg->privacy_enable = privacy_enable; - p_msg->set_local_privacy_cback = set_local_privacy_cback; bta_sys_sendmsg(p_msg); } #else @@ -2085,7 +2056,7 @@ void BTA_DmBleDisconnect(BD_ADDR bd_addr) ** ** *******************************************************************************/ -void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length, tBTA_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback) +void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length) { tBTA_DM_API_BLE_SET_DATA_LENGTH *p_msg; @@ -2094,7 +2065,6 @@ void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length, tBTA_S bdcpy(p_msg->remote_bda, remote_device); p_msg->hdr.event = BTA_DM_API_SET_DATA_LENGTH_EVT; p_msg->tx_data_length = tx_data_length; - p_msg->p_set_pkt_data_cback = p_set_pkt_data_cback; bta_sys_sendmsg(p_msg); } @@ -2147,7 +2117,7 @@ void BTA_DmBleDtmStop(tBTA_DTM_CMD_CMPL_CBACK *p_dtm_cmpl_cback) } #endif // #if ((BLE_42_DTM_TEST_EN == TRUE) || (BLE_50_DTM_TEST_EN == TRUE)) -void BTA_DmBleSetPrivacyMode(uint8_t addr_type, BD_ADDR addr, uint8_t privacy_mode, tBTA_SET_PRIVACY_MODE_CMPL_CBACK *p_cback) +void BTA_DmBleSetPrivacyMode(uint8_t addr_type, BD_ADDR addr, uint8_t privacy_mode) { tBTA_DM_API_SET_PRIVACY_MODE *p_msg; @@ -2157,7 +2127,6 @@ void BTA_DmBleSetPrivacyMode(uint8_t addr_type, BD_ADDR addr, uint8_t privacy_mo p_msg->addr_type = addr_type; memcpy(p_msg->addr, addr, sizeof(BD_ADDR)); p_msg->privacy_mode = privacy_mode; - p_msg->p_cback = p_cback; bta_sys_sendmsg(p_msg); } } @@ -2227,8 +2196,7 @@ void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_DM_ENCR ** *******************************************************************************/ extern void BTA_DmBleScan(BOOLEAN start, UINT32 duration, - tBTA_DM_SEARCH_CBACK *p_results_cb, - tBTA_START_STOP_SCAN_CMPL_CBACK *p_start_stop_scan_cb) + tBTA_DM_SEARCH_CBACK *p_results_cb) { tBTA_DM_API_BLE_SCAN *p_msg; @@ -2241,12 +2209,6 @@ extern void BTA_DmBleScan(BOOLEAN start, UINT32 duration, p_msg->start = start; p_msg->duration = duration; p_msg->p_cback = p_results_cb; - if (start){ - p_msg->p_start_scan_cback = p_start_stop_scan_cb; - } - else { - p_msg->p_stop_scan_cback = p_start_stop_scan_cb; - } bta_sys_sendmsg(p_msg); } @@ -2265,7 +2227,7 @@ extern void BTA_DmBleScan(BOOLEAN start, UINT32 duration, ** ** *******************************************************************************/ -extern void BTA_DmSetRandAddress(BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK *p_set_rand_addr_cback) +extern void BTA_DmSetRandAddress(BD_ADDR rand_addr) { tBTA_DM_APT_SET_DEV_ADDR *p_msg; APPL_TRACE_API("set the random address "); @@ -2274,7 +2236,6 @@ extern void BTA_DmSetRandAddress(BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK *p_ memcpy(p_msg->address, rand_addr, BD_ADDR_LEN); p_msg->hdr.event = BTA_DM_API_SET_RAND_ADDR_EVT; p_msg->addr_type = BLE_ADDR_RANDOM; - p_msg->p_set_rand_addr_cback = p_set_rand_addr_cback; //start sent the msg to the bta system control module bta_sys_sendmsg(p_msg); } @@ -2295,14 +2256,13 @@ extern void BTA_DmSetRandAddress(BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK *p_ ** ** *******************************************************************************/ -void BTA_DmBleSetRpaTimeout(uint16_t rpa_timeout,tBTA_SET_RPA_TIMEOUT_CMPL_CBACK *p_set_rpa_timeout_cback) +void BTA_DmBleSetRpaTimeout(uint16_t rpa_timeout) { tBTA_DM_API_SET_RPA_TIMEOUT *p_msg; if ((p_msg = (tBTA_DM_API_SET_RPA_TIMEOUT *) osi_malloc(sizeof(tBTA_DM_API_SET_RPA_TIMEOUT))) != NULL) { memset(p_msg, 0, sizeof(tBTA_DM_API_SET_RPA_TIMEOUT)); p_msg->hdr.event = BTA_DM_API_SET_RPA_TIMEOUT_EVT; p_msg->rpa_timeout = rpa_timeout; // Assign the RPA timeout value to the message - p_msg->p_set_rpa_timeout_cback = p_set_rpa_timeout_cback; bta_sys_sendmsg(p_msg); } } @@ -2326,8 +2286,7 @@ void BTA_DmBleSetRpaTimeout(uint16_t rpa_timeout,tBTA_SET_RPA_TIMEOUT_CMPL_CBACK *******************************************************************************/ void BTA_DmBleAddDevToResolvingList(BD_ADDR addr, uint8_t addr_type, - PEER_IRK irk, - tBTA_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *add_dev_to_resolving_list_callback) + PEER_IRK irk) { tBTA_DM_API_ADD_DEV_TO_RESOLVING_LIST *p_msg; if ((p_msg = (tBTA_DM_API_ADD_DEV_TO_RESOLVING_LIST *) osi_malloc(sizeof(tBTA_DM_API_ADD_DEV_TO_RESOLVING_LIST))) != NULL) { @@ -2336,7 +2295,6 @@ void BTA_DmBleAddDevToResolvingList(BD_ADDR addr, memcpy(p_msg->addr, addr, BD_ADDR_LEN); // Copy the device address to the message p_msg->addr_type = addr_type; // Assign the address type to the message memcpy(p_msg->irk, irk, PEER_IRK_LEN); // Copy the IRK to the message - p_msg->p_add_dev_to_resolving_list_callback = add_dev_to_resolving_list_callback; bta_sys_sendmsg(p_msg); } } 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 9a6722e37f..1f8e188dbc 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_main.c @@ -158,7 +158,7 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = { bta_dm_ble_set_key_material, /* BTA_DM_API_KEY_MATERIAL_EVT */ #endif #if (BLE_42_ADV_EN == TRUE) - bta_dm_ble_set_adv_params_all, /* BTA_DM_API_BLE_ADV_PARAM_All_EVT */ + bta_dm_ble_start_adv_with_params, /* BTA_DM_API_BLE_ADV_START_WITH_PARAMS_EVT */ bta_dm_ble_set_adv_config, /* BTA_DM_API_BLE_SET_ADV_CONFIG_EVT */ /* New function to allow set raw adv data to HCI */ diff --git a/components/bt/host/bluedroid/bta/dm/include/bta_dm_gap.h b/components/bt/host/bluedroid/bta/dm/include/bta_dm_gap.h new file mode 100644 index 0000000000..35dce1be9f --- /dev/null +++ b/components/bt/host/bluedroid/bta/dm/include/bta_dm_gap.h @@ -0,0 +1,112 @@ +/****************************************************************************** + * + * Copyright (C) 2003-2012 Broadcom Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + ******************************************************************************/ + +/****************************************************************************** + * + * This is the private interface file for the BTA device manager. + * + ******************************************************************************/ +#ifndef BTA_DM_GAP_H +#define BTA_DM_GAP_H + +#include +#include "common/bt_target.h" + +#if BLE_INCLUDED == TRUE +typedef uint8_t tBTM_BLE_LEGACY_GAP_EVENT; + +typedef struct { + uint8_t status; + uint16_t rx_len; + uint16_t tx_len; +} tBTM_BLE_DATA_LEN_UP_EVT; + +typedef struct { + uint8_t status; + BD_ADDR remote_bd_addr; + uint16_t min_conn_int; + uint16_t max_conn_int; + uint16_t conn_int; + uint16_t slave_latency; + uint16_t supervision_tout; +} tBTM_BLE_CONN_PRAMS_UPDATE_EVT; + +typedef struct { + uint8_t status; + uint8_t operation; +} tBTM_BLE_WHITE_LIST_UPDATE_EVT; + +typedef struct { + tBTM_STATUS status; + uint8_t hci_status; + uint8_t channel_map[5]; + BD_ADDR rem_bda; +} tBTM_BLE_CH_MAP_EVT; + +typedef struct { + uint8_t status; + uint8_t subcode; + uint32_t length; + uint8_t *device_info; +} tBTM_BLE_EXCEPTION_LIST_UPDATE_EVT; + +typedef struct { + tBTM_STATUS status; + uint8_t hci_status; +} tBTM_BLE_SET_CHANNELS_EVT; + +typedef union { + uint8_t status; + tBTM_BLE_DATA_LEN_UP_EVT data_length_params; + tBTM_BLE_CONN_PRAMS_UPDATE_EVT conn_params_update; + tBTM_BLE_WHITE_LIST_UPDATE_EVT white_list_update; + tBTM_BLE_CH_MAP_EVT ch_map_results; + tBTM_BLE_EXCEPTION_LIST_UPDATE_EVT exception_list_up; + tBTM_BLE_SET_CHANNELS_EVT set_channels; +} tBTM_BLE_LEGACY_GAP_CB_PARAMS; + +#define BTM_BLE_LEGACY_GAP_ADV_START_COMPLETE_EVT 0x01 +#define BTM_BLE_LEGACY_GAP_ADV_STOP_COMPLETE_EVT 0x02 +#define BTM_BLE_LEGACY_GAP_ADV_DATA_SET_COMPLETE_EVT 0x03 +#define BTM_BLE_LEGACY_GAP_ADV_RAW_SET_COMPLETE_EVT 0x04 +#define BTM_BLE_LEGACY_GAP_SCAN_RSP_SET_COMPLETE_EVT 0x05 +#define BTM_BLE_LEGACY_GAP_RSP_RAW_SET_COMPLETE_EVT 0x06 +#define BTM_BLE_LEGACY_GAP_SCAN_PARAMS_SET_COMPLETE_EVT 0x07 +#define BTM_BLE_LEGACY_GAP_SCAN_START_COMPLETE_EVT 0x08 +#define BTM_BLE_LEGACY_GAP_SCAN_STOP_COMPLETE_EVT 0x09 +#define BTM_BLE_LEGACY_GAP_DATA_LEN_SET_COMPLETE_EVT 0x0A +#define BTM_BLE_LEGACY_GAP_CONNECTION_PARAMS_UPDATE_EVT 0x0B +#define BTM_BLE_LEGACY_GAP_SET_RANDOM_ADDR_EVT 0x0C +#define BTM_BLE_LEGACY_GAP_RPA_TIMEOUT_EVT 0x0D +#define BTM_BLE_LEGACY_GAP_ADD_DEV_TO_RPA_LIST_EVT 0x0E +#define BTM_BLE_LEGACY_GAP_SET_PRIVACY_EVT 0x0F +#define BTM_BLE_LEGACY_GAP_WHITE_LIST_UPDATE_EVT 0x10 +#define BTM_BLE_LEGACY_GAP_READ_CHANNEL_MAP_EVT 0x11 +#define BTM_BLE_LEGACY_GAP_EXCEPTION_LIST_UPDATE_EVT 0x12 +#define BTM_BLE_LEGACY_GAP_CLEAR_ADV_COMPLETE_EVT 0x13 +#define BTM_BLE_LEGACY_GAP_SET_CSA_SUPPORT_COMPLETE_EVT 0x14 +#define BTM_BLE_LEGACY_GAP_SET_VENDOR_EVT_MASK_COMPLETE_EVT 0x15 +#define BTM_BLE_LEGACY_GAP_SET_CHANNELS_COMPLETE_EVT 0x16 +#define BTM_BLE_LEGACY_GAP_SET_PRIVACY_MODE_COMPLETE_EVT 0x17 + +typedef void (*tBTM_BLE_LEGACY_GAP_CBACK)(tBTM_BLE_LEGACY_GAP_EVENT event, tBTM_BLE_LEGACY_GAP_CB_PARAMS *params); +void BTM_BleLegacyGapRegisterCallback(tBTM_BLE_LEGACY_GAP_CBACK cb); +void BTM_LegacyBleCallbackTrigger(tBTM_BLE_LEGACY_GAP_EVENT event, tBTM_BLE_LEGACY_GAP_CB_PARAMS *params); +#endif // #if BLE_INCLUDED == TRUE + +#endif /* BTA_DM_GAP_H */ 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 858d2fb45d..1f1f4d2996 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 @@ -152,7 +152,7 @@ enum { /*******This event added by Yulong at 2016/10/20 to support setting the ble advertising param by the APP******/ #if (BLE_42_ADV_EN == TRUE) - BTA_DM_API_BLE_ADV_PARAM_All_EVT, + BTA_DM_API_BLE_ADV_START_WITH_PARAMS_EVT, BTA_DM_API_BLE_SET_ADV_CONFIG_EVT, /* Add for set raw advertising data */ BTA_DM_API_BLE_SET_ADV_CONFIG_RAW_EVT, @@ -436,7 +436,6 @@ typedef struct { typedef struct { BT_HDR hdr; AFH_CHANNELS channels; - tBTA_CMPL_CB *set_channels_cb; }tBTA_DM_API_BLE_SET_CHANNELS; typedef struct { @@ -444,7 +443,6 @@ typedef struct { BOOLEAN add_remove; BD_ADDR remote_addr; tBLE_ADDR_TYPE addr_type; - tBTA_UPDATE_WHITELIST_CBACK *update_wl_cb; }tBTA_DM_API_UPDATE_WHITE_LIST; #if ((BLE_42_SCAN_EN == TRUE) || (BLE_50_EXTEND_SCAN_EN == TRUE)) @@ -453,7 +451,6 @@ typedef struct { UINT8 subcode; UINT32 type; BD_ADDR device_info; - tBTA_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK *exceptional_list_cb; }tBTA_DM_API_UPDATE_DUPLICATE_EXCEPTIONAL_LIST; #endif // ((BLE_42_SCAN_EN == TRUE) || (BLE_50_EXTEND_SCAN_EN == TRUE)) @@ -504,7 +501,6 @@ typedef struct { typedef struct { BT_HDR hdr; BD_ADDR remote_addr; - tBTA_CMPL_CB *read_ch_map_cb; } tBTA_DM_API_READ_CH_MAP; /* data type for BTA_DM_API_SET_VISIBILITY_EVT */ @@ -827,7 +823,6 @@ typedef struct { typedef struct { BT_HDR hdr; BOOLEAN privacy_enable; - tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback; } tBTA_DM_API_LOCAL_PRIVACY; typedef struct { @@ -843,16 +838,6 @@ typedef struct { } tBTA_DM_API_KEY_MATERIAL; #endif -/* set scan parameter for BLE connections */ -typedef struct { - BT_HDR hdr; - tBTA_GATTC_IF client_if; - UINT32 scan_int; - UINT32 scan_window; - tBLE_SCAN_MODE scan_mode; - tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback; -} tBTA_DM_API_BLE_SCAN_PARAMS; - typedef struct { BT_HDR hdr; tBTA_GATTC_IF client_if; @@ -862,14 +847,11 @@ typedef struct { UINT8 addr_type_own; UINT8 scan_duplicate_filter; UINT8 scan_filter_policy; - tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback; } tBTA_DM_API_BLE_SCAN_FILTER_PARAMS; /* Data type for start/stop observe */ typedef struct { BT_HDR hdr; - BOOLEAN start; - tBTA_START_STOP_ADV_CMPL_CBACK *p_stop_adv_cback; } tBTA_DM_API_BLE_ADVACTION; /* Data type for start/stop scan */ @@ -878,15 +860,12 @@ typedef struct { BOOLEAN start; UINT32 duration; tBTA_DM_SEARCH_CBACK *p_cback; - tBTA_START_STOP_SCAN_CMPL_CBACK *p_start_scan_cback; - tBTA_START_STOP_SCAN_CMPL_CBACK *p_stop_scan_cback; } tBTA_DM_API_BLE_SCAN; typedef struct { BT_HDR hdr; BD_ADDR remote_bda; UINT16 tx_data_length; - tBTA_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback; } tBTA_DM_API_BLE_SET_DATA_LENGTH; /* set the address for BLE device @@ -895,7 +874,6 @@ typedef struct { BT_HDR hdr; tBLE_ADDR_TYPE addr_type; BD_ADDR address; - tBTA_SET_RAND_ADDR_CBACK *p_set_rand_addr_cback; } tBTA_DM_APT_SET_DEV_ADDR; typedef struct { @@ -905,7 +883,6 @@ typedef struct { typedef struct { BT_HDR hdr; UINT16 rpa_timeout; - tBTA_SET_RPA_TIMEOUT_CMPL_CBACK *p_set_rpa_timeout_cback; } tBTA_DM_API_SET_RPA_TIMEOUT; typedef struct { @@ -913,7 +890,6 @@ typedef struct { esp_bd_addr_t addr; // Bluetooth device address UINT8 addr_type; // Type of the address UINT8 irk[PEER_IRK_LEN]; // Identity Resolving Key (IRK) - tBTA_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *p_add_dev_to_resolving_list_callback; // Callback function pointer } tBTA_DM_API_ADD_DEV_TO_RESOLVING_LIST; /* set adv parameter for BLE advertising */ @@ -926,7 +902,6 @@ typedef struct { tBTM_BLE_ADV_CHNL_MAP channel_map; tBTM_BLE_AFP adv_filter_policy; tBLE_BD_ADDR *p_dir_bda; - tBTA_START_ADV_CMPL_CBACK *p_start_adv_cback; } tBTA_DM_API_BLE_ADV_PARAMS_ALL; @@ -940,7 +915,6 @@ typedef struct { BT_HDR hdr; UINT32 data_mask; tBTA_BLE_ADV_DATA *p_adv_cfg; - tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback; } tBTA_DM_API_SET_ADV_CONFIG; /* raw scan response and raw advertising data use @@ -949,7 +923,6 @@ typedef struct { BT_HDR hdr; UINT8 *p_raw_adv; UINT32 raw_adv_len; - tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback; } tBTA_DM_API_SET_ADV_CONFIG_RAW; typedef struct { @@ -980,7 +953,6 @@ typedef struct { typedef struct { BT_HDR hdr; - tBTA_CLEAR_ADV_CMPL_CBACK *p_clear_adv_cback; } tBTA_DM_API_CLEAR_ADV; typedef struct { @@ -988,19 +960,16 @@ typedef struct { tBLE_ADDR_TYPE addr_type; BD_ADDR addr; UINT8 privacy_mode; - tBTA_SET_PRIVACY_MODE_CMPL_CBACK *p_cback; } tBTA_DM_API_SET_PRIVACY_MODE; typedef struct { BT_HDR hdr; UINT8 csa_select; - tBTA_SET_CSA_SUPPORT_CMPL_CBACK *p_cback; } tBTA_DM_API_BLE_SET_CSA_SUPPORT; typedef struct { BT_HDR hdr; UINT32 evt_mask; - tBTA_SET_VENDOR_EVT_MASK_CBACK *p_cback; } tBTA_DM_API_BLE_SET_VENDOR_EVT_MASK; #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) @@ -2313,7 +2282,7 @@ extern void bta_dm_ble_config_local_icon (tBTA_DM_MSG *p_data); #if (BT_GATTS_KEY_MATERIAL_CHAR == TRUE) extern void bta_dm_ble_set_key_material (tBTA_DM_MSG *p_data); #endif -extern void bta_dm_ble_set_adv_params_all(tBTA_DM_MSG *p_data); +extern void bta_dm_ble_start_adv_with_params(tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_adv_config_raw (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_scan_rsp (tBTA_DM_MSG *p_data); diff --git a/components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c b/components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c index 3a2f325aed..9aa81e375e 100644 --- a/components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c +++ b/components/bt/host/bluedroid/bta/gatt/bta_gattc_act.c @@ -67,7 +67,7 @@ static void bta_gattc_req_cback (UINT16 conn_id, UINT32 trans_id, tGATTS_REQ_TYP static tBTA_GATTC_FIND_SERVICE_CB bta_gattc_register_service_change_notify(UINT16 conn_id, BD_ADDR remote_bda); extern void btc_gattc_congest_callback(tBTA_GATTC *param); -extern uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK *cb); +extern uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type); static const tGATT_CBACK bta_gattc_cl_cback = { bta_gattc_conn_cback, @@ -345,7 +345,7 @@ void bta_gattc_process_api_open (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg) if (p_clreg != NULL) { if (p_msg->api_conn.own_addr_type <= BLE_ADDR_TYPE_MAX) { // update own address type for creating connection - BTM_BleUpdateOwnType(&p_msg->api_conn.own_addr_type, NULL); + BTM_BleUpdateOwnType(&p_msg->api_conn.own_addr_type); } if (p_msg->api_conn.is_direct) { if ((p_clcb = bta_gattc_find_alloc_clcb(p_msg->api_conn.client_if, 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 6913a7411e..07f2cc1f4f 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_api.h @@ -410,36 +410,14 @@ typedef struct { UINT8 tx_power; } tBTA_BLE_ADV_DATA; -typedef void (tBTA_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK) (tBTA_STATUS status, uint8_t subcode, uint32_t length, uint8_t *device_info); - -typedef void (tBTA_SET_ADV_DATA_CMPL_CBACK) (tBTA_STATUS status); +// typedef void (tBTA_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK) (tBTA_STATUS status, uint8_t subcode, uint32_t length, uint8_t *device_info); typedef tBTM_VSC_CMPL_CB tBTA_SEND_VENDOR_HCI_CMPL_CBACK; -typedef tBTM_START_ADV_CMPL_CBACK tBTA_START_ADV_CMPL_CBACK; - -typedef tBTM_START_STOP_ADV_CMPL_CBACK tBTA_START_STOP_ADV_CMPL_CBACK; - -typedef tBTM_UPDATE_WHITELIST_CBACK tBTA_UPDATE_WHITELIST_CBACK; - -typedef tBTM_SET_PKT_DATA_LENGTH_CBACK tBTA_SET_PKT_DATA_LENGTH_CBACK; +// typedef tBTM_UPDATE_WHITELIST_CBACK tBTA_UPDATE_WHITELIST_CBACK; typedef tBTM_DTM_CMD_CMPL_CBACK tBTA_DTM_CMD_CMPL_CBACK; -typedef tBTM_SET_RAND_ADDR_CBACK tBTA_SET_RAND_ADDR_CBACK; - -typedef tBTM_SET_LOCAL_PRIVACY_CBACK tBTA_SET_LOCAL_PRIVACY_CBACK; - -typedef tBTM_SET_RPA_TIMEOUT_CMPL_CBACK tBTA_SET_RPA_TIMEOUT_CMPL_CBACK; - -typedef tBTM_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK tBTA_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK; - -typedef tBTM_SET_PRIVACY_MODE_CMPL_CBACK tBTA_SET_PRIVACY_MODE_CMPL_CBACK; - -typedef tBTM_SET_CSA_SUPPORT_CMPL_CBACK tBTA_SET_CSA_SUPPORT_CMPL_CBACK; - -typedef tBTM_SET_VENDOR_EVT_MASK_CBACK tBTA_SET_VENDOR_EVT_MASK_CBACK; - typedef tBTM_CMPL_CB tBTA_CMPL_CB; typedef tBTM_VSC_CMPL tBTA_VSC_CMPL; @@ -744,7 +722,6 @@ typedef UINT8 tBTA_DM_BLE_CONN_TYPE; typedef BOOLEAN (tBTA_DM_BLE_SEL_CBACK)(BD_ADDR random_bda, UINT8 *p_remote_name); typedef tBTM_LE_UPDATE_CONN_PRAMS tBTA_LE_UPDATE_CONN_PRAMS; -typedef tBTM_UPDATE_CONN_PARAM_CBACK tBTA_UPDATE_CONN_PARAM_CBACK; /* Structure associated with BTA_DM_BLE_SEC_REQ_EVT */ @@ -1204,11 +1181,7 @@ typedef void (tBTA_BLE_SCAN_REP_CBACK) (tBTA_DM_BLE_REF_VALUE ref_value, UINT8 r UINT8 num_records, UINT16 data_len, UINT8 *p_rep_data, tBTA_STATUS status); -typedef void (tBTA_START_STOP_SCAN_CMPL_CBACK) (tBTA_STATUS status); -typedef void (tBTA_START_STOP_ADV_CMPL_CBACK) (tBTA_STATUS status); - -typedef void (tBTA_CLEAR_ADV_CMPL_CBACK) (tBTA_STATUS status); #else typedef UINT8 tBTA_DM_BLE_SEC_ACT; @@ -2007,11 +1980,11 @@ void BTA_DmSetMinEncKeySize(UINT8 key_size, tBTM_CMPL_CB *p_cb); ** Returns void ** *******************************************************************************/ -void BTA_DmBleSetChannels(const uint8_t *channels, tBTA_CMPL_CB *set_channels_cb); +void BTA_DmBleSetChannels(const uint8_t *channels); -extern void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr, tBLE_ADDR_TYPE addr_type, tBTA_UPDATE_WHITELIST_CBACK *update_wl_cb); +extern void BTA_DmUpdateWhiteList(BOOLEAN add_remove, BD_ADDR remote_addr, tBLE_ADDR_TYPE addr_type); -extern void BTA_DmClearWhiteList(tBTA_UPDATE_WHITELIST_CBACK *update_wl_cb); +extern void BTA_DmClearWhiteList(void); extern void BTA_DmBleReadAdvTxPower(tBTA_CMPL_CB *cmpl_cb); #endif ///BLE_INCLUDED == TRUE @@ -2583,26 +2556,6 @@ extern void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr, extern void BTA_DmSetBleConnScanParams(UINT32 scan_interval, UINT32 scan_window); -/******************************************************************************* -** -** Function BTA_DmSetBleScanParams -** -** Description This function is called to set scan parameters -** -** Parameters: client_if - Client IF -** scan_interval - scan interval -** scan_window - scan window -** scan_mode - scan mode -** scan_param_setup_status_cback - Set scan param status callback -** -** Returns void -** -*******************************************************************************/ -extern void BTA_DmSetBleScanParams(tGATT_IF client_if, UINT32 scan_interval, - UINT32 scan_window, tBLE_SCAN_MODE scan_mode, - tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_status_cback); - - /******************************************************************************* ** ** Function BTA_DmSetBleScanFilterParams @@ -2621,13 +2574,13 @@ extern void BTA_DmSetBleScanParams(tGATT_IF client_if, UINT32 scan_interval, *******************************************************************************/ extern void BTA_DmSetBleScanFilterParams(tGATT_IF client_if, UINT32 scan_interval, UINT32 scan_window, tBLE_SCAN_MODE scan_mode, UINT8 scan_fil_poilcy, - UINT8 addr_type_own, UINT8 scan_duplicate_filter, tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback); + UINT8 addr_type_own, UINT8 scan_duplicate_filter); -extern void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max, +extern void BTA_DmAdvStartWithParams (UINT16 adv_int_min, UINT16 adv_int_max, UINT8 adv_type, tBLE_ADDR_TYPE addr_type_own, tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP adv_fil_pol, - tBLE_BD_ADDR *p_dir_bda, tBTA_START_ADV_CMPL_CBACK p_start_adv_cb); + tBLE_BD_ADDR *p_dir_bda); /******************************************************************************* @@ -2717,25 +2670,6 @@ extern void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_DM_ENCRYPT_CBACK *p_callback, tBTA_DM_BLE_SEC_ACT sec_act); - -/******************************************************************************* -** -** Function BTA_DmBleObserve -** -** Description This procedure keep the device listening for advertising -** events from a broadcast device. -** -** Parameters start: start or stop observe. -** duration : Duration of the scan. Continuous scan if 0 is passed -** p_results_cb: Callback to be called with scan results -** -** Returns void -** -*******************************************************************************/ -extern void BTA_DmBleObserve(BOOLEAN start, UINT32 duration, - tBTA_DM_SEARCH_CBACK *p_results_cb, - tBTA_START_STOP_SCAN_CMPL_CBACK *p_start_stop_scan_cb); - /******************************************************************************* ** ** Function BTA_DmBleScan @@ -2751,17 +2685,15 @@ extern void BTA_DmBleObserve(BOOLEAN start, UINT32 duration, ** *******************************************************************************/ extern void BTA_DmBleScan(BOOLEAN start, UINT32 duration, - tBTA_DM_SEARCH_CBACK *p_results_cb, - tBTA_START_STOP_SCAN_CMPL_CBACK *p_start_stop_scan_cb); + tBTA_DM_SEARCH_CBACK *p_results_cb); -extern void BTA_DmSetRandAddress(BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK *p_set_rand_addr_cback); +extern void BTA_DmSetRandAddress(BD_ADDR rand_addr); extern void BTA_DmClearRandAddress(void); -extern void BTA_DmBleSetRpaTimeout(uint16_t rpa_timeout,tBTA_SET_RPA_TIMEOUT_CMPL_CBACK *p_set_rpa_timeout_cback); +extern void BTA_DmBleSetRpaTimeout(uint16_t rpa_timeout); extern void BTA_DmBleAddDevToResolvingList(BD_ADDR addr, uint8_t addr_type, - PEER_IRK irk, - tBTA_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *add_dev_to_resolving_list_callback); + PEER_IRK irk); #endif #if BLE_INCLUDED == TRUE @@ -2773,11 +2705,11 @@ extern void BTA_DmBleAddDevToResolvingList(BD_ADDR addr, ** Description Enable/disable privacy on the local device ** ** Parameters: privacy_enable - enable/disable privacy on remote device. -** set_local_privacy_cback -callback to be called with result +** ** Returns void ** *******************************************************************************/ -extern void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback); +extern void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable); /******************************************************************************* ** @@ -2835,8 +2767,7 @@ extern void BTA_DmBleEnableRemotePrivacy(BD_ADDR bd_addr, BOOLEAN privacy_enable ** *******************************************************************************/ extern void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, - tBTA_BLE_ADV_DATA *p_adv_cfg, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); + tBTA_BLE_ADV_DATA *p_adv_cfg); /******************************************************************************* ** @@ -2851,8 +2782,7 @@ extern void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, ** Returns None ** *******************************************************************************/ -extern void BTA_DmBleSetAdvConfigRaw (UINT8 *p_raw_adv, UINT32 raw_adv_len, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); +extern void BTA_DmBleSetAdvConfigRaw (UINT8 *p_raw_adv, UINT32 raw_adv_len); /******************************************************************************* @@ -2866,7 +2796,7 @@ extern void BTA_DmBleSetAdvConfigRaw (UINT8 *p_raw_adv, UINT32 raw_adv_len, ** Returns None ** *******************************************************************************/ -void BTA_DmBleClearAdv (tBTA_CLEAR_ADV_CMPL_CBACK *p_clear_adv_cback); +void BTA_DmBleClearAdv (void); /******************************************************************************* ** @@ -2880,8 +2810,7 @@ void BTA_DmBleClearAdv (tBTA_CLEAR_ADV_CMPL_CBACK *p_clear_adv_cback); ** *******************************************************************************/ extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, - tBTA_BLE_ADV_DATA *p_adv_cfg, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback); + tBTA_BLE_ADV_DATA *p_adv_cfg); /******************************************************************************* ** @@ -2891,13 +2820,12 @@ extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, ** ** Parameters p_raw_scan_rsp : raw scan_rspertising data. ** raw_scan_rsp_len : raw scan_rspertising data length. -** p_scan_rsp_data_cback : set scan_rsp data complete callback. +** ** ** Returns None ** *******************************************************************************/ -extern void BTA_DmBleSetScanRspRaw (UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len, - tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback); +extern void BTA_DmBleSetScanRspRaw (UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len); /******************************************************************************* ** @@ -2914,8 +2842,7 @@ extern void BTA_DmBleSetScanRspRaw (UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_l ** *******************************************************************************/ extern void BTA_DmUpdateDuplicateExceptionalList(UINT8 subcode, UINT32 type, - BD_ADDR device_info, - tBTA_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK p_update_duplicate_exceptional_list_cback); + BD_ADDR device_info); /******************************************************************************* ** @@ -2924,12 +2851,12 @@ extern void BTA_DmUpdateDuplicateExceptionalList(UINT8 subcode, UINT32 type, ** Description This function starts or stops LE broadcasting. ** ** Parameters start: start or stop broadcast. -** p_start_stop_adv_cb: stop broadcast completed event +** ** ** Returns None ** *******************************************************************************/ -extern void BTA_DmBleAdvStop (BOOLEAN start, tBTA_START_STOP_ADV_CMPL_CBACK *p_start_stop_adv_cb); +extern void BTA_DmBleAdvStop (void); /******************************************************************************* ** @@ -2969,7 +2896,7 @@ extern void BTA_DmBleDisconnect(BD_ADDR bd_addr); ** Returns void ** *******************************************************************************/ -extern void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length, tBTA_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback); +extern void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length); #if (BLE_42_DTM_TEST_EN == TRUE) extern void BTA_DmBleDtmTxStart(uint8_t tx_channel, uint8_t len_of_data, uint8_t pkt_payload, tBTA_DTM_CMD_CMPL_CBACK *p_dtm_cmpl_cback); extern void BTA_DmBleDtmRxStart(uint8_t rx_channel, tBTA_DTM_CMD_CMPL_CBACK *p_dtm_cmpl_cback); @@ -2977,11 +2904,11 @@ extern void BTA_DmBleDtmRxStart(uint8_t rx_channel, tBTA_DTM_CMD_CMPL_CBACK *p_d extern void BTA_DmBleDtmStop(tBTA_DTM_CMD_CMPL_CBACK *p_dtm_cmpl_cback); -extern void BTA_DmBleSetPrivacyMode(uint8_t addr_type, BD_ADDR addr, uint8_t privacy_mode, tBTA_SET_PRIVACY_MODE_CMPL_CBACK *p_cback); +extern void BTA_DmBleSetPrivacyMode(uint8_t addr_type, BD_ADDR addr, uint8_t privacy_mode); -extern void BTA_DmBleGapSetCsaSupport(uint8_t csa_select, tBTM_SET_CSA_SUPPORT_CMPL_CBACK *p_callback); +extern void BTA_DmBleGapSetCsaSupport(uint8_t csa_select); -extern void BTA_DmBleGapSetVendorEventMask(uint32_t evt_mask, tBTA_SET_VENDOR_EVT_MASK_CBACK *p_callback); +extern void BTA_DmBleGapSetVendorEventMask(uint32_t evt_mask); #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) void BTA_DmBleGapEnhReadTransPwrLevel(uint16_t conn_handle, uint8_t phy); diff --git a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c index de3c5e68f4..a734f99429 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -27,6 +27,7 @@ #if (BT_CONTROLLER_INCLUDED == TRUE) #include "esp_bt.h" #endif +#include "bta_dm_gap.h" #if (BLE_INCLUDED == TRUE) #if (BLE_42_FEATURE_SUPPORT == TRUE) @@ -354,7 +355,7 @@ static void btc_adv_data_callback(tBTA_STATUS status) msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_GAP_BLE; msg.act = ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT; - param.adv_data_cmpl.status = status; + param.adv_data_cmpl.status = btc_btm_status_to_esp_status(status); ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL, NULL); @@ -373,7 +374,7 @@ static void btc_scan_rsp_data_callback(tBTA_STATUS status) msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_GAP_BLE; msg.act = ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT; - param.scan_rsp_data_cmpl.status = status; + param.scan_rsp_data_cmpl.status = btc_btm_status_to_esp_status(status); ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL, NULL); @@ -392,7 +393,7 @@ static void btc_adv_data_raw_callback(tBTA_STATUS status) msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_GAP_BLE; msg.act = ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT; - param.adv_data_raw_cmpl.status = status; + param.adv_data_raw_cmpl.status = btc_btm_status_to_esp_status(status); ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL, NULL); @@ -411,7 +412,7 @@ static void btc_scan_rsp_data_raw_callback(tBTA_STATUS status) msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_GAP_BLE; msg.act = ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT; - param.scan_rsp_data_raw_cmpl.status = status; + param.scan_rsp_data_raw_cmpl.status = btc_btm_status_to_esp_status(status); ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL, NULL); @@ -421,30 +422,27 @@ static void btc_scan_rsp_data_raw_callback(tBTA_STATUS status) } } -static void btc_ble_set_adv_data(esp_ble_adv_data_t *adv_data, - tBTA_SET_ADV_DATA_CMPL_CBACK p_adv_data_cback) +static void btc_ble_set_adv_data(esp_ble_adv_data_t *adv_data) { tBTA_BLE_AD_MASK data_mask = 0; if (!adv_data->set_scan_rsp) { btc_to_bta_adv_data(adv_data, &gl_bta_adv_data, &data_mask); - BTA_DmBleSetAdvConfig(data_mask, &gl_bta_adv_data, p_adv_data_cback); + BTA_DmBleSetAdvConfig(data_mask, &gl_bta_adv_data); } else { btc_to_bta_adv_data(adv_data, &gl_bta_scan_rsp_data, &data_mask); - BTA_DmBleSetScanRsp(data_mask, &gl_bta_scan_rsp_data, p_adv_data_cback); + BTA_DmBleSetScanRsp(data_mask, &gl_bta_scan_rsp_data); } } -static void btc_ble_set_adv_data_raw(uint8_t *raw_adv, uint32_t raw_adv_len, - tBTA_SET_ADV_DATA_CMPL_CBACK p_adv_data_cback) +static void btc_ble_set_adv_data_raw(uint8_t *raw_adv, uint32_t raw_adv_len) { - BTA_DmBleSetAdvConfigRaw(raw_adv, raw_adv_len, p_adv_data_cback); + BTA_DmBleSetAdvConfigRaw(raw_adv, raw_adv_len); } -static void btc_ble_set_scan_rsp_data_raw(uint8_t *raw_scan_rsp, uint32_t raw_scan_rsp_len, - tBTA_SET_ADV_DATA_CMPL_CBACK p_scan_rsp_data_cback) +static void btc_ble_set_scan_rsp_data_raw(uint8_t *raw_scan_rsp, uint32_t raw_scan_rsp_len) { - BTA_DmBleSetScanRspRaw(raw_scan_rsp, raw_scan_rsp_len, p_scan_rsp_data_cback); + BTA_DmBleSetScanRspRaw(raw_scan_rsp, raw_scan_rsp_len); } static void btc_start_adv_callback(uint8_t status) @@ -456,7 +454,7 @@ static void btc_start_adv_callback(uint8_t status) msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_GAP_BLE; msg.act = ESP_GAP_BLE_ADV_START_COMPLETE_EVT; - param.adv_start_cmpl.status = btc_hci_to_esp_status(status); + param.adv_start_cmpl.status = btc_btm_status_to_esp_status(status); ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL, NULL); @@ -475,7 +473,7 @@ static void btc_stop_adv_callback(uint8_t status) msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_GAP_BLE; msg.act = ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT; - param.adv_stop_cmpl.status = btc_hci_to_esp_status(status); + param.adv_stop_cmpl.status = btc_btm_status_to_esp_status(status); ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL, NULL); @@ -487,7 +485,7 @@ static void btc_stop_adv_callback(uint8_t status) #endif // #if (BLE_42_ADV_EN == TRUE) #if (BLE_42_ADV_EN == TRUE) -static void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params, tBTA_START_ADV_CMPL_CBACK start_adv_cback) +static void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params) { tBLE_BD_ADDR peer_addr; esp_bt_status_t status = ESP_BT_STATUS_SUCCESS; @@ -513,14 +511,14 @@ static void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params, tBT status = ESP_BT_STATUS_PARM_INVALID; BTC_TRACE_ERROR("Invalid advertisting channel map parameters.\n"); } + if (!BLE_ISVALID_PARAM(ble_adv_params->peer_addr_type, BLE_ADDR_TYPE_PUBLIC, BLE_ADDR_TYPE_RANDOM)) { status = ESP_BT_STATUS_PARM_INVALID; BTC_TRACE_ERROR("Invalid advertisting peer address type parameters.\n"); } + if(status != ESP_BT_STATUS_SUCCESS) { - if(start_adv_cback) { - start_adv_cback(status); - } + btc_start_adv_callback(status); return; } @@ -528,14 +526,13 @@ static void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params, tBT memcpy(peer_addr.bda, ble_adv_params->peer_addr, ESP_BD_ADDR_LEN); peer_addr.type = ble_adv_params->peer_addr_type; - BTA_DmSetBleAdvParamsAll(ble_adv_params->adv_int_min, + BTA_DmAdvStartWithParams(ble_adv_params->adv_int_min, ble_adv_params->adv_int_max, ble_adv_params->adv_type, ble_adv_params->own_addr_type, ble_adv_params->channel_map, ble_adv_params->adv_filter_policy, - &peer_addr, - start_adv_cback); + &peer_addr); } #endif // #if (BLE_42_ADV_EN == TRUE) @@ -549,7 +546,7 @@ static void btc_scan_params_callback(tGATT_IF gatt_if, tBTM_STATUS status) msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_GAP_BLE; msg.act = ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT; - param.scan_param_cmpl.status = status; + param.scan_param_cmpl.status = btc_btm_status_to_esp_status(status); ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL, NULL); @@ -559,7 +556,7 @@ static void btc_scan_params_callback(tGATT_IF gatt_if, tBTM_STATUS status) } } -static void btc_ble_set_scan_params(esp_ble_scan_params_t *scan_params, tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback) +static void btc_ble_set_scan_params(esp_ble_scan_params_t *scan_params) { if (BLE_ISVALID_PARAM(scan_params->scan_interval, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) && BLE_ISVALID_PARAM(scan_params->scan_window, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) && @@ -573,8 +570,7 @@ static void btc_ble_set_scan_params(esp_ble_scan_params_t *scan_params, tBLE_SCA scan_params->scan_type, scan_params->scan_filter_policy, scan_params->own_addr_type, - scan_params->scan_duplicate, - scan_param_setup_cback); + scan_params->scan_duplicate); } else { btc_scan_params_callback(ESP_DEFAULT_GATT_IF, BTM_ILLEGAL_VALUE); } @@ -692,7 +688,7 @@ static void btc_start_scan_callback(uint8_t status) msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_GAP_BLE; msg.act = ESP_GAP_BLE_SCAN_START_COMPLETE_EVT; - param.scan_start_cmpl.status = status; + param.scan_start_cmpl.status = btc_btm_status_to_esp_status(status); ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL, NULL); @@ -711,7 +707,7 @@ static void btc_stop_scan_callback(tBTA_STATUS status) msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_GAP_BLE; msg.act = ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT; - param.scan_stop_cmpl.status = status; + param.scan_stop_cmpl.status = btc_btm_status_to_esp_status(status); ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL, NULL); @@ -747,14 +743,14 @@ void btc_update_duplicate_exceptional_list_callback(tBTA_STATUS status, uint8_t } } -static void btc_ble_update_duplicate_exceptional_list(uint8_t subcode, uint32_t info_type, BD_ADDR device_info, - tBTA_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK p_update_duplicate_ignore_list_cback) +static void btc_ble_update_duplicate_exceptional_list(uint8_t subcode, uint32_t info_type, BD_ADDR device_info) { - BTA_DmUpdateDuplicateExceptionalList(subcode, info_type, device_info, p_update_duplicate_ignore_list_cback); + BTA_DmUpdateDuplicateExceptionalList(subcode, info_type, device_info); } #endif // ((BLE_42_SCAN_EN == TRUE) || (BLE_50_EXTEND_SCAN_EN == TRUE)) -void btc_update_conn_param_callback (UINT8 status, BD_ADDR bd_addr, tBTM_LE_UPDATE_CONN_PRAMS *update_conn_params) +void btc_update_conn_param_callback (UINT8 status, BD_ADDR bd_addr, UINT16 min_conn_int, UINT16 max_conn_int, + UINT16 conn_int, UINT16 slave_latency, UINT16 supervision_tout) { esp_ble_gap_cb_param_t param; bt_status_t ret; @@ -763,11 +759,11 @@ void btc_update_conn_param_callback (UINT8 status, BD_ADDR bd_addr, tBTM_LE_UPDA msg.pid = BTC_PID_GAP_BLE; msg.act = ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT; param.update_conn_params.status = btc_hci_to_esp_status(status); - param.update_conn_params.min_int = update_conn_params->min_conn_int; - param.update_conn_params.max_int = update_conn_params->max_conn_int; - param.update_conn_params.conn_int = update_conn_params->conn_int; - param.update_conn_params.latency = update_conn_params->slave_latency; - param.update_conn_params.timeout = update_conn_params->supervision_tout; + param.update_conn_params.min_int = min_conn_int; + param.update_conn_params.max_int = max_conn_int; + param.update_conn_params.conn_int = conn_int; + param.update_conn_params.latency = slave_latency; + param.update_conn_params.timeout = supervision_tout; memcpy(param.update_conn_params.bda, bd_addr, sizeof(esp_bd_addr_t)); ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL, NULL); @@ -777,7 +773,7 @@ void btc_update_conn_param_callback (UINT8 status, BD_ADDR bd_addr, tBTM_LE_UPDA } } -static void btc_set_pkt_length_callback(UINT8 status, tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS *data_len_params) +static void btc_set_pkt_length_callback(UINT8 status, UINT16 rx_len, UINT16 tx_len) { esp_ble_gap_cb_param_t param; bt_status_t ret; @@ -786,8 +782,8 @@ static void btc_set_pkt_length_callback(UINT8 status, tBTM_LE_SET_PKT_DATA_LENGT msg.pid = BTC_PID_GAP_BLE; msg.act = ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT; param.pkt_data_length_cmpl.status = btc_btm_status_to_esp_status(status); - param.pkt_data_length_cmpl.params.rx_len = data_len_params->rx_len; - param.pkt_data_length_cmpl.params.tx_len = data_len_params->tx_len; + param.pkt_data_length_cmpl.params.rx_len = rx_len; + param.pkt_data_length_cmpl.params.tx_len = tx_len; ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL, NULL); @@ -796,9 +792,8 @@ static void btc_set_pkt_length_callback(UINT8 status, tBTM_LE_SET_PKT_DATA_LENGT } } -static void btc_gap_ble_set_channels_cmpl_callback(void *p_data) +static void btc_gap_ble_set_channels_cmpl_callback(tBTM_STATUS status) { - tBTA_BLE_SET_CHANNELS_RESULTS *result = (tBTA_BLE_SET_CHANNELS_RESULTS *)p_data; esp_ble_gap_cb_param_t param; bt_status_t ret; btc_msg_t msg = {0}; @@ -806,7 +801,7 @@ static void btc_gap_ble_set_channels_cmpl_callback(void *p_data) msg.pid = BTC_PID_GAP_BLE; msg.act = ESP_GAP_BLE_SET_CHANNELS_EVT; - param.ble_set_channels.stat = btc_btm_status_to_esp_status(result->status); + param.ble_set_channels.stat = btc_btm_status_to_esp_status(status); ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL, NULL); @@ -958,6 +953,106 @@ static void btc_ble_read_channel_map_callback(void *p_data) } } +#if (BLE_VENDOR_HCI_EN == TRUE) +static void btc_clear_adv_callback(uint8_t status); +static void btc_ble_set_csa_support_callback(UINT8 status); +static void btc_ble_set_vendor_evt_mask_callback(UINT8 status); +#endif // #if (BLE_VENDOR_HCI_EN == TRUE) +static void btc_ble_set_privacy_mode_callback(UINT8 status); + +void btc_ble_legacy_gap_callback(tBTM_BLE_LEGACY_GAP_EVENT event, tBTM_BLE_LEGACY_GAP_CB_PARAMS *params) +{ + switch(event) { +#if (BLE_42_ADV_EN == TRUE) + case BTM_BLE_LEGACY_GAP_ADV_DATA_SET_COMPLETE_EVT: + btc_adv_data_callback(params->status); + break; + case BTM_BLE_LEGACY_GAP_ADV_RAW_SET_COMPLETE_EVT: + btc_adv_data_raw_callback(params->status); + break; + case BTM_BLE_LEGACY_GAP_SCAN_RSP_SET_COMPLETE_EVT: + btc_scan_rsp_data_callback(params->status); + break; + case BTM_BLE_LEGACY_GAP_RSP_RAW_SET_COMPLETE_EVT: + btc_scan_rsp_data_raw_callback(params->status); + break; + case BTM_BLE_LEGACY_GAP_ADV_START_COMPLETE_EVT: + btc_start_adv_callback(params->status); + break; + case BTM_BLE_LEGACY_GAP_ADV_STOP_COMPLETE_EVT: + btc_stop_adv_callback(params->status); + break; +#endif // #if (BLE_42_ADV_EN == TRUE) +#if (BLE_42_SCAN_EN == TRUE) + case BTM_BLE_LEGACY_GAP_SCAN_PARAMS_SET_COMPLETE_EVT: + btc_scan_params_callback(ESP_DEFAULT_GATT_IF, params->status); + break; + case BTM_BLE_LEGACY_GAP_SCAN_START_COMPLETE_EVT: + btc_start_scan_callback(params->status); + break; + case BTM_BLE_LEGACY_GAP_SCAN_STOP_COMPLETE_EVT: + btc_stop_scan_callback(params->status); + break; +#endif // #if (BLE_42_SCAN_EN == TRUE) + case BTM_BLE_LEGACY_GAP_DATA_LEN_SET_COMPLETE_EVT: + btc_set_pkt_length_callback(params->data_length_params.status, + params->data_length_params.rx_len, + params->data_length_params.tx_len); + break; + case BTM_BLE_LEGACY_GAP_CONNECTION_PARAMS_UPDATE_EVT: + btc_update_conn_param_callback(params->conn_params_update.status, + params->conn_params_update.remote_bd_addr, + params->conn_params_update.min_conn_int, + params->conn_params_update.max_conn_int, + params->conn_params_update.conn_int, + params->conn_params_update.slave_latency, + params->conn_params_update.supervision_tout); + break; + case BTM_BLE_LEGACY_GAP_SET_RANDOM_ADDR_EVT: + btc_set_rand_addr_callback(params->status); + break; + case BTM_BLE_LEGACY_GAP_RPA_TIMEOUT_EVT: + btc_set_rpa_timeout_callback(params->status); + break; + case BTM_BLE_LEGACY_GAP_ADD_DEV_TO_RPA_LIST_EVT: + btc_add_dev_to_resolving_list_callback(params->status); + break; + case BTM_BLE_LEGACY_GAP_SET_PRIVACY_EVT: + btc_set_local_privacy_callback(params->status); + break; + case BTM_BLE_LEGACY_GAP_WHITE_LIST_UPDATE_EVT: + btc_update_whitelist_complete_callback(params->white_list_update.status, params->white_list_update.operation); + break; + case BTM_BLE_LEGACY_GAP_READ_CHANNEL_MAP_EVT: + btc_ble_read_channel_map_callback(¶ms->ch_map_results); + break; + case BTM_BLE_LEGACY_GAP_EXCEPTION_LIST_UPDATE_EVT: +#if ((BLE_42_SCAN_EN == TRUE) || (BLE_50_EXTEND_SCAN_EN == TRUE)) + btc_update_duplicate_exceptional_list_callback(params->exception_list_up.status, params->exception_list_up.subcode, params->exception_list_up.length, params->exception_list_up.device_info); +#endif // #if ((BLE_42_SCAN_EN == TRUE) || (BLE_50_EXTEND_SCAN_EN == TRUE)) + break; +#if (BLE_VENDOR_HCI_EN == TRUE) + case BTM_BLE_LEGACY_GAP_CLEAR_ADV_COMPLETE_EVT: + btc_clear_adv_callback(params->status); + break; + case BTM_BLE_LEGACY_GAP_SET_CSA_SUPPORT_COMPLETE_EVT: + btc_ble_set_csa_support_callback(params->status); + break; + case BTM_BLE_LEGACY_GAP_SET_VENDOR_EVT_MASK_COMPLETE_EVT: + btc_ble_set_vendor_evt_mask_callback(params->status); + break; +#endif // #if (BLE_VENDOR_HCI_EN == TRUE) + case BTM_BLE_LEGACY_GAP_SET_CHANNELS_COMPLETE_EVT: + btc_gap_ble_set_channels_cmpl_callback(params->set_channels.status); + break; + case BTM_BLE_LEGACY_GAP_SET_PRIVACY_MODE_COMPLETE_EVT: + btc_ble_set_privacy_mode_callback(params->status); + break; + default: + BTC_TRACE_ERROR("%s: Unknown event %d\n", __func__, event); + break; + } +} #if (BLE_50_FEATURE_SUPPORT == TRUE) void btc_ble_5_gap_callback(tBTA_DM_BLE_5_GAP_EVENT event, @@ -1797,30 +1892,26 @@ void btc_get_whitelist_size(uint16_t *length) #if (BLE_42_FEATURE_SUPPORT == TRUE) #if (BLE_42_SCAN_EN == TRUE) static void btc_ble_start_scanning(uint32_t duration, - tBTA_DM_SEARCH_CBACK *results_cb, - tBTA_START_STOP_SCAN_CMPL_CBACK *start_scan_cb) + tBTA_DM_SEARCH_CBACK *results_cb) { - if ((results_cb != NULL) && (start_scan_cb != NULL)) { + if (results_cb != NULL) { //Start scan the device - BTA_DmBleScan(true, duration, results_cb, start_scan_cb); + BTA_DmBleScan(true, duration, results_cb); } else { - BTC_TRACE_ERROR("The start_scan_cb or results_cb invalid\n"); + BTC_TRACE_ERROR("The results_cb invalid\n"); } } -static void btc_ble_stop_scanning(tBTA_START_STOP_SCAN_CMPL_CBACK *stop_scan_cb) +static void btc_ble_stop_scanning(void) { - uint8_t duration = 0; - BTA_DmBleScan(false, duration, NULL, stop_scan_cb); + BTA_DmBleScan(false, 0, NULL); } #endif // #if (BLE_42_SCAN_EN == TRUE) #if (BLE_42_ADV_EN == TRUE) -static void btc_ble_stop_advertising(tBTA_START_STOP_ADV_CMPL_CBACK *stop_adv_cb) +static void btc_ble_stop_advertising(void) { - bool stop_adv = false; - - BTA_DmBleAdvStop(stop_adv, stop_adv_cb); + BTA_DmBleAdvStop(); } #endif // #if (BLE_42_ADV_EN == TRUE) @@ -1840,7 +1931,7 @@ static void btc_ble_update_conn_params(BD_ADDR bd_addr, uint16_t min_int, latency, timeout); } -static void btc_ble_set_pkt_data_len(BD_ADDR remote_device, uint16_t tx_data_length, tBTA_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback) +static void btc_ble_set_pkt_data_len(BD_ADDR remote_device, uint16_t tx_data_length) { if (tx_data_length > BTM_BLE_DATA_SIZE_MAX) { tx_data_length = BTM_BLE_DATA_SIZE_MAX; @@ -1848,7 +1939,7 @@ static void btc_ble_set_pkt_data_len(BD_ADDR remote_device, uint16_t tx_data_len tx_data_length = BTM_BLE_DATA_SIZE_MIN; } - BTA_DmBleSetDataLength(remote_device, tx_data_length, p_set_pkt_data_cback); + BTA_DmBleSetDataLength(remote_device, tx_data_length); } static void btc_ble_config_local_icon(uint16_t icon) @@ -1856,8 +1947,9 @@ static void btc_ble_config_local_icon(uint16_t icon) BTA_DmBleConfigLocalIcon(icon); } -static void btc_ble_set_rand_addr (BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK *p_set_rand_addr_cback) +static void btc_ble_set_rand_addr (BD_ADDR rand_addr) { + bool is_addr_valid = false; if (rand_addr != NULL) { /* A static address is a 48-bit randomly generated address and shall meet the following requirements: @@ -1876,40 +1968,47 @@ static void btc_ble_set_rand_addr (BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK * if((rand_addr[0] & BT_STATIC_RAND_ADDR_MASK) == BT_STATIC_RAND_ADDR_MASK) { invalid_rand_addr_b[0] = invalid_rand_addr_b[0] | BT_STATIC_RAND_ADDR_MASK; if (memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) != 0 && memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) != 0) { - BTA_DmSetRandAddress(rand_addr, btc_set_rand_addr_callback); + is_addr_valid = true; } else { - btc_set_rand_addr_callback(BTM_INVALID_STATIC_RAND_ADDR); + is_addr_valid = false; BTC_TRACE_ERROR("Invalid static random address, the high bit should be 0b11, bits of the random part shall not be all 1 or 0"); } } else if ((rand_addr[0] | BT_NON_RPA_MASK) == BT_NON_RPA_MASK) { invalid_rand_addr_a[0] = invalid_rand_addr_a[0] & BT_NON_RPA_MASK; if (memcmp(invalid_rand_addr_a, rand_addr, BD_ADDR_LEN) != 0 && memcmp(invalid_rand_addr_b, rand_addr, BD_ADDR_LEN) != 0) { - BTA_DmSetRandAddress(rand_addr, btc_set_rand_addr_callback); + is_addr_valid = true; } else { - btc_set_rand_addr_callback(BTM_INVALID_STATIC_RAND_ADDR); + is_addr_valid = false; BTC_TRACE_ERROR("Invalid non-resolvable private address, the high bit should be 0b00, bits of the random part shall not be all 1 or 0"); } }else { - btc_set_rand_addr_callback(BTM_INVALID_STATIC_RAND_ADDR); + is_addr_valid = false; BTC_TRACE_ERROR("Invalid random address type"); } } else { - btc_set_rand_addr_callback(BTM_INVALID_STATIC_RAND_ADDR); + is_addr_valid = false; BTC_TRACE_ERROR("Invalid address, the address value is NULL"); } + + if (is_addr_valid) + { + BTA_DmSetRandAddress(rand_addr); + } else { + btc_set_rand_addr_callback(BTM_INVALID_STATIC_RAND_ADDR); + } + } -static void btc_ble_set_rpa_timeout(uint16_t rpa_timeout,tBTA_SET_RPA_TIMEOUT_CMPL_CBACK *set_rpa_timeout_cback) +static void btc_ble_set_rpa_timeout(uint16_t rpa_timeout) { - BTA_DmBleSetRpaTimeout(rpa_timeout,set_rpa_timeout_cback); + BTA_DmBleSetRpaTimeout(rpa_timeout); } static void btc_ble_add_device_to_resolving_list(BD_ADDR addr, uint8_t addr_type, - uint8_t irk[], - tBTA_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *add_dev_to_resolving_list_callback) + uint8_t irk[]) { - BTA_DmBleAddDevToResolvingList(addr, addr_type, irk, add_dev_to_resolving_list_callback); + BTA_DmBleAddDevToResolvingList(addr, addr_type, irk); } static void btc_ble_clear_rand_addr (void) @@ -1917,9 +2016,9 @@ static void btc_ble_clear_rand_addr (void) BTA_DmClearRandAddress(); } -static void btc_ble_config_local_privacy(bool privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback) +static void btc_ble_config_local_privacy(bool privacy_enable) { - BTA_DmBleConfigLocalPrivacy(privacy_enable, set_local_privacy_cback); + BTA_DmBleConfigLocalPrivacy(privacy_enable); } static void btc_ble_disconnect(BD_ADDR bd_addr) @@ -1929,7 +2028,7 @@ static void btc_ble_disconnect(BD_ADDR bd_addr) static void btc_gap_ble_set_channels(esp_gap_ble_channels channels) { - BTA_DmBleSetChannels(channels, btc_gap_ble_set_channels_cmpl_callback); + BTA_DmBleSetChannels(channels); } #if (BLE_42_DTM_TEST_EN == TRUE) @@ -1974,10 +2073,9 @@ static void btc_ble_dtm_stop(tBTA_DTM_CMD_CMPL_CBACK *p_dtm_cmpl_cback) #endif // #if ((BLE_42_DTM_TEST_EN == TRUE) || (BLE_50_DTM_TEST_EN == TRUE)) static void btc_ble_set_privacy_mode(uint8_t addr_type, BD_ADDR addr, - uint8_t privacy_mode, - tBTA_SET_PRIVACY_MODE_CMPL_CBACK *p_cback) + uint8_t privacy_mode) { - BTA_DmBleSetPrivacyMode(addr_type, addr, privacy_mode, p_cback); + BTA_DmBleSetPrivacyMode(addr_type, addr, privacy_mode); } void btc_gap_ble_cb_handler(btc_msg_t *msg) @@ -2616,31 +2714,27 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) #if (BLE_42_FEATURE_SUPPORT == TRUE) #if (BLE_42_ADV_EN == TRUE) case BTC_GAP_BLE_ACT_CFG_ADV_DATA: { - if (arg->cfg_adv_data.adv_data.set_scan_rsp == false) { - btc_ble_set_adv_data(&arg->cfg_adv_data.adv_data, btc_adv_data_callback); - } else { - btc_ble_set_adv_data(&arg->cfg_adv_data.adv_data, btc_scan_rsp_data_callback); - } + btc_ble_set_adv_data(&arg->cfg_adv_data.adv_data); break; } #endif // #if (BLE_42_ADV_EN == TRUE) #if (BLE_42_SCAN_EN == TRUE) case BTC_GAP_BLE_ACT_SET_SCAN_PARAM: - btc_ble_set_scan_params(&arg->set_scan_param.scan_params, btc_scan_params_callback); + btc_ble_set_scan_params(&arg->set_scan_param.scan_params); break; case BTC_GAP_BLE_ACT_START_SCAN: - btc_ble_start_scanning(arg->start_scan.duration, btc_search_callback, btc_start_scan_callback); + btc_ble_start_scanning(arg->start_scan.duration, btc_search_callback); break; case BTC_GAP_BLE_ACT_STOP_SCAN: - btc_ble_stop_scanning(btc_stop_scan_callback); + btc_ble_stop_scanning(); break; #endif // #if (BLE_42_SCAN_EN == TRUE) #if (BLE_42_ADV_EN == TRUE) case BTC_GAP_BLE_ACT_START_ADV: - btc_ble_start_advertising(&arg->start_adv.adv_params, btc_start_adv_callback); + btc_ble_start_advertising(&arg->start_adv.adv_params); break; case BTC_GAP_BLE_ACT_STOP_ADV: - btc_ble_stop_advertising(btc_stop_adv_callback); + btc_ble_stop_advertising(); break; #endif // #if (BLE_42_ADV_EN == TRUE) #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE) @@ -2652,23 +2746,22 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) arg->conn_update_params.conn_params.timeout); break; case BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN: - btc_ble_set_pkt_data_len(arg->set_pkt_data_len.remote_device, arg->set_pkt_data_len.tx_data_length, btc_set_pkt_length_callback); + btc_ble_set_pkt_data_len(arg->set_pkt_data_len.remote_device, arg->set_pkt_data_len.tx_data_length); break; case BTC_GAP_BLE_ACT_SET_RAND_ADDRESS: { BD_ADDR bd_addr; memcpy(bd_addr, arg->set_rand_addr.rand_addr, sizeof(BD_ADDR)); - btc_ble_set_rand_addr(bd_addr, btc_set_rand_addr_callback); + btc_ble_set_rand_addr(bd_addr); break; } case BTC_GAP_BLE_ACT_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT: { - btc_ble_set_rpa_timeout(arg->set_rpa_timeout.rpa_timeout,btc_set_rpa_timeout_callback); + btc_ble_set_rpa_timeout(arg->set_rpa_timeout.rpa_timeout); break; } case BTC_GAP_BLE_ACT_ADD_DEVICE_TO_RESOLVING_LIST: { btc_ble_add_device_to_resolving_list(arg->add_dev_to_resolving_list.addr, arg->add_dev_to_resolving_list.addr_type, - arg->add_dev_to_resolving_list.irk, - btc_add_dev_to_resolving_list_callback); + arg->add_dev_to_resolving_list.irk); break; } case BTC_GAP_BLE_ACT_CLEAR_RAND_ADDRESS: { @@ -2676,22 +2769,22 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) break; } case BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY: - btc_ble_config_local_privacy(arg->cfg_local_privacy.privacy_enable, btc_set_local_privacy_callback); + btc_ble_config_local_privacy(arg->cfg_local_privacy.privacy_enable); break; case BTC_GAP_BLE_ACT_CONFIG_LOCAL_ICON: btc_ble_config_local_icon(arg->cfg_local_icon.icon); break; case BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST: - BTA_DmUpdateWhiteList(arg->update_white_list.add_remove, arg->update_white_list.remote_bda, arg->update_white_list.wl_addr_type, btc_update_whitelist_complete_callback); + BTA_DmUpdateWhiteList(arg->update_white_list.add_remove, arg->update_white_list.remote_bda, arg->update_white_list.wl_addr_type); break; case BTC_GAP_BLE_ACT_CLEAR_WHITE_LIST: - BTA_DmClearWhiteList(btc_update_whitelist_complete_callback); + BTA_DmClearWhiteList(); break; case BTC_GAP_BLE_ACT_READ_RSSI: BTA_DmReadRSSI(arg->read_rssi.remote_addr, BTA_TRANSPORT_LE, btc_read_ble_rssi_cmpl_callback); break; case BTC_GAP_BLE_READ_CHANNEL_MAP: - BTA_DmBleReadChannelMap(arg->read_channel_map.bd_addr, btc_ble_read_channel_map_callback); + BTA_DmBleReadChannelMap(arg->read_channel_map.bd_addr); break; #if (BLE_42_FEATURE_SUPPORT == TRUE) case BTC_GAP_BLE_ACT_SET_CONN_PARAMS: @@ -2710,13 +2803,11 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) #if (BLE_42_ADV_EN == TRUE) case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW: btc_ble_set_adv_data_raw(arg->cfg_adv_data_raw.raw_adv, - arg->cfg_adv_data_raw.raw_adv_len, - btc_adv_data_raw_callback); + arg->cfg_adv_data_raw.raw_adv_len); break; case BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW: btc_ble_set_scan_rsp_data_raw(arg->cfg_scan_rsp_data_raw.raw_scan_rsp, - arg->cfg_scan_rsp_data_raw.raw_scan_rsp_len, - btc_scan_rsp_data_raw_callback); + arg->cfg_scan_rsp_data_raw.raw_scan_rsp_len); break; #endif // #if (BLE_42_ADV_EN == TRUE) #endif // #if (BLE_42_FEATURE_SUPPORT == TRUE) @@ -2725,8 +2816,7 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) case BTC_GAP_BLE_UPDATE_DUPLICATE_SCAN_EXCEPTIONAL_LIST: btc_ble_update_duplicate_exceptional_list(arg->update_duplicate_exceptional_list.subcode, arg->update_duplicate_exceptional_list.info_type, - arg->update_duplicate_exceptional_list.device_info, - btc_update_duplicate_exceptional_list_callback); + arg->update_duplicate_exceptional_list.device_info); break; #endif // ((BLE_42_SCAN_EN == TRUE) || (BLE_50_EXTEND_SCAN_EN == TRUE)) @@ -3117,11 +3207,11 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) #endif // #if (BLE_50_DTM_TEST_EN == TRUE) case BTC_GAP_BLE_SET_PRIVACY_MODE: btc_ble_set_privacy_mode(arg->set_privacy_mode.addr_type, arg->set_privacy_mode.addr, - arg->set_privacy_mode.privacy_mode, btc_ble_set_privacy_mode_callback); + arg->set_privacy_mode.privacy_mode); break; #if (BLE_VENDOR_HCI_EN == TRUE) case BTC_GAP_BLE_ACT_CLEAR_ADV: - BTA_DmBleClearAdv(btc_clear_adv_callback); + BTA_DmBleClearAdv(); break; case BTC_GAP_BLE_ACT_VENDOR_HCI_CMD_EVT: BTA_DmsendVendorHciCmd(arg->vendor_cmd_send.opcode, @@ -3130,10 +3220,10 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) btc_ble_vendor_hci_cmd_complete_callback); break; case BTC_GAP_BLE_SET_CSA_SUPPORT: - BTA_DmBleGapSetCsaSupport(arg->set_csa_support.csa_select, btc_ble_set_csa_support_callback); + BTA_DmBleGapSetCsaSupport(arg->set_csa_support.csa_select); break; case BTC_GAP_BLE_ACT_SET_VENDOR_EVT_MASK: - BTA_DmBleGapSetVendorEventMask(arg->set_vendor_evt_mask.evt_mask, btc_ble_set_vendor_evt_mask_callback); + BTA_DmBleGapSetVendorEventMask(arg->set_vendor_evt_mask.evt_mask); break; #endif // #if (BLE_VENDOR_HCI_EN == TRUE) #if (BLE_FEAT_POWER_CONTROL_EN == TRUE) @@ -3235,11 +3325,12 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) //register connection parameter update callback void btc_gap_callback_init(void) { - BTM_BleRegiseterPktLengthChangeCallback(btc_set_pkt_length_callback); - BTM_BleRegiseterConnParamCallback(btc_update_conn_param_callback); #if (BLE_50_FEATURE_SUPPORT == TRUE) BTM_BleGapRegisterCallback(btc_ble_5_gap_callback); #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) + + BTM_BleLegacyGapRegisterCallback(btc_ble_legacy_gap_callback); + #if (BLE_VENDOR_HCI_EN == TRUE) BTM_BleRegisterVendorHciEventCallback(btc_ble_vendor_hci_event_callback); #endif // #if (BLE_VENDOR_HCI_EN == TRUE) diff --git a/components/bt/host/bluedroid/hci/hci_layer.c b/components/bt/host/bluedroid/hci/hci_layer.c index 30284f3c90..4bf553d0ce 100644 --- a/components/bt/host/bluedroid/hci/hci_layer.c +++ b/components/bt/host/bluedroid/hci/hci_layer.c @@ -199,7 +199,7 @@ static int hci_layer_init_env(void) HCI_TRACE_ERROR("%s unable to create command response timer.", __func__); return -1; } -#if (BLE_50_FEATURE_SUPPORT == TRUE) +#if ((BLE_50_FEATURE_SUPPORT == TRUE) || (BLE_42_FEATURE_SUPPORT == TRUE)) btsnd_hcic_ble_sync_sem_init(); #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) @@ -225,9 +225,9 @@ static void hci_layer_deinit_env(void) osi_mutex_free(&cmd_wait_q->commands_pending_response_lock); osi_alarm_free(cmd_wait_q->command_response_timer); cmd_wait_q->command_response_timer = NULL; -#if (BLE_50_FEATURE_SUPPORT == TRUE) +#if ((BLE_50_FEATURE_SUPPORT == TRUE) || (BLE_42_FEATURE_SUPPORT == TRUE)) btsnd_hcic_ble_sync_sem_deinit(); -#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) +#endif // ((BLE_50_FEATURE_SUPPORT == TRUE) || (BLE_42_FEATURE_SUPPORT == TRUE)) } static void hci_downstream_data_handler(void *arg) @@ -481,7 +481,7 @@ static bool filter_incoming_event(BT_HDR *packet) metadata = (hci_cmd_metadata_t *)(wait_entry->data); if (metadata->command_complete_cb) { metadata->command_complete_cb(packet, metadata->context); -#if (BLE_50_FEATURE_SUPPORT == TRUE) +#if ((BLE_50_FEATURE_SUPPORT == TRUE) || (BLE_42_FEATURE_SUPPORT == TRUE)) BlE_SYNC *sync_info = btsnd_hcic_ble_get_sync_info(); if(!sync_info) { HCI_TRACE_WARNING("%s sync_info is NULL. opcode = 0x%x", __func__, opcode); @@ -491,7 +491,7 @@ static bool filter_incoming_event(BT_HDR *packet) sync_info->opcode = 0; } } -#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) +#endif // #if ((BLE_50_FEATURE_SUPPORT == TRUE) || (BLE_42_FEATURE_SUPPORT == TRUE)) } else if (metadata->flags_vnd & HCI_CMD_MSG_F_VND_FUTURE) { future_ready((future_t *)(metadata->complete_future), packet); } diff --git a/components/bt/host/bluedroid/stack/btm/btm_acl.c b/components/bt/host/bluedroid/stack/btm/btm_acl.c index 6d53ba49b0..45e80f9ce8 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_acl.c +++ b/components/bt/host/bluedroid/stack/btm/btm_acl.c @@ -49,6 +49,7 @@ #include "stack/hcidefs.h" //#include "bt_utils.h" #include "osi/list.h" +#include "bta_dm_gap.h" static void btm_read_remote_features (UINT16 handle); static void btm_read_remote_ext_features (UINT16 handle, UINT8 page_number); @@ -2275,10 +2276,11 @@ void btm_acl_pkt_types_changed(UINT8 status, UINT16 handle, UINT16 pkt_types) ** Returns BTM_CMD_STARTED if successfully initiated or error code ** *******************************************************************************/ -tBTM_STATUS BTM_ReadChannelMap(BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb) +tBTM_STATUS BTM_ReadChannelMap(BD_ADDR remote_bda) { tACL_CONN *p; tBTM_BLE_CH_MAP_RESULTS result; + UINT8 status; BTM_TRACE_DEBUG("BTM_ReadChannelMap: RemBdAddr: %02x%02x%02x%02x%02x%02x\n", remote_bda[0], remote_bda[1], remote_bda[2], @@ -2286,29 +2288,33 @@ tBTM_STATUS BTM_ReadChannelMap(BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb) memset(result.channel_map, 0, sizeof(result.channel_map)); // Clear channel map data /* If someone already waiting for the channel map, do not allow another */ - if (btm_cb.devcb.p_ble_ch_map_cmpl_cb) { + if (btm_cb.devcb.is_ch_map_cb) { result.status = BTM_BUSY; - (*p_cb)(&result); - return BTM_BUSY; + status = BTM_BUSY; + goto _ch_map_err; } p = btm_bda_to_acl(remote_bda, BT_TRANSPORT_LE); if (p != NULL) { - btm_cb.devcb.p_ble_ch_map_cmpl_cb = p_cb; - if (!btsnd_hcic_ble_read_chnl_map(p->hci_handle)) { - btm_cb.devcb.p_ble_ch_map_cmpl_cb = NULL; + btm_cb.devcb.is_ch_map_cb = false; result.status = BTM_NO_RESOURCES; - (*p_cb)(&result); - return BTM_NO_RESOURCES; + status = BTM_NO_RESOURCES; + goto _ch_map_err; } else { + btm_cb.devcb.is_ch_map_cb = true; return BTM_CMD_STARTED; } } - + status = BTM_UNKNOWN_ADDR; /* If here, no BD Addr found */ result.status = BTM_UNKNOWN_ADDR; - (*p_cb)(&result); - return BTM_UNKNOWN_ADDR; + +_ch_map_err: + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + // `ch_map_read` is same as `results` + memcpy(&cb_params.ch_map_results, &result, sizeof(tBTM_BLE_CH_MAP_RESULTS)); + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_READ_CHANNEL_MAP_EVT, &cb_params); + return status; } void BTM_BleGetWhiteListSize(uint16_t *length) @@ -2349,17 +2355,15 @@ void BTM_BleGetPeriodicAdvListSize(uint8_t *size) *******************************************************************************/ void btm_read_channel_map_complete(UINT8 *p) { - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_ble_ch_map_cmpl_cb; tBTM_BLE_CH_MAP_RESULTS results; UINT16 handle; tACL_CONN *p_acl_cb = NULL; BTM_TRACE_DEBUG("btm_read_channel_map_complete\n"); - /* Reset the callback pointer to prevent duplicate calls */ - btm_cb.devcb.p_ble_ch_map_cmpl_cb = NULL; - - if (p_cb) { + if (btm_cb.devcb.is_ch_map_cb) { + /* Reset the callback pointer to prevent duplicate calls */ + btm_cb.devcb.is_ch_map_cb = false; /* Extract HCI status from the response */ STREAM_TO_UINT8(results.hci_status, p); @@ -2386,7 +2390,10 @@ void btm_read_channel_map_complete(UINT8 *p) } /* Invoke the registered callback with the results */ - (*p_cb)(&results); + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + // `ch_map_read` is same as `results` + memcpy(&cb_params.ch_map_results, &results, sizeof(tBTM_BLE_CH_MAP_RESULTS)); + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_READ_CHANNEL_MAP_EVT, &cb_params); } } #endif // #if BLE_INCLUDED == TRUE diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble.c b/components/bt/host/bluedroid/stack/btm/btm_ble.c index 5a35fa0e9b..71dcdc0768 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble.c @@ -904,7 +904,7 @@ tBTM_STATUS BTM_SetBleDataLength(BD_ADDR bd_addr, UINT16 tx_pdu_length) } else if (tx_pdu_length < BTM_BLE_DATA_SIZE_MIN) { tx_pdu_length = BTM_BLE_DATA_SIZE_MIN; } - + p_acl->data_len_updating = true; /* always set the TxTime to be max, as controller does not care for now */ btsnd_hcic_ble_set_data_length(p_acl->hci_handle, tx_pdu_length, BTM_BLE_DATA_TX_TIME_MAX); diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c index 089f7758e1..4a2f30090c 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c @@ -23,7 +23,7 @@ tBTM_BLE_5_HCI_CBACK ble_5_hci_cb; extern BOOLEAN BTM_GetLocalResolvablePrivateAddr(BD_ADDR bda); extern void BTM_UpdateAddrInfor(uint8_t addr_type, BD_ADDR bda); extern void BTM_BleSetStaticAddr(BD_ADDR rand_addr); -extern uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK *cb); +extern uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type); #if (BLE_50_EXTEND_ADV_EN == TRUE) static tBTM_STATUS btm_ble_ext_adv_params_validate(tBTM_BLE_GAP_EXT_ADV_PARAMS *params); static tBTM_STATUS btm_ble_ext_adv_set_data_validate(UINT8 instance, UINT16 len, UINT8 *data); @@ -56,156 +56,6 @@ static tBTM_BLE_SYNC_RETRY_CB sync_retry_cb = {0}; extern void btm_ble_inter_set(bool extble_inter); -#if !UC_BT_STACK_NO_LOG -static const char *btm_ble_hci_status_to_str(tHCI_STATUS status) -{ - switch(status) { - case HCI_SUCCESS: - return "HCI_SUCCESS"; - case HCI_ERR_ILLEGAL_COMMAND: - return "HCI_ERR_ILLEGAL_COMMAND"; - case HCI_ERR_NO_CONNECTION: - return "HCI_ERR_NO_CONNECTION"; - case HCI_ERR_HW_FAILURE: - return "HCI_ERR_HW_FAILURE"; - case HCI_ERR_PAGE_TIMEOUT: - return "HCI_ERR_PAGE_TIMEOUT"; - case HCI_ERR_AUTH_FAILURE: - return "HCI_ERR_AUTH_FAILURE"; - case HCI_ERR_KEY_MISSING: - return "HCI_ERR_KEY_MISSING"; - case HCI_ERR_MEMORY_FULL: - return "HCI_ERR_MEMORY_FULL"; - case HCI_ERR_CONNECTION_TOUT: - return "HCI_ERR_CONNECTION_TOUT"; - case HCI_ERR_MAX_NUM_OF_CONNECTIONS: - return "HCI_ERR_MAX_NUM_OF_CONNECTIONS"; - case HCI_ERR_MAX_NUM_OF_SCOS: - return "HCI_ERR_MAX_NUM_OF_SCOS"; - case HCI_ERR_CONNECTION_EXISTS: - return "HCI_ERR_CONNECTION_EXISTS"; - case HCI_ERR_COMMAND_DISALLOWED: - return "HCI_ERR_COMMAND_DISALLOWED"; - case HCI_ERR_HOST_REJECT_RESOURCES: - return "HCI_ERR_HOST_REJECT_RESOURCES"; - case HCI_ERR_HOST_REJECT_SECURITY: - return "HCI_ERR_HOST_REJECT_SECURITY"; - case HCI_ERR_HOST_REJECT_DEVICE: - return "HCI_ERR_HOST_REJECT_DEVICE"; - case HCI_ERR_HOST_TIMEOUT: - return "HCI_ERR_HOST_TIMEOUT"; - case HCI_ERR_UNSUPPORTED_VALUE: - return "HCI_ERR_UNSUPPORTED_VALUE"; - case HCI_ERR_ILLEGAL_PARAMETER_FMT: - return "HCI_ERR_ILLEGAL_PARAMETER_FMT"; - case HCI_ERR_PEER_USER: - return "HCI_ERR_PEER_USER"; - case HCI_ERR_PEER_LOW_RESOURCES: - return "HCI_ERR_PEER_LOW_RESOURCES"; - case HCI_ERR_PEER_POWER_OFF: - return "HCI_ERR_PEER_POWER_OFF"; - case HCI_ERR_CONN_CAUSE_LOCAL_HOST: - return "HCI_ERR_CONN_CAUSE_LOCAL_HOST"; - case HCI_ERR_REPEATED_ATTEMPTS: - return "HCI_ERR_REPEATED_ATTEMPTS"; - case HCI_ERR_PAIRING_NOT_ALLOWED: - return "HCI_ERR_PAIRING_NOT_ALLOWED"; - case HCI_ERR_UNKNOWN_LMP_PDU: - return "HCI_ERR_UNKNOWN_LMP_PDU"; - case HCI_ERR_UNSUPPORTED_REM_FEATURE: - return "HCI_ERR_UNSUPPORTED_REM_FEATURE"; - case HCI_ERR_SCO_OFFSET_REJECTED: - return "HCI_ERR_SCO_OFFSET_REJECTED"; - case HCI_ERR_SCO_INTERVAL_REJECTED: - return "HCI_ERR_SCO_INTERVAL_REJECTED"; - case HCI_ERR_SCO_AIR_MODE: - return "HCI_ERR_SCO_AIR_MODE"; - case HCI_ERR_INVALID_LMP_PARAM: - return "HCI_ERR_INVALID_LMP_PARAM"; - case HCI_ERR_UNSPECIFIED: - return "HCI_ERR_UNSPECIFIED"; - case HCI_ERR_UNSUPPORTED_LMP_PARAMETERS: - return "HCI_ERR_UNSUPPORTED_LMP_PARAMETERS"; - case HCI_ERR_ROLE_CHANGE_NOT_ALLOWED: - return "HCI_ERR_ROLE_CHANGE_NOT_ALLOWED"; - case HCI_ERR_LMP_RESPONSE_TIMEOUT: - return "HCI_ERR_LMP_RESPONSE_TIMEOUT"; - case HCI_ERR_LMP_ERR_TRANS_COLLISION: - return "HCI_ERR_LMP_ERR_TRANS_COLLISION"; - case HCI_ERR_LMP_PDU_NOT_ALLOWED: - return "HCI_ERR_LMP_PDU_NOT_ALLOWED"; - case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE: - return "HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE"; - case HCI_ERR_UNIT_KEY_USED: - return "HCI_ERR_UNIT_KEY_USED"; - case HCI_ERR_QOS_NOT_SUPPORTED: - return "HCI_ERR_QOS_NOT_SUPPORTED"; - case HCI_ERR_INSTANT_PASSED: - return "HCI_ERR_INSTANT_PASSED"; - case HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED: - return "HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED"; - case HCI_ERR_DIFF_TRANSACTION_COLLISION: - return "HCI_ERR_DIFF_TRANSACTION_COLLISION"; - case HCI_ERR_UNDEFINED_0x2B: - return "HCI_ERR_UNDEFINED_0x2B"; - case HCI_ERR_QOS_UNACCEPTABLE_PARAM: - return "HCI_ERR_QOS_UNACCEPTABLE_PARAM"; - case HCI_ERR_QOS_REJECTED: - return "HCI_ERR_QOS_REJECTED"; - case HCI_ERR_CHAN_CLASSIF_NOT_SUPPORTED: - return "HCI_ERR_CHAN_CLASSIF_NOT_SUPPORTED"; - case HCI_ERR_INSUFFCIENT_SECURITY: - return "HCI_ERR_INSUFFCIENT_SECURITY"; - case HCI_ERR_PARAM_OUT_OF_RANGE: - return "HCI_ERR_PARAM_OUT_OF_RANGE"; - case HCI_ERR_UNDEFINED_0x31: - return "HCI_ERR_UNDEFINED_0x31"; - case HCI_ERR_ROLE_SWITCH_PENDING: - return "HCI_ERR_ROLE_SWITCH_PENDING"; - case HCI_ERR_UNDEFINED_0x33: - return "HCI_ERR_UNDEFINED_0x33"; - case HCI_ERR_RESERVED_SLOT_VIOLATION: - return "HCI_ERR_RESERVED_SLOT_VIOLATION"; - case HCI_ERR_ROLE_SWITCH_FAILED: - return "HCI_ERR_ROLE_SWITCH_FAILED"; - case HCI_ERR_INQ_RSP_DATA_TOO_LARGE: - return "HCI_ERR_INQ_RSP_DATA_TOO_LARGE"; - case HCI_ERR_SIMPLE_PAIRING_NOT_SUPPORTED: - return "HCI_ERR_SIMPLE_PAIRING_NOT_SUPPORTED"; - case HCI_ERR_HOST_BUSY_PAIRING: - return "HCI_ERR_HOST_BUSY_PAIRING"; - case HCI_ERR_REJ_NO_SUITABLE_CHANNEL: - return "HCI_ERR_REJ_NO_SUITABLE_CHANNEL"; - case HCI_ERR_CONTROLLER_BUSY: - return "HCI_ERR_CONTROLLER_BUSY"; - case HCI_ERR_UNACCEPT_CONN_INTERVAL: - return "HCI_ERR_UNACCEPT_CONN_INTERVAL"; - case HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT: - return "HCI_ERR_DIRECTED_ADVERTISING_TIMEOUT"; - case HCI_ERR_CONN_TOUT_DUE_TO_MIC_FAILURE: - return "HCI_ERR_CONN_TOUT_DUE_TO_MIC_FAILURE"; - case HCI_ERR_CONN_FAILED_ESTABLISHMENT: - return "HCI_ERR_CONN_FAILED_ESTABLISHMENT"; - case HCI_ERR_MAC_CONNECTION_FAILED: - return "HCI_ERR_MAC_CONNECTION_FAILED"; - case HCI_ERR_LT_ADDR_ALREADY_IN_USE: - return "HCI_ERR_LT_ADDR_ALREADY_IN_USE"; - case HCI_ERR_LT_ADDR_NOT_ALLOCATED: - return "HCI_ERR_LT_ADDR_NOT_ALLOCATED"; - case HCI_ERR_CLB_NOT_ENABLED: - return "HCI_ERR_CLB_NOT_ENABLED"; - case HCI_ERR_MAX_ERR: - return "HCI_ERR_MAX_ERR"; - case HCI_ERR_ESP_VENDOR_FAIL: - return "HCI_ERR_ESP_VENDOR_FAIL"; - case HCI_HINT_TO_RECREATE_AMP_PHYS_LINK: - return "HCI_HINT_TO_RECREATE_AMP_PHYS_LINK"; - default: - return "Invalid HCI status code."; - } -} -#endif /* !UC_BT_STACK_NO_LOG */ - void btm_ble_extendadvcb_init(void) { memset(&extend_adv_cb, 0, sizeof(tBTM_BLE_EXTENDED_CB)); @@ -245,9 +95,7 @@ tBTM_STATUS BTM_BleReadPhy(BD_ADDR bd_addr, UINT8 *tx_phy, UINT8 *rx_phy) cb_params.read_phy.status = BTM_ILLEGAL_VALUE; memcpy(cb_params.read_phy.addr, bd_addr, BD_ADDR_LEN); - if (ble_5_hci_cb) { - ble_5_hci_cb(BTM_BLE_5_GAP_READ_PHY_COMPLETE_EVT, &cb_params); - } + BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_READ_PHY_COMPLETE_EVT, &cb_params); BTM_TRACE_ERROR("%s, invalid parameters", __func__); return BTM_ILLEGAL_VALUE; } @@ -265,8 +113,8 @@ tBTM_STATUS BTM_BleSetPreferDefaultPhy(UINT8 tx_phy_mask, UINT8 rx_phy_mask) tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0}; if ((err = btsnd_hcic_ble_set_prefered_default_phy(all_phys, tx_phy_mask, rx_phy_mask)) != HCI_SUCCESS) { - BTM_TRACE_ERROR("%s, fail to send the hci command, the error code = %s(0x%x)", - __func__, btm_ble_hci_status_to_str(err), err); + BTM_TRACE_ERROR("%s, fail to send the hci command, the error code = 0x%x", + __func__, err); status = BTM_HCI_ERROR | err; } @@ -286,9 +134,7 @@ tBTM_STATUS BTM_BleSetPreferPhy(BD_ADDR bd_addr, UINT8 all_phys, UINT8 tx_phy_ma if (!p_lcb) { cb_params.status = BTM_ILLEGAL_VALUE; - if (ble_5_hci_cb) { - ble_5_hci_cb(BTM_BLE_5_GAP_SET_PREFERED_PHY_COMPLETE_EVT, &cb_params); - } + BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_SET_PREFERED_PHY_COMPLETE_EVT, &cb_params); BTM_TRACE_ERROR("%s, invalid parameters", __func__); return BTM_ILLEGAL_VALUE; } @@ -347,8 +193,8 @@ tBTM_STATUS BTM_BleSetExtendedAdvRandaddr(UINT8 instance, BD_ADDR rand_addr) // set random address if((err = btsnd_hcic_ble_set_extend_rand_address(instance, rand_addr)) != HCI_SUCCESS) { - BTM_TRACE_ERROR("%s, fail to send the hci command, the error code = %s(0x%x)", - __func__, btm_ble_hci_status_to_str(err), err); + BTM_TRACE_ERROR("%s, fail to send the hci command, the error code = 0x%x", + __func__, err); status = BTM_HCI_ERROR | err; } else { // set random address success, update address info @@ -1120,7 +966,7 @@ tBTM_STATUS BTM_BleSetExtendedScanParams(tBTM_BLE_EXT_SCAN_PARAMS *params) phy_count++; } - if (BTM_BleUpdateOwnType(¶ms->own_addr_type, NULL) != 0 ) { + if (BTM_BleUpdateOwnType(¶ms->own_addr_type) != 0 ) { status = BTM_ILLEGAL_VALUE; BTM_TRACE_ERROR("LE UpdateOwnType err"); goto end; diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_addr.c b/components/bt/host/bluedroid/stack/btm/btm_ble_addr.c index d130a08476..e3ea81961d 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_addr.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_addr.c @@ -34,6 +34,7 @@ #if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE) #include "btm_ble_int.h" #include "stack/smp_api.h" +#include "bta_dm_gap.h" /******************************************************************************* @@ -50,6 +51,7 @@ static void btm_gen_resolve_paddr_cmpl(tSMP_ENC *p) { tBTM_LE_RANDOM_CB *p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; BTM_TRACE_EVENT ("btm_gen_resolve_paddr_cmpl"); + tBTM_STATUS status = BTM_SUCCESS; if (p) { /* set hash to be LSB of rpAddress */ @@ -62,10 +64,7 @@ static void btm_gen_resolve_paddr_cmpl(tSMP_ENC *p) p_cb->exist_addr_bit |= BTM_BLE_GAP_ADDR_BIT_RESOLVABLE; memcpy(p_cb->resolvale_addr, p_cb->private_addr, BD_ADDR_LEN); - if (p_cb->set_local_privacy_cback){ - (*p_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_SUCCESS); - p_cb->set_local_privacy_cback = NULL; - } + status = BTM_SET_PRIVACY_SUCCESS; /* start a periodical timer to refresh random addr */ btu_stop_timer_oneshot(&p_cb->raddr_timer_ent); @@ -79,11 +78,12 @@ static void btm_gen_resolve_paddr_cmpl(tSMP_ENC *p) } else { /* random address set failure */ BTM_TRACE_DEBUG("set random address failed"); - if (p_cb->set_local_privacy_cback){ - (*p_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_FAIL); - p_cb->set_local_privacy_cback = NULL; - } + status = BTM_SET_PRIVACY_FAIL; } + + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_SET_PRIVACY_EVT, &cb_params); } /******************************************************************************* ** diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_bgconn.c b/components/bt/host/bluedroid/stack/btm/btm_ble_bgconn.c index 452d3b3a1a..8ebfe0e290 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_bgconn.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_bgconn.c @@ -33,6 +33,7 @@ #include "l2c_int.h" #include "stack/hcimsgs.h" //#include "bt_utils.h" +#include "bta_dm_gap.h" #ifndef BTM_BLE_SCAN_PARAM_TOUT #define BTM_BLE_SCAN_PARAM_TOUT 50 /* 50 seconds */ @@ -278,8 +279,10 @@ void btm_enq_wl_dev_operation(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE ad ** the white list. ** *******************************************************************************/ -BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBTM_UPDATE_WHITELIST_CBACK *update_wl_cb) +BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type) { + BOOLEAN result = TRUE; + UINT8 status; #if (BLE_50_FEATURE_SUPPORT == TRUE) if (addr_type > BLE_ADDR_RANDOM && addr_type != BLE_ADDR_ANONYMOUS) #else @@ -287,10 +290,9 @@ BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_ #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) { BTM_TRACE_ERROR("%s address type is error, unable to add device", __func__); - if (update_wl_cb){ - update_wl_cb(HCI_ERR_ILLEGAL_PARAMETER_FMT,to_add); - } - return FALSE; + status = HCI_ERR_ILLEGAL_PARAMETER_FMT; + result = FALSE; + goto _wl_end; } BD_ADDR invalid_rand_addr_a, invalid_rand_addr_b; @@ -319,10 +321,9 @@ BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_ // do nothing } else { BTC_TRACE_ERROR(" controller not support resolvable address"); - if (update_wl_cb){ - update_wl_cb(HCI_ERR_ILLEGAL_PARAMETER_FMT,to_add); - } - return FALSE; + status = HCI_ERR_ILLEGAL_PARAMETER_FMT; + result = FALSE; + goto _wl_end; } } @@ -331,10 +332,9 @@ BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_ if (to_add && p_cb->white_list_avail_size == 0) { BTM_TRACE_ERROR("%s Whitelist full, unable to add device", __func__); - if (update_wl_cb){ - update_wl_cb(HCI_ERR_MEMORY_FULL,to_add); - } - return FALSE; + status = HCI_ERR_MEMORY_FULL; + result = FALSE; + goto _wl_end; } #if (BLE_GATT_BGCONN == TRUE) @@ -342,27 +342,21 @@ BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_ /* added the bd_addr to the connection hash map queue */ if(!background_connection_add((bt_bdaddr_t *)bd_addr)) { /* if the bd_addr already exist in whitelist, just callback return TRUE */ - if (update_wl_cb){ - update_wl_cb(HCI_SUCCESS,to_add); - } - return TRUE; + status = HCI_SUCCESS; + result = TRUE; + goto _wl_end; } } else { /* remove the bd_addr to the connection hash map queue */ if(!background_connection_remove((bt_bdaddr_t *)bd_addr)){ /* if the bd_addr don't exist in whitelist, just callback return TRUE */ - if (update_wl_cb){ - update_wl_cb(HCI_SUCCESS,to_add); - } - return TRUE; + status = HCI_SUCCESS; + result = TRUE; + goto _wl_end; } } #endif // (BLE_GATT_BGCONN == TRUE) - if (update_wl_cb){ - //save add whitelist complete callback - p_cb->update_wl_cb = update_wl_cb; - } /* stop the auto connect */ btm_suspend_wl_activity(p_cb->wl_state); /* save the bd_addr to the btm_cb env */ @@ -370,6 +364,13 @@ BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_ /* save the ba_addr to the controller white list */ btm_wl_update_to_controller(); return TRUE; + +_wl_end: + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.white_list_update.status = status; + cb_params.white_list_update.operation = to_add ? BTM_WHITELIST_ADD : BTM_WHITELIST_REMOVE; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_WHITE_LIST_UPDATE_EVT, &cb_params); + return result; } /******************************************************************************* @@ -379,20 +380,14 @@ BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_ ** Description This function clears the white list. ** *******************************************************************************/ -void btm_ble_clear_white_list (tBTM_UPDATE_WHITELIST_CBACK *update_wl_cb) +void btm_ble_clear_white_list (void) { - tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; - BTM_TRACE_EVENT ("btm_ble_clear_white_list"); btsnd_hcic_ble_clear_white_list(); #if (BLE_GATT_BGCONN == TRUE) background_connections_clear(); #endif // (BLE_GATT_BGCONN == TRUE) - - if (update_wl_cb) { - p_cb->update_wl_cb = update_wl_cb; - } } /******************************************************************************* @@ -417,9 +412,10 @@ void btm_ble_clear_white_list_complete(UINT8 *p_data, UINT16 evt_len) BTM_TRACE_ERROR ("%s failed, status 0x%x\n", __func__, status); } - if (p_cb->update_wl_cb) { - (*p_cb->update_wl_cb)(status, BTM_WHITELIST_CLEAR); - } + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.white_list_update.status = status; + cb_params.white_list_update.operation = BTM_WHITELIST_CLEAR; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_WHITE_LIST_UPDATE_EVT, &cb_params); } /******************************************************************************* @@ -462,7 +458,6 @@ void btm_ble_periodic_adv_list_init(UINT8 periodic_adv_size) void btm_ble_add_2_white_list_complete(UINT8 status) { BTM_TRACE_EVENT("%s status=%d", __func__, status); - tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; if (status == HCI_SUCCESS) { // --btm_cb.ble_ctr_cb.white_list_avail_size; /* @@ -475,10 +470,10 @@ void btm_ble_add_2_white_list_complete(UINT8 status) */ } // add whitelist complete callback - if (p_cb->update_wl_cb) - { - (*p_cb->update_wl_cb)(status, BTM_WHITELIST_ADD); - } + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.white_list_update.status = status; + cb_params.white_list_update.operation = BTM_WHITELIST_ADD; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_WHITE_LIST_UPDATE_EVT, &cb_params); } @@ -491,16 +486,16 @@ void btm_ble_add_2_white_list_complete(UINT8 status) *******************************************************************************/ void btm_ble_remove_from_white_list_complete(UINT8 *p, UINT16 evt_len) { - tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; UNUSED(evt_len); BTM_TRACE_EVENT ("%s status=%d", __func__, *p); if (*p == HCI_SUCCESS) { // ++btm_cb.ble_ctr_cb.white_list_avail_size; } - if (p_cb->update_wl_cb) - { - (*p_cb->update_wl_cb)(*p, BTM_WHITELIST_REMOVE); - } + + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.white_list_update.status = *p; + cb_params.white_list_update.operation = BTM_WHITELIST_REMOVE; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_WHITE_LIST_UPDATE_EVT, &cb_params); } #if (BLE_GATT_BGCONN == TRUE) @@ -619,11 +614,11 @@ BOOLEAN btm_ble_start_select_conn(BOOLEAN start, tBTM_BLE_SEL_CBACK *p_select_cb /* Process advertising packets only from devices in the white list */ /* use passive scan by default */ - if (!btsnd_hcic_ble_set_scan_params(BTM_BLE_SCAN_MODE_PASS, - scan_int, - scan_win, - p_cb->addr_mgnt_cb.own_addr_type, - SP_ADV_WL)) { + if (btsnd_hcic_ble_set_scan_params(BTM_BLE_SCAN_MODE_PASS, + scan_int, + scan_win, + p_cb->addr_mgnt_cb.own_addr_type, + SP_ADV_WL) != HCI_SUCCESS) { return FALSE; } #if (BLE_TOPOLOGY_CHECK == TRUE) @@ -636,7 +631,7 @@ BOOLEAN btm_ble_start_select_conn(BOOLEAN start, tBTM_BLE_SEL_CBACK *p_select_cb #if BLE_PRIVACY_SPT == TRUE btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_SCAN); #endif - if (!btsnd_hcic_ble_set_scan_enable(TRUE, TRUE)) { /* duplicate filtering enabled */ + if (btsnd_hcic_ble_set_scan_enable(TRUE, TRUE) != HCI_SUCCESS) { /* duplicate filtering enabled */ return FALSE; } /* mark up inquiry status flag */ 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 51973d310e..50d89d8b0b 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c @@ -59,8 +59,6 @@ #define BTM_BLE_GAP_ADV_RPT_BATCH_SIZE (10) - -tBTM_CallbackFunc conn_callback_func; // BLE vendor HCI event callback #if (BLE_VENDOR_HCI_EN == TRUE) static tBTM_BLE_VENDOR_HCI_EVT_CBACK *ble_vs_evt_callback = NULL; @@ -80,11 +78,11 @@ static UINT8 btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB *p_cb, BD_ADDR_PTR p_peer_addr_ptr, tBLE_ADDR_TYPE *p_peer_addr_type, tBLE_ADDR_TYPE *p_own_addr_type); -static void btm_ble_stop_discover(void); #if (BLE_42_SCAN_EN == TRUE) +static tBTM_STATUS btm_ble_stop_discover(void); static void btm_adv_pkt_handler(void *arg); #endif // #if (BLE_42_SCAN_EN == TRUE) -uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK *cb); +uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type); #define BTM_BLE_INQ_RESULT 0x01 #define BTM_BLE_OBS_RESULT 0x02 @@ -247,105 +245,22 @@ const UINT8 btm_le_state_combo_tbl[BTM_BLE_STATE_MAX][BTM_BLE_STATE_MAX][2] = { #define BTM_LE_STATES_SUPPORTED(x, y, z) ((x)[(z)] & (y)) #endif // (BLE_TOPOLOGY_CHECK == TRUE) -#if (BLE_42_ADV_EN == TRUE) -static osi_mutex_t adv_enable_lock; -static osi_mutex_t adv_data_lock; -static osi_mutex_t adv_param_lock; -osi_sem_t adv_enable_sem; -osi_sem_t adv_data_sem; -osi_sem_t adv_param_sem; -uint8_t adv_enable_status = 0; -uint8_t adv_data_status = 0; -uint8_t adv_param_status = 0; -#endif // #if (BLE_42_ADV_EN == TRUE) - -#if (BLE_42_SCAN_EN == TRUE) -static osi_mutex_t scan_enable_lock; -static osi_mutex_t scan_param_lock; -osi_sem_t scan_enable_sem; -osi_sem_t scan_param_sem; -uint8_t scan_enable_status = 0; -uint8_t scan_param_status = 0; -#endif // #if (BLE_42_SCAN_EN == TRUE) +#if ((BLE_42_ADV_EN == TRUE) || (BLE_42_SCAN_EN == TRUE)) +static osi_mutex_t btm_lock; +#endif // ((BLE_42_ADV_EN == TRUE) || (BLE_42_SCAN_EN == TRUE)) void btm_ble_lock_init(void) { -#if (BLE_42_ADV_EN == TRUE) - osi_mutex_new(&adv_enable_lock); - osi_mutex_new(&adv_data_lock); - osi_mutex_new(&adv_param_lock); -#endif // #if (BLE_42_ADV_EN == TRUE) -#if (BLE_42_SCAN_EN == TRUE) - osi_mutex_new(&scan_enable_lock); - osi_mutex_new(&scan_param_lock); -#endif // #if (BLE_42_SCAN_EN == TRUE) +#if ((BLE_42_ADV_EN == TRUE) || (BLE_42_SCAN_EN == TRUE)) + osi_mutex_new(&btm_lock); +#endif // ((BLE_42_ADV_EN == TRUE) || (BLE_42_SCAN_EN == TRUE)) } void btm_ble_lock_free(void) { -#if (BLE_42_ADV_EN == TRUE) - osi_mutex_free(&adv_enable_lock); - osi_mutex_free(&adv_data_lock); - osi_mutex_free(&adv_param_lock); -#endif // #if (BLE_42_ADV_EN == TRUE) -#if (BLE_42_SCAN_EN == TRUE) - osi_mutex_free(&scan_enable_lock); - osi_mutex_free(&scan_param_lock); -#endif // #if (BLE_42_SCAN_EN == TRUE) -} - -void btm_ble_sem_init(void) -{ -#if (BLE_42_ADV_EN == TRUE) - osi_sem_new(&adv_enable_sem, 1, 0); - osi_sem_new(&adv_data_sem, 1, 0); - osi_sem_new(&adv_param_sem, 1, 0); -#endif // #if (BLE_42_ADV_EN == TRUE) -#if (BLE_42_SCAN_EN == TRUE) - osi_sem_new(&scan_enable_sem, 1, 0); - osi_sem_new(&scan_param_sem, 1, 0); -#endif // #if (BLE_42_SCAN_EN == TRUE) -} - -void btm_ble_sem_free(void) -{ -#if (BLE_42_ADV_EN == TRUE) - osi_sem_free(&adv_enable_sem); - osi_sem_free(&adv_data_sem); - osi_sem_free(&adv_param_sem); -#endif // #if (BLE_42_ADV_EN == TRUE) -#if (BLE_42_SCAN_EN == TRUE) - osi_sem_free(&scan_enable_sem); - osi_sem_free(&scan_param_sem); -#endif // #if (BLE_42_SCAN_EN == TRUE) -} - -/******************************************************************************* -** -** Function BTM_BleRegiseterConnParamCallback -** -** Description register connection parameters update callback func -** -** Returns void -** -*******************************************************************************/ -void BTM_BleRegiseterConnParamCallback(tBTM_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb) -{ - conn_callback_func.update_conn_param_cb = update_conn_param_cb; -} - -/******************************************************************************* -** -** Function BTM_BleRegiseterPktLengthChangeCallback -** -** Description Registers a callback function for packet length changes. -** -** Returns void -** -*******************************************************************************/ -void BTM_BleRegiseterPktLengthChangeCallback(tBTM_SET_PKT_DATA_LENGTH_CBACK *ptk_len_chane_cb) -{ - conn_callback_func.set_pkt_data_length_cb = ptk_len_chane_cb; +#if ((BLE_42_ADV_EN == TRUE) || (BLE_42_SCAN_EN == TRUE)) + osi_mutex_free(&btm_lock); +#endif // ((BLE_42_ADV_EN == TRUE) || (BLE_42_SCAN_EN == TRUE)) } #if (BLE_VENDOR_HCI_EN == TRUE) @@ -364,9 +279,9 @@ void BTM_BleRegisterVendorHciEventCallback(tBTM_BLE_VENDOR_HCI_EVT_CBACK *vendor ** Returns void ** *******************************************************************************/ -BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR remote_bda, tBLE_ADDR_TYPE addr_type, tBTM_UPDATE_WHITELIST_CBACK *update_wl_cb) +BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR remote_bda, tBLE_ADDR_TYPE addr_type) { - return btm_update_dev_to_white_list(add_remove, remote_bda, addr_type, update_wl_cb); + return btm_update_dev_to_white_list(add_remove, remote_bda, addr_type); } /******************************************************************************* @@ -378,9 +293,9 @@ BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR remote_bda, tBLE_A ** Returns void ** *******************************************************************************/ -void BTM_BleClearWhitelist(tBTM_UPDATE_WHITELIST_CBACK *update_wl_cb) +void BTM_BleClearWhitelist(void) { - btm_ble_clear_white_list(update_wl_cb); + btm_ble_clear_white_list(); } #if (BLE_42_SCAN_EN == TRUE) @@ -454,8 +369,7 @@ tBTM_STATUS BTM_BleScan(BOOLEAN start, UINT32 duration, } } } else if (BTM_BLE_IS_DISCO_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) { - status = BTM_CMD_STARTED; - btm_ble_stop_discover(); + status = btm_ble_stop_discover(); } else { BTM_TRACE_ERROR("%s scan not active\n", __func__); } @@ -468,63 +382,30 @@ tBTM_STATUS BTM_BleScan(BOOLEAN start, UINT32 duration, #if (BLE_42_ADV_EN == TRUE) /******************************************************************************* ** -** Function BTM_BleBroadcast +** Function BTM_BleAdvStop ** -** Description This function is to start or stop broadcasting. +** Description This function is to stop broadcasting. ** -** Parameters start: start or stop broadcasting. +** Parameters void ** ** Returns status. ** *******************************************************************************/ -tBTM_STATUS BTM_BleBroadcast(BOOLEAN start, tBTM_START_STOP_ADV_CMPL_CBACK *p_stop_adv_cback) +tBTM_STATUS BTM_BleAdvStop(void) { tBTM_STATUS status = BTM_NO_RESOURCES; // tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; - tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; //UINT8 evt_type = p_cb->scan_rsp ? BTM_BLE_DISCOVER_EVT : BTM_BLE_NON_CONNECT_EVT; if (!controller_get_interface()->supports_ble()) { return BTM_ILLEGAL_VALUE; } -#ifdef BTM_BLE_PC_ADV_TEST_MODE - if (BTM_BLE_PC_ADV_TEST_MODE) { - evt_type = p_cb->scan_rsp ? BTM_BLE_CONNECT_EVT : BTM_BLE_NON_CONNECT_EVT; - } -#endif - - if (start) { -// "start" should not be true -#if (0) - /* update adv params */ - if (!btsnd_hcic_ble_write_adv_params ((UINT16)(p_cb->adv_interval_min ? p_cb->adv_interval_min : - BTM_BLE_GAP_ADV_INT), - (UINT16)(p_cb->adv_interval_max ? p_cb->adv_interval_max : - BTM_BLE_GAP_ADV_INT), - evt_type, - p_addr_cb->own_addr_type, - p_cb->direct_bda.type, - p_cb->direct_bda.bda, - p_cb->adv_chnl_map, - p_cb->afp)) - - { - status = BTM_NO_RESOURCES; - } else { - p_cb->evt_type = evt_type; - } - - status = btm_ble_start_adv (); -#endif // - } else { - //save the stop adv callback to the BTM env. - p_cb->p_stop_adv_cb = p_stop_adv_cback; - status = btm_ble_stop_adv(); + status = btm_ble_stop_adv(); #if BLE_PRIVACY_SPT == TRUE - btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE); + btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE); #endif - } + return status; } #endif // #if (BLE_42_ADV_EN == TRUE) @@ -598,16 +479,11 @@ void BTM_BleEnableMixedPrivacyMode(BOOLEAN mixed_on) ** Returns BOOLEAN privacy mode set success; otherwise failed. ** *******************************************************************************/ -BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode, tBTM_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback) +BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode) { #if BLE_PRIVACY_SPT == TRUE tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; tBTM_LE_RANDOM_CB *random_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; - if (random_cb){ - random_cb->set_local_privacy_cback = set_local_privacy_cback; - }else{ - BTM_TRACE_ERROR("%s,random_cb = NULL", __func__); - } BTM_TRACE_EVENT ("%s\n", __func__); @@ -616,6 +492,12 @@ BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode, tBTM_SET_LOCAL_PRIVACY_CBACK return FALSE; } + if (random_cb){ + random_cb->cb_is_triggered = false; + }else{ + BTM_TRACE_ERROR("%s,random_cb = NULL", __func__); + } + #if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE && GATTS_INCLUDED == TRUE) uint8_t addr_resolution = 0; #endif /* defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE && GATTS_INCLUDED == TRUE */ @@ -723,14 +605,14 @@ void BTM_BleSetStaticAddr(BD_ADDR rand_addr) } #if (CONTROLLER_RPA_LIST_ENABLE == FALSE) -uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK *cb) +uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type) { if(*own_bda_type == BLE_ADDR_RANDOM) { if((btm_cb.ble_ctr_cb.addr_mgnt_cb.exist_addr_bit & BTM_BLE_GAP_ADDR_BIT_RANDOM) == BTM_BLE_GAP_ADDR_BIT_RANDOM) { //close privacy #if BLE_PRIVACY_SPT == TRUE if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) { - BTM_BleConfigPrivacy(FALSE, NULL); + BTM_BleConfigPrivacy(FALSE); } #endif btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type = BLE_ADDR_RANDOM; @@ -744,9 +626,6 @@ uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK * btsnd_hcic_ble_set_random_addr(btm_cb.ble_ctr_cb.addr_mgnt_cb.resolvale_addr); }else { BTM_TRACE_ERROR ("No random address yet, please set random address using API \"esp_ble_gap_set_rand_addr\" and retry\n"); - if(cb) { - (* cb)(HCI_ERR_ESP_VENDOR_FAIL); - } return BTM_ILLEGAL_VALUE; } } else if(*own_bda_type == BLE_ADDR_PUBLIC_ID || *own_bda_type == BLE_ADDR_RANDOM_ID) { @@ -759,9 +638,6 @@ uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK * #if BLE_PRIVACY_SPT == TRUE if(btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) { BTM_TRACE_ERROR ("Error state\n"); - if(cb) { - (* cb)(HCI_ERR_ESP_VENDOR_FAIL); - } return BTM_ILLEGAL_VALUE; } #endif @@ -776,9 +652,6 @@ uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK * btsnd_hcic_ble_set_random_addr(btm_cb.ble_ctr_cb.addr_mgnt_cb.static_rand_addr); } else { BTM_TRACE_ERROR ("No RPA and no random address yet, please set RPA or random address and try\n"); - if(cb) { - (* cb)(HCI_ERR_ESP_VENDOR_FAIL); - } return BTM_ILLEGAL_VALUE; } } @@ -790,25 +663,19 @@ uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK * return BTM_SUCCESS; } #else -uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK *cb) +uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type) { tBTM_LE_RANDOM_CB *p_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; if((*own_bda_type == BLE_ADDR_RANDOM) || (*own_bda_type == BLE_ADDR_RANDOM_ID)) { if((p_cb->exist_addr_bit & BTM_BLE_GAP_ADDR_BIT_RANDOM) != BTM_BLE_GAP_ADDR_BIT_RANDOM) { BTM_TRACE_ERROR("No random address yet, please set random address and try\n"); - if(cb) { - (* cb)(HCI_ERR_ESP_VENDOR_FAIL); - } return BTM_ILLEGAL_VALUE; } // If a device is using RPA, it shall also have an Identity Address if ((*own_bda_type == BLE_ADDR_RANDOM_ID) && BTM_BLE_IS_NON_RESLVE_BDA(p_cb->static_rand_addr)) { BTM_TRACE_ERROR("No identity address yet, please set static random address and try\n"); - if (cb) { - (* cb)(HCI_ERR_ESP_VENDOR_FAIL); - } return BTM_ILLEGAL_VALUE; } } @@ -1043,7 +910,7 @@ BOOLEAN BTM_BleSetBgConnType(tBTM_BLE_CONN_TYPE bg_conn_type, void BTM_BleClearBgConnDev(void) { btm_ble_start_auto_conn(FALSE); - btm_ble_clear_white_list(NULL); + btm_ble_clear_white_list(); gatt_reset_bgdev_list(); } #endif // #if (GATT_BG_CONN_DEV == TRUE) @@ -1066,7 +933,7 @@ void BTM_BleClearBgConnDev(void) BOOLEAN BTM_BleUpdateBgConnDev(BOOLEAN add_remove, BD_ADDR remote_bda) { BTM_TRACE_EVENT("%s() add=%d", __func__, add_remove); - return btm_update_dev_to_white_list(add_remove, remote_bda, 0, NULL); + return btm_update_dev_to_white_list(add_remove, remote_bda, 0); } #if 0 /******************************************************************************* @@ -1189,7 +1056,7 @@ static UINT8 btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB *p_cb, #if (BLE_42_ADV_EN == TRUE) /******************************************************************************* ** -** Function BTM_BleSetAdvParamsAll +** Function BTM_BleStartAdvWithParams ** ** Description This function is called to set all of the advertising parameters. ** @@ -1198,33 +1065,30 @@ static UINT8 btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB *p_cb, ** Returns void ** *******************************************************************************/ -tBTM_STATUS BTM_BleSetAdvParamsAll(UINT16 adv_int_min, UINT16 adv_int_max, UINT8 adv_type, +tBTM_STATUS BTM_BleStartAdvWithParams(UINT16 adv_int_min, UINT16 adv_int_max, UINT8 adv_type, tBLE_ADDR_TYPE own_bda_type, tBLE_BD_ADDR *p_dir_bda, - tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP afp, tBTM_START_ADV_CMPL_CBACK *adv_cb) + tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP afp) { tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; - BTM_TRACE_EVENT ("BTM_BleSetAdvParamsAll\n"); + BTM_TRACE_EVENT ("BTM_BleStartAdvWithParams\n"); if (!controller_get_interface()->supports_ble()) { return BTM_ILLEGAL_VALUE; } - if (BTM_BleUpdateOwnType(&own_bda_type, adv_cb) != 0) { + if (BTM_BleUpdateOwnType(&own_bda_type) != 0) { return BTM_ILLEGAL_VALUE; } if (!BTM_BLE_ISVALID_PARAM(adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) || !BTM_BLE_ISVALID_PARAM(adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) { BTM_TRACE_ERROR ("adv_int_min or adv_int_max is invalid\n"); - if(adv_cb) { - (* adv_cb)(HCI_ERR_ESP_VENDOR_FAIL); - } return BTM_ILLEGAL_VALUE; } btm_ble_stop_adv(); - osi_mutex_lock(&adv_param_lock, OSI_MUTEX_MAX_TIMEOUT); + osi_mutex_lock(&btm_lock, OSI_MUTEX_MAX_TIMEOUT); #if (BLE_TOPOLOGY_CHECK == TRUE) if(adv_type == BTM_BLE_CONNECT_DIR_EVT){ btm_ble_set_topology_mask(BTM_BLE_STATE_HI_DUTY_DIR_ADV_BIT); @@ -1240,11 +1104,11 @@ tBTM_STATUS BTM_BleSetAdvParamsAll(UINT16 adv_int_min, UINT16 adv_int_max, UINT8 p_addr_cb->own_addr_type = own_bda_type; p_cb->evt_type = adv_type; p_cb->afp = afp; - p_cb->p_adv_cb = adv_cb; if (p_dir_bda) { memcpy(&p_cb->direct_bda, p_dir_bda, sizeof(tBLE_BD_ADDR)); } else { + osi_mutex_unlock(&btm_lock); return BTM_ILLEGAL_VALUE; } @@ -1259,13 +1123,11 @@ tBTM_STATUS BTM_BleSetAdvParamsAll(UINT16 adv_int_min, UINT16 adv_int_max, UINT8 p_dir_bda->type, p_dir_bda->bda, chnl_map, - p_cb->afp)) { - osi_sem_take(&adv_param_sem, OSI_SEM_MAX_TIMEOUT); - status = adv_param_status; - } else { + p_cb->afp) != HCI_SUCCESS) { status = BTM_NO_RESOURCES; } - osi_mutex_unlock(&adv_param_lock); + + osi_mutex_unlock(&btm_lock); return status; } @@ -1286,8 +1148,7 @@ tBTM_STATUS BTM_BleStartAdv(void) #if (BLE_42_SCAN_EN == TRUE) tBTM_STATUS BTM_BleSetScanFilterParams(tGATT_IF client_if, UINT32 scan_interval, UINT32 scan_window, - tBLE_SCAN_MODE scan_mode, UINT8 addr_type_own, UINT8 scan_duplicate_filter, tBTM_BLE_SFP scan_filter_policy, - tBLE_SCAN_PARAM_SETUP_CBACK scan_setup_status_cback) + tBLE_SCAN_MODE scan_mode, UINT8 addr_type_own, UINT8 scan_duplicate_filter, tBTM_BLE_SFP scan_filter_policy) { tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; UINT32 max_scan_interval; @@ -1298,7 +1159,7 @@ tBTM_STATUS BTM_BleSetScanFilterParams(tGATT_IF client_if, UINT32 scan_interval, if (!controller_get_interface()->supports_ble()) { return BTM_ILLEGAL_VALUE; } - if (BTM_BleUpdateOwnType(&addr_type_own, NULL) != 0) { + if (BTM_BleUpdateOwnType(&addr_type_own) != 0) { return BTM_ILLEGAL_VALUE; } @@ -1306,33 +1167,34 @@ tBTM_STATUS BTM_BleSetScanFilterParams(tGATT_IF client_if, UINT32 scan_interval, max_scan_window = BTM_BLE_SCAN_WIN_MAX; - osi_mutex_lock(&scan_param_lock, OSI_MUTEX_MAX_TIMEOUT); + osi_mutex_lock(&btm_lock, OSI_MUTEX_MAX_TIMEOUT); if (BTM_BLE_ISVALID_PARAM(scan_interval, BTM_BLE_SCAN_INT_MIN, max_scan_interval) && BTM_BLE_ISVALID_PARAM(scan_window, BTM_BLE_SCAN_WIN_MIN, max_scan_window) && (scan_mode == BTM_BLE_SCAN_MODE_ACTI || scan_mode == BTM_BLE_SCAN_MODE_PASS) && (scan_duplicate_filter < BTM_BLE_SCAN_DUPLICATE_MAX) && (scan_window <= scan_interval)) { - p_cb->scan_type = scan_mode; - p_cb->scan_interval = scan_interval; - p_cb->scan_window = scan_window; - p_cb->sfp = scan_filter_policy; - p_cb->scan_params_set = TRUE; - p_cb->scan_duplicate_filter = scan_duplicate_filter; - - if (btsnd_hcic_ble_set_scan_params(p_cb->scan_type, (UINT16)scan_interval, + if ((btsnd_hcic_ble_set_scan_params(scan_mode, (UINT16)scan_interval, (UINT16)scan_window, addr_type_own, - scan_filter_policy)) { - osi_sem_take(&scan_param_sem, OSI_SEM_MAX_TIMEOUT); - ret = scan_param_status; + scan_filter_policy)) != HCI_SUCCESS) { + ret = BTM_ILLEGAL_VALUE; + BTM_TRACE_ERROR("Illegal params: scan_interval = %d scan_window = %d\n", + scan_interval, scan_window); + } else { + p_cb->scan_type = scan_mode; + p_cb->scan_interval = scan_interval; + p_cb->scan_window = scan_window; + p_cb->sfp = scan_filter_policy; + p_cb->scan_params_set = TRUE; + p_cb->scan_duplicate_filter = scan_duplicate_filter; } } else { ret = BTM_ILLEGAL_VALUE; - BTM_TRACE_ERROR("Illegal params: scan_interval = %d scan_window = %d\n", + BTM_TRACE_ERROR("Invalid params: scan_interval = %d scan_window = %d\n", scan_interval, scan_window); } - osi_mutex_unlock(&scan_param_lock); + osi_mutex_unlock(&btm_lock); return ret; } #endif // #if (BLE_42_SCAN_EN == TRUE) @@ -1361,7 +1223,7 @@ tBTM_STATUS BTM_BleWriteScanRsp(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p return BTM_ILLEGAL_VALUE; } - osi_mutex_lock(&adv_data_lock, OSI_MUTEX_MAX_TIMEOUT); + osi_mutex_lock(&btm_lock, OSI_MUTEX_MAX_TIMEOUT); memset(rsp_data, 0, BTM_BLE_AD_DATA_LEN); btm_ble_build_adv_data(&data_mask, &p, p_data); if (data_mask != 0) { @@ -1369,20 +1231,20 @@ tBTM_STATUS BTM_BleWriteScanRsp(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p BTM_TRACE_WARNING("%s, Partial data write into ADV", __func__); } - if (btsnd_hcic_ble_set_scan_rsp_data((UINT8)(p - rsp_data), rsp_data)) { - osi_sem_take(&adv_data_sem, OSI_SEM_MAX_TIMEOUT); - ret = adv_data_status; - - if (adv_data_status == BTM_SUCCESS && data_mask != 0) { - btm_cb.ble_ctr_cb.inq_var.scan_rsp = TRUE; - } else { - btm_cb.ble_ctr_cb.inq_var.scan_rsp = FALSE; - } - } else { + if (btsnd_hcic_ble_set_scan_rsp_data((UINT8)(p - rsp_data), rsp_data) != HCI_SUCCESS) { ret = BTM_ILLEGAL_VALUE; + btm_cb.ble_ctr_cb.inq_var.scan_rsp = FALSE; + } else { + ret = BTM_SUCCESS; } - osi_mutex_unlock(&adv_data_lock); + if (ret == BTM_SUCCESS && data_mask != 0) { + btm_cb.ble_ctr_cb.inq_var.scan_rsp = TRUE; + } else { + btm_cb.ble_ctr_cb.inq_var.scan_rsp = FALSE; + } + + osi_mutex_unlock(&btm_lock); return ret; } @@ -1399,16 +1261,13 @@ tBTM_STATUS BTM_BleWriteScanRsp(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p *******************************************************************************/ tBTM_STATUS BTM_BleWriteScanRspRaw(UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len) { - tBTM_STATUS ret; + tBTM_STATUS ret = BTM_SUCCESS; - osi_mutex_lock(&adv_data_lock, OSI_MUTEX_MAX_TIMEOUT); - if (btsnd_hcic_ble_set_scan_rsp_data((UINT8)raw_scan_rsp_len, p_raw_scan_rsp)) { - osi_sem_take(&adv_data_sem, OSI_SEM_MAX_TIMEOUT); - ret = adv_data_status; - } else { + osi_mutex_lock(&btm_lock, OSI_MUTEX_MAX_TIMEOUT); + if (btsnd_hcic_ble_set_scan_rsp_data((UINT8)raw_scan_rsp_len, p_raw_scan_rsp) != HCI_SUCCESS) { ret = BTM_NO_RESOURCES; } - osi_mutex_unlock(&adv_data_lock); + osi_mutex_unlock(&btm_lock); return ret; } @@ -1424,19 +1283,15 @@ tBTM_STATUS BTM_BleWriteScanRspRaw(UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_le ** Parameters: subcode: add, remove or clean duplicate scan exceptional list. ** type: device info type ** device_info: device information -** update_exceptional_list_cmp_cb: complete callback +** ** ** Returns status ** *******************************************************************************/ -tBTM_STATUS BTM_UpdateBleDuplicateExceptionalList(uint8_t subcode, uint32_t type, BD_ADDR device_info, - tBTM_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK update_exceptional_list_cmp_cb) +tBTM_STATUS BTM_UpdateBleDuplicateExceptionalList(uint8_t subcode, uint32_t type, BD_ADDR device_info) { - tBTM_BLE_CB *ble_cb = &btm_cb.ble_ctr_cb; tBTM_STATUS status = BTM_NO_RESOURCES; - ble_cb->update_exceptional_list_cmp_cb = update_exceptional_list_cmp_cb; - if (!controller_get_interface()->supports_ble()) { return BTM_ILLEGAL_VALUE; } @@ -1498,14 +1353,14 @@ tBTM_STATUS BTM_BleWriteAdvData(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p tBTM_BLE_LOCAL_ADV_DATA *p_cb_data = &btm_cb.ble_ctr_cb.inq_var.adv_data; UINT8 *p; tBTM_BLE_AD_MASK mask = data_mask; - tBTM_STATUS ret; + tBTM_STATUS ret = BTM_SUCCESS; BTM_TRACE_EVENT ("BTM_BleWriteAdvData "); if (!controller_get_interface()->supports_ble()) { return BTM_ILLEGAL_VALUE; } - osi_mutex_lock(&adv_data_lock, OSI_MUTEX_MAX_TIMEOUT); + osi_mutex_lock(&btm_lock, OSI_MUTEX_MAX_TIMEOUT); memset(p_cb_data, 0, sizeof(tBTM_BLE_LOCAL_ADV_DATA)); p = p_cb_data->ad_data; p_cb_data->data_mask = data_mask; @@ -1521,14 +1376,11 @@ tBTM_STATUS BTM_BleWriteAdvData(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p p_cb_data->data_mask &= ~mask; - if (btsnd_hcic_ble_set_adv_data((UINT8)(p_cb_data->p_pad - p_cb_data->ad_data), - p_cb_data->ad_data)) { - osi_sem_take(&adv_data_sem, OSI_SEM_MAX_TIMEOUT); - ret = adv_data_status; - } else { + if ((btsnd_hcic_ble_set_adv_data((UINT8)(p_cb_data->p_pad - p_cb_data->ad_data), + p_cb_data->ad_data)) != HCI_SUCCESS) { ret = BTM_NO_RESOURCES; } - osi_mutex_unlock(&adv_data_lock); + osi_mutex_unlock(&btm_lock); return ret; } @@ -1545,15 +1397,12 @@ tBTM_STATUS BTM_BleWriteAdvData(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p *******************************************************************************/ tBTM_STATUS BTM_BleWriteAdvDataRaw(UINT8 *p_raw_adv, UINT32 raw_adv_len) { - tBTM_STATUS ret; - osi_mutex_lock(&adv_data_lock, OSI_MUTEX_MAX_TIMEOUT); - if (btsnd_hcic_ble_set_adv_data((UINT8)raw_adv_len, p_raw_adv)) { - osi_sem_take(&adv_data_sem, OSI_SEM_MAX_TIMEOUT); - ret = adv_data_status; - } else { + tBTM_STATUS ret = BTM_SUCCESS; + osi_mutex_lock(&btm_lock, OSI_MUTEX_MAX_TIMEOUT); + if ((btsnd_hcic_ble_set_adv_data((UINT8)raw_adv_len, p_raw_adv)) != HCI_SUCCESS) { ret = BTM_NO_RESOURCES; } - osi_mutex_unlock(&adv_data_lock); + osi_mutex_unlock(&btm_lock); return ret; } @@ -2215,14 +2064,14 @@ tBTM_STATUS btm_ble_set_discoverability(UINT16 combined_mode) #endif // #if (BLE_42_ADV_EN == TRUE) /* update adv params */ - if (!btsnd_hcic_ble_write_adv_params (adv_int_min, + if (btsnd_hcic_ble_write_adv_params (adv_int_min, adv_int_max, evt_type, own_addr_type, init_addr_type, p_addr_ptr, p_cb->adv_chnl_map, - p_cb->afp)) { + p_cb->afp) != HCI_SUCCESS) { status = BTM_NO_RESOURCES; } else { p_cb->evt_type = evt_type; @@ -2313,14 +2162,14 @@ tBTM_STATUS btm_ble_set_connectability(UINT16 combined_mode) btm_ble_stop_adv(); #endif // #if (BLE_42_ADV_EN == TRUE) - if (!btsnd_hcic_ble_write_adv_params (adv_int_min, + if (btsnd_hcic_ble_write_adv_params (adv_int_min, adv_int_max, evt_type, own_addr_type, peer_addr_type, p_addr_ptr, p_cb->adv_chnl_map, - p_cb->afp)) { + p_cb->afp) != HCI_SUCCESS) { status = BTM_NO_RESOURCES; } else { p_cb->evt_type = evt_type; @@ -2499,7 +2348,7 @@ static void btm_ble_update_adv_flag(UINT8 flag) } if (btsnd_hcic_ble_set_adv_data((UINT8)(p_adv_data->p_pad - p_adv_data->ad_data), - p_adv_data->ad_data)) { + p_adv_data->ad_data) == HCI_SUCCESS) { p_adv_data->data_mask |= BTM_BLE_AD_BIT_FLAGS; } @@ -3385,19 +3234,15 @@ tBTM_STATUS btm_ble_start_scan(void) tBTM_BLE_INQ_CB *p_inq = &btm_cb.ble_ctr_cb.inq_var; tBTM_STATUS status = BTM_CMD_STARTED; - osi_mutex_lock(&scan_enable_lock, OSI_MUTEX_MAX_TIMEOUT); + osi_mutex_lock(&btm_lock, OSI_MUTEX_MAX_TIMEOUT); if(p_inq->scan_duplicate_filter > BTM_BLE_DUPLICATE_MAX) { p_inq->scan_duplicate_filter = BTM_BLE_DUPLICATE_DISABLE; } /* start scan, disable duplicate filtering */ - if (!btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, p_inq->scan_duplicate_filter)) { + if ((btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, p_inq->scan_duplicate_filter)) != HCI_SUCCESS) { status = BTM_NO_RESOURCES; } else { - osi_sem_take(&scan_enable_sem, OSI_SEM_MAX_TIMEOUT); - if(scan_enable_status != BTM_SUCCESS) { - status = BTM_NO_RESOURCES; - } btm_cb.ble_ctr_cb.inq_var.state |= BTM_BLE_SCANNING; #if (BLE_TOPOLOGY_CHECK == TRUE) if (p_inq->scan_type == BTM_BLE_SCAN_MODE_ACTI) { @@ -3407,7 +3252,7 @@ tBTM_STATUS btm_ble_start_scan(void) } #endif // (BLE_TOPOLOGY_CHECK == TRUE) } - osi_mutex_unlock(&scan_enable_lock); + osi_mutex_unlock(&btm_lock); return status; } #endif // #if (BLE_42_SCAN_EN == TRUE) @@ -3429,13 +3274,16 @@ void btm_ble_stop_scan(void) btm_cb.ble_ctr_cb.inq_var.scan_type = BTM_BLE_SCAN_MODE_NONE; btm_cb.ble_ctr_cb.inq_var.state &= ~BTM_BLE_SCANNING; /* stop discovery now */ - btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE); + if (btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE) != HCI_SUCCESS) { + BTM_TRACE_WARNING("stop scan failed\n"); + } btm_update_scanner_filter_policy(SP_ADV_ALL); btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_SCAN; } +#if (BLE_42_SCAN_EN == TRUE) /******************************************************************************* ** ** Function btm_ble_stop_observe @@ -3445,14 +3293,15 @@ void btm_ble_stop_scan(void) ** Returns void ** *******************************************************************************/ -static void btm_ble_stop_discover(void) +static tBTM_STATUS btm_ble_stop_discover(void) { -#if (BLE_42_SCAN_EN == TRUE) + tBTM_STATUS status = BTM_CMD_STARTED; tBTM_BLE_CB *p_ble_cb = & btm_cb.ble_ctr_cb; - tBTM_CMPL_CB *p_scan_cb = p_ble_cb->p_scan_cmpl_cb; btu_stop_timer (&p_ble_cb->scan_timer_ent); - osi_mutex_lock(&scan_enable_lock, OSI_MUTEX_MAX_TIMEOUT); + osi_mutex_lock(&btm_lock, OSI_MUTEX_MAX_TIMEOUT); + + tBTM_CMPL_CB *p_scan_cb = p_ble_cb->p_scan_cmpl_cb; p_ble_cb->scan_activity &= ~BTM_LE_DISCOVER_ACTIVE; p_ble_cb->p_scan_results_cb = NULL; @@ -3462,8 +3311,8 @@ static void btm_ble_stop_discover(void) /* Clear the inquiry callback if set */ btm_cb.ble_ctr_cb.inq_var.state &= ~BTM_BLE_SCANNING; /* stop discovery now */ - if(btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE)) { - osi_sem_take(&scan_enable_sem, OSI_SEM_MAX_TIMEOUT); + if (btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_DUPLICATE_ENABLE) != HCI_SUCCESS) { + status = BTM_NO_RESOURCES; } #if (BLE_TOPOLOGY_CHECK == TRUE) /* reset status */ @@ -3472,12 +3321,19 @@ static void btm_ble_stop_discover(void) #endif // (BLE_TOPOLOGY_CHECK == TRUE) } + /* Copy completion info and unlock before invoking callback to avoid deadlock: + * callback may call BTM APIs that take btm_lock (non-recursive mutex). */ + tBTM_INQUIRY_CMPL inq_cmpl_info; + memcpy(&inq_cmpl_info, &btm_cb.btm_inq_vars.inq_cmpl_info, sizeof(inq_cmpl_info)); + osi_mutex_unlock(&btm_lock); + if (p_scan_cb) { - (p_scan_cb)((tBTM_INQUIRY_CMPL *) &btm_cb.btm_inq_vars.inq_cmpl_info); + (p_scan_cb)((tBTM_INQUIRY_CMPL *) &inq_cmpl_info); } - osi_mutex_unlock(&scan_enable_lock); -#endif // #if (BLE_42_SCAN_EN == TRUE) + + return status; } +#endif // #if (BLE_42_SCAN_EN == TRUE) /******************************************************************************* ** @@ -3536,7 +3392,7 @@ static BOOLEAN btm_ble_adv_states_operation(BTM_TOPOLOGY_FUNC_PTR *p_handler, UI tBTM_STATUS btm_ble_start_adv(void) { tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; - tBTM_STATUS rt = BTM_NO_RESOURCES; + tBTM_STATUS rt = BTM_SUCCESS; BTM_TRACE_EVENT ("btm_ble_start_adv\n"); #if (BLE_TOPOLOGY_CHECK == TRUE) @@ -3545,7 +3401,7 @@ tBTM_STATUS btm_ble_start_adv(void) } #endif // (BLE_TOPOLOGY_CHECK == TRUE) - osi_mutex_lock(&adv_enable_lock, OSI_MUTEX_MAX_TIMEOUT); + osi_mutex_lock(&btm_lock, OSI_MUTEX_MAX_TIMEOUT); #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) /* To relax resolving list, always have resolving list enabled, unless directed adv */ @@ -3571,18 +3427,8 @@ tBTM_STATUS btm_ble_start_adv(void) #if (BLE_TOPOLOGY_CHECK == TRUE) btm_ble_adv_states_operation(btm_ble_set_topology_mask, p_cb->evt_type); #endif // (BLE_TOPOLOGY_CHECK == TRUE) - if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE)) { - osi_sem_take(&adv_enable_sem, OSI_SEM_MAX_TIMEOUT); - rt = adv_enable_status; - BTM_TRACE_EVENT ("BTM_SUCCESS\n"); - } else { + if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE) != HCI_SUCCESS) { rt = BTM_NO_RESOURCES; - // reinit adv_enable_status - // There is no suitable value, temporarily changed to 0xff - adv_enable_status = 0xff; - } - - if(adv_enable_status != HCI_SUCCESS) { p_cb->state = temp_state; p_cb->adv_mode = adv_mode; #if (BLE_TOPOLOGY_CHECK == TRUE) @@ -3590,7 +3436,7 @@ tBTM_STATUS btm_ble_start_adv(void) #endif // (BLE_TOPOLOGY_CHECK == TRUE) btm_cb.ble_ctr_cb.wl_state = wl_state; } - osi_mutex_unlock(&adv_enable_lock); + osi_mutex_unlock(&btm_lock); return rt; } @@ -3608,7 +3454,7 @@ tBTM_STATUS btm_ble_stop_adv(void) tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; tBTM_STATUS rt = BTM_SUCCESS; if (p_cb) { - osi_mutex_lock(&adv_enable_lock, OSI_MUTEX_MAX_TIMEOUT); + osi_mutex_lock(&btm_lock, OSI_MUTEX_MAX_TIMEOUT); UINT8 temp_adv_mode = p_cb->adv_mode; BOOLEAN temp_fast_adv_on = p_cb->fast_adv_on; tBTM_BLE_GAP_STATE temp_state = p_cb->state; @@ -3625,16 +3471,7 @@ tBTM_STATUS btm_ble_stop_adv(void) /* clear all adv states */ btm_ble_clear_topology_mask (BTM_BLE_STATE_ALL_ADV_MASK); #endif // (BLE_TOPOLOGY_CHECK == TRUE) - if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_DISABLE)) { - osi_sem_take(&adv_enable_sem, OSI_SEM_MAX_TIMEOUT); - rt = adv_enable_status; - } else { - rt = BTM_NO_RESOURCES; - // reinit adv_enable_status - // There is no suitable value, temporarily changed to 0xff - adv_enable_status = 0xff; - } - if(adv_enable_status != HCI_SUCCESS) { + if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_DISABLE) != HCI_SUCCESS) { // reset state p_cb->fast_adv_on = temp_fast_adv_on; p_cb->adv_mode = temp_adv_mode; @@ -3643,8 +3480,12 @@ tBTM_STATUS btm_ble_stop_adv(void) #if (BLE_TOPOLOGY_CHECK == TRUE) btm_ble_set_topology_mask (temp_mask); #endif // (BLE_TOPOLOGY_CHECK == TRUE) + rt = BTM_NO_RESOURCES; } - osi_mutex_unlock(&adv_enable_lock); + if(rt != HCI_SUCCESS) { + p_cb->adv_mode = temp_adv_mode; + } + osi_mutex_unlock(&btm_lock); } return rt; } @@ -3653,31 +3494,24 @@ tBTM_STATUS btm_ble_stop_adv(void) tBTM_STATUS btm_ble_set_random_addr(BD_ADDR random_bda) { tBTM_STATUS rt = BTM_SUCCESS; -#if (BLE_42_ADV_EN == TRUE) - osi_mutex_lock(&adv_enable_lock, OSI_MUTEX_MAX_TIMEOUT); -#endif // #if (BLE_42_ADV_EN == TRUE) -#if (BLE_42_SCAN_EN == TRUE) - osi_mutex_lock(&scan_enable_lock, OSI_MUTEX_MAX_TIMEOUT); -#endif // #if (BLE_42_SCAN_EN == TRUE) +#if ((BLE_42_ADV_EN == TRUE) || (BLE_42_SCAN_EN == TRUE)) + osi_mutex_lock(&btm_lock, OSI_MUTEX_MAX_TIMEOUT); +#endif // ((BLE_42_ADV_EN == TRUE) || (BLE_42_SCAN_EN == TRUE)) #if (BLE_42_ADV_EN == TRUE) if (btm_cb.ble_ctr_cb.inq_var.adv_mode == BTM_BLE_ADV_ENABLE) { - if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_DISABLE)) { - osi_sem_take(&adv_enable_sem, OSI_SEM_MAX_TIMEOUT); - rt = adv_enable_status; - } else { + if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_DISABLE) != HCI_SUCCESS) { rt = BTM_BAD_VALUE_RET; + BTM_TRACE_WARNING ("Disable ADV failed"); } } #endif // #if (BLE_42_ADV_EN == TRUE) #if (BLE_42_SCAN_EN == TRUE) if (BTM_BLE_IS_DISCO_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) { - if (btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_SCAN_DUPLICATE_DISABLE)) { - osi_sem_take(&scan_enable_sem, OSI_SEM_MAX_TIMEOUT); - rt = scan_enable_status; - } else { + if ((btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_DISABLE, BTM_BLE_SCAN_DUPLICATE_DISABLE)) != HCI_SUCCESS) { rt = BTM_BAD_VALUE_RET; + BTM_TRACE_WARNING ("Disable scan failed"); } } #endif // #if (BLE_42_SCAN_EN == TRUE) @@ -3688,37 +3522,30 @@ tBTM_STATUS btm_ble_set_random_addr(BD_ADDR random_bda) #if (BLE_42_ADV_EN == TRUE) if (btm_cb.ble_ctr_cb.inq_var.adv_mode == BTM_BLE_ADV_ENABLE) { - if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE)) { - osi_sem_take(&adv_enable_sem, OSI_SEM_MAX_TIMEOUT); - rt = adv_enable_status; - } else { + if (btsnd_hcic_ble_set_adv_enable (BTM_BLE_ADV_ENABLE) != HCI_SUCCESS) { rt = BTM_BAD_VALUE_RET; + BTM_TRACE_WARNING ("restart adv failed"); } } #endif // #if (BLE_42_ADV_EN == TRUE) #if (BLE_42_SCAN_EN == TRUE) if (BTM_BLE_IS_DISCO_ACTIVE(btm_cb.ble_ctr_cb.scan_activity)) { - if (btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, btm_cb.ble_ctr_cb.inq_var.scan_duplicate_filter)) { - osi_sem_take(&scan_enable_sem, OSI_SEM_MAX_TIMEOUT); - rt = scan_enable_status; - } else { + if ((btsnd_hcic_ble_set_scan_enable (BTM_BLE_SCAN_ENABLE, btm_cb.ble_ctr_cb.inq_var.scan_duplicate_filter)) != HCI_SUCCESS) { rt = BTM_BAD_VALUE_RET; + BTM_TRACE_WARNING ("restart scan failed"); } } #endif // #if (BLE_42_SCAN_EN == TRUE) -#if (BLE_42_ADV_EN == TRUE) - osi_mutex_unlock(&adv_enable_lock); -#endif // #if (BLE_42_ADV_EN == TRUE) -#if (BLE_42_SCAN_EN == TRUE) - osi_mutex_unlock(&scan_enable_lock); -#endif // #if (BLE_42_SCAN_EN == TRUE) +#if ((BLE_42_ADV_EN == TRUE) || (BLE_42_SCAN_EN == TRUE)) + osi_mutex_unlock(&btm_lock); +#endif // ((BLE_42_ADV_EN == TRUE) || (BLE_42_SCAN_EN == TRUE)) return rt; } - +#if (BLE_42_ADV_EN == TRUE) /******************************************************************************* ** ** Function btm_ble_start_slow_adv @@ -3730,7 +3557,6 @@ tBTM_STATUS btm_ble_set_random_addr(BD_ADDR random_bda) *******************************************************************************/ static void btm_ble_start_slow_adv (void) { -#if (BLE_42_ADV_EN == TRUE) tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; if (p_cb->adv_mode == BTM_BLE_ADV_ENABLE) { @@ -3751,8 +3577,8 @@ static void btm_ble_start_slow_adv (void) p_cb->adv_chnl_map, p_cb->afp); btm_ble_start_adv(); } -#endif // #if (BLE_42_ADV_EN == TRUE) } +#endif // #if (BLE_42_ADV_EN == TRUE) /******************************************************************************* ** ** Function btm_ble_timeout @@ -3770,7 +3596,9 @@ void btm_ble_timeout(TIMER_LIST_ENT *p_tle) case BTU_TTYPE_BLE_OBSERVE: break; case BTU_TTYPE_BLE_SCAN: +#if (BLE_42_SCAN_EN == TRUE) btm_ble_stop_discover(); +#endif break; case BTU_TTYPE_BLE_INQUIRY: break; @@ -3793,8 +3621,10 @@ void btm_ble_timeout(TIMER_LIST_ENT *p_tle) break; case BTU_TTYPE_BLE_GAP_FAST_ADV: +#if (BLE_42_ADV_EN == TRUE) /* fast adv is completed, fall back to slow adv interval */ btm_ble_start_slow_adv(); +#endif break; default: @@ -4225,74 +4055,66 @@ BOOLEAN BTM_Ble_Authorization(BD_ADDR bd_addr, BOOLEAN authorize) ** Parameter p_clear_adv_cback - Command complete callback ** *******************************************************************************/ -BOOLEAN BTM_BleClearAdv(tBTM_CLEAR_ADV_CMPL_CBACK *p_clear_adv_cback) +BOOLEAN BTM_BleClearAdv(void) { - tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb; - if (btsnd_hcic_ble_clear_adv() == FALSE) { BTM_TRACE_ERROR("%s: Unable to Clear Advertising", __FUNCTION__); return FALSE; } - p_cb->inq_var.p_clear_adv_cb = p_clear_adv_cback; return TRUE; } -BOOLEAN BTM_BleSetCsaSupport(UINT8 csa_select, tBTM_SET_CSA_SUPPORT_CMPL_CBACK *p_callback) +BOOLEAN BTM_BleSetCsaSupport(UINT8 csa_select) { if (btsnd_hcic_ble_set_csa_support(csa_select) != TRUE) { BTM_TRACE_ERROR("LE SetCsaSupport csa_select=%d: error", csa_select); return FALSE; } - btm_cb.ble_ctr_cb.set_csa_support_cmpl_cb = p_callback; return TRUE; } -BOOLEAN BTM_BleSetVendorEventMask(UINT32 evt_mask, tBTM_SET_VENDOR_EVT_MASK_CBACK *p_callback) +BOOLEAN BTM_BleSetVendorEventMask(UINT32 evt_mask) { if (btsnd_hcic_ble_set_vendor_evt_mask(evt_mask) != TRUE) { BTM_TRACE_ERROR("LE SetVendorEventMask evt_mask=%x: error", evt_mask); return FALSE; } - btm_cb.ble_ctr_cb.set_vendor_evt_mask_cmpl_cb = p_callback; return TRUE; } #endif // #if (BLE_VENDOR_HCI_EN == TRUE) -BOOLEAN BTM_BleSetRpaTimeout(uint16_t rpa_timeout,tBTM_SET_RPA_TIMEOUT_CMPL_CBACK *p_set_rpa_timeout_cback) +BOOLEAN BTM_BleSetRpaTimeout(uint16_t rpa_timeout) { if ((btsnd_hcic_ble_set_rand_priv_addr_timeout(rpa_timeout)) != TRUE) { BTM_TRACE_ERROR("Set RPA Timeout error, rpa_timeout:0x%04x",rpa_timeout); return FALSE; } - btm_cb.devcb.p_ble_set_rpa_timeout_cmpl_cb = p_set_rpa_timeout_cback; return TRUE; } BOOLEAN BTM_BleAddDevToResolvingList(BD_ADDR addr, uint8_t addr_type, - uint8_t irk[], - tBTM_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *p_add_dev_to_resolving_list_callback) + uint8_t irk[]) { UINT8 *local_irk = btm_cb.devcb.id_keys.irk; if ((btsnd_hcic_ble_add_device_resolving_list(addr_type, addr, irk, local_irk)) != TRUE) { BTM_TRACE_ERROR("Add device to resolving list error"); return FALSE; } - btm_cb.devcb.p_add_dev_to_resolving_list_cmpl_cb = p_add_dev_to_resolving_list_callback; + return TRUE; } -BOOLEAN BTM_BleSetPrivacyMode(UINT8 addr_type, BD_ADDR bd_addr, UINT8 privacy_mode, tBTM_SET_PRIVACY_MODE_CMPL_CBACK *p_callback) +BOOLEAN BTM_BleSetPrivacyMode(UINT8 addr_type, BD_ADDR bd_addr, UINT8 privacy_mode) { if (btsnd_hcic_ble_set_privacy_mode(addr_type, bd_addr, privacy_mode) != TRUE) { BTM_TRACE_ERROR("LE SetPrivacyMode Mode=%d: error", privacy_mode); return FALSE; } - btm_cb.devcb.p_set_privacy_mode_cmpl_cb = p_callback; return TRUE; } diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c b/components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c index 72dbebd24b..1bf66625fc 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c @@ -32,6 +32,7 @@ #include "btm_int.h" #include "device/controller.h" #include "stack/hcidefs.h" +#include "bta_dm_gap.h" #define HCI_VENDOR_BLE_RPA_VSC (0x0155 | HCI_GRP_VENDOR_SPECIFIC) @@ -294,14 +295,10 @@ void btm_ble_add_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len) { UINT8 status; STREAM_TO_UINT8(status, p); - if (btm_cb.devcb.p_add_dev_to_resolving_list_cmpl_cb) { - tBTM_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *p_cb = btm_cb.devcb.p_add_dev_to_resolving_list_cmpl_cb; - if (p_cb) { - (*p_cb)(status); - } - } else { - BTM_TRACE_DEBUG("no resolving list callback"); - } + + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_ADD_DEV_TO_RPA_LIST_EVT, &cb_params); BTM_TRACE_DEBUG("%s status = %d", __func__, status); @@ -441,19 +438,17 @@ void btm_ble_set_addr_resolution_enable_complete(UINT8 *p, UINT16 evt_len) tBTM_LE_RANDOM_CB *random_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; - if (!(random_cb && random_cb->set_local_privacy_cback)) { + if (random_cb->cb_is_triggered) { return; } - if (status == HCI_SUCCESS) { - random_cb->set_local_privacy_cback(BTM_SUCCESS); - return; - } else if (status == HCI_ERR_COMMAND_DISALLOWED) { - BTM_TRACE_ERROR("a non-connected activity is ongoing, such as advertising and scanning"); - } else { - BTM_TRACE_ERROR("set local privacy failed"); + if (status != HCI_SUCCESS) { + BTM_TRACE_ERROR("set local privacy failed with status: 0x%x", status); } - random_cb->set_local_privacy_cback(BTM_ILLEGAL_VALUE); + random_cb->cb_is_triggered = true; + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = (status == HCI_SUCCESS)? BTM_SUCCESS : BTM_ILLEGAL_VALUE; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_SET_PRIVACY_EVT, &cb_params); } /******************************************************************************* @@ -478,11 +473,9 @@ void btm_ble_set_rpa_timeout_complete(UINT8 *p, UINT16 evt_len) BTM_TRACE_DEBUG("%s status = %d", __func__, status); - tBTM_SET_RPA_TIMEOUT_CMPL_CBACK *p_cb = btm_cb.devcb.p_ble_set_rpa_timeout_cmpl_cb; - - if (p_cb) { - (*p_cb)(status); - } + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_RPA_TIMEOUT_EVT, &cb_params); } @@ -507,11 +500,9 @@ void btm_ble_set_privacy_mode_complete(UINT8 *p, UINT16 evt_len) BTM_TRACE_DEBUG("%s status = 0x%x", __func__, status); - tBTM_SET_PRIVACY_MODE_CMPL_CBACK *p_cb = btm_cb.devcb.p_set_privacy_mode_cmpl_cb; - - if (p_cb) { - (*p_cb)(status); - } + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_SET_PRIVACY_MODE_COMPLETE_EVT, &cb_params); } #if (0) diff --git a/components/bt/host/bluedroid/stack/btm/btm_devctl.c b/components/bt/host/bluedroid/stack/btm/btm_devctl.c index 4b70ca1c60..1cc41f7e68 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_devctl.c +++ b/components/bt/host/bluedroid/stack/btm/btm_devctl.c @@ -42,6 +42,7 @@ #if BLE_INCLUDED == TRUE #include "gatt_int.h" #endif /* BLE_INCLUDED */ +#include "bta_dm_gap.h" //extern thread_t *bt_workqueue_thread; @@ -769,7 +770,6 @@ void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len, tBTM_CMPL_CB *p_vsc_cplt_cback) { #if (BLE_INCLUDED == TRUE) - tBTM_BLE_CB *ble_cb = &btm_cb.ble_ctr_cb; switch(opcode) { case HCI_VENDOR_BLE_UPDATE_DUPLICATE_EXCEPTIONAL_LIST: { #if ((BLE_42_SCAN_EN == TRUE) || (BLE_50_EXTEND_SCAN_EN == TRUE)) @@ -777,34 +777,38 @@ void btm_vsc_complete (UINT8 *p, UINT16 opcode, UINT16 evt_len, STREAM_TO_UINT8(status, p); STREAM_TO_UINT8(subcode, p); STREAM_TO_UINT32(length, p); - if(ble_cb && ble_cb->update_exceptional_list_cmp_cb) { - (*ble_cb->update_exceptional_list_cmp_cb)(status, subcode, length, p); - } + + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.exception_list_up.status = status; + cb_params.exception_list_up.subcode = subcode; + cb_params.exception_list_up.length = length; + cb_params.exception_list_up.device_info = p; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_EXCEPTION_LIST_UPDATE_EVT, &cb_params); #endif // ((BLE_42_SCAN_EN == TRUE) || (BLE_50_EXTEND_SCAN_EN == TRUE)) - break; + break; } case HCI_VENDOR_BLE_CLEAR_ADV: { uint8_t status; STREAM_TO_UINT8(status, p); - if (ble_cb && ble_cb->inq_var.p_clear_adv_cb) { - ble_cb->inq_var.p_clear_adv_cb(status); - } + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_CLEAR_ADV_COMPLETE_EVT, &cb_params); break; } case HCI_VENDOR_BLE_SET_CSA_SUPPORT: { uint8_t status; STREAM_TO_UINT8(status, p); - if (ble_cb && ble_cb->set_csa_support_cmpl_cb) { - ble_cb->set_csa_support_cmpl_cb(status); - } + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_SET_CSA_SUPPORT_COMPLETE_EVT, &cb_params); break; } case HCI_VENDOR_BLE_SET_EVT_MASK: { uint8_t status; STREAM_TO_UINT8(status, p); - if (ble_cb && ble_cb->set_vendor_evt_mask_cmpl_cb) { - ble_cb->set_vendor_evt_mask_cmpl_cb(status); - } + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.status = status; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_SET_VENDOR_EVT_MASK_COMPLETE_EVT, &cb_params); break; } default: @@ -1286,20 +1290,12 @@ void btm_set_afh_channels_complete (UINT8 *p) ** Returns status of the operation ** *******************************************************************************/ -tBTM_STATUS BTM_BleSetChannels (BLE_CHANNELS channels, tBTM_CMPL_CB *p_ble_channels_cmpl_cback) +tBTM_STATUS BTM_BleSetChannels (BLE_CHANNELS channels) { if (!controller_get_interface()->get_is_ready()) { return (BTM_DEV_RESET); } - /* Check if set afh already in progress */ - if (btm_cb.devcb.p_ble_channels_cmpl_cb) { - return (BTM_NO_RESOURCES); - } - - /* Save callback */ - btm_cb.devcb.p_ble_channels_cmpl_cb = p_ble_channels_cmpl_cback; - if (!btsnd_hcic_ble_set_channels (channels)) { return (BTM_NO_RESOURCES); } @@ -1321,30 +1317,24 @@ tBTM_STATUS BTM_BleSetChannels (BLE_CHANNELS channels, tBTM_CMPL_CB *p_ble_chann *******************************************************************************/ void btm_ble_set_channels_complete (UINT8 *p) { - tBTM_CMPL_CB *p_cb = btm_cb.devcb.p_ble_channels_cmpl_cb; - tBTM_BLE_SET_CHANNELS_RESULTS results; + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; btu_free_timer (&btm_cb.devcb.ble_channels_timer); - /* If there is a callback address for setting AFH channels, call it */ - btm_cb.devcb.p_ble_channels_cmpl_cb = NULL; + STREAM_TO_UINT8 (cb_params.set_channels.hci_status, p); - if (p_cb) { - STREAM_TO_UINT8 (results.hci_status, p); - - switch (results.hci_status){ - case HCI_SUCCESS: - results.status = BTM_SUCCESS; - break; - case HCI_ERR_UNSUPPORTED_VALUE: - case HCI_ERR_ILLEGAL_PARAMETER_FMT: - results.status = BTM_ILLEGAL_VALUE; - break; - default: - results.status = BTM_ERR_PROCESSING; - break; - } - (*p_cb)(&results); + switch (cb_params.set_channels.hci_status){ + case HCI_SUCCESS: + cb_params.set_channels.status = BTM_SUCCESS; + break; + case HCI_ERR_UNSUPPORTED_VALUE: + case HCI_ERR_ILLEGAL_PARAMETER_FMT: + cb_params.set_channels.status = BTM_ILLEGAL_VALUE; + break; + default: + cb_params.set_channels.status = BTM_ERR_PROCESSING; + break; } + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_SET_CHANNELS_COMPLETE_EVT, &cb_params); } #endif /// BLE_INCLUDED == TRUE diff --git a/components/bt/host/bluedroid/stack/btm/btm_main.c b/components/bt/host/bluedroid/stack/btm/btm_main.c index 5543047786..5392ac4b55 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_main.c +++ b/components/bt/host/bluedroid/stack/btm/btm_main.c @@ -88,7 +88,6 @@ void btm_init (void) btm_dev_init(); /* Device Manager Structures & HCI_Reset */ #if BLE_INCLUDED == TRUE btm_ble_lock_init(); - btm_ble_sem_init(); #if ((SMP_INCLUDED == TRUE) || (BLE_PRIVACY_SPT == TRUE)) btm_cb.addr_res_en = TRUE; #endif // ((SMP_INCLUDED == TRUE) || (BLE_PRIVACY_SPT == TRUE)) @@ -131,7 +130,6 @@ void btm_free(void) #endif #if BLE_INCLUDED == TRUE btm_ble_lock_free(); - btm_ble_sem_free(); #endif } diff --git a/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h b/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h index 9340c81dd8..3005ec2d48 100644 --- a/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h +++ b/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h @@ -157,9 +157,6 @@ typedef struct { UINT16 adv_interval_max; tBTM_BLE_AFP afp; /* advertising filter policy */ tBTM_BLE_SFP sfp; /* scanning filter policy */ - tBTM_START_ADV_CMPL_CBACK *p_adv_cb; - tBTM_START_STOP_ADV_CMPL_CBACK *p_stop_adv_cb; - tBTM_CLEAR_ADV_CMPL_CBACK *p_clear_adv_cb; tBLE_ADDR_TYPE adv_addr_type; UINT8 evt_type; UINT8 adv_mode; @@ -206,7 +203,7 @@ typedef struct { tBTM_BLE_ADDR_CBACK *p_generate_cback; void *p; TIMER_LIST_ENT raddr_timer_ent; - tBTM_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback; + bool cb_is_triggered; } tBTM_LE_RANDOM_CB; #define BTM_BLE_MAX_BG_CONN_DEV_NUM 10 @@ -358,7 +355,6 @@ typedef struct { /* periodic list information */ UINT8 periodic_adv_list_size; #endif //#if (BLE_50_EXTEND_SYNC_EN == TRUE) - tBTM_UPDATE_WHITELIST_CBACK *update_wl_cb; tBTM_BLE_WL_STATE wl_state; fixed_queue_t *conn_pending_q; @@ -386,13 +382,6 @@ typedef struct { tBTM_BLE_STATE_MASK cur_states; /* bit mask of tBTM_BLE_STATE */ UINT8 link_count[2]; /* total link count master and slave*/ #endif // (BLE_TOPOLOGY_CHECK == TRUE) -#if ((BLE_42_SCAN_EN == TRUE) || (BLE_50_EXTEND_SCAN_EN == TRUE)) - tBTM_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK *update_exceptional_list_cmp_cb; -#endif // ((BLE_42_SCAN_EN == TRUE) || (BLE_50_EXTEND_SCAN_EN == TRUE)) -#if (BLE_VENDOR_HCI_EN == TRUE) - tBTM_SET_CSA_SUPPORT_CMPL_CBACK *set_csa_support_cmpl_cb; - tBTM_SET_VENDOR_EVT_MASK_CBACK *set_vendor_evt_mask_cmpl_cb; -#endif // (BLE_VENDOR_HCI_EN == TRUE) } tBTM_BLE_CB; #ifdef __cplusplus @@ -464,10 +453,10 @@ void btm_ble_update_sec_key_size(BD_ADDR bd_addr, UINT8 enc_key_size); UINT8 btm_ble_read_sec_key_size(BD_ADDR bd_addr); /* white list function */ -BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBTM_UPDATE_WHITELIST_CBACK *update_wl_cb); +BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type); void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy); void btm_update_adv_filter_policy(tBTM_BLE_AFP adv_policy); -void btm_ble_clear_white_list (tBTM_UPDATE_WHITELIST_CBACK *update_wl_cb); +void btm_ble_clear_white_list (void); void btm_read_white_list_size_complete(UINT8 *p, UINT16 evt_len); void btm_ble_add_2_white_list_complete(UINT8 status); void btm_ble_remove_from_white_list_complete(UINT8 *p, UINT16 evt_len); diff --git a/components/bt/host/bluedroid/stack/btm/include/btm_int.h b/components/bt/host/bluedroid/stack/btm/include/btm_int.h index 6c13beaa50..c0a1e2f2e2 100644 --- a/components/bt/host/bluedroid/stack/btm/include/btm_int.h +++ b/components/bt/host/bluedroid/stack/btm/include/btm_int.h @@ -158,12 +158,10 @@ UINT8 conn_addr_type; /* local device address type for this co BD_ADDR active_remote_addr; /* remote address used on this connection */ UINT8 active_remote_addr_type; /* local device address type for this connection */ BD_FEATURES peer_le_features; /* Peer LE Used features mask for the device */ -tBTM_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback; tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS data_length_params; BOOLEAN data_len_updating; // data len update cmd cache BOOLEAN data_len_waiting; -tBTM_SET_PKT_DATA_LENGTH_CBACK *p_set_data_len_cback_waiting; UINT16 tx_len_waiting; #endif tBTM_PM_MCB *p_pm_mode_db; /* Pointer to PM mode control block per ACL link */ @@ -241,7 +239,7 @@ tBTM_CMPL_CB *p_write_iscan_tx_pwr_lvl_cmpl_cb; /* Callback function t #endif // (CLASSIC_BT_INCLUDED == TRUE) #if BLE_INCLUDED == TRUE -tBTM_CMPL_CB *p_ble_ch_map_cmpl_cb; /* Callback function to be called when */ +BOOLEAN is_ch_map_cb; #endif // #if BLE_INCLUDED == TRUE /* read channel map function completes */ #if (CLASSIC_BT_INCLUDED == TRUE) @@ -292,15 +290,6 @@ DEV_CLASS dev_class; /* Local device class #if BLE_INCLUDED == TRUE TIMER_LIST_ENT ble_channels_timer; -tBTM_CMPL_CB *p_ble_channels_cmpl_cb; /* Callback function to be called When - ble set host channels is completed */ - -tBTM_SET_RPA_TIMEOUT_CMPL_CBACK *p_ble_set_rpa_timeout_cmpl_cb; /* Callback function to be called When - ble set rpa timeout is completed */ - -tBTM_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *p_add_dev_to_resolving_list_cmpl_cb; - -tBTM_SET_PRIVACY_MODE_CMPL_CBACK *p_set_privacy_mode_cmpl_cb; tBTM_CMPL_CB *p_le_test_cmd_cmpl_cb; /* Callback function to be called when LE test mode command has been sent successfully */ @@ -1053,14 +1042,6 @@ typedef struct { #endif } tBTM_CB; -typedef struct{ - //connection parameters update callback - tBTM_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb; - // setting packet data length callback - tBTM_SET_PKT_DATA_LENGTH_CBACK *set_pkt_data_length_cb; -}tBTM_CallbackFunc; - -extern tBTM_CallbackFunc conn_callback_func; /* security action for L2CAP COC channels */ #define BTM_SEC_OK 1 #define BTM_SEC_ENCRYPT 2 /* encrypt the link with current key */ @@ -1365,10 +1346,6 @@ void btm_sec_clr_temp_auth_service (BD_ADDR bda); void btm_ble_lock_init(void); -void btm_ble_sem_init(void); - -void btm_ble_sem_free(void); - void btm_ble_lock_free(void); void btm_sec_handle_remote_legacy_auth_cmp(UINT16 handle); diff --git a/components/bt/host/bluedroid/stack/btu/btu_hcif.c b/components/bt/host/bluedroid/stack/btu/btu_hcif.c index 39fb65e20b..b5e0382aa7 100644 --- a/components/bt/host/bluedroid/stack/btu/btu_hcif.c +++ b/components/bt/host/bluedroid/stack/btu/btu_hcif.c @@ -254,20 +254,6 @@ static void btu_ble_cs_subevt_result_evt(UINT8 *p, UINT8 evt_len); static void btu_ble_cs_subevt_result_continue_evt(UINT8 *p, UINT8 evt_len); #endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) -#if (BLE_42_ADV_EN == TRUE) -extern osi_sem_t adv_enable_sem; -extern osi_sem_t adv_data_sem; -extern osi_sem_t adv_param_sem; -extern uint8_t adv_enable_status; -extern uint8_t adv_data_status; -extern uint8_t adv_param_status; -#endif // #if (BLE_42_ADV_EN == TRUE) -#if (BLE_42_SCAN_EN == TRUE) -extern osi_sem_t scan_enable_sem; -extern osi_sem_t scan_param_sem; -extern uint8_t scan_enable_status; -extern uint8_t scan_param_status; -#endif // #if (BLE_42_SCAN_EN == TRUE) #endif /******************************************************************************* @@ -726,7 +712,7 @@ void btu_hcif_send_cmd (UNUSED_ATTR UINT8 controller_id, BT_HDR *p_buf) #endif } -#if (BLE_50_FEATURE_SUPPORT == TRUE) +#if ((BLE_50_FEATURE_SUPPORT == TRUE) || (BLE_42_FEATURE_SUPPORT == TRUE)) UINT8 btu_hcif_send_cmd_sync (UINT8 controller_id, BT_HDR *p_buf) { if (!p_buf) { @@ -777,8 +763,7 @@ UINT8 btu_hcif_send_cmd_sync (UINT8 controller_id, BT_HDR *p_buf) #endif return btsnd_hcic_ble_get_status(); } -#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) - +#endif // ((BLE_50_FEATURE_SUPPORT == TRUE) || (BLE_42_FEATURE_SUPPORT == TRUE)) /******************************************************************************* ** @@ -1523,52 +1508,14 @@ static void btu_hcif_command_complete_evt_on_task(BT_HDR *event) static void btu_hcif_command_complete_evt(BT_HDR *response, void *context) { -#if (BLE_INCLUDED == TRUE) - command_opcode_t opcode; - uint8_t *stream = response->data + response->offset + 3; - STREAM_TO_UINT16(opcode, stream); - switch (opcode) { -#if (BLE_42_ADV_EN == TRUE) - case HCI_BLE_WRITE_ADV_DATA: - adv_data_status = *stream; - osi_sem_give(&adv_data_sem); - break; - case HCI_BLE_WRITE_SCAN_RSP_DATA: - adv_data_status = *stream; - osi_sem_give(&adv_data_sem); - break; - case HCI_BLE_WRITE_ADV_ENABLE: { - adv_enable_status = *stream; - osi_sem_give(&adv_enable_sem); - break; - } - case HCI_BLE_WRITE_ADV_PARAMS: - adv_param_status = *stream; - osi_sem_give(&adv_param_sem); - break; -#endif // #if (BLE_42_ADV_EN == TRUE) -#if (BLE_42_SCAN_EN == TRUE) - case HCI_BLE_WRITE_SCAN_PARAMS: - scan_param_status = *stream; - osi_sem_give(&scan_param_sem); - break; - case HCI_BLE_WRITE_SCAN_ENABLE: - scan_enable_status = *stream; - osi_sem_give(&scan_enable_sem); - break; -#endif // #if (BLE_42_SCAN_EN == TRUE) - default: - break; - } -#endif BT_HDR *event = osi_calloc(sizeof(BT_HDR) + sizeof(command_complete_hack_t)); command_complete_hack_t *hack = (command_complete_hack_t *)&event->data[0]; -#if (BLE_50_FEATURE_SUPPORT == TRUE) +#if ((BLE_50_FEATURE_SUPPORT == TRUE) || (BLE_42_FEATURE_SUPPORT == TRUE)) UINT8 status = 0; - stream = response->data + response->offset + 3 + 2; // 2 to skip the event headers, 1 to skip the command credits, 2 to opcode. + uint8_t *stream = response->data + response->offset + 3 + 2; // 2 to skip the event headers, 1 to skip the command credits, 2 to opcode. STREAM_TO_UINT8(status, stream); btsnd_hci_ble_set_status(status); -#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) +#endif // #if ((BLE_50_FEATURE_SUPPORT == TRUE) || (BLE_42_FEATURE_SUPPORT == TRUE)) HCI_TRACE_DEBUG("btu_hcif_command_complete_evt\n"); hack->callback = btu_hcif_command_complete_evt_on_task; diff --git a/components/bt/host/bluedroid/stack/gatt/gatt_utils.c b/components/bt/host/bluedroid/stack/gatt/gatt_utils.c index b536468e2e..0782a32c16 100644 --- a/components/bt/host/bluedroid/stack/gatt/gatt_utils.c +++ b/components/bt/host/bluedroid/stack/gatt/gatt_utils.c @@ -2542,7 +2542,7 @@ BOOLEAN gatt_add_bg_dev_list(tGATT_REG *p_reg, BD_ADDR bd_addr, BOOLEAN is_init if (i == 0) { // To check, we do not support background connection, code will not be called here - ret = BTM_BleUpdateAdvWhitelist(TRUE, bd_addr, 0, NULL); + ret = BTM_BleUpdateAdvWhitelist(TRUE, bd_addr, 0); } else { ret = TRUE; } @@ -2683,7 +2683,7 @@ BOOLEAN gatt_remove_bg_dev_from_list(tGATT_REG *p_reg, BD_ADDR bd_addr, BOOLEAN if (p_dev->listen_gif[0] == 0) { // To check, we do not support background connection, code will not be called here - ret = BTM_BleUpdateAdvWhitelist(FALSE, p_dev->remote_bda, 0, NULL); + ret = BTM_BleUpdateAdvWhitelist(FALSE, p_dev->remote_bda, 0); } else { ret = TRUE; } @@ -2745,7 +2745,7 @@ void gatt_deregister_bgdev_list(tGATT_IF gatt_if) if (p_dev_list->listen_gif[0] == 0) { // To check, we do not support background connection, code will not be called here - BTM_BleUpdateAdvWhitelist(FALSE, p_dev_list->remote_bda, 0, NULL); + BTM_BleUpdateAdvWhitelist(FALSE, p_dev_list->remote_bda, 0); } } } diff --git a/components/bt/host/bluedroid/stack/hcic/hciblecmds.c b/components/bt/host/bluedroid/stack/hcic/hciblecmds.c index 445c61ec06..4b365e16ed 100644 --- a/components/bt/host/bluedroid/stack/hcic/hciblecmds.c +++ b/components/bt/host/bluedroid/stack/hcic/hciblecmds.c @@ -33,7 +33,7 @@ #include #include -#if (BLE_50_FEATURE_SUPPORT == TRUE) +#if ((BLE_50_FEATURE_SUPPORT == TRUE) || (BLE_42_FEATURE_SUPPORT == TRUE)) static BlE_SYNC ble_sync_info; void btsnd_hcic_ble_sync_sem_init(void) @@ -63,7 +63,7 @@ void btsnd_hci_ble_set_status(UINT8 hci_status) ble_sync_info.status = hci_status; return; } -#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) +#endif // ((BLE_50_FEATURE_SUPPORT == TRUE) || (BLE_42_FEATURE_SUPPORT == TRUE)) #if (defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE) @@ -111,7 +111,7 @@ BOOLEAN btsnd_hcic_ble_set_random_addr (BD_ADDR random_bda) return (TRUE); } -BOOLEAN btsnd_hcic_ble_write_adv_params (UINT16 adv_int_min, UINT16 adv_int_max, +UINT8 btsnd_hcic_ble_write_adv_params (UINT16 adv_int_min, UINT16 adv_int_max, UINT8 adv_type, UINT8 addr_type_own, UINT8 addr_type_dir, BD_ADDR direct_bda, UINT8 channel_map, UINT8 adv_filter_policy) @@ -119,7 +119,7 @@ BOOLEAN btsnd_hcic_ble_write_adv_params (UINT16 adv_int_min, UINT16 adv_int_max, BT_HDR *p; UINT8 *pp; if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_ADV_PARAMS)) == NULL) { - return (FALSE); + return HCI_ERR_MEMORY_FULL; } pp = (UINT8 *)(p + 1); @@ -139,9 +139,9 @@ BOOLEAN btsnd_hcic_ble_write_adv_params (UINT16 adv_int_min, UINT16 adv_int_max, UINT8_TO_STREAM (pp, channel_map); UINT8_TO_STREAM (pp, adv_filter_policy); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); - return (TRUE); + return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p); } + BOOLEAN btsnd_hcic_ble_read_adv_chnl_tx_power (void) { BT_HDR *p; @@ -164,7 +164,7 @@ BOOLEAN btsnd_hcic_ble_read_adv_chnl_tx_power (void) } -BOOLEAN btsnd_hcic_ble_set_adv_data (UINT8 data_len, UINT8 *p_data) +UINT8 btsnd_hcic_ble_set_adv_data (UINT8 data_len, UINT8 *p_data) { BT_HDR *p; UINT8 *pp; @@ -174,7 +174,7 @@ BOOLEAN btsnd_hcic_ble_set_adv_data (UINT8 data_len, UINT8 *p_data) } if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_ADV_DATA + 1)) == NULL) { - return (FALSE); + return HCI_ERR_MEMORY_FULL; } pp = (UINT8 *)(p + 1); @@ -197,17 +197,16 @@ BOOLEAN btsnd_hcic_ble_set_adv_data (UINT8 data_len, UINT8 *p_data) ARRAY_TO_STREAM (pp, p_data, data_len); } - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); - - return (TRUE); + return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p); } -BOOLEAN btsnd_hcic_ble_set_scan_rsp_data (UINT8 data_len, UINT8 *p_scan_rsp) + +UINT8 btsnd_hcic_ble_set_scan_rsp_data (UINT8 data_len, UINT8 *p_scan_rsp) { BT_HDR *p; UINT8 *pp; if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_SCAN_RSP + 1)) == NULL) { - return (FALSE); + return HCI_ERR_MEMORY_FULL; } pp = (UINT8 *)(p + 1); @@ -232,18 +231,16 @@ BOOLEAN btsnd_hcic_ble_set_scan_rsp_data (UINT8 data_len, UINT8 *p_scan_rsp) ARRAY_TO_STREAM (pp, p_scan_rsp, data_len); } - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); - - return (TRUE); + return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p); } -BOOLEAN btsnd_hcic_ble_set_adv_enable (UINT8 adv_enable) +UINT8 btsnd_hcic_ble_set_adv_enable (UINT8 adv_enable) { BT_HDR *p; UINT8 *pp; if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_ADV_ENABLE)) == NULL) { - return (FALSE); + return HCI_ERR_MEMORY_FULL; } pp = (UINT8 *)(p + 1); @@ -256,10 +253,10 @@ BOOLEAN btsnd_hcic_ble_set_adv_enable (UINT8 adv_enable) UINT8_TO_STREAM (pp, adv_enable); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); - return (TRUE); + return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p); } -BOOLEAN btsnd_hcic_ble_set_scan_params (UINT8 scan_type, + +UINT8 btsnd_hcic_ble_set_scan_params (UINT8 scan_type, UINT16 scan_int, UINT16 scan_win, UINT8 addr_type_own, UINT8 scan_filter_policy) { @@ -267,7 +264,7 @@ BOOLEAN btsnd_hcic_ble_set_scan_params (UINT8 scan_type, UINT8 *pp; if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_SCAN_PARAM)) == NULL) { - return (FALSE); + return HCI_ERR_MEMORY_FULL; } pp = (UINT8 *)(p + 1); @@ -284,17 +281,16 @@ BOOLEAN btsnd_hcic_ble_set_scan_params (UINT8 scan_type, UINT8_TO_STREAM (pp, addr_type_own); UINT8_TO_STREAM (pp, scan_filter_policy); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); - return (TRUE); + return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p); } -BOOLEAN btsnd_hcic_ble_set_scan_enable (UINT8 scan_enable, UINT8 duplicate) +UINT8 btsnd_hcic_ble_set_scan_enable (UINT8 scan_enable, UINT8 duplicate) { BT_HDR *p; UINT8 *pp; if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_WRITE_SCAN_ENABLE)) == NULL) { - return (FALSE); + return HCI_ERR_MEMORY_FULL; } pp = (UINT8 *)(p + 1); @@ -308,8 +304,7 @@ BOOLEAN btsnd_hcic_ble_set_scan_enable (UINT8 scan_enable, UINT8 duplicate) UINT8_TO_STREAM (pp, scan_enable); UINT8_TO_STREAM (pp, duplicate); - btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p); - return (TRUE); + return btu_hcif_send_cmd_sync (LOCAL_BR_EDR_CONTROLLER_ID, p); } /* link layer connection management commands */ @@ -1103,6 +1098,16 @@ BOOLEAN btsnd_hcic_ble_set_channels (BLE_CHANNELS channels) p->offset = 0; \ } while(0) +/* For UINT8-returning functions that call btu_hcif_send_cmd_sync (return HCI status) */ +#define HCIC_BLE_CMD_CREATED_U8(p, pp, size) do{\ + if ((p = HCI_GET_CMD_BUF(size)) == NULL) { \ + return HCI_ERR_MEMORY_FULL; \ + } \ + pp = p->data; \ + p->len = HCIC_PREAMBLE_SIZE + size;\ + p->offset = 0; \ +} while(0) + #if (BLE_50_FEATURE_SUPPORT == TRUE) BOOLEAN btsnd_hcic_ble_read_phy(UINT16 conn_handle) @@ -1129,7 +1134,7 @@ UINT8 btsnd_hcic_ble_set_prefered_default_phy(UINT8 all_phys, UINT8 *pp; HCI_TRACE_EVENT("%s, all_phys = %d, tx_phys = %d, rx_phys = %d", __func__, all_phys, tx_phys, rx_phys); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_BLE_SET_DEF_PHY); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_BLE_SET_DEF_PHY); UINT16_TO_STREAM(pp, HCI_BLE_SET_DEFAULT_PHY); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_BLE_SET_DEF_PHY); @@ -1217,7 +1222,7 @@ UINT8 btsnd_hcic_ble_set_extend_rand_address(UINT8 adv_handle, BD_ADDR rand_addr UINT8 *pp; HCI_TRACE_EVENT("%s, adv_handle = %d", __func__, adv_handle); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_EXT_RAND_ADDR); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_EXT_RAND_ADDR); UINT16_TO_STREAM (pp, HCI_BLE_SET_ADV_RAND_ADDR); UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_EXT_RAND_ADDR); @@ -1249,7 +1254,7 @@ UINT8 btsnd_hcic_ble_set_ext_adv_params_v2(UINT8 adv_handle, UINT16 properties, primary_adv_phy, secondary_adv_max_skip, secondary_adv_phy, adv_sid, scan_req_ntf_enable, primary_adv_phy_options, secondary_adv_phy_options); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_EXT_ADV_SET_PARAMS + 2); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_EXT_ADV_SET_PARAMS + 2); UINT16_TO_STREAM(pp, HCI_BLE_SET_EXT_ADV_PARAM_V2); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_EXT_ADV_SET_PARAMS + 2); @@ -1295,7 +1300,7 @@ UINT8 btsnd_hcic_ble_set_ext_adv_params(UINT8 adv_handle, UINT16 properties, UIN channel_map, own_addr_type, peer_addr_type, adv_filter_policy, adv_tx_power, primary_adv_phy, secondary_adv_max_skip, secondary_adv_phy, adv_sid, scan_req_ntf_enable); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_EXT_ADV_SET_PARAMS); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_EXT_ADV_SET_PARAMS); UINT16_TO_STREAM(pp, HCI_BLE_SET_EXT_ADV_PARAM); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_EXT_ADV_SET_PARAMS); @@ -1333,7 +1338,7 @@ UINT8 btsnd_hcic_ble_set_ext_adv_data(UINT8 adv_handle, data_len = HCIC_PARAM_SIZE_EXT_ADV_WRITE_DATA; } - HCIC_BLE_CMD_CREATED(p, pp, data_len + 4); + HCIC_BLE_CMD_CREATED_U8(p, pp, data_len + 4); UINT16_TO_STREAM(pp, HCI_BLE_SET_EXT_ADV_DATA); UINT8_TO_STREAM(pp, data_len + 4); UINT8_TO_STREAM(pp, adv_handle); @@ -1365,7 +1370,7 @@ UINT8 btsnd_hcic_ble_set_ext_adv_scan_rsp_data(UINT8 adv_handle, data_len = HCIC_PARAM_SIZE_EXT_ADV_WRITE_DATA; } - HCIC_BLE_CMD_CREATED(p, pp, data_len + 4); + HCIC_BLE_CMD_CREATED_U8(p, pp, data_len + 4); UINT16_TO_STREAM(pp, HCI_BLE_SET_EXT_SCAN_RSP_DATA); UINT8_TO_STREAM(pp, data_len + 4); @@ -1388,7 +1393,7 @@ UINT8 btsnd_hcic_ble_ext_adv_enable(UINT8 enable, UINT8 num_of_sets, UINT8 *adv_ BT_HDR *p; UINT8 *pp; UINT8 ext_adv_size = num_of_sets*4 + 2; - HCIC_BLE_CMD_CREATED(p, pp, ext_adv_size); + HCIC_BLE_CMD_CREATED_U8(p, pp, ext_adv_size); HCI_TRACE_EVENT("%s, enable = %d, num_of_sets = %d", __func__, enable, num_of_sets); @@ -1417,7 +1422,7 @@ UINT8 btsnd_hcic_ble_read_max_adv_len(void) UINT8 *pp; HCI_TRACE_EVENT("%s", __func__); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_READ_MAX_ADV_SIZE); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_READ_MAX_ADV_SIZE); UINT16_TO_STREAM(pp, HCI_BLE_RD_MAX_ADV_DATA_LEN); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_MAX_ADV_SIZE); @@ -1431,7 +1436,7 @@ UINT8 btsnd_hcic_ble_read_num_support_adv_set(void) UINT8 *pp; HCI_TRACE_EVENT("%s", __func__); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_NUM_SUPPORT_ADV_SET); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_NUM_SUPPORT_ADV_SET); UINT16_TO_STREAM(pp, HCI_BLE_RD_NUM_OF_ADV_SETS); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_NUM_SUPPORT_ADV_SET); @@ -1445,7 +1450,7 @@ UINT8 btsnd_hcic_ble_remove_adv_set(UINT8 adv_handle) UINT8 *pp; HCI_TRACE_EVENT("%s, adv_handle = %d", __func__, adv_handle); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_REMOVE_ADV_SET); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_REMOVE_ADV_SET); UINT16_TO_STREAM(pp, HCI_BLE_REMOVE_ADV_SET); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_REMOVE_ADV_SET); @@ -1460,7 +1465,7 @@ UINT8 btsnd_hcic_ble_clear_adv_set(void) UINT8 *pp; HCI_TRACE_EVENT("%s", __func__); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_CLEAR_ADV_SET); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_CLEAR_ADV_SET); UINT16_TO_STREAM(pp, HCI_BLE_CLEAR_ADV_SETS); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CLEAR_ADV_SET); @@ -1481,7 +1486,7 @@ UINT8 btsnd_hcic_ble_set_periodic_adv_params_v2(UINT8 adv_handle, UINT16 interva HCI_TRACE_EVENT("%s, adv_handle = %d, interval_min = %d, interval_max = %d, propertics = %d num_subevents = %d subevent_interval = %d rsp_slot_delay %d rsp_slot_spacing %d num_rsp_slots %d", __func__, adv_handle, interval_min, interval_max, propertics, num_subevents, subevent_interval, rsp_slot_delay, rsp_slot_spacing, num_rsp_slots); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_PERIODIC_ADV_PARAMS_V2); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_PERIODIC_ADV_PARAMS_V2); UINT16_TO_STREAM(pp, HCI_BLE_SET_PERIOD_ADV_PARAMS_V2); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SET_PERIODIC_ADV_PARAMS_V2); @@ -1511,7 +1516,7 @@ UINT8 btsnd_hcic_ble_set_periodic_adv_params(UINT8 adv_handle, HCI_TRACE_EVENT("%s, adv_handle = %d, interval_min = %d, interval_max = %d, propertics = %d", __func__, adv_handle, interval_min, interval_max, propertics); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_PERIODIC_ADV_PARAMS); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_PERIODIC_ADV_PARAMS); UINT16_TO_STREAM(pp, HCI_BLE_SET_PERIOD_ADV_PARAMS); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SET_PERIODIC_ADV_PARAMS); @@ -1542,7 +1547,7 @@ UINT8 btsnd_hcic_ble_set_periodic_adv_data(UINT8 adv_handle, len = HCIC_PARAM_SIZE_WRITE_PERIODIC_ADV_DATA; } - HCIC_BLE_CMD_CREATED(p, pp, len + 3); + HCIC_BLE_CMD_CREATED_U8(p, pp, len + 3); UINT16_TO_STREAM(pp, HCI_BLE_SET_PERIOD_ADV_DATA); UINT8_TO_STREAM(pp, len + 3); @@ -1566,7 +1571,7 @@ UINT8 btsnd_hcic_ble_periodic_adv_enable(UINT8 enable, UINT8 adv_handle) HCI_TRACE_EVENT("%s, enable = %d, adv_handle = %d", __func__, enable, adv_handle); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_PERIODIC_ADV_ENABLE); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_PERIODIC_ADV_ENABLE); UINT16_TO_STREAM(pp, HCI_BLE_SET_PERIOD_ADV_ENABLE); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PERIODIC_ADV_ENABLE); @@ -1589,7 +1594,7 @@ UINT8 btsnd_hcic_ble_set_ext_scan_params(UINT8 own_addr_type, UINT8 filter_polic __func__, own_addr_type, filter_policy, phy_mask, phy_count); UINT8 params_size = HCIC_PARAM_SIZE_SET_EXT_SCAN_PARAMS + phy_count*5; - HCIC_BLE_CMD_CREATED(p, pp, params_size); + HCIC_BLE_CMD_CREATED_U8(p, pp, params_size); UINT16_TO_STREAM(pp, HCI_BLE_SET_EXT_SCAN_PARAMS); UINT8_TO_STREAM(pp, params_size); @@ -1615,7 +1620,7 @@ UINT8 btsnd_hcic_ble_ext_scan_enable(UINT8 enable, UINT8 filter_dups, HCI_TRACE_EVENT("%s, enable = %d, filter_dups = %d, duration = %d, period = %d", __func__, enable, filter_dups, duration, period); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_EXT_SCAN_ENABLE); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_EXT_SCAN_ENABLE); UINT16_TO_STREAM(pp, HCI_BLE_SET_EXT_SCAN_ENABLE); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_EXT_SCAN_ENABLE); @@ -1809,7 +1814,7 @@ UINT8 btsnd_hcic_ble_periodic_adv_create_sync_cancel(void) UINT8 *pp; HCI_TRACE_EVENT("%s", __func__); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_PERIODIC_ADV_CREATE_SYNC_CANCEL); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_PERIODIC_ADV_CREATE_SYNC_CANCEL); UINT16_TO_STREAM(pp, HCI_BLE_PERIOD_ADV_CREATE_SYNC_CANCEL); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PERIODIC_ADV_CREATE_SYNC_CANCEL); @@ -1823,7 +1828,7 @@ UINT8 btsnd_hcic_ble_periodic_adv_term_sync(UINT16 sync_handle) UINT8 *pp; HCI_TRACE_EVENT("%s, sync_handle = %d", __func__, sync_handle); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_PERIODIC_ADV_TERM_SYNC); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_PERIODIC_ADV_TERM_SYNC); UINT16_TO_STREAM(pp, HCI_BLE_PERIOD_ADV_TERM_SYNC); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PERIODIC_ADV_TERM_SYNC); @@ -1841,7 +1846,7 @@ UINT8 btsnd_hcic_ble_add_dev_to_periodic_adv_list(UINT8 adv_addr_type, BD_ADDR a HCI_TRACE_EVENT("%s, adv_addr_type = %d, adv_sid = %d", __func__, adv_addr_type, adv_sid); esp_log_buffer_hex_internal("addr", adv_addr, sizeof(BD_ADDR), ESP_LOG_WARN); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_ADD_DEV_TO_PERIODIC_ADV_LIST); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_ADD_DEV_TO_PERIODIC_ADV_LIST); UINT16_TO_STREAM(pp, HCI_BLE_ADV_DEV_TO_PERIOD_ADV_LIST); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ADD_DEV_TO_PERIODIC_ADV_LIST); @@ -1860,7 +1865,7 @@ UINT8 btsnd_hcic_ble_rm_dev_from_periodic_adv_list(UINT8 adv_addr_type, BD_ADDR HCI_TRACE_EVENT("%s, adv_addr_type = %d, adv_sid = %d", __func__, adv_addr_type, adv_sid); esp_log_buffer_hex_internal("addr", adv_addr, sizeof(BD_ADDR), ESP_LOG_WARN); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_RM_DEV_FROM_PERIODIC_ADV_LIST); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_RM_DEV_FROM_PERIODIC_ADV_LIST); UINT16_TO_STREAM(pp, HCI_BLE_REMOVE_DEV_FROM_PERIOD_ADV_LIST); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_RM_DEV_FROM_PERIODIC_ADV_LIST); @@ -1878,7 +1883,7 @@ UINT8 btsnd_hcic_ble_clear_periodic_adv_list(void) UINT8 *pp; HCI_TRACE_EVENT("%s", __func__); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_CLEAR_PERIODIC_ADV_LIST); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_CLEAR_PERIODIC_ADV_LIST); UINT16_TO_STREAM(pp, HCI_BLE_CLEAR_PERIOD_ADV_LIST); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CLEAR_PERIODIC_ADV_LIST); @@ -1892,7 +1897,7 @@ UINT8 btsnd_hcic_ble_read_periodic_adv_list_size(void) UINT8 *pp; HCI_TRACE_EVENT("%s", __func__); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_READ_PERIODIC_ADV_LIST); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_READ_PERIODIC_ADV_LIST); UINT16_TO_STREAM(pp, HCI_BLE_RD_PERIOD_ADV_LIST_SIZE); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_PERIODIC_ADV_LIST); @@ -1907,7 +1912,7 @@ UINT8 btsnd_hcic_ble_read_trans_power(void) UINT8 *pp; HCI_TRACE_EVENT("%s", __func__); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_READ_TRANS_POWER); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_READ_TRANS_POWER); UINT16_TO_STREAM(pp, HCI_BLE_RD_TRANSMIT_POWER); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_TRANS_POWER); @@ -1921,7 +1926,7 @@ UINT8 btsnd_hcic_ble_read_rf_path_compensation(void) UINT8 *pp; HCI_TRACE_EVENT("%s", __func__); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_READ_RF_PATH_COMPENSATION); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_READ_RF_PATH_COMPENSATION); UINT16_TO_STREAM(pp, HCI_BLE_RD_RF_PATH_COMPENSATION); UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_RF_PATH_COMPENSATION); @@ -1935,7 +1940,7 @@ UINT8 btsnd_hcic_ble_write_rf_path_compensation(UINT16 rf_tx_path, UINT16 rf_rx_ UINT8 *pp; HCI_TRACE_EVENT("%s, rf_tx_path = %d, rf_rx_path = %d", __func__, rf_tx_path, rf_rx_path); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_WRITE_RF_PATH_COMPENSATION); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_WRITE_RF_PATH_COMPENSATION); pp = (UINT8 *)(p + 1); @@ -1958,7 +1963,7 @@ UINT8 btsnd_hcic_ble_set_periodic_adv_recv_enable(UINT16 sync_handle, UINT8 enab BT_HDR *p; UINT8 *pp; - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_PERIODIC_ADV_RECV_ENABLE); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_PERIODIC_ADV_RECV_ENABLE); pp = (UINT8 *)(p + 1); @@ -2044,7 +2049,7 @@ UINT8 btsnd_hcic_ble_set_default_periodic_adv_sync_trans_params(UINT8 mode, UINT HCI_TRACE_DEBUG("%s mode %x, skip %x, sync timeout %x", __func__, mode, skip, sync_timeout); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_DEFAULT_PAST_PARAMS); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_DEFAULT_PAST_PARAMS); pp = (UINT8 *)(p + 1); @@ -2298,7 +2303,7 @@ UINT8 btsnd_hcic_ble_big_sync_terminate(uint8_t big_handle) HCI_TRACE_DEBUG("%s big_handle %d", __func__, big_handle); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_BIG_SYNC_TERMINATE_PARAMS); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_BIG_SYNC_TERMINATE_PARAMS); pp = (UINT8 *)(p + 1); @@ -2320,7 +2325,7 @@ UINT8 btsnd_hcic_ble_iso_set_data_path(uint16_t conn_handle, uint8_t data_path_d HCI_TRACE_DEBUG("hci set data path: conn_handle %d data_path_dir %d data_path_id %d coding_fmt %d company_id 0x%x vs_codec_id %d controller_delay %ld codec_len %d", conn_handle, data_path_dir, data_path_id, coding_fmt, company_id, vs_codec_id, controller_delay, codec_len); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_ISO_SET_DATA_PATH_PARAMS + codec_len); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_ISO_SET_DATA_PATH_PARAMS + codec_len); pp = (UINT8 *)(p + 1); @@ -2349,7 +2354,7 @@ UINT8 btsnd_hcic_ble_iso_remove_data_path(uint16_t conn_handle, uint8_t data_pat HCI_TRACE_DEBUG("hci remove data path: conn_handle %d data_path_dir %d", conn_handle, data_path_dir); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_ISO_REMOVE_DATA_PATH_PARAMS); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_ISO_REMOVE_DATA_PATH_PARAMS); pp = (UINT8 *)(p + 1); @@ -2369,7 +2374,7 @@ UINT8 btsnd_hcic_ble_iso_read_tx_sync(uint16_t iso_hdl) HCI_TRACE_DEBUG("hci read iso tx sync: iso_hdl %d", iso_hdl); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_ISO_READ_TX_SYNC_PARAMS); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_ISO_READ_TX_SYNC_PARAMS); pp = (UINT8 *)(p + 1); @@ -2390,7 +2395,7 @@ UINT8 btsnd_hcic_ble_iso_set_cig_params(uint8_t cig_id, uint32_t sdu_int_c_to_p, HCI_TRACE_DEBUG("hci set cig params: cig_id %d sdu_int_c_to_p %d sdu_int_p_to_c %d worse_case_SCA %d packing %d framing %d mtl_c_to_p %d mtl_p_to_c %d cis_cnt %d", cig_id, sdu_int_c_to_p, sdu_int_p_to_c, worse_case_SCA, packing, framing, mtl_c_to_p, mtl_p_to_c, cis_cnt); UINT8 cis_param_len = cis_cnt * 9; - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_ISO_SET_CIG_PARAMS + cis_param_len); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_ISO_SET_CIG_PARAMS + cis_param_len); pp = (UINT8 *)(p + 1); @@ -2431,7 +2436,7 @@ UINT8 btsnd_hcic_ble_iso_set_cig_params_test(uint8_t cig_id, uint32_t sdu_int_c_ HCI_TRACE_DEBUG("hci set cig params test: cig_id %d sdu_int_c_to_p %d sdu_int_p_to_c %d ft_c_to_p %d ft_p_to_c %d iso_interval %d worse_case_SCA %d packing %d framing %d cis_cnt %d", cig_id, sdu_int_c_to_p, sdu_int_p_to_c, ft_c_to_p, ft_p_to_c, iso_interval, worse_case_SCA, packing, framing, cis_cnt); UINT8 cis_param_len = cis_cnt * 14; - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_ISO_SET_CIG_TEST_PARAMS + cis_param_len); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_ISO_SET_CIG_TEST_PARAMS + cis_param_len); pp = (UINT8 *)(p + 1); @@ -2505,7 +2510,7 @@ UINT8 btsnd_hcic_ble_iso_remove_cig(uint8_t cig_id) HCI_TRACE_DEBUG("hci remove cig: cig_id %d", cig_id); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_ISO_REMOVE_CIG_PARAMS); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_ISO_REMOVE_CIG_PARAMS); pp = (UINT8 *)(p + 1); @@ -2547,7 +2552,7 @@ UINT8 btsnd_hcic_ble_iso_reject_cis_req(uint16_t cis_handle, uint8_t reason) HCI_TRACE_DEBUG("hci reject cis req: cis_handle %d reason %d", cis_handle, reason); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_ISO_REJECT_CIS_REQ_PARAMS); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_ISO_REJECT_CIS_REQ_PARAMS); pp = (UINT8 *)(p + 1); @@ -2568,7 +2573,7 @@ UINT8 btsnd_hcic_ble_iso_read_iso_link_quality(uint16_t iso_handle) HCI_TRACE_DEBUG("hci read iso link quality: cis_handle %d", iso_handle); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_ISO_READ_LINK_QUALITY_PARAMS); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_ISO_READ_LINK_QUALITY_PARAMS); pp = (UINT8 *)(p + 1); @@ -2592,7 +2597,7 @@ UINT8 btsnd_hcic_ble_set_connless_cte_trans_params(uint8_t adv_hdl, uint8_t cte_ HCI_TRACE_DEBUG("hci set connless cte trans: adv_hdl %d cte_len %d cte_type %d cte_cnt %d", adv_hdl, cte_len, cte_type, cte_cnt); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_CONNLESS_CTE_TRANS_PARAMS + switching_pattern_len); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_CONNLESS_CTE_TRANS_PARAMS + switching_pattern_len); pp = (UINT8 *)(p + 1); @@ -2619,7 +2624,7 @@ UINT8 btsnd_hcic_ble_set_connless_cte_enable(uint8_t adv_hdl, uint8_t cte_en) HCI_TRACE_DEBUG("hci set connect cte enable: adv_hdl %d cte_en %d", adv_hdl, cte_en); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_CONNLESS_CTE_TRANS_ENABLE); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_CONNLESS_CTE_TRANS_ENABLE); pp = (UINT8 *)(p + 1); @@ -2640,7 +2645,7 @@ UINT8 btsnd_hcic_ble_set_connless_iq_sampling_enable(uint16_t sync_hdl, uint8_t HCI_TRACE_DEBUG("hci enable IQ sampling: sync_hdl %d sampling_en %d slot_dur %d", sync_hdl, sampling_en, slot_dur); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_CONNLESS_IQ_SAMPLING_ENABLE + switching_pattern_len); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_CONNLESS_IQ_SAMPLING_ENABLE + switching_pattern_len); pp = (UINT8 *)(p + 1); @@ -2670,7 +2675,7 @@ UINT8 btsnd_hcic_ble_set_conn_cte_receive_params(uint16_t conn_hdl, uint8_t samp HCI_TRACE_DEBUG("hci set connection cte receive params: conn_hdl %d sampling_en %d slot_dur %d", conn_hdl, sampling_en, slot_dur); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_CONN_CTE_RECEIVE_PARAMS + switching_pattern_len); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_CONN_CTE_RECEIVE_PARAMS + switching_pattern_len); pp = (UINT8 *)(p + 1); @@ -2696,7 +2701,7 @@ UINT8 btsnd_hcic_ble_set_conn_cte_trans_params(uint16_t conn_hdl, uint8_t cte_ty HCI_TRACE_DEBUG("hci set connection cte trans params: conn_hdl %d cte_type %d len %d", conn_hdl, cte_type, switching_pattern_len); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_CONN_CTE_TRANS_PARAMS + switching_pattern_len); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_CONN_CTE_TRANS_PARAMS + switching_pattern_len); pp = (UINT8 *)(p + 1); @@ -2721,7 +2726,7 @@ UINT8 btsnd_hcic_ble_conn_cte_req_enable(uint16_t conn_hdl, uint8_t enable, uint HCI_TRACE_DEBUG("hci set connect cte request enable: conn_hdl %d enable %d cte_req_int %d req_cte_len %d req_cte_type %d", conn_hdl, enable, cte_req_int, req_cte_len, req_cte_type); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_CONN_CTE_REQ_ENABLE); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_CONN_CTE_REQ_ENABLE); pp = (UINT8 *)(p + 1); @@ -2744,7 +2749,7 @@ UINT8 btsnd_hcic_ble_conn_cte_rsp_enable(uint16_t conn_hdl, uint8_t enable) HCI_TRACE_DEBUG("hci set connect cte response enable: conn_hdl %d enable %d", conn_hdl, enable); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_CONN_CTE_RSP_ENABLE); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_CONN_CTE_RSP_ENABLE); pp = (UINT8 *)(p + 1); @@ -2765,7 +2770,7 @@ UINT8 btsnd_hcic_ble_read_antenna_info(void) HCI_TRACE_DEBUG("hci read antenna information"); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_READ_ANT_INFO); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_READ_ANT_INFO); pp = (UINT8 *)(p + 1); @@ -2784,7 +2789,7 @@ UINT8 btsnd_hcic_ble_enh_read_trans_power_level(uint16_t conn_handle, uint8_t ph HCI_TRACE_DEBUG("hci enh read trans power level, conn_handle %d phy %d", conn_handle, phy); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_ENH_READ_TRANS_PWR_LEVEL); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_ENH_READ_TRANS_PWR_LEVEL); pp = (UINT8 *)(p + 1); @@ -2828,7 +2833,7 @@ UINT8 btsnd_hcic_ble_set_path_loss_rpt_params(uint16_t conn_handle, uint8_t high conn_handle, high_threshold, high_hysteresis, low_threshold, low_hysteresis, min_time_spent); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_PATH_LOSS_REPORTING_PARAMS); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_PATH_LOSS_REPORTING_PARAMS); pp = (UINT8 *)(p + 1); @@ -2851,7 +2856,7 @@ UINT8 btsnd_hcic_ble_set_path_loss_rpt_enable(uint16_t conn_handle, uint8_t enab UINT8 *pp; HCI_TRACE_DEBUG("hci set path loss rpt en, conn_handle %d enable %d", conn_handle, enable); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_PATH_LOSS_REPORTING_ENABLE); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_PATH_LOSS_REPORTING_ENABLE); pp = (UINT8 *)(p + 1); @@ -2870,7 +2875,7 @@ UINT8 btsnd_hcic_ble_set_trans_pwr_rpt_enable(uint16_t conn_handle, uint8_t loca UINT8 *pp; HCI_TRACE_DEBUG("hci set trans power rpt en, conn_handle %d local_enable %d remote_enable %d", conn_handle, local_enable, remote_enable); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_TRANS_PWR_REPORTING_ENABLE); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_TRANS_PWR_REPORTING_ENABLE); pp = (UINT8 *)(p + 1); @@ -2895,7 +2900,7 @@ UINT8 btsnd_hcic_ble_set_default_subrate(UINT16 subrate_min, UINT16 subrate_max, HCI_TRACE_DEBUG("hci set default subrate, subrate_min %d subrate_max %d max_latency %d continuation_number %d supervision_timeout %d", subrate_min, subrate_max, max_latency, continuation_number, supervision_timeout); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_DEFAULT_SUBRATE_PARAMS_LEN); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_DEFAULT_SUBRATE_PARAMS_LEN); pp = (UINT8 *)(p + 1); @@ -2947,9 +2952,9 @@ UINT8 btsnd_hcic_ble_set_host_feature(uint16_t bit_num, uint8_t bit_val) HCI_TRACE_DEBUG("hci set host feature: bit_num %d bit_val %d", bit_num, bit_val); #if (BLE_FEAT_ISO_60_EN == TRUE) - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_HOST_FEATURE_PARAMS_V2); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_HOST_FEATURE_PARAMS_V2); #else - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_HOST_FEATURE_PARAMS); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_HOST_FEATURE_PARAMS); #endif // #if (BLE_FEAT_ISO_60_EN == TRUE) pp = (UINT8 *)(p + 1); #if (BLE_FEAT_ISO_60_EN == TRUE) @@ -2996,7 +3001,7 @@ UINT8 btsnd_hcic_ble_set_periodic_adv_subevt_data(UINT8 adv_handle, UINT8 num_su param_len += (4 + subevent_params[i].subevent_data_len); } - HCIC_BLE_CMD_CREATED(p, pp, param_len); + HCIC_BLE_CMD_CREATED_U8(p, pp, param_len); pp = (UINT8 *)(p + 1); @@ -3027,7 +3032,7 @@ UINT8 btsnd_hcic_ble_set_periodic_adv_rsp_data(UINT16 sync_handle, UINT16 req_ev HCI_TRACE_DEBUG("hci set PA rsp data, sync_handle %d req_evt %d req_subevt %d rsp_subevt %d rsp_slot %d rsp_data_len %d", sync_handle, req_evt, req_subevt, rsp_subevt, rsp_slot, rsp_data_len); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_PA_RESPONSE_DATA_PARAMS_LEN + rsp_data_len); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_PA_RESPONSE_DATA_PARAMS_LEN + rsp_data_len); pp = (UINT8 *)(p + 1); @@ -3060,7 +3065,7 @@ UINT8 btsnd_hcic_ble_set_periodic_sync_subevt(UINT16 sync_handle, UINT16 periodi HCI_TRACE_DEBUG("subevt[%d] = %d", i, subevt[i]); } - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_PA_SYNC_SUBEVT_PARAMS_LEN + num_subevents_to_sync); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_PA_SYNC_SUBEVT_PARAMS_LEN + num_subevents_to_sync); pp = (UINT8 *)(p + 1); @@ -3138,7 +3143,7 @@ UINT8 btsnd_hcic_ble_cs_write_cached_remote_supported_capabilities(UINT16 conn_h NADM_random_capability, cs_sync_phys_supported, subfeatures_supported, T_IP1_times_supported, T_IP2_times_supported, T_FCS_times_supported, T_PM_times_supported, T_SW_times_supported, TX_SNR_capability); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_WRITE_CACHE_REMOTE_SUPP_CAPS_PARAMS_LEN); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_WRITE_CACHE_REMOTE_SUPP_CAPS_PARAMS_LEN); pp = (UINT8 *)(p + 1); @@ -3196,7 +3201,7 @@ UINT8 btsnd_hcic_ble_cs_set_default_settings(UINT16 conn_handle, UINT8 role_enab HCI_TRACE_DEBUG("cs set default settings, conn_handle %d role_enable %d cs_sync_ant_selection %d max_tx_power %d", conn_handle, role_enable, cs_sync_ant_selection, max_tx_power); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_DEFAULT_SETTINGS_PARAMS_LEN); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_DEFAULT_SETTINGS_PARAMS_LEN); pp = (UINT8 *)(p + 1); @@ -3237,7 +3242,7 @@ UINT8 btsnd_hcic_ble_cs_write_cached_remote_fae_table(UINT16 conn_handle, UINT8 HCI_TRACE_DEBUG("cs write cached remote fae table, conn_handle %d", conn_handle); esp_log_buffer_hex_internal("remote_fae_table", remote_fae_table, 72, ESP_LOG_DEBUG); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_WRITE_CACHED_REMOTE_FAE_TAB_PARAMS_LEN); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_WRITE_CACHED_REMOTE_FAE_TAB_PARAMS_LEN); pp = (UINT8 *)(p + 1); @@ -3325,7 +3330,7 @@ UINT8 btsnd_hcic_ble_cs_set_channel_classification(UINT8 *channel_class) HCI_TRACE_DEBUG("cs set channel class"); esp_log_buffer_hex_internal("channel", channel_class, 10, ESP_LOG_DEBUG); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_CHANNEL_CLASS_PARAMS_LEN); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_CHANNEL_CLASS_PARAMS_LEN); pp = (UINT8 *)(p + 1); @@ -3353,7 +3358,7 @@ UINT8 btsnd_hcic_ble_cs_set_procedure_params(UINT16 conn_handle, UINT8 config_id conn_handle, config_id, max_procedure_len, min_procedure_interval, max_procedure_interval, max_procedure_count, min_subevent_len, max_subevent_len, tone_ant_config_selection, phy, tx_power_delta, preferred_peer_antenna, SNR_control_initiator, SNR_control_reflector); - HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_PROCEDURE_PARAMS_LEN); + HCIC_BLE_CMD_CREATED_U8(p, pp, HCIC_PARAM_SIZE_SET_PROCEDURE_PARAMS_LEN); pp = (UINT8 *)(p + 1); diff --git a/components/bt/host/bluedroid/stack/include/stack/btm_api.h b/components/bt/host/bluedroid/stack/include/stack/btm_api.h index 0cd4302d5c..94a000a976 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_api.h @@ -171,23 +171,13 @@ typedef void (tBTM_VSC_CMPL_CB) (tBTM_VSC_CMPL *p1); ** Parameters are the BD Address of remote and the Dev Class of remote. ** If the app returns none zero, the connection or inquiry result will be dropped. */ -typedef UINT8 (tBTM_FILTER_CB) (BD_ADDR bd_addr, DEV_CLASS dc); - -typedef void (tBTM_UPDATE_CONN_PARAM_CBACK) (UINT8 status, BD_ADDR bd_addr, tBTM_LE_UPDATE_CONN_PRAMS *update_conn_params); - -typedef void (tBTM_SET_PKT_DATA_LENGTH_CBACK) (UINT8 status, tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS *data_length_params); +// typedef UINT8 (tBTM_FILTER_CB) (BD_ADDR bd_addr, DEV_CLASS dc); typedef void (tBTM_DTM_CMD_CMPL_CBACK) (void *p1); typedef void (tBTM_SET_RAND_ADDR_CBACK) (UINT8 status); -typedef void (tBTM_UPDATE_WHITELIST_CBACK) (UINT8 status, tBTM_WL_OPERATION wl_opration); - -typedef void (tBTM_SET_LOCAL_PRIVACY_CBACK) (UINT8 status); - -typedef void (tBTM_SET_RPA_TIMEOUT_CMPL_CBACK) (UINT8 status); - -typedef void (tBTM_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK) (UINT8 status); +// typedef void (tBTM_UPDATE_WHITELIST_CBACK) (UINT8 status, tBTM_WL_OPERATION wl_opration); typedef void (tBTM_BLE_VENDOR_HCI_EVT_CBACK) (UINT8 subevt_code, UINT8 param_len, UINT8 *params); /******************************* @@ -3167,7 +3157,7 @@ tBTM_STATUS BTM_WriteBredrTxPwrLvl(tBTM_TX_PWR_LVL_TYPE type, INT8 tx_power, tBT ** Returns BTM_CMD_STARTED if successfully initiated or error code ** *******************************************************************************/ -tBTM_STATUS BTM_ReadChannelMap(BD_ADDR remote_bda, tBTM_CMPL_CB *p_cb); +tBTM_STATUS BTM_ReadChannelMap(BD_ADDR remote_bda); void BTM_BleGetWhiteListSize(uint16_t *length); @@ -4480,7 +4470,7 @@ tBTM_STATUS BTM_SetAfhChannels (AFH_CHANNELS channels, tBTM_CMPL_CB *p_afh_chann ** Returns status of the operation ** *******************************************************************************/ -tBTM_STATUS BTM_BleSetChannels (BLE_CHANNELS channels, tBTM_CMPL_CB *p_ble_channels_cmpl_cback); +tBTM_STATUS BTM_BleSetChannels (BLE_CHANNELS channels); /******************************************************************************* ** diff --git a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h index 57c4660bc6..9c35491e75 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h @@ -867,17 +867,8 @@ typedef void (tBTM_BLE_VERIFY_CBACK)(void *p_ref_data, BOOLEAN match); typedef void (tBTM_BLE_RANDOM_SET_CBACK) (BD_ADDR random_bda); typedef void (tBTM_BLE_SCAN_REQ_CBACK)(BD_ADDR remote_bda, tBLE_ADDR_TYPE addr_type, UINT8 adv_evt); -typedef void (*tBLE_SCAN_PARAM_SETUP_CBACK)(tGATT_IF client_if, tBTM_STATUS status); - -typedef void (tBTM_START_ADV_CMPL_CBACK) (UINT8 status); -typedef void (tBTM_START_STOP_ADV_CMPL_CBACK) (UINT8 status); typedef void (tBTM_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK) (tBTM_STATUS status, uint8_t subcode, uint32_t length, uint8_t *device_info); -typedef void (tBTM_CLEAR_ADV_CMPL_CBACK) (UINT8 status); -typedef void (tBTM_SET_PRIVACY_MODE_CMPL_CBACK) (tBTM_STATUS status); -typedef void (tBTM_SET_CSA_SUPPORT_CMPL_CBACK) (tBTM_STATUS status); -typedef void (tBTM_SET_VENDOR_EVT_MASK_CBACK) (tBTM_STATUS status); - #if (BLE_50_FEATURE_SUPPORT == TRUE) #define BTM_BLE_5_GAP_READ_PHY_COMPLETE_EVT 1 #define BTM_BLE_5_GAP_SET_PREFERED_DEFAULT_PHY_COMPLETE_EVT 2 @@ -1939,19 +1930,6 @@ extern "C" { #endif */ -/******************************************************************************* -** -** Function BTM_BleRegiseterConnParamCallback -** -** Description register connection parameters update callback func -** -** Parameters: update_conn_param_cb -** -** Returns void -** -*******************************************************************************/ -void BTM_BleRegiseterConnParamCallback(tBTM_UPDATE_CONN_PARAM_CBACK *update_conn_param_cb); -void BTM_BleRegiseterPktLengthChangeCallback(tBTM_SET_PKT_DATA_LENGTH_CBACK *ptk_len_chane_cb); void BTM_BleRegisterVendorHciEventCallback(tBTM_BLE_VENDOR_HCI_EVT_CBACK *vendor_hci_evt_cb); /******************************************************************************* @@ -1996,7 +1974,7 @@ BOOLEAN BTM_SecAddBleKey (BD_ADDR bd_addr, tBTM_LE_KEY_VALUE *p_le_key, /******************************************************************************* ** -** Function BTM_BleSetAdvParamsAll +** Function BTM_BleStartAdvWithParams ** ** Description This function is called to set all of the advertising parameters. ** @@ -2005,9 +1983,9 @@ BOOLEAN BTM_SecAddBleKey (BD_ADDR bd_addr, tBTM_LE_KEY_VALUE *p_le_key, ** Returns void ** *******************************************************************************/ -tBTM_STATUS BTM_BleSetAdvParamsAll(UINT16 adv_int_min, UINT16 adv_int_max, UINT8 adv_type, +tBTM_STATUS BTM_BleStartAdvWithParams(UINT16 adv_int_min, UINT16 adv_int_max, UINT8 adv_type, tBLE_ADDR_TYPE own_bda_type, tBLE_BD_ADDR *p_dir_bda, - tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP afp, tBTM_START_ADV_CMPL_CBACK *adv_cb); + tBTM_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP afp); /******************************************************************************* ** @@ -2078,8 +2056,7 @@ void BTM_BleClearRandAddress(void); ** *******************************************************************************/ tBTM_STATUS BTM_BleSetScanFilterParams(tGATT_IF client_if, UINT32 scan_interval, UINT32 scan_window, - tBLE_SCAN_MODE scan_mode, UINT8 addr_type_own, UINT8 scan_duplicate_filter, tBTM_BLE_SFP scan_filter_policy, - tBLE_SCAN_PARAM_SETUP_CBACK scan_setup_status_cback); + tBLE_SCAN_MODE scan_mode, UINT8 addr_type_own, UINT8 scan_duplicate_filter, tBTM_BLE_SFP scan_filter_policy); /******************************************************************************* @@ -2111,22 +2088,6 @@ tBTM_STATUS BTM_BleWriteScanRsp(tBTM_BLE_AD_MASK data_mask, //extern tBTM_STATUS BTM_BleWriteScanRspRaw(UINT8 *p_raw_scan_rsp, UINT32 raw_scan_rsp_len); -/******************************************************************************* -** -** Function BTM_BleObserve -** -** Description This procedure keep the device listening for advertising -** events from a broadcast device. -** -** Parameters start: start or stop observe. -** -** Returns void -** -*******************************************************************************/ -//extern -tBTM_STATUS BTM_BleObserve(BOOLEAN start, UINT32 duration, - tBTM_INQ_RESULTS_CB *p_results_cb, tBTM_CMPL_CB *p_cmpl_cb); - /******************************************************************************* ** ** Function BTM_BleScan @@ -2571,17 +2532,17 @@ BOOLEAN BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, /******************************************************************************* ** -** Function BTM_BleBroadcast +** Function BTM_BleAdvStop ** -** Description This function is to start or stop broadcasting. +** Description This function is to stop broadcasting. ** -** Parameters start: start or stop broadcasting. +** Parameters void ** ** Returns status. ** *******************************************************************************/ //extern -tBTM_STATUS BTM_BleBroadcast(BOOLEAN start, tBTM_START_STOP_ADV_CMPL_CBACK *p_stop_adv_cback); +tBTM_STATUS BTM_BleAdvStop(void); /******************************************************************************* ** @@ -2596,7 +2557,7 @@ tBTM_STATUS BTM_BleBroadcast(BOOLEAN start, tBTM_START_STOP_ADV_CMPL_CBACK *p_st ** *******************************************************************************/ //extern -BOOLEAN BTM_BleConfigPrivacy(BOOLEAN enable, tBTM_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cabck); +BOOLEAN BTM_BleConfigPrivacy(BOOLEAN enable); /******************************************************************************* ** @@ -2712,7 +2673,7 @@ void BTM_BleTurnOnPrivacyOnRemote(BD_ADDR bd_addr, ** *******************************************************************************/ //extern -BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR emote_bda, tBLE_ADDR_TYPE addr_type, tBTM_UPDATE_WHITELIST_CBACK *update_wl_cb); +BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR emote_bda, tBLE_ADDR_TYPE addr_type); /******************************************************************************* ** @@ -2723,7 +2684,7 @@ BOOLEAN BTM_BleUpdateAdvWhitelist(BOOLEAN add_remove, BD_ADDR emote_bda, tBLE_AD ** Returns void ** *******************************************************************************/ -void BTM_BleClearWhitelist(tBTM_UPDATE_WHITELIST_CBACK *update_wl_cb); +void BTM_BleClearWhitelist(void); /******************************************************************************* ** @@ -2915,13 +2876,13 @@ tBTM_STATUS BTM_SetBleDataLength(BD_ADDR bd_addr, UINT16 tx_pdu_length); ** Parameters: subcode: add, remove or clean duplicate scan exceptional list. ** type: device info type ** device_info: device information -** update_exceptional_list_cmp_cb: complete callback +** ** ** Returns status ** *******************************************************************************/ -tBTM_STATUS BTM_UpdateBleDuplicateExceptionalList(uint8_t subcode, uint32_t type, BD_ADDR device_info, tBTM_UPDATE_DUPLICATE_EXCEPTIONAL_LIST_CMPL_CBACK update_exceptional_list_cmp_cb); +tBTM_STATUS BTM_UpdateBleDuplicateExceptionalList(uint8_t subcode, uint32_t type, BD_ADDR device_info); /******************************************************************************* ** @@ -2956,7 +2917,7 @@ BOOLEAN BTM_Ble_Authorization(BD_ADDR bd_addr, BOOLEAN authorize); ** Parameter p_clear_adv_cback - Command complete callback ** *******************************************************************************/ -BOOLEAN BTM_BleClearAdv(tBTM_CLEAR_ADV_CMPL_CBACK *p_clear_adv_cback); +BOOLEAN BTM_BleClearAdv(void); /******************************************************************************* ** @@ -2968,7 +2929,7 @@ BOOLEAN BTM_BleClearAdv(tBTM_CLEAR_ADV_CMPL_CBACK *p_clear_adv_cback); ** Parameter rpa_timeout - The timeout value for RPA, typically in seconds. ** *******************************************************************************/ -BOOLEAN BTM_BleSetRpaTimeout(uint16_t rpa_timeout, tBTM_SET_RPA_TIMEOUT_CMPL_CBACK *p_set_rpa_timeout_cback); +BOOLEAN BTM_BleSetRpaTimeout(uint16_t rpa_timeout); /******************************************************************************* ** @@ -2981,15 +2942,14 @@ BOOLEAN BTM_BleSetRpaTimeout(uint16_t rpa_timeout, tBTM_SET_RPA_TIMEOUT_CMPL_CBA ** Parameters addr - The address of the device to be added to the resolving list. ** addr_type - The address type of the device (public or random). ** irk - The Identity Resolving Key (IRK) of the device. -** p_add_dev_to_resolving_list_callback - Callback function to be called when the operation is completed. +** ** ** Returns TRUE if the operation was successful, otherwise FALSE. ** *******************************************************************************/ BOOLEAN BTM_BleAddDevToResolvingList(BD_ADDR addr, uint8_t addr_type, - uint8_t irk[], - tBTM_ADD_DEV_TO_RESOLVING_LIST_CMPL_CBACK *p_add_dev_to_resolving_list_callback); + uint8_t irk[]); /******************************************************************************* ** @@ -3007,8 +2967,7 @@ BOOLEAN BTM_BleAddDevToResolvingList(BD_ADDR addr, *******************************************************************************/ BOOLEAN BTM_BleSetPrivacyMode(UINT8 addr_type, BD_ADDR bd_addr, - UINT8 privacy_mode, - tBTM_SET_PRIVACY_MODE_CMPL_CBACK *p_callback); + UINT8 privacy_mode); /******************************************************************************* ** @@ -3022,7 +2981,7 @@ BOOLEAN BTM_BleSetPrivacyMode(UINT8 addr_type, ** Returns TRUE if the operation was successful, otherwise FALSE. ** *******************************************************************************/ -BOOLEAN BTM_BleSetCsaSupport (UINT8 csa_select, tBTM_SET_CSA_SUPPORT_CMPL_CBACK *p_callback); +BOOLEAN BTM_BleSetCsaSupport (UINT8 csa_select); /******************************************************************************* ** @@ -3036,7 +2995,7 @@ BOOLEAN BTM_BleSetCsaSupport (UINT8 csa_select, tBTM_SET_CSA_SUPPORT_CMPL_CBACK ** Returns TRUE if the operation was successful, otherwise FALSE. ** *******************************************************************************/ -BOOLEAN BTM_BleSetVendorEventMask(UINT32 evt_mask, tBTM_SET_VENDOR_EVT_MASK_CBACK *p_callback); +BOOLEAN BTM_BleSetVendorEventMask(UINT32 evt_mask); /* #ifdef __cplusplus } diff --git a/components/bt/host/bluedroid/stack/include/stack/btu.h b/components/bt/host/bluedroid/stack/include/stack/btu.h index 075adcdd1b..c2a80916d3 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btu.h +++ b/components/bt/host/bluedroid/stack/include/stack/btu.h @@ -280,9 +280,7 @@ void btu_check_bt_sleep (void); */ void btu_hcif_process_event (UINT8 controller_id, BT_HDR *p_buf); void btu_hcif_send_cmd (UINT8 controller_id, BT_HDR *p_msg); -#if (BLE_50_FEATURE_SUPPORT == TRUE) UINT8 btu_hcif_send_cmd_sync (UINT8 controller_id, BT_HDR *p_buf); -#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) void btu_hcif_send_host_rdy_for_data(void); void btu_hcif_cmd_timeout (UINT8 controller_id); diff --git a/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h b/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h index 93863a4ba6..3ca881d48d 100644 --- a/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h +++ b/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h @@ -799,7 +799,9 @@ void btsnd_hcic_vendor_spec_cmd (BT_HDR *buffer, UINT16 opcode, #define HCIC_PARAM_SIZE_READ_TRANS_POWER 0 #define HCIC_PARAM_SIZE_READ_RF_PATH_COMPENSATION 0 #define HCIC_PARAM_SIZE_WRITE_RF_PATH_COMPENSATION 4 +#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) +#if ((BLE_50_FEATURE_SUPPORT == TRUE) || (BLE_42_FEATURE_SUPPORT == TRUE)) BlE_SYNC *btsnd_hcic_ble_get_sync_info(void); void btsnd_hcic_ble_sync_sem_init(void); void btsnd_hcic_ble_sync_sem_deinit(void); @@ -807,7 +809,7 @@ void btsnd_hcic_ble_sync_sem_deinit(void); uint8_t btsnd_hcic_ble_get_status(void); void btsnd_hci_ble_set_status(UINT8 hci_status); -#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) +#endif // ((BLE_50_FEATURE_SUPPORT == TRUE) || (BLE_42_FEATURE_SUPPORT == TRUE)) /* ULP HCI command */ BOOLEAN btsnd_hcic_ble_set_evt_mask (BT_EVENT_MASK event_mask); @@ -820,25 +822,24 @@ BOOLEAN btsnd_hcic_ble_set_local_used_feat (UINT8 feat_set[8]); BOOLEAN btsnd_hcic_ble_set_random_addr (BD_ADDR random_addr); -BOOLEAN btsnd_hcic_ble_write_adv_params (UINT16 adv_int_min, UINT16 adv_int_max, +UINT8 btsnd_hcic_ble_write_adv_params (UINT16 adv_int_min, UINT16 adv_int_max, UINT8 adv_type, UINT8 addr_type_own, UINT8 addr_type_dir, BD_ADDR direct_bda, UINT8 channel_map, UINT8 adv_filter_policy); BOOLEAN btsnd_hcic_ble_read_adv_chnl_tx_power (void); -BOOLEAN btsnd_hcic_ble_set_adv_data (UINT8 data_len, UINT8 *p_data); +UINT8 btsnd_hcic_ble_set_adv_data (UINT8 data_len, UINT8 *p_data); -BOOLEAN btsnd_hcic_ble_set_scan_rsp_data (UINT8 data_len, UINT8 *p_scan_rsp); +UINT8 btsnd_hcic_ble_set_scan_rsp_data (UINT8 data_len, UINT8 *p_scan_rsp); -BOOLEAN btsnd_hcic_ble_set_adv_enable (UINT8 adv_enable); +UINT8 btsnd_hcic_ble_set_adv_enable (UINT8 adv_enable); -BOOLEAN btsnd_hcic_ble_set_scan_params (UINT8 scan_type, +UINT8 btsnd_hcic_ble_set_scan_params (UINT8 scan_type, UINT16 scan_int, UINT16 scan_win, UINT8 addr_type, UINT8 scan_filter_policy); -BOOLEAN btsnd_hcic_ble_set_scan_enable (UINT8 scan_enable, UINT8 duplicate); - +UINT8 btsnd_hcic_ble_set_scan_enable (UINT8 scan_enable, UINT8 duplicate); BOOLEAN btsnd_hcic_ble_create_ll_conn (UINT16 scan_int, UINT16 scan_win, UINT8 init_filter_policy, UINT8 addr_type_peer, BD_ADDR bda_peer, UINT8 addr_type_own, UINT16 conn_int_min, UINT16 conn_int_max, UINT16 conn_latency, UINT16 conn_timeout, diff --git a/components/bt/host/bluedroid/stack/l2cap/l2c_ble.c b/components/bt/host/bluedroid/stack/l2cap/l2c_ble.c index c430e55629..817d0b94b8 100644 --- a/components/bt/host/bluedroid/stack/l2cap/l2c_ble.c +++ b/components/bt/host/bluedroid/stack/l2cap/l2c_ble.c @@ -31,6 +31,7 @@ #include "btm_int.h" #include "stack/hcimsgs.h" #include "device/controller.h" +#include "bta_dm_gap.h" #if (BLE_INCLUDED == TRUE) @@ -171,14 +172,18 @@ BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bda, UINT16 min_int, UINT16 max_in L2CAP_TRACE_ERROR("%s connection parameter update in progress, please try later", __func__); } - if ((need_cb == TRUE) && (conn_callback_func.update_conn_param_cb != NULL)) { - tBTM_LE_UPDATE_CONN_PRAMS update_param; - update_param.max_conn_int = max_int; - update_param.min_conn_int = min_int; - update_param.conn_int = p_lcb->current_used_conn_interval; - update_param.slave_latency = p_lcb->current_used_conn_latency; - update_param.supervision_tout = p_lcb->current_used_conn_timeout; - (conn_callback_func.update_conn_param_cb)(status, p_lcb->remote_bd_addr, &update_param); + if (need_cb) { + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.conn_params_update.status = status; + memcpy(cb_params.conn_params_update.remote_bd_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN); + cb_params.conn_params_update.min_conn_int = min_int; + cb_params.conn_params_update.max_conn_int = max_int; + cb_params.conn_params_update.conn_int = p_lcb->current_used_conn_interval; + cb_params.conn_params_update.slave_latency = p_lcb->current_used_conn_latency; + cb_params.conn_params_update.supervision_tout = p_lcb->current_used_conn_timeout; + + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_CONNECTION_PARAMS_UPDATE_EVT, &cb_params); + return (status == HCI_SUCCESS); } @@ -647,9 +652,8 @@ void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status, UINT16 conn_in p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PARAM_FULL; btu_stop_timer(&p_lcb->upda_con_timer); - if (conn_callback_func.update_conn_param_cb != NULL) { - l2c_send_update_conn_params_cb(p_lcb, status); - } + + l2c_send_update_conn_params_cb(p_lcb, status); if (l2cble_start_conn_update(p_lcb) == TRUE) { UINT32 time = CalConnectParamTimeout(p_lcb); @@ -686,9 +690,8 @@ void l2cble_get_conn_param_format_err_from_contoller (UINT8 status, UINT16 handl btu_stop_timer (&p_lcb->upda_con_timer); - if (conn_callback_func.update_conn_param_cb != NULL) { - l2c_send_update_conn_params_cb(p_lcb, status); - } + l2c_send_update_conn_params_cb(p_lcb, status); + if ((p_lcb->conn_update_mask & L2C_BLE_UPDATE_PARAM_FULL) != 0){ p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PARAM_FULL; if (l2cble_start_conn_update(p_lcb) == TRUE) { @@ -1419,23 +1422,24 @@ void l2cble_process_data_length_change_event(UINT16 handle, UINT16 tx_data_len, if(p_acl) { p_acl->data_length_params = data_length_params; - if (p_acl->p_set_pkt_data_cback) { - // Only when the corresponding API is called will the callback be registered - (*p_acl->p_set_pkt_data_cback)(BTM_SUCCESS, &data_length_params); - } else { - // If the callback is not registered,using global callback - (*conn_callback_func.set_pkt_data_length_cb)(BTM_SUCCESS, &data_length_params); - } + + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.data_length_params.status = BTM_SUCCESS; + cb_params.data_length_params.rx_len = data_length_params.rx_len; + cb_params.data_length_params.tx_len = data_length_params.tx_len; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_DATA_LEN_SET_COMPLETE_EVT, &cb_params); + p_acl->data_len_updating = false; if(p_acl->data_len_waiting) { p_acl->data_len_waiting = false; - p_acl->p_set_pkt_data_cback = p_acl->p_set_data_len_cback_waiting; - p_acl->p_set_data_len_cback_waiting = NULL; // if value is same, trigger callback directly if(p_acl->tx_len_waiting == p_acl->data_length_params.tx_len) { - if(p_acl->p_set_pkt_data_cback) { - (*p_acl->p_set_pkt_data_cback)(BTM_SUCCESS, &p_acl->data_length_params); - } + + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + cb_params.data_length_params.status = BTM_SUCCESS; + cb_params.data_length_params.rx_len = data_length_params.rx_len; + cb_params.data_length_params.tx_len = data_length_params.tx_len; + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_DATA_LEN_SET_COMPLETE_EVT, &cb_params); return; } p_acl->data_len_updating = true; @@ -1495,24 +1499,26 @@ void l2cble_set_fixed_channel_tx_data_length(BD_ADDR remote_bda, UINT16 fix_cid, *******************************************************************************/ void l2c_send_update_conn_params_cb(tL2C_LCB *p_lcb, UINT8 status) { - if(conn_callback_func.update_conn_param_cb != NULL){ - tBTM_LE_UPDATE_CONN_PRAMS update_param; - //if myself update the connection parameters - if (p_lcb->updating_param_flag){ - update_param.max_conn_int = p_lcb->updating_conn_max_interval; - update_param.min_conn_int = p_lcb->updating_conn_min_interval; - p_lcb->updating_param_flag = false; - }else{ - // remote device update the connection parameters - update_param.max_conn_int = update_param.min_conn_int = 0; - } - // current connection parameters - update_param.conn_int = p_lcb->current_used_conn_interval; - update_param.slave_latency = p_lcb->current_used_conn_latency; - update_param.supervision_tout = p_lcb->current_used_conn_timeout; - - (conn_callback_func.update_conn_param_cb)(status, p_lcb->remote_bd_addr, &update_param); + tBTM_BLE_LEGACY_GAP_CB_PARAMS cb_params = {0}; + //if myself update the connection parameters + if (p_lcb->updating_param_flag){ + cb_params.conn_params_update.max_conn_int = p_lcb->updating_conn_max_interval; + cb_params.conn_params_update.min_conn_int = p_lcb->updating_conn_min_interval; + p_lcb->updating_param_flag = false; + }else{ + // remote device update the connection parameters + cb_params.conn_params_update.max_conn_int = cb_params.conn_params_update.min_conn_int = 0; } + // current connection parameters + cb_params.conn_params_update.conn_int = p_lcb->current_used_conn_interval; + cb_params.conn_params_update.slave_latency = p_lcb->current_used_conn_latency; + cb_params.conn_params_update.supervision_tout = p_lcb->current_used_conn_timeout; + + + cb_params.conn_params_update.status = status; + memcpy(cb_params.conn_params_update.remote_bd_addr, p_lcb->remote_bd_addr, BD_ADDR_LEN); + + BTM_LegacyBleCallbackTrigger(BTM_BLE_LEGACY_GAP_CONNECTION_PARAMS_UPDATE_EVT, &cb_params); } /*******************************************************************************