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 "hci_internal.h" 23 24 namespace OHOS { 25 namespace HDI { 26 namespace Bluetooth { 27 namespace Hci { 28 class HciProtocol { 29 public: 30 using HciDataCallback = std::function<void(const std::vector<uint8_t> &data)>; 31 32 HciProtocol() = default; 33 virtual ~HciProtocol() = default; 34 35 virtual ssize_t SendPacket(HciPacketType packetType, const std::vector<uint8_t> &packetData) = 0; 36 37 const PacketHeader& GetPacketHeaderInfo(HciPacketType packetType); 38 39 protected: 40 static ssize_t Read(int fd, uint8_t *data, size_t length); 41 static ssize_t Write(int fd, const uint8_t *data, size_t length); 42 43 static const PacketHeader header_[HCI_PACKET_TYPE_MAX]; 44 }; 45 } // namespace Hci 46 } // namespace Bluetooth 47 } // namespace HDI 48 } // namespace OHOS 49 #endif /* OHOS_HDI_BLUETOOTH_HCI_HCI_PROTOCOL_H */