diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index 2d08011f4f..559e340ca1 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -4731,20 +4731,17 @@ void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_ble_set_adv_params_all (tBTA_DM_MSG *p_data) { - tBTA_STATUS status = BTA_FAILURE; - if (BTM_BleSetAdvParamsStartAdv(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) == 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, + p_data->ble_set_adv_params_all.p_start_adv_cback) == BTM_SUCCESS) { + APPL_TRACE_DEBUG("%s(), success to start ble adv.", __func__); + } else { + APPL_TRACE_ERROR("%s(), fail to start ble adv.", __func__); } } @@ -4888,15 +4885,13 @@ void bta_dm_ble_broadcast (tBTA_DM_MSG *p_data) tBTM_STATUS status = 0; BOOLEAN start = p_data->ble_observe.start; - status = BTM_BleBroadcast(start); + status = BTM_BleBroadcast(start, p_data->ble_observe.p_stop_adv_cback); if (p_data->ble_observe.p_stop_adv_cback){ if (status != BTM_SUCCESS){ APPL_TRACE_WARNING("%s, %s, status=0x%x\n", __func__,\ (start == TRUE) ? "start adv failed" : "stop adv failed", status); } - status = (status == BTM_SUCCESS ? BTA_SUCCESS : BTA_FAILURE); - p_data->ble_observe.p_stop_adv_cback(status); } } diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c index 3196ffb678..5a25ebafde 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_act.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_act.c @@ -2172,7 +2172,7 @@ void bta_gattc_broadcast(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg) UNUSED(p_cb); cb_data.reg_oper.client_if = p_msg->api_listen.client_if; - cb_data.reg_oper.status = BTM_BleBroadcast(p_msg->api_listen.start); + cb_data.reg_oper.status = BTM_BleBroadcast(p_msg->api_listen.start, NULL); if (p_clreg && p_clreg->p_cback) { (*p_clreg->p_cback)(BTA_GATTC_LISTEN_EVT, &cb_data); @@ -2361,6 +2361,7 @@ static void bta_gattc_wait4_service_change_ccc_cback (TIMER_LIST_ENT *p_tle) p_tle->param = (TIMER_PARAM_TYPE)0; if (p_timer_param == NULL){ APPL_TRACE_ERROR("p_timer_param is NULL in %s\n", __func__); + osi_mutex_unlock(&write_ccc_mutex); return; } @@ -2368,6 +2369,7 @@ static void bta_gattc_wait4_service_change_ccc_cback (TIMER_LIST_ENT *p_tle) if (p_conn == NULL){ APPL_TRACE_ERROR("p_conn is NULL in %s\n", __func__); osi_free(p_timer_param); + osi_mutex_unlock(&write_ccc_mutex); return; } diff --git a/components/bt/bluedroid/bta/include/bta_api.h b/components/bt/bluedroid/bta/include/bta_api.h index f0a3f8f9d8..7f57f5650f 100644 --- a/components/bt/bluedroid/bta/include/bta_api.h +++ b/components/bt/bluedroid/bta/include/bta_api.h @@ -400,7 +400,10 @@ typedef struct { typedef void (tBTA_SET_ADV_DATA_CMPL_CBACK) (tBTA_STATUS status); -typedef void (tBTA_START_ADV_CMPL_CBACK) (tBTA_STATUS status); +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_ADD_WHITELIST_CBACK tBTA_ADD_WHITELIST_CBACK; diff --git a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c index 4136e0b9a8..53fd83d3d6 100644 --- a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -438,7 +438,7 @@ static void btc_ble_set_scan_rsp_data_raw(uint8_t *raw_scan_rsp, uint32_t raw_sc BTA_DmBleSetScanRspRaw(raw_scan_rsp, raw_scan_rsp_len, p_scan_rsp_data_cback); } -static void btc_start_adv_callback(tBTA_STATUS status) +static void btc_start_adv_callback(uint8_t status) { esp_ble_gap_cb_param_t param; bt_status_t ret; @@ -447,7 +447,7 @@ static void btc_start_adv_callback(tBTA_STATUS 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 = status; + param.adv_start_cmpl.status = btc_hci_to_esp_status(status); ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL); @@ -457,7 +457,7 @@ static void btc_start_adv_callback(tBTA_STATUS status) } } -static void btc_stop_adv_callback(tBTA_STATUS status) +static void btc_stop_adv_callback(uint8_t status) { esp_ble_gap_cb_param_t param; bt_status_t ret; @@ -466,7 +466,7 @@ static void btc_stop_adv_callback(tBTA_STATUS 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 = status; + param.adv_stop_cmpl.status = btc_hci_to_esp_status(status); ret = btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL); @@ -546,8 +546,8 @@ static void btc_ble_set_scan_params(esp_ble_scan_params_t *scan_params, tBLE_SCA scan_params->own_addr_type, scan_param_setup_cback); } else { - btc_scan_params_callback(ESP_DEFAULT_GATT_IF, BTM_ILLEGAL_VALUE); - } + btc_scan_params_callback(ESP_DEFAULT_GATT_IF, BTM_ILLEGAL_VALUE); + } } static void btc_search_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data) @@ -566,7 +566,7 @@ static void btc_search_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data param.scan_rst.dev_type = p_data->inq_res.device_type; param.scan_rst.rssi = p_data->inq_res.rssi; param.scan_rst.ble_addr_type = p_data->inq_res.ble_addr_type; - param.scan_rst.ble_evt_type = p_data->inq_res.ble_evt_type; + param.scan_rst.ble_evt_type = p_data->inq_res.ble_evt_type; param.scan_rst.flag = p_data->inq_res.flag; param.scan_rst.num_resps = 1; param.scan_rst.adv_data_len = p_data->inq_res.adv_data_len; @@ -601,7 +601,7 @@ static void btc_search_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data btc_transfer_context(&msg, ¶m, sizeof(esp_ble_gap_cb_param_t), NULL); } -static void btc_start_scan_callback(tBTA_STATUS status) +static void btc_start_scan_callback(uint8_t status) { esp_ble_gap_cb_param_t param; bt_status_t ret; diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index f8be10940f..2e6379a782 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -501,7 +501,7 @@ tBTM_STATUS BTM_BleScan(BOOLEAN start, UINT32 duration, ** Returns status. ** *******************************************************************************/ -tBTM_STATUS BTM_BleBroadcast(BOOLEAN start) +tBTM_STATUS BTM_BleBroadcast(BOOLEAN start, tBTM_START_STOP_ADV_CMPL_CBACK *p_stop_adv_cback) { tBTM_STATUS status = BTM_NO_RESOURCES; tBTM_LE_RANDOM_CB *p_addr_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; @@ -539,6 +539,8 @@ tBTM_STATUS BTM_BleBroadcast(BOOLEAN start) status = btm_ble_start_adv (); } else if (!start) { + //save the stop adv callback to the BTM env. + p_cb->p_stop_adv_cb = p_stop_adv_cback; status = btm_ble_stop_adv(); #if BLE_PRIVACY_SPT == TRUE btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, TRUE); @@ -1152,7 +1154,7 @@ tBTM_STATUS BTM_BleSetAdvParams(UINT16 adv_int_min, UINT16 adv_int_max, *******************************************************************************/ tBTM_STATUS BTM_BleSetAdvParamsStartAdv(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_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP afp, tBTM_START_ADV_CMPL_CBACK *adv_cb) { 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; @@ -1182,6 +1184,7 @@ tBTM_STATUS BTM_BleSetAdvParamsStartAdv(UINT16 adv_int_min, UINT16 adv_int_max, 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)); @@ -3495,7 +3498,14 @@ void btm_ble_read_remote_features_complete(UINT8 *p) void btm_ble_write_adv_enable_complete(UINT8 *p) { tBTM_BLE_INQ_CB *p_cb = &btm_cb.ble_ctr_cb.inq_var; + UINT8 status = *p; + // callback to the APP after receive the adv complete from the controller. + if (p_cb->p_adv_cb && p_cb->adv_mode == BTM_BLE_ADV_ENABLE) { + (*p_cb->p_adv_cb)(status); + } else if (p_cb->p_stop_adv_cb && p_cb->adv_mode == BTM_BLE_ADV_DISABLE) { + (*p_cb->p_stop_adv_cb)(status); + } /* if write adv enable/disbale not succeed */ if (*p != HCI_SUCCESS) { /* toggle back the adv mode */ diff --git a/components/bt/bluedroid/stack/include/btm_ble_api.h b/components/bt/bluedroid/stack/include/btm_ble_api.h index fa6c575eac..0587b65be2 100644 --- a/components/bt/bluedroid/stack/include/btm_ble_api.h +++ b/components/bt/bluedroid/stack/include/btm_ble_api.h @@ -852,6 +852,11 @@ typedef void (*tBLE_SCAN_PARAM_SETUP_CBACK)(tGATT_IF client_if, tBTM_STATUS stat tBTM_BLE_SCAN_SETUP_CBACK bta_ble_scan_setup_cb; +typedef void (tBTM_START_ADV_CMPL_CBACK) (UINT8 status); +typedef void (tBTM_START_STOP_ADV_CMPL_CBACK) (UINT8 status); + + + /***************************************************************************** ** EXTERNAL FUNCTION DECLARATIONS *****************************************************************************/ @@ -943,7 +948,7 @@ tBTM_STATUS BTM_BleSetAdvParams(UINT16 adv_int_min, UINT16 adv_int_max, *******************************************************************************/ tBTM_STATUS BTM_BleSetAdvParamsStartAdv(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_BLE_ADV_CHNL_MAP chnl_map, tBTM_BLE_AFP afp, tBTM_START_ADV_CMPL_CBACK *adv_cb); /******************************************************************************* @@ -1610,7 +1615,7 @@ BOOLEAN BTM_ReadConnectedTransportAddress(BD_ADDR remote_bda, ** *******************************************************************************/ //extern -tBTM_STATUS BTM_BleBroadcast(BOOLEAN start); +tBTM_STATUS BTM_BleBroadcast(BOOLEAN start, tBTM_START_STOP_ADV_CMPL_CBACK *p_stop_adv_cback); /******************************************************************************* ** diff --git a/components/bt/bluedroid/stack/include/btm_ble_int.h b/components/bt/bluedroid/stack/include/btm_ble_int.h index b690db1bb1..f5b6c90b15 100644 --- a/components/bt/bluedroid/stack/include/btm_ble_int.h +++ b/components/bt/bluedroid/stack/include/btm_ble_int.h @@ -147,7 +147,8 @@ 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; tBLE_ADDR_TYPE adv_addr_type; UINT8 evt_type; UINT8 adv_mode; @@ -319,7 +320,6 @@ typedef struct { UINT32 scan_int; UINT32 scan_win; tBTM_BLE_SEL_CBACK *p_select_cback; - /* white list information */ UINT8 white_list_avail_size; tBTM_ADD_WHITELIST_CBACK *add_wl_cb;