• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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         HciDataCallback onIsoReceive);
31 
32     ssize_t SendPacket(HciPacketType packetType, const std::vector<uint8_t> &packetData) override;
33     void ReadData(int fd);
34     ~H4Protocol() override;
35 
36 private:
37     void PacketCallback();
38     void SetRTSchedule();
39 
40 private:
41     int hciFd_ = 0;
42     HciDataCallback onAclReceive_;
43     HciDataCallback onScoReceive_;
44     HciDataCallback onEventReceive_;
45     HciDataCallback onIsoReceive_;
46     std::mutex tidMutex_;
47     std::map<pid_t, bool> tidMap_;
48 
49     uint8_t packetType_ = 0;
50     std::vector<uint8_t> hciPacket_;
51     uint32_t readLength_ = 0;
52 };
53 }  // namespace Hci
54 }  // namespace Bluetooth
55 }  // namespace HDI
56 }  // namespace OHOS
57 
58 #endif /* OHOS_HDI_BLUETOOTH_HCI_H4_PROTOCOL_H */