OSDN Git Service

gd: Present zeroed peer addr with type when using connect list
authorChris Manton <cmanton@google.com>
Sat, 31 Oct 2020 17:56:45 +0000 (10:56 -0700)
committerChris Manton <cmanton@google.com>
Wed, 4 Nov 2020 18:30:05 +0000 (10:30 -0800)
The fields are ignored but zeroed out for correctness.
Preserves original stack behavior

Bug: 171568335
Test: CtsVerifier
Test: atest --host bluetooth_test_gd
Tag: #refactor

Change-Id: I6235c9545115a247d4f4b3a7f31dfa97ce3d06b2

gd/hci/acl_manager/le_impl.h
gd/hci/acl_manager_test.cc

index fff94f0..c0569ed 100644 (file)
@@ -390,6 +390,10 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
 
     connecting_le_.insert(address_with_type);
 
+    if (initiator_filter_policy == InitiatorFilterPolicy::USE_CONNECT_LIST) {
+      address_with_type = AddressWithType();
+    }
+
     if (controller_->IsSupported(OpCode::LE_EXTENDED_CREATE_CONNECTION)) {
       LeCreateConnPhyScanParameters tmp;
       tmp.scan_interval_ = le_scan_interval;
index 3237fe5..c1e8958 100644 (file)
@@ -43,6 +43,7 @@ using packet::PacketView;
 using packet::RawBuilder;
 
 constexpr std::chrono::seconds kTimeout = std::chrono::seconds(2);
+const AddressWithType empty_address_with_type = hci::AddressWithType();
 
 PacketView<kLittleEndian> GetPacketView(std::unique_ptr<packet::BasePacketBuilder> packet) {
   auto bytes = std::make_shared<std::vector<uint8_t>>();
@@ -352,6 +353,7 @@ class AclManagerNoCallbacksTest : public ::testing::Test {
   os::Handler* client_handler_ = nullptr;
   Address remote;
   AddressWithType my_initiating_address;
+  const bool use_connect_list_ = true;  // gd currently only supports connect list
 
   std::future<void> GetConnectionFuture() {
     ASSERT_LOG(mock_connection_callback_.connection_promise_ == nullptr, "Promises promises ... Only one at a time");
@@ -582,8 +584,13 @@ class AclManagerWithLeConnectionTest : public AclManagerTest {
     auto le_connection_management_command_view = LeConnectionManagementCommandView::Create(packet);
     auto command_view = LeCreateConnectionView::Create(le_connection_management_command_view);
     ASSERT_TRUE(command_view.IsValid());
-    EXPECT_EQ(command_view.GetPeerAddress(), remote);
-    EXPECT_EQ(command_view.GetPeerAddressType(), AddressType::PUBLIC_DEVICE_ADDRESS);
+    if (use_connect_list_) {
+      ASSERT_EQ(command_view.GetPeerAddress(), empty_address_with_type.GetAddress());
+      ASSERT_EQ(command_view.GetPeerAddressType(), empty_address_with_type.GetAddressType());
+    } else {
+      ASSERT_EQ(command_view.GetPeerAddress(), remote);
+      ASSERT_EQ(command_view.GetPeerAddressType(), AddressType::PUBLIC_DEVICE_ADDRESS);
+    }
 
     test_hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01));
 
@@ -659,7 +666,11 @@ TEST_F(AclManagerTest, invoke_registered_callback_le_connection_complete_fail) {
   auto le_connection_management_command_view = LeConnectionManagementCommandView::Create(packet);
   auto command_view = LeCreateConnectionView::Create(le_connection_management_command_view);
   ASSERT_TRUE(command_view.IsValid());
-  EXPECT_EQ(command_view.GetPeerAddress(), remote);
+  if (use_connect_list_) {
+    ASSERT_EQ(command_view.GetPeerAddress(), hci::Address::kEmpty);
+  } else {
+    ASSERT_EQ(command_view.GetPeerAddress(), remote);
+  }
   EXPECT_EQ(command_view.GetPeerAddressType(), AddressType::PUBLIC_DEVICE_ADDRESS);
 
   test_hci_layer_->IncomingEvent(LeCreateConnectionStatusBuilder::Create(ErrorCode::SUCCESS, 0x01));