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

Commit 11f306f2 authored by Henri Chataing's avatar Henri Chataing
Browse files

system/stack/avdt: Migrate to libbluetooth_log

Test: m com.android.btservices
Bug: 305066880
Flag: EXEMPT, mechanical refactor
Change-Id: I14481077b8c5a9bb6976e1ce0299e58a8bf0b21d
parent 8b1e0777
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1088,6 +1088,7 @@ cc_test {
        "libcutils",
    ],
    static_libs: [
        "libbase",
        "libbluetooth-types",
        "libbluetooth_crypto_toolbox",
        "libbluetooth_gd",
+33 −34
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
 *
 ******************************************************************************/

#include <base/logging.h>
#include <bluetooth/log.h>
#include <string.h>

#include "avdt_api.h"
@@ -35,21 +35,21 @@
#include "stack/include/bt_hdr.h"
#include "stack/include/btm_sec_api_types.h"

using namespace bluetooth;

AvdtpScb* AvdtpAdaptationLayer::LookupAvdtpScb(
    const AvdtpTransportChannel& tc) {
  if (tc.ccb_idx >= AVDT_NUM_LINKS) {
    LOG_ERROR("%s: AvdtpScb entry not found: invalid ccb_idx:%d", __func__,
              tc.ccb_idx);
    log::error("AvdtpScb entry not found: invalid ccb_idx:{}", tc.ccb_idx);
    return nullptr;
  }
  if (tc.tcid >= AVDT_NUM_RT_TBL) {
    LOG_ERROR("%s: AvdtpScb entry not found: invalid tcid:%d", __func__,
              tc.tcid);
    log::error("AvdtpScb entry not found: invalid tcid:{}", tc.tcid);
    return nullptr;
  }
  const AvdtpRoutingEntry& re = rt_tbl[tc.ccb_idx][tc.tcid];
  LOG_VERBOSE("%s: ccb_idx:%d tcid:%d scb_hdl:%d", __func__, tc.ccb_idx,
              tc.tcid, re.scb_hdl);
  log::verbose("ccb_idx:{} tcid:{} scb_hdl:{}", tc.ccb_idx, tc.tcid,
               re.scb_hdl);
  return avdt_scb_by_hdl(re.scb_hdl);
}

@@ -74,7 +74,7 @@ uint8_t avdt_ad_type_to_tcid(uint8_t type, AvdtpScb* p_scb) {
  // There are AVDT_CHAN_NUM_TYPES channel types per SEP. Here we compute
  // the type index (TCID) from the SEP index and the type itself.
  uint8_t tcid = (scb_idx * (AVDT_CHAN_NUM_TYPES - 1)) + type;
  LOG_VERBOSE("%s: type:%d, tcid: %d", __func__, type, tcid);
  log::verbose("type:{}, tcid: {}", type, tcid);
  return tcid;
}

@@ -101,7 +101,7 @@ static uint8_t avdt_ad_tcid_to_type(uint8_t tcid) {
    */
    type = ((tcid + AVDT_CHAN_NUM_TYPES - 2) % (AVDT_CHAN_NUM_TYPES - 1)) + 1;
  }
  LOG_VERBOSE("tcid: %d, type: %d", tcid, type);
  log::verbose("tcid: {}, type: {}", tcid, type);
  return type;
}

@@ -275,7 +275,7 @@ AvdtpTransportChannel* avdt_ad_tc_tbl_alloc(AvdtpCcb* p_ccb) {
 *
 ******************************************************************************/
uint8_t avdt_ad_tc_tbl_to_idx(AvdtpTransportChannel* p_tbl) {
  LOG_VERBOSE("avdt_ad_tc_tbl_to_idx: %ld", (long)(p_tbl - avdtp_cb.ad.tc_tbl));
  log::verbose("avdt_ad_tc_tbl_to_idx: {}", (long)(p_tbl - avdtp_cb.ad.tc_tbl));
  /* use array arithmetic to determine index */
  return (uint8_t)(p_tbl - avdtp_cb.ad.tc_tbl);
}
@@ -305,8 +305,7 @@ void avdt_ad_tc_close_ind(AvdtpTransportChannel* p_tbl) {
  p_tbl->cfg_flags = 0;
  p_tbl->peer_mtu = L2CAP_DEFAULT_MTU;

  LOG_VERBOSE("%s: tcid: %d, old: %d", __func__, p_tbl->tcid,
              close.old_tc_state);
  log::verbose("tcid: {}, old: {}", p_tbl->tcid, close.old_tc_state);
  /* if signaling channel, notify ccb that channel open */
  if (p_tbl->tcid == 0) {
    p_ccb = avdt_ccb_by_idx(p_tbl->ccb_idx);
@@ -317,8 +316,8 @@ void avdt_ad_tc_close_ind(AvdtpTransportChannel* p_tbl) {
  /* look up scb in stream routing table by ccb, tcid */
  p_scb = avdtp_cb.ad.LookupAvdtpScb(*p_tbl);
  if (p_scb == nullptr) {
    LOG_ERROR("%s: Cannot find AvdtScb entry: ccb_idx:%d tcid:%d", __func__,
              p_tbl->ccb_idx, p_tbl->tcid);
    log::error("Cannot find AvdtScb entry: ccb_idx:{} tcid:{}", p_tbl->ccb_idx,
               p_tbl->tcid);
    return;
  }
  close.tcid = p_tbl->tcid;
@@ -346,8 +345,8 @@ void avdt_ad_tc_open_ind(AvdtpTransportChannel* p_tbl) {
  tAVDT_OPEN open;
  tAVDT_EVT_HDR evt;

  LOG_VERBOSE("%s: p_tbl:%p state:%d ccb_idx:%d tcid:%d scb_hdl:%d", __func__,
              p_tbl, p_tbl->state, p_tbl->ccb_idx, p_tbl->tcid,
  log::verbose("p_tbl:{} state:{} ccb_idx:{} tcid:{} scb_hdl:{}",
               fmt::ptr(p_tbl), p_tbl->state, p_tbl->ccb_idx, p_tbl->tcid,
               avdtp_cb.ad.rt_tbl[p_tbl->ccb_idx][p_tbl->tcid].scb_hdl);

  p_tbl->state = AVDT_AD_ST_OPEN;
@@ -374,8 +373,8 @@ void avdt_ad_tc_open_ind(AvdtpTransportChannel* p_tbl) {
  /* look up scb in stream routing table by ccb, tcid */
  p_scb = avdtp_cb.ad.LookupAvdtpScb(*p_tbl);
  if (p_scb == nullptr) {
    LOG_ERROR("%s: Cannot find AvdtScb entry: ccb_idx:%d tcid:%d", __func__,
              p_tbl->ccb_idx, p_tbl->tcid);
    log::error("Cannot find AvdtScb entry: ccb_idx:{} tcid:{}", p_tbl->ccb_idx,
               p_tbl->tcid);
    return;
  }
  /* put lcid in event data */
@@ -417,8 +416,8 @@ void avdt_ad_tc_cong_ind(AvdtpTransportChannel* p_tbl, bool is_congested) {
  /* look up scb in stream routing table by ccb, tcid */
  p_scb = avdtp_cb.ad.LookupAvdtpScb(*p_tbl);
  if (p_scb == nullptr) {
    LOG_ERROR("%s: Cannot find AvdtScb entry: ccb_idx:%d tcid:%d", __func__,
              p_tbl->ccb_idx, p_tbl->tcid);
    log::error("Cannot find AvdtScb entry: ccb_idx:{} tcid:{}", p_tbl->ccb_idx,
               p_tbl->tcid);
    return;
  }
  tAVDT_SCB_EVT avdt_scb_evt;
@@ -454,10 +453,10 @@ void avdt_ad_tc_data_ind(AvdtpTransportChannel* p_tbl, BT_HDR* p_buf) {
  /* if media or other channel, send event to scb */
  p_scb = avdtp_cb.ad.LookupAvdtpScb(*p_tbl);
  if (p_scb == nullptr) {
    LOG_ERROR("%s: Cannot find AvdtScb entry: ccb_idx:%d tcid:%d", __func__,
              p_tbl->ccb_idx, p_tbl->tcid);
    log::error("Cannot find AvdtScb entry: ccb_idx:{} tcid:{}", p_tbl->ccb_idx,
               p_tbl->tcid);
    osi_free(p_buf);
    LOG_ERROR("%s: buffer freed", __func__);
    log::error("buffer freed");
    return;
  }
  avdt_scb_event(p_scb, AVDT_SCB_TC_DATA_EVT, (tAVDT_SCB_EVT*)&p_buf);
@@ -513,12 +512,12 @@ void avdt_ad_open_req(uint8_t type, AvdtpCcb* p_ccb, AvdtpScb* p_scb,

  p_tbl = avdt_ad_tc_tbl_alloc(p_ccb);
  if (p_tbl == NULL) {
    LOG_ERROR("avdt_ad_open_req: Cannot allocate p_tbl");
    log::error("avdt_ad_open_req: Cannot allocate p_tbl");
    return;
  }

  p_tbl->tcid = avdt_ad_type_to_tcid(type, p_scb);
  LOG_VERBOSE("avdt_ad_open_req: type: %d, role: %d, tcid:%d", type, role,
  log::verbose("avdt_ad_open_req: type: {}, role: {}, tcid:{}", type, role,
               p_tbl->tcid);

  if (type == AVDT_CHAN_SIG) {
@@ -531,7 +530,7 @@ void avdt_ad_open_req(uint8_t type, AvdtpCcb* p_ccb, AvdtpScb* p_scb,
    /* also set scb_hdl in rt_tbl */
    avdtp_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].scb_hdl =
        avdt_scb_to_hdl(p_scb);
    LOG_VERBOSE("avdtp_cb.ad.rt_tbl[%d][%d].scb_hdl = %d",
    log::verbose("avdtp_cb.ad.rt_tbl[{}][{}].scb_hdl = {}",
                 avdt_ccb_to_idx(p_ccb), p_tbl->tcid, avdt_scb_to_hdl(p_scb));
  }

@@ -549,11 +548,11 @@ void avdt_ad_open_req(uint8_t type, AvdtpCcb* p_ccb, AvdtpScb* p_scb,
    if (lcid != 0) {
      /* if connect req ok, store tcid in lcid table  */
      avdtp_cb.ad.lcid_tbl[lcid] = avdt_ad_tc_tbl_to_idx(p_tbl);
      LOG_VERBOSE("avdtp_cb.ad.lcid_tbl[%d] = %d", (lcid),
      log::verbose("avdtp_cb.ad.lcid_tbl[{}] = {}", (lcid),
                   avdt_ad_tc_tbl_to_idx(p_tbl));

      avdtp_cb.ad.rt_tbl[avdt_ccb_to_idx(p_ccb)][p_tbl->tcid].lcid = lcid;
      LOG_VERBOSE("avdtp_cb.ad.rt_tbl[%d][%d].lcid = 0x%x",
      log::verbose("avdtp_cb.ad.rt_tbl[{}][{}].lcid = 0x{:x}",
                   avdt_ccb_to_idx(p_ccb), p_tbl->tcid, lcid);
    } else {
      /* if connect req failed, call avdt_ad_tc_close_ind() */
@@ -579,7 +578,7 @@ void avdt_ad_close_req(uint8_t type, AvdtpCcb* p_ccb, AvdtpScb* p_scb) {
  AvdtpTransportChannel* p_tbl;

  p_tbl = avdt_ad_tc_tbl_by_type(type, p_ccb, p_scb);
  LOG_VERBOSE("avdt_ad_close_req state: %d", p_tbl->state);
  log::verbose("avdt_ad_close_req state: {}", p_tbl->state);

  switch (p_tbl->state) {
    case AVDT_AD_ST_UNUSED:
+63 −65
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@

#include "avdt_api.h"

#include <bluetooth/log.h>
#include <string.h>

#include "avdt_int.h"
@@ -37,6 +38,8 @@
#include "stack/include/bt_hdr.h"
#include "types/raw_address.h"

using namespace bluetooth;

/* Control block for AVDTP */
AvdtpCb avdtp_cb;

@@ -126,14 +129,13 @@ void AVDT_Deregister(void) {
}

void AVDT_AbortReq(uint8_t handle) {
  LOG_WARN("%s: avdt_handle=%d", __func__, handle);
  log::warn("avdt_handle={}", handle);

  AvdtpScb* p_scb = avdt_scb_by_hdl(handle);
  if (p_scb != NULL) {
    avdt_scb_event(p_scb, AVDT_SCB_API_ABORT_REQ_EVT, NULL);
  } else {
    LOG_ERROR("%s Improper avdp_handle=%d, can not abort the stream", __func__,
              handle);
    log::error("Improper avdp_handle={}, can not abort the stream", handle);
  }
}

@@ -160,7 +162,8 @@ uint16_t AVDT_CreateStream(uint8_t peer_id, uint8_t* p_handle,
  if (((avdtp_stream_config.cfg.psc_mask & (~AVDT_PSC)) != 0) ||
      (avdtp_stream_config.p_avdt_ctrl_cback == NULL)) {
    result = AVDT_BAD_PARAMS;
    LOG_ERROR("Invalid AVDT stream endpoint parameters peer_id=%d scb_index=%d",
    log::error(
        "Invalid AVDT stream endpoint parameters peer_id={} scb_index={}",
        peer_id, avdtp_stream_config.scb_index);
  }

@@ -168,12 +171,13 @@ uint16_t AVDT_CreateStream(uint8_t peer_id, uint8_t* p_handle,
  else {
    p_scb = avdt_scb_alloc(peer_id, avdtp_stream_config);
    if (p_scb == NULL) {
      LOG_ERROR("Unable to create AVDT stream endpoint peer_id=%d scb_index=%d",
      log::error(
          "Unable to create AVDT stream endpoint peer_id={} scb_index={}",
          peer_id, avdtp_stream_config.scb_index);
      result = AVDT_NO_RESOURCES;
    } else {
      *p_handle = avdt_scb_to_hdl(p_scb);
      LOG_DEBUG("Created stream endpoint peer_id=%d handle=%hhu", peer_id,
      log::debug("Created stream endpoint peer_id={} handle={}", peer_id,
                 *p_handle);
    }
  }
@@ -198,7 +202,7 @@ uint16_t AVDT_RemoveStream(uint8_t handle) {
  uint16_t result = AVDT_SUCCESS;
  AvdtpScb* p_scb;

  LOG_VERBOSE("%s: avdt_handle=%d", __func__, handle);
  log::verbose("avdt_handle={}", handle);

  /* look up scb */
  p_scb = avdt_scb_by_hdl(handle);
@@ -210,7 +214,7 @@ uint16_t AVDT_RemoveStream(uint8_t handle) {
  }

  if (result != AVDT_SUCCESS) {
    LOG_ERROR("%s: result=%d avdt_handle=%d", __func__, result, handle);
    log::error("result={} avdt_handle={}", result, handle);
  }

  return result;
@@ -249,7 +253,7 @@ uint16_t AVDT_DiscoverReq(const RawAddress& bd_addr, uint8_t channel_index,
  uint16_t result = AVDT_SUCCESS;
  tAVDT_CCB_EVT evt;

  LOG_VERBOSE("%s", __func__);
  log::verbose("");

  /* find channel control block for this bd addr; if none, allocate one */
  p_ccb = avdt_ccb_by_bd(bd_addr);
@@ -276,7 +280,7 @@ uint16_t AVDT_DiscoverReq(const RawAddress& bd_addr, uint8_t channel_index,
  }

  if (result != AVDT_SUCCESS) {
    LOG_ERROR("%s: result=%d address=%s", __func__, result,
    log::error("result={} address={}", result,
               ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
  }
  return result;
@@ -297,12 +301,12 @@ static uint16_t avdt_get_cap_req(const RawAddress& bd_addr,
  AvdtpCcb* p_ccb = NULL;
  uint16_t result = AVDT_SUCCESS;

  LOG_VERBOSE("%s", __func__);
  log::verbose("");

  /* verify SEID */
  if ((p_evt->single.seid < AVDT_SEID_MIN) ||
      (p_evt->single.seid > AVDT_SEID_MAX)) {
    LOG_ERROR("seid: %d", p_evt->single.seid);
    log::error("seid: {}", p_evt->single.seid);
    result = AVDT_BAD_PARAMS;
  }
  /* find channel control block for this bd addr; if none, allocate one */
@@ -329,7 +333,7 @@ static uint16_t avdt_get_cap_req(const RawAddress& bd_addr,
  }

  if (result != AVDT_SUCCESS) {
    LOG_ERROR("%s: result=%d address=%s", __func__, result,
    log::error("result={} address={}", result,
               ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
  }
  return result;
@@ -365,7 +369,7 @@ uint16_t AVDT_GetCapReq(const RawAddress& bd_addr, uint8_t channel_index,
  tAVDT_CCB_API_GETCAP getcap;
  uint16_t result = AVDT_SUCCESS;

  LOG_VERBOSE("%s", __func__);
  log::verbose("");

  getcap.single.seid = seid;
  if (get_all_cap) {
@@ -378,7 +382,7 @@ uint16_t AVDT_GetCapReq(const RawAddress& bd_addr, uint8_t channel_index,
  result = avdt_get_cap_req(bd_addr, channel_index, &getcap);

  if (result != AVDT_SUCCESS) {
    LOG_ERROR("%s: result=%d address=%s", __func__, result,
    log::error("result={} address={}", result,
               ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
  }
  return result;
@@ -400,8 +404,7 @@ uint16_t AVDT_DelayReport(uint8_t handle, uint8_t seid, uint16_t delay) {
  uint16_t result = AVDT_SUCCESS;
  tAVDT_SCB_EVT evt;

  LOG_VERBOSE("%s: avdt_handle=%d seid=%d delay=%d", __func__, handle, seid,
              delay);
  log::verbose("avdt_handle={} seid={} delay={}", handle, seid, delay);

  /* map handle to scb */
  p_scb = avdt_scb_by_hdl(handle);
@@ -416,8 +419,7 @@ uint16_t AVDT_DelayReport(uint8_t handle, uint8_t seid, uint16_t delay) {
  }

  if (result != AVDT_SUCCESS) {
    LOG_ERROR("%s: result=%d avdt_handle=%d seid=%d", __func__, result, handle,
              seid);
    log::error("result={} avdt_handle={} seid={}", result, handle, seid);
  }
  return result;
}
@@ -444,7 +446,7 @@ uint16_t AVDT_OpenReq(uint8_t handle, const RawAddress& bd_addr,
  uint16_t result = AVDT_SUCCESS;
  tAVDT_SCB_EVT evt;

  LOG_VERBOSE("%s: address=%s avdt_handle=%d seid=%d", __func__,
  log::verbose("address={} avdt_handle={} seid={}",
               ADDRESS_TO_LOGGABLE_CSTR(bd_addr), handle, seid);

  /* verify SEID */
@@ -472,8 +474,7 @@ uint16_t AVDT_OpenReq(uint8_t handle, const RawAddress& bd_addr,

  /* send event to scb */
  if (result == AVDT_SUCCESS) {
    LOG_VERBOSE("%s: codec: %s", __func__,
                A2DP_CodecInfoString(p_cfg->codec_info).c_str());
    log::verbose("codec: {}", A2DP_CodecInfoString(p_cfg->codec_info).c_str());

    evt.msg.config_cmd.hdr.seid = seid;
    evt.msg.config_cmd.hdr.ccb_idx = avdt_ccb_to_idx(p_ccb);
@@ -481,7 +482,7 @@ uint16_t AVDT_OpenReq(uint8_t handle, const RawAddress& bd_addr,
    evt.msg.config_cmd.p_cfg = p_cfg;
    avdt_scb_event(p_scb, AVDT_SCB_API_SETCONFIG_REQ_EVT, &evt);
  } else {
    LOG_ERROR("%s: result=%d address=%s avdt_handle=%d", __func__, result,
    log::error("result={} address={} avdt_handle={}", result,
               ADDRESS_TO_LOGGABLE_CSTR(bd_addr), handle);
  }

@@ -507,8 +508,8 @@ uint16_t AVDT_ConfigRsp(uint8_t handle, uint8_t label, uint8_t error_code,
  uint16_t result = AVDT_SUCCESS;
  uint8_t event_code;

  LOG_VERBOSE("%s: avdt_handle=%d label=%d error_code=0x%x category=%d",
              __func__, handle, label, error_code, category);
  log::verbose("avdt_handle={} label={} error_code=0x{:x} category={}", handle,
               label, error_code, category);

  /* map handle to scb */
  p_scb = avdt_scb_by_hdl(handle);
@@ -535,7 +536,7 @@ uint16_t AVDT_ConfigRsp(uint8_t handle, uint8_t label, uint8_t error_code,
  }

  if (result != AVDT_SUCCESS) {
    LOG_ERROR("%s: result=%d avdt_handle=%d", __func__, result, handle);
    log::error("result={} avdt_handle={}", result, handle);
  }
  return result;
}
@@ -561,7 +562,7 @@ uint16_t AVDT_StartReq(uint8_t* p_handles, uint8_t num_handles) {
  uint16_t result = AVDT_SUCCESS;
  int i;

  LOG_VERBOSE("%s: num_handles=%d", __func__, num_handles);
  log::verbose("num_handles={}", num_handles);

  if ((num_handles == 0) || (num_handles > AVDT_NUM_SEPS)) {
    result = AVDT_BAD_PARAMS;
@@ -589,10 +590,9 @@ uint16_t AVDT_StartReq(uint8_t* p_handles, uint8_t num_handles) {

  if (result != AVDT_SUCCESS) {
    if ((num_handles == 0) || (num_handles > AVDT_NUM_SEPS)) {
      LOG_ERROR("%s: result=%d num_handles=%d invalid", __func__, result,
                num_handles);
      log::error("result={} num_handles={} invalid", result, num_handles);
    } else {
      LOG_ERROR("%s: result=%d avdt_handle=%d", __func__, result,
      log::error("result={} avdt_handle={}", result,
                 (i < num_handles ? p_handles[i] : p_handles[num_handles - 1]));
    }
  }
@@ -620,7 +620,7 @@ uint16_t AVDT_SuspendReq(uint8_t* p_handles, uint8_t num_handles) {
  uint16_t result = AVDT_SUCCESS;
  int i;

  LOG_VERBOSE("%s: num_handles=%d", __func__, num_handles);
  log::verbose("num_handles={}", num_handles);

  if ((num_handles == 0) || (num_handles > AVDT_NUM_SEPS)) {
    result = AVDT_BAD_PARAMS;
@@ -648,10 +648,9 @@ uint16_t AVDT_SuspendReq(uint8_t* p_handles, uint8_t num_handles) {

  if (result != AVDT_SUCCESS) {
    if ((num_handles == 0) || (num_handles > AVDT_NUM_SEPS)) {
      LOG_ERROR("%s: result=%d num_handles=%d invalid", __func__, result,
                num_handles);
      log::error("result={} num_handles={} invalid", result, num_handles);
    } else {
      LOG_ERROR("%s: result=%d avdt_handle=%d", __func__, result,
      log::error("result={} avdt_handle={}", result,
                 (i < num_handles ? p_handles[i] : p_handles[num_handles - 1]));
    }
  }
@@ -676,7 +675,7 @@ uint16_t AVDT_CloseReq(uint8_t handle) {
  AvdtpScb* p_scb;
  uint16_t result = AVDT_SUCCESS;

  LOG_VERBOSE("%s: avdt_handle=%d", __func__, handle);
  log::verbose("avdt_handle={}", handle);

  /* map handle to scb */
  p_scb = avdt_scb_by_hdl(handle);
@@ -689,7 +688,7 @@ uint16_t AVDT_CloseReq(uint8_t handle) {
  }

  if (result != AVDT_SUCCESS) {
    LOG_ERROR("%s: result=%d avdt_handle=%d", __func__, result, handle);
    log::error("result={} avdt_handle={}", result, handle);
  }
  return result;
}
@@ -716,7 +715,7 @@ uint16_t AVDT_ReconfigReq(uint8_t handle, AvdtpSepConfig* p_cfg) {
  uint16_t result = AVDT_SUCCESS;
  tAVDT_SCB_EVT evt;

  LOG_VERBOSE("%s: avdt_handle=%d", __func__, handle);
  log::verbose("avdt_handle={}", handle);

  /* map handle to scb */
  p_scb = avdt_scb_by_hdl(handle);
@@ -732,7 +731,7 @@ uint16_t AVDT_ReconfigReq(uint8_t handle, AvdtpSepConfig* p_cfg) {
  }

  if (result != AVDT_SUCCESS) {
    LOG_ERROR("%s: result=%d avdt_handle=%d", __func__, result, handle);
    log::error("result={} avdt_handle={}", result, handle);
  }
  return result;
}
@@ -756,7 +755,7 @@ uint16_t AVDT_SecurityReq(uint8_t handle, uint8_t* p_data, uint16_t len) {
  uint16_t result = AVDT_SUCCESS;
  tAVDT_SCB_EVT evt;

  LOG_VERBOSE("%s: avdt_handle=%d len=%d", __func__, handle, len);
  log::verbose("avdt_handle={} len={}", handle, len);

  /* map handle to scb */
  p_scb = avdt_scb_by_hdl(handle);
@@ -771,7 +770,7 @@ uint16_t AVDT_SecurityReq(uint8_t handle, uint8_t* p_data, uint16_t len) {
  }

  if (result != AVDT_SUCCESS) {
    LOG_ERROR("%s: result=%d avdt_handle=%d", __func__, result, handle);
    log::error("result={} avdt_handle={}", result, handle);
  }
  return result;
}
@@ -796,8 +795,8 @@ uint16_t AVDT_SecurityRsp(uint8_t handle, uint8_t label, uint8_t error_code,
  uint16_t result = AVDT_SUCCESS;
  tAVDT_SCB_EVT evt;

  LOG_VERBOSE("%s: avdt_handle=%d label=%d error_code=0x%x len=%d", __func__,
              handle, label, error_code, len);
  log::verbose("avdt_handle={} label={} error_code=0x{:x} len={}", handle,
               label, error_code, len);

  /* map handle to scb */
  p_scb = avdt_scb_by_hdl(handle);
@@ -814,7 +813,7 @@ uint16_t AVDT_SecurityRsp(uint8_t handle, uint8_t label, uint8_t error_code,
  }

  if (result != AVDT_SUCCESS) {
    LOG_ERROR("%s: result=%d avdt_handle=%d", __func__, result, handle);
    log::error("result={} avdt_handle={}", result, handle);
  }
  return result;
}
@@ -862,8 +861,8 @@ uint16_t AVDT_WriteReqOpt(uint8_t handle, BT_HDR* p_pkt, uint32_t time_stamp,
  tAVDT_SCB_EVT evt;
  uint16_t result = AVDT_SUCCESS;

  LOG_VERBOSE("%s: avdt_handle=%d timestamp=%d m_pt=0x%x opt=0x%x", __func__,
              handle, time_stamp, m_pt, opt);
  log::verbose("avdt_handle={} timestamp={} m_pt=0x{:x} opt=0x{:x}", handle,
               time_stamp, m_pt, opt);

  /* map handle to scb */
  p_scb = avdt_scb_by_hdl(handle);
@@ -877,7 +876,7 @@ uint16_t AVDT_WriteReqOpt(uint8_t handle, BT_HDR* p_pkt, uint32_t time_stamp,
    avdt_scb_event(p_scb, AVDT_SCB_API_WRITE_REQ_EVT, &evt);
  }

  LOG_VERBOSE("%s: result=%d avdt_handle=%d", __func__, result, handle);
  log::verbose("result={} avdt_handle={}", result, handle);
  return result;
}

@@ -902,8 +901,8 @@ uint16_t AVDT_ConnectReq(const RawAddress& bd_addr, uint8_t channel_index,
  uint16_t result = AVDT_SUCCESS;
  tAVDT_CCB_EVT evt;

  LOG_WARN("%s: address=%s channel_index=%d", __func__,
           ADDRESS_TO_LOGGABLE_CSTR(bd_addr), channel_index);
  log::warn("address={} channel_index={}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
            channel_index);

  /* find channel control block for this bd addr; if none, allocate one */
  p_ccb = avdt_ccb_by_bd(bd_addr);
@@ -914,7 +913,7 @@ uint16_t AVDT_ConnectReq(const RawAddress& bd_addr, uint8_t channel_index,
      result = AVDT_NO_RESOURCES;
    }
  } else if (!p_ccb->ll_opened) {
    LOG_WARN("AVDT_ConnectReq: CCB LL is in the middle of opening");
    log::warn("AVDT_ConnectReq: CCB LL is in the middle of opening");

    /* ccb was already allocated for the incoming signalling. */
    result = AVDT_BUSY;
@@ -926,8 +925,7 @@ uint16_t AVDT_ConnectReq(const RawAddress& bd_addr, uint8_t channel_index,
    avdt_ccb_event(p_ccb, AVDT_CCB_API_CONNECT_REQ_EVT, &evt);
  }

  LOG_WARN("%s: address=%s result=%d", __func__,
           ADDRESS_TO_LOGGABLE_CSTR(bd_addr), result);
  log::warn("address={} result={}", ADDRESS_TO_LOGGABLE_CSTR(bd_addr), result);

  return result;
}
@@ -953,11 +951,11 @@ uint16_t AVDT_DisconnectReq(const RawAddress& bd_addr,
  /* find channel control block for this bd addr; if none, error */
  p_ccb = avdt_ccb_by_bd(bd_addr);
  if (p_ccb == NULL) {
    LOG_ERROR("Unable to find AVDT stream endpoint peer:%s",
    log::error("Unable to find AVDT stream endpoint peer:{}",
               ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    result = AVDT_BAD_PARAMS;
  } else {
    LOG_DEBUG("Sending disconnect request to ccb peer:%s",
    log::debug("Sending disconnect request to ccb peer:{}",
               ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    evt.disconnect.p_cback = p_cback;
    avdt_ccb_event(p_ccb, AVDT_CCB_API_DISCONNECT_REQ_EVT, &evt);
+23 −20
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
 *
 ******************************************************************************/

#include <base/logging.h>  // VLOG
#include <bluetooth/log.h>
#include <string.h>

#include "avdt_int.h"
@@ -31,6 +31,8 @@
#include "osi/include/osi.h"
#include "types/raw_address.h"

using namespace bluetooth;

/*****************************************************************************
 * state machine constants and types
 ****************************************************************************/
@@ -367,9 +369,9 @@ void avdt_ccb_event(AvdtpCcb* p_ccb, uint8_t event, tAVDT_CCB_EVT* p_data) {
  int i;

#if (AVDT_DEBUG == TRUE)
  LOG_VERBOSE("%s: CCB ccb=%d event=%s state=%s p_ccb=%p", __func__,
              avdt_ccb_to_idx(p_ccb), avdt_ccb_evt_str[event],
              avdt_ccb_st_str[p_ccb->state], p_ccb);
  log::verbose("CCB ccb={} event={} state={} p_ccb={}", avdt_ccb_to_idx(p_ccb),
               avdt_ccb_evt_str[event], avdt_ccb_st_str[p_ccb->state],
               fmt::ptr(p_ccb));
#endif

  /* look up the state table for the current state */
@@ -383,8 +385,8 @@ void avdt_ccb_event(AvdtpCcb* p_ccb, uint8_t event, tAVDT_CCB_EVT* p_data) {
  /* execute action functions */
  for (i = 0; i < AVDT_CCB_ACTIONS; i++) {
    action = state_table[event][i];
    LOG_VERBOSE("%s: event=%s state=%s action=%d", __func__,
                avdt_ccb_evt_str[event], avdt_ccb_st_str[p_ccb->state], action);
    log::verbose("event={} state={} action={}", avdt_ccb_evt_str[event],
                 avdt_ccb_st_str[p_ccb->state], action);
    if (action != AVDT_CCB_IGNORE) {
      (*avdtp_cb.p_ccb_act[action])(p_ccb, p_data);
    } else {
@@ -418,7 +420,7 @@ AvdtpCcb* avdt_ccb_by_bd(const RawAddress& bd_addr) {
    /* if no ccb found */
    p_ccb = NULL;

    VLOG(1) << "No ccb for addr " << bd_addr;
    log::verbose("No ccb for addr {}", ADDRESS_TO_LOGGABLE_STR(bd_addr));
  }
  return p_ccb;
}
@@ -439,13 +441,13 @@ AvdtpCcb* avdt_ccb_alloc(const RawAddress& bd_addr) {
  for (int i = 0; i < AVDT_NUM_LINKS; i++, p_ccb++) {
    if (!p_ccb->allocated) {
      p_ccb->Allocate(bd_addr);
      LOG_VERBOSE("%s: allocated (index %d) for peer %s", __func__, i,
      log::verbose("allocated (index {}) for peer {}", i,
                   ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
      return p_ccb;
    }
  }

  LOG_WARN("%s: out of AvdtpCcb entries", __func__);
  log::warn("out of AvdtpCcb entries");
  return nullptr;
}

@@ -453,19 +455,20 @@ AvdtpCcb* avdt_ccb_alloc_by_channel_index(const RawAddress& bd_addr,
                                          uint8_t channel_index) {
  // Allocate the entry for the specified channel index
  if (channel_index >= AVDT_NUM_LINKS) {
    LOG_ERROR("%s: peer %s invalid channel index %d (max %d)", __func__,
              ADDRESS_TO_LOGGABLE_CSTR(bd_addr), channel_index, AVDT_NUM_LINKS);
    log::error("peer {} invalid channel index {} (max {})",
               ADDRESS_TO_LOGGABLE_CSTR(bd_addr), channel_index,
               AVDT_NUM_LINKS);
    return nullptr;
  }
  AvdtpCcb* p_ccb = &avdtp_cb.ccb[channel_index];
  if (p_ccb->allocated) {
    LOG_ERROR("%s: peer %s channel index %d already allocated", __func__,
    log::error("peer {} channel index {} already allocated",
               ADDRESS_TO_LOGGABLE_CSTR(bd_addr), channel_index);
    return nullptr;
  }
  p_ccb->Allocate(bd_addr);
  LOG_VERBOSE("%s: allocated (index %d) peer=%s p_ccb=%p", __func__,
              channel_index, ADDRESS_TO_LOGGABLE_CSTR(p_ccb->peer_addr), p_ccb);
  log::verbose("allocated (index {}) peer={} p_ccb={}", channel_index,
               ADDRESS_TO_LOGGABLE_CSTR(p_ccb->peer_addr), fmt::ptr(p_ccb));
  return p_ccb;
}

@@ -491,9 +494,9 @@ void AvdtpCcb::Allocate(const RawAddress& peer_address) {
 *
 ******************************************************************************/
void avdt_ccb_dealloc(AvdtpCcb* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) {
  LOG_VERBOSE("%s: deallocated (index %d) peer=%s p_ccb=%p", __func__,
  log::verbose("deallocated (index {}) peer={} p_ccb={}",
               avdt_ccb_to_idx(p_ccb),
              ADDRESS_TO_LOGGABLE_CSTR(p_ccb->peer_addr), p_ccb);
               ADDRESS_TO_LOGGABLE_CSTR(p_ccb->peer_addr), fmt::ptr(p_ccb));
  p_ccb->ResetCcb();
}

@@ -530,7 +533,7 @@ AvdtpCcb* avdt_ccb_by_idx(uint8_t idx) {
    p_ccb = &avdtp_cb.ccb[idx];
  } else {
    p_ccb = NULL;
    LOG_WARN("No ccb for idx %d", idx);
    log::warn("No ccb for idx {}", idx);
  }
  return p_ccb;
}
+13 −11
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
 *
 ******************************************************************************/

#include <bluetooth/log.h>
#include <string.h>

#include "avdt_api.h"
@@ -34,6 +35,8 @@
#include "stack/include/bt_hdr.h"
#include "types/raw_address.h"

using namespace bluetooth;

/*******************************************************************************
 *
 * Function         avdt_ccb_clear_ccb
@@ -143,7 +146,7 @@ void avdt_ccb_hdl_discover_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data) {
  tAVDT_SEP_INFO sep_info[AVDT_NUM_SEPS];
  AvdtpScb* p_scb = &(p_ccb->scb[0]);

  LOG_VERBOSE("%s: p_ccb index=%d", __func__, avdt_ccb_to_idx(p_ccb));
  log::verbose("p_ccb index={}", avdt_ccb_to_idx(p_ccb));

  p_data->msg.discover_rsp.p_sep_info = sep_info;
  p_data->msg.discover_rsp.num_seps = 0;
@@ -491,7 +494,7 @@ void avdt_ccb_snd_start_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data) {
  tAVDT_MSG avdt_msg;
  uint8_t seid_list[AVDT_NUM_SEPS];

  LOG_VERBOSE("%s", __func__);
  log::verbose("");

  /* make copy of our seid list */
  memcpy(seid_list, p_data->msg.multi.seid_list, p_data->msg.multi.num_seps);
@@ -501,7 +504,7 @@ void avdt_ccb_snd_start_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data) {
      avdt_scb_verify(p_ccb, AVDT_VERIFY_OPEN, p_data->msg.multi.seid_list,
                      p_data->msg.multi.num_seps, &avdt_msg.hdr.err_code);
  if (avdt_msg.hdr.err_param == 0) {
    LOG_VERBOSE("%s: AVDT_SIG_START", __func__);
    log::verbose("AVDT_SIG_START");

    /* set peer seid list in messsage */
    avdt_scb_peer_seid_list(&p_data->msg.multi);
@@ -513,7 +516,7 @@ void avdt_ccb_snd_start_cmd(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data) {
    for (i = 0; i < p_data->msg.multi.num_seps; i++) {
      p_scb = avdt_scb_by_hdl(seid_list[i]);
      if (p_scb != NULL) {
        LOG_VERBOSE("%s: AVDT_SCB_MSG_START_REJ_EVT: i=%d", __func__, i);
        log::verbose("AVDT_SCB_MSG_START_REJ_EVT: i={}", i);
        tAVDT_SCB_EVT avdt_scb_evt;
        avdt_scb_evt.msg.hdr = avdt_msg.hdr;
        avdt_scb_event(p_scb, AVDT_SCB_MSG_START_REJ_EVT, &avdt_scb_evt);
@@ -958,7 +961,7 @@ void avdt_ccb_set_conn(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data) {
 ******************************************************************************/
void avdt_ccb_set_disconn(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data) {
  /*
  LOG_VERBOSE("avdt_ccb_set_disconn:conn:x%x, api:x%x",
  log::verbose("avdt_ccb_set_disconn:conn:x{:x}, api:x{:x}",
  p_ccb->p_conn_cback, p_data->disconnect.p_cback);
      */
  /* save callback */
@@ -998,8 +1001,7 @@ void avdt_ccb_ll_closed(AvdtpCcb* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) {
  tAVDT_CTRL_CBACK* p_cback;
  tAVDT_CTRL avdt_ctrl;

  LOG_VERBOSE("%s peer %s", __func__,
              ADDRESS_TO_LOGGABLE_CSTR(p_ccb->peer_addr));
  log::verbose("peer {}", ADDRESS_TO_LOGGABLE_CSTR(p_ccb->peer_addr));

  /* clear any pending commands */
  avdt_ccb_clear_cmds(p_ccb, NULL);
@@ -1034,9 +1036,9 @@ void avdt_ccb_ll_closed(AvdtpCcb* p_ccb, UNUSED_ATTR tAVDT_CCB_EVT* p_data) {
void avdt_ccb_ll_opened(AvdtpCcb* p_ccb, tAVDT_CCB_EVT* p_data) {
  tAVDT_CTRL avdt_ctrl;

  LOG_VERBOSE("%s peer %s BtaAvScbIndex=%d p_ccb=%p", __func__,
  log::verbose("peer {} BtaAvScbIndex={} p_ccb={}",
               ADDRESS_TO_LOGGABLE_CSTR(p_ccb->peer_addr),
              p_ccb->BtaAvScbIndex(), p_ccb);
               p_ccb->BtaAvScbIndex(), fmt::ptr(p_ccb));
  p_ccb->ll_opened = true;

  if (!p_ccb->p_conn_cback) p_ccb->p_conn_cback = avdtp_cb.p_conn_cback;
Loading