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 #define UCI_HEADER_SIZE 4
19 #define UCI_MAX_PAYLOAD_SIZE 255
20 #define UCI_MAX_PACKET_SIZE (UCI_HEADER_SIZE + UCI_MAX_PAYLOAD_SIZE)
21
22 constexpr const size_t kBufferSize = UCI_MAX_PACKET_SIZE * 2;
23
24 namespace cuttlefish {
25
UwbConnector(const CuttlefishConfig & config,const CuttlefishConfig::InstanceSpecific & instance)26 Result<std::optional<MonitorCommand>> UwbConnector(
27 const CuttlefishConfig& config,
28 const CuttlefishConfig::InstanceSpecific& instance) {
29 if (!config.enable_host_uwb_connector()) {
30 return {};
31 }
32 std::vector<std::string> fifo_paths = {
33 instance.PerInstanceInternalPath("uwb_fifo_vm.in"),
34 instance.PerInstanceInternalPath("uwb_fifo_vm.out"),
35 };
36 std::vector<SharedFD> fifos;
37 for (const auto& path : fifo_paths) {
38 fifos.push_back(CF_EXPECT(SharedFD::Fifo(path, 0660)));
39 }
40 return Command(HostBinaryPath("tcp_connector"))
41 .AddParameter("-fifo_out=", fifos[0])
42 .AddParameter("-fifo_in=", fifos[1])
43 .AddParameter("-data_port=", config.pica_uci_port())
44 .AddParameter("-buffer_size=", kBufferSize);
45 }
46
47 } // namespace cuttlefish
48