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

Commit 2e83c93d authored by Myles Watson's avatar Myles Watson
Browse files

RootCanal: Send LeReadRemoteFeatures to LE address

Bug: 181371297
Test: cert/run DirectHciTest
Tag: #gd-refactor
Change-Id: I8b795c2bb440f98fc840a837e2ab27ef35811558
parent f5a771b8
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ from bluetooth_packets_python3.hci_packets import BroadcastFlag
from bluetooth_packets_python3.hci_packets import ConnectListAddressType
from bluetooth_packets_python3.hci_packets import LeAddDeviceToConnectListBuilder
from bluetooth_packets_python3.hci_packets import LeSetRandomAddressBuilder
from bluetooth_packets_python3.hci_packets import LeReadRemoteFeaturesBuilder
from bluetooth_packets_python3.hci_packets import WritePageTimeoutBuilder
from bluetooth_packets_python3.hci_packets import ReadBdAddrBuilder
from bluetooth_packets_python3.hci_packets import CreateConnectionBuilder
@@ -204,7 +205,8 @@ class DirectHciTest(GdBaseTestClass):

    def test_le_connection_dut_advertises(self):
        self.dut_hci.register_for_le_events(SubeventCode.CONNECTION_COMPLETE, SubeventCode.ADVERTISING_SET_TERMINATED,
                                            SubeventCode.ENHANCED_CONNECTION_COMPLETE)
                                            SubeventCode.ENHANCED_CONNECTION_COMPLETE,
                                            SubeventCode.READ_REMOTE_FEATURES_COMPLETE)
        # Cert Connects
        self.cert_hal.send_hci_command(LeSetRandomAddressBuilder('0C:05:04:03:02:01'))
        phy_scan_params = DirectHciTest._create_phy_scan_params()
@@ -220,6 +222,11 @@ class DirectHciTest(GdBaseTestClass):

        (dut_handle, cert_handle) = self._verify_le_connection_complete()

        self.dut_hci.send_command(LeReadRemoteFeaturesBuilder(dut_handle))
        assertThat(self.dut_hci.get_le_event_stream()).emits(
            lambda packet: packet.payload[0] == int(EventCode.LE_META_EVENT) and packet.payload[2] == int(SubeventCode.READ_REMOTE_FEATURES_COMPLETE)
        )

        # Send ACL Data
        self.enqueue_acl_data(dut_handle, PacketBoundaryFlag.FIRST_NON_AUTOMATICALLY_FLUSHABLE,
                              BroadcastFlag.POINT_TO_POINT, bytes(b'Just SomeAclData'))
+29 −8
Original line number Diff line number Diff line
@@ -62,16 +62,29 @@ void LinkLayerController::SendLinkLayerPacket(
  });
}

ErrorCode LinkLayerController::SendLeCommandToRemoteByAddress(
    OpCode opcode, bluetooth::packet::PacketView<true> args,
    const Address& remote, const Address& local) {
  switch (opcode) {
    case (OpCode::LE_READ_REMOTE_FEATURES):
      SendLinkLayerPacket(
          model::packets::LeReadRemoteFeaturesBuilder::Create(local, remote));
      break;
    default:
      LOG_INFO("Dropping unhandled command 0x%04x",
               static_cast<uint16_t>(opcode));
      return ErrorCode::UNKNOWN_HCI_COMMAND;
  }

  return ErrorCode::SUCCESS;
}

ErrorCode LinkLayerController::SendCommandToRemoteByAddress(
    OpCode opcode, bluetooth::packet::PacketView<true> args,
    const Address& remote) {
  Address local_address = properties_.GetAddress();

  switch (opcode) {
    case (OpCode::LE_READ_REMOTE_FEATURES):
      SendLinkLayerPacket(model::packets::LeReadRemoteFeaturesBuilder::Create(
          local_address, remote));
      break;
    case (OpCode::REMOTE_NAME_REQUEST):
      // LMP features get requested with remote name requests.
      SendLinkLayerPacket(model::packets::ReadRemoteLmpFeaturesBuilder::Create(
@@ -111,13 +124,20 @@ ErrorCode LinkLayerController::SendCommandToRemoteByAddress(

ErrorCode LinkLayerController::SendCommandToRemoteByHandle(
    OpCode opcode, bluetooth::packet::PacketView<true> args, uint16_t handle) {
  // TODO: Handle LE connections
  if (!connections_.HasHandle(handle)) {
    return ErrorCode::UNKNOWN_CONNECTION;
  }

  switch (opcode) {
    case (OpCode::LE_READ_REMOTE_FEATURES):
      return SendLeCommandToRemoteByAddress(
          opcode, args, connections_.GetAddress(handle).GetAddress(),
          connections_.GetOwnAddress(handle).GetAddress());
    default:
      return SendCommandToRemoteByAddress(
          opcode, args, connections_.GetAddress(handle).GetAddress());
  }
}

ErrorCode LinkLayerController::SendAclToRemote(
    bluetooth::hci::AclView acl_packet) {
@@ -1334,7 +1354,7 @@ void LinkLayerController::IncomingLeReadRemoteFeatures(
      connections_.GetHandleOnlyAddress(incoming.GetSourceAddress());
  ErrorCode status = ErrorCode::SUCCESS;
  if (handle == kReservedHandle) {
    LOG_INFO("@%s: Unknown connection @%s",
    LOG_WARN("@%s: Unknown connection @%s",
             incoming.GetDestinationAddress().ToString().c_str(),
             incoming.GetSourceAddress().ToString().c_str());
  }
@@ -1351,6 +1371,7 @@ void LinkLayerController::IncomingLeReadRemoteFeaturesResponse(
  ErrorCode status = ErrorCode::SUCCESS;
  auto response =
      model::packets::LeReadRemoteFeaturesResponseView::Create(incoming);
  ASSERT(response.IsValid());
  if (handle == kReservedHandle) {
    LOG_INFO("@%s: Unknown connection @%s",
             incoming.GetDestinationAddress().ToString().c_str(),
+3 −0
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@ class LinkLayerController {
  ErrorCode SendCommandToRemoteByAddress(
      OpCode opcode, bluetooth::packet::PacketView<true> args,
      const Address& remote);
  ErrorCode SendLeCommandToRemoteByAddress(
      OpCode opcode, bluetooth::packet::PacketView<true> args,
      const Address& remote, const Address& local);
  ErrorCode SendCommandToRemoteByHandle(
      OpCode opcode, bluetooth::packet::PacketView<true> args, uint16_t handle);
  ErrorCode SendScoToRemote(bluetooth::hci::ScoView sco_packet);