• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 #include <string>
18 
19 #include <android-base/logging.h>
20 #include <gflags/gflags.h>
21 
22 #include "common/libs/fs/shared_buf.h"
23 #include "common/libs/fs/shared_fd.h"
24 #include "host/commands/cvd_send_id_disclosure/cellular_identifier_disclosure_command_builder.h"
25 #include "host/libs/config/cuttlefish_config.h"
26 
27 DEFINE_int32(instance_num, cuttlefish::GetInstance(),
28              "Which instance to read the configs from");
29 DEFINE_int32(modem_num, 0, "Which modem to send command to");
30 DEFINE_int32(identifier, 1,
31              "The identifier type that was disclosed. See "
32              "android.hardware.radio.network.CellularIdentifier");
33 DEFINE_int32(protocol_message, 1,
34              "The protocol message of the disclosure. See "
35              "android.hardware.radio.network.NasProtocolMessage");
36 DEFINE_bool(is_emergency, false,
37             "Whether or not this disclosure occurred during an emergency call");
38 DEFINE_string(plmn, "001001",
39               "The PLMN of the network on which the identifier was disclosed");
40 
41 namespace cuttlefish {
42 namespace {
43 
SendDisclosure(SharedFD fd)44 void SendDisclosure(SharedFD fd) {
45   std::string command =
46       fmt::format("REM{}{}", FLAGS_modem_num,
47                   GetATCommand(FLAGS_plmn, FLAGS_identifier,
48                                FLAGS_protocol_message, FLAGS_is_emergency));
49 
50   LOG(DEBUG) << "Attempting to send command: " << command;
51 
52   long written = WriteAll(fd, command);
53   if (written != command.size()) {
54     LOG(FATAL) << "Failed to write data to shared fd. Tried to write "
55                << command.size() << " bytes, but only wrote " << written
56                << " bytes.";
57   }
58 }
59 
SendIdDisclosureMain(int argc,char ** argv)60 int SendIdDisclosureMain(int argc, char **argv) {
61   ::android::base::InitLogging(argv, android::base::StderrLogger);
62   google::ParseCommandLineFlags(&argc, &argv, true);
63 
64   auto config = CuttlefishConfig::Get();
65   if (!config) {
66     LOG(FATAL) << "Failed to obtain config object";
67   }
68 
69   auto cf_config = config->ForInstance(FLAGS_instance_num);
70   std::string socket_name =
71       fmt::format("modem_simulator{}", cf_config.modem_simulator_host_id());
72 
73   LOG(INFO) << "Connecting over local socket: " << socket_name;
74   SharedFD modem_simulator_fd =
75       cuttlefish::SharedFD::SocketLocalClient(socket_name, true, SOCK_STREAM);
76 
77   SendDisclosure(modem_simulator_fd);
78 
79   return 0;
80 }
81 
82 }  // namespace
83 }  // namespace cuttlefish
84 
main(int argc,char ** argv)85 int main(int argc, char **argv) {
86   return cuttlefish::SendIdDisclosureMain(argc, argv);
87 }