#define LOG_TAG "bt_bta_av"
-#include "bt_target.h"
-
-#include <base/logging.h>
-#include <string.h>
+#include <base/strings/stringprintf.h>
+#include <cstdint>
+#include <cstring>
#include <vector>
-#include "a2dp_sbc.h"
-#include "avdt_api.h"
-#include "avrcp_service.h"
-#include "bt_utils.h"
-#include "bta_av_int.h"
+#include "bt_target.h" // Must be first to define build configuration
+
+#include "bta/av/bta_av_int.h"
+#include "bta/include/bta_ar_api.h"
+#include "bta/include/bta_av_co.h"
+#include "btif/avrcp/avrcp_service.h"
#include "btif/include/btif_av_co.h"
#include "btif/include/btif_config.h"
#include "btif/include/btif_storage.h"
-#include "btm_int.h"
-#include "device/include/controller.h"
#include "device/include/interop.h"
-#include "l2c_api.h"
-#include "l2cdefs.h"
+#include "main/shim/dumpsys.h"
#include "osi/include/log.h"
#include "osi/include/osi.h"
#include "osi/include/properties.h"
-#include "utl.h"
-#if (BTA_AR_INCLUDED == TRUE)
-#include "bta_ar_api.h"
-#endif
-#include "btif/include/btif_av.h"
-#include "btif/include/btif_hf.h"
+#include "stack/include/a2dp_sbc.h"
+#include "stack/include/acl_api.h"
+#include "stack/include/btm_api.h"
+#include "stack/include/btm_client_interface.h"
+#include "stack/include/l2c_api.h"
+#include "types/hci_role.h"
+
+namespace {
+
+constexpr char kBtmLogTag[] = "A2DP";
+
+}
/*****************************************************************************
* Constants
/* ACL quota we are letting FW use for A2DP Offload Tx. */
#define BTA_AV_A2DP_OFFLOAD_XMIT_QUOTA 4
-#define BTIF_A2DP_MAX_BITPOOL_MQ 35
-
static void bta_av_offload_codec_builder(tBTA_AV_SCB* p_scb,
tBT_A2DP_OFFLOAD* p_a2dp_offload);
-static void bta_av_st_rc_timer(tBTA_AV_SCB* p_scb,
- UNUSED_ATTR tBTA_AV_DATA* p_data);
/* state machine states */
enum {
bta_av_co_audio_source_data_path,
bta_av_co_audio_delay,
bta_av_co_audio_update_mtu,
- bta_av_co_content_protect_is_active};
-
-/* ssm action functions for audio stream */
-const tBTA_AV_SACT bta_av_a2dp_action[] = {
- bta_av_do_disc_a2dp, /* BTA_AV_DO_DISC */
- bta_av_cleanup, /* BTA_AV_CLEANUP */
- bta_av_free_sdb, /* BTA_AV_FREE_SDB */
- bta_av_config_ind, /* BTA_AV_CONFIG_IND */
- bta_av_disconnect_req, /* BTA_AV_DISCONNECT_REQ */
- bta_av_security_req, /* BTA_AV_SECURITY_REQ */
- bta_av_security_rsp, /* BTA_AV_SECURITY_RSP */
- bta_av_setconfig_rsp, /* BTA_AV_SETCONFIG_RSP */
- bta_av_st_rc_timer, /* BTA_AV_ST_RC_TIMER */
- bta_av_str_opened, /* BTA_AV_STR_OPENED */
- bta_av_security_ind, /* BTA_AV_SECURITY_IND */
- bta_av_security_cfm, /* BTA_AV_SECURITY_CFM */
- bta_av_do_close, /* BTA_AV_DO_CLOSE */
- bta_av_connect_req, /* BTA_AV_CONNECT_REQ */
- bta_av_sdp_failed, /* BTA_AV_SDP_FAILED */
- bta_av_disc_results, /* BTA_AV_DISC_RESULTS */
- bta_av_disc_res_as_acp, /* BTA_AV_DISC_RES_AS_ACP */
- bta_av_open_failed, /* BTA_AV_OPEN_FAILED */
- bta_av_getcap_results, /* BTA_AV_GETCAP_RESULTS */
- bta_av_setconfig_rej, /* BTA_AV_SETCONFIG_REJ */
- bta_av_discover_req, /* BTA_AV_DISCOVER_REQ */
- bta_av_conn_failed, /* BTA_AV_CONN_FAILED */
- bta_av_do_start, /* BTA_AV_DO_START */
- bta_av_str_stopped, /* BTA_AV_STR_STOPPED */
- bta_av_reconfig, /* BTA_AV_RECONFIG */
- bta_av_data_path, /* BTA_AV_DATA_PATH */
- bta_av_start_ok, /* BTA_AV_START_OK */
- bta_av_start_failed, /* BTA_AV_START_FAILED */
- bta_av_str_closed, /* BTA_AV_STR_CLOSED */
- bta_av_clr_cong, /* BTA_AV_CLR_CONG */
- bta_av_suspend_cfm, /* BTA_AV_SUSPEND_CFM */
- bta_av_rcfg_str_ok, /* BTA_AV_RCFG_STR_OK */
- bta_av_rcfg_failed, /* BTA_AV_RCFG_FAILED */
- bta_av_rcfg_connect, /* BTA_AV_RCFG_CONNECT */
- bta_av_rcfg_discntd, /* BTA_AV_RCFG_DISCNTD */
- bta_av_suspend_cont, /* BTA_AV_SUSPEND_CONT */
- bta_av_rcfg_cfm, /* BTA_AV_RCFG_CFM */
- bta_av_rcfg_open, /* BTA_AV_RCFG_OPEN */
- bta_av_security_rej, /* BTA_AV_SECURITY_REJ */
- bta_av_open_rc, /* BTA_AV_OPEN_RC */
- bta_av_chk_2nd_start, /* BTA_AV_CHK_2ND_START */
- bta_av_save_caps, /* BTA_AV_SAVE_CAPS */
- bta_av_set_use_rc, /* BTA_AV_SET_USE_RC */
- bta_av_cco_close, /* BTA_AV_CCO_CLOSE */
- bta_av_switch_role, /* BTA_AV_SWITCH_ROLE */
- bta_av_role_res, /* BTA_AV_ROLE_RES */
- bta_av_delay_co, /* BTA_AV_DELAY_CO */
- bta_av_open_at_inc, /* BTA_AV_OPEN_AT_INC */
- bta_av_offload_req, /* BTA_AV_OFFLOAD_REQ */
- bta_av_offload_rsp, /* BTA_AV_OFFLOAD_RSP */
- NULL};
+ bta_av_co_get_scmst_info};
/* these tables translate AVDT events to SSM events */
static const uint16_t bta_av_stream_evt_ok[] = {
BTA_AV_AVDT_RPT_CONN_EVT, /* AVDT_REPORT_CONN_EVT */
BTA_AV_AVDT_RPT_CONN_EVT, /* AVDT_REPORT_DISCONN_EVT */
BTA_AV_AVDT_DELAY_RPT_EVT, /* AVDT_DELAY_REPORT_EVT */
- 0 /* AVDT_DELAY_REPORT_CFM_EVT */
+ BTA_AV_AVDT_DELAY_RPT_CFM_EVT, /* AVDT_DELAY_REPORT_CFM_EVT */
};
static const uint16_t bta_av_stream_evt_fail[] = {
BTA_AV_AVDT_RPT_CONN_EVT, /* AVDT_REPORT_CONN_EVT */
BTA_AV_AVDT_RPT_CONN_EVT, /* AVDT_REPORT_DISCONN_EVT */
BTA_AV_AVDT_DELAY_RPT_EVT, /* AVDT_DELAY_REPORT_EVT */
- 0 /* AVDT_DELAY_REPORT_CFM_EVT */
+ BTA_AV_AVDT_DELAY_RPT_CFM_EVT, /* AVDT_DELAY_REPORT_CFM_EVT */
};
/***********************************************
bd_addr.ToString().c_str(), p_scb->recfg_sup,
p_scb->suspend_sup);
if (p_scb->PeerAddress() != bd_addr) {
- LOG_INFO(LOG_TAG, "%s: reset flags old_addr=%s new_addr=%s", __func__,
+ LOG_INFO("%s: reset flags old_addr=%s new_addr=%s", __func__,
p_scb->PeerAddress().ToString().c_str(),
bd_addr.ToString().c_str());
/* a new addr, reset the supported flags */
*
******************************************************************************/
static void notify_start_failed(tBTA_AV_SCB* p_scb) {
- LOG_ERROR(LOG_TAG, "%s: peer %s role:0x%x bta_channel:%d bta_handle:0x%x",
- __func__, p_scb->PeerAddress().ToString().c_str(), p_scb->role,
- p_scb->chnl, p_scb->hndl);
+ LOG_ERROR("%s: peer %s role:0x%x bta_channel:%d bta_handle:0x%x", __func__,
+ p_scb->PeerAddress().ToString().c_str(), p_scb->role, p_scb->chnl,
+ p_scb->hndl);
tBTA_AV_START start;
/* if start failed, clear role */
p_scb->role &= ~BTA_AV_ROLE_START_INT;
* Returns void
*
******************************************************************************/
-static void bta_av_st_rc_timer(tBTA_AV_SCB* p_scb,
- UNUSED_ATTR tBTA_AV_DATA* p_data) {
+void bta_av_st_rc_timer(tBTA_AV_SCB* p_scb, UNUSED_ATTR tBTA_AV_DATA* p_data) {
APPL_TRACE_DEBUG("%s: rc_handle:%d, use_rc: %d", __func__, p_scb->rc_handle,
p_scb->use_rc);
/* for outgoing RC connection as INT/CT */
BTA_AV_AVRC_TIMER_EVT, p_scb->hndl);
}
- if (bta_av_cb.features & BTA_AV_FEAT_MASTER) {
- L2CA_SetDesireRole(L2CAP_ROLE_DISALLOW_SWITCH);
-
- if (bta_av_cb.audio_open_cnt == 1) {
- /* there's already an A2DP connection. do not allow switch */
- bta_sys_clear_default_policy(BTA_ID_AV, HCI_ENABLE_MASTER_SLAVE_SWITCH);
- }
- }
/* store peer addr other parameters */
bta_av_save_addr(p_scb, p_data->api_open.bd_addr);
- p_scb->sec_mask = p_data->api_open.sec_mask;
p_scb->use_rc = p_data->api_open.use_rc;
bta_sys_app_open(BTA_ID_AV, p_scb->app_id, p_scb->PeerAddress());
tBTA_AV_CONN_CHG msg;
uint8_t role = BTA_AV_ROLE_AD_INT;
- LOG_INFO(LOG_TAG, "%s peer %s", __func__,
- p_scb->PeerAddress().ToString().c_str());
+ LOG_INFO("%s peer %s", __func__, p_scb->PeerAddress().ToString().c_str());
/* free any buffers */
p_scb->sdp_discovery_started = false;
/* if de-registering shut everything down */
msg.hdr.layer_specific = p_scb->hndl;
p_scb->started = false;
- p_scb->offload_started = false;
p_scb->use_rtp_header_marker_bit = false;
p_scb->cong = false;
p_scb->role = role;
p_scb->num_disc_snks = 0;
p_scb->coll_mask = 0;
alarm_cancel(p_scb->avrc_ct_timer);
+ alarm_cancel(p_scb->link_signalling_timer);
+ alarm_cancel(p_scb->accept_signalling_timer);
/* TODO(eisenbach): RE-IMPLEMENT USING VSC OR HAL EXTENSION
vendor_get_interface()->send_command(
}
*/
- p_scb->offload_start_pending = false;
-
if (p_scb->deregistering) {
/* remove stream */
for (int i = 0; i < BTAV_A2DP_CODEC_INDEX_MAX; i++) {
/* Clear collision mask */
p_scb->coll_mask = 0;
- alarm_cancel(bta_av_cb.accept_signalling_timer);
+ alarm_cancel(p_scb->accept_signalling_timer);
/* if no codec parameters in configuration, fail */
if ((p_evt_cfg->num_codec == 0) ||
APPL_TRACE_API("%s: conn_lcb: 0x%x peer_addr: %s", __func__,
bta_av_cb.conn_lcb, p_scb->PeerAddress().ToString().c_str());
- alarm_cancel(bta_av_cb.link_signalling_timer);
+ alarm_cancel(p_scb->link_signalling_timer);
+ alarm_cancel(p_scb->accept_signalling_timer);
alarm_cancel(p_scb->avrc_ct_timer);
// conn_lcb is the index bitmask of all used LCBs, and since LCB and SCB use
/* we like this codec_type. find the sep_idx */
local_sep = bta_av_get_scb_sep_type(p_scb, avdt_handle);
bta_av_adjust_seps_idx(p_scb, avdt_handle);
- LOG_DEBUG(
- LOG_TAG,
+ LOG_INFO(
"%s: peer %s bta_handle=0x%x avdt_handle=%d sep_idx=%d cur_psc_mask:0x%x",
__func__, p_scb->PeerAddress().ToString().c_str(), p_scb->hndl,
p_scb->avdt_handle, p_scb->sep_idx, p_scb->cur_psc_mask);
AVDT_ConfigRsp(p_scb->avdt_handle, p_scb->avdt_label,
p_data->ci_setconfig.err_code, p_data->ci_setconfig.category);
- alarm_cancel(bta_av_cb.link_signalling_timer);
+ alarm_cancel(p_scb->link_signalling_timer);
if (p_data->ci_setconfig.err_code == AVDT_SUCCESS) {
p_scb->wait = BTA_AV_WAIT_ACP_CAPS_ON;
******************************************************************************/
void bta_av_str_opened(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
tBTA_AV_CONN_CHG msg;
+ char remote_name[BTM_MAX_REM_BD_NAME_LEN] = "";
uint8_t* p;
APPL_TRACE_DEBUG("%s: peer %s bta_handle: 0x%x", __func__,
bta_av_conn_chg((tBTA_AV_DATA*)&msg);
/* set the congestion flag, so AV would not send media packets by accident */
p_scb->cong = true;
- p_scb->offload_start_pending = false;
+ // Don't use AVDTP SUSPEND for restrict listed devices
+ btif_storage_get_stored_remote_name(p_scb->PeerAddress(), remote_name);
+ if (interop_match_name(INTEROP_DISABLE_AVDTP_SUSPEND, remote_name) ||
+ interop_match_addr(INTEROP_DISABLE_AVDTP_SUSPEND,
+ &p_scb->PeerAddress())) {
+ LOG_INFO("%s: disable AVDTP SUSPEND: interop matched name %s address %s",
+ __func__, remote_name, p_scb->PeerAddress().ToString().c_str());
+ p_scb->suspend_sup = false;
+ }
p_scb->stream_mtu =
p_data->str_msg.msg.open_ind.peer_mtu - AVDT_MEDIA_HDR_SIZE;
}
}
}
-#if (BTA_AR_INCLUDED == TRUE)
bta_ar_avdt_conn(BTA_ID_AV, open.bd_addr, p_scb->hdi);
-#endif
if (p_scb->seps[p_scb->sep_idx].tsep == AVDT_TSEP_SRC) {
open.starting = false;
open.sep = AVDT_TSEP_SNK;
if (p_scb->co_started) {
bta_av_str_stopped(p_scb, NULL);
}
- alarm_cancel(bta_av_cb.link_signalling_timer);
+ alarm_cancel(p_scb->link_signalling_timer);
/* close stream */
p_scb->started = false;
return;
}
- AVDT_ConnectReq(p_scb->PeerAddress(), p_scb->hdi, p_scb->sec_mask,
- &bta_av_proc_stream_evt);
+ AVDT_ConnectReq(p_scb->PeerAddress(), p_scb->hdi, &bta_av_proc_stream_evt);
}
/*******************************************************************************
else if (uuid_int == UUID_SERVCLASS_AUDIO_SINK)
bta_av_adjust_seps_idx(p_scb,
bta_av_get_scb_handle(p_scb, AVDT_TSEP_SNK));
- LOG_DEBUG(LOG_TAG, "%s: sep_idx=%d avdt_handle=%d bta_handle=0x%x",
- __func__, p_scb->sep_idx, p_scb->avdt_handle, p_scb->hndl);
+ LOG_INFO("%s: sep_idx=%d avdt_handle=%d bta_handle=0x%x", __func__,
+ p_scb->sep_idx, p_scb->avdt_handle, p_scb->hndl);
/* use only the services peer supports */
cfg.psc_mask &= p_scb->peer_cap.psc_mask;
uint8_t avdt_handle = p_data->ci_setconfig.avdt_handle;
bta_av_adjust_seps_idx(p_scb, avdt_handle);
- LOG_DEBUG(LOG_TAG, "%s: sep_idx=%d avdt_handle=%d bta_handle=0x%x", __func__,
- p_scb->sep_idx, p_scb->avdt_handle, p_scb->hndl);
+ LOG_INFO("%s: sep_idx=%d avdt_handle=%d bta_handle=0x%x", __func__,
+ p_scb->sep_idx, p_scb->avdt_handle, p_scb->hndl);
AVDT_ConfigRsp(p_scb->avdt_handle, p_scb->avdt_label, AVDT_ERR_UNSUP_CFG, 0);
reject.bd_addr = p_data->str_msg.bd_addr;
*
******************************************************************************/
void bta_av_do_start(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
- uint8_t clear_policy = 0;
- uint8_t cur_role;
-
- LOG_INFO(LOG_TAG,
- "%s: peer %s sco_occupied:%s role:0x%x started:%s wait:0x%x",
- __func__, p_scb->PeerAddress().ToString().c_str(),
- logbool(bta_av_cb.sco_occupied).c_str(), p_scb->role,
- logbool(p_scb->started).c_str(), p_scb->wait);
+ LOG_INFO(
+ "A2dp stream start peer:%s sco_occupied:%s av_role:0x%x started:%s "
+ "wait:0x%x",
+ PRIVATE_ADDRESS(p_scb->PeerAddress()),
+ logbool(bta_av_cb.sco_occupied).c_str(), p_scb->role,
+ logbool(p_scb->started).c_str(), p_scb->wait);
if (bta_av_cb.sco_occupied) {
+ LOG_WARN("A2dp stream start failed");
bta_av_start_failed(p_scb, p_data);
return;
}
- /* disallow role switch during streaming, only if we are the master role
- * i.e. allow role switch, if we are slave.
- * It would not hurt us, if the peer device wants us to be master */
+ /* disallow role switch during streaming, only if we are the central role
+ * i.e. allow role switch, if we are peripheral.
+ * It would not hurt us, if the peer device wants us to be central */
+ tHCI_ROLE cur_role;
if ((BTM_GetRole(p_scb->PeerAddress(), &cur_role) == BTM_SUCCESS) &&
- (cur_role == BTM_ROLE_MASTER)) {
- clear_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
+ (cur_role == HCI_ROLE_CENTRAL)) {
+ BTM_block_role_switch_for(p_scb->PeerAddress());
}
-
- bta_sys_clear_policy(BTA_ID_AV, clear_policy, p_scb->PeerAddress());
+ BTM_block_sniff_mode_for(p_scb->PeerAddress());
if (p_scb->started) {
p_scb->role |= BTA_AV_ROLE_START_INT;
if (p_scb->wait != 0) {
LOG_WARN(
- LOG_TAG,
"%s: peer %s start stream request ignored: "
"already waiting: sco_occupied:%s role:0x%x started:%s wait:0x%x",
__func__, p_scb->PeerAddress().ToString().c_str(),
if ((p_scb->role & BTA_AV_ROLE_START_INT) != 0) {
LOG_WARN(
- LOG_TAG,
"%s: peer %s start stream request ignored: "
"already initiated: sco_occupied:%s role:0x%x started:%s wait:0x%x",
__func__, p_scb->PeerAddress().ToString().c_str(),
bta_sys_busy(BTA_ID_AV, bta_av_cb.audio_open_cnt, p_scb->PeerAddress());
uint16_t result = AVDT_StartReq(&p_scb->avdt_handle, 1);
if (result != AVDT_SUCCESS) {
- LOG_ERROR(LOG_TAG, "%s: AVDT_StartReq failed for peer %s result:%d",
- __func__, p_scb->PeerAddress().ToString().c_str(), result);
+ LOG_ERROR("%s: AVDT_StartReq failed for peer %s result:%d", __func__,
+ p_scb->PeerAddress().ToString().c_str(), result);
bta_av_start_failed(p_scb, p_data);
}
- LOG_INFO(LOG_TAG,
- "%s: peer %s start requested: sco_occupied:%s role:0x%x "
- "started:%s wait:0x%x",
- __func__, p_scb->PeerAddress().ToString().c_str(),
- logbool(bta_av_cb.sco_occupied).c_str(), p_scb->role,
- logbool(p_scb->started).c_str(), p_scb->wait);
+ LOG_INFO(
+ "%s: peer %s start requested: sco_occupied:%s role:0x%x "
+ "started:%s wait:0x%x",
+ __func__, p_scb->PeerAddress().ToString().c_str(),
+ logbool(bta_av_cb.sco_occupied).c_str(), p_scb->role,
+ logbool(p_scb->started).c_str(), p_scb->wait);
}
/*******************************************************************************
uint8_t start = p_scb->started;
bool sus_evt = true;
BT_HDR* p_buf;
- uint8_t set_policy = HCI_ENABLE_SNIFF_MODE;
APPL_TRACE_ERROR(
"%s: peer %s bta_handle:0x%x audio_open_cnt:%d, p_data %p start:%d",
bta_av_cb.audio_open_cnt, p_data, start);
bta_sys_idle(BTA_ID_AV, bta_av_cb.audio_open_cnt, p_scb->PeerAddress());
- if ((bta_av_cb.features & BTA_AV_FEAT_MASTER) == 0 ||
- bta_av_cb.audio_open_cnt == 1) {
- set_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
- }
- bta_sys_set_policy(BTA_ID_AV, set_policy, p_scb->PeerAddress());
+ BTM_unblock_role_switch_for(p_scb->PeerAddress());
+ BTM_unblock_sniff_mode_for(p_scb->PeerAddress());
if (p_scb->co_started) {
- if (p_scb->offload_started) {
+ uint16_t handle = get_btm_client_interface().lifecycle.BTM_GetHCIConnHandle(
+ p_scb->PeerAddress(), BT_TRANSPORT_BR_EDR);
+ if (bta_av_cb.offload_started_acl_hdl == handle) {
+ bta_av_vendor_offload_stop();
+ bta_av_cb.offload_started_acl_hdl = HCI_INVALID_HANDLE;
+ } else if (bta_av_cb.offload_start_pending_acl_hdl == handle) {
+ APPL_TRACE_WARNING("%s: Stop pending offload start command", __func__);
bta_av_vendor_offload_stop();
- p_scb->offload_started = false;
+ bta_av_cb.offload_start_pending_acl_hdl = HCI_INVALID_HANDLE;
}
bta_av_stream_chg(p_scb, false);
p_scb->co_started = false;
p_scb->p_cos->stop(p_scb->hndl, p_scb->PeerAddress());
- L2CA_SetFlushTimeout(p_scb->PeerAddress(), L2CAP_DEFAULT_FLUSH_TO);
}
/* if q_info.a2dp_list is not empty, drop it now */
alarm_cancel(p_scb->avrc_ct_timer);
- APPL_TRACE_DEBUG(
- "%s: p_scb->sep_info_idx=%d p_scb->rcfg_idx=%d p_rcfg->sep_info_idx=%d",
- __func__, p_scb->sep_info_idx, p_scb->rcfg_idx, p_rcfg->sep_info_idx);
- APPL_TRACE_DEBUG("%s: codec: %s", __func__,
- A2DP_CodecInfoString(p_scb->peer_cap.codec_info).c_str());
- APPL_TRACE_DEBUG("%s: codec: %s", __func__,
- A2DP_CodecInfoString(p_scb->cfg.codec_info).c_str());
- APPL_TRACE_DEBUG("%s: codec: %s", __func__,
- A2DP_CodecInfoString(p_rcfg->codec_info).c_str());
+ LOG_DEBUG("p_scb->sep_info_idx=%d p_scb->rcfg_idx=%d p_rcfg->sep_info_idx=%d",
+ p_scb->sep_info_idx, p_scb->rcfg_idx, p_rcfg->sep_info_idx);
+ LOG_DEBUG("Peer capable codec: %s",
+ A2DP_CodecInfoString(p_scb->peer_cap.codec_info).c_str());
+ LOG_DEBUG("Current codec: %s",
+ A2DP_CodecInfoString(p_scb->cfg.codec_info).c_str());
+ LOG_DEBUG("Reconfig codec: %s",
+ A2DP_CodecInfoString(p_rcfg->codec_info).c_str());
+
+ BTM_LogHistory(
+ kBtmLogTag, p_scb->PeerAddress(), "Codec reconfig",
+ base::StringPrintf("%s => %s", A2DP_CodecName(p_scb->cfg.codec_info),
+ A2DP_CodecName(p_rcfg->codec_info)));
p_cfg->num_protect = p_rcfg->num_protect;
memcpy(p_cfg->codec_info, p_rcfg->codec_info, AVDT_CODEC_SIZE);
void bta_av_start_ok(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
bool initiator = false;
bool suspend = false;
- uint16_t flush_to;
uint8_t new_role = p_scb->role;
- BT_HDR hdr;
- uint8_t clear_policy = 0;
- uint8_t cur_role;
+ BT_HDR_RIGID hdr;
+ tHCI_ROLE cur_role;
uint8_t local_tsep = p_scb->seps[p_scb->sep_idx].tsep;
- LOG_INFO(LOG_TAG,
- "%s: peer %s bta_handle:0x%x wait:0x%x role:0x%x local_tsep:%d",
+ LOG_INFO("%s: peer %s bta_handle:0x%x wait:0x%x role:0x%x local_tsep:%d",
__func__, p_scb->PeerAddress().ToString().c_str(), p_scb->hndl,
p_scb->wait, p_scb->role, local_tsep);
if (!bta_av_link_role_ok(p_scb, A2DP_SET_ONE_BIT))
p_scb->q_tag = BTA_AV_Q_TAG_START;
else {
- /* The wait flag may be set here while we are already master on the link */
+ /* The wait flag may be set here while we are already central on the link */
/* this could happen if a role switch complete event occurred during
* reconfig */
- /* if we are now master on the link, there is no need to wait for the role
+ /* if we are now central on the link, there is no need to wait for the role
* switch, */
/* complete anymore so we can clear the wait for role switch flag */
p_scb->wait &= ~BTA_AV_WAIT_ROLE_SW_BITS;
* to be changed
*/
p_scb->co_started = bta_av_cb.audio_open_cnt;
- flush_to = p_bta_av_cfg->p_audio_flush_to[p_scb->co_started - 1];
- } else {
- flush_to = 0;
}
- L2CA_SetFlushTimeout(p_scb->PeerAddress(), flush_to);
/* clear the congestion flag */
p_scb->cong = false;
{
/* If sink starts stream, disable sniff mode here */
if (!initiator) {
- /* If souce is the master role, disable role switch during streaming.
- * Otherwise allow role switch, if source is slave.
+ /* If souce is the central role, disable role switch during streaming.
+ * Otherwise allow role switch, if source is peripheral.
* Because it would not hurt source, if the peer device wants source to be
- * master */
+ * central */
if ((BTM_GetRole(p_scb->PeerAddress(), &cur_role) == BTM_SUCCESS) &&
- (cur_role == BTM_ROLE_MASTER)) {
- clear_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
+ (cur_role == HCI_ROLE_CENTRAL)) {
+ BTM_block_role_switch_for(p_scb->PeerAddress());
}
-
- bta_sys_clear_policy(BTA_ID_AV, clear_policy, p_scb->PeerAddress());
}
p_scb->role = new_role;
*
******************************************************************************/
void bta_av_start_failed(tBTA_AV_SCB* p_scb, UNUSED_ATTR tBTA_AV_DATA* p_data) {
- uint8_t set_policy = (HCI_ENABLE_SNIFF_MODE | HCI_ENABLE_MASTER_SLAVE_SWITCH);
-
APPL_TRACE_ERROR(
"%s: peer %s bta_handle:0x%x audio_open_cnt:%d started:%s co_started:%d",
__func__, p_scb->PeerAddress().ToString().c_str(), p_scb->hndl,
notify_start_failed(p_scb);
}
- bta_sys_set_policy(BTA_ID_AV, set_policy, p_scb->PeerAddress());
+ BTM_unblock_role_switch_for(p_scb->PeerAddress());
+ BTM_unblock_sniff_mode_for(p_scb->PeerAddress());
p_scb->sco_suspend = false;
}
void bta_av_str_closed(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
tBTA_AV data;
tBTA_AV_EVT event;
- uint8_t set_policy = HCI_ENABLE_SNIFF_MODE;
APPL_TRACE_WARNING(
"%s: peer %s bta_handle:0x%x open_status:%d chnl:%d co_started:%d",
__func__, p_scb->PeerAddress().ToString().c_str(), p_scb->hndl,
p_scb->open_status, p_scb->chnl, p_scb->co_started);
- if ((bta_av_cb.features & BTA_AV_FEAT_MASTER) == 0 ||
- bta_av_cb.audio_open_cnt == 1) {
- set_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
- }
- bta_sys_set_policy(BTA_ID_AV, set_policy, p_scb->PeerAddress());
+ BTM_unblock_role_switch_for(p_scb->PeerAddress());
+ BTM_unblock_sniff_mode_for(p_scb->PeerAddress());
if (bta_av_cb.audio_open_cnt <= 1) {
- /* last connection - restore the allow switch flag */
- L2CA_SetDesireRole(L2CAP_ROLE_ALLOW_SWITCH);
+ BTM_default_unblock_role_switch();
}
if (p_scb->open_status != BTA_AV_SUCCESS) {
void bta_av_suspend_cfm(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
tBTA_AV_SUSPEND suspend_rsp;
uint8_t err_code = p_data->str_msg.msg.hdr.err_code;
- uint8_t set_policy = HCI_ENABLE_SNIFF_MODE;
APPL_TRACE_DEBUG("%s: peer %s bta_handle:0x%x audio_open_cnt:%d err_code:%d",
__func__, p_scb->PeerAddress().ToString().c_str(),
suspend_rsp.status = BTA_AV_SUCCESS;
if (err_code && (err_code != AVDT_ERR_BAD_STATE)) {
- /* Disable suspend feature only with explicit rejection(not with timeout) */
- if (err_code != AVDT_ERR_TIMEOUT) {
- p_scb->suspend_sup = false;
- }
suspend_rsp.status = BTA_AV_FAIL;
APPL_TRACE_ERROR("%s: suspend failed, closing connection", __func__);
}
bta_sys_idle(BTA_ID_AV, bta_av_cb.audio_open_cnt, p_scb->PeerAddress());
- if ((bta_av_cb.features & BTA_AV_FEAT_MASTER) == 0 ||
- bta_av_cb.audio_open_cnt == 1) {
- set_policy |= HCI_ENABLE_MASTER_SLAVE_SWITCH;
- }
- bta_sys_set_policy(BTA_ID_AV, set_policy, p_scb->PeerAddress());
+ BTM_unblock_role_switch_for(p_scb->PeerAddress());
+ BTM_unblock_sniff_mode_for(p_scb->PeerAddress());
/* in case that we received suspend_ind, we may need to call co_stop here */
if (p_scb->co_started) {
- if (p_scb->offload_started) {
+ uint16_t handle = get_btm_client_interface().lifecycle.BTM_GetHCIConnHandle(
+ p_scb->PeerAddress(), BT_TRANSPORT_BR_EDR);
+ if (bta_av_cb.offload_started_acl_hdl == handle) {
+ bta_av_vendor_offload_stop();
+ bta_av_cb.offload_started_acl_hdl = HCI_INVALID_HANDLE;
+ } else if (bta_av_cb.offload_start_pending_acl_hdl == handle) {
+ APPL_TRACE_WARNING("%s: Stop pending offload start command", __func__);
bta_av_vendor_offload_stop();
- p_scb->offload_started = false;
+ bta_av_cb.offload_start_pending_acl_hdl = HCI_INVALID_HANDLE;
}
bta_av_stream_chg(p_scb, false);
p_scb->co_started = false;
p_scb->p_cos->stop(p_scb->hndl, p_scb->PeerAddress());
}
- L2CA_SetFlushTimeout(p_scb->PeerAddress(), L2CAP_DEFAULT_FLUSH_TO);
}
{
/* let bta_av_rcfg_failed report fail */
bta_av_rcfg_failed(p_scb, NULL);
} else {
- AVDT_ConnectReq(p_scb->PeerAddress(), p_scb->hdi, p_scb->sec_mask,
- &bta_av_proc_stream_evt);
+ AVDT_ConnectReq(p_scb->PeerAddress(), p_scb->hdi, &bta_av_proc_stream_evt);
}
}
/* report close event & go to init state */
bta_av_ssm_execute(p_scb, BTA_AV_STR_DISC_FAIL_EVT, NULL);
} else {
- AVDT_ConnectReq(p_scb->PeerAddress(), p_scb->hdi, p_scb->sec_mask,
- &bta_av_proc_stream_evt);
+ AVDT_ConnectReq(p_scb->PeerAddress(), p_scb->hdi, &bta_av_proc_stream_evt);
}
}
bta_av_ssm_execute(p_scb, BTA_AV_STR_DISC_FAIL_EVT, NULL);
} else {
APPL_TRACE_ERROR("%s: suspend rejected, try close", __func__);
- /* Disable suspend feature only with explicit rejection(not with timeout)
- */
- if (err_code != AVDT_ERR_TIMEOUT) {
- p_scb->suspend_sup = false;
- }
/* drop the buffers queued in L2CAP */
L2CA_FlushChannel(p_scb->l2c_cid, L2CAP_FLUSH_CHANS_ALL);
APPL_TRACE_DEBUG("%s: err_code = %d", __func__, err_code);
- // Disable AVDTP RECONFIGURE for blacklisted devices
+ // Disable AVDTP RECONFIGURE for rejectlisted devices
bool disable_avdtp_reconfigure = false;
{
char remote_name[BTM_MAX_REM_BD_NAME_LEN] = "";
if (interop_match_name(INTEROP_DISABLE_AVDTP_RECONFIGURE, remote_name) ||
interop_match_addr(INTEROP_DISABLE_AVDTP_RECONFIGURE,
(const RawAddress*)&p_scb->PeerAddress())) {
- LOG_INFO(LOG_TAG,
- "%s: disable AVDTP RECONFIGURE: interop matched "
- "name %s address %s",
- __func__, remote_name,
- p_scb->PeerAddress().ToString().c_str());
+ LOG_INFO(
+ "%s: disable AVDTP RECONFIGURE: interop matched "
+ "name %s address %s",
+ __func__, remote_name, p_scb->PeerAddress().ToString().c_str());
disable_avdtp_reconfigure = true;
}
}
/* we may choose to use a different SEP at reconfig.
* adjust the sep_idx now */
bta_av_adjust_seps_idx(p_scb, bta_av_get_scb_handle(p_scb, AVDT_TSEP_SRC));
- LOG_DEBUG(LOG_TAG, "%s: sep_idx=%d avdt_handle=%d bta_handle=0x%x",
- __func__, p_scb->sep_idx, p_scb->avdt_handle, p_scb->hndl);
+ LOG_INFO("%s: sep_idx=%d avdt_handle=%d bta_handle=0x%x", __func__,
+ p_scb->sep_idx, p_scb->avdt_handle, p_scb->hndl);
/* open the stream with the new config */
p_scb->sep_info_idx = p_scb->rcfg_idx;
******************************************************************************/
void bta_av_chk_2nd_start(tBTA_AV_SCB* p_scb,
UNUSED_ATTR tBTA_AV_DATA* p_data) {
- LOG_INFO(LOG_TAG,
- "%s: peer %s channel:%d bta_av_cb.audio_open_cnt:%d role:0x%x "
- "features:0x%x",
- __func__, p_scb->PeerAddress().ToString().c_str(), p_scb->chnl,
- bta_av_cb.audio_open_cnt, p_scb->role, bta_av_cb.features);
+ LOG_INFO(
+ "%s: peer %s channel:%d bta_av_cb.audio_open_cnt:%d role:0x%x "
+ "features:0x%x",
+ __func__, p_scb->PeerAddress().ToString().c_str(), p_scb->chnl,
+ bta_av_cb.audio_open_cnt, p_scb->role, bta_av_cb.features);
if ((p_scb->chnl == BTA_AV_CHNL_AUDIO) && (bta_av_cb.audio_open_cnt >= 2) &&
(((p_scb->role & BTA_AV_ROLE_AD_ACP) == 0) || // Outgoing connection or
if (!new_started) {
// Start the new stream
new_started = true;
- LOG_INFO(LOG_TAG,
- "%s: starting new stream for peer %s because peer %s "
- "already started",
- __func__, p_scb->PeerAddress().ToString().c_str(),
- p_scbi->PeerAddress().ToString().c_str());
+ LOG_INFO(
+ "%s: starting new stream for peer %s because peer %s "
+ "already started",
+ __func__, p_scb->PeerAddress().ToString().c_str(),
+ p_scbi->PeerAddress().ToString().c_str());
bta_av_ssm_execute(p_scb, BTA_AV_AP_START_EVT, NULL);
}
// May need to update the flush timeout of this already started stream
if (p_scbi->co_started != bta_av_cb.audio_open_cnt) {
p_scbi->co_started = bta_av_cb.audio_open_cnt;
- L2CA_SetFlushTimeout(
- p_scbi->PeerAddress(),
- p_bta_av_cfg->p_audio_flush_to[p_scbi->co_started - 1]);
}
}
}
if (param->param_len) {
APPL_TRACE_DEBUG("%s: param_len = %d status = %d", __func__,
param->param_len, param->p_param_buf[0]);
- value.status = param->p_param_buf[0];
+ value.status = static_cast<tBTA_AV_STATUS>(param->p_param_buf[0]);
}
if (value.status == 0) {
sub_opcode = param->p_param_buf[1];
APPL_TRACE_DEBUG("%s: VS_HCI_STOP_A2DP_MEDIA successful", __func__);
break;
case VS_HCI_A2DP_OFFLOAD_START:
+ if (bta_av_cb.offload_start_pending_acl_hdl != HCI_INVALID_HANDLE) {
+ bta_av_cb.offload_started_acl_hdl =
+ bta_av_cb.offload_start_pending_acl_hdl;
+ bta_av_cb.offload_start_pending_acl_hdl = HCI_INVALID_HANDLE;
+ } else {
+ LOG_INFO("%s: No pending start command due to AVDTP suspend immediately", __func__);
+ }
(*bta_av_cb.p_cback)(BTA_AV_OFFLOAD_START_RSP_EVT, &value);
break;
default:
} else {
APPL_TRACE_DEBUG("%s: Offload failed for subopcode= %d", __func__,
sub_opcode);
- if (param->opcode != VS_HCI_A2DP_OFFLOAD_STOP)
+ if (param->opcode != VS_HCI_A2DP_OFFLOAD_STOP) {
+ bta_av_cb.offload_start_pending_acl_hdl = HCI_INVALID_HANDLE;
(*bta_av_cb.p_cback)(BTA_AV_OFFLOAD_START_RSP_EVT, &value);
+ }
}
}
UINT32_TO_STREAM(p_param, offload_start->codec_type);
UINT16_TO_STREAM(p_param, offload_start->max_latency);
- UINT16_TO_STREAM(p_param, offload_start->scms_t_enable);
+ ARRAY_TO_STREAM(p_param, offload_start->scms_t_enable,
+ static_cast<int>(offload_start->scms_t_enable.size()));
UINT32_TO_STREAM(p_param, offload_start->sample_rate);
UINT8_TO_STREAM(p_param, offload_start->bits_per_sample);
UINT8_TO_STREAM(p_param, offload_start->ch_mode);
UINT16_TO_STREAM(p_param, offload_start->mtu);
ARRAY_TO_STREAM(p_param, offload_start->codec_info,
(int8_t)sizeof(offload_start->codec_info));
- p_scb->offload_started = true;
+ bta_av_cb.offload_start_pending_acl_hdl = offload_start->acl_hdl;
BTM_VendorSpecificCommand(HCI_CONTROLLER_A2DP, p_param - param,
param, offload_vendor_callback);
}
/* Support offload if only one audio source stream is open. */
if (p_scb->started != true) {
status = BTA_AV_FAIL_STREAM;
+ } else if (bta_av_cb.offload_start_pending_acl_hdl != HCI_INVALID_HANDLE ||
+ bta_av_cb.offload_started_acl_hdl != HCI_INVALID_HANDLE) {
+ APPL_TRACE_WARNING("%s: offload already started, ignore request", __func__);
+ return;
} else {
bta_av_offload_codec_builder(p_scb, &offload_start);
bta_av_vendor_offload_start(p_scb, &offload_start);
status = BTA_AV_FAIL_STREAM;
}
- p_scb->offload_start_pending = false;
+ bta_av_cb.offload_start_pending_acl_hdl = HCI_INVALID_HANDLE;
tBTA_AV bta_av_data;
bta_av_data.status = status;
(*bta_av_cb.p_cback)(BTA_AV_OFFLOAD_START_RSP_EVT, &bta_av_data);
case BTAV_A2DP_CODEC_INDEX_SOURCE_SBC:
codec_type = BTA_AV_CODEC_TYPE_SBC;
if (A2DP_GetMaxBitpoolSbc(p_scb->cfg.codec_info) <=
- BTIF_A2DP_MAX_BITPOOL_MQ) {
+ A2DP_SBC_BITPOOL_MIDDLE_QUALITY) {
APPL_TRACE_WARNING("%s: Restricting streaming MTU size for MQ Bitpool",
__func__);
mtu = MAX_2MBPS_AVDTP_MTU;
p_a2dp_offload->max_latency = 0;
p_a2dp_offload->mtu = mtu;
p_a2dp_offload->acl_hdl =
- BTM_GetHCIConnHandle(p_scb->PeerAddress(), BT_TRANSPORT_BR_EDR);
- p_a2dp_offload->scms_t_enable =
- p_scb->p_cos->cp_is_active(p_scb->PeerAddress());
- APPL_TRACE_DEBUG("%s: scms_t_enable =%d", __func__,
- p_a2dp_offload->scms_t_enable);
+ get_btm_client_interface().lifecycle.BTM_GetHCIConnHandle(
+ p_scb->PeerAddress(), BT_TRANSPORT_BR_EDR);
+ btav_a2dp_scmst_info_t scmst_info =
+ p_scb->p_cos->get_scmst_info(p_scb->PeerAddress());
+ p_a2dp_offload->scms_t_enable[0] = scmst_info.enable_status;
+ p_a2dp_offload->scms_t_enable[1] = scmst_info.cp_header;
+ APPL_TRACE_DEBUG(
+ "%s: SCMS-T_enable status: %d, "
+ "SCMS-T header (if it's enabled): 0x%02x",
+ __func__, scmst_info.enable_status, scmst_info.cp_header);
switch (A2DP_GetTrackSampleRate(p_scb->cfg.codec_info)) {
case 44100:
p_a2dp_offload->sample_rate = BTAV_A2DP_CODEC_SAMPLE_RATE_96000;
break;
}
- if (L2CA_GetIdentifiers(p_scb->l2c_cid, &p_a2dp_offload->l2c_rcid, NULL) ==
- false) {
+ if (L2CA_GetRemoteCid(p_scb->l2c_cid, &p_a2dp_offload->l2c_rcid) == false) {
APPL_TRACE_ERROR("%s: Failed to fetch l2c rcid", __func__);
return;
}