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

Commit f3198a93 authored by Myles Watson's avatar Myles Watson
Browse files

Rootcanal: Use LinkLayer packets for commands

Use a different LinkLayer packet for each command and response.
Use std::array for device name and keys.

Bug: 138260499
Test: Connect two phones with Rootcanal, try to pair
Change-Id: I82a54afd0821ac71324878904025732a7655abc3
parent 6fa61f77
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -42,19 +42,25 @@ uint16_t AclConnectionHandler::GetUnusedHandle() {
  return unused_handle;
}

bool AclConnectionHandler::CreatePendingConnection(Address addr) {
bool AclConnectionHandler::CreatePendingConnection(
    Address addr, bool authenticate_on_connect) {
  if (classic_connection_pending_) {
    return false;
  }
  classic_connection_pending_ = true;
  pending_connection_address_ = addr;
  authenticate_pending_classic_connection_ = authenticate_on_connect;
  return true;
}

bool AclConnectionHandler::HasPendingConnection(Address addr) {
bool AclConnectionHandler::HasPendingConnection(Address addr) const {
  return classic_connection_pending_ && pending_connection_address_ == addr;
}

bool AclConnectionHandler::AuthenticatePendingConnection() const {
  return authenticate_pending_classic_connection_;
}

bool AclConnectionHandler::CancelPendingConnection(Address addr) {
  if (!classic_connection_pending_ || pending_connection_address_ != addr) {
    return false;
@@ -79,7 +85,8 @@ bool AclConnectionHandler::CreatePendingLeConnection(Address addr, uint8_t addre
  return true;
}

bool AclConnectionHandler::HasPendingLeConnection(Address addr, uint8_t address_type) {
bool AclConnectionHandler::HasPendingLeConnection(Address addr,
                                                  uint8_t address_type) const {
  return le_connection_pending_ && pending_le_connection_address_ == addr &&
         pending_le_connection_address_type_ == address_type;
}
+9 −6
Original line number Diff line number Diff line
@@ -34,12 +34,13 @@ class AclConnectionHandler {

  virtual ~AclConnectionHandler() = default;

  bool CreatePendingConnection(Address addr);
  bool HasPendingConnection(Address addr);
  bool CreatePendingConnection(Address addr, bool authenticate_on_connect);
  bool HasPendingConnection(Address addr) const;
  bool CancelPendingConnection(Address addr);
  bool AuthenticatePendingConnection() const;

  bool CreatePendingLeConnection(Address addr, uint8_t addr_type);
  bool HasPendingLeConnection(Address addr, uint8_t addr_type);
  bool HasPendingLeConnection(Address addr, uint8_t addr_type) const;
  bool CancelPendingLeConnection(Address addr, uint8_t addr_type);

  uint16_t CreateConnection(Address addr);
@@ -65,10 +66,12 @@ class AclConnectionHandler {
 private:
  std::unordered_map<uint16_t, AclConnection> acl_connections_;
  bool classic_connection_pending_{false};
  Address pending_connection_address_;
  Address pending_connection_address_{Address::kEmpty};
  bool authenticate_pending_classic_connection_{false};
  bool le_connection_pending_{false};
  Address pending_le_connection_address_;
  uint8_t pending_le_connection_address_type_;
  Address pending_le_connection_address_{Address::kEmpty};
  uint8_t pending_le_connection_address_type_{false};

  uint16_t GetUnusedHandle();
  uint16_t last_handle_{acl::kReservedHandle - 2};
  void set_own_address_type(uint16_t handle, uint8_t own_address_type);
+6 −9
Original line number Diff line number Diff line
@@ -338,9 +338,8 @@ void DualModeController::HciReset(packets::PacketView<true> args) {
    loopback_mode_ = hci::LoopbackMode::NO;
  }

  auto packet = bluetooth::hci::ResetCompleteBuilder::Create(
      kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
  send_event_(std::move(packet));
  send_event_(bluetooth::hci::ResetCompleteBuilder::Create(
      kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS));
}

void DualModeController::HciReadBufferSize(packets::PacketView<true> args) {
@@ -941,8 +940,6 @@ void DualModeController::HciWriteExtendedInquiryResponse(packets::PacketView<tru
  // Strip FEC byte and trailing zeros
  std::vector<uint8_t> clipped(args.begin() + 1, args.begin() + LastNonZero(args) + 1);
  properties_.SetExtendedInquiryData(clipped);
  LOG_WARN("Write EIR Inquiry - Size = %d (%d)", static_cast<int>(properties_.GetExtendedInquiryData().size()),
           static_cast<int>(clipped.size()));
  auto packet =
      bluetooth::hci::WriteExtendedInquiryResponseCompleteBuilder::Create(
          kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
@@ -1045,8 +1042,9 @@ void DualModeController::HciRejectConnectionRequest(packets::PacketView<true> ar

void DualModeController::HciLinkKeyRequestReply(packets::PacketView<true> args) {
  ASSERT_LOG(args.size() == 22, "%s  size=%zu", __func__, args.size());
  Address addr = args.begin().extract<Address>();
  packets::PacketView<true> key = args.SubViewLittleEndian(6, 22);
  auto args_it = args.begin();
  Address addr = args_it.extract<Address>();
  auto key = args.begin().extract<std::array<uint8_t, 16>>();
  auto status = link_layer_controller_.LinkKeyRequestReply(addr, key);
  auto packet = bluetooth::hci::LinkKeyRequestReplyCompleteBuilder::Create(
      kNumCommandPackets, status);
@@ -1089,7 +1087,7 @@ void DualModeController::HciRemoteNameRequest(packets::PacketView<true> args) {
  Address remote_addr = args.begin().extract<Address>();

  auto status = link_layer_controller_.SendCommandToRemoteByAddress(
      bluetooth::hci::OpCode::REMOTE_NAME_REQUEST, args, remote_addr, false);
      bluetooth::hci::OpCode::REMOTE_NAME_REQUEST, args, remote_addr);

  auto packet = bluetooth::hci::RemoteNameRequestStatusBuilder::Create(
      status, kNumCommandPackets);
@@ -1192,7 +1190,6 @@ void DualModeController::HciLeSetScanParameters(packets::PacketView<true> args)

void DualModeController::HciLeSetScanEnable(packets::PacketView<true> args) {
  ASSERT_LOG(args.size() == 2, "%s  size=%zu", __func__, args.size());
  LOG_INFO("SetScanEnable: %d %d", args[0], args[1]);
  link_layer_controller_.SetLeScanEnable(args[0]);
  link_layer_controller_.SetLeFilterDuplicates(args[1]);
  auto packet = bluetooth::hci::LeSetScanEnableCompleteBuilder::Create(
+280 −205

File changed.

Preview size limit exceeded, changes collapsed.

+25 −6
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ class LinkLayerController {
  LinkLayerController(const DeviceProperties& properties) : properties_(properties) {}
  bluetooth::hci::ErrorCode SendCommandToRemoteByAddress(
      bluetooth::hci::OpCode opcode, packets::PacketView<true> args,
      const Address& remote, bool use_public_address);
      const Address& remote);
  bluetooth::hci::ErrorCode SendCommandToRemoteByHandle(
      bluetooth::hci::OpCode opcode, packets::PacketView<true> args,
      uint16_t handle);
@@ -51,8 +51,8 @@ class LinkLayerController {
  void StartSimplePairing(const Address& address);
  void AuthenticateRemoteStage1(const Address& address, PairingType pairing_type);
  void AuthenticateRemoteStage2(const Address& address);
  bluetooth::hci::ErrorCode LinkKeyRequestReply(const Address& address,
                                                packets::PacketView<true> key);
  bluetooth::hci::ErrorCode LinkKeyRequestReply(
      const Address& address, const std::array<uint8_t, 16>& key);
  bluetooth::hci::ErrorCode LinkKeyRequestNegativeReply(const Address& address);
  bluetooth::hci::ErrorCode IoCapabilityRequestReply(
      const Address& peer, uint8_t io_capability, uint8_t oob_data_present_flag,
@@ -106,7 +106,7 @@ class LinkLayerController {
  // Set the callbacks for sending packets to the HCI.
  void RegisterEventChannel(
      const std::function<void(
          std::shared_ptr<bluetooth::hci::EventPacketBuilder>)>& send_event_);
          std::shared_ptr<bluetooth::hci::EventPacketBuilder>)>& send_event);

  void RegisterAclChannel(const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_acl);

@@ -261,7 +261,6 @@ class LinkLayerController {
      std::unique_ptr<model::packets::LinkLayerPacketBuilder> packet);
  void IncomingAclPacket(model::packets::LinkLayerPacketView packet);
  void IncomingAclAckPacket(model::packets::LinkLayerPacketView packet);
  void IncomingCommandPacket(model::packets::LinkLayerPacketView packet);
  void IncomingCreateConnectionPacket(
      model::packets::LinkLayerPacketView packet);
  void IncomingDisconnectPacket(model::packets::LinkLayerPacketView packet);
@@ -287,7 +286,27 @@ class LinkLayerController {
  void IncomingPagePacket(model::packets::LinkLayerPacketView packet);
  void IncomingPageRejectPacket(model::packets::LinkLayerPacketView packet);
  void IncomingPageResponsePacket(model::packets::LinkLayerPacketView packet);
  void IncomingResponsePacket(model::packets::LinkLayerPacketView packet);
  void IncomingReadRemoteLmpFeatures(
      model::packets::LinkLayerPacketView packet);
  void IncomingReadRemoteLmpFeaturesResponse(
      model::packets::LinkLayerPacketView packet);
  void IncomingReadRemoteSupportedFeatures(
      model::packets::LinkLayerPacketView packet);
  void IncomingReadRemoteSupportedFeaturesResponse(
      model::packets::LinkLayerPacketView packet);
  void IncomingReadRemoteExtendedFeatures(
      model::packets::LinkLayerPacketView packet);
  void IncomingReadRemoteExtendedFeaturesResponse(
      model::packets::LinkLayerPacketView packet);
  void IncomingReadRemoteVersion(model::packets::LinkLayerPacketView packet);
  void IncomingReadRemoteVersionResponse(
      model::packets::LinkLayerPacketView packet);
  void IncomingReadClockOffset(model::packets::LinkLayerPacketView packet);
  void IncomingReadClockOffsetResponse(
      model::packets::LinkLayerPacketView packet);
  void IncomingRemoteNameRequest(model::packets::LinkLayerPacketView packet);
  void IncomingRemoteNameRequestResponse(
      model::packets::LinkLayerPacketView packet);

 private:
  const DeviceProperties& properties_;
Loading