Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 1 | /* |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 2 | * |
| 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 Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 17 | */ |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include <memory> |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 22 | #include <utility> |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 23 | |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 24 | #include "hci/address_with_type.h" |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 25 | |
| 26 | namespace bluetooth { |
| 27 | namespace security { |
| 28 | namespace record { |
| 29 | |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 30 | enum BondState { NOT_BONDED, PAIRING, PAIRED, BONDED }; |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 31 | |
| 32 | class SecurityRecord { |
| 33 | public: |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 34 | explicit SecurityRecord(hci::AddressWithType device) : device_(device), state_(NOT_BONDED) {} |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * Returns true if the device is bonded to another device |
| 38 | */ |
| 39 | bool IsBonded() { |
| 40 | return state_ == BONDED; |
| 41 | } |
| 42 | |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 43 | bool IsPaired() { |
| 44 | return state_ == PAIRED; |
| 45 | } |
| 46 | |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 47 | /** |
| 48 | * Returns true if a device is currently pairing to another device |
| 49 | */ |
| 50 | bool IsPairing() { |
| 51 | return state_ == PAIRING; |
| 52 | } |
| 53 | |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 54 | 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 Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 68 | return device_; |
| 69 | } |
| 70 | |
| 71 | private: |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 72 | const hci::AddressWithType device_; |
Martin Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 73 | BondState state_; |
Martin Brabham | 80854c2 | 2019-11-12 14:52:42 -0800 | [diff] [blame^] | 74 | 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 Brabham | 605d6f1 | 2019-03-29 12:02:30 -0700 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | } // namespace record |
| 79 | } // namespace security |
| 80 | } // namespace bluetooth |