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_H4_PROTOCOL_H 17 #define OHOS_HDI_BLUETOOTH_HCI_H4_PROTOCOL_H 18 19 #include "hci_protocol.h" 20 #include <map> 21 #include <mutex> 22 23 namespace OHOS { 24 namespace HDI { 25 namespace Bluetooth { 26 namespace Hci { 27 class H4Protocol : public HciProtocol { 28 public: 29 H4Protocol(int fd, HciDataCallback onAclReceive, HciDataCallback onScoReceive, HciDataCallback onEventReceive); 30 31 ssize_t SendPacket(HciPacketType packetType, const std::vector<uint8_t> &packetData) override; 32 void ReadData(int fd); 33 ~H4Protocol() override; 34 35 private: 36 void PacketCallback(); 37 void SetRTSchedule(); 38 39 private: 40 int hciFd_ = 0; 41 HciDataCallback onAclReceive_; 42 HciDataCallback onScoReceive_; 43 HciDataCallback onEventReceive_; 44 std::mutex tidMutex_; 45 std::map<pid_t, bool> tidMap_; 46 47 uint8_t packetType_ = 0; 48 std::vector<uint8_t> hciPacket_; 49 uint32_t readLength_ = 0; 50 }; 51 } // namespace Hci 52 } // namespace Bluetooth 53 } // namespace HDI 54 } // namespace OHOS 55 56 #endif /* OHOS_HDI_BLUETOOTH_HCI_H4_PROTOCOL_H */