1 /* 2 * Copyright 2018 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 <memory> // for shared_ptr, make_... 20 21 #include "model/hci/h4_data_channel_packetizer.h" // for H4DataChannelP... 22 #include "model/hci/hci_transport.h" // for HciTransport 23 #include "net/async_data_channel.h" // for AsyncDataChannel 24 25 namespace rootcanal { 26 27 using android::net::AsyncDataChannel; 28 29 class HciSocketTransport : public HciTransport { 30 public: 31 HciSocketTransport(std::shared_ptr<AsyncDataChannel> socket); 32 ~HciSocketTransport() = default; 33 Create(std::shared_ptr<AsyncDataChannel> socket)34 static std::shared_ptr<HciTransport> Create( 35 std::shared_ptr<AsyncDataChannel> socket) { 36 return std::make_shared<HciSocketTransport>(socket); 37 } 38 39 void SendEvent(const std::vector<uint8_t>& packet) override; 40 41 void SendAcl(const std::vector<uint8_t>& packet) override; 42 43 void SendSco(const std::vector<uint8_t>& packet) override; 44 45 void SendIso(const std::vector<uint8_t>& packet) override; 46 47 void RegisterCallbacks(PacketCallback command_callback, 48 PacketCallback acl_callback, 49 PacketCallback sco_callback, 50 PacketCallback iso_callback, 51 CloseCallback close_callback) override; 52 53 void Tick() override; 54 55 void Close() override; 56 57 private: 58 void SendHci(PacketType packet_type, const std::vector<uint8_t>& packet); 59 60 std::shared_ptr<AsyncDataChannel> socket_; 61 H4DataChannelPacketizer h4_{socket_, 62 [](const std::vector<uint8_t>&) {}, 63 [](const std::vector<uint8_t>&) {}, 64 [](const std::vector<uint8_t>&) {}, 65 [](const std::vector<uint8_t>&) {}, 66 [](const std::vector<uint8_t>&) {}, 67 [] {}}; 68 }; 69 70 } // namespace rootcanal 71