• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #include "pw_bluetooth_sapphire/internal/host/gap/identity_resolving_list.h"
16 
17 #include "pw_bluetooth_sapphire/internal/host/common/log.h"
18 #include "pw_bluetooth_sapphire/internal/host/sm/util.h"
19 
20 namespace bt::gap {
21 
Add(DeviceAddress identity,const UInt128 & irk)22 void IdentityResolvingList::Add(DeviceAddress identity, const UInt128& irk) {
23   bt_log(DEBUG, "gap", "Adding IRK for identity address %s", bt_str(identity));
24   registry_[identity] = irk;
25 }
26 
Remove(DeviceAddress identity)27 void IdentityResolvingList::Remove(DeviceAddress identity) {
28   bt_log(
29       DEBUG, "gap", "Removing IRK for identity address %s", bt_str(identity));
30   registry_.erase(identity);
31 }
32 
Resolve(DeviceAddress rpa) const33 std::optional<DeviceAddress> IdentityResolvingList::Resolve(
34     DeviceAddress rpa) const {
35   if (!rpa.IsResolvablePrivate()) {
36     return std::nullopt;
37   }
38 
39   for (const auto& [identity, irk] : registry_) {
40     if (sm::util::IrkCanResolveRpa(irk, rpa)) {
41       bt_log(
42           DEBUG, "gap", "RPA %s resolved to %s", bt_str(rpa), bt_str(identity));
43       return identity;
44     }
45   }
46 
47   return std::nullopt;
48 }
49 
50 }  // namespace bt::gap
51