• 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 <stddef.h>  // for size_t
20 #include <stdint.h>  // for uint8_t
21 
22 #include <memory>  // for shared_ptr
23 
24 #include "h4_parser.h"     // for ClientDisconnectCallback, H4Parser
25 #include "hci_protocol.h"  // for PacketReadCallback, AsyncDataChannel, HciProtocol
26 #include "net/async_data_channel.h"  // for AsyncDataChannel
27 
28 namespace rootcanal {
29 
30 using android::net::AsyncDataChannel;
31 
32 // A socket based H4DataChannelPacketizer. Call OnDataReady whenever
33 // data can be read from the socket.
34 class H4DataChannelPacketizer : public HciProtocol {
35  public:
36   H4DataChannelPacketizer(std::shared_ptr<AsyncDataChannel> socket,
37                           PacketReadCallback command_cb,
38                           PacketReadCallback event_cb,
39                           PacketReadCallback acl_cb, PacketReadCallback sco_cb,
40                           PacketReadCallback iso_cb,
41                           ClientDisconnectCallback disconnect_cb);
42 
43   size_t Send(uint8_t type, const uint8_t* data, size_t length) override;
44 
45   void OnDataReady(std::shared_ptr<AsyncDataChannel> socket);
46 
47  private:
48   std::shared_ptr<AsyncDataChannel> uart_socket_;
49   H4Parser h4_parser_;
50 
51   ClientDisconnectCallback disconnect_cb_;
52   bool disconnected_{false};
53 };
54 
55 }  // namespace rootcanal
56