blob: 0c82fd6aa59af9f5ea1f110411a1863edefdad35 [file] [log] [blame]
Zach Johnson917efb12017-02-26 23:46:05 -08001//
2// Copyright 2017 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 <hidl/HidlSupport.h>
20
21#include "async_fd_watcher.h"
22#include "bt_vendor_lib.h"
23#include "hci_internals.h"
24#include "hci_protocol.h"
25
26namespace android {
27namespace hardware {
28namespace bluetooth {
29namespace hci {
30
31class H4Protocol : public HciProtocol {
32 public:
33 H4Protocol(int fd, PacketReadCallback event_cb, PacketReadCallback acl_cb,
Jakub Pawlowski13b4d312019-11-05 12:27:29 +010034 PacketReadCallback sco_cb, PacketReadCallback iso_cb)
Zach Johnson917efb12017-02-26 23:46:05 -080035 : uart_fd_(fd),
36 event_cb_(event_cb),
37 acl_cb_(acl_cb),
38 sco_cb_(sco_cb),
Jakub Pawlowski13b4d312019-11-05 12:27:29 +010039 iso_cb_(iso_cb),
Zach Johnson917efb12017-02-26 23:46:05 -080040 hci_packetizer_([this]() { OnPacketReady(); }) {}
41
42 size_t Send(uint8_t type, const uint8_t* data, size_t length);
43
44 void OnPacketReady();
45
46 void OnDataReady(int fd);
47
48 private:
49 int uart_fd_;
50
51 PacketReadCallback event_cb_;
52 PacketReadCallback acl_cb_;
53 PacketReadCallback sco_cb_;
Jakub Pawlowski13b4d312019-11-05 12:27:29 +010054 PacketReadCallback iso_cb_;
Zach Johnson917efb12017-02-26 23:46:05 -080055
56 HciPacketType hci_packet_type_{HCI_PACKET_TYPE_UNKNOWN};
57 hci::HciPacketizer hci_packetizer_;
58};
59
60} // namespace hci
61} // namespace bluetooth
62} // namespace hardware
63} // namespace android