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

Commit 501001d0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes Ibc8a2e94,I04cb8753,Idf047b8d,Id55bb63f

* changes:
  RFCOMM: Use std map to store channel map
  AVDT: Use std map to store channel map
  Remove unused AVDT API
  Fix L2cap shim crash on shutdown
parents 20b4bb12 2fed4160
Loading
Loading
Loading
Loading
+22 −6
Original line number Diff line number Diff line
@@ -76,6 +76,8 @@ void remove_classic_cid_token_entry(uint16_t cid_token) {
  classic_cid_token_to_channel_map_.erase(cid_token);
}

void remove_classic_dynamic_channel_helper(uint16_t psm);

struct ClassicDynamicChannelHelper {
  ClassicDynamicChannelHelper(uint16_t psm, tL2CAP_APPL_INFO appl_info,
                              classic::DynamicChannelConfigurationOption config,
@@ -143,11 +145,13 @@ struct ClassicDynamicChannelHelper {
    for (const auto& device : channels_) {
      device.second->Close();
    }
    remove_classic_dynamic_channel_helper(psm_);
  }

  void on_channel_close(uint16_t cid_token,
                        bluetooth::hci::ErrorCode error_code) {
    channel_enqueue_buffer_[cid_token] = nullptr;
    channel_enqueue_buffer_.erase(cid_token);
    channels_[cid_token]->GetQueueUpEnd()->UnregisterDequeue();
    channels_.erase(cid_token);
    do_in_main_thread(FROM_HERE, base::Bind(appl_info_.pL2CA_DisconnectInd_Cb,
@@ -291,6 +295,13 @@ struct ClassicDynamicChannelHelper {
std::unordered_map<uint16_t, std::unique_ptr<ClassicDynamicChannelHelper>>
    classic_dynamic_channel_helper_map_;

void remove_classic_dynamic_channel_helper(uint16_t psm) {
  if (classic_dynamic_channel_helper_map_.count(psm) != 0 &&
      classic_dynamic_channel_helper_map_[psm]->channels_.empty()) {
    classic_dynamic_channel_helper_map_.erase(psm);
  }
}

// Helper: L2cap security enforcement shim

std::unordered_map<intptr_t,
@@ -722,9 +733,6 @@ void L2CA_Deregister(uint16_t psm) {
    return;
  }
  classic_dynamic_channel_helper_map_[psm]->Unregister();
  if (classic_dynamic_channel_helper_map_[psm]->channels_.empty()) {
    classic_dynamic_channel_helper_map_.erase(psm);
  }
}

/**
@@ -1233,6 +1241,8 @@ void remove_le_cid_token_entry(uint16_t cid_token) {
  le_cid_token_to_channel_map_.erase(cid_token);
}

void remove_le_dynamic_channel_helper(uint16_t psm);

struct LeDynamicChannelHelper {
  LeDynamicChannelHelper(uint16_t psm, tL2CAP_APPL_INFO appl_info,
                         le::DynamicChannelConfigurationOption config,
@@ -1311,11 +1321,13 @@ struct LeDynamicChannelHelper {
    for (const auto& device : channels_) {
      device.second->Close();
    }
    remove_le_dynamic_channel_helper(psm_);
  }

  void on_channel_close(uint16_t cid_token,
                        bluetooth::hci::ErrorCode error_code) {
    channel_enqueue_buffer_[cid_token] = nullptr;
    channel_enqueue_buffer_.erase(cid_token);
    channels_[cid_token]->GetQueueUpEnd()->UnregisterDequeue();
    channels_.erase(cid_token);
    do_in_main_thread(FROM_HERE, base::Bind(appl_info_.pL2CA_DisconnectInd_Cb,
@@ -1418,6 +1430,13 @@ struct LeDynamicChannelHelper {
std::unordered_map<uint16_t, std::unique_ptr<LeDynamicChannelHelper>>
    le_dynamic_channel_helper_map_;

void remove_le_dynamic_channel_helper(uint16_t psm) {
  if (le_dynamic_channel_helper_map_.count(psm) != 0 &&
      le_dynamic_channel_helper_map_[psm]->channels_.empty()) {
    le_dynamic_channel_helper_map_.erase(psm);
  }
}

std::unordered_set<uint16_t> assigned_dynamic_le_psm_;
uint16_t next_assigned_dynamic_le_psm_ = 0x80;
}  // namespace
@@ -1470,9 +1489,6 @@ void L2CA_DeregisterLECoc(uint16_t psm) {
    return;
  }
  le_dynamic_channel_helper_map_[psm]->Unregister();
  if (le_dynamic_channel_helper_map_[psm]->channels_.empty()) {
    le_dynamic_channel_helper_map_.erase(psm);
  }
}

uint16_t L2CA_ConnectLECocReq(uint16_t psm, const RawAddress& p_bd_addr,
+5 −10
Original line number Diff line number Diff line
@@ -193,14 +193,11 @@ AvdtpTransportChannel* avdt_ad_tc_tbl_by_st(uint8_t type, AvdtpCcb* p_ccb,
 *
 ******************************************************************************/
AvdtpTransportChannel* avdt_ad_tc_tbl_by_lcid(uint16_t lcid) {
  uint8_t idx;

  idx = avdtp_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID];

  if (idx < AVDT_NUM_TC_TBL) {
  if (avdtp_cb.ad.lcid_tbl.count(lcid) != 0) {
    uint8_t idx = avdtp_cb.ad.lcid_tbl[lcid];
    return &avdtp_cb.ad.tc_tbl[idx];
  } else {
    return NULL;
    return nullptr;
  }
}

@@ -553,10 +550,8 @@ void avdt_ad_open_req(uint8_t type, AvdtpCcb* p_ccb, AvdtpScb* p_scb,
        L2CA_ConnectReq2(AVDT_PSM, p_ccb->peer_addr, BTM_SEC_OUT_AUTHENTICATE);
    if (lcid != 0) {
      /* if connect req ok, store tcid in lcid table  */
      avdtp_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID] =
          avdt_ad_tc_tbl_to_idx(p_tbl);
      AVDT_TRACE_DEBUG("avdtp_cb.ad.lcid_tbl[%d] = %d",
                       (lcid - L2CAP_BASE_APPL_CID),
      avdtp_cb.ad.lcid_tbl[lcid] = avdt_ad_tc_tbl_to_idx(p_tbl);
      AVDT_TRACE_DEBUG("avdtp_cb.ad.lcid_tbl[%d] = %d", (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;
+0 −178
Original line number Diff line number Diff line
@@ -739,46 +739,6 @@ uint16_t AVDT_ReconfigReq(uint8_t handle, AvdtpSepConfig* p_cfg) {
  return result;
}

/*******************************************************************************
 *
 * Function         AVDT_ReconfigRsp
 *
 * Description      Respond to a reconfigure request from the peer device.
 *                  This function must be called if the application receives
 *                  an AVDT_RECONFIG_IND_EVT through its control callback.
 *
 *
 * Returns          AVDT_SUCCESS if successful, otherwise error.
 *
 ******************************************************************************/
uint16_t AVDT_ReconfigRsp(uint8_t handle, uint8_t label, uint8_t error_code,
                          uint8_t category) {
  AvdtpScb* p_scb;
  tAVDT_SCB_EVT evt;
  uint16_t result = AVDT_SUCCESS;

  AVDT_TRACE_DEBUG("%s: avdt_handle=%d label=%d error_code=0x%x category=%d",
                   __func__, handle, label, error_code, category);

  /* map handle to scb */
  p_scb = avdt_scb_by_hdl(handle);
  if (p_scb == NULL) {
    result = AVDT_BAD_HANDLE;
  }
  /* send event to scb */
  else {
    evt.msg.hdr.err_code = error_code;
    evt.msg.hdr.err_param = category;
    evt.msg.hdr.label = label;
    avdt_scb_event(p_scb, AVDT_SCB_API_RECONFIG_RSP_EVT, &evt);
  }

  if (result != AVDT_SUCCESS) {
    AVDT_TRACE_ERROR("%s: result=%d avdt_handle=%d", __func__, result, handle);
  }
  return result;
}

/*******************************************************************************
 *
 * Function         AVDT_SecurityReq
@@ -923,45 +883,6 @@ uint16_t AVDT_WriteReqOpt(uint8_t handle, BT_HDR* p_pkt, uint32_t time_stamp,
  return result;
}

/*******************************************************************************
 *
 * Function         AVDT_WriteReq
 *
 * Description      Send a media packet to the peer device.  The stream must
 *                  be started before this function is called.  Also, this
 *                  function can only be called if the stream is a SRC.
 *
 *                  When AVDTP has sent the media packet and is ready for the
 *                  next packet, an AVDT_WRITE_CFM_EVT is sent to the
 *                  application via the control callback.  The application must
 *                  wait for the AVDT_WRITE_CFM_EVT before it makes the next
 *                  call to AVDT_WriteReq().  If the applications calls
 *                  AVDT_WriteReq() before it receives the event the packet
 *                  will not be sent.  The application may make its first call
 *                  to AVDT_WriteReq() after it receives an AVDT_START_CFM_EVT
 *                  or AVDT_START_IND_EVT.
 *
 *                  The application passes the packet using the BT_HDR
 *                  structure.
 *                  This structure is described in section 2.1.  The offset
 *                  field must be equal to or greater than AVDT_MEDIA_OFFSET.
 *                  This allows enough space in the buffer for the L2CAP and
 *                  AVDTP headers.
 *
 *                  The memory pointed to by p_pkt must be a GKI buffer
 *                  allocated by the application.  This buffer will be freed
 *                  by the protocol stack; the application must not free
 *                  this buffer.
 *
 *
 * Returns          AVDT_SUCCESS if successful, otherwise error.
 *
 ******************************************************************************/
uint16_t AVDT_WriteReq(uint8_t handle, BT_HDR* p_pkt, uint32_t time_stamp,
                       uint8_t m_pt) {
  return AVDT_WriteReqOpt(handle, p_pkt, time_stamp, m_pt, AVDT_DATA_OPT_NONE);
}

/*******************************************************************************
 *
 * Function         AVDT_ConnectReq
@@ -1078,105 +999,6 @@ uint16_t AVDT_GetL2CapChannel(uint8_t handle) {
  return (lcid);
}

/*******************************************************************************
 *
 * Function         AVDT_SendReport
 *
 * Description
 *
 *
 *
 * Returns
 *
 ******************************************************************************/
uint16_t AVDT_SendReport(uint8_t handle, AVDT_REPORT_TYPE type,
                         tAVDT_REPORT_DATA* p_data) {
  AvdtpScb* p_scb;
  uint16_t result = AVDT_BAD_PARAMS;
  AvdtpTransportChannel* p_tbl;
  uint8_t *p, *plen, *pm1, *p_end;
  uint32_t ssrc;
  uint16_t len;

  AVDT_TRACE_DEBUG("%s: avdt_handle=%d type=%d", __func__, handle, type);

  /* map handle to scb && verify parameters */
  if (((p_scb = avdt_scb_by_hdl(handle)) != NULL) && (p_scb->p_ccb != NULL) &&
      (((type == AVDT_RTCP_PT_SR) &&
        (p_scb->stream_config.tsep == AVDT_TSEP_SRC)) ||
       ((type == AVDT_RTCP_PT_RR) &&
        (p_scb->stream_config.tsep == AVDT_TSEP_SNK)) ||
       (type == AVDT_RTCP_PT_SDES))) {
    result = AVDT_NO_RESOURCES;

    /* build SR - assume fit in one packet */
    p_tbl = avdt_ad_tc_tbl_by_type(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb);
    if (p_tbl->state == AVDT_AD_ST_OPEN) {
      BT_HDR* p_pkt = (BT_HDR*)osi_malloc(p_tbl->peer_mtu + sizeof(BT_HDR));

      p_pkt->offset = L2CAP_MIN_OFFSET;
      p = (uint8_t*)(p_pkt + 1) + p_pkt->offset;
      pm1 = p;
      *p++ = AVDT_MEDIA_OCTET1 | 1;
      *p++ = type;
      /* save the location for length */
      plen = p;
      p += 2;
      ssrc = avdt_scb_gen_ssrc(p_scb);
      UINT32_TO_BE_STREAM(p, ssrc);

      switch (type) {
        case AVDT_RTCP_PT_SR: /* Sender Report */
          *pm1 = AVDT_MEDIA_OCTET1;
          UINT32_TO_BE_STREAM(p, p_data->sr.ntp_sec);
          UINT32_TO_BE_STREAM(p, p_data->sr.ntp_frac);
          UINT32_TO_BE_STREAM(p, p_data->sr.rtp_time);
          UINT32_TO_BE_STREAM(p, p_data->sr.pkt_count);
          UINT32_TO_BE_STREAM(p, p_data->sr.octet_count);
          break;

        case AVDT_RTCP_PT_RR: /* Receiver Report */
          *p++ = p_data->rr.frag_lost;
          AVDT_TRACE_API("packet_lost: %d", p_data->rr.packet_lost);
          p_data->rr.packet_lost &= 0xFFFFFF;
          AVDT_TRACE_API("packet_lost: %d", p_data->rr.packet_lost);
          UINT24_TO_BE_STREAM(p, p_data->rr.packet_lost);
          UINT32_TO_BE_STREAM(p, p_data->rr.seq_num_rcvd);
          UINT32_TO_BE_STREAM(p, p_data->rr.jitter);
          UINT32_TO_BE_STREAM(p, p_data->rr.lsr);
          UINT32_TO_BE_STREAM(p, p_data->rr.dlsr);
          break;

        case AVDT_RTCP_PT_SDES: /* Source Description */
          *p++ = AVDT_RTCP_SDES_CNAME;
          len = strlen((char*)p_data->cname);
          if (len > AVDT_MAX_CNAME_SIZE) len = AVDT_MAX_CNAME_SIZE;
          *p++ = (uint8_t)len;
          strlcpy((char*)p, (char*)p_data->cname, len + 1);
          p += len;
          break;
      }
      p_end = p;
      len = p - pm1 - 1;
      UINT16_TO_BE_STREAM(plen, len);

      /* set the actual payload length */
      p_pkt->len = p_end - p;
      /* send the packet */
      if (L2CAP_DW_FAILED !=
          avdt_ad_write_req(AVDT_CHAN_REPORT, p_scb->p_ccb, p_scb, p_pkt))
        result = AVDT_SUCCESS;
    }
  }

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

  return result;
}

/******************************************************************************
 *
 * Function         AVDT_SetTraceLevel
+6 −3
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@
#ifndef AVDT_INT_H
#define AVDT_INT_H

#include <unordered_map>

#include "avdt_api.h"
#include "avdt_defs.h"
#include "avdtc_api.h"
@@ -686,7 +688,7 @@ class AvdtpRoutingEntry {
 */
class AvdtpAdaptationLayer {
 public:
  AvdtpAdaptationLayer() : lcid_tbl{} {}
  AvdtpAdaptationLayer() {}

  void Reset() {
    for (size_t i = 0; i < AVDT_NUM_LINKS; i++) {
@@ -697,7 +699,7 @@ class AvdtpAdaptationLayer {
    for (size_t i = 0; i < AVDT_NUM_TC_TBL; i++) {
      tc_tbl[i].Reset();
    }
    memset(lcid_tbl, 0, sizeof(lcid_tbl));
    lcid_tbl.clear();
  }

  /**
@@ -711,7 +713,8 @@ class AvdtpAdaptationLayer {

  AvdtpRoutingEntry rt_tbl[AVDT_NUM_LINKS][AVDT_NUM_RT_TBL];
  AvdtpTransportChannel tc_tbl[AVDT_NUM_TC_TBL];
  uint8_t lcid_tbl[MAX_L2CAP_CHANNELS];  // Map LCID to tc_tbl index

  std::unordered_map<uint16_t, uint8_t> lcid_tbl;  // Map LCID to tc_tbl index
};

/**
+2 −4
Original line number Diff line number Diff line
@@ -77,8 +77,7 @@ static void avdt_sec_check_complete_term(const RawAddress* bd_addr,
  if (p_tbl == NULL) return;

  /* store idx in LCID table, store LCID in routing table */
  avdtp_cb.ad.lcid_tbl[p_tbl->lcid - L2CAP_BASE_APPL_CID] =
      avdt_ad_tc_tbl_to_idx(p_tbl);
  avdtp_cb.ad.lcid_tbl[p_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 = p_tbl->lcid;

  /* transition to configuration state */
@@ -204,8 +203,7 @@ void avdt_l2c_connect_ind_cback(const RawAddress& bd_addr, uint16_t lcid,

  /* if result ok, proceed with connection */
  /* store idx in LCID table, store LCID in routing table */
  avdtp_cb.ad.lcid_tbl[lcid - L2CAP_BASE_APPL_CID] =
      avdt_ad_tc_tbl_to_idx(p_tbl);
  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;

  /* transition to configuration state */
Loading