blob: 077f595ff4559df248fe7d23bcba3bd3f05fce99 [file] [log] [blame]
// Copyright 2018 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.
#include "src/connectivity/bluetooth/core/bt-host/public/pw_bluetooth_sapphire/internal/host/gap/identity_resolving_list.h"
#include "src/connectivity/bluetooth/core/bt-host/public/pw_bluetooth_sapphire/internal/host/common/log.h"
#include "src/connectivity/bluetooth/core/bt-host/public/pw_bluetooth_sapphire/internal/host/sm/util.h"
namespace bt::gap {
void IdentityResolvingList::Add(DeviceAddress identity, const UInt128& irk) {
bt_log(DEBUG, "gap", "Adding IRK for identity address %s", bt_str(identity));
registry_[identity] = irk;
}
void IdentityResolvingList::Remove(DeviceAddress identity) {
bt_log(
DEBUG, "gap", "Removing IRK for identity address %s", bt_str(identity));
registry_.erase(identity);
}
std::optional<DeviceAddress> IdentityResolvingList::Resolve(
DeviceAddress rpa) const {
if (!rpa.IsResolvablePrivate()) {
return std::nullopt;
}
for (const auto& [identity, irk] : registry_) {
if (sm::util::IrkCanResolveRpa(irk, rpa)) {
bt_log(
DEBUG, "gap", "RPA %s resolved to %s", bt_str(rpa), bt_str(identity));
return identity;
}
}
return std::nullopt;
}
} // namespace bt::gap