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

Commit 12ed7436 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski Committed by Gerrit Code Review
Browse files

Merge changes I5390fd9d,I6d31a0c0,Ie0227c16,I8eee1f86,I09efc499 into main

* changes:
  has_client: Disconnect profile when link key is not found
  leaudio: Disconnect profile when link key is not found
  vc: Disconnect profile when link key is not found
  csis: Disconnect profile when link key is not found
  btm: Fix result when Link Key is missing
parents eb55cc18 6775832c
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -1950,7 +1950,15 @@ class CsisClientImpl : public CsisClient {

    int result = BTM_SetEncryption(device->addr, BT_TRANSPORT_LE, nullptr,
                                   nullptr, BTM_BLE_SEC_ENCRYPT);
    LOG_INFO("Encryption required. Request result: 0x%02x", result);

    LOG_INFO("Encryption required for %s. Request result: 0x%02x",
             ADDRESS_TO_LOGGABLE_CSTR(device->addr), result);

    if (result == BTM_ERR_KEY_MISSING) {
      LOG_ERROR("Link key unknown for %s, disconnect profile",
                ADDRESS_TO_LOGGABLE_CSTR(device->addr));
      BTA_GATTC_Close(device->conn_id);
    }
  }

  void OnGattDisconnected(const tBTA_GATTC_CLOSE& evt) {
+23 −0
Original line number Diff line number Diff line
@@ -837,6 +837,29 @@ TEST_F(CsisClientTest, test_search_complete_before_encryption) {
  TestAppUnregister();
}

TEST_F(CsisClientTest, test_disconnect_when_link_key_is_gone) {
  SetSampleDatabaseCsis(1, 1);
  TestAppRegister();
  TestConnect(test_address, false);
  EXPECT_CALL(*callbacks,
              OnConnectionState(test_address, ConnectionState::CONNECTED))
      .Times(0);

  ON_CALL(btm_interface, BTM_IsEncrypted(test_address, _))
      .WillByDefault(DoAll(Return(false)));
  ON_CALL(btm_interface, SetEncryption(test_address, _, _, _, _))
      .WillByDefault(Return(BTM_ERR_KEY_MISSING));

  EXPECT_CALL(gatt_interface, Close(1));

  InjectConnectedEvent(test_address, 1);

  Mock::VerifyAndClearExpectations(&gatt_interface);
  Mock::VerifyAndClearExpectations(callbacks.get());

  TestAppUnregister();
}

TEST_F(CsisClientTest, test_is_group_empty) {
  std::list<std::shared_ptr<CsisGroup>> csis_groups_;
  auto g_1 = std::make_shared<CsisGroup>(666, bluetooth::Uuid::kEmpty);
+9 −1
Original line number Diff line number Diff line
@@ -1888,7 +1888,15 @@ class HasClientImpl : public HasClient {

    int result = BTM_SetEncryption(device->addr, BT_TRANSPORT_LE, nullptr,
                                   nullptr, BTM_BLE_SEC_ENCRYPT);
    LOG_INFO("Encryption required. Request result: 0x%02x", result);

    LOG_INFO("Encryption required for %s. Request result: 0x%02x",
             ADDRESS_TO_LOGGABLE_CSTR(device->addr), result);

    if (result == BTM_ERR_KEY_MISSING) {
      LOG_ERROR("Link key unknown for %s, disconnect profile",
                ADDRESS_TO_LOGGABLE_CSTR(device->addr));
      BTA_GATTC_Close(device->conn_id);
    }
  }

  void OnGattDisconnected(const tBTA_GATTC_CLOSE& evt) {
+27 −0
Original line number Diff line number Diff line
@@ -892,6 +892,9 @@ class HasClientTestBase : public ::testing::Test {

    ON_CALL(btm_interface, BTM_IsEncrypted(address, _))
        .WillByDefault(DoAll(Return(encryption_result)));

    ON_CALL(btm_interface, IsLinkKeyKnown(address, _))
        .WillByDefault(DoAll(Return(true)));
  }

  void InjectNotifyReadPresetResponse(uint16_t conn_id,
@@ -1323,6 +1326,30 @@ TEST_F(HasClientTest, test_service_discovery_complete_before_encryption) {
  Mock::VerifyAndClearExpectations(callbacks.get());
}

TEST_F(HasClientTest, test_disconnect_when_link_key_is_gone) {
  const RawAddress test_address = GetTestAddress(1);
  SetSampleDatabaseHasPresetsNtf(
      test_address, bluetooth::has::kFeatureBitHearingAidTypeBinaural);

  EXPECT_CALL(*callbacks,
              OnConnectionState(ConnectionState::DISCONNECTED, test_address))
      .Times(0);
  EXPECT_CALL(*callbacks,
              OnConnectionState(ConnectionState::CONNECTED, test_address))
      .Times(0);

  ON_CALL(btm_interface, BTM_IsEncrypted(test_address, _))
      .WillByDefault(DoAll(Return(false)));
  ON_CALL(btm_interface, SetEncryption(test_address, _, _, _, _))
      .WillByDefault(Return(BTM_ERR_KEY_MISSING));

  auto test_conn_id = GetTestConnId(test_address);
  EXPECT_CALL(gatt_interface, Close(test_conn_id)).Times(1);
  InjectConnectedEvent(test_address, GetTestConnId(test_address));

  Mock::VerifyAndClearExpectations(callbacks.get());
}

TEST_F(HasClientTest, test_reconnect_after_encryption_failed) {
  const RawAddress test_address = GetTestAddress(1);
  SetSampleDatabaseHasNoPresetChange(
+14 −11
Original line number Diff line number Diff line
@@ -1951,19 +1951,22 @@ class LeAudioClientImpl : public LeAudioClient {
      return;
    }

    if (BTM_IsLinkKeyKnown(address, BT_TRANSPORT_LE)) {
    int result = BTM_SetEncryption(address, BT_TRANSPORT_LE, nullptr, nullptr,
                                   BTM_BLE_SEC_ENCRYPT);

      LOG(INFO) << __func__
                << "Encryption required. Request result: " << result;
      return;
    }
    LOG_INFO("Encryption required for %s. Request result: 0x%02x",
             ADDRESS_TO_LOGGABLE_CSTR(address), result);

    LOG(ERROR) << __func__ << " Encryption error";
    if (result == BTM_ERR_KEY_MISSING) {
      LOG_ERROR("Link key unknown for %s, disconnect profile",
                ADDRESS_TO_LOGGABLE_CSTR(address));
      le_audio::MetricsCollector::Get()->OnConnectionStateChanged(
          leAudioDevice->group_id_, address, ConnectionState::CONNECTED,
          le_audio::ConnectionStatus::FAILED);

      /* If link cannot be enctypted, disconnect profile */
      BTA_GATTC_Close(conn_id);
    }
  }

  void RegisterKnownNotifications(LeAudioDevice* leAudioDevice,
Loading