xref: /aosp_15_r20/external/pigweed/pw_bluetooth/public/pw_bluetooth/low_energy/bond_data2.h (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2024 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 #pragma once
15 
16 #include <array>
17 #include <cstdint>
18 #include <optional>
19 
20 #include "pw_bluetooth/low_energy/connection2.h"
21 #include "pw_bluetooth/types.h"
22 #include "pw_containers/vector.h"
23 
24 namespace pw::bluetooth::low_energy {
25 
26 // A 128-bit secret key.
27 using Key = std::array<uint8_t, 16>;
28 
29 /// Represents a LE Long-Term peer key used for link encryption. The `ediv` and
30 /// `rand` fields are zero if distributed using LE Secure Connections pairing.
31 struct LongTermKey {
32   Key key;
33   uint16_t ediv;
34   uint16_t rand;
35 };
36 
37 struct BondData {
38   // The identifier that uniquely identifies this peer.
39   PeerId peer_id;
40 
41   // The local Bluetooth identity address that this bond is associated with.
42   Address local_address;
43 
44   std::optional<DeviceName> name;
45 
46   // The identity address of the peer.
47   Address peer_address;
48 
49   // The peer's preferred connection parameters, if known.
50   std::optional<Connection2::RequestedConnectionParameters>
51       connection_parameters;
52 
53   // Identity Resolving RemoteKey used to generate and resolve random addresses.
54   Key identity_resolving_remote_key;
55 
56   // Connection Signature Resolving RemoteKey used for data signing without
57   // encryption.
58   Key connection_signature_resolving_remote_key;
59 
60   // LE long-term key used to encrypt a connection when the peer is in the LE
61   // Peripheral role.
62   //
63   // In legacy pairing (`peer_long_term_key.security.secure_connections` is
64   // false),  this key corresponds to the key distributed by the peer. In Secure
65   // Connections pairing there is only one LTK and `peer_long_term_key` is the
66   // same as `local_long_term_key`.
67   LongTermKey peer_long_term_key;
68 
69   // LE long-term key used to encrypt a connection when the peer is in the LE
70   // Central role.
71   //
72   // In legacy pairing (`local_long_term_key.security.secure_connections` is
73   // false), this key corresponds to the key distributed by the local device.
74   // In Secure Connections pairing there is only one LTK and
75   // `local_long_term_key` is the same as `peer_long_term_key`.
76   LongTermKey local_long_term_key;
77 };
78 
79 }  // namespace pw::bluetooth::low_energy
80