1 // Copyright 2024 The Pigweed Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not 4 // use this file except in compliance with the License. You may obtain a copy of 5 // the License at 6 // 7 // https://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, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations under 13 // the License. 14 15 #pragma once 16 17 #include "pw_assert/check.h" // IWYU pragma: keep 18 #include "pw_bluetooth_proxy/h4_packet.h" 19 #include "pw_function/function.h" 20 21 namespace pw::bluetooth::proxy { 22 23 // Contains the facilities for forwarding HCI packets to the host and 24 // controller. 25 class HciTransport { 26 public: HciTransport(pw::Function<void (H4PacketWithHci && packet)> && send_to_host_fn,pw::Function<void (H4PacketWithH4 && packet)> && send_to_controller_fn)27 HciTransport( 28 pw::Function<void(H4PacketWithHci&& packet)>&& send_to_host_fn, 29 pw::Function<void(H4PacketWithH4&& packet)>&& send_to_controller_fn) 30 : outward_send_to_host_fn_(std::move(send_to_host_fn)), 31 outward_send_to_controller_fn_(std::move(send_to_controller_fn)) {} 32 33 // Send packet onwards to host. SendToHost(H4PacketWithHci && h4_packet)34 void SendToHost(H4PacketWithHci&& h4_packet) { 35 PW_DCHECK(outward_send_to_host_fn_ != nullptr); 36 outward_send_to_host_fn_(std::move(h4_packet)); 37 } 38 39 // Send packet onwards to controller. SendToController(H4PacketWithH4 && h4_packet)40 void SendToController(H4PacketWithH4&& h4_packet) { 41 PW_DCHECK(outward_send_to_controller_fn_ != nullptr); 42 outward_send_to_controller_fn_(std::move(h4_packet)); 43 } 44 45 private: 46 // Function to call when proxy wants proxy container to pass a packet to the 47 // host. 48 pw::Function<void(H4PacketWithHci&& packet)> outward_send_to_host_fn_; 49 50 // Function to call when proxy wants proxy container to pass a packet to the 51 // controller. 52 pw::Function<void(H4PacketWithH4&& packet)> outward_send_to_controller_fn_; 53 }; 54 55 } // namespace pw::bluetooth::proxy 56