1 //
2 // Copyright 2022 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #pragma once
18 
19 #include <functional>
20 #include <memory>
21 #include <vector>
22 
23 #include "model/hci/h4.h"
24 
25 namespace rootcanal {
26 
27 using PacketCallback = std::function<void(
28     PacketType, const std::shared_ptr<std::vector<uint8_t>>)>;
29 using CloseCallback = std::function<void()>;
30 
31 class HciTransport {
32  public:
33   virtual ~HciTransport() = default;
34 
35   /// Send the input HCI packet with the selected H4 packet type.
36   /// The packet data contains the H4 header but not the IDC byte.
37   virtual void Send(PacketType packet_type,
38                     std::vector<uint8_t> const& packet) = 0;
39 
40   /// Register the handler for received HCI packets.
41   virtual void RegisterCallbacks(PacketCallback packet_callback,
42                                  CloseCallback close_callback) = 0;
43 
44   virtual void Tick() = 0;
45   virtual void Close() = 0;
46 };
47 
48 }  // namespace rootcanal
49