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

Commit 3c87668d authored by Hansong Zhang's avatar Hansong Zhang
Browse files

L2cap shim clean up

Now we send ConfigReq and ConfigRsp automatically, we need to send
callbacks automatically.

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I34e9a8afef63fed21befeda5c3a66e425d6ffaf8
parent b6e905c4
Loading
Loading
Loading
Loading
+0 −12
Original line number Diff line number Diff line
@@ -109,22 +109,10 @@ bool bluetooth::shim::L2CA_ConnectRsp(const RawAddress& p_bd_addr, uint8_t id,
  return shim_l2cap.ConnectResponse(p_bd_addr, id, lcid, result, status);
}

bool bluetooth::shim::L2CA_ConfigReq(uint16_t cid, tL2CAP_CFG_INFO* cfg_info) {
  return shim_l2cap.ConfigRequest(cid, cfg_info);
}

bool bluetooth::shim::L2CA_ConfigRsp(uint16_t cid, tL2CAP_CFG_INFO* cfg_info) {
  return shim_l2cap.ConfigResponse(cid, cfg_info);
}

bool bluetooth::shim::L2CA_DisconnectReq(uint16_t cid) {
  return shim_l2cap.DisconnectRequest(cid);
}

bool bluetooth::shim::L2CA_DisconnectRsp(uint16_t cid) {
  return shim_l2cap.DisconnectResponse(cid);
}

/**
 * Le Connection Oriented Channel APIs
 */
+0 −35
Original line number Diff line number Diff line
@@ -187,29 +187,6 @@ bool L2CA_ConnectLECocRsp(const RawAddress& p_bd_addr, uint8_t id,
 ******************************************************************************/
bool L2CA_GetPeerLECocConfig(uint16_t lcid, tL2CAP_LE_CFG_INFO* peer_cfg);

/*******************************************************************************
 *
 * Function         L2CA_ConfigReq
 *
 * Description      Higher layers call this function to send configuration.
 *
 * Returns          true if configuration sent, else false
 *
 ******************************************************************************/
bool L2CA_ConfigReq(uint16_t cid, tL2CAP_CFG_INFO* p_cfg);

/*******************************************************************************
 *
 * Function         L2CA_ConfigRsp
 *
 * Description      Higher layers call this function to send a configuration
 *                  response.
 *
 * Returns          true if configuration response sent, else false
 *
 ******************************************************************************/
bool L2CA_ConfigRsp(uint16_t cid, tL2CAP_CFG_INFO* p_cfg);

/*******************************************************************************
 *
 * Function         L2CA_DisconnectReq
@@ -221,18 +198,6 @@ bool L2CA_ConfigRsp(uint16_t cid, tL2CAP_CFG_INFO* p_cfg);
 ******************************************************************************/
bool L2CA_DisconnectReq(uint16_t cid);

/*******************************************************************************
 *
 * Function         L2CA_DisconnectRsp
 *
 * Description      Higher layers call this function to acknowledge the
 *                  disconnection of a channel.
 *
 * Returns          void
 *
 ******************************************************************************/
bool L2CA_DisconnectRsp(uint16_t cid);

/*******************************************************************************
 *
 * Function         L2CA_DataWrite
+18 −48
Original line number Diff line number Diff line
@@ -267,6 +267,15 @@ void bluetooth::shim::legacy::L2cap::OnLocalInitiatedConnectionCreated(
        FROM_HERE,
        base::Bind(classic_.Callbacks(psm).pL2CA_ConnectCfm_Cb, cid,
                   connected ? (kConnectionSuccess) : (kConnectionFail)));
    tL2CAP_CFG_INFO cfg_info{};
    do_in_main_thread(
        FROM_HERE,
        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,
                   L2CAP_CFG_OK));

  } else {
    LOG_DEBUG("Connection Closed before presentation to upper layer");
@@ -298,6 +307,15 @@ void bluetooth::shim::legacy::L2cap::OnRemoteInitiatedConnectionCreated(
      FROM_HERE,
      base::Bind(classic_.Callbacks(CidToPsm(cid)).pL2CA_ConnectInd_Cb,
                 raw_address, cid, psm, kUnusedId));
  tL2CAP_CFG_INFO cfg_info{};
  do_in_main_thread(
      FROM_HERE,
      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,
                 L2CAP_CFG_OK));
}

bool bluetooth::shim::legacy::L2cap::Write(uint16_t cid, BT_HDR* bt_hdr) {
@@ -358,46 +376,6 @@ bool bluetooth::shim::legacy::L2cap::ConnectResponse(
  return true;
}

bool bluetooth::shim::legacy::L2cap::ConfigRequest(
    uint16_t cid, const tL2CAP_CFG_INFO* config_info) {
  LOG_INFO("Received config request from upper layer cid:%hd", cid);
  CHECK(ConnectionExists(cid));

  bluetooth::shim::GetL2cap()->SendLoopbackResponse([this, cid]() {
    CHECK(ConnectionExists(cid));
    tL2CAP_CFG_INFO cfg_info{
        .result = L2CAP_CFG_OK,
        .mtu_present = false,
        .qos_present = false,
        .flush_to_present = false,
        .fcr_present = false,
        .fcs_present = false,
        .ext_flow_spec_present = false,
        .flags = 0,
    };
    LOG(INFO) << __func__ << "Rcvd config request";
    do_in_main_thread(
        FROM_HERE,
        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,
                   L2CAP_CFG_OK));
  });
  return true;
}

bool bluetooth::shim::legacy::L2cap::ConfigResponse(
    uint16_t cid, const tL2CAP_CFG_INFO* config_info) {
  CHECK(ConnectionExists(cid));
  LOG_DEBUG(

      "%s Silently dropping client config response as channel is already open",
      __func__);
  return true;
}

bool bluetooth::shim::legacy::L2cap::DisconnectRequest(uint16_t cid) {
  CHECK(ConnectionExists(cid));
  if (cid_closing_set_.find(cid) != cid_closing_set_.end()) {
@@ -410,14 +388,6 @@ bool bluetooth::shim::legacy::L2cap::DisconnectRequest(uint16_t cid) {
  return true;
}

bool bluetooth::shim::legacy::L2cap::DisconnectResponse(uint16_t cid) {
  LOG_DEBUG(
      "%s Silently dropping client disconnect response as channel is "
      "already disconnected",
      __func__);
  return true;
}

void bluetooth::shim::legacy::L2cap::Dump(int fd) {
  if (cid_to_psm_map_.empty()) {
    dprintf(fd, "%s No active l2cap channels\n", kModuleName);
+1 −3
Original line number Diff line number Diff line
@@ -85,10 +85,8 @@ class L2cap {
  // Legacy API entry points
  bool ConnectResponse(const RawAddress& raw_address, uint8_t signal_id,
                       uint16_t cid, uint16_t result, uint16_t status);
  bool ConfigRequest(uint16_t cid, const tL2CAP_CFG_INFO* config_info);
  bool ConfigResponse(uint16_t cid, const tL2CAP_CFG_INFO* config_info);

  bool DisconnectRequest(uint16_t cid);
  bool DisconnectResponse(uint16_t cid);

  bool GetRemoteCid(uint16_t cid, uint16_t* remote_cid);