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

Commit bf3e2fe6 authored by Henri Chataing's avatar Henri Chataing Committed by Gerrit Code Review
Browse files

Merge "RootCanal: Implement filtering of Inquiry packets based on IAC"

parents 3cc5e479 bca3008b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -307,6 +307,7 @@ ControllerProperties::ControllerProperties(const std::string& file_name)
  ParseUint(root, "total_num_le_acl_data_packets ",
            total_num_le_acl_data_packets);
  ParseUint(root, "total_num_iso_data_packets ", total_num_iso_data_packets);
  ParseUint(root, "num_supported_iac", num_supported_iac);

  ParseUintArray(root, "lmp_features", lmp_features);
  ParseUintVector(root, "supported_standard_codecs", supported_standard_codecs);
+3 −0
Original line number Diff line number Diff line
@@ -76,6 +76,9 @@ struct ControllerProperties {
  uint8_t total_num_le_acl_data_packets{20};
  uint8_t total_num_iso_data_packets{12};

  // Number of Supported IAC (Vol 4, Part E § 7.3.43).
  uint8_t num_supported_iac{4};

  // Supported Codecs (Vol 4, Part E § 7.4.8).
  // Implements the [v1] version only.
  std::vector<uint8_t> supported_standard_codecs{0};
+4 −5
Original line number Diff line number Diff line
@@ -1745,25 +1745,24 @@ void DualModeController::ReadNumberOfSupportedIac(CommandView command) {
  auto command_view = gd_hci::ReadNumberOfSupportedIacView::Create(
      gd_hci::DiscoveryCommandView::Create(command));
  ASSERT(command_view.IsValid());
  uint8_t num_support_iac = 0x1;
  send_event_(bluetooth::hci::ReadNumberOfSupportedIacCompleteBuilder::Create(
      kNumCommandPackets, ErrorCode::SUCCESS, num_support_iac));
      kNumCommandPackets, ErrorCode::SUCCESS, properties_.num_supported_iac));
}

void DualModeController::ReadCurrentIacLap(CommandView command) {
  auto command_view = gd_hci::ReadCurrentIacLapView::Create(
      gd_hci::DiscoveryCommandView::Create(command));
  ASSERT(command_view.IsValid());
  gd_hci::Lap lap;
  lap.lap_ = 0x30;
  send_event_(bluetooth::hci::ReadCurrentIacLapCompleteBuilder::Create(
      kNumCommandPackets, ErrorCode::SUCCESS, {lap}));
      kNumCommandPackets, ErrorCode::SUCCESS,
      link_layer_controller_.ReadCurrentIacLap()));
}

void DualModeController::WriteCurrentIacLap(CommandView command) {
  auto command_view = gd_hci::WriteCurrentIacLapView::Create(
      gd_hci::DiscoveryCommandView::Create(command));
  ASSERT(command_view.IsValid());
  link_layer_controller_.WriteCurrentIacLap(command_view.GetLapsToWrite());
  send_event_(bluetooth::hci::WriteCurrentIacLapCompleteBuilder::Create(
      kNumCommandPackets, ErrorCode::SUCCESS));
}
+31 −1
Original line number Diff line number Diff line
@@ -1292,6 +1292,14 @@ void LinkLayerController::IncomingInquiryPacket(
  ASSERT(inquiry.IsValid());

  Address peer = incoming.GetSourceAddress();
  uint8_t lap = inquiry.GetLap();

  // Filter out inquiry packets with IAC not present in the
  // list Current_IAC_LAP.
  if (std::none_of(current_iac_lap_list_.cbegin(), current_iac_lap_list_.cend(),
                   [lap](auto iac_lap) { return iac_lap.lap_ == lap; })) {
    return;
  }

  switch (inquiry.GetInquiryType()) {
    case (model::packets::InquiryType::STANDARD): {
@@ -3252,6 +3260,22 @@ ErrorCode LinkLayerController::SetConnectionEncryption(
}
#endif /* ROOTCANAL_LMP */

std::vector<bluetooth::hci::Lap> const& LinkLayerController::ReadCurrentIacLap()
    const {
  return current_iac_lap_list_;
}

void LinkLayerController::WriteCurrentIacLap(
    std::vector<bluetooth::hci::Lap> iac_lap) {
  current_iac_lap_list_.swap(iac_lap);

  //  If Num_Current_IAC is greater than Num_Supported_IAC then only the first
  //  Num_Supported_IAC shall be stored in the Controller
  if (current_iac_lap_list_.size() > properties_.num_supported_iac) {
    current_iac_lap_list_.resize(properties_.num_supported_iac);
  }
}

ErrorCode LinkLayerController::AcceptConnectionRequest(const Address& bd_addr,
                                                       bool try_role_switch) {
  if (connections_.HasPendingConnection(bd_addr)) {
@@ -4206,6 +4230,12 @@ void LinkLayerController::Reset() {
  last_inquiry_ = steady_clock::now();
  page_scan_enable_ = false;
  inquiry_scan_enable_ = false;

  bluetooth::hci::Lap general_iac;
  general_iac.lap_ = 0x33;  // 0x9E8B33
  current_iac_lap_list_.clear();
  current_iac_lap_list_.emplace_back(general_iac);

#ifdef ROOTCANAL_LMP
  lm_.reset(link_manager_create(ops_));
#endif
@@ -4250,7 +4280,7 @@ void LinkLayerController::Inquiry() {
  }

  SendLinkLayerPacket(model::packets::InquiryBuilder::Create(
      GetAddress(), Address::kEmpty, inquiry_mode_));
      GetAddress(), Address::kEmpty, inquiry_mode_, inquiry_lap_));
  last_inquiry_ = now;
}

+6 −0
Original line number Diff line number Diff line
@@ -104,6 +104,9 @@ class LinkLayerController {
  ErrorCode AuthenticationRequested(uint16_t handle);
#endif /* ROOTCANAL_LMP */

  std::vector<bluetooth::hci::Lap> const& ReadCurrentIacLap() const;
  void WriteCurrentIacLap(std::vector<bluetooth::hci::Lap> iac_lap);

  ErrorCode AcceptConnectionRequest(const Address& addr, bool try_role_switch);
  void MakePeripheralConnection(const Address& addr, bool try_role_switch);
  ErrorCode RejectConnectionRequest(const Address& addr, uint8_t reason);
@@ -735,6 +738,9 @@ class LinkLayerController {

  // Other configuration parameters.

  // Current IAC LAP (Vol 4, Part E § 7.3.44).
  std::vector<bluetooth::hci::Lap> current_iac_lap_list_{};

  // Min Encryption Key Size (Vol 4, Part E § 7.3.102).
  uint8_t min_encryption_key_size_{16};

Loading