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

Commit 4e72f180 authored by Henri Chataing's avatar Henri Chataing
Browse files

RootCanal: Simplify hci_packets.pdl

- Remove intermediate command views:
  AclCommandView, SecurityCommandView a.s.o.

Bug: 279465240
Test: m root-canal
Change-Id: I2e7327a75f9014ab74badff75058a9595d9975ce
parent 7104087b
Loading
Loading
Loading
Loading
+6 −12
Original line number Diff line number Diff line
@@ -77,8 +77,7 @@ std::vector<uint8_t> PcapFilter::FilterHciCommand(
    case OpCode::LE_SET_PERIODIC_ADVERTISING_DATA:
      return FilterLeSetPeriodicAdvertisingData(command);
    case OpCode::LE_MULTI_ADVT: {
      auto le_multi_advt_command =
          LeMultiAdvtView::Create(LeAdvertisingCommandView::Create(command));
      auto le_multi_advt_command = LeMultiAdvtView::Create(command);
      ASSERT(le_multi_advt_command.IsValid());
      switch (le_multi_advt_command.GetSubCmd()) {
        case SubOcf::SET_DATA:
@@ -231,8 +230,7 @@ std::vector<uint8_t> PcapFilter::FilterWriteExtendedInquiryResponse(
// Replace the device names in the GAP entries of the advertising data.
std::vector<uint8_t> PcapFilter::FilterLeSetAdvertisingData(
    CommandView& command) {
  auto parameters = LeSetAdvertisingDataView::Create(
      LeAdvertisingCommandView::Create(command));
  auto parameters = LeSetAdvertisingDataView::Create(command);
  ASSERT(parameters.IsValid());

  std::vector<GapData> advertising_data = parameters.GetAdvertisingData();
@@ -244,8 +242,7 @@ std::vector<uint8_t> PcapFilter::FilterLeSetAdvertisingData(
// Replace the device names in the GAP entries of the scan response data.
std::vector<uint8_t> PcapFilter::FilterLeSetScanResponseData(
    CommandView& command) {
  auto parameters = LeSetScanResponseDataView::Create(
      LeAdvertisingCommandView::Create(command));
  auto parameters = LeSetScanResponseDataView::Create(command);
  ASSERT(parameters.IsValid());

  std::vector<GapData> advertising_data = parameters.GetAdvertisingData();
@@ -257,8 +254,7 @@ std::vector<uint8_t> PcapFilter::FilterLeSetScanResponseData(
// Replace the device names in the GAP entries of the extended advertising data.
std::vector<uint8_t> PcapFilter::FilterLeSetExtendedAdvertisingData(
    CommandView& command) {
  auto parameters = LeSetExtendedAdvertisingDataView::Create(
      LeAdvertisingCommandView::Create(command));
  auto parameters = LeSetExtendedAdvertisingDataView::Create(command);
  ASSERT(parameters.IsValid());

  std::vector<GapData> advertising_data = parameters.GetAdvertisingData();
@@ -273,8 +269,7 @@ std::vector<uint8_t> PcapFilter::FilterLeSetExtendedAdvertisingData(
// data.
std::vector<uint8_t> PcapFilter::FilterLeSetExtendedScanResponseData(
    CommandView& command) {
  auto parameters = LeSetExtendedScanResponseDataView::Create(
      LeAdvertisingCommandView::Create(command));
  auto parameters = LeSetExtendedScanResponseDataView::Create(command);
  ASSERT(parameters.IsValid());

  std::vector<GapData> advertising_data = parameters.GetScanResponseData();
@@ -289,8 +284,7 @@ std::vector<uint8_t> PcapFilter::FilterLeSetExtendedScanResponseData(
// data.
std::vector<uint8_t> PcapFilter::FilterLeSetPeriodicAdvertisingData(
    bluetooth::hci::CommandView& command) {
  auto parameters = LeSetPeriodicAdvertisingDataView::Create(
      LeAdvertisingCommandView::Create(command));
  auto parameters = LeSetPeriodicAdvertisingDataView::Create(command);
  ASSERT(parameters.IsValid());

  std::vector<GapData> advertising_data = parameters.GetAdvertisingData();
+77 −95
Original line number Diff line number Diff line
@@ -124,13 +124,11 @@ impl LinkManager {
        command: &hci::CommandPacket,
        status: hci::ErrorCode,
    ) -> Result<(), LinkManagerError> {
        use hci::ConnectionManagementCommandChild::*;
        use hci::SecurityCommandChild::*;
        use hci::CommandChild::*;
        #[allow(unused_imports)]
        use Option::None; // Overwrite `None` variant of `Child` enum

        let event: hci::EventPacket = match command.specialize() {
            hci::CommandChild::SecurityCommand(command) => match command.specialize() {
            LinkKeyRequestReply(packet) => hci::LinkKeyRequestReplyCompleteBuilder {
                status,
                bd_addr: packet.get_bd_addr(),
@@ -203,14 +201,12 @@ impl LinkManager {
                }
                .into()
            }
                RemoteOobDataRequestReply(packet) => {
                    hci::RemoteOobDataRequestReplyCompleteBuilder {
            RemoteOobDataRequestReply(packet) => hci::RemoteOobDataRequestReplyCompleteBuilder {
                status,
                bd_addr: packet.get_bd_addr(),
                num_hci_command_packets,
            }
                    .into()
                }
            .into(),
            RemoteOobDataRequestNegativeReply(packet) => {
                hci::RemoteOobDataRequestNegativeReplyCompleteBuilder {
                    status,
@@ -225,27 +221,13 @@ impl LinkManager {
                num_hci_command_packets,
            }
            .into(),
                _ => return Err(LinkManagerError::UnhandledHciPacket),
            },
            hci::CommandChild::AclCommand(command) => match command.specialize() {
                hci::AclCommandChild::ConnectionManagementCommand(command) => {
                    match command.specialize() {
                        AuthenticationRequested(_) => hci::AuthenticationRequestedStatusBuilder {
                            status,
                            num_hci_command_packets,
                        }
                        .into(),
                        SetConnectionEncryption(_) => hci::SetConnectionEncryptionStatusBuilder {
                            status,
                            num_hci_command_packets,
                        }
                        .into(),
                        _ => return Err(LinkManagerError::UnhandledHciPacket),
            AuthenticationRequested(_) => {
                hci::AuthenticationRequestedStatusBuilder { status, num_hci_command_packets }.into()
            }
            SetConnectionEncryption(_) => {
                hci::SetConnectionEncryptionStatusBuilder { status, num_hci_command_packets }.into()
            }
            _ => return Err(LinkManagerError::UnhandledHciPacket),
            },
            _ => return Err(LinkManagerError::UnhandledHciPacket),
        };
        self.ops.send_hci_event(&event.to_vec());
        Ok(())
+18 −29
Original line number Diff line number Diff line
@@ -93,12 +93,11 @@ pub mod hci {
    include!(concat!(env!("OUT_DIR"), "/hci_packets.rs"));

    pub fn command_remote_device_address(command: &CommandPacket) -> Option<Address> {
        use CommandChild::*;
        #[allow(unused_imports)]
        use Option::None;
        use SecurityCommandChild::*; // Overwrite `None` variant of `Child` enum
        use Option::None; // Overwrite `None` variant of `Child` enum

        match command.specialize() {
            CommandChild::SecurityCommand(command) => match command.specialize() {
            LinkKeyRequestReply(packet) => Some(packet.get_bd_addr()),
            LinkKeyRequestNegativeReply(packet) => Some(packet.get_bd_addr()),
            PinCodeRequestReply(packet) => Some(packet.get_bd_addr()),
@@ -113,30 +112,20 @@ pub mod hci {
            RemoteOobDataRequestNegativeReply(packet) => Some(packet.get_bd_addr()),
            SendKeypressNotification(packet) => Some(packet.get_bd_addr()),
            _ => None,
            },
            _ => None,
        }
    }

    pub fn command_connection_handle(command: &CommandPacket) -> Option<u16> {
        use ConnectionManagementCommandChild::*;
        use CommandChild::*;
        #[allow(unused_imports)]
        use Option::None; // Overwrite `None` variant of `Child` enum

        match command.specialize() {
            CommandChild::AclCommand(command) => match command.specialize() {
                AclCommandChild::ConnectionManagementCommand(command) => {
        match command.specialize() {
            AuthenticationRequested(packet) => Some(packet.get_connection_handle()),
            SetConnectionEncryption(packet) => Some(packet.get_connection_handle()),
            _ => None,
        }
    }
                _ => None,
            },
            _ => None,
        }
    }
}

pub mod lmp {
+193 −333

File changed.

Preview size limit exceeded, changes collapsed.

+196 −206

File changed.

Preview size limit exceeded, changes collapsed.