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

Commit 1b65f88c authored by Chris Manton's avatar Chris Manton Committed by Hansong Zhang
Browse files

Legacy shim l2cap updates

Bug: 144171652
Test: bluetooth_test_gd

Change-Id: Ieb6b9c0443b112e3a655e4badab567d5643308f1
parent a0615303
Loading
Loading
Loading
Loading
+6 −10
Original line number Diff line number Diff line
@@ -143,24 +143,20 @@ bool bluetooth::shim::L2CA_ConnectRsp(const RawAddress& p_bd_addr, uint8_t id,
                                              status, NULL);
}

bool bluetooth::shim::L2CA_ConfigReq(uint16_t cid, tL2CAP_CFG_INFO* p_cfg) {
  LOG_INFO(LOG_TAG, "UNIMPLEMENTED %s cid:%hd p_cfg:%p", __func__, cid, p_cfg);
  return false;
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* p_cfg) {
  LOG_INFO(LOG_TAG, "UNIMPLEMENTED %s cid:%hd p_cfg:%p", __func__, cid, p_cfg);
  return false;
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) {
  LOG_INFO(LOG_TAG, "UNIMPLEMENTED %s cid:%hd ", __func__, cid);
  return false;
  return shim_l2cap.DisconnectRequest(cid);
}

bool bluetooth::shim::L2CA_DisconnectRsp(uint16_t cid) {
  LOG_INFO(LOG_TAG, "UNIMPLEMENTED %s cid:%hd ", __func__, cid);
  return false;
  return shim_l2cap.DisconnectResponse(cid);
}

/**
+59 −26
Original line number Diff line number Diff line
@@ -73,6 +73,10 @@ bluetooth::legacy::shim::PsmData& bluetooth::legacy::shim::L2cap::Classic() {
  return classic_;
}

bool bluetooth::legacy::shim::L2cap::ConnectionExists(uint16_t cid) const {
  return cid_to_psm_map_.find(cid) != cid_to_psm_map_.end();
}

uint16_t bluetooth::legacy::shim::L2cap::ConvertClientToRealPsm(
    uint16_t client_psm, bool is_outgoing_only_connection) {
  if (!is_outgoing_only_connection) {
@@ -209,27 +213,33 @@ void bluetooth::legacy::shim::L2cap::OnConnectionReady(
  }
  LOG_DEBUG(LOG_TAG, "%s Setting postable map for cid:%d", __func__, cid);
  cid_to_postable_map_[cid] = func;

  func([&cid, &callbacks](uint16_t cid2) {
    LOG_WARN(LOG_TAG, "Cid:%hd Cid2:%hd", cid, cid2);
    LOG_WARN(LOG_TAG,
             "Queuing up the connection confirm to the upper stack but really "
             "a connection has already been done Cid:%hd Cid2:%hd",
             cid, cid2);
    callbacks->pL2CA_ConnectCfm_Cb(cid2, 0);
  });
}

bool bluetooth::legacy::shim::L2cap::IsCongested(uint16_t cid) const {
  LOG_WARN(LOG_TAG, "UNIMPLEMENTED checking congestion on a channel");
  CHECK(ConnectionExists(cid));
  LOG_WARN(LOG_TAG, "Ignoring checks for congestion on cid:%hd", cid);
  return false;
}

bool bluetooth::legacy::shim::L2cap::Write(uint16_t cid, BT_HDR* bt_hdr) {
  CHECK(ConnectionExists(cid));
  CHECK(bt_hdr != nullptr);
  const uint8_t* data = bt_hdr->data + bt_hdr->offset;
  size_t len = bt_hdr->len;
  LOG_DEBUG(LOG_TAG, "Writing data cid:%hd len:%zd", cid, len);
  return bluetooth::shim::GetL2cap()->Write(cid, data, len);
}

bool bluetooth::legacy::shim::L2cap::WriteFlushable(uint16_t cid,
                                                    BT_HDR* bt_hdr) {
  CHECK(ConnectionExists(cid));
  CHECK(bt_hdr != nullptr);
  const uint8_t* data = bt_hdr->data + bt_hdr->offset;
  size_t len = bt_hdr->len;
@@ -238,6 +248,7 @@ bool bluetooth::legacy::shim::L2cap::WriteFlushable(uint16_t cid,

bool bluetooth::legacy::shim::L2cap::WriteNonFlushable(uint16_t cid,
                                                       BT_HDR* bt_hdr) {
  CHECK(ConnectionExists(cid));
  CHECK(bt_hdr != nullptr);
  const uint8_t* data = bt_hdr->data + bt_hdr->offset;
  size_t len = bt_hdr->len;
@@ -247,6 +258,7 @@ bool bluetooth::legacy::shim::L2cap::WriteNonFlushable(uint16_t cid,
bool bluetooth::legacy::shim::L2cap::SetCallbacks(
    uint16_t cid, const tL2CAP_APPL_INFO* callbacks) {
  CHECK(callbacks != nullptr);
  CHECK(ConnectionExists(cid));
  LOG_ASSERT(cid_to_callback_map_.find(cid) == cid_to_callback_map_.end())
      << "Already have callbacks registered for "
         "connection_interface_descriptor:"
@@ -255,10 +267,7 @@ bool bluetooth::legacy::shim::L2cap::SetCallbacks(

  bluetooth::shim::GetL2cap()->SetReadDataReadyCallback(
      cid, [this](uint16_t cid, std::vector<const uint8_t> data) {
        LOG_DEBUG(LOG_TAG,
                  "Got data on connection_interface_descriptor:%hd len:%zd",
                  cid, data.size());

        LOG_DEBUG(LOG_TAG, "OnDataReady cid:%hd len:%zd", cid, data.size());
        BT_HDR* bt_hdr =
            static_cast<BT_HDR*>(osi_calloc(data.size() + kBtHdrSize));
        std::copy(data.begin(), data.end(), bt_hdr->data);
@@ -268,22 +277,32 @@ bool bluetooth::legacy::shim::L2cap::SetCallbacks(

  bluetooth::shim::GetL2cap()->SetConnectionClosedCallback(
      cid, [this](uint16_t cid, int error_code) {
        LOG_DEBUG(LOG_TAG, "Channel closed connection_interface_descriptor:%hd",
                  cid);
        LOG_DEBUG(LOG_TAG, "OnChannel closed callback cid:%hd", cid);
        cid_to_callback_map_[cid]->pL2CA_DisconnectInd_Cb(cid, true);
      });
  return true;
}

void bluetooth::legacy::shim::L2cap::ClearCallbacks(uint16_t cid) {
  LOG_ASSERT(cid_to_callback_map_.find(cid) == cid_to_callback_map_.end())
      << "Clearing callbacks that do not exist connection_interface_descriptor:"
      << cid;
  CHECK(ConnectionExists(cid));
  cid_to_callback_map_.erase(cid);
}

bool bluetooth::legacy::shim::L2cap::ConnectResponse(
    const RawAddress& raw_address, uint8_t signal_id, uint16_t cid,
    uint16_t result, uint16_t status, tL2CAP_ERTM_INFO* ertm_info) {
  CHECK(ConnectionExists(cid));
  LOG_DEBUG(LOG_TAG,
            "%s Silently dropping client connect response as channel is "
            "already connected",
            __func__);
  return true;
}

bool bluetooth::legacy::shim::L2cap::ConfigRequest(
    uint16_t cid, const tL2CAP_CFG_INFO* config_info) {
  CHECK(ConnectionExists(cid));
  LOG_INFO(LOG_TAG, "Received config request from upper layer");
  CHECK(cid_to_psm_map_.find(cid) != cid_to_psm_map_.end());
  const tL2CAP_APPL_INFO* callbacks = Classic().Callbacks(cid_to_psm_map_[cid]);
  CHECK(callbacks != nullptr);
@@ -291,30 +310,44 @@ bool bluetooth::legacy::shim::L2cap::ConfigRequest(

  auto func = cid_to_postable_map_[cid];
  func([&cid, &callbacks](uint16_t cid2) {
    callbacks->pL2CA_ConfigCfm_Cb(cid, nullptr);
    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(LOG_TAG, "Config request lambda");
    callbacks->pL2CA_ConfigCfm_Cb(cid, &cfg_info);
    callbacks->pL2CA_ConfigInd_Cb(cid, &cfg_info);
  });
  return true;
}

bool bluetooth::legacy::shim::L2cap::ConnectResponse(
    const RawAddress& raw_address, uint8_t signal_id, uint16_t cid,
    uint16_t result, uint16_t status, tL2CAP_ERTM_INFO* ertm_info) {
  LOG_INFO(LOG_TAG, "%s UNIMPLEMENTED", __func__);
  return false;
}

bool bluetooth::legacy::shim::L2cap::ConfigResponse(
    uint16_t cid, const tL2CAP_CFG_INFO* config_info) {
  LOG_INFO(LOG_TAG, "%s UNIMPLEMENTED", __func__);
  return false;
  CHECK(ConnectionExists(cid));
  LOG_DEBUG(
      LOG_TAG,
      "%s Silently dropping client config response as channel is already open",
      __func__);
  return true;
}

bool bluetooth::legacy::shim::L2cap::DisconnectRequest(uint16_t cid) {
  LOG_INFO(LOG_TAG, "%s UNIMPLEMENTED", __func__);
  return false;
  CHECK(ConnectionExists(cid));
  bluetooth::shim::GetL2cap()->CloseConnection(cid);
  return true;
}

bool bluetooth::legacy::shim::L2cap::DisconnectResponse(uint16_t cid) {
  LOG_INFO(LOG_TAG, "%s UNIMPLEMENTED", __func__);
  return false;
  CHECK(ConnectionExists(cid));
  LOG_DEBUG(LOG_TAG,
            "%s Silently dropping client disconnect response as channel is "
            "already disconnected",
            __func__);
  return true;
}
+2 −0
Original line number Diff line number Diff line
@@ -96,6 +96,8 @@ class L2cap {
  PsmData classic_;
  PsmData le_;

  bool ConnectionExists(uint16_t cid) const;

  uint16_t classic_dynamic_psm_;
  uint16_t le_dynamic_psm_;
  uint16_t classic_virtual_psm_;