[bt] Restore device name from bonding data
Saves name from previously bonded device in the device cache.
BT-751 #done
Test:
Connected and bonded device to astro, noted name, rebooted and name
persisted. Ensured that this was not the case before changes were
made.
bt-host-unit-tests: Modified peer_cache_unittest to test low-level persistence of new field.
bt-integration-tests: Added high-level test in bonding.rs to test that name is persisted,
ensured that it failed before changes and passed with the changes.
Change-Id: Ia80434bab6bef8b21495dfe5010bfbdd561cd3af
diff --git a/src/connectivity/bluetooth/core/bt-host/fidl/host_server.cc b/src/connectivity/bluetooth/core/bt-host/fidl/host_server.cc
index b59043c..e1b517e 100644
--- a/src/connectivity/bluetooth/core/bt-host/fidl/host_server.cc
+++ b/src/connectivity/bluetooth/core/bt-host/fidl/host_server.cc
@@ -12,6 +12,7 @@
#include "profile_server.h"
#include "src/connectivity/bluetooth/core/bt-host/common/log.h"
#include "src/connectivity/bluetooth/core/bt-host/gap/adapter.h"
+#include "src/connectivity/bluetooth/core/bt-host/gap/bonding_data.h"
#include "src/connectivity/bluetooth/core/bt-host/gap/bredr_connection_manager.h"
#include "src/connectivity/bluetooth/core/bt-host/gap/bredr_discovery_manager.h"
#include "src/connectivity/bluetooth/core/bt-host/gap/gap.h"
@@ -284,6 +285,11 @@
continue;
}
+ std::optional<std::string> peer_name;
+ if (bond.name) {
+ peer_name = std::move(bond.name);
+ }
+
bt::DeviceAddress address;
bt::sm::PairingData le_bond_data;
if (bond.le) {
@@ -320,8 +326,9 @@
// TODO(armansito): BondingData should contain the identity address for both
// transports instead of storing them separately. For now use the one we
// obtained from |bond.le|.
- if (!adapter()->AddBondedPeer(*peer_id, address, le_bond_data,
- bredr_link_key)) {
+ if (!adapter()->AddBondedPeer(bt::gap::BondingData{*peer_id, address,
+ peer_name, le_bond_data,
+ bredr_link_key})){
failed_ids.push_back(bond.identifier);
continue;
}
diff --git a/src/connectivity/bluetooth/core/bt-host/gap/adapter.cc b/src/connectivity/bluetooth/core/bt-host/gap/adapter.cc
index b6dd6d7..cfcfe72 100644
--- a/src/connectivity/bluetooth/core/bt-host/gap/adapter.cc
+++ b/src/connectivity/bluetooth/core/bt-host/gap/adapter.cc
@@ -192,11 +192,8 @@
CleanUp();
}
-bool Adapter::AddBondedPeer(PeerId identifier, const DeviceAddress& address,
- const sm::PairingData& le_bond_data,
- const std::optional<sm::LTK>& link_key) {
- return peer_cache()->AddBondedPeer(identifier, address, le_bond_data,
- link_key);
+bool Adapter::AddBondedPeer(BondingData bonding_data) {
+ return peer_cache()->AddBondedPeer(bonding_data);
}
void Adapter::SetPairingDelegate(fxl::WeakPtr<PairingDelegate> delegate) {
diff --git a/src/connectivity/bluetooth/core/bt-host/gap/adapter.h b/src/connectivity/bluetooth/core/bt-host/gap/adapter.h
index 9bcb469..099c828 100644
--- a/src/connectivity/bluetooth/core/bt-host/gap/adapter.h
+++ b/src/connectivity/bluetooth/core/bt-host/gap/adapter.h
@@ -16,6 +16,7 @@
#include "src/connectivity/bluetooth/core/bt-host/common/identifier.h"
#include "src/connectivity/bluetooth/core/bt-host/data/domain.h"
#include "src/connectivity/bluetooth/core/bt-host/gap/adapter_state.h"
+#include "src/connectivity/bluetooth/core/bt-host/gap/bonding_data.h"
#include "src/connectivity/bluetooth/core/bt-host/gap/low_energy_connection_manager.h"
#include "src/connectivity/bluetooth/core/bt-host/gap/peer_cache.h"
#include "src/connectivity/bluetooth/core/bt-host/gatt/gatt.h"
@@ -152,9 +153,7 @@
// Add a previously bonded device to the peer cache and set it up for
// auto-connect procedures.
- bool AddBondedPeer(PeerId identifier, const DeviceAddress& address,
- const sm::PairingData& le_bond_data,
- const std::optional<sm::LTK>& link_key);
+ bool AddBondedPeer(BondingData bonding_data);
// Assigns a pairing delegate to this adapter. This PairingDelegate and its
// I/O capabilities will be used for all future pairing procedures. Setting a
diff --git a/src/connectivity/bluetooth/core/bt-host/gap/adapter_unittest.cc b/src/connectivity/bluetooth/core/bt-host/gap/adapter_unittest.cc
index de85b08..9b64ad7 100644
--- a/src/connectivity/bluetooth/core/bt-host/gap/adapter_unittest.cc
+++ b/src/connectivity/bluetooth/core/bt-host/gap/adapter_unittest.cc
@@ -308,7 +308,8 @@
// Mark the peer as bonded and advance the scan period.
sm::PairingData pdata;
pdata.ltk = sm::LTK();
- adapter()->peer_cache()->AddBondedPeer(kPeerId, kTestAddr, pdata, {});
+ adapter()->peer_cache()->AddBondedPeer(BondingData{kPeerId, kTestAddr, {},
+ pdata, {}});
EXPECT_EQ(1u, adapter()->peer_cache()->count());
RunLoopFor(kTestScanPeriod);
diff --git a/src/connectivity/bluetooth/core/bt-host/gap/bonding_data.h b/src/connectivity/bluetooth/core/bt-host/gap/bonding_data.h
new file mode 100644
index 0000000..8c234e9
--- /dev/null
+++ b/src/connectivity/bluetooth/core/bt-host/gap/bonding_data.h
@@ -0,0 +1,27 @@
+// Copyright 2019 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SRC_CONNECTIVITY_BLUETOOTH_CORE_BT_HOST_GAP_BONDING_DATA_H_
+#define SRC_CONNECTIVITY_BLUETOOTH_CORE_BT_HOST_GAP_BONDING_DATA_H_
+
+#include "src/connectivity/bluetooth/core/bt-host/gap/peer.h"
+#include "src/connectivity/bluetooth/core/bt-host/sm/types.h"
+
+namespace bt {
+namespace gap {
+
+// A |BondingData| struct can be passed to the peer cache and allows for
+// flexibility in adding new fields to cache.
+struct BondingData {
+ PeerId identifier;
+ DeviceAddress address;
+ std::optional<std::string> name;
+ sm::PairingData le_pairing_data;
+ std::optional<sm::LTK> bredr_link_key;
+};
+
+} // namespace gap
+} // namespace bt
+
+#endif // SRC_CONNECTIVITY_BLUETOOTH_CORE_BT_HOST_GAP_BONDING_DATA_H_
diff --git a/src/connectivity/bluetooth/core/bt-host/gap/bredr_connection_manager_unittest.cc b/src/connectivity/bluetooth/core/bt-host/gap/bredr_connection_manager_unittest.cc
index 6f96ade..2efd91f 100644
--- a/src/connectivity/bluetooth/core/bt-host/gap/bredr_connection_manager_unittest.cc
+++ b/src/connectivity/bluetooth/core/bt-host/gap/bredr_connection_manager_unittest.cc
@@ -825,7 +825,8 @@
// Test: replies to Link Key Requests for bonded peer
TEST_F(GAP_BrEdrConnectionManagerTest, RecallLinkKeyForBondedPeer) {
ASSERT_TRUE(
- peer_cache()->AddBondedPeer(PeerId(999), kTestDevAddr, {}, kLinkKey));
+ peer_cache()->AddBondedPeer(BondingData{PeerId(999), kTestDevAddr, {},
+ {}, kLinkKey}));
auto* peer = peer_cache()->FindByAddress(kTestDevAddr);
ASSERT_TRUE(peer);
ASSERT_FALSE(peer->connected());
diff --git a/src/connectivity/bluetooth/core/bt-host/gap/low_energy_discovery_manager_unittest.cc b/src/connectivity/bluetooth/core/bt-host/gap/low_energy_discovery_manager_unittest.cc
index d4c7f6a..b195421 100644
--- a/src/connectivity/bluetooth/core/bt-host/gap/low_energy_discovery_manager_unittest.cc
+++ b/src/connectivity/bluetooth/core/bt-host/gap/low_energy_discovery_manager_unittest.cc
@@ -830,7 +830,7 @@
constexpr PeerId kPeerId(1);
sm::PairingData pdata;
pdata.ltk = sm::LTK();
- peer_cache()->AddBondedPeer(kPeerId, kAddress0, pdata, {});
+ peer_cache()->AddBondedPeer(BondingData{kPeerId, kAddress0, {}, pdata, {}});
EXPECT_EQ(1u, peer_cache()->count());
// Advance to the next scan period. We should receive a new notification.
@@ -1042,8 +1042,10 @@
// expect advertisements from all other devices to get ignored.
sm::PairingData pdata;
pdata.ltk = sm::LTK();
- peer_cache()->AddBondedPeer(kBondedPeerId1, kAddress0, pdata, {});
- peer_cache()->AddBondedPeer(kBondedPeerId2, kAddress4, pdata, {});
+ peer_cache()->AddBondedPeer(BondingData{kBondedPeerId1, kAddress0, {}, pdata,
+ {}});
+ peer_cache()->AddBondedPeer(BondingData{kBondedPeerId2, kAddress4, {}, pdata,
+ {}});
EXPECT_EQ(2u, peer_cache()->count());
int count = 0;
diff --git a/src/connectivity/bluetooth/core/bt-host/gap/peer_cache.cc b/src/connectivity/bluetooth/core/bt-host/gap/peer_cache.cc
index 17478d5..f4830b8 100644
--- a/src/connectivity/bluetooth/core/bt-host/gap/peer_cache.cc
+++ b/src/connectivity/bluetooth/core/bt-host/gap/peer_cache.cc
@@ -49,31 +49,31 @@
}
}
-bool PeerCache::AddBondedPeer(PeerId identifier, const DeviceAddress& address,
- const sm::PairingData& bond_data,
- const std::optional<sm::LTK>& link_key) {
+bool PeerCache::AddBondedPeer(BondingData bd) {
ZX_DEBUG_ASSERT(thread_checker_.IsCreationThreadCurrent());
- ZX_DEBUG_ASSERT(!bond_data.identity_address ||
- address.value() == bond_data.identity_address->value());
- ZX_DEBUG_ASSERT(address.type() != DeviceAddress::Type::kLEAnonymous);
+ ZX_DEBUG_ASSERT(!bd.le_pairing_data.identity_address ||
+ bd.address.value() == bd.le_pairing_data.identity_address->value());
+ ZX_DEBUG_ASSERT(bd.address.type() !=
+ DeviceAddress::Type::kLEAnonymous);
- const bool bond_le = bond_data.ltk || bond_data.csrk;
- const bool bond_bredr = link_key.has_value();
+ const bool bond_le = bd.le_pairing_data.ltk || bd.le_pairing_data.csrk;
+ const bool bond_bredr = bd.bredr_link_key.has_value();
- // |bond_data| must contain either a LTK or CSRK for LE Security Mode 1 or 2.
- if (address.IsLowEnergy() && !bond_le) {
+ // |bd.le_pairing_data| must contain either a LTK or CSRK for LE
+ // Security Mode 1 or 2.
+ if (bd.address.IsLowEnergy() && !bond_le) {
bt_log(ERROR, "gap-le", "mandatory keys missing: no LTK or CSRK (id: %s)",
- bt_str(identifier));
+ bt_str(bd.identifier));
return false;
}
- if (address.IsBrEdr() && !bond_bredr) {
+ if (bd.address.IsBrEdr() && !bond_bredr) {
bt_log(ERROR, "gap-bredr", "mandatory link key missing (id: %s)",
- bt_str(identifier));
+ bt_str(bd.identifier));
return false;
}
- auto* peer = InsertPeerRecord(identifier, address, true);
+ auto* peer = InsertPeerRecord(bd.identifier, bd.address, true);
if (!peer) {
return false;
}
@@ -81,29 +81,33 @@
// A bonded peer must have its identity known.
peer->set_identity_known(true);
+ if (bd.name.has_value()) {
+ peer->SetName(bd.name.value());
+ }
+
if (bond_le) {
- peer->MutLe().SetBondData(bond_data);
+ peer->MutLe().SetBondData(bd.le_pairing_data);
ZX_DEBUG_ASSERT(peer->le()->bonded());
// Add the peer to the resolving list if it has an IRK.
- if (bond_data.irk) {
- le_resolving_list_.Add(peer->address(), bond_data.irk->value());
+ if (bd.le_pairing_data.irk) {
+ le_resolving_list_.Add(peer->address(), bd.le_pairing_data.irk->value());
}
}
if (bond_bredr) {
- peer->MutBrEdr().SetBondData(*link_key);
+ peer->MutBrEdr().SetBondData(*bd.bredr_link_key);
ZX_DEBUG_ASSERT(peer->bredr()->bonded());
}
if (peer->technology() == TechnologyType::kDualMode) {
- address_map_[GetAliasAddress(address)] = identifier;
+ address_map_[GetAliasAddress(bd.address)] = bd.identifier;
}
ZX_DEBUG_ASSERT(!peer->temporary());
ZX_DEBUG_ASSERT(peer->bonded());
- bt_log(SPEW, "gap", "restored bonded peer: %s, id: %s", bt_str(address),
- bt_str(identifier));
+ bt_log(SPEW, "gap", "restored bonded peer: %s, id: %s",
+ bt_str(bd.address), bt_str(bd.identifier));
// Don't call UpdateExpiry(). Since a bonded peer starts out as
// non-temporary it is not necessary to ever set up the expiration callback.
diff --git a/src/connectivity/bluetooth/core/bt-host/gap/peer_cache.h b/src/connectivity/bluetooth/core/bt-host/gap/peer_cache.h
index 7698575..f2e096b 100644
--- a/src/connectivity/bluetooth/core/bt-host/gap/peer_cache.h
+++ b/src/connectivity/bluetooth/core/bt-host/gap/peer_cache.h
@@ -12,6 +12,7 @@
#include <unordered_map>
#include "src/connectivity/bluetooth/core/bt-host/common/device_address.h"
+#include "src/connectivity/bluetooth/core/bt-host/gap/bonding_data.h"
#include "src/connectivity/bluetooth/core/bt-host/gap/identity_resolving_list.h"
#include "src/connectivity/bluetooth/core/bt-host/gap/peer.h"
#include "src/connectivity/bluetooth/core/bt-host/hci/connection.h"
@@ -54,24 +55,22 @@
// Peer objects.
void ForEach(PeerCallback f);
- // Creates a new non-temporary peer entry using the given |identifier| and
- // identity |address|. This is intended to initialize this PeerCache
+ // Creates a new non-temporary peer entry using the given |bd.identifier| and
+ // identity |bd.address|. This is intended to initialize this PeerCache
// with previously bonded peers while bootstrapping a bt-host peer. The
// "peer bonded" callback will not be invoked.
//
// This method is not intended for updating the bonding data of a peer that
- // already exists the cache and returns false if a mapping for |identifier| or
- // |address| is already present. Use Store*Bond() methods to update pairing
- // information of an existing peer.
+ // already exists the cache and returns false if a mapping for
+ // |bd. identifier| or |bd.address| is already present. Use Store*Bond()
+ // methods to update pairing information of an existing peer.
//
// If a peer already exists that has the same public identity address with a
// different technology, this method will return false. The existing peer
// should be instead updated with new bond information to create a dual-mode
// peer.
//
- bool AddBondedPeer(PeerId identifier, const DeviceAddress& address,
- const sm::PairingData& bond_data,
- const std::optional<sm::LTK>& link_key);
+ bool AddBondedPeer(BondingData bd);
// Update the peer with the given identifier with new LE bonding
// information. The peer will be considered "bonded" and the bonded callback
diff --git a/src/connectivity/bluetooth/core/bt-host/gap/peer_cache_unittest.cc b/src/connectivity/bluetooth/core/bt-host/gap/peer_cache_unittest.cc
index a9524e3..66ea112 100644
--- a/src/connectivity/bluetooth/core/bt-host/gap/peer_cache_unittest.cc
+++ b/src/connectivity/bluetooth/core/bt-host/gap/peer_cache_unittest.cc
@@ -43,6 +43,10 @@
const DeviceAddress kAddrLeAnon(DeviceAddress::Type::kLEAnonymous,
"06:05:04:03:02:01");
+// Arbitrary name value used by the bonding tests below. The actual value of
+// this constant does not effect the test logic.
+const std::string kName = "TestName";
+
const auto kAdvData =
CreateStaticByteBuffer(0x05, // Length
0x09, // AD type: Complete Local Name
@@ -378,14 +382,16 @@
sm::PairingData data;
data.ltk = kLTK;
EXPECT_FALSE(
- cache()->AddBondedPeer(peer()->identifier(), kAddrLeRandom, data, {}));
+ cache()->AddBondedPeer(BondingData{peer()->identifier(), kAddrLeRandom, {},
+ data, {}}));
EXPECT_FALSE(bonded_callback_called());
}
TEST_F(GAP_PeerCacheTest_BondingTest, AddBondedPeerFailsWithExistingAddress) {
sm::PairingData data;
data.ltk = kLTK;
- EXPECT_FALSE(cache()->AddBondedPeer(kId, peer()->address(), data, {}));
+ EXPECT_FALSE(
+ cache()->AddBondedPeer(BondingData{kId, peer()->address(), {}, data, {}}));
EXPECT_FALSE(bonded_callback_called());
}
@@ -394,22 +400,26 @@
EXPECT_TRUE(NewPeer(kAddrBrEdr, true));
sm::PairingData data;
data.ltk = kLTK;
- EXPECT_FALSE(cache()->AddBondedPeer(kId, kAddrLeAlias, data, {}));
+ EXPECT_FALSE(
+ cache()->AddBondedPeer(BondingData{kId, kAddrLeAlias, {}, data, {}}));
EXPECT_FALSE(bonded_callback_called());
}
TEST_F(GAP_PeerCacheTest_BondingTest,
AddBondedBrEdrPeerFailsWithExistingLowEnergyAliasAddress) {
EXPECT_TRUE(NewPeer(kAddrLeAlias, true));
- EXPECT_FALSE(cache()->AddBondedPeer(kId, kAddrBrEdr, {}, kBrEdrKey));
+ EXPECT_FALSE(
+ cache()->AddBondedPeer(BondingData{kId, kAddrBrEdr, {}, {}, kBrEdrKey}));
EXPECT_FALSE(bonded_callback_called());
}
TEST_F(GAP_PeerCacheTest_BondingTest, AddBondedPeerFailsWithoutMandatoryKeys) {
sm::PairingData data;
- EXPECT_FALSE(cache()->AddBondedPeer(kId, kAddrLeAlias, data, kBrEdrKey));
+ EXPECT_FALSE(
+ cache()->AddBondedPeer(BondingData{kId, kAddrLeAlias, {}, data, kBrEdrKey}));
data.ltk = kLTK;
- EXPECT_FALSE(cache()->AddBondedPeer(kId, kAddrBrEdr, data, {}));
+ EXPECT_FALSE(
+ cache()->AddBondedPeer(BondingData{kId, kAddrBrEdr, {}, data, {}}));
EXPECT_FALSE(bonded_callback_called());
}
@@ -417,12 +427,14 @@
sm::PairingData data;
data.ltk = kLTK;
- EXPECT_TRUE(cache()->AddBondedPeer(kId, kAddrLeRandom, data, {}));
+ EXPECT_TRUE(
+ cache()->AddBondedPeer(BondingData{kId, kAddrLeRandom, kName, data, {}}));
auto* peer = cache()->FindById(kId);
ASSERT_TRUE(peer);
EXPECT_EQ(peer, cache()->FindByAddress(kAddrLeRandom));
EXPECT_EQ(kId, peer->identifier());
EXPECT_EQ(kAddrLeRandom, peer->address());
+ EXPECT_EQ(kName, peer->name());
EXPECT_TRUE(peer->identity_known());
ASSERT_TRUE(peer->le());
EXPECT_TRUE(peer->le()->bonded());
@@ -440,12 +452,14 @@
PeerId kId(5);
sm::PairingData data;
- EXPECT_TRUE(cache()->AddBondedPeer(kId, kAddrBrEdr, data, kBrEdrKey));
+ EXPECT_TRUE(
+ cache()->AddBondedPeer(BondingData{kId, kAddrBrEdr, {}, data, kBrEdrKey}));
auto* peer = cache()->FindById(kId);
ASSERT_TRUE(peer);
EXPECT_EQ(peer, cache()->FindByAddress(kAddrBrEdr));
EXPECT_EQ(kId, peer->identifier());
EXPECT_EQ(kAddrBrEdr, peer->address());
+ ASSERT_FALSE(peer->name());
EXPECT_TRUE(peer->identity_known());
ASSERT_TRUE(peer->bredr());
EXPECT_TRUE(peer->bredr()->bonded());
@@ -465,7 +479,8 @@
data.ltk = kLTK;
data.irk = sm::Key(sm::SecurityProperties(), RandomUInt128());
- EXPECT_TRUE(cache()->AddBondedPeer(kId, kAddrLeRandom, data, {}));
+ EXPECT_TRUE(
+ cache()->AddBondedPeer(BondingData{kId, kAddrLeRandom, {}, data, {}}));
auto* peer = cache()->FindByAddress(kAddrLeRandom);
ASSERT_TRUE(peer);
EXPECT_EQ(kAddrLeRandom, peer->address());
@@ -772,13 +787,15 @@
data.ltk = kLTK;
const DeviceAddress& address = GetParam();
- EXPECT_TRUE(cache()->AddBondedPeer(kId, address, data, kBrEdrKey));
+ EXPECT_TRUE(
+ cache()->AddBondedPeer(BondingData{kId, address, kName, data, kBrEdrKey}));
auto* peer = cache()->FindById(kId);
ASSERT_TRUE(peer);
EXPECT_EQ(peer, cache()->FindByAddress(kAddrLeAlias));
EXPECT_EQ(peer, cache()->FindByAddress(kAddrBrEdr));
EXPECT_EQ(kId, peer->identifier());
EXPECT_EQ(address, peer->address());
+ EXPECT_EQ(kName, peer->name());
EXPECT_TRUE(peer->identity_known());
EXPECT_TRUE(peer->bonded());
ASSERT_TRUE(peer->le());
@@ -802,7 +819,8 @@
data.ltk = kLTK;
const DeviceAddress& address = GetParam();
- EXPECT_TRUE(cache()->AddBondedPeer(kId, address, data, kBrEdrKey));
+ EXPECT_TRUE(
+ cache()->AddBondedPeer(BondingData{kId, address, {}, data, kBrEdrKey}));
auto* peer = cache()->FindById(kId);
ASSERT_TRUE(peer);
ASSERT_TRUE(peer->bonded());
diff --git a/src/connectivity/bluetooth/tests/integration/src/tests/bonding.rs b/src/connectivity/bluetooth/tests/integration/src/tests/bonding.rs
index 947b888..4191959 100644
--- a/src/connectivity/bluetooth/tests/integration/src/tests/bonding.rs
+++ b/src/connectivity/bluetooth/tests/integration/src/tests/bonding.rs
@@ -17,11 +17,11 @@
// TODO(armansito|xow): Add tests for BR/EDR and dual mode bond data.
-fn new_le_bond_data(id: &str, address: &str, has_ltk: bool) -> BondingData {
+fn new_le_bond_data(id: &str, address: &str, name: &str, has_ltk: bool) -> BondingData {
BondingData {
identifier: id.to_string(),
local_address: "AA:BB:CC:DD:EE:FF".to_string(),
- name: None,
+ name: Some(name.to_string()),
le: Some(Box::new(LeData {
address: address.to_string(),
address_type: AddressType::LeRandom,
@@ -62,6 +62,8 @@
const TEST_ID2: &str = "2345";
const TEST_ADDR1: &str = "01:02:03:04:05:06";
const TEST_ADDR2: &str = "06:05:04:03:02:01";
+const TEST_NAME1: &str = "Name1";
+const TEST_NAME2: &str = "Name2";
// Tests initializing bonded LE devices.
pub async fn test_add_bonded_devices_success(test_state: HostDriverHarness) -> Result<(), Error> {
@@ -69,8 +71,8 @@
let devices = await!(test_state.host_proxy().list_devices())?;
expect_eq!(vec![], devices)?;
- let bond_data1 = new_le_bond_data(TEST_ID1, TEST_ADDR1, true /* has LTK */);
- let bond_data2 = new_le_bond_data(TEST_ID2, TEST_ADDR2, true /* has LTK */);
+ let bond_data1 = new_le_bond_data(TEST_ID1, TEST_ADDR1, TEST_NAME1, true /* has LTK */);
+ let bond_data2 = new_le_bond_data(TEST_ID2, TEST_ADDR2, TEST_NAME2, true /* has LTK */);
let status = await!(add_bonds(&test_state, vec![bond_data1, bond_data2]))?;
expect_true!(status.error.is_none())?;
@@ -91,6 +93,9 @@
expect_true!(devices.iter().any(|dev| dev.address == TEST_ADDR1))?;
expect_true!(devices.iter().any(|dev| dev.address == TEST_ADDR2))?;
+ expect_true!(devices.iter().any(|dev| dev.name == Some(TEST_NAME1.to_string())))?;
+ expect_true!(devices.iter().any(|dev| dev.name == Some(TEST_NAME2.to_string())))?;
+
Ok(())
}
@@ -102,7 +107,7 @@
expect_eq!(vec![], devices)?;
// Inserting a bonded device without a LTK should fail.
- let bond_data = new_le_bond_data(TEST_ID1, TEST_ADDR1, false /* no LTK */);
+ let bond_data = new_le_bond_data(TEST_ID1, TEST_ADDR1, TEST_NAME1, false /* no LTK */);
let status = await!(add_bonds(&test_state, vec![bond_data]))?;
expect_true!(status.error.is_some())?;
@@ -120,7 +125,7 @@
expect_eq!(vec![], devices)?;
// Initialize one entry.
- let bond_data = new_le_bond_data(TEST_ID1, TEST_ADDR1, true /* with LTK */);
+ let bond_data = new_le_bond_data(TEST_ID1, TEST_ADDR1, TEST_NAME1, true /* with LTK */);
let status = await!(add_bonds(&test_state, vec![bond_data]))?;
expect_true!(status.error.is_none())?;
@@ -134,12 +139,12 @@
expect_eq!(1, devices.len())?;
// Adding an entry with the existing id should fail.
- let bond_data = new_le_bond_data(TEST_ID1, TEST_ADDR2, true /* with LTK */);
+ let bond_data = new_le_bond_data(TEST_ID1, TEST_ADDR2, TEST_NAME2, true /* with LTK */);
let status = await!(add_bonds(&test_state, vec![bond_data]))?;
expect_true!(status.error.is_some())?;
// Adding an entry with a different ID but existing address should fail.
- let bond_data = new_le_bond_data(TEST_ID2, TEST_ADDR1, true /* with LTK */);
+ let bond_data = new_le_bond_data(TEST_ID2, TEST_ADDR1, TEST_NAME1, true /* with LTK */);
let status = await!(add_bonds(&test_state, vec![bond_data]))?;
expect_true!(status.error.is_some())?;
@@ -157,8 +162,8 @@
// Add one entry with no LTK (invalid) and one with (valid). This should create an entry for the
// valid device but report an error for the invalid entry.
- let no_ltk = new_le_bond_data(TEST_ID1, TEST_ADDR1, false);
- let with_ltk = new_le_bond_data(TEST_ID2, TEST_ADDR2, true);
+ let no_ltk = new_le_bond_data(TEST_ID1, TEST_ADDR1, TEST_NAME1, false);
+ let with_ltk = new_le_bond_data(TEST_ID2, TEST_ADDR2, TEST_NAME2, true);
let status = await!(add_bonds(&test_state, vec![no_ltk, with_ltk]))?;
expect_true!(status.error.is_some())?;