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

Commit 748b3f6e authored by Henri Chataing's avatar Henri Chataing
Browse files

RootCanal: Implement additional filter accept list parameter validation

Additional checks for:
  - LeClearFilterAcceptList
  - LeAddDeviceToFilterAcceptList
  - LeRemoveDeviceFromFilterAcceptList

Test: gd cert test
Test: atest --host --no-bazel rootcanal_hci_test
Bug: 245578454
Ignore-AOSP-First: cherry-pick from AOSP
Merged-In: I909f53cfd6fea7f735d06c7a3038a3c1e94fec37
Change-Id: I909f53cfd6fea7f735d06c7a3038a3c1e94fec37
(cherry picked from commit 8338f328)
parent e63442a4
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -125,6 +125,9 @@ cc_test_host {
        "rootcanal_defaults",
    ],
    srcs: [
        "test/controller/le/le_clear_filter_accept_list_test.cc",
        "test/controller/le/le_add_device_to_filter_accept_list_test.cc",
        "test/controller/le/le_remove_device_from_filter_accept_list_test.cc",
        "test/controller/le/le_add_device_to_resolving_list_test.cc",
        "test/controller/le/le_clear_resolving_list_test.cc",
        "test/controller/le/le_remove_device_from_resolving_list_test.cc",
+0 −3
Original line number Diff line number Diff line
@@ -285,9 +285,6 @@ ControllerProperties::ControllerProperties(const std::string& file_name)
  ParseUint(root, "ManufacturerName", company_identifier);

  ParseHex64(root["LeSupportedFeatures"], &le_features);
  ParseUint(root, "LeConnectListIgnoreReasons", le_connect_list_ignore_reasons);
  ParseUint(root, "LeResolvingListIgnoreReasons",
            le_resolving_list_ignore_reasons);

  // Configuration options.

+0 −9
Original line number Diff line number Diff line
@@ -93,15 +93,6 @@ struct ControllerProperties {
  // Vendor Information.
  // Provide parameters returned by vendor specific commands.
  std::vector<uint8_t> le_vendor_capabilities{};

  // LE Workarounds
  uint16_t le_connect_list_ignore_reasons{0};
  uint16_t le_resolving_list_ignore_reasons{0};

  // Workaround for misbehaving stacks
  static constexpr uint8_t kLeListIgnoreScanEnable = 0x1;
  static constexpr uint8_t kLeListIgnoreConnections = 0x2;
  static constexpr uint8_t kLeListIgnoreAdvertising = 0x4;
};

}  // namespace rootcanal
+18 −30
Original line number Diff line number Diff line
@@ -2097,7 +2097,7 @@ void DualModeController::LeSetAdvertisingParameters(CommandView command) {
      static_cast<uint8_t>(command_view.GetOwnAddressType()),
      static_cast<uint8_t>(command_view.GetPeerAddressType()), peer_address,
      command_view.GetAdvertisingChannelMap(),
      static_cast<uint8_t>(command_view.GetAdvertisingFilterPolicy()));
      command_view.GetAdvertisingFilterPolicy());

  send_event_(bluetooth::hci::LeSetAdvertisingParametersCompleteBuilder::Create(
      kNumCommandPackets, ErrorCode::SUCCESS));
@@ -2165,7 +2165,7 @@ void DualModeController::LeSetScanParameters(CommandView command) {
  link_layer_controller_.SetLeScanWindow(command_view.GetLeScanWindow());
  link_layer_controller_.SetLeAddressType(command_view.GetOwnAddressType());
  link_layer_controller_.SetLeScanFilterPolicy(
      static_cast<uint8_t>(command_view.GetScanningFilterPolicy()));
      command_view.GetScanningFilterPolicy());
  send_event_(bluetooth::hci::LeSetScanParametersCompleteBuilder::Create(
      kNumCommandPackets, ErrorCode::SUCCESS));
}
@@ -2194,13 +2194,15 @@ void DualModeController::LeCreateConnection(CommandView command) {
      gd_hci::LeConnectionManagementCommandView::Create(
          gd_hci::AclCommandView::Create(command)));
  ASSERT(command_view.IsValid());
  auto initiator_filter_policy = command_view.GetInitiatorFilterPolicy();

  link_layer_controller_.SetLeScanInterval(command_view.GetLeScanInterval());
  link_layer_controller_.SetLeScanWindow(command_view.GetLeScanWindow());
  uint8_t initiator_filter_policy =
      static_cast<uint8_t>(command_view.GetInitiatorFilterPolicy());
  link_layer_controller_.SetLeInitiatorFilterPolicy(initiator_filter_policy);

  if (initiator_filter_policy == 0) {  // Connect list not used
  if (initiator_filter_policy ==
      bluetooth::hci::InitiatorFilterPolicy::USE_PEER_ADDRESS) {
    // Connect list not used
    uint8_t peer_address_type =
        static_cast<uint8_t>(command_view.GetPeerAddressType());
    Address peer_address = command_view.GetPeerAddress();
@@ -2326,9 +2328,9 @@ void DualModeController::LeClearFilterAcceptList(CommandView command) {
      gd_hci::LeConnectionManagementCommandView::Create(
          gd_hci::AclCommandView::Create(command)));
  ASSERT(command_view.IsValid());
  link_layer_controller_.LeFilterAcceptListClear();
  ErrorCode status = link_layer_controller_.LeClearFilterAcceptList();
  send_event_(bluetooth::hci::LeClearFilterAcceptListCompleteBuilder::Create(
      kNumCommandPackets, ErrorCode::SUCCESS));
      kNumCommandPackets, status));
}

void DualModeController::LeAddDeviceToFilterAcceptList(CommandView command) {
@@ -2336,17 +2338,11 @@ void DualModeController::LeAddDeviceToFilterAcceptList(CommandView command) {
      gd_hci::LeConnectionManagementCommandView::Create(
          gd_hci::AclCommandView::Create(command)));
  ASSERT(command_view.IsValid());

  ErrorCode result = ErrorCode::INVALID_HCI_COMMAND_PARAMETERS;
  if (command_view.GetAddressType() !=
      bluetooth::hci::FilterAcceptListAddressType::ANONYMOUS_ADVERTISERS) {
    result = link_layer_controller_.LeFilterAcceptListAddDevice(
        command_view.GetAddress(), static_cast<bluetooth::hci::AddressType>(
                                       command_view.GetAddressType()));
  }
  ErrorCode status = link_layer_controller_.LeAddDeviceToFilterAcceptList(
      command_view.GetAddressType(), command_view.GetAddress());
  send_event_(
      bluetooth::hci::LeAddDeviceToFilterAcceptListCompleteBuilder::Create(
          kNumCommandPackets, result));
          kNumCommandPackets, status));
}

void DualModeController::LeRemoveDeviceFromFilterAcceptList(
@@ -2355,16 +2351,8 @@ void DualModeController::LeRemoveDeviceFromFilterAcceptList(
      gd_hci::LeConnectionManagementCommandView::Create(
          gd_hci::AclCommandView::Create(command)));
  ASSERT(command_view.IsValid());

  ErrorCode status = ErrorCode::SUCCESS;
  if (command_view.GetAddressType() !=
      bluetooth::hci::FilterAcceptListAddressType::ANONYMOUS_ADVERTISERS) {
    link_layer_controller_.LeFilterAcceptListAddDevice(
        command_view.GetAddress(), static_cast<bluetooth::hci::AddressType>(
                                       command_view.GetAddressType()));
  } else {
    status = ErrorCode::INVALID_HCI_COMMAND_PARAMETERS;
  }
  ErrorCode status = link_layer_controller_.LeRemoveDeviceFromFilterAcceptList(
      command_view.GetAddressType(), command_view.GetAddress());
  send_event_(
      bluetooth::hci::LeRemoveDeviceFromFilterAcceptListCompleteBuilder::Create(
          kNumCommandPackets, status));
@@ -2492,7 +2480,7 @@ void DualModeController::LeSetExtendedScanParameters(CommandView command) {
    link_layer_controller_.SetLeScanWindow(parameters[0].le_scan_window_);
    link_layer_controller_.SetLeAddressType(command_view.GetOwnAddressType());
    link_layer_controller_.SetLeScanFilterPolicy(
        static_cast<uint8_t>(command_view.GetScanningFilterPolicy()));
        command_view.GetScanningFilterPolicy());
  } else {
    status = ErrorCode::COMMAND_DISALLOWED;
  }
@@ -2524,11 +2512,11 @@ void DualModeController::LeExtendedCreateConnection(CommandView command) {
  ASSERT(command_view.IsValid());
  ASSERT_LOG(command_view.GetInitiatingPhys() == 1, "Only LE_1M is supported");
  auto params = command_view.GetPhyScanParameters();
  auto initiator_filter_policy = command_view.GetInitiatorFilterPolicy();

  link_layer_controller_.SetLeScanInterval(params[0].scan_interval_);
  link_layer_controller_.SetLeScanWindow(params[0].scan_window_);
  auto initiator_filter_policy = command_view.GetInitiatorFilterPolicy();
  link_layer_controller_.SetLeInitiatorFilterPolicy(
      static_cast<uint8_t>(initiator_filter_policy));
  link_layer_controller_.SetLeInitiatorFilterPolicy(initiator_filter_policy);

  if (initiator_filter_policy ==
      gd_hci::InitiatorFilterPolicy::USE_PEER_ADDRESS) {
+14 −13
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ namespace rootcanal {
void LeAdvertiser::Initialize(OwnAddressType address_type,
                              AddressWithType public_address,
                              AddressWithType peer_address,
                              LeScanningFilterPolicy filter_policy,
                              AdvertisingFilterPolicy filter_policy,
                              AdvertisingType type,
                              const std::vector<uint8_t>& advertisement,
                              const std::vector<uint8_t>& scan_response,
@@ -44,7 +44,7 @@ void LeAdvertiser::Initialize(OwnAddressType address_type,
void LeAdvertiser::InitializeExtended(
    unsigned advertising_handle, OwnAddressType address_type,
    AddressWithType public_address, AddressWithType peer_address,
    LeScanningFilterPolicy filter_policy, AdvertisingType type,
    AdvertisingFilterPolicy filter_policy, AdvertisingType type,
    std::chrono::steady_clock::duration interval, uint8_t tx_power,
    const std::function<bluetooth::hci::Address()>& get_address) {
  get_address_ = get_address;
@@ -64,7 +64,7 @@ void LeAdvertiser::InitializeExtended(
void LeAdvertiser::Clear() {
  address_ = AddressWithType{};
  peer_address_ = AddressWithType{};
  filter_policy_ = LeScanningFilterPolicy::ACCEPT_ALL;
  filter_policy_ = AdvertisingFilterPolicy::ALL_DEVICES;
  type_ = AdvertisingType::ADV_IND;
  advertisement_.clear();
  scan_response_.clear();
@@ -256,24 +256,25 @@ LeAdvertiser::GetAdvertisement(std::chrono::steady_clock::time_point now) {

std::unique_ptr<model::packets::LinkLayerPacketBuilder>
LeAdvertiser::GetScanResponse(bluetooth::hci::Address scanned,
                              bluetooth::hci::Address scanner) {
                              bluetooth::hci::Address scanner,
                              bool scanner_in_filter_accept_list) {
  (void)scanner;
  if (scanned != address_.GetAddress() || !enabled_) {
    return nullptr;
  }

  switch (filter_policy_) {
    case bluetooth::hci::LeScanningFilterPolicy::
        FILTER_ACCEPT_LIST_AND_INITIATORS_IDENTITY:
    case bluetooth::hci::LeScanningFilterPolicy::FILTER_ACCEPT_LIST_ONLY:
      LOG_WARN("ScanResponses don't handle connect list filters");
      return nullptr;
    case bluetooth::hci::LeScanningFilterPolicy::CHECK_INITIATORS_IDENTITY:
      if (scanner != peer_address_.GetAddress()) {
    case bluetooth::hci::AdvertisingFilterPolicy::ALL_DEVICES:
    case bluetooth::hci::AdvertisingFilterPolicy::LISTED_CONNECT:
      break;
    case bluetooth::hci::AdvertisingFilterPolicy::LISTED_SCAN:
    case bluetooth::hci::AdvertisingFilterPolicy::LISTED_SCAN_AND_CONNECT:
      if (!scanner_in_filter_accept_list) {
        return nullptr;
      }
      break;
    case bluetooth::hci::LeScanningFilterPolicy::ACCEPT_ALL:
      break;
  }

  if (tx_power_ == kTxPowerUnavailable) {
    return model::packets::LeScanResponseBuilder::Create(
        address_.GetAddress(), peer_address_.GetAddress(),
Loading