Android-cuttlefish cvd tool
modem_service.h
Go to the documentation of this file.
1//
2// Copyright (C) 2020 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#pragma once
17
18
19#include <functional>
20#include <map>
21#include <optional>
22
26
27namespace cuttlefish {
28
29enum ModemServiceType : int {
38};
39
40using f_func = std::function<void(const Client&)>; // Full match
41using p_func = std::function<void(const Client&, std::string&)>; // Partial match
42
44 public:
45 CommandHandler(const std::string& command, f_func handler);
46 CommandHandler(const std::string& command, p_func handler);
47
48 ~CommandHandler() = default;
49
50 int Compare(const std::string& command) const;
51 void HandleCommand(const Client& client, std::string& command) const;
52
53 private:
55
56 std::string command_prefix;
58
59 std::optional<f_func> f_command_handler;
60 std::optional<p_func> p_command_handler;
61};
62
64 public:
65
66 virtual ~ModemService() = default;
67
68 ModemService(const ModemService &) = delete;
70
71 bool HandleModemCommand(const Client& client, std::string command);
72
73 static constexpr char kCmeErrorOperationNotAllowed[] = "+CME ERROR: 3";
74 static constexpr char kCmeErrorOperationNotSupported[] = "+CME ERROR: 4";
75 static constexpr char kCmeErrorSimNotInserted[] = "+CME ERROR: 10";
76 static constexpr char kCmeErrorSimPinRequired[] = "+CME ERROR: 11";
77 static constexpr char kCmeErrorSimPukRequired[] = "+CME ERROR: 12";
78 static constexpr char kCmeErrorSimBusy[] = "+CME ERROR: 14";
79 static constexpr char kCmeErrorIncorrectPassword[] = "+CME ERROR: 16";
80 static constexpr char kCmeErrorMemoryFull[] = "+CME ERROR: 20";
81 static constexpr char kCmeErrorInvalidIndex[] = "+CME ERROR: 21";
82 static constexpr char kCmeErrorNotFound[] = "+CME ERROR: 22";
84 "+CME ERROR: 27";
85 static constexpr char kCmeErrorNoNetworkService[] = "+CME ERROR: 30";
87 "+CME ERROR: 32";
88 static constexpr char kCmeErrorInCorrectParameters[] = "+CME ERROR: 50";
89 static constexpr char
91 "+CME ERROR: 53";
92 static constexpr char kCmeErrorFixedDialNumberOnlyAllowed[] =
93 "+CME ERROR: 56";
94
95 static constexpr char kCmsErrorOperationNotAllowed[] = "+CMS ERROR: 302";
96 static constexpr char kCmsErrorOperationNotSupported[] = "+CMS ERROR: 303";
97 static constexpr char kCmsErrorInvalidPDUModeParam[] = "+CMS ERROR: 304";
98 static constexpr char kCmsErrorSCAddressUnknown[] = "+CMS ERROR: 304";
99
100 static constexpr std::pair<int, int> kRemotePortRange{6520, 6527};
101
102 void CloseRemoteConnection(ClientId remote_client);
103
104 protected:
105 ModemService(int32_t service_id, std::vector<CommandHandler> command_handlers,
106 ChannelMonitor* channel_monitor, ThreadLooper* thread_looper);
107 void HandleCommandDefaultSupported(const Client& client);
108 void SendUnsolicitedCommand(std::string unsol_command);
109
111 void SendCommandToRemote(ClientId remote_client, std::string response);
112 static std::string GetHostId();
113
114 int32_t service_id_;
115 const std::vector<CommandHandler> command_handlers_;
118};
119
120} // namespace cuttlefish
Definition: channel_monitor.h:35
Definition: client.h:30
Definition: client.h:47
Definition: modem_service.h:43
MatchMode
Definition: modem_service.h:54
@ FULL_MATCH
Definition: modem_service.h:54
@ PARTIAL_MATCH
Definition: modem_service.h:54
std::string command_prefix
Definition: modem_service.h:56
MatchMode match_mode
Definition: modem_service.h:57
void HandleCommand(const Client &client, std::string &command) const
Definition: modem_service.cpp:46
CommandHandler(const std::string &command, f_func handler)
Definition: modem_service.cpp:26
std::optional< f_func > f_command_handler
Definition: modem_service.h:59
int Compare(const std::string &command) const
Definition: modem_service.cpp:36
std::optional< p_func > p_command_handler
Definition: modem_service.h:60
Definition: modem_service.h:63
ModemService(const ModemService &)=delete
cuttlefish::SharedFD ConnectToRemoteCvd(std::string port)
Definition: modem_service.cpp:90
ModemService & operator=(const ModemService &)=delete
static constexpr char kCmeErrorFixedDialNumberOnlyAllowed[]
Definition: modem_service.h:92
static constexpr char kCmeErrorOperationNotAllowed[]
Definition: modem_service.h:73
static constexpr char kCmeErrorMemoryFull[]
Definition: modem_service.h:80
static constexpr char kCmeErrorInvalidCharactersInTextString[]
Definition: modem_service.h:83
static constexpr char kCmeErrorIncorrectPassword[]
Definition: modem_service.h:79
static constexpr char kCmsErrorSCAddressUnknown[]
Definition: modem_service.h:98
static constexpr std::pair< int, int > kRemotePortRange
Definition: modem_service.h:100
static constexpr char kCmeErrorSimNotInserted[]
Definition: modem_service.h:75
static constexpr char kCmsErrorInvalidPDUModeParam[]
Definition: modem_service.h:97
static constexpr char kCmeErrorInvalidIndex[]
Definition: modem_service.h:81
static constexpr char kCmeErrorNotFound[]
Definition: modem_service.h:82
static constexpr char kCmeErrorNetworkNotAttachedDueToMTFunctionalRestrictions[]
Definition: modem_service.h:90
ThreadLooper * thread_looper_
Definition: modem_service.h:116
virtual ~ModemService()=default
void SendCommandToRemote(ClientId remote_client, std::string response)
Definition: modem_service.cpp:101
bool HandleModemCommand(const Client &client, std::string command)
Definition: modem_service.cpp:66
static std::string GetHostId()
Definition: modem_service.cpp:116
static constexpr char kCmsErrorOperationNotSupported[]
Definition: modem_service.h:96
const std::vector< CommandHandler > command_handlers_
Definition: modem_service.h:115
void CloseRemoteConnection(ClientId remote_client)
Definition: modem_service.cpp:109
static constexpr char kCmeErrorSimPukRequired[]
Definition: modem_service.h:77
static constexpr char kCmeErrorInCorrectParameters[]
Definition: modem_service.h:88
int32_t service_id_
Definition: modem_service.h:114
static constexpr char kCmeErrorSimBusy[]
Definition: modem_service.h:78
static constexpr char kCmeErrorNetworkNotAllowedEmergencyCallsOnly[]
Definition: modem_service.h:86
static constexpr char kCmsErrorOperationNotAllowed[]
Definition: modem_service.h:95
ChannelMonitor * channel_monitor_
Definition: modem_service.h:117
static constexpr char kCmeErrorSimPinRequired[]
Definition: modem_service.h:76
static constexpr char kCmeErrorNoNetworkService[]
Definition: modem_service.h:85
static constexpr char kCmeErrorOperationNotSupported[]
Definition: modem_service.h:74
void SendUnsolicitedCommand(std::string unsol_command)
Definition: modem_service.cpp:83
void HandleCommandDefaultSupported(const Client &client)
Definition: modem_service.cpp:78
Definition: shared_fd.h:129
Definition: thread_looper.h:51
Definition: alloc_utils.cpp:23
ModemServiceType
Definition: modem_service.h:29
@ kSmsService
Definition: modem_service.h:34
@ kMiscService
Definition: modem_service.h:37
@ kCallService
Definition: modem_service.h:33
@ kSupService
Definition: modem_service.h:35
@ kSimService
Definition: modem_service.h:30
@ kNetworkService
Definition: modem_service.h:31
@ kStkService
Definition: modem_service.h:36
@ kDataService
Definition: modem_service.h:32
std::function< void(const Client &, std::string &)> p_func
Definition: modem_service.h:41
std::function< void(const Client &)> f_func
Definition: modem_service.h:40