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

Commit de14a263 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fix l2cap callback connection creation API" am: 2626d823 am: f7bffb73

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1420529

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

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


  if ((callbacks->pL2CA_ConfigCfm_Cb == nullptr) ||
  if ((callbacks.pL2CA_ConfigCfm_Cb == nullptr) ||
      (callbacks->pL2CA_ConfigInd_Cb == nullptr) ||
      (callbacks.pL2CA_ConfigInd_Cb == nullptr) ||
      (callbacks->pL2CA_DataInd_Cb == nullptr) ||
      (callbacks.pL2CA_DataInd_Cb == nullptr) ||
      (callbacks->pL2CA_DisconnectInd_Cb == nullptr)) {
      (callbacks.pL2CA_DisconnectInd_Cb == nullptr)) {
    LOG_ERROR("%s Invalid classic callbacks psm:%hd", __func__, client_psm);
    LOG_ERROR("%s Invalid classic callbacks psm:%hd", __func__, client_psm);
    return 0;
    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.
   * Check if this is a registration for an outgoing-only connection.
   */
   */
  bool is_outgoing_connection_only = callbacks->pL2CA_ConnectInd_Cb == nullptr;
  const bool is_outgoing_connection_only =
  uint16_t psm = shim_l2cap.ConvertClientToRealPsm(client_psm,
      callbacks.pL2CA_ConnectInd_Cb == nullptr;
                                                   is_outgoing_connection_only);
  const uint16_t psm = shim_l2cap.ConvertClientToRealPsm(
      client_psm, is_outgoing_connection_only);


  if (shim_l2cap.Classic().IsPsmRegistered(psm)) {
  if (shim_l2cap.Classic().IsPsmRegistered(psm)) {
    LOG_ERROR("%s Already registered classic client_psm:%hd psm:%hd", __func__,
    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
 * Le Connection Oriented Channel APIs
 */
 */
uint16_t bluetooth::shim::L2CA_RegisterLECoc(uint16_t psm,
uint16_t bluetooth::shim::L2CA_RegisterLECoc(
                                             tL2CAP_APPL_INFO* callbacks) {
    uint16_t psm, const tL2CAP_APPL_INFO& callbacks) {
  LOG_INFO("UNIMPLEMENTED %s psm:%hd callbacks:%p", __func__, psm, callbacks);
  LOG_INFO("UNIMPLEMENTED %s psm:%hd", __func__, psm);
  return 0;
  return 0;
}
}


+2 −2
Original line number Original line Diff line number Diff line
@@ -38,7 +38,7 @@ namespace shim {
 *                  BTM_SetSecurityLevel().
 *                  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,
                       bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
                       uint16_t required_mtu);
                       uint16_t required_mtu);


@@ -148,7 +148,7 @@ uint16_t L2CA_ErtmConnectReq(uint16_t psm, const RawAddress& p_bd_addr,
 *                  and BTM_SetSecurityLevel().
 *                  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 Original line 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 {
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(
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));
  CHECK(!HasClient(psm));
  psm_to_callback_map_[psm] = callbacks;
  psm_to_callback_map_.try_emplace(psm, tL2CAP_APPL_INFO(callbacks));
}

void bluetooth::shim::legacy::PsmManager::RegisterPsm(uint16_t psm) {
  RegisterPsm(psm, nullptr);
}
}


void bluetooth::shim::legacy::PsmManager::UnregisterPsm(uint16_t psm) {
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);
  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) {
    uint16_t psm) {
  CHECK(HasClient(psm));
  CHECK(HasClient(psm));
  return psm_to_callback_map_[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 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) {
    tL2CAP_ERTM_INFO* p_ertm_info, uint16_t required_mtu) {
  if (Classic().IsPsmRegistered(psm)) {
  if (Classic().IsPsmRegistered(psm)) {
    LOG_WARN("Service is already registered psm:%hd", psm);
    LOG_WARN("Service is already registered psm:%hd", psm);
@@ -269,7 +266,7 @@ void bluetooth::shim::legacy::L2cap::OnLocalInitiatedConnectionCreated(
    }
    }
    do_in_main_thread(
    do_in_main_thread(
        FROM_HERE,
        FROM_HERE,
        base::Bind(classic_.Callbacks(psm)->pL2CA_ConnectCfm_Cb, cid,
        base::Bind(classic_.Callbacks(psm).pL2CA_ConnectCfm_Cb, cid,
                   connected ? (kConnectionSuccess) : (kConnectionFail)));
                   connected ? (kConnectionSuccess) : (kConnectionFail)));


  } else {
  } else {
@@ -300,7 +297,7 @@ void bluetooth::shim::legacy::L2cap::OnRemoteInitiatedConnectionCreated(
  SetDownstreamCallbacks(cid);
  SetDownstreamCallbacks(cid);
  do_in_main_thread(
  do_in_main_thread(
      FROM_HERE,
      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));
                 raw_address, cid, psm, kUnusedId));
}
}


@@ -326,7 +323,7 @@ void bluetooth::shim::legacy::L2cap::SetDownstreamCallbacks(uint16_t cid) {
        bt_hdr->len = data.size();
        bt_hdr->len = data.size();
        do_in_main_thread(
        do_in_main_thread(
            FROM_HERE,
            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)));
                       base::Unretained(bt_hdr)));
      });
      });


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


        } else {
        } else {
          do_in_main_thread(
          do_in_main_thread(
              FROM_HERE,
              FROM_HERE,
              base::Bind(
              base::Bind(
                  classic_.Callbacks(CidToPsm(cid))->pL2CA_DisconnectInd_Cb,
                  classic_.Callbacks(CidToPsm(cid)).pL2CA_DisconnectInd_Cb, cid,
                  cid, kDisconnectResponseRequired));
                  kDisconnectResponseRequired));
        }
        }
        cid_to_psm_map_.erase(cid);
        cid_to_psm_map_.erase(cid);
        cid_to_remote_cid_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";
    LOG(INFO) << __func__ << "Rcvd config request";
    do_in_main_thread(
    do_in_main_thread(
        FROM_HERE,
        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)));
                   base::Unretained(&cfg_info)));
    do_in_main_thread(
    do_in_main_thread(
        FROM_HERE,
        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)));
                   base::Unretained(&cfg_info)));
  });
  });
  return true;
  return true;
+4 −5
Original line number Original line Diff line number Diff line
@@ -38,10 +38,9 @@ class PsmManager {
 public:
 public:
  bool IsPsmRegistered(uint16_t psm) const;
  bool IsPsmRegistered(uint16_t psm) const;
  bool HasClient(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, const tL2CAP_APPL_INFO& callbacks);
  void RegisterPsm(uint16_t psm);
  void UnregisterPsm(uint16_t psm);
  void UnregisterPsm(uint16_t psm);
  const tL2CAP_APPL_INFO* Callbacks(uint16_t psm);
  const tL2CAP_APPL_INFO Callbacks(uint16_t psm);


 private:
 private:
  /**
  /**
@@ -54,12 +53,12 @@ class PsmManager {
   * A valid client is indicated with a valid psm key entry and a
   * A valid client is indicated with a valid psm key entry and a
   * non-nullptr value.
   * 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 {
class L2cap {
 public:
 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,
                           bool enable_snoop, tL2CAP_ERTM_INFO* p_ertm_info,
                           uint16_t required_mtu);
                           uint16_t required_mtu);
  void UnregisterService(uint16_t psm);
  void UnregisterService(uint16_t psm);
+4 −6
Original line number Original line 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;
  avct_cb.mtu = mtu;


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


  /* Include the browsing channel which uses eFCR */
  /* Include the browsing channel which uses eFCR */
  tL2CAP_ERTM_INFO ertm_info;
  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;
  if (mtu_br < AVCT_MIN_BROWSE_MTU) mtu_br = AVCT_MIN_BROWSE_MTU;
  avct_cb.mtu_br = mtu_br;
  avct_cb.mtu_br = mtu_br;


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


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