1 //
2 // Copyright (C) 2019 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 #include "host/commands/run_cvd/launch/launch.h"
17
18 #include <string>
19 #include <vector>
20
21 #include <fruit/fruit.h>
22
23 #include "common/libs/utils/result.h"
24 #include "host/libs/config/command_source.h"
25 #include "host/libs/config/known_paths.h"
26
27 // Copied from net/bluetooth/hci.h
28 #define HCI_MAX_ACL_SIZE 1024
29 #define HCI_MAX_FRAME_SIZE (HCI_MAX_ACL_SIZE + 4)
30
31 // Include H4 header byte, and reserve more buffer size in the case of excess
32 // packet.
33 constexpr const size_t kBufferSize = (HCI_MAX_FRAME_SIZE + 1) * 2;
34
35 namespace cuttlefish {
36
BluetoothConnector(const CuttlefishConfig & config,const CuttlefishConfig::InstanceSpecific & instance)37 Result<std::optional<MonitorCommand>> BluetoothConnector(
38 const CuttlefishConfig& config,
39 const CuttlefishConfig::InstanceSpecific& instance) {
40 if (!config.enable_host_bluetooth_connector()) {
41 return {};
42 }
43 std::vector<std::string> fifo_paths = {
44 instance.PerInstanceInternalPath("bt_fifo_vm.in"),
45 instance.PerInstanceInternalPath("bt_fifo_vm.out"),
46 };
47 std::vector<SharedFD> fifos;
48 for (const auto& path : fifo_paths) {
49 fifos.emplace_back(CF_EXPECT(SharedFD::Fifo(path, 0660)));
50 }
51 return Command(TcpConnectorBinary())
52 .AddParameter("-fifo_out=", fifos[0])
53 .AddParameter("-fifo_in=", fifos[1])
54 .AddParameter("-data_port=", config.rootcanal_hci_port())
55 .AddParameter("-buffer_size=", kBufferSize);
56 }
57
58 } // namespace cuttlefish
59