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

Commit dfc15dd9 authored by Rahul Arya's avatar Rahul Arya
Browse files

[Non-Discoverable Mode] Store discoverable bit in security record

Thread it through the advertising manager -> connection manager -> shim
-> legacy security.

Followup CLs will actually do something with this bit.

Bug: 254314964
Test: compiles
Change-Id: I5da4c60ba9a80fb950947be41e5eced7212740af
parent ac962b24
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -309,14 +309,19 @@ void AclManager::WriteDefaultLinkPolicySettings(uint16_t default_link_policy_set
}

void AclManager::OnAdvertisingSetTerminated(
    ErrorCode status, uint16_t conn_handle, uint8_t adv_set_id, hci::AddressWithType adv_address) {
    ErrorCode status,
    uint16_t conn_handle,
    uint8_t adv_set_id,
    hci::AddressWithType adv_address,
    bool is_discoverable) {
  if (status == ErrorCode::SUCCESS) {
    CallOn(
        pimpl_->le_impl_,
        &le_impl::OnAdvertisingSetTerminated,
        conn_handle,
        adv_set_id,
        adv_address);
        adv_address,
        is_discoverable);
  }
}

+5 −1
Original line number Diff line number Diff line
@@ -130,7 +130,11 @@ public:

 // Callback from Advertising Manager to notify the advitiser (local) address
 virtual void OnAdvertisingSetTerminated(
     ErrorCode status, uint16_t conn_handle, uint8_t adv_set_id, hci::AddressWithType adv_address);
     ErrorCode status,
     uint16_t conn_handle,
     uint8_t adv_set_id,
     hci::AddressWithType adv_address,
     bool is_discoverable);

 // In order to avoid circular dependency use setter rather than module dependency.
 virtual void SetSecurityModule(security::SecurityModule* security_module);
+3 −0
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@ struct DataAsPeripheral {
  // the advertising set ID that the peer connected to - in LE, our role is peripheral iff the peer
  // initiated a connection to our advertisement
  std::optional<uint8_t> advertising_set_id;
  // whether the peripheral connected to a discoverable advertisement (this affects the readability
  // of GAP characteristics)
  bool connected_to_discoverable;
};

// when we know it's a peripheral, but we don't yet have all the data about the set it connected to
+9 −3
Original line number Diff line number Diff line
@@ -623,7 +623,10 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    } else {
      // the exception is if we only support legacy advertising - here, our current address is also
      // our advertised address
      return DataAsPeripheral{le_address_manager_->GetCurrentAddress(), {}};
      return DataAsPeripheral{
          le_address_manager_->GetCurrentAddress(),
          {},
          true /* For now, ignore non-discoverable legacy advertising TODO(b/254314964) */};
    }
  }

@@ -745,9 +748,12 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
  }

  void OnAdvertisingSetTerminated(
      uint16_t conn_handle, uint8_t adv_set_id, hci::AddressWithType adv_set_address) {
      uint16_t conn_handle,
      uint8_t adv_set_id,
      hci::AddressWithType adv_set_address,
      bool is_discoverable) {
    auto connection = connections.record_peripheral_data_and_extract_pending_connection(
        conn_handle, DataAsPeripheral{adv_set_address, adv_set_id});
        conn_handle, DataAsPeripheral{adv_set_address, adv_set_id, is_discoverable});

    if (connection != nullptr) {
      le_client_handler_->Post(common::BindOnce(
+53 −1
Original line number Diff line number Diff line
@@ -1596,7 +1596,7 @@ TEST_P(

  check.Call("terminating_advertising_set");
  le_impl_->OnAdvertisingSetTerminated(
      kHciHandle, advertising_set_id, advertiser_address_with_type);
      kHciHandle, advertising_set_id, advertiser_address_with_type, false /* is_discoverable */);
  sync_handler();

  // assert
@@ -1615,6 +1615,58 @@ INSTANTIATE_TEST_SUITE_P(
        ConnectionCompleteType::CONNECTION_COMPLETE,
        ConnectionCompleteType::ENHANCED_CONNECTION_COMPLETE));

class LeImplTestParameterizedByDiscoverability : public LeImplTest,
                                                 public ::testing::WithParamInterface<bool> {};

TEST_P(LeImplTestParameterizedByDiscoverability, ConnectionCompleteAsDiscoverable) {
  // arrange
  controller_->AddSupported(hci::OpCode::LE_MULTI_ADVT);
  set_random_device_address_policy();
  auto is_discoverable = GetParam();

  // expect
  std::unique_ptr<LeAclConnection> connection{};
  EXPECT_CALL(
      mock_le_connection_callbacks_, OnLeConnectSuccess(remote_public_address_with_type_, _))
      .WillOnce(WithArg<1>(::testing::Invoke(
          [&](std::unique_ptr<LeAclConnection> conn) { connection = std::move(conn); })));

  // act
  hci_layer_->IncomingLeMetaEvent(LeConnectionCompleteBuilder::Create(
      ErrorCode::SUCCESS,
      kHciHandle,
      Role::PERIPHERAL,
      AddressType::PUBLIC_DEVICE_ADDRESS,
      remote_address_,
      0x0024,
      0x0000,
      0x0011,
      ClockAccuracy::PPM_30));
  // the sync is needed since otherwise the OnAdvertisingSetTerminated() event arrives first, due to
  // handler indirection (2 hops vs 1 hop) this isn't a bug in production since there we'd have:
  // 1. Connection Complete: HCI -> LE_IMPL (2 hops)
  // 2. Advertising Set Terminated: HCI -> ADV -> LE_IMPL (3 hops)
  // so this sync is only needed in test
  sync_handler();
  le_impl_->OnAdvertisingSetTerminated(
      kHciHandle, 1 /* advertiser_set_id */, fixed_address_, is_discoverable);
  sync_handler();

  // assert
  ASSERT_NE(connection, nullptr);
  EXPECT_THAT(
      connection->GetRoleSpecificData(),
      VariantWith<DataAsPeripheral>(Field(
          "connected_to_discoverable",
          &DataAsPeripheral::connected_to_discoverable,
          Eq(is_discoverable))));
}

INSTANTIATE_TEST_SUITE_P(
    LeImplTestParameterizedByDiscoverability,
    LeImplTestParameterizedByDiscoverability,
    ::testing::Values(false, true));

}  // namespace acl_manager
}  // namespace hci
}  // namespace bluetooth
Loading