Skip to content

Commit

Permalink
bt:Fixed the use of invalid configuration when the peer device config…
Browse files Browse the repository at this point in the history
…ures the stream, and returned an incorrect error code
  • Loading branch information
xiongweichao committed Dec 15, 2022
1 parent 5278cc7 commit 9bd1484
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 57 deletions.
2 changes: 1 addition & 1 deletion components/bt/host/bluedroid/bta/av/bta_av_aact.c
Original file line number Diff line number Diff line change
Expand Up @@ -1914,7 +1914,7 @@ void bta_av_setconfig_rej (tBTA_AV_SCB *p_scb, tBTA_AV_DATA *p_data)

bta_av_adjust_seps_idx(p_scb, avdt_handle);
APPL_TRACE_DEBUG("bta_av_setconfig_rej: sep_idx: %d", p_scb->sep_idx);
AVDT_ConfigRsp(p_scb->avdt_handle, p_scb->avdt_label, AVDT_ERR_UNSUP_CFG, 0);
AVDT_ConfigRsp(p_scb->avdt_handle, p_scb->avdt_label, p_data->ci_setconfig.err_code, 0);

bdcpy(reject.bd_addr, p_data->str_msg.bd_addr);
reject.hndl = p_scb->hndl;
Expand Down
58 changes: 31 additions & 27 deletions components/bt/host/bluedroid/btc/profile/std/a2dp/bta_av_co.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ static void bta_av_co_audio_peer_reset_config(tBTA_AV_CO_PEER *p_peer);
static BOOLEAN bta_av_co_cp_is_scmst(const UINT8 *p_protectinfo);
static BOOLEAN bta_av_co_audio_sink_has_scmst(const tBTA_AV_CO_SINK *p_sink);
static BOOLEAN bta_av_co_audio_peer_supports_codec(tBTA_AV_CO_PEER *p_peer, UINT8 *p_snk_index);
static BOOLEAN bta_av_co_audio_media_supports_config(UINT8 codec_type, const UINT8 *p_codec_cfg);
static BOOLEAN bta_av_co_audio_sink_supports_config(UINT8 codec_type, const UINT8 *p_codec_cfg);
static UINT8 bta_av_co_audio_media_supports_config(UINT8 codec_type, const UINT8 *p_codec_cfg);
static UINT8 bta_av_co_audio_sink_supports_config(UINT8 codec_type, const UINT8 *p_codec_cfg);
static BOOLEAN bta_av_co_audio_peer_src_supports_codec(tBTA_AV_CO_PEER *p_peer, UINT8 *p_src_index);


Expand Down Expand Up @@ -660,7 +660,7 @@ void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
UINT8 status = A2D_SUCCESS;
UINT8 category = A2D_SUCCESS;
BOOLEAN recfg_needed = FALSE;
BOOLEAN codec_cfg_supported = FALSE;
UINT8 codec_cfg_status = A2D_SUCCESS;
UNUSED(seid);
UNUSED(addr);

Expand Down Expand Up @@ -709,15 +709,15 @@ void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
#endif
if (status == A2D_SUCCESS) {
if (AVDT_TSEP_SNK == t_local_sep) {
codec_cfg_supported = bta_av_co_audio_sink_supports_config(codec_type, p_codec_info);
codec_cfg_status = bta_av_co_audio_sink_supports_config(codec_type, p_codec_info);
APPL_TRACE_DEBUG(" Peer is A2DP SRC ");
}
if (AVDT_TSEP_SRC == t_local_sep) {
codec_cfg_supported = bta_av_co_audio_media_supports_config(codec_type, p_codec_info);
codec_cfg_status = bta_av_co_audio_media_supports_config(codec_type, p_codec_info);
APPL_TRACE_DEBUG(" Peer is A2DP SINK ");
}
/* Check if codec configuration is supported */
if (codec_cfg_supported) {
if (codec_cfg_status == A2D_SUCCESS) {

/* Protect access to bta_av_co_cb.codec_cfg */
osi_mutex_global_lock();
Expand Down Expand Up @@ -757,15 +757,15 @@ void bta_av_co_audio_setconfig(tBTA_AV_HNDL hndl, tBTA_AV_CODEC codec_type,
osi_mutex_global_unlock();
} else {
category = AVDT_ASC_CODEC;
status = A2D_WRONG_CODEC;
status = A2D_FAIL;
}
}

if (status != A2D_SUCCESS) {
APPL_TRACE_DEBUG("bta_av_co_audio_setconfig reject s=%d c=%d", status, category);
APPL_TRACE_DEBUG("bta_av_co_audio_setconfig reject s=%d c=%d", codec_cfg_status, category);

/* Call call-in rejecting the configuration */
bta_av_ci_setconfig(hndl, status, category, 0, NULL, FALSE, avdt_handle);
bta_av_ci_setconfig(hndl, codec_cfg_status, category, 0, NULL, FALSE, avdt_handle);
} else {
/* Mark that this is an acceptor peer */
p_peer->acp = TRUE;
Expand Down Expand Up @@ -1275,24 +1275,26 @@ static BOOLEAN bta_av_co_audio_peer_src_supports_codec(tBTA_AV_CO_PEER *p_peer,
** Returns TRUE if the media source supports this config, FALSE otherwise
**
*******************************************************************************/
static BOOLEAN bta_av_co_audio_sink_supports_config(UINT8 codec_type, const UINT8 *p_codec_cfg)
static UINT8 bta_av_co_audio_sink_supports_config(UINT8 codec_type, const UINT8 *p_codec_cfg)
{
FUNC_TRACE();
UINT8 status = A2D_BAD_CODEC_TYPE;

switch (codec_type) {
case BTA_AV_CODEC_SBC:
if (bta_av_sbc_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_SBC_CIE *)&bta_av_co_sbc_sink_caps)) {
return FALSE;
}
status = bta_av_sbc_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_SBC_CIE *)&bta_av_co_sbc_sink_caps);
break;
case BTA_AV_CODEC_M12:
case BTA_AV_CODEC_M24:
case BTA_AV_CODEC_ATRAC:
status = A2D_NS_CODEC_TYPE;
APPL_TRACE_ERROR("bta_av_co_audio_sink_supports_config unsupported codec type %d", codec_type);
break;


default:
APPL_TRACE_ERROR("bta_av_co_audio_media_supports_config unsupported codec type %d", codec_type);
return FALSE;
APPL_TRACE_ERROR("bta_av_co_audio_sink_supports_config invalid codec type %d", codec_type);
break;
}
return TRUE;
return status;
}

/*******************************************************************************
Expand All @@ -1304,24 +1306,26 @@ static BOOLEAN bta_av_co_audio_sink_supports_config(UINT8 codec_type, const UINT
** Returns TRUE if the media source supports this config, FALSE otherwise
**
*******************************************************************************/
static BOOLEAN bta_av_co_audio_media_supports_config(UINT8 codec_type, const UINT8 *p_codec_cfg)
static UINT8 bta_av_co_audio_media_supports_config(UINT8 codec_type, const UINT8 *p_codec_cfg)
{
FUNC_TRACE();
UINT8 status = A2D_BAD_CODEC_TYPE;

switch (codec_type) {
case BTA_AV_CODEC_SBC:
if (bta_av_sbc_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_SBC_CIE *)&bta_av_co_sbc_caps)) {
return FALSE;
}
status = bta_av_sbc_cfg_in_cap((UINT8 *)p_codec_cfg, (tA2D_SBC_CIE *)&bta_av_co_sbc_caps);
break;


default:
case BTA_AV_CODEC_M12:
case BTA_AV_CODEC_M24:
case BTA_AV_CODEC_ATRAC:
status = A2D_NS_CODEC_TYPE;
APPL_TRACE_ERROR("bta_av_co_audio_media_supports_config unsupported codec type %d", codec_type);
return FALSE;
break;
default:
APPL_TRACE_ERROR("bta_av_co_audio_media_supports_config invalid codec type %d", codec_type);
break;
}
return TRUE;
return status;
}

/*******************************************************************************
Expand Down
15 changes: 5 additions & 10 deletions components/bt/host/bluedroid/stack/a2dp/a2d_sbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ tA2D_STATUS A2D_BldSbcInfo(UINT8 media_type, tA2D_SBC_CIE *p_ie, UINT8 *p_result
******************************************************************************/
tA2D_STATUS A2D_ParsSbcInfo(tA2D_SBC_CIE *p_ie, UINT8 *p_info, BOOLEAN for_caps)
{
tA2D_STATUS status;
tA2D_STATUS status = A2D_SUCCESS;
UINT8 losc;

if ( p_ie == NULL || p_info == NULL) {
Expand All @@ -127,7 +127,6 @@ tA2D_STATUS A2D_ParsSbcInfo(tA2D_SBC_CIE *p_ie, UINT8 *p_info, BOOLEAN for_caps)
p_info++;
p_ie->min_bitpool = *p_info++;
p_ie->max_bitpool = *p_info;
status = A2D_SUCCESS;
if (p_ie->min_bitpool < A2D_SBC_IE_MIN_BITPOOL || p_ie->min_bitpool > A2D_SBC_IE_MAX_BITPOOL ) {
status = A2D_BAD_MIN_BITPOOL;
}
Expand All @@ -140,17 +139,13 @@ tA2D_STATUS A2D_ParsSbcInfo(tA2D_SBC_CIE *p_ie, UINT8 *p_info, BOOLEAN for_caps)
if (for_caps == FALSE) {
if (A2D_BitsSet(p_ie->samp_freq) != A2D_SET_ONE_BIT) {
status = A2D_BAD_SAMP_FREQ;
}
if (A2D_BitsSet(p_ie->ch_mode) != A2D_SET_ONE_BIT) {
} else if (A2D_BitsSet(p_ie->ch_mode) != A2D_SET_ONE_BIT) {
status = A2D_BAD_CH_MODE;
}
if (A2D_BitsSet(p_ie->block_len) != A2D_SET_ONE_BIT) {
} else if (A2D_BitsSet(p_ie->block_len) != A2D_SET_ONE_BIT) {
status = A2D_BAD_BLOCK_LEN;
}
if (A2D_BitsSet(p_ie->num_subbands) != A2D_SET_ONE_BIT) {
} else if (A2D_BitsSet(p_ie->num_subbands) != A2D_SET_ONE_BIT) {
status = A2D_BAD_SUBBANDS;
}
if (A2D_BitsSet(p_ie->alloc_mthd) != A2D_SET_ONE_BIT) {
} else if (A2D_BitsSet(p_ie->alloc_mthd) != A2D_SET_ONE_BIT) {
status = A2D_BAD_ALLOC_MTHD;
}
}
Expand Down
31 changes: 12 additions & 19 deletions components/bt/host/bluedroid/stack/avdt/avdt_scb_act.c
Original file line number Diff line number Diff line change
Expand Up @@ -788,25 +788,18 @@ void avdt_scb_hdl_setconfig_cmd(tAVDT_SCB *p_scb, tAVDT_SCB_EVT *p_data)

if (!p_scb->in_use) {
p_cfg = p_data->msg.config_cmd.p_cfg;
if (p_scb->cs.cfg.codec_info[AVDT_CODEC_TYPE_INDEX] == p_cfg->codec_info[AVDT_CODEC_TYPE_INDEX]) {
/* set sep as in use */
p_scb->in_use = TRUE;

/* copy info to scb */
p_scb->p_ccb = avdt_ccb_by_idx(p_data->msg.config_cmd.hdr.ccb_idx);
p_scb->peer_seid = p_data->msg.config_cmd.int_seid;
memcpy(&p_scb->req_cfg, p_cfg, sizeof(tAVDT_CFG));
/* call app callback */
(*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), /* handle of scb- which is same as sep handle of bta_av_cb.p_scb*/
p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL,
AVDT_CONFIG_IND_EVT,
(tAVDT_CTRL *) &p_data->msg.config_cmd);
} else {
p_data->msg.hdr.err_code = AVDT_ERR_UNSUP_CFG;
p_data->msg.hdr.err_param = 0;
avdt_msg_send_rej(avdt_ccb_by_idx(p_data->msg.hdr.ccb_idx),
p_data->msg.hdr.sig_id, &p_data->msg);
}
/* set sep as in use */
p_scb->in_use = TRUE;

/* copy info to scb */
p_scb->p_ccb = avdt_ccb_by_idx(p_data->msg.config_cmd.hdr.ccb_idx);
p_scb->peer_seid = p_data->msg.config_cmd.int_seid;
memcpy(&p_scb->req_cfg, p_cfg, sizeof(tAVDT_CFG));
/* call app callback */
(*p_scb->cs.p_ctrl_cback)(avdt_scb_to_hdl(p_scb), /* handle of scb- which is same as sep handle of bta_av_cb.p_scb*/
p_scb->p_ccb ? p_scb->p_ccb->peer_addr : NULL,
AVDT_CONFIG_IND_EVT,
(tAVDT_CTRL *) &p_data->msg.config_cmd);
} else {
avdt_scb_rej_in_use(p_scb, p_data);
}
Expand Down

0 comments on commit 9bd1484

Please sign in to comment.