• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
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 <functional>
22 #include <vector>
23 
24 #include "hci_internals.h"
25 
26 namespace android {
27 namespace hardware {
28 namespace bluetooth {
29 namespace hci {
30 
31 using ::android::hardware::hidl_vec;
32 using HciPacketReadyCallback = std::function<void(void)>;
33 
34 class HciPacketizer {
35  public:
36   HciPacketizer() = default;
37   bool OnDataReady(HciPacketType packet_type, const std::vector<uint8_t>& data,
38                    size_t offset);
39   const hidl_vec<uint8_t>& GetPacket() const;
40 
41  private:
42   size_t fill_header(HciPacketType packet_type,
43                      const std::vector<uint8_t>& data, size_t offset);
44   void fill_payload(const std::vector<uint8_t>& data, size_t offset);
45   enum State { HCI_HEADER, HCI_PAYLOAD };
46   State state_{HCI_HEADER};
47   hidl_vec<uint8_t> packet_;
48   std::vector<uint8_t> packet_buffer_;
49   size_t bytes_remaining_{0};
50 };
51 
52 }  // namespace hci
53 }  // namespace bluetooth
54 }  // namespace hardware
55 }  // namespace android
56