Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6e70b7e3 authored by Henri Chataing's avatar Henri Chataing
Browse files

Return correct error code in response to invalid AVDTP Set Configuration request

Blocking the certification of the Android Bluetooth stack for the PTS tests
A2DP/SRC/AVP/BI-*-C, A2DP/SNK/AVP/BI-*-C

Bug: 336232163
Bug: 338139069
Test: m com.android.btservices
Change-Id: I971e3765831bedd8eb3e59d6b42690497e257bd3
parent cf32f431
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@

#include <base/strings/stringprintf.h>
#include <bluetooth/log.h>
#include <com_android_bluetooth_flags.h>

#include <cstdint>
#include <cstring>
@@ -1737,11 +1738,22 @@ void bta_av_getcap_results(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
 ******************************************************************************/
void bta_av_setconfig_rej(tBTA_AV_SCB* p_scb, tBTA_AV_DATA* p_data) {
  uint8_t avdt_handle = p_data->ci_setconfig.avdt_handle;
  uint8_t err_code = p_data->ci_setconfig.err_code;

  bta_av_adjust_seps_idx(p_scb, avdt_handle);
  log::info("sep_idx={} avdt_handle={} bta_handle=0x{:x}", 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);

  log::info("sep_idx={} avdt_handle={} bta_handle=0x{:x} err_code=0x{:x}", p_scb->sep_idx,
            p_scb->avdt_handle, p_scb->hndl, err_code);

  if (!com::android::bluetooth::flags::avdtp_error_codes()) {
    err_code = AVDT_ERR_UNSUP_CFG;
  }

  // The error code must be set by the caller, otherwise
  // AVDT_ConfigRsp will interpret the event as RSP instead of REJ.
  log::assert_that(err_code != 0, "err_code != 0");

  AVDT_ConfigRsp(p_scb->avdt_handle, p_scb->avdt_label, err_code, 0);

  tBTA_AV bta_av_data = {
      .reject =
+15 −22
Original line number Diff line number Diff line
@@ -475,40 +475,28 @@ void BtaAvCo::ProcessSetConfig(tBTA_AV_HNDL bta_av_handle, const RawAddress& pee
  }

  if (status == A2DP_SUCCESS) {
    bool codec_config_supported = false;
    category = AVDT_ASC_CODEC;

    if (t_local_sep == AVDT_TSEP_SNK) {
      log::verbose("peer {} is A2DP Source", p_peer->addr);
      codec_config_supported = A2DP_IsSinkCodecSupported(p_codec_info);
      if (codec_config_supported) {
      status = A2DP_IsSinkCodecSupported(p_codec_info) ? A2DP_SUCCESS : A2DP_INVALID_CODEC_TYPE;

      if (status == A2DP_SUCCESS) {
        // If Peer is Source, and our config subset matches with what is
        // requested by peer, then just accept what peer wants.
        SaveNewCodecConfig(p_peer, p_codec_info, num_protect, p_protect_info, t_local_sep);
      }
    }
    if (t_local_sep == AVDT_TSEP_SRC) {
    } else if (t_local_sep == AVDT_TSEP_SRC) {
      log::verbose("peer {} is A2DP SINK", p_peer->addr);
      if ((p_peer->GetCodecs() == nullptr) ||
          SetCodecOtaConfig(p_peer, p_codec_info, num_protect, p_protect_info, t_local_sep) !=
                  A2DP_SUCCESS) {
        log::error("cannot set source codec {} for peer {}", A2DP_CodecName(p_codec_info),
                   p_peer->addr);
      } else {
        codec_config_supported = true;
      status = SetCodecOtaConfig(p_peer, p_codec_info, num_protect, p_protect_info, t_local_sep);

      // Check if reconfiguration is needed
        if ((num_protect == 1) && !p_peer->ContentProtectActive()) {
      if (status == A2DP_SUCCESS && num_protect == 1 && !p_peer->ContentProtectActive()) {
        reconfig_needed = true;
      }
    }
  }

    // Check if codec configuration is supported
    if (!codec_config_supported) {
      category = AVDT_ASC_CODEC;
      status = AVDTP_UNSUPPORTED_CONFIGURATION;
    }
  }

  if (status != A2DP_SUCCESS) {
    log::verbose("peer {} reject s={} c={}", p_peer->addr, status, category);
    // Call call-in rejecting the configuration
@@ -1339,6 +1327,11 @@ tA2DP_STATUS BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer, const uint8_t* p_ot

  log::info("peer_address={}, codec: {}", p_peer->addr, A2DP_CodecInfoString(p_ota_codec_config));

  if (p_peer->GetCodecs() == nullptr) {
    log::error("peer codecs are not yet initialized");
    return AVDTP_UNSUPPORTED_CONFIGURATION;
  }

  // Find the peer SEP codec to use
  const BtaAvCoSep* p_sink = peer_cache_->FindPeerSink(
          p_peer, A2DP_SourceCodecIndex(p_ota_codec_config), ContentProtectFlag());