blob: 2a9f2e354fa62ea84712f1c1c86e30922e5ecb03 [file] [log] [blame]
Martin Brabham80854c22019-11-12 14:52:42 -08001/*
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +02002 *
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 */
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +020018
19#pragma once
20
Martin Brabham605d6f12019-03-29 12:02:30 -070021#include <memory>
22#include <vector>
23
Jakub Pawlowskid2c82f52019-11-22 15:33:12 +010024#include "hci/address_with_type.h"
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +020025#include "security/internal/security_manager_impl.h"
26
27namespace bluetooth {
28namespace security {
29
Martin Brabham605d6f12019-03-29 12:02:30 -070030/**
Jakub Pawlowski5a67e402019-11-18 16:14:22 +010031 * Callback interface from SecurityManager.
32 */
33class ISecurityManagerListener {
34 public:
Jakub Pawlowskiaf9379b2019-11-18 17:51:13 +010035 virtual ~ISecurityManagerListener() = 0;
Jakub Pawlowski5a67e402019-11-18 16:14:22 +010036
37 /**
38 * Called when a device is successfully bonded.
39 *
Jakub Pawlowskid2c82f52019-11-22 15:33:12 +010040 * @param address of the newly bonded device
Jakub Pawlowski5a67e402019-11-18 16:14:22 +010041 */
Jakub Pawlowskid2c82f52019-11-22 15:33:12 +010042 virtual void OnDeviceBonded(bluetooth::hci::AddressWithType device) = 0;
Jakub Pawlowski5a67e402019-11-18 16:14:22 +010043
44 /**
45 * Called when a device is successfully un-bonded.
46 *
Jakub Pawlowskid2c82f52019-11-22 15:33:12 +010047 * @param address of device that is no longer bonded
Jakub Pawlowski5a67e402019-11-18 16:14:22 +010048 */
Jakub Pawlowskid2c82f52019-11-22 15:33:12 +010049 virtual void OnDeviceUnbonded(bluetooth::hci::AddressWithType device) = 0;
Jakub Pawlowski5a67e402019-11-18 16:14:22 +010050
51 /**
52 * Called as a result of a failure during the bonding process.
53 *
Jakub Pawlowskid2c82f52019-11-22 15:33:12 +010054 * @param address of the device that failed to bond
Jakub Pawlowski5a67e402019-11-18 16:14:22 +010055 */
Jakub Pawlowskid2c82f52019-11-22 15:33:12 +010056 virtual void OnDeviceBondFailed(bluetooth::hci::AddressWithType device) = 0;
Jakub Pawlowski5a67e402019-11-18 16:14:22 +010057};
58
59/**
Martin Brabham605d6f12019-03-29 12:02:30 -070060 * Manages the security attributes, pairing, bonding of devices, and the
61 * encryption/decryption of communications.
62 */
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +020063class SecurityManager {
64 public:
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +020065 friend class SecurityModule;
66
Martin Brabham605d6f12019-03-29 12:02:30 -070067 /**
68 * Initialize the security record map from an internal device database.
69 */
70 void Init();
71
72 /**
73 * Checks the device for existing bond, if not bonded, initiates pairing.
74 *
75 * @param device pointer to device we want to bond with
76 */
Martin Brabham80854c22019-11-12 14:52:42 -080077 void CreateBond(hci::AddressWithType device);
Martin Brabham605d6f12019-03-29 12:02:30 -070078
79 /**
80 * Cancels the pairing process for this device.
81 *
82 * @param device pointer to device with which we want to cancel our bond
83 */
Martin Brabham80854c22019-11-12 14:52:42 -080084 void CancelBond(hci::AddressWithType device);
Martin Brabham605d6f12019-03-29 12:02:30 -070085
86 /**
87 * Disassociates the device and removes the persistent LTK
88 *
89 * @param device pointer to device we want to forget
90 */
Martin Brabham80854c22019-11-12 14:52:42 -080091 void RemoveBond(hci::AddressWithType device);
Martin Brabham605d6f12019-03-29 12:02:30 -070092
93 /**
94 * Register to listen for callback events from SecurityManager
95 *
96 * @param listener ISecurityManagerListener instance to handle callbacks
97 */
Jakub Pawlowski24d5f352019-11-18 18:54:09 +010098 void RegisterCallbackListener(ISecurityManagerListener* listener, os::Handler* handler);
Martin Brabham605d6f12019-03-29 12:02:30 -070099
100 /**
101 * Unregister listener for callback events from SecurityManager
102 *
103 * @param listener ISecurityManagerListener instance to unregister
104 */
Jakub Pawlowski5a67e402019-11-18 16:14:22 +0100105 void UnregisterCallbackListener(ISecurityManagerListener* listener);
Martin Brabham605d6f12019-03-29 12:02:30 -0700106
107 protected:
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +0200108 SecurityManager(os::Handler* security_handler, internal::SecurityManagerImpl* security_manager_impl)
109 : security_handler_(security_handler), security_manager_impl_(security_manager_impl) {}
110
Martin Brabham605d6f12019-03-29 12:02:30 -0700111 private:
Jakub Pawlowskifa057bd2019-10-10 14:36:29 +0200112 os::Handler* security_handler_ = nullptr;
113 internal::SecurityManagerImpl* security_manager_impl_;
114 DISALLOW_COPY_AND_ASSIGN(SecurityManager);
115};
116
117} // namespace security
Martin Brabham605d6f12019-03-29 12:02:30 -0700118} // namespace bluetooth