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

Commit 35e7f00a authored by Hansong Zhang's avatar Hansong Zhang
Browse files

LE COC shim: Implement GetMtu()

So the client knows how to split their SDU.

Tag: #gd-refactor
Bug: 141555841
Test: cert/run --host
Test: CtsVerifier
Change-Id: I9dd3fdac1ec7c982d38d9a8751fa0e135b862bb8
parent b8d31bbb
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -24,6 +24,10 @@ LinkOptions* DynamicChannel::GetLinkOptions() {
  return link_->GetLinkOptions();
}

Mtu DynamicChannel::GetMtu() const {
  return mtu_;
}

}  // namespace le
}  // namespace l2cap
}  // namespace bluetooth
+10 −3
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include "l2cap/dynamic_channel.h"
#include "l2cap/le/link_options.h"
#include "l2cap/mtu.h"

namespace bluetooth {
namespace l2cap {
@@ -28,9 +29,12 @@ class Link;

class DynamicChannel : public l2cap::DynamicChannel {
 public:
  DynamicChannel(std::shared_ptr<l2cap::internal::DynamicChannelImpl> impl, os::Handler* l2cap_handler,
                 internal::Link* link)
      : l2cap::DynamicChannel(impl, l2cap_handler), link_(link) {}
  DynamicChannel(
      std::shared_ptr<l2cap::internal::DynamicChannelImpl> impl,
      os::Handler* l2cap_handler,
      internal::Link* link,
      Mtu mtu)
      : l2cap::DynamicChannel(impl, l2cap_handler), link_(link), mtu_(mtu) {}

  /**
   * Get the Proxy for L2CAP Link Options.
@@ -39,8 +43,11 @@ class DynamicChannel : public l2cap::DynamicChannel {
   */
  LinkOptions* GetLinkOptions();

  Mtu GetMtu() const;

 private:
  internal::Link* link_;
  Mtu mtu_;
};

}  // namespace le
+7 −4
Original line number Diff line number Diff line
@@ -259,10 +259,11 @@ void LeSignallingManager::on_security_result_for_incoming(Psm psm, PendingConnec
                           LeCreditBasedConnectionResponseResult::SUCCESS);
  auto* data_controller = reinterpret_cast<l2cap::internal::LeCreditBasedDataController*>(
      data_pipeline_manager_->GetDataController(new_channel->GetCid()));
  data_controller->SetMtu(std::min(request.mtu, local_mtu));
  auto actual_mtu = std::min(request.mtu, local_mtu);
  data_controller->SetMtu(actual_mtu);
  data_controller->SetMps(std::min(request.max_pdu_size, local_mps));
  data_controller->OnCredit(request.initial_credits);
  auto user_channel = std::make_unique<DynamicChannel>(new_channel, handler_, link_);
  auto user_channel = std::make_unique<DynamicChannel>(new_channel, handler_, link_, actual_mtu);
  dynamic_service_manager_->GetService(psm)->NotifyChannelCreation(std::move(user_channel));
}

@@ -295,10 +296,12 @@ void LeSignallingManager::OnConnectionResponse(SignalId signal_id, Cid remote_ci
  }
  auto* data_controller = reinterpret_cast<l2cap::internal::LeCreditBasedDataController*>(
      data_pipeline_manager_->GetDataController(new_channel->GetCid()));
  data_controller->SetMtu(std::min(mtu, command_just_sent_.mtu_));
  auto actual_mtu = std::min(mtu, command_just_sent_.mtu_);
  data_controller->SetMtu(actual_mtu);
  data_controller->SetMps(std::min(mps, command_just_sent_.mps_));
  data_controller->OnCredit(initial_credits);
  std::unique_ptr<DynamicChannel> user_channel = std::make_unique<DynamicChannel>(new_channel, handler_, link_);
  std::unique_ptr<DynamicChannel> user_channel =
      std::make_unique<DynamicChannel>(new_channel, handler_, link_, actual_mtu);
  dynamic_service_manager_->GetService(command_just_sent_.psm_)->NotifyChannelCreation(std::move(user_channel));
}

+22 −5
Original line number Diff line number Diff line
@@ -567,6 +567,13 @@ struct LeDynamicChannelHelper {
    return true;
  }

  uint16_t GetMtu(AddressWithType remote) {
    if (channels_.count(remote) == 0) {
      return 0;
    }
    return static_cast<uint16_t>(channels_[remote]->GetMtu());
  }

  std::unordered_map<AddressWithType, std::unique_ptr<DynamicChannel>>
      channels_;
  std::unordered_map<AddressWithType,
@@ -617,12 +624,22 @@ uint16_t bluetooth::shim::L2CA_ConnectLECocReq(uint16_t psm,
  return add_cid_token_entry(psm, p_bd_addr);
}

bool bluetooth::shim::L2CA_GetPeerLECocConfig(uint16_t lcid,
bool bluetooth::shim::L2CA_GetPeerLECocConfig(uint16_t cid,
                                              tL2CAP_LE_CFG_INFO* peer_cfg) {
  // TODO(hsz): Implement me with real value
  peer_cfg->mps = 1000;
  peer_cfg->mtu = 1000;
  return true;
  if (cid_token_to_channel_map_.count(cid) == 0) {
    LOG(ERROR) << __func__ << "Invalid cid: " << cid;
    return false;
  }
  auto psm = cid_token_to_channel_map_[cid].psm;
  auto remote = cid_token_to_channel_map_[cid].remote;
  if (le_dynamic_channel_helper_map_.count(psm) == 0) {
    LOG(ERROR) << __func__ << "Not registered psm: " << psm;
    return false;
  }
  auto mtu = le_dynamic_channel_helper_map_[psm]->GetMtu(
      bluetooth::ToAddressWithType(remote, Btm::GetAddressType(remote)));
  peer_cfg->mtu = mtu;
  return mtu;
}

bool bluetooth::shim::L2CA_DisconnectLECocReq(uint16_t cid) {