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

Commit 024d3e4b authored by Henri Chataing's avatar Henri Chataing Committed by Gerrit Code Review
Browse files

Merge changes I971e3765,Ib6dc5da8,I85027226,Iddb282d5 into main

* changes:
  Return correct error code in response to invalid AVDTP Set Configuration request
  pandora/mmi2grpc: Do not invoke WaitSource for A2DP/*/AVP/* tests
  bta_av_co: Modify BtaAvCo::SetCodecOtaConfig to return tA2DP_STATUS
  system/stack: Modify A2dpCodecConfig::setCodecConfig to return tA2DP_STATUS
parents 52166733 6e70b7e3
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -67,7 +67,13 @@ class A2DPProxy(ProfileProxy):
        the IUT connects to PTS to establish pairing.
        """

        if "SRC" in test:
        if "A2DP/SRC/AVP" in test or "A2DP/SNK/AVP" in test:
            # WaitSource is blocking and cannot be invoked in these tests
            # because Android will initiate the AVDTP connection after a
            # timeout if the remote device is inactive.
            self.connection = self.host.WaitConnection(address=pts_addr).connection

        elif "SRC" in test:
            self.connection = self.host.WaitConnection(address=pts_addr).connection
            try:
                if "INT" in test:
+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 =
+26 −31
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)) {
        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
@@ -1329,7 +1317,7 @@ BtaAvCoState* BtaAvCo::getStateFromPeer(const BtaAvCoPeer* p_peer) {
  }
}

bool BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer, const uint8_t* p_ota_codec_config,
tA2DP_STATUS BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer, const uint8_t* p_ota_codec_config,
                                        uint8_t num_protect, const uint8_t* p_protect_info,
                                        const uint8_t t_local_sep) {
  uint8_t result_codec_config[AVDT_CODEC_SIZE];
@@ -1339,6 +1327,11 @@ bool BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer, const uint8_t* p_ota_codec_

  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());
@@ -1347,15 +1340,17 @@ bool BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer, const uint8_t* p_ota_codec_
    // We have all the information we need from the peer, so we can
    // proceed with the OTA codec configuration.
    log::error("peer {} : cannot find peer SEP to configure", p_peer->addr);
    return false;
    return AVDTP_UNSUPPORTED_CONFIGURATION;
  }

  tA2DP_ENCODER_INIT_PEER_PARAMS peer_params;
  GetPeerEncoderParameters(p_peer->addr, &peer_params);
  if (!p_peer->GetCodecs()->setCodecOtaConfig(p_ota_codec_config, &peer_params, result_codec_config,
                                              &restart_input, &restart_output, &config_updated)) {
    log::error("peer {} : cannot set OTA config", p_peer->addr);
    return false;
  auto status = p_peer->GetCodecs()->setCodecOtaConfig(p_ota_codec_config, &peer_params,
                                                       result_codec_config, &restart_input,
                                                       &restart_output, &config_updated);
  if (status != A2DP_SUCCESS) {
    log::error("peer {} : cannot set OTA config, status: 0x{:x}", p_peer->addr, status);
    return status;
  }

  if (restart_output) {
@@ -1371,7 +1366,7 @@ bool BtaAvCo::SetCodecOtaConfig(BtaAvCoPeer* p_peer, const uint8_t* p_ota_codec_
    ReportSourceCodecState(p_peer);
  }

  return true;
  return A2DP_SUCCESS;
}

void bta_av_co_init(const std::vector<btav_a2dp_codec_config_t>& codec_priorities,
+3 −3
Original line number Diff line number Diff line
@@ -452,7 +452,7 @@ private:
   * @param t_local_sep the profile for which ota config needs to be set.
   * @return true on success, otherwise false
   */
  bool SetCodecOtaConfig(BtaAvCoPeer* p_peer, const uint8_t* p_ota_codec_config,
  tA2DP_STATUS SetCodecOtaConfig(BtaAvCoPeer* p_peer, const uint8_t* p_ota_codec_config,
                                 uint8_t num_protect, const uint8_t* p_protect_info,
                                 const uint8_t t_local_sep);

+9 −4
Original line number Diff line number Diff line
@@ -930,7 +930,8 @@ static bool select_audio_channel_mode(const btav_a2dp_codec_config_t* p_codec_au
  return false;
}

bool A2dpCodecConfigAacBase::setCodecConfig(const uint8_t* p_peer_codec_info, bool is_capability,
tA2DP_STATUS A2dpCodecConfigAacBase::setCodecConfig(const uint8_t* p_peer_codec_info,
                                                    bool is_capability,
                                                    uint8_t* p_result_codec_config) {
  std::lock_guard<std::recursive_mutex> lock(codec_mutex_);
  tA2DP_AAC_CIE peer_info_cie;
@@ -1094,6 +1095,7 @@ bool A2dpCodecConfigAacBase::setCodecConfig(const uint8_t* p_peer_codec_info, bo
            "cannot match sample frequency: source caps = 0x{:x} peer info = "
            "0x{:x}",
            p_a2dp_aac_caps->sampleRate, peer_info_cie.sampleRate);
    status = A2DP_NOT_SUPPORTED_SAMPLING_FREQUENCY;
    goto fail;
  }

@@ -1168,6 +1170,7 @@ bool A2dpCodecConfigAacBase::setCodecConfig(const uint8_t* p_peer_codec_info, bo
            "cannot match bits per sample: default = 0x{:x} user preference = "
            "0x{:x}",
            a2dp_aac_default_config.bits_per_sample, codec_user_config_.bits_per_sample);
    status = A2DP_NOT_SUPPORTED_BIT_RATE;
    goto fail;
  }

@@ -1239,6 +1242,7 @@ bool A2dpCodecConfigAacBase::setCodecConfig(const uint8_t* p_peer_codec_info, bo
  if (codec_config_.channel_mode == BTAV_A2DP_CODEC_CHANNEL_MODE_NONE) {
    log::error("cannot match channel mode: source caps = 0x{:x} peer info = 0x{:x}",
               p_a2dp_aac_caps->channelMode, peer_info_cie.channelMode);
    status = A2DP_NOT_SUPPORTED_CHANNEL_MODE;
    goto fail;
  }

@@ -1286,6 +1290,7 @@ bool A2dpCodecConfigAacBase::setCodecConfig(const uint8_t* p_peer_codec_info, bo
  }

  if (!A2DP_BuildInfoAac(AVDT_MEDIA_TYPE_AUDIO, &result_config_cie, p_result_codec_config)) {
    status = AVDTP_UNSUPPORTED_CONFIGURATION;
    goto fail;
  }

@@ -1302,7 +1307,7 @@ bool A2dpCodecConfigAacBase::setCodecConfig(const uint8_t* p_peer_codec_info, bo
  }
  log::assert_that(A2DP_BuildInfoAac(AVDT_MEDIA_TYPE_AUDIO, &result_config_cie, ota_codec_config_),
                   "Failed to build media codec capabilities");
  return true;
  return A2DP_SUCCESS;

fail:
  // Restore the internal state
@@ -1315,7 +1320,7 @@ fail:
  memcpy(ota_codec_peer_capability_, saved_ota_codec_peer_capability,
         sizeof(ota_codec_peer_capability_));
  memcpy(ota_codec_peer_config_, saved_ota_codec_peer_config, sizeof(ota_codec_peer_config_));
  return false;
  return status;
}

bool A2dpCodecConfigAacBase::setPeerCodecCapabilities(const uint8_t* p_peer_codec_capabilities) {
Loading