1 // Copyright 2022 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/connection.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 encyrption. 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<RequestedConnectionParameters> connection_parameters; 51 52 // Identity Resolving RemoteKey used to generate and resolve random addresses. 53 Key identity_resolving_remote_key; 54 55 // Connection Signature Resolving RemoteKey used for data signing without 56 // encryption. 57 Key connection_signature_resolving_remote_key; 58 59 // LE long-term key used to encrypt a connection when the peer is in the LE 60 // Peripheral role. 61 // 62 // In legacy pairing (`peer_long_term_key.security.secure_connections` is 63 // false), this key corresponds to the key distributed by the peer. In Secure 64 // Connections pairing there is only one LTK and `peer_long_term_key` is the 65 // same as `local_long_term_key`. 66 LongTermKey peer_long_term_key; 67 68 // LE long-term key used to encrypt a connection when the peer is in the LE 69 // Central role. 70 // 71 // In legacy pairing (`local_long_term_key.security.secure_connections` is 72 // false), this key corresponds to the key distributed by the local device. 73 // In Secure Connections pairing there is only one LTK and 74 // `local_long_term_key` is the same as `peer_long_term_key`. 75 LongTermKey local_long_term_key; 76 }; 77 78 } // namespace pw::bluetooth::low_energy 79