1/* 2 * Copyright (C) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#ifndef OHOS_HDI_BLUETOOTH_HCI_HCI_PROTOCOL_H 17#define OHOS_HDI_BLUETOOTH_HCI_HCI_PROTOCOL_H 18 19#include <cstdio> 20#include <vector> 21 22#include <functional> 23#include "hci_internal.h" 24 25namespace OHOS { 26namespace HDI { 27namespace Bluetooth { 28namespace Hci { 29class HciProtocol { 30public: 31 using HciDataCallback = std::function<void(const std::vector<uint8_t> &data)>; 32 33 HciProtocol() = default; 34 virtual ~HciProtocol() = default; 35 36 virtual ssize_t SendPacket(HciPacketType packetType, const std::vector<uint8_t> &packetData) = 0; 37 38 const PacketHeader& GetPacketHeaderInfo(HciPacketType packetType); 39 40protected: 41 static ssize_t Read(int fd, uint8_t *data, size_t length); 42 static ssize_t Write(int fd, const uint8_t *data, size_t length); 43 44 static const PacketHeader header_[HCI_PACKET_TYPE_MAX]; 45}; 46} // namespace Hci 47} // namespace Bluetooth 48} // namespace HDI 49} // namespace OHOS 50#endif /* OHOS_HDI_BLUETOOTH_HCI_HCI_PROTOCOL_H */