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

Commit 2626d823 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Fix l2cap callback connection creation API"

parents ead84230 4ce609b1
Loading
Loading
Loading
Loading
+12 −13
Original line number Diff line number Diff line
@@ -32,21 +32,19 @@ static bluetooth::shim::legacy::L2cap shim_l2cap;
 * Classic Service Registration APIs
 */
uint16_t bluetooth::shim::L2CA_Register(uint16_t client_psm,
                                        tL2CAP_APPL_INFO* callbacks,
                                        const tL2CAP_APPL_INFO& callbacks,
                                        bool enable_snoop,
                                        tL2CAP_ERTM_INFO* p_ertm_info,
                                        uint16_t required_mtu) {
  CHECK(callbacks != nullptr);

  if (L2C_INVALID_PSM(client_psm)) {
    LOG_ERROR("%s Invalid classic psm:%hd", __func__, client_psm);
    return 0;
  }

  if ((callbacks->pL2CA_ConfigCfm_Cb == nullptr) ||
      (callbacks->pL2CA_ConfigInd_Cb == nullptr) ||
      (callbacks->pL2CA_DataInd_Cb == nullptr) ||
      (callbacks->pL2CA_DisconnectInd_Cb == nullptr)) {
  if ((callbacks.pL2CA_ConfigCfm_Cb == nullptr) ||
      (callbacks.pL2CA_ConfigInd_Cb == nullptr) ||
      (callbacks.pL2CA_DataInd_Cb == nullptr) ||
      (callbacks.pL2CA_DisconnectInd_Cb == nullptr)) {
    LOG_ERROR("%s Invalid classic callbacks psm:%hd", __func__, client_psm);
    return 0;
  }
@@ -54,9 +52,10 @@ uint16_t bluetooth::shim::L2CA_Register(uint16_t client_psm,
  /**
   * Check if this is a registration for an outgoing-only connection.
   */
  bool is_outgoing_connection_only = callbacks->pL2CA_ConnectInd_Cb == nullptr;
  uint16_t psm = shim_l2cap.ConvertClientToRealPsm(client_psm,
                                                   is_outgoing_connection_only);
  const bool is_outgoing_connection_only =
      callbacks.pL2CA_ConnectInd_Cb == nullptr;
  const uint16_t psm = shim_l2cap.ConvertClientToRealPsm(
      client_psm, is_outgoing_connection_only);

  if (shim_l2cap.Classic().IsPsmRegistered(psm)) {
    LOG_ERROR("%s Already registered classic client_psm:%hd psm:%hd", __func__,
@@ -144,9 +143,9 @@ bool bluetooth::shim::L2CA_DisconnectRsp(uint16_t cid) {
/**
 * Le Connection Oriented Channel APIs
 */
uint16_t bluetooth::shim::L2CA_RegisterLECoc(uint16_t psm,
                                             tL2CAP_APPL_INFO* callbacks) {
  LOG_INFO("UNIMPLEMENTED %s psm:%hd callbacks:%p", __func__, psm, callbacks);
uint16_t bluetooth::shim::L2CA_RegisterLECoc(
    uint16_t psm, const tL2CAP_APPL_INFO& callbacks) {
  LOG_INFO("UNIMPLEMENTED %s psm:%hd", __func__, psm);
  return 0;
}

+2 −2
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ namespace shim {
 *                  BTM_SetSecurityLevel().
 *
 ******************************************************************************/
uint16_t L2CA_Register(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info,
uint16_t L2CA_Register(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info,
                       bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
                       uint16_t required_mtu);

@@ -148,7 +148,7 @@ uint16_t L2CA_ErtmConnectReq(uint16_t psm, const RawAddress& p_bd_addr,
 *                  and BTM_SetSecurityLevel().
 *
 ******************************************************************************/
uint16_t L2CA_RegisterLECoc(uint16_t psm, tL2CAP_APPL_INFO* p_cb_info);
uint16_t L2CA_RegisterLECoc(uint16_t psm, const tL2CAP_APPL_INFO& p_cb_info);

/*******************************************************************************
 *
+15 −18
Original line number Diff line number Diff line
@@ -43,17 +43,14 @@ bool bluetooth::shim::legacy::PsmManager::IsPsmRegistered(uint16_t psm) const {
}

bool bluetooth::shim::legacy::PsmManager::HasClient(uint16_t psm) const {
  return IsPsmRegistered(psm) && psm_to_callback_map_.at(psm) != nullptr;
  return IsPsmRegistered(psm) &&
         psm_to_callback_map_.find(psm) != psm_to_callback_map_.end();
}

void bluetooth::shim::legacy::PsmManager::RegisterPsm(
    uint16_t psm, const tL2CAP_APPL_INFO* callbacks) {
    uint16_t psm, const tL2CAP_APPL_INFO& callbacks) {
  CHECK(!HasClient(psm));
  psm_to_callback_map_[psm] = callbacks;
}

void bluetooth::shim::legacy::PsmManager::RegisterPsm(uint16_t psm) {
  RegisterPsm(psm, nullptr);
  psm_to_callback_map_.try_emplace(psm, tL2CAP_APPL_INFO(callbacks));
}

void bluetooth::shim::legacy::PsmManager::UnregisterPsm(uint16_t psm) {
@@ -61,7 +58,7 @@ void bluetooth::shim::legacy::PsmManager::UnregisterPsm(uint16_t psm) {
  psm_to_callback_map_.erase(psm);
}

const tL2CAP_APPL_INFO* bluetooth::shim::legacy::PsmManager::Callbacks(
const tL2CAP_APPL_INFO bluetooth::shim::legacy::PsmManager::Callbacks(
    uint16_t psm) {
  CHECK(HasClient(psm));
  return psm_to_callback_map_[psm];
@@ -164,7 +161,7 @@ uint16_t bluetooth::shim::legacy::L2cap::GetNextDynamicClassicPsm() {
}

uint16_t bluetooth::shim::legacy::L2cap::RegisterService(
    uint16_t psm, const tL2CAP_APPL_INFO* callbacks, bool enable_snoop,
    uint16_t psm, const tL2CAP_APPL_INFO& callbacks, bool enable_snoop,
    tL2CAP_ERTM_INFO* p_ertm_info, uint16_t required_mtu) {
  if (Classic().IsPsmRegistered(psm)) {
    LOG_WARN("Service is already registered psm:%hd", psm);
@@ -269,7 +266,7 @@ void bluetooth::shim::legacy::L2cap::OnLocalInitiatedConnectionCreated(
    }
    do_in_main_thread(
        FROM_HERE,
        base::Bind(classic_.Callbacks(psm)->pL2CA_ConnectCfm_Cb, cid,
        base::Bind(classic_.Callbacks(psm).pL2CA_ConnectCfm_Cb, cid,
                   connected ? (kConnectionSuccess) : (kConnectionFail)));

  } else {
@@ -300,7 +297,7 @@ void bluetooth::shim::legacy::L2cap::OnRemoteInitiatedConnectionCreated(
  SetDownstreamCallbacks(cid);
  do_in_main_thread(
      FROM_HERE,
      base::Bind(classic_.Callbacks(CidToPsm(cid))->pL2CA_ConnectInd_Cb,
      base::Bind(classic_.Callbacks(CidToPsm(cid)).pL2CA_ConnectInd_Cb,
                 raw_address, cid, psm, kUnusedId));
}

@@ -326,7 +323,7 @@ void bluetooth::shim::legacy::L2cap::SetDownstreamCallbacks(uint16_t cid) {
        bt_hdr->len = data.size();
        do_in_main_thread(
            FROM_HERE,
            base::Bind(classic_.Callbacks(CidToPsm(cid))->pL2CA_DataInd_Cb, cid,
            base::Bind(classic_.Callbacks(CidToPsm(cid)).pL2CA_DataInd_Cb, cid,
                       base::Unretained(bt_hdr)));
      });

@@ -342,15 +339,15 @@ void bluetooth::shim::legacy::L2cap::SetDownstreamCallbacks(uint16_t cid) {
          do_in_main_thread(
              FROM_HERE,
              base::Bind(
                  classic_.Callbacks(CidToPsm(cid))->pL2CA_DisconnectCfm_Cb,
                  cid, kUnusedResult));
                  classic_.Callbacks(CidToPsm(cid)).pL2CA_DisconnectCfm_Cb, cid,
                  kUnusedResult));

        } else {
          do_in_main_thread(
              FROM_HERE,
              base::Bind(
                  classic_.Callbacks(CidToPsm(cid))->pL2CA_DisconnectInd_Cb,
                  cid, kDisconnectResponseRequired));
                  classic_.Callbacks(CidToPsm(cid)).pL2CA_DisconnectInd_Cb, cid,
                  kDisconnectResponseRequired));
        }
        cid_to_psm_map_.erase(cid);
        cid_to_remote_cid_map_.erase(cid);
@@ -388,11 +385,11 @@ bool bluetooth::shim::legacy::L2cap::ConfigRequest(
    LOG(INFO) << __func__ << "Rcvd config request";
    do_in_main_thread(
        FROM_HERE,
        base::Bind(classic_.Callbacks(CidToPsm(cid))->pL2CA_ConfigInd_Cb, cid,
        base::Bind(classic_.Callbacks(CidToPsm(cid)).pL2CA_ConfigInd_Cb, cid,
                   base::Unretained(&cfg_info)));
    do_in_main_thread(
        FROM_HERE,
        base::Bind(classic_.Callbacks(CidToPsm(cid))->pL2CA_ConfigCfm_Cb, cid,
        base::Bind(classic_.Callbacks(CidToPsm(cid)).pL2CA_ConfigCfm_Cb, cid,
                   base::Unretained(&cfg_info)));
  });
  return true;
+4 −5
Original line number Diff line number Diff line
@@ -38,10 +38,9 @@ class PsmManager {
 public:
  bool IsPsmRegistered(uint16_t psm) const;
  bool HasClient(uint16_t psm) const;
  void RegisterPsm(uint16_t psm, const tL2CAP_APPL_INFO* callbacks);
  void RegisterPsm(uint16_t psm);
  void RegisterPsm(uint16_t psm, const tL2CAP_APPL_INFO& callbacks);
  void UnregisterPsm(uint16_t psm);
  const tL2CAP_APPL_INFO* Callbacks(uint16_t psm);
  const tL2CAP_APPL_INFO Callbacks(uint16_t psm);

 private:
  /**
@@ -54,12 +53,12 @@ class PsmManager {
   * A valid client is indicated with a valid psm key entry and a
   * non-nullptr value.
   */
  std::unordered_map<uint16_t, const tL2CAP_APPL_INFO*> psm_to_callback_map_;
  std::unordered_map<uint16_t, const tL2CAP_APPL_INFO> psm_to_callback_map_;
};

class L2cap {
 public:
  uint16_t RegisterService(uint16_t psm, const tL2CAP_APPL_INFO* callbacks,
  uint16_t RegisterService(uint16_t psm, const tL2CAP_APPL_INFO& callbacks,
                           bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
                           uint16_t required_mtu);
  void UnregisterService(uint16_t psm);
+4 −6
Original line number Diff line number Diff line
@@ -64,9 +64,8 @@ void AVCT_Register(uint16_t mtu, UNUSED_ATTR uint16_t mtu_br) {
  avct_cb.mtu = mtu;

  /* register PSM with L2CAP */
  L2CA_Register2(AVCT_PSM, (tL2CAP_APPL_INFO*)&avct_l2c_appl,
                 true /* enable_snoop */, nullptr, avct_cb.mtu,
                 BTA_SEC_AUTHENTICATE);
  L2CA_Register2(AVCT_PSM, avct_l2c_appl, true /* enable_snoop */, nullptr,
                 avct_cb.mtu, BTA_SEC_AUTHENTICATE);

  /* Include the browsing channel which uses eFCR */
  tL2CAP_ERTM_INFO ertm_info;
@@ -80,9 +79,8 @@ void AVCT_Register(uint16_t mtu, UNUSED_ATTR uint16_t mtu_br) {
  if (mtu_br < AVCT_MIN_BROWSE_MTU) mtu_br = AVCT_MIN_BROWSE_MTU;
  avct_cb.mtu_br = mtu_br;

  L2CA_Register2(AVCT_BR_PSM, (tL2CAP_APPL_INFO*)&avct_l2c_br_appl,
                 true /*enable_snoop*/, &ertm_info, avct_cb.mtu_br,
                 BTA_SEC_AUTHENTICATE);
  L2CA_Register2(AVCT_BR_PSM, avct_l2c_br_appl, true /*enable_snoop*/,
                 &ertm_info, avct_cb.mtu_br, BTA_SEC_AUTHENTICATE);

#if defined(AVCT_INITIAL_TRACE_LEVEL)
  avct_cb.trace_level = AVCT_INITIAL_TRACE_LEVEL;
Loading