blob: e844a4c38d6092117786a363c49e111c8aef0c73 [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#pragma once
19
20#include <memory>
21#include <vector>
22
Martin Brabham80854c22019-11-12 14:52:42 -080023#include "hci/address_with_type.h"
Martin Brabham605d6f12019-03-29 12:02:30 -070024#include "hci/hci_layer.h"
Martin Brabham80854c22019-11-12 14:52:42 -080025#include "hci/hci_packets.h"
Martin Brabham605d6f12019-03-29 12:02:30 -070026#include "hci/security_interface.h"
Martin Brabham605d6f12019-03-29 12:02:30 -070027
28namespace bluetooth {
29namespace security {
30namespace channel {
31
Martin Brabham605d6f12019-03-29 12:02:30 -070032/**
33 * Interface for listening to the channel for SMP commands.
34 */
35class ISecurityManagerChannelListener {
36 public:
37 virtual ~ISecurityManagerChannelListener() = default;
Martin Brabham80854c22019-11-12 14:52:42 -080038 virtual void OnHciEventReceived(hci::EventPacketView packet) = 0;
Martin Brabham605d6f12019-03-29 12:02:30 -070039};
40
41/**
42 * Channel for consolidating traffic and making the transport agnostic.
43 */
44class SecurityManagerChannel {
45 public:
46 explicit SecurityManagerChannel(os::Handler* handler, hci::HciLayer* hci_layer)
47 : listener_(nullptr),
48 hci_security_interface_(hci_layer->GetSecurityInterface(
49 common::Bind(&SecurityManagerChannel::OnHciEventReceived, common::Unretained(this)), handler)),
50 handler_(handler) {}
51 ~SecurityManagerChannel() {
52 delete listener_;
53 }
54
55 /**
56 * Send a given SMP command over the SecurityManagerChannel
57 *
Martin Brabham605d6f12019-03-29 12:02:30 -070058 * @param command smp command to send
59 */
Martin Brabham80854c22019-11-12 14:52:42 -080060 void SendCommand(std::unique_ptr<hci::SecurityCommandBuilder> command);
Martin Brabham605d6f12019-03-29 12:02:30 -070061
62 /**
63 * Sets the listener to listen for channel events
64 *
65 * @param listener the caller interested in events
66 */
67 void SetChannelListener(ISecurityManagerChannelListener* listener) {
68 listener_ = listener;
69 }
70
71 /**
72 * Called when an incoming HCI event happens
73 *
74 * @param event_packet
75 */
Martin Brabham80854c22019-11-12 14:52:42 -080076 void OnHciEventReceived(hci::EventPacketView packet);
Martin Brabham605d6f12019-03-29 12:02:30 -070077
78 /**
79 * Called when an HCI command is completed
80 *
81 * @param on_complete
82 */
Martin Brabham80854c22019-11-12 14:52:42 -080083 void OnCommandComplete(hci::CommandCompleteView packet);
Martin Brabham605d6f12019-03-29 12:02:30 -070084
85 private:
86 ISecurityManagerChannelListener* listener_;
87 hci::SecurityInterface* hci_security_interface_;
88 os::Handler* handler_;
89};
90
91} // namespace channel
92} // namespace security
93} // namespace bluetooth