blob: 58f047b96fb24e80e9e6e76f030be87f0a6d58ef [file] [log] [blame]
Martin Brabham80854c22019-11-12 14:52:42 -08001/*
Martin Brabham605d6f12019-03-29 12:02:30 -07002 *
3 * Copyright 2019 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
Martin Brabham80854c22019-11-12 14:52:42 -080017 */
Martin Brabham605d6f12019-03-29 12:02:30 -070018
19#pragma once
20
21#include <memory>
Martin Brabham80854c22019-11-12 14:52:42 -080022#include <utility>
Martin Brabham605d6f12019-03-29 12:02:30 -070023
Martin Brabham80854c22019-11-12 14:52:42 -080024#include "hci/address_with_type.h"
Martin Brabham605d6f12019-03-29 12:02:30 -070025
26namespace bluetooth {
27namespace security {
28namespace record {
29
Martin Brabham80854c22019-11-12 14:52:42 -080030enum BondState { NOT_BONDED, PAIRING, PAIRED, BONDED };
Martin Brabham605d6f12019-03-29 12:02:30 -070031
32class SecurityRecord {
33 public:
Martin Brabham80854c22019-11-12 14:52:42 -080034 explicit SecurityRecord(hci::AddressWithType device) : device_(device), state_(NOT_BONDED) {}
Martin Brabham605d6f12019-03-29 12:02:30 -070035
36 /**
37 * Returns true if the device is bonded to another device
38 */
39 bool IsBonded() {
40 return state_ == BONDED;
41 }
42
Martin Brabham80854c22019-11-12 14:52:42 -080043 bool IsPaired() {
44 return state_ == PAIRED;
45 }
46
Martin Brabham605d6f12019-03-29 12:02:30 -070047 /**
48 * Returns true if a device is currently pairing to another device
49 */
50 bool IsPairing() {
51 return state_ == PAIRING;
52 }
53
Martin Brabham80854c22019-11-12 14:52:42 -080054 void SetLinkKey(std::array<uint8_t, 16> link_key, hci::KeyType key_type) {
55 link_key_ = link_key;
56 key_type_ = key_type;
57 }
58
59 std::array<uint8_t, 16> GetLinkKey() {
60 return link_key_;
61 }
62
63 hci::KeyType GetKeyType() {
64 return key_type_;
65 }
66
67 hci::AddressWithType GetDevice() {
Martin Brabham605d6f12019-03-29 12:02:30 -070068 return device_;
69 }
70
71 private:
Martin Brabham80854c22019-11-12 14:52:42 -080072 const hci::AddressWithType device_;
Martin Brabham605d6f12019-03-29 12:02:30 -070073 BondState state_;
Martin Brabham80854c22019-11-12 14:52:42 -080074 std::array<uint8_t, 16> link_key_ = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
75 hci::KeyType key_type_ = hci::KeyType::DEBUG_COMBINATION;
Martin Brabham605d6f12019-03-29 12:02:30 -070076};
77
78} // namespace record
79} // namespace security
80} // namespace bluetooth