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 #include <cstdint>
16 #include <utility>
17
18 #include "pw_bloat/bloat_this_binary.h"
19 #include "pw_bluetooth_proxy/h4_packet.h"
20 #include "pw_bluetooth_proxy/proxy_host.h"
21 #include "pw_span/span.h"
22
23 namespace pw::bluetooth::proxy {
24
25 namespace {
26
UsePassthroughProxy()27 void UsePassthroughProxy() {
28 // Populate H4 buffer to send towards controller.
29 std::array<uint8_t, 20> h4_array_from_host{0};
30 H4PacketWithH4 h4_span_from_host = {pw::span(h4_array_from_host)};
31
32 // Populate H4 buffer to send towards host.
33 std::array<uint8_t, 19> hci_array_from_controller{0};
34 H4PacketWithHci h4_span_from_controller = {
35 emboss::H4PacketType::COMMAND, pw::span(hci_array_from_controller)};
36
37 pw::Function<void(H4PacketWithHci && packet)> container_send_to_host_fn(
38 []([[maybe_unused]] H4PacketWithHci packet) {});
39
40 pw::Function<void(H4PacketWithH4 && packet)> container_send_to_controller_fn(
41 ([]([[maybe_unused]] H4PacketWithH4&& packet) {}));
42
43 ProxyHost proxy = ProxyHost(std::move(container_send_to_host_fn),
44 std::move(container_send_to_controller_fn),
45 /*le_acl_credits_to_reserve=*/0,
46 /*br_edr_acl_credits_to_reserve=*/0);
47
48 proxy.HandleH4HciFromHost(std::move(h4_span_from_host));
49
50 proxy.HandleH4HciFromController(std::move(h4_span_from_controller));
51 }
52
53 } // namespace
54 } // namespace pw::bluetooth::proxy
55
main()56 int main() {
57 pw::bloat::BloatThisBinary();
58 pw::bluetooth::proxy::UsePassthroughProxy();
59 return 0;
60 }
61