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

Commit 6310469d authored by Chienyuan's avatar Chienyuan Committed by Chienyuan Huang
Browse files

Read APCF extended features

Bug: 247032118
Test: gd/cert/run
Test: ./bluetooth_test_gd_unit64 --gtest_filter=*ScanningManagerTest* --gtest_repeat=1000
Tag: #refactor
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: Id956c8e0d37fad934033dc462f393b050d19d9fb
Merged-In: Id956c8e0d37fad934033dc462f393b050d19d9fb
parent 85b92d46
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -1169,9 +1169,16 @@ class CsisClientImpl : public CsisClient {
  }

  void CsisActiveObserverSet(bool enable) {
    LOG(INFO) << __func__ << " CSIS Discovery SET: " << enable;

    bool is_ad_type_filter_supported =
        bluetooth::shim::is_ad_type_filter_supported();
    LOG_INFO("CSIS Discovery SET: %d, is_ad_type_filter_supported: %d", enable,
             is_ad_type_filter_supported);
    if (is_ad_type_filter_supported) {
      bluetooth::shim::set_ad_type_rsi_filter(enable);
    } else {
      bluetooth::shim::set_empty_filter(enable);
    }

    BTA_DmBleCsisObserve(
        enable, [](tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data) {
          /* If there's no instance we are most likely shutting
+17 −0
Original line number Diff line number Diff line
@@ -4845,6 +4845,7 @@ enum ApcfOpcode : 8 {
  MANUFACTURER_DATA = 0x06,
  SERVICE_DATA = 0x07,
  AD_TYPE = 0x08,
  READ_EXTENDED_FEATURES = 0xFF,
}

// https://source.android.com/devices/bluetooth/hci_requirements#advertising-packet-content-filter
@@ -5012,6 +5013,22 @@ packet LeAdvFilterADTypeComplete : LeAdvFilterComplete (apcf_opcode = AD_TYPE) {
  apcf_available_spaces : 8,
}

packet LeAdvFilterReadExtendedFeatures : LeAdvFilter (apcf_opcode = READ_EXTENDED_FEATURES) {
}

test LeAdvFilterReadExtendedFeatures {
  "\x57\xfd\x01\xff",
}

packet LeAdvFilterReadExtendedFeaturesComplete : LeAdvFilterComplete (apcf_opcode = READ_EXTENDED_FEATURES) {
  ad_type_filter : 1,
  _reserved_ : 15,
}

test LeAdvFilterReadExtendedFeaturesComplete {
  "\x0e\x07\x01\x57\xfd\x00\xff\x01\x00",
}

packet LeEnergyInfo : VendorCommand (op_code = LE_ENERGY_INFO) {
}

+102 −62

File changed.

Preview size limit exceeded, changes collapsed.

+2 −0
Original line number Diff line number Diff line
@@ -92,6 +92,8 @@ class LeScanningManager : public bluetooth::Module {

  virtual void RegisterScanningCallback(ScanningCallback* scanning_callback);

  virtual bool IsAdTypeFilterSupported() const;

  static const ModuleFactory Factory;

 protected:
+40 −18
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ class TestHciLayer : public HciLayer {
  void EnqueueCommand(
      std::unique_ptr<CommandBuilder> command,
      common::ContextualOnceCallback<void(CommandStatusView)> on_status) override {
    std::lock_guard<std::mutex> lock(mutex_);
    command_queue_.push(std::move(command));
    command_status_callbacks.push_back(std::move(on_status));
    command_count_--;
@@ -86,6 +87,7 @@ class TestHciLayer : public HciLayer {
  void EnqueueCommand(
      std::unique_ptr<CommandBuilder> command,
      common::ContextualOnceCallback<void(CommandCompleteView)> on_complete) override {
    std::lock_guard<std::mutex> lock(mutex_);
    command_queue_.push(std::move(command));
    command_complete_callbacks.push_back(std::move(on_complete));
    command_count_--;
@@ -103,31 +105,21 @@ class TestHciLayer : public HciLayer {
    command_future_ = std::make_unique<std::future<void>>(command_promise_->get_future());
  }

  CommandView GetLastCommand() {
    if (command_queue_.size() == 0) {
      return empty_command_view_;
    }
    auto last = std::move(command_queue_.front());
    command_queue_.pop();
    return CommandView::Create(GetPacketView(std::move(last)));
  }

  CommandView GetCommand() {
    if (!command_queue_.empty()) {
      std::lock_guard<std::mutex> lock(mutex_);
      if (command_future_ != nullptr) {
        command_future_.reset();
        command_promise_.reset();
      }
    } else if (command_future_ != nullptr) {
    // Wait for EnqueueCommand if command_queue_ is empty
    if (command_queue_.empty() && command_future_ != nullptr) {
      command_future_->wait_for(std::chrono::milliseconds(1000));
    }

    std::lock_guard<std::mutex> lock(mutex_);
    if (command_queue_.empty()) {
      LOG_ERROR("Command queue is empty");
      return empty_command_view_;
    }
    CommandView command_packet_view = GetLastCommand();

    auto last = std::move(command_queue_.front());
    command_queue_.pop();
    CommandView command_packet_view = CommandView::Create(GetPacketView(std::move(last)));
    if (!command_packet_view.IsValid()) {
      LOG_ERROR("Got invalid command");
      return empty_command_view_;
@@ -283,7 +275,12 @@ class LeScanningManagerTest : public ::testing::Test {
    fake_registry_.InjectTestModule(&AclManager::Factory, test_acl_manager_);
    client_handler_ = fake_registry_.GetTestModuleHandler(&HciLayer::Factory);
    ASSERT_NE(client_handler_, nullptr);
    if (is_filter_support_) {
      // Will send APCF read extended features command if APCF supported
      test_hci_layer_->SetCommandFuture(2);
    } else {
      test_hci_layer_->SetCommandFuture(1);
    }
    // configure_scan will be trigger by impl.start() and enqueue set scan parameter command
    fake_registry_.Start<LeScanningManager>(&thread_);
    le_scanning_manager =
@@ -293,6 +290,7 @@ class LeScanningManagerTest : public ::testing::Test {
  }

  void TearDown() override {
    sync_client_handler();
    fake_registry_.SynchronizeModuleHandler(&LeScanningManager::Factory, std::chrono::milliseconds(20));
    fake_registry_.StopAll();
  }
@@ -378,9 +376,13 @@ class LeAndroidHciScanningManagerTest : public LeScanningManagerTest {
    is_filter_support_ = true;
    is_batch_scan_support_ = true;
    LeScanningManagerTest::SetUp();
    sync_client_handler();
  }

  void HandleConfiguration() override {
    ASSERT_EQ(OpCode::LE_ADV_FILTER, test_hci_layer_->GetCommand().GetOpCode());
    test_hci_layer_->IncomingEvent(LeAdvFilterReadExtendedFeaturesCompleteBuilder::Create(1, ErrorCode::SUCCESS, 0x01));
    sync_client_handler();
    ASSERT_EQ(param_opcode_, test_hci_layer_->GetCommand().GetOpCode());
    test_hci_layer_->IncomingEvent(LeExtendedScanParamsCompleteBuilder::Create(1, ErrorCode::SUCCESS));
  }
@@ -432,6 +434,22 @@ TEST_F(LeScanningManagerTest, start_scan_test) {
  test_hci_layer_->IncomingLeMetaEvent(LeAdvertisingReportBuilder::Create({report}));
}

TEST_F(LeScanningManagerTest, is_ad_type_filter_supported_false_test) {
  ASSERT_FALSE(le_scanning_manager->IsAdTypeFilterSupported());
}

TEST_F(LeScanningManagerTest, scan_filter_add_ad_type_not_supported_test) {
  test_hci_layer_->SetCommandFuture(1);
  std::vector<AdvertisingPacketContentFilterCommand> filters = {};
  AdvertisingPacketContentFilterCommand filter{};
  filter.filter_type = ApcfFilterType::AD_TYPE;
  filter.ad_type = 0x09;
  filter.data = {0x12, 0x34, 0x56, 0x78};
  filter.data_mask = {0xff, 0xff, 0xff, 0xff};
  filters.push_back(filter);
  le_scanning_manager->ScanFilterAdd(0x01, filters);
}

TEST_F(LeAndroidHciScanningManagerTest, startup_teardown) {}

TEST_F(LeAndroidHciScanningManagerTest, start_scan_test) {
@@ -464,6 +482,10 @@ TEST_F(LeAndroidHciScanningManagerTest, start_scan_test) {
  test_hci_layer_->IncomingLeMetaEvent(LeAdvertisingReportBuilder::Create({report}));
}

TEST_F(LeAndroidHciScanningManagerTest, is_ad_type_filter_supported_true_test) {
  ASSERT_TRUE(le_scanning_manager->IsAdTypeFilterSupported());
}

TEST_F(LeAndroidHciScanningManagerTest, scan_filter_enable_test) {
  test_hci_layer_->SetCommandFuture(1);
  le_scanning_manager->ScanFilterEnable(true);
Loading