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

Commit bdcea72e authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

csis: Disconnect profile when link key is not found

Bug: 312691809
Test: atest bluetooth_csis_test
Tag: #feature
Change-Id: I8eee1f86e37e0f4285aba5ec51f605cb189e3e46
parent 69a7a71a
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);